@adcp/sdk 14.0.0-rc.38 → 14.0.0-rc.39

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 (600) hide show
  1. package/bin/adcp-storyboard-summary.js +286 -0
  2. package/bin/adcp.js +221 -10
  3. package/dist/lib/conformance/schemaLoader.d.mts +1 -1
  4. package/dist/lib/conformance/schemaLoader.d.ts +1 -1
  5. package/dist/lib/core/AgentClient.d.mts +6 -1
  6. package/dist/lib/core/AgentClient.d.ts +6 -1
  7. package/dist/lib/core/AgentClient.js +9 -0
  8. package/dist/lib/core/AgentClient.mjs +9 -0
  9. package/dist/lib/core/ConversationTypes.d.mts +29 -0
  10. package/dist/lib/core/ConversationTypes.d.ts +29 -0
  11. package/dist/lib/core/SingleAgentClient.d.mts +3 -1
  12. package/dist/lib/core/SingleAgentClient.d.ts +3 -1
  13. package/dist/lib/core/SingleAgentClient.js +9 -1
  14. package/dist/lib/core/SingleAgentClient.mjs +9 -1
  15. package/dist/lib/core/TaskExecutor.d.mts +13 -1
  16. package/dist/lib/core/TaskExecutor.d.ts +13 -1
  17. package/dist/lib/core/TaskExecutor.js +216 -18
  18. package/dist/lib/core/TaskExecutor.mjs +216 -19
  19. package/dist/lib/index.d.mts +5 -2
  20. package/dist/lib/index.d.ts +5 -2
  21. package/dist/lib/index.js +10 -1
  22. package/dist/lib/index.mjs +10 -1
  23. package/dist/lib/media-buy/action-assessment.d.mts +77 -0
  24. package/dist/lib/media-buy/action-assessment.d.ts +77 -0
  25. package/dist/lib/media-buy/action-assessment.js +300 -0
  26. package/dist/lib/media-buy/action-assessment.mjs +284 -0
  27. package/dist/lib/media-buy/action-constraints.d.mts +9 -0
  28. package/dist/lib/media-buy/action-constraints.d.ts +9 -0
  29. package/dist/lib/media-buy/action-constraints.js +170 -0
  30. package/dist/lib/media-buy/action-constraints.mjs +146 -0
  31. package/dist/lib/media-buy/action-contracts.d.mts +40 -0
  32. package/dist/lib/media-buy/action-contracts.d.ts +40 -0
  33. package/dist/lib/media-buy/action-contracts.js +304 -0
  34. package/dist/lib/media-buy/action-contracts.mjs +267 -0
  35. package/dist/lib/media-buy/action-metadata.generated.d.mts +37 -0
  36. package/dist/lib/media-buy/action-metadata.generated.d.ts +37 -0
  37. package/dist/lib/media-buy/action-metadata.generated.js +128 -0
  38. package/dist/lib/media-buy/action-metadata.generated.mjs +101 -0
  39. package/dist/lib/media-buy/action-types.d.mts +106 -0
  40. package/dist/lib/media-buy/action-types.d.ts +106 -0
  41. package/dist/lib/{types/v3-1-beta/tools.generated.js → media-buy/action-types.js} +2 -2
  42. package/dist/lib/media-buy/actions.d.mts +6 -0
  43. package/dist/lib/media-buy/actions.d.ts +6 -0
  44. package/dist/lib/media-buy/actions.js +38 -0
  45. package/dist/lib/media-buy/actions.mjs +9 -0
  46. package/dist/lib/media-buy/available-actions.d.mts +2 -1
  47. package/dist/lib/media-buy/available-actions.d.ts +2 -1
  48. package/dist/lib/media-buy/available-actions.js +4 -3
  49. package/dist/lib/media-buy/available-actions.mjs +4 -3
  50. package/dist/lib/media-buy/compatibility.js +3 -0
  51. package/dist/lib/media-buy/compatibility.mjs +3 -0
  52. package/dist/lib/media-buy/index.d.mts +4 -0
  53. package/dist/lib/media-buy/index.d.ts +4 -0
  54. package/dist/lib/media-buy/index.js +3 -1
  55. package/dist/lib/media-buy/index.mjs +1 -0
  56. package/dist/lib/media-buy/legacy-action-ids.d.mts +1 -0
  57. package/dist/lib/media-buy/legacy-action-ids.d.ts +1 -0
  58. package/dist/lib/media-buy/legacy-action-ids.js +50 -0
  59. package/dist/lib/media-buy/legacy-action-ids.mjs +26 -0
  60. package/dist/lib/media-buy/mutations.d.mts +70 -0
  61. package/dist/lib/media-buy/mutations.d.ts +70 -0
  62. package/dist/lib/media-buy/mutations.js +525 -0
  63. package/dist/lib/media-buy/mutations.mjs +498 -0
  64. package/dist/lib/media-buy/preflight.d.mts +20 -69
  65. package/dist/lib/media-buy/preflight.d.ts +20 -69
  66. package/dist/lib/media-buy/preflight.js +100 -336
  67. package/dist/lib/media-buy/preflight.mjs +111 -333
  68. package/dist/lib/media-buy/targeting-input.d.mts +7 -4
  69. package/dist/lib/media-buy/targeting-input.d.ts +7 -4
  70. package/dist/lib/media-buy/types.d.mts +55 -7
  71. package/dist/lib/media-buy/types.d.ts +55 -7
  72. package/dist/lib/protocols/rawResponseCapture.d.mts +12 -0
  73. package/dist/lib/protocols/rawResponseCapture.d.ts +12 -0
  74. package/dist/lib/protocols/rawResponseCapture.js +33 -3
  75. package/dist/lib/protocols/rawResponseCapture.mjs +32 -3
  76. package/dist/lib/registry/types.generated.d.mts +377 -9
  77. package/dist/lib/registry/types.generated.d.ts +377 -9
  78. package/dist/lib/reporting/evidence.d.mts +1 -0
  79. package/dist/lib/reporting/evidence.d.ts +1 -0
  80. package/dist/lib/reporting/evidence.js +32 -3
  81. package/dist/lib/reporting/evidence.mjs +31 -3
  82. package/dist/lib/reporting/ledger/handler.d.mts +51 -1
  83. package/dist/lib/reporting/ledger/handler.d.ts +51 -1
  84. package/dist/lib/reporting/ledger/handler.js +306 -38
  85. package/dist/lib/reporting/ledger/handler.mjs +304 -37
  86. package/dist/lib/reporting/ledger/health.d.mts +12 -0
  87. package/dist/lib/reporting/ledger/health.d.ts +12 -0
  88. package/dist/lib/reporting/ledger/health.js +15 -2
  89. package/dist/lib/reporting/ledger/health.mjs +13 -1
  90. package/dist/lib/reporting/ledger/index.d.mts +3 -0
  91. package/dist/lib/reporting/ledger/index.d.ts +3 -0
  92. package/dist/lib/reporting/ledger/index.js +7 -1
  93. package/dist/lib/reporting/ledger/index.mjs +3 -0
  94. package/dist/lib/reporting/ledger/lifecycle.d.mts +31 -4
  95. package/dist/lib/reporting/ledger/lifecycle.d.ts +31 -4
  96. package/dist/lib/reporting/ledger/lifecycle.js +244 -37
  97. package/dist/lib/reporting/ledger/lifecycle.mjs +244 -37
  98. package/dist/lib/reporting/ledger/managed-postgres.d.mts +231 -0
  99. package/dist/lib/reporting/ledger/managed-postgres.d.ts +231 -0
  100. package/dist/lib/reporting/ledger/managed-postgres.js +1797 -0
  101. package/dist/lib/reporting/ledger/managed-postgres.mjs +1776 -0
  102. package/dist/lib/reporting/ledger/managed.d.mts +355 -0
  103. package/dist/lib/reporting/ledger/managed.d.ts +355 -0
  104. package/dist/lib/reporting/ledger/managed.js +661 -0
  105. package/dist/lib/reporting/ledger/managed.mjs +633 -0
  106. package/dist/lib/reporting/ledger/notification-activity.d.mts +222 -0
  107. package/dist/lib/reporting/ledger/notification-activity.d.ts +222 -0
  108. package/dist/lib/reporting/ledger/notification-activity.js +1139 -0
  109. package/dist/lib/reporting/ledger/notification-activity.mjs +1110 -0
  110. package/dist/lib/reporting/ledger/postgres.d.mts +161 -1
  111. package/dist/lib/reporting/ledger/postgres.d.ts +161 -1
  112. package/dist/lib/reporting/ledger/postgres.js +1153 -21
  113. package/dist/lib/reporting/ledger/postgres.mjs +1152 -21
  114. package/dist/lib/reporting/ledger/producer.d.mts +8 -0
  115. package/dist/lib/reporting/ledger/producer.d.ts +8 -0
  116. package/dist/lib/reporting/ledger/producer.js +146 -52
  117. package/dist/lib/reporting/ledger/producer.mjs +146 -51
  118. package/dist/lib/reporting/ledger/types.d.mts +358 -1
  119. package/dist/lib/reporting/ledger/types.d.ts +358 -1
  120. package/dist/lib/reporting/ledger/types.js +3 -0
  121. package/dist/lib/reporting/ledger/types.mjs +2 -0
  122. package/dist/lib/reporting/service/conformance.d.mts +35 -0
  123. package/dist/lib/reporting/service/conformance.d.ts +35 -0
  124. package/dist/lib/reporting/service/conformance.js +89 -0
  125. package/dist/lib/reporting/service/conformance.mjs +68 -0
  126. package/dist/lib/reporting/service/index.d.mts +182 -0
  127. package/dist/lib/reporting/service/index.d.ts +182 -0
  128. package/dist/lib/reporting/service/index.js +793 -0
  129. package/dist/lib/reporting/service/index.mjs +787 -0
  130. package/dist/lib/reporting/source/index.d.mts +2 -1
  131. package/dist/lib/reporting/source/index.d.ts +2 -1
  132. package/dist/lib/reporting/source/index.js +16 -3
  133. package/dist/lib/reporting/source/index.mjs +12 -1
  134. package/dist/lib/reporting/source/inline.d.mts +88 -1
  135. package/dist/lib/reporting/source/inline.d.ts +88 -1
  136. package/dist/lib/reporting/source/inline.js +1161 -163
  137. package/dist/lib/reporting/source/inline.mjs +1166 -163
  138. package/dist/lib/reporting/source/manifest.js +12 -7
  139. package/dist/lib/reporting/source/manifest.mjs +12 -7
  140. package/dist/lib/reporting/source/source.d.mts +26 -0
  141. package/dist/lib/reporting/source/source.d.ts +26 -0
  142. package/dist/lib/reporting/source/source.js +71 -2
  143. package/dist/lib/reporting/source/source.mjs +65 -1
  144. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  145. package/dist/lib/server/create-adcp-server.d.mts +18 -0
  146. package/dist/lib/server/create-adcp-server.d.ts +18 -0
  147. package/dist/lib/server/create-adcp-server.js +52 -2
  148. package/dist/lib/server/create-adcp-server.mjs +52 -2
  149. package/dist/lib/server/decisioning/account.d.mts +1 -1
  150. package/dist/lib/server/decisioning/account.d.ts +1 -1
  151. package/dist/lib/server/decisioning/index.d.mts +1 -0
  152. package/dist/lib/server/decisioning/index.d.ts +1 -0
  153. package/dist/lib/server/decisioning/platform.d.mts +3 -0
  154. package/dist/lib/server/decisioning/platform.d.ts +3 -0
  155. package/dist/lib/server/decisioning/runtime/from-platform.js +88 -10
  156. package/dist/lib/server/decisioning/runtime/from-platform.mjs +88 -10
  157. package/dist/lib/server/decisioning/specialisms/reporting.d.mts +38 -0
  158. package/dist/lib/server/decisioning/specialisms/reporting.d.ts +38 -0
  159. package/dist/lib/{types/v3-1-beta/index.js → server/decisioning/specialisms/reporting.js} +2 -8
  160. package/dist/lib/server/decisioning/specialisms/reporting.mjs +0 -0
  161. package/dist/lib/server/index.d.mts +4 -2
  162. package/dist/lib/server/index.d.ts +4 -2
  163. package/dist/lib/server/index.js +5 -0
  164. package/dist/lib/server/index.mjs +4 -0
  165. package/dist/lib/server/media-buy-action-resolver.d.mts +63 -0
  166. package/dist/lib/server/media-buy-action-resolver.d.ts +63 -0
  167. package/dist/lib/server/media-buy-action-resolver.js +297 -0
  168. package/dist/lib/server/media-buy-action-resolver.mjs +285 -0
  169. package/dist/lib/server/media-buy-actions.d.mts +7 -8
  170. package/dist/lib/server/media-buy-actions.d.ts +7 -8
  171. package/dist/lib/server/media-buy-actions.js +57 -14
  172. package/dist/lib/server/media-buy-actions.mjs +63 -14
  173. package/dist/lib/server/notification-subscriptions/index.d.mts +2 -2
  174. package/dist/lib/server/notification-subscriptions/index.d.ts +2 -2
  175. package/dist/lib/server/notification-subscriptions/index.js +2 -0
  176. package/dist/lib/server/notification-subscriptions/index.mjs +2 -0
  177. package/dist/lib/server/notification-subscriptions/postgres-runtime.d.mts +3 -1
  178. package/dist/lib/server/notification-subscriptions/postgres-runtime.d.ts +3 -1
  179. package/dist/lib/server/notification-subscriptions/postgres-runtime.js +1 -0
  180. package/dist/lib/server/notification-subscriptions/postgres-runtime.mjs +1 -0
  181. package/dist/lib/server/notification-subscriptions/runtime.d.mts +12 -1
  182. package/dist/lib/server/notification-subscriptions/runtime.d.ts +12 -1
  183. package/dist/lib/server/notification-subscriptions/runtime.js +102 -16
  184. package/dist/lib/server/notification-subscriptions/runtime.mjs +101 -16
  185. package/dist/lib/server/notification-subscriptions/types.d.mts +104 -1
  186. package/dist/lib/server/notification-subscriptions/types.d.ts +104 -1
  187. package/dist/lib/server/webhook-emitter.d.mts +40 -5
  188. package/dist/lib/server/webhook-emitter.d.ts +40 -5
  189. package/dist/lib/server/webhook-emitter.js +23 -12
  190. package/dist/lib/server/webhook-emitter.mjs +23 -12
  191. package/dist/lib/storage/interfaces.d.mts +14 -2
  192. package/dist/lib/storage/interfaces.d.ts +14 -2
  193. package/dist/lib/testing/compliance/comply.d.mts +9 -3
  194. package/dist/lib/testing/compliance/comply.d.ts +9 -3
  195. package/dist/lib/testing/compliance/comply.js +158 -3
  196. package/dist/lib/testing/compliance/comply.mjs +159 -4
  197. package/dist/lib/testing/compliance/storyboard-tracks.js +7 -5
  198. package/dist/lib/testing/compliance/storyboard-tracks.mjs +7 -5
  199. package/dist/lib/testing/compliance/summary.js +10 -1
  200. package/dist/lib/testing/compliance/summary.mjs +10 -1
  201. package/dist/lib/testing/index.d.mts +1 -1
  202. package/dist/lib/testing/index.d.ts +1 -1
  203. package/dist/lib/testing/index.js +2 -0
  204. package/dist/lib/testing/index.mjs +3 -1
  205. package/dist/lib/testing/storyboard/agent-routing.d.mts +12 -43
  206. package/dist/lib/testing/storyboard/agent-routing.d.ts +12 -43
  207. package/dist/lib/testing/storyboard/agent-routing.js +75 -13
  208. package/dist/lib/testing/storyboard/agent-routing.mjs +70 -12
  209. package/dist/lib/testing/storyboard/index.d.mts +1 -0
  210. package/dist/lib/testing/storyboard/index.d.ts +1 -0
  211. package/dist/lib/testing/storyboard/index.js +3 -0
  212. package/dist/lib/testing/storyboard/index.mjs +2 -0
  213. package/dist/lib/testing/storyboard/junit.d.mts +1 -1
  214. package/dist/lib/testing/storyboard/junit.d.ts +1 -1
  215. package/dist/lib/testing/storyboard/junit.js +21 -2
  216. package/dist/lib/testing/storyboard/junit.mjs +21 -2
  217. package/dist/lib/testing/storyboard/probes.d.mts +130 -0
  218. package/dist/lib/testing/storyboard/probes.d.ts +130 -0
  219. package/dist/lib/testing/storyboard/probes.js +682 -10
  220. package/dist/lib/testing/storyboard/probes.mjs +683 -3
  221. package/dist/lib/testing/storyboard/request-signing/builder.d.mts +16 -5
  222. package/dist/lib/testing/storyboard/request-signing/builder.d.ts +16 -5
  223. package/dist/lib/testing/storyboard/request-signing/grader.d.mts +44 -1
  224. package/dist/lib/testing/storyboard/request-signing/grader.d.ts +44 -1
  225. package/dist/lib/testing/storyboard/request-signing/grader.js +46 -22
  226. package/dist/lib/testing/storyboard/request-signing/grader.mjs +43 -21
  227. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.mts +86 -11
  228. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.ts +86 -11
  229. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js +119 -25
  230. package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs +117 -26
  231. package/dist/lib/testing/storyboard/request-signing/synthesize.js +22 -2
  232. package/dist/lib/testing/storyboard/request-signing/synthesize.mjs +22 -2
  233. package/dist/lib/testing/storyboard/runner.d.mts +103 -0
  234. package/dist/lib/testing/storyboard/runner.d.ts +103 -0
  235. package/dist/lib/testing/storyboard/runner.js +1090 -268
  236. package/dist/lib/testing/storyboard/runner.mjs +1096 -261
  237. package/dist/lib/testing/storyboard/seeding.d.mts +4 -1
  238. package/dist/lib/testing/storyboard/seeding.d.ts +4 -1
  239. package/dist/lib/testing/storyboard/seeding.js +55 -24
  240. package/dist/lib/testing/storyboard/seeding.mjs +55 -24
  241. package/dist/lib/testing/storyboard/test-kit.d.mts +37 -3
  242. package/dist/lib/testing/storyboard/test-kit.d.ts +37 -3
  243. package/dist/lib/testing/storyboard/test-kit.js +8 -2
  244. package/dist/lib/testing/storyboard/test-kit.mjs +7 -2
  245. package/dist/lib/testing/storyboard/types.d.mts +132 -10
  246. package/dist/lib/testing/storyboard/types.d.ts +132 -10
  247. package/dist/lib/testing/storyboard/types.js +17 -0
  248. package/dist/lib/testing/storyboard/types.mjs +16 -0
  249. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  250. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  251. package/dist/lib/testing/storyboard/validations.js +16 -0
  252. package/dist/lib/testing/storyboard/validations.mjs +16 -0
  253. package/dist/lib/testing/test-controller.d.mts +1 -1
  254. package/dist/lib/testing/test-controller.d.ts +1 -1
  255. package/dist/lib/types/buy-products.d.ts +71 -6
  256. package/dist/lib/types/control-media-buy.d.ts +25 -11
  257. package/dist/lib/types/core.generated.d.mts +69 -10
  258. package/dist/lib/types/core.generated.d.ts +69 -10
  259. package/dist/lib/types/create-media-buy.d.ts +71 -6
  260. package/dist/lib/types/forward-compat-error-codes.d.mts +7 -6
  261. package/dist/lib/types/forward-compat-error-codes.d.ts +7 -6
  262. package/dist/lib/types/index.d.mts +2 -2
  263. package/dist/lib/types/index.d.ts +2 -2
  264. package/dist/lib/types/schemas.generated.d.ts +8040 -8116
  265. package/dist/lib/types/schemas.generated.js +1074 -309
  266. package/dist/lib/types/schemas.generated.mjs +1068 -309
  267. package/dist/lib/types/tools.generated.d.mts +65 -6
  268. package/dist/lib/types/tools.generated.d.ts +65 -6
  269. package/dist/lib/types/update-media-buy.d.ts +71 -6
  270. package/dist/lib/utils/redact-secrets.d.mts +1 -1
  271. package/dist/lib/utils/redact-secrets.d.ts +1 -1
  272. package/dist/lib/utils/redact-secrets.js +1 -1
  273. package/dist/lib/utils/redact-secrets.mjs +1 -1
  274. package/dist/lib/v2/projection/cache-versions.d.mts +0 -1
  275. package/dist/lib/v2/projection/cache-versions.d.ts +0 -1
  276. package/dist/lib/v2/projection/cache-versions.js +1 -15
  277. package/dist/lib/v2/projection/cache-versions.mjs +1 -14
  278. package/dist/lib/v2/projection/canonical-properties.js +2 -2
  279. package/dist/lib/v2/projection/canonical-properties.mjs +3 -3
  280. package/dist/lib/v2/projection/registry.d.mts +1 -1
  281. package/dist/lib/v2/projection/registry.d.ts +1 -1
  282. package/dist/lib/v2/projection/registry.js +2 -2
  283. package/dist/lib/v2/projection/registry.mjs +3 -3
  284. package/dist/lib/version.d.mts +5 -5
  285. package/dist/lib/version.d.ts +5 -5
  286. package/dist/lib/version.js +3 -8
  287. package/dist/lib/version.mjs +3 -8
  288. package/dist/lib/wholesale-feed-sync/index.d.mts +1 -0
  289. package/dist/lib/wholesale-feed-sync/index.d.ts +1 -0
  290. package/dist/lib/wholesale-feed-sync/protocol-types.d.mts +42 -0
  291. package/dist/lib/wholesale-feed-sync/protocol-types.d.ts +42 -0
  292. package/dist/lib/wholesale-feed-sync/protocol-types.js +16 -0
  293. package/dist/lib/wholesale-feed-sync/protocol-types.mjs +0 -0
  294. package/dist/lib/wholesale-feed-sync/sync.d.mts +6 -6
  295. package/dist/lib/wholesale-feed-sync/sync.d.ts +6 -6
  296. package/dist/lib/wholesale-feed-sync/sync.js +3 -1
  297. package/dist/lib/wholesale-feed-sync/sync.mjs +3 -1
  298. package/dist/lib/wholesale-feed-sync/types.d.mts +15 -14
  299. package/dist/lib/wholesale-feed-sync/types.d.ts +15 -14
  300. package/dist/lib/wholesale-feed-sync/webhook-notification.d.mts +7 -5
  301. package/dist/lib/wholesale-feed-sync/webhook-notification.d.ts +7 -5
  302. package/dist/lib/wholesale-feed-sync/webhook-notification.js +45 -0
  303. package/dist/lib/wholesale-feed-sync/webhook-notification.mjs +44 -0
  304. package/docs/CLI.md +1 -1
  305. package/docs/TYPE-SUMMARY.md +118 -4
  306. package/docs/guides/ASYNC-API-REFERENCE.md +62 -1
  307. package/docs/guides/ASYNC-DEVELOPER-GUIDE.md +25 -0
  308. package/docs/guides/ASYNC-DOCUMENTATION-INDEX.md +3 -0
  309. package/docs/guides/BUYER-QUICKSTART-3.2.md +5 -0
  310. package/docs/guides/DURABLE-BUYER-WRITES.md +337 -0
  311. package/docs/guides/EXISTING-PLATFORM.md +35 -0
  312. package/docs/guides/MEDIA-BUY-3.2-COMPATIBILITY.md +7 -3
  313. package/docs/guides/MEDIA-BUY-ACTION-ASSESSMENT.md +300 -0
  314. package/docs/guides/REPORTING-LEDGER.md +654 -3
  315. package/docs/guides/REPORTING-SOURCE-EXECUTOR.md +63 -1
  316. package/docs/guides/SELLER-QUICKSTART-3.2.md +2 -0
  317. package/docs/guides/VALIDATE-YOUR-AGENT.md +35 -0
  318. package/docs/guides/idempotency-crash-recovery.md +4 -0
  319. package/docs/llms.txt +4 -2
  320. package/docs/migration-14.x-rc-worksheet.md +5 -5
  321. package/docs/migration-7.9-to-7.10.md +7 -5
  322. package/examples/README.md +17 -0
  323. package/examples/durable-buyer-writes/caller.ts +745 -0
  324. package/examples/durable-buyer-writes/worker.ts +240 -0
  325. package/examples/reliable-reporting-service/README.md +100 -0
  326. package/examples/seller-3.2-starter.ts +7 -8
  327. package/examples/targeting-input-existing-platform.ts +153 -0
  328. package/package.json +41 -29
  329. package/skills/build-seller-agent/specialisms/signed-requests.md +11 -1
  330. package/skills/cross-cutting.md +28 -11
  331. package/compliance/cache/3.1.0-beta.7/domains/brand/index.yaml +0 -160
  332. package/compliance/cache/3.1.0-beta.7/domains/brand/scenarios/distributed_brand_resolution.yaml +0 -415
  333. package/compliance/cache/3.1.0-beta.7/domains/brand/scenarios/single_side_trust_extension.yaml +0 -454
  334. package/compliance/cache/3.1.0-beta.7/domains/creative/index.yaml +0 -339
  335. package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/billing_out_of_band.yaml +0 -153
  336. package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/creative_lifecycle_webhooks.yaml +0 -389
  337. package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/native_in_feed.yaml +0 -543
  338. package/compliance/cache/3.1.0-beta.7/domains/governance/index.yaml +0 -682
  339. package/compliance/cache/3.1.0-beta.7/domains/media-buy/index.yaml +0 -781
  340. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/audience_buy_flow.yaml +0 -380
  341. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/available_actions.yaml +0 -565
  342. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/billing_finality_delivery.yaml +0 -354
  343. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/canonical_formats.yaml +0 -711
  344. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/clicks_buy_flow.yaml +0 -264
  345. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/completed_views_buy_flow.yaml +0 -344
  346. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/create_media_buy_async.yaml +0 -234
  347. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/creative_fate_after_cancellation.yaml +0 -419
  348. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/creative_reception.yaml +0 -247
  349. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/delivery_reporting.yaml +0 -357
  350. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/dependency_impairment.yaml +0 -633
  351. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/dependency_impairment_cardinality.yaml +0 -800
  352. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/event_dedup_flow.yaml +0 -399
  353. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/frequency_cap_enforcement.yaml +0 -309
  354. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_approved.yaml +0 -214
  355. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_conditions.yaml +0 -199
  356. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_denied.yaml +0 -204
  357. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_denied_recovery.yaml +0 -252
  358. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/invalid_transitions.yaml +0 -289
  359. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/inventory_list_no_match.yaml +0 -148
  360. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/inventory_list_targeting.yaml +0 -276
  361. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/measurement_accountability.yaml +0 -244
  362. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/measurement_terms_rejected.yaml +0 -203
  363. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/pending_creatives_to_start.yaml +0 -274
  364. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/per_creative_conversion_attribution.yaml +0 -500
  365. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/performance_buy_flow.yaml +0 -428
  366. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/performance_buy_flow_roas.yaml +0 -470
  367. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/product_signal_targeting.yaml +0 -373
  368. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_finalize.yaml +0 -399
  369. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_finalize_asap_timing.yaml +0 -264
  370. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_not_found_errors.yaml +0 -257
  371. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_audit_observation.yaml +0 -333
  372. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_enforcement.yaml +0 -517
  373. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_truth_of_claim.yaml +0 -294
  374. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/reach_buy_flow.yaml +0 -823
  375. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/refine_finalize_exclusivity.yaml +0 -360
  376. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/refine_products.yaml +0 -148
  377. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_accountability.yaml +0 -293
  378. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_catalog_precondition.yaml +0 -307
  379. package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_optimization_flow.yaml +0 -576
  380. package/compliance/cache/3.1.0-beta.7/domains/media-buy/state-machine.yaml +0 -442
  381. package/compliance/cache/3.1.0-beta.7/domains/signals/index.yaml +0 -266
  382. package/compliance/cache/3.1.0-beta.7/domains/sponsored-intelligence/index.yaml +0 -256
  383. package/compliance/cache/3.1.0-beta.7/index.json +0 -356
  384. package/compliance/cache/3.1.0-beta.7/protocols/brand/index.yaml +0 -160
  385. package/compliance/cache/3.1.0-beta.7/protocols/brand/scenarios/distributed_brand_resolution.yaml +0 -415
  386. package/compliance/cache/3.1.0-beta.7/protocols/brand/scenarios/single_side_trust_extension.yaml +0 -454
  387. package/compliance/cache/3.1.0-beta.7/protocols/creative/index.yaml +0 -339
  388. package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/billing_out_of_band.yaml +0 -153
  389. package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/creative_lifecycle_webhooks.yaml +0 -389
  390. package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/native_in_feed.yaml +0 -543
  391. package/compliance/cache/3.1.0-beta.7/protocols/governance/index.yaml +0 -682
  392. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/index.yaml +0 -781
  393. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/audience_buy_flow.yaml +0 -380
  394. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/available_actions.yaml +0 -565
  395. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/billing_finality_delivery.yaml +0 -354
  396. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/canonical_formats.yaml +0 -711
  397. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/clicks_buy_flow.yaml +0 -264
  398. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/completed_views_buy_flow.yaml +0 -344
  399. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/create_media_buy_async.yaml +0 -234
  400. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/creative_fate_after_cancellation.yaml +0 -419
  401. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/creative_reception.yaml +0 -247
  402. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/delivery_reporting.yaml +0 -357
  403. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/dependency_impairment.yaml +0 -633
  404. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/dependency_impairment_cardinality.yaml +0 -800
  405. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/event_dedup_flow.yaml +0 -399
  406. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/frequency_cap_enforcement.yaml +0 -309
  407. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_approved.yaml +0 -214
  408. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_conditions.yaml +0 -199
  409. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_denied.yaml +0 -204
  410. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_denied_recovery.yaml +0 -252
  411. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/invalid_transitions.yaml +0 -289
  412. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/inventory_list_no_match.yaml +0 -148
  413. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/inventory_list_targeting.yaml +0 -276
  414. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/measurement_accountability.yaml +0 -244
  415. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/measurement_terms_rejected.yaml +0 -203
  416. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/pending_creatives_to_start.yaml +0 -274
  417. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/per_creative_conversion_attribution.yaml +0 -500
  418. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/performance_buy_flow.yaml +0 -428
  419. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/performance_buy_flow_roas.yaml +0 -470
  420. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/product_signal_targeting.yaml +0 -373
  421. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_finalize.yaml +0 -399
  422. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_finalize_asap_timing.yaml +0 -264
  423. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_not_found_errors.yaml +0 -257
  424. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_audit_observation.yaml +0 -333
  425. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_enforcement.yaml +0 -517
  426. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_truth_of_claim.yaml +0 -294
  427. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/reach_buy_flow.yaml +0 -823
  428. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/refine_finalize_exclusivity.yaml +0 -360
  429. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/refine_products.yaml +0 -148
  430. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_accountability.yaml +0 -293
  431. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_catalog_precondition.yaml +0 -307
  432. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_optimization_flow.yaml +0 -576
  433. package/compliance/cache/3.1.0-beta.7/protocols/media-buy/state-machine.yaml +0 -442
  434. package/compliance/cache/3.1.0-beta.7/protocols/signals/index.yaml +0 -266
  435. package/compliance/cache/3.1.0-beta.7/protocols/sponsored-intelligence/index.yaml +0 -256
  436. package/compliance/cache/3.1.0-beta.7/specialisms/audience-sync/index.yaml +0 -313
  437. package/compliance/cache/3.1.0-beta.7/specialisms/brand-rights/index.yaml +0 -350
  438. package/compliance/cache/3.1.0-beta.7/specialisms/brand-rights/scenarios/governance_denied.yaml +0 -226
  439. package/compliance/cache/3.1.0-beta.7/specialisms/collection-lists/index.yaml +0 -359
  440. package/compliance/cache/3.1.0-beta.7/specialisms/content-standards/index.yaml +0 -572
  441. package/compliance/cache/3.1.0-beta.7/specialisms/creative-ad-server/index.yaml +0 -409
  442. package/compliance/cache/3.1.0-beta.7/specialisms/creative-generative/generative-seller.yaml +0 -807
  443. package/compliance/cache/3.1.0-beta.7/specialisms/creative-generative/index.yaml +0 -758
  444. package/compliance/cache/3.1.0-beta.7/specialisms/creative-template/index.yaml +0 -510
  445. package/compliance/cache/3.1.0-beta.7/specialisms/governance-aware-seller/index.yaml +0 -143
  446. package/compliance/cache/3.1.0-beta.7/specialisms/governance-aware-seller/scenarios/governance_multi_agent_rejected.yaml +0 -117
  447. package/compliance/cache/3.1.0-beta.7/specialisms/governance-delivery-monitor/index.yaml +0 -441
  448. package/compliance/cache/3.1.0-beta.7/specialisms/governance-spend-authority/denied.yaml +0 -221
  449. package/compliance/cache/3.1.0-beta.7/specialisms/governance-spend-authority/index.yaml +0 -330
  450. package/compliance/cache/3.1.0-beta.7/specialisms/property-lists/index.yaml +0 -482
  451. package/compliance/cache/3.1.0-beta.7/specialisms/sales-broadcast-tv/index.yaml +0 -738
  452. package/compliance/cache/3.1.0-beta.7/specialisms/sales-catalog-driven/index.yaml +0 -840
  453. package/compliance/cache/3.1.0-beta.7/specialisms/sales-guaranteed/index.yaml +0 -601
  454. package/compliance/cache/3.1.0-beta.7/specialisms/sales-non-guaranteed/index.yaml +0 -546
  455. package/compliance/cache/3.1.0-beta.7/specialisms/sales-proposal-mode/index.yaml +0 -586
  456. package/compliance/cache/3.1.0-beta.7/specialisms/sales-social/index.yaml +0 -919
  457. package/compliance/cache/3.1.0-beta.7/specialisms/signal-marketplace/index.yaml +0 -424
  458. package/compliance/cache/3.1.0-beta.7/specialisms/signal-marketplace/scenarios/governance_denied.yaml +0 -211
  459. package/compliance/cache/3.1.0-beta.7/specialisms/signal-owned/index.yaml +0 -317
  460. package/compliance/cache/3.1.0-beta.7/specialisms/sponsored-intelligence/index.yaml +0 -59
  461. package/compliance/cache/3.1.0-beta.7/test-kits/acme-outdoor-live.yaml +0 -78
  462. package/compliance/cache/3.1.0-beta.7/test-kits/acme-outdoor.yaml +0 -223
  463. package/compliance/cache/3.1.0-beta.7/test-kits/billing-gate-runner.yaml +0 -115
  464. package/compliance/cache/3.1.0-beta.7/test-kits/bistro-oranje.yaml +0 -126
  465. package/compliance/cache/3.1.0-beta.7/test-kits/distributed-brand-runner.yaml +0 -281
  466. package/compliance/cache/3.1.0-beta.7/test-kits/nova-motors.yaml +0 -262
  467. package/compliance/cache/3.1.0-beta.7/test-kits/osei-natural.yaml +0 -126
  468. package/compliance/cache/3.1.0-beta.7/test-kits/parallel-dispatch-runner.yaml +0 -196
  469. package/compliance/cache/3.1.0-beta.7/test-kits/rate-limit-trip-runner.yaml +0 -172
  470. package/compliance/cache/3.1.0-beta.7/test-kits/signed-requests-runner.yaml +0 -155
  471. package/compliance/cache/3.1.0-beta.7/test-kits/single-side-trust-runner.yaml +0 -294
  472. package/compliance/cache/3.1.0-beta.7/test-kits/substitution-observer-runner.yaml +0 -688
  473. package/compliance/cache/3.1.0-beta.7/test-kits/summit-foods.yaml +0 -125
  474. package/compliance/cache/3.1.0-beta.7/test-kits/webhook-receiver-runner.yaml +0 -265
  475. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/001-minimal-plan.json +0 -43
  476. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/002-full-plan.json +0 -217
  477. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/003-bookkeeping-stripped.json +0 -60
  478. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/004a-human-review-omitted.json +0 -43
  479. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/004b-human-review-explicit-null.json +0 -49
  480. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/005a-policy-categories-order-1.json +0 -53
  481. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/005b-policy-categories-order-2.json +0 -57
  482. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/006a-ext-trace-v1.json +0 -49
  483. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/006b-ext-trace-v2.json +0 -53
  484. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/007-unicode-objectives.json +0 -43
  485. package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/008-numeric-canonicalization.json +0 -65
  486. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/README.md +0 -220
  487. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/canonicalization.json +0 -241
  488. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/keys.json +0 -60
  489. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/001-no-signature-header.json +0 -24
  490. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/002-wrong-tag.json +0 -26
  491. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/003-expired-signature.json +0 -26
  492. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/004-window-too-long.json +0 -26
  493. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/005-alg-not-allowed.json +0 -26
  494. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/006-missing-covered-component.json +0 -26
  495. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/007-missing-content-digest.json +0 -26
  496. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/008-unknown-keyid.json +0 -26
  497. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/009-key-ops-missing-verify.json +0 -27
  498. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/010-content-digest-mismatch.json +0 -33
  499. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/011-malformed-header.json +0 -27
  500. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/012-missing-expires-param.json +0 -26
  501. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/013-expires-le-created.json +0 -27
  502. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/014-missing-nonce-param.json +0 -27
  503. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/015-signature-invalid.json +0 -28
  504. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/016-replayed-nonce.json +0 -35
  505. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/017-key-revoked.json +0 -38
  506. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/018-digest-covered-when-forbidden.json +0 -28
  507. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/019-signature-without-signature-input.json +0 -26
  508. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/020-rate-abuse.json +0 -34
  509. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/021-duplicate-signature-input-label.json +0 -31
  510. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/022-multi-valued-content-type.json +0 -31
  511. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/023-multi-valued-content-digest.json +0 -32
  512. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/024-unquoted-string-param.json +0 -31
  513. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/025-jwk-alg-crv-mismatch.json +0 -43
  514. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/026-non-ascii-host.json +0 -31
  515. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/027-webhook-registration-authentication-unsigned.json +0 -25
  516. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/028-unsigned-protocol-method-required.json +0 -26
  517. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/001-basic-post.json +0 -30
  518. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/002-post-with-content-digest.json +0 -31
  519. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/003-es256-post.json +0 -30
  520. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/004-multiple-signature-labels.json +0 -26
  521. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/005-default-port-stripped.json +0 -30
  522. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/006-dot-segment-path.json +0 -30
  523. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/007-query-byte-preserved.json +0 -30
  524. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/008-percent-encoded-path.json +0 -30
  525. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/009-percent-encoded-unreserved-decoded.json +0 -30
  526. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/010-percent-encoded-slash-preserved.json +0 -30
  527. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/011-ipv6-authority.json +0 -30
  528. package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/012-ipv6-authority-default-port-stripped.json +0 -30
  529. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/README.md +0 -211
  530. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/keys.json +0 -61
  531. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/001-wrong-tag.json +0 -26
  532. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/002-expired-signature.json +0 -26
  533. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/003-window-too-long.json +0 -26
  534. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/004-alg-not-allowed.json +0 -26
  535. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/005-missing-authority-component.json +0 -26
  536. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/006-missing-content-digest.json +0 -25
  537. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/007-unknown-keyid.json +0 -26
  538. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/008-wrong-adcp-use.json +0 -26
  539. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/009-content-digest-mismatch.json +0 -26
  540. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/010-malformed-signature-input.json +0 -26
  541. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/011-signature-without-input.json +0 -25
  542. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/012-missing-expires-param.json +0 -26
  543. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/013-expires-le-created.json +0 -26
  544. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/014-missing-nonce-param.json +0 -26
  545. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/015-signature-invalid.json +0 -26
  546. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/016-replayed-nonce.json +0 -37
  547. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/017-key-revoked.json +0 -32
  548. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/018-rate-abuse.json +0 -33
  549. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/019-revocation-stale.json +0 -32
  550. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/020-key-ops-missing-verify.json +0 -41
  551. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/021-base64-alphabet-mixing.json +0 -26
  552. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/001-basic-post.json +0 -24
  553. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/002-es256-post.json +0 -24
  554. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/003-multiple-signature-labels.json +0 -24
  555. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/004-default-port-stripped.json +0 -24
  556. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/005-percent-encoded-path.json +0 -24
  557. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/006-query-byte-preserved.json +0 -24
  558. package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/007-body-without-idempotency-key.json +0 -25
  559. package/compliance/cache/3.1.0-beta.7/universal/billing-gate-dispatch.yaml +0 -450
  560. package/compliance/cache/3.1.0-beta.7/universal/canonical-format-validate-input.yaml +0 -640
  561. package/compliance/cache/3.1.0-beta.7/universal/capability-discovery.yaml +0 -125
  562. package/compliance/cache/3.1.0-beta.7/universal/collection-lists-pagination-integrity.yaml +0 -306
  563. package/compliance/cache/3.1.0-beta.7/universal/comply-controller-mode-gate.yaml +0 -141
  564. package/compliance/cache/3.1.0-beta.7/universal/content-standards-pagination-integrity.yaml +0 -326
  565. package/compliance/cache/3.1.0-beta.7/universal/deterministic-testing.yaml +0 -1430
  566. package/compliance/cache/3.1.0-beta.7/universal/error-compliance-signals.yaml +0 -377
  567. package/compliance/cache/3.1.0-beta.7/universal/error-compliance.yaml +0 -528
  568. package/compliance/cache/3.1.0-beta.7/universal/fictional-entities.yaml +0 -307
  569. package/compliance/cache/3.1.0-beta.7/universal/get-media-buys-pagination-integrity.yaml +0 -160
  570. package/compliance/cache/3.1.0-beta.7/universal/get-signals-pagination-integrity.yaml +0 -211
  571. package/compliance/cache/3.1.0-beta.7/universal/idempotency.yaml +0 -861
  572. package/compliance/cache/3.1.0-beta.7/universal/notification-config-event-scope.yaml +0 -119
  573. package/compliance/cache/3.1.0-beta.7/universal/notification-config-lifecycle.yaml +0 -337
  574. package/compliance/cache/3.1.0-beta.7/universal/notification-config-rejections.yaml +0 -107
  575. package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity-creative-formats.yaml +0 -265
  576. package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity-list-accounts.yaml +0 -245
  577. package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity.yaml +0 -263
  578. package/compliance/cache/3.1.0-beta.7/universal/property-lists-pagination-integrity.yaml +0 -307
  579. package/compliance/cache/3.1.0-beta.7/universal/read-tool-idempotency.yaml +0 -405
  580. package/compliance/cache/3.1.0-beta.7/universal/runner-output-contract.yaml +0 -1266
  581. package/compliance/cache/3.1.0-beta.7/universal/schema-validation-signals.yaml +0 -181
  582. package/compliance/cache/3.1.0-beta.7/universal/schema-validation.yaml +0 -548
  583. package/compliance/cache/3.1.0-beta.7/universal/security.yaml +0 -539
  584. package/compliance/cache/3.1.0-beta.7/universal/signed-requests.yaml +0 -217
  585. package/compliance/cache/3.1.0-beta.7/universal/stale-response-advisory.yaml +0 -295
  586. package/compliance/cache/3.1.0-beta.7/universal/storyboard-schema.yaml +0 -2136
  587. package/compliance/cache/3.1.0-beta.7/universal/v3-envelope-integrity.yaml +0 -117
  588. package/compliance/cache/3.1.0-beta.7/universal/version-negotiation.yaml +0 -130
  589. package/compliance/cache/3.1.0-beta.7/universal/webhook-emission.yaml +0 -411
  590. package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-bulk-webhooks.yaml +0 -82
  591. package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-product-webhooks.yaml +0 -83
  592. package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-products.yaml +0 -151
  593. package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-signal-webhooks.yaml +0 -83
  594. package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-signals.yaml +0 -149
  595. package/dist/lib/types/v3-1-beta/index.d.mts +0 -1
  596. package/dist/lib/types/v3-1-beta/index.d.ts +0 -1
  597. package/dist/lib/types/v3-1-beta/index.mjs +0 -1
  598. package/dist/lib/types/v3-1-beta/tools.generated.d.mts +0 -26788
  599. package/dist/lib/types/v3-1-beta/tools.generated.d.ts +0 -26788
  600. /package/dist/lib/{types/v3-1-beta/tools.generated.mjs → media-buy/action-types.mjs} +0 -0
@@ -0,0 +1,1110 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { notificationSuppressionDisposition } from "../../server/notification-subscriptions/index.mjs";
3
+ import { canonicalJsonSha256 } from "../../utils/jcs.mjs";
4
+ const DEFAULT_TABLE = "adcp_reporting_notification_activity";
5
+ const REPORTING_STATUS_EVENT_TYPE = "reporting.status_changed";
6
+ const DEFAULT_NAMESPACE = "adcp-reporting";
7
+ const DEFAULT_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
8
+ const DEFAULT_MAX_PENDING_PER_TENANT = 1e5;
9
+ const DEFAULT_MAX_ATTEMPTS = 100;
10
+ const MAX_ACTIVITY_BYTES = 64 * 1024;
11
+ const MAX_CURSOR_BYTES = 16 * 1024;
12
+ class ReportingNotificationRetryableSuppressionError extends Error {
13
+ constructor(reason) {
14
+ super(`Reporting notification delivery authority failed closed (${reason}); no external attempt was made`);
15
+ this.reason = reason;
16
+ }
17
+ reason;
18
+ name = "ReportingNotificationRetryableSuppressionError";
19
+ }
20
+ const MAX_SUPPORTED_RECIPIENTS = 1e4;
21
+ const MAX_SUPPORTED_RETAINED_RECIPIENTS = 1e5;
22
+ const MAX_BTREE_ENTRY_BYTES = 2704;
23
+ const RECIPIENT_FINGERPRINT_BYTES = 64;
24
+ const RECIPIENT_ROUND_BYTES = 4;
25
+ const MAX_TRANSITION_ID_BYTES = 512;
26
+ const MAX_RECIPIENT_TABLE_BYTES = 53;
27
+ function getReportingNotificationActivityMigration(options = {}) {
28
+ const raw = options.tableName ?? DEFAULT_TABLE;
29
+ const table = quoteIdentifier(raw);
30
+ const rawRecipients = recipientTableName(raw);
31
+ const recipientTable = quoteIdentifier(rawRecipients, MAX_RECIPIENT_TABLE_BYTES);
32
+ return `
33
+ CREATE TABLE IF NOT EXISTS ${table} (
34
+ namespace TEXT NOT NULL,
35
+ transition_id TEXT NOT NULL,
36
+ activity_sequence BIGSERIAL NOT NULL UNIQUE,
37
+ tenant_scope TEXT NOT NULL,
38
+ account_id TEXT NOT NULL,
39
+ obligation_id TEXT NOT NULL,
40
+ activity JSONB NOT NULL,
41
+ intent_fingerprint TEXT NOT NULL,
42
+ state TEXT NOT NULL DEFAULT 'pending',
43
+ notification_required BOOLEAN NOT NULL,
44
+ attempt_count INTEGER NOT NULL DEFAULT 0,
45
+ next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
46
+ lease_owner TEXT,
47
+ lease_version BIGINT NOT NULL DEFAULT 0,
48
+ lease_expires_at TIMESTAMPTZ,
49
+ created_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
50
+ projected_at TIMESTAMPTZ,
51
+ retain_until TIMESTAMPTZ,
52
+ delivery_intent_at TIMESTAMPTZ,
53
+ abandoned_at TIMESTAMPTZ,
54
+ PRIMARY KEY (namespace, transition_id),
55
+ CONSTRAINT ${raw}_valid_state CHECK (state IN ('pending', 'projected', 'abandoned')),
56
+ CONSTRAINT ${raw}_valid_fingerprint CHECK (intent_fingerprint ~ '^[a-f0-9]{64}$'),
57
+ CONSTRAINT ${raw}_valid_activity CHECK (jsonb_typeof(activity) = 'object'),
58
+ CONSTRAINT ${raw}_valid_projection CHECK (
59
+ (state = 'pending' AND notification_required AND projected_at IS NULL AND retain_until IS NULL) OR
60
+ (state = 'projected' AND projected_at IS NOT NULL AND retain_until IS NOT NULL) OR
61
+ -- Abandoned: bounded out of the pending set without ever being recorded as
62
+ -- delivered, so it stops consuming tenant capacity but stays auditable.
63
+ (state = 'abandoned' AND projected_at IS NULL AND retain_until IS NOT NULL AND abandoned_at IS NOT NULL)
64
+ )
65
+ );
66
+
67
+ -- Upgrade in place, once, and touch nothing on a rerun.
68
+ --
69
+ -- Every statement here is guarded on the catalog, including the column adds:
70
+ -- \`ADD COLUMN IF NOT EXISTS\` still takes ACCESS EXCLUSIVE to discover the
71
+ -- column already exists, so a rerun during normal traffic blocks behind ordinary
72
+ -- readers and fails outright under a lock_timeout. An already-upgraded rerun now
73
+ -- issues no table-locking statement at all.
74
+ --
75
+ -- Every guard is scoped to this schema's table by resolving it once to a
76
+ -- regclass. A database-wide lookup by index name would see an upgraded index in
77
+ -- another schema and skip the upgrade here, leaving that deployment with a
78
+ -- projected-only retention index that cannot serve abandonment pruning.
79
+ DO $$
80
+ DECLARE
81
+ activity_table regclass := to_regclass('${raw}');
82
+ stale_index oid;
83
+ BEGIN
84
+ IF activity_table IS NULL THEN
85
+ RETURN;
86
+ END IF;
87
+ IF NOT EXISTS (
88
+ SELECT 1 FROM pg_attribute
89
+ WHERE attrelid = activity_table AND attname = 'delivery_intent_at' AND NOT attisdropped
90
+ ) THEN
91
+ ALTER TABLE ${table} ADD COLUMN delivery_intent_at TIMESTAMPTZ;
92
+ END IF;
93
+ IF NOT EXISTS (
94
+ SELECT 1 FROM pg_attribute
95
+ WHERE attrelid = activity_table AND attname = 'abandoned_at' AND NOT attisdropped
96
+ ) THEN
97
+ ALTER TABLE ${table} ADD COLUMN abandoned_at TIMESTAMPTZ;
98
+ END IF;
99
+ IF NOT EXISTS (
100
+ SELECT 1 FROM pg_constraint
101
+ WHERE conrelid = activity_table AND conname = '${raw}_valid_state'
102
+ AND pg_get_constraintdef(oid) LIKE '%abandoned%'
103
+ ) THEN
104
+ ALTER TABLE ${table} DROP CONSTRAINT IF EXISTS ${raw}_valid_state;
105
+ ALTER TABLE ${table} ADD CONSTRAINT ${raw}_valid_state
106
+ CHECK (state IN ('pending', 'projected', 'abandoned'));
107
+ END IF;
108
+ IF NOT EXISTS (
109
+ SELECT 1 FROM pg_constraint
110
+ WHERE conrelid = activity_table AND conname = '${raw}_valid_projection'
111
+ AND pg_get_constraintdef(oid) LIKE '%abandoned_at%'
112
+ ) THEN
113
+ ALTER TABLE ${table} DROP CONSTRAINT IF EXISTS ${raw}_valid_projection;
114
+ ALTER TABLE ${table} ADD CONSTRAINT ${raw}_valid_projection CHECK (
115
+ (state = 'pending' AND notification_required AND projected_at IS NULL AND retain_until IS NULL) OR
116
+ (state = 'projected' AND projected_at IS NOT NULL AND retain_until IS NOT NULL) OR
117
+ (state = 'abandoned' AND projected_at IS NULL AND retain_until IS NOT NULL AND abandoned_at IS NOT NULL)
118
+ );
119
+ END IF;
120
+ SELECT index_class.oid INTO stale_index
121
+ FROM pg_index
122
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
123
+ WHERE pg_index.indrelid = activity_table
124
+ AND index_class.relname = 'idx_${raw}_retention'
125
+ AND pg_get_indexdef(pg_index.indexrelid) NOT LIKE '%abandoned%';
126
+ IF stale_index IS NOT NULL THEN
127
+ EXECUTE format('DROP INDEX %s', stale_index::regclass);
128
+ END IF;
129
+ IF NOT EXISTS (
130
+ SELECT 1 FROM pg_index
131
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
132
+ WHERE pg_index.indrelid = activity_table AND index_class.relname = 'idx_${raw}_retention'
133
+ ) THEN
134
+ CREATE INDEX idx_${raw}_retention
135
+ ON ${table}(namespace, retain_until, activity_sequence)
136
+ WHERE state IN ('projected', 'abandoned');
137
+ END IF;
138
+ END $$;
139
+
140
+ -- One row per frozen recipient, carrying that recipient's own delivery state.
141
+ --
142
+ -- Relational rather than one serialized document: a document needs a size cap,
143
+ -- and a fanout that legitimately exceeded it could never be committed and would
144
+ -- retry until it aged out. Only the bounded 64-hex fingerprint enters the index,
145
+ -- so an individual recipient reference has no length limit of its own.
146
+ --
147
+ -- Per-recipient rather than per-emission: attempt_at is the durable pre-POST
148
+ -- checkpoint for exactly one recipient, so one recipient's attempt cannot pin a
149
+ -- sibling that was suppressed before its own first POST. Rows with no
150
+ -- attempt_at are revisable and replaced in place, so a pre-attempt retry can
151
+ -- never accumulate superseded state.
152
+ --
153
+ -- subscriber_key identifies the subscriber independently of its destination
154
+ -- generation. Pinning is per subscriber: once a subscriber has been addressed,
155
+ -- a later generation of the same subscriber is never addressed for this
156
+ -- notification, because that would be the same logical delivery under a new
157
+ -- idempotency key. A different subscriber is unaffected.
158
+ CREATE TABLE IF NOT EXISTS ${recipientTable} (
159
+ namespace TEXT NOT NULL,
160
+ transition_id TEXT NOT NULL,
161
+ recipient_fingerprint TEXT NOT NULL,
162
+ subscriber_key TEXT NOT NULL,
163
+ recipient JSONB NOT NULL,
164
+ frozen_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
165
+ attempt_at TIMESTAMPTZ,
166
+ settled_at TIMESTAMPTZ,
167
+ disposition TEXT,
168
+ PRIMARY KEY (namespace, transition_id, recipient_fingerprint),
169
+ CONSTRAINT ${rawRecipients}_fk FOREIGN KEY (namespace, transition_id)
170
+ REFERENCES ${table}(namespace, transition_id) ON DELETE CASCADE,
171
+ CONSTRAINT ${rawRecipients}_fp CHECK (recipient_fingerprint ~ '^[a-f0-9]{64}$'),
172
+ CONSTRAINT ${rawRecipients}_sk CHECK (subscriber_key ~ '^[a-f0-9]{64}$'),
173
+ CONSTRAINT ${rawRecipients}_obj CHECK (jsonb_typeof(recipient) = 'object'),
174
+ CONSTRAINT ${rawRecipients}_set CHECK (
175
+ (settled_at IS NULL AND disposition IS NULL) OR
176
+ (settled_at IS NOT NULL AND disposition IN ('delivered', 'terminal'))
177
+ )
178
+ );
179
+ -- Indexes are catalog-guarded too. CREATE INDEX IF NOT EXISTS still takes a
180
+ -- ShareLock to discover the index already exists, which conflicts with the
181
+ -- RowExclusiveLock every ordinary writer holds \u2014 so an already-current rerun
182
+ -- would stall live traffic, or fail under a lock_timeout, despite creating
183
+ -- nothing. Scoped to this schema's tables by regclass, like every other guard.
184
+ DO $$
185
+ DECLARE
186
+ activity_table regclass := to_regclass('${raw}');
187
+ recipient_table regclass := to_regclass('${rawRecipients}');
188
+ BEGIN
189
+ IF activity_table IS NULL OR recipient_table IS NULL THEN
190
+ RETURN;
191
+ END IF;
192
+ IF NOT EXISTS (
193
+ SELECT 1 FROM pg_index
194
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
195
+ WHERE pg_index.indrelid = recipient_table AND index_class.relname = 'idx_${rawRecipients}_unsettled'
196
+ ) THEN
197
+ CREATE INDEX idx_${rawRecipients}_unsettled
198
+ ON ${recipientTable}(namespace, transition_id)
199
+ WHERE settled_at IS NULL;
200
+ END IF;
201
+ -- At most one addressed generation per subscriber, enforced by the database.
202
+ --
203
+ -- The checkpoint and a concurrent recipient replacement run as separate
204
+ -- statements against a connection pool, so neither sees the other's
205
+ -- uncommitted work: a freeze can propose a replacement generation while the
206
+ -- original is being checkpointed, and PostgreSQL will keep both rows. This
207
+ -- index is the serialization point. The second generation's checkpoint fails,
208
+ -- so it is never POSTed, and the next freeze drops it because its subscriber
209
+ -- is already claimed. One logical delivery, one idempotency key.
210
+ IF NOT EXISTS (
211
+ SELECT 1 FROM pg_index
212
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
213
+ WHERE pg_index.indrelid = recipient_table
214
+ AND index_class.relname = 'idx_${rawRecipients}_attempted_subscriber'
215
+ ) THEN
216
+ CREATE UNIQUE INDEX idx_${rawRecipients}_attempted_subscriber
217
+ ON ${recipientTable}(namespace, transition_id, subscriber_key)
218
+ WHERE attempt_at IS NOT NULL;
219
+ END IF;
220
+ IF NOT EXISTS (
221
+ SELECT 1 FROM pg_index
222
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
223
+ WHERE pg_index.indrelid = activity_table AND index_class.relname = 'idx_${raw}_pending'
224
+ ) THEN
225
+ CREATE INDEX idx_${raw}_pending
226
+ ON ${table}(namespace, next_attempt_at, lease_expires_at, activity_sequence)
227
+ WHERE state = 'pending';
228
+ END IF;
229
+ IF NOT EXISTS (
230
+ SELECT 1 FROM pg_index
231
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
232
+ WHERE pg_index.indrelid = activity_table AND index_class.relname = 'idx_${raw}_pending_tenant'
233
+ ) THEN
234
+ CREATE INDEX idx_${raw}_pending_tenant
235
+ ON ${table}(namespace, tenant_scope)
236
+ WHERE state = 'pending';
237
+ END IF;
238
+ IF NOT EXISTS (
239
+ SELECT 1 FROM pg_index
240
+ JOIN pg_class index_class ON index_class.oid = pg_index.indexrelid
241
+ WHERE pg_index.indrelid = activity_table AND index_class.relname = 'idx_${raw}_account_activity'
242
+ ) THEN
243
+ CREATE INDEX idx_${raw}_account_activity
244
+ ON ${table}(namespace, tenant_scope, account_id, activity_sequence DESC);
245
+ END IF;
246
+ END $$;
247
+ `.trim();
248
+ }
249
+ function recipientTableName(tableName = DEFAULT_TABLE) {
250
+ return `${tableName}_recipients`;
251
+ }
252
+ const REPORTING_NOTIFICATION_ACTIVITY_MIGRATION = getReportingNotificationActivityMigration();
253
+ function createPostgresReportingNotificationAttemptCheckpoint(options) {
254
+ if (!options?.db || typeof options.db.query !== "function") {
255
+ throw new TypeError("createPostgresReportingNotificationAttemptCheckpoint requires a PostgreSQL queryable");
256
+ }
257
+ const namespace = options.namespace ?? DEFAULT_NAMESPACE;
258
+ assertIdentifier(namespace, "namespace", 255);
259
+ const rawTable = options.tableName ?? DEFAULT_TABLE;
260
+ const recipientTable = quoteIdentifier(recipientTableName(rawTable), MAX_RECIPIENT_TABLE_BYTES);
261
+ const owned = /* @__PURE__ */ new Set([REPORTING_STATUS_EVENT_TYPE, ...options.eventTypes ?? []]);
262
+ const checkpoint = async (input) => {
263
+ if (!owned.has(input.eventType)) return;
264
+ const fingerprint = recipientFingerprint({
265
+ scope: input.scope,
266
+ subscriberId: input.subscriberId,
267
+ destinationGeneration: input.destinationGeneration
268
+ });
269
+ const marked = await reportingActivityDatabaseOperation(
270
+ "Reporting notification delivery attempt could not be checkpointed",
271
+ () => options.db.query(
272
+ `UPDATE ${recipientTable} SET attempt_at = COALESCE(attempt_at, clock_timestamp())
273
+ WHERE namespace = $1 AND transition_id = $2 AND recipient_fingerprint = $3`,
274
+ [namespace, input.notificationId, fingerprint]
275
+ )
276
+ );
277
+ if (marked.rowCount !== 1) {
278
+ throw new Error(
279
+ "Reporting notification delivery attempt has no frozen recipient to checkpoint; the emission owner must freeze its recipient set before any external attempt"
280
+ );
281
+ }
282
+ };
283
+ return Object.assign(checkpoint, {
284
+ activityStore: Object.freeze({ db: options.db, namespace, tableName: rawTable })
285
+ });
286
+ }
287
+ function createPostgresReportingNotificationActivityRuntime(options) {
288
+ if (!options?.db || typeof options.db.query !== "function") {
289
+ throw new TypeError("createPostgresReportingNotificationActivityRuntime requires a PostgreSQL queryable");
290
+ }
291
+ if (!options.notifications || typeof options.notifications.emit !== "function") {
292
+ throw new TypeError(
293
+ "createPostgresReportingNotificationActivityRuntime requires the persistent notification runtime"
294
+ );
295
+ }
296
+ if (typeof options.tenantScopeForAccount !== "function") {
297
+ throw new TypeError("tenantScopeForAccount must be a function");
298
+ }
299
+ if (options.notifications.hasDeliveryAttemptCheckpoint !== true && !options.acknowledgeMissingAttemptCheckpoint) {
300
+ throw new TypeError(
301
+ "createPostgresReportingNotificationActivityRuntime requires a notification port that runs the durable pre-POST attempt checkpoint. Build createPostgresReportingNotificationAttemptCheckpoint() and pass it as checkpointDeliveryAttempt; a custom port must set hasDeliveryAttemptCheckpoint: true to prove it forwards the event it is given."
302
+ );
303
+ }
304
+ const namespace = options.namespace ?? DEFAULT_NAMESPACE;
305
+ if (!options.attemptCheckpoint && !options.acknowledgeMissingAttemptCheckpoint) {
306
+ throw new TypeError(
307
+ "createPostgresReportingNotificationActivityRuntime requires attemptCheckpoint: pass the very checkpoint wired into the notification runtime so its durable store can be verified against this one."
308
+ );
309
+ }
310
+ const wired = options.notifications.deliveryAttemptCheckpoint;
311
+ if (wired !== void 0 && options.attemptCheckpoint && wired !== options.attemptCheckpoint) {
312
+ throw new TypeError(
313
+ "createPostgresReportingNotificationActivityRuntime: the notification runtime invokes a different checkpoint than the one passed as attemptCheckpoint. Each can be correctly built and still target a different store, in which case every delivery checkpoints nothing and is abandoned undelivered. Pass the very object wired into checkpointDeliveryAttempt."
314
+ );
315
+ }
316
+ if (options.attemptCheckpoint && wired === void 0 && !options.attemptCheckpoint.activityStore) {
317
+ throw new TypeError(
318
+ "createPostgresReportingNotificationActivityRuntime: attemptCheckpoint declares no durable store and the notification port does not expose the checkpoint it invokes, so neither its identity nor its target can be verified. Build it with createPostgresReportingNotificationAttemptCheckpoint()."
319
+ );
320
+ }
321
+ if (options.attemptCheckpoint?.activityStore) {
322
+ const bound = options.attemptCheckpoint.activityStore;
323
+ const mismatch = bound.db !== options.db || bound.namespace !== namespace || bound.tableName !== (options.tableName ?? DEFAULT_TABLE);
324
+ if (mismatch) {
325
+ throw new TypeError(
326
+ `createPostgresReportingNotificationActivityRuntime: attemptCheckpoint is bound to a different durable store (namespace ${JSON.stringify(bound.namespace)}, table ${JSON.stringify(bound.tableName)}${bound.db === options.db ? "" : ", different queryable"}) than this runtime (namespace ${JSON.stringify(namespace)}, table ${JSON.stringify(options.tableName ?? DEFAULT_TABLE)}). A mismatched pair checkpoints nothing, so every delivery is suppressed until its binding retires and the notification is lost silently.`
327
+ );
328
+ }
329
+ }
330
+ const development = process.env.NODE_ENV === "test" || process.env.NODE_ENV === "development";
331
+ if (!development && options.namespace === void 0 && !options.acknowledgeIsolatedDatabase) {
332
+ throw new TypeError(
333
+ "Production reporting notification activity requires an explicit deployment namespace or acknowledgeIsolatedDatabase: true"
334
+ );
335
+ }
336
+ assertIdentifier(namespace, "namespace", 255);
337
+ const rawTable = options.tableName ?? DEFAULT_TABLE;
338
+ const table = quoteIdentifier(rawTable);
339
+ const retentionMs = options.retentionMs ?? DEFAULT_RETENTION_MS;
340
+ positiveInteger(retentionMs, "retentionMs");
341
+ const maxPendingPerTenant = options.maxPendingPerTenant ?? DEFAULT_MAX_PENDING_PER_TENANT;
342
+ boundedInteger(maxPendingPerTenant, "maxPendingPerTenant", 1, 1e6);
343
+ const maxRecipients = options.maxRecipients ?? MAX_SUPPORTED_RECIPIENTS;
344
+ boundedInteger(maxRecipients, "maxRecipients", 1, MAX_SUPPORTED_RECIPIENTS);
345
+ const maxRetainedRecipients = options.maxRetainedRecipients ?? maxRecipients * 2;
346
+ boundedInteger(maxRetainedRecipients, "maxRetainedRecipients", 1, MAX_SUPPORTED_RETAINED_RECIPIENTS);
347
+ if (maxRetainedRecipients < maxRecipients) {
348
+ throw new TypeError(
349
+ `maxRetainedRecipients ${maxRetainedRecipients} is below maxRecipients ${maxRecipients}; a full fanout could then never be retained and every claim at that size would abandon undelivered`
350
+ );
351
+ }
352
+ const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
353
+ boundedInteger(maxAttempts, "maxAttempts", 1, 1e5);
354
+ const recipientRawTable = recipientTableName(rawTable);
355
+ const recipientTable = quoteIdentifier(recipientRawTable, MAX_RECIPIENT_TABLE_BYTES);
356
+ const worstCaseIndexBytes = Buffer.byteLength(namespace, "utf8") + MAX_TRANSITION_ID_BYTES + RECIPIENT_ROUND_BYTES + RECIPIENT_FINGERPRINT_BYTES;
357
+ if (worstCaseIndexBytes > MAX_BTREE_ENTRY_BYTES) {
358
+ throw new TypeError(
359
+ `Reporting notification activity namespace is too long to index recipient intent (${worstCaseIndexBytes} of ${MAX_BTREE_ENTRY_BYTES} bytes); shorten namespace`
360
+ );
361
+ }
362
+ const port = {
363
+ async recordTransition(input, transaction) {
364
+ if (!transaction || typeof transaction.query !== "function") {
365
+ throw new TypeError("Reporting notification/activity persistence requires the active ledger transaction");
366
+ }
367
+ const accountId = input.obligation.account.account_id;
368
+ assertIdentifier(accountId, "accountId", 512);
369
+ assertIdentifier(input.transition.transitionId, "transitionId", MAX_TRANSITION_ID_BYTES);
370
+ const tenantId = options.tenantScopeForAccount(accountId);
371
+ if (isPromiseLike(tenantId)) {
372
+ throw new TypeError("tenantScopeForAccount must be synchronous and side-effect free");
373
+ }
374
+ assertIdentifier(tenantId, "tenantId", 512);
375
+ if (input.transition.reporting_obligation_id !== input.obligation.reporting_obligation_id) {
376
+ throw new Error("Reporting transition and authoritative obligation identities disagree");
377
+ }
378
+ const activity = buildActivity(namespace, tenantId, input.transition, input.obligation);
379
+ const notificationRequired = input.transition.previousHealth !== input.transition.health;
380
+ if (Buffer.byteLength(JSON.stringify(activity), "utf8") > MAX_ACTIVITY_BYTES) {
381
+ throw new RangeError("Reporting notification/activity intent exceeds 64 KiB");
382
+ }
383
+ const fingerprint = canonicalJsonSha256(activity);
384
+ if (notificationRequired) {
385
+ await reportingActivityDatabaseOperation("Reporting notification/activity capacity check failed", async () => {
386
+ await transaction.query("SELECT pg_advisory_xact_lock(hashtextextended($1, 0))", [
387
+ `adcp-reporting-activity-cap:${namespace}:${tenantId}`
388
+ ]);
389
+ const existing = await transaction.query(
390
+ `SELECT intent_fingerprint, tenant_scope, account_id, obligation_id
391
+ FROM ${table}
392
+ WHERE namespace = $1 AND transition_id = $2`,
393
+ [namespace, input.transition.transitionId]
394
+ );
395
+ const existingIntent = existing.rows[0];
396
+ if (existingIntent) {
397
+ if (existingIntent.intent_fingerprint !== fingerprint || existingIntent.tenant_scope !== tenantId || existingIntent.account_id !== accountId || existingIntent.obligation_id !== input.obligation.reporting_obligation_id) {
398
+ throw new Error("Reporting transition identity conflicts with existing notification/activity intent");
399
+ }
400
+ return;
401
+ }
402
+ const pending = await transaction.query(
403
+ `SELECT COUNT(*)::integer AS count FROM ${table}
404
+ WHERE namespace = $1 AND tenant_scope = $2 AND state = 'pending'`,
405
+ [namespace, tenantId]
406
+ );
407
+ if ((pending.rows[0]?.count ?? 0) >= maxPendingPerTenant) {
408
+ throw new Error("Reporting notification activity pending capacity reached; recovery must catch up");
409
+ }
410
+ });
411
+ }
412
+ let write;
413
+ try {
414
+ write = await transaction.query(
415
+ `INSERT INTO ${table} (
416
+ namespace, transition_id, tenant_scope, account_id, obligation_id,
417
+ activity, intent_fingerprint, notification_required, state,
418
+ projected_at, retain_until
419
+ ) VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7, $8,
420
+ CASE WHEN $8 THEN 'pending' ELSE 'projected' END,
421
+ CASE WHEN $8 THEN NULL ELSE clock_timestamp() END,
422
+ CASE WHEN $8 THEN NULL ELSE clock_timestamp() + ($9::bigint * INTERVAL '1 millisecond') END)
423
+ ON CONFLICT (namespace, transition_id) DO UPDATE SET
424
+ transition_id = EXCLUDED.transition_id
425
+ WHERE ${table}.intent_fingerprint = EXCLUDED.intent_fingerprint
426
+ AND ${table}.tenant_scope = EXCLUDED.tenant_scope
427
+ AND ${table}.account_id = EXCLUDED.account_id
428
+ AND ${table}.obligation_id = EXCLUDED.obligation_id
429
+ RETURNING transition_id`,
430
+ [
431
+ namespace,
432
+ input.transition.transitionId,
433
+ tenantId,
434
+ accountId,
435
+ input.obligation.reporting_obligation_id,
436
+ JSON.stringify(activity),
437
+ fingerprint,
438
+ notificationRequired,
439
+ retentionMs
440
+ ]
441
+ );
442
+ } catch (cause) {
443
+ if (isPostgresUndefinedTable(cause)) {
444
+ throw new Error(
445
+ "Reporting notification/activity persistence failed: run getReportingNotificationActivityMigration() before serving",
446
+ { cause }
447
+ );
448
+ }
449
+ throw new Error("Reporting notification/activity persistence failed", { cause });
450
+ }
451
+ if (write.rowCount !== 1) {
452
+ throw new Error("Reporting transition identity conflicts with existing notification/activity intent");
453
+ }
454
+ }
455
+ };
456
+ return {
457
+ port,
458
+ migrations: {
459
+ activity: getReportingNotificationActivityMigration({ tableName: rawTable }),
460
+ all: [getReportingNotificationActivityMigration({ tableName: rawTable })]
461
+ },
462
+ async probe() {
463
+ if (options.notifications.hasDeliveryAttemptCheckpoint !== true) {
464
+ throw new Error(
465
+ "Reporting notification/activity probe failed: the notification port does not prove it runs the durable pre-POST attempt checkpoint. Wire createPostgresReportingNotificationAttemptCheckpoint() into checkpointDeliveryAttempt, or set hasDeliveryAttemptCheckpoint: true on a custom port that forwards the event it is given."
466
+ );
467
+ }
468
+ try {
469
+ await options.db.query(
470
+ `SELECT namespace, transition_id, tenant_scope, account_id, obligation_id,
471
+ activity, intent_fingerprint, state, notification_required, lease_owner, lease_version,
472
+ lease_expires_at, projected_at, retain_until, delivery_intent_at, abandoned_at
473
+ FROM ${table} LIMIT 0`
474
+ );
475
+ await options.db.query(
476
+ `SELECT namespace, transition_id, recipient_fingerprint, recipient, frozen_at,
477
+ attempt_at, settled_at, disposition
478
+ FROM ${recipientTable} LIMIT 0`
479
+ );
480
+ } catch (cause) {
481
+ throw new Error(
482
+ "Reporting notification/activity probe failed: run getReportingNotificationActivityMigration() before serving",
483
+ { cause }
484
+ );
485
+ }
486
+ },
487
+ async recoverOnce(recoveryOptions = {}) {
488
+ const ownerToken = recoveryOptions.ownerToken ?? randomUUID();
489
+ assertIdentifier(ownerToken, "ownerToken", 255);
490
+ if (ownerToken.length < 8) throw new TypeError("ownerToken must contain at least 8 characters");
491
+ const leaseMs = recoveryOptions.leaseMs ?? 6e4;
492
+ const limit = recoveryOptions.limit ?? 50;
493
+ const retryAfterMs = recoveryOptions.retryAfterMs ?? 3e4;
494
+ boundedInteger(leaseMs, "leaseMs", 1e3, 3e5);
495
+ boundedInteger(limit, "limit", 1, 1e3);
496
+ boundedInteger(retryAfterMs, "retryAfterMs", 1, 6048e5);
497
+ const metrics = {
498
+ claimed: 0,
499
+ matched: 0,
500
+ projected: 0,
501
+ retried: 0,
502
+ leaseLost: 0,
503
+ abandoned: 0
504
+ };
505
+ for (let index = 0; index < limit; index += 1) {
506
+ const [claim] = await claimPending(options.db, table, namespace, ownerToken, leaseMs, 1);
507
+ if (!claim) break;
508
+ metrics.claimed += 1;
509
+ let leaseLost = false;
510
+ let renewing = false;
511
+ const heartbeat = setInterval(
512
+ () => {
513
+ if (renewing || leaseLost) return;
514
+ renewing = true;
515
+ void renewClaim(options.db, table, namespace, claim, leaseMs).then((renewed) => {
516
+ if (!renewed) leaseLost = true;
517
+ }).catch(() => {
518
+ leaseLost = true;
519
+ }).finally(() => {
520
+ renewing = false;
521
+ });
522
+ },
523
+ Math.max(250, Math.floor(leaseMs / 3))
524
+ );
525
+ heartbeat.unref?.();
526
+ try {
527
+ if (claim.activity.notificationType !== "reporting.status_changed") {
528
+ throw new Error("Pending reporting activity is not a health-transition notification");
529
+ }
530
+ let frozen = [];
531
+ let froze = false;
532
+ const result = await options.notifications.emit({
533
+ emissionId: claim.activity.activityId,
534
+ notificationId: claim.activity.transitionId,
535
+ notificationType: "reporting.status_changed",
536
+ anchor: "account",
537
+ tenantId: claim.tenantId,
538
+ accountId: claim.accountId,
539
+ payload: notificationPayload(claim.activity),
540
+ // Commit the recipient set under this lease before anything leaves
541
+ // the process. Each recipient is revisable until its own durable
542
+ // pre-POST checkpoint and pinned afterwards.
543
+ freezeRecipients: async (candidates) => {
544
+ froze = true;
545
+ frozen = await freezeClaimRecipients(
546
+ options.db,
547
+ table,
548
+ recipientTable,
549
+ namespace,
550
+ claim,
551
+ maxRecipients,
552
+ maxRetainedRecipients,
553
+ candidates
554
+ );
555
+ return frozen;
556
+ }
557
+ });
558
+ if (!froze) {
559
+ throw new Error(
560
+ "Reporting notification port did not freeze its recipient set; it must forward the emitted event, including freezeRecipients, to a runtime that honours it. Nothing was projected."
561
+ );
562
+ }
563
+ metrics.matched += result.matched;
564
+ const outcomes = result.deliveries.map((delivery) => classifyDelivery(delivery));
565
+ const settlement = await settleClaimRecipients(
566
+ options.db,
567
+ table,
568
+ recipientTable,
569
+ namespace,
570
+ claim,
571
+ frozen,
572
+ outcomes
573
+ );
574
+ if (!settlement.settled) {
575
+ const retryable = outcomes.find((outcome) => outcome.disposition === "retryable");
576
+ throw retryable?.suppression ? new ReportingNotificationRetryableSuppressionError(retryable.suppression) : new Error(
577
+ `Reporting notification delivery is not settled for ${settlement.unsettled} recipient(s); retrying`
578
+ );
579
+ }
580
+ const projected = !leaseLost && await projectClaim(options.db, table, namespace, claim, retentionMs);
581
+ if (projected) metrics.projected += 1;
582
+ else metrics.leaseLost += 1;
583
+ } catch (error) {
584
+ reportProjectionError(recoveryOptions.onError, error, claim);
585
+ if (!leaseLost && claim.attemptCount >= maxAttempts) {
586
+ const abandoned = await abandonClaim(options.db, table, namespace, claim, retentionMs);
587
+ if (abandoned) metrics.abandoned += 1;
588
+ else metrics.leaseLost += 1;
589
+ } else {
590
+ const released = !leaseLost && await releaseClaim(options.db, table, namespace, claim, retryAfterMs);
591
+ if (released) metrics.retried += 1;
592
+ else metrics.leaseLost += 1;
593
+ }
594
+ } finally {
595
+ clearInterval(heartbeat);
596
+ }
597
+ }
598
+ return metrics;
599
+ },
600
+ async listActivity(input) {
601
+ assertIdentifier(input.tenantId, "tenantId", 512);
602
+ assertIdentifier(input.accountId, "accountId", 512);
603
+ const expectedTenantId = options.tenantScopeForAccount(input.accountId);
604
+ if (isPromiseLike(expectedTenantId)) {
605
+ throw new TypeError("tenantScopeForAccount must be synchronous and side-effect free");
606
+ }
607
+ assertIdentifier(expectedTenantId, "tenantId", 512);
608
+ if (expectedTenantId !== input.tenantId) {
609
+ throw new TypeError("Reporting account activity scope does not match the trusted account directory");
610
+ }
611
+ const limit = input.limit ?? 100;
612
+ boundedInteger(limit, "limit", 1, 200);
613
+ const before = decodeCursor(input.cursor, namespace, input.tenantId, input.accountId);
614
+ const result = await reportingActivityDatabaseOperation(
615
+ "Reporting account activity read failed",
616
+ () => options.db.query(
617
+ `SELECT activity, state, created_at, projected_at, abandoned_at, activity_sequence
618
+ FROM ${table}
619
+ WHERE namespace = $1 AND tenant_scope = $2 AND account_id = $3
620
+ AND ($4::bigint IS NULL OR activity_sequence < $4)
621
+ ORDER BY activity_sequence DESC
622
+ LIMIT $5`,
623
+ [namespace, input.tenantId, input.accountId, before ?? null, limit + 1]
624
+ )
625
+ );
626
+ const selected = result.rows.slice(0, limit);
627
+ const activities = selected.map((row) => ({
628
+ ...structuredClone(row.activity),
629
+ recordedAt: asIso(row.created_at),
630
+ ...row.projected_at ? { notificationProjectedAt: asIso(row.projected_at) } : {},
631
+ ...row.abandoned_at ? { notificationAbandonedAt: asIso(row.abandoned_at) } : {}
632
+ }));
633
+ const hasMore = result.rows.length > limit;
634
+ return {
635
+ activities,
636
+ hasMore,
637
+ ...hasMore && selected.length > 0 ? {
638
+ nextCursor: encodeCursor(
639
+ namespace,
640
+ input.tenantId,
641
+ input.accountId,
642
+ String(selected[selected.length - 1].activity_sequence)
643
+ )
644
+ } : {}
645
+ };
646
+ },
647
+ async pruneProjected(pruneOptions = {}) {
648
+ const limit = pruneOptions.limit ?? 1e3;
649
+ boundedInteger(limit, "limit", 1, 1e4);
650
+ const result = await reportingActivityDatabaseOperation(
651
+ "Reporting account activity pruning failed",
652
+ () => options.db.query(
653
+ `WITH expired AS (
654
+ SELECT namespace, transition_id FROM ${table}
655
+ WHERE namespace = $1 AND state IN ('projected', 'abandoned')
656
+ AND retain_until <= clock_timestamp()
657
+ ORDER BY retain_until, activity_sequence
658
+ FOR UPDATE SKIP LOCKED LIMIT $2
659
+ )
660
+ DELETE FROM ${table} target USING expired
661
+ WHERE target.namespace = expired.namespace AND target.transition_id = expired.transition_id`,
662
+ [namespace, limit]
663
+ )
664
+ );
665
+ return result.rowCount ?? 0;
666
+ }
667
+ };
668
+ }
669
+ function buildActivity(namespace, tenantId, transition, obligation) {
670
+ const identity = canonicalJsonSha256({
671
+ namespace,
672
+ tenantId,
673
+ accountId: obligation.account.account_id,
674
+ transitionId: transition.transitionId
675
+ });
676
+ return {
677
+ activityId: `ract_${identity.slice(0, 32)}`,
678
+ transitionId: transition.transitionId,
679
+ activityType: "reporting.lifecycle_changed",
680
+ ...transition.previousHealth === transition.health ? {} : { notificationType: "reporting.status_changed" },
681
+ tenantId,
682
+ accountId: obligation.account.account_id,
683
+ reporting_obligation_id: obligation.reporting_obligation_id,
684
+ previousHealth: transition.previousHealth,
685
+ health: transition.health,
686
+ previousFinality: transition.previousFinality ?? "none",
687
+ finality: transition.finality ?? "none",
688
+ issueIds: [...transition.issueIds],
689
+ occurredAt: transition.occurredAt,
690
+ correlation: {
691
+ delivery_config_id: obligation.delivery_config_id,
692
+ delivery_config_version: obligation.delivery_config_version,
693
+ report_definition_id: obligation.report_definition_id,
694
+ feed_purpose: obligation.feedPurpose,
695
+ period: { start: obligation.period.start, end: obligation.period.end }
696
+ }
697
+ };
698
+ }
699
+ function notificationPayload(activity) {
700
+ return {
701
+ reporting_obligation_id: activity.reporting_obligation_id,
702
+ previous_health: activity.previousHealth,
703
+ health: activity.health,
704
+ issue_ids: [...activity.issueIds],
705
+ fired_at: activity.occurredAt,
706
+ delivery_config_id: activity.correlation.delivery_config_id,
707
+ delivery_config_version: activity.correlation.delivery_config_version,
708
+ feed_purpose: activity.correlation.feed_purpose
709
+ };
710
+ }
711
+ async function claimPending(db, table, namespace, ownerToken, leaseMs, limit) {
712
+ const result = await reportingActivityDatabaseOperation(
713
+ "Reporting notification recovery claim failed",
714
+ () => db.query(
715
+ `WITH candidates AS (
716
+ SELECT namespace, transition_id FROM ${table}
717
+ WHERE namespace = $1 AND state = 'pending' AND next_attempt_at <= clock_timestamp()
718
+ AND (lease_expires_at IS NULL OR lease_expires_at < clock_timestamp())
719
+ ORDER BY next_attempt_at, activity_sequence
720
+ FOR UPDATE SKIP LOCKED LIMIT $4
721
+ )
722
+ UPDATE ${table} target SET
723
+ lease_owner = $2,
724
+ lease_version = target.lease_version + 1,
725
+ lease_expires_at = clock_timestamp() + ($3::bigint * INTERVAL '1 millisecond'),
726
+ attempt_count = target.attempt_count + 1
727
+ FROM candidates
728
+ WHERE target.namespace = candidates.namespace AND target.transition_id = candidates.transition_id
729
+ RETURNING target.transition_id, target.tenant_scope, target.account_id,
730
+ target.activity, target.lease_version::text, target.attempt_count`,
731
+ [namespace, ownerToken, leaseMs, limit]
732
+ )
733
+ );
734
+ return result.rows.map((row) => ({
735
+ transitionId: row.transition_id,
736
+ tenantId: row.tenant_scope,
737
+ accountId: row.account_id,
738
+ activity: structuredClone(row.activity),
739
+ leaseOwner: ownerToken,
740
+ leaseVersion: row.lease_version,
741
+ attemptCount: row.attempt_count
742
+ }));
743
+ }
744
+ async function freezeClaimRecipients(db, table, recipientTable, namespace, claim, maxRecipients, maxRetainedRecipients, candidates) {
745
+ if (candidates.length > maxRecipients) {
746
+ throw new Error(
747
+ `Reporting notification fanout of ${candidates.length} recipients exceeds maxRecipients ${maxRecipients}; raise maxRecipients to at least the notification runtime maxFanoutCandidates`
748
+ );
749
+ }
750
+ const fenced = await reportingActivityDatabaseOperation(
751
+ "Reporting notification recipient intent could not be committed",
752
+ () => db.query(
753
+ `UPDATE ${table} SET delivery_intent_at = COALESCE(delivery_intent_at, clock_timestamp())
754
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
755
+ AND lease_owner = $3 AND lease_version = $4::bigint
756
+ AND lease_expires_at >= clock_timestamp()`,
757
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion]
758
+ )
759
+ );
760
+ if (fenced.rowCount !== 1) {
761
+ throw new Error("Reporting notification recipient intent was not committed; the recovery lease was lost");
762
+ }
763
+ const rows = canonicalRecipients(candidates);
764
+ await compactSettledRecipients(db, table, recipientTable, namespace, claim);
765
+ const committed = await reportingActivityDatabaseOperation(
766
+ "Reporting notification recipient intent could not be committed",
767
+ () => db.query(
768
+ `WITH leased AS MATERIALIZED (
769
+ -- The parent row is the serialization point, and MATERIALIZED makes
770
+ -- its lock the statement's first act. Reading the lease without
771
+ -- locking it only proved the lease was live when the snapshot was
772
+ -- taken: a statement that then blocked on a recipient lock could
773
+ -- resume long after a successor had claimed, still see its own lease
774
+ -- in the cached snapshot, and mutate the successor's rows. Holding
775
+ -- this lock means a takeover cannot complete while this statement
776
+ -- runs, and a statement that starts after one sees the new lease and
777
+ -- matches nothing.
778
+ SELECT transition_id FROM ${table}
779
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
780
+ AND lease_owner = $3 AND lease_version = $4::bigint
781
+ AND lease_expires_at >= clock_timestamp()
782
+ FOR UPDATE
783
+ ), existing AS (
784
+ -- FOR UPDATE is what serializes this statement against a concurrent
785
+ -- checkpoint. Without it the budget is computed from a snapshot in
786
+ -- which a row is still revisable, the DELETE then re-checks the
787
+ -- locked row, finds it attempted and skips it, and the retained set
788
+ -- lands one row above the budget that approved the write.
789
+ SELECT current.recipient_fingerprint, current.subscriber_key, current.recipient,
790
+ current.attempt_at, current.settled_at
791
+ FROM ${recipientTable} current, leased
792
+ WHERE current.namespace = $1 AND current.transition_id = $2
793
+ FOR UPDATE OF current
794
+ ), claimed AS (
795
+ SELECT subscriber_key FROM existing
796
+ WHERE attempt_at IS NOT NULL OR settled_at IS NOT NULL
797
+ ), proposed AS (
798
+ SELECT entry.fingerprint, entry.subscriber_key, entry.recipient::jsonb AS recipient
799
+ FROM leased, unnest($5::text[], $6::text[], $7::text[])
800
+ AS entry(fingerprint, subscriber_key, recipient)
801
+ WHERE NOT EXISTS (SELECT 1 FROM claimed WHERE claimed.subscriber_key = entry.subscriber_key)
802
+ ), budget AS (
803
+ SELECT
804
+ (SELECT count(*) FROM existing
805
+ WHERE attempt_at IS NOT NULL OR settled_at IS NOT NULL
806
+ OR recipient_fingerprint IN (SELECT fingerprint FROM proposed))
807
+ + (SELECT count(*) FROM proposed
808
+ WHERE fingerprint NOT IN (SELECT recipient_fingerprint FROM existing)) AS retained
809
+ ), gate AS (
810
+ -- The lease is part of the gate, not just of the row sources. A
811
+ -- stale worker sees an empty \`leased\`, which makes every source
812
+ -- empty and the budget zero; without this predicate the budget would
813
+ -- be satisfied and the delete below would reap the rows the
814
+ -- successor had already frozen under its own lease.
815
+ SELECT retained, retained <= $8::integer AND EXISTS (SELECT 1 FROM leased) AS ok FROM budget
816
+ ), dropped AS (
817
+ DELETE FROM ${recipientTable} stale USING gate, leased
818
+ WHERE gate.ok AND stale.namespace = $1 AND stale.transition_id = $2
819
+ AND stale.attempt_at IS NULL AND stale.settled_at IS NULL
820
+ AND NOT (stale.recipient_fingerprint IN (SELECT fingerprint FROM proposed))
821
+ ), added AS (
822
+ INSERT INTO ${recipientTable}
823
+ (namespace, transition_id, recipient_fingerprint, subscriber_key, recipient)
824
+ SELECT $1, $2, proposed.fingerprint, proposed.subscriber_key, proposed.recipient
825
+ FROM proposed, gate, leased WHERE gate.ok
826
+ ON CONFLICT (namespace, transition_id, recipient_fingerprint) DO NOTHING
827
+ ), pinned AS (
828
+ SELECT recipient FROM existing WHERE attempt_at IS NOT NULL AND settled_at IS NULL
829
+ )
830
+ SELECT (SELECT count(*) FROM leased) = 1 AS leased, gate.ok, gate.retained, entry.recipient
831
+ FROM gate
832
+ LEFT JOIN (SELECT recipient FROM proposed UNION ALL SELECT recipient FROM pinned) entry ON TRUE`,
833
+ [
834
+ namespace,
835
+ claim.transitionId,
836
+ claim.leaseOwner,
837
+ claim.leaseVersion,
838
+ rows.map((entry) => entry.fingerprint),
839
+ rows.map((entry) => entry.subscriberKey),
840
+ rows.map((entry) => JSON.stringify(entry.recipient)),
841
+ maxRetainedRecipients
842
+ ]
843
+ )
844
+ );
845
+ const verdict = committed.rows[0];
846
+ if (!verdict?.leased) {
847
+ throw new Error("Reporting notification recipient intent was not committed; the recovery lease was lost");
848
+ }
849
+ if (!verdict.ok) {
850
+ throw new Error(
851
+ `Reporting notification recipient intent would hold ${verdict.retained} recipients, above maxRetainedRecipients ${maxRetainedRecipients}; nothing was changed. Raise maxRetainedRecipients to at least the fanout plus the distinct subscribers this notification can replace, or reduce its destination churn`
852
+ );
853
+ }
854
+ return committed.rows.flatMap((row) => row.recipient === null ? [] : [row.recipient]);
855
+ }
856
+ async function settleClaimRecipients(db, table, recipientTable, namespace, claim, frozen, deliveries) {
857
+ const outcomes = new Map(deliveries.map((delivery) => [recipientFingerprint(delivery.recipient), delivery]));
858
+ const terminal = [];
859
+ const delivered = [];
860
+ for (const recipient of frozen) {
861
+ const fingerprint = recipientFingerprint(recipient);
862
+ const outcome = outcomes.get(fingerprint);
863
+ if (outcome === void 0) {
864
+ terminal.push(fingerprint);
865
+ continue;
866
+ }
867
+ if (outcome.disposition === "delivered") delivered.push(fingerprint);
868
+ else if (outcome.disposition === "terminal") terminal.push(fingerprint);
869
+ }
870
+ if (delivered.length > 0 || terminal.length > 0) {
871
+ await reportingActivityDatabaseOperation(
872
+ "Reporting notification recipient settlement failed",
873
+ () => db.query(
874
+ `WITH leased AS MATERIALIZED (
875
+ SELECT transition_id FROM ${table}
876
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
877
+ AND lease_owner = $5 AND lease_version = $6::bigint
878
+ AND lease_expires_at >= clock_timestamp()
879
+ FOR UPDATE
880
+ )
881
+ UPDATE ${recipientTable} AS target SET settled_at = clock_timestamp(),
882
+ disposition = CASE WHEN target.recipient_fingerprint = ANY($3::text[]) THEN 'delivered' ELSE 'terminal' END
883
+ FROM leased
884
+ WHERE target.namespace = $1 AND target.transition_id = $2 AND target.settled_at IS NULL
885
+ AND (target.recipient_fingerprint = ANY($3::text[]) OR target.recipient_fingerprint = ANY($4::text[]))`,
886
+ [namespace, claim.transitionId, delivered, terminal, claim.leaseOwner, claim.leaseVersion]
887
+ )
888
+ );
889
+ await compactSettledRecipients(db, table, recipientTable, namespace, claim);
890
+ }
891
+ const remaining = await reportingActivityDatabaseOperation(
892
+ "Reporting notification recipient settlement failed",
893
+ () => db.query(
894
+ `SELECT count(*)::integer AS unsettled FROM ${recipientTable}
895
+ WHERE namespace = $1 AND transition_id = $2 AND settled_at IS NULL`,
896
+ [namespace, claim.transitionId]
897
+ )
898
+ );
899
+ const unsettled = remaining.rows[0]?.unsettled ?? 0;
900
+ return { settled: unsettled === 0, unsettled };
901
+ }
902
+ async function compactSettledRecipients(db, table, recipientTable, namespace, claim) {
903
+ await reportingActivityDatabaseOperation(
904
+ "Reporting notification recipient compaction failed",
905
+ () => db.query(
906
+ `WITH leased AS MATERIALIZED (
907
+ SELECT transition_id FROM ${table}
908
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
909
+ AND lease_owner = $3 AND lease_version = $4::bigint
910
+ AND lease_expires_at >= clock_timestamp()
911
+ FOR UPDATE
912
+ )
913
+ DELETE FROM ${recipientTable} superseded USING leased
914
+ WHERE superseded.namespace = $1 AND superseded.transition_id = $2
915
+ AND superseded.settled_at IS NOT NULL
916
+ AND EXISTS (
917
+ SELECT 1 FROM ${recipientTable} survivor
918
+ WHERE survivor.namespace = superseded.namespace
919
+ AND survivor.transition_id = superseded.transition_id
920
+ AND survivor.subscriber_key = superseded.subscriber_key
921
+ AND survivor.settled_at IS NOT NULL
922
+ AND (survivor.disposition, survivor.recipient_fingerprint)
923
+ > (superseded.disposition, superseded.recipient_fingerprint)
924
+ )`,
925
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion]
926
+ )
927
+ );
928
+ }
929
+ function classifyDelivery(delivery) {
930
+ const recipient = {
931
+ scope: delivery.scope,
932
+ subscriberId: delivery.subscriberId,
933
+ destinationGeneration: delivery.destinationGeneration
934
+ };
935
+ if (delivery.failure !== void 0 || !delivery.result) {
936
+ return { recipient, disposition: delivery.failure?.terminal === true ? "terminal" : "retryable" };
937
+ }
938
+ const suppression = delivery.result.suppression;
939
+ if (suppression) {
940
+ return {
941
+ recipient,
942
+ disposition: notificationSuppressionDisposition(suppression.reason) === "retryable" ? "retryable" : "terminal",
943
+ suppression: suppression.reason
944
+ };
945
+ }
946
+ if (delivery.result.delivered) return { recipient, disposition: "delivered" };
947
+ return { recipient, disposition: delivery.result.terminal === true ? "terminal" : "retryable" };
948
+ }
949
+ function recipientFingerprint(recipient) {
950
+ return canonicalJsonSha256({
951
+ scope: recipient.scope,
952
+ subscriberId: recipient.subscriberId,
953
+ destinationGeneration: recipient.destinationGeneration
954
+ });
955
+ }
956
+ function canonicalRecipients(candidates) {
957
+ return candidates.map((candidate) => {
958
+ const recipient = {
959
+ scope: candidate.scope,
960
+ subscriberId: candidate.subscriberId,
961
+ destinationGeneration: candidate.destinationGeneration
962
+ };
963
+ return {
964
+ fingerprint: recipientFingerprint(recipient),
965
+ subscriberKey: subscriberKey(recipient),
966
+ recipient
967
+ };
968
+ }).sort((left, right) => left.fingerprint < right.fingerprint ? -1 : 1);
969
+ }
970
+ function subscriberKey(recipient) {
971
+ return canonicalJsonSha256({ scope: recipient.scope, subscriberId: recipient.subscriberId });
972
+ }
973
+ async function renewClaim(db, table, namespace, claim, leaseMs) {
974
+ const result = await reportingActivityDatabaseOperation(
975
+ "Reporting notification lease renewal failed",
976
+ () => db.query(
977
+ `UPDATE ${table} SET lease_expires_at = clock_timestamp() + ($5::bigint * INTERVAL '1 millisecond')
978
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
979
+ AND lease_owner = $3 AND lease_version = $4::bigint
980
+ AND lease_expires_at >= clock_timestamp()`,
981
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion, leaseMs]
982
+ )
983
+ );
984
+ return result.rowCount === 1;
985
+ }
986
+ async function projectClaim(db, table, namespace, claim, retentionMs) {
987
+ const result = await reportingActivityDatabaseOperation(
988
+ "Reporting notification projection settlement failed",
989
+ () => db.query(
990
+ `UPDATE ${table} SET state = 'projected', projected_at = clock_timestamp(),
991
+ retain_until = clock_timestamp() + ($5::bigint * INTERVAL '1 millisecond'),
992
+ lease_owner = NULL, lease_expires_at = NULL
993
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
994
+ AND lease_owner = $3 AND lease_version = $4::bigint
995
+ AND lease_expires_at >= clock_timestamp()`,
996
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion, retentionMs]
997
+ )
998
+ );
999
+ return result.rowCount === 1;
1000
+ }
1001
+ async function releaseClaim(db, table, namespace, claim, retryAfterMs) {
1002
+ const result = await reportingActivityDatabaseOperation(
1003
+ "Reporting notification lease release failed",
1004
+ () => db.query(
1005
+ `UPDATE ${table} SET lease_owner = NULL, lease_expires_at = NULL,
1006
+ next_attempt_at = clock_timestamp() + ($5::bigint * INTERVAL '1 millisecond')
1007
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
1008
+ AND lease_owner = $3 AND lease_version = $4::bigint
1009
+ AND lease_expires_at >= clock_timestamp()`,
1010
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion, retryAfterMs]
1011
+ )
1012
+ );
1013
+ return result.rowCount === 1;
1014
+ }
1015
+ async function abandonClaim(db, table, namespace, claim, retentionMs) {
1016
+ const result = await reportingActivityDatabaseOperation(
1017
+ "Reporting notification abandonment failed",
1018
+ () => db.query(
1019
+ `UPDATE ${table} SET state = 'abandoned',
1020
+ abandoned_at = clock_timestamp(),
1021
+ retain_until = clock_timestamp() + ($5::bigint * INTERVAL '1 millisecond'),
1022
+ lease_owner = NULL, lease_expires_at = NULL
1023
+ WHERE namespace = $1 AND transition_id = $2 AND state = 'pending'
1024
+ AND lease_owner = $3 AND lease_version = $4::bigint
1025
+ AND lease_expires_at >= clock_timestamp()`,
1026
+ [namespace, claim.transitionId, claim.leaseOwner, claim.leaseVersion, retentionMs]
1027
+ )
1028
+ );
1029
+ return result.rowCount === 1;
1030
+ }
1031
+ function encodeCursor(namespace, tenantId, accountId, before) {
1032
+ const cursor = `ract1.${Buffer.from(JSON.stringify({ namespace, tenantId, accountId, before })).toString("base64url")}`;
1033
+ if (Buffer.byteLength(cursor, "utf8") > MAX_CURSOR_BYTES) {
1034
+ throw new Error("Reporting account activity cursor exceeds its internal bound");
1035
+ }
1036
+ return cursor;
1037
+ }
1038
+ function decodeCursor(cursor, namespace, tenantId, accountId) {
1039
+ if (cursor === void 0) return void 0;
1040
+ try {
1041
+ if (Buffer.byteLength(cursor, "utf8") > MAX_CURSOR_BYTES) throw new Error();
1042
+ if (!cursor.startsWith("ract1.")) throw new Error();
1043
+ const value = JSON.parse(Buffer.from(cursor.slice(6), "base64url").toString("utf8"));
1044
+ if (value.namespace !== namespace || value.tenantId !== tenantId || value.accountId !== accountId || typeof value.before !== "string" || !/^[1-9][0-9]*$/.test(value.before)) {
1045
+ throw new Error();
1046
+ }
1047
+ if (BigInt(value.before) > 9223372036854775807n) throw new Error();
1048
+ return value.before;
1049
+ } catch {
1050
+ throw new TypeError("Reporting account activity cursor is invalid for the authenticated scope");
1051
+ }
1052
+ }
1053
+ function quoteIdentifier(value, maxBytes = 42) {
1054
+ if (!/^[a-z_][a-z0-9_]*$/.test(value) || Buffer.byteLength(value, "utf8") > maxBytes) {
1055
+ throw new TypeError(
1056
+ `Invalid reporting activity table name ${JSON.stringify(value)}: use at most ${maxBytes} lowercase characters`
1057
+ );
1058
+ }
1059
+ return `"${value}"`;
1060
+ }
1061
+ function assertIdentifier(value, name, maxBytes) {
1062
+ if (typeof value !== "string" || value.length === 0 || value.includes("\0") || Buffer.byteLength(value) > maxBytes) {
1063
+ throw new TypeError(`${name} must be a non-empty UTF-8 string of at most ${maxBytes} bytes without NUL`);
1064
+ }
1065
+ }
1066
+ function positiveInteger(value, name) {
1067
+ if (!Number.isSafeInteger(value) || value < 1) throw new TypeError(`${name} must be a positive safe integer`);
1068
+ }
1069
+ function boundedInteger(value, name, minimum, maximum) {
1070
+ if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
1071
+ throw new TypeError(`${name} must be an integer from ${minimum} through ${maximum}`);
1072
+ }
1073
+ }
1074
+ function isPromiseLike(value) {
1075
+ return value != null && typeof value === "object" && typeof value.then === "function";
1076
+ }
1077
+ function isPostgresUndefinedTable(value) {
1078
+ return typeof value === "object" && value !== null && value.code === "42P01";
1079
+ }
1080
+ function reportProjectionError(observer, error, claim) {
1081
+ try {
1082
+ const result = observer?.(error, {
1083
+ transitionId: claim.transitionId,
1084
+ tenantId: claim.tenantId,
1085
+ accountId: claim.accountId,
1086
+ attemptCount: claim.attemptCount
1087
+ });
1088
+ if (isPromiseLike(result)) void Promise.resolve(result).catch(() => {
1089
+ });
1090
+ } catch {
1091
+ }
1092
+ }
1093
+ async function reportingActivityDatabaseOperation(message, operation) {
1094
+ try {
1095
+ return await operation();
1096
+ } catch (cause) {
1097
+ throw new Error(message, { cause });
1098
+ }
1099
+ }
1100
+ function asIso(value) {
1101
+ return value instanceof Date ? value.toISOString() : new Date(value).toISOString();
1102
+ }
1103
+ export {
1104
+ REPORTING_NOTIFICATION_ACTIVITY_MIGRATION,
1105
+ ReportingNotificationRetryableSuppressionError,
1106
+ createPostgresReportingNotificationActivityRuntime,
1107
+ createPostgresReportingNotificationAttemptCheckpoint,
1108
+ getReportingNotificationActivityMigration,
1109
+ recipientTableName
1110
+ };