@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,937 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 云端 Runtime 启动装配(设计 v0.1.2 §8.1)。
|
|
18
|
+
*
|
|
19
|
+
* 启动顺序(缺任一项即拒绝启动,不静默降级):
|
|
20
|
+
* 校验平台契约与配置 → 校验商家绑定与状态目录 → 装配商家面(审批/策略/商品/
|
|
21
|
+
* 工具面)→ 构造 A2A 核心(Ledger/幂等/merchant handler)→ 挂载单端口路由 →
|
|
22
|
+
* **严格**按平台端口监听(占用即失败)→ 自检并输出脱敏启动行。
|
|
23
|
+
*
|
|
24
|
+
* 与自托管形态的差异(全部是云端硬约束):
|
|
25
|
+
* - 不启动交互式 CLI、不启动对话内核;
|
|
26
|
+
* - 不调用 `startA2aNode` 的 catalog 自动注册分支(目录注册由 M4 Enrollment 编排);
|
|
27
|
+
* - 端口占用**不换端口**(T013);
|
|
28
|
+
* - 权威状态目录必须显式给出且不在制品内(T014);
|
|
29
|
+
* - 公网广告地址下弱认证在配置层已被拒绝(T015)。
|
|
30
|
+
*/
|
|
31
|
+
import { createServer } from "node:http";
|
|
32
|
+
import { randomBytes } from "node:crypto";
|
|
33
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
34
|
+
import path from "node:path";
|
|
35
|
+
import { DatabaseSync } from "node:sqlite";
|
|
36
|
+
import { createA2aNodeCore, createA2aAuthVerifier } from "../a2a/node.js";
|
|
37
|
+
import { loadOrCreateA2aSigningIdentity, toJwsSigningIdentity } from "../a2a/signing-key.js";
|
|
38
|
+
import { loadProfile, ProfileError } from "../config/profile.js";
|
|
39
|
+
import { createMerchantManagementApiHandler } from "../http/merchant-management/api.js";
|
|
40
|
+
import { createMerchantFeedApiHandler } from "../http/merchant-feed-api.js";
|
|
41
|
+
import { createMerchantFollowApiHandler } from "../http/merchant-follow-api.js";
|
|
42
|
+
import { createMerchantEngagementApiHandler } from "../http/merchant-engagement-api.js";
|
|
43
|
+
import { createMerchantPrivacyApiHandler } from "../http/merchant-privacy-api.js";
|
|
44
|
+
import { MerchantImportDraftStore } from "../http/merchant-management/draft-store.js";
|
|
45
|
+
import { renderMerchantManagementPage } from "../http/merchant-management/page.js";
|
|
46
|
+
import { createTrustedWorkbenchPageHandler } from "../http/merchant-management/trusted-page.js";
|
|
47
|
+
import { MerchantManagementOperationStore } from "../http/merchant-management/operation-store.js";
|
|
48
|
+
import { WorkbenchConfirmationStore } from "../http/merchant-management/webauthn-confirmation.js";
|
|
49
|
+
import { WorkbenchReconciliationStore, WorkbenchReconciliationWorker, candidateReconciliationResult, committedDecisionOutcomeResult, } from "../http/merchant-management/reconciliation-worker.js";
|
|
50
|
+
import { MutableServiceState } from "../http/merchant-management/service-state.js";
|
|
51
|
+
import { WorkbenchEventProjectionStore } from "../http/merchant-management/event-projection.js";
|
|
52
|
+
import { MerchantFeedStore } from "../merchant/feed-store.js";
|
|
53
|
+
import { MerchantFollowStore } from "../merchant/follow-store.js";
|
|
54
|
+
import { MerchantEngagementStore } from "../merchant/engagement-store.js";
|
|
55
|
+
import { recommendedRetentionPolicy, WorkbenchRetentionStore, } from "../privacy/workbench-retention.js";
|
|
56
|
+
import { createLocalBackupDeletionHandler } from "../privacy/local-backup-deletion.js";
|
|
57
|
+
import { createLedgerPayloadDeletionHandler } from "../privacy/ledger-payload-deletion.js";
|
|
58
|
+
import { createBroadcastExecutors } from "../merchant/feed-executors.js";
|
|
59
|
+
import { isCurrentGrantAuthorization, MerchantGrantStore } from "../merchant/grant-store.js";
|
|
60
|
+
import { createGrantExecutors } from "../merchant/grant-executors.js";
|
|
61
|
+
import { MerchantPromotionStore } from "../merchant/promotion-store.js";
|
|
62
|
+
import { ClockSafetyStore, probeReferenceClock } from "../merchant/clock-safety.js";
|
|
63
|
+
import { createPromotionExecutors } from "../merchant/promotion-executors.js";
|
|
64
|
+
import { PromotionBroadcastWorkflowStore } from "../merchant/promotion-broadcast-workflow.js";
|
|
65
|
+
import { recoverPromotionBroadcastWorkflows } from "../merchant/promotion-broadcast-recovery.js";
|
|
66
|
+
import { createServiceControlExecutors } from "../merchant/service-control-executors.js";
|
|
67
|
+
import { calculateWorkbenchQuote } from "../merchant/quote-calculator.js";
|
|
68
|
+
import { WORKBENCH_CURRENCY_TABLE_VERSION } from "../merchant/application/money.js";
|
|
69
|
+
import { OnboardingStore } from "./onboarding/store.js";
|
|
70
|
+
import { ManagementError, } from "../merchant/application/service.js";
|
|
71
|
+
import { assembleMerchantRuntime, MerchantAssemblyError, } from "../mcp/merchant-runtime-assembly.js";
|
|
72
|
+
import { createMerchantHttpHandler, DEFAULT_MERCHANT_MCP_PATH as MCP_PATH, } from "../mcp/merchant-server.js";
|
|
73
|
+
import { PRODUCT_VERSION } from "../product-cli.js";
|
|
74
|
+
import { CloudConfigError, assertNoDemoPriceFallback, describeCloudConfig, loadCloudConfig, } from "./config.js";
|
|
75
|
+
import { createChallengeResponder } from "./binding/runtime-challenge.js";
|
|
76
|
+
import { createCloudRouter } from "./http-router.js";
|
|
77
|
+
import { commitProductTable, createFileProductSource, loadProductTableSnapshot, ProductTableError, } from "./product-source.js";
|
|
78
|
+
import { runReadiness } from "./readiness.js";
|
|
79
|
+
/** 云端 A2A 端点路径(设计 §8.2;与自托管根路径不同,便于同端口分发)。 */
|
|
80
|
+
export const CLOUD_A2A_PATH = "/a2a";
|
|
81
|
+
/** 启动失败:code 稳定可判(配置错误/装配错误/端口占用等)。 */
|
|
82
|
+
export class CloudStartupError extends Error {
|
|
83
|
+
code;
|
|
84
|
+
constructor(code, message) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.name = "CloudStartupError";
|
|
87
|
+
this.code = code;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 权威状态目录防覆盖(M0 事实 #2):deploy 是目录上传覆盖同名文件,若状态目录
|
|
92
|
+
* 里出现制品文件(package.json),说明制品被发布到了状态目录之上——权威状态
|
|
93
|
+
* 已在不可知状态,必须拒绝启动而不是继续写。
|
|
94
|
+
*/
|
|
95
|
+
function assertDataDirNotClobbered(dataDir) {
|
|
96
|
+
const markers = ["package.json"];
|
|
97
|
+
for (const marker of markers) {
|
|
98
|
+
if (existsSync(path.join(dataDir, marker))) {
|
|
99
|
+
throw new CloudStartupError("DATA_DIR_CLOBBERED", `状态目录 ${dataDir} 内出现制品文件 ${marker}:制品可能被发布到状态目录之上,` +
|
|
100
|
+
"权威状态不可信,拒绝启动");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function loadOrCreateFeedCursorKey(dataDir) {
|
|
105
|
+
const file = path.join(dataDir, "feed-cursor.key");
|
|
106
|
+
const read = () => {
|
|
107
|
+
const key = Buffer.from(readFileSync(file, "utf8").trim(), "base64url");
|
|
108
|
+
if (key.length !== 32) {
|
|
109
|
+
throw new CloudStartupError("FEED_CURSOR_KEY_INVALID", "Feed cursor key must decode to 32 bytes");
|
|
110
|
+
}
|
|
111
|
+
return key;
|
|
112
|
+
};
|
|
113
|
+
if (existsSync(file))
|
|
114
|
+
return read();
|
|
115
|
+
const generated = randomBytes(32);
|
|
116
|
+
try {
|
|
117
|
+
writeFileSync(file, `${generated.toString("base64url")}\n`, { mode: 0o600, flag: "wx" });
|
|
118
|
+
return generated;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error.code === "EEXIST")
|
|
122
|
+
return read();
|
|
123
|
+
throw new CloudStartupError("FEED_CURSOR_KEY_WRITE_FAILED", "cannot persist Feed cursor key");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** 权威存储可读写探针:写一行、读回、回滚(不留痕,也不依赖表结构)。 */
|
|
127
|
+
function probeAuthoritativeStorage(dataDir) {
|
|
128
|
+
const dbPath = path.join(dataDir, "state.sqlite");
|
|
129
|
+
if (!existsSync(dbPath)) {
|
|
130
|
+
return { ok: false, code: "STORAGE_MISSING" };
|
|
131
|
+
}
|
|
132
|
+
let db;
|
|
133
|
+
try {
|
|
134
|
+
db = new DatabaseSync(dbPath);
|
|
135
|
+
// P2-1 逃逸口(merchant-core/storage/transaction.ts 模块头的逃逸口规则):
|
|
136
|
+
// 保留手写事务——这里的**主动 ROLLBACK 不是异常路径,而是探针的目的本身**
|
|
137
|
+
// (写后不留痕)。wrapper 的「fn 返回即 commit」语义与探针目标相反。
|
|
138
|
+
db.exec("BEGIN IMMEDIATE");
|
|
139
|
+
db.exec("CREATE TABLE IF NOT EXISTS readyz_probe (id INTEGER PRIMARY KEY, at TEXT NOT NULL)");
|
|
140
|
+
db.prepare("INSERT INTO readyz_probe (at) VALUES (?)").run(new Date().toISOString());
|
|
141
|
+
const row = db.prepare("SELECT COUNT(*) AS count FROM readyz_probe").get();
|
|
142
|
+
db.exec("ROLLBACK");
|
|
143
|
+
return (row?.count ?? 0) > 0 ? { ok: true } : { ok: false, code: "STORAGE_READBACK_FAILED" };
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// 只回稳定码:细节(路径、锁持有者)留在启动日志,不对外暴露。
|
|
147
|
+
return { ok: false, code: "STORAGE_WRITE_FAILED" };
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
try {
|
|
151
|
+
db?.close();
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// 关闭失败不改变结论
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 启动云端 Runtime。任何拒绝都抛 CloudStartupError / CloudConfigError,
|
|
160
|
+
* 由入口非零退出并打印(绝不带着错误配置对外服务)。
|
|
161
|
+
*/
|
|
162
|
+
export async function bootstrapCloudRuntime(options = {}) {
|
|
163
|
+
const log = options.log ??
|
|
164
|
+
((line) => {
|
|
165
|
+
process.stdout.write(line);
|
|
166
|
+
});
|
|
167
|
+
const config = loadCloudConfig(options.env ?? process.env, {
|
|
168
|
+
...(options.artifactRoot !== undefined ? { artifactRoot: options.artifactRoot } : {}),
|
|
169
|
+
});
|
|
170
|
+
// 1) 商家 profile:云端只接受 merchant 角色(buyer 侧由 Catalog/Buyer 通道承载)。
|
|
171
|
+
let profile;
|
|
172
|
+
try {
|
|
173
|
+
profile = loadProfile(config.profilePath);
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
if (err instanceof ProfileError) {
|
|
177
|
+
throw new CloudStartupError("PROFILE_LOAD_FAILED", err.message);
|
|
178
|
+
}
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
if (profile.role !== "merchant") {
|
|
182
|
+
throw new CloudStartupError("PROFILE_NOT_MERCHANT", `云端 Runtime 需要 merchant profile(收到 role=${profile.role})`);
|
|
183
|
+
}
|
|
184
|
+
// 生产禁演示价回退(设计 §10.2):演示价会让"商品源失联"看起来像有报价。
|
|
185
|
+
assertNoDemoPriceFallback(profile);
|
|
186
|
+
assertDataDirNotClobbered(config.dataDir);
|
|
187
|
+
const serviceState = MutableServiceState.fromDeclared(options.env?.KIWI_CLOUD_SERVICE_STATE);
|
|
188
|
+
// 2) 商家面装配(审批/策略/商品/RFQ/工具面);认证走 OAuth(issuer = 公网 origin)。
|
|
189
|
+
let assembly;
|
|
190
|
+
let feedStoreForExecutors;
|
|
191
|
+
let grantStoreForExecutors;
|
|
192
|
+
let promotionStoreForExecutors;
|
|
193
|
+
let promotionWorkflowStoreForExecutors;
|
|
194
|
+
let readinessForServiceControl;
|
|
195
|
+
try {
|
|
196
|
+
assembly = await assembleMerchantRuntime({
|
|
197
|
+
profile,
|
|
198
|
+
dataDir: config.dataDir,
|
|
199
|
+
host: config.bindHost,
|
|
200
|
+
port: config.port,
|
|
201
|
+
mcpPath: MCP_PATH,
|
|
202
|
+
authMode: "oauth",
|
|
203
|
+
issuer: config.publicOrigin,
|
|
204
|
+
requireCommittedProductDecisions: true,
|
|
205
|
+
extraExecutors: [
|
|
206
|
+
...createBroadcastExecutors({
|
|
207
|
+
merchantId: profile.owner_id,
|
|
208
|
+
getStore: () => feedStoreForExecutors,
|
|
209
|
+
authorizeExecution: (args) => {
|
|
210
|
+
const authorization = recordValue(args["authorization"]);
|
|
211
|
+
const actorId = String(authorization["actor_id"] ?? "");
|
|
212
|
+
const grants = grantStoreForExecutors;
|
|
213
|
+
if (grants === undefined ||
|
|
214
|
+
!isCurrentGrantAuthorization(grants, {
|
|
215
|
+
merchantId: profile.owner_id,
|
|
216
|
+
actorId,
|
|
217
|
+
action: "broadcast.draft",
|
|
218
|
+
snapshot: authorization,
|
|
219
|
+
})) {
|
|
220
|
+
throw new Error("broadcast draft authorization is missing");
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
onPublished: (args) => {
|
|
224
|
+
const workflowId = typeof args["workflow_id"] === "string" ? args["workflow_id"] : undefined;
|
|
225
|
+
if (workflowId !== undefined) {
|
|
226
|
+
const workflows = promotionWorkflowStoreForExecutors;
|
|
227
|
+
if (workflows === undefined) {
|
|
228
|
+
throw new Error("promotion workflow authority is unavailable");
|
|
229
|
+
}
|
|
230
|
+
workflows.markCompleted(profile.owner_id, workflowId);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
}),
|
|
234
|
+
...createGrantExecutors({
|
|
235
|
+
merchantId: profile.owner_id,
|
|
236
|
+
getStore: () => grantStoreForExecutors,
|
|
237
|
+
}),
|
|
238
|
+
...createPromotionExecutors({
|
|
239
|
+
merchantId: profile.owner_id,
|
|
240
|
+
getStore: () => promotionStoreForExecutors,
|
|
241
|
+
getWorkflowStore: () => promotionWorkflowStoreForExecutors,
|
|
242
|
+
prepareBroadcast: async ({ broadcast, authorization, workflowId }) => {
|
|
243
|
+
const actorId = String(authorization["actor_id"] ?? "");
|
|
244
|
+
const grants = grantStoreForExecutors;
|
|
245
|
+
if (grants === undefined ||
|
|
246
|
+
!isCurrentGrantAuthorization(grants, {
|
|
247
|
+
merchantId: profile.owner_id,
|
|
248
|
+
actorId,
|
|
249
|
+
action: "broadcast.draft",
|
|
250
|
+
snapshot: authorization,
|
|
251
|
+
})) {
|
|
252
|
+
throw new Error("broadcast draft authorization changed after promotion approval");
|
|
253
|
+
}
|
|
254
|
+
const prepared = await assembly.service.prepareBroadcastPublish({
|
|
255
|
+
broadcast,
|
|
256
|
+
authorization,
|
|
257
|
+
workflowId,
|
|
258
|
+
reason: "promotion workflow generated broadcast draft",
|
|
259
|
+
});
|
|
260
|
+
return prepared.candidate.candidate_id;
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
...createServiceControlExecutors({
|
|
264
|
+
state: serviceState,
|
|
265
|
+
readiness: async () => {
|
|
266
|
+
if (readinessForServiceControl === undefined) {
|
|
267
|
+
throw new Error("readiness provider is not configured");
|
|
268
|
+
}
|
|
269
|
+
return await readinessForServiceControl();
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
],
|
|
273
|
+
log,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
if (err instanceof MerchantAssemblyError) {
|
|
278
|
+
throw new CloudStartupError(`ASSEMBLY_${err.code}`, err.message);
|
|
279
|
+
}
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
// 3) A2A 核心:签名身份 + 入站认证(弱模式已在配置层拒绝)。
|
|
283
|
+
//
|
|
284
|
+
// Runtime 身份**始终**创建(M2 §6.3:Runtime 首次启动生成持久密钥,公钥摘要
|
|
285
|
+
// 绑定到开通意图)。即使入站认证用 bearer,绑定/挑战也需要这把持久密钥;
|
|
286
|
+
// 公钥随 Agent Card 公开(非秘密),私钥留在状态目录、不出进程。
|
|
287
|
+
const signingKeyDir = config.dataDir;
|
|
288
|
+
const signingIdentity = loadOrCreateA2aSigningIdentity(signingKeyDir, config.publicOrigin);
|
|
289
|
+
const bearerToken = config.a2aAuth.mode === "bearer"
|
|
290
|
+
? (options.env ?? process.env)[config.a2aAuth.tokenEnv]
|
|
291
|
+
: undefined;
|
|
292
|
+
const authVerifier = createA2aAuthVerifier({
|
|
293
|
+
mode: config.a2aAuth.mode,
|
|
294
|
+
...(bearerToken !== undefined ? { bearerToken } : {}),
|
|
295
|
+
signingKeyDir,
|
|
296
|
+
signingKeyId: signingIdentity?.keyid ?? config.publicOrigin,
|
|
297
|
+
advertisedBase: config.publicOrigin,
|
|
298
|
+
// 云端必须按声明 origin 重建目标 URI:平台网关会改写入站 Host(M0 事实 #4)。
|
|
299
|
+
authoritySource: "declared",
|
|
300
|
+
});
|
|
301
|
+
// 商品源:配置文件给了商品表就用"商家上传商品表"路径(设计 §10.1),
|
|
302
|
+
// 否则沿用 HTTP 商品源(shopping-cli 开放层)。两条路径都不含演示价回退。
|
|
303
|
+
const fileProductSource = config.productsFile !== undefined
|
|
304
|
+
? createFileProductSource({ file: config.productsFile, merchantId: profile.owner_id })
|
|
305
|
+
: undefined;
|
|
306
|
+
// 服务可取用性闸门(M4 §5.4/T012 + BD-02):由可变服务状态驱动——初始值来自
|
|
307
|
+
// 操作者显式环境声明,之后可经管理 API 暂停/恢复(owner + 确认 + 就绪门)。
|
|
308
|
+
//
|
|
309
|
+
// 为什么不接就绪检查:就绪语义与业务可取用性**不是一回事**——就绪里含"探针 SKU
|
|
310
|
+
// 是否配置/商品数据是否新鲜"这类核对项,把它们当成"停业"会让正常营业的商家因探针
|
|
311
|
+
// 没配而被拒绝接待(实测:接就绪后 T018 与"过期商品表"用例当场被拒)。正确映射要
|
|
312
|
+
// 与"过期商品该不该停业"一起决定,属暂停/撤回控制落地时的事;在那之前这里只认
|
|
313
|
+
// **操作者显式声明**的状态,绝不替商家判断。
|
|
314
|
+
const serviceAvailability = {
|
|
315
|
+
check: () => serviceState.gateCheck(),
|
|
316
|
+
};
|
|
317
|
+
const core = createA2aNodeCore({
|
|
318
|
+
profile,
|
|
319
|
+
advertisedBase: config.publicOrigin,
|
|
320
|
+
a2aPath: CLOUD_A2A_PATH,
|
|
321
|
+
dataDir: config.dataDir,
|
|
322
|
+
authVerifier,
|
|
323
|
+
...(signingIdentity !== undefined ? { signingIdentity } : {}),
|
|
324
|
+
...(fileProductSource !== undefined ? { productSource: fileProductSource.source } : {}),
|
|
325
|
+
...(serviceAvailability !== undefined ? { serviceAvailability } : {}),
|
|
326
|
+
promotionPrice: ({ sku, quantity }) => {
|
|
327
|
+
const promotion = promotionStoreForExecutors?.activeForSku(profile.owner_id, sku, quantity)[0];
|
|
328
|
+
return promotion === undefined
|
|
329
|
+
? undefined
|
|
330
|
+
: {
|
|
331
|
+
promotionId: promotion.promotion_id,
|
|
332
|
+
revision: promotion.revision,
|
|
333
|
+
currency: promotion.unit_price.currency,
|
|
334
|
+
amountMinor: promotion.unit_price.amount_minor,
|
|
335
|
+
endsAt: promotion.ends_at,
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
// 4) 就绪检查(无敏感值;stale 商品/未配置探针 SKU 都算未就绪,不冒充可用)。
|
|
340
|
+
const probeSku = config.readinessSku;
|
|
341
|
+
const readiness = async () => await runReadiness({
|
|
342
|
+
timeoutMs: config.readinessTimeoutMs,
|
|
343
|
+
identity: () => {
|
|
344
|
+
if (config.a2aAuth.mode === "signature") {
|
|
345
|
+
return signingIdentity !== undefined
|
|
346
|
+
? { ok: true }
|
|
347
|
+
: { ok: false, code: "IDENTITY_SIGNING_KEY_MISSING" };
|
|
348
|
+
}
|
|
349
|
+
return bearerToken !== undefined
|
|
350
|
+
? { ok: true }
|
|
351
|
+
: { ok: false, code: "IDENTITY_BEARER_TOKEN_MISSING" };
|
|
352
|
+
},
|
|
353
|
+
storage: () => probeAuthoritativeStorage(config.dataDir),
|
|
354
|
+
products: async () => {
|
|
355
|
+
if (core.productSource === undefined)
|
|
356
|
+
return { ok: false, code: "PRODUCTS_SOURCE_ABSENT" };
|
|
357
|
+
if (probeSku === undefined || probeSku === "") {
|
|
358
|
+
// 未配置探针 SKU:M1 必须用授权真实测试商品,不能凭"进程活着"判就绪。
|
|
359
|
+
return { ok: false, code: "PRODUCTS_PROBE_SKU_UNSET" };
|
|
360
|
+
}
|
|
361
|
+
if (fileProductSource !== undefined) {
|
|
362
|
+
// 文件式商品源:只回可用性原因码(不含价格)。
|
|
363
|
+
const check = fileProductSource.describeSku(probeSku);
|
|
364
|
+
return check.available
|
|
365
|
+
? { ok: true }
|
|
366
|
+
: { ok: false, code: check.code ?? "PRODUCTS_UNAVAILABLE" };
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
const product = await core.productSource.getProduct(probeSku);
|
|
370
|
+
return product !== undefined ? { ok: true } : { ok: false, code: "PRODUCTS_NOT_FOUND" };
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return { ok: false, code: "PRODUCTS_UNREACHABLE" };
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
policy: () => {
|
|
377
|
+
const current = assembly.policy();
|
|
378
|
+
return current.digest !== "" ? { ok: true } : { ok: false, code: "POLICY_EMPTY" };
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
readinessForServiceControl = async () => {
|
|
382
|
+
const report = await readiness();
|
|
383
|
+
return { ready: report.ready, checks: report.checks };
|
|
384
|
+
};
|
|
385
|
+
// 4.5) BD-02:私有管理 API(/merchant/api/*)。会话与 /admin 同源;业务经共用
|
|
386
|
+
// MerchantApplicationService;权威操作记录落 state.sqlite。管理面未装配
|
|
387
|
+
// (无 admin 会话)时不挂载——/merchant/api 维持别名/404 旧行为。
|
|
388
|
+
const adminOptions = assembly.serverOptions.admin;
|
|
389
|
+
const productsFilePath = config.productsFile;
|
|
390
|
+
const applyPolicyOverride = assembly.service.policyApplier;
|
|
391
|
+
let managementDb;
|
|
392
|
+
let merchantApiHandler;
|
|
393
|
+
let publicFeedHandler;
|
|
394
|
+
let buyerHandler;
|
|
395
|
+
let reconciliationTimer;
|
|
396
|
+
let clockTimer;
|
|
397
|
+
if (adminOptions !== undefined) {
|
|
398
|
+
managementDb = new DatabaseSync(path.join(config.dataDir, "state.sqlite"));
|
|
399
|
+
serviceState.attachPersistence(managementDb, profile.owner_id);
|
|
400
|
+
const workbenchConfirmations = new WorkbenchConfirmationStore({ db: managementDb });
|
|
401
|
+
const reconciliationStore = new WorkbenchReconciliationStore({ db: managementDb });
|
|
402
|
+
const clockSafety = new ClockSafetyStore({ db: managementDb, alerts: reconciliationStore });
|
|
403
|
+
const workbenchCursorKey = loadOrCreateFeedCursorKey(config.dataDir);
|
|
404
|
+
const feedStore = new MerchantFeedStore({
|
|
405
|
+
db: managementDb,
|
|
406
|
+
cursorKey: workbenchCursorKey,
|
|
407
|
+
});
|
|
408
|
+
const grantStore = new MerchantGrantStore({ db: managementDb });
|
|
409
|
+
const followStore = new MerchantFollowStore({ db: managementDb });
|
|
410
|
+
const engagementStore = new MerchantEngagementStore({ db: managementDb });
|
|
411
|
+
const retentionStore = new WorkbenchRetentionStore({
|
|
412
|
+
db: managementDb,
|
|
413
|
+
deletionHandlers: {
|
|
414
|
+
"negotiation-ledger": createLedgerPayloadDeletionHandler({
|
|
415
|
+
dir: path.join(config.dataDir, "a2a"),
|
|
416
|
+
}),
|
|
417
|
+
"controlled-backup": createLocalBackupDeletionHandler({
|
|
418
|
+
dataDir: config.dataDir,
|
|
419
|
+
backupsDir: path.join(config.dataDir, "backups"),
|
|
420
|
+
}),
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
const retentionProcessor = String((options.env ?? process.env).KIWI_RETENTION_PROCESSOR ?? "").trim();
|
|
424
|
+
const retentionBasis = String((options.env ?? process.env).KIWI_RETENTION_BASIS ?? "").trim();
|
|
425
|
+
const retentionReviewAt = String((options.env ?? process.env).KIWI_RETENTION_REVIEW_AT ?? "").trim();
|
|
426
|
+
if (retentionProcessor !== "" && retentionBasis !== "" && retentionReviewAt !== "") {
|
|
427
|
+
retentionStore.configurePolicy(recommendedRetentionPolicy({
|
|
428
|
+
processor: retentionProcessor,
|
|
429
|
+
basis: retentionBasis,
|
|
430
|
+
reviewAt: retentionReviewAt,
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
const promotionStore = new MerchantPromotionStore({ db: managementDb, clockSafety });
|
|
434
|
+
const promotionWorkflowStore = new PromotionBroadcastWorkflowStore({ db: managementDb });
|
|
435
|
+
const eventProjectionStore = new WorkbenchEventProjectionStore({
|
|
436
|
+
db: managementDb,
|
|
437
|
+
cursorKey: workbenchCursorKey,
|
|
438
|
+
});
|
|
439
|
+
feedStoreForExecutors = feedStore;
|
|
440
|
+
grantStoreForExecutors = grantStore;
|
|
441
|
+
promotionStoreForExecutors = promotionStore;
|
|
442
|
+
promotionWorkflowStoreForExecutors = promotionWorkflowStore;
|
|
443
|
+
const referenceTimeUrl = String((options.env ?? process.env).KIWI_REFERENCE_TIME_URL ?? "").trim();
|
|
444
|
+
if (referenceTimeUrl !== "") {
|
|
445
|
+
const referenceUrl = requireSecureProbeUrl(referenceTimeUrl, "KIWI_REFERENCE_TIME_URL");
|
|
446
|
+
let clockProbeRunning = false;
|
|
447
|
+
const probeClock = () => {
|
|
448
|
+
if (clockProbeRunning)
|
|
449
|
+
return;
|
|
450
|
+
clockProbeRunning = true;
|
|
451
|
+
void probeReferenceClock(clockSafety, {
|
|
452
|
+
merchantId: profile.owner_id,
|
|
453
|
+
referenceUrl,
|
|
454
|
+
})
|
|
455
|
+
.catch(() => {
|
|
456
|
+
log("[kiwi-cloud] reference clock probe failed; prior clock-safety state retained\n");
|
|
457
|
+
})
|
|
458
|
+
.finally(() => {
|
|
459
|
+
clockProbeRunning = false;
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
clockTimer = setInterval(probeClock, 60_000);
|
|
463
|
+
clockTimer.unref();
|
|
464
|
+
probeClock();
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
log("[kiwi-cloud] KIWI_REFERENCE_TIME_URL is unset; time-sensitive promotion writes remain paused\n");
|
|
468
|
+
}
|
|
469
|
+
await recoverPromotionBroadcastWorkflows({
|
|
470
|
+
merchantId: profile.owner_id,
|
|
471
|
+
workflows: promotionWorkflowStore,
|
|
472
|
+
promotions: promotionStore,
|
|
473
|
+
grants: grantStore,
|
|
474
|
+
listPending: () => adminOptions.surface.listPending(),
|
|
475
|
+
getCandidate: (candidateId) => adminOptions.surface.getCandidate?.(candidateId),
|
|
476
|
+
prepareBroadcast: async ({ broadcast, authorization, workflowId }) => {
|
|
477
|
+
const prepared = await assembly.service.prepareBroadcastPublish({
|
|
478
|
+
broadcast,
|
|
479
|
+
authorization,
|
|
480
|
+
workflowId,
|
|
481
|
+
reason: "startup recovery for published promotion",
|
|
482
|
+
});
|
|
483
|
+
return prepared.candidate.candidate_id;
|
|
484
|
+
},
|
|
485
|
+
});
|
|
486
|
+
publicFeedHandler = createMerchantFeedApiHandler({
|
|
487
|
+
merchantId: profile.owner_id,
|
|
488
|
+
store: feedStore,
|
|
489
|
+
});
|
|
490
|
+
const resolveVerifiedBuyer = async (request, body) => {
|
|
491
|
+
const socketTls = request.socket;
|
|
492
|
+
const result = await authVerifier.verify({
|
|
493
|
+
remoteAddress: request.socket.remoteAddress,
|
|
494
|
+
authorizationHeader: request.headers.authorization,
|
|
495
|
+
method: request.method ?? "",
|
|
496
|
+
url: request.url ?? "",
|
|
497
|
+
scheme: socketTls.encrypted === true ? "https" : "http",
|
|
498
|
+
headers: request.headers,
|
|
499
|
+
body,
|
|
500
|
+
});
|
|
501
|
+
if (!result.authenticated ||
|
|
502
|
+
result.identityVerified !== true ||
|
|
503
|
+
typeof result.identity !== "string" ||
|
|
504
|
+
result.identity.trim() === "") {
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
merchantId: profile.owner_id,
|
|
509
|
+
buyerPrincipalId: result.identity,
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
const followHandler = createMerchantFollowApiHandler({
|
|
513
|
+
merchantId: profile.owner_id,
|
|
514
|
+
store: followStore,
|
|
515
|
+
resolveBuyer: resolveVerifiedBuyer,
|
|
516
|
+
});
|
|
517
|
+
const engagementHandler = createMerchantEngagementApiHandler({
|
|
518
|
+
merchantId: profile.owner_id,
|
|
519
|
+
store: engagementStore,
|
|
520
|
+
broadcastExists: (broadcastId) => feedStore.getBroadcast(profile.owner_id, broadcastId) !== undefined,
|
|
521
|
+
resolveBuyer: async (request, body) => await resolveVerifiedBuyer(request, body),
|
|
522
|
+
});
|
|
523
|
+
const privacyHandler = createMerchantPrivacyApiHandler({
|
|
524
|
+
merchantId: profile.owner_id,
|
|
525
|
+
store: retentionStore,
|
|
526
|
+
resolveBuyer: resolveVerifiedBuyer,
|
|
527
|
+
});
|
|
528
|
+
buyerHandler = (request, response) => {
|
|
529
|
+
const pathname = new URL(request.url ?? "/", "http://buyer.internal").pathname;
|
|
530
|
+
if (pathname === "/buyer/v1/follow")
|
|
531
|
+
followHandler(request, response);
|
|
532
|
+
else if (pathname.startsWith("/buyer/v1/privacy-requests")) {
|
|
533
|
+
privacyHandler(request, response);
|
|
534
|
+
}
|
|
535
|
+
else
|
|
536
|
+
engagementHandler(request, response);
|
|
537
|
+
};
|
|
538
|
+
merchantApiHandler = createMerchantManagementApiHandler({
|
|
539
|
+
merchantId: profile.owner_id,
|
|
540
|
+
// 单代次实例(与 M2 挑战应答的 currentGeneration 同值);代次切换属 BD-05。
|
|
541
|
+
generation: () => 1,
|
|
542
|
+
runtimeVersion: PRODUCT_VERSION,
|
|
543
|
+
sessions: adminOptions.sessions,
|
|
544
|
+
...(adminOptions.secureCookies === true ? { secureCookies: true } : {}),
|
|
545
|
+
allowedOrigins: [config.publicOrigin],
|
|
546
|
+
listPending: () => adminOptions.surface.listPending(),
|
|
547
|
+
mintCandidateConfirmation: (input) => adminOptions.store.createConfirmation(input),
|
|
548
|
+
executeDecision: async (input) => {
|
|
549
|
+
if (input.approve) {
|
|
550
|
+
await adminOptions.surface.executeApproved(input.candidateId, input.actorId, input.confirmationRef);
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
await adminOptions.surface.rejectCandidate(input.candidateId, input.actorId, input.confirmationRef);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
policy: () => {
|
|
557
|
+
const current = assembly.policy();
|
|
558
|
+
return current.digest === ""
|
|
559
|
+
? undefined
|
|
560
|
+
: { version: current.version, digest: current.digest };
|
|
561
|
+
},
|
|
562
|
+
// 商品投影/导入:仅在配置了商品表文件时可用;ProductTableError → 503
|
|
563
|
+
//(不让「表不可读」伪装成「无商品」)。价格即商品表的 major units(元),
|
|
564
|
+
// 与 MerchantProductSource 契约同单位,不经换算(金额单位红线)。
|
|
565
|
+
...(fileProductSource !== undefined && productsFilePath !== undefined
|
|
566
|
+
? {
|
|
567
|
+
products: async (query) => {
|
|
568
|
+
let records;
|
|
569
|
+
try {
|
|
570
|
+
records = fileProductSource.list();
|
|
571
|
+
}
|
|
572
|
+
catch (err) {
|
|
573
|
+
if (err instanceof ProductTableError) {
|
|
574
|
+
throw new ManagementError("unavailable", `product table unavailable (${err.code})`);
|
|
575
|
+
}
|
|
576
|
+
throw err;
|
|
577
|
+
}
|
|
578
|
+
const offset = query.cursor !== undefined
|
|
579
|
+
? Math.max(0, Number.parseInt(query.cursor, 10) || 0)
|
|
580
|
+
: 0;
|
|
581
|
+
const limit = Math.min(Math.max(query.limit ?? 50, 1), 100);
|
|
582
|
+
const nowMs = Date.now();
|
|
583
|
+
const items = records.slice(offset, offset + limit).map((record) => ({
|
|
584
|
+
sku: record.sku,
|
|
585
|
+
title: record.title,
|
|
586
|
+
currency: record.currency,
|
|
587
|
+
price: record.price,
|
|
588
|
+
price_unit: record.unit,
|
|
589
|
+
min_order_qty: record.moq ?? null,
|
|
590
|
+
valid_until: record.valid_until,
|
|
591
|
+
updated_at: record.updated_at,
|
|
592
|
+
status: record.status === "paused"
|
|
593
|
+
? "paused"
|
|
594
|
+
: Date.parse(record.valid_until) < nowMs
|
|
595
|
+
? "expired"
|
|
596
|
+
: "active",
|
|
597
|
+
}));
|
|
598
|
+
return {
|
|
599
|
+
items,
|
|
600
|
+
next_cursor: offset + limit < records.length ? String(offset + limit) : null,
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
productsImport: {
|
|
604
|
+
currentTable: () => {
|
|
605
|
+
const snapshot = loadProductTableSnapshot(productsFilePath, profile.owner_id);
|
|
606
|
+
return { digest: snapshot.digest, records: snapshot.records };
|
|
607
|
+
},
|
|
608
|
+
commit: (table) => commitProductTable(productsFilePath, profile.owner_id, table),
|
|
609
|
+
},
|
|
610
|
+
}
|
|
611
|
+
: {}),
|
|
612
|
+
...(applyPolicyOverride !== undefined
|
|
613
|
+
? {
|
|
614
|
+
policyApply: async (patch) => {
|
|
615
|
+
const applied = await applyPolicyOverride(patch);
|
|
616
|
+
return { version: applied.version, digest: applied.digest };
|
|
617
|
+
},
|
|
618
|
+
}
|
|
619
|
+
: {}),
|
|
620
|
+
drafts: new MerchantImportDraftStore({
|
|
621
|
+
db: managementDb,
|
|
622
|
+
now: () => new Date().toISOString(),
|
|
623
|
+
}),
|
|
624
|
+
operations: new MerchantManagementOperationStore({ db: managementDb }),
|
|
625
|
+
// M4 §5.4:开通向导与 /admin/onboarding 读**同一份** OnboardingStore(同一个
|
|
626
|
+
// state.sqlite),不复制状态机。`platformEvidence` 适配器**故意不配**——平台侧
|
|
627
|
+
// 取回执的能力尚未落地,因此需要权威证据的步骤会明确 503(不推进),
|
|
628
|
+
// 绝不用请求体自报的证据顶上(T029)。
|
|
629
|
+
onboarding: { store: new OnboardingStore(managementDb) },
|
|
630
|
+
workbenchConfirmations,
|
|
631
|
+
workbenchReconciliation: reconciliationStore,
|
|
632
|
+
workbenchEvents: eventProjectionStore,
|
|
633
|
+
followerSummary: () => followStore.activeCount(profile.owner_id),
|
|
634
|
+
engagementSummary: () => engagementStore.summary(profile.owner_id),
|
|
635
|
+
workbenchRetention: retentionStore,
|
|
636
|
+
workbenchFeed: feedStore,
|
|
637
|
+
workbenchGrants: grantStore,
|
|
638
|
+
workbenchPromotions: promotionStore,
|
|
639
|
+
promotionBroadcastWorkflows: promotionWorkflowStore,
|
|
640
|
+
...(adminOptions.surface.listA2aNegotiations !== undefined &&
|
|
641
|
+
adminOptions.surface.getA2aNegotiation !== undefined
|
|
642
|
+
? {
|
|
643
|
+
negotiations: {
|
|
644
|
+
list: (limit) => adminOptions.surface.listA2aNegotiations(limit),
|
|
645
|
+
get: (negotiationId) => adminOptions.surface.getA2aNegotiation(negotiationId),
|
|
646
|
+
},
|
|
647
|
+
}
|
|
648
|
+
: {}),
|
|
649
|
+
...(adminOptions.surface.listExactProducts !== undefined &&
|
|
650
|
+
adminOptions.surface.getExactProduct !== undefined
|
|
651
|
+
? {
|
|
652
|
+
exactProducts: {
|
|
653
|
+
list: () => adminOptions.surface.listExactProducts(),
|
|
654
|
+
get: (sku) => adminOptions.surface.getExactProduct(sku),
|
|
655
|
+
},
|
|
656
|
+
}
|
|
657
|
+
: {}),
|
|
658
|
+
...(adminOptions.surface.getExactProduct !== undefined
|
|
659
|
+
? {
|
|
660
|
+
quotePreview: async (sku, quantity) => {
|
|
661
|
+
const product = await adminOptions.surface.getExactProduct(sku);
|
|
662
|
+
const promotions = promotionStore.activeForSku(profile.owner_id, sku, quantity);
|
|
663
|
+
if (product.currency_table_version !== WORKBENCH_CURRENCY_TABLE_VERSION) {
|
|
664
|
+
throw new Error("exact product currency table version mismatch");
|
|
665
|
+
}
|
|
666
|
+
const privateFloorMinor = assembly.privateFloorMinor(sku, product.currency);
|
|
667
|
+
return calculateWorkbenchQuote({
|
|
668
|
+
base: {
|
|
669
|
+
currency: product.currency,
|
|
670
|
+
amount_minor: product.price_minor,
|
|
671
|
+
currency_table_version: WORKBENCH_CURRENCY_TABLE_VERSION,
|
|
672
|
+
},
|
|
673
|
+
quantity,
|
|
674
|
+
promotions,
|
|
675
|
+
...(privateFloorMinor !== undefined ? { privateFloorMinor } : {}),
|
|
676
|
+
});
|
|
677
|
+
},
|
|
678
|
+
}
|
|
679
|
+
: {}),
|
|
680
|
+
...(adminOptions.surface.prepareBroadcastPublish !== undefined
|
|
681
|
+
? { prepareBroadcastPublish: adminOptions.surface.prepareBroadcastPublish }
|
|
682
|
+
: {}),
|
|
683
|
+
...(adminOptions.surface.prepareInventoryUpdate !== undefined
|
|
684
|
+
? { prepareInventoryUpdate: adminOptions.surface.prepareInventoryUpdate }
|
|
685
|
+
: {}),
|
|
686
|
+
...(adminOptions.surface.prepareListingChange !== undefined
|
|
687
|
+
? { prepareListingChange: adminOptions.surface.prepareListingChange }
|
|
688
|
+
: {}),
|
|
689
|
+
...(adminOptions.surface.prepareExactProductCreate !== undefined
|
|
690
|
+
? { prepareExactProductCreate: adminOptions.surface.prepareExactProductCreate }
|
|
691
|
+
: {}),
|
|
692
|
+
...(adminOptions.surface.prepareExactProductMoneyUpdate !== undefined
|
|
693
|
+
? {
|
|
694
|
+
prepareExactProductMoneyUpdate: adminOptions.surface.prepareExactProductMoneyUpdate,
|
|
695
|
+
}
|
|
696
|
+
: {}),
|
|
697
|
+
...(adminOptions.surface.prepareServiceResume !== undefined
|
|
698
|
+
? { prepareServiceResume: adminOptions.surface.prepareServiceResume }
|
|
699
|
+
: {}),
|
|
700
|
+
...(adminOptions.surface.prepareBroadcastRevise !== undefined
|
|
701
|
+
? { prepareBroadcastRevise: adminOptions.surface.prepareBroadcastRevise }
|
|
702
|
+
: {}),
|
|
703
|
+
...(adminOptions.surface.prepareBroadcastWithdraw !== undefined
|
|
704
|
+
? { prepareBroadcastWithdraw: adminOptions.surface.prepareBroadcastWithdraw }
|
|
705
|
+
: {}),
|
|
706
|
+
...(adminOptions.surface.prepareGrantCreate !== undefined
|
|
707
|
+
? { prepareGrantCreate: adminOptions.surface.prepareGrantCreate }
|
|
708
|
+
: {}),
|
|
709
|
+
...(adminOptions.surface.prepareGrantRevoke !== undefined
|
|
710
|
+
? { prepareGrantRevoke: adminOptions.surface.prepareGrantRevoke }
|
|
711
|
+
: {}),
|
|
712
|
+
...(adminOptions.surface.preparePromotionPublish !== undefined
|
|
713
|
+
? { preparePromotionPublish: adminOptions.surface.preparePromotionPublish }
|
|
714
|
+
: {}),
|
|
715
|
+
...(adminOptions.surface.preparePromotionWithdraw !== undefined
|
|
716
|
+
? { preparePromotionWithdraw: adminOptions.surface.preparePromotionWithdraw }
|
|
717
|
+
: {}),
|
|
718
|
+
serviceState,
|
|
719
|
+
readiness: async () => {
|
|
720
|
+
const report = await readiness();
|
|
721
|
+
return { ready: report.ready, checks: report.checks };
|
|
722
|
+
},
|
|
723
|
+
log,
|
|
724
|
+
});
|
|
725
|
+
const worker = new WorkbenchReconciliationWorker(reconciliationStore, {
|
|
726
|
+
workerId: `runtime:${profile.agent_id}`,
|
|
727
|
+
merchantId: profile.owner_id,
|
|
728
|
+
execute: async (lease) => {
|
|
729
|
+
if (adminOptions.surface.executeCommittedDecision === undefined) {
|
|
730
|
+
return { status: "failed", error: "committed-decision execution is not configured" };
|
|
731
|
+
}
|
|
732
|
+
try {
|
|
733
|
+
const authorization = workbenchConfirmations.authorizationSnapshotForOperation(lease.operationId);
|
|
734
|
+
if (authorization !== undefined) {
|
|
735
|
+
const action = String(authorization["action"] ?? "");
|
|
736
|
+
const allowed = action === "grants.manage" || action === "service.resume"
|
|
737
|
+
? authorization["actor_id"] === lease.actorId &&
|
|
738
|
+
authorization["actor_role"] === "owner"
|
|
739
|
+
: isCurrentGrantAuthorization(grantStore, {
|
|
740
|
+
merchantId: profile.owner_id,
|
|
741
|
+
actorId: lease.actorId,
|
|
742
|
+
action: action === "product.decide" || action === "product.create"
|
|
743
|
+
? action
|
|
744
|
+
: "broadcast.decide",
|
|
745
|
+
...(action === "product.decide"
|
|
746
|
+
? {
|
|
747
|
+
resourceType: "product",
|
|
748
|
+
resourceIds: Array.isArray(authorization["resource_ids"])
|
|
749
|
+
? authorization["resource_ids"].map((value) => String(value))
|
|
750
|
+
: [],
|
|
751
|
+
}
|
|
752
|
+
: action === "product.create"
|
|
753
|
+
? { resourceType: "merchant" }
|
|
754
|
+
: {}),
|
|
755
|
+
snapshot: authorization,
|
|
756
|
+
});
|
|
757
|
+
if (!allowed) {
|
|
758
|
+
return { status: "failed", error: "Workbench decision authorization was revoked" };
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const outcome = await adminOptions.surface.executeCommittedDecision({
|
|
762
|
+
operationId: lease.operationId,
|
|
763
|
+
candidateId: lease.candidateId,
|
|
764
|
+
actorId: lease.actorId,
|
|
765
|
+
decision: lease.decision,
|
|
766
|
+
}, workbenchConfirmations);
|
|
767
|
+
return committedDecisionOutcomeResult(outcome);
|
|
768
|
+
}
|
|
769
|
+
catch (error) {
|
|
770
|
+
// The executor may have crossed an external side-effect boundary before throwing.
|
|
771
|
+
// Never resubmit: persist UNKNOWN and let the query path reconcile the same operation.
|
|
772
|
+
return {
|
|
773
|
+
status: "unknown",
|
|
774
|
+
error: error instanceof Error ? error.message : String(error),
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
},
|
|
778
|
+
query: async (lease) => {
|
|
779
|
+
if (adminOptions.surface.queryCommittedDecisionOutcome !== undefined) {
|
|
780
|
+
return await adminOptions.surface.queryCommittedDecisionOutcome({
|
|
781
|
+
operationId: lease.operationId,
|
|
782
|
+
candidateId: lease.candidateId,
|
|
783
|
+
actorId: lease.actorId,
|
|
784
|
+
decision: lease.decision,
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
if (adminOptions.surface.getCandidate === undefined) {
|
|
788
|
+
return { status: "failed", error: "candidate query is not configured" };
|
|
789
|
+
}
|
|
790
|
+
const candidate = adminOptions.surface.getCandidate(reconciliationStore.candidateIdForOperation(lease.operationId) ?? "");
|
|
791
|
+
if (candidate === undefined)
|
|
792
|
+
return { status: "failed", error: "candidate is unavailable" };
|
|
793
|
+
return candidateReconciliationResult({
|
|
794
|
+
status: candidate.status,
|
|
795
|
+
executionClaimed: adminOptions.surface.candidateExecutionWasClaimed?.(candidate.candidate_id),
|
|
796
|
+
});
|
|
797
|
+
},
|
|
798
|
+
});
|
|
799
|
+
let workerRunning = false;
|
|
800
|
+
const tick = () => {
|
|
801
|
+
if (workerRunning)
|
|
802
|
+
return;
|
|
803
|
+
workerRunning = true;
|
|
804
|
+
void worker
|
|
805
|
+
.runOnce()
|
|
806
|
+
.catch((error) => {
|
|
807
|
+
log(`[kiwi-cloud] Workbench reconciliation tick failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
808
|
+
})
|
|
809
|
+
.finally(() => {
|
|
810
|
+
workerRunning = false;
|
|
811
|
+
});
|
|
812
|
+
};
|
|
813
|
+
reconciliationTimer = setInterval(tick, 5_000);
|
|
814
|
+
reconciliationTimer.unref();
|
|
815
|
+
tick();
|
|
816
|
+
}
|
|
817
|
+
// 4.6) 商家工作台首页(/merchant/ 静态壳;数据经 /merchant/api/* 认证获取)。
|
|
818
|
+
const merchantHomePage = (_req, res) => {
|
|
819
|
+
res.writeHead(200, {
|
|
820
|
+
"content-type": "text/html; charset=utf-8",
|
|
821
|
+
"cache-control": "no-store",
|
|
822
|
+
});
|
|
823
|
+
res.end(renderMerchantManagementPage());
|
|
824
|
+
};
|
|
825
|
+
// 5) 单端口路由:A2A 面 / 商家面 / 管理面 / 探针,各自鉴权边界不变。
|
|
826
|
+
const merchantHandler = createMerchantHttpHandler(assembly.serverOptions);
|
|
827
|
+
const router = createCloudRouter({
|
|
828
|
+
a2aHandler: core.server.handler(),
|
|
829
|
+
merchantHandler: merchantHandler.handler,
|
|
830
|
+
...(merchantApiHandler !== undefined ? { merchantApiHandler } : {}),
|
|
831
|
+
...(publicFeedHandler !== undefined ? { publicFeedHandler } : {}),
|
|
832
|
+
...(buyerHandler !== undefined ? { buyerHandler } : {}),
|
|
833
|
+
trustedPageHandler: createTrustedWorkbenchPageHandler(),
|
|
834
|
+
merchantHomePage,
|
|
835
|
+
readiness,
|
|
836
|
+
a2aPaths: [CLOUD_A2A_PATH],
|
|
837
|
+
// 绑定挑战应答(M2 §6.3):只签发给本实例的受限结构挑战,一次性、有速率上限。
|
|
838
|
+
challengeHandler: createChallengeResponder({
|
|
839
|
+
signingIdentity: toJwsSigningIdentity(signingIdentity),
|
|
840
|
+
expectedMerchantId: profile.owner_id,
|
|
841
|
+
expectedAgentId: profile.agent_id,
|
|
842
|
+
currentGeneration: 1,
|
|
843
|
+
...(options.challengeStore !== undefined ? { store: options.challengeStore } : {}),
|
|
844
|
+
}),
|
|
845
|
+
version: PRODUCT_VERSION,
|
|
846
|
+
});
|
|
847
|
+
const server = createServer(router);
|
|
848
|
+
server.on("clientError", () => {
|
|
849
|
+
// 畸形客户端流量(中止的 socket 等)不得让服务崩溃。
|
|
850
|
+
});
|
|
851
|
+
// 6) 严格监听:端口被占用即失败,绝不换端口(T013)。
|
|
852
|
+
try {
|
|
853
|
+
await new Promise((resolve, reject) => {
|
|
854
|
+
const onError = (err) => {
|
|
855
|
+
reject(new CloudStartupError(err.code === "EADDRINUSE" ? "PORT_IN_USE" : "LISTEN_FAILED", `监听 ${config.bindHost}:${config.port} 失败(${err.code ?? "unknown"}):` +
|
|
856
|
+
"云端不换端口——请确认端口未被占用且与平台注入值一致"));
|
|
857
|
+
};
|
|
858
|
+
server.once("error", onError);
|
|
859
|
+
server.listen(config.port, config.bindHost, () => {
|
|
860
|
+
server.removeListener("error", onError);
|
|
861
|
+
resolve();
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
catch (err) {
|
|
866
|
+
if (reconciliationTimer !== undefined)
|
|
867
|
+
clearInterval(reconciliationTimer);
|
|
868
|
+
if (clockTimer !== undefined)
|
|
869
|
+
clearInterval(clockTimer);
|
|
870
|
+
managementDb?.close();
|
|
871
|
+
core.close();
|
|
872
|
+
await assembly.close().catch(() => undefined);
|
|
873
|
+
throw err;
|
|
874
|
+
}
|
|
875
|
+
const summary = describeCloudConfig(config);
|
|
876
|
+
log(`[kiwi-cloud] listening ${config.bindHost}:${config.port}` +
|
|
877
|
+
`(origin=${summary.publicOrigin},a2a=${CLOUD_A2A_PATH},auth=${summary.a2aAuth},` +
|
|
878
|
+
`merchant=${assembly.authLabel},version=${PRODUCT_VERSION})\n`);
|
|
879
|
+
// 自检:把就绪结论写进启动日志(不含敏感值);不就绪只告警不拒绝启动
|
|
880
|
+
// (M1 允许"进程活着但未就绪"——探针语义由 /readyz 精确表达)。
|
|
881
|
+
try {
|
|
882
|
+
const report = await readiness();
|
|
883
|
+
log(`[kiwi-cloud] readyz=${report.ready ? "ready" : "not-ready"}` +
|
|
884
|
+
` checks=${JSON.stringify(report.checks)}\n`);
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
log("[kiwi-cloud] readyz 自检异常(不影响启动)\n");
|
|
888
|
+
}
|
|
889
|
+
return {
|
|
890
|
+
config,
|
|
891
|
+
server,
|
|
892
|
+
readiness,
|
|
893
|
+
close: async () => {
|
|
894
|
+
await new Promise((resolve) => {
|
|
895
|
+
server.close(() => resolve());
|
|
896
|
+
server.closeAllConnections();
|
|
897
|
+
});
|
|
898
|
+
await merchantHandler.close().catch(() => undefined);
|
|
899
|
+
if (reconciliationTimer !== undefined)
|
|
900
|
+
clearInterval(reconciliationTimer);
|
|
901
|
+
if (clockTimer !== undefined)
|
|
902
|
+
clearInterval(clockTimer);
|
|
903
|
+
core.close();
|
|
904
|
+
await assembly.close().catch(() => undefined);
|
|
905
|
+
managementDb?.close();
|
|
906
|
+
},
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
/** 供入口脚本复用的错误渲染:稳定码 + 可读消息,不含凭据。 */
|
|
910
|
+
export function renderStartupFailure(err) {
|
|
911
|
+
if (err instanceof CloudConfigError || err instanceof CloudStartupError) {
|
|
912
|
+
return `[kiwi-cloud] 启动失败(${err.code}):${err.message}\n`;
|
|
913
|
+
}
|
|
914
|
+
if (err instanceof Error)
|
|
915
|
+
return `[kiwi-cloud] 启动失败:${err.message}\n`;
|
|
916
|
+
return `[kiwi-cloud] 启动失败:${String(err)}\n`;
|
|
917
|
+
}
|
|
918
|
+
function recordValue(value) {
|
|
919
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
920
|
+
throw new Error("broadcast authorization snapshot is missing");
|
|
921
|
+
}
|
|
922
|
+
return value;
|
|
923
|
+
}
|
|
924
|
+
function requireSecureProbeUrl(value, field) {
|
|
925
|
+
let url;
|
|
926
|
+
try {
|
|
927
|
+
url = new URL(value);
|
|
928
|
+
}
|
|
929
|
+
catch {
|
|
930
|
+
throw new CloudStartupError("INVALID_CONFIG", `${field} must be a valid URL`);
|
|
931
|
+
}
|
|
932
|
+
if (url.protocol !== "https:" && !["127.0.0.1", "localhost", "::1"].includes(url.hostname)) {
|
|
933
|
+
throw new CloudStartupError("INVALID_CONFIG", `${field} must use HTTPS unless it is loopback`);
|
|
934
|
+
}
|
|
935
|
+
return url;
|
|
936
|
+
}
|
|
937
|
+
//# sourceMappingURL=bootstrap.js.map
|