@adcp/sdk 15.9.1 → 16.0.0-beta.2

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 (321) hide show
  1. package/bin/adcp-identity.js +74 -0
  2. package/bin/adcp.js +2 -0
  3. package/dist/lib/adapters/keyed-account-backend.d.mts +37 -0
  4. package/dist/lib/adapters/keyed-account-backend.d.ts +37 -0
  5. package/dist/lib/adapters/keyed-account-backend.js +121 -0
  6. package/dist/lib/adapters/keyed-account-backend.mjs +94 -0
  7. package/dist/lib/adapters/keyed-account-store.d.mts +28 -0
  8. package/dist/lib/adapters/keyed-account-store.d.ts +28 -0
  9. package/dist/lib/adapters/keyed-account-store.js +227 -0
  10. package/dist/lib/adapters/keyed-account-store.mjs +203 -0
  11. package/dist/lib/core/SingleAgentClient.d.mts +25 -2
  12. package/dist/lib/core/SingleAgentClient.d.ts +25 -2
  13. package/dist/lib/core/SingleAgentClient.js +280 -62
  14. package/dist/lib/core/SingleAgentClient.mjs +282 -57
  15. package/dist/lib/core/TaskExecutor.d.mts +6 -0
  16. package/dist/lib/core/TaskExecutor.d.ts +6 -0
  17. package/dist/lib/core/TaskExecutor.js +66 -5
  18. package/dist/lib/core/TaskExecutor.mjs +71 -5
  19. package/dist/lib/core/postgres-webhook-registration-store.js +32 -5
  20. package/dist/lib/core/postgres-webhook-registration-store.mjs +32 -5
  21. package/dist/lib/core/redis-webhook-registration-store.js +23 -1
  22. package/dist/lib/core/redis-webhook-registration-store.mjs +23 -1
  23. package/dist/lib/core/webhook-registration.d.mts +7 -1
  24. package/dist/lib/core/webhook-registration.d.ts +7 -1
  25. package/dist/lib/core/webhook-registration.js +24 -2
  26. package/dist/lib/core/webhook-registration.mjs +23 -2
  27. package/dist/lib/identity-3.3/generated-compat.d.mts +34 -0
  28. package/dist/lib/identity-3.3/generated-compat.d.ts +34 -0
  29. package/dist/lib/identity-3.3/generated-compat.js +16 -0
  30. package/dist/lib/identity-3.3/generated-compat.mjs +0 -0
  31. package/dist/lib/identity-3.3/index.d.mts +10 -0
  32. package/dist/lib/identity-3.3/index.d.ts +10 -0
  33. package/dist/lib/identity-3.3/index.js +79 -0
  34. package/dist/lib/identity-3.3/index.mjs +50 -0
  35. package/dist/lib/identity-3.3/lifecycle.d.mts +125 -0
  36. package/dist/lib/identity-3.3/lifecycle.d.ts +125 -0
  37. package/dist/lib/identity-3.3/lifecycle.js +294 -0
  38. package/dist/lib/identity-3.3/lifecycle.mjs +272 -0
  39. package/dist/lib/identity-3.3/revocation.d.mts +86 -0
  40. package/dist/lib/identity-3.3/revocation.d.ts +86 -0
  41. package/dist/lib/identity-3.3/revocation.js +308 -0
  42. package/dist/lib/identity-3.3/revocation.mjs +286 -0
  43. package/dist/lib/identity-3.3/schemas.draft.d.mts +2472 -0
  44. package/dist/lib/identity-3.3/schemas.draft.d.ts +2472 -0
  45. package/dist/lib/identity-3.3/schemas.draft.js +1448 -0
  46. package/dist/lib/identity-3.3/schemas.draft.mjs +1428 -0
  47. package/dist/lib/identity-3.3/server.d.mts +46 -0
  48. package/dist/lib/identity-3.3/server.d.ts +46 -0
  49. package/dist/lib/identity-3.3/server.js +279 -0
  50. package/dist/lib/identity-3.3/server.mjs +260 -0
  51. package/dist/lib/identity-3.3/store.d.mts +24 -0
  52. package/dist/lib/identity-3.3/store.d.ts +24 -0
  53. package/dist/lib/identity-3.3/store.js +191 -0
  54. package/dist/lib/identity-3.3/store.mjs +169 -0
  55. package/dist/lib/identity-3.3/trust.d.mts +155 -0
  56. package/dist/lib/identity-3.3/trust.d.ts +155 -0
  57. package/dist/lib/identity-3.3/trust.js +383 -0
  58. package/dist/lib/identity-3.3/trust.mjs +342 -0
  59. package/dist/lib/identity-3.3/types.d.mts +155 -0
  60. package/dist/lib/identity-3.3/types.d.ts +155 -0
  61. package/dist/lib/identity-3.3/types.js +16 -0
  62. package/dist/lib/identity-3.3/types.mjs +0 -0
  63. package/dist/lib/identity-3.3/validation.d.mts +2 -0
  64. package/dist/lib/identity-3.3/validation.d.ts +2 -0
  65. package/dist/lib/identity-3.3/validation.js +125 -0
  66. package/dist/lib/identity-3.3/validation.mjs +91 -0
  67. package/dist/lib/index.d.mts +1 -1
  68. package/dist/lib/index.d.ts +1 -1
  69. package/dist/lib/index.js +2 -0
  70. package/dist/lib/index.mjs +2 -0
  71. package/dist/lib/protocols/index.d.mts +1 -1
  72. package/dist/lib/protocols/index.d.ts +1 -1
  73. package/dist/lib/protocols/index.js +2 -2
  74. package/dist/lib/protocols/index.mjs +2 -2
  75. package/dist/lib/reporting/azure/index.d.mts +5 -0
  76. package/dist/lib/reporting/azure/index.d.ts +5 -0
  77. package/dist/lib/reporting/azure/index.js +26 -7
  78. package/dist/lib/reporting/azure/index.mjs +26 -7
  79. package/dist/lib/reporting/bigquery/index.d.mts +39 -5
  80. package/dist/lib/reporting/bigquery/index.d.ts +39 -5
  81. package/dist/lib/reporting/bigquery/index.js +26 -20
  82. package/dist/lib/reporting/bigquery/index.mjs +26 -20
  83. package/dist/lib/reporting/gcs/adapter.d.mts +8 -1
  84. package/dist/lib/reporting/gcs/adapter.d.ts +8 -1
  85. package/dist/lib/reporting/gcs/errors.d.mts +6 -0
  86. package/dist/lib/reporting/gcs/errors.d.ts +6 -0
  87. package/dist/lib/reporting/gcs/fence.d.mts +5 -0
  88. package/dist/lib/reporting/gcs/fence.d.ts +5 -0
  89. package/dist/lib/reporting/gcs/index.d.mts +9 -0
  90. package/dist/lib/reporting/gcs/index.d.ts +9 -0
  91. package/dist/lib/reporting/gcs/reader.d.mts +27 -3
  92. package/dist/lib/reporting/gcs/reader.d.ts +27 -3
  93. package/dist/lib/reporting/gcs/row-provider.d.mts +7 -0
  94. package/dist/lib/reporting/gcs/row-provider.d.ts +7 -0
  95. package/dist/lib/reporting/gcs/row-provider.js +34 -14
  96. package/dist/lib/reporting/gcs/row-provider.mjs +34 -14
  97. package/dist/lib/reporting/ledger/change-feed.d.mts +22 -1
  98. package/dist/lib/reporting/ledger/change-feed.d.ts +22 -1
  99. package/dist/lib/reporting/ledger/index.d.mts +11 -0
  100. package/dist/lib/reporting/ledger/index.d.ts +11 -0
  101. package/dist/lib/reporting/ledger/managed-postgres.d.mts +8 -0
  102. package/dist/lib/reporting/ledger/managed-postgres.d.ts +8 -0
  103. package/dist/lib/reporting/ledger/managed-router.d.mts +27 -2
  104. package/dist/lib/reporting/ledger/managed-router.d.ts +27 -2
  105. package/dist/lib/reporting/ledger/managed.d.mts +86 -6
  106. package/dist/lib/reporting/ledger/managed.d.ts +86 -6
  107. package/dist/lib/reporting/ledger/notification-activity.d.mts +65 -3
  108. package/dist/lib/reporting/ledger/notification-activity.d.ts +65 -3
  109. package/dist/lib/reporting/ledger/object-writes.d.mts +64 -5
  110. package/dist/lib/reporting/ledger/object-writes.d.ts +64 -5
  111. package/dist/lib/reporting/ledger/postgres.d.mts +43 -9
  112. package/dist/lib/reporting/ledger/postgres.d.ts +43 -9
  113. package/dist/lib/reporting/ledger/postgres.js +43 -27
  114. package/dist/lib/reporting/ledger/postgres.mjs +43 -27
  115. package/dist/lib/reporting/ledger/row-encoding.d.mts +92 -6
  116. package/dist/lib/reporting/ledger/row-encoding.d.ts +92 -6
  117. package/dist/lib/reporting/ledger/row-encoding.js +8 -4
  118. package/dist/lib/reporting/ledger/row-encoding.mjs +6 -3
  119. package/dist/lib/reporting/ledger/row-storage-errors.d.mts +11 -1
  120. package/dist/lib/reporting/ledger/row-storage-errors.d.ts +11 -1
  121. package/dist/lib/reporting/ledger/row-storage-migration.d.mts +19 -1
  122. package/dist/lib/reporting/ledger/row-storage-migration.d.ts +19 -1
  123. package/dist/lib/reporting/ledger/row-storage-migration.js +133 -18
  124. package/dist/lib/reporting/ledger/row-storage-migration.mjs +133 -18
  125. package/dist/lib/reporting/ledger/row-storage-object.d.mts +103 -12
  126. package/dist/lib/reporting/ledger/row-storage-object.d.ts +103 -12
  127. package/dist/lib/reporting/ledger/row-storage-object.js +106 -31
  128. package/dist/lib/reporting/ledger/row-storage-object.mjs +104 -31
  129. package/dist/lib/reporting/ledger/row-storage.d.mts +87 -20
  130. package/dist/lib/reporting/ledger/row-storage.d.ts +87 -20
  131. package/dist/lib/reporting/ledger/row-storage.js +126 -66
  132. package/dist/lib/reporting/ledger/row-storage.mjs +129 -67
  133. package/dist/lib/reporting/ledger/schedule.d.mts +13 -0
  134. package/dist/lib/reporting/ledger/schedule.d.ts +13 -0
  135. package/dist/lib/reporting/ledger/schedule.js +24 -0
  136. package/dist/lib/reporting/ledger/schedule.mjs +23 -0
  137. package/dist/lib/reporting/ledger/types.d.mts +23 -1
  138. package/dist/lib/reporting/ledger/types.d.ts +23 -1
  139. package/dist/lib/reporting/s3/index.d.mts +5 -0
  140. package/dist/lib/reporting/s3/index.d.ts +5 -0
  141. package/dist/lib/reporting/s3/index.js +37 -14
  142. package/dist/lib/reporting/s3/index.mjs +37 -14
  143. package/dist/lib/reporting/service/index.d.mts +10 -0
  144. package/dist/lib/reporting/service/index.d.ts +10 -0
  145. package/dist/lib/reporting/service/maintenance.d.mts +28 -2
  146. package/dist/lib/reporting/service/maintenance.d.ts +28 -2
  147. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  148. package/dist/lib/server/account-sync-contract.d.mts +14 -0
  149. package/dist/lib/server/account-sync-contract.d.ts +14 -0
  150. package/dist/lib/server/account-sync-contract.js +225 -0
  151. package/dist/lib/server/account-sync-contract.mjs +197 -0
  152. package/dist/lib/server/adcp-server.js +5 -0
  153. package/dist/lib/server/adcp-server.mjs +10 -0
  154. package/dist/lib/server/auth-signature.d.mts +15 -0
  155. package/dist/lib/server/auth-signature.d.ts +15 -0
  156. package/dist/lib/server/auth-signature.js +72 -2
  157. package/dist/lib/server/auth-signature.mjs +81 -2
  158. package/dist/lib/server/auth.d.mts +6 -0
  159. package/dist/lib/server/auth.d.ts +6 -0
  160. package/dist/lib/server/auth.js +6 -0
  161. package/dist/lib/server/auth.mjs +6 -0
  162. package/dist/lib/server/create-adcp-server.d.mts +19 -5
  163. package/dist/lib/server/create-adcp-server.d.ts +19 -5
  164. package/dist/lib/server/create-adcp-server.js +259 -19
  165. package/dist/lib/server/create-adcp-server.mjs +266 -10
  166. package/dist/lib/server/decisioning/account.d.mts +24 -1
  167. package/dist/lib/server/decisioning/account.d.ts +24 -1
  168. package/dist/lib/server/decisioning/index.d.mts +1 -1
  169. package/dist/lib/server/decisioning/index.d.ts +1 -1
  170. package/dist/lib/server/decisioning/runtime/from-platform.d.mts +0 -50
  171. package/dist/lib/server/decisioning/runtime/from-platform.d.ts +0 -50
  172. package/dist/lib/server/decisioning/runtime/from-platform.js +61 -11
  173. package/dist/lib/server/decisioning/runtime/from-platform.mjs +65 -12
  174. package/dist/lib/server/index.d.mts +2 -0
  175. package/dist/lib/server/index.d.ts +2 -0
  176. package/dist/lib/server/index.js +12 -0
  177. package/dist/lib/server/index.mjs +12 -0
  178. package/dist/lib/server/notification-subscriptions/runtime.js +9 -1
  179. package/dist/lib/server/notification-subscriptions/runtime.mjs +9 -1
  180. package/dist/lib/server/notification-subscriptions/types.d.mts +5 -0
  181. package/dist/lib/server/notification-subscriptions/types.d.ts +5 -0
  182. package/dist/lib/server/principal/types.d.mts +1 -1
  183. package/dist/lib/server/principal/types.d.ts +1 -1
  184. package/dist/lib/server/serve.js +5 -0
  185. package/dist/lib/server/serve.mjs +5 -0
  186. package/dist/lib/server/webhook-delivery/recovery.d.mts +1 -0
  187. package/dist/lib/server/webhook-delivery/recovery.d.ts +1 -0
  188. package/dist/lib/server/webhook-delivery/recovery.js +4 -0
  189. package/dist/lib/server/webhook-delivery/recovery.mjs +4 -0
  190. package/dist/lib/server/webhook-emitter.d.mts +10 -0
  191. package/dist/lib/server/webhook-emitter.d.ts +10 -0
  192. package/dist/lib/server/webhook-emitter.js +22 -0
  193. package/dist/lib/server/webhook-emitter.mjs +22 -0
  194. package/dist/lib/signing/agent-context.d.mts +0 -5
  195. package/dist/lib/signing/agent-context.d.ts +0 -5
  196. package/dist/lib/signing/agent-context.js +9 -1
  197. package/dist/lib/signing/agent-context.mjs +9 -1
  198. package/dist/lib/signing/agent-fetch.js +27 -2
  199. package/dist/lib/signing/agent-fetch.mjs +32 -2
  200. package/dist/lib/signing/agent-resolver/canonicalize.d.mts +10 -15
  201. package/dist/lib/signing/agent-resolver/canonicalize.d.ts +10 -15
  202. package/dist/lib/signing/agent-resolver/canonicalize.js +17 -5
  203. package/dist/lib/signing/agent-resolver/canonicalize.mjs +16 -5
  204. package/dist/lib/signing/agent-resolver/index.d.mts +1 -0
  205. package/dist/lib/signing/agent-resolver/index.d.ts +1 -0
  206. package/dist/lib/signing/agent-resolver/index.js +5 -0
  207. package/dist/lib/signing/agent-resolver/index.mjs +3 -0
  208. package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.mts +3 -2
  209. package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.ts +3 -2
  210. package/dist/lib/signing/agent-resolver/resolved-agent-jwks.js +30 -3
  211. package/dist/lib/signing/agent-resolver/resolved-agent-jwks.mjs +30 -3
  212. package/dist/lib/signing/agent-resolver/strict-json.d.mts +2 -2
  213. package/dist/lib/signing/agent-resolver/strict-json.d.ts +2 -2
  214. package/dist/lib/signing/agent-resolver/strict-json.js +5 -3
  215. package/dist/lib/signing/agent-resolver/strict-json.mjs +5 -3
  216. package/dist/lib/signing/brand-jwks.d.mts +2 -2
  217. package/dist/lib/signing/brand-jwks.d.ts +2 -2
  218. package/dist/lib/signing/brand-jwks.js +4 -4
  219. package/dist/lib/signing/brand-jwks.mjs +4 -4
  220. package/dist/lib/signing/client.d.mts +1 -0
  221. package/dist/lib/signing/client.d.ts +1 -0
  222. package/dist/lib/signing/client.js +5 -0
  223. package/dist/lib/signing/client.mjs +3 -0
  224. package/dist/lib/signing/crypto.js +8 -0
  225. package/dist/lib/signing/crypto.mjs +9 -1
  226. package/dist/lib/signing/fetch-async.js +1 -1
  227. package/dist/lib/signing/fetch-async.mjs +1 -1
  228. package/dist/lib/signing/fetch.js +1 -1
  229. package/dist/lib/signing/fetch.mjs +1 -1
  230. package/dist/lib/signing/jwks-https.d.mts +1 -1
  231. package/dist/lib/signing/jwks-https.d.ts +1 -1
  232. package/dist/lib/signing/jwks-https.js +1 -1
  233. package/dist/lib/signing/jwks-https.mjs +1 -1
  234. package/dist/lib/signing/jwks.d.mts +11 -3
  235. package/dist/lib/signing/jwks.d.ts +11 -3
  236. package/dist/lib/signing/jwks.js +1 -1
  237. package/dist/lib/signing/jwks.mjs +1 -1
  238. package/dist/lib/signing/middleware.js +9 -0
  239. package/dist/lib/signing/middleware.mjs +14 -0
  240. package/dist/lib/signing/parser.d.mts +9 -6
  241. package/dist/lib/signing/parser.d.ts +9 -6
  242. package/dist/lib/signing/parser.js +82 -64
  243. package/dist/lib/signing/parser.mjs +83 -65
  244. package/dist/lib/signing/revocation.d.mts +4 -1
  245. package/dist/lib/signing/revocation.d.ts +4 -1
  246. package/dist/lib/signing/revocation.js +36 -3
  247. package/dist/lib/signing/revocation.mjs +34 -2
  248. package/dist/lib/signing/server.d.mts +1 -1
  249. package/dist/lib/signing/server.d.ts +1 -1
  250. package/dist/lib/signing/server.js +4 -0
  251. package/dist/lib/signing/server.mjs +4 -0
  252. package/dist/lib/signing/types.d.mts +3 -0
  253. package/dist/lib/signing/types.d.ts +3 -0
  254. package/dist/lib/signing/verifier.js +1 -1
  255. package/dist/lib/signing/verifier.mjs +1 -1
  256. package/dist/lib/signing/web-bot-auth.d.mts +191 -0
  257. package/dist/lib/signing/web-bot-auth.d.ts +191 -0
  258. package/dist/lib/signing/web-bot-auth.js +837 -0
  259. package/dist/lib/signing/web-bot-auth.mjs +796 -0
  260. package/dist/lib/signing/webhook-verifier.js +1 -1
  261. package/dist/lib/signing/webhook-verifier.mjs +1 -1
  262. package/dist/lib/testing/client.d.mts +1 -4
  263. package/dist/lib/testing/client.d.ts +1 -4
  264. package/dist/lib/testing/client.js +141 -20
  265. package/dist/lib/testing/client.mjs +137 -19
  266. package/dist/lib/testing/compliance/comply.js +29 -10
  267. package/dist/lib/testing/compliance/comply.mjs +37 -11
  268. package/dist/lib/testing/storyboard/account-sync-contract.d.mts +3 -0
  269. package/dist/lib/testing/storyboard/account-sync-contract.d.ts +3 -0
  270. package/dist/lib/testing/storyboard/account-sync-contract.js +79 -0
  271. package/dist/lib/testing/storyboard/account-sync-contract.mjs +55 -0
  272. package/dist/lib/testing/storyboard/default-invariants.js +2 -0
  273. package/dist/lib/testing/storyboard/default-invariants.mjs +2 -0
  274. package/dist/lib/testing/storyboard/runner.js +23 -8
  275. package/dist/lib/testing/storyboard/runner.mjs +24 -8
  276. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  277. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  278. package/dist/lib/types/adcp.d.mts +4 -0
  279. package/dist/lib/types/adcp.d.ts +4 -0
  280. package/dist/lib/types/schemas.generated.d.ts +6 -6
  281. package/dist/lib/utils/capabilities.d.mts +1 -0
  282. package/dist/lib/utils/capabilities.d.ts +1 -0
  283. package/dist/lib/utils/capabilities.js +5 -0
  284. package/dist/lib/utils/capabilities.mjs +5 -0
  285. package/dist/lib/v2/projection/catalog-snapshot.js +3 -1
  286. package/dist/lib/v2/projection/catalog-snapshot.mjs +3 -1
  287. package/dist/lib/v2/projection/creative-delivery.d.mts +34 -10
  288. package/dist/lib/v2/projection/creative-delivery.d.ts +34 -10
  289. package/dist/lib/v2/projection/creative-delivery.js +26 -10
  290. package/dist/lib/v2/projection/creative-delivery.mjs +26 -10
  291. package/dist/lib/v2/projection/index.d.mts +1 -1
  292. package/dist/lib/v2/projection/index.d.ts +1 -1
  293. package/dist/lib/v2/projection/index.js +2 -0
  294. package/dist/lib/v2/projection/index.mjs +2 -0
  295. package/dist/lib/v2/projection/legacy-routes.d.mts +34 -2
  296. package/dist/lib/v2/projection/legacy-routes.d.ts +34 -2
  297. package/dist/lib/v2/projection/legacy-routes.js +35 -2
  298. package/dist/lib/v2/projection/legacy-routes.mjs +32 -2
  299. package/dist/lib/validation/schema-loader.d.mts +2 -0
  300. package/dist/lib/validation/schema-loader.d.ts +2 -0
  301. package/dist/lib/validation/schema-loader.js +43 -4
  302. package/dist/lib/validation/schema-loader.mjs +39 -3
  303. package/dist/lib/version.d.mts +3 -3
  304. package/dist/lib/version.d.ts +3 -3
  305. package/dist/lib/version.js +3 -3
  306. package/dist/lib/version.mjs +3 -3
  307. package/docs/TYPE-SUMMARY.md +2 -2
  308. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +4 -0
  309. package/docs/guides/REPORTING-LEDGER-CUTOVER.md +1 -1
  310. package/docs/guides/REPORTING-LEDGER.md +99 -29
  311. package/docs/guides/REPORTING-OPERATIONS.md +29 -13
  312. package/docs/guides/REPORTING-STABILITY.md +76 -0
  313. package/docs/guides/account-resolution.md +101 -0
  314. package/docs/llms.txt +3 -2
  315. package/docs/migration-12-to-13.md +15 -0
  316. package/docs/migration-14.x-rc-worksheet.md +4 -4
  317. package/docs/migration-agent-identity-3.3.md +494 -0
  318. package/docs/migration-agent-resolution-3.3.md +5 -0
  319. package/docs/migration-reporting-row-storage-alignment.md +137 -0
  320. package/examples/storyboards/account-sync-contract.yaml +57 -0
  321. package/package.json +17 -1
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var lifecycle_exports = {};
20
+ __export(lifecycle_exports, {
21
+ InMemoryOriginIdentityStore: () => InMemoryOriginIdentityStore,
22
+ OriginIdentityLifecycle: () => OriginIdentityLifecycle,
23
+ evaluateOnboardingRequirements: () => evaluateOnboardingRequirements,
24
+ validateAgentOnboarding: () => validateAgentOnboarding
25
+ });
26
+ module.exports = __toCommonJS(lifecycle_exports);
27
+ var import_crypto = require("crypto");
28
+ var import_tldts = require("tldts");
29
+ var import_canonicalize = require('../signing/agent-resolver/canonicalize.js');
30
+ var import_etld = require('../signing/agent-resolver/etld.js');
31
+ var import_trust = require('./trust.js');
32
+ class InMemoryOriginIdentityStore {
33
+ durability = "process-local";
34
+ bindings = /* @__PURE__ */ new Map();
35
+ applications = /* @__PURE__ */ new Map();
36
+ async getBinding(origin) {
37
+ const value = this.bindings.get((0, import_canonicalize.canonicalAgentOrigin)(origin));
38
+ return value && structuredClone(value);
39
+ }
40
+ async bind(binding) {
41
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(binding.origin);
42
+ if (origin !== binding.origin || !binding.principalId || !binding.audit.approvedBy || !binding.audit.reason || !Number.isFinite(Date.parse(binding.audit.approvedAt)))
43
+ throw new TypeError("Explicit bindings require canonical origin and audit evidence");
44
+ const existing = this.bindings.get(origin);
45
+ if (existing && JSON.stringify(existing) !== JSON.stringify(binding)) throw new import_trust.IdentityAuthorizationError();
46
+ this.bindings.set(origin, structuredClone(binding));
47
+ }
48
+ async bindOpen(binding, maxPerOperator) {
49
+ const existing = this.bindings.get(binding.origin);
50
+ if (existing) throw new import_trust.IdentityAuthorizationError();
51
+ if (!binding.openAccess || !Number.isInteger(maxPerOperator) || maxPerOperator < 1 || [...this.bindings.values()].filter((b) => b.operator === binding.operator && b.openAccess).length >= maxPerOperator)
52
+ throw new import_trust.IdentityAuthorizationError();
53
+ await this.bind(binding);
54
+ return structuredClone(binding);
55
+ }
56
+ async getApplication(origin) {
57
+ const value = this.applications.get((0, import_canonicalize.canonicalAgentOrigin)(origin));
58
+ return value && structuredClone(value);
59
+ }
60
+ async compareAndSetApplication(origin, expectedRevision, application) {
61
+ origin = (0, import_canonicalize.canonicalAgentOrigin)(origin);
62
+ if (this.applications.get(origin)?.revision !== expectedRevision || application.revision !== (expectedRevision ?? 0) + 1)
63
+ return false;
64
+ this.applications.set(origin, structuredClone(application));
65
+ return true;
66
+ }
67
+ }
68
+ const BUYER_GATES = /* @__PURE__ */ new Set(["aao_verified", "storyboard", "sandbox", "experimental_feature"]);
69
+ const SELLER_GATES = /* @__PURE__ */ new Set([
70
+ "agent_identity",
71
+ "grant",
72
+ "billing_entity",
73
+ "contract",
74
+ "credit_application"
75
+ ]);
76
+ async function evaluateOnboardingRequirements(requirements, direction, check) {
77
+ const relevant = direction === "seller" ? SELLER_GATES : BUYER_GATES;
78
+ const wrong = direction === "seller" ? BUYER_GATES : SELLER_GATES;
79
+ const unsatisfied = [];
80
+ for (const requirement of requirements) {
81
+ if (wrong.has(requirement.kind)) continue;
82
+ const wellFormed = requirement.kind !== "aao_verified" || !!requirement.role && !!requirement.verification_modes?.length && !!(requirement.verified_specialisms ?? requirement.specialisms)?.length && !!requirement.adcp_version;
83
+ const hasId = !["storyboard", "experimental_feature"].includes(requirement.kind) || !!requirement.id;
84
+ if (!relevant.has(requirement.kind) || !wellFormed || !hasId || !await check(requirement))
85
+ unsatisfied.push(requirement);
86
+ }
87
+ return { satisfied: !unsatisfied.length, unsatisfied };
88
+ }
89
+ function validateAgentOnboarding(posture, account, experimentalFeatures) {
90
+ if (!(0, import_trust.validateIdentity33Schema)("core/agent-onboarding", posture) || !experimentalFeatures.includes("account.agent_onboarding") || posture.sandbox && account.sandbox !== true || Object.keys(posture.billing ?? {}).some((k) => !account.supported_billing?.includes(k)))
91
+ throw new TypeError("Invalid experimental agent onboarding posture");
92
+ }
93
+ class OriginIdentityLifecycle {
94
+ constructor(options) {
95
+ this.options = options;
96
+ }
97
+ options;
98
+ /** Identity-established origins get no durable identifier. Reads never create. */
99
+ async getPrincipal(originUrl) {
100
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
101
+ const binding = await this.options.store.getBinding(origin);
102
+ const application = await this.options.store.getApplication(origin);
103
+ return {
104
+ ...binding ? { binding } : {},
105
+ result: {
106
+ kind: binding ? "recognized" : "unconfigured",
107
+ ...binding ? { principal_id: binding.principalId, principal_kind: binding.principalKind ?? "buyer_agent" } : {},
108
+ ...application ? { relationship: application.relationship } : {}
109
+ }
110
+ };
111
+ }
112
+ async bindPrincipal(input) {
113
+ if (input.principalKind !== void 0 && !["buyer_agent", "operator"].includes(input.principalKind) || input.sharedOrigin || input.existingRfcPrincipal && input.migrationApproved !== true)
114
+ throw new import_trust.IdentityAuthorizationError();
115
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(input.origin);
116
+ const legacy = await this.options.lookupLegacyPrincipals?.(origin);
117
+ if (legacy && (legacy.length > 1 || legacy.length === 1 && (legacy[0] !== input.principalId || !input.migrationApproved)))
118
+ throw new import_trust.IdentityAuthorizationError();
119
+ const trust = await this.options.trust.match(origin, "adcp:buying");
120
+ const binding = {
121
+ origin,
122
+ operator: trust.operator,
123
+ principalId: input.principalId,
124
+ ...input.principalKind && { principalKind: input.principalKind },
125
+ audit: {
126
+ approvedBy: input.approvedBy,
127
+ reason: input.reason,
128
+ approvedAt: new Date(this.now() * 1e3).toISOString(),
129
+ ...input.migrationApproved ? { migrationApproved: true } : {}
130
+ }
131
+ };
132
+ await this.options.store.bind(binding);
133
+ return binding;
134
+ }
135
+ /**
136
+ * Cryptographic verification does not call this. Authorization revalidates
137
+ * delisting: the last record read does not list the origin (an empty
138
+ * `agents[]` retires it; a known delisting stays delisted through a failed
139
+ * refresh) and throws {@link TrustMembershipError}. An unreadable record
140
+ * (404/410 included) throws {@link TrustRecordUnavailableError} for spend;
141
+ * read-only and identity-configuration calls continue under the binding only
142
+ * while the last record read listed the origin and is within the evaluator's
143
+ * `maxOutageContinuationSeconds`.
144
+ */
145
+ async authorizeBound(originUrl, access) {
146
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
147
+ const binding = await this.options.store.getBinding(origin);
148
+ if (!binding) throw new import_trust.IdentityAuthorizationError();
149
+ try {
150
+ let trust;
151
+ try {
152
+ trust = await this.options.trust.match(origin, "adcp:buying");
153
+ } catch (error) {
154
+ if (error instanceof import_trust.TrustMembershipError && error.membership === "absent")
155
+ throw Object.assign(new import_trust.TrustRecordUnavailableError(), { cause: error });
156
+ throw error;
157
+ }
158
+ if (binding.operator !== trust.operator) throw new import_trust.TrustMembershipError();
159
+ } catch (error) {
160
+ if (!(error instanceof import_trust.TrustRecordUnavailableError) || !error.lastKnownListed || !(access?.readOnly || access?.identityConfiguration))
161
+ throw error;
162
+ }
163
+ const relationship = (await this.options.store.getApplication(origin))?.relationship;
164
+ if (!access?.readOnly && relationship && (relationship.status !== "active" || relationship.expires_at && Date.parse(relationship.expires_at) <= this.now() * 1e3))
165
+ throw new import_trust.IdentityAuthorizationError();
166
+ if (binding.openAccess && !access) throw new import_trust.IdentityAuthorizationError();
167
+ if (binding.openAccess && access && !access.readOnly && !access.identityConfiguration) {
168
+ if (access.sandbox) {
169
+ if (!binding.openAccess.sandbox) throw new import_trust.IdentityAuthorizationError();
170
+ } else {
171
+ if (!access.billing || access.billing === "agent" || !binding.openAccess.billing?.includes(access.billing))
172
+ throw new import_trust.IdentityAuthorizationError();
173
+ const billedParty = access.billing === "operator" ? binding.operator : access.brandDomain && (0, import_etld.eTldPlusOne)(access.brandDomain);
174
+ if (!billedParty || !await this.options.hasBillingRelationship?.(billedParty, access.billing))
175
+ throw new import_trust.IdentityAuthorizationError();
176
+ }
177
+ }
178
+ return binding;
179
+ }
180
+ /** Called by explicit sync_principal only; allocates new identities, never migrates existing ones. */
181
+ async syncOpen(originUrl, options) {
182
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
183
+ if (![this.options.onboarding?.sandbox, ...Object.values(this.options.onboarding?.billing ?? {})].some(
184
+ (tier) => tier?.mode === "open"
185
+ ))
186
+ throw new import_trust.IdentityAuthorizationError();
187
+ if (await this.options.store.getBinding(origin)) throw new import_trust.IdentityAuthorizationError();
188
+ if (!this.options.lookupLegacyPrincipals || (await this.options.lookupLegacyPrincipals(origin)).length)
189
+ throw new import_trust.IdentityAuthorizationError();
190
+ const relationship = (await this.options.store.getApplication(origin))?.relationship;
191
+ if (relationship && (["blocked", "suspended"].includes(relationship.status) || relationship.expires_at && Date.parse(relationship.expires_at) <= this.now() * 1e3))
192
+ throw new import_trust.IdentityAuthorizationError();
193
+ const trust = await this.options.trust.match(origin, "adcp:buying");
194
+ const privateSuffix = (0, import_tldts.parse)(new URL(origin).hostname, { allowPrivateDomains: true }).isPrivate;
195
+ const access = {};
196
+ const eligible = async (tier) => tier?.mode === "open" && (await evaluateOnboardingRequirements(
197
+ tier.requirements ?? [],
198
+ "seller",
199
+ (req) => this.options.checkRequirement?.(origin, req) ?? Promise.resolve(false)
200
+ )).satisfied;
201
+ if (await eligible(this.options.onboarding?.sandbox)) access.sandbox = true;
202
+ if (!privateSuffix) {
203
+ for (const billing of ["operator", "advertiser"])
204
+ if (await eligible(this.options.onboarding?.billing?.[billing])) (access.billing ??= []).push(billing);
205
+ }
206
+ if (!access.sandbox && !access.billing?.length) throw new import_trust.IdentityAuthorizationError();
207
+ const binding = {
208
+ origin,
209
+ operator: trust.operator,
210
+ principalId: (0, import_crypto.randomUUID)(),
211
+ openAccess: access,
212
+ audit: {
213
+ approvedBy: "open-onboarding-policy",
214
+ reason: "new principal for declared open tiers",
215
+ approvedAt: new Date(this.now() * 1e3).toISOString()
216
+ }
217
+ };
218
+ if (options?.dryRun) return binding;
219
+ return this.options.store.bindOpen(binding, this.options.maxOpenPrincipalsPerOperator ?? 10);
220
+ }
221
+ async setRelationship(originUrl, relationship) {
222
+ if (!(0, import_trust.validateIdentity33Schema)("core/principal-relationship", relationship))
223
+ throw new TypeError("Invalid relationship");
224
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
225
+ for (let attempt = 0; attempt < 5; attempt++) {
226
+ const prior = await this.options.store.getApplication(origin);
227
+ if (prior && JSON.stringify(prior.relationship) === JSON.stringify(relationship)) {
228
+ await this.flushRelationshipNotifications(origin);
229
+ return;
230
+ }
231
+ if (await this.options.store.compareAndSetApplication(origin, prior?.revision, {
232
+ relationship: structuredClone(relationship),
233
+ revision: (prior?.revision ?? 0) + 1,
234
+ ...prior?.relationship.expires_at === relationship.expires_at && prior?.expiryNotified ? { expiryNotified: prior.expiryNotified } : {},
235
+ pendingNotifications: [
236
+ ...prior?.pendingNotifications ?? [],
237
+ { id: (0, import_crypto.randomUUID)(), reason: "relationship_changed" }
238
+ ]
239
+ })) {
240
+ await this.flushRelationshipNotifications(origin);
241
+ return;
242
+ }
243
+ }
244
+ throw new import_trust.IdentityAuthorizationError();
245
+ }
246
+ async notifyRelationshipExpiring(originUrl, leadSeconds) {
247
+ if (!Number.isFinite(leadSeconds) || leadSeconds < 0) throw new TypeError("Invalid expiry lead time");
248
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
249
+ await this.flushRelationshipNotifications(origin);
250
+ const prior = await this.options.store.getApplication(origin);
251
+ const expires = prior?.relationship.expires_at;
252
+ if (!prior || !expires || prior.expiryNotified === expires || Date.parse(expires) / 1e3 - this.now() > leadSeconds || Date.parse(expires) / 1e3 <= this.now())
253
+ return false;
254
+ if (!await this.options.store.compareAndSetApplication(origin, prior.revision, {
255
+ ...prior,
256
+ revision: prior.revision + 1,
257
+ expiryNotified: expires,
258
+ pendingNotifications: [
259
+ ...prior.pendingNotifications ?? [],
260
+ { id: (0, import_crypto.randomUUID)(), reason: "relationship_expiring" }
261
+ ]
262
+ }))
263
+ return false;
264
+ await this.flushRelationshipNotifications(origin);
265
+ return true;
266
+ }
267
+ async flushRelationshipNotifications(originUrl) {
268
+ if (!this.options.notify) return;
269
+ const origin = (0, import_canonicalize.canonicalAgentOrigin)(originUrl);
270
+ for (let attempt = 0; attempt < 100; attempt++) {
271
+ const prior = await this.options.store.getApplication(origin), notification = prior?.pendingNotifications?.[0];
272
+ if (!prior || !notification) return;
273
+ await this.options.notify(origin, notification.reason, notification.id);
274
+ await this.options.store.compareAndSetApplication(origin, prior.revision, {
275
+ ...prior,
276
+ revision: prior.revision + 1,
277
+ pendingNotifications: prior.pendingNotifications.slice(1)
278
+ });
279
+ }
280
+ }
281
+ async assertLegacyAllowed(agentUrl) {
282
+ if (await this.options.store.getBinding((0, import_canonicalize.canonicalAgentOrigin)(agentUrl))) throw new import_trust.IdentityAuthorizationError();
283
+ }
284
+ now() {
285
+ return (this.options.now ?? (() => Date.now() / 1e3))();
286
+ }
287
+ }
288
+ // Annotate the CommonJS export names for ESM import in node:
289
+ 0 && (module.exports = {
290
+ InMemoryOriginIdentityStore,
291
+ OriginIdentityLifecycle,
292
+ evaluateOnboardingRequirements,
293
+ validateAgentOnboarding
294
+ });
@@ -0,0 +1,272 @@
1
+ import { randomUUID } from "crypto";
2
+ import { parse as parseTld } from "tldts";
3
+ import { canonicalAgentOrigin } from "../signing/agent-resolver/canonicalize.mjs";
4
+ import { eTldPlusOne } from "../signing/agent-resolver/etld.mjs";
5
+ import {
6
+ IdentityAuthorizationError,
7
+ TrustMembershipError,
8
+ TrustRecordUnavailableError,
9
+ validateIdentity33Schema
10
+ } from "./trust.mjs";
11
+ class InMemoryOriginIdentityStore {
12
+ durability = "process-local";
13
+ bindings = /* @__PURE__ */ new Map();
14
+ applications = /* @__PURE__ */ new Map();
15
+ async getBinding(origin) {
16
+ const value = this.bindings.get(canonicalAgentOrigin(origin));
17
+ return value && structuredClone(value);
18
+ }
19
+ async bind(binding) {
20
+ const origin = canonicalAgentOrigin(binding.origin);
21
+ if (origin !== binding.origin || !binding.principalId || !binding.audit.approvedBy || !binding.audit.reason || !Number.isFinite(Date.parse(binding.audit.approvedAt)))
22
+ throw new TypeError("Explicit bindings require canonical origin and audit evidence");
23
+ const existing = this.bindings.get(origin);
24
+ if (existing && JSON.stringify(existing) !== JSON.stringify(binding)) throw new IdentityAuthorizationError();
25
+ this.bindings.set(origin, structuredClone(binding));
26
+ }
27
+ async bindOpen(binding, maxPerOperator) {
28
+ const existing = this.bindings.get(binding.origin);
29
+ if (existing) throw new IdentityAuthorizationError();
30
+ if (!binding.openAccess || !Number.isInteger(maxPerOperator) || maxPerOperator < 1 || [...this.bindings.values()].filter((b) => b.operator === binding.operator && b.openAccess).length >= maxPerOperator)
31
+ throw new IdentityAuthorizationError();
32
+ await this.bind(binding);
33
+ return structuredClone(binding);
34
+ }
35
+ async getApplication(origin) {
36
+ const value = this.applications.get(canonicalAgentOrigin(origin));
37
+ return value && structuredClone(value);
38
+ }
39
+ async compareAndSetApplication(origin, expectedRevision, application) {
40
+ origin = canonicalAgentOrigin(origin);
41
+ if (this.applications.get(origin)?.revision !== expectedRevision || application.revision !== (expectedRevision ?? 0) + 1)
42
+ return false;
43
+ this.applications.set(origin, structuredClone(application));
44
+ return true;
45
+ }
46
+ }
47
+ const BUYER_GATES = /* @__PURE__ */ new Set(["aao_verified", "storyboard", "sandbox", "experimental_feature"]);
48
+ const SELLER_GATES = /* @__PURE__ */ new Set([
49
+ "agent_identity",
50
+ "grant",
51
+ "billing_entity",
52
+ "contract",
53
+ "credit_application"
54
+ ]);
55
+ async function evaluateOnboardingRequirements(requirements, direction, check) {
56
+ const relevant = direction === "seller" ? SELLER_GATES : BUYER_GATES;
57
+ const wrong = direction === "seller" ? BUYER_GATES : SELLER_GATES;
58
+ const unsatisfied = [];
59
+ for (const requirement of requirements) {
60
+ if (wrong.has(requirement.kind)) continue;
61
+ const wellFormed = requirement.kind !== "aao_verified" || !!requirement.role && !!requirement.verification_modes?.length && !!(requirement.verified_specialisms ?? requirement.specialisms)?.length && !!requirement.adcp_version;
62
+ const hasId = !["storyboard", "experimental_feature"].includes(requirement.kind) || !!requirement.id;
63
+ if (!relevant.has(requirement.kind) || !wellFormed || !hasId || !await check(requirement))
64
+ unsatisfied.push(requirement);
65
+ }
66
+ return { satisfied: !unsatisfied.length, unsatisfied };
67
+ }
68
+ function validateAgentOnboarding(posture, account, experimentalFeatures) {
69
+ if (!validateIdentity33Schema("core/agent-onboarding", posture) || !experimentalFeatures.includes("account.agent_onboarding") || posture.sandbox && account.sandbox !== true || Object.keys(posture.billing ?? {}).some((k) => !account.supported_billing?.includes(k)))
70
+ throw new TypeError("Invalid experimental agent onboarding posture");
71
+ }
72
+ class OriginIdentityLifecycle {
73
+ constructor(options) {
74
+ this.options = options;
75
+ }
76
+ options;
77
+ /** Identity-established origins get no durable identifier. Reads never create. */
78
+ async getPrincipal(originUrl) {
79
+ const origin = canonicalAgentOrigin(originUrl);
80
+ const binding = await this.options.store.getBinding(origin);
81
+ const application = await this.options.store.getApplication(origin);
82
+ return {
83
+ ...binding ? { binding } : {},
84
+ result: {
85
+ kind: binding ? "recognized" : "unconfigured",
86
+ ...binding ? { principal_id: binding.principalId, principal_kind: binding.principalKind ?? "buyer_agent" } : {},
87
+ ...application ? { relationship: application.relationship } : {}
88
+ }
89
+ };
90
+ }
91
+ async bindPrincipal(input) {
92
+ if (input.principalKind !== void 0 && !["buyer_agent", "operator"].includes(input.principalKind) || input.sharedOrigin || input.existingRfcPrincipal && input.migrationApproved !== true)
93
+ throw new IdentityAuthorizationError();
94
+ const origin = canonicalAgentOrigin(input.origin);
95
+ const legacy = await this.options.lookupLegacyPrincipals?.(origin);
96
+ if (legacy && (legacy.length > 1 || legacy.length === 1 && (legacy[0] !== input.principalId || !input.migrationApproved)))
97
+ throw new IdentityAuthorizationError();
98
+ const trust = await this.options.trust.match(origin, "adcp:buying");
99
+ const binding = {
100
+ origin,
101
+ operator: trust.operator,
102
+ principalId: input.principalId,
103
+ ...input.principalKind && { principalKind: input.principalKind },
104
+ audit: {
105
+ approvedBy: input.approvedBy,
106
+ reason: input.reason,
107
+ approvedAt: new Date(this.now() * 1e3).toISOString(),
108
+ ...input.migrationApproved ? { migrationApproved: true } : {}
109
+ }
110
+ };
111
+ await this.options.store.bind(binding);
112
+ return binding;
113
+ }
114
+ /**
115
+ * Cryptographic verification does not call this. Authorization revalidates
116
+ * delisting: the last record read does not list the origin (an empty
117
+ * `agents[]` retires it; a known delisting stays delisted through a failed
118
+ * refresh) and throws {@link TrustMembershipError}. An unreadable record
119
+ * (404/410 included) throws {@link TrustRecordUnavailableError} for spend;
120
+ * read-only and identity-configuration calls continue under the binding only
121
+ * while the last record read listed the origin and is within the evaluator's
122
+ * `maxOutageContinuationSeconds`.
123
+ */
124
+ async authorizeBound(originUrl, access) {
125
+ const origin = canonicalAgentOrigin(originUrl);
126
+ const binding = await this.options.store.getBinding(origin);
127
+ if (!binding) throw new IdentityAuthorizationError();
128
+ try {
129
+ let trust;
130
+ try {
131
+ trust = await this.options.trust.match(origin, "adcp:buying");
132
+ } catch (error) {
133
+ if (error instanceof TrustMembershipError && error.membership === "absent")
134
+ throw Object.assign(new TrustRecordUnavailableError(), { cause: error });
135
+ throw error;
136
+ }
137
+ if (binding.operator !== trust.operator) throw new TrustMembershipError();
138
+ } catch (error) {
139
+ if (!(error instanceof TrustRecordUnavailableError) || !error.lastKnownListed || !(access?.readOnly || access?.identityConfiguration))
140
+ throw error;
141
+ }
142
+ const relationship = (await this.options.store.getApplication(origin))?.relationship;
143
+ if (!access?.readOnly && relationship && (relationship.status !== "active" || relationship.expires_at && Date.parse(relationship.expires_at) <= this.now() * 1e3))
144
+ throw new IdentityAuthorizationError();
145
+ if (binding.openAccess && !access) throw new IdentityAuthorizationError();
146
+ if (binding.openAccess && access && !access.readOnly && !access.identityConfiguration) {
147
+ if (access.sandbox) {
148
+ if (!binding.openAccess.sandbox) throw new IdentityAuthorizationError();
149
+ } else {
150
+ if (!access.billing || access.billing === "agent" || !binding.openAccess.billing?.includes(access.billing))
151
+ throw new IdentityAuthorizationError();
152
+ const billedParty = access.billing === "operator" ? binding.operator : access.brandDomain && eTldPlusOne(access.brandDomain);
153
+ if (!billedParty || !await this.options.hasBillingRelationship?.(billedParty, access.billing))
154
+ throw new IdentityAuthorizationError();
155
+ }
156
+ }
157
+ return binding;
158
+ }
159
+ /** Called by explicit sync_principal only; allocates new identities, never migrates existing ones. */
160
+ async syncOpen(originUrl, options) {
161
+ const origin = canonicalAgentOrigin(originUrl);
162
+ if (![this.options.onboarding?.sandbox, ...Object.values(this.options.onboarding?.billing ?? {})].some(
163
+ (tier) => tier?.mode === "open"
164
+ ))
165
+ throw new IdentityAuthorizationError();
166
+ if (await this.options.store.getBinding(origin)) throw new IdentityAuthorizationError();
167
+ if (!this.options.lookupLegacyPrincipals || (await this.options.lookupLegacyPrincipals(origin)).length)
168
+ throw new IdentityAuthorizationError();
169
+ const relationship = (await this.options.store.getApplication(origin))?.relationship;
170
+ if (relationship && (["blocked", "suspended"].includes(relationship.status) || relationship.expires_at && Date.parse(relationship.expires_at) <= this.now() * 1e3))
171
+ throw new IdentityAuthorizationError();
172
+ const trust = await this.options.trust.match(origin, "adcp:buying");
173
+ const privateSuffix = parseTld(new URL(origin).hostname, { allowPrivateDomains: true }).isPrivate;
174
+ const access = {};
175
+ const eligible = async (tier) => tier?.mode === "open" && (await evaluateOnboardingRequirements(
176
+ tier.requirements ?? [],
177
+ "seller",
178
+ (req) => this.options.checkRequirement?.(origin, req) ?? Promise.resolve(false)
179
+ )).satisfied;
180
+ if (await eligible(this.options.onboarding?.sandbox)) access.sandbox = true;
181
+ if (!privateSuffix) {
182
+ for (const billing of ["operator", "advertiser"])
183
+ if (await eligible(this.options.onboarding?.billing?.[billing])) (access.billing ??= []).push(billing);
184
+ }
185
+ if (!access.sandbox && !access.billing?.length) throw new IdentityAuthorizationError();
186
+ const binding = {
187
+ origin,
188
+ operator: trust.operator,
189
+ principalId: randomUUID(),
190
+ openAccess: access,
191
+ audit: {
192
+ approvedBy: "open-onboarding-policy",
193
+ reason: "new principal for declared open tiers",
194
+ approvedAt: new Date(this.now() * 1e3).toISOString()
195
+ }
196
+ };
197
+ if (options?.dryRun) return binding;
198
+ return this.options.store.bindOpen(binding, this.options.maxOpenPrincipalsPerOperator ?? 10);
199
+ }
200
+ async setRelationship(originUrl, relationship) {
201
+ if (!validateIdentity33Schema("core/principal-relationship", relationship))
202
+ throw new TypeError("Invalid relationship");
203
+ const origin = canonicalAgentOrigin(originUrl);
204
+ for (let attempt = 0; attempt < 5; attempt++) {
205
+ const prior = await this.options.store.getApplication(origin);
206
+ if (prior && JSON.stringify(prior.relationship) === JSON.stringify(relationship)) {
207
+ await this.flushRelationshipNotifications(origin);
208
+ return;
209
+ }
210
+ if (await this.options.store.compareAndSetApplication(origin, prior?.revision, {
211
+ relationship: structuredClone(relationship),
212
+ revision: (prior?.revision ?? 0) + 1,
213
+ ...prior?.relationship.expires_at === relationship.expires_at && prior?.expiryNotified ? { expiryNotified: prior.expiryNotified } : {},
214
+ pendingNotifications: [
215
+ ...prior?.pendingNotifications ?? [],
216
+ { id: randomUUID(), reason: "relationship_changed" }
217
+ ]
218
+ })) {
219
+ await this.flushRelationshipNotifications(origin);
220
+ return;
221
+ }
222
+ }
223
+ throw new IdentityAuthorizationError();
224
+ }
225
+ async notifyRelationshipExpiring(originUrl, leadSeconds) {
226
+ if (!Number.isFinite(leadSeconds) || leadSeconds < 0) throw new TypeError("Invalid expiry lead time");
227
+ const origin = canonicalAgentOrigin(originUrl);
228
+ await this.flushRelationshipNotifications(origin);
229
+ const prior = await this.options.store.getApplication(origin);
230
+ const expires = prior?.relationship.expires_at;
231
+ if (!prior || !expires || prior.expiryNotified === expires || Date.parse(expires) / 1e3 - this.now() > leadSeconds || Date.parse(expires) / 1e3 <= this.now())
232
+ return false;
233
+ if (!await this.options.store.compareAndSetApplication(origin, prior.revision, {
234
+ ...prior,
235
+ revision: prior.revision + 1,
236
+ expiryNotified: expires,
237
+ pendingNotifications: [
238
+ ...prior.pendingNotifications ?? [],
239
+ { id: randomUUID(), reason: "relationship_expiring" }
240
+ ]
241
+ }))
242
+ return false;
243
+ await this.flushRelationshipNotifications(origin);
244
+ return true;
245
+ }
246
+ async flushRelationshipNotifications(originUrl) {
247
+ if (!this.options.notify) return;
248
+ const origin = canonicalAgentOrigin(originUrl);
249
+ for (let attempt = 0; attempt < 100; attempt++) {
250
+ const prior = await this.options.store.getApplication(origin), notification = prior?.pendingNotifications?.[0];
251
+ if (!prior || !notification) return;
252
+ await this.options.notify(origin, notification.reason, notification.id);
253
+ await this.options.store.compareAndSetApplication(origin, prior.revision, {
254
+ ...prior,
255
+ revision: prior.revision + 1,
256
+ pendingNotifications: prior.pendingNotifications.slice(1)
257
+ });
258
+ }
259
+ }
260
+ async assertLegacyAllowed(agentUrl) {
261
+ if (await this.options.store.getBinding(canonicalAgentOrigin(agentUrl))) throw new IdentityAuthorizationError();
262
+ }
263
+ now() {
264
+ return (this.options.now ?? (() => Date.now() / 1e3))();
265
+ }
266
+ }
267
+ export {
268
+ InMemoryOriginIdentityStore,
269
+ OriginIdentityLifecycle,
270
+ evaluateOnboardingRequirements,
271
+ validateAgentOnboarding
272
+ };
@@ -0,0 +1,86 @@
1
+ import { type JWK } from 'jose';
2
+ import { type SsrfFetchOptions } from '../net/index.mjs';
3
+ import type { RevocationDetail } from './types.mjs';
4
+ export interface OriginRevocationSnapshot {
5
+ issuer: string;
6
+ updated: string;
7
+ next_update: string;
8
+ revoked_kids: string[];
9
+ revoked_jtis?: string[];
10
+ revocation_details?: Record<string, RevocationDetail>;
11
+ }
12
+ export interface MonotonicOriginRevocationStore {
13
+ /** Merge atomically and persist forever. Never replace with a new snapshot. */
14
+ merge(origin: string, snapshot: OriginRevocationSnapshot): Promise<void>;
15
+ get(origin: string, keyid: string): Promise<RevocationDetail | undefined>;
16
+ }
17
+ /**
18
+ * Process-local revocation history for development and tests. Public
19
+ * deployments need durable history (`createIdentity33StateStores`) so a
20
+ * restart never forgets a revocation.
21
+ *
22
+ * Capacity is bounded per origin, per operator (registrable domain) and in
23
+ * total. The operator budget stops one registrable domain's wildcard
24
+ * subdomains from filling the store alone; it does not reserve capacity for
25
+ * anyone else, so several operators together can still exhaust the total.
26
+ * Facts are never evicted to regain capacity; a refused merge fails closed.
27
+ */
28
+ export declare class InMemoryOriginRevocationStore implements MonotonicOriginRevocationStore {
29
+ readonly durability: "process-local";
30
+ private readonly revoked;
31
+ private readonly originKeys;
32
+ private readonly operatorKeys;
33
+ private readonly limits;
34
+ constructor(limits?: {
35
+ perOrigin?: number;
36
+ perOperator?: number;
37
+ total?: number;
38
+ });
39
+ merge(origin: string, snapshot: OriginRevocationSnapshot): Promise<void>;
40
+ get(origin: string, keyid: string): Promise<RevocationDetail | undefined>;
41
+ }
42
+ /** See {@link OriginRevocationResolver.status}. */
43
+ export type OriginRevocationStatus = 'revoked' | 'current' | 'absent' | 'unknown';
44
+ export declare class OriginRevocationResolver {
45
+ private readonly options;
46
+ private readonly freshness;
47
+ private readonly updated;
48
+ private readonly graceUntil;
49
+ private readonly pending;
50
+ private readonly failures;
51
+ private readonly persistenceFailures;
52
+ private readonly absentUntil;
53
+ constructor(options: {
54
+ directory: import('../signing/web-bot-auth.mjs').SignatureDirectoryResolver;
55
+ store: MonotonicOriginRevocationStore;
56
+ pollingIntervalSeconds?: number;
57
+ now?: () => number;
58
+ fetchOptions?: Pick<SsrfFetchOptions, 'lookup' | 'trustedFetchFn'>;
59
+ maxOrigins?: number;
60
+ });
61
+ /**
62
+ * Compatibility wrapper over {@link status}: `true` when revoked, `false`
63
+ * when the list is current, and `revocation_unavailable` when the identity
64
+ * publishes no list (`absent`) or its status is not known (`unknown`).
65
+ */
66
+ isRevoked(originUrl: string, keyid: string): Promise<boolean>;
67
+ /**
68
+ * Revocation status of `keyid` at `origin`:
69
+ * - `revoked`: a stored (permanent) revocation covers the key.
70
+ * - `current`: a signed list is current, or within `next_update` + grace.
71
+ * - `absent`: the origin serves no list (404/410). The identity is still
72
+ * established but cannot be bound for spend.
73
+ * - `unknown`: no list could be verified and grace has passed (or there was
74
+ * never a list). The identity is not established.
75
+ * Throws {@link WebBotAuthUnavailableError} (`revocation_persistence_failed`)
76
+ * when the history store fails: an infrastructure outage, never a
77
+ * revocation outcome.
78
+ */
79
+ status(originUrl: string, keyid: string): Promise<OriginRevocationStatus>;
80
+ private currentStatus;
81
+ private readStored;
82
+ private refresh;
83
+ private now;
84
+ }
85
+ /** Publish a signed list even when there are no revoked keys; refresh before next_update. */
86
+ export declare function createSignedOriginRevocationList(snapshot: OriginRevocationSnapshot, privateKey: JWK): Promise<string>;