@adcp/sdk 14.0.0-rc.37 → 14.0.0-rc.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/adcp-storyboard-summary.js +286 -0
- package/bin/adcp.js +221 -10
- package/dist/lib/conformance/schemaLoader.d.mts +1 -1
- package/dist/lib/conformance/schemaLoader.d.ts +1 -1
- package/dist/lib/core/AgentClient.d.mts +6 -1
- package/dist/lib/core/AgentClient.d.ts +6 -1
- package/dist/lib/core/AgentClient.js +9 -0
- package/dist/lib/core/AgentClient.mjs +9 -0
- package/dist/lib/core/ConversationTypes.d.mts +29 -0
- package/dist/lib/core/ConversationTypes.d.ts +29 -0
- package/dist/lib/core/SingleAgentClient.d.mts +3 -1
- package/dist/lib/core/SingleAgentClient.d.ts +3 -1
- package/dist/lib/core/SingleAgentClient.js +9 -1
- package/dist/lib/core/SingleAgentClient.mjs +9 -1
- package/dist/lib/core/TaskExecutor.d.mts +13 -1
- package/dist/lib/core/TaskExecutor.d.ts +13 -1
- package/dist/lib/core/TaskExecutor.js +216 -18
- package/dist/lib/core/TaskExecutor.mjs +216 -19
- package/dist/lib/index.d.mts +5 -2
- package/dist/lib/index.d.ts +5 -2
- package/dist/lib/index.js +10 -1
- package/dist/lib/index.mjs +10 -1
- package/dist/lib/media-buy/action-assessment.d.mts +77 -0
- package/dist/lib/media-buy/action-assessment.d.ts +77 -0
- package/dist/lib/media-buy/action-assessment.js +300 -0
- package/dist/lib/media-buy/action-assessment.mjs +284 -0
- package/dist/lib/media-buy/action-constraints.d.mts +9 -0
- package/dist/lib/media-buy/action-constraints.d.ts +9 -0
- package/dist/lib/media-buy/action-constraints.js +170 -0
- package/dist/lib/media-buy/action-constraints.mjs +146 -0
- package/dist/lib/media-buy/action-contracts.d.mts +40 -0
- package/dist/lib/media-buy/action-contracts.d.ts +40 -0
- package/dist/lib/media-buy/action-contracts.js +304 -0
- package/dist/lib/media-buy/action-contracts.mjs +267 -0
- package/dist/lib/media-buy/action-metadata.generated.d.mts +37 -0
- package/dist/lib/media-buy/action-metadata.generated.d.ts +37 -0
- package/dist/lib/media-buy/action-metadata.generated.js +128 -0
- package/dist/lib/media-buy/action-metadata.generated.mjs +101 -0
- package/dist/lib/media-buy/action-types.d.mts +106 -0
- package/dist/lib/media-buy/action-types.d.ts +106 -0
- package/dist/lib/{types/v3-1-beta/tools.generated.js → media-buy/action-types.js} +2 -2
- package/dist/lib/media-buy/actions.d.mts +6 -0
- package/dist/lib/media-buy/actions.d.ts +6 -0
- package/dist/lib/media-buy/actions.js +38 -0
- package/dist/lib/media-buy/actions.mjs +9 -0
- package/dist/lib/media-buy/available-actions.d.mts +2 -1
- package/dist/lib/media-buy/available-actions.d.ts +2 -1
- package/dist/lib/media-buy/available-actions.js +4 -3
- package/dist/lib/media-buy/available-actions.mjs +4 -3
- package/dist/lib/media-buy/compatibility.js +3 -0
- package/dist/lib/media-buy/compatibility.mjs +3 -0
- package/dist/lib/media-buy/index.d.mts +4 -0
- package/dist/lib/media-buy/index.d.ts +4 -0
- package/dist/lib/media-buy/index.js +3 -1
- package/dist/lib/media-buy/index.mjs +1 -0
- package/dist/lib/media-buy/legacy-action-ids.d.mts +1 -0
- package/dist/lib/media-buy/legacy-action-ids.d.ts +1 -0
- package/dist/lib/media-buy/legacy-action-ids.js +50 -0
- package/dist/lib/media-buy/legacy-action-ids.mjs +26 -0
- package/dist/lib/media-buy/mutations.d.mts +70 -0
- package/dist/lib/media-buy/mutations.d.ts +70 -0
- package/dist/lib/media-buy/mutations.js +525 -0
- package/dist/lib/media-buy/mutations.mjs +498 -0
- package/dist/lib/media-buy/preflight.d.mts +20 -69
- package/dist/lib/media-buy/preflight.d.ts +20 -69
- package/dist/lib/media-buy/preflight.js +100 -336
- package/dist/lib/media-buy/preflight.mjs +111 -333
- package/dist/lib/media-buy/targeting-input.d.mts +7 -4
- package/dist/lib/media-buy/targeting-input.d.ts +7 -4
- package/dist/lib/media-buy/types.d.mts +55 -7
- package/dist/lib/media-buy/types.d.ts +55 -7
- package/dist/lib/protocols/rawResponseCapture.d.mts +12 -0
- package/dist/lib/protocols/rawResponseCapture.d.ts +12 -0
- package/dist/lib/protocols/rawResponseCapture.js +33 -3
- package/dist/lib/protocols/rawResponseCapture.mjs +32 -3
- package/dist/lib/registry/types.generated.d.mts +377 -9
- package/dist/lib/registry/types.generated.d.ts +377 -9
- package/dist/lib/reporting/content-mismatch.d.mts +126 -0
- package/dist/lib/reporting/content-mismatch.d.ts +126 -0
- package/dist/lib/reporting/content-mismatch.js +90 -0
- package/dist/lib/reporting/content-mismatch.mjs +66 -0
- package/dist/lib/reporting/evidence.d.mts +1 -0
- package/dist/lib/reporting/evidence.d.ts +1 -0
- package/dist/lib/reporting/evidence.js +32 -3
- package/dist/lib/reporting/evidence.mjs +31 -3
- package/dist/lib/reporting/index.d.mts +3 -1
- package/dist/lib/reporting/index.d.ts +3 -1
- package/dist/lib/reporting/index.js +3 -0
- package/dist/lib/reporting/index.mjs +2 -0
- package/dist/lib/reporting/ledger/handler.d.mts +51 -1
- package/dist/lib/reporting/ledger/handler.d.ts +51 -1
- package/dist/lib/reporting/ledger/handler.js +306 -38
- package/dist/lib/reporting/ledger/handler.mjs +304 -37
- package/dist/lib/reporting/ledger/health.d.mts +12 -0
- package/dist/lib/reporting/ledger/health.d.ts +12 -0
- package/dist/lib/reporting/ledger/health.js +15 -2
- package/dist/lib/reporting/ledger/health.mjs +13 -1
- package/dist/lib/reporting/ledger/index.d.mts +3 -0
- package/dist/lib/reporting/ledger/index.d.ts +3 -0
- package/dist/lib/reporting/ledger/index.js +7 -1
- package/dist/lib/reporting/ledger/index.mjs +3 -0
- package/dist/lib/reporting/ledger/lifecycle.d.mts +31 -4
- package/dist/lib/reporting/ledger/lifecycle.d.ts +31 -4
- package/dist/lib/reporting/ledger/lifecycle.js +244 -37
- package/dist/lib/reporting/ledger/lifecycle.mjs +244 -37
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +231 -0
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +231 -0
- package/dist/lib/reporting/ledger/managed-postgres.js +1797 -0
- package/dist/lib/reporting/ledger/managed-postgres.mjs +1776 -0
- package/dist/lib/reporting/ledger/managed.d.mts +355 -0
- package/dist/lib/reporting/ledger/managed.d.ts +355 -0
- package/dist/lib/reporting/ledger/managed.js +661 -0
- package/dist/lib/reporting/ledger/managed.mjs +633 -0
- package/dist/lib/reporting/ledger/notification-activity.d.mts +222 -0
- package/dist/lib/reporting/ledger/notification-activity.d.ts +222 -0
- package/dist/lib/reporting/ledger/notification-activity.js +1139 -0
- package/dist/lib/reporting/ledger/notification-activity.mjs +1110 -0
- package/dist/lib/reporting/ledger/postgres.d.mts +161 -1
- package/dist/lib/reporting/ledger/postgres.d.ts +161 -1
- package/dist/lib/reporting/ledger/postgres.js +1153 -21
- package/dist/lib/reporting/ledger/postgres.mjs +1152 -21
- package/dist/lib/reporting/ledger/producer.d.mts +8 -0
- package/dist/lib/reporting/ledger/producer.d.ts +8 -0
- package/dist/lib/reporting/ledger/producer.js +146 -52
- package/dist/lib/reporting/ledger/producer.mjs +146 -51
- package/dist/lib/reporting/ledger/types.d.mts +358 -1
- package/dist/lib/reporting/ledger/types.d.ts +358 -1
- package/dist/lib/reporting/ledger/types.js +3 -0
- package/dist/lib/reporting/ledger/types.mjs +2 -0
- package/dist/lib/reporting/reconciliation.d.mts +362 -2
- package/dist/lib/reporting/reconciliation.d.ts +362 -2
- package/dist/lib/reporting/reconciliation.js +1051 -7
- package/dist/lib/reporting/reconciliation.mjs +1053 -7
- package/dist/lib/reporting/service/conformance.d.mts +35 -0
- package/dist/lib/reporting/service/conformance.d.ts +35 -0
- package/dist/lib/reporting/service/conformance.js +89 -0
- package/dist/lib/reporting/service/conformance.mjs +68 -0
- package/dist/lib/reporting/service/index.d.mts +182 -0
- package/dist/lib/reporting/service/index.d.ts +182 -0
- package/dist/lib/reporting/service/index.js +793 -0
- package/dist/lib/reporting/service/index.mjs +787 -0
- package/dist/lib/reporting/source/index.d.mts +2 -1
- package/dist/lib/reporting/source/index.d.ts +2 -1
- package/dist/lib/reporting/source/index.js +16 -3
- package/dist/lib/reporting/source/index.mjs +12 -1
- package/dist/lib/reporting/source/inline.d.mts +88 -1
- package/dist/lib/reporting/source/inline.d.ts +88 -1
- package/dist/lib/reporting/source/inline.js +1161 -163
- package/dist/lib/reporting/source/inline.mjs +1166 -163
- package/dist/lib/reporting/source/manifest.js +12 -7
- package/dist/lib/reporting/source/manifest.mjs +12 -7
- package/dist/lib/reporting/source/source.d.mts +26 -0
- package/dist/lib/reporting/source/source.d.ts +26 -0
- package/dist/lib/reporting/source/source.js +71 -2
- package/dist/lib/reporting/source/source.mjs +65 -1
- package/dist/lib/schemas/index.d.mts +22 -1
- package/dist/lib/schemas/index.d.ts +22 -1
- package/dist/lib/schemas/index.js +7 -0
- package/dist/lib/schemas/index.mjs +7 -0
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/server/create-adcp-server.d.mts +18 -0
- package/dist/lib/server/create-adcp-server.d.ts +18 -0
- package/dist/lib/server/create-adcp-server.js +52 -2
- package/dist/lib/server/create-adcp-server.mjs +52 -2
- package/dist/lib/server/decisioning/account.d.mts +1 -1
- package/dist/lib/server/decisioning/account.d.ts +1 -1
- package/dist/lib/server/decisioning/index.d.mts +1 -0
- package/dist/lib/server/decisioning/index.d.ts +1 -0
- package/dist/lib/server/decisioning/platform.d.mts +3 -0
- package/dist/lib/server/decisioning/platform.d.ts +3 -0
- package/dist/lib/server/decisioning/runtime/from-platform.js +88 -10
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +88 -10
- package/dist/lib/server/decisioning/specialisms/reporting.d.mts +38 -0
- package/dist/lib/server/decisioning/specialisms/reporting.d.ts +38 -0
- package/dist/lib/{types/v3-1-beta/index.js → server/decisioning/specialisms/reporting.js} +2 -8
- package/dist/lib/server/decisioning/specialisms/reporting.mjs +0 -0
- package/dist/lib/server/index.d.mts +4 -2
- package/dist/lib/server/index.d.ts +4 -2
- package/dist/lib/server/index.js +5 -0
- package/dist/lib/server/index.mjs +4 -0
- package/dist/lib/server/media-buy-action-resolver.d.mts +63 -0
- package/dist/lib/server/media-buy-action-resolver.d.ts +63 -0
- package/dist/lib/server/media-buy-action-resolver.js +297 -0
- package/dist/lib/server/media-buy-action-resolver.mjs +285 -0
- package/dist/lib/server/media-buy-actions.d.mts +7 -8
- package/dist/lib/server/media-buy-actions.d.ts +7 -8
- package/dist/lib/server/media-buy-actions.js +57 -14
- package/dist/lib/server/media-buy-actions.mjs +63 -14
- package/dist/lib/server/notification-subscriptions/index.d.mts +2 -2
- package/dist/lib/server/notification-subscriptions/index.d.ts +2 -2
- package/dist/lib/server/notification-subscriptions/index.js +2 -0
- package/dist/lib/server/notification-subscriptions/index.mjs +2 -0
- package/dist/lib/server/notification-subscriptions/postgres-runtime.d.mts +3 -1
- package/dist/lib/server/notification-subscriptions/postgres-runtime.d.ts +3 -1
- package/dist/lib/server/notification-subscriptions/postgres-runtime.js +1 -0
- package/dist/lib/server/notification-subscriptions/postgres-runtime.mjs +1 -0
- package/dist/lib/server/notification-subscriptions/runtime.d.mts +12 -1
- package/dist/lib/server/notification-subscriptions/runtime.d.ts +12 -1
- package/dist/lib/server/notification-subscriptions/runtime.js +102 -16
- package/dist/lib/server/notification-subscriptions/runtime.mjs +101 -16
- package/dist/lib/server/notification-subscriptions/types.d.mts +104 -1
- package/dist/lib/server/notification-subscriptions/types.d.ts +104 -1
- package/dist/lib/server/webhook-emitter.d.mts +40 -5
- package/dist/lib/server/webhook-emitter.d.ts +40 -5
- package/dist/lib/server/webhook-emitter.js +23 -12
- package/dist/lib/server/webhook-emitter.mjs +23 -12
- package/dist/lib/storage/interfaces.d.mts +14 -2
- package/dist/lib/storage/interfaces.d.ts +14 -2
- package/dist/lib/testing/compliance/comply.d.mts +9 -3
- package/dist/lib/testing/compliance/comply.d.ts +9 -3
- package/dist/lib/testing/compliance/comply.js +158 -3
- package/dist/lib/testing/compliance/comply.mjs +159 -4
- package/dist/lib/testing/compliance/storyboard-tracks.js +7 -5
- package/dist/lib/testing/compliance/storyboard-tracks.mjs +7 -5
- package/dist/lib/testing/compliance/summary.js +10 -1
- package/dist/lib/testing/compliance/summary.mjs +10 -1
- package/dist/lib/testing/index.d.mts +1 -1
- package/dist/lib/testing/index.d.ts +1 -1
- package/dist/lib/testing/index.js +2 -0
- package/dist/lib/testing/index.mjs +3 -1
- package/dist/lib/testing/storyboard/agent-routing.d.mts +12 -43
- package/dist/lib/testing/storyboard/agent-routing.d.ts +12 -43
- package/dist/lib/testing/storyboard/agent-routing.js +75 -13
- package/dist/lib/testing/storyboard/agent-routing.mjs +70 -12
- package/dist/lib/testing/storyboard/index.d.mts +1 -0
- package/dist/lib/testing/storyboard/index.d.ts +1 -0
- package/dist/lib/testing/storyboard/index.js +3 -0
- package/dist/lib/testing/storyboard/index.mjs +2 -0
- package/dist/lib/testing/storyboard/junit.d.mts +1 -1
- package/dist/lib/testing/storyboard/junit.d.ts +1 -1
- package/dist/lib/testing/storyboard/junit.js +21 -2
- package/dist/lib/testing/storyboard/junit.mjs +21 -2
- package/dist/lib/testing/storyboard/probes.d.mts +130 -0
- package/dist/lib/testing/storyboard/probes.d.ts +130 -0
- package/dist/lib/testing/storyboard/probes.js +682 -10
- package/dist/lib/testing/storyboard/probes.mjs +683 -3
- package/dist/lib/testing/storyboard/request-signing/builder.d.mts +16 -5
- package/dist/lib/testing/storyboard/request-signing/builder.d.ts +16 -5
- package/dist/lib/testing/storyboard/request-signing/grader.d.mts +44 -1
- package/dist/lib/testing/storyboard/request-signing/grader.d.ts +44 -1
- package/dist/lib/testing/storyboard/request-signing/grader.js +46 -22
- package/dist/lib/testing/storyboard/request-signing/grader.mjs +43 -21
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.mts +86 -11
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.d.ts +86 -11
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js +119 -25
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs +117 -26
- package/dist/lib/testing/storyboard/request-signing/synthesize.js +22 -2
- package/dist/lib/testing/storyboard/request-signing/synthesize.mjs +22 -2
- package/dist/lib/testing/storyboard/runner.d.mts +103 -0
- package/dist/lib/testing/storyboard/runner.d.ts +103 -0
- package/dist/lib/testing/storyboard/runner.js +1090 -268
- package/dist/lib/testing/storyboard/runner.mjs +1096 -261
- package/dist/lib/testing/storyboard/seeding.d.mts +4 -1
- package/dist/lib/testing/storyboard/seeding.d.ts +4 -1
- package/dist/lib/testing/storyboard/seeding.js +55 -24
- package/dist/lib/testing/storyboard/seeding.mjs +55 -24
- package/dist/lib/testing/storyboard/test-kit.d.mts +37 -3
- package/dist/lib/testing/storyboard/test-kit.d.ts +37 -3
- package/dist/lib/testing/storyboard/test-kit.js +8 -2
- package/dist/lib/testing/storyboard/test-kit.mjs +7 -2
- package/dist/lib/testing/storyboard/types.d.mts +132 -10
- package/dist/lib/testing/storyboard/types.d.ts +132 -10
- package/dist/lib/testing/storyboard/types.js +17 -0
- package/dist/lib/testing/storyboard/types.mjs +16 -0
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/testing/storyboard/validations.js +16 -0
- package/dist/lib/testing/storyboard/validations.mjs +16 -0
- package/dist/lib/testing/test-controller.d.mts +1 -1
- package/dist/lib/testing/test-controller.d.ts +1 -1
- package/dist/lib/types/buy-products.d.ts +71 -6
- package/dist/lib/types/control-media-buy.d.ts +25 -11
- package/dist/lib/types/core.generated.d.mts +69 -10
- package/dist/lib/types/core.generated.d.ts +69 -10
- package/dist/lib/types/create-media-buy.d.ts +71 -6
- package/dist/lib/types/forward-compat-error-codes.d.mts +7 -6
- package/dist/lib/types/forward-compat-error-codes.d.ts +7 -6
- package/dist/lib/types/index.d.mts +2 -2
- package/dist/lib/types/index.d.ts +2 -2
- package/dist/lib/types/schemas.generated.d.ts +8040 -8116
- package/dist/lib/types/schemas.generated.js +1074 -309
- package/dist/lib/types/schemas.generated.mjs +1068 -309
- package/dist/lib/types/tools.generated.d.mts +65 -6
- package/dist/lib/types/tools.generated.d.ts +65 -6
- package/dist/lib/types/update-media-buy.d.ts +71 -6
- package/dist/lib/utils/redact-secrets.d.mts +1 -1
- package/dist/lib/utils/redact-secrets.d.ts +1 -1
- package/dist/lib/utils/redact-secrets.js +1 -1
- package/dist/lib/utils/redact-secrets.mjs +1 -1
- package/dist/lib/v2/projection/cache-versions.d.mts +0 -1
- package/dist/lib/v2/projection/cache-versions.d.ts +0 -1
- package/dist/lib/v2/projection/cache-versions.js +1 -15
- package/dist/lib/v2/projection/cache-versions.mjs +1 -14
- package/dist/lib/v2/projection/canonical-properties.js +2 -2
- package/dist/lib/v2/projection/canonical-properties.mjs +3 -3
- package/dist/lib/v2/projection/registry.d.mts +1 -1
- package/dist/lib/v2/projection/registry.d.ts +1 -1
- package/dist/lib/v2/projection/registry.js +2 -2
- package/dist/lib/v2/projection/registry.mjs +3 -3
- package/dist/lib/validation/schema-loader.d.mts +9 -1
- package/dist/lib/validation/schema-loader.d.ts +9 -1
- package/dist/lib/validation/schema-loader.js +65 -8
- package/dist/lib/validation/schema-loader.mjs +64 -8
- package/dist/lib/version.d.mts +5 -5
- package/dist/lib/version.d.ts +5 -5
- package/dist/lib/version.js +3 -8
- package/dist/lib/version.mjs +3 -8
- package/dist/lib/wholesale-feed-sync/index.d.mts +1 -0
- package/dist/lib/wholesale-feed-sync/index.d.ts +1 -0
- package/dist/lib/wholesale-feed-sync/protocol-types.d.mts +42 -0
- package/dist/lib/wholesale-feed-sync/protocol-types.d.ts +42 -0
- package/dist/lib/wholesale-feed-sync/protocol-types.js +16 -0
- package/dist/lib/wholesale-feed-sync/protocol-types.mjs +0 -0
- package/dist/lib/wholesale-feed-sync/sync.d.mts +6 -6
- package/dist/lib/wholesale-feed-sync/sync.d.ts +6 -6
- package/dist/lib/wholesale-feed-sync/sync.js +3 -1
- package/dist/lib/wholesale-feed-sync/sync.mjs +3 -1
- package/dist/lib/wholesale-feed-sync/types.d.mts +15 -14
- package/dist/lib/wholesale-feed-sync/types.d.ts +15 -14
- package/dist/lib/wholesale-feed-sync/webhook-notification.d.mts +7 -5
- package/dist/lib/wholesale-feed-sync/webhook-notification.d.ts +7 -5
- package/dist/lib/wholesale-feed-sync/webhook-notification.js +45 -0
- package/dist/lib/wholesale-feed-sync/webhook-notification.mjs +44 -0
- package/docs/CLI.md +1 -1
- package/docs/TYPE-SUMMARY.md +118 -4
- package/docs/guides/ASYNC-API-REFERENCE.md +62 -1
- package/docs/guides/ASYNC-DEVELOPER-GUIDE.md +25 -0
- package/docs/guides/ASYNC-DOCUMENTATION-INDEX.md +3 -0
- package/docs/guides/BUYER-QUICKSTART-3.2.md +5 -0
- package/docs/guides/DURABLE-BUYER-WRITES.md +337 -0
- package/docs/guides/EXISTING-PLATFORM.md +80 -1
- package/docs/guides/MEDIA-BUY-3.2-COMPATIBILITY.md +57 -0
- package/docs/guides/MEDIA-BUY-ACTION-ASSESSMENT.md +300 -0
- package/docs/guides/REPORTING-LEDGER.md +654 -3
- package/docs/guides/REPORTING-RECONCILIATION.md +50 -0
- package/docs/guides/REPORTING-SOURCE-EXECUTOR.md +63 -1
- package/docs/guides/SELLER-QUICKSTART-3.2.md +2 -0
- package/docs/guides/VALIDATE-YOUR-AGENT.md +35 -0
- package/docs/guides/idempotency-crash-recovery.md +4 -0
- package/docs/llms.txt +4 -2
- package/docs/migration-14.x-rc-worksheet.md +60 -5
- package/docs/migration-7.9-to-7.10.md +7 -5
- package/examples/README.md +17 -0
- package/examples/durable-buyer-writes/caller.ts +745 -0
- package/examples/durable-buyer-writes/worker.ts +240 -0
- package/examples/reliable-reporting-service/README.md +100 -0
- package/examples/seller-3.2-starter.ts +7 -8
- package/examples/targeting-input-existing-platform.ts +153 -0
- package/package.json +41 -29
- package/skills/build-seller-agent/SKILL.md +2 -0
- package/skills/build-seller-agent/specialisms/signed-requests.md +11 -1
- package/skills/cross-cutting.md +28 -11
- package/compliance/cache/3.1.0-beta.7/domains/brand/index.yaml +0 -160
- package/compliance/cache/3.1.0-beta.7/domains/brand/scenarios/distributed_brand_resolution.yaml +0 -415
- package/compliance/cache/3.1.0-beta.7/domains/brand/scenarios/single_side_trust_extension.yaml +0 -454
- package/compliance/cache/3.1.0-beta.7/domains/creative/index.yaml +0 -339
- package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/billing_out_of_band.yaml +0 -153
- package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/creative_lifecycle_webhooks.yaml +0 -389
- package/compliance/cache/3.1.0-beta.7/domains/creative/scenarios/native_in_feed.yaml +0 -543
- package/compliance/cache/3.1.0-beta.7/domains/governance/index.yaml +0 -682
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/index.yaml +0 -781
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/audience_buy_flow.yaml +0 -380
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/available_actions.yaml +0 -565
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/billing_finality_delivery.yaml +0 -354
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/canonical_formats.yaml +0 -711
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/clicks_buy_flow.yaml +0 -264
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/completed_views_buy_flow.yaml +0 -344
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/create_media_buy_async.yaml +0 -234
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/creative_fate_after_cancellation.yaml +0 -419
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/creative_reception.yaml +0 -247
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/delivery_reporting.yaml +0 -357
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/dependency_impairment.yaml +0 -633
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/dependency_impairment_cardinality.yaml +0 -800
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/event_dedup_flow.yaml +0 -399
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/frequency_cap_enforcement.yaml +0 -309
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_approved.yaml +0 -214
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_conditions.yaml +0 -199
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_denied.yaml +0 -204
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/governance_denied_recovery.yaml +0 -252
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/invalid_transitions.yaml +0 -289
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/inventory_list_no_match.yaml +0 -148
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/inventory_list_targeting.yaml +0 -276
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/measurement_accountability.yaml +0 -244
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/measurement_terms_rejected.yaml +0 -203
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/pending_creatives_to_start.yaml +0 -274
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/per_creative_conversion_attribution.yaml +0 -500
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/performance_buy_flow.yaml +0 -428
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/performance_buy_flow_roas.yaml +0 -470
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/product_signal_targeting.yaml +0 -373
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_finalize.yaml +0 -399
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_finalize_asap_timing.yaml +0 -264
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/proposal_not_found_errors.yaml +0 -257
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_audit_observation.yaml +0 -333
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_enforcement.yaml +0 -517
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/provenance_truth_of_claim.yaml +0 -294
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/reach_buy_flow.yaml +0 -823
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/refine_finalize_exclusivity.yaml +0 -360
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/refine_products.yaml +0 -148
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_accountability.yaml +0 -293
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_catalog_precondition.yaml +0 -307
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/scenarios/vendor_metric_optimization_flow.yaml +0 -576
- package/compliance/cache/3.1.0-beta.7/domains/media-buy/state-machine.yaml +0 -442
- package/compliance/cache/3.1.0-beta.7/domains/signals/index.yaml +0 -266
- package/compliance/cache/3.1.0-beta.7/domains/sponsored-intelligence/index.yaml +0 -256
- package/compliance/cache/3.1.0-beta.7/index.json +0 -356
- package/compliance/cache/3.1.0-beta.7/protocols/brand/index.yaml +0 -160
- package/compliance/cache/3.1.0-beta.7/protocols/brand/scenarios/distributed_brand_resolution.yaml +0 -415
- package/compliance/cache/3.1.0-beta.7/protocols/brand/scenarios/single_side_trust_extension.yaml +0 -454
- package/compliance/cache/3.1.0-beta.7/protocols/creative/index.yaml +0 -339
- package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/billing_out_of_band.yaml +0 -153
- package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/creative_lifecycle_webhooks.yaml +0 -389
- package/compliance/cache/3.1.0-beta.7/protocols/creative/scenarios/native_in_feed.yaml +0 -543
- package/compliance/cache/3.1.0-beta.7/protocols/governance/index.yaml +0 -682
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/index.yaml +0 -781
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/audience_buy_flow.yaml +0 -380
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/available_actions.yaml +0 -565
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/billing_finality_delivery.yaml +0 -354
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/canonical_formats.yaml +0 -711
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/clicks_buy_flow.yaml +0 -264
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/completed_views_buy_flow.yaml +0 -344
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/create_media_buy_async.yaml +0 -234
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/creative_fate_after_cancellation.yaml +0 -419
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/creative_reception.yaml +0 -247
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/delivery_reporting.yaml +0 -357
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/dependency_impairment.yaml +0 -633
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/dependency_impairment_cardinality.yaml +0 -800
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/event_dedup_flow.yaml +0 -399
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/frequency_cap_enforcement.yaml +0 -309
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_approved.yaml +0 -214
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_conditions.yaml +0 -199
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_denied.yaml +0 -204
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/governance_denied_recovery.yaml +0 -252
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/invalid_transitions.yaml +0 -289
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/inventory_list_no_match.yaml +0 -148
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/inventory_list_targeting.yaml +0 -276
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/measurement_accountability.yaml +0 -244
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/measurement_terms_rejected.yaml +0 -203
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/pending_creatives_to_start.yaml +0 -274
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/per_creative_conversion_attribution.yaml +0 -500
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/performance_buy_flow.yaml +0 -428
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/performance_buy_flow_roas.yaml +0 -470
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/product_signal_targeting.yaml +0 -373
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_finalize.yaml +0 -399
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_finalize_asap_timing.yaml +0 -264
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/proposal_not_found_errors.yaml +0 -257
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_audit_observation.yaml +0 -333
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_enforcement.yaml +0 -517
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/provenance_truth_of_claim.yaml +0 -294
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/reach_buy_flow.yaml +0 -823
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/refine_finalize_exclusivity.yaml +0 -360
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/refine_products.yaml +0 -148
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_accountability.yaml +0 -293
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_catalog_precondition.yaml +0 -307
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/scenarios/vendor_metric_optimization_flow.yaml +0 -576
- package/compliance/cache/3.1.0-beta.7/protocols/media-buy/state-machine.yaml +0 -442
- package/compliance/cache/3.1.0-beta.7/protocols/signals/index.yaml +0 -266
- package/compliance/cache/3.1.0-beta.7/protocols/sponsored-intelligence/index.yaml +0 -256
- package/compliance/cache/3.1.0-beta.7/specialisms/audience-sync/index.yaml +0 -313
- package/compliance/cache/3.1.0-beta.7/specialisms/brand-rights/index.yaml +0 -350
- package/compliance/cache/3.1.0-beta.7/specialisms/brand-rights/scenarios/governance_denied.yaml +0 -226
- package/compliance/cache/3.1.0-beta.7/specialisms/collection-lists/index.yaml +0 -359
- package/compliance/cache/3.1.0-beta.7/specialisms/content-standards/index.yaml +0 -572
- package/compliance/cache/3.1.0-beta.7/specialisms/creative-ad-server/index.yaml +0 -409
- package/compliance/cache/3.1.0-beta.7/specialisms/creative-generative/generative-seller.yaml +0 -807
- package/compliance/cache/3.1.0-beta.7/specialisms/creative-generative/index.yaml +0 -758
- package/compliance/cache/3.1.0-beta.7/specialisms/creative-template/index.yaml +0 -510
- package/compliance/cache/3.1.0-beta.7/specialisms/governance-aware-seller/index.yaml +0 -143
- package/compliance/cache/3.1.0-beta.7/specialisms/governance-aware-seller/scenarios/governance_multi_agent_rejected.yaml +0 -117
- package/compliance/cache/3.1.0-beta.7/specialisms/governance-delivery-monitor/index.yaml +0 -441
- package/compliance/cache/3.1.0-beta.7/specialisms/governance-spend-authority/denied.yaml +0 -221
- package/compliance/cache/3.1.0-beta.7/specialisms/governance-spend-authority/index.yaml +0 -330
- package/compliance/cache/3.1.0-beta.7/specialisms/property-lists/index.yaml +0 -482
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-broadcast-tv/index.yaml +0 -738
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-catalog-driven/index.yaml +0 -840
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-guaranteed/index.yaml +0 -601
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-non-guaranteed/index.yaml +0 -546
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-proposal-mode/index.yaml +0 -586
- package/compliance/cache/3.1.0-beta.7/specialisms/sales-social/index.yaml +0 -919
- package/compliance/cache/3.1.0-beta.7/specialisms/signal-marketplace/index.yaml +0 -424
- package/compliance/cache/3.1.0-beta.7/specialisms/signal-marketplace/scenarios/governance_denied.yaml +0 -211
- package/compliance/cache/3.1.0-beta.7/specialisms/signal-owned/index.yaml +0 -317
- package/compliance/cache/3.1.0-beta.7/specialisms/sponsored-intelligence/index.yaml +0 -59
- package/compliance/cache/3.1.0-beta.7/test-kits/acme-outdoor-live.yaml +0 -78
- package/compliance/cache/3.1.0-beta.7/test-kits/acme-outdoor.yaml +0 -223
- package/compliance/cache/3.1.0-beta.7/test-kits/billing-gate-runner.yaml +0 -115
- package/compliance/cache/3.1.0-beta.7/test-kits/bistro-oranje.yaml +0 -126
- package/compliance/cache/3.1.0-beta.7/test-kits/distributed-brand-runner.yaml +0 -281
- package/compliance/cache/3.1.0-beta.7/test-kits/nova-motors.yaml +0 -262
- package/compliance/cache/3.1.0-beta.7/test-kits/osei-natural.yaml +0 -126
- package/compliance/cache/3.1.0-beta.7/test-kits/parallel-dispatch-runner.yaml +0 -196
- package/compliance/cache/3.1.0-beta.7/test-kits/rate-limit-trip-runner.yaml +0 -172
- package/compliance/cache/3.1.0-beta.7/test-kits/signed-requests-runner.yaml +0 -155
- package/compliance/cache/3.1.0-beta.7/test-kits/single-side-trust-runner.yaml +0 -294
- package/compliance/cache/3.1.0-beta.7/test-kits/substitution-observer-runner.yaml +0 -688
- package/compliance/cache/3.1.0-beta.7/test-kits/summit-foods.yaml +0 -125
- package/compliance/cache/3.1.0-beta.7/test-kits/webhook-receiver-runner.yaml +0 -265
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/001-minimal-plan.json +0 -43
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/002-full-plan.json +0 -217
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/003-bookkeeping-stripped.json +0 -60
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/004a-human-review-omitted.json +0 -43
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/004b-human-review-explicit-null.json +0 -49
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/005a-policy-categories-order-1.json +0 -53
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/005b-policy-categories-order-2.json +0 -57
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/006a-ext-trace-v1.json +0 -49
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/006b-ext-trace-v2.json +0 -53
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/007-unicode-objectives.json +0 -43
- package/compliance/cache/3.1.0-beta.7/test-vectors/plan-hash/008-numeric-canonicalization.json +0 -65
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/README.md +0 -220
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/canonicalization.json +0 -241
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/keys.json +0 -60
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/001-no-signature-header.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/002-wrong-tag.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/003-expired-signature.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/004-window-too-long.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/005-alg-not-allowed.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/006-missing-covered-component.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/007-missing-content-digest.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/008-unknown-keyid.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/009-key-ops-missing-verify.json +0 -27
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/010-content-digest-mismatch.json +0 -33
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/011-malformed-header.json +0 -27
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/012-missing-expires-param.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/013-expires-le-created.json +0 -27
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/014-missing-nonce-param.json +0 -27
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/015-signature-invalid.json +0 -28
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/016-replayed-nonce.json +0 -35
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/017-key-revoked.json +0 -38
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/018-digest-covered-when-forbidden.json +0 -28
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/019-signature-without-signature-input.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/020-rate-abuse.json +0 -34
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/021-duplicate-signature-input-label.json +0 -31
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/022-multi-valued-content-type.json +0 -31
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/023-multi-valued-content-digest.json +0 -32
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/024-unquoted-string-param.json +0 -31
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/025-jwk-alg-crv-mismatch.json +0 -43
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/026-non-ascii-host.json +0 -31
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/027-webhook-registration-authentication-unsigned.json +0 -25
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/negative/028-unsigned-protocol-method-required.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/001-basic-post.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/002-post-with-content-digest.json +0 -31
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/003-es256-post.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/004-multiple-signature-labels.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/005-default-port-stripped.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/006-dot-segment-path.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/007-query-byte-preserved.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/008-percent-encoded-path.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/009-percent-encoded-unreserved-decoded.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/010-percent-encoded-slash-preserved.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/011-ipv6-authority.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/request-signing/positive/012-ipv6-authority-default-port-stripped.json +0 -30
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/README.md +0 -211
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/keys.json +0 -61
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/001-wrong-tag.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/002-expired-signature.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/003-window-too-long.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/004-alg-not-allowed.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/005-missing-authority-component.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/006-missing-content-digest.json +0 -25
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/007-unknown-keyid.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/008-wrong-adcp-use.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/009-content-digest-mismatch.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/010-malformed-signature-input.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/011-signature-without-input.json +0 -25
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/012-missing-expires-param.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/013-expires-le-created.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/014-missing-nonce-param.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/015-signature-invalid.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/016-replayed-nonce.json +0 -37
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/017-key-revoked.json +0 -32
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/018-rate-abuse.json +0 -33
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/019-revocation-stale.json +0 -32
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/020-key-ops-missing-verify.json +0 -41
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/negative/021-base64-alphabet-mixing.json +0 -26
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/001-basic-post.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/002-es256-post.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/003-multiple-signature-labels.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/004-default-port-stripped.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/005-percent-encoded-path.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/006-query-byte-preserved.json +0 -24
- package/compliance/cache/3.1.0-beta.7/test-vectors/webhook-signing/positive/007-body-without-idempotency-key.json +0 -25
- package/compliance/cache/3.1.0-beta.7/universal/billing-gate-dispatch.yaml +0 -450
- package/compliance/cache/3.1.0-beta.7/universal/canonical-format-validate-input.yaml +0 -640
- package/compliance/cache/3.1.0-beta.7/universal/capability-discovery.yaml +0 -125
- package/compliance/cache/3.1.0-beta.7/universal/collection-lists-pagination-integrity.yaml +0 -306
- package/compliance/cache/3.1.0-beta.7/universal/comply-controller-mode-gate.yaml +0 -141
- package/compliance/cache/3.1.0-beta.7/universal/content-standards-pagination-integrity.yaml +0 -326
- package/compliance/cache/3.1.0-beta.7/universal/deterministic-testing.yaml +0 -1430
- package/compliance/cache/3.1.0-beta.7/universal/error-compliance-signals.yaml +0 -377
- package/compliance/cache/3.1.0-beta.7/universal/error-compliance.yaml +0 -528
- package/compliance/cache/3.1.0-beta.7/universal/fictional-entities.yaml +0 -307
- package/compliance/cache/3.1.0-beta.7/universal/get-media-buys-pagination-integrity.yaml +0 -160
- package/compliance/cache/3.1.0-beta.7/universal/get-signals-pagination-integrity.yaml +0 -211
- package/compliance/cache/3.1.0-beta.7/universal/idempotency.yaml +0 -861
- package/compliance/cache/3.1.0-beta.7/universal/notification-config-event-scope.yaml +0 -119
- package/compliance/cache/3.1.0-beta.7/universal/notification-config-lifecycle.yaml +0 -337
- package/compliance/cache/3.1.0-beta.7/universal/notification-config-rejections.yaml +0 -107
- package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity-creative-formats.yaml +0 -265
- package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity-list-accounts.yaml +0 -245
- package/compliance/cache/3.1.0-beta.7/universal/pagination-integrity.yaml +0 -263
- package/compliance/cache/3.1.0-beta.7/universal/property-lists-pagination-integrity.yaml +0 -307
- package/compliance/cache/3.1.0-beta.7/universal/read-tool-idempotency.yaml +0 -405
- package/compliance/cache/3.1.0-beta.7/universal/runner-output-contract.yaml +0 -1266
- package/compliance/cache/3.1.0-beta.7/universal/schema-validation-signals.yaml +0 -181
- package/compliance/cache/3.1.0-beta.7/universal/schema-validation.yaml +0 -548
- package/compliance/cache/3.1.0-beta.7/universal/security.yaml +0 -539
- package/compliance/cache/3.1.0-beta.7/universal/signed-requests.yaml +0 -217
- package/compliance/cache/3.1.0-beta.7/universal/stale-response-advisory.yaml +0 -295
- package/compliance/cache/3.1.0-beta.7/universal/storyboard-schema.yaml +0 -2136
- package/compliance/cache/3.1.0-beta.7/universal/v3-envelope-integrity.yaml +0 -117
- package/compliance/cache/3.1.0-beta.7/universal/version-negotiation.yaml +0 -130
- package/compliance/cache/3.1.0-beta.7/universal/webhook-emission.yaml +0 -411
- package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-bulk-webhooks.yaml +0 -82
- package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-product-webhooks.yaml +0 -83
- package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-products.yaml +0 -151
- package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-signal-webhooks.yaml +0 -83
- package/compliance/cache/3.1.0-beta.7/universal/wholesale-feed-signals.yaml +0 -149
- package/dist/lib/types/v3-1-beta/index.d.mts +0 -1
- package/dist/lib/types/v3-1-beta/index.d.ts +0 -1
- package/dist/lib/types/v3-1-beta/index.mjs +0 -1
- package/dist/lib/types/v3-1-beta/tools.generated.d.mts +0 -26788
- package/dist/lib/types/v3-1-beta/tools.generated.d.ts +0 -26788
- /package/dist/lib/{types/v3-1-beta/tools.generated.mjs → media-buy/action-types.mjs} +0 -0
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ADCP_VERSION,
|
|
8
|
+
AgentClient,
|
|
9
|
+
canonicalJsonSha256,
|
|
10
|
+
getWebhookRegistrationMigration,
|
|
11
|
+
pgWebhookRegistrationStore,
|
|
12
|
+
WebhookDispatchError,
|
|
13
|
+
type AgentConfig,
|
|
14
|
+
type BuyProductsResponse,
|
|
15
|
+
type BuyProductsRequest,
|
|
16
|
+
type DeferredTaskStorage,
|
|
17
|
+
type TaskResult,
|
|
18
|
+
type TaskStatus,
|
|
19
|
+
type WebhookMetadata,
|
|
20
|
+
type WebhookRegistration,
|
|
21
|
+
type WebhookRegistrationStore,
|
|
22
|
+
} from '@adcp/sdk';
|
|
23
|
+
import { getIdempotencyMigration, pgBackend, type PgQueryable } from '@adcp/sdk/server';
|
|
24
|
+
import { BuyProductsResponseSchema } from '@adcp/sdk/schemas';
|
|
25
|
+
import { getReplayStoreMigration, PostgresReplayStore } from '@adcp/sdk/signing/server';
|
|
26
|
+
|
|
27
|
+
export const STORE_NAMES = {
|
|
28
|
+
deployment: 'buyer_prod_v1',
|
|
29
|
+
operations: 'buyer_adcp_operations',
|
|
30
|
+
operationRoutes: 'buyer_adcp_operation_routes',
|
|
31
|
+
publications: 'buyer_adcp_publications',
|
|
32
|
+
registrations: 'buyer_adcp_webhook_registrations',
|
|
33
|
+
webhookReplay: 'buyer_adcp_webhook_replays',
|
|
34
|
+
webhookDedup: 'buyer_adcp_webhook_dedup',
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
// Seven days is both the SDK 14 default registration horizon and the maximum
|
|
38
|
+
// webhook retry horizon advertised by the pinned AdCP 3.2 schema.
|
|
39
|
+
export const RECEIVER_RETENTION_SECONDS = 7 * 24 * 60 * 60;
|
|
40
|
+
|
|
41
|
+
export const HOST_OPERATION_MIGRATION = `
|
|
42
|
+
CREATE TABLE IF NOT EXISTS ${STORE_NAMES.operations} (
|
|
43
|
+
deployment_namespace TEXT NOT NULL,
|
|
44
|
+
logical_operation_id TEXT NOT NULL,
|
|
45
|
+
natural_key TEXT NOT NULL,
|
|
46
|
+
tenant_id TEXT NOT NULL,
|
|
47
|
+
principal_id TEXT NOT NULL,
|
|
48
|
+
seller_id TEXT NOT NULL,
|
|
49
|
+
seller_url TEXT NOT NULL,
|
|
50
|
+
seller_protocol TEXT NOT NULL CHECK (seller_protocol IN ('mcp', 'a2a')),
|
|
51
|
+
seller_account_id TEXT NOT NULL,
|
|
52
|
+
request_idempotency_key TEXT NOT NULL,
|
|
53
|
+
request_payload JSONB NOT NULL,
|
|
54
|
+
request_fingerprint TEXT NOT NULL,
|
|
55
|
+
seller_task_id TEXT,
|
|
56
|
+
deferred_token TEXT,
|
|
57
|
+
continuation_claim_token TEXT,
|
|
58
|
+
continuation_claim_expires_at TIMESTAMPTZ,
|
|
59
|
+
status TEXT NOT NULL DEFAULT 'staged',
|
|
60
|
+
terminal_fingerprint TEXT,
|
|
61
|
+
terminal_result JSONB,
|
|
62
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
63
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
64
|
+
PRIMARY KEY (deployment_namespace, logical_operation_id),
|
|
65
|
+
UNIQUE (deployment_namespace, request_idempotency_key)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
CREATE INDEX IF NOT EXISTS buyer_adcp_operations_natural_key
|
|
69
|
+
ON ${STORE_NAMES.operations} (
|
|
70
|
+
deployment_namespace, tenant_id, seller_id, seller_account_id, natural_key
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
CREATE TABLE IF NOT EXISTS ${STORE_NAMES.operationRoutes} (
|
|
74
|
+
deployment_namespace TEXT NOT NULL,
|
|
75
|
+
seller_id TEXT NOT NULL,
|
|
76
|
+
sdk_operation_id TEXT NOT NULL,
|
|
77
|
+
logical_operation_id TEXT NOT NULL,
|
|
78
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
79
|
+
PRIMARY KEY (deployment_namespace, seller_id, sdk_operation_id),
|
|
80
|
+
FOREIGN KEY (deployment_namespace, logical_operation_id)
|
|
81
|
+
REFERENCES ${STORE_NAMES.operations} (deployment_namespace, logical_operation_id)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
CREATE INDEX IF NOT EXISTS buyer_adcp_operation_routes_logical_operation
|
|
85
|
+
ON ${STORE_NAMES.operationRoutes} (deployment_namespace, logical_operation_id);
|
|
86
|
+
|
|
87
|
+
CREATE TABLE IF NOT EXISTS ${STORE_NAMES.publications} (
|
|
88
|
+
deployment_namespace TEXT NOT NULL,
|
|
89
|
+
logical_operation_id TEXT NOT NULL,
|
|
90
|
+
terminal_fingerprint TEXT NOT NULL,
|
|
91
|
+
payload JSONB NOT NULL,
|
|
92
|
+
claim_token TEXT,
|
|
93
|
+
claim_expires_at TIMESTAMPTZ,
|
|
94
|
+
published_at TIMESTAMPTZ,
|
|
95
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
96
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
97
|
+
PRIMARY KEY (deployment_namespace, logical_operation_id),
|
|
98
|
+
FOREIGN KEY (deployment_namespace, logical_operation_id)
|
|
99
|
+
REFERENCES ${STORE_NAMES.operations} (deployment_namespace, logical_operation_id)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
CREATE INDEX IF NOT EXISTS buyer_adcp_publications_unpublished
|
|
103
|
+
ON ${STORE_NAMES.publications} (deployment_namespace, updated_at)
|
|
104
|
+
WHERE published_at IS NULL;
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
export interface AuthorizedSellerSession {
|
|
108
|
+
tenantId: string;
|
|
109
|
+
principalId: string;
|
|
110
|
+
sellerId: string;
|
|
111
|
+
sellerUrl: string;
|
|
112
|
+
sellerProtocol: 'mcp' | 'a2a';
|
|
113
|
+
sellerAccountId: string;
|
|
114
|
+
/** Request-local secret. The operation ledger never persists it. */
|
|
115
|
+
authToken: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface DurableBuyerPgClient extends PgQueryable {
|
|
119
|
+
release(): void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface DurableBuyerPgPool extends PgQueryable {
|
|
123
|
+
connect(): Promise<DurableBuyerPgClient>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface StoredOperation {
|
|
127
|
+
logicalOperationId: string;
|
|
128
|
+
naturalKey: string;
|
|
129
|
+
tenantId: string;
|
|
130
|
+
principalId: string;
|
|
131
|
+
sellerId: string;
|
|
132
|
+
sellerUrl: string;
|
|
133
|
+
sellerProtocol: 'mcp' | 'a2a';
|
|
134
|
+
sellerAccountId: string;
|
|
135
|
+
request: BuyProductsRequest;
|
|
136
|
+
requestFingerprint: string;
|
|
137
|
+
sellerTaskId?: string;
|
|
138
|
+
deferredToken?: string;
|
|
139
|
+
status: string;
|
|
140
|
+
terminalFingerprint?: string;
|
|
141
|
+
terminalResult?: unknown;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface DurableBuyerDependencies {
|
|
145
|
+
pool: DurableBuyerPgPool;
|
|
146
|
+
/** Host implementation of the SDK's atomic DeferredTaskStorage contract. */
|
|
147
|
+
deferredStorage: DeferredTaskStorage;
|
|
148
|
+
/** Re-derive current credentials and authorization; never load them from the operation row. */
|
|
149
|
+
resolveSellerSession(operation: StoredOperation): Promise<AuthorizedSellerSession | undefined>;
|
|
150
|
+
callbackUrlTemplate: string;
|
|
151
|
+
/** Five-minute minimum; the worker renews this lease while resume is active. */
|
|
152
|
+
continuationClaimSeconds?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface DispatchContext {
|
|
156
|
+
logicalOperationId: string;
|
|
157
|
+
session: AuthorizedSellerSession;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const dispatchContext = new AsyncLocalStorage<DispatchContext>();
|
|
161
|
+
export const TERMINAL_TASK_STATUSES: ReadonlySet<string> = new Set<TaskStatus>([
|
|
162
|
+
'completed',
|
|
163
|
+
'failed',
|
|
164
|
+
'canceled',
|
|
165
|
+
'rejected',
|
|
166
|
+
'governance-denied',
|
|
167
|
+
'aborted',
|
|
168
|
+
]);
|
|
169
|
+
export const DEFAULT_CONTINUATION_CLAIM_SECONDS = 5 * 60;
|
|
170
|
+
const SAFE_ROUTE_SEGMENT = /^[A-Za-z0-9._~-]+$/;
|
|
171
|
+
|
|
172
|
+
export class TerminalObservationConflictError extends Error {}
|
|
173
|
+
export class TerminalObservationInProgressError extends Error {}
|
|
174
|
+
|
|
175
|
+
function normalizeTaskStatus(status: string): string {
|
|
176
|
+
return status === 'cancelled' ? 'canceled' : status;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function canonicalTerminalPayload(status: string, value: unknown): unknown | undefined {
|
|
180
|
+
if (!TERMINAL_TASK_STATUSES.has(status) || value === undefined) return undefined;
|
|
181
|
+
// Webhook and tasks/get envelopes may carry task status beside a result
|
|
182
|
+
// object that omits the commitment discriminant. Preserve an explicit
|
|
183
|
+
// result status; otherwise derive only the schema's completed/failed arm.
|
|
184
|
+
const candidate =
|
|
185
|
+
typeof value === 'object' && value !== null && !Array.isArray(value) && !Object.hasOwn(value, 'status')
|
|
186
|
+
? { ...value, status: status === 'completed' ? 'completed' : 'failed' }
|
|
187
|
+
: value;
|
|
188
|
+
const parsed = BuyProductsResponseSchema.safeParse(candidate);
|
|
189
|
+
if (!parsed.success || parsed.data.status === 'submitted') return undefined;
|
|
190
|
+
return parsed.data;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function terminalOutcomeFingerprintPayload(value: unknown): unknown {
|
|
194
|
+
const response = value as BuyProductsResponse;
|
|
195
|
+
// Explicitly exclude channel/envelope fields (`replayed`, `context`, `ext`)
|
|
196
|
+
// so a retry, callback, and poll of the same commitment have one identity.
|
|
197
|
+
if (response.status === 'failed') return { status: response.status, errors: response.errors };
|
|
198
|
+
if (response.status !== 'completed') throw new Error('A submitted response is not a terminal outcome.');
|
|
199
|
+
return {
|
|
200
|
+
status: response.status,
|
|
201
|
+
media_buy_id: response.media_buy_id,
|
|
202
|
+
revision: response.revision,
|
|
203
|
+
accepted_proposal: response.accepted_proposal,
|
|
204
|
+
purchase_bindings: response.purchase_bindings,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function rowToOperation(row: Record<string, unknown>): StoredOperation {
|
|
209
|
+
return {
|
|
210
|
+
logicalOperationId: String(row.logical_operation_id),
|
|
211
|
+
naturalKey: String(row.natural_key),
|
|
212
|
+
tenantId: String(row.tenant_id),
|
|
213
|
+
principalId: String(row.principal_id),
|
|
214
|
+
sellerId: String(row.seller_id),
|
|
215
|
+
sellerUrl: String(row.seller_url),
|
|
216
|
+
sellerProtocol: row.seller_protocol === 'a2a' ? 'a2a' : 'mcp',
|
|
217
|
+
sellerAccountId: String(row.seller_account_id),
|
|
218
|
+
request: row.request_payload as BuyProductsRequest,
|
|
219
|
+
requestFingerprint: String(row.request_fingerprint),
|
|
220
|
+
...(row.seller_task_id ? { sellerTaskId: String(row.seller_task_id) } : {}),
|
|
221
|
+
...(row.deferred_token ? { deferredToken: String(row.deferred_token) } : {}),
|
|
222
|
+
status: String(row.status),
|
|
223
|
+
...(row.terminal_fingerprint ? { terminalFingerprint: String(row.terminal_fingerprint) } : {}),
|
|
224
|
+
...(row.terminal_result !== null && row.terminal_result !== undefined
|
|
225
|
+
? { terminalResult: row.terminal_result }
|
|
226
|
+
: {}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export class PostgresOperationLedger {
|
|
231
|
+
constructor(readonly pool: DurableBuyerPgPool) {}
|
|
232
|
+
|
|
233
|
+
async stage(
|
|
234
|
+
logicalOperationId: string,
|
|
235
|
+
naturalKey: string,
|
|
236
|
+
session: AuthorizedSellerSession,
|
|
237
|
+
requestWithoutKey: Omit<BuyProductsRequest, 'idempotency_key'>,
|
|
238
|
+
idempotencyKey?: string
|
|
239
|
+
): Promise<StoredOperation> {
|
|
240
|
+
if (!naturalKey.trim()) throw new Error('The business natural key must be non-empty.');
|
|
241
|
+
if (
|
|
242
|
+
!('account_id' in requestWithoutKey.account) ||
|
|
243
|
+
requestWithoutKey.account.account_id !== session.sellerAccountId
|
|
244
|
+
) {
|
|
245
|
+
throw new Error('The request account must match the currently authorized seller account.');
|
|
246
|
+
}
|
|
247
|
+
const candidateKey = idempotencyKey ?? randomUUID();
|
|
248
|
+
const candidateRequest = structuredClone({
|
|
249
|
+
...requestWithoutKey,
|
|
250
|
+
idempotency_key: candidateKey,
|
|
251
|
+
}) as BuyProductsRequest;
|
|
252
|
+
const candidateFingerprint = canonicalJsonSha256(candidateRequest);
|
|
253
|
+
await this.pool.query(
|
|
254
|
+
`INSERT INTO ${STORE_NAMES.operations} (
|
|
255
|
+
deployment_namespace, logical_operation_id, natural_key, tenant_id, principal_id,
|
|
256
|
+
seller_id, seller_url, seller_protocol, seller_account_id,
|
|
257
|
+
request_idempotency_key, request_payload, request_fingerprint
|
|
258
|
+
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11::jsonb,$12)
|
|
259
|
+
ON CONFLICT DO NOTHING`,
|
|
260
|
+
[
|
|
261
|
+
STORE_NAMES.deployment,
|
|
262
|
+
logicalOperationId,
|
|
263
|
+
naturalKey,
|
|
264
|
+
session.tenantId,
|
|
265
|
+
session.principalId,
|
|
266
|
+
session.sellerId,
|
|
267
|
+
session.sellerUrl,
|
|
268
|
+
session.sellerProtocol,
|
|
269
|
+
session.sellerAccountId,
|
|
270
|
+
candidateKey,
|
|
271
|
+
JSON.stringify(candidateRequest),
|
|
272
|
+
candidateFingerprint,
|
|
273
|
+
]
|
|
274
|
+
);
|
|
275
|
+
const stored = await this.get(logicalOperationId);
|
|
276
|
+
if (!stored) {
|
|
277
|
+
throw new Error('The request idempotency key is already bound to a different logical operation.');
|
|
278
|
+
}
|
|
279
|
+
const expectedRequest = structuredClone({
|
|
280
|
+
...requestWithoutKey,
|
|
281
|
+
idempotency_key: idempotencyKey ?? stored.request.idempotency_key,
|
|
282
|
+
}) as BuyProductsRequest;
|
|
283
|
+
if (
|
|
284
|
+
stored.naturalKey !== naturalKey ||
|
|
285
|
+
stored.requestFingerprint !== canonicalJsonSha256(expectedRequest) ||
|
|
286
|
+
stored.tenantId !== session.tenantId ||
|
|
287
|
+
stored.principalId !== session.principalId ||
|
|
288
|
+
stored.sellerId !== session.sellerId ||
|
|
289
|
+
stored.sellerUrl !== session.sellerUrl ||
|
|
290
|
+
stored.sellerProtocol !== session.sellerProtocol ||
|
|
291
|
+
stored.sellerAccountId !== session.sellerAccountId
|
|
292
|
+
) {
|
|
293
|
+
throw new Error(
|
|
294
|
+
'Logical operation already exists with a different natural key, canonical request, or authorization binding; create a new operation.'
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
return stored;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async get(logicalOperationId: string): Promise<StoredOperation | undefined> {
|
|
301
|
+
const { rows } = await this.pool.query(
|
|
302
|
+
`SELECT * FROM ${STORE_NAMES.operations}
|
|
303
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2`,
|
|
304
|
+
[STORE_NAMES.deployment, logicalOperationId]
|
|
305
|
+
);
|
|
306
|
+
return rows[0] ? rowToOperation(rows[0]) : undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async getBySdkOperation(sellerId: string, sdkOperationId: string): Promise<StoredOperation | undefined> {
|
|
310
|
+
const { rows } = await this.pool.query(
|
|
311
|
+
`SELECT operation.*
|
|
312
|
+
FROM ${STORE_NAMES.operationRoutes} AS route
|
|
313
|
+
JOIN ${STORE_NAMES.operations} AS operation
|
|
314
|
+
ON operation.deployment_namespace = route.deployment_namespace
|
|
315
|
+
AND operation.logical_operation_id = route.logical_operation_id
|
|
316
|
+
WHERE route.deployment_namespace = $1
|
|
317
|
+
AND route.seller_id = $2 AND route.sdk_operation_id = $3`,
|
|
318
|
+
[STORE_NAMES.deployment, sellerId, sdkOperationId]
|
|
319
|
+
);
|
|
320
|
+
return rows[0] ? rowToOperation(rows[0]) : undefined;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async markDispatchUncertain(logicalOperationId: string): Promise<void> {
|
|
324
|
+
await this.pool.query(
|
|
325
|
+
`UPDATE ${STORE_NAMES.operations}
|
|
326
|
+
SET status = 'dispatch-uncertain', updated_at = clock_timestamp()
|
|
327
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2
|
|
328
|
+
AND terminal_fingerprint IS NULL`,
|
|
329
|
+
[STORE_NAMES.deployment, logicalOperationId]
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async bindRegistration(
|
|
334
|
+
tx: DurableBuyerPgClient,
|
|
335
|
+
registration: WebhookRegistration,
|
|
336
|
+
context: DispatchContext
|
|
337
|
+
): Promise<void> {
|
|
338
|
+
if (registration.agentId !== context.session.sellerId)
|
|
339
|
+
throw new Error('Webhook seller binding changed before dispatch.');
|
|
340
|
+
const bound = await tx.query(
|
|
341
|
+
`INSERT INTO ${STORE_NAMES.operationRoutes} (
|
|
342
|
+
deployment_namespace, seller_id, sdk_operation_id, logical_operation_id
|
|
343
|
+
)
|
|
344
|
+
SELECT $1, $6, $3, logical_operation_id
|
|
345
|
+
FROM ${STORE_NAMES.operations}
|
|
346
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2
|
|
347
|
+
AND tenant_id = $4 AND principal_id = $5 AND seller_id = $6
|
|
348
|
+
AND seller_url = $7 AND seller_protocol = $8 AND seller_account_id = $9
|
|
349
|
+
ON CONFLICT (deployment_namespace, seller_id, sdk_operation_id) DO NOTHING
|
|
350
|
+
RETURNING logical_operation_id`,
|
|
351
|
+
[
|
|
352
|
+
STORE_NAMES.deployment,
|
|
353
|
+
context.logicalOperationId,
|
|
354
|
+
registration.operationId,
|
|
355
|
+
context.session.tenantId,
|
|
356
|
+
context.session.principalId,
|
|
357
|
+
context.session.sellerId,
|
|
358
|
+
context.session.sellerUrl,
|
|
359
|
+
context.session.sellerProtocol,
|
|
360
|
+
context.session.sellerAccountId,
|
|
361
|
+
]
|
|
362
|
+
);
|
|
363
|
+
if (bound.rowCount === 1) return;
|
|
364
|
+
const proof = await tx.query(
|
|
365
|
+
`SELECT logical_operation_id FROM ${STORE_NAMES.operationRoutes}
|
|
366
|
+
WHERE deployment_namespace = $1 AND seller_id = $2 AND sdk_operation_id = $3`,
|
|
367
|
+
[STORE_NAMES.deployment, context.session.sellerId, registration.operationId]
|
|
368
|
+
);
|
|
369
|
+
if (proof.rows[0]?.logical_operation_id !== context.logicalOperationId) {
|
|
370
|
+
throw new Error('Could not atomically bind the SDK operation to the authorized host operation.');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async observeByLogicalOperation(
|
|
375
|
+
logicalOperationId: string,
|
|
376
|
+
result: TaskResult<unknown>,
|
|
377
|
+
continuationClaimToken?: string
|
|
378
|
+
): Promise<void> {
|
|
379
|
+
// TaskExecutor also uses `failed` for transport exceptions. Without a
|
|
380
|
+
// seller payload, delivery is uncertain and must be reconciled/retried
|
|
381
|
+
// with the stored request key instead of becoming the terminal winner.
|
|
382
|
+
const status =
|
|
383
|
+
TERMINAL_TASK_STATUSES.has(result.status) && result.data === undefined ? 'dispatch-uncertain' : result.status;
|
|
384
|
+
await this.observe(
|
|
385
|
+
logicalOperationId,
|
|
386
|
+
status,
|
|
387
|
+
result.data,
|
|
388
|
+
result.metadata.serverTaskId,
|
|
389
|
+
result.deferred?.token,
|
|
390
|
+
continuationClaimToken
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async observeBySdkOperation(response: unknown, metadata: WebhookMetadata): Promise<void> {
|
|
395
|
+
const operation = await this.getBySdkOperation(metadata.agent_id, metadata.operation_id);
|
|
396
|
+
if (!operation) throw new Error('No authorized host operation owns this callback route.');
|
|
397
|
+
if (
|
|
398
|
+
TERMINAL_TASK_STATUSES.has(normalizeTaskStatus(metadata.status)) &&
|
|
399
|
+
canonicalTerminalPayload(normalizeTaskStatus(metadata.status), response) === undefined
|
|
400
|
+
) {
|
|
401
|
+
throw new WebhookDispatchError(
|
|
402
|
+
'webhook_publication_in_progress',
|
|
403
|
+
'A terminal callback did not contain a canonical buy_products result; retry or reconcile by polling.'
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
await this.observe(operation.logicalOperationId, metadata.status, response, metadata.task_id);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
if (error instanceof TerminalObservationConflictError) {
|
|
410
|
+
throw new WebhookDispatchError('webhook_idempotency_conflict', error.message, error);
|
|
411
|
+
}
|
|
412
|
+
if (error instanceof TerminalObservationInProgressError) {
|
|
413
|
+
throw new WebhookDispatchError('webhook_publication_in_progress', error.message, error);
|
|
414
|
+
}
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async observe(
|
|
420
|
+
logicalOperationId: string,
|
|
421
|
+
status: string,
|
|
422
|
+
value: unknown,
|
|
423
|
+
sellerTaskId?: string,
|
|
424
|
+
deferredToken?: string,
|
|
425
|
+
continuationClaimToken?: string
|
|
426
|
+
): Promise<void> {
|
|
427
|
+
const tx = await this.pool.connect();
|
|
428
|
+
try {
|
|
429
|
+
await tx.query('BEGIN');
|
|
430
|
+
const { rows } = await tx.query(
|
|
431
|
+
`SELECT *,
|
|
432
|
+
continuation_claim_token IS NOT NULL
|
|
433
|
+
AND continuation_claim_expires_at > clock_timestamp()
|
|
434
|
+
AS continuation_claim_is_active
|
|
435
|
+
FROM ${STORE_NAMES.operations}
|
|
436
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2 FOR UPDATE`,
|
|
437
|
+
[STORE_NAMES.deployment, logicalOperationId]
|
|
438
|
+
);
|
|
439
|
+
const currentRow = rows[0] as Record<string, unknown> | undefined;
|
|
440
|
+
const current = currentRow ? rowToOperation(currentRow) : undefined;
|
|
441
|
+
if (!current) throw new Error('Unknown logical operation.');
|
|
442
|
+
if (current.sellerTaskId && sellerTaskId && current.sellerTaskId !== sellerTaskId) {
|
|
443
|
+
throw new TerminalObservationConflictError('Seller task identity conflict.');
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const normalizedStatus = normalizeTaskStatus(status);
|
|
447
|
+
const terminalPayload = canonicalTerminalPayload(normalizedStatus, value);
|
|
448
|
+
const terminalFingerprint =
|
|
449
|
+
terminalPayload !== undefined
|
|
450
|
+
? canonicalJsonSha256({
|
|
451
|
+
task_type: 'buy_products',
|
|
452
|
+
value: terminalOutcomeFingerprintPayload(terminalPayload),
|
|
453
|
+
})
|
|
454
|
+
: undefined;
|
|
455
|
+
const claimIsActive = currentRow?.continuation_claim_is_active === true;
|
|
456
|
+
if (
|
|
457
|
+
continuationClaimToken !== undefined &&
|
|
458
|
+
(!claimIsActive || currentRow?.continuation_claim_token !== continuationClaimToken)
|
|
459
|
+
) {
|
|
460
|
+
throw new TerminalObservationInProgressError('The continuation settlement lease was lost.');
|
|
461
|
+
}
|
|
462
|
+
if (terminalFingerprint && claimIsActive && currentRow?.continuation_claim_token !== continuationClaimToken) {
|
|
463
|
+
throw new TerminalObservationInProgressError('A continuation resume currently owns terminal settlement.');
|
|
464
|
+
}
|
|
465
|
+
if (current.terminalFingerprint) {
|
|
466
|
+
if (terminalFingerprint && current.terminalFingerprint !== terminalFingerprint) {
|
|
467
|
+
throw new TerminalObservationConflictError(
|
|
468
|
+
'Conflicting terminal observation; the recorded winner was preserved.'
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
if (!terminalFingerprint) {
|
|
472
|
+
await tx.query('COMMIT');
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
await tx.query(
|
|
478
|
+
`UPDATE ${STORE_NAMES.operations}
|
|
479
|
+
SET seller_task_id = COALESCE(seller_task_id, $3),
|
|
480
|
+
deferred_token = CASE WHEN $6::text IS NOT NULL THEN NULL ELSE COALESCE($4, deferred_token) END,
|
|
481
|
+
status = CASE WHEN terminal_fingerprint IS NULL THEN $5 ELSE status END,
|
|
482
|
+
terminal_fingerprint = COALESCE(terminal_fingerprint, $6::text),
|
|
483
|
+
terminal_result = CASE WHEN terminal_fingerprint IS NULL AND $6::text IS NOT NULL THEN $7::jsonb ELSE terminal_result END,
|
|
484
|
+
updated_at = clock_timestamp()
|
|
485
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2`,
|
|
486
|
+
[
|
|
487
|
+
STORE_NAMES.deployment,
|
|
488
|
+
logicalOperationId,
|
|
489
|
+
sellerTaskId ?? null,
|
|
490
|
+
deferredToken ?? null,
|
|
491
|
+
terminalFingerprint || !TERMINAL_TASK_STATUSES.has(normalizedStatus)
|
|
492
|
+
? normalizedStatus
|
|
493
|
+
: 'terminal-result-pending',
|
|
494
|
+
terminalFingerprint ?? null,
|
|
495
|
+
terminalFingerprint ? JSON.stringify(terminalPayload) : null,
|
|
496
|
+
]
|
|
497
|
+
);
|
|
498
|
+
if (terminalFingerprint) {
|
|
499
|
+
await tx.query(
|
|
500
|
+
`INSERT INTO ${STORE_NAMES.publications} (
|
|
501
|
+
deployment_namespace, logical_operation_id, terminal_fingerprint, payload
|
|
502
|
+
) VALUES ($1,$2,$3,$4::jsonb)
|
|
503
|
+
ON CONFLICT (deployment_namespace, logical_operation_id) DO NOTHING`,
|
|
504
|
+
[STORE_NAMES.deployment, logicalOperationId, terminalFingerprint, JSON.stringify(terminalPayload)]
|
|
505
|
+
);
|
|
506
|
+
const proof = await tx.query(
|
|
507
|
+
`SELECT terminal_fingerprint FROM ${STORE_NAMES.publications}
|
|
508
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2`,
|
|
509
|
+
[STORE_NAMES.deployment, logicalOperationId]
|
|
510
|
+
);
|
|
511
|
+
if (proof.rows[0]?.terminal_fingerprint !== terminalFingerprint) {
|
|
512
|
+
throw new TerminalObservationConflictError('Publication outbox conflicts with the terminal winner.');
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
await tx.query('COMMIT');
|
|
516
|
+
} catch (error) {
|
|
517
|
+
try {
|
|
518
|
+
await tx.query('ROLLBACK');
|
|
519
|
+
} catch {
|
|
520
|
+
// Preserve the transaction's original failure; releasing the client
|
|
521
|
+
// below discards any broken connection.
|
|
522
|
+
}
|
|
523
|
+
throw error;
|
|
524
|
+
} finally {
|
|
525
|
+
tx.release();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async claimContinuation(
|
|
530
|
+
logicalOperationId: string,
|
|
531
|
+
claimSeconds = DEFAULT_CONTINUATION_CLAIM_SECONDS
|
|
532
|
+
): Promise<string> {
|
|
533
|
+
if (!Number.isSafeInteger(claimSeconds) || claimSeconds < 5 * 60 || claimSeconds > 24 * 60 * 60) {
|
|
534
|
+
throw new RangeError('continuationClaimSeconds must be between 300 and 86400 seconds.');
|
|
535
|
+
}
|
|
536
|
+
const claimToken = randomUUID();
|
|
537
|
+
const claimed = await this.pool.query(
|
|
538
|
+
`UPDATE ${STORE_NAMES.operations}
|
|
539
|
+
SET continuation_claim_token = $3,
|
|
540
|
+
continuation_claim_expires_at = clock_timestamp() + ($4 * INTERVAL '1 second'),
|
|
541
|
+
updated_at = clock_timestamp()
|
|
542
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2
|
|
543
|
+
AND terminal_fingerprint IS NULL
|
|
544
|
+
AND (continuation_claim_token IS NULL OR continuation_claim_expires_at <= clock_timestamp())
|
|
545
|
+
RETURNING logical_operation_id`,
|
|
546
|
+
[STORE_NAMES.deployment, logicalOperationId, claimToken, claimSeconds]
|
|
547
|
+
);
|
|
548
|
+
if (claimed.rowCount !== 1) {
|
|
549
|
+
throw new Error('The operation is already terminal or another continuation owns settlement.');
|
|
550
|
+
}
|
|
551
|
+
return claimToken;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async renewContinuationClaim(logicalOperationId: string, claimToken: string, claimSeconds: number): Promise<void> {
|
|
555
|
+
const renewed = await this.pool.query(
|
|
556
|
+
`UPDATE ${STORE_NAMES.operations}
|
|
557
|
+
SET continuation_claim_expires_at = clock_timestamp() + ($4 * INTERVAL '1 second'),
|
|
558
|
+
updated_at = clock_timestamp()
|
|
559
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2
|
|
560
|
+
AND continuation_claim_token = $3 AND terminal_fingerprint IS NULL
|
|
561
|
+
RETURNING logical_operation_id`,
|
|
562
|
+
[STORE_NAMES.deployment, logicalOperationId, claimToken, claimSeconds]
|
|
563
|
+
);
|
|
564
|
+
if (renewed.rowCount !== 1) throw new Error('The continuation settlement lease could not be renewed.');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
async releaseContinuationClaim(logicalOperationId: string, claimToken: string): Promise<void> {
|
|
568
|
+
await this.pool.query(
|
|
569
|
+
`UPDATE ${STORE_NAMES.operations}
|
|
570
|
+
SET continuation_claim_token = NULL, continuation_claim_expires_at = NULL,
|
|
571
|
+
updated_at = clock_timestamp()
|
|
572
|
+
WHERE deployment_namespace = $1 AND logical_operation_id = $2
|
|
573
|
+
AND continuation_claim_token = $3`,
|
|
574
|
+
[STORE_NAMES.deployment, logicalOperationId, claimToken]
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
class OperationBoundRegistrationStore implements WebhookRegistrationStore {
|
|
580
|
+
private readonly shared: WebhookRegistrationStore;
|
|
581
|
+
|
|
582
|
+
constructor(
|
|
583
|
+
private readonly pool: DurableBuyerPgPool,
|
|
584
|
+
private readonly ledger: PostgresOperationLedger
|
|
585
|
+
) {
|
|
586
|
+
this.shared = pgWebhookRegistrationStore(pool, { tableName: STORE_NAMES.registrations });
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
get(agentId: string, operationId: string) {
|
|
590
|
+
return this.shared.get(agentId, operationId);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async putIfAbsent(registration: WebhookRegistration): Promise<void> {
|
|
594
|
+
const context = dispatchContext.getStore();
|
|
595
|
+
if (!context) throw new Error('Outbound webhook registration has no host operation context.');
|
|
596
|
+
const tx = await this.pool.connect();
|
|
597
|
+
try {
|
|
598
|
+
await tx.query('BEGIN');
|
|
599
|
+
await pgWebhookRegistrationStore(tx, { tableName: STORE_NAMES.registrations }).putIfAbsent(registration);
|
|
600
|
+
await this.ledger.bindRegistration(tx, registration, context);
|
|
601
|
+
await tx.query('COMMIT');
|
|
602
|
+
} catch (error) {
|
|
603
|
+
try {
|
|
604
|
+
await tx.query('ROLLBACK');
|
|
605
|
+
} catch {
|
|
606
|
+
// Preserve the registration/binding failure.
|
|
607
|
+
}
|
|
608
|
+
throw error;
|
|
609
|
+
} finally {
|
|
610
|
+
tx.release();
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
markRequiresDurableSettlement(agentId: string, operationId: string) {
|
|
615
|
+
if (!this.shared.markRequiresDurableSettlement)
|
|
616
|
+
throw new Error('The registration store does not support durable-settlement marking.');
|
|
617
|
+
return this.shared.markRequiresDurableSettlement(agentId, operationId);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
delete(agentId: string, operationId: string) {
|
|
621
|
+
if (!this.shared.delete) throw new Error('The registration store does not support registration deletion.');
|
|
622
|
+
return this.shared.delete(agentId, operationId);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export async function migrateDurableBuyer(pool: DurableBuyerPgPool): Promise<void> {
|
|
627
|
+
await pool.query(getWebhookRegistrationMigration({ tableName: STORE_NAMES.registrations }));
|
|
628
|
+
await pool.query(getReplayStoreMigration(STORE_NAMES.webhookReplay));
|
|
629
|
+
await pool.query(getIdempotencyMigration({ tableName: STORE_NAMES.webhookDedup }));
|
|
630
|
+
await pool.query(HOST_OPERATION_MIGRATION);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export async function probeDurableBuyerStores(pool: DurableBuyerPgPool): Promise<void> {
|
|
634
|
+
const registrations = pgWebhookRegistrationStore(pool, { tableName: STORE_NAMES.registrations });
|
|
635
|
+
const webhookDedup = pgBackend(pool, { tableName: STORE_NAMES.webhookDedup });
|
|
636
|
+
if (!webhookDedup.probe) throw new Error('The selected webhook dedup backend has no readiness probe.');
|
|
637
|
+
await Promise.all([
|
|
638
|
+
registrations.probe(),
|
|
639
|
+
webhookDedup.probe(),
|
|
640
|
+
pool.query(`SELECT keyid, scope, nonce, expires_at FROM ${STORE_NAMES.webhookReplay} LIMIT 0`),
|
|
641
|
+
pool.query(
|
|
642
|
+
`SELECT logical_operation_id, request_idempotency_key, seller_task_id, deferred_token,
|
|
643
|
+
terminal_fingerprint, continuation_claim_token
|
|
644
|
+
FROM ${STORE_NAMES.operations} LIMIT 0`
|
|
645
|
+
),
|
|
646
|
+
pool.query(`SELECT seller_id, sdk_operation_id, logical_operation_id FROM ${STORE_NAMES.operationRoutes} LIMIT 0`),
|
|
647
|
+
pool.query(
|
|
648
|
+
`SELECT logical_operation_id, terminal_fingerprint, payload, published_at
|
|
649
|
+
FROM ${STORE_NAMES.publications} LIMIT 0`
|
|
650
|
+
),
|
|
651
|
+
]);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export function assertSameAuthorization(operation: StoredOperation, session: AuthorizedSellerSession): void {
|
|
655
|
+
if (
|
|
656
|
+
session.tenantId !== operation.tenantId ||
|
|
657
|
+
session.principalId !== operation.principalId ||
|
|
658
|
+
session.sellerId !== operation.sellerId ||
|
|
659
|
+
session.sellerUrl !== operation.sellerUrl ||
|
|
660
|
+
session.sellerProtocol !== operation.sellerProtocol ||
|
|
661
|
+
session.sellerAccountId !== operation.sellerAccountId
|
|
662
|
+
) {
|
|
663
|
+
throw new Error('Current seller/account authorization does not match the durable operation.');
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export async function createDurableAgent(
|
|
668
|
+
dependencies: DurableBuyerDependencies,
|
|
669
|
+
ledger: PostgresOperationLedger,
|
|
670
|
+
session: AuthorizedSellerSession
|
|
671
|
+
): Promise<AgentClient> {
|
|
672
|
+
if (
|
|
673
|
+
!dependencies.callbackUrlTemplate.includes('{task_type}') ||
|
|
674
|
+
!dependencies.callbackUrlTemplate.includes('{agent_id}') ||
|
|
675
|
+
!dependencies.callbackUrlTemplate.includes('{operation_id}')
|
|
676
|
+
) {
|
|
677
|
+
throw new Error('The trusted callback URL template must include {task_type}, {agent_id}, and {operation_id}.');
|
|
678
|
+
}
|
|
679
|
+
if (!SAFE_ROUTE_SEGMENT.test(session.sellerId)) {
|
|
680
|
+
throw new Error('sellerId must be an RFC 3986 unreserved callback-route segment.');
|
|
681
|
+
}
|
|
682
|
+
const registrationStore = new OperationBoundRegistrationStore(dependencies.pool, ledger);
|
|
683
|
+
const replayStore = new PostgresReplayStore(dependencies.pool, { tableName: STORE_NAMES.webhookReplay });
|
|
684
|
+
const webhookDedup = pgBackend(dependencies.pool, { tableName: STORE_NAMES.webhookDedup });
|
|
685
|
+
|
|
686
|
+
const agent: AgentConfig = {
|
|
687
|
+
id: session.sellerId,
|
|
688
|
+
name: session.sellerId,
|
|
689
|
+
agent_uri: session.sellerUrl,
|
|
690
|
+
protocol: session.sellerProtocol,
|
|
691
|
+
auth_token: session.authToken,
|
|
692
|
+
};
|
|
693
|
+
const client = new AgentClient(agent, {
|
|
694
|
+
adcpVersion: ADCP_VERSION,
|
|
695
|
+
webhookUrlTemplate: { template: dependencies.callbackUrlTemplate, tools: ['buy_products'] },
|
|
696
|
+
webhookRegistrationStore: registrationStore,
|
|
697
|
+
webhookRegistrationTtlSeconds: RECEIVER_RETENTION_SECONDS,
|
|
698
|
+
webhookVerification: { replayStore },
|
|
699
|
+
deferredStorage: dependencies.deferredStorage,
|
|
700
|
+
deferredTaskTtlSeconds: RECEIVER_RETENTION_SECONDS,
|
|
701
|
+
handlers: {
|
|
702
|
+
webhookDedup: { backend: webhookDedup, ttlSeconds: RECEIVER_RETENTION_SECONDS },
|
|
703
|
+
onTaskStatusChange: async (response, metadata) => {
|
|
704
|
+
await ledger.observeBySdkOperation(response, metadata);
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
return client;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Outbound request process. Stage first, then always dispatch the stored value
|
|
713
|
+
* and key. An uncertain retry calls this again with the same logical operation;
|
|
714
|
+
* it never creates a replacement key automatically.
|
|
715
|
+
*/
|
|
716
|
+
export async function dispatchStagedBuy(
|
|
717
|
+
dependencies: DurableBuyerDependencies,
|
|
718
|
+
logicalOperationId: string
|
|
719
|
+
): Promise<TaskResult<unknown> | { alreadySettled: true; value: unknown }> {
|
|
720
|
+
const ledger = new PostgresOperationLedger(dependencies.pool);
|
|
721
|
+
const operation = await ledger.get(logicalOperationId);
|
|
722
|
+
if (!operation) throw new Error('Stage the logical operation before dispatch.');
|
|
723
|
+
const session = await dependencies.resolveSellerSession(operation);
|
|
724
|
+
if (!session) throw new Error('The staged operation is no longer authorized.');
|
|
725
|
+
assertSameAuthorization(operation, session);
|
|
726
|
+
if (operation.terminalFingerprint) {
|
|
727
|
+
return { alreadySettled: true, value: structuredClone(operation.terminalResult) };
|
|
728
|
+
}
|
|
729
|
+
const seller = await createDurableAgent(dependencies, ledger, session);
|
|
730
|
+
let result: TaskResult<unknown>;
|
|
731
|
+
try {
|
|
732
|
+
result = (await dispatchContext.run({ logicalOperationId, session }, () =>
|
|
733
|
+
seller.buyProducts(operation.request)
|
|
734
|
+
)) as TaskResult<unknown>;
|
|
735
|
+
} catch (error) {
|
|
736
|
+
try {
|
|
737
|
+
await ledger.markDispatchUncertain(logicalOperationId);
|
|
738
|
+
} catch (ledgerError) {
|
|
739
|
+
throw new AggregateError([error, ledgerError], 'Dispatch and durable uncertainty recording both failed.');
|
|
740
|
+
}
|
|
741
|
+
throw error;
|
|
742
|
+
}
|
|
743
|
+
await ledger.observeByLogicalOperation(logicalOperationId, result as TaskResult<unknown>);
|
|
744
|
+
return result as TaskResult<unknown>;
|
|
745
|
+
}
|