@forgeroute/ui 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"forgeroute-ui-offline.mjs","names":[],"sources":["../../../projects/forgeroute-ui/offline/src/config/offline-config.ts","../../../projects/forgeroute-ui/offline/src/config/uuid.ts","../../../projects/forgeroute-ui/offline/src/state/connection-state.service.ts","../../../projects/forgeroute-ui/offline/src/state/stale-data.service.ts","../../../projects/forgeroute-ui/offline/src/store/offline-store.ts","../../../projects/forgeroute-ui/offline/src/http/errors.ts","../../../projects/forgeroute-ui/offline/src/store/temp-ids.ts","../../../projects/forgeroute-ui/offline/src/replay/offline-replayer.ts","../../../projects/forgeroute-ui/offline/src/http/request-timeout.ts","../../../projects/forgeroute-ui/offline/src/http/idempotency.interceptor.ts","../../../projects/forgeroute-ui/offline/src/http/connection.interceptor.ts","../../../projects/forgeroute-ui/offline/src/support/offline-support.service.ts","../../../projects/forgeroute-ui/offline/src/http/offline.interceptor.ts","../../../projects/forgeroute-ui/offline/src/http/offline-http-interceptors.ts","../../../projects/forgeroute-ui/offline/src/notes/offline-notes-queue.ts","../../../projects/forgeroute-ui/offline/src/support/provide-offline-support.ts","../../../projects/forgeroute-ui/offline/src/ui/connection-banner/connection-banner.component.ts","../../../projects/forgeroute-ui/offline/src/ui/relative-time.ts","../../../projects/forgeroute-ui/offline/src/ui/pending-changes-drawer/pending-changes-drawer.component.ts","../../../projects/forgeroute-ui/offline/src/ui/stale-data-chip/stale-data-chip.component.ts","../../../projects/forgeroute-ui/offline/src/ui/still-working/still-working.component.ts"],"sourcesContent":["import { InjectionToken, Injector } from '@angular/core';\nimport type { OfflineMutation } from '../store/offline-store';\n\n/** string = path prefix or substring after the origin is stripped; RegExp is tested on path + query. */\nexport type UrlMatcher = string | RegExp;\n\n/**\n * What a {@link QueueRule.label} callback receives as its 4th argument: the app's injector, so the label can read app services (the signed-in company's\n * user type, a language service ...) with `ctx.injector.get(Token)` or `runInInjectionContext(ctx.injector, () => inject(Token))`. It is the injector of the\n * HTTP request being queued; the callback runs synchronously while the change is being queued.\n */\nexport interface QueueLabelContext {\n readonly injector: Injector;\n}\n\nexport interface QueueRule {\n pattern: RegExp;\n methods: readonly string[];\n /**\n * Plain-words name of the change shown in the pending-changes list (e.g. \"Add lot 12\"). A callback that takes only (method, url, body) keeps working\n * unchanged; the optional 4th argument is a {@link QueueLabelContext} for labels that need app state.\n */\n label?: (method: string, url: string, body: unknown, ctx: QueueLabelContext) => string;\n entityType?: (url: string) => string | undefined;\n}\n\nexport interface OfflineSupportConfig {\n /** Only URLs containing this are intercepted. Default '/api/'. */\n apiPrefix?: string;\n /** Never touched (auth, public, uploads...). */\n skip?: readonly UrlMatcher[];\n /** The signed-in user's id; null = nobody (nothing is queued/cached). Scopes the store. */\n getUserId: () => string | null;\n /** ALLOW-LIST mode: only requests matching a rule may be queued offline. Omit for BLOCK-LIST mode (everything may be queued except `blockOffline`). */\n allowQueue?: readonly QueueRule[];\n /** Writes that must NEVER be queued (payments, sends...). While offline/unreachable they fail with OfflineBlockedError. */\n blockOffline?: readonly { pattern: UrlMatcher; message?: string }[];\n /** GET endpoints that must never be stored or served from the device copy. */\n neverCache?: readonly UrlMatcher[];\n /** Safe extra headers copied onto the queued row and re-sent on replay (never Authorization). */\n replayHeaders?: readonly string[];\n /** Cheap authenticated/unauthenticated GET used ONLY while the connection is suspect. null/omitted = no probe. */\n probe?: { url: string; intervalMs?: number /* default 15000 */ } | null;\n /** Client timeouts in ms. Defaults: read 30000, write 60000, long 180000. `long` applies to blob/arraybuffer, FormData, and matchers in `longRequests`. */\n timeouts?: { read?: number; write?: number; long?: number };\n longRequests?: readonly UrlMatcher[];\n /** Slow detection thresholds. Defaults: slowMs 5000, slowCount 2 within windowMs 60000; single in-flight > stuckMs 8000; recover after quietMs 30000 of fast requests. */\n slow?: { slowMs?: number; slowCount?: number; windowMs?: number; stuckMs?: number; quietMs?: number };\n /** IndexedDB database name. Default 'forgeroute-offline'. */\n dbName?: string;\n /** Cache TTLs in ms (default 10 min lists / 30 min details); `ttl(url)` overrides. */\n cacheTtl?: (url: string) => number;\n maxQueue?: number; // default 500\n maxAttempts?: number; // default 5\n /**\n * Reads the id the server gave a record that was created offline, from the 2xx answer of the replayed POST (`body` is the parsed JSON answer,\n * `undefined` when the answer was empty / not JSON). Used to rewrite later saved changes that point at the client-made temporary id.\n * Default: `body.id`, else `body.data.id`; a string or a finite number. Return `undefined` when the answer has no id (dependent changes then fail\n * with kind `dependency` instead of being sent with a wrong id).\n */\n createdId?: (body: unknown, row: OfflineMutation) => string | number | undefined;\n /**\n * Names of top-level JSON body fields that carry the \"record as the editor loaded it\" stamp (e.g. `expectedUpdatedAt`). Default `[]` = the\n * \"Keep my version\" feature is OFF. When a replayed change gets 409 the row becomes `conflict`; `OfflineSupportService.keepMine(rowId)` then removes\n * these fields from the stored body (so the server no longer compares) and sends the change again: last write wins, by the user's explicit choice.\n */\n conflictStampFields?: string[];\n /**\n * The `code` the backend puts in the JSON body of its 409 \"this request is already being processed\" answer (the first copy of the same\n * Idempotency-Key is still running). Such a 409 is NOT a conflict: the row stays pending and is sent again later (back-off, or the `Retry-After`\n * header when present). Default `IDEMPOTENCY_IN_PROGRESS_CODE` (`'IDEMPOTENCY_IN_PROGRESS'`).\n */\n idempotencyInProgressCode?: string;\n}\n\n/** Default `code` of the backend's \"same request still running\" 409 (see `OfflineSupportConfig.idempotencyInProgressCode`). */\nexport const IDEMPOTENCY_IN_PROGRESS_CODE = 'IDEMPOTENCY_IN_PROGRESS';\n\nexport const OFFLINE_SUPPORT_CONFIG = new InjectionToken<OfflineSupportConfig>('OFFLINE_SUPPORT_CONFIG');\n\n/** Header the replayer sets on every replayed request; the idempotency and offline interceptors let such requests through untouched. */\nexport const OFFLINE_REPLAY_HEADER = 'X-Offline-Replay';\nexport const IDEMPOTENCY_HEADER = 'Idempotency-Key';\n/** Response header on an answer served from the device copy; the value is the `cachedAt` time in ms. */\nexport const FROM_CACHE_HEADER = 'X-From-Offline-Cache';\n\nexport interface ResolvedSlowConfig { slowMs: number; slowCount: number; windowMs: number; stuckMs: number; quietMs: number }\n\n/** The config with every default filled in. */\nexport interface ResolvedOfflineConfig {\n apiPrefix: string;\n skip: readonly UrlMatcher[];\n getUserId: () => string | null;\n allowQueue: readonly QueueRule[] | null;\n blockOffline: readonly { pattern: UrlMatcher; message?: string }[];\n neverCache: readonly UrlMatcher[];\n replayHeaders: readonly string[];\n probe: { url: string; intervalMs: number } | null;\n timeouts: { read: number; write: number; long: number };\n longRequests: readonly UrlMatcher[];\n slow: ResolvedSlowConfig;\n dbName: string;\n cacheTtl: ((url: string) => number) | null;\n maxQueue: number;\n maxAttempts: number;\n createdId: (body: unknown, row: OfflineMutation) => string | number | undefined;\n conflictStampFields: readonly string[];\n idempotencyInProgressCode: string;\n}\n\nfunction usableId(v: unknown): string | number | undefined {\n if (typeof v === 'string') return v.trim() === '' ? undefined : v;\n if (typeof v === 'number' && Number.isFinite(v)) return v;\n return undefined;\n}\n\n/** Default for `createdId`: `body.id`, else `body.data.id` (string or finite number), otherwise undefined. */\nexport function defaultCreatedId(body: unknown): string | number | undefined {\n if (body === null || typeof body !== 'object') return undefined;\n const b = body as { id?: unknown; data?: unknown };\n const direct = usableId(b.id);\n if (direct !== undefined) return direct;\n const data = b.data;\n return data !== null && typeof data === 'object' ? usableId((data as { id?: unknown }).id) : undefined;\n}\n\n/** Wraps an app-supplied `createdId` so that it can never throw and never return something that is not a usable id. */\nfunction safeCreatedId(fn: NonNullable<OfflineSupportConfig['createdId']>): ResolvedOfflineConfig['createdId'] {\n return (body, row) => {\n try { return usableId(fn(body, row)); } catch { return undefined; }\n };\n}\n\nexport const DEFAULT_LIST_TTL_MS = 10 * 60 * 1000;\nexport const DEFAULT_DETAIL_TTL_MS = 30 * 60 * 1000;\n\nfunction positive(value: number | undefined, fallback: number): number {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;\n}\n\nexport function resolveConfig(cfg: OfflineSupportConfig): ResolvedOfflineConfig {\n return {\n apiPrefix: cfg.apiPrefix || '/api/',\n skip: cfg.skip ?? [],\n getUserId: cfg.getUserId,\n allowQueue: cfg.allowQueue ?? null,\n blockOffline: cfg.blockOffline ?? [],\n neverCache: cfg.neverCache ?? [],\n replayHeaders: cfg.replayHeaders ?? [],\n probe: cfg.probe && cfg.probe.url ? { url: cfg.probe.url, intervalMs: positive(cfg.probe.intervalMs, 15000) } : null,\n timeouts: {\n read: positive(cfg.timeouts?.read, 30000),\n write: positive(cfg.timeouts?.write, 60000),\n long: positive(cfg.timeouts?.long, 180000),\n },\n longRequests: cfg.longRequests ?? [],\n slow: {\n slowMs: positive(cfg.slow?.slowMs, 5000),\n slowCount: positive(cfg.slow?.slowCount, 2),\n windowMs: positive(cfg.slow?.windowMs, 60000),\n stuckMs: positive(cfg.slow?.stuckMs, 8000),\n quietMs: positive(cfg.slow?.quietMs, 30000),\n },\n dbName: cfg.dbName || 'forgeroute-offline',\n cacheTtl: cfg.cacheTtl ?? null,\n maxQueue: positive(cfg.maxQueue, 500),\n maxAttempts: positive(cfg.maxAttempts, 5),\n createdId: cfg.createdId ? safeCreatedId(cfg.createdId) : defaultCreatedId,\n conflictStampFields: Array.isArray(cfg.conflictStampFields)\n ? [...new Set(cfg.conflictStampFields.filter(f => typeof f === 'string' && f.trim() !== ''))]\n : [],\n idempotencyInProgressCode: typeof cfg.idempotencyInProgressCode === 'string' && cfg.idempotencyInProgressCode.trim() !== '' ? cfg.idempotencyInProgressCode.trim() : IDEMPOTENCY_IN_PROGRESS_CODE,\n };\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n if (v === null || typeof v !== 'object' || Array.isArray(v)) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\n/** The stored body as a JSON object: an object as it is, or a string that parses to a JSON object; otherwise null (absent, form text, array, number...). */\nfunction jsonObjectBody(body: unknown): { obj: Record<string, unknown>; wasString: boolean } | null {\n if (isPlainObject(body)) return { obj: body, wasString: false };\n if (typeof body === 'string') {\n try {\n const parsed: unknown = JSON.parse(body);\n return isPlainObject(parsed) ? { obj: parsed, wasString: true } : null;\n } catch {\n return null;\n }\n }\n return null;\n}\n\n/** True when the body is a JSON object that has at least one of the `fields` as a top-level key. */\nexport function hasStampField(body: unknown, fields: readonly string[]): boolean {\n const j = jsonObjectBody(body);\n return !!j && fields.some(f => Object.prototype.hasOwnProperty.call(j.obj, f));\n}\n\n/** The body without the `fields` (top-level only; every other field is kept as it is). A body that is not a JSON object is returned unchanged. */\nexport function stripStampFields(body: unknown, fields: readonly string[]): unknown {\n const j = jsonObjectBody(body);\n if (!j || !fields.some(f => Object.prototype.hasOwnProperty.call(j.obj, f))) return body;\n const copy: Record<string, unknown> = {};\n for (const k of Object.keys(j.obj)) if (!fields.includes(k)) copy[k] = j.obj[k];\n return j.wasString ? JSON.stringify(copy) : copy;\n}\n\n/** Path + query of a URL with the origin removed ('https://x.test/api/a?b=1' -> '/api/a?b=1'). Relative URLs are returned as they are. */\nexport function pathAndQuery(url: string): string {\n const m = /^[a-z][a-z0-9+.-]*:\\/\\/[^/?#]+(.*)$/i.exec(url);\n const rest = m ? m[1] : url;\n const noHash = rest.split('#')[0];\n return noHash === '' ? '/' : noHash;\n}\n\n/** Path only (no query) of a URL with the origin removed. */\nexport function pathOnly(url: string): string {\n return pathAndQuery(url).split('?')[0];\n}\n\n/** True when `matcher` matches `url`: a string anywhere in the path + query, a RegExp tested on path + query (a global/sticky RegExp is not made stateful). */\nexport function matchesUrl(url: string, matcher: UrlMatcher): boolean {\n const target = pathAndQuery(url);\n if (typeof matcher === 'string') return matcher !== '' && target.includes(matcher);\n matcher.lastIndex = 0;\n const hit = matcher.test(target);\n matcher.lastIndex = 0;\n return hit;\n}\n\nexport function matchesAny(url: string, matchers: readonly UrlMatcher[]): boolean {\n return matchers.some(m => matchesUrl(url, m));\n}\n\nexport function isMutationMethod(method: string): boolean {\n const m = method.toUpperCase();\n return m === 'POST' || m === 'PUT' || m === 'PATCH' || m === 'DELETE';\n}\n\nconst ID_SEGMENT = /^(?:\\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;\n\n/** First id-looking path segment (digits or UUID) with the segment before it as the entity type: '/api/lots/42/notes' -> { entityType: 'lots', entityId: '42' }. */\nexport function deriveEntity(url: string): { entityType?: string; entityId?: string } {\n const segments = pathOnly(url).split('/').filter(Boolean);\n for (let i = 1; i < segments.length; i++) {\n if (ID_SEGMENT.test(segments[i])) return { entityType: segments[i - 1], entityId: segments[i] };\n }\n return {};\n}\n\n/** The path prefix whose stored GET copies a successful write may have made stale: the path without trailing id segments ('/api/contacts/12' -> '/api/contacts'). */\nexport function invalidationPrefix(url: string): string {\n const segments = pathOnly(url).split('/').filter(Boolean);\n while (segments.length > 1 && ID_SEGMENT.test(segments[segments.length - 1])) segments.pop();\n return '/' + segments.join('/');\n}\n\nconst resolvedCache = new WeakMap<OfflineSupportConfig, ResolvedOfflineConfig>();\n\n/** `resolveConfig` memoised per config object (interceptors run on every request). */\nexport function resolveConfigCached(cfg: OfflineSupportConfig): ResolvedOfflineConfig {\n let resolved = resolvedCache.get(cfg);\n if (!resolved) {\n resolved = resolveConfig(cfg);\n resolvedCache.set(cfg, resolved);\n }\n return resolved;\n}\n\n/** True when the request is one the offline layer looks at: under `apiPrefix` and not matched by `skip`. */\nexport function isInScope(url: string, cfg: ResolvedOfflineConfig): boolean {\n return url.includes(cfg.apiPrefix) && !matchesAny(url, cfg.skip);\n}\n\nexport function lastSegmentIsId(url: string): boolean {\n const segments = pathOnly(url).split('/').filter(Boolean);\n return segments.length > 0 && ID_SEGMENT.test(segments[segments.length - 1]);\n}\n","/**\n * A v4 UUID. Uses `crypto.randomUUID` when the browser has it (Safari < 15.4 and insecure contexts do not),\n * then `crypto.getRandomValues`, then `Math.random` as the last resort. Always 36 characters.\n */\nexport function generateUuid(): string {\n const c: Crypto | undefined = typeof globalThis !== 'undefined' ? (globalThis as { crypto?: Crypto }).crypto : undefined;\n if (c && typeof c.randomUUID === 'function') {\n try { return c.randomUUID(); } catch { /* insecure context: fall through */ }\n }\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === 'function') {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0'));\n return `${hex.slice(0, 4).join('')}-${hex.slice(4, 6).join('')}-${hex.slice(6, 8).join('')}-${hex.slice(8, 10).join('')}-${hex.slice(10, 16).join('')}`;\n}\n","import { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Injectable, computed, inject, signal } from '@angular/core';\nimport { Subject } from 'rxjs';\nimport { OFFLINE_SUPPORT_CONFIG, resolveConfig } from '../config/offline-config';\n\nexport type ConnectionState = 'online' | 'slow' | 'unreachable' | 'offline';\n\nexport interface RecordRequestInfo {\n durationMs: number;\n ok: boolean;\n status: number;\n timedOut?: boolean;\n method: string;\n /** Long requests (blob / FormData / `longRequests`) never count as slow. Additive to the documented shape. */\n long?: boolean;\n}\n\n/** What made the connection usable again: the browser `online` event / a normal request that got an answer, or the probe. */\nexport type RecoveryTrigger = 'online' | 'probe';\n\n/** Debounce for the browser `online` event (flapping wifi). `offline` is applied at once: queueing is always the safe side. */\nexport const ONLINE_DEBOUNCE_MS = 300;\nconst PROBE_TIMEOUT_MS = 5000;\n\n/**\n * The one answer to \"can this device reach the server?\": online | slow | unreachable | offline.\n * Measured from real request timings (works in Safari/Firefox, which have no `navigator.connection`), the browser online/offline events and an\n * optional probe GET that runs only while the connection is suspect.\n */\n@Injectable({ providedIn: 'root' })\nexport class ConnectionStateService {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly win = inject(DOCUMENT).defaultView;\n\n private readonly browserOnline = signal(this.readNavigatorOnline());\n private readonly unreachable = signal(false);\n private readonly slowFlag = signal(false);\n private readonly _slowRequestActive = signal(false);\n private readonly _inFlightCount = signal(0);\n private readonly _state = signal<ConnectionState>(this.browserOnline() ? 'online' : 'offline');\n private readonly _lastChangeAt = signal(Date.now());\n\n readonly state = this._state.asReadonly();\n readonly isOnline = computed(() => this._state() === 'online' || this._state() === 'slow');\n readonly isOffline = computed(() => this._state() === 'offline' || this._state() === 'unreachable');\n /** Some request has been in flight longer than `slow.stuckMs`. */\n readonly slowRequestActive = this._slowRequestActive.asReadonly();\n readonly inFlightCount = this._inFlightCount.asReadonly();\n readonly lastChangeAt = this._lastChangeAt.asReadonly();\n /** True while the user should be told \"this is taking a while\" (a request is stuck or the connection is slow). */\n readonly slowRequestHint = computed(() => this._slowRequestActive() || this._state() === 'slow');\n /** Emits when the connection became usable again; the replayer listens to it. */\n readonly recovered$ = new Subject<RecoveryTrigger>();\n\n private failures: number[] = [];\n private slowTimes: number[] = [];\n private quietTimer: ReturnType<typeof setTimeout> | null = null;\n private onlineTimer: ReturnType<typeof setTimeout> | null = null;\n private probeTimer: ReturnType<typeof setInterval> | null = null;\n private optimisticTimer: ReturnType<typeof setTimeout> | null = null;\n private probeInFlight: Promise<boolean> | null = null;\n private readonly inFlight = new Map<number, { start: number; stuck: boolean; timer: ReturnType<typeof setTimeout> | null }>();\n private nextRequestId = 0;\n\n private readonly onWindowOnline = () => this.scheduleOnline();\n private readonly onWindowOffline = () => { this.cancelOnlineTimer(); this.setBrowserOnline(false); };\n private readonly onFocus = () => this.syncFromNavigator();\n\n constructor() {\n const win = this.win;\n if (win) {\n win.addEventListener('online', this.onWindowOnline);\n win.addEventListener('offline', this.onWindowOffline);\n win.addEventListener('focus', this.onFocus);\n win.document?.addEventListener('visibilitychange', this.onFocus);\n }\n inject(DestroyRef).onDestroy(() => this.teardown());\n }\n\n /** Called by `connectionInterceptor` when a request finished (or failed / timed out). */\n recordRequest(info: RecordRequestInfo): void {\n const now = Date.now();\n if (info.timedOut || info.status === 0) {\n this.handleFailure(now);\n return;\n }\n // The server answered (any HTTP status): it is reachable.\n this.failures = [];\n if (this.unreachable()) this.clearUnreachable('online');\n if (info.long) return;\n if (info.durationMs >= this.cfg.slow.slowMs) {\n this.slowTimes = this.slowTimes.filter(t => now - t <= this.cfg.slow.windowMs);\n this.slowTimes.push(now);\n if (this.slowTimes.length >= this.cfg.slow.slowCount || this.slowFlag()) this.markSlow();\n }\n }\n\n /**\n * Starts tracking one request; call the returned function when it ends (success, error, timeout or cancel; calling it twice is harmless).\n * A non-long request still in flight after `slow.stuckMs` turns `slowRequestActive` and the state to `slow`.\n */\n beginRequest(options: { long?: boolean } = {}): () => void {\n const id = ++this.nextRequestId;\n const entry: { start: number; stuck: boolean; timer: ReturnType<typeof setTimeout> | null } = { start: Date.now(), stuck: false, timer: null };\n this.inFlight.set(id, entry);\n this._inFlightCount.set(this.inFlight.size);\n if (!options.long) {\n entry.timer = setTimeout(() => {\n entry.timer = null;\n if (!this.inFlight.has(id)) return;\n entry.stuck = true;\n this._slowRequestActive.set(true);\n this.markSlow();\n }, this.cfg.slow.stuckMs);\n }\n return () => {\n const current = this.inFlight.get(id);\n if (!current) return;\n if (current.timer) clearTimeout(current.timer);\n this.inFlight.delete(id);\n this._inFlightCount.set(this.inFlight.size);\n this._slowRequestActive.set([...this.inFlight.values()].some(e => e.stuck));\n this.recompute();\n };\n }\n\n /**\n * Asks the probe URL once. Resolves true when it answered with ANY HTTP status (a 401 still proves the server is reachable).\n * Without a configured probe there is nothing to ask: the answer is what the browser says.\n */\n probeNow(): Promise<boolean> {\n const probe = this.cfg.probe;\n if (!probe) return Promise.resolve(this.browserOnline());\n if (this.probeInFlight) return this.probeInFlight;\n const run = this.runProbe(probe.url).then(ok => {\n if (ok) this.onProbeSuccess();\n return ok;\n }).finally(() => { this.probeInFlight = null; });\n this.probeInFlight = run;\n return run;\n }\n\n private async runProbe(url: string): Promise<boolean> {\n const win = this.win;\n if (!win || typeof win.fetch !== 'function') return false;\n const controller = typeof AbortController === 'function' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS) : null;\n try {\n await win.fetch(url, { method: 'GET', cache: 'no-store', credentials: 'same-origin', signal: controller?.signal });\n return true;\n } catch {\n return false;\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n\n private onProbeSuccess(): void {\n this.failures = [];\n if (this.unreachable()) this.clearUnreachable('probe');\n }\n\n private handleFailure(now: number): void {\n if (!this.browserOnline()) return;\n this.failures = this.failures.filter(t => now - t <= this.cfg.slow.windowMs);\n this.failures.push(now);\n if (this.failures.length >= 2) {\n this.setUnreachable();\n return;\n }\n if (this.cfg.probe) {\n void this.probeNow().then(ok => {\n if (!ok && this.browserOnline() && this.failures.length > 0) this.setUnreachable();\n });\n }\n }\n\n private setUnreachable(): void {\n if (this.unreachable()) return;\n this.unreachable.set(true);\n this.recompute();\n if (this.cfg.probe) {\n this.probeTimer = setInterval(() => { void this.probeNow(); }, this.cfg.probe.intervalMs);\n } else {\n // No probe to ask: assume it may be back after a while. The next failing request flips it straight back.\n this.optimisticTimer = setTimeout(() => {\n this.optimisticTimer = null;\n if (this.unreachable()) this.clearUnreachable('online');\n }, 15000);\n }\n }\n\n private clearUnreachable(trigger: RecoveryTrigger): void {\n if (!this.unreachable()) return;\n this.unreachable.set(false);\n this.stopRecoveryTimers();\n this.recompute();\n if (this.browserOnline()) this.recovered$.next(trigger);\n }\n\n private stopRecoveryTimers(): void {\n if (this.probeTimer) { clearInterval(this.probeTimer); this.probeTimer = null; }\n if (this.optimisticTimer) { clearTimeout(this.optimisticTimer); this.optimisticTimer = null; }\n }\n\n private markSlow(): void {\n this.slowFlag.set(true);\n if (this.quietTimer) clearTimeout(this.quietTimer);\n this.quietTimer = setTimeout(() => {\n this.quietTimer = null;\n this.slowFlag.set(false);\n this.slowTimes = [];\n this.recompute();\n }, this.cfg.slow.quietMs);\n this.recompute();\n }\n\n private scheduleOnline(): void {\n this.cancelOnlineTimer();\n this.onlineTimer = setTimeout(() => {\n this.onlineTimer = null;\n this.setBrowserOnline(true);\n }, ONLINE_DEBOUNCE_MS);\n }\n\n private cancelOnlineTimer(): void {\n if (this.onlineTimer) { clearTimeout(this.onlineTimer); this.onlineTimer = null; }\n }\n\n private setBrowserOnline(value: boolean): void {\n if (this.browserOnline() === value) return;\n this.browserOnline.set(value);\n if (value) {\n // Back from a real outage: forget the old failures and the old \"unreachable\" verdict; the next requests decide again.\n this.failures = [];\n if (this.unreachable()) { this.unreachable.set(false); this.stopRecoveryTimers(); }\n this.recompute();\n this.recovered$.next('online');\n } else {\n this.recompute();\n }\n }\n\n private syncFromNavigator(): void {\n if (!this.readNavigatorOnline()) { this.cancelOnlineTimer(); this.setBrowserOnline(false); }\n else if (!this.browserOnline()) this.scheduleOnline(); // a missed `online` event (sleep / wifi roaming): the browser says online again\n }\n\n private readNavigatorOnline(): boolean {\n try {\n return this.win?.navigator?.onLine !== false;\n } catch {\n return true;\n }\n }\n\n private recompute(): void {\n const next: ConnectionState = !this.browserOnline() ? 'offline'\n : this.unreachable() ? 'unreachable'\n : (this.slowFlag() || this._slowRequestActive()) ? 'slow'\n : 'online';\n if (next === this._state()) return;\n this._state.set(next);\n this._lastChangeAt.set(Date.now());\n }\n\n private teardown(): void {\n const win = this.win;\n if (win) {\n win.removeEventListener('online', this.onWindowOnline);\n win.removeEventListener('offline', this.onWindowOffline);\n win.removeEventListener('focus', this.onFocus);\n win.document?.removeEventListener('visibilitychange', this.onFocus);\n }\n this.cancelOnlineTimer();\n this.stopRecoveryTimers();\n if (this.quietTimer) { clearTimeout(this.quietTimer); this.quietTimer = null; }\n for (const e of this.inFlight.values()) if (e.timer) clearTimeout(e.timer);\n this.inFlight.clear();\n this.recovered$.complete();\n }\n}\n","import { Injectable, signal } from '@angular/core';\n\n/** Key used by callers that do not track which request a stale copy belongs to. */\nconst DEFAULT_KEY = '*';\n\n/** Tells the UI when what the user sees came from the device copy instead of the server. Tracked per request key (the cache key of the GET). */\n@Injectable({ providedIn: 'root' })\nexport class StaleDataService {\n private readonly _staleAt = signal<number | null>(null);\n private readonly entries = new Map<string, number>();\n /** `cachedAt` of the most recent cache-served GET that has not been replaced by a live answer for the same request; null = everything shown is live. */\n readonly staleAt = this._staleAt.asReadonly();\n\n markStale(cachedAt: number, key: string = DEFAULT_KEY): void {\n this.entries.set(key, cachedAt);\n this.publish();\n }\n\n /** A live answer arrived for this request: only its own stale mark goes away. */\n clearKey(key: string): void {\n if (this.entries.delete(key)) this.publish();\n }\n\n /** Forgets every stale mark. */\n clear(): void {\n if (this.entries.size === 0) return;\n this.entries.clear();\n this.publish();\n }\n\n private publish(): void {\n let latest: number | null = null;\n for (const v of this.entries.values()) if (latest === null || v > latest) latest = v;\n this._staleAt.set(latest);\n }\n}\n","import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { Subject } from 'rxjs';\nimport { uiText } from '@forgeroute/ui';\nimport { OFFLINE_SUPPORT_CONFIG, hasStampField, resolveConfig, stripStampFields } from '../config/offline-config';\n\nexport type MutationStatus = 'pending' | 'syncing' | 'failed' | 'conflict';\nexport type MutationErrorKind = 'conflict' | 'rejected' | 'auth' | 'server' | 'network' | 'timeout' | 'dependency';\n\nexport interface MutationError {\n kind: MutationErrorKind;\n status?: number;\n message: string;\n}\n\nexport interface OfflineMutation {\n id: string;\n seq: number;\n userId: string;\n /** The Idempotency-Key header of the original request; re-sent unchanged on every replay. */\n key: string;\n method: string;\n url: string;\n body: unknown;\n headers?: Record<string, string>;\n label: string;\n entityType?: string;\n entityId?: string;\n createdAt: number;\n status: MutationStatus;\n claimOwner?: string;\n claimAt?: number;\n attempts: number;\n nextAttemptAt?: number;\n lastError?: MutationError;\n /**\n * Set on a queued POST to a collection whose body had no id of its own: the client-made id handed out in the synthetic 202 (equals `id`).\n * Later saved changes may refer to it; after this row is delivered it is mapped to the server's real id (store `idmap`).\n */\n tempId?: string;\n /** Ids of the queued create rows whose temp id this change refers to (URL, query or body), set when the change was saved. */\n dependsOn?: string[];\n /** The temp ids behind `dependsOn`, same order (needed after the create row is gone to find its `idmap` entry). */\n dependsOnTempIds?: string[];\n /** Set by \"Keep my version\": the conflict stamp fields were removed from the body on the user's explicit choice, so this change overwrites the server's newer version. Kept for traceability. */\n overwrite?: boolean;\n}\n\nexport type NewMutation = Omit<OfflineMutation, 'seq'>;\n\nexport interface CachedEntry {\n /** Composite primary key: `<userId>::<url key>`. */\n key: string;\n urlKey: string;\n userId: string;\n data: unknown;\n cachedAt: number;\n expiresAt: number;\n}\n\n/** Maps a temp id to the real id the server gave the record. Key `<userId>:<tempId>`; kept 7 days. */\nexport interface IdMapEntry {\n key: string;\n userId: string;\n tempId: string;\n /** Always text; `numeric` tells that the server's id was a number (so a JSON body gets a number back). */\n realId: string;\n numeric?: boolean;\n createdAt: number;\n expiresAt: number;\n}\n\nexport const IDMAP_TTL_MS = 7 * 24 * 60 * 60 * 1000;\n\nexport interface MutationCounts { pending: number; syncing: number; failed: number; conflict: number }\n\n/** A claim older than this in status `syncing` belongs to a tab that died mid-send and may be taken over. */\nexport const STALE_CLAIM_MS = 60_000;\nconst DB_VERSION = 2;\nconst OPEN_TIMEOUT_MS = 10_000;\nconst MAX_CACHE_ENTRIES = 500;\nconst EVICT_COUNT = 50;\nconst MUTATIONS = 'mutations';\nconst RESPONSES = 'responses';\nconst META = 'meta';\nconst IDMAP = 'idmap';\n\n/** IndexedDB, or null when the browser has none / refuses access (some privacy modes throw on the property read). */\nexport const OFFLINE_IDB_FACTORY = new InjectionToken<IDBFactory | null>('OFFLINE_IDB_FACTORY', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof indexedDB !== 'undefined' ? indexedDB : null;\n } catch {\n return null;\n }\n },\n});\n\n/** IndexedDB is missing, blocked or failed to open: nothing can be saved on this device. */\nexport class StorageUnavailableError extends Error {\n constructor(message: string = uiText('connection.storageNotAvailable')) {\n super(message);\n this.name = 'StorageUnavailableError';\n Object.setPrototypeOf(this, StorageUnavailableError.prototype);\n }\n}\n\n/** The user already has `maxQueue` saved changes. */\nexport class QueueFullError extends Error {\n constructor(readonly limit: number) {\n super(uiText('connection.queueFull', { limit }));\n this.name = 'QueueFullError';\n Object.setPrototypeOf(this, QueueFullError.prototype);\n }\n}\n\nexport function isQuotaError(e: unknown): boolean {\n const x = e as { name?: string; code?: number } | null;\n return !!x && (x.name === 'QuotaExceededError' || x.name === 'NS_ERROR_DOM_QUOTA_REACHED' || x.code === 22 || x.code === 1014);\n}\n\nfunction isInvalidState(e: unknown): boolean {\n const x = e as { name?: string } | null;\n return !!x && (x.name === 'InvalidStateError' || x.name === 'TransactionInactiveError');\n}\n\nconst RETRYABLE_FAILURES: readonly MutationErrorKind[] = ['server', 'network', 'timeout'];\n\n/** True when `claim` may take the row: pending, a failed row whose failure was transient, or a `syncing` row whose claim went stale. */\nexport function isClaimable(row: OfflineMutation, now: number): boolean {\n if (row.status === 'pending') return true;\n if (row.status === 'failed') return !!row.lastError && RETRYABLE_FAILURES.includes(row.lastError.kind);\n if (row.status === 'syncing') return now - (row.claimAt ?? 0) > STALE_CLAIM_MS;\n return false;\n}\n\ntype Stores = Record<string, IDBObjectStore>;\n\n/**\n * Thin promise wrapper over IndexedDB: the queued writes (`mutations`) and the per-user device copy of GET answers (`responses`).\n * Every row and cache entry carries its `userId`; reads and deletes are always scoped to a user. If IndexedDB cannot be used,\n * `available()` is false and callers must refuse to queue (never a fake success).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineStore {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly factory = inject(OFFLINE_IDB_FACTORY);\n\n /** Emits after every write to the saved changes (add, claim, update, delete, clear); other tabs are told by OfflineSupportService. */\n readonly mutated$ = new Subject<void>();\n\n private db: IDBDatabase | null = null;\n private opening: Promise<IDBDatabase> | null = null;\n private initPromise: Promise<void> | null = null;\n private ready = false;\n\n available(): boolean {\n return this.ready;\n }\n\n /** Opens the database. Never rejects: on failure `available()` stays false (and a later `init()` tries again). */\n init(): Promise<void> {\n if (!this.initPromise) {\n this.initPromise = this.doInit().then(() => {\n if (!this.ready) this.initPromise = null;\n });\n }\n return this.initPromise;\n }\n\n private async doInit(): Promise<void> {\n if (!this.factory) { this.ready = false; return; }\n try {\n await this.getDb();\n this.ready = true;\n } catch {\n this.ready = false;\n return;\n }\n try { await this.purgeExpired(); } catch { /* cleanup is best effort */ }\n try { await this.purgeExpiredIdMap(); } catch { /* cleanup is best effort */ }\n }\n\n // ---- saved changes -------------------------------------------------------------------------------------------------------------\n\n /**\n * Saves a new change. If this user already has a row with the same idempotency `key` that row is returned instead (a double click that\n * re-used the key must not queue twice). Rejects with QueueFullError, StorageUnavailableError or the storage error (e.g. QuotaExceededError).\n */\n async addMutation(row: NewMutation): Promise<OfflineMutation> {\n await this.init();\n if (!this.ready) throw new StorageUnavailableError();\n const limit = this.cfg.maxQueue;\n const saved = await this.runTx<OfflineMutation>([MUTATIONS, META], 'readwrite', (s, resolveWith, abortWith) => {\n const existing = s[MUTATIONS].index('userId').getAll(row.userId) as IDBRequest<OfflineMutation[]>;\n existing.onsuccess = () => {\n const rows = existing.result;\n const dup = rows.find(r => r.key === row.key);\n if (dup) { resolveWith(dup); return; }\n if (rows.length >= limit) { abortWith(new QueueFullError(limit)); return; }\n const seqReq = s[META].get('seq') as IDBRequest<{ id: string; value: number } | undefined>;\n seqReq.onsuccess = () => {\n const seq = (seqReq.result?.value ?? 0) + 1;\n const full: OfflineMutation = { ...row, seq };\n s[META].put({ id: 'seq', value: seq });\n s[MUTATIONS].add(full);\n resolveWith(full);\n };\n };\n });\n this.mutated$.next();\n return saved;\n }\n\n /**\n * Atomically takes a row for sending: only if it is pending, failed with a transient error, or `syncing` with a claim older than 60 s.\n * Returns the claimed row, or null when it is gone or somebody else holds a live claim.\n */\n async claim(id: string, owner: string, now: number = Date.now()): Promise<OfflineMutation | null> {\n const claimed = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || !isClaimable(row, now)) return;\n const next: OfflineMutation = { ...row, status: 'syncing', claimOwner: owner, claimAt: now };\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (claimed) this.mutated$.next();\n return claimed;\n }\n\n /** Merges `patch` into the row (an `undefined` value removes the field). With `ifOwner` it only applies while that owner still holds the claim. */\n async update(id: string, patch: Partial<OfflineMutation>, opts: { ifOwner?: string } = {}): Promise<OfflineMutation | null> {\n const updated = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row) return;\n if (opts.ifOwner !== undefined && row.claimOwner !== opts.ifOwner) return;\n const merged = { ...row, ...patch, id: row.id, userId: row.userId } as OfflineMutation;\n const loose = merged as unknown as Record<string, unknown>;\n for (const k of Object.keys(loose)) if (loose[k] === undefined) delete loose[k];\n s[MUTATIONS].put(merged);\n resolveWith(merged);\n };\n });\n if (updated) this.mutated$.next();\n return updated;\n }\n\n /**\n * The user's \"Retry\": puts one row (any status) back to pending with 0 attempts, in ONE transaction so a claim taken in between cannot be overwritten.\n * Returns the reset row, or null when the row is missing, belongs to another user, or is being sent right now (live claim).\n */\n async resetForRetry(id: string, userId: string, now: number = Date.now()): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n const reset = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || row.userId !== userId) return;\n if (row.status === 'syncing' && now - (row.claimAt ?? 0) <= STALE_CLAIM_MS) return;\n const next: OfflineMutation = { ...row, status: 'pending', attempts: 0 };\n delete next.nextAttemptAt;\n delete next.lastError;\n delete next.claimOwner;\n delete next.claimAt;\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (reset) this.mutated$.next();\n return reset;\n }\n\n /**\n * The user's \"Keep my version\": in ONE transaction, only for a row in status `conflict` that belongs to `userId` and whose body has at least one of\n * the stamp `fields`: removes those fields from the body, gives it a NEW idempotency key (the old one is bound to the stored 409 on the server), sets it\n * back to pending with 0 attempts and marks `overwrite: true`. id, seq, createdAt and dependencies are kept. LATER rows of the same record are NOT\n * touched here: they keep their stamp (and stay held / pending) until the overwrite has really been delivered; only then does the replayer call\n * `stripStampsAfter`. So if the overwrite fails for good or is discarded, a later edit is never sent unstamped.\n * Returns the row, or null when it is missing, foreign, not in conflict, or has no stamp field (nothing to overwrite: it would re-send an unchanged body).\n */\n async resetForKeepMine(id: string, userId: string, fields: readonly string[], newKey: string): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n const reset = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || row.userId !== userId || row.status !== 'conflict' || !hasStampField(row.body, fields)) return;\n const next: OfflineMutation = { ...row, body: stripStampFields(row.body, fields), key: newKey, status: 'pending', attempts: 0, overwrite: true };\n delete next.nextAttemptAt;\n delete next.lastError;\n delete next.claimOwner;\n delete next.claimAt;\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (reset) this.mutated$.next();\n return reset;\n }\n\n /**\n * Called after a \"Keep my version\" overwrite was DELIVERED: removes the stamp `fields` from every row of `userId` for the same record (entityType +\n * entityId) with a higher seq than `afterSeq` that is still `pending` (marks them `overwrite: true`), so they do not each turn into another conflict.\n * failed / conflict / syncing rows and rows of other records are left exactly as they are. Returns how many rows changed.\n */\n async stripStampsAfter(userId: string, entityType: string, entityId: string, afterSeq: number, fields: readonly string[]): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n const changed = await this.runTx<number>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const all = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n all.onsuccess = () => {\n let n = 0;\n for (const r of all.result) {\n if (r.userId !== userId || r.seq <= afterSeq || r.status !== 'pending') continue;\n if (r.entityType !== entityType || r.entityId !== entityId || !hasStampField(r.body, fields)) continue;\n s[MUTATIONS].put({ ...r, body: stripStampFields(r.body, fields), overwrite: true });\n n++;\n }\n resolveWith(n);\n };\n });\n if (changed > 0) this.mutated$.next();\n return changed;\n }\n\n async get(id: string): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n return this.runTx<OfflineMutation | null>([MUTATIONS], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n });\n }\n\n /** Deletes the row; with `ifOwner` only while that owner still holds the claim. Returns whether a row was deleted. */\n async delete(id: string, opts: { ifOwner?: string } = {}): Promise<boolean> {\n const deleted = await this.runTx<boolean>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(false);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row) return;\n if (opts.ifOwner !== undefined && row.claimOwner !== opts.ifOwner) return;\n s[MUTATIONS].delete(id);\n resolveWith(true);\n };\n });\n if (deleted) this.mutated$.next();\n return deleted;\n }\n\n /** The user's rows in send order (seq, then createdAt). */\n async list(userId: string): Promise<OfflineMutation[]> {\n if (!(await this.ensureReady())) return [];\n const rows = await this.runTx<OfflineMutation[]>([MUTATIONS], 'readonly', (s, resolveWith) => {\n resolveWith([]);\n const req = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n req.onsuccess = () => resolveWith(req.result);\n });\n return rows.filter(r => r.userId === userId).sort((a, b) => a.seq - b.seq || a.createdAt - b.createdAt);\n }\n\n async count(userId: string): Promise<number> {\n return (await this.list(userId)).length;\n }\n\n async countsByStatus(userId: string): Promise<MutationCounts> {\n const counts: MutationCounts = { pending: 0, syncing: 0, failed: 0, conflict: 0 };\n for (const r of await this.list(userId)) counts[r.status]++;\n return counts;\n }\n\n /** Deletes only the saved changes of this user (their device copy of GET answers stays). */\n async deleteMutations(userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n const removed = await this.runTx<number>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n req.onsuccess = () => {\n const rows = req.result.filter(r => r.userId === userId);\n for (const r of rows) s[MUTATIONS].delete(r.id);\n resolveWith(rows.length);\n };\n });\n if (removed > 0) this.mutated$.next();\n return removed;\n }\n\n /** Deletes this user's saved changes AND device copy. Never touches another user's data. */\n async clearUser(userId: string): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.deleteMutations(userId);\n await this.clearCache(userId);\n await this.deleteIdMap(userId);\n }\n\n /** Deletes everything for every user (rows, device copy). Only for an explicit, confirmed full reset. */\n async clearAll(): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.runTx<void>([MUTATIONS, RESPONSES, IDMAP], 'readwrite', (s) => {\n s[MUTATIONS].clear();\n s[RESPONSES].clear();\n s[IDMAP].clear();\n });\n this.mutated$.next();\n }\n\n // ---- temp id -> real id ---------------------------------------------------------------------------------------------------------\n\n /** Saves (or overwrites: a replayed create gives the same answer) the real id for a temp id. Rejects when the write fails. */\n async putIdMapping(userId: string, tempId: string, realId: string | number, now: number = Date.now()): Promise<IdMapEntry> {\n await this.init();\n if (!this.ready) throw new StorageUnavailableError();\n const entry: IdMapEntry = {\n key: `${userId}:${tempId}`, userId, tempId, realId: String(realId), createdAt: now, expiresAt: now + IDMAP_TTL_MS,\n ...(typeof realId === 'number' ? { numeric: true } : {}),\n };\n await this.runTx<void>([IDMAP], 'readwrite', s => { s[IDMAP].put(entry); });\n return entry;\n }\n\n /** The user's real id for `tempId`, or null (missing, expired, or somebody else's). */\n async getIdMapping(userId: string, tempId: string, now: number = Date.now()): Promise<IdMapEntry | null> {\n if (!(await this.ensureReady())) return null;\n const entry = await this.runTx<IdMapEntry | null>([IDMAP], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[IDMAP].get(`${userId}:${tempId}`) as IDBRequest<IdMapEntry | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n });\n return entry && entry.userId === userId && entry.expiresAt > now ? entry : null;\n }\n\n /** All of the user's unexpired temp id mappings. */\n async listIdMap(userId: string, now: number = Date.now()): Promise<IdMapEntry[]> {\n if (!(await this.ensureReady())) return [];\n const all = await this.runTx<IdMapEntry[]>([IDMAP], 'readonly', (s, resolveWith) => {\n resolveWith([]);\n const req = s[IDMAP].index('userId').getAll(userId) as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => resolveWith(req.result);\n });\n return all.filter(e => e.userId === userId && e.expiresAt > now);\n }\n\n /** Deletes this user's temp id mappings only. */\n async deleteIdMap(userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n return this.runTx<number>([IDMAP], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[IDMAP].index('userId').getAll(userId) as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => {\n const mine = req.result.filter(e => e.userId === userId);\n for (const e of mine) s[IDMAP].delete(e.key);\n resolveWith(mine.length);\n };\n });\n }\n\n /** Removes mappings whose 7 days are over (every user). Returns how many. */\n async purgeExpiredIdMap(now: number = Date.now()): Promise<number> {\n return this.runTx<number>([IDMAP], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[IDMAP].getAll() as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => {\n const old = req.result.filter(e => e.expiresAt <= now);\n for (const e of old) s[IDMAP].delete(e.key);\n resolveWith(old.length);\n };\n });\n }\n\n // ---- device copy of GET answers --------------------------------------------------------------------------------------------------\n\n /** Stores a GET answer for this user. Returns false when it could not be stored (never throws: the copy is optional). */\n async cacheResponse(key: string, userId: string, data: unknown, ttlMs: number, now: number = Date.now()): Promise<boolean> {\n if (!(await this.ensureReady())) return false;\n const entry: CachedEntry = { key: `${userId}::${key}`, urlKey: key, userId, data, cachedAt: now, expiresAt: now + ttlMs };\n const put = () => this.runTx<void>([RESPONSES], 'readwrite', s => { s[RESPONSES].put(entry); });\n try {\n await put();\n } catch (e) {\n if (!isQuotaError(e)) return false;\n try {\n await this.evictOldest(EVICT_COUNT, now);\n await put();\n } catch {\n return false;\n }\n }\n void this.enforceCacheLimit().catch(() => undefined);\n return true;\n }\n\n /** The user's stored answer for `key`, or null (missing, expired or belonging to somebody else). */\n async getCached(key: string, userId: string, now: number = Date.now()): Promise<CachedEntry | null> {\n if (!(await this.ensureReady())) return null;\n const composite = `${userId}::${key}`;\n const entry = await this.runTx<CachedEntry | null>([RESPONSES], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[RESPONSES].get(composite) as IDBRequest<CachedEntry | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n }).catch(() => null);\n if (!entry || entry.userId !== userId) return null;\n if (entry.expiresAt <= now) {\n void this.runTx<void>([RESPONSES], 'readwrite', s => { s[RESPONSES].delete(composite); }).catch(() => undefined);\n return null;\n }\n return entry;\n }\n\n /** Removes this user's stored answers whose URL key starts with `prefix`. */\n async invalidatePrefix(prefix: string, userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n return this.runTx<number>([RESPONSES], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].index('userId').getAll(userId) as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const hits = req.result.filter(e => e.userId === userId && e.urlKey.startsWith(prefix));\n for (const e of hits) s[RESPONSES].delete(e.key);\n resolveWith(hits.length);\n };\n }).catch(() => 0);\n }\n\n /** Deletes the device copy of one user, or of everybody when `userId` is omitted. Saved changes are never touched. */\n async clearCache(userId?: string): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.runTx<void>([RESPONSES], 'readwrite', (s) => {\n if (userId === undefined) { s[RESPONSES].clear(); return; }\n const req = s[RESPONSES].index('userId').getAll(userId) as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => { for (const e of req.result) if (e.userId === userId) s[RESPONSES].delete(e.key); };\n });\n }\n\n async purgeExpired(now: number = Date.now()): Promise<number> {\n return this.runTx<number>([RESPONSES], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].getAll() as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const old = req.result.filter(e => e.expiresAt <= now);\n for (const e of old) s[RESPONSES].delete(e.key);\n resolveWith(old.length);\n };\n });\n }\n\n private async evictOldest(count: number, now: number): Promise<void> {\n await this.runTx<void>([RESPONSES], 'readwrite', (s) => {\n const req = s[RESPONSES].getAll() as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const sorted = [...req.result].sort((a, b) => (a.expiresAt <= now ? 0 : 1) - (b.expiresAt <= now ? 0 : 1) || a.cachedAt - b.cachedAt);\n for (const e of sorted.slice(0, count)) s[RESPONSES].delete(e.key);\n };\n });\n }\n\n private async enforceCacheLimit(): Promise<void> {\n const total = await this.runTx<number>([RESPONSES], 'readonly', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].count() as IDBRequest<number>;\n req.onsuccess = () => resolveWith(req.result);\n });\n if (total > MAX_CACHE_ENTRIES) await this.evictOldest(EVICT_COUNT, Date.now());\n }\n\n // ---- plumbing ------------------------------------------------------------------------------------------------------------------\n\n private async ensureReady(): Promise<boolean> {\n await this.init();\n return this.ready;\n }\n\n private getDb(): Promise<IDBDatabase> {\n if (this.db) return Promise.resolve(this.db);\n if (this.opening) return this.opening;\n const opening = this.openWithRetry().then(\n db => { this.db = db; this.opening = null; return db; },\n err => { this.opening = null; throw err; },\n );\n this.opening = opening;\n return opening;\n }\n\n private async openWithRetry(): Promise<IDBDatabase> {\n try {\n return await this.openOnce();\n } catch (first) {\n // Safari sometimes fails the very first open of a fresh profile; one more try is what the browsers recommend.\n if (first instanceof StorageUnavailableError || (first as { name?: string } | null)?.name === 'SecurityError') throw first;\n return this.openOnce();\n }\n }\n\n private openOnce(): Promise<IDBDatabase> {\n const factory = this.factory;\n return new Promise<IDBDatabase>((resolve, reject) => {\n if (!factory) { reject(new StorageUnavailableError()); return; }\n let req: IDBOpenDBRequest;\n try {\n req = factory.open(this.cfg.dbName, DB_VERSION);\n } catch (e) {\n reject(e);\n return;\n }\n const timer = setTimeout(() => reject(new StorageUnavailableError(uiText('connection.storageTimeout'))), OPEN_TIMEOUT_MS);\n req.onupgradeneeded = () => {\n const db = req.result;\n if (!db.objectStoreNames.contains(MUTATIONS)) {\n const m = db.createObjectStore(MUTATIONS, { keyPath: 'id' });\n m.createIndex('userId', 'userId');\n m.createIndex('status', 'status');\n m.createIndex('createdAt', 'createdAt');\n }\n if (!db.objectStoreNames.contains(RESPONSES)) {\n const r = db.createObjectStore(RESPONSES, { keyPath: 'key' });\n r.createIndex('userId', 'userId');\n r.createIndex('expiresAt', 'expiresAt');\n }\n if (!db.objectStoreNames.contains(META)) db.createObjectStore(META, { keyPath: 'id' });\n // Version 2 only ADDS this store; every store and row from version 1 is left exactly as it is.\n if (!db.objectStoreNames.contains(IDMAP)) {\n const i = db.createObjectStore(IDMAP, { keyPath: 'key' });\n i.createIndex('userId', 'userId');\n i.createIndex('expiresAt', 'expiresAt');\n }\n };\n req.onsuccess = () => {\n clearTimeout(timer);\n const db = req.result;\n // Another tab wants to upgrade, or the browser closed the connection: drop it so the next call reopens.\n db.onversionchange = () => { db.close(); if (this.db === db) this.db = null; };\n db.onclose = () => { if (this.db === db) this.db = null; };\n resolve(db);\n };\n req.onerror = () => { clearTimeout(timer); reject(req.error ?? new StorageUnavailableError()); };\n req.onblocked = () => { /* waits for the other connection to close; the timeout above ends the wait */ };\n });\n }\n\n private async runTx<T>(\n names: string[],\n mode: IDBTransactionMode,\n work: (stores: Stores, resolveWith: (v: T) => void, abortWith: (e: unknown) => void) => void,\n retried = false,\n ): Promise<T> {\n const db = await this.getDb();\n let tx: IDBTransaction;\n try {\n tx = db.transaction(names, mode);\n } catch (e) {\n if (!retried && isInvalidState(e)) {\n if (this.db === db) this.db = null;\n return this.runTx(names, mode, work, true);\n }\n throw e;\n }\n return new Promise<T>((resolve, reject) => {\n let result: T | undefined;\n let failure: unknown;\n let failed = false;\n const abortWith = (e: unknown) => {\n failed = true;\n failure = e;\n try { tx.abort(); } catch { /* already finished */ }\n };\n tx.oncomplete = () => resolve(result as T);\n tx.onabort = () => reject(failed ? failure : tx.error ?? new Error(uiText('connection.transactionAborted')));\n const stores: Stores = {};\n try {\n for (const n of names) stores[n] = tx.objectStore(n);\n work(stores, v => { result = v; }, abortWith);\n } catch (e) {\n abortWith(e);\n }\n });\n }\n}\n","/** Why an offline write was refused. */\nexport type OfflineBlockedReason = 'blocked' | 'upload' | 'storage' | 'not-allowed';\n\n/**\n * A write that cannot be saved on the device while offline. `message` is plain words for the user (from UiLabelsService or the app's\n * `blockOffline[].message`). Nothing was queued and nothing was sent.\n */\nexport class OfflineBlockedError extends Error {\n readonly offlineBlocked = true;\n readonly status = 0;\n readonly reason: OfflineBlockedReason;\n constructor(message: string, reason: OfflineBlockedReason = 'blocked') {\n super(message);\n this.name = 'OfflineBlockedError';\n this.reason = reason;\n Object.setPrototypeOf(this, OfflineBlockedError.prototype);\n }\n}\n\n/** The client gave up waiting. For a write `outcomeUnknown` is true: the server may still have handled it. */\nexport class RequestTimeoutError extends Error {\n readonly timeout = true;\n readonly status = 0;\n readonly method: string;\n readonly url: string;\n readonly outcomeUnknown: boolean;\n constructor(message: string, method: string, url: string, outcomeUnknown: boolean) {\n super(message);\n this.name = 'RequestTimeoutError';\n this.method = method;\n this.url = url;\n this.outcomeUnknown = outcomeUnknown;\n Object.setPrototypeOf(this, RequestTimeoutError.prototype);\n }\n}\n\nexport function isOfflineBlockedError(e: unknown): e is OfflineBlockedError {\n return e instanceof OfflineBlockedError || (typeof e === 'object' && e !== null && (e as { offlineBlocked?: unknown }).offlineBlocked === true);\n}\n\nexport function isRequestTimeoutError(e: unknown): e is RequestTimeoutError {\n return e instanceof RequestTimeoutError || (typeof e === 'object' && e !== null && (e as { timeout?: unknown }).timeout === true && (e as { status?: unknown }).status === 0);\n}\n","import { lastSegmentIsId } from '../config/offline-config';\n\n/**\n * Temporary ids: a record created offline gets a client-made id (the `id` of the synthetic 202). Later saved changes may point at it (URL path\n * segment, query value, or a string value anywhere inside the JSON body). These helpers find those references and, at send time, swap them for the\n * server's real id. Matching is EXACT equality of a whole segment / value: a string that merely contains the temp id is never touched, and keys are\n * never touched. Nothing here mutates its input.\n */\n\n/** True when a JSON object body carries an `id` of its own (not null / undefined): the app chose the id, so nothing needs mapping. */\nexport function bodyHasOwnId(body: unknown): boolean {\n if (body === null || typeof body !== 'object' || Array.isArray(body)) return false;\n const id = (body as Record<string, unknown>)['id'];\n return id !== undefined && id !== null;\n}\n\n/** A POST to a collection (last path segment is not an id) whose body has no id of its own: the server will invent the id. */\nexport function isTempIdCreate(method: string, url: string, body: unknown): boolean {\n return method.toUpperCase() === 'POST' && !lastSegmentIsId(url) && !bodyHasOwnId(body);\n}\n\ninterface UrlParts { path: string; query: string | null; hash: string }\n\nfunction splitUrl(url: string): UrlParts {\n const h = url.indexOf('#');\n const hash = h >= 0 ? url.slice(h) : '';\n const noHash = h >= 0 ? url.slice(0, h) : url;\n const q = noHash.indexOf('?');\n return { path: q >= 0 ? noHash.slice(0, q) : noHash, query: q >= 0 ? noHash.slice(q + 1) : null, hash };\n}\n\nfunction decode(s: string): string {\n try { return decodeURIComponent(s); } catch { return s; }\n}\n\nfunction walkStrings(value: unknown, visit: (s: string) => void): void {\n if (typeof value === 'string') { visit(value); return; }\n if (Array.isArray(value)) { for (const v of value) walkStrings(v, visit); return; }\n if (value !== null && typeof value === 'object') { for (const v of Object.values(value as Record<string, unknown>)) walkStrings(v, visit); }\n}\n\n/** Every string that could be a reference: path segments, query values (decoded) and body string values. Keys are not included. */\nfunction referenceStrings(url: string, body: unknown): string[] {\n const out: string[] = [];\n const parts = splitUrl(url);\n for (const seg of parts.path.split('/')) if (seg !== '') out.push(decode(seg));\n if (parts.query !== null) {\n for (const pair of parts.query.split('&')) {\n const eq = pair.indexOf('=');\n if (eq >= 0) out.push(decode(pair.slice(eq + 1)));\n }\n }\n walkStrings(body, s => out.push(s));\n return out;\n}\n\n/** The candidate temp ids that the URL / body of a request refers to, each once, in order of first appearance. */\nexport function findTempIds(url: string, body: unknown, candidates: ReadonlySet<string> | ReadonlyMap<string, unknown>): string[] {\n const found: string[] = [];\n if (candidates.size === 0) return found;\n for (const s of referenceStrings(url, body)) {\n if (candidates.has(s) && !found.includes(s)) found.push(s);\n }\n return found;\n}\n\nfunction rewriteValue(value: unknown, map: ReadonlyMap<string, string | number>): unknown {\n if (typeof value === 'string') return map.has(value) ? map.get(value) : value;\n if (Array.isArray(value)) return value.map(v => rewriteValue(v, map));\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n // defineProperty so an own \"__proto__\" key from JSON.parse is kept as data instead of being swallowed by the prototype setter.\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n Object.defineProperty(out, k, { value: rewriteValue(v, map), enumerable: true, writable: true, configurable: true });\n }\n return out;\n }\n return value;\n}\n\n/**\n * The request as it must be sent now: every path segment / query value / body string value that EQUALS a temp id in `map` is replaced by the real id\n * (in the URL always as text, URL-encoded; in the body as given: a number stays a number). Returns new values; the inputs are not modified.\n */\nexport function rewriteTempIds(url: string, body: unknown, map: ReadonlyMap<string, string | number>): { url: string; body: unknown } {\n if (map.size === 0) return { url, body };\n const parts = splitUrl(url);\n const path = parts.path.split('/').map(seg => {\n const d = decode(seg);\n return map.has(d) ? encodeURIComponent(String(map.get(d))) : seg;\n }).join('/');\n let query = parts.query;\n if (query !== null) {\n query = query.split('&').map(pair => {\n const eq = pair.indexOf('=');\n if (eq < 0) return pair;\n const d = decode(pair.slice(eq + 1));\n return map.has(d) ? `${pair.slice(0, eq)}=${encodeURIComponent(String(map.get(d)))}` : pair;\n }).join('&');\n }\n return { url: path + (query !== null ? `?${query}` : '') + parts.hash, body: rewriteValue(body, map) };\n}\n","import { HttpClient, HttpErrorResponse } from '@angular/common/http';\nimport { Injectable, InjectionToken, inject, signal } from '@angular/core';\nimport { Subject, firstValueFrom } from 'rxjs';\nimport { ToastService, UiLabelsService } from '@forgeroute/ui';\nimport {\n IDEMPOTENCY_HEADER, IDEMPOTENCY_IN_PROGRESS_CODE, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, resolveConfig,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\nimport { isRequestTimeoutError } from '../http/errors';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { IdMapEntry, MutationError, MutationErrorKind, OfflineMutation, OfflineStore } from '../store/offline-store';\nimport { findTempIds, rewriteTempIds } from '../store/temp-ids';\n\nexport type ReplayTrigger = 'start' | 'online' | 'probe' | 'manual';\n\nexport interface ReplayResult {\n synced: number;\n failed: number;\n conflicts: number;\n blockedByAuth: boolean;\n}\n\n/** What \"Keep my version\" ended with: `sent` (delivered), `shortly` (still queued, goes out on its own) or `failed` (refused again / a new conflict). */\nexport type KeepMineOutcome = 'sent' | 'shortly' | 'failed';\n\nexport interface KeepMineRun {\n applied: boolean;\n result: ReplayResult | null;\n followUp: ReplayResult | null;\n /** null when nothing was applied. */\n outcome: KeepMineOutcome | null;\n}\n\n/** `navigator.locks`, or null when the browser has none (older Safari) - the replayer then falls back to an in-tab mutex plus a localStorage lease. */\nexport const OFFLINE_LOCK_MANAGER = new InjectionToken<LockManager | null>('OFFLINE_LOCK_MANAGER', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof navigator !== 'undefined' && navigator.locks && typeof navigator.locks.request === 'function' ? navigator.locks : null;\n } catch {\n return null;\n }\n },\n});\n\nexport type LeaseStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n\n/** Storage for the lock-less fallback lease: ONE small key holding `{ owner, until }`, never any data. */\nexport const OFFLINE_LEASE_STORAGE = new InjectionToken<LeaseStorage | null>('OFFLINE_LEASE_STORAGE', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof localStorage !== 'undefined' ? localStorage : null;\n } catch {\n return null;\n }\n },\n});\n\nexport const LEASE_TTL_MS = 30_000;\nconst LEASE_REFRESH_MS = 10_000;\nconst BACKOFF_BASE_MS = 2000;\nconst BACKOFF_CAP_MS = 5 * 60_000;\n\n/** Wait before the next automatic try after `attempts` failed sends: 2 s, 4 s, 8 s ... capped at 5 minutes. */\nexport function backoffMs(attempts: number): number {\n return Math.min(BACKOFF_BASE_MS * 2 ** Math.max(0, attempts - 1), BACKOFF_CAP_MS);\n}\n\ntype Outcome =\n | { action: 'ok'; text?: string }\n | { action: 'dependency' }\n | { action: 'conflict'; status: number }\n | { action: 'rejected'; status: number }\n | { action: 'auth'; status: number }\n | { action: 'retry'; kind: Extract<MutationErrorKind, 'server' | 'network' | 'timeout'>; status: number; retryAfterMs?: number };\n\n/** `Retry-After` in whole seconds -> ms; only 1..300 s are believed (HTTP dates, zero, negatives and junk are ignored, the normal back-off applies). */\nfunction retryAfterMs(err: HttpErrorResponse): number | undefined {\n const raw = err.headers?.get('Retry-After');\n if (raw === null || raw === undefined || !/^\\s*\\d+\\s*$/.test(raw)) return undefined;\n const seconds = Number(raw);\n return seconds >= 1 && seconds <= BACKOFF_CAP_MS / 1000 ? seconds * 1000 : undefined;\n}\n\n/** True when the 409's JSON body (an object, or the text of one: replays read answers as text) has `code` equal to the in-progress code. */\nfunction isInProgress409(err: HttpErrorResponse, code: string): boolean {\n let body: unknown = err.error;\n if (typeof body === 'string') { try { body = JSON.parse(body); } catch { return false; } }\n return !!body && typeof body === 'object' && (body as { code?: unknown }).code === code;\n}\n\n/**\n * Maps what a replayed request ended with to what happens to its row. Anything unknown stays retryable: only a real 4xx answer is final.\n * A 409 whose body `code` is `inProgressCode` (the same Idempotency-Key is still being processed) is transient: retry, honouring `Retry-After`.\n */\nexport function classifyReplay(err: unknown, inProgressCode: string = IDEMPOTENCY_IN_PROGRESS_CODE): Outcome {\n if (isRequestTimeoutError(err)) return { action: 'retry', kind: 'timeout', status: 0 };\n if (!(err instanceof HttpErrorResponse)) return { action: 'retry', kind: 'network', status: 0 };\n const s = err.status;\n if (s >= 200 && s < 300) return { action: 'ok' };\n if (s === 0) return { action: 'retry', kind: 'network', status: 0 };\n if (s === 401 || s === 403) return { action: 'auth', status: s };\n if (s === 409) {\n if (!isInProgress409(err, inProgressCode)) return { action: 'conflict', status: s };\n const wait = retryAfterMs(err);\n return wait === undefined ? { action: 'retry', kind: 'server', status: s } : { action: 'retry', kind: 'server', status: s, retryAfterMs: wait };\n }\n if (s === 408 || s === 429) return { action: 'retry', kind: 'server', status: s };\n if (s >= 400 && s < 500) return { action: 'rejected', status: s };\n return { action: 'retry', kind: 'server', status: s };\n}\n\n/**\n * Sends the signed-in user's saved changes, oldest first, when the connection is back. Safe by construction:\n * - one run at a time per browser (navigator.locks, or in-tab mutex + localStorage lease), and every row is `claim`ed atomically in IndexedDB;\n * - the row's own Idempotency-Key is re-sent unchanged, so even a crash after the server answered cannot create a second record;\n * - 401/403 never touch a row, a permanent 4xx marks the row failed (only the user's Retry sends it again), nothing is ever deleted except\n * after a 2xx or the user's own Discard.\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineReplayer {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly store = inject(OfflineStore);\n private readonly http = inject(HttpClient);\n private readonly connection = inject(ConnectionStateService);\n private readonly toast = inject(ToastService);\n private readonly labels = inject(UiLabelsService);\n private readonly locks = inject(OFFLINE_LOCK_MANAGER);\n private readonly leaseStorage = inject(OFFLINE_LEASE_STORAGE);\n\n private readonly owner = generateUuid();\n private running: Promise<ReplayResult | null> | null = null;\n\n private readonly _syncing = signal(false);\n private readonly _pendingCount = signal(0);\n private readonly _failedCount = signal(0);\n private readonly _conflictCount = signal(0);\n private readonly _lastSyncAt = signal<number | null>(null);\n private readonly _syncTick = signal(0);\n private readonly _authBlocked = signal(false);\n private readonly _lastResult = signal<ReplayResult | null>(null);\n\n readonly syncing = this._syncing.asReadonly();\n /** Rows waiting to be sent (pending + being sent right now). */\n readonly pendingCount = this._pendingCount.asReadonly();\n readonly failedCount = this._failedCount.asReadonly();\n readonly conflictCount = this._conflictCount.asReadonly();\n readonly lastSyncAt = this._lastSyncAt.asReadonly();\n /** Bumped when a run changed server data (a row was delivered): open pages refresh on it. */\n readonly syncTick = this._syncTick.asReadonly();\n /** True after a 401/403 stopped a run: the rows are safe and wait for the user to sign in again. */\n readonly authBlocked = this._authBlocked.asReadonly();\n readonly lastResult = this._lastResult.asReadonly();\n /** Emits at the end of every run that did something. */\n readonly runCompleted$ = new Subject<{ trigger: ReplayTrigger; result: ReplayResult; changed: boolean }>();\n\n /** Sends everything that is due. Concurrent calls in this tab share one run; another tab's run makes this resolve null. */\n replayAll(trigger: ReplayTrigger): Promise<ReplayResult | null> {\n if (this.running) return this.running;\n return this.start(() => this.run(trigger, null));\n }\n\n /** Puts one row (any status, conflict and failed included) back to pending with 0 attempts and sends only that row. */\n async retryOne(id: string): Promise<ReplayResult | null> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return null;\n // One atomic step in the store: a row another run is sending right now (live claim) is left alone.\n const reset = await this.store.resetForRetry(id, userId);\n if (!reset) return null;\n if (this.running) await this.running;\n return this.start(() => this.run('manual', id));\n }\n\n /**\n * \"Keep my version\" for one conflict row: strips the configured stamp fields from its body, gives it a new idempotency key, puts it back to pending\n * and sends ONLY that row first (same claim / lock / ordering rules as `retryOne`). When that overwrite was DELIVERED (2xx, row deleted) it then starts\n * one normal full run (`replayAll('online')`, the run a reconnect starts), so the later changes to the same record that were held behind the conflict\n * and any other due change go out right away. If the overwrite did not go through, nothing else is started and the later changes stay held.\n * `applied` is false when nothing was changed: the feature is off, nobody is signed in, or the row is missing, foreign, no longer a conflict, or has no stamp field (nothing to overwrite). The later still-pending rows of the same record keep their stamp until the overwrite is delivered; the run that delivers it removes it from them (`stripStampsAfter`). When the run could not start (another tab holds the lock) `result` is null and the row stays pending: the next normal run sends it.\n * `outcome` tells the user what happened (`sent` / `shortly` / `failed`, null when not applied). `result` is the overwrite's own run; `followUp` is the normal run that came after it (null when none was started).\n */\n async keepMineOne(id: string): Promise<KeepMineRun> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n const fields = this.cfg.conflictStampFields;\n if (!userId || fields.length === 0) return { applied: false, result: null, followUp: null, outcome: null };\n const reset = await this.store.resetForKeepMine(id, userId, fields, generateUuid());\n if (!reset) return { applied: false, result: null, followUp: null, outcome: null };\n if (this.running) await this.running;\n const result = await this.start(() => this.run('manual', id));\n const after = await this.store.get(id);\n let followUp: ReplayResult | null = null;\n // Delivered = this run synced a row and the row is gone. The single-row run has ended (its lock is released), so this is never a nested run.\n const delivered = !!result && result.synced > 0 && after === null;\n if (delivered) followUp = await this.replayAll('online');\n return { applied: true, result, followUp, outcome: this.keepMineOutcome(delivered, result, after) };\n }\n\n /** sent = delivered; shortly = it is still queued (no run could start because another tab holds the lock, still pending / being sent, or waiting out a retry); failed = refused again or a new conflict. */\n private keepMineOutcome(delivered: boolean, result: ReplayResult | null, after: OfflineMutation | null): KeepMineOutcome {\n if (delivered) return 'sent';\n // The row is gone though this run synced nothing: a full run that was already in flight (or another tab's run) delivered it first.\n if (!after) return 'sent';\n if (!result) return 'shortly';\n return after.status === 'pending' || after.status === 'syncing' ? 'shortly' : 'failed';\n }\n\n /** Deletes one row of the signed-in user (the user chose to discard it). Resolves `true` when this call found and deleted the row, `false` when it was already gone (e.g. delivered meanwhile) or is not the user's. When that row was a stuck (failed / conflict) one with later pending changes of the same record behind it, one normal drain follows so they go out. */\n async discard(id: string): Promise<boolean> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return false;\n const row = await this.store.get(id);\n if (!row || row.userId !== userId) return false;\n await this.store.delete(id);\n await this.refreshCounts();\n // A discarded failed / conflict row no longer holds back later changes to the same record: send them now (the normal drain a reconnect starts:\n // run lock, back-off and \"still offline\" are respected). Nothing behind it = nothing to do (one cheap read, no run). The drain is NOT awaited:\n // discard resolves as soon as the row is gone (the drawer announces it at once); `drainSettled()` tells when the drain is over.\n if ((row.status === 'failed' || row.status === 'conflict') && row.entityType && row.entityId) {\n // The row IS gone: nothing that goes wrong while looking for / starting the drain may make discard reject (the caller would skip its refresh).\n try {\n const behind = (await this.store.list(userId)).some(r => r.id !== id && r.status === 'pending' && r.entityType === row.entityType && r.entityId === row.entityId);\n if (behind) {\n const drain: Promise<void> = this.drainAfterDiscard()\n .catch(() => { /* a failed drain leaves the rows queued; the next run sends them */ })\n .finally(() => { this.discardDrains.delete(drain); });\n this.discardDrains.add(drain);\n }\n } catch { /* the held change goes out on the next trigger */ }\n }\n return true;\n }\n\n private readonly discardDrains = new Set<Promise<void>>();\n\n /** Resolves when EVERY drain started by a `discard` (also overlapping ones) has finished; immediately when none is running. Never rejects. */\n async drainSettled(): Promise<void> {\n while (this.discardDrains.size > 0) await Promise.all([...this.discardDrains]);\n }\n\n /**\n * `replayAll('online')` joins a run that is already in flight, but that run decided up front which records are blocked and never looks at the\n * discarded record again. So when a run was in flight (a full run, or a single-row retry / keep-my-version run), one FRESH run follows it.\n */\n private async drainAfterDiscard(): Promise<void> {\n const inFlight = this.running;\n await this.replayAll('online');\n if (inFlight) await this.replayAll('online');\n }\n\n /** Deletes all rows of the signed-in user (the user chose to discard everything). */\n async discardAll(): Promise<void> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return;\n await this.store.deleteMutations(userId);\n this._authBlocked.set(false);\n await this.refreshCounts();\n }\n\n /** Re-reads the counts for the signed-in user (zeros when nobody is signed in or storage is unavailable). */\n async refreshCounts(): Promise<void> {\n const userId = this.cfg.getUserId();\n if (!userId || !this.store.available()) {\n this._pendingCount.set(0); this._failedCount.set(0); this._conflictCount.set(0);\n return;\n }\n const c = await this.store.countsByStatus(userId);\n if (this.cfg.getUserId() !== userId) return;\n this._pendingCount.set(c.pending + c.syncing);\n this._failedCount.set(c.failed);\n this._conflictCount.set(c.conflict);\n }\n\n clearAuthBlocked(): void {\n this._authBlocked.set(false);\n }\n\n /** Another tab delivered rows: open pages in this tab must refresh too. */\n noteRemoteSync(): void {\n this._syncTick.update(n => n + 1);\n }\n\n /** Forgets everything about the previous user (counts, last result); the stored rows are not touched. */\n resetView(): void {\n this._pendingCount.set(0); this._failedCount.set(0); this._conflictCount.set(0);\n this._lastResult.set(null); this._authBlocked.set(false);\n }\n\n // ---- run -----------------------------------------------------------------------------------------------------------------------\n\n private start(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n const p = this.exclusive(job).finally(() => { if (this.running === p) this.running = null; });\n this.running = p;\n return p;\n }\n\n private async exclusive(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n const name = `forgeroute-offline-replay:${this.cfg.dbName}`;\n if (this.locks) {\n try {\n return await this.locks.request(name, { ifAvailable: true }, async lock => (lock ? job() : null)) as ReplayResult | null;\n } catch (e) {\n // Opaque origins / some embedded views refuse the Web Locks API: use the lease instead. Errors of the job itself are not swallowed.\n if (!(e instanceof DOMException) || (e.name !== 'SecurityError' && e.name !== 'NotSupportedError')) throw e;\n }\n }\n return this.withLease(job);\n }\n\n private leaseKey(): string {\n return `forgeroute-offline-lease:${this.cfg.dbName}`;\n }\n\n private readLease(): { owner?: string; until?: number } | null {\n try {\n const parsed = JSON.parse(this.leaseStorage?.getItem(this.leaseKey()) ?? 'null') as { owner?: string; until?: number } | null;\n return parsed && typeof parsed === 'object' ? parsed : null;\n } catch {\n return null; // a corrupt value counts as no lease\n }\n }\n\n private tryAcquireLease(): boolean {\n const storage = this.leaseStorage;\n if (!storage) return true; // no shared storage: the in-tab mutex above is all there is\n try {\n const now = Date.now();\n const current = this.readLease();\n if (current && current.owner !== this.owner && typeof current.until === 'number' && current.until > now) return false;\n storage.setItem(this.leaseKey(), JSON.stringify({ owner: this.owner, until: now + LEASE_TTL_MS }));\n return this.readLease()?.owner === this.owner;\n } catch {\n return true; // storage refuses writes (quota / privacy mode): run anyway, the row claims still prevent double sending\n }\n }\n\n private releaseLease(): void {\n const storage = this.leaseStorage;\n if (!storage) return;\n try {\n if (this.readLease()?.owner === this.owner) storage.removeItem(this.leaseKey());\n } catch { /* nothing to release */ }\n }\n\n private async withLease(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n if (!this.tryAcquireLease()) return null;\n const heartbeat = this.leaseStorage ? setInterval(() => this.tryAcquireLease(), LEASE_REFRESH_MS) : null;\n try {\n return await job();\n } finally {\n if (heartbeat) clearInterval(heartbeat);\n this.releaseLease();\n }\n }\n\n private async run(trigger: ReplayTrigger, onlyId: string | null): Promise<ReplayResult | null> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId || !this.store.available()) return null;\n if (trigger !== 'manual' && this.connection.isOffline()) return null;\n\n this._syncing.set(true);\n const result: ReplayResult = { synced: 0, failed: 0, conflicts: 0, blockedByAuth: false };\n let attempted = 0;\n let changed = false;\n try {\n const all = await this.store.list(userId);\n const rows = onlyId ? all.filter(r => r.id === onlyId) : all;\n // Temp ids: which create rows are still queued, and what the server already answered for finished ones.\n const idMap = new Map<string, IdMapEntry>();\n for (const e of await this.store.listIdMap(userId)) idMap.set(e.tempId, e);\n const createsByTemp = new Map<string, OfflineMutation>();\n for (const r of all) if (r.tempId) createsByTemp.set(r.tempId, r);\n const blocked = new Set<string>();\n const entityOf = (r: OfflineMutation) => (r.entityType && r.entityId ? `${r.entityType}::${r.entityId}` : null);\n if (!onlyId) {\n // An older change that is stuck (failed / conflict) holds back later changes to the same record: an older PUT must never overwrite a newer one.\n for (const r of rows) {\n const k = entityOf(r);\n if (k && (r.status === 'failed' || r.status === 'conflict')) blocked.add(k);\n }\n }\n for (const row of rows) {\n if (this.cfg.getUserId() !== userId) break; // the user switched mid-run: the rest belongs to somebody else's session\n const ek = entityOf(row);\n if (!onlyId) {\n if (row.status === 'failed' || row.status === 'conflict') continue;\n if (ek && blocked.has(ek)) continue;\n if (row.status === 'pending' && row.nextAttemptAt !== undefined && row.nextAttemptAt > Date.now() && trigger !== 'manual') {\n if (ek) blocked.add(ek);\n continue;\n }\n }\n // A change that points at a record created offline waits for that create (never sent while it is still queued), and is failed without\n // being sent when the create can no longer provide the real id.\n const dependency = await this.checkDependencies(row, userId, idMap, createsByTemp);\n if (dependency === 'hold') { if (ek) blocked.add(ek); continue; }\n const claimed = await this.store.claim(row.id, this.owner);\n if (!claimed) { if (ek) blocked.add(ek); continue; }\n if (this.cfg.getUserId() !== userId) {\n // The session changed while the claim was being made: never send this row under another user's token. Give the claim back.\n await this.store.update(claimed.id, { status: 'pending', claimOwner: undefined, claimAt: undefined }, { ifOwner: this.owner });\n break;\n }\n attempted++;\n const outcome: Outcome = dependency === 'fail' ? { action: 'dependency' } : await this.send(claimed, idMap);\n const stop = await this.apply(claimed, outcome, result, idMap);\n if (outcome.action === 'ok') {\n changed = true;\n // A delivered \"Keep my version\" overwrite: only now do the later edits of the same record lose their stale stamp (see resetForKeepMine).\n if (claimed.overwrite && claimed.entityType && claimed.entityId && this.cfg.conflictStampFields.length > 0) {\n // The overwrite is already delivered: a failing strip must not turn that into an error (the later rows keep their stamp and conflict at worst).\n try { await this.store.stripStampsAfter(userId, claimed.entityType, claimed.entityId, claimed.seq, this.cfg.conflictStampFields); } catch { /* keep going */ }\n }\n }\n if (outcome.action !== 'ok' && ek) blocked.add(ek);\n if (stop) break;\n }\n } finally {\n this._syncing.set(false);\n }\n await this.refreshCounts();\n if (result.synced > 0 && !result.blockedByAuth) this._authBlocked.set(false);\n if (attempted > 0) {\n this._lastResult.set(result);\n if (result.synced + result.failed + result.conflicts > 0) this._lastSyncAt.set(Date.now());\n }\n if (changed) this._syncTick.update(n => n + 1);\n this.announce(result);\n if (attempted > 0) this.runCompleted$.next({ trigger, result, changed });\n return result;\n }\n\n /**\n * 'hold': a create this change points at is still pending / being sent (or waiting out a backoff): do not send it yet.\n * 'fail': a create it points at failed / conflicted, was discarded, or answered without a readable id: it can never be sent correctly.\n * Reads the store fresh for every create that has no mapping yet, so a run in another tab that just finished the create is seen.\n */\n private async checkDependencies(\n row: OfflineMutation, userId: string, idMap: Map<string, IdMapEntry>, createsByTemp: ReadonlyMap<string, OfflineMutation>,\n ): Promise<'ok' | 'hold' | 'fail'> {\n const deps = new Map<string, string | undefined>(); // temp id -> create row id\n (row.dependsOn ?? []).forEach((rowId, i) => {\n const tempId = row.dependsOnTempIds?.[i] ?? [...createsByTemp.values()].find(c => c.id === rowId)?.tempId;\n deps.set(tempId ?? `\\u0000${rowId}`, rowId);\n });\n for (const t of findTempIds(row.url, row.body, createsByTemp)) {\n if (t !== row.tempId && !deps.has(t)) deps.set(t, createsByTemp.get(t)?.id);\n }\n let hold = false;\n for (const [tempId, creatorId] of deps) {\n if (idMap.has(tempId)) continue;\n let creator = creatorId ? await this.store.get(creatorId) : null;\n if (creator && creator.userId !== userId) creator = null;\n if (creator) {\n if (creator.status === 'pending' || creator.status === 'syncing') hold = true;\n else return 'fail';\n continue;\n }\n const late = await this.store.getIdMapping(userId, tempId);\n if (late) { idMap.set(tempId, late); continue; }\n return 'fail';\n }\n return hold ? 'hold' : 'ok';\n }\n\n private async send(row: OfflineMutation, idMap: ReadonlyMap<string, IdMapEntry>): Promise<Outcome> {\n try {\n const real = new Map<string, string | number>();\n for (const [tempId, e] of idMap) real.set(tempId, e.numeric && String(Number(e.realId)) === e.realId ? Number(e.realId) : e.realId);\n const target = rewriteTempIds(row.url, row.body, real);\n const response = await firstValueFrom(this.http.request(row.method, target.url, {\n body: target.body,\n headers: { ...(row.headers ?? {}), [IDEMPOTENCY_HEADER]: row.key, [OFFLINE_REPLAY_HEADER]: '1' },\n observe: 'response',\n responseType: 'text',\n }));\n return { action: 'ok', text: typeof response.body === 'string' ? response.body : undefined };\n } catch (err) {\n return classifyReplay(err, this.cfg.idempotencyInProgressCode);\n }\n }\n\n /** Stores the outcome on the row (only while we still own the claim). Returns true when the run must stop. */\n private async apply(row: OfflineMutation, outcome: Outcome, result: ReplayResult, idMap: Map<string, IdMapEntry>): Promise<boolean> {\n const owner = { ifOwner: this.owner };\n const release = { claimOwner: undefined, claimAt: undefined };\n const err = (kind: MutationErrorKind, status: number | undefined, key: Parameters<UiLabelsService['t']>[0]): MutationError =>\n ({ kind, ...(status !== undefined ? { status } : {}), message: this.labels.t(key) });\n\n switch (outcome.action) {\n case 'ok':\n try {\n // Order matters: the mapping is saved BEFORE the create row is deleted. If this tab dies in between, the create is replayed with the same\n // Idempotency-Key (same answer, same real id) and the mapping is simply written again.\n if (row.tempId) {\n const real = this.readCreatedId(row, outcome.text);\n if (real !== undefined) idMap.set(row.tempId, await this.store.putIdMapping(row.userId, row.tempId, real));\n }\n await this.store.delete(row.id, owner);\n } catch {\n // Storage trouble after the server accepted it: give the row back (it is replayed safely with the same key) and stop this run.\n await this.store.update(row.id, { status: 'pending', ...release }, owner).catch(() => null);\n return true;\n }\n result.synced++;\n this._authBlocked.set(false);\n return false;\n case 'dependency':\n // Never sent: the id it points at is unknown. attempts is not counted; only the user's Retry (once the create is healthy) sends it.\n await this.store.update(row.id, { status: 'failed', ...release, nextAttemptAt: undefined, lastError: err('dependency', undefined, 'connection.error.dependency') }, owner);\n result.failed++;\n return false;\n case 'conflict':\n await this.store.update(row.id, { status: 'conflict', ...release, attempts: row.attempts + 1, lastError: err('conflict', outcome.status, 'connection.error.conflict') }, owner);\n result.conflicts++;\n return false;\n case 'rejected':\n await this.store.update(row.id, { status: 'failed', ...release, attempts: row.attempts + 1, lastError: err('rejected', outcome.status, 'connection.error.rejected') }, owner);\n result.failed++;\n return false;\n case 'auth':\n // The token is stale or the permission is gone: nothing is wrong with the data. Keep the row exactly as it was and stop.\n await this.store.update(row.id, { status: 'pending', ...release, lastError: err('auth', outcome.status, 'connection.authBlocked') }, owner);\n this._authBlocked.set(true);\n result.blockedByAuth = true;\n return true;\n case 'retry': {\n const message = outcome.kind === 'network' ? 'connection.error.network' : outcome.kind === 'timeout' ? 'connection.error.timeout' : 'connection.error.server';\n const lastError = err(outcome.kind, outcome.status || undefined, message);\n const stillOffline = outcome.status === 0 && this.connection.isOffline();\n if (stillOffline) {\n await this.store.update(row.id, { status: 'pending', ...release, lastError }, owner);\n return true;\n }\n const attempts = row.attempts + 1;\n if (attempts >= this.cfg.maxAttempts) {\n await this.store.update(row.id, { status: 'failed', ...release, attempts, nextAttemptAt: undefined, lastError }, owner);\n result.failed++;\n } else {\n await this.store.update(row.id, { status: 'pending', ...release, attempts, nextAttemptAt: Date.now() + (outcome.retryAfterMs ?? backoffMs(attempts)), lastError }, owner);\n }\n return outcome.kind !== 'server'; // no answer at all: still offline, stop; a 5xx / 429 only holds back this record\n }\n }\n }\n\n /** The server's id for a created record: the answer text parsed as JSON (undefined when empty / not JSON) run through `config.createdId`. */\n private readCreatedId(row: OfflineMutation, text: string | undefined): string | number | undefined {\n let body: unknown;\n try { body = text ? JSON.parse(text) : undefined; } catch { body = undefined; }\n return this.cfg.createdId(body, row);\n }\n\n private announce(result: ReplayResult): void {\n const attention = result.failed + result.conflicts;\n if (attention > 0) this.toast.warning(this.labels.t(attention === 1 ? 'connection.needAttention.one' : 'connection.needAttention.other', { count: attention }));\n else if (result.synced > 0 && !result.blockedByAuth) this.toast.success(this.labels.t('connection.synced'));\n }\n}\n","import { HttpContextToken } from '@angular/common/http';\n\n/**\n * Per-request client timeout in ms, set through `HttpContext`: `http.get(url, { context: new HttpContext().set(REQUEST_TIMEOUT_MS, 120000) })`.\n * `null` (default) = the configured read / write / long timeout. A value of 0 or less switches the timeout off for that request.\n */\nexport const REQUEST_TIMEOUT_MS = new HttpContextToken<number | null>(() => null);\n\n/**\n * Marks ONE request as long-running, whatever its URL: `http.get('/api/x?size=10000', { context: new HttpContext().set(REQUEST_LONG, true) })`.\n * Same effect as a `longRequests` match, a blob download or an upload: it uses the long timeout (unless `REQUEST_TIMEOUT_MS` overrides it), is not\n * counted in the slow-answer rule, never arms the \"stuck\" timer (so no \"Slow connection\" banner) and a failed read is not retried automatically.\n * `longRequests` matches the URL WITHOUT its query string, so a request that is long only because of its parameters (a table Export asking for\n * 10,000 rows) needs this token, set by the host app in an HTTP interceptor placed BEFORE the offline interceptors.\n */\nexport const REQUEST_LONG = new HttpContextToken<boolean>(() => false);\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport {\n IDEMPOTENCY_HEADER, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, isInScope, isMutationMethod, resolveConfigCached,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\n\n/**\n * Gives every write under `apiPrefix` an `Idempotency-Key: <uuid>` unless the caller already set one (callers that must keep ONE key across\n * user retries set it themselves). The same key goes on the queued row and on every replay, so the server can recognise a repeat.\n * Left alone: reads, skipped URLs, FormData bodies, and replays (`X-Offline-Replay`, which already carry the row's key).\n */\nexport const idempotencyInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (!isMutationMethod(req.method)) return next(req);\n if (req.headers.has(OFFLINE_REPLAY_HEADER)) return next(req);\n if (!isInScope(req.url, cfg)) return next(req);\n if (typeof FormData !== 'undefined' && req.body instanceof FormData) return next(req);\n if (req.headers.has(IDEMPOTENCY_HEADER)) return next(req);\n return next(req.clone({ setHeaders: { [IDEMPOTENCY_HEADER]: generateUuid() } }));\n};\n","import { HttpErrorResponse, HttpEvent, HttpInterceptorFn, HttpResponse } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { Observable, defer, throwError, timer } from 'rxjs';\nimport { finalize, retry, tap, timeout } from 'rxjs/operators';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport {\n OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, isInScope, matchesAny, resolveConfigCached,\n} from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { RequestTimeoutError, isRequestTimeoutError } from './errors';\nimport { REQUEST_LONG, REQUEST_TIMEOUT_MS } from './request-timeout';\n\n/** Pause before the single automatic retry of a read that failed without an answer. */\nexport const READ_RETRY_DELAY_MS = 1000;\n\nexport function isNetworkFailure(err: unknown): boolean {\n return isRequestTimeoutError(err) || (err instanceof HttpErrorResponse && err.status === 0);\n}\n\n/**\n * Measures every API request (feeds ConnectionStateService), applies the client timeout and retries a failed READ once.\n * A write is never retried here: after a timeout or status 0 its outcome is unknown, so the user decides (the same Idempotency-Key makes\n * a retry safe). Sits closest to the network so the offline interceptor sees timeouts and failures as errors.\n */\nexport const connectionInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (!isInScope(req.url, cfg)) return next(req);\n\n const connection = inject(ConnectionStateService);\n const labels = inject(UiLabelsService);\n const method = req.method.toUpperCase();\n const isRead = method === 'GET' || method === 'HEAD' || method === 'OPTIONS';\n const long = req.responseType === 'blob' || req.responseType === 'arraybuffer' || req.reportProgress\n || (typeof FormData !== 'undefined' && req.body instanceof FormData) || matchesAny(req.url, cfg.longRequests) || req.context.get(REQUEST_LONG) === true;\n const override = req.context.get(REQUEST_TIMEOUT_MS);\n const timeoutMs = override !== null && override !== undefined ? override : long ? cfg.timeouts.long : isRead ? cfg.timeouts.read : cfg.timeouts.write;\n // The marker only exists for the interceptors in front of this one; the network does not need to hear about it.\n const outgoing = req.headers.has(OFFLINE_REPLAY_HEADER) ? req.clone({ headers: req.headers.delete(OFFLINE_REPLAY_HEADER) }) : req;\n\n const attempt = (): Observable<HttpEvent<unknown>> => defer(() => {\n const end = connection.beginRequest({ long });\n const started = Date.now();\n let outcome: { status: number; ok: boolean; timedOut: boolean } | null = null;\n let stream: Observable<HttpEvent<unknown>> = next(outgoing);\n if (timeoutMs > 0) {\n stream = stream.pipe(timeout({\n each: timeoutMs,\n with: () => throwError(() => new RequestTimeoutError(labels.t(isRead ? 'connection.timeout.read' : 'connection.timeout.write'), method, req.urlWithParams, !isRead)),\n }));\n }\n return stream.pipe(\n tap({\n next: ev => { if (ev instanceof HttpResponse) outcome = { status: ev.status, ok: ev.ok, timedOut: false }; },\n error: err => {\n if (isRequestTimeoutError(err)) outcome = { status: 0, ok: false, timedOut: true };\n else if (err instanceof HttpErrorResponse) outcome = { status: err.status, ok: false, timedOut: false };\n },\n }),\n finalize(() => {\n end();\n if (outcome) {\n connection.recordRequest({\n durationMs: Math.max(0, Date.now() - started), ok: outcome.ok, status: outcome.status, timedOut: outcome.timedOut, method, long,\n });\n }\n }),\n );\n });\n\n if (!isRead || long) return attempt();\n return attempt().pipe(retry({\n count: 1,\n delay: err => (isNetworkFailure(err) && connection.state() !== 'offline' ? timer(READ_RETRY_DELAY_MS) : throwError(() => err)),\n }));\n};\n","import { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Injectable, inject, signal } from '@angular/core';\nimport { ToastService, UiLabelsService } from '@forgeroute/ui';\nimport { OFFLINE_SUPPORT_CONFIG, hasStampField, resolveConfig } from '../config/offline-config';\nimport { KeepMineOutcome, OfflineReplayer, ReplayResult, ReplayTrigger } from '../replay/offline-replayer';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { StaleDataService } from '../state/stale-data.service';\nimport { OfflineMutation, OfflineStore } from '../store/offline-store';\n\n/** What tabs tell each other: `changed` = the saved changes changed (re-read them), `synced` = rows were delivered (refresh open pages). */\nexport type CrossTabMessage = { type: 'changed' } | { type: 'synced' };\n\n/** Creates the cross-tab channel; null when the browser has no BroadcastChannel (the focus / visibility poll still keeps tabs in step). */\nexport function createChannel(name: string): BroadcastChannel | null {\n try {\n return typeof BroadcastChannel === 'function' ? new BroadcastChannel(name) : null;\n } catch {\n return null;\n }\n}\n\n/** `keepMine` was refused: `disabled` = `conflictStampFields` is empty, `notFound` = no such row for the signed-in user, `notConflict` = the row is not in status conflict, `noStamp` = its body has none of the configured stamp fields (nothing to overwrite). */\nexport class KeepMineError extends Error {\n constructor(readonly reason: 'disabled' | 'notFound' | 'notConflict' | 'noStamp', message: string) {\n super(message);\n this.name = 'KeepMineError';\n Object.setPrototypeOf(this, KeepMineError.prototype);\n }\n}\n\n/**\n * What the app talks to: counts, the list for the pending-changes drawer, Sync now / Retry / Discard, and the session helpers.\n * Everything is scoped to `config.getUserId()`; nothing here ever deletes saved changes unless the user chose it\n * (`discard`, `discardAll`, `endSession({ discardPending: true })` after the app asked the user).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineSupportService {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly store = inject(OfflineStore);\n private readonly replayer = inject(OfflineReplayer);\n private readonly connection = inject(ConnectionStateService);\n private readonly stale = inject(StaleDataService);\n private readonly toast = inject(ToastService);\n private readonly labels = inject(UiLabelsService);\n private readonly doc = inject(DOCUMENT);\n private readonly destroyRef = inject(DestroyRef);\n\n private readonly _rows = signal<readonly OfflineMutation[]>([]);\n private readonly _lastQueued = signal<{ label: string; at: number } | null>(null);\n private readonly _storageAvailable = signal(true);\n\n readonly pendingCount = this.replayer.pendingCount;\n readonly failedCount = this.replayer.failedCount;\n readonly conflictCount = this.replayer.conflictCount;\n readonly syncing = this.replayer.syncing;\n readonly lastSyncAt = this.replayer.lastSyncAt;\n readonly syncTick = this.replayer.syncTick;\n readonly authBlocked = this.replayer.authBlocked;\n readonly lastResult = this.replayer.lastResult;\n /** The signed-in user's saved changes, oldest first, for the drawer. Updates when another tab changes them. */\n readonly rows = this._rows.asReadonly();\n /** The most recent change saved on this device while offline ({ label, at }). */\n readonly lastQueued = this._lastQueued.asReadonly();\n /** False when IndexedDB could not be opened on this device (set after the store initialised): the drawer then must not say \"all synced\". */\n readonly storageAvailable = this._storageAvailable.asReadonly();\n\n private started = false;\n private channel: BroadcastChannel | null = null;\n private refreshing: Promise<void> | null = null;\n private dirty = false;\n private lastKnownUserId: string | null = null;\n private cleanups: (() => void)[] = [];\n private retryTimer: ReturnType<typeof setTimeout> | null = null;\n private destroyed = false;\n\n /** Wires the triggers (called by `provideOfflineSupport`'s initializer; calling it again does nothing). Resolves when the first read is done. */\n async start(): Promise<void> {\n if (this.started) return;\n this.started = true;\n await this.store.init();\n this._storageAvailable.set(this.store.available());\n\n this.channel = createChannel(`forgeroute-offline:${this.cfg.dbName}`);\n if (this.channel) {\n const channel = this.channel;\n channel.onmessage = ev => this.onRemote(ev.data as CrossTabMessage);\n this.cleanups.push(() => { channel.onmessage = null; channel.close(); });\n }\n const win = this.doc.defaultView;\n if (win) {\n const poll = () => { if (this.doc.visibilityState !== 'hidden') void this.refresh(); };\n win.addEventListener('focus', poll);\n this.doc.addEventListener('visibilitychange', poll);\n this.cleanups.push(() => { win.removeEventListener('focus', poll); this.doc.removeEventListener('visibilitychange', poll); });\n }\n const subs = [\n this.connection.recovered$.subscribe(trigger => this.replay(trigger)),\n this.store.mutated$.subscribe(() => { void this.refresh(); this.post({ type: 'changed' }); }),\n this.replayer.runCompleted$.subscribe(({ changed }) => { if (changed) this.post({ type: 'synced' }); }),\n // A run that ended with rows still waiting out a backoff must schedule their next try (nothing else would).\n this.replayer.runCompleted$.subscribe(() => { void this.refresh(); }),\n ];\n this.cleanups.push(() => subs.forEach(s => s.unsubscribe()));\n this.destroyRef.onDestroy(() => {\n this.destroyed = true;\n this.clearRetryTimer();\n this.cleanups.forEach(c => c()); this.cleanups = []; this.channel = null;\n });\n\n await this.refresh();\n if (this.connection.isOnline() && this.cfg.getUserId()) this.replay('start');\n }\n\n /** Starts a replay run without ever leaving an unhandled rejection behind. */\n private replay(trigger: ReplayTrigger): void {\n void this.replayer.replayAll(trigger).catch(() => undefined);\n }\n\n private clearRetryTimer(): void {\n if (this.retryTimer) { clearTimeout(this.retryTimer); this.retryTimer = null; }\n }\n\n /**\n * Rows that failed with a transient error wait for `nextAttemptAt`. Nothing else triggers a run while the connection stays `online`, so a timer\n * fires one replay when the earliest of them is due.\n */\n private scheduleRetry(): void {\n this.clearRetryTimer();\n if (this.destroyed) return;\n let earliest: number | null = null;\n for (const r of this._rows()) {\n if (r.status === 'pending' && r.nextAttemptAt !== undefined && (earliest === null || r.nextAttemptAt < earliest)) earliest = r.nextAttemptAt;\n }\n if (earliest === null) return;\n this.retryTimer = setTimeout(() => {\n this.retryTimer = null;\n // While offline (or signed out) nothing is sent; the recovery trigger replays everything that is due once the connection is back.\n if (this.cfg.getUserId() && this.connection.isOnline()) this.replay('online');\n }, Math.max(0, earliest - Date.now()) + 50);\n }\n\n private post(msg: CrossTabMessage): void {\n try { this.channel?.postMessage(msg); } catch { /* channel closed */ }\n }\n\n private onRemote(msg: CrossTabMessage | null): void {\n if (!msg) return;\n if (msg.type === 'synced') this.replayer.noteRemoteSync();\n void this.refresh();\n }\n\n /** Called by the offline interceptor after a write was saved on the device. */\n onQueued(row: OfflineMutation): void {\n this.lastKnownUserId = row.userId;\n this._lastQueued.set({ label: row.label, at: Date.now() });\n this.toast.info(this.labels.t('connection.savedOnDevice'));\n void this.refresh();\n }\n\n /** Re-reads the rows and counts. Calls that overlap are merged into one extra read. */\n refresh(): Promise<void> {\n if (this.refreshing) { this.dirty = true; return this.refreshing; }\n const p = this.doRefresh().finally(() => { this.refreshing = null; });\n this.refreshing = p;\n return p;\n }\n\n private async doRefresh(): Promise<void> {\n do {\n this.dirty = false;\n const userId = this.cfg.getUserId();\n if (!userId) {\n this._rows.set([]);\n } else {\n this.lastKnownUserId = userId;\n await this.store.init();\n const rows = await this.store.list(userId);\n if (this.cfg.getUserId() !== userId) { this.dirty = true; continue; }\n this._rows.set(rows);\n }\n await this.replayer.refreshCounts();\n } while (this.dirty);\n this.scheduleRetry();\n }\n\n /** \"Sync now\": sends everything due, even rows waiting out a backoff. */\n async syncNow(): Promise<ReplayResult | null> {\n const result = await this.replayer.replayAll('manual');\n await this.refresh();\n return result;\n }\n\n async retry(id: string): Promise<void> {\n await this.replayer.retryOne(id);\n await this.refresh();\n }\n\n /** True when \"Keep my version\" can be offered for this row: the feature is on (`conflictStampFields` not empty), the row is a conflict, and its body has at least one stamp field. */\n canKeepMine(row: OfflineMutation): boolean {\n return this.cfg.conflictStampFields.length > 0 && row.status === 'conflict' && hasStampField(row.body, this.cfg.conflictStampFields);\n }\n\n /**\n * The user chose \"Keep my version\" for a conflict row: the stamp fields are removed from its body, it gets a new idempotency key, goes back to pending and\n * only that row is sent first and, once it is delivered, one normal sync follows (later changes to the same record and other due changes go out). Last write wins here, by the user's explicit choice (the server can no longer detect a newer edit, so no second 409 for the stamp).\n * Resolves with what happened: `sent` (delivered), `shortly` (still queued: another tab holds the sync lock, or it waits for a retry) or `failed` (refused again or a new conflict; the change stays saved on the device).\n * Throws `KeepMineError` when the feature is off, the row does not exist, it is not in status `conflict`, or its body has no stamp field (`noStamp`; same rule as `canKeepMine`).\n */\n async keepMine(id: string): Promise<KeepMineOutcome> {\n if (this.cfg.conflictStampFields.length === 0) throw new KeepMineError('disabled', this.labels.t('connection.conflict.error.disabled'));\n const userId = this.cfg.getUserId();\n await this.store.init();\n const row = userId ? await this.store.get(id) : null;\n if (!row || row.userId !== userId) throw new KeepMineError('notFound', this.labels.t('connection.conflict.error.notFound'));\n if (row.status !== 'conflict') throw new KeepMineError('notConflict', this.labels.t('connection.conflict.error.notConflict'));\n if (!hasStampField(row.body, this.cfg.conflictStampFields)) throw new KeepMineError('noStamp', this.labels.t('connection.conflict.error.noStamp'));\n const { applied, outcome } = await this.replayer.keepMineOne(id);\n await this.refresh();\n if (!applied || !outcome) throw new KeepMineError('notConflict', this.labels.t('connection.conflict.error.notConflict'));\n return outcome;\n }\n\n /** Rows the USER discarded (id -> when), set before the row is deleted so a reader that sees the row leave can tell a discard from a delivery. */\n private readonly discardedIds = new Map<string, number>();\n\n /** A discard mark only matters while its row leaves the list; it expires after this many ms (and the map is emptied when it grows past 500). */\n private static readonly DISCARD_MARK_MS = 60_000;\n\n /** True when the row with this id left the list because the user discarded it (not because it was delivered). */\n wasDiscarded(id: string): boolean {\n const at = this.discardedIds.get(id);\n if (at === undefined) return false;\n if (Date.now() - at > OfflineSupportService.DISCARD_MARK_MS) { this.discardedIds.delete(id); return false; }\n return true;\n }\n\n private markDiscarded(ids: string[]): void {\n if (this.discardedIds.size > 500) this.discardedIds.clear();\n const now = Date.now();\n for (const id of ids) this.discardedIds.set(id, now);\n }\n\n async discard(id: string): Promise<void> {\n // Only a row that really exists (and is this user's) can be discarded; a row that is already gone (delivered meanwhile) gets no mark.\n const userId = this.cfg.getUserId();\n const existing = userId ? await this.store.get(id) : undefined;\n if (!existing || existing.userId !== userId) { await this.replayer.discard(id); await this.refresh(); return; }\n this.markDiscarded([id]);\n try {\n // The row can be delivered between the check above and the delete: then nothing was discarded and the mark must not stay.\n if (!(await this.replayer.discard(id))) this.discardedIds.delete(id);\n } catch (e) { this.discardedIds.delete(id); throw e; }\n await this.refresh();\n }\n\n async discardAll(): Promise<void> {\n const userId = this.cfg.getUserId();\n const ids = userId ? (await this.store.list(userId)).map(r => r.id) : [];\n this.markDiscarded(ids);\n try { await this.replayer.discardAll(); } catch (e) { for (const id of ids) this.discardedIds.delete(id); throw e; }\n await this.refresh();\n }\n\n // ---- session helpers -----------------------------------------------------------------------------------------------------------\n\n /**\n * Call in logout BEFORE signing out. `pending` = changes not yet delivered (waiting or being sent), `failed` = changes that need attention\n * (failed or conflict). When `pending + failed > 0` show a ConfirmService dialog with `connection.logoutPending.one` / `connection.logoutPending.other`; then call\n * `endSession({ discardPending })` with the user's choice. Nothing is deleted here.\n */\n async beforeSessionEnd(): Promise<{ pending: number; failed: number }> {\n const userId = this.cfg.getUserId() ?? this.lastKnownUserId;\n if (!userId) return { pending: 0, failed: 0 };\n await this.store.init();\n if (!this.store.available()) return { pending: 0, failed: 0 };\n const c = await this.store.countsByStatus(userId);\n return { pending: c.pending + c.syncing, failed: c.failed + c.conflict };\n }\n\n /** The signed-in user changed (sign-in, switch): re-scope the view to them and send what they have waiting. */\n async onSessionStart(userId: string): Promise<void> {\n this.lastKnownUserId = userId;\n this.replayer.resetView();\n this._lastQueued.set(null);\n this.stale.clear();\n await this.refresh();\n if (this.cfg.getUserId() === userId) this.replay('start');\n }\n\n /**\n * Called by the offline interceptor for every in-scope request: when the signed-in user is not the one the view was built for (the app never\n * called `onSessionStart`), forget the previous user's rows and counts and re-read for the new one.\n */\n ensureScope(): void {\n const current = this.cfg.getUserId();\n if (current === this.lastKnownUserId) return;\n if (this.lastKnownUserId === null) {\n // First sight of a user: nothing from a previous user can be on screen yet, so only read their rows.\n this.lastKnownUserId = current;\n void this.refresh();\n return;\n }\n this.replayer.resetView();\n this._rows.set([]);\n this._lastQueued.set(null);\n this.stale.clear();\n this.lastKnownUserId = current;\n void this.refresh();\n }\n\n /**\n * The user signed out. By default NOTHING is deleted: the saved changes and the device copy stay for that user and are sent when they sign in again.\n * Only `discardPending: true` (the app asked the user first) deletes that one user's changes and device copy. Other users' data is never touched.\n * `userId` names the user who is leaving; pass it when the app already switched to somebody else (impersonation, portal logout), otherwise the\n * user the view was last built for is used.\n */\n async endSession(options: { discardPending: boolean; userId?: string }): Promise<void> {\n const userId = options.userId ?? this.lastKnownUserId ?? this.cfg.getUserId();\n if (options.discardPending && userId) await this.store.clearUser(userId);\n this._rows.set([]);\n this._lastQueued.set(null);\n this.replayer.resetView();\n this.stale.clear();\n }\n\n /**\n * Empties the device copy of every user's GET answers and the in-memory view. Saved changes are kept unless `discardPending` is true, which wipes\n * them for EVERY user: only for a deliberate full reset the user confirmed, never at logout.\n */\n async clearAll(options: { discardPending?: boolean } = {}): Promise<void> {\n if (options.discardPending) await this.store.clearAll();\n else await this.store.clearCache();\n this._rows.set([]);\n this._lastQueued.set(null);\n this.replayer.resetView();\n this.stale.clear();\n }\n}\n","import { HttpErrorResponse, HttpEvent, HttpHeaders, HttpInterceptorFn, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http';\nimport { Injector, inject } from '@angular/core';\nimport { Observable, from, of, throwError } from 'rxjs';\nimport { catchError, switchMap, tap } from 'rxjs/operators';\nimport { UiLabelsService, uiText } from '@forgeroute/ui';\nimport {\n DEFAULT_DETAIL_TTL_MS, DEFAULT_LIST_TTL_MS, FROM_CACHE_HEADER, IDEMPOTENCY_HEADER, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG,\n QueueRule, ResolvedOfflineConfig, deriveEntity, invalidationPrefix, isInScope, isMutationMethod, lastSegmentIsId, matchesAny, matchesUrl,\n pathAndQuery, pathOnly, resolveConfigCached,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { StaleDataService } from '../state/stale-data.service';\nimport { OfflineMutation, OfflineStore } from '../store/offline-store';\nimport { findTempIds, isTempIdCreate } from '../store/temp-ids';\nimport { OfflineSupportService } from '../support/offline-support.service';\nimport { OfflineBlockedError } from './errors';\nimport { isNetworkFailure } from './connection.interceptor';\n\nconst FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded;charset=UTF-8';\n\n/** Header names that must never be copied onto a queued row, whatever `replayHeaders` says: the live token is attached at replay time. */\nconst NEVER_STORED_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];\n\nfunction isUploadBody(body: unknown): boolean {\n return (typeof FormData !== 'undefined' && body instanceof FormData)\n || (typeof Blob !== 'undefined' && body instanceof Blob)\n || body instanceof ArrayBuffer\n || ArrayBuffer.isView(body);\n}\n\nfunction isFormBody(body: unknown): body is HttpParams | URLSearchParams {\n return body instanceof HttpParams || (typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams);\n}\n\n/** A structured-clone-safe copy of the JSON body (undefined values dropped), or `undefined` when it cannot be stored. */\nfunction storableBody(body: unknown): { ok: true; value: unknown } | { ok: false } {\n if (body === null || body === undefined) return { ok: true, value: null };\n if (isFormBody(body)) return { ok: true, value: body.toString() };\n if (typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean') return { ok: true, value: body };\n try {\n return { ok: true, value: JSON.parse(JSON.stringify(body)) };\n } catch {\n return { ok: false };\n }\n}\n\n/**\n * The label a queued change gets when no rule writes one: \"Add lots\" / \"Update lots\" / \"Delete lots\" (the entity is the URL's own word, \"item\" when the\n * URL has none). It is written in the language active when the change is queued and saved on the row as such - a row stored before a language\n * switch keeps its old wording.\n */\nfunction defaultLabel(labels: UiLabelsService, method: string, url: string): string {\n const key = method === 'POST' ? 'connection.defaultLabel.add' : method === 'DELETE' ? 'connection.defaultLabel.delete' : 'connection.defaultLabel.update';\n const segments = pathOnly(url).split('/').filter(Boolean);\n const entity = deriveEntity(url).entityType ?? segments[segments.length - 1] ?? labels.t('connection.entityFallback');\n return labels.t(key, { entity });\n}\n\nfunction findRule(rules: readonly QueueRule[], req: HttpRequest<unknown>): QueueRule | undefined {\n const target = pathAndQuery(req.urlWithParams);\n const method = req.method.toUpperCase();\n return rules.find(r => {\n r.pattern.lastIndex = 0;\n const hit = r.pattern.test(target);\n r.pattern.lastIndex = 0;\n return hit && r.methods.some(m => m.toUpperCase() === method);\n });\n}\n\nfunction safeHeaders(req: HttpRequest<unknown>, cfg: ResolvedOfflineConfig, formBody: boolean): Record<string, string> | undefined {\n const out: Record<string, string> = {};\n const contentType = req.headers.get('Content-Type');\n if (contentType && !/^application\\/json/i.test(contentType)) out['Content-Type'] = contentType;\n else if (formBody) out['Content-Type'] = FORM_CONTENT_TYPE;\n for (const name of cfg.replayHeaders) {\n if (NEVER_STORED_HEADERS.includes(name.toLowerCase())) continue;\n const value = req.headers.get(name);\n if (value !== null) out[name] = value;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Reads: network first; the answer is also stored (per user) unless excluded; while offline/unreachable, or when the request fails with no\n * answer, the stored copy is served (header `X-From-Offline-Cache: <cachedAt>`, StaleDataService told) and otherwise the error is rethrown.\n * Writes while offline/unreachable: blocked (OfflineBlockedError) or saved on the device with the request's Idempotency-Key and answered with a\n * typed synthetic 202. Writes while online pass through; a write with an unknown outcome (timeout / status 0 while the browser is online) is\n * never queued automatically.\n */\nexport const offlineInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (req.headers.has(OFFLINE_REPLAY_HEADER) || !isInScope(req.url, cfg)) return next(req);\n // A changed signed-in user must not keep showing the previous user's saved changes: re-scope the view (cheap no-op when unchanged).\n inject(OfflineSupportService).ensureScope();\n if (req.method === 'GET') return handleRead(req, next, cfg);\n if (isMutationMethod(req.method)) return handleWrite(req, next, cfg);\n return next(req);\n};\n\nfunction cachedResponse(req: HttpRequest<unknown>, data: unknown, cachedAt: number): HttpResponse<unknown> {\n return new HttpResponse({\n body: data, status: 200, statusText: 'OK', url: req.urlWithParams,\n headers: new HttpHeaders({ [FROM_CACHE_HEADER]: String(cachedAt) }),\n });\n}\n\nfunction handleRead(req: HttpRequest<unknown>, next: (r: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>, cfg: ResolvedOfflineConfig): Observable<HttpEvent<unknown>> {\n const userId = cfg.getUserId();\n if (userId === null || req.responseType !== 'json' || matchesAny(req.url, cfg.neverCache)) return next(req);\n\n const connection = inject(ConnectionStateService);\n const store = inject(OfflineStore);\n const stale = inject(StaleDataService);\n const key = pathAndQuery(req.urlWithParams);\n const ttl = cfg.cacheTtl ? cfg.cacheTtl(req.url) : lastSegmentIsId(req.url) ? DEFAULT_DETAIL_TTL_MS : DEFAULT_LIST_TTL_MS;\n\n const live = (): Observable<HttpEvent<unknown>> => next(req).pipe(tap(ev => {\n if (!(ev instanceof HttpResponse) || ev.status !== 200) return;\n stale.clearKey(key);\n const noStore = (ev.headers.get('Cache-Control') ?? '').toLowerCase().includes('no-store');\n if (!noStore && ev.body !== null && ev.body !== undefined) void store.cacheResponse(key, userId, ev.body, ttl).catch(() => undefined);\n }));\n\n const serveCopyOr = (otherwise: () => Observable<HttpEvent<unknown>>): Observable<HttpEvent<unknown>> =>\n from(store.getCached(key, userId)).pipe(switchMap(entry => {\n if (!entry) return otherwise();\n stale.markStale(entry.cachedAt, key);\n return of(cachedResponse(req, entry.data, entry.cachedAt));\n }));\n\n if (connection.isOffline()) {\n return serveCopyOr(() => connection.state() === 'unreachable'\n ? live() // nothing saved: try the network anyway, it may be back\n : throwError(() => new HttpErrorResponse({ url: req.urlWithParams, status: 0, statusText: 'Offline', error: uiText('connection.noCopy') })));\n }\n return live().pipe(catchError(err => isNetworkFailure(err) ? serveCopyOr(() => throwError(() => err)) : throwError(() => err)));\n}\n\nfunction handleWrite(req: HttpRequest<unknown>, next: (r: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>, cfg: ResolvedOfflineConfig): Observable<HttpEvent<unknown>> {\n const connection = inject(ConnectionStateService);\n const userId = cfg.getUserId();\n\n if (!connection.isOffline() || userId === null) {\n if (userId === null) return next(req);\n const store = inject(OfflineStore);\n return next(req).pipe(tap(ev => {\n if (ev instanceof HttpResponse && ev.ok) void store.invalidatePrefix(invalidationPrefix(req.url), userId).catch(() => undefined);\n }));\n }\n\n const labels = inject(UiLabelsService);\n const block = cfg.blockOffline.find(b => matchesUrl(req.urlWithParams, b.pattern));\n if (block) {\n return throwError(() => new OfflineBlockedError(block.message ?? labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'blocked'));\n }\n if (isUploadBody(req.body)) {\n return throwError(() => new OfflineBlockedError(labels.t('connection.uploadBlocked'), 'upload'));\n }\n let rule: QueueRule | undefined;\n if (cfg.allowQueue) {\n rule = findRule(cfg.allowQueue, req);\n if (!rule) return throwError(() => new OfflineBlockedError(labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'not-allowed'));\n }\n const body = storableBody(req.body);\n if (!body.ok) return throwError(() => new OfflineBlockedError(labels.t('connection.storageUnavailable'), 'storage'));\n\n const store = inject(OfflineStore);\n const support = inject(OfflineSupportService);\n const method = req.method.toUpperCase();\n const url = req.urlWithParams;\n const derived = deriveEntity(url);\n const row = {\n id: generateUuid(),\n userId,\n key: req.headers.get(IDEMPOTENCY_HEADER) ?? generateUuid(),\n method,\n url,\n body: body.value,\n headers: safeHeaders(req, cfg, isFormBody(req.body)),\n label: rule?.label?.(method, url, req.body, { injector: inject(Injector) }) ?? defaultLabel(labels, method, url),\n entityType: rule?.entityType?.(url) ?? derived.entityType,\n entityId: derived.entityId,\n createdAt: Date.now(),\n status: 'pending' as const,\n attempts: 0,\n };\n // A create gets its own id as the temp id; a change that refers to the temp id of a create that is still queued remembers that create.\n const tempId = isTempIdCreate(method, url, body.value) ? row.id : undefined;\n return from(store.list(userId).catch((): OfflineMutation[] => [])).pipe(\n switchMap(existing => {\n const creates = new Map<string, string>();\n for (const r of existing) if (r.tempId) creates.set(r.tempId, r.id);\n const refs = findTempIds(url, body.value, creates);\n return store.addMutation({\n ...row,\n ...(tempId ? { tempId } : {}),\n ...(refs.length > 0 ? { dependsOn: refs.map(t => creates.get(t) as string), dependsOnTempIds: refs } : {}),\n });\n }),\n catchError(() => throwError(() => new OfflineBlockedError(labels.t('connection.storageUnavailable'), 'storage'))),\n switchMap(saved => {\n // The same key already belongs to a row that will never be sent again (failed / conflict): answering \"saved\" would be a fake success.\n if (saved.status === 'failed' || saved.status === 'conflict') {\n return throwError(() => new OfflineBlockedError(labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'not-allowed'));\n }\n support.onQueued(saved);\n return of(saved);\n }),\n switchMap(saved => {\n const base = body.value !== null && typeof body.value === 'object' && !Array.isArray(body.value) ? body.value as Record<string, unknown> : {};\n return of(new HttpResponse<unknown>({\n status: 202, statusText: 'Accepted', url,\n body: { ...base, id: base['id'] ?? saved.tempId ?? saved.id, _offline: true },\n }));\n }),\n );\n}\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { connectionInterceptor } from './connection.interceptor';\nimport { idempotencyInterceptor } from './idempotency.interceptor';\nimport { offlineInterceptor } from './offline.interceptor';\n\n/**\n * Register LAST in `withInterceptors([... ,...offlineHttpInterceptors])` (after errorContext and the app's own auth interceptor; replays carry\n * `X-Offline-Replay`, so an app whose auth interceptor sits after these still gets the live token on replays).\n *\n * Array order is outermost first: idempotency (adds the key) -> offline (queue / device copy) -> connection (timeout, timing, GET retry, closest\n * to the network). The offline interceptor must be OUTSIDE the connection one: it has to see timeouts and status-0 failures as errors to fall back\n * to the device copy, and answers it makes itself (queued 202, device copy) must not be measured as network successes.\n */\nexport const offlineHttpInterceptors: readonly HttpInterceptorFn[] = [idempotencyInterceptor, offlineInterceptor, connectionInterceptor];\n","import { Injectable, inject } from '@angular/core';\nimport { QueuedNote, QueuedNoteState, UiNotesQueue } from '@forgeroute/ui';\nimport { pathOnly } from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { OfflineSupportService } from '../support/offline-support.service';\nimport type { MutationStatus, OfflineMutation } from '../store/offline-store';\n\nconst STATE: Record<MutationStatus, QueuedNoteState> = { pending: 'waiting', syncing: 'sending', failed: 'failed', conflict: 'conflict' };\n\n/** The text of a queued note body: `{ body }` (generic notes API) or `{ content }` (a resource's own API); '' when there is none. */\nfunction textOf(body: unknown): string {\n let b = body;\n if (typeof b === 'string') { try { b = JSON.parse(b); } catch { return ''; } }\n if (b === null || typeof b !== 'object') return '';\n const o = b as { body?: unknown; content?: unknown };\n const text = typeof o.body === 'string' ? o.body : typeof o.content === 'string' ? o.content : '';\n return text.trim();\n}\n\nfunction decode(segment: string): string {\n try { return decodeURIComponent(segment); } catch { return segment; }\n}\n\n/**\n * The decoded path segments of a URL: origin, query and hash dropped, empty segments (trailing or double slashes) removed, each segment decoded on its own\n * (so an encoded slash `%2F` stays inside its segment). Two URLs name the same resource when these lists are equal, however each was written.\n */\nfunction segments(url: string): string[] {\n return pathOnly(url).split('/').filter(s => s !== '').map(decode);\n}\n\nfunction startsWith(path: string[], prefix: string[]): boolean {\n return path.length >= prefix.length && prefix.every((s, i) => path[i] === s);\n}\n\n/**\n * Lets `ui-notes` show the note changes the offline layer has saved on the device. It reads `OfflineSupportService.rows` (the offline layer's own\n * list - nothing is copied or cached here) and keeps the rows whose URL belongs to the notes list asked for. Provided as `UI_NOTES_QUEUE` by\n * `provideOfflineSupport`; the app still decides whether notes may be queued at all (its `allowQueue` rules / `blockOffline`).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineNotesQueue implements UiNotesQueue {\n private readonly support = inject(OfflineSupportService);\n private readonly connection = inject(ConnectionStateService);\n\n readonly offline = this.connection.isOffline;\n wasDiscarded(rowId: string): boolean { return this.support.wasDiscarded(rowId); }\n\n queuedFor(listPath: string, itemPrefix: string): readonly QueuedNote[] {\n const list = segments(listPath);\n const prefix = segments(itemPrefix);\n const out: QueuedNote[] = [];\n for (const row of this.support.rows()) {\n const queued = this.toQueued(row, list, prefix);\n if (queued) out.push(queued);\n }\n return out;\n }\n\n private toQueued(row: OfflineMutation, list: string[], prefix: string[]): QueuedNote | null {\n const path = segments(row.url);\n const method = row.method.toUpperCase();\n const base = { rowId: row.id, createdAt: row.createdAt, state: STATE[row.status] };\n if (method === 'POST' && path.length === list.length && startsWith(path, list)) return { ...base, kind: 'add', noteId: '', text: textOf(row.body) };\n if ((method === 'PUT' || method === 'PATCH' || method === 'DELETE') && startsWith(path, prefix)) {\n if (path.length !== prefix.length + 1) return null;\n const id = path[prefix.length];\n return method === 'DELETE'\n ? { ...base, kind: 'delete', noteId: id, text: '' }\n : { ...base, kind: 'edit', noteId: id, text: textOf(row.body) };\n }\n return null;\n }\n}\n","import { UI_NOTES_QUEUE } from '@forgeroute/ui';\nimport { EnvironmentProviders, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { OFFLINE_SUPPORT_CONFIG, OfflineSupportConfig } from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { OfflineStore } from '../store/offline-store';\nimport { OfflineNotesQueue } from '../notes/offline-notes-queue';\nimport { OfflineSupportService } from './offline-support.service';\n\n/**\n * Provides the config and starts the offline layer with the app: opens the store, then wires the replay triggers (app start when online, browser\n * `online`, connection back to `online`, probe success) and the cross-tab sync. Pair it with\n * `provideHttpClient(withInterceptors([..., ...offlineHttpInterceptors]))`.\n */\nexport function provideOfflineSupport(config: OfflineSupportConfig): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: OFFLINE_SUPPORT_CONFIG, useValue: config },\n // Lets `ui-notes` show note changes saved on the device (the app still decides whether notes may be queued).\n { provide: UI_NOTES_QUEUE, useExisting: OfflineNotesQueue },\n provideAppInitializer(() => {\n const store = inject(OfflineStore);\n const support = inject(OfflineSupportService);\n inject(ConnectionStateService);\n return store.init().then(() => { void support.start().catch(() => undefined); });\n }),\n ]);\n}\n","import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, ElementRef, computed, effect, inject, input, output, signal, untracked, viewChild } from '@angular/core';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport { ConnectionStateService, OfflineSupportService } from '../deps';\n\n/** How long the green \"All changes synced\" bar stays after a sync. */\nexport const SYNCED_FLASH_MS = 3000;\n\nexport type ConnectionBannerKind = 'auth' | 'offline' | 'unreachable' | 'syncing' | 'attention' | 'slow' | 'synced';\n\ninterface BannerView {\n kind: ConnectionBannerKind;\n title: string;\n message: string;\n detail: string;\n /** Spoken text: exactly what the sighted user reads. */\n announcement: string;\n}\n\nlet nextId = 0;\n\n/**\n * THE connection banner. Put ONE near the root of the app, above the routed content (inside the scrolling page, not fixed):\n *\n * <ui-connection-banner (viewChanges)=\"drawerOpen.set(true)\" />\n *\n * One plain-words message per situation, by priority: sign-in needed for saved changes > offline > server unreachable >\n * sending saved changes > changes need attention > slow connection > \"All changes synced\" (3 s, also after automatic syncs) > nothing.\n *\n * Accessibility: two live regions (polite status, assertive alert for the sign-in message) exist from the first render and only their text\n * changes, so screen readers announce every change; the visible bar is ordinary content that mirrors the same words. The bar is\n * `position: sticky; top: 0` inside the page flow, so it never covers content, and sits below modals / side panels.\n *\n * A page that REFUSES writes while offline (a public shop: payment needs a connection and nothing is saved on the device) sets `[queues]=\"false\"`\n * (library source 2026-11-10, NOT yet published): the texts then never mention saving on the device or sending later, \"View changes\" / \"Sync now\" /\n * the waiting count and the sync states are not shown, \"What can I do?\" appears only when the app passed `infoOffline` / `infoNeedsConnection`\n * (only the lists the app passed), and coming back online flashes the neutral \"You're back online\" (3 s). It needs no signed-in user.\n *\n * Test ids: connection-banner, connection-banner-live, connection-banner-live-alert, connection-banner-title, connection-banner-message,\n * connection-banner-detail, connection-banner-sync-now, connection-banner-view, connection-banner-info-toggle, connection-banner-info-panel,\n * connection-banner-info-hide.\n */\n@Component({\n selector: 'ui-connection-banner',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"cb-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"connection-banner-live\">{{ politeText() }}</div>\n <div class=\"cb-live\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-testid=\"connection-banner-live-alert\">{{ alertText() }}</div>\n @if (view(); as v) {\n <div class=\"cb-bar\" [class]=\"'cb-bar cb-' + v.kind\" role=\"group\" [attr.aria-label]=\"labels.t('connection.region')\"\n data-testid=\"connection-banner\" [attr.data-state]=\"v.kind\" (keydown.escape)=\"onEscape($event)\">\n <div class=\"cb-text\">\n <strong class=\"cb-title\" data-testid=\"connection-banner-title\">{{ v.title }}</strong>\n @if (v.message) { <span class=\"cb-msg\" data-testid=\"connection-banner-message\"> {{ v.message }}</span> }\n @if (v.detail) { <span class=\"cb-detail\" data-testid=\"connection-banner-detail\"> {{ v.detail }}</span> }\n </div>\n @if (showSyncNow() || showView() || infoAllowed()) {\n <div class=\"cb-actions\">\n @if (showSyncNow()) {\n <button type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-sync-now\" (click)=\"syncNow()\">{{ labels.t('connection.syncNow') }}</button>\n }\n @if (showView()) {\n <button type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-view\" (click)=\"viewChanges.emit()\">{{ labels.t('connection.viewChanges') }}</button>\n }\n @if (infoAllowed()) {\n <button #infoToggle type=\"button\" class=\"cb-btn cb-btn-ghost\" data-testid=\"connection-banner-info-toggle\"\n [attr.aria-expanded]=\"infoOpen()\" [attr.aria-controls]=\"panelId\" (click)=\"toggleInfo()\">{{ labels.t('connection.whatCanIDo') }}</button>\n }\n </div>\n }\n @if (infoAllowed() && infoOpen()) {\n <div class=\"cb-info\" [id]=\"panelId\" role=\"region\" tabindex=\"-1\" [attr.aria-label]=\"labels.t('connection.info.panelLabel')\" data-testid=\"connection-banner-info-panel\">\n @if (showCanDo()) {\n <p class=\"cb-info-h\">{{ labels.t('connection.info.canDoTitle') }}</p>\n <ul class=\"cb-list\">@for (item of canDoItems(); track $index) { <li>{{ item }}</li> }</ul>\n }\n @if (showNeeds()) {\n <p class=\"cb-info-h\">{{ labels.t('connection.info.needsTitle') }}</p>\n <ul class=\"cb-list\">@for (item of needsItems(); track $index) { <li>{{ item }}</li> }</ul>\n }\n <button #infoHide type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-info-hide\" (click)=\"closeInfo(true)\">{{ labels.t('connection.hide') }}</button>\n </div>\n }\n </div>\n }\n `,\n styles: [`\n :host { display: block; position: -webkit-sticky; position: sticky; top: 0; z-index: 50; }\n .cb-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .cb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; font-size: 0.875rem; line-height: 1.4;\n border-block-end: 1px solid; border-inline-start: 6px solid; box-sizing: border-box; }\n .cb-text { flex: 1 1 280px; min-inline-size: 0; overflow-wrap: anywhere; }\n .cb-actions { display: flex; flex-wrap: wrap; gap: 8px; }\n .cb-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid currentColor; background: #fff; color: inherit;\n font: inherit; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .cb-btn-ghost { background: transparent; }\n .cb-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .cb-btn:focus:not(:focus-visible) { outline: none; }\n .cb-info { flex: 1 1 100%; padding: 12px 14px; border-radius: 8px; background: rgba(255, 255, 255, 0.7); border: 1px solid currentColor; }\n .cb-info:focus { outline: none; }\n .cb-info-h { margin: 0 0 4px; font-weight: 700; }\n .cb-list { margin: 0 0 12px; padding-inline-start: 20px; }\n .cb-offline, .cb-slow, .cb-attention { background: #fef3c7; color: #78350f; border-color: #b45309; }\n .cb-unreachable, .cb-auth { background: #fee2e2; color: #7f1d1d; border-color: #b91c1c; }\n .cb-syncing { background: #dbeafe; color: #1e3a8a; border-color: #1d4ed8; }\n .cb-synced { background: #dcfce7; color: #14532d; border-color: #15803d; }\n @media (prefers-reduced-motion: no-preference) { .cb-bar { animation: cb-in 160ms ease-out; } }\n @keyframes cb-in { from { opacity: 0; } to { opacity: 1; } }\n @media (max-width: 480px) {\n .cb-actions { flex-direction: column; inline-size: 100%; }\n .cb-btn { inline-size: 100%; }\n }\n @media (forced-colors: active) {\n .cb-bar, .cb-info { border: 2px solid CanvasText; background: Canvas; color: CanvasText; }\n .cb-btn { border-color: ButtonText; background: ButtonFace; color: ButtonText; }\n }\n `],\n})\nexport class ConnectionBannerComponent {\n protected readonly labels = inject(UiLabelsService);\n private readonly connection = inject(ConnectionStateService);\n private readonly support = inject(OfflineSupportService);\n private readonly cdr = inject(ChangeDetectorRef);\n\n /** What the user can still do while offline (app specific). Default: a generic list. */\n readonly infoOffline = input<readonly string[] | null>(null);\n /** What needs a connection (app specific, should match what the app really blocks). Default: a generic list. */\n readonly infoNeedsConnection = input<readonly string[] | null>(null);\n /**\n * True (default): the page saves writes on the device while offline and sends them later (today's behaviour, unchanged). False: the page\n * refuses writes while offline and saves nothing - honest texts, no queue controls (see the class comment). Library source 2026-11-10, NOT yet published.\n */\n readonly queues = input(true);\n /** The user pressed \"View changes\" - the app opens `<ui-pending-changes-drawer>`. */\n readonly viewChanges = output<void>();\n\n protected readonly panelId = `ui-cb-info-${++nextId}`;\n protected readonly infoOpen = signal(false);\n private readonly infoToggleRef = viewChild<ElementRef<HTMLButtonElement>>('infoToggle');\n private readonly infoHideRef = viewChild<ElementRef<HTMLButtonElement>>('infoHide');\n\n private readonly syncTotal = signal(0);\n private readonly showSynced = signal(false);\n private syncedTimer: ReturnType<typeof setTimeout> | null = null;\n private seenTick = this.support.syncTick();\n private flashPending = false;\n private wasSyncing = false;\n private prevState = this.connection.state();\n\n protected readonly canDoItems = computed(() => this.infoOffline() ?? (this.queues() ? [this.labels.t('connection.info.canDo1'), this.labels.t('connection.info.canDo2')] : []));\n protected readonly needsItems = computed(() => this.infoNeedsConnection() ?? (this.queues() ? [this.labels.t('connection.info.needs1')] : []));\n /** With `queues` the two default lists always show; without it only the lists the app passed (the generic defaults talk about saved changes). */\n protected readonly showCanDo = computed(() => this.queues() || this.canDoItems().length > 0);\n protected readonly showNeeds = computed(() => this.queues() || this.needsItems().length > 0);\n\n private count(base: 'connection.syncing' | 'connection.needAttention' | 'connection.pending', n: number): string {\n return this.labels.t(`${base}.${n === 1 ? 'one' : 'other'}`, { count: n });\n }\n\n protected readonly view = computed((): BannerView | null => {\n const state = this.connection.state();\n const pending = this.support.pendingCount();\n const attention = this.support.failedCount() + this.support.conflictCount();\n const l = this.labels;\n const queues = this.queues();\n let v: Omit<BannerView, 'announcement'> | null = null;\n if (!queues) {\n // Nothing is saved or sent: only the connection itself is described. Neither the replayer's state nor the waiting count is read.\n if (state === 'offline') v = { kind: 'offline', title: l.t('connection.offline.title'), message: l.t('connection.offline.noQueue.message'), detail: '' };\n else if (state === 'unreachable') v = { kind: 'unreachable', title: l.t('connection.unreachable.title'), message: l.t('connection.unreachable.noQueue.message'), detail: '' };\n else if (state === 'slow') v = { kind: 'slow', title: l.t('connection.slow.title'), message: l.t('connection.slow.noQueue.message'), detail: '' };\n else if (this.showSynced()) v = { kind: 'synced', title: l.t('connection.backOnline'), message: '', detail: '' };\n } else if (this.support.authBlocked()) {\n v = { kind: 'auth', title: l.t('connection.authBlocked'), message: '', detail: '' };\n } else if (state === 'offline') {\n v = { kind: 'offline', title: l.t('connection.offline.title'), message: l.t('connection.offline.message'), detail: pending > 0 ? this.count('connection.pending', pending) : '' };\n } else if (state === 'unreachable') {\n v = { kind: 'unreachable', title: l.t('connection.unreachable.title'), message: l.t('connection.unreachable.message'), detail: pending > 0 ? this.count('connection.pending', pending) : '' };\n } else if (this.support.syncing() && Math.max(this.syncTotal(), pending) > 0) {\n v = { kind: 'syncing', title: this.count('connection.syncing', Math.max(this.syncTotal(), pending)), message: '', detail: '' };\n } else if (attention > 0) {\n v = { kind: 'attention', title: this.count('connection.needAttention', attention), message: '', detail: '' };\n } else if (state === 'slow') {\n v = { kind: 'slow', title: l.t('connection.slow.title'), message: l.t('connection.slow.message'), detail: '' };\n } else if (this.showSynced()) {\n v = { kind: 'synced', title: l.t('connection.synced'), message: '', detail: '' };\n }\n if (!v) return null;\n const sentence = (s: string) => (/[.…!?]$/.test(s) ? s : s + '.');\n return { ...v, announcement: [v.title, v.message, v.detail].filter(Boolean).map(sentence).join(' ') };\n });\n\n /** Set when a \"Sync now\" call was rejected: said politely in the status region (nothing is lost, the changes stay saved). */\n private readonly actionFailure = signal('');\n protected readonly politeText = computed(() => {\n const v = this.view();\n return [v && v.kind !== 'auth' ? v.announcement : '', this.actionFailure()].filter(Boolean).join(' ');\n });\n protected readonly alertText = computed(() => { const v = this.view(); return v && v.kind === 'auth' ? v.announcement : ''; });\n\n protected readonly infoAllowed = computed(() => {\n const k = this.view()?.kind;\n return (k === 'offline' || k === 'unreachable') && (this.queues() || this.showCanDo() || this.showNeeds());\n });\n protected readonly showSyncNow = computed(() => {\n const k = this.view()?.kind;\n return this.queues() && (k === 'unreachable' || k === 'slow' || k === 'attention') && this.support.pendingCount() > 0 && !this.support.syncing();\n });\n protected readonly showView = computed(() => {\n const k = this.view()?.kind;\n if (!this.queues() || !k || k === 'synced') return false;\n return this.rowsTotal() > 0 || k === 'auth';\n });\n private readonly rowsTotal = computed(() => this.support.pendingCount() + this.support.failedCount() + this.support.conflictCount());\n\n constructor() {\n // Remember how many changes a sync started with (\"Sending 3 changes…\" must not count down to 0 while it runs), and flash\n // \"All changes synced\" when a run that changed data (syncTick bumped) ends - manual and automatic runs alike.\n effect(() => {\n const syncing = this.support.syncing();\n const tick = this.support.syncTick();\n untracked(() => {\n if (tick !== this.seenTick) { this.seenTick = tick; if (this.queues()) this.flashPending = true; }\n if (syncing && !this.wasSyncing) this.syncTotal.set(Math.max(this.support.pendingCount(), 0));\n if (!syncing) this.syncTotal.set(0);\n this.wasSyncing = syncing;\n if (!syncing && this.flashPending) { this.flashPending = false; this.flashSynced(); }\n });\n });\n // Without a queue there is no sync to flash: flash the neutral \"You're back online\" when the connection comes back from offline / unreachable.\n effect(() => {\n const state = this.connection.state();\n const queues = this.queues();\n untracked(() => {\n const wasDown = this.prevState === 'offline' || this.prevState === 'unreachable';\n this.prevState = state;\n if (!queues && wasDown && state !== 'offline' && state !== 'unreachable') this.flashSynced();\n });\n });\n effect(() => { if (!this.infoAllowed()) this.infoOpen.set(false); });\n inject(DestroyRef).onDestroy(() => { if (this.syncedTimer) clearTimeout(this.syncedTimer); });\n }\n\n private flashSynced(): void {\n if (this.syncedTimer) clearTimeout(this.syncedTimer);\n this.showSynced.set(true);\n this.syncedTimer = setTimeout(() => { this.syncedTimer = null; this.showSynced.set(false); }, SYNCED_FLASH_MS);\n }\n\n protected syncNow(): void {\n this.actionFailure.set('');\n let call: Promise<unknown>;\n try { call = Promise.resolve(this.support.syncNow()); } catch { call = Promise.reject(new Error('syncNow')); }\n call.catch(() => this.actionFailure.set(this.labels.t('connection.error.unknown')));\n }\n\n protected toggleInfo(): void {\n if (this.infoOpen()) { this.closeInfo(true); return; }\n this.infoOpen.set(true);\n this.cdr.detectChanges();\n this.infoHideRef()?.nativeElement.focus();\n }\n\n protected closeInfo(returnFocus: boolean): void {\n this.infoOpen.set(false);\n this.cdr.detectChanges();\n if (returnFocus) this.infoToggleRef()?.nativeElement.focus();\n }\n\n protected onEscape(event: Event): void {\n if (!this.infoOpen()) return;\n event.stopPropagation();\n this.closeInfo(true);\n }\n}\n","/**\n * \"5 minutes ago\" for the offline UI. Uses `Intl.RelativeTimeFormat` when the browser has it (feature-detected; every current\n * Chrome / Edge / Firefox / Safari does) and falls back to the browser's own date formatting otherwise. `locale` undefined = the\n * page language / browser default.\n */\nexport function formatRelativeTime(then: number, now: number, justNowText: string, locale?: string): string {\n const diffSec = Math.round((now - then) / 1000);\n if (diffSec < 45) return justNowText;\n const rtfCtor = (globalThis as { Intl?: { RelativeTimeFormat?: new (l?: string, o?: { numeric: 'auto' | 'always' }) => { format(v: number, u: string): string } } }).Intl?.RelativeTimeFormat;\n const minutes = Math.round(diffSec / 60);\n const hours = Math.round(diffSec / 3600);\n const days = Math.round(diffSec / 86400);\n if (rtfCtor) {\n let rtf: { format(v: number, u: string): string };\n try { rtf = new rtfCtor(locale, { numeric: 'auto' }); } catch { rtf = new rtfCtor(undefined, { numeric: 'auto' }); }\n if (minutes < 60) return rtf.format(-minutes, 'minute');\n if (hours < 24) return rtf.format(-hours, 'hour');\n if (days <= 30) return rtf.format(-days, 'day');\n }\n return absoluteTime(then, locale);\n}\n\n/** Full local date and time, e.g. for a `title` / `<time>` tooltip. */\nexport function absoluteTime(at: number, locale?: string): string {\n try { return new Date(at).toLocaleString(locale); } catch { return new Date(at).toLocaleString(); }\n}\n\n/**\n * The language of the times the offline UI shows. With `labelsLocale` (the label service's `locale()`, which follows the active dictionary's\n * `i18n.locale` marker or the app's `setLocale`) it always wins, so the times agree with the texts around them. Without `labelsLocale` it is the\n * page language (`<html lang>`) only (`undefined` = the browser default).\n */\nexport function pageLocale(doc: Document, labelsLocale?: string): string | undefined {\n if (labelsLocale) return labelsLocale;\n return doc.documentElement?.lang || undefined;\n}\n","import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, ElementRef, computed, inject, input, output, signal } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { ConfirmService, SidePanelComponent, UiLabelsService } from '@forgeroute/ui';\nimport { KeepMineError, KeepMineOutcome, OfflineSupportService, PendingRow } from '../deps';\nimport { absoluteTime, formatRelativeTime, pageLocale } from '../relative-time';\n\ntype ErrorKind = 'conflict' | 'rejected' | 'auth' | 'server' | 'network' | 'timeout' | 'dependency';\nconst ERROR_KEYS = {\n conflict: 'connection.error.conflict',\n rejected: 'connection.error.rejected',\n auth: 'connection.error.auth',\n server: 'connection.error.server',\n network: 'connection.error.network',\n timeout: 'connection.error.timeout',\n dependency: 'connection.error.dependency',\n} as const;\n\n/**\n * Side panel that lists every change saved on this device and not yet accepted by the server, with plain-words reasons and\n * the actions Retry / Discard per change (a conflict row, when `conflictStampFields` is configured, offers \"Keep my version\" and \"Discard my change\" instead of Retry), Sync all and Discard all. Open it from `(viewChanges)` of `<ui-connection-banner>`:\n *\n * <ui-pending-changes-drawer [open]=\"drawerOpen()\" (closed)=\"drawerOpen.set(false)\" />\n *\n * Raw server text is never shown: the wording comes from `lastError.kind`. Discards ask first (ConfirmService). Results are announced\n * in a polite live region that exists from the first render. Test ids: pending-drawer-live, pending-drawer-auth, pending-drawer-list,\n * pending-drawer-empty, pending-row-<id>, pending-row-status-<id>, pending-row-error-<id>, pending-row-time-<id>, pending-row-retry-<id>,\n * pending-row-keep-mine-<id>, pending-row-discard-<id>, pending-drawer-sync-all, pending-drawer-discard-all.\n */\n@Component({\n selector: 'ui-pending-changes-drawer',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [SidePanelComponent],\n template: `\n <div class=\"pcd-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"pending-drawer-live\">{{ announcement() }}</div>\n <ui-side-panel\n [open]=\"open()\"\n [title]=\"labels.t('connection.drawer.title')\"\n [cancelLabel]=\"labels.t('connection.drawer.close')\"\n [primaryLabel]=\"labels.t('connection.syncAll')\"\n [primaryDisabled]=\"rows().length === 0 || support.syncing()\"\n [primaryLoading]=\"support.syncing()\"\n primaryTestId=\"pending-drawer-sync-all\"\n (closed)=\"closed.emit()\"\n (primaryClick)=\"syncAll()\">\n @if (support.authBlocked()) {\n <p class=\"pcd-auth\" data-testid=\"pending-drawer-auth\">{{ labels.t('connection.authBlocked') }}</p>\n }\n @if (rows().length === 0) {\n <p class=\"pcd-empty\" tabindex=\"-1\" data-testid=\"pending-drawer-empty\">{{ support.storageAvailable() ? labels.t('connection.drawer.empty') : labels.t('connection.storageUnavailable') }}</p>\n } @else {\n <ul class=\"pcd-list\" [attr.aria-label]=\"labels.t('connection.drawer.list')\" data-testid=\"pending-drawer-list\">\n @for (row of rows(); track row.id) {\n <li class=\"pcd-row\" [attr.data-testid]=\"'pending-row-' + row.id\" [attr.data-status]=\"row.status\">\n <div class=\"pcd-main\">\n <span class=\"pcd-label\">{{ row.label }}</span>\n <span class=\"pcd-status\" [attr.data-testid]=\"'pending-row-status-' + row.id\">{{ statusText(row) }}</span>\n </div>\n <time class=\"pcd-time\" [attr.datetime]=\"iso(row)\" [attr.title]=\"absolute(row)\" [attr.data-testid]=\"'pending-row-time-' + row.id\">{{ savedText(row) }}</time>\n @if (errorText(row); as err) {\n <p class=\"pcd-error\" [attr.data-testid]=\"'pending-row-error-' + row.id\">{{ err }}</p>\n }\n <div class=\"pcd-actions\">\n @if (support.canKeepMine(row)) {\n <button type=\"button\" class=\"pcd-btn pcd-btn-primary\" [attr.data-testid]=\"'pending-row-keep-mine-' + row.id\"\n [attr.aria-label]=\"labels.t('connection.conflict.keepMineNamed', { label: row.label })\" [attr.aria-disabled]=\"isBusy(row) ? 'true' : null\" [attr.aria-busy]=\"isBusy(row) ? 'true' : null\" [class.pcd-btn-busy]=\"isBusy(row)\" (click)=\"keepMine(row)\">{{ labels.t('connection.conflict.keepMine') }}</button>\n }\n @if (canRetry(row) && !support.canKeepMine(row)) {\n <button type=\"button\" class=\"pcd-btn\" [attr.data-testid]=\"'pending-row-retry-' + row.id\"\n [attr.aria-label]=\"labels.t('connection.retryNamed', { label: row.label })\" [attr.aria-disabled]=\"isBusy(row) ? 'true' : null\" [attr.aria-busy]=\"isBusy(row) ? 'true' : null\" [class.pcd-btn-busy]=\"isBusy(row)\" (click)=\"retry(row)\">{{ labels.t('connection.retry') }}</button>\n }\n <button type=\"button\" class=\"pcd-btn pcd-btn-danger\" [attr.data-testid]=\"'pending-row-discard-' + row.id\" [disabled]=\"row.status === 'syncing'\"\n [attr.aria-label]=\"discardName(row)\" (click)=\"discard(row)\">{{ discardText(row) }}</button>\n </div>\n </li>\n }\n </ul>\n }\n <button panel-footer-extra type=\"button\" class=\"pcd-btn pcd-btn-danger\" data-testid=\"pending-drawer-discard-all\"\n [disabled]=\"rows().length === 0 || support.syncing()\" (click)=\"discardAll()\">{{ labels.t('connection.discardAll') }}</button>\n </ui-side-panel>\n `,\n styles: [`\n :host { display: contents; }\n .pcd-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .pcd-auth { margin: 0 0 16px; padding: 12px 14px; border-radius: 8px; border: 1px solid #b91c1c; background: #fee2e2; color: #7f1d1d; font-size: 0.875rem; }\n .pcd-empty { margin: 0; padding: 24px 0; color: #475569; font-size: 0.9375rem; text-align: center; }\n .pcd-empty:focus { outline: none; }\n .pcd-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }\n .pcd-row { padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; display: flex; flex-direction: column; gap: 6px; }\n .pcd-main { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }\n .pcd-label { font-weight: 600; color: #0f172a; overflow-wrap: anywhere; min-inline-size: 0; }\n .pcd-status { font-size: 0.8125rem; color: #334155; }\n .pcd-time { font-size: 0.8125rem; color: #475569; }\n .pcd-error { margin: 0; font-size: 0.875rem; color: #7f1d1d; }\n .pcd-row[data-status='conflict'] .pcd-error, .pcd-row[data-status='failed'] .pcd-error { color: #78350f; }\n .pcd-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 4px; }\n .pcd-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid #334155; background: #fff; color: #0f172a;\n font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .pcd-btn-primary { border-color: #1d4ed8; background: #1d4ed8; color: #fff; }\n .pcd-btn-danger { border-color: #b91c1c; color: #b91c1c; }\n .pcd-btn:disabled, .pcd-btn-busy { opacity: 0.5; cursor: not-allowed; }\n .pcd-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .pcd-btn:focus:not(:focus-visible) { outline: none; }\n @media (max-width: 480px) { .pcd-actions { flex-direction: column; } .pcd-btn { inline-size: 100%; } }\n @media (forced-colors: active) { .pcd-row, .pcd-auth, .pcd-btn { border: 1px solid CanvasText; background: Canvas; color: CanvasText; } }\n `],\n})\nexport class PendingChangesDrawerComponent {\n protected readonly labels = inject(UiLabelsService);\n protected readonly support = inject(OfflineSupportService);\n private readonly confirmService = inject(ConfirmService);\n private readonly cdr = inject(ChangeDetectorRef);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly doc = inject(DOCUMENT);\n\n readonly open = input(false);\n readonly closed = output<void>();\n\n protected readonly rows = computed(() => this.support.rows());\n protected readonly announcement = signal('');\n private readonly now = signal(Date.now());\n /** Rows whose Retry / Keep my version (confirm or request) is in flight: their buttons are disabled so a second click cannot start it twice. */\n private readonly busyIds = signal<ReadonlySet<string>>(new Set());\n\n constructor() {\n const timer = setInterval(() => this.now.set(Date.now()), 30_000);\n inject(DestroyRef).onDestroy(() => clearInterval(timer));\n }\n\n protected statusText(row: PendingRow): string {\n switch (row.status) {\n case 'syncing': return this.labels.t('connection.status.syncing');\n case 'failed': return this.labels.t('connection.status.failed');\n case 'conflict': return this.labels.t('connection.status.conflict');\n default: return this.labels.t('connection.status.pending');\n }\n }\n\n /** Plain words from the error KIND; the server's own text (`lastError.message`) is never shown. */\n protected errorText(row: PendingRow): string {\n if (row.status === 'conflict') return this.labels.t('connection.conflict.rowText');\n const kind = row.lastError?.kind as ErrorKind | undefined;\n if (kind && kind in ERROR_KEYS) return this.labels.t(ERROR_KEYS[kind]);\n if (row.status === 'failed' || row.lastError) return this.labels.t('connection.error.unknown');\n return '';\n }\n\n protected canRetry(row: PendingRow): boolean {\n return row.status === 'failed' || row.status === 'conflict' || (row.status === 'pending' && !!row.lastError);\n }\n\n protected discardText(row: PendingRow): string {\n return this.labels.t(row.status === 'conflict' ? 'connection.conflict.discard' : 'connection.discard');\n }\n\n protected discardName(row: PendingRow): string {\n return row.status === 'conflict' ? this.labels.t('connection.conflict.discardNamed', { label: row.label }) : this.labels.t('connection.discardNamed', { label: row.label });\n }\n\n protected iso(row: PendingRow): string { return new Date(row.createdAt).toISOString(); }\n protected absolute(row: PendingRow): string { return absoluteTime(row.createdAt, pageLocale(this.doc, this.labels.locale())); }\n protected savedText(row: PendingRow): string {\n const time = formatRelativeTime(row.createdAt, this.now(), this.labels.t('connection.time.justNow'), pageLocale(this.doc, this.labels.locale()));\n return this.labels.t('connection.savedAt', { time });\n }\n\n protected isBusy(row: PendingRow): boolean {\n return this.busyIds().has(row.id);\n }\n\n private setBusy(id: string, busy: boolean): void {\n this.busyIds.update(set => { const next = new Set(set); if (busy) next.add(id); else next.delete(id); return next; });\n }\n\n protected async retry(row: PendingRow): Promise<void> {\n if (this.isBusy(row)) return;\n this.setBusy(row.id, true);\n try {\n this.announcement.set(this.labels.t('connection.result.retrying', { label: row.label }));\n try { await this.support.retry(row.id); } catch { this.announceFailure(); }\n } finally {\n this.setBusy(row.id, false);\n }\n }\n\n /** \"Keep my version\": asks first (the other person's version is lost), then removes the stamp and sends only this change, then says what happened (sent / will be sent shortly / could not be sent). */\n protected async keepMine(row: PendingRow): Promise<void> {\n if (this.isBusy(row)) return;\n this.setBusy(row.id, true);\n try {\n const index = this.rows().findIndex(r => r.id === row.id);\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.conflict.confirmTitle'),\n message: this.labels.t('connection.conflict.confirmMessage'),\n confirmLabel: this.labels.t('connection.conflict.keepMine'),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n this.announcement.set(this.labels.t('connection.conflict.result.keeping', { label: row.label }));\n let outcome: KeepMineOutcome;\n try { outcome = await this.support.keepMine(row.id); } catch (e) { this.announcement.set(e instanceof KeepMineError ? e.message : this.labels.t('connection.conflict.error.unknown')); return; }\n this.announcement.set(outcome === 'sent' ? this.labels.t('connection.conflict.result.sent', { label: row.label })\n : outcome === 'shortly' ? this.labels.t('connection.conflict.result.shortly', { label: row.label })\n : this.labels.t('connection.conflict.error.unknown'));\n this.cdr.detectChanges();\n if (!this.rows().some(r => r.id === row.id)) this.focusAfterRemoval(index);\n } finally {\n this.setBusy(row.id, false);\n }\n }\n\n protected async syncAll(): Promise<void> {\n this.announcement.set(this.labels.t('connection.result.syncStarted'));\n try { await this.support.syncNow(); } catch { this.announceFailure(); }\n }\n\n protected async discard(row: PendingRow): Promise<void> {\n const index = this.rows().findIndex(r => r.id === row.id);\n // Other saved changes that point at a record this change creates cannot be sent once it is gone: say so before the user decides.\n // The count follows chains (create A, create B that uses A, an edit of B: discarding A fails both B and the edit); the set also guards against cycles.\n const all = this.rows();\n const dependentIds = new Set<string>();\n const pending = [row.id];\n while (pending.length > 0) {\n const current = pending.pop() as string;\n for (const r of all) {\n if (r.id !== row.id && !dependentIds.has(r.id) && (r.dependsOn ?? []).includes(current)) { dependentIds.add(r.id); pending.push(r.id); }\n }\n }\n const dependents = dependentIds.size;\n const message = dependents === 0 ? this.labels.t('connection.discard.message', { label: row.label })\n : dependents === 1 ? this.labels.t('connection.discard.dependents.one', { label: row.label })\n : this.labels.t('connection.discard.dependents.other', { label: row.label, count: dependents });\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.discard.title'),\n message,\n confirmLabel: this.discardText(row),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n try { await this.support.discard(row.id); } catch { this.announceFailure(); return; }\n this.announcement.set(this.labels.t('connection.result.discarded', { label: row.label }));\n this.cdr.detectChanges();\n this.focusAfterRemoval(index);\n }\n\n protected async discardAll(): Promise<void> {\n const count = this.rows().length;\n if (count === 0) return;\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.discardAll.title'),\n message: this.labels.t(count === 1 ? 'connection.discardAll.message.one' : 'connection.discardAll.message.other', { count }),\n confirmLabel: this.labels.t('connection.discardAll'),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n try { await this.support.discardAll(); } catch { this.announceFailure(); return; }\n this.announcement.set(this.labels.t('connection.result.discardedAll'));\n this.cdr.detectChanges();\n this.focusAfterRemoval(0);\n }\n\n /** A rejected service call must not become an unhandled rejection; tell the user politely (nothing was lost). */\n private announceFailure(): void {\n this.announcement.set(this.labels.t('connection.error.unknown'));\n }\n\n /** The row the user acted on is gone: move focus to the row now at that position (or the previous one, or the empty message). */\n private focusAfterRemoval(index: number): void {\n // ui-side-panel projects its body into the panel element, which lives under this component's host.\n const root = this.host.nativeElement;\n const rowEls = Array.from(root.querySelectorAll<HTMLElement>('li.pcd-row'));\n const target = rowEls[Math.min(index, rowEls.length - 1)]?.querySelector<HTMLElement>('button:not([disabled])') ?? root.querySelector<HTMLElement>('.pcd-empty');\n target?.focus();\n }\n}\n","import { ChangeDetectionStrategy, Component, DestroyRef, computed, inject, output, signal } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport { StaleDataService } from '../deps';\nimport { absoluteTime, formatRelativeTime, pageLocale } from '../relative-time';\n\nconst TIME_MARK = '\\u0001';\n\n/**\n * \"Showing saved data from 5 minutes ago [Refresh]\" while `StaleDataService.staleAt()` is set (a GET was answered from the\n * device copy). Put it at the top of the page area that shows the data; the app reloads the data on `(refresh)`:\n *\n * <ui-stale-data-chip (refresh)=\"reload()\" />\n *\n * A polite live region exists from the first render (visually hidden) and mirrors the sentence. Test ids: stale-data-chip,\n * stale-data-chip-live, stale-data-chip-time, stale-data-chip-refresh.\n */\n@Component({\n selector: 'ui-stale-data-chip',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"sdc-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"stale-data-chip-live\">{{ announcement() }}</div>\n @if (parts(); as p) {\n <div class=\"sdc\" data-testid=\"stale-data-chip\">\n <span class=\"sdc-text\">{{ p.before }}<time [attr.datetime]=\"p.iso\" [attr.title]=\"p.absolute\" data-testid=\"stale-data-chip-time\">{{ p.relative }}</time>{{ p.after }}</span>\n <button type=\"button\" class=\"sdc-btn\" data-testid=\"stale-data-chip-refresh\" [attr.aria-label]=\"labels.t('connection.refreshAria')\" (click)=\"refresh.emit()\">{{ labels.t('connection.refresh') }}</button>\n </div>\n }\n `,\n styles: [`\n :host { display: block; position: relative; }\n .sdc-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .sdc { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 8px 6px 14px; border-radius: 999px; border: 1px solid #b45309;\n background: #fef3c7; color: #78350f; font-size: 0.8125rem; line-height: 1.4; max-inline-size: 100%; box-sizing: border-box; }\n .sdc-text { min-inline-size: 0; overflow-wrap: anywhere; }\n .sdc-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid currentColor; background: #fff; color: inherit;\n font: inherit; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .sdc-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .sdc-btn:focus:not(:focus-visible) { outline: none; }\n @media (max-width: 480px) { .sdc { border-radius: 12px; } .sdc-btn { inline-size: 100%; } }\n @media (forced-colors: active) { .sdc, .sdc-btn { border: 1px solid CanvasText; background: Canvas; color: CanvasText; } }\n `],\n})\nexport class StaleDataChipComponent {\n protected readonly labels = inject(UiLabelsService);\n private readonly stale = inject(StaleDataService);\n private readonly doc = inject(DOCUMENT);\n /** The user pressed Refresh - reload the data from the server. */\n readonly refresh = output<void>();\n\n private readonly now = signal(Date.now());\n\n protected readonly parts = computed(() => {\n const at = this.stale.staleAt();\n if (at == null) return null;\n const locale = pageLocale(this.doc, this.labels.locale());\n const relative = formatRelativeTime(at, this.now(), this.labels.t('connection.time.justNow'), locale);\n const text = this.labels.t('connection.stale', { time: TIME_MARK });\n const at0 = text.indexOf(TIME_MARK);\n // A translation without the {{ time }} placeholder still shows the time, after the text and a space (never glued to the last word).\n const before = at0 < 0 ? `${text} ` : text.slice(0, at0);\n const after = at0 < 0 ? '' : text.slice(at0 + TIME_MARK.length);\n return { before, after, relative, iso: new Date(at).toISOString(), absolute: absoluteTime(at, locale) };\n });\n\n protected readonly announcement = computed(() => {\n const p = this.parts();\n return p ? `${p.before}${p.relative}${p.after}` : '';\n });\n\n constructor() {\n // Keep \"5 minutes ago\" current while the page stays open.\n const timer = setInterval(() => this.now.set(Date.now()), 30_000);\n inject(DestroyRef).onDestroy(() => clearInterval(timer));\n }\n}\n","import { ChangeDetectionStrategy, Component, computed, effect, inject, input, signal, untracked } from '@angular/core';\nimport { UiLabelsService } from '@forgeroute/ui';\n\n/**\n * \"Still working… please don't tap again.\" for a button or panel whose request has been running for a while.\n *\n * <ui-still-working [active]=\"saving()\" />\n *\n * The host keeps its own button disabled while `active`. The text appears only after `delayMs` (default 4 s) of continuous\n * `active`, disappears at once when `active` turns false, and sits in a polite live region that exists from the first render\n * (so screen readers announce the text when it appears). `text` (optional, library source 2026-11-10, NOT yet published) replaces the label:\n * `<ui-still-working [active]=\"paying()\" [delayMs]=\"4000\" text=\"Please do not close or refresh this page, we are finishing your payment.\" />`.\n * Test id: still-working.\n */\n@Component({\n selector: 'ui-still-working',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `<div class=\"sw\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"still-working\">{{ shown() }}</div>`,\n styles: [`\n :host { display: block; }\n .sw { color: #475569; font-size: 0.8125rem; line-height: 1.4; }\n .sw:empty { min-block-size: 0; margin: 0; padding: 0; }\n @media (forced-colors: active) { .sw { color: CanvasText; } }\n `],\n})\nexport class StillWorkingComponent {\n private readonly labels = inject(UiLabelsService);\n /** True while the request runs. */\n readonly active = input(false);\n /** Milliseconds of continuous `active` before the text appears. */\n readonly delayMs = input(4000);\n /**\n * Optional text shown instead of the library label (already translated by the app), e.g. the pay step: \"Please do not close or refresh this\n * page, we are finishing your payment.\" Empty or whitespace only = the library label, as before. Library source 2026-11-10, NOT yet published.\n */\n readonly text = input('');\n\n private readonly elapsed = signal(false);\n protected readonly shown = computed(() => {\n if (!this.active() || !this.elapsed()) return '';\n const custom = this.text().trim();\n return custom ? this.text() : this.labels.t('connection.stillWorking');\n });\n\n constructor() {\n effect(onCleanup => {\n const active = this.active();\n const delay = this.delayMs();\n untracked(() => this.elapsed.set(false));\n if (!active) return;\n const timer = setTimeout(() => this.elapsed.set(true), Math.max(0, delay));\n onCleanup(() => clearTimeout(timer));\n });\n }\n}\n"],"mappings":";;;;;;;AA4EA,MAAa,+BAA+B;AAE5C,MAAa,yBAAyB,IAAI,e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,CAAA;CAAA;;AAQpH,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA;EAZjC,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAkB,YAChB;GAAI,iBACC,wBAAwB;GAAM,UACrC;GAAqH,QAAA,CAAA,8KAAA;EAAA,CAAA"}
1
+ {"version":3,"file":"forgeroute-ui-offline.mjs","names":[],"sources":["../../../projects/forgeroute-ui/offline/src/config/offline-config.ts","../../../projects/forgeroute-ui/offline/src/config/uuid.ts","../../../projects/forgeroute-ui/offline/src/state/connection-state.service.ts","../../../projects/forgeroute-ui/offline/src/state/stale-data.service.ts","../../../projects/forgeroute-ui/offline/src/store/offline-store.ts","../../../projects/forgeroute-ui/offline/src/http/errors.ts","../../../projects/forgeroute-ui/offline/src/store/temp-ids.ts","../../../projects/forgeroute-ui/offline/src/replay/offline-replayer.ts","../../../projects/forgeroute-ui/offline/src/http/request-timeout.ts","../../../projects/forgeroute-ui/offline/src/http/idempotency.interceptor.ts","../../../projects/forgeroute-ui/offline/src/http/connection.interceptor.ts","../../../projects/forgeroute-ui/offline/src/support/offline-support.service.ts","../../../projects/forgeroute-ui/offline/src/http/offline.interceptor.ts","../../../projects/forgeroute-ui/offline/src/http/offline-http-interceptors.ts","../../../projects/forgeroute-ui/offline/src/notes/offline-notes-queue.ts","../../../projects/forgeroute-ui/offline/src/support/provide-offline-support.ts","../../../projects/forgeroute-ui/offline/src/ui/connection-banner/connection-banner.component.ts","../../../projects/forgeroute-ui/offline/src/ui/relative-time.ts","../../../projects/forgeroute-ui/offline/src/ui/pending-changes-drawer/pending-changes-drawer.component.ts","../../../projects/forgeroute-ui/offline/src/ui/stale-data-chip/stale-data-chip.component.ts","../../../projects/forgeroute-ui/offline/src/ui/still-working/still-working.component.ts"],"sourcesContent":["import { InjectionToken, Injector } from '@angular/core';\nimport type { OfflineMutation } from '../store/offline-store';\n\n/** string = path prefix or substring after the origin is stripped; RegExp is tested on path + query. */\nexport type UrlMatcher = string | RegExp;\n\n/**\n * What a {@link QueueRule.label} callback receives as its 4th argument: the app's injector, so the label can read app services (the signed-in company's\n * user type, a language service ...) with `ctx.injector.get(Token)` or `runInInjectionContext(ctx.injector, () => inject(Token))`. It is the injector of the\n * HTTP request being queued; the callback runs synchronously while the change is being queued.\n */\nexport interface QueueLabelContext {\n readonly injector: Injector;\n}\n\nexport interface QueueRule {\n pattern: RegExp;\n methods: readonly string[];\n /**\n * Plain-words name of the change shown in the pending-changes list (e.g. \"Add lot 12\"). A callback that takes only (method, url, body) keeps working\n * unchanged; the optional 4th argument is a {@link QueueLabelContext} for labels that need app state.\n */\n label?: (method: string, url: string, body: unknown, ctx: QueueLabelContext) => string;\n entityType?: (url: string) => string | undefined;\n}\n\nexport interface OfflineSupportConfig {\n /** Only URLs containing this are intercepted. Default '/api/'. */\n apiPrefix?: string;\n /** Never touched (auth, public, uploads...). */\n skip?: readonly UrlMatcher[];\n /** The signed-in user's id; null = nobody (nothing is queued/cached). Scopes the store. */\n getUserId: () => string | null;\n /** ALLOW-LIST mode: only requests matching a rule may be queued offline. Omit for BLOCK-LIST mode (everything may be queued except `blockOffline`). */\n allowQueue?: readonly QueueRule[];\n /** Writes that must NEVER be queued (payments, sends...). While offline/unreachable they fail with OfflineBlockedError. */\n blockOffline?: readonly { pattern: UrlMatcher; message?: string }[];\n /** GET endpoints that must never be stored or served from the device copy. */\n neverCache?: readonly UrlMatcher[];\n /** Safe extra headers copied onto the queued row and re-sent on replay (never Authorization). */\n replayHeaders?: readonly string[];\n /** Cheap authenticated/unauthenticated GET used ONLY while the connection is suspect. null/omitted = no probe. */\n probe?: { url: string; intervalMs?: number /* default 15000 */ } | null;\n /** Client timeouts in ms. Defaults: read 30000, write 60000, long 180000. `long` applies to blob/arraybuffer, FormData, and matchers in `longRequests`. */\n timeouts?: { read?: number; write?: number; long?: number };\n longRequests?: readonly UrlMatcher[];\n /** Slow detection thresholds. Defaults: slowMs 5000, slowCount 2 within windowMs 60000; single in-flight > stuckMs 8000; recover after quietMs 30000 of fast requests. */\n slow?: { slowMs?: number; slowCount?: number; windowMs?: number; stuckMs?: number; quietMs?: number };\n /** IndexedDB database name. Default 'forgeroute-offline'. */\n dbName?: string;\n /** Cache TTLs in ms (default 10 min lists / 30 min details); `ttl(url)` overrides. */\n cacheTtl?: (url: string) => number;\n maxQueue?: number; // default 500\n maxAttempts?: number; // default 5\n /**\n * Reads the id the server gave a record that was created offline, from the 2xx answer of the replayed POST (`body` is the parsed JSON answer,\n * `undefined` when the answer was empty / not JSON). Used to rewrite later saved changes that point at the client-made temporary id.\n * Default: `body.id`, else `body.data.id`; a string or a finite number. Return `undefined` when the answer has no id (dependent changes then fail\n * with kind `dependency` instead of being sent with a wrong id).\n */\n createdId?: (body: unknown, row: OfflineMutation) => string | number | undefined;\n /**\n * Names of top-level JSON body fields that carry the \"record as the editor loaded it\" stamp (e.g. `expectedUpdatedAt`). Default `[]` = the\n * \"Keep my version\" feature is OFF. When a replayed change gets 409 the row becomes `conflict`; `OfflineSupportService.keepMine(rowId)` then removes\n * these fields from the stored body (so the server no longer compares) and sends the change again: last write wins, by the user's explicit choice.\n */\n conflictStampFields?: string[];\n /**\n * The `code` the backend puts in the JSON body of its 409 \"this request is already being processed\" answer (the first copy of the same\n * Idempotency-Key is still running). Such a 409 is NOT a conflict: the row stays pending and is sent again later (back-off, or the `Retry-After`\n * header when present). Default `IDEMPOTENCY_IN_PROGRESS_CODE` (`'IDEMPOTENCY_IN_PROGRESS'`).\n */\n idempotencyInProgressCode?: string;\n}\n\n/** Default `code` of the backend's \"same request still running\" 409 (see `OfflineSupportConfig.idempotencyInProgressCode`). */\nexport const IDEMPOTENCY_IN_PROGRESS_CODE = 'IDEMPOTENCY_IN_PROGRESS';\n\nexport const OFFLINE_SUPPORT_CONFIG = new InjectionToken<OfflineSupportConfig>('OFFLINE_SUPPORT_CONFIG');\n\n/** Header the replayer sets on every replayed request; the idempotency and offline interceptors let such requests through untouched. */\nexport const OFFLINE_REPLAY_HEADER = 'X-Offline-Replay';\nexport const IDEMPOTENCY_HEADER = 'Idempotency-Key';\n/** Response header on an answer served from the device copy; the value is the `cachedAt` time in ms. */\nexport const FROM_CACHE_HEADER = 'X-From-Offline-Cache';\n\nexport interface ResolvedSlowConfig { slowMs: number; slowCount: number; windowMs: number; stuckMs: number; quietMs: number }\n\n/** The config with every default filled in. */\nexport interface ResolvedOfflineConfig {\n apiPrefix: string;\n skip: readonly UrlMatcher[];\n getUserId: () => string | null;\n allowQueue: readonly QueueRule[] | null;\n blockOffline: readonly { pattern: UrlMatcher; message?: string }[];\n neverCache: readonly UrlMatcher[];\n replayHeaders: readonly string[];\n probe: { url: string; intervalMs: number } | null;\n timeouts: { read: number; write: number; long: number };\n longRequests: readonly UrlMatcher[];\n slow: ResolvedSlowConfig;\n dbName: string;\n cacheTtl: ((url: string) => number) | null;\n maxQueue: number;\n maxAttempts: number;\n createdId: (body: unknown, row: OfflineMutation) => string | number | undefined;\n conflictStampFields: readonly string[];\n idempotencyInProgressCode: string;\n}\n\nfunction usableId(v: unknown): string | number | undefined {\n if (typeof v === 'string') return v.trim() === '' ? undefined : v;\n if (typeof v === 'number' && Number.isFinite(v)) return v;\n return undefined;\n}\n\n/** Default for `createdId`: `body.id`, else `body.data.id` (string or finite number), otherwise undefined. */\nexport function defaultCreatedId(body: unknown): string | number | undefined {\n if (body === null || typeof body !== 'object') return undefined;\n const b = body as { id?: unknown; data?: unknown };\n const direct = usableId(b.id);\n if (direct !== undefined) return direct;\n const data = b.data;\n return data !== null && typeof data === 'object' ? usableId((data as { id?: unknown }).id) : undefined;\n}\n\n/** Wraps an app-supplied `createdId` so that it can never throw and never return something that is not a usable id. */\nfunction safeCreatedId(fn: NonNullable<OfflineSupportConfig['createdId']>): ResolvedOfflineConfig['createdId'] {\n return (body, row) => {\n try { return usableId(fn(body, row)); } catch { return undefined; }\n };\n}\n\nexport const DEFAULT_LIST_TTL_MS = 10 * 60 * 1000;\nexport const DEFAULT_DETAIL_TTL_MS = 30 * 60 * 1000;\n\nfunction positive(value: number | undefined, fallback: number): number {\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;\n}\n\nexport function resolveConfig(cfg: OfflineSupportConfig): ResolvedOfflineConfig {\n return {\n apiPrefix: cfg.apiPrefix || '/api/',\n skip: cfg.skip ?? [],\n getUserId: cfg.getUserId,\n allowQueue: cfg.allowQueue ?? null,\n blockOffline: cfg.blockOffline ?? [],\n neverCache: cfg.neverCache ?? [],\n replayHeaders: cfg.replayHeaders ?? [],\n probe: cfg.probe && cfg.probe.url ? { url: cfg.probe.url, intervalMs: positive(cfg.probe.intervalMs, 15000) } : null,\n timeouts: {\n read: positive(cfg.timeouts?.read, 30000),\n write: positive(cfg.timeouts?.write, 60000),\n long: positive(cfg.timeouts?.long, 180000),\n },\n longRequests: cfg.longRequests ?? [],\n slow: {\n slowMs: positive(cfg.slow?.slowMs, 5000),\n slowCount: positive(cfg.slow?.slowCount, 2),\n windowMs: positive(cfg.slow?.windowMs, 60000),\n stuckMs: positive(cfg.slow?.stuckMs, 8000),\n quietMs: positive(cfg.slow?.quietMs, 30000),\n },\n dbName: cfg.dbName || 'forgeroute-offline',\n cacheTtl: cfg.cacheTtl ?? null,\n maxQueue: positive(cfg.maxQueue, 500),\n maxAttempts: positive(cfg.maxAttempts, 5),\n createdId: cfg.createdId ? safeCreatedId(cfg.createdId) : defaultCreatedId,\n conflictStampFields: Array.isArray(cfg.conflictStampFields)\n ? [...new Set(cfg.conflictStampFields.filter(f => typeof f === 'string' && f.trim() !== ''))]\n : [],\n idempotencyInProgressCode: typeof cfg.idempotencyInProgressCode === 'string' && cfg.idempotencyInProgressCode.trim() !== '' ? cfg.idempotencyInProgressCode.trim() : IDEMPOTENCY_IN_PROGRESS_CODE,\n };\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n if (v === null || typeof v !== 'object' || Array.isArray(v)) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n}\n\n/** The stored body as a JSON object: an object as it is, or a string that parses to a JSON object; otherwise null (absent, form text, array, number...). */\nfunction jsonObjectBody(body: unknown): { obj: Record<string, unknown>; wasString: boolean } | null {\n if (isPlainObject(body)) return { obj: body, wasString: false };\n if (typeof body === 'string') {\n try {\n const parsed: unknown = JSON.parse(body);\n return isPlainObject(parsed) ? { obj: parsed, wasString: true } : null;\n } catch {\n return null;\n }\n }\n return null;\n}\n\n/** True when the body is a JSON object that has at least one of the `fields` as a top-level key. */\nexport function hasStampField(body: unknown, fields: readonly string[]): boolean {\n const j = jsonObjectBody(body);\n return !!j && fields.some(f => Object.prototype.hasOwnProperty.call(j.obj, f));\n}\n\n/** The body without the `fields` (top-level only; every other field is kept as it is). A body that is not a JSON object is returned unchanged. */\nexport function stripStampFields(body: unknown, fields: readonly string[]): unknown {\n const j = jsonObjectBody(body);\n if (!j || !fields.some(f => Object.prototype.hasOwnProperty.call(j.obj, f))) return body;\n const copy: Record<string, unknown> = {};\n for (const k of Object.keys(j.obj)) if (!fields.includes(k)) copy[k] = j.obj[k];\n return j.wasString ? JSON.stringify(copy) : copy;\n}\n\n/** Path + query of a URL with the origin removed ('https://x.test/api/a?b=1' -> '/api/a?b=1'). Relative URLs are returned as they are. */\nexport function pathAndQuery(url: string): string {\n const m = /^[a-z][a-z0-9+.-]*:\\/\\/[^/?#]+(.*)$/i.exec(url);\n const rest = m ? m[1] : url;\n const noHash = rest.split('#')[0];\n return noHash === '' ? '/' : noHash;\n}\n\n/** Path only (no query) of a URL with the origin removed. */\nexport function pathOnly(url: string): string {\n return pathAndQuery(url).split('?')[0];\n}\n\n/** True when `matcher` matches `url`: a string anywhere in the path + query, a RegExp tested on path + query (a global/sticky RegExp is not made stateful). */\nexport function matchesUrl(url: string, matcher: UrlMatcher): boolean {\n const target = pathAndQuery(url);\n if (typeof matcher === 'string') return matcher !== '' && target.includes(matcher);\n matcher.lastIndex = 0;\n const hit = matcher.test(target);\n matcher.lastIndex = 0;\n return hit;\n}\n\nexport function matchesAny(url: string, matchers: readonly UrlMatcher[]): boolean {\n return matchers.some(m => matchesUrl(url, m));\n}\n\nexport function isMutationMethod(method: string): boolean {\n const m = method.toUpperCase();\n return m === 'POST' || m === 'PUT' || m === 'PATCH' || m === 'DELETE';\n}\n\nconst ID_SEGMENT = /^(?:\\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;\n\n/** First id-looking path segment (digits or UUID) with the segment before it as the entity type: '/api/lots/42/notes' -> { entityType: 'lots', entityId: '42' }. */\nexport function deriveEntity(url: string): { entityType?: string; entityId?: string } {\n const segments = pathOnly(url).split('/').filter(Boolean);\n for (let i = 1; i < segments.length; i++) {\n if (ID_SEGMENT.test(segments[i])) return { entityType: segments[i - 1], entityId: segments[i] };\n }\n return {};\n}\n\n/** The path prefix whose stored GET copies a successful write may have made stale: the path without trailing id segments ('/api/contacts/12' -> '/api/contacts'). */\nexport function invalidationPrefix(url: string): string {\n const segments = pathOnly(url).split('/').filter(Boolean);\n while (segments.length > 1 && ID_SEGMENT.test(segments[segments.length - 1])) segments.pop();\n return '/' + segments.join('/');\n}\n\nconst resolvedCache = new WeakMap<OfflineSupportConfig, ResolvedOfflineConfig>();\n\n/** `resolveConfig` memoised per config object (interceptors run on every request). */\nexport function resolveConfigCached(cfg: OfflineSupportConfig): ResolvedOfflineConfig {\n let resolved = resolvedCache.get(cfg);\n if (!resolved) {\n resolved = resolveConfig(cfg);\n resolvedCache.set(cfg, resolved);\n }\n return resolved;\n}\n\n/**\n * Payment routes must NEVER be queued, retried in the background or replayed (a replay after reconnect is a second charge). This builds the entries of the config's EXISTING `blockOffline`\n * list from the app's payment URL patterns, so a payment POST fails fast with `OfflineBlockedError` while offline / unreachable and nothing is stored:\n *\n * provideOfflineSupport({ getUserId, blockOffline: [...blockPaymentsOffline([/\\/api\\/payments(\\/|$)/, '/api/portal/pay'], 'Payments need an internet connection.')] })\n *\n * Also add the same patterns to `neverCache`. The payment forms of `@forgeroute/ui/stripe|square|quickbooks` do not use this layer themselves (the QuickBooks tokenizer is a plain `fetch` with its own\n * AbortController); the host's own payment calls (create payment, status check) go through the host's HttpClient and are the ones to exclude.\n */\nexport function blockPaymentsOffline(patterns: readonly UrlMatcher[], message?: string): { pattern: UrlMatcher; message?: string }[] {\n return patterns.map(pattern => ({ pattern, ...(message ? { message } : {}) }));\n}\n\n/** True when the request is one the offline layer looks at: under `apiPrefix` and not matched by `skip`. */\nexport function isInScope(url: string, cfg: ResolvedOfflineConfig): boolean {\n return url.includes(cfg.apiPrefix) && !matchesAny(url, cfg.skip);\n}\n\nexport function lastSegmentIsId(url: string): boolean {\n const segments = pathOnly(url).split('/').filter(Boolean);\n return segments.length > 0 && ID_SEGMENT.test(segments[segments.length - 1]);\n}\n","/**\n * A v4 UUID. Uses `crypto.randomUUID` when the browser has it (Safari < 15.4 and insecure contexts do not),\n * then `crypto.getRandomValues`, then `Math.random` as the last resort. Always 36 characters.\n */\nexport function generateUuid(): string {\n const c: Crypto | undefined = typeof globalThis !== 'undefined' ? (globalThis as { crypto?: Crypto }).crypto : undefined;\n if (c && typeof c.randomUUID === 'function') {\n try { return c.randomUUID(); } catch { /* insecure context: fall through */ }\n }\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === 'function') {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0'));\n return `${hex.slice(0, 4).join('')}-${hex.slice(4, 6).join('')}-${hex.slice(6, 8).join('')}-${hex.slice(8, 10).join('')}-${hex.slice(10, 16).join('')}`;\n}\n","import { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Injectable, computed, inject, signal } from '@angular/core';\nimport { Subject } from 'rxjs';\nimport { OFFLINE_SUPPORT_CONFIG, resolveConfig } from '../config/offline-config';\n\nexport type ConnectionState = 'online' | 'slow' | 'unreachable' | 'offline';\n\nexport interface RecordRequestInfo {\n durationMs: number;\n ok: boolean;\n status: number;\n timedOut?: boolean;\n method: string;\n /** Long requests (blob / FormData / `longRequests`) never count as slow. Additive to the documented shape. */\n long?: boolean;\n}\n\n/** What made the connection usable again: the browser `online` event / a normal request that got an answer, or the probe. */\nexport type RecoveryTrigger = 'online' | 'probe';\n\n/** Debounce for the browser `online` event (flapping wifi). `offline` is applied at once: queueing is always the safe side. */\nexport const ONLINE_DEBOUNCE_MS = 300;\nconst PROBE_TIMEOUT_MS = 5000;\n\n/**\n * The one answer to \"can this device reach the server?\": online | slow | unreachable | offline.\n * Measured from real request timings (works in Safari/Firefox, which have no `navigator.connection`), the browser online/offline events and an\n * optional probe GET that runs only while the connection is suspect.\n */\n@Injectable({ providedIn: 'root' })\nexport class ConnectionStateService {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly win = inject(DOCUMENT).defaultView;\n\n private readonly browserOnline = signal(this.readNavigatorOnline());\n private readonly unreachable = signal(false);\n private readonly slowFlag = signal(false);\n private readonly _slowRequestActive = signal(false);\n private readonly _inFlightCount = signal(0);\n private readonly _state = signal<ConnectionState>(this.browserOnline() ? 'online' : 'offline');\n private readonly _lastChangeAt = signal(Date.now());\n\n readonly state = this._state.asReadonly();\n readonly isOnline = computed(() => this._state() === 'online' || this._state() === 'slow');\n readonly isOffline = computed(() => this._state() === 'offline' || this._state() === 'unreachable');\n /** Some request has been in flight longer than `slow.stuckMs`. */\n readonly slowRequestActive = this._slowRequestActive.asReadonly();\n readonly inFlightCount = this._inFlightCount.asReadonly();\n readonly lastChangeAt = this._lastChangeAt.asReadonly();\n /** True while the user should be told \"this is taking a while\" (a request is stuck or the connection is slow). */\n readonly slowRequestHint = computed(() => this._slowRequestActive() || this._state() === 'slow');\n /** Emits when the connection became usable again; the replayer listens to it. */\n readonly recovered$ = new Subject<RecoveryTrigger>();\n\n private failures: number[] = [];\n private slowTimes: number[] = [];\n private quietTimer: ReturnType<typeof setTimeout> | null = null;\n private onlineTimer: ReturnType<typeof setTimeout> | null = null;\n private probeTimer: ReturnType<typeof setInterval> | null = null;\n private optimisticTimer: ReturnType<typeof setTimeout> | null = null;\n private probeInFlight: Promise<boolean> | null = null;\n private readonly inFlight = new Map<number, { start: number; stuck: boolean; timer: ReturnType<typeof setTimeout> | null }>();\n private nextRequestId = 0;\n\n private readonly onWindowOnline = () => this.scheduleOnline();\n private readonly onWindowOffline = () => { this.cancelOnlineTimer(); this.setBrowserOnline(false); };\n private readonly onFocus = () => this.syncFromNavigator();\n\n constructor() {\n const win = this.win;\n if (win) {\n win.addEventListener('online', this.onWindowOnline);\n win.addEventListener('offline', this.onWindowOffline);\n win.addEventListener('focus', this.onFocus);\n win.document?.addEventListener('visibilitychange', this.onFocus);\n }\n inject(DestroyRef).onDestroy(() => this.teardown());\n }\n\n /** Called by `connectionInterceptor` when a request finished (or failed / timed out). */\n recordRequest(info: RecordRequestInfo): void {\n const now = Date.now();\n if (info.timedOut || info.status === 0) {\n this.handleFailure(now);\n return;\n }\n // The server answered (any HTTP status): it is reachable.\n this.failures = [];\n if (this.unreachable()) this.clearUnreachable('online');\n if (info.long) return;\n if (info.durationMs >= this.cfg.slow.slowMs) {\n this.slowTimes = this.slowTimes.filter(t => now - t <= this.cfg.slow.windowMs);\n this.slowTimes.push(now);\n if (this.slowTimes.length >= this.cfg.slow.slowCount || this.slowFlag()) this.markSlow();\n }\n }\n\n /**\n * Starts tracking one request; call the returned function when it ends (success, error, timeout or cancel; calling it twice is harmless).\n * A non-long request still in flight after `slow.stuckMs` turns `slowRequestActive` and the state to `slow`.\n */\n beginRequest(options: { long?: boolean } = {}): () => void {\n const id = ++this.nextRequestId;\n const entry: { start: number; stuck: boolean; timer: ReturnType<typeof setTimeout> | null } = { start: Date.now(), stuck: false, timer: null };\n this.inFlight.set(id, entry);\n this._inFlightCount.set(this.inFlight.size);\n if (!options.long) {\n entry.timer = setTimeout(() => {\n entry.timer = null;\n if (!this.inFlight.has(id)) return;\n entry.stuck = true;\n this._slowRequestActive.set(true);\n this.markSlow();\n }, this.cfg.slow.stuckMs);\n }\n return () => {\n const current = this.inFlight.get(id);\n if (!current) return;\n if (current.timer) clearTimeout(current.timer);\n this.inFlight.delete(id);\n this._inFlightCount.set(this.inFlight.size);\n this._slowRequestActive.set([...this.inFlight.values()].some(e => e.stuck));\n this.recompute();\n };\n }\n\n /**\n * Asks the probe URL once. Resolves true when it answered with ANY HTTP status (a 401 still proves the server is reachable).\n * Without a configured probe there is nothing to ask: the answer is what the browser says.\n */\n probeNow(): Promise<boolean> {\n const probe = this.cfg.probe;\n if (!probe) return Promise.resolve(this.browserOnline());\n if (this.probeInFlight) return this.probeInFlight;\n const run = this.runProbe(probe.url).then(ok => {\n if (ok) this.onProbeSuccess();\n return ok;\n }).finally(() => { this.probeInFlight = null; });\n this.probeInFlight = run;\n return run;\n }\n\n private async runProbe(url: string): Promise<boolean> {\n const win = this.win;\n if (!win || typeof win.fetch !== 'function') return false;\n const controller = typeof AbortController === 'function' ? new AbortController() : null;\n const timer = controller ? setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS) : null;\n try {\n await win.fetch(url, { method: 'GET', cache: 'no-store', credentials: 'same-origin', signal: controller?.signal });\n return true;\n } catch {\n return false;\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n\n private onProbeSuccess(): void {\n this.failures = [];\n if (this.unreachable()) this.clearUnreachable('probe');\n }\n\n private handleFailure(now: number): void {\n if (!this.browserOnline()) return;\n this.failures = this.failures.filter(t => now - t <= this.cfg.slow.windowMs);\n this.failures.push(now);\n if (this.failures.length >= 2) {\n this.setUnreachable();\n return;\n }\n if (this.cfg.probe) {\n void this.probeNow().then(ok => {\n if (!ok && this.browserOnline() && this.failures.length > 0) this.setUnreachable();\n });\n }\n }\n\n private setUnreachable(): void {\n if (this.unreachable()) return;\n this.unreachable.set(true);\n this.recompute();\n if (this.cfg.probe) {\n this.probeTimer = setInterval(() => { void this.probeNow(); }, this.cfg.probe.intervalMs);\n } else {\n // No probe to ask: assume it may be back after a while. The next failing request flips it straight back.\n this.optimisticTimer = setTimeout(() => {\n this.optimisticTimer = null;\n if (this.unreachable()) this.clearUnreachable('online');\n }, 15000);\n }\n }\n\n private clearUnreachable(trigger: RecoveryTrigger): void {\n if (!this.unreachable()) return;\n this.unreachable.set(false);\n this.stopRecoveryTimers();\n this.recompute();\n if (this.browserOnline()) this.recovered$.next(trigger);\n }\n\n private stopRecoveryTimers(): void {\n if (this.probeTimer) { clearInterval(this.probeTimer); this.probeTimer = null; }\n if (this.optimisticTimer) { clearTimeout(this.optimisticTimer); this.optimisticTimer = null; }\n }\n\n private markSlow(): void {\n this.slowFlag.set(true);\n if (this.quietTimer) clearTimeout(this.quietTimer);\n this.quietTimer = setTimeout(() => {\n this.quietTimer = null;\n this.slowFlag.set(false);\n this.slowTimes = [];\n this.recompute();\n }, this.cfg.slow.quietMs);\n this.recompute();\n }\n\n private scheduleOnline(): void {\n this.cancelOnlineTimer();\n this.onlineTimer = setTimeout(() => {\n this.onlineTimer = null;\n this.setBrowserOnline(true);\n }, ONLINE_DEBOUNCE_MS);\n }\n\n private cancelOnlineTimer(): void {\n if (this.onlineTimer) { clearTimeout(this.onlineTimer); this.onlineTimer = null; }\n }\n\n private setBrowserOnline(value: boolean): void {\n if (this.browserOnline() === value) return;\n this.browserOnline.set(value);\n if (value) {\n // Back from a real outage: forget the old failures and the old \"unreachable\" verdict; the next requests decide again.\n this.failures = [];\n if (this.unreachable()) { this.unreachable.set(false); this.stopRecoveryTimers(); }\n this.recompute();\n this.recovered$.next('online');\n } else {\n this.recompute();\n }\n }\n\n private syncFromNavigator(): void {\n if (!this.readNavigatorOnline()) { this.cancelOnlineTimer(); this.setBrowserOnline(false); }\n else if (!this.browserOnline()) this.scheduleOnline(); // a missed `online` event (sleep / wifi roaming): the browser says online again\n }\n\n private readNavigatorOnline(): boolean {\n try {\n return this.win?.navigator?.onLine !== false;\n } catch {\n return true;\n }\n }\n\n private recompute(): void {\n const next: ConnectionState = !this.browserOnline() ? 'offline'\n : this.unreachable() ? 'unreachable'\n : (this.slowFlag() || this._slowRequestActive()) ? 'slow'\n : 'online';\n if (next === this._state()) return;\n this._state.set(next);\n this._lastChangeAt.set(Date.now());\n }\n\n private teardown(): void {\n const win = this.win;\n if (win) {\n win.removeEventListener('online', this.onWindowOnline);\n win.removeEventListener('offline', this.onWindowOffline);\n win.removeEventListener('focus', this.onFocus);\n win.document?.removeEventListener('visibilitychange', this.onFocus);\n }\n this.cancelOnlineTimer();\n this.stopRecoveryTimers();\n if (this.quietTimer) { clearTimeout(this.quietTimer); this.quietTimer = null; }\n for (const e of this.inFlight.values()) if (e.timer) clearTimeout(e.timer);\n this.inFlight.clear();\n this.recovered$.complete();\n }\n}\n","import { Injectable, signal } from '@angular/core';\n\n/** Key used by callers that do not track which request a stale copy belongs to. */\nconst DEFAULT_KEY = '*';\n\n/** Tells the UI when what the user sees came from the device copy instead of the server. Tracked per request key (the cache key of the GET). */\n@Injectable({ providedIn: 'root' })\nexport class StaleDataService {\n private readonly _staleAt = signal<number | null>(null);\n private readonly entries = new Map<string, number>();\n /** `cachedAt` of the most recent cache-served GET that has not been replaced by a live answer for the same request; null = everything shown is live. */\n readonly staleAt = this._staleAt.asReadonly();\n\n markStale(cachedAt: number, key: string = DEFAULT_KEY): void {\n this.entries.set(key, cachedAt);\n this.publish();\n }\n\n /** A live answer arrived for this request: only its own stale mark goes away. */\n clearKey(key: string): void {\n if (this.entries.delete(key)) this.publish();\n }\n\n /** Forgets every stale mark. */\n clear(): void {\n if (this.entries.size === 0) return;\n this.entries.clear();\n this.publish();\n }\n\n private publish(): void {\n let latest: number | null = null;\n for (const v of this.entries.values()) if (latest === null || v > latest) latest = v;\n this._staleAt.set(latest);\n }\n}\n","import { Injectable, InjectionToken, inject } from '@angular/core';\nimport { Subject } from 'rxjs';\nimport { uiText } from '@forgeroute/ui';\nimport { OFFLINE_SUPPORT_CONFIG, hasStampField, resolveConfig, stripStampFields } from '../config/offline-config';\n\nexport type MutationStatus = 'pending' | 'syncing' | 'failed' | 'conflict';\nexport type MutationErrorKind = 'conflict' | 'rejected' | 'auth' | 'server' | 'network' | 'timeout' | 'dependency';\n\nexport interface MutationError {\n kind: MutationErrorKind;\n status?: number;\n message: string;\n}\n\nexport interface OfflineMutation {\n id: string;\n seq: number;\n userId: string;\n /** The Idempotency-Key header of the original request; re-sent unchanged on every replay. */\n key: string;\n method: string;\n url: string;\n body: unknown;\n headers?: Record<string, string>;\n label: string;\n entityType?: string;\n entityId?: string;\n createdAt: number;\n status: MutationStatus;\n claimOwner?: string;\n claimAt?: number;\n attempts: number;\n nextAttemptAt?: number;\n lastError?: MutationError;\n /**\n * Set on a queued POST to a collection whose body had no id of its own: the client-made id handed out in the synthetic 202 (equals `id`).\n * Later saved changes may refer to it; after this row is delivered it is mapped to the server's real id (store `idmap`).\n */\n tempId?: string;\n /** Ids of the queued create rows whose temp id this change refers to (URL, query or body), set when the change was saved. */\n dependsOn?: string[];\n /** The temp ids behind `dependsOn`, same order (needed after the create row is gone to find its `idmap` entry). */\n dependsOnTempIds?: string[];\n /** Set by \"Keep my version\": the conflict stamp fields were removed from the body on the user's explicit choice, so this change overwrites the server's newer version. Kept for traceability. */\n overwrite?: boolean;\n}\n\nexport type NewMutation = Omit<OfflineMutation, 'seq'>;\n\nexport interface CachedEntry {\n /** Composite primary key: `<userId>::<url key>`. */\n key: string;\n urlKey: string;\n userId: string;\n data: unknown;\n cachedAt: number;\n expiresAt: number;\n}\n\n/** Maps a temp id to the real id the server gave the record. Key `<userId>:<tempId>`; kept 7 days. */\nexport interface IdMapEntry {\n key: string;\n userId: string;\n tempId: string;\n /** Always text; `numeric` tells that the server's id was a number (so a JSON body gets a number back). */\n realId: string;\n numeric?: boolean;\n createdAt: number;\n expiresAt: number;\n}\n\nexport const IDMAP_TTL_MS = 7 * 24 * 60 * 60 * 1000;\n\nexport interface MutationCounts { pending: number; syncing: number; failed: number; conflict: number }\n\n/** A claim older than this in status `syncing` belongs to a tab that died mid-send and may be taken over. */\nexport const STALE_CLAIM_MS = 60_000;\nconst DB_VERSION = 2;\nconst OPEN_TIMEOUT_MS = 10_000;\nconst MAX_CACHE_ENTRIES = 500;\nconst EVICT_COUNT = 50;\nconst MUTATIONS = 'mutations';\nconst RESPONSES = 'responses';\nconst META = 'meta';\nconst IDMAP = 'idmap';\n\n/** IndexedDB, or null when the browser has none / refuses access (some privacy modes throw on the property read). */\nexport const OFFLINE_IDB_FACTORY = new InjectionToken<IDBFactory | null>('OFFLINE_IDB_FACTORY', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof indexedDB !== 'undefined' ? indexedDB : null;\n } catch {\n return null;\n }\n },\n});\n\n/** IndexedDB is missing, blocked or failed to open: nothing can be saved on this device. */\nexport class StorageUnavailableError extends Error {\n constructor(message: string = uiText('connection.storageNotAvailable')) {\n super(message);\n this.name = 'StorageUnavailableError';\n Object.setPrototypeOf(this, StorageUnavailableError.prototype);\n }\n}\n\n/** The user already has `maxQueue` saved changes. */\nexport class QueueFullError extends Error {\n constructor(readonly limit: number) {\n super(uiText('connection.queueFull', { limit }));\n this.name = 'QueueFullError';\n Object.setPrototypeOf(this, QueueFullError.prototype);\n }\n}\n\nexport function isQuotaError(e: unknown): boolean {\n const x = e as { name?: string; code?: number } | null;\n return !!x && (x.name === 'QuotaExceededError' || x.name === 'NS_ERROR_DOM_QUOTA_REACHED' || x.code === 22 || x.code === 1014);\n}\n\nfunction isInvalidState(e: unknown): boolean {\n const x = e as { name?: string } | null;\n return !!x && (x.name === 'InvalidStateError' || x.name === 'TransactionInactiveError');\n}\n\nconst RETRYABLE_FAILURES: readonly MutationErrorKind[] = ['server', 'network', 'timeout'];\n\n/** True when `claim` may take the row: pending, a failed row whose failure was transient, or a `syncing` row whose claim went stale. */\nexport function isClaimable(row: OfflineMutation, now: number): boolean {\n if (row.status === 'pending') return true;\n if (row.status === 'failed') return !!row.lastError && RETRYABLE_FAILURES.includes(row.lastError.kind);\n if (row.status === 'syncing') return now - (row.claimAt ?? 0) > STALE_CLAIM_MS;\n return false;\n}\n\ntype Stores = Record<string, IDBObjectStore>;\n\n/**\n * Thin promise wrapper over IndexedDB: the queued writes (`mutations`) and the per-user device copy of GET answers (`responses`).\n * Every row and cache entry carries its `userId`; reads and deletes are always scoped to a user. If IndexedDB cannot be used,\n * `available()` is false and callers must refuse to queue (never a fake success).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineStore {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly factory = inject(OFFLINE_IDB_FACTORY);\n\n /** Emits after every write to the saved changes (add, claim, update, delete, clear); other tabs are told by OfflineSupportService. */\n readonly mutated$ = new Subject<void>();\n\n private db: IDBDatabase | null = null;\n private opening: Promise<IDBDatabase> | null = null;\n private initPromise: Promise<void> | null = null;\n private ready = false;\n\n available(): boolean {\n return this.ready;\n }\n\n /** Opens the database. Never rejects: on failure `available()` stays false (and a later `init()` tries again). */\n init(): Promise<void> {\n if (!this.initPromise) {\n this.initPromise = this.doInit().then(() => {\n if (!this.ready) this.initPromise = null;\n });\n }\n return this.initPromise;\n }\n\n private async doInit(): Promise<void> {\n if (!this.factory) { this.ready = false; return; }\n try {\n await this.getDb();\n this.ready = true;\n } catch {\n this.ready = false;\n return;\n }\n try { await this.purgeExpired(); } catch { /* cleanup is best effort */ }\n try { await this.purgeExpiredIdMap(); } catch { /* cleanup is best effort */ }\n }\n\n // ---- saved changes -------------------------------------------------------------------------------------------------------------\n\n /**\n * Saves a new change. If this user already has a row with the same idempotency `key` that row is returned instead (a double click that\n * re-used the key must not queue twice). Rejects with QueueFullError, StorageUnavailableError or the storage error (e.g. QuotaExceededError).\n */\n async addMutation(row: NewMutation): Promise<OfflineMutation> {\n await this.init();\n if (!this.ready) throw new StorageUnavailableError();\n const limit = this.cfg.maxQueue;\n const saved = await this.runTx<OfflineMutation>([MUTATIONS, META], 'readwrite', (s, resolveWith, abortWith) => {\n const existing = s[MUTATIONS].index('userId').getAll(row.userId) as IDBRequest<OfflineMutation[]>;\n existing.onsuccess = () => {\n const rows = existing.result;\n const dup = rows.find(r => r.key === row.key);\n if (dup) { resolveWith(dup); return; }\n if (rows.length >= limit) { abortWith(new QueueFullError(limit)); return; }\n const seqReq = s[META].get('seq') as IDBRequest<{ id: string; value: number } | undefined>;\n seqReq.onsuccess = () => {\n const seq = (seqReq.result?.value ?? 0) + 1;\n const full: OfflineMutation = { ...row, seq };\n s[META].put({ id: 'seq', value: seq });\n s[MUTATIONS].add(full);\n resolveWith(full);\n };\n };\n });\n this.mutated$.next();\n return saved;\n }\n\n /**\n * Atomically takes a row for sending: only if it is pending, failed with a transient error, or `syncing` with a claim older than 60 s.\n * Returns the claimed row, or null when it is gone or somebody else holds a live claim.\n */\n async claim(id: string, owner: string, now: number = Date.now()): Promise<OfflineMutation | null> {\n const claimed = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || !isClaimable(row, now)) return;\n const next: OfflineMutation = { ...row, status: 'syncing', claimOwner: owner, claimAt: now };\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (claimed) this.mutated$.next();\n return claimed;\n }\n\n /** Merges `patch` into the row (an `undefined` value removes the field). With `ifOwner` it only applies while that owner still holds the claim. */\n async update(id: string, patch: Partial<OfflineMutation>, opts: { ifOwner?: string } = {}): Promise<OfflineMutation | null> {\n const updated = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row) return;\n if (opts.ifOwner !== undefined && row.claimOwner !== opts.ifOwner) return;\n const merged = { ...row, ...patch, id: row.id, userId: row.userId } as OfflineMutation;\n const loose = merged as unknown as Record<string, unknown>;\n for (const k of Object.keys(loose)) if (loose[k] === undefined) delete loose[k];\n s[MUTATIONS].put(merged);\n resolveWith(merged);\n };\n });\n if (updated) this.mutated$.next();\n return updated;\n }\n\n /**\n * The user's \"Retry\": puts one row (any status) back to pending with 0 attempts, in ONE transaction so a claim taken in between cannot be overwritten.\n * Returns the reset row, or null when the row is missing, belongs to another user, or is being sent right now (live claim).\n */\n async resetForRetry(id: string, userId: string, now: number = Date.now()): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n const reset = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || row.userId !== userId) return;\n if (row.status === 'syncing' && now - (row.claimAt ?? 0) <= STALE_CLAIM_MS) return;\n const next: OfflineMutation = { ...row, status: 'pending', attempts: 0 };\n delete next.nextAttemptAt;\n delete next.lastError;\n delete next.claimOwner;\n delete next.claimAt;\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (reset) this.mutated$.next();\n return reset;\n }\n\n /**\n * The user's \"Keep my version\": in ONE transaction, only for a row in status `conflict` that belongs to `userId` and whose body has at least one of\n * the stamp `fields`: removes those fields from the body, gives it a NEW idempotency key (the old one is bound to the stored 409 on the server), sets it\n * back to pending with 0 attempts and marks `overwrite: true`. id, seq, createdAt and dependencies are kept. LATER rows of the same record are NOT\n * touched here: they keep their stamp (and stay held / pending) until the overwrite has really been delivered; only then does the replayer call\n * `stripStampsAfter`. So if the overwrite fails for good or is discarded, a later edit is never sent unstamped.\n * Returns the row, or null when it is missing, foreign, not in conflict, or has no stamp field (nothing to overwrite: it would re-send an unchanged body).\n */\n async resetForKeepMine(id: string, userId: string, fields: readonly string[], newKey: string): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n const reset = await this.runTx<OfflineMutation | null>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row || row.userId !== userId || row.status !== 'conflict' || !hasStampField(row.body, fields)) return;\n const next: OfflineMutation = { ...row, body: stripStampFields(row.body, fields), key: newKey, status: 'pending', attempts: 0, overwrite: true };\n delete next.nextAttemptAt;\n delete next.lastError;\n delete next.claimOwner;\n delete next.claimAt;\n s[MUTATIONS].put(next);\n resolveWith(next);\n };\n });\n if (reset) this.mutated$.next();\n return reset;\n }\n\n /**\n * Called after a \"Keep my version\" overwrite was DELIVERED: removes the stamp `fields` from every row of `userId` for the same record (entityType +\n * entityId) with a higher seq than `afterSeq` that is still `pending` (marks them `overwrite: true`), so they do not each turn into another conflict.\n * failed / conflict / syncing rows and rows of other records are left exactly as they are. Returns how many rows changed.\n */\n async stripStampsAfter(userId: string, entityType: string, entityId: string, afterSeq: number, fields: readonly string[]): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n const changed = await this.runTx<number>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const all = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n all.onsuccess = () => {\n let n = 0;\n for (const r of all.result) {\n if (r.userId !== userId || r.seq <= afterSeq || r.status !== 'pending') continue;\n if (r.entityType !== entityType || r.entityId !== entityId || !hasStampField(r.body, fields)) continue;\n s[MUTATIONS].put({ ...r, body: stripStampFields(r.body, fields), overwrite: true });\n n++;\n }\n resolveWith(n);\n };\n });\n if (changed > 0) this.mutated$.next();\n return changed;\n }\n\n async get(id: string): Promise<OfflineMutation | null> {\n if (!(await this.ensureReady())) return null;\n return this.runTx<OfflineMutation | null>([MUTATIONS], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n });\n }\n\n /** Deletes the row; with `ifOwner` only while that owner still holds the claim. Returns whether a row was deleted. */\n async delete(id: string, opts: { ifOwner?: string } = {}): Promise<boolean> {\n const deleted = await this.runTx<boolean>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(false);\n const req = s[MUTATIONS].get(id) as IDBRequest<OfflineMutation | undefined>;\n req.onsuccess = () => {\n const row = req.result;\n if (!row) return;\n if (opts.ifOwner !== undefined && row.claimOwner !== opts.ifOwner) return;\n s[MUTATIONS].delete(id);\n resolveWith(true);\n };\n });\n if (deleted) this.mutated$.next();\n return deleted;\n }\n\n /** The user's rows in send order (seq, then createdAt). */\n async list(userId: string): Promise<OfflineMutation[]> {\n if (!(await this.ensureReady())) return [];\n const rows = await this.runTx<OfflineMutation[]>([MUTATIONS], 'readonly', (s, resolveWith) => {\n resolveWith([]);\n const req = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n req.onsuccess = () => resolveWith(req.result);\n });\n return rows.filter(r => r.userId === userId).sort((a, b) => a.seq - b.seq || a.createdAt - b.createdAt);\n }\n\n async count(userId: string): Promise<number> {\n return (await this.list(userId)).length;\n }\n\n async countsByStatus(userId: string): Promise<MutationCounts> {\n const counts: MutationCounts = { pending: 0, syncing: 0, failed: 0, conflict: 0 };\n for (const r of await this.list(userId)) counts[r.status]++;\n return counts;\n }\n\n /** Deletes only the saved changes of this user (their device copy of GET answers stays). */\n async deleteMutations(userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n const removed = await this.runTx<number>([MUTATIONS], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[MUTATIONS].index('userId').getAll(userId) as IDBRequest<OfflineMutation[]>;\n req.onsuccess = () => {\n const rows = req.result.filter(r => r.userId === userId);\n for (const r of rows) s[MUTATIONS].delete(r.id);\n resolveWith(rows.length);\n };\n });\n if (removed > 0) this.mutated$.next();\n return removed;\n }\n\n /** Deletes this user's saved changes AND device copy. Never touches another user's data. */\n async clearUser(userId: string): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.deleteMutations(userId);\n await this.clearCache(userId);\n await this.deleteIdMap(userId);\n }\n\n /** Deletes everything for every user (rows, device copy). Only for an explicit, confirmed full reset. */\n async clearAll(): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.runTx<void>([MUTATIONS, RESPONSES, IDMAP], 'readwrite', (s) => {\n s[MUTATIONS].clear();\n s[RESPONSES].clear();\n s[IDMAP].clear();\n });\n this.mutated$.next();\n }\n\n // ---- temp id -> real id ---------------------------------------------------------------------------------------------------------\n\n /** Saves (or overwrites: a replayed create gives the same answer) the real id for a temp id. Rejects when the write fails. */\n async putIdMapping(userId: string, tempId: string, realId: string | number, now: number = Date.now()): Promise<IdMapEntry> {\n await this.init();\n if (!this.ready) throw new StorageUnavailableError();\n const entry: IdMapEntry = {\n key: `${userId}:${tempId}`, userId, tempId, realId: String(realId), createdAt: now, expiresAt: now + IDMAP_TTL_MS,\n ...(typeof realId === 'number' ? { numeric: true } : {}),\n };\n await this.runTx<void>([IDMAP], 'readwrite', s => { s[IDMAP].put(entry); });\n return entry;\n }\n\n /** The user's real id for `tempId`, or null (missing, expired, or somebody else's). */\n async getIdMapping(userId: string, tempId: string, now: number = Date.now()): Promise<IdMapEntry | null> {\n if (!(await this.ensureReady())) return null;\n const entry = await this.runTx<IdMapEntry | null>([IDMAP], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[IDMAP].get(`${userId}:${tempId}`) as IDBRequest<IdMapEntry | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n });\n return entry && entry.userId === userId && entry.expiresAt > now ? entry : null;\n }\n\n /** All of the user's unexpired temp id mappings. */\n async listIdMap(userId: string, now: number = Date.now()): Promise<IdMapEntry[]> {\n if (!(await this.ensureReady())) return [];\n const all = await this.runTx<IdMapEntry[]>([IDMAP], 'readonly', (s, resolveWith) => {\n resolveWith([]);\n const req = s[IDMAP].index('userId').getAll(userId) as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => resolveWith(req.result);\n });\n return all.filter(e => e.userId === userId && e.expiresAt > now);\n }\n\n /** Deletes this user's temp id mappings only. */\n async deleteIdMap(userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n return this.runTx<number>([IDMAP], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[IDMAP].index('userId').getAll(userId) as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => {\n const mine = req.result.filter(e => e.userId === userId);\n for (const e of mine) s[IDMAP].delete(e.key);\n resolveWith(mine.length);\n };\n });\n }\n\n /** Removes mappings whose 7 days are over (every user). Returns how many. */\n async purgeExpiredIdMap(now: number = Date.now()): Promise<number> {\n return this.runTx<number>([IDMAP], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[IDMAP].getAll() as IDBRequest<IdMapEntry[]>;\n req.onsuccess = () => {\n const old = req.result.filter(e => e.expiresAt <= now);\n for (const e of old) s[IDMAP].delete(e.key);\n resolveWith(old.length);\n };\n });\n }\n\n // ---- device copy of GET answers --------------------------------------------------------------------------------------------------\n\n /** Stores a GET answer for this user. Returns false when it could not be stored (never throws: the copy is optional). */\n async cacheResponse(key: string, userId: string, data: unknown, ttlMs: number, now: number = Date.now()): Promise<boolean> {\n if (!(await this.ensureReady())) return false;\n const entry: CachedEntry = { key: `${userId}::${key}`, urlKey: key, userId, data, cachedAt: now, expiresAt: now + ttlMs };\n const put = () => this.runTx<void>([RESPONSES], 'readwrite', s => { s[RESPONSES].put(entry); });\n try {\n await put();\n } catch (e) {\n if (!isQuotaError(e)) return false;\n try {\n await this.evictOldest(EVICT_COUNT, now);\n await put();\n } catch {\n return false;\n }\n }\n void this.enforceCacheLimit().catch(() => undefined);\n return true;\n }\n\n /** The user's stored answer for `key`, or null (missing, expired or belonging to somebody else). */\n async getCached(key: string, userId: string, now: number = Date.now()): Promise<CachedEntry | null> {\n if (!(await this.ensureReady())) return null;\n const composite = `${userId}::${key}`;\n const entry = await this.runTx<CachedEntry | null>([RESPONSES], 'readonly', (s, resolveWith) => {\n resolveWith(null);\n const req = s[RESPONSES].get(composite) as IDBRequest<CachedEntry | undefined>;\n req.onsuccess = () => resolveWith(req.result ?? null);\n }).catch(() => null);\n if (!entry || entry.userId !== userId) return null;\n if (entry.expiresAt <= now) {\n void this.runTx<void>([RESPONSES], 'readwrite', s => { s[RESPONSES].delete(composite); }).catch(() => undefined);\n return null;\n }\n return entry;\n }\n\n /** Removes this user's stored answers whose URL key starts with `prefix`. */\n async invalidatePrefix(prefix: string, userId: string): Promise<number> {\n if (!(await this.ensureReady())) return 0;\n return this.runTx<number>([RESPONSES], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].index('userId').getAll(userId) as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const hits = req.result.filter(e => e.userId === userId && e.urlKey.startsWith(prefix));\n for (const e of hits) s[RESPONSES].delete(e.key);\n resolveWith(hits.length);\n };\n }).catch(() => 0);\n }\n\n /** Deletes the device copy of one user, or of everybody when `userId` is omitted. Saved changes are never touched. */\n async clearCache(userId?: string): Promise<void> {\n if (!(await this.ensureReady())) return;\n await this.runTx<void>([RESPONSES], 'readwrite', (s) => {\n if (userId === undefined) { s[RESPONSES].clear(); return; }\n const req = s[RESPONSES].index('userId').getAll(userId) as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => { for (const e of req.result) if (e.userId === userId) s[RESPONSES].delete(e.key); };\n });\n }\n\n async purgeExpired(now: number = Date.now()): Promise<number> {\n return this.runTx<number>([RESPONSES], 'readwrite', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].getAll() as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const old = req.result.filter(e => e.expiresAt <= now);\n for (const e of old) s[RESPONSES].delete(e.key);\n resolveWith(old.length);\n };\n });\n }\n\n private async evictOldest(count: number, now: number): Promise<void> {\n await this.runTx<void>([RESPONSES], 'readwrite', (s) => {\n const req = s[RESPONSES].getAll() as IDBRequest<CachedEntry[]>;\n req.onsuccess = () => {\n const sorted = [...req.result].sort((a, b) => (a.expiresAt <= now ? 0 : 1) - (b.expiresAt <= now ? 0 : 1) || a.cachedAt - b.cachedAt);\n for (const e of sorted.slice(0, count)) s[RESPONSES].delete(e.key);\n };\n });\n }\n\n private async enforceCacheLimit(): Promise<void> {\n const total = await this.runTx<number>([RESPONSES], 'readonly', (s, resolveWith) => {\n resolveWith(0);\n const req = s[RESPONSES].count() as IDBRequest<number>;\n req.onsuccess = () => resolveWith(req.result);\n });\n if (total > MAX_CACHE_ENTRIES) await this.evictOldest(EVICT_COUNT, Date.now());\n }\n\n // ---- plumbing ------------------------------------------------------------------------------------------------------------------\n\n private async ensureReady(): Promise<boolean> {\n await this.init();\n return this.ready;\n }\n\n private getDb(): Promise<IDBDatabase> {\n if (this.db) return Promise.resolve(this.db);\n if (this.opening) return this.opening;\n const opening = this.openWithRetry().then(\n db => { this.db = db; this.opening = null; return db; },\n err => { this.opening = null; throw err; },\n );\n this.opening = opening;\n return opening;\n }\n\n private async openWithRetry(): Promise<IDBDatabase> {\n try {\n return await this.openOnce();\n } catch (first) {\n // Safari sometimes fails the very first open of a fresh profile; one more try is what the browsers recommend.\n if (first instanceof StorageUnavailableError || (first as { name?: string } | null)?.name === 'SecurityError') throw first;\n return this.openOnce();\n }\n }\n\n private openOnce(): Promise<IDBDatabase> {\n const factory = this.factory;\n return new Promise<IDBDatabase>((resolve, reject) => {\n if (!factory) { reject(new StorageUnavailableError()); return; }\n let req: IDBOpenDBRequest;\n try {\n req = factory.open(this.cfg.dbName, DB_VERSION);\n } catch (e) {\n reject(e);\n return;\n }\n const timer = setTimeout(() => reject(new StorageUnavailableError(uiText('connection.storageTimeout'))), OPEN_TIMEOUT_MS);\n req.onupgradeneeded = () => {\n const db = req.result;\n if (!db.objectStoreNames.contains(MUTATIONS)) {\n const m = db.createObjectStore(MUTATIONS, { keyPath: 'id' });\n m.createIndex('userId', 'userId');\n m.createIndex('status', 'status');\n m.createIndex('createdAt', 'createdAt');\n }\n if (!db.objectStoreNames.contains(RESPONSES)) {\n const r = db.createObjectStore(RESPONSES, { keyPath: 'key' });\n r.createIndex('userId', 'userId');\n r.createIndex('expiresAt', 'expiresAt');\n }\n if (!db.objectStoreNames.contains(META)) db.createObjectStore(META, { keyPath: 'id' });\n // Version 2 only ADDS this store; every store and row from version 1 is left exactly as it is.\n if (!db.objectStoreNames.contains(IDMAP)) {\n const i = db.createObjectStore(IDMAP, { keyPath: 'key' });\n i.createIndex('userId', 'userId');\n i.createIndex('expiresAt', 'expiresAt');\n }\n };\n req.onsuccess = () => {\n clearTimeout(timer);\n const db = req.result;\n // Another tab wants to upgrade, or the browser closed the connection: drop it so the next call reopens.\n db.onversionchange = () => { db.close(); if (this.db === db) this.db = null; };\n db.onclose = () => { if (this.db === db) this.db = null; };\n resolve(db);\n };\n req.onerror = () => { clearTimeout(timer); reject(req.error ?? new StorageUnavailableError()); };\n req.onblocked = () => { /* waits for the other connection to close; the timeout above ends the wait */ };\n });\n }\n\n private async runTx<T>(\n names: string[],\n mode: IDBTransactionMode,\n work: (stores: Stores, resolveWith: (v: T) => void, abortWith: (e: unknown) => void) => void,\n retried = false,\n ): Promise<T> {\n const db = await this.getDb();\n let tx: IDBTransaction;\n try {\n tx = db.transaction(names, mode);\n } catch (e) {\n if (!retried && isInvalidState(e)) {\n if (this.db === db) this.db = null;\n return this.runTx(names, mode, work, true);\n }\n throw e;\n }\n return new Promise<T>((resolve, reject) => {\n let result: T | undefined;\n let failure: unknown;\n let failed = false;\n const abortWith = (e: unknown) => {\n failed = true;\n failure = e;\n try { tx.abort(); } catch { /* already finished */ }\n };\n tx.oncomplete = () => resolve(result as T);\n tx.onabort = () => reject(failed ? failure : tx.error ?? new Error(uiText('connection.transactionAborted')));\n const stores: Stores = {};\n try {\n for (const n of names) stores[n] = tx.objectStore(n);\n work(stores, v => { result = v; }, abortWith);\n } catch (e) {\n abortWith(e);\n }\n });\n }\n}\n","/** Why an offline write was refused. */\nexport type OfflineBlockedReason = 'blocked' | 'upload' | 'storage' | 'not-allowed';\n\n/**\n * A write that cannot be saved on the device while offline. `message` is plain words for the user (from UiLabelsService or the app's\n * `blockOffline[].message`). Nothing was queued and nothing was sent.\n */\nexport class OfflineBlockedError extends Error {\n readonly offlineBlocked = true;\n readonly status = 0;\n readonly reason: OfflineBlockedReason;\n constructor(message: string, reason: OfflineBlockedReason = 'blocked') {\n super(message);\n this.name = 'OfflineBlockedError';\n this.reason = reason;\n Object.setPrototypeOf(this, OfflineBlockedError.prototype);\n }\n}\n\n/** The client gave up waiting. For a write `outcomeUnknown` is true: the server may still have handled it. */\nexport class RequestTimeoutError extends Error {\n readonly timeout = true;\n readonly status = 0;\n readonly method: string;\n readonly url: string;\n readonly outcomeUnknown: boolean;\n constructor(message: string, method: string, url: string, outcomeUnknown: boolean) {\n super(message);\n this.name = 'RequestTimeoutError';\n this.method = method;\n this.url = url;\n this.outcomeUnknown = outcomeUnknown;\n Object.setPrototypeOf(this, RequestTimeoutError.prototype);\n }\n}\n\nexport function isOfflineBlockedError(e: unknown): e is OfflineBlockedError {\n return e instanceof OfflineBlockedError || (typeof e === 'object' && e !== null && (e as { offlineBlocked?: unknown }).offlineBlocked === true);\n}\n\nexport function isRequestTimeoutError(e: unknown): e is RequestTimeoutError {\n return e instanceof RequestTimeoutError || (typeof e === 'object' && e !== null && (e as { timeout?: unknown }).timeout === true && (e as { status?: unknown }).status === 0);\n}\n","import { lastSegmentIsId } from '../config/offline-config';\n\n/**\n * Temporary ids: a record created offline gets a client-made id (the `id` of the synthetic 202). Later saved changes may point at it (URL path\n * segment, query value, or a string value anywhere inside the JSON body). These helpers find those references and, at send time, swap them for the\n * server's real id. Matching is EXACT equality of a whole segment / value: a string that merely contains the temp id is never touched, and keys are\n * never touched. Nothing here mutates its input.\n */\n\n/** True when a JSON object body carries an `id` of its own (not null / undefined): the app chose the id, so nothing needs mapping. */\nexport function bodyHasOwnId(body: unknown): boolean {\n if (body === null || typeof body !== 'object' || Array.isArray(body)) return false;\n const id = (body as Record<string, unknown>)['id'];\n return id !== undefined && id !== null;\n}\n\n/** A POST to a collection (last path segment is not an id) whose body has no id of its own: the server will invent the id. */\nexport function isTempIdCreate(method: string, url: string, body: unknown): boolean {\n return method.toUpperCase() === 'POST' && !lastSegmentIsId(url) && !bodyHasOwnId(body);\n}\n\ninterface UrlParts { path: string; query: string | null; hash: string }\n\nfunction splitUrl(url: string): UrlParts {\n const h = url.indexOf('#');\n const hash = h >= 0 ? url.slice(h) : '';\n const noHash = h >= 0 ? url.slice(0, h) : url;\n const q = noHash.indexOf('?');\n return { path: q >= 0 ? noHash.slice(0, q) : noHash, query: q >= 0 ? noHash.slice(q + 1) : null, hash };\n}\n\nfunction decode(s: string): string {\n try { return decodeURIComponent(s); } catch { return s; }\n}\n\nfunction walkStrings(value: unknown, visit: (s: string) => void): void {\n if (typeof value === 'string') { visit(value); return; }\n if (Array.isArray(value)) { for (const v of value) walkStrings(v, visit); return; }\n if (value !== null && typeof value === 'object') { for (const v of Object.values(value as Record<string, unknown>)) walkStrings(v, visit); }\n}\n\n/** Every string that could be a reference: path segments, query values (decoded) and body string values. Keys are not included. */\nfunction referenceStrings(url: string, body: unknown): string[] {\n const out: string[] = [];\n const parts = splitUrl(url);\n for (const seg of parts.path.split('/')) if (seg !== '') out.push(decode(seg));\n if (parts.query !== null) {\n for (const pair of parts.query.split('&')) {\n const eq = pair.indexOf('=');\n if (eq >= 0) out.push(decode(pair.slice(eq + 1)));\n }\n }\n walkStrings(body, s => out.push(s));\n return out;\n}\n\n/** The candidate temp ids that the URL / body of a request refers to, each once, in order of first appearance. */\nexport function findTempIds(url: string, body: unknown, candidates: ReadonlySet<string> | ReadonlyMap<string, unknown>): string[] {\n const found: string[] = [];\n if (candidates.size === 0) return found;\n for (const s of referenceStrings(url, body)) {\n if (candidates.has(s) && !found.includes(s)) found.push(s);\n }\n return found;\n}\n\nfunction rewriteValue(value: unknown, map: ReadonlyMap<string, string | number>): unknown {\n if (typeof value === 'string') return map.has(value) ? map.get(value) : value;\n if (Array.isArray(value)) return value.map(v => rewriteValue(v, map));\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n // defineProperty so an own \"__proto__\" key from JSON.parse is kept as data instead of being swallowed by the prototype setter.\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n Object.defineProperty(out, k, { value: rewriteValue(v, map), enumerable: true, writable: true, configurable: true });\n }\n return out;\n }\n return value;\n}\n\n/**\n * The request as it must be sent now: every path segment / query value / body string value that EQUALS a temp id in `map` is replaced by the real id\n * (in the URL always as text, URL-encoded; in the body as given: a number stays a number). Returns new values; the inputs are not modified.\n */\nexport function rewriteTempIds(url: string, body: unknown, map: ReadonlyMap<string, string | number>): { url: string; body: unknown } {\n if (map.size === 0) return { url, body };\n const parts = splitUrl(url);\n const path = parts.path.split('/').map(seg => {\n const d = decode(seg);\n return map.has(d) ? encodeURIComponent(String(map.get(d))) : seg;\n }).join('/');\n let query = parts.query;\n if (query !== null) {\n query = query.split('&').map(pair => {\n const eq = pair.indexOf('=');\n if (eq < 0) return pair;\n const d = decode(pair.slice(eq + 1));\n return map.has(d) ? `${pair.slice(0, eq)}=${encodeURIComponent(String(map.get(d)))}` : pair;\n }).join('&');\n }\n return { url: path + (query !== null ? `?${query}` : '') + parts.hash, body: rewriteValue(body, map) };\n}\n","import { HttpClient, HttpErrorResponse } from '@angular/common/http';\nimport { Injectable, InjectionToken, inject, signal } from '@angular/core';\nimport { Subject, firstValueFrom } from 'rxjs';\nimport { ToastService, UiLabelsService } from '@forgeroute/ui';\nimport {\n IDEMPOTENCY_HEADER, IDEMPOTENCY_IN_PROGRESS_CODE, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, resolveConfig,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\nimport { isRequestTimeoutError } from '../http/errors';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { IdMapEntry, MutationError, MutationErrorKind, OfflineMutation, OfflineStore } from '../store/offline-store';\nimport { findTempIds, rewriteTempIds } from '../store/temp-ids';\n\nexport type ReplayTrigger = 'start' | 'online' | 'probe' | 'manual';\n\nexport interface ReplayResult {\n synced: number;\n failed: number;\n conflicts: number;\n blockedByAuth: boolean;\n}\n\n/** What \"Keep my version\" ended with: `sent` (delivered), `shortly` (still queued, goes out on its own) or `failed` (refused again / a new conflict). */\nexport type KeepMineOutcome = 'sent' | 'shortly' | 'failed';\n\nexport interface KeepMineRun {\n applied: boolean;\n result: ReplayResult | null;\n followUp: ReplayResult | null;\n /** null when nothing was applied. */\n outcome: KeepMineOutcome | null;\n}\n\n/** `navigator.locks`, or null when the browser has none (older Safari) - the replayer then falls back to an in-tab mutex plus a localStorage lease. */\nexport const OFFLINE_LOCK_MANAGER = new InjectionToken<LockManager | null>('OFFLINE_LOCK_MANAGER', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof navigator !== 'undefined' && navigator.locks && typeof navigator.locks.request === 'function' ? navigator.locks : null;\n } catch {\n return null;\n }\n },\n});\n\nexport type LeaseStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;\n\n/** Storage for the lock-less fallback lease: ONE small key holding `{ owner, until }`, never any data. */\nexport const OFFLINE_LEASE_STORAGE = new InjectionToken<LeaseStorage | null>('OFFLINE_LEASE_STORAGE', {\n providedIn: 'root',\n factory: () => {\n try {\n return typeof localStorage !== 'undefined' ? localStorage : null;\n } catch {\n return null;\n }\n },\n});\n\nexport const LEASE_TTL_MS = 30_000;\nconst LEASE_REFRESH_MS = 10_000;\nconst BACKOFF_BASE_MS = 2000;\nconst BACKOFF_CAP_MS = 5 * 60_000;\n\n/** Wait before the next automatic try after `attempts` failed sends: 2 s, 4 s, 8 s ... capped at 5 minutes. */\nexport function backoffMs(attempts: number): number {\n return Math.min(BACKOFF_BASE_MS * 2 ** Math.max(0, attempts - 1), BACKOFF_CAP_MS);\n}\n\ntype Outcome =\n | { action: 'ok'; text?: string }\n | { action: 'dependency' }\n | { action: 'conflict'; status: number }\n | { action: 'rejected'; status: number }\n | { action: 'auth'; status: number }\n | { action: 'retry'; kind: Extract<MutationErrorKind, 'server' | 'network' | 'timeout'>; status: number; retryAfterMs?: number };\n\n/** `Retry-After` in whole seconds -> ms; only 1..300 s are believed (HTTP dates, zero, negatives and junk are ignored, the normal back-off applies). */\nfunction retryAfterMs(err: HttpErrorResponse): number | undefined {\n const raw = err.headers?.get('Retry-After');\n if (raw === null || raw === undefined || !/^\\s*\\d+\\s*$/.test(raw)) return undefined;\n const seconds = Number(raw);\n return seconds >= 1 && seconds <= BACKOFF_CAP_MS / 1000 ? seconds * 1000 : undefined;\n}\n\n/** True when the 409's JSON body (an object, or the text of one: replays read answers as text) has `code` equal to the in-progress code. */\nfunction isInProgress409(err: HttpErrorResponse, code: string): boolean {\n let body: unknown = err.error;\n if (typeof body === 'string') { try { body = JSON.parse(body); } catch { return false; } }\n return !!body && typeof body === 'object' && (body as { code?: unknown }).code === code;\n}\n\n/**\n * Maps what a replayed request ended with to what happens to its row. Anything unknown stays retryable: only a real 4xx answer is final.\n * A 409 whose body `code` is `inProgressCode` (the same Idempotency-Key is still being processed) is transient: retry, honouring `Retry-After`.\n */\nexport function classifyReplay(err: unknown, inProgressCode: string = IDEMPOTENCY_IN_PROGRESS_CODE): Outcome {\n if (isRequestTimeoutError(err)) return { action: 'retry', kind: 'timeout', status: 0 };\n if (!(err instanceof HttpErrorResponse)) return { action: 'retry', kind: 'network', status: 0 };\n const s = err.status;\n if (s >= 200 && s < 300) return { action: 'ok' };\n if (s === 0) return { action: 'retry', kind: 'network', status: 0 };\n if (s === 401 || s === 403) return { action: 'auth', status: s };\n if (s === 409) {\n if (!isInProgress409(err, inProgressCode)) return { action: 'conflict', status: s };\n const wait = retryAfterMs(err);\n return wait === undefined ? { action: 'retry', kind: 'server', status: s } : { action: 'retry', kind: 'server', status: s, retryAfterMs: wait };\n }\n if (s === 408 || s === 429) return { action: 'retry', kind: 'server', status: s };\n if (s >= 400 && s < 500) return { action: 'rejected', status: s };\n return { action: 'retry', kind: 'server', status: s };\n}\n\n/**\n * Sends the signed-in user's saved changes, oldest first, when the connection is back. Safe by construction:\n * - one run at a time per browser (navigator.locks, or in-tab mutex + localStorage lease), and every row is `claim`ed atomically in IndexedDB;\n * - the row's own Idempotency-Key is re-sent unchanged, so even a crash after the server answered cannot create a second record;\n * - 401/403 never touch a row, a permanent 4xx marks the row failed (only the user's Retry sends it again), nothing is ever deleted except\n * after a 2xx or the user's own Discard.\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineReplayer {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly store = inject(OfflineStore);\n private readonly http = inject(HttpClient);\n private readonly connection = inject(ConnectionStateService);\n private readonly toast = inject(ToastService);\n private readonly labels = inject(UiLabelsService);\n private readonly locks = inject(OFFLINE_LOCK_MANAGER);\n private readonly leaseStorage = inject(OFFLINE_LEASE_STORAGE);\n\n private readonly owner = generateUuid();\n private running: Promise<ReplayResult | null> | null = null;\n\n private readonly _syncing = signal(false);\n private readonly _pendingCount = signal(0);\n private readonly _failedCount = signal(0);\n private readonly _conflictCount = signal(0);\n private readonly _lastSyncAt = signal<number | null>(null);\n private readonly _syncTick = signal(0);\n private readonly _authBlocked = signal(false);\n private readonly _lastResult = signal<ReplayResult | null>(null);\n\n readonly syncing = this._syncing.asReadonly();\n /** Rows waiting to be sent (pending + being sent right now). */\n readonly pendingCount = this._pendingCount.asReadonly();\n readonly failedCount = this._failedCount.asReadonly();\n readonly conflictCount = this._conflictCount.asReadonly();\n readonly lastSyncAt = this._lastSyncAt.asReadonly();\n /** Bumped when a run changed server data (a row was delivered): open pages refresh on it. */\n readonly syncTick = this._syncTick.asReadonly();\n /** True after a 401/403 stopped a run: the rows are safe and wait for the user to sign in again. */\n readonly authBlocked = this._authBlocked.asReadonly();\n readonly lastResult = this._lastResult.asReadonly();\n /** Emits at the end of every run that did something. */\n readonly runCompleted$ = new Subject<{ trigger: ReplayTrigger; result: ReplayResult; changed: boolean }>();\n\n /** Sends everything that is due. Concurrent calls in this tab share one run; another tab's run makes this resolve null. */\n replayAll(trigger: ReplayTrigger): Promise<ReplayResult | null> {\n if (this.running) return this.running;\n return this.start(() => this.run(trigger, null));\n }\n\n /** Puts one row (any status, conflict and failed included) back to pending with 0 attempts and sends only that row. */\n async retryOne(id: string): Promise<ReplayResult | null> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return null;\n // One atomic step in the store: a row another run is sending right now (live claim) is left alone.\n const reset = await this.store.resetForRetry(id, userId);\n if (!reset) return null;\n if (this.running) await this.running;\n return this.start(() => this.run('manual', id));\n }\n\n /**\n * \"Keep my version\" for one conflict row: strips the configured stamp fields from its body, gives it a new idempotency key, puts it back to pending\n * and sends ONLY that row first (same claim / lock / ordering rules as `retryOne`). When that overwrite was DELIVERED (2xx, row deleted) it then starts\n * one normal full run (`replayAll('online')`, the run a reconnect starts), so the later changes to the same record that were held behind the conflict\n * and any other due change go out right away. If the overwrite did not go through, nothing else is started and the later changes stay held.\n * `applied` is false when nothing was changed: the feature is off, nobody is signed in, or the row is missing, foreign, no longer a conflict, or has no stamp field (nothing to overwrite). The later still-pending rows of the same record keep their stamp until the overwrite is delivered; the run that delivers it removes it from them (`stripStampsAfter`). When the run could not start (another tab holds the lock) `result` is null and the row stays pending: the next normal run sends it.\n * `outcome` tells the user what happened (`sent` / `shortly` / `failed`, null when not applied). `result` is the overwrite's own run; `followUp` is the normal run that came after it (null when none was started).\n */\n async keepMineOne(id: string): Promise<KeepMineRun> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n const fields = this.cfg.conflictStampFields;\n if (!userId || fields.length === 0) return { applied: false, result: null, followUp: null, outcome: null };\n const reset = await this.store.resetForKeepMine(id, userId, fields, generateUuid());\n if (!reset) return { applied: false, result: null, followUp: null, outcome: null };\n if (this.running) await this.running;\n const result = await this.start(() => this.run('manual', id));\n const after = await this.store.get(id);\n let followUp: ReplayResult | null = null;\n // Delivered = this run synced a row and the row is gone. The single-row run has ended (its lock is released), so this is never a nested run.\n const delivered = !!result && result.synced > 0 && after === null;\n if (delivered) followUp = await this.replayAll('online');\n return { applied: true, result, followUp, outcome: this.keepMineOutcome(delivered, result, after) };\n }\n\n /** sent = delivered; shortly = it is still queued (no run could start because another tab holds the lock, still pending / being sent, or waiting out a retry); failed = refused again or a new conflict. */\n private keepMineOutcome(delivered: boolean, result: ReplayResult | null, after: OfflineMutation | null): KeepMineOutcome {\n if (delivered) return 'sent';\n // The row is gone though this run synced nothing: a full run that was already in flight (or another tab's run) delivered it first.\n if (!after) return 'sent';\n if (!result) return 'shortly';\n return after.status === 'pending' || after.status === 'syncing' ? 'shortly' : 'failed';\n }\n\n /** Deletes one row of the signed-in user (the user chose to discard it). Resolves `true` when this call found and deleted the row, `false` when it was already gone (e.g. delivered meanwhile) or is not the user's. When that row was a stuck (failed / conflict) one with later pending changes of the same record behind it, one normal drain follows so they go out. */\n async discard(id: string): Promise<boolean> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return false;\n const row = await this.store.get(id);\n if (!row || row.userId !== userId) return false;\n await this.store.delete(id);\n await this.refreshCounts();\n // A discarded failed / conflict row no longer holds back later changes to the same record: send them now (the normal drain a reconnect starts:\n // run lock, back-off and \"still offline\" are respected). Nothing behind it = nothing to do (one cheap read, no run). The drain is NOT awaited:\n // discard resolves as soon as the row is gone (the drawer announces it at once); `drainSettled()` tells when the drain is over.\n if ((row.status === 'failed' || row.status === 'conflict') && row.entityType && row.entityId) {\n // The row IS gone: nothing that goes wrong while looking for / starting the drain may make discard reject (the caller would skip its refresh).\n try {\n const behind = (await this.store.list(userId)).some(r => r.id !== id && r.status === 'pending' && r.entityType === row.entityType && r.entityId === row.entityId);\n if (behind) {\n const drain: Promise<void> = this.drainAfterDiscard()\n .catch(() => { /* a failed drain leaves the rows queued; the next run sends them */ })\n .finally(() => { this.discardDrains.delete(drain); });\n this.discardDrains.add(drain);\n }\n } catch { /* the held change goes out on the next trigger */ }\n }\n return true;\n }\n\n private readonly discardDrains = new Set<Promise<void>>();\n\n /** Resolves when EVERY drain started by a `discard` (also overlapping ones) has finished; immediately when none is running. Never rejects. */\n async drainSettled(): Promise<void> {\n while (this.discardDrains.size > 0) await Promise.all([...this.discardDrains]);\n }\n\n /**\n * `replayAll('online')` joins a run that is already in flight, but that run decided up front which records are blocked and never looks at the\n * discarded record again. So when a run was in flight (a full run, or a single-row retry / keep-my-version run), one FRESH run follows it.\n */\n private async drainAfterDiscard(): Promise<void> {\n const inFlight = this.running;\n await this.replayAll('online');\n if (inFlight) await this.replayAll('online');\n }\n\n /** Deletes all rows of the signed-in user (the user chose to discard everything). */\n async discardAll(): Promise<void> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId) return;\n await this.store.deleteMutations(userId);\n this._authBlocked.set(false);\n await this.refreshCounts();\n }\n\n /** Re-reads the counts for the signed-in user (zeros when nobody is signed in or storage is unavailable). */\n async refreshCounts(): Promise<void> {\n const userId = this.cfg.getUserId();\n if (!userId || !this.store.available()) {\n this._pendingCount.set(0); this._failedCount.set(0); this._conflictCount.set(0);\n return;\n }\n const c = await this.store.countsByStatus(userId);\n if (this.cfg.getUserId() !== userId) return;\n this._pendingCount.set(c.pending + c.syncing);\n this._failedCount.set(c.failed);\n this._conflictCount.set(c.conflict);\n }\n\n clearAuthBlocked(): void {\n this._authBlocked.set(false);\n }\n\n /** Another tab delivered rows: open pages in this tab must refresh too. */\n noteRemoteSync(): void {\n this._syncTick.update(n => n + 1);\n }\n\n /** Forgets everything about the previous user (counts, last result); the stored rows are not touched. */\n resetView(): void {\n this._pendingCount.set(0); this._failedCount.set(0); this._conflictCount.set(0);\n this._lastResult.set(null); this._authBlocked.set(false);\n }\n\n // ---- run -----------------------------------------------------------------------------------------------------------------------\n\n private start(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n const p = this.exclusive(job).finally(() => { if (this.running === p) this.running = null; });\n this.running = p;\n return p;\n }\n\n private async exclusive(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n const name = `forgeroute-offline-replay:${this.cfg.dbName}`;\n if (this.locks) {\n try {\n return await this.locks.request(name, { ifAvailable: true }, async lock => (lock ? job() : null)) as ReplayResult | null;\n } catch (e) {\n // Opaque origins / some embedded views refuse the Web Locks API: use the lease instead. Errors of the job itself are not swallowed.\n if (!(e instanceof DOMException) || (e.name !== 'SecurityError' && e.name !== 'NotSupportedError')) throw e;\n }\n }\n return this.withLease(job);\n }\n\n private leaseKey(): string {\n return `forgeroute-offline-lease:${this.cfg.dbName}`;\n }\n\n private readLease(): { owner?: string; until?: number } | null {\n try {\n const parsed = JSON.parse(this.leaseStorage?.getItem(this.leaseKey()) ?? 'null') as { owner?: string; until?: number } | null;\n return parsed && typeof parsed === 'object' ? parsed : null;\n } catch {\n return null; // a corrupt value counts as no lease\n }\n }\n\n private tryAcquireLease(): boolean {\n const storage = this.leaseStorage;\n if (!storage) return true; // no shared storage: the in-tab mutex above is all there is\n try {\n const now = Date.now();\n const current = this.readLease();\n if (current && current.owner !== this.owner && typeof current.until === 'number' && current.until > now) return false;\n storage.setItem(this.leaseKey(), JSON.stringify({ owner: this.owner, until: now + LEASE_TTL_MS }));\n return this.readLease()?.owner === this.owner;\n } catch {\n return true; // storage refuses writes (quota / privacy mode): run anyway, the row claims still prevent double sending\n }\n }\n\n private releaseLease(): void {\n const storage = this.leaseStorage;\n if (!storage) return;\n try {\n if (this.readLease()?.owner === this.owner) storage.removeItem(this.leaseKey());\n } catch { /* nothing to release */ }\n }\n\n private async withLease(job: () => Promise<ReplayResult | null>): Promise<ReplayResult | null> {\n if (!this.tryAcquireLease()) return null;\n const heartbeat = this.leaseStorage ? setInterval(() => this.tryAcquireLease(), LEASE_REFRESH_MS) : null;\n try {\n return await job();\n } finally {\n if (heartbeat) clearInterval(heartbeat);\n this.releaseLease();\n }\n }\n\n private async run(trigger: ReplayTrigger, onlyId: string | null): Promise<ReplayResult | null> {\n await this.store.init();\n const userId = this.cfg.getUserId();\n if (!userId || !this.store.available()) return null;\n if (trigger !== 'manual' && this.connection.isOffline()) return null;\n\n this._syncing.set(true);\n const result: ReplayResult = { synced: 0, failed: 0, conflicts: 0, blockedByAuth: false };\n let attempted = 0;\n let changed = false;\n try {\n const all = await this.store.list(userId);\n const rows = onlyId ? all.filter(r => r.id === onlyId) : all;\n // Temp ids: which create rows are still queued, and what the server already answered for finished ones.\n const idMap = new Map<string, IdMapEntry>();\n for (const e of await this.store.listIdMap(userId)) idMap.set(e.tempId, e);\n const createsByTemp = new Map<string, OfflineMutation>();\n for (const r of all) if (r.tempId) createsByTemp.set(r.tempId, r);\n const blocked = new Set<string>();\n const entityOf = (r: OfflineMutation) => (r.entityType && r.entityId ? `${r.entityType}::${r.entityId}` : null);\n if (!onlyId) {\n // An older change that is stuck (failed / conflict) holds back later changes to the same record: an older PUT must never overwrite a newer one.\n for (const r of rows) {\n const k = entityOf(r);\n if (k && (r.status === 'failed' || r.status === 'conflict')) blocked.add(k);\n }\n }\n for (const row of rows) {\n if (this.cfg.getUserId() !== userId) break; // the user switched mid-run: the rest belongs to somebody else's session\n const ek = entityOf(row);\n if (!onlyId) {\n if (row.status === 'failed' || row.status === 'conflict') continue;\n if (ek && blocked.has(ek)) continue;\n if (row.status === 'pending' && row.nextAttemptAt !== undefined && row.nextAttemptAt > Date.now() && trigger !== 'manual') {\n if (ek) blocked.add(ek);\n continue;\n }\n }\n // A change that points at a record created offline waits for that create (never sent while it is still queued), and is failed without\n // being sent when the create can no longer provide the real id.\n const dependency = await this.checkDependencies(row, userId, idMap, createsByTemp);\n if (dependency === 'hold') { if (ek) blocked.add(ek); continue; }\n const claimed = await this.store.claim(row.id, this.owner);\n if (!claimed) { if (ek) blocked.add(ek); continue; }\n if (this.cfg.getUserId() !== userId) {\n // The session changed while the claim was being made: never send this row under another user's token. Give the claim back.\n await this.store.update(claimed.id, { status: 'pending', claimOwner: undefined, claimAt: undefined }, { ifOwner: this.owner });\n break;\n }\n attempted++;\n const outcome: Outcome = dependency === 'fail' ? { action: 'dependency' } : await this.send(claimed, idMap);\n const stop = await this.apply(claimed, outcome, result, idMap);\n if (outcome.action === 'ok') {\n changed = true;\n // A delivered \"Keep my version\" overwrite: only now do the later edits of the same record lose their stale stamp (see resetForKeepMine).\n if (claimed.overwrite && claimed.entityType && claimed.entityId && this.cfg.conflictStampFields.length > 0) {\n // The overwrite is already delivered: a failing strip must not turn that into an error (the later rows keep their stamp and conflict at worst).\n try { await this.store.stripStampsAfter(userId, claimed.entityType, claimed.entityId, claimed.seq, this.cfg.conflictStampFields); } catch { /* keep going */ }\n }\n }\n if (outcome.action !== 'ok' && ek) blocked.add(ek);\n if (stop) break;\n }\n } finally {\n this._syncing.set(false);\n }\n await this.refreshCounts();\n if (result.synced > 0 && !result.blockedByAuth) this._authBlocked.set(false);\n if (attempted > 0) {\n this._lastResult.set(result);\n if (result.synced + result.failed + result.conflicts > 0) this._lastSyncAt.set(Date.now());\n }\n if (changed) this._syncTick.update(n => n + 1);\n this.announce(result);\n if (attempted > 0) this.runCompleted$.next({ trigger, result, changed });\n return result;\n }\n\n /**\n * 'hold': a create this change points at is still pending / being sent (or waiting out a backoff): do not send it yet.\n * 'fail': a create it points at failed / conflicted, was discarded, or answered without a readable id: it can never be sent correctly.\n * Reads the store fresh for every create that has no mapping yet, so a run in another tab that just finished the create is seen.\n */\n private async checkDependencies(\n row: OfflineMutation, userId: string, idMap: Map<string, IdMapEntry>, createsByTemp: ReadonlyMap<string, OfflineMutation>,\n ): Promise<'ok' | 'hold' | 'fail'> {\n const deps = new Map<string, string | undefined>(); // temp id -> create row id\n (row.dependsOn ?? []).forEach((rowId, i) => {\n const tempId = row.dependsOnTempIds?.[i] ?? [...createsByTemp.values()].find(c => c.id === rowId)?.tempId;\n deps.set(tempId ?? `\\u0000${rowId}`, rowId);\n });\n for (const t of findTempIds(row.url, row.body, createsByTemp)) {\n if (t !== row.tempId && !deps.has(t)) deps.set(t, createsByTemp.get(t)?.id);\n }\n let hold = false;\n for (const [tempId, creatorId] of deps) {\n if (idMap.has(tempId)) continue;\n let creator = creatorId ? await this.store.get(creatorId) : null;\n if (creator && creator.userId !== userId) creator = null;\n if (creator) {\n if (creator.status === 'pending' || creator.status === 'syncing') hold = true;\n else return 'fail';\n continue;\n }\n const late = await this.store.getIdMapping(userId, tempId);\n if (late) { idMap.set(tempId, late); continue; }\n return 'fail';\n }\n return hold ? 'hold' : 'ok';\n }\n\n private async send(row: OfflineMutation, idMap: ReadonlyMap<string, IdMapEntry>): Promise<Outcome> {\n try {\n const real = new Map<string, string | number>();\n for (const [tempId, e] of idMap) real.set(tempId, e.numeric && String(Number(e.realId)) === e.realId ? Number(e.realId) : e.realId);\n const target = rewriteTempIds(row.url, row.body, real);\n const response = await firstValueFrom(this.http.request(row.method, target.url, {\n body: target.body,\n headers: { ...(row.headers ?? {}), [IDEMPOTENCY_HEADER]: row.key, [OFFLINE_REPLAY_HEADER]: '1' },\n observe: 'response',\n responseType: 'text',\n }));\n return { action: 'ok', text: typeof response.body === 'string' ? response.body : undefined };\n } catch (err) {\n return classifyReplay(err, this.cfg.idempotencyInProgressCode);\n }\n }\n\n /** Stores the outcome on the row (only while we still own the claim). Returns true when the run must stop. */\n private async apply(row: OfflineMutation, outcome: Outcome, result: ReplayResult, idMap: Map<string, IdMapEntry>): Promise<boolean> {\n const owner = { ifOwner: this.owner };\n const release = { claimOwner: undefined, claimAt: undefined };\n const err = (kind: MutationErrorKind, status: number | undefined, key: Parameters<UiLabelsService['t']>[0]): MutationError =>\n ({ kind, ...(status !== undefined ? { status } : {}), message: this.labels.t(key) });\n\n switch (outcome.action) {\n case 'ok':\n try {\n // Order matters: the mapping is saved BEFORE the create row is deleted. If this tab dies in between, the create is replayed with the same\n // Idempotency-Key (same answer, same real id) and the mapping is simply written again.\n if (row.tempId) {\n const real = this.readCreatedId(row, outcome.text);\n if (real !== undefined) idMap.set(row.tempId, await this.store.putIdMapping(row.userId, row.tempId, real));\n }\n await this.store.delete(row.id, owner);\n } catch {\n // Storage trouble after the server accepted it: give the row back (it is replayed safely with the same key) and stop this run.\n await this.store.update(row.id, { status: 'pending', ...release }, owner).catch(() => null);\n return true;\n }\n result.synced++;\n this._authBlocked.set(false);\n return false;\n case 'dependency':\n // Never sent: the id it points at is unknown. attempts is not counted; only the user's Retry (once the create is healthy) sends it.\n await this.store.update(row.id, { status: 'failed', ...release, nextAttemptAt: undefined, lastError: err('dependency', undefined, 'connection.error.dependency') }, owner);\n result.failed++;\n return false;\n case 'conflict':\n await this.store.update(row.id, { status: 'conflict', ...release, attempts: row.attempts + 1, lastError: err('conflict', outcome.status, 'connection.error.conflict') }, owner);\n result.conflicts++;\n return false;\n case 'rejected':\n await this.store.update(row.id, { status: 'failed', ...release, attempts: row.attempts + 1, lastError: err('rejected', outcome.status, 'connection.error.rejected') }, owner);\n result.failed++;\n return false;\n case 'auth':\n // The token is stale or the permission is gone: nothing is wrong with the data. Keep the row exactly as it was and stop.\n await this.store.update(row.id, { status: 'pending', ...release, lastError: err('auth', outcome.status, 'connection.authBlocked') }, owner);\n this._authBlocked.set(true);\n result.blockedByAuth = true;\n return true;\n case 'retry': {\n const message = outcome.kind === 'network' ? 'connection.error.network' : outcome.kind === 'timeout' ? 'connection.error.timeout' : 'connection.error.server';\n const lastError = err(outcome.kind, outcome.status || undefined, message);\n const stillOffline = outcome.status === 0 && this.connection.isOffline();\n if (stillOffline) {\n await this.store.update(row.id, { status: 'pending', ...release, lastError }, owner);\n return true;\n }\n const attempts = row.attempts + 1;\n if (attempts >= this.cfg.maxAttempts) {\n await this.store.update(row.id, { status: 'failed', ...release, attempts, nextAttemptAt: undefined, lastError }, owner);\n result.failed++;\n } else {\n await this.store.update(row.id, { status: 'pending', ...release, attempts, nextAttemptAt: Date.now() + (outcome.retryAfterMs ?? backoffMs(attempts)), lastError }, owner);\n }\n return outcome.kind !== 'server'; // no answer at all: still offline, stop; a 5xx / 429 only holds back this record\n }\n }\n }\n\n /** The server's id for a created record: the answer text parsed as JSON (undefined when empty / not JSON) run through `config.createdId`. */\n private readCreatedId(row: OfflineMutation, text: string | undefined): string | number | undefined {\n let body: unknown;\n try { body = text ? JSON.parse(text) : undefined; } catch { body = undefined; }\n return this.cfg.createdId(body, row);\n }\n\n private announce(result: ReplayResult): void {\n const attention = result.failed + result.conflicts;\n if (attention > 0) this.toast.warning(this.labels.t(attention === 1 ? 'connection.needAttention.one' : 'connection.needAttention.other', { count: attention }));\n else if (result.synced > 0 && !result.blockedByAuth) this.toast.success(this.labels.t('connection.synced'));\n }\n}\n","import { HttpContextToken } from '@angular/common/http';\n\n/**\n * Per-request client timeout in ms, set through `HttpContext`: `http.get(url, { context: new HttpContext().set(REQUEST_TIMEOUT_MS, 120000) })`.\n * `null` (default) = the configured read / write / long timeout. A value of 0 or less switches the timeout off for that request.\n */\nexport const REQUEST_TIMEOUT_MS = new HttpContextToken<number | null>(() => null);\n\n/**\n * Marks ONE request as long-running, whatever its URL: `http.get('/api/x?size=10000', { context: new HttpContext().set(REQUEST_LONG, true) })`.\n * Same effect as a `longRequests` match, a blob download or an upload: it uses the long timeout (unless `REQUEST_TIMEOUT_MS` overrides it), is not\n * counted in the slow-answer rule, never arms the \"stuck\" timer (so no \"Slow connection\" banner) and a failed read is not retried automatically.\n * `longRequests` matches the URL WITHOUT its query string, so a request that is long only because of its parameters (a table Export asking for\n * 10,000 rows) needs this token, set by the host app in an HTTP interceptor placed BEFORE the offline interceptors.\n */\nexport const REQUEST_LONG = new HttpContextToken<boolean>(() => false);\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport {\n IDEMPOTENCY_HEADER, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, isInScope, isMutationMethod, resolveConfigCached,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\n\n/**\n * Gives every write under `apiPrefix` an `Idempotency-Key: <uuid>` unless the caller already set one (callers that must keep ONE key across\n * user retries set it themselves). The same key goes on the queued row and on every replay, so the server can recognise a repeat.\n * Left alone: reads, skipped URLs, FormData bodies, and replays (`X-Offline-Replay`, which already carry the row's key).\n */\nexport const idempotencyInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (!isMutationMethod(req.method)) return next(req);\n if (req.headers.has(OFFLINE_REPLAY_HEADER)) return next(req);\n if (!isInScope(req.url, cfg)) return next(req);\n if (typeof FormData !== 'undefined' && req.body instanceof FormData) return next(req);\n if (req.headers.has(IDEMPOTENCY_HEADER)) return next(req);\n return next(req.clone({ setHeaders: { [IDEMPOTENCY_HEADER]: generateUuid() } }));\n};\n","import { HttpErrorResponse, HttpEvent, HttpInterceptorFn, HttpResponse } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { Observable, defer, throwError, timer } from 'rxjs';\nimport { finalize, retry, tap, timeout } from 'rxjs/operators';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport {\n OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG, isInScope, matchesAny, resolveConfigCached,\n} from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { RequestTimeoutError, isRequestTimeoutError } from './errors';\nimport { REQUEST_LONG, REQUEST_TIMEOUT_MS } from './request-timeout';\n\n/** Pause before the single automatic retry of a read that failed without an answer. */\nexport const READ_RETRY_DELAY_MS = 1000;\n\nexport function isNetworkFailure(err: unknown): boolean {\n return isRequestTimeoutError(err) || (err instanceof HttpErrorResponse && err.status === 0);\n}\n\n/**\n * Measures every API request (feeds ConnectionStateService), applies the client timeout and retries a failed READ once.\n * A write is never retried here: after a timeout or status 0 its outcome is unknown, so the user decides (the same Idempotency-Key makes\n * a retry safe). Sits closest to the network so the offline interceptor sees timeouts and failures as errors.\n */\nexport const connectionInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (!isInScope(req.url, cfg)) return next(req);\n\n const connection = inject(ConnectionStateService);\n const labels = inject(UiLabelsService);\n const method = req.method.toUpperCase();\n const isRead = method === 'GET' || method === 'HEAD' || method === 'OPTIONS';\n const long = req.responseType === 'blob' || req.responseType === 'arraybuffer' || req.reportProgress\n || (typeof FormData !== 'undefined' && req.body instanceof FormData) || matchesAny(req.url, cfg.longRequests) || req.context.get(REQUEST_LONG) === true;\n const override = req.context.get(REQUEST_TIMEOUT_MS);\n const timeoutMs = override !== null && override !== undefined ? override : long ? cfg.timeouts.long : isRead ? cfg.timeouts.read : cfg.timeouts.write;\n // The marker only exists for the interceptors in front of this one; the network does not need to hear about it.\n const outgoing = req.headers.has(OFFLINE_REPLAY_HEADER) ? req.clone({ headers: req.headers.delete(OFFLINE_REPLAY_HEADER) }) : req;\n\n const attempt = (): Observable<HttpEvent<unknown>> => defer(() => {\n const end = connection.beginRequest({ long });\n const started = Date.now();\n let outcome: { status: number; ok: boolean; timedOut: boolean } | null = null;\n let stream: Observable<HttpEvent<unknown>> = next(outgoing);\n if (timeoutMs > 0) {\n stream = stream.pipe(timeout({\n each: timeoutMs,\n with: () => throwError(() => new RequestTimeoutError(labels.t(isRead ? 'connection.timeout.read' : 'connection.timeout.write'), method, req.urlWithParams, !isRead)),\n }));\n }\n return stream.pipe(\n tap({\n next: ev => { if (ev instanceof HttpResponse) outcome = { status: ev.status, ok: ev.ok, timedOut: false }; },\n error: err => {\n if (isRequestTimeoutError(err)) outcome = { status: 0, ok: false, timedOut: true };\n else if (err instanceof HttpErrorResponse) outcome = { status: err.status, ok: false, timedOut: false };\n },\n }),\n finalize(() => {\n end();\n if (outcome) {\n connection.recordRequest({\n durationMs: Math.max(0, Date.now() - started), ok: outcome.ok, status: outcome.status, timedOut: outcome.timedOut, method, long,\n });\n }\n }),\n );\n });\n\n if (!isRead || long) return attempt();\n return attempt().pipe(retry({\n count: 1,\n delay: err => (isNetworkFailure(err) && connection.state() !== 'offline' ? timer(READ_RETRY_DELAY_MS) : throwError(() => err)),\n }));\n};\n","import { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Injectable, inject, signal } from '@angular/core';\nimport { ToastService, UiLabelsService } from '@forgeroute/ui';\nimport { OFFLINE_SUPPORT_CONFIG, hasStampField, resolveConfig } from '../config/offline-config';\nimport { KeepMineOutcome, OfflineReplayer, ReplayResult, ReplayTrigger } from '../replay/offline-replayer';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { StaleDataService } from '../state/stale-data.service';\nimport { OfflineMutation, OfflineStore } from '../store/offline-store';\n\n/** What tabs tell each other: `changed` = the saved changes changed (re-read them), `synced` = rows were delivered (refresh open pages). */\nexport type CrossTabMessage = { type: 'changed' } | { type: 'synced' };\n\n/** Creates the cross-tab channel; null when the browser has no BroadcastChannel (the focus / visibility poll still keeps tabs in step). */\nexport function createChannel(name: string): BroadcastChannel | null {\n try {\n return typeof BroadcastChannel === 'function' ? new BroadcastChannel(name) : null;\n } catch {\n return null;\n }\n}\n\n/** `keepMine` was refused: `disabled` = `conflictStampFields` is empty, `notFound` = no such row for the signed-in user, `notConflict` = the row is not in status conflict, `noStamp` = its body has none of the configured stamp fields (nothing to overwrite). */\nexport class KeepMineError extends Error {\n constructor(readonly reason: 'disabled' | 'notFound' | 'notConflict' | 'noStamp', message: string) {\n super(message);\n this.name = 'KeepMineError';\n Object.setPrototypeOf(this, KeepMineError.prototype);\n }\n}\n\n/**\n * What the app talks to: counts, the list for the pending-changes drawer, Sync now / Retry / Discard, and the session helpers.\n * Everything is scoped to `config.getUserId()`; nothing here ever deletes saved changes unless the user chose it\n * (`discard`, `discardAll`, `endSession({ discardPending: true })` after the app asked the user).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineSupportService {\n private readonly cfg = resolveConfig(inject(OFFLINE_SUPPORT_CONFIG, { optional: true }) ?? { getUserId: () => null });\n private readonly store = inject(OfflineStore);\n private readonly replayer = inject(OfflineReplayer);\n private readonly connection = inject(ConnectionStateService);\n private readonly stale = inject(StaleDataService);\n private readonly toast = inject(ToastService);\n private readonly labels = inject(UiLabelsService);\n private readonly doc = inject(DOCUMENT);\n private readonly destroyRef = inject(DestroyRef);\n\n private readonly _rows = signal<readonly OfflineMutation[]>([]);\n private readonly _lastQueued = signal<{ label: string; at: number } | null>(null);\n private readonly _storageAvailable = signal(true);\n\n readonly pendingCount = this.replayer.pendingCount;\n readonly failedCount = this.replayer.failedCount;\n readonly conflictCount = this.replayer.conflictCount;\n readonly syncing = this.replayer.syncing;\n readonly lastSyncAt = this.replayer.lastSyncAt;\n readonly syncTick = this.replayer.syncTick;\n readonly authBlocked = this.replayer.authBlocked;\n readonly lastResult = this.replayer.lastResult;\n /** The signed-in user's saved changes, oldest first, for the drawer. Updates when another tab changes them. */\n readonly rows = this._rows.asReadonly();\n /** The most recent change saved on this device while offline ({ label, at }). */\n readonly lastQueued = this._lastQueued.asReadonly();\n /** False when IndexedDB could not be opened on this device (set after the store initialised): the drawer then must not say \"all synced\". */\n readonly storageAvailable = this._storageAvailable.asReadonly();\n\n private started = false;\n private channel: BroadcastChannel | null = null;\n private refreshing: Promise<void> | null = null;\n private dirty = false;\n private lastKnownUserId: string | null = null;\n private cleanups: (() => void)[] = [];\n private retryTimer: ReturnType<typeof setTimeout> | null = null;\n private destroyed = false;\n\n /** Wires the triggers (called by `provideOfflineSupport`'s initializer; calling it again does nothing). Resolves when the first read is done. */\n async start(): Promise<void> {\n if (this.started) return;\n this.started = true;\n await this.store.init();\n this._storageAvailable.set(this.store.available());\n\n this.channel = createChannel(`forgeroute-offline:${this.cfg.dbName}`);\n if (this.channel) {\n const channel = this.channel;\n channel.onmessage = ev => this.onRemote(ev.data as CrossTabMessage);\n this.cleanups.push(() => { channel.onmessage = null; channel.close(); });\n }\n const win = this.doc.defaultView;\n if (win) {\n const poll = () => { if (this.doc.visibilityState !== 'hidden') void this.refresh(); };\n win.addEventListener('focus', poll);\n this.doc.addEventListener('visibilitychange', poll);\n this.cleanups.push(() => { win.removeEventListener('focus', poll); this.doc.removeEventListener('visibilitychange', poll); });\n }\n const subs = [\n this.connection.recovered$.subscribe(trigger => this.replay(trigger)),\n this.store.mutated$.subscribe(() => { void this.refresh(); this.post({ type: 'changed' }); }),\n this.replayer.runCompleted$.subscribe(({ changed }) => { if (changed) this.post({ type: 'synced' }); }),\n // A run that ended with rows still waiting out a backoff must schedule their next try (nothing else would).\n this.replayer.runCompleted$.subscribe(() => { void this.refresh(); }),\n ];\n this.cleanups.push(() => subs.forEach(s => s.unsubscribe()));\n this.destroyRef.onDestroy(() => {\n this.destroyed = true;\n this.clearRetryTimer();\n this.cleanups.forEach(c => c()); this.cleanups = []; this.channel = null;\n });\n\n await this.refresh();\n if (this.connection.isOnline() && this.cfg.getUserId()) this.replay('start');\n }\n\n /** Starts a replay run without ever leaving an unhandled rejection behind. */\n private replay(trigger: ReplayTrigger): void {\n void this.replayer.replayAll(trigger).catch(() => undefined);\n }\n\n private clearRetryTimer(): void {\n if (this.retryTimer) { clearTimeout(this.retryTimer); this.retryTimer = null; }\n }\n\n /**\n * Rows that failed with a transient error wait for `nextAttemptAt`. Nothing else triggers a run while the connection stays `online`, so a timer\n * fires one replay when the earliest of them is due.\n */\n private scheduleRetry(): void {\n this.clearRetryTimer();\n if (this.destroyed) return;\n let earliest: number | null = null;\n for (const r of this._rows()) {\n if (r.status === 'pending' && r.nextAttemptAt !== undefined && (earliest === null || r.nextAttemptAt < earliest)) earliest = r.nextAttemptAt;\n }\n if (earliest === null) return;\n this.retryTimer = setTimeout(() => {\n this.retryTimer = null;\n // While offline (or signed out) nothing is sent; the recovery trigger replays everything that is due once the connection is back.\n if (this.cfg.getUserId() && this.connection.isOnline()) this.replay('online');\n }, Math.max(0, earliest - Date.now()) + 50);\n }\n\n private post(msg: CrossTabMessage): void {\n try { this.channel?.postMessage(msg); } catch { /* channel closed */ }\n }\n\n private onRemote(msg: CrossTabMessage | null): void {\n if (!msg) return;\n if (msg.type === 'synced') this.replayer.noteRemoteSync();\n void this.refresh();\n }\n\n /** Called by the offline interceptor after a write was saved on the device. */\n onQueued(row: OfflineMutation): void {\n this.lastKnownUserId = row.userId;\n this._lastQueued.set({ label: row.label, at: Date.now() });\n this.toast.info(this.labels.t('connection.savedOnDevice'));\n void this.refresh();\n }\n\n /** Re-reads the rows and counts. Calls that overlap are merged into one extra read. */\n refresh(): Promise<void> {\n if (this.refreshing) { this.dirty = true; return this.refreshing; }\n const p = this.doRefresh().finally(() => { this.refreshing = null; });\n this.refreshing = p;\n return p;\n }\n\n private async doRefresh(): Promise<void> {\n do {\n this.dirty = false;\n const userId = this.cfg.getUserId();\n if (!userId) {\n this._rows.set([]);\n } else {\n this.lastKnownUserId = userId;\n await this.store.init();\n const rows = await this.store.list(userId);\n if (this.cfg.getUserId() !== userId) { this.dirty = true; continue; }\n this._rows.set(rows);\n }\n await this.replayer.refreshCounts();\n } while (this.dirty);\n this.scheduleRetry();\n }\n\n /** \"Sync now\": sends everything due, even rows waiting out a backoff. */\n async syncNow(): Promise<ReplayResult | null> {\n const result = await this.replayer.replayAll('manual');\n await this.refresh();\n return result;\n }\n\n async retry(id: string): Promise<void> {\n await this.replayer.retryOne(id);\n await this.refresh();\n }\n\n /** True when \"Keep my version\" can be offered for this row: the feature is on (`conflictStampFields` not empty), the row is a conflict, and its body has at least one stamp field. */\n canKeepMine(row: OfflineMutation): boolean {\n return this.cfg.conflictStampFields.length > 0 && row.status === 'conflict' && hasStampField(row.body, this.cfg.conflictStampFields);\n }\n\n /**\n * The user chose \"Keep my version\" for a conflict row: the stamp fields are removed from its body, it gets a new idempotency key, goes back to pending and\n * only that row is sent first and, once it is delivered, one normal sync follows (later changes to the same record and other due changes go out). Last write wins here, by the user's explicit choice (the server can no longer detect a newer edit, so no second 409 for the stamp).\n * Resolves with what happened: `sent` (delivered), `shortly` (still queued: another tab holds the sync lock, or it waits for a retry) or `failed` (refused again or a new conflict; the change stays saved on the device).\n * Throws `KeepMineError` when the feature is off, the row does not exist, it is not in status `conflict`, or its body has no stamp field (`noStamp`; same rule as `canKeepMine`).\n */\n async keepMine(id: string): Promise<KeepMineOutcome> {\n if (this.cfg.conflictStampFields.length === 0) throw new KeepMineError('disabled', this.labels.t('connection.conflict.error.disabled'));\n const userId = this.cfg.getUserId();\n await this.store.init();\n const row = userId ? await this.store.get(id) : null;\n if (!row || row.userId !== userId) throw new KeepMineError('notFound', this.labels.t('connection.conflict.error.notFound'));\n if (row.status !== 'conflict') throw new KeepMineError('notConflict', this.labels.t('connection.conflict.error.notConflict'));\n if (!hasStampField(row.body, this.cfg.conflictStampFields)) throw new KeepMineError('noStamp', this.labels.t('connection.conflict.error.noStamp'));\n const { applied, outcome } = await this.replayer.keepMineOne(id);\n await this.refresh();\n if (!applied || !outcome) throw new KeepMineError('notConflict', this.labels.t('connection.conflict.error.notConflict'));\n return outcome;\n }\n\n /** Rows the USER discarded (id -> when), set before the row is deleted so a reader that sees the row leave can tell a discard from a delivery. */\n private readonly discardedIds = new Map<string, number>();\n\n /** A discard mark only matters while its row leaves the list; it expires after this many ms (and the map is emptied when it grows past 500). */\n private static readonly DISCARD_MARK_MS = 60_000;\n\n /** True when the row with this id left the list because the user discarded it (not because it was delivered). */\n wasDiscarded(id: string): boolean {\n const at = this.discardedIds.get(id);\n if (at === undefined) return false;\n if (Date.now() - at > OfflineSupportService.DISCARD_MARK_MS) { this.discardedIds.delete(id); return false; }\n return true;\n }\n\n private markDiscarded(ids: string[]): void {\n if (this.discardedIds.size > 500) this.discardedIds.clear();\n const now = Date.now();\n for (const id of ids) this.discardedIds.set(id, now);\n }\n\n async discard(id: string): Promise<void> {\n // Only a row that really exists (and is this user's) can be discarded; a row that is already gone (delivered meanwhile) gets no mark.\n const userId = this.cfg.getUserId();\n const existing = userId ? await this.store.get(id) : undefined;\n if (!existing || existing.userId !== userId) { await this.replayer.discard(id); await this.refresh(); return; }\n this.markDiscarded([id]);\n try {\n // The row can be delivered between the check above and the delete: then nothing was discarded and the mark must not stay.\n if (!(await this.replayer.discard(id))) this.discardedIds.delete(id);\n } catch (e) { this.discardedIds.delete(id); throw e; }\n await this.refresh();\n }\n\n async discardAll(): Promise<void> {\n const userId = this.cfg.getUserId();\n const ids = userId ? (await this.store.list(userId)).map(r => r.id) : [];\n this.markDiscarded(ids);\n try { await this.replayer.discardAll(); } catch (e) { for (const id of ids) this.discardedIds.delete(id); throw e; }\n await this.refresh();\n }\n\n // ---- session helpers -----------------------------------------------------------------------------------------------------------\n\n /**\n * Call in logout BEFORE signing out. `pending` = changes not yet delivered (waiting or being sent), `failed` = changes that need attention\n * (failed or conflict). When `pending + failed > 0` show a ConfirmService dialog with `connection.logoutPending.one` / `connection.logoutPending.other`; then call\n * `endSession({ discardPending })` with the user's choice. Nothing is deleted here.\n */\n async beforeSessionEnd(): Promise<{ pending: number; failed: number }> {\n const userId = this.cfg.getUserId() ?? this.lastKnownUserId;\n if (!userId) return { pending: 0, failed: 0 };\n await this.store.init();\n if (!this.store.available()) return { pending: 0, failed: 0 };\n const c = await this.store.countsByStatus(userId);\n return { pending: c.pending + c.syncing, failed: c.failed + c.conflict };\n }\n\n /** The signed-in user changed (sign-in, switch): re-scope the view to them and send what they have waiting. */\n async onSessionStart(userId: string): Promise<void> {\n this.lastKnownUserId = userId;\n this.replayer.resetView();\n this._lastQueued.set(null);\n this.stale.clear();\n await this.refresh();\n if (this.cfg.getUserId() === userId) this.replay('start');\n }\n\n /**\n * Called by the offline interceptor for every in-scope request: when the signed-in user is not the one the view was built for (the app never\n * called `onSessionStart`), forget the previous user's rows and counts and re-read for the new one.\n */\n ensureScope(): void {\n const current = this.cfg.getUserId();\n if (current === this.lastKnownUserId) return;\n if (this.lastKnownUserId === null) {\n // First sight of a user: nothing from a previous user can be on screen yet, so only read their rows.\n this.lastKnownUserId = current;\n void this.refresh();\n return;\n }\n this.replayer.resetView();\n this._rows.set([]);\n this._lastQueued.set(null);\n this.stale.clear();\n this.lastKnownUserId = current;\n void this.refresh();\n }\n\n /**\n * The user signed out. By default NOTHING is deleted: the saved changes and the device copy stay for that user and are sent when they sign in again.\n * Only `discardPending: true` (the app asked the user first) deletes that one user's changes and device copy. Other users' data is never touched.\n * `userId` names the user who is leaving; pass it when the app already switched to somebody else (impersonation, portal logout), otherwise the\n * user the view was last built for is used.\n */\n async endSession(options: { discardPending: boolean; userId?: string }): Promise<void> {\n const userId = options.userId ?? this.lastKnownUserId ?? this.cfg.getUserId();\n if (options.discardPending && userId) await this.store.clearUser(userId);\n this._rows.set([]);\n this._lastQueued.set(null);\n this.replayer.resetView();\n this.stale.clear();\n }\n\n /**\n * Empties the device copy of every user's GET answers and the in-memory view. Saved changes are kept unless `discardPending` is true, which wipes\n * them for EVERY user: only for a deliberate full reset the user confirmed, never at logout.\n */\n async clearAll(options: { discardPending?: boolean } = {}): Promise<void> {\n if (options.discardPending) await this.store.clearAll();\n else await this.store.clearCache();\n this._rows.set([]);\n this._lastQueued.set(null);\n this.replayer.resetView();\n this.stale.clear();\n }\n}\n","import { HttpErrorResponse, HttpEvent, HttpHeaders, HttpInterceptorFn, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http';\nimport { Injector, inject, isDevMode } from '@angular/core';\nimport { Observable, from, of, throwError } from 'rxjs';\nimport { catchError, switchMap, tap } from 'rxjs/operators';\nimport { UiLabelsService, uiText } from '@forgeroute/ui';\nimport {\n DEFAULT_DETAIL_TTL_MS, DEFAULT_LIST_TTL_MS, FROM_CACHE_HEADER, IDEMPOTENCY_HEADER, OFFLINE_REPLAY_HEADER, OFFLINE_SUPPORT_CONFIG,\n QueueRule, ResolvedOfflineConfig, deriveEntity, invalidationPrefix, isInScope, isMutationMethod, lastSegmentIsId, matchesAny, matchesUrl,\n pathAndQuery, pathOnly, resolveConfigCached,\n} from '../config/offline-config';\nimport { generateUuid } from '../config/uuid';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { StaleDataService } from '../state/stale-data.service';\nimport { OfflineMutation, OfflineStore } from '../store/offline-store';\nimport { findTempIds, isTempIdCreate } from '../store/temp-ids';\nimport { OfflineSupportService } from '../support/offline-support.service';\nimport { OfflineBlockedError } from './errors';\nimport { isNetworkFailure } from './connection.interceptor';\n\nconst FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded;charset=UTF-8';\n\n/** Header names that must never be copied onto a queued row, whatever `replayHeaders` says: the live token is attached at replay time. */\nconst NEVER_STORED_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];\n\nfunction isUploadBody(body: unknown): boolean {\n return (typeof FormData !== 'undefined' && body instanceof FormData)\n || (typeof Blob !== 'undefined' && body instanceof Blob)\n || body instanceof ArrayBuffer\n || ArrayBuffer.isView(body);\n}\n\nfunction isFormBody(body: unknown): body is HttpParams | URLSearchParams {\n return body instanceof HttpParams || (typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams);\n}\n\n/** A structured-clone-safe copy of the JSON body (undefined values dropped), or `undefined` when it cannot be stored. */\nfunction storableBody(body: unknown): { ok: true; value: unknown } | { ok: false } {\n if (body === null || body === undefined) return { ok: true, value: null };\n if (isFormBody(body)) return { ok: true, value: body.toString() };\n if (typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean') return { ok: true, value: body };\n try {\n return { ok: true, value: JSON.parse(JSON.stringify(body)) };\n } catch {\n return { ok: false };\n }\n}\n\n/**\n * The label a queued change gets when no rule writes one: \"Add lots\" / \"Update lots\" / \"Delete lots\" (the entity is the URL's own word, \"item\" when the\n * URL has none). It is written in the language active when the change is queued and saved on the row as such - a row stored before a language\n * switch keeps its old wording.\n */\nfunction defaultLabel(labels: UiLabelsService, method: string, url: string): string {\n const key = method === 'POST' ? 'connection.defaultLabel.add' : method === 'DELETE' ? 'connection.defaultLabel.delete' : 'connection.defaultLabel.update';\n const segments = pathOnly(url).split('/').filter(Boolean);\n const entity = deriveEntity(url).entityType ?? segments[segments.length - 1] ?? labels.t('connection.entityFallback');\n return labels.t(key, { entity });\n}\n\nfunction findRule(rules: readonly QueueRule[], req: HttpRequest<unknown>): QueueRule | undefined {\n const target = pathAndQuery(req.urlWithParams);\n const method = req.method.toUpperCase();\n return rules.find(r => {\n r.pattern.lastIndex = 0;\n const hit = r.pattern.test(target);\n r.pattern.lastIndex = 0;\n return hit && r.methods.some(m => m.toUpperCase() === method);\n });\n}\n\nfunction safeHeaders(req: HttpRequest<unknown>, cfg: ResolvedOfflineConfig, formBody: boolean): Record<string, string> | undefined {\n const out: Record<string, string> = {};\n const contentType = req.headers.get('Content-Type');\n if (contentType && !/^application\\/json/i.test(contentType)) out['Content-Type'] = contentType;\n else if (formBody) out['Content-Type'] = FORM_CONTENT_TYPE;\n for (const name of cfg.replayHeaders) {\n if (NEVER_STORED_HEADERS.includes(name.toLowerCase())) continue;\n const value = req.headers.get(name);\n if (value !== null) out[name] = value;\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\n/**\n * Reads: network first; the answer is also stored (per user) unless excluded; while offline/unreachable, or when the request fails with no\n * answer, the stored copy is served (header `X-From-Offline-Cache: <cachedAt>`, StaleDataService told) and otherwise the error is rethrown.\n * Writes while offline/unreachable: blocked (OfflineBlockedError) or saved on the device with the request's Idempotency-Key and answered with a\n * typed synthetic 202. Writes while online pass through; a write with an unknown outcome (timeout / status 0 while the browser is online) is\n * never queued automatically.\n */\nexport const offlineInterceptor: HttpInterceptorFn = (req, next) => {\n const raw = inject(OFFLINE_SUPPORT_CONFIG, { optional: true });\n if (!raw) return next(req);\n const cfg = resolveConfigCached(raw);\n if (req.headers.has(OFFLINE_REPLAY_HEADER) || !isInScope(req.url, cfg)) return next(req);\n // A changed signed-in user must not keep showing the previous user's saved changes: re-scope the view (cheap no-op when unchanged).\n inject(OfflineSupportService).ensureScope();\n if (req.method === 'GET') return handleRead(req, next, cfg);\n if (isMutationMethod(req.method)) return handleWrite(req, next, cfg);\n return next(req);\n};\n\nfunction cachedResponse(req: HttpRequest<unknown>, data: unknown, cachedAt: number): HttpResponse<unknown> {\n return new HttpResponse({\n body: data, status: 200, statusText: 'OK', url: req.urlWithParams,\n headers: new HttpHeaders({ [FROM_CACHE_HEADER]: String(cachedAt) }),\n });\n}\n\nfunction handleRead(req: HttpRequest<unknown>, next: (r: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>, cfg: ResolvedOfflineConfig): Observable<HttpEvent<unknown>> {\n const userId = cfg.getUserId();\n if (userId === null || req.responseType !== 'json' || matchesAny(req.url, cfg.neverCache)) return next(req);\n\n const connection = inject(ConnectionStateService);\n const store = inject(OfflineStore);\n const stale = inject(StaleDataService);\n const key = pathAndQuery(req.urlWithParams);\n const ttl = cfg.cacheTtl ? cfg.cacheTtl(req.url) : lastSegmentIsId(req.url) ? DEFAULT_DETAIL_TTL_MS : DEFAULT_LIST_TTL_MS;\n\n const live = (): Observable<HttpEvent<unknown>> => next(req).pipe(tap(ev => {\n if (!(ev instanceof HttpResponse) || ev.status !== 200) return;\n stale.clearKey(key);\n const noStore = (ev.headers.get('Cache-Control') ?? '').toLowerCase().includes('no-store');\n if (!noStore && ev.body !== null && ev.body !== undefined) void store.cacheResponse(key, userId, ev.body, ttl).catch(() => undefined);\n }));\n\n const serveCopyOr = (otherwise: () => Observable<HttpEvent<unknown>>): Observable<HttpEvent<unknown>> =>\n from(store.getCached(key, userId)).pipe(switchMap(entry => {\n if (!entry) return otherwise();\n stale.markStale(entry.cachedAt, key);\n return of(cachedResponse(req, entry.data, entry.cachedAt));\n }));\n\n if (connection.isOffline()) {\n return serveCopyOr(() => connection.state() === 'unreachable'\n ? live() // nothing saved: try the network anyway, it may be back\n : throwError(() => new HttpErrorResponse({ url: req.urlWithParams, status: 0, statusText: 'Offline', error: uiText('connection.noCopy') })));\n }\n return live().pipe(catchError(err => isNetworkFailure(err) ? serveCopyOr(() => throwError(() => err)) : throwError(() => err)));\n}\n\nconst warnedPaymentUrls = new Set<string>();\n\n/** A path SEGMENT that names a payment (`/pay`, `/payments`, `/payment-links`, `/payment-intents`, `/charge(s)`, `/refund(s)`): `/repay` and `/payroll` are not payments. */\nconst PAYMENT_SEGMENT = /(^|\\/)(payments?|payment-links?|payment-intents?|pay|charges?|refunds?)(\\/|$)/i;\n\n/**\n * Development help: a request whose path has a payment segment (`/pay`, `/payments`, `/charge`, `/refund`) is about to be SAVED for replay. A replay after reconnecting is a second charge, so such routes belong in\n * `blockOffline` (see `blockPaymentsOffline`). Warns once per path, in development mode only.\n */\nexport function warnIfPaymentQueued(url: string): void {\n if (!isDevMode()) return;\n const path = pathOnly(url);\n if (!PAYMENT_SEGMENT.test(path) || warnedPaymentUrls.has(path)) return;\n warnedPaymentUrls.add(path);\n console.warn(`Offline: \"${path}\" looks like a payment and is being QUEUED for replay while offline. A replay after reconnecting is a second charge: list it in blockOffline with blockPaymentsOffline().`);\n}\n\n/** @internal Specs only (not part of the public entry): forget which payment paths were already warned about. */\nexport function resetPaymentQueueWarnings(): void { warnedPaymentUrls.clear(); }\n\nfunction handleWrite(req: HttpRequest<unknown>, next: (r: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>, cfg: ResolvedOfflineConfig): Observable<HttpEvent<unknown>> {\n const connection = inject(ConnectionStateService);\n const userId = cfg.getUserId();\n\n if (!connection.isOffline() || userId === null) {\n if (userId === null) return next(req);\n const store = inject(OfflineStore);\n return next(req).pipe(tap(ev => {\n if (ev instanceof HttpResponse && ev.ok) void store.invalidatePrefix(invalidationPrefix(req.url), userId).catch(() => undefined);\n }));\n }\n\n const labels = inject(UiLabelsService);\n const block = cfg.blockOffline.find(b => matchesUrl(req.urlWithParams, b.pattern));\n if (block) {\n return throwError(() => new OfflineBlockedError(block.message ?? labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'blocked'));\n }\n if (isUploadBody(req.body)) {\n return throwError(() => new OfflineBlockedError(labels.t('connection.uploadBlocked'), 'upload'));\n }\n let rule: QueueRule | undefined;\n if (cfg.allowQueue) {\n rule = findRule(cfg.allowQueue, req);\n if (!rule) return throwError(() => new OfflineBlockedError(labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'not-allowed'));\n }\n const body = storableBody(req.body);\n if (!body.ok) return throwError(() => new OfflineBlockedError(labels.t('connection.storageUnavailable'), 'storage'));\n\n warnIfPaymentQueued(req.urlWithParams);\n const store = inject(OfflineStore);\n const support = inject(OfflineSupportService);\n const method = req.method.toUpperCase();\n const url = req.urlWithParams;\n const derived = deriveEntity(url);\n const row = {\n id: generateUuid(),\n userId,\n key: req.headers.get(IDEMPOTENCY_HEADER) ?? generateUuid(),\n method,\n url,\n body: body.value,\n headers: safeHeaders(req, cfg, isFormBody(req.body)),\n label: rule?.label?.(method, url, req.body, { injector: inject(Injector) }) ?? defaultLabel(labels, method, url),\n entityType: rule?.entityType?.(url) ?? derived.entityType,\n entityId: derived.entityId,\n createdAt: Date.now(),\n status: 'pending' as const,\n attempts: 0,\n };\n // A create gets its own id as the temp id; a change that refers to the temp id of a create that is still queued remembers that create.\n const tempId = isTempIdCreate(method, url, body.value) ? row.id : undefined;\n return from(store.list(userId).catch((): OfflineMutation[] => [])).pipe(\n switchMap(existing => {\n const creates = new Map<string, string>();\n for (const r of existing) if (r.tempId) creates.set(r.tempId, r.id);\n const refs = findTempIds(url, body.value, creates);\n return store.addMutation({\n ...row,\n ...(tempId ? { tempId } : {}),\n ...(refs.length > 0 ? { dependsOn: refs.map(t => creates.get(t) as string), dependsOnTempIds: refs } : {}),\n });\n }),\n catchError(() => throwError(() => new OfflineBlockedError(labels.t('connection.storageUnavailable'), 'storage'))),\n switchMap(saved => {\n // The same key already belongs to a row that will never be sent again (failed / conflict): answering \"saved\" would be a fake success.\n if (saved.status === 'failed' || saved.status === 'conflict') {\n return throwError(() => new OfflineBlockedError(labels.t('connection.blocked', { action: labels.t('connection.thisAction') }), 'not-allowed'));\n }\n support.onQueued(saved);\n return of(saved);\n }),\n switchMap(saved => {\n const base = body.value !== null && typeof body.value === 'object' && !Array.isArray(body.value) ? body.value as Record<string, unknown> : {};\n return of(new HttpResponse<unknown>({\n status: 202, statusText: 'Accepted', url,\n body: { ...base, id: base['id'] ?? saved.tempId ?? saved.id, _offline: true },\n }));\n }),\n );\n}\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { connectionInterceptor } from './connection.interceptor';\nimport { idempotencyInterceptor } from './idempotency.interceptor';\nimport { offlineInterceptor } from './offline.interceptor';\n\n/**\n * Register LAST in `withInterceptors([... ,...offlineHttpInterceptors])` (after errorContext and the app's own auth interceptor; replays carry\n * `X-Offline-Replay`, so an app whose auth interceptor sits after these still gets the live token on replays).\n *\n * Array order is outermost first: idempotency (adds the key) -> offline (queue / device copy) -> connection (timeout, timing, GET retry, closest\n * to the network). The offline interceptor must be OUTSIDE the connection one: it has to see timeouts and status-0 failures as errors to fall back\n * to the device copy, and answers it makes itself (queued 202, device copy) must not be measured as network successes.\n */\nexport const offlineHttpInterceptors: readonly HttpInterceptorFn[] = [idempotencyInterceptor, offlineInterceptor, connectionInterceptor];\n","import { Injectable, inject } from '@angular/core';\nimport { QueuedNote, QueuedNoteState, UiNotesQueue } from '@forgeroute/ui';\nimport { pathOnly } from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { OfflineSupportService } from '../support/offline-support.service';\nimport type { MutationStatus, OfflineMutation } from '../store/offline-store';\n\nconst STATE: Record<MutationStatus, QueuedNoteState> = { pending: 'waiting', syncing: 'sending', failed: 'failed', conflict: 'conflict' };\n\n/** The text of a queued note body: `{ body }` (generic notes API) or `{ content }` (a resource's own API); '' when there is none. */\nfunction textOf(body: unknown): string {\n let b = body;\n if (typeof b === 'string') { try { b = JSON.parse(b); } catch { return ''; } }\n if (b === null || typeof b !== 'object') return '';\n const o = b as { body?: unknown; content?: unknown };\n const text = typeof o.body === 'string' ? o.body : typeof o.content === 'string' ? o.content : '';\n return text.trim();\n}\n\nfunction decode(segment: string): string {\n try { return decodeURIComponent(segment); } catch { return segment; }\n}\n\n/**\n * The decoded path segments of a URL: origin, query and hash dropped, empty segments (trailing or double slashes) removed, each segment decoded on its own\n * (so an encoded slash `%2F` stays inside its segment). Two URLs name the same resource when these lists are equal, however each was written.\n */\nfunction segments(url: string): string[] {\n return pathOnly(url).split('/').filter(s => s !== '').map(decode);\n}\n\nfunction startsWith(path: string[], prefix: string[]): boolean {\n return path.length >= prefix.length && prefix.every((s, i) => path[i] === s);\n}\n\n/**\n * Lets `ui-notes` show the note changes the offline layer has saved on the device. It reads `OfflineSupportService.rows` (the offline layer's own\n * list - nothing is copied or cached here) and keeps the rows whose URL belongs to the notes list asked for. Provided as `UI_NOTES_QUEUE` by\n * `provideOfflineSupport`; the app still decides whether notes may be queued at all (its `allowQueue` rules / `blockOffline`).\n */\n@Injectable({ providedIn: 'root' })\nexport class OfflineNotesQueue implements UiNotesQueue {\n private readonly support = inject(OfflineSupportService);\n private readonly connection = inject(ConnectionStateService);\n\n readonly offline = this.connection.isOffline;\n wasDiscarded(rowId: string): boolean { return this.support.wasDiscarded(rowId); }\n\n queuedFor(listPath: string, itemPrefix: string): readonly QueuedNote[] {\n const list = segments(listPath);\n const prefix = segments(itemPrefix);\n const out: QueuedNote[] = [];\n for (const row of this.support.rows()) {\n const queued = this.toQueued(row, list, prefix);\n if (queued) out.push(queued);\n }\n return out;\n }\n\n private toQueued(row: OfflineMutation, list: string[], prefix: string[]): QueuedNote | null {\n const path = segments(row.url);\n const method = row.method.toUpperCase();\n const base = { rowId: row.id, createdAt: row.createdAt, state: STATE[row.status] };\n if (method === 'POST' && path.length === list.length && startsWith(path, list)) return { ...base, kind: 'add', noteId: '', text: textOf(row.body) };\n if ((method === 'PUT' || method === 'PATCH' || method === 'DELETE') && startsWith(path, prefix)) {\n if (path.length !== prefix.length + 1) return null;\n const id = path[prefix.length];\n return method === 'DELETE'\n ? { ...base, kind: 'delete', noteId: id, text: '' }\n : { ...base, kind: 'edit', noteId: id, text: textOf(row.body) };\n }\n return null;\n }\n}\n","import { UI_NOTES_QUEUE } from '@forgeroute/ui';\nimport { EnvironmentProviders, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { OFFLINE_SUPPORT_CONFIG, OfflineSupportConfig } from '../config/offline-config';\nimport { ConnectionStateService } from '../state/connection-state.service';\nimport { OfflineStore } from '../store/offline-store';\nimport { OfflineNotesQueue } from '../notes/offline-notes-queue';\nimport { OfflineSupportService } from './offline-support.service';\n\n/**\n * Provides the config and starts the offline layer with the app: opens the store, then wires the replay triggers (app start when online, browser\n * `online`, connection back to `online`, probe success) and the cross-tab sync. Pair it with\n * `provideHttpClient(withInterceptors([..., ...offlineHttpInterceptors]))`.\n */\nexport function provideOfflineSupport(config: OfflineSupportConfig): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: OFFLINE_SUPPORT_CONFIG, useValue: config },\n // Lets `ui-notes` show note changes saved on the device (the app still decides whether notes may be queued).\n { provide: UI_NOTES_QUEUE, useExisting: OfflineNotesQueue },\n provideAppInitializer(() => {\n const store = inject(OfflineStore);\n const support = inject(OfflineSupportService);\n inject(ConnectionStateService);\n return store.init().then(() => { void support.start().catch(() => undefined); });\n }),\n ]);\n}\n","import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, ElementRef, computed, effect, inject, input, output, signal, untracked, viewChild } from '@angular/core';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport { ConnectionStateService, OfflineSupportService } from '../deps';\n\n/** How long the green \"All changes synced\" bar stays after a sync. */\nexport const SYNCED_FLASH_MS = 3000;\n\nexport type ConnectionBannerKind = 'auth' | 'offline' | 'unreachable' | 'syncing' | 'attention' | 'slow' | 'synced';\n\ninterface BannerView {\n kind: ConnectionBannerKind;\n title: string;\n message: string;\n detail: string;\n /** Spoken text: exactly what the sighted user reads. */\n announcement: string;\n}\n\nlet nextId = 0;\n\n/**\n * THE connection banner. Put ONE near the root of the app, above the routed content (inside the scrolling page, not fixed):\n *\n * <ui-connection-banner (viewChanges)=\"drawerOpen.set(true)\" />\n *\n * One plain-words message per situation, by priority: sign-in needed for saved changes > offline > server unreachable >\n * sending saved changes > changes need attention > slow connection > \"All changes synced\" (3 s, also after automatic syncs) > nothing.\n *\n * Accessibility: two live regions (polite status, assertive alert for the sign-in message) exist from the first render and only their text\n * changes, so screen readers announce every change; the visible bar is ordinary content that mirrors the same words. The bar is\n * `position: sticky; top: 0` inside the page flow, so it never covers content, and sits below modals / side panels.\n *\n * A page that REFUSES writes while offline (a public shop: payment needs a connection and nothing is saved on the device) sets `[queues]=\"false\"`\n * (library source 2026-11-10, NOT yet published): the texts then never mention saving on the device or sending later, \"View changes\" / \"Sync now\" /\n * the waiting count and the sync states are not shown, \"What can I do?\" appears only when the app passed `infoOffline` / `infoNeedsConnection`\n * (only the lists the app passed), and coming back online flashes the neutral \"You're back online\" (3 s). It needs no signed-in user.\n *\n * Test ids: connection-banner, connection-banner-live, connection-banner-live-alert, connection-banner-title, connection-banner-message,\n * connection-banner-detail, connection-banner-sync-now, connection-banner-view, connection-banner-info-toggle, connection-banner-info-panel,\n * connection-banner-info-hide.\n */\n@Component({\n selector: 'ui-connection-banner',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"cb-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"connection-banner-live\">{{ politeText() }}</div>\n <div class=\"cb-live\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-testid=\"connection-banner-live-alert\">{{ alertText() }}</div>\n @if (view(); as v) {\n <div class=\"cb-bar\" [class]=\"'cb-bar cb-' + v.kind\" role=\"group\" [attr.aria-label]=\"labels.t('connection.region')\"\n data-testid=\"connection-banner\" [attr.data-state]=\"v.kind\" (keydown.escape)=\"onEscape($event)\">\n <div class=\"cb-text\">\n <strong class=\"cb-title\" data-testid=\"connection-banner-title\">{{ v.title }}</strong>\n @if (v.message) { <span class=\"cb-msg\" data-testid=\"connection-banner-message\"> {{ v.message }}</span> }\n @if (v.detail) { <span class=\"cb-detail\" data-testid=\"connection-banner-detail\"> {{ v.detail }}</span> }\n </div>\n @if (showSyncNow() || showView() || infoAllowed()) {\n <div class=\"cb-actions\">\n @if (showSyncNow()) {\n <button type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-sync-now\" (click)=\"syncNow()\">{{ labels.t('connection.syncNow') }}</button>\n }\n @if (showView()) {\n <button type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-view\" (click)=\"viewChanges.emit()\">{{ labels.t('connection.viewChanges') }}</button>\n }\n @if (infoAllowed()) {\n <button #infoToggle type=\"button\" class=\"cb-btn cb-btn-ghost\" data-testid=\"connection-banner-info-toggle\"\n [attr.aria-expanded]=\"infoOpen()\" [attr.aria-controls]=\"panelId\" (click)=\"toggleInfo()\">{{ labels.t('connection.whatCanIDo') }}</button>\n }\n </div>\n }\n @if (infoAllowed() && infoOpen()) {\n <div class=\"cb-info\" [id]=\"panelId\" role=\"region\" tabindex=\"-1\" [attr.aria-label]=\"labels.t('connection.info.panelLabel')\" data-testid=\"connection-banner-info-panel\">\n @if (showCanDo()) {\n <p class=\"cb-info-h\">{{ labels.t('connection.info.canDoTitle') }}</p>\n <ul class=\"cb-list\">@for (item of canDoItems(); track $index) { <li>{{ item }}</li> }</ul>\n }\n @if (showNeeds()) {\n <p class=\"cb-info-h\">{{ labels.t('connection.info.needsTitle') }}</p>\n <ul class=\"cb-list\">@for (item of needsItems(); track $index) { <li>{{ item }}</li> }</ul>\n }\n <button #infoHide type=\"button\" class=\"cb-btn\" data-testid=\"connection-banner-info-hide\" (click)=\"closeInfo(true)\">{{ labels.t('connection.hide') }}</button>\n </div>\n }\n </div>\n }\n `,\n styles: [`\n :host { display: block; position: -webkit-sticky; position: sticky; top: 0; z-index: 50; }\n .cb-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .cb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; font-size: 0.875rem; line-height: 1.4;\n border-block-end: 1px solid; border-inline-start: 6px solid; box-sizing: border-box; }\n .cb-text { flex: 1 1 280px; min-inline-size: 0; overflow-wrap: anywhere; }\n .cb-actions { display: flex; flex-wrap: wrap; gap: 8px; }\n .cb-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid currentColor; background: #fff; color: inherit;\n font: inherit; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .cb-btn-ghost { background: transparent; }\n .cb-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .cb-btn:focus:not(:focus-visible) { outline: none; }\n .cb-info { flex: 1 1 100%; padding: 12px 14px; border-radius: 8px; background: rgba(255, 255, 255, 0.7); border: 1px solid currentColor; }\n .cb-info:focus { outline: none; }\n .cb-info-h { margin: 0 0 4px; font-weight: 700; }\n .cb-list { margin: 0 0 12px; padding-inline-start: 20px; }\n .cb-offline, .cb-slow, .cb-attention { background: #fef3c7; color: #78350f; border-color: #b45309; }\n .cb-unreachable, .cb-auth { background: #fee2e2; color: #7f1d1d; border-color: #b91c1c; }\n .cb-syncing { background: #dbeafe; color: #1e3a8a; border-color: #1d4ed8; }\n .cb-synced { background: #dcfce7; color: #14532d; border-color: #15803d; }\n @media (prefers-reduced-motion: no-preference) { .cb-bar { animation: cb-in 160ms ease-out; } }\n @keyframes cb-in { from { opacity: 0; } to { opacity: 1; } }\n @media (max-width: 480px) {\n .cb-actions { flex-direction: column; inline-size: 100%; }\n .cb-btn { inline-size: 100%; }\n }\n @media (forced-colors: active) {\n .cb-bar, .cb-info { border: 2px solid CanvasText; background: Canvas; color: CanvasText; }\n .cb-btn { border-color: ButtonText; background: ButtonFace; color: ButtonText; }\n }\n `],\n})\nexport class ConnectionBannerComponent {\n protected readonly labels = inject(UiLabelsService);\n private readonly connection = inject(ConnectionStateService);\n private readonly support = inject(OfflineSupportService);\n private readonly cdr = inject(ChangeDetectorRef);\n\n /** What the user can still do while offline (app specific). Default: a generic list. */\n readonly infoOffline = input<readonly string[] | null>(null);\n /** What needs a connection (app specific, should match what the app really blocks). Default: a generic list. */\n readonly infoNeedsConnection = input<readonly string[] | null>(null);\n /**\n * True (default): the page saves writes on the device while offline and sends them later (today's behaviour, unchanged). False: the page\n * refuses writes while offline and saves nothing - honest texts, no queue controls (see the class comment). Library source 2026-11-10, NOT yet published.\n */\n readonly queues = input(true);\n /** The user pressed \"View changes\" - the app opens `<ui-pending-changes-drawer>`. */\n readonly viewChanges = output<void>();\n\n protected readonly panelId = `ui-cb-info-${++nextId}`;\n protected readonly infoOpen = signal(false);\n private readonly infoToggleRef = viewChild<ElementRef<HTMLButtonElement>>('infoToggle');\n private readonly infoHideRef = viewChild<ElementRef<HTMLButtonElement>>('infoHide');\n\n private readonly syncTotal = signal(0);\n private readonly showSynced = signal(false);\n private syncedTimer: ReturnType<typeof setTimeout> | null = null;\n private seenTick = this.support.syncTick();\n private flashPending = false;\n private wasSyncing = false;\n private prevState = this.connection.state();\n\n protected readonly canDoItems = computed(() => this.infoOffline() ?? (this.queues() ? [this.labels.t('connection.info.canDo1'), this.labels.t('connection.info.canDo2')] : []));\n protected readonly needsItems = computed(() => this.infoNeedsConnection() ?? (this.queues() ? [this.labels.t('connection.info.needs1')] : []));\n /** With `queues` the two default lists always show; without it only the lists the app passed (the generic defaults talk about saved changes). */\n protected readonly showCanDo = computed(() => this.queues() || this.canDoItems().length > 0);\n protected readonly showNeeds = computed(() => this.queues() || this.needsItems().length > 0);\n\n private count(base: 'connection.syncing' | 'connection.needAttention' | 'connection.pending', n: number): string {\n return this.labels.t(`${base}.${n === 1 ? 'one' : 'other'}`, { count: n });\n }\n\n protected readonly view = computed((): BannerView | null => {\n const state = this.connection.state();\n const pending = this.support.pendingCount();\n const attention = this.support.failedCount() + this.support.conflictCount();\n const l = this.labels;\n const queues = this.queues();\n let v: Omit<BannerView, 'announcement'> | null = null;\n if (!queues) {\n // Nothing is saved or sent: only the connection itself is described. Neither the replayer's state nor the waiting count is read.\n if (state === 'offline') v = { kind: 'offline', title: l.t('connection.offline.title'), message: l.t('connection.offline.noQueue.message'), detail: '' };\n else if (state === 'unreachable') v = { kind: 'unreachable', title: l.t('connection.unreachable.title'), message: l.t('connection.unreachable.noQueue.message'), detail: '' };\n else if (state === 'slow') v = { kind: 'slow', title: l.t('connection.slow.title'), message: l.t('connection.slow.noQueue.message'), detail: '' };\n else if (this.showSynced()) v = { kind: 'synced', title: l.t('connection.backOnline'), message: '', detail: '' };\n } else if (this.support.authBlocked()) {\n v = { kind: 'auth', title: l.t('connection.authBlocked'), message: '', detail: '' };\n } else if (state === 'offline') {\n v = { kind: 'offline', title: l.t('connection.offline.title'), message: l.t('connection.offline.message'), detail: pending > 0 ? this.count('connection.pending', pending) : '' };\n } else if (state === 'unreachable') {\n v = { kind: 'unreachable', title: l.t('connection.unreachable.title'), message: l.t('connection.unreachable.message'), detail: pending > 0 ? this.count('connection.pending', pending) : '' };\n } else if (this.support.syncing() && Math.max(this.syncTotal(), pending) > 0) {\n v = { kind: 'syncing', title: this.count('connection.syncing', Math.max(this.syncTotal(), pending)), message: '', detail: '' };\n } else if (attention > 0) {\n v = { kind: 'attention', title: this.count('connection.needAttention', attention), message: '', detail: '' };\n } else if (state === 'slow') {\n v = { kind: 'slow', title: l.t('connection.slow.title'), message: l.t('connection.slow.message'), detail: '' };\n } else if (this.showSynced()) {\n v = { kind: 'synced', title: l.t('connection.synced'), message: '', detail: '' };\n }\n if (!v) return null;\n const sentence = (s: string) => (/[.…!?]$/.test(s) ? s : s + '.');\n return { ...v, announcement: [v.title, v.message, v.detail].filter(Boolean).map(sentence).join(' ') };\n });\n\n /** Set when a \"Sync now\" call was rejected: said politely in the status region (nothing is lost, the changes stay saved). */\n private readonly actionFailure = signal('');\n protected readonly politeText = computed(() => {\n const v = this.view();\n return [v && v.kind !== 'auth' ? v.announcement : '', this.actionFailure()].filter(Boolean).join(' ');\n });\n protected readonly alertText = computed(() => { const v = this.view(); return v && v.kind === 'auth' ? v.announcement : ''; });\n\n protected readonly infoAllowed = computed(() => {\n const k = this.view()?.kind;\n return (k === 'offline' || k === 'unreachable') && (this.queues() || this.showCanDo() || this.showNeeds());\n });\n protected readonly showSyncNow = computed(() => {\n const k = this.view()?.kind;\n return this.queues() && (k === 'unreachable' || k === 'slow' || k === 'attention') && this.support.pendingCount() > 0 && !this.support.syncing();\n });\n protected readonly showView = computed(() => {\n const k = this.view()?.kind;\n if (!this.queues() || !k || k === 'synced') return false;\n return this.rowsTotal() > 0 || k === 'auth';\n });\n private readonly rowsTotal = computed(() => this.support.pendingCount() + this.support.failedCount() + this.support.conflictCount());\n\n constructor() {\n // Remember how many changes a sync started with (\"Sending 3 changes…\" must not count down to 0 while it runs), and flash\n // \"All changes synced\" when a run that changed data (syncTick bumped) ends - manual and automatic runs alike.\n effect(() => {\n const syncing = this.support.syncing();\n const tick = this.support.syncTick();\n untracked(() => {\n if (tick !== this.seenTick) { this.seenTick = tick; if (this.queues()) this.flashPending = true; }\n if (syncing && !this.wasSyncing) this.syncTotal.set(Math.max(this.support.pendingCount(), 0));\n if (!syncing) this.syncTotal.set(0);\n this.wasSyncing = syncing;\n if (!syncing && this.flashPending) { this.flashPending = false; this.flashSynced(); }\n });\n });\n // Without a queue there is no sync to flash: flash the neutral \"You're back online\" when the connection comes back from offline / unreachable.\n effect(() => {\n const state = this.connection.state();\n const queues = this.queues();\n untracked(() => {\n const wasDown = this.prevState === 'offline' || this.prevState === 'unreachable';\n this.prevState = state;\n if (!queues && wasDown && state !== 'offline' && state !== 'unreachable') this.flashSynced();\n });\n });\n effect(() => { if (!this.infoAllowed()) this.infoOpen.set(false); });\n inject(DestroyRef).onDestroy(() => { if (this.syncedTimer) clearTimeout(this.syncedTimer); });\n }\n\n private flashSynced(): void {\n if (this.syncedTimer) clearTimeout(this.syncedTimer);\n this.showSynced.set(true);\n this.syncedTimer = setTimeout(() => { this.syncedTimer = null; this.showSynced.set(false); }, SYNCED_FLASH_MS);\n }\n\n protected syncNow(): void {\n this.actionFailure.set('');\n let call: Promise<unknown>;\n try { call = Promise.resolve(this.support.syncNow()); } catch { call = Promise.reject(new Error('syncNow')); }\n call.catch(() => this.actionFailure.set(this.labels.t('connection.error.unknown')));\n }\n\n protected toggleInfo(): void {\n if (this.infoOpen()) { this.closeInfo(true); return; }\n this.infoOpen.set(true);\n this.cdr.detectChanges();\n this.infoHideRef()?.nativeElement.focus();\n }\n\n protected closeInfo(returnFocus: boolean): void {\n this.infoOpen.set(false);\n this.cdr.detectChanges();\n if (returnFocus) this.infoToggleRef()?.nativeElement.focus();\n }\n\n protected onEscape(event: Event): void {\n if (!this.infoOpen()) return;\n event.stopPropagation();\n this.closeInfo(true);\n }\n}\n","/**\n * \"5 minutes ago\" for the offline UI. Uses `Intl.RelativeTimeFormat` when the browser has it (feature-detected; every current\n * Chrome / Edge / Firefox / Safari does) and falls back to the browser's own date formatting otherwise. `locale` undefined = the\n * page language / browser default.\n */\nexport function formatRelativeTime(then: number, now: number, justNowText: string, locale?: string): string {\n const diffSec = Math.round((now - then) / 1000);\n if (diffSec < 45) return justNowText;\n const rtfCtor = (globalThis as { Intl?: { RelativeTimeFormat?: new (l?: string, o?: { numeric: 'auto' | 'always' }) => { format(v: number, u: string): string } } }).Intl?.RelativeTimeFormat;\n const minutes = Math.round(diffSec / 60);\n const hours = Math.round(diffSec / 3600);\n const days = Math.round(diffSec / 86400);\n if (rtfCtor) {\n let rtf: { format(v: number, u: string): string };\n try { rtf = new rtfCtor(locale, { numeric: 'auto' }); } catch { rtf = new rtfCtor(undefined, { numeric: 'auto' }); }\n if (minutes < 60) return rtf.format(-minutes, 'minute');\n if (hours < 24) return rtf.format(-hours, 'hour');\n if (days <= 30) return rtf.format(-days, 'day');\n }\n return absoluteTime(then, locale);\n}\n\n/** Full local date and time, e.g. for a `title` / `<time>` tooltip. */\nexport function absoluteTime(at: number, locale?: string): string {\n try { return new Date(at).toLocaleString(locale); } catch { return new Date(at).toLocaleString(); }\n}\n\n/**\n * The language of the times the offline UI shows. With `labelsLocale` (the label service's `locale()`, which follows the active dictionary's\n * `i18n.locale` marker or the app's `setLocale`) it always wins, so the times agree with the texts around them. Without `labelsLocale` it is the\n * page language (`<html lang>`) only (`undefined` = the browser default).\n */\nexport function pageLocale(doc: Document, labelsLocale?: string): string | undefined {\n if (labelsLocale) return labelsLocale;\n return doc.documentElement?.lang || undefined;\n}\n","import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, ElementRef, computed, inject, input, output, signal } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { ConfirmService, SidePanelComponent, UiLabelsService } from '@forgeroute/ui';\nimport { KeepMineError, KeepMineOutcome, OfflineSupportService, PendingRow } from '../deps';\nimport { absoluteTime, formatRelativeTime, pageLocale } from '../relative-time';\n\ntype ErrorKind = 'conflict' | 'rejected' | 'auth' | 'server' | 'network' | 'timeout' | 'dependency';\nconst ERROR_KEYS = {\n conflict: 'connection.error.conflict',\n rejected: 'connection.error.rejected',\n auth: 'connection.error.auth',\n server: 'connection.error.server',\n network: 'connection.error.network',\n timeout: 'connection.error.timeout',\n dependency: 'connection.error.dependency',\n} as const;\n\n/**\n * Side panel that lists every change saved on this device and not yet accepted by the server, with plain-words reasons and\n * the actions Retry / Discard per change (a conflict row, when `conflictStampFields` is configured, offers \"Keep my version\" and \"Discard my change\" instead of Retry), Sync all and Discard all. Open it from `(viewChanges)` of `<ui-connection-banner>`:\n *\n * <ui-pending-changes-drawer [open]=\"drawerOpen()\" (closed)=\"drawerOpen.set(false)\" />\n *\n * Raw server text is never shown: the wording comes from `lastError.kind`. Discards ask first (ConfirmService). Results are announced\n * in a polite live region that exists from the first render. Test ids: pending-drawer-live, pending-drawer-auth, pending-drawer-list,\n * pending-drawer-empty, pending-row-<id>, pending-row-status-<id>, pending-row-error-<id>, pending-row-time-<id>, pending-row-retry-<id>,\n * pending-row-keep-mine-<id>, pending-row-discard-<id>, pending-drawer-sync-all, pending-drawer-discard-all.\n */\n@Component({\n selector: 'ui-pending-changes-drawer',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [SidePanelComponent],\n template: `\n <div class=\"pcd-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"pending-drawer-live\">{{ announcement() }}</div>\n <ui-side-panel\n [open]=\"open()\"\n [title]=\"labels.t('connection.drawer.title')\"\n [cancelLabel]=\"labels.t('connection.drawer.close')\"\n [primaryLabel]=\"labels.t('connection.syncAll')\"\n [primaryDisabled]=\"rows().length === 0 || support.syncing()\"\n [primaryLoading]=\"support.syncing()\"\n primaryTestId=\"pending-drawer-sync-all\"\n (closed)=\"closed.emit()\"\n (primaryClick)=\"syncAll()\">\n @if (support.authBlocked()) {\n <p class=\"pcd-auth\" data-testid=\"pending-drawer-auth\">{{ labels.t('connection.authBlocked') }}</p>\n }\n @if (rows().length === 0) {\n <p class=\"pcd-empty\" tabindex=\"-1\" data-testid=\"pending-drawer-empty\">{{ support.storageAvailable() ? labels.t('connection.drawer.empty') : labels.t('connection.storageUnavailable') }}</p>\n } @else {\n <ul class=\"pcd-list\" [attr.aria-label]=\"labels.t('connection.drawer.list')\" data-testid=\"pending-drawer-list\">\n @for (row of rows(); track row.id) {\n <li class=\"pcd-row\" [attr.data-testid]=\"'pending-row-' + row.id\" [attr.data-status]=\"row.status\">\n <div class=\"pcd-main\">\n <span class=\"pcd-label\">{{ row.label }}</span>\n <span class=\"pcd-status\" [attr.data-testid]=\"'pending-row-status-' + row.id\">{{ statusText(row) }}</span>\n </div>\n <time class=\"pcd-time\" [attr.datetime]=\"iso(row)\" [attr.title]=\"absolute(row)\" [attr.data-testid]=\"'pending-row-time-' + row.id\">{{ savedText(row) }}</time>\n @if (errorText(row); as err) {\n <p class=\"pcd-error\" [attr.data-testid]=\"'pending-row-error-' + row.id\">{{ err }}</p>\n }\n <div class=\"pcd-actions\">\n @if (support.canKeepMine(row)) {\n <button type=\"button\" class=\"pcd-btn pcd-btn-primary\" [attr.data-testid]=\"'pending-row-keep-mine-' + row.id\"\n [attr.aria-label]=\"labels.t('connection.conflict.keepMineNamed', { label: row.label })\" [attr.aria-disabled]=\"isBusy(row) ? 'true' : null\" [attr.aria-busy]=\"isBusy(row) ? 'true' : null\" [class.pcd-btn-busy]=\"isBusy(row)\" (click)=\"keepMine(row)\">{{ labels.t('connection.conflict.keepMine') }}</button>\n }\n @if (canRetry(row) && !support.canKeepMine(row)) {\n <button type=\"button\" class=\"pcd-btn\" [attr.data-testid]=\"'pending-row-retry-' + row.id\"\n [attr.aria-label]=\"labels.t('connection.retryNamed', { label: row.label })\" [attr.aria-disabled]=\"isBusy(row) ? 'true' : null\" [attr.aria-busy]=\"isBusy(row) ? 'true' : null\" [class.pcd-btn-busy]=\"isBusy(row)\" (click)=\"retry(row)\">{{ labels.t('connection.retry') }}</button>\n }\n <button type=\"button\" class=\"pcd-btn pcd-btn-danger\" [attr.data-testid]=\"'pending-row-discard-' + row.id\" [disabled]=\"row.status === 'syncing'\"\n [attr.aria-label]=\"discardName(row)\" (click)=\"discard(row)\">{{ discardText(row) }}</button>\n </div>\n </li>\n }\n </ul>\n }\n <button panel-footer-extra type=\"button\" class=\"pcd-btn pcd-btn-danger\" data-testid=\"pending-drawer-discard-all\"\n [disabled]=\"rows().length === 0 || support.syncing()\" (click)=\"discardAll()\">{{ labels.t('connection.discardAll') }}</button>\n </ui-side-panel>\n `,\n styles: [`\n :host { display: contents; }\n .pcd-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .pcd-auth { margin: 0 0 16px; padding: 12px 14px; border-radius: 8px; border: 1px solid #b91c1c; background: #fee2e2; color: #7f1d1d; font-size: 0.875rem; }\n .pcd-empty { margin: 0; padding: 24px 0; color: #475569; font-size: 0.9375rem; text-align: center; }\n .pcd-empty:focus { outline: none; }\n .pcd-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }\n .pcd-row { padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; display: flex; flex-direction: column; gap: 6px; }\n .pcd-main { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }\n .pcd-label { font-weight: 600; color: #0f172a; overflow-wrap: anywhere; min-inline-size: 0; }\n .pcd-status { font-size: 0.8125rem; color: #334155; }\n .pcd-time { font-size: 0.8125rem; color: #475569; }\n .pcd-error { margin: 0; font-size: 0.875rem; color: #7f1d1d; }\n .pcd-row[data-status='conflict'] .pcd-error, .pcd-row[data-status='failed'] .pcd-error { color: #78350f; }\n .pcd-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 4px; }\n .pcd-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid #334155; background: #fff; color: #0f172a;\n font: inherit; font-size: 0.875rem; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .pcd-btn-primary { border-color: #1d4ed8; background: #1d4ed8; color: #fff; }\n .pcd-btn-danger { border-color: #b91c1c; color: #b91c1c; }\n .pcd-btn:disabled, .pcd-btn-busy { opacity: 0.5; cursor: not-allowed; }\n .pcd-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .pcd-btn:focus:not(:focus-visible) { outline: none; }\n @media (max-width: 480px) { .pcd-actions { flex-direction: column; } .pcd-btn { inline-size: 100%; } }\n @media (forced-colors: active) { .pcd-row, .pcd-auth, .pcd-btn { border: 1px solid CanvasText; background: Canvas; color: CanvasText; } }\n `],\n})\nexport class PendingChangesDrawerComponent {\n protected readonly labels = inject(UiLabelsService);\n protected readonly support = inject(OfflineSupportService);\n private readonly confirmService = inject(ConfirmService);\n private readonly cdr = inject(ChangeDetectorRef);\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n private readonly doc = inject(DOCUMENT);\n\n readonly open = input(false);\n readonly closed = output<void>();\n\n protected readonly rows = computed(() => this.support.rows());\n protected readonly announcement = signal('');\n private readonly now = signal(Date.now());\n /** Rows whose Retry / Keep my version (confirm or request) is in flight: their buttons are disabled so a second click cannot start it twice. */\n private readonly busyIds = signal<ReadonlySet<string>>(new Set());\n\n constructor() {\n const timer = setInterval(() => this.now.set(Date.now()), 30_000);\n inject(DestroyRef).onDestroy(() => clearInterval(timer));\n }\n\n protected statusText(row: PendingRow): string {\n switch (row.status) {\n case 'syncing': return this.labels.t('connection.status.syncing');\n case 'failed': return this.labels.t('connection.status.failed');\n case 'conflict': return this.labels.t('connection.status.conflict');\n default: return this.labels.t('connection.status.pending');\n }\n }\n\n /** Plain words from the error KIND; the server's own text (`lastError.message`) is never shown. */\n protected errorText(row: PendingRow): string {\n if (row.status === 'conflict') return this.labels.t('connection.conflict.rowText');\n const kind = row.lastError?.kind as ErrorKind | undefined;\n if (kind && kind in ERROR_KEYS) return this.labels.t(ERROR_KEYS[kind]);\n if (row.status === 'failed' || row.lastError) return this.labels.t('connection.error.unknown');\n return '';\n }\n\n protected canRetry(row: PendingRow): boolean {\n return row.status === 'failed' || row.status === 'conflict' || (row.status === 'pending' && !!row.lastError);\n }\n\n protected discardText(row: PendingRow): string {\n return this.labels.t(row.status === 'conflict' ? 'connection.conflict.discard' : 'connection.discard');\n }\n\n protected discardName(row: PendingRow): string {\n return row.status === 'conflict' ? this.labels.t('connection.conflict.discardNamed', { label: row.label }) : this.labels.t('connection.discardNamed', { label: row.label });\n }\n\n protected iso(row: PendingRow): string { return new Date(row.createdAt).toISOString(); }\n protected absolute(row: PendingRow): string { return absoluteTime(row.createdAt, pageLocale(this.doc, this.labels.locale())); }\n protected savedText(row: PendingRow): string {\n const time = formatRelativeTime(row.createdAt, this.now(), this.labels.t('connection.time.justNow'), pageLocale(this.doc, this.labels.locale()));\n return this.labels.t('connection.savedAt', { time });\n }\n\n protected isBusy(row: PendingRow): boolean {\n return this.busyIds().has(row.id);\n }\n\n private setBusy(id: string, busy: boolean): void {\n this.busyIds.update(set => { const next = new Set(set); if (busy) next.add(id); else next.delete(id); return next; });\n }\n\n protected async retry(row: PendingRow): Promise<void> {\n if (this.isBusy(row)) return;\n this.setBusy(row.id, true);\n try {\n this.announcement.set(this.labels.t('connection.result.retrying', { label: row.label }));\n try { await this.support.retry(row.id); } catch { this.announceFailure(); }\n } finally {\n this.setBusy(row.id, false);\n }\n }\n\n /** \"Keep my version\": asks first (the other person's version is lost), then removes the stamp and sends only this change, then says what happened (sent / will be sent shortly / could not be sent). */\n protected async keepMine(row: PendingRow): Promise<void> {\n if (this.isBusy(row)) return;\n this.setBusy(row.id, true);\n try {\n const index = this.rows().findIndex(r => r.id === row.id);\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.conflict.confirmTitle'),\n message: this.labels.t('connection.conflict.confirmMessage'),\n confirmLabel: this.labels.t('connection.conflict.keepMine'),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n this.announcement.set(this.labels.t('connection.conflict.result.keeping', { label: row.label }));\n let outcome: KeepMineOutcome;\n try { outcome = await this.support.keepMine(row.id); } catch (e) { this.announcement.set(e instanceof KeepMineError ? e.message : this.labels.t('connection.conflict.error.unknown')); return; }\n this.announcement.set(outcome === 'sent' ? this.labels.t('connection.conflict.result.sent', { label: row.label })\n : outcome === 'shortly' ? this.labels.t('connection.conflict.result.shortly', { label: row.label })\n : this.labels.t('connection.conflict.error.unknown'));\n this.cdr.detectChanges();\n if (!this.rows().some(r => r.id === row.id)) this.focusAfterRemoval(index);\n } finally {\n this.setBusy(row.id, false);\n }\n }\n\n protected async syncAll(): Promise<void> {\n this.announcement.set(this.labels.t('connection.result.syncStarted'));\n try { await this.support.syncNow(); } catch { this.announceFailure(); }\n }\n\n protected async discard(row: PendingRow): Promise<void> {\n const index = this.rows().findIndex(r => r.id === row.id);\n // Other saved changes that point at a record this change creates cannot be sent once it is gone: say so before the user decides.\n // The count follows chains (create A, create B that uses A, an edit of B: discarding A fails both B and the edit); the set also guards against cycles.\n const all = this.rows();\n const dependentIds = new Set<string>();\n const pending = [row.id];\n while (pending.length > 0) {\n const current = pending.pop() as string;\n for (const r of all) {\n if (r.id !== row.id && !dependentIds.has(r.id) && (r.dependsOn ?? []).includes(current)) { dependentIds.add(r.id); pending.push(r.id); }\n }\n }\n const dependents = dependentIds.size;\n const message = dependents === 0 ? this.labels.t('connection.discard.message', { label: row.label })\n : dependents === 1 ? this.labels.t('connection.discard.dependents.one', { label: row.label })\n : this.labels.t('connection.discard.dependents.other', { label: row.label, count: dependents });\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.discard.title'),\n message,\n confirmLabel: this.discardText(row),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n try { await this.support.discard(row.id); } catch { this.announceFailure(); return; }\n this.announcement.set(this.labels.t('connection.result.discarded', { label: row.label }));\n this.cdr.detectChanges();\n this.focusAfterRemoval(index);\n }\n\n protected async discardAll(): Promise<void> {\n const count = this.rows().length;\n if (count === 0) return;\n const ok = await this.confirmService.confirm({\n title: this.labels.t('connection.discardAll.title'),\n message: this.labels.t(count === 1 ? 'connection.discardAll.message.one' : 'connection.discardAll.message.other', { count }),\n confirmLabel: this.labels.t('connection.discardAll'),\n cancelLabel: this.labels.t('toolbar.cancel'),\n variant: 'danger',\n });\n if (!ok) return;\n try { await this.support.discardAll(); } catch { this.announceFailure(); return; }\n this.announcement.set(this.labels.t('connection.result.discardedAll'));\n this.cdr.detectChanges();\n this.focusAfterRemoval(0);\n }\n\n /** A rejected service call must not become an unhandled rejection; tell the user politely (nothing was lost). */\n private announceFailure(): void {\n this.announcement.set(this.labels.t('connection.error.unknown'));\n }\n\n /** The row the user acted on is gone: move focus to the row now at that position (or the previous one, or the empty message). */\n private focusAfterRemoval(index: number): void {\n // ui-side-panel projects its body into the panel element, which lives under this component's host.\n const root = this.host.nativeElement;\n const rowEls = Array.from(root.querySelectorAll<HTMLElement>('li.pcd-row'));\n const target = rowEls[Math.min(index, rowEls.length - 1)]?.querySelector<HTMLElement>('button:not([disabled])') ?? root.querySelector<HTMLElement>('.pcd-empty');\n target?.focus();\n }\n}\n","import { ChangeDetectionStrategy, Component, DestroyRef, computed, inject, output, signal } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { UiLabelsService } from '@forgeroute/ui';\nimport { StaleDataService } from '../deps';\nimport { absoluteTime, formatRelativeTime, pageLocale } from '../relative-time';\n\nconst TIME_MARK = '\\u0001';\n\n/**\n * \"Showing saved data from 5 minutes ago [Refresh]\" while `StaleDataService.staleAt()` is set (a GET was answered from the\n * device copy). Put it at the top of the page area that shows the data; the app reloads the data on `(refresh)`:\n *\n * <ui-stale-data-chip (refresh)=\"reload()\" />\n *\n * A polite live region exists from the first render (visually hidden) and mirrors the sentence. Test ids: stale-data-chip,\n * stale-data-chip-live, stale-data-chip-time, stale-data-chip-refresh.\n */\n@Component({\n selector: 'ui-stale-data-chip',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n <div class=\"sdc-live\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"stale-data-chip-live\">{{ announcement() }}</div>\n @if (parts(); as p) {\n <div class=\"sdc\" data-testid=\"stale-data-chip\">\n <span class=\"sdc-text\">{{ p.before }}<time [attr.datetime]=\"p.iso\" [attr.title]=\"p.absolute\" data-testid=\"stale-data-chip-time\">{{ p.relative }}</time>{{ p.after }}</span>\n <button type=\"button\" class=\"sdc-btn\" data-testid=\"stale-data-chip-refresh\" [attr.aria-label]=\"labels.t('connection.refreshAria')\" (click)=\"refresh.emit()\">{{ labels.t('connection.refresh') }}</button>\n </div>\n }\n `,\n styles: [`\n :host { display: block; position: relative; }\n .sdc-live { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }\n .sdc { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 6px 8px 6px 14px; border-radius: 999px; border: 1px solid #b45309;\n background: #fef3c7; color: #78350f; font-size: 0.8125rem; line-height: 1.4; max-inline-size: 100%; box-sizing: border-box; }\n .sdc-text { min-inline-size: 0; overflow-wrap: anywhere; }\n .sdc-btn { min-block-size: 44px; min-inline-size: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid currentColor; background: #fff; color: inherit;\n font: inherit; font-weight: 600; cursor: pointer; -webkit-appearance: none; appearance: none; }\n .sdc-btn:focus { outline: 3px solid #1d4ed8; outline-offset: 2px; }\n .sdc-btn:focus:not(:focus-visible) { outline: none; }\n @media (max-width: 480px) { .sdc { border-radius: 12px; } .sdc-btn { inline-size: 100%; } }\n @media (forced-colors: active) { .sdc, .sdc-btn { border: 1px solid CanvasText; background: Canvas; color: CanvasText; } }\n `],\n})\nexport class StaleDataChipComponent {\n protected readonly labels = inject(UiLabelsService);\n private readonly stale = inject(StaleDataService);\n private readonly doc = inject(DOCUMENT);\n /** The user pressed Refresh - reload the data from the server. */\n readonly refresh = output<void>();\n\n private readonly now = signal(Date.now());\n\n protected readonly parts = computed(() => {\n const at = this.stale.staleAt();\n if (at == null) return null;\n const locale = pageLocale(this.doc, this.labels.locale());\n const relative = formatRelativeTime(at, this.now(), this.labels.t('connection.time.justNow'), locale);\n const text = this.labels.t('connection.stale', { time: TIME_MARK });\n const at0 = text.indexOf(TIME_MARK);\n // A translation without the {{ time }} placeholder still shows the time, after the text and a space (never glued to the last word).\n const before = at0 < 0 ? `${text} ` : text.slice(0, at0);\n const after = at0 < 0 ? '' : text.slice(at0 + TIME_MARK.length);\n return { before, after, relative, iso: new Date(at).toISOString(), absolute: absoluteTime(at, locale) };\n });\n\n protected readonly announcement = computed(() => {\n const p = this.parts();\n return p ? `${p.before}${p.relative}${p.after}` : '';\n });\n\n constructor() {\n // Keep \"5 minutes ago\" current while the page stays open.\n const timer = setInterval(() => this.now.set(Date.now()), 30_000);\n inject(DestroyRef).onDestroy(() => clearInterval(timer));\n }\n}\n","import { ChangeDetectionStrategy, Component, computed, effect, inject, input, signal, untracked } from '@angular/core';\nimport { UiLabelsService } from '@forgeroute/ui';\n\n/**\n * \"Still working… please don't tap again.\" for a button or panel whose request has been running for a while.\n *\n * <ui-still-working [active]=\"saving()\" />\n *\n * The host keeps its own button disabled while `active`. The text appears only after `delayMs` (default 4 s) of continuous\n * `active`, disappears at once when `active` turns false, and sits in a polite live region that exists from the first render\n * (so screen readers announce the text when it appears). `text` (optional, library source 2026-11-10, NOT yet published) replaces the label:\n * `<ui-still-working [active]=\"paying()\" [delayMs]=\"4000\" text=\"Please do not close or refresh this page, we are finishing your payment.\" />`.\n * Test id: still-working.\n */\n@Component({\n selector: 'ui-still-working',\n standalone: true,\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `<div class=\"sw\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\" data-testid=\"still-working\">{{ shown() }}</div>`,\n styles: [`\n :host { display: block; }\n .sw { color: #475569; font-size: 0.8125rem; line-height: 1.4; }\n .sw:empty { min-block-size: 0; margin: 0; padding: 0; }\n @media (forced-colors: active) { .sw { color: CanvasText; } }\n `],\n})\nexport class StillWorkingComponent {\n private readonly labels = inject(UiLabelsService);\n /** True while the request runs. */\n readonly active = input(false);\n /** Milliseconds of continuous `active` before the text appears. */\n readonly delayMs = input(4000);\n /**\n * Optional text shown instead of the library label (already translated by the app), e.g. the pay step: \"Please do not close or refresh this\n * page, we are finishing your payment.\" Empty or whitespace only = the library label, as before. Library source 2026-11-10, NOT yet published.\n */\n readonly text = input('');\n\n private readonly elapsed = signal(false);\n protected readonly shown = computed(() => {\n if (!this.active() || !this.elapsed()) return '';\n const custom = this.text().trim();\n return custom ? this.text() : this.labels.t('connection.stillWorking');\n });\n\n constructor() {\n effect(onCleanup => {\n const active = this.active();\n const delay = this.delayMs();\n untracked(() => this.elapsed.set(false));\n if (!active) return;\n const timer = setTimeout(() => this.elapsed.set(true), Math.max(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