mppx 0.0.1 → 0.1.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 +21 -0
- package/README.md +195 -0
- package/dist/BodyDigest.d.ts +42 -0
- package/dist/BodyDigest.d.ts.map +1 -0
- package/dist/BodyDigest.js +40 -0
- package/dist/BodyDigest.js.map +1 -0
- package/dist/Challenge.d.ts +271 -0
- package/dist/Challenge.d.ts.map +1 -0
- package/dist/Challenge.js +291 -0
- package/dist/Challenge.js.map +1 -0
- package/dist/Credential.d.ts +91 -0
- package/dist/Credential.d.ts.map +1 -0
- package/dist/Credential.js +122 -0
- package/dist/Credential.js.map +1 -0
- package/dist/Errors.d.ts +243 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +201 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Expires.d.ts +15 -0
- package/dist/Expires.d.ts.map +1 -0
- package/dist/Expires.js +29 -0
- package/dist/Expires.js.map +1 -0
- package/dist/Intent.d.ts +101 -0
- package/dist/Intent.d.ts.map +1 -0
- package/dist/Intent.js +83 -0
- package/dist/Intent.js.map +1 -0
- package/dist/Mcp.d.ts +74 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +9 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/MethodIntent.d.ts +225 -0
- package/dist/MethodIntent.d.ts.map +1 -0
- package/dist/MethodIntent.js +156 -0
- package/dist/MethodIntent.js.map +1 -0
- package/dist/PaymentRequest.d.ts +88 -0
- package/dist/PaymentRequest.d.ts.map +1 -0
- package/dist/PaymentRequest.js +81 -0
- package/dist/PaymentRequest.js.map +1 -0
- package/dist/Receipt.d.ts +110 -0
- package/dist/Receipt.d.ts.map +1 -0
- package/dist/Receipt.js +105 -0
- package/dist/Receipt.js.map +1 -0
- package/dist/Store.d.ts +28 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +61 -0
- package/dist/Store.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1219 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/Methods.d.ts +4 -0
- package/dist/client/Methods.d.ts.map +1 -0
- package/dist/client/Methods.js +4 -0
- package/dist/client/Methods.js.map +1 -0
- package/dist/client/Mppx.d.ts +84 -0
- package/dist/client/Mppx.d.ts.map +1 -0
- package/dist/client/Mppx.js +64 -0
- package/dist/client/Mppx.js.map +1 -0
- package/dist/client/Transport.d.ts +56 -0
- package/dist/client/Transport.d.ts.map +1 -0
- package/dist/client/Transport.js +81 -0
- package/dist/client/Transport.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +5 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/internal/Fetch.d.ts +85 -0
- package/dist/client/internal/Fetch.d.ts.map +1 -0
- package/dist/client/internal/Fetch.js +95 -0
- package/dist/client/internal/Fetch.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +302 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/mcp-sdk/client/McpClient.d.ts +78 -0
- package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -0
- package/dist/mcp-sdk/client/McpClient.js +98 -0
- package/dist/mcp-sdk/client/McpClient.js.map +1 -0
- package/dist/mcp-sdk/client/index.d.ts +3 -0
- package/dist/mcp-sdk/client/index.d.ts.map +1 -0
- package/dist/mcp-sdk/client/index.js +3 -0
- package/dist/mcp-sdk/client/index.js.map +1 -0
- package/dist/mcp-sdk/server/Transport.d.ts +43 -0
- package/dist/mcp-sdk/server/Transport.d.ts.map +1 -0
- package/dist/mcp-sdk/server/Transport.js +71 -0
- package/dist/mcp-sdk/server/Transport.js.map +1 -0
- package/dist/mcp-sdk/server/index.d.ts +2 -0
- package/dist/mcp-sdk/server/index.d.ts.map +1 -0
- package/dist/mcp-sdk/server/index.js +2 -0
- package/dist/mcp-sdk/server/index.js.map +1 -0
- package/dist/middlewares/elysia.d.ts +51 -0
- package/dist/middlewares/elysia.d.ts.map +1 -0
- package/dist/middlewares/elysia.js +59 -0
- package/dist/middlewares/elysia.js.map +1 -0
- package/dist/middlewares/express.d.ts +46 -0
- package/dist/middlewares/express.d.ts.map +1 -0
- package/dist/middlewares/express.js +69 -0
- package/dist/middlewares/express.js.map +1 -0
- package/dist/middlewares/hono.d.ts +46 -0
- package/dist/middlewares/hono.d.ts.map +1 -0
- package/dist/middlewares/hono.js +57 -0
- package/dist/middlewares/hono.js.map +1 -0
- package/dist/middlewares/internal/mppx.d.ts +16 -0
- package/dist/middlewares/internal/mppx.d.ts.map +1 -0
- package/dist/middlewares/internal/mppx.js +16 -0
- package/dist/middlewares/internal/mppx.js.map +1 -0
- package/dist/middlewares/nextjs.d.ts +45 -0
- package/dist/middlewares/nextjs.d.ts.map +1 -0
- package/dist/middlewares/nextjs.js +57 -0
- package/dist/middlewares/nextjs.js.map +1 -0
- package/dist/proxy/Proxy.d.ts +47 -0
- package/dist/proxy/Proxy.d.ts.map +1 -0
- package/dist/proxy/Proxy.js +126 -0
- package/dist/proxy/Proxy.js.map +1 -0
- package/dist/proxy/Service.d.ts +100 -0
- package/dist/proxy/Service.d.ts.map +1 -0
- package/dist/proxy/Service.js +147 -0
- package/dist/proxy/Service.js.map +1 -0
- package/dist/proxy/index.d.ts +7 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +7 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/proxy/internal/Headers.d.ts +3 -0
- package/dist/proxy/internal/Headers.d.ts.map +1 -0
- package/dist/proxy/internal/Headers.js +41 -0
- package/dist/proxy/internal/Headers.js.map +1 -0
- package/dist/proxy/internal/Route.d.ts +14 -0
- package/dist/proxy/internal/Route.d.ts.map +1 -0
- package/dist/proxy/internal/Route.js +47 -0
- package/dist/proxy/internal/Route.js.map +1 -0
- package/dist/proxy/services/anthropic.d.ts +29 -0
- package/dist/proxy/services/anthropic.d.ts.map +1 -0
- package/dist/proxy/services/anthropic.js +30 -0
- package/dist/proxy/services/anthropic.js.map +1 -0
- package/dist/proxy/services/openai.d.ts +29 -0
- package/dist/proxy/services/openai.d.ts.map +1 -0
- package/dist/proxy/services/openai.js +30 -0
- package/dist/proxy/services/openai.js.map +1 -0
- package/dist/proxy/services/stripe.d.ts +29 -0
- package/dist/proxy/services/stripe.d.ts.map +1 -0
- package/dist/proxy/services/stripe.js +30 -0
- package/dist/proxy/services/stripe.js.map +1 -0
- package/dist/server/Methods.d.ts +3 -0
- package/dist/server/Methods.d.ts.map +1 -0
- package/dist/server/Methods.js +3 -0
- package/dist/server/Methods.js.map +1 -0
- package/dist/server/Mppx.d.ts +116 -0
- package/dist/server/Mppx.d.ts.map +1 -0
- package/dist/server/Mppx.js +207 -0
- package/dist/server/Mppx.js.map +1 -0
- package/dist/server/NodeListener.d.ts +3 -0
- package/dist/server/NodeListener.d.ts.map +1 -0
- package/dist/server/NodeListener.js +3 -0
- package/dist/server/NodeListener.js.map +1 -0
- package/dist/server/Request.d.ts +24 -0
- package/dist/server/Request.d.ts.map +1 -0
- package/dist/server/Request.js +26 -0
- package/dist/server/Request.js.map +1 -0
- package/dist/server/Response.d.ts +10 -0
- package/dist/server/Response.d.ts.map +1 -0
- package/dist/server/Response.js +15 -0
- package/dist/server/Response.js.map +1 -0
- package/dist/server/Transport.d.ts +93 -0
- package/dist/server/Transport.d.ts.map +1 -0
- package/dist/server/Transport.js +132 -0
- package/dist/server/Transport.js.map +1 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +9 -0
- package/dist/server/index.js.map +1 -0
- package/dist/stripe/Intents.d.ts +54 -0
- package/dist/stripe/Intents.d.ts.map +1 -0
- package/dist/stripe/Intents.js +27 -0
- package/dist/stripe/Intents.js.map +1 -0
- package/dist/stripe/client/Charge.d.ts +114 -0
- package/dist/stripe/client/Charge.d.ts.map +1 -0
- package/dist/stripe/client/Charge.js +77 -0
- package/dist/stripe/client/Charge.js.map +1 -0
- package/dist/stripe/client/MethodIntents.d.ts +80 -0
- package/dist/stripe/client/MethodIntents.d.ts.map +1 -0
- package/dist/stripe/client/MethodIntents.js +34 -0
- package/dist/stripe/client/MethodIntents.js.map +1 -0
- package/dist/stripe/client/index.d.ts +3 -0
- package/dist/stripe/client/index.d.ts.map +1 -0
- package/dist/stripe/client/index.js +3 -0
- package/dist/stripe/client/index.js.map +1 -0
- package/dist/stripe/index.d.ts +2 -0
- package/dist/stripe/index.d.ts.map +1 -0
- package/dist/stripe/index.js +2 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/server/Charge.d.ts +74 -0
- package/dist/stripe/server/Charge.d.ts.map +1 -0
- package/dist/stripe/server/Charge.js +79 -0
- package/dist/stripe/server/Charge.js.map +1 -0
- package/dist/stripe/server/MethodIntents.d.ts +65 -0
- package/dist/stripe/server/MethodIntents.d.ts.map +1 -0
- package/dist/stripe/server/MethodIntents.js +21 -0
- package/dist/stripe/server/MethodIntents.js.map +1 -0
- package/dist/stripe/server/index.d.ts +3 -0
- package/dist/stripe/server/index.d.ts.map +1 -0
- package/dist/stripe/server/index.js +3 -0
- package/dist/stripe/server/index.js.map +1 -0
- package/dist/tempo/Attribution.d.ts +101 -0
- package/dist/tempo/Attribution.d.ts.map +1 -0
- package/dist/tempo/Attribution.js +124 -0
- package/dist/tempo/Attribution.js.map +1 -0
- package/dist/tempo/Intents.d.ts +132 -0
- package/dist/tempo/Intents.d.ts.map +1 -0
- package/dist/tempo/Intents.js +81 -0
- package/dist/tempo/Intents.js.map +1 -0
- package/dist/tempo/client/ChannelOps.d.ts +54 -0
- package/dist/tempo/client/ChannelOps.d.ts.map +1 -0
- package/dist/tempo/client/ChannelOps.js +138 -0
- package/dist/tempo/client/ChannelOps.js.map +1 -0
- package/dist/tempo/client/Charge.d.ts +76 -0
- package/dist/tempo/client/Charge.d.ts.map +1 -0
- package/dist/tempo/client/Charge.js +69 -0
- package/dist/tempo/client/Charge.js.map +1 -0
- package/dist/tempo/client/MethodIntents.d.ts +157 -0
- package/dist/tempo/client/MethodIntents.d.ts.map +1 -0
- package/dist/tempo/client/MethodIntents.js +25 -0
- package/dist/tempo/client/MethodIntents.js.map +1 -0
- package/dist/tempo/client/Session.d.ts +159 -0
- package/dist/tempo/client/Session.d.ts.map +1 -0
- package/dist/tempo/client/Session.js +263 -0
- package/dist/tempo/client/Session.js.map +1 -0
- package/dist/tempo/client/SessionManager.d.ts +62 -0
- package/dist/tempo/client/SessionManager.d.ts.map +1 -0
- package/dist/tempo/client/SessionManager.js +196 -0
- package/dist/tempo/client/SessionManager.js.map +1 -0
- package/dist/tempo/client/index.d.ts +6 -0
- package/dist/tempo/client/index.d.ts.map +1 -0
- package/dist/tempo/client/index.js +5 -0
- package/dist/tempo/client/index.js.map +1 -0
- package/dist/tempo/index.d.ts +3 -0
- package/dist/tempo/index.d.ts.map +1 -0
- package/dist/tempo/index.js +3 -0
- package/dist/tempo/index.js.map +1 -0
- package/dist/tempo/internal/account.d.ts +32 -0
- package/dist/tempo/internal/account.d.ts.map +1 -0
- package/dist/tempo/internal/account.js +33 -0
- package/dist/tempo/internal/account.js.map +1 -0
- package/dist/tempo/internal/defaults.d.ts +18 -0
- package/dist/tempo/internal/defaults.d.ts.map +1 -0
- package/dist/tempo/internal/defaults.js +18 -0
- package/dist/tempo/internal/defaults.js.map +1 -0
- package/dist/tempo/internal/types.d.ts +11 -0
- package/dist/tempo/internal/types.d.ts.map +1 -0
- package/dist/tempo/internal/types.js +2 -0
- package/dist/tempo/internal/types.js.map +1 -0
- package/dist/tempo/server/Charge.d.ts +77 -0
- package/dist/tempo/server/Charge.d.ts.map +1 -0
- package/dist/tempo/server/Charge.js +228 -0
- package/dist/tempo/server/Charge.js.map +1 -0
- package/dist/tempo/server/MethodIntents.d.ts +140 -0
- package/dist/tempo/server/MethodIntents.d.ts.map +1 -0
- package/dist/tempo/server/MethodIntents.js +26 -0
- package/dist/tempo/server/MethodIntents.js.map +1 -0
- package/dist/tempo/server/Session.d.ts +148 -0
- package/dist/tempo/server/Session.d.ts.map +1 -0
- package/dist/tempo/server/Session.js +529 -0
- package/dist/tempo/server/Session.js.map +1 -0
- package/dist/tempo/server/internal/transport.d.ts +47 -0
- package/dist/tempo/server/internal/transport.d.ts.map +1 -0
- package/dist/tempo/server/internal/transport.js +118 -0
- package/dist/tempo/server/internal/transport.js.map +1 -0
- package/dist/tempo/stream/Chain.d.ts +52 -0
- package/dist/tempo/stream/Chain.d.ts.map +1 -0
- package/dist/tempo/stream/Chain.js +215 -0
- package/dist/tempo/stream/Chain.js.map +1 -0
- package/dist/tempo/stream/Channel.d.ts +26 -0
- package/dist/tempo/stream/Channel.d.ts.map +1 -0
- package/dist/tempo/stream/Channel.js +27 -0
- package/dist/tempo/stream/Channel.js.map +1 -0
- package/dist/tempo/stream/ChannelStore.d.ts +103 -0
- package/dist/tempo/stream/ChannelStore.d.ts.map +1 -0
- package/dist/tempo/stream/ChannelStore.js +100 -0
- package/dist/tempo/stream/ChannelStore.js.map +1 -0
- package/dist/tempo/stream/Receipt.d.ts +22 -0
- package/dist/tempo/stream/Receipt.d.ts.map +1 -0
- package/dist/tempo/stream/Receipt.js +34 -0
- package/dist/tempo/stream/Receipt.js.map +1 -0
- package/dist/tempo/stream/Sse.d.ts +134 -0
- package/dist/tempo/stream/Sse.d.ts.map +1 -0
- package/dist/tempo/stream/Sse.js +288 -0
- package/dist/tempo/stream/Sse.js.map +1 -0
- package/dist/tempo/stream/Types.d.ts +78 -0
- package/dist/tempo/stream/Types.d.ts.map +1 -0
- package/dist/tempo/stream/Types.js +2 -0
- package/dist/tempo/stream/Types.js.map +1 -0
- package/dist/tempo/stream/Voucher.d.ts +20 -0
- package/dist/tempo/stream/Voucher.d.ts.map +1 -0
- package/dist/tempo/stream/Voucher.js +98 -0
- package/dist/tempo/stream/Voucher.js.map +1 -0
- package/dist/tempo/stream/escrow.abi.d.ts +598 -0
- package/dist/tempo/stream/escrow.abi.d.ts.map +1 -0
- package/dist/tempo/stream/escrow.abi.js +760 -0
- package/dist/tempo/stream/escrow.abi.js.map +1 -0
- package/dist/tempo/stream/index.d.ts +8 -0
- package/dist/tempo/stream/index.d.ts.map +1 -0
- package/dist/tempo/stream/index.js +8 -0
- package/dist/tempo/stream/index.js.map +1 -0
- package/dist/viem/Account.d.ts +12 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +14 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Client.d.ts +21 -0
- package/dist/viem/Client.d.ts.map +1 -0
- package/dist/viem/Client.js +19 -0
- package/dist/viem/Client.js.map +1 -0
- package/dist/zod.d.ts +17 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +35 -0
- package/dist/zod.js.map +1 -0
- package/package.json +117 -4
- package/src/BodyDigest.test.ts +43 -0
- package/src/BodyDigest.ts +53 -0
- package/src/Challenge.test-d.ts +81 -0
- package/src/Challenge.test.ts +414 -0
- package/src/Challenge.ts +429 -0
- package/src/Credential.test.ts +227 -0
- package/src/Credential.ts +154 -0
- package/src/Errors.test.ts +402 -0
- package/src/Errors.ts +348 -0
- package/src/Expires.ts +34 -0
- package/src/Intent.test.ts +180 -0
- package/src/Intent.ts +109 -0
- package/src/Mcp.ts +81 -0
- package/src/MethodIntent.test.ts +303 -0
- package/src/MethodIntent.ts +388 -0
- package/src/PaymentRequest.test.ts +152 -0
- package/src/PaymentRequest.ts +107 -0
- package/src/Receipt.test.ts +98 -0
- package/src/Receipt.ts +129 -0
- package/src/Store.ts +84 -0
- package/src/cli.test.ts +542 -0
- package/src/cli.ts +1319 -0
- package/src/client/Methods.ts +3 -0
- package/src/client/Mppx.test-d.ts +90 -0
- package/src/client/Mppx.test.ts +468 -0
- package/src/client/Mppx.ts +149 -0
- package/src/client/Transport.test.ts +283 -0
- package/src/client/Transport.ts +115 -0
- package/src/client/index.ts +4 -0
- package/src/client/internal/Fetch.test-d.ts +57 -0
- package/src/client/internal/Fetch.test.ts +281 -0
- package/src/client/internal/Fetch.ts +157 -0
- package/src/env.d.ts +11 -0
- package/src/index.ts +12 -0
- package/src/internal/types.ts +403 -0
- package/src/mcp-sdk/client/McpClient.test-d.ts +109 -0
- package/src/mcp-sdk/client/McpClient.test.ts +219 -0
- package/src/mcp-sdk/client/McpClient.ts +187 -0
- package/src/mcp-sdk/client/index.ts +2 -0
- package/src/mcp-sdk/server/Transport.ts +94 -0
- package/src/mcp-sdk/server/index.ts +1 -0
- package/src/middlewares/elysia.ts +66 -0
- package/src/middlewares/express.test.ts +155 -0
- package/src/middlewares/express.ts +82 -0
- package/src/middlewares/hono.test.ts +148 -0
- package/src/middlewares/hono.ts +62 -0
- package/src/middlewares/internal/mppx.ts +30 -0
- package/src/middlewares/nextjs.test.ts +164 -0
- package/src/middlewares/nextjs.ts +66 -0
- package/src/proxy/Proxy.test.ts +472 -0
- package/src/proxy/Proxy.ts +175 -0
- package/src/proxy/Service.test.ts +125 -0
- package/src/proxy/Service.ts +227 -0
- package/src/proxy/index.ts +6 -0
- package/src/proxy/internal/Headers.test.ts +100 -0
- package/src/proxy/internal/Headers.ts +40 -0
- package/src/proxy/internal/Route.test.ts +143 -0
- package/src/proxy/internal/Route.ts +54 -0
- package/src/proxy/services/anthropic.ts +45 -0
- package/src/proxy/services/openai.test.ts +97 -0
- package/src/proxy/services/openai.ts +48 -0
- package/src/proxy/services/stripe.ts +49 -0
- package/src/server/Methods.ts +2 -0
- package/src/server/Mppx.test-d.ts +343 -0
- package/src/server/Mppx.test.ts +342 -0
- package/src/server/Mppx.ts +378 -0
- package/src/server/NodeListener.test.ts +188 -0
- package/src/server/NodeListener.ts +3 -0
- package/src/server/Request.test.ts +102 -0
- package/src/server/Request.ts +33 -0
- package/src/server/Response.test.ts +31 -0
- package/src/server/Response.ts +27 -0
- package/src/server/Transport.test.ts +294 -0
- package/src/server/Transport.ts +222 -0
- package/src/server/index.ts +8 -0
- package/src/stripe/Charge.integration.test.ts +326 -0
- package/src/stripe/Intents.test.ts +52 -0
- package/src/stripe/Intents.ts +27 -0
- package/src/stripe/client/Charge.ts +119 -0
- package/src/stripe/client/MethodIntents.ts +37 -0
- package/src/stripe/client/index.ts +2 -0
- package/src/stripe/index.ts +1 -0
- package/src/stripe/server/Charge.ts +121 -0
- package/src/stripe/server/MethodIntents.ts +24 -0
- package/src/stripe/server/index.ts +2 -0
- package/src/tempo/Attribution.test.ts +187 -0
- package/src/tempo/Attribution.ts +156 -0
- package/src/tempo/Intents.test.ts +84 -0
- package/src/tempo/Intents.ts +93 -0
- package/src/tempo/client/ChannelOps.ts +233 -0
- package/src/tempo/client/Charge.ts +84 -0
- package/src/tempo/client/MethodIntents.ts +28 -0
- package/src/tempo/client/Session.ts +369 -0
- package/src/tempo/client/SessionManager.test.ts +223 -0
- package/src/tempo/client/SessionManager.ts +270 -0
- package/src/tempo/client/index.ts +5 -0
- package/src/tempo/index.ts +2 -0
- package/src/tempo/internal/account.ts +47 -0
- package/src/tempo/internal/defaults.ts +20 -0
- package/src/tempo/internal/types.ts +8 -0
- package/src/tempo/server/Charge.test.ts +847 -0
- package/src/tempo/server/Charge.ts +309 -0
- package/src/tempo/server/MethodIntents.ts +29 -0
- package/src/tempo/server/Session.test.ts +1349 -0
- package/src/tempo/server/Session.ts +773 -0
- package/src/tempo/server/Sse.test.ts +289 -0
- package/src/tempo/server/index.ts +5 -0
- package/src/tempo/server/internal/transport.ts +153 -0
- package/src/tempo/stream/Chain.ts +333 -0
- package/src/tempo/stream/Channel.ts +50 -0
- package/src/tempo/stream/ChannelStore.test.ts +473 -0
- package/src/tempo/stream/ChannelStore.ts +202 -0
- package/src/tempo/stream/Receipt.test.ts +84 -0
- package/src/tempo/stream/Receipt.ts +45 -0
- package/src/tempo/stream/Sse.test.ts +401 -0
- package/src/tempo/stream/Sse.ts +375 -0
- package/src/tempo/stream/Types.ts +86 -0
- package/src/tempo/stream/Voucher.test.ts +134 -0
- package/src/tempo/stream/Voucher.ts +123 -0
- package/src/tempo/stream/escrow.abi.ts +759 -0
- package/src/tempo/stream/index.ts +7 -0
- package/src/tsconfig.json +10 -0
- package/src/viem/Account.test.ts +71 -0
- package/src/viem/Account.ts +30 -0
- package/src/viem/Client.test.ts +58 -0
- package/src/viem/Client.ts +33 -0
- package/src/zod.ts +47 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as Mppx_core from '../server/Mppx.js'
|
|
2
|
+
import * as Mppx_internal from './internal/mppx.js'
|
|
3
|
+
|
|
4
|
+
export * from '../server/Methods.js'
|
|
5
|
+
|
|
6
|
+
type RouteHandler = (request: Request) => Promise<Response> | Response
|
|
7
|
+
|
|
8
|
+
type NextjsHandler = (handler: RouteHandler) => RouteHandler
|
|
9
|
+
|
|
10
|
+
export namespace Mppx {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Next.js-aware payment handler where each intent
|
|
13
|
+
* returns a wrapper that accepts a route handler.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // app/api/premium/route.ts
|
|
18
|
+
* import { Mppx, tempo } from 'mppx/nextjs'
|
|
19
|
+
*
|
|
20
|
+
* const mppx = Mppx.create({ methods: [tempo()] })
|
|
21
|
+
*
|
|
22
|
+
* export const GET = mppx.charge({ amount: '1' })(() =>
|
|
23
|
+
* Response.json({ data: 'paid content' }),
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function create<const methods extends Mppx_core.Methods>(
|
|
28
|
+
config: Mppx_core.create.Config<methods>,
|
|
29
|
+
): Mppx_internal.Wrap<Mppx_core.Mppx<methods>, NextjsHandler> {
|
|
30
|
+
return Mppx_internal.wrap(Mppx_core.create(config), (intent, options) => {
|
|
31
|
+
return (handler: RouteHandler) => payment(intent, options, handler)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Next.js route handler wrapper that gates a route behind a payment intent.
|
|
38
|
+
*
|
|
39
|
+
* Returns a 402 challenge if no valid credential is provided,
|
|
40
|
+
* otherwise attaches a `Payment-Receipt` header to the response.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // app/api/premium/route.ts
|
|
45
|
+
* import { Mppx } from 'mppx/server'
|
|
46
|
+
* import { payment } from 'mppx/nextjs'
|
|
47
|
+
*
|
|
48
|
+
* const mppx = Mppx.create({ methods: [tempo()] })
|
|
49
|
+
*
|
|
50
|
+
* export const GET = payment(mppx.charge, { amount: '1' }, () =>
|
|
51
|
+
* Response.json({ data: 'paid content' }),
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function payment<const intent extends Mppx_internal.AnyIntentFn>(
|
|
56
|
+
intent: intent,
|
|
57
|
+
options: intent extends (options: infer options) => any ? options : never,
|
|
58
|
+
handler: RouteHandler,
|
|
59
|
+
): RouteHandler {
|
|
60
|
+
return async (request) => {
|
|
61
|
+
const result = await intent(options)(request)
|
|
62
|
+
if (result.status === 402) return result.challenge
|
|
63
|
+
const response = await handler(request)
|
|
64
|
+
return result.withReceipt(response)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { Receipt } from 'mppx'
|
|
2
|
+
import { Mppx as Mppx_client, tempo as tempo_client } from 'mppx/client'
|
|
3
|
+
import { Mppx as Mppx_server, tempo as tempo_server } from 'mppx/server'
|
|
4
|
+
import { afterEach, describe, expect, test } from 'vitest'
|
|
5
|
+
import * as Http from '~test/Http.js'
|
|
6
|
+
import { accounts, asset, client } from '~test/tempo/viem.js'
|
|
7
|
+
import * as ApiProxy from './Proxy.js'
|
|
8
|
+
import * as Service from './Service.js'
|
|
9
|
+
import { anthropic } from './services/anthropic.js'
|
|
10
|
+
import { openai } from './services/openai.js'
|
|
11
|
+
|
|
12
|
+
const mppx_server = Mppx_server.create({
|
|
13
|
+
methods: [
|
|
14
|
+
tempo_server({
|
|
15
|
+
account: accounts[0],
|
|
16
|
+
currency: asset,
|
|
17
|
+
getClient: () => client,
|
|
18
|
+
feePayer: true,
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const mppx_client = Mppx_client.create({
|
|
24
|
+
polyfill: false,
|
|
25
|
+
methods: [
|
|
26
|
+
tempo_client({
|
|
27
|
+
account: accounts[1],
|
|
28
|
+
getClient: () => client,
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
let upstream: Awaited<ReturnType<typeof Http.createServer>> | undefined
|
|
34
|
+
let proxyServer: Awaited<ReturnType<typeof Http.createServer>> | undefined
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
upstream?.close()
|
|
38
|
+
proxyServer?.close()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
function createUpstream(handler: (req: Request) => Response | Promise<Response>) {
|
|
42
|
+
return Http.createServer(async (req, res) => {
|
|
43
|
+
const url = new URL(req.url!, 'http://localhost')
|
|
44
|
+
const chunks: Buffer[] = []
|
|
45
|
+
for await (const chunk of req) chunks.push(chunk)
|
|
46
|
+
const body = chunks.length > 0 ? Buffer.concat(chunks) : undefined
|
|
47
|
+
const request = new Request(url, {
|
|
48
|
+
method: req.method!,
|
|
49
|
+
headers: Object.entries(req.headers).reduce((h, [k, v]) => {
|
|
50
|
+
if (v) h.set(k, Array.isArray(v) ? v.join(', ') : v)
|
|
51
|
+
return h
|
|
52
|
+
}, new Headers()),
|
|
53
|
+
...(body !== undefined && { body }),
|
|
54
|
+
})
|
|
55
|
+
const response = await handler(request)
|
|
56
|
+
res.writeHead(response.status, Object.fromEntries(response.headers))
|
|
57
|
+
const resBody = await response.text()
|
|
58
|
+
if (resBody) res.write(resBody)
|
|
59
|
+
res.end()
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('create', () => {
|
|
64
|
+
test('behavior: GET /services returns service discovery', async () => {
|
|
65
|
+
const proxy = ApiProxy.create({
|
|
66
|
+
services: [
|
|
67
|
+
Service.from('api', {
|
|
68
|
+
baseUrl: 'https://api.example.com',
|
|
69
|
+
routes: {
|
|
70
|
+
'GET /v1/models': true,
|
|
71
|
+
'POST /v1/generate': mppx_server.charge({ amount: '1', description: 'Generate text' }),
|
|
72
|
+
'POST /v1/stream': mppx_server.session({
|
|
73
|
+
amount: '1',
|
|
74
|
+
description: 'Stream text',
|
|
75
|
+
unitType: 'token',
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
})
|
|
81
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
82
|
+
|
|
83
|
+
const res = await fetch(`${proxyServer.url}/services`)
|
|
84
|
+
expect(res.status).toBe(200)
|
|
85
|
+
expect(await res.json()).toMatchInlineSnapshot(`
|
|
86
|
+
[
|
|
87
|
+
{
|
|
88
|
+
"baseUrl": "https://api.example.com",
|
|
89
|
+
"id": "api",
|
|
90
|
+
"routes": [
|
|
91
|
+
{
|
|
92
|
+
"method": "GET",
|
|
93
|
+
"path": "/v1/models",
|
|
94
|
+
"pattern": "GET /v1/models",
|
|
95
|
+
"payment": null,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"method": "POST",
|
|
99
|
+
"path": "/v1/generate",
|
|
100
|
+
"pattern": "POST /v1/generate",
|
|
101
|
+
"payment": {
|
|
102
|
+
"amount": "1000000",
|
|
103
|
+
"currency": "0x20c0000000000000000000000000000000000001",
|
|
104
|
+
"decimals": 6,
|
|
105
|
+
"description": "Generate text",
|
|
106
|
+
"intent": "charge",
|
|
107
|
+
"method": "tempo",
|
|
108
|
+
"recipient": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"method": "POST",
|
|
113
|
+
"path": "/v1/stream",
|
|
114
|
+
"pattern": "POST /v1/stream",
|
|
115
|
+
"payment": {
|
|
116
|
+
"amount": "1000000",
|
|
117
|
+
"currency": "0x20c0000000000000000000000000000000000001",
|
|
118
|
+
"decimals": 6,
|
|
119
|
+
"description": "Stream text",
|
|
120
|
+
"intent": "session",
|
|
121
|
+
"method": "tempo",
|
|
122
|
+
"recipient": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
123
|
+
"unitType": "token",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
]
|
|
129
|
+
`)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('behavior: GET /llms.txt returns markdown', async () => {
|
|
133
|
+
const proxy = ApiProxy.create({
|
|
134
|
+
services: [
|
|
135
|
+
openai({
|
|
136
|
+
apiKey: 'sk-test',
|
|
137
|
+
routes: {
|
|
138
|
+
'POST /v1/chat/completions': mppx_server.charge({
|
|
139
|
+
amount: '0.05',
|
|
140
|
+
description: 'Chat completion',
|
|
141
|
+
}),
|
|
142
|
+
'POST /v1/embeddings': mppx_server.charge({
|
|
143
|
+
amount: '0.01',
|
|
144
|
+
description: 'Generate embeddings',
|
|
145
|
+
}),
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
anthropic({
|
|
149
|
+
apiKey: 'sk-ant-test',
|
|
150
|
+
routes: {
|
|
151
|
+
'POST /v1/messages': mppx_server.charge({
|
|
152
|
+
amount: '0.03',
|
|
153
|
+
description: 'Send message',
|
|
154
|
+
}),
|
|
155
|
+
'POST /v1/messages/stream': mppx_server.session({
|
|
156
|
+
amount: '0.01',
|
|
157
|
+
description: 'Stream message',
|
|
158
|
+
unitType: 'token',
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
],
|
|
163
|
+
})
|
|
164
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
165
|
+
|
|
166
|
+
const res = await fetch(`${proxyServer.url}/llms.txt`)
|
|
167
|
+
expect(res.status).toBe(200)
|
|
168
|
+
expect(res.headers.get('content-type')).toBe('text/plain; charset=utf-8')
|
|
169
|
+
expect(await res.text()).toMatchInlineSnapshot(`
|
|
170
|
+
"# API Proxy
|
|
171
|
+
|
|
172
|
+
> Paid API proxy powered by [Machine Payments Protocol](https://mpp.tempo.xyz).
|
|
173
|
+
|
|
174
|
+
For machine-readable service data, use \`GET /services\` (JSON).
|
|
175
|
+
|
|
176
|
+
## Services
|
|
177
|
+
|
|
178
|
+
- [openai](https://api.openai.com): 2 paid
|
|
179
|
+
- [anthropic](https://api.anthropic.com): 2 paid
|
|
180
|
+
|
|
181
|
+
## openai
|
|
182
|
+
|
|
183
|
+
- \`POST /v1/chat/completions\`: charge — 50000 units — "Chat completion" — (currency: 0x20c0000000000000000000000000000000000001, decimals: 6)
|
|
184
|
+
- \`POST /v1/embeddings\`: charge — 10000 units — "Generate embeddings" — (currency: 0x20c0000000000000000000000000000000000001, decimals: 6)
|
|
185
|
+
|
|
186
|
+
## anthropic
|
|
187
|
+
|
|
188
|
+
- \`POST /v1/messages\`: charge — 30000 units — "Send message" — (currency: 0x20c0000000000000000000000000000000000001, decimals: 6)
|
|
189
|
+
- \`POST /v1/messages/stream\`: session — 10000 units per token — "Stream message" — (currency: 0x20c0000000000000000000000000000000000001, decimals: 6)"
|
|
190
|
+
`)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('behavior: GET /services/:id returns single service', async () => {
|
|
194
|
+
const proxy = ApiProxy.create({
|
|
195
|
+
services: [
|
|
196
|
+
Service.from('api', {
|
|
197
|
+
baseUrl: 'https://api.example.com',
|
|
198
|
+
routes: {
|
|
199
|
+
'GET /v1/models': true,
|
|
200
|
+
'POST /v1/generate': mppx_server.charge({ amount: '1', description: 'Generate text' }),
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
],
|
|
204
|
+
})
|
|
205
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
206
|
+
|
|
207
|
+
const res = await fetch(`${proxyServer.url}/services/api`)
|
|
208
|
+
expect(res.status).toBe(200)
|
|
209
|
+
expect(await res.json()).toMatchInlineSnapshot(`
|
|
210
|
+
{
|
|
211
|
+
"baseUrl": "https://api.example.com",
|
|
212
|
+
"id": "api",
|
|
213
|
+
"routes": [
|
|
214
|
+
{
|
|
215
|
+
"method": "GET",
|
|
216
|
+
"path": "/v1/models",
|
|
217
|
+
"pattern": "GET /v1/models",
|
|
218
|
+
"payment": null,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"method": "POST",
|
|
222
|
+
"path": "/v1/generate",
|
|
223
|
+
"pattern": "POST /v1/generate",
|
|
224
|
+
"payment": {
|
|
225
|
+
"amount": "1000000",
|
|
226
|
+
"currency": "0x20c0000000000000000000000000000000000001",
|
|
227
|
+
"decimals": 6,
|
|
228
|
+
"description": "Generate text",
|
|
229
|
+
"intent": "charge",
|
|
230
|
+
"method": "tempo",
|
|
231
|
+
"recipient": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
}
|
|
236
|
+
`)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('behavior: GET /services/:id returns 404 for unknown', async () => {
|
|
240
|
+
const proxy = ApiProxy.create({ services: [] })
|
|
241
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
242
|
+
const res = await fetch(`${proxyServer.url}/services/unknown`)
|
|
243
|
+
expect(res.status).toBe(404)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('behavior: returns 404 for unknown service', async () => {
|
|
247
|
+
const proxy = ApiProxy.create({ services: [] })
|
|
248
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
249
|
+
const res = await fetch(`${proxyServer.url}/unknown/path`)
|
|
250
|
+
expect(res.status).toBe(404)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('behavior: returns 404 for unmatched route', async () => {
|
|
254
|
+
upstream = await createUpstream(() => Response.json({ ok: true }))
|
|
255
|
+
const proxy = ApiProxy.create({
|
|
256
|
+
services: [
|
|
257
|
+
Service.from('api', {
|
|
258
|
+
baseUrl: upstream.url,
|
|
259
|
+
routes: { 'GET /v1/known': true },
|
|
260
|
+
}),
|
|
261
|
+
],
|
|
262
|
+
})
|
|
263
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
264
|
+
const res = await fetch(`${proxyServer.url}/api/v1/unknown`)
|
|
265
|
+
expect(res.status).toBe(404)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
test('behavior: returns 404 for empty path', async () => {
|
|
269
|
+
const proxy = ApiProxy.create({ services: [] })
|
|
270
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
271
|
+
const res = await fetch(`${proxyServer.url}/`)
|
|
272
|
+
expect(res.status).toBe(404)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test('behavior: proxies upstream when endpoint is true', async () => {
|
|
276
|
+
upstream = await createUpstream((req) => Response.json({ path: new URL(req.url).pathname }))
|
|
277
|
+
const proxy = ApiProxy.create({
|
|
278
|
+
services: [
|
|
279
|
+
Service.from('api', {
|
|
280
|
+
baseUrl: upstream.url,
|
|
281
|
+
routes: { 'GET /v1/status': true },
|
|
282
|
+
}),
|
|
283
|
+
],
|
|
284
|
+
})
|
|
285
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
286
|
+
|
|
287
|
+
const res = await fetch(`${proxyServer.url}/api/v1/status`)
|
|
288
|
+
expect(res.status).toBe(200)
|
|
289
|
+
expect(await res.json()).toEqual({ path: '/v1/status' })
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
test('behavior: returns 402 when no credential', async () => {
|
|
293
|
+
upstream = await createUpstream(() => Response.json({ result: 'ok' }))
|
|
294
|
+
const proxy = ApiProxy.create({
|
|
295
|
+
services: [
|
|
296
|
+
Service.from('api', {
|
|
297
|
+
baseUrl: upstream.url,
|
|
298
|
+
routes: { 'GET /v1/generate': mppx_server.charge({ amount: '1', decimals: 6 }) },
|
|
299
|
+
}),
|
|
300
|
+
],
|
|
301
|
+
})
|
|
302
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
303
|
+
|
|
304
|
+
const res = await fetch(`${proxyServer.url}/api/v1/generate`)
|
|
305
|
+
expect(res.status).toBe(402)
|
|
306
|
+
expect(res.headers.get('WWW-Authenticate')).toContain('Payment')
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test('behavior: full 402 flow with mppx client', async () => {
|
|
310
|
+
upstream = await createUpstream((req) => Response.json({ path: new URL(req.url).pathname }))
|
|
311
|
+
const proxy = ApiProxy.create({
|
|
312
|
+
services: [
|
|
313
|
+
Service.from('api', {
|
|
314
|
+
baseUrl: upstream.url,
|
|
315
|
+
bearer: 'sk-upstream-key',
|
|
316
|
+
routes: { 'GET /v1/generate': mppx_server.charge({ amount: '1', decimals: 6 }) },
|
|
317
|
+
}),
|
|
318
|
+
],
|
|
319
|
+
})
|
|
320
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
321
|
+
|
|
322
|
+
const res = await mppx_client.fetch(`${proxyServer.url}/api/v1/generate`)
|
|
323
|
+
expect(res.status).toBe(200)
|
|
324
|
+
expect(await res.json()).toEqual({ path: '/v1/generate' })
|
|
325
|
+
|
|
326
|
+
const receipt = Receipt.fromResponse(res)
|
|
327
|
+
expect(receipt.status).toBe('success')
|
|
328
|
+
expect(receipt.method).toBe('tempo')
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
test('behavior: injects bearer token to upstream', async () => {
|
|
332
|
+
upstream = await createUpstream((req) =>
|
|
333
|
+
Response.json({ auth: req.headers.get('authorization') }),
|
|
334
|
+
)
|
|
335
|
+
const proxy = ApiProxy.create({
|
|
336
|
+
services: [
|
|
337
|
+
Service.from('api', {
|
|
338
|
+
baseUrl: upstream.url,
|
|
339
|
+
bearer: 'sk-test-123',
|
|
340
|
+
routes: { 'GET /v1/data': mppx_server.charge({ amount: '1', decimals: 6 }) },
|
|
341
|
+
}),
|
|
342
|
+
],
|
|
343
|
+
})
|
|
344
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
345
|
+
|
|
346
|
+
const res = await mppx_client.fetch(`${proxyServer.url}/api/v1/data`)
|
|
347
|
+
expect(res.status).toBe(200)
|
|
348
|
+
expect(await res.json()).toEqual({ auth: 'Bearer sk-test-123' })
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
test('behavior: injects custom header to upstream', async () => {
|
|
352
|
+
upstream = await createUpstream((req) => Response.json({ key: req.headers.get('x-api-key') }))
|
|
353
|
+
const proxy = ApiProxy.create({
|
|
354
|
+
services: [
|
|
355
|
+
Service.from('api', {
|
|
356
|
+
baseUrl: upstream.url,
|
|
357
|
+
headers: { 'X-Api-Key': 'secret' },
|
|
358
|
+
routes: { 'GET /v1/data': mppx_server.charge({ amount: '1', decimals: 6 }) },
|
|
359
|
+
}),
|
|
360
|
+
],
|
|
361
|
+
})
|
|
362
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
363
|
+
|
|
364
|
+
const res = await mppx_client.fetch(`${proxyServer.url}/api/v1/data`)
|
|
365
|
+
expect(res.status).toBe(200)
|
|
366
|
+
expect(await res.json()).toEqual({ key: 'secret' })
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
test('behavior: auth injected for free passthrough', async () => {
|
|
370
|
+
upstream = await createUpstream((req) =>
|
|
371
|
+
Response.json({ auth: req.headers.get('authorization') }),
|
|
372
|
+
)
|
|
373
|
+
const proxy = ApiProxy.create({
|
|
374
|
+
services: [
|
|
375
|
+
Service.from('api', {
|
|
376
|
+
baseUrl: upstream.url,
|
|
377
|
+
bearer: 'sk-test-123',
|
|
378
|
+
routes: { 'GET /v1/public': true },
|
|
379
|
+
}),
|
|
380
|
+
],
|
|
381
|
+
})
|
|
382
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
383
|
+
|
|
384
|
+
const res = await fetch(`${proxyServer.url}/api/v1/public`)
|
|
385
|
+
expect(await res.json()).toEqual({ auth: 'Bearer sk-test-123' })
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
test('behavior: strips incoming authorization from upstream', async () => {
|
|
389
|
+
upstream = await createUpstream((req) =>
|
|
390
|
+
Response.json({ auth: req.headers.get('authorization') }),
|
|
391
|
+
)
|
|
392
|
+
const proxy = ApiProxy.create({
|
|
393
|
+
services: [
|
|
394
|
+
Service.from('api', {
|
|
395
|
+
baseUrl: upstream.url,
|
|
396
|
+
routes: { 'GET /v1/data': true },
|
|
397
|
+
}),
|
|
398
|
+
],
|
|
399
|
+
})
|
|
400
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
401
|
+
|
|
402
|
+
const res = await fetch(`${proxyServer.url}/api/v1/data`, {
|
|
403
|
+
headers: { Authorization: 'Payment credential=abc' },
|
|
404
|
+
})
|
|
405
|
+
expect(await res.json()).toEqual({ auth: null })
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
test('behavior: preserves safe headers', async () => {
|
|
409
|
+
upstream = await createUpstream((req) =>
|
|
410
|
+
Response.json({
|
|
411
|
+
accept: req.headers.get('accept'),
|
|
412
|
+
}),
|
|
413
|
+
)
|
|
414
|
+
const proxy = ApiProxy.create({
|
|
415
|
+
services: [
|
|
416
|
+
Service.from('api', {
|
|
417
|
+
baseUrl: upstream.url,
|
|
418
|
+
routes: { 'GET /v1/data': true },
|
|
419
|
+
}),
|
|
420
|
+
],
|
|
421
|
+
})
|
|
422
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
423
|
+
|
|
424
|
+
const res = await fetch(`${proxyServer.url}/api/v1/data`, {
|
|
425
|
+
headers: { Accept: 'application/json' },
|
|
426
|
+
})
|
|
427
|
+
expect(await res.json()).toEqual({ accept: 'application/json' })
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
test('behavior: forwards request body to upstream', async () => {
|
|
431
|
+
upstream = await createUpstream(async (req) => {
|
|
432
|
+
const body = await req.text()
|
|
433
|
+
return Response.json({ method: req.method, body: JSON.parse(body) })
|
|
434
|
+
})
|
|
435
|
+
const proxy = ApiProxy.create({
|
|
436
|
+
services: [
|
|
437
|
+
Service.from('api', {
|
|
438
|
+
baseUrl: upstream.url,
|
|
439
|
+
routes: { 'POST /v1/generate': true },
|
|
440
|
+
}),
|
|
441
|
+
],
|
|
442
|
+
})
|
|
443
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
444
|
+
|
|
445
|
+
const res = await fetch(`${proxyServer.url}/api/v1/generate`, {
|
|
446
|
+
method: 'POST',
|
|
447
|
+
headers: { 'Content-Type': 'application/json' },
|
|
448
|
+
body: JSON.stringify({ model: 'gpt-4', prompt: 'hello' }),
|
|
449
|
+
})
|
|
450
|
+
expect(res.status).toBe(200)
|
|
451
|
+
expect(await res.json()).toEqual({
|
|
452
|
+
method: 'POST',
|
|
453
|
+
body: { model: 'gpt-4', prompt: 'hello' },
|
|
454
|
+
})
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
test('behavior: forwards query params to upstream', async () => {
|
|
458
|
+
upstream = await createUpstream((req) => Response.json({ search: new URL(req.url).search }))
|
|
459
|
+
const proxy = ApiProxy.create({
|
|
460
|
+
services: [
|
|
461
|
+
Service.from('api', {
|
|
462
|
+
baseUrl: upstream.url,
|
|
463
|
+
routes: { 'GET /v1/search': true },
|
|
464
|
+
}),
|
|
465
|
+
],
|
|
466
|
+
})
|
|
467
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
468
|
+
|
|
469
|
+
const res = await fetch(`${proxyServer.url}/api/v1/search?q=hello&limit=10`)
|
|
470
|
+
expect(await res.json()).toEqual({ search: '?q=hello&limit=10' })
|
|
471
|
+
})
|
|
472
|
+
})
|