mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
2e1dca9fe9
Settings, Integrations, wanderer gains an optional background check of the trails you imported, off until you switch it on. While on, TREK reads the short record of each such trail at most once a day (never its GPX file) and leaves a hint when the trail may have moved on: "may have changed" when only wanderer's change time moved, "changed" when its name or description proves it, and "not checkable" when the trail is gone, no longer yours or carries no change time. Nothing is ever said to be unchanged. A new hint arrives as a notification that opens the tour (a new ?place= link in the planner); the tour's provenance shows it with the source check right beside it, and the card lists all open hints in a dialog, each leading to its tour. The check reads the source in full as before and spends the hint; taking a change in stays the confirmed reimport. No tour is ever changed or deleted. The check only asks through your own connection, only about trails your account imported into trips you can still open, and stops when you switch it off, remove the connection, wanderer refuses the token (until a test passes or a new token is saved) or the admin switches wanderer off; hints and snapshots stay. A run asks at most 25 connections for at most 10 records each, one after another, and an instance that fails (an outage, a rate limit) is left alone for an hour, doubling up to two days. Server: migration 046120 adds the switch and the run bookkeeping to wanderer_connections and the tour_source_hints table (one row per snapshot, for its importer, gone with it). WandererWatchService and an hourly wanderer-watch job on the CronRegistrar live in the tours domain and read through WandererService; GET and PUT /api/integrations/wanderer/watch and GET /api/trips/:tripId/tours/wanderer/sources/:placeId/hint (place_edit, like the check) answer with @trek/shared contracts. A new user notification event, wanderer_source_hint, can be muted per channel. Saving a new token now clears what the last check said about the old one. There is no MCP tool, as for the rest of the personal wanderer connection. All 27 locales carry the strings, and the admin wiki page says what the check does.
89 lines
3.9 KiB
TypeScript
89 lines
3.9 KiB
TypeScript
import { idSchema } from '../common/primitives.schema';
|
|
|
|
import { z } from 'zod';
|
|
|
|
/**
|
|
* WAN-02: the optional background watch over a user's own wanderer snapshots.
|
|
*
|
|
* Off until the user switches it on for their personal connection. While on,
|
|
* the server now and then reads the small record of each trail the user
|
|
* imported (never its GPX) and leaves a hint where the record suggests the
|
|
* trail moved on. A hint only ever points at the manual check of the source
|
|
* (MF-03) and from there at the confirmed reimport: nothing here changes,
|
|
* replaces or deletes a tour, and no answer is ever read as "unchanged".
|
|
*/
|
|
|
|
/**
|
|
* What the watch found about one snapshot's source.
|
|
*
|
|
* - `possible_change`: the trail's change time moved since the user last saw
|
|
* it. A time is no proof of content, so only the manual check can tell.
|
|
* - `changed`: the trail's record itself differs in its name or description,
|
|
* which the record alone proves. Its line may differ too; that again only
|
|
* the manual check reads.
|
|
* - `unverifiable`: the watch could not judge the source, see the reason.
|
|
*/
|
|
export const tourSourceHintStateSchema = z.enum(['possible_change', 'changed', 'unverifiable']);
|
|
export type TourSourceHintState = z.infer<typeof tourSourceHintStateSchema>;
|
|
|
|
/**
|
|
* Why a source could not be judged: the trail is gone or no longer the
|
|
* user's own to read, or neither the import nor the trail carries a change
|
|
* time to compare.
|
|
*/
|
|
export const tourSourceHintReasonSchema = z.enum(['unavailable', 'no_change_time']);
|
|
export type TourSourceHintReason = z.infer<typeof tourSourceHintReasonSchema>;
|
|
|
|
/** The parts of a trail its record alone can prove changed; the line needs the manual check. */
|
|
export const tourSourceHintChangeSchema = z.enum(['name', 'description']);
|
|
export type TourSourceHintChange = z.infer<typeof tourSourceHintChangeSchema>;
|
|
|
|
export const tourSourceHintSchema = z.object({
|
|
state: tourSourceHintStateSchema,
|
|
/** For `changed`: what the record proves different. Empty for the other states. */
|
|
changes: z.array(tourSourceHintChangeSchema),
|
|
/** For `unverifiable`: why. Null for the other states. */
|
|
reason: tourSourceHintReasonSchema.nullable(),
|
|
/** The trail's change time as wanderer said it at the look; a hint, never a proof. */
|
|
externalUpdated: z.string().nullable(),
|
|
/** When the watch last looked at this source. */
|
|
checkedAt: z.string(),
|
|
});
|
|
export type TourSourceHint = z.infer<typeof tourSourceHintSchema>;
|
|
|
|
/** The caller's own hint on one snapshot of a trip; null when there is none. */
|
|
export const tourSourceHintResponseSchema = z.object({
|
|
hint: tourSourceHintSchema.nullable(),
|
|
});
|
|
export type TourSourceHintResponse = z.infer<typeof tourSourceHintResponseSchema>;
|
|
|
|
/** A hint as the settings list shows it: with the tour and the trip it belongs to. */
|
|
export const wandererSourceHintItemSchema = tourSourceHintSchema.extend({
|
|
placeId: idSchema,
|
|
tripId: idSchema,
|
|
tripTitle: z.string(),
|
|
tourName: z.string(),
|
|
});
|
|
export type WandererSourceHintItem = z.infer<typeof wandererSourceHintItemSchema>;
|
|
|
|
export const wandererWatchSchema = z.object({
|
|
/** The user switched the watch on for their connection. */
|
|
enabled: z.boolean(),
|
|
/** There is a connection to watch with; without one the switch has nothing to act on. */
|
|
connected: z.boolean(),
|
|
/** When the watch last finished a look through this connection. */
|
|
lastRunAt: z.string().nullable(),
|
|
/** After failed looks the watch waits until then before it asks the instance again. */
|
|
pausedUntil: z.string().nullable(),
|
|
/** wanderer refused the token: nothing is asked until a test of the connection passes again. */
|
|
blocked: z.boolean(),
|
|
/** The open hints, newest look first. */
|
|
hints: z.array(wandererSourceHintItemSchema),
|
|
});
|
|
export type WandererWatch = z.infer<typeof wandererWatchSchema>;
|
|
|
|
export const wandererWatchRequestSchema = z.object({
|
|
enabled: z.boolean(),
|
|
});
|
|
export type WandererWatchRequest = z.infer<typeof wandererWatchRequestSchema>;
|