@cross-deck/node 1.3.1 → 1.5.1

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.
@@ -111,6 +111,110 @@ declare class CrossdeckConfigurationError extends CrossdeckError {
111
111
  */
112
112
  declare function makeCrossdeckError(payload: CrossdeckErrorPayload): CrossdeckError;
113
113
 
114
+ /**
115
+ * Public, typed accessor for the bank-grade behavioural contracts
116
+ * this SDK ships. The full architecture — schema, distribution,
117
+ * audit loop, pillar taxonomy — lives in `contracts/README.md`
118
+ * at the monorepo root.
119
+ *
120
+ * Why a typed surface (vs. plain JSON access): contract IDs and
121
+ * pillar names are part of Crossdeck's public commitment to
122
+ * customers. Reading them through `CrossdeckContracts` means the
123
+ * compiler catches drift the moment a contract is renamed or
124
+ * retired. Tools that consume contracts at runtime (dashboards,
125
+ * AI assistants, customer integration tests) get the exact same
126
+ * shape every SDK ships, with no parsing layer to drift.
127
+ *
128
+ * --- BINARY STABILITY ---
129
+ * `Contract` is treated as an evolving — but back-compat — wire
130
+ * shape. Fields may be added in any minor release. Existing
131
+ * fields will not be removed or repurposed except in a major
132
+ * version bump, even if all known contracts stop using them.
133
+ * Customers can rely on `id`, `pillar`, `status`, `appliesTo`,
134
+ * `codeRef`, `testRef`, `registeredAt`, `firstRegisteredIn`,
135
+ * and `bundledIn` being present on every contract in every
136
+ * future minor/patch release of this SDK.
137
+ */
138
+ type ContractPillar = "revenue" | "entitlements" | "analytics" | "webhooks" | "errors" | "lifecycle" | "identity";
139
+ type ContractStatus = "enforced" | "proposed" | "retired";
140
+ type ContractAppliesTo = "web" | "node" | "react-native" | "swift" | "android" | "backend";
141
+ interface ContractTestRef {
142
+ readonly file: string;
143
+ readonly name: string;
144
+ }
145
+ interface Contract {
146
+ readonly id: string;
147
+ readonly pillar: ContractPillar;
148
+ readonly status: ContractStatus;
149
+ readonly claim: string;
150
+ readonly appliesTo: readonly ContractAppliesTo[];
151
+ readonly codeRef: readonly string[];
152
+ readonly testRef: readonly ContractTestRef[];
153
+ readonly registeredAt: string;
154
+ readonly firstRegisteredIn: string;
155
+ readonly bundledIn: string;
156
+ }
157
+ /**
158
+ * Typed entry point to the bank-grade contracts bundled with this
159
+ * SDK release. Stable, side-effect-free, tree-shakeable.
160
+ *
161
+ * @example Audit at app boot
162
+ * ```ts
163
+ * import { CrossdeckContracts } from "@cross-deck/node";
164
+ *
165
+ * for (const c of CrossdeckContracts.all()) {
166
+ * console.log(`[crossdeck] ${c.id} (${c.pillar})`);
167
+ * }
168
+ * ```
169
+ */
170
+ declare const CrossdeckContracts: {
171
+ readonly all: () => readonly Contract[];
172
+ readonly allIncludingHistorical: () => readonly Contract[];
173
+ readonly byId: (id: string) => Contract | undefined;
174
+ readonly byPillar: (pillar: ContractPillar) => readonly Contract[];
175
+ readonly withStatus: (status: ContractStatus) => readonly Contract[];
176
+ readonly sdkVersion: "1.5.1";
177
+ readonly bundledIn: "@cross-deck/node@1.5.1";
178
+ /**
179
+ * Resolve a failing test back to the contract it exercises.
180
+ * Used by test-framework hooks to find the contract id of a
181
+ * failed contract test so `reportContractFailure(...)` can stamp
182
+ * the right `contract_id` on the emitted event.
183
+ */
184
+ readonly findByTestName: (name: string) => Contract | undefined;
185
+ };
186
+ /**
187
+ * Input to {@link CrossdeckServer.reportContractFailure}. Mirrors
188
+ * the per-SDK shape exactly.
189
+ *
190
+ * SCHEMA-LOCK: this interface's field set is exhaustively named. No
191
+ * free-form `extra: Record<string, unknown>` — the schema-lock
192
+ * contract at
193
+ * `contracts/diagnostics/contract-failed-payload-schema-lock.json`
194
+ * forbids unbounded fields. Adding a field requires a PR that
195
+ * amends the contract first, then the public interface.
196
+ */
197
+ interface ContractFailureInput {
198
+ contractId: string;
199
+ /**
200
+ * Short categorical-ish label — the SDK convention is to keep
201
+ * this under 128 chars and stable across runs (so dashboards can
202
+ * group). Never an end-user-supplied string.
203
+ */
204
+ failureReason: string;
205
+ runContext: "ci" | "dogfood" | "customer-app";
206
+ runId: string;
207
+ testRef?: {
208
+ file: string;
209
+ name: string;
210
+ };
211
+ /**
212
+ * Optional coarse device class, e.g. "linux-server", "container",
213
+ * "lambda". A categorical bucket, not a host identifier.
214
+ */
215
+ deviceClass?: string;
216
+ }
217
+
114
218
  /**
115
219
  * Breadcrumb ring buffer — context attached to every error report.
116
220
  *
@@ -409,6 +513,10 @@ interface PurchaseResult {
409
513
  crossdeckCustomerId: string;
410
514
  env: Environment;
411
515
  entitlements: PublicEntitlement[];
516
+ /** True when the response came from the backend's idempotency
517
+ * cache instead of fresh processing. Backend also returns
518
+ * `Idempotent-Replayed: true` as a response header (v1.4.0). */
519
+ idempotent_replay?: boolean;
412
520
  }
413
521
  /**
414
522
  * Response shape from `GET /v1/sdk/heartbeat`. Used by
@@ -462,6 +570,25 @@ interface CrossdeckServerOptions {
462
570
  * not the source of truth.
463
571
  */
464
572
  appId?: string;
573
+ /**
574
+ * Apply Crossdeck's PII scrubber to every `track()` payload before
575
+ * enqueue. Default `true` (parity with Web / RN / Swift SDKs — Node
576
+ * pre-v1.4.0 was the odd one out and SHIPPED EMAILS UNREDACTED, a
577
+ * privacy contract drift versus the README claim).
578
+ *
579
+ * The scrubber rewrites email-shaped and card-number-shaped
580
+ * substrings to `<email>` / `<card>` sentinels recursively across
581
+ * nested maps + arrays. See `scrubPii` / `scrubPiiFromProperties`.
582
+ *
583
+ * **Blast radius of setting `false`:** every `track()` payload —
584
+ * including event names with embedded emails ("user wes@example.com
585
+ * upgraded"), trait values, group memberships, error context blobs
586
+ * — ships verbatim to Crossdeck and downstream warehouses /
587
+ * analytics exports. Disable only for explicit compliance use
588
+ * cases (regulator-required audit trails where the raw value MUST
589
+ * be preserved) and document the decision at the call site.
590
+ */
591
+ scrubPii?: boolean;
465
592
  /**
466
593
  * Error capture configuration. Default: ON with `onUncaughtException` +
467
594
  * `onUnhandledRejection` + `wrapFetch` all enabled.
@@ -672,6 +799,14 @@ interface RequestOptions {
672
799
  * `timeoutMs`. Pass `0` to disable.
673
800
  */
674
801
  timeoutMs?: number;
802
+ /**
803
+ * Override the deterministic Idempotency-Key derivation (v1.4.0).
804
+ * The SDK derives a stable key from the request body so retries
805
+ * collapse on the backend. Override only when an outer
806
+ * orchestrator (job runner, retry harness) needs a different
807
+ * idempotency window — and document why at the call site.
808
+ */
809
+ idempotencyKey?: string;
675
810
  }
676
811
  interface IdentityHints {
677
812
  customerId?: string;
@@ -1162,6 +1297,10 @@ declare class CrossdeckServer extends EventEmitter {
1162
1297
  private readonly baseUrl;
1163
1298
  private readonly appId;
1164
1299
  private readonly env;
1300
+ /** PII scrubber toggle. Default true — parity with Web/RN/Swift.
1301
+ * Pre-v1.4.0 the Node SDK shipped track() payloads UNREDACTED,
1302
+ * a privacy contract drift versus the README. */
1303
+ private readonly scrubPii;
1165
1304
  private readonly secretKeyPrefix;
1166
1305
  /**
1167
1306
  * Process-stable pseudo-anonymous ID. Used as the default identity
@@ -1207,6 +1346,15 @@ declare class CrossdeckServer extends EventEmitter {
1207
1346
  private errorContext;
1208
1347
  private errorTags;
1209
1348
  private errorBeforeSend;
1349
+ /**
1350
+ * Dedup gate for `sdk.shutdown`. Both `shutdown()` (async) and
1351
+ * `shutdownSync()` need to emit so direct callers of EITHER see
1352
+ * the event (the async path's listener guarantees pre-launch
1353
+ * tests, the sync path covers `Symbol.dispose` + tests that call
1354
+ * `shutdownSync()` directly). Without this flag, `shutdown()`'s
1355
+ * tail call into `shutdownSync()` would emit twice.
1356
+ */
1357
+ private didEmitShutdown;
1210
1358
  constructor(options: CrossdeckServerOptions);
1211
1359
  /**
1212
1360
  * Emit the honest "no cold-start durability" warning when the runtime
@@ -1331,6 +1479,17 @@ declare class CrossdeckServer extends EventEmitter {
1331
1479
  * `uncaughtException` has no per-request context; without the
1332
1480
  * auto-fill, the event would be rejected at queue enqueue.
1333
1481
  */
1482
+ /**
1483
+ * Emit `crossdeck.contract_failed` to the Crossdeck reliability
1484
+ * endpoint — single-fire, one-way, never visible in the customer's
1485
+ * dashboard. Goes over a dedicated HTTP path with the reliability
1486
+ * publishable key embedded at build time; the customer's track()
1487
+ * pipeline never carries `crossdeck.*` events. This is the
1488
+ * independent-controller flow described in Privacy Policy §6
1489
+ * ("Flow B"). The wire shape is fixed by the schema-lock contract
1490
+ * at `contracts/diagnostics/contract-failed-payload-schema-lock.json`.
1491
+ */
1492
+ reportContractFailure(input: ContractFailureInput): void;
1334
1493
  track(event: ServerEvent): void;
1335
1494
  /**
1336
1495
  * Immediate POST of one or more events. For bulk imports / replay
@@ -1541,11 +1700,36 @@ declare class CrossdeckServer extends EventEmitter {
1541
1700
  getGroups(): Record<string, GroupMembership>;
1542
1701
  diagnostics(): Diagnostics;
1543
1702
  /**
1544
- * Tear down handlers and clear in-memory state. Tests + custom
1545
- * lifecycle callers only. Production code should rely on
1546
- * `flush-on-exit` instead.
1703
+ * Tear down handlers and clear in-memory state.
1704
+ *
1705
+ * **v1.4.0 bank-grade contract:** `shutdown()` AWAITS `flush()`
1706
+ * before dropping the queue, so callers don't silently lose
1707
+ * every queued event on a clean shutdown. The pre-v1.4.0
1708
+ * behaviour (sync `eventQueue.reset()` with no flush) was the
1709
+ * default for both `shutdown()` and `[Symbol.dispose]`; only
1710
+ * `await using` + `[Symbol.asyncDispose]` flushed correctly.
1711
+ *
1712
+ * Production servers should still prefer `await server.flush()`
1713
+ * (visible) followed by `server.shutdown()` so the flush
1714
+ * outcome is observable — `shutdown()`'s internal flush swallows
1715
+ * errors as a best-effort drain.
1716
+ *
1717
+ * Use [[shutdownSync]] only when the runtime cannot await
1718
+ * (e.g. inside `Symbol.dispose` — see below).
1719
+ */
1720
+ shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): Promise<void>;
1721
+ /**
1722
+ * Synchronous teardown — drops the in-memory queue WITHOUT
1723
+ * flushing, then clears all in-memory state. Used by
1724
+ * `[Symbol.dispose]` (which has no await) and tests that need
1725
+ * an unconditional sync wipe. Production code should use
1726
+ * [[shutdown]] (async) instead so queued events are flushed.
1727
+ *
1728
+ * A queue with items at sync-shutdown logs a warning recommending
1729
+ * `[Symbol.asyncDispose]` or `await server.shutdown()` — silent
1730
+ * loss is incompatible with the bank-grade contract.
1547
1731
  */
1548
- shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1732
+ shutdownSync(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1549
1733
  /**
1550
1734
  * Convert a `CapturedError` into a `ServerEvent` and push through
1551
1735
  * `track()`. Goes through the same queue / enrichment / breadcrumb
@@ -1614,17 +1798,21 @@ declare class CrossdeckServer extends EventEmitter {
1614
1798
  * // ... use server ...
1615
1799
  * // at end of block, server[Symbol.dispose]() runs automatically
1616
1800
  *
1617
- * `Symbol.dispose` is synchronous so we can't await `flush()` here
1618
- * for that, use `await using` + `[Symbol.asyncDispose]()`. This
1619
- * sync variant just calls `shutdown()` (handler cleanup +
1620
- * in-memory state wipe).
1801
+ * **`Symbol.dispose` is synchronous so it CANNOT await the queue
1802
+ * flush.** A queue with pending events at sync-dispose time will
1803
+ * be DROPPED `shutdownSync` warns to the console when this
1804
+ * happens. For the common case of "drain the queue before
1805
+ * exit", switch to `await using` + `[Symbol.asyncDispose]` (or
1806
+ * call `await server.shutdown()` explicitly before the variable
1807
+ * goes out of scope).
1621
1808
  */
1622
1809
  [Symbol.dispose](): void;
1623
1810
  /**
1624
1811
  * Async disposal hook — runs when an `await using` declaration
1625
- * exits scope. Awaits `flush()` THEN runs `shutdown()`. Use this
1626
- * variant when the caller needs the queue drained before exit
1627
- * (the common case for serverless handlers).
1812
+ * exits scope. Awaits the bank-grade `shutdown()` which flushes
1813
+ * the queue THEN tears down. Use this variant for any code path
1814
+ * that owns queued events at exit (serverless handlers,
1815
+ * background workers, end-of-request hooks).
1628
1816
  *
1629
1817
  * await using server = new CrossdeckServer({ ... });
1630
1818
  */
@@ -1710,4 +1898,4 @@ declare class CrossdeckServer extends EventEmitter {
1710
1898
  private normalizeIngestEvent;
1711
1899
  }
1712
1900
 
1713
- export { type StoredEntitlements as $, type AliasIdentityInput as A, type Breadcrumb as B, CROSSDECK_API_VERSION as C, DEFAULT_BASE_URL as D, type EntitlementCacheOptions as E, type ErrorLevel as F, type EventProperties as G, type ForgetResult as H, type GrantDuration as I, type GrantEntitlementInput as J, type GroupMembership as K, type HeartbeatResponse as L, type HttpRequestInfo as M, type HttpResponseInfo as N, type HttpRetriesConfig as O, type IdentifyOptions as P, type IdentityHints as Q, type IngestOptions as R, type IngestResponse as S, type PublicEntitlement as T, type PurchaseResult as U, type RequestOptions as V, type RevokeEntitlementInput as W, type RuntimeHost as X, type RuntimeInfo as Y, type ServerEvent as Z, type StackFrame as _, type AliasResult as a, type SyncPurchaseInput as a0, makeCrossdeckError as a1, type AuditDecision as b, type AuditEntry as c, type BreadcrumbCategory as d, type BreadcrumbLevel as e, type CapturedError as f, CrossdeckAuthenticationError as g, CrossdeckConfigurationError as h, CrossdeckError as i, type CrossdeckErrorPayload as j, type CrossdeckErrorType as k, CrossdeckInternalError as l, CrossdeckNetworkError as m, CrossdeckPermissionError as n, CrossdeckRateLimitError as o, CrossdeckServer as p, type CrossdeckServerOptions as q, CrossdeckValidationError as r, DEFAULT_TIMEOUT_MS as s, type Diagnostics as t, type EntitlementMutationResult as u, type EntitlementStore as v, type EntitlementsListResponse as w, type EntitlementsListener as x, type Environment as y, type ErrorCaptureConfig as z };
1901
+ export { type PurchaseResult as $, type AliasIdentityInput as A, type Breadcrumb as B, CROSSDECK_API_VERSION as C, DEFAULT_BASE_URL as D, type Diagnostics as E, type EntitlementCacheOptions as F, type EntitlementMutationResult as G, type EntitlementStore as H, type EntitlementsListResponse as I, type EntitlementsListener as J, type Environment as K, type ErrorCaptureConfig as L, type ErrorLevel as M, type EventProperties as N, type ForgetResult as O, type GrantDuration as P, type GrantEntitlementInput as Q, type GroupMembership as R, type HeartbeatResponse as S, type HttpRequestInfo as T, type HttpResponseInfo as U, type HttpRetriesConfig as V, type IdentifyOptions as W, type IdentityHints as X, type IngestOptions as Y, type IngestResponse as Z, type PublicEntitlement as _, type AliasResult as a, type RequestOptions as a0, type RevokeEntitlementInput as a1, type RuntimeHost as a2, type RuntimeInfo as a3, type ServerEvent as a4, type StackFrame as a5, type StoredEntitlements as a6, type SyncPurchaseInput as a7, makeCrossdeckError as a8, type AuditDecision as b, type AuditEntry as c, type BreadcrumbCategory as d, type BreadcrumbLevel as e, type CapturedError as f, type Contract as g, type ContractAppliesTo as h, type ContractFailureInput as i, type ContractPillar as j, type ContractStatus as k, type ContractTestRef as l, CrossdeckAuthenticationError as m, CrossdeckConfigurationError as n, CrossdeckContracts as o, CrossdeckError as p, type CrossdeckErrorPayload as q, type CrossdeckErrorType as r, CrossdeckInternalError as s, CrossdeckNetworkError as t, CrossdeckPermissionError as u, CrossdeckRateLimitError as v, CrossdeckServer as w, type CrossdeckServerOptions as x, CrossdeckValidationError as y, DEFAULT_TIMEOUT_MS as z };
@@ -111,6 +111,110 @@ declare class CrossdeckConfigurationError extends CrossdeckError {
111
111
  */
112
112
  declare function makeCrossdeckError(payload: CrossdeckErrorPayload): CrossdeckError;
113
113
 
114
+ /**
115
+ * Public, typed accessor for the bank-grade behavioural contracts
116
+ * this SDK ships. The full architecture — schema, distribution,
117
+ * audit loop, pillar taxonomy — lives in `contracts/README.md`
118
+ * at the monorepo root.
119
+ *
120
+ * Why a typed surface (vs. plain JSON access): contract IDs and
121
+ * pillar names are part of Crossdeck's public commitment to
122
+ * customers. Reading them through `CrossdeckContracts` means the
123
+ * compiler catches drift the moment a contract is renamed or
124
+ * retired. Tools that consume contracts at runtime (dashboards,
125
+ * AI assistants, customer integration tests) get the exact same
126
+ * shape every SDK ships, with no parsing layer to drift.
127
+ *
128
+ * --- BINARY STABILITY ---
129
+ * `Contract` is treated as an evolving — but back-compat — wire
130
+ * shape. Fields may be added in any minor release. Existing
131
+ * fields will not be removed or repurposed except in a major
132
+ * version bump, even if all known contracts stop using them.
133
+ * Customers can rely on `id`, `pillar`, `status`, `appliesTo`,
134
+ * `codeRef`, `testRef`, `registeredAt`, `firstRegisteredIn`,
135
+ * and `bundledIn` being present on every contract in every
136
+ * future minor/patch release of this SDK.
137
+ */
138
+ type ContractPillar = "revenue" | "entitlements" | "analytics" | "webhooks" | "errors" | "lifecycle" | "identity";
139
+ type ContractStatus = "enforced" | "proposed" | "retired";
140
+ type ContractAppliesTo = "web" | "node" | "react-native" | "swift" | "android" | "backend";
141
+ interface ContractTestRef {
142
+ readonly file: string;
143
+ readonly name: string;
144
+ }
145
+ interface Contract {
146
+ readonly id: string;
147
+ readonly pillar: ContractPillar;
148
+ readonly status: ContractStatus;
149
+ readonly claim: string;
150
+ readonly appliesTo: readonly ContractAppliesTo[];
151
+ readonly codeRef: readonly string[];
152
+ readonly testRef: readonly ContractTestRef[];
153
+ readonly registeredAt: string;
154
+ readonly firstRegisteredIn: string;
155
+ readonly bundledIn: string;
156
+ }
157
+ /**
158
+ * Typed entry point to the bank-grade contracts bundled with this
159
+ * SDK release. Stable, side-effect-free, tree-shakeable.
160
+ *
161
+ * @example Audit at app boot
162
+ * ```ts
163
+ * import { CrossdeckContracts } from "@cross-deck/node";
164
+ *
165
+ * for (const c of CrossdeckContracts.all()) {
166
+ * console.log(`[crossdeck] ${c.id} (${c.pillar})`);
167
+ * }
168
+ * ```
169
+ */
170
+ declare const CrossdeckContracts: {
171
+ readonly all: () => readonly Contract[];
172
+ readonly allIncludingHistorical: () => readonly Contract[];
173
+ readonly byId: (id: string) => Contract | undefined;
174
+ readonly byPillar: (pillar: ContractPillar) => readonly Contract[];
175
+ readonly withStatus: (status: ContractStatus) => readonly Contract[];
176
+ readonly sdkVersion: "1.5.1";
177
+ readonly bundledIn: "@cross-deck/node@1.5.1";
178
+ /**
179
+ * Resolve a failing test back to the contract it exercises.
180
+ * Used by test-framework hooks to find the contract id of a
181
+ * failed contract test so `reportContractFailure(...)` can stamp
182
+ * the right `contract_id` on the emitted event.
183
+ */
184
+ readonly findByTestName: (name: string) => Contract | undefined;
185
+ };
186
+ /**
187
+ * Input to {@link CrossdeckServer.reportContractFailure}. Mirrors
188
+ * the per-SDK shape exactly.
189
+ *
190
+ * SCHEMA-LOCK: this interface's field set is exhaustively named. No
191
+ * free-form `extra: Record<string, unknown>` — the schema-lock
192
+ * contract at
193
+ * `contracts/diagnostics/contract-failed-payload-schema-lock.json`
194
+ * forbids unbounded fields. Adding a field requires a PR that
195
+ * amends the contract first, then the public interface.
196
+ */
197
+ interface ContractFailureInput {
198
+ contractId: string;
199
+ /**
200
+ * Short categorical-ish label — the SDK convention is to keep
201
+ * this under 128 chars and stable across runs (so dashboards can
202
+ * group). Never an end-user-supplied string.
203
+ */
204
+ failureReason: string;
205
+ runContext: "ci" | "dogfood" | "customer-app";
206
+ runId: string;
207
+ testRef?: {
208
+ file: string;
209
+ name: string;
210
+ };
211
+ /**
212
+ * Optional coarse device class, e.g. "linux-server", "container",
213
+ * "lambda". A categorical bucket, not a host identifier.
214
+ */
215
+ deviceClass?: string;
216
+ }
217
+
114
218
  /**
115
219
  * Breadcrumb ring buffer — context attached to every error report.
116
220
  *
@@ -409,6 +513,10 @@ interface PurchaseResult {
409
513
  crossdeckCustomerId: string;
410
514
  env: Environment;
411
515
  entitlements: PublicEntitlement[];
516
+ /** True when the response came from the backend's idempotency
517
+ * cache instead of fresh processing. Backend also returns
518
+ * `Idempotent-Replayed: true` as a response header (v1.4.0). */
519
+ idempotent_replay?: boolean;
412
520
  }
413
521
  /**
414
522
  * Response shape from `GET /v1/sdk/heartbeat`. Used by
@@ -462,6 +570,25 @@ interface CrossdeckServerOptions {
462
570
  * not the source of truth.
463
571
  */
464
572
  appId?: string;
573
+ /**
574
+ * Apply Crossdeck's PII scrubber to every `track()` payload before
575
+ * enqueue. Default `true` (parity with Web / RN / Swift SDKs — Node
576
+ * pre-v1.4.0 was the odd one out and SHIPPED EMAILS UNREDACTED, a
577
+ * privacy contract drift versus the README claim).
578
+ *
579
+ * The scrubber rewrites email-shaped and card-number-shaped
580
+ * substrings to `<email>` / `<card>` sentinels recursively across
581
+ * nested maps + arrays. See `scrubPii` / `scrubPiiFromProperties`.
582
+ *
583
+ * **Blast radius of setting `false`:** every `track()` payload —
584
+ * including event names with embedded emails ("user wes@example.com
585
+ * upgraded"), trait values, group memberships, error context blobs
586
+ * — ships verbatim to Crossdeck and downstream warehouses /
587
+ * analytics exports. Disable only for explicit compliance use
588
+ * cases (regulator-required audit trails where the raw value MUST
589
+ * be preserved) and document the decision at the call site.
590
+ */
591
+ scrubPii?: boolean;
465
592
  /**
466
593
  * Error capture configuration. Default: ON with `onUncaughtException` +
467
594
  * `onUnhandledRejection` + `wrapFetch` all enabled.
@@ -672,6 +799,14 @@ interface RequestOptions {
672
799
  * `timeoutMs`. Pass `0` to disable.
673
800
  */
674
801
  timeoutMs?: number;
802
+ /**
803
+ * Override the deterministic Idempotency-Key derivation (v1.4.0).
804
+ * The SDK derives a stable key from the request body so retries
805
+ * collapse on the backend. Override only when an outer
806
+ * orchestrator (job runner, retry harness) needs a different
807
+ * idempotency window — and document why at the call site.
808
+ */
809
+ idempotencyKey?: string;
675
810
  }
676
811
  interface IdentityHints {
677
812
  customerId?: string;
@@ -1162,6 +1297,10 @@ declare class CrossdeckServer extends EventEmitter {
1162
1297
  private readonly baseUrl;
1163
1298
  private readonly appId;
1164
1299
  private readonly env;
1300
+ /** PII scrubber toggle. Default true — parity with Web/RN/Swift.
1301
+ * Pre-v1.4.0 the Node SDK shipped track() payloads UNREDACTED,
1302
+ * a privacy contract drift versus the README. */
1303
+ private readonly scrubPii;
1165
1304
  private readonly secretKeyPrefix;
1166
1305
  /**
1167
1306
  * Process-stable pseudo-anonymous ID. Used as the default identity
@@ -1207,6 +1346,15 @@ declare class CrossdeckServer extends EventEmitter {
1207
1346
  private errorContext;
1208
1347
  private errorTags;
1209
1348
  private errorBeforeSend;
1349
+ /**
1350
+ * Dedup gate for `sdk.shutdown`. Both `shutdown()` (async) and
1351
+ * `shutdownSync()` need to emit so direct callers of EITHER see
1352
+ * the event (the async path's listener guarantees pre-launch
1353
+ * tests, the sync path covers `Symbol.dispose` + tests that call
1354
+ * `shutdownSync()` directly). Without this flag, `shutdown()`'s
1355
+ * tail call into `shutdownSync()` would emit twice.
1356
+ */
1357
+ private didEmitShutdown;
1210
1358
  constructor(options: CrossdeckServerOptions);
1211
1359
  /**
1212
1360
  * Emit the honest "no cold-start durability" warning when the runtime
@@ -1331,6 +1479,17 @@ declare class CrossdeckServer extends EventEmitter {
1331
1479
  * `uncaughtException` has no per-request context; without the
1332
1480
  * auto-fill, the event would be rejected at queue enqueue.
1333
1481
  */
1482
+ /**
1483
+ * Emit `crossdeck.contract_failed` to the Crossdeck reliability
1484
+ * endpoint — single-fire, one-way, never visible in the customer's
1485
+ * dashboard. Goes over a dedicated HTTP path with the reliability
1486
+ * publishable key embedded at build time; the customer's track()
1487
+ * pipeline never carries `crossdeck.*` events. This is the
1488
+ * independent-controller flow described in Privacy Policy §6
1489
+ * ("Flow B"). The wire shape is fixed by the schema-lock contract
1490
+ * at `contracts/diagnostics/contract-failed-payload-schema-lock.json`.
1491
+ */
1492
+ reportContractFailure(input: ContractFailureInput): void;
1334
1493
  track(event: ServerEvent): void;
1335
1494
  /**
1336
1495
  * Immediate POST of one or more events. For bulk imports / replay
@@ -1541,11 +1700,36 @@ declare class CrossdeckServer extends EventEmitter {
1541
1700
  getGroups(): Record<string, GroupMembership>;
1542
1701
  diagnostics(): Diagnostics;
1543
1702
  /**
1544
- * Tear down handlers and clear in-memory state. Tests + custom
1545
- * lifecycle callers only. Production code should rely on
1546
- * `flush-on-exit` instead.
1703
+ * Tear down handlers and clear in-memory state.
1704
+ *
1705
+ * **v1.4.0 bank-grade contract:** `shutdown()` AWAITS `flush()`
1706
+ * before dropping the queue, so callers don't silently lose
1707
+ * every queued event on a clean shutdown. The pre-v1.4.0
1708
+ * behaviour (sync `eventQueue.reset()` with no flush) was the
1709
+ * default for both `shutdown()` and `[Symbol.dispose]`; only
1710
+ * `await using` + `[Symbol.asyncDispose]` flushed correctly.
1711
+ *
1712
+ * Production servers should still prefer `await server.flush()`
1713
+ * (visible) followed by `server.shutdown()` so the flush
1714
+ * outcome is observable — `shutdown()`'s internal flush swallows
1715
+ * errors as a best-effort drain.
1716
+ *
1717
+ * Use [[shutdownSync]] only when the runtime cannot await
1718
+ * (e.g. inside `Symbol.dispose` — see below).
1719
+ */
1720
+ shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): Promise<void>;
1721
+ /**
1722
+ * Synchronous teardown — drops the in-memory queue WITHOUT
1723
+ * flushing, then clears all in-memory state. Used by
1724
+ * `[Symbol.dispose]` (which has no await) and tests that need
1725
+ * an unconditional sync wipe. Production code should use
1726
+ * [[shutdown]] (async) instead so queued events are flushed.
1727
+ *
1728
+ * A queue with items at sync-shutdown logs a warning recommending
1729
+ * `[Symbol.asyncDispose]` or `await server.shutdown()` — silent
1730
+ * loss is incompatible with the bank-grade contract.
1547
1731
  */
1548
- shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1732
+ shutdownSync(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1549
1733
  /**
1550
1734
  * Convert a `CapturedError` into a `ServerEvent` and push through
1551
1735
  * `track()`. Goes through the same queue / enrichment / breadcrumb
@@ -1614,17 +1798,21 @@ declare class CrossdeckServer extends EventEmitter {
1614
1798
  * // ... use server ...
1615
1799
  * // at end of block, server[Symbol.dispose]() runs automatically
1616
1800
  *
1617
- * `Symbol.dispose` is synchronous so we can't await `flush()` here
1618
- * for that, use `await using` + `[Symbol.asyncDispose]()`. This
1619
- * sync variant just calls `shutdown()` (handler cleanup +
1620
- * in-memory state wipe).
1801
+ * **`Symbol.dispose` is synchronous so it CANNOT await the queue
1802
+ * flush.** A queue with pending events at sync-dispose time will
1803
+ * be DROPPED `shutdownSync` warns to the console when this
1804
+ * happens. For the common case of "drain the queue before
1805
+ * exit", switch to `await using` + `[Symbol.asyncDispose]` (or
1806
+ * call `await server.shutdown()` explicitly before the variable
1807
+ * goes out of scope).
1621
1808
  */
1622
1809
  [Symbol.dispose](): void;
1623
1810
  /**
1624
1811
  * Async disposal hook — runs when an `await using` declaration
1625
- * exits scope. Awaits `flush()` THEN runs `shutdown()`. Use this
1626
- * variant when the caller needs the queue drained before exit
1627
- * (the common case for serverless handlers).
1812
+ * exits scope. Awaits the bank-grade `shutdown()` which flushes
1813
+ * the queue THEN tears down. Use this variant for any code path
1814
+ * that owns queued events at exit (serverless handlers,
1815
+ * background workers, end-of-request hooks).
1628
1816
  *
1629
1817
  * await using server = new CrossdeckServer({ ... });
1630
1818
  */
@@ -1710,4 +1898,4 @@ declare class CrossdeckServer extends EventEmitter {
1710
1898
  private normalizeIngestEvent;
1711
1899
  }
1712
1900
 
1713
- export { type StoredEntitlements as $, type AliasIdentityInput as A, type Breadcrumb as B, CROSSDECK_API_VERSION as C, DEFAULT_BASE_URL as D, type EntitlementCacheOptions as E, type ErrorLevel as F, type EventProperties as G, type ForgetResult as H, type GrantDuration as I, type GrantEntitlementInput as J, type GroupMembership as K, type HeartbeatResponse as L, type HttpRequestInfo as M, type HttpResponseInfo as N, type HttpRetriesConfig as O, type IdentifyOptions as P, type IdentityHints as Q, type IngestOptions as R, type IngestResponse as S, type PublicEntitlement as T, type PurchaseResult as U, type RequestOptions as V, type RevokeEntitlementInput as W, type RuntimeHost as X, type RuntimeInfo as Y, type ServerEvent as Z, type StackFrame as _, type AliasResult as a, type SyncPurchaseInput as a0, makeCrossdeckError as a1, type AuditDecision as b, type AuditEntry as c, type BreadcrumbCategory as d, type BreadcrumbLevel as e, type CapturedError as f, CrossdeckAuthenticationError as g, CrossdeckConfigurationError as h, CrossdeckError as i, type CrossdeckErrorPayload as j, type CrossdeckErrorType as k, CrossdeckInternalError as l, CrossdeckNetworkError as m, CrossdeckPermissionError as n, CrossdeckRateLimitError as o, CrossdeckServer as p, type CrossdeckServerOptions as q, CrossdeckValidationError as r, DEFAULT_TIMEOUT_MS as s, type Diagnostics as t, type EntitlementMutationResult as u, type EntitlementStore as v, type EntitlementsListResponse as w, type EntitlementsListener as x, type Environment as y, type ErrorCaptureConfig as z };
1901
+ export { type PurchaseResult as $, type AliasIdentityInput as A, type Breadcrumb as B, CROSSDECK_API_VERSION as C, DEFAULT_BASE_URL as D, type Diagnostics as E, type EntitlementCacheOptions as F, type EntitlementMutationResult as G, type EntitlementStore as H, type EntitlementsListResponse as I, type EntitlementsListener as J, type Environment as K, type ErrorCaptureConfig as L, type ErrorLevel as M, type EventProperties as N, type ForgetResult as O, type GrantDuration as P, type GrantEntitlementInput as Q, type GroupMembership as R, type HeartbeatResponse as S, type HttpRequestInfo as T, type HttpResponseInfo as U, type HttpRetriesConfig as V, type IdentifyOptions as W, type IdentityHints as X, type IngestOptions as Y, type IngestResponse as Z, type PublicEntitlement as _, type AliasResult as a, type RequestOptions as a0, type RevokeEntitlementInput as a1, type RuntimeHost as a2, type RuntimeInfo as a3, type ServerEvent as a4, type StackFrame as a5, type StoredEntitlements as a6, type SyncPurchaseInput as a7, makeCrossdeckError as a8, type AuditDecision as b, type AuditEntry as c, type BreadcrumbCategory as d, type BreadcrumbLevel as e, type CapturedError as f, type Contract as g, type ContractAppliesTo as h, type ContractFailureInput as i, type ContractPillar as j, type ContractStatus as k, type ContractTestRef as l, CrossdeckAuthenticationError as m, CrossdeckConfigurationError as n, CrossdeckContracts as o, CrossdeckError as p, type CrossdeckErrorPayload as q, type CrossdeckErrorType as r, CrossdeckInternalError as s, CrossdeckNetworkError as t, CrossdeckPermissionError as u, CrossdeckRateLimitError as v, CrossdeckServer as w, type CrossdeckServerOptions as x, CrossdeckValidationError as y, DEFAULT_TIMEOUT_MS as z };