@harrylabsj/kiwi 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +150 -0
- package/contracts/candidate-agent-dto-1.0.README.md +39 -0
- package/contracts/candidate-agent-dto-1.0.schema.json +172 -0
- package/contracts/interop/kiwi-buyer-message-send.json +43 -0
- package/contracts/interop/knp-data-part-examples.json +243 -0
- package/contracts/kiwi-catalog/1.0/agent-record.schema.json +78 -0
- package/contracts/kiwi-catalog/1.0/listing-record.schema.json +88 -0
- package/contracts/kiwi-catalog/1.0/listing-search-result.schema.json +60 -0
- package/contracts/negotiation/1.0/schema.json +501 -0
- package/contracts/shopping.negotiation/0.1/capabilities.schema.json +47 -0
- package/contracts/shopping.negotiation/0.1/decision.schema.json +120 -0
- package/contracts/shopping.negotiation/0.1/policy-result.schema.json +52 -0
- package/contracts/shopping.negotiation/0.1/snapshot.schema.json +172 -0
- package/dist/a2a/client/client.d.ts +33 -0
- package/dist/a2a/client/client.js +161 -0
- package/dist/a2a/client/client.js.map +1 -0
- package/dist/a2a/client/error.d.ts +35 -0
- package/dist/a2a/client/error.js +34 -0
- package/dist/a2a/client/error.js.map +1 -0
- package/dist/a2a/client/index.d.ts +29 -0
- package/dist/a2a/client/index.js +26 -0
- package/dist/a2a/client/index.js.map +1 -0
- package/dist/a2a/client/jsonrpc.d.ts +49 -0
- package/dist/a2a/client/jsonrpc.js +85 -0
- package/dist/a2a/client/jsonrpc.js.map +1 -0
- package/dist/a2a/client/parse.d.ts +18 -0
- package/dist/a2a/client/parse.js +134 -0
- package/dist/a2a/client/parse.js.map +1 -0
- package/dist/a2a/client/types.d.ts +102 -0
- package/dist/a2a/client/types.js +26 -0
- package/dist/a2a/client/types.js.map +1 -0
- package/dist/a2a/client/url-policy.d.ts +44 -0
- package/dist/a2a/client/url-policy.js +242 -0
- package/dist/a2a/client/url-policy.js.map +1 -0
- package/dist/a2a/negotiate.d.ts +68 -0
- package/dist/a2a/negotiate.js +288 -0
- package/dist/a2a/negotiate.js.map +1 -0
- package/dist/a2a/node.d.ts +37 -0
- package/dist/a2a/node.js +155 -0
- package/dist/a2a/node.js.map +1 -0
- package/dist/a2a/server/auth.d.ts +38 -0
- package/dist/a2a/server/auth.js +112 -0
- package/dist/a2a/server/auth.js.map +1 -0
- package/dist/a2a/server/card.d.ts +19 -0
- package/dist/a2a/server/card.js +81 -0
- package/dist/a2a/server/card.js.map +1 -0
- package/dist/a2a/server/errors.d.ts +109 -0
- package/dist/a2a/server/errors.js +178 -0
- package/dist/a2a/server/errors.js.map +1 -0
- package/dist/a2a/server/handler.d.ts +22 -0
- package/dist/a2a/server/handler.js +57 -0
- package/dist/a2a/server/handler.js.map +1 -0
- package/dist/a2a/server/inbound-message.d.ts +37 -0
- package/dist/a2a/server/inbound-message.js +104 -0
- package/dist/a2a/server/inbound-message.js.map +1 -0
- package/dist/a2a/server/index.d.ts +43 -0
- package/dist/a2a/server/index.js +42 -0
- package/dist/a2a/server/index.js.map +1 -0
- package/dist/a2a/server/merchant-handler.d.ts +69 -0
- package/dist/a2a/server/merchant-handler.js +316 -0
- package/dist/a2a/server/merchant-handler.js.map +1 -0
- package/dist/a2a/server/pipeline.d.ts +69 -0
- package/dist/a2a/server/pipeline.js +329 -0
- package/dist/a2a/server/pipeline.js.map +1 -0
- package/dist/a2a/server/server.d.ts +64 -0
- package/dist/a2a/server/server.js +420 -0
- package/dist/a2a/server/server.js.map +1 -0
- package/dist/a2a/server/task-registry.d.ts +31 -0
- package/dist/a2a/server/task-registry.js +67 -0
- package/dist/a2a/server/task-registry.js.map +1 -0
- package/dist/a2a/server/throttle.d.ts +154 -0
- package/dist/a2a/server/throttle.js +289 -0
- package/dist/a2a/server/throttle.js.map +1 -0
- package/dist/a2a/server/types.d.ts +191 -0
- package/dist/a2a/server/types.js +17 -0
- package/dist/a2a/server/types.js.map +1 -0
- package/dist/a2a/server/ucp.d.ts +49 -0
- package/dist/a2a/server/ucp.js +85 -0
- package/dist/a2a/server/ucp.js.map +1 -0
- package/dist/a2a/task/index.d.ts +24 -0
- package/dist/a2a/task/index.js +22 -0
- package/dist/a2a/task/index.js.map +1 -0
- package/dist/a2a/task/ledger.d.ts +48 -0
- package/dist/a2a/task/ledger.js +65 -0
- package/dist/a2a/task/ledger.js.map +1 -0
- package/dist/a2a/task/poller.d.ts +93 -0
- package/dist/a2a/task/poller.js +184 -0
- package/dist/a2a/task/poller.js.map +1 -0
- package/dist/a2a/task/state.d.ts +72 -0
- package/dist/a2a/task/state.js +119 -0
- package/dist/a2a/task/state.js.map +1 -0
- package/dist/a2a/ucp-agent.d.ts +49 -0
- package/dist/a2a/ucp-agent.js +78 -0
- package/dist/a2a/ucp-agent.js.map +1 -0
- package/dist/agent/agent-db.d.ts +31 -0
- package/dist/agent/agent-db.js +91 -0
- package/dist/agent/agent-db.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.d.ts +70 -0
- package/dist/agent/buyer/buyer-tools.js +1353 -0
- package/dist/agent/buyer/buyer-tools.js.map +1 -0
- package/dist/agent/buyer/ranker.d.ts +53 -0
- package/dist/agent/buyer/ranker.js +153 -0
- package/dist/agent/buyer/ranker.js.map +1 -0
- package/dist/agent/buyer/scheduler.d.ts +58 -0
- package/dist/agent/buyer/scheduler.js +317 -0
- package/dist/agent/buyer/scheduler.js.map +1 -0
- package/dist/agent/buyer/search-loop.d.ts +42 -0
- package/dist/agent/buyer/search-loop.js +280 -0
- package/dist/agent/buyer/search-loop.js.map +1 -0
- package/dist/agent/buyer/task-store.d.ts +178 -0
- package/dist/agent/buyer/task-store.js +637 -0
- package/dist/agent/buyer/task-store.js.map +1 -0
- package/dist/agent/buyer/types.d.ts +222 -0
- package/dist/agent/buyer/types.js +124 -0
- package/dist/agent/buyer/types.js.map +1 -0
- package/dist/agent/chat-tools.d.ts +41 -0
- package/dist/agent/chat-tools.js +193 -0
- package/dist/agent/chat-tools.js.map +1 -0
- package/dist/agent/chat-tui.d.ts +49 -0
- package/dist/agent/chat-tui.js +314 -0
- package/dist/agent/chat-tui.js.map +1 -0
- package/dist/agent/connector/fake-connector.d.ts +50 -0
- package/dist/agent/connector/fake-connector.js +138 -0
- package/dist/agent/connector/fake-connector.js.map +1 -0
- package/dist/agent/connector/http-connector.d.ts +49 -0
- package/dist/agent/connector/http-connector.js +208 -0
- package/dist/agent/connector/http-connector.js.map +1 -0
- package/dist/agent/connector/types.d.ts +103 -0
- package/dist/agent/connector/types.js +97 -0
- package/dist/agent/connector/types.js.map +1 -0
- package/dist/agent/fake-chat-model.d.ts +22 -0
- package/dist/agent/fake-chat-model.js +134 -0
- package/dist/agent/fake-chat-model.js.map +1 -0
- package/dist/agent/kernel.d.ts +258 -0
- package/dist/agent/kernel.js +1099 -0
- package/dist/agent/kernel.js.map +1 -0
- package/dist/agent/memory/schema.d.ts +32 -0
- package/dist/agent/memory/schema.js +291 -0
- package/dist/agent/memory/schema.js.map +1 -0
- package/dist/agent/memory/store.d.ts +193 -0
- package/dist/agent/memory/store.js +881 -0
- package/dist/agent/memory/store.js.map +1 -0
- package/dist/agent/memory/types.d.ts +139 -0
- package/dist/agent/memory/types.js +119 -0
- package/dist/agent/memory/types.js.map +1 -0
- package/dist/agent/memory/vault.d.ts +49 -0
- package/dist/agent/memory/vault.js +125 -0
- package/dist/agent/memory/vault.js.map +1 -0
- package/dist/agent/merchant/action-candidate.d.ts +106 -0
- package/dist/agent/merchant/action-candidate.js +241 -0
- package/dist/agent/merchant/action-candidate.js.map +1 -0
- package/dist/agent/merchant/credential-broker.d.ts +67 -0
- package/dist/agent/merchant/credential-broker.js +76 -0
- package/dist/agent/merchant/credential-broker.js.map +1 -0
- package/dist/agent/merchant/fake-merchant-client.d.ts +47 -0
- package/dist/agent/merchant/fake-merchant-client.js +143 -0
- package/dist/agent/merchant/fake-merchant-client.js.map +1 -0
- package/dist/agent/merchant/merchant-client.d.ts +49 -0
- package/dist/agent/merchant/merchant-client.js +186 -0
- package/dist/agent/merchant/merchant-client.js.map +1 -0
- package/dist/agent/merchant/merchant-tools.d.ts +74 -0
- package/dist/agent/merchant/merchant-tools.js +582 -0
- package/dist/agent/merchant/merchant-tools.js.map +1 -0
- package/dist/agent/merchant/types.d.ts +119 -0
- package/dist/agent/merchant/types.js +133 -0
- package/dist/agent/merchant/types.js.map +1 -0
- package/dist/agent/mode.d.ts +32 -0
- package/dist/agent/mode.js +34 -0
- package/dist/agent/mode.js.map +1 -0
- package/dist/agent/negotiation-chat.d.ts +81 -0
- package/dist/agent/negotiation-chat.js +330 -0
- package/dist/agent/negotiation-chat.js.map +1 -0
- package/dist/agent/session.d.ts +22 -0
- package/dist/agent/session.js +164 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/system-prompt.d.ts +26 -0
- package/dist/agent/system-prompt.js +77 -0
- package/dist/agent/system-prompt.js.map +1 -0
- package/dist/agent/write-gate.d.ts +98 -0
- package/dist/agent/write-gate.js +76 -0
- package/dist/agent/write-gate.js.map +1 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.js +1139 -0
- package/dist/cli.js.map +1 -0
- package/dist/commerce/data-source.d.ts +88 -0
- package/dist/commerce/data-source.js +25 -0
- package/dist/commerce/data-source.js.map +1 -0
- package/dist/commerce/erp-source.d.ts +51 -0
- package/dist/commerce/erp-source.js +184 -0
- package/dist/commerce/erp-source.js.map +1 -0
- package/dist/commerce/fake-client.d.ts +167 -0
- package/dist/commerce/fake-client.js +549 -0
- package/dist/commerce/fake-client.js.map +1 -0
- package/dist/commerce/http-client.d.ts +73 -0
- package/dist/commerce/http-client.js +284 -0
- package/dist/commerce/http-client.js.map +1 -0
- package/dist/commerce/local-db-source.d.ts +50 -0
- package/dist/commerce/local-db-source.js +162 -0
- package/dist/commerce/local-db-source.js.map +1 -0
- package/dist/commerce/shopping-cli-source.d.ts +57 -0
- package/dist/commerce/shopping-cli-source.js +206 -0
- package/dist/commerce/shopping-cli-source.js.map +1 -0
- package/dist/commerce/types.d.ts +146 -0
- package/dist/commerce/types.js +31 -0
- package/dist/commerce/types.js.map +1 -0
- package/dist/config/profile.d.ts +122 -0
- package/dist/config/profile.js +386 -0
- package/dist/config/profile.js.map +1 -0
- package/dist/contracts/negotiation-schema.d.ts +28 -0
- package/dist/contracts/negotiation-schema.js +101 -0
- package/dist/contracts/negotiation-schema.js.map +1 -0
- package/dist/contracts/schemas.d.ts +31 -0
- package/dist/contracts/schemas.js +122 -0
- package/dist/contracts/schemas.js.map +1 -0
- package/dist/counterparty/a2a-direct/index.d.ts +41 -0
- package/dist/counterparty/a2a-direct/index.js +330 -0
- package/dist/counterparty/a2a-direct/index.js.map +1 -0
- package/dist/counterparty/channel.d.ts +200 -0
- package/dist/counterparty/channel.js +61 -0
- package/dist/counterparty/channel.js.map +1 -0
- package/dist/counterparty/index.d.ts +28 -0
- package/dist/counterparty/index.js +24 -0
- package/dist/counterparty/index.js.map +1 -0
- package/dist/counterparty/platform-api/index.d.ts +41 -0
- package/dist/counterparty/platform-api/index.js +65 -0
- package/dist/counterparty/platform-api/index.js.map +1 -0
- package/dist/counterparty/registry.d.ts +51 -0
- package/dist/counterparty/registry.js +71 -0
- package/dist/counterparty/registry.js.map +1 -0
- package/dist/counterparty/shopping-cli-hosted/index.d.ts +36 -0
- package/dist/counterparty/shopping-cli-hosted/index.js +337 -0
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -0
- package/dist/discovery/agent-card/error.d.ts +28 -0
- package/dist/discovery/agent-card/error.js +31 -0
- package/dist/discovery/agent-card/error.js.map +1 -0
- package/dist/discovery/agent-card/extensions.d.ts +20 -0
- package/dist/discovery/agent-card/extensions.js +59 -0
- package/dist/discovery/agent-card/extensions.js.map +1 -0
- package/dist/discovery/agent-card/index.d.ts +29 -0
- package/dist/discovery/agent-card/index.js +38 -0
- package/dist/discovery/agent-card/index.js.map +1 -0
- package/dist/discovery/agent-card/secrets.d.ts +30 -0
- package/dist/discovery/agent-card/secrets.js +240 -0
- package/dist/discovery/agent-card/secrets.js.map +1 -0
- package/dist/discovery/agent-card/types.d.ts +110 -0
- package/dist/discovery/agent-card/types.js +37 -0
- package/dist/discovery/agent-card/types.js.map +1 -0
- package/dist/discovery/agent-card/validate.d.ts +31 -0
- package/dist/discovery/agent-card/validate.js +210 -0
- package/dist/discovery/agent-card/validate.js.map +1 -0
- package/dist/discovery/capability/error.d.ts +23 -0
- package/dist/discovery/capability/error.js +28 -0
- package/dist/discovery/capability/error.js.map +1 -0
- package/dist/discovery/capability/index.d.ts +21 -0
- package/dist/discovery/capability/index.js +21 -0
- package/dist/discovery/capability/index.js.map +1 -0
- package/dist/discovery/capability/intersect.d.ts +56 -0
- package/dist/discovery/capability/intersect.js +137 -0
- package/dist/discovery/capability/intersect.js.map +1 -0
- package/dist/discovery/catalog-source/errors.d.ts +32 -0
- package/dist/discovery/catalog-source/errors.js +41 -0
- package/dist/discovery/catalog-source/errors.js.map +1 -0
- package/dist/discovery/catalog-source/index.d.ts +30 -0
- package/dist/discovery/catalog-source/index.js +29 -0
- package/dist/discovery/catalog-source/index.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-record.d.ts +183 -0
- package/dist/discovery/catalog-source/kiwi-record.js +72 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-schema.d.ts +33 -0
- package/dist/discovery/catalog-source/kiwi-schema.js +106 -0
- package/dist/discovery/catalog-source/kiwi-schema.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-source.d.ts +38 -0
- package/dist/discovery/catalog-source/kiwi-source.js +318 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -0
- package/dist/discovery/catalog-source/register.d.ts +48 -0
- package/dist/discovery/catalog-source/register.js +83 -0
- package/dist/discovery/catalog-source/register.js.map +1 -0
- package/dist/discovery/catalog-source/schema.d.ts +21 -0
- package/dist/discovery/catalog-source/schema.js +63 -0
- package/dist/discovery/catalog-source/schema.js.map +1 -0
- package/dist/discovery/catalog-source/source.d.ts +45 -0
- package/dist/discovery/catalog-source/source.js +197 -0
- package/dist/discovery/catalog-source/source.js.map +1 -0
- package/dist/discovery/catalog-source/types.d.ts +122 -0
- package/dist/discovery/catalog-source/types.js +30 -0
- package/dist/discovery/catalog-source/types.js.map +1 -0
- package/dist/discovery/index.d.ts +25 -0
- package/dist/discovery/index.js +25 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/resolve.d.ts +175 -0
- package/dist/discovery/resolve.js +367 -0
- package/dist/discovery/resolve.js.map +1 -0
- package/dist/discovery/ucp/error.d.ts +25 -0
- package/dist/discovery/ucp/error.js +27 -0
- package/dist/discovery/ucp/error.js.map +1 -0
- package/dist/discovery/ucp/index.d.ts +33 -0
- package/dist/discovery/ucp/index.js +28 -0
- package/dist/discovery/ucp/index.js.map +1 -0
- package/dist/discovery/ucp/intersect.d.ts +148 -0
- package/dist/discovery/ucp/intersect.js +312 -0
- package/dist/discovery/ucp/intersect.js.map +1 -0
- package/dist/discovery/ucp/resolver.d.ts +62 -0
- package/dist/discovery/ucp/resolver.js +214 -0
- package/dist/discovery/ucp/resolver.js.map +1 -0
- package/dist/discovery/ucp/types.d.ts +97 -0
- package/dist/discovery/ucp/types.js +103 -0
- package/dist/discovery/ucp/types.js.map +1 -0
- package/dist/discovery/ucp/validate.d.ts +38 -0
- package/dist/discovery/ucp/validate.js +232 -0
- package/dist/discovery/ucp/validate.js.map +1 -0
- package/dist/discovery/ucp/vendor.d.ts +60 -0
- package/dist/discovery/ucp/vendor.js +61 -0
- package/dist/discovery/ucp/vendor.js.map +1 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +113 -0
- package/dist/doctor.js.map +1 -0
- package/dist/exit-codes.d.ts +26 -0
- package/dist/exit-codes.js +27 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/fanout/disclosure.d.ts +138 -0
- package/dist/fanout/disclosure.js +188 -0
- package/dist/fanout/disclosure.js.map +1 -0
- package/dist/fanout/index.d.ts +32 -0
- package/dist/fanout/index.js +30 -0
- package/dist/fanout/index.js.map +1 -0
- package/dist/fanout/orchestrator.d.ts +153 -0
- package/dist/fanout/orchestrator.js +439 -0
- package/dist/fanout/orchestrator.js.map +1 -0
- package/dist/fanout/policy.d.ts +128 -0
- package/dist/fanout/policy.js +130 -0
- package/dist/fanout/policy.js.map +1 -0
- package/dist/handoff/acp-commerce.d.ts +58 -0
- package/dist/handoff/acp-commerce.js +69 -0
- package/dist/handoff/acp-commerce.js.map +1 -0
- package/dist/handoff/authorization.d.ts +127 -0
- package/dist/handoff/authorization.js +107 -0
- package/dist/handoff/authorization.js.map +1 -0
- package/dist/handoff/candidate.d.ts +94 -0
- package/dist/handoff/candidate.js +172 -0
- package/dist/handoff/candidate.js.map +1 -0
- package/dist/handoff/channel.d.ts +88 -0
- package/dist/handoff/channel.js +189 -0
- package/dist/handoff/channel.js.map +1 -0
- package/dist/handoff/completion.d.ts +44 -0
- package/dist/handoff/completion.js +136 -0
- package/dist/handoff/completion.js.map +1 -0
- package/dist/handoff/delivery.d.ts +59 -0
- package/dist/handoff/delivery.js +185 -0
- package/dist/handoff/delivery.js.map +1 -0
- package/dist/handoff/destination.d.ts +39 -0
- package/dist/handoff/destination.js +99 -0
- package/dist/handoff/destination.js.map +1 -0
- package/dist/handoff/errors.d.ts +34 -0
- package/dist/handoff/errors.js +47 -0
- package/dist/handoff/errors.js.map +1 -0
- package/dist/handoff/idempotency.d.ts +51 -0
- package/dist/handoff/idempotency.js +168 -0
- package/dist/handoff/idempotency.js.map +1 -0
- package/dist/handoff/index.d.ts +46 -0
- package/dist/handoff/index.js +48 -0
- package/dist/handoff/index.js.map +1 -0
- package/dist/handoff/ledger.d.ts +94 -0
- package/dist/handoff/ledger.js +195 -0
- package/dist/handoff/ledger.js.map +1 -0
- package/dist/handoff/lifecycle.d.ts +29 -0
- package/dist/handoff/lifecycle.js +102 -0
- package/dist/handoff/lifecycle.js.map +1 -0
- package/dist/handoff/metrics.d.ts +56 -0
- package/dist/handoff/metrics.js +78 -0
- package/dist/handoff/metrics.js.map +1 -0
- package/dist/handoff/operator-approval.d.ts +143 -0
- package/dist/handoff/operator-approval.js +287 -0
- package/dist/handoff/operator-approval.js.map +1 -0
- package/dist/handoff/order-record.d.ts +104 -0
- package/dist/handoff/order-record.js +235 -0
- package/dist/handoff/order-record.js.map +1 -0
- package/dist/handoff/package.d.ts +102 -0
- package/dist/handoff/package.js +132 -0
- package/dist/handoff/package.js.map +1 -0
- package/dist/handoff/transaction.d.ts +96 -0
- package/dist/handoff/transaction.js +263 -0
- package/dist/handoff/transaction.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.d.ts +111 -0
- package/dist/handoff/ucp-checkout/cart-channel.js +370 -0
- package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-parse.d.ts +22 -0
- package/dist/handoff/ucp-checkout/cart-parse.js +102 -0
- package/dist/handoff/ucp-checkout/cart-parse.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-types.d.ts +93 -0
- package/dist/handoff/ucp-checkout/cart-types.js +38 -0
- package/dist/handoff/ucp-checkout/cart-types.js.map +1 -0
- package/dist/handoff/ucp-checkout/channel.d.ts +159 -0
- package/dist/handoff/ucp-checkout/channel.js +636 -0
- package/dist/handoff/ucp-checkout/channel.js.map +1 -0
- package/dist/handoff/ucp-checkout/client.d.ts +88 -0
- package/dist/handoff/ucp-checkout/client.js +228 -0
- package/dist/handoff/ucp-checkout/client.js.map +1 -0
- package/dist/handoff/ucp-checkout/endpoint.d.ts +36 -0
- package/dist/handoff/ucp-checkout/endpoint.js +145 -0
- package/dist/handoff/ucp-checkout/endpoint.js.map +1 -0
- package/dist/handoff/ucp-checkout/index.d.ts +35 -0
- package/dist/handoff/ucp-checkout/index.js +36 -0
- package/dist/handoff/ucp-checkout/index.js.map +1 -0
- package/dist/handoff/ucp-checkout/parse.d.ts +71 -0
- package/dist/handoff/ucp-checkout/parse.js +349 -0
- package/dist/handoff/ucp-checkout/parse.js.map +1 -0
- package/dist/handoff/ucp-checkout/totals.d.ts +41 -0
- package/dist/handoff/ucp-checkout/totals.js +36 -0
- package/dist/handoff/ucp-checkout/totals.js.map +1 -0
- package/dist/handoff/ucp-checkout/types.d.ts +149 -0
- package/dist/handoff/ucp-checkout/types.js +58 -0
- package/dist/handoff/ucp-checkout/types.js.map +1 -0
- package/dist/handoff/url-safety.d.ts +44 -0
- package/dist/handoff/url-safety.js +121 -0
- package/dist/handoff/url-safety.js.map +1 -0
- package/dist/i18n.d.ts +24 -0
- package/dist/i18n.js +27 -0
- package/dist/i18n.js.map +1 -0
- package/dist/negotiation/action-candidate.d.ts +97 -0
- package/dist/negotiation/action-candidate.js +160 -0
- package/dist/negotiation/action-candidate.js.map +1 -0
- package/dist/negotiation/condition/evaluator.d.ts +36 -0
- package/dist/negotiation/condition/evaluator.js +123 -0
- package/dist/negotiation/condition/evaluator.js.map +1 -0
- package/dist/negotiation/context-map/index.d.ts +23 -0
- package/dist/negotiation/context-map/index.js +22 -0
- package/dist/negotiation/context-map/index.js.map +1 -0
- package/dist/negotiation/context-map/store.d.ts +51 -0
- package/dist/negotiation/context-map/store.js +186 -0
- package/dist/negotiation/context-map/store.js.map +1 -0
- package/dist/negotiation/context-map/types.d.ts +29 -0
- package/dist/negotiation/context-map/types.js +57 -0
- package/dist/negotiation/context-map/types.js.map +1 -0
- package/dist/negotiation/domain/common.d.ts +95 -0
- package/dist/negotiation/domain/common.js +216 -0
- package/dist/negotiation/domain/common.js.map +1 -0
- package/dist/negotiation/domain/envelope.d.ts +55 -0
- package/dist/negotiation/domain/envelope.js +110 -0
- package/dist/negotiation/domain/envelope.js.map +1 -0
- package/dist/negotiation/domain/identifiers.d.ts +65 -0
- package/dist/negotiation/domain/identifiers.js +130 -0
- package/dist/negotiation/domain/identifiers.js.map +1 -0
- package/dist/negotiation/domain/objects.d.ts +149 -0
- package/dist/negotiation/domain/objects.js +335 -0
- package/dist/negotiation/domain/objects.js.map +1 -0
- package/dist/negotiation/idempotency/index.d.ts +26 -0
- package/dist/negotiation/idempotency/index.js +25 -0
- package/dist/negotiation/idempotency/index.js.map +1 -0
- package/dist/negotiation/idempotency/store.d.ts +52 -0
- package/dist/negotiation/idempotency/store.js +189 -0
- package/dist/negotiation/idempotency/store.js.map +1 -0
- package/dist/negotiation/idempotency/types.d.ts +102 -0
- package/dist/negotiation/idempotency/types.js +47 -0
- package/dist/negotiation/idempotency/types.js.map +1 -0
- package/dist/negotiation/jcs.d.ts +21 -0
- package/dist/negotiation/jcs.js +114 -0
- package/dist/negotiation/jcs.js.map +1 -0
- package/dist/negotiation/ledger/event.d.ts +142 -0
- package/dist/negotiation/ledger/event.js +206 -0
- package/dist/negotiation/ledger/event.js.map +1 -0
- package/dist/negotiation/ledger/index.d.ts +26 -0
- package/dist/negotiation/ledger/index.js +25 -0
- package/dist/negotiation/ledger/index.js.map +1 -0
- package/dist/negotiation/ledger/store.d.ts +97 -0
- package/dist/negotiation/ledger/store.js +338 -0
- package/dist/negotiation/ledger/store.js.map +1 -0
- package/dist/negotiation/prompt.d.ts +34 -0
- package/dist/negotiation/prompt.js +113 -0
- package/dist/negotiation/prompt.js.map +1 -0
- package/dist/negotiation/recovery/index.d.ts +26 -0
- package/dist/negotiation/recovery/index.js +24 -0
- package/dist/negotiation/recovery/index.js.map +1 -0
- package/dist/negotiation/recovery/outbound.d.ts +49 -0
- package/dist/negotiation/recovery/outbound.js +34 -0
- package/dist/negotiation/recovery/outbound.js.map +1 -0
- package/dist/negotiation/recovery/recover.d.ts +59 -0
- package/dist/negotiation/recovery/recover.js +486 -0
- package/dist/negotiation/recovery/recover.js.map +1 -0
- package/dist/negotiation/recovery/types.d.ts +85 -0
- package/dist/negotiation/recovery/types.js +17 -0
- package/dist/negotiation/recovery/types.js.map +1 -0
- package/dist/negotiation/state/phase.d.ts +70 -0
- package/dist/negotiation/state/phase.js +200 -0
- package/dist/negotiation/state/phase.js.map +1 -0
- package/dist/negotiation/types.d.ts +139 -0
- package/dist/negotiation/types.js +24 -0
- package/dist/negotiation/types.js.map +1 -0
- package/dist/net/safe-http.d.ts +54 -0
- package/dist/net/safe-http.js +116 -0
- package/dist/net/safe-http.js.map +1 -0
- package/dist/operator/controller.d.ts +181 -0
- package/dist/operator/controller.js +784 -0
- package/dist/operator/controller.js.map +1 -0
- package/dist/operator/runner.d.ts +128 -0
- package/dist/operator/runner.js +248 -0
- package/dist/operator/runner.js.map +1 -0
- package/dist/operator/store.d.ts +39 -0
- package/dist/operator/store.js +169 -0
- package/dist/operator/store.js.map +1 -0
- package/dist/operator/strategy.d.ts +54 -0
- package/dist/operator/strategy.js +249 -0
- package/dist/operator/strategy.js.map +1 -0
- package/dist/operator/tui.d.ts +27 -0
- package/dist/operator/tui.js +395 -0
- package/dist/operator/tui.js.map +1 -0
- package/dist/operator/types.d.ts +224 -0
- package/dist/operator/types.js +17 -0
- package/dist/operator/types.js.map +1 -0
- package/dist/product-buyer.d.ts +74 -0
- package/dist/product-buyer.js +161 -0
- package/dist/product-buyer.js.map +1 -0
- package/dist/product-cli.d.ts +56 -0
- package/dist/product-cli.js +175 -0
- package/dist/product-cli.js.map +1 -0
- package/dist/product-compat.d.ts +50 -0
- package/dist/product-compat.js +63 -0
- package/dist/product-compat.js.map +1 -0
- package/dist/product-init.d.ts +73 -0
- package/dist/product-init.js +203 -0
- package/dist/product-init.js.map +1 -0
- package/dist/product-publish.d.ts +85 -0
- package/dist/product-publish.js +216 -0
- package/dist/product-publish.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.d.ts +42 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.js +561 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.d.ts +78 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.js +321 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/money.d.ts +49 -0
- package/dist/protocol/legacy-shopping-negotiation/money.js +70 -0
- package/dist/protocol/legacy-shopping-negotiation/money.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/types.d.ts +107 -0
- package/dist/protocol/legacy-shopping-negotiation/types.js +34 -0
- package/dist/protocol/legacy-shopping-negotiation/types.js.map +1 -0
- package/dist/runtime/buyer-policy.d.ts +58 -0
- package/dist/runtime/buyer-policy.js +89 -0
- package/dist/runtime/buyer-policy.js.map +1 -0
- package/dist/runtime/fake-model.d.ts +77 -0
- package/dist/runtime/fake-model.js +307 -0
- package/dist/runtime/fake-model.js.map +1 -0
- package/dist/runtime/foreground.d.ts +56 -0
- package/dist/runtime/foreground.js +97 -0
- package/dist/runtime/foreground.js.map +1 -0
- package/dist/runtime/heartbeat.d.ts +36 -0
- package/dist/runtime/heartbeat.js +49 -0
- package/dist/runtime/heartbeat.js.map +1 -0
- package/dist/runtime/merchant-turn.d.ts +35 -0
- package/dist/runtime/merchant-turn.js +20 -0
- package/dist/runtime/merchant-turn.js.map +1 -0
- package/dist/runtime/model.d.ts +40 -0
- package/dist/runtime/model.js +86 -0
- package/dist/runtime/model.js.map +1 -0
- package/dist/runtime/negotiation-turn.d.ts +101 -0
- package/dist/runtime/negotiation-turn.js +317 -0
- package/dist/runtime/negotiation-turn.js.map +1 -0
- package/dist/runtime/tools.d.ts +64 -0
- package/dist/runtime/tools.js +236 -0
- package/dist/runtime/tools.js.map +1 -0
- package/dist/supervisor/init.d.ts +31 -0
- package/dist/supervisor/init.js +222 -0
- package/dist/supervisor/init.js.map +1 -0
- package/dist/supervisor/logs.d.ts +28 -0
- package/dist/supervisor/logs.js +101 -0
- package/dist/supervisor/logs.js.map +1 -0
- package/dist/supervisor/manage.d.ts +72 -0
- package/dist/supervisor/manage.js +419 -0
- package/dist/supervisor/manage.js.map +1 -0
- package/dist/supervisor/manifest.d.ts +69 -0
- package/dist/supervisor/manifest.js +209 -0
- package/dist/supervisor/manifest.js.map +1 -0
- package/dist/supervisor/stack-config.d.ts +79 -0
- package/dist/supervisor/stack-config.js +262 -0
- package/dist/supervisor/stack-config.js.map +1 -0
- package/dist/supervisor/wrapper.d.ts +17 -0
- package/dist/supervisor/wrapper.js +138 -0
- package/dist/supervisor/wrapper.js.map +1 -0
- package/dist/trust/identity/auth-verifier.d.ts +96 -0
- package/dist/trust/identity/auth-verifier.js +166 -0
- package/dist/trust/identity/auth-verifier.js.map +1 -0
- package/dist/trust/identity/identity-binding.d.ts +63 -0
- package/dist/trust/identity/identity-binding.js +59 -0
- package/dist/trust/identity/identity-binding.js.map +1 -0
- package/dist/trust/identity/index.d.ts +38 -0
- package/dist/trust/identity/index.js +31 -0
- package/dist/trust/identity/index.js.map +1 -0
- package/dist/trust/identity/jws.d.ts +64 -0
- package/dist/trust/identity/jws.js +178 -0
- package/dist/trust/identity/jws.js.map +1 -0
- package/dist/trust/identity/keys.d.ts +71 -0
- package/dist/trust/identity/keys.js +118 -0
- package/dist/trust/identity/keys.js.map +1 -0
- package/dist/trust/identity/message-signature.d.ts +105 -0
- package/dist/trust/identity/message-signature.js +297 -0
- package/dist/trust/identity/message-signature.js.map +1 -0
- package/dist/trust/identity/nonce.d.ts +45 -0
- package/dist/trust/identity/nonce.js +50 -0
- package/dist/trust/identity/nonce.js.map +1 -0
- package/dist/trust/identity/signature-base.d.ts +84 -0
- package/dist/trust/identity/signature-base.js +261 -0
- package/dist/trust/identity/signature-base.js.map +1 -0
- package/dist/trust/identity/trust-policy.d.ts +92 -0
- package/dist/trust/identity/trust-policy.js +95 -0
- package/dist/trust/identity/trust-policy.js.map +1 -0
- package/dist/trust/index.d.ts +21 -0
- package/dist/trust/index.js +22 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/records/evaluator.d.ts +76 -0
- package/dist/trust/records/evaluator.js +122 -0
- package/dist/trust/records/evaluator.js.map +1 -0
- package/dist/trust/records/index.d.ts +28 -0
- package/dist/trust/records/index.js +26 -0
- package/dist/trust/records/index.js.map +1 -0
- package/dist/trust/records/store.d.ts +75 -0
- package/dist/trust/records/store.js +339 -0
- package/dist/trust/records/store.js.map +1 -0
- package/dist/trust/records/types.d.ts +159 -0
- package/dist/trust/records/types.js +40 -0
- package/dist/trust/records/types.js.map +1 -0
- package/dist/tui/banner.d.ts +46 -0
- package/dist/tui/banner.js +99 -0
- package/dist/tui/banner.js.map +1 -0
- package/dist/tui/styles.d.ts +70 -0
- package/dist/tui/styles.js +197 -0
- package/dist/tui/styles.js.map +1 -0
- package/dist/tui/theme.d.ts +63 -0
- package/dist/tui/theme.js +136 -0
- package/dist/tui/theme.js.map +1 -0
- package/examples/profiles/buyer.deepseek.yaml +34 -0
- package/examples/profiles/buyer.fake.yaml +36 -0
- package/examples/profiles/buyer.local.yaml +40 -0
- package/examples/profiles/merchant.deepseek.yaml +32 -0
- package/examples/profiles/merchant.fake.yaml +31 -0
- package/examples/profiles/merchant.local.yaml +34 -0
- package/package.json +55 -0
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
* Kiwi v0.7.0 Transaction Handoff(WP2 补全)— UcpCartChannel:UCP Cart client +
|
|
18
|
+
* cart→checkout 转换。
|
|
19
|
+
*
|
|
20
|
+
* Cart(UCP 2026-04-08):
|
|
21
|
+
* - capability `dev.ucp.shopping.cart`;操作 Create/Get/Update(全量替换)/Cancel;
|
|
22
|
+
* - cart 无支付配置、无 status 生命周期、无 complete 操作;totals 是估算,
|
|
23
|
+
* 平台 SHOULD 视为 estimate(本 channel 不做 checkout 级 sum 校验);
|
|
24
|
+
* - ucp.status=success|error 判别;Get 对不存在/过期/已取消返回 not_found
|
|
25
|
+
* (client.ts 结构化判别 → cart_not_found);
|
|
26
|
+
* - Cancel 返回删除前的 cart 状态,后续操作返回 not_found。
|
|
27
|
+
*
|
|
28
|
+
* cart→checkout 转换(createCheckoutFromCart):
|
|
29
|
+
* - 前置:business profile 宣告 cart capability(cartCapabilityVerified);
|
|
30
|
+
* 本地 cart 镜像存在且未被 cancel;远端仍是活 cart(refresh,防过期/已取消);
|
|
31
|
+
* - 委托 UcpCheckoutChannel.createSession(pkg, {cart_id})——payload 不带
|
|
32
|
+
* line_items;链接由 checkout channel 本地记录(cartCheckoutLink);
|
|
33
|
+
* - 幂等:同 cart_id + 同 terms_digest 二次转换短接为既有会话;
|
|
34
|
+
* 完成门禁不变(complete 仍需 HandoffPackage + 授权)。
|
|
35
|
+
*
|
|
36
|
+
* 零新增依赖;HTTP 传输复用 UcpCheckoutHttpClient(client.ts)。
|
|
37
|
+
*/
|
|
38
|
+
import { type TermSet } from "../../negotiation/domain/common.js";
|
|
39
|
+
import type { AuthorizationProvider } from "../authorization.js";
|
|
40
|
+
import type { HandoffPackage } from "../package.js";
|
|
41
|
+
import type { UcpProfile } from "../../discovery/ucp/types.js";
|
|
42
|
+
import { UcpCheckoutChannel } from "./channel.js";
|
|
43
|
+
import type { UcpCartResult } from "./cart-types.js";
|
|
44
|
+
import type { UcpCheckoutResult } from "./types.js";
|
|
45
|
+
export interface UcpCartChannelOptions {
|
|
46
|
+
/** cart REST service endpoint(与 profile 二选一;优先 endpoint)。 */
|
|
47
|
+
endpoint?: string;
|
|
48
|
+
/** UCP profile:解析 cart endpoint + checkout endpoint,并验证 cart capability。 */
|
|
49
|
+
profile?: UcpProfile;
|
|
50
|
+
/** 显式指定 profile 内 cart service 名(自动探测时省略)。 */
|
|
51
|
+
cartServiceName?: string;
|
|
52
|
+
/** 预建的 checkout channel(缺省按 profile/checkoutEndpoint 自建)。 */
|
|
53
|
+
checkout?: UcpCheckoutChannel;
|
|
54
|
+
/** 预建缺省时,checkout REST service endpoint(profile 缺 checkout 时用)。 */
|
|
55
|
+
checkoutEndpoint?: string;
|
|
56
|
+
/** 预建缺省时,显式指定 profile 内 checkout service 名。 */
|
|
57
|
+
checkoutServiceName?: string;
|
|
58
|
+
fetchImpl?: typeof fetch;
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
/** 透传给 url-policy 的私网放行开关(默认 false,fail-closed)。 */
|
|
61
|
+
allowPrivateRanges?: boolean;
|
|
62
|
+
/** 跳过请求前 DNS 复查(测试用;生产应保持 false)。 */
|
|
63
|
+
skipDnsCheck?: boolean;
|
|
64
|
+
resolveIp?: (hostname: string) => Promise<string[]>;
|
|
65
|
+
/** buyer 的 UCP profile URI;配置时每个请求携带 `UCP-Agent` 头(§25.1)。 */
|
|
66
|
+
ucpAgentProfile?: string;
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
/** 可注入时钟(RFC 3339);缺省 new Date().toISOString()。 */
|
|
69
|
+
now?: () => string;
|
|
70
|
+
/** 预建 checkout channel 时透传的授权提供方(cart 自身无 complete)。 */
|
|
71
|
+
authorizationProvider?: AuthorizationProvider;
|
|
72
|
+
}
|
|
73
|
+
export declare class UcpCartChannel {
|
|
74
|
+
private readonly client;
|
|
75
|
+
private readonly now;
|
|
76
|
+
/** cart_id 仅在 business profile 宣告 cart capability 时可用。 */
|
|
77
|
+
private readonly cartCapabilityVerified;
|
|
78
|
+
private readonly checkout?;
|
|
79
|
+
/** 本地 cart 镜像:只服务本地前置校验;远端 cart 是状态权威(not_found 判别)。 */
|
|
80
|
+
private readonly carts;
|
|
81
|
+
constructor(options?: UcpCartChannelOptions);
|
|
82
|
+
createCart(pkg: HandoffPackage): Promise<UcpCartResult>;
|
|
83
|
+
getCart(cartId: string): Promise<UcpCartResult>;
|
|
84
|
+
/** Update 全量替换语义:远端确认存活后 PUT 完整 cart 表示。 */
|
|
85
|
+
updateCart(cartId: string, terms: TermSet): Promise<UcpCartResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Cancel:返回删除前的 cart 状态(记录为本地 canceled 快照);后续操作
|
|
88
|
+
* (get/update/cancel)远端返回 not_found → cart_not_found / cart_not_actionable。
|
|
89
|
+
*/
|
|
90
|
+
cancelCart(cartId: string): Promise<UcpCartResult>;
|
|
91
|
+
/**
|
|
92
|
+
* 把已存在的 cart 转成 checkout 会话。
|
|
93
|
+
*
|
|
94
|
+
* 前置(spec 事实):
|
|
95
|
+
* - business profile 宣告 cart capability(否则 cart_capability_unavailable);
|
|
96
|
+
* - 本地镜像存在且未 cancel;
|
|
97
|
+
* - refresh 远端确认 cart 仍是活的(过期/已取消 → not_found → cart_not_found)。
|
|
98
|
+
* 委托 checkout channel.createSession(pkg, {cart_id})——payload 不带 line_items;
|
|
99
|
+
* 链接由 checkout channel 本地记录;幂等语义见 UcpCheckoutChannel。
|
|
100
|
+
*/
|
|
101
|
+
createCheckoutFromCart(cartId: string, pkg: HandoffPackage): Promise<UcpCheckoutResult>;
|
|
102
|
+
/** 当前本地 cart 镜像数量(诊断用)。 */
|
|
103
|
+
get cartCount(): number;
|
|
104
|
+
private validatePackage;
|
|
105
|
+
/** 远端确认 cart 仍是活的:not_found → cart_not_found;error envelope → 消息算法。 */
|
|
106
|
+
private confirmLive;
|
|
107
|
+
private failWith;
|
|
108
|
+
private mapHttpError;
|
|
109
|
+
/** error envelope → 三形态结果(error 响应绝不 ok)。 */
|
|
110
|
+
private cartDecision;
|
|
111
|
+
}
|
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
* Kiwi v0.7.0 Transaction Handoff(WP2 补全)— UcpCartChannel:UCP Cart client +
|
|
18
|
+
* cart→checkout 转换。
|
|
19
|
+
*
|
|
20
|
+
* Cart(UCP 2026-04-08):
|
|
21
|
+
* - capability `dev.ucp.shopping.cart`;操作 Create/Get/Update(全量替换)/Cancel;
|
|
22
|
+
* - cart 无支付配置、无 status 生命周期、无 complete 操作;totals 是估算,
|
|
23
|
+
* 平台 SHOULD 视为 estimate(本 channel 不做 checkout 级 sum 校验);
|
|
24
|
+
* - ucp.status=success|error 判别;Get 对不存在/过期/已取消返回 not_found
|
|
25
|
+
* (client.ts 结构化判别 → cart_not_found);
|
|
26
|
+
* - Cancel 返回删除前的 cart 状态,后续操作返回 not_found。
|
|
27
|
+
*
|
|
28
|
+
* cart→checkout 转换(createCheckoutFromCart):
|
|
29
|
+
* - 前置:business profile 宣告 cart capability(cartCapabilityVerified);
|
|
30
|
+
* 本地 cart 镜像存在且未被 cancel;远端仍是活 cart(refresh,防过期/已取消);
|
|
31
|
+
* - 委托 UcpCheckoutChannel.createSession(pkg, {cart_id})——payload 不带
|
|
32
|
+
* line_items;链接由 checkout channel 本地记录(cartCheckoutLink);
|
|
33
|
+
* - 幂等:同 cart_id + 同 terms_digest 二次转换短接为既有会话;
|
|
34
|
+
* 完成门禁不变(complete 仍需 HandoffPackage + 授权)。
|
|
35
|
+
*
|
|
36
|
+
* 零新增依赖;HTTP 传输复用 UcpCheckoutHttpClient(client.ts)。
|
|
37
|
+
*/
|
|
38
|
+
import { validateTermSet } from "../../negotiation/domain/common.js";
|
|
39
|
+
import { contentDigest } from "../../negotiation/jcs.js";
|
|
40
|
+
import { HandoffError } from "../errors.js";
|
|
41
|
+
import { verifyHandoffPackageDigest } from "../package.js";
|
|
42
|
+
import { UcpCheckoutChannel, mapTermsToLineItems, } from "./channel.js";
|
|
43
|
+
import { isUcpCartErrorResponse } from "./cart-parse.js";
|
|
44
|
+
import { decideMessages } from "./parse.js";
|
|
45
|
+
import { UcpCheckoutHttpClient, } from "./client.js";
|
|
46
|
+
import { findCartEndpoint, profileHasCartCapability, findCheckoutEndpoint } from "./endpoint.js";
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// UcpCartChannel
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
export class UcpCartChannel {
|
|
51
|
+
client;
|
|
52
|
+
now;
|
|
53
|
+
/** cart_id 仅在 business profile 宣告 cart capability 时可用。 */
|
|
54
|
+
cartCapabilityVerified;
|
|
55
|
+
checkout;
|
|
56
|
+
/** 本地 cart 镜像:只服务本地前置校验;远端 cart 是状态权威(not_found 判别)。 */
|
|
57
|
+
carts = new Map();
|
|
58
|
+
constructor(options = {}) {
|
|
59
|
+
const cartEndpoint = options.endpoint ??
|
|
60
|
+
(options.profile !== undefined
|
|
61
|
+
? findCartEndpoint(options.profile, { serviceName: options.cartServiceName })
|
|
62
|
+
: undefined);
|
|
63
|
+
if (cartEndpoint === undefined) {
|
|
64
|
+
throw new HandoffError("invalid_input", "UcpCartChannel requires cart endpoint or a profile with a cart REST service");
|
|
65
|
+
}
|
|
66
|
+
let client;
|
|
67
|
+
try {
|
|
68
|
+
client = new UcpCheckoutHttpClient({
|
|
69
|
+
endpoint: cartEndpoint,
|
|
70
|
+
fetchImpl: options.fetchImpl,
|
|
71
|
+
timeoutMs: options.timeoutMs,
|
|
72
|
+
allowPrivateRanges: options.allowPrivateRanges,
|
|
73
|
+
skipDnsCheck: options.skipDnsCheck,
|
|
74
|
+
resolveIp: options.resolveIp,
|
|
75
|
+
ucpAgentProfile: options.ucpAgentProfile,
|
|
76
|
+
headers: options.headers,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
throw new HandoffError("invalid_input", `ucp cart endpoint rejected: ${err instanceof Error ? err.message : String(err)}`);
|
|
81
|
+
}
|
|
82
|
+
this.client = client;
|
|
83
|
+
this.now = options.now ?? (() => new Date().toISOString());
|
|
84
|
+
this.cartCapabilityVerified =
|
|
85
|
+
options.profile !== undefined ? profileHasCartCapability(options.profile) : false;
|
|
86
|
+
if (options.checkout !== undefined) {
|
|
87
|
+
this.checkout = options.checkout;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const checkoutEndpoint = options.checkoutEndpoint ??
|
|
91
|
+
(options.profile !== undefined
|
|
92
|
+
? findCheckoutEndpoint(options.profile, { serviceName: options.checkoutServiceName })
|
|
93
|
+
: undefined);
|
|
94
|
+
if (checkoutEndpoint !== undefined) {
|
|
95
|
+
const checkoutOpts = {
|
|
96
|
+
endpoint: checkoutEndpoint,
|
|
97
|
+
fetchImpl: options.fetchImpl,
|
|
98
|
+
timeoutMs: options.timeoutMs,
|
|
99
|
+
allowPrivateRanges: options.allowPrivateRanges,
|
|
100
|
+
skipDnsCheck: options.skipDnsCheck,
|
|
101
|
+
resolveIp: options.resolveIp,
|
|
102
|
+
ucpAgentProfile: options.ucpAgentProfile,
|
|
103
|
+
headers: options.headers,
|
|
104
|
+
now: options.now,
|
|
105
|
+
authorizationProvider: options.authorizationProvider,
|
|
106
|
+
};
|
|
107
|
+
if (options.profile !== undefined)
|
|
108
|
+
checkoutOpts.profile = options.profile;
|
|
109
|
+
this.checkout = new UcpCheckoutChannel(checkoutOpts);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// -- Cart CRUD -----------------------------------------------------------
|
|
114
|
+
async createCart(pkg) {
|
|
115
|
+
const guard = this.validatePackage(pkg, "createCart");
|
|
116
|
+
if (!guard.ok)
|
|
117
|
+
return this.failWith(guard.reason, guard.code);
|
|
118
|
+
const mapped = mapTermsToLineItems(guard.terms);
|
|
119
|
+
if (!mapped.ok) {
|
|
120
|
+
return this.failWith(`createCart rejected: ${mapped.reason}`, "invalid_quantity");
|
|
121
|
+
}
|
|
122
|
+
const http = await this.client.createCart({ line_items: mapped.items });
|
|
123
|
+
if (http.kind === "error")
|
|
124
|
+
return this.mapHttpError(http);
|
|
125
|
+
if (http.kind === "not_found") {
|
|
126
|
+
return this.failWith(`cart_not_found: create cart returned not_found`, "cart_not_found");
|
|
127
|
+
}
|
|
128
|
+
if (isUcpCartErrorResponse(http.response)) {
|
|
129
|
+
return this.cartDecision(decideMessages(http.response.messages, http.response.continue_url), {
|
|
130
|
+
messages: http.response.messages,
|
|
131
|
+
continue_url: http.response.continue_url,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const cart = http.response;
|
|
135
|
+
this.carts.set(cart.cart_id, { cart, canceled: false });
|
|
136
|
+
return { status: "ok", cart_ref: cart.cart_id, cart };
|
|
137
|
+
}
|
|
138
|
+
async getCart(cartId) {
|
|
139
|
+
const http = await this.client.getCart(cartId);
|
|
140
|
+
if (http.kind === "error")
|
|
141
|
+
return this.mapHttpError(http);
|
|
142
|
+
if (http.kind === "not_found") {
|
|
143
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
144
|
+
}
|
|
145
|
+
if (isUcpCartErrorResponse(http.response)) {
|
|
146
|
+
return this.cartDecision(decideMessages(http.response.messages, http.response.continue_url), {
|
|
147
|
+
messages: http.response.messages,
|
|
148
|
+
continue_url: http.response.continue_url,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const cart = http.response;
|
|
152
|
+
this.carts.set(cartId, { cart, canceled: false });
|
|
153
|
+
return { status: "ok", cart_ref: cartId, cart };
|
|
154
|
+
}
|
|
155
|
+
/** Update 全量替换语义:远端确认存活后 PUT 完整 cart 表示。 */
|
|
156
|
+
async updateCart(cartId, terms) {
|
|
157
|
+
const mirror = this.carts.get(cartId);
|
|
158
|
+
if (mirror === undefined) {
|
|
159
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
160
|
+
}
|
|
161
|
+
if (mirror.canceled) {
|
|
162
|
+
return this.failWith(`cart_not_actionable: canceled ${cartId}`, "cart_not_actionable");
|
|
163
|
+
}
|
|
164
|
+
const live = await this.confirmLive(cartId);
|
|
165
|
+
if (live.status !== "ok")
|
|
166
|
+
return live;
|
|
167
|
+
let nextTerms;
|
|
168
|
+
try {
|
|
169
|
+
nextTerms = validateTermSet(terms, "terms");
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return this.failWith(`updateCart rejected: ${err instanceof Error ? err.message : String(err)}`, "invalid_terms");
|
|
173
|
+
}
|
|
174
|
+
const mapped = mapTermsToLineItems(nextTerms);
|
|
175
|
+
if (!mapped.ok) {
|
|
176
|
+
return this.failWith(`updateCart rejected: ${mapped.reason}`, "invalid_quantity");
|
|
177
|
+
}
|
|
178
|
+
const put = await this.client.updateCart(cartId, { line_items: mapped.items });
|
|
179
|
+
if (put.kind === "error")
|
|
180
|
+
return this.mapHttpError(put);
|
|
181
|
+
if (put.kind === "not_found") {
|
|
182
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
183
|
+
}
|
|
184
|
+
if (isUcpCartErrorResponse(put.response)) {
|
|
185
|
+
return this.cartDecision(decideMessages(put.response.messages, put.response.continue_url), {
|
|
186
|
+
messages: put.response.messages,
|
|
187
|
+
continue_url: put.response.continue_url,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
const cart = put.response;
|
|
191
|
+
this.carts.set(cartId, { cart, canceled: false });
|
|
192
|
+
return { status: "ok", cart_ref: cartId, cart };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Cancel:返回删除前的 cart 状态(记录为本地 canceled 快照);后续操作
|
|
196
|
+
* (get/update/cancel)远端返回 not_found → cart_not_found / cart_not_actionable。
|
|
197
|
+
*/
|
|
198
|
+
async cancelCart(cartId) {
|
|
199
|
+
const mirror = this.carts.get(cartId);
|
|
200
|
+
if (mirror === undefined) {
|
|
201
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
202
|
+
}
|
|
203
|
+
if (mirror.canceled) {
|
|
204
|
+
return this.failWith(`cart_not_actionable: already canceled ${cartId}`, "cart_not_actionable");
|
|
205
|
+
}
|
|
206
|
+
const live = await this.confirmLive(cartId);
|
|
207
|
+
if (live.status !== "ok")
|
|
208
|
+
return live;
|
|
209
|
+
const cancel = await this.client.cancelCart(cartId);
|
|
210
|
+
if (cancel.kind === "error")
|
|
211
|
+
return this.mapHttpError(cancel);
|
|
212
|
+
if (cancel.kind === "not_found") {
|
|
213
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
214
|
+
}
|
|
215
|
+
if (isUcpCartErrorResponse(cancel.response)) {
|
|
216
|
+
return this.cartDecision(decideMessages(cancel.response.messages, cancel.response.continue_url), {
|
|
217
|
+
messages: cancel.response.messages,
|
|
218
|
+
continue_url: cancel.response.continue_url,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// 成功:返回的是删除前的 cart 状态。
|
|
222
|
+
const cart = cancel.response;
|
|
223
|
+
this.carts.set(cartId, { cart, canceled: true });
|
|
224
|
+
return { status: "ok", cart_ref: cartId, cart, canceled: true };
|
|
225
|
+
}
|
|
226
|
+
// -- cart→checkout 转换 ---------------------------------------------------
|
|
227
|
+
/**
|
|
228
|
+
* 把已存在的 cart 转成 checkout 会话。
|
|
229
|
+
*
|
|
230
|
+
* 前置(spec 事实):
|
|
231
|
+
* - business profile 宣告 cart capability(否则 cart_capability_unavailable);
|
|
232
|
+
* - 本地镜像存在且未 cancel;
|
|
233
|
+
* - refresh 远端确认 cart 仍是活的(过期/已取消 → not_found → cart_not_found)。
|
|
234
|
+
* 委托 checkout channel.createSession(pkg, {cart_id})——payload 不带 line_items;
|
|
235
|
+
* 链接由 checkout channel 本地记录;幂等语义见 UcpCheckoutChannel。
|
|
236
|
+
*/
|
|
237
|
+
async createCheckoutFromCart(cartId, pkg) {
|
|
238
|
+
if (!this.cartCapabilityVerified) {
|
|
239
|
+
return {
|
|
240
|
+
status: "fail_closed",
|
|
241
|
+
reason: "cart_id unavailable: business profile does not declare dev.ucp.shopping.cart",
|
|
242
|
+
code: "cart_capability_unavailable",
|
|
243
|
+
messages: [],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (this.checkout === undefined) {
|
|
247
|
+
return {
|
|
248
|
+
status: "fail_closed",
|
|
249
|
+
reason: "no checkout channel configured for cart→checkout conversion",
|
|
250
|
+
code: "cart_capability_unavailable",
|
|
251
|
+
messages: [],
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const mirror = this.carts.get(cartId);
|
|
255
|
+
if (mirror === undefined) {
|
|
256
|
+
return { status: "fail_closed", reason: `cart_not_found: ${cartId}`, code: "cart_not_found", messages: [] };
|
|
257
|
+
}
|
|
258
|
+
if (mirror.canceled) {
|
|
259
|
+
return {
|
|
260
|
+
status: "fail_closed",
|
|
261
|
+
reason: "cart_not_actionable: canceled",
|
|
262
|
+
code: "cart_not_actionable",
|
|
263
|
+
messages: [],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// Refresh:远端仍是活 cart(过期/已取消 → not_found)。
|
|
267
|
+
const fresh = await this.getCart(cartId);
|
|
268
|
+
if (fresh.status !== "ok") {
|
|
269
|
+
return {
|
|
270
|
+
status: "fail_closed",
|
|
271
|
+
reason: fresh.status === "fail_closed" ? fresh.reason : "cart refresh failed",
|
|
272
|
+
code: fresh.status === "fail_closed" ? fresh.code ?? "network" : "network",
|
|
273
|
+
messages: fresh.status === "fail_closed" ? fresh.messages : [],
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return this.checkout.createSession(pkg, { cart_id: cartId });
|
|
277
|
+
}
|
|
278
|
+
/** 当前本地 cart 镜像数量(诊断用)。 */
|
|
279
|
+
get cartCount() {
|
|
280
|
+
return this.carts.size;
|
|
281
|
+
}
|
|
282
|
+
// -- 内部辅助 ---------------------------------------------------------------
|
|
283
|
+
validatePackage(pkg, op) {
|
|
284
|
+
if (!verifyHandoffPackageDigest(pkg)) {
|
|
285
|
+
return { ok: false, reason: `${op} rejected: package terms_digest verification failed`, code: "invalid_package" };
|
|
286
|
+
}
|
|
287
|
+
let terms;
|
|
288
|
+
try {
|
|
289
|
+
terms = validateTermSet(pkg.agreed_terms, "agreed_terms");
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
return {
|
|
293
|
+
ok: false,
|
|
294
|
+
reason: `${op} rejected: ${err instanceof Error ? err.message : String(err)}`,
|
|
295
|
+
code: "invalid_terms",
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (contentDigest(terms) !== pkg.terms_digest) {
|
|
299
|
+
return {
|
|
300
|
+
ok: false,
|
|
301
|
+
reason: `${op} rejected: package terms_digest does not match validated agreed_terms`,
|
|
302
|
+
code: "invalid_package",
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return { ok: true, terms };
|
|
306
|
+
}
|
|
307
|
+
/** 远端确认 cart 仍是活的:not_found → cart_not_found;error envelope → 消息算法。 */
|
|
308
|
+
async confirmLive(cartId) {
|
|
309
|
+
const http = await this.client.getCart(cartId);
|
|
310
|
+
if (http.kind === "error")
|
|
311
|
+
return this.mapHttpError(http);
|
|
312
|
+
if (http.kind === "not_found") {
|
|
313
|
+
return this.failWith(`cart_not_found: ${cartId}`, "cart_not_found");
|
|
314
|
+
}
|
|
315
|
+
if (isUcpCartErrorResponse(http.response)) {
|
|
316
|
+
return this.cartDecision(decideMessages(http.response.messages, http.response.continue_url), {
|
|
317
|
+
messages: http.response.messages,
|
|
318
|
+
continue_url: http.response.continue_url,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
this.carts.set(cartId, { cart: http.response, canceled: false });
|
|
322
|
+
return { status: "ok", cart_ref: cartId, cart: http.response };
|
|
323
|
+
}
|
|
324
|
+
failWith(reason, code) {
|
|
325
|
+
return { status: "fail_closed", reason, code, messages: [] };
|
|
326
|
+
}
|
|
327
|
+
mapHttpError(err) {
|
|
328
|
+
return {
|
|
329
|
+
status: "fail_closed",
|
|
330
|
+
reason: `ucp_cart_${err.code}: ${err.reason}`,
|
|
331
|
+
code: err.code,
|
|
332
|
+
messages: [],
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/** error envelope → 三形态结果(error 响应绝不 ok)。 */
|
|
336
|
+
cartDecision(decision, ctx) {
|
|
337
|
+
switch (decision.action) {
|
|
338
|
+
case "ok":
|
|
339
|
+
return {
|
|
340
|
+
status: "fail_closed",
|
|
341
|
+
reason: "ucp error response without actionable messages",
|
|
342
|
+
code: "unrecoverable",
|
|
343
|
+
messages: ctx.messages,
|
|
344
|
+
};
|
|
345
|
+
case "requires_user":
|
|
346
|
+
return {
|
|
347
|
+
status: "requires_user",
|
|
348
|
+
reason: decision.reason ?? "requires user",
|
|
349
|
+
continue_url: decision.continue_url ?? ctx.continue_url,
|
|
350
|
+
messages: ctx.messages,
|
|
351
|
+
};
|
|
352
|
+
case "retryable":
|
|
353
|
+
return {
|
|
354
|
+
status: "fail_closed",
|
|
355
|
+
reason: decision.reason ?? "recoverable",
|
|
356
|
+
code: "recoverable",
|
|
357
|
+
messages: ctx.messages,
|
|
358
|
+
retryable: true,
|
|
359
|
+
};
|
|
360
|
+
case "fail_closed":
|
|
361
|
+
return {
|
|
362
|
+
status: "fail_closed",
|
|
363
|
+
reason: decision.reason ?? "fail closed",
|
|
364
|
+
code: "unrecoverable",
|
|
365
|
+
messages: ctx.messages,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=cart-channel.js.map
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oBACvD,QAAQ,EAAE,GAAG,CAAC,QAAQ;iBACvB,CAAC;YACJ,KAAK,WAAW;gBACd,OAAO;oBACL,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,aAAa;oBACxC,IAAI,EAAE,aAAa;oBACnB,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,SAAS,EAAE,IAAI;iBAChB,CAAC;YACJ,KAAK,aAAa;gBAChB,OAAO;oBACL,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,aAAa;oBACxC,IAAI,EAAE,eAAe;oBACrB,QAAQ,EAAE,GAAG,CAAC,QAAQ;iBACvB,CAAC;QACN,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { UcpCart, UcpCartErrorResponse, UcpCartResponse } from "./cart-types.js";
|
|
17
|
+
/** 解析并校验 UCP cart 响应(success/error 判别走 /ucp/status)。 */
|
|
18
|
+
export declare function parseUcpCartResponse(raw: unknown): UcpCartResponse;
|
|
19
|
+
/** 判别守卫:success 响应(cart 资源本体)。 */
|
|
20
|
+
export declare function isUcpCartSuccess(value: UcpCartResponse): value is UcpCart;
|
|
21
|
+
/** 判别守卫:error 响应(无 cart 资源,只有 messages + continue_url)。 */
|
|
22
|
+
export declare function isUcpCartErrorResponse(value: UcpCartResponse): value is UcpCartErrorResponse;
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
* Kiwi v0.7.0 Transaction Handoff(WP2 补全)— UCP Cart 响应解析。
|
|
18
|
+
*
|
|
19
|
+
* 与 checkout 判别同构:`/ucp/status === success|error`。success 资源本体是
|
|
20
|
+
* `UcpCart`(cart_id 取代 session_id;无 status 生命周期);error 响应复用
|
|
21
|
+
* parse.ts 的 error envelope 解析(结构完全一致)。
|
|
22
|
+
*
|
|
23
|
+
* 结构解析全部复用 parse.ts 的子解析器(line_items / totals / messages / links)
|
|
24
|
+
* 与校验原语;任何结构问题抛 UcpCheckoutParseError(fail-closed,§4.6)。
|
|
25
|
+
*/
|
|
26
|
+
import { UcpCheckoutParseError, parseLineItems, parseLinks, parseMessages, parseTotals, parseUcpErrorEnvelope, preserveUnknown, requireIsoTimestamp, requireNonEmptyString, requireObject, } from "./parse.js";
|
|
27
|
+
function fail(path, message) {
|
|
28
|
+
throw new UcpCheckoutParseError(path, message);
|
|
29
|
+
}
|
|
30
|
+
/** 解析并校验 UCP cart 响应(success/error 判别走 /ucp/status)。 */
|
|
31
|
+
export function parseUcpCartResponse(raw) {
|
|
32
|
+
const root = requireObject(raw, "/");
|
|
33
|
+
const ucp = requireObject(root.ucp, "/ucp");
|
|
34
|
+
const version = requireNonEmptyString(ucp.version, "/ucp/version");
|
|
35
|
+
const status = ucp.status;
|
|
36
|
+
if (status !== "success" && status !== "error") {
|
|
37
|
+
fail("/ucp/status", `must be success|error (got ${String(status)})`);
|
|
38
|
+
}
|
|
39
|
+
if (status === "success") {
|
|
40
|
+
return parseSuccessCart(root, ucp, version);
|
|
41
|
+
}
|
|
42
|
+
return parseUcpErrorEnvelope(root, ucp, version);
|
|
43
|
+
}
|
|
44
|
+
function parseSuccessCart(root, ucp, version) {
|
|
45
|
+
// 缺 id 是次要指标;fail-closed:success envelope 必须带 cart_id,否则视为畸形。
|
|
46
|
+
const cart = {
|
|
47
|
+
ucp: { ...ucp, status: "success", version },
|
|
48
|
+
cart_id: requireNonEmptyString(root.cart_id, "/cart_id"),
|
|
49
|
+
};
|
|
50
|
+
const known = new Set(["ucp", "cart_id"]);
|
|
51
|
+
if (root.expires_at !== undefined) {
|
|
52
|
+
cart.expires_at = requireIsoTimestamp(root.expires_at, "/expires_at");
|
|
53
|
+
known.add("expires_at");
|
|
54
|
+
}
|
|
55
|
+
if (root.line_items !== undefined) {
|
|
56
|
+
cart.line_items = parseLineItems(root.line_items);
|
|
57
|
+
known.add("line_items");
|
|
58
|
+
}
|
|
59
|
+
if (root.totals !== undefined) {
|
|
60
|
+
cart.totals = parseTotals(root.totals);
|
|
61
|
+
known.add("totals");
|
|
62
|
+
}
|
|
63
|
+
if (root.context !== undefined) {
|
|
64
|
+
cart.context = requireObject(root.context, "/context");
|
|
65
|
+
known.add("context");
|
|
66
|
+
}
|
|
67
|
+
if (root.buyer !== undefined) {
|
|
68
|
+
cart.buyer = requireObject(root.buyer, "/buyer");
|
|
69
|
+
known.add("buyer");
|
|
70
|
+
}
|
|
71
|
+
if (root.signals !== undefined) {
|
|
72
|
+
cart.signals = requireObject(root.signals, "/signals");
|
|
73
|
+
known.add("signals");
|
|
74
|
+
}
|
|
75
|
+
if (root.attribution !== undefined) {
|
|
76
|
+
cart.attribution = requireObject(root.attribution, "/attribution");
|
|
77
|
+
known.add("attribution");
|
|
78
|
+
}
|
|
79
|
+
if (root.messages !== undefined) {
|
|
80
|
+
cart.messages = parseMessages(root.messages);
|
|
81
|
+
known.add("messages");
|
|
82
|
+
}
|
|
83
|
+
if (root.links !== undefined) {
|
|
84
|
+
cart.links = parseLinks(root.links);
|
|
85
|
+
known.add("links");
|
|
86
|
+
}
|
|
87
|
+
if (root.continue_url !== undefined) {
|
|
88
|
+
cart.continue_url = requireNonEmptyString(root.continue_url, "/continue_url");
|
|
89
|
+
known.add("continue_url");
|
|
90
|
+
}
|
|
91
|
+
preserveUnknown(root, cart, known);
|
|
92
|
+
return cart;
|
|
93
|
+
}
|
|
94
|
+
/** 判别守卫:success 响应(cart 资源本体)。 */
|
|
95
|
+
export function isUcpCartSuccess(value) {
|
|
96
|
+
return value.ucp.status === "success";
|
|
97
|
+
}
|
|
98
|
+
/** 判别守卫:error 响应(无 cart 资源,只有 messages + continue_url)。 */
|
|
99
|
+
export function isUcpCartErrorResponse(value) {
|
|
100
|
+
return value.ucp.status === "error";
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=cart-parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-parse.js","sourceRoot":"","sources":["../../../src/handoff/ucp-checkout/cart-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,aAAa,EACb,WAAW,EACX,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,SAAS,IAAI,CAAC,IAAY,EAAE,OAAe;IACzC,MAAM,IAAI,qBAAqB,CAAC,IAAI,EAAE,OA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