@guidelytech/sdk-core 0.9.0 → 0.11.0

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.
Files changed (48) hide show
  1. package/README.md +15 -4
  2. package/dist/{capture-Dqd7up2n.d.ts → capture-CgN69Lxq.d.cts} +2 -1
  3. package/dist/{capture-C3faAYb7.d.cts → capture-Csz721-A.d.ts} +2 -1
  4. package/dist/capture.cjs +4 -0
  5. package/dist/capture.cjs.map +1 -1
  6. package/dist/capture.d.cts +3 -2
  7. package/dist/capture.d.ts +3 -2
  8. package/dist/capture.js +4 -6
  9. package/dist/capture.js.map +1 -1
  10. package/dist/chunk-JUSM7J5N.js +376 -0
  11. package/dist/chunk-JUSM7J5N.js.map +1 -0
  12. package/dist/{chunk-544KSOC3.js → chunk-ZAF2KRJA.js} +142 -22
  13. package/dist/chunk-ZAF2KRJA.js.map +1 -0
  14. package/dist/headless.cjs +307 -44
  15. package/dist/headless.cjs.map +1 -1
  16. package/dist/headless.d.cts +44 -3
  17. package/dist/headless.d.ts +44 -3
  18. package/dist/headless.js +21 -9
  19. package/dist/health-sbP9JwTE.d.cts +90 -0
  20. package/dist/health-sbP9JwTE.d.ts +90 -0
  21. package/dist/{http-47tiAlOM.d.ts → http-Cb6KYYFv.d.cts} +10 -35
  22. package/dist/{http-47tiAlOM.d.cts → http-D047Ngxk.d.ts} +10 -35
  23. package/dist/index.cjs +1352 -500
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +81 -8
  26. package/dist/index.d.ts +81 -8
  27. package/dist/index.js +809 -211
  28. package/dist/index.js.map +1 -1
  29. package/dist/recorder.cjs +70 -9
  30. package/dist/recorder.cjs.map +1 -1
  31. package/dist/recorder.d.cts +9 -0
  32. package/dist/recorder.d.ts +9 -0
  33. package/dist/recorder.js +57 -11
  34. package/dist/recorder.js.map +1 -1
  35. package/dist/{types-DnJW_4ck.d.ts → types-BDlebXrm.d.ts} +68 -7
  36. package/dist/{types-zM5e3loY.d.cts → types-Mtlmlj5C.d.cts} +68 -7
  37. package/package.json +4 -4
  38. package/dist/chunk-544KSOC3.js.map +0 -1
  39. package/dist/chunk-AKNE7D5M.js +0 -160
  40. package/dist/chunk-AKNE7D5M.js.map +0 -1
  41. package/dist/chunk-CYAG6ZYX.js +0 -85
  42. package/dist/chunk-CYAG6ZYX.js.map +0 -1
  43. package/dist/chunk-GDF6RCHQ.js +0 -209
  44. package/dist/chunk-GDF6RCHQ.js.map +0 -1
  45. package/dist/types-DbKQPvFt.d.cts +0 -238
  46. package/dist/types-DqhNl5Am.d.ts +0 -238
  47. package/dist/types-RyeRQd9f.d.ts +0 -226
  48. package/dist/types-d4eOerxi.d.cts +0 -226
@@ -1,226 +0,0 @@
1
- import { SdkEvent, PublishedGuide, FrequencyConfig, AutocaptureSettings, NetworkRequest, ProjectTheme, SdkConfigResponse, ChecklistTask, MessengerMessage, MessengerConversation } from '@guidelytech/shared';
2
- import { b as KeyValueStore, S as StorageKind } from './http-47tiAlOM.cjs';
3
-
4
- interface EventQueueOptions {
5
- store: KeyValueStore;
6
- storageKey: string;
7
- /** Sends one batch. Resolve `{ ok: true }` on success, `{ ok: false, retry }` otherwise. */
8
- send: (events: SdkEvent[]) => Promise<{
9
- ok: boolean;
10
- retry?: boolean;
11
- }>;
12
- /** Synchronous best-effort send used on page hide. */
13
- beacon?: (events: SdkEvent[]) => boolean;
14
- /** Should events be flushed right now? (analytics enabled + consent granted). */
15
- enabled: () => boolean;
16
- flushIntervalMs?: number;
17
- maxQueue?: number;
18
- batchSize?: number;
19
- maxAttempts?: number;
20
- onError?: (err: unknown) => void;
21
- }
22
- /**
23
- * Bounded, persisted event queue. Batches ≤50 events every 2s (or on demand), dedupes by
24
- * `eventId`, retries with exponential backoff (1s→30s, 5 attempts) and keeps failed events for
25
- * the next flush. Drops the oldest events once the queue exceeds 200.
26
- */
27
- declare class EventQueue {
28
- private readonly opts;
29
- private events;
30
- private timer;
31
- private retryTimer;
32
- private inflight;
33
- private inflightIds;
34
- private attempt;
35
- private destroyed;
36
- private readonly flushIntervalMs;
37
- private readonly maxQueue;
38
- private readonly batchSize;
39
- private readonly maxAttempts;
40
- constructor(opts: EventQueueOptions);
41
- get size(): number;
42
- /** Pending events (read-only copy, for debugging). */
43
- peek(): SdkEvent[];
44
- enqueue(event: SdkEvent): void;
45
- private persist;
46
- private schedule;
47
- /** Sends queued events now (one batch at a time). Safe to call at any time. */
48
- flush(): Promise<void>;
49
- /** Best-effort synchronous flush on unload using `sendBeacon`. */
50
- flushSync(): void;
51
- clear(): void;
52
- destroy(): void;
53
- }
54
-
55
- /** Per-guide state kept locally and merged with the server's `IdentifyResponse.guideState`. */
56
- interface GuideLocalState {
57
- impressions: number;
58
- completedAt?: string | null;
59
- dismissedAt?: string | null;
60
- lastShownAt?: string | null;
61
- /** Last step reached in a multi-step flow (local only), so the messenger can offer to resume it. */
62
- lastStepId?: string | null;
63
- }
64
- /**
65
- * Pure frequency evaluation. `shownThisSession` comes from session storage.
66
- * - `once`: a single impression ever (unless `reshowAfterDismiss` and it was only dismissed).
67
- * - `once_per_session`: at most once per browser session.
68
- * - `every_time`: on every trigger (still blocked by completion/dismissal rules below).
69
- * - `interval`: at most once every `intervalHours`.
70
- * `maxImpressions` caps total impressions; dismissal blocks re-showing unless `reshowAfterDismiss`
71
- * (then `cooldownHours` must have elapsed); completion blocks unless mode is `every_time`.
72
- */
73
- declare function isFrequencyEligible(freq: FrequencyConfig, state: GuideLocalState | undefined, shownThisSession: boolean, now?: number): boolean;
74
- /**
75
- * Exclusive guides (flows, modals, tooltips, announcements, surveys) run one at a time.
76
- * Banners, checklists and hotspot-only tooltips can coexist with an active flow.
77
- */
78
- declare function isExclusiveGuide(guide: PublishedGuide): boolean;
79
- /** Is `a` mutually exclusive with `b` (by id or key, in either direction)? */
80
- declare function areMutuallyExclusive(a: PublishedGuide, b: PublishedGuide): boolean;
81
- /** Survey scheduling window. */
82
- declare function isWithinSchedule(guide: PublishedGuide, now?: number): boolean;
83
-
84
- type GuidelyEnvironment = "development" | "staging" | "production";
85
- type ConsentState = "granted" | "denied" | "pending";
86
- interface GuidelyAccount {
87
- id: string;
88
- traits?: Record<string, unknown>;
89
- }
90
- interface GuidelyUser {
91
- id: string;
92
- traits?: Record<string, unknown>;
93
- account?: GuidelyAccount;
94
- }
95
- interface GuidelyOptions {
96
- /** Environment public key, e.g. `pk_dev_…`. Not a secret. */
97
- projectId: string;
98
- environment?: GuidelyEnvironment;
99
- /** Base URL of the Guidely API (default `https://api.guidely.app`; use `http://localhost:3000` locally). */
100
- apiUrl?: string;
101
- /** Log trigger decisions and requests to the console. */
102
- debug?: boolean;
103
- /** Send analytics events (default `true`). Guides still render when disabled. */
104
- analytics?: boolean;
105
- /** `pending` buffers events until `setConsent("granted")`; `denied` disables analytics. */
106
- consent?: ConsentState;
107
- /** Where to persist identity, cached config and the event queue (default `local`). */
108
- storage?: StorageKind;
109
- /** Interval for re-checking element-visibility triggers while the page is idle (default 1000ms). */
110
- pollIntervalMs?: number;
111
- /** How often to refresh the published config (default 5 minutes). */
112
- configRefreshMs?: number;
113
- /** Elements whose text must never be captured (authoring snapshots, click text, session replays). Merged with the project setting. */
114
- maskSelectors?: string[];
115
- /**
116
- * Page views, page leave, clicks and rage clicks are captured when the project enables them.
117
- * `false` turns all of them off for this installation; an object turns individual ones off
118
- * (`{ clicks: false }`). Options can only switch capture off, never on.
119
- */
120
- autocapture?: boolean | Partial<AutocaptureSettings>;
121
- /** App version or commit SHA (≤100 chars), sent with every `exception` to pick the matching uploaded source maps. */
122
- release?: string;
123
- /** `false` stops uncaught errors / unhandled rejections from being reported (`captureException` still works). */
124
- captureErrors?: boolean;
125
- /**
126
- * `false` never records sessions on this installation. An object can only make masking stricter:
127
- * `maskAllText` masks every text node, `blockSelectors` replaces matching elements with a placeholder.
128
- */
129
- sessionReplay?: boolean | {
130
- maskAllText?: boolean;
131
- blockSelectors?: string[];
132
- /** `false`: never record network requests / WebSockets in replays. */
133
- recordNetwork?: false;
134
- /** `false`: never record request/response headers, bodies or WebSocket frame data. */
135
- recordNetworkPayloads?: false;
136
- /** Last say over each recorded request (applied after redaction): return a modified copy, or null to drop it. */
137
- maskNetworkRequest?: (request: NetworkRequest) => NetworkRequest | null;
138
- };
139
- onError?: (error: Error) => void;
140
- /** Overrides for the project theme (colors, radius, font). */
141
- theme?: Partial<ProjectTheme>;
142
- /** Identify this user as soon as the client initialises. */
143
- user?: GuidelyUser;
144
- /** Custom fetch (tests / polyfills). */
145
- fetch?: typeof fetch;
146
- /** Disable the authoring-mode and how-to capture URL parameter detection. */
147
- disableAuthoring?: boolean;
148
- }
149
- interface ChecklistProgressState {
150
- completedTaskIds: string[];
151
- completedAt?: string | null;
152
- dismissedAt?: string | null;
153
- }
154
- /** Everything the client persists per project key (`guidely:state:<key>`). */
155
- interface PersistedState {
156
- guides: Record<string, GuideLocalState>;
157
- checklists: Record<string, ChecklistProgressState>;
158
- surveysSubmitted: string[];
159
- audienceIds: string[];
160
- firstSeenAt?: string;
161
- }
162
- interface SessionState {
163
- id: string;
164
- startedAt: string;
165
- shownGuides: string[];
166
- events: string[];
167
- /** Epoch ms of the last tracked activity; the session rotates after `sessionTimeoutMinutes` of inactivity. */
168
- lastActivityAt?: number;
169
- /** Page views sent in this session (the first one carries the referrer). */
170
- pageViews?: number;
171
- /** Exceptions reported in this session (capped at 100). */
172
- exceptions?: number;
173
- /** Replay decision for this session: sampled in / forced (`true`), sampled out or disabled by the server (`false`). */
174
- replay?: boolean;
175
- }
176
- interface GuideStepInfo {
177
- guide: PublishedGuide;
178
- stepId: string;
179
- stepIndex: number;
180
- }
181
- interface GuidelyEvents {
182
- /** Config loaded (from network or cache) and triggers evaluated. */
183
- ready: (config: SdkConfigResponse) => void;
184
- /** Config (re)loaded. */
185
- config: (config: SdkConfigResponse) => void;
186
- "guide:start": (guide: PublishedGuide) => void;
187
- "guide:step": (info: GuideStepInfo) => void;
188
- "guide:complete": (guide: PublishedGuide) => void;
189
- "guide:dismiss": (guide: PublishedGuide) => void;
190
- "guide:skip": (guide: PublishedGuide) => void;
191
- "checklist:task": (info: {
192
- guide: PublishedGuide;
193
- task: ChecklistTask;
194
- progress: ChecklistProgressState;
195
- }) => void;
196
- "checklist:complete": (guide: PublishedGuide) => void;
197
- "survey:submit": (info: {
198
- guide: PublishedGuide;
199
- answers: Record<string, unknown>;
200
- responseId: string;
201
- }) => void;
202
- "resource-center:open": () => void;
203
- "messenger:open": () => void;
204
- /** A Scout or teammate message arrived in the messenger. */
205
- "conversation:message": (info: {
206
- message: MessengerMessage;
207
- conversation: MessengerConversation;
208
- }) => void;
209
- error: (error: Error) => void;
210
- /** Every tracked event (custom and lifecycle). */
211
- track: (event: SdkEvent) => void;
212
- identify: (info: {
213
- userId: string | null;
214
- anonymousId: string;
215
- }) => void;
216
- authoring: (info: {
217
- active: boolean;
218
- }) => void;
219
- /** How-to capture (recording steps for a how-to guide) started or ended in this tab. */
220
- capture: (info: {
221
- active: boolean;
222
- }) => void;
223
- }
224
- type GuidelyEventName = keyof GuidelyEvents;
225
-
226
- export { type ChecklistProgressState as C, EventQueue as E, type GuideLocalState as G, type PersistedState as P, type SessionState as S, type ConsentState as a, type EventQueueOptions as b, type GuidelyAccount as c, type GuidelyEnvironment as d, type GuidelyUser as e, areMutuallyExclusive as f, isFrequencyEligible as g, isWithinSchedule as h, isExclusiveGuide as i, type GuidelyOptions as j, type GuidelyEvents as k, type GuideStepInfo as l, type GuidelyEventName as m };