mppx 0.6.31 → 0.8.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/CHANGELOG.md +50 -0
- package/README.md +20 -11
- package/dist/Challenge.d.ts.map +1 -1
- package/dist/Challenge.js +27 -13
- package/dist/Challenge.js.map +1 -1
- package/dist/Constants.d.ts +46 -0
- package/dist/Constants.d.ts.map +1 -0
- package/dist/Constants.js +46 -0
- package/dist/Constants.js.map +1 -0
- package/dist/Credential.d.ts.map +1 -1
- package/dist/Credential.js +5 -4
- package/dist/Credential.js.map +1 -1
- package/dist/Mcp.d.ts +3 -0
- package/dist/Mcp.d.ts.map +1 -1
- package/dist/Mcp.js +2 -0
- package/dist/Mcp.js.map +1 -1
- package/dist/Method.d.ts +32 -4
- package/dist/Method.d.ts.map +1 -1
- package/dist/Method.js +5 -2
- package/dist/Method.js.map +1 -1
- package/dist/PaymentRequest.d.ts +10 -10
- package/dist/PaymentRequest.js +8 -8
- package/dist/Receipt.d.ts.map +1 -1
- package/dist/Receipt.js +3 -2
- package/dist/Receipt.js.map +1 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +19 -11
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/plugins/tempo.d.ts.map +1 -1
- package/dist/cli/plugins/tempo.js +17 -6
- package/dist/cli/plugins/tempo.js.map +1 -1
- package/dist/cli/utils.d.ts +5 -0
- package/dist/cli/utils.d.ts.map +1 -1
- package/dist/cli/utils.js +10 -0
- package/dist/cli/utils.js.map +1 -1
- package/dist/client/Methods.d.ts +5 -2
- package/dist/client/Methods.d.ts.map +1 -1
- package/dist/client/Methods.js +5 -2
- package/dist/client/Methods.js.map +1 -1
- package/dist/client/Mppx.js +2 -2
- package/dist/client/Mppx.js.map +1 -1
- package/dist/client/Transport.d.ts +11 -16
- package/dist/client/Transport.d.ts.map +1 -1
- package/dist/client/Transport.js +55 -76
- package/dist/client/Transport.js.map +1 -1
- package/dist/client/index.d.ts +5 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal/Fetch.d.ts.map +1 -1
- package/dist/client/internal/Fetch.js +60 -13
- package/dist/client/internal/Fetch.js.map +1 -1
- package/dist/client/internal/protocols/Mcp.d.ts +7 -0
- package/dist/client/internal/protocols/Mcp.d.ts.map +1 -0
- package/dist/client/internal/protocols/Mcp.js +159 -0
- package/dist/client/internal/protocols/Mcp.js.map +1 -0
- package/dist/client/internal/protocols/Mpp.d.ts +4 -0
- package/dist/client/internal/protocols/Mpp.d.ts.map +1 -0
- package/dist/client/internal/protocols/Mpp.js +18 -0
- package/dist/client/internal/protocols/Mpp.js.map +1 -0
- package/dist/client/internal/protocols/Protocol.d.ts +10 -0
- package/dist/client/internal/protocols/Protocol.d.ts.map +1 -0
- package/dist/client/internal/protocols/Protocol.js +2 -0
- package/dist/client/internal/protocols/Protocol.js.map +1 -0
- package/dist/client/internal/protocols/Shared.d.ts +5 -0
- package/dist/client/internal/protocols/Shared.d.ts.map +1 -0
- package/dist/client/internal/protocols/Shared.js +20 -0
- package/dist/client/internal/protocols/Shared.js.map +1 -0
- package/dist/client/internal/protocols/X402.d.ts +8 -0
- package/dist/client/internal/protocols/X402.d.ts.map +1 -0
- package/dist/client/internal/protocols/X402.js +39 -0
- package/dist/client/internal/protocols/X402.js.map +1 -0
- package/dist/evm/client/index.d.ts +1 -0
- package/dist/evm/client/index.d.ts.map +1 -1
- package/dist/evm/client/index.js +1 -0
- package/dist/evm/client/index.js.map +1 -1
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +2 -0
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/evm/server/Methods.d.ts.map +1 -1
- package/dist/evm/server/index.d.ts +1 -0
- package/dist/evm/server/index.d.ts.map +1 -1
- package/dist/evm/server/index.js +1 -0
- package/dist/evm/server/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/AcceptPayment.d.ts +3 -0
- package/dist/internal/AcceptPayment.d.ts.map +1 -1
- package/dist/internal/AcceptPayment.js +15 -11
- package/dist/internal/AcceptPayment.js.map +1 -1
- package/dist/mcp/client/McpClient.d.ts +101 -0
- package/dist/mcp/client/McpClient.d.ts.map +1 -0
- package/dist/mcp/client/McpClient.js +162 -0
- package/dist/mcp/client/McpClient.js.map +1 -0
- package/dist/mcp/client/index.d.ts.map +1 -0
- package/dist/mcp/client/index.js.map +1 -0
- package/dist/mcp/server/Transport.d.ts.map +1 -0
- package/dist/mcp/server/Transport.js.map +1 -0
- package/dist/mcp/server/index.d.ts.map +1 -0
- package/dist/mcp/server/index.js.map +1 -0
- package/dist/server/Mppx.d.ts +12 -4
- package/dist/server/Mppx.d.ts.map +1 -1
- package/dist/server/Mppx.js +85 -27
- package/dist/server/Mppx.js.map +1 -1
- package/dist/server/Response.d.ts.map +1 -1
- package/dist/server/Response.js +2 -1
- package/dist/server/Response.js.map +1 -1
- package/dist/server/Transport.d.ts +1 -1
- package/dist/server/Transport.d.ts.map +1 -1
- package/dist/server/Transport.js +5 -4
- package/dist/server/Transport.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/stripe/client/Charge.d.ts +1 -1
- package/dist/stripe/client/Charge.d.ts.map +1 -1
- package/dist/stripe/client/Charge.js +3 -1
- package/dist/stripe/client/Charge.js.map +1 -1
- package/dist/stripe/server/Charge.d.ts +1 -1
- package/dist/stripe/server/Charge.d.ts.map +1 -1
- package/dist/stripe/server/Charge.js +9 -2
- package/dist/stripe/server/Charge.js.map +1 -1
- package/dist/stripe/server/Methods.d.ts +1 -1
- package/dist/stripe/server/Methods.d.ts.map +1 -1
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.d.ts.map +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/stripe/server/internal/html.gen.js.map +1 -1
- package/dist/tempo/Methods.d.ts +18 -0
- package/dist/tempo/Methods.d.ts.map +1 -1
- package/dist/tempo/Methods.js +16 -1
- package/dist/tempo/Methods.js.map +1 -1
- package/dist/tempo/Proof.d.ts +85 -1
- package/dist/tempo/Proof.d.ts.map +1 -1
- package/dist/tempo/Proof.js +35 -0
- package/dist/tempo/Proof.js.map +1 -1
- package/dist/tempo/client/Charge.d.ts +19 -1
- package/dist/tempo/client/Charge.d.ts.map +1 -1
- package/dist/tempo/client/Charge.js +47 -27
- package/dist/tempo/client/Charge.js.map +1 -1
- package/dist/tempo/client/Methods.d.ts +41 -10
- package/dist/tempo/client/Methods.d.ts.map +1 -1
- package/dist/tempo/client/Methods.js +16 -7
- package/dist/tempo/client/Methods.js.map +1 -1
- package/dist/tempo/client/ResolveAccount.d.ts +40 -0
- package/dist/tempo/client/ResolveAccount.d.ts.map +1 -0
- package/dist/tempo/client/ResolveAccount.js +2 -0
- package/dist/tempo/client/ResolveAccount.js.map +1 -0
- package/dist/tempo/client/index.d.ts +7 -4
- package/dist/tempo/client/index.d.ts.map +1 -1
- package/dist/tempo/client/index.js +5 -3
- package/dist/tempo/client/index.js.map +1 -1
- package/dist/tempo/index.d.ts +1 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +1 -0
- package/dist/tempo/index.js.map +1 -1
- package/dist/tempo/internal/fee-payer.d.ts +29 -1
- package/dist/tempo/internal/fee-payer.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.js +138 -4
- package/dist/tempo/internal/fee-payer.js.map +1 -1
- package/dist/tempo/internal/proof.d.ts +71 -5
- package/dist/tempo/internal/proof.d.ts.map +1 -1
- package/dist/tempo/internal/proof.js +42 -6
- package/dist/tempo/internal/proof.js.map +1 -1
- package/dist/tempo/{client → legacy/client}/ChannelOps.d.ts +19 -6
- package/dist/tempo/legacy/client/ChannelOps.d.ts.map +1 -0
- package/dist/tempo/{client → legacy/client}/ChannelOps.js +9 -3
- package/dist/tempo/legacy/client/ChannelOps.js.map +1 -0
- package/dist/tempo/{client → legacy/client}/Session.d.ts +23 -4
- package/dist/tempo/legacy/client/Session.d.ts.map +1 -0
- package/dist/tempo/{client → legacy/client}/Session.js +14 -7
- package/dist/tempo/legacy/client/Session.js.map +1 -0
- package/dist/tempo/{client → legacy/client}/SessionManager.d.ts +20 -5
- package/dist/tempo/legacy/client/SessionManager.d.ts.map +1 -0
- package/dist/tempo/{client → legacy/client}/SessionManager.js +30 -19
- package/dist/tempo/legacy/client/SessionManager.js.map +1 -0
- package/dist/tempo/legacy/client/index.d.ts +7 -0
- package/dist/tempo/legacy/client/index.d.ts.map +1 -0
- package/dist/tempo/legacy/client/index.js +5 -0
- package/dist/tempo/legacy/client/index.js.map +1 -0
- package/dist/tempo/legacy/index.d.ts +7 -0
- package/dist/tempo/legacy/index.d.ts.map +1 -0
- package/dist/tempo/legacy/index.js +7 -0
- package/dist/tempo/legacy/index.js.map +1 -0
- package/dist/tempo/{server → legacy/server}/Session.d.ts +28 -11
- package/dist/tempo/legacy/server/Session.d.ts.map +1 -0
- package/dist/tempo/{server → legacy/server}/Session.js +12 -10
- package/dist/tempo/legacy/server/Session.js.map +1 -0
- package/dist/tempo/legacy/server/index.d.ts +5 -0
- package/dist/tempo/legacy/server/index.d.ts.map +1 -0
- package/dist/tempo/legacy/server/index.js +5 -0
- package/dist/tempo/legacy/server/index.js.map +1 -0
- package/dist/tempo/{session → legacy/session}/Chain.d.ts +30 -23
- package/dist/tempo/legacy/session/Chain.d.ts.map +1 -0
- package/dist/tempo/{session → legacy/session}/Chain.js +12 -11
- package/dist/tempo/legacy/session/Chain.js.map +1 -0
- package/dist/tempo/{session → legacy/session}/Channel.d.ts +1 -0
- package/dist/tempo/legacy/session/Channel.d.ts.map +1 -0
- package/dist/tempo/legacy/session/Channel.js.map +1 -0
- package/dist/tempo/legacy/session/ChannelStore.d.ts +22 -0
- package/dist/tempo/legacy/session/ChannelStore.d.ts.map +1 -0
- package/dist/tempo/legacy/session/ChannelStore.js +6 -0
- package/dist/tempo/legacy/session/ChannelStore.js.map +1 -0
- package/dist/tempo/legacy/session/Types.d.ts +73 -0
- package/dist/tempo/legacy/session/Types.d.ts.map +1 -0
- package/dist/tempo/legacy/session/Types.js.map +1 -0
- package/dist/tempo/{session → legacy/session}/Voucher.d.ts +4 -4
- package/dist/tempo/legacy/session/Voucher.d.ts.map +1 -0
- package/dist/tempo/{session → legacy/session}/Voucher.js +1 -1
- package/dist/tempo/legacy/session/Voucher.js.map +1 -0
- package/dist/tempo/{session → legacy/session}/escrow.abi.d.ts +1 -0
- package/dist/tempo/{session → legacy/session}/escrow.abi.d.ts.map +1 -1
- package/dist/tempo/{session → legacy/session}/escrow.abi.js +1 -0
- package/dist/tempo/legacy/session/escrow.abi.js.map +1 -0
- package/dist/tempo/legacy/session/index.d.ts +9 -0
- package/dist/tempo/legacy/session/index.d.ts.map +1 -0
- package/dist/tempo/legacy/session/index.js +9 -0
- package/dist/tempo/legacy/session/index.js.map +1 -0
- package/dist/tempo/server/Charge.d.ts +1 -1
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +51 -30
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/Methods.d.ts +67 -8
- package/dist/tempo/server/Methods.d.ts.map +1 -1
- package/dist/tempo/server/Methods.js +40 -10
- package/dist/tempo/server/Methods.js.map +1 -1
- package/dist/tempo/server/Subscription.d.ts +11 -1
- package/dist/tempo/server/Subscription.d.ts.map +1 -1
- package/dist/tempo/server/Subscription.js +135 -23
- package/dist/tempo/server/Subscription.js.map +1 -1
- package/dist/tempo/server/index.d.ts +6 -5
- package/dist/tempo/server/index.d.ts.map +1 -1
- package/dist/tempo/server/index.js +5 -5
- package/dist/tempo/server/index.js.map +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/html.gen.js.map +1 -1
- package/dist/tempo/server/internal/request-body.d.ts +7 -2
- package/dist/tempo/server/internal/request-body.d.ts.map +1 -1
- package/dist/tempo/server/internal/request-body.js +20 -3
- package/dist/tempo/server/internal/request-body.js.map +1 -1
- package/dist/tempo/server/internal/transport.d.ts +8 -4
- package/dist/tempo/server/internal/transport.d.ts.map +1 -1
- package/dist/tempo/server/internal/transport.js +8 -7
- package/dist/tempo/server/internal/transport.js.map +1 -1
- package/dist/tempo/session/Snapshot.d.ts +32 -0
- package/dist/tempo/session/Snapshot.d.ts.map +1 -0
- package/dist/tempo/session/Snapshot.js +37 -0
- package/dist/tempo/session/Snapshot.js.map +1 -0
- package/dist/tempo/session/client/ChannelOps.d.ts +81 -0
- package/dist/tempo/session/client/ChannelOps.d.ts.map +1 -0
- package/dist/tempo/session/client/ChannelOps.js +201 -0
- package/dist/tempo/session/client/ChannelOps.js.map +1 -0
- package/dist/tempo/session/client/ChannelStore.d.ts +51 -0
- package/dist/tempo/session/client/ChannelStore.d.ts.map +1 -0
- package/dist/tempo/session/client/ChannelStore.js +63 -0
- package/dist/tempo/session/client/ChannelStore.js.map +1 -0
- package/dist/tempo/session/client/CredentialState.d.ts +245 -0
- package/dist/tempo/session/client/CredentialState.d.ts.map +1 -0
- package/dist/tempo/session/client/CredentialState.js +419 -0
- package/dist/tempo/session/client/CredentialState.js.map +1 -0
- package/dist/tempo/session/client/ReceiptCoordinator.d.ts +26 -0
- package/dist/tempo/session/client/ReceiptCoordinator.d.ts.map +1 -0
- package/dist/tempo/session/client/ReceiptCoordinator.js +61 -0
- package/dist/tempo/session/client/ReceiptCoordinator.js.map +1 -0
- package/dist/tempo/session/client/Runtime.d.ts +464 -0
- package/dist/tempo/session/client/Runtime.d.ts.map +1 -0
- package/dist/tempo/session/client/Runtime.js +499 -0
- package/dist/tempo/session/client/Runtime.js.map +1 -0
- package/dist/tempo/session/client/Session.d.ts +138 -0
- package/dist/tempo/session/client/Session.d.ts.map +1 -0
- package/dist/tempo/session/client/Session.js +69 -0
- package/dist/tempo/session/client/Session.js.map +1 -0
- package/dist/tempo/session/client/SessionManager.d.ts +84 -0
- package/dist/tempo/session/client/SessionManager.d.ts.map +1 -0
- package/dist/tempo/session/client/SessionManager.js +577 -0
- package/dist/tempo/session/client/SessionManager.js.map +1 -0
- package/dist/tempo/session/client/Transports.d.ts +449 -0
- package/dist/tempo/session/client/Transports.d.ts.map +1 -0
- package/dist/tempo/session/client/Transports.js +721 -0
- package/dist/tempo/session/client/Transports.js.map +1 -0
- package/dist/tempo/session/client/index.d.ts +11 -0
- package/dist/tempo/session/client/index.d.ts.map +1 -0
- package/dist/tempo/session/client/index.js +6 -0
- package/dist/tempo/session/client/index.js.map +1 -0
- package/dist/tempo/session/index.d.ts +7 -8
- package/dist/tempo/session/index.d.ts.map +1 -1
- package/dist/tempo/session/index.js +7 -8
- package/dist/tempo/session/index.js.map +1 -1
- package/dist/tempo/session/precompile/Chain.d.ts +319 -0
- package/dist/tempo/session/precompile/Chain.d.ts.map +1 -0
- package/dist/tempo/session/precompile/Chain.js +492 -0
- package/dist/tempo/session/precompile/Chain.js.map +1 -0
- package/dist/tempo/session/precompile/Channel.d.ts +46 -0
- package/dist/tempo/session/precompile/Channel.d.ts.map +1 -0
- package/dist/tempo/session/precompile/Channel.js +56 -0
- package/dist/tempo/session/precompile/Channel.js.map +1 -0
- package/dist/tempo/session/precompile/Protocol.d.ts +308 -0
- package/dist/tempo/session/precompile/Protocol.d.ts.map +1 -0
- package/dist/tempo/session/precompile/Protocol.js +264 -0
- package/dist/tempo/session/precompile/Protocol.js.map +1 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +40 -0
- package/dist/tempo/session/precompile/Voucher.d.ts.map +1 -0
- package/dist/tempo/session/precompile/Voucher.js +125 -0
- package/dist/tempo/session/precompile/Voucher.js.map +1 -0
- package/dist/tempo/session/precompile/escrow.abi.d.ts +522 -0
- package/dist/tempo/session/precompile/escrow.abi.d.ts.map +1 -0
- package/dist/tempo/session/precompile/escrow.abi.js +224 -0
- package/dist/tempo/session/precompile/escrow.abi.js.map +1 -0
- package/dist/tempo/session/precompile/index.d.ts +24 -0
- package/dist/tempo/session/precompile/index.d.ts.map +1 -0
- package/dist/tempo/session/precompile/index.js +22 -0
- package/dist/tempo/session/precompile/index.js.map +1 -0
- package/dist/tempo/session/server/ChannelOps.d.ts +56 -0
- package/dist/tempo/session/server/ChannelOps.d.ts.map +1 -0
- package/dist/tempo/session/server/ChannelOps.js +91 -0
- package/dist/tempo/session/server/ChannelOps.js.map +1 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +347 -0
- package/dist/tempo/session/server/ChannelStore.d.ts.map +1 -0
- package/dist/tempo/session/server/ChannelStore.js +404 -0
- package/dist/tempo/session/server/ChannelStore.js.map +1 -0
- package/dist/tempo/session/server/CredentialVerification.d.ts +85 -0
- package/dist/tempo/session/server/CredentialVerification.d.ts.map +1 -0
- package/dist/tempo/session/server/CredentialVerification.js +494 -0
- package/dist/tempo/session/server/CredentialVerification.js.map +1 -0
- package/dist/tempo/session/server/MeteredStream.d.ts +40 -0
- package/dist/tempo/session/server/MeteredStream.d.ts.map +1 -0
- package/dist/tempo/session/server/MeteredStream.js +42 -0
- package/dist/tempo/session/server/MeteredStream.js.map +1 -0
- package/dist/tempo/session/server/RequestState.d.ts +208 -0
- package/dist/tempo/session/server/RequestState.d.ts.map +1 -0
- package/dist/tempo/session/server/RequestState.js +252 -0
- package/dist/tempo/session/server/RequestState.js.map +1 -0
- package/dist/tempo/session/server/Session.d.ts +169 -0
- package/dist/tempo/session/server/Session.d.ts.map +1 -0
- package/dist/tempo/session/server/Session.js +351 -0
- package/dist/tempo/session/server/Session.js.map +1 -0
- package/dist/tempo/session/server/Settlement.d.ts +185 -0
- package/dist/tempo/session/server/Settlement.d.ts.map +1 -0
- package/dist/tempo/session/server/Settlement.js +252 -0
- package/dist/tempo/session/server/Settlement.js.map +1 -0
- package/dist/tempo/session/{Sse.d.ts → server/Sse.d.ts} +9 -56
- package/dist/tempo/session/server/Sse.d.ts.map +1 -0
- package/dist/tempo/session/server/Sse.js +184 -0
- package/dist/tempo/session/server/Sse.js.map +1 -0
- package/dist/tempo/session/server/Transports.d.ts +89 -0
- package/dist/tempo/session/server/Transports.d.ts.map +1 -0
- package/dist/tempo/session/server/Transports.js +149 -0
- package/dist/tempo/session/server/Transports.js.map +1 -0
- package/dist/tempo/session/server/Ws.d.ts +48 -0
- package/dist/tempo/session/server/Ws.d.ts.map +1 -0
- package/dist/tempo/session/server/Ws.js +244 -0
- package/dist/tempo/session/server/Ws.js.map +1 -0
- package/dist/tempo/session/server/index.d.ts +4 -0
- package/dist/tempo/session/server/index.d.ts.map +1 -0
- package/dist/tempo/session/server/index.js +2 -0
- package/dist/tempo/session/server/index.js.map +1 -0
- package/dist/tempo/subscription/KeyAuthorization.d.ts +712 -1
- package/dist/tempo/subscription/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/subscription/Store.d.ts +2 -0
- package/dist/tempo/subscription/Store.d.ts.map +1 -1
- package/dist/tempo/subscription/Store.js +16 -1
- package/dist/tempo/subscription/Store.js.map +1 -1
- package/dist/x402/index.d.ts +1 -0
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +1 -0
- package/dist/x402/index.js.map +1 -1
- package/package.json +25 -9
- package/src/Challenge.test.ts +40 -0
- package/src/Challenge.ts +28 -13
- package/src/Constants.ts +58 -0
- package/src/Credential.ts +5 -4
- package/src/Mcp.ts +4 -0
- package/src/Method.ts +46 -5
- package/src/PaymentRequest.ts +10 -10
- package/src/Receipt.ts +3 -2
- package/src/cli/cli.test.ts +38 -43
- package/src/cli/cli.ts +23 -10
- package/src/cli/mcp.test.ts +21 -7
- package/src/cli/plugins/tempo.ts +21 -8
- package/src/cli/utils.test.ts +25 -1
- package/src/cli/utils.ts +10 -0
- package/src/client/Methods.ts +5 -2
- package/src/client/Mppx.test-d.ts +31 -1
- package/src/client/Mppx.test.ts +76 -1
- package/src/client/Mppx.ts +2 -2
- package/src/client/Transport.test.ts +225 -178
- package/src/client/Transport.ts +77 -84
- package/src/client/index.ts +25 -1
- package/src/client/internal/Fetch.test.ts +236 -6
- package/src/client/internal/Fetch.ts +69 -11
- package/src/client/internal/protocols/Mcp.test.ts +220 -0
- package/src/client/internal/protocols/Mcp.ts +162 -0
- package/src/client/internal/protocols/Mpp.ts +21 -0
- package/src/client/internal/protocols/Protocol.ts +10 -0
- package/src/client/internal/protocols/Shared.ts +25 -0
- package/src/client/internal/protocols/X402.ts +42 -0
- package/src/discovery/OpenApi.test.ts +1 -1
- package/src/env.d.ts +1 -1
- package/src/evm/PublicInterface.test-d.ts +1 -1
- package/src/evm/client/index.ts +1 -0
- package/src/evm/index.ts +2 -0
- package/src/evm/server/Charge.test.ts +1 -1
- package/src/evm/server/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/internal/AcceptPayment.test.ts +61 -0
- package/src/internal/AcceptPayment.ts +21 -14
- package/src/{mcp-sdk → mcp}/client/McpClient.integration.test.ts +18 -11
- package/src/{mcp-sdk → mcp}/client/McpClient.test-d.ts +45 -11
- package/src/{mcp-sdk → mcp}/client/McpClient.test.ts +211 -5
- package/src/mcp/client/McpClient.ts +307 -0
- package/src/mcp/client/McpClient.unit.test.ts +135 -0
- package/src/middlewares/elysia.test.ts +9 -5
- package/src/middlewares/express.test.ts +9 -5
- package/src/middlewares/hono.test.ts +5 -5
- package/src/middlewares/internal/mppx.test.ts +1 -1
- package/src/middlewares/nextjs.test.ts +9 -5
- package/src/proxy/Proxy.test.ts +9 -9
- package/src/proxy/services/anthropic.test.ts +1 -1
- package/src/proxy/services/openai.test.ts +1 -1
- package/src/proxy/services/stripe.test.ts +1 -1
- package/src/server/Mppx.authorize.test.ts +1 -1
- package/src/server/Mppx.test-d.ts +55 -1
- package/src/server/Mppx.test.ts +220 -9
- package/src/server/Mppx.ts +501 -407
- package/src/server/Response.ts +2 -1
- package/src/server/Transport.test.ts +6 -6
- package/src/server/Transport.ts +5 -4
- package/src/server/index.ts +1 -0
- package/src/stripe/Charge.integration.test.ts +1 -1
- package/src/stripe/client/Charge.test.ts +21 -6
- package/src/stripe/client/Charge.ts +6 -2
- package/src/stripe/server/Charge.test.ts +115 -2
- package/src/stripe/server/Charge.ts +13 -2
- package/src/stripe/server/internal/html/package.json +1 -1
- package/src/stripe/server/internal/html.gen.ts +1 -1
- package/src/tempo/AccessKeyAuthorization.test.ts +4 -94
- package/src/tempo/Methods.test.ts +45 -17
- package/src/tempo/Methods.ts +22 -0
- package/src/tempo/Proof.conformance.test.ts +146 -0
- package/src/tempo/Proof.test-d.ts +15 -0
- package/src/tempo/Proof.ts +52 -1
- package/src/tempo/PublicExports.test-d.ts +105 -0
- package/src/tempo/Subscription.integration.test.ts +1 -1
- package/src/tempo/client/Charge.test.ts +258 -0
- package/src/tempo/client/Charge.ts +84 -38
- package/src/tempo/client/Methods.ts +22 -8
- package/src/tempo/client/ResolveAccount.ts +46 -0
- package/src/tempo/client/index.ts +15 -4
- package/src/tempo/index.ts +1 -0
- package/src/tempo/internal/fee-payer.test.ts +296 -17
- package/src/tempo/internal/fee-payer.ts +186 -4
- package/src/tempo/internal/fee-token.test.ts +14 -9
- package/src/tempo/internal/proof.test.ts +12 -4
- package/src/tempo/internal/proof.ts +55 -6
- package/src/tempo/legacy/AccessKeyAuthorization.test.ts +162 -0
- package/src/tempo/legacy/README.md +9 -0
- package/src/tempo/{client → legacy/client}/ChannelOps.test.ts +6 -7
- package/src/tempo/{client → legacy/client}/ChannelOps.ts +22 -9
- package/src/tempo/{client → legacy/client}/Session.test.ts +51 -9
- package/src/tempo/{client → legacy/client}/Session.ts +25 -11
- package/src/tempo/{client → legacy/client}/SessionManager.test.ts +81 -9
- package/src/tempo/{client → legacy/client}/SessionManager.ts +52 -23
- package/src/tempo/legacy/client/index.ts +6 -0
- package/src/tempo/legacy/index.ts +6 -0
- package/src/tempo/{server → legacy/server}/Session.test.ts +136 -71
- package/src/tempo/{server → legacy/server}/Session.ts +32 -23
- package/src/tempo/legacy/server/index.ts +4 -0
- package/src/tempo/{session → legacy/session}/Chain.test.ts +3 -4
- package/src/tempo/{session → legacy/session}/Chain.ts +94 -63
- package/src/tempo/{session → legacy/session}/Channel.ts +1 -0
- package/src/tempo/legacy/session/ChannelStore.test.ts +58 -0
- package/src/tempo/legacy/session/ChannelStore.ts +39 -0
- package/src/tempo/legacy/session/Types.ts +91 -0
- package/src/tempo/{session → legacy/session}/Voucher.ts +12 -8
- package/src/tempo/{session → legacy/session}/escrow.abi.ts +1 -0
- package/src/tempo/legacy/session/index.ts +8 -0
- package/src/tempo/server/AtomicStore.test-d.ts +16 -11
- package/src/tempo/server/Charge.test.ts +480 -31
- package/src/tempo/server/Charge.ts +54 -30
- package/src/tempo/server/Methods.ts +58 -10
- package/src/tempo/server/Sse.test.ts +2 -2
- package/src/tempo/server/Subscription.test.ts +465 -3
- package/src/tempo/server/Subscription.ts +174 -19
- package/src/tempo/server/index.ts +6 -5
- package/src/tempo/server/internal/html/package.json +2 -2
- package/src/tempo/server/internal/html.gen.ts +1 -1
- package/src/tempo/server/internal/request-body.test.ts +37 -4
- package/src/tempo/server/internal/request-body.ts +25 -6
- package/src/tempo/server/internal/transport.test.ts +4 -4
- package/src/tempo/server/internal/transport.ts +19 -10
- package/src/tempo/session/Snapshot.test.ts +41 -0
- package/src/tempo/session/Snapshot.ts +74 -0
- package/src/tempo/session/client/ChannelOps.test.ts +163 -0
- package/src/tempo/session/client/ChannelOps.ts +330 -0
- package/src/tempo/session/client/ChannelStore.ts +111 -0
- package/src/tempo/session/client/CredentialState.test.ts +789 -0
- package/src/tempo/session/client/CredentialState.ts +799 -0
- package/src/tempo/session/client/ReceiptCoordinator.ts +95 -0
- package/src/tempo/session/client/Runtime.test.ts +1092 -0
- package/src/tempo/session/client/Runtime.ts +986 -0
- package/src/tempo/session/client/Session.test.ts +774 -0
- package/src/tempo/session/client/Session.ts +123 -0
- package/src/tempo/session/client/SessionManager.test.ts +1397 -0
- package/src/tempo/session/client/SessionManager.ts +751 -0
- package/src/tempo/session/client/Transports.test.ts +837 -0
- package/src/tempo/session/client/Transports.ts +1292 -0
- package/src/tempo/session/client/index.ts +40 -0
- package/src/tempo/session/index.ts +7 -8
- package/src/tempo/session/precompile/Chain.integration.test.ts +321 -0
- package/src/tempo/session/precompile/Chain.test.ts +1258 -0
- package/src/tempo/session/precompile/Chain.ts +979 -0
- package/src/tempo/session/precompile/Channel.test.ts +138 -0
- package/src/tempo/session/precompile/Channel.ts +103 -0
- package/src/tempo/session/precompile/Protocol.test.ts +358 -0
- package/src/tempo/session/precompile/Protocol.ts +520 -0
- package/src/tempo/session/precompile/Voucher.test.ts +354 -0
- package/src/tempo/session/precompile/Voucher.ts +162 -0
- package/src/tempo/session/precompile/escrow.abi.ts +226 -0
- package/src/tempo/session/precompile/index.ts +33 -0
- package/src/tempo/session/server/ChannelOps.test.ts +129 -0
- package/src/tempo/session/server/ChannelOps.ts +157 -0
- package/src/tempo/session/{ChannelStore.test.ts → server/ChannelStore.test.ts} +536 -29
- package/src/tempo/session/server/ChannelStore.ts +835 -0
- package/src/tempo/session/server/CredentialVerification.test.ts +146 -0
- package/src/tempo/session/server/CredentialVerification.ts +710 -0
- package/src/tempo/session/server/MeteredStream.ts +88 -0
- package/src/tempo/session/server/RequestState.test.ts +531 -0
- package/src/tempo/session/server/RequestState.ts +499 -0
- package/src/tempo/session/server/Session.integration.test.ts +444 -0
- package/src/tempo/session/server/Session.test.ts +3253 -0
- package/src/tempo/session/server/Session.ts +543 -0
- package/src/tempo/session/server/Settlement.test.ts +329 -0
- package/src/tempo/session/server/Settlement.ts +471 -0
- package/src/tempo/session/{Sse.test.ts → server/Sse.test.ts} +37 -3
- package/src/tempo/session/server/Sse.ts +254 -0
- package/src/tempo/session/server/Transports.test.ts +346 -0
- package/src/tempo/session/server/Transports.ts +255 -0
- package/src/tempo/session/{Ws.test.ts → server/Ws.test.ts} +4 -4
- package/src/tempo/session/server/Ws.ts +380 -0
- package/src/tempo/session/server/index.ts +8 -0
- package/src/tempo/subscription/Store.ts +27 -9
- package/src/x402/Exact.e2e.test.ts +1 -1
- package/src/x402/PublicInterface.test-d.ts +1 -1
- package/src/x402/index.ts +1 -0
- package/dist/mcp-sdk/client/McpClient.d.ts +0 -78
- package/dist/mcp-sdk/client/McpClient.d.ts.map +0 -1
- package/dist/mcp-sdk/client/McpClient.js +0 -105
- package/dist/mcp-sdk/client/McpClient.js.map +0 -1
- package/dist/mcp-sdk/client/index.d.ts.map +0 -1
- package/dist/mcp-sdk/client/index.js.map +0 -1
- package/dist/mcp-sdk/server/Transport.d.ts.map +0 -1
- package/dist/mcp-sdk/server/Transport.js.map +0 -1
- package/dist/mcp-sdk/server/index.d.ts.map +0 -1
- package/dist/mcp-sdk/server/index.js.map +0 -1
- package/dist/tempo/client/ChannelOps.d.ts.map +0 -1
- package/dist/tempo/client/ChannelOps.js.map +0 -1
- package/dist/tempo/client/Session.d.ts.map +0 -1
- package/dist/tempo/client/Session.js.map +0 -1
- package/dist/tempo/client/SessionManager.d.ts.map +0 -1
- package/dist/tempo/client/SessionManager.js.map +0 -1
- package/dist/tempo/server/Session.d.ts.map +0 -1
- package/dist/tempo/server/Session.js.map +0 -1
- package/dist/tempo/session/Chain.d.ts.map +0 -1
- package/dist/tempo/session/Chain.js.map +0 -1
- package/dist/tempo/session/Channel.d.ts.map +0 -1
- package/dist/tempo/session/Channel.js.map +0 -1
- package/dist/tempo/session/ChannelStore.d.ts +0 -117
- package/dist/tempo/session/ChannelStore.d.ts.map +0 -1
- package/dist/tempo/session/ChannelStore.js +0 -172
- package/dist/tempo/session/ChannelStore.js.map +0 -1
- package/dist/tempo/session/Receipt.d.ts +0 -22
- package/dist/tempo/session/Receipt.d.ts.map +0 -1
- package/dist/tempo/session/Receipt.js +0 -34
- package/dist/tempo/session/Receipt.js.map +0 -1
- package/dist/tempo/session/Sse.d.ts.map +0 -1
- package/dist/tempo/session/Sse.js +0 -363
- package/dist/tempo/session/Sse.js.map +0 -1
- package/dist/tempo/session/Types.d.ts +0 -78
- package/dist/tempo/session/Types.d.ts.map +0 -1
- package/dist/tempo/session/Types.js.map +0 -1
- package/dist/tempo/session/Voucher.d.ts.map +0 -1
- package/dist/tempo/session/Voucher.js.map +0 -1
- package/dist/tempo/session/Ws.d.ts +0 -87
- package/dist/tempo/session/Ws.d.ts.map +0 -1
- package/dist/tempo/session/Ws.js +0 -443
- package/dist/tempo/session/Ws.js.map +0 -1
- package/dist/tempo/session/escrow.abi.js.map +0 -1
- package/src/mcp-sdk/client/McpClient.ts +0 -196
- package/src/tempo/session/ChannelStore.ts +0 -308
- package/src/tempo/session/Receipt.test.ts +0 -89
- package/src/tempo/session/Receipt.ts +0 -46
- package/src/tempo/session/Sse.ts +0 -462
- package/src/tempo/session/Types.ts +0 -86
- package/src/tempo/session/Ws.ts +0 -576
- /package/dist/{mcp-sdk → mcp}/client/index.d.ts +0 -0
- /package/dist/{mcp-sdk → mcp}/client/index.js +0 -0
- /package/dist/{mcp-sdk → mcp}/server/Transport.d.ts +0 -0
- /package/dist/{mcp-sdk → mcp}/server/Transport.js +0 -0
- /package/dist/{mcp-sdk → mcp}/server/index.d.ts +0 -0
- /package/dist/{mcp-sdk → mcp}/server/index.js +0 -0
- /package/dist/tempo/{session → legacy/session}/Channel.js +0 -0
- /package/dist/tempo/{session → legacy/session}/Types.js +0 -0
- /package/src/{mcp-sdk → mcp}/client/index.ts +0 -0
- /package/src/{mcp-sdk → mcp}/server/Transport.test.ts +0 -0
- /package/src/{mcp-sdk → mcp}/server/Transport.ts +0 -0
- /package/src/{mcp-sdk → mcp}/server/index.ts +0 -0
- /package/src/tempo/{session → legacy/session}/Channel.test.ts +0 -0
- /package/src/tempo/{session → legacy/session}/Voucher.test.ts +0 -0
- /package/src/tempo/session/{Sse.fuzz.test.ts → server/Sse.fuzz.test.ts} +0 -0
package/src/client/Transport.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import * as Challenge from '../Challenge.js'
|
|
2
2
|
import * as Credential from '../Credential.js'
|
|
3
3
|
import * as Mcp from '../Mcp.js'
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const paymentAuthChallengeHeader = 'WWW-Authenticate'
|
|
10
|
-
const paymentAuthCredentialHeader = 'Authorization'
|
|
11
|
-
const credentialHeaders = [
|
|
12
|
-
paymentAuthCredentialHeader,
|
|
13
|
-
x402_Types.paymentRequiredHeader,
|
|
14
|
-
x402_Types.paymentResponseHeader,
|
|
15
|
-
x402_Types.paymentSignatureHeader,
|
|
16
|
-
]
|
|
4
|
+
import { mcp as mcpProtocol } from './internal/protocols/Mcp.js'
|
|
5
|
+
import { mpp as mppProtocol } from './internal/protocols/Mpp.js'
|
|
6
|
+
import type { Protocol } from './internal/protocols/Protocol.js'
|
|
7
|
+
import { paymentRequiredStatus } from './internal/protocols/Shared.js'
|
|
8
|
+
import { x402 as x402Protocol } from './internal/protocols/X402.js'
|
|
17
9
|
|
|
18
10
|
/**
|
|
19
11
|
* Client-side transport adapter.
|
|
@@ -24,12 +16,21 @@ const credentialHeaders = [
|
|
|
24
16
|
export type Transport<in out request = unknown, in out response = unknown> = {
|
|
25
17
|
/** Transport name for identification. */
|
|
26
18
|
name: string
|
|
27
|
-
/**
|
|
28
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a response indicates payment is required. May inspect the request (to gate
|
|
21
|
+
* body reads) and be async (to read a response body).
|
|
22
|
+
*/
|
|
23
|
+
isPaymentRequired: (response: response, request?: request) => boolean | Promise<boolean>
|
|
29
24
|
/** Extracts all challenges from a payment-required response, when the transport supports multiple offers. */
|
|
30
|
-
getChallenges?: (
|
|
25
|
+
getChallenges?: (
|
|
26
|
+
response: response,
|
|
27
|
+
request?: request,
|
|
28
|
+
) => Challenge.Challenge[] | Promise<Challenge.Challenge[]>
|
|
31
29
|
/** Extracts the challenge from a payment-required response. */
|
|
32
|
-
getChallenge: (
|
|
30
|
+
getChallenge: (
|
|
31
|
+
response: response,
|
|
32
|
+
request?: request,
|
|
33
|
+
) => Challenge.Challenge | Promise<Challenge.Challenge>
|
|
33
34
|
/** Attaches a credential to a request. */
|
|
34
35
|
setCredential: (
|
|
35
36
|
request: request,
|
|
@@ -75,87 +76,79 @@ export function from<request, response>(
|
|
|
75
76
|
return transport
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
/** HTTP transport that composes payment protocols while keeping `fetch` as the single boundary. */
|
|
80
|
+
export function http(): Transport<RequestInit, Response> {
|
|
81
|
+
const protocols: readonly Protocol[] = [mppProtocol(), x402Protocol(), mcpProtocol()]
|
|
82
|
+
const protocolForChallenge = new WeakMap<Challenge.Challenge, Protocol>()
|
|
83
|
+
|
|
84
|
+
const remember = (protocol: Protocol, challenges: Challenge.Challenge[]) => {
|
|
85
|
+
for (const challenge of challenges) protocolForChallenge.set(challenge, protocol)
|
|
86
|
+
return challenges
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Collect every protocol offer. Header-only 402 paths stay synchronous; MCP returns a promise
|
|
90
|
+
// only when it has to inspect a JSON-RPC/SSE body.
|
|
91
|
+
const collect = (
|
|
92
|
+
response: Response,
|
|
93
|
+
request?: RequestInit,
|
|
94
|
+
): Challenge.Challenge[] | Promise<Challenge.Challenge[]> => {
|
|
95
|
+
const collectFrom = (
|
|
96
|
+
index: number,
|
|
97
|
+
collected: Challenge.Challenge[],
|
|
98
|
+
): Challenge.Challenge[] | Promise<Challenge.Challenge[]> => {
|
|
99
|
+
for (let i = index; i < protocols.length; i++) {
|
|
100
|
+
const protocol = protocols[i]!
|
|
101
|
+
const challenges = protocol.getChallenges(response, request)
|
|
102
|
+
if (challenges instanceof Promise)
|
|
103
|
+
return challenges.then((list) =>
|
|
104
|
+
collectFrom(i + 1, [...collected, ...remember(protocol, list)]),
|
|
105
|
+
)
|
|
106
|
+
collected.push(...remember(protocol, challenges))
|
|
107
|
+
}
|
|
108
|
+
return collected
|
|
109
|
+
}
|
|
110
|
+
return collectFrom(0, [])
|
|
111
|
+
}
|
|
112
|
+
|
|
87
113
|
return from<RequestInit, Response>({
|
|
88
114
|
name: 'http',
|
|
89
115
|
|
|
90
|
-
isPaymentRequired(response) {
|
|
91
|
-
|
|
116
|
+
isPaymentRequired(response, request) {
|
|
117
|
+
if (response.status === paymentRequiredStatus) return true // HTTP 402 — sync fast path
|
|
118
|
+
const challenges = collect(response, request)
|
|
119
|
+
return challenges instanceof Promise
|
|
120
|
+
? challenges.then((list) => list.length > 0)
|
|
121
|
+
: challenges.length > 0
|
|
92
122
|
},
|
|
93
123
|
|
|
94
|
-
getChallenges(response) {
|
|
95
|
-
return
|
|
124
|
+
getChallenges(response, request) {
|
|
125
|
+
return collect(response, request)
|
|
96
126
|
},
|
|
97
127
|
|
|
98
|
-
getChallenge(response) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
getChallenge(response, request) {
|
|
129
|
+
const pick = (challenges: Challenge.Challenge[]): Challenge.Challenge => {
|
|
130
|
+
const challenge = challenges[0]
|
|
131
|
+
if (!challenge) throw new Error('No challenge in response.')
|
|
132
|
+
return challenge
|
|
133
|
+
}
|
|
134
|
+
const challenges = collect(response, request)
|
|
135
|
+
return challenges instanceof Promise ? challenges.then(pick) : pick(challenges)
|
|
102
136
|
},
|
|
103
137
|
|
|
104
138
|
setCredential(request, credential, options) {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
} else {
|
|
110
|
-
headers.set(paymentAuthCredentialHeader, credential)
|
|
111
|
-
}
|
|
112
|
-
return { ...request, headers }
|
|
139
|
+
const protocol = options?.challenge ? protocolForChallenge.get(options.challenge) : undefined
|
|
140
|
+
const fallback = protocols[0]
|
|
141
|
+
if (!protocol && !fallback) throw new Error('No protocol to attach the credential.')
|
|
142
|
+
return (protocol ?? fallback)!.setCredential(request, credential)
|
|
113
143
|
},
|
|
114
144
|
})
|
|
115
145
|
}
|
|
116
146
|
|
|
117
|
-
function paymentRequiredChallenges(response: Response): Challenge.Challenge[] {
|
|
118
|
-
return [
|
|
119
|
-
...(response.headers.has(paymentAuthChallengeHeader)
|
|
120
|
-
? Challenge.fromResponseList(response)
|
|
121
|
-
: []),
|
|
122
|
-
...x402Challenges(response),
|
|
123
|
-
]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function x402Challenges(response: Response): Challenge.Challenge[] {
|
|
127
|
-
const header = response.headers.get(x402_Types.paymentRequiredHeader)
|
|
128
|
-
if (!header) return []
|
|
129
|
-
const paymentRequired = x402_Header.decodePaymentRequired(header)
|
|
130
|
-
if (response.url && paymentRequired.resource.url !== response.url)
|
|
131
|
-
throw new Error('x402 payment-required resource does not match response URL.')
|
|
132
|
-
return paymentRequired.accepts.map((accepted, index) =>
|
|
133
|
-
x402_ChallengeBrand.mark(
|
|
134
|
-
Challenge.from({
|
|
135
|
-
id: `${x402_Types.syntheticChallengeIdPrefix}${index}`,
|
|
136
|
-
intent: x402_Types.exactIntent,
|
|
137
|
-
method: x402_Types.paymentMethod,
|
|
138
|
-
realm: new URL(paymentRequired.resource.url).host,
|
|
139
|
-
request: {
|
|
140
|
-
...accepted,
|
|
141
|
-
...(paymentRequired.extensions ? { extensions: paymentRequired.extensions } : {}),
|
|
142
|
-
resource: paymentRequired.resource,
|
|
143
|
-
},
|
|
144
|
-
}),
|
|
145
|
-
),
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function isX402Challenge(challenge: Challenge.Challenge | undefined): boolean {
|
|
150
|
-
return x402_ChallengeBrand.is(challenge)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
147
|
/**
|
|
154
|
-
* MCP transport for
|
|
148
|
+
* MCP protocol transport for direct JSON-RPC objects.
|
|
155
149
|
*
|
|
156
|
-
* -
|
|
157
|
-
*
|
|
158
|
-
* - Sends credentials via `_meta["org.paymentauth/credential"]`
|
|
150
|
+
* Prefer {@link http} for MCP-over-HTTP fetches; this remains for callers that already operate on
|
|
151
|
+
* parsed MCP request/response objects.
|
|
159
152
|
*/
|
|
160
153
|
export function mcp() {
|
|
161
154
|
return from<Mcp.Request, Mcp.Response>({
|
|
@@ -185,8 +178,8 @@ export function mcp() {
|
|
|
185
178
|
...request,
|
|
186
179
|
params: {
|
|
187
180
|
...request.params,
|
|
188
|
-
_meta: {
|
|
189
|
-
...request.params?._meta,
|
|
181
|
+
['_meta']: {
|
|
182
|
+
...request.params?.['_meta'],
|
|
190
183
|
[Mcp.credentialMetaKey]: parsed,
|
|
191
184
|
},
|
|
192
185
|
},
|
package/src/client/index.ts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
+
export * as Constants from '../Constants.js'
|
|
1
2
|
export * as Expires from '../Expires.js'
|
|
2
3
|
export * as Fetch from './internal/Fetch.js'
|
|
3
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
evm,
|
|
6
|
+
session,
|
|
7
|
+
sessionManager,
|
|
8
|
+
sessionMethod,
|
|
9
|
+
sessionLegacy,
|
|
10
|
+
sessionLegacyManager,
|
|
11
|
+
stripe,
|
|
12
|
+
tempo,
|
|
13
|
+
} from './Methods.js'
|
|
14
|
+
export {
|
|
15
|
+
createChannelStore,
|
|
16
|
+
createJsonChannelStore,
|
|
17
|
+
entryKey,
|
|
18
|
+
type ChannelStore,
|
|
19
|
+
type JsonChannelKv,
|
|
20
|
+
} from '../tempo/session/client/ChannelStore.js'
|
|
21
|
+
export type { ChargeContext } from '../tempo/client/Charge.js'
|
|
22
|
+
export type {
|
|
23
|
+
ResolveAccount,
|
|
24
|
+
ResolveAccountCall,
|
|
25
|
+
ResolveAccountInfo,
|
|
26
|
+
ResolveAccountOperation,
|
|
27
|
+
} from '../tempo/client/ResolveAccount.js'
|
|
4
28
|
export * as Mppx from './Mppx.js'
|
|
5
29
|
export * as Transport from './Transport.js'
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Challenge, Errors, Receipt } from 'mppx'
|
|
1
|
+
import { Challenge, Credential, Errors, Mcp, Receipt } from 'mppx'
|
|
2
2
|
import { tempo } from 'mppx/client'
|
|
3
3
|
import { Mppx as Mppx_server, tempo as tempo_server } from 'mppx/server'
|
|
4
|
+
import { Header as x402_Header, Types as x402_Types, type PaymentRequired } from 'mppx/x402'
|
|
4
5
|
import { createClient, defineChain } from 'viem'
|
|
5
6
|
import { describe, expect, test, vi } from 'vp/test'
|
|
6
7
|
import * as Http from '~test/Http.js'
|
|
7
|
-
import { rpcUrl } from '~test/tempo/
|
|
8
|
+
import { rpcUrl } from '~test/tempo/rpc.js'
|
|
8
9
|
import { accounts, asset, chain, client, http } from '~test/tempo/viem.js'
|
|
9
10
|
|
|
10
11
|
import * as Fetch from './Fetch.js'
|
|
11
12
|
|
|
12
13
|
const realm = 'api.example.com'
|
|
13
|
-
const secretKey = 'test-secret-key'
|
|
14
|
+
const secretKey = 'test-secret-key-test-secret-key-32'
|
|
14
15
|
|
|
15
16
|
const server = Mppx_server.create({
|
|
16
17
|
methods: [
|
|
@@ -334,6 +335,21 @@ const noopMethod = {
|
|
|
334
335
|
createCredential: async () => 'credential',
|
|
335
336
|
} as any
|
|
336
337
|
|
|
338
|
+
const x402PaymentRequired = {
|
|
339
|
+
accepts: [
|
|
340
|
+
{
|
|
341
|
+
amount: '10000',
|
|
342
|
+
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
|
|
343
|
+
maxTimeoutSeconds: 60,
|
|
344
|
+
network: 'eip155:84532',
|
|
345
|
+
payTo: '0x209693Bc6afc0C5328bA36FaF03C514EF312287C',
|
|
346
|
+
scheme: x402_Types.schemes[0],
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
resource: { url: 'https://example.com/api' },
|
|
350
|
+
x402Version: 2,
|
|
351
|
+
} satisfies PaymentRequired
|
|
352
|
+
|
|
337
353
|
/** Builds a valid 402 response with a WWW-Authenticate header. */
|
|
338
354
|
function make402(overrides?: { expires?: string; intent?: string; method?: string }) {
|
|
339
355
|
const method = overrides?.method ?? 'test'
|
|
@@ -350,6 +366,19 @@ function make402(overrides?: { expires?: string; intent?: string; method?: strin
|
|
|
350
366
|
})
|
|
351
367
|
}
|
|
352
368
|
|
|
369
|
+
function makeCombined402() {
|
|
370
|
+
const response = make402()
|
|
371
|
+
const headers = new Headers(response.headers)
|
|
372
|
+
headers.set(
|
|
373
|
+
x402_Types.paymentRequiredHeader,
|
|
374
|
+
x402_Header.encodePaymentRequired(x402PaymentRequired),
|
|
375
|
+
)
|
|
376
|
+
return new Response(null, {
|
|
377
|
+
status: 402,
|
|
378
|
+
headers,
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
|
|
353
382
|
describe('Fetch.from: init passthrough (non-402)', () => {
|
|
354
383
|
test('preserves init object identity while adding Accept-Payment', async () => {
|
|
355
384
|
const receivedInits: (RequestInit | undefined)[] = []
|
|
@@ -669,7 +698,183 @@ describe('Fetch.from: 402 retry path', () => {
|
|
|
669
698
|
expect(headers.get('Authorization')).toBe('credential')
|
|
670
699
|
})
|
|
671
700
|
|
|
672
|
-
test('
|
|
701
|
+
test('chooses native Payment-auth from combined MPP and x402 HTTP 402 offers', async () => {
|
|
702
|
+
let callCount = 0
|
|
703
|
+
const calls: { init: RequestInit | undefined }[] = []
|
|
704
|
+
const mockFetch: typeof globalThis.fetch = async (_input, init) => {
|
|
705
|
+
calls.push({ init })
|
|
706
|
+
callCount++
|
|
707
|
+
if (callCount === 1) return makeCombined402()
|
|
708
|
+
return new Response('OK', { status: 200 })
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const fetch = Fetch.from({
|
|
712
|
+
fetch: mockFetch,
|
|
713
|
+
methods: [noopMethod],
|
|
714
|
+
})
|
|
715
|
+
|
|
716
|
+
const response = await fetch('https://example.com/api')
|
|
717
|
+
|
|
718
|
+
expect(response.status).toBe(200)
|
|
719
|
+
expect(calls).toHaveLength(2)
|
|
720
|
+
const retryHeaders = new Headers(calls[1]!.init?.headers)
|
|
721
|
+
expect(retryHeaders.get('Authorization')).toBe('credential')
|
|
722
|
+
expect(retryHeaders.get(x402_Types.paymentSignatureHeader)).toBeNull()
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
test('settles MCP-over-HTTP JSON-RPC payment challenges at the fetch boundary', async () => {
|
|
726
|
+
const mcpChallenge = Challenge.from({
|
|
727
|
+
id: 'mcp-challenge',
|
|
728
|
+
intent: 'test',
|
|
729
|
+
method: 'test',
|
|
730
|
+
realm: 'test',
|
|
731
|
+
request: { amount: '1' },
|
|
732
|
+
})
|
|
733
|
+
const method = {
|
|
734
|
+
...noopMethod,
|
|
735
|
+
createCredential: async ({ challenge }: { challenge: Challenge.Challenge }) =>
|
|
736
|
+
Credential.serialize({ challenge, payload: { source: 'mcp' } }),
|
|
737
|
+
}
|
|
738
|
+
const initialBody = JSON.stringify({
|
|
739
|
+
jsonrpc: '2.0',
|
|
740
|
+
id: 1,
|
|
741
|
+
method: 'tools/call',
|
|
742
|
+
params: { name: 'paid-tool' },
|
|
743
|
+
})
|
|
744
|
+
let callCount = 0
|
|
745
|
+
const calls: { init: RequestInit | undefined }[] = []
|
|
746
|
+
const mockFetch: typeof globalThis.fetch = async (_input, init) => {
|
|
747
|
+
calls.push({ init })
|
|
748
|
+
callCount++
|
|
749
|
+
if (callCount === 1)
|
|
750
|
+
return Response.json({
|
|
751
|
+
jsonrpc: '2.0',
|
|
752
|
+
id: 1,
|
|
753
|
+
error: {
|
|
754
|
+
code: Mcp.paymentRequiredCode,
|
|
755
|
+
message: 'Payment Required',
|
|
756
|
+
data: { challenges: [mcpChallenge] },
|
|
757
|
+
},
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
const body = JSON.parse(init?.body as string)
|
|
761
|
+
expect(new Headers(init?.headers).get('Authorization')).toBeNull()
|
|
762
|
+
expect(body.params['_meta'][Mcp.credentialMetaKey]).toMatchObject({
|
|
763
|
+
payload: { source: 'mcp' },
|
|
764
|
+
})
|
|
765
|
+
return Response.json({ ok: true })
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const fetch = Fetch.from({
|
|
769
|
+
fetch: mockFetch,
|
|
770
|
+
methods: [method],
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
const response = await fetch('https://example.com/mcp', {
|
|
774
|
+
method: 'POST',
|
|
775
|
+
headers: { accept: 'application/json, text/event-stream' },
|
|
776
|
+
body: initialBody,
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
expect(response.status).toBe(200)
|
|
780
|
+
expect(calls).toHaveLength(2)
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
test('settles MCP-over-HTTP when the JSON-RPC request body is carried by Request input', async () => {
|
|
784
|
+
const mcpChallenge = Challenge.from({
|
|
785
|
+
id: 'mcp-request-input-challenge',
|
|
786
|
+
intent: 'test',
|
|
787
|
+
method: 'test',
|
|
788
|
+
realm: 'test',
|
|
789
|
+
request: { amount: '1' },
|
|
790
|
+
})
|
|
791
|
+
const method = {
|
|
792
|
+
...noopMethod,
|
|
793
|
+
createCredential: async ({ challenge }: { challenge: Challenge.Challenge }) =>
|
|
794
|
+
Credential.serialize({ challenge, payload: { source: 'request-input' } }),
|
|
795
|
+
}
|
|
796
|
+
const initialBody = JSON.stringify({
|
|
797
|
+
jsonrpc: '2.0',
|
|
798
|
+
id: 1,
|
|
799
|
+
method: 'tools/call',
|
|
800
|
+
params: { name: 'paid-tool' },
|
|
801
|
+
})
|
|
802
|
+
let callCount = 0
|
|
803
|
+
const calls: { init: RequestInit | undefined; input: RequestInfo | URL }[] = []
|
|
804
|
+
const mockFetch: typeof globalThis.fetch = async (input, init) => {
|
|
805
|
+
calls.push({ input, init })
|
|
806
|
+
callCount++
|
|
807
|
+
if (callCount === 1) {
|
|
808
|
+
expect(input).toBeInstanceOf(Request)
|
|
809
|
+
expect(await (input as Request).text()).toBe(initialBody)
|
|
810
|
+
return Response.json({
|
|
811
|
+
jsonrpc: '2.0',
|
|
812
|
+
id: 1,
|
|
813
|
+
error: {
|
|
814
|
+
code: Mcp.paymentRequiredCode,
|
|
815
|
+
message: 'Payment Required',
|
|
816
|
+
data: { challenges: [mcpChallenge] },
|
|
817
|
+
},
|
|
818
|
+
})
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const body = JSON.parse(init?.body as string)
|
|
822
|
+
expect(body.params['_meta'][Mcp.credentialMetaKey]).toMatchObject({
|
|
823
|
+
payload: { source: 'request-input' },
|
|
824
|
+
})
|
|
825
|
+
return Response.json({ ok: true })
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const fetch = Fetch.from({
|
|
829
|
+
fetch: mockFetch,
|
|
830
|
+
methods: [method],
|
|
831
|
+
})
|
|
832
|
+
const request = new Request('https://example.com/mcp', {
|
|
833
|
+
method: 'POST',
|
|
834
|
+
headers: { accept: 'application/json, text/event-stream' },
|
|
835
|
+
body: initialBody,
|
|
836
|
+
})
|
|
837
|
+
|
|
838
|
+
const response = await fetch(request)
|
|
839
|
+
|
|
840
|
+
expect(response.status).toBe(200)
|
|
841
|
+
expect(calls).toHaveLength(2)
|
|
842
|
+
expect(calls[1]?.input).toBe(request)
|
|
843
|
+
})
|
|
844
|
+
|
|
845
|
+
test('settles native HTTP 402 when a POST body is carried by Request input', async () => {
|
|
846
|
+
const initialBody = JSON.stringify({ ok: true })
|
|
847
|
+
let callCount = 0
|
|
848
|
+
const calls: { init: RequestInit | undefined; input: RequestInfo | URL }[] = []
|
|
849
|
+
const mockFetch: typeof globalThis.fetch = async (input, init) => {
|
|
850
|
+
calls.push({ input, init })
|
|
851
|
+
callCount++
|
|
852
|
+
const request = input instanceof Request && !init ? input : new Request(input, init)
|
|
853
|
+
expect(await request.text()).toBe(initialBody)
|
|
854
|
+
if (callCount === 1) return make402()
|
|
855
|
+
|
|
856
|
+
expect(request.headers.get('Authorization')).toBe('credential')
|
|
857
|
+
return new Response('OK', { status: 200 })
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const fetch = Fetch.from({
|
|
861
|
+
fetch: mockFetch,
|
|
862
|
+
methods: [noopMethod],
|
|
863
|
+
})
|
|
864
|
+
const request = new Request('https://example.com/api', {
|
|
865
|
+
method: 'POST',
|
|
866
|
+
headers: { 'Content-Type': 'application/json' },
|
|
867
|
+
body: initialBody,
|
|
868
|
+
})
|
|
869
|
+
|
|
870
|
+
const response = await fetch(request)
|
|
871
|
+
|
|
872
|
+
expect(response.status).toBe(200)
|
|
873
|
+
expect(calls).toHaveLength(2)
|
|
874
|
+
expect(calls[1]?.input).toBe(request)
|
|
875
|
+
})
|
|
876
|
+
|
|
877
|
+
test('sends credential retry to the final same-origin 402 response URL', async () => {
|
|
673
878
|
let callCount = 0
|
|
674
879
|
const calls: { input: RequestInfo | URL; init: RequestInit | undefined }[] = []
|
|
675
880
|
const mockFetch: typeof globalThis.fetch = async (input, init) => {
|
|
@@ -678,7 +883,7 @@ describe('Fetch.from: 402 retry path', () => {
|
|
|
678
883
|
if (callCount === 1) {
|
|
679
884
|
const response = make402()
|
|
680
885
|
Object.defineProperty(response, 'url', {
|
|
681
|
-
value: 'https://
|
|
886
|
+
value: 'https://api.example.com/redirected-protected',
|
|
682
887
|
})
|
|
683
888
|
return response
|
|
684
889
|
}
|
|
@@ -694,10 +899,35 @@ describe('Fetch.from: 402 retry path', () => {
|
|
|
694
899
|
|
|
695
900
|
expect(response.status).toBe(200)
|
|
696
901
|
expect(calls[0]!.input).toBe('https://api.example.com/protected')
|
|
697
|
-
expect(calls[1]!.input).toBe('https://
|
|
902
|
+
expect(calls[1]!.input).toBe('https://api.example.com/redirected-protected')
|
|
698
903
|
expect(new Headers(calls[1]!.init?.headers).get('Authorization')).toBe('credential')
|
|
699
904
|
})
|
|
700
905
|
|
|
906
|
+
test('rejects credential retry to a cross-origin 402 response URL', async () => {
|
|
907
|
+
const calls: { input: RequestInfo | URL; init: RequestInit | undefined }[] = []
|
|
908
|
+
const mockFetch: typeof globalThis.fetch = async (input, init) => {
|
|
909
|
+
calls.push({ input, init })
|
|
910
|
+
const response = make402()
|
|
911
|
+
Object.defineProperty(response, 'url', {
|
|
912
|
+
value: 'https://payments.example.com/protected',
|
|
913
|
+
})
|
|
914
|
+
return response
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const fetch = Fetch.from({
|
|
918
|
+
fetch: mockFetch,
|
|
919
|
+
methods: [noopMethod],
|
|
920
|
+
})
|
|
921
|
+
|
|
922
|
+
await expect(fetch('https://api.example.com/protected')).rejects.toThrow(
|
|
923
|
+
'Refusing to send payment credential across redirect from https://api.example.com to https://payments.example.com',
|
|
924
|
+
)
|
|
925
|
+
|
|
926
|
+
expect(calls).toHaveLength(1)
|
|
927
|
+
expect(calls[0]!.input).toBe('https://api.example.com/protected')
|
|
928
|
+
expect(new Headers(calls[0]!.init?.headers).get('Authorization')).toBeNull()
|
|
929
|
+
})
|
|
930
|
+
|
|
701
931
|
test('emits client events and allows challenge handler to provide credential', async () => {
|
|
702
932
|
const events: string[] = []
|
|
703
933
|
const createCredential = vi.fn(async () => 'method-credential')
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Challenge from '../../Challenge.js'
|
|
2
|
+
import * as Constants from '../../Constants.js'
|
|
2
3
|
import * as Expires from '../../Expires.js'
|
|
3
4
|
import * as AcceptPayment from '../../internal/AcceptPayment.js'
|
|
4
5
|
import type { MaybePromise } from '../../internal/types.js'
|
|
@@ -173,8 +174,9 @@ export function from<const methods extends readonly Method.AnyClient[]>(
|
|
|
173
174
|
|
|
174
175
|
const wrappedFetch = async (input: RequestInfo | URL, init?: from.RequestInit<methods>) => {
|
|
175
176
|
const callerHeaders = getCallerHeaders(input, init?.headers)
|
|
176
|
-
const hasExplicitAcceptPayment = callerHeaders.has(
|
|
177
|
+
const hasExplicitAcceptPayment = callerHeaders.has(Constants.Headers.acceptPayment)
|
|
177
178
|
const paymentPreferences = resolvePaymentPreferences(callerHeaders, resolvedAcceptPayment)
|
|
179
|
+
const capturedBody = captureRequestBody(input, init, callerHeaders)
|
|
178
180
|
const initialRequest = prepareInitialRequest(
|
|
179
181
|
input,
|
|
180
182
|
init,
|
|
@@ -183,9 +185,10 @@ export function from<const methods extends readonly Method.AnyClient[]>(
|
|
|
183
185
|
hasExplicitAcceptPayment,
|
|
184
186
|
acceptPaymentPolicy,
|
|
185
187
|
)
|
|
186
|
-
const response = await baseFetch(initialRequest.input, initialRequest.init)
|
|
188
|
+
const response = await baseFetch(cloneRequestInput(initialRequest.input), initialRequest.init)
|
|
189
|
+
const transportRequest = withCapturedBody(initialRequest.init, await capturedBody)
|
|
187
190
|
|
|
188
|
-
if (!transport.isPaymentRequired(response)) return response
|
|
191
|
+
if (!(await transport.isPaymentRequired(response, transportRequest as never))) return response
|
|
189
192
|
|
|
190
193
|
// Only extract context for payment handling after confirming 402.
|
|
191
194
|
const context = (init as Record<string, unknown> | undefined)?.context
|
|
@@ -193,7 +196,7 @@ export function from<const methods extends readonly Method.AnyClient[]>(
|
|
|
193
196
|
context: _,
|
|
194
197
|
orderChallenges: requestOrderChallenges,
|
|
195
198
|
...fetchInit
|
|
196
|
-
} = (
|
|
199
|
+
} = (transportRequest ?? {}) as Record<string, unknown>
|
|
197
200
|
|
|
198
201
|
let challenge: Challenge.Challenge | undefined
|
|
199
202
|
let challenges: readonly Challenge.Challenge[] | undefined
|
|
@@ -201,8 +204,8 @@ export function from<const methods extends readonly Method.AnyClient[]>(
|
|
|
201
204
|
|
|
202
205
|
try {
|
|
203
206
|
challenges = transport.getChallenges
|
|
204
|
-
? transport.getChallenges(response)
|
|
205
|
-
: [transport.getChallenge(response)]
|
|
207
|
+
? await transport.getChallenges(response, transportRequest as never)
|
|
208
|
+
: [await transport.getChallenge(response, transportRequest as never)]
|
|
206
209
|
|
|
207
210
|
const candidates = AcceptPayment.selectChallengeCandidates(
|
|
208
211
|
challenges,
|
|
@@ -262,7 +265,7 @@ export function from<const methods extends readonly Method.AnyClient[]>(
|
|
|
262
265
|
)
|
|
263
266
|
|
|
264
267
|
const paymentResponse = await baseFetch(
|
|
265
|
-
resolvePaymentRetryInput(response, initialRequest.input),
|
|
268
|
+
resolvePaymentRetryInput(response, initialRequest.input, initialRequest.input),
|
|
266
269
|
transport.setCredential(
|
|
267
270
|
{
|
|
268
271
|
...fetchInit,
|
|
@@ -665,7 +668,13 @@ function snapshotInit<methods extends readonly Method.AnyClient[]>(
|
|
|
665
668
|
}
|
|
666
669
|
|
|
667
670
|
function snapshotInput(input: RequestInfo | URL | undefined): RequestInfo | URL | undefined {
|
|
668
|
-
if (input instanceof Request)
|
|
671
|
+
if (input instanceof Request) {
|
|
672
|
+
try {
|
|
673
|
+
return input.clone()
|
|
674
|
+
} catch {
|
|
675
|
+
return input
|
|
676
|
+
}
|
|
677
|
+
}
|
|
669
678
|
if (input instanceof URL) return new URL(input)
|
|
670
679
|
return input
|
|
671
680
|
}
|
|
@@ -717,7 +726,7 @@ function prepareInitialRequest<methods extends readonly Method.AnyClient[]>(
|
|
|
717
726
|
callerHeaders.forEach((value, key) => {
|
|
718
727
|
headers.set(key, value)
|
|
719
728
|
})
|
|
720
|
-
headers.set(
|
|
729
|
+
headers.set(Constants.Headers.acceptPayment, header)
|
|
721
730
|
|
|
722
731
|
if (init) {
|
|
723
732
|
// Preserve init identity for callers like websocket upgrade helpers that
|
|
@@ -737,6 +746,35 @@ function prepareInitialRequest<methods extends readonly Method.AnyClient[]>(
|
|
|
737
746
|
}
|
|
738
747
|
}
|
|
739
748
|
|
|
749
|
+
function captureRequestBody<methods extends readonly Method.AnyClient[]>(
|
|
750
|
+
input: RequestInfo | URL,
|
|
751
|
+
init: from.RequestInit<methods> | undefined,
|
|
752
|
+
headers: Headers,
|
|
753
|
+
): Promise<string | undefined> | undefined {
|
|
754
|
+
if (!(input instanceof Request) || init?.body !== undefined || !input.body || input.bodyUsed)
|
|
755
|
+
return undefined
|
|
756
|
+
if (!headers.has('mcp-method')) {
|
|
757
|
+
const accept = headers.get('accept')?.toLowerCase() ?? ''
|
|
758
|
+
if (!accept.includes('application/json') || !accept.includes('text/event-stream'))
|
|
759
|
+
return undefined
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
return input
|
|
763
|
+
.clone()
|
|
764
|
+
.text()
|
|
765
|
+
.catch(() => undefined)
|
|
766
|
+
} catch {
|
|
767
|
+
return undefined
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function withCapturedBody<methods extends readonly Method.AnyClient[]>(
|
|
772
|
+
init: from.RequestInit<methods> | undefined,
|
|
773
|
+
body: string | undefined,
|
|
774
|
+
): from.RequestInit<methods> | undefined {
|
|
775
|
+
return body === undefined ? init : ({ ...init, body } as from.RequestInit<methods>)
|
|
776
|
+
}
|
|
777
|
+
|
|
740
778
|
/** @internal */
|
|
741
779
|
function getCallerHeaders(input: RequestInfo | URL, headers: HeadersInit | undefined): Headers {
|
|
742
780
|
if (headers) return new Headers(headers)
|
|
@@ -752,6 +790,15 @@ function unwrapFetch(fetch: typeof globalThis.fetch): typeof globalThis.fetch {
|
|
|
752
790
|
return current as typeof globalThis.fetch
|
|
753
791
|
}
|
|
754
792
|
|
|
793
|
+
function cloneRequestInput(input: RequestInfo | URL): RequestInfo | URL {
|
|
794
|
+
if (!(input instanceof Request) || !input.body || input.bodyUsed) return input
|
|
795
|
+
try {
|
|
796
|
+
return input.clone()
|
|
797
|
+
} catch {
|
|
798
|
+
return input
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
755
802
|
/** @internal */
|
|
756
803
|
function isWrappedFetch(fetch: typeof globalThis.fetch): fetch is WrappedFetch {
|
|
757
804
|
return Boolean((fetch as WrappedFetch)[MPPX_FETCH_WRAPPER])
|
|
@@ -781,7 +828,7 @@ function resolvePaymentPreferences<methods extends readonly Method.AnyClient[]>(
|
|
|
781
828
|
headers: Headers,
|
|
782
829
|
acceptPayment: AcceptPayment.Resolved<methods>,
|
|
783
830
|
): AcceptPayment.Resolved<methods> {
|
|
784
|
-
const header = headers.get(
|
|
831
|
+
const header = headers.get(Constants.Headers.acceptPayment)
|
|
785
832
|
if (!header) return acceptPayment
|
|
786
833
|
|
|
787
834
|
try {
|
|
@@ -847,6 +894,17 @@ function resolveRequestUrl(input: RequestInfo | URL): URL {
|
|
|
847
894
|
function resolvePaymentRetryInput(
|
|
848
895
|
response: Response,
|
|
849
896
|
fallback: RequestInfo | URL,
|
|
897
|
+
initialInput: RequestInfo | URL,
|
|
850
898
|
): RequestInfo | URL {
|
|
851
|
-
|
|
899
|
+
if (!response.url) return fallback
|
|
900
|
+
|
|
901
|
+
const responseUrl = new URL(response.url)
|
|
902
|
+
const initialUrl = resolveRequestUrl(initialInput)
|
|
903
|
+
if (responseUrl.origin !== initialUrl.origin) {
|
|
904
|
+
throw new Error(
|
|
905
|
+
`Refusing to send payment credential across redirect from ${initialUrl.origin} to ${responseUrl.origin}`,
|
|
906
|
+
)
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
return response.url
|
|
852
910
|
}
|