@corbado/observe 0.16.4 → 0.16.6

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
@@ -58,6 +58,17 @@ type UserReference = {
58
58
  /** Shared UUID used to link sessions across environments. */
59
59
  crossEnvironmentTransactionID?: string;
60
60
  };
61
+ /**
62
+ * A stable reference to the flows one flow event belongs to: every flow a `flow_started` opened,
63
+ * or the flow a `flow_finished` finished.
64
+ */
65
+ interface FlowHandle {
66
+ /** Attach identity to this journey, including after it finishes or the tracker session changes.
67
+ * Resolves when tracking/enqueue completes, not when server delivery is acknowledged.
68
+ * The tracker must remain alive; this method does not revive a destroyed tracker.
69
+ */
70
+ enrich(user: UserReference): Promise<void>;
71
+ }
61
72
  type LegacyUserReference = {
62
73
  /** @deprecated Use tracker.setUser() within the active flow instead. */
63
74
  userId?: string;
@@ -254,6 +265,14 @@ interface EventBatchMeta {
254
265
  * changes propagate with page-load lag, so calendar-date cohorts are mixed).
255
266
  */
256
267
  configVersion?: string;
268
+ /**
269
+ * Project-scoped data policy code (integer 0..255; an opaque selector of a policy configured in
270
+ * Corbado, 0 = the project default) the tracker is running under, as set via
271
+ * `init({ dataPolicy })` or `setDataPolicy()`. Once known it is sent on every batch (including an
272
+ * explicit 0); omitted while no policy has ever been set. The server records the latest code it
273
+ * receives per session (last write wins), so the SDK always sends the current value.
274
+ */
275
+ dataPolicy?: number;
257
276
  }
258
277
  interface EventMeta {
259
278
  initiator?: LowEventInitiator;
@@ -1219,6 +1238,12 @@ interface TrackerOptions {
1219
1238
  * assignments and then attached to every event the tracker produces (see {@link CorbadoTracker.setExperiment}).
1220
1239
  */
1221
1240
  experiments?: Record<string, string>;
1241
+ /**
1242
+ * Data policy code to seed at init: a project-scoped non-negative integer (0..255) selecting a
1243
+ * policy configured in Corbado (0 is the project default). Overlays any persisted code and is then
1244
+ * sent as `meta.dataPolicy` on every batch (see {@link CorbadoTracker.setDataPolicy}).
1245
+ */
1246
+ dataPolicy?: number;
1222
1247
  applicationId?: string;
1223
1248
  /**
1224
1249
  * @deprecated The flush interval is server-controlled via the SDK reliability config
@@ -1259,6 +1284,11 @@ declare class CorbadoTracker {
1259
1284
  private lastActivityWriteAt;
1260
1285
  /** Persistent experiment assignments (experiment key → variant), attached to every produced event. */
1261
1286
  private experiments;
1287
+ /**
1288
+ * Persistent data policy code, stamped into every batch's `meta.dataPolicy` once set. Never
1289
+ * cleared (only overwritten): it survives reloads, session rotation, resetSession and destroy.
1290
+ */
1291
+ private dataPolicy?;
1262
1292
  /** Self-instrumentation state: re-entrancy guard, readiness, per-load dedupe, and pre-queue buffer. */
1263
1293
  private telemetryReporting;
1264
1294
  private telemetryReady;
@@ -1307,6 +1337,23 @@ declare class CorbadoTracker {
1307
1337
  * @returns A frozen snapshot, created fresh on every call.
1308
1338
  */
1309
1339
  getSdkConfig(): ObserveSdkConfigSnapshot;
1340
+ /**
1341
+ * Set the data policy code for this tracker (e.g. `setDataPolicy(1)` once the user agreed to
1342
+ * extended processing; `setDataPolicy(0)` to return to the project default). Codes are
1343
+ * project-scoped non-negative integers (0..255) selecting a policy configured in Corbado; they
1344
+ * carry no ordering.
1345
+ *
1346
+ * The code is persisted (localStorage, project-scoped) and sent as `meta.dataPolicy` on every
1347
+ * subsequent batch, across reloads and session rotation. It is never cleared, only overwritten.
1348
+ * The server records the latest code it receives for a session (last write wins). Invalid codes
1349
+ * are ignored with a debug log; never throws.
1350
+ */
1351
+ setDataPolicy(code: number): void;
1352
+ /** Returns the current data policy code, or undefined when none has ever been set. */
1353
+ getDataPolicy(): number | undefined;
1354
+ private static isValidDataPolicy;
1355
+ private loadPersistedDataPolicy;
1356
+ private persistDataPolicy;
1310
1357
  private static isValidExperimentKey;
1311
1358
  private static isValidExperimentVariant;
1312
1359
  private loadPersistedExperiments;
@@ -1418,6 +1465,9 @@ declare class CorbadoTracker {
1418
1465
  * checkout login, or account recovery). If users can choose between multiple flows
1419
1466
  * (such as login vs signup), pass `flowNames` and optionally `defaultFlowName`.
1420
1467
  *
1468
+ * The returned handle can attach identity after completion with `await flow.enrich({ userId })`.
1469
+ * Enrichment requires a backend supporting explicit event targeting.
1470
+ *
1421
1471
  * @param data - Flow metadata, including one flow (`flowName`) or multiple candidates (`flowNames`).
1422
1472
  * @param tags - Optional key-value tags for filtering and segmentation.
1423
1473
  * @param experiments - Optional per-call experiment overrides.
@@ -1433,7 +1483,7 @@ declare class CorbadoTracker {
1433
1483
  * });
1434
1484
  * ```
1435
1485
  */
1436
- flowStarted(data: FlowStarted | MultiFlowStarted, tags?: Record<string, string>, experiments?: Record<string, string>, contexts?: Record<string, unknown>): void;
1486
+ flowStarted(data: FlowStarted | MultiFlowStarted, tags?: Record<string, string>, experiments?: Record<string, string>, contexts?: Record<string, unknown>): FlowHandle;
1437
1487
  /**
1438
1488
  * Track when the user commits to a specific flow.
1439
1489
  *
@@ -1479,8 +1529,13 @@ declare class CorbadoTracker {
1479
1529
  *
1480
1530
  * @remarks
1481
1531
  * Fire this when the user has finished the target flow end-to-end, such as completed login,
1482
- * signup, or recovery. Record identity separately with `setUser()` while the flow
1483
- * is still active, before calling `flowFinished()`.
1532
+ * signup, or recovery. Record identity with `setUser()` while the flow is active,
1533
+ * or enrich it after completion through the handle returned by `flowStarted()` or by this call.
1534
+ *
1535
+ * The returned handle targets the flow this event finished, so identity learned only after
1536
+ * completion — for example from a profile request that follows account creation — can be
1537
+ * attached with `await finished.enrich({ userId })` even on a page that never saw the flow start.
1538
+ * Enrichment requires a backend supporting explicit flow-event targeting.
1484
1539
  *
1485
1540
  * Legacy identity fields in `data` remain supported but are deprecated.
1486
1541
  *
@@ -1489,12 +1544,14 @@ declare class CorbadoTracker {
1489
1544
  *
1490
1545
  * @example
1491
1546
  * ```typescript
1492
- * tracker.flowFinished({
1493
- * flowName: "login",
1494
- * });
1547
+ * const finished = tracker.flowFinished({ flowName: "signup" });
1548
+ * const userId = await hashUserId(createdAccountId);
1549
+ * await finished.enrich({ userId });
1495
1550
  * ```
1496
1551
  */
1497
- flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): void;
1552
+ flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): FlowHandle;
1553
+ /** Emits `flow_enriched` against an explicit target, in the session that emitted the target. */
1554
+ private flowHandle;
1498
1555
  /**
1499
1556
  * Track when an in-progress flow is reset and restarted.
1500
1557
  *
@@ -1940,6 +1997,11 @@ interface QueueOptions {
1940
1997
  * {@link EventStore}). Defaults to the shared {@link OUTBOX_LOCK_NAME}.
1941
1998
  */
1942
1999
  outboxLockName?: string;
2000
+ /**
2001
+ * Returns the data policy code to stamp into `meta.dataPolicy` of every batch, or undefined when
2002
+ * none has ever been set. Read at send time so a change applies to the next batch without a flush.
2003
+ */
2004
+ getDataPolicy?: () => number | undefined;
1943
2005
  }
1944
2006
  /**
1945
2007
  * @remarks When `window` is defined, `visibilitychange` (when the document becomes hidden) and `pagehide`
@@ -1993,6 +2055,7 @@ declare class RequestQueue {
1993
2055
  private readonly debug;
1994
2056
  private readonly requestConfig;
1995
2057
  private readonly onConfigReceived?;
2058
+ private readonly getDataPolicy?;
1996
2059
  /** Current delivery policy, including live updates. */
1997
2060
  private config;
1998
2061
  /**
@@ -2063,10 +2126,13 @@ declare class RequestQueue {
2063
2126
  * Stamps delivery metadata onto the batch: the trigger that caused this flush, the config version
2064
2127
  * this load runs under (omitted on built-in defaults) and the number of prior failed delivery
2065
2128
  * attempts (the max across its entries, only when at least one entry is a retry). `entry.attempts`
2066
- * is incremented on each failed flush, so it equals the retry count at send time. The transport
2067
- * later merges in `sent`/`transport`.
2129
+ * is incremented on each failed flush, so it equals the retry count at send time. The data policy
2130
+ * code (when one has ever been set) is read live, so it reflects the tracker state at send time.
2131
+ * The transport later merges in `sent`/`transport`.
2068
2132
  */
2069
2133
  private attachBatchMeta;
2134
+ /** The data policy code from the tracker, or undefined; a throwing getter must never break a flush. */
2135
+ private readDataPolicy;
2070
2136
  private getDuePending;
2071
2137
  private takeLows;
2072
2138
  private validPendingLow;
@@ -2350,4 +2416,4 @@ declare function logInfo(message: string): void;
2350
2416
  declare function logError(message: string): void;
2351
2417
  declare function destroy(): Promise<void>;
2352
2418
 
2353
- export { type AppConfirmationOperationCeremonyTypedError, type AppConfirmationOperationConfig, 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, type EmailLinkOperationConfig, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationConfig, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type ErrorStepOptions, 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, type KeyOperationConfig, KeyRegistrationOperationFull, KeySigningOperationFull, LocalStorage, type Logger, type LowEvent, type LowEventFieldRole, type LowEventInitiator, type LowEventInputEffect, type LowEventSourceKind, type MultiFlowReset, type MultiFlowStarted, NamespacedStorage, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, type ObserveSdkConfigSnapshot, 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, type PasskeyLoginOperationConfig, PasskeyLoginOperationFull, type PasskeyLoginPostResponseStart, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, type PasswordLoginConfig, type PasswordLoginExplicitSpecType, 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, RAW_ERROR_BOUNDS, type RawErrorEnvelope, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkReliabilityConfigOverrides, type SdkRetryConfig, type SerializeRawErrorOptions, SessionStorage, type SmsOTPOperationConfig, type SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, type SocialLoginOperationConfig, 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 TrustedDeviceBindingMetadata, type TrustedDeviceCheckConfig, TrustedDeviceCheckOperationFull, type TrustedDeviceCheckResult, type TrustedDeviceCheckStepResult, type TrustedDeviceCheckTypedError, TrustedDeviceEnrollmentOperationFull, type TrustedDeviceEnrollmentResult, type TrustedDeviceOperationConfig, type TrustedDevicePurpose, type TrustedDeviceStorage, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getSessionId, getTracker, init, loadCachedConfig, logError, logInfo, namespacedKey, parseReliabilityConfig, resetSession, resolveRawErrorLimits, resolveReliabilityConfig, sanitizeAssertionResponse, sanitizeCreationOptions, sanitizeCreationResponse, sanitizeRequestOptions, serializeRawError, setExperiment, setExperiments, setUser, telemetry };
2419
+ export { type AppConfirmationOperationCeremonyTypedError, type AppConfirmationOperationConfig, 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, type EmailLinkOperationConfig, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationConfig, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type ErrorStepOptions, type Event, type EventBatch, type EventBatchMeta, type EventMeta, EventStore, type EventType, type FlowAutoFinished, type FlowDecided, type FlowFinished, type FlowHandle, type FlowReset, type FlowStarted, type FlowType, type FlushReason, type JavaScriptHighEntropy, type KeyOperationConfig, KeyRegistrationOperationFull, KeySigningOperationFull, LocalStorage, type Logger, type LowEvent, type LowEventFieldRole, type LowEventInitiator, type LowEventInputEffect, type LowEventSourceKind, type MultiFlowReset, type MultiFlowStarted, NamespacedStorage, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, type ObserveSdkConfigSnapshot, 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, type PasskeyLoginOperationConfig, PasskeyLoginOperationFull, type PasskeyLoginPostResponseStart, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, type PasswordLoginConfig, type PasswordLoginExplicitSpecType, 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, RAW_ERROR_BOUNDS, type RawErrorEnvelope, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkReliabilityConfigOverrides, type SdkRetryConfig, type SerializeRawErrorOptions, SessionStorage, type SmsOTPOperationConfig, type SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, type SocialLoginOperationConfig, 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 TrustedDeviceBindingMetadata, type TrustedDeviceCheckConfig, TrustedDeviceCheckOperationFull, type TrustedDeviceCheckResult, type TrustedDeviceCheckStepResult, type TrustedDeviceCheckTypedError, TrustedDeviceEnrollmentOperationFull, type TrustedDeviceEnrollmentResult, type TrustedDeviceOperationConfig, type TrustedDevicePurpose, type TrustedDeviceStorage, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getSessionId, getTracker, init, loadCachedConfig, logError, logInfo, namespacedKey, parseReliabilityConfig, resetSession, resolveRawErrorLimits, resolveReliabilityConfig, sanitizeAssertionResponse, sanitizeCreationOptions, sanitizeCreationResponse, sanitizeRequestOptions, serializeRawError, setExperiment, setExperiments, setUser, telemetry };
package/dist/index.d.ts CHANGED
@@ -58,6 +58,17 @@ type UserReference = {
58
58
  /** Shared UUID used to link sessions across environments. */
59
59
  crossEnvironmentTransactionID?: string;
60
60
  };
61
+ /**
62
+ * A stable reference to the flows one flow event belongs to: every flow a `flow_started` opened,
63
+ * or the flow a `flow_finished` finished.
64
+ */
65
+ interface FlowHandle {
66
+ /** Attach identity to this journey, including after it finishes or the tracker session changes.
67
+ * Resolves when tracking/enqueue completes, not when server delivery is acknowledged.
68
+ * The tracker must remain alive; this method does not revive a destroyed tracker.
69
+ */
70
+ enrich(user: UserReference): Promise<void>;
71
+ }
61
72
  type LegacyUserReference = {
62
73
  /** @deprecated Use tracker.setUser() within the active flow instead. */
63
74
  userId?: string;
@@ -254,6 +265,14 @@ interface EventBatchMeta {
254
265
  * changes propagate with page-load lag, so calendar-date cohorts are mixed).
255
266
  */
256
267
  configVersion?: string;
268
+ /**
269
+ * Project-scoped data policy code (integer 0..255; an opaque selector of a policy configured in
270
+ * Corbado, 0 = the project default) the tracker is running under, as set via
271
+ * `init({ dataPolicy })` or `setDataPolicy()`. Once known it is sent on every batch (including an
272
+ * explicit 0); omitted while no policy has ever been set. The server records the latest code it
273
+ * receives per session (last write wins), so the SDK always sends the current value.
274
+ */
275
+ dataPolicy?: number;
257
276
  }
258
277
  interface EventMeta {
259
278
  initiator?: LowEventInitiator;
@@ -1219,6 +1238,12 @@ interface TrackerOptions {
1219
1238
  * assignments and then attached to every event the tracker produces (see {@link CorbadoTracker.setExperiment}).
1220
1239
  */
1221
1240
  experiments?: Record<string, string>;
1241
+ /**
1242
+ * Data policy code to seed at init: a project-scoped non-negative integer (0..255) selecting a
1243
+ * policy configured in Corbado (0 is the project default). Overlays any persisted code and is then
1244
+ * sent as `meta.dataPolicy` on every batch (see {@link CorbadoTracker.setDataPolicy}).
1245
+ */
1246
+ dataPolicy?: number;
1222
1247
  applicationId?: string;
1223
1248
  /**
1224
1249
  * @deprecated The flush interval is server-controlled via the SDK reliability config
@@ -1259,6 +1284,11 @@ declare class CorbadoTracker {
1259
1284
  private lastActivityWriteAt;
1260
1285
  /** Persistent experiment assignments (experiment key → variant), attached to every produced event. */
1261
1286
  private experiments;
1287
+ /**
1288
+ * Persistent data policy code, stamped into every batch's `meta.dataPolicy` once set. Never
1289
+ * cleared (only overwritten): it survives reloads, session rotation, resetSession and destroy.
1290
+ */
1291
+ private dataPolicy?;
1262
1292
  /** Self-instrumentation state: re-entrancy guard, readiness, per-load dedupe, and pre-queue buffer. */
1263
1293
  private telemetryReporting;
1264
1294
  private telemetryReady;
@@ -1307,6 +1337,23 @@ declare class CorbadoTracker {
1307
1337
  * @returns A frozen snapshot, created fresh on every call.
1308
1338
  */
1309
1339
  getSdkConfig(): ObserveSdkConfigSnapshot;
1340
+ /**
1341
+ * Set the data policy code for this tracker (e.g. `setDataPolicy(1)` once the user agreed to
1342
+ * extended processing; `setDataPolicy(0)` to return to the project default). Codes are
1343
+ * project-scoped non-negative integers (0..255) selecting a policy configured in Corbado; they
1344
+ * carry no ordering.
1345
+ *
1346
+ * The code is persisted (localStorage, project-scoped) and sent as `meta.dataPolicy` on every
1347
+ * subsequent batch, across reloads and session rotation. It is never cleared, only overwritten.
1348
+ * The server records the latest code it receives for a session (last write wins). Invalid codes
1349
+ * are ignored with a debug log; never throws.
1350
+ */
1351
+ setDataPolicy(code: number): void;
1352
+ /** Returns the current data policy code, or undefined when none has ever been set. */
1353
+ getDataPolicy(): number | undefined;
1354
+ private static isValidDataPolicy;
1355
+ private loadPersistedDataPolicy;
1356
+ private persistDataPolicy;
1310
1357
  private static isValidExperimentKey;
1311
1358
  private static isValidExperimentVariant;
1312
1359
  private loadPersistedExperiments;
@@ -1418,6 +1465,9 @@ declare class CorbadoTracker {
1418
1465
  * checkout login, or account recovery). If users can choose between multiple flows
1419
1466
  * (such as login vs signup), pass `flowNames` and optionally `defaultFlowName`.
1420
1467
  *
1468
+ * The returned handle can attach identity after completion with `await flow.enrich({ userId })`.
1469
+ * Enrichment requires a backend supporting explicit event targeting.
1470
+ *
1421
1471
  * @param data - Flow metadata, including one flow (`flowName`) or multiple candidates (`flowNames`).
1422
1472
  * @param tags - Optional key-value tags for filtering and segmentation.
1423
1473
  * @param experiments - Optional per-call experiment overrides.
@@ -1433,7 +1483,7 @@ declare class CorbadoTracker {
1433
1483
  * });
1434
1484
  * ```
1435
1485
  */
1436
- flowStarted(data: FlowStarted | MultiFlowStarted, tags?: Record<string, string>, experiments?: Record<string, string>, contexts?: Record<string, unknown>): void;
1486
+ flowStarted(data: FlowStarted | MultiFlowStarted, tags?: Record<string, string>, experiments?: Record<string, string>, contexts?: Record<string, unknown>): FlowHandle;
1437
1487
  /**
1438
1488
  * Track when the user commits to a specific flow.
1439
1489
  *
@@ -1479,8 +1529,13 @@ declare class CorbadoTracker {
1479
1529
  *
1480
1530
  * @remarks
1481
1531
  * Fire this when the user has finished the target flow end-to-end, such as completed login,
1482
- * signup, or recovery. Record identity separately with `setUser()` while the flow
1483
- * is still active, before calling `flowFinished()`.
1532
+ * signup, or recovery. Record identity with `setUser()` while the flow is active,
1533
+ * or enrich it after completion through the handle returned by `flowStarted()` or by this call.
1534
+ *
1535
+ * The returned handle targets the flow this event finished, so identity learned only after
1536
+ * completion — for example from a profile request that follows account creation — can be
1537
+ * attached with `await finished.enrich({ userId })` even on a page that never saw the flow start.
1538
+ * Enrichment requires a backend supporting explicit flow-event targeting.
1484
1539
  *
1485
1540
  * Legacy identity fields in `data` remain supported but are deprecated.
1486
1541
  *
@@ -1489,12 +1544,14 @@ declare class CorbadoTracker {
1489
1544
  *
1490
1545
  * @example
1491
1546
  * ```typescript
1492
- * tracker.flowFinished({
1493
- * flowName: "login",
1494
- * });
1547
+ * const finished = tracker.flowFinished({ flowName: "signup" });
1548
+ * const userId = await hashUserId(createdAccountId);
1549
+ * await finished.enrich({ userId });
1495
1550
  * ```
1496
1551
  */
1497
- flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): void;
1552
+ flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): FlowHandle;
1553
+ /** Emits `flow_enriched` against an explicit target, in the session that emitted the target. */
1554
+ private flowHandle;
1498
1555
  /**
1499
1556
  * Track when an in-progress flow is reset and restarted.
1500
1557
  *
@@ -1940,6 +1997,11 @@ interface QueueOptions {
1940
1997
  * {@link EventStore}). Defaults to the shared {@link OUTBOX_LOCK_NAME}.
1941
1998
  */
1942
1999
  outboxLockName?: string;
2000
+ /**
2001
+ * Returns the data policy code to stamp into `meta.dataPolicy` of every batch, or undefined when
2002
+ * none has ever been set. Read at send time so a change applies to the next batch without a flush.
2003
+ */
2004
+ getDataPolicy?: () => number | undefined;
1943
2005
  }
1944
2006
  /**
1945
2007
  * @remarks When `window` is defined, `visibilitychange` (when the document becomes hidden) and `pagehide`
@@ -1993,6 +2055,7 @@ declare class RequestQueue {
1993
2055
  private readonly debug;
1994
2056
  private readonly requestConfig;
1995
2057
  private readonly onConfigReceived?;
2058
+ private readonly getDataPolicy?;
1996
2059
  /** Current delivery policy, including live updates. */
1997
2060
  private config;
1998
2061
  /**
@@ -2063,10 +2126,13 @@ declare class RequestQueue {
2063
2126
  * Stamps delivery metadata onto the batch: the trigger that caused this flush, the config version
2064
2127
  * this load runs under (omitted on built-in defaults) and the number of prior failed delivery
2065
2128
  * attempts (the max across its entries, only when at least one entry is a retry). `entry.attempts`
2066
- * is incremented on each failed flush, so it equals the retry count at send time. The transport
2067
- * later merges in `sent`/`transport`.
2129
+ * is incremented on each failed flush, so it equals the retry count at send time. The data policy
2130
+ * code (when one has ever been set) is read live, so it reflects the tracker state at send time.
2131
+ * The transport later merges in `sent`/`transport`.
2068
2132
  */
2069
2133
  private attachBatchMeta;
2134
+ /** The data policy code from the tracker, or undefined; a throwing getter must never break a flush. */
2135
+ private readDataPolicy;
2070
2136
  private getDuePending;
2071
2137
  private takeLows;
2072
2138
  private validPendingLow;
@@ -2350,4 +2416,4 @@ declare function logInfo(message: string): void;
2350
2416
  declare function logError(message: string): void;
2351
2417
  declare function destroy(): Promise<void>;
2352
2418
 
2353
- export { type AppConfirmationOperationCeremonyTypedError, type AppConfirmationOperationConfig, 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, type EmailLinkOperationConfig, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationConfig, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type ErrorStepOptions, 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, type KeyOperationConfig, KeyRegistrationOperationFull, KeySigningOperationFull, LocalStorage, type Logger, type LowEvent, type LowEventFieldRole, type LowEventInitiator, type LowEventInputEffect, type LowEventSourceKind, type MultiFlowReset, type MultiFlowStarted, NamespacedStorage, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, type ObserveSdkConfigSnapshot, 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, type PasskeyLoginOperationConfig, PasskeyLoginOperationFull, type PasskeyLoginPostResponseStart, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, type PasswordLoginConfig, type PasswordLoginExplicitSpecType, 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, RAW_ERROR_BOUNDS, type RawErrorEnvelope, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkReliabilityConfigOverrides, type SdkRetryConfig, type SerializeRawErrorOptions, SessionStorage, type SmsOTPOperationConfig, type SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, type SocialLoginOperationConfig, 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 TrustedDeviceBindingMetadata, type TrustedDeviceCheckConfig, TrustedDeviceCheckOperationFull, type TrustedDeviceCheckResult, type TrustedDeviceCheckStepResult, type TrustedDeviceCheckTypedError, TrustedDeviceEnrollmentOperationFull, type TrustedDeviceEnrollmentResult, type TrustedDeviceOperationConfig, type TrustedDevicePurpose, type TrustedDeviceStorage, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getSessionId, getTracker, init, loadCachedConfig, logError, logInfo, namespacedKey, parseReliabilityConfig, resetSession, resolveRawErrorLimits, resolveReliabilityConfig, sanitizeAssertionResponse, sanitizeCreationOptions, sanitizeCreationResponse, sanitizeRequestOptions, serializeRawError, setExperiment, setExperiments, setUser, telemetry };
2419
+ export { type AppConfirmationOperationCeremonyTypedError, type AppConfirmationOperationConfig, 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, type EmailLinkOperationConfig, EmailLinkOperationFull, type EmailLinkOperationPostResponseStart, type EmailLinkOperationSendStart, type EmailLinkOperationSpecType, type EmailOTPOperationConfig, type EmailOTPOperationPostResponseStart, type EmailOTPOperationSendOTPStart, type EmailOTPOperationSpecType, EmailOtpOperationFull, type ErrorStepOptions, type Event, type EventBatch, type EventBatchMeta, type EventMeta, EventStore, type EventType, type FlowAutoFinished, type FlowDecided, type FlowFinished, type FlowHandle, type FlowReset, type FlowStarted, type FlowType, type FlushReason, type JavaScriptHighEntropy, type KeyOperationConfig, KeyRegistrationOperationFull, KeySigningOperationFull, LocalStorage, type Logger, type LowEvent, type LowEventFieldRole, type LowEventInitiator, type LowEventInputEffect, type LowEventSourceKind, type MultiFlowReset, type MultiFlowStarted, NamespacedStorage, type NormalizedError, OUTBOX_LOCK_NAME, OUTBOX_STORAGE_KEY, type ObserveSdkConfigSnapshot, 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, type PasskeyLoginOperationConfig, PasskeyLoginOperationFull, type PasskeyLoginPostResponseStart, type PasskeyLoginStartable, type PasskeyLoginSubmitted, type PasskeyOperationEnrollmentExplicitSpecType, type PasskeyOperationLoginExplicitSpecType, type PasswordEnrollmentConfig, PasswordEnrollmentOperationFull, type PasswordEnrollmentTypedError, type PasswordLoginCUICeremonyStart, type PasswordLoginCUIGetOptionsFinished, type PasswordLoginCUIGetOptionsStart, type PasswordLoginCUISpecType, type PasswordLoginCUITypedError, type PasswordLoginConfig, type PasswordLoginExplicitSpecType, 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, RAW_ERROR_BOUNDS, type RawErrorEnvelope, RequestQueue, SDK_NAME, SDK_VERSION, type SdkInfo, type SdkReliabilityConfig, type SdkReliabilityConfigOverrides, type SdkRetryConfig, type SerializeRawErrorOptions, SessionStorage, type SmsOTPOperationConfig, type SmsOTPOperationPostResponseStart, type SmsOTPOperationSpecType, SmsOtpOperationFull, type SocialLoginExchangeCodeFinished, type SocialLoginExchangeCodeStart, type SocialLoginGetRedirectUrlFinished, type SocialLoginGetRedirectUrlStart, type SocialLoginOperationConfig, 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 TrustedDeviceBindingMetadata, type TrustedDeviceCheckConfig, TrustedDeviceCheckOperationFull, type TrustedDeviceCheckResult, type TrustedDeviceCheckStepResult, type TrustedDeviceCheckTypedError, TrustedDeviceEnrollmentOperationFull, type TrustedDeviceEnrollmentResult, type TrustedDeviceOperationConfig, type TrustedDevicePurpose, type TrustedDeviceStorage, type UserReference, cacheConfig, clearExperiment, clearExperiments, createLogger, destroy, getExperiments, getSessionId, getTracker, init, loadCachedConfig, logError, logInfo, namespacedKey, parseReliabilityConfig, resetSession, resolveRawErrorLimits, resolveReliabilityConfig, sanitizeAssertionResponse, sanitizeCreationOptions, sanitizeCreationResponse, sanitizeRequestOptions, serializeRawError, setExperiment, setExperiments, setUser, telemetry };