@stackone/connect-sdk 1.52.0 → 1.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -628,7 +628,10 @@ declare class ConnectSDKError extends Error {
|
|
|
628
628
|
//#region src/meta/types.d.ts
|
|
629
629
|
interface ConfigOperation {
|
|
630
630
|
id: string;
|
|
631
|
+
label: string;
|
|
631
632
|
description: string;
|
|
633
|
+
tags?: string[];
|
|
634
|
+
schemaType: 'native' | 'unified';
|
|
632
635
|
[key: string]: unknown;
|
|
633
636
|
}
|
|
634
637
|
interface ConfigAuthentication {
|
|
@@ -660,9 +663,10 @@ type ConfigMeta = {
|
|
|
660
663
|
authentication: AuthenticationConfig[];
|
|
661
664
|
actions: {
|
|
662
665
|
id: string;
|
|
663
|
-
|
|
666
|
+
label: string;
|
|
664
667
|
description: string;
|
|
665
668
|
schema_type: string;
|
|
669
|
+
tags?: string[];
|
|
666
670
|
operation_details?: ConfigOperation;
|
|
667
671
|
authentication: AuthenticationConfig[];
|
|
668
672
|
}[];
|
package/dist/index.d.ts
CHANGED
|
@@ -628,7 +628,10 @@ declare class ConnectSDKError extends Error {
|
|
|
628
628
|
//#region src/meta/types.d.ts
|
|
629
629
|
interface ConfigOperation {
|
|
630
630
|
id: string;
|
|
631
|
+
label: string;
|
|
631
632
|
description: string;
|
|
633
|
+
tags?: string[];
|
|
634
|
+
schemaType: 'native' | 'unified';
|
|
632
635
|
[key: string]: unknown;
|
|
633
636
|
}
|
|
634
637
|
interface ConfigAuthentication {
|
|
@@ -660,9 +663,10 @@ type ConfigMeta = {
|
|
|
660
663
|
authentication: AuthenticationConfig[];
|
|
661
664
|
actions: {
|
|
662
665
|
id: string;
|
|
663
|
-
|
|
666
|
+
label: string;
|
|
664
667
|
description: string;
|
|
665
668
|
schema_type: string;
|
|
669
|
+
tags?: string[];
|
|
666
670
|
operation_details?: ConfigOperation;
|
|
667
671
|
authentication: AuthenticationConfig[];
|
|
668
672
|
}[];
|
package/dist/index.js
CHANGED
|
@@ -27,4 +27,4 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
27
27
|
...iss,
|
|
28
28
|
path: iss.path ? [${k(e)}, ...iss.path] : [${k(e)}]
|
|
29
29
|
})));`),t.write(`newResult[${k(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=de,o=!E.jitless,s=fe,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?pn(e,s,t,f):H(e,s,t))):i?pn(r,s,t,f):H(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=>H(t,s,e))):H(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 hn(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,D())))}),t}const gn=C(`$ZodUnion`,(e,t)=>{B.init(e,t),O(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),O(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),O(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),O(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=>se(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=>hn(t,n,e,r)):hn(a,n,e,r)}}),_n=C(`$ZodDiscriminatedUnion`,(e,t)=>{gn.init(e,t);let n=e._zod.parse;O(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=ae(()=>{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(!de(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)}}),vn=C(`$ZodIntersection`,(e,t)=>{B.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])=>bn(e,t,n)):bn(e,i,a)}});function yn(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(pe(e)&&pe(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=yn(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=yn(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 bn(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=yn(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const xn=C(`$ZodRecord`,(e,t)=>{B.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!pe(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,D())),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}}),Sn=C(`$ZodEnum`,(e,t)=>{B.init(e,t);let n=re(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>me.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}}),Cn=C(`$ZodLiteral`,(e,t)=>{B.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}}),wn=C(`$ZodTransform`,(e,t)=>{B.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 T;return e.value=r,e}}),Tn=C(`$ZodOptional`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,O(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),O(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${se(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)}),En=C(`$ZodNullable`,(e,t)=>{B.init(e,t),O(e._zod,`optin`,()=>t.innerType._zod.optin),O(e._zod,`optout`,()=>t.innerType._zod.optout),O(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${se(e.source)}|null)$`):void 0}),O(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)}),Dn=C(`$ZodDefault`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,O(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=>On(e,t)):On(r,t)}});function On(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const kn=C(`$ZodPrefault`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,O(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))}),An=C(`$ZodNonOptional`,(e,t)=>{B.init(e,t),O(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 Mn=C(`$ZodCatch`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,O(e._zod,`optout`,()=>t.innerType._zod.optout),O(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,D()))},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,D()))},input:e.value}),e.issues=[]),e)}}),Nn=C(`$ZodPipe`,(e,t)=>{B.init(e,t),O(e._zod,`values`,()=>t.in._zod.values),O(e._zod,`optin`,()=>t.in._zod.optin),O(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=>Pn(e,t,n)):Pn(r,t,n)}});function Pn(e,t,n){return N(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Fn=C(`$ZodReadonly`,(e,t)=>{B.init(e,t),O(e._zod,`propValues`,()=>t.innerType._zod.propValues),O(e._zod,`values`,()=>t.innerType._zod.values),O(e._zod,`optin`,()=>t.innerType._zod.optin),O(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(In):In(r)}});function In(e){return e.value=Object.freeze(e.value),e}const Ln=C(`$ZodLazy`,(e,t)=>{B.init(e,t),O(e._zod,`innerType`,()=>t.getter()),O(e._zod,`pattern`,()=>e._zod.innerType._zod.pattern),O(e._zod,`propValues`,()=>e._zod.innerType._zod.propValues),O(e._zod,`optin`,()=>e._zod.innerType._zod.optin),O(e._zod,`optout`,()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>{let r=e._zod.innerType;return r._zod.run(t,n)}}),Rn=C(`$ZodCustom`,(e,t)=>{R.init(e,t),B.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>zn(t,n,r,e));zn(i,n,r,e)}});function zn(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 Bn=Symbol(`ZodOutput`),Vn=Symbol(`ZodInput`);var Hn=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 Un(){return new Hn}const Wn=Un();function Gn(e,t){return new e({type:`string`,...M(t)})}function Kn(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...M(t)})}function qn(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...M(t)})}function Jn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...M(t)})}function Yn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...M(t)})}function Xn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...M(t)})}function Zn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...M(t)})}function Qn(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...M(t)})}function $n(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...M(t)})}function er(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...M(t)})}function tr(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...M(t)})}function nr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...M(t)})}function rr(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...M(t)})}function ir(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...M(t)})}function ar(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...M(t)})}function or(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...M(t)})}function sr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...M(t)})}function cr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...M(t)})}function lr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...M(t)})}function ur(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...M(t)})}function dr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...M(t)})}function fr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...M(t)})}function pr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...M(t)})}function mr(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...M(t)})}function hr(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...M(t)})}function gr(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...M(t)})}function _r(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...M(t)})}function vr(e,t){return new e({type:`number`,checks:[],...M(t)})}function yr(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...M(t)})}function br(e,t){return new e({type:`boolean`,...M(t)})}function xr(e){return new e({type:`any`})}function Sr(e){return new e({type:`unknown`})}function Cr(e,t){return new e({type:`never`,...M(t)})}function wr(e,t){return new ht({check:`less_than`,...M(t),value:e,inclusive:!1})}function Tr(e,t){return new ht({check:`less_than`,...M(t),value:e,inclusive:!0})}function Er(e,t){return new gt({check:`greater_than`,...M(t),value:e,inclusive:!1})}function Dr(e,t){return new gt({check:`greater_than`,...M(t),value:e,inclusive:!0})}function Or(e,t){return new _t({check:`multiple_of`,...M(t),value:e})}function kr(e,t){let n=new yt({check:`max_length`,...M(t),maximum:e});return n}function Ar(e,t){return new bt({check:`min_length`,...M(t),minimum:e})}function jr(e,t){return new xt({check:`length_equals`,...M(t),length:e})}function Mr(e,t){return new St({check:`string_format`,format:`regex`,...M(t),pattern:e})}function Nr(e){return new Ct({check:`string_format`,format:`lowercase`,...M(e)})}function Pr(e){return new wt({check:`string_format`,format:`uppercase`,...M(e)})}function Fr(e,t){return new Tt({check:`string_format`,format:`includes`,...M(t),includes:e})}function Ir(e,t){return new Et({check:`string_format`,format:`starts_with`,...M(t),prefix:e})}function Lr(e,t){return new Dt({check:`string_format`,format:`ends_with`,...M(t),suffix:e})}function U(e){return new Ot({check:`overwrite`,tx:e})}function Rr(e){return U(t=>t.normalize(e))}function zr(){return U(e=>e.trim())}function Br(){return U(e=>e.toLowerCase())}function Vr(){return U(e=>e.toUpperCase())}function Hr(e,t,n){return new e({type:`array`,element:t,...M(n)})}function Ur(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...M(n)});return r}const Wr=C(`ZodISODateTime`,(e,t)=>{Ut.init(e,t),K.init(e,t)});function Gr(e){return mr(Wr,e)}const Kr=C(`ZodISODate`,(e,t)=>{Wt.init(e,t),K.init(e,t)});function qr(e){return hr(Kr,e)}const Jr=C(`ZodISOTime`,(e,t)=>{Gt.init(e,t),K.init(e,t)});function Yr(e){return gr(Jr,e)}const Xr=C(`ZodISODuration`,(e,t)=>{Kt.init(e,t),K.init(e,t)});function Zr(e){return _r(Xr,e)}const Qr=(e,t)=>{Ee.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Oe(e,t)},flatten:{value:t=>De(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get(){return e.issues.length===0}}})},$r=C(`ZodError`,Qr),ei=C(`ZodError`,Qr,{Parent:Error}),ti=ke(ei),ni=je(ei),ri=Ne(ei),ii=Fe(ei),W=C(`ZodType`,(e,t)=>(B.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)=>ti(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>ri(e,t,n),e.parseAsync=async(t,n)=>ni(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ii(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(ga(t,n)),e.superRefine=t=>e.check(_a(t)),e.overwrite=t=>e.check(U(t)),e.optional=()=>Zi(e),e.nullable=()=>$i(e),e.nullish=()=>Zi($i(e)),e.nonoptional=t=>aa(e,t),e.array=()=>Ii(e),e.or=t=>zi([e,t]),e.and=t=>Ui(e,t),e.transform=t=>la(e,Yi(t)),e.default=t=>ta(e,t),e.prefault=t=>ra(e,t),e.catch=t=>sa(e,t),e.pipe=t=>la(e,t),e.readonly=()=>da(e),e.describe=t=>{let n=e.clone();return Wn.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return Wn.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return Wn.get(e);let n=e.clone();return Wn.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ai=C(`_ZodString`,(e,t)=>{jt.init(e,t),W.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(Mr(...t)),e.includes=(...t)=>e.check(Fr(...t)),e.startsWith=(...t)=>e.check(Ir(...t)),e.endsWith=(...t)=>e.check(Lr(...t)),e.min=(...t)=>e.check(Ar(...t)),e.max=(...t)=>e.check(kr(...t)),e.length=(...t)=>e.check(jr(...t)),e.nonempty=(...t)=>e.check(Ar(1,...t)),e.lowercase=t=>e.check(Nr(t)),e.uppercase=t=>e.check(Pr(t)),e.trim=()=>e.check(zr()),e.normalize=(...t)=>e.check(Rr(...t)),e.toLowerCase=()=>e.check(Br()),e.toUpperCase=()=>e.check(Vr())}),oi=C(`ZodString`,(e,t)=>{jt.init(e,t),ai.init(e,t),e.email=t=>e.check(Kn(si,t)),e.url=t=>e.check(Qn(ui,t)),e.jwt=t=>e.check(pr(Ti,t)),e.emoji=t=>e.check($n(di,t)),e.guid=t=>e.check(qn(ci,t)),e.uuid=t=>e.check(Jn(li,t)),e.uuidv4=t=>e.check(Yn(li,t)),e.uuidv6=t=>e.check(Xn(li,t)),e.uuidv7=t=>e.check(Zn(li,t)),e.nanoid=t=>e.check(er(fi,t)),e.guid=t=>e.check(qn(ci,t)),e.cuid=t=>e.check(tr(pi,t)),e.cuid2=t=>e.check(nr(mi,t)),e.ulid=t=>e.check(rr(hi,t)),e.base64=t=>e.check(ur(Si,t)),e.base64url=t=>e.check(dr(Ci,t)),e.xid=t=>e.check(ir(gi,t)),e.ksuid=t=>e.check(ar(_i,t)),e.ipv4=t=>e.check(or(vi,t)),e.ipv6=t=>e.check(sr(yi,t)),e.cidrv4=t=>e.check(cr(bi,t)),e.cidrv6=t=>e.check(lr(xi,t)),e.e164=t=>e.check(fr(wi,t)),e.datetime=t=>e.check(Gr(t)),e.date=t=>e.check(qr(t)),e.time=t=>e.check(Yr(t)),e.duration=t=>e.check(Zr(t))});function G(e){return Gn(oi,e)}const K=C(`ZodStringFormat`,(e,t)=>{V.init(e,t),ai.init(e,t)}),si=C(`ZodEmail`,(e,t)=>{Pt.init(e,t),K.init(e,t)}),ci=C(`ZodGUID`,(e,t)=>{Mt.init(e,t),K.init(e,t)}),li=C(`ZodUUID`,(e,t)=>{Nt.init(e,t),K.init(e,t)}),ui=C(`ZodURL`,(e,t)=>{Ft.init(e,t),K.init(e,t)}),di=C(`ZodEmoji`,(e,t)=>{It.init(e,t),K.init(e,t)}),fi=C(`ZodNanoID`,(e,t)=>{Lt.init(e,t),K.init(e,t)}),pi=C(`ZodCUID`,(e,t)=>{Rt.init(e,t),K.init(e,t)}),mi=C(`ZodCUID2`,(e,t)=>{zt.init(e,t),K.init(e,t)}),hi=C(`ZodULID`,(e,t)=>{Bt.init(e,t),K.init(e,t)}),gi=C(`ZodXID`,(e,t)=>{Vt.init(e,t),K.init(e,t)}),_i=C(`ZodKSUID`,(e,t)=>{Ht.init(e,t),K.init(e,t)}),vi=C(`ZodIPv4`,(e,t)=>{qt.init(e,t),K.init(e,t)}),yi=C(`ZodIPv6`,(e,t)=>{Jt.init(e,t),K.init(e,t)}),bi=C(`ZodCIDRv4`,(e,t)=>{Yt.init(e,t),K.init(e,t)}),xi=C(`ZodCIDRv6`,(e,t)=>{Xt.init(e,t),K.init(e,t)}),Si=C(`ZodBase64`,(e,t)=>{Qt.init(e,t),K.init(e,t)}),Ci=C(`ZodBase64URL`,(e,t)=>{en.init(e,t),K.init(e,t)}),wi=C(`ZodE164`,(e,t)=>{tn.init(e,t),K.init(e,t)}),Ti=C(`ZodJWT`,(e,t)=>{rn.init(e,t),K.init(e,t)}),Ei=C(`ZodNumber`,(e,t)=>{an.init(e,t),W.init(e,t),e.gt=(t,n)=>e.check(Er(t,n)),e.gte=(t,n)=>e.check(Dr(t,n)),e.min=(t,n)=>e.check(Dr(t,n)),e.lt=(t,n)=>e.check(wr(t,n)),e.lte=(t,n)=>e.check(Tr(t,n)),e.max=(t,n)=>e.check(Tr(t,n)),e.int=t=>e.check(Oi(t)),e.safe=t=>e.check(Oi(t)),e.positive=t=>e.check(Er(0,t)),e.nonnegative=t=>e.check(Dr(0,t)),e.negative=t=>e.check(wr(0,t)),e.nonpositive=t=>e.check(Tr(0,t)),e.multipleOf=(t,n)=>e.check(Or(t,n)),e.step=(t,n)=>e.check(Or(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 q(e){return vr(Ei,e)}const Di=C(`ZodNumberFormat`,(e,t)=>{on.init(e,t),Ei.init(e,t)});function Oi(e){return yr(Di,e)}const ki=C(`ZodBoolean`,(e,t)=>{sn.init(e,t),W.init(e,t)});function J(e){return br(ki,e)}const Ai=C(`ZodAny`,(e,t)=>{cn.init(e,t),W.init(e,t)});function ji(){return xr(Ai)}const Mi=C(`ZodUnknown`,(e,t)=>{ln.init(e,t),W.init(e,t)});function Y(){return Sr(Mi)}const Ni=C(`ZodNever`,(e,t)=>{un.init(e,t),W.init(e,t)});function Pi(e){return Cr(Ni,e)}const Fi=C(`ZodArray`,(e,t)=>{fn.init(e,t),W.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Ar(t,n)),e.nonempty=t=>e.check(Ar(1,t)),e.max=(t,n)=>e.check(kr(t,n)),e.length=(t,n)=>e.check(jr(t,n)),e.unwrap=()=>e.element});function Ii(e,t){return Hr(Fi,e,t)}const Li=C(`ZodObject`,(e,t)=>{mn.init(e,t),W.init(e,t),O(e,`shape`,()=>t.shape),e.keyof=()=>Z(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Y()}),e.loose=()=>e.clone({...e._zod.def,catchall:Y()}),e.strict=()=>e.clone({...e._zod.def,catchall:Pi()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>ye(e,t),e.merge=t=>be(e,t),e.pick=t=>_e(e,t),e.omit=t=>ve(e,t),e.partial=(...t)=>xe(Xi,e,t[0]),e.required=(...t)=>Se(ia,e,t[0])});function X(e,t){let n={type:`object`,get shape(){return le(this,`shape`,{...e}),this.shape},...M(t)};return new Li(n)}const Ri=C(`ZodUnion`,(e,t)=>{gn.init(e,t),W.init(e,t),e.options=t.options});function zi(e,t){return new Ri({type:`union`,options:e,...M(t)})}const Bi=C(`ZodDiscriminatedUnion`,(e,t)=>{Ri.init(e,t),_n.init(e,t)});function Vi(e,t,n){return new Bi({type:`union`,options:t,discriminator:e,...M(n)})}const Hi=C(`ZodIntersection`,(e,t)=>{vn.init(e,t),W.init(e,t)});function Ui(e,t){return new Hi({type:`intersection`,left:e,right:t})}const Wi=C(`ZodRecord`,(e,t)=>{xn.init(e,t),W.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Gi(e,t,n){return new Wi({type:`record`,keyType:e,valueType:t,...M(n)})}const Ki=C(`ZodEnum`,(e,t)=>{Sn.init(e,t),W.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 Ki({...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 Ki({...t,checks:[],...M(r),entries:i})}});function Z(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Ki({type:`enum`,entries:n,...M(t)})}const qi=C(`ZodLiteral`,(e,t)=>{Cn.init(e,t),W.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 Q(e,t){return new qi({type:`literal`,values:Array.isArray(e)?e:[e],...M(t)})}const Ji=C(`ZodTransform`,(e,t)=>{wn.init(e,t),W.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 Yi(e){return new Ji({type:`transform`,transform:e})}const Xi=C(`ZodOptional`,(e,t)=>{Tn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Zi(e){return new Xi({type:`optional`,innerType:e})}const Qi=C(`ZodNullable`,(e,t)=>{En.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function $i(e){return new Qi({type:`nullable`,innerType:e})}const ea=C(`ZodDefault`,(e,t)=>{Dn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ta(e,t){return new ea({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const na=C(`ZodPrefault`,(e,t)=>{kn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ra(e,t){return new na({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const ia=C(`ZodNonOptional`,(e,t)=>{An.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function aa(e,t){return new ia({type:`nonoptional`,innerType:e,...M(t)})}const oa=C(`ZodCatch`,(e,t)=>{Mn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function sa(e,t){return new oa({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const ca=C(`ZodPipe`,(e,t)=>{Nn.init(e,t),W.init(e,t),e.in=t.in,e.out=t.out});function la(e,t){return new ca({type:`pipe`,in:e,out:t})}const ua=C(`ZodReadonly`,(e,t)=>{Fn.init(e,t),W.init(e,t)});function da(e){return new ua({type:`readonly`,innerType:e})}const fa=C(`ZodLazy`,(e,t)=>{Ln.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.getter()});function pa(e){return new fa({type:`lazy`,getter:e})}const ma=C(`ZodCustom`,(e,t)=>{Rn.init(e,t),W.init(e,t)});function ha(e){let t=new R({check:`custom`});return t._zod.check=e,t}function ga(e,t={}){return Ur(ma,e,t)}function _a(e){let t=ha(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 va=25,ya=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},ba=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},xa={key:G(),label:G(),required:J().optional().default(!1),secret:J().optional().default(!1),readOnly:J().optional().default(!1),placeholder:G().optional(),description:G().optional(),tooltip:G().optional()},Sa=Vi(`type`,[X({...xa,type:Z([`text`,`password`])}),X({...xa,type:Q(`select`),options:X({value:G(),label:G()}).array()})]),Ca=X({targetFieldKey:G(),alias:G().optional(),expression:G().optional(),values:Y().optional(),type:Z([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:J().default(!1),custom:J().default(!1),hidden:J().default(!1),enumMapper:X({matcher:Z([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`]).or(X({matchExpression:G(),value:G()}).array())}).optional(),properties:pa(()=>Ca).array().optional()}),wa=X({operationId:G(),categories:G().array(),operationType:Z([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:G().optional(),schemaType:Z([`native`,`unified`]).optional().default(`native`),entrypointUrl:G().optional(),entrypointHttpMethod:G().optional(),label:G(),description:G(),tags:G().array().optional(),context:G().optional(),responses:X({statusCode:q(),description:G()}).array().optional(),inputs:X({name:G(),type:G(),required:J(),description:G(),in:G()}).array().optional(),cursor:X({enabled:J(),pageSize:q()}).optional(),compositeIdentifiers:X({enabled:J(),version:q().optional(),fields:X({targetFieldKey:G(),remote:G().optional(),components:G().array()}).array().optional()}).optional(),scheduledJobs:X({enabled:J(),type:Z([`data_sync`]),schedule:G(),description:G(),requestParams:X({fields:G().array().optional(),expand:G().array().optional(),filter:Gi(G(),G()).optional()}).optional(),syncFilter:X({name:Z([`updated_after`,`created_after`]),initialLoopbackPeriod:G(),incrementalLoopbackPeriod:G()}).optional()}).array().optional(),fieldConfigs:Ca.array().optional(),steps:X({stepId:G(),description:G(),stepFunction:X({functionName:G(),version:G().optional(),parameters:Gi(G(),Y())}),condition:G().optional(),ignoreError:J().optional()}).array(),result:G().or(Gi(G(),Y())).optional()}),Ta=X({schedule:G().optional(),operation:wa.extend({operationType:Q(`refresh_token`)})}),Ea=X({mainRatelimit:q(),subPools:Ii(X({subPoolKey:G(),urlPattern:G(),rateLimit:q()})).optional(),mappedRateLimitErrors:Ii(X({errorStatus:q(),errorMessage:G(),errorMessagePath:G().optional(),retryAfterPath:G().optional(),retryAfterUnit:zi([Q(`seconds`),Q(`milliseconds`),Q(`date`)]).optional(),retryAfterValue:q().optional()})).optional()}),Da=X({mainMaxConcurrency:q(),subPools:Ii(X({subPoolKey:G(),urlPattern:G(),maxConcurrency:q()})).optional()}),Oa=X({StackOne:G(),info:X({title:G(),version:G(),key:G(),assets:X({icon:G()}),description:G().optional()}),context:G().optional(),baseUrl:G(),authentication:Gi(G(),X({type:G(),label:G(),authorization:f.AUTHENTICATION_SCHEMA,environments:X({key:G(),name:G()}).array(),support:X({link:G(),description:G().optional()}),configFields:Sa.array().optional(),setupFields:Sa.array().optional(),refreshAuthentication:Ta.optional(),testOperations:X({operation:G().or(wa),condition:G().optional(),required:J().default(!0)}).array().optional()})).array().optional(),operations:wa.array().optional(),rateLimit:Ea.optional(),concurrency:Da.optional()});function ka(e){try{let t=(0,m.parse)(e),n=Oa.parse(t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},i=Na(n),a={baseUrl:n.baseUrl,authentication:Aa(i)},o=za(n,a);return r.operations=o,ja(i,o,a),r.authentication=i,(0,c.notMissing)(o)&&(r.categories=Ma(Object.values(o))),r}catch(e){throw Error(`Error parsing YAML file: ${e.message}`)}}const Aa=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=Aa(c)}else t[n]=r;return t},ja=(e,t,n)=>{if(!(!e||!t))for(let r of Object.values(e))for(let e of Object.values(r)){let r=e.testOperations;e.testOperations=r?.map(e=>{if((0,c.notMissing)(e.operation))if(typeof e.operation==`string`){let n=e.operation,r=Object.values(t).find(e=>e.id===n);if(r)return{...e,operation:r}}else{let t=Ba(e.operation,n);return{...e,operation:t}}return e})}},Ma=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},Na=e=>{let t={};for(let n of e.authentication??[]){let[e]=Object.keys(n),r=n[e].environments.reduce((t,r)=>{let{key:i,name:a}=r,{environments:o,refreshAuthentication:s,testOperations:l,...u}=n[e],d=(0,c.notMissing)(s)?{schedule:s.schedule,operation:Ba(s.operation)}:void 0;return t[i]={...u,refreshAuthentication:d,envKey:i,envName:a,testOperations:l},t},{});t[e]=r}return t},Pa=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,Fa=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,Ia=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},La=e=>{if(!(e.operationType===`refresh_token`||(0,c.isMissing)(e.schema)))return e.operationType===`list`?`/${e.schema}`:`/${e.schema}/:id`},Ra=e=>{let t={success:ya(e.operationType),errors:ba()},n=e.responses?.reduce((e,t)=>{let n=(0,p.isSuccessStatusCode)(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},za=(e,t)=>{let n=e.operations?.reduce((e,n)=>{let r=Pa(n),i=Fa(n);return e[r??i]=Ba(n,t),e},{});return n},Ba=(e,t)=>{let n=La(e),r=Ra(e),i=Wa(e),a=e.inputs||[];i.enabled&&a?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`});let o=Ia(e);return{id:e.operationId,categories:e.categories,label:e.label,description:e.description,operationType:e.operationType,schemaType:e.schemaType??`native`,entrypointUrl:e.entrypointUrl??n,entrypointHttpMethod:o,tags:e.tags,context:e.context,responses:r,cursor:i,compositeIdentifiers:Ga(e),scheduledJobs:Ka(e),inputs:a,steps:e.steps.reduce((n,r)=>(n[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...r.stepFunction.parameters,...qa(r.stepFunction.functionName,t,r.stepFunction.parameters),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:r.stepFunction.parameters.fields??e.fieldConfigs}:{}}}},n),{}),result:e.result}},Va=(e,t)=>{if(!e.inputs)return{};let n=Ua(e.inputs),r=n.parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},Ha=e=>{let t={};return e.forEach(e=>{let n;switch(e.type.toLowerCase()){case`string`:n=G();break;case`number`:n=q();break;case`boolean`:n=J();break;default:n=ji()}t[e.name]=e.required?n:n.optional()}),X(t)},Ua=e=>{let t=e.filter(e=>e.in===`path`),n=e.filter(e=>e.in===`query`),r=e.filter(e=>e.in===`body`),i=e.filter(e=>e.in===`headers`);return X({path:Ha(t).optional(),query:Ha(n).optional(),body:Ha(r).optional(),headers:Ha(i).optional()})},Wa=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:va};return{enabled:n.enabled&&t,pageSize:n.pageSize}},Ga=e=>{if(e.operationType===`refresh_token`)return{enabled:!1};if((0,c.isMissing)(e.compositeIdentifiers)){let t=e.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=(0,c.notMissing)(t)?[{targetFieldKey:t.targetFieldKey,remote:`id`,components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:f.COMPOSITE_ID_LATEST_VERSION,fields:n}}let t=[];for(let n of e.compositeIdentifiers?.fields??[]){let r=n.components.map(t=>{let n=e.fieldConfigs?.find(e=>e.targetFieldKey===t);return{name:t,alias:n?.alias}});t.push({targetFieldKey:n.targetFieldKey,remote:n.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},Ka=e=>{if(!(0,c.isMissing)(e.scheduledJobs))return e.scheduledJobs},qa=(e,t,n={})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n.customErrors&&Array.isArray(n.customErrors)?n.customErrors:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},Ja=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if((0,c.notMissing)(r))return{operation:r,params:{}}},Ya=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=Ja(e,t,n);return(0,c.notMissing)(r)},Xa=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},Za=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},Qa=e=>{try{let t=[],n=(0,m.parse)(e),r=Oa.safeParse(n);return r.success||r.error.issues.forEach(n=>{let r=$a(n.path,e);t.push({line:r,message:n.message,field:n.path.join(`.`)})}),t.length>0?{success:!1,errors:t}:{success:!0}}catch(e){let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;return{success:!1,errors:[{line:r,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]}}},$a=(e,t)=>{let n=t.split(`
|
|
30
|
-
`),r=0,i=-1,a=0;for(let t=0;t<n.length;t++){let o=n[t],s=o.match(/^(\s*)/)?.[1]?.length||0,l=o.replace(`- `,``).trim();if(l.startsWith(`#`)||l===``||s<=i)continue;let u=(0,c.notMissing)(e[r])?`${String(e[r])}`:``;if((0,c.isMissing)(u))return a+1;if(isNaN(Number(u))){if(l.startsWith(`${u}:`)){if(r===e.length-1)return t+1;i=s,a=t,r++}}else{let e=parseInt(u,10),i=-1;for(let o=t;o<n.length;o++){let s=n[o],c=s.trim();if(c.startsWith(`-`)&&i++,i===e){r++,a=t,t--;break}else t++}}}return a+1};var $=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},eo=class extends ${constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},to=class extends ${constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},no=class extends ${constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},ro=class extends ${constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const io=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),name:e.description.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:`native`,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.description,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},ao=(e,t)=>e.map(e=>io(e,t)),oo=`stackone://internal//`,so=`${oo}refresh_token`,co=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=f.StepFunctionsFactory.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===f.StepFunctionName.MAP_FIELDS?{[f.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},lo=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),uo=e=>{let t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||(0,c.isMissing)(n))return e;let r=t.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),i={version:t.version??f.COMPOSITE_ID_LATEST_VERSION,aliases:r};return fo(n,i,e.logger),{...e,inputs:n}},fo=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))vo(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)fo(e,t,n);else typeof i==`object`&&i&&fo(i,t,n)}},po=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=(0,f.decodeCompositeId)(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},mo=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},ho=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},go=(e,t,n,r,i)=>{n.every(ho)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},_o=(e,t,n)=>{e instanceof f.CoreError&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},vo=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=po(o,t,r,i);mo(n,t,s,a),go(n,t,s,c,a)}catch(e){_o(e,t,i)}},yo=`remote_`,bo=e=>{let t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;let n=`data`,r=e.outputs?.[n];if((0,c.isMissing)(r))return e;let i=Array.isArray(r)?r.map(e=>xo(e,t)):xo(r,t);return{...e,outputs:{...e.outputs??{},[n]:i}}},xo=(e,t)=>{let n=So(e,t),r=Ao(n);return{...e,...(0,c.isObject)(r)?r:{}}},So=(e,t)=>{let n=t.version??f.COMPOSITE_ID_LATEST_VERSION,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=(0,f.encodeCompositeId)(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${yo}${t.remote}`]=e[t.remote])}),{...e,...r}},Co=e=>e===`id`||/.+_id(s)?$/.test(e),wo=e=>Array.isArray(e)&&e.every(e=>(0,c.isString)(e)&&e.length>0),To=(e,t)=>(0,f.isCompositeId)(e)||t.startsWith(yo),Eo=(e,t)=>{try{return(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION})}catch{return t}},Do=(e,t,n)=>{let r=t.map(t=>(0,c.isString)(t)&&t.length>0&&!(0,f.isCompositeId)(t)?Eo(e,t):t);n[e]=r,n[`${yo}${e}`]=t},Oo=(e,t,n)=>{if(To(t,e))return;let r=(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION});n[e]=r,n[`remote_${e}`]=t},ko=(e,t,n)=>{wo(t)?Do(e,t,n):(0,c.isString)(t)&&t.length>0&&Oo(e,t,n)},Ao=e=>{if(Array.isArray(e))return e.map(e=>Ao(e));if(!(0,c.isObject)(e))return e;let t={...e};for(let[n,r]of Object.entries(e))((0,c.isObject)(r)||Array.isArray(r)&&r.length>0&&(0,c.isObject)(r[0]))&&(t[n]=Ao(r)),Co(n)&&ko(n,r,t);return t},jo=(e,t)=>{let n=Number(e.inputs?.page_size),r=(0,c.notMissing)(e.inputs?.page_size)&&(0,c.isNumber)(n)&&!Number.isNaN(n)?n:e.operation?.cursor?.pageSize??t;return r},Mo=(e,t,n,r)=>{let i=(0,c.isMissing)(e)?void 0:e.data,a=Object.keys(n).length+1,o=(0,f.isCursorEmpty)({cursor:r,ignoreStepIndex:a});if(!(0,c.isObject)(e)||(0,c.isMissing)(i)||(i?.length??0)<=t)return{result:e,next:(0,c.notMissing)(r)&&!o?(0,f.minifyCursor)(r):null};let s=r?.remote?.[a]?.pageNumber??1,l=(s-1)*t,u=l+t,d=i.slice(l,u),p=i.length>u||!o,m=(0,f.updateCursor)({cursor:r,stepIndex:a,pageNumber:s+1});return{result:{...e,data:d},next:p?(0,f.minifyCursor)(m):null}},No=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=Mo,encodeResultCompositeIds:r=bo,decodeInputCompositeIds:i=uo})=>{let a=i(e),o=await zo({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},Po=(e,t)=>e.condition?!(0,h.safeEvaluate)(e.condition,t):!1,Fo=(e,t,n)=>{let r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},Io=(e,t,n,r,i)=>{let a=Vo({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},Lo=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(Po(o,r))return Vo({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Vo({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=Fo(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return Io(r,e,u,o,i);let d=r.operation?.cursor.enabled?(0,f.updateCursor)({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Vo({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},Ro=(e,t,n,r,i)=>{let a=!n.hasFatalError,o=a?e.operation?.responses.success.statusCode??200:n.errorStatusCode??500,s=(0,c.notMissing)(i)&&(0,c.isObject)(i.result)?{next:i.next,...i.result}:r;return{...t,outputs:s,response:{successful:a,statusCode:o,message:a?void 0:e.operation?.responses?.errors?.[o]?.description??p.HttpErrorMessages?.[o]??`Error while processing the request`}}},zo=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=Mo})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=jo(e,va),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await Lo(t,e,r,i,s,c);let l=e.operation?.result?Bo(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return Ro(e,i,s,l,u)},Bo=(e,t)=>(0,c.isObject)(e)?(0,h.safeEvaluateRecord)(e,t):(0,h.safeEvaluate)(e,t),Vo=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),Ho=async({operationId:e,account:t,connector:n,queryParams:r={},body:i,headers:a,logger:o,getHttpClient:s,parseConnector:l=ka,parseOperationInputsFn:u=Va,createBlockContextFn:d=lo,createBlockFn:f=g,runStepOperationFn:p=No})=>{let m=t.authConfigKey,h=t.environment??`production`,_=t.secureId,v=t.projectSecureId,y=t.credentials,b=d({category:`action`,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:m,environment:h,accountSecureId:_,projectSecureId:v}),ee;try{ee=(0,c.isString)(n)?l(n):n}catch{throw new eo(b,`Error while parsing connector`)}let x=ne(n,e);if((0,c.isMissing)(x))throw new to(b,`No matching operation found`);b.operationType=x.operationType,b.schema=x.schema?.key;let te=Uo(r,b),S;try{S=u(x,{query:r,body:i,headers:a})}catch{throw new no(b,`Error while parsing operation inputs`)}let C=await f({connector:ee,inputs:S,context:b,operation:x,credentials:y,nextCursor:te,logger:o,getHttpClient:s});return await p({block:C})},Uo=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new ro(t,`Invalid cursor.`);return r},Wo=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:l,getHttpClient:u,parseConnector:d=ka,getOperationFromUrlFn:f=ee,getOperationForRefreshAuthenticationFn:p=Ja,parseOperationInputsFn:m=Va,createBlockContextFn:h=lo,createBlockFn:_=g,runStepOperationFn:v=No})=>{let y=e.authConfigKey,b=e.environment??`production`,x=e.secureId,te=e.projectSecureId,ne=e.credentials,S=h({category:n,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:y,environment:b,accountSecureId:x,projectSecureId:te}),C;try{C=(0,c.isString)(t)?d(t):t}catch{throw new eo(S,`Error while parsing connector`)}let w=Ko(r)?p(C,y,b):f(C,r,i);if((0,c.isMissing)(w))throw new to(S,`No matching operation found`);S.operationType=w.operation.operationType,S.schema=w.operation.schema?.key;let T=Go(a,S),E;try{E=m(w.operation,{query:a,body:o,headers:s,path:w.params})}catch{throw new no(S,`Error while parsing operation inputs`)}let D=await _({connector:C,inputs:E,context:S,operation:w.operation,credentials:ne,nextCursor:T,logger:l,getHttpClient:u});return await v({block:D})},Go=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new ro(t,`Invalid cursor.`);return r},Ko=e=>e===so,qo=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,Jo=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=ka,getTestOperationsFn:a=qo,createBlockContextFn:o=lo,createBlockFn:s=g,runStepOperationFn:l=No})=>{let u=e.authConfigKey,d=e.environment??`production`,f=e.secureId,p=e.projectSecureId,m=e.credentials,_=o({category:`internal`,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:u,environment:d,accountSecureId:f,projectSecureId:p}),v;try{v=(0,c.isString)(t)?i(t):t}catch{throw new eo(_,`Error while parsing connector`)}let y=a(v,u,d);if((0,c.isMissing)(y)||y.length===0)return!0;_.operationType=`test`;for(let e of y){let t=await s({connector:v,inputs:void 0,context:_,operation:e.operation,credentials:m,nextCursor:void 0,logger:n,getHttpClient:r}),i=(0,c.notMissing)(e.condition)?(0,h.evaluate)(e.condition,t):!0;if(!i)continue;let a=await l({block:t});if(((0,c.isMissing)(a?.response?.successful)||!a.response.successful)&&e.required)return n?.error({code:`TestOperationFailed`,message:`Test operation "${e.operation.id}" failed with error: ${a?.response?.message}`}),!1}return!0};exports.ConnectSDKError=$,exports.REFRESH_TOKEN_OPERATION_PATH=so,exports.buildActionsMetaFromConfig=io,exports.createBlock=g,exports.executeStepFunction=co,exports.getActionsMetaFromConfigs=ao,exports.getOperationFromUrl=ee,exports.getRefreshTokenExpiresIn=Za,exports.getTokenExpiresIn=Xa,exports.loadConnector=_,exports.parseOperationInputs=Va,exports.parseYamlConnector=ka,exports.runConnectorAction=Ho,exports.runConnectorOperation=Wo,exports.runStepOperation=No,exports.runTestOperations=Jo,exports.supportsRefreshAuthentication=Ya,exports.validateYamlConnector=Qa;
|
|
30
|
+
`),r=0,i=-1,a=0;for(let t=0;t<n.length;t++){let o=n[t],s=o.match(/^(\s*)/)?.[1]?.length||0,l=o.replace(`- `,``).trim();if(l.startsWith(`#`)||l===``||s<=i)continue;let u=(0,c.notMissing)(e[r])?`${String(e[r])}`:``;if((0,c.isMissing)(u))return a+1;if(isNaN(Number(u))){if(l.startsWith(`${u}:`)){if(r===e.length-1)return t+1;i=s,a=t,r++}}else{let e=parseInt(u,10),i=-1;for(let o=t;o<n.length;o++){let s=n[o],c=s.trim();if(c.startsWith(`-`)&&i++,i===e){r++,a=t,t--;break}else t++}}}return a+1};var $=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},eo=class extends ${constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},to=class extends ${constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},no=class extends ${constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},ro=class extends ${constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const io=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.description,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},ao=(e,t)=>e.map(e=>io(e,t)),oo=`stackone://internal//`,so=`${oo}refresh_token`,co=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=f.StepFunctionsFactory.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===f.StepFunctionName.MAP_FIELDS?{[f.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},lo=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),uo=e=>{let t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||(0,c.isMissing)(n))return e;let r=t.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),i={version:t.version??f.COMPOSITE_ID_LATEST_VERSION,aliases:r};return fo(n,i,e.logger),{...e,inputs:n}},fo=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))vo(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)fo(e,t,n);else typeof i==`object`&&i&&fo(i,t,n)}},po=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=(0,f.decodeCompositeId)(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},mo=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},ho=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},go=(e,t,n,r,i)=>{n.every(ho)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},_o=(e,t,n)=>{e instanceof f.CoreError&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},vo=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=po(o,t,r,i);mo(n,t,s,a),go(n,t,s,c,a)}catch(e){_o(e,t,i)}},yo=`remote_`,bo=e=>{let t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;let n=`data`,r=e.outputs?.[n];if((0,c.isMissing)(r))return e;let i=Array.isArray(r)?r.map(e=>xo(e,t)):xo(r,t);return{...e,outputs:{...e.outputs??{},[n]:i}}},xo=(e,t)=>{let n=So(e,t),r=Ao(n);return{...e,...(0,c.isObject)(r)?r:{}}},So=(e,t)=>{let n=t.version??f.COMPOSITE_ID_LATEST_VERSION,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=(0,f.encodeCompositeId)(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${yo}${t.remote}`]=e[t.remote])}),{...e,...r}},Co=e=>e===`id`||/.+_id(s)?$/.test(e),wo=e=>Array.isArray(e)&&e.every(e=>(0,c.isString)(e)&&e.length>0),To=(e,t)=>(0,f.isCompositeId)(e)||t.startsWith(yo),Eo=(e,t)=>{try{return(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION})}catch{return t}},Do=(e,t,n)=>{let r=t.map(t=>(0,c.isString)(t)&&t.length>0&&!(0,f.isCompositeId)(t)?Eo(e,t):t);n[e]=r,n[`${yo}${e}`]=t},Oo=(e,t,n)=>{if(To(t,e))return;let r=(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION});n[e]=r,n[`remote_${e}`]=t},ko=(e,t,n)=>{wo(t)?Do(e,t,n):(0,c.isString)(t)&&t.length>0&&Oo(e,t,n)},Ao=e=>{if(Array.isArray(e))return e.map(e=>Ao(e));if(!(0,c.isObject)(e))return e;let t={...e};for(let[n,r]of Object.entries(e))((0,c.isObject)(r)||Array.isArray(r)&&r.length>0&&(0,c.isObject)(r[0]))&&(t[n]=Ao(r)),Co(n)&&ko(n,r,t);return t},jo=(e,t)=>{let n=Number(e.inputs?.page_size),r=(0,c.notMissing)(e.inputs?.page_size)&&(0,c.isNumber)(n)&&!Number.isNaN(n)?n:e.operation?.cursor?.pageSize??t;return r},Mo=(e,t,n,r)=>{let i=(0,c.isMissing)(e)?void 0:e.data,a=Object.keys(n).length+1,o=(0,f.isCursorEmpty)({cursor:r,ignoreStepIndex:a});if(!(0,c.isObject)(e)||(0,c.isMissing)(i)||(i?.length??0)<=t)return{result:e,next:(0,c.notMissing)(r)&&!o?(0,f.minifyCursor)(r):null};let s=r?.remote?.[a]?.pageNumber??1,l=(s-1)*t,u=l+t,d=i.slice(l,u),p=i.length>u||!o,m=(0,f.updateCursor)({cursor:r,stepIndex:a,pageNumber:s+1});return{result:{...e,data:d},next:p?(0,f.minifyCursor)(m):null}},No=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=Mo,encodeResultCompositeIds:r=bo,decodeInputCompositeIds:i=uo})=>{let a=i(e),o=await zo({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},Po=(e,t)=>e.condition?!(0,h.safeEvaluate)(e.condition,t):!1,Fo=(e,t,n)=>{let r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},Io=(e,t,n,r,i)=>{let a=Vo({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},Lo=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(Po(o,r))return Vo({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Vo({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=Fo(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return Io(r,e,u,o,i);let d=r.operation?.cursor.enabled?(0,f.updateCursor)({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Vo({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},Ro=(e,t,n,r,i)=>{let a=!n.hasFatalError,o=a?e.operation?.responses.success.statusCode??200:n.errorStatusCode??500,s=(0,c.notMissing)(i)&&(0,c.isObject)(i.result)?{next:i.next,...i.result}:r;return{...t,outputs:s,response:{successful:a,statusCode:o,message:a?void 0:e.operation?.responses?.errors?.[o]?.description??p.HttpErrorMessages?.[o]??`Error while processing the request`}}},zo=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=Mo})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=jo(e,va),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await Lo(t,e,r,i,s,c);let l=e.operation?.result?Bo(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return Ro(e,i,s,l,u)},Bo=(e,t)=>(0,c.isObject)(e)?(0,h.safeEvaluateRecord)(e,t):(0,h.safeEvaluate)(e,t),Vo=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),Ho=async({operationId:e,account:t,connector:n,queryParams:r={},body:i,headers:a,logger:o,getHttpClient:s,parseConnector:l=ka,parseOperationInputsFn:u=Va,createBlockContextFn:d=lo,createBlockFn:f=g,runStepOperationFn:p=No})=>{let m=t.authConfigKey,h=t.environment??`production`,_=t.secureId,v=t.projectSecureId,y=t.credentials,b=d({category:`action`,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:m,environment:h,accountSecureId:_,projectSecureId:v}),ee;try{ee=(0,c.isString)(n)?l(n):n}catch{throw new eo(b,`Error while parsing connector`)}let x=ne(n,e);if((0,c.isMissing)(x))throw new to(b,`No matching operation found`);b.operationType=x.operationType,b.schema=x.schema?.key;let te=Uo(r,b),S;try{S=u(x,{query:r,body:i,headers:a})}catch{throw new no(b,`Error while parsing operation inputs`)}let C=await f({connector:ee,inputs:S,context:b,operation:x,credentials:y,nextCursor:te,logger:o,getHttpClient:s});return await p({block:C})},Uo=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new ro(t,`Invalid cursor.`);return r},Wo=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:l,getHttpClient:u,parseConnector:d=ka,getOperationFromUrlFn:f=ee,getOperationForRefreshAuthenticationFn:p=Ja,parseOperationInputsFn:m=Va,createBlockContextFn:h=lo,createBlockFn:_=g,runStepOperationFn:v=No})=>{let y=e.authConfigKey,b=e.environment??`production`,x=e.secureId,te=e.projectSecureId,ne=e.credentials,S=h({category:n,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:y,environment:b,accountSecureId:x,projectSecureId:te}),C;try{C=(0,c.isString)(t)?d(t):t}catch{throw new eo(S,`Error while parsing connector`)}let w=Ko(r)?p(C,y,b):f(C,r,i);if((0,c.isMissing)(w))throw new to(S,`No matching operation found`);S.operationType=w.operation.operationType,S.schema=w.operation.schema?.key;let T=Go(a,S),E;try{E=m(w.operation,{query:a,body:o,headers:s,path:w.params})}catch{throw new no(S,`Error while parsing operation inputs`)}let D=await _({connector:C,inputs:E,context:S,operation:w.operation,credentials:ne,nextCursor:T,logger:l,getHttpClient:u});return await v({block:D})},Go=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new ro(t,`Invalid cursor.`);return r},Ko=e=>e===so,qo=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,Jo=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=ka,getTestOperationsFn:a=qo,createBlockContextFn:o=lo,createBlockFn:s=g,runStepOperationFn:l=No})=>{let u=e.authConfigKey,d=e.environment??`production`,f=e.secureId,p=e.projectSecureId,m=e.credentials,_=o({category:`internal`,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:u,environment:d,accountSecureId:f,projectSecureId:p}),v;try{v=(0,c.isString)(t)?i(t):t}catch{throw new eo(_,`Error while parsing connector`)}let y=a(v,u,d);if((0,c.isMissing)(y)||y.length===0)return!0;_.operationType=`test`;for(let e of y){let t=await s({connector:v,inputs:void 0,context:_,operation:e.operation,credentials:m,nextCursor:void 0,logger:n,getHttpClient:r}),i=(0,c.notMissing)(e.condition)?(0,h.evaluate)(e.condition,t):!0;if(!i)continue;let a=await l({block:t});if(((0,c.isMissing)(a?.response?.successful)||!a.response.successful)&&e.required)return n?.error({code:`TestOperationFailed`,message:`Test operation "${e.operation.id}" failed with error: ${a?.response?.message}`}),!1}return!0};exports.ConnectSDKError=$,exports.REFRESH_TOKEN_OPERATION_PATH=so,exports.buildActionsMetaFromConfig=io,exports.createBlock=g,exports.executeStepFunction=co,exports.getActionsMetaFromConfigs=ao,exports.getOperationFromUrl=ee,exports.getRefreshTokenExpiresIn=Za,exports.getTokenExpiresIn=Xa,exports.loadConnector=_,exports.parseOperationInputs=Va,exports.parseYamlConnector=ka,exports.runConnectorAction=Ho,exports.runConnectorOperation=Wo,exports.runStepOperation=No,exports.runTestOperations=Jo,exports.supportsRefreshAuthentication=Ya,exports.validateYamlConnector=Qa;
|
package/dist/index.mjs
CHANGED
|
@@ -27,4 +27,4 @@ import{isMissing as e,isNumber as t,isObject as n,isString as r,notMissing as i}
|
|
|
27
27
|
...iss,
|
|
28
28
|
path: iss.path ? [${A(e)}, ...iss.path] : [${A(e)}]
|
|
29
29
|
})));`),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=be,o=!de.jitless,s=xe,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?Sn(e,s,t,f):V(e,s,t))):i?Sn(r,s,t,f):V(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=>V(t,s,e))):V(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 wn(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 Tn=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=>ge(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=>wn(t,n,e,r)):wn(a,n,e,r)}}),En=E(`$ZodDiscriminatedUnion`,(e,t)=>{Tn.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=me(()=>{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(!be(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)}}),Dn=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])=>kn(e,t,n)):kn(e,i,a)}});function On(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Se(e)&&Se(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=On(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=On(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 kn(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=On(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const An=E(`$ZodRecord`,(e,t)=>{z.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Se(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}}),jn=E(`$ZodEnum`,(e,t)=>{z.init(e,t);let n=fe(t.entries);e._zod.values=new Set(n),e._zod.pattern=RegExp(`^(${n.filter(e=>Ce.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}}),Mn=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}}),Nn=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}}),Pn=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(`^(${ge(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)}),Fn=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(`^(${ge(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)}),In=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=>Ln(e,t)):Ln(r,t)}});function Ln(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Rn=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))}),zn=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=>Bn(t,e)):Bn(i,e)}});function Bn(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 Vn=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)}}),Hn=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=>Un(e,t,n)):Un(r,t,n)}});function Un(e,t,n){return P(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Wn=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(Gn):Gn(r)}});function Gn(e){return e.value=Object.freeze(e.value),e}const Kn=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)}}),qn=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=>Jn(t,n,r,e));Jn(i,n,r,e)}});function Jn(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 Yn=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 Xn(){return new Yn}const H=Xn();function Zn(e,t){return new e({type:`string`,...N(t)})}function Qn(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...N(t)})}function $n(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...N(t)})}function er(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...N(t)})}function tr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...N(t)})}function nr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...N(t)})}function rr(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 ar(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...N(t)})}function or(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...N(t)})}function sr(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...N(t)})}function cr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...N(t)})}function lr(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 dr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...N(t)})}function fr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...N(t)})}function pr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...N(t)})}function mr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...N(t)})}function hr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...N(t)})}function gr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...N(t)})}function _r(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...N(t)})}function vr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...N(t)})}function yr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...N(t)})}function br(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...N(t)})}function xr(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...N(t)})}function Sr(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...N(t)})}function Cr(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...N(t)})}function wr(e,t){return new e({type:`number`,checks:[],...N(t)})}function Tr(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...N(t)})}function Er(e,t){return new e({type:`boolean`,...N(t)})}function Dr(e){return new e({type:`any`})}function Or(e){return new e({type:`unknown`})}function kr(e,t){return new e({type:`never`,...N(t)})}function Ar(e,t){return new Ct({check:`less_than`,...N(t),value:e,inclusive:!1})}function jr(e,t){return new Ct({check:`less_than`,...N(t),value:e,inclusive:!0})}function Mr(e,t){return new wt({check:`greater_than`,...N(t),value:e,inclusive:!1})}function Nr(e,t){return new wt({check:`greater_than`,...N(t),value:e,inclusive:!0})}function Pr(e,t){return new Tt({check:`multiple_of`,...N(t),value:e})}function Fr(e,t){let n=new Dt({check:`max_length`,...N(t),maximum:e});return n}function Ir(e,t){return new Ot({check:`min_length`,...N(t),minimum:e})}function Lr(e,t){return new kt({check:`length_equals`,...N(t),length:e})}function Rr(e,t){return new jt({check:`string_format`,format:`regex`,...N(t),pattern:e})}function zr(e){return new Mt({check:`string_format`,format:`lowercase`,...N(e)})}function Br(e){return new Nt({check:`string_format`,format:`uppercase`,...N(e)})}function Vr(e,t){return new Pt({check:`string_format`,format:`includes`,...N(t),includes:e})}function Hr(e,t){return new Ft({check:`string_format`,format:`starts_with`,...N(t),prefix:e})}function Ur(e,t){return new It({check:`string_format`,format:`ends_with`,...N(t),suffix:e})}function U(e){return new Lt({check:`overwrite`,tx:e})}function Wr(e){return U(t=>t.normalize(e))}function Gr(){return U(e=>e.trim())}function Kr(){return U(e=>e.toLowerCase())}function qr(){return U(e=>e.toUpperCase())}function Jr(e,t,n){return new e({type:`array`,element:t,...N(n)})}function Yr(e,t,n){let r=new e({type:`custom`,check:`custom`,fn:t,...N(n)});return r}const Xr=E(`ZodISODateTime`,(e,t)=>{Qt.init(e,t),K.init(e,t)});function Zr(e){return br(Xr,e)}const Qr=E(`ZodISODate`,(e,t)=>{$t.init(e,t),K.init(e,t)});function $r(e){return xr(Qr,e)}const ei=E(`ZodISOTime`,(e,t)=>{en.init(e,t),K.init(e,t)});function ti(e){return Sr(ei,e)}const ni=E(`ZodISODuration`,(e,t)=>{tn.init(e,t),K.init(e,t)});function ri(e){return Cr(ni,e)}const ii=(e,t)=>{Fe.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Re(e,t)},flatten:{value:t=>Le(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`,ii);const ai=E(`ZodError`,ii,{Parent:Error}),oi=ze(ai),si=Be(ai),ci=Ve(ai),li=Ue(ai),W=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)=>oi(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>ci(e,t,n),e.parseAsync=async(t,n)=>si(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>li(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(xa(t,n)),e.superRefine=t=>e.check(Sa(t)),e.overwrite=t=>e.check(U(t)),e.optional=()=>na(e),e.nullable=()=>ia(e),e.nullish=()=>na(ia(e)),e.nonoptional=t=>ua(e,t),e.array=()=>Vi(e),e.or=t=>Wi([e,t]),e.and=t=>Ji(e,t),e.transform=t=>ma(e,ea(t)),e.default=t=>oa(e,t),e.prefault=t=>ca(e,t),e.catch=t=>fa(e,t),e.pipe=t=>ma(e,t),e.readonly=()=>ga(e),e.describe=t=>{let n=e.clone();return H.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return H.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return H.get(e);let n=e.clone();return H.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),ui=E(`_ZodString`,(e,t)=>{Bt.init(e,t),W.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(Rr(...t)),e.includes=(...t)=>e.check(Vr(...t)),e.startsWith=(...t)=>e.check(Hr(...t)),e.endsWith=(...t)=>e.check(Ur(...t)),e.min=(...t)=>e.check(Ir(...t)),e.max=(...t)=>e.check(Fr(...t)),e.length=(...t)=>e.check(Lr(...t)),e.nonempty=(...t)=>e.check(Ir(1,...t)),e.lowercase=t=>e.check(zr(t)),e.uppercase=t=>e.check(Br(t)),e.trim=()=>e.check(Gr()),e.normalize=(...t)=>e.check(Wr(...t)),e.toLowerCase=()=>e.check(Kr()),e.toUpperCase=()=>e.check(qr())}),di=E(`ZodString`,(e,t)=>{Bt.init(e,t),ui.init(e,t),e.email=t=>e.check(Qn(fi,t)),e.url=t=>e.check(ir(hi,t)),e.jwt=t=>e.check(yr(Ai,t)),e.emoji=t=>e.check(ar(gi,t)),e.guid=t=>e.check($n(pi,t)),e.uuid=t=>e.check(er(mi,t)),e.uuidv4=t=>e.check(tr(mi,t)),e.uuidv6=t=>e.check(nr(mi,t)),e.uuidv7=t=>e.check(rr(mi,t)),e.nanoid=t=>e.check(or(_i,t)),e.guid=t=>e.check($n(pi,t)),e.cuid=t=>e.check(sr(vi,t)),e.cuid2=t=>e.check(cr(yi,t)),e.ulid=t=>e.check(lr(bi,t)),e.base64=t=>e.check(gr(Di,t)),e.base64url=t=>e.check(_r(Oi,t)),e.xid=t=>e.check(ur(xi,t)),e.ksuid=t=>e.check(dr(Si,t)),e.ipv4=t=>e.check(fr(Ci,t)),e.ipv6=t=>e.check(pr(wi,t)),e.cidrv4=t=>e.check(mr(Ti,t)),e.cidrv6=t=>e.check(hr(Ei,t)),e.e164=t=>e.check(vr(ki,t)),e.datetime=t=>e.check(Zr(t)),e.date=t=>e.check($r(t)),e.time=t=>e.check(ti(t)),e.duration=t=>e.check(ri(t))});function G(e){return Zn(di,e)}const K=E(`ZodStringFormat`,(e,t)=>{B.init(e,t),ui.init(e,t)}),fi=E(`ZodEmail`,(e,t)=>{Ut.init(e,t),K.init(e,t)}),pi=E(`ZodGUID`,(e,t)=>{Vt.init(e,t),K.init(e,t)}),mi=E(`ZodUUID`,(e,t)=>{Ht.init(e,t),K.init(e,t)}),hi=E(`ZodURL`,(e,t)=>{Wt.init(e,t),K.init(e,t)}),gi=E(`ZodEmoji`,(e,t)=>{Gt.init(e,t),K.init(e,t)}),_i=E(`ZodNanoID`,(e,t)=>{Kt.init(e,t),K.init(e,t)}),vi=E(`ZodCUID`,(e,t)=>{qt.init(e,t),K.init(e,t)}),yi=E(`ZodCUID2`,(e,t)=>{Jt.init(e,t),K.init(e,t)}),bi=E(`ZodULID`,(e,t)=>{Yt.init(e,t),K.init(e,t)}),xi=E(`ZodXID`,(e,t)=>{Xt.init(e,t),K.init(e,t)}),Si=E(`ZodKSUID`,(e,t)=>{Zt.init(e,t),K.init(e,t)}),Ci=E(`ZodIPv4`,(e,t)=>{nn.init(e,t),K.init(e,t)}),wi=E(`ZodIPv6`,(e,t)=>{rn.init(e,t),K.init(e,t)}),Ti=E(`ZodCIDRv4`,(e,t)=>{an.init(e,t),K.init(e,t)}),Ei=E(`ZodCIDRv6`,(e,t)=>{on.init(e,t),K.init(e,t)}),Di=E(`ZodBase64`,(e,t)=>{cn.init(e,t),K.init(e,t)}),Oi=E(`ZodBase64URL`,(e,t)=>{un.init(e,t),K.init(e,t)}),ki=E(`ZodE164`,(e,t)=>{dn.init(e,t),K.init(e,t)}),Ai=E(`ZodJWT`,(e,t)=>{pn.init(e,t),K.init(e,t)}),ji=E(`ZodNumber`,(e,t)=>{mn.init(e,t),W.init(e,t),e.gt=(t,n)=>e.check(Mr(t,n)),e.gte=(t,n)=>e.check(Nr(t,n)),e.min=(t,n)=>e.check(Nr(t,n)),e.lt=(t,n)=>e.check(Ar(t,n)),e.lte=(t,n)=>e.check(jr(t,n)),e.max=(t,n)=>e.check(jr(t,n)),e.int=t=>e.check(Ni(t)),e.safe=t=>e.check(Ni(t)),e.positive=t=>e.check(Mr(0,t)),e.nonnegative=t=>e.check(Nr(0,t)),e.negative=t=>e.check(Ar(0,t)),e.nonpositive=t=>e.check(jr(0,t)),e.multipleOf=(t,n)=>e.check(Pr(t,n)),e.step=(t,n)=>e.check(Pr(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 q(e){return wr(ji,e)}const Mi=E(`ZodNumberFormat`,(e,t)=>{hn.init(e,t),ji.init(e,t)});function Ni(e){return Tr(Mi,e)}const Pi=E(`ZodBoolean`,(e,t)=>{gn.init(e,t),W.init(e,t)});function J(e){return Er(Pi,e)}const Fi=E(`ZodAny`,(e,t)=>{_n.init(e,t),W.init(e,t)});function Ii(){return Dr(Fi)}const Li=E(`ZodUnknown`,(e,t)=>{vn.init(e,t),W.init(e,t)});function Y(){return Or(Li)}const Ri=E(`ZodNever`,(e,t)=>{yn.init(e,t),W.init(e,t)});function zi(e){return kr(Ri,e)}const Bi=E(`ZodArray`,(e,t)=>{xn.init(e,t),W.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(Ir(t,n)),e.nonempty=t=>e.check(Ir(1,t)),e.max=(t,n)=>e.check(Fr(t,n)),e.length=(t,n)=>e.check(Lr(t,n)),e.unwrap=()=>e.element});function Vi(e,t){return Jr(Bi,e,t)}const Hi=E(`ZodObject`,(e,t)=>{Cn.init(e,t),W.init(e,t),k(e,`shape`,()=>t.shape),e.keyof=()=>Z(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Y()}),e.loose=()=>e.clone({...e._zod.def,catchall:Y()}),e.strict=()=>e.clone({...e._zod.def,catchall:zi()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>Oe(e,t),e.merge=t=>ke(e,t),e.pick=t=>Ee(e,t),e.omit=t=>De(e,t),e.partial=(...t)=>Ae(ta,e,t[0]),e.required=(...t)=>je(la,e,t[0])});function X(e,t){let n={type:`object`,get shape(){return ve(this,`shape`,{...e}),this.shape},...N(t)};return new Hi(n)}const Ui=E(`ZodUnion`,(e,t)=>{Tn.init(e,t),W.init(e,t),e.options=t.options});function Wi(e,t){return new Ui({type:`union`,options:e,...N(t)})}const Gi=E(`ZodDiscriminatedUnion`,(e,t)=>{Ui.init(e,t),En.init(e,t)});function Ki(e,t,n){return new Gi({type:`union`,options:t,discriminator:e,...N(n)})}const qi=E(`ZodIntersection`,(e,t)=>{Dn.init(e,t),W.init(e,t)});function Ji(e,t){return new qi({type:`intersection`,left:e,right:t})}const Yi=E(`ZodRecord`,(e,t)=>{An.init(e,t),W.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function Xi(e,t,n){return new Yi({type:`record`,keyType:e,valueType:t,...N(n)})}const Zi=E(`ZodEnum`,(e,t)=>{jn.init(e,t),W.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 Zi({...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 Zi({...t,checks:[],...N(r),entries:i})}});function Z(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Zi({type:`enum`,entries:n,...N(t)})}const Qi=E(`ZodLiteral`,(e,t)=>{Mn.init(e,t),W.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 Q(e,t){return new Qi({type:`literal`,values:Array.isArray(e)?e:[e],...N(t)})}const $i=E(`ZodTransform`,(e,t)=>{Nn.init(e,t),W.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 ea(e){return new $i({type:`transform`,transform:e})}const ta=E(`ZodOptional`,(e,t)=>{Pn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function na(e){return new ta({type:`optional`,innerType:e})}const ra=E(`ZodNullable`,(e,t)=>{Fn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ia(e){return new ra({type:`nullable`,innerType:e})}const aa=E(`ZodDefault`,(e,t)=>{In.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function oa(e,t){return new aa({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const sa=E(`ZodPrefault`,(e,t)=>{Rn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ca(e,t){return new sa({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():t}})}const la=E(`ZodNonOptional`,(e,t)=>{zn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ua(e,t){return new la({type:`nonoptional`,innerType:e,...N(t)})}const da=E(`ZodCatch`,(e,t)=>{Vn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function fa(e,t){return new da({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const pa=E(`ZodPipe`,(e,t)=>{Hn.init(e,t),W.init(e,t),e.in=t.in,e.out=t.out});function ma(e,t){return new pa({type:`pipe`,in:e,out:t})}const ha=E(`ZodReadonly`,(e,t)=>{Wn.init(e,t),W.init(e,t)});function ga(e){return new ha({type:`readonly`,innerType:e})}const _a=E(`ZodLazy`,(e,t)=>{Kn.init(e,t),W.init(e,t),e.unwrap=()=>e._zod.def.getter()});function va(e){return new _a({type:`lazy`,getter:e})}const ya=E(`ZodCustom`,(e,t)=>{qn.init(e,t),W.init(e,t)});function ba(e){let t=new R({check:`custom`});return t._zod.check=e,t}function xa(e,t={}){return Yr(ya,e,t)}function Sa(e){let t=ba(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 Ca=25,wa=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},Ta=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},Ea={key:G(),label:G(),required:J().optional().default(!1),secret:J().optional().default(!1),readOnly:J().optional().default(!1),placeholder:G().optional(),description:G().optional(),tooltip:G().optional()},Da=Ki(`type`,[X({...Ea,type:Z([`text`,`password`])}),X({...Ea,type:Q(`select`),options:X({value:G(),label:G()}).array()})]),Oa=X({targetFieldKey:G(),alias:G().optional(),expression:G().optional(),values:Y().optional(),type:Z([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:J().default(!1),custom:J().default(!1),hidden:J().default(!1),enumMapper:X({matcher:Z([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`]).or(X({matchExpression:G(),value:G()}).array())}).optional(),properties:va(()=>Oa).array().optional()}),ka=X({operationId:G(),categories:G().array(),operationType:Z([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:G().optional(),schemaType:Z([`native`,`unified`]).optional().default(`native`),entrypointUrl:G().optional(),entrypointHttpMethod:G().optional(),label:G(),description:G(),tags:G().array().optional(),context:G().optional(),responses:X({statusCode:q(),description:G()}).array().optional(),inputs:X({name:G(),type:G(),required:J(),description:G(),in:G()}).array().optional(),cursor:X({enabled:J(),pageSize:q()}).optional(),compositeIdentifiers:X({enabled:J(),version:q().optional(),fields:X({targetFieldKey:G(),remote:G().optional(),components:G().array()}).array().optional()}).optional(),scheduledJobs:X({enabled:J(),type:Z([`data_sync`]),schedule:G(),description:G(),requestParams:X({fields:G().array().optional(),expand:G().array().optional(),filter:Xi(G(),G()).optional()}).optional(),syncFilter:X({name:Z([`updated_after`,`created_after`]),initialLoopbackPeriod:G(),incrementalLoopbackPeriod:G()}).optional()}).array().optional(),fieldConfigs:Oa.array().optional(),steps:X({stepId:G(),description:G(),stepFunction:X({functionName:G(),version:G().optional(),parameters:Xi(G(),Y())}),condition:G().optional(),ignoreError:J().optional()}).array(),result:G().or(Xi(G(),Y())).optional()}),Aa=X({schedule:G().optional(),operation:ka.extend({operationType:Q(`refresh_token`)})}),ja=X({mainRatelimit:q(),subPools:Vi(X({subPoolKey:G(),urlPattern:G(),rateLimit:q()})).optional(),mappedRateLimitErrors:Vi(X({errorStatus:q(),errorMessage:G(),errorMessagePath:G().optional(),retryAfterPath:G().optional(),retryAfterUnit:Wi([Q(`seconds`),Q(`milliseconds`),Q(`date`)]).optional(),retryAfterValue:q().optional()})).optional()}),Ma=X({mainMaxConcurrency:q(),subPools:Vi(X({subPoolKey:G(),urlPattern:G(),maxConcurrency:q()})).optional()}),Na=X({StackOne:G(),info:X({title:G(),version:G(),key:G(),assets:X({icon:G()}),description:G().optional()}),context:G().optional(),baseUrl:G(),authentication:Xi(G(),X({type:G(),label:G(),authorization:u,environments:X({key:G(),name:G()}).array(),support:X({link:G(),description:G().optional()}),configFields:Da.array().optional(),setupFields:Da.array().optional(),refreshAuthentication:Aa.optional(),testOperations:X({operation:G().or(ka),condition:G().optional(),required:J().default(!0)}).array().optional()})).array().optional(),operations:ka.array().optional(),rateLimit:ja.optional(),concurrency:Ma.optional()});function Pa(e){try{let t=C(e),n=Na.parse(t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},a=Ra(n),o={baseUrl:n.baseUrl,authentication:Fa(a)},s=Wa(n,o);return r.operations=s,Ia(a,s,o),r.authentication=a,i(s)&&(r.categories=La(Object.values(s))),r}catch(e){throw Error(`Error parsing YAML file: ${e.message}`)}}const Fa=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=Fa(c)}else t[n]=r;return t},Ia=(e,t,n)=>{if(!(!e||!t))for(let r of Object.values(e))for(let e of Object.values(r)){let r=e.testOperations;e.testOperations=r?.map(e=>{if(i(e.operation))if(typeof e.operation==`string`){let n=e.operation,r=Object.values(t).find(e=>e.id===n);if(r)return{...e,operation:r}}else{let t=Ga(e.operation,n);return{...e,operation:t}}return e})}},La=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},Ra=e=>{let t={};for(let n of e.authentication??[]){let[e]=Object.keys(n),r=n[e].environments.reduce((t,r)=>{let{key:a,name:o}=r,{environments:s,refreshAuthentication:c,testOperations:l,...u}=n[e],d=i(c)?{schedule:c.schedule,operation:Ga(c.operation)}:void 0;return t[a]={...u,refreshAuthentication:d,envKey:a,envName:o,testOperations:l},t},{});t[e]=r}return t},za=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,Ba=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,Va=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},Ha=t=>{if(!(t.operationType===`refresh_token`||e(t.schema)))return t.operationType===`list`?`/${t.schema}`:`/${t.schema}/:id`},Ua=e=>{let t={success:wa(e.operationType),errors:Ta()},n=e.responses?.reduce((e,t)=>{let n=ee(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},Wa=(e,t)=>{let n=e.operations?.reduce((e,n)=>{let r=za(n),i=Ba(n);return e[r??i]=Ga(n,t),e},{});return n},Ga=(e,t)=>{let n=Ha(e),r=Ua(e),i=Ya(e),a=e.inputs||[];i.enabled&&a?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`});let o=Va(e);return{id:e.operationId,categories:e.categories,label:e.label,description:e.description,operationType:e.operationType,schemaType:e.schemaType??`native`,entrypointUrl:e.entrypointUrl??n,entrypointHttpMethod:o,tags:e.tags,context:e.context,responses:r,cursor:i,compositeIdentifiers:Xa(e),scheduledJobs:Za(e),inputs:a,steps:e.steps.reduce((n,r)=>(n[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...r.stepFunction.parameters,...Qa(r.stepFunction.functionName,t,r.stepFunction.parameters),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:r.stepFunction.parameters.fields??e.fieldConfigs}:{}}}},n),{}),result:e.result}},Ka=(e,t)=>{if(!e.inputs)return{};let n=Ja(e.inputs),r=n.parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},qa=e=>{let t={};return e.forEach(e=>{let n;switch(e.type.toLowerCase()){case`string`:n=G();break;case`number`:n=q();break;case`boolean`:n=J();break;default:n=Ii()}t[e.name]=e.required?n:n.optional()}),X(t)},Ja=e=>{let t=e.filter(e=>e.in===`path`),n=e.filter(e=>e.in===`query`),r=e.filter(e=>e.in===`body`),i=e.filter(e=>e.in===`headers`);return X({path:qa(t).optional(),query:qa(n).optional(),body:qa(r).optional(),headers:qa(i).optional()})},Ya=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:Ca};return{enabled:n.enabled&&t,pageSize:n.pageSize}},Xa=t=>{if(t.operationType===`refresh_token`)return{enabled:!1};if(e(t.compositeIdentifiers)){let e=t.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=i(e)?[{targetFieldKey:e.targetFieldKey,remote:`id`,components:[{name:e.targetFieldKey,alias:e.alias}]}]:void 0;return{enabled:!0,version:d,fields:n}}let n=[];for(let e of t.compositeIdentifiers?.fields??[]){let r=e.components.map(e=>{let n=t.fieldConfigs?.find(t=>t.targetFieldKey===e);return{name:e,alias:n?.alias}});n.push({targetFieldKey:e.targetFieldKey,remote:e.remote,components:r})}return{enabled:t.compositeIdentifiers.enabled,version:t.compositeIdentifiers.version,fields:n.length>0?n:void 0}},Za=t=>{if(!e(t.scheduledJobs))return t.scheduledJobs},Qa=(e,t,n={})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n.customErrors&&Array.isArray(n.customErrors)?n.customErrors:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},$a=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if(i(r))return{operation:r,params:{}}},eo=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=$a(e,t,n);return i(r)},to=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},no=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},ro=e=>{try{let t=[],n=C(e),r=Na.safeParse(n);return r.success||r.error.issues.forEach(n=>{let r=io(n.path,e);t.push({line:r,message:n.message,field:n.path.join(`.`)})}),t.length>0?{success:!1,errors:t}:{success:!0}}catch(e){let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;return{success:!1,errors:[{line:r,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]}}},io=(t,n)=>{let r=n.split(`
|
|
30
|
-
`),a=0,o=-1,s=0;for(let n=0;n<r.length;n++){let c=r[n],l=c.match(/^(\s*)/)?.[1]?.length||0,u=c.replace(`- `,``).trim();if(u.startsWith(`#`)||u===``||l<=o)continue;let d=i(t[a])?`${String(t[a])}`:``;if(e(d))return s+1;if(isNaN(Number(d))){if(u.startsWith(`${d}:`)){if(a===t.length-1)return n+1;o=l,s=n,a++}}else{let e=parseInt(d,10),t=-1;for(let i=n;i<r.length;i++){let o=r[i],c=o.trim();if(c.startsWith(`-`)&&t++,t===e){a++,s=n,n--;break}else n++}}}return s+1};var $=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},ao=class extends ${constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},oo=class extends ${constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},so=class extends ${constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},co=class extends ${constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const lo=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),name:e.description.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:`native`,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.description,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},uo=(e,t)=>e.map(e=>lo(e,t)),fo=`stackone://internal//`,po=`${fo}refresh_token`,mo=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=m.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===p.MAP_FIELDS?{[p.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},ho=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),go=t=>{let n=t.operation?.compositeIdentifiers,r={...t.inputs??{}};if(!n?.enabled||e(r))return t;let i=n.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),a={version:n.version??d,aliases:i};return _o(r,a,t.logger),{...t,inputs:r}},_o=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))Co(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)_o(e,t,n);else typeof i==`object`&&i&&_o(i,t,n)}},vo=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=h(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},yo=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},bo=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},xo=(e,t,n,r,i)=>{n.every(bo)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},So=(e,t,n)=>{e instanceof f&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},Co=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=vo(o,t,r,i);yo(n,t,s,a),xo(n,t,s,c,a)}catch(e){So(e,t,i)}},wo=`remote_`,To=t=>{let n=t.operation?.compositeIdentifiers;if(!n?.enabled)return t;let r=`data`,i=t.outputs?.[r];if(e(i))return t;let a=Array.isArray(i)?i.map(e=>Eo(e,n)):Eo(i,n);return{...t,outputs:{...t.outputs??{},[r]:a}}},Eo=(e,t)=>{let r=Do(e,t),i=Fo(r);return{...e,...n(i)?i:{}}},Do=(e,t)=>{let n=t.version??d,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=g(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${wo}${t.remote}`]=e[t.remote])}),{...e,...r}},Oo=e=>e===`id`||/.+_id(s)?$/.test(e),ko=e=>Array.isArray(e)&&e.every(e=>r(e)&&e.length>0),Ao=(e,t)=>v(e)||t.startsWith(wo),jo=(e,t)=>{try{return g({key:e,value:t},{version:d})}catch{return t}},Mo=(e,t,n)=>{let i=t.map(t=>r(t)&&t.length>0&&!v(t)?jo(e,t):t);n[e]=i,n[`${wo}${e}`]=t},No=(e,t,n)=>{if(Ao(t,e))return;let r=g({key:e,value:t},{version:d});n[e]=r,n[`remote_${e}`]=t},Po=(e,t,n)=>{ko(t)?Mo(e,t,n):r(t)&&t.length>0&&No(e,t,n)},Fo=e=>{if(Array.isArray(e))return e.map(e=>Fo(e));if(!n(e))return e;let t={...e};for(let[r,i]of Object.entries(e))(n(i)||Array.isArray(i)&&i.length>0&&n(i[0]))&&(t[r]=Fo(i)),Oo(r)&&Po(r,i,t);return t},Io=(e,n)=>{let r=Number(e.inputs?.page_size),a=i(e.inputs?.page_size)&&t(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??n;return a},Lo=(t,r,a,o)=>{let s=e(t)?void 0:t.data,c=Object.keys(a).length+1,l=y({cursor:o,ignoreStepIndex:c});if(!n(t)||e(s)||(s?.length??0)<=r)return{result:t,next:i(o)&&!l?b(o):null};let u=o?.remote?.[c]?.pageNumber??1,d=(u-1)*r,f=d+r,p=s.slice(d,f),m=s.length>f||!l,h=x({cursor:o,stepIndex:c,pageNumber:u+1});return{result:{...t,data:p},next:m?b(h):null}},Ro=async({block:e,buildStepFunction:t=m.build,virtualPaginateResultFn:n=Lo,encodeResultCompositeIds:r=To,decodeInputCompositeIds:i=go})=>{let a=i(e),o=await Wo({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},zo=(e,t)=>e.condition?!T(e.condition,t):!1,Bo=(e,t,n)=>{let r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},Vo=(e,t,n,r,i)=>{let a=Ko({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},Ho=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(zo(o,r))return Ko({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Ko({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=Bo(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return Vo(r,e,u,o,i);let d=r.operation?.cursor.enabled?x({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Ko({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},Uo=(e,t,r,a,o)=>{let s=!r.hasFatalError,c=s?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500,l=i(o)&&n(o.result)?{next:o.next,...o.result}:a;return{...t,outputs:l,response:{successful:s,statusCode:c,message:s?void 0:e.operation?.responses?.errors?.[c]?.description??S?.[c]??`Error while processing the request`}}},Wo=async({block:e,buildStepFunction:t=m.build,virtualPaginateResultFn:n=Lo})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=Io(e,Ca),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await Ho(t,e,r,i,s,c);let l=e.operation?.result?Go(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return Uo(e,i,s,l,u)},Go=(e,t)=>n(e)?te(e,t):T(e,t),Ko=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),qo=async({operationId:t,account:n,connector:i,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=Pa,parseOperationInputsFn:d=Ka,createBlockContextFn:f=ho,createBlockFn:p=ne,runStepOperationFn:m=Ro})=>{let h=n.authConfigKey,g=n.environment??`production`,_=n.secureId,v=n.projectSecureId,y=n.credentials,b=f({category:`action`,connectorKey:n.providerKey,connectorVersion:n.providerVersion,authConfigKey:h,environment:g,accountSecureId:_,projectSecureId:v}),x;try{x=r(i)?u(i):i}catch{throw new ao(b,`Error while parsing connector`)}let S=ue(i,t);if(e(S))throw new oo(b,`No matching operation found`);b.operationType=S.operationType,b.schema=S.schema?.key;let ee=Jo(a,b),C;try{C=d(S,{query:a,body:o,headers:s})}catch{throw new so(b,`Error while parsing operation inputs`)}let w=await p({connector:x,inputs:C,context:b,operation:S,credentials:y,nextCursor:ee,logger:c,getHttpClient:l});return await m({block:w})},Jo=(e,t)=>{let n=e?.next,r=i(n)&&t.operationType===`list`?_(n):void 0;if(r===null)throw new co(t,`Invalid cursor.`);return r},Yo=async({account:t,connector:n,category:i,path:a,method:o=`get`,queryParams:s={},body:c,headers:l,logger:u,getHttpClient:d,parseConnector:f=Pa,getOperationFromUrlFn:p=se,getOperationForRefreshAuthenticationFn:m=$a,parseOperationInputsFn:h=Ka,createBlockContextFn:g=ho,createBlockFn:_=ne,runStepOperationFn:v=Ro})=>{let y=t.authConfigKey,b=t.environment??`production`,x=t.secureId,S=t.projectSecureId,ee=t.credentials,C=g({category:i,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:y,environment:b,accountSecureId:x,projectSecureId:S}),w;try{w=r(n)?f(n):n}catch{throw new ao(C,`Error while parsing connector`)}let T=Zo(a)?m(w,y,b):p(w,a,o);if(e(T))throw new oo(C,`No matching operation found`);C.operationType=T.operation.operationType,C.schema=T.operation.schema?.key;let te=Xo(s,C),re;try{re=h(T.operation,{query:s,body:c,headers:l,path:T.params})}catch{throw new so(C,`Error while parsing operation inputs`)}let ie=await _({connector:w,inputs:re,context:C,operation:T.operation,credentials:ee,nextCursor:te,logger:u,getHttpClient:d});return await v({block:ie})},Xo=(e,t)=>{let n=e?.next,r=i(n)&&t.operationType===`list`?_(n):void 0;if(r===null)throw new co(t,`Invalid cursor.`);return r},Zo=e=>e===po,Qo=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,$o=async({account:t,connector:n,logger:a,getHttpClient:o,parseConnector:s=Pa,getTestOperationsFn:c=Qo,createBlockContextFn:l=ho,createBlockFn:u=ne,runStepOperationFn:d=Ro})=>{let f=t.authConfigKey,p=t.environment??`production`,m=t.secureId,h=t.projectSecureId,g=t.credentials,_=l({category:`internal`,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:f,environment:p,accountSecureId:m,projectSecureId:h}),v;try{v=r(n)?s(n):n}catch{throw new ao(_,`Error while parsing connector`)}let y=c(v,f,p);if(e(y)||y.length===0)return!0;_.operationType=`test`;for(let t of y){let n=await u({connector:v,inputs:void 0,context:_,operation:t.operation,credentials:g,nextCursor:void 0,logger:a,getHttpClient:o}),r=i(t.condition)?w(t.condition,n):!0;if(!r)continue;let s=await d({block:n});if((e(s?.response?.successful)||!s.response.successful)&&t.required)return a?.error({code:`TestOperationFailed`,message:`Test operation "${t.operation.id}" failed with error: ${s?.response?.message}`}),!1}return!0};export{$ as ConnectSDKError,po as REFRESH_TOKEN_OPERATION_PATH,lo as buildActionsMetaFromConfig,ne as createBlock,mo as executeStepFunction,uo as getActionsMetaFromConfigs,se as getOperationFromUrl,no as getRefreshTokenExpiresIn,to as getTokenExpiresIn,re as loadConnector,Ka as parseOperationInputs,Pa as parseYamlConnector,qo as runConnectorAction,Yo as runConnectorOperation,Ro as runStepOperation,$o as runTestOperations,eo as supportsRefreshAuthentication,ro as validateYamlConnector};
|
|
30
|
+
`),a=0,o=-1,s=0;for(let n=0;n<r.length;n++){let c=r[n],l=c.match(/^(\s*)/)?.[1]?.length||0,u=c.replace(`- `,``).trim();if(u.startsWith(`#`)||u===``||l<=o)continue;let d=i(t[a])?`${String(t[a])}`:``;if(e(d))return s+1;if(isNaN(Number(d))){if(u.startsWith(`${d}:`)){if(a===t.length-1)return n+1;o=l,s=n,a++}}else{let e=parseInt(d,10),t=-1;for(let i=n;i<r.length;i++){let o=r[i],c=o.trim();if(c.startsWith(`-`)&&t++,t===e){a++,s=n,n--;break}else n++}}}return s+1};var $=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},ao=class extends ${constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},oo=class extends ${constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},so=class extends ${constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},co=class extends ${constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const lo=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.description,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},uo=(e,t)=>e.map(e=>lo(e,t)),fo=`stackone://internal//`,po=`${fo}refresh_token`,mo=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=m.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===p.MAP_FIELDS?{[p.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},ho=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),go=t=>{let n=t.operation?.compositeIdentifiers,r={...t.inputs??{}};if(!n?.enabled||e(r))return t;let i=n.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),a={version:n.version??d,aliases:i};return _o(r,a,t.logger),{...t,inputs:r}},_o=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))Co(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)_o(e,t,n);else typeof i==`object`&&i&&_o(i,t,n)}},vo=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=h(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},yo=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},bo=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},xo=(e,t,n,r,i)=>{n.every(bo)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},So=(e,t,n)=>{e instanceof f&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},Co=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=vo(o,t,r,i);yo(n,t,s,a),xo(n,t,s,c,a)}catch(e){So(e,t,i)}},wo=`remote_`,To=t=>{let n=t.operation?.compositeIdentifiers;if(!n?.enabled)return t;let r=`data`,i=t.outputs?.[r];if(e(i))return t;let a=Array.isArray(i)?i.map(e=>Eo(e,n)):Eo(i,n);return{...t,outputs:{...t.outputs??{},[r]:a}}},Eo=(e,t)=>{let r=Do(e,t),i=Fo(r);return{...e,...n(i)?i:{}}},Do=(e,t)=>{let n=t.version??d,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=g(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${wo}${t.remote}`]=e[t.remote])}),{...e,...r}},Oo=e=>e===`id`||/.+_id(s)?$/.test(e),ko=e=>Array.isArray(e)&&e.every(e=>r(e)&&e.length>0),Ao=(e,t)=>v(e)||t.startsWith(wo),jo=(e,t)=>{try{return g({key:e,value:t},{version:d})}catch{return t}},Mo=(e,t,n)=>{let i=t.map(t=>r(t)&&t.length>0&&!v(t)?jo(e,t):t);n[e]=i,n[`${wo}${e}`]=t},No=(e,t,n)=>{if(Ao(t,e))return;let r=g({key:e,value:t},{version:d});n[e]=r,n[`remote_${e}`]=t},Po=(e,t,n)=>{ko(t)?Mo(e,t,n):r(t)&&t.length>0&&No(e,t,n)},Fo=e=>{if(Array.isArray(e))return e.map(e=>Fo(e));if(!n(e))return e;let t={...e};for(let[r,i]of Object.entries(e))(n(i)||Array.isArray(i)&&i.length>0&&n(i[0]))&&(t[r]=Fo(i)),Oo(r)&&Po(r,i,t);return t},Io=(e,n)=>{let r=Number(e.inputs?.page_size),a=i(e.inputs?.page_size)&&t(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??n;return a},Lo=(t,r,a,o)=>{let s=e(t)?void 0:t.data,c=Object.keys(a).length+1,l=y({cursor:o,ignoreStepIndex:c});if(!n(t)||e(s)||(s?.length??0)<=r)return{result:t,next:i(o)&&!l?b(o):null};let u=o?.remote?.[c]?.pageNumber??1,d=(u-1)*r,f=d+r,p=s.slice(d,f),m=s.length>f||!l,h=x({cursor:o,stepIndex:c,pageNumber:u+1});return{result:{...t,data:p},next:m?b(h):null}},Ro=async({block:e,buildStepFunction:t=m.build,virtualPaginateResultFn:n=Lo,encodeResultCompositeIds:r=To,decodeInputCompositeIds:i=go})=>{let a=i(e),o=await Wo({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},zo=(e,t)=>e.condition?!T(e.condition,t):!1,Bo=(e,t,n)=>{let r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},Vo=(e,t,n,r,i)=>{let a=Ko({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},Ho=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(zo(o,r))return Ko({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Ko({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=Bo(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return Vo(r,e,u,o,i);let d=r.operation?.cursor.enabled?x({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Ko({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},Uo=(e,t,r,a,o)=>{let s=!r.hasFatalError,c=s?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500,l=i(o)&&n(o.result)?{next:o.next,...o.result}:a;return{...t,outputs:l,response:{successful:s,statusCode:c,message:s?void 0:e.operation?.responses?.errors?.[c]?.description??S?.[c]??`Error while processing the request`}}},Wo=async({block:e,buildStepFunction:t=m.build,virtualPaginateResultFn:n=Lo})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=Io(e,Ca),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await Ho(t,e,r,i,s,c);let l=e.operation?.result?Go(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return Uo(e,i,s,l,u)},Go=(e,t)=>n(e)?te(e,t):T(e,t),Ko=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),qo=async({operationId:t,account:n,connector:i,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=Pa,parseOperationInputsFn:d=Ka,createBlockContextFn:f=ho,createBlockFn:p=ne,runStepOperationFn:m=Ro})=>{let h=n.authConfigKey,g=n.environment??`production`,_=n.secureId,v=n.projectSecureId,y=n.credentials,b=f({category:`action`,connectorKey:n.providerKey,connectorVersion:n.providerVersion,authConfigKey:h,environment:g,accountSecureId:_,projectSecureId:v}),x;try{x=r(i)?u(i):i}catch{throw new ao(b,`Error while parsing connector`)}let S=ue(i,t);if(e(S))throw new oo(b,`No matching operation found`);b.operationType=S.operationType,b.schema=S.schema?.key;let ee=Jo(a,b),C;try{C=d(S,{query:a,body:o,headers:s})}catch{throw new so(b,`Error while parsing operation inputs`)}let w=await p({connector:x,inputs:C,context:b,operation:S,credentials:y,nextCursor:ee,logger:c,getHttpClient:l});return await m({block:w})},Jo=(e,t)=>{let n=e?.next,r=i(n)&&t.operationType===`list`?_(n):void 0;if(r===null)throw new co(t,`Invalid cursor.`);return r},Yo=async({account:t,connector:n,category:i,path:a,method:o=`get`,queryParams:s={},body:c,headers:l,logger:u,getHttpClient:d,parseConnector:f=Pa,getOperationFromUrlFn:p=se,getOperationForRefreshAuthenticationFn:m=$a,parseOperationInputsFn:h=Ka,createBlockContextFn:g=ho,createBlockFn:_=ne,runStepOperationFn:v=Ro})=>{let y=t.authConfigKey,b=t.environment??`production`,x=t.secureId,S=t.projectSecureId,ee=t.credentials,C=g({category:i,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:y,environment:b,accountSecureId:x,projectSecureId:S}),w;try{w=r(n)?f(n):n}catch{throw new ao(C,`Error while parsing connector`)}let T=Zo(a)?m(w,y,b):p(w,a,o);if(e(T))throw new oo(C,`No matching operation found`);C.operationType=T.operation.operationType,C.schema=T.operation.schema?.key;let te=Xo(s,C),re;try{re=h(T.operation,{query:s,body:c,headers:l,path:T.params})}catch{throw new so(C,`Error while parsing operation inputs`)}let ie=await _({connector:w,inputs:re,context:C,operation:T.operation,credentials:ee,nextCursor:te,logger:u,getHttpClient:d});return await v({block:ie})},Xo=(e,t)=>{let n=e?.next,r=i(n)&&t.operationType===`list`?_(n):void 0;if(r===null)throw new co(t,`Invalid cursor.`);return r},Zo=e=>e===po,Qo=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,$o=async({account:t,connector:n,logger:a,getHttpClient:o,parseConnector:s=Pa,getTestOperationsFn:c=Qo,createBlockContextFn:l=ho,createBlockFn:u=ne,runStepOperationFn:d=Ro})=>{let f=t.authConfigKey,p=t.environment??`production`,m=t.secureId,h=t.projectSecureId,g=t.credentials,_=l({category:`internal`,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:f,environment:p,accountSecureId:m,projectSecureId:h}),v;try{v=r(n)?s(n):n}catch{throw new ao(_,`Error while parsing connector`)}let y=c(v,f,p);if(e(y)||y.length===0)return!0;_.operationType=`test`;for(let t of y){let n=await u({connector:v,inputs:void 0,context:_,operation:t.operation,credentials:g,nextCursor:void 0,logger:a,getHttpClient:o}),r=i(t.condition)?w(t.condition,n):!0;if(!r)continue;let s=await d({block:n});if((e(s?.response?.successful)||!s.response.successful)&&t.required)return a?.error({code:`TestOperationFailed`,message:`Test operation "${t.operation.id}" failed with error: ${s?.response?.message}`}),!1}return!0};export{$ as ConnectSDKError,po as REFRESH_TOKEN_OPERATION_PATH,lo as buildActionsMetaFromConfig,ne as createBlock,mo as executeStepFunction,uo as getActionsMetaFromConfigs,se as getOperationFromUrl,no as getRefreshTokenExpiresIn,to as getTokenExpiresIn,re as loadConnector,Ka as parseOperationInputs,Pa as parseYamlConnector,qo as runConnectorAction,Yo as runConnectorOperation,Ro as runStepOperation,$o as runTestOperations,eo as supportsRefreshAuthentication,ro as validateYamlConnector};
|