mppx 0.12.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 (108) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/Method.d.ts +7 -1
  3. package/dist/Method.js +7 -2
  4. package/dist/Receipt.d.ts +2 -0
  5. package/dist/Receipt.js +2 -0
  6. package/dist/cli/cli.d.ts +8 -0
  7. package/dist/cli/cli.js +134 -136
  8. package/dist/cli/plugins/index.js +12 -14
  9. package/dist/cli/plugins/tempo.js +9 -2
  10. package/dist/cli/utils.d.ts +11 -1
  11. package/dist/cli/utils.js +15 -2
  12. package/dist/cli/validate/challenge.d.ts +2 -0
  13. package/dist/cli/validate/challenge.js +19 -4
  14. package/dist/cli/validate/discovery.d.ts +1 -0
  15. package/dist/cli/validate/discovery.js +10 -1
  16. package/dist/cli/validate/payment.js +34 -12
  17. package/dist/client/Methods.d.ts +0 -2
  18. package/dist/client/Methods.js +0 -2
  19. package/dist/client/Mppx.js +1 -0
  20. package/dist/client/index.d.ts +1 -1
  21. package/dist/client/index.js +1 -1
  22. package/dist/client/internal/Fetch.d.ts +2 -0
  23. package/dist/client/internal/Fetch.js +8 -2
  24. package/dist/client/internal/MethodChallenge.d.ts +1 -0
  25. package/dist/evm/Types.js +1 -1
  26. package/dist/evm/server/Charge.js +5 -0
  27. package/dist/integrations/x402/Evm.js +4 -3
  28. package/dist/internal/HeaderCodec.d.ts +2 -2
  29. package/dist/internal/version.d.ts +2 -2
  30. package/dist/internal/version.js +1 -1
  31. package/dist/mcp/client/McpClient.js +4 -7
  32. package/dist/middlewares/elysia.d.ts +11 -8
  33. package/dist/middlewares/elysia.js +67 -14
  34. package/dist/middlewares/express.js +13 -6
  35. package/dist/middlewares/hono.js +4 -4
  36. package/dist/middlewares/nextjs.js +9 -5
  37. package/dist/proxy/internal/Headers.js +65 -0
  38. package/dist/proxy/services/stripe.js +1 -0
  39. package/dist/server/Mppx.d.ts +13 -1
  40. package/dist/server/Mppx.js +85 -44
  41. package/dist/server/NodeListener.js +71 -6
  42. package/dist/server/Request.d.ts +11 -1
  43. package/dist/server/Request.js +132 -13
  44. package/dist/server/Transport.d.ts +14 -1
  45. package/dist/server/Transport.js +1 -0
  46. package/dist/stripe/server/Methods.d.ts +10 -3
  47. package/dist/stripe/server/Methods.js +17 -2
  48. package/dist/stripe/server/internal/html.gen.js +1 -1
  49. package/dist/tempo/Methods.d.ts +1 -0
  50. package/dist/tempo/Methods.js +1 -0
  51. package/dist/tempo/client/Charge.js +17 -13
  52. package/dist/tempo/client/Methods.d.ts +1 -5
  53. package/dist/tempo/client/Methods.js +10 -5
  54. package/dist/tempo/client/ResolveAccount.d.ts +3 -0
  55. package/dist/tempo/client/index.d.ts +0 -3
  56. package/dist/tempo/client/index.js +0 -2
  57. package/dist/tempo/internal/fee-payer.d.ts +6 -3
  58. package/dist/tempo/internal/fee-payer.js +23 -6
  59. package/dist/tempo/internal/machine-token-charge.d.ts +23 -0
  60. package/dist/tempo/internal/machine-token-charge.js +2 -1
  61. package/dist/tempo/legacy/index.d.ts +1 -3
  62. package/dist/tempo/legacy/index.js +1 -3
  63. package/dist/tempo/server/Charge.js +75 -46
  64. package/dist/tempo/server/Methods.d.ts +55 -10
  65. package/dist/tempo/server/Subscription.d.ts +1 -1
  66. package/dist/tempo/server/Subscription.js +31 -4
  67. package/dist/tempo/server/internal/html.gen.js +1 -1
  68. package/dist/tempo/server/internal/transport.js +28 -11
  69. package/dist/tempo/session/client/ChannelOps.js +5 -0
  70. package/dist/tempo/session/client/Session.d.ts +1 -0
  71. package/dist/tempo/session/client/Session.js +7 -4
  72. package/dist/tempo/session/client/SessionManager.js +3 -0
  73. package/dist/tempo/session/client/Transports.d.ts +8 -1
  74. package/dist/tempo/session/client/Transports.js +12 -3
  75. package/dist/tempo/session/precompile/Chain.js +16 -1
  76. package/dist/tempo/session/precompile/Protocol.d.ts +2 -0
  77. package/dist/tempo/session/precompile/Voucher.d.ts +16 -0
  78. package/dist/tempo/session/precompile/Voucher.js +48 -0
  79. package/dist/tempo/session/server/ChannelStore.d.ts +20 -2
  80. package/dist/tempo/session/server/ChannelStore.js +25 -4
  81. package/dist/tempo/session/server/CredentialVerification.d.ts +4 -1
  82. package/dist/tempo/session/server/CredentialVerification.js +34 -6
  83. package/dist/tempo/session/server/MeteredStream.d.ts +3 -2
  84. package/dist/tempo/session/server/MeteredStream.js +85 -29
  85. package/dist/tempo/session/server/Session.d.ts +2 -1
  86. package/dist/tempo/session/server/Session.js +2 -1
  87. package/dist/tempo/session/server/Settlement.d.ts +21 -0
  88. package/dist/tempo/session/server/Settlement.js +92 -17
  89. package/dist/tempo/session/server/Sse.d.ts +3 -1
  90. package/dist/tempo/session/server/Sse.js +105 -32
  91. package/dist/tempo/session/server/Transports.d.ts +24 -19
  92. package/dist/tempo/session/server/Transports.js +169 -58
  93. package/dist/tempo/session/server/Ws.d.ts +5 -1
  94. package/dist/tempo/session/server/Ws.js +75 -20
  95. package/dist/tempo/subscription/Store.d.ts +2 -0
  96. package/dist/tempo/subscription/Store.js +3 -0
  97. package/dist/validation/core.js +2 -1
  98. package/dist/x402/server/EvmCharge.d.ts +3 -1
  99. package/dist/x402/server/EvmCharge.js +14 -1
  100. package/package.json +6 -6
  101. package/dist/tempo/legacy/client/ChannelOps.d.ts +0 -69
  102. package/dist/tempo/legacy/client/ChannelOps.js +0 -168
  103. package/dist/tempo/legacy/client/Session.d.ts +0 -185
  104. package/dist/tempo/legacy/client/Session.js +0 -279
  105. package/dist/tempo/legacy/client/SessionManager.d.ts +0 -100
  106. package/dist/tempo/legacy/client/SessionManager.js +0 -706
  107. package/dist/tempo/legacy/client/index.d.ts +0 -7
  108. package/dist/tempo/legacy/client/index.js +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
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
+
3
58
  ## 0.12.0
4
59
 
5
60
  ### Minor Changes
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). */
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: {