@stackone/core 1.57.0 → 1.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -23,4 +23,4 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
23
23
  if (${n}.issues.length) payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
24
24
  ...iss,
25
25
  path: iss.path ? [${we(e)}, ...iss.path] : [${we(e)}]
26
- })));`),t.write(`newResult[${we(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=Ee,o=!ge.jitless,s=De,c=o&&s.value,l=t.catchall,u;e._zod.parse=(s,d)=>{u??=n.value;let f=s.value;if(!a(f))return s.issues.push({expected:`object`,code:`invalid_type`,input:f,inst:e}),s;let p=[];if(o&&c&&d?.async===!1&&d.jitless!==!0)i||=r(t.shape),s=i(s,d);else{s.value={};let e=u.shape;for(let t of u.keys){let n=e[t],r=n._zod.run({value:f[t],issues:[]},d),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?p.push(r.then(e=>i?An(e,s,t,f):kn(e,s,t))):i?An(r,s,t,f):kn(r,s,t)}}if(!l)return p.length?Promise.all(p).then(()=>s):s;let m=[],h=u.keySet,g=l._zod,_=g.def.type;for(let e of Object.keys(f)){if(h.has(e))continue;if(_===`never`){m.push(e);continue}let t=g.run({value:f[e],issues:[]},d);t instanceof Promise?p.push(t.then(t=>kn(t,s,e))):kn(t,s,e)}return m.length&&s.issues.push({code:`unrecognized_keys`,keys:m,input:f,inst:e}),p.length?Promise.all(p).then(()=>s):s}});function Mn(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>F(e,r,O())))}),t}const Nn=D(`$ZodUnion`,(e,t)=>{R.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>xe(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>Mn(t,n,e,r)):Mn(a,n,e,r)}}),Pn=D(`$ZodDiscriminatedUnion`,(e,t)=>{Nn.init(e,t);let n=e._zod.parse;k(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=ye(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!Ee(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,input:o,path:[t.discriminator],inst:e}),i)}}),Fn=D(`$ZodIntersection`,(e,t)=>{R.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>Ln(e,t,n)):Ln(e,i,a)}});function In(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Oe(e)&&Oe(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=In(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=In(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ln(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),N(e))return e;let r=In(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Rn=D(`$ZodRecord`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Oe(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...P(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...P(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({origin:`record`,code:`invalid_key`,issues:s.issues.map(e=>F(e,r,O())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...P(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...P(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),zn=D(`$ZodEnum`,(e,t)=>{R.init(e,t);let n=_e(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>ke.has(typeof e)).map(e=>typeof e==`string`?A(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),Bn=D(`$ZodLiteral`,(e,t)=>{R.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?A(e):e?e.toString():String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),Vn=D(`$ZodTransform`,(e,t)=>{R.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new he;return e.value=r,e}}),Hn=D(`$ZodOptional`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${xe(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),Un=D(`$ZodNullable`,(e,t)=>{R.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${xe(e.source)}|null)$`):void 0}),k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Wn=D(`$ZodDefault`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Gn(e,t)):Gn(r,t)}});function Gn(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Kn=D(`$ZodPrefault`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),qn=D(`$ZodNonOptional`,(e,t)=>{R.init(e,t),k(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Jn(t,e)):Jn(i,e)}});function Jn(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Yn=D(`$ZodCatch`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)}}),Xn=D(`$ZodPipe`,(e,t)=>{R.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Zn(e,t,n)):Zn(r,t,n)}});function Zn(e,t,n){return N(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Qn=D(`$ZodReadonly`,(e,t)=>{R.init(e,t),k(e._zod,`propValues`,()=>t.innerType._zod.propValues),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then($n):$n(r)}});function $n(e){return e.value=Object.freeze(e.value),e}const er=D(`$ZodLazy`,(e,t)=>{R.init(e,t),k(e._zod,`innerType`,()=>t.getter()),k(e._zod,`pattern`,()=>e._zod.innerType._zod.pattern),k(e._zod,`propValues`,()=>e._zod.innerType._zod.propValues),k(e._zod,`optin`,()=>e._zod.innerType._zod.optin),k(e._zod,`optout`,()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>{let r=e._zod.innerType;return r._zod.run(t,n)}}),tr=D(`$ZodCustom`,(e,t)=>{L.init(e,t),R.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>nr(t,n,r,e));nr(i,n,r,e)}});function nr(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(I(e))}}const rr=Symbol(`ZodOutput`),ir=Symbol(`ZodInput`);var ar=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function or(){return new ar}const sr=or();function cr(e,t){return new e({type:`string`,...M(t)})}function lr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...M(t)})}function ur(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...M(t)})}function dr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...M(t)})}function fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...M(t)})}function pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...M(t)})}function mr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...M(t)})}function hr(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...M(t)})}function gr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...M(t)})}function _r(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...M(t)})}function vr(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...M(t)})}function yr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...M(t)})}function br(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...M(t)})}function xr(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...M(t)})}function Sr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...M(t)})}function Cr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...M(t)})}function wr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...M(t)})}function Tr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...M(t)})}function Er(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...M(t)})}function Dr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...M(t)})}function Or(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...M(t)})}function kr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...M(t)})}function Ar(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...M(t)})}function jr(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...M(t)})}function Mr(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...M(t)})}function Nr(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...M(t)})}function Pr(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...M(t)})}function Fr(e,t){return new e({type:`number`,checks:[],...M(t)})}function Ir(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...M(t)})}function Lr(e,t){return new e({type:`boolean`,...M(t)})}function Rr(e){return new e({type:`unknown`})}function zr(e,t){return new e({type:`never`,...M(t)})}function Br(e,t){return new jt({check:`less_than`,...M(t),value:e,inclusive:!1})}function Vr(e,t){return new jt({check:`less_than`,...M(t),value:e,inclusive:!0})}function Hr(e,t){return new Mt({check:`greater_than`,...M(t),value:e,inclusive:!1})}function Ur(e,t){return new Mt({check:`greater_than`,...M(t),value:e,inclusive:!0})}function Wr(e,t){return new Nt({check:`multiple_of`,...M(t),value:e})}function Gr(e,t){let n=new Ft({check:`max_length`,...M(t),maximum:e});return n}function Kr(e,t){return new It({check:`min_length`,...M(t),minimum:e})}function qr(e,t){return new Lt({check:`length_equals`,...M(t),length:e})}function Jr(e,t){return new zt({check:`string_format`,format:`regex`,...M(t),pattern:e})}function Yr(e){return new Bt({check:`string_format`,format:`lowercase`,...M(e)})}function Xr(e){return new Vt({check:`string_format`,format:`uppercase`,...M(e)})}function Zr(e,t){return new Ht({check:`string_format`,format:`includes`,...M(t),includes:e})}function Qr(e,t){return new Ut({check:`string_format`,format:`starts_with`,...M(t),prefix:e})}function $r(e,t){return new Wt({check:`string_format`,format:`ends_with`,...M(t),suffix:e})}function B(e){return new Gt({check:`overwrite`,tx:e})}function ei(e){return B(t=>t.normalize(e))}function ti(){return B(e=>e.trim())}function ni(){return B(e=>e.toLowerCase())}function ri(){return B(e=>e.toUpperCase())}function ii(e,t,n){return new e({type:`array`,element:t,...M(n)})}function ai(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...M(n)});return r}const oi=D(`ZodISODateTime`,(e,t)=>{sn.init(e,t),U.init(e,t)});function si(e){return jr(oi,e)}const ci=D(`ZodISODate`,(e,t)=>{cn.init(e,t),U.init(e,t)});function li(e){return Mr(ci,e)}const ui=D(`ZodISOTime`,(e,t)=>{ln.init(e,t),U.init(e,t)});function di(e){return Nr(ui,e)}const fi=D(`ZodISODuration`,(e,t)=>{un.init(e,t),U.init(e,t)});function pi(e){return Pr(fi,e)}const mi=(e,t)=>{Ve.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>We(e,t)},flatten:{value:t=>Ue(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})},hi=D(`ZodError`,mi),gi=D(`ZodError`,mi,{Parent:Error}),_i=Ge(gi),vi=qe(gi),yi=Ye(gi),bi=Ze(gi),V=D(`ZodType`,(e,t)=>(R.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>j(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>_i(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>yi(e,t,n),e.parseAsync=async(t,n)=>vi(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>bi(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(ka(t,n)),e.superRefine=t=>e.check(Aa(t)),e.overwrite=t=>e.check(B(t)),e.optional=()=>ua(e),e.nullable=()=>fa(e),e.nullish=()=>ua(fa(e)),e.nonoptional=t=>va(e,t),e.array=()=>Xi(e),e.or=t=>$i([e,t]),e.and=t=>ra(e,t),e.transform=t=>Sa(e,ca(t)),e.default=t=>ma(e,t),e.prefault=t=>ga(e,t),e.catch=t=>ba(e,t),e.pipe=t=>Sa(e,t),e.readonly=()=>wa(e),e.describe=t=>{let n=e.clone();return sr.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return sr.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return sr.get(e);let n=e.clone();return sr.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),xi=D(`_ZodString`,(e,t)=>{Jt.init(e,t),V.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Jr(...t)),e.includes=(...t)=>e.check(Zr(...t)),e.startsWith=(...t)=>e.check(Qr(...t)),e.endsWith=(...t)=>e.check($r(...t)),e.min=(...t)=>e.check(Kr(...t)),e.max=(...t)=>e.check(Gr(...t)),e.length=(...t)=>e.check(qr(...t)),e.nonempty=(...t)=>e.check(Kr(1,...t)),e.lowercase=t=>e.check(Yr(t)),e.uppercase=t=>e.check(Xr(t)),e.trim=()=>e.check(ti()),e.normalize=(...t)=>e.check(ei(...t)),e.toLowerCase=()=>e.check(ni()),e.toUpperCase=()=>e.check(ri())}),Si=D(`ZodString`,(e,t)=>{Jt.init(e,t),xi.init(e,t),e.email=t=>e.check(lr(Ci,t)),e.url=t=>e.check(hr(Ei,t)),e.jwt=t=>e.check(Ar(Vi,t)),e.emoji=t=>e.check(gr(Di,t)),e.guid=t=>e.check(ur(wi,t)),e.uuid=t=>e.check(dr(Ti,t)),e.uuidv4=t=>e.check(fr(Ti,t)),e.uuidv6=t=>e.check(pr(Ti,t)),e.uuidv7=t=>e.check(mr(Ti,t)),e.nanoid=t=>e.check(_r(Oi,t)),e.guid=t=>e.check(ur(wi,t)),e.cuid=t=>e.check(vr(ki,t)),e.cuid2=t=>e.check(yr(Ai,t)),e.ulid=t=>e.check(br(ji,t)),e.base64=t=>e.check(Dr(Ri,t)),e.base64url=t=>e.check(Or(zi,t)),e.xid=t=>e.check(xr(Mi,t)),e.ksuid=t=>e.check(Sr(Ni,t)),e.ipv4=t=>e.check(Cr(Pi,t)),e.ipv6=t=>e.check(wr(Fi,t)),e.cidrv4=t=>e.check(Tr(Ii,t)),e.cidrv6=t=>e.check(Er(Li,t)),e.e164=t=>e.check(kr(Bi,t)),e.datetime=t=>e.check(si(t)),e.date=t=>e.check(li(t)),e.time=t=>e.check(di(t)),e.duration=t=>e.check(pi(t))});function H(e){return cr(Si,e)}const U=D(`ZodStringFormat`,(e,t)=>{z.init(e,t),xi.init(e,t)}),Ci=D(`ZodEmail`,(e,t)=>{Zt.init(e,t),U.init(e,t)}),wi=D(`ZodGUID`,(e,t)=>{Yt.init(e,t),U.init(e,t)}),Ti=D(`ZodUUID`,(e,t)=>{Xt.init(e,t),U.init(e,t)}),Ei=D(`ZodURL`,(e,t)=>{Qt.init(e,t),U.init(e,t)}),Di=D(`ZodEmoji`,(e,t)=>{$t.init(e,t),U.init(e,t)}),Oi=D(`ZodNanoID`,(e,t)=>{en.init(e,t),U.init(e,t)}),ki=D(`ZodCUID`,(e,t)=>{tn.init(e,t),U.init(e,t)}),Ai=D(`ZodCUID2`,(e,t)=>{nn.init(e,t),U.init(e,t)}),ji=D(`ZodULID`,(e,t)=>{rn.init(e,t),U.init(e,t)}),Mi=D(`ZodXID`,(e,t)=>{an.init(e,t),U.init(e,t)}),Ni=D(`ZodKSUID`,(e,t)=>{on.init(e,t),U.init(e,t)}),Pi=D(`ZodIPv4`,(e,t)=>{dn.init(e,t),U.init(e,t)}),Fi=D(`ZodIPv6`,(e,t)=>{fn.init(e,t),U.init(e,t)}),Ii=D(`ZodCIDRv4`,(e,t)=>{pn.init(e,t),U.init(e,t)}),Li=D(`ZodCIDRv6`,(e,t)=>{mn.init(e,t),U.init(e,t)}),Ri=D(`ZodBase64`,(e,t)=>{gn.init(e,t),U.init(e,t)}),zi=D(`ZodBase64URL`,(e,t)=>{vn.init(e,t),U.init(e,t)}),Bi=D(`ZodE164`,(e,t)=>{yn.init(e,t),U.init(e,t)}),Vi=D(`ZodJWT`,(e,t)=>{xn.init(e,t),U.init(e,t)}),Hi=D(`ZodNumber`,(e,t)=>{Sn.init(e,t),V.init(e,t),e.gt=(t,n)=>e.check(Hr(t,n)),e.gte=(t,n)=>e.check(Ur(t,n)),e.min=(t,n)=>e.check(Ur(t,n)),e.lt=(t,n)=>e.check(Br(t,n)),e.lte=(t,n)=>e.check(Vr(t,n)),e.max=(t,n)=>e.check(Vr(t,n)),e.int=t=>e.check(Wi(t)),e.safe=t=>e.check(Wi(t)),e.positive=t=>e.check(Hr(0,t)),e.nonnegative=t=>e.check(Ur(0,t)),e.negative=t=>e.check(Br(0,t)),e.nonpositive=t=>e.check(Vr(0,t)),e.multipleOf=(t,n)=>e.check(Wr(t,n)),e.step=(t,n)=>e.check(Wr(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function W(e){return Fr(Hi,e)}const Ui=D(`ZodNumberFormat`,(e,t)=>{Cn.init(e,t),Hi.init(e,t)});function Wi(e){return Ir(Ui,e)}const Gi=D(`ZodBoolean`,(e,t)=>{wn.init(e,t),V.init(e,t)});function G(e){return Lr(Gi,e)}const Ki=D(`ZodUnknown`,(e,t)=>{Tn.init(e,t),V.init(e,t)});function K(){return Rr(Ki)}const qi=D(`ZodNever`,(e,t)=>{En.init(e,t),V.init(e,t)});function Ji(e){return zr(qi,e)}const Yi=D(`ZodArray`,(e,t)=>{On.init(e,t),V.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Kr(t,n)),e.nonempty=t=>e.check(Kr(1,t)),e.max=(t,n)=>e.check(Gr(t,n)),e.length=(t,n)=>e.check(qr(t,n)),e.unwrap=()=>e.element});function Xi(e,t){return ii(Yi,e,t)}const Zi=D(`ZodObject`,(e,t)=>{jn.init(e,t),V.init(e,t),k(e,`shape`,()=>t.shape),e.keyof=()=>Y(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:K()}),e.loose=()=>e.clone({...e._zod.def,catchall:K()}),e.strict=()=>e.clone({...e._zod.def,catchall:Ji()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Pe(e,t),e.merge=t=>Fe(e,t),e.pick=t=>Me(e,t),e.omit=t=>Ne(e,t),e.partial=(...t)=>Ie(la,e,t[0]),e.required=(...t)=>Le(_a,e,t[0])});function q(e,t){let n={type:`object`,get shape(){return Ce(this,`shape`,{...e}),this.shape},...M(t)};return new Zi(n)}const Qi=D(`ZodUnion`,(e,t)=>{Nn.init(e,t),V.init(e,t),e.options=t.options});function $i(e,t){return new Qi({type:`union`,options:e,...M(t)})}const ea=D(`ZodDiscriminatedUnion`,(e,t)=>{Qi.init(e,t),Pn.init(e,t)});function ta(e,t,n){return new ea({type:`union`,options:t,discriminator:e,...M(n)})}const na=D(`ZodIntersection`,(e,t)=>{Fn.init(e,t),V.init(e,t)});function ra(e,t){return new na({type:`intersection`,left:e,right:t})}const ia=D(`ZodRecord`,(e,t)=>{Rn.init(e,t),V.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function J(e,t,n){return new ia({type:`record`,keyType:e,valueType:t,...M(n)})}const aa=D(`ZodEnum`,(e,t)=>{zn.init(e,t),V.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new aa({...t,checks:[],...M(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new aa({...t,checks:[],...M(r),entries:i})}});function Y(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new aa({type:`enum`,entries:n,...M(t)})}const oa=D(`ZodLiteral`,(e,t)=>{Bn.init(e,t),V.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function X(e,t){return new oa({type:`literal`,values:Array.isArray(e)?e:[e],...M(t)})}const sa=D(`ZodTransform`,(e,t)=>{Vn.init(e,t),V.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(I(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(I(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function ca(e){return new sa({type:`transform`,transform:e})}const la=D(`ZodOptional`,(e,t)=>{Hn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ua(e){return new la({type:`optional`,innerType:e})}const da=D(`ZodNullable`,(e,t)=>{Un.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function fa(e){return new da({type:`nullable`,innerType:e})}const pa=D(`ZodDefault`,(e,t)=>{Wn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ma(e,t){return new pa({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const ha=D(`ZodPrefault`,(e,t)=>{Kn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ga(e,t){return new ha({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const _a=D(`ZodNonOptional`,(e,t)=>{qn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function va(e,t){return new _a({type:`nonoptional`,innerType:e,...M(t)})}const ya=D(`ZodCatch`,(e,t)=>{Yn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ba(e,t){return new ya({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const xa=D(`ZodPipe`,(e,t)=>{Xn.init(e,t),V.init(e,t),e.in=t.in,e.out=t.out});function Sa(e,t){return new xa({type:`pipe`,in:e,out:t})}const Ca=D(`ZodReadonly`,(e,t)=>{Qn.init(e,t),V.init(e,t)});function wa(e){return new Ca({type:`readonly`,innerType:e})}const Ta=D(`ZodLazy`,(e,t)=>{er.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.getter()});function Ea(e){return new Ta({type:`lazy`,getter:e})}const Da=D(`ZodCustom`,(e,t)=>{tr.init(e,t),V.init(e,t)});function Oa(e){let t=new L({check:`custom`});return t._zod.check=e,t}function ka(e,t={}){return ai(Da,e,t)}function Aa(e){let t=Oa(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(I(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(I(r))}},e(n.value,n)));return t}const ja=q({r:J(H(),q({n:W().optional().nullable(),c:H().optional().nullable(),p:W().optional().nullable()})),v:W(),t:W()}),Ma=q({remote:J(H(),q({pageNumber:W().optional(),providerPageCursor:H().optional(),position:W().optional()})),version:W(),timestamp:W()}),Na=e=>(0,c.encodeToBase64)(JSON.stringify(Pa(e))),Pa=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},Fa=e=>{try{if((0,c.isString)(e)){let t=(0,c.decodeFromBase64)(e),n=JSON.parse(t),r=ja.parse(n);return Ia(r)}else return Ma.parse(e),e}catch{return null}},Ia=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},La=(e,t)=>{let n=typeof e==`string`?Fa(e):e,r=typeof t==`string`?Fa(t):t;if(n===null||r===null)return n===r;let{timestamp:i,...a}=n,{timestamp:o,...s}=r;return(0,c.getContentHash)(a)===(0,c.getContentHash)(s)},Ra=({cursor:e,ignoreStepIndex:t})=>(0,c.isMissing)(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return((0,c.isMissing)(t)||r!==t.toString())&&(n=n&&(0,c.isMissing)(i.pageNumber)&&(0,c.isMissing)(i.position)&&(0,c.isMissing)(i.providerPageCursor)),n},!0),za=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=(0,c.isMissing)(n)&&(0,c.isMissing)(r)&&(0,c.isMissing)(i);return(0,c.isMissing)(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},Ba=e=>e instanceof b,Va=q({stepsDataToGroup:Xi(H()),isSingleRecord:G().optional()}),Ha=q({data:K()}),Ua=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=Va.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=(0,c.notMissing)(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},Wa=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=Ga(r,a,i),s=Ka(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=Ka(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},Ga=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),Ka=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=qa(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},qa=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=(0,l.evaluate)(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},Ja=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return c.getCountryAlpha2CodeByAlpha2Code;case`country_alpha3code_by_alpha3code`:return c.getCountryAlpha3CodeByAlpha3Code;case`country_code_by_country_code`:return c.getCountryCodeByCountryCode;case`country_name_by_country_name`:return c.getCountryNameByCountryName;case`country_name_by_alpha3code`:return c.getCountryNameByAlpha3Code;case`country_name_by_alpha2code`:return c.getCountryNameByAlpha2Code;case`country_name_by_country_code`:return c.getCountryNameByCountryCode;case`country_alpha3code_by_alpha2code`:return c.getCountryAlpha3CodeByAlpha2Code;case`country_alpha3code_by_country_name`:return c.getCountryAlpha3CodeByCountryName;case`country_alpha3code_by_country_code`:return c.getCountryAlpha3CodeByCountryCode;case`country_alpha2code_by_alpha3code`:return c.getCountryAlpha2CodeByAlpha3Code;case`country_alpha2code_by_country_name`:return c.getCountryAlpha2CodeByCountryName;case`country_alpha2code_by_country_code`:return c.getCountryAlpha2CodeByCountryCode;case`country_code_by_alpha2code`:return c.getCountryCodeByAlpha2Code;case`country_code_by_alpha3code`:return c.getCountryCodeByAlpha3Code;case`country_code_by_country_name`:return c.getCountryCodeByCountryName;case`country_subdivisions_by_alpha2code`:return c.getCountrySubDivisionsByAlpha2Code;case`country_subdivision_code_by_subdivision_name`:return c.getCountrySubDivisionCodeBySubDivisionName;case`country_alpha2code_by_citizenship`:return c.getCountryAlpha2CodeByCitizenship;case`country_subdivision_name_by_subdivision_code`:return c.getCountrySubDivisionNameBySubDivisionCode;default:return}},Ya=q({targetFieldKey:H(),alias:H().optional(),expression:H().optional(),values:K().optional(),type:Y([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:G().default(!1),custom:G().default(!1),hidden:G().default(!1),enumMapper:q({matcher:H().or(q({matchExpression:H(),value:H()}).array())}).optional(),properties:Ea(()=>Ya).array().optional()}),Xa=q({fields:Ya.array(),dataSource:H()}),Za=q({data:K()}),Qa=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i}=Xa.parse(t),a=(0,l.evaluate)(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!a)return{block:e,successful:!0};let o;if(Array.isArray(a))o=a.map(e=>{let t=Z(r,e);return n.push(...t?.errors||[]),t?.record});else{let e=Z(r,a);o=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:o},errors:Object.keys(n).length>0?n:void 0}},$a=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=ro(r,t),a=Z(e.properties,i);return(0,c.notMissing)(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},eo=(e,t,n)=>{if(e.expression)try{let r=(0,l.evaluate)(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=Z(e.properties,t);return(0,c.notMissing)(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=Z(e.properties,r);return(0,c.notMissing)(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},to=(e,t,n)=>{let r=(0,c.notMissing)(e.values)?e.values:t,i=Z(e.properties,r);return(0,c.notMissing)(i?.errors)&&n.push(...i.errors),i?.record},no=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?$a(e,t,n):e.array&&e.expression?eo(e,t,n):to(e,t,n)},Z=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=no(a,t,r),e===void 0)continue}else{let{error:n,value:i}=io(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:r.length>0?r:void 0}},ro=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if((0,l.isValidExpression)(e))try{return(0,l.evaluate)(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>ro(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=ro(r,t);return n}return e},io=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return ao(n,t,e);case`enum`:return oo(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},ao=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=(0,l.evaluate)(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},oo=(e,t,n)=>{let r=ao(e,t,n),i=(0,c.notMissing)(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if((0,c.isString)(a)){let n=Ja(a);if((0,c.notMissing)(n)){let e=(0,c.notMissing)(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=(0,l.evaluate)(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},so=q({type:X(`basic`),username:H().optional(),password:H().optional(),encoding:H().optional()}),co=q({type:X(`bearer`),token:H(),includeBearer:G().optional().default(!0)}),lo=q({type:X(`oauth2`),authorizationUrl:H().optional(),authorizationParams:J(H(),H()).optional(),tokenUrl:H().optional(),tokenParams:J(H(),H()).optional(),tokenExpiresIn:W().optional(),tokenRefreshExpiresIn:W().optional(),token:H(),includeBearer:G().optional().default(!0),scopes:H().optional()}),uo=ta(`type`,[so,co,lo]),fo=q({baseUrl:H(),url:H(),method:Y(u.HttpMethods),response:q({indexField:H().optional(),dataKey:H().optional(),nextKey:H().optional()}).optional(),iterator:q({key:H(),in:Y(u.RequestParameterLocations)}),cursor:q({token:H().optional().nullable(),position:W().optional().nullable()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:q({name:H(),value:K(),in:Y(u.RequestParameterLocations),condition:H().optional()}).array().optional()}),po=q({data:K().optional(),raw:K().optional(),statusCode:W(),message:H().optional(),next:H().optional().nullable(),position:W().optional()}).optional(),mo=25,ho=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?mo:i,o=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?(0,l.safeEvaluateRecord)({...t,args:o},e):{},d={...s,customErrors:t?.customErrors},{baseUrl:f,url:p,method:m,response:h,iterator:g,cursor:_,customErrors:v,args:ee}=fo.parse(d),y=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=uo.parse(y),x=ee?(0,u.parseRequestParameters)(ee):{query:{},body:{},headers:{}},te=(0,u.createAuthorizationHeaders)(b),ne={...x?.headers??{},...te},S=_?.token??null,C=null,re=null,w=[],T=[],ie=[],ae=a,E=_?.position??0,oe=!0,se=!0;do{oe?oe=!1:E=0,S!==null&&(g.in===`query`?x.query[g.key]=S.toString():g.in===`body`&&(x.body[g.key]=S));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${f}${p}`,queryParams:x?.query,method:m,headers:ne,body:x?.body,customErrorConfigs:v})}catch(t){let n=t;return{block:e,successful:!1,errors:[t],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}C=S,T=h?.dataKey?t.data[h?.dataKey]:t.data;let r=T?.slice(E,ae);ae-=r.length,E+=r.length,ie.push(t),w=w.concat(r),re=t?.status,S=h?.nextKey?t.data[h?.nextKey]:void 0,r.length===T.length&&ae===0&&(E=0,C=S),se=(0,c.isMissing)(S)&&w.length<a}while((0,c.notMissing)(S)&&w.length<a&&T?.length>0);let ce=go(w,h);return{block:e,successful:!0,output:{data:ce,raw:ie,statusCode:re,next:se?void 0:C,position:se?void 0:E}}},go=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},_o=q({type:X(`basic`),username:H().optional(),password:H().optional(),encoding:H().optional()}),vo=q({type:X(`bearer`),token:H(),includeBearer:G().optional().default(!0)}),yo=q({type:X(`oauth2`),authorizationUrl:H().optional(),authorizationParams:J(H(),H()).optional(),tokenUrl:H().optional(),tokenParams:J(H(),H()).optional(),tokenExpiresIn:W().optional(),tokenRefreshExpiresIn:W().optional(),token:H(),includeBearer:G().optional().default(!0),scopes:H().optional()}),bo=ta(`type`,[_o,vo,yo]),xo=q({baseUrl:H(),url:H(),method:Y(u.HttpMethods),authorization:bo.optional(),response:q({collection:G().optional(),indexField:H().optional(),dataKey:H().optional()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:q({name:H(),value:K(),in:Y(u.RequestParameterLocations),condition:H().optional()}).array().optional()}),So=q({data:K().optional(),raw:K().optional(),statusCode:W(),message:H().optional()}).optional(),Co=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?(0,l.safeEvaluateRecord)({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:d,method:f,response:p,authorization:m,customErrors:h,args:g}=xo.parse(o),_=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=g?(0,u.parseRequestParameters)(g):{query:{},body:{},headers:{}},ee=(0,c.notMissing)(m)?m:bo.parse(_),y=(0,u.createAuthorizationHeaders)(ee),b={...v?.headers??{},...y},x;try{x=await n.performRequest({httpClient:e.httpClient,url:`${s}${d}`,queryParams:v?.query,method:f,headers:b,body:v?.body,customErrorConfigs:h})}catch(t){let n=t;return{block:e,successful:!1,errors:[t],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let te=p?.dataKey?x.data[p?.dataKey]:x.data,ne=wo(te,p);return{block:e,successful:!0,output:{data:ne,raw:x,statusCode:x?.status,message:x?.message}}},wo=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},To=q({targetFieldKey:H(),type:Y([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:G().default(!1),custom:G().default(!1),hidden:G().default(!1),properties:Ea(()=>To).array().optional()}),Eo=q({fields:To.array().optional(),dataSource:H()}),Do=q({data:K()});let Q=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Oo=({value:e,type:t,format:n})=>{if((0,c.isMissing)(e))return null;switch(t){case Q.String:return(0,c.safeParseToString)({value:e});case Q.Number:return(0,c.safeParseToNumber)({value:e});case Q.Boolean:return(0,c.safeParseToBoolean)({value:e});case Q.DateTimeString:return(0,c.safeParseToDateTimeString)({value:e,format:n});default:return e}},ko=e=>{let t=Object.values(Q);return t.includes(e)},Ao=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>jo(e,t)):jo(e.result,t),{block:{...e,result:n},successful:!0}},jo=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;ko(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=Oo({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Oo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},Mo=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Eo.parse(t),i=(0,l.evaluate)(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Po(e,n)):Po(i,n),{block:{...e},successful:!0,output:{data:a}}},No=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Po(t,e.properties):t):typeof t==`object`&&t?Po(t,e.properties):t,Po=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;i===`object`?!t.custom&&(0,c.notMissing)(n[r])?n[r]=No(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=No(t,e.unified_custom_fields?.[r])):ko(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=Oo({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Oo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e}({});const Fo={[$.TYPECAST]:{v1:{fn:Ao},v2:{fn:Mo,inputSchema:Eo,outputSchema:Do}},[$.MAP_FIELDS]:{v1:{fn:Wa},v2:{fn:Qa,inputSchema:Xa,outputSchema:Za}},[$.REQUEST]:{v1:{fn:Co,inputSchema:xo,outputSchema:So}},[$.GROUP_DATA]:{v1:{fn:Ua,inputSchema:Va,outputSchema:Ha}},[$.PAGINATED_REQUEST]:{v1:{fn:ho,inputSchema:fo,outputSchema:po}}},Io=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch{return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},Lo={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=Fo}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:Io(i,e)}:i}};exports.AUTHENTICATION_SCHEMA=bo,exports.COMPOSITE_ID_LATEST_VERSION=y,exports.CoreError=b,exports.StepFunctionName=$,exports.StepFunctionsFactory=Lo,exports.areCursorsEqual=La,exports.decodeCompositeId=ie,exports.encodeCompositeId=T,exports.expandCursor=Fa,exports.getCategoryDetails=f,exports.isCompositeId=fe,exports.isCoreError=Ba,exports.isCursorEmpty=Ra,exports.isValidCategory=p,exports.minifyCursor=Na,exports.updateCursor=za;
26
+ })));`),t.write(`newResult[${we(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=Ee,o=!ge.jitless,s=De,c=o&&s.value,l=t.catchall,u;e._zod.parse=(s,d)=>{u??=n.value;let f=s.value;if(!a(f))return s.issues.push({expected:`object`,code:`invalid_type`,input:f,inst:e}),s;let p=[];if(o&&c&&d?.async===!1&&d.jitless!==!0)i||=r(t.shape),s=i(s,d);else{s.value={};let e=u.shape;for(let t of u.keys){let n=e[t],r=n._zod.run({value:f[t],issues:[]},d),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?p.push(r.then(e=>i?An(e,s,t,f):kn(e,s,t))):i?An(r,s,t,f):kn(r,s,t)}}if(!l)return p.length?Promise.all(p).then(()=>s):s;let m=[],h=u.keySet,g=l._zod,_=g.def.type;for(let e of Object.keys(f)){if(h.has(e))continue;if(_===`never`){m.push(e);continue}let t=g.run({value:f[e],issues:[]},d);t instanceof Promise?p.push(t.then(t=>kn(t,s,e))):kn(t,s,e)}return m.length&&s.issues.push({code:`unrecognized_keys`,keys:m,input:f,inst:e}),p.length?Promise.all(p).then(()=>s):s}});function Mn(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>F(e,r,O())))}),t}const Nn=D(`$ZodUnion`,(e,t)=>{R.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>xe(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>Mn(t,n,e,r)):Mn(a,n,e,r)}}),Pn=D(`$ZodDiscriminatedUnion`,(e,t)=>{Nn.init(e,t);let n=e._zod.parse;k(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=ye(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!Ee(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,input:o,path:[t.discriminator],inst:e}),i)}}),Fn=D(`$ZodIntersection`,(e,t)=>{R.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>Ln(e,t,n)):Ln(e,i,a)}});function In(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Oe(e)&&Oe(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=In(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=In(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Ln(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),N(e))return e;let r=In(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Rn=D(`$ZodRecord`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Oe(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...P(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...P(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({origin:`record`,code:`invalid_key`,issues:s.issues.map(e=>F(e,r,O())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...P(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...P(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),zn=D(`$ZodEnum`,(e,t)=>{R.init(e,t);let n=_e(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>ke.has(typeof e)).map(e=>typeof e==`string`?A(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),Bn=D(`$ZodLiteral`,(e,t)=>{R.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?A(e):e?e.toString():String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),Vn=D(`$ZodTransform`,(e,t)=>{R.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new he;return e.value=r,e}}),Hn=D(`$ZodOptional`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${xe(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),Un=D(`$ZodNullable`,(e,t)=>{R.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${xe(e.source)}|null)$`):void 0}),k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Wn=D(`$ZodDefault`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Gn(e,t)):Gn(r,t)}});function Gn(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Kn=D(`$ZodPrefault`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),qn=D(`$ZodNonOptional`,(e,t)=>{R.init(e,t),k(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Jn(t,e)):Jn(i,e)}});function Jn(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Yn=D(`$ZodCatch`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,O()))},input:e.value}),e.issues=[]),e)}}),Xn=D(`$ZodPipe`,(e,t)=>{R.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Zn(e,t,n)):Zn(r,t,n)}});function Zn(e,t,n){return N(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Qn=D(`$ZodReadonly`,(e,t)=>{R.init(e,t),k(e._zod,`propValues`,()=>t.innerType._zod.propValues),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then($n):$n(r)}});function $n(e){return e.value=Object.freeze(e.value),e}const er=D(`$ZodLazy`,(e,t)=>{R.init(e,t),k(e._zod,`innerType`,()=>t.getter()),k(e._zod,`pattern`,()=>e._zod.innerType._zod.pattern),k(e._zod,`propValues`,()=>e._zod.innerType._zod.propValues),k(e._zod,`optin`,()=>e._zod.innerType._zod.optin),k(e._zod,`optout`,()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>{let r=e._zod.innerType;return r._zod.run(t,n)}}),tr=D(`$ZodCustom`,(e,t)=>{L.init(e,t),R.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>nr(t,n,r,e));nr(i,n,r,e)}});function nr(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(I(e))}}const rr=Symbol(`ZodOutput`),ir=Symbol(`ZodInput`);var ar=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function or(){return new ar}const sr=or();function cr(e,t){return new e({type:`string`,...M(t)})}function lr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...M(t)})}function ur(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...M(t)})}function dr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...M(t)})}function fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...M(t)})}function pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...M(t)})}function mr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...M(t)})}function hr(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...M(t)})}function gr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...M(t)})}function _r(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...M(t)})}function vr(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...M(t)})}function yr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...M(t)})}function br(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...M(t)})}function xr(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...M(t)})}function Sr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...M(t)})}function Cr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...M(t)})}function wr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...M(t)})}function Tr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...M(t)})}function Er(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...M(t)})}function Dr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...M(t)})}function Or(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...M(t)})}function kr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...M(t)})}function Ar(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...M(t)})}function jr(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...M(t)})}function Mr(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...M(t)})}function Nr(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...M(t)})}function Pr(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...M(t)})}function Fr(e,t){return new e({type:`number`,checks:[],...M(t)})}function Ir(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...M(t)})}function Lr(e,t){return new e({type:`boolean`,...M(t)})}function Rr(e){return new e({type:`unknown`})}function zr(e,t){return new e({type:`never`,...M(t)})}function Br(e,t){return new jt({check:`less_than`,...M(t),value:e,inclusive:!1})}function Vr(e,t){return new jt({check:`less_than`,...M(t),value:e,inclusive:!0})}function Hr(e,t){return new Mt({check:`greater_than`,...M(t),value:e,inclusive:!1})}function Ur(e,t){return new Mt({check:`greater_than`,...M(t),value:e,inclusive:!0})}function Wr(e,t){return new Nt({check:`multiple_of`,...M(t),value:e})}function Gr(e,t){let n=new Ft({check:`max_length`,...M(t),maximum:e});return n}function Kr(e,t){return new It({check:`min_length`,...M(t),minimum:e})}function qr(e,t){return new Lt({check:`length_equals`,...M(t),length:e})}function Jr(e,t){return new zt({check:`string_format`,format:`regex`,...M(t),pattern:e})}function Yr(e){return new Bt({check:`string_format`,format:`lowercase`,...M(e)})}function Xr(e){return new Vt({check:`string_format`,format:`uppercase`,...M(e)})}function Zr(e,t){return new Ht({check:`string_format`,format:`includes`,...M(t),includes:e})}function Qr(e,t){return new Ut({check:`string_format`,format:`starts_with`,...M(t),prefix:e})}function $r(e,t){return new Wt({check:`string_format`,format:`ends_with`,...M(t),suffix:e})}function B(e){return new Gt({check:`overwrite`,tx:e})}function ei(e){return B(t=>t.normalize(e))}function ti(){return B(e=>e.trim())}function ni(){return B(e=>e.toLowerCase())}function ri(){return B(e=>e.toUpperCase())}function ii(e,t,n){return new e({type:`array`,element:t,...M(n)})}function ai(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...M(n)});return r}const oi=D(`ZodISODateTime`,(e,t)=>{sn.init(e,t),U.init(e,t)});function si(e){return jr(oi,e)}const ci=D(`ZodISODate`,(e,t)=>{cn.init(e,t),U.init(e,t)});function li(e){return Mr(ci,e)}const ui=D(`ZodISOTime`,(e,t)=>{ln.init(e,t),U.init(e,t)});function di(e){return Nr(ui,e)}const fi=D(`ZodISODuration`,(e,t)=>{un.init(e,t),U.init(e,t)});function pi(e){return Pr(fi,e)}const mi=(e,t)=>{Ve.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>We(e,t)},flatten:{value:t=>Ue(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})},hi=D(`ZodError`,mi),gi=D(`ZodError`,mi,{Parent:Error}),_i=Ge(gi),vi=qe(gi),yi=Ye(gi),bi=Ze(gi),V=D(`ZodType`,(e,t)=>(R.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>j(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>_i(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>yi(e,t,n),e.parseAsync=async(t,n)=>vi(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>bi(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(ka(t,n)),e.superRefine=t=>e.check(Aa(t)),e.overwrite=t=>e.check(B(t)),e.optional=()=>ua(e),e.nullable=()=>fa(e),e.nullish=()=>ua(fa(e)),e.nonoptional=t=>va(e,t),e.array=()=>Xi(e),e.or=t=>$i([e,t]),e.and=t=>ra(e,t),e.transform=t=>Sa(e,ca(t)),e.default=t=>ma(e,t),e.prefault=t=>ga(e,t),e.catch=t=>ba(e,t),e.pipe=t=>Sa(e,t),e.readonly=()=>wa(e),e.describe=t=>{let n=e.clone();return sr.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return sr.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return sr.get(e);let n=e.clone();return sr.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),xi=D(`_ZodString`,(e,t)=>{Jt.init(e,t),V.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Jr(...t)),e.includes=(...t)=>e.check(Zr(...t)),e.startsWith=(...t)=>e.check(Qr(...t)),e.endsWith=(...t)=>e.check($r(...t)),e.min=(...t)=>e.check(Kr(...t)),e.max=(...t)=>e.check(Gr(...t)),e.length=(...t)=>e.check(qr(...t)),e.nonempty=(...t)=>e.check(Kr(1,...t)),e.lowercase=t=>e.check(Yr(t)),e.uppercase=t=>e.check(Xr(t)),e.trim=()=>e.check(ti()),e.normalize=(...t)=>e.check(ei(...t)),e.toLowerCase=()=>e.check(ni()),e.toUpperCase=()=>e.check(ri())}),Si=D(`ZodString`,(e,t)=>{Jt.init(e,t),xi.init(e,t),e.email=t=>e.check(lr(Ci,t)),e.url=t=>e.check(hr(Ei,t)),e.jwt=t=>e.check(Ar(Vi,t)),e.emoji=t=>e.check(gr(Di,t)),e.guid=t=>e.check(ur(wi,t)),e.uuid=t=>e.check(dr(Ti,t)),e.uuidv4=t=>e.check(fr(Ti,t)),e.uuidv6=t=>e.check(pr(Ti,t)),e.uuidv7=t=>e.check(mr(Ti,t)),e.nanoid=t=>e.check(_r(Oi,t)),e.guid=t=>e.check(ur(wi,t)),e.cuid=t=>e.check(vr(ki,t)),e.cuid2=t=>e.check(yr(Ai,t)),e.ulid=t=>e.check(br(ji,t)),e.base64=t=>e.check(Dr(Ri,t)),e.base64url=t=>e.check(Or(zi,t)),e.xid=t=>e.check(xr(Mi,t)),e.ksuid=t=>e.check(Sr(Ni,t)),e.ipv4=t=>e.check(Cr(Pi,t)),e.ipv6=t=>e.check(wr(Fi,t)),e.cidrv4=t=>e.check(Tr(Ii,t)),e.cidrv6=t=>e.check(Er(Li,t)),e.e164=t=>e.check(kr(Bi,t)),e.datetime=t=>e.check(si(t)),e.date=t=>e.check(li(t)),e.time=t=>e.check(di(t)),e.duration=t=>e.check(pi(t))});function H(e){return cr(Si,e)}const U=D(`ZodStringFormat`,(e,t)=>{z.init(e,t),xi.init(e,t)}),Ci=D(`ZodEmail`,(e,t)=>{Zt.init(e,t),U.init(e,t)}),wi=D(`ZodGUID`,(e,t)=>{Yt.init(e,t),U.init(e,t)}),Ti=D(`ZodUUID`,(e,t)=>{Xt.init(e,t),U.init(e,t)}),Ei=D(`ZodURL`,(e,t)=>{Qt.init(e,t),U.init(e,t)}),Di=D(`ZodEmoji`,(e,t)=>{$t.init(e,t),U.init(e,t)}),Oi=D(`ZodNanoID`,(e,t)=>{en.init(e,t),U.init(e,t)}),ki=D(`ZodCUID`,(e,t)=>{tn.init(e,t),U.init(e,t)}),Ai=D(`ZodCUID2`,(e,t)=>{nn.init(e,t),U.init(e,t)}),ji=D(`ZodULID`,(e,t)=>{rn.init(e,t),U.init(e,t)}),Mi=D(`ZodXID`,(e,t)=>{an.init(e,t),U.init(e,t)}),Ni=D(`ZodKSUID`,(e,t)=>{on.init(e,t),U.init(e,t)}),Pi=D(`ZodIPv4`,(e,t)=>{dn.init(e,t),U.init(e,t)}),Fi=D(`ZodIPv6`,(e,t)=>{fn.init(e,t),U.init(e,t)}),Ii=D(`ZodCIDRv4`,(e,t)=>{pn.init(e,t),U.init(e,t)}),Li=D(`ZodCIDRv6`,(e,t)=>{mn.init(e,t),U.init(e,t)}),Ri=D(`ZodBase64`,(e,t)=>{gn.init(e,t),U.init(e,t)}),zi=D(`ZodBase64URL`,(e,t)=>{vn.init(e,t),U.init(e,t)}),Bi=D(`ZodE164`,(e,t)=>{yn.init(e,t),U.init(e,t)}),Vi=D(`ZodJWT`,(e,t)=>{xn.init(e,t),U.init(e,t)}),Hi=D(`ZodNumber`,(e,t)=>{Sn.init(e,t),V.init(e,t),e.gt=(t,n)=>e.check(Hr(t,n)),e.gte=(t,n)=>e.check(Ur(t,n)),e.min=(t,n)=>e.check(Ur(t,n)),e.lt=(t,n)=>e.check(Br(t,n)),e.lte=(t,n)=>e.check(Vr(t,n)),e.max=(t,n)=>e.check(Vr(t,n)),e.int=t=>e.check(Wi(t)),e.safe=t=>e.check(Wi(t)),e.positive=t=>e.check(Hr(0,t)),e.nonnegative=t=>e.check(Ur(0,t)),e.negative=t=>e.check(Br(0,t)),e.nonpositive=t=>e.check(Vr(0,t)),e.multipleOf=(t,n)=>e.check(Wr(t,n)),e.step=(t,n)=>e.check(Wr(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function W(e){return Fr(Hi,e)}const Ui=D(`ZodNumberFormat`,(e,t)=>{Cn.init(e,t),Hi.init(e,t)});function Wi(e){return Ir(Ui,e)}const Gi=D(`ZodBoolean`,(e,t)=>{wn.init(e,t),V.init(e,t)});function G(e){return Lr(Gi,e)}const Ki=D(`ZodUnknown`,(e,t)=>{Tn.init(e,t),V.init(e,t)});function K(){return Rr(Ki)}const qi=D(`ZodNever`,(e,t)=>{En.init(e,t),V.init(e,t)});function Ji(e){return zr(qi,e)}const Yi=D(`ZodArray`,(e,t)=>{On.init(e,t),V.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Kr(t,n)),e.nonempty=t=>e.check(Kr(1,t)),e.max=(t,n)=>e.check(Gr(t,n)),e.length=(t,n)=>e.check(qr(t,n)),e.unwrap=()=>e.element});function Xi(e,t){return ii(Yi,e,t)}const Zi=D(`ZodObject`,(e,t)=>{jn.init(e,t),V.init(e,t),k(e,`shape`,()=>t.shape),e.keyof=()=>Y(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:K()}),e.loose=()=>e.clone({...e._zod.def,catchall:K()}),e.strict=()=>e.clone({...e._zod.def,catchall:Ji()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Pe(e,t),e.merge=t=>Fe(e,t),e.pick=t=>Me(e,t),e.omit=t=>Ne(e,t),e.partial=(...t)=>Ie(la,e,t[0]),e.required=(...t)=>Le(_a,e,t[0])});function q(e,t){let n={type:`object`,get shape(){return Ce(this,`shape`,{...e}),this.shape},...M(t)};return new Zi(n)}const Qi=D(`ZodUnion`,(e,t)=>{Nn.init(e,t),V.init(e,t),e.options=t.options});function $i(e,t){return new Qi({type:`union`,options:e,...M(t)})}const ea=D(`ZodDiscriminatedUnion`,(e,t)=>{Qi.init(e,t),Pn.init(e,t)});function ta(e,t,n){return new ea({type:`union`,options:t,discriminator:e,...M(n)})}const na=D(`ZodIntersection`,(e,t)=>{Fn.init(e,t),V.init(e,t)});function ra(e,t){return new na({type:`intersection`,left:e,right:t})}const ia=D(`ZodRecord`,(e,t)=>{Rn.init(e,t),V.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function J(e,t,n){return new ia({type:`record`,keyType:e,valueType:t,...M(n)})}const aa=D(`ZodEnum`,(e,t)=>{zn.init(e,t),V.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new aa({...t,checks:[],...M(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new aa({...t,checks:[],...M(r),entries:i})}});function Y(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new aa({type:`enum`,entries:n,...M(t)})}const oa=D(`ZodLiteral`,(e,t)=>{Bn.init(e,t),V.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function X(e,t){return new oa({type:`literal`,values:Array.isArray(e)?e:[e],...M(t)})}const sa=D(`ZodTransform`,(e,t)=>{Vn.init(e,t),V.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(I(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(I(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function ca(e){return new sa({type:`transform`,transform:e})}const la=D(`ZodOptional`,(e,t)=>{Hn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ua(e){return new la({type:`optional`,innerType:e})}const da=D(`ZodNullable`,(e,t)=>{Un.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function fa(e){return new da({type:`nullable`,innerType:e})}const pa=D(`ZodDefault`,(e,t)=>{Wn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ma(e,t){return new pa({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const ha=D(`ZodPrefault`,(e,t)=>{Kn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ga(e,t){return new ha({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const _a=D(`ZodNonOptional`,(e,t)=>{qn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType});function va(e,t){return new _a({type:`nonoptional`,innerType:e,...M(t)})}const ya=D(`ZodCatch`,(e,t)=>{Yn.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ba(e,t){return new ya({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const xa=D(`ZodPipe`,(e,t)=>{Xn.init(e,t),V.init(e,t),e.in=t.in,e.out=t.out});function Sa(e,t){return new xa({type:`pipe`,in:e,out:t})}const Ca=D(`ZodReadonly`,(e,t)=>{Qn.init(e,t),V.init(e,t)});function wa(e){return new Ca({type:`readonly`,innerType:e})}const Ta=D(`ZodLazy`,(e,t)=>{er.init(e,t),V.init(e,t),e.unwrap=()=>e._zod.def.getter()});function Ea(e){return new Ta({type:`lazy`,getter:e})}const Da=D(`ZodCustom`,(e,t)=>{tr.init(e,t),V.init(e,t)});function Oa(e){let t=new L({check:`custom`});return t._zod.check=e,t}function ka(e,t={}){return ai(Da,e,t)}function Aa(e){let t=Oa(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(I(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(I(r))}},e(n.value,n)));return t}const ja=q({r:J(H(),q({n:W().optional().nullable(),c:H().optional().nullable(),p:W().optional().nullable()})),v:W(),t:W()}),Ma=q({remote:J(H(),q({pageNumber:W().optional(),providerPageCursor:H().optional(),position:W().optional()})),version:W(),timestamp:W()}),Na=e=>(0,c.encodeToBase64)(JSON.stringify(Pa(e))),Pa=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},Fa=e=>{try{if((0,c.isString)(e)){let t=(0,c.decodeFromBase64)(e),n=JSON.parse(t),r=ja.parse(n);return Ia(r)}else return Ma.parse(e),e}catch{return null}},Ia=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},La=(e,t)=>{let n=typeof e==`string`?Fa(e):e,r=typeof t==`string`?Fa(t):t;if(n===null||r===null)return n===r;let{timestamp:i,...a}=n,{timestamp:o,...s}=r;return(0,c.getContentHash)(a)===(0,c.getContentHash)(s)},Ra=({cursor:e,ignoreStepIndex:t})=>(0,c.isMissing)(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return((0,c.isMissing)(t)||r!==t.toString())&&(n=n&&(0,c.isMissing)(i.pageNumber)&&(0,c.isMissing)(i.position)&&(0,c.isMissing)(i.providerPageCursor)),n},!0),za=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=(0,c.isMissing)(n)&&(0,c.isMissing)(r)&&(0,c.isMissing)(i);return(0,c.isMissing)(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},Ba=e=>e instanceof b,Va=q({stepsDataToGroup:Xi(H()),isSingleRecord:G().optional()}),Ha=q({data:K()}),Ua=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=Va.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=(0,c.notMissing)(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},Wa=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=Ga(r,a,i),s=Ka(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=Ka(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},Ga=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),Ka=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=qa(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},qa=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=(0,l.evaluate)(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},Ja=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return c.getCountryAlpha2CodeByAlpha2Code;case`country_alpha3code_by_alpha3code`:return c.getCountryAlpha3CodeByAlpha3Code;case`country_code_by_country_code`:return c.getCountryCodeByCountryCode;case`country_name_by_country_name`:return c.getCountryNameByCountryName;case`country_name_by_alpha3code`:return c.getCountryNameByAlpha3Code;case`country_name_by_alpha2code`:return c.getCountryNameByAlpha2Code;case`country_name_by_country_code`:return c.getCountryNameByCountryCode;case`country_alpha3code_by_alpha2code`:return c.getCountryAlpha3CodeByAlpha2Code;case`country_alpha3code_by_country_name`:return c.getCountryAlpha3CodeByCountryName;case`country_alpha3code_by_country_code`:return c.getCountryAlpha3CodeByCountryCode;case`country_alpha2code_by_alpha3code`:return c.getCountryAlpha2CodeByAlpha3Code;case`country_alpha2code_by_country_name`:return c.getCountryAlpha2CodeByCountryName;case`country_alpha2code_by_country_code`:return c.getCountryAlpha2CodeByCountryCode;case`country_code_by_alpha2code`:return c.getCountryCodeByAlpha2Code;case`country_code_by_alpha3code`:return c.getCountryCodeByAlpha3Code;case`country_code_by_country_name`:return c.getCountryCodeByCountryName;case`country_subdivisions_by_alpha2code`:return c.getCountrySubDivisionsByAlpha2Code;case`country_subdivision_code_by_subdivision_name`:return c.getCountrySubDivisionCodeBySubDivisionName;case`country_alpha2code_by_citizenship`:return c.getCountryAlpha2CodeByCitizenship;case`country_subdivision_name_by_subdivision_code`:return c.getCountrySubDivisionNameBySubDivisionCode;default:return}},Ya=q({targetFieldKey:H(),alias:H().optional(),expression:H().optional(),values:K().optional(),type:Y([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:G().default(!1),custom:G().default(!1),hidden:G().default(!1),enumMapper:q({matcher:H().or(q({matchExpression:H(),value:H()}).array())}).optional(),properties:Ea(()=>Ya).array().optional()}),Xa=q({fields:Ya.array(),dataSource:H()}),Za=q({data:K()}),Qa=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i}=Xa.parse(t),a=(0,l.evaluate)(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!a)return{block:e,successful:!0};let o;if(Array.isArray(a))o=a.map(e=>{let t=Z(r,e);return n.push(...t?.errors||[]),t?.record});else{let e=Z(r,a);o=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:o},errors:Object.keys(n).length>0?n:void 0}},$a=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=ro(r,t),a=Z(e.properties,i);return(0,c.notMissing)(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},eo=(e,t,n)=>{if(e.expression)try{let r=(0,l.evaluate)(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=Z(e.properties,t);return(0,c.notMissing)(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=Z(e.properties,r);return(0,c.notMissing)(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},to=(e,t,n)=>{let r=(0,c.notMissing)(e.values)?e.values:t,i=Z(e.properties,r);return(0,c.notMissing)(i?.errors)&&n.push(...i.errors),i?.record},no=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?$a(e,t,n):e.array&&e.expression?eo(e,t,n):to(e,t,n)},Z=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=no(a,t,r),e===void 0)continue}else{let{error:n,value:i}=io(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:r.length>0?r:void 0}},ro=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if((0,l.isValidExpression)(e))try{return(0,l.evaluate)(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>ro(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=ro(r,t);return n}return e},io=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return ao(n,t,e);case`enum`:return oo(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},ao=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=(0,l.evaluate)(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},oo=(e,t,n)=>{let r=ao(e,t,n),i=(0,c.notMissing)(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if((0,c.isString)(a)){let n=Ja(a);if((0,c.notMissing)(n)){let e=(0,c.notMissing)(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=(0,l.evaluate)(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},so=q({type:X(`basic`),username:H().optional(),password:H().optional(),encoding:H().optional()}),co=q({type:X(`bearer`),token:H(),includeBearer:G().optional().default(!0)}),lo=q({type:X(`oauth2`),authorizationUrl:H().optional(),authorizationParams:J(H(),H()).optional(),tokenUrl:H().optional(),tokenParams:J(H(),H()).optional(),tokenExpiresIn:W().optional(),tokenRefreshExpiresIn:W().optional(),token:H(),includeBearer:G().optional().default(!0),scopes:H().optional()}),uo=ta(`type`,[so,co,lo]),fo=q({baseUrl:H(),url:H(),method:Y(u.HttpMethods),response:q({indexField:H().optional(),dataKey:H().optional(),nextKey:H().optional()}).optional(),iterator:q({key:H(),in:Y(u.RequestParameterLocations)}),cursor:q({token:H().optional().nullable(),position:W().optional().nullable()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:q({name:H(),value:K(),in:Y(u.RequestParameterLocations),condition:H().optional()}).array().optional()}),po=q({data:K().optional(),raw:K().optional(),statusCode:W(),message:H().optional(),next:H().optional().nullable(),position:W().optional()}).optional(),mo=25,ho=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?mo:i,o=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?(0,l.safeEvaluateRecord)({...t,args:o},e):{},d={...s,customErrors:t?.customErrors},{baseUrl:f,url:p,method:m,response:h,iterator:g,cursor:_,customErrors:v,args:ee}=fo.parse(d),y=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=uo.parse(y),x=ee?(0,u.parseRequestParameters)(ee):{query:{},body:{},headers:{}},te=(0,u.createAuthorizationHeaders)(b),ne={...x?.headers??{},...te},S=_?.token??null,C=null,re=null,w=[],T=[],ie=[],ae=a,E=_?.position??0,oe=!0,se=!0;do{oe?oe=!1:E=0,S!==null&&(g.in===`query`?x.query[g.key]=S.toString():g.in===`body`&&(x.body[g.key]=S));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${f}${p}`,queryParams:x?.query,method:m,headers:ne,body:x?.body,customErrorConfigs:v})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}C=S,T=h?.dataKey?t.data[h?.dataKey]:t.data;let r=T?.slice(E,ae);ae-=r.length,E+=r.length,ie.push(t),w=w.concat(r),re=t?.status,S=h?.nextKey?t.data[h?.nextKey]:void 0,r.length===T.length&&ae===0&&(E=0,C=S),se=(0,c.isMissing)(S)&&w.length<a}while((0,c.notMissing)(S)&&w.length<a&&T?.length>0);let ce=go(w,h);return{block:e,successful:!0,output:{data:ce,raw:ie,statusCode:re,next:se?void 0:C,position:se?void 0:E}}},go=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},_o=q({type:X(`basic`),username:H().optional(),password:H().optional(),encoding:H().optional()}),vo=q({type:X(`bearer`),token:H(),includeBearer:G().optional().default(!0)}),yo=q({type:X(`oauth2`),authorizationUrl:H().optional(),authorizationParams:J(H(),H()).optional(),tokenUrl:H().optional(),tokenParams:J(H(),H()).optional(),tokenExpiresIn:W().optional(),tokenRefreshExpiresIn:W().optional(),token:H(),includeBearer:G().optional().default(!0),scopes:H().optional()}),bo=ta(`type`,[_o,vo,yo]),xo=q({baseUrl:H(),url:H(),method:Y(u.HttpMethods),authorization:bo.optional(),response:q({collection:G().optional(),indexField:H().optional(),dataKey:H().optional()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:q({name:H(),value:K(),in:Y(u.RequestParameterLocations),condition:H().optional()}).array().optional()}),So=q({data:K().optional(),raw:K().optional(),statusCode:W(),message:H().optional()}).optional(),Co=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?(0,l.safeEvaluateRecord)({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:d,method:f,response:p,authorization:m,customErrors:h,args:g}=xo.parse(o),_=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=g?(0,u.parseRequestParameters)(g):{query:{},body:{},headers:{}},ee=(0,c.notMissing)(m)?m:bo.parse(_),y=(0,u.createAuthorizationHeaders)(ee),b={...v?.headers??{},...y},x;try{x=await n.performRequest({httpClient:e.httpClient,url:`${s}${d}`,queryParams:v?.query,method:f,headers:b,body:v?.body,customErrorConfigs:h})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let te=p?.dataKey?x.data[p?.dataKey]:x.data,ne=wo(te,p);return{block:e,successful:!0,output:{data:ne,raw:x,statusCode:x?.status,message:x?.message}}},wo=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},To=q({targetFieldKey:H(),type:Y([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:G().default(!1),custom:G().default(!1),hidden:G().default(!1),properties:Ea(()=>To).array().optional()}),Eo=q({fields:To.array().optional(),dataSource:H()}),Do=q({data:K()});let Q=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Oo=({value:e,type:t,format:n})=>{if((0,c.isMissing)(e))return null;switch(t){case Q.String:return(0,c.safeParseToString)({value:e});case Q.Number:return(0,c.safeParseToNumber)({value:e});case Q.Boolean:return(0,c.safeParseToBoolean)({value:e});case Q.DateTimeString:return(0,c.safeParseToDateTimeString)({value:e,format:n});default:return e}},ko=e=>{let t=Object.values(Q);return t.includes(e)},Ao=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>jo(e,t)):jo(e.result,t),{block:{...e,result:n},successful:!0}},jo=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;ko(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=Oo({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Oo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},Mo=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Eo.parse(t),i=(0,l.evaluate)(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Po(e,n)):Po(i,n),{block:{...e},successful:!0,output:{data:a}}},No=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Po(t,e.properties):t):typeof t==`object`&&t?Po(t,e.properties):t,Po=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;i===`object`?!t.custom&&(0,c.notMissing)(n[r])?n[r]=No(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=No(t,e.unified_custom_fields?.[r])):ko(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=Oo({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Oo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e}({});const Fo={[$.TYPECAST]:{v1:{fn:Ao},v2:{fn:Mo,inputSchema:Eo,outputSchema:Do}},[$.MAP_FIELDS]:{v1:{fn:Wa},v2:{fn:Qa,inputSchema:Xa,outputSchema:Za}},[$.REQUEST]:{v1:{fn:Co,inputSchema:xo,outputSchema:So}},[$.GROUP_DATA]:{v1:{fn:Ua,inputSchema:Va,outputSchema:Ha}},[$.PAGINATED_REQUEST]:{v1:{fn:ho,inputSchema:fo,outputSchema:po}}},Io=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch{return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},Lo={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=Fo}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:Io(i,e)}:i}};exports.AUTHENTICATION_SCHEMA=bo,exports.COMPOSITE_ID_LATEST_VERSION=y,exports.CoreError=b,exports.StepFunctionName=$,exports.StepFunctionsFactory=Lo,exports.areCursorsEqual=La,exports.decodeCompositeId=ie,exports.encodeCompositeId=T,exports.expandCursor=Fa,exports.getCategoryDetails=f,exports.isCompositeId=fe,exports.isCoreError=Ba,exports.isCursorEmpty=Ra,exports.isValidCategory=p,exports.minifyCursor=Na,exports.updateCursor=za;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import{decodeFromBase64 as e,encodeToBase64 as t,getContentHash as n,getCountryAlpha2CodeByAlpha2Code as r,getCountryAlpha2CodeByAlpha3Code as i,getCountryAlpha2CodeByCitizenship as a,getCountryAlpha2CodeByCountryCode as o,getCountryAlpha2CodeByCountryName as s,getCountryAlpha3CodeByAlpha2Code as c,getCountryAlpha3CodeByAlpha3Code as ee,getCountryAlpha3CodeByCountryCode as l,getCountryAlpha3CodeByCountryName as u,getCountryCodeByAlpha2Code as d,getCountryCodeByAlpha3Code as f,getCountryCodeByCountryCode as p,getCountryCodeByCountryName as m,getCountryNameByAlpha2Code as h,getCountryNameByAlpha3Code as te,getCountryNameByCountryCode as ne,getCountryNameByCountryName as g,getCountrySubDivisionCodeBySubDivisionName as re,getCountrySubDivisionNameBySubDivisionCode as ie,getCountrySubDivisionsByAlpha2Code as _,isMissing as v,isString as y,notMissing as b,safeParseToBoolean as ae,safeParseToDateTimeString as x,safeParseToNumber as S,safeParseToString as oe}from"@stackone/utils";import{evaluate as C,isValidExpression as se,safeEvaluateRecord as ce}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as w,HttpMethods as le,RequestClientFactory as ue,RequestParameterLocations as T,createAuthorizationHeaders as de,parseRequestParameters as fe}from"@stackone/transport";const pe={hris:{title:`HRIS`,key:`hris`,description:`Human Resource Information System`},crm:{title:`CRM`,key:`crm`,description:`Customer Relationship Management`},ats:{title:`ATS`,key:`ats`,description:`Applicant Tracking System`},lms:{title:`LMS`,key:`lms`,description:`Learning Management System`},marketing:{title:`Marketing`,key:`marketing`,description:`Marketing`},filestorage:{title:`File Storage`,key:`filestorage`,description:`File Storage`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`}},me=e=>{let t=pe[e.toLowerCase()];return t??null},he=e=>!!pe[e.toLowerCase()],ge=`so1!`,_e=t(ge),ve=`:`,ye=`,`,be=RegExp(`(?<!\\\\)${ve}`,`g`),xe=RegExp(`(?<!\\\\)${ye}`,`g`),Se=1;var Ce=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},we=class extends Ce{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},Te=class extends we{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},Ee=class extends we{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},De=class extends we{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},Oe=class extends we{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const ke=e=>!v(e)&&`value`in e&&e.value!==void 0,Ae=e=>!v(e)&&`identifiers`in e&&e.identifiers!==void 0,je=(e,t={version:Se})=>{if(t.version===1)return Le(Ne(e,t.aliases));throw new Oe(`Cannot generate ID, unsupported version number: ${t.version}`)},Me=(e,t={version:Se})=>{let n=Ie(e,t),r={};return n&&n.split(xe).forEach(e=>{let[n,i]=e.split(be),a=Fe(n,t.aliases??{});r[a]=Be(i)}),r},Ne=(e,t={})=>{if(ke(e))return Pe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(Ae(e))return e.identifiers.map(e=>Pe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(ye);throw new De},Pe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,ze(e.value)].filter(Boolean).join(ve)},Fe=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,Ie=(e,t)=>{if(t.version===1)return Re(e);throw new Oe(`Cannot decode ID, unsupported version number: ${t.version}`)},Le=e=>`${_e}${t(e)}`,Re=t=>{if(!t.startsWith(_e))throw new Te(`Trying to decode an ID without the header: ${t}`);let n=t.split(_e)[1];if(!n)throw new Ee(`Trying to decode an ID without a body: ${t}`);return e(n)},ze=e=>[ye,ve].reduce((e,t)=>e.replace(t,`\\`+t),e),Be=e=>[ye,ve].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),Ve=e=>v(e)?!1:e.startsWith(_e);Object.freeze({status:`aborted`});function E(e,t,n){function r(n,r){var i;for(let a in Object.defineProperty(n,`_zod`,{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r),o.prototype)a in n||Object.defineProperty(n,a,{value:o.prototype[a].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}Symbol(`zod_brand`);var D=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};const He={};function O(e){return e&&Object.assign(He,e),He}function Ue(e){let t=Object.values(e).filter(e=>typeof e==`number`),n=Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t);return n}function We(e,t){return typeof t==`bigint`?t.toString():t}function Ge(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function Ke(e){return e==null}function qe(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Je(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r,a=Number.parseInt(e.toFixed(i).replace(`.`,``)),o=Number.parseInt(t.toFixed(i).replace(`.`,``));return a%o/10**i}function k(e,t,n){Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}throw Error(`cached value already set`)},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Ye(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function A(e){return JSON.stringify(e)}const Xe=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function Ze(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Qe=Ge(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{let e=Function;return new e(``),!0}catch{return!1}});function $e(e){if(Ze(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(Ze(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}const et=new Set([`string`,`number`,`symbol`]);function j(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function M(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function N(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 tt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const nt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function rt(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;n[e]=r.shape[e]}return M(e,{...e._zod.def,shape:n,checks:[]})}function it(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;delete n[e]}return M(e,{...e._zod.def,shape:n,checks:[]})}function at(e,t){if(!$e(t))throw Error(`Invalid input to extend: expected a plain object`);let n={...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return Ye(this,`shape`,n),n},checks:[]};return M(e,n)}function ot(e,t){return M(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return Ye(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function st(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t]}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return M(t,{...t._zod.def,shape:i,checks:[]})}function ct(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=new e({type:`nonoptional`,innerType:r[t]})}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return M(t,{...t._zod.def,shape:i,checks:[]})}function P(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function F(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function lt(e){return typeof e==`string`?e:e?.message}function I(e,t,n){let r={...e,path:e.path??[]};if(!e.message){let i=lt(e.inst?._zod.def?.error?.(e))??lt(t?.error?.(e))??lt(n.customError?.(e))??lt(n.localeError?.(e))??`Invalid input`;r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function ut(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function L(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const dt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),Object.defineProperty(e,`message`,{get(){return JSON.stringify(t,We,2)},enumerable:!0}),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},ft=E(`$ZodError`,dt),pt=E(`$ZodError`,dt,{Parent:Error});function mt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function ht(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i],a=i===t.path.length-1;a?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}const gt=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new D;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>I(e,a,O())));throw Xe(t,i?.callee),t}return o.value},_t=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>I(e,a,O())));throw Xe(t,i?.callee),t}return o.value},vt=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 D;return a.issues.length?{success:!1,error:new(e??ft)(a.issues.map(e=>I(e,i,O())))}:{success:!0,data:a.value}},yt=vt(pt),bt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>I(e,i,O())))}:{success:!0,data:a.value}},xt=bt(pt),St=/^[cC][^\s-]{8,}$/,Ct=/^[0-9a-z]+$/,wt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Tt=/^[0-9a-vA-V]{20}$/,Et=/^[A-Za-z0-9]{27}$/,Dt=/^[a-zA-Z0-9_-]{21}$/,Ot=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,kt=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,At=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,jt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Mt=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Nt(){return new RegExp(Mt,`u`)}const Pt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ft=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,It=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Lt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Rt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,zt=/^[A-Za-z0-9_-]*$/,Bt=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,Vt=/^\+(?:[0-9]){6,14}[0-9]$/,Ht=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Ut=RegExp(`^${Ht}$`);function Wt(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`,n=typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;return n}function Gt(e){return RegExp(`^${Wt(e)}$`)}function Kt(e){let t=Wt({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Ht}T(?:${r})$`)}const qt=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Jt=/^\d+$/,Yt=/^-?\d+(?:\.\d+)?/i,Xt=/true|false/i,Zt=/^[^A-Z]*$/,Qt=/^[^a-z]*$/,R=E(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),$t={number:`number`,bigint:`bigint`,object:`date`},en=E(`$ZodCheckLessThan`,(e,t)=>{R.init(e,t);let n=$t[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tn=E(`$ZodCheckGreaterThan`,(e,t)=>{R.init(e,t);let n=$t[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),nn=E(`$ZodCheckMultipleOf`,(e,t)=>{R.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);let r=typeof n.value==`bigint`?n.value%t.value===BigInt(0):Je(n.value,t.value)===0;r||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),rn=E(`$ZodCheckNumberFormat`,(e,t)=>{R.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=nt[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Jt)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),an=E(`$ZodCheckMaxLength`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ke(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i<=t.maximum)return;let a=ut(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),on=E(`$ZodCheckMinLength`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ke(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i>=t.minimum)return;let a=ut(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),sn=E(`$ZodCheckLengthEquals`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Ke(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=ut(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),cn=E(`$ZodCheckStringFormat`,(e,t)=>{var n,r;R.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),ln=E(`$ZodCheckRegex`,(e,t)=>{cn.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})}}),un=E(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Zt,cn.init(e,t)}),dn=E(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Qt,cn.init(e,t)}),fn=E(`$ZodCheckIncludes`,(e,t)=>{R.init(e,t);let n=j(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),pn=E(`$ZodCheckStartsWith`,(e,t)=>{R.init(e,t);let n=RegExp(`^${j(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),mn=E(`$ZodCheckEndsWith`,(e,t)=>{R.init(e,t);let n=RegExp(`.*${j(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),hn=E(`$ZodCheckOverwrite`,(e,t)=>{R.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var gn=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e,n=t.split(`
1
+ import{decodeFromBase64 as e,encodeToBase64 as t,getContentHash as n,getCountryAlpha2CodeByAlpha2Code as r,getCountryAlpha2CodeByAlpha3Code as i,getCountryAlpha2CodeByCitizenship as a,getCountryAlpha2CodeByCountryCode as o,getCountryAlpha2CodeByCountryName as s,getCountryAlpha3CodeByAlpha2Code as c,getCountryAlpha3CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as u,getCountryAlpha3CodeByCountryName as d,getCountryCodeByAlpha2Code as f,getCountryCodeByAlpha3Code as p,getCountryCodeByCountryCode as m,getCountryCodeByCountryName as h,getCountryNameByAlpha2Code as g,getCountryNameByAlpha3Code as ee,getCountryNameByCountryCode as te,getCountryNameByCountryName as _,getCountrySubDivisionCodeBySubDivisionName as ne,getCountrySubDivisionNameBySubDivisionCode as re,getCountrySubDivisionsByAlpha2Code as v,isMissing as y,isString as b,notMissing as x,safeParseToBoolean as ie,safeParseToDateTimeString as S,safeParseToNumber as C,safeParseToString as ae}from"@stackone/utils";import{evaluate as w,isValidExpression as oe,safeEvaluateRecord as se}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as T,HttpMethods as ce,RequestClientFactory as le,RequestParameterLocations as E,createAuthorizationHeaders as ue,parseRequestParameters as de,serializeHttpResponseError as fe}from"@stackone/transport";const pe={hris:{title:`HRIS`,key:`hris`,description:`Human Resource Information System`},crm:{title:`CRM`,key:`crm`,description:`Customer Relationship Management`},ats:{title:`ATS`,key:`ats`,description:`Applicant Tracking System`},lms:{title:`LMS`,key:`lms`,description:`Learning Management System`},marketing:{title:`Marketing`,key:`marketing`,description:`Marketing`},filestorage:{title:`File Storage`,key:`filestorage`,description:`File Storage`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`}},me=e=>{let t=pe[e.toLowerCase()];return t??null},he=e=>!!pe[e.toLowerCase()],ge=`so1!`,_e=t(ge),ve=`:`,ye=`,`,be=RegExp(`(?<!\\\\)${ve}`,`g`),xe=RegExp(`(?<!\\\\)${ye}`,`g`),Se=1;var Ce=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},we=class extends Ce{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},Te=class extends we{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},Ee=class extends we{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},De=class extends we{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},Oe=class extends we{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const ke=e=>!y(e)&&`value`in e&&e.value!==void 0,Ae=e=>!y(e)&&`identifiers`in e&&e.identifiers!==void 0,je=(e,t={version:Se})=>{if(t.version===1)return Le(Ne(e,t.aliases));throw new Oe(`Cannot generate ID, unsupported version number: ${t.version}`)},Me=(e,t={version:Se})=>{let n=Ie(e,t),r={};return n&&n.split(xe).forEach(e=>{let[n,i]=e.split(be),a=Fe(n,t.aliases??{});r[a]=Be(i)}),r},Ne=(e,t={})=>{if(ke(e))return Pe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(Ae(e))return e.identifiers.map(e=>Pe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(ye);throw new De},Pe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,ze(e.value)].filter(Boolean).join(ve)},Fe=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,Ie=(e,t)=>{if(t.version===1)return Re(e);throw new Oe(`Cannot decode ID, unsupported version number: ${t.version}`)},Le=e=>`${_e}${t(e)}`,Re=t=>{if(!t.startsWith(_e))throw new Te(`Trying to decode an ID without the header: ${t}`);let n=t.split(_e)[1];if(!n)throw new Ee(`Trying to decode an ID without a body: ${t}`);return e(n)},ze=e=>[ye,ve].reduce((e,t)=>e.replace(t,`\\`+t),e),Be=e=>[ye,ve].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),Ve=e=>y(e)?!1:e.startsWith(_e);Object.freeze({status:`aborted`});function D(e,t,n){function r(n,r){var i;for(let a in Object.defineProperty(n,`_zod`,{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r),o.prototype)a in n||Object.defineProperty(n,a,{value:o.prototype[a].bind(n)});n._zod.constr=o,n._zod.def=r}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,`name`,{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,`init`,{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,`name`,{value:e}),o}Symbol(`zod_brand`);var He=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};const Ue={};function O(e){return e&&Object.assign(Ue,e),Ue}function We(e){let t=Object.values(e).filter(e=>typeof e==`number`),n=Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t);return n}function Ge(e,t){return typeof t==`bigint`?t.toString():t}function Ke(e){return{get value(){{let t=e();return Object.defineProperty(this,`value`,{value:t}),t}throw Error(`cached value already set`)}}}function qe(e){return e==null}function Je(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Ye(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=(t.toString().split(`.`)[1]||``).length,i=n>r?n:r,a=Number.parseInt(e.toFixed(i).replace(`.`,``)),o=Number.parseInt(t.toFixed(i).replace(`.`,``));return a%o/10**i}function k(e,t,n){Object.defineProperty(e,t,{get(){{let r=n();return e[t]=r,r}throw Error(`cached value already set`)},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Xe(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function A(e){return JSON.stringify(e)}const Ze=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const $e=Ke(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{let e=Function;return new e(``),!0}catch{return!1}});function et(e){if(Qe(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(Qe(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}const tt=new Set([`string`,`number`,`symbol`]);function j(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function M(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function N(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 nt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const rt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function it(e,t){let n={},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;n[e]=r.shape[e]}return M(e,{...e._zod.def,shape:n,checks:[]})}function at(e,t){let n={...e._zod.def.shape},r=e._zod.def;for(let e in t){if(!(e in r.shape))throw Error(`Unrecognized key: "${e}"`);if(!t[e])continue;delete n[e]}return M(e,{...e._zod.def,shape:n,checks:[]})}function ot(e,t){if(!et(t))throw Error(`Invalid input to extend: expected a plain object`);let n={...e._zod.def,get shape(){let n={...e._zod.def.shape,...t};return Xe(this,`shape`,n),n},checks:[]};return M(e,n)}function st(e,t){return M(e,{...e._zod.def,get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return Xe(this,`shape`,n),n},catchall:t._zod.def.catchall,checks:[]})}function ct(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t]}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return M(t,{...t._zod.def,shape:i,checks:[]})}function lt(e,t,n){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);if(!n[t])continue;i[t]=new e({type:`nonoptional`,innerType:r[t]})}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return M(t,{...t._zod.def,shape:i,checks:[]})}function P(e,t=0){for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function F(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function ut(e){return typeof e==`string`?e:e?.message}function I(e,t,n){let r={...e,path:e.path??[]};if(!e.message){let i=ut(e.inst?._zod.def?.error?.(e))??ut(t?.error?.(e))??ut(n.customError?.(e))??ut(n.localeError?.(e))??`Invalid input`;r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function dt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function L(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const ft=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,`_zod`,{value:e._zod,enumerable:!1}),Object.defineProperty(e,`issues`,{value:t,enumerable:!1}),Object.defineProperty(e,`message`,{get(){return JSON.stringify(t,Ge,2)},enumerable:!0}),Object.defineProperty(e,`toString`,{value:()=>e.message,enumerable:!1})},pt=D(`$ZodError`,ft),mt=D(`$ZodError`,ft,{Parent:Error});function ht(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function gt(e,t){let n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(let t of e.issues)if(t.code===`invalid_union`&&t.errors.length)t.errors.map(e=>i({issues:e}));else if(t.code===`invalid_key`)i({issues:t.issues});else if(t.code===`invalid_element`)i({issues:t.issues});else if(t.path.length===0)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){let r=t.path[i],a=i===t.path.length-1;a?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}const _t=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new He;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>I(e,a,O())));throw Ze(t,i?.callee),t}return o.value},vt=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>I(e,a,O())));throw Ze(t,i?.callee),t}return o.value},yt=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 He;return a.issues.length?{success:!1,error:new(e??pt)(a.issues.map(e=>I(e,i,O())))}:{success:!0,data:a.value}},bt=yt(mt),xt=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>I(e,i,O())))}:{success:!0,data:a.value}},St=xt(mt),Ct=/^[cC][^\s-]{8,}$/,wt=/^[0-9a-z]+$/,Tt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Et=/^[0-9a-vA-V]{20}$/,Dt=/^[A-Za-z0-9]{27}$/,Ot=/^[a-zA-Z0-9_-]{21}$/,kt=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,At=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,jt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,Mt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Nt=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Pt(){return new RegExp(Nt,`u`)}const Ft=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,It=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,Lt=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Rt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Bt=/^[A-Za-z0-9_-]*$/,Vt=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,Ht=/^\+(?:[0-9]){6,14}[0-9]$/,Ut=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Wt=RegExp(`^${Ut}$`);function Gt(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`,n=typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`;return n}function Kt(e){return RegExp(`^${Gt(e)}$`)}function qt(e){let t=Gt({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-]\\d{2}:\\d{2})`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Ut}T(?:${r})$`)}const Jt=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Yt=/^\d+$/,Xt=/^-?\d+(?:\.\d+)?/i,Zt=/true|false/i,Qt=/^[^A-Z]*$/,$t=/^[^a-z]*$/,R=D(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),en={number:`number`,bigint:`bigint`,object:`date`},tn=D(`$ZodCheckLessThan`,(e,t)=>{R.init(e,t);let n=en[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),nn=D(`$ZodCheckGreaterThan`,(e,t)=>{R.init(e,t);let n=en[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),rn=D(`$ZodCheckMultipleOf`,(e,t)=>{R.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);let r=typeof n.value==`bigint`?n.value%t.value===BigInt(0):Ye(n.value,t.value)===0;r||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),an=D(`$ZodCheckNumberFormat`,(e,t)=>{R.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=rt[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Yt)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inst:e})}}),on=D(`$ZodCheckMaxLength`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!qe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i<=t.maximum)return;let a=dt(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),sn=D(`$ZodCheckMinLength`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!qe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value,i=r.length;if(i>=t.minimum)return;let a=dt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),cn=D(`$ZodCheckLengthEquals`,(e,t)=>{var n;R.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!qe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=dt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ln=D(`$ZodCheckStringFormat`,(e,t)=>{var n,r;R.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),un=D(`$ZodCheckRegex`,(e,t)=>{ln.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})}}),dn=D(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Qt,ln.init(e,t)}),fn=D(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=$t,ln.init(e,t)}),pn=D(`$ZodCheckIncludes`,(e,t)=>{R.init(e,t);let n=j(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),mn=D(`$ZodCheckStartsWith`,(e,t)=>{R.init(e,t);let n=RegExp(`^${j(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),hn=D(`$ZodCheckEndsWith`,(e,t)=>{R.init(e,t);let n=RegExp(`.*${j(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),gn=D(`$ZodCheckOverwrite`,(e,t)=>{R.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var _n=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e,n=t.split(`
2
2
  `).filter(e=>e),r=Math.min(...n.map(e=>e.length-e.trimStart().length)),i=n.map(e=>e.slice(r)).map(e=>` `.repeat(this.indent*2)+e);for(let e of i)this.content.push(e)}compile(){let e=Function,t=this?.args,n=this?.content??[``],r=[...n.map(e=>` ${e}`)];return new e(...t,r.join(`
3
- `))}};const _n={major:4,minor:0,patch:0},z=E(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=_n;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=P(e),i;for(let a of t){if(a._zod.def.when){let t=a._zod.def.when(e);if(!t)continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new D;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o;let n=e.issues.length;n!==t&&(r||=P(e,t))});else{let n=e.issues.length;if(n===t)continue;r||=P(e,t)}}return i?i.then(()=>e):e};e._zod.run=(n,i)=>{let a=e._zod.parse(n,i);if(a instanceof Promise){if(i.async===!1)throw new D;return a.then(e=>t(e,r,i))}return t(a,r,i)}}e[`~standard`]={validate:t=>{try{let n=yt(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return xt(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}}),vn=E(`$ZodString`,(e,t)=>{z.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??qt(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),B=E(`$ZodStringFormat`,(e,t)=>{cn.init(e,t),vn.init(e,t)}),yn=E(`$ZodGUID`,(e,t)=>{t.pattern??=kt,B.init(e,t)}),bn=E(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8},n=e[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=At(n)}else t.pattern??=At();B.init(e,t)}),xn=E(`$ZodEmail`,(e,t)=>{t.pattern??=jt,B.init(e,t)}),Sn=E(`$ZodURL`,(e,t)=>{B.init(e,t),e._zod.check=n=>{try{let r=n.value,i=new URL(r),a=i.href;t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:Bt.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),!r.endsWith(`/`)&&a.endsWith(`/`)?n.value=a.slice(0,-1):n.value=a;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Cn=E(`$ZodEmoji`,(e,t)=>{t.pattern??=Nt(),B.init(e,t)}),wn=E(`$ZodNanoID`,(e,t)=>{t.pattern??=Dt,B.init(e,t)}),Tn=E(`$ZodCUID`,(e,t)=>{t.pattern??=St,B.init(e,t)}),En=E(`$ZodCUID2`,(e,t)=>{t.pattern??=Ct,B.init(e,t)}),Dn=E(`$ZodULID`,(e,t)=>{t.pattern??=wt,B.init(e,t)}),On=E(`$ZodXID`,(e,t)=>{t.pattern??=Tt,B.init(e,t)}),kn=E(`$ZodKSUID`,(e,t)=>{t.pattern??=Et,B.init(e,t)}),An=E(`$ZodISODateTime`,(e,t)=>{t.pattern??=Kt(t),B.init(e,t)}),jn=E(`$ZodISODate`,(e,t)=>{t.pattern??=Ut,B.init(e,t)}),Mn=E(`$ZodISOTime`,(e,t)=>{t.pattern??=Gt(t),B.init(e,t)}),Nn=E(`$ZodISODuration`,(e,t)=>{t.pattern??=Ot,B.init(e,t)}),Pn=E(`$ZodIPv4`,(e,t)=>{t.pattern??=Pt,B.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv4`})}),Fn=E(`$ZodIPv6`,(e,t)=>{t.pattern??=Ft,B.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv6`}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),In=E(`$ZodCIDRv4`,(e,t)=>{t.pattern??=It,B.init(e,t)}),Ln=E(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Lt,B.init(e,t),e._zod.check=n=>{let[r,i]=n.value.split(`/`);try{if(!i)throw Error();let e=Number(i);if(`${e}`!==i||e<0||e>128)throw Error();new URL(`http://[${r}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Rn(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const zn=E(`$ZodBase64`,(e,t)=>{t.pattern??=Rt,B.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64`}),e._zod.check=n=>{Rn(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Bn(e){if(!zt.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`),n=t.padEnd(Math.ceil(t.length/4)*4,`=`);return Rn(n)}const Vn=E(`$ZodBase64URL`,(e,t)=>{t.pattern??=zt,B.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64url`}),e._zod.check=n=>{Bn(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Hn=E(`$ZodE164`,(e,t)=>{t.pattern??=Vt,B.init(e,t)});function Un(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Wn=E(`$ZodJWT`,(e,t)=>{B.init(e,t),e._zod.check=n=>{Un(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Gn=E(`$ZodNumber`,(e,t)=>{z.init(e,t),e._zod.pattern=e._zod.bag.pattern??Yt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Kn=E(`$ZodNumber`,(e,t)=>{rn.init(e,t),Gn.init(e,t)}),qn=E(`$ZodBoolean`,(e,t)=>{z.init(e,t),e._zod.pattern=Xt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Jn=E(`$ZodUnknown`,(e,t)=>{z.init(e,t),e._zod.parse=e=>e}),Yn=E(`$ZodNever`,(e,t)=>{z.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Xn(e,t,n){e.issues.length&&t.issues.push(...F(n,e.issues)),t.value[n]=e.value}const Zn=E(`$ZodArray`,(e,t)=>{z.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Xn(t,n,e))):Xn(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Qn(e,t,n){e.issues.length&&t.issues.push(...F(n,e.issues)),t.value[n]=e.value}function $n(e,t,n,r){e.issues.length?r[n]===void 0?n in r?t.value[n]=void 0:t.value[n]=e.value:t.issues.push(...F(n,e.issues)):e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}const er=E(`$ZodObject`,(e,t)=>{z.init(e,t);let n=Ge(()=>{let e=Object.keys(t.shape);for(let n of e)if(!(t.shape[n]instanceof z))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=tt(t.shape);return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});k(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=e=>{let t=new gn([`shape`,`payload`,`ctx`]),r=n.value,i=e=>{let t=A(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of r.keys)a[e]=`key_${o++}`;t.write(`const newResult = {}`);for(let e of r.keys)if(r.optionalKeys.has(e)){let n=a[e];t.write(`const ${n} = ${i(e)};`);let r=A(e);t.write(`
3
+ `))}};const vn={major:4,minor:0,patch:0},z=D(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=vn;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=P(e),i;for(let a of t){if(a._zod.def.when){let t=a._zod.def.when(e);if(!t)continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new He;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o;let n=e.issues.length;n!==t&&(r||=P(e,t))});else{let n=e.issues.length;if(n===t)continue;r||=P(e,t)}}return i?i.then(()=>e):e};e._zod.run=(n,i)=>{let a=e._zod.parse(n,i);if(a instanceof Promise){if(i.async===!1)throw new He;return a.then(e=>t(e,r,i))}return t(a,r,i)}}e[`~standard`]={validate:t=>{try{let n=bt(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return St(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}}),yn=D(`$ZodString`,(e,t)=>{z.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Jt(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),B=D(`$ZodStringFormat`,(e,t)=>{ln.init(e,t),yn.init(e,t)}),bn=D(`$ZodGUID`,(e,t)=>{t.pattern??=At,B.init(e,t)}),xn=D(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8},n=e[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=jt(n)}else t.pattern??=jt();B.init(e,t)}),Sn=D(`$ZodEmail`,(e,t)=>{t.pattern??=Mt,B.init(e,t)}),Cn=D(`$ZodURL`,(e,t)=>{B.init(e,t),e._zod.check=n=>{try{let r=n.value,i=new URL(r),a=i.href;t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:Vt.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),!r.endsWith(`/`)&&a.endsWith(`/`)?n.value=a.slice(0,-1):n.value=a;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),wn=D(`$ZodEmoji`,(e,t)=>{t.pattern??=Pt(),B.init(e,t)}),Tn=D(`$ZodNanoID`,(e,t)=>{t.pattern??=Ot,B.init(e,t)}),En=D(`$ZodCUID`,(e,t)=>{t.pattern??=Ct,B.init(e,t)}),Dn=D(`$ZodCUID2`,(e,t)=>{t.pattern??=wt,B.init(e,t)}),On=D(`$ZodULID`,(e,t)=>{t.pattern??=Tt,B.init(e,t)}),kn=D(`$ZodXID`,(e,t)=>{t.pattern??=Et,B.init(e,t)}),An=D(`$ZodKSUID`,(e,t)=>{t.pattern??=Dt,B.init(e,t)}),jn=D(`$ZodISODateTime`,(e,t)=>{t.pattern??=qt(t),B.init(e,t)}),Mn=D(`$ZodISODate`,(e,t)=>{t.pattern??=Wt,B.init(e,t)}),Nn=D(`$ZodISOTime`,(e,t)=>{t.pattern??=Kt(t),B.init(e,t)}),Pn=D(`$ZodISODuration`,(e,t)=>{t.pattern??=kt,B.init(e,t)}),Fn=D(`$ZodIPv4`,(e,t)=>{t.pattern??=Ft,B.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv4`})}),In=D(`$ZodIPv6`,(e,t)=>{t.pattern??=It,B.init(e,t),e._zod.onattach.push(e=>{let t=e._zod.bag;t.format=`ipv6`}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Ln=D(`$ZodCIDRv4`,(e,t)=>{t.pattern??=Lt,B.init(e,t)}),Rn=D(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Rt,B.init(e,t),e._zod.check=n=>{let[r,i]=n.value.split(`/`);try{if(!i)throw Error();let e=Number(i);if(`${e}`!==i||e<0||e>128)throw Error();new URL(`http://[${r}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function zn(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Bn=D(`$ZodBase64`,(e,t)=>{t.pattern??=zt,B.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64`}),e._zod.check=n=>{zn(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Vn(e){if(!Bt.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`),n=t.padEnd(Math.ceil(t.length/4)*4,`=`);return zn(n)}const Hn=D(`$ZodBase64URL`,(e,t)=>{t.pattern??=Bt,B.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding=`base64url`}),e._zod.check=n=>{Vn(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Un=D(`$ZodE164`,(e,t)=>{t.pattern??=Ht,B.init(e,t)});function Wn(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Gn=D(`$ZodJWT`,(e,t)=>{B.init(e,t),e._zod.check=n=>{Wn(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Kn=D(`$ZodNumber`,(e,t)=>{z.init(e,t),e._zod.pattern=e._zod.bag.pattern??Xt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),qn=D(`$ZodNumber`,(e,t)=>{an.init(e,t),Kn.init(e,t)}),Jn=D(`$ZodBoolean`,(e,t)=>{z.init(e,t),e._zod.pattern=Zt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Yn=D(`$ZodUnknown`,(e,t)=>{z.init(e,t),e._zod.parse=e=>e}),Xn=D(`$ZodNever`,(e,t)=>{z.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Zn(e,t,n){e.issues.length&&t.issues.push(...F(n,e.issues)),t.value[n]=e.value}const Qn=D(`$ZodArray`,(e,t)=>{z.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Zn(t,n,e))):Zn(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function $n(e,t,n){e.issues.length&&t.issues.push(...F(n,e.issues)),t.value[n]=e.value}function er(e,t,n,r){e.issues.length?r[n]===void 0?n in r?t.value[n]=void 0:t.value[n]=e.value:t.issues.push(...F(n,e.issues)):e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}const tr=D(`$ZodObject`,(e,t)=>{z.init(e,t);let n=Ke(()=>{let e=Object.keys(t.shape);for(let n of e)if(!(t.shape[n]instanceof z))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=nt(t.shape);return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});k(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=e=>{let t=new _n([`shape`,`payload`,`ctx`]),r=n.value,i=e=>{let t=A(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of r.keys)a[e]=`key_${o++}`;t.write(`const newResult = {}`);for(let e of r.keys)if(r.optionalKeys.has(e)){let n=a[e];t.write(`const ${n} = ${i(e)};`);let r=A(e);t.write(`
4
4
  if (${n}.issues.length) {
5
5
  if (input[${r}] === undefined) {
6
6
  if (${r} in input) {
@@ -23,4 +23,4 @@ import{decodeFromBase64 as e,encodeToBase64 as t,getContentHash as n,getCountryA
23
23
  if (${n}.issues.length) payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
24
24
  ...iss,
25
25
  path: iss.path ? [${A(e)}, ...iss.path] : [${A(e)}]
26
- })));`),t.write(`newResult[${A(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=Ze,o=!He.jitless,s=Qe,c=o&&s.value,ee=t.catchall,l;e._zod.parse=(s,u)=>{l??=n.value;let d=s.value;if(!a(d))return s.issues.push({expected:`object`,code:`invalid_type`,input:d,inst:e}),s;let f=[];if(o&&c&&u?.async===!1&&u.jitless!==!0)i||=r(t.shape),s=i(s,u);else{s.value={};let e=l.shape;for(let t of l.keys){let n=e[t],r=n._zod.run({value:d[t],issues:[]},u),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?f.push(r.then(e=>i?$n(e,s,t,d):Qn(e,s,t))):i?$n(r,s,t,d):Qn(r,s,t)}}if(!ee)return f.length?Promise.all(f).then(()=>s):s;let p=[],m=l.keySet,h=ee._zod,te=h.def.type;for(let e of Object.keys(d)){if(m.has(e))continue;if(te===`never`){p.push(e);continue}let t=h.run({value:d[e],issues:[]},u);t instanceof Promise?f.push(t.then(t=>Qn(t,s,e))):Qn(t,s,e)}return p.length&&s.issues.push({code:`unrecognized_keys`,keys:p,input:d,inst:e}),f.length?Promise.all(f).then(()=>s):s}});function tr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>I(e,r,O())))}),t}const nr=E(`$ZodUnion`,(e,t)=>{z.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>qe(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>tr(t,n,e,r)):tr(a,n,e,r)}}),rr=E(`$ZodDiscriminatedUnion`,(e,t)=>{nr.init(e,t);let n=e._zod.parse;k(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=Ge(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!Ze(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,input:o,path:[t.discriminator],inst:e}),i)}}),ir=E(`$ZodIntersection`,(e,t)=>{z.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>or(e,t,n)):or(e,i,a)}});function ar(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if($e(e)&&$e(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=ar(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ar(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function or(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),P(e))return e;let r=ar(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const sr=E(`$ZodRecord`,(e,t)=>{z.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!$e(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...F(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...F(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({origin:`record`,code:`invalid_key`,issues:s.issues.map(e=>I(e,r,O())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...F(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...F(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),cr=E(`$ZodEnum`,(e,t)=>{z.init(e,t);let n=Ue(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>et.has(typeof e)).map(e=>typeof e==`string`?j(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),lr=E(`$ZodLiteral`,(e,t)=>{z.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?j(e):e?e.toString():String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),ur=E(`$ZodTransform`,(e,t)=>{z.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new D;return e.value=r,e}}),dr=E(`$ZodOptional`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${qe(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),fr=E(`$ZodNullable`,(e,t)=>{z.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${qe(e.source)}|null)$`):void 0}),k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),pr=E(`$ZodDefault`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>mr(e,t)):mr(r,t)}});function mr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const hr=E(`$ZodPrefault`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),gr=E(`$ZodNonOptional`,(e,t)=>{z.init(e,t),k(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>_r(t,e)):_r(i,e)}});function _r(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const vr=E(`$ZodCatch`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>I(e,n,O()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>I(e,n,O()))},input:e.value}),e.issues=[]),e)}}),yr=E(`$ZodPipe`,(e,t)=>{z.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>br(e,t,n)):br(r,t,n)}});function br(e,t,n){return P(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const xr=E(`$ZodReadonly`,(e,t)=>{z.init(e,t),k(e._zod,`propValues`,()=>t.innerType._zod.propValues),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Sr):Sr(r)}});function Sr(e){return e.value=Object.freeze(e.value),e}const Cr=E(`$ZodLazy`,(e,t)=>{z.init(e,t),k(e._zod,`innerType`,()=>t.getter()),k(e._zod,`pattern`,()=>e._zod.innerType._zod.pattern),k(e._zod,`propValues`,()=>e._zod.innerType._zod.propValues),k(e._zod,`optin`,()=>e._zod.innerType._zod.optin),k(e._zod,`optout`,()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>{let r=e._zod.innerType;return r._zod.run(t,n)}}),wr=E(`$ZodCustom`,(e,t)=>{R.init(e,t),z.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=>Tr(t,n,r,e));Tr(i,n,r,e)}});function Tr(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(L(e))}}Symbol(`ZodOutput`),Symbol(`ZodInput`);var Er=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function Dr(){return new Er}const Or=Dr();function kr(e,t){return new e({type:`string`,...N(t)})}function Ar(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function jr(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function Mr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function Nr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function Pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function Fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...N(t)})}function Ir(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...N(t)})}function Lr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function Rr(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function zr(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function Br(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function Vr(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...N(t)})}function Hr(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...N(t)})}function Ur(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function Wr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function Gr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function Kr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function qr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function Jr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function Yr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function Xr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function Zr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function Qr(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function $r(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function ei(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function ti(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function ni(e,t){return new e({type:`number`,checks:[],...N(t)})}function ri(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function ii(e,t){return new e({type:`boolean`,...N(t)})}function ai(e){return new e({type:`unknown`})}function oi(e,t){return new e({type:`never`,...N(t)})}function si(e,t){return new en({check:`less_than`,...N(t),value:e,inclusive:!1})}function ci(e,t){return new en({check:`less_than`,...N(t),value:e,inclusive:!0})}function li(e,t){return new tn({check:`greater_than`,...N(t),value:e,inclusive:!1})}function ui(e,t){return new tn({check:`greater_than`,...N(t),value:e,inclusive:!0})}function di(e,t){return new nn({check:`multiple_of`,...N(t),value:e})}function fi(e,t){let n=new an({check:`max_length`,...N(t),maximum:e});return n}function pi(e,t){return new on({check:`min_length`,...N(t),minimum:e})}function mi(e,t){return new sn({check:`length_equals`,...N(t),length:e})}function hi(e,t){return new ln({check:`string_format`,format:`regex`,...N(t),pattern:e})}function gi(e){return new un({check:`string_format`,format:`lowercase`,...N(e)})}function _i(e){return new dn({check:`string_format`,format:`uppercase`,...N(e)})}function vi(e,t){return new fn({check:`string_format`,format:`includes`,...N(t),includes:e})}function yi(e,t){return new pn({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function bi(e,t){return new mn({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function V(e){return new hn({check:`overwrite`,tx:e})}function xi(e){return V(t=>t.normalize(e))}function Si(){return V(e=>e.trim())}function Ci(){return V(e=>e.toLowerCase())}function wi(){return V(e=>e.toUpperCase())}function Ti(e,t,n){return new e({type:`array`,element:t,...N(n)})}function Ei(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...N(n)});return r}const Di=E(`ZodISODateTime`,(e,t)=>{An.init(e,t),W.init(e,t)});function Oi(e){return Qr(Di,e)}const ki=E(`ZodISODate`,(e,t)=>{jn.init(e,t),W.init(e,t)});function Ai(e){return $r(ki,e)}const ji=E(`ZodISOTime`,(e,t)=>{Mn.init(e,t),W.init(e,t)});function Mi(e){return ei(ji,e)}const Ni=E(`ZodISODuration`,(e,t)=>{Nn.init(e,t),W.init(e,t)});function Pi(e){return ti(Ni,e)}const Fi=(e,t)=>{ft.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>ht(e,t)},flatten:{value:t=>mt(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})};E(`ZodError`,Fi);const Ii=E(`ZodError`,Fi,{Parent:Error}),Li=gt(Ii),Ri=_t(Ii),zi=vt(Ii),Bi=bt(Ii),H=E(`ZodType`,(e,t)=>(z.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>M(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Li(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>zi(e,t,n),e.parseAsync=async(t,n)=>Ri(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Bi(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(Ya(t,n)),e.superRefine=t=>e.check(Xa(t)),e.overwrite=t=>e.check(V(t)),e.optional=()=>Aa(e),e.nullable=()=>Ma(e),e.nullish=()=>Aa(Ma(e)),e.nonoptional=t=>Ra(e,t),e.array=()=>ga(e),e.or=t=>ya([e,t]),e.and=t=>Ca(e,t),e.transform=t=>Ha(e,Oa(t)),e.default=t=>Pa(e,t),e.prefault=t=>Ia(e,t),e.catch=t=>Ba(e,t),e.pipe=t=>Ha(e,t),e.readonly=()=>Wa(e),e.describe=t=>{let n=e.clone();return Or.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Or.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Or.get(e);let n=e.clone();return Or.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Vi=E(`_ZodString`,(e,t)=>{vn.init(e,t),H.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(hi(...t)),e.includes=(...t)=>e.check(vi(...t)),e.startsWith=(...t)=>e.check(yi(...t)),e.endsWith=(...t)=>e.check(bi(...t)),e.min=(...t)=>e.check(pi(...t)),e.max=(...t)=>e.check(fi(...t)),e.length=(...t)=>e.check(mi(...t)),e.nonempty=(...t)=>e.check(pi(1,...t)),e.lowercase=t=>e.check(gi(t)),e.uppercase=t=>e.check(_i(t)),e.trim=()=>e.check(Si()),e.normalize=(...t)=>e.check(xi(...t)),e.toLowerCase=()=>e.check(Ci()),e.toUpperCase=()=>e.check(wi())}),Hi=E(`ZodString`,(e,t)=>{vn.init(e,t),Vi.init(e,t),e.email=t=>e.check(Ar(Ui,t)),e.url=t=>e.check(Ir(Ki,t)),e.jwt=t=>e.check(Zr(sa,t)),e.emoji=t=>e.check(Lr(qi,t)),e.guid=t=>e.check(jr(Wi,t)),e.uuid=t=>e.check(Mr(Gi,t)),e.uuidv4=t=>e.check(Nr(Gi,t)),e.uuidv6=t=>e.check(Pr(Gi,t)),e.uuidv7=t=>e.check(Fr(Gi,t)),e.nanoid=t=>e.check(Rr(Ji,t)),e.guid=t=>e.check(jr(Wi,t)),e.cuid=t=>e.check(zr(Yi,t)),e.cuid2=t=>e.check(Br(Xi,t)),e.ulid=t=>e.check(Vr(Zi,t)),e.base64=t=>e.check(Jr(ia,t)),e.base64url=t=>e.check(Yr(aa,t)),e.xid=t=>e.check(Hr(Qi,t)),e.ksuid=t=>e.check(Ur($i,t)),e.ipv4=t=>e.check(Wr(ea,t)),e.ipv6=t=>e.check(Gr(ta,t)),e.cidrv4=t=>e.check(Kr(na,t)),e.cidrv6=t=>e.check(qr(ra,t)),e.e164=t=>e.check(Xr(oa,t)),e.datetime=t=>e.check(Oi(t)),e.date=t=>e.check(Ai(t)),e.time=t=>e.check(Mi(t)),e.duration=t=>e.check(Pi(t))});function U(e){return kr(Hi,e)}const W=E(`ZodStringFormat`,(e,t)=>{B.init(e,t),Vi.init(e,t)}),Ui=E(`ZodEmail`,(e,t)=>{xn.init(e,t),W.init(e,t)}),Wi=E(`ZodGUID`,(e,t)=>{yn.init(e,t),W.init(e,t)}),Gi=E(`ZodUUID`,(e,t)=>{bn.init(e,t),W.init(e,t)}),Ki=E(`ZodURL`,(e,t)=>{Sn.init(e,t),W.init(e,t)}),qi=E(`ZodEmoji`,(e,t)=>{Cn.init(e,t),W.init(e,t)}),Ji=E(`ZodNanoID`,(e,t)=>{wn.init(e,t),W.init(e,t)}),Yi=E(`ZodCUID`,(e,t)=>{Tn.init(e,t),W.init(e,t)}),Xi=E(`ZodCUID2`,(e,t)=>{En.init(e,t),W.init(e,t)}),Zi=E(`ZodULID`,(e,t)=>{Dn.init(e,t),W.init(e,t)}),Qi=E(`ZodXID`,(e,t)=>{On.init(e,t),W.init(e,t)}),$i=E(`ZodKSUID`,(e,t)=>{kn.init(e,t),W.init(e,t)}),ea=E(`ZodIPv4`,(e,t)=>{Pn.init(e,t),W.init(e,t)}),ta=E(`ZodIPv6`,(e,t)=>{Fn.init(e,t),W.init(e,t)}),na=E(`ZodCIDRv4`,(e,t)=>{In.init(e,t),W.init(e,t)}),ra=E(`ZodCIDRv6`,(e,t)=>{Ln.init(e,t),W.init(e,t)}),ia=E(`ZodBase64`,(e,t)=>{zn.init(e,t),W.init(e,t)}),aa=E(`ZodBase64URL`,(e,t)=>{Vn.init(e,t),W.init(e,t)}),oa=E(`ZodE164`,(e,t)=>{Hn.init(e,t),W.init(e,t)}),sa=E(`ZodJWT`,(e,t)=>{Wn.init(e,t),W.init(e,t)}),ca=E(`ZodNumber`,(e,t)=>{Gn.init(e,t),H.init(e,t),e.gt=(t,n)=>e.check(li(t,n)),e.gte=(t,n)=>e.check(ui(t,n)),e.min=(t,n)=>e.check(ui(t,n)),e.lt=(t,n)=>e.check(si(t,n)),e.lte=(t,n)=>e.check(ci(t,n)),e.max=(t,n)=>e.check(ci(t,n)),e.int=t=>e.check(ua(t)),e.safe=t=>e.check(ua(t)),e.positive=t=>e.check(li(0,t)),e.nonnegative=t=>e.check(ui(0,t)),e.negative=t=>e.check(si(0,t)),e.nonpositive=t=>e.check(ci(0,t)),e.multipleOf=(t,n)=>e.check(di(t,n)),e.step=(t,n)=>e.check(di(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function G(e){return ni(ca,e)}const la=E(`ZodNumberFormat`,(e,t)=>{Kn.init(e,t),ca.init(e,t)});function ua(e){return ri(la,e)}const da=E(`ZodBoolean`,(e,t)=>{qn.init(e,t),H.init(e,t)});function K(e){return ii(da,e)}const fa=E(`ZodUnknown`,(e,t)=>{Jn.init(e,t),H.init(e,t)});function q(){return ai(fa)}const pa=E(`ZodNever`,(e,t)=>{Yn.init(e,t),H.init(e,t)});function ma(e){return oi(pa,e)}const ha=E(`ZodArray`,(e,t)=>{Zn.init(e,t),H.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(pi(t,n)),e.nonempty=t=>e.check(pi(1,t)),e.max=(t,n)=>e.check(fi(t,n)),e.length=(t,n)=>e.check(mi(t,n)),e.unwrap=()=>e.element});function ga(e,t){return Ti(ha,e,t)}const _a=E(`ZodObject`,(e,t)=>{er.init(e,t),H.init(e,t),k(e,`shape`,()=>t.shape),e.keyof=()=>X(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:q()}),e.loose=()=>e.clone({...e._zod.def,catchall:q()}),e.strict=()=>e.clone({...e._zod.def,catchall:ma()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>at(e,t),e.merge=t=>ot(e,t),e.pick=t=>rt(e,t),e.omit=t=>it(e,t),e.partial=(...t)=>st(ka,e,t[0]),e.required=(...t)=>ct(La,e,t[0])});function J(e,t){let n={type:`object`,get shape(){return Ye(this,`shape`,{...e}),this.shape},...N(t)};return new _a(n)}const va=E(`ZodUnion`,(e,t)=>{nr.init(e,t),H.init(e,t),e.options=t.options});function ya(e,t){return new va({type:`union`,options:e,...N(t)})}const ba=E(`ZodDiscriminatedUnion`,(e,t)=>{va.init(e,t),rr.init(e,t)});function xa(e,t,n){return new ba({type:`union`,options:t,discriminator:e,...N(n)})}const Sa=E(`ZodIntersection`,(e,t)=>{ir.init(e,t),H.init(e,t)});function Ca(e,t){return new Sa({type:`intersection`,left:e,right:t})}const wa=E(`ZodRecord`,(e,t)=>{sr.init(e,t),H.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Y(e,t,n){return new wa({type:`record`,keyType:e,valueType:t,...N(n)})}const Ta=E(`ZodEnum`,(e,t)=>{cr.init(e,t),H.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ta({...t,checks:[],...N(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ta({...t,checks:[],...N(r),entries:i})}});function X(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Ta({type:`enum`,entries:n,...N(t)})}const Ea=E(`ZodLiteral`,(e,t)=>{lr.init(e,t),H.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Z(e,t){return new Ea({type:`literal`,values:Array.isArray(e)?e:[e],...N(t)})}const Da=E(`ZodTransform`,(e,t)=>{ur.init(e,t),H.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(L(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(L(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Oa(e){return new Da({type:`transform`,transform:e})}const ka=E(`ZodOptional`,(e,t)=>{dr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Aa(e){return new ka({type:`optional`,innerType:e})}const ja=E(`ZodNullable`,(e,t)=>{fr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ma(e){return new ja({type:`nullable`,innerType:e})}const Na=E(`ZodDefault`,(e,t)=>{pr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Pa(e,t){return new Na({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const Fa=E(`ZodPrefault`,(e,t)=>{hr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ia(e,t){return new Fa({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const La=E(`ZodNonOptional`,(e,t)=>{gr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ra(e,t){return new La({type:`nonoptional`,innerType:e,...N(t)})}const za=E(`ZodCatch`,(e,t)=>{vr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Ba(e,t){return new za({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const Va=E(`ZodPipe`,(e,t)=>{yr.init(e,t),H.init(e,t),e.in=t.in,e.out=t.out});function Ha(e,t){return new Va({type:`pipe`,in:e,out:t})}const Ua=E(`ZodReadonly`,(e,t)=>{xr.init(e,t),H.init(e,t)});function Wa(e){return new Ua({type:`readonly`,innerType:e})}const Ga=E(`ZodLazy`,(e,t)=>{Cr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.getter()});function Ka(e){return new Ga({type:`lazy`,getter:e})}const qa=E(`ZodCustom`,(e,t)=>{wr.init(e,t),H.init(e,t)});function Ja(e){let t=new R({check:`custom`});return t._zod.check=e,t}function Ya(e,t={}){return Ei(qa,e,t)}function Xa(e){let t=Ja(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(L(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(L(r))}},e(n.value,n)));return t}const Za=J({r:Y(U(),J({n:G().optional().nullable(),c:U().optional().nullable(),p:G().optional().nullable()})),v:G(),t:G()}),Qa=J({remote:Y(U(),J({pageNumber:G().optional(),providerPageCursor:U().optional(),position:G().optional()})),version:G(),timestamp:G()}),$a=e=>t(JSON.stringify(eo(e))),eo=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},to=t=>{try{if(y(t)){let n=e(t),r=JSON.parse(n),i=Za.parse(r);return no(i)}else return Qa.parse(t),t}catch{return null}},no=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},ro=(e,t)=>{let r=typeof e==`string`?to(e):e,i=typeof t==`string`?to(t):t;if(r===null||i===null)return r===i;let{timestamp:a,...o}=r,{timestamp:s,...c}=i;return n(o)===n(c)},io=({cursor:e,ignoreStepIndex:t})=>v(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return(v(t)||r!==t.toString())&&(n=n&&v(i.pageNumber)&&v(i.position)&&v(i.providerPageCursor)),n},!0),ao=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=v(n)&&v(r)&&v(i);return v(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},oo=e=>e instanceof Ce,so=J({stepsDataToGroup:ga(U()),isSingleRecord:K().optional()}),co=J({data:q()}),lo=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=so.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=b(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},uo=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=fo(r,a,i),s=po(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=po(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},fo=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),po=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=mo(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},mo=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=C(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},ho=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return r;case`country_alpha3code_by_alpha3code`:return ee;case`country_code_by_country_code`:return p;case`country_name_by_country_name`:return g;case`country_name_by_alpha3code`:return te;case`country_name_by_alpha2code`:return h;case`country_name_by_country_code`:return ne;case`country_alpha3code_by_alpha2code`:return c;case`country_alpha3code_by_country_name`:return u;case`country_alpha3code_by_country_code`:return l;case`country_alpha2code_by_alpha3code`:return i;case`country_alpha2code_by_country_name`:return s;case`country_alpha2code_by_country_code`:return o;case`country_code_by_alpha2code`:return d;case`country_code_by_alpha3code`:return f;case`country_code_by_country_name`:return m;case`country_subdivisions_by_alpha2code`:return _;case`country_subdivision_code_by_subdivision_name`:return re;case`country_alpha2code_by_citizenship`:return a;case`country_subdivision_name_by_subdivision_code`:return ie;default:return}},go=J({targetFieldKey:U(),alias:U().optional(),expression:U().optional(),values:q().optional(),type:X([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:K().default(!1),custom:K().default(!1),hidden:K().default(!1),enumMapper:J({matcher:U().or(J({matchExpression:U(),value:U()}).array())}).optional(),properties:Ka(()=>go).array().optional()}),_o=J({fields:go.array(),dataSource:U()}),vo=J({data:q()}),yo=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i}=_o.parse(t),a=C(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!a)return{block:e,successful:!0};let o;if(Array.isArray(a))o=a.map(e=>{let t=Q(r,e);return n.push(...t?.errors||[]),t?.record});else{let e=Q(r,a);o=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:o},errors:Object.keys(n).length>0?n:void 0}},bo=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=wo(r,t),a=Q(e.properties,i);return b(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},xo=(e,t,n)=>{if(e.expression)try{let r=C(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=Q(e.properties,t);return b(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=Q(e.properties,r);return b(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},So=(e,t,n)=>{let r=b(e.values)?e.values:t,i=Q(e.properties,r);return b(i?.errors)&&n.push(...i.errors),i?.record},Co=(e,t,n)=>{if(!v(e.properties))return e.array&&Array.isArray(e.values)?bo(e,t,n):e.array&&e.expression?xo(e,t,n):So(e,t,n)},Q=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=Co(a,t,r),e===void 0)continue}else{let{error:n,value:i}=To(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:r.length>0?r:void 0}},wo=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if(se(e))try{return C(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>wo(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=wo(r,t);return n}return e},To=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return Eo(n,t,e);case`enum`:return Do(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},Eo=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=C(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},Do=(e,t,n)=>{let r=Eo(e,t,n),i=b(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if(y(a)){let n=ho(a);if(b(n)){let e=b(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=C(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},Oo=J({type:Z(`basic`),username:U().optional(),password:U().optional(),encoding:U().optional()}),ko=J({type:Z(`bearer`),token:U(),includeBearer:K().optional().default(!0)}),Ao=J({type:Z(`oauth2`),authorizationUrl:U().optional(),authorizationParams:Y(U(),U()).optional(),tokenUrl:U().optional(),tokenParams:Y(U(),U()).optional(),tokenExpiresIn:G().optional(),tokenRefreshExpiresIn:G().optional(),token:U(),includeBearer:K().optional().default(!0),scopes:U().optional()}),jo=xa(`type`,[Oo,ko,Ao]),Mo=J({baseUrl:U(),url:U(),method:X(le),response:J({indexField:U().optional(),dataKey:U().optional(),nextKey:U().optional()}).optional(),iterator:J({key:U(),in:X(T)}),cursor:J({token:U().optional().nullable(),position:G().optional().nullable()}).optional(),customErrors:w.array().optional(),args:J({name:U(),value:q(),in:X(T),condition:U().optional()}).array().optional()}),No=J({data:q().optional(),raw:q().optional(),statusCode:G(),message:U().optional(),next:U().optional().nullable(),position:G().optional()}).optional(),Po=25,Fo=async({block:e,params:t})=>{let n=ue.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?Po:i,o=r?r.filter(t=>!t.condition||C(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?ce({...t,args:o},e):{},c={...s,customErrors:t?.customErrors},{baseUrl:ee,url:l,method:u,response:d,iterator:f,cursor:p,customErrors:m,args:h}=Mo.parse(c),te=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,ne=jo.parse(te),g=h?fe(h):{query:{},body:{},headers:{}},re=de(ne),ie={...g?.headers??{},...re},_=p?.token??null,y=null,ae=null,x=[],S=[],oe=[],se=a,w=p?.position??0,le=!0,T=!0;do{le?le=!1:w=0,_!==null&&(f.in===`query`?g.query[f.key]=_.toString():f.in===`body`&&(g.body[f.key]=_));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${ee}${l}`,queryParams:g?.query,method:u,headers:ie,body:g?.body,customErrorConfigs:m})}catch(t){let n=t;return{block:e,successful:!1,errors:[t],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}y=_,S=d?.dataKey?t.data[d?.dataKey]:t.data;let r=S?.slice(w,se);se-=r.length,w+=r.length,oe.push(t),x=x.concat(r),ae=t?.status,_=d?.nextKey?t.data[d?.nextKey]:void 0,r.length===S.length&&se===0&&(w=0,y=_),T=v(_)&&x.length<a}while(b(_)&&x.length<a&&S?.length>0);let pe=Io(x,d);return{block:e,successful:!0,output:{data:pe,raw:oe,statusCode:ae,next:T?void 0:y,position:T?void 0:w}}},Io=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Lo=J({type:Z(`basic`),username:U().optional(),password:U().optional(),encoding:U().optional()}),Ro=J({type:Z(`bearer`),token:U(),includeBearer:K().optional().default(!0)}),zo=J({type:Z(`oauth2`),authorizationUrl:U().optional(),authorizationParams:Y(U(),U()).optional(),tokenUrl:U().optional(),tokenParams:Y(U(),U()).optional(),tokenExpiresIn:G().optional(),tokenRefreshExpiresIn:G().optional(),token:U(),includeBearer:K().optional().default(!0),scopes:U().optional()}),Bo=xa(`type`,[Lo,Ro,zo]),Vo=J({baseUrl:U(),url:U(),method:X(le),authorization:Bo.optional(),response:J({collection:K().optional(),indexField:U().optional(),dataKey:U().optional()}).optional(),customErrors:w.array().optional(),args:J({name:U(),value:q(),in:X(T),condition:U().optional()}).array().optional()}),Ho=J({data:q().optional(),raw:q().optional(),statusCode:G(),message:U().optional()}).optional(),Uo=async({block:e,params:t})=>{let n=ue.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||C(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?ce({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:ee,response:l,authorization:u,customErrors:d,args:f}=Vo.parse(o),p=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,m=f?fe(f):{query:{},body:{},headers:{}},h=b(u)?u:Bo.parse(p),te=de(h),ne={...m?.headers??{},...te},g;try{g=await n.performRequest({httpClient:e.httpClient,url:`${s}${c}`,queryParams:m?.query,method:ee,headers:ne,body:m?.body,customErrorConfigs:d})}catch(t){let n=t;return{block:e,successful:!1,errors:[t],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let re=l?.dataKey?g.data[l?.dataKey]:g.data,ie=Wo(re,l);return{block:e,successful:!0,output:{data:ie,raw:g,statusCode:g?.status,message:g?.message}}},Wo=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Go=J({targetFieldKey:U(),type:X([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:K().default(!1),custom:K().default(!1),hidden:K().default(!1),properties:Ka(()=>Go).array().optional()}),Ko=J({fields:Go.array().optional(),dataSource:U()}),qo=J({data:q()});let Jo=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Yo=({value:e,type:t,format:n})=>{if(v(e))return null;switch(t){case Jo.String:return oe({value:e});case Jo.Number:return S({value:e});case Jo.Boolean:return ae({value:e});case Jo.DateTimeString:return x({value:e,format:n});default:return e}},Xo=e=>{let t=Object.values(Jo);return t.includes(e)},Zo=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>Qo(e,t)):Qo(e.result,t),{block:{...e,result:n},successful:!0}},Qo=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Xo(i)&&(!t.custom&&b(n[r])?n[r]=Yo({value:e[r],type:i}):n.unified_custom_fields&&b(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Yo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},$o=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Ko.parse(t),i=C(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>ts(e,n)):ts(i,n),{block:{...e},successful:!0,output:{data:a}}},es=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?ts(t,e.properties):t):typeof t==`object`&&t?ts(t,e.properties):t,ts=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;i===`object`?!t.custom&&b(n[r])?n[r]=es(t,e[r]):n.unified_custom_fields&&b(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=es(t,e.unified_custom_fields?.[r])):Xo(i)&&(!t.custom&&b(n[r])?n[r]=Yo({value:e[r],type:i}):n.unified_custom_fields&&b(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Yo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e}({});const ns={[$.TYPECAST]:{v1:{fn:Zo},v2:{fn:$o,inputSchema:Ko,outputSchema:qo}},[$.MAP_FIELDS]:{v1:{fn:uo},v2:{fn:yo,inputSchema:_o,outputSchema:vo}},[$.REQUEST]:{v1:{fn:Uo,inputSchema:Vo,outputSchema:Ho}},[$.GROUP_DATA]:{v1:{fn:lo,inputSchema:so,outputSchema:co}},[$.PAGINATED_REQUEST]:{v1:{fn:Fo,inputSchema:Mo,outputSchema:No}}},rs=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch{return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},os={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=ns}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:rs(i,e)}:i}};export{Bo as AUTHENTICATION_SCHEMA,Se as COMPOSITE_ID_LATEST_VERSION,Ce as CoreError,$ as StepFunctionName,os as StepFunctionsFactory,ro as areCursorsEqual,Me as decodeCompositeId,je as encodeCompositeId,to as expandCursor,me as getCategoryDetails,Ve as isCompositeId,oo as isCoreError,io as isCursorEmpty,he as isValidCategory,$a as minifyCursor,ao as updateCursor};
26
+ })));`),t.write(`newResult[${A(e)}] = ${n}.value`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},i,a=Qe,o=!Ue.jitless,s=$e,c=o&&s.value,l=t.catchall,u;e._zod.parse=(s,d)=>{u??=n.value;let f=s.value;if(!a(f))return s.issues.push({expected:`object`,code:`invalid_type`,input:f,inst:e}),s;let p=[];if(o&&c&&d?.async===!1&&d.jitless!==!0)i||=r(t.shape),s=i(s,d);else{s.value={};let e=u.shape;for(let t of u.keys){let n=e[t],r=n._zod.run({value:f[t],issues:[]},d),i=n._zod.optin===`optional`&&n._zod.optout===`optional`;r instanceof Promise?p.push(r.then(e=>i?er(e,s,t,f):$n(e,s,t))):i?er(r,s,t,f):$n(r,s,t)}}if(!l)return p.length?Promise.all(p).then(()=>s):s;let m=[],h=u.keySet,g=l._zod,ee=g.def.type;for(let e of Object.keys(f)){if(h.has(e))continue;if(ee===`never`){m.push(e);continue}let t=g.run({value:f[e],issues:[]},d);t instanceof Promise?p.push(t.then(t=>$n(t,s,e))):$n(t,s,e)}return m.length&&s.issues.push({code:`unrecognized_keys`,keys:m,input:f,inst:e}),p.length?Promise.all(p).then(()=>s):s}});function nr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;return t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>I(e,r,O())))}),t}const rr=D(`$ZodUnion`,(e,t)=>{z.init(e,t),k(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),k(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),k(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),k(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>Je(e.source)).join(`|`)})$`)}}),e._zod.parse=(n,r)=>{let i=!1,a=[];for(let e of t.options){let t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)a.push(t),i=!0;else{if(t.issues.length===0)return t;a.push(t)}}return i?Promise.all(a).then(t=>nr(t,n,e,r)):nr(a,n,e,r)}}),ir=D(`$ZodDiscriminatedUnion`,(e,t)=>{rr.init(e,t);let n=e._zod.parse;k(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=Ke(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!Qe(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,input:o,path:[t.discriminator],inst:e}),i)}}),ar=D(`$ZodIntersection`,(e,t)=>{z.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n),o=i instanceof Promise||a instanceof Promise;return o?Promise.all([i,a]).then(([t,n])=>sr(e,t,n)):sr(e,i,a)}});function or(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(et(e)&&et(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=or(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=or(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function sr(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),P(e))return e;let r=or(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const cr=D(`$ZodRecord`,(e,t)=>{z.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!et(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...F(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...F(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({origin:`record`,code:`invalid_key`,issues:s.issues.map(e=>I(e,r,O())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...F(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...F(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),lr=D(`$ZodEnum`,(e,t)=>{z.init(e,t);let n=We(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>tt.has(typeof e)).map(e=>typeof e==`string`?j(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,r)=>{let i=t.value;return e._zod.values.has(i)||t.issues.push({code:`invalid_value`,values:n,input:i,inst:e}),t}}),ur=D(`$ZodLiteral`,(e,t)=>{z.init(e,t),e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?j(e):e?e.toString():String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),dr=D(`$ZodTransform`,(e,t)=>{z.init(e,t),e._zod.parse=(e,n)=>{let r=t.transform(e.value,e);if(n.async){let t=r instanceof Promise?r:Promise.resolve(r);return t.then(t=>(e.value=t,e))}if(r instanceof Promise)throw new He;return e.value=r,e}}),fr=D(`$ZodOptional`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Je(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>t.innerType._zod.optin===`optional`?t.innerType._zod.run(e,n):e.value===void 0?e:t.innerType._zod.run(e,n)}),pr=D(`$ZodNullable`,(e,t)=>{z.init(e,t),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${Je(e.source)}|null)$`):void 0}),k(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),mr=D(`$ZodDefault`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>hr(e,t)):hr(r,t)}});function hr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const gr=D(`$ZodPrefault`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),_r=D(`$ZodNonOptional`,(e,t)=>{z.init(e,t),k(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>vr(t,e)):vr(i,e)}});function vr(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const yr=D(`$ZodCatch`,(e,t)=>{z.init(e,t),e._zod.optin=`optional`,k(e._zod,`optout`,()=>t.innerType._zod.optout),k(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>I(e,n,O()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>I(e,n,O()))},input:e.value}),e.issues=[]),e)}}),br=D(`$ZodPipe`,(e,t)=>{z.init(e,t),k(e._zod,`values`,()=>t.in._zod.values),k(e._zod,`optin`,()=>t.in._zod.optin),k(e._zod,`optout`,()=>t.out._zod.optout),e._zod.parse=(e,n)=>{let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>xr(e,t,n)):xr(r,t,n)}});function xr(e,t,n){return P(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Sr=D(`$ZodReadonly`,(e,t)=>{z.init(e,t),k(e._zod,`propValues`,()=>t.innerType._zod.propValues),k(e._zod,`values`,()=>t.innerType._zod.values),k(e._zod,`optin`,()=>t.innerType._zod.optin),k(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Cr):Cr(r)}});function Cr(e){return e.value=Object.freeze(e.value),e}const wr=D(`$ZodLazy`,(e,t)=>{z.init(e,t),k(e._zod,`innerType`,()=>t.getter()),k(e._zod,`pattern`,()=>e._zod.innerType._zod.pattern),k(e._zod,`propValues`,()=>e._zod.innerType._zod.propValues),k(e._zod,`optin`,()=>e._zod.innerType._zod.optin),k(e._zod,`optout`,()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>{let r=e._zod.innerType;return r._zod.run(t,n)}}),Tr=D(`$ZodCustom`,(e,t)=>{R.init(e,t),z.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=>Er(t,n,r,e));Er(i,n,r,e)}});function Er(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(L(e))}}Symbol(`ZodOutput`),Symbol(`ZodInput`);var Dr=class{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}};function Or(){return new Dr}const kr=Or();function Ar(e,t){return new e({type:`string`,...N(t)})}function jr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function Mr(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function Nr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function Pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function Fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function Ir(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...N(t)})}function Lr(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...N(t)})}function Rr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function zr(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function Br(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function Vr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function Hr(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...N(t)})}function Ur(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...N(t)})}function Wr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function Gr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function Kr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function qr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function Jr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function Yr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function Xr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function Zr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function Qr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function $r(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function ei(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function ti(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function ni(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function ri(e,t){return new e({type:`number`,checks:[],...N(t)})}function ii(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function ai(e,t){return new e({type:`boolean`,...N(t)})}function oi(e){return new e({type:`unknown`})}function si(e,t){return new e({type:`never`,...N(t)})}function ci(e,t){return new tn({check:`less_than`,...N(t),value:e,inclusive:!1})}function li(e,t){return new tn({check:`less_than`,...N(t),value:e,inclusive:!0})}function ui(e,t){return new nn({check:`greater_than`,...N(t),value:e,inclusive:!1})}function di(e,t){return new nn({check:`greater_than`,...N(t),value:e,inclusive:!0})}function fi(e,t){return new rn({check:`multiple_of`,...N(t),value:e})}function pi(e,t){let n=new on({check:`max_length`,...N(t),maximum:e});return n}function mi(e,t){return new sn({check:`min_length`,...N(t),minimum:e})}function hi(e,t){return new cn({check:`length_equals`,...N(t),length:e})}function gi(e,t){return new un({check:`string_format`,format:`regex`,...N(t),pattern:e})}function _i(e){return new dn({check:`string_format`,format:`lowercase`,...N(e)})}function vi(e){return new fn({check:`string_format`,format:`uppercase`,...N(e)})}function yi(e,t){return new pn({check:`string_format`,format:`includes`,...N(t),includes:e})}function bi(e,t){return new mn({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function xi(e,t){return new hn({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function V(e){return new gn({check:`overwrite`,tx:e})}function Si(e){return V(t=>t.normalize(e))}function Ci(){return V(e=>e.trim())}function wi(){return V(e=>e.toLowerCase())}function Ti(){return V(e=>e.toUpperCase())}function Ei(e,t,n){return new e({type:`array`,element:t,...N(n)})}function Di(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...N(n)});return r}const Oi=D(`ZodISODateTime`,(e,t)=>{jn.init(e,t),W.init(e,t)});function ki(e){return $r(Oi,e)}const Ai=D(`ZodISODate`,(e,t)=>{Mn.init(e,t),W.init(e,t)});function ji(e){return ei(Ai,e)}const Mi=D(`ZodISOTime`,(e,t)=>{Nn.init(e,t),W.init(e,t)});function Ni(e){return ti(Mi,e)}const Pi=D(`ZodISODuration`,(e,t)=>{Pn.init(e,t),W.init(e,t)});function Fi(e){return ni(Pi,e)}const Ii=(e,t)=>{pt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>gt(e,t)},flatten:{value:t=>ht(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})};D(`ZodError`,Ii);const Li=D(`ZodError`,Ii,{Parent:Error}),Ri=_t(Li),zi=vt(Li),Bi=yt(Li),Vi=xt(Li),H=D(`ZodType`,(e,t)=>(z.init(e,t),e.def=t,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),e.clone=(t,n)=>M(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>Ri(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Bi(e,t,n),e.parseAsync=async(t,n)=>zi(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Vi(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(Xa(t,n)),e.superRefine=t=>e.check(Za(t)),e.overwrite=t=>e.check(V(t)),e.optional=()=>ja(e),e.nullable=()=>Na(e),e.nullish=()=>ja(Na(e)),e.nonoptional=t=>za(e,t),e.array=()=>_a(e),e.or=t=>ba([e,t]),e.and=t=>wa(e,t),e.transform=t=>Ua(e,ka(t)),e.default=t=>Fa(e,t),e.prefault=t=>La(e,t),e.catch=t=>Va(e,t),e.pipe=t=>Ua(e,t),e.readonly=()=>Ga(e),e.describe=t=>{let n=e.clone();return kr.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return kr.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return kr.get(e);let n=e.clone();return kr.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Hi=D(`_ZodString`,(e,t)=>{yn.init(e,t),H.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(gi(...t)),e.includes=(...t)=>e.check(yi(...t)),e.startsWith=(...t)=>e.check(bi(...t)),e.endsWith=(...t)=>e.check(xi(...t)),e.min=(...t)=>e.check(mi(...t)),e.max=(...t)=>e.check(pi(...t)),e.length=(...t)=>e.check(hi(...t)),e.nonempty=(...t)=>e.check(mi(1,...t)),e.lowercase=t=>e.check(_i(t)),e.uppercase=t=>e.check(vi(t)),e.trim=()=>e.check(Ci()),e.normalize=(...t)=>e.check(Si(...t)),e.toLowerCase=()=>e.check(wi()),e.toUpperCase=()=>e.check(Ti())}),Ui=D(`ZodString`,(e,t)=>{yn.init(e,t),Hi.init(e,t),e.email=t=>e.check(jr(Wi,t)),e.url=t=>e.check(Lr(qi,t)),e.jwt=t=>e.check(Qr(ca,t)),e.emoji=t=>e.check(Rr(Ji,t)),e.guid=t=>e.check(Mr(Gi,t)),e.uuid=t=>e.check(Nr(Ki,t)),e.uuidv4=t=>e.check(Pr(Ki,t)),e.uuidv6=t=>e.check(Fr(Ki,t)),e.uuidv7=t=>e.check(Ir(Ki,t)),e.nanoid=t=>e.check(zr(Yi,t)),e.guid=t=>e.check(Mr(Gi,t)),e.cuid=t=>e.check(Br(Xi,t)),e.cuid2=t=>e.check(Vr(Zi,t)),e.ulid=t=>e.check(Hr(Qi,t)),e.base64=t=>e.check(Yr(aa,t)),e.base64url=t=>e.check(Xr(oa,t)),e.xid=t=>e.check(Ur($i,t)),e.ksuid=t=>e.check(Wr(ea,t)),e.ipv4=t=>e.check(Gr(ta,t)),e.ipv6=t=>e.check(Kr(na,t)),e.cidrv4=t=>e.check(qr(ra,t)),e.cidrv6=t=>e.check(Jr(ia,t)),e.e164=t=>e.check(Zr(sa,t)),e.datetime=t=>e.check(ki(t)),e.date=t=>e.check(ji(t)),e.time=t=>e.check(Ni(t)),e.duration=t=>e.check(Fi(t))});function U(e){return Ar(Ui,e)}const W=D(`ZodStringFormat`,(e,t)=>{B.init(e,t),Hi.init(e,t)}),Wi=D(`ZodEmail`,(e,t)=>{Sn.init(e,t),W.init(e,t)}),Gi=D(`ZodGUID`,(e,t)=>{bn.init(e,t),W.init(e,t)}),Ki=D(`ZodUUID`,(e,t)=>{xn.init(e,t),W.init(e,t)}),qi=D(`ZodURL`,(e,t)=>{Cn.init(e,t),W.init(e,t)}),Ji=D(`ZodEmoji`,(e,t)=>{wn.init(e,t),W.init(e,t)}),Yi=D(`ZodNanoID`,(e,t)=>{Tn.init(e,t),W.init(e,t)}),Xi=D(`ZodCUID`,(e,t)=>{En.init(e,t),W.init(e,t)}),Zi=D(`ZodCUID2`,(e,t)=>{Dn.init(e,t),W.init(e,t)}),Qi=D(`ZodULID`,(e,t)=>{On.init(e,t),W.init(e,t)}),$i=D(`ZodXID`,(e,t)=>{kn.init(e,t),W.init(e,t)}),ea=D(`ZodKSUID`,(e,t)=>{An.init(e,t),W.init(e,t)}),ta=D(`ZodIPv4`,(e,t)=>{Fn.init(e,t),W.init(e,t)}),na=D(`ZodIPv6`,(e,t)=>{In.init(e,t),W.init(e,t)}),ra=D(`ZodCIDRv4`,(e,t)=>{Ln.init(e,t),W.init(e,t)}),ia=D(`ZodCIDRv6`,(e,t)=>{Rn.init(e,t),W.init(e,t)}),aa=D(`ZodBase64`,(e,t)=>{Bn.init(e,t),W.init(e,t)}),oa=D(`ZodBase64URL`,(e,t)=>{Hn.init(e,t),W.init(e,t)}),sa=D(`ZodE164`,(e,t)=>{Un.init(e,t),W.init(e,t)}),ca=D(`ZodJWT`,(e,t)=>{Gn.init(e,t),W.init(e,t)}),la=D(`ZodNumber`,(e,t)=>{Kn.init(e,t),H.init(e,t),e.gt=(t,n)=>e.check(ui(t,n)),e.gte=(t,n)=>e.check(di(t,n)),e.min=(t,n)=>e.check(di(t,n)),e.lt=(t,n)=>e.check(ci(t,n)),e.lte=(t,n)=>e.check(li(t,n)),e.max=(t,n)=>e.check(li(t,n)),e.int=t=>e.check(da(t)),e.safe=t=>e.check(da(t)),e.positive=t=>e.check(ui(0,t)),e.nonnegative=t=>e.check(di(0,t)),e.negative=t=>e.check(ci(0,t)),e.nonpositive=t=>e.check(li(0,t)),e.multipleOf=(t,n)=>e.check(fi(t,n)),e.step=(t,n)=>e.check(fi(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function G(e){return ri(la,e)}const ua=D(`ZodNumberFormat`,(e,t)=>{qn.init(e,t),la.init(e,t)});function da(e){return ii(ua,e)}const fa=D(`ZodBoolean`,(e,t)=>{Jn.init(e,t),H.init(e,t)});function K(e){return ai(fa,e)}const pa=D(`ZodUnknown`,(e,t)=>{Yn.init(e,t),H.init(e,t)});function q(){return oi(pa)}const ma=D(`ZodNever`,(e,t)=>{Xn.init(e,t),H.init(e,t)});function ha(e){return si(ma,e)}const ga=D(`ZodArray`,(e,t)=>{Qn.init(e,t),H.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(mi(t,n)),e.nonempty=t=>e.check(mi(1,t)),e.max=(t,n)=>e.check(pi(t,n)),e.length=(t,n)=>e.check(hi(t,n)),e.unwrap=()=>e.element});function _a(e,t){return Ei(ga,e,t)}const va=D(`ZodObject`,(e,t)=>{tr.init(e,t),H.init(e,t),k(e,`shape`,()=>t.shape),e.keyof=()=>X(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:q()}),e.loose=()=>e.clone({...e._zod.def,catchall:q()}),e.strict=()=>e.clone({...e._zod.def,catchall:ha()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>ot(e,t),e.merge=t=>st(e,t),e.pick=t=>it(e,t),e.omit=t=>at(e,t),e.partial=(...t)=>ct(Aa,e,t[0]),e.required=(...t)=>lt(Ra,e,t[0])});function J(e,t){let n={type:`object`,get shape(){return Xe(this,`shape`,{...e}),this.shape},...N(t)};return new va(n)}const ya=D(`ZodUnion`,(e,t)=>{rr.init(e,t),H.init(e,t),e.options=t.options});function ba(e,t){return new ya({type:`union`,options:e,...N(t)})}const xa=D(`ZodDiscriminatedUnion`,(e,t)=>{ya.init(e,t),ir.init(e,t)});function Sa(e,t,n){return new xa({type:`union`,options:t,discriminator:e,...N(n)})}const Ca=D(`ZodIntersection`,(e,t)=>{ar.init(e,t),H.init(e,t)});function wa(e,t){return new Ca({type:`intersection`,left:e,right:t})}const Ta=D(`ZodRecord`,(e,t)=>{cr.init(e,t),H.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Y(e,t,n){return new Ta({type:`record`,keyType:e,valueType:t,...N(n)})}const Ea=D(`ZodEnum`,(e,t)=>{lr.init(e,t),H.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ea({...t,checks:[],...N(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ea({...t,checks:[],...N(r),entries:i})}});function X(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Ea({type:`enum`,entries:n,...N(t)})}const Da=D(`ZodLiteral`,(e,t)=>{ur.init(e,t),H.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Z(e,t){return new Da({type:`literal`,values:Array.isArray(e)?e:[e],...N(t)})}const Oa=D(`ZodTransform`,(e,t)=>{dr.init(e,t),H.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if(typeof r==`string`)n.issues.push(L(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,t.continue??=!0,n.issues.push(L(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function ka(e){return new Oa({type:`transform`,transform:e})}const Aa=D(`ZodOptional`,(e,t)=>{fr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ja(e){return new Aa({type:`optional`,innerType:e})}const Ma=D(`ZodNullable`,(e,t)=>{pr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Na(e){return new Ma({type:`nullable`,innerType:e})}const Pa=D(`ZodDefault`,(e,t)=>{mr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Fa(e,t){return new Pa({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const Ia=D(`ZodPrefault`,(e,t)=>{gr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function La(e,t){return new Ia({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const Ra=D(`ZodNonOptional`,(e,t)=>{_r.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType});function za(e,t){return new Ra({type:`nonoptional`,innerType:e,...N(t)})}const Ba=D(`ZodCatch`,(e,t)=>{yr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Va(e,t){return new Ba({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const Ha=D(`ZodPipe`,(e,t)=>{br.init(e,t),H.init(e,t),e.in=t.in,e.out=t.out});function Ua(e,t){return new Ha({type:`pipe`,in:e,out:t})}const Wa=D(`ZodReadonly`,(e,t)=>{Sr.init(e,t),H.init(e,t)});function Ga(e){return new Wa({type:`readonly`,innerType:e})}const Ka=D(`ZodLazy`,(e,t)=>{wr.init(e,t),H.init(e,t),e.unwrap=()=>e._zod.def.getter()});function qa(e){return new Ka({type:`lazy`,getter:e})}const Ja=D(`ZodCustom`,(e,t)=>{Tr.init(e,t),H.init(e,t)});function Ya(e){let t=new R({check:`custom`});return t._zod.check=e,t}function Xa(e,t={}){return Di(Ja,e,t)}function Za(e){let t=Ya(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(L(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(L(r))}},e(n.value,n)));return t}const Qa=J({r:Y(U(),J({n:G().optional().nullable(),c:U().optional().nullable(),p:G().optional().nullable()})),v:G(),t:G()}),$a=J({remote:Y(U(),J({pageNumber:G().optional(),providerPageCursor:U().optional(),position:G().optional()})),version:G(),timestamp:G()}),eo=e=>t(JSON.stringify(to(e))),to=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},no=t=>{try{if(b(t)){let n=e(t),r=JSON.parse(n),i=Qa.parse(r);return ro(i)}else return $a.parse(t),t}catch{return null}},ro=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},io=(e,t)=>{let r=typeof e==`string`?no(e):e,i=typeof t==`string`?no(t):t;if(r===null||i===null)return r===i;let{timestamp:a,...o}=r,{timestamp:s,...c}=i;return n(o)===n(c)},ao=({cursor:e,ignoreStepIndex:t})=>y(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return(y(t)||r!==t.toString())&&(n=n&&y(i.pageNumber)&&y(i.position)&&y(i.providerPageCursor)),n},!0),oo=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=y(n)&&y(r)&&y(i);return y(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},so=e=>e instanceof Ce,co=J({stepsDataToGroup:_a(U()),isSingleRecord:K().optional()}),lo=J({data:q()}),uo=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=co.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=x(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},fo=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=po(r,a,i),s=mo(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=mo(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},po=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),mo=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=ho(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},ho=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=w(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},go=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return r;case`country_alpha3code_by_alpha3code`:return l;case`country_code_by_country_code`:return m;case`country_name_by_country_name`:return _;case`country_name_by_alpha3code`:return ee;case`country_name_by_alpha2code`:return g;case`country_name_by_country_code`:return te;case`country_alpha3code_by_alpha2code`:return c;case`country_alpha3code_by_country_name`:return d;case`country_alpha3code_by_country_code`:return u;case`country_alpha2code_by_alpha3code`:return i;case`country_alpha2code_by_country_name`:return s;case`country_alpha2code_by_country_code`:return o;case`country_code_by_alpha2code`:return f;case`country_code_by_alpha3code`:return p;case`country_code_by_country_name`:return h;case`country_subdivisions_by_alpha2code`:return v;case`country_subdivision_code_by_subdivision_name`:return ne;case`country_alpha2code_by_citizenship`:return a;case`country_subdivision_name_by_subdivision_code`:return re;default:return}},_o=J({targetFieldKey:U(),alias:U().optional(),expression:U().optional(),values:q().optional(),type:X([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:K().default(!1),custom:K().default(!1),hidden:K().default(!1),enumMapper:J({matcher:U().or(J({matchExpression:U(),value:U()}).array())}).optional(),properties:qa(()=>_o).array().optional()}),vo=J({fields:_o.array(),dataSource:U()}),yo=J({data:q()}),bo=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i}=vo.parse(t),a=w(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!a)return{block:e,successful:!0};let o;if(Array.isArray(a))o=a.map(e=>{let t=Q(r,e);return n.push(...t?.errors||[]),t?.record});else{let e=Q(r,a);o=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:o},errors:Object.keys(n).length>0?n:void 0}},xo=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=To(r,t),a=Q(e.properties,i);return x(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},So=(e,t,n)=>{if(e.expression)try{let r=w(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=Q(e.properties,t);return x(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=Q(e.properties,r);return x(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},Co=(e,t,n)=>{let r=x(e.values)?e.values:t,i=Q(e.properties,r);return x(i?.errors)&&n.push(...i.errors),i?.record},wo=(e,t,n)=>{if(!y(e.properties))return e.array&&Array.isArray(e.values)?xo(e,t,n):e.array&&e.expression?So(e,t,n):Co(e,t,n)},Q=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=wo(a,t,r),e===void 0)continue}else{let{error:n,value:i}=Eo(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:r.length>0?r:void 0}},To=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if(oe(e))try{return w(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>To(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=To(r,t);return n}return e},Eo=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return Do(n,t,e);case`enum`:return Oo(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},Do=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=w(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},Oo=(e,t,n)=>{let r=Do(e,t,n),i=x(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if(b(a)){let n=go(a);if(x(n)){let e=x(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=w(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},ko=J({type:Z(`basic`),username:U().optional(),password:U().optional(),encoding:U().optional()}),Ao=J({type:Z(`bearer`),token:U(),includeBearer:K().optional().default(!0)}),jo=J({type:Z(`oauth2`),authorizationUrl:U().optional(),authorizationParams:Y(U(),U()).optional(),tokenUrl:U().optional(),tokenParams:Y(U(),U()).optional(),tokenExpiresIn:G().optional(),tokenRefreshExpiresIn:G().optional(),token:U(),includeBearer:K().optional().default(!0),scopes:U().optional()}),Mo=Sa(`type`,[ko,Ao,jo]),No=J({baseUrl:U(),url:U(),method:X(ce),response:J({indexField:U().optional(),dataKey:U().optional(),nextKey:U().optional()}).optional(),iterator:J({key:U(),in:X(E)}),cursor:J({token:U().optional().nullable(),position:G().optional().nullable()}).optional(),customErrors:T.array().optional(),args:J({name:U(),value:q(),in:X(E),condition:U().optional()}).array().optional()}),Po=J({data:q().optional(),raw:q().optional(),statusCode:G(),message:U().optional(),next:U().optional().nullable(),position:G().optional()}).optional(),Fo=25,Io=async({block:e,params:t})=>{let n=le.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?Fo:i,o=r?r.filter(t=>!t.condition||w(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?se({...t,args:o},e):{},c={...s,customErrors:t?.customErrors},{baseUrl:l,url:u,method:d,response:f,iterator:p,cursor:m,customErrors:h,args:g}=No.parse(c),ee=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,te=Mo.parse(ee),_=g?de(g):{query:{},body:{},headers:{}},ne=ue(te),re={..._?.headers??{},...ne},v=m?.token??null,b=null,ie=null,S=[],C=[],ae=[],oe=a,T=m?.position??0,ce=!0,E=!0;do{ce?ce=!1:T=0,v!==null&&(p.in===`query`?_.query[p.key]=v.toString():p.in===`body`&&(_.body[p.key]=v));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${l}${u}`,queryParams:_?.query,method:d,headers:re,body:_?.body,customErrorConfigs:h})}catch(t){let n=t;return{block:e,successful:!1,errors:[fe(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}b=v,C=f?.dataKey?t.data[f?.dataKey]:t.data;let r=C?.slice(T,oe);oe-=r.length,T+=r.length,ae.push(t),S=S.concat(r),ie=t?.status,v=f?.nextKey?t.data[f?.nextKey]:void 0,r.length===C.length&&oe===0&&(T=0,b=v),E=y(v)&&S.length<a}while(x(v)&&S.length<a&&C?.length>0);let pe=Lo(S,f);return{block:e,successful:!0,output:{data:pe,raw:ae,statusCode:ie,next:E?void 0:b,position:E?void 0:T}}},Lo=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Ro=J({type:Z(`basic`),username:U().optional(),password:U().optional(),encoding:U().optional()}),zo=J({type:Z(`bearer`),token:U(),includeBearer:K().optional().default(!0)}),Bo=J({type:Z(`oauth2`),authorizationUrl:U().optional(),authorizationParams:Y(U(),U()).optional(),tokenUrl:U().optional(),tokenParams:Y(U(),U()).optional(),tokenExpiresIn:G().optional(),tokenRefreshExpiresIn:G().optional(),token:U(),includeBearer:K().optional().default(!0),scopes:U().optional()}),Vo=Sa(`type`,[Ro,zo,Bo]),Ho=J({baseUrl:U(),url:U(),method:X(ce),authorization:Vo.optional(),response:J({collection:K().optional(),indexField:U().optional(),dataKey:U().optional()}).optional(),customErrors:T.array().optional(),args:J({name:U(),value:q(),in:X(E),condition:U().optional()}).array().optional()}),Uo=J({data:q().optional(),raw:q().optional(),statusCode:G(),message:U().optional()}).optional(),Wo=async({block:e,params:t})=>{let n=le.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||w(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?se({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:l,response:u,authorization:d,customErrors:f,args:p}=Ho.parse(o),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,h=p?de(p):{query:{},body:{},headers:{}},g=x(d)?d:Vo.parse(m),ee=ue(g),te={...h?.headers??{},...ee},_;try{_=await n.performRequest({httpClient:e.httpClient,url:`${s}${c}`,queryParams:h?.query,method:l,headers:te,body:h?.body,customErrorConfigs:f})}catch(t){let n=t;return{block:e,successful:!1,errors:[fe(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let ne=u?.dataKey?_.data[u?.dataKey]:_.data,re=Go(ne,u);return{block:e,successful:!0,output:{data:re,raw:_,statusCode:_?.status,message:_?.message}}},Go=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Ko=J({targetFieldKey:U(),type:X([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:K().default(!1),custom:K().default(!1),hidden:K().default(!1),properties:qa(()=>Ko).array().optional()}),qo=J({fields:Ko.array().optional(),dataSource:U()}),Jo=J({data:q()});let Yo=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Xo=({value:e,type:t,format:n})=>{if(y(e))return null;switch(t){case Yo.String:return ae({value:e});case Yo.Number:return C({value:e});case Yo.Boolean:return ie({value:e});case Yo.DateTimeString:return S({value:e,format:n});default:return e}},Zo=e=>{let t=Object.values(Yo);return t.includes(e)},Qo=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>$o(e,t)):$o(e.result,t),{block:{...e,result:n},successful:!0}},$o=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Zo(i)&&(!t.custom&&x(n[r])?n[r]=Xo({value:e[r],type:i}):n.unified_custom_fields&&x(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Xo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},es=async({block:e,params:t})=>{let{fields:n,dataSource:r}=qo.parse(t),i=w(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>ns(e,n)):ns(i,n),{block:{...e},successful:!0,output:{data:a}}},ts=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?ns(t,e.properties):t):typeof t==`object`&&t?ns(t,e.properties):t,ns=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;i===`object`?!t.custom&&x(n[r])?n[r]=ts(t,e[r]):n.unified_custom_fields&&x(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=ts(t,e.unified_custom_fields?.[r])):Zo(i)&&(!t.custom&&x(n[r])?n[r]=Xo({value:e[r],type:i}):n.unified_custom_fields&&x(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Xo({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e}({});const rs={[$.TYPECAST]:{v1:{fn:Qo},v2:{fn:es,inputSchema:qo,outputSchema:Jo}},[$.MAP_FIELDS]:{v1:{fn:fo},v2:{fn:bo,inputSchema:vo,outputSchema:yo}},[$.REQUEST]:{v1:{fn:Wo,inputSchema:Ho,outputSchema:Uo}},[$.GROUP_DATA]:{v1:{fn:uo,inputSchema:co,outputSchema:lo}},[$.PAGINATED_REQUEST]:{v1:{fn:Io,inputSchema:No,outputSchema:Po}}},os=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch{return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},ss={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=rs}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:os(i,e)}:i}};export{Vo as AUTHENTICATION_SCHEMA,Se as COMPOSITE_ID_LATEST_VERSION,Ce as CoreError,$ as StepFunctionName,ss as StepFunctionsFactory,io as areCursorsEqual,Me as decodeCompositeId,je as encodeCompositeId,no as expandCursor,me as getCategoryDetails,Ve as isCompositeId,so as isCoreError,ao as isCursorEmpty,he as isValidCategory,eo as minifyCursor,oo as updateCursor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.57.0",
3
+ "version": "1.57.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",