@corbado/observe 0.9.1 → 0.10.0-next.85-cf81a6b

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/index.d.mts CHANGED
@@ -3,8 +3,8 @@ interface SdkInfo {
3
3
  version: string;
4
4
  }
5
5
  type EventType = "predefined" | "custom" | "error" | "identify";
6
- type AuthMethodType = "identifier-email" | "passkey-login-known-identifier" | "passkey-login-no-identifier" | "passkey-login-cui" | "passkey-login-immediate" | "passkey-enrollment" | "password-login-known-identifier" | "password-login-with-identifier" | "password-enrollment" | "email-otp-login" | "email-otp-enrollment" | "email-link-login" | "email-link-enrollment" | "social-google" | "social-apple" | "social-facebook" | "social-other" | "reset-flow";
7
- type SubflowType = "passkey-enrollment" | "passkey-login" | "email-otp" | "email-link" | "social-login" | "sms-otp" | "provide-identifier" | "provide-data" | "password-login" | "password-enrollment" | "totp" | "app-confirmation";
6
+ type AuthMethodType = "identifier-email" | "passkey-login-known-identifier" | "passkey-login-no-identifier" | "passkey-login-cui" | "passkey-login-immediate" | "passkey-enrollment" | "password-login" | "password-login-known-identifier" | "password-login-with-identifier" | "password-enrollment" | "email-otp" | "email-otp-login" | "email-otp-enrollment" | "email-link" | "email-link-login" | "email-link-enrollment" | "sms-otp" | "sms-otp-login" | "sms-otp-enrollment" | "social-google" | "social-apple" | "social-facebook" | "social-other" | "reset-flow" | "provide-data";
7
+ type SubflowType = "passkey-enrollment" | "passkey-login" | "email-otp" | "email-link" | "social-login" | "sms-otp" | "provide-identifier" | "provide-data" | "password-login" | "password-enrollment" | "totp" | "app-confirmation" | "captcha";
8
8
  type FlowType = "login" | "signup" | "recovery" | "enrollment" | (string & {});
9
9
  type SocialLoginProviderType = "google" | "apple" | "facebook" | "github" | "microsoft" | "other";
10
10
  declare enum AuthEventName {
@@ -175,9 +175,31 @@ interface TelemetryEntry {
175
175
  /** Capture time, unix ms. */
176
176
  ts: number;
177
177
  }
178
+ /**
179
+ * Why a delivery attempt happened. Each value maps 1:1 to one flush trigger, so server-side
180
+ * analyses can tell which triggers actually carry the traffic and whether the trigger switches and
181
+ * opt-in flush features of the reliability config earn their keep.
182
+ *
183
+ * - `timer`: the flush interval elapsed (the ordinary cadence).
184
+ * - `backoff`: a retry whose backoff delay elapsed — a resend, not new work.
185
+ * - `recovery`: events recovered from the durable outbox at boot (previous load never delivered them).
186
+ * - `flow-finished`: a configured priority flow type completed (`flushOnFlowTypeFinished`).
187
+ * - `telemetry`: a telemetry entry escalated to an immediate flush (`flushOnTelemetry`).
188
+ * - `visibility-change`: the document became hidden (`tvc`).
189
+ * - `pagehide`: the page is going away (`tph`).
190
+ * - `low-event-teardown`: a low-event tracker's unload teardown handed over its batched lows (`tlf`).
191
+ * - `destroy`: the tracker was destroyed (`td`).
192
+ * - `manual`: the host app called `flushKeepalive()` itself.
193
+ */
194
+ type FlushReason = "timer" | "backoff" | "recovery" | "flow-finished" | "telemetry" | "visibility-change" | "pagehide" | "low-event-teardown" | "destroy" | "manual";
178
195
  interface EventBatchMeta {
179
196
  sent: number;
180
197
  transport: "fetch" | "beacon";
198
+ /**
199
+ * What triggered the flush this batch was sent in. All batches of one flush (a backlog larger
200
+ * than `batchSize` is drained in several requests) carry the same reason.
201
+ */
202
+ flushReason?: FlushReason;
181
203
  /** Number of prior failed delivery attempts for this batch; omitted on the first attempt. */
182
204
  retryCount?: number;
183
205
  /**
@@ -219,6 +241,11 @@ interface DeviceInfoDataWeb {
219
241
  javaScriptHighEntropy?: JavaScriptHighEntropy;
220
242
  privateMode?: boolean;
221
243
  webdriver?: boolean;
244
+ /**
245
+ * `navigator.maxTouchPoints` — maximum simultaneous touch contact points. Reported raw so the
246
+ * backend can separate iPadOS (non-zero, but sends a macOS user agent) from real macOS devices (0).
247
+ */
248
+ maxTouchPoints?: number;
222
249
  }
223
250
  type DeviceInfoCollectionError = {
224
251
  field: keyof DeviceInfoDataWeb;
@@ -281,7 +308,14 @@ interface SdkReliabilityConfig {
281
308
  * relevant when `sessionContinuity` is enabled.
282
309
  */
283
310
  sessionInactivityMs: number;
284
- /** Maximum time to wait for the cross-tab sequence Web Lock before allocating without it. */
311
+ /**
312
+ * Maximum time to wait for the cross-tab sequence Web Lock before allocating without it.
313
+ *
314
+ * `0` disables the lock: the counter is then allocated straight away, without ever requesting a
315
+ * lock. That gives up cross-tab atomicity — two tabs sharing a continuity session can allocate the
316
+ * same seq, which is what the unlocked fallback already does on every timeout — in exchange for
317
+ * removing a lock round-trip per tracked event.
318
+ */
285
319
  seqLockTimeoutMs: number;
286
320
  /**
287
321
  * Flush-trigger switch: flush pending events when the document becomes hidden
@@ -311,13 +345,31 @@ interface SdkReliabilityConfig {
311
345
  */
312
346
  flushOnTelemetry: boolean;
313
347
  /**
314
- * Event names that trigger an immediate flush when enqueued (e.g. `flow_finished`,
315
- * `conversion`), so high-value events go out via a normal fetch while the page is still alive
316
- * instead of relying on unload delivery. Empty by default (no priority events). The whole
317
- * pending queue is sent, and the immediate flush coexists with the interval timer without
318
- * double-sending (the in-flight drain absorbs it).
348
+ * Flow types (e.g. `login`, `enrollment`) whose completion triggers an immediate flush when
349
+ * enqueued, so the highest-value events go out via a normal fetch while the page is still alive
350
+ * instead of relying on unload delivery. Both completion events count — `flow_finished` and
351
+ * `flow_auto_finished` — matched on their `flowName`; no other event name ever flushes early.
352
+ * Empty by default (no priority flows). The whole pending queue is sent, and the immediate flush
353
+ * coexists with the interval timer without double-sending (the in-flight drain absorbs it).
319
354
  */
320
- flushOnEventNames: string[];
355
+ flushOnFlowTypeFinished: FlowType[];
356
+ /**
357
+ * Per-field timeout for device info collection, in milliseconds. A field whose browser API does
358
+ * not answer within this budget is recorded as a `TimeoutError` in `collectionErrors` and left
359
+ * undefined; the remaining fields are unaffected. Defaults to 1000ms.
360
+ *
361
+ * Read at collection time, so a config that arrives mid-load applies from the next device info
362
+ * refresh onward. The very first collection of a load booting on the built-in defaults (nothing
363
+ * cached) always runs on the default.
364
+ */
365
+ deviceInfoCollectorTimeoutMs: number;
366
+ /**
367
+ * When true (and `telemetry` is enabled), every device info collection emits an `info` telemetry
368
+ * entry with the total duration and the per-field durations in milliseconds. Defaults to false:
369
+ * this is a diagnostic stream to switch on while investigating slow collection, not something to
370
+ * run permanently.
371
+ */
372
+ deviceInfoTiming: boolean;
321
373
  /** Retry configuration for failed event flushes. */
322
374
  retry: SdkRetryConfig;
323
375
  }
@@ -429,6 +481,13 @@ declare abstract class OperationFull {
429
481
  }
430
482
 
431
483
  type PasskeyOperationLoginExplicitSpecType = "passkey-cui" | "passkey-known-identifier" | "passkey-no-identifier"
484
+ /**
485
+ * The `-auto` variants are the same two ceremonies started by the integration rather than by a
486
+ * user gesture — `navigator.credentials.get()` called without user activation, so the passkey
487
+ * prompt appears on its own. Unlike `passkey-immediate` they still run after the auth-method
488
+ * decision is rendered and attribute to the same decision option as their manual counterpart.
489
+ */
490
+ | "passkey-known-identifier-auto" | "passkey-no-identifier-auto"
432
491
  /**
433
492
  * WebAuthn immediate mediation (`navigator.credentials.get({ uiMode: "immediate" })`, Chrome 149+):
434
493
  * button-triggered, discoverable credentials only (empty allowList). Shows the account picker when
@@ -449,10 +508,20 @@ type PasskeyLoginCeremonyStart = {
449
508
  type PasskeyLoginCeremonyFinished = {
450
509
  assertionResponse: string;
451
510
  };
511
+ type PasskeyLoginPostResponseStart = {
512
+ /**
513
+ * Fallback carrier for the WebAuthn assertion, same JSON shape the ceremony step reports. Set it
514
+ * only when the ceremony itself could not be observed — e.g. an extension holds
515
+ * `navigator.credentials` in a form the integration declines to patch — and the submitted
516
+ * credential is the only remaining copy. Leave it unset whenever a ceremony step carried the
517
+ * assertion, so consumers never see two sources for one login.
518
+ */
519
+ assertionResponse?: string;
520
+ };
452
521
  declare class PasskeyLoginOperationFull extends OperationFull {
453
522
  readonly getOptions: StepHelper<PasskeyLoginGetOptionsStart, PasskeyLoginGetOptionsFinished>;
454
523
  readonly ceremony: StepHelper<PasskeyLoginCeremonyStart, PasskeyLoginCeremonyFinished>;
455
- readonly postResponse: StepHelper;
524
+ readonly postResponse: StepHelper<PasskeyLoginPostResponseStart>;
456
525
  private lowEventTracker;
457
526
  constructor(tracker: CorbadoTracker);
458
527
  /**
@@ -470,21 +539,27 @@ type EmailOTPOperationSendOTPStart = {
470
539
  type EmailOTPOperationPostResponseStart = {
471
540
  explicitSpecType?: EmailOTPOperationSpecType;
472
541
  };
542
+ type EmailOTPOperationConfig = {
543
+ explicitSpecType?: EmailOTPOperationSpecType;
544
+ };
473
545
  declare class EmailOtpOperationFull extends OperationFull {
474
546
  readonly send: StepHelper<EmailOTPOperationSendOTPStart>;
475
547
  readonly postResponse: StepHelper<EmailOTPOperationPostResponseStart>;
476
548
  readonly resend: StepHelper;
477
- constructor(tracker: CorbadoTracker);
549
+ constructor(tracker: CorbadoTracker, config?: EmailOTPOperationConfig);
478
550
  }
479
551
 
480
552
  type SmsOTPOperationSpecType = "sms-otp-login" | "sms-otp-enrollment";
481
553
  type SmsOTPOperationPostResponseStart = {
482
554
  explicitSpecType?: SmsOTPOperationSpecType;
483
555
  };
556
+ type SmsOTPOperationConfig = {
557
+ explicitSpecType?: SmsOTPOperationSpecType;
558
+ };
484
559
  declare class SmsOtpOperationFull extends OperationFull {
485
560
  readonly postResponse: StepHelper<SmsOTPOperationPostResponseStart>;
486
561
  readonly resend: StepHelper;
487
- constructor(tracker: CorbadoTracker);
562
+ constructor(tracker: CorbadoTracker, config?: SmsOTPOperationConfig);
488
563
  }
489
564
 
490
565
  type EmailLinkOperationSpecType = "email-link-login" | "email-link-enrollment";
@@ -517,12 +592,26 @@ type PasskeyEnrollmentCeremonyStart = {
517
592
  type PasskeyEnrollmentCeremonyFinished = {
518
593
  attestationResponse: string;
519
594
  };
595
+ type PasskeyEnrollmentPostResponseStart = {
596
+ /**
597
+ * Fallback carrier for the WebAuthn attestation, mirroring the passkey-login contract. Set it only
598
+ * when the ceremony itself could not be observed — e.g. an extension holds `navigator.credentials`
599
+ * in a form the integration declines to patch — and the submitted credential is the only remaining
600
+ * copy. Leave it unset whenever a ceremony step carried the attestation, so consumers never see two
601
+ * sources for one enrollment. A credential recovered from the submission may carry more members
602
+ * than the ceremony reports; consumers must tolerate unknown keys.
603
+ */
604
+ attestationResponse?: string;
605
+ };
606
+ type PasskeyEnrollmentOperationConfig = {
607
+ explicitSpecType?: PasskeyOperationEnrollmentExplicitSpecType;
608
+ };
520
609
  declare class PasskeyEnrollmentOperationFull extends OperationFull {
521
610
  readonly getOptions: StepHelper<PasskeyEnrollmentGetOptionsStart, PasskeyEnrollmentGetOptionsFinished>;
522
611
  readonly ceremony: StepHelper<PasskeyEnrollmentCeremonyStart, PasskeyEnrollmentCeremonyFinished>;
523
- readonly postResponse: StepHelper;
612
+ readonly postResponse: StepHelper<PasskeyEnrollmentPostResponseStart>;
524
613
  private lowEventTracker;
525
- constructor(tracker: CorbadoTracker);
614
+ constructor(tracker: CorbadoTracker, config?: PasskeyEnrollmentOperationConfig);
526
615
  destroy(): void;
527
616
  }
528
617
 
@@ -609,7 +698,7 @@ type PasskeyLoginCUITypedError = {
609
698
  code: PasskeyLoginCUITypedErrorCode;
610
699
  };
611
700
  type PasskeyLoginCUITypedErrorCode = "cancel_detected";
612
- type ProvideIdentifierSpecType = "email";
701
+ type ProvideIdentifierSpecType = "email" | "phone";
613
702
  type ProvideIdentifierPostResponseStart = {
614
703
  explicitSpecType?: ProvideIdentifierSpecType;
615
704
  };
@@ -624,6 +713,10 @@ type PasskeyLoginCUIGetOptionsFinished = {
624
713
  explicitSpecType?: ProvideIdentifierSpecType;
625
714
  assertionOptions: string;
626
715
  };
716
+ type OperationFullProvideIdentifierWithCUIConfig = {
717
+ inputHtmlField?: HTMLInputElement;
718
+ explicitSpecType?: ProvideIdentifierSpecType;
719
+ };
627
720
  declare class OperationFullProvideIdentifierWithCUI {
628
721
  private tracker;
629
722
  private lowEventTracker?;
@@ -635,7 +728,7 @@ declare class OperationFullProvideIdentifierWithCUI {
635
728
  trigger: (data: SubflowTrigger, options?: StepOptions) => void;
636
729
  getOptions: StepHelper<PasskeyLoginCUIGetOptionsStart, PasskeyLoginCUIGetOptionsFinished>;
637
730
  ceremony: StepHelper<CUICeremonyStart, PasskeyLoginCeremonyFinished, PasskeyLoginCUITypedError>;
638
- postResponse: StepHelper;
731
+ postResponse: StepHelper<PasskeyLoginPostResponseStart>;
639
732
  };
640
733
  readonly provideIdentifier: {
641
734
  /**
@@ -646,7 +739,7 @@ declare class OperationFullProvideIdentifierWithCUI {
646
739
  clientValidation: StepHelper;
647
740
  postResponse: StepHelper<ProvideIdentifierPostResponseStart>;
648
741
  };
649
- constructor(tracker: CorbadoTracker, inputHtmlField?: HTMLInputElement);
742
+ constructor(tracker: CorbadoTracker, config?: OperationFullProvideIdentifierWithCUIConfig);
650
743
  private createStep;
651
744
  destroy(): void;
652
745
  }
@@ -683,6 +776,29 @@ declare class AppConfirmationOperationFull extends OperationFull {
683
776
  constructor(tracker: CorbadoTracker, explicitSpecType?: AppConfirmationOperationSpecType);
684
777
  }
685
778
 
779
+ /**
780
+ * Which captcha widget the integration observed. The tier is decided server-side per request, so it
781
+ * is a property of the rendered challenge, not of the integration:
782
+ * - `visible`: a widget presenting UI to the user. Can require interaction.
783
+ * - `invisible`: a widget that never presents UI and always solves itself.
784
+ */
785
+ type CaptchaOperationSpecType = "visible" | "invisible";
786
+ type CaptchaOperationConfig = {
787
+ explicitSpecType?: CaptchaOperationSpecType;
788
+ };
789
+ declare class CaptchaOperationFull extends OperationFull {
790
+ /**
791
+ * Challenge shown (`start`) until a captcha token exists (`finished`) or the challenge failed.
792
+ *
793
+ * The ceremony carries no actor: a widget that self-solves and one awaiting a click are the same
794
+ * observation from the page, and nothing in a vendor's frame reports which of the two happened.
795
+ */
796
+ readonly ceremony: StepHelper;
797
+ /** Submission of the captcha token and the server's verdict on it. */
798
+ readonly postResponse: StepHelper;
799
+ constructor(tracker: CorbadoTracker, config?: CaptchaOperationConfig);
800
+ }
801
+
686
802
  type ProvideDataOperationSpecType = "signup" | "login" | "recovery" | "enrollment";
687
803
  type ProvideDataOperationStart = {
688
804
  /** Stable name of the data field collected by this subflow, when known. */
@@ -715,7 +831,12 @@ interface TrackerOptions {
715
831
  logger?: Logger;
716
832
  /** Minimum time between attaching cached device info to events. */
717
833
  deviceInfoDebounceTime?: number;
718
- /** Per-field collection timeout. Defaults to 200ms. */
834
+ /**
835
+ * @deprecated The device info collection timeout is server-controlled via the SDK reliability
836
+ * config (`deviceInfoCollectorTimeoutMs`). This option only applies as long as no server config
837
+ * has been received (i.e. before the first config response is cached); once a server config is
838
+ * cached it wins. It will be removed in a future release.
839
+ */
719
840
  deviceInfoCollectorTimeout?: number;
720
841
  defaultTags?: Record<string, string>;
721
842
  /**
@@ -731,6 +852,8 @@ interface TrackerOptions {
731
852
  * It will be removed in a future release.
732
853
  */
733
854
  flushInterval?: number;
855
+ /** Generates new Observe session ids; returned values must be UUID-compatible. Existing stored sessions are still reused. */
856
+ sessionIdGenerator?: () => string;
734
857
  }
735
858
  declare class CorbadoTracker {
736
859
  private options;
@@ -749,6 +872,12 @@ declare class CorbadoTracker {
749
872
  private config;
750
873
  private deviceInfoManager;
751
874
  private seq;
875
+ /**
876
+ * When the continuity record's `lastActiveAt` was last persisted. Throttles that write inside the
877
+ * seq critical section (see {@link SESSION_ACTIVITY_WRITE_INTERVAL_MS}). 0 = not written yet on
878
+ * this load, so the first allocation always persists.
879
+ */
880
+ private lastActivityWriteAt;
752
881
  /** Persistent experiment assignments (experiment key → variant), attached to every produced event. */
753
882
  private experiments;
754
883
  /** Self-instrumentation state: re-entrancy guard, readiness, per-load dedupe, and pre-queue buffer. */
@@ -805,24 +934,42 @@ declare class CorbadoTracker {
805
934
  */
806
935
  private resolveExperiments;
807
936
  private isTrackingBlocked;
808
- private getSessionId;
937
+ private createSessionId;
938
+ private resolveSessionId;
809
939
  /**
810
940
  * Resolve the session id from localStorage so it survives reloads and is shared across tabs of the
811
941
  * same browser. Rotates after `config.sessionInactivityMs` of inactivity (server-controlled,
812
942
  * boot-snapshot like the rest of the config), resetting the seq counter.
943
+ *
944
+ * This is the ONLY place an inactivity rotation happens. Rotating here is safe because the load
945
+ * that triggers it also re-announces its flow (an integration emits `flow_started` on page load),
946
+ * so the fresh session id gets a classifiable flow. Mid-page there is no such re-announcement:
947
+ * rotating between two tracked events would leave the started flow unfinished in the old session
948
+ * and the remaining events without a flow start in the new one — one gap counted as a drop-off,
949
+ * one completion counted as nothing. `nextSeq` therefore never rotates on inactivity.
813
950
  */
814
951
  private getContinuitySessionId;
952
+ /**
953
+ * Persist the continuity record and remember when, so the throttled refresh in the seq critical
954
+ * section measures from the last write that actually happened — whoever made it.
955
+ */
956
+ private persistContinuitySession;
815
957
  /**
816
958
  * Return the next sequence number. With session continuity the counter is persisted so ordering
817
959
  * survives reloads/redirects; the read-increment-write runs under a cross-tab Web Lock
818
960
  * ({@link SEQ_LOCK_NAME}) so two tabs sharing the session cannot allocate the same seq (where Web
819
961
  * Locks are unavailable or exceed the configured timeout it degrades to the historical best-effort merge).
820
- * Lock grants are FIFO, so seq order matches `track()` call order within a tab. Every tracked event also bumps the
821
- * continuity session's `lastActiveAt`, so the inactivity window measures real user inactivity
822
- * instead of time-since-page-load (a long-lived active tab must not rotate the session on the next
823
- * reload). An empty store while this load already has a session id means persistence is failing
824
- * (or was cleared); the in-memory id is reused then — never re-minted — so a broken store degrades
825
- * to one session per page load instead of one session per event.
962
+ * Lock grants are FIFO, so seq order matches `track()` call order within a tab. Tracking also keeps the
963
+ * continuity session's `lastActiveAt` fresh (throttled, see {@link SESSION_ACTIVITY_WRITE_INTERVAL_MS}),
964
+ * so the window the NEXT boot evaluates measures real user
965
+ * inactivity instead of time-since-page-load (a long-lived active tab must not rotate the session
966
+ * on the next reload). It never rotates the session itself: the inactivity window is evaluated at
967
+ * boot only ({@link getContinuitySessionId} documents why). Consequence: while a page is never
968
+ * reloaded — foreground idle, bfcache restore, long-lived SPA tab — a session can outlive
969
+ * `sessionInactivityMs`. That inflates flow durations but keeps flow counts correct, which is the
970
+ * better half of the trade. An empty store while this load already has a session id means
971
+ * persistence is failing (or was cleared); the in-memory id is reused then — never re-minted — so
972
+ * a broken store degrades to one session per page load instead of one session per event.
826
973
  */
827
974
  private nextSeq;
828
975
  private resolveTrackingSourcePath;
@@ -1028,9 +1175,12 @@ declare class CorbadoTracker {
1028
1175
  * Synchronously flush any pending events and low events via beacon. Use during page-unload
1029
1176
  * style teardown where async flushing is unreliable.
1030
1177
  *
1178
+ * @param reason What triggered the flush; recorded as `meta.flushReason` on the batch. Defaults
1179
+ * to a direct call by the host app.
1180
+ *
1031
1181
  * @internal
1032
1182
  */
1033
- flushKeepalive(): void;
1183
+ flushKeepalive(reason?: FlushReason): void;
1034
1184
  /**
1035
1185
  * Keepalive flush requested by a low-event tracker's `pagehide` teardown. Gated by the
1036
1186
  * server-controlled trigger switch `tlf` (boot-snapshot, default true = historical behavior):
@@ -1040,16 +1190,17 @@ declare class CorbadoTracker {
1040
1190
  */
1041
1191
  lowEventFlushKeepalive(): void;
1042
1192
  passkeyLoginFullOperation(): PasskeyLoginOperationFull;
1043
- passkeyEnrollmentFullOperation(): PasskeyEnrollmentOperationFull;
1193
+ passkeyEnrollmentFullOperation(config?: PasskeyEnrollmentOperationConfig): PasskeyEnrollmentOperationFull;
1044
1194
  passwordLoginFullOperation(autoTrackConfig?: PasswordLoginAutoTrackConfig): PasswordLoginOperationFull;
1045
1195
  passwordEnrollmentFullOperation(autoTrackConfig?: PasswordEnrollmentAutoTrackConfig): PasswordEnrollmentOperationFull;
1046
1196
  emailLinkOperationFull(): EmailLinkOperationFull;
1047
- emailOtpOperationFull(): EmailOtpOperationFull;
1048
- smsOtpOperationFull(): SmsOtpOperationFull;
1049
- provideIdentifierOperationFull(inputHtmlField?: HTMLInputElement): OperationFullProvideIdentifierWithCUI;
1197
+ emailOtpOperationFull(config?: EmailOTPOperationConfig): EmailOtpOperationFull;
1198
+ smsOtpOperationFull(config?: SmsOTPOperationConfig): SmsOtpOperationFull;
1199
+ provideIdentifierOperationFull(config?: OperationFullProvideIdentifierWithCUIConfig): OperationFullProvideIdentifierWithCUI;
1050
1200
  provideDataOperationFull(config?: ProvideDataOperationConfig): ProvideDataOperationFull;
1051
1201
  socialLoginOperationFull(): SocialLoginOperationFull;
1052
1202
  appConfirmationOperationFull(explicitSpecType?: AppConfirmationOperationSpecType): AppConfirmationOperationFull;
1203
+ captchaOperationFull(config?: CaptchaOperationConfig): CaptchaOperationFull;
1053
1204
  /**
1054
1205
  * Flush any pending events and release all resources (timers, event listeners).
1055
1206
  *
@@ -1061,6 +1212,38 @@ declare class CorbadoTracker {
1061
1212
  * resources are released either way.
1062
1213
  */
1063
1214
  destroy(): Promise<void>;
1215
+ /**
1216
+ * Return the Observe session id this tracker is currently reporting under.
1217
+ *
1218
+ * @remarks
1219
+ * Use this to route a server-side event into the same session the browser reports to: read the id,
1220
+ * pass it to your own backend, and let the backend use it as the `sessionID` of its ingest call.
1221
+ * Reading it here is the supported path — the storage layout behind it is an implementation detail
1222
+ * that has already changed once (per-tab `sessionStorage` to the cross-tab continuity record).
1223
+ *
1224
+ * The value is **not stable for the lifetime of the page**. It changes on
1225
+ * {@link CorbadoTracker.resetSession}, when this tab adopts a continuity session another tab
1226
+ * rotated to, and when a failed bootstrap recovers. Read it at the moment you need it; never cache
1227
+ * it across a request.
1228
+ *
1229
+ * `undefined` means no session id could be established at all — an environment without Web Crypto,
1230
+ * where tracking is not working either. Skip the server-side event instead of sending an empty id:
1231
+ * the ingest API requires a UUID and would reject the batch.
1232
+ *
1233
+ * @returns The current session id, or `undefined` if none could be established.
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * const sessionId = tracker.getSessionId();
1238
+ * if (sessionId) {
1239
+ * await fetch("/api/checkout", {
1240
+ * method: "POST",
1241
+ * body: JSON.stringify({ ...payload, observeSessionId: sessionId }),
1242
+ * });
1243
+ * }
1244
+ * ```
1245
+ */
1246
+ getSessionId(): string | undefined;
1064
1247
  /** @internal */
1065
1248
  resetSession(): string;
1066
1249
  }
@@ -1206,6 +1389,9 @@ interface QueueOptions {
1206
1389
  *
1207
1390
  * Flushing is timer-driven only (the flush interval); `batchSize` caps the events per request, and a
1208
1391
  * flush drains all due work in sequential capped batches, stopping at the first failed send.
1392
+ *
1393
+ * Every flush carries a {@link FlushReason} that names its trigger; it is stamped onto the batch as
1394
+ * `meta.flushReason` so the server can see which triggers actually deliver.
1209
1395
  */
1210
1396
  declare class RequestQueue {
1211
1397
  private readonly logger;
@@ -1243,8 +1429,11 @@ declare class RequestQueue {
1243
1429
  * config (see {@link handleConfigResponse}).
1244
1430
  */
1245
1431
  private config;
1246
- /** Event names that trigger an immediate flush at enqueue time (config.flushOnEventNames). */
1247
- private priorityNames;
1432
+ /**
1433
+ * Flow types whose completion triggers an immediate flush at enqueue time
1434
+ * (config.flushOnFlowTypeFinished).
1435
+ */
1436
+ private priorityFlowTypes;
1248
1437
  private store?;
1249
1438
  /**
1250
1439
  * Once the server has answered the config request with a 2xx (200 = fresh config cached for the
@@ -1279,20 +1468,35 @@ declare class RequestQueue {
1279
1468
  */
1280
1469
  enqueueTelemetry(entry: TelemetryEntry): void;
1281
1470
  private scheduleAfterEnqueue;
1471
+ /**
1472
+ * Whether this event completes one of the configured priority flow types. Only the two flow
1473
+ * completion events qualify — `flow_finished` and `flow_auto_finished`, both carrying the
1474
+ * finished flow in `data.flowName`. Custom events never match, even when named like one of them.
1475
+ */
1476
+ private isPriorityEvent;
1477
+ /**
1478
+ * Arm the flush timer. The `reason` travels with the timer into the flush it triggers; an
1479
+ * already-armed timer keeps the reason it was armed with (the flush it fires is that flush, and
1480
+ * it takes whatever accumulated in the meantime with it).
1481
+ */
1282
1482
  private scheduleFlush;
1283
1483
  private clearTimer;
1284
1484
  /**
1485
+ * @param reason What triggered this flush; stamped onto every batch it sends as
1486
+ * `meta.flushReason`. Defaults to the ordinary interval cadence.
1487
+ *
1285
1488
  * Error situations:
1286
1489
  * - Queue is empty: return without calling transport.send
1287
1490
  * - A flush is already in progress: return without calling transport.send again
1288
1491
  * - transport.send rejects or throws, or any other error in the try block: log "Unexpected error in queue flush"
1289
1492
  */
1290
- flush(): Promise<void>;
1493
+ flush(reason?: FlushReason): Promise<void>;
1291
1494
  /**
1292
- * Stamps delivery metadata onto the batch: the config version this load runs under (omitted on
1293
- * built-in defaults) and the number of prior failed delivery attempts (the max across its entries,
1294
- * only when at least one entry is a retry). `entry.attempts` is incremented on each failed flush,
1295
- * so it equals the retry count at send time. The transport later merges in `sent`/`transport`.
1495
+ * Stamps delivery metadata onto the batch: the trigger that caused this flush, the config version
1496
+ * this load runs under (omitted on built-in defaults) and the number of prior failed delivery
1497
+ * attempts (the max across its entries, only when at least one entry is a retry). `entry.attempts`
1498
+ * is incremented on each failed flush, so it equals the retry count at send time. The transport
1499
+ * later merges in `sent`/`transport`.
1296
1500
  */
1297
1501
  private attachBatchMeta;
1298
1502
  private getDuePending;
@@ -1311,7 +1515,7 @@ declare class RequestQueue {
1311
1515
  /**
1312
1516
  * Switch this load from the built-in defaults to the first server config (defaults boot only).
1313
1517
  * Most fields are read at use time, so replacing the reference is enough; only the derived state
1314
- * (priority-name set, durable outbox store) needs rebuilding.
1518
+ * (priority flow type set, durable outbox store) needs rebuilding.
1315
1519
  */
1316
1520
  private applyConfigLive;
1317
1521
  /** Returns true when the batch was acknowledged with a 2xx (safe to keep draining). */
@@ -1339,9 +1543,13 @@ declare class RequestQueue {
1339
1543
  * with the host app). With `config.durableOutbox` enabled, entries are NOT removed (they are
1340
1544
  * resent on the next load and deduped server-side); otherwise the sent chunk is removed
1341
1545
  * best-effort and a remainder keeps the next lifecycle signal flush-worthy.
1342
- * Deduplicated: a call with nothing newly enqueued since the last sync flush is a no-op.
1546
+ * Deduplicated: a call with nothing newly enqueued since the last sync flush is a no-op — so of
1547
+ * several unload signals in one navigation only the first one that finds something to send is
1548
+ * recorded as the flush reason.
1549
+ *
1550
+ * @param reason What triggered the unload flush; defaults to a direct call by the host app.
1343
1551
  */
1344
- flushKeepalive(): void;
1552
+ flushKeepalive(reason?: FlushReason): void;
1345
1553
  private flushSync;
1346
1554
  /**
1347
1555
  * Error situations:
@@ -1361,6 +1569,12 @@ declare const CONFIG_REQUEST_HEADER = "X-Corbado-Observe-Config";
1361
1569
  /** Built-in flush interval used until the server provides one. Matches the historical default. */
1362
1570
  declare const DEFAULT_FLUSH_INTERVAL_MS = 500;
1363
1571
  declare const DEFAULT_SEQ_LOCK_TIMEOUT_MS = 50;
1572
+ /**
1573
+ * Built-in per-field device info collection timeout. Also the timeout of the very first collection
1574
+ * of a load that booted without a cached config, since collection starts before the first server
1575
+ * response can arrive — generous enough that a slow-but-working browser API still answers.
1576
+ */
1577
+ declare const DEFAULT_DEVICE_INFO_COLLECTOR_TIMEOUT_MS = 1000;
1364
1578
  /**
1365
1579
  * Clamping bounds for server-provided config values. They protect the client from a dangerous
1366
1580
  * server-side config mistake (e.g. a 0ms flush interval would busy-loop); the server clamps with
@@ -1384,10 +1598,14 @@ declare const CONFIG_BOUNDS: {
1384
1598
  readonly max: 86400000;
1385
1599
  };
1386
1600
  readonly seqLockTimeoutMs: {
1387
- readonly min: 1;
1601
+ readonly min: 0;
1388
1602
  readonly max: 250;
1389
1603
  };
1390
- readonly flushOnEventNames: {
1604
+ readonly deviceInfoCollectorTimeoutMs: {
1605
+ readonly min: 10;
1606
+ readonly max: 10000;
1607
+ };
1608
+ readonly flushOnFlowTypeFinished: {
1391
1609
  readonly maxEntries: 20;
1392
1610
  readonly maxNameLength: 100;
1393
1611
  };
@@ -1483,6 +1701,11 @@ declare class EventStore {
1483
1701
  declare function init(options: TrackerOptions): CorbadoTracker;
1484
1702
  declare function getTracker(): CorbadoTracker | undefined;
1485
1703
  declare function resetSession(): string | undefined;
1704
+ /**
1705
+ * Session id of the global tracker, or `undefined` when no tracker was initialized or no session
1706
+ * could be established. See {@link CorbadoTracker.getSessionId}.
1707
+ */
1708
+ declare function getSessionId(): string | undefined;
1486
1709
  declare function setExperiment(key: string, variant: string): void;
1487
1710
  declare function setExperiments(assignments: Record<string, string>): void;
1488
1711
  declare function clearExperiment(key: string): void;
@@ -1493,4 +1716,4 @@ declare function logInfo(message: string): void;
1493
1716
  declare function logError(message: string): void;
1494
1717
  declare function destroy(): Promise<void>;
1495
1718
 
1496
- export { type AppConfirmationOperationCeremonyTypedError, AppConfirmationOperationFull, type AppConfirmationOperationRetryReason, type AppConfirmationOperationSpecType, type AppConfirmationOperationStart, type AuthDecisionFinished, type AuthDecisionStarted, AuthEventName, type AuthMethodDecisionFinished, type AuthMethodDecisionStarted, type AuthMethodType, type BaseEvent, CEREMONY_LOW_EVENT_TAIL_MS, 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_SEQ_LOCK_TIMEOUT_MS, 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, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, PasswordLoginOperationFull, type PasswordLoginTypedError, type PredefinedEvent, type ProvideDataOperationConfig, ProvideDataOperationFull, type ProvideDataOperationPostResponseStart, type ProvideDataOperationSpecType, type ProvideDataOperationStart, 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 SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, SocialLoginOperationFull, type SocialLoginProviderType, type SocialLoginSpecType, type StepHelper, type StepOptions, type StorageEngine, type SubflowTrigger, type SubflowType, type TelemetryEntry, type TelemetryLevel, type TelemetrySink, type TrackerOptions, type Transport, type TransportMakeRequestResponse, type TransportOptions, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getTracker, init, loadCachedConfig, logError, logInfo, parseReliabilityConfig, resetSession, setExperiment, setExperiments, telemetry };
1719
+ export { type AppConfirmationOperationCeremonyTypedError, AppConfirmationOperationFull, type AppConfirmationOperationRetryReason, type AppConfirmationOperationSpecType, type AppConfirmationOperationStart, type AuthDecisionFinished, type AuthDecisionStarted, AuthEventName, type AuthMethodDecisionFinished, type AuthMethodDecisionStarted, type AuthMethodType, type BaseEvent, CEREMONY_LOW_EVENT_TAIL_MS, CONFIG_BOUNDS, CONFIG_REQUEST_HEADER, CONFIG_STORAGE_KEY, type CaptchaOperationConfig, CaptchaOperationFull, type CaptchaOperationSpecType, type ClientCapabilities, type ClientEnvHandleMeta, type ClientEnvHandleMetaSource, type Conversion, CookieStorage, CorbadoTracker, type CreateLoggerOptions, type CustomEvent, DEFAULT_DEVICE_INFO_COLLECTOR_TIMEOUT_MS, DEFAULT_FLUSH_INTERVAL_MS, DEFAULT_MAX_ENTRIES, DEFAULT_MAX_SERIALIZED_LENGTH, DEFAULT_RELIABILITY_CONFIG, DEFAULT_SEQ_LOCK_TIMEOUT_MS, DEFAULT_SESSION_INACTIVITY_MS, type DeviceInfo, type DeviceInfoCollectionError, type DeviceInfoDataWeb, type DeviceType, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationConfig, 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 FlushReason, type JavaScriptHighEntropy, LocalStorage, type Logger, type LowEvent, type MultiFlowReset, type MultiFlowStarted, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, OperationFull, OperationFullProvideIdentifierWithCUI, type OperationFullProvideIdentifierWithCUIConfig, type OutboxEntry, type PasskeyEnrollmentCeremonyFinished, type PasskeyEnrollmentCeremonyStart, type PasskeyEnrollmentGetOptionsFinished, type PasskeyEnrollmentGetOptionsStart, type PasskeyEnrollmentOperationConfig, PasskeyEnrollmentOperationFull, type PasskeyEnrollmentPostResponseStart, type PasskeyLoginCUIGetOptionsFinished, type PasskeyLoginCUIGetOptionsStart, type PasskeyLoginCUISpecType, type PasskeyLoginCeremonyFinished, type PasskeyLoginCeremonyStart, type PasskeyLoginClientError, type PasskeyLoginFinish, type PasskeyLoginGetOptionsFinished, type PasskeyLoginGetOptionsStart, PasskeyLoginOperationFull, type PasskeyLoginPostResponseStart, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentAutoTrackConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginAutoTrackConfig, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, PasswordLoginOperationFull, type PasswordLoginTypedError, type PredefinedEvent, type ProvideDataOperationConfig, ProvideDataOperationFull, type ProvideDataOperationPostResponseStart, type ProvideDataOperationSpecType, type ProvideDataOperationStart, 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 SmsOTPOperationConfig, type SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, SocialLoginOperationFull, type SocialLoginProviderType, type SocialLoginSpecType, type StepHelper, type StepOptions, type StorageEngine, type SubflowTrigger, type SubflowType, type TelemetryEntry, type TelemetryLevel, type TelemetrySink, type TrackerOptions, type Transport, type TransportMakeRequestResponse, type TransportOptions, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getSessionId, getTracker, init, loadCachedConfig, logError, logInfo, parseReliabilityConfig, resetSession, setExperiment, setExperiments, telemetry };