@guidelytech/sdk-core 0.5.0 → 0.6.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.
- package/dist/capture-C3faAYb7.d.cts +99 -0
- package/dist/capture-Dqd7up2n.d.ts +99 -0
- package/dist/capture.cjs +313 -0
- package/dist/capture.cjs.map +1 -0
- package/dist/capture.d.cts +3 -0
- package/dist/capture.d.ts +3 -0
- package/dist/capture.js +235 -0
- package/dist/capture.js.map +1 -0
- package/dist/{chunk-GJT7CFAC.js → chunk-AKNE7D5M.js} +14 -5
- package/dist/chunk-AKNE7D5M.js.map +1 -0
- package/dist/chunk-CYAG6ZYX.js +85 -0
- package/dist/chunk-CYAG6ZYX.js.map +1 -0
- package/dist/{chunk-HLR3W63Z.js → chunk-GDF6RCHQ.js} +6 -79
- package/dist/chunk-GDF6RCHQ.js.map +1 -0
- package/dist/headless.cjs +18 -5
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +3 -49
- package/dist/headless.d.ts +3 -49
- package/dist/headless.js +6 -4
- package/dist/http-47tiAlOM.d.cts +86 -0
- package/dist/http-47tiAlOM.d.ts +86 -0
- package/dist/index.cjs +309 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +273 -39
- package/dist/index.js.map +1 -1
- package/dist/recorder.cjs +1 -1
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.js +2 -2
- package/dist/recorder.js.map +1 -1
- package/dist/{types-BZ9r3Fs9.d.cts → types-RyeRQd9f.d.ts} +9 -30
- package/dist/{types-BZ9r3Fs9.d.ts → types-d4eOerxi.d.cts} +9 -30
- package/package.json +8 -3
- package/dist/chunk-GJT7CFAC.js.map +0 -1
- package/dist/chunk-HLR3W63Z.js.map +0 -1
package/dist/headless.cjs
CHANGED
|
@@ -58,7 +58,8 @@ var Api = class {
|
|
|
58
58
|
const f = this.fetcher;
|
|
59
59
|
if (!f) throw new Error("fetch is not available");
|
|
60
60
|
const headers = { ...options.headers, "X-Guidely-Key": this.key, Accept: "application/json" };
|
|
61
|
-
|
|
61
|
+
const form = typeof FormData !== "undefined" && options.body instanceof FormData;
|
|
62
|
+
if (options.body !== void 0 && !form) headers["Content-Type"] = "application/json";
|
|
62
63
|
if (options.etag) headers["If-None-Match"] = options.etag;
|
|
63
64
|
const ac = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
64
65
|
const timer = ac ? setTimeout(() => ac.abort(), options.timeoutMs ?? 1e4) : null;
|
|
@@ -66,7 +67,7 @@ var Api = class {
|
|
|
66
67
|
const res = await f(this.url(path, options.params), {
|
|
67
68
|
method,
|
|
68
69
|
headers,
|
|
69
|
-
body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
|
|
70
|
+
body: options.body === void 0 ? void 0 : form ? options.body : JSON.stringify(options.body),
|
|
70
71
|
keepalive: options.keepalive,
|
|
71
72
|
signal: ac?.signal,
|
|
72
73
|
credentials: "omit",
|
|
@@ -91,6 +92,10 @@ var Api = class {
|
|
|
91
92
|
post(path, body, options) {
|
|
92
93
|
return this.request("POST", path, { body, ...options });
|
|
93
94
|
}
|
|
95
|
+
/** Multipart POST (file uploads). No Content-Type header: the browser adds it with the boundary. */
|
|
96
|
+
postForm(path, form, options) {
|
|
97
|
+
return this.request("POST", path, { body: form, ...options });
|
|
98
|
+
}
|
|
94
99
|
/**
|
|
95
100
|
* POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is
|
|
96
101
|
* returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.
|
|
@@ -133,10 +138,10 @@ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
133
138
|
function backoffMs(attempt, baseMs = 1e3, maxMs = 3e4) {
|
|
134
139
|
return Math.min(maxMs, baseMs * 2 ** Math.max(0, attempt));
|
|
135
140
|
}
|
|
136
|
-
async function
|
|
141
|
+
async function withRetry(send, attempts = 3, baseMs = 500) {
|
|
137
142
|
for (let i = 0; i < attempts; i++) {
|
|
138
143
|
try {
|
|
139
|
-
const res = await
|
|
144
|
+
const res = await send();
|
|
140
145
|
if (res.ok || res.status >= 400 && res.status < 500 && res.status !== 429) return res;
|
|
141
146
|
} catch {
|
|
142
147
|
}
|
|
@@ -144,6 +149,9 @@ async function postWithRetry(api, path, body, attempts = 3, baseMs = 500) {
|
|
|
144
149
|
}
|
|
145
150
|
return null;
|
|
146
151
|
}
|
|
152
|
+
function postWithRetry(api, path, body, attempts = 3, baseMs = 500) {
|
|
153
|
+
return withRetry(() => api.post(path, body), attempts, baseMs);
|
|
154
|
+
}
|
|
147
155
|
async function readEventStream(body, onEvent) {
|
|
148
156
|
const reader = body.getReader();
|
|
149
157
|
const decoder = new TextDecoder();
|
|
@@ -209,8 +217,13 @@ var KEYS = {
|
|
|
209
217
|
session: "guidely:session",
|
|
210
218
|
active: "guidely:active",
|
|
211
219
|
authoring: "guidely:authoring",
|
|
220
|
+
/** How-to capture session marker ({ token, … }) and its not-yet-uploaded steps. */
|
|
221
|
+
capture: "guidely:capture",
|
|
222
|
+
capturePending: "guidely:capture:pending",
|
|
212
223
|
/** Messenger conversations this browser can read: [{ id, token }]. */
|
|
213
|
-
conversations: (key) => `guidely:conversations:${key}
|
|
224
|
+
conversations: (key) => `guidely:conversations:${key}`,
|
|
225
|
+
/** Announcement ids opened in the messenger's News tab. */
|
|
226
|
+
newsSeen: (key) => `guidely:news:${key}`
|
|
214
227
|
};
|
|
215
228
|
|
|
216
229
|
// src/queue.ts
|
package/dist/headless.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/headless.ts","../src/http.ts","../src/storage.ts","../src/queue.ts","../src/emitter.ts","../src/frequency.ts"],"sourcesContent":["/**\n * `@guidelytech/sdk-core/headless` — the DOM-free building blocks of the SDK (HTTP client, event\n * queue, frequency rules, emitter, key/value storage helpers). Used by the React Native SDK, which\n * renders guides natively instead of through `@guidelytech/guide-runtime`.\n */\nexport { Api, postWithRetry, backoffMs, sleep } from \"./http\";\nexport type { ApiResponse, FetchLike } from \"./http\";\nexport { EventQueue } from \"./queue\";\nexport type { EventQueueOptions } from \"./queue\";\nexport { Emitter } from \"./emitter\";\nexport { isFrequencyEligible, isExclusiveGuide, areMutuallyExclusive, isWithinSchedule } from \"./frequency\";\nexport type { GuideLocalState } from \"./frequency\";\nexport { memoryStore, readJson, writeJson, KEYS } from \"./storage\";\nexport type { KeyValueStore } from \"./storage\";\nexport type { ChecklistProgressState, PersistedState, SessionState, ConsentState, GuidelyAccount, GuidelyUser, GuidelyEnvironment } from \"./types\";\n","export interface ApiResponse<T> {\n status: number;\n ok: boolean;\n data: T | null;\n etag: string | null;\n}\n\nexport type FetchLike = typeof fetch;\n\n/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */\nexport class Api {\n constructor(\n private readonly baseUrl: string,\n private readonly key: string,\n private readonly fetchImpl?: FetchLike,\n ) {}\n\n url(path: string, params: Record<string, string | undefined> = {}): string {\n // Built by hand rather than with URL/searchParams, which React Native does not implement.\n const query = Object.entries({ key: this.key, ...params })\n .filter((e): e is [string, string] => e[1] != null)\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n return `${this.baseUrl.replace(/\\/$/, \"\")}/api/v1/sdk${path}?${query}`;\n }\n\n private get fetcher(): FetchLike | null {\n if (this.fetchImpl) return this.fetchImpl;\n return typeof fetch === \"function\" ? fetch.bind(globalThis) : null;\n }\n\n async request<T>(method: \"GET\" | \"POST\", path: string, options: { body?: unknown; etag?: string | null; params?: Record<string, string | undefined>; keepalive?: boolean; timeoutMs?: number; headers?: Record<string, string> } = {}): Promise<ApiResponse<T>> {\n const f = this.fetcher;\n if (!f) throw new Error(\"fetch is not available\");\n const headers: Record<string, string> = { ...options.headers, \"X-Guidely-Key\": this.key, Accept: \"application/json\" };\n if (options.body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n if (options.etag) headers[\"If-None-Match\"] = options.etag;\n const ac = typeof AbortController !== \"undefined\" ? new AbortController() : null;\n const timer = ac ? setTimeout(() => ac.abort(), options.timeoutMs ?? 10000) : null;\n try {\n const res = await f(this.url(path, options.params), {\n method,\n headers,\n body: options.body === undefined ? undefined : JSON.stringify(options.body),\n keepalive: options.keepalive,\n signal: ac?.signal,\n credentials: \"omit\",\n mode: \"cors\",\n });\n let data: T | null = null;\n if (res.status !== 304 && res.status !== 204) {\n try {\n data = (await res.json()) as T;\n } catch {\n data = null;\n }\n }\n return { status: res.status, ok: res.ok, data, etag: res.headers?.get?.(\"etag\") ?? null };\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n\n get<T>(path: string, options?: { etag?: string | null; params?: Record<string, string | undefined>; headers?: Record<string, string> }): Promise<ApiResponse<T>> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body: unknown, options?: { params?: Record<string, string | undefined>; keepalive?: boolean; headers?: Record<string, string> }): Promise<ApiResponse<T>> {\n return this.request<T>(\"POST\", path, { body, ...options });\n }\n\n /**\n * POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is\n * returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.\n */\n async stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers: Record<string, string> = {}): Promise<ApiResponse<T>> {\n const f = this.fetcher;\n if (!f) throw new Error(\"fetch is not available\");\n const res = await f(this.url(path), {\n method: \"POST\",\n headers: { ...headers, \"X-Guidely-Key\": this.key, Accept: \"text/event-stream, application/json\", \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n credentials: \"omit\",\n mode: \"cors\",\n });\n const type = res.headers?.get?.(\"content-type\") ?? \"\";\n if (!type.includes(\"text/event-stream\") || !res.body) {\n let data: T | null = null;\n try {\n data = (await res.json()) as T;\n } catch {\n data = null;\n }\n return { status: res.status, ok: res.ok, data, etag: null };\n }\n await readEventStream(res.body, onEvent);\n return { status: res.status, ok: res.ok, data: null, etag: null };\n }\n\n /** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */\n beacon(path: string, body: unknown): boolean {\n try {\n if (typeof navigator === \"undefined\" || typeof navigator.sendBeacon !== \"function\") return false;\n // text/plain is a CORS-safelisted type: cross-origin beacons need no preflight (which\n // browsers drop during unload). The API parses the body regardless of content type.\n const blob = new Blob([JSON.stringify(body)], { type: \"text/plain;charset=UTF-8\" });\n return navigator.sendBeacon(this.url(path), blob);\n } catch {\n return false;\n }\n }\n}\n\nexport const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));\n\n/** Exponential backoff helper: 1s → 2s → 4s … capped. */\nexport function backoffMs(attempt: number, baseMs = 1000, maxMs = 30000): number {\n return Math.min(maxMs, baseMs * 2 ** Math.max(0, attempt));\n}\n\n/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */\nexport async function postWithRetry<T>(api: Api, path: string, body: unknown, attempts = 3, baseMs = 500): Promise<ApiResponse<T> | null> {\n for (let i = 0; i < attempts; i++) {\n try {\n const res = await api.post<T>(path, body);\n if (res.ok || (res.status >= 400 && res.status < 500 && res.status !== 429)) return res;\n } catch {\n /* network error → retry */\n }\n if (i < attempts - 1) await sleep(backoffMs(i, baseMs, 8000));\n }\n return null;\n}\n\n/** Parses a `text/event-stream` body (`event:` + single-line JSON `data:`; comment lines ignored). */\nexport async function readEventStream(body: ReadableStream<Uint8Array>, onEvent: (event: string, data: unknown) => void): Promise<void> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n const dispatch = (raw: string) => {\n let event = \"message\";\n const data: string[] = [];\n for (const line of raw.split(\"\\n\")) {\n if (!line || line.startsWith(\":\")) continue;\n const i = line.indexOf(\":\");\n const field = i < 0 ? line : line.slice(0, i);\n const value = i < 0 ? \"\" : line.slice(i + 1).replace(/^ /, \"\");\n if (field === \"event\") event = value;\n else if (field === \"data\") data.push(value);\n }\n if (!data.length) return;\n try {\n onEvent(event, JSON.parse(data.join(\"\\n\")));\n } catch {\n /* ignore malformed events */\n }\n };\n for (;;) {\n const { done, value } = await reader.read();\n if (value) buffer += decoder.decode(value, { stream: true }).replace(/\\r\\n?/g, \"\\n\");\n let sep: number;\n while ((sep = buffer.indexOf(\"\\n\\n\")) >= 0) {\n dispatch(buffer.slice(0, sep));\n buffer = buffer.slice(sep + 2);\n }\n if (done) break;\n }\n if (buffer.trim()) dispatch(buffer);\n}\n","export type StorageKind = \"local\" | \"session\" | \"memory\";\n\n/** Minimal synchronous key/value store; never throws (private mode, quota, SSR). */\nexport interface KeyValueStore {\n get(key: string): string | null;\n set(key: string, value: string): void;\n remove(key: string): void;\n}\n\nexport function memoryStore(): KeyValueStore {\n const map = new Map<string, string>();\n return { get: (k) => map.get(k) ?? null, set: (k, v) => void map.set(k, v), remove: (k) => void map.delete(k) };\n}\n\nfunction webStore(area: \"localStorage\" | \"sessionStorage\"): KeyValueStore | null {\n try {\n if (typeof window === \"undefined\") return null;\n const s = window[area];\n if (!s) return null;\n const probe = \"__guidely_probe__\";\n s.setItem(probe, \"1\");\n s.removeItem(probe);\n return {\n get: (k) => {\n try {\n return s.getItem(k);\n } catch {\n return null;\n }\n },\n set: (k, v) => {\n try {\n s.setItem(k, v);\n } catch {\n /* quota / private mode */\n }\n },\n remove: (k) => {\n try {\n s.removeItem(k);\n } catch {\n /* ignore */\n }\n },\n };\n } catch {\n return null;\n }\n}\n\n/** Creates a store of the requested kind, degrading to memory when unavailable. */\nexport function createStorage(kind: StorageKind = \"local\"): KeyValueStore {\n if (kind === \"memory\") return memoryStore();\n return webStore(kind === \"local\" ? \"localStorage\" : \"sessionStorage\") ?? memoryStore();\n}\n\nexport function readJson<T>(store: KeyValueStore, key: string, fallback: T): T {\n const raw = store.get(key);\n if (raw == null) return fallback;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n}\n\nexport function writeJson(store: KeyValueStore, key: string, value: unknown): void {\n try {\n store.set(key, JSON.stringify(value));\n } catch {\n /* ignore */\n }\n}\n\n/** Storage keys used by the SDK (documented for integrators). */\nexport const KEYS = {\n anon: \"guidely:anon\",\n seen: \"guidely:seen\",\n config: (key: string) => `guidely:config:${key}`,\n etag: (key: string) => `guidely:etag:${key}`,\n state: (key: string) => `guidely:state:${key}`,\n user: (key: string) => `guidely:user:${key}`,\n queue: (key: string) => `guidely:queue:${key}`,\n session: \"guidely:session\",\n active: \"guidely:active\",\n authoring: \"guidely:authoring\",\n /** Messenger conversations this browser can read: [{ id, token }]. */\n conversations: (key: string) => `guidely:conversations:${key}`,\n} as const;\n","import type { SdkEvent } from \"@guidelytech/shared\";\nimport { backoffMs } from \"./http\";\nimport { readJson, writeJson, type KeyValueStore } from \"./storage\";\n\nexport interface EventQueueOptions {\n store: KeyValueStore;\n storageKey: string;\n /** Sends one batch. Resolve `{ ok: true }` on success, `{ ok: false, retry }` otherwise. */\n send: (events: SdkEvent[]) => Promise<{ ok: boolean; retry?: boolean }>;\n /** Synchronous best-effort send used on page hide. */\n beacon?: (events: SdkEvent[]) => boolean;\n /** Should events be flushed right now? (analytics enabled + consent granted). */\n enabled: () => boolean;\n flushIntervalMs?: number;\n maxQueue?: number;\n batchSize?: number;\n maxAttempts?: number;\n onError?: (err: unknown) => void;\n}\n\n/**\n * Bounded, persisted event queue. Batches ≤50 events every 2s (or on demand), dedupes by\n * `eventId`, retries with exponential backoff (1s→30s, 5 attempts) and keeps failed events for\n * the next flush. Drops the oldest events once the queue exceeds 200.\n */\nexport class EventQueue {\n private events: SdkEvent[] = [];\n private timer: ReturnType<typeof setTimeout> | null = null;\n private retryTimer: ReturnType<typeof setTimeout> | null = null;\n private inflight = false;\n private inflightIds = new Set<string>();\n private attempt = 0;\n private destroyed = false;\n private readonly flushIntervalMs: number;\n private readonly maxQueue: number;\n private readonly batchSize: number;\n private readonly maxAttempts: number;\n\n constructor(private readonly opts: EventQueueOptions) {\n this.flushIntervalMs = opts.flushIntervalMs ?? 2000;\n this.maxQueue = opts.maxQueue ?? 200;\n this.batchSize = opts.batchSize ?? 50;\n this.maxAttempts = opts.maxAttempts ?? 5;\n const persisted = readJson<SdkEvent[]>(opts.store, opts.storageKey, []);\n if (Array.isArray(persisted)) this.events = persisted.filter((e) => e && typeof e.eventId === \"string\").slice(-this.maxQueue);\n // Events left over from a previous page load are flushed on the next tick.\n if (this.events.length) this.schedule();\n }\n\n get size(): number {\n return this.events.length;\n }\n\n /** Pending events (read-only copy, for debugging). */\n peek(): SdkEvent[] {\n return this.events.slice();\n }\n\n enqueue(event: SdkEvent): void {\n if (this.destroyed) return;\n if (this.events.some((e) => e.eventId === event.eventId)) return;\n this.events.push(event);\n if (this.events.length > this.maxQueue) this.events.splice(0, this.events.length - this.maxQueue);\n this.persist();\n this.schedule();\n }\n\n private persist(): void {\n writeJson(this.opts.store, this.opts.storageKey, this.events);\n }\n\n private schedule(): void {\n if (this.timer || this.retryTimer || this.destroyed) return;\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.flush();\n }, this.flushIntervalMs);\n }\n\n /** Sends queued events now (one batch at a time). Safe to call at any time. */\n async flush(): Promise<void> {\n if (this.destroyed || this.inflight || !this.events.length || !this.opts.enabled()) return;\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n this.inflight = true;\n const batch = this.events.slice(0, this.batchSize);\n this.inflightIds = new Set(batch.map((e) => e.eventId));\n let ok = false;\n let retry = true;\n try {\n const res = await this.opts.send(batch);\n ok = res.ok;\n retry = res.retry ?? !res.ok;\n } catch (err) {\n this.opts.onError?.(err);\n }\n this.inflight = false;\n this.inflightIds.clear();\n if (this.destroyed) return;\n if (ok || !retry) {\n const ids = new Set(batch.map((e) => e.eventId));\n this.events = this.events.filter((e) => !ids.has(e.eventId));\n this.attempt = 0;\n this.persist();\n if (this.events.length) this.schedule();\n return;\n }\n this.attempt += 1;\n if (this.attempt >= this.maxAttempts) {\n // Give up for now; events stay queued until the next flush trigger (navigation, timer, unload).\n this.attempt = 0;\n return;\n }\n this.retryTimer = setTimeout(() => {\n this.retryTimer = null;\n void this.flush();\n }, backoffMs(this.attempt - 1));\n }\n\n /** Best-effort synchronous flush on unload using `sendBeacon`. */\n flushSync(): void {\n if (this.destroyed || !this.opts.enabled() || !this.opts.beacon) return;\n // Events already in flight (fetch with keepalive) survive unload; only beacon the rest to avoid duplicate batches.\n const batch = this.events.filter((e) => !this.inflightIds.has(e.eventId)).slice(0, this.batchSize);\n if (!batch.length) return;\n if (this.opts.beacon(batch)) {\n const ids = new Set(batch.map((e) => e.eventId));\n this.events = this.events.filter((e) => !ids.has(e.eventId));\n this.persist();\n }\n }\n\n clear(): void {\n this.events = [];\n this.persist();\n }\n\n destroy(): void {\n this.destroyed = true;\n if (this.timer) clearTimeout(this.timer);\n if (this.retryTimer) clearTimeout(this.retryTimer);\n this.timer = null;\n this.retryTimer = null;\n this.persist();\n }\n}\n","type AnyFn = (...args: any[]) => void;\n\n/** Tiny typed event emitter. Listener errors are reported, never thrown into the caller. */\nexport class Emitter<Events extends { [K in keyof Events]: AnyFn }> {\n private listeners = new Map<keyof Events, Set<AnyFn>>();\n constructor(private readonly onError?: (err: unknown) => void) {}\n\n on<K extends keyof Events>(event: K, cb: Events[K]): () => void {\n let set = this.listeners.get(event);\n if (!set) {\n set = new Set();\n this.listeners.set(event, set);\n }\n set.add(cb);\n return () => this.off(event, cb);\n }\n\n off<K extends keyof Events>(event: K, cb: Events[K]): void {\n this.listeners.get(event)?.delete(cb);\n }\n\n emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): void {\n const set = this.listeners.get(event);\n if (!set) return;\n for (const cb of Array.from(set)) {\n try {\n cb(...args);\n } catch (err) {\n this.onError?.(err);\n }\n }\n }\n\n clear(): void {\n this.listeners.clear();\n }\n}\n","import type { FrequencyConfig, PublishedGuide } from \"@guidelytech/shared\";\n\n/** Per-guide state kept locally and merged with the server's `IdentifyResponse.guideState`. */\nexport interface GuideLocalState {\n impressions: number;\n completedAt?: string | null;\n dismissedAt?: string | null;\n lastShownAt?: string | null;\n}\n\nconst HOUR = 3600 * 1000;\n\n/**\n * Pure frequency evaluation. `shownThisSession` comes from session storage.\n * - `once`: a single impression ever (unless `reshowAfterDismiss` and it was only dismissed).\n * - `once_per_session`: at most once per browser session.\n * - `every_time`: on every trigger (still blocked by completion/dismissal rules below).\n * - `interval`: at most once every `intervalHours`.\n * `maxImpressions` caps total impressions; dismissal blocks re-showing unless `reshowAfterDismiss`\n * (then `cooldownHours` must have elapsed); completion blocks unless mode is `every_time`.\n */\nexport function isFrequencyEligible(freq: FrequencyConfig, state: GuideLocalState | undefined, shownThisSession: boolean, now: number = Date.now()): boolean {\n const s = state ?? { impressions: 0 };\n if (freq.maxImpressions != null && s.impressions >= freq.maxImpressions) return false;\n if (s.completedAt && freq.mode !== \"every_time\") return false;\n if (s.dismissedAt) {\n if (!freq.reshowAfterDismiss) return false;\n if (freq.cooldownHours > 0 && now - Date.parse(s.dismissedAt) < freq.cooldownHours * HOUR) return false;\n }\n switch (freq.mode) {\n case \"once\":\n return s.impressions === 0 || (!!s.dismissedAt && freq.reshowAfterDismiss);\n case \"once_per_session\":\n return !shownThisSession;\n case \"interval\": {\n if (!s.lastShownAt) return true;\n const hours = freq.intervalHours ?? 24;\n return now - Date.parse(s.lastShownAt) >= hours * HOUR;\n }\n case \"every_time\":\n default:\n return true;\n }\n}\n\n/**\n * Exclusive guides (flows, modals, tooltips, announcements, surveys) run one at a time.\n * Banners, checklists and hotspot-only tooltips can coexist with an active flow.\n */\nexport function isExclusiveGuide(guide: PublishedGuide): boolean {\n if (guide.kind === \"banner\" || guide.kind === \"checklist\") return false;\n const steps = guide.config.steps;\n if (steps.length > 0 && steps.every((s) => s.type === \"hotspot\" || s.type === \"banner\")) return false;\n return true;\n}\n\n/** Is `a` mutually exclusive with `b` (by id or key, in either direction)? */\nexport function areMutuallyExclusive(a: PublishedGuide, b: PublishedGuide): boolean {\n const la = a.config.frequency.mutuallyExclusiveWith;\n const lb = b.config.frequency.mutuallyExclusiveWith;\n return la.includes(b.id) || la.includes(b.key) || lb.includes(a.id) || lb.includes(a.key);\n}\n\n/** Survey scheduling window. */\nexport function isWithinSchedule(guide: PublishedGuide, now: number = Date.now()): boolean {\n const s = guide.config.survey;\n if (!s) return true;\n if (s.startAt && now < Date.parse(s.startAt)) return false;\n if (s.endAt && now > Date.parse(s.endAt)) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,IAAM,MAAN,MAAU;AAAA,EACf,YACmB,SACA,KACA,WACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAEH,IAAI,MAAc,SAA6C,CAAC,GAAW;AAEzE,UAAM,QAAQ,OAAO,QAAQ,EAAE,KAAK,KAAK,KAAK,GAAG,OAAO,CAAC,EACtD,OAAO,CAAC,MAA6B,EAAE,CAAC,KAAK,IAAI,EACjD,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,EAAE,EACnE,KAAK,GAAG;AACX,WAAO,GAAG,KAAK,QAAQ,QAAQ,OAAO,EAAE,CAAC,cAAc,IAAI,IAAI,KAAK;AAAA,EACtE;AAAA,EAEA,IAAY,UAA4B;AACtC,QAAI,KAAK,UAAW,QAAO,KAAK;AAChC,WAAO,OAAO,UAAU,aAAa,MAAM,KAAK,UAAU,IAAI;AAAA,EAChE;AAAA,EAEA,MAAM,QAAW,QAAwB,MAAc,UAA4K,CAAC,GAA4B;AAC9P,UAAM,IAAI,KAAK;AACf,QAAI,CAAC,EAAG,OAAM,IAAI,MAAM,wBAAwB;AAChD,UAAM,UAAkC,EAAE,GAAG,QAAQ,SAAS,iBAAiB,KAAK,KAAK,QAAQ,mBAAmB;AACpH,QAAI,QAAQ,SAAS,OAAW,SAAQ,cAAc,IAAI;AAC1D,QAAI,QAAQ,KAAM,SAAQ,e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B,GAAmB,GAA4B;AAClF,QAAM,KAAK,EAAE,OAAO,UAAU;AAC9B,QAAM,KAAK,EAAE,OAAO,UAAU;AAC9B,SAAO,GAAG,SAAS,EAAE,EAAE,KAAK,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,SAAS,EAAE,EAAE,KAAK,GAAG,SAAS,EAAE,GAAG;AAC1F;AAGO,SAAS,iBAAiB,OAAuB,MAAc,KAAK,IAAI,GAAY;AACzF,QAAM,IAAI,MAAM,OAAO;AACvB,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,EAAE,WAAW,MAAM,KAAK,MAAM,EAAE,OAAO,EAAG,QAAO;AACrD,MAAI,EAAE,SAAS,MAAM,KAAK,MAAM,EAAE,KAAK,EAAG,QAAO;AACjD,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/headless.ts","../src/http.ts","../src/storage.ts","../src/queue.ts","../src/emitter.ts","../src/frequency.ts"],"sourcesContent":["/**\n * `@guidelytech/sdk-core/headless` — the DOM-free building blocks of the SDK (HTTP client, event\n * queue, frequency rules, emitter, key/value storage helpers). Used by the React Native SDK, which\n * renders guides natively instead of through `@guidelytech/guide-runtime`.\n */\nexport { Api, postWithRetry, backoffMs, sleep } from \"./http\";\nexport type { ApiResponse, FetchLike } from \"./http\";\nexport { EventQueue } from \"./queue\";\nexport type { EventQueueOptions } from \"./queue\";\nexport { Emitter } from \"./emitter\";\nexport { isFrequencyEligible, isExclusiveGuide, areMutuallyExclusive, isWithinSchedule } from \"./frequency\";\nexport type { GuideLocalState } from \"./frequency\";\nexport { memoryStore, readJson, writeJson, KEYS } from \"./storage\";\nexport type { KeyValueStore } from \"./storage\";\nexport type { ChecklistProgressState, PersistedState, SessionState, ConsentState, GuidelyAccount, GuidelyUser, GuidelyEnvironment } from \"./types\";\n","export interface ApiResponse<T> {\n status: number;\n ok: boolean;\n data: T | null;\n etag: string | null;\n}\n\nexport type FetchLike = typeof fetch;\n\n/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */\nexport class Api {\n constructor(\n private readonly baseUrl: string,\n private readonly key: string,\n private readonly fetchImpl?: FetchLike,\n ) {}\n\n url(path: string, params: Record<string, string | undefined> = {}): string {\n // Built by hand rather than with URL/searchParams, which React Native does not implement.\n const query = Object.entries({ key: this.key, ...params })\n .filter((e): e is [string, string] => e[1] != null)\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n return `${this.baseUrl.replace(/\\/$/, \"\")}/api/v1/sdk${path}?${query}`;\n }\n\n private get fetcher(): FetchLike | null {\n if (this.fetchImpl) return this.fetchImpl;\n return typeof fetch === \"function\" ? fetch.bind(globalThis) : null;\n }\n\n async request<T>(method: \"GET\" | \"POST\", path: string, options: { body?: unknown; etag?: string | null; params?: Record<string, string | undefined>; keepalive?: boolean; timeoutMs?: number; headers?: Record<string, string> } = {}): Promise<ApiResponse<T>> {\n const f = this.fetcher;\n if (!f) throw new Error(\"fetch is not available\");\n const headers: Record<string, string> = { ...options.headers, \"X-Guidely-Key\": this.key, Accept: \"application/json\" };\n // Multipart bodies set their own Content-Type (with the boundary).\n const form = typeof FormData !== \"undefined\" && options.body instanceof FormData;\n if (options.body !== undefined && !form) headers[\"Content-Type\"] = \"application/json\";\n if (options.etag) headers[\"If-None-Match\"] = options.etag;\n const ac = typeof AbortController !== \"undefined\" ? new AbortController() : null;\n const timer = ac ? setTimeout(() => ac.abort(), options.timeoutMs ?? 10000) : null;\n try {\n const res = await f(this.url(path, options.params), {\n method,\n headers,\n body: options.body === undefined ? undefined : form ? (options.body as FormData) : JSON.stringify(options.body),\n keepalive: options.keepalive,\n signal: ac?.signal,\n credentials: \"omit\",\n mode: \"cors\",\n });\n let data: T | null = null;\n if (res.status !== 304 && res.status !== 204) {\n try {\n data = (await res.json()) as T;\n } catch {\n data = null;\n }\n }\n return { status: res.status, ok: res.ok, data, etag: res.headers?.get?.(\"etag\") ?? null };\n } finally {\n if (timer) clearTimeout(timer);\n }\n }\n\n get<T>(path: string, options?: { etag?: string | null; params?: Record<string, string | undefined>; headers?: Record<string, string> }): Promise<ApiResponse<T>> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body: unknown, options?: { params?: Record<string, string | undefined>; keepalive?: boolean; headers?: Record<string, string> }): Promise<ApiResponse<T>> {\n return this.request<T>(\"POST\", path, { body, ...options });\n }\n\n /** Multipart POST (file uploads). No Content-Type header: the browser adds it with the boundary. */\n postForm<T>(path: string, form: FormData, options?: { params?: Record<string, string | undefined>; timeoutMs?: number }): Promise<ApiResponse<T>> {\n return this.request<T>(\"POST\", path, { body: form, ...options });\n }\n\n /**\n * POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is\n * returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.\n */\n async stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers: Record<string, string> = {}): Promise<ApiResponse<T>> {\n const f = this.fetcher;\n if (!f) throw new Error(\"fetch is not available\");\n const res = await f(this.url(path), {\n method: \"POST\",\n headers: { ...headers, \"X-Guidely-Key\": this.key, Accept: \"text/event-stream, application/json\", \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n credentials: \"omit\",\n mode: \"cors\",\n });\n const type = res.headers?.get?.(\"content-type\") ?? \"\";\n if (!type.includes(\"text/event-stream\") || !res.body) {\n let data: T | null = null;\n try {\n data = (await res.json()) as T;\n } catch {\n data = null;\n }\n return { status: res.status, ok: res.ok, data, etag: null };\n }\n await readEventStream(res.body, onEvent);\n return { status: res.status, ok: res.ok, data: null, etag: null };\n }\n\n /** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */\n beacon(path: string, body: unknown): boolean {\n try {\n if (typeof navigator === \"undefined\" || typeof navigator.sendBeacon !== \"function\") return false;\n // text/plain is a CORS-safelisted type: cross-origin beacons need no preflight (which\n // browsers drop during unload). The API parses the body regardless of content type.\n const blob = new Blob([JSON.stringify(body)], { type: \"text/plain;charset=UTF-8\" });\n return navigator.sendBeacon(this.url(path), blob);\n } catch {\n return false;\n }\n }\n}\n\nexport const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));\n\n/** Exponential backoff helper: 1s → 2s → 4s … capped. */\nexport function backoffMs(attempt: number, baseMs = 1000, maxMs = 30000): number {\n return Math.min(maxMs, baseMs * 2 ** Math.max(0, attempt));\n}\n\n/**\n * Sends with bounded retries: network errors, 429 and 5xx are retried with backoff; success and\n * other 4xx answers are returned as they are. Null when every attempt failed.\n */\nexport async function withRetry<T>(send: () => Promise<ApiResponse<T>>, attempts = 3, baseMs = 500): Promise<ApiResponse<T> | null> {\n for (let i = 0; i < attempts; i++) {\n try {\n const res = await send();\n if (res.ok || (res.status >= 400 && res.status < 500 && res.status !== 429)) return res;\n } catch {\n /* network error → retry */\n }\n if (i < attempts - 1) await sleep(backoffMs(i, baseMs, 8000));\n }\n return null;\n}\n\n/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */\nexport function postWithRetry<T>(api: Api, path: string, body: unknown, attempts = 3, baseMs = 500): Promise<ApiResponse<T> | null> {\n return withRetry(() => api.post<T>(path, body), attempts, baseMs);\n}\n\n/** Parses a `text/event-stream` body (`event:` + single-line JSON `data:`; comment lines ignored). */\nexport async function readEventStream(body: ReadableStream<Uint8Array>, onEvent: (event: string, data: unknown) => void): Promise<void> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n const dispatch = (raw: string) => {\n let event = \"message\";\n const data: string[] = [];\n for (const line of raw.split(\"\\n\")) {\n if (!line || line.startsWith(\":\")) continue;\n const i = line.indexOf(\":\");\n const field = i < 0 ? line : line.slice(0, i);\n const value = i < 0 ? \"\" : line.slice(i + 1).replace(/^ /, \"\");\n if (field === \"event\") event = value;\n else if (field === \"data\") data.push(value);\n }\n if (!data.length) return;\n try {\n onEvent(event, JSON.parse(data.join(\"\\n\")));\n } catch {\n /* ignore malformed events */\n }\n };\n for (;;) {\n const { done, value } = await reader.read();\n if (value) buffer += decoder.decode(value, { stream: true }).replace(/\\r\\n?/g, \"\\n\");\n let sep: number;\n while ((sep = buffer.indexOf(\"\\n\\n\")) >= 0) {\n dispatch(buffer.slice(0, sep));\n buffer = buffer.slice(sep + 2);\n }\n if (done) break;\n }\n if (buffer.trim()) dispatch(buffer);\n}\n","export type StorageKind = \"local\" | \"session\" | \"memory\";\n\n/** Minimal synchronous key/value store; never throws (private mode, quota, SSR). */\nexport interface KeyValueStore {\n get(key: string): string | null;\n set(key: string, value: string): void;\n remove(key: string): void;\n}\n\nexport function memoryStore(): KeyValueStore {\n const map = new Map<string, string>();\n return { get: (k) => map.get(k) ?? null, set: (k, v) => void map.set(k, v), remove: (k) => void map.delete(k) };\n}\n\nfunction webStore(area: \"localStorage\" | \"sessionStorage\"): KeyValueStore | null {\n try {\n if (typeof window === \"undefined\") return null;\n const s = window[area];\n if (!s) return null;\n const probe = \"__guidely_probe__\";\n s.setItem(probe, \"1\");\n s.removeItem(probe);\n return {\n get: (k) => {\n try {\n return s.getItem(k);\n } catch {\n return null;\n }\n },\n set: (k, v) => {\n try {\n s.setItem(k, v);\n } catch {\n /* quota / private mode */\n }\n },\n remove: (k) => {\n try {\n s.removeItem(k);\n } catch {\n /* ignore */\n }\n },\n };\n } catch {\n return null;\n }\n}\n\n/** Creates a store of the requested kind, degrading to memory when unavailable. */\nexport function createStorage(kind: StorageKind = \"local\"): KeyValueStore {\n if (kind === \"memory\") return memoryStore();\n return webStore(kind === \"local\" ? \"localStorage\" : \"sessionStorage\") ?? memoryStore();\n}\n\nexport function readJson<T>(store: KeyValueStore, key: string, fallback: T): T {\n const raw = store.get(key);\n if (raw == null) return fallback;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n}\n\nexport function writeJson(store: KeyValueStore, key: string, value: unknown): void {\n try {\n store.set(key, JSON.stringify(value));\n } catch {\n /* ignore */\n }\n}\n\n/** Storage keys used by the SDK (documented for integrators). */\nexport const KEYS = {\n anon: \"guidely:anon\",\n seen: \"guidely:seen\",\n config: (key: string) => `guidely:config:${key}`,\n etag: (key: string) => `guidely:etag:${key}`,\n state: (key: string) => `guidely:state:${key}`,\n user: (key: string) => `guidely:user:${key}`,\n queue: (key: string) => `guidely:queue:${key}`,\n session: \"guidely:session\",\n active: \"guidely:active\",\n authoring: \"guidely:authoring\",\n /** How-to capture session marker ({ token, … }) and its not-yet-uploaded steps. */\n capture: \"guidely:capture\",\n capturePending: \"guidely:capture:pending\",\n /** Messenger conversations this browser can read: [{ id, token }]. */\n conversations: (key: string) => `guidely:conversations:${key}`,\n /** Announcement ids opened in the messenger's News tab. */\n newsSeen: (key: string) => `guidely:news:${key}`,\n} as const;\n","import type { SdkEvent } from \"@guidelytech/shared\";\nimport { backoffMs } from \"./http\";\nimport { readJson, writeJson, type KeyValueStore } from \"./storage\";\n\nexport interface EventQueueOptions {\n store: KeyValueStore;\n storageKey: string;\n /** Sends one batch. Resolve `{ ok: true }` on success, `{ ok: false, retry }` otherwise. */\n send: (events: SdkEvent[]) => Promise<{ ok: boolean; retry?: boolean }>;\n /** Synchronous best-effort send used on page hide. */\n beacon?: (events: SdkEvent[]) => boolean;\n /** Should events be flushed right now? (analytics enabled + consent granted). */\n enabled: () => boolean;\n flushIntervalMs?: number;\n maxQueue?: number;\n batchSize?: number;\n maxAttempts?: number;\n onError?: (err: unknown) => void;\n}\n\n/**\n * Bounded, persisted event queue. Batches ≤50 events every 2s (or on demand), dedupes by\n * `eventId`, retries with exponential backoff (1s→30s, 5 attempts) and keeps failed events for\n * the next flush. Drops the oldest events once the queue exceeds 200.\n */\nexport class EventQueue {\n private events: SdkEvent[] = [];\n private timer: ReturnType<typeof setTimeout> | null = null;\n private retryTimer: ReturnType<typeof setTimeout> | null = null;\n private inflight = false;\n private inflightIds = new Set<string>();\n private attempt = 0;\n private destroyed = false;\n private readonly flushIntervalMs: number;\n private readonly maxQueue: number;\n private readonly batchSize: number;\n private readonly maxAttempts: number;\n\n constructor(private readonly opts: EventQueueOptions) {\n this.flushIntervalMs = opts.flushIntervalMs ?? 2000;\n this.maxQueue = opts.maxQueue ?? 200;\n this.batchSize = opts.batchSize ?? 50;\n this.maxAttempts = opts.maxAttempts ?? 5;\n const persisted = readJson<SdkEvent[]>(opts.store, opts.storageKey, []);\n if (Array.isArray(persisted)) this.events = persisted.filter((e) => e && typeof e.eventId === \"string\").slice(-this.maxQueue);\n // Events left over from a previous page load are flushed on the next tick.\n if (this.events.length) this.schedule();\n }\n\n get size(): number {\n return this.events.length;\n }\n\n /** Pending events (read-only copy, for debugging). */\n peek(): SdkEvent[] {\n return this.events.slice();\n }\n\n enqueue(event: SdkEvent): void {\n if (this.destroyed) return;\n if (this.events.some((e) => e.eventId === event.eventId)) return;\n this.events.push(event);\n if (this.events.length > this.maxQueue) this.events.splice(0, this.events.length - this.maxQueue);\n this.persist();\n this.schedule();\n }\n\n private persist(): void {\n writeJson(this.opts.store, this.opts.storageKey, this.events);\n }\n\n private schedule(): void {\n if (this.timer || this.retryTimer || this.destroyed) return;\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.flush();\n }, this.flushIntervalMs);\n }\n\n /** Sends queued events now (one batch at a time). Safe to call at any time. */\n async flush(): Promise<void> {\n if (this.destroyed || this.inflight || !this.events.length || !this.opts.enabled()) return;\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n this.inflight = true;\n const batch = this.events.slice(0, this.batchSize);\n this.inflightIds = new Set(batch.map((e) => e.eventId));\n let ok = false;\n let retry = true;\n try {\n const res = await this.opts.send(batch);\n ok = res.ok;\n retry = res.retry ?? !res.ok;\n } catch (err) {\n this.opts.onError?.(err);\n }\n this.inflight = false;\n this.inflightIds.clear();\n if (this.destroyed) return;\n if (ok || !retry) {\n const ids = new Set(batch.map((e) => e.eventId));\n this.events = this.events.filter((e) => !ids.has(e.eventId));\n this.attempt = 0;\n this.persist();\n if (this.events.length) this.schedule();\n return;\n }\n this.attempt += 1;\n if (this.attempt >= this.maxAttempts) {\n // Give up for now; events stay queued until the next flush trigger (navigation, timer, unload).\n this.attempt = 0;\n return;\n }\n this.retryTimer = setTimeout(() => {\n this.retryTimer = null;\n void this.flush();\n }, backoffMs(this.attempt - 1));\n }\n\n /** Best-effort synchronous flush on unload using `sendBeacon`. */\n flushSync(): void {\n if (this.destroyed || !this.opts.enabled() || !this.opts.beacon) return;\n // Events already in flight (fetch with keepalive) survive unload; only beacon the rest to avoid duplicate batches.\n const batch = this.events.filter((e) => !this.inflightIds.has(e.eventId)).slice(0, this.batchSize);\n if (!batch.length) return;\n if (this.opts.beacon(batch)) {\n const ids = new Set(batch.map((e) => e.eventId));\n this.events = this.events.filter((e) => !ids.has(e.eventId));\n this.persist();\n }\n }\n\n clear(): void {\n this.events = [];\n this.persist();\n }\n\n destroy(): void {\n this.destroyed = true;\n if (this.timer) clearTimeout(this.timer);\n if (this.retryTimer) clearTimeout(this.retryTimer);\n this.timer = null;\n this.retryTimer = null;\n this.persist();\n }\n}\n","type AnyFn = (...args: any[]) => void;\n\n/** Tiny typed event emitter. Listener errors are reported, never thrown into the caller. */\nexport class Emitter<Events extends { [K in keyof Events]: AnyFn }> {\n private listeners = new Map<keyof Events, Set<AnyFn>>();\n constructor(private readonly onError?: (err: unknown) => void) {}\n\n on<K extends keyof Events>(event: K, cb: Events[K]): () => void {\n let set = this.listeners.get(event);\n if (!set) {\n set = new Set();\n this.listeners.set(event, set);\n }\n set.add(cb);\n return () => this.off(event, cb);\n }\n\n off<K extends keyof Events>(event: K, cb: Events[K]): void {\n this.listeners.get(event)?.delete(cb);\n }\n\n emit<K extends keyof Events>(event: K, ...args: Parameters<Events[K]>): void {\n const set = this.listeners.get(event);\n if (!set) return;\n for (const cb of Array.from(set)) {\n try {\n cb(...args);\n } catch (err) {\n this.onError?.(err);\n }\n }\n }\n\n clear(): void {\n this.listeners.clear();\n }\n}\n","import type { FrequencyConfig, PublishedGuide } from \"@guidelytech/shared\";\n\n/** Per-guide state kept locally and merged with the server's `IdentifyResponse.guideState`. */\nexport interface GuideLocalState {\n impressions: number;\n completedAt?: string | null;\n dismissedAt?: string | null;\n lastShownAt?: string | null;\n /** Last step reached in a multi-step flow (local only), so the messenger can offer to resume it. */\n lastStepId?: string | null;\n}\n\nconst HOUR = 3600 * 1000;\n\n/**\n * Pure frequency evaluation. `shownThisSession` comes from session storage.\n * - `once`: a single impression ever (unless `reshowAfterDismiss` and it was only dismissed).\n * - `once_per_session`: at most once per browser session.\n * - `every_time`: on every trigger (still blocked by completion/dismissal rules below).\n * - `interval`: at most once every `intervalHours`.\n * `maxImpressions` caps total impressions; dismissal blocks re-showing unless `reshowAfterDismiss`\n * (then `cooldownHours` must have elapsed); completion blocks unless mode is `every_time`.\n */\nexport function isFrequencyEligible(freq: FrequencyConfig, state: GuideLocalState | undefined, shownThisSession: boolean, now: number = Date.now()): boolean {\n const s = state ?? { impressions: 0 };\n if (freq.maxImpressions != null && s.impressions >= freq.maxImpressions) return false;\n if (s.completedAt && freq.mode !== \"every_time\") return false;\n if (s.dismissedAt) {\n if (!freq.reshowAfterDismiss) return false;\n if (freq.cooldownHours > 0 && now - Date.parse(s.dismissedAt) < freq.cooldownHours * HOUR) return false;\n }\n switch (freq.mode) {\n case \"once\":\n return s.impressions === 0 || (!!s.dismissedAt && freq.reshowAfterDismiss);\n case \"once_per_session\":\n return !shownThisSession;\n case \"interval\": {\n if (!s.lastShownAt) return true;\n const hours = freq.intervalHours ?? 24;\n return now - Date.parse(s.lastShownAt) >= hours * HOUR;\n }\n case \"every_time\":\n default:\n return true;\n }\n}\n\n/**\n * Exclusive guides (flows, modals, tooltips, announcements, surveys) run one at a time.\n * Banners, checklists and hotspot-only tooltips can coexist with an active flow.\n */\nexport function isExclusiveGuide(guide: PublishedGuide): boolean {\n if (guide.kind === \"banner\" || guide.kind === \"checklist\") return false;\n const steps = guide.config.steps;\n if (steps.length > 0 && steps.every((s) => s.type === \"hotspot\" || s.type === \"banner\")) return false;\n return true;\n}\n\n/** Is `a` mutually exclusive with `b` (by id or key, in either direction)? */\nexport function areMutuallyExclusive(a: PublishedGuide, b: PublishedGuide): boolean {\n const la = a.config.frequency.mutuallyExclusiveWith;\n const lb = b.config.frequency.mutuallyExclusiveWith;\n return la.includes(b.id) || la.includes(b.key) || lb.includes(a.id) || lb.includes(a.key);\n}\n\n/** Survey scheduling window. */\nexport function isWithinSchedule(guide: PublishedGuide, now: number = Date.now()): boolean {\n const s = guide.config.survey;\n if (!s) return true;\n if (s.startAt && now < Date.parse(s.startAt)) return false;\n if (s.endAt && now > Date.parse(s.endAt)) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,IAAM,MAAN,MAAU;AAAA,EACf,YACmB,SACA,KACA,WACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAEH,IAAI,MAAc,SAA6C,CAAC,GAAW;AAEzE,UAAM,QAAQ,OAAO,QAAQ,EAAE,KAAK,KAAK,KAAK,GAAG,OAAO,CAAC,EACtD,OAAO,CAAC,MAA6B,EAAE,CAAC,KAAK,IAAI,EACjD,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,EAAE,EACnE,KAAK,GAAG;AACX,WAAO,GAAG,KAAK,QAAQ,QAAQ,OAAO,EAAE,CAAC,cAAc,IAAI,IAAI,KAAK;AAAA,EACtE;AAAA,EAEA,IAAY,UAA4B;AACtC,QAAI,KAAK,UAAW,QAAO,KAAK;AAChC,WAAO,OAAO,UAAU,aAAa,MAAM,KAAK,UAAU,IAAI;AAAA,EAChE;AAAA,EAEA,MAAM,QAAW,QAAwB,MAAc,UAA4K,CAAC,GAA4B;AAC9P,UAAM,IAAI,KAAK;AACf,QAAI,CAAC,EAAG,OAAM,IAAI,MAAM,wBAAwB;AAChD,UAAM,UAAkC,EAAE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,aAAO,EAAE,gBAAgB,KAAM,CAAC,CAAC,EAAE,eAAe,KAAK;AAAA,IACzD,KAAK;AACH,aAAO,CAAC;AAAA,IACV,KAAK,YAAY;AACf,UAAI,CAAC,EAAE,YAAa,QAAO;AAC3B,YAAM,QAAQ,KAAK,iBAAiB;AACpC,aAAO,MAAM,KAAK,MAAM,EAAE,WAAW,KAAK,QAAQ;AAAA,IACpD;AAAA,IACA,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAMO,SAAS,iBAAiB,OAAgC;AAC/D,MAAI,MAAM,SAAS,YAAY,MAAM,SAAS,YAAa,QAAO;AAClE,QAAM,QAAQ,MAAM,OAAO;AAC3B,MAAI,MAAM,SAAS,KAAK,MAAM,MAAM,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,SAAS,QAAQ,EAAG,QAAO;AAChG,SAAO;AACT;AAGO,SAAS,qBAAqB,GAAmB,GAA4B;AAClF,QAAM,KAAK,EAAE,OAAO,UAAU;AAC9B,QAAM,KAAK,EAAE,OAAO,UAAU;AAC9B,SAAO,GAAG,SAAS,EAAE,EAAE,KAAK,GAAG,SAAS,EAAE,GAAG,KAAK,GAAG,SAAS,EAAE,EAAE,KAAK,GAAG,SAAS,EAAE,GAAG;AAC1F;AAGO,SAAS,iBAAiB,OAAuB,MAAc,KAAK,IAAI,GAAY;AACzF,QAAM,IAAI,MAAM,OAAO;AACvB,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,EAAE,WAAW,MAAM,KAAK,MAAM,EAAE,OAAO,EAAG,QAAO;AACrD,MAAI,EAAE,SAAS,MAAM,KAAK,MAAM,EAAE,KAAK,EAAG,QAAO;AACjD,SAAO;AACT;","names":[]}
|
package/dist/headless.d.cts
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as Api, a as ApiResponse, F as FetchLike, K as KEYS, b as KeyValueStore, c as backoffMs, m as memoryStore, p as postWithRetry, r as readJson, s as sleep, w as writeJson } from './http-47tiAlOM.cjs';
|
|
2
|
+
export { C as ChecklistProgressState, a as ConsentState, E as EventQueue, b as EventQueueOptions, G as GuideLocalState, c as GuidelyAccount, d as GuidelyEnvironment, e as GuidelyUser, P as PersistedState, S as SessionState, f as areMutuallyExclusive, i as isExclusiveGuide, g as isFrequencyEligible, h as isWithinSchedule } from './types-d4eOerxi.cjs';
|
|
2
3
|
import '@guidelytech/shared';
|
|
3
4
|
|
|
4
|
-
interface ApiResponse<T> {
|
|
5
|
-
status: number;
|
|
6
|
-
ok: boolean;
|
|
7
|
-
data: T | null;
|
|
8
|
-
etag: string | null;
|
|
9
|
-
}
|
|
10
|
-
type FetchLike = typeof fetch;
|
|
11
|
-
/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */
|
|
12
|
-
declare class Api {
|
|
13
|
-
private readonly baseUrl;
|
|
14
|
-
private readonly key;
|
|
15
|
-
private readonly fetchImpl?;
|
|
16
|
-
constructor(baseUrl: string, key: string, fetchImpl?: FetchLike | undefined);
|
|
17
|
-
url(path: string, params?: Record<string, string | undefined>): string;
|
|
18
|
-
private get fetcher();
|
|
19
|
-
request<T>(method: "GET" | "POST", path: string, options?: {
|
|
20
|
-
body?: unknown;
|
|
21
|
-
etag?: string | null;
|
|
22
|
-
params?: Record<string, string | undefined>;
|
|
23
|
-
keepalive?: boolean;
|
|
24
|
-
timeoutMs?: number;
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
}): Promise<ApiResponse<T>>;
|
|
27
|
-
get<T>(path: string, options?: {
|
|
28
|
-
etag?: string | null;
|
|
29
|
-
params?: Record<string, string | undefined>;
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
}): Promise<ApiResponse<T>>;
|
|
32
|
-
post<T>(path: string, body: unknown, options?: {
|
|
33
|
-
params?: Record<string, string | undefined>;
|
|
34
|
-
keepalive?: boolean;
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
}): Promise<ApiResponse<T>>;
|
|
37
|
-
/**
|
|
38
|
-
* POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is
|
|
39
|
-
* returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.
|
|
40
|
-
*/
|
|
41
|
-
stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
42
|
-
/** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */
|
|
43
|
-
beacon(path: string, body: unknown): boolean;
|
|
44
|
-
}
|
|
45
|
-
declare const sleep: (ms: number) => Promise<void>;
|
|
46
|
-
/** Exponential backoff helper: 1s → 2s → 4s … capped. */
|
|
47
|
-
declare function backoffMs(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
48
|
-
/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */
|
|
49
|
-
declare function postWithRetry<T>(api: Api, path: string, body: unknown, attempts?: number, baseMs?: number): Promise<ApiResponse<T> | null>;
|
|
50
|
-
|
|
51
5
|
type AnyFn = (...args: any[]) => void;
|
|
52
6
|
/** Tiny typed event emitter. Listener errors are reported, never thrown into the caller. */
|
|
53
7
|
declare class Emitter<Events extends {
|
|
@@ -62,4 +16,4 @@ declare class Emitter<Events extends {
|
|
|
62
16
|
clear(): void;
|
|
63
17
|
}
|
|
64
18
|
|
|
65
|
-
export {
|
|
19
|
+
export { Emitter };
|
package/dist/headless.d.ts
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as Api, a as ApiResponse, F as FetchLike, K as KEYS, b as KeyValueStore, c as backoffMs, m as memoryStore, p as postWithRetry, r as readJson, s as sleep, w as writeJson } from './http-47tiAlOM.js';
|
|
2
|
+
export { C as ChecklistProgressState, a as ConsentState, E as EventQueue, b as EventQueueOptions, G as GuideLocalState, c as GuidelyAccount, d as GuidelyEnvironment, e as GuidelyUser, P as PersistedState, S as SessionState, f as areMutuallyExclusive, i as isExclusiveGuide, g as isFrequencyEligible, h as isWithinSchedule } from './types-RyeRQd9f.js';
|
|
2
3
|
import '@guidelytech/shared';
|
|
3
4
|
|
|
4
|
-
interface ApiResponse<T> {
|
|
5
|
-
status: number;
|
|
6
|
-
ok: boolean;
|
|
7
|
-
data: T | null;
|
|
8
|
-
etag: string | null;
|
|
9
|
-
}
|
|
10
|
-
type FetchLike = typeof fetch;
|
|
11
|
-
/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */
|
|
12
|
-
declare class Api {
|
|
13
|
-
private readonly baseUrl;
|
|
14
|
-
private readonly key;
|
|
15
|
-
private readonly fetchImpl?;
|
|
16
|
-
constructor(baseUrl: string, key: string, fetchImpl?: FetchLike | undefined);
|
|
17
|
-
url(path: string, params?: Record<string, string | undefined>): string;
|
|
18
|
-
private get fetcher();
|
|
19
|
-
request<T>(method: "GET" | "POST", path: string, options?: {
|
|
20
|
-
body?: unknown;
|
|
21
|
-
etag?: string | null;
|
|
22
|
-
params?: Record<string, string | undefined>;
|
|
23
|
-
keepalive?: boolean;
|
|
24
|
-
timeoutMs?: number;
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
}): Promise<ApiResponse<T>>;
|
|
27
|
-
get<T>(path: string, options?: {
|
|
28
|
-
etag?: string | null;
|
|
29
|
-
params?: Record<string, string | undefined>;
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
}): Promise<ApiResponse<T>>;
|
|
32
|
-
post<T>(path: string, body: unknown, options?: {
|
|
33
|
-
params?: Record<string, string | undefined>;
|
|
34
|
-
keepalive?: boolean;
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
}): Promise<ApiResponse<T>>;
|
|
37
|
-
/**
|
|
38
|
-
* POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is
|
|
39
|
-
* returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.
|
|
40
|
-
*/
|
|
41
|
-
stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
42
|
-
/** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */
|
|
43
|
-
beacon(path: string, body: unknown): boolean;
|
|
44
|
-
}
|
|
45
|
-
declare const sleep: (ms: number) => Promise<void>;
|
|
46
|
-
/** Exponential backoff helper: 1s → 2s → 4s … capped. */
|
|
47
|
-
declare function backoffMs(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
48
|
-
/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */
|
|
49
|
-
declare function postWithRetry<T>(api: Api, path: string, body: unknown, attempts?: number, baseMs?: number): Promise<ApiResponse<T> | null>;
|
|
50
|
-
|
|
51
5
|
type AnyFn = (...args: any[]) => void;
|
|
52
6
|
/** Tiny typed event emitter. Listener errors are reported, never thrown into the caller. */
|
|
53
7
|
declare class Emitter<Events extends {
|
|
@@ -62,4 +16,4 @@ declare class Emitter<Events extends {
|
|
|
62
16
|
clear(): void;
|
|
63
17
|
}
|
|
64
18
|
|
|
65
|
-
export {
|
|
19
|
+
export { Emitter };
|
package/dist/headless.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Emitter,
|
|
3
3
|
EventQueue,
|
|
4
|
-
KEYS,
|
|
5
4
|
areMutuallyExclusive,
|
|
6
5
|
isExclusiveGuide,
|
|
7
6
|
isFrequencyEligible,
|
|
8
|
-
isWithinSchedule
|
|
7
|
+
isWithinSchedule
|
|
8
|
+
} from "./chunk-GDF6RCHQ.js";
|
|
9
|
+
import {
|
|
10
|
+
KEYS,
|
|
9
11
|
memoryStore,
|
|
10
12
|
readJson,
|
|
11
13
|
writeJson
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-CYAG6ZYX.js";
|
|
13
15
|
import {
|
|
14
16
|
Api,
|
|
15
17
|
backoffMs,
|
|
16
18
|
postWithRetry,
|
|
17
19
|
sleep
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-AKNE7D5M.js";
|
|
19
21
|
export {
|
|
20
22
|
Api,
|
|
21
23
|
Emitter,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
type StorageKind = "local" | "session" | "memory";
|
|
2
|
+
/** Minimal synchronous key/value store; never throws (private mode, quota, SSR). */
|
|
3
|
+
interface KeyValueStore {
|
|
4
|
+
get(key: string): string | null;
|
|
5
|
+
set(key: string, value: string): void;
|
|
6
|
+
remove(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
declare function memoryStore(): KeyValueStore;
|
|
9
|
+
/** Creates a store of the requested kind, degrading to memory when unavailable. */
|
|
10
|
+
declare function createStorage(kind?: StorageKind): KeyValueStore;
|
|
11
|
+
declare function readJson<T>(store: KeyValueStore, key: string, fallback: T): T;
|
|
12
|
+
declare function writeJson(store: KeyValueStore, key: string, value: unknown): void;
|
|
13
|
+
/** Storage keys used by the SDK (documented for integrators). */
|
|
14
|
+
declare const KEYS: {
|
|
15
|
+
readonly anon: "guidely:anon";
|
|
16
|
+
readonly seen: "guidely:seen";
|
|
17
|
+
readonly config: (key: string) => string;
|
|
18
|
+
readonly etag: (key: string) => string;
|
|
19
|
+
readonly state: (key: string) => string;
|
|
20
|
+
readonly user: (key: string) => string;
|
|
21
|
+
readonly queue: (key: string) => string;
|
|
22
|
+
readonly session: "guidely:session";
|
|
23
|
+
readonly active: "guidely:active";
|
|
24
|
+
readonly authoring: "guidely:authoring";
|
|
25
|
+
/** How-to capture session marker ({ token, … }) and its not-yet-uploaded steps. */
|
|
26
|
+
readonly capture: "guidely:capture";
|
|
27
|
+
readonly capturePending: "guidely:capture:pending";
|
|
28
|
+
/** Messenger conversations this browser can read: [{ id, token }]. */
|
|
29
|
+
readonly conversations: (key: string) => string;
|
|
30
|
+
/** Announcement ids opened in the messenger's News tab. */
|
|
31
|
+
readonly newsSeen: (key: string) => string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface ApiResponse<T> {
|
|
35
|
+
status: number;
|
|
36
|
+
ok: boolean;
|
|
37
|
+
data: T | null;
|
|
38
|
+
etag: string | null;
|
|
39
|
+
}
|
|
40
|
+
type FetchLike = typeof fetch;
|
|
41
|
+
/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */
|
|
42
|
+
declare class Api {
|
|
43
|
+
private readonly baseUrl;
|
|
44
|
+
private readonly key;
|
|
45
|
+
private readonly fetchImpl?;
|
|
46
|
+
constructor(baseUrl: string, key: string, fetchImpl?: FetchLike | undefined);
|
|
47
|
+
url(path: string, params?: Record<string, string | undefined>): string;
|
|
48
|
+
private get fetcher();
|
|
49
|
+
request<T>(method: "GET" | "POST", path: string, options?: {
|
|
50
|
+
body?: unknown;
|
|
51
|
+
etag?: string | null;
|
|
52
|
+
params?: Record<string, string | undefined>;
|
|
53
|
+
keepalive?: boolean;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
}): Promise<ApiResponse<T>>;
|
|
57
|
+
get<T>(path: string, options?: {
|
|
58
|
+
etag?: string | null;
|
|
59
|
+
params?: Record<string, string | undefined>;
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
}): Promise<ApiResponse<T>>;
|
|
62
|
+
post<T>(path: string, body: unknown, options?: {
|
|
63
|
+
params?: Record<string, string | undefined>;
|
|
64
|
+
keepalive?: boolean;
|
|
65
|
+
headers?: Record<string, string>;
|
|
66
|
+
}): Promise<ApiResponse<T>>;
|
|
67
|
+
/** Multipart POST (file uploads). No Content-Type header: the browser adds it with the boundary. */
|
|
68
|
+
postForm<T>(path: string, form: FormData, options?: {
|
|
69
|
+
params?: Record<string, string | undefined>;
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
}): Promise<ApiResponse<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is
|
|
74
|
+
* returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.
|
|
75
|
+
*/
|
|
76
|
+
stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
77
|
+
/** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */
|
|
78
|
+
beacon(path: string, body: unknown): boolean;
|
|
79
|
+
}
|
|
80
|
+
declare const sleep: (ms: number) => Promise<void>;
|
|
81
|
+
/** Exponential backoff helper: 1s → 2s → 4s … capped. */
|
|
82
|
+
declare function backoffMs(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
83
|
+
/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */
|
|
84
|
+
declare function postWithRetry<T>(api: Api, path: string, body: unknown, attempts?: number, baseMs?: number): Promise<ApiResponse<T> | null>;
|
|
85
|
+
|
|
86
|
+
export { Api as A, type FetchLike as F, KEYS as K, type StorageKind as S, type ApiResponse as a, type KeyValueStore as b, backoffMs as c, createStorage as d, memoryStore as m, postWithRetry as p, readJson as r, sleep as s, writeJson as w };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
type StorageKind = "local" | "session" | "memory";
|
|
2
|
+
/** Minimal synchronous key/value store; never throws (private mode, quota, SSR). */
|
|
3
|
+
interface KeyValueStore {
|
|
4
|
+
get(key: string): string | null;
|
|
5
|
+
set(key: string, value: string): void;
|
|
6
|
+
remove(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
declare function memoryStore(): KeyValueStore;
|
|
9
|
+
/** Creates a store of the requested kind, degrading to memory when unavailable. */
|
|
10
|
+
declare function createStorage(kind?: StorageKind): KeyValueStore;
|
|
11
|
+
declare function readJson<T>(store: KeyValueStore, key: string, fallback: T): T;
|
|
12
|
+
declare function writeJson(store: KeyValueStore, key: string, value: unknown): void;
|
|
13
|
+
/** Storage keys used by the SDK (documented for integrators). */
|
|
14
|
+
declare const KEYS: {
|
|
15
|
+
readonly anon: "guidely:anon";
|
|
16
|
+
readonly seen: "guidely:seen";
|
|
17
|
+
readonly config: (key: string) => string;
|
|
18
|
+
readonly etag: (key: string) => string;
|
|
19
|
+
readonly state: (key: string) => string;
|
|
20
|
+
readonly user: (key: string) => string;
|
|
21
|
+
readonly queue: (key: string) => string;
|
|
22
|
+
readonly session: "guidely:session";
|
|
23
|
+
readonly active: "guidely:active";
|
|
24
|
+
readonly authoring: "guidely:authoring";
|
|
25
|
+
/** How-to capture session marker ({ token, … }) and its not-yet-uploaded steps. */
|
|
26
|
+
readonly capture: "guidely:capture";
|
|
27
|
+
readonly capturePending: "guidely:capture:pending";
|
|
28
|
+
/** Messenger conversations this browser can read: [{ id, token }]. */
|
|
29
|
+
readonly conversations: (key: string) => string;
|
|
30
|
+
/** Announcement ids opened in the messenger's News tab. */
|
|
31
|
+
readonly newsSeen: (key: string) => string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface ApiResponse<T> {
|
|
35
|
+
status: number;
|
|
36
|
+
ok: boolean;
|
|
37
|
+
data: T | null;
|
|
38
|
+
etag: string | null;
|
|
39
|
+
}
|
|
40
|
+
type FetchLike = typeof fetch;
|
|
41
|
+
/** Thin HTTP client for the public SDK API. Adds the public key as query + header. */
|
|
42
|
+
declare class Api {
|
|
43
|
+
private readonly baseUrl;
|
|
44
|
+
private readonly key;
|
|
45
|
+
private readonly fetchImpl?;
|
|
46
|
+
constructor(baseUrl: string, key: string, fetchImpl?: FetchLike | undefined);
|
|
47
|
+
url(path: string, params?: Record<string, string | undefined>): string;
|
|
48
|
+
private get fetcher();
|
|
49
|
+
request<T>(method: "GET" | "POST", path: string, options?: {
|
|
50
|
+
body?: unknown;
|
|
51
|
+
etag?: string | null;
|
|
52
|
+
params?: Record<string, string | undefined>;
|
|
53
|
+
keepalive?: boolean;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
}): Promise<ApiResponse<T>>;
|
|
57
|
+
get<T>(path: string, options?: {
|
|
58
|
+
etag?: string | null;
|
|
59
|
+
params?: Record<string, string | undefined>;
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
}): Promise<ApiResponse<T>>;
|
|
62
|
+
post<T>(path: string, body: unknown, options?: {
|
|
63
|
+
params?: Record<string, string | undefined>;
|
|
64
|
+
keepalive?: boolean;
|
|
65
|
+
headers?: Record<string, string>;
|
|
66
|
+
}): Promise<ApiResponse<T>>;
|
|
67
|
+
/** Multipart POST (file uploads). No Content-Type header: the browser adds it with the boundary. */
|
|
68
|
+
postForm<T>(path: string, form: FormData, options?: {
|
|
69
|
+
params?: Record<string, string | undefined>;
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
}): Promise<ApiResponse<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* POST that may answer with server-sent events. Each event is passed to `onEvent`; a JSON answer is
|
|
74
|
+
* returned instead. No timeout: Scout replies can take a while and the server keeps the stream alive.
|
|
75
|
+
*/
|
|
76
|
+
stream<T>(path: string, body: unknown, onEvent: (event: string, data: unknown) => void, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
77
|
+
/** `navigator.sendBeacon` when available (page unload); returns false when it could not be queued. */
|
|
78
|
+
beacon(path: string, body: unknown): boolean;
|
|
79
|
+
}
|
|
80
|
+
declare const sleep: (ms: number) => Promise<void>;
|
|
81
|
+
/** Exponential backoff helper: 1s → 2s → 4s … capped. */
|
|
82
|
+
declare function backoffMs(attempt: number, baseMs?: number, maxMs?: number): number;
|
|
83
|
+
/** Fire-and-forget POST with bounded retries (used for state sync; never blocks UI). */
|
|
84
|
+
declare function postWithRetry<T>(api: Api, path: string, body: unknown, attempts?: number, baseMs?: number): Promise<ApiResponse<T> | null>;
|
|
85
|
+
|
|
86
|
+
export { Api as A, type FetchLike as F, KEYS as K, type StorageKind as S, type ApiResponse as a, type KeyValueStore as b, backoffMs as c, createStorage as d, memoryStore as m, postWithRetry as p, readJson as r, sleep as s, writeJson as w };
|