@sidebandai/sideband-core 0.0.0-stage → 1.4.1-rc.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SidebandAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ # @sidebandai/sideband-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Renderer-free primitives for Sideband transport, browser context, event
4
+ delivery, and survey-session state. It does not mount UI or import renderer
5
+ code.
6
+
7
+ For a website or React application, use
8
+ [@sidebandai/sideband-web](https://www.npmjs.com/package/@sidebandai/sideband-web)
9
+ or [@sidebandai/sideband-react](https://www.npmjs.com/package/@sidebandai/sideband-react).
10
+ Both install core automatically. Install core directly when building a custom
11
+ integration.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @sidebandai/sideband-core@rc
17
+ ```
18
+
19
+ The `rc` tag selects the latest release candidate. Installation uses the public
20
+ npm registry and requires no registry credentials.
21
+
22
+ Both web renderers consume this package. Events use `track`, metadata values
23
+ are strings, and `appVersion` is optional without a default. Requests use the
24
+ production endpoint by default.
25
+
26
+ ## Event metadata and Pulse targeting
27
+
28
+ Pass metadata to `track` as string key-value pairs. Use metadata to describe an
29
+ event without creating a separate event name for each source, item type, or mode.
30
+ Only these six keys support Pulse trigger filters and event-history conditions:
31
+
32
+ | Key | Value format | Example |
33
+ | --- | --- | --- |
34
+ | `source` | String | `'home'` |
35
+ | `item_type` | String | `'article'` |
36
+ | `mode` | String | `'manual'` |
37
+ | `variant` | String | `'control'` |
38
+ | `count` | Integer sent as a string | `'3'` |
39
+ | `duration` | Seconds sent as a string; fractions allowed | `'12.5'` |
40
+
41
+ Use the exact lowercase key names. The server trims and lowercases values for
42
+ `source`, `item_type`, `mode`, and `variant`. These keys support equals and
43
+ not-equals comparisons. It compares `count` and `duration` numerically, with
44
+ equals, not-equals, greater-than, greater-than-or-equal, less-than, and
45
+ less-than-or-equal comparisons. Send `duration` in seconds, not milliseconds.
46
+
47
+ ```ts
48
+ runtime.track('content_created', {
49
+ source: 'editor',
50
+ item_type: 'article',
51
+ count: '3',
52
+ duration: '12.5',
53
+ content_id: 'article-123',
54
+ })
55
+ ```
56
+
57
+ Here, `runtime` is a started instance returned by `createSidebandRuntime()`.
58
+
59
+ Custom keys such as `content_id`, `screen`, or `plan` are stored unchanged, but
60
+ cannot be used in Pulse targeting filters. A missing key does not match any
61
+ filter, including not-equals.
62
+
63
+ The server stores at most 20 metadata properties per event. It keeps valid
64
+ targeting keys first, then fills the remaining slots with custom keys in sorted
65
+ key order. It drops empty keys and invalid targeting values without rejecting
66
+ the event. For example, `count: '3.5'` and `count: '3.0'` are invalid; use
67
+ `count: '3'`. Normalization and numeric comparison happen on the server, not in
68
+ the SDK.
69
+
70
+ ## Runtime
71
+
72
+ `createSidebandRuntime()` is the authoritative core integration point for
73
+ adapters. Construction is side-effect free; call `start()` to queue the
74
+ `system_app_launch` event and enable browser lifecycle observation. Browser
75
+ background and foreground transitions queue `system_app_background` and
76
+ `system_app_foreground` respectively.
77
+
78
+ Regular delivery batches queued events and honors the full server-provided
79
+ `next_sync_seconds` minimum. It does not poll while idle. `flush()`, explicit
80
+ `sync()`, and hidden/pagehide lifecycle snapshots are forced operations that
81
+ bypass pacing and retry gates. Forced manual flushes drain accepted snapshots;
82
+ lifecycle snapshots make one keepalive best-effort attempt.
83
+
84
+ `tagUser(userId: string)` persists an opaque identity exactly, including empty
85
+ and whitespace-only strings, and takes precedence over `context.user_id`.
86
+ `untagUser()` is the only API that clears runtime and persisted identity; the
87
+ configured context then applies again.
88
+
89
+ Web and React automatically queue `system_login`/`system_logout` when the
90
+ tagged identity changes, with the exact affected ID in `metadata.user_id`.
91
+ Switching users queues logout before login with the same invocation-time
92
+ `timestamp`. Duplicate tags, duplicate untags, and persisted restoration emit no
93
+ auth events; configured context alone does not log in. Event IDs, timestamps,
94
+ and auth metadata survive batching and retries, even when batch context advances.
95
+
96
+ Sync errors include documented `invalid_request`, `unauthorized`, `not_found`,
97
+ and retryable `service_unavailable` (HTTP 503) envelopes.
@@ -0,0 +1,15 @@
1
+ import type { ClientContext, EventMetadata, SidebandClientConfig, SyncErrorResponse, SyncOptions, SyncRequest, SyncResponse, TrackOptions } from '../types';
2
+ export declare class SidebandApiError extends Error {
3
+ status: number;
4
+ body: SyncErrorResponse | unknown;
5
+ retryAfterSeconds?: number;
6
+ constructor(message: string, status: number, body: SyncErrorResponse | unknown, retryAfterSeconds?: number);
7
+ }
8
+ export declare function createSidebandClient(config: SidebandClientConfig): {
9
+ sync: (request: Omit<SyncRequest, "context"> & {
10
+ context?: ClientContext;
11
+ }, options?: SyncOptions) => Promise<SyncResponse>;
12
+ track: (eventName: string, metadata?: EventMetadata, options?: TrackOptions) => Promise<SyncResponse>;
13
+ };
14
+ export type SidebandClient = ReturnType<typeof createSidebandClient>;
15
+ //# sourceMappingURL=create-sideband-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-sideband-client.d.ts","sourceRoot":"","sources":["../../src/client/create-sideband-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,UAAU,CAAA;AA2FjB,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAA;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAA;gBAGxB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,GAAG,OAAO,EACjC,iBAAiB,CAAC,EAAE,MAAM;CAQ7B;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB;oBAMpD,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG;QAAE,OAAO,CAAC,EAAE,aAAa,CAAA;KAAE,YACzD,WAAW,KACpB,OAAO,CAAC,YAAY,CAAC;uBAkDX,MAAM,aACN,aAAa,YACd,YAAY;EAsBzB;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { ClientContext } from '../types';
2
+ export declare function generateUuid(): string;
3
+ export declare function getDeviceId(): string;
4
+ export declare function getSessionId(): string;
5
+ export declare function getStoredUserId(): string | null;
6
+ export declare function setStoredUserId(userId: string): void;
7
+ export declare function clearStoredUserId(): void;
8
+ export declare function resetContextMemoForTests(): void;
9
+ export declare function createDefaultContext(appVersion?: string, libraryVersion?: string): ClientContext;
10
+ export declare function createContextResolver(appVersion?: string, overrides?: Partial<ClientContext> | (() => Partial<ClientContext> | Promise<Partial<ClientContext>>), libraryVersion?: string): () => Promise<ClientContext>;
11
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAS7C,wBAAgB,YAAY,IAAI,MAAM,CAqBrC;AAsCD,wBAAgB,WAAW,IAAI,MAAM,CAMpC;AAED,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,wBAAgB,eAAe,IAAI,MAAM,GAAG,IAAI,CAM/C;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,QAM7C;AAED,wBAAgB,iBAAiB,SAMhC;AAED,wBAAgB,wBAAwB,SAGvC;AAED,wBAAgB,oBAAoB,CAClC,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,SAA4B,GACzC,aAAa,CAqBf;AAQD,wBAAgB,qBAAqB,CACnC,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EACR,OAAO,CAAC,aAAa,CAAC,GACpB,CAAC,MAAM,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EACpE,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,OAAO,CAAC,aAAa,CAAC,CAS9B"}
@@ -0,0 +1,3 @@
1
+ import type { SidebandRuntime, SidebandRuntimeConfig } from '../types';
2
+ export declare function createSidebandRuntime(config: SidebandRuntimeConfig): SidebandRuntime;
3
+ //# sourceMappingURL=create-sideband-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-sideband-runtime.d.ts","sourceRoot":"","sources":["../../src/core/create-sideband-runtime.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAIV,eAAe,EACf,qBAAqB,EAItB,MAAM,UAAU,CAAA;AAEjB,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAoEpF"}
@@ -0,0 +1,7 @@
1
+ import type { Fab, FabPlacement, PulseQuestion } from '../types';
2
+ /** Select data only; renderers retain the shared FAB geometry and clamping rules. */
3
+ export declare function resolveSnackbarPresentation(question: PulseQuestion, fab: Fab | null): {
4
+ imageUrl: string | null | undefined;
5
+ placement: FabPlacement | undefined;
6
+ };
7
+ //# sourceMappingURL=snackbar-presentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snackbar-presentation.d.ts","sourceRoot":"","sources":["../../src/core/snackbar-presentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAehE,qFAAqF;AACrF,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;;;EAOnF"}
@@ -0,0 +1,121 @@
1
+ import type { Interaction, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, SidebandCoreConfig, SentimentPresentation, SimulatedPulseDefinition, SurveyAnswerMap, SurveyAnswerValue, SurveyPresentationKind, SyncResponse } from '../types';
2
+ export type FabState = 'hidden' | 'expanded';
3
+ export type SurveyAnswerDraft = {
4
+ answer_key?: string;
5
+ value?: string;
6
+ };
7
+ export type SurveySessionState = {
8
+ presentationId: number;
9
+ isSimulated: boolean;
10
+ snackbar: SnackbarState | null;
11
+ survey: Pulse;
12
+ answers: SurveyAnswerMap;
13
+ drafts: Record<string, SurveyAnswerDraft>;
14
+ currentNodeId: string | null;
15
+ completion: PulseCompletion | null;
16
+ history: string[];
17
+ fabState: FabState;
18
+ isOpen: boolean;
19
+ isBusy: boolean;
20
+ sentimentSelectionLocked: boolean;
21
+ isCompleting: boolean;
22
+ presentationConfirmed: boolean;
23
+ fabEntranceCompleted: boolean;
24
+ };
25
+ export type SnackbarState = {
26
+ phase: 'question' | 'feedback' | 'awaitingReady' | 'dwelling' | 'journey';
27
+ selectedKey: string | null;
28
+ startedAt: number | null;
29
+ deadline: number | null;
30
+ frozenFraction: number | null;
31
+ };
32
+ export type SurveyStoreSnapshot = {
33
+ state: SurveySessionState | null;
34
+ destroyed: boolean;
35
+ };
36
+ export type SurveyStoreUpdateReason = 'transition' | 'text' | 'select' | 'destroyed';
37
+ export type SurveyStoreListener = (reason?: SurveyStoreUpdateReason) => void;
38
+ type SurveyStoreDeps = {
39
+ syncInteraction: (interaction: Interaction) => Promise<unknown>;
40
+ trackEvent?: (eventName: string, metadata?: Record<string, string>) => void;
41
+ shouldPresentPulse?: SidebandCoreConfig['shouldPresentPulse'];
42
+ onRateApp?: SidebandCoreConfig['onRateApp'];
43
+ onError?: SidebandCoreConfig['onError'];
44
+ };
45
+ export declare function buildFabTitle(pulse: Pulse): string;
46
+ export declare function getChoiceValue(choice: PulseAnswer): string;
47
+ /** Identifies the reserved, case-sensitive canonical Other choice. */
48
+ export declare function isSystemOtherChoice(choice: PulseAnswer): boolean;
49
+ export declare function isPositiveSentimentChoice(choice: PulseAnswer): boolean;
50
+ /**
51
+ * Framework-neutral state machine for a canonical node-keyed pending pulse.
52
+ * Renderers confirm presentation explicitly; construction itself has no DOM
53
+ * dependency and its snapshots are stable between published updates.
54
+ */
55
+ export declare class SurveySessionStore {
56
+ private snapshot;
57
+ private listeners;
58
+ private readonly deps;
59
+ private fabTimeoutId;
60
+ private sentimentAdvanceTimeoutId;
61
+ private completionTransitionTimeoutId;
62
+ private destroyed;
63
+ private decisionGeneration;
64
+ private seenPulseKeys;
65
+ private presentedKeys;
66
+ constructor(deps: SurveyStoreDeps);
67
+ getState(): SurveySessionState | null;
68
+ getSnapshot(): SurveyStoreSnapshot;
69
+ getServerSnapshot(): SurveyStoreSnapshot;
70
+ subscribe(listener: SurveyStoreListener): () => void;
71
+ destroy(): void;
72
+ currentQuestion(): PulseQuestion | null;
73
+ currentAnswer(): SurveyAnswerValue | undefined;
74
+ currentDraft(): SurveyAnswerDraft | undefined;
75
+ currentText(): string;
76
+ isSentimentStep(): boolean;
77
+ sentimentChoices(): PulseAnswer[];
78
+ shouldShowContinue(): boolean;
79
+ progress(): number;
80
+ canContinue(): boolean;
81
+ handleSyncResponse(response: SyncResponse): Promise<void>;
82
+ /** Synchronously presents a validated canonical pulse without transport. */
83
+ presentPulse(pulse: Pulse, options?: {
84
+ sentimentPresentation?: SentimentPresentation;
85
+ }): boolean;
86
+ /** Simulation never reports impressions, responses, or rating requests to the host. */
87
+ presentSimulatedPulse(definition: SimulatedPulseDefinition): boolean;
88
+ private presentLocalPulse;
89
+ private beginPulse;
90
+ openSurvey(): void;
91
+ closeSurvey(): Promise<void>;
92
+ selectChoice(choice: PulseAnswer): Promise<void>;
93
+ setText(value: string): void;
94
+ advance(): Promise<void>;
95
+ handleCompletionAction(action: PulseCompletionAction): Promise<void>;
96
+ confirmPresentation(kind: SurveyPresentationKind, presentationId?: number): void;
97
+ confirmFabEntranceCompleted(presentationId?: number): void;
98
+ answerSnackbar(presentationId: number, choiceId: string): boolean;
99
+ /** The visible renderer calls this after expansion and content reveal finish. */
100
+ confirmSnackbarContentReady(presentationId: number): void;
101
+ private resolvePresentationDecision;
102
+ private sendPresentationDecline;
103
+ private commitCurrentAnswer;
104
+ private advanceFrom;
105
+ private completeTerminal;
106
+ private dismiss;
107
+ private dismissOrPartial;
108
+ private queueInteraction;
109
+ private emitPresentationEvent;
110
+ private scheduleFabTimeout;
111
+ private clearFabTimeout;
112
+ private clearSurveyTransitionTimeouts;
113
+ private rendersAsSentiment;
114
+ private projectedQuestionIds;
115
+ private projectedNextQuestionId;
116
+ private publish;
117
+ private reportError;
118
+ private isSystemOtherDraft;
119
+ }
120
+ export {};
121
+ //# sourceMappingURL=survey-session-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"survey-session-store.d.ts","sourceRoot":"","sources":["../../src/core/survey-session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EACL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2B,CAAC,cAAc,EAAE,MAAM;YAgBpC,2BAA2B;YAoB3B,uBAAuB;IAarC,OAAO,CAAC,mBAAmB;YAqDb,WAAW;YAkGX,gBAAgB;YAYhB,OAAO;YAIP,gBAAgB;YAyBhB,gBAAgB;IAS9B,OAAO,CAAC,qBAAqB;IAiB7B,OAAO,CAAC,kBAAkB;IAsC1B,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,6BAA6B;IAWrC,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,uBAAuB;IAqB/B,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,kBAAkB;CAU3B"}
@@ -0,0 +1,11 @@
1
+ import type { SyncOptions } from '../types';
2
+ export type SyncRetryReason = 'server_retry' | 'server_error' | 'network' | 'timeout';
3
+ export type SyncAttemptMetadata = {
4
+ attempt: number;
5
+ retryReason?: SyncRetryReason;
6
+ };
7
+ export declare function withSyncAttemptMetadata(options: SyncOptions, metadata: SyncAttemptMetadata): SyncOptions;
8
+ export declare function getSyncAttemptMetadata(options?: SyncOptions): SyncAttemptMetadata | undefined;
9
+ export declare function markFetchFailure(error: unknown): void;
10
+ export declare function isFetchFailure(error: unknown): boolean;
11
+ //# sourceMappingURL=sync-attempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-attempt.d.ts","sourceRoot":"","sources":["../../src/core/sync-attempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,CAAA;AAErF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B,CAAA;AASD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,mBAAmB,GAC5B,WAAW,CAIb;AAED,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,mBAAmB,GAAG,SAAS,CAE7F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,QAI9C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,WAK5C"}
@@ -0,0 +1,96 @@
1
+ import type { ClientContext, EventMetadata, EventRecord, Interaction, SyncOptions, SyncResponse, TrackedEvent } from '../types';
2
+ export type SyncEngineOptions = {
3
+ maxBatchSize?: number;
4
+ flushIntervalSeconds?: number;
5
+ retryIntervalSeconds?: number;
6
+ maxQueuedEvents?: number;
7
+ maxServerPacingSeconds?: number;
8
+ };
9
+ export type SyncEngineDeps = {
10
+ sendSync: (request: {
11
+ context?: ClientContext;
12
+ events?: EventRecord[];
13
+ interaction?: Interaction;
14
+ }, options?: SyncOptions) => Promise<SyncResponse>;
15
+ resolveContext?: () => Promise<ClientContext>;
16
+ onSyncResponse?: (response: SyncResponse, event?: TrackedEvent) => void | Promise<void>;
17
+ onError?: (error: unknown) => void;
18
+ };
19
+ /**
20
+ * Renderer-free event and interaction delivery. Construction deliberately has
21
+ * no browser side effects; call `start()` to enable lifecycle observation and
22
+ * queue the automatic launch event.
23
+ */
24
+ export declare class SyncEngine {
25
+ private readonly deps;
26
+ private readonly maxBatchSize;
27
+ private readonly flushIntervalMs;
28
+ private readonly retryIntervalMs;
29
+ private readonly maxQueuedEvents;
30
+ private queuedEvents;
31
+ private queuedInteractions;
32
+ private contextRevision;
33
+ private acknowledgedContextRevision;
34
+ private inFlightEventIds;
35
+ private timerId;
36
+ private timerDueAt;
37
+ private inFlight;
38
+ private abortController;
39
+ private regularDueAt;
40
+ private urgentDueAt;
41
+ private paceUntil;
42
+ private retryUntil;
43
+ private retrySnapshot;
44
+ private failureStreak;
45
+ private automaticRetrySuspended;
46
+ private overflowReported;
47
+ private started;
48
+ private destroyed;
49
+ private backgrounded;
50
+ private pendingLifecycleForce;
51
+ private pendingForcedRetry;
52
+ private manualFlushPromise;
53
+ private lastAttemptAccepted;
54
+ private detachLifecycle;
55
+ constructor(deps: SyncEngineDeps, options?: SyncEngineOptions);
56
+ start(): void;
57
+ track(eventName: string, metadata?: EventMetadata, options?: {
58
+ timestamp?: string;
59
+ }): void;
60
+ private enqueueEvent;
61
+ tagUser(previousUserId?: string | null, userId?: string | null, timestamp?: string): void;
62
+ submitInteraction(interaction: Interaction): void;
63
+ requestRegular(): void;
64
+ /** Records a decoded HTTP 200 obtained by a forced raw sync. */
65
+ observeResponse(response: SyncResponse): Promise<void>;
66
+ notePacing(response: SyncResponse): void;
67
+ flush(): Promise<void>;
68
+ destroy(): void;
69
+ private drainForcedSnapshots;
70
+ private requestRegularAt;
71
+ /**
72
+ * A confirmed pulse presentation or response interaction is time-sensitive,
73
+ * but still uses one bounded snapshot. Retry timing remains authoritative.
74
+ */
75
+ private requestUrgent;
76
+ private hasWork;
77
+ private createSnapshot;
78
+ private beginAttempt;
79
+ private runAttempt;
80
+ private handleDecodedResponse;
81
+ private handleFailure;
82
+ private clearRetryState;
83
+ private applyServerPacing;
84
+ private notifyResponse;
85
+ private afterAttempt;
86
+ private updateSchedule;
87
+ private scheduleTimer;
88
+ private clearTimer;
89
+ private hasUrgentWork;
90
+ private clearUrgencyIfSatisfied;
91
+ private enforceQueueLimit;
92
+ private attachLifecycle;
93
+ private requestLifecycleForce;
94
+ private reportError;
95
+ }
96
+ //# sourceMappingURL=sync-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/core/sync-engine.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,UAAU,CAAA;AAUjB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBA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AgEnC,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,iBAAiB;YAWX,cAAc;IAY5B,OAAO,CAAC,YAAY;IAuCpB,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,uBAAuB;IAW/B,OAAO,CAAC,iBAAiB;IAkCzB,OAAO,CAAC,eAAe;IAuCvB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,WAAW;CAWpB"}
@@ -0,0 +1,4 @@
1
+ import type { EventMetadata } from '../types';
2
+ export declare function validateApiKey(apiKey: string): void;
3
+ export declare function validateEvent(eventName: string, metadata?: EventMetadata): void;
4
+ //# sourceMappingURL=validate-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-input.d.ts","sourceRoot":"","sources":["../../src/core/validate-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,QAI5C;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,QAaxE"}
@@ -0,0 +1,11 @@
1
+ export { createSidebandClient, SidebandApiError } from './client/create-sideband-client';
2
+ export type { SidebandClient } from './client/create-sideband-client';
3
+ export { createContextResolver, getDeviceId, getSessionId } from './core/context';
4
+ export { createSidebandRuntime } from './core/create-sideband-runtime';
5
+ export { resolveSnackbarPresentation } from './core/snackbar-presentation';
6
+ export { SurveySessionStore, buildFabTitle, getChoiceValue, isSystemOtherChoice, isPositiveSentimentChoice, } from './core/survey-session-store';
7
+ export { SyncEngine } from './core/sync-engine';
8
+ export type { SyncEngineDeps, SyncEngineOptions } from './core/sync-engine';
9
+ export type { FabState, SurveyAnswerDraft, SnackbarState, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, } from './core/survey-session-store';
10
+ export type { AnsweredInteraction, ApiErrorDetail, ClientContext, CompletionActionStyle, CompletionActionType, CompletionIconType, CompletionType, DismissedInteraction, EventMetadata, EventRecord, Fab, FabOffset, FabPlacement, FabPoint, Interaction, Platform, PendingPulse, SyncEndpoint, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, QuestionType, SentimentPresentation, SimulatedPulseDefinition, SidebandClientConfig, SidebandCoreConfig, SidebandRuntime, SidebandRuntimeConfig, SurveyAnswerMap, SurveyAnswerValue, SurveyPresentationDecision, SurveyPresentationKind, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, } from './types';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAC1E,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3E,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAA;AACpC,Y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