mppx 0.10.1 → 0.12.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +22 -1
  3. package/dist/cli/agent.d.ts +3 -0
  4. package/dist/cli/agent.js +20 -0
  5. package/dist/cli/cli.d.ts +1 -1
  6. package/dist/cli/cli.js +135 -135
  7. package/dist/cli/plugins/index.js +12 -12
  8. package/dist/cli/validate/payment.js +29 -12
  9. package/dist/client/internal/protocols/X402.js +0 -2
  10. package/dist/evm/server/Methods.d.ts +164 -3
  11. package/dist/evm/server/Methods.js +50 -2
  12. package/dist/internal/version.d.ts +2 -2
  13. package/dist/internal/version.js +1 -1
  14. package/dist/server/Mppx.d.ts +5 -1
  15. package/dist/server/Mppx.js +120 -49
  16. package/dist/server/internal/html/compose.main.gen.d.ts +1 -1
  17. package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
  18. package/dist/stripe/server/Methods.js +13 -7
  19. package/dist/stripe/server/internal/analytics.d.ts +1 -0
  20. package/dist/stripe/server/internal/analytics.js +2 -2
  21. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  22. package/dist/stripe/server/internal/record-payment.js +2 -2
  23. package/dist/tempo/Methods.d.ts +5 -3
  24. package/dist/tempo/Methods.js +6 -5
  25. package/dist/tempo/client/Charge.d.ts +6 -4
  26. package/dist/tempo/client/Charge.js +61 -28
  27. package/dist/tempo/client/Methods.d.ts +5 -3
  28. package/dist/tempo/index.d.ts +2 -1
  29. package/dist/tempo/index.js +2 -1
  30. package/dist/tempo/internal/currencies.d.ts +19 -0
  31. package/dist/tempo/internal/currencies.js +41 -0
  32. package/dist/tempo/internal/defaults.d.ts +16 -3
  33. package/dist/tempo/internal/defaults.js +17 -2
  34. package/dist/tempo/internal/fee-payer.d.ts +5 -4
  35. package/dist/tempo/internal/fee-payer.js +7 -5
  36. package/dist/tempo/internal/machine-token-charge.d.ts +56 -0
  37. package/dist/tempo/internal/machine-token-charge.js +108 -0
  38. package/dist/tempo/server/Charge.d.ts +15 -1
  39. package/dist/tempo/server/Charge.js +101 -67
  40. package/dist/tempo/server/Methods.d.ts +5008 -40
  41. package/dist/tempo/server/Methods.js +105 -11
  42. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  43. package/dist/tempo/server/internal/html.gen.js +1 -1
  44. package/dist/tempo/session/server/ChannelStore.d.ts +2 -0
  45. package/dist/tempo/session/server/ChannelStore.js +12 -3
  46. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  47. package/dist/tempo/session/server/CredentialVerification.js +22 -13
  48. package/dist/tempo/session/server/RequestState.d.ts +6 -0
  49. package/dist/tempo/session/server/RequestState.js +11 -4
  50. package/dist/tempo/session/server/Session.js +8 -1
  51. package/dist/tempo/session/server/Settlement.d.ts +2 -0
  52. package/dist/tempo/session/server/Settlement.js +13 -8
  53. package/dist/tempo/subscription/KeyAuthorization.d.ts +70 -8
  54. package/package.json +3 -3
  55. package/dist/tempo/Tokens.d.ts +0 -13
  56. package/dist/tempo/Tokens.js +0 -13
@@ -64,22 +64,18 @@ export function create(config) {
64
64
  ? createAttestationGuard(attestation)
65
65
  : undefined;
66
66
  const handlers = {};
67
+ const methodHandlers = new Map();
67
68
  const intentCount = {};
69
+ function composeConfigured(configured) {
70
+ if (transport.name === 'mcp' || transport.name === 'mcp-sdk')
71
+ return composeMcpHandlers(configured, transport);
72
+ return composeHandlers(configured, undefined, selectOffers);
73
+ }
74
+ function createGroupedHandler(group) {
75
+ return (options) => composeConfigured(group.map((method) => methodHandlers.get(method)(options)));
76
+ }
68
77
  for (const mi of methods) {
69
78
  intentCount[mi.intent] = (intentCount[mi.intent] ?? 0) + 1;
70
- if (mi.onPaymentSuccess) {
71
- serverEvents.on('payment.success', (async (ctx) => {
72
- if (ctx.method.name === mi.name && ctx.method.intent === mi.intent) {
73
- await mi.onPaymentSuccess({
74
- challenge: ctx.challenge,
75
- input: ctx.input,
76
- receipt: ctx.receipt,
77
- request: ctx.request,
78
- ...(ctx.requestInput !== undefined && { requestInput: ctx.requestInput }),
79
- });
80
- }
81
- }));
82
- }
83
79
  }
84
80
  assertNoReservedMppxKeys(methods);
85
81
  for (const mi of methods) {
@@ -105,6 +101,8 @@ export function create(config) {
105
101
  const aliasKey = mi.alias ? `${mi.name}/${mi.alias}` : undefined;
106
102
  if (mi.extensions)
107
103
  Object.assign(fn, mi.extensions);
104
+ Object.assign(fn, { _method: mi });
105
+ methodHandlers.set(mi, fn);
108
106
  if (!aliasKey || !handlers[wireKey])
109
107
  handlers[wireKey] = fn;
110
108
  if (aliasKey)
@@ -122,23 +120,25 @@ export function create(config) {
122
120
  }
123
121
  else {
124
122
  const intentMethods = methods.filter((m) => m.intent === mi.intent);
125
- handlers[mi.intent] = (options) => {
126
- const configured = intentMethods.map((m) => {
127
- const key = `${m.name}/${m.intent}`;
128
- const handlerFn = handlers[key];
129
- return handlerFn(options);
130
- });
131
- return composeHandlers(configured, undefined, selectOffers);
132
- };
123
+ handlers[mi.intent] = createGroupedHandler(intentMethods);
133
124
  }
134
125
  }
126
+ // Preserve distinct configured offers sharing a wire method, including nested handlers.
127
+ for (const key of new Set(methods.filter((m) => !m.alias).map((m) => `${m.name}/${m.intent}`))) {
128
+ const matching = methods.filter((m) => !m.alias && `${m.name}/${m.intent}` === key);
129
+ if (matching.length < 2)
130
+ continue;
131
+ const composed = createGroupedHandler(matching);
132
+ Object.assign(composed, matching[0].extensions);
133
+ handlers[key] = composed;
134
+ }
135
135
  // Build nested handlers: mppx.tempo.charge(...)
136
136
  for (const mi of methods) {
137
137
  if (!handlers[mi.name])
138
138
  handlers[mi.name] = {};
139
139
  const key = mi.alias ? `${mi.name}/${mi.alias}` : `${mi.name}/${mi.intent}`;
140
140
  const fn = handlers[key];
141
- fn._method = mi;
141
+ fn._method ??= mi;
142
142
  handlers[mi.name][mi.alias ?? mi.intent] = fn;
143
143
  }
144
144
  // Build challenge generators: mppx.challenge.tempo.charge(...)
@@ -146,6 +146,8 @@ export function create(config) {
146
146
  for (const mi of methods) {
147
147
  if (!challengeHandlers[mi.name])
148
148
  challengeHandlers[mi.name] = {};
149
+ if (challengeHandlers[mi.name][mi.alias ?? mi.intent])
150
+ continue;
149
151
  challengeHandlers[mi.name][mi.alias ?? mi.intent] = createChallengeFn({
150
152
  credentialHeader,
151
153
  defaults: mi.defaults,
@@ -160,7 +162,7 @@ export function create(config) {
160
162
  const emitFailures = parameters.emitFailures === true;
161
163
  const { method: credMethod, intent: credIntent } = credential.challenge;
162
164
  const methodCandidates = methods.filter((m) => m.name === credMethod && m.intent === credIntent);
163
- const mi = methodCandidates[0];
165
+ let mi = methodCandidates[0];
164
166
  const eventMethod = mi ?? { intent: credIntent, name: credMethod };
165
167
  const emitStandalonePaymentFailed = async (failure) => {
166
168
  if (!emitFailures)
@@ -191,11 +193,6 @@ export function create(config) {
191
193
  reason: `no registered method for ${credMethod}/${credIntent}`,
192
194
  }));
193
195
  }
194
- if (parameters.requireValidate && !mi.validate)
195
- await fail(new Errors.VerificationFailedError({
196
- details: { intent: credIntent, method: credMethod },
197
- reason: `${credMethod}/${credIntent} does not support non-mutating credential validation`,
198
- }));
199
196
  if (!Challenge.verify(credential.challenge, { secretKey: secretKey })) {
200
197
  await fail(new Errors.InvalidChallengeError({
201
198
  id: credential.challenge.id,
@@ -210,6 +207,24 @@ export function create(config) {
210
207
  await fail(e);
211
208
  throw e;
212
209
  }
210
+ if (methodCandidates.length > 1) {
211
+ const matches = [
212
+ ...new Set(methodCandidates.filter((candidate) => matchesStandaloneMethod(candidate, credential.challenge.request, options?.request))),
213
+ ];
214
+ if (matches.length !== 1)
215
+ await fail(new Errors.InvalidChallengeError({
216
+ id: credential.challenge.id,
217
+ reason: matches.length === 0
218
+ ? 'no configured method matches the challenge request'
219
+ : 'multiple configured methods match the challenge request; use a configured route handler',
220
+ }));
221
+ mi = matches[0];
222
+ }
223
+ if (parameters.requireValidate && !mi.validate)
224
+ await fail(new Errors.VerificationFailedError({
225
+ details: { intent: credIntent, method: credMethod },
226
+ reason: `${credMethod}/${credIntent} does not support non-mutating credential validation`,
227
+ }));
213
228
  let parsedCredential;
214
229
  try {
215
230
  parsedCredential = withParsedCredentialPayload(credential, mi.schema.credential.payload.parse(credential.payload));
@@ -336,7 +351,7 @@ export function create(config) {
336
351
  receipt,
337
352
  request: parsedRequest,
338
353
  ...(requestInput !== undefined && { requestInput }),
339
- }));
354
+ }), mi);
340
355
  return receipt;
341
356
  }
342
357
  const verifyCredentialFn = broadcastCredentialFn;
@@ -347,18 +362,27 @@ export function create(config) {
347
362
  if (entries.length === 0)
348
363
  throw new Error('compose() requires at least one entry');
349
364
  const configured = entries.map(([methodOrKey, options]) => {
365
+ const method = typeof methodOrKey === 'string'
366
+ ? undefined
367
+ : typeof methodOrKey === 'function'
368
+ ? methodOrKey._method
369
+ : methodOrKey;
350
370
  const key = typeof methodOrKey === 'string'
351
371
  ? methodOrKey
352
- : typeof methodOrKey === 'function' && '_method' in methodOrKey
353
- ? `${methodOrKey._method.name}/${methodOrKey._method.alias ?? methodOrKey._method.intent}`
354
- : `${methodOrKey.name}/${methodOrKey.alias ?? methodOrKey.intent}`;
355
- const handlerFn = handlers[key];
372
+ : `${method.name}/${method.alias ?? method.intent}`;
373
+ const handlerFn = typeof methodOrKey === 'function' && handlers[key] === methodOrKey
374
+ ? methodOrKey
375
+ : method
376
+ ? methodHandlers.get(method)
377
+ : handlers[key];
356
378
  if (!handlerFn)
357
379
  throw new Error(`No handler for "${key}". Is this method in your methods array?`);
358
- const method = handlerFn._method;
359
- if (isMcp && method?.transport && method.transport.name !== transport.name)
380
+ const configuredMethod = handlerFn._method;
381
+ if (isMcp &&
382
+ configuredMethod?.transport &&
383
+ configuredMethod.transport.name !== transport.name)
360
384
  throw new Error('MCP compose() requires methods using the configured MCP transport');
361
- if (isMcp && method?.canOffer)
385
+ if (isMcp && configuredMethod?.canOffer)
362
386
  throw new Error('MCP compose() does not support HTTP canOffer hooks');
363
387
  return handlerFn(options);
364
388
  });
@@ -628,7 +652,7 @@ function createMethodFn(parameters) {
628
652
  receipt: authorized.receipt,
629
653
  request: parsedRequest,
630
654
  requestInput: request,
631
- }));
655
+ }), method);
632
656
  return success(authorized.receipt, {
633
657
  managementResponse: authorized.response,
634
658
  });
@@ -851,7 +875,7 @@ function createMethodFn(parameters) {
851
875
  receipt: receiptData,
852
876
  request: parsedRequest,
853
877
  requestInput: request,
854
- }));
878
+ }), method);
855
879
  return success(receiptData, {
856
880
  challengeId: credential.challenge.id,
857
881
  credentialForReceipt: parsedCredential,
@@ -916,6 +940,7 @@ function createAttestationGuard(verifiers) {
916
940
  return verification;
917
941
  };
918
942
  }
943
+ /** Dispatches instance events and scopes success hooks to the supplied configured method. */
919
944
  function createServerEventDispatcher() {
920
945
  const handlers = {
921
946
  '*': new Set(),
@@ -936,7 +961,22 @@ function createServerEventDispatcher() {
936
961
  }
937
962
  };
938
963
  return {
939
- async emit(name, context) {
964
+ async emit(name, context, method) {
965
+ if (name === 'payment.success' && method?.onPaymentSuccess) {
966
+ const success = context;
967
+ try {
968
+ await method.onPaymentSuccess({
969
+ challenge: success.challenge,
970
+ input: success.input,
971
+ receipt: success.receipt,
972
+ request: success.request,
973
+ ...(success.requestInput !== undefined && { requestInput: success.requestInput }),
974
+ });
975
+ }
976
+ catch {
977
+ // Per-method hooks are isolated just like instance event handlers.
978
+ }
979
+ }
940
980
  await emitServerEventHandlers(handlers[name], context);
941
981
  await emitServerEventHandlers(handlers['*'], toServerEventEnvelope(name, context));
942
982
  },
@@ -1328,6 +1368,30 @@ function getPinnedChallengeMismatch(expectedChallenge, actualChallenge) {
1328
1368
  return 'opaque';
1329
1369
  return getPinnedRequestBindingMismatch(expectedChallenge.request, actualChallenge.request);
1330
1370
  }
1371
+ /** Matches standalone credentials against the configured portion of a method's stable binding. */
1372
+ function matchesStandaloneMethod(method, request, routeRequest) {
1373
+ try {
1374
+ const configured = { ...method.defaults, ...routeRequest };
1375
+ const parsed = method.schema.request.safeParse(configured);
1376
+ // Standalone callers may omit route-only inputs such as amount. In that
1377
+ // case, constrain selection by the defaults we have rather than parsing
1378
+ // the echoed wire request as input and applying its transforms twice.
1379
+ const expectedRequest = parsed.success ? parsed.data : configured;
1380
+ const binding = (value) => {
1381
+ if (method.stableBinding)
1382
+ return getStableBinding(value, method.stableBinding);
1383
+ const { coreBinding, methodBinding } = getPinnedRequestBinding(value);
1384
+ return { ...coreBinding, ...methodBinding };
1385
+ };
1386
+ const expected = binding(expectedRequest);
1387
+ const actual = binding(request);
1388
+ return Object.entries(expected).every(([key, value]) => value === undefined ||
1389
+ isDeepStrictEqual(normalizeComparable(value), normalizeComparable(actual[key])));
1390
+ }
1391
+ catch {
1392
+ return false;
1393
+ }
1394
+ }
1331
1395
  function getPinnedRequestBindingMismatch(expectedRequest, actualRequest) {
1332
1396
  const expected = getPinnedRequestBinding(expectedRequest);
1333
1397
  const actual = getPinnedRequestBinding(actualRequest);
@@ -1457,6 +1521,11 @@ export function compose(...args) {
1457
1521
  return composeHandlers(handlers, composeOptions);
1458
1522
  }
1459
1523
  function composeHandlers(handlers, composeOptions, selectOffers) {
1524
+ // Flatten only shared policies; a static wrapper must retain a nested server's selector.
1525
+ handlers = handlers.flatMap((handler) => {
1526
+ const internal = handler._internal;
1527
+ return internal?.selectOffers === selectOffers ? (internal?.handlers ?? [handler]) : [handler];
1528
+ });
1460
1529
  if (handlers.length === 0)
1461
1530
  throw new Error('compose() requires at least one handler');
1462
1531
  const offerSelector = selectOffers;
@@ -1539,6 +1608,8 @@ function composeHandlers(handlers, composeOptions, selectOffers) {
1539
1608
  const result = await handler(input);
1540
1609
  if (result.status === 200)
1541
1610
  return result;
1611
+ if (result.challenge.status !== 402)
1612
+ return result;
1542
1613
  results.push(result);
1543
1614
  }
1544
1615
  const challengeEntries = (() => {
@@ -1655,7 +1726,7 @@ function composeHandlers(handlers, composeOptions, selectOffers) {
1655
1726
  };
1656
1727
  const offers = handlers.flatMap(getConfiguredOffers);
1657
1728
  if (offers.length > 0)
1658
- composed._internal = { offers };
1729
+ composed._internal = { offers, handlers: handlers, selectOffers };
1659
1730
  return composed;
1660
1731
  }
1661
1732
  /** Returns the flattened configured offers accepted by a handler. */
@@ -1669,7 +1740,7 @@ function getConfiguredOffers(handler) {
1669
1740
  }
1670
1741
  /** Dispatches one MCP credential or gathers unsigned offers in their configured order. */
1671
1742
  function composeMcpHandlers(handlers, transport) {
1672
- return async (input) => {
1743
+ const composed = async (input) => {
1673
1744
  let credential;
1674
1745
  try {
1675
1746
  const parsed = transport.getCredential(input);
@@ -1680,13 +1751,9 @@ function composeMcpHandlers(handlers, transport) {
1680
1751
  return handlers[0](input);
1681
1752
  }
1682
1753
  if (credential) {
1683
- const candidates = handlers.filter((handler) => {
1684
- const internal = handler._internal;
1685
- return (internal.name === credential.challenge.method &&
1686
- internal.intent === credential.challenge.intent);
1687
- });
1688
- const match = candidates.find((handler) => {
1689
- const internal = handler._internal;
1754
+ const candidates = handlers.filter((handler) => getConfiguredOffers(handler).some((internal) => internal.name === credential.challenge.method &&
1755
+ internal.intent === credential.challenge.intent));
1756
+ const match = candidates.find((handler) => getConfiguredOffers(handler).some((internal) => {
1690
1757
  try {
1691
1758
  const mismatch = internal._stableBinding
1692
1759
  ? getRequestBindingMismatch(getStableBinding(internal._canonicalRequest, internal._stableBinding), getStableBinding(credential.challenge.request, internal._stableBinding))
@@ -1696,7 +1763,7 @@ function composeMcpHandlers(handlers, transport) {
1696
1763
  catch {
1697
1764
  return false;
1698
1765
  }
1699
- });
1766
+ }));
1700
1767
  // Verification and settlement belong to exactly one handler, including failures.
1701
1768
  return (match ?? candidates[0] ?? handlers[0])(input);
1702
1769
  }
@@ -1738,6 +1805,10 @@ function composeMcpHandlers(handlers, transport) {
1738
1805
  },
1739
1806
  };
1740
1807
  };
1808
+ composed._internal = {
1809
+ offers: handlers.flatMap((handler) => getConfiguredOffers(handler)),
1810
+ };
1811
+ return composed;
1741
1812
  }
1742
1813
  function isComposedHandlerMetadata(internal) {
1743
1814
  return 'offers' in internal && !('_canonicalRequest' in internal);
@@ -1,2 +1,2 @@
1
- export declare const tabScript = "<script>(function(){let e={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},t={error:`mppx-error`,header:`mppx-header`,logo:`mppx-logo`,summary:`mppx-summary`,summaryAmount:`mppx-summary-amount`,summaryDescription:`mppx-summary-description`,summaryExpires:`mppx-summary-expires`,tab:`mppx-tab`,tabList:`mppx-tablist`,tabPanel:`mppx-tabpanel`},n=document.querySelector(`.${t.tabList}`),r=document.querySelector(`.${t.summary}`),i=r.querySelector(`.${t.summaryAmount}`),a=Array.from(n.querySelectorAll(`[role=\"tab\"]`)),o=[],s={};for(let e of a){let t=e.textContent.trim().toLowerCase();s[t]=(s[t]||0)+1,o.push(s[t]===1?t:`${t}-${s[t]}`)}function c(e){if(i.textContent=e.dataset.amount,r.querySelector(`.${t.summaryDescription}`)?.remove(),e.dataset.description){let n=document.createElement(`p`);n.className=t.summaryDescription,n.textContent=e.dataset.description,i.after(n)}if(r.querySelector(`.${t.summaryExpires}`)?.remove(),e.dataset.expires){let n=document.createElement(`p`);n.className=t.summaryExpires;let i=new Date(e.dataset.expires),a=document.createElement(`time`);a.dateTime=i.toISOString(),a.textContent=i.toLocaleString(),n.textContent=`${e.dataset.expiresLabel} `,n.appendChild(a),r.appendChild(n)}}function l(t,n=!0){if(a.forEach(e=>{e.setAttribute(`aria-selected`,`false`),e.setAttribute(`tabindex`,`-1`)}),t.setAttribute(`aria-selected`,`true`),t.removeAttribute(`tabindex`),t.focus(),document.querySelectorAll(`[role=\"tabpanel\"]`).forEach(e=>{e.hidden=!0}),document.getElementById(t.getAttribute(`aria-controls`)).hidden=!1,c(t),n){let n=new URL(location.href);n.searchParams.set(e.tab,o[a.indexOf(t)]),history.replaceState(null,``,n)}}let u=new URL(location.href).searchParams.get(e.tab);if(u!==null){let e=o.indexOf(u);e>=0&&l(a[e],!1)}n.addEventListener(`click`,e=>{let t=e.target.closest(`[role=\"tab\"]`);t&&l(t)}),n.addEventListener(`keydown`,e=>{let t=a.indexOf(e.target);if(t<0)return;let n;e.key===`ArrowRight`?n=a[(t+1)%a.length]:e.key===`ArrowLeft`?n=a[(t-1+a.length)%a.length]:e.key===`Home`?n=a[0]:e.key===`End`&&(n=a[a.length-1]),n&&(e.preventDefault(),l(n))})})();</script>";
1
+ export declare const tabScript: string;
2
2
  //# sourceMappingURL=compose.main.gen.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const serviceWorker = "(function(){let e=self,t,n=`Authorization`;e.addEventListener(`activate`,t=>{t.waitUntil(e.clients.claim())}),e.addEventListener(`message`,e=>{if(!e.source)return;let r=e.data?.credential;typeof r!=`string`||!r.startsWith(`Payment `)||(t=r,typeof e.data?.header==`string`&&(n=e.data.header),e.ports[0]?.postMessage(`ack`))}),e.addEventListener(`fetch`,r=>{if(!t||r.request.mode!==`navigate`||new URL(r.request.url).origin!==e.location.origin)return;let i=new Headers(r.request.headers);i.set(n,t),t=void 0,r.respondWith(fetch(r.request,{headers:i})),e.registration.unregister()})})();";
1
+ export declare const serviceWorker: string;
2
2
  //# sourceMappingURL=serviceWorker.gen.d.ts.map
@@ -83,12 +83,10 @@ export function stripe(parameters) {
83
83
  const { client, networkId, livemode, hostedFeePayer, connect, depositAddresses, metadata } = parameters;
84
84
  if (!client.rawRequest)
85
85
  throw new Error('stripe.create() requires a Stripe SDK client with rawRequest() (v15+)');
86
- if (hostedFeePayer && !livemode)
87
- throw new Error('Stripe hosted fee payer requires a live-mode integration.');
88
86
  if (hostedFeePayer && connect)
89
87
  throw new Error('Stripe hosted fee payer does not support Connect account routing.');
90
88
  const tempoCurrency = (livemode ? tempoDefaults.tokens.usdc : tempoDefaults.tokens.pathUsd);
91
- const hostedTempoFeePayer = hostedFeePayer ? HostedFeePayer.create(client) : undefined;
89
+ const hostedTempoFeePayer = hostedFeePayer && livemode ? HostedFeePayer.create(client) : undefined;
92
90
  const tempoPaymentHandler = createPaymentSuccessHandler(client, 'tempo', connect, metadata);
93
91
  const basePaymentHandler = createPaymentSuccessHandler(client, 'base', connect, metadata);
94
92
  // All stripe-managed crypto rails use 6-decimal stablecoins. Reject amounts
@@ -121,13 +119,21 @@ export function stripe(parameters) {
121
119
  }));
122
120
  }
123
121
  function makeTempoSession(params) {
124
- const { recipient, ...rest } = params;
122
+ const { recipient, onSessionSettlement, ...rest } = params;
125
123
  return tempoSession({
126
124
  currency: tempoCurrency,
127
125
  recipient,
128
- ...(!livemode && { testnet: true }),
126
+ ...(!livemode && { chainId: tempoDefaults.chainId.testnet }),
129
127
  ...(hostedTempoFeePayer && { feePayer: hostedTempoFeePayer }),
130
128
  ...rest,
129
+ async onSessionSettlement(context) {
130
+ await tempoPaymentHandler({
131
+ intent: 'session',
132
+ receipt: { reference: context.txHash },
133
+ request: { amount: context.delta.toString() },
134
+ });
135
+ await onSessionSettlement?.(context);
136
+ },
131
137
  });
132
138
  }
133
139
  function makeBaseCharge(params) {
@@ -283,7 +289,7 @@ function customRails(additional) {
283
289
  }
284
290
  function createPaymentSuccessHandler(client, network, connect, metadata) {
285
291
  return (params) => {
286
- const { challenge, receipt, request, requestInput } = params;
292
+ const { challenge, intent, receipt, request, requestInput } = params;
287
293
  if (receipt?.reference && request?.amount) {
288
294
  const paymentIntentOptionsInput = requestInput?.paymentIntentOptions;
289
295
  const paymentIntentOptions = typeof paymentIntentOptionsInput === 'function' ? undefined : paymentIntentOptionsInput;
@@ -300,7 +306,7 @@ function createPaymentSuccessHandler(client, network, connect, metadata) {
300
306
  reference: receipt.reference,
301
307
  amount: String(request.amount),
302
308
  ...(connect && { connect }),
303
- analyticsMetadata: buildAnalytics({ challenge }),
309
+ analyticsMetadata: buildAnalytics({ challenge, intent }),
304
310
  ...(Object.keys(resolvedPaymentIntentOptions).length > 0 && {
305
311
  paymentIntentOptions: resolvedPaymentIntentOptions,
306
312
  }),
@@ -2,5 +2,6 @@ import type * as Challenge from '../../../Challenge.js';
2
2
  /** Builds Stripe metadata used to identify and analyze MPP payments. */
3
3
  export declare function buildAnalytics(parameters: {
4
4
  challenge?: Pick<Challenge.Challenge, 'id' | 'intent'> | undefined;
5
+ intent?: string | undefined;
5
6
  }): Record<string, string>;
6
7
  //# sourceMappingURL=analytics.d.ts.map
@@ -2,13 +2,13 @@ import { sdkIdentifier } from '../../../internal/version.js';
2
2
  import { machinePaymentMetadata } from '../../internal/constants.js';
3
3
  /** Builds Stripe metadata used to identify and analyze MPP payments. */
4
4
  export function buildAnalytics(parameters) {
5
- const { challenge } = parameters;
5
+ const { challenge, intent = challenge?.intent } = parameters;
6
6
  const metadata = {
7
7
  ...machinePaymentMetadata,
8
8
  mpp_sdk: sdkIdentifier,
9
+ ...(intent && { mpp_intent: intent }),
9
10
  ...(challenge && {
10
11
  mpp_challenge_id: challenge.id,
11
- mpp_intent: challenge.intent,
12
12
  }),
13
13
  };
14
14
  return Object.fromEntries(Object.entries(metadata).map(([key, value]) => [key, [...value].slice(0, 500).join('')]));
@@ -1,2 +1,2 @@
1
- export declare const html = "<script>(function(){var e=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},t=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),n=t((e=>{Object.defineProperty(e,\"__esModule\",{value:!0});function t(e){\"@babel/helpers - typeof\";return t=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t(e)}var n=`dahlia`,r=function(e){return e===3?`v3`:e},i=`https://js.stripe.com`,a=`${i}/${n}/stripe.js`,o=/^https:\\/\\/js\\.stripe\\.com\\/v3\\/?(\\?.*)?$/,s=/^https:\\/\\/js\\.stripe\\.com\\/(v3|[a-z]+)\\/stripe\\.js(\\?.*)?$/,c=`loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used`,l=function(e){return o.test(e)||s.test(e)},u=function(){for(var e=document.querySelectorAll(`script[src^=\"${i}\"]`),t=0;t<e.length;t++){var n=e[t];if(l(n.src))return n}return null},d=function(e){var t=e&&!e.advancedFraudSignals?`?advancedFraudSignals=false`:``,n=document.createElement(`script`);n.src=`${a}${t}`;var r=document.head||document.body;if(!r)throw Error(`Expected document.body not to be null. Stripe.js requires a <body> element.`);return r.appendChild(n),n},f=function(e,t){!e||!e._registerWrapper||e._registerWrapper({name:`stripe-js`,version:`9.13.0`,startTime:t})},p=null,m=null,h=null,ee=function(e){return function(t){e(Error(`Failed to load Stripe.js`,{cause:t}))}},g=function(e,t){return function(){window.Stripe?e(window.Stripe):t(Error(`Stripe.js not available`))}},_=function(e){return p===null?(p=new Promise(function(t,n){if(typeof window>`u`||typeof document>`u`){t(null);return}if(window.Stripe&&e&&console.warn(c),window.Stripe){t(window.Stripe);return}try{var r=u();if(r&&e)console.warn(c);else if(!r)r=d(e);else if(r&&h!==null&&m!==null){var i;r.removeEventListener(`load`,h),r.removeEventListener(`error`,m),(i=r.parentNode)==null||i.removeChild(r),r=d(e)}h=g(t,n),m=ee(n),r.addEventListener(`load`,h),r.addEventListener(`error`,m)}catch(e){n(e);return}}),p.catch(function(e){return p=null,Promise.reject(e)})):p},te=function(e,i,a){if(e===null)return null;var o=i[0];if(typeof o!=`string`)throw Error(`Expected publishable key to be of type string, got type ${t(o)} instead.`);var s=o.match(/^pk_test/),c=r(e.version),l=n;s&&c!==l&&console.warn(`Stripe.js@${c} was loaded on the page, but @stripe/stripe-js@9.13.0 expected Stripe.js@${l}. This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning`);var u=e.apply(void 0,i);return f(u,a),u},v=function(e){var n=`invalid load parameters; expected object of shape\n\n {advancedFraudSignals: boolean}\n\nbut received\n\n ${JSON.stringify(e)}\n`;if(e===null||t(e)!==`object`)throw Error(n);if(Object.keys(e).length===1&&typeof e.advancedFraudSignals==`boolean`)return e;throw Error(n)},y,b=!1,x=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];b=!0;var r=Date.now();return _(y).then(function(e){return te(e,t,r)})};x.setLoadParameters=function(e){if(b&&y){var t=v(e);if(Object.keys(t).reduce(function(t,n){return t&&e[n]===y?.[n]},!0))return}if(b)throw Error(`You cannot change load parameters after calling loadStripe`);y=v(e)},e.loadStripe=x})),r=t(((e,t)=>{t.exports=n()}));let i={payment:`Payment`};var a,o=e((()=>{a=`0.1.1`}));function s(){return a}var c=e((()=>{o()}));function l(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?l(e.cause,t):t?null:e}var u,d=e((()=>{c(),u=class e extends Error{static setStaticOptions(t){e.prototype.docsOrigin=t.docsOrigin,e.prototype.showVersion=t.showVersion,e.prototype.version=t.version}constructor(t,n={}){let r=(()=>{if(n.cause instanceof e){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&`details`in n.cause&&typeof n.cause.details==`string`?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=n.docsOrigin??e.prototype.docsOrigin,o=`${a}${i??``}`,s=!!(n.version??e.prototype.showVersion),c=n.version??e.prototype.version,l=[t||`An error occurred.`,...n.metaMessages?[``,...n.metaMessages]:[],...r||i||s?[``,r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0,s?`Version: ${c}`:void 0]:[]].filter(e=>typeof e==`string`).join(`\n`);super(l,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,\"details\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"docs\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"docsOrigin\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"docsPath\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"shortMessage\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"showVersion\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"version\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"cause\",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,\"name\",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsOrigin=a,this.docsPath=i,this.shortMessage=t,this.showVersion=s,this.version=c}walk(e){return l(this,e)}},Object.defineProperty(u,\"defaultStaticOptions\",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${s()}`}}),u.setStaticOptions(u.defaultStaticOptions)}));function f(e,t){if(y(e)>t)throw new x({givenSize:y(e),maxSize:t})}function p(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new S({size:e.length,targetSize:r,type:`Bytes`});let i=new Uint8Array(r);for(let t=0;t<r;t++){let a=n===`right`;i[a?t:r-t-1]=e[a?t:e.length-t-1]}return i}var m=e((()=>{ne()}));function h(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`){if(!Number.isFinite(e))throw TypeError(`Cannot canonicalize non-finite number`);return Object.is(e,-0)?`0`:JSON.stringify(e)}if(typeof e==`bigint`)throw TypeError(`Cannot canonicalize bigint`);if(Array.isArray(e))return`[${e.map(e=>h(e)).join(`,`)}]`;if(typeof e==`object`)return`{${Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return r!==void 0&&t.push(`${JSON.stringify(n)}:${h(r)}`),t},[]).join(`,`)}}`}function ee(e,t){return JSON.parse(e,(e,n)=>{let r=n;return typeof r==`string`&&r.endsWith(g)?BigInt(r.slice(0,-9)):typeof t==`function`?t(e,r):r})}var g,_=e((()=>{g=`#__bigint`}));function te(e,t={}){let{size:n}=t,r=b.encode(e);return typeof n==`number`?(f(r,n),v(r,n)):r}function v(e,t){return p(e,{dir:`right`,size:t})}function y(e){return e.length}var b,x,S,ne=e((()=>{d(),m(),_(),b=new TextEncoder,x=class extends u{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \\`${t}\\` bytes. Given size: \\`${e}\\` bytes.`),Object.defineProperty(this,\"name\",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeOverflowError`})}},S=class extends u{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\\`${e}\\`) exceeds padding size (\\`${t}\\`).`),Object.defineProperty(this,\"name\",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeExceedsPaddingSizeError`})}}}));ne();let re=new TextDecoder,C=Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[t,e.charCodeAt(0)]));({...Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[e.charCodeAt(0),t]))});function ie(e,t={}){let{pad:n=!0,url:r=!1}=t,i=new Uint8Array(Math.ceil(e.length/3)*4);for(let t=0,n=0;n<e.length;t+=4,n+=3){let r=(e[n]<<16)+(e[n+1]<<8)+(e[n+2]|0);i[t]=C[r>>18],i[t+1]=C[r>>12&63],i[t+2]=C[r>>6&63],i[t+3]=C[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=re.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function ae(e,t={}){return ie(te(e),t)}_();function oe(e){return ae(h(e),{pad:!1,url:!0})}var se;function w(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,\"_zod\",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,\"name\",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,\"init\",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,\"name\",{value:e}),o}var T=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},ce=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(se=globalThis).__zod_globalConfig??(se.__zod_globalConfig={});let le=globalThis.__zod_globalConfig;function E(e){return e&&Object.assign(le,e),le}function ue(e,t){return typeof t==`bigint`?t.toString():t}function de(e){return{get value(){{let t=e();return Object.defineProperty(this,\"value\",{value:t}),t}}}}function fe(e){return e==null}function D(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}let O=Symbol(`evaluating`);function k(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==O)return r===void 0&&(r=O,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}let pe=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function A(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function me(e){if(A(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return A(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function he(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function j(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error(\"Cannot specify both `message` and `error` params\");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function ge(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}-Number.MAX_VALUE,Number.MAX_VALUE;function M(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function _e(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function N(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function P(e){return typeof e==`string`?e:e?.message}function F(e,t,n){let r=e.message?e.message:P(e.inst?._zod.def?.error?.(e))??P(t?.error?.(e))??P(n.customError?.(e))??P(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function ve(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function ye(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}let be=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,\"_zod\",{value:e._zod,enumerable:!1}),Object.defineProperty(e,\"issues\",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ue,2),Object.defineProperty(e,\"toString\",{value:()=>e.message,enumerable:!1})},xe=w(`$ZodError`,be),I=w(`$ZodError`,be,{Parent:Error}),Se=(e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new T;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>F(e,a,E())));throw pe(t,i?.callee),t}return o.value})(I),Ce=(e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>F(e,a,E())));throw pe(t,i?.callee),t}return o.value})(I),we=(e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new T;return a.issues.length?{success:!1,error:new(e??xe)(a.issues.map(e=>F(e,i,E())))}:{success:!0,data:a.value}})(I),Te=(e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>F(e,i,E())))}:{success:!0,data:a.value}})(I),Ee=e=>{let t=e?`[\\\\s\\\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\\\s\\\\S]*`;return RegExp(`^${t}$`)},De=/^-?\\d+(?:\\.\\d+)?$/,L=w(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Oe=w(`$ZodCheckMinLength`,(e,t)=>{var n;L.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!fe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=ve(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ke=w(`$ZodCheckStringFormat`,(e,t)=>{var n,r;L.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Ae=w(`$ZodCheckRegex`,(e,t)=>{ke.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),je={major:4,minor:4,patch:3},R=w(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=je;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=M(e),i;for(let a of t){if(a._zod.def.when){if(_e(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new T;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=M(e,t))});else{if(e.issues.length===t)continue;r||=M(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(M(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new T;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new T;return o.then(e=>t(e,r,a))}return t(o,r,a)}}k(e,`~standard`,()=>({validate:t=>{try{let n=we(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Te(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Me=w(`$ZodString`,(e,t)=>{R.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Ee(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),Ne=w(`$ZodNumber`,(e,t)=>{R.init(e,t),e._zod.pattern=e._zod.bag.pattern??De,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}});function z(e,t,n){e.issues.length&&t.issues.push(...N(n,e.issues)),t.value[n]=e.value}let Pe=w(`$ZodArray`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>z(t,n,e))):z(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function B(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...N(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Fe(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key \"${n}\": expected a Zod schema`);let n=ge(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Ie(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>B(e,n,i,t,u,d))):B(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}let Le=w(`$ZodObject`,(e,t)=>{if(R.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,\"shape\",{get:()=>{let n={...e};return Object.defineProperty(t,\"shape\",{value:n}),n}})}let n=de(()=>Fe(t));k(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=A,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>B(n,t,e,s,r,i))):B(a,t,e,s,r,i)}return i?Ie(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}});function V(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!M(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>F(e,r,E())))}),t)}let Re=w(`$ZodUnion`,(e,t)=>{R.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>D(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>V(t,r,e,i)):V(o,r,e,i)}}),ze=w(`$ZodRecord`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!me(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>F(e,r,E())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...N(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...N(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&De.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>F(e,r,E())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...N(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...N(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Be=w(`$ZodTransform`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new ce(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new T;return n.value=i,n.fallback=!0,n}});function H(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}let Ve=w(`$ZodOptional`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${D(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>H(e,r)):H(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),He=w(`$ZodPipe`,(e,t)=>{R.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),k(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>U(e,t.in,n)):U(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>U(e,t.out,n)):U(r,t.out,n)}});function U(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}let Ue=w(`$ZodCustom`,(e,t)=>{L.init(e,t),R.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>We(t,n,r,e));We(i,n,r,e)}});function We(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(ye(e))}}function Ge(e,t){return new e({type:`string`,...j(t)})}function Ke(e,t){return new e({type:`number`,checks:[],...j(t)})}function W(e,t){return new Oe({check:`min_length`,...j(t),minimum:e})}function qe(e,t){return new Ae({check:`string_format`,format:`regex`,...j(t),pattern:e})}function Je(e,t,n){let r=j(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}let G=w(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);R.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>Se(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>we(e,t,n),e.parseAsync=async(t,n)=>Ce(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Te(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>he(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),Ye=w(`ZodMiniString`,(e,t)=>{Me.init(e,t),G.init(e,t)});function K(e){return Ge(Ye,e)}let Xe=w(`ZodMiniNumber`,(e,t)=>{Ne.init(e,t),G.init(e,t)});function Ze(e){return Ke(Xe,e)}let Qe=w(`ZodMiniArray`,(e,t)=>{Pe.init(e,t),G.init(e,t)});function $e(e,t){return new Qe({type:`array`,element:e,...j(t)})}let et=w(`ZodMiniObject`,(e,t)=>{Le.init(e,t),G.init(e,t),k(e,`shape`,()=>t.shape)});function q(e,t){let n={type:`object`,shape:e??{},...j(t)};return new et(n)}let tt=w(`ZodMiniUnion`,(e,t)=>{Re.init(e,t),G.init(e,t)});function nt(e,t){return new tt({type:`union`,options:e,...j(t)})}let rt=w(`ZodMiniRecord`,(e,t)=>{ze.init(e,t),G.init(e,t)});function it(e,t,n){return!t||!t._zod?new rt({type:`record`,keyType:K(),valueType:e,...j(t)}):new rt({type:`record`,keyType:e,valueType:t,...j(n)})}let at=w(`ZodMiniTransform`,(e,t)=>{Be.init(e,t),G.init(e,t)});function ot(e){return new at({type:`transform`,transform:e})}let st=w(`ZodMiniOptional`,(e,t)=>{Ve.init(e,t),G.init(e,t)});function J(e){return new st({type:`optional`,innerType:e})}let ct=w(`ZodMiniPipe`,(e,t)=>{He.init(e,t),G.init(e,t)});function lt(e,t){return new ct({type:`pipe`,in:e,out:t})}let ut=w(`ZodMiniCustom`,(e,t)=>{Ue.init(e,t),G.init(e,t)});function dt(e,t){return Je(ut,e??(()=>!0),t)}function ft(){return K().check(qe(/^\\d+(\\.\\d+)?$/,`Invalid amount`))}function pt(e){let{meta:t,opaque:n,request:r,...a}=e.challenge,o=n??(t===void 0?void 0:oe(t)),s={challenge:{...a,...o!==void 0&&{opaque:o},request:oe(r)},payload:e.payload,...e.source&&{source:e.source}},c=ae(JSON.stringify(s),{pad:!1,url:!0});return`${i.payment} ${c}`}function mt(e){return e}function ht(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}function gt(e,t){if(!Number.isInteger(t)||t<0)throw RangeError(`Decimals must be a non-negative integer.`);if(!/^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)$/.test(e))throw TypeError(`Value \\`${e}\\` is not a valid decimal number.`);let n=e.startsWith(`-`),[r=`0`,i=``]=(n?e.slice(1):e).split(`.`),a=i.slice(0,t).padEnd(t,`0`),o=BigInt(`${r||`0`}${a}`);return i.length>t&&i[t]>=`5`&&(o+=1n),n?-o:o}let _t=nt([q({customer:J(K().check(W(1))),hooks:J(q({inputs:q({tax:q({calculation:K().check(W(1))})})})),metadata:J(it(K(),K())),receipt_email:J(K().check(W(1)))}),dt(e=>typeof e==`function`)]),vt=mt({name:`stripe`,intent:`charge`,schema:{credential:{payload:q({externalId:J(K()),spt:K()})},request:lt(q({amount:ft(),currency:K(),decimals:Ze(),description:J(K()),externalId:J(K()),metadata:J(it(K(),K())),networkId:K(),paymentIntentOptions:J(_t),paymentMethodTypes:$e(K()).check(W(1)),recipient:J(K())}),ot(({amount:e,decimals:t,metadata:n,networkId:r,paymentIntentOptions:i,paymentMethodTypes:a,...o})=>({...o,amount:gt(e,t).toString(),methodDetails:{networkId:r,paymentMethodTypes:a,...n!==void 0&&{metadata:n}}})))}});function yt(e){let{client:t,createToken:n,externalId:r,paymentMethod:i}=e;return ht(vt,{context:q({paymentMethod:J(K())}),async createCredential({challenge:e,context:a}){let o=a?.paymentMethod??i;if(!o)throw Error(`paymentMethod is required (pass via context or parameters)`);let s=e.request.amount,c=e.request.currency,l=typeof e.request.externalId==`string`?e.request.externalId:void 0,u=e.request.methodDetails?.networkId;if(!u)throw Error(`networkId is required in challenge.methodDetails`);let d=e.request.methodDetails?.metadata;if(d?.externalId)throw Error(`methodDetails.metadata.externalId is reserved; use credential externalId instead`);let f=e.expires?Math.floor(new Date(e.expires).getTime()/1e3):Math.floor(Date.now()/1e3)+3600,p=await n({amount:s,challenge:e,client:t,currency:c,expiresAt:f,metadata:d,networkId:u,paymentMethod:o}),m=l??r;return pt({challenge:e,payload:{spt:p,...m===void 0?{}:{externalId:m}}})}})}function bt(e){return[yt(e)]}(function(e){e.charge=yt})(bt||={});var xt=r();let Y={data:`__MPPX_DATA__`,error:`root_error`,root:`root`},St={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},X={challengeId:`data-mppx-challenge-id`,remaining:`data-remaining`};var Z=class{name;constructor(e){this.name=`--mppx-${e}`}toString(){return`var(${this.name})`}};let Ct={accent:new Z(`accent`),background:new Z(`background`),border:new Z(`border`),foreground:new Z(`foreground`),muted:new Z(`muted`),negative:new Z(`negative`),positive:new Z(`positive`),surface:new Z(`surface`),fontFamily:new Z(`font-family`),fontSizeBase:new Z(`font-size-base`),radius:new Z(`radius`),spacingUnit:new Z(`spacing-unit`)};String.raw`<style>\n *,\n ::after,\n ::before,\n ::backdrop,\n ::file-selector-button {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: 0 solid;\n border-color: ${Ct.border};\n }\n html,\n :host {\n line-height: 1.5;\n -webkit-text-size-adjust: 100%;\n tab-size: 4;\n -webkit-tap-highlight-color: transparent;\n }\n h1,\n h2,\n h3,\n h4,\n h5,\n h6 {\n font-size: inherit;\n font-weight: inherit;\n }\n a {\n color: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n }\n b,\n strong {\n font-weight: bolder;\n }\n code,\n kbd,\n samp,\n pre {\n font-family:\n ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',\n monospace;\n font-size: 1em;\n }\n small {\n font-size: 80%;\n }\n ol,\n ul,\n menu {\n list-style: none;\n }\n img,\n svg,\n video,\n canvas,\n audio,\n iframe,\n embed,\n object {\n display: block;\n vertical-align: middle;\n }\n img,\n video {\n max-width: 100%;\n height: auto;\n }\n button,\n input,\n select,\n optgroup,\n textarea,\n ::file-selector-button {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n border-radius: 0;\n background-color: transparent;\n opacity: 1;\n }\n ::file-selector-button {\n margin-inline-end: 4px;\n }\n ::placeholder {\n opacity: 1;\n }\n @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {\n ::placeholder {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n }\n textarea {\n resize: vertical;\n }\n ::-webkit-search-decoration {\n -webkit-appearance: none;\n }\n :-moz-ui-invalid {\n box-shadow: none;\n }\n button,\n input:where([type='button'], [type='reset'], [type='submit']),\n ::file-selector-button {\n appearance: button;\n }\n ::-webkit-inner-spin-button,\n ::-webkit-outer-spin-button {\n height: auto;\n }\n [hidden]:where(:not([hidden='until-found'])) {\n display: none !important;\n }\n</style>`;function wt(e,t){if(t==null)return e;if(!Q(e)||!Q(t))return t??e;let n={...e};for(let[e,r]of Object.entries(t)){if(r==null||r===``)continue;let t=n[e];n[e]=Q(t)&&Q(r)?wt(t,r):r}return n}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Tt(e,t=`Authorization`){let n=new URL(location.href);n.searchParams.set(St.serviceWorker,``);let r=await navigator.serviceWorker.register(n.pathname+n.search),i=await new Promise(e=>{let t=r.installing??r.waiting??r.active;if(t?.state===`activated`)return e(t);let n=t??r;n.addEventListener(`statechange`,function t(){let i=r.active;i?.state===`activated`&&(n.removeEventListener(`statechange`,t),e(i))})});await new Promise(n=>{let r=new MessageChannel;r.port1.onmessage=()=>n(),i.postMessage({credential:e,header:t},[r.port2])}),location.reload()}_();function Et(e){let t=document.getElementById(Y.data),n=ee(t.textContent),r=t.getAttribute(X.remaining);!r||Number(r)<=1?t.remove():t.setAttribute(X.remaining,String(Number(r)-1));let i=document.currentScript,a=i?.getAttribute(X.challengeId),o=a?(i.removeAttribute(X.challengeId),n[a]):Object.values(n).find(t=>t.challenge.method===e);return{...o,error(e){if(!e){document.getElementById(Y.error)?.remove();return}let t=document.getElementById(Y.error);if(t){t.textContent=e;return}let n=document.createElement(`p`);n.id=Y.error,n.className=`mppx-error`,n.role=`alert`,n.textContent=e,document.getElementById(o.rootId)?.after(n)},root:document.getElementById(o.rootId),submit:e=>Tt(e,o.challenge.header),vars:Ct}}let $=Et(`stripe`),Dt=String.raw,Ot=document.createElement(`style`);Ot.textContent=Dt`\n form {\n display: flex;\n flex-direction: column;\n gap: calc(${$.vars.spacingUnit} * 8);\n }\n button {\n background: ${$.vars.accent};\n border-radius: ${$.vars.radius};\n color: ${$.vars.background};\n cursor: pointer;\n font-weight: 500;\n padding: calc(${$.vars.spacingUnit} * 4) calc(${$.vars.spacingUnit} * 8);\n width: 100%;\n }\n button:hover:not(:disabled) {\n opacity: 0.85;\n }\n button:disabled {\n cursor: default;\n opacity: 0.5;\n }\n`,$.root.append(Ot),(async()=>{let e=await(0,xt.loadStripe)($.config.publishableKey);if(!e)throw Error(`Failed to loadStripe`);let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{let e=(()=>{if($.config.elements?.options?.appearance?.theme)return $.config.elements?.options?.appearance?.theme;switch($.theme.colorScheme){case`light dark`:return t.matches?`night`:`stripe`;case`light`:return`stripe`;case`dark`:return`night`}})(),n=+!!t.matches;return wt({disableAnimations:!0,theme:e,variables:{borderRadius:$.theme.radius,colorBackground:$.theme.surface[n],colorDanger:$.theme.negative[n],colorPrimary:$.theme.accent[n],colorText:$.theme.foreground[n],colorTextSecondary:$.theme.muted[n],fontSizeBase:$.theme.fontSizeBase,fontFamily:$.theme.fontFamily,spacingUnit:$.theme.spacingUnit}},$.config.elements?.options?.appearance??{})},r=e.elements({appearance:n(),...$.config.elements?.options,amount:Number($.challenge.request.amount),currency:$.challenge.request.currency,mode:`payment`,paymentMethodCreation:`manual`,paymentMethodTypes:$.challenge.request.methodDetails.paymentMethodTypes});t.addEventListener(`change`,()=>{r.update({appearance:n()})});let i=document.createElement(`form`);r.create(`payment`,$.config.elements?.paymentOptions).mount(i),$.root.appendChild(i);let a=document.createElement(`button`);a.textContent=$.text.pay,a.type=`submit`,i.appendChild(a),i.onsubmit=async t=>{t.preventDefault(),$.error(),a.disabled=!0;try{await r.submit();let{paymentMethod:t,error:n}=await e.createPaymentMethod({...$.config.elements?.createPaymentMethodOptions,elements:r});if(n||!t)throw n??Error(`Failed to create payment method`);let i=await bt({client:e,createToken:kt})[0].createCredential({challenge:$.challenge,context:{paymentMethod:t.id}});await $.submit(i)}catch(e){$.error(e instanceof Error?e.message:`Payment failed`)}finally{a.disabled=!1}}})();async function kt(e){let t=new URL($.config.createTokenUrl,location.origin);if(t.origin!==location.origin)throw Error(`createTokenUrl must be same-origin`);let n=await fetch(t,{method:`POST`,headers:{\"Content-Type\":`application/json`},body:JSON.stringify(e)});if(!n.ok){let e=await n.text().catch(()=>`<response body unavailable>`);throw Error(`Failed to create SPT (${n.status}): ${e}`)}return(await n.json()).spt}})();</script>";
1
+ export declare const html: string;
2
2
  //# sourceMappingURL=html.gen.d.ts.map
@@ -13,9 +13,9 @@ export function recordCryptoPayment(client, parameters) {
13
13
  const { network, reference, amount, connect, analyticsMetadata, paymentIntentOptions } = parameters;
14
14
  const { customer, hooks, metadata, receipt_email } = paymentIntentOptions ?? {};
15
15
  const { stripeNetworkName, tokenDecimals } = NETWORK_CONFIG[network];
16
- const amountCents = Math.round(Number(amount) / 10 ** (tokenDecimals - 2));
16
+ const amountCents = Number(BigInt(amount) / 10n ** BigInt(tokenDecimals - 2));
17
17
  if (amountCents < 1) {
18
- console.warn(`[stripe] skipping PI recording: ${amount} raw units on ${network} rounds to ${amountCents} cents (below Stripe minimum)`);
18
+ console.warn(`[stripe] skipping PI recording: ${amount} raw units on ${network} floors to ${amountCents} cents (below Stripe minimum)`);
19
19
  return Promise.resolve();
20
20
  }
21
21
  const requiredParams = {
@@ -35,6 +35,7 @@ export declare const charge: {
35
35
  }, z.core.$strip>], "type">;
36
36
  };
37
37
  request: z.ZodMiniPipe<z.ZodMiniObject<{
38
+ machineTokenEnabled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
38
39
  amount: z.ZodMiniString<string>;
39
40
  chainId: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
40
41
  currency: z.ZodMiniString<string>;
@@ -42,7 +43,7 @@ export declare const charge: {
42
43
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
43
44
  externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
44
45
  feePayer: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniCustom<Account, Account>]>, z.ZodMiniTransform<boolean, boolean | Account>>>;
45
- memo: z.ZodMiniOptional<z.ZodMiniString<string>>;
46
+ memo: z.ZodMiniOptional<z.ZodMiniNever>;
46
47
  recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
47
48
  splits: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
48
49
  amount: z.ZodMiniString<string>;
@@ -60,9 +61,9 @@ export declare const charge: {
60
61
  recipient?: string | undefined;
61
62
  amount: string;
62
63
  methodDetails?: {
64
+ machineTokenEnabled?: boolean | undefined;
63
65
  chainId?: number | undefined;
64
66
  feePayer?: boolean | undefined;
65
- memo?: string | undefined;
66
67
  splits?: {
67
68
  memo?: string | undefined;
68
69
  recipient: `0x${string}`;
@@ -71,6 +72,7 @@ export declare const charge: {
71
72
  supportedModes?: ("pull" | "push")[] | undefined;
72
73
  } | undefined;
73
74
  }, {
75
+ machineTokenEnabled?: boolean | undefined;
74
76
  amount: string;
75
77
  chainId?: number | undefined;
76
78
  currency: string;
@@ -78,7 +80,7 @@ export declare const charge: {
78
80
  description?: string | undefined;
79
81
  externalId?: string | undefined;
80
82
  feePayer?: boolean | undefined;
81
- memo?: string | undefined;
83
+ memo?: undefined;
82
84
  recipient?: string | undefined;
83
85
  splits?: {
84
86
  amount: string;
@@ -82,6 +82,7 @@ export const charge = Method.from({
82
82
  },
83
83
  request: z.pipe(z
84
84
  .object({
85
+ machineTokenEnabled: z.optional(z.boolean()),
85
86
  amount: z.amount(),
86
87
  chainId: z.optional(z.number()),
87
88
  currency: z.string(),
@@ -89,7 +90,7 @@ export const charge = Method.from({
89
90
  description: z.optional(z.string()),
90
91
  externalId: z.optional(z.string()),
91
92
  feePayer: z.optional(z.pipe(z.union([z.boolean(), z.custom()]), z.transform((v) => (typeof v === 'object' ? true : v)))),
92
- memo: z.optional(z.hash()),
93
+ memo: z.optional(z.never()),
93
94
  recipient: z.optional(z.string()),
94
95
  splits: z.optional(z.array(split).check(z.minLength(1), z.maxLength(10))),
95
96
  supportedModes: z.optional(z.array(z.enum(chargeModes)).check(z.minLength(1))),
@@ -101,19 +102,19 @@ export const charge = Method.from({
101
102
  const splitTotal = splits.reduce((sum, split) => sum + parseUnits(split.amount, decimals), 0n);
102
103
  return (splits.every((split) => parseUnits(split.amount, decimals) > 0n) &&
103
104
  splitTotal < totalAmount);
104
- }, 'Invalid splits')), z.transform(({ amount, chainId, decimals, feePayer, memo, splits, supportedModes, ...rest }) => ({
105
+ }, 'Invalid splits')), z.transform(({ machineTokenEnabled, amount, chainId, decimals, feePayer, memo: _memo, splits, supportedModes, ...rest }) => ({
105
106
  ...rest,
106
107
  amount: parseUnits(amount, decimals).toString(),
107
- ...(chainId !== undefined ||
108
+ ...(machineTokenEnabled !== undefined ||
109
+ chainId !== undefined ||
108
110
  feePayer !== undefined ||
109
- memo !== undefined ||
110
111
  splits !== undefined ||
111
112
  supportedModes !== undefined
112
113
  ? {
113
114
  methodDetails: {
115
+ ...(machineTokenEnabled !== undefined && { machineTokenEnabled }),
114
116
  ...(chainId !== undefined && { chainId }),
115
117
  ...(feePayer !== undefined && { feePayer }),
116
- ...(memo !== undefined && { memo }),
117
118
  ...(splits !== undefined && {
118
119
  splits: splits.map((split) => ({
119
120
  ...split,