@corbado/observe 0.2.0-next.30-5569831 → 0.3.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.
- package/dist/cdn/script.global.js +1 -1
- package/dist/index.d.mts +188 -34
- package/dist/index.d.ts +188 -34
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -156,6 +156,12 @@ interface EventBatchMeta {
|
|
|
156
156
|
transport: "fetch" | "beacon";
|
|
157
157
|
/** Number of prior failed delivery attempts for this batch; omitted on the first attempt. */
|
|
158
158
|
retryCount?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Version of the SDK reliability config this batch was captured under; omitted when running on
|
|
161
|
+
* built-in defaults. Lets server-side analyses segment by the config actually in effect (config
|
|
162
|
+
* changes propagate with page-load lag, so calendar-date cohorts are mixed).
|
|
163
|
+
*/
|
|
164
|
+
configVersion?: string;
|
|
159
165
|
}
|
|
160
166
|
interface EventMeta {
|
|
161
167
|
trackingSourcePath: string;
|
|
@@ -221,8 +227,20 @@ interface SdkRetryConfig {
|
|
|
221
227
|
* SDK reliability configuration returned by the events endpoint (opt-in via the
|
|
222
228
|
* `X-Corbado-Observe-Config` header). Mirrors the server `observeEventCreateRes` schema.
|
|
223
229
|
* All delivery-reliability features default OFF until the server returns config.
|
|
230
|
+
*
|
|
231
|
+
* @remarks
|
|
232
|
+
* Boot-snapshot model: the config resolved at construction (from the localStorage cache) is the
|
|
233
|
+
* config for the entire page load. A config received from the server during the load is only
|
|
234
|
+
* cached for the NEXT load, never applied live — this keeps session identity, seq source and
|
|
235
|
+
* outbox mode coherent within one load.
|
|
224
236
|
*/
|
|
225
237
|
interface SdkReliabilityConfig {
|
|
238
|
+
/**
|
|
239
|
+
* Content-derived version (hash) assigned by the server. Echoed in the config request header so
|
|
240
|
+
* the server can answer 204 when nothing changed, and stamped into every batch's
|
|
241
|
+
* `meta.configVersion`. Empty string for the built-in defaults (nothing cached yet).
|
|
242
|
+
*/
|
|
243
|
+
version: string;
|
|
226
244
|
/** How often the SDK flushes its event queue, in milliseconds. */
|
|
227
245
|
flushIntervalMs: number;
|
|
228
246
|
/** Persist queued events to a durable outbox so they survive reloads, redirects and context switches. */
|
|
@@ -231,6 +249,29 @@ interface SdkReliabilityConfig {
|
|
|
231
249
|
beaconKeepalive: boolean;
|
|
232
250
|
/** Maintain session continuity across reloads/tabs by persisting the session id in localStorage. */
|
|
233
251
|
sessionContinuity: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Inactivity threshold for continuity sessions, in milliseconds. When more time than this has
|
|
254
|
+
* passed since the last tracked activity, the session id is rotated on the next load. Only
|
|
255
|
+
* relevant when `sessionContinuity` is enabled.
|
|
256
|
+
*/
|
|
257
|
+
sessionInactivityMs: number;
|
|
258
|
+
/**
|
|
259
|
+
* Flush-trigger switch: flush pending events when the document becomes hidden
|
|
260
|
+
* (`visibilitychange`). Defaults to true — a missing value can never disable delivery.
|
|
261
|
+
*/
|
|
262
|
+
tvc: boolean;
|
|
263
|
+
/** Flush-trigger switch: flush pending events on `pagehide` (navigation/close). Defaults to true. */
|
|
264
|
+
tph: boolean;
|
|
265
|
+
/** Flush-trigger switch: flush pending events when the integrator calls `destroy()`. Defaults to true. */
|
|
266
|
+
td: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Event names that trigger an immediate flush when enqueued (e.g. `flow_finished`,
|
|
269
|
+
* `conversion`), so high-value events go out via a normal fetch while the page is still alive
|
|
270
|
+
* instead of relying on unload delivery. Empty by default (no priority events). The whole
|
|
271
|
+
* pending queue is sent, and the immediate flush coexists with the interval timer without
|
|
272
|
+
* double-sending (the in-flight drain absorbs it).
|
|
273
|
+
*/
|
|
274
|
+
flushOnEventNames: string[];
|
|
234
275
|
/** Retry configuration for failed event flushes. */
|
|
235
276
|
retry: SdkRetryConfig;
|
|
236
277
|
}
|
|
@@ -436,6 +477,12 @@ interface TrackerOptions {
|
|
|
436
477
|
deviceInfoDebounceTime?: number;
|
|
437
478
|
defaultTags?: Record<string, string>;
|
|
438
479
|
applicationId?: string;
|
|
480
|
+
/**
|
|
481
|
+
* @deprecated The flush interval is server-controlled via the SDK reliability config
|
|
482
|
+
* (`flushIntervalMs`). This option only applies as long as no server config has been received
|
|
483
|
+
* (i.e. before the first config response is cached); once a server config is cached it wins.
|
|
484
|
+
* It will be removed in a future release.
|
|
485
|
+
*/
|
|
439
486
|
flushInterval?: number;
|
|
440
487
|
}
|
|
441
488
|
declare class CorbadoTracker {
|
|
@@ -447,16 +494,17 @@ declare class CorbadoTracker {
|
|
|
447
494
|
private sessionStorage;
|
|
448
495
|
/** Dedicated localStorage engine for reliability state (config cache, outbox, continuity session, seq). */
|
|
449
496
|
private persistentStorage;
|
|
450
|
-
|
|
497
|
+
/** Boot snapshot of the reliability config; immutable for the lifetime of this page load. */
|
|
498
|
+
private readonly config;
|
|
451
499
|
private deviceInfoCollector;
|
|
452
500
|
private deviceInfoDebounceTime;
|
|
453
501
|
private deviceInfoTransmittedLastTime;
|
|
454
502
|
private seq;
|
|
455
503
|
constructor(options: TrackerOptions);
|
|
456
504
|
/**
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
* load via
|
|
505
|
+
* Cache fresh server config as last-known. Boot-snapshot model: the config is NOT applied to this
|
|
506
|
+
* load — `this.config` stays the construction-time snapshot — it takes effect on the next page
|
|
507
|
+
* load via {@link loadCachedConfig}.
|
|
460
508
|
*/
|
|
461
509
|
private handleConfig;
|
|
462
510
|
/**
|
|
@@ -468,12 +516,19 @@ declare class CorbadoTracker {
|
|
|
468
516
|
private getSessionId;
|
|
469
517
|
/**
|
|
470
518
|
* Resolve the session id from localStorage so it survives reloads and is shared across tabs of the
|
|
471
|
-
* same browser. Rotates after
|
|
519
|
+
* same browser. Rotates after `config.sessionInactivityMs` of inactivity (server-controlled,
|
|
520
|
+
* boot-snapshot like the rest of the config), resetting the seq counter.
|
|
472
521
|
*/
|
|
473
522
|
private getContinuitySessionId;
|
|
474
523
|
/**
|
|
475
|
-
* Return the next sequence number. With session continuity the counter is persisted
|
|
476
|
-
*
|
|
524
|
+
* Return the next sequence number. With session continuity the counter is persisted so ordering
|
|
525
|
+
* survives reloads/redirects; the read-increment-write runs under a cross-tab Web Lock
|
|
526
|
+
* ({@link SEQ_LOCK_NAME}) so two tabs sharing the session cannot allocate the same seq (where Web
|
|
527
|
+
* Locks are unavailable it degrades to the historical best-effort merge). Lock grants are FIFO, so
|
|
528
|
+
* seq order matches `track()` call order within a tab. Every tracked event also bumps the
|
|
529
|
+
* continuity session's `lastActiveAt`, so the inactivity window measures real user inactivity
|
|
530
|
+
* instead of time-since-page-load (a long-lived active tab must not rotate the session on the next
|
|
531
|
+
* reload).
|
|
477
532
|
*/
|
|
478
533
|
private nextSeq;
|
|
479
534
|
private updateDeviceDebounced;
|
|
@@ -667,6 +722,8 @@ declare class CorbadoTracker {
|
|
|
667
722
|
* After calling destroy, the tracker must not be used. Operation objects
|
|
668
723
|
* returned by factory methods (e.g. `passwordLoginFullOperation`) that hold
|
|
669
724
|
* DOM references must be destroyed separately by the caller.
|
|
725
|
+
* The final flush is gated by the server-controlled trigger switch `td` (default true);
|
|
726
|
+
* resources are released either way.
|
|
670
727
|
*/
|
|
671
728
|
destroy(): Promise<void>;
|
|
672
729
|
/** @internal */
|
|
@@ -774,13 +831,25 @@ declare class SessionStorage implements StorageEngine {
|
|
|
774
831
|
}
|
|
775
832
|
|
|
776
833
|
interface QueueOptions {
|
|
834
|
+
/**
|
|
835
|
+
* Maximum number of events per request (payload cap). A backlog larger than this is drained in
|
|
836
|
+
* sequential capped batches within one flush. Reaching this size does NOT trigger an early
|
|
837
|
+
* flush — delivery cadence is controlled solely by the flush interval.
|
|
838
|
+
*/
|
|
777
839
|
batchSize?: number;
|
|
778
|
-
/**
|
|
840
|
+
/**
|
|
841
|
+
* Explicit override of the flush timer interval; otherwise `config.flushIntervalMs` is used.
|
|
842
|
+
* Internal/test use only — the tracker does not pass this; the interval is server-controlled.
|
|
843
|
+
*/
|
|
779
844
|
flushInterval?: number;
|
|
780
845
|
debug?: boolean;
|
|
781
|
-
/**
|
|
846
|
+
/**
|
|
847
|
+
* Reliability config snapshot for this page load; defaults to all-features-OFF. Boot-snapshot
|
|
848
|
+
* model: the queue never changes its behavior mid-load. A fresh config returned by the server is
|
|
849
|
+
* only handed to {@link QueueOptions.onConfigReceived} for caching and applies on the next load.
|
|
850
|
+
*/
|
|
782
851
|
config?: SdkReliabilityConfig;
|
|
783
|
-
/** Called
|
|
852
|
+
/** Called when the server returns a fresh config, so the client can cache it for the next load. */
|
|
784
853
|
onConfigReceived?: (config: SdkReliabilityConfig) => void;
|
|
785
854
|
/** Whether to send the opt-in config header on the first flush of this load. Defaults to true. */
|
|
786
855
|
requestConfig?: boolean;
|
|
@@ -788,12 +857,19 @@ interface QueueOptions {
|
|
|
788
857
|
/**
|
|
789
858
|
* @remarks When `window` is defined, `visibilitychange` (when the document becomes hidden) and `pagehide`
|
|
790
859
|
* trigger a synchronous unload flush (`flushSync`). Any thrown error in that path is logged as
|
|
791
|
-
* "Unexpected error in queue flushSync".
|
|
860
|
+
* "Unexpected error in queue flushSync". Sync flushes are deduplicated: once everything pending has
|
|
861
|
+
* been handed to a sync transport, further lifecycle signals are no-ops until something new is
|
|
862
|
+
* enqueued — otherwise a single navigation would resend the same batch several times
|
|
863
|
+
* (visibilitychange + pagehide + per-input flushKeepalive), since entries are intentionally kept
|
|
864
|
+
* under `durableOutbox`.
|
|
792
865
|
*
|
|
793
866
|
* Pending events are held as {@link OutboxEntry} records. When `config.durableOutbox` is enabled they are
|
|
794
867
|
* additionally persisted to a localStorage-backed {@link EventStore} and recovered on the next load.
|
|
795
868
|
* Delivery removes an entry only on a 2xx response; retryable failures back off (honoring `Retry-After`)
|
|
796
869
|
* up to `config.retry.maxAttempts`. Low events are best-effort and never persisted.
|
|
870
|
+
*
|
|
871
|
+
* Flushing is timer-driven only (the flush interval); `batchSize` caps the events per request, and a
|
|
872
|
+
* flush drains all due work in sequential capped batches, stopping at the first failed send.
|
|
797
873
|
*/
|
|
798
874
|
declare class RequestQueue {
|
|
799
875
|
private readonly logger;
|
|
@@ -805,6 +881,12 @@ declare class RequestQueue {
|
|
|
805
881
|
private lowsQueue;
|
|
806
882
|
private timer;
|
|
807
883
|
private isFlushing;
|
|
884
|
+
/**
|
|
885
|
+
* True when something was enqueued (or recovered) since the last sync flush. visibilitychange,
|
|
886
|
+
* pagehide and per-input flushKeepalive calls all funnel into flushSync; this flag makes the
|
|
887
|
+
* duplicate calls no-ops. The async flush path ignores it.
|
|
888
|
+
*/
|
|
889
|
+
private dirtySinceSyncFlush;
|
|
808
890
|
private onVisibilityChange;
|
|
809
891
|
private onPageHide;
|
|
810
892
|
private readonly batchSize;
|
|
@@ -812,21 +894,27 @@ declare class RequestQueue {
|
|
|
812
894
|
private readonly debug;
|
|
813
895
|
private readonly requestConfig;
|
|
814
896
|
private readonly onConfigReceived?;
|
|
815
|
-
private config;
|
|
897
|
+
private readonly config;
|
|
898
|
+
/** Event names that trigger an immediate flush at enqueue time (config.flushOnEventNames). */
|
|
899
|
+
private readonly priorityNames;
|
|
816
900
|
private store?;
|
|
817
|
-
/**
|
|
901
|
+
/**
|
|
902
|
+
* Once the server has answered the config request with a 2xx (200 = fresh config cached for the
|
|
903
|
+
* next load, 204 = cached version still current) we stop sending the header for this load. A
|
|
904
|
+
* transport-level failure or error status keeps the request pending for the next flush.
|
|
905
|
+
*/
|
|
818
906
|
private configResolved;
|
|
819
907
|
constructor(logger: Logger, transport: Transport, sessionId: string, sdk: SdkInfo, options?: QueueOptions, storage?: StorageEngine | undefined);
|
|
820
908
|
setSessionId(sessionId: string): void;
|
|
821
909
|
private flushInterval;
|
|
822
910
|
/**
|
|
823
911
|
* Error situations:
|
|
824
|
-
* - Any error while enqueueing or scheduling flush
|
|
912
|
+
* - Any error while enqueueing or scheduling the flush timer: log "Failed to enqueue event"
|
|
825
913
|
*/
|
|
826
914
|
enqueue(event: Event): void;
|
|
827
915
|
/**
|
|
828
916
|
* Error situations:
|
|
829
|
-
* - Any error while enqueueing or scheduling flush
|
|
917
|
+
* - Any error while enqueueing or scheduling the flush timer: log "Failed to enqueue low event"
|
|
830
918
|
*/
|
|
831
919
|
enqueueLow(low: LowEvent): void;
|
|
832
920
|
private scheduleAfterEnqueue;
|
|
@@ -840,16 +928,22 @@ declare class RequestQueue {
|
|
|
840
928
|
*/
|
|
841
929
|
flush(): Promise<void>;
|
|
842
930
|
/**
|
|
843
|
-
* Stamps the batch
|
|
844
|
-
*
|
|
931
|
+
* Stamps delivery metadata onto the batch: the config version this load runs under (omitted on
|
|
932
|
+
* built-in defaults) and the number of prior failed delivery attempts (the max across its entries,
|
|
933
|
+
* only when at least one entry is a retry). `entry.attempts` is incremented on each failed flush,
|
|
845
934
|
* so it equals the retry count at send time. The transport later merges in `sent`/`transport`.
|
|
846
935
|
*/
|
|
847
|
-
private
|
|
936
|
+
private attachBatchMeta;
|
|
848
937
|
private getDuePending;
|
|
849
938
|
private takeLows;
|
|
850
939
|
private shouldRequestConfig;
|
|
940
|
+
/**
|
|
941
|
+
* Handle the server's answer to the config request. Boot-snapshot model: a fresh config is ONLY
|
|
942
|
+
* handed to `onConfigReceived` for caching — it is never applied to this load. The behavior the
|
|
943
|
+
* queue was constructed with stays in effect until the page unloads.
|
|
944
|
+
*/
|
|
851
945
|
private handleConfigResponse;
|
|
852
|
-
|
|
946
|
+
/** Returns true when the batch was acknowledged with a 2xx (safe to keep draining). */
|
|
853
947
|
private handleSendResult;
|
|
854
948
|
private isRetryable;
|
|
855
949
|
/**
|
|
@@ -868,9 +962,13 @@ declare class RequestQueue {
|
|
|
868
962
|
* Synchronously flush pending events (and best-effort lows) during page unload.
|
|
869
963
|
*
|
|
870
964
|
* @remarks
|
|
871
|
-
* When `config.beaconKeepalive` is on, uses `sendBeacon
|
|
872
|
-
*
|
|
873
|
-
*
|
|
965
|
+
* When `config.beaconKeepalive` is on, uses `sendBeacon` (falling back to fetch keepalive when
|
|
966
|
+
* the UA refuses the beacon); otherwise fires a fire-and-forget `fetch` keepalive request. The
|
|
967
|
+
* send is capped at one `batchSize` chunk per call (unload transports share an in-flight budget
|
|
968
|
+
* with the host app). With `config.durableOutbox` enabled, entries are NOT removed (they are
|
|
969
|
+
* resent on the next load and deduped server-side); otherwise the sent chunk is removed
|
|
970
|
+
* best-effort and a remainder keeps the next lifecycle signal flush-worthy.
|
|
971
|
+
* Deduplicated: a call with nothing newly enqueued since the last sync flush is a no-op.
|
|
874
972
|
*/
|
|
875
973
|
flushKeepalive(): void;
|
|
876
974
|
private flushSync;
|
|
@@ -883,24 +981,63 @@ declare class RequestQueue {
|
|
|
883
981
|
|
|
884
982
|
/** localStorage key under which the last-known server config is cached. */
|
|
885
983
|
declare const CONFIG_STORAGE_KEY = "cbo_sdk_config";
|
|
886
|
-
/**
|
|
984
|
+
/**
|
|
985
|
+
* Opt-in request header that asks the events endpoint to return the SDK reliability config. Its value
|
|
986
|
+
* is the config version the SDK is currently running, or "1" when none is cached yet. The server
|
|
987
|
+
* answers 204 when that version is still current and 200 + config body when it is stale.
|
|
988
|
+
*/
|
|
887
989
|
declare const CONFIG_REQUEST_HEADER = "X-Corbado-Observe-Config";
|
|
888
990
|
/** Built-in flush interval used until the server provides one. Matches the historical default. */
|
|
889
991
|
declare const DEFAULT_FLUSH_INTERVAL_MS = 500;
|
|
992
|
+
/**
|
|
993
|
+
* Clamping bounds for server-provided config values. They protect the client from a dangerous
|
|
994
|
+
* server-side config mistake (e.g. a 0ms flush interval would busy-loop); the server clamps with
|
|
995
|
+
* the same bounds as the first line of defense.
|
|
996
|
+
*/
|
|
997
|
+
declare const CONFIG_BOUNDS: {
|
|
998
|
+
readonly flushIntervalMs: {
|
|
999
|
+
readonly min: 100;
|
|
1000
|
+
readonly max: 60000;
|
|
1001
|
+
};
|
|
1002
|
+
readonly retryMaxAttempts: {
|
|
1003
|
+
readonly min: 1;
|
|
1004
|
+
readonly max: 10;
|
|
1005
|
+
};
|
|
1006
|
+
readonly retryDelayMs: {
|
|
1007
|
+
readonly min: 50;
|
|
1008
|
+
readonly max: 120000;
|
|
1009
|
+
};
|
|
1010
|
+
readonly sessionInactivityMs: {
|
|
1011
|
+
readonly min: 60000;
|
|
1012
|
+
readonly max: 86400000;
|
|
1013
|
+
};
|
|
1014
|
+
readonly flushOnEventNames: {
|
|
1015
|
+
readonly maxEntries: 20;
|
|
1016
|
+
readonly maxNameLength: 100;
|
|
1017
|
+
};
|
|
1018
|
+
};
|
|
1019
|
+
/** Built-in continuity-session inactivity threshold (30 minutes); matches the historical default. */
|
|
1020
|
+
declare const DEFAULT_SESSION_INACTIVITY_MS: number;
|
|
890
1021
|
/**
|
|
891
1022
|
* Default config: every delivery-reliability feature is OFF. The SDK behaves like a plain async
|
|
892
|
-
* fetch-keepalive flusher until the server returns config (which is then cached as last-known
|
|
1023
|
+
* fetch-keepalive flusher until the server returns config (which is then cached as last-known and
|
|
1024
|
+
* applied on the NEXT page load — boot-snapshot model). The empty version means "nothing cached";
|
|
1025
|
+
* the config request header sends "1" in that case.
|
|
893
1026
|
*/
|
|
894
1027
|
declare const DEFAULT_RELIABILITY_CONFIG: SdkReliabilityConfig;
|
|
895
1028
|
/**
|
|
896
1029
|
* Coerce an arbitrary value (cached blob or parsed API body) into a {@link SdkReliabilityConfig}.
|
|
897
|
-
* Returns `null` if the input is not an object
|
|
898
|
-
*
|
|
1030
|
+
* Returns `null` if the input is not an object or carries no `version` (a config without identity
|
|
1031
|
+
* cannot participate in the version handshake and must not be trusted). Missing fields fall back to
|
|
1032
|
+
* the OFF defaults so a partial/older payload can never silently enable a feature; the
|
|
1033
|
+
* flush-trigger switches (`tvc`/`tph`/`td`) invert this and default ON, so a partial payload can
|
|
1034
|
+
* never silently disable delivery. Numeric values are clamped to {@link CONFIG_BOUNDS} so a bad
|
|
1035
|
+
* server value cannot harm the client.
|
|
899
1036
|
*/
|
|
900
1037
|
declare function parseReliabilityConfig(raw: unknown): SdkReliabilityConfig | null;
|
|
901
1038
|
/** Read the cached config from storage, or `null` if absent/invalid. */
|
|
902
1039
|
declare function loadCachedConfig(storage: StorageEngine): SdkReliabilityConfig | null;
|
|
903
|
-
/** Persist the config as last-known so the next page load starts with features
|
|
1040
|
+
/** Persist the config as last-known so the next page load starts with these features enabled. */
|
|
904
1041
|
declare function cacheConfig(storage: StorageEngine, config: SdkReliabilityConfig): void;
|
|
905
1042
|
|
|
906
1043
|
/** A persisted, not-yet-acknowledged event awaiting delivery. */
|
|
@@ -918,34 +1055,51 @@ interface OutboxEntry {
|
|
|
918
1055
|
}
|
|
919
1056
|
/** localStorage key under which the durable outbox is persisted. */
|
|
920
1057
|
declare const OUTBOX_STORAGE_KEY = "cbo_outbox";
|
|
1058
|
+
/** Web Lock name guarding outbox mutations across tabs. */
|
|
1059
|
+
declare const OUTBOX_LOCK_NAME = "cbo_outbox";
|
|
921
1060
|
/** Default maximum number of entries kept; oldest are evicted past this. */
|
|
922
1061
|
declare const DEFAULT_MAX_ENTRIES = 500;
|
|
1062
|
+
/**
|
|
1063
|
+
* Default budget for the outbox's serialized size, in UTF-16 code units (the unit localStorage
|
|
1064
|
+
* quotas are measured in; ~1 MB on disk). The entry-count cap alone does not bound bytes —
|
|
1065
|
+
* `event.data` is arbitrary customer payload — and localStorage's ~5M-unit quota is shared with
|
|
1066
|
+
* the HOST app: an unbounded outbox could make the host's own writes throw QuotaExceededError.
|
|
1067
|
+
*/
|
|
1068
|
+
declare const DEFAULT_MAX_SERIALIZED_LENGTH: number;
|
|
923
1069
|
/**
|
|
924
1070
|
* Durable, localStorage-backed outbox of pending events, mirrored in memory.
|
|
925
1071
|
*
|
|
926
1072
|
* @remarks
|
|
927
|
-
* Every mutation
|
|
928
|
-
*
|
|
1073
|
+
* Every mutation is a read-merge-write against storage, executed under a cross-tab Web Lock
|
|
1074
|
+
* ({@link OUTBOX_LOCK_NAME}) so concurrent tabs sharing the same localStorage cannot interleave
|
|
1075
|
+
* between the read and the write (which would silently drop the other tab's entries). Where the
|
|
1076
|
+
* Web Locks API is unavailable the mutation runs unlocked, matching the historical best-effort
|
|
1077
|
+
* behavior. Mutations never reject; failures are logged.
|
|
929
1078
|
* The store is size-capped; overflow evicts the oldest entries and logs the count.
|
|
930
1079
|
*/
|
|
931
1080
|
declare class EventStore {
|
|
932
1081
|
private readonly storage;
|
|
933
1082
|
private readonly logger;
|
|
934
1083
|
private readonly maxEntries;
|
|
1084
|
+
private readonly maxSerializedLength;
|
|
935
1085
|
private entries;
|
|
936
|
-
|
|
1086
|
+
/** Malformed entries are dropped on every read; report only once per instance to avoid log spam. */
|
|
1087
|
+
private reportedMalformed;
|
|
1088
|
+
constructor(storage: StorageEngine, logger: Logger, maxEntries?: number, maxSerializedLength?: number);
|
|
937
1089
|
private read;
|
|
938
1090
|
private mutate;
|
|
1091
|
+
/** Evict oldest entries until the serialized outbox fits {@link maxSerializedLength}. */
|
|
1092
|
+
private enforceSizeBudget;
|
|
939
1093
|
/** Append an entry. No-op if an entry with the same id already exists. */
|
|
940
|
-
add(entry: OutboxEntry): void
|
|
1094
|
+
add(entry: OutboxEntry): Promise<void>;
|
|
941
1095
|
/** Re-read from storage and return all entries (memory mirror refreshed). */
|
|
942
1096
|
all(): OutboxEntry[];
|
|
943
1097
|
/** Entries whose `flushAfter` has elapsed, in insertion order. */
|
|
944
1098
|
getDue(now: number): OutboxEntry[];
|
|
945
1099
|
/** Remove entries by id (acknowledged or permanently dropped). */
|
|
946
|
-
remove(ids: string[]): void
|
|
1100
|
+
remove(ids: string[]): Promise<void>;
|
|
947
1101
|
/** Replace existing entries (matched by id) with updated copies, e.g. after bumping backoff. */
|
|
948
|
-
update(updated: OutboxEntry[]): void
|
|
1102
|
+
update(updated: OutboxEntry[]): Promise<void>;
|
|
949
1103
|
size(): number;
|
|
950
1104
|
}
|
|
951
1105
|
|
|
@@ -954,4 +1108,4 @@ declare function getTracker(): CorbadoTracker | undefined;
|
|
|
954
1108
|
declare function resetSession(): string | undefined;
|
|
955
1109
|
declare function destroy(): Promise<void>;
|
|
956
1110
|
|
|
957
|
-
export { type AuthDecisionFinished, type AuthDecisionStarted, AuthEventName, type AuthMethodDecisionFinished, type AuthMethodDecisionStarted, type AuthMethodType, type BaseEvent, CONFIG_REQUEST_HEADER, CONFIG_STORAGE_KEY, type ClientCapabilities, type ClientEnvHandleMeta, type ClientEnvHandleMetaSource, type Conversion, CookieStorage, CorbadoTracker, type CreateLoggerOptions, type CustomEvent, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_ENTRIES, DEFAULT_RELIABILITY_CONFIG, type DeviceInfo, type DeviceInfoCollectionError, type DeviceInfoDataWeb, type DeviceType, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type Event, type EventBatch, type EventBatchMeta, type EventMeta, EventStore, type EventType, type FlowAutoFinished, type FlowDecided, type FlowFinished, type FlowReset, type FlowStarted, type FlowType, type JavaScriptHighEntropy, LocalStorage, type Logger, type LowEvent, type MultiFlowReset, type MultiFlowStarted, type NormalizedError, OUTBOX_STORAGE_KEY, OperationFull, OperationFullProvideIdentifierWithCUI, type OutboxEntry, type PasskeyEnrollmentCeremonyFinished, type PasskeyEnrollmentCeremonyStart, type PasskeyEnrollmentGetOptionsFinished, type PasskeyEnrollmentGetOptionsStart, PasskeyEnrollmentOperationFull, type PasskeyLoginCUIGetOptionsFinished, type PasskeyLoginCUIGetOptionsStart, type PasskeyLoginCUISpecType, type PasskeyLoginCeremonyFinished, type PasskeyLoginCeremonyStart, type PasskeyLoginClientError, type PasskeyLoginFinish, type PasskeyLoginGetOptionsFinished, type PasskeyLoginGetOptionsStart, PasskeyLoginOperationFull, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentAutoTrackConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginAutoTrackConfig, PasswordLoginOperationFull, type PasswordLoginTypedError, type PredefinedEvent, type ProvideIdentifierError, type ProvideIdentifierFinish, type ProvideIdentifierPostResponseStart, type ProvideIdentifierSpecType, type ProvideIdentifierStart, type QueueOptions, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkRetryConfig, SessionStorage, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, SocialLoginOperationFull, type SocialLoginProviderType, type SocialLoginSpecType, type StepHelper, type StepOptions, type StorageEngine, type SubflowTrigger, type SubflowType, type TrackerOptions, type Transport, type TransportMakeRequestResponse, type TransportOptions, type UserReference, cacheConfig, createLogger, destroy, getTracker, init, loadCachedConfig, parseReliabilityConfig, resetSession };
|
|
1111
|
+
export { type AuthDecisionFinished, type AuthDecisionStarted, AuthEventName, type AuthMethodDecisionFinished, type AuthMethodDecisionStarted, type AuthMethodType, type BaseEvent, CONFIG_BOUNDS, CONFIG_REQUEST_HEADER, CONFIG_STORAGE_KEY, type ClientCapabilities, type ClientEnvHandleMeta, type ClientEnvHandleMetaSource, type Conversion, CookieStorage, CorbadoTracker, type CreateLoggerOptions, type CustomEvent, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_ENTRIES, DEFAULT_MAX_SERIALIZED_LENGTH, DEFAULT_RELIABILITY_CONFIG, DEFAULT_SESSION_INACTIVITY_MS, type DeviceInfo, type DeviceInfoCollectionError, type DeviceInfoDataWeb, type DeviceType, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type Event, type EventBatch, type EventBatchMeta, type EventMeta, EventStore, type EventType, type FlowAutoFinished, type FlowDecided, type FlowFinished, type FlowReset, type FlowStarted, type FlowType, type JavaScriptHighEntropy, LocalStorage, type Logger, type LowEvent, type MultiFlowReset, type MultiFlowStarted, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, OperationFull, OperationFullProvideIdentifierWithCUI, type OutboxEntry, type PasskeyEnrollmentCeremonyFinished, type PasskeyEnrollmentCeremonyStart, type PasskeyEnrollmentGetOptionsFinished, type PasskeyEnrollmentGetOptionsStart, PasskeyEnrollmentOperationFull, type PasskeyLoginCUIGetOptionsFinished, type PasskeyLoginCUIGetOptionsStart, type PasskeyLoginCUISpecType, type PasskeyLoginCeremonyFinished, type PasskeyLoginCeremonyStart, type PasskeyLoginClientError, type PasskeyLoginFinish, type PasskeyLoginGetOptionsFinished, type PasskeyLoginGetOptionsStart, PasskeyLoginOperationFull, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentAutoTrackConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginAutoTrackConfig, PasswordLoginOperationFull, type PasswordLoginTypedError, type PredefinedEvent, type ProvideIdentifierError, type ProvideIdentifierFinish, type ProvideIdentifierPostResponseStart, type ProvideIdentifierSpecType, type ProvideIdentifierStart, type QueueOptions, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkRetryConfig, SessionStorage, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, SocialLoginOperationFull, type SocialLoginProviderType, type SocialLoginSpecType, type StepHelper, type StepOptions, type StorageEngine, type SubflowTrigger, type SubflowType, type TrackerOptions, type Transport, type TransportMakeRequestResponse, type TransportOptions, type UserReference, cacheConfig, createLogger, destroy, getTracker, init, loadCachedConfig, parseReliabilityConfig, resetSession };
|