mppx 0.11.0 → 0.13.1

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.
Files changed (126) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +22 -1
  3. package/dist/Method.d.ts +7 -1
  4. package/dist/Method.js +7 -2
  5. package/dist/Receipt.d.ts +2 -0
  6. package/dist/Receipt.js +2 -0
  7. package/dist/cli/agent.d.ts +3 -0
  8. package/dist/cli/agent.js +20 -0
  9. package/dist/cli/cli.d.ts +9 -1
  10. package/dist/cli/cli.js +134 -136
  11. package/dist/cli/plugins/index.js +12 -14
  12. package/dist/cli/plugins/tempo.js +9 -2
  13. package/dist/cli/utils.d.ts +11 -1
  14. package/dist/cli/utils.js +15 -2
  15. package/dist/cli/validate/challenge.d.ts +2 -0
  16. package/dist/cli/validate/challenge.js +19 -4
  17. package/dist/cli/validate/discovery.d.ts +1 -0
  18. package/dist/cli/validate/discovery.js +10 -1
  19. package/dist/cli/validate/payment.js +63 -24
  20. package/dist/client/Methods.d.ts +0 -2
  21. package/dist/client/Methods.js +0 -2
  22. package/dist/client/Mppx.js +1 -0
  23. package/dist/client/index.d.ts +1 -1
  24. package/dist/client/index.js +1 -1
  25. package/dist/client/internal/Fetch.d.ts +2 -0
  26. package/dist/client/internal/Fetch.js +8 -2
  27. package/dist/client/internal/MethodChallenge.d.ts +1 -0
  28. package/dist/evm/Types.js +1 -1
  29. package/dist/evm/server/Charge.js +5 -0
  30. package/dist/evm/server/Methods.d.ts +164 -3
  31. package/dist/evm/server/Methods.js +50 -2
  32. package/dist/integrations/x402/Evm.js +4 -3
  33. package/dist/internal/HeaderCodec.d.ts +2 -2
  34. package/dist/internal/version.d.ts +2 -2
  35. package/dist/internal/version.js +1 -1
  36. package/dist/mcp/client/McpClient.js +4 -7
  37. package/dist/middlewares/elysia.d.ts +11 -8
  38. package/dist/middlewares/elysia.js +67 -14
  39. package/dist/middlewares/express.js +13 -6
  40. package/dist/middlewares/hono.js +4 -4
  41. package/dist/middlewares/nextjs.js +9 -5
  42. package/dist/proxy/internal/Headers.js +65 -0
  43. package/dist/proxy/services/stripe.js +1 -0
  44. package/dist/server/Mppx.d.ts +18 -2
  45. package/dist/server/Mppx.js +204 -92
  46. package/dist/server/NodeListener.js +71 -6
  47. package/dist/server/Request.d.ts +11 -1
  48. package/dist/server/Request.js +132 -13
  49. package/dist/server/Transport.d.ts +14 -1
  50. package/dist/server/Transport.js +1 -0
  51. package/dist/server/internal/html/compose.main.gen.d.ts +1 -1
  52. package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
  53. package/dist/stripe/server/Methods.d.ts +10 -3
  54. package/dist/stripe/server/Methods.js +19 -6
  55. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  56. package/dist/stripe/server/internal/html.gen.js +1 -1
  57. package/dist/tempo/Methods.d.ts +1 -0
  58. package/dist/tempo/Methods.js +1 -0
  59. package/dist/tempo/client/Charge.js +17 -13
  60. package/dist/tempo/client/Methods.d.ts +1 -5
  61. package/dist/tempo/client/Methods.js +10 -5
  62. package/dist/tempo/client/ResolveAccount.d.ts +3 -0
  63. package/dist/tempo/client/index.d.ts +0 -3
  64. package/dist/tempo/client/index.js +0 -2
  65. package/dist/tempo/internal/currencies.d.ts +19 -0
  66. package/dist/tempo/internal/currencies.js +41 -0
  67. package/dist/tempo/internal/defaults.d.ts +5 -3
  68. package/dist/tempo/internal/defaults.js +6 -2
  69. package/dist/tempo/internal/fee-payer.d.ts +11 -7
  70. package/dist/tempo/internal/fee-payer.js +30 -11
  71. package/dist/tempo/internal/machine-token-charge.d.ts +23 -0
  72. package/dist/tempo/internal/machine-token-charge.js +2 -1
  73. package/dist/tempo/legacy/index.d.ts +1 -3
  74. package/dist/tempo/legacy/index.js +1 -3
  75. package/dist/tempo/server/Charge.d.ts +12 -1
  76. package/dist/tempo/server/Charge.js +109 -78
  77. package/dist/tempo/server/Methods.d.ts +5048 -40
  78. package/dist/tempo/server/Methods.js +104 -13
  79. package/dist/tempo/server/Subscription.d.ts +1 -1
  80. package/dist/tempo/server/Subscription.js +31 -4
  81. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  82. package/dist/tempo/server/internal/html.gen.js +1 -1
  83. package/dist/tempo/server/internal/transport.js +28 -11
  84. package/dist/tempo/session/client/ChannelOps.js +5 -0
  85. package/dist/tempo/session/client/Session.d.ts +1 -0
  86. package/dist/tempo/session/client/Session.js +7 -4
  87. package/dist/tempo/session/client/SessionManager.js +3 -0
  88. package/dist/tempo/session/client/Transports.d.ts +8 -1
  89. package/dist/tempo/session/client/Transports.js +12 -3
  90. package/dist/tempo/session/precompile/Chain.js +16 -1
  91. package/dist/tempo/session/precompile/Protocol.d.ts +2 -0
  92. package/dist/tempo/session/precompile/Voucher.d.ts +16 -0
  93. package/dist/tempo/session/precompile/Voucher.js +48 -0
  94. package/dist/tempo/session/server/ChannelStore.d.ts +22 -2
  95. package/dist/tempo/session/server/ChannelStore.js +37 -7
  96. package/dist/tempo/session/server/CredentialVerification.d.ts +6 -1
  97. package/dist/tempo/session/server/CredentialVerification.js +56 -19
  98. package/dist/tempo/session/server/MeteredStream.d.ts +3 -2
  99. package/dist/tempo/session/server/MeteredStream.js +85 -29
  100. package/dist/tempo/session/server/RequestState.d.ts +6 -0
  101. package/dist/tempo/session/server/RequestState.js +11 -4
  102. package/dist/tempo/session/server/Session.d.ts +2 -1
  103. package/dist/tempo/session/server/Session.js +10 -2
  104. package/dist/tempo/session/server/Settlement.d.ts +23 -0
  105. package/dist/tempo/session/server/Settlement.js +105 -25
  106. package/dist/tempo/session/server/Sse.d.ts +3 -1
  107. package/dist/tempo/session/server/Sse.js +105 -32
  108. package/dist/tempo/session/server/Transports.d.ts +24 -19
  109. package/dist/tempo/session/server/Transports.js +169 -58
  110. package/dist/tempo/session/server/Ws.d.ts +5 -1
  111. package/dist/tempo/session/server/Ws.js +75 -20
  112. package/dist/tempo/subscription/KeyAuthorization.d.ts +70 -8
  113. package/dist/tempo/subscription/Store.d.ts +2 -0
  114. package/dist/tempo/subscription/Store.js +3 -0
  115. package/dist/validation/core.js +2 -1
  116. package/dist/x402/server/EvmCharge.d.ts +3 -1
  117. package/dist/x402/server/EvmCharge.js +14 -1
  118. package/package.json +8 -8
  119. package/dist/tempo/legacy/client/ChannelOps.d.ts +0 -69
  120. package/dist/tempo/legacy/client/ChannelOps.js +0 -168
  121. package/dist/tempo/legacy/client/Session.d.ts +0 -185
  122. package/dist/tempo/legacy/client/Session.js +0 -279
  123. package/dist/tempo/legacy/client/SessionManager.d.ts +0 -100
  124. package/dist/tempo/legacy/client/SessionManager.js +0 -706
  125. package/dist/tempo/legacy/client/index.d.ts +0 -7
  126. package/dist/tempo/legacy/client/index.js +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,88 @@
1
1
  # mppx
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ec6c6cf: Added paired Elysia lifecycle hooks that wrapped actual route responses for streaming metering. Rejected streaming payments registered with only a beforeHandle hook and required Elysia 1.2.0 or newer.
8
+ - 86dddc8: Stopped emitting payment-success events when authorization reused existing access without verifying a new credential.
9
+ - e60b7ea: Settled previously accepted vouchers when terminal voucher processing detected a pending channel close, using the existing shared scheduled-settlement claim. Kept standalone validation free of settlement side effects.
10
+ - cfb4bff: Reserved stream charges atomically in shared channel state and released or expired unused reservations.
11
+
12
+ ## 0.13.0
13
+
14
+ ### Minor Changes
15
+
16
+ - e6f903f: Required shared replay storage for Stripe Tempo payment methods.
17
+ - 44b9115: Removed the deprecated legacy session client exports.
18
+
19
+ ### Patch Changes
20
+
21
+ - e73cd68: Fixed Node server responses so streams stopped when clients disconnected.
22
+ - eb888ab: Fixed server request handling so bodies were bounded and backpressured.
23
+ - 22c0633: Fixed proxy requests so payment authorization was not forwarded upstream.
24
+ - beceee5: Fixed proxy responses so payment-specific headers were stripped.
25
+ - 47e2faf: Fixed Stripe proxy requests so caller routing headers were removed.
26
+ - e2bfcf3: Fixed CLI discovery so untrusted origins were rejected.
27
+ - b224b23: Fixed EVM nonce hashing so input fields were framed unambiguously.
28
+ - 4bdad2b: Fixed Tempo SSE parsing so standard line endings were accepted.
29
+ - e66245d: Fixed MCP payments so the selected payment method was used.
30
+ - 8c42db6: Fixed Tempo transaction credentials so proofs were bound to their source account.
31
+ - 23499aa: Fixed composed server methods so credential headers remained scoped to their transports.
32
+ - 3fc6dd4: Fixed x402 verification so route-bound credentials were required by default.
33
+ - 7e6a86a: Fixed CLI credential retries so requests remained pinned to the challenge origin.
34
+ - 7c91998: Fixed CLI challenge handling so mismatched payment realms were rejected.
35
+ - 8bfe2d1: Fixed middleware payment challenges so credentials were bound to routes.
36
+ - 8bfeb03: Fixed manual session streams so terminal charges were committed.
37
+ - 52b88c6: Fixed session charging so the final retry result was validated.
38
+ - adc5c07: Fixed Tempo sessions so expected chain pins were applied.
39
+ - f9c56d8: Fixed Tempo payment proofs so signer accounts were resolved correctly.
40
+ - ad11f54: Fixed subscriptions so pending renewal credentials were rejected.
41
+ - f14f1ee: Fixed CLI token approvals so configured decimals were verified.
42
+ - c301267: Fixed session channel waits so timed-out callers were cancelled.
43
+ - 91eed32: Fixed session WebSocket input so oversized frames were rejected.
44
+ - f823c86: Fixed session management requests so nested operations honored cancellation.
45
+ - 6568964: Fixed session SSE streams so values were pulled with backpressure.
46
+ - d40dfbd: Fixed session WebSocket output so buffered data remained bounded.
47
+ - e77e9c3: Fixed hosted session sponsorship so configured policy was enforced.
48
+ - 9076794: Fixed sponsored access keys so installation required explicit opt-in.
49
+ - dcee2e8: Fixed sponsored subscriptions so fee tokens were restricted to configured tokens.
50
+ - a7eb66a: Fixed x402 compatibility offers so their payment lifecycle remained safe.
51
+ - 25952d3: Fixed cooperative session closes so close credentials were authorized.
52
+ - 909ccc1: Fixed sponsored session calls so supported call payloads were canonicalized.
53
+ - f431415: Fixed session voucher acceptance so channel state was refreshed before validation.
54
+ - 2afa94d: Fixed scheduled session settlements so concurrent workers claimed each settlement atomically.
55
+ - bd96362: Fixed bodyless session responses so payment accounting completed before protected handlers continued.
56
+ - c7968ca: Added optional funding currency metadata to Tempo charge receipts for verified direct, MACH, and DEX auto-swap payment routes.
57
+
58
+ ## 0.12.0
59
+
60
+ ### Minor Changes
61
+
62
+ - e4f0e02: Added ordered `currencies` configuration to the Tempo and EVM server factories, with OUSD followed by USDC.e on Tempo mainnet and OUSD followed by pathUSD on Moderato. Added chain-aware viem token-set support and deprecated the factories' singular `currency` option. Explicit currency configuration continued to restrict acceptance to that currency.
63
+
64
+ Changed `tempo.charge()`, `tempo.session()`, and `tempo.subscription()` to return ordered method groups. Existing `methods: [tempo.charge(options)]` configuration remained supported. Code inspecting a single method directly must now destructure the returned group; explicit composition should use configured handlers such as `mppx.tempo.charge`. Wire Challenges and per-handler currency overrides remained singular.
65
+
66
+ Preserved offer selection, callbacks, and error responses through nested composition. Preserved proof replay policy without a configured store and honored explicit charge chain IDs. Shared session storage and settlement dispatch across accepted currencies, applied settlement thresholds using each channel's currency, and initialized session extensions without mutating previously created methods. Preserved each existing subscription's authorized currency during reuse and renewal, and defaulted new subscription offers to mainnet, with `testnet: true` selecting Moderato.
67
+
68
+ Reduced package size by removing duplicated HTML bundle literals from generated type declarations.
69
+
70
+ Pinned workspace viem dependencies to the public `2.57.1` release and required `viem >=2.57.1` as a peer dependency.
71
+
72
+ ### Patch Changes
73
+
74
+ - 1d08567: Added AI agent attribution to the CLI User-Agent header when a recognized environment signal is present.
75
+ - 869885e: Added `allowedFeeTokens` for sponsored Tempo charges. Preserved local token defaults and allowed hosted sponsors to choose their fee token unless explicitly restricted.
76
+ - 3a23894: Fixed implicit and explicit composition to preserve each configured method's identity, currency defaults, and offer order. Resolved standalone credentials against configured request bindings, rejected ambiguous method matches, and limited per-method payment success hooks to the selected method.
77
+ - dcf1589: Fixed CLI agent attribution test isolation across agent environments.
78
+ - 75cb219: Fixed hosted fee sponsorship for credential-triggered Tempo session settlement and close.
79
+ - fe2e66e: Fixed split-charge verification to reject payment transfers with attribution memos bound to conflicting challenges or realms.
80
+ - 8d2fb06: Fixed Tempo session content requests to require a voucher advance before charging, preventing an accepted cumulative voucher from authorizing multiple responses while preserving idempotent management updates.
81
+ - 8829293: Allowed `hostedFeePayer: true` in Stripe test mode by applying hosted fee sponsorship only in live mode.
82
+ - 8405b23: Fixed Stripe sandbox sessions to use Tempo testnet.
83
+ - 7159693: Fixed testnet validation of streaming Tempo sessions.
84
+ - 420b99b: Added automatic testnet faucet funding for session operators in `mppx validate`.
85
+
3
86
  ## 0.11.0
4
87
 
5
88
  ### Minor Changes
package/README.md CHANGED
@@ -51,7 +51,6 @@ import { Mppx, tempo } from 'mppx/server'
51
51
  const mppx = Mppx.create({
52
52
  methods: [
53
53
  tempo({
54
- currency: '0x20c0000000000000000000000000000000000000',
55
54
  recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
56
55
  }),
57
56
  ],
@@ -226,3 +225,25 @@ Built on the ["Payment" HTTP Authentication Scheme](https://datatracker.ietf.org
226
225
  ## License
227
226
 
228
227
  MIT
228
+
229
+ ### Accepted Tempo currencies
230
+
231
+ `tempo()`, `tempo.charge()`, `tempo.session()`, and `tempo.subscription()` offer OUSD first, followed by USDC.e on mainnet or pathUSD on Moderato (`testnet: true`). Each factory returns a group accepted directly by `Mppx.create`. Clients choose one offer; ordering does not trigger an automatic swap.
232
+
233
+ ```ts
234
+ import { Mppx, tempo } from 'mppx/server'
235
+ import { ousd, usdce } from 'viem/tokens'
236
+
237
+ const mppx = Mppx.create({
238
+ methods: [
239
+ tempo.charge({
240
+ currencies: [ousd, usdce],
241
+ recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
242
+ }),
243
+ ],
244
+ })
245
+ ```
246
+
247
+ Omit `currencies` for the network defaults, or use `currencies: [ousd]` to accept only OUSD on mainnet. Explicit lists replace the defaults. The deprecated `currency` option also restricts acceptance to one token. Wire requests and handler overrides continue to use singular `currency`.
248
+
249
+ Use configured handlers such as `mppx.tempo.charge` when composing payments. Code that directly inspects a Method can destructure the group: `const [charge] = tempo.charge({ currencies: [ousd] })`. Existing sessions and subscriptions continue using their originally authorized currency.
package/dist/Method.d.ts CHANGED
@@ -84,7 +84,10 @@ export type VerifyContext<method extends Method> = {
84
84
  request: z.input<method['schema']['request']>;
85
85
  };
86
86
  /** Validation hook parameters for a single method. */
87
- export type ValidateContext<method extends Method> = VerifyContext<method>;
87
+ export type ValidateContext<method extends Method> = VerifyContext<method> & {
88
+ /** Whether validation is standalone or immediately precedes terminal broadcast. */
89
+ operation?: 'broadcast' | 'validate' | undefined;
90
+ };
88
91
  /** Response hook parameters for a single method. */
89
92
  export type RespondContext<method extends Method> = VerifyContext<method> & {
90
93
  input: globalThis.Request;
@@ -223,6 +226,9 @@ export type RequestFn<method extends Method> = (options: RequestContext<method>)
223
226
  * a server grant access based on existing application state (for example, an
224
227
  * active subscription) without requiring a fresh `Payment` credential.
225
228
  *
229
+ * Authorization does not emit `payment.success`; use method lifecycle hooks for
230
+ * payments performed during authorization.
231
+ *
226
232
  * **HTTP-only.** The `input` parameter is a Fetch `Request`; non-HTTP transports
227
233
  * do not invoke this hook.
228
234
  *
package/dist/Method.js CHANGED
@@ -47,6 +47,7 @@ export async function validateCredential(methods, input) {
47
47
  });
48
48
  return prepared.method.validate({
49
49
  credential: prepared.credential,
50
+ operation: 'validate',
50
51
  request: prepared.request,
51
52
  });
52
53
  }
@@ -60,7 +61,11 @@ export async function broadcastCredential(methods, input) {
60
61
  const prepared = prepareCredential(methods, input);
61
62
  const { method } = prepared;
62
63
  if (method.broadcast && method.validate)
63
- await method.validate({ credential: prepared.credential, request: prepared.request });
64
+ await method.validate({
65
+ credential: prepared.credential,
66
+ operation: 'broadcast',
67
+ request: prepared.request,
68
+ });
64
69
  const broadcast = method.broadcast ?? method.verify;
65
70
  return broadcast({ credential: prepared.credential, request: prepared.request });
66
71
  }
@@ -144,7 +149,7 @@ export function toServer(method, options) {
144
149
  const effectiveVerify = verify ??
145
150
  (async (parameters) => {
146
151
  if (validate)
147
- await validate(parameters);
152
+ await validate({ ...parameters, operation: 'broadcast' });
148
153
  if (!broadcast)
149
154
  throw new Errors.VerificationFailedError({
150
155
  reason: `${method.name}/${method.intent} does not support credential broadcast`,
package/dist/Receipt.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as z from './zod.js';
2
2
  /** Base-field schema used only to derive the {@link Receipt} type without an index signature. */
3
3
  declare const BaseSchema: z.ZodMiniObject<{
4
+ fundingCurrency: z.ZodMiniOptional<z.ZodMiniString<string>>;
4
5
  method: z.ZodMiniString<string>;
5
6
  reference: z.ZodMiniString<string>;
6
7
  externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -23,6 +24,7 @@ declare const BaseSchema: z.ZodMiniObject<{
23
24
  * ```
24
25
  */
25
26
  export declare const Schema: z.ZodMiniObject<{
27
+ fundingCurrency: z.ZodMiniOptional<z.ZodMiniString<string>>;
26
28
  method: z.ZodMiniString<string>;
27
29
  reference: z.ZodMiniString<string>;
28
30
  externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
package/dist/Receipt.js CHANGED
@@ -2,6 +2,8 @@ import { Base64 } from 'ox';
2
2
  import * as Constants from './Constants.js';
3
3
  import * as z from './zod.js';
4
4
  const shape = {
5
+ /** Currency actually debited to fund the payment, when known. */
6
+ fundingCurrency: z.optional(z.string()),
5
7
  /** Payment method used (e.g., "tempo", "stripe"). */
6
8
  method: z.string(),
7
9
  /** Method-specific reference (e.g., transaction hash). */
@@ -0,0 +1,3 @@
1
+ /** Returns the first recognized AI agent in signal priority order. */
2
+ export declare function detectAgent(env?: NodeJS.ProcessEnv): string | undefined;
3
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,20 @@
1
+ const agentSignals = [
2
+ ['ANTIGRAVITY_CLI_ALIAS', 'antigravity'],
3
+ ['CLAUDECODE', 'claude_code'],
4
+ ['CLINE_ACTIVE', 'cline'],
5
+ ['CODEX_SANDBOX', 'codex_cli'],
6
+ ['CODEX_THREAD_ID', 'codex_cli'],
7
+ ['CODEX_SANDBOX_NETWORK_DISABLED', 'codex_cli'],
8
+ ['CODEX_CI', 'codex_cli'],
9
+ ['CURSOR_AGENT', 'cursor'],
10
+ ['GEMINI_CLI', 'gemini_cli'],
11
+ ['OPENCODE', 'open_code'],
12
+ ['OPENCLAW_SHELL', 'openclaw'],
13
+ ['CLAUDE_CODE_ENTRYPOINT', 'claude_code'],
14
+ ['CODEX_INTERNAL_ORIGINATOR_OVERRIDE', 'codex_cli'],
15
+ ];
16
+ /** Returns the first recognized AI agent in signal priority order. */
17
+ export function detectAgent(env = process.env) {
18
+ return agentSignals.find(([variable]) => env[variable])?.[1];
19
+ }
20
+ //# sourceMappingURL=agent.js.map
package/dist/cli/cli.d.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  import { Cli } from 'incur';
2
+ /** Resolves a credential retry without allowing an MPP challenge redirect to change origins. */
3
+ export declare function resolveMppCredentialTarget(initialUrl: string, _initialTarget: {
4
+ host?: string | undefined;
5
+ url: string;
6
+ }, responseUrl: string): {
7
+ host?: string | undefined;
8
+ url: string;
9
+ };
2
10
  declare const cli: Cli.Cli<{
3
11
  mppx: {
4
12
  args: {
@@ -26,7 +34,7 @@ declare const cli: Cli.Cli<{
26
34
  session: string;
27
35
  silent: boolean;
28
36
  slippage?: number | undefined;
29
- userAgent: string;
37
+ userAgent?: string | undefined;
30
38
  verbose: number;
31
39
  };
32
40
  };