@depsmith/depsmith-sdk 0.0.0-stage → 0.6.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.
@@ -0,0 +1,560 @@
1
+ /**
2
+ * User-property operators (API_SPEC §14).
3
+ *
4
+ * The operators exist because applying them on a client is wrong, not merely inconvenient:
5
+ * `$add` on a device is a read-modify-write race between tabs, and `$append` cannot converge
6
+ * at all. So the SDK's job is to *describe* the change and let the collector apply it.
7
+ *
8
+ * Two invariants are the client's responsibility, and both are here rather than in the
9
+ * collector — the schema's own comment explains why: they are what keep the collector free
10
+ * of operator algebra.
11
+ *
12
+ * 1. A key appears under AT MOST ONE operator per event. Without it, `$set` then `$add` on
13
+ * one key is only resolvable by assuming the value is numeric.
14
+ * 2. `$clear_all` is exclusive. Combining it with anything else makes the result depend on
15
+ * ordering that is otherwise unobservable.
16
+ *
17
+ * Both are enforced by dropping the offending entry with a debug warning, never by throwing:
18
+ * the public API is fire-and-forget and must not break a host page over a analytics call.
19
+ */
20
+
21
+ /**
22
+ * The closed operator set, exactly as `event.schema.json` `$defs.userPropertyOps` declares it.
23
+ * Closed on purpose: level 2 is a fixed 10-member enum the collector knows at compile time,
24
+ * which is what lets `user_properties.$add.orders` flatten deterministically into a warehouse
25
+ * column despite being three levels from the root.
26
+ */
27
+ interface UserPropertyOps {
28
+ $set?: Properties;
29
+ $set_once?: Properties;
30
+ $append?: Properties;
31
+ $prepend?: Properties;
32
+ $pre_insert?: Properties;
33
+ $post_insert?: Properties;
34
+ $remove?: Properties;
35
+ /** Numeric increments. Absent counts as 0; negative is allowed. */
36
+ $add?: Record<string, number>;
37
+ $unset?: string[];
38
+ /** Deletes every user property for this identity. Exclusive. */
39
+ $clear_all?: true;
40
+ }
41
+
42
+ /** Canonical types mirroring spec/schema/event.schema.json. */
43
+
44
+ type Scalar = string | number | boolean | null;
45
+ type PropertyValue = Scalar | Scalar[] | Record<string, Scalar>;
46
+ type Properties = Record<string, PropertyValue>;
47
+ type EventType = 'track' | 'page_view' | 'screen' | 'identify' | 'alias' | 'group' | 'autocapture' | 'session_start' | 'session_end';
48
+ type NetworkType = '2g' | '3g' | '4g' | '5g' | 'wifi' | 'ethernet' | 'none' | 'unknown';
49
+ interface EventContext {
50
+ library: {
51
+ name: string;
52
+ version: string;
53
+ };
54
+ page?: {
55
+ url?: string;
56
+ referrer?: string;
57
+ title?: string;
58
+ path?: string;
59
+ };
60
+ screen?: {
61
+ width?: number;
62
+ height?: number;
63
+ density?: number;
64
+ };
65
+ browser?: {
66
+ name?: string;
67
+ version?: string;
68
+ engine?: string;
69
+ };
70
+ /** No `id` — the device fingerprint is the top-level `DepsmithSdkEvent.device_id`. */
71
+ device?: {
72
+ manufacturer?: string;
73
+ model?: string;
74
+ type?: string;
75
+ };
76
+ os?: {
77
+ name?: string;
78
+ version?: string;
79
+ };
80
+ network?: {
81
+ wifi?: boolean;
82
+ cellular?: boolean;
83
+ type?: NetworkType;
84
+ carrier?: string;
85
+ isp?: string;
86
+ vpn?: boolean;
87
+ };
88
+ /**
89
+ * Coordinates may come from the device (`geolocation: true`, permission already granted);
90
+ * city/region/country are always server-enriched from the request IP. `source` records
91
+ * where the coordinates came from.
92
+ */
93
+ location?: {
94
+ latitude?: number;
95
+ longitude?: number;
96
+ accuracy?: number;
97
+ source?: 'gps' | 'ip';
98
+ city?: string;
99
+ region?: string;
100
+ country?: string;
101
+ };
102
+ locale?: string;
103
+ timezone?: string;
104
+ user_agent?: string;
105
+ traits?: Properties;
106
+ }
107
+ interface DepsmithSdkEvent {
108
+ event_id: string;
109
+ event: string;
110
+ event_type: EventType;
111
+ properties?: Properties;
112
+ timestamp: string;
113
+ session_id: string;
114
+ /** When the event's session began. Lets session length be computed per row. */
115
+ session_started_at?: string;
116
+ user_id?: string | null;
117
+ anonymous_id: string;
118
+ group_id?: string | null;
119
+ /**
120
+ * Device fingerprint — the third column identity resolution joins on, after `user_id` and
121
+ * `anonymous_id`, and the recovery path when `anonymous_id` has been cleared.
122
+ *
123
+ * Absent (never empty) unless `deviceFingerprinting` is on, `childSafeMode` is off and
124
+ * consent is granted — the same gate that populates the rest of the fingerprint context.
125
+ */
126
+ device_id?: string;
127
+ context: EventContext;
128
+ /**
129
+ * Server-applied user-property operators (API_SPEC §14). Present only on the events that
130
+ * carry a change; applied against `user_id` when set, else `anonymous_id`.
131
+ */
132
+ user_properties?: UserPropertyOps;
133
+ platform: 'web';
134
+ sdk_version: string;
135
+ }
136
+ interface BatchPayload {
137
+ batch: DepsmithSdkEvent[];
138
+ api_key: string;
139
+ source: 'sdk';
140
+ sent_at: string;
141
+ anonymize_ip?: boolean;
142
+ }
143
+ type ConsentState = 'pending' | 'granted' | 'denied';
144
+
145
+ /**
146
+ * Per-field suppression of context signals (API_SPEC §12.2).
147
+ *
148
+ * Every key defaults true (collected). This filter is SUBTRACTIVE ONLY — leaving an option
149
+ * true never re-enables a field that `deviceFingerprinting`, `childSafeMode` or consent
150
+ * already suppressed, so the controls compose by intersection and no context field ends up
151
+ * with two sources of truth.
152
+ */
153
+ interface TrackingOptions {
154
+ /** context.app. Mobile only — web has no app-version concept. */
155
+ appVersion?: boolean;
156
+ /** context.browser. Populated only when deviceFingerprinting is on. */
157
+ browser?: boolean;
158
+ /** context.network.carrier. Implied by `network: false`. */
159
+ carrier?: boolean;
160
+ deviceManufacturer?: boolean;
161
+ deviceModel?: boolean;
162
+ deviceType?: boolean;
163
+ /** context.locale. */
164
+ language?: boolean;
165
+ /** context.network in full. Subsumes carrier. */
166
+ network?: boolean;
167
+ osName?: boolean;
168
+ osVersion?: boolean;
169
+ /** context.page. Not the `name` property on $page_view — that is a property, not context. */
170
+ page?: boolean;
171
+ screen?: boolean;
172
+ timezone?: boolean;
173
+ /** context.user_agent. */
174
+ userAgent?: boolean;
175
+ }
176
+
177
+ /** Public config — keys mirror spec/schema/config.schema.json. */
178
+ interface DepsmithSdkConfig {
179
+ apiKey: string;
180
+ endpoint: string;
181
+ batchSize?: number;
182
+ batchIntervalMs?: number;
183
+ maxQueueSize?: number;
184
+ /**
185
+ * Ceiling on the serialised queue, in UTF-16 code units — the unit browsers meter
186
+ * storage quota in. Bounds the bytes DepsmithSdk occupies in an origin-shared `localStorage`,
187
+ * which `maxQueueSize` (a count) cannot. Oldest events are dropped first. Web only.
188
+ */
189
+ maxQueueBytes?: number;
190
+ sessionTimeoutMs?: number;
191
+ /** Fraction of SESSIONS captured, 0..1. Default 1. Session-sticky; see config.schema.json. */
192
+ sampleRate?: number;
193
+ /** Emit $session_start/$session_end as events, or leave them derivable server-side. Default 'emit'. */
194
+ sessionEvents?: 'emit' | 'derive';
195
+ consentMode?: 'granted' | 'pending';
196
+ respectDnt?: boolean;
197
+ maxRetries?: number;
198
+ debug?: boolean;
199
+ autocapture?: boolean | AutocaptureConfig;
200
+ defaultProperties?: Properties;
201
+ /** Batch upload compression. gzip when CompressionStream exists, transparent fallback otherwise. */
202
+ compression?: 'gzip' | 'none';
203
+ /** COPPA: memory-only identity, identify()/alias() disabled, anonymizeIp forced on. */
204
+ childSafeMode?: boolean;
205
+ /** Ask the server to strip the last IP octet (anonymize_ip on every batch). */
206
+ anonymizeIp?: boolean;
207
+ /** Device fingerprinting (browser/os/device.id/network). **Default true** — opt-OUT, unlike `geolocation`. Suppressed under DNT/childSafeMode/pending consent. */
208
+ deviceFingerprinting?: boolean;
209
+ /**
210
+ * Opt-in device position on context.location (latitude/longitude/accuracy). Never prompts:
211
+ * read only when the site already holds the geolocation permission. City/region/country
212
+ * remain server-resolved from the request IP. Suppressed under DNT/childSafeMode/pending
213
+ * consent, like deviceFingerprinting. Default false.
214
+ */
215
+ geolocation?: boolean;
216
+ /** Per-field context suppression, all keys default true. Subtractive only; see API_SPEC §12.2. */
217
+ trackingOptions?: TrackingOptions;
218
+ /** Persist identity keys in a cookie scoped to this domain (cross-subdomain identity). */
219
+ cookieDomain?: string;
220
+ /** Queue persistence backend. */
221
+ storage?: 'localstorage' | 'indexeddb' | 'memory';
222
+ }
223
+ /**
224
+ * Which clicks produce a `$autocapture` event.
225
+ * 'interactive' — only clicks resolving to a link/button/[role=button]/submit control
226
+ * or an explicit [data-depsmith-sdk-capture]. The default.
227
+ * 'all' — every click anywhere on the page, including layout containers.
228
+ * true — alias of 'interactive'; false disables click capture.
229
+ */
230
+ type ClickCapture = boolean | 'interactive' | 'all';
231
+ interface AutocaptureConfig {
232
+ clicks?: ClickCapture;
233
+ forms?: boolean;
234
+ scrolls?: boolean;
235
+ pageviews?: boolean;
236
+ ignoredSelectors?: string[];
237
+ selectorMaxDepth?: number;
238
+ }
239
+
240
+ /**
241
+ * Key-value storage abstraction. localStorage when available (synchronous — safe to
242
+ * write during pagehide), in-memory fallback for SSR / privacy modes that block storage.
243
+ */
244
+ interface KVStorage {
245
+ get(key: string): string | null;
246
+ set(key: string, value: string): void;
247
+ remove(key: string): void;
248
+ }
249
+ /**
250
+ * Every key DepsmithSdk persists. Single source of truth for hosts that must enumerate
251
+ * them up front — e.g. `AsyncMirrorAdapter`, whose backend has no bulk read.
252
+ * Kept in sync with the `KEY_*` consts in identity/session/consent/queue/depsmith-sdk/breaker.
253
+ */
254
+ declare const DEPSMITH_SDK_STORAGE_KEYS: readonly ["depsmith_anonymous_id", "depsmith_user_id", "depsmith_group_id", "depsmith_user_props", "depsmith_session", "depsmith_consent", "depsmith_queue", "depsmith_config_fp", "depsmith_net_breaker"];
255
+ /**
256
+ * Minimal async key-value backend. Shaped to accept Shopify's `browser.localStorage`
257
+ * / `browser.sessionStorage` directly (all methods Promise-returning, proxied to the
258
+ * top frame from the web-pixel sandbox).
259
+ */
260
+ interface AsyncKV {
261
+ getItem(key: string): Promise<string | null | undefined>;
262
+ setItem(key: string, value: string): Promise<unknown>;
263
+ removeItem(key: string): Promise<unknown>;
264
+ }
265
+ /**
266
+ * Synchronous `KVStorage` over an asynchronous backend: an in-memory mirror serves
267
+ * reads, writes go through to the mirror and are flushed write-behind.
268
+ *
269
+ * `hydrate()` must be awaited **before** constructing a DepsmithSdkClient over this
270
+ * adapter — IdentityManager/SessionManager/EventQueue all read in their constructors,
271
+ * and a cold mirror would mint a fresh anonymousId over a returning visitor's.
272
+ */
273
+ declare class AsyncMirrorAdapter implements KVStorage {
274
+ private backend;
275
+ private keys;
276
+ private mirror;
277
+ private hydrated;
278
+ constructor(backend: AsyncKV, keys?: readonly string[]);
279
+ /** Bulk-loads `keys` into the mirror. Idempotent; never rejects. */
280
+ hydrate(): Promise<void>;
281
+ get(key: string): string | null;
282
+ set(key: string, value: string): void;
283
+ remove(key: string): void;
284
+ }
285
+
286
+ /** Injectable time source — the conformance runner substitutes a controllable clock. */
287
+ interface Clock {
288
+ now(): number;
289
+ }
290
+
291
+ /**
292
+ * Deferred work scheduling.
293
+ *
294
+ * Exists so persistence can be moved off the capture task. Writing to `localStorage` is
295
+ * synchronous and blocks the main thread; doing it inside a click handler is what put
296
+ * DepsmithSdk on the critical path of every shopper interaction. Coalescing those writes onto
297
+ * an idle callback keeps the interaction cheap and collapses a burst of events into a
298
+ * single write.
299
+ */
300
+ type Scheduler = (fn: () => void) => void;
301
+ /**
302
+ * Runs `fn` at the next idle moment, or within {@link IDLE_TIMEOUT_MS} at the latest.
303
+ *
304
+ * Falls back to a macrotask where `requestIdleCallback` is absent — Safari below 16.4 and
305
+ * jsdom. The fallback is still correct, just less considerate about when it lands.
306
+ */
307
+ declare const idleScheduler: Scheduler;
308
+ /**
309
+ * Runs `fn` immediately, restoring write-through behaviour.
310
+ *
311
+ * The seam tests use to assert persisted state without pumping timers, and the escape
312
+ * hatch for any host that needs durability over latency.
313
+ */
314
+ declare const syncScheduler: Scheduler;
315
+
316
+ /** Test/conformance seams. Not part of the public API contract. */
317
+ interface InternalOverrides {
318
+ storage?: KVStorage;
319
+ clock?: Clock;
320
+ fetchFn?: typeof fetch;
321
+ isOnline?: () => boolean;
322
+ sleep?: (ms: number) => Promise<void>;
323
+ dnt?: boolean;
324
+ /** Per-attempt upload timeout. Test seam so a hung-request test needn't wait 30s. */
325
+ requestTimeoutMs?: number;
326
+ /** Disable timers/listeners (conformance runners drive flushes explicitly). */
327
+ manualLifecycle?: boolean;
328
+ /**
329
+ * Called at capture time for host-supplied `context` fields, shallow-merged over the
330
+ * derived ones. Used by the Shopify web-pixel adapter, which gets fresh page context
331
+ * on every event and cannot read the real `window`/`document`.
332
+ */
333
+ contextProvider?: () => Partial<EventContext>;
334
+ /**
335
+ * How queue/session persistence is deferred. Defaults to an idle callback, which is what
336
+ * keeps the blocking `localStorage` write off the capture path. Pass `syncScheduler` to
337
+ * restore write-through — tests do, and so does any host whose storage is already
338
+ * non-blocking (the Shopify pixel's async-mirrored storage).
339
+ */
340
+ schedule?: Scheduler;
341
+ }
342
+ declare class DepsmithSdkClient {
343
+ private config;
344
+ private logger;
345
+ private storage;
346
+ private clock;
347
+ private identity;
348
+ private session;
349
+ private consent;
350
+ private queue;
351
+ private uploader;
352
+ private flushTimer;
353
+ /**
354
+ * Set once a teardown drain has run, so `pagehide` and `visibilitychange`→hidden do not
355
+ * both run it on one navigation. Cleared on resume, on `pageshow`, and by any newly
356
+ * captured event ({@link enqueueEvent}).
357
+ */
358
+ private drained;
359
+ private teardownFns;
360
+ private contextProvider?;
361
+ /** Resolves once async storage (IndexedDB) is hydrated; uploads gate on this. */
362
+ private ready;
363
+ constructor(config: DepsmithSdkConfig, overrides?: InternalOverrides);
364
+ track(name: string, properties?: Properties): void;
365
+ /**
366
+ * Rejects an envelope id the collector's schema would refuse, at the point it enters the SDK.
367
+ *
368
+ * Dropping the call is harsh, and it is the lesser harm. `event`, `user_id` and `group_id` are
369
+ * all capped at 255 in event.schema.json, the collector validates every batch with Ajv, and a
370
+ * 400 is non-retryable — so the uploader discards the WHOLE batch as a poison pill. For
371
+ * `user_id` and `group_id` that is not a one-batch loss either: both are persisted and ride on
372
+ * every subsequent event, so a single over-long id silently destroys everything that user sends
373
+ * until reset(). A JWT or a concatenated composite key passed as a user id does it.
374
+ *
375
+ * Truncating instead would keep the events but silently merge two users sharing a 255-char
376
+ * prefix, inventing data rather than losing it. Rejecting a schema-invalid value at capture is
377
+ * the rule throughout: such an event would 400 and take the whole batch with it.
378
+ */
379
+ private tooLong;
380
+ page(name?: string, properties?: Properties): void;
381
+ /** Alias of page() — unified mobile naming. */
382
+ screen(name?: string, properties?: Properties): void;
383
+ identify(userId: string, traits?: Properties): void;
384
+ alias(aliasId: string): void;
385
+ reset(): void;
386
+ group(groupId: string, traits?: Properties): void;
387
+ setGroupTraits(traits: Properties): void;
388
+ setProperty(key: string, value: Properties[string]): void;
389
+ /**
390
+ * Sets a property only if this device has not already set it.
391
+ *
392
+ * The local check is the cross-SDK contract (`spec/conformance/fixtures/
393
+ * user_props_set_setonce_unset.json` asserts that a repeat call emits nothing), so it
394
+ * stays. It is an optimisation, not the guarantee: a client can only see THIS device, and
395
+ * a returning visitor on a second browser looks like a first write. `$set_once` closes
396
+ * that, because the collector evaluates it against the stored identity.
397
+ */
398
+ setOnceProperty(key: string, value: Properties[string]): void;
399
+ unsetProperty(key: string): void;
400
+ /**
401
+ * Applies user-property operators server-side (API_SPEC §14).
402
+ *
403
+ * The whole closed operator set in one call — `$set`, `$set_once`, `$add`, `$append`,
404
+ * `$prepend`, `$pre_insert`, `$post_insert`, `$remove`, `$unset`, `$clear_all` — rather
405
+ * than ten methods, because the set is fixed by the schema and a typed map keeps the
406
+ * public surface proportional to what it buys.
407
+ *
408
+ * `$add` is the reason this exists at all: incrementing on the client is a
409
+ * read-modify-write race between tabs, and no amount of care on one device fixes it.
410
+ *
411
+ * Unlike the three convenience methods above, this sends NO `context.traits`. Those carry
412
+ * traits for compatibility with consumers that read them today; a caller reaching for the
413
+ * operators directly is asking for the server-applied semantics, and duplicating an
414
+ * `$append` into a trait would misreport it as an overwrite.
415
+ *
416
+ * Silently does nothing when nothing survives validation — a key claimed twice, a
417
+ * non-finite `$add`, an empty map — since the schema forbids an empty operator object.
418
+ */
419
+ setUserProperties(ops: UserPropertyOps): void;
420
+ optIn(): void;
421
+ optOut(): void;
422
+ flush(): Promise<void>;
423
+ /**
424
+ * Autocapture engine entry point ($autocapture events). Not part of the public API —
425
+ * the lazily-loaded engine calls this through its `emit` hook.
426
+ *
427
+ * Named rather than inlined into startAutocapture() so the conformance runner can drive
428
+ * it by reflection, exactly as Android's `autocapture()` and iOS's `autocapture(_:)`
429
+ * already allow. Without a named entry point the whole subsystem is unreachable from a
430
+ * shared fixture, which is why it had none.
431
+ */
432
+ autocapture(properties: Properties): void;
433
+ /** Conformance/testing: await any in-flight upload (incl. retries) without forcing one. */
434
+ drainInFlight(): Promise<void>;
435
+ getAnonymousId(): string;
436
+ getSessionId(): string;
437
+ /**
438
+ * Adopts an externally supplied session id, so a session can span a web→app handoff or
439
+ * two contexts that do not share storage. Must be a UUIDv7; anything else is a debug-warn
440
+ * no-op rather than a corrupted session. Emits no `$session_start` (API_SPEC §5).
441
+ */
442
+ setSessionId(sessionId: string, startedAt?: number): void;
443
+ /** Stops timers/listeners. Queued events stay persisted. */
444
+ shutdown(): void;
445
+ /**
446
+ * Forces the write-behind queue and session state to storage now.
447
+ *
448
+ * Persistence is deferred to an idle callback so a captured event does not pay a
449
+ * blocking `localStorage` write on the interaction that produced it. This is the escape
450
+ * hatch for the moments where there may be no later tick: page teardown and shutdown.
451
+ */
452
+ private persistNow;
453
+ /**
454
+ * Queues an event and re-arms the teardown drain.
455
+ *
456
+ * `drained` exists only to stop `pagehide` and `visibilitychange`→hidden running the
457
+ * same drain twice on one navigation. It must not outlive the work it covered: on
458
+ * desktop, `visibilitychange`→hidden fires on an ordinary tab switch, and a backgrounded
459
+ * tab keeps capturing (the batch-interval timer, `online`, a host-driven `track()`). If
460
+ * that tab is then closed without ever becoming visible again, a latch left set would
461
+ * skip both the final `sendBeaconAll()` and the teardown write, losing everything
462
+ * captured while hidden — a correctness hole opened by a pure optimisation.
463
+ */
464
+ private enqueueEvent;
465
+ /**
466
+ * The single entry point for starting an upload.
467
+ *
468
+ * Persistence is NOT forced here. API_SPEC §1 step 4 (durable storage before any network
469
+ * attempt) is upheld inside the uploader's drain loop, which persists per batch it is
470
+ * about to send. Forcing it here instead meant a synchronous write on every capture once
471
+ * the queue sat at or above `batchSize` — which is the regression this whole change
472
+ * exists to remove, reappearing in the exact case that matters most (a backed-up queue).
473
+ */
474
+ private flushUploads;
475
+ /**
476
+ * Fingerprinting is opt-in and privacy-gated: it requires explicit config, granted
477
+ * consent (consent.current is 'denied' under DNT and never 'granted' while pending),
478
+ * and non-COPPA mode.
479
+ */
480
+ private contextOptions;
481
+ /**
482
+ * Session-sticky sampling.
483
+ *
484
+ * The decision is derived from (apiKey, session_id) rather than drawn at random, so it
485
+ * is stable for the session's whole lifetime and identical across tabs sharing that
486
+ * session. A random draw per event would split sessions in half, which is worse than
487
+ * useless: a funnel built from partial sessions is wrong rather than merely noisy.
488
+ *
489
+ * Salted with the apiKey so a future, independently-configured sampler at the same rate
490
+ * does not select the identical set of sessions.
491
+ *
492
+ * Identity events are NEVER sampled. Dropping $identify for 90% of users would stop
493
+ * their user properties applying at all — that is not less data, it is wrong data.
494
+ * Everything else follows the session: a session is wholly in or wholly out. Scale
495
+ * sampled metrics by 1/sampleRate.
496
+ */
497
+ private sessionInSample;
498
+ /** Identity events are exempt; everything else follows its session. */
499
+ private inSample;
500
+ private capture;
501
+ /**
502
+ * Config drift (guidelines §12): events queued under a different apiKey belong to
503
+ * another project — drop them rather than misattribute. Fingerprint, not raw key.
504
+ */
505
+ private detectConfigDrift;
506
+ private pickStorage;
507
+ private enqueueSessionEnd;
508
+ /**
509
+ * Announces a session the SDK just observed beginning.
510
+ *
511
+ * Consent-gated for the same reason as enqueueSessionEnd: the visibilitychange resume
512
+ * path reaches this without going through capture(). Under `pending` consent
513
+ * canCapture() is true, so it is queued and held — matching capture() exactly.
514
+ *
515
+ * Not emitted by reset()/rotate() (an explicit user action, not an observed boundary)
516
+ * nor by peek()'s mint-if-absent branch (analytics from a getter).
517
+ */
518
+ private enqueueSessionStart;
519
+ private startFlushTimer;
520
+ private attachLifecycle;
521
+ /** Lazily loads the autocapture engine so the core bundle stays <10KB gz. */
522
+ private startAutocapture;
523
+ private guard;
524
+ }
525
+
526
+ /**
527
+ * Default singleton facade:
528
+ *
529
+ * import { DepsmithSdk } from '@depsmith/depsmith-sdk';
530
+ * DepsmithSdk.init({ apiKey: '...', endpoint: 'https://collector.example.com' });
531
+ * DepsmithSdk.track('button_clicked', { color: 'red' });
532
+ *
533
+ * Re-init with the same apiKey is a no-op; a different apiKey replaces the client (API_SPEC §2).
534
+ */
535
+ declare const DepsmithSdk: {
536
+ init(config: DepsmithSdkConfig, overrides?: InternalOverrides): DepsmithSdkClient | null;
537
+ track: (name: string, properties?: Properties) => void;
538
+ page: (name?: string, properties?: Properties) => void;
539
+ screen: (name?: string, properties?: Properties) => void;
540
+ identify: (userId: string, traits?: Properties) => void;
541
+ alias: (aliasId: string) => void;
542
+ reset: () => void;
543
+ group: (groupId: string, traits?: Properties) => void;
544
+ setGroupTraits: (traits: Properties) => void;
545
+ setProperty: (key: string, value: Properties[string]) => void;
546
+ setOnceProperty: (key: string, value: Properties[string]) => void;
547
+ unsetProperty: (key: string) => void;
548
+ /** Applies the §14 operator set server-side: $set, $add, $append, $unset, $clear_all, … */
549
+ setUserProperties: (ops: UserPropertyOps) => void;
550
+ optIn: () => void;
551
+ optOut: () => void;
552
+ flush: () => Promise<void>;
553
+ getAnonymousId: () => string | undefined;
554
+ getSessionId: () => string | undefined;
555
+ setSessionId: (sessionId: string, startedAt?: number) => void;
556
+ /** Testing/teardown: stop timers and forget the singleton. */
557
+ shutdown(): void;
558
+ };
559
+
560
+ export { type AsyncKV, AsyncMirrorAdapter, type AutocaptureConfig, type BatchPayload, type ConsentState, DEPSMITH_SDK_STORAGE_KEYS, DepsmithSdk, DepsmithSdkClient, type DepsmithSdkConfig, type DepsmithSdkEvent, type EventContext, type EventType, type InternalOverrides, type KVStorage, type Properties, type PropertyValue, type Scheduler, type TrackingOptions, type UserPropertyOps, idleScheduler, syncScheduler };