mppx 0.21.4 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/BodyDigest.d.ts +3 -3
- package/dist/BodyDigest.js +5 -3
- package/dist/Challenge.js +12 -2
- package/dist/Credential.js +9 -1
- package/dist/Errors.d.ts +62 -8
- package/dist/Errors.js +57 -6
- package/dist/Store.d.ts +7 -4
- package/dist/Store.js +18 -8
- package/dist/cli/cli.js +135 -135
- package/dist/cli/internal.js +1 -1
- package/dist/cli/plugins/index.js +12 -12
- package/dist/client/Budget.d.ts +49 -0
- package/dist/client/Budget.js +101 -0
- package/dist/client/Mppx.d.ts +8 -3
- package/dist/client/Mppx.js +55 -13
- package/dist/client/Spend.d.ts +134 -0
- package/dist/client/Spend.js +58 -0
- package/dist/client/core.d.ts +2 -0
- package/dist/client/core.js +2 -0
- package/dist/client/internal/Fetch.d.ts +23 -3
- package/dist/client/internal/Fetch.js +155 -37
- package/dist/client/internal/FundsMoved.d.ts +9 -0
- package/dist/client/internal/FundsMoved.js +18 -0
- package/dist/client/internal/SpendGate.d.ts +136 -0
- package/dist/client/internal/SpendGate.js +608 -0
- package/dist/client/internal/SpendHooks.d.ts +42 -0
- package/dist/client/internal/SpendHooks.js +36 -0
- package/dist/client/internal/protocols/Mcp.d.ts +9 -0
- package/dist/client/internal/protocols/Mcp.js +27 -0
- package/dist/client/internal/protocols/Mpp.js +20 -3
- package/dist/client/internal/protocols/Shared.js +29 -3
- package/dist/evm/client/Charge.js +20 -8
- package/dist/extensions/identity/erc8004/server/index.d.ts +7 -1
- package/dist/extensions/identity/erc8004/server/index.js +13 -1
- package/dist/extensions/identity/link/client/index.js +57 -5
- package/dist/identity/Client.d.ts +7 -3
- package/dist/identity/Client.js +178 -13
- package/dist/identity/Types.d.ts +2 -1
- package/dist/integrations/x402/Negotiator.js +4 -1
- package/dist/integrations/x402/Solana.d.ts +75 -0
- package/dist/integrations/x402/Solana.js +143 -0
- package/dist/internal/challengeMeta.d.ts +17 -2
- package/dist/internal/challengeMeta.js +35 -7
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/mcp/client/McpClient.d.ts +6 -1
- package/dist/mcp/client/McpClient.js +48 -10
- package/dist/server/Mppx.d.ts +12 -1
- package/dist/server/Mppx.js +58 -6
- package/dist/server/Transport.js +46 -2
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/client/Charge.js +81 -17
- package/dist/tempo/server/Charge.d.ts +7 -1
- package/dist/tempo/server/Charge.js +98 -12
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/SessionManager.js +3 -0
- package/dist/x402/server/EvmCharge.js +3 -0
- package/package.json +1 -1
package/dist/server/Transport.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Challenge from '../Challenge.js';
|
|
2
2
|
import * as Constants from '../Constants.js';
|
|
3
3
|
import * as Credential from '../Credential.js';
|
|
4
|
+
import * as Errors from '../Errors.js';
|
|
4
5
|
import * as Html from '../internal/html/config.js';
|
|
5
6
|
import { serviceWorker } from '../internal/html/serviceWorker.gen.js';
|
|
6
7
|
import * as McpCredential from '../internal/McpCredential.js';
|
|
@@ -49,7 +50,20 @@ export function http(options = {}) {
|
|
|
49
50
|
};
|
|
50
51
|
},
|
|
51
52
|
getCredential(request) {
|
|
53
|
+
// A Payment credential in a field the Challenge didn't select is ignored, but more than
|
|
54
|
+
// one Payment credential across both fields is a bad request.
|
|
55
|
+
// Oversized fields are rejected (selected) or ignored (unselected) before any parsing.
|
|
52
56
|
const header = request.headers.get(credentialHeader);
|
|
57
|
+
if (header && header.length > maxCredentialHeaderLength)
|
|
58
|
+
throw new Credential.InvalidCredentialEncodingError();
|
|
59
|
+
const count = [Constants.Headers.authorization, Constants.Headers.paymentAuthorization]
|
|
60
|
+
.map((name) => request.headers.get(name))
|
|
61
|
+
.reduce((total, value) => total +
|
|
62
|
+
(value && value.length <= maxCredentialHeaderLength
|
|
63
|
+
? countPaymentCredentials(value)
|
|
64
|
+
: 0), 0);
|
|
65
|
+
if (count > 1)
|
|
66
|
+
throw new Errors.MultipleCredentialsError();
|
|
53
67
|
if (!header)
|
|
54
68
|
return null;
|
|
55
69
|
const payment = Credential.extractPaymentScheme(header);
|
|
@@ -60,8 +74,9 @@ export function http(options = {}) {
|
|
|
60
74
|
async respondChallenge(options) {
|
|
61
75
|
const { challenge, error, input } = options;
|
|
62
76
|
// A 403 means the payment was valid but cannot pay for this request.
|
|
63
|
-
// Omit the challenge so clients do not pay again.
|
|
64
|
-
|
|
77
|
+
// Omit the challenge so clients do not pay again. A request with more than
|
|
78
|
+
// one Payment credential gets 400 and no challenge too.
|
|
79
|
+
if (error?.status === 403 || error instanceof Errors.MultipleCredentialsError)
|
|
65
80
|
return new Response(JSON.stringify(error.toProblemDetails()), {
|
|
66
81
|
status: error.status,
|
|
67
82
|
headers: {
|
|
@@ -125,6 +140,35 @@ export function http(options = {}) {
|
|
|
125
140
|
},
|
|
126
141
|
});
|
|
127
142
|
}
|
|
143
|
+
/** Longest credential field value accepted (65536 octets); longer ones are malformed credentials. */
|
|
144
|
+
const maxCredentialHeaderLength = 64 * 1024;
|
|
145
|
+
/**
|
|
146
|
+
* Counts the Payment credentials (`Payment <token>`) in a comma-joined credential field value.
|
|
147
|
+
* Commas inside quoted strings (another scheme's auth-params) don't separate credentials.
|
|
148
|
+
*/
|
|
149
|
+
function countPaymentCredentials(value) {
|
|
150
|
+
let count = 0;
|
|
151
|
+
let start = 0;
|
|
152
|
+
let quoted = false;
|
|
153
|
+
for (let i = 0; i <= value.length; i++) {
|
|
154
|
+
const char = value[i];
|
|
155
|
+
if (quoted) {
|
|
156
|
+
if (char === '\\')
|
|
157
|
+
i++;
|
|
158
|
+
else if (char === '"')
|
|
159
|
+
quoted = false;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (char === '"')
|
|
163
|
+
quoted = true;
|
|
164
|
+
else if (char === ',' || i === value.length) {
|
|
165
|
+
if (/^\s*Payment\s+\S/i.test(value.slice(start, i)))
|
|
166
|
+
count++;
|
|
167
|
+
start = i + 1;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return count;
|
|
171
|
+
}
|
|
128
172
|
function withPrivateCacheControl(value) {
|
|
129
173
|
if (!value)
|
|
130
174
|
return 'private';
|
|
@@ -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,ne=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)})};ne.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=ne})),r=t(((e,t)=>{t.exports=n()})),i,a=e((()=>{i={payment:`Payment`}})),o,s=e((()=>{o=class extends Error{name=`LegacyUnicodeEscapedChallengeError`;constructor(){super(`Legacy unicode-escaped challenge: the server escaped a bound parameter as \\\\uXXXX; upgrade the server.`)}}})),c,l=e((()=>{c=`0.1.1`}));function u(){return c}var d=e((()=>{l()}));function f(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?f(e.cause,t):t?null:e}var p,m=e((()=>{d(),p=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 f(this,e)}},Object.defineProperty(p,\"defaultStaticOptions\",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${u()}`}}),p.setStaticOptions(p.defaultStaticOptions)}));function h(e,t){if(re(e)>t)throw new ae({givenSize:re(e),maxSize:t})}function ee(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new oe({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 g=e((()=>{x()}));function _(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=>_(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)}:${_(r)}`),t},[]).join(`,`)}}`}function te(e,t){return JSON.parse(e,(e,n)=>{let r=n;return typeof r==`string`&&r.endsWith(v)?BigInt(r.slice(0,-9)):typeof t==`function`?t(e,r):r})}var v,y=e((()=>{v=`#__bigint`}));function b(e,t={}){let{size:n}=t,r=ie.encode(e);return typeof n==`number`?(h(r,n),ne(r,n)):r}function ne(e,t){return ee(e,{dir:`right`,size:t})}function re(e){return e.length}var ie,ae,oe,x=e((()=>{m(),g(),y(),ie=new TextEncoder,ae=class extends p{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`})}},oe=class extends p{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 se(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=le.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function ce(e,t={}){return se(b(e),t)}var le,S,ue=e((()=>{x(),le=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]))}})),C=e((()=>{m(),x(),g(),y(),d(),ue(),C()}));function de(e){return ce(_(e),{pad:!1,url:!0})}var fe=e((()=>{C()}));function pe(e,t){return typeof t==`bigint`?t.toString():t}function me(e){return new Ne(e)}function he(e){return e==null}function ge(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function _e(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function ve(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ye(e){if(ve(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return ve(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function be(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 xe(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 Se(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 Ce(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 we(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function O(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}function Te(e){let t=e.length;if(!Fe.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 Ee(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function De(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function Oe(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Ae(e,n,r.value)}}function k(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function ke(e,t,n){return k(e,t,n,!1)}function Ae(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:k(this,t,n.bind(this))},set(e){k(this,t,e)}})}function je(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}function A(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&Ie!==e._zod){Ie=void 0;return}Ie=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Le);let e=j;j=!1;try{let r=n(this);return j?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),j||=e,r}catch(n){throw delete this[t],j||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function Me(e,t,n,r){let i=je(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 Ne,Pe,Fe,Ie,j,Le,M=e((()=>{Ne=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}},Pe=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{},Fe=/[\\uD800-\\uDBFF]/,j=!1,Le={configurable:!0,get(){j=!0}}}));function Re(e){let t=Ve;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Ve=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function N(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){Be.value=new a(r);try{Object.defineProperty(n,\"_zod\",Be)}finally{Be.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),Oe(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?Re(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 P(e){return e&&Object.assign(I,e),I}var ze,Be,Ve,F,He,I,L=e((()=>{M(),Be={value:void 0,enumerable:!1},Ve=`captureStackTrace`in Error?Error:null,F=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},He=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},(ze=globalThis).__zod_globalConfig??(ze.__zod_globalConfig={}),I=globalThis.__zod_globalConfig}));function Ue(){let e=this._zod;return e.message??=JSON.stringify(e.def,pe,2),e.message}function We(e){this._zod.message=e}var Ge,R,Ke,qe,z,Je=e((()=>{L(),M(),Ge={get:Ue,set:We,enumerable:!0,configurable:!0},R={value:void 0,enumerable:!1},Ke=new WeakSet([Object.prototype,Error.prototype]),qe=(e,t)=>{e.name=`$ZodError`,R.value=t,Object.defineProperty(e,\"issues\",R),R.value=void 0,Object.defineProperty(e,\"message\",Ge);let n=Object.getPrototypeOf(e);Ke.has(n)||(Ke.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})}}))},N(`$ZodError`,qe),z=N(`$ZodError`,qe,void 0,{Parent:Error})}));function Ye(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>O(e,n,P()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}var Xe,Ze,Qe,$e,et,tt,nt,rt,it=e((()=>{L(),Je(),M(),Xe=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=>O(e,o,P())));throw Pe(n,a?.callee??t),n}return s.value};return t},Ze=Xe(z),Qe=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=>O(e,o,P())));throw Pe(n,a?.callee??t),n}return s.value};return t},$e=Qe(z),et=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?Ye(e,a.issues,i):{success:!0,data:a.value}},tt=et(z),nt=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?Ye(e,a.issues,i):{success:!0,data:a.value}},rt=nt(z)})),at,ot,st=e((()=>{at=/^[\\s\\S]{0,}$/,ot=/^-?\\d+(?:\\.\\d+)?$/})),B,ct,lt,ut,dt,ft=e((()=>{L(),M(),B=N(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ct=e=>{let t=e.value;return!he(t)&&t.length!==void 0},lt=N(`$ZodCheckMinLength`,(e,t)=>{var n;B.init(e,t),(n=e._zod.def).when??(n.when=ct),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?Te(r):i)>=t.minimum)return;let a=Ee(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ut=N(`$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=()=>{})}),dt=N(`$ZodCheckRegex`,(e,t)=>{ut.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})}})})),pt=e((()=>{})),mt,ht=e((()=>{mt={major:4,minor:6,patch:7}}));async function gt(e,t){let n={async:!0};return Tt(await e._zod.run({value:t,issues:[]},n),n)}function _t(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return Tt(r,n)}catch{}return gt(e,t)},vendor:`zod`,version:1}}function vt(e,t){let n=Ce(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 Ce(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,we(n.issues,t,e),n}}return i(n,a)}}function yt(e,t,n){e.issues.length&&t.issues.push(...E(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(...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}}function bt(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:At,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=xe(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function xt(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}function St(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=>O(e,r,P())))}),t)}function Ct(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 wt(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(De(e))}}var U,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt,Rt=e((()=>{ft(),L(),st(),M(),ht(),U=N(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=mt;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(Se(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&&(we(t.issues,n,e),i||=T(t,n))});else{if(t.issues.length===n)continue;we(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 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 ke(this,`~standard`,_t(this))},set\"~standard\"(e){k(this,`~standard`,e)}}),Tt=(e,t)=>e.issues.length?{issues:e.issues.map(e=>O(e,t,P()))}:{value:e.value},Et=N(`$ZodString`,(e,t)=>{U.init(e,t),e._zod.pattern=t.pattern??at,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}}),Dt=N(`$ZodNumber`,(e,t)=>{U.init(e,t),e._zod.pattern=ot,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}}),Ot=e=>Array.isArray(e)?e.length:-1,kt=N(`$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=>yt(t,r,e)));else if(yt(c,r,e),s&&c.issues.length!==0&&T(c))break}return o.length?Promise.all(o).then(()=>r):r},vt(e,Ot)}),At=[],jt=N(`$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=me(()=>bt(t));A(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)||_e(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=ve,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(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?xt(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),Mt=N(`$ZodUnion`,(e,t)=>{U.init(e,t),A(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),A(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),A(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)))}),A(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=>ge(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=>St(t,r,e,i)):St(o,r,e,i)}}),Nt=N(`$ZodRecord`,(e,t)=>{U.init(e,t);let n=I.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!ye(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=>O(e,i,P())),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`&&ot.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=>O(e,i,P())),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}}),Pt=N(`$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 He(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}}),Ft=N(`$ZodOptional`,(e,t)=>{U.init(e,t),A(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,A(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),A(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${ge(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=>Ct(e,t)):Ct(e,r)}return t.innerType._zod.run(e,n)}}),It=N(`$ZodPipe`,(e,t)=>{U.init(e,t),A(e,`values`,e=>e.def.in._zod.values),A(e,`optin`,e=>e.def.in._zod.optin),A(e,`optout`,e=>e.def.out._zod.optout),A(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)}}),Lt=N(`$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=>wt(t,n,r,e));wt(i,n,r,e)}})})),zt=e((()=>{})),Bt=e((()=>{globalThis.__zod_globalRegistry})),Vt=e((()=>{}));function Ht(e){return e.checks&&=[...e.checks],e}function Ut(e,t){return new e(Ht({type:`string`,...w(t)}))}function Wt(e,t){return new e(Ht({type:`number`,checks:[],...w(t)}))}function W(e,t){return new lt({check:`min_length`,...w(t),minimum:e})}function Gt(e,t){return new dt({check:`string_format`,format:`regex`,...w(t),pattern:e})}function Kt(e,t,n){let r=w(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}function qt(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...w(n)})}var Jt=e((()=>{ft(),M()})),Yt=e((()=>{})),G=e((()=>{L(),it(),Je(),Rt(),zt(),ft(),ht(),M(),st(),Bt(),pt(),Vt(),Jt(),Yt(),Rt(),Yt()})),Xt=e((()=>{G()}));function K(e){return Ut(on,e)}function Zt(e){return Wt(sn,e)}function Qt(e,t){return new cn({type:`array`,element:e,...w(t)})}function q(e,t){let n={type:`object`,shape:e??{},...w(t)};return new ln(n)}function $t(e,t){return new un({type:`union`,options:e,...w(t)})}function en(e,t,n){return!t||!t._zod?new dn({type:`record`,keyType:K(),valueType:e,...w(t)}):new dn({type:`record`,keyType:e,valueType:t,...w(n)})}function tn(e){return new fn({type:`transform`,transform:e})}function J(e){return new pn({type:`optional`,innerType:e})}function nn(e,t){return new mn({type:`pipe`,in:e,out:t})}function rn(e,t){return Kt(hn,e??(()=>!0),t)}function an(e,t={}){return qt(hn,e,t)}var Y,on,sn,cn,ln,un,dn,fn,pn,mn,hn,gn=e((()=>{G(),M(),Xt(),Y=N(`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){k(this,`with`,e)},parse(e,t){return Ze(this,e,t,{callee:this.parse})},parseAsync(e,t){return $e(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return tt(this,e,t)},safeParseAsync(e,t){return rt(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 be(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)}}),on=N(`ZodMiniString`,(e,t)=>{Et.init(e,t),Y.init(e,t)}),sn=N(`ZodMiniNumber`,(e,t)=>{Dt.init(e,t),Y.init(e,t)}),cn=N(`ZodMiniArray`,(e,t)=>{kt.init(e,t),Y.init(e,t)}),ln=N(`ZodMiniObject`,(e,t)=>{jt.init(e,t),Y.init(e,t),Me(e,`shape`,e=>e._zod.def.shape,!1)}),un=N(`ZodMiniUnion`,(e,t)=>{Mt.init(e,t),Y.init(e,t)}),dn=N(`ZodMiniRecord`,(e,t)=>{Nt.init(e,t),Y.init(e,t)}),fn=N(`ZodMiniTransform`,(e,t)=>{Pt.init(e,t),Y.init(e,t)}),pn=N(`ZodMiniOptional`,(e,t)=>{Ft.init(e,t),Y.init(e,t)}),mn=N(`ZodMiniPipe`,(e,t)=>{It.init(e,t),Y.init(e,t)}),hn=N(`ZodMiniCustom`,(e,t)=>{Lt.init(e,t),Y.init(e,t)})})),_n=e((()=>{G()})),vn=e((()=>{G(),Xt(),gn(),_n(),Rt(),M(),gn(),st(),Yt()})),yn=e((()=>{vn()}));function bn(){return K().check(Gt(/^\\d+(\\.\\d+)?$/,`Invalid amount`))}function xn(){return K().check(Gt(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/,`Invalid ISO 8601 datetime`))}var X=e((()=>{yn(),yn()}));function Sn(e){return!!(e&&typeof e==`object`&&e[Tn])}function Cn(e){if(Sn(e))throw new o}function wn(e){return/^payment-authorization$/i.test(e)}var Tn,En,Dn=e((()=>{s(),X(),Tn=Symbol(`mppx.Challenge.legacyUnicodeEscape`),En=`Unsupported credential header: challenges may only select Payment-Authorization.`,K().check(Gt(/^sha-256=/,`Invalid digest format`)),xn(),K().check(an(wn,En)),K().check(W(1))}));function On(e){let{meta:t,opaque:n,request:r,...a}=e.challenge,o=n??(t===void 0?void 0:de(t)),s={challenge:{...a,...o!==void 0&&{opaque:o},request:de(r)},payload:e.payload,...e.source&&{source:e.source}},c=ce(JSON.stringify(s),{pad:!1,url:!0});return`${i.payment} ${c}`}var kn=e((()=>{C(),a(),fe()})),An=e((()=>{a(),s(),C(),Dn(),kn(),X()}));function jn(e){return e}function Mn(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,async createCredential(e){return Cn(e.challenge),i.call(this,e)}}}var Nn=e((()=>{Dn()}));function Pn(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 Fn=e((()=>{})),In,Ln,Rn,zn=e((()=>{X(),In=q({customer:J(K().check(W(1))),hooks:J(q({inputs:q({tax:q({calculation:K().check(W(1))})})})),metadata:J(en(K(),K())),receipt_email:J(K().check(W(1)))}),Ln=rn(e=>typeof e==`function`),Rn=$t([In,Ln])})),Bn,Vn=e((()=>{Nn(),X(),Fn(),zn(),Bn=jn({name:`stripe`,intent:`charge`,schema:{credential:{payload:q({externalId:J(K()),spt:K()})},request:nn(q({amount:bn(),currency:K(),decimals:Zt(),description:J(K()),externalId:J(K()),metadata:J(en(K(),K())),networkId:K(),paymentIntentOptions:J(Rn),paymentMethodTypes:Qt(K()).check(W(1)),recipient:J(K())}),tn(({amount:e,decimals:t,metadata:n,networkId:r,paymentIntentOptions:i,paymentMethodTypes:a,...o})=>({...o,amount:Pn(e,t).toString(),methodDetails:{networkId:r,paymentMethodTypes:a,...n!==void 0&&{metadata:n}}})))}})}));function Hn(e){let{client:t,createToken:n,externalId:r,paymentMethod:i}=e;return Mn(Bn,{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 On({challenge:e,payload:{spt:p,...m===void 0?{}:{externalId:m}}})}})}var Un=e((()=>{kn(),Nn(),X(),Vn()}));function Wn(e){return[Hn(e)]}var Gn=e((()=>{Un(),(function(e){e.charge=Hn})(Wn||={})})),Kn=e((()=>{Un(),Gn()})),qn=e((()=>{x(),m(),g(),y(),ue(),d(),kn(),Nn(),C(),X(),fe(),Kn(),Jn(),a(),s(),Dn()})),Jn=e((()=>{An(),qn(),x(),m(),g(),y(),ue(),d(),C(),Jn(),kn(),s(),fe(),Nn(),X(),a(),Dn()})),Yn=r();Jn();let Xn={data:`__MPPX_DATA__`,error:`root_error`,root:`root`},Zn={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},Qn={challengeId:`data-mppx-challenge-id`,remaining:`data-remaining`};var Z=class{name;constructor(e){this.name=`--mppx-${e}`}toString(){return`var(${this.name})`}};let $n={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: ${$n.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 er(e,t){if(t==null)return e;if(!tr(e)||!tr(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]=tr(t)&&tr(r)?er(t,r):r}return n}function tr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function nr(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()}C();function rr(e){let t=document.getElementById(Xn.data),n=te(t.textContent),r=t.getAttribute(Qn.remaining);!r||Number(r)<=1?t.remove():t.setAttribute(Qn.remaining,String(Number(r)-1));let i=document.currentScript,a=i?.getAttribute(Qn.challengeId),o=a?(i.removeAttribute(Qn.challengeId),n[a]):Object.values(n).find(t=>t.challenge.method===e);return{...o,error(e){if(!e){document.getElementById(Xn.error)?.remove();return}let t=document.getElementById(Xn.error);if(t){t.textContent=e;return}let n=document.createElement(`p`);n.id=Xn.error,n.className=`mppx-error`,n.role=`alert`,n.textContent=e,document.getElementById(o.rootId)?.after(n)},root:document.getElementById(o.rootId),submit:e=>nr(e,o.challenge.header),vars:$n}}let Q=rr(`stripe`),$=Q.config.elements,ir=String.raw,ar=document.createElement(`style`);ar.textContent=ir`\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(ar),(async()=>{let e=await(0,Yn.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 er({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 Wn({client:e,createToken:or})[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 or(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=class extends Error{name=`LegacyUnicodeEscapedChallengeError`;constructor(){super(`Legacy unicode-escaped challenge: the server escaped a bound parameter as \\\\uXXXX; upgrade the server.`)}}})),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((()=>{x()}));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,x=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 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=se.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(ne(e),t)}var se,S,ce=e((()=>{x(),se=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]))}})),C=e((()=>{f(),x(),h(),_(),l(),ce(),C()})),le,w=e((()=>{le={payment:`Payment`}}));function ue(e){return oe(g(e),{pad:!1,url:!0})}var T=e((()=>{C()}));function de(e,t){return typeof t==`bigint`?t.toString():t}function fe(e){return new je(e)}function pe(e){return e==null}function me(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function he(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function ge(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _e(e){if(ge(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return ge(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function ve(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function E(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 ye(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}function D(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 be(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 O(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function k(e){return typeof e==`string`?e:e?.message}function xe(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 Se(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function A(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:k(e.inst?._zod.def?.error?.(e))??k(a?.(e))??k(t?.error?.(e))??k(n.customError?.(e))??k(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 Ce(e){let t=e.length;if(!Ne.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 we(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Te(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function Ee(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Oe(e,n,r.value)}}function j(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function De(e,t,n){return j(e,t,n,!1)}function Oe(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:j(this,t,n.bind(this))},set(e){j(this,t,e)}})}function ke(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}function M(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&Pe!==e._zod){Pe=void 0;return}Pe=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Fe);let e=N;N=!1;try{let r=n(this);return N?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),N||=e,r}catch(n){throw delete this[t],N||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function Ae(e,t,n,r){let i=ke(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 je,Me,Ne,Pe,N,Fe,P=e((()=>{je=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}},Me=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{},Ne=/[\\uD800-\\uDBFF]/,N=!1,Fe={configurable:!0,get(){N=!0}}}));function Ie(e){let t=Re;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Re=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){L.value=new a(r);try{Object.defineProperty(n,\"_zod\",L)}finally{L.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),Ee(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?Ie(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 I(e){return e&&Object.assign(z,e),z}var Le,L,Re,R,ze,z,B=e((()=>{P(),L={value:void 0,enumerable:!1},Re=`captureStackTrace`in Error?Error:null,R=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},ze=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},(Le=globalThis).__zod_globalConfig??(Le.__zod_globalConfig={}),z=globalThis.__zod_globalConfig}));function Be(){let e=this._zod;return e.message??=JSON.stringify(e.def,de,2),e.message}function Ve(e){this._zod.message=e}var He,V,Ue,We,H,Ge=e((()=>{B(),P(),He={get:Be,set:Ve,enumerable:!0,configurable:!0},V={value:void 0,enumerable:!1},Ue=new WeakSet([Object.prototype,Error.prototype]),We=(e,t)=>{e.name=`$ZodError`,V.value=t,Object.defineProperty(e,\"issues\",V),V.value=void 0,Object.defineProperty(e,\"message\",He);let n=Object.getPrototypeOf(e);Ue.has(n)||(Ue.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`,We),H=F(`$ZodError`,We,void 0,{Parent:Error})}));function Ke(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>A(e,n,I()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}var qe,Je,Ye,Xe,Ze,Qe,$e,et,tt=e((()=>{B(),Ge(),P(),qe=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 R;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>A(e,o,I())));throw Me(n,a?.callee??t),n}return s.value};return t},Je=qe(H),Ye=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=>A(e,o,I())));throw Me(n,a?.callee??t),n}return s.value};return t},Xe=Ye(H),Ze=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 R;return a.issues.length?Ke(e,a.issues,i):{success:!0,data:a.value}},Qe=Ze(H),$e=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?Ke(e,a.issues,i):{success:!0,data:a.value}},et=$e(H)})),nt,rt,it=e((()=>{nt=/^[\\s\\S]{0,}$/,rt=/^-?\\d+(?:\\.\\d+)?$/})),U,at,ot,st,ct,lt=e((()=>{B(),P(),U=F(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),at=e=>{let t=e.value;return!pe(t)&&t.length!==void 0},ot=F(`$ZodCheckMinLength`,(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=at),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?Ce(r):i)>=t.minimum)return;let a=we(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),st=F(`$ZodCheckStringFormat`,(e,t)=>{var n,r;U.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=()=>{})}),ct=F(`$ZodCheckRegex`,(e,t)=>{st.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})}})})),ut=e((()=>{})),dt,ft=e((()=>{dt={major:4,minor:6,patch:7}}));async function pt(e,t){let n={async:!0};return wt(await e._zod.run({value:t,issues:[]},n),n)}function mt(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return wt(r,n)}catch{}return pt(e,t)},vendor:`zod`,version:1}}function ht(e,t){let n=xe(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 xe(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,Se(n.issues,t,e),n}}return i(n,a)}}function gt(e,t,n){e.issues.length&&t.issues.push(...O(n,e.issues)),t.value[n]=e.value}function _t(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(...O(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:kt,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=ye(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(D(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=>_t(e,n,i,t,d,f))):_t(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=>!D(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=>A(e,r,I())))}),t)}function xt(e,t){return e.value=t.issues.length?void 0:t.value,e}function St(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 Ct(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(Te(e))}}var W,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt=e((()=>{lt(),B(),it(),P(),ft(),W=F(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=dt;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=D(t),a;for(let o of n){if(o._zod.def.when){if(be(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 R;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(Se(t.issues,n,e),i||=D(t,n))});else{if(t.issues.length===n)continue;Se(t.issues,n,e),i||=D(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(D(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new R;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 R;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get\"~standard\"(){return De(this,`~standard`,mt(this))},set\"~standard\"(e){j(this,`~standard`,e)}}),wt=(e,t)=>e.issues.length?{issues:e.issues.map(e=>A(e,t,I()))}:{value:e.value},Tt=F(`$ZodString`,(e,t)=>{W.init(e,t),e._zod.pattern=t.pattern??nt,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}}),Et=F(`$ZodNumber`,(e,t)=>{W.init(e,t),e._zod.pattern=rt,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}}),Dt=e=>Array.isArray(e)?e.length:-1,Ot=F(`$ZodArray`,(e,t)=>{W.init(e,t);let n=z.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=>gt(t,r,e)));else if(gt(c,r,e),s&&c.issues.length!==0&&D(c))break}return o.length?Promise.all(o).then(()=>r):r},ht(e,Dt)}),kt=[],At=F(`$ZodObject`,(e,t)=>{W.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=fe(()=>vt(t));M(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)||he(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=ge,o=t.catchall,s,c=z.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(D(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=>_t(n,t,e,r,a,o))):_t(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}}),jt=F(`$ZodUnion`,(e,t)=>{W.init(e,t),M(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),M(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),M(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)))}),M(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=>me(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)}}),Mt=F(`$ZodRecord`,(e,t)=>{W.init(e,t);let n=z.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!_e(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=>A(e,i,I())),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(...O(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...O(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`&&rt.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=>A(e,i,I())),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(...O(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...O(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}}),Nt=F(`$ZodTransform`,(e,t)=>{W.init(e,t),e._zod.optin=`optional`,z.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new ze(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 R;return n.value=i,n}}),Pt=F(`$ZodOptional`,(e,t)=>{W.init(e,t),M(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,M(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),M(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${me(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)}}),Ft=F(`$ZodPipe`,(e,t)=>{W.init(e,t),M(e,`values`,e=>e.def.in._zod.values),M(e,`optin`,e=>e.def.in._zod.optin),M(e,`optout`,e=>e.def.out._zod.optout),M(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=>St(e,t.in,n)):St(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>St(e,t.out,n)):St(r,t.out,n)}}),It=F(`$ZodCustom`,(e,t)=>{U.init(e,t),W.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=>Ct(t,n,r,e));Ct(i,n,r,e)}})})),Rt=e((()=>{})),zt=e((()=>{globalThis.__zod_globalRegistry})),Bt=e((()=>{}));function Vt(e){return e.checks&&=[...e.checks],e}function Ht(e,t){return new e(Vt({type:`string`,...E(t)}))}function Ut(e,t){return new e(Vt({type:`number`,checks:[],...E(t)}))}function G(e,t){return new ot({check:`min_length`,...E(t),minimum:e})}function Wt(e,t){return new ct({check:`string_format`,format:`regex`,...E(t),pattern:e})}function Gt(e,t,n){let r=E(n);return r.abort??=!0,new e({type:`custom`,check:`custom`,fn:t,...r})}function Kt(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...E(n)})}var qt=e((()=>{lt(),P()})),Jt=e((()=>{})),Yt=e((()=>{B(),tt(),Ge(),Lt(),Rt(),lt(),ft(),P(),it(),zt(),ut(),Bt(),qt(),Jt(),Lt(),Jt()})),Xt=e((()=>{Yt()}));function K(e){return Ht(on,e)}function Zt(e){return Ut(sn,e)}function Qt(e,t){return new cn({type:`array`,element:e,...E(t)})}function q(e,t){let n={type:`object`,shape:e??{},...E(t)};return new ln(n)}function $t(e,t){return new un({type:`union`,options:e,...E(t)})}function en(e,t,n){return!t||!t._zod?new dn({type:`record`,keyType:K(),valueType:e,...E(t)}):new dn({type:`record`,keyType:e,valueType:t,...E(n)})}function tn(e){return new fn({type:`transform`,transform:e})}function J(e){return new pn({type:`optional`,innerType:e})}function nn(e,t){return new mn({type:`pipe`,in:e,out:t})}function rn(e,t){return Gt(hn,e??(()=>!0),t)}function an(e,t={}){return Kt(hn,e,t)}var Y,on,sn,cn,ln,un,dn,fn,pn,mn,hn,gn=e((()=>{Yt(),P(),Xt(),Y=F(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);W.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){j(this,`with`,e)},parse(e,t){return Je(this,e,t,{callee:this.parse})},parseAsync(e,t){return Xe(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return Qe(this,e,t)},safeParseAsync(e,t){return et(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 ve(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)}}),on=F(`ZodMiniString`,(e,t)=>{Tt.init(e,t),Y.init(e,t)}),sn=F(`ZodMiniNumber`,(e,t)=>{Et.init(e,t),Y.init(e,t)}),cn=F(`ZodMiniArray`,(e,t)=>{Ot.init(e,t),Y.init(e,t)}),ln=F(`ZodMiniObject`,(e,t)=>{At.init(e,t),Y.init(e,t),Ae(e,`shape`,e=>e._zod.def.shape,!1)}),un=F(`ZodMiniUnion`,(e,t)=>{jt.init(e,t),Y.init(e,t)}),dn=F(`ZodMiniRecord`,(e,t)=>{Mt.init(e,t),Y.init(e,t)}),fn=F(`ZodMiniTransform`,(e,t)=>{Nt.init(e,t),Y.init(e,t)}),pn=F(`ZodMiniOptional`,(e,t)=>{Pt.init(e,t),Y.init(e,t)}),mn=F(`ZodMiniPipe`,(e,t)=>{Ft.init(e,t),Y.init(e,t)}),hn=F(`ZodMiniCustom`,(e,t)=>{It.init(e,t),Y.init(e,t)})})),_n=e((()=>{Yt()})),vn=e((()=>{Yt(),Xt(),gn(),_n(),Lt(),P(),gn(),it(),Jt()})),yn=e((()=>{vn()}));function bn(){return K().check(Wt(/^\\d+(\\.\\d+)?$/,`Invalid amount`))}function xn(){return K().check(Wt(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/,`Invalid ISO 8601 datetime`))}var X=e((()=>{yn(),yn()}));function Sn(e){return!!(e&&typeof e==`object`&&e[Tn])}function Cn(e){if(Sn(e))throw new i}function wn(e){return/^payment-authorization$/i.test(e)}var Tn,En,Dn=e((()=>{a(),X(),Tn=Symbol(`mppx.Challenge.legacyUnicodeEscape`),En=`Unsupported credential header: challenges may only select Payment-Authorization.`,K().check(Wt(/^sha-256=/,`Invalid digest format`)),xn(),K().check(an(wn,En)),K().check(G(1))}));function On(e){let{meta:t,opaque:n,request:r,...i}=e.challenge,a=n??(t===void 0?void 0:ue(t)),o={challenge:{...i,...a!==void 0&&{opaque:a},request:ue(r)},payload:e.payload,...e.source&&{source:e.source}},s=oe(JSON.stringify(o),{pad:!1,url:!0});return`${le.payment} ${s}`}var kn=e((()=>{C(),w(),T()})),An=e((()=>{a(),kn(),C(),X(),T(),w(),Dn()}));function jn(e){return e}function Mn(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,async createCredential(e){return Cn(e.challenge),i.call(this,e)}}}var Nn=e((()=>{Dn()}));function Pn(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 Fn=e((()=>{})),In,Ln,Rn,zn=e((()=>{X(),In=q({customer:J(K().check(G(1))),hooks:J(q({inputs:q({tax:q({calculation:K().check(G(1))})})})),metadata:J(en(K(),K())),receipt_email:J(K().check(G(1)))}),Ln=rn(e=>typeof e==`function`),Rn=$t([In,Ln])})),Bn,Vn=e((()=>{Nn(),X(),Fn(),zn(),Bn=jn({name:`stripe`,intent:`charge`,schema:{credential:{payload:q({externalId:J(K()),spt:K()})},request:nn(q({amount:bn(),currency:K(),decimals:Zt(),description:J(K()),externalId:J(K()),metadata:J(en(K(),K())),networkId:K(),paymentIntentOptions:J(Rn),paymentMethodTypes:Qt(K()).check(G(1)),recipient:J(K())}),tn(({amount:e,decimals:t,metadata:n,networkId:r,paymentIntentOptions:i,paymentMethodTypes:a,...o})=>({...o,amount:Pn(e,t).toString(),methodDetails:{networkId:r,paymentMethodTypes:a,...n!==void 0&&{metadata:n}}})))}})}));function Hn(e){let{client:t,createToken:n,externalId:r,paymentMethod:i}=e;return Mn(Bn,{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 On({challenge:e,payload:{spt:p,...m===void 0?{}:{externalId:m}}})}})}var Un=e((()=>{kn(),Nn(),X(),Vn()}));function Wn(e){return[Hn(e)]}var Gn=e((()=>{Un(),(function(e){e.charge=Hn})(Wn||={})})),Kn=e((()=>{Un(),Gn()})),qn=e((()=>{x(),f(),h(),_(),ce(),l(),kn(),Nn(),C(),X(),T(),Kn(),Jn(),w(),a(),Dn()})),Jn=e((()=>{An(),qn(),x(),f(),h(),_(),ce(),l(),C(),Jn(),kn(),a(),T(),Nn(),X(),w(),Dn()})),Yn=r();Jn();let Xn={data:`__MPPX_DATA__`,error:`root_error`,root:`root`},Zn={serviceWorker:`__mppx_worker`,tab:`__mppx_tab`},Qn={challengeId:`data-mppx-challenge-id`,remaining:`data-remaining`};var Z=class{name;constructor(e){this.name=`--mppx-${e}`}toString(){return`var(${this.name})`}};let $n={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: ${$n.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 er(e,t){if(t==null)return e;if(!tr(e)||!tr(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]=tr(t)&&tr(r)?er(t,r):r}return n}function tr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function nr(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()}C();function rr(e){let t=document.getElementById(Xn.data),n=ee(t.textContent),r=t.getAttribute(Qn.remaining);!r||Number(r)<=1?t.remove():t.setAttribute(Qn.remaining,String(Number(r)-1));let i=document.currentScript,a=i?.getAttribute(Qn.challengeId),o=a?(i.removeAttribute(Qn.challengeId),n[a]):Object.values(n).find(t=>t.challenge.method===e);return{...o,error(e){if(!e){document.getElementById(Xn.error)?.remove();return}let t=document.getElementById(Xn.error);if(t){t.textContent=e;return}let n=document.createElement(`p`);n.id=Xn.error,n.className=`mppx-error`,n.role=`alert`,n.textContent=e,document.getElementById(o.rootId)?.after(n)},root:document.getElementById(o.rootId),submit:e=>nr(e,o.challenge.header),vars:$n}}let Q=rr(`stripe`),$=Q.config.elements,ir=String.raw,ar=document.createElement(`style`);ar.textContent=ir`\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(ar),(async()=>{let e=await(0,Yn.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 er({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 Wn({client:e,createToken:or})[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 or(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
|
|
@@ -3,7 +3,9 @@ import { keccak256, parseEventLogs, parseUnits, } from 'viem';
|
|
|
3
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
|
+
import * as FundsMoved from '../../client/internal/FundsMoved.js';
|
|
6
7
|
import * as MethodResponse from '../../client/internal/MethodResponse.js';
|
|
8
|
+
import * as SpendHooks from '../../client/internal/SpendHooks.js';
|
|
7
9
|
import * as Credential from '../../Credential.js';
|
|
8
10
|
import * as Currency from '../../Currency.js';
|
|
9
11
|
import * as Errors from '../../Errors.js';
|
|
@@ -90,6 +92,10 @@ export function charge(parameters = {}) {
|
|
|
90
92
|
context: chargeContextSchema,
|
|
91
93
|
async createCredential(credentialParameters) {
|
|
92
94
|
const { challenge, context } = credentialParameters;
|
|
95
|
+
// Set when the client's spending options checked this payment.
|
|
96
|
+
const spend = SpendHooks.of(credentialParameters);
|
|
97
|
+
// Spending checks were skipped to resume an outstanding withdrawal: never pay anew.
|
|
98
|
+
const notResumable = () => new Error('The Zone withdrawal this challenge resumes is no longer outstanding. Retry the request to pay it.');
|
|
93
99
|
assertChallengePolicy(parameters, caps, challenge.request);
|
|
94
100
|
// Sign on the pinned chain when the challenge omits a chain ID.
|
|
95
101
|
const challengeChainId = challenge.request.methodDetails?.chainId;
|
|
@@ -143,6 +149,8 @@ export function charge(parameters = {}) {
|
|
|
143
149
|
const outstanding = findZoneWithdrawal(options);
|
|
144
150
|
if (outstanding)
|
|
145
151
|
return resumeZoneCredential(options, outstanding);
|
|
152
|
+
if (spend?.resume)
|
|
153
|
+
throw notResumable();
|
|
146
154
|
// With nothing outstanding, an expired challenge can't be paid: its server refuses any
|
|
147
155
|
// credential for it, so a payment on Tempo would be lost.
|
|
148
156
|
if (challenge.expires)
|
|
@@ -150,6 +158,8 @@ export function charge(parameters = {}) {
|
|
|
150
158
|
if (settlesBeforeExpiry(challenge.expires, parameters.zone.settlementTimeoutMs))
|
|
151
159
|
return createZoneCredential(options);
|
|
152
160
|
}
|
|
161
|
+
if (spend?.resume)
|
|
162
|
+
throw notResumable();
|
|
153
163
|
const defaultAccount = getAccount(client, context);
|
|
154
164
|
const resolveAccount = async (operation) => (await parameters.resolveAccount?.({
|
|
155
165
|
account: defaultAccount,
|
|
@@ -178,11 +188,14 @@ export function charge(parameters = {}) {
|
|
|
178
188
|
}
|
|
179
189
|
const currency = request.currency;
|
|
180
190
|
const isMachineTokenCurrency = MachineTokenCharge.isMachineToken({ chainId, currency });
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
// A memo the server requires (`methodDetails.memo`, which other MPP servers may set)
|
|
192
|
+
// goes on the primary transfer as is; otherwise the optional attribution memo does.
|
|
193
|
+
const memo = methodDetails?.memo ??
|
|
194
|
+
Attribution.encode({
|
|
195
|
+
challengeId: challenge.id,
|
|
196
|
+
clientId,
|
|
197
|
+
serverId: challenge.realm,
|
|
198
|
+
});
|
|
186
199
|
const transfers = Charge_internal.getTransfers({
|
|
187
200
|
amount,
|
|
188
201
|
methodDetails: {
|
|
@@ -198,7 +211,9 @@ export function charge(parameters = {}) {
|
|
|
198
211
|
token: currency,
|
|
199
212
|
}));
|
|
200
213
|
const autoSwap = AutoSwap.resolve(context?.autoSwap ?? parameters.autoSwap, AutoSwap.defaultCurrencies);
|
|
201
|
-
|
|
214
|
+
// Spending options checked the charge currency, so under them the payment debits only that
|
|
215
|
+
// currency, never MACH.
|
|
216
|
+
const machineTokenEnabled = methodDetails?.machineTokenEnabled === true && !spend;
|
|
202
217
|
const machineTokenCandidate = machineTokenEnabled
|
|
203
218
|
? MachineTokenCharge.getRoute({ chainId, currency, transfers })
|
|
204
219
|
: undefined;
|
|
@@ -249,6 +264,13 @@ export function charge(parameters = {}) {
|
|
|
249
264
|
maxAmountIn: autoSwap.maxAmountIn,
|
|
250
265
|
})
|
|
251
266
|
: undefined;
|
|
267
|
+
// A swap debits another token, by up to its slippage, which spending options never
|
|
268
|
+
// checked: refuse it. A funder can swap into the charge currency beforehand.
|
|
269
|
+
if (spend && swapCalls)
|
|
270
|
+
throw new Errors.PaymentLimitExceededError({
|
|
271
|
+
limit: spend.limit,
|
|
272
|
+
reason: 'asset',
|
|
273
|
+
});
|
|
252
274
|
// Without MACH or the charge currency the payment can only revert, so say where to buy MACH.
|
|
253
275
|
if (machineTokenUnpayable && !autoSwap) {
|
|
254
276
|
const error = await getMachineTokenFundingError(client, {
|
|
@@ -296,7 +318,14 @@ export function charge(parameters = {}) {
|
|
|
296
318
|
const challengeExpiry = Math.floor(new Date(challenge.expires).getTime() / 1000) + 1;
|
|
297
319
|
return Math.min(defaultExpiry, challengeExpiry);
|
|
298
320
|
})();
|
|
321
|
+
// The client's spending checks can outlast the challenge, and its server refuses a credential
|
|
322
|
+
// for an expired one: under them, never broadcast or sign for it.
|
|
323
|
+
const assertUnexpired = () => {
|
|
324
|
+
if (spend && challenge.expires)
|
|
325
|
+
Expires.assert(challenge.expires, challenge.id);
|
|
326
|
+
};
|
|
299
327
|
if (mode === 'push') {
|
|
328
|
+
assertUnexpired();
|
|
300
329
|
const { receipts } = account.type === 'local'
|
|
301
330
|
? {
|
|
302
331
|
receipts: [
|
|
@@ -317,8 +346,9 @@ export function charge(parameters = {}) {
|
|
|
317
346
|
forceAtomic: calls.length > 1,
|
|
318
347
|
});
|
|
319
348
|
const hash = receipts?.[0]?.transactionHash;
|
|
349
|
+
// The calls were sent and may have paid, so spending limits keep counting them.
|
|
320
350
|
if (!hash)
|
|
321
|
-
throw new Error('No transaction receipt returned.');
|
|
351
|
+
throw FundsMoved.mark(new Error('No transaction receipt returned.'));
|
|
322
352
|
return Credential.serialize({
|
|
323
353
|
challenge,
|
|
324
354
|
payload: { hash, type: 'hash' },
|
|
@@ -361,6 +391,7 @@ export function charge(parameters = {}) {
|
|
|
361
391
|
}
|
|
362
392
|
// Preparation is asynchronous: check again immediately before signing.
|
|
363
393
|
assertSponsorable();
|
|
394
|
+
assertUnexpired();
|
|
364
395
|
const signature = await signTransaction(client, prepared);
|
|
365
396
|
return Credential.serialize({
|
|
366
397
|
challenge,
|
|
@@ -378,14 +409,26 @@ export function charge(parameters = {}) {
|
|
|
378
409
|
const account = options.context?.account ?? parameters.account;
|
|
379
410
|
const signer = (typeof account === 'string' ? account : account?.address)?.toLowerCase();
|
|
380
411
|
const key = `${signer ?? ''}:${options.challenge.id}`;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
412
|
+
const constraints = SpendHooks.of(options);
|
|
413
|
+
const shared = signing.get(key);
|
|
414
|
+
// One signing is one payment: the client's spending options count it for the call that
|
|
415
|
+
// started it, not again for each call that joins it. A retry that starts its own signing,
|
|
416
|
+
// such as one resuming a Zone payment, is counted for itself.
|
|
417
|
+
if (constraints)
|
|
418
|
+
SpendHooks.join(constraints, shared?.constraints);
|
|
419
|
+
if (shared)
|
|
420
|
+
return shared.promise;
|
|
421
|
+
const promise = method.createCredential(options).finally(() => signing.delete(key));
|
|
422
|
+
signing.set(key, { constraints, promise });
|
|
386
423
|
return promise;
|
|
387
424
|
};
|
|
388
|
-
return MethodResponse.registerTransactionHash({ ...method, createCredential }, transactionHash)
|
|
425
|
+
return SpendHooks.register(MethodResponse.registerTransactionHash({ ...method, createCredential }, transactionHash), {
|
|
426
|
+
// The client's spending options refuse what this policy refuses before any funder runs.
|
|
427
|
+
assert: (challenge) => assertChallengePolicy(parameters, caps, challenge.request),
|
|
428
|
+
// A withdrawal already sent for this challenge was counted when it started.
|
|
429
|
+
resumes: (challenge) => hasZoneWithdrawal(pendingZoneWithdrawals, challenge, parameters.zone &&
|
|
430
|
+
(parameters.zone.zoneId ?? Zone.idFromChainId(parameters.zone.client.chain?.id ?? 0))),
|
|
431
|
+
});
|
|
389
432
|
}
|
|
390
433
|
/**
|
|
391
434
|
* Returns an error that links to the MACH onramp when a machine-token-enabled charge can't be paid:
|
|
@@ -493,6 +536,26 @@ function findZoneWithdrawal(options) {
|
|
|
493
536
|
}
|
|
494
537
|
return undefined;
|
|
495
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Whether creating this challenge's credential resumes a withdrawal already started, as
|
|
541
|
+
* {@link findZoneWithdrawal} would find, rather than paying: its own, or one with the same terms
|
|
542
|
+
* that can still be redeemed and no call is waiting on. It only reads `pending`.
|
|
543
|
+
*/
|
|
544
|
+
function hasZoneWithdrawal(pending, challenge, zoneId) {
|
|
545
|
+
if (zoneId === undefined || pending.size === 0)
|
|
546
|
+
return false;
|
|
547
|
+
if (pending.has(zoneWithdrawalKey(challenge)))
|
|
548
|
+
return true;
|
|
549
|
+
const terms = zoneTermsKey(challenge, zoneId);
|
|
550
|
+
if (terms === undefined)
|
|
551
|
+
return false;
|
|
552
|
+
for (const entry of pending.values())
|
|
553
|
+
if (entry.terms === terms &&
|
|
554
|
+
isRedeemable(entry.challenge.expires) &&
|
|
555
|
+
(entry.redeemedLate || entry.waiters === 0))
|
|
556
|
+
return true;
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
496
559
|
/**
|
|
497
560
|
* Waits for an outstanding withdrawal to settle and returns a `zone` credential for the
|
|
498
561
|
* challenge it pays. A withdrawal started for an earlier challenge pays only that challenge,
|
|
@@ -531,7 +594,8 @@ async function waitForZoneCredential(options, entry) {
|
|
|
531
594
|
const error = new Error(`Zone withdrawal transaction ${withdrawal.transactionHash} was sent, but its sender tag could not be read from the Zone. Retry the challenge to resume without withdrawing again.`);
|
|
532
595
|
// Defined manually (non-enumerable, like native `cause`) so consumers on pre-ES2022 libs still typecheck.
|
|
533
596
|
Object.defineProperty(error, 'cause', { configurable: true, value: cause, writable: true });
|
|
534
|
-
|
|
597
|
+
// The withdrawal was mined, so spending limits keep counting it.
|
|
598
|
+
throw FundsMoved.mark(error);
|
|
535
599
|
}));
|
|
536
600
|
let settled;
|
|
537
601
|
try {
|
|
@@ -726,9 +790,9 @@ async function requestZoneWithdrawal(options, state) {
|
|
|
726
790
|
hash,
|
|
727
791
|
timeout: zoneReceiptRecoveryTimeoutMs,
|
|
728
792
|
}).catch(() => {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
793
|
+
// Typed so spending limits keep counting a payment that may have moved funds.
|
|
794
|
+
const error = new Errors.BroadcastOutcomeUnknownError({ cause, transactionHash: hash });
|
|
795
|
+
error.message = `Zone withdrawal outcome is unknown: transaction ${hash} may have been sent. Retrying this challenge does not withdraw again.`;
|
|
732
796
|
throw error;
|
|
733
797
|
}));
|
|
734
798
|
// A reverted withdrawal moved nothing, so the challenge may be retried.
|
|
@@ -23,7 +23,7 @@ import * as SponsorBudget from './SponsorBudget.js';
|
|
|
23
23
|
export declare function charge<const parameters extends charge.Parameters>(parameters?: NoExtraKeys<parameters, charge.Parameters>): Method.Server<typeof Methods.charge, charge.DeriveDefaults<parameters>>;
|
|
24
24
|
export declare namespace charge {
|
|
25
25
|
type StoreItemMap = {
|
|
26
|
-
[key: `mppx:charge:${string}`]: number | SponsorBudget.State | Store.ReplayMarker;
|
|
26
|
+
[key: `mppx:charge:${string}`]: number | SponsorBudget.State | Store.ReplayMarker | BroadcastMarker;
|
|
27
27
|
};
|
|
28
28
|
type Defaults = LooseOmit<Method.RequestDefaults<typeof Methods.charge>, 'feePayer' | 'recipient'>;
|
|
29
29
|
type ValidateSender = (parameters: ValidateSenderParameters) => boolean | Promise<boolean>;
|
|
@@ -209,5 +209,11 @@ type ExpectedTransfer = {
|
|
|
209
209
|
memo?: `0x${string}` | undefined;
|
|
210
210
|
recipient: `0x${string}`;
|
|
211
211
|
};
|
|
212
|
+
/** A broadcast this server sent for a challenge whose outcome was unknown. */
|
|
213
|
+
type BroadcastMarker = {
|
|
214
|
+
challengeId: string;
|
|
215
|
+
expires: number;
|
|
216
|
+
type: 'mppx:broadcast';
|
|
217
|
+
};
|
|
212
218
|
export {};
|
|
213
219
|
//# sourceMappingURL=Charge.d.ts.map
|