mppx 0.18.0 → 0.18.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 (90) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/Currency.d.ts +59 -0
  3. package/dist/Currency.js +60 -0
  4. package/dist/Errors.d.ts +13 -0
  5. package/dist/Errors.js +15 -6
  6. package/dist/cli/cli.js +135 -135
  7. package/dist/cli/plugins/index.js +12 -12
  8. package/dist/cli/plugins/tempo.js +13 -1
  9. package/dist/client/internal/Fetch.d.ts +5 -0
  10. package/dist/client/internal/Fetch.js +7 -0
  11. package/dist/cloudflare/ChannelStore.d.ts +1 -2
  12. package/dist/cloudflare/ChannelStore.js +14 -20
  13. package/dist/cloudflare/Channels.d.ts +20 -2
  14. package/dist/cloudflare/Channels.js +47 -4
  15. package/dist/cloudflare/index.d.ts +1 -1
  16. package/dist/cloudflare/index.js +1 -1
  17. package/dist/discovery/Discovery.d.ts +116 -9
  18. package/dist/discovery/Discovery.js +169 -0
  19. package/dist/evm/server/Charge.js +2 -3
  20. package/dist/evm/server/Methods.d.ts +1 -1
  21. package/dist/evm/server/Methods.js +3 -2
  22. package/dist/extensions/identity/email-otp/client/index.js +4 -4
  23. package/dist/extensions/identity/index.d.ts +4 -0
  24. package/dist/extensions/identity/index.js +4 -0
  25. package/dist/extensions/identity/link/Constants.d.ts +102 -0
  26. package/dist/extensions/identity/link/Constants.js +16 -0
  27. package/dist/extensions/identity/link/client/index.d.ts +80 -0
  28. package/dist/extensions/identity/link/client/index.js +211 -0
  29. package/dist/extensions/identity/link/index.d.ts +12 -0
  30. package/dist/extensions/identity/link/index.js +12 -0
  31. package/dist/extensions/identity/link/server/index.d.ts +124 -0
  32. package/dist/extensions/identity/link/server/index.js +518 -0
  33. package/dist/extensions/identity/persona/Constants.d.ts +24 -0
  34. package/dist/extensions/identity/persona/Constants.js +24 -0
  35. package/dist/extensions/identity/persona/Did.d.ts +24 -0
  36. package/dist/extensions/identity/persona/Did.js +24 -0
  37. package/dist/extensions/identity/persona/Types.d.ts +21 -0
  38. package/dist/extensions/identity/persona/Types.js +2 -0
  39. package/dist/extensions/identity/persona/index.d.ts +10 -0
  40. package/dist/extensions/identity/persona/index.js +9 -0
  41. package/dist/extensions/identity/persona/server/index.d.ts +152 -0
  42. package/dist/extensions/identity/persona/server/index.js +263 -0
  43. package/dist/identity/Headers.d.ts +6 -1
  44. package/dist/identity/Headers.js +6 -1
  45. package/dist/identity/Server.js +2 -0
  46. package/dist/identity/Types.d.ts +5 -0
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +1 -0
  49. package/dist/internal/version.d.ts +2 -2
  50. package/dist/internal/version.js +1 -1
  51. package/dist/proxy/internal/Headers.js +4 -4
  52. package/dist/server/Mppx.js +5 -2
  53. package/dist/stripe/server/internal/html.gen.js +1 -1
  54. package/dist/tempo/client/Charge.d.ts +11 -8
  55. package/dist/tempo/client/Charge.js +53 -6
  56. package/dist/tempo/index.d.ts +4 -0
  57. package/dist/tempo/index.js +4 -0
  58. package/dist/tempo/internal/auto-swap.d.ts +6 -5
  59. package/dist/tempo/internal/auto-swap.js +17 -2
  60. package/dist/tempo/internal/currencies.d.ts +5 -4
  61. package/dist/tempo/internal/currencies.js +13 -9
  62. package/dist/tempo/internal/defaults.d.ts +7 -0
  63. package/dist/tempo/internal/defaults.js +7 -0
  64. package/dist/tempo/internal/fee-payer.js +8 -2
  65. package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
  66. package/dist/tempo/internal/machine-token-charge.js +82 -1
  67. package/dist/tempo/server/Charge.js +59 -2
  68. package/dist/tempo/server/Methods.d.ts +1 -1
  69. package/dist/tempo/server/internal/html.gen.js +1 -1
  70. package/dist/tempo/server/internal/transport.d.ts +1 -1
  71. package/dist/tempo/server/internal/transport.js +9 -16
  72. package/dist/tempo/session/client/CredentialState.js +31 -0
  73. package/dist/tempo/session/client/Session.d.ts +12 -6
  74. package/dist/tempo/session/client/Session.js +64 -18
  75. package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
  76. package/dist/tempo/session/server/ChannelStore.js +58 -8
  77. package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
  78. package/dist/tempo/session/server/CloseSupervisor.js +110 -12
  79. package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
  80. package/dist/tempo/session/server/CredentialVerification.js +6 -32
  81. package/dist/tempo/session/server/Session.js +6 -3
  82. package/dist/tempo/session/server/Settlement.d.ts +7 -0
  83. package/dist/tempo/session/server/Settlement.js +36 -6
  84. package/dist/tempo/session/server/Sse.d.ts +2 -0
  85. package/dist/tempo/session/server/Sse.js +12 -12
  86. package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
  87. package/dist/tempo/subscription/KeyAuthorization.js +1 -1
  88. package/dist/x402/Assets.d.ts +14 -5
  89. package/dist/x402/Assets.js +11 -16
  90. package/package.json +15 -3
@@ -1,3 +1,3 @@
1
1
  // Generated — do not edit.
2
- export 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.17.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.17.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 ne({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((()=>{re()}));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,ne,re=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`})}},ne=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`})}}}));re();let ie=new TextDecoder,S=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 ae(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]=S[r>>18],i[t+1]=S[r>>12&63],i[t+2]=S[r>>6&63],i[t+3]=S[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=ie.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function oe(e,t={}){return ae(te(e),t)}_();function se(e){return oe(h(e),{pad:!1,url:!0})}function ce(e,t){return typeof t==`bigint`?t.toString():t}var le=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function ue(e){return new le(e)}function de(e){return e==null}function fe(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function pe(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}let me=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function C(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function he(e){if(C(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return C(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function ge(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function w(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 _e(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}function T(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 ve(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 E(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function D(e){return typeof e==`string`?e:e?.message}function ye(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function O(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function k(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:D(e.inst?._zod.def?.error?.(e))??D(a?.(e))??D(t?.error?.(e))??D(n.customError?.(e))??D(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}let be=/[\\uD800-\\uDBFF]/;function xe(e){let t=e.length;if(!be.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function Se(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Ce(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function we(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Ee(e,n,r.value)}}function A(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Te(e,t,n){return A(e,t,n,!1)}function Ee(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:A(this,t,n.bind(this))},set(e){A(this,t,e)}})}function De(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let j,M=!1,Oe={configurable:!0,get(){M=!0}};function N(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&j!==e._zod){j=void 0;return}j=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Oe);let e=M;M=!1;try{let r=n(this);return M?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),M||=e,r}catch(n){throw delete this[t],M||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function ke(e,t,n,r){let i=De(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var Ae;let P={value:void 0,enumerable:!1},je=`captureStackTrace`in Error?Error:null;function Me(e){let t=je;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return je=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function F(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){P.value=new a(r);try{Object.defineProperty(n,\"_zod\",P)}finally{P.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),we(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,\"name\",{value:e});function d(e){let t=r?.Parent?Me(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,\"init\",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,\"name\",{value:e}),d}var I=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Ne=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Ae=globalThis).__zod_globalConfig??(Ae.__zod_globalConfig={});let L=globalThis.__zod_globalConfig;function R(e){return e&&Object.assign(L,e),L}function Pe(){let e=this._zod;return e.message??=JSON.stringify(e.def,ce,2),e.message}function Fe(e){this._zod.message=e}let Ie={get:Pe,set:Fe,enumerable:!0,configurable:!0},Le={value:void 0,enumerable:!1},Re=new WeakSet([Object.prototype,Error.prototype]),ze=(e,t)=>{e.name=`$ZodError`,Le.value=t,Object.defineProperty(e,\"issues\",Le),Le.value=void 0,Object.defineProperty(e,\"message\",Ie);let n=Object.getPrototypeOf(e);Re.has(n)||(Re.add(n),Object.defineProperty(n,\"toString\",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,\"toString\",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,\"toString\",{value:e,configurable:!0,writable:!0})}}))};F(`$ZodError`,ze);let z=F(`$ZodError`,ze,void 0,{Parent:Error}),Be=(e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new I;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>k(e,o,R())));throw me(n,a?.callee??t),n}return s.value};return t})(z),Ve=(e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>k(e,o,R())));throw me(n,a?.callee??t),n}return s.value};return t})(z),He=(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 I;return a.issues.length?Ue(e,a.issues,i):{success:!0,data:a.value}})(z);function Ue(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>k(e,n,R()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}let We=(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?Ue(e,a.issues,i):{success:!0,data:a.value}})(z),Ge=/^[\\s\\S]{0,}$/,Ke=/^-?\\d+(?:\\.\\d+)?$/,qe=F(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Je=e=>{let t=e.value;return!de(t)&&t.length!==void 0},Ye=F(`$ZodCheckMinLength`,(e,t)=>{var n;qe.init(e,t),(n=e._zod.def).when??(n.when=Je),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?xe(r):i)>=t.minimum)return;let a=Se(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Xe=F(`$ZodCheckStringFormat`,(e,t)=>{var n,r;qe.init(e,t),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=()=>{})}),Ze=F(`$ZodCheckRegex`,(e,t)=>{Xe.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})}}),Qe={major:4,minor:6,patch:7},B=F(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Qe;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=T(t),a;for(let o of n){if(o._zod.def.when){if(ve(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new I;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(O(t.issues,n,e),i||=T(t,n))});else{if(t.issues.length===n)continue;O(t.issues,n,e),i||=T(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(T(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new I;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new I;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get\"~standard\"(){return Te(this,`~standard`,tt(this))},set\"~standard\"(e){A(this,`~standard`,e)}}),$e=(e,t)=>e.issues.length?{issues:e.issues.map(e=>k(e,t,R()))}:{value:e.value};async function et(e,t){let n={async:!0};return $e(await e._zod.run({value:t,issues:[]},n),n)}function tt(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return $e(r,n)}catch{}return et(e,t)},vendor:`zod`,version:1}}let nt=F(`$ZodString`,(e,t)=>{B.init(e,t),e._zod.pattern=t.pattern??Ge,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}}),rt=F(`$ZodNumber`,(e,t)=>{B.init(e,t),e._zod.pattern=Ke,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:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}});function it(e,t){let n=ye(e._zod.def.checks);if(!n.length)return;let r=Math.min(...n.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(n,a)=>{let o=t(n.value);if(o>r&&!a?.skipChecks&&a?.direction!==`backward`){for(let[t,r]of ye(e._zod.def.checks))if(o>t&&r._zod.def.when(n)){let t=n.issues.length;return r._zod.check(n),n.issues[t].continue=!1,O(n.issues,t,e),n}}return i(n,a)}}let at=e=>Array.isArray(e)?e.length:-1;function ot(e,t,n){e.issues.length&&t.issues.push(...E(n,e.issues)),t.value[n]=e.value}let st=F(`$ZodArray`,(e,t)=>{B.init(e,t);let n=L.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>ot(t,r,e)));else if(ot(c,r,e),s&&c.issues.length!==0&&T(c))break}return o.length?Promise.all(o).then(()=>r):r},it(e,at)});function V(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(!(!o&&s&&i===`optional`)){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...E(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}let ct=[];function lt(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:ct,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key \"${String(t)}\": expected a Zod schema`);let a=_e(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function ut(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(T(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>V(e,n,i,t,d,f))):V(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}let dt=F(`$ZodObject`,(e,t)=>{B.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,\"shape\",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,\"shape\",{get:e})}let i=ue(()=>lt(t));N(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||pe(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=C,o=t.catchall,s,c=L.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(T(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>V(n,t,e,r,a,o))):V(s,t,e,r,a,o)}return o?ut(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}});function ft(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=>!T(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=>k(e,r,R())))}),t)}let pt=F(`$ZodUnion`,(e,t)=>{B.init(e,t),N(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),N(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),N(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),N(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>fe(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=>ft(t,r,e,i)):ft(o,r,e,i)}}),mt=F(`$ZodRecord`,(e,t)=>{B.init(e,t);let n=L.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!he(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>k(e,i,R())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...E(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...E(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Ke.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>k(e,i,R())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...E(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...E(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),ht=F(`$ZodTransform`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,L.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ne(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));if(i instanceof Promise)throw new I;return n.value=i,n}});function gt(e,t){return e.value=t.issues.length?void 0:t.value,e}let _t=F(`$ZodOptional`,(e,t)=>{B.init(e,t),N(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,N(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),N(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${fe(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>gt(e,t)):gt(e,r)}return t.innerType._zod.run(e,n)}}),vt=F(`$ZodPipe`,(e,t)=>{B.init(e,t),N(e,`values`,e=>e.def.in._zod.values),N(e,`optin`,e=>e.def.in._zod.optin),N(e,`optout`,e=>e.def.out._zod.optout),N(e,`propValues`,e=>e.def.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=>H(e,t.in,n)):H(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>H(e,t.out,n)):H(r,t.out,n)}});function H(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}let yt=F(`$ZodCustom`,(e,t)=>{qe.init(e,t),B.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=>bt(t,n,r,e));bt(i,n,r,e)}});function bt(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(Ce(e))}}function xt(e){return e.checks&&=[...e.checks],e}function St(e,t){return new e(xt({type:`string`,...w(t)}))}function Ct(e,t){return new e(xt({type:`number`,checks:[],...w(t)}))}function U(e,t){return new Ye({check:`min_length`,...w(t),minimum:e})}function wt(e,t){return new Ze({check:`string_format`,format:`regex`,...w(t),pattern:e})}function Tt(e,t,n){let r=w(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}let W=F(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);B.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){A(this,`with`,e)},parse(e,t){return Be(this,e,t,{callee:this.parse})},parseAsync(e,t){return Ve(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return He(this,e,t)},safeParseAsync(e,t){return We(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0})},clone(e,t){return ge(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),Et=F(`ZodMiniString`,(e,t)=>{nt.init(e,t),W.init(e,t)});function G(e){return St(Et,e)}let Dt=F(`ZodMiniNumber`,(e,t)=>{rt.init(e,t),W.init(e,t)});function Ot(e){return Ct(Dt,e)}let kt=F(`ZodMiniArray`,(e,t)=>{st.init(e,t),W.init(e,t)});function At(e,t){return new kt({type:`array`,element:e,...w(t)})}let jt=F(`ZodMiniObject`,(e,t)=>{dt.init(e,t),W.init(e,t),ke(e,`shape`,e=>e._zod.def.shape,!1)});function K(e,t){let n={type:`object`,shape:e??{},...w(t)};return new jt(n)}let Mt=F(`ZodMiniUnion`,(e,t)=>{pt.init(e,t),W.init(e,t)});function Nt(e,t){return new Mt({type:`union`,options:e,...w(t)})}let Pt=F(`ZodMiniRecord`,(e,t)=>{mt.init(e,t),W.init(e,t)});function Ft(e,t,n){return!t||!t._zod?new Pt({type:`record`,keyType:G(),valueType:e,...w(t)}):new Pt({type:`record`,keyType:e,valueType:t,...w(n)})}let It=F(`ZodMiniTransform`,(e,t)=>{ht.init(e,t),W.init(e,t)});function Lt(e){return new It({type:`transform`,transform:e})}let Rt=F(`ZodMiniOptional`,(e,t)=>{_t.init(e,t),W.init(e,t)});function q(e){return new Rt({type:`optional`,innerType:e})}let zt=F(`ZodMiniPipe`,(e,t)=>{vt.init(e,t),W.init(e,t)});function Bt(e,t){return new zt({type:`pipe`,in:e,out:t})}let Vt=F(`ZodMiniCustom`,(e,t)=>{yt.init(e,t),W.init(e,t)});function Ht(e,t){return Tt(Vt,e??(()=>!0),t)}function Ut(){return G().check(wt(/^\\d+(\\.\\d+)?$/,`Invalid amount`))}function Wt(e){let{meta:t,opaque:n,request:r,...a}=e.challenge,o=n??(t===void 0?void 0:se(t)),s={challenge:{...a,...o!==void 0&&{opaque:o},request:se(r)},payload:e.payload,...e.source&&{source:e.source}},c=oe(JSON.stringify(s),{pad:!1,url:!0});return`${i.payment} ${c}`}function Gt(e){return e}function Kt(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}function qt(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 Jt=Nt([K({customer:q(G().check(U(1))),hooks:q(K({inputs:K({tax:K({calculation:G().check(U(1))})})})),metadata:q(Ft(G(),G())),receipt_email:q(G().check(U(1)))}),Ht(e=>typeof e==`function`)]),Yt=Gt({name:`stripe`,intent:`charge`,schema:{credential:{payload:K({externalId:q(G()),spt:G()})},request:Bt(K({amount:Ut(),currency:G(),decimals:Ot(),description:q(G()),externalId:q(G()),metadata:q(Ft(G(),G())),networkId:G(),paymentIntentOptions:q(Jt),paymentMethodTypes:At(G()).check(U(1)),recipient:q(G())}),Lt(({amount:e,decimals:t,metadata:n,networkId:r,paymentIntentOptions:i,paymentMethodTypes:a,...o})=>({...o,amount:qt(e,t).toString(),methodDetails:{networkId:r,paymentMethodTypes:a,...n!==void 0&&{metadata:n}}})))}});function Xt(e){let{client:t,createToken:n,externalId:r,paymentMethod:i}=e;return Kt(Yt,{context:K({paymentMethod:q(G())}),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 Wt({challenge:e,payload:{spt:p,...m===void 0?{}:{externalId:m}}})}})}function Zt(e){return[Xt(e)]}(function(e){e.charge=Xt})(Zt||={});var Qt=r();let J={data:`__MPPX_DATA__`,error:`root_error`,root:`root`},$t={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},Y={challengeId:`data-mppx-challenge-id`,remaining:`data-remaining`};var X=class{name;constructor(e){this.name=`--mppx-${e}`}toString(){return`var(${this.name})`}};let en={accent:new X(`accent`),background:new X(`background`),border:new X(`border`),foreground:new X(`foreground`),muted:new X(`muted`),negative:new X(`negative`),positive:new X(`positive`),surface:new X(`surface`),fontFamily:new X(`font-family`),fontSizeBase:new X(`font-size-base`),radius:new X(`radius`),spacingUnit:new X(`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: ${en.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 tn(e,t){if(t==null)return e;if(!Z(e)||!Z(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]=Z(t)&&Z(r)?tn(t,r):r}return n}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function nn(e,t=`Authorization`){let n=new URL(location.href);n.searchParams.set($t.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 rn(e){let t=document.getElementById(J.data),n=ee(t.textContent),r=t.getAttribute(Y.remaining);!r||Number(r)<=1?t.remove():t.setAttribute(Y.remaining,String(Number(r)-1));let i=document.currentScript,a=i?.getAttribute(Y.challengeId),o=a?(i.removeAttribute(Y.challengeId),n[a]):Object.values(n).find(t=>t.challenge.method===e);return{...o,error(e){if(!e){document.getElementById(J.error)?.remove();return}let t=document.getElementById(J.error);if(t){t.textContent=e;return}let n=document.createElement(`p`);n.id=J.error,n.className=`mppx-error`,n.role=`alert`,n.textContent=e,document.getElementById(o.rootId)?.after(n)},root:document.getElementById(o.rootId),submit:e=>nn(e,o.challenge.header),vars:en}}let Q=rn(`stripe`),$=Q.config.elements,an=String.raw,on=document.createElement(`style`);on.textContent=an`\n form {\n display: flex;\n flex-direction: column;\n gap: calc(${Q.vars.spacingUnit} * 8);\n }\n button {\n background: ${Q.vars.accent};\n border-radius: ${Q.vars.radius};\n color: ${Q.vars.background};\n cursor: pointer;\n font-weight: 500;\n padding: calc(${Q.vars.spacingUnit} * 4) calc(${Q.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`,Q.root.append(on),(async()=>{let e=await(0,Qt.loadStripe)(Q.config.publishableKey);if(!e)throw Error(`Failed to loadStripe`);let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{let e=(()=>{if($?.options?.appearance?.theme)return $?.options?.appearance?.theme;switch(Q.theme.colorScheme){case`light dark`:return t.matches?`night`:`stripe`;case`light`:return`stripe`;case`dark`:return`night`}})(),n=+!!t.matches;return tn({disableAnimations:!0,theme:e,variables:{borderRadius:Q.theme.radius,colorBackground:Q.theme.surface[n],colorDanger:Q.theme.negative[n],colorPrimary:Q.theme.accent[n],colorText:Q.theme.foreground[n],colorTextSecondary:Q.theme.muted[n],fontSizeBase:Q.theme.fontSizeBase,fontFamily:Q.theme.fontFamily,spacingUnit:Q.theme.spacingUnit}},$?.options?.appearance??{})},r=e.elements({appearance:n(),...$?.options,amount:Number(Q.challenge.request.amount),currency:Q.challenge.request.currency,mode:`payment`,paymentMethodCreation:`manual`,paymentMethodTypes:Q.challenge.request.methodDetails.paymentMethodTypes});t.addEventListener(`change`,()=>{r.update({appearance:n()})});let i=document.createElement(`form`);r.create(`payment`,$?.paymentOptions).mount(i),Q.root.appendChild(i);let a=document.createElement(`button`);a.textContent=Q.text.pay,a.type=`submit`,i.appendChild(a),i.onsubmit=async t=>{t.preventDefault(),Q.error(),a.disabled=!0;try{await r.submit();let{paymentMethod:t,error:n}=await e.createPaymentMethod({...$?.createPaymentMethodOptions,elements:r});if(n||!t)throw n??Error(`Failed to create payment method`);let i=await Zt({client:e,createToken:sn})[0].createCredential({challenge:Q.challenge,context:{paymentMethod:t.id}});await Q.submit(i)}catch(e){Q.error(e instanceof Error?e.message:`Payment failed`)}finally{a.disabled=!1}}})();async function sn(e){let t=new URL(Q.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>";
2
+ export 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.17.0`,startTime:t})},p=null,m=null,h=null,g=function(e){return function(t){e(Error(`Failed to load Stripe.js`,{cause:t}))}},ee=function(e,t){return function(){window.Stripe?e(window.Stripe):t(Error(`Stripe.js not available`))}},te=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=ee(t,n),m=g(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},_=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.17.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},ne=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)},v,y=!1,b=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];y=!0;var r=Date.now();return te(v).then(function(e){return _(e,t,r)})};b.setLoadParameters=function(e){if(y&&v){var t=ne(e);if(Object.keys(t).reduce(function(t,n){return t&&e[n]===v?.[n]},!0))return}if(y)throw Error(`You cannot change load parameters after calling loadStripe`);v=ne(e)},e.loadStripe=b})),r=t(((e,t)=>{t.exports=n()})),i,a=e((()=>{i={payment:`Payment`}})),o,s=e((()=>{o=`0.1.1`}));function c(){return o}var l=e((()=>{s()}));function u(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?u(e.cause,t):t?null:e}var d,f=e((()=>{l(),d=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 u(this,e)}},Object.defineProperty(d,\"defaultStaticOptions\",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${c()}`}}),d.setStaticOptions(d.defaultStaticOptions)}));function p(e,t){if(y(e)>t)throw new re({givenSize:y(e),maxSize:t})}function m(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new ie({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 h=e((()=>{ae()}));function g(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=>g(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)}:${g(r)}`),t},[]).join(`,`)}}`}function ee(e,t){return JSON.parse(e,(e,n)=>{let r=n;return typeof r==`string`&&r.endsWith(te)?BigInt(r.slice(0,-9)):typeof t==`function`?t(e,r):r})}var te,_=e((()=>{te=`#__bigint`}));function ne(e,t={}){let{size:n}=t,r=b.encode(e);return typeof n==`number`?(p(r,n),v(r,n)):r}function v(e,t){return m(e,{dir:`right`,size:t})}function y(e){return e.length}var b,re,ie,ae=e((()=>{f(),h(),_(),b=new TextEncoder,re=class extends d{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`})}},ie=class extends d{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`})}}}));function oe(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]=x[r>>18],i[t+1]=x[r>>12&63],i[t+2]=x[r>>6&63],i[t+3]=x[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=ce.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function se(e,t={}){return oe(ne(e),t)}var ce,x,le=e((()=>{ae(),ce=new TextDecoder,x=Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[t,e.charCodeAt(0)])),{...Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[e.charCodeAt(0),t]))}})),S=e((()=>{f(),ae(),h(),_(),l(),le(),S()}));function ue(e){return se(g(e),{pad:!1,url:!0})}var de=e((()=>{S()}));function fe(e,t){return typeof t==`bigint`?t.toString():t}function pe(e){return new Me(e)}function me(e){return e==null}function he(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function ge(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function _e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ve(e){if(_e(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return _e(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function ye(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function C(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 be(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}function w(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 xe(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 T(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function E(e){return typeof e==`string`?e:e?.message}function Se(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function Ce(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function D(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:E(e.inst?._zod.def?.error?.(e))??E(a?.(e))??E(t?.error?.(e))??E(n.customError?.(e))??E(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}function we(e){let t=e.length;if(!Pe.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function Te(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Ee(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function De(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):ke(e,n,r.value)}}function O(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Oe(e,t,n){return O(e,t,n,!1)}function ke(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:O(this,t,n.bind(this))},set(e){O(this,t,e)}})}function Ae(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}function k(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&Fe!==e._zod){Fe=void 0;return}Fe=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Ie);let e=A;A=!1;try{let r=n(this);return A?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),A||=e,r}catch(n){throw delete this[t],A||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function je(e,t,n,r){let i=Ae(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var Me,Ne,Pe,Fe,A,Ie,j=e((()=>{Me=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}},Ne=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{},Pe=/[\\uD800-\\uDBFF]/,A=!1,Ie={configurable:!0,get(){A=!0}}}));function Le(e){let t=ze;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return ze=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function M(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){P.value=new a(r);try{Object.defineProperty(n,\"_zod\",P)}finally{P.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),De(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,\"name\",{value:e});function d(e){let t=r?.Parent?Le(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,\"init\",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,\"name\",{value:e}),d}function N(e){return e&&Object.assign(I,e),I}var Re,P,ze,F,Be,I,L=e((()=>{j(),P={value:void 0,enumerable:!1},ze=`captureStackTrace`in Error?Error:null,F=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Be=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},(Re=globalThis).__zod_globalConfig??(Re.__zod_globalConfig={}),I=globalThis.__zod_globalConfig}));function Ve(){let e=this._zod;return e.message??=JSON.stringify(e.def,fe,2),e.message}function He(e){this._zod.message=e}var Ue,R,We,Ge,z,Ke=e((()=>{L(),j(),Ue={get:Ve,set:He,enumerable:!0,configurable:!0},R={value:void 0,enumerable:!1},We=new WeakSet([Object.prototype,Error.prototype]),Ge=(e,t)=>{e.name=`$ZodError`,R.value=t,Object.defineProperty(e,\"issues\",R),R.value=void 0,Object.defineProperty(e,\"message\",Ue);let n=Object.getPrototypeOf(e);We.has(n)||(We.add(n),Object.defineProperty(n,\"toString\",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,\"toString\",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,\"toString\",{value:e,configurable:!0,writable:!0})}}))},M(`$ZodError`,Ge),z=M(`$ZodError`,Ge,void 0,{Parent:Error})}));function qe(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>D(e,n,N()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}var Je,Ye,Xe,Ze,Qe,$e,et,tt,nt=e((()=>{L(),Ke(),j(),Je=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new F;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>D(e,o,N())));throw Ne(n,a?.callee??t),n}return s.value};return t},Ye=Je(z),Xe=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>D(e,o,N())));throw Ne(n,a?.callee??t),n}return s.value};return t},Ze=Xe(z),Qe=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 F;return a.issues.length?qe(e,a.issues,i):{success:!0,data:a.value}},$e=Qe(z),et=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?qe(e,a.issues,i):{success:!0,data:a.value}},tt=et(z)})),rt,it,at=e((()=>{rt=/^[\\s\\S]{0,}$/,it=/^-?\\d+(?:\\.\\d+)?$/})),B,ot,st,ct,lt,ut=e((()=>{L(),j(),B=M(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ot=e=>{let t=e.value;return!me(t)&&t.length!==void 0},st=M(`$ZodCheckMinLength`,(e,t)=>{var n;B.init(e,t),(n=e._zod.def).when??(n.when=ot),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?we(r):i)>=t.minimum)return;let a=Te(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ct=M(`$ZodCheckStringFormat`,(e,t)=>{var n,r;B.init(e,t),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=()=>{})}),lt=M(`$ZodCheckRegex`,(e,t)=>{ct.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})}})})),dt=e((()=>{})),ft,pt=e((()=>{ft={major:4,minor:6,patch:7}}));async function mt(e,t){let n={async:!0};return Ct(await e._zod.run({value:t,issues:[]},n),n)}function ht(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return Ct(r,n)}catch{}return mt(e,t)},vendor:`zod`,version:1}}function gt(e,t){let n=Se(e._zod.def.checks);if(!n.length)return;let r=Math.min(...n.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(n,a)=>{let o=t(n.value);if(o>r&&!a?.skipChecks&&a?.direction!==`backward`){for(let[t,r]of Se(e._zod.def.checks))if(o>t&&r._zod.def.when(n)){let t=n.issues.length;return r._zod.check(n),n.issues[t].continue=!1,Ce(n.issues,t,e),n}}return i(n,a)}}function _t(e,t,n){e.issues.length&&t.issues.push(...T(n,e.issues)),t.value[n]=e.value}function V(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(!(!o&&s&&i===`optional`)){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...T(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}function vt(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:Ot,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key \"${String(t)}\": expected a Zod schema`);let a=be(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function yt(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(w(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>V(e,n,i,t,d,f))):V(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}function bt(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=>!w(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=>D(e,r,N())))}),t)}function xt(e,t){return e.value=t.issues.length?void 0:t.value,e}function H(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}function St(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(Ee(e))}}var U,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It=e((()=>{ut(),L(),at(),j(),pt(),U=M(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ft;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=w(t),a;for(let o of n){if(o._zod.def.when){if(xe(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new F;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(Ce(t.issues,n,e),i||=w(t,n))});else{if(t.issues.length===n)continue;Ce(t.issues,n,e),i||=w(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(w(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new F;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new F;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get\"~standard\"(){return Oe(this,`~standard`,ht(this))},set\"~standard\"(e){O(this,`~standard`,e)}}),Ct=(e,t)=>e.issues.length?{issues:e.issues.map(e=>D(e,t,N()))}:{value:e.value},wt=M(`$ZodString`,(e,t)=>{U.init(e,t),e._zod.pattern=t.pattern??rt,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}}),Tt=M(`$ZodNumber`,(e,t)=>{U.init(e,t),e._zod.pattern=it,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:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Et=e=>Array.isArray(e)?e.length:-1,Dt=M(`$ZodArray`,(e,t)=>{U.init(e,t);let n=I.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>_t(t,r,e)));else if(_t(c,r,e),s&&c.issues.length!==0&&w(c))break}return o.length?Promise.all(o).then(()=>r):r},gt(e,Et)}),Ot=[],kt=M(`$ZodObject`,(e,t)=>{U.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,\"shape\",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,\"shape\",{get:e})}let i=pe(()=>vt(t));k(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||ge(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=_e,o=t.catchall,s,c=I.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(w(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>V(n,t,e,r,a,o))):V(s,t,e,r,a,o)}return o?yt(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),At=M(`$ZodUnion`,(e,t)=>{U.init(e,t),k(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),k(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),k(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>he(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=>bt(t,r,e,i)):bt(o,r,e,i)}}),jt=M(`$ZodRecord`,(e,t)=>{U.init(e,t);let n=I.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!ve(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>D(e,i,N())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...T(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...T(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&it.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>D(e,i,N())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...T(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...T(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),Mt=M(`$ZodTransform`,(e,t)=>{U.init(e,t),e._zod.optin=`optional`,I.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Be(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));if(i instanceof Promise)throw new F;return n.value=i,n}}),Nt=M(`$ZodOptional`,(e,t)=>{U.init(e,t),k(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,k(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),k(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${he(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>xt(e,t)):xt(e,r)}return t.innerType._zod.run(e,n)}}),Pt=M(`$ZodPipe`,(e,t)=>{U.init(e,t),k(e,`values`,e=>e.def.in._zod.values),k(e,`optin`,e=>e.def.in._zod.optin),k(e,`optout`,e=>e.def.out._zod.optout),k(e,`propValues`,e=>e.def.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=>H(e,t.in,n)):H(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>H(e,t.out,n)):H(r,t.out,n)}}),Ft=M(`$ZodCustom`,(e,t)=>{B.init(e,t),U.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=>St(t,n,r,e));St(i,n,r,e)}})})),Lt=e((()=>{})),Rt=e((()=>{globalThis.__zod_globalRegistry})),zt=e((()=>{}));function Bt(e){return e.checks&&=[...e.checks],e}function Vt(e,t){return new e(Bt({type:`string`,...C(t)}))}function Ht(e,t){return new e(Bt({type:`number`,checks:[],...C(t)}))}function W(e,t){return new st({check:`min_length`,...C(t),minimum:e})}function Ut(e,t){return new lt({check:`string_format`,format:`regex`,...C(t),pattern:e})}function Wt(e,t,n){let r=C(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}var Gt=e((()=>{ut(),j()})),Kt=e((()=>{})),G=e((()=>{L(),nt(),Ke(),It(),Lt(),ut(),pt(),j(),at(),Rt(),dt(),zt(),Gt(),Kt(),It(),Kt()})),qt=e((()=>{G()}));function K(e){return Vt(tn,e)}function Jt(e){return Ht(nn,e)}function Yt(e,t){return new rn({type:`array`,element:e,...C(t)})}function q(e,t){let n={type:`object`,shape:e??{},...C(t)};return new an(n)}function Xt(e,t){return new on({type:`union`,options:e,...C(t)})}function Zt(e,t,n){return!t||!t._zod?new sn({type:`record`,keyType:K(),valueType:e,...C(t)}):new sn({type:`record`,keyType:e,valueType:t,...C(n)})}function Qt(e){return new cn({type:`transform`,transform:e})}function J(e){return new ln({type:`optional`,innerType:e})}function $t(e,t){return new un({type:`pipe`,in:e,out:t})}function en(e,t){return Wt(dn,e??(()=>!0),t)}var Y,tn,nn,rn,an,on,sn,cn,ln,un,dn,fn=e((()=>{G(),j(),qt(),Y=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);U.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){O(this,`with`,e)},parse(e,t){return Ye(this,e,t,{callee:this.parse})},parseAsync(e,t){return Ze(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return $e(this,e,t)},safeParseAsync(e,t){return tt(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0})},clone(e,t){return ye(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),tn=M(`ZodMiniString`,(e,t)=>{wt.init(e,t),Y.init(e,t)}),nn=M(`ZodMiniNumber`,(e,t)=>{Tt.init(e,t),Y.init(e,t)}),rn=M(`ZodMiniArray`,(e,t)=>{Dt.init(e,t),Y.init(e,t)}),an=M(`ZodMiniObject`,(e,t)=>{kt.init(e,t),Y.init(e,t),je(e,`shape`,e=>e._zod.def.shape,!1)}),on=M(`ZodMiniUnion`,(e,t)=>{At.init(e,t),Y.init(e,t)}),sn=M(`ZodMiniRecord`,(e,t)=>{jt.init(e,t),Y.init(e,t)}),cn=M(`ZodMiniTransform`,(e,t)=>{Mt.init(e,t),Y.init(e,t)}),ln=M(`ZodMiniOptional`,(e,t)=>{Nt.init(e,t),Y.init(e,t)}),un=M(`ZodMiniPipe`,(e,t)=>{Pt.init(e,t),Y.init(e,t)}),dn=M(`ZodMiniCustom`,(e,t)=>{Ft.init(e,t),Y.init(e,t)})})),pn=e((()=>{G()})),mn=e((()=>{G(),qt(),fn(),pn(),It(),j(),fn(),at(),Kt()})),hn=e((()=>{mn()}));function gn(){return K().check(Ut(/^\\d+(\\.\\d+)?$/,`Invalid amount`))}var X=e((()=>{hn(),hn()}));function _n(e){let{meta:t,opaque:n,request:r,...a}=e.challenge,o=n??(t===void 0?void 0:ue(t)),s={challenge:{...a,...o!==void 0&&{opaque:o},request:ue(r)},payload:e.payload,...e.source&&{source:e.source}},c=se(JSON.stringify(s),{pad:!1,url:!0});return`${i.payment} ${c}`}var vn=e((()=>{S(),a(),de()}));function yn(e){return e}function bn(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}var xn=e((()=>{}));function Sn(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}var Cn=e((()=>{})),wn,Tn,En,Dn=e((()=>{X(),wn=q({customer:J(K().check(W(1))),hooks:J(q({inputs:q({tax:q({calculation:K().check(W(1))})})})),metadata:J(Zt(K(),K())),receipt_email:J(K().check(W(1)))}),Tn=en(e=>typeof e==`function`),En=Xt([wn,Tn])})),On,kn=e((()=>{xn(),X(),Cn(),Dn(),On=yn({name:`stripe`,intent:`charge`,schema:{credential:{payload:q({externalId:J(K()),spt:K()})},request:$t(q({amount:gn(),currency:K(),decimals:Jt(),description:J(K()),externalId:J(K()),metadata:J(Zt(K(),K())),networkId:K(),paymentIntentOptions:J(En),paymentMethodTypes:Yt(K()).check(W(1)),recipient:J(K())}),Qt(({amount:e,decimals:t,metadata:n,networkId:r,paymentIntentOptions:i,paymentMethodTypes:a,...o})=>({...o,amount:Sn(e,t).toString(),methodDetails:{networkId:r,paymentMethodTypes:a,...n!==void 0&&{metadata:n}}})))}})}));function An(e){let{client:t,createToken:n,externalId:r,paymentMethod:i}=e;return bn(On,{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 _n({challenge:e,payload:{spt:p,...m===void 0?{}:{externalId:m}}})}})}var jn=e((()=>{vn(),xn(),X(),kn()}));function Mn(e){return[An(e)]}var Nn=e((()=>{jn(),(function(e){e.charge=An})(Mn||={})})),Pn=e((()=>{jn(),Nn()})),Fn=e((()=>{ae(),f(),h(),_(),le(),l(),vn(),xn(),S(),X(),de(),Pn(),In(),a()})),In=e((()=>{a(),S(),de(),X(),vn(),Fn()})),Ln=r();In();let Rn={data:`__MPPX_DATA__`,error:`root_error`,root:`root`},zn={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},Bn={challengeId:`data-mppx-challenge-id`,remaining:`data-remaining`};var Z=class{name;constructor(e){this.name=`--mppx-${e}`}toString(){return`var(${this.name})`}};let Vn={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: ${Vn.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 Hn(e,t){if(t==null)return e;if(!Un(e)||!Un(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]=Un(t)&&Un(r)?Hn(t,r):r}return n}function Un(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Wn(e,t=`Authorization`){let n=new URL(location.href);n.searchParams.set(zn.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()}S();function Gn(e){let t=document.getElementById(Rn.data),n=ee(t.textContent),r=t.getAttribute(Bn.remaining);!r||Number(r)<=1?t.remove():t.setAttribute(Bn.remaining,String(Number(r)-1));let i=document.currentScript,a=i?.getAttribute(Bn.challengeId),o=a?(i.removeAttribute(Bn.challengeId),n[a]):Object.values(n).find(t=>t.challenge.method===e);return{...o,error(e){if(!e){document.getElementById(Rn.error)?.remove();return}let t=document.getElementById(Rn.error);if(t){t.textContent=e;return}let n=document.createElement(`p`);n.id=Rn.error,n.className=`mppx-error`,n.role=`alert`,n.textContent=e,document.getElementById(o.rootId)?.after(n)},root:document.getElementById(o.rootId),submit:e=>Wn(e,o.challenge.header),vars:Vn}}let Q=Gn(`stripe`),$=Q.config.elements,Kn=String.raw,qn=document.createElement(`style`);qn.textContent=Kn`\n form {\n display: flex;\n flex-direction: column;\n gap: calc(${Q.vars.spacingUnit} * 8);\n }\n button {\n background: ${Q.vars.accent};\n border-radius: ${Q.vars.radius};\n color: ${Q.vars.background};\n cursor: pointer;\n font-weight: 500;\n padding: calc(${Q.vars.spacingUnit} * 4) calc(${Q.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`,Q.root.append(qn),(async()=>{let e=await(0,Ln.loadStripe)(Q.config.publishableKey);if(!e)throw Error(`Failed to loadStripe`);let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{let e=(()=>{if($?.options?.appearance?.theme)return $?.options?.appearance?.theme;switch(Q.theme.colorScheme){case`light dark`:return t.matches?`night`:`stripe`;case`light`:return`stripe`;case`dark`:return`night`}})(),n=+!!t.matches;return Hn({disableAnimations:!0,theme:e,variables:{borderRadius:Q.theme.radius,colorBackground:Q.theme.surface[n],colorDanger:Q.theme.negative[n],colorPrimary:Q.theme.accent[n],colorText:Q.theme.foreground[n],colorTextSecondary:Q.theme.muted[n],fontSizeBase:Q.theme.fontSizeBase,fontFamily:Q.theme.fontFamily,spacingUnit:Q.theme.spacingUnit}},$?.options?.appearance??{})},r=e.elements({appearance:n(),...$?.options,amount:Number(Q.challenge.request.amount),currency:Q.challenge.request.currency,mode:`payment`,paymentMethodCreation:`manual`,paymentMethodTypes:Q.challenge.request.methodDetails.paymentMethodTypes});t.addEventListener(`change`,()=>{r.update({appearance:n()})});let i=document.createElement(`form`);r.create(`payment`,$?.paymentOptions).mount(i),Q.root.appendChild(i);let a=document.createElement(`button`);a.textContent=Q.text.pay,a.type=`submit`,i.appendChild(a),i.onsubmit=async t=>{t.preventDefault(),Q.error(),a.disabled=!0;try{await r.submit();let{paymentMethod:t,error:n}=await e.createPaymentMethod({...$?.createPaymentMethodOptions,elements:r});if(n||!t)throw n??Error(`Failed to create payment method`);let i=await Mn({client:e,createToken:Jn})[0].createCredential({challenge:Q.challenge,context:{paymentMethod:t.id}});await Q.submit(i)}catch(e){Q.error(e instanceof Error?e.message:`Payment failed`)}finally{a.disabled=!1}}})();async function Jn(e){let t=new URL(Q.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>";
3
3
  //# sourceMappingURL=html.gen.js.map
@@ -1,4 +1,5 @@
1
1
  import { type Address, type Client as viem_Client } from 'viem';
2
+ import * as Currency from '../../Currency.js';
2
3
  import * as Method from '../../Method.js';
3
4
  import * as Account from '../../viem/Account.js';
4
5
  import * as Client from '../../viem/Client.js';
@@ -262,20 +263,22 @@ export declare namespace charge {
262
263
  */
263
264
  expectedRecipients?: readonly Address[] | undefined;
264
265
  /**
265
- * Allowlist of TIP-20 currency addresses this client will pay in, compared
266
- * case-insensitively. Offers in other currencies are skipped during selection
267
- * and rejected before signing; an empty list rejects all. Required with
268
- * `maxAmount` or `maxAtomicAmount`, which are denominated in the challenge currency.
266
+ * Allowlist of currencies this client will pay in: TIP-20 addresses, compared
267
+ * case-insensitively, or `viem/tokens` tokens, matched on the challenge's chain.
268
+ * Offers in other currencies are skipped during selection and rejected before
269
+ * signing; an empty list rejects all. Required with `maxAmount` or
270
+ * `maxAtomicAmount`, which are denominated in the challenge currency.
269
271
  */
270
- currencies?: readonly Address[] | undefined;
272
+ currencies?: readonly Currency.Currency[] | undefined;
271
273
  /**
272
- * Decimals of the `currencies`, used to parse `maxAmount`. Required with
273
- * `maxAmount` because challenges do not carry currency decimals.
274
+ * Decimals of address `currencies`, used to parse `maxAmount`. Tokens carry their
275
+ * own. Required with `maxAmount` for addresses, because challenges do not carry
276
+ * currency decimals.
274
277
  */
275
278
  decimals?: number | undefined;
276
279
  /**
277
280
  * Maximum display-unit amount (e.g. `'1.5'`) the client is willing to pay per
278
- * charge, parsed with `decimals`. Values with more fractional digits than
281
+ * charge, parsed with the matched currency's decimals. Values with more fractional digits than
279
282
  * `decimals` are rejected rather than rounded. Compared against the challenge
280
283
  * amount, which includes splits; larger offers are skipped during selection and
281
284
  * rejected before signing. Applies per credential, not cumulatively across
@@ -1,10 +1,11 @@
1
1
  import { TxEnvelopeTempo } from 'ox/tempo';
2
2
  import { keccak256, parseEventLogs, parseUnits, } from 'viem';
3
- import { prepareTransactionRequest, sendCallsSync, sendRawTransactionSync, sendTransactionSync, signTypedData, signTransaction, waitForTransactionReceipt, } from 'viem/actions';
3
+ import { prepareTransactionRequest, readContract, sendCallsSync, sendRawTransactionSync, sendTransactionSync, signTypedData, signTransaction, waitForTransactionReceipt, } from 'viem/actions';
4
4
  import { Abis, Actions, Addresses } from 'viem/tempo';
5
5
  import { tempo as tempo_chain } from 'viem/tempo/chains';
6
6
  import * as MethodResponse from '../../client/internal/MethodResponse.js';
7
7
  import * as Credential from '../../Credential.js';
8
+ import * as Currency from '../../Currency.js';
8
9
  import * as Errors from '../../Errors.js';
9
10
  import * as Method from '../../Method.js';
10
11
  import * as Account from '../../viem/Account.js';
@@ -55,8 +56,11 @@ export function charge(parameters = {}) {
55
56
  if ((parameters.maxAmount !== undefined || parameters.maxAtomicAmount !== undefined) &&
56
57
  parameters.currencies === undefined)
57
58
  throw new Error('Tempo charge maxAmount and maxAtomicAmount require currencies.');
59
+ // Fail at construction for any accepted currency whose decimals cannot parse `maxAmount`.
60
+ for (const currency of parameters.currencies ?? [])
61
+ parseMaxAmount(parameters.maxAmount, typeof currency === 'string' ? parameters.decimals : currency.decimals);
58
62
  const caps = {
59
- maxAmount: parseMaxAmount(parameters.maxAmount, parameters.decimals),
63
+ maxAmount: parameters.maxAmount,
60
64
  maxAtomicAmount: parameters.maxAtomicAmount === undefined ? undefined : BigInt(parameters.maxAtomicAmount),
61
65
  };
62
66
  const getClient = Client.getResolver({
@@ -93,6 +97,9 @@ export function charge(parameters = {}) {
93
97
  Client.assertAllowedChainId(parameters.allowedChainIds, chainId);
94
98
  if (chainId === undefined)
95
99
  throw new Error('No `chainId` provided. Pass a chain ID in the challenge or client.');
100
+ // A challenge without a chain ID was checked without one: check its currency on this chain.
101
+ if (challengeChainId === undefined)
102
+ assertChallengePolicy(parameters, caps, challenge.request, chainId);
96
103
  const { request } = challenge;
97
104
  const { amount, methodDetails } = request;
98
105
  const supportedModes = methodDetails?.supportedModes ?? ['pull', 'push'];
@@ -180,6 +187,8 @@ export function charge(parameters = {}) {
180
187
  : undefined;
181
188
  let account = defaultAccount;
182
189
  let machineTokenRoute;
190
+ // Whether the account could run the MACH route but lacked the MACH or the route reverted.
191
+ let machineTokenUnpayable = false;
183
192
  if (machineTokenCandidate) {
184
193
  const machineTokenAccount = await (async () => {
185
194
  try {
@@ -203,6 +212,8 @@ export function charge(parameters = {}) {
203
212
  });
204
213
  if (machineTokenRoute)
205
214
  account = machineTokenAccount;
215
+ else
216
+ machineTokenUnpayable = true;
206
217
  }
207
218
  }
208
219
  let swapCalls;
@@ -221,6 +232,17 @@ export function charge(parameters = {}) {
221
232
  maxAmountIn: autoSwap.maxAmountIn,
222
233
  })
223
234
  : undefined;
235
+ // Without MACH or the charge currency the payment can only revert, so say where to buy MACH.
236
+ if (machineTokenUnpayable && !autoSwap) {
237
+ const error = await getMachineTokenFundingError(client, {
238
+ account: account.address,
239
+ amount: BigInt(amount),
240
+ chainId,
241
+ currency,
242
+ });
243
+ if (error)
244
+ throw error;
245
+ }
224
246
  }
225
247
  const calls = machineTokenRoute?.calls ?? [...(swapCalls ?? []), ...transferCalls];
226
248
  const allowedFeeTokens = defaultFeeTokens(chainId);
@@ -346,6 +368,17 @@ export function charge(parameters = {}) {
346
368
  };
347
369
  return MethodResponse.registerTransactionHash({ ...method, createCredential }, transactionHash);
348
370
  }
371
+ /**
372
+ * Returns an error that links to the MACH onramp when a machine-token-enabled charge can't be paid:
373
+ * the account holds less than `amount` of both the charge currency and MACH.
374
+ */
375
+ async function getMachineTokenFundingError(client, parameters) {
376
+ const { account, amount, chainId, currency } = parameters;
377
+ const balance = await readContract(client, Actions.token.getBalance.call(client, { account, token: currency })).catch(() => undefined);
378
+ if (typeof balance !== 'bigint' || balance >= amount)
379
+ return undefined;
380
+ return MachineTokenCharge.getInsufficientBalanceError(client, { account, amount, chainId });
381
+ }
349
382
  /**
350
383
  * Returns the final transaction hash of a credential, when known before settlement.
351
384
  *
@@ -551,7 +584,9 @@ function parseMaxAmount(maxAmount, decimals) {
551
584
  * Rejects a challenge whose chain, currency, recipients, or amount violate the client policy.
552
585
  * Runs during challenge selection and again before any client, account, or signing work.
553
586
  */
554
- function assertChallengePolicy(parameters, caps, request) {
587
+ function assertChallengePolicy(parameters, caps, request,
588
+ /** Chain the client signs on, once resolved, for a challenge that names none. */
589
+ signingChainId) {
555
590
  const { amount, methodDetails, recipient } = request;
556
591
  // Chain pinning: reject a challenge whose chain ID conflicts with the pinned one.
557
592
  const challengeChainId = methodDetails?.chainId;
@@ -561,8 +596,19 @@ function assertChallengePolicy(parameters, caps, request) {
561
596
  throw new Error(`Chain ID mismatch: expected ${parameters.expectedChainId}, got ${challengeChainId}.`);
562
597
  if (challengeChainId !== undefined || parameters.allowedChainIds?.length === 0)
563
598
  Client.assertAllowedChainId(parameters.allowedChainIds, challengeChainId);
564
- if (parameters.currencies &&
565
- !parameters.currencies.some((c) => c.toLowerCase() === request.currency.toLowerCase()))
599
+ // Tokens match on the chain the client signs on: the challenge's, else the pinned or resolved
600
+ // one. Only selection, before a client is resolved, may match a token on any chain it lists,
601
+ // and `createCredential` checks the currency again on the resolved chain before signing.
602
+ const currency = parameters.currencies
603
+ ? Currency.find(parameters.currencies, request.currency, {
604
+ chainId: challengeChainId ??
605
+ signingChainId ??
606
+ parameters.expectedChainId ??
607
+ (parameters.allowedChainIds?.length === 1 ? parameters.allowedChainIds[0] : undefined),
608
+ decimals: parameters.decimals,
609
+ })
610
+ : undefined;
611
+ if (parameters.currencies && !currency)
566
612
  throw new Error(`Tempo charge currency is not allowed: ${request.currency}.`);
567
613
  if (parameters.expectedRecipients) {
568
614
  const allowed = new Set(parameters.expectedRecipients.map((a) => a.toLowerCase()));
@@ -578,7 +624,8 @@ function assertChallengePolicy(parameters, caps, request) {
578
624
  }
579
625
  if (caps.maxAtomicAmount !== undefined && BigInt(amount) > caps.maxAtomicAmount)
580
626
  throw new Error('Tempo charge amount exceeds maxAtomicAmount.');
581
- if (caps.maxAmount !== undefined && BigInt(amount) > caps.maxAmount)
627
+ if (caps.maxAmount !== undefined &&
628
+ BigInt(amount) > parseMaxAmount(caps.maxAmount, currency?.decimals))
582
629
  throw new Error('Tempo charge amount exceeds maxAmount.');
583
630
  }
584
631
  //# sourceMappingURL=Charge.js.map
@@ -6,4 +6,8 @@ export * as SessionLegacy from './legacy/index.js';
6
6
  export * as Subscription from './subscription/index.js';
7
7
  /** Canonical first-party machine-token deployments by Tempo chain ID. */
8
8
  export { machineToken as machineTokenDeployments } from './internal/defaults.js';
9
+ /** Tempo Wallet page that buys MACH on Tempo mainnet. */
10
+ export { machineTokenFundingBaseUrl } from './internal/defaults.js';
11
+ /** Builds the Tempo Wallet link that buys MACH, prefilled with a payer and amount. */
12
+ export { fundingUrl as machineTokenFundingUrl } from './internal/machine-token-charge.js';
9
13
  //# sourceMappingURL=index.d.ts.map
@@ -6,4 +6,8 @@ export * as SessionLegacy from './legacy/index.js';
6
6
  export * as Subscription from './subscription/index.js';
7
7
  /** Canonical first-party machine-token deployments by Tempo chain ID. */
8
8
  export { machineToken as machineTokenDeployments } from './internal/defaults.js';
9
+ /** Tempo Wallet page that buys MACH on Tempo mainnet. */
10
+ export { machineTokenFundingBaseUrl } from './internal/defaults.js';
11
+ /** Builds the Tempo Wallet link that buys MACH, prefilled with a payer and amount. */
12
+ export { fundingUrl as machineTokenFundingUrl } from './internal/machine-token-charge.js';
9
13
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,5 @@
1
1
  import type { Address, Client } from 'viem';
2
+ import * as Currency from '../../Currency.js';
2
3
  /** Default fallback currencies for auto-swap, in priority order. */
3
4
  export declare const defaultCurrencies: readonly Address[];
4
5
  /**
@@ -15,8 +16,8 @@ export declare namespace findCalls {
15
16
  account: Address;
16
17
  /** Amount of the target token needed. */
17
18
  amountOut: bigint;
18
- /** Candidate input tokens to swap from, in priority order. */
19
- tokenIn: readonly Address[];
19
+ /** Candidate input tokens to swap from, in priority order, resolved on the client's chain. */
20
+ tokenIn: readonly Currency.Currency[];
20
21
  /** Maximum input-token units to spend. Defaults to the missing output amount plus slippage (1:1 units). */
21
22
  maxAmountIn?: bigint | undefined;
22
23
  /** Max slippage tolerance as a percentage (e.g. `1` = 1%). */
@@ -33,8 +34,8 @@ export declare namespace resolve {
33
34
  type Options = {
34
35
  /** Maximum input-token units per swap. Defaults to parity with the missing output amount plus slippage; set explicitly for non-parity pairs. */
35
36
  maxAmountIn?: bigint | undefined;
36
- /** Fallback tokens to try swapping from, in priority order. */
37
- tokenIn?: Address[] | undefined;
37
+ /** Fallback tokens to try swapping from, in priority order: addresses or `viem/tokens` tokens. */
38
+ tokenIn?: readonly Currency.Currency[] | undefined;
38
39
  /**
39
40
  * Whether to also try the default currencies after `tokenIn`. Set `false` to swap only from
40
41
  * `tokenIn`, as an allowlist. Ignored without `tokenIn`. @default true
@@ -45,7 +46,7 @@ export declare namespace resolve {
45
46
  };
46
47
  type Value = boolean | Options;
47
48
  type Resolved = {
48
- tokenIn: readonly Address[];
49
+ tokenIn: readonly Currency.Currency[];
49
50
  slippage: number;
50
51
  maxAmountIn?: bigint | undefined;
51
52
  };
@@ -1,5 +1,6 @@
1
1
  import { readContract } from 'viem/actions';
2
2
  import { Actions, Addresses } from 'viem/tempo';
3
+ import * as Currency from '../../Currency.js';
3
4
  import * as TempoAddress from './address.js';
4
5
  import * as defaults from './defaults.js';
5
6
  /** Basis-point denominator (100% = 10 000 bps). */
@@ -23,7 +24,21 @@ export async function findCalls(client, parameters) {
23
24
  throw new Error('Auto-swap slippage must be between 0 and 50 percent.');
24
25
  if (parameters.maxAmountIn !== undefined && parameters.maxAmountIn <= 0n)
25
26
  throw new Error('Auto-swap maxAmountIn must be positive.');
26
- const candidates = tokenIn.filter((t) => !TempoAddress.isEqual(t, tokenOut));
27
+ // Tokens resolve on the client's chain; ones without an address there are skipped.
28
+ const chainId = client.chain?.id;
29
+ const candidates = [];
30
+ for (const currency of tokenIn) {
31
+ const address = typeof currency === 'string'
32
+ ? currency
33
+ : chainId === undefined
34
+ ? undefined
35
+ : Currency.resolve(currency, { chainId })?.address;
36
+ if (!address || TempoAddress.isEqual(address, tokenOut))
37
+ continue;
38
+ if (candidates.some((candidate) => TempoAddress.isEqual(candidate, address)))
39
+ continue;
40
+ candidates.push(address);
41
+ }
27
42
  // Reads never carry the client's account: a node refuses every call from an access key whose
28
43
  // authorization is not yet published, which would hide every route from a new key.
29
44
  const balanceResults = await Promise.allSettled([
@@ -98,7 +113,7 @@ export function resolve(value, defaultCurrencies) {
98
113
  ...value.tokenIn,
99
114
  ...(value.fallback === false
100
115
  ? []
101
- : defaultCurrencies.filter((d) => !value.tokenIn.some((c) => TempoAddress.isEqual(c, d)))),
116
+ : defaultCurrencies.filter((d) => !value.tokenIn.some((c) => typeof c === 'string' && TempoAddress.isEqual(c, d)))),
102
117
  ]
103
118
  : defaultCurrencies;
104
119
  return {
@@ -1,11 +1,12 @@
1
- import type { Token } from 'viem/tokens';
2
- /** An explicit token address or a chain-indexed token definition. */
3
- export type Currency = string | Token;
1
+ import * as Currency_ from '../../Currency.js';
2
+ /** An accepted Tempo currency: an address or a `viem/tokens` token, chain-indexed or resolved. */
3
+ export type Currency = Currency_.Currency;
4
4
  /** Resolves ordered USD offers without expanding acceptance from a live registry. */
5
5
  export declare function resolve(parameters: {
6
6
  chainId?: number | undefined;
7
7
  testnet?: boolean | undefined;
8
- currencies?: readonly Currency[] | undefined;
8
+ /** Accepted currencies. A plain string is a token address (the deprecated `currency` option). */
9
+ currencies?: readonly (Currency | (string & {}))[] | undefined;
9
10
  decimals?: number | undefined;
10
11
  }): [({
11
12
  currency: string;
@@ -1,4 +1,5 @@
1
1
  import { isAddress } from 'viem';
2
+ import * as Currency_ from '../../Currency.js';
2
3
  import * as defaults from './defaults.js';
3
4
  /** Resolves ordered USD offers without expanding acceptance from a live registry. */
4
5
  export function resolve(parameters) {
@@ -7,8 +8,7 @@ export function resolve(parameters) {
7
8
  (chainId === defaults.chainId.mainnet
8
9
  ? [defaults.tokens.ousd, defaults.tokens.usdc]
9
10
  : chainId === defaults.chainId.testnet
10
- ? // TODO: Use viem's chain-specific OUSD definition once it includes Moderato (42431).
11
- [defaults.tokens.ousd, defaults.tokens.pathUsd]
11
+ ? [defaults.tokens.ousd, defaults.tokens.pathUsd]
12
12
  : [defaults.resolveCurrency({ chainId })]);
13
13
  const seen = new Set();
14
14
  const resolved = [];
@@ -16,23 +16,27 @@ export function resolve(parameters) {
16
16
  // A shared USD price cannot also price EUR, BTC, or unknown denominations.
17
17
  if (typeof token !== 'string' && token.currency !== 'USD')
18
18
  continue;
19
- const currency = typeof token === 'string' ? token : token.addresses[chainId];
19
+ const currency = Currency_.resolve(token, {
20
+ chainId,
21
+ decimals: parameters.decimals ?? defaults.decimals,
22
+ });
23
+ // Tokens not on this chain are skipped before their decimals are compared.
20
24
  if (currency === undefined)
21
25
  continue;
22
- if (!isAddress(currency, { strict: false }))
23
- throw new Error(`Invalid Tempo currency address: ${currency}.`);
24
- const decimals = typeof token === 'string' ? (parameters.decimals ?? defaults.decimals) : token.decimals;
25
26
  if (typeof token !== 'string' &&
26
27
  parameters.decimals !== undefined &&
27
- parameters.decimals !== decimals)
28
+ parameters.decimals !== token.decimals)
28
29
  throw new Error('Configured `decimals` must match each token definition.');
30
+ if (!isAddress(currency.address, { strict: false }))
31
+ throw new Error(`Invalid Tempo currency address: ${currency.address}.`);
32
+ const decimals = currency.decimals ?? defaults.decimals;
29
33
  if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255)
30
34
  throw new Error('Token decimals must be an integer between 0 and 255.');
31
- const key = currency.toLowerCase();
35
+ const key = currency.address.toLowerCase();
32
36
  if (seen.has(key))
33
37
  continue;
34
38
  seen.add(key);
35
- resolved.push({ currency, decimals, chainId });
39
+ resolved.push({ currency: currency.address, decimals, chainId });
36
40
  }
37
41
  if (resolved.length === 0)
38
42
  throw new Error(`No accepted USD currencies for chain ${chainId}.`);
@@ -29,6 +29,13 @@ export declare const machineToken: Readonly<{
29
29
  token: "0x20c000000000000000000000f37de3740ADec032";
30
30
  }>;
31
31
  }>;
32
+ /**
33
+ * Tempo Wallet page that buys MACH on Tempo mainnet, the only chain it sells MACH on.
34
+ *
35
+ * Add `address` (the payer) and `amount` (USD, at most two decimals) query parameters to
36
+ * prefill it, or build the link with `machineTokenFundingUrl`.
37
+ */
38
+ export declare const machineTokenFundingBaseUrl = "https://wallet.tempo.xyz/agent?action=fund&intent=mach&chainId=4217";
32
39
  /**
33
40
  * Default token decimals for TIP-20 stablecoins (e.g. pathUSD, USDC).
34
41
  *
@@ -29,6 +29,13 @@ export const machineToken = Object.freeze({
29
29
  token: '0x20c000000000000000000000f37de3740ADec032',
30
30
  }),
31
31
  });
32
+ /**
33
+ * Tempo Wallet page that buys MACH on Tempo mainnet, the only chain it sells MACH on.
34
+ *
35
+ * Add `address` (the payer) and `amount` (USD, at most two decimals) query parameters to
36
+ * prefill it, or build the link with `machineTokenFundingUrl`.
37
+ */
38
+ export const machineTokenFundingBaseUrl = 'https://wallet.tempo.xyz/agent?action=fund&intent=mach&chainId=4217';
32
39
  /**
33
40
  * Default token decimals for TIP-20 stablecoins (e.g. pathUSD, USDC).
34
41
  *
@@ -341,11 +341,17 @@ export async function preflightSponsorship(parameters) {
341
341
  return { feePayerSignature: completed.feePayerSignature, transaction: completed.transaction };
342
342
  // The signature binds the gas limit, so a local fee payer signs a simulation-only copy
343
343
  // with headroom for the node's sponsored `eth_call` overhead. The broadcast keeps its gas.
344
- const padded = gas === undefined
344
+ // The node's `eth_call` recovers the fee payer of an expiring-nonce transaction as if its
345
+ // `nonce` were 0, so the copy zeroes the random discriminator. The broadcast keeps its nonce.
346
+ const expiring = completed.transaction.nonceKey === maxUint256;
347
+ const padded = gas === undefined && !expiring
345
348
  ? completed.transaction
346
349
  : {
347
350
  ...completed.transaction,
348
- gas: sponsoredSimulationGas(completed.transaction, policy),
351
+ ...(gas !== undefined
352
+ ? { gas: sponsoredSimulationGas(completed.transaction, policy) }
353
+ : {}),
354
+ ...(expiring ? { nonce: 0 } : {}),
349
355
  };
350
356
  const feePayerSignature = await signFeePayerSimulation(padded);
351
357
  return feePayerSignature