mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
df3edac7b9
* fix(places): match imports on the provider id so renamed places are not duplicated Re-importing a Google Maps list duplicated every place the user had renamed. buildDedupSet only ever collected names and, for unnamed places, coordinates, and isPlaceDuplicate returns on the name before it reaches the coordinate fallback, so a renamed place was findable by neither. The ids were stored all along, and even backfilled onto matched places, they were simply never read. Match on google_place_id / google_ftid / osm_id first, keeping name and coordinates in their old roles below it. Widening the coordinate check instead would have merged the restaurant and the bar in the same building. The collection copy carried a hand-mirrored port of the same predicate; it now uses the shared helpers and gets the fix with them. Closes #1550 * feat(calendar): put accommodations into the subscribed feed as all-day stays A hotel keeps its dates on the linked stay, not on the reservation: the booking form writes reservation_time = NULL for type 'hotel', and day_accommodations carries start day, end day and the check-in/out clock. The feed only ever read the reservation, so a stay showed up once on the arrival day at best, and not at all when it came from the booking form. Join the stay in and emit the reservation as an all-day range over every night, which also keeps it correct when days are reordered later — the dates now come from the day rows rather than from the copy stamped at creation time. Check-in and check-out become their own timed events when the stay records a clock, because an all-day event cannot carry the time you actually need reminding of. The check-in window, when set, becomes that event's DTEND. Closes #1586 * fix(oauth): treat a concurrent refresh as a race, not as a stolen token Refresh rotation is a race by construction. Several MCP clients share one refresh token, both post it within the same second, and the loser was read as a replay: chain revoked, MCP sessions torn down, browser window asking to log in again. That is the daily re-authentication people were seeing, not a short lifetime — access tokens last an hour and refresh tokens roll for thirty days. A revoked refresh token now only counts as a replay once it is outside a 30-second grace window, and only when the rotation that revoked it left a successor still alive. Inside the window the caller gets its own pair branched off the same parent, so both clients walk away with a working token. Explicit revocation leaves no live successor and a chain killed by a real replay has none either, so neither can slip through the window. Closes #1007 * feat(collections): mark a place visited from the trip it belongs to A place saved in several lists had to be opened in each of them to say you had been there, which is the wrong way round: you find out you have been somewhere while looking at the trip, not while browsing the library. The save picker now shows each list's own status and cycles it in place, with one action for "visited, wherever this is saved". The planner's selection bar and the mobile bulk toolbar carry the same thing for a whole selection — select all, one tap, done. Matching happens on the server with the signals findMembership already uses plus the source link a place saved from this trip carries, so a copy renamed inside a list is still found. Lists you may only read are skipped rather than refused; a shared list you cannot edit should not stop you marking your own. Closes #1469 * feat(journey): jump to the top or back to the last entry in a long journal Everything that adds to a journal sits at the top — the entry button, the gallery upload — and where you left off sits at the bottom, so adding one photo to a long journey meant scrolling the whole way twice. Two buttons float over the middle of the feed, clear of the Add Entry column on one side and the reorder arrows on the other, each appearing only when there is more than a screenful to travel in that direction. They live in a zero-height sticky box so they take no layout space and never push the timeline around. While in the header, the status pill also picks up the height of the round buttons beside it. Closes #1088 * fix(packing): give the item name the row back on phones An item name had roughly a third of the row to itself: a spelled-out sharing sentence, an empty weight column and two round action buttons took the rest, so anything longer than a word was cut off. Sharing is now the icon it always was next to a label rather than a sentence in the layout, an unset weight prints nothing instead of a dash, and edit/delete sit behind one overflow button that opens the same inline menu the bag picker already uses. The to-do list needed none of this — it wraps its chips onto a second line already. Closes #1525 * docs(wiki): cover the six community changes - Calendar feeds: accommodations as an all-day range plus check-in/check-out - Collections: setting the visited status from a trip, and how places are matched - Journey: the jump buttons on a long journal - Packing: what the phone row keeps and what moved behind the overflow button - Places: re-importing a list no longer duplicates renamed places - MCP setup: the rotation race no longer ends an OAuth session * test(collections): assert the stored status instead of a private method tests/ sits outside the build tsconfig, so reaching into getPlaceById only showed up in the dedicated typecheck step. Reading the row is the better assertion anyway — it pins what was persisted, not what a getter returns.
127 lines
7.7 KiB
TypeScript
127 lines
7.7 KiB
TypeScript
import apiClient, { postMultipart } from './client'
|
|
import type { AxiosResponse } from 'axios'
|
|
import type {
|
|
CollectionListResponse,
|
|
CollectionDetailResponse,
|
|
CollectionSaveResult,
|
|
CollectionMembership,
|
|
CollectionCreateRequest,
|
|
CollectionUpdateRequest,
|
|
CollectionSavePlaceRequest,
|
|
CollectionSaveFromTripRequest,
|
|
CollectionImportablesResponse,
|
|
CollectionPlaceUpdateRequest,
|
|
CollectionCopyToTripRequest,
|
|
CollectionInviteRequest,
|
|
CollectionRole,
|
|
CollectionInviteActionRequest,
|
|
CollectionInviteCancelRequest,
|
|
CollectionStatus,
|
|
CollectionSetStatusManyResponse,
|
|
Collection,
|
|
CollectionPlace,
|
|
CollectionLabel,
|
|
CollectionLabelCreateRequest,
|
|
CollectionLabelUpdateRequest,
|
|
} from '@trek/shared'
|
|
|
|
const ax = apiClient
|
|
const base = '/addons/collections'
|
|
|
|
/** Query for the library-wide "is this place already saved?" lookup. */
|
|
export interface MembershipQuery {
|
|
google_place_id?: string
|
|
google_ftid?: string
|
|
name?: string
|
|
lat?: number
|
|
lng?: number
|
|
}
|
|
|
|
export interface CopyToTripResult {
|
|
copied: number
|
|
skipped: { id: number; name: string }[]
|
|
}
|
|
|
|
/**
|
|
* Axios calls for the Collections addon (/api/addons/collections). Mirrors the
|
|
* vacayStore api shape — each method returns the unwrapped response body and
|
|
* uses `satisfies` on the request payloads so the shared Zod request types stay
|
|
* the single source of truth.
|
|
*/
|
|
export const collectionsApi = {
|
|
list: (): Promise<CollectionListResponse> =>
|
|
ax.get(base).then((r: AxiosResponse) => r.data),
|
|
get: (id: number): Promise<CollectionDetailResponse> =>
|
|
ax.get(`${base}/${id}`).then((r: AxiosResponse) => r.data),
|
|
create: (body: CollectionCreateRequest): Promise<{ collection: Collection }> =>
|
|
ax.post(base, body satisfies CollectionCreateRequest).then((r: AxiosResponse) => r.data),
|
|
update: (id: number, body: CollectionUpdateRequest): Promise<{ collection: Collection }> =>
|
|
ax.patch(`${base}/${id}`, body satisfies CollectionUpdateRequest).then((r: AxiosResponse) => r.data),
|
|
uploadCover: (id: number, formData: FormData): Promise<Collection> =>
|
|
postMultipart(`${base}/${id}/cover`, formData),
|
|
remove: (id: number): Promise<unknown> =>
|
|
ax.delete(`${base}/${id}`).then((r: AxiosResponse) => r.data),
|
|
reorder: (orderedIds: number[]): Promise<unknown> =>
|
|
ax.post(`${base}/reorder`, { orderedIds }).then((r: AxiosResponse) => r.data),
|
|
|
|
savePlace: (body: CollectionSavePlaceRequest): Promise<CollectionSaveResult> =>
|
|
ax.post(`${base}/places`, body satisfies CollectionSavePlaceRequest).then((r: AxiosResponse) => r.data),
|
|
saveFromTrip: (body: CollectionSaveFromTripRequest): Promise<CollectionSaveResult> =>
|
|
ax.post(`${base}/places/from-trip`, body satisfies CollectionSaveFromTripRequest).then((r: AxiosResponse) => r.data),
|
|
saveFromTripMany: (collectionId: number, tripId: number, placeIds: number[], force?: boolean): Promise<{ copied: number; skipped: { id: number; name: string }[] }> =>
|
|
ax.post(`${base}/places/from-trip-many`, { collection_id: collectionId, source_trip_id: tripId, source_place_ids: placeIds, force }).then((r: AxiosResponse) => r.data),
|
|
importable: (collectionId: number, tripId: number): Promise<CollectionImportablesResponse> =>
|
|
ax.get(`${base}/${collectionId}/importable/${tripId}`).then((r: AxiosResponse) => r.data),
|
|
updatePlace: (pid: number, body: CollectionPlaceUpdateRequest): Promise<CollectionPlace> =>
|
|
ax.patch(`${base}/places/${pid}`, body satisfies CollectionPlaceUpdateRequest).then((r: AxiosResponse) => r.data),
|
|
uploadPlaceImage: (pid: number, formData: FormData): Promise<CollectionPlace> =>
|
|
postMultipart(`${base}/places/${pid}/image`, formData),
|
|
setStatus: (pid: number, status: CollectionStatus): Promise<CollectionPlace> =>
|
|
ax.post(`${base}/places/${pid}/status`, { status }).then((r: AxiosResponse) => r.data),
|
|
setStatusMany: (ids: number[], status: CollectionStatus): Promise<CollectionSetStatusManyResponse> =>
|
|
ax.post(`${base}/places/status-many`, { ids, status }).then((r: AxiosResponse) => r.data),
|
|
setStatusFromTrip: (tripId: number, placeIds: number[], status: CollectionStatus): Promise<CollectionSetStatusManyResponse> =>
|
|
ax.post(`${base}/places/status-from-trip`, { trip_id: tripId, place_ids: placeIds, status }).then((r: AxiosResponse) => r.data),
|
|
ratePlace: (pid: number, rating: number | null): Promise<CollectionPlace> =>
|
|
rating === null
|
|
? ax.delete(`${base}/places/${pid}/rating`).then((r: AxiosResponse) => r.data)
|
|
: ax.put(`${base}/places/${pid}/rating`, { rating }).then((r: AxiosResponse) => r.data),
|
|
deletePlace: (pid: number): Promise<unknown> =>
|
|
ax.delete(`${base}/places/${pid}`).then((r: AxiosResponse) => r.data),
|
|
deleteMany: (ids: number[]): Promise<unknown> =>
|
|
ax.post(`${base}/places/delete-many`, { ids }).then((r: AxiosResponse) => r.data),
|
|
|
|
copyToTrip: (body: CollectionCopyToTripRequest): Promise<CopyToTripResult> =>
|
|
ax.post(`${base}/copy-to-trip`, body satisfies CollectionCopyToTripRequest).then((r: AxiosResponse) => r.data),
|
|
membership: (params: MembershipQuery): Promise<CollectionMembership> =>
|
|
ax.get(`${base}/membership`, { params }).then((r: AxiosResponse) => r.data),
|
|
|
|
invite: (collectionId: number, userId: number, role?: CollectionRole): Promise<unknown> =>
|
|
ax.post(`${base}/invite`, { collection_id: collectionId, user_id: userId, role } satisfies CollectionInviteRequest).then((r: AxiosResponse) => r.data),
|
|
setMemberRole: (collectionId: number, userId: number, role: CollectionRole): Promise<unknown> =>
|
|
ax.post(`${base}/members/role`, { collection_id: collectionId, user_id: userId, role }).then((r: AxiosResponse) => r.data),
|
|
acceptInvite: (collectionId: number): Promise<unknown> =>
|
|
ax.post(`${base}/invite/accept`, { collection_id: collectionId } satisfies CollectionInviteActionRequest).then((r: AxiosResponse) => r.data),
|
|
declineInvite: (collectionId: number): Promise<unknown> =>
|
|
ax.post(`${base}/invite/decline`, { collection_id: collectionId } satisfies CollectionInviteActionRequest).then((r: AxiosResponse) => r.data),
|
|
cancelInvite: (collectionId: number, userId: number): Promise<unknown> =>
|
|
ax.post(`${base}/invite/cancel`, { collection_id: collectionId, user_id: userId } satisfies CollectionInviteCancelRequest).then((r: AxiosResponse) => r.data),
|
|
leave: (collectionId: number): Promise<unknown> =>
|
|
ax.post(`${base}/leave`, { collection_id: collectionId }).then((r: AxiosResponse) => r.data),
|
|
removeMember: (collectionId: number, userId: number): Promise<unknown> =>
|
|
ax.post(`${base}/members/remove`, { collection_id: collectionId, user_id: userId }).then((r: AxiosResponse) => r.data),
|
|
availableUsers: (id: number): Promise<{ users: { id: number; username: string }[] }> =>
|
|
ax.get(`${base}/${id}/available-users`).then((r: AxiosResponse) => r.data),
|
|
|
|
createLabel: (collectionId: number, name: string, color?: string): Promise<CollectionLabel> =>
|
|
ax.post(`${base}/labels`, { collection_id: collectionId, name, color } satisfies CollectionLabelCreateRequest).then((r: AxiosResponse) => r.data),
|
|
updateLabel: (labelId: number, body: CollectionLabelUpdateRequest): Promise<CollectionLabel> =>
|
|
ax.patch(`${base}/labels/${labelId}`, body satisfies CollectionLabelUpdateRequest).then((r: AxiosResponse) => r.data),
|
|
deleteLabel: (labelId: number): Promise<unknown> =>
|
|
ax.delete(`${base}/labels/${labelId}`).then((r: AxiosResponse) => r.data),
|
|
assignLabels: (labelIds: number[], placeIds: number[]): Promise<{ changed: number }> =>
|
|
ax.post(`${base}/labels/assign`, { label_ids: labelIds, place_ids: placeIds }).then((r: AxiosResponse) => r.data),
|
|
unassignLabels: (labelIds: number[], placeIds: number[]): Promise<{ changed: number }> =>
|
|
ax.post(`${base}/labels/unassign`, { label_ids: labelIds, place_ids: placeIds }).then((r: AxiosResponse) => r.data),
|
|
}
|