@harrylabsj/kiwi 0.12.31 → 0.12.33
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 +8 -0
- package/dist/a2a/inquiry-nonce-store.d.ts +12 -1
- package/dist/a2a/inquiry-nonce-store.js +49 -17
- package/dist/a2a/inquiry-nonce-store.js.map +1 -1
- package/dist/a2a/negotiate.d.ts +30 -1
- package/dist/a2a/negotiate.js +121 -32
- package/dist/a2a/negotiate.js.map +1 -1
- package/dist/a2a/node.d.ts +4 -0
- package/dist/a2a/node.js +182 -4
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/open-inquiry-session.d.ts +1 -0
- package/dist/a2a/open-inquiry-session.js +3 -1
- package/dist/a2a/open-inquiry-session.js.map +1 -1
- package/dist/a2a/open-inquiry-verifier.js +2 -2
- package/dist/a2a/open-inquiry-verifier.js.map +1 -1
- package/dist/a2a/reception/agent-runtime.d.ts +32 -1
- package/dist/a2a/reception/agent-runtime.js +420 -11
- package/dist/a2a/reception/agent-runtime.js.map +1 -1
- package/dist/a2a/reception/customer-memory-tools.d.ts +73 -0
- package/dist/a2a/reception/customer-memory-tools.js +17 -0
- package/dist/a2a/reception/customer-memory-tools.js.map +1 -0
- package/dist/a2a/reception/engine.d.ts +12 -0
- package/dist/a2a/reception/engine.js +42 -1
- package/dist/a2a/reception/engine.js.map +1 -1
- package/dist/a2a/reception/publish.d.ts +14 -1
- package/dist/a2a/reception/publish.js +62 -1
- package/dist/a2a/reception/publish.js.map +1 -1
- package/dist/a2a/reception/question-spec.d.ts +91 -0
- package/dist/a2a/reception/question-spec.js +260 -0
- package/dist/a2a/reception/question-spec.js.map +1 -0
- package/dist/a2a/reception/reply-outbox.d.ts +6 -0
- package/dist/a2a/reception/reply-outbox.js +44 -0
- package/dist/a2a/reception/reply-outbox.js.map +1 -1
- package/dist/a2a/reception/responder.d.ts +13 -1
- package/dist/a2a/reception/responder.js +26 -3
- package/dist/a2a/reception/responder.js.map +1 -1
- package/dist/a2a/reception/skill-catalog.d.ts +72 -0
- package/dist/a2a/reception/skill-catalog.js +85 -0
- package/dist/a2a/reception/skill-catalog.js.map +1 -0
- package/dist/a2a/reception/skill-contract.d.ts +70 -0
- package/dist/a2a/reception/skill-contract.js +183 -0
- package/dist/a2a/reception/skill-contract.js.map +1 -0
- package/dist/a2a/reception/types.d.ts +12 -0
- package/dist/a2a/server/customer-identity-gateway.d.ts +111 -0
- package/dist/a2a/server/customer-identity-gateway.js +441 -0
- package/dist/a2a/server/customer-identity-gateway.js.map +1 -0
- package/dist/a2a/server/errors.d.ts +4 -3
- package/dist/a2a/server/errors.js +10 -2
- package/dist/a2a/server/errors.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +75 -1
- package/dist/a2a/server/merchant-handler.js +676 -86
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/merchant-procurement.d.ts +90 -0
- package/dist/a2a/server/merchant-procurement.js +75 -0
- package/dist/a2a/server/merchant-procurement.js.map +1 -0
- package/dist/a2a/server/merchant-product-facts.d.ts +2 -0
- package/dist/a2a/server/merchant-product-facts.js.map +1 -1
- package/dist/a2a/server/negotiation-approvals.d.ts +11 -0
- package/dist/a2a/server/negotiation-approvals.js +43 -0
- package/dist/a2a/server/negotiation-approvals.js.map +1 -1
- package/dist/a2a/server/pipeline.js +78 -30
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.js +4 -3
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/types.d.ts +4 -1
- package/dist/a2a/unit-alias.d.ts +3 -3
- package/dist/a2a/unit-alias.js +9 -5
- package/dist/a2a/unit-alias.js.map +1 -1
- package/dist/agent/alipay-native-view.d.ts +27 -0
- package/dist/agent/alipay-native-view.js +113 -0
- package/dist/agent/alipay-native-view.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.d.ts +20 -0
- package/dist/agent/buyer/buyer-tools.js +241 -48
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/types.d.ts +1 -1
- package/dist/agent/buyer/types.js.map +1 -1
- package/dist/agent/chat-tui.js +16 -1
- package/dist/agent/chat-tui.js.map +1 -1
- package/dist/agent/kernel-builder.d.ts +2 -0
- package/dist/agent/kernel-builder.js +14 -0
- package/dist/agent/kernel-builder.js.map +1 -1
- package/dist/agent/kernel.d.ts +8 -0
- package/dist/agent/kernel.js +67 -1
- package/dist/agent/kernel.js.map +1 -1
- package/dist/auth/merchant-sessions.d.ts +3 -0
- package/dist/auth/merchant-sessions.js +21 -5
- package/dist/auth/merchant-sessions.js.map +1 -1
- package/dist/buyer-core/a2a-accept-terms.d.ts +11 -0
- package/dist/buyer-core/a2a-accept-terms.js +28 -0
- package/dist/buyer-core/a2a-accept-terms.js.map +1 -0
- package/dist/buyer-core/a2a-knp.d.ts +7 -2
- package/dist/buyer-core/a2a-knp.js +8 -5
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +17 -0
- package/dist/buyer-core/a2a-negotiator.js +70 -26
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -15
- package/dist/buyer-core/a2a-quote-fetcher.js +92 -19
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/a2a-quote-history.d.ts +94 -0
- package/dist/buyer-core/a2a-quote-history.js +149 -0
- package/dist/buyer-core/a2a-quote-history.js.map +1 -0
- package/dist/buyer-core/build-service.d.ts +19 -0
- package/dist/buyer-core/build-service.js +30 -1
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/errors.d.ts +1 -1
- package/dist/buyer-core/errors.js +1 -0
- package/dist/buyer-core/errors.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +2 -2
- package/dist/buyer-core/merchant-index.js +23 -5
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/open-inquiry-signer.d.ts +1 -0
- package/dist/buyer-core/open-inquiry-signer.js +5 -2
- package/dist/buyer-core/open-inquiry-signer.js.map +1 -1
- package/dist/buyer-core/procurement/cases.d.ts +441 -0
- package/dist/buyer-core/procurement/cases.js +457 -0
- package/dist/buyer-core/procurement/cases.js.map +1 -0
- package/dist/buyer-core/procurement/quote-comparison.d.ts +137 -0
- package/dist/buyer-core/procurement/quote-comparison.js +106 -0
- package/dist/buyer-core/procurement/quote-comparison.js.map +1 -0
- package/dist/buyer-core/procurement/quote-normalizer.d.ts +45 -0
- package/dist/buyer-core/procurement/quote-normalizer.js +153 -0
- package/dist/buyer-core/procurement/quote-normalizer.js.map +1 -0
- package/dist/buyer-core/procurement/requirements.d.ts +50 -0
- package/dist/buyer-core/procurement/requirements.js +43 -0
- package/dist/buyer-core/procurement/requirements.js.map +1 -0
- package/dist/buyer-core/procurement/source-observation.d.ts +57 -0
- package/dist/buyer-core/procurement/source-observation.js +54 -0
- package/dist/buyer-core/procurement/source-observation.js.map +1 -0
- package/dist/buyer-core/procurement/store.d.ts +21 -0
- package/dist/buyer-core/procurement/store.js +68 -0
- package/dist/buyer-core/procurement/store.js.map +1 -0
- package/dist/buyer-core/protocol-recovery.d.ts +10 -1
- package/dist/buyer-core/protocol-recovery.js +31 -6
- package/dist/buyer-core/protocol-recovery.js.map +1 -1
- package/dist/buyer-core/quote-quantity.d.ts +5 -0
- package/dist/buyer-core/quote-quantity.js +15 -0
- package/dist/buyer-core/quote-quantity.js.map +1 -0
- package/dist/buyer-core/service.d.ts +128 -8
- package/dist/buyer-core/service.js +543 -75
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +21 -0
- package/dist/buyer-core/store.js +62 -10
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +26 -19
- package/dist/cli.js.map +1 -1
- package/dist/cloud/alipay-collection-http.d.ts +44 -0
- package/dist/cloud/alipay-collection-http.js +111 -0
- package/dist/cloud/alipay-collection-http.js.map +1 -0
- package/dist/cloud/bootstrap.js +218 -19
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/http-router.d.ts +2 -0
- package/dist/cloud/http-router.js +5 -0
- package/dist/cloud/http-router.js.map +1 -1
- package/dist/commerce/receipt/dispatcher.d.ts +43 -0
- package/dist/commerce/receipt/dispatcher.js +86 -0
- package/dist/commerce/receipt/dispatcher.js.map +1 -0
- package/dist/commerce/receipt/receipts.d.ts +147 -0
- package/dist/commerce/receipt/receipts.js +285 -0
- package/dist/commerce/receipt/receipts.js.map +1 -0
- package/dist/config/profile.d.ts +2 -2
- package/dist/discovery/catalog-source/buyer-follows.d.ts +3 -3
- package/dist/discovery/catalog-source/buyer-follows.js +6 -3
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +4 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/handoff/alipay-collection.d.ts +23 -0
- package/dist/handoff/alipay-collection.js +70 -0
- package/dist/handoff/alipay-collection.js.map +1 -0
- package/dist/handoff/order-receipts.d.ts +62 -0
- package/dist/handoff/order-receipts.js +72 -0
- package/dist/handoff/order-receipts.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.d.ts +2 -1
- package/dist/handoff/ucp-checkout/cart-channel.js +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -1
- package/dist/handoff/ucp-checkout/channel.d.ts +7 -0
- package/dist/handoff/ucp-checkout/channel.js +79 -10
- package/dist/handoff/ucp-checkout/channel.js.map +1 -1
- package/dist/http/cli.js +6 -0
- package/dist/http/cli.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +18 -0
- package/dist/http/merchant-management/api.js +752 -3
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/draft-store.js +8 -6
- package/dist/http/merchant-management/draft-store.js.map +1 -1
- package/dist/http/merchant-management/page.d.ts +1 -0
- package/dist/http/merchant-management/page.js +335 -5
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/http/server.js +9 -2
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/cli.d.ts +3 -1
- package/dist/mcp/cli.js +18 -2
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/merchant-runtime-assembly.d.ts +20 -0
- package/dist/mcp/merchant-runtime-assembly.js +94 -11
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
- package/dist/mcp/merchant-server.d.ts +5 -0
- package/dist/mcp/merchant-server.js +12 -0
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/mcp/procurement-tools.d.ts +10 -0
- package/dist/mcp/procurement-tools.js +173 -0
- package/dist/mcp/procurement-tools.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.js +63 -9
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +4 -1
- package/dist/mcp/tools.js +83 -28
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +3 -1
- package/dist/merchant/application/actor.js +21 -0
- package/dist/merchant/application/actor.js.map +1 -1
- package/dist/merchant/negotiation-ops.d.ts +2 -0
- package/dist/merchant/negotiation-ops.js +4 -0
- package/dist/merchant/negotiation-ops.js.map +1 -1
- package/dist/merchant/weixin-channel.d.ts +68 -0
- package/dist/merchant/weixin-channel.js +313 -0
- package/dist/merchant/weixin-channel.js.map +1 -0
- package/dist/merchant/workbench-server.d.ts +1 -0
- package/dist/merchant/workbench-server.js +189 -2
- package/dist/merchant/workbench-server.js.map +1 -1
- package/dist/merchant-core/budget/background-budget.d.ts +132 -0
- package/dist/merchant-core/budget/background-budget.js +308 -0
- package/dist/merchant-core/budget/background-budget.js.map +1 -0
- package/dist/merchant-core/collection/alipay-store.d.ts +22 -0
- package/dist/merchant-core/collection/alipay-store.js +125 -0
- package/dist/merchant-core/collection/alipay-store.js.map +1 -0
- package/dist/merchant-core/commercial/calculate.js +6 -6
- package/dist/merchant-core/commercial/calculate.js.map +1 -1
- package/dist/merchant-core/context-governance/actor-context.d.ts +56 -0
- package/dist/merchant-core/context-governance/actor-context.js +76 -0
- package/dist/merchant-core/context-governance/actor-context.js.map +1 -0
- package/dist/merchant-core/context-governance/authority.d.ts +39 -0
- package/dist/merchant-core/context-governance/authority.js +28 -0
- package/dist/merchant-core/context-governance/authority.js.map +1 -0
- package/dist/merchant-core/context-governance/context-guard.d.ts +104 -0
- package/dist/merchant-core/context-governance/context-guard.js +194 -0
- package/dist/merchant-core/context-governance/context-guard.js.map +1 -0
- package/dist/merchant-core/context-governance/data-use-grant.d.ts +91 -0
- package/dist/merchant-core/context-governance/data-use-grant.js +211 -0
- package/dist/merchant-core/context-governance/data-use-grant.js.map +1 -0
- package/dist/merchant-core/context-governance/feature-flags.d.ts +32 -0
- package/dist/merchant-core/context-governance/feature-flags.js +83 -0
- package/dist/merchant-core/context-governance/feature-flags.js.map +1 -0
- package/dist/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
- package/dist/merchant-core/context-governance/pilot-readiness.js +141 -0
- package/dist/merchant-core/context-governance/pilot-readiness.js.map +1 -0
- package/dist/merchant-core/context-governance/source-governance.d.ts +157 -0
- package/dist/merchant-core/context-governance/source-governance.js +492 -0
- package/dist/merchant-core/context-governance/source-governance.js.map +1 -0
- package/dist/merchant-core/context-governance/types.d.ts +62 -0
- package/dist/merchant-core/context-governance/types.js +92 -0
- package/dist/merchant-core/context-governance/types.js.map +1 -0
- package/dist/merchant-core/customer-delivery/binding.d.ts +55 -0
- package/dist/merchant-core/customer-delivery/binding.js +121 -0
- package/dist/merchant-core/customer-delivery/binding.js.map +1 -0
- package/dist/merchant-core/customer-delivery/channel.d.ts +75 -0
- package/dist/merchant-core/customer-delivery/channel.js +157 -0
- package/dist/merchant-core/customer-delivery/channel.js.map +1 -0
- package/dist/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
- package/dist/merchant-core/customer-delivery/consent-repository.js +160 -0
- package/dist/merchant-core/customer-delivery/consent-repository.js.map +1 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
- package/dist/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
- package/dist/merchant-core/customer-delivery/dispatcher.js +166 -0
- package/dist/merchant-core/customer-delivery/dispatcher.js.map +1 -0
- package/dist/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
- package/dist/merchant-core/customer-delivery/email-adapter.js +90 -0
- package/dist/merchant-core/customer-delivery/email-adapter.js.map +1 -0
- package/dist/merchant-core/customer-delivery/gate.d.ts +37 -0
- package/dist/merchant-core/customer-delivery/gate.js +196 -0
- package/dist/merchant-core/customer-delivery/gate.js.map +1 -0
- package/dist/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
- package/dist/merchant-core/customer-delivery/reconciliation.js +70 -0
- package/dist/merchant-core/customer-delivery/reconciliation.js.map +1 -0
- package/dist/merchant-core/customer-delivery/repository.d.ts +55 -0
- package/dist/merchant-core/customer-delivery/repository.js +235 -0
- package/dist/merchant-core/customer-delivery/repository.js.map +1 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.js +183 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
- package/dist/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
- package/dist/merchant-core/customer-delivery/stream-gate.js +123 -0
- package/dist/merchant-core/customer-delivery/stream-gate.js.map +1 -0
- package/dist/merchant-core/customer-delivery/types.d.ts +103 -0
- package/dist/merchant-core/customer-delivery/types.js +32 -0
- package/dist/merchant-core/customer-delivery/types.js.map +1 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.js +56 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
- package/dist/merchant-core/customer-memory/auto-identity.d.ts +43 -0
- package/dist/merchant-core/customer-memory/auto-identity.js +163 -0
- package/dist/merchant-core/customer-memory/auto-identity.js.map +1 -0
- package/dist/merchant-core/customer-memory/grants.d.ts +72 -0
- package/dist/merchant-core/customer-memory/grants.js +224 -0
- package/dist/merchant-core/customer-memory/grants.js.map +1 -0
- package/dist/merchant-core/customer-memory/history.d.ts +51 -0
- package/dist/merchant-core/customer-memory/history.js +252 -0
- package/dist/merchant-core/customer-memory/history.js.map +1 -0
- package/dist/merchant-core/customer-memory/identity.d.ts +66 -0
- package/dist/merchant-core/customer-memory/identity.js +249 -0
- package/dist/merchant-core/customer-memory/identity.js.map +1 -0
- package/dist/merchant-core/customer-memory/maintenance.d.ts +51 -0
- package/dist/merchant-core/customer-memory/maintenance.js +67 -0
- package/dist/merchant-core/customer-memory/maintenance.js.map +1 -0
- package/dist/merchant-core/customer-memory/memory.d.ts +119 -0
- package/dist/merchant-core/customer-memory/memory.js +502 -0
- package/dist/merchant-core/customer-memory/memory.js.map +1 -0
- package/dist/merchant-core/customer-memory/private-transport.d.ts +10 -0
- package/dist/merchant-core/customer-memory/private-transport.js +108 -0
- package/dist/merchant-core/customer-memory/private-transport.js.map +1 -0
- package/dist/merchant-core/customer-memory/quote-history.d.ts +160 -0
- package/dist/merchant-core/customer-memory/quote-history.js +392 -0
- package/dist/merchant-core/customer-memory/quote-history.js.map +1 -0
- package/dist/merchant-core/customer-memory/reception-provider.d.ts +69 -0
- package/dist/merchant-core/customer-memory/reception-provider.js +250 -0
- package/dist/merchant-core/customer-memory/reception-provider.js.map +1 -0
- package/dist/merchant-core/customer-memory/reception-writer.d.ts +19 -0
- package/dist/merchant-core/customer-memory/reception-writer.js +32 -0
- package/dist/merchant-core/customer-memory/reception-writer.js.map +1 -0
- package/dist/merchant-core/customer-memory/types.d.ts +111 -0
- package/dist/merchant-core/customer-memory/types.js +58 -0
- package/dist/merchant-core/customer-memory/types.js.map +1 -0
- package/dist/merchant-core/followup/repository.d.ts +2 -1
- package/dist/merchant-core/followup/repository.js +29 -23
- package/dist/merchant-core/followup/repository.js.map +1 -1
- package/dist/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
- package/dist/merchant-core/learning/evaluation-fixtures.js +83 -0
- package/dist/merchant-core/learning/evaluation-fixtures.js.map +1 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.js +129 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
- package/dist/merchant-core/learning/evaluation.d.ts +84 -0
- package/dist/merchant-core/learning/evaluation.js +581 -0
- package/dist/merchant-core/learning/evaluation.js.map +1 -0
- package/dist/merchant-core/learning/initial-skills.d.ts +36 -0
- package/dist/merchant-core/learning/initial-skills.js +67 -0
- package/dist/merchant-core/learning/initial-skills.js.map +1 -0
- package/dist/merchant-core/learning/precheck.d.ts +33 -0
- package/dist/merchant-core/learning/precheck.js +56 -0
- package/dist/merchant-core/learning/precheck.js.map +1 -0
- package/dist/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
- package/dist/merchant-core/learning/real-evaluation-runner.js +167 -0
- package/dist/merchant-core/learning/real-evaluation-runner.js.map +1 -0
- package/dist/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
- package/dist/merchant-core/learning/reception-skill-catalog.js +145 -0
- package/dist/merchant-core/learning/reception-skill-catalog.js.map +1 -0
- package/dist/merchant-core/learning/recovery-gateway.d.ts +27 -0
- package/dist/merchant-core/learning/recovery-gateway.js +106 -0
- package/dist/merchant-core/learning/recovery-gateway.js.map +1 -0
- package/dist/merchant-core/learning/repository.d.ts +130 -0
- package/dist/merchant-core/learning/repository.js +588 -0
- package/dist/merchant-core/learning/repository.js.map +1 -0
- package/dist/merchant-core/learning/service.d.ts +262 -0
- package/dist/merchant-core/learning/service.js +1498 -0
- package/dist/merchant-core/learning/service.js.map +1 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.js +145 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
- package/dist/merchant-core/learning/types.d.ts +217 -0
- package/dist/merchant-core/learning/types.js +52 -0
- package/dist/merchant-core/learning/types.js.map +1 -0
- package/dist/merchant-core/migrations/ledgers.d.ts +40 -0
- package/dist/merchant-core/migrations/ledgers.js +824 -0
- package/dist/merchant-core/migrations/ledgers.js.map +1 -0
- package/dist/merchant-core/migrations/runner.d.ts +55 -0
- package/dist/merchant-core/migrations/runner.js +114 -0
- package/dist/merchant-core/migrations/runner.js.map +1 -0
- package/dist/merchant-core/operating/repository.d.ts +0 -1
- package/dist/merchant-core/operating/repository.js +2 -17
- package/dist/merchant-core/operating/repository.js.map +1 -1
- package/dist/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
- package/dist/merchant-core/operations-jobs/advice-runner.js +199 -0
- package/dist/merchant-core/operations-jobs/advice-runner.js.map +1 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.js +109 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.js +98 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
- package/dist/merchant-core/operations-jobs/projection.d.ts +41 -0
- package/dist/merchant-core/operations-jobs/projection.js +158 -0
- package/dist/merchant-core/operations-jobs/projection.js.map +1 -0
- package/dist/merchant-core/operations-jobs/scheduler.d.ts +68 -0
- package/dist/merchant-core/operations-jobs/scheduler.js +233 -0
- package/dist/merchant-core/operations-jobs/scheduler.js.map +1 -0
- package/dist/merchant-core/operations-jobs/service.d.ts +260 -0
- package/dist/merchant-core/operations-jobs/service.js +922 -0
- package/dist/merchant-core/operations-jobs/service.js.map +1 -0
- package/dist/merchant-core/opportunity/repository.d.ts +0 -1
- package/dist/merchant-core/opportunity/repository.js +2 -17
- package/dist/merchant-core/opportunity/repository.js.map +1 -1
- package/dist/merchant-core/ops/facade.d.ts +10 -0
- package/dist/merchant-core/ops/facade.js +52 -0
- package/dist/merchant-core/ops/facade.js.map +1 -1
- package/dist/merchant-core/ops/schema.d.ts +1 -1
- package/dist/merchant-core/ops/schema.js +119 -2
- package/dist/merchant-core/ops/schema.js.map +1 -1
- package/dist/merchant-core/ops/surface.d.ts +37 -0
- package/dist/merchant-core/ops/surface.js +240 -0
- package/dist/merchant-core/ops/surface.js.map +1 -1
- package/dist/merchant-core/orders/model.d.ts +1 -8
- package/dist/merchant-core/orders/model.js +10 -2
- package/dist/merchant-core/orders/model.js.map +1 -1
- package/dist/merchant-core/orders/repository.d.ts +0 -1
- package/dist/merchant-core/orders/repository.js +3 -18
- package/dist/merchant-core/orders/repository.js.map +1 -1
- package/dist/merchant-core/orders/service.js +34 -8
- package/dist/merchant-core/orders/service.js.map +1 -1
- package/dist/merchant-core/ownership/instance-ownership.d.ts +122 -0
- package/dist/merchant-core/ownership/instance-ownership.js +236 -0
- package/dist/merchant-core/ownership/instance-ownership.js.map +1 -0
- package/dist/merchant-core/ownership/runtime.d.ts +175 -0
- package/dist/merchant-core/ownership/runtime.js +422 -0
- package/dist/merchant-core/ownership/runtime.js.map +1 -0
- package/dist/merchant-core/proposal/engine.js +2 -0
- package/dist/merchant-core/proposal/engine.js.map +1 -1
- package/dist/merchant-core/proposal/publish.d.ts +0 -6
- package/dist/merchant-core/proposal/publish.js +37 -3
- package/dist/merchant-core/proposal/publish.js.map +1 -1
- package/dist/merchant-core/proposal/repository.d.ts +0 -7
- package/dist/merchant-core/proposal/repository.js +8 -17
- package/dist/merchant-core/proposal/repository.js.map +1 -1
- package/dist/merchant-core/proposal/types.d.ts +1 -0
- package/dist/merchant-core/proposal/types.js.map +1 -1
- package/dist/merchant-core/rfq/policy.d.ts +1 -0
- package/dist/merchant-core/rfq/policy.js +6 -7
- package/dist/merchant-core/rfq/policy.js.map +1 -1
- package/dist/merchant-core/rfq/repository.d.ts +0 -1
- package/dist/merchant-core/rfq/repository.js +2 -17
- package/dist/merchant-core/rfq/repository.js.map +1 -1
- package/dist/merchant-core/rfq/service.d.ts +2 -1
- package/dist/merchant-core/rfq/service.js +2 -4
- package/dist/merchant-core/rfq/service.js.map +1 -1
- package/dist/merchant-core/storage/transaction.d.ts +95 -7
- package/dist/merchant-core/storage/transaction.js +251 -2
- package/dist/merchant-core/storage/transaction.js.map +1 -1
- package/dist/merchant-credential-rotation.d.ts +4 -1
- package/dist/merchant-credential-rotation.js +12 -8
- package/dist/merchant-credential-rotation.js.map +1 -1
- package/dist/merchant-runtime/manager.d.ts +2 -0
- package/dist/merchant-runtime/manager.js +5 -0
- package/dist/merchant-runtime/manager.js.map +1 -1
- package/dist/negotiation/domain/objects.d.ts +2 -0
- package/dist/negotiation/domain/objects.js +3 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/ledger/store.d.ts +4 -0
- package/dist/negotiation/ledger/store.js +20 -0
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/product-init.d.ts +1 -0
- package/dist/product-init.js +4 -1
- package/dist/product-init.js.map +1 -1
- package/dist/trust/identity/message-signature.d.ts +1 -1
- package/dist/trust/identity/message-signature.js +6 -1
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/dist/trust/identity/nonce.d.ts +5 -0
- package/dist/trust/identity/nonce.js +2 -0
- package/dist/trust/identity/nonce.js.map +1 -1
- package/dist/weixin/ilink-client.d.ts +3 -2
- package/dist/weixin/ilink-client.js +9 -2
- package/dist/weixin/ilink-client.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
* 客户主体与绑定(设计 v1.1 §9.1 / §9.2 / D-M0-01 / M3-0)。
|
|
18
|
+
*
|
|
19
|
+
* - P0 只创建 organization / agent_scope 主体;person / verified_person 拒绝。
|
|
20
|
+
* - 绑定挑战由商家侧(memory:write)签发,5 分钟有效、单次消费;挑战证明
|
|
21
|
+
* 经带外渠道送达客户,由客户会话(customer:self)确认后创建新 binding_epoch。
|
|
22
|
+
* 签发者不能自我确认——同一会话既是挑战签发者又是证明消费者不构成身份证明。
|
|
23
|
+
* - 撤销绑定递增 epoch;旧主体绑定不复用。昵称/电话/IP/文本相似度不能建立身份。
|
|
24
|
+
*/
|
|
25
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
26
|
+
import { contentDigest } from "../../negotiation/jcs.js";
|
|
27
|
+
import { hasCapability } from "../context-governance/actor-context.js";
|
|
28
|
+
import { GOVERNANCE_POLICY_VERSION } from "../context-governance/types.js";
|
|
29
|
+
import { inImmediateTransaction } from "../storage/transaction.js";
|
|
30
|
+
import { CustomerMemoryError, P0_SUBJECT_KINDS, } from "./types.js";
|
|
31
|
+
const CHALLENGE_TTL_MS = 5 * 60 * 1000;
|
|
32
|
+
const BINDING_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
33
|
+
function id(value, field) {
|
|
34
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 128) {
|
|
35
|
+
throw new CustomerMemoryError("validation", `${field}_invalid`, `${field} 必须是 1..128 字符`);
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line no-control-regex
|
|
38
|
+
if (/[\u0000-\u001f\u007f]/.test(value)) {
|
|
39
|
+
throw new CustomerMemoryError("validation", `${field}_invalid`, `${field} 含控制字符`);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function requireActor(actor, merchantId, capability) {
|
|
44
|
+
if (actor.merchant_id !== merchantId) {
|
|
45
|
+
throw new CustomerMemoryError("access_denied", "actor_merchant_mismatch", "ActorContext 与商家作用域不一致");
|
|
46
|
+
}
|
|
47
|
+
if (actor.policy_version !== GOVERNANCE_POLICY_VERSION) {
|
|
48
|
+
throw new CustomerMemoryError("validation", "policy_version_mismatch", "治理策略版本不一致");
|
|
49
|
+
}
|
|
50
|
+
if (!hasCapability(actor, capability)) {
|
|
51
|
+
throw new CustomerMemoryError("access_denied", "capability_missing", `actor 缺少 ${capability}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function nowUtc(now) {
|
|
55
|
+
const ms = Date.parse(now());
|
|
56
|
+
if (!Number.isFinite(ms)) {
|
|
57
|
+
throw new CustomerMemoryError("validation", "now_invalid", "时钟输出必须是可解析的 RFC3339 时间");
|
|
58
|
+
}
|
|
59
|
+
return new Date(ms).toISOString();
|
|
60
|
+
}
|
|
61
|
+
export class CustomerIdentityService {
|
|
62
|
+
db;
|
|
63
|
+
now;
|
|
64
|
+
constructor(options) {
|
|
65
|
+
this.db = options.db;
|
|
66
|
+
this.now = options.now;
|
|
67
|
+
}
|
|
68
|
+
createSubject(input) {
|
|
69
|
+
const merchantId = id(input.merchant_id, "merchant_id");
|
|
70
|
+
requireActor(input.actor, merchantId, "memory:write");
|
|
71
|
+
if (!P0_SUBJECT_KINDS.has(input.subject_kind)) {
|
|
72
|
+
throw new CustomerMemoryError("validation", "subject_kind_rejected", `P0 只启用 organization / agent_scope(D-M0-01):${input.subject_kind}`);
|
|
73
|
+
}
|
|
74
|
+
const stamp = nowUtc(this.now);
|
|
75
|
+
const subject = {
|
|
76
|
+
subject_id: `subj_${randomUUID()}`,
|
|
77
|
+
merchant_id: merchantId,
|
|
78
|
+
subject_kind: input.subject_kind,
|
|
79
|
+
status: "ACTIVE",
|
|
80
|
+
created_at: stamp,
|
|
81
|
+
updated_at: stamp,
|
|
82
|
+
};
|
|
83
|
+
this.db
|
|
84
|
+
.prepare(`INSERT INTO customer_subjects
|
|
85
|
+
(subject_id, merchant_id, subject_kind, status, created_at, updated_at)
|
|
86
|
+
VALUES (?, ?, ?, 'ACTIVE', ?, ?)`)
|
|
87
|
+
.run(subject.subject_id, merchantId, subject.subject_kind, stamp, stamp);
|
|
88
|
+
return subject;
|
|
89
|
+
}
|
|
90
|
+
getSubject(merchantId, subjectId) {
|
|
91
|
+
const row = this.db
|
|
92
|
+
.prepare("SELECT * FROM customer_subjects WHERE merchant_id = ? AND subject_id = ?")
|
|
93
|
+
.get(id(merchantId, "merchant_id"), id(subjectId, "subject_id"));
|
|
94
|
+
return row;
|
|
95
|
+
}
|
|
96
|
+
linkChallenge(input) {
|
|
97
|
+
const merchantId = id(input.merchant_id, "merchant_id");
|
|
98
|
+
// P0-2:挑战只能由商家侧签发;证明由商家带外送达客户,客户会话不能
|
|
99
|
+
// 为任意主体自行签发挑战。
|
|
100
|
+
requireActor(input.actor, merchantId, "memory:write");
|
|
101
|
+
const sessionId = id(input.source_session_id, "source_session_id");
|
|
102
|
+
const subjectId = id(input.target_subject_id, "target_subject_id");
|
|
103
|
+
const subject = this.getSubject(merchantId, subjectId);
|
|
104
|
+
if (subject === undefined || subject.status !== "ACTIVE") {
|
|
105
|
+
throw new CustomerMemoryError("not_found", "subject_not_found", "主体不存在或不可见");
|
|
106
|
+
}
|
|
107
|
+
const scope = (input.scope ?? []).map((item) => id(item, "scope"));
|
|
108
|
+
if (scope.length > 20) {
|
|
109
|
+
throw new CustomerMemoryError("validation", "scope_too_many", "scope 最多 20 项");
|
|
110
|
+
}
|
|
111
|
+
const ttlSeconds = input.ttl_seconds ?? 300;
|
|
112
|
+
if (!Number.isSafeInteger(ttlSeconds) || ttlSeconds < 60 || ttlSeconds > 300) {
|
|
113
|
+
throw new CustomerMemoryError("validation", "ttl_invalid", "挑战 ttl 必须为 60..300 秒");
|
|
114
|
+
}
|
|
115
|
+
const stamp = nowUtc(this.now);
|
|
116
|
+
const challengeId = `chl_${randomUUID()}`;
|
|
117
|
+
const proof = randomBytes(24).toString("base64url");
|
|
118
|
+
const expiresAt = new Date(Date.parse(stamp) + Math.min(ttlSeconds * 1000, CHALLENGE_TTL_MS)).toISOString();
|
|
119
|
+
this.db
|
|
120
|
+
.prepare(`INSERT INTO binding_challenges
|
|
121
|
+
(challenge_id, merchant_id, actor_id, source_session_id, target_subject_id,
|
|
122
|
+
scope_json, proof_digest, expires_at, consumed_at, created_at, issuer_actor_id)
|
|
123
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?)`)
|
|
124
|
+
.run(challengeId, merchantId, input.actor.actor_id, sessionId, subjectId, JSON.stringify(scope), contentDigest({ purpose: "binding_challenge", proof }), expiresAt, stamp, input.actor.actor_id);
|
|
125
|
+
return { challenge_id: challengeId, proof, expires_at: expiresAt };
|
|
126
|
+
}
|
|
127
|
+
linkConfirm(input) {
|
|
128
|
+
const merchantId = id(input.merchant_id, "merchant_id");
|
|
129
|
+
requireActor(input.actor, merchantId, "customer:self");
|
|
130
|
+
const challengeId = id(input.challenge_id, "challenge_id");
|
|
131
|
+
id(input.source_session_id, "source_session_id");
|
|
132
|
+
return inImmediateTransaction(this.db, () => {
|
|
133
|
+
const row = this.db
|
|
134
|
+
.prepare("SELECT * FROM binding_challenges WHERE merchant_id = ? AND challenge_id = ?")
|
|
135
|
+
.get(merchantId, challengeId);
|
|
136
|
+
if (row === undefined ||
|
|
137
|
+
row.proof_digest !== contentDigest({ purpose: "binding_challenge", proof: input.proof })) {
|
|
138
|
+
throw new CustomerMemoryError("confirmation_invalid", "proof_mismatch", "绑定证明不匹配");
|
|
139
|
+
}
|
|
140
|
+
if (row.consumed_at !== null) {
|
|
141
|
+
throw new CustomerMemoryError("confirmation_consumed", "challenge_consumed", "挑战已消费");
|
|
142
|
+
}
|
|
143
|
+
const stamp = nowUtc(this.now);
|
|
144
|
+
if (row.expires_at <= stamp) {
|
|
145
|
+
throw new CustomerMemoryError("confirmation_expired", "challenge_expired", "挑战已过期");
|
|
146
|
+
}
|
|
147
|
+
// P0-2:签发者不能自我确认;旧版自签挑战(无签发者)一律拒绝。
|
|
148
|
+
if (row.issuer_actor_id === null || row.issuer_actor_id === input.actor.actor_id) {
|
|
149
|
+
throw new CustomerMemoryError("access_denied", "issuer_cannot_confirm", "绑定挑战必须由客户会话确认,签发者不能自我确认");
|
|
150
|
+
}
|
|
151
|
+
const subject = this.getSubject(merchantId, row.target_subject_id);
|
|
152
|
+
if (subject === undefined || subject.status !== "ACTIVE") {
|
|
153
|
+
throw new CustomerMemoryError("not_found", "subject_not_found", "主体不存在或不可见");
|
|
154
|
+
}
|
|
155
|
+
this.db
|
|
156
|
+
.prepare("UPDATE binding_challenges SET consumed_at = ? WHERE merchant_id = ? AND challenge_id = ?")
|
|
157
|
+
.run(stamp, merchantId, challengeId);
|
|
158
|
+
const epochRow = this.db
|
|
159
|
+
.prepare(`SELECT COALESCE(MAX(binding_epoch), 0) AS epoch FROM subject_bindings
|
|
160
|
+
WHERE merchant_id = ? AND actor_id = ? AND subject_id = ?`)
|
|
161
|
+
.get(merchantId, input.actor.actor_id, row.target_subject_id);
|
|
162
|
+
const binding = {
|
|
163
|
+
binding_id: `bind_${randomUUID()}`,
|
|
164
|
+
merchant_id: merchantId,
|
|
165
|
+
subject_id: row.target_subject_id,
|
|
166
|
+
actor_id: input.actor.actor_id,
|
|
167
|
+
issuer: "operator-out-of-band",
|
|
168
|
+
assurance_class: "operator_verified",
|
|
169
|
+
binding_epoch: Number(epochRow.epoch) + 1,
|
|
170
|
+
status: "ACTIVE",
|
|
171
|
+
expires_at: input.expires_at ?? new Date(Date.parse(stamp) + BINDING_TTL_MS).toISOString(),
|
|
172
|
+
created_at: stamp,
|
|
173
|
+
updated_at: stamp,
|
|
174
|
+
};
|
|
175
|
+
this.db
|
|
176
|
+
.prepare(`INSERT INTO subject_bindings
|
|
177
|
+
(binding_id, merchant_id, subject_id, actor_id, issuer, assurance_class,
|
|
178
|
+
proof_ref, binding_epoch, status, expires_at, created_at, updated_at)
|
|
179
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'ACTIVE', ?, ?, ?)`)
|
|
180
|
+
.run(binding.binding_id, binding.merchant_id, binding.subject_id, binding.actor_id, binding.issuer, binding.assurance_class, contentDigest({
|
|
181
|
+
purpose: "binding_proof",
|
|
182
|
+
challenge_id: challengeId,
|
|
183
|
+
issuer_session_id: row.source_session_id,
|
|
184
|
+
confirming_actor_id: binding.actor_id,
|
|
185
|
+
}), binding.binding_epoch, binding.expires_at, binding.created_at, binding.updated_at);
|
|
186
|
+
return binding;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
revokeBinding(input) {
|
|
190
|
+
const merchantId = id(input.merchant_id, "merchant_id");
|
|
191
|
+
if (!hasCapability(input.actor, "customer:self") &&
|
|
192
|
+
!hasCapability(input.actor, "memory:write")) {
|
|
193
|
+
throw new CustomerMemoryError("access_denied", "capability_missing", "缺少 customer:self/memory:write");
|
|
194
|
+
}
|
|
195
|
+
if (input.actor.merchant_id !== merchantId) {
|
|
196
|
+
throw new CustomerMemoryError("access_denied", "actor_merchant_mismatch", "ActorContext 与商家作用域不一致");
|
|
197
|
+
}
|
|
198
|
+
const bindingId = id(input.binding_id, "binding_id");
|
|
199
|
+
return inImmediateTransaction(this.db, () => {
|
|
200
|
+
if (!hasCapability(input.actor, "memory:write")) {
|
|
201
|
+
const ownBinding = this.db.prepare("SELECT 1 FROM subject_bindings WHERE merchant_id = ? AND binding_id = ? AND actor_id = ?").get(merchantId, bindingId, input.actor.actor_id);
|
|
202
|
+
if (ownBinding === undefined) {
|
|
203
|
+
throw new CustomerMemoryError("access_denied", "subject_not_bound", "绑定不属于当前身份");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const stamp = nowUtc(this.now);
|
|
207
|
+
const result = this.db
|
|
208
|
+
.prepare(`UPDATE subject_bindings SET status = 'REVOKED', updated_at = ?
|
|
209
|
+
WHERE merchant_id = ? AND binding_id = ? AND binding_epoch = ? AND status = 'ACTIVE'`)
|
|
210
|
+
.run(stamp, merchantId, bindingId, input.expected_epoch);
|
|
211
|
+
if (Number(result.changes) !== 1) {
|
|
212
|
+
throw new CustomerMemoryError("version_conflict", "binding_epoch_mismatch", "绑定已变化或不属于该主体");
|
|
213
|
+
}
|
|
214
|
+
return this.db
|
|
215
|
+
.prepare("SELECT * FROM subject_bindings WHERE merchant_id = ? AND binding_id = ?")
|
|
216
|
+
.get(merchantId, bindingId);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** 当前会话 actor 的有效绑定(最新 epoch);undefined = 未绑定/已撤销/过期。 */
|
|
220
|
+
currentSubjectForActor(merchantId, actorId) {
|
|
221
|
+
const row = this.db
|
|
222
|
+
.prepare(`SELECT subject_id, binding_id, binding_epoch FROM subject_bindings
|
|
223
|
+
WHERE merchant_id = ? AND actor_id = ? AND status = 'ACTIVE' AND expires_at > ?
|
|
224
|
+
ORDER BY binding_epoch DESC LIMIT 1`)
|
|
225
|
+
.get(id(merchantId, "merchant_id"), id(actorId, "actor_id"), nowUtc(this.now));
|
|
226
|
+
return row;
|
|
227
|
+
}
|
|
228
|
+
currentBindingEpoch(merchantId, actorId) {
|
|
229
|
+
return this.currentSubjectForActor(merchantId, actorId)?.binding_epoch;
|
|
230
|
+
}
|
|
231
|
+
listBindings(merchantId, actor, subjectId) {
|
|
232
|
+
merchantId = id(merchantId, "merchant_id");
|
|
233
|
+
if (!hasCapability(actor, "memory:write")) {
|
|
234
|
+
requireActor(actor, merchantId, "customer:self");
|
|
235
|
+
return this.db.prepare(`SELECT * FROM subject_bindings
|
|
236
|
+
WHERE merchant_id = ? AND actor_id = ? AND (? IS NULL OR subject_id = ?)
|
|
237
|
+
ORDER BY binding_epoch ASC`).all(merchantId, actor.actor_id, subjectId ?? null, subjectId ?? null);
|
|
238
|
+
}
|
|
239
|
+
requireActor(actor, merchantId, "memory:write");
|
|
240
|
+
return (subjectId === undefined
|
|
241
|
+
? this.db
|
|
242
|
+
.prepare("SELECT * FROM subject_bindings WHERE merchant_id = ? ORDER BY binding_epoch ASC")
|
|
243
|
+
.all(id(merchantId, "merchant_id"))
|
|
244
|
+
: this.db
|
|
245
|
+
.prepare("SELECT * FROM subject_bindings WHERE merchant_id = ? AND subject_id = ? ORDER BY binding_epoch ASC")
|
|
246
|
+
.all(id(merchantId, "merchant_id"), id(subjectId, "subject_id")));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-memory/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GAIjB,MAAM,YAAY,CAAC;AAEpB,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACvC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EA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AC1C,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CACpB;;sCAE8B,CAC/B,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,CAAgC,CAAC;QACzG,CAAC;QACD,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QAChD,OAAO,CACL,SAAS,KAAK,SAAS;YACrB,CAAC,CAAC,IAAI,CAAC,EAAE;iBACJ,OAAO,CACN,iFAAiF,CAClF;iBACA,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC,EAAE;iBACJ,OAAO,CACN,oGAAoG,CACrG;iBACA,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CACxC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
* 客户数据保留期清算调度(审查 P1-7)。
|
|
18
|
+
*
|
|
19
|
+
* `CustomerMemoryService.expireDue` 与 `DataUseGrantStore.expireDue` 只有
|
|
20
|
+
* 接入周期性 tick 才真正执行保留承诺;本模块把它们放进同一所有权栅栏内,
|
|
21
|
+
* 由持有写权的进程每小时执行一次(与 OperationsScheduler 并列)。
|
|
22
|
+
*/
|
|
23
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
24
|
+
export interface CustomerDataMaintenanceOptions {
|
|
25
|
+
readonly db: DatabaseSync;
|
|
26
|
+
readonly now: () => string;
|
|
27
|
+
/** 所有权栅栏:丢失写权时抛错,tick 只记日志不写库。 */
|
|
28
|
+
readonly write: <T>(work: () => T) => T;
|
|
29
|
+
readonly interval_ms?: number;
|
|
30
|
+
readonly merchantId?: string;
|
|
31
|
+
readonly memory?: boolean;
|
|
32
|
+
readonly learning?: boolean;
|
|
33
|
+
readonly log?: (line: string) => void;
|
|
34
|
+
}
|
|
35
|
+
export interface CustomerDataMaintenanceResult {
|
|
36
|
+
readonly memories: number;
|
|
37
|
+
readonly history: number;
|
|
38
|
+
readonly grants: number;
|
|
39
|
+
readonly learning?: {
|
|
40
|
+
evaluations: number;
|
|
41
|
+
receipts: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare class CustomerDataMaintenance {
|
|
45
|
+
private readonly options;
|
|
46
|
+
private timer;
|
|
47
|
+
constructor(options: CustomerDataMaintenanceOptions);
|
|
48
|
+
runOnce(): CustomerDataMaintenanceResult;
|
|
49
|
+
start(): void;
|
|
50
|
+
stop(): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
import { DataUseGrantStore } from "../context-governance/data-use-grant.js";
|
|
17
|
+
import { LearningRepository } from "../learning/repository.js";
|
|
18
|
+
import { QuoteHistoryStore } from "./quote-history.js";
|
|
19
|
+
import { CustomerMemoryService } from "./memory.js";
|
|
20
|
+
export class CustomerDataMaintenance {
|
|
21
|
+
options;
|
|
22
|
+
timer;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
runOnce() {
|
|
27
|
+
const memory = new CustomerMemoryService({
|
|
28
|
+
db: this.options.db,
|
|
29
|
+
now: this.options.now,
|
|
30
|
+
});
|
|
31
|
+
const grants = new DataUseGrantStore({ db: this.options.db, now: this.options.now });
|
|
32
|
+
return this.options.write(() => {
|
|
33
|
+
if (this.options.merchantId !== undefined) {
|
|
34
|
+
new QuoteHistoryStore({ db: this.options.db, now: this.options.now }).pruneForMerchant(this.options.merchantId);
|
|
35
|
+
}
|
|
36
|
+
const expired = this.options.memory === false
|
|
37
|
+
? { memories: 0, history: 0, grants: 0 }
|
|
38
|
+
: { ...memory.expireDue(), grants: grants.expireDue() };
|
|
39
|
+
return {
|
|
40
|
+
...expired,
|
|
41
|
+
...(this.options.learning === true ? {
|
|
42
|
+
learning: new LearningRepository({ db: this.options.db }).pruneEvaluationHistory(this.options.now()),
|
|
43
|
+
} : {}),
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
start() {
|
|
48
|
+
if (this.timer !== undefined)
|
|
49
|
+
return;
|
|
50
|
+
this.timer = setInterval(() => {
|
|
51
|
+
try {
|
|
52
|
+
this.runOnce();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
this.options.log?.(`[customer data maintenance] tick failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
56
|
+
}
|
|
57
|
+
}, this.options.interval_ms ?? 60 * 60 * 1000);
|
|
58
|
+
this.timer.unref?.();
|
|
59
|
+
}
|
|
60
|
+
stop() {
|
|
61
|
+
if (this.timer !== undefined) {
|
|
62
|
+
clearInterval(this.timer);
|
|
63
|
+
this.timer = undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=maintenance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintenance.js","sourceRoot":"","sources":["../../../src/merchant-core/customer-memory/maintenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAqBpD,MAAM,OAAO,uBAAuB;IACjB,OAAO,CAAiC;IACjD,KAAK,CAA6C;IAE1D,YAAY,OAAuC;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,OAAO;QACL,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC;YACvC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YACnB,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;SACtB,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACrF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE;YAC7B,IAAI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AAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CACjG,CAAC;YACJ,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IACvB,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
17
|
+
import type { ActorContext } from "../context-governance/actor-context.js";
|
|
18
|
+
import type { CustomerIdentityService } from "./identity.js";
|
|
19
|
+
import { SourceGovernanceService, type DeletionJobRecord } from "../context-governance/source-governance.js";
|
|
20
|
+
import { type CustomerMemory, type MemoryNamespace, type MemorySourceKind } from "./types.js";
|
|
21
|
+
export interface CustomerMemoryServiceOptions {
|
|
22
|
+
db: DatabaseSync;
|
|
23
|
+
now: () => string;
|
|
24
|
+
/** 来源治理(删除作业/封存/来源可用性);缺省时删除只清理本域表。 */
|
|
25
|
+
sourceGovernance?: SourceGovernanceService;
|
|
26
|
+
/**
|
|
27
|
+
* 主体绑定查询(B04):客户自助确认/纠错必须证明自己是该记忆的主体。
|
|
28
|
+
* 缺省时客户写路径 fail-closed(管理员 memory:write 不受影响)。
|
|
29
|
+
*/
|
|
30
|
+
identity?: CustomerIdentityService;
|
|
31
|
+
}
|
|
32
|
+
export declare class CustomerMemoryService {
|
|
33
|
+
private readonly db;
|
|
34
|
+
private readonly now;
|
|
35
|
+
private readonly grants;
|
|
36
|
+
private readonly sourceGovernance?;
|
|
37
|
+
private readonly identity?;
|
|
38
|
+
constructor(options: CustomerMemoryServiceOptions);
|
|
39
|
+
/**
|
|
40
|
+
* B04:客户自助写路径必须绑定到目标主体。商家管理员(memory:write 且
|
|
41
|
+
* organization/agent_scope)可跨主体管理;匿名/未绑定会话一律拒绝。
|
|
42
|
+
*/
|
|
43
|
+
private assertActorOwnsSubject;
|
|
44
|
+
private requireActiveGrant;
|
|
45
|
+
private subjectActive;
|
|
46
|
+
/** memory_set_version 递增:任何 active 集合变化都使旧快照失效。 */
|
|
47
|
+
private bumpSetVersion;
|
|
48
|
+
currentMemorySetVersion(merchantId: string, subjectId: string): number | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* 写入候选记忆:必须有 customer_memory 用途授权;value_ref 为受控引用,
|
|
51
|
+
* 不内联精确地址/手机号;来源引用只做形状校验与数量上限。
|
|
52
|
+
*/
|
|
53
|
+
proposeMemory(input: {
|
|
54
|
+
merchant_id: string;
|
|
55
|
+
actor: ActorContext;
|
|
56
|
+
subject_id: string;
|
|
57
|
+
resource_scope_id: string;
|
|
58
|
+
namespace: MemoryNamespace;
|
|
59
|
+
key: string;
|
|
60
|
+
value_ref: string;
|
|
61
|
+
value_type: string;
|
|
62
|
+
source_kind: MemorySourceKind;
|
|
63
|
+
source_refs?: readonly string[];
|
|
64
|
+
confidence?: number;
|
|
65
|
+
expires_at?: string;
|
|
66
|
+
}): CustomerMemory;
|
|
67
|
+
/** 客户确认:candidate/needs_review → active;版本递增并刷新 memory_set_version。 */
|
|
68
|
+
confirmMemory(input: {
|
|
69
|
+
merchant_id: string;
|
|
70
|
+
actor: ActorContext;
|
|
71
|
+
memory_id: string;
|
|
72
|
+
expected_version: number;
|
|
73
|
+
}): CustomerMemory;
|
|
74
|
+
/** 纠错:新版本 active 并 supersede 旧版本;旧快照因 set version 失效。 */
|
|
75
|
+
correctMemory(input: {
|
|
76
|
+
merchant_id: string;
|
|
77
|
+
actor: ActorContext;
|
|
78
|
+
memory_id: string;
|
|
79
|
+
expected_version: number;
|
|
80
|
+
value_ref: string;
|
|
81
|
+
source_refs?: readonly string[];
|
|
82
|
+
}): CustomerMemory;
|
|
83
|
+
/**
|
|
84
|
+
* 删除:先登记 DeletionJob/封存 scope/撤权(source governance),再清理
|
|
85
|
+
* 记忆与历史索引;备份面保持 pending(backup_pending)。
|
|
86
|
+
*/
|
|
87
|
+
requestDeletion(input: {
|
|
88
|
+
merchant_id: string;
|
|
89
|
+
actor: ActorContext;
|
|
90
|
+
erase_scope_id: string;
|
|
91
|
+
requested_by: string;
|
|
92
|
+
reason: string;
|
|
93
|
+
}): DeletionJobRecord | undefined;
|
|
94
|
+
/** 到期/超过 purge_at 的记忆失效;历史索引超期删除。 */
|
|
95
|
+
expireDue(): {
|
|
96
|
+
memories: number;
|
|
97
|
+
history: number;
|
|
98
|
+
};
|
|
99
|
+
getMemory(merchantId: string, memoryId: string): CustomerMemory | undefined;
|
|
100
|
+
/** 当前主体有效记忆的最小字段(客户自助;不返回其他主体)。 */
|
|
101
|
+
listMine(merchantId: string, subjectId: string): Array<{
|
|
102
|
+
memory_id: string;
|
|
103
|
+
namespace: MemoryNamespace;
|
|
104
|
+
key: string;
|
|
105
|
+
value_ref: string;
|
|
106
|
+
value_type: string;
|
|
107
|
+
confirmed_at: string | null;
|
|
108
|
+
expires_at: string;
|
|
109
|
+
version: number;
|
|
110
|
+
}>;
|
|
111
|
+
/** 当前主体 active 记忆(接待 recall 工具用;最小字段)。 */
|
|
112
|
+
listActiveForRecall(merchantId: string, subjectId: string): CustomerMemory[];
|
|
113
|
+
private assertWithinRetention;
|
|
114
|
+
private requireMemory;
|
|
115
|
+
private insertMemory;
|
|
116
|
+
private updateMemory;
|
|
117
|
+
private insertEvidence;
|
|
118
|
+
private appendEvent;
|
|
119
|
+
}
|