@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,137 @@
|
|
|
1
|
+
import { type Basis } from "./requirements.js";
|
|
2
|
+
import { type Observation } from "./source-observation.js";
|
|
3
|
+
export declare function compareQuotes(basis: Basis, observations: Observation[]): {
|
|
4
|
+
rows: ({
|
|
5
|
+
cash_total_minor: number | null;
|
|
6
|
+
conditional_amount_minor: number | null;
|
|
7
|
+
known_amount_minor: number | null;
|
|
8
|
+
missing: string[];
|
|
9
|
+
group: string;
|
|
10
|
+
questions: {
|
|
11
|
+
source_id: string;
|
|
12
|
+
offer_digest: string;
|
|
13
|
+
field: string;
|
|
14
|
+
}[];
|
|
15
|
+
budget: string;
|
|
16
|
+
budget_excess_minor: number | undefined;
|
|
17
|
+
conflicts: string[];
|
|
18
|
+
source_id: string;
|
|
19
|
+
supplier: string;
|
|
20
|
+
supplier_ref: string | undefined;
|
|
21
|
+
channel: "kiwi" | "ecommerce";
|
|
22
|
+
variant: string;
|
|
23
|
+
price_kind: import("./source-observation.js").PriceKind;
|
|
24
|
+
offer_digest: string;
|
|
25
|
+
evidence: import("./source-observation.js").Evidence;
|
|
26
|
+
field_evidence: {
|
|
27
|
+
price: {
|
|
28
|
+
source_ref: string;
|
|
29
|
+
field: string;
|
|
30
|
+
observed_at: string;
|
|
31
|
+
version: string;
|
|
32
|
+
};
|
|
33
|
+
match: {
|
|
34
|
+
source_ref: string;
|
|
35
|
+
field: string;
|
|
36
|
+
observed_at: string;
|
|
37
|
+
version: string;
|
|
38
|
+
};
|
|
39
|
+
delivery: {
|
|
40
|
+
source_ref: string;
|
|
41
|
+
field: string;
|
|
42
|
+
observed_at: string;
|
|
43
|
+
version: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
matching: string;
|
|
47
|
+
requirements: {
|
|
48
|
+
id: string;
|
|
49
|
+
requested: import("./requirements.js").RequirementValue;
|
|
50
|
+
hardness: "hard" | "soft";
|
|
51
|
+
transmitted: "UNKNOWN" | "NOT_SENT" | "PREPARED" | "RECEIPTED";
|
|
52
|
+
confirmed: string;
|
|
53
|
+
value: unknown;
|
|
54
|
+
evidence: {
|
|
55
|
+
source_ref: string;
|
|
56
|
+
field: string;
|
|
57
|
+
observed_at: string;
|
|
58
|
+
version: string;
|
|
59
|
+
} | undefined;
|
|
60
|
+
}[];
|
|
61
|
+
} | {
|
|
62
|
+
cash_total_minor: number | null;
|
|
63
|
+
conditional_amount_minor: number | null;
|
|
64
|
+
known_amount_minor: number | null;
|
|
65
|
+
missing: string[];
|
|
66
|
+
group: string;
|
|
67
|
+
questions: {
|
|
68
|
+
source_id: string;
|
|
69
|
+
offer_digest: string;
|
|
70
|
+
field: string;
|
|
71
|
+
}[];
|
|
72
|
+
budget: string;
|
|
73
|
+
budget_excess_minor: number | undefined;
|
|
74
|
+
scenario?: {
|
|
75
|
+
quantity: number;
|
|
76
|
+
extra: number;
|
|
77
|
+
cash_total_minor: number | null;
|
|
78
|
+
} | undefined;
|
|
79
|
+
stated_total_minor: number | null;
|
|
80
|
+
deposit_minor: number | undefined;
|
|
81
|
+
conflicts: string[];
|
|
82
|
+
source_id: string;
|
|
83
|
+
supplier: string;
|
|
84
|
+
supplier_ref: string | undefined;
|
|
85
|
+
channel: "kiwi" | "ecommerce";
|
|
86
|
+
variant: string;
|
|
87
|
+
price_kind: import("./source-observation.js").PriceKind;
|
|
88
|
+
offer_digest: string;
|
|
89
|
+
evidence: import("./source-observation.js").Evidence;
|
|
90
|
+
field_evidence: {
|
|
91
|
+
price: {
|
|
92
|
+
source_ref: string;
|
|
93
|
+
field: string;
|
|
94
|
+
observed_at: string;
|
|
95
|
+
version: string;
|
|
96
|
+
};
|
|
97
|
+
match: {
|
|
98
|
+
source_ref: string;
|
|
99
|
+
field: string;
|
|
100
|
+
observed_at: string;
|
|
101
|
+
version: string;
|
|
102
|
+
};
|
|
103
|
+
delivery: {
|
|
104
|
+
source_ref: string;
|
|
105
|
+
field: string;
|
|
106
|
+
observed_at: string;
|
|
107
|
+
version: string;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
matching: string;
|
|
111
|
+
requirements: {
|
|
112
|
+
id: string;
|
|
113
|
+
requested: import("./requirements.js").RequirementValue;
|
|
114
|
+
hardness: "hard" | "soft";
|
|
115
|
+
transmitted: "UNKNOWN" | "NOT_SENT" | "PREPARED" | "RECEIPTED";
|
|
116
|
+
confirmed: string;
|
|
117
|
+
value: unknown;
|
|
118
|
+
evidence: {
|
|
119
|
+
source_ref: string;
|
|
120
|
+
field: string;
|
|
121
|
+
observed_at: string;
|
|
122
|
+
version: string;
|
|
123
|
+
} | undefined;
|
|
124
|
+
}[];
|
|
125
|
+
})[];
|
|
126
|
+
requirements: string[];
|
|
127
|
+
independent_suppliers_confirmed: number;
|
|
128
|
+
supplier_identity_unknown: boolean;
|
|
129
|
+
coverage_insufficient: boolean;
|
|
130
|
+
recommendation: string | null;
|
|
131
|
+
eligible: string[];
|
|
132
|
+
questions: {
|
|
133
|
+
source_id: string;
|
|
134
|
+
offer_digest: string;
|
|
135
|
+
field: string;
|
|
136
|
+
}[];
|
|
137
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { normalizeCosts } from "./quote-normalizer.js";
|
|
2
|
+
import { asRecord, conditionMatches, isProjectable, validTimestamp } from "./requirements.js";
|
|
3
|
+
import { missingBasis } from "./source-observation.js";
|
|
4
|
+
const productKinds = new Set(["specification", "condition", "packaging"]);
|
|
5
|
+
function evaluate(basis, observation) {
|
|
6
|
+
const { source, evidence, product, response } = observation;
|
|
7
|
+
const nativeResponse = response?.schema_version === 1 && response.request_projection_digest === observation.projection_digest && observation.projection_digest
|
|
8
|
+
? response : undefined;
|
|
9
|
+
const responses = Array.isArray(nativeResponse?.requirements) ? nativeResponse.requirements.map(asRecord) : [];
|
|
10
|
+
const evidenceRef = (field) => ({ source_ref: evidence.reference, field, observed_at: evidence.captured_at, version: observation.digest });
|
|
11
|
+
const requirements = basis.requirements.map(requirement => {
|
|
12
|
+
const answers = responses.filter(answer => answer.requirement_id === requirement.id);
|
|
13
|
+
const answer = answers.length === 1 ? answers[0] : undefined;
|
|
14
|
+
const commercialValue = nativeResponse ? ((answer?.status === "confirmed" || answer?.status === "deviation") && typeof answer.source_version === "string" ? answer.value : undefined) :
|
|
15
|
+
observation.verified && source.channel === "ecommerce" ? product?.values?.[requirement.id] : undefined;
|
|
16
|
+
const actual = productKinds.has(requirement.kind) ? commercialValue ?? product?.values?.[requirement.id] : commercialValue;
|
|
17
|
+
const confirmed = answers.length > 1 ? "CONFLICT" : actual === undefined ? "UNKNOWN" :
|
|
18
|
+
conditionMatches(requirement, actual) ? "MET" : "NOT_MET";
|
|
19
|
+
return { id: requirement.id, requested: requirement.value, hardness: requirement.hardness,
|
|
20
|
+
transmitted: isProjectable(requirement) && observation.projection_digest ? observation.transmission : "NOT_SENT",
|
|
21
|
+
confirmed, value: actual, evidence: actual !== undefined ? evidenceRef(requirement.id) : undefined };
|
|
22
|
+
});
|
|
23
|
+
const hardProduct = requirements.filter(result => result.hardness === "hard" && basis.requirements.some(r => r.id === result.id && productKinds.has(r.kind)));
|
|
24
|
+
const modelSame = !!basis.model && product?.model?.trim().toUpperCase() === basis.model.trim().toUpperCase();
|
|
25
|
+
const modelConflict = !!basis.model && !!product?.model && !modelSame;
|
|
26
|
+
const matching = hardProduct.some(result => result.confirmed === "NOT_MET") || (basis.selection_mode === "exact_item" && modelConflict) ? "ALTERNATIVE" :
|
|
27
|
+
hardProduct.some(result => result.confirmed !== "MET") ? "UNVERIFIED" :
|
|
28
|
+
modelSame ? "SAME_ITEM" :
|
|
29
|
+
basis.selection_mode === "spec_based" && hardProduct.length ? "MEETS_SPEC" : "UNVERIFIED";
|
|
30
|
+
const costs = normalizeCosts(observation.costs, basis.quantity, basis.unit, observation.native_item);
|
|
31
|
+
const budget = basis.budget;
|
|
32
|
+
const cap = budget ? BigInt(budget.amount_minor) * BigInt(budget.scope === "unit" ? basis.quantity ?? 0 : 1) : undefined;
|
|
33
|
+
const pageOrImport = observation.price_kind === "PAGE_REFERENCE" || observation.price_kind === "IMPORTED_REFERENCE";
|
|
34
|
+
const cash = pageOrImport ? null : costs.cash_total_minor;
|
|
35
|
+
const hypothetical = pageOrImport ? costs.cash_total_minor ?? costs.known_amount_minor : null;
|
|
36
|
+
const budgetStatus = !budget ? "not_provided" : cash === null || (budget.scope === "unit" && basis.quantity === undefined) ? "unknown" :
|
|
37
|
+
BigInt(cash) > cap ? "exceeds" : "within";
|
|
38
|
+
const arrival = nativeResponse?.arrives_by ?? product?.arrived_by;
|
|
39
|
+
const nativeDelivery = asRecord(observation.native_fulfillment).delivery_before;
|
|
40
|
+
const destination = nativeResponse?.destination ?? product?.destination;
|
|
41
|
+
const confirmedQuantity = nativeResponse?.available_quantity ?? product?.stock_quantity;
|
|
42
|
+
const missing = [...costs.missing, ...costs.conflicts,
|
|
43
|
+
...requirements.filter(r => r.confirmed !== "MET" && r.hardness === "hard").map(r => `requirement:${r.id}:${r.confirmed}`)];
|
|
44
|
+
if (basis.delivery_before && (!validTimestamp(arrival) || Date.parse(arrival) > Date.parse(basis.delivery_before)))
|
|
45
|
+
missing.push("arrival_deadline");
|
|
46
|
+
if (nativeResponse && validTimestamp(arrival) && validTimestamp(nativeDelivery) &&
|
|
47
|
+
Date.parse(arrival) !== Date.parse(nativeDelivery))
|
|
48
|
+
missing.push("delivery_terms_conflict");
|
|
49
|
+
if (basis.destination && destination !== basis.destination)
|
|
50
|
+
missing.push("delivery_destination");
|
|
51
|
+
if (basis.quantity !== undefined && !(typeof confirmedQuantity === "number" && Number.isSafeInteger(confirmedQuantity) &&
|
|
52
|
+
confirmedQuantity >= basis.quantity))
|
|
53
|
+
missing.push("available_quantity");
|
|
54
|
+
if (response && Object.keys(response).length && !nativeResponse)
|
|
55
|
+
missing.push("projection_digest_mismatch");
|
|
56
|
+
if (matching === "UNVERIFIED" || matching === "ALTERNATIVE")
|
|
57
|
+
missing.push("item_matching");
|
|
58
|
+
if (observation.expired)
|
|
59
|
+
missing.push("freshness");
|
|
60
|
+
if (basis.budget?.hardness === "hard" && budgetStatus !== "within")
|
|
61
|
+
missing.push("hard_budget");
|
|
62
|
+
const formal = observation.verified && (observation.price_kind === "KNP_OFFER" ? observation.native_current === true : validTimestamp(evidence.valid_until));
|
|
63
|
+
if (observation.verified && !formal)
|
|
64
|
+
missing.push("formal_valid_until");
|
|
65
|
+
const group = formal
|
|
66
|
+
? (missing.length === 0 && cash !== null && !observation.expired ? "CONFIRMED" : "INCOMPLETE")
|
|
67
|
+
: "REFERENCE";
|
|
68
|
+
const questions = [...new Set(missing.filter(field => field !== "hard_budget"))].map(field => ({
|
|
69
|
+
source_id: source.id, offer_digest: observation.digest, field,
|
|
70
|
+
}));
|
|
71
|
+
return { source_id: source.id, supplier: source.name, supplier_ref: product?.supplier_ref, channel: source.channel,
|
|
72
|
+
variant: source.variant, price_kind: observation.price_kind, offer_digest: observation.digest,
|
|
73
|
+
evidence, field_evidence: { price: evidenceRef("costs"), match: evidenceRef("product"), delivery: evidenceRef("delivery") },
|
|
74
|
+
matching, requirements, ...costs, cash_total_minor: cash, conditional_amount_minor: hypothetical,
|
|
75
|
+
known_amount_minor: pageOrImport ? null : costs.known_amount_minor, missing, group, questions, budget: budgetStatus,
|
|
76
|
+
budget_excess_minor: budgetStatus === "exceeds" ? Number(BigInt(cash) - cap) : undefined };
|
|
77
|
+
}
|
|
78
|
+
export function compareQuotes(basis, observations) {
|
|
79
|
+
const mapped = new Map();
|
|
80
|
+
for (const observation of observations) {
|
|
81
|
+
const { supplier_ref: supplier, verified_kiwi_merchant_id: merchant } = observation.product ?? {};
|
|
82
|
+
if (observation.price_kind !== "SUPPLIER_QUOTE" || !observation.verified || !supplier || !merchant)
|
|
83
|
+
continue;
|
|
84
|
+
const suppliers = mapped.get(merchant) ?? new Set();
|
|
85
|
+
suppliers.add(supplier);
|
|
86
|
+
mapped.set(merchant, suppliers);
|
|
87
|
+
}
|
|
88
|
+
const rows = observations.map(observation => {
|
|
89
|
+
const merchant = observation.source.merchant_id;
|
|
90
|
+
const identities = merchant ? mapped.get(merchant) : undefined;
|
|
91
|
+
const supplier = identities?.size === 1 ? [...identities][0] : undefined;
|
|
92
|
+
return evaluate(basis, supplier ? { ...observation, product: { ...observation.product, supplier_ref: supplier } } : observation);
|
|
93
|
+
});
|
|
94
|
+
const eligible = rows.filter(row => row.group === "CONFIRMED")
|
|
95
|
+
.sort((a, b) => a.cash_total_minor - b.cash_total_minor || a.source_id.localeCompare(b.source_id));
|
|
96
|
+
const distinct = new Set(eligible.map(row => row.supplier_ref).filter(Boolean)).size;
|
|
97
|
+
const requirements = missingBasis(basis);
|
|
98
|
+
const coverageInsufficient = basis.minimum_suppliers !== undefined && distinct < basis.minimum_suppliers;
|
|
99
|
+
return { rows, requirements, independent_suppliers_confirmed: distinct,
|
|
100
|
+
supplier_identity_unknown: rows.some(row => !row.supplier_ref),
|
|
101
|
+
coverage_insufficient: coverageInsufficient,
|
|
102
|
+
recommendation: !requirements.length && !coverageInsufficient ? eligible[0]?.source_id ?? null : null,
|
|
103
|
+
eligible: eligible.map(row => row.source_id),
|
|
104
|
+
questions: rows.flatMap(row => row.questions) };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=quote-comparison.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote-comparison.js","sourceRoot":"","sources":["../../../src/buyer-core/procurement/quote-comparison.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAc,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAoB,MAAM,yBAAyB,CAAC;AAEzE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;AAE1E,SAAS,QAAQ,CAAC,KAAY,EAAE,WAAwB;IACtD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;IAC5D,MAAM,cAAc,GAAG,Q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YAAY,CAAC;QAC9D,qBAAqB,EAAE,oBAAoB;QAC3C,cAAc,EAAE,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI;QACrG,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;QAC5C,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface QuoteCosts {
|
|
2
|
+
currency: "CNY";
|
|
3
|
+
mode: "components" | "direct_total";
|
|
4
|
+
complete: boolean;
|
|
5
|
+
quantity: number;
|
|
6
|
+
unit: string;
|
|
7
|
+
goods?: CostLine;
|
|
8
|
+
charges?: CostLine[];
|
|
9
|
+
total_minor?: number;
|
|
10
|
+
native_basis?: "net" | "gross";
|
|
11
|
+
deposit_minor?: number;
|
|
12
|
+
pack_multiple?: number;
|
|
13
|
+
min_quantity?: number;
|
|
14
|
+
max_quantity?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface CostLine {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: "goods" | "freight" | "fee" | "discount";
|
|
19
|
+
scope: "per_unit" | "order";
|
|
20
|
+
included?: boolean;
|
|
21
|
+
eligible?: boolean;
|
|
22
|
+
amount_minor: number;
|
|
23
|
+
tax: "gross" | "net" | "unknown";
|
|
24
|
+
tax_minor?: number;
|
|
25
|
+
tax_bps?: number;
|
|
26
|
+
rounding?: "half_up";
|
|
27
|
+
}
|
|
28
|
+
export declare function normalizeCosts(raw: unknown, quantity?: number, unit?: string, nativeItem?: unknown): {
|
|
29
|
+
known_amount_minor: null;
|
|
30
|
+
cash_total_minor: null;
|
|
31
|
+
missing: string[];
|
|
32
|
+
conflicts: string[];
|
|
33
|
+
} | {
|
|
34
|
+
scenario?: {
|
|
35
|
+
quantity: number;
|
|
36
|
+
extra: number;
|
|
37
|
+
cash_total_minor: number | null;
|
|
38
|
+
} | undefined;
|
|
39
|
+
known_amount_minor: number | null;
|
|
40
|
+
cash_total_minor: number | null;
|
|
41
|
+
stated_total_minor: number | null;
|
|
42
|
+
deposit_minor: number | undefined;
|
|
43
|
+
missing: string[];
|
|
44
|
+
conflicts: string[];
|
|
45
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { asRecord } from "./requirements.js";
|
|
2
|
+
function safe(value) {
|
|
3
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
4
|
+
}
|
|
5
|
+
function amount(value) {
|
|
6
|
+
if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER))
|
|
7
|
+
throw new RangeError("AMOUNT_OUT_OF_RANGE");
|
|
8
|
+
return Number(value);
|
|
9
|
+
}
|
|
10
|
+
function gross(line, quantity) {
|
|
11
|
+
if (!safe(line.amount_minor) || !["order", "per_unit"].includes(line.scope))
|
|
12
|
+
throw new RangeError("INVALID_AMOUNT");
|
|
13
|
+
const base = BigInt(line.amount_minor) * BigInt(line.scope === "per_unit" ? quantity : 1);
|
|
14
|
+
if (line.tax === "gross")
|
|
15
|
+
return base;
|
|
16
|
+
if (line.tax !== "net")
|
|
17
|
+
return undefined;
|
|
18
|
+
if (line.tax_minor !== undefined) {
|
|
19
|
+
if (!safe(line.tax_minor))
|
|
20
|
+
throw new RangeError("INVALID_TAX_AMOUNT");
|
|
21
|
+
return base + BigInt(line.tax_minor);
|
|
22
|
+
}
|
|
23
|
+
if (line.tax_bps === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
if (!safe(line.tax_bps) || line.tax_bps > 10000)
|
|
26
|
+
throw new RangeError("INVALID_TAX_RATE");
|
|
27
|
+
const tax = base * BigInt(line.tax_bps);
|
|
28
|
+
if (tax % 10000n !== 0n && line.rounding !== "half_up")
|
|
29
|
+
return undefined;
|
|
30
|
+
return base + (tax + (line.rounding === "half_up" ? 5000n : 0n)) / 10000n;
|
|
31
|
+
}
|
|
32
|
+
export function normalizeCosts(raw, quantity, unit, nativeItem) {
|
|
33
|
+
const input = asRecord(raw);
|
|
34
|
+
const missing = [];
|
|
35
|
+
const conflicts = [];
|
|
36
|
+
let known = null;
|
|
37
|
+
let total = null;
|
|
38
|
+
let scenario;
|
|
39
|
+
const declared = safe(input.total_minor) ? input.total_minor : null;
|
|
40
|
+
try {
|
|
41
|
+
if (input.currency !== "CNY" || (input.mode !== "direct_total" && input.mode !== "components")) {
|
|
42
|
+
return { known_amount_minor: known, cash_total_minor: total, missing: ["costs"], conflicts };
|
|
43
|
+
}
|
|
44
|
+
for (const value of [input.total_minor, input.deposit_minor, input.min_quantity, input.max_quantity, input.pack_multiple]) {
|
|
45
|
+
if (value !== undefined && !safe(value))
|
|
46
|
+
throw new RangeError("INVALID_AMOUNT");
|
|
47
|
+
}
|
|
48
|
+
if (quantity === undefined || unit === undefined || input.unit !== unit ||
|
|
49
|
+
!safe(input.quantity) || input.quantity === 0)
|
|
50
|
+
missing.push("quantity_unit");
|
|
51
|
+
const priced = input.quantity;
|
|
52
|
+
if (priced === undefined || !safe(priced) || priced === 0) {
|
|
53
|
+
return { known_amount_minor: known, cash_total_minor: total, missing, conflicts };
|
|
54
|
+
}
|
|
55
|
+
if (quantity !== priced || (input.min_quantity ?? 0) > priced || (input.max_quantity ?? Infinity) < priced)
|
|
56
|
+
missing.push("quantity_applicability");
|
|
57
|
+
if (input.complete !== true)
|
|
58
|
+
missing.push("all_required_fees");
|
|
59
|
+
if ((input.deposit_minor ?? 0) > 0)
|
|
60
|
+
missing.push("refundable_deposit_terms");
|
|
61
|
+
if (input.pack_multiple === 0)
|
|
62
|
+
throw new RangeError("INVALID_PACK_MULTIPLE");
|
|
63
|
+
if (input.pack_multiple && quantity !== undefined && quantity % input.pack_multiple !== 0) {
|
|
64
|
+
const packed = amount(((BigInt(quantity) + BigInt(input.pack_multiple) - 1n) / BigInt(input.pack_multiple)) * BigInt(input.pack_multiple));
|
|
65
|
+
missing.push("pack_multiple");
|
|
66
|
+
scenario = { quantity: packed, extra: packed - quantity, cash_total_minor: null };
|
|
67
|
+
}
|
|
68
|
+
const item = asRecord(nativeItem);
|
|
69
|
+
if (nativeItem !== undefined) {
|
|
70
|
+
const nativePrice = asRecord(item.unit_price);
|
|
71
|
+
const nativeQuantity = asRecord(item.quantity);
|
|
72
|
+
const goods = input.goods;
|
|
73
|
+
if (priced !== nativeQuantity.value || input.unit !== nativeQuantity.unit || nativePrice.currency !== "CNY")
|
|
74
|
+
conflicts.push("native_quantity_or_currency");
|
|
75
|
+
if (input.mode === "components") {
|
|
76
|
+
if (!goods || !safe(nativePrice.amount_minor) || (input.native_basis !== "net" && input.native_basis !== "gross")) {
|
|
77
|
+
missing.push("native_goods_basis");
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const native = BigInt(nativePrice.amount_minor) * BigInt(priced);
|
|
81
|
+
const stated = input.native_basis === "gross" ? gross(goods, priced) :
|
|
82
|
+
goods.tax === "net" && safe(goods.amount_minor) ? BigInt(goods.amount_minor) * BigInt(goods.scope === "per_unit" ? priced : 1) : undefined;
|
|
83
|
+
if (stated !== native)
|
|
84
|
+
conflicts.push("native_goods_amount");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (input.mode === "direct_total") {
|
|
89
|
+
if (declared === null)
|
|
90
|
+
missing.push("declared_total");
|
|
91
|
+
if (input.goods !== undefined || input.charges?.length)
|
|
92
|
+
conflicts.push("mixed_cost_modes");
|
|
93
|
+
if (!missing.includes("quantity_applicability"))
|
|
94
|
+
known = declared;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (!input.goods)
|
|
98
|
+
missing.push("goods");
|
|
99
|
+
const lines = [...(input.goods ? [input.goods] : []), ...(input.charges ?? [])];
|
|
100
|
+
const ids = new Set();
|
|
101
|
+
let sum = 0n;
|
|
102
|
+
let knownLines = 0;
|
|
103
|
+
let scenarioSum = 0n;
|
|
104
|
+
for (const line of lines) {
|
|
105
|
+
if (!line.id || ids.has(line.id))
|
|
106
|
+
throw new RangeError("DUPLICATE_FEE");
|
|
107
|
+
ids.add(line.id);
|
|
108
|
+
const isGoods = line === input.goods;
|
|
109
|
+
if (isGoods ? line.kind !== "goods" || line.included === true : !["freight", "fee", "discount"].includes(line.kind))
|
|
110
|
+
throw new RangeError("INVALID_FEE_KIND");
|
|
111
|
+
if (!isGoods && line.included === undefined) {
|
|
112
|
+
missing.push(`inclusion:${line.id}`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!safe(line.amount_minor))
|
|
116
|
+
throw new RangeError("INVALID_AMOUNT");
|
|
117
|
+
if (line.included === true)
|
|
118
|
+
continue;
|
|
119
|
+
if (line.kind === "discount" && line.eligible !== true) {
|
|
120
|
+
if (line.eligible === undefined)
|
|
121
|
+
missing.push(`eligibility:${line.id}`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const charge = gross(line, priced);
|
|
125
|
+
if (charge === undefined) {
|
|
126
|
+
missing.push(`tax_or_amount:${line.id}`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const sign = line.kind === "discount" ? -1n : 1n;
|
|
130
|
+
sum += sign * charge;
|
|
131
|
+
knownLines++;
|
|
132
|
+
if (scenario !== undefined && line.scope === "per_unit")
|
|
133
|
+
scenarioSum += sign * (gross(line, scenario.quantity) ?? 0n);
|
|
134
|
+
}
|
|
135
|
+
if (knownLines && !missing.includes("quantity_applicability"))
|
|
136
|
+
known = amount(sum);
|
|
137
|
+
if (scenario && knownLines && lines.every(line => line.scope === "per_unit" && line.kind !== "discount") &&
|
|
138
|
+
input.complete === true && missing.every(reason => reason === "pack_multiple") &&
|
|
139
|
+
scenario.quantity <= (input.max_quantity ?? Infinity))
|
|
140
|
+
scenario.cash_total_minor = amount(scenarioSum);
|
|
141
|
+
if (declared !== null && !missing.length && BigInt(declared) !== sum)
|
|
142
|
+
conflicts.push("declared_total_disagrees");
|
|
143
|
+
}
|
|
144
|
+
if (!missing.length && !conflicts.length)
|
|
145
|
+
total = known;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
conflicts.push(error instanceof RangeError ? error.message : "INVALID_COSTS");
|
|
149
|
+
}
|
|
150
|
+
return { known_amount_minor: known, cash_total_minor: total, stated_total_minor: declared, deposit_minor: input.deposit_minor,
|
|
151
|
+
missing, conflicts, ...(scenario === undefined ? {} : { scenario }) };
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=quote-normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quote-normalizer.js","sourceRoot":"","sources":["../../../src/buyer-core/procurement/quote-normalizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA8B7C,SAAS,IAAI,CAAC,KAAc;IAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC3B,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACvG,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,KAAK,CAAC,IAAc,EAAE,QAAgB;IAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC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B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa;QAC3H,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const requirementKinds: readonly ["invoice", "payment", "delivery", "warranty", "specification", "condition", "packaging", "after_sales"];
|
|
2
|
+
export type RequirementKind = (typeof requirementKinds)[number];
|
|
3
|
+
export type RequirementValue = string | number | boolean;
|
|
4
|
+
export interface Requirement {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: RequirementKind;
|
|
7
|
+
hardness: "hard" | "soft";
|
|
8
|
+
value: RequirementValue;
|
|
9
|
+
comparison?: "eq" | "min" | "max";
|
|
10
|
+
source: string;
|
|
11
|
+
disclose: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface Basis {
|
|
14
|
+
buyer_item_key: string;
|
|
15
|
+
description: string;
|
|
16
|
+
selection_mode: "exact_item" | "spec_based";
|
|
17
|
+
model?: string;
|
|
18
|
+
quantity?: number;
|
|
19
|
+
unit?: string;
|
|
20
|
+
destination?: string;
|
|
21
|
+
delivery_before?: string;
|
|
22
|
+
requirements: Requirement[];
|
|
23
|
+
budget?: {
|
|
24
|
+
amount_minor: number;
|
|
25
|
+
hardness: "hard" | "soft";
|
|
26
|
+
scope: "total" | "unit";
|
|
27
|
+
};
|
|
28
|
+
channels?: ("kiwi" | "ecommerce")[];
|
|
29
|
+
minimum_suppliers?: number;
|
|
30
|
+
company?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const REQUIREMENTS_KEY = "kiwi_procurement_requirements_v1";
|
|
33
|
+
export declare const RESPONSE_KEY = "kiwi_procurement_response_v1";
|
|
34
|
+
export declare const COSTS_KEY = "kiwi_quote_costs_v1";
|
|
35
|
+
export declare function basisDigest(basis: Basis): string;
|
|
36
|
+
export declare function projectRequirements(basis: Basis): {
|
|
37
|
+
projection_digest: string;
|
|
38
|
+
schema_version: number;
|
|
39
|
+
requirements: {
|
|
40
|
+
comparison?: "eq" | "min" | "max" | undefined;
|
|
41
|
+
id: string;
|
|
42
|
+
kind: "invoice" | "payment" | "delivery" | "warranty" | "specification" | "condition" | "packaging" | "after_sales";
|
|
43
|
+
strength: "hard" | "soft";
|
|
44
|
+
requested: RequirementValue;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
export declare function isProjectable(requirement: Requirement): boolean;
|
|
48
|
+
export declare function validTimestamp(value: unknown): value is string;
|
|
49
|
+
export declare function conditionMatches(requirement: Requirement, actual: unknown): boolean;
|
|
50
|
+
export declare function asRecord(value: unknown): Record<string, unknown>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { contentDigest } from "../../negotiation/jcs.js";
|
|
2
|
+
export const requirementKinds = ["invoice", "payment", "delivery", "warranty", "specification", "condition", "packaging", "after_sales"];
|
|
3
|
+
export const REQUIREMENTS_KEY = "kiwi_procurement_requirements_v1";
|
|
4
|
+
export const RESPONSE_KEY = "kiwi_procurement_response_v1";
|
|
5
|
+
export const COSTS_KEY = "kiwi_quote_costs_v1";
|
|
6
|
+
export function basisDigest(basis) {
|
|
7
|
+
const { budget: _budget, company: _company, channels: _channels, minimum_suppliers: _minimum, ...commercial } = basis;
|
|
8
|
+
return contentDigest({ ...commercial, requirements: commercial.requirements.map(({ source: _source, ...requirement }) => requirement).sort((a, b) => a.id.localeCompare(b.id)) });
|
|
9
|
+
}
|
|
10
|
+
export function projectRequirements(basis) {
|
|
11
|
+
const requirements = basis.requirements.filter(isProjectable)
|
|
12
|
+
.map(({ id, kind, hardness, value, comparison }) => ({ id, kind, strength: hardness, requested: value, ...(comparison ? { comparison } : {}) }))
|
|
13
|
+
.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
14
|
+
const body = { schema_version: 1, requirements };
|
|
15
|
+
return { ...body, projection_digest: contentDigest(body) };
|
|
16
|
+
}
|
|
17
|
+
export function isProjectable(requirement) {
|
|
18
|
+
return requirement.disclose && ["invoice", "payment", "delivery", "warranty", "specification"].includes(requirement.kind);
|
|
19
|
+
}
|
|
20
|
+
export function validTimestamp(value) {
|
|
21
|
+
return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(value)
|
|
22
|
+
&& Number.isFinite(Date.parse(value)) && Number.isFinite(Date.parse(value.slice(0, 10)))
|
|
23
|
+
&& new Date(value.slice(0, 10)).toISOString().slice(0, 10) === value.slice(0, 10);
|
|
24
|
+
}
|
|
25
|
+
export function conditionMatches(requirement, actual) {
|
|
26
|
+
if (requirement.comparison === "eq")
|
|
27
|
+
return actual === requirement.value;
|
|
28
|
+
if ((requirement.comparison === "min" || requirement.comparison === "max") && typeof requirement.value === "number") {
|
|
29
|
+
return typeof actual === "number" && Number.isSafeInteger(actual) &&
|
|
30
|
+
(requirement.comparison === "min" ? actual >= requirement.value : actual <= requirement.value);
|
|
31
|
+
}
|
|
32
|
+
if (requirement.kind === "warranty" && typeof requirement.value === "number") {
|
|
33
|
+
return typeof actual === "number" && Number.isSafeInteger(actual) && actual >= requirement.value;
|
|
34
|
+
}
|
|
35
|
+
if (requirement.kind === "delivery" && validTimestamp(requirement.value)) {
|
|
36
|
+
return validTimestamp(actual) && Date.parse(actual) <= Date.parse(requirement.value);
|
|
37
|
+
}
|
|
38
|
+
return actual === requirement.value;
|
|
39
|
+
}
|
|
40
|
+
export function asRecord(value) {
|
|
41
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=requirements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirements.js","sourceRoot":"","sources":["../../../src/buyer-core/procurement/requirements.ts"],"names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,CAAC,CAAC,EAAE,CAAC;AACtH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type Basis } from "./requirements.js";
|
|
2
|
+
export type Coverage = "completed" | "partial" | "timeout" | "error" | "not_searched";
|
|
3
|
+
export type PriceKind = "KNP_OFFER" | "SUPPLIER_QUOTE" | "CHECKOUT_SNAPSHOT" | "PAGE_REFERENCE" | "IMPORTED_REFERENCE";
|
|
4
|
+
export interface Evidence {
|
|
5
|
+
reference: string;
|
|
6
|
+
captured_at: string;
|
|
7
|
+
location?: string;
|
|
8
|
+
freshness_due_at?: string;
|
|
9
|
+
valid_until?: string;
|
|
10
|
+
account_scope?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ObservedProduct {
|
|
13
|
+
model?: string;
|
|
14
|
+
values?: Record<string, string | number | boolean>;
|
|
15
|
+
supplier_ref?: string;
|
|
16
|
+
verified_kiwi_merchant_id?: string;
|
|
17
|
+
stock_quantity?: number;
|
|
18
|
+
arrived_by?: string;
|
|
19
|
+
destination?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Source {
|
|
22
|
+
id: string;
|
|
23
|
+
channel: "kiwi" | "ecommerce";
|
|
24
|
+
name: string;
|
|
25
|
+
variant: string;
|
|
26
|
+
merchant_id?: string;
|
|
27
|
+
inquiry_available?: boolean;
|
|
28
|
+
evidence: Evidence;
|
|
29
|
+
product?: ObservedProduct;
|
|
30
|
+
price_kind: PriceKind;
|
|
31
|
+
costs?: unknown;
|
|
32
|
+
version: string;
|
|
33
|
+
basis_digest: string;
|
|
34
|
+
replaces_source_id?: string;
|
|
35
|
+
task_id?: string;
|
|
36
|
+
candidate_id?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface Observation {
|
|
39
|
+
source: Source;
|
|
40
|
+
price_kind: PriceKind;
|
|
41
|
+
digest: string;
|
|
42
|
+
evidence: Evidence;
|
|
43
|
+
product?: ObservedProduct;
|
|
44
|
+
costs?: unknown;
|
|
45
|
+
native_item?: unknown;
|
|
46
|
+
native_fulfillment?: unknown;
|
|
47
|
+
projection_digest?: string;
|
|
48
|
+
response?: Record<string, unknown>;
|
|
49
|
+
transmission: "NOT_SENT" | "PREPARED" | "RECEIPTED" | "UNKNOWN";
|
|
50
|
+
observed_at: string;
|
|
51
|
+
expired: boolean;
|
|
52
|
+
verified: boolean;
|
|
53
|
+
native_current?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare function observe(source: Source, candidate: Record<string, unknown> | undefined, at: string, projection?: string, state?: Observation["transmission"]): Observation;
|
|
56
|
+
export declare function sourceVersion(source: Omit<Source, "version">): Source;
|
|
57
|
+
export declare function missingBasis(basis: Basis): string[];
|