@corbado/observe 0.16.5 → 0.16.7

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,7 +58,10 @@ type UserReference = {
58
58
  /** Shared UUID used to link sessions across environments. */
59
59
  crossEnvironmentTransactionID?: string;
60
60
  };
61
- /** A stable reference to all flows opened by one flow_started event. */
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
+ */
62
65
  interface FlowHandle {
63
66
  /** Attach identity to this journey, including after it finishes or the tracker session changes.
64
67
  * Resolves when tracking/enqueue completes, not when server delivery is acknowledged.
@@ -262,6 +265,14 @@ interface EventBatchMeta {
262
265
  * changes propagate with page-load lag, so calendar-date cohorts are mixed).
263
266
  */
264
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;
265
276
  }
266
277
  interface EventMeta {
267
278
  initiator?: LowEventInitiator;
@@ -449,9 +460,24 @@ interface SdkReliabilityConfig {
449
460
  * instruments.
450
461
  */
451
462
  aap: string;
463
+ /**
464
+ * Which query values `meta.trackingSourcePath` carries. `"allowlist"` (default) keeps every query
465
+ * key and its position but replaces each value with `*` unless its key matches
466
+ * {@link SdkReliabilityConfig.sourcePathQueryAllow} (empty by default); empty values and keys
467
+ * without a value stay as they are. `"all"` reports the page URL's query unchanged. The path itself
468
+ * is never changed. Applies to events tracked after the config takes effect.
469
+ */
470
+ sourcePathQuery: SourcePathQueryMode;
471
+ /**
472
+ * Query keys whose values are kept in `"allowlist"` mode. Matched case-insensitively and exactly;
473
+ * a trailing `*` matches a key prefix (`utm_*`). Capped at 50 entries of up to 64 characters.
474
+ */
475
+ sourcePathQueryAllow: string[];
452
476
  /** Retry configuration for failed event flushes. */
453
477
  retry: SdkRetryConfig;
454
478
  }
479
+ /** Query handling for `meta.trackingSourcePath`; see {@link SdkReliabilityConfig.sourcePathQuery}. */
480
+ type SourcePathQueryMode = "all" | "allowlist";
455
481
  /** Optional init overrides; omitted fields (including nested retry fields) inherit server policy or defaults. */
456
482
  type SdkReliabilityConfigOverrides = Partial<Omit<SdkReliabilityConfig, "retry">> & {
457
483
  retry?: Partial<SdkRetryConfig>;
@@ -1227,6 +1253,12 @@ interface TrackerOptions {
1227
1253
  * assignments and then attached to every event the tracker produces (see {@link CorbadoTracker.setExperiment}).
1228
1254
  */
1229
1255
  experiments?: Record<string, string>;
1256
+ /**
1257
+ * Data policy code to seed at init: a project-scoped non-negative integer (0..255) selecting a
1258
+ * policy configured in Corbado (0 is the project default). Overlays any persisted code and is then
1259
+ * sent as `meta.dataPolicy` on every batch (see {@link CorbadoTracker.setDataPolicy}).
1260
+ */
1261
+ dataPolicy?: number;
1230
1262
  applicationId?: string;
1231
1263
  /**
1232
1264
  * @deprecated The flush interval is server-controlled via the SDK reliability config
@@ -1267,6 +1299,11 @@ declare class CorbadoTracker {
1267
1299
  private lastActivityWriteAt;
1268
1300
  /** Persistent experiment assignments (experiment key → variant), attached to every produced event. */
1269
1301
  private experiments;
1302
+ /**
1303
+ * Persistent data policy code, stamped into every batch's `meta.dataPolicy` once set. Never
1304
+ * cleared (only overwritten): it survives reloads, session rotation, resetSession and destroy.
1305
+ */
1306
+ private dataPolicy?;
1270
1307
  /** Self-instrumentation state: re-entrancy guard, readiness, per-load dedupe, and pre-queue buffer. */
1271
1308
  private telemetryReporting;
1272
1309
  private telemetryReady;
@@ -1315,6 +1352,23 @@ declare class CorbadoTracker {
1315
1352
  * @returns A frozen snapshot, created fresh on every call.
1316
1353
  */
1317
1354
  getSdkConfig(): ObserveSdkConfigSnapshot;
1355
+ /**
1356
+ * Set the data policy code for this tracker (e.g. `setDataPolicy(1)` once the user agreed to
1357
+ * extended processing; `setDataPolicy(0)` to return to the project default). Codes are
1358
+ * project-scoped non-negative integers (0..255) selecting a policy configured in Corbado; they
1359
+ * carry no ordering.
1360
+ *
1361
+ * The code is persisted (localStorage, project-scoped) and sent as `meta.dataPolicy` on every
1362
+ * subsequent batch, across reloads and session rotation. It is never cleared, only overwritten.
1363
+ * The server records the latest code it receives for a session (last write wins). Invalid codes
1364
+ * are ignored with a debug log; never throws.
1365
+ */
1366
+ setDataPolicy(code: number): void;
1367
+ /** Returns the current data policy code, or undefined when none has ever been set. */
1368
+ getDataPolicy(): number | undefined;
1369
+ private static isValidDataPolicy;
1370
+ private loadPersistedDataPolicy;
1371
+ private persistDataPolicy;
1318
1372
  private static isValidExperimentKey;
1319
1373
  private static isValidExperimentVariant;
1320
1374
  private loadPersistedExperiments;
@@ -1427,7 +1481,7 @@ declare class CorbadoTracker {
1427
1481
  * (such as login vs signup), pass `flowNames` and optionally `defaultFlowName`.
1428
1482
  *
1429
1483
  * The returned handle can attach identity after completion with `await flow.enrich({ userId })`.
1430
- * Enrichment requires a backend supporting explicit start-event targeting.
1484
+ * Enrichment requires a backend supporting explicit event targeting.
1431
1485
  *
1432
1486
  * @param data - Flow metadata, including one flow (`flowName`) or multiple candidates (`flowNames`).
1433
1487
  * @param tags - Optional key-value tags for filtering and segmentation.
@@ -1491,7 +1545,12 @@ declare class CorbadoTracker {
1491
1545
  * @remarks
1492
1546
  * Fire this when the user has finished the target flow end-to-end, such as completed login,
1493
1547
  * signup, or recovery. Record identity with `setUser()` while the flow is active,
1494
- * or use the handle returned by `flowStarted()` to enrich it after completion.
1548
+ * or enrich it after completion through the handle returned by `flowStarted()` or by this call.
1549
+ *
1550
+ * The returned handle targets the flow this event finished, so identity learned only after
1551
+ * completion — for example from a profile request that follows account creation — can be
1552
+ * attached with `await finished.enrich({ userId })` even on a page that never saw the flow start.
1553
+ * Enrichment requires a backend supporting explicit flow-event targeting.
1495
1554
  *
1496
1555
  * Legacy identity fields in `data` remain supported but are deprecated.
1497
1556
  *
@@ -1500,12 +1559,14 @@ declare class CorbadoTracker {
1500
1559
  *
1501
1560
  * @example
1502
1561
  * ```typescript
1503
- * tracker.flowFinished({
1504
- * flowName: "login",
1505
- * });
1562
+ * const finished = tracker.flowFinished({ flowName: "signup" });
1563
+ * const userId = await hashUserId(createdAccountId);
1564
+ * await finished.enrich({ userId });
1506
1565
  * ```
1507
1566
  */
1508
- flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): void;
1567
+ flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): FlowHandle;
1568
+ /** Emits `flow_enriched` against an explicit target, in the session that emitted the target. */
1569
+ private flowHandle;
1509
1570
  /**
1510
1571
  * Track when an in-progress flow is reset and restarted.
1511
1572
  *
@@ -1951,6 +2012,11 @@ interface QueueOptions {
1951
2012
  * {@link EventStore}). Defaults to the shared {@link OUTBOX_LOCK_NAME}.
1952
2013
  */
1953
2014
  outboxLockName?: string;
2015
+ /**
2016
+ * Returns the data policy code to stamp into `meta.dataPolicy` of every batch, or undefined when
2017
+ * none has ever been set. Read at send time so a change applies to the next batch without a flush.
2018
+ */
2019
+ getDataPolicy?: () => number | undefined;
1954
2020
  }
1955
2021
  /**
1956
2022
  * @remarks When `window` is defined, `visibilitychange` (when the document becomes hidden) and `pagehide`
@@ -2004,6 +2070,7 @@ declare class RequestQueue {
2004
2070
  private readonly debug;
2005
2071
  private readonly requestConfig;
2006
2072
  private readonly onConfigReceived?;
2073
+ private readonly getDataPolicy?;
2007
2074
  /** Current delivery policy, including live updates. */
2008
2075
  private config;
2009
2076
  /**
@@ -2074,10 +2141,13 @@ declare class RequestQueue {
2074
2141
  * Stamps delivery metadata onto the batch: the trigger that caused this flush, the config version
2075
2142
  * this load runs under (omitted on built-in defaults) and the number of prior failed delivery
2076
2143
  * attempts (the max across its entries, only when at least one entry is a retry). `entry.attempts`
2077
- * is incremented on each failed flush, so it equals the retry count at send time. The transport
2078
- * later merges in `sent`/`transport`.
2144
+ * is incremented on each failed flush, so it equals the retry count at send time. The data policy
2145
+ * code (when one has ever been set) is read live, so it reflects the tracker state at send time.
2146
+ * The transport later merges in `sent`/`transport`.
2079
2147
  */
2080
2148
  private attachBatchMeta;
2149
+ /** The data policy code from the tracker, or undefined; a throwing getter must never break a flush. */
2150
+ private readDataPolicy;
2081
2151
  private getDuePending;
2082
2152
  private takeLows;
2083
2153
  private validPendingLow;
@@ -2187,6 +2257,10 @@ declare const CONFIG_BOUNDS: {
2187
2257
  readonly maxEntries: 20;
2188
2258
  readonly maxNameLength: 100;
2189
2259
  };
2260
+ readonly sourcePathQueryAllow: {
2261
+ readonly maxEntries: 50;
2262
+ readonly maxKeyLength: 64;
2263
+ };
2190
2264
  };
2191
2265
  /** Built-in continuity-session inactivity threshold (30 minutes); matches the historical default. */
2192
2266
  declare const DEFAULT_SESSION_INACTIVITY_MS: number;
@@ -2361,4 +2435,4 @@ declare function logInfo(message: string): void;
2361
2435
  declare function logError(message: string): void;
2362
2436
  declare function destroy(): Promise<void>;
2363
2437
 
2364
- 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 };
2438
+ 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 SourcePathQueryMode, 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,7 +58,10 @@ type UserReference = {
58
58
  /** Shared UUID used to link sessions across environments. */
59
59
  crossEnvironmentTransactionID?: string;
60
60
  };
61
- /** A stable reference to all flows opened by one flow_started event. */
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
+ */
62
65
  interface FlowHandle {
63
66
  /** Attach identity to this journey, including after it finishes or the tracker session changes.
64
67
  * Resolves when tracking/enqueue completes, not when server delivery is acknowledged.
@@ -262,6 +265,14 @@ interface EventBatchMeta {
262
265
  * changes propagate with page-load lag, so calendar-date cohorts are mixed).
263
266
  */
264
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;
265
276
  }
266
277
  interface EventMeta {
267
278
  initiator?: LowEventInitiator;
@@ -449,9 +460,24 @@ interface SdkReliabilityConfig {
449
460
  * instruments.
450
461
  */
451
462
  aap: string;
463
+ /**
464
+ * Which query values `meta.trackingSourcePath` carries. `"allowlist"` (default) keeps every query
465
+ * key and its position but replaces each value with `*` unless its key matches
466
+ * {@link SdkReliabilityConfig.sourcePathQueryAllow} (empty by default); empty values and keys
467
+ * without a value stay as they are. `"all"` reports the page URL's query unchanged. The path itself
468
+ * is never changed. Applies to events tracked after the config takes effect.
469
+ */
470
+ sourcePathQuery: SourcePathQueryMode;
471
+ /**
472
+ * Query keys whose values are kept in `"allowlist"` mode. Matched case-insensitively and exactly;
473
+ * a trailing `*` matches a key prefix (`utm_*`). Capped at 50 entries of up to 64 characters.
474
+ */
475
+ sourcePathQueryAllow: string[];
452
476
  /** Retry configuration for failed event flushes. */
453
477
  retry: SdkRetryConfig;
454
478
  }
479
+ /** Query handling for `meta.trackingSourcePath`; see {@link SdkReliabilityConfig.sourcePathQuery}. */
480
+ type SourcePathQueryMode = "all" | "allowlist";
455
481
  /** Optional init overrides; omitted fields (including nested retry fields) inherit server policy or defaults. */
456
482
  type SdkReliabilityConfigOverrides = Partial<Omit<SdkReliabilityConfig, "retry">> & {
457
483
  retry?: Partial<SdkRetryConfig>;
@@ -1227,6 +1253,12 @@ interface TrackerOptions {
1227
1253
  * assignments and then attached to every event the tracker produces (see {@link CorbadoTracker.setExperiment}).
1228
1254
  */
1229
1255
  experiments?: Record<string, string>;
1256
+ /**
1257
+ * Data policy code to seed at init: a project-scoped non-negative integer (0..255) selecting a
1258
+ * policy configured in Corbado (0 is the project default). Overlays any persisted code and is then
1259
+ * sent as `meta.dataPolicy` on every batch (see {@link CorbadoTracker.setDataPolicy}).
1260
+ */
1261
+ dataPolicy?: number;
1230
1262
  applicationId?: string;
1231
1263
  /**
1232
1264
  * @deprecated The flush interval is server-controlled via the SDK reliability config
@@ -1267,6 +1299,11 @@ declare class CorbadoTracker {
1267
1299
  private lastActivityWriteAt;
1268
1300
  /** Persistent experiment assignments (experiment key → variant), attached to every produced event. */
1269
1301
  private experiments;
1302
+ /**
1303
+ * Persistent data policy code, stamped into every batch's `meta.dataPolicy` once set. Never
1304
+ * cleared (only overwritten): it survives reloads, session rotation, resetSession and destroy.
1305
+ */
1306
+ private dataPolicy?;
1270
1307
  /** Self-instrumentation state: re-entrancy guard, readiness, per-load dedupe, and pre-queue buffer. */
1271
1308
  private telemetryReporting;
1272
1309
  private telemetryReady;
@@ -1315,6 +1352,23 @@ declare class CorbadoTracker {
1315
1352
  * @returns A frozen snapshot, created fresh on every call.
1316
1353
  */
1317
1354
  getSdkConfig(): ObserveSdkConfigSnapshot;
1355
+ /**
1356
+ * Set the data policy code for this tracker (e.g. `setDataPolicy(1)` once the user agreed to
1357
+ * extended processing; `setDataPolicy(0)` to return to the project default). Codes are
1358
+ * project-scoped non-negative integers (0..255) selecting a policy configured in Corbado; they
1359
+ * carry no ordering.
1360
+ *
1361
+ * The code is persisted (localStorage, project-scoped) and sent as `meta.dataPolicy` on every
1362
+ * subsequent batch, across reloads and session rotation. It is never cleared, only overwritten.
1363
+ * The server records the latest code it receives for a session (last write wins). Invalid codes
1364
+ * are ignored with a debug log; never throws.
1365
+ */
1366
+ setDataPolicy(code: number): void;
1367
+ /** Returns the current data policy code, or undefined when none has ever been set. */
1368
+ getDataPolicy(): number | undefined;
1369
+ private static isValidDataPolicy;
1370
+ private loadPersistedDataPolicy;
1371
+ private persistDataPolicy;
1318
1372
  private static isValidExperimentKey;
1319
1373
  private static isValidExperimentVariant;
1320
1374
  private loadPersistedExperiments;
@@ -1427,7 +1481,7 @@ declare class CorbadoTracker {
1427
1481
  * (such as login vs signup), pass `flowNames` and optionally `defaultFlowName`.
1428
1482
  *
1429
1483
  * The returned handle can attach identity after completion with `await flow.enrich({ userId })`.
1430
- * Enrichment requires a backend supporting explicit start-event targeting.
1484
+ * Enrichment requires a backend supporting explicit event targeting.
1431
1485
  *
1432
1486
  * @param data - Flow metadata, including one flow (`flowName`) or multiple candidates (`flowNames`).
1433
1487
  * @param tags - Optional key-value tags for filtering and segmentation.
@@ -1491,7 +1545,12 @@ declare class CorbadoTracker {
1491
1545
  * @remarks
1492
1546
  * Fire this when the user has finished the target flow end-to-end, such as completed login,
1493
1547
  * signup, or recovery. Record identity with `setUser()` while the flow is active,
1494
- * or use the handle returned by `flowStarted()` to enrich it after completion.
1548
+ * or enrich it after completion through the handle returned by `flowStarted()` or by this call.
1549
+ *
1550
+ * The returned handle targets the flow this event finished, so identity learned only after
1551
+ * completion — for example from a profile request that follows account creation — can be
1552
+ * attached with `await finished.enrich({ userId })` even on a page that never saw the flow start.
1553
+ * Enrichment requires a backend supporting explicit flow-event targeting.
1495
1554
  *
1496
1555
  * Legacy identity fields in `data` remain supported but are deprecated.
1497
1556
  *
@@ -1500,12 +1559,14 @@ declare class CorbadoTracker {
1500
1559
  *
1501
1560
  * @example
1502
1561
  * ```typescript
1503
- * tracker.flowFinished({
1504
- * flowName: "login",
1505
- * });
1562
+ * const finished = tracker.flowFinished({ flowName: "signup" });
1563
+ * const userId = await hashUserId(createdAccountId);
1564
+ * await finished.enrich({ userId });
1506
1565
  * ```
1507
1566
  */
1508
- flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): void;
1567
+ flowFinished(data: FlowFinished, tags?: Record<string, string>, experiments?: Record<string, string>): FlowHandle;
1568
+ /** Emits `flow_enriched` against an explicit target, in the session that emitted the target. */
1569
+ private flowHandle;
1509
1570
  /**
1510
1571
  * Track when an in-progress flow is reset and restarted.
1511
1572
  *
@@ -1951,6 +2012,11 @@ interface QueueOptions {
1951
2012
  * {@link EventStore}). Defaults to the shared {@link OUTBOX_LOCK_NAME}.
1952
2013
  */
1953
2014
  outboxLockName?: string;
2015
+ /**
2016
+ * Returns the data policy code to stamp into `meta.dataPolicy` of every batch, or undefined when
2017
+ * none has ever been set. Read at send time so a change applies to the next batch without a flush.
2018
+ */
2019
+ getDataPolicy?: () => number | undefined;
1954
2020
  }
1955
2021
  /**
1956
2022
  * @remarks When `window` is defined, `visibilitychange` (when the document becomes hidden) and `pagehide`
@@ -2004,6 +2070,7 @@ declare class RequestQueue {
2004
2070
  private readonly debug;
2005
2071
  private readonly requestConfig;
2006
2072
  private readonly onConfigReceived?;
2073
+ private readonly getDataPolicy?;
2007
2074
  /** Current delivery policy, including live updates. */
2008
2075
  private config;
2009
2076
  /**
@@ -2074,10 +2141,13 @@ declare class RequestQueue {
2074
2141
  * Stamps delivery metadata onto the batch: the trigger that caused this flush, the config version
2075
2142
  * this load runs under (omitted on built-in defaults) and the number of prior failed delivery
2076
2143
  * attempts (the max across its entries, only when at least one entry is a retry). `entry.attempts`
2077
- * is incremented on each failed flush, so it equals the retry count at send time. The transport
2078
- * later merges in `sent`/`transport`.
2144
+ * is incremented on each failed flush, so it equals the retry count at send time. The data policy
2145
+ * code (when one has ever been set) is read live, so it reflects the tracker state at send time.
2146
+ * The transport later merges in `sent`/`transport`.
2079
2147
  */
2080
2148
  private attachBatchMeta;
2149
+ /** The data policy code from the tracker, or undefined; a throwing getter must never break a flush. */
2150
+ private readDataPolicy;
2081
2151
  private getDuePending;
2082
2152
  private takeLows;
2083
2153
  private validPendingLow;
@@ -2187,6 +2257,10 @@ declare const CONFIG_BOUNDS: {
2187
2257
  readonly maxEntries: 20;
2188
2258
  readonly maxNameLength: 100;
2189
2259
  };
2260
+ readonly sourcePathQueryAllow: {
2261
+ readonly maxEntries: 50;
2262
+ readonly maxKeyLength: 64;
2263
+ };
2190
2264
  };
2191
2265
  /** Built-in continuity-session inactivity threshold (30 minutes); matches the historical default. */
2192
2266
  declare const DEFAULT_SESSION_INACTIVITY_MS: number;
@@ -2361,4 +2435,4 @@ declare function logInfo(message: string): void;
2361
2435
  declare function logError(message: string): void;
2362
2436
  declare function destroy(): Promise<void>;
2363
2437
 
2364
- 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 };
2438
+ 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 SourcePathQueryMode, 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 };