@sidebandai/sideband-core 1.4.5-rc.1 → 1.4.5-rc.3
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/README.md +34 -0
- package/dist/client/create-sideband-client.d.ts +2 -0
- package/dist/client/create-sideband-client.d.ts.map +1 -1
- package/dist/core/create-sideband-runtime.d.ts.map +1 -1
- package/dist/core/pending-interactions.d.ts +28 -0
- package/dist/core/pending-interactions.d.ts.map +1 -0
- package/dist/core/sync-engine.d.ts +35 -0
- package/dist/core/sync-engine.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +260 -96
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,32 @@ sideband.start()
|
|
|
36
36
|
Replace `1.0.0` with your application's version, not the SDK version.
|
|
37
37
|
`appVersion` must be a non-empty string of at most 64 characters.
|
|
38
38
|
|
|
39
|
+
Create the runtime in the browser only. In a server-rendered app, create it from
|
|
40
|
+
client-side code and guard it so it starts once per page load.
|
|
41
|
+
|
|
42
|
+
## Content Security Policy
|
|
43
|
+
|
|
44
|
+
If your site sends a Content Security Policy, allow the Sideband API origin in
|
|
45
|
+
`connect-src`. Without it, the browser blocks every send.
|
|
46
|
+
|
|
47
|
+
| Endpoint | Origin to allow |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| Production (default) | `https://api.sideband.ai` |
|
|
50
|
+
| Development (`syncEndpoint: 'dev'`) | `https://api.dev-sideband.ai` |
|
|
51
|
+
| A custom `baseUrl` | That URL's origin |
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
connect-src 'self' https://api.sideband.ai
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Consent
|
|
58
|
+
|
|
59
|
+
Your app decides when Sideband runs. If Sideband needs consent on your site,
|
|
60
|
+
create and start the runtime only after the user gives it, and call
|
|
61
|
+
`sideband.destroy()` when the user withdraws it. Which consent category applies
|
|
62
|
+
is your decision; this README does not give legal advice. A user who declines
|
|
63
|
+
sends no events. The SDK has no consent setting of its own.
|
|
64
|
+
|
|
39
65
|
## Identify users
|
|
40
66
|
|
|
41
67
|
Tag the signed-in user wherever your app knows who they are: after sign-up and
|
|
@@ -96,6 +122,14 @@ pulses. After each send, the server sets a minimum wait before the next
|
|
|
96
122
|
regular send, and the SDK honors it. A pulse therefore usually shows a few
|
|
97
123
|
seconds after its trigger event, not exactly one second after it.
|
|
98
124
|
|
|
125
|
+
Ordinary event batches wait for that interval, so a trigger tracked soon after
|
|
126
|
+
a send waits for the rest of it, including after a client-side route change.
|
|
127
|
+
Some sends do not wait, and queued events go with them: a new pulse answer, a pulse
|
|
128
|
+
impression, the page being hidden, and an explicit `flush()`. On a quiet page, a
|
|
129
|
+
new page load sends `system_app_launch` about one second after the SDK starts,
|
|
130
|
+
with the default `flushIntervalSeconds`. Tagging the user right after start
|
|
131
|
+
sends it sooner.
|
|
132
|
+
|
|
99
133
|
## Events the SDK sends itself
|
|
100
134
|
|
|
101
135
|
Do not track these yourself:
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ClientContext, EventMetadata, SidebandClientConfig, SyncErrorResponse, SyncOptions, SyncRequest, SyncResponse, TrackOptions } from '../types';
|
|
2
|
+
/** The API base URL a client with this configuration sends to. */
|
|
3
|
+
export declare function resolveApiBaseUrl(config: Pick<SidebandClientConfig, 'baseUrl' | 'syncEndpoint'>): string;
|
|
2
4
|
export declare class SidebandApiError extends Error {
|
|
3
5
|
status: number;
|
|
4
6
|
body: SyncErrorResponse | unknown;
|
|
@@ -1 +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;
|
|
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;AAkCjB,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,cAAc,CAAC,UAE/F;AA2DD,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;uBAmDX,MAAM,aACN,aAAa,YACd,YAAY;EAsBzB;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-sideband-runtime.d.ts","sourceRoot":"","sources":["../../src/core/create-sideband-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-sideband-runtime.d.ts","sourceRoot":"","sources":["../../src/core/create-sideband-runtime.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAIV,eAAe,EACf,qBAAqB,EAItB,MAAM,UAAU,CAAA;AAEjB,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAoGpF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Interaction } from '../types';
|
|
2
|
+
export declare const PENDING_INTERACTIONS_STORAGE_PREFIX = "sideband:pending_interactions:";
|
|
3
|
+
export declare const MAX_STORED_INTERACTIONS = 10;
|
|
4
|
+
export declare const MAX_STORED_INTERACTION_AGE_MS: number;
|
|
5
|
+
export type StoredInteraction = {
|
|
6
|
+
interaction: Interaction;
|
|
7
|
+
user_id: string | null;
|
|
8
|
+
stored_at: number;
|
|
9
|
+
};
|
|
10
|
+
export type PendingInteractionStorageReason = 'storage_unavailable' | 'storage_write_failed' | 'queue_full';
|
|
11
|
+
/** A pending answer could not be kept across a page load, or an older one was evicted. */
|
|
12
|
+
export declare class PendingInteractionStorageError extends Error {
|
|
13
|
+
readonly reason: PendingInteractionStorageReason;
|
|
14
|
+
constructor(reason: PendingInteractionStorageReason, message: string, cause?: unknown);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Storage key for one channel configuration: a hash of the API key and the
|
|
18
|
+
* resolved API base URL, so another key or endpoint never reads these answers.
|
|
19
|
+
*/
|
|
20
|
+
export declare function pendingInteractionsStorageKey(apiKey: string, baseUrl: string): string;
|
|
21
|
+
/** Valid entries younger than a day, newest last. Throws only when storage is unusable. */
|
|
22
|
+
export declare function readStoredInteractions(key: string, now?: number): StoredInteraction[];
|
|
23
|
+
/**
|
|
24
|
+
* Writes the newest MAX_STORED_INTERACTIONS entries. Throws after writing when
|
|
25
|
+
* older entries were evicted, and when storage refuses the write.
|
|
26
|
+
*/
|
|
27
|
+
export declare function writeStoredInteractions(key: string, entries: StoredInteraction[]): void;
|
|
28
|
+
//# sourceMappingURL=pending-interactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-interactions.d.ts","sourceRoot":"","sources":["../../src/core/pending-interactions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAM3C,eAAO,MAAM,mCAAmC,mCAAmC,CAAA;AACnF,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC,eAAO,MAAM,6BAA6B,QAAsB,CAAA;AAIhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,WAAW,CAAA;IAExB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG,qBAAqB,GAAG,sBAAsB,GAAG,YAAY,CAAA;AAE3G,0FAA0F;AAC1F,qBAAa,8BAA+B,SAAQ,KAAK;IACvD,QAAQ,CAAC,MAAM,EAAE,+BAA+B,CAAA;gBAEpC,MAAM,EAAE,+BAA+B,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAKtF;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAE5E;AAgFD,2FAA2F;AAC3F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,iBAAiB,EAAE,CAuBzF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,QA0BhF"}
|
|
@@ -6,6 +6,21 @@ export type SyncEngineOptions = {
|
|
|
6
6
|
maxQueuedEvents?: number;
|
|
7
7
|
maxServerPacingSeconds?: number;
|
|
8
8
|
};
|
|
9
|
+
/** An interaction kept across a page load, with the user it may be sent for. */
|
|
10
|
+
export type PersistedInteraction = {
|
|
11
|
+
interaction: Interaction;
|
|
12
|
+
owner: string | null;
|
|
13
|
+
storedAt: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Keeps submitted interactions across a page load. `save` receives every
|
|
17
|
+
* interaction not yet accepted by the server, in send order, after each change.
|
|
18
|
+
* Either function may throw; the engine reports the error through `onError`.
|
|
19
|
+
*/
|
|
20
|
+
export type InteractionPersistence = {
|
|
21
|
+
restore: () => PersistedInteraction[];
|
|
22
|
+
save: (pending: PersistedInteraction[]) => void;
|
|
23
|
+
};
|
|
9
24
|
export type SyncEngineDeps = {
|
|
10
25
|
sendSync: (request: {
|
|
11
26
|
context?: ClientContext;
|
|
@@ -15,6 +30,13 @@ export type SyncEngineDeps = {
|
|
|
15
30
|
resolveContext?: () => Promise<ClientContext>;
|
|
16
31
|
onSyncResponse?: (response: SyncResponse, event?: TrackedEvent) => void | Promise<void>;
|
|
17
32
|
onError?: (error: unknown) => void;
|
|
33
|
+
interactionPersistence?: InteractionPersistence;
|
|
34
|
+
/**
|
|
35
|
+
* The user an interaction submitted now belongs to (the effective
|
|
36
|
+
* `context.user_id`, or null). When set, an interaction is only sent in a
|
|
37
|
+
* request whose resolved context has that same user.
|
|
38
|
+
*/
|
|
39
|
+
currentInteractionOwner?: () => string | null;
|
|
18
40
|
};
|
|
19
41
|
/**
|
|
20
42
|
* Renderer-free event and interaction delivery. Construction deliberately has
|
|
@@ -29,6 +51,11 @@ export declare class SyncEngine {
|
|
|
29
51
|
private readonly maxQueuedEvents;
|
|
30
52
|
private queuedEvents;
|
|
31
53
|
private queuedInteractions;
|
|
54
|
+
private restoredInteractions;
|
|
55
|
+
private replayedInteractions;
|
|
56
|
+
private interactionMeta;
|
|
57
|
+
private restoreReleaseTimer;
|
|
58
|
+
private unpersistedInteractions;
|
|
32
59
|
private contextRevision;
|
|
33
60
|
private acknowledgedContextRevision;
|
|
34
61
|
private inFlightEventIds;
|
|
@@ -105,6 +132,14 @@ export declare class SyncEngine {
|
|
|
105
132
|
private enforceQueueLimit;
|
|
106
133
|
private attachLifecycle;
|
|
107
134
|
private requestLifecycleForce;
|
|
135
|
+
private restoreInteractions;
|
|
136
|
+
private releaseRestoredInteractions;
|
|
137
|
+
private currentOwner;
|
|
138
|
+
private ownerMatches;
|
|
139
|
+
/** Queued interactions that may go out now: those owned by the current user. */
|
|
140
|
+
private sendableInteractions;
|
|
141
|
+
private dropInteraction;
|
|
142
|
+
private persistInteractions;
|
|
108
143
|
private reportError;
|
|
109
144
|
}
|
|
110
145
|
//# sourceMappingURL=sync-engine.d.ts.map
|
|
@@ -1 +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,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,CACR,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,aAAa,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE,EACvF,OAAO,CAAC,EAAE,WAAW,KAClB,OAAO,CAAC,YAAY,CAAC,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;IAC7C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"sync-engine.d.ts","sourceRoot":"","sources":["../../src/core/sync-engine.ts"],"names":[],"mappings":"AAOA,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,CAAC,eAAe;IAuCvB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,2BAA2B;IAcnC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;IAUpB,gFAAgF;IAChF,OAAO,CAAC,oBAAoB;IAW5B,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,mBAAmB;IAmB3B,OAAO,CAAC,WAAW;CAWpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ export { createSidebandRuntime } from './core/create-sideband-runtime';
|
|
|
5
5
|
export { resolveSnackbarPresentation } from './core/snackbar-presentation';
|
|
6
6
|
export { SurveySessionStore, buildFabTitle, getChoiceValue, isSystemOtherChoice, isPositiveSentimentChoice, } from './core/survey-session-store';
|
|
7
7
|
export { SyncEngine } from './core/sync-engine';
|
|
8
|
-
export type { SyncEngineDeps, SyncEngineOptions } from './core/sync-engine';
|
|
8
|
+
export type { InteractionPersistence, PersistedInteraction, SyncEngineDeps, SyncEngineOptions, } from './core/sync-engine';
|
|
9
|
+
export { PendingInteractionStorageError } from './core/pending-interactions';
|
|
10
|
+
export type { PendingInteractionStorageReason } from './core/pending-interactions';
|
|
9
11
|
export type { FabState, SurveyAnswerDraft, SnackbarState, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, } from './core/survey-session-store';
|
|
10
12
|
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, SentimentPresentationOptions, BarPosition, BarBehavior, SimulatedPulseDefinition, SidebandClientConfig, SidebandCoreConfig, SidebandRuntime, SidebandRuntimeConfig, SurveyAnswerMap, SurveyAnswerValue, SurveyPresentationDecision, SurveyPresentationKind, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, } from './types';
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,EACV,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,GAClB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAA;AAC5E,YAAY,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAA;AAClF,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAA;AACpC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,UAAU,EACV,UAAU,GACX,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ function d() {
|
|
|
52
52
|
r("local")?.removeItem(e);
|
|
53
53
|
} catch {}
|
|
54
54
|
}
|
|
55
|
-
function ee(e, t = "1.4.5-rc.
|
|
55
|
+
function ee(e, t = "1.4.5-rc.3") {
|
|
56
56
|
let n = {
|
|
57
57
|
device_id: s(),
|
|
58
58
|
platform: "web",
|
|
@@ -67,21 +67,21 @@ function ee(e, t = "1.4.5-rc.1") {
|
|
|
67
67
|
}
|
|
68
68
|
return n;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function f(e) {
|
|
71
71
|
return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function p(e, t, n) {
|
|
74
74
|
return async () => {
|
|
75
75
|
let r = typeof t == "function" ? await t() : t;
|
|
76
76
|
return {
|
|
77
77
|
...ee(e, n),
|
|
78
|
-
...
|
|
78
|
+
...f(r ?? {})
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
//#endregion
|
|
83
83
|
//#region src/core/validate-input.ts
|
|
84
|
-
function
|
|
84
|
+
function te(e) {
|
|
85
85
|
if (typeof e != "string" || !e.trim()) throw TypeError("Sideband.configure apiKey must be a non-empty string.");
|
|
86
86
|
}
|
|
87
87
|
function m(e, t = "Sideband.configure appVersion") {
|
|
@@ -94,51 +94,54 @@ function h(e, t) {
|
|
|
94
94
|
for (let [e, n] of Object.entries(t)) if (typeof n != "string") throw TypeError(`Sideband.track metadata value for "${e}" must be a string.`);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function g(e) {
|
|
98
98
|
return Array.from(e).length;
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
100
|
+
function _(e) {
|
|
101
|
+
return g(e) > 256;
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region src/core/sync-attempt.ts
|
|
105
|
-
var
|
|
106
|
-
function
|
|
105
|
+
var v = Symbol("sideband.syncAttemptMetadata"), y = /* @__PURE__ */ new WeakSet();
|
|
106
|
+
function ne(e, t) {
|
|
107
107
|
let n = { ...e };
|
|
108
|
-
return n[
|
|
108
|
+
return n[v] = t, n;
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
return e?.[
|
|
110
|
+
function re(e) {
|
|
111
|
+
return e?.[v];
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
(typeof e == "object" && e || typeof e == "function") &&
|
|
113
|
+
function ie(e) {
|
|
114
|
+
(typeof e == "object" && e || typeof e == "function") && y.add(e);
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
return (typeof e == "object" && !!e || typeof e == "function") &&
|
|
116
|
+
function b(e) {
|
|
117
|
+
return (typeof e == "object" && !!e || typeof e == "function") && y.has(e);
|
|
118
118
|
}
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region src/client/create-sideband-client.ts
|
|
121
|
-
var
|
|
121
|
+
var x = "/v1/sync", S = {
|
|
122
122
|
local: "https://api.pancake-betelgeuse.ts.net",
|
|
123
123
|
dev: "https://api.dev-sideband.ai",
|
|
124
124
|
prod: "https://api.sideband.ai"
|
|
125
125
|
};
|
|
126
|
-
function
|
|
126
|
+
function ae(e) {
|
|
127
127
|
if (e) return e;
|
|
128
128
|
if (typeof fetch != "function") throw Error("Sideband requires a fetch implementation.");
|
|
129
129
|
return fetch;
|
|
130
130
|
}
|
|
131
|
-
async function
|
|
131
|
+
async function oe(e) {
|
|
132
132
|
return typeof e == "function" ? await e() : e;
|
|
133
133
|
}
|
|
134
|
-
async function
|
|
134
|
+
async function se(e) {
|
|
135
135
|
let t = typeof e == "function" ? await e() : e;
|
|
136
136
|
return new Headers(t);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
return
|
|
138
|
+
function C(e) {
|
|
139
|
+
return e.baseUrl ?? S[e.syncEndpoint ?? "prod"];
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
function ce(e) {
|
|
142
|
+
return new URL(x, e).toString();
|
|
143
|
+
}
|
|
144
|
+
async function le(e) {
|
|
142
145
|
let t = await e.text();
|
|
143
146
|
if (!t) return null;
|
|
144
147
|
try {
|
|
@@ -147,10 +150,10 @@ async function se(e) {
|
|
|
147
150
|
return t;
|
|
148
151
|
}
|
|
149
152
|
}
|
|
150
|
-
function
|
|
153
|
+
function ue(e, t) {
|
|
151
154
|
return typeof e == "object" && e && "error" in e && typeof e.error == "object" && e.error !== null && "message" in e.error && typeof e.error.message == "string" ? e.error.message : t;
|
|
152
155
|
}
|
|
153
|
-
function
|
|
156
|
+
function de(e) {
|
|
154
157
|
let t = e.headers.get("retry-after");
|
|
155
158
|
if (!t) return;
|
|
156
159
|
let n = Number(t);
|
|
@@ -158,7 +161,7 @@ function le(e) {
|
|
|
158
161
|
let r = Date.parse(t);
|
|
159
162
|
if (!Number.isNaN(r)) return Math.max((r - Date.now()) / 1e3, 0);
|
|
160
163
|
}
|
|
161
|
-
var
|
|
164
|
+
var w = class extends Error {
|
|
162
165
|
status;
|
|
163
166
|
body;
|
|
164
167
|
retryAfterSeconds;
|
|
@@ -166,14 +169,14 @@ var T = class extends Error {
|
|
|
166
169
|
super(e), this.name = "SidebandApiError", this.status = t, this.body = n, this.retryAfterSeconds = r;
|
|
167
170
|
}
|
|
168
171
|
};
|
|
169
|
-
function
|
|
170
|
-
if (
|
|
172
|
+
function T(e) {
|
|
173
|
+
if (te(e.apiKey), e.syncEndpoint !== void 0 && !Object.hasOwn(S, e.syncEndpoint)) throw TypeError("Sideband.configure syncEndpoint must be local, dev, or prod.");
|
|
171
174
|
async function t(t, n) {
|
|
172
|
-
let r =
|
|
175
|
+
let r = ae(e.fetch), i = t.context ?? await oe(e.context);
|
|
173
176
|
m(i.app_version, "Sideband context.app_version");
|
|
174
|
-
let a = await
|
|
177
|
+
let a = await se(e.headers), o = re(n);
|
|
175
178
|
a.set("content-type", "application/json"), a.set("x-bc-api-key", e.apiKey), a.set("x-bc-sync-attempt", String(o?.attempt ?? 1)), o?.retryReason ? a.set("x-bc-sync-retry-reason", o.retryReason) : a.delete("x-bc-sync-retry-reason");
|
|
176
|
-
let s =
|
|
179
|
+
let s = ce(C(e)), c = {
|
|
177
180
|
method: "POST",
|
|
178
181
|
headers: a,
|
|
179
182
|
body: JSON.stringify({
|
|
@@ -186,10 +189,10 @@ function E(e) {
|
|
|
186
189
|
try {
|
|
187
190
|
l = await r(s, c);
|
|
188
191
|
} catch (e) {
|
|
189
|
-
throw
|
|
192
|
+
throw ie(e), e;
|
|
190
193
|
}
|
|
191
|
-
let u = await
|
|
192
|
-
if (!l.ok) throw new
|
|
194
|
+
let u = await le(l);
|
|
195
|
+
if (!l.ok) throw new w(ue(u, "Sideband sync request failed."), l.status, u, de(l));
|
|
193
196
|
return u;
|
|
194
197
|
}
|
|
195
198
|
async function r(e, r, i) {
|
|
@@ -206,23 +209,105 @@ function E(e) {
|
|
|
206
209
|
};
|
|
207
210
|
}
|
|
208
211
|
//#endregion
|
|
212
|
+
//#region src/core/pending-interactions.ts
|
|
213
|
+
var fe = "sideband:pending_interactions:", pe = 1440 * 60 * 1e3, E = /* @__PURE__ */ new Set([
|
|
214
|
+
"completed",
|
|
215
|
+
"partial",
|
|
216
|
+
"not_now",
|
|
217
|
+
"never"
|
|
218
|
+
]), D = class extends Error {
|
|
219
|
+
reason;
|
|
220
|
+
constructor(e, t, n) {
|
|
221
|
+
super(t, n === void 0 ? void 0 : { cause: n }), this.name = "PendingInteractionStorageError", this.reason = e;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
function O(e, t) {
|
|
225
|
+
return `${fe}${k(`${t}\n${e}`)}`;
|
|
226
|
+
}
|
|
227
|
+
function k(e) {
|
|
228
|
+
let t = 3735928559, n = 1103547991;
|
|
229
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
230
|
+
let i = e.charCodeAt(r);
|
|
231
|
+
t = Math.imul(t ^ i, 2654435761), n = Math.imul(n ^ i, 1597334677);
|
|
232
|
+
}
|
|
233
|
+
return t = Math.imul(t ^ t >>> 16, 2246822507) ^ Math.imul(n ^ n >>> 13, 3266489909), n = Math.imul(n ^ n >>> 16, 2246822507) ^ Math.imul(t ^ t >>> 13, 3266489909), (4294967296 * (2097151 & n) + (t >>> 0)).toString(36);
|
|
234
|
+
}
|
|
235
|
+
function A() {
|
|
236
|
+
if (typeof window > "u") return null;
|
|
237
|
+
try {
|
|
238
|
+
return window.sessionStorage;
|
|
239
|
+
} catch (e) {
|
|
240
|
+
throw new D("storage_unavailable", "Sideband cannot use sessionStorage; pending answers are kept for this page only.", e);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function j(e) {
|
|
244
|
+
return e === void 0 || typeof e == "string";
|
|
245
|
+
}
|
|
246
|
+
function M(e) {
|
|
247
|
+
return !!e && typeof e == "object" && !Array.isArray(e) && Object.values(e).every((e) => {
|
|
248
|
+
if (!e || typeof e != "object") return !1;
|
|
249
|
+
let t = e;
|
|
250
|
+
return typeof t.answered_at == "string" && j(t.answer_key) && j(t.value);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function N(e) {
|
|
254
|
+
if (!e || typeof e != "object") return !1;
|
|
255
|
+
let t = e;
|
|
256
|
+
return typeof t.pulse_id != "string" || typeof t.action != "string" || !E.has(t.action) || t.pulse_version !== void 0 && typeof t.pulse_version != "number" || !j(t.impression_id) || !j(t.responded_at) ? !1 : t.action === "completed" || t.action === "partial" ? M(t.answers) && j(t.completion_action_id) : !0;
|
|
257
|
+
}
|
|
258
|
+
function P(e) {
|
|
259
|
+
if (!e || typeof e != "object") return !1;
|
|
260
|
+
let t = e;
|
|
261
|
+
return typeof t.stored_at == "number" && (t.user_id === null || typeof t.user_id == "string") && N(t.interaction);
|
|
262
|
+
}
|
|
263
|
+
function F(e, t = Date.now()) {
|
|
264
|
+
let n = A(), r;
|
|
265
|
+
try {
|
|
266
|
+
r = n?.getItem(e) ?? null;
|
|
267
|
+
} catch (e) {
|
|
268
|
+
throw new D("storage_unavailable", "Sideband could not read pending answers.", e);
|
|
269
|
+
}
|
|
270
|
+
if (!r) return [];
|
|
271
|
+
try {
|
|
272
|
+
let e = JSON.parse(r);
|
|
273
|
+
return Array.isArray(e) ? e.filter(P).filter((e) => t - e.stored_at < pe).slice(-10) : [];
|
|
274
|
+
} catch {
|
|
275
|
+
return [];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function I(e, t) {
|
|
279
|
+
let n = A();
|
|
280
|
+
if (!n) return;
|
|
281
|
+
let r = t.slice(-10);
|
|
282
|
+
try {
|
|
283
|
+
r.length ? n.setItem(e, JSON.stringify(r)) : n.removeItem(e);
|
|
284
|
+
} catch (e) {
|
|
285
|
+
throw new D("storage_write_failed", "Sideband could not save pending answers to sessionStorage (it may be full); they are kept for this page only.", e);
|
|
286
|
+
}
|
|
287
|
+
if (r.length < t.length) throw new D("queue_full", "Sideband keeps at most 10 pending answers across page loads; the oldest were not saved.");
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
209
290
|
//#region src/core/sync-engine.ts
|
|
210
|
-
var
|
|
211
|
-
function
|
|
291
|
+
var L = 20, R = 50, z = 1, B = 15, me = 1e3, he = 300 * 1e3, ge = 2147483647, _e = 1e4;
|
|
292
|
+
function ve(e, t, n) {
|
|
212
293
|
return Math.min(Math.max(e, t), n);
|
|
213
294
|
}
|
|
214
|
-
function
|
|
295
|
+
function ye(e) {
|
|
296
|
+
let t = e?.status;
|
|
297
|
+
return typeof t == "number" ? t : void 0;
|
|
298
|
+
}
|
|
299
|
+
function be(e) {
|
|
215
300
|
let t = e?.status;
|
|
216
301
|
return typeof t != "number" || t === 408 || t === 425 || t === 429 || t >= 500;
|
|
217
302
|
}
|
|
218
|
-
function
|
|
303
|
+
function V(e) {
|
|
219
304
|
let t = e?.retryAfterSeconds;
|
|
220
305
|
return typeof t == "number" && Number.isFinite(t) ? Math.max(t, 0) * 1e3 : void 0;
|
|
221
306
|
}
|
|
222
|
-
function
|
|
223
|
-
return e?.status === 503 &&
|
|
307
|
+
function xe(e) {
|
|
308
|
+
return e?.status === 503 && V(e) !== void 0 ? "server_retry" : b(e) ? "network" : "server_error";
|
|
224
309
|
}
|
|
225
|
-
var
|
|
310
|
+
var H = class {
|
|
226
311
|
deps;
|
|
227
312
|
maxBatchSize;
|
|
228
313
|
flushIntervalMs;
|
|
@@ -230,6 +315,11 @@ var R = class {
|
|
|
230
315
|
maxQueuedEvents;
|
|
231
316
|
queuedEvents = [];
|
|
232
317
|
queuedInteractions = [];
|
|
318
|
+
restoredInteractions = [];
|
|
319
|
+
replayedInteractions = /* @__PURE__ */ new WeakSet();
|
|
320
|
+
interactionMeta = /* @__PURE__ */ new WeakMap();
|
|
321
|
+
restoreReleaseTimer = null;
|
|
322
|
+
unpersistedInteractions = /* @__PURE__ */ new WeakSet();
|
|
233
323
|
contextRevision = 0;
|
|
234
324
|
acknowledgedContextRevision = 0;
|
|
235
325
|
inFlightEventIds = /* @__PURE__ */ new Set();
|
|
@@ -257,10 +347,10 @@ var R = class {
|
|
|
257
347
|
syncAttempts = 0;
|
|
258
348
|
detachLifecycle = null;
|
|
259
349
|
constructor(e, t = {}) {
|
|
260
|
-
this.deps = e, this.maxBatchSize =
|
|
350
|
+
this.deps = e, this.maxBatchSize = ve(t.maxBatchSize ?? L, 1, R), this.flushIntervalMs = Math.max(t.flushIntervalSeconds ?? z, 1) * 1e3, this.retryIntervalMs = Math.max(t.retryIntervalSeconds ?? B, 1) * 1e3, this.maxQueuedEvents = Math.max(t.maxQueuedEvents ?? me, this.maxBatchSize);
|
|
261
351
|
}
|
|
262
352
|
start() {
|
|
263
|
-
this.started || this.destroyed || (this.started = !0, this.attachLifecycle(), this.track("system_app_launch"));
|
|
353
|
+
this.started || this.destroyed || (this.started = !0, this.restoreInteractions(), this.attachLifecycle(), this.track("system_app_launch"));
|
|
264
354
|
}
|
|
265
355
|
getDeliveryStatus() {
|
|
266
356
|
let e = new Set([...this.queuedEvents, ...this.retrySnapshot?.events ?? []].map((e) => e.record.event_id));
|
|
@@ -269,7 +359,7 @@ var R = class {
|
|
|
269
359
|
acceptedInteractions: this.acceptedInteractions,
|
|
270
360
|
syncAttempts: this.syncAttempts,
|
|
271
361
|
pendingEvents: e.size,
|
|
272
|
-
pendingInteractions: this.queuedInteractions.length,
|
|
362
|
+
pendingInteractions: this.queuedInteractions.length + this.restoredInteractions.length,
|
|
273
363
|
hasPendingContext: this.contextRevision > this.acknowledgedContextRevision,
|
|
274
364
|
isSyncing: this.inFlight !== null,
|
|
275
365
|
isTerminal: this.destroyed || this.automaticRetrySuspended
|
|
@@ -310,7 +400,10 @@ var R = class {
|
|
|
310
400
|
}
|
|
311
401
|
}
|
|
312
402
|
submitInteraction(e) {
|
|
313
|
-
this.destroyed || (this.
|
|
403
|
+
this.destroyed || (this.interactionMeta.set(e, {
|
|
404
|
+
owner: this.currentOwner(),
|
|
405
|
+
storedAt: Date.now()
|
|
406
|
+
}), this.queuedInteractions.push(e), this.persistInteractions(), this.requestUrgent());
|
|
314
407
|
}
|
|
315
408
|
requestRegular() {
|
|
316
409
|
this.requestRegularAt(Date.now());
|
|
@@ -327,7 +420,7 @@ var R = class {
|
|
|
327
420
|
}), this.manualFlushPromise;
|
|
328
421
|
}
|
|
329
422
|
destroy() {
|
|
330
|
-
this.destroyed || (this.destroyed = !0, this.clearTimer(), this.detachLifecycle?.(), this.detachLifecycle = null, this.abortController?.abort(), this.abortController = null, this.pendingLifecycleForce = !1);
|
|
423
|
+
this.destroyed || (this.destroyed = !0, this.clearTimer(), this.restoreReleaseTimer !== null && (clearTimeout(this.restoreReleaseTimer), this.restoreReleaseTimer = null), this.detachLifecycle?.(), this.detachLifecycle = null, this.abortController?.abort(), this.abortController = null, this.pendingLifecycleForce = !1);
|
|
331
424
|
}
|
|
332
425
|
async drainForcedSnapshots() {
|
|
333
426
|
for (; !this.destroyed;) {
|
|
@@ -352,7 +445,7 @@ var R = class {
|
|
|
352
445
|
this.urgentDueAt = this.urgentDueAt === null ? e : Math.min(this.urgentDueAt, e), this.updateSchedule();
|
|
353
446
|
}
|
|
354
447
|
hasWork() {
|
|
355
|
-
return this.queuedEvents.length > 0 || this.
|
|
448
|
+
return this.queuedEvents.length > 0 || this.sendableInteractions().length > 0 || this.contextRevision > this.acknowledgedContextRevision;
|
|
356
449
|
}
|
|
357
450
|
createSnapshot(e) {
|
|
358
451
|
let t = this.queuedEvents.slice(0, this.maxBatchSize);
|
|
@@ -367,9 +460,10 @@ var R = class {
|
|
|
367
460
|
t = [...this.queuedEvents.filter((e) => !r.has(e)).slice(0, e - n.length), ...n];
|
|
368
461
|
}
|
|
369
462
|
}
|
|
370
|
-
|
|
463
|
+
let n = this.sendableInteractions(), r = e === "forced-lifecycle" ? n.find((e) => !this.replayedInteractions.has(e)) : n[0];
|
|
464
|
+
return r && this.replayedInteractions.has(r) && (t = []), {
|
|
371
465
|
events: t,
|
|
372
|
-
interaction:
|
|
466
|
+
interaction: r,
|
|
373
467
|
contextRevision: this.contextRevision,
|
|
374
468
|
attempt: 1,
|
|
375
469
|
trigger: e
|
|
@@ -389,12 +483,13 @@ var R = class {
|
|
|
389
483
|
}
|
|
390
484
|
async runAttempt(e, t) {
|
|
391
485
|
try {
|
|
392
|
-
!e.context && this.deps.resolveContext && (e.context = { ...await this.deps.resolveContext() }), this.
|
|
486
|
+
if (!e.context && this.deps.resolveContext && (e.context = { ...await this.deps.resolveContext() }), e.interaction && !this.ownerMatches(e.interaction, e.context) && (e.interaction = void 0, !e.events.length && e.contextRevision <= this.acknowledgedContextRevision)) return;
|
|
487
|
+
this.syncAttempts++;
|
|
393
488
|
let n = await this.deps.sendSync({
|
|
394
489
|
...e.context ? { context: e.context } : {},
|
|
395
490
|
...e.events.length ? { events: e.events.map((e) => e.record) } : {},
|
|
396
491
|
...e.interaction ? { interaction: e.interaction } : {}
|
|
397
|
-
},
|
|
492
|
+
}, ne({
|
|
398
493
|
signal: t,
|
|
399
494
|
...e.trigger === "forced-lifecycle" ? { keepalive: !0 } : {}
|
|
400
495
|
}, {
|
|
@@ -415,9 +510,9 @@ var R = class {
|
|
|
415
510
|
}
|
|
416
511
|
if (e.accepted && t.interaction) {
|
|
417
512
|
let e = this.queuedInteractions.indexOf(t.interaction);
|
|
418
|
-
e >= 0 && (this.acceptedInteractions++, this.queuedInteractions.splice(e, 1));
|
|
513
|
+
e >= 0 && (this.acceptedInteractions++, this.queuedInteractions.splice(e, 1), this.persistInteractions());
|
|
419
514
|
}
|
|
420
|
-
if (await this.notifyResponse(e, t.events.length ? t.events[t.events.length - 1]?.tagEvent : void 0), !e.accepted) {
|
|
515
|
+
if (e.accepted && this.releaseRestoredInteractions(), await this.notifyResponse(e, t.events.length ? t.events[t.events.length - 1]?.tagEvent : void 0), !e.accepted) {
|
|
421
516
|
this.regularDueAt = null, this.urgentDueAt = null;
|
|
422
517
|
return;
|
|
423
518
|
}
|
|
@@ -432,12 +527,16 @@ var R = class {
|
|
|
432
527
|
this.hasWork() && !this.manualFlushPromise && this.requestRegular();
|
|
433
528
|
}
|
|
434
529
|
handleFailure(e, t) {
|
|
435
|
-
if (this.lastAttemptAccepted = !1,
|
|
436
|
-
this.
|
|
530
|
+
if (this.lastAttemptAccepted = !1, t.interaction && ye(e) === 404) {
|
|
531
|
+
this.dropInteraction(t.interaction), this.clearRetryState(), this.reportError(e), this.regularDueAt = null, this.urgentDueAt = null, this.requestRegular();
|
|
437
532
|
return;
|
|
438
533
|
}
|
|
439
|
-
|
|
440
|
-
|
|
534
|
+
if (!be(e)) {
|
|
535
|
+
t.interaction && (this.unpersistedInteractions.add(t.interaction), this.persistInteractions()), this.retrySnapshot = null, this.automaticRetrySuspended = !0, this.regularDueAt = null, this.reportError(e);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
this.failureStreak += 1, t.attempt = Math.min(t.attempt + 1, 1e3), t.retryReason = xe(e), this.retrySnapshot = t;
|
|
539
|
+
let n = V(e), r = Math.min(this.retryIntervalMs * 2 ** (this.failureStreak - 1), he) * (.5 + Math.random() * .5), i = Math.max(r, n ?? 0);
|
|
441
540
|
this.retryUntil = Date.now() + i, this.regularDueAt = this.retryUntil, t.trigger !== "regular" && (this.pendingForcedRetry = t.trigger), this.failureStreak === 1 && this.reportError(e);
|
|
442
541
|
}
|
|
443
542
|
clearRetryState() {
|
|
@@ -498,13 +597,13 @@ var R = class {
|
|
|
498
597
|
}
|
|
499
598
|
this.pendingForcedRetry = null, this.beginAttempt(t);
|
|
500
599
|
}
|
|
501
|
-
}, Math.min(Math.max(e - Date.now(), 0),
|
|
600
|
+
}, Math.min(Math.max(e - Date.now(), 0), ge)));
|
|
502
601
|
}
|
|
503
602
|
clearTimer() {
|
|
504
603
|
this.timerId !== null && (clearTimeout(this.timerId), this.timerId = null), this.timerDueAt = null;
|
|
505
604
|
}
|
|
506
605
|
hasUrgentWork() {
|
|
507
|
-
return this.
|
|
606
|
+
return this.sendableInteractions().length > 0 || this.queuedEvents.some((e) => e.record.event_name === "system_did_present_pulse");
|
|
508
607
|
}
|
|
509
608
|
clearUrgencyIfSatisfied() {
|
|
510
609
|
this.hasUrgentWork() || (this.urgentDueAt = null, this.pendingForcedRetry === "urgent" && (this.pendingForcedRetry = null));
|
|
@@ -552,6 +651,56 @@ var R = class {
|
|
|
552
651
|
this.hasWork() && this.beginAttempt("forced-lifecycle");
|
|
553
652
|
}
|
|
554
653
|
}
|
|
654
|
+
restoreInteractions() {
|
|
655
|
+
if (!this.deps.interactionPersistence) return;
|
|
656
|
+
let e = [];
|
|
657
|
+
try {
|
|
658
|
+
e = this.deps.interactionPersistence.restore();
|
|
659
|
+
} catch (e) {
|
|
660
|
+
this.reportError(e);
|
|
661
|
+
}
|
|
662
|
+
this.restoredInteractions = e.map((e) => (this.interactionMeta.set(e.interaction, {
|
|
663
|
+
owner: e.owner,
|
|
664
|
+
storedAt: e.storedAt
|
|
665
|
+
}), this.replayedInteractions.add(e.interaction), e.interaction)), this.restoredInteractions.length && (this.restoreReleaseTimer = setTimeout(() => {
|
|
666
|
+
this.restoreReleaseTimer = null, !(this.destroyed || !this.restoredInteractions.length) && (this.releaseRestoredInteractions(), this.requestRegular());
|
|
667
|
+
}, _e));
|
|
668
|
+
}
|
|
669
|
+
releaseRestoredInteractions() {
|
|
670
|
+
this.restoreReleaseTimer !== null && (clearTimeout(this.restoreReleaseTimer), this.restoreReleaseTimer = null), this.restoredInteractions.length && (this.queuedInteractions = [...this.restoredInteractions, ...this.queuedInteractions], this.restoredInteractions = []);
|
|
671
|
+
}
|
|
672
|
+
currentOwner() {
|
|
673
|
+
return this.deps.currentInteractionOwner ? this.deps.currentInteractionOwner() : null;
|
|
674
|
+
}
|
|
675
|
+
ownerMatches(e, t) {
|
|
676
|
+
return !this.deps.currentInteractionOwner || (this.interactionMeta.get(e)?.owner ?? null) === (t ? t.user_id ?? null : this.currentOwner());
|
|
677
|
+
}
|
|
678
|
+
sendableInteractions() {
|
|
679
|
+
if (!this.deps.currentInteractionOwner) return this.queuedInteractions;
|
|
680
|
+
let e = this.currentOwner();
|
|
681
|
+
return this.queuedInteractions.filter((t) => (this.interactionMeta.get(t)?.owner ?? null) === e);
|
|
682
|
+
}
|
|
683
|
+
dropInteraction(e) {
|
|
684
|
+
let t = this.queuedInteractions.indexOf(e);
|
|
685
|
+
t >= 0 && this.queuedInteractions.splice(t, 1), this.persistInteractions();
|
|
686
|
+
}
|
|
687
|
+
persistInteractions() {
|
|
688
|
+
if (this.deps.interactionPersistence) try {
|
|
689
|
+
this.deps.interactionPersistence.save([...this.restoredInteractions, ...this.queuedInteractions].filter((e) => !this.unpersistedInteractions.has(e)).map((e) => {
|
|
690
|
+
let t = this.interactionMeta.get(e) ?? {
|
|
691
|
+
owner: this.currentOwner(),
|
|
692
|
+
storedAt: Date.now()
|
|
693
|
+
};
|
|
694
|
+
return {
|
|
695
|
+
interaction: e,
|
|
696
|
+
owner: t.owner,
|
|
697
|
+
storedAt: t.storedAt
|
|
698
|
+
};
|
|
699
|
+
}));
|
|
700
|
+
} catch (e) {
|
|
701
|
+
this.reportError(e);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
555
704
|
reportError(e) {
|
|
556
705
|
try {
|
|
557
706
|
this.deps.onError ? this.deps.onError(e) : console.error("[sideband]", e);
|
|
@@ -560,65 +709,80 @@ var R = class {
|
|
|
560
709
|
};
|
|
561
710
|
//#endregion
|
|
562
711
|
//#region src/core/create-sideband-runtime.ts
|
|
563
|
-
function
|
|
712
|
+
function Se(e) {
|
|
564
713
|
m(e.appVersion);
|
|
565
|
-
let t =
|
|
714
|
+
let t = Ce(e.onError), n = p(e.appVersion, e.context, e.libraryVersion), r = e.context && typeof e.context == "object" ? e.context.user_id ?? null : null, i = async () => {
|
|
566
715
|
let e = await n();
|
|
567
|
-
return t === null ? e : {
|
|
716
|
+
return r = e.user_id ?? null, t === null ? e : {
|
|
568
717
|
...e,
|
|
569
718
|
user_id: t
|
|
570
719
|
};
|
|
571
|
-
},
|
|
720
|
+
}, a = T({
|
|
572
721
|
baseUrl: e.baseUrl,
|
|
573
722
|
syncEndpoint: e.syncEndpoint,
|
|
574
723
|
apiKey: e.apiKey,
|
|
575
|
-
context:
|
|
724
|
+
context: i,
|
|
576
725
|
headers: e.headers,
|
|
577
726
|
fetch: e.fetch
|
|
578
|
-
}),
|
|
579
|
-
sendSync: (e, t) =>
|
|
580
|
-
resolveContext:
|
|
727
|
+
}), o = O(e.apiKey, C(e)), c = new H({
|
|
728
|
+
sendSync: (e, t) => a.sync(e, t),
|
|
729
|
+
resolveContext: i,
|
|
581
730
|
onSyncResponse: e.onSyncResponse,
|
|
582
|
-
onError: e.onError
|
|
731
|
+
onError: e.onError,
|
|
732
|
+
interactionPersistence: {
|
|
733
|
+
restore: () => F(o).map((e) => ({
|
|
734
|
+
interaction: e.interaction,
|
|
735
|
+
owner: e.user_id,
|
|
736
|
+
storedAt: e.stored_at
|
|
737
|
+
})),
|
|
738
|
+
save: (e) => {
|
|
739
|
+
I(o, e.map((e) => ({
|
|
740
|
+
interaction: e.interaction,
|
|
741
|
+
user_id: e.owner,
|
|
742
|
+
stored_at: e.storedAt
|
|
743
|
+
})));
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
currentInteractionOwner: () => t ?? r
|
|
583
747
|
}, {
|
|
584
748
|
maxBatchSize: e.maxBatchSize,
|
|
585
749
|
flushIntervalSeconds: e.flushIntervalSeconds,
|
|
586
750
|
retryIntervalSeconds: e.retryIntervalSeconds,
|
|
587
751
|
maxQueuedEvents: e.maxQueuedEvents,
|
|
588
752
|
maxServerPacingSeconds: e.maxServerPacingSeconds
|
|
589
|
-
}),
|
|
590
|
-
if (n !== null &&
|
|
753
|
+
}), l = (n) => {
|
|
754
|
+
if (n !== null && _(n)) {
|
|
591
755
|
e.onError?.(/* @__PURE__ */ Error("Sideband.tagUser rejected a user ID longer than 256 characters."));
|
|
592
756
|
return;
|
|
593
757
|
}
|
|
594
758
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = t;
|
|
595
|
-
t = n, n === null ? d() : u(n),
|
|
759
|
+
t = n, n === null ? d() : u(n), c.tagUser(i, n, r);
|
|
596
760
|
};
|
|
597
761
|
return {
|
|
598
|
-
getDeliveryStatus: () =>
|
|
599
|
-
start: () =>
|
|
762
|
+
getDeliveryStatus: () => c.getDeliveryStatus(),
|
|
763
|
+
start: () => c.start(),
|
|
600
764
|
track: (e, t, n) => {
|
|
601
|
-
|
|
765
|
+
c.track(e, t, n);
|
|
602
766
|
},
|
|
603
|
-
tagUser: (e) =>
|
|
604
|
-
untagUser: () =>
|
|
605
|
-
submitInteraction: (e) =>
|
|
767
|
+
tagUser: (e) => l(e),
|
|
768
|
+
untagUser: () => l(null),
|
|
769
|
+
submitInteraction: (e) => c.submitInteraction(e),
|
|
606
770
|
async sync(e, t) {
|
|
607
|
-
let n = await
|
|
608
|
-
return await
|
|
771
|
+
let n = await a.sync(e, t);
|
|
772
|
+
return await c.observeResponse(n), n;
|
|
609
773
|
},
|
|
610
|
-
flush: () =>
|
|
774
|
+
flush: () => c.flush(),
|
|
611
775
|
getDeviceId: s,
|
|
612
|
-
destroy: () =>
|
|
776
|
+
destroy: () => c.destroy()
|
|
613
777
|
};
|
|
614
778
|
}
|
|
615
|
-
function
|
|
779
|
+
function Ce(e) {
|
|
616
780
|
let t = l();
|
|
617
|
-
return t === null || !
|
|
781
|
+
return t === null || !_(t) ? t : (d(), e?.(/* @__PURE__ */ Error("Sideband cleared a stored user ID longer than 256 characters.")), null);
|
|
618
782
|
}
|
|
619
783
|
//#endregion
|
|
620
784
|
//#region src/core/snackbar-presentation.ts
|
|
621
|
-
function
|
|
785
|
+
function we(e) {
|
|
622
786
|
if (!e || typeof e != "object") return !1;
|
|
623
787
|
let t = e;
|
|
624
788
|
return [
|
|
@@ -632,22 +796,22 @@ function ue(e) {
|
|
|
632
796
|
return typeof r == "number" && Number.isFinite(r) && typeof i == "number" && Number.isFinite(i) && (e !== "offset" || Number.isInteger(r) && Number.isInteger(i));
|
|
633
797
|
});
|
|
634
798
|
}
|
|
635
|
-
function
|
|
799
|
+
function Te(e, t) {
|
|
636
800
|
return {
|
|
637
801
|
imageUrl: e.imageUrl ?? t?.imageUrl,
|
|
638
|
-
placement:
|
|
802
|
+
placement: we(e.placement) ? e.placement : t?.placement
|
|
639
803
|
};
|
|
640
804
|
}
|
|
641
805
|
//#endregion
|
|
642
806
|
//#region src/core/survey-session-store.ts
|
|
643
|
-
var
|
|
807
|
+
var U = {
|
|
644
808
|
destroyed: !1,
|
|
645
809
|
state: null
|
|
646
|
-
},
|
|
647
|
-
function
|
|
810
|
+
}, Ee = 0;
|
|
811
|
+
function De(e) {
|
|
648
812
|
return e.fab?.title ?? e.title;
|
|
649
813
|
}
|
|
650
|
-
function
|
|
814
|
+
function Oe(e) {
|
|
651
815
|
return e.id;
|
|
652
816
|
}
|
|
653
817
|
function W(e) {
|
|
@@ -709,8 +873,8 @@ function $(e, t) {
|
|
|
709
873
|
}
|
|
710
874
|
return e.next_node_id ?? null;
|
|
711
875
|
}
|
|
712
|
-
var
|
|
713
|
-
snapshot =
|
|
876
|
+
var ke = class {
|
|
877
|
+
snapshot = U;
|
|
714
878
|
listeners = /* @__PURE__ */ new Set();
|
|
715
879
|
deps;
|
|
716
880
|
fabTimeoutId = null;
|
|
@@ -730,7 +894,7 @@ var pe = class {
|
|
|
730
894
|
return this.snapshot;
|
|
731
895
|
}
|
|
732
896
|
getServerSnapshot() {
|
|
733
|
-
return
|
|
897
|
+
return U;
|
|
734
898
|
}
|
|
735
899
|
subscribe(e) {
|
|
736
900
|
return this.destroyed ? () => {} : (this.listeners.add(e), () => this.listeners.delete(e));
|
|
@@ -818,7 +982,7 @@ var pe = class {
|
|
|
818
982
|
beginPulse(e, t, n) {
|
|
819
983
|
let r = K(e, e.root_node_id), i = q(e, e.root_node_id), a = e.sentimentPresentation === "toolbar", o = e.sentimentPresentation === void 0 ? r?.isSnackBar === !0 || r?.isSnackBar !== !1 && t === "snackbar" && !!e.fab : e.sentimentPresentation === "snackbar", s = (a || o) && r?.type === "yes_no" && r.answers?.length === 2 && !r.answers.some(J);
|
|
820
984
|
this.clearSurveyTransitionTimeouts(), this.publish({
|
|
821
|
-
presentationId: ++
|
|
985
|
+
presentationId: ++Ee,
|
|
822
986
|
sentimentPresentation: s ? a ? "bar" : "snackbar" : "sheet",
|
|
823
987
|
barPosition: "bottom",
|
|
824
988
|
barBehavior: "dismiss",
|
|
@@ -1276,4 +1440,4 @@ var pe = class {
|
|
|
1276
1440
|
}
|
|
1277
1441
|
};
|
|
1278
1442
|
//#endregion
|
|
1279
|
-
export {
|
|
1443
|
+
export { D as PendingInteractionStorageError, w as SidebandApiError, ke as SurveySessionStore, H as SyncEngine, De as buildFabTitle, p as createContextResolver, T as createSidebandClient, Se as createSidebandRuntime, Oe as getChoiceValue, s as getDeviceId, c as getSessionId, Y as isPositiveSentimentChoice, J as isSystemOtherChoice, Te as resolveSnackbarPresentation };
|