@adcp/sdk 17.0.0-beta.21 → 17.0.0-beta.23

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.
Files changed (223) hide show
  1. package/README.md +26 -2
  2. package/dist/lib/adapters/version/index.d.mts +1 -1
  3. package/dist/lib/adapters/version/index.d.ts +1 -1
  4. package/dist/lib/adapters/version/index.js +2 -0
  5. package/dist/lib/adapters/version/index.mjs +2 -0
  6. package/dist/lib/adapters/version/negotiate.d.mts +13 -0
  7. package/dist/lib/adapters/version/negotiate.d.ts +13 -0
  8. package/dist/lib/adapters/version/negotiate.js +6 -0
  9. package/dist/lib/adapters/version/negotiate.mjs +5 -0
  10. package/dist/lib/client/core.d.mts +4 -0
  11. package/dist/lib/client/core.d.ts +4 -0
  12. package/dist/lib/client/core.js +13 -0
  13. package/dist/lib/client/core.mjs +12 -0
  14. package/dist/lib/conformance/property-lists.d.mts +1 -1
  15. package/dist/lib/conformance/property-lists.d.ts +1 -1
  16. package/dist/lib/conformance/property-lists.js +1 -1
  17. package/dist/lib/conformance/property-lists.mjs +1 -1
  18. package/dist/lib/core/SingleAgentClient.d.mts +23 -1
  19. package/dist/lib/core/SingleAgentClient.d.ts +23 -1
  20. package/dist/lib/core/SingleAgentClient.js +102 -18
  21. package/dist/lib/core/SingleAgentClient.mjs +108 -18
  22. package/dist/lib/core/targeting-helpers.d.mts +123 -0
  23. package/dist/lib/core/targeting-helpers.d.ts +123 -0
  24. package/dist/lib/core/targeting-helpers.js +412 -0
  25. package/dist/lib/core/targeting-helpers.mjs +370 -0
  26. package/dist/lib/entrypoints/client-account-changes.d.mts +5 -0
  27. package/dist/lib/entrypoints/client-account-changes.d.ts +5 -0
  28. package/dist/lib/entrypoints/client-account-changes.js +28 -0
  29. package/dist/lib/entrypoints/client-account-changes.mjs +4 -0
  30. package/dist/lib/entrypoints/client-webhook-stores.d.mts +2 -0
  31. package/dist/lib/entrypoints/client-webhook-stores.d.ts +2 -0
  32. package/dist/lib/entrypoints/client-webhook-stores.js +37 -0
  33. package/dist/lib/entrypoints/client-webhook-stores.mjs +16 -0
  34. package/dist/lib/entrypoints/discovery.d.mts +9 -0
  35. package/dist/lib/entrypoints/discovery.d.ts +9 -0
  36. package/dist/lib/entrypoints/discovery.js +72 -0
  37. package/dist/lib/entrypoints/discovery.mjs +56 -0
  38. package/dist/lib/entrypoints/errors.d.mts +11 -0
  39. package/dist/lib/entrypoints/errors.d.ts +11 -0
  40. package/dist/lib/entrypoints/errors.js +159 -0
  41. package/dist/lib/entrypoints/errors.mjs +132 -0
  42. package/dist/lib/entrypoints/media-buy.d.mts +5 -0
  43. package/dist/lib/entrypoints/media-buy.d.ts +5 -0
  44. package/dist/lib/entrypoints/media-buy.js +119 -0
  45. package/dist/lib/entrypoints/media-buy.mjs +100 -0
  46. package/dist/lib/entrypoints/registry.d.mts +5 -0
  47. package/dist/lib/entrypoints/registry.d.ts +5 -0
  48. package/dist/lib/entrypoints/registry.js +61 -0
  49. package/dist/lib/entrypoints/registry.mjs +40 -0
  50. package/dist/lib/entrypoints/utils.d.mts +7 -0
  51. package/dist/lib/entrypoints/utils.d.ts +7 -0
  52. package/dist/lib/entrypoints/utils.js +100 -0
  53. package/dist/lib/entrypoints/utils.mjs +72 -0
  54. package/dist/lib/entrypoints/version.d.mts +3 -0
  55. package/dist/lib/entrypoints/version.d.ts +3 -0
  56. package/dist/lib/entrypoints/version.js +57 -0
  57. package/dist/lib/entrypoints/version.mjs +36 -0
  58. package/dist/lib/index.d.mts +1 -1
  59. package/dist/lib/index.d.ts +1 -1
  60. package/dist/lib/media-buy/action-contracts.js +3 -3
  61. package/dist/lib/media-buy/action-contracts.mjs +1 -1
  62. package/dist/lib/media-buy/creative-start-policy.d.mts +19 -0
  63. package/dist/lib/media-buy/creative-start-policy.d.ts +19 -0
  64. package/dist/lib/media-buy/creative-start-policy.js +59 -0
  65. package/dist/lib/media-buy/creative-start-policy.mjs +31 -0
  66. package/dist/lib/media-buy/valid-actions.d.mts +47 -0
  67. package/dist/lib/media-buy/valid-actions.d.ts +47 -0
  68. package/dist/lib/media-buy/valid-actions.js +42 -0
  69. package/dist/lib/media-buy/valid-actions.mjs +18 -0
  70. package/dist/lib/net/pin-and-bind-fetch.d.mts +121 -0
  71. package/dist/lib/net/pin-and-bind-fetch.d.ts +121 -0
  72. package/dist/lib/net/pin-and-bind-fetch.js +209 -0
  73. package/dist/lib/net/pin-and-bind-fetch.mjs +183 -0
  74. package/dist/lib/protocols/mcp-modern.js +20 -4
  75. package/dist/lib/protocols/mcp-modern.mjs +20 -4
  76. package/dist/lib/registry/types.generated.d.ts +224 -3
  77. package/dist/lib/reporting/ledger/index.d.mts +1 -0
  78. package/dist/lib/reporting/ledger/index.d.ts +1 -0
  79. package/dist/lib/reporting/ledger/index.js +3 -1
  80. package/dist/lib/reporting/ledger/index.mjs +1 -0
  81. package/dist/lib/reporting/ledger/instant.d.mts +5 -0
  82. package/dist/lib/reporting/ledger/instant.d.ts +5 -0
  83. package/dist/lib/reporting/ledger/instant.js +10 -0
  84. package/dist/lib/reporting/ledger/instant.mjs +9 -0
  85. package/dist/lib/reporting/ledger/issue-events.d.mts +333 -0
  86. package/dist/lib/reporting/ledger/issue-events.d.ts +333 -0
  87. package/dist/lib/reporting/ledger/issue-events.js +310 -0
  88. package/dist/lib/reporting/ledger/issue-events.mjs +282 -0
  89. package/dist/lib/reporting/service/index.d.mts +36 -1
  90. package/dist/lib/reporting/service/index.d.ts +36 -1
  91. package/dist/lib/reporting/service/index.js +51 -1
  92. package/dist/lib/reporting/service/index.mjs +52 -2
  93. package/dist/lib/reporting/service/scheduler-support.d.mts +1 -1
  94. package/dist/lib/reporting/service/scheduler-support.d.ts +1 -1
  95. package/dist/lib/reporting/service/scheduler-support.js +1 -1
  96. package/dist/lib/reporting/service/scheduler-support.mjs +1 -1
  97. package/dist/lib/server/capabilities-release-projection.d.mts +43 -0
  98. package/dist/lib/server/capabilities-release-projection.d.ts +43 -0
  99. package/dist/lib/server/capabilities-release-projection.js +128 -0
  100. package/dist/lib/server/capabilities-release-projection.mjs +112 -0
  101. package/dist/lib/server/create-adcp-server.d.mts +29 -5
  102. package/dist/lib/server/create-adcp-server.d.ts +29 -5
  103. package/dist/lib/server/create-adcp-server.js +97 -24
  104. package/dist/lib/server/create-adcp-server.mjs +108 -23
  105. package/dist/lib/server/decisioning/capabilities.d.mts +27 -0
  106. package/dist/lib/server/decisioning/capabilities.d.ts +27 -0
  107. package/dist/lib/server/decisioning/runtime/from-platform.js +99 -27
  108. package/dist/lib/server/decisioning/runtime/from-platform.mjs +103 -27
  109. package/dist/lib/server/declared-input-schema.d.mts +108 -0
  110. package/dist/lib/server/declared-input-schema.d.ts +108 -0
  111. package/dist/lib/server/declared-input-schema.js +167 -0
  112. package/dist/lib/server/declared-input-schema.mjs +137 -0
  113. package/dist/lib/server/envelope-allowlist.d.mts +1 -105
  114. package/dist/lib/server/envelope-allowlist.d.ts +1 -105
  115. package/dist/lib/server/envelope-allowlist.js +3 -79
  116. package/dist/lib/server/envelope-allowlist.mjs +1 -71
  117. package/dist/lib/server/errors.d.mts +1 -186
  118. package/dist/lib/server/errors.d.ts +1 -186
  119. package/dist/lib/server/errors.js +3 -98
  120. package/dist/lib/server/errors.mjs +1 -94
  121. package/dist/lib/server/index.d.mts +1 -1
  122. package/dist/lib/server/index.d.ts +1 -1
  123. package/dist/lib/server/mcp-modern-server.js +21 -4
  124. package/dist/lib/server/mcp-modern-server.mjs +21 -4
  125. package/dist/lib/server/media-buy-action-resolver.d.mts +7 -0
  126. package/dist/lib/server/media-buy-action-resolver.d.ts +7 -0
  127. package/dist/lib/server/media-buy-action-resolver.js +10 -1
  128. package/dist/lib/server/media-buy-action-resolver.mjs +10 -1
  129. package/dist/lib/server/media-buy-helpers.d.mts +1 -47
  130. package/dist/lib/server/media-buy-helpers.d.ts +1 -47
  131. package/dist/lib/server/media-buy-helpers.js +3 -23
  132. package/dist/lib/server/media-buy-helpers.mjs +1 -18
  133. package/dist/lib/server/pick-safe-details.d.mts +1 -89
  134. package/dist/lib/server/pick-safe-details.d.ts +1 -89
  135. package/dist/lib/server/pick-safe-details.js +3 -61
  136. package/dist/lib/server/pick-safe-details.mjs +1 -56
  137. package/dist/lib/server/pin-and-bind-fetch.d.mts +1 -121
  138. package/dist/lib/server/pin-and-bind-fetch.d.ts +1 -121
  139. package/dist/lib/server/pin-and-bind-fetch.js +3 -190
  140. package/dist/lib/server/pin-and-bind-fetch.mjs +1 -183
  141. package/dist/lib/server/targeting-helpers.d.mts +1 -123
  142. package/dist/lib/server/targeting-helpers.d.ts +1 -123
  143. package/dist/lib/server/targeting-helpers.js +3 -393
  144. package/dist/lib/server/targeting-helpers.mjs +1 -370
  145. package/dist/lib/server/test-controller.js +7 -3
  146. package/dist/lib/server/test-controller.mjs +7 -3
  147. package/dist/lib/storage/memory-ledger.js +219 -1
  148. package/dist/lib/storage/memory-ledger.mjs +223 -1
  149. package/dist/lib/testing/client.js +26 -5
  150. package/dist/lib/testing/client.mjs +24 -5
  151. package/dist/lib/testing/compliance/storyboard-tracks.js +0 -4
  152. package/dist/lib/testing/compliance/storyboard-tracks.mjs +0 -4
  153. package/dist/lib/testing/comply-controller.js +7 -2
  154. package/dist/lib/testing/comply-controller.mjs +7 -2
  155. package/dist/lib/testing/storyboard/request-signing/grader.d.mts +21 -0
  156. package/dist/lib/testing/storyboard/request-signing/grader.d.ts +21 -0
  157. package/dist/lib/testing/storyboard/request-signing/grader.js +31 -0
  158. package/dist/lib/testing/storyboard/request-signing/grader.mjs +30 -0
  159. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js +1 -1
  160. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs +2 -1
  161. package/dist/lib/testing/storyboard/request-signing/types.d.mts +12 -0
  162. package/dist/lib/testing/storyboard/request-signing/types.d.ts +12 -0
  163. package/dist/lib/testing/storyboard/request-signing/vector-loader.js +7 -2
  164. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +7 -2
  165. package/dist/lib/testing/storyboard/runner.js +4 -4
  166. package/dist/lib/testing/storyboard/runner.mjs +4 -4
  167. package/dist/lib/testing/storyboard/task-map.js +4 -1
  168. package/dist/lib/testing/storyboard/task-map.mjs +4 -1
  169. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  170. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  171. package/dist/lib/utils/adcp-error-response.d.mts +196 -0
  172. package/dist/lib/utils/adcp-error-response.d.ts +196 -0
  173. package/dist/lib/utils/adcp-error-response.js +118 -0
  174. package/dist/lib/utils/adcp-error-response.mjs +95 -0
  175. package/dist/lib/utils/buyer-retry-policy.js +2 -2
  176. package/dist/lib/utils/buyer-retry-policy.mjs +1 -1
  177. package/dist/lib/utils/capabilities.d.mts +6 -0
  178. package/dist/lib/utils/capabilities.d.ts +6 -0
  179. package/dist/lib/utils/capabilities.js +6 -2
  180. package/dist/lib/utils/capabilities.mjs +6 -2
  181. package/dist/lib/utils/envelope-allowlist.d.mts +105 -0
  182. package/dist/lib/utils/envelope-allowlist.d.ts +105 -0
  183. package/dist/lib/utils/envelope-allowlist.js +98 -0
  184. package/dist/lib/utils/envelope-allowlist.mjs +71 -0
  185. package/dist/lib/utils/pick-safe-details.d.mts +89 -0
  186. package/dist/lib/utils/pick-safe-details.d.ts +89 -0
  187. package/dist/lib/utils/pick-safe-details.js +80 -0
  188. package/dist/lib/utils/pick-safe-details.mjs +56 -0
  189. package/dist/lib/v2/projection/augment-response.d.mts +4 -0
  190. package/dist/lib/v2/projection/augment-response.d.ts +4 -0
  191. package/dist/lib/v2/projection/creative-delivery.d.mts +20 -3
  192. package/dist/lib/v2/projection/creative-delivery.d.ts +20 -3
  193. package/dist/lib/v2/projection/creative-delivery.js +20 -4
  194. package/dist/lib/v2/projection/creative-delivery.mjs +19 -4
  195. package/dist/lib/v2/projection/index.d.mts +2 -2
  196. package/dist/lib/v2/projection/index.d.ts +2 -2
  197. package/dist/lib/v2/projection/index.js +4 -0
  198. package/dist/lib/v2/projection/index.mjs +5 -1
  199. package/dist/lib/v2/projection/legacy-metadata.d.mts +7 -0
  200. package/dist/lib/v2/projection/legacy-metadata.d.ts +7 -0
  201. package/dist/lib/v2/projection/legacy-metadata.js +14 -0
  202. package/dist/lib/v2/projection/legacy-metadata.mjs +12 -0
  203. package/dist/lib/v2/projection/legacy-routes.d.mts +11 -0
  204. package/dist/lib/v2/projection/legacy-routes.d.ts +11 -0
  205. package/dist/lib/v2/projection/legacy-routes.js +2 -1
  206. package/dist/lib/v2/projection/legacy-routes.mjs +7 -2
  207. package/dist/lib/v2/projection/v1-to-v2.d.mts +21 -1
  208. package/dist/lib/v2/projection/v1-to-v2.d.ts +21 -1
  209. package/dist/lib/v2/projection/v1-to-v2.js +18 -11
  210. package/dist/lib/v2/projection/v1-to-v2.mjs +19 -11
  211. package/dist/lib/version.d.mts +3 -3
  212. package/dist/lib/version.d.ts +3 -3
  213. package/dist/lib/version.js +3 -3
  214. package/dist/lib/version.mjs +3 -3
  215. package/docs/TYPE-SUMMARY.md +2 -2
  216. package/docs/guides/CREATIVE-DELIVERY.md +12 -0
  217. package/docs/guides/REPORTING-LEDGER.md +121 -0
  218. package/docs/guides/VALIDATE-YOUR-AGENT.md +1 -0
  219. package/docs/llms.txt +2 -2
  220. package/docs/migration-14.x-rc-worksheet.md +4 -4
  221. package/docs/migration-16-to-17.md +149 -0
  222. package/docs/migration-reporting-storage-package.md +10 -0
  223. package/package.json +106 -1
@@ -238,7 +238,10 @@ function parseCapabilitiesResponse(response) {
238
238
  propertyListFiltering: response.media_buy?.features?.property_list_filtering ?? false,
239
239
  contentStandards: response.media_buy?.features?.content_standards === true || declaresContentStandardsSpecialism,
240
240
  conversionTracking: response.media_buy?.features?.conversion_tracking ?? false,
241
- audienceTargeting: response.media_buy?.features?.audience_targeting ?? false
241
+ audienceTargeting: response.media_buy?.features?.audience_targeting ?? false,
242
+ ...typeof response.media_buy?.features?.creative_start_policy === "boolean" && {
243
+ creativeStartPolicy: response.media_buy.features.creative_start_policy
244
+ }
242
245
  };
243
246
  let account;
244
247
  if (response.account) {
@@ -425,8 +428,9 @@ const FEATURE_KEY_MAP = {
425
428
  content_standards: "contentStandards",
426
429
  conversion_tracking: "conversionTracking",
427
430
  audience_targeting: "audienceTargeting",
428
- audience_management: "audienceTargeting"
431
+ audience_management: "audienceTargeting",
429
432
  // legacy alias
433
+ creative_start_policy: "creativeStartPolicy"
430
434
  };
431
435
  function resolveFeature(capabilities, feature) {
432
436
  if (capabilities.protocols.includes(feature)) {
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Envelope-allowlist governance for AdCP error responses.
3
+ *
4
+ * Two orthogonal concerns both govern what round-trips on an AdCP error
5
+ * envelope. They live side-by-side here so that a change to one forces
6
+ * the reviewer to weigh the other (security review M4 on #788 — the
7
+ * pair is conceptually related and can drift in separate files).
8
+ *
9
+ * - `ERROR_ENVELOPE_FIELD_ALLOWLIST` governs keys that may appear as
10
+ * SIBLINGS of `adcp_error` on the wire response. Enforced by
11
+ * `wrapEnvelope` in `./wrap-envelope.ts`.
12
+ * - `ADCP_ERROR_FIELD_ALLOWLIST` governs keys that may appear INSIDE
13
+ * the `adcp_error` block, keyed by error code. Consumed by
14
+ * `adcpError()` (which filters its output to the allowlisted set)
15
+ * AND by the dispatcher in `create-adcp-server.ts` (re-applied to
16
+ * every handler-returned envelope via `sanitizeAdcpErrorEnvelope`
17
+ * — defence-in-depth for handlers that hand-roll an error envelope
18
+ * instead of going through the builder). The same set powers the
19
+ * `idempotency.conflict_no_payload_leak` invariant in
20
+ * `../testing/storyboard/default-invariants.ts`. The legacy
21
+ * `CONFLICT_ADCP_ERROR_ALLOWLIST` export is a convenience alias for
22
+ * the `IDEMPOTENCY_CONFLICT` entry.
23
+ *
24
+ * Both sets apply to the same wire response but at different nesting
25
+ * levels. A seller that needs to extend one should audit whether the
26
+ * other also needs updating.
27
+ *
28
+ * Hand-rolling an error envelope? Prefer `adcpError(code, options)` —
29
+ * it wraps both transport layers and applies this allowlist for you.
30
+ * The dispatcher sanitizer is a belt-and-suspenders, not a primary API.
31
+ */
32
+ /**
33
+ * Fail-closed default allowlist for unknown error codes.
34
+ *
35
+ * An error code without an explicit entry in
36
+ * `ERROR_ENVELOPE_FIELD_ALLOWLIST` gets this set — only `context`
37
+ * round-trips (matching the invariant that every allowlist permits
38
+ * correlation tracing). Sellers that want `replayed` or `operation_id`
39
+ * on a bespoke error code must register it explicitly.
40
+ *
41
+ * This is the fail-closed posture — sellers MUST opt in to any field
42
+ * they want on an error envelope, rather than inheriting success-path
43
+ * semantics by default. Security review M3 on #788.
44
+ */
45
+ export declare const DEFAULT_ERROR_ENVELOPE_FIELDS: ReadonlySet<string>;
46
+ /**
47
+ * Per-error-code envelope-field allowlist.
48
+ *
49
+ * A code listed here restricts which envelope fields `wrapEnvelope`
50
+ * will attach on top of the error's inner payload. Codes NOT listed
51
+ * here receive `DEFAULT_ERROR_ENVELOPE_FIELDS` (fail-closed —
52
+ * `context` only).
53
+ *
54
+ * `IDEMPOTENCY_CONFLICT` deliberately excludes `replayed`: the
55
+ * conflict path in `create-adcp-server.ts` builds its error via
56
+ * `finalize()`, which only echoes `context` and never calls
57
+ * `stampReplayed`. The framework's own behavior is preserved.
58
+ *
59
+ * **Invariant**: every allowlist set MUST include `'context'`.
60
+ * `ensureContextEcho` enforces this at module load so new error codes
61
+ * can't accidentally drop context echo (which sellers rely on for
62
+ * correlation tracing across both success and error paths).
63
+ */
64
+ export declare const ERROR_ENVELOPE_FIELD_ALLOWLIST: Readonly<Record<string, ReadonlySet<string>>>;
65
+ /**
66
+ * Per-error-code allowlist for keys permitted INSIDE the `adcp_error`
67
+ * block. The `adcpError()` builder consults this table and drops any
68
+ * field the caller passes that isn't allowlisted for the given code —
69
+ * the allowlist IS the contract for what a framework-emitted error may
70
+ * carry. Storyboard invariants enforce the same contract on the wire.
71
+ *
72
+ * A code without an explicit entry permits everything `adcpError()`
73
+ * would otherwise emit — the default case is pass-through. Sellers who
74
+ * want a bespoke code to be strict should register it here (or wrap
75
+ * `adcpError()` with their own sanitizer).
76
+ *
77
+ * **Scope warning for future contributors:** only register a code here
78
+ * if it belongs to the AdCP standard error vocabulary (`enums/error-code.json`).
79
+ * Per `core/error.json`, clients "MUST handle unknown codes gracefully
80
+ * by falling back to the recovery classification" — so dropping
81
+ * `recovery` on a vendor / non-standard code makes the response
82
+ * genuinely lossy for any buyer agent that doesn't have the code in
83
+ * its local vocabulary.
84
+ *
85
+ * `IDEMPOTENCY_CONFLICT` is narrow on purpose: a conflict response MUST
86
+ * NOT echo the prior request payload or cached response (stolen-key
87
+ * read oracle defence). Standard recovery metadata is allowed because it
88
+ * is normalized to the fixed classifier, not trusted as caller-provided
89
+ * prior request or cached response data.
90
+ * `retry_after` is excluded: no framework path currently emits it on conflict, and a seller
91
+ * that computed `retry_after = cached_entry_age` would leak the prior
92
+ * payload's creation time (a distinguisher between "key never seen" vs
93
+ * "key seen N seconds ago"). Retry hints belong on transient codes
94
+ * (`SERVICE_UNAVAILABLE`, `RATE_LIMITED`), not on a terminal conflict.
95
+ * `adcpError()` and the dispatcher sanitizer both enforce this.
96
+ */
97
+ export declare const ADCP_ERROR_FIELD_ALLOWLIST: Readonly<Record<string, ReadonlySet<string>>>;
98
+ /**
99
+ * Convenience alias for the `IDEMPOTENCY_CONFLICT` entry in
100
+ * {@link ADCP_ERROR_FIELD_ALLOWLIST}. Kept as a named export because
101
+ * the default `idempotency.conflict_no_payload_leak` invariant and a
102
+ * handful of consumer tests reach for it by name; new code should use
103
+ * `ADCP_ERROR_FIELD_ALLOWLIST.IDEMPOTENCY_CONFLICT` directly.
104
+ */
105
+ export declare const CONFLICT_ADCP_ERROR_ALLOWLIST: ReadonlySet<string>;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Envelope-allowlist governance for AdCP error responses.
3
+ *
4
+ * Two orthogonal concerns both govern what round-trips on an AdCP error
5
+ * envelope. They live side-by-side here so that a change to one forces
6
+ * the reviewer to weigh the other (security review M4 on #788 — the
7
+ * pair is conceptually related and can drift in separate files).
8
+ *
9
+ * - `ERROR_ENVELOPE_FIELD_ALLOWLIST` governs keys that may appear as
10
+ * SIBLINGS of `adcp_error` on the wire response. Enforced by
11
+ * `wrapEnvelope` in `./wrap-envelope.ts`.
12
+ * - `ADCP_ERROR_FIELD_ALLOWLIST` governs keys that may appear INSIDE
13
+ * the `adcp_error` block, keyed by error code. Consumed by
14
+ * `adcpError()` (which filters its output to the allowlisted set)
15
+ * AND by the dispatcher in `create-adcp-server.ts` (re-applied to
16
+ * every handler-returned envelope via `sanitizeAdcpErrorEnvelope`
17
+ * — defence-in-depth for handlers that hand-roll an error envelope
18
+ * instead of going through the builder). The same set powers the
19
+ * `idempotency.conflict_no_payload_leak` invariant in
20
+ * `../testing/storyboard/default-invariants.ts`. The legacy
21
+ * `CONFLICT_ADCP_ERROR_ALLOWLIST` export is a convenience alias for
22
+ * the `IDEMPOTENCY_CONFLICT` entry.
23
+ *
24
+ * Both sets apply to the same wire response but at different nesting
25
+ * levels. A seller that needs to extend one should audit whether the
26
+ * other also needs updating.
27
+ *
28
+ * Hand-rolling an error envelope? Prefer `adcpError(code, options)` —
29
+ * it wraps both transport layers and applies this allowlist for you.
30
+ * The dispatcher sanitizer is a belt-and-suspenders, not a primary API.
31
+ */
32
+ /**
33
+ * Fail-closed default allowlist for unknown error codes.
34
+ *
35
+ * An error code without an explicit entry in
36
+ * `ERROR_ENVELOPE_FIELD_ALLOWLIST` gets this set — only `context`
37
+ * round-trips (matching the invariant that every allowlist permits
38
+ * correlation tracing). Sellers that want `replayed` or `operation_id`
39
+ * on a bespoke error code must register it explicitly.
40
+ *
41
+ * This is the fail-closed posture — sellers MUST opt in to any field
42
+ * they want on an error envelope, rather than inheriting success-path
43
+ * semantics by default. Security review M3 on #788.
44
+ */
45
+ export declare const DEFAULT_ERROR_ENVELOPE_FIELDS: ReadonlySet<string>;
46
+ /**
47
+ * Per-error-code envelope-field allowlist.
48
+ *
49
+ * A code listed here restricts which envelope fields `wrapEnvelope`
50
+ * will attach on top of the error's inner payload. Codes NOT listed
51
+ * here receive `DEFAULT_ERROR_ENVELOPE_FIELDS` (fail-closed —
52
+ * `context` only).
53
+ *
54
+ * `IDEMPOTENCY_CONFLICT` deliberately excludes `replayed`: the
55
+ * conflict path in `create-adcp-server.ts` builds its error via
56
+ * `finalize()`, which only echoes `context` and never calls
57
+ * `stampReplayed`. The framework's own behavior is preserved.
58
+ *
59
+ * **Invariant**: every allowlist set MUST include `'context'`.
60
+ * `ensureContextEcho` enforces this at module load so new error codes
61
+ * can't accidentally drop context echo (which sellers rely on for
62
+ * correlation tracing across both success and error paths).
63
+ */
64
+ export declare const ERROR_ENVELOPE_FIELD_ALLOWLIST: Readonly<Record<string, ReadonlySet<string>>>;
65
+ /**
66
+ * Per-error-code allowlist for keys permitted INSIDE the `adcp_error`
67
+ * block. The `adcpError()` builder consults this table and drops any
68
+ * field the caller passes that isn't allowlisted for the given code —
69
+ * the allowlist IS the contract for what a framework-emitted error may
70
+ * carry. Storyboard invariants enforce the same contract on the wire.
71
+ *
72
+ * A code without an explicit entry permits everything `adcpError()`
73
+ * would otherwise emit — the default case is pass-through. Sellers who
74
+ * want a bespoke code to be strict should register it here (or wrap
75
+ * `adcpError()` with their own sanitizer).
76
+ *
77
+ * **Scope warning for future contributors:** only register a code here
78
+ * if it belongs to the AdCP standard error vocabulary (`enums/error-code.json`).
79
+ * Per `core/error.json`, clients "MUST handle unknown codes gracefully
80
+ * by falling back to the recovery classification" — so dropping
81
+ * `recovery` on a vendor / non-standard code makes the response
82
+ * genuinely lossy for any buyer agent that doesn't have the code in
83
+ * its local vocabulary.
84
+ *
85
+ * `IDEMPOTENCY_CONFLICT` is narrow on purpose: a conflict response MUST
86
+ * NOT echo the prior request payload or cached response (stolen-key
87
+ * read oracle defence). Standard recovery metadata is allowed because it
88
+ * is normalized to the fixed classifier, not trusted as caller-provided
89
+ * prior request or cached response data.
90
+ * `retry_after` is excluded: no framework path currently emits it on conflict, and a seller
91
+ * that computed `retry_after = cached_entry_age` would leak the prior
92
+ * payload's creation time (a distinguisher between "key never seen" vs
93
+ * "key seen N seconds ago"). Retry hints belong on transient codes
94
+ * (`SERVICE_UNAVAILABLE`, `RATE_LIMITED`), not on a terminal conflict.
95
+ * `adcpError()` and the dispatcher sanitizer both enforce this.
96
+ */
97
+ export declare const ADCP_ERROR_FIELD_ALLOWLIST: Readonly<Record<string, ReadonlySet<string>>>;
98
+ /**
99
+ * Convenience alias for the `IDEMPOTENCY_CONFLICT` entry in
100
+ * {@link ADCP_ERROR_FIELD_ALLOWLIST}. Kept as a named export because
101
+ * the default `idempotency.conflict_no_payload_leak` invariant and a
102
+ * handful of consumer tests reach for it by name; new code should use
103
+ * `ADCP_ERROR_FIELD_ALLOWLIST.IDEMPOTENCY_CONFLICT` directly.
104
+ */
105
+ export declare const CONFLICT_ADCP_ERROR_ALLOWLIST: ReadonlySet<string>;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var envelope_allowlist_exports = {};
20
+ __export(envelope_allowlist_exports, {
21
+ ADCP_ERROR_FIELD_ALLOWLIST: () => ADCP_ERROR_FIELD_ALLOWLIST,
22
+ CONFLICT_ADCP_ERROR_ALLOWLIST: () => CONFLICT_ADCP_ERROR_ALLOWLIST,
23
+ DEFAULT_ERROR_ENVELOPE_FIELDS: () => DEFAULT_ERROR_ENVELOPE_FIELDS,
24
+ ERROR_ENVELOPE_FIELD_ALLOWLIST: () => ERROR_ENVELOPE_FIELD_ALLOWLIST
25
+ });
26
+ module.exports = __toCommonJS(envelope_allowlist_exports);
27
+ const DEFAULT_ERROR_ENVELOPE_FIELDS = Object.freeze(/* @__PURE__ */ new Set(["context"]));
28
+ const ERROR_ENVELOPE_FIELD_ALLOWLIST = Object.freeze({
29
+ // Spec-defined: conflict is not a replay; `replayed` intentionally
30
+ // dropped. `operation_id` round-trips for async-op correlation.
31
+ IDEMPOTENCY_CONFLICT: /* @__PURE__ */ new Set(["context", "operation_id"]),
32
+ // A cached purge result is itself the durable outcome. Replays MUST be
33
+ // distinguishable without reopening the committed-resource lookup.
34
+ COMMITTED_RESOURCE_PURGED: /* @__PURE__ */ new Set(["context", "replayed"])
35
+ });
36
+ const ADCP_ERROR_FIELD_ALLOWLIST = Object.freeze({
37
+ IDEMPOTENCY_CONFLICT: /* @__PURE__ */ new Set([
38
+ "code",
39
+ "message",
40
+ "recovery",
41
+ "status",
42
+ "correlation_id",
43
+ "request_id",
44
+ "operation_id"
45
+ ]),
46
+ // `IDEMPOTENCY_IN_FLIGHT` (AdCP 3.1) carries `recovery: transient` plus a
47
+ // store-derived `retry_after` so transient-aware buyer SDKs can replay
48
+ // shortly. Allowlist registration is defense-in-depth — `adcpError()` at
49
+ // the in-flight call site only assembles framework-controlled keys today,
50
+ // but the registration forces any future caller that tries to attach
51
+ // payload fingerprints onto the in-flight envelope to land here in code
52
+ // review first.
53
+ IDEMPOTENCY_IN_FLIGHT: /* @__PURE__ */ new Set([
54
+ "code",
55
+ "message",
56
+ "recovery",
57
+ "retry_after",
58
+ "status",
59
+ "correlation_id",
60
+ "request_id",
61
+ "operation_id"
62
+ ])
63
+ });
64
+ const CONFLICT_ADCP_ERROR_ALLOWLIST = ADCP_ERROR_FIELD_ALLOWLIST.IDEMPOTENCY_CONFLICT;
65
+ function ensureContextEcho(allowlist) {
66
+ if (!DEFAULT_ERROR_ENVELOPE_FIELDS.has("context")) {
67
+ throw new Error(
68
+ "DEFAULT_ERROR_ENVELOPE_FIELDS must include 'context' so correlation ids can round-trip on error envelopes."
69
+ );
70
+ }
71
+ for (const [code, fields] of Object.entries(allowlist)) {
72
+ if (!fields.has("context")) {
73
+ throw new Error(
74
+ `ERROR_ENVELOPE_FIELD_ALLOWLIST['${code}'] is missing 'context'. Every error-code allowlist must include 'context' so correlation ids can round-trip on error envelopes.`
75
+ );
76
+ }
77
+ }
78
+ }
79
+ ensureContextEcho(ERROR_ENVELOPE_FIELD_ALLOWLIST);
80
+ function ensureCoreAdcpErrorFields(allowlist) {
81
+ for (const [code, fields] of Object.entries(allowlist)) {
82
+ for (const required of ["code", "message"]) {
83
+ if (!fields.has(required)) {
84
+ throw new Error(
85
+ `ADCP_ERROR_FIELD_ALLOWLIST['${code}'] is missing '${required}'. Every inside-adcp_error allowlist must include 'code' and 'message' \u2014 they are the only two required fields on the AdCP error schema.`
86
+ );
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ensureCoreAdcpErrorFields(ADCP_ERROR_FIELD_ALLOWLIST);
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ ADCP_ERROR_FIELD_ALLOWLIST,
95
+ CONFLICT_ADCP_ERROR_ALLOWLIST,
96
+ DEFAULT_ERROR_ENVELOPE_FIELDS,
97
+ ERROR_ENVELOPE_FIELD_ALLOWLIST
98
+ });
@@ -0,0 +1,71 @@
1
+ const DEFAULT_ERROR_ENVELOPE_FIELDS = Object.freeze(/* @__PURE__ */ new Set(["context"]));
2
+ const ERROR_ENVELOPE_FIELD_ALLOWLIST = Object.freeze({
3
+ // Spec-defined: conflict is not a replay; `replayed` intentionally
4
+ // dropped. `operation_id` round-trips for async-op correlation.
5
+ IDEMPOTENCY_CONFLICT: /* @__PURE__ */ new Set(["context", "operation_id"]),
6
+ // A cached purge result is itself the durable outcome. Replays MUST be
7
+ // distinguishable without reopening the committed-resource lookup.
8
+ COMMITTED_RESOURCE_PURGED: /* @__PURE__ */ new Set(["context", "replayed"])
9
+ });
10
+ const ADCP_ERROR_FIELD_ALLOWLIST = Object.freeze({
11
+ IDEMPOTENCY_CONFLICT: /* @__PURE__ */ new Set([
12
+ "code",
13
+ "message",
14
+ "recovery",
15
+ "status",
16
+ "correlation_id",
17
+ "request_id",
18
+ "operation_id"
19
+ ]),
20
+ // `IDEMPOTENCY_IN_FLIGHT` (AdCP 3.1) carries `recovery: transient` plus a
21
+ // store-derived `retry_after` so transient-aware buyer SDKs can replay
22
+ // shortly. Allowlist registration is defense-in-depth — `adcpError()` at
23
+ // the in-flight call site only assembles framework-controlled keys today,
24
+ // but the registration forces any future caller that tries to attach
25
+ // payload fingerprints onto the in-flight envelope to land here in code
26
+ // review first.
27
+ IDEMPOTENCY_IN_FLIGHT: /* @__PURE__ */ new Set([
28
+ "code",
29
+ "message",
30
+ "recovery",
31
+ "retry_after",
32
+ "status",
33
+ "correlation_id",
34
+ "request_id",
35
+ "operation_id"
36
+ ])
37
+ });
38
+ const CONFLICT_ADCP_ERROR_ALLOWLIST = ADCP_ERROR_FIELD_ALLOWLIST.IDEMPOTENCY_CONFLICT;
39
+ function ensureContextEcho(allowlist) {
40
+ if (!DEFAULT_ERROR_ENVELOPE_FIELDS.has("context")) {
41
+ throw new Error(
42
+ "DEFAULT_ERROR_ENVELOPE_FIELDS must include 'context' so correlation ids can round-trip on error envelopes."
43
+ );
44
+ }
45
+ for (const [code, fields] of Object.entries(allowlist)) {
46
+ if (!fields.has("context")) {
47
+ throw new Error(
48
+ `ERROR_ENVELOPE_FIELD_ALLOWLIST['${code}'] is missing 'context'. Every error-code allowlist must include 'context' so correlation ids can round-trip on error envelopes.`
49
+ );
50
+ }
51
+ }
52
+ }
53
+ ensureContextEcho(ERROR_ENVELOPE_FIELD_ALLOWLIST);
54
+ function ensureCoreAdcpErrorFields(allowlist) {
55
+ for (const [code, fields] of Object.entries(allowlist)) {
56
+ for (const required of ["code", "message"]) {
57
+ if (!fields.has(required)) {
58
+ throw new Error(
59
+ `ADCP_ERROR_FIELD_ALLOWLIST['${code}'] is missing '${required}'. Every inside-adcp_error allowlist must include 'code' and 'message' \u2014 they are the only two required fields on the AdCP error schema.`
60
+ );
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ensureCoreAdcpErrorFields(ADCP_ERROR_FIELD_ALLOWLIST);
66
+ export {
67
+ ADCP_ERROR_FIELD_ALLOWLIST,
68
+ CONFLICT_ADCP_ERROR_ALLOWLIST,
69
+ DEFAULT_ERROR_ENVELOPE_FIELDS,
70
+ ERROR_ENVELOPE_FIELD_ALLOWLIST
71
+ };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Security primitive for the `details` field on `AdcpError` and the
3
+ * `Error` wire row. Adopters fronting upstream platforms (GAM, Snap,
4
+ * retail-media APIs, internal billing systems) often want to surface
5
+ * upstream error context to buyers — but raw upstream errors carry
6
+ * credentials, PII, internal stack traces, request IDs that leak
7
+ * tenant identity, and other liability surfaces that MUST NOT cross
8
+ * the wire boundary.
9
+ *
10
+ * `pickSafeDetails(input, allowlist, opts?)` is an explicit-allowlist
11
+ * sanitizer: only keys in the allowlist survive, with optional caps
12
+ * on depth and serialized size. Returns `undefined` when the input is
13
+ * not a plain object or the allowlist filter produces an empty
14
+ * result, so callers can spread the return into an optional `details`
15
+ * field without polluting it with `{}`.
16
+ *
17
+ * Adopters should call this BEFORE constructing the `AdcpError` /
18
+ * wire `Error` row. The framework's `normalizeError` does NOT
19
+ * sanitize details — it shallow-copies whatever was passed.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { pickSafeDetails } from '@adcp/client/server';
24
+ *
25
+ * try {
26
+ * await gamClient.createOrder(req);
27
+ * } catch (upstreamErr) {
28
+ * throw new AdcpError('UPSTREAM_REJECTED', {
29
+ * recovery: 'transient',
30
+ * message: 'Ad server rejected the order',
31
+ * // Allowlist: only safe upstream fields cross the wire
32
+ * details: pickSafeDetails(upstreamErr, [
33
+ * 'http_status',
34
+ * 'request_id',
35
+ * 'gam_error_code',
36
+ * ]),
37
+ * });
38
+ * }
39
+ * ```
40
+ *
41
+ * @public
42
+ */
43
+ export interface PickSafeDetailsOptions {
44
+ /**
45
+ * Maximum nesting depth retained in the result. `undefined` keeps
46
+ * the input unchanged at any depth; values like `2` keep top-level
47
+ * + one nested level. Strings, numbers, booleans, and null are
48
+ * leaves; arrays and plain objects count as a level.
49
+ *
50
+ * Default: `2` — top-level + one nested level. Caps cardinality
51
+ * blast radius from accidentally-recursive upstream error objects.
52
+ */
53
+ maxDepth?: number;
54
+ /**
55
+ * Maximum serialized JSON byte size of the result (best-effort
56
+ * UTF-8 estimate via `JSON.stringify().length`). When the projected
57
+ * result exceeds this, returns `undefined` rather than truncating —
58
+ * adopters should choose a tighter allowlist if they hit the cap.
59
+ *
60
+ * Default: `2048` bytes. Wire envelopes shouldn't carry kilobytes
61
+ * of details; if you need that, ship via `publishStatusChange` or
62
+ * `task_registry.progress`.
63
+ */
64
+ maxSizeBytes?: number;
65
+ }
66
+ /**
67
+ * Filter `input` to keys named in `allowlist`, depth-capped and
68
+ * size-capped. Returns `undefined` when the result is empty or
69
+ * exceeds the size cap so callers can spread the value into an
70
+ * optional `details` field without polluting it.
71
+ *
72
+ * Properties NOT in the allowlist are dropped silently (no warning;
73
+ * the design assumes the allowlist is the contract). Nested objects
74
+ * are recursively filtered with the SAME allowlist — there is no
75
+ * per-key allowlist for nested fields. Adopters who need per-level
76
+ * filtering should call `pickSafeDetails` recursively on each
77
+ * nested value.
78
+ *
79
+ * Common-sense behaviors:
80
+ * - `null` / `undefined` / non-object input → `undefined`
81
+ * - Empty result after filtering → `undefined`
82
+ * - Arrays at the top level → `undefined` (use a wrapping object)
83
+ * - Functions and Symbols are dropped
84
+ * - Date / RegExp / Error / Map / Set are dropped (use a string
85
+ * allowlist of primitive fields, or pre-shape the input)
86
+ *
87
+ * @public
88
+ */
89
+ export declare function pickSafeDetails(input: unknown, allowlist: readonly string[], opts?: PickSafeDetailsOptions): Record<string, unknown> | undefined;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Security primitive for the `details` field on `AdcpError` and the
3
+ * `Error` wire row. Adopters fronting upstream platforms (GAM, Snap,
4
+ * retail-media APIs, internal billing systems) often want to surface
5
+ * upstream error context to buyers — but raw upstream errors carry
6
+ * credentials, PII, internal stack traces, request IDs that leak
7
+ * tenant identity, and other liability surfaces that MUST NOT cross
8
+ * the wire boundary.
9
+ *
10
+ * `pickSafeDetails(input, allowlist, opts?)` is an explicit-allowlist
11
+ * sanitizer: only keys in the allowlist survive, with optional caps
12
+ * on depth and serialized size. Returns `undefined` when the input is
13
+ * not a plain object or the allowlist filter produces an empty
14
+ * result, so callers can spread the return into an optional `details`
15
+ * field without polluting it with `{}`.
16
+ *
17
+ * Adopters should call this BEFORE constructing the `AdcpError` /
18
+ * wire `Error` row. The framework's `normalizeError` does NOT
19
+ * sanitize details — it shallow-copies whatever was passed.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { pickSafeDetails } from '@adcp/client/server';
24
+ *
25
+ * try {
26
+ * await gamClient.createOrder(req);
27
+ * } catch (upstreamErr) {
28
+ * throw new AdcpError('UPSTREAM_REJECTED', {
29
+ * recovery: 'transient',
30
+ * message: 'Ad server rejected the order',
31
+ * // Allowlist: only safe upstream fields cross the wire
32
+ * details: pickSafeDetails(upstreamErr, [
33
+ * 'http_status',
34
+ * 'request_id',
35
+ * 'gam_error_code',
36
+ * ]),
37
+ * });
38
+ * }
39
+ * ```
40
+ *
41
+ * @public
42
+ */
43
+ export interface PickSafeDetailsOptions {
44
+ /**
45
+ * Maximum nesting depth retained in the result. `undefined` keeps
46
+ * the input unchanged at any depth; values like `2` keep top-level
47
+ * + one nested level. Strings, numbers, booleans, and null are
48
+ * leaves; arrays and plain objects count as a level.
49
+ *
50
+ * Default: `2` — top-level + one nested level. Caps cardinality
51
+ * blast radius from accidentally-recursive upstream error objects.
52
+ */
53
+ maxDepth?: number;
54
+ /**
55
+ * Maximum serialized JSON byte size of the result (best-effort
56
+ * UTF-8 estimate via `JSON.stringify().length`). When the projected
57
+ * result exceeds this, returns `undefined` rather than truncating —
58
+ * adopters should choose a tighter allowlist if they hit the cap.
59
+ *
60
+ * Default: `2048` bytes. Wire envelopes shouldn't carry kilobytes
61
+ * of details; if you need that, ship via `publishStatusChange` or
62
+ * `task_registry.progress`.
63
+ */
64
+ maxSizeBytes?: number;
65
+ }
66
+ /**
67
+ * Filter `input` to keys named in `allowlist`, depth-capped and
68
+ * size-capped. Returns `undefined` when the result is empty or
69
+ * exceeds the size cap so callers can spread the value into an
70
+ * optional `details` field without polluting it.
71
+ *
72
+ * Properties NOT in the allowlist are dropped silently (no warning;
73
+ * the design assumes the allowlist is the contract). Nested objects
74
+ * are recursively filtered with the SAME allowlist — there is no
75
+ * per-key allowlist for nested fields. Adopters who need per-level
76
+ * filtering should call `pickSafeDetails` recursively on each
77
+ * nested value.
78
+ *
79
+ * Common-sense behaviors:
80
+ * - `null` / `undefined` / non-object input → `undefined`
81
+ * - Empty result after filtering → `undefined`
82
+ * - Arrays at the top level → `undefined` (use a wrapping object)
83
+ * - Functions and Symbols are dropped
84
+ * - Date / RegExp / Error / Map / Set are dropped (use a string
85
+ * allowlist of primitive fields, or pre-shape the input)
86
+ *
87
+ * @public
88
+ */
89
+ export declare function pickSafeDetails(input: unknown, allowlist: readonly string[], opts?: PickSafeDetailsOptions): Record<string, unknown> | undefined;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pick_safe_details_exports = {};
20
+ __export(pick_safe_details_exports, {
21
+ pickSafeDetails: () => pickSafeDetails
22
+ });
23
+ module.exports = __toCommonJS(pick_safe_details_exports);
24
+ const DEFAULT_OPTIONS = {
25
+ maxDepth: 2,
26
+ maxSizeBytes: 2048
27
+ };
28
+ function pickSafeDetails(input, allowlist, opts) {
29
+ if (!isPlainObject(input)) return void 0;
30
+ if (allowlist.length === 0) return void 0;
31
+ const maxDepth = opts?.maxDepth ?? DEFAULT_OPTIONS.maxDepth;
32
+ const maxSize = opts?.maxSizeBytes ?? DEFAULT_OPTIONS.maxSizeBytes;
33
+ const allowSet = new Set(allowlist);
34
+ const result = filterByAllowlist(input, allowSet, maxDepth);
35
+ if (result == null || Object.keys(result).length === 0) return void 0;
36
+ let serialized;
37
+ try {
38
+ serialized = JSON.stringify(result);
39
+ } catch {
40
+ return void 0;
41
+ }
42
+ if (serialized.length > maxSize) return void 0;
43
+ return result;
44
+ }
45
+ function filterByAllowlist(obj, allow, remainingDepth) {
46
+ const out = {};
47
+ for (const key of Object.keys(obj)) {
48
+ if (!allow.has(key)) continue;
49
+ const value = obj[key];
50
+ const safe = sanitizeValue(value, allow, remainingDepth - 1);
51
+ if (safe !== void 0) out[key] = safe;
52
+ }
53
+ return Object.keys(out).length === 0 ? null : out;
54
+ }
55
+ function sanitizeValue(value, allow, remainingDepth) {
56
+ if (value === null) return null;
57
+ const t = typeof value;
58
+ if (t === "string" || t === "number" || t === "boolean") return value;
59
+ if (t === "function" || t === "symbol" || t === "undefined" || t === "bigint") return void 0;
60
+ if (Array.isArray(value)) {
61
+ const mapped = value.map((v) => sanitizeValue(v, allow, remainingDepth));
62
+ return mapped.filter((v) => v !== void 0);
63
+ }
64
+ if (isPlainObject(value)) {
65
+ if (remainingDepth <= 0) return void 0;
66
+ const filtered = filterByAllowlist(value, allow, remainingDepth);
67
+ return filtered ?? void 0;
68
+ }
69
+ return void 0;
70
+ }
71
+ function isPlainObject(value) {
72
+ if (value === null || typeof value !== "object") return false;
73
+ if (Array.isArray(value)) return false;
74
+ const proto = Object.getPrototypeOf(value);
75
+ return proto === Object.prototype || proto === null;
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ pickSafeDetails
80
+ });