@cross-deck/node 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -111,6 +111,96 @@ 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.0";
177
+ readonly bundledIn: "@cross-deck/node@1.5.0";
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 — the Crossdeck dashboard joins
189
+ * `crossdeck.contract_failed` events across every SDK on
190
+ * `contract_id`, so the property bag has to agree.
191
+ */
192
+ interface ContractFailureInput {
193
+ contractId: string;
194
+ failureReason: string;
195
+ runContext: "ci" | "dogfood" | "customer-app";
196
+ runId: string;
197
+ testRef?: {
198
+ file: string;
199
+ name: string;
200
+ };
201
+ extra?: Record<string, unknown>;
202
+ }
203
+
114
204
  /**
115
205
  * Breadcrumb ring buffer — context attached to every error report.
116
206
  *
@@ -409,6 +499,10 @@ interface PurchaseResult {
409
499
  crossdeckCustomerId: string;
410
500
  env: Environment;
411
501
  entitlements: PublicEntitlement[];
502
+ /** True when the response came from the backend's idempotency
503
+ * cache instead of fresh processing. Backend also returns
504
+ * `Idempotent-Replayed: true` as a response header (v1.4.0). */
505
+ idempotent_replay?: boolean;
412
506
  }
413
507
  /**
414
508
  * Response shape from `GET /v1/sdk/heartbeat`. Used by
@@ -462,6 +556,25 @@ interface CrossdeckServerOptions {
462
556
  * not the source of truth.
463
557
  */
464
558
  appId?: string;
559
+ /**
560
+ * Apply Crossdeck's PII scrubber to every `track()` payload before
561
+ * enqueue. Default `true` (parity with Web / RN / Swift SDKs — Node
562
+ * pre-v1.4.0 was the odd one out and SHIPPED EMAILS UNREDACTED, a
563
+ * privacy contract drift versus the README claim).
564
+ *
565
+ * The scrubber rewrites email-shaped and card-number-shaped
566
+ * substrings to `<email>` / `<card>` sentinels recursively across
567
+ * nested maps + arrays. See `scrubPii` / `scrubPiiFromProperties`.
568
+ *
569
+ * **Blast radius of setting `false`:** every `track()` payload —
570
+ * including event names with embedded emails ("user wes@example.com
571
+ * upgraded"), trait values, group memberships, error context blobs
572
+ * — ships verbatim to Crossdeck and downstream warehouses /
573
+ * analytics exports. Disable only for explicit compliance use
574
+ * cases (regulator-required audit trails where the raw value MUST
575
+ * be preserved) and document the decision at the call site.
576
+ */
577
+ scrubPii?: boolean;
465
578
  /**
466
579
  * Error capture configuration. Default: ON with `onUncaughtException` +
467
580
  * `onUnhandledRejection` + `wrapFetch` all enabled.
@@ -672,6 +785,14 @@ interface RequestOptions {
672
785
  * `timeoutMs`. Pass `0` to disable.
673
786
  */
674
787
  timeoutMs?: number;
788
+ /**
789
+ * Override the deterministic Idempotency-Key derivation (v1.4.0).
790
+ * The SDK derives a stable key from the request body so retries
791
+ * collapse on the backend. Override only when an outer
792
+ * orchestrator (job runner, retry harness) needs a different
793
+ * idempotency window — and document why at the call site.
794
+ */
795
+ idempotencyKey?: string;
675
796
  }
676
797
  interface IdentityHints {
677
798
  customerId?: string;
@@ -1162,6 +1283,10 @@ declare class CrossdeckServer extends EventEmitter {
1162
1283
  private readonly baseUrl;
1163
1284
  private readonly appId;
1164
1285
  private readonly env;
1286
+ /** PII scrubber toggle. Default true — parity with Web/RN/Swift.
1287
+ * Pre-v1.4.0 the Node SDK shipped track() payloads UNREDACTED,
1288
+ * a privacy contract drift versus the README. */
1289
+ private readonly scrubPii;
1165
1290
  private readonly secretKeyPrefix;
1166
1291
  /**
1167
1292
  * Process-stable pseudo-anonymous ID. Used as the default identity
@@ -1207,6 +1332,15 @@ declare class CrossdeckServer extends EventEmitter {
1207
1332
  private errorContext;
1208
1333
  private errorTags;
1209
1334
  private errorBeforeSend;
1335
+ /**
1336
+ * Dedup gate for `sdk.shutdown`. Both `shutdown()` (async) and
1337
+ * `shutdownSync()` need to emit so direct callers of EITHER see
1338
+ * the event (the async path's listener guarantees pre-launch
1339
+ * tests, the sync path covers `Symbol.dispose` + tests that call
1340
+ * `shutdownSync()` directly). Without this flag, `shutdown()`'s
1341
+ * tail call into `shutdownSync()` would emit twice.
1342
+ */
1343
+ private didEmitShutdown;
1210
1344
  constructor(options: CrossdeckServerOptions);
1211
1345
  /**
1212
1346
  * Emit the honest "no cold-start durability" warning when the runtime
@@ -1331,6 +1465,14 @@ declare class CrossdeckServer extends EventEmitter {
1331
1465
  * `uncaughtException` has no per-request context; without the
1332
1466
  * auto-fill, the event would be rejected at queue enqueue.
1333
1467
  */
1468
+ /**
1469
+ * Emit `crossdeck.contract_failed` with the canonical property
1470
+ * shape. Same wire shape every Crossdeck SDK uses for contract
1471
+ * verification telemetry — see `contracts/README.md` for the
1472
+ * full pattern. No new endpoint, no special path; goes through
1473
+ * the standard server-side `track()` pipeline.
1474
+ */
1475
+ reportContractFailure(input: ContractFailureInput): void;
1334
1476
  track(event: ServerEvent): void;
1335
1477
  /**
1336
1478
  * Immediate POST of one or more events. For bulk imports / replay
@@ -1541,11 +1683,36 @@ declare class CrossdeckServer extends EventEmitter {
1541
1683
  getGroups(): Record<string, GroupMembership>;
1542
1684
  diagnostics(): Diagnostics;
1543
1685
  /**
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.
1686
+ * Tear down handlers and clear in-memory state.
1687
+ *
1688
+ * **v1.4.0 bank-grade contract:** `shutdown()` AWAITS `flush()`
1689
+ * before dropping the queue, so callers don't silently lose
1690
+ * every queued event on a clean shutdown. The pre-v1.4.0
1691
+ * behaviour (sync `eventQueue.reset()` with no flush) was the
1692
+ * default for both `shutdown()` and `[Symbol.dispose]`; only
1693
+ * `await using` + `[Symbol.asyncDispose]` flushed correctly.
1694
+ *
1695
+ * Production servers should still prefer `await server.flush()`
1696
+ * (visible) followed by `server.shutdown()` so the flush
1697
+ * outcome is observable — `shutdown()`'s internal flush swallows
1698
+ * errors as a best-effort drain.
1699
+ *
1700
+ * Use [[shutdownSync]] only when the runtime cannot await
1701
+ * (e.g. inside `Symbol.dispose` — see below).
1702
+ */
1703
+ shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): Promise<void>;
1704
+ /**
1705
+ * Synchronous teardown — drops the in-memory queue WITHOUT
1706
+ * flushing, then clears all in-memory state. Used by
1707
+ * `[Symbol.dispose]` (which has no await) and tests that need
1708
+ * an unconditional sync wipe. Production code should use
1709
+ * [[shutdown]] (async) instead so queued events are flushed.
1710
+ *
1711
+ * A queue with items at sync-shutdown logs a warning recommending
1712
+ * `[Symbol.asyncDispose]` or `await server.shutdown()` — silent
1713
+ * loss is incompatible with the bank-grade contract.
1547
1714
  */
1548
- shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1715
+ shutdownSync(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1549
1716
  /**
1550
1717
  * Convert a `CapturedError` into a `ServerEvent` and push through
1551
1718
  * `track()`. Goes through the same queue / enrichment / breadcrumb
@@ -1614,17 +1781,21 @@ declare class CrossdeckServer extends EventEmitter {
1614
1781
  * // ... use server ...
1615
1782
  * // at end of block, server[Symbol.dispose]() runs automatically
1616
1783
  *
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).
1784
+ * **`Symbol.dispose` is synchronous so it CANNOT await the queue
1785
+ * flush.** A queue with pending events at sync-dispose time will
1786
+ * be DROPPED `shutdownSync` warns to the console when this
1787
+ * happens. For the common case of "drain the queue before
1788
+ * exit", switch to `await using` + `[Symbol.asyncDispose]` (or
1789
+ * call `await server.shutdown()` explicitly before the variable
1790
+ * goes out of scope).
1621
1791
  */
1622
1792
  [Symbol.dispose](): void;
1623
1793
  /**
1624
1794
  * 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).
1795
+ * exits scope. Awaits the bank-grade `shutdown()` which flushes
1796
+ * the queue THEN tears down. Use this variant for any code path
1797
+ * that owns queued events at exit (serverless handlers,
1798
+ * background workers, end-of-request hooks).
1628
1799
  *
1629
1800
  * await using server = new CrossdeckServer({ ... });
1630
1801
  */
@@ -1710,4 +1881,4 @@ declare class CrossdeckServer extends EventEmitter {
1710
1881
  private normalizeIngestEvent;
1711
1882
  }
1712
1883
 
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 };
1884
+ 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,96 @@ 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.0";
177
+ readonly bundledIn: "@cross-deck/node@1.5.0";
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 — the Crossdeck dashboard joins
189
+ * `crossdeck.contract_failed` events across every SDK on
190
+ * `contract_id`, so the property bag has to agree.
191
+ */
192
+ interface ContractFailureInput {
193
+ contractId: string;
194
+ failureReason: string;
195
+ runContext: "ci" | "dogfood" | "customer-app";
196
+ runId: string;
197
+ testRef?: {
198
+ file: string;
199
+ name: string;
200
+ };
201
+ extra?: Record<string, unknown>;
202
+ }
203
+
114
204
  /**
115
205
  * Breadcrumb ring buffer — context attached to every error report.
116
206
  *
@@ -409,6 +499,10 @@ interface PurchaseResult {
409
499
  crossdeckCustomerId: string;
410
500
  env: Environment;
411
501
  entitlements: PublicEntitlement[];
502
+ /** True when the response came from the backend's idempotency
503
+ * cache instead of fresh processing. Backend also returns
504
+ * `Idempotent-Replayed: true` as a response header (v1.4.0). */
505
+ idempotent_replay?: boolean;
412
506
  }
413
507
  /**
414
508
  * Response shape from `GET /v1/sdk/heartbeat`. Used by
@@ -462,6 +556,25 @@ interface CrossdeckServerOptions {
462
556
  * not the source of truth.
463
557
  */
464
558
  appId?: string;
559
+ /**
560
+ * Apply Crossdeck's PII scrubber to every `track()` payload before
561
+ * enqueue. Default `true` (parity with Web / RN / Swift SDKs — Node
562
+ * pre-v1.4.0 was the odd one out and SHIPPED EMAILS UNREDACTED, a
563
+ * privacy contract drift versus the README claim).
564
+ *
565
+ * The scrubber rewrites email-shaped and card-number-shaped
566
+ * substrings to `<email>` / `<card>` sentinels recursively across
567
+ * nested maps + arrays. See `scrubPii` / `scrubPiiFromProperties`.
568
+ *
569
+ * **Blast radius of setting `false`:** every `track()` payload —
570
+ * including event names with embedded emails ("user wes@example.com
571
+ * upgraded"), trait values, group memberships, error context blobs
572
+ * — ships verbatim to Crossdeck and downstream warehouses /
573
+ * analytics exports. Disable only for explicit compliance use
574
+ * cases (regulator-required audit trails where the raw value MUST
575
+ * be preserved) and document the decision at the call site.
576
+ */
577
+ scrubPii?: boolean;
465
578
  /**
466
579
  * Error capture configuration. Default: ON with `onUncaughtException` +
467
580
  * `onUnhandledRejection` + `wrapFetch` all enabled.
@@ -672,6 +785,14 @@ interface RequestOptions {
672
785
  * `timeoutMs`. Pass `0` to disable.
673
786
  */
674
787
  timeoutMs?: number;
788
+ /**
789
+ * Override the deterministic Idempotency-Key derivation (v1.4.0).
790
+ * The SDK derives a stable key from the request body so retries
791
+ * collapse on the backend. Override only when an outer
792
+ * orchestrator (job runner, retry harness) needs a different
793
+ * idempotency window — and document why at the call site.
794
+ */
795
+ idempotencyKey?: string;
675
796
  }
676
797
  interface IdentityHints {
677
798
  customerId?: string;
@@ -1162,6 +1283,10 @@ declare class CrossdeckServer extends EventEmitter {
1162
1283
  private readonly baseUrl;
1163
1284
  private readonly appId;
1164
1285
  private readonly env;
1286
+ /** PII scrubber toggle. Default true — parity with Web/RN/Swift.
1287
+ * Pre-v1.4.0 the Node SDK shipped track() payloads UNREDACTED,
1288
+ * a privacy contract drift versus the README. */
1289
+ private readonly scrubPii;
1165
1290
  private readonly secretKeyPrefix;
1166
1291
  /**
1167
1292
  * Process-stable pseudo-anonymous ID. Used as the default identity
@@ -1207,6 +1332,15 @@ declare class CrossdeckServer extends EventEmitter {
1207
1332
  private errorContext;
1208
1333
  private errorTags;
1209
1334
  private errorBeforeSend;
1335
+ /**
1336
+ * Dedup gate for `sdk.shutdown`. Both `shutdown()` (async) and
1337
+ * `shutdownSync()` need to emit so direct callers of EITHER see
1338
+ * the event (the async path's listener guarantees pre-launch
1339
+ * tests, the sync path covers `Symbol.dispose` + tests that call
1340
+ * `shutdownSync()` directly). Without this flag, `shutdown()`'s
1341
+ * tail call into `shutdownSync()` would emit twice.
1342
+ */
1343
+ private didEmitShutdown;
1210
1344
  constructor(options: CrossdeckServerOptions);
1211
1345
  /**
1212
1346
  * Emit the honest "no cold-start durability" warning when the runtime
@@ -1331,6 +1465,14 @@ declare class CrossdeckServer extends EventEmitter {
1331
1465
  * `uncaughtException` has no per-request context; without the
1332
1466
  * auto-fill, the event would be rejected at queue enqueue.
1333
1467
  */
1468
+ /**
1469
+ * Emit `crossdeck.contract_failed` with the canonical property
1470
+ * shape. Same wire shape every Crossdeck SDK uses for contract
1471
+ * verification telemetry — see `contracts/README.md` for the
1472
+ * full pattern. No new endpoint, no special path; goes through
1473
+ * the standard server-side `track()` pipeline.
1474
+ */
1475
+ reportContractFailure(input: ContractFailureInput): void;
1334
1476
  track(event: ServerEvent): void;
1335
1477
  /**
1336
1478
  * Immediate POST of one or more events. For bulk imports / replay
@@ -1541,11 +1683,36 @@ declare class CrossdeckServer extends EventEmitter {
1541
1683
  getGroups(): Record<string, GroupMembership>;
1542
1684
  diagnostics(): Diagnostics;
1543
1685
  /**
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.
1686
+ * Tear down handlers and clear in-memory state.
1687
+ *
1688
+ * **v1.4.0 bank-grade contract:** `shutdown()` AWAITS `flush()`
1689
+ * before dropping the queue, so callers don't silently lose
1690
+ * every queued event on a clean shutdown. The pre-v1.4.0
1691
+ * behaviour (sync `eventQueue.reset()` with no flush) was the
1692
+ * default for both `shutdown()` and `[Symbol.dispose]`; only
1693
+ * `await using` + `[Symbol.asyncDispose]` flushed correctly.
1694
+ *
1695
+ * Production servers should still prefer `await server.flush()`
1696
+ * (visible) followed by `server.shutdown()` so the flush
1697
+ * outcome is observable — `shutdown()`'s internal flush swallows
1698
+ * errors as a best-effort drain.
1699
+ *
1700
+ * Use [[shutdownSync]] only when the runtime cannot await
1701
+ * (e.g. inside `Symbol.dispose` — see below).
1702
+ */
1703
+ shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): Promise<void>;
1704
+ /**
1705
+ * Synchronous teardown — drops the in-memory queue WITHOUT
1706
+ * flushing, then clears all in-memory state. Used by
1707
+ * `[Symbol.dispose]` (which has no await) and tests that need
1708
+ * an unconditional sync wipe. Production code should use
1709
+ * [[shutdown]] (async) instead so queued events are flushed.
1710
+ *
1711
+ * A queue with items at sync-shutdown logs a warning recommending
1712
+ * `[Symbol.asyncDispose]` or `await server.shutdown()` — silent
1713
+ * loss is incompatible with the bank-grade contract.
1547
1714
  */
1548
- shutdown(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1715
+ shutdownSync(reason?: "shutdown" | "dispose" | "asyncDispose"): void;
1549
1716
  /**
1550
1717
  * Convert a `CapturedError` into a `ServerEvent` and push through
1551
1718
  * `track()`. Goes through the same queue / enrichment / breadcrumb
@@ -1614,17 +1781,21 @@ declare class CrossdeckServer extends EventEmitter {
1614
1781
  * // ... use server ...
1615
1782
  * // at end of block, server[Symbol.dispose]() runs automatically
1616
1783
  *
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).
1784
+ * **`Symbol.dispose` is synchronous so it CANNOT await the queue
1785
+ * flush.** A queue with pending events at sync-dispose time will
1786
+ * be DROPPED `shutdownSync` warns to the console when this
1787
+ * happens. For the common case of "drain the queue before
1788
+ * exit", switch to `await using` + `[Symbol.asyncDispose]` (or
1789
+ * call `await server.shutdown()` explicitly before the variable
1790
+ * goes out of scope).
1621
1791
  */
1622
1792
  [Symbol.dispose](): void;
1623
1793
  /**
1624
1794
  * 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).
1795
+ * exits scope. Awaits the bank-grade `shutdown()` which flushes
1796
+ * the queue THEN tears down. Use this variant for any code path
1797
+ * that owns queued events at exit (serverless handlers,
1798
+ * background workers, end-of-request hooks).
1628
1799
  *
1629
1800
  * await using server = new CrossdeckServer({ ... });
1630
1801
  */
@@ -1710,4 +1881,4 @@ declare class CrossdeckServer extends EventEmitter {
1710
1881
  private normalizeIngestEvent;
1711
1882
  }
1712
1883
 
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 };
1884
+ 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 };