mppx 0.8.19 → 0.9.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 (135) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +0 -6
  3. package/dist/Challenge.d.ts +7 -0
  4. package/dist/Challenge.js +32 -6
  5. package/dist/Constants.d.ts +1 -0
  6. package/dist/Constants.js +1 -0
  7. package/dist/Credential.d.ts +11 -5
  8. package/dist/Credential.js +8 -8
  9. package/dist/Errors.d.ts +10 -0
  10. package/dist/Errors.js +12 -0
  11. package/dist/Html.js +1 -1
  12. package/dist/Mcp.d.ts +9 -1
  13. package/dist/Mcp.js +18 -0
  14. package/dist/Method.d.ts +7 -0
  15. package/dist/cli/THIRD-PARTY-LICENSES.txt +1 -1
  16. package/dist/cli/cli.d.ts +2 -2
  17. package/dist/cli/cli.js +134 -134
  18. package/dist/cli/plugins/index.js +13 -13
  19. package/dist/cli/sessions/Manager.js +4 -6
  20. package/dist/cli/sessions/commands.d.ts +1 -1
  21. package/dist/cli/sessions/store.js +13 -19
  22. package/dist/cli/validate/index.d.ts +2 -2
  23. package/dist/client/Mppx.d.ts +39 -2
  24. package/dist/client/Mppx.js +102 -46
  25. package/dist/client/Transport.js +1 -1
  26. package/dist/client/internal/protocols/Mcp.js +2 -1
  27. package/dist/client/internal/protocols/Mpp.d.ts +1 -1
  28. package/dist/client/internal/protocols/Mpp.js +5 -3
  29. package/dist/client/internal/protocols/Protocol.d.ts +3 -1
  30. package/dist/client/internal/protocols/Shared.js +5 -1
  31. package/dist/integrations/x402/Evm.d.ts +29 -0
  32. package/dist/integrations/x402/Evm.js +150 -0
  33. package/dist/integrations/x402/Negotiator.d.ts +36 -0
  34. package/dist/integrations/x402/Negotiator.js +165 -0
  35. package/dist/mcp/client/McpClient.js +22 -10
  36. package/dist/mcp/internal/Credential.d.ts +9 -0
  37. package/dist/mcp/internal/Credential.js +16 -0
  38. package/dist/mcp/server/Transport.d.ts +2 -2
  39. package/dist/mcp/server/Transport.js +11 -6
  40. package/dist/middlewares/express.js +5 -12
  41. package/dist/middlewares/internal/express.d.ts +8 -0
  42. package/dist/middlewares/internal/express.js +24 -0
  43. package/dist/middlewares/internal/node.d.ts +10 -0
  44. package/dist/middlewares/internal/node.js +34 -0
  45. package/dist/proxy/Proxy.js +15 -9
  46. package/dist/server/Mppx.d.ts +8 -0
  47. package/dist/server/Mppx.js +92 -20
  48. package/dist/server/Transport.d.ts +8 -2
  49. package/dist/server/Transport.js +14 -18
  50. package/dist/server/internal/SecretKey.d.ts +3 -0
  51. package/dist/server/internal/SecretKey.js +9 -0
  52. package/dist/server/internal/html/serviceWorker.client.d.ts +1 -1
  53. package/dist/server/internal/html/serviceWorker.client.js +2 -2
  54. package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
  55. package/dist/server/internal/html/serviceWorker.gen.js +1 -1
  56. package/dist/stripe/Methods.d.ts +6 -0
  57. package/dist/stripe/Methods.js +3 -1
  58. package/dist/stripe/client/Charge.d.ts +6 -0
  59. package/dist/stripe/client/Methods.d.ts +6 -0
  60. package/dist/stripe/internal/payment-intent.d.ts +7 -0
  61. package/dist/stripe/internal/payment-intent.js +6 -0
  62. package/dist/stripe/server/Charge.d.ts +6 -0
  63. package/dist/stripe/server/Charge.js +8 -3
  64. package/dist/stripe/server/Methods.js +62 -7
  65. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  66. package/dist/stripe/server/internal/html.gen.js +1 -1
  67. package/dist/tempo/Methods.d.ts +0 -10
  68. package/dist/tempo/Methods.js +3 -12
  69. package/dist/tempo/Tokens.d.ts +13 -0
  70. package/dist/tempo/Tokens.js +13 -0
  71. package/dist/tempo/client/Charge.d.ts +1 -4
  72. package/dist/tempo/client/Charge.js +20 -13
  73. package/dist/tempo/client/Methods.d.ts +0 -10
  74. package/dist/tempo/index.d.ts +1 -0
  75. package/dist/tempo/index.js +1 -0
  76. package/dist/tempo/internal/account.d.ts +15 -6
  77. package/dist/tempo/internal/account.js +17 -26
  78. package/dist/tempo/internal/defaults.d.ts +0 -11
  79. package/dist/tempo/internal/defaults.js +0 -11
  80. package/dist/tempo/internal/fee-payer.d.ts +22 -4
  81. package/dist/tempo/internal/fee-payer.js +12 -31
  82. package/dist/tempo/internal/fee-token.d.ts +2 -0
  83. package/dist/tempo/internal/fee-token.js +7 -0
  84. package/dist/tempo/internal/remote-fee-payer.d.ts +12 -0
  85. package/dist/tempo/internal/remote-fee-payer.js +17 -0
  86. package/dist/tempo/legacy/client/Session.d.ts +0 -7
  87. package/dist/tempo/server/Charge.d.ts +0 -3
  88. package/dist/tempo/server/Charge.js +26 -68
  89. package/dist/tempo/server/Methods.d.ts +4 -18
  90. package/dist/tempo/server/Methods.js +4 -8
  91. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  92. package/dist/tempo/server/internal/html.gen.js +1 -1
  93. package/dist/tempo/session/client/ChannelOps.d.ts +0 -14
  94. package/dist/tempo/session/client/ChannelOps.js +0 -22
  95. package/dist/tempo/session/client/ChannelStore.d.ts +5 -0
  96. package/dist/tempo/session/client/ChannelStore.js +2 -2
  97. package/dist/tempo/session/client/CredentialState.d.ts +2 -12
  98. package/dist/tempo/session/client/CredentialState.js +75 -73
  99. package/dist/tempo/session/client/Session.d.ts +2 -9
  100. package/dist/tempo/session/client/Session.js +71 -176
  101. package/dist/tempo/session/client/SessionManager.js +7 -27
  102. package/dist/tempo/session/precompile/Chain.d.ts +0 -4
  103. package/dist/tempo/session/precompile/Chain.js +1 -29
  104. package/dist/tempo/session/precompile/Protocol.d.ts +0 -13
  105. package/dist/tempo/session/precompile/Voucher.d.ts +1 -3
  106. package/dist/tempo/session/precompile/Voucher.js +12 -6
  107. package/dist/tempo/session/server/ChannelStore.d.ts +0 -6
  108. package/dist/tempo/session/server/ChannelStore.js +4 -11
  109. package/dist/tempo/session/server/CredentialVerification.d.ts +7 -9
  110. package/dist/tempo/session/server/CredentialVerification.js +118 -184
  111. package/dist/tempo/session/server/RequestState.d.ts +0 -17
  112. package/dist/tempo/session/server/RequestState.js +15 -59
  113. package/dist/tempo/session/server/Session.d.ts +0 -9
  114. package/dist/tempo/session/server/Session.js +13 -39
  115. package/dist/tempo/session/server/Settlement.d.ts +0 -7
  116. package/dist/tempo/session/server/Settlement.js +16 -50
  117. package/dist/viem/Client.d.ts +7 -2
  118. package/dist/viem/Client.js +17 -5
  119. package/dist/x402/Types.d.ts +2 -0
  120. package/dist/x402/Types.js +2 -0
  121. package/dist/x402/mcp.d.ts +20 -0
  122. package/dist/x402/mcp.js +154 -0
  123. package/dist/x402/middlewares/express.d.ts +23 -0
  124. package/dist/x402/middlewares/express.js +49 -0
  125. package/dist/x402/middlewares/hono.d.ts +13 -0
  126. package/dist/x402/middlewares/hono.js +36 -0
  127. package/dist/x402/middlewares/next.d.ts +17 -0
  128. package/dist/x402/middlewares/next.js +58 -0
  129. package/package.json +41 -1
  130. package/dist/tempo/internal/machine-token-charge.d.ts +0 -51
  131. package/dist/tempo/internal/machine-token-charge.js +0 -113
  132. package/dist/tempo/internal/machine-token-session.d.ts +0 -88
  133. package/dist/tempo/internal/machine-token-session.js +0 -173
  134. package/dist/tempo/internal/signature-envelope.d.ts +0 -14
  135. package/dist/tempo/internal/signature-envelope.js +0 -28
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # mppx
2
2
 
3
+ ## 0.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - a33ff0a: Added MACH as a charge currency with stablecoin gas fallback and preserved session recovery.
8
+ - c74d2ce: Added request-scoped PaymentIntent metadata to Stripe machine payment charge handlers, and exposed pre-transform request input to payment-success callbacks.
9
+ - 2735c65: Fixed MCP payment errors to use the specification-defined JSON-RPC codes and retry verification challenges.
10
+
11
+ ## 0.9.0
12
+
13
+ ### Minor Changes
14
+
15
+ - c23eaf0: Removed machineUSD charge and session flows, requiring servers that advertise machineUSD to remove that configuration before upgrading.
16
+
17
+ ### Patch Changes
18
+
19
+ - 9582c40: Routed hosted Tempo fee-payer fills through the configured `withFeePayer` transport and broadcast completed transactions through the default RPC transport.
20
+ - d343aae: Added `preparePayment` for inspecting a selected client payment before creating and attaching its credential.
21
+ - 7ce3160: Added the V8 coverage provider required by the configured test coverage command.
22
+ - 5e10359: Fixed concurrent HTML builds sharing a temporary directory.
23
+ - 4e4810a: Added a `requiresAuth` server option that used `Payment-Authorization` for Payment credentials.
24
+ - 1a36a5e: Added HTTP headers to remote Tempo fee-payer configuration.
25
+ - 07c59cf: Added dual MPP/x402 wrappers for Express, Hono, Next.js, and MCP, backed by official x402 adapters and native MPP protocol handling. Exposed Tempo and source-chain MPP payments for compatible EVM requirements; x402 Fastify and Axios compatibility adapters were deferred.
26
+
3
27
  ## 0.8.19
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -52,7 +52,6 @@ const mppx = Mppx.create({
52
52
  methods: [
53
53
  tempo({
54
54
  currency: '0x20c0000000000000000000000000000000000000',
55
- machineTokenEnabled: true,
56
55
  recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
57
56
  }),
58
57
  ],
@@ -84,11 +83,6 @@ Mppx.create({
84
83
  const res = await fetch('https://mpp.dev/api/ping/paid')
85
84
  ```
86
85
 
87
- The client API is the same for PathUSD, USDC.e, and machineUSD. A server advertises
88
- `machineTokenEnabled`; the client uses machineUSD when a verified route and sufficient balance
89
- are available, and otherwise pays the token requested by the challenge. Sessions keep the selected
90
- rail until the channel closes.
91
-
92
86
  ## Examples
93
87
 
94
88
  | Example | Description |
@@ -16,6 +16,7 @@ export declare const Schema: z.ZodMiniObject<{
16
16
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
17
17
  digest: z.ZodMiniOptional<z.ZodMiniString<string>>;
18
18
  expires: z.ZodMiniOptional<z.ZodMiniString<string>>;
19
+ header: z.ZodMiniOptional<z.ZodMiniString<string>>;
19
20
  id: z.ZodMiniString<string>;
20
21
  intent: z.ZodMiniString<string>;
21
22
  method: z.ZodMiniString<string>;
@@ -106,6 +107,8 @@ export declare namespace from {
106
107
  digest?: string | undefined;
107
108
  /** Optional expiration timestamp (ISO 8601). */
108
109
  expires?: z.DatetimeInput | undefined;
110
+ /** Optional HTTP field name to carry the payment credential. When omitted, uses Authorization. */
111
+ header?: string | undefined;
109
112
  /** Intent type (e.g., "charge", "session"). */
110
113
  intent: string;
111
114
  /** Optional server-defined correlation data (serialized as `opaque` on the challenge). Flat string-to-string map; clients MUST NOT modify. */
@@ -168,6 +171,8 @@ export declare namespace fromMethod {
168
171
  digest?: string | undefined;
169
172
  /** Optional expiration timestamp (ISO 8601). */
170
173
  expires?: z.DatetimeInput | undefined;
174
+ /** Optional HTTP field name to carry the payment credential. When omitted, uses Authorization. */
175
+ header?: string | undefined;
171
176
  /** Optional server-defined correlation data (serialized as `opaque` on the challenge). Flat string-to-string map; clients MUST NOT modify. */
172
177
  meta?: Record<string, string> | undefined;
173
178
  /** Server realm (e.g., hostname). */
@@ -309,4 +314,6 @@ export declare namespace verify {
309
314
  }
310
315
  /** Extracts parsed server-defined correlation data from a challenge when available. */
311
316
  export declare function meta(challenge: Challenge): Record<string, string> | undefined;
317
+ /** Returns the HTTP field name a client must use for a payment credential. */
318
+ export declare function credentialHeader(challenge: Challenge): string;
312
319
  //# sourceMappingURL=Challenge.d.ts.map
package/dist/Challenge.js CHANGED
@@ -21,6 +21,8 @@ export const Schema = z.object({
21
21
  digest: z.optional(z.string().check(z.regex(/^sha-256=/, 'Invalid digest format'))),
22
22
  /** Optional expiration timestamp (ISO 8601). */
23
23
  expires: z.optional(z.datetime()),
24
+ /** Optional HTTP field name to carry the payment credential. When omitted, uses Authorization. */
25
+ header: z.optional(z.string().check(z.regex(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/, 'Invalid HTTP header name'))),
24
26
  /** Unique challenge identifier (HMAC-bound). */
25
27
  id: z.string().check(z.minLength(1)),
26
28
  /** Intent type (e.g., "charge", "session"). */
@@ -75,7 +77,11 @@ export const Schema = z.object({
75
77
  */
76
78
  export function from(parameters, options) {
77
79
  void options;
78
- const { description, digest, meta, method: methodName, intent, realm, request, secretKey, } = parameters;
80
+ const { description, digest, meta, method: methodName, header: suppliedHeader, intent, realm, request, secretKey, } = parameters;
81
+ // `Authorization` is the implicit protocol default and is intentionally not
82
+ // advertised on the wire. This preserves the legacy challenge binding and
83
+ // lets servers opt into an alternate credential field explicitly.
84
+ const header = isDefaultCredentialHeader(suppliedHeader) ? undefined : suppliedHeader;
79
85
  const expires = parameters.expires ? z.toDatetimeString(parameters.expires) : undefined;
80
86
  const opaque = parameters.opaque ?? (meta !== undefined ? PaymentRequest.serialize(meta) : undefined);
81
87
  const id = secretKey
@@ -90,6 +96,7 @@ export function from(parameters, options) {
90
96
  ...(description && { description }),
91
97
  ...(digest && { digest }),
92
98
  ...(expires && { expires }),
99
+ ...(header !== undefined && { header }),
93
100
  ...(meta !== undefined && { meta }),
94
101
  ...(opaque !== undefined && { opaque }),
95
102
  });
@@ -128,7 +135,7 @@ export function from(parameters, options) {
128
135
  */
129
136
  export function fromMethod(method, parameters) {
130
137
  const { name: methodName, intent } = method;
131
- const { description, digest, expires, id, meta, realm, secretKey } = parameters;
138
+ const { description, digest, expires, header, id, meta, realm, secretKey } = parameters;
132
139
  const request = PaymentRequest.fromMethod(method, parameters.request);
133
140
  return from({
134
141
  ...(id !== undefined ? { id } : { secretKey }),
@@ -139,6 +146,7 @@ export function fromMethod(method, parameters) {
139
146
  description,
140
147
  digest,
141
148
  expires,
149
+ header,
142
150
  meta,
143
151
  });
144
152
  }
@@ -170,6 +178,9 @@ export function serialize(challenge) {
170
178
  parts.push(authParam('digest', challenge.digest));
171
179
  if (challenge.expires !== undefined)
172
180
  parts.push(authParam('expires', challenge.expires));
181
+ const credentialHeader = challenge.header;
182
+ if (credentialHeader !== undefined && !isDefaultCredentialHeader(credentialHeader))
183
+ parts.push(authParam('header', credentialHeader));
173
184
  if (challenge.opaque !== undefined)
174
185
  parts.push(authParam('opaque', challenge.opaque));
175
186
  else if (challenge.meta !== undefined)
@@ -490,22 +501,37 @@ export function meta(challenge) {
490
501
  * of truth for what the challenge ID binds to — used by both `computeId()`
491
502
  * (challenge creation) and `verify()` (credential verification).
492
503
  *
493
- * Slots: realm | method | intent | request | expires | digest | opaque
504
+ * Legacy slots: realm | method | intent | request | expires | digest | opaque.
505
+ * Challenges advertising a credential header insert it immediately before the
506
+ * final opaque slot.
494
507
  *
495
508
  * Because the HMAC covers ALL fields, the server does not need to separately
496
509
  * pin opaque, digest, or expires during verification — any change to those
497
510
  * fields produces a different HMAC and fails the ID comparison.
498
511
  */
499
512
  function idBindingInput(challenge) {
500
- return [
513
+ const values = [
501
514
  challenge.realm,
502
515
  challenge.method,
503
516
  challenge.intent,
504
517
  PaymentRequest.serialize(challenge.request),
505
518
  challenge.expires ?? '',
506
519
  challenge.digest ?? '',
507
- challenge.opaque ?? (challenge.meta ? PaymentRequest.serialize(challenge.meta) : ''),
508
- ].join('|');
520
+ ];
521
+ // Keep opaque in the final optional slot required by the Payment auth scheme.
522
+ const credentialHeader = challenge.header;
523
+ if (credentialHeader !== undefined && !isDefaultCredentialHeader(credentialHeader))
524
+ values.push(credentialHeader);
525
+ values.push(challenge.opaque ?? (challenge.meta ? PaymentRequest.serialize(challenge.meta) : ''));
526
+ return values.join('|');
527
+ }
528
+ /** Returns the HTTP field name a client must use for a payment credential. */
529
+ export function credentialHeader(challenge) {
530
+ return challenge.header ?? Constants.Headers.authorization;
531
+ }
532
+ /** Returns whether a credential header is the implicit HTTP authentication default. */
533
+ function isDefaultCredentialHeader(header) {
534
+ return header?.toLowerCase() === Constants.Headers.authorization.toLowerCase();
509
535
  }
510
536
  /** @internal Computes HMAC-SHA256 challenge ID from parameters. */
511
537
  function computeId(challenge, options) {
@@ -2,6 +2,7 @@
2
2
  export declare const Headers: {
3
3
  readonly acceptPayment: 'Accept-Payment';
4
4
  readonly authorization: 'Authorization';
5
+ readonly paymentAuthorization: 'Payment-Authorization';
5
6
  readonly paymentReceipt: 'Payment-Receipt';
6
7
  readonly paymentSession: 'Payment-Session';
7
8
  readonly paymentSessionSnapshot: 'Payment-Session-Snapshot';
package/dist/Constants.js CHANGED
@@ -2,6 +2,7 @@
2
2
  export const Headers = {
3
3
  acceptPayment: 'Accept-Payment',
4
4
  authorization: 'Authorization',
5
+ paymentAuthorization: 'Payment-Authorization',
5
6
  paymentReceipt: 'Payment-Receipt',
6
7
  paymentSession: 'Payment-Session',
7
8
  paymentSessionSnapshot: 'Payment-Session-Snapshot',
@@ -12,7 +12,7 @@ export type Credential<payload = unknown, challenge extends Challenge.Challenge
12
12
  };
13
13
  export declare class MissingAuthorizationHeaderError extends Error {
14
14
  readonly name = "MissingAuthorizationHeaderError";
15
- constructor();
15
+ constructor(header?: string);
16
16
  }
17
17
  export declare class MissingPaymentSchemeError extends Error {
18
18
  readonly name = "MissingPaymentSchemeError";
@@ -23,7 +23,7 @@ export declare class InvalidCredentialEncodingError extends Error {
23
23
  constructor();
24
24
  }
25
25
  /**
26
- * Deserializes an Authorization header value to a credential.
26
+ * Deserializes a Payment credential header value to a credential.
27
27
  * Accepts the spec-compliant base64url `opaque` string shape and the legacy
28
28
  * object-shaped `opaque` form emitted by older mppx versions.
29
29
  *
@@ -66,7 +66,7 @@ export declare namespace from {
66
66
  };
67
67
  }
68
68
  /**
69
- * Extracts the credential from a Request's Authorization header.
69
+ * Extracts the credential from a Request's configured credential header.
70
70
  *
71
71
  * @param request - The HTTP request.
72
72
  * @returns The deserialized credential.
@@ -78,9 +78,15 @@ export declare namespace from {
78
78
  * const credential = Credential.fromRequest(request)
79
79
  * ```
80
80
  */
81
- export declare function fromRequest<payload = unknown>(request: Request): Credential<payload>;
81
+ export declare function fromRequest<payload = unknown>(request: Request, options?: fromRequest.Options): Credential<payload>;
82
+ export declare namespace fromRequest {
83
+ type Options = {
84
+ /** HTTP field containing the Payment credential. @default 'Authorization' */
85
+ header?: string | undefined;
86
+ };
87
+ }
82
88
  /**
83
- * Serializes a credential to the Authorization header format.
89
+ * Serializes a credential to the Payment credential header format.
84
90
  * When present, `challenge.opaque` is emitted unchanged as the base64url string
85
91
  * required by the Payment auth credential format.
86
92
  *
@@ -4,8 +4,8 @@ import * as Constants from './Constants.js';
4
4
  import * as PaymentRequest from './PaymentRequest.js';
5
5
  export class MissingAuthorizationHeaderError extends Error {
6
6
  name = 'MissingAuthorizationHeaderError';
7
- constructor() {
8
- super('Missing Authorization header.');
7
+ constructor(header = Constants.Headers.authorization) {
8
+ super(`Missing ${header} header.`);
9
9
  }
10
10
  }
11
11
  export class MissingPaymentSchemeError extends Error {
@@ -21,7 +21,7 @@ export class InvalidCredentialEncodingError extends Error {
21
21
  }
22
22
  }
23
23
  /**
24
- * Deserializes an Authorization header value to a credential.
24
+ * Deserializes a Payment credential header value to a credential.
25
25
  * Accepts the spec-compliant base64url `opaque` string shape and the legacy
26
26
  * object-shaped `opaque` form emitted by older mppx versions.
27
27
  *
@@ -105,7 +105,7 @@ export function from(parameters) {
105
105
  };
106
106
  }
107
107
  /**
108
- * Extracts the credential from a Request's Authorization header.
108
+ * Extracts the credential from a Request's configured credential header.
109
109
  *
110
110
  * @param request - The HTTP request.
111
111
  * @returns The deserialized credential.
@@ -117,17 +117,17 @@ export function from(parameters) {
117
117
  * const credential = Credential.fromRequest(request)
118
118
  * ```
119
119
  */
120
- export function fromRequest(request) {
121
- const header = request.headers.get(Constants.Headers.authorization);
120
+ export function fromRequest(request, options = {}) {
121
+ const header = request.headers.get(options.header ?? Constants.Headers.authorization);
122
122
  if (!header)
123
- throw new MissingAuthorizationHeaderError();
123
+ throw new MissingAuthorizationHeaderError(options.header);
124
124
  const payment = extractPaymentScheme(header);
125
125
  if (!payment)
126
126
  throw new MissingPaymentSchemeError();
127
127
  return deserialize(payment);
128
128
  }
129
129
  /**
130
- * Serializes a credential to the Authorization header format.
130
+ * Serializes a credential to the Payment credential header format.
131
131
  * When present, `challenge.opaque` is emitted unchanged as the base64url string
132
132
  * required by the Payment auth credential format.
133
133
  *
package/dist/Errors.d.ts CHANGED
@@ -95,6 +95,16 @@ export declare namespace VerificationFailedError {
95
95
  reason?: string;
96
96
  };
97
97
  }
98
+ /**
99
+ * Payment processing failed because of an unexpected internal error.
100
+ */
101
+ export declare class InternalPaymentError extends PaymentError {
102
+ readonly name = "InternalPaymentError";
103
+ readonly title = "Internal Payment Error";
104
+ readonly status = 500;
105
+ readonly type = "https://paymentauth.org/problems/internal-payment-error";
106
+ constructor();
107
+ }
98
108
  /**
99
109
  * Payment requires additional action (e.g., 3DS authentication).
100
110
  */
package/dist/Errors.js CHANGED
@@ -74,6 +74,18 @@ export class VerificationFailedError extends PaymentError {
74
74
  });
75
75
  }
76
76
  }
77
+ /**
78
+ * Payment processing failed because of an unexpected internal error.
79
+ */
80
+ export class InternalPaymentError extends PaymentError {
81
+ name = 'InternalPaymentError';
82
+ title = 'Internal Payment Error';
83
+ status = 500;
84
+ type = 'https://paymentauth.org/problems/internal-payment-error';
85
+ constructor() {
86
+ super('An internal payment error occurred.');
87
+ }
88
+ }
77
89
  /**
78
90
  * Payment requires additional action (e.g., 3DS authentication).
79
91
  */
package/dist/Html.js CHANGED
@@ -34,7 +34,7 @@ export function init(methodName) {
34
34
  document.getElementById(data.rootId)?.after(el);
35
35
  },
36
36
  root: document.getElementById(data.rootId),
37
- submit: submitCredential,
37
+ submit: (credential) => submitCredential(credential, data.challenge.header),
38
38
  vars,
39
39
  };
40
40
  }
package/dist/Mcp.d.ts CHANGED
@@ -1,12 +1,20 @@
1
1
  import type * as Challenge from './Challenge.js';
2
2
  import type * as Credential from './Credential.js';
3
- import type * as Errors from './Errors.js';
3
+ import * as Errors from './Errors.js';
4
4
  import type { OneOf } from './internal/types.js';
5
5
  import type * as core_Receipt from './Receipt.js';
6
6
  /** MCP JSON-RPC error code for payment required. */
7
7
  export declare const paymentRequiredCode = -32042;
8
8
  /** MCP JSON-RPC error code for payment verification failed. */
9
9
  export declare const paymentVerificationFailedCode = -32043;
10
+ /** JSON-RPC error code for invalid parameters. */
11
+ export declare const invalidParamsCode = -32602;
12
+ /** JSON-RPC error code for internal errors. */
13
+ export declare const internalErrorCode = -32603;
14
+ /**
15
+ * Maps a payment error to its MCP JSON-RPC error code.
16
+ */
17
+ export declare function errorCode(error?: Errors.PaymentError): number;
10
18
  /** MCP metadata key for credentials. */
11
19
  export declare const credentialMetaKey = "org.paymentauth/credential";
12
20
  /** MCP metadata key for payment-required tool results. */
package/dist/Mcp.js CHANGED
@@ -1,7 +1,25 @@
1
+ import * as Errors from './Errors.js';
1
2
  /** MCP JSON-RPC error code for payment required. */
2
3
  export const paymentRequiredCode = -32042;
3
4
  /** MCP JSON-RPC error code for payment verification failed. */
4
5
  export const paymentVerificationFailedCode = -32043;
6
+ /** JSON-RPC error code for invalid parameters. */
7
+ export const invalidParamsCode = -32602;
8
+ /** JSON-RPC error code for internal errors. */
9
+ export const internalErrorCode = -32603;
10
+ /**
11
+ * Maps a payment error to its MCP JSON-RPC error code.
12
+ */
13
+ export function errorCode(error) {
14
+ if (!error || error instanceof Errors.PaymentRequiredError)
15
+ return paymentRequiredCode;
16
+ if (error instanceof Errors.MalformedCredentialError ||
17
+ error instanceof Errors.InvalidPayloadError)
18
+ return invalidParamsCode;
19
+ if (error instanceof Errors.InternalPaymentError)
20
+ return internalErrorCode;
21
+ return paymentVerificationFailedCode;
22
+ }
5
23
  /** MCP metadata key for credentials. */
6
24
  export const credentialMetaKey = 'org.paymentauth/credential';
7
25
  /** MCP metadata key for payment-required tool results. */
package/dist/Method.d.ts CHANGED
@@ -187,7 +187,14 @@ export type CanOfferFn<method extends Method> = (parameters: {
187
187
  export type OnPaymentSuccessFn<method extends Method> = (parameters: {
188
188
  input?: globalThis.Request;
189
189
  receipt: DeepReadonly<Receipt.Receipt>;
190
+ /** Canonical payment request included in the challenge. */
190
191
  request: DeepReadonly<z.output<method['schema']['request']>>;
192
+ /**
193
+ * Server-side request after defaults and request hooks, before the method
194
+ * request schema's output transforms. Absent during standalone credential
195
+ * verification when no route options are supplied.
196
+ */
197
+ requestInput?: DeepReadonly<z.input<method['schema']['request']>> | undefined;
191
198
  }) => MaybePromise<void>;
192
199
  export type ComposableHooks<method extends Method> = {
193
200
  /** Decides whether this method's configured offer is available for an HTTP request. */
@@ -253,7 +253,7 @@ SOFTWARE.
253
253
 
254
254
  ---
255
255
 
256
- # incur@0.4.26 (MIT)
256
+ # incur@0.5.1 (MIT)
257
257
 
258
258
  LICENSE
259
259
  -------
package/dist/cli/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Cli } from 'incur';
2
2
  declare const cli: Cli.Cli<{
3
- [x: string]: {
3
+ mppx: {
4
4
  args: {
5
5
  url: string;
6
6
  };
@@ -29,6 +29,6 @@ declare const cli: Cli.Cli<{
29
29
  verbose: number;
30
30
  };
31
31
  };
32
- }, undefined, undefined, undefined>;
32
+ }, undefined, undefined, undefined, "mppx">;
33
33
  export default cli;
34
34
  //# sourceMappingURL=cli.d.ts.map