@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,225 @@
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 account_sync_contract_exports = {};
20
+ __export(account_sync_contract_exports, {
21
+ checkSyncAccountRows: () => checkSyncAccountRows,
22
+ diagnoseAccountBilling: () => diagnoseAccountBilling,
23
+ existingSyncAccounts: () => existingSyncAccounts,
24
+ isolateAccountCallbackInput: () => isolateAccountCallbackInput,
25
+ projectAccountList: () => projectAccountList
26
+ });
27
+ module.exports = __toCommonJS(account_sync_contract_exports);
28
+ var import_account_key = require('../core/account-key.js');
29
+ var import_account = require('./decisioning/account.js');
30
+ var import_async_outcome = require('./decisioning/async-outcome.js');
31
+ function isolateAccountCallbackInput(ctx) {
32
+ const descriptors = Object.getOwnPropertyDescriptors(ctx);
33
+ delete descriptors.input;
34
+ const copy = Object.defineProperties({}, descriptors);
35
+ if ("input" in ctx) {
36
+ let captured = false;
37
+ let input;
38
+ Object.defineProperty(copy, "input", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ get() {
42
+ if (!captured) {
43
+ const source = ctx.input;
44
+ input = source === void 0 ? void 0 : structuredClone(source);
45
+ captured = true;
46
+ }
47
+ return input;
48
+ },
49
+ set(value) {
50
+ input = value;
51
+ captured = true;
52
+ }
53
+ });
54
+ }
55
+ return copy;
56
+ }
57
+ function naturalRef(entry) {
58
+ const ref = entry.account ?? entry;
59
+ if (!ref || "account_id" in ref || !("brand" in ref) || !ref.brand || typeof ref.operator !== "string")
60
+ return void 0;
61
+ return ref;
62
+ }
63
+ async function lookup(accounts, ref, ctx, onUnsupported) {
64
+ try {
65
+ const account = await accounts.resolve(
66
+ structuredClone(ref),
67
+ isolateAccountCallbackInput({ ...ctx, provisioning: false })
68
+ );
69
+ if (account && "account_id" in ref && account.id !== ref.account_id) return null;
70
+ if (account && "brand" in ref) {
71
+ const identity = account;
72
+ const values = identity;
73
+ const known = Object.fromEntries(
74
+ ["operator_unit", "currency", "timezone", "sandbox"].filter((field) => values[field] !== void 0).map((field) => [field, values[field]])
75
+ );
76
+ const projected = {
77
+ ...ref,
78
+ ...known,
79
+ brand: { ...ref.brand, ...identity.brand },
80
+ operator: identity.operator ?? ref.operator
81
+ };
82
+ if ((0, import_account_key.accountReferenceKey)(projected) !== (0, import_account_key.accountReferenceKey)(ref)) return null;
83
+ }
84
+ return account ? { ...account, billing: account.billing && { ...account.billing } } : null;
85
+ } catch (error) {
86
+ if (error instanceof import_account.AccountNotFoundError || error instanceof import_async_outcome.AdcpError && error.code === "ACCOUNT_NOT_FOUND")
87
+ return null;
88
+ if (error instanceof import_async_outcome.AdcpError && ["INVALID_REQUEST", "UNSUPPORTED_FEATURE"].includes(error.code)) {
89
+ onUnsupported?.();
90
+ return null;
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ async function existingSyncAccounts(accounts, entries, ctx, logger) {
96
+ const existing = [];
97
+ for (const [index, entry] of entries.entries()) {
98
+ const ref = accounts.resolution === "derived" ? void 0 : naturalRef(entry);
99
+ const account = ref ? await lookup(accounts, ref, ctx, () => {
100
+ if (logger)
101
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_LOOKUP_UNSUPPORTED", toolName: "sync_accounts", index });
102
+ }) : null;
103
+ existing.push(
104
+ typeof account?.brand?.domain === "string" && account.brand.domain.length > 0 && typeof account.operator === "string" ? account : null
105
+ );
106
+ }
107
+ return existing;
108
+ }
109
+ function diagnose(accounts, logger, diagnostic) {
110
+ if (process.env.NODE_ENV !== "production") safeWarn(logger, "Account store contract violation", { ...diagnostic });
111
+ try {
112
+ const pending = accounts.onDiagnostic?.(diagnostic);
113
+ if (pending) void Promise.resolve(pending).catch(() => safeWarn(logger, "Account diagnostic callback failed"));
114
+ } catch {
115
+ safeWarn(logger, "Account diagnostic callback failed");
116
+ }
117
+ }
118
+ function safeWarn(logger, message, data) {
119
+ try {
120
+ logger.warn(message, data);
121
+ } catch {
122
+ }
123
+ }
124
+ function diagnoseAccountBilling(accounts, logger, account, toolName, index) {
125
+ if (account.billing === "agent" && account.payment_terms === void 0) {
126
+ diagnose(accounts, logger, { code: "ACCOUNT_BILLING_FIELDS_MISSING", toolName, index });
127
+ }
128
+ }
129
+ async function projectAccountList(accounts, items, ctx, logger) {
130
+ const rows = [];
131
+ for (const [index, account] of items.entries()) {
132
+ const row = (0, import_account.toWireAccount)(account);
133
+ if (row.billing === void 0 || row.payment_terms === void 0) {
134
+ const ref = accounts.resolution === "implicit" ? naturalRef(account) : { account_id: account.id };
135
+ if (ref) {
136
+ try {
137
+ const stored = await lookup(accounts, ref, ctx);
138
+ if (stored?.id === account.id) {
139
+ const wire = (0, import_account.toWireAccount)(stored);
140
+ row.billing ??= wire.billing;
141
+ row.payment_terms ??= wire.payment_terms;
142
+ }
143
+ } catch {
144
+ safeWarn(logger, "Could not enrich listed account billing fields");
145
+ }
146
+ }
147
+ }
148
+ diagnoseAccountBilling(accounts, logger, row, "list_accounts", index);
149
+ rows.push(row);
150
+ }
151
+ return rows;
152
+ }
153
+ async function checkSyncAccountRows(accounts, entries, existing, rows, indices, ctx, logger) {
154
+ const seen = /* @__PURE__ */ new Map();
155
+ const checked = [];
156
+ for (const [offset, inputRow] of rows.entries()) {
157
+ const entry = entries[offset];
158
+ const index = indices[offset];
159
+ const ref = naturalRef(entry);
160
+ const key = ref && (0, import_account_key.accountReferenceKey)(ref);
161
+ const priorId = existing[offset]?.id ?? (key ? seen.get(key) : void 0);
162
+ let row = { ...inputRow };
163
+ if (row.action === "failed") {
164
+ checked.push(row);
165
+ continue;
166
+ }
167
+ const idViolation = priorId !== void 0 && (row.account_id !== priorId || row.action === "created");
168
+ if (idViolation)
169
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_IDEMPOTENCY_VIOLATION", toolName: "sync_accounts", index });
170
+ const requestedRef = entry.account ?? entry;
171
+ const enrichmentRef = ref ?? ("account_id" in requestedRef && accounts.resolution !== "implicit" ? { account_id: requestedRef.account_id } : void 0);
172
+ let stored = null;
173
+ if (enrichmentRef && (row.billing === void 0 || row.payment_terms === void 0)) {
174
+ try {
175
+ stored = await lookup(accounts, enrichmentRef, ctx);
176
+ } catch {
177
+ safeWarn(logger, "Could not enrich account sync billing fields");
178
+ }
179
+ }
180
+ const source = stored?.id === row.account_id ? stored : existing[offset]?.id === row.account_id ? existing[offset] : null;
181
+ if (source) {
182
+ const wire = (0, import_account.toWireAccount)(source);
183
+ row.billing ??= wire.billing;
184
+ row.payment_terms ??= wire.payment_terms;
185
+ }
186
+ const missing = (entry.billing === "agent" || row.billing === "agent") && (row.billing === void 0 || row.payment_terms === void 0);
187
+ if (missing)
188
+ diagnose(accounts, logger, { code: "ACCOUNT_BILLING_FIELDS_MISSING", toolName: "sync_accounts", index });
189
+ const termsViolation = entry.payment_terms !== void 0 && row.status === "active" && row.payment_terms !== entry.payment_terms;
190
+ const billingViolation = entry.billing === "agent" && row.status === "active" && row.billing !== void 0 && row.billing !== "agent";
191
+ if (billingViolation)
192
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_BILLING_MISMATCH", toolName: "sync_accounts", index });
193
+ if (termsViolation)
194
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_PAYMENT_TERMS_MISMATCH", toolName: "sync_accounts", index });
195
+ if (key && row.account_id) seen.set(key, priorId ?? row.account_id);
196
+ if (accounts.strictIdempotency && (idViolation || termsViolation || billingViolation)) {
197
+ const error = new import_async_outcome.AdcpError(
198
+ termsViolation ? "PAYMENT_TERMS_NOT_SUPPORTED" : billingViolation ? "BILLING_NOT_SUPPORTED" : "SERVICE_UNAVAILABLE",
199
+ {
200
+ message: termsViolation ? "The seller did not accept the requested payment terms." : billingViolation ? "The seller did not accept agent billing." : "The account store did not preserve the existing account identity.",
201
+ recovery: termsViolation || billingViolation ? "correctable" : "transient",
202
+ field: `accounts[${index}]${termsViolation ? ".payment_terms" : billingViolation ? ".billing" : ""}`
203
+ }
204
+ ).toStructuredError();
205
+ row = {
206
+ brand: row.brand,
207
+ operator: row.operator,
208
+ ...priorId === row.account_id && priorId && { account_id: priorId },
209
+ action: "failed",
210
+ status: existing[offset]?.status ?? row.status,
211
+ errors: [error]
212
+ };
213
+ }
214
+ checked.push(row);
215
+ }
216
+ return checked;
217
+ }
218
+ // Annotate the CommonJS export names for ESM import in node:
219
+ 0 && (module.exports = {
220
+ checkSyncAccountRows,
221
+ diagnoseAccountBilling,
222
+ existingSyncAccounts,
223
+ isolateAccountCallbackInput,
224
+ projectAccountList
225
+ });
@@ -0,0 +1,197 @@
1
+ import { accountReferenceKey } from "../core/account-key.mjs";
2
+ import { AccountNotFoundError, toWireAccount } from "./decisioning/account.mjs";
3
+ import { AdcpError } from "./decisioning/async-outcome.mjs";
4
+ function isolateAccountCallbackInput(ctx) {
5
+ const descriptors = Object.getOwnPropertyDescriptors(ctx);
6
+ delete descriptors.input;
7
+ const copy = Object.defineProperties({}, descriptors);
8
+ if ("input" in ctx) {
9
+ let captured = false;
10
+ let input;
11
+ Object.defineProperty(copy, "input", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ get() {
15
+ if (!captured) {
16
+ const source = ctx.input;
17
+ input = source === void 0 ? void 0 : structuredClone(source);
18
+ captured = true;
19
+ }
20
+ return input;
21
+ },
22
+ set(value) {
23
+ input = value;
24
+ captured = true;
25
+ }
26
+ });
27
+ }
28
+ return copy;
29
+ }
30
+ function naturalRef(entry) {
31
+ const ref = entry.account ?? entry;
32
+ if (!ref || "account_id" in ref || !("brand" in ref) || !ref.brand || typeof ref.operator !== "string")
33
+ return void 0;
34
+ return ref;
35
+ }
36
+ async function lookup(accounts, ref, ctx, onUnsupported) {
37
+ try {
38
+ const account = await accounts.resolve(
39
+ structuredClone(ref),
40
+ isolateAccountCallbackInput({ ...ctx, provisioning: false })
41
+ );
42
+ if (account && "account_id" in ref && account.id !== ref.account_id) return null;
43
+ if (account && "brand" in ref) {
44
+ const identity = account;
45
+ const values = identity;
46
+ const known = Object.fromEntries(
47
+ ["operator_unit", "currency", "timezone", "sandbox"].filter((field) => values[field] !== void 0).map((field) => [field, values[field]])
48
+ );
49
+ const projected = {
50
+ ...ref,
51
+ ...known,
52
+ brand: { ...ref.brand, ...identity.brand },
53
+ operator: identity.operator ?? ref.operator
54
+ };
55
+ if (accountReferenceKey(projected) !== accountReferenceKey(ref)) return null;
56
+ }
57
+ return account ? { ...account, billing: account.billing && { ...account.billing } } : null;
58
+ } catch (error) {
59
+ if (error instanceof AccountNotFoundError || error instanceof AdcpError && error.code === "ACCOUNT_NOT_FOUND")
60
+ return null;
61
+ if (error instanceof AdcpError && ["INVALID_REQUEST", "UNSUPPORTED_FEATURE"].includes(error.code)) {
62
+ onUnsupported?.();
63
+ return null;
64
+ }
65
+ throw error;
66
+ }
67
+ }
68
+ async function existingSyncAccounts(accounts, entries, ctx, logger) {
69
+ const existing = [];
70
+ for (const [index, entry] of entries.entries()) {
71
+ const ref = accounts.resolution === "derived" ? void 0 : naturalRef(entry);
72
+ const account = ref ? await lookup(accounts, ref, ctx, () => {
73
+ if (logger)
74
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_LOOKUP_UNSUPPORTED", toolName: "sync_accounts", index });
75
+ }) : null;
76
+ existing.push(
77
+ typeof account?.brand?.domain === "string" && account.brand.domain.length > 0 && typeof account.operator === "string" ? account : null
78
+ );
79
+ }
80
+ return existing;
81
+ }
82
+ function diagnose(accounts, logger, diagnostic) {
83
+ if (process.env.NODE_ENV !== "production") safeWarn(logger, "Account store contract violation", { ...diagnostic });
84
+ try {
85
+ const pending = accounts.onDiagnostic?.(diagnostic);
86
+ if (pending) void Promise.resolve(pending).catch(() => safeWarn(logger, "Account diagnostic callback failed"));
87
+ } catch {
88
+ safeWarn(logger, "Account diagnostic callback failed");
89
+ }
90
+ }
91
+ function safeWarn(logger, message, data) {
92
+ try {
93
+ logger.warn(message, data);
94
+ } catch {
95
+ }
96
+ }
97
+ function diagnoseAccountBilling(accounts, logger, account, toolName, index) {
98
+ if (account.billing === "agent" && account.payment_terms === void 0) {
99
+ diagnose(accounts, logger, { code: "ACCOUNT_BILLING_FIELDS_MISSING", toolName, index });
100
+ }
101
+ }
102
+ async function projectAccountList(accounts, items, ctx, logger) {
103
+ const rows = [];
104
+ for (const [index, account] of items.entries()) {
105
+ const row = toWireAccount(account);
106
+ if (row.billing === void 0 || row.payment_terms === void 0) {
107
+ const ref = accounts.resolution === "implicit" ? naturalRef(account) : { account_id: account.id };
108
+ if (ref) {
109
+ try {
110
+ const stored = await lookup(accounts, ref, ctx);
111
+ if (stored?.id === account.id) {
112
+ const wire = toWireAccount(stored);
113
+ row.billing ??= wire.billing;
114
+ row.payment_terms ??= wire.payment_terms;
115
+ }
116
+ } catch {
117
+ safeWarn(logger, "Could not enrich listed account billing fields");
118
+ }
119
+ }
120
+ }
121
+ diagnoseAccountBilling(accounts, logger, row, "list_accounts", index);
122
+ rows.push(row);
123
+ }
124
+ return rows;
125
+ }
126
+ async function checkSyncAccountRows(accounts, entries, existing, rows, indices, ctx, logger) {
127
+ const seen = /* @__PURE__ */ new Map();
128
+ const checked = [];
129
+ for (const [offset, inputRow] of rows.entries()) {
130
+ const entry = entries[offset];
131
+ const index = indices[offset];
132
+ const ref = naturalRef(entry);
133
+ const key = ref && accountReferenceKey(ref);
134
+ const priorId = existing[offset]?.id ?? (key ? seen.get(key) : void 0);
135
+ let row = { ...inputRow };
136
+ if (row.action === "failed") {
137
+ checked.push(row);
138
+ continue;
139
+ }
140
+ const idViolation = priorId !== void 0 && (row.account_id !== priorId || row.action === "created");
141
+ if (idViolation)
142
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_IDEMPOTENCY_VIOLATION", toolName: "sync_accounts", index });
143
+ const requestedRef = entry.account ?? entry;
144
+ const enrichmentRef = ref ?? ("account_id" in requestedRef && accounts.resolution !== "implicit" ? { account_id: requestedRef.account_id } : void 0);
145
+ let stored = null;
146
+ if (enrichmentRef && (row.billing === void 0 || row.payment_terms === void 0)) {
147
+ try {
148
+ stored = await lookup(accounts, enrichmentRef, ctx);
149
+ } catch {
150
+ safeWarn(logger, "Could not enrich account sync billing fields");
151
+ }
152
+ }
153
+ const source = stored?.id === row.account_id ? stored : existing[offset]?.id === row.account_id ? existing[offset] : null;
154
+ if (source) {
155
+ const wire = toWireAccount(source);
156
+ row.billing ??= wire.billing;
157
+ row.payment_terms ??= wire.payment_terms;
158
+ }
159
+ const missing = (entry.billing === "agent" || row.billing === "agent") && (row.billing === void 0 || row.payment_terms === void 0);
160
+ if (missing)
161
+ diagnose(accounts, logger, { code: "ACCOUNT_BILLING_FIELDS_MISSING", toolName: "sync_accounts", index });
162
+ const termsViolation = entry.payment_terms !== void 0 && row.status === "active" && row.payment_terms !== entry.payment_terms;
163
+ const billingViolation = entry.billing === "agent" && row.status === "active" && row.billing !== void 0 && row.billing !== "agent";
164
+ if (billingViolation)
165
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_BILLING_MISMATCH", toolName: "sync_accounts", index });
166
+ if (termsViolation)
167
+ diagnose(accounts, logger, { code: "ACCOUNT_SYNC_PAYMENT_TERMS_MISMATCH", toolName: "sync_accounts", index });
168
+ if (key && row.account_id) seen.set(key, priorId ?? row.account_id);
169
+ if (accounts.strictIdempotency && (idViolation || termsViolation || billingViolation)) {
170
+ const error = new AdcpError(
171
+ termsViolation ? "PAYMENT_TERMS_NOT_SUPPORTED" : billingViolation ? "BILLING_NOT_SUPPORTED" : "SERVICE_UNAVAILABLE",
172
+ {
173
+ message: termsViolation ? "The seller did not accept the requested payment terms." : billingViolation ? "The seller did not accept agent billing." : "The account store did not preserve the existing account identity.",
174
+ recovery: termsViolation || billingViolation ? "correctable" : "transient",
175
+ field: `accounts[${index}]${termsViolation ? ".payment_terms" : billingViolation ? ".billing" : ""}`
176
+ }
177
+ ).toStructuredError();
178
+ row = {
179
+ brand: row.brand,
180
+ operator: row.operator,
181
+ ...priorId === row.account_id && priorId && { account_id: priorId },
182
+ action: "failed",
183
+ status: existing[offset]?.status ?? row.status,
184
+ errors: [error]
185
+ };
186
+ }
187
+ checked.push(row);
188
+ }
189
+ return checked;
190
+ }
191
+ export {
192
+ checkSyncAccountRows,
193
+ diagnoseAccountBilling,
194
+ existingSyncAccounts,
195
+ isolateAccountCallbackInput,
196
+ projectAccountList
197
+ };
@@ -225,6 +225,11 @@ function wrapMcpServer(inner, compliance, adcpVersion = import_version.ADCP_VERS
225
225
  return handler({ method: request.method, params: request.params ?? {} }, extra);
226
226
  };
227
227
  const invoke = async (options2) => {
228
+ if (options2.authInfo?.extra?.identity33 || options2.authInfo?.extra?.webBotAuthAuthorization) {
229
+ const { getWebBotAuthAuthorizationFailure, webBotAuthToolFailure } = require('../signing/web-bot-auth.js');
230
+ const failure = getWebBotAuthAuthorizationFailure(options2.authInfo.extra);
231
+ if (failure) return webBotAuthToolFailure(failure, adcpVersion);
232
+ }
228
233
  const tool = getRegisteredTool(mcp, options2.toolName);
229
234
  if (!tool) {
230
235
  throw new Error(`AdcpServer.invoke: tool "${options2.toolName}" is not registered`);
@@ -1,3 +1,8 @@
1
+ import { fileURLToPath as __adcpFileURLToPath } from "node:url";
2
+ import { dirname as __adcpDirname } from "node:path";
3
+ import { createRequire as __adcpCreateRequire } from "node:module";
4
+ const __dirname = __adcpDirname(__adcpFileURLToPath(import.meta.url));
5
+ const require2 = __adcpCreateRequire(import.meta.url);
1
6
  import { ADCP_VERSION } from "../version.mjs";
2
7
  import {
3
8
  applyStructuredContentTextFallback
@@ -175,6 +180,11 @@ function wrapMcpServer(inner, compliance, adcpVersion = ADCP_VERSION, options =
175
180
  return handler({ method: request.method, params: request.params ?? {} }, extra);
176
181
  };
177
182
  const invoke = async (options2) => {
183
+ if (options2.authInfo?.extra?.identity33 || options2.authInfo?.extra?.webBotAuthAuthorization) {
184
+ const { getWebBotAuthAuthorizationFailure, webBotAuthToolFailure } = require2("../signing/web-bot-auth");
185
+ const failure = getWebBotAuthAuthorizationFailure(options2.authInfo.extra);
186
+ if (failure) return webBotAuthToolFailure(failure, adcpVersion);
187
+ }
178
188
  const tool = getRegisteredTool(mcp, options2.toolName);
179
189
  if (!tool) {
180
190
  throw new Error(`AdcpServer.invoke: tool "${options2.toolName}" is not registered`);
@@ -38,6 +38,7 @@
38
38
  * `serve()` buffers `req.rawBody` before authentication runs.
39
39
  */
40
40
  import type { IncomingMessage } from 'http';
41
+ import { type VerifiedWebBotSigner } from '../signing/web-bot-auth.mjs';
41
42
  import type { JwksResolver } from '../signing/jwks.mjs';
42
43
  import { type ReplayStore } from '../signing/replay.mjs';
43
44
  import { type RevocationStore } from '../signing/revocation.mjs';
@@ -45,6 +46,20 @@ import type { VerifiedSigner, VerifierCapability } from '../signing/types.mjs';
45
46
  import { type OperationResolutionInput, type ResolvedOperation } from '../signing/operation-resolution.mjs';
46
47
  import { type AuthPrincipal, type Authenticator } from './auth.mjs';
47
48
  export interface VerifySignatureAsAuthenticatorOptions {
49
+ /** Explicit experimental profile. Verification never creates a principal or fetches trust.json. */
50
+ webBotAuth?: {
51
+ directory: import('../signing/web-bot-auth.mjs').SignatureDirectoryResolver;
52
+ /**
53
+ * @deprecated Revocation belongs to the identity layer: use
54
+ * `createIdentity33PrincipalResolver({ revocation })`. Required only when
55
+ * `resolvePrincipal` does not check revocation itself.
56
+ */
57
+ isRevoked?: (origin: string, keyid: string) => Promise<boolean>;
58
+ /** Resolve only an existing audited binding; handle identity-established callers with anonymous scope. */
59
+ resolvePrincipal: (signers: readonly VerifiedWebBotSigner[], operation: ResolvedOperation) => Promise<AuthPrincipal>;
60
+ };
61
+ /** Refuse legacy credentials for an origin already bound to Web Bot Auth. */
62
+ assertLegacyOriginAllowed?: (agentUrl: string) => Promise<void>;
48
63
  /** Verifier capability block. `required_for` is not enforced here — unsigned
49
64
  * requests fall through to the next authenticator — so set it to whatever
50
65
  * your `request_signing` capability claim advertises. */
@@ -38,6 +38,7 @@
38
38
  * `serve()` buffers `req.rawBody` before authentication runs.
39
39
  */
40
40
  import type { IncomingMessage } from 'http';
41
+ import { type VerifiedWebBotSigner } from '../signing/web-bot-auth';
41
42
  import type { JwksResolver } from '../signing/jwks';
42
43
  import { type ReplayStore } from '../signing/replay';
43
44
  import { type RevocationStore } from '../signing/revocation';
@@ -45,6 +46,20 @@ import type { VerifiedSigner, VerifierCapability } from '../signing/types';
45
46
  import { type OperationResolutionInput, type ResolvedOperation } from '../signing/operation-resolution';
46
47
  import { type AuthPrincipal, type Authenticator } from './auth';
47
48
  export interface VerifySignatureAsAuthenticatorOptions {
49
+ /** Explicit experimental profile. Verification never creates a principal or fetches trust.json. */
50
+ webBotAuth?: {
51
+ directory: import('../signing/web-bot-auth').SignatureDirectoryResolver;
52
+ /**
53
+ * @deprecated Revocation belongs to the identity layer: use
54
+ * `createIdentity33PrincipalResolver({ revocation })`. Required only when
55
+ * `resolvePrincipal` does not check revocation itself.
56
+ */
57
+ isRevoked?: (origin: string, keyid: string) => Promise<boolean>;
58
+ /** Resolve only an existing audited binding; handle identity-established callers with anonymous scope. */
59
+ resolvePrincipal: (signers: readonly VerifiedWebBotSigner[], operation: ResolvedOperation) => Promise<AuthPrincipal>;
60
+ };
61
+ /** Refuse legacy credentials for an origin already bound to Web Bot Auth. */
62
+ assertLegacyOriginAllowed?: (agentUrl: string) => Promise<void>;
48
63
  /** Verifier capability block. `required_for` is not enforced here — unsigned
49
64
  * requests fall through to the next authenticator — so set it to whatever
50
65
  * your `request_signing` capability claim advertises. */
@@ -26,7 +26,9 @@ __export(auth_signature_exports, {
26
26
  verifySignatureAsAuthenticator: () => verifySignatureAsAuthenticator
27
27
  });
28
28
  module.exports = __toCommonJS(auth_signature_exports);
29
+ var import_web_bot_auth = require('../signing/web-bot-auth.js');
29
30
  var import_errors = require('../signing/errors.js');
31
+ var import_web_bot_auth2 = require('../signing/web-bot-auth.js');
30
32
  var import_replay = require('../signing/replay.js');
31
33
  var import_revocation = require('../signing/revocation.js');
32
34
  var import_operation_resolution = require('../signing/operation-resolution.js');
@@ -35,6 +37,15 @@ var import_buyer_agent = require('./decisioning/buyer-agent.js');
35
37
  var import_auth = require('./auth.js');
36
38
  function verifySignatureAsAuthenticator(options) {
37
39
  const replayStore = options.replayStore ?? new import_replay.InMemoryReplayStore();
40
+ const legacyOriginGate = options.assertLegacyOriginAllowed ?? (0, import_web_bot_auth.getWebBotAuthLegacyOriginGate)(options.webBotAuth?.resolvePrincipal);
41
+ if (options.webBotAuth && !legacyOriginGate)
42
+ throw new TypeError(
43
+ "Web Bot Auth requires an origin-binding migration fence; use createIdentity33PrincipalResolver or supply assertLegacyOriginAllowed"
44
+ );
45
+ if (options.webBotAuth && !options.webBotAuth.isRevoked && !(0, import_web_bot_auth2.isWebBotAuthRevocationChecked)(options.webBotAuth.resolvePrincipal))
46
+ throw new TypeError(
47
+ "Web Bot Auth requires origin revocation: use createIdentity33PrincipalResolver({ revocation }) or supply isRevoked"
48
+ );
38
49
  const revocationStore = options.revocationStore ?? new import_revocation.InMemoryRevocationStore();
39
50
  const authenticator = async (req) => {
40
51
  if (!hasSignatureHeader(req)) return null;
@@ -48,6 +59,49 @@ function verifySignatureAsAuthenticator(options) {
48
59
  };
49
60
  let result;
50
61
  try {
62
+ if ((0, import_web_bot_auth2.selectSignatureProfile)(requestLike) === "web-bot-auth") {
63
+ if (!options.getUrl && !(0, import_auth.getServeRequestContext)(req)?.publicUrl || !options.webBotAuth || !options.capability.profiles?.includes("web-bot-auth"))
64
+ throw new import_web_bot_auth2.WebBotAuthError(403, "profile_disabled");
65
+ if (req.method !== "GET" && req.rawBody === void 0)
66
+ throw new import_web_bot_auth2.WebBotAuthError(403, "raw_body_missing");
67
+ const signers = await (0, import_web_bot_auth2.verifyWebBotAuth)(requestLike, {
68
+ directory: options.webBotAuth.directory,
69
+ replayStore,
70
+ now: options.now,
71
+ ...options.webBotAuth.isRevoked && { isRevoked: options.webBotAuth.isRevoked }
72
+ });
73
+ const operation = options.resolveOperation(req);
74
+ let principal2;
75
+ let deferredFailure;
76
+ try {
77
+ principal2 = await options.webBotAuth.resolvePrincipal(signers, operation);
78
+ } catch (error) {
79
+ if (error instanceof import_web_bot_auth2.WebBotAuthError || error instanceof import_web_bot_auth2.WebBotAuthUnavailableError) throw error;
80
+ if (typeof operation !== "string") throw (0, import_web_bot_auth2.webBotAuthPrincipalFailureError)(error);
81
+ const deferred = (0, import_web_bot_auth2.deferWebBotAuthPrincipalFailure)(signers, error);
82
+ principal2 = { principal: deferred.principal };
83
+ deferredFailure = deferred.authorizationFailure;
84
+ }
85
+ const signer2 = signers[signers.length - 1];
86
+ req.verifiedSigner = {
87
+ keyid: signer2.keyid,
88
+ agent_url: signer2.origin,
89
+ verified_at: signer2.verified_at
90
+ };
91
+ const failed = signers.find((s) => s.authorizationFailure);
92
+ return {
93
+ ...principal2,
94
+ extra: {
95
+ ...principal2.extra,
96
+ webBotAuthAuthorization: {
97
+ signer: failed ?? signer2,
98
+ ...(failed?.authorizationFailure ?? deferredFailure) && {
99
+ authorizationFailure: failed?.authorizationFailure ?? deferredFailure
100
+ }
101
+ }
102
+ }
103
+ };
104
+ }
51
105
  result = await (0, import_verifier.verifyRequestSignature)(requestLike, {
52
106
  capability: options.capability,
53
107
  jwks: options.jwks,
@@ -58,7 +112,22 @@ function verifySignatureAsAuthenticator(options) {
58
112
  operation: options.resolveOperation(req),
59
113
  agentUrlForKeyid: options.agentUrlForKeyid
60
114
  });
115
+ if (result.status === "verified" && legacyOriginGate) {
116
+ if (!result.agent_url)
117
+ throw new import_errors.RequestSignatureError(
118
+ "request_signature_key_unknown",
119
+ 7,
120
+ "Legacy signer must resolve an agent origin when migration fencing is enabled"
121
+ );
122
+ await legacyOriginGate(result.agent_url);
123
+ }
61
124
  } catch (err) {
125
+ if (err instanceof import_web_bot_auth2.WebBotAuthError)
126
+ throw new import_auth.AuthError(err.message, { cause: err, status: err.status, headers: err.headers, body: err.body });
127
+ if (err instanceof import_web_bot_auth2.WebBotAuthUnavailableError) {
128
+ const outage = (0, import_web_bot_auth2.webBotAuthUnavailableResponse)();
129
+ throw new import_auth.AuthError(err.message, { cause: err, ...outage });
130
+ }
62
131
  if (err instanceof import_errors.RequestSignatureError) {
63
132
  throw new import_auth.AuthError(`Signature rejected (${err.code}).`, { cause: err });
64
133
  }
@@ -79,7 +148,8 @@ function verifySignatureAsAuthenticator(options) {
79
148
  req.verifiedSigner = signer;
80
149
  return principal;
81
150
  };
82
- return (0, import_auth.tagAuthenticatorNeedsRawBody)(authenticator);
151
+ const tagged = (0, import_auth.tagAuthenticatorNeedsRawBody)(authenticator);
152
+ return options.webBotAuth ? (0, import_auth.tagAuthenticatorPresenceGated)(tagged) : tagged;
83
153
  }
84
154
  function principalForVerifiedSigner(signer, makePrincipal) {
85
155
  if (!SAFE_KEYID.test(signer.keyid)) {
@@ -206,7 +276,7 @@ function logUnresolvable(req) {
206
276
  }
207
277
  const SAFE_KEYID = /^[A-Za-z0-9._-]{1,256}$/;
208
278
  function hasSignatureHeader(req) {
209
- return nonEmptyHeader(req.headers["signature-input"]) || nonEmptyHeader(req.headers["signature"]);
279
+ return req.headers["signature-agent"] !== void 0 || nonEmptyHeader(req.headers["signature-input"]) || nonEmptyHeader(req.headers["signature"]);
210
280
  }
211
281
  function nonEmptyHeader(v) {
212
282
  if (typeof v === "string") return v.length > 0;