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