@harrylabsj/kiwi 0.10.0 → 0.11.0
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/README.md +1 -1
- package/contracts/card-publication/0.1.2/request.schema.json +78 -0
- package/contracts/kiwi-contracts.lock.json +2 -2
- package/contracts/manifest.json +127 -1
- package/contracts/merchant-management/1.0/README.md +109 -0
- package/contracts/merchant-management/1.0/approval-decision.schema.json +16 -0
- package/contracts/merchant-management/1.0/approval-preview.schema.json +26 -0
- package/contracts/merchant-management/1.0/connector-delivery-manifest.schema.json +78 -0
- package/contracts/merchant-management/1.0/management-error.schema.json +30 -0
- package/contracts/merchant-management/1.0/operation-receipt.schema.json +28 -0
- package/contracts/merchant-management/1.0/runtime-management-descriptor.schema.json +33 -0
- package/contracts/merchant-management/1.0/runtime-status.schema.json +42 -0
- package/contracts/merchant-rfq/0.1.0/delivery-record.schema.json +206 -0
- package/contracts/merchant-rfq/0.1.0/fact-snapshot.schema.json +118 -0
- package/contracts/merchant-rfq/0.1.0/handoff-record.schema.json +251 -0
- package/contracts/merchant-rfq/0.1.0/pricing-input.schema.json +139 -0
- package/contracts/merchant-rfq/0.1.0/quote-revision.schema.json +153 -0
- package/contracts/merchant-rfq/0.1.0/release-request.schema.json +121 -0
- package/contracts/merchant-rfq/0.1.0/rfq-case.schema.json +357 -0
- package/contracts/merchant-rfq/0.1.0/source-record.schema.json +162 -0
- package/contracts/merchant-workbench/1.0/README.md +6 -0
- package/contracts/merchant-workbench/1.0/money.schema.json +19 -0
- package/contracts/merchant-workbench/1.0/problem.schema.json +73 -0
- package/contracts/runtime-binding/0.1.2/binding-request.schema.json +73 -0
- package/contracts/runtime-binding/0.1.2/claims.schema.json +100 -0
- package/contracts/runtime-binding/0.1.2/document.schema.json +161 -0
- package/contracts/vectors/binding-thumbprint.json +15 -0
- package/dist/a2a/node.d.ts +96 -2
- package/dist/a2a/node.js +164 -91
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/errors.d.ts +8 -0
- package/dist/a2a/server/errors.js +8 -0
- package/dist/a2a/server/errors.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +13 -0
- package/dist/a2a/server/merchant-handler.js +267 -34
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/pipeline.d.ts +15 -10
- package/dist/a2a/server/pipeline.js +48 -18
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.d.ts +20 -1
- package/dist/a2a/server/server.js +87 -13
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/task-registry.d.ts +31 -11
- package/dist/a2a/server/task-registry.js +65 -20
- package/dist/a2a/server/task-registry.js.map +1 -1
- package/dist/a2a/server/types.d.ts +23 -0
- package/dist/a2a/signing-key.d.ts +6 -0
- package/dist/a2a/signing-key.js +12 -0
- package/dist/a2a/signing-key.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.js +1 -1
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/host/web-renderer.d.ts +5 -0
- package/dist/agent/host/web-renderer.js +25 -6
- package/dist/agent/host/web-renderer.js.map +1 -1
- package/dist/agent/kernel.js +6 -6
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/memory/schema.d.ts +1 -1
- package/dist/agent/memory/schema.js +190 -1
- package/dist/agent/memory/schema.js.map +1 -1
- package/dist/agent/memory/store.js +3 -1
- package/dist/agent/memory/store.js.map +1 -1
- package/dist/agent/merchant/action-candidate.d.ts +1 -0
- package/dist/agent/merchant/action-candidate.js +42 -24
- package/dist/agent/merchant/action-candidate.js.map +1 -1
- package/dist/agent/merchant/fake-merchant-client.d.ts +30 -1
- package/dist/agent/merchant/fake-merchant-client.js +151 -2
- package/dist/agent/merchant/fake-merchant-client.js.map +1 -1
- package/dist/agent/merchant/intelligence/default-backend.js +2 -2
- package/dist/agent/merchant/intelligence/default-backend.js.map +1 -1
- package/dist/agent/merchant/merchant-client.d.ts +38 -5
- package/dist/agent/merchant/merchant-client.js +103 -8
- package/dist/agent/merchant/merchant-client.js.map +1 -1
- package/dist/agent/merchant/types.d.ts +107 -0
- package/dist/agent/merchant/types.js +69 -0
- package/dist/agent/merchant/types.js.map +1 -1
- package/dist/alerts/external-delivery.d.ts +78 -0
- package/dist/alerts/external-delivery.js +256 -0
- package/dist/alerts/external-delivery.js.map +1 -0
- package/dist/auth/app-oauth-callback.d.ts +38 -0
- package/dist/auth/app-oauth-callback.js +119 -0
- package/dist/auth/app-oauth-callback.js.map +1 -0
- package/dist/auth/merchant-oauth.js +15 -41
- package/dist/auth/merchant-oauth.js.map +1 -1
- package/dist/auth/merchant-pairing.d.ts +51 -0
- package/dist/auth/merchant-pairing.js +66 -16
- package/dist/auth/merchant-pairing.js.map +1 -1
- package/dist/auth/merchant-sessions.d.ts +7 -1
- package/dist/auth/merchant-sessions.js +25 -3
- package/dist/auth/merchant-sessions.js.map +1 -1
- package/dist/buyer-core/build-service.d.ts +3 -1
- package/dist/buyer-core/build-service.js +4 -1
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +20 -0
- package/dist/buyer-core/merchant-index.js +83 -12
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/network-search.d.ts +92 -0
- package/dist/buyer-core/network-search.js +144 -0
- package/dist/buyer-core/network-search.js.map +1 -0
- package/dist/buyer-core/product-summary.d.ts +71 -0
- package/dist/buyer-core/product-summary.js +63 -0
- package/dist/buyer-core/product-summary.js.map +1 -0
- package/dist/buyer-core/service.d.ts +26 -0
- package/dist/buyer-core/service.js +38 -8
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/cli.js +21 -242
- package/dist/cli.js.map +1 -1
- package/dist/cloud/binding/audit.d.ts +72 -0
- package/dist/cloud/binding/audit.js +137 -0
- package/dist/cloud/binding/audit.js.map +1 -0
- package/dist/cloud/binding/issuance.d.ts +76 -0
- package/dist/cloud/binding/issuance.js +121 -0
- package/dist/cloud/binding/issuance.js.map +1 -0
- package/dist/cloud/binding/proofs.d.ts +110 -0
- package/dist/cloud/binding/proofs.js +200 -0
- package/dist/cloud/binding/proofs.js.map +1 -0
- package/dist/cloud/binding/runtime-challenge.d.ts +48 -0
- package/dist/cloud/binding/runtime-challenge.js +178 -0
- package/dist/cloud/binding/runtime-challenge.js.map +1 -0
- package/dist/cloud/bootstrap.d.ts +63 -0
- package/dist/cloud/bootstrap.js +937 -0
- package/dist/cloud/bootstrap.js.map +1 -0
- package/dist/cloud/config.d.ts +91 -0
- package/dist/cloud/config.js +229 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/http-router.d.ts +61 -0
- package/dist/cloud/http-router.js +127 -0
- package/dist/cloud/http-router.js.map +1 -0
- package/dist/cloud/main.d.ts +16 -0
- package/dist/cloud/main.js +64 -0
- package/dist/cloud/main.js.map +1 -0
- package/dist/cloud/onboarding/local-fallback.d.ts +86 -0
- package/dist/cloud/onboarding/local-fallback.js +98 -0
- package/dist/cloud/onboarding/local-fallback.js.map +1 -0
- package/dist/cloud/onboarding/steps.d.ts +95 -0
- package/dist/cloud/onboarding/steps.js +175 -0
- package/dist/cloud/onboarding/steps.js.map +1 -0
- package/dist/cloud/onboarding/store.d.ts +136 -0
- package/dist/cloud/onboarding/store.js +472 -0
- package/dist/cloud/onboarding/store.js.map +1 -0
- package/dist/cloud/onboarding/types.d.ts +132 -0
- package/dist/cloud/onboarding/types.js +152 -0
- package/dist/cloud/onboarding/types.js.map +1 -0
- package/dist/cloud/product-source.d.ts +97 -0
- package/dist/cloud/product-source.js +226 -0
- package/dist/cloud/product-source.js.map +1 -0
- package/dist/cloud/readiness.d.ts +49 -0
- package/dist/cloud/readiness.js +54 -0
- package/dist/cloud/readiness.js.map +1 -0
- package/dist/commerce/data-source.d.ts +5 -0
- package/dist/commerce/data-source.js.map +1 -1
- package/dist/config/provider-kind.d.ts +26 -0
- package/dist/config/provider-kind.js +19 -0
- package/dist/config/provider-kind.js.map +1 -0
- package/dist/contracts/cloud-contracts.d.ts +23 -0
- package/dist/contracts/cloud-contracts.js +90 -0
- package/dist/contracts/cloud-contracts.js.map +1 -0
- package/dist/counterparty/a2a-direct/index.d.ts +3 -0
- package/dist/counterparty/a2a-direct/index.js +22 -6
- package/dist/counterparty/a2a-direct/index.js.map +1 -1
- package/dist/counterparty/registry.d.ts +2 -0
- package/dist/counterparty/registry.js +2 -0
- package/dist/counterparty/registry.js.map +1 -1
- package/dist/counterparty/shopping-cli-hosted/index.d.ts +3 -0
- package/dist/counterparty/shopping-cli-hosted/index.js +9 -2
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
- package/dist/discovery/catalog-source/buyer-follows.js +2 -2
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/dist/discovery/catalog-source/cloud-card.d.ts +184 -0
- package/dist/discovery/catalog-source/cloud-card.js +379 -0
- package/dist/discovery/catalog-source/cloud-card.js.map +1 -0
- package/dist/discovery/catalog-source/cloud-hosting.d.ts +71 -0
- package/dist/discovery/catalog-source/cloud-hosting.js +70 -0
- package/dist/discovery/catalog-source/cloud-hosting.js.map +1 -0
- package/dist/discovery/catalog-source/errors.d.ts +12 -2
- package/dist/discovery/catalog-source/errors.js +14 -1
- package/dist/discovery/catalog-source/errors.js.map +1 -1
- package/dist/discovery/catalog-source/index.d.ts +2 -0
- package/dist/discovery/catalog-source/index.js +2 -0
- package/dist/discovery/catalog-source/index.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +2 -2
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/discovery/catalog-source/merchant-publications.d.ts +2 -2
- package/dist/discovery/catalog-source/merchant-publications.js +10 -5
- package/dist/discovery/catalog-source/merchant-publications.js.map +1 -1
- package/dist/discovery/catalog-source/source.js +2 -2
- package/dist/discovery/catalog-source/source.js.map +1 -1
- package/dist/discovery/merchant-subscriptions.d.ts +45 -0
- package/dist/discovery/merchant-subscriptions.js +319 -0
- package/dist/discovery/merchant-subscriptions.js.map +1 -0
- package/dist/discovery/resolve.d.ts +38 -0
- package/dist/discovery/resolve.js +100 -7
- package/dist/discovery/resolve.js.map +1 -1
- package/dist/fanout/orchestrator.d.ts +2 -0
- package/dist/fanout/orchestrator.js +4 -1
- package/dist/fanout/orchestrator.js.map +1 -1
- package/dist/handoff/ledger.d.ts +1 -0
- package/dist/handoff/ledger.js +3 -0
- package/dist/handoff/ledger.js.map +1 -1
- package/dist/handoff/transaction.js +1 -1
- package/dist/handoff/transaction.js.map +1 -1
- package/dist/http/merchant-engagement-api.d.ts +10 -0
- package/dist/http/merchant-engagement-api.js +138 -0
- package/dist/http/merchant-engagement-api.js.map +1 -0
- package/dist/http/merchant-feed-api.d.ts +7 -0
- package/dist/http/merchant-feed-api.js +129 -0
- package/dist/http/merchant-feed-api.js.map +1 -0
- package/dist/http/merchant-follow-api.d.ts +15 -0
- package/dist/http/merchant-follow-api.js +192 -0
- package/dist/http/merchant-follow-api.js.map +1 -0
- package/dist/http/merchant-management/api.d.ts +241 -0
- package/dist/http/merchant-management/api.js +2785 -0
- package/dist/http/merchant-management/api.js.map +1 -0
- package/dist/http/merchant-management/draft-store.d.ts +51 -0
- package/dist/http/merchant-management/draft-store.js +95 -0
- package/dist/http/merchant-management/draft-store.js.map +1 -0
- package/dist/http/merchant-management/event-projection.d.ts +41 -0
- package/dist/http/merchant-management/event-projection.js +190 -0
- package/dist/http/merchant-management/event-projection.js.map +1 -0
- package/dist/http/merchant-management/operation-store.d.ts +97 -0
- package/dist/http/merchant-management/operation-store.js +252 -0
- package/dist/http/merchant-management/operation-store.js.map +1 -0
- package/dist/http/merchant-management/page.d.ts +29 -0
- package/dist/http/merchant-management/page.js +346 -0
- package/dist/http/merchant-management/page.js.map +1 -0
- package/dist/http/merchant-management/problem-client.d.ts +19 -0
- package/dist/http/merchant-management/problem-client.js +55 -0
- package/dist/http/merchant-management/problem-client.js.map +1 -0
- package/dist/http/merchant-management/problem.d.ts +74 -0
- package/dist/http/merchant-management/problem.js +112 -0
- package/dist/http/merchant-management/problem.js.map +1 -0
- package/dist/http/merchant-management/reconciliation-worker.d.ts +95 -0
- package/dist/http/merchant-management/reconciliation-worker.js +397 -0
- package/dist/http/merchant-management/reconciliation-worker.js.map +1 -0
- package/dist/http/merchant-management/service-state.d.ts +86 -0
- package/dist/http/merchant-management/service-state.js +217 -0
- package/dist/http/merchant-management/service-state.js.map +1 -0
- package/dist/http/merchant-management/trusted-page.d.ts +3 -0
- package/dist/http/merchant-management/trusted-page.js +73 -0
- package/dist/http/merchant-management/trusted-page.js.map +1 -0
- package/dist/http/merchant-management/webauthn-confirmation.d.ts +148 -0
- package/dist/http/merchant-management/webauthn-confirmation.js +517 -0
- package/dist/http/merchant-management/webauthn-confirmation.js.map +1 -0
- package/dist/http/merchant-privacy-api.d.ts +9 -0
- package/dist/http/merchant-privacy-api.js +96 -0
- package/dist/http/merchant-privacy-api.js.map +1 -0
- package/dist/mcp/merchant-rfq-resources.d.ts +37 -0
- package/dist/mcp/merchant-rfq-resources.js +132 -0
- package/dist/mcp/merchant-rfq-resources.js.map +1 -0
- package/dist/mcp/merchant-rfq-tools.d.ts +61 -0
- package/dist/mcp/merchant-rfq-tools.js +584 -0
- package/dist/mcp/merchant-rfq-tools.js.map +1 -0
- package/dist/mcp/merchant-runtime-assembly.d.ts +74 -0
- package/dist/mcp/merchant-runtime-assembly.js +473 -0
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -0
- package/dist/mcp/merchant-server.d.ts +64 -1
- package/dist/mcp/merchant-server.js +245 -23
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/mcp/tools.js +8 -2
- package/dist/mcp/tools.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +85 -0
- package/dist/merchant/application/actor.js +162 -0
- package/dist/merchant/application/actor.js.map +1 -0
- package/dist/merchant/application/money.d.ts +35 -0
- package/dist/merchant/application/money.js +124 -0
- package/dist/merchant/application/money.js.map +1 -0
- package/dist/merchant/application/service.d.ts +228 -0
- package/dist/merchant/application/service.js +262 -0
- package/dist/merchant/application/service.js.map +1 -0
- package/dist/merchant/clock-safety.d.ts +50 -0
- package/dist/merchant/clock-safety.js +153 -0
- package/dist/merchant/clock-safety.js.map +1 -0
- package/dist/merchant/engagement-store.d.ts +32 -0
- package/dist/merchant/engagement-store.js +119 -0
- package/dist/merchant/engagement-store.js.map +1 -0
- package/dist/merchant/exact-product-executors.d.ts +11 -0
- package/dist/merchant/exact-product-executors.js +132 -0
- package/dist/merchant/exact-product-executors.js.map +1 -0
- package/dist/merchant/feed-executors.d.ts +17 -0
- package/dist/merchant/feed-executors.js +151 -0
- package/dist/merchant/feed-executors.js.map +1 -0
- package/dist/merchant/feed-store.d.ts +141 -0
- package/dist/merchant/feed-store.js +496 -0
- package/dist/merchant/feed-store.js.map +1 -0
- package/dist/merchant/follow-store.d.ts +66 -0
- package/dist/merchant/follow-store.js +295 -0
- package/dist/merchant/follow-store.js.map +1 -0
- package/dist/merchant/grant-executors.d.ts +11 -0
- package/dist/merchant/grant-executors.js +136 -0
- package/dist/merchant/grant-executors.js.map +1 -0
- package/dist/merchant/grant-store.d.ts +125 -0
- package/dist/merchant/grant-store.js +313 -0
- package/dist/merchant/grant-store.js.map +1 -0
- package/dist/merchant/inventory-executors.d.ts +47 -0
- package/dist/merchant/inventory-executors.js +91 -0
- package/dist/merchant/inventory-executors.js.map +1 -0
- package/dist/merchant/listing-executors.d.ts +51 -0
- package/dist/merchant/listing-executors.js +100 -0
- package/dist/merchant/listing-executors.js.map +1 -0
- package/dist/merchant/operation-receipts.d.ts +57 -0
- package/dist/merchant/operation-receipts.js +138 -0
- package/dist/merchant/operation-receipts.js.map +1 -0
- package/dist/merchant/promotion-broadcast-recovery.d.ts +22 -0
- package/dist/merchant/promotion-broadcast-recovery.js +74 -0
- package/dist/merchant/promotion-broadcast-recovery.js.map +1 -0
- package/dist/merchant/promotion-broadcast-workflow.d.ts +42 -0
- package/dist/merchant/promotion-broadcast-workflow.js +171 -0
- package/dist/merchant/promotion-broadcast-workflow.js.map +1 -0
- package/dist/merchant/promotion-executors.d.ts +18 -0
- package/dist/merchant/promotion-executors.js +133 -0
- package/dist/merchant/promotion-executors.js.map +1 -0
- package/dist/merchant/promotion-store.d.ts +114 -0
- package/dist/merchant/promotion-store.js +325 -0
- package/dist/merchant/promotion-store.js.map +1 -0
- package/dist/merchant/promotion-time.d.ts +19 -0
- package/dist/merchant/promotion-time.js +162 -0
- package/dist/merchant/promotion-time.js.map +1 -0
- package/dist/merchant/quote-calculator.d.ts +32 -0
- package/dist/merchant/quote-calculator.js +70 -0
- package/dist/merchant/quote-calculator.js.map +1 -0
- package/dist/merchant/service-control-executors.d.ts +15 -0
- package/dist/merchant/service-control-executors.js +52 -0
- package/dist/merchant/service-control-executors.js.map +1 -0
- package/dist/merchant/workbench-service.d.ts +1 -0
- package/dist/merchant/workbench-service.js +11 -1
- package/dist/merchant/workbench-service.js.map +1 -1
- package/dist/merchant-admin/pending-page.d.ts +104 -0
- package/dist/merchant-admin/pending-page.js +20 -0
- package/dist/merchant-admin/pending-page.js.map +1 -1
- package/dist/merchant-admin/rfq-page.d.ts +105 -0
- package/dist/merchant-admin/rfq-page.js +176 -0
- package/dist/merchant-admin/rfq-page.js.map +1 -0
- package/dist/merchant-core/commands.d.ts +27 -0
- package/dist/merchant-core/commands.js +90 -1
- package/dist/merchant-core/commands.js.map +1 -1
- package/dist/merchant-core/executor.d.ts +27 -3
- package/dist/merchant-core/executor.js +13 -4
- package/dist/merchant-core/executor.js.map +1 -1
- package/dist/merchant-core/rfq/artifacts.d.ts +78 -0
- package/dist/merchant-core/rfq/artifacts.js +219 -0
- package/dist/merchant-core/rfq/artifacts.js.map +1 -0
- package/dist/merchant-core/rfq/data-source-adapter.d.ts +49 -0
- package/dist/merchant-core/rfq/data-source-adapter.js +128 -0
- package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -0
- package/dist/merchant-core/rfq/delivery.d.ts +43 -0
- package/dist/merchant-core/rfq/delivery.js +57 -0
- package/dist/merchant-core/rfq/delivery.js.map +1 -0
- package/dist/merchant-core/rfq/fact-resolver.d.ts +76 -0
- package/dist/merchant-core/rfq/fact-resolver.js +220 -0
- package/dist/merchant-core/rfq/fact-resolver.js.map +1 -0
- package/dist/merchant-core/rfq/handoff.d.ts +54 -0
- package/dist/merchant-core/rfq/handoff.js +71 -0
- package/dist/merchant-core/rfq/handoff.js.map +1 -0
- package/dist/merchant-core/rfq/policy.d.ts +77 -0
- package/dist/merchant-core/rfq/policy.js +104 -0
- package/dist/merchant-core/rfq/policy.js.map +1 -0
- package/dist/merchant-core/rfq/pricing.d.ts +48 -0
- package/dist/merchant-core/rfq/pricing.js +150 -0
- package/dist/merchant-core/rfq/pricing.js.map +1 -0
- package/dist/merchant-core/rfq/quote-revisions.d.ts +52 -0
- package/dist/merchant-core/rfq/quote-revisions.js +126 -0
- package/dist/merchant-core/rfq/quote-revisions.js.map +1 -0
- package/dist/merchant-core/rfq/release-coordinator.d.ts +99 -0
- package/dist/merchant-core/rfq/release-coordinator.js +355 -0
- package/dist/merchant-core/rfq/release-coordinator.js.map +1 -0
- package/dist/merchant-core/rfq/repository.d.ts +398 -0
- package/dist/merchant-core/rfq/repository.js +855 -0
- package/dist/merchant-core/rfq/repository.js.map +1 -0
- package/dist/merchant-core/rfq/service.d.ts +398 -0
- package/dist/merchant-core/rfq/service.js +1036 -0
- package/dist/merchant-core/rfq/service.js.map +1 -0
- package/dist/merchant-core/rfq/source-records.d.ts +97 -0
- package/dist/merchant-core/rfq/source-records.js +349 -0
- package/dist/merchant-core/rfq/source-records.js.map +1 -0
- package/dist/merchant-core/rfq/types.d.ts +197 -0
- package/dist/merchant-core/rfq/types.js +110 -0
- package/dist/merchant-core/rfq/types.js.map +1 -0
- package/dist/merchant-core/service.d.ts +118 -1
- package/dist/merchant-core/service.js +202 -7
- package/dist/merchant-core/service.js.map +1 -1
- package/dist/merchant-core/storage/clock-skew-alerts.d.ts +21 -0
- package/dist/merchant-core/storage/clock-skew-alerts.js +67 -0
- package/dist/merchant-core/storage/clock-skew-alerts.js.map +1 -0
- package/dist/merchant-core/storage/leased-job.d.ts +42 -0
- package/dist/merchant-core/storage/leased-job.js +38 -0
- package/dist/merchant-core/storage/leased-job.js.map +1 -0
- package/dist/merchant-core/storage/operation-lifecycle.d.ts +78 -0
- package/dist/merchant-core/storage/operation-lifecycle.js +111 -0
- package/dist/merchant-core/storage/operation-lifecycle.js.map +1 -0
- package/dist/merchant-core/storage/redact.d.ts +29 -0
- package/dist/merchant-core/storage/redact.js +34 -0
- package/dist/merchant-core/storage/redact.js.map +1 -0
- package/dist/merchant-core/storage/schema.d.ts +24 -0
- package/dist/merchant-core/storage/schema.js +22 -0
- package/dist/merchant-core/storage/schema.js.map +1 -0
- package/dist/merchant-core/storage/transaction.d.ts +47 -0
- package/dist/merchant-core/storage/transaction.js +28 -0
- package/dist/merchant-core/storage/transaction.js.map +1 -0
- package/dist/merchant-gateway/entry-server.js +10 -0
- package/dist/merchant-gateway/entry-server.js.map +1 -1
- package/dist/negotiation/domain/objects.d.ts +7 -0
- package/dist/negotiation/domain/objects.js +8 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/idempotency/store.d.ts +23 -0
- package/dist/negotiation/idempotency/store.js +72 -1
- package/dist/negotiation/idempotency/store.js.map +1 -1
- package/dist/negotiation/idempotency/types.d.ts +16 -0
- package/dist/negotiation/idempotency/types.js +2 -0
- package/dist/negotiation/idempotency/types.js.map +1 -1
- package/dist/negotiation/lease/store.d.ts +18 -22
- package/dist/negotiation/lease/store.js +133 -88
- package/dist/negotiation/lease/store.js.map +1 -1
- package/dist/negotiation/ledger/event.d.ts +6 -0
- package/dist/negotiation/ledger/event.js +1 -0
- package/dist/negotiation/ledger/event.js.map +1 -1
- package/dist/negotiation/ledger/index.d.ts +4 -2
- package/dist/negotiation/ledger/index.js +1 -0
- package/dist/negotiation/ledger/index.js.map +1 -1
- package/dist/negotiation/ledger/payload-segments.d.ts +51 -0
- package/dist/negotiation/ledger/payload-segments.js +247 -0
- package/dist/negotiation/ledger/payload-segments.js.map +1 -0
- package/dist/negotiation/ledger/store.d.ts +34 -0
- package/dist/negotiation/ledger/store.js +162 -0
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/negotiation/recovery/recover.js +1 -1
- package/dist/negotiation/recovery/recover.js.map +1 -1
- package/dist/privacy/ledger-payload-deletion.d.ts +10 -0
- package/dist/privacy/ledger-payload-deletion.js +31 -0
- package/dist/privacy/ledger-payload-deletion.js.map +1 -0
- package/dist/privacy/local-backup-deletion.d.ts +13 -0
- package/dist/privacy/local-backup-deletion.js +115 -0
- package/dist/privacy/local-backup-deletion.js.map +1 -0
- package/dist/privacy/workbench-retention.d.ts +105 -0
- package/dist/privacy/workbench-retention.js +501 -0
- package/dist/privacy/workbench-retention.js.map +1 -0
- package/dist/runtime/model.d.ts +1 -1
- package/dist/runtime/model.js +3 -3
- package/dist/runtime/model.js.map +1 -1
- package/dist/trust/binding/claims.d.ts +92 -0
- package/dist/trust/binding/claims.js +175 -0
- package/dist/trust/binding/claims.js.map +1 -0
- package/dist/trust/binding/thumbprint.d.ts +35 -0
- package/dist/trust/binding/thumbprint.js +88 -0
- package/dist/trust/binding/thumbprint.js.map +1 -0
- package/dist/trust/binding/verify.d.ts +84 -0
- package/dist/trust/binding/verify.js +121 -0
- package/dist/trust/binding/verify.js.map +1 -0
- package/dist/trust/identity/auth-verifier.d.ts +9 -0
- package/dist/trust/identity/auth-verifier.js +10 -2
- package/dist/trust/identity/auth-verifier.js.map +1 -1
- package/dist/trust/identity/jws.d.ts +22 -1
- package/dist/trust/identity/jws.js +31 -2
- package/dist/trust/identity/jws.js.map +1 -1
- package/package.json +12 -4
- package/skills/kiwi-buyer/SKILL.md +33 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed-executors.js","sourceRoot":"","sources":["../../src/merchant/feed-executors.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E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E,CAAC;QAC9B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5B,QAAQ,EAAE,QAAQ;QAClB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,GAAG,CAAC,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,GAAG,CAAC,OAAO,GAAG,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5F,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAc,EAAE,KAAa;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/** Merchant public Feed authority (Workbench v0.1.1 §7 / WB-041,052—054). */
|
|
2
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
3
|
+
/**
|
|
4
|
+
* 广播写操作的回执标识。**operationKind 与执行器工具一一对应**,`queryOutcome`
|
|
5
|
+
* 据它判断"查到的回执是不是我这次操作"。
|
|
6
|
+
*/
|
|
7
|
+
export interface FeedOperation {
|
|
8
|
+
operationId: string;
|
|
9
|
+
operationKind: BroadcastOperationKind;
|
|
10
|
+
requestHash: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const BROADCAST_OPERATION_KINDS: {
|
|
13
|
+
readonly publish: "broadcast_publish";
|
|
14
|
+
readonly revise: "broadcast_revise";
|
|
15
|
+
readonly withdraw: "broadcast_withdraw";
|
|
16
|
+
};
|
|
17
|
+
export type BroadcastOperationKind = (typeof BROADCAST_OPERATION_KINDS)[keyof typeof BROADCAST_OPERATION_KINDS];
|
|
18
|
+
export interface BroadcastInput {
|
|
19
|
+
kind: string;
|
|
20
|
+
title: string;
|
|
21
|
+
body: string;
|
|
22
|
+
skuRefs?: readonly string[];
|
|
23
|
+
promotionRef?: string;
|
|
24
|
+
effectiveUntil?: string;
|
|
25
|
+
audience: "public";
|
|
26
|
+
}
|
|
27
|
+
export interface FeedEvent {
|
|
28
|
+
feed_id: string;
|
|
29
|
+
epoch: number;
|
|
30
|
+
seq: number;
|
|
31
|
+
event_id: string;
|
|
32
|
+
event_type: "published" | "revised" | "withdrawn";
|
|
33
|
+
broadcast_id: string;
|
|
34
|
+
revision: number;
|
|
35
|
+
created_at: string;
|
|
36
|
+
payload: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export type FeedReadResult = {
|
|
39
|
+
kind: "not_modified";
|
|
40
|
+
etag: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "events";
|
|
43
|
+
feed_id: string;
|
|
44
|
+
epoch: number;
|
|
45
|
+
events: FeedEvent[];
|
|
46
|
+
next_cursor: string;
|
|
47
|
+
has_more: boolean;
|
|
48
|
+
etag: string;
|
|
49
|
+
};
|
|
50
|
+
export declare class MerchantFeedError extends Error {
|
|
51
|
+
readonly code: "validation_error" | "not_found" | "version_conflict" | "feed_cursor_invalid" | "feed_reset_required" | "snapshot_expired";
|
|
52
|
+
constructor(code: MerchantFeedError["code"], message: string);
|
|
53
|
+
}
|
|
54
|
+
export declare class MerchantFeedStore {
|
|
55
|
+
private readonly db;
|
|
56
|
+
private readonly cursorKey;
|
|
57
|
+
private readonly now;
|
|
58
|
+
private readonly receipts;
|
|
59
|
+
constructor(options: {
|
|
60
|
+
db: DatabaseSync;
|
|
61
|
+
cursorKey: Buffer;
|
|
62
|
+
now?: () => string;
|
|
63
|
+
});
|
|
64
|
+
publish(merchantId: string, input: BroadcastInput): {
|
|
65
|
+
broadcast_id: string;
|
|
66
|
+
revision: number;
|
|
67
|
+
};
|
|
68
|
+
publishWithId(merchantId: string, broadcastId: string, input: BroadcastInput, operation?: FeedOperation): {
|
|
69
|
+
broadcast_id: string;
|
|
70
|
+
revision: number;
|
|
71
|
+
};
|
|
72
|
+
getBroadcast(merchantId: string, broadcastId: string): (BroadcastInput & {
|
|
73
|
+
broadcast_id: string;
|
|
74
|
+
revision: number;
|
|
75
|
+
status: "published" | "withdrawn";
|
|
76
|
+
}) | undefined;
|
|
77
|
+
listBroadcasts(merchantId: string, options?: {
|
|
78
|
+
cursor?: string;
|
|
79
|
+
limit?: number;
|
|
80
|
+
}): {
|
|
81
|
+
items: Array<BroadcastInput & {
|
|
82
|
+
broadcast_id: string;
|
|
83
|
+
revision: number;
|
|
84
|
+
status: "published" | "withdrawn";
|
|
85
|
+
}>;
|
|
86
|
+
next_cursor: string | null;
|
|
87
|
+
};
|
|
88
|
+
summary(merchantId: string): {
|
|
89
|
+
total: number;
|
|
90
|
+
published: number;
|
|
91
|
+
withdrawn: number;
|
|
92
|
+
};
|
|
93
|
+
revise(merchantId: string, broadcastId: string, expectedRevision: number, input: BroadcastInput, operation?: FeedOperation): {
|
|
94
|
+
broadcast_id: string;
|
|
95
|
+
revision: number;
|
|
96
|
+
};
|
|
97
|
+
withdraw(merchantId: string, broadcastId: string, expectedRevision: number, operation?: FeedOperation): {
|
|
98
|
+
broadcast_id: string;
|
|
99
|
+
revision: number;
|
|
100
|
+
};
|
|
101
|
+
read(merchantId: string, options?: {
|
|
102
|
+
cursor?: string;
|
|
103
|
+
limit?: number;
|
|
104
|
+
ifNoneMatch?: string;
|
|
105
|
+
}): FeedReadResult;
|
|
106
|
+
createSnapshot(merchantId: string): {
|
|
107
|
+
snapshot_id: string;
|
|
108
|
+
high_water_cursor: string;
|
|
109
|
+
expires_at: string;
|
|
110
|
+
};
|
|
111
|
+
readSnapshotPage(merchantId: string, snapshotId: string, offset?: number, limit?: number): {
|
|
112
|
+
items: unknown[];
|
|
113
|
+
next_offset: number | null;
|
|
114
|
+
};
|
|
115
|
+
sweep(): {
|
|
116
|
+
events: number;
|
|
117
|
+
snapshots: number;
|
|
118
|
+
};
|
|
119
|
+
private writeBroadcast;
|
|
120
|
+
/**
|
|
121
|
+
* 回执重放判定(原语见 operation-receipts.ts)。**必须在写之前调用,且在调用方
|
|
122
|
+
* 的同一事务内**。未带 operation 时返回 undefined(`publish()` 等非决定路径不开
|
|
123
|
+
* 回执)。
|
|
124
|
+
*/
|
|
125
|
+
private replayOperation;
|
|
126
|
+
private recordOperation;
|
|
127
|
+
/** 按 operation_id 查回执(对账用;只向所属商家开放)。 */
|
|
128
|
+
getOperation(merchantId: string, operationId: string): {
|
|
129
|
+
operation_id: string;
|
|
130
|
+
merchant_id: string;
|
|
131
|
+
operation_kind: string;
|
|
132
|
+
broadcast_id: string;
|
|
133
|
+
revision: number;
|
|
134
|
+
} | undefined;
|
|
135
|
+
private appendEvent;
|
|
136
|
+
private state;
|
|
137
|
+
private broadcastRow;
|
|
138
|
+
private minRetainedSeq;
|
|
139
|
+
private encodeCursor;
|
|
140
|
+
private decodeCursor;
|
|
141
|
+
}
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
/** Merchant public Feed authority (Workbench v0.1.1 §7 / WB-041,052—054). */
|
|
2
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
3
|
+
import { inImmediateTransaction } from "../merchant-core/storage/transaction.js";
|
|
4
|
+
import { MerchantOperationReceipts, operationReceiptsSchema, } from "./operation-receipts.js";
|
|
5
|
+
const RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
6
|
+
const SNAPSHOT_TTL_MS = 10 * 60 * 1000;
|
|
7
|
+
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
8
|
+
const FORBIDDEN_BIDI = /[\u202A-\u202E\u2066-\u2069]/u;
|
|
9
|
+
const SCHEMA = `
|
|
10
|
+
CREATE TABLE IF NOT EXISTS merchant_feed_state (
|
|
11
|
+
merchant_id TEXT PRIMARY KEY,
|
|
12
|
+
feed_id TEXT UNIQUE NOT NULL,
|
|
13
|
+
epoch INTEGER NOT NULL,
|
|
14
|
+
next_seq INTEGER NOT NULL,
|
|
15
|
+
updated_at TEXT NOT NULL
|
|
16
|
+
);
|
|
17
|
+
CREATE TABLE IF NOT EXISTS merchant_broadcasts (
|
|
18
|
+
merchant_id TEXT NOT NULL,
|
|
19
|
+
broadcast_id TEXT NOT NULL,
|
|
20
|
+
revision INTEGER NOT NULL,
|
|
21
|
+
kind TEXT NOT NULL,
|
|
22
|
+
title TEXT NOT NULL,
|
|
23
|
+
body TEXT NOT NULL,
|
|
24
|
+
sku_refs_json TEXT NOT NULL,
|
|
25
|
+
promotion_ref TEXT,
|
|
26
|
+
published_at TEXT NOT NULL,
|
|
27
|
+
effective_until TEXT,
|
|
28
|
+
audience TEXT NOT NULL CHECK(audience='public'),
|
|
29
|
+
status TEXT NOT NULL CHECK(status IN ('published','withdrawn')),
|
|
30
|
+
updated_at TEXT NOT NULL,
|
|
31
|
+
PRIMARY KEY (merchant_id, broadcast_id)
|
|
32
|
+
);
|
|
33
|
+
CREATE TABLE IF NOT EXISTS merchant_broadcast_revisions (
|
|
34
|
+
merchant_id TEXT NOT NULL,
|
|
35
|
+
broadcast_id TEXT NOT NULL,
|
|
36
|
+
revision INTEGER NOT NULL,
|
|
37
|
+
content_json TEXT NOT NULL,
|
|
38
|
+
created_at TEXT NOT NULL,
|
|
39
|
+
PRIMARY KEY (merchant_id, broadcast_id, revision)
|
|
40
|
+
);
|
|
41
|
+
CREATE TABLE IF NOT EXISTS merchant_feed_events (
|
|
42
|
+
merchant_id TEXT NOT NULL,
|
|
43
|
+
feed_id TEXT NOT NULL,
|
|
44
|
+
epoch INTEGER NOT NULL,
|
|
45
|
+
seq INTEGER NOT NULL,
|
|
46
|
+
event_id TEXT UNIQUE NOT NULL,
|
|
47
|
+
event_type TEXT NOT NULL CHECK(event_type IN ('published','revised','withdrawn')),
|
|
48
|
+
broadcast_id TEXT NOT NULL,
|
|
49
|
+
revision INTEGER NOT NULL,
|
|
50
|
+
payload_json TEXT NOT NULL,
|
|
51
|
+
created_at TEXT NOT NULL,
|
|
52
|
+
PRIMARY KEY (merchant_id, epoch, seq)
|
|
53
|
+
);
|
|
54
|
+
CREATE TABLE IF NOT EXISTS merchant_feed_snapshots (
|
|
55
|
+
snapshot_id TEXT PRIMARY KEY,
|
|
56
|
+
merchant_id TEXT NOT NULL,
|
|
57
|
+
epoch INTEGER NOT NULL,
|
|
58
|
+
high_water_seq INTEGER NOT NULL,
|
|
59
|
+
content_json TEXT NOT NULL,
|
|
60
|
+
expires_at TEXT NOT NULL,
|
|
61
|
+
created_at TEXT NOT NULL
|
|
62
|
+
);
|
|
63
|
+
${operationReceiptsSchema("merchant_feed_operations", "broadcast_id")}
|
|
64
|
+
`;
|
|
65
|
+
export const BROADCAST_OPERATION_KINDS = {
|
|
66
|
+
publish: "broadcast_publish",
|
|
67
|
+
revise: "broadcast_revise",
|
|
68
|
+
withdraw: "broadcast_withdraw",
|
|
69
|
+
};
|
|
70
|
+
export class MerchantFeedError extends Error {
|
|
71
|
+
code;
|
|
72
|
+
constructor(code, message) {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = "MerchantFeedError";
|
|
75
|
+
this.code = code;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class MerchantFeedStore {
|
|
79
|
+
db;
|
|
80
|
+
cursorKey;
|
|
81
|
+
now;
|
|
82
|
+
receipts;
|
|
83
|
+
constructor(options) {
|
|
84
|
+
if (options.cursorKey.length < 32)
|
|
85
|
+
throw new Error("cursorKey must contain at least 32 bytes");
|
|
86
|
+
this.db = options.db;
|
|
87
|
+
this.cursorKey = Buffer.from(options.cursorKey);
|
|
88
|
+
this.now = options.now ?? (() => new Date().toISOString());
|
|
89
|
+
this.receipts = new MerchantOperationReceipts({
|
|
90
|
+
db: options.db,
|
|
91
|
+
table: "merchant_feed_operations",
|
|
92
|
+
entityColumn: "broadcast_id",
|
|
93
|
+
now: this.now,
|
|
94
|
+
conflictError: (message) => new MerchantFeedError("version_conflict", message),
|
|
95
|
+
});
|
|
96
|
+
this.db.exec("pragma busy_timeout = 5000");
|
|
97
|
+
this.db.exec(SCHEMA);
|
|
98
|
+
}
|
|
99
|
+
publish(merchantId, input) {
|
|
100
|
+
const broadcastId = `bct_${randomBytes(16).toString("base64url")}`;
|
|
101
|
+
return this.publishWithId(merchantId, broadcastId, input);
|
|
102
|
+
}
|
|
103
|
+
publishWithId(merchantId, broadcastId, input, operation) {
|
|
104
|
+
if (!/^bct_[A-Za-z0-9_-]{16,128}$/.test(broadcastId)) {
|
|
105
|
+
throw new MerchantFeedError("validation_error", "broadcast_id shape is invalid");
|
|
106
|
+
}
|
|
107
|
+
return this.writeBroadcast(merchantId, broadcastId, 0, "published", input, operation);
|
|
108
|
+
}
|
|
109
|
+
getBroadcast(merchantId, broadcastId) {
|
|
110
|
+
const row = this.db
|
|
111
|
+
.prepare("SELECT * FROM merchant_broadcasts WHERE merchant_id=? AND broadcast_id=?")
|
|
112
|
+
.get(merchantId, broadcastId);
|
|
113
|
+
if (row === undefined)
|
|
114
|
+
return undefined;
|
|
115
|
+
return {
|
|
116
|
+
broadcast_id: String(row["broadcast_id"]),
|
|
117
|
+
revision: Number(row["revision"]),
|
|
118
|
+
status: String(row["status"]),
|
|
119
|
+
kind: String(row["kind"]),
|
|
120
|
+
title: String(row["title"]),
|
|
121
|
+
body: String(row["body"]),
|
|
122
|
+
skuRefs: JSON.parse(String(row["sku_refs_json"])),
|
|
123
|
+
...(row["promotion_ref"] === null ? {} : { promotionRef: String(row["promotion_ref"]) }),
|
|
124
|
+
...(row["effective_until"] === null
|
|
125
|
+
? {}
|
|
126
|
+
: { effectiveUntil: String(row["effective_until"]) }),
|
|
127
|
+
audience: "public",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
listBroadcasts(merchantId, options = {}) {
|
|
131
|
+
const offset = options.cursor === undefined ? 0 : Number.parseInt(options.cursor, 10);
|
|
132
|
+
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
133
|
+
throw new MerchantFeedError("validation_error", "broadcast cursor is invalid");
|
|
134
|
+
}
|
|
135
|
+
const limit = Math.min(Math.max(options.limit ?? 50, 1), 100);
|
|
136
|
+
const rows = this.db
|
|
137
|
+
.prepare(`SELECT broadcast_id FROM merchant_broadcasts
|
|
138
|
+
WHERE merchant_id=? ORDER BY updated_at DESC, broadcast_id LIMIT ? OFFSET ?`)
|
|
139
|
+
.all(merchantId, limit + 1, offset);
|
|
140
|
+
const items = rows
|
|
141
|
+
.slice(0, limit)
|
|
142
|
+
.map((row) => this.getBroadcast(merchantId, row.broadcast_id))
|
|
143
|
+
.filter((item) => item !== undefined);
|
|
144
|
+
return {
|
|
145
|
+
items,
|
|
146
|
+
next_cursor: rows.length > limit ? String(offset + limit) : null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
summary(merchantId) {
|
|
150
|
+
const rows = this.db
|
|
151
|
+
.prepare(`SELECT status, count(*) count FROM merchant_broadcasts
|
|
152
|
+
WHERE merchant_id=? GROUP BY status`)
|
|
153
|
+
.all(merchantId);
|
|
154
|
+
const published = rows.find((row) => row.status === "published")?.count ?? 0;
|
|
155
|
+
const withdrawn = rows.find((row) => row.status === "withdrawn")?.count ?? 0;
|
|
156
|
+
return { total: published + withdrawn, published, withdrawn };
|
|
157
|
+
}
|
|
158
|
+
revise(merchantId, broadcastId, expectedRevision, input, operation) {
|
|
159
|
+
return this.writeBroadcast(merchantId, broadcastId, expectedRevision, "revised", input, operation);
|
|
160
|
+
}
|
|
161
|
+
withdraw(merchantId, broadcastId, expectedRevision, operation) {
|
|
162
|
+
const stamp = this.now();
|
|
163
|
+
return inImmediateTransaction(this.db, () => {
|
|
164
|
+
const replay = this.replayOperation(merchantId, operation);
|
|
165
|
+
if (replay !== undefined) {
|
|
166
|
+
// 早退在 fn 内 return:只读重放由 wrapper 提交空事务(与 rollback 等价)
|
|
167
|
+
return replay;
|
|
168
|
+
}
|
|
169
|
+
const current = this.broadcastRow(merchantId, broadcastId);
|
|
170
|
+
if (current === undefined)
|
|
171
|
+
throw new MerchantFeedError("not_found", "unknown broadcast");
|
|
172
|
+
if (current.revision !== expectedRevision || current.status !== "published") {
|
|
173
|
+
throw new MerchantFeedError("version_conflict", "broadcast revision/status changed");
|
|
174
|
+
}
|
|
175
|
+
const revision = current.revision + 1;
|
|
176
|
+
this.db
|
|
177
|
+
.prepare(`UPDATE merchant_broadcasts SET revision=?, status='withdrawn', updated_at=?
|
|
178
|
+
WHERE merchant_id=? AND broadcast_id=? AND revision=? AND status='published'`)
|
|
179
|
+
.run(revision, stamp, merchantId, broadcastId, expectedRevision);
|
|
180
|
+
this.appendEvent(merchantId, "withdrawn", broadcastId, revision, {
|
|
181
|
+
broadcast_id: broadcastId,
|
|
182
|
+
revision,
|
|
183
|
+
status: "withdrawn",
|
|
184
|
+
});
|
|
185
|
+
this.recordOperation(merchantId, operation, broadcastId, {
|
|
186
|
+
broadcast_id: broadcastId,
|
|
187
|
+
revision,
|
|
188
|
+
});
|
|
189
|
+
return { broadcast_id: broadcastId, revision };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
read(merchantId, options = {}) {
|
|
193
|
+
const state = this.state(merchantId);
|
|
194
|
+
const afterSeq = options.cursor === undefined ? 0 : this.decodeCursor(merchantId, state, options.cursor);
|
|
195
|
+
const min = this.minRetainedSeq(merchantId, state.epoch);
|
|
196
|
+
if (afterSeq > 0 && min !== undefined && afterSeq < min - 1) {
|
|
197
|
+
throw new MerchantFeedError("feed_reset_required", "cursor predates the retained Feed window");
|
|
198
|
+
}
|
|
199
|
+
const limit = Math.min(Math.max(options.limit ?? 50, 1), 50);
|
|
200
|
+
const rows = this.db
|
|
201
|
+
.prepare(`SELECT * FROM merchant_feed_events
|
|
202
|
+
WHERE merchant_id=? AND epoch=? AND seq>? ORDER BY seq LIMIT ?`)
|
|
203
|
+
.all(merchantId, state.epoch, afterSeq, limit + 1);
|
|
204
|
+
const selected = [];
|
|
205
|
+
let bytes = 0;
|
|
206
|
+
for (const row of rows.slice(0, limit)) {
|
|
207
|
+
const event = toEvent(row);
|
|
208
|
+
const eventBytes = Buffer.byteLength(JSON.stringify(event), "utf8");
|
|
209
|
+
if (selected.length > 0 && bytes + eventBytes > MAX_RESPONSE_BYTES)
|
|
210
|
+
break;
|
|
211
|
+
bytes += eventBytes;
|
|
212
|
+
selected.push(event);
|
|
213
|
+
}
|
|
214
|
+
const coveredSeq = selected.at(-1)?.seq ?? afterSeq;
|
|
215
|
+
const hasMore = rows.some((row) => row.seq > coveredSeq);
|
|
216
|
+
const nextCursor = this.encodeCursor(merchantId, state, coveredSeq);
|
|
217
|
+
const representation = {
|
|
218
|
+
feed_id: state.feed_id,
|
|
219
|
+
epoch: state.epoch,
|
|
220
|
+
events: selected,
|
|
221
|
+
next_cursor: nextCursor,
|
|
222
|
+
has_more: hasMore,
|
|
223
|
+
};
|
|
224
|
+
const etag = `"${createHash("sha256").update(JSON.stringify({ afterSeq, limit, representation })).digest("base64url")}"`;
|
|
225
|
+
// Cursor validity/reset was checked before ETag, so 304 can never hide a required reset.
|
|
226
|
+
if (options.ifNoneMatch === etag)
|
|
227
|
+
return { kind: "not_modified", etag };
|
|
228
|
+
return { kind: "events", ...representation, etag };
|
|
229
|
+
}
|
|
230
|
+
createSnapshot(merchantId) {
|
|
231
|
+
const state = this.state(merchantId);
|
|
232
|
+
const rows = this.db
|
|
233
|
+
.prepare(`SELECT broadcast_id, revision, kind, title, body, sku_refs_json, promotion_ref,
|
|
234
|
+
published_at, effective_until, audience, status
|
|
235
|
+
FROM merchant_broadcasts WHERE merchant_id=? AND status='published'
|
|
236
|
+
ORDER BY broadcast_id`)
|
|
237
|
+
.all(merchantId);
|
|
238
|
+
const content = rows.map((row) => ({
|
|
239
|
+
...row,
|
|
240
|
+
sku_refs: JSON.parse(String(row["sku_refs_json"])),
|
|
241
|
+
sku_refs_json: undefined,
|
|
242
|
+
}));
|
|
243
|
+
const snapshotId = `fsn_${randomBytes(18).toString("base64url")}`;
|
|
244
|
+
const stamp = this.now();
|
|
245
|
+
const expiresAt = new Date(Date.parse(stamp) + SNAPSHOT_TTL_MS).toISOString();
|
|
246
|
+
const highWater = Math.max(0, state.next_seq - 1);
|
|
247
|
+
this.db
|
|
248
|
+
.prepare(`INSERT INTO merchant_feed_snapshots
|
|
249
|
+
(snapshot_id, merchant_id, epoch, high_water_seq, content_json, expires_at, created_at)
|
|
250
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
251
|
+
.run(snapshotId, merchantId, state.epoch, highWater, JSON.stringify(content), expiresAt, stamp);
|
|
252
|
+
return {
|
|
253
|
+
snapshot_id: snapshotId,
|
|
254
|
+
high_water_cursor: this.encodeCursor(merchantId, state, highWater),
|
|
255
|
+
expires_at: expiresAt,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
readSnapshotPage(merchantId, snapshotId, offset = 0, limit = 50) {
|
|
259
|
+
const row = this.db
|
|
260
|
+
.prepare(`SELECT content_json, expires_at FROM merchant_feed_snapshots
|
|
261
|
+
WHERE snapshot_id=? AND merchant_id=?`)
|
|
262
|
+
.get(snapshotId, merchantId);
|
|
263
|
+
if (row === undefined)
|
|
264
|
+
throw new MerchantFeedError("not_found", "unknown snapshot");
|
|
265
|
+
if (Date.parse(row.expires_at) <= Date.parse(this.now())) {
|
|
266
|
+
throw new MerchantFeedError("snapshot_expired", "Feed snapshot expired");
|
|
267
|
+
}
|
|
268
|
+
const all = JSON.parse(row.content_json);
|
|
269
|
+
const safeOffset = Math.max(0, offset);
|
|
270
|
+
const safeLimit = Math.min(Math.max(limit, 1), 50);
|
|
271
|
+
const items = all.slice(safeOffset, safeOffset + safeLimit);
|
|
272
|
+
const next = safeOffset + items.length < all.length ? safeOffset + items.length : null;
|
|
273
|
+
return { items, next_offset: next };
|
|
274
|
+
}
|
|
275
|
+
sweep() {
|
|
276
|
+
const stamp = this.now();
|
|
277
|
+
const cutoff = new Date(Date.parse(stamp) - RETENTION_MS).toISOString();
|
|
278
|
+
const events = Number(this.db.prepare("DELETE FROM merchant_feed_events WHERE created_at<?").run(cutoff).changes);
|
|
279
|
+
const snapshots = Number(this.db.prepare("DELETE FROM merchant_feed_snapshots WHERE expires_at<=?").run(stamp).changes);
|
|
280
|
+
return { events, snapshots };
|
|
281
|
+
}
|
|
282
|
+
writeBroadcast(merchantId, broadcastId, expectedRevision, eventType, input, operation) {
|
|
283
|
+
const content = normalizeBroadcast(input);
|
|
284
|
+
const stamp = this.now();
|
|
285
|
+
return inImmediateTransaction(this.db, () => {
|
|
286
|
+
// 重放判定必须在写之前(同 operation_id 同请求回原回执,不产生第二次效果)
|
|
287
|
+
const replay = this.replayOperation(merchantId, operation);
|
|
288
|
+
if (replay !== undefined) {
|
|
289
|
+
return replay;
|
|
290
|
+
}
|
|
291
|
+
const existing = this.broadcastRow(merchantId, broadcastId);
|
|
292
|
+
if (eventType === "published" && existing !== undefined) {
|
|
293
|
+
throw new MerchantFeedError("version_conflict", "broadcast already exists");
|
|
294
|
+
}
|
|
295
|
+
if (eventType === "revised" &&
|
|
296
|
+
(existing === undefined ||
|
|
297
|
+
existing.revision !== expectedRevision ||
|
|
298
|
+
existing.status !== "published")) {
|
|
299
|
+
throw new MerchantFeedError("version_conflict", "broadcast revision/status changed");
|
|
300
|
+
}
|
|
301
|
+
const revision = eventType === "published" ? 1 : expectedRevision + 1;
|
|
302
|
+
this.db
|
|
303
|
+
.prepare(`INSERT INTO merchant_broadcasts
|
|
304
|
+
(merchant_id, broadcast_id, revision, kind, title, body, sku_refs_json,
|
|
305
|
+
promotion_ref, published_at, effective_until, audience, status, updated_at)
|
|
306
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'public', 'published', ?)
|
|
307
|
+
ON CONFLICT(merchant_id, broadcast_id) DO UPDATE SET
|
|
308
|
+
revision=excluded.revision, kind=excluded.kind, title=excluded.title,
|
|
309
|
+
body=excluded.body, sku_refs_json=excluded.sku_refs_json,
|
|
310
|
+
promotion_ref=excluded.promotion_ref, effective_until=excluded.effective_until,
|
|
311
|
+
status='published', updated_at=excluded.updated_at`)
|
|
312
|
+
.run(merchantId, broadcastId, revision, content.kind, content.title, content.body, JSON.stringify(content.sku_refs), content.promotion_ref, existing?.published_at ?? stamp, content.effective_until, stamp);
|
|
313
|
+
const payload = {
|
|
314
|
+
broadcast_id: broadcastId,
|
|
315
|
+
revision,
|
|
316
|
+
...content,
|
|
317
|
+
audience: "public",
|
|
318
|
+
status: "published",
|
|
319
|
+
};
|
|
320
|
+
this.db
|
|
321
|
+
.prepare(`INSERT INTO merchant_broadcast_revisions
|
|
322
|
+
(merchant_id, broadcast_id, revision, content_json, created_at)
|
|
323
|
+
VALUES (?, ?, ?, ?, ?)`)
|
|
324
|
+
.run(merchantId, broadcastId, revision, JSON.stringify(payload), stamp);
|
|
325
|
+
this.appendEvent(merchantId, eventType, broadcastId, revision, payload);
|
|
326
|
+
// 回执与效果同事务:要么都提交、要么都不提交,于是「有回执 ⟺ 效果已提交」
|
|
327
|
+
this.recordOperation(merchantId, operation, broadcastId, {
|
|
328
|
+
broadcast_id: broadcastId,
|
|
329
|
+
revision,
|
|
330
|
+
});
|
|
331
|
+
return { broadcast_id: broadcastId, revision };
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* 回执重放判定(原语见 operation-receipts.ts)。**必须在写之前调用,且在调用方
|
|
336
|
+
* 的同一事务内**。未带 operation 时返回 undefined(`publish()` 等非决定路径不开
|
|
337
|
+
* 回执)。
|
|
338
|
+
*/
|
|
339
|
+
replayOperation(merchantId, operation) {
|
|
340
|
+
const receipt = this.receipts.replay(merchantId, operation);
|
|
341
|
+
if (receipt === undefined)
|
|
342
|
+
return undefined;
|
|
343
|
+
return receipt.response;
|
|
344
|
+
}
|
|
345
|
+
recordOperation(merchantId, operation, broadcastId, response) {
|
|
346
|
+
this.receipts.record(merchantId, operation, broadcastId, response);
|
|
347
|
+
}
|
|
348
|
+
/** 按 operation_id 查回执(对账用;只向所属商家开放)。 */
|
|
349
|
+
getOperation(merchantId, operationId) {
|
|
350
|
+
const receipt = this.receipts.get(merchantId, operationId);
|
|
351
|
+
if (receipt === undefined)
|
|
352
|
+
return undefined;
|
|
353
|
+
return {
|
|
354
|
+
operation_id: operationId,
|
|
355
|
+
merchant_id: merchantId,
|
|
356
|
+
operation_kind: receipt.operation_kind,
|
|
357
|
+
broadcast_id: receipt.entity_id,
|
|
358
|
+
revision: Number(receipt.response.revision ?? 0),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
appendEvent(merchantId, eventType, broadcastId, revision, payload) {
|
|
362
|
+
const state = this.state(merchantId);
|
|
363
|
+
const seq = state.next_seq;
|
|
364
|
+
const stamp = this.now();
|
|
365
|
+
this.db
|
|
366
|
+
.prepare(`INSERT INTO merchant_feed_events
|
|
367
|
+
(merchant_id, feed_id, epoch, seq, event_id, event_type, broadcast_id,
|
|
368
|
+
revision, payload_json, created_at)
|
|
369
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
370
|
+
.run(merchantId, state.feed_id, state.epoch, seq, `fev_${randomBytes(16).toString("base64url")}`, eventType, broadcastId, revision, JSON.stringify(payload), stamp);
|
|
371
|
+
this.db
|
|
372
|
+
.prepare("UPDATE merchant_feed_state SET next_seq=?, updated_at=? WHERE merchant_id=?")
|
|
373
|
+
.run(seq + 1, stamp, merchantId);
|
|
374
|
+
}
|
|
375
|
+
state(merchantId) {
|
|
376
|
+
let row = this.db
|
|
377
|
+
.prepare("SELECT feed_id, epoch, next_seq FROM merchant_feed_state WHERE merchant_id=?")
|
|
378
|
+
.get(merchantId);
|
|
379
|
+
if (row === undefined) {
|
|
380
|
+
this.db
|
|
381
|
+
.prepare(`INSERT OR IGNORE INTO merchant_feed_state
|
|
382
|
+
(merchant_id, feed_id, epoch, next_seq, updated_at) VALUES (?, ?, 1, 1, ?)`)
|
|
383
|
+
.run(merchantId, `feed_${randomBytes(16).toString("base64url")}`, this.now());
|
|
384
|
+
row = this.db
|
|
385
|
+
.prepare("SELECT feed_id, epoch, next_seq FROM merchant_feed_state WHERE merchant_id=?")
|
|
386
|
+
.get(merchantId);
|
|
387
|
+
}
|
|
388
|
+
return row;
|
|
389
|
+
}
|
|
390
|
+
broadcastRow(merchantId, broadcastId) {
|
|
391
|
+
return this.db
|
|
392
|
+
.prepare(`SELECT revision, status, published_at FROM merchant_broadcasts
|
|
393
|
+
WHERE merchant_id=? AND broadcast_id=?`)
|
|
394
|
+
.get(merchantId, broadcastId);
|
|
395
|
+
}
|
|
396
|
+
minRetainedSeq(merchantId, epoch) {
|
|
397
|
+
const row = this.db
|
|
398
|
+
.prepare("SELECT min(seq) value FROM merchant_feed_events WHERE merchant_id=? AND epoch=?")
|
|
399
|
+
.get(merchantId, epoch);
|
|
400
|
+
return row.value ?? undefined;
|
|
401
|
+
}
|
|
402
|
+
encodeCursor(merchantId, state, seq) {
|
|
403
|
+
const payload = Buffer.from(JSON.stringify({ merchant: merchantId, feed: state.feed_id, epoch: state.epoch, seq }), "utf8").toString("base64url");
|
|
404
|
+
const signature = createHmac("sha256", this.cursorKey).update(payload).digest("base64url");
|
|
405
|
+
return `${payload}.${signature}`;
|
|
406
|
+
}
|
|
407
|
+
decodeCursor(merchantId, state, cursor) {
|
|
408
|
+
const [payload, signature, extra] = cursor.split(".");
|
|
409
|
+
if (payload === undefined || signature === undefined || extra !== undefined) {
|
|
410
|
+
throw new MerchantFeedError("feed_cursor_invalid", "malformed Feed cursor");
|
|
411
|
+
}
|
|
412
|
+
const expected = createHmac("sha256", this.cursorKey).update(payload).digest("base64url");
|
|
413
|
+
if (signature !== expected)
|
|
414
|
+
throw new MerchantFeedError("feed_cursor_invalid", "Feed cursor signature mismatch");
|
|
415
|
+
let parsed;
|
|
416
|
+
try {
|
|
417
|
+
parsed = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
throw new MerchantFeedError("feed_cursor_invalid", "Feed cursor payload is invalid");
|
|
421
|
+
}
|
|
422
|
+
if (parsed.merchant !== merchantId ||
|
|
423
|
+
parsed.feed !== state.feed_id ||
|
|
424
|
+
parsed.epoch !== state.epoch ||
|
|
425
|
+
typeof parsed.seq !== "number" ||
|
|
426
|
+
!Number.isInteger(parsed.seq) ||
|
|
427
|
+
parsed.seq < 0 ||
|
|
428
|
+
parsed.seq >= state.next_seq) {
|
|
429
|
+
throw new MerchantFeedError("feed_cursor_invalid", "Feed cursor does not match this feed/epoch");
|
|
430
|
+
}
|
|
431
|
+
return parsed.seq;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function normalizeBroadcast(input) {
|
|
435
|
+
if (input.audience !== "public") {
|
|
436
|
+
throw new MerchantFeedError("validation_error", "Workbench v1 audience must be public");
|
|
437
|
+
}
|
|
438
|
+
const kind = normalizeText(input.kind, "kind", 1, 64);
|
|
439
|
+
const title = normalizeText(input.title, "title", 1, 120);
|
|
440
|
+
const body = normalizeText(input.body.replaceAll("\r\n", "\n").replaceAll("\r", "\n"), "body", 1, 4000);
|
|
441
|
+
if (Buffer.byteLength(body, "utf8") > 16 * 1024) {
|
|
442
|
+
throw new MerchantFeedError("validation_error", "body exceeds 16 KiB UTF-8 limit");
|
|
443
|
+
}
|
|
444
|
+
const skuRefs = [...new Set(input.skuRefs ?? [])].map((sku) => normalizeText(sku, "sku_ref", 1, 160));
|
|
445
|
+
if (skuRefs.length > 50)
|
|
446
|
+
throw new MerchantFeedError("validation_error", "sku_refs exceeds 50 entries");
|
|
447
|
+
const promotionRef = input.promotionRef === undefined
|
|
448
|
+
? null
|
|
449
|
+
: normalizeText(input.promotionRef, "promotion_ref", 1, 160);
|
|
450
|
+
const effectiveUntil = input.effectiveUntil ?? null;
|
|
451
|
+
if (effectiveUntil !== null && !Number.isFinite(Date.parse(effectiveUntil))) {
|
|
452
|
+
throw new MerchantFeedError("validation_error", "effective_until must be an ISO timestamp");
|
|
453
|
+
}
|
|
454
|
+
const normalized = {
|
|
455
|
+
kind,
|
|
456
|
+
title,
|
|
457
|
+
body,
|
|
458
|
+
sku_refs: skuRefs,
|
|
459
|
+
promotion_ref: promotionRef,
|
|
460
|
+
effective_until: effectiveUntil,
|
|
461
|
+
};
|
|
462
|
+
if (Buffer.byteLength(JSON.stringify(normalized), "utf8") > 24 * 1024) {
|
|
463
|
+
throw new MerchantFeedError("validation_error", "normalized broadcast exceeds 24 KiB");
|
|
464
|
+
}
|
|
465
|
+
return normalized;
|
|
466
|
+
}
|
|
467
|
+
function normalizeText(value, field, min, max) {
|
|
468
|
+
const normalized = String(value ?? "").normalize("NFC");
|
|
469
|
+
const length = [...normalized].length;
|
|
470
|
+
const forbiddenControl = [...normalized].some((character) => {
|
|
471
|
+
const code = character.codePointAt(0) ?? 0;
|
|
472
|
+
return (code <= 0x08 ||
|
|
473
|
+
code === 0x0b ||
|
|
474
|
+
code === 0x0c ||
|
|
475
|
+
(code >= 0x0e && code <= 0x1f) ||
|
|
476
|
+
code === 0x7f);
|
|
477
|
+
});
|
|
478
|
+
if (length < min || length > max || forbiddenControl || FORBIDDEN_BIDI.test(normalized)) {
|
|
479
|
+
throw new MerchantFeedError("validation_error", `${field} length/content is invalid`);
|
|
480
|
+
}
|
|
481
|
+
return normalized;
|
|
482
|
+
}
|
|
483
|
+
function toEvent(row) {
|
|
484
|
+
return {
|
|
485
|
+
feed_id: row.feed_id,
|
|
486
|
+
epoch: row.epoch,
|
|
487
|
+
seq: row.seq,
|
|
488
|
+
event_id: row.event_id,
|
|
489
|
+
event_type: row.event_type,
|
|
490
|
+
broadcast_id: row.broadcast_id,
|
|
491
|
+
revision: row.revision,
|
|
492
|
+
created_at: row.created_at,
|
|
493
|
+
payload: JSON.parse(row.payload_json),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
//# sourceMappingURL=feed-store.js.map
|