mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-12 23:31:02 +00:00
Compare commits
6 Commits
v5.1.3-tf.2
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d6a6b49b6b | |||
| 0855bafca7 | |||
| a39f3fe40c | |||
| f13a0aa6ee | |||
| 10d1a61614 | |||
| 2bcfc1bfcb |
@@ -1,5 +1,5 @@
|
||||
apiVersion: v2
|
||||
name: trek
|
||||
version: 5.1.3
|
||||
version: 5.1.4
|
||||
description: Minimal Helm chart for TREK app
|
||||
appVersion: "5.1.3"
|
||||
appVersion: "5.1.4"
|
||||
|
||||
@@ -685,7 +685,7 @@ extension TrekShellPlugin {
|
||||
// A held one that was delivered stops the purchase here. One that was paid
|
||||
// but never set up is handed back as bought, so its instance is set up now.
|
||||
if let held = await TrekStore.currentEntitlement(prefix: "cloud.") {
|
||||
if await TrekStore.isUnfinished(held.id) {
|
||||
if await TrekStore.awaitingSetup(held) {
|
||||
call.resolve(["kind": "bought", "jws": held.jws, "transactionId": String(held.id), "productId": held.productId])
|
||||
} else {
|
||||
call.resolve(["kind": "subscribed"])
|
||||
@@ -759,8 +759,8 @@ extension TrekShellPlugin {
|
||||
call.resolve(["held": false])
|
||||
return
|
||||
}
|
||||
let unfinished = await TrekStore.isUnfinished(held.id)
|
||||
call.resolve(["held": !unfinished])
|
||||
let awaiting = await TrekStore.awaitingSetup(held)
|
||||
call.resolve(["held": !awaiting])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -793,17 +793,54 @@ enum TrekStore {
|
||||
}
|
||||
}
|
||||
|
||||
static func currentEntitlement(prefix: String) async -> (jws: String, id: UInt64, productId: String)? {
|
||||
var newest: (date: Date, jws: String, id: UInt64, productId: String)?
|
||||
typealias Held = (jws: String, id: UInt64, productId: String, firstPurchase: Bool)
|
||||
|
||||
/// The subscription this Apple ID holds under `prefix`, newest first. The
|
||||
/// entitlements on the device come first; on a fresh install they can still
|
||||
/// be empty while the subscription runs, so the status of the subscription
|
||||
/// group, which StoreKit asks the App Store for, decides then.
|
||||
static func currentEntitlement(prefix: String) async -> Held? {
|
||||
var newest: (date: Date, held: Held)?
|
||||
for await result in Transaction.currentEntitlements {
|
||||
guard case .verified(let transaction) = result,
|
||||
transaction.productID.hasPrefix(prefix),
|
||||
transaction.revocationDate == nil else { continue }
|
||||
if newest == nil || transaction.purchaseDate > newest!.date {
|
||||
newest = (transaction.purchaseDate, result.jwsRepresentation, transaction.id, transaction.productID)
|
||||
newest = (transaction.purchaseDate, held(result.jwsRepresentation, transaction))
|
||||
}
|
||||
}
|
||||
return newest.map { (jws: $0.jws, id: $0.id, productId: $0.productId) }
|
||||
if let newest { return newest.held }
|
||||
return await subscriptionGroupHeld(prefix: prefix)
|
||||
}
|
||||
|
||||
/// The plans the control plane sells (`cloud.<plan>.<monthly|yearly>`, as
|
||||
/// productIdFor in iap.ts); one of them is enough to find their group.
|
||||
private static let plans = ["start", "basis", "plus", "pro"]
|
||||
|
||||
private static func subscriptionGroupHeld(prefix: String) async -> Held? {
|
||||
let ids = plans.flatMap { ["\(prefix)\($0).monthly", "\(prefix)\($0).yearly"] }
|
||||
guard let products = try? await Product.products(for: ids),
|
||||
let group = products.compactMap({ $0.subscription?.subscriptionGroupID }).first,
|
||||
let statuses = try? await Product.SubscriptionInfo.status(for: group) else { return nil }
|
||||
let running: [Product.SubscriptionInfo.RenewalState] = [.subscribed, .inGracePeriod, .inBillingRetryPeriod]
|
||||
for status in statuses where running.contains(status.state) {
|
||||
if case .verified(let transaction) = status.transaction, transaction.revocationDate == nil {
|
||||
return held(status.transaction.jwsRepresentation, transaction)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private static func held(_ jws: String, _ transaction: Transaction) -> Held {
|
||||
(jws: jws, id: transaction.id, productId: transaction.productID, firstPurchase: transaction.originalID == transaction.id)
|
||||
}
|
||||
|
||||
/// A first purchase that was paid but whose instance was never set up: handed
|
||||
/// back as bought so it is set up now. A renewal the device has not finished
|
||||
/// yet is no such purchase; its subscription is running and counts as held.
|
||||
static func awaitingSetup(_ held: Held) async -> Bool {
|
||||
guard held.firstPurchase else { return false }
|
||||
return await isUnfinished(held.id)
|
||||
}
|
||||
|
||||
/// Paid but not delivered yet: the shell finishes a transaction once its instance exists.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@trek/client",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"engines": {
|
||||
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import L from 'leaflet';
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { act, render, waitFor } from '../../../tests/helpers/render';
|
||||
import { resetAllStores } from '../../../tests/helpers/store';
|
||||
import { withMarkerCategory } from '../../pages/collections/collectionsModel';
|
||||
import CollectionMap from './CollectionMap';
|
||||
|
||||
vi.mock('../../hooks/useGeolocation', () => ({
|
||||
@@ -258,3 +259,26 @@ describe('CollectionMap framing', () => {
|
||||
expect(wrappedIn(map, '[--bottom-nav-h:0px]')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CollectionMap pins (#3073)', () => {
|
||||
const MUSEUM = { id: 4, name: 'Museum', color: '#7c3aed', icon: 'Landmark' };
|
||||
|
||||
it('FE-COMP-COLMAP-008: a saved place carries its category where the markers read it', () => {
|
||||
const pin = withMarkerCategory({ ...place(1, 'Belvedere', 48.1915, 16.3809), category_id: 4, category: MUSEUM });
|
||||
expect(pin).toMatchObject({ category_name: 'Museum', category_color: '#7c3aed', category_icon: 'Landmark' });
|
||||
expect(withMarkerCategory(place(2, 'Somewhere', 48.2, 16.37))).toMatchObject({
|
||||
category_name: null,
|
||||
category_color: null,
|
||||
category_icon: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('FE-COMP-COLMAP-009: the pin of a place with a category wears its colour, not the grey default', async () => {
|
||||
const { view } = await renderMap([
|
||||
{ ...place(1, 'Belvedere', 48.1915, 16.3809), category_id: 4, category: MUSEUM },
|
||||
]);
|
||||
await waitFor(() => expect(view.container.querySelector('.leaflet-marker-icon')).not.toBeNull());
|
||||
const html = view.container.querySelector('.leaflet-marker-icon')?.innerHTML ?? '';
|
||||
expect(html.toLowerCase()).toContain('#7c3aed');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useMemo } from 'react'
|
||||
import { MapViewAuto } from '../Map/MapViewAuto'
|
||||
import type { CollectionPlace } from '@trek/shared'
|
||||
import { mappablePlaces } from '../../pages/collections/collectionsModel'
|
||||
import { mappablePlaces, withMarkerCategory } from '../../pages/collections/collectionsModel'
|
||||
import { useTileUrl } from '../../hooks/useTileUrl'
|
||||
import { OFM_DARK, OFM_POSITRON } from '../../constants/mapDefaults'
|
||||
import type { ViewportPadding } from '../../utils/mapViewport'
|
||||
@@ -70,7 +70,7 @@ function framePoints(places: CollectionPlace[]): [number, number][] {
|
||||
* while the map is built rather than flying in.
|
||||
*/
|
||||
export default function CollectionMap({ places, selectedPlaceId, onOpenPlace, onDeselect, dark, underBar = false }: CollectionMapProps): React.ReactElement {
|
||||
const pts = useMemo(() => mappablePlaces(places), [places])
|
||||
const pts = useMemo(() => mappablePlaces(places).map(withMarkerCategory), [places])
|
||||
const tileUrl = useTileUrl(dark ? OFM_DARK : OFM_POSITRON)
|
||||
const focusPoints = useMemo(() => framePoints(pts), [pts])
|
||||
// The places as a set: another list, a filter or a new place frames again, while a
|
||||
|
||||
@@ -6,6 +6,7 @@ import { loadUnionPlaces } from '../../store/collectionUnion'
|
||||
import { STATUS_META, STATUS_ORDER } from '../../pages/collections/collectionsModel'
|
||||
import type { CollectionPlace, CollectionStatus } from '@trek/shared'
|
||||
import type { TranslationFn } from '../../types'
|
||||
import { textMatchesSearch } from '../../utils/placeSearch'
|
||||
import { fs } from '../shared/DialogShell'
|
||||
import { EditorField, INPUT, LABEL } from '../shared/dialogParts'
|
||||
import { ColumnHead, HintCard, SIDE_COLUMN, WHITE_BUTTON } from '../Planner/placeDialogParts'
|
||||
@@ -143,12 +144,10 @@ export default function CollectionPicker({ bias, onSelect, t }: CollectionPicker
|
||||
const [shown, setShown] = useState(PAGE)
|
||||
|
||||
const visible = useMemo(() => {
|
||||
const q = search.trim().toLowerCase()
|
||||
const list = places.filter(p => {
|
||||
if (listFilter !== 'all' && p.collection_id !== listFilter) return false
|
||||
if (statusFilter !== 'all' && p.status !== statusFilter) return false
|
||||
if (!q) return true
|
||||
return p.name.toLowerCase().includes(q) || (p.address ?? '').toLowerCase().includes(q)
|
||||
return textMatchesSearch([p.name, p.address], search)
|
||||
})
|
||||
if (center) list.sort((a, b) => distanceTo(a, center) - distanceTo(b, center))
|
||||
else list.sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getCategoryIcon } from '../shared/categoryIcons'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { formatDate } from '../../utils/formatters'
|
||||
import { textMatchesSearch } from '../../utils/placeSearch'
|
||||
import { getApiErrorMessage } from '../../types'
|
||||
import type { Category, TranslationFn } from '../../types'
|
||||
import type { CollectionImportablePlace, Trip } from '@trek/shared'
|
||||
@@ -128,10 +129,9 @@ export default function ImportFromTripModal({ isOpen, collectionId, collectionNa
|
||||
const savedCount = items.length - newCount
|
||||
|
||||
const visible = useMemo(() => {
|
||||
const q = query.trim().toLowerCase()
|
||||
return items
|
||||
.filter(p => (onlyNew ? !p.already_in_list : true))
|
||||
.filter(p => !q || p.name.toLowerCase().includes(q) || (p.address ?? '').toLowerCase().includes(q))
|
||||
.filter(p => textMatchesSearch([p.name, p.address], query))
|
||||
.sort((a, b) => importOrder(a) - importOrder(b) || a.name.localeCompare(b.name))
|
||||
}, [items, onlyNew, query])
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useId, useRef, useState } from 'react'
|
||||
import { MapPin, Search } from 'lucide-react'
|
||||
import { mapsApi } from '../../api/client'
|
||||
import { textMatchesSearch } from '../../utils/placeSearch'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { useLocationBias } from '../../hooks/useLocationBias'
|
||||
import { usePlaceSuggestions } from '../../hooks/usePlaceSuggestions'
|
||||
@@ -196,7 +197,7 @@ function SourceMark({ label }: { label: string | null }) {
|
||||
function pickRows<T>(value: LocationPoint | null, typed: string, places: LocationPoint[] | undefined, results: T[]) {
|
||||
const showPicks = !value && typed.length < 3 && !!places?.length
|
||||
const rows: (T | LocationPoint)[] = showPicks
|
||||
? (places ?? []).filter(p => !typed || p.name.toLowerCase().includes(typed.toLowerCase()))
|
||||
? (places ?? []).filter(p => textMatchesSearch([p.name], typed))
|
||||
: results
|
||||
return { showPicks, rows }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// FE-PLANNER-PLACEFORM-125: a place picked from a collection inside a trip (#3074).
|
||||
import { placeFormProps, seedPlaceFormStores } from '../../../tests/helpers/placeFormSetup';
|
||||
import { fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { collectionsApi } from '../../api/collections';
|
||||
import { useAddonStore } from '../../store/addonStore';
|
||||
import PlaceFormModal from './PlaceFormModal';
|
||||
|
||||
vi.mock('../shared/CustomTimePicker', async () => ({
|
||||
default: (await import('../../../tests/helpers/placeForm')).TimePickerStub,
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
resetAllStores();
|
||||
seedPlaceFormStores();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('PlaceFormModal with a place from a collection', () => {
|
||||
it('FE-PLANNER-PLACEFORM-125: a place picked from a collection keeps the category it was saved under (#3074)', async () => {
|
||||
seedStore(useAddonStore, {
|
||||
addons: [{ id: 'collections', name: 'Collections', type: 'collections', icon: '', enabled: true }],
|
||||
loaded: true,
|
||||
});
|
||||
vi.spyOn(collectionsApi, 'list').mockResolvedValue({
|
||||
collections: [{ id: 1, owner_id: 1, name: 'Tokyo 2026', color: '#ec4899' }],
|
||||
incomingInvites: [],
|
||||
});
|
||||
vi.spyOn(collectionsApi, 'get').mockResolvedValue({
|
||||
collection: { id: 1, owner_id: 1, name: 'Tokyo 2026', color: '#ec4899' },
|
||||
places: [
|
||||
{
|
||||
id: 10,
|
||||
collection_id: 1,
|
||||
name: 'Zebra Cafe',
|
||||
status: 'idea',
|
||||
lat: 35.66,
|
||||
lng: 139.7,
|
||||
category_id: 7,
|
||||
category: { id: 7, name: 'Must see', color: '#f59e0b', icon: 'Star' },
|
||||
},
|
||||
],
|
||||
});
|
||||
const onSave = vi.fn().mockResolvedValue(undefined);
|
||||
// A cafe saved as "Must see": the guess from its kind would be the cafe category.
|
||||
const categories = [
|
||||
{ id: 3, name: 'Cafe', color: '#7c3aed', icon: 'Coffee' },
|
||||
{ id: 7, name: 'Must see', color: '#f59e0b', icon: 'Star' },
|
||||
];
|
||||
render(<PlaceFormModal {...placeFormProps} categories={categories} onSave={onSave} />);
|
||||
fireEvent.click(await screen.findByText('Zebra Cafe'));
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Add$/i }));
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalled());
|
||||
expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ name: 'Zebra Cafe', category_id: '7' }));
|
||||
});
|
||||
});
|
||||
@@ -410,3 +410,15 @@ export function formPin(form: Pick<PlaceFormData, 'lat' | 'lng'>): { lat: number
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180) return null
|
||||
return { lat, lng }
|
||||
}
|
||||
|
||||
/**
|
||||
* The category a picked place already carries, as the form's value, when this server
|
||||
* has it. A place saved in a collection keeps its category_id, and categories are the
|
||||
* server's own, so it fits the trip as it stands. Guessing from the place's kind
|
||||
* instead dropped it (#3074).
|
||||
*/
|
||||
export function savedCategoryId(result: Record<string, unknown>, categories: readonly { id: number }[]): string | null {
|
||||
const id = result.category_id
|
||||
if (typeof id !== 'number') return null
|
||||
return categories.some(c => c.id === id) ? String(id) : null
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { weekFromPeriods } from './placeHours'
|
||||
import type { PlaceOpeningHours } from '@trek/shared'
|
||||
import {
|
||||
DEFAULT_FORM, endsBeforeStart, findDuplicatePlace, formPin, mergeResult, parseCoordinatePair, placeEditForm, placeFormPayload,
|
||||
prefillForm, type PlaceFormData, type PlacePrefill,
|
||||
prefillForm, savedCategoryId, type PlaceFormData, type PlacePrefill,
|
||||
} from './PlaceFormModal.helpers'
|
||||
import { useNewCategory, usePlaceForm } from './usePlaceForm'
|
||||
import { usePlaceSearch } from './usePlaceSearch'
|
||||
@@ -135,9 +135,10 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
|
||||
// the next pick may replace it and a hand choice is never overwritten (#2282).
|
||||
const categoryGuessedRef = useRef(false)
|
||||
const guessedCategory = (result: Record<string, unknown>): string => {
|
||||
const id = guessCategoryId(result, categories || [])
|
||||
const saved = savedCategoryId(result, categories || []) // a collection's place keeps its own (#3074)
|
||||
const id = saved ? null : guessCategoryId(result, categories || [])
|
||||
categoryGuessedRef.current = id != null
|
||||
return id != null ? String(id) : ''
|
||||
return saved ?? (id != null ? String(id) : '')
|
||||
}
|
||||
// The hours the details column looked up, as a week the contact block can take over (#2472).
|
||||
const [detailsHours, setDetailsHours] = useState<PlaceOpeningHours | null>(null)
|
||||
|
||||
@@ -53,6 +53,17 @@ const HOLE = undefined as unknown as CollectionPlace;
|
||||
describe('collectionsModel', () => {
|
||||
// ── filterPlaces ────────────────────────────────────────────────────────────
|
||||
describe('filterPlaces', () => {
|
||||
it('FE-COLLECTIONS-MODEL-045: the search finds Óbidos and São Brás typed without accents (#3075)', () => {
|
||||
const places = [
|
||||
cp({ id: 1, name: 'Óbidos', status: 'idea' }),
|
||||
cp({ id: 2, name: 'São Brás de Alportel', status: 'idea' }),
|
||||
cp({ id: 3, name: 'Lagos', status: 'idea', address: 'Rua de Évora' }),
|
||||
];
|
||||
expect(filterPlaces(places, 'all', 'obidos').map(p => p.id)).toEqual([1]);
|
||||
expect(filterPlaces(places, 'all', 'Sao Bras').map(p => p.id)).toEqual([2]);
|
||||
expect(filterPlaces(places, 'all', 'evora').map(p => p.id)).toEqual([3]);
|
||||
});
|
||||
|
||||
it('FE-COLLECTIONS-MODEL-001: status filter keeps only the matching status', () => {
|
||||
const places = [
|
||||
cp({ id: 1, name: 'A', status: 'idea' }),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { CollectionPlace, CollectionLabel } from '@trek/shared'
|
||||
import type { StatusFilter, CollectionSortMode } from '../../store/collectionStore'
|
||||
import { textMatchesSearch } from '../../utils/placeSearch'
|
||||
|
||||
/**
|
||||
* Pure data shaping + presentation metadata for the Collections page. No React
|
||||
@@ -36,7 +37,6 @@ export function filterPlaces(
|
||||
labelFilter: number[] = [],
|
||||
ratingFilter: number | 'all' = 'all',
|
||||
): CollectionPlace[] {
|
||||
const q = search.trim().toLowerCase()
|
||||
return places.filter(p => {
|
||||
if (!p) return false
|
||||
if (statusFilter !== 'all' && p.status !== statusFilter) return false
|
||||
@@ -44,12 +44,7 @@ export function filterPlaces(
|
||||
// Minimum-average-stars filter (#1435): unrated places drop out once a floor is set.
|
||||
if (ratingFilter !== 'all' && (p.rating_avg == null || p.rating_avg < ratingFilter)) return false
|
||||
if (labelFilter.length && !labelFilter.some(id => (p.label_ids ?? []).includes(id))) return false
|
||||
if (!q) return true
|
||||
return (
|
||||
p.name.toLowerCase().includes(q) ||
|
||||
(p.address ?? '').toLowerCase().includes(q) ||
|
||||
(p.notes ?? '').toLowerCase().includes(q)
|
||||
)
|
||||
return textMatchesSearch([p.name, p.address, p.notes], search)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,6 +88,25 @@ export function mappablePlaces(places: CollectionPlace[]): CollectionPlace[] {
|
||||
return places.filter(p => p && typeof p.lat === 'number' && typeof p.lng === 'number')
|
||||
}
|
||||
|
||||
/**
|
||||
* A saved place with its category where the trip map reads it. The server nests a
|
||||
* collection place's category (`category.color`), the markers and the hover card
|
||||
* read the flat fields a trip place carries, so every pin here was the grey default
|
||||
* (#3073).
|
||||
*/
|
||||
export function withMarkerCategory(place: CollectionPlace): CollectionPlace & {
|
||||
category_name: string | null
|
||||
category_color: string | null
|
||||
category_icon: string | null
|
||||
} {
|
||||
return {
|
||||
...place,
|
||||
category_name: place.category?.name ?? null,
|
||||
category_color: place.category?.color ?? null,
|
||||
category_icon: place.category?.icon ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise a user-typed link: prepend https:// when there's no scheme so the
|
||||
* href is absolute (a bare "booking.com" would otherwise resolve relative to the
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// FE-UTIL-PLACESEARCH-001 to FE-UTIL-PLACESEARCH-004
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { placeMatchesSearch } from './placeSearch'
|
||||
import { foldForSearch, placeMatchesSearch, textMatchesSearch } from './placeSearch'
|
||||
|
||||
const place = {
|
||||
name: 'Café Central',
|
||||
@@ -32,3 +32,25 @@ describe('placeMatchesSearch', () => {
|
||||
expect(placeMatchesSearch(place, 'pizza')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('search without accents (#3075)', () => {
|
||||
it('FE-UTIL-PLACESEARCH-005: a query without accents finds the accented name, and the other way round', () => {
|
||||
for (const [query, name] of [['Obidos', 'Óbidos'], ['Evora', 'Évora'], ['Sao Bras', 'São Brás'], ['Loule', 'Loulé']]) {
|
||||
expect(placeMatchesSearch({ name, address: null, description: null, notes: null }, query)).toBe(true)
|
||||
expect(placeMatchesSearch({ name: query, address: null, description: null, notes: null }, name)).toBe(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('FE-UTIL-PLACESEARCH-006: letters with the mark built in fold to their plain spelling', () => {
|
||||
expect(foldForSearch('Straße')).toBe('strasse')
|
||||
expect(foldForSearch('Łódź')).toBe('lodz')
|
||||
expect(foldForSearch('Ærø')).toBe('aero')
|
||||
expect(textMatchesSearch(['Kraków'], 'krakow')).toBe(true)
|
||||
})
|
||||
|
||||
it('FE-UTIL-PLACESEARCH-007: marks that change a word outside Latin script stay, so が is not か', () => {
|
||||
expect(foldForSearch('が')).toBe('が')
|
||||
expect(textMatchesSearch(['かき'], 'がき')).toBe(false)
|
||||
expect(foldForSearch('한국')).toBe('한국')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,9 +10,33 @@ type Searchable = Pick<Place, 'name' | 'address' | 'description' | 'notes'>
|
||||
* can never disagree about what a search finds.
|
||||
*/
|
||||
export function placeMatchesSearch(place: Searchable, query: string): boolean {
|
||||
const q = query.trim().toLowerCase()
|
||||
if (!q) return true
|
||||
return [place.name, place.address, place.description, place.notes].some(
|
||||
field => !!field && field.toLowerCase().includes(q),
|
||||
)
|
||||
return textMatchesSearch([place.name, place.address, place.description, place.notes], query)
|
||||
}
|
||||
|
||||
/** The combining accents of Latin script (U+0300 to U+036F), the marks NFD splits off a letter. */
|
||||
const LATIN_MARKS = new RegExp(`[${String.fromCharCode(0x300)}-${String.fromCharCode(0x36f)}]`, 'g')
|
||||
|
||||
/** Letters that carry their mark in the letter itself, so taking the marks off leaves them as they are. */
|
||||
const FOLDED_LETTERS: Record<string, string> = { ß: 'ss', ø: 'o', æ: 'ae', œ: 'oe', ł: 'l', đ: 'd', ð: 'd', þ: 'th', ı: 'i' }
|
||||
|
||||
/**
|
||||
* Text as a search compares it: lower case and without accents, so "Obidos" finds
|
||||
* "Óbidos", "Sao Bras" finds "São Brás" and the other way round (#3075). Only
|
||||
* Latin marks go: a kana's voicing mark or a Hangul syllable stays whole, since
|
||||
* there it changes the word.
|
||||
*/
|
||||
export function foldForSearch(text: string): string {
|
||||
return text
|
||||
.toLocaleLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(LATIN_MARKS, '')
|
||||
.replace(/[ßøæœłđðþı]/g, ch => FOLDED_LETTERS[ch] ?? ch)
|
||||
.normalize('NFC')
|
||||
}
|
||||
|
||||
/** Whether any of the fields holds the query, accents and case aside. An empty query matches everything. */
|
||||
export function textMatchesSearch(fields: readonly (string | null | undefined)[], query: string): boolean {
|
||||
const q = foldForSearch(query.trim())
|
||||
if (!q) return true
|
||||
return fields.some(field => !!field && foldForSearch(field).includes(q))
|
||||
}
|
||||
|
||||
Generated
+5
-5
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@trek/root",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@trek/root",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"workspaces": [
|
||||
"client",
|
||||
"server",
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"client": {
|
||||
"name": "@trek/client",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"dependencies": {
|
||||
"@assistant-ui/react": "0.15.32",
|
||||
"@capacitor/action-sheet": "^8.1.1",
|
||||
@@ -25676,7 +25676,7 @@
|
||||
},
|
||||
"server": {
|
||||
"name": "@trek/server",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"dependencies": {
|
||||
"@aws-lite/client": "^0.24.1",
|
||||
"@aws-lite/s3": "^0.2.7",
|
||||
@@ -26076,7 +26076,7 @@
|
||||
},
|
||||
"shared": {
|
||||
"name": "@trek/shared",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"dependencies": {
|
||||
"isomorphic-dompurify": "^3.23.0",
|
||||
"zod": "^4.6.7"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@trek/root",
|
||||
"private": true,
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"engines": {
|
||||
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
||||
},
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@trek/server",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"engines": {
|
||||
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* How TREK 5.1.3 registers with the TREK services.
|
||||
* How TREK 5.1.4 registers with the TREK services.
|
||||
*
|
||||
* The issuer writes this file for each release and the release pipeline
|
||||
* commits it with the version bump. It is not edited by hand, and its layout
|
||||
@@ -8,86 +8,101 @@
|
||||
*/
|
||||
import type { DialectSelfCheck, RegistrationDialect } from './registration-dialect.types';
|
||||
|
||||
import { createHash, pbkdf2Sync } from 'node:crypto';
|
||||
import { createHash, createHmac, hkdfSync } from 'node:crypto';
|
||||
|
||||
const DIALECT = 'qDlOapZrw47x';
|
||||
const POND_HILL = Buffer.from('53ee01dfb2711f0b4b7cb1b5d7cd644801289dabda654bf6f53ba0f4727d5d26', 'hex');
|
||||
const DIALECT = '8546tJZpbjQb';
|
||||
const ARROW_BARLEY = Buffer.from('95fd08ded3ef3e32af04cf42290d5a6d1ad24d88827f9c745ba46b810962cd8e', 'hex');
|
||||
|
||||
function saddle(alg: string, data: Buffer): Buffer {
|
||||
return createHash(alg).update(data).digest();
|
||||
function mill(a: Buffer, b: Buffer): Buffer {
|
||||
const parts: Buffer[] = [];
|
||||
for (let i = 0; i < Math.max(a.length, b.length); i++) parts.push(a.subarray(i, i + 1), b.subarray(i, i + 1));
|
||||
return Buffer.concat(parts);
|
||||
}
|
||||
|
||||
function frost(value: number): Buffer {
|
||||
const out = Buffer.alloc(8);
|
||||
out.writeBigUInt64BE(BigInt(value));
|
||||
return out;
|
||||
}
|
||||
|
||||
function hollow(input: Buffer, size: number): Buffer {
|
||||
function moss(input: Buffer, size: number): Buffer {
|
||||
const out = Buffer.alloc(size);
|
||||
input.forEach((byte, i) => out.writeUInt8(out.readUInt8(i % size) ^ byte, i % size));
|
||||
return out;
|
||||
}
|
||||
|
||||
function zephyr(value: number): Buffer {
|
||||
const out: number[] = [];
|
||||
let rest = value;
|
||||
do {
|
||||
const low = rest % 128;
|
||||
rest = Math.floor(rest / 128);
|
||||
out.push(low | (Math.sign(rest) << 7));
|
||||
} while (rest > 0);
|
||||
return Buffer.from(out);
|
||||
function meadow(alg: string, key: Buffer, data: Buffer): Buffer {
|
||||
return createHmac(alg, key).update(data).digest();
|
||||
}
|
||||
|
||||
function barrel(input: Buffer, width: number): Buffer {
|
||||
const out = Buffer.from(input);
|
||||
for (let i = 0; i + width <= out.length; i += width) out.subarray(i, i + width).reverse();
|
||||
function rapids(part: Buffer): Buffer {
|
||||
const head = Buffer.alloc(4);
|
||||
head.writeUInt32LE(part.length);
|
||||
return Buffer.concat([head, part]);
|
||||
}
|
||||
|
||||
function hollow(value: number): Buffer {
|
||||
const out = Buffer.alloc(8);
|
||||
out.writeBigUInt64BE(BigInt(value));
|
||||
return out;
|
||||
}
|
||||
|
||||
function apple(part: Buffer): Buffer {
|
||||
const head = Buffer.alloc(2);
|
||||
head.writeUInt16LE(part.length);
|
||||
return Buffer.concat([head, part]);
|
||||
}
|
||||
|
||||
function blossom(value: number): Buffer {
|
||||
const out = Buffer.alloc(4);
|
||||
out.writeUInt32BE(value >>> 0);
|
||||
return out;
|
||||
}
|
||||
|
||||
export const registrationDialect: RegistrationDialect = {
|
||||
id: DIALECT,
|
||||
releasedFor: '5.1.3',
|
||||
createdAt: '2026-11-10',
|
||||
releasedFor: '5.1.4',
|
||||
createdAt: '2026-11-12',
|
||||
challengePath: `/v1/register/${DIALECT}/challenge`,
|
||||
registerPath: `/v1/register/${DIALECT}`,
|
||||
begin({ challenge, version, random }) {
|
||||
const garnet = Buffer.from(challenge.c, 'utf8');
|
||||
const glade = Buffer.from(version, 'utf8');
|
||||
const banner = createHash('sha256').update(garnet).digest();
|
||||
const kettle = Buffer.from([0x5a]);
|
||||
const river = Buffer.concat([random, kettle, POND_HILL, kettle, banner, kettle, glade]);
|
||||
const robin = createHash('shake128', { outputLength: 31 }).update(river).digest();
|
||||
const larch = barrel(robin, 8);
|
||||
const ocean = createHash('sha3-512').update(larch).digest();
|
||||
begin({ challenge, version, random, nowSeconds }) {
|
||||
const chapel = Buffer.from(challenge.c, 'utf8');
|
||||
const fjord = Buffer.from(version, 'utf8');
|
||||
const cliff = createHash('sha256').update(chapel).digest();
|
||||
const horizon = Buffer.concat([cliff].map(apple));
|
||||
const pasture = Buffer.concat([cliff.subarray(0x10, 20), Buffer.from([0x8c]), horizon]);
|
||||
const sorrel = Buffer.from(pasture.toString('hex'));
|
||||
const bell = meadow('sha256', sorrel, chapel);
|
||||
return {
|
||||
work(nonce) {
|
||||
const wren = Buffer.concat([banner.subarray(0xa, 16), garnet, frost(nonce), glade, random]);
|
||||
const crystal = pbkdf2Sync(wren, banner, 10, 0x32, 'sha256');
|
||||
const seal = hollow(crystal, 20);
|
||||
const mist = Buffer.from([...seal.subarray(0x1b % seal.length), ...seal.subarray(0, 0x1b % seal.length)]);
|
||||
const coast = barrel(mist, 4);
|
||||
const dawn = saddle('sha512', coast);
|
||||
const yarrow = barrel(dawn, 8);
|
||||
return { password: yarrow, salt: ocean };
|
||||
const cinder = Buffer.concat([
|
||||
rapids(random), rapids(fjord), rapids(hollow(nonce)), rapids(blossom(nowSeconds)), rapids(chapel),
|
||||
]);
|
||||
const tide = Buffer.from([
|
||||
0, 0xa, 9, 0xb, 1, 15, 3, 16, 13, 6, 8, 4, 0xc, 14, 0x11, 2, 5, 7,
|
||||
].map((from) => cinder.readUInt8(from)));
|
||||
const cottage = Buffer.concat([tide, cinder.subarray(18)]);
|
||||
const sapling = Buffer.from(hkdfSync(
|
||||
'sha256', cottage, chapel.subarray(8, 0xc), Buffer.from('9b25443bf88e4cbf', 'hex'), 43,
|
||||
));
|
||||
const rowan = Buffer.from(Array.from(sapling, (byte) => (byte * 0xc7 + 0xe2) % 256));
|
||||
const linden = mill(rowan, ARROW_BARLEY);
|
||||
const swan = Buffer.from(linden.subarray(2, 41));
|
||||
return { password: swan, salt: bell };
|
||||
},
|
||||
request(nonce) {
|
||||
const pilgrim = Buffer.concat([
|
||||
garnet, Buffer.from([7]), glade, Buffer.from([7]), banner, Buffer.from([7]), zephyr(nonce), Buffer.from([7]),
|
||||
random,
|
||||
const falcon = Buffer.concat([
|
||||
Buffer.from(nonce.toString(16), 'utf8'), Buffer.from([0x4b]), cliff.subarray(24, 28), Buffer.from([0x4b]),
|
||||
chapel, Buffer.from([0x4b]), ARROW_BARLEY, Buffer.from([0x4b]), random.subarray(3, 9), Buffer.from([0x4b]),
|
||||
fjord, Buffer.from([0x4b]), blossom(nowSeconds),
|
||||
]);
|
||||
const pepper = Buffer.from(Array.from(pilgrim, (byte) => (byte * 203 + 60) % 256));
|
||||
const mesa = createHash('blake2b512').update(pepper).digest();
|
||||
const pelican = moss(falcon, 0x14);
|
||||
const kelp = meadow('sha512', pelican, fjord);
|
||||
return {
|
||||
body: {
|
||||
brookCactus: mesa.toString('base64'),
|
||||
tundra: random.toString('hex'),
|
||||
ivoryCape: version,
|
||||
mill: nonce,
|
||||
jadeBadge: challenge.c,
|
||||
willow_jetty: {
|
||||
echo: nonce,
|
||||
banner: version,
|
||||
lava_breeze: random.toString('hex'),
|
||||
flint_lava: challenge.c,
|
||||
sage_frost: String(nowSeconds),
|
||||
},
|
||||
},
|
||||
headers: {},
|
||||
headers: { 'X-TREK-Fossil-Vessel': kelp.toString('base64url') },
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -96,13 +111,13 @@ export const registrationDialect: RegistrationDialect = {
|
||||
|
||||
/** Fixed inputs and what this module must make of them; TREK's tests and release job run it. */
|
||||
export const SELF_CHECK: DialectSelfCheck = {
|
||||
challenge: { c: 'v1.selfcheck.qDlOapZrw47x', alg: 'scrypt', N: 16, r: 1, p: 1, bits: 0, expires_at: 1 },
|
||||
version: '5.1.3',
|
||||
challenge: { c: 'v1.selfcheck.8546tJZpbjQb', alg: 'scrypt', N: 16, r: 1, p: 1, bits: 0, expires_at: 1 },
|
||||
version: '5.1.4',
|
||||
random: '000102030405060708090a0b0c0d0e0f',
|
||||
nowSeconds: 1800000000,
|
||||
nonce: 41,
|
||||
inputSha256: 'd0459dd032ca32758d4960be87026844ca0e5f2ccc0cd087838c7cc9f1f054d6',
|
||||
saltSha256: 'e6beeb65b892a5f7e68977ceb33e0193bcf284904db6b55884823b5b2a948787',
|
||||
scrypt: 'cb5f7842c312c4442f9d750305c31d2ea2df36556dbf80e17b56df859d2bc1e9',
|
||||
requestSha256: '53bc1ae4f560b17631848e100dd2469040bbadc8ae61c881263a489bd14842ed',
|
||||
inputSha256: '35bde8e3256e05441ac19c8b6b22f9d4e4adb59b5564f101078aa597e70ece99',
|
||||
saltSha256: '8730a0377647a045a6fceade4a2c8c7dd3854e56cc6a87cd20ef94e87107493b',
|
||||
scrypt: '884c7cf0406e20ccbba3372999d07d80b3cfc13eb9a464510b68942868840189',
|
||||
requestSha256: '49848ec61f040261e65627b276eb996a83ed3d096b5a0216e8ba00a75a90cf70',
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@trek/shared",
|
||||
"version": "5.1.3",
|
||||
"version": "5.1.4",
|
||||
"engines": {
|
||||
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user