@stackone/connect-sdk 1.33.0 → 1.35.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.js CHANGED
@@ -1 +1,4170 @@
1
- "use strict";var e=require("@stackone/transport"),t=require("path-to-regexp"),o=require("@stackone/core"),r=require("@stackone/utils"),n=require("yaml"),s=require("zod"),i=require("@stackone/expressions");const a=async({inputs:t,context:o,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>e.HttpClientManager.getInstance()})=>({inputs:t,fieldConfigs:[],context:o,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),c=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=p(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},u=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},p=(e,o,r)=>{const n=u(e);for(const e of r)if(e.startsWith(o)){const r=e.replace(`${o} `,"").trim(),s=t.match(u(r))(u(n));if(!1!==s)return{path:e,params:s.params}}},d=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"unknown":return{statusCode:200};default:throw new Error(`Unknown operation type: ${e}`)}},l={key:s.z.string(),label:s.z.string(),required:s.z.boolean().optional().default(!1),secret:s.z.boolean().optional().default(!1),readOnly:s.z.boolean().optional().default(!1),placeholder:s.z.string().optional(),description:s.z.string().optional(),tooltip:s.z.string().optional()},y=s.z.discriminatedUnion("type",[s.z.object({...l,type:s.z.enum(["text","password"])}),s.z.object({...l,type:s.z.literal("select"),options:s.z.object({value:s.z.string(),label:s.z.string()}).array()})]),g=s.z.object({operationId:s.z.string(),categories:s.z.string().array(),operationType:s.z.enum(["list","get","create","update","delete","custom","unknown"]),schema:s.z.string().optional(),entrypointUrl:s.z.string().optional(),entrypointHttpMethod:s.z.string().optional(),description:s.z.string(),responses:s.z.object({statusCode:s.z.number(),description:s.z.string()}).array().optional(),inputs:s.z.object({name:s.z.string(),type:s.z.string(),required:s.z.boolean(),description:s.z.string(),in:s.z.string()}).array().optional(),cursor:s.z.object({enabled:s.z.boolean(),pageSize:s.z.number()}).optional(),compositeIdentifiers:s.z.object({enabled:s.z.boolean(),version:s.z.number().optional(),fields:s.z.object({targetFieldKey:s.z.string(),remote:s.z.string().optional(),components:s.z.string().array()}).array().optional()}).optional(),scheduledJobs:s.z.object({enabled:s.z.boolean(),type:s.z.enum(["data_sync"]),schedule:s.z.string(),description:s.z.string(),requestParams:s.z.object({fields:s.z.string().array().optional(),expand:s.z.string().array().optional(),filter:s.z.record(s.z.string(),s.z.string()).optional()}).optional(),syncFilter:s.z.object({name:s.z.enum(["updated_after","created_after"]),initialLoopbackPeriod:s.z.string(),incrementalLoopbackPeriod:s.z.string()}).optional()}).array().optional(),fieldConfigs:s.z.object({targetFieldKey:s.z.string(),alias:s.z.string().optional(),expression:s.z.string(),type:s.z.enum(["string","number","boolean","datetime_string","enum"]),custom:s.z.boolean().default(!1),hidden:s.z.boolean().default(!1),enumMapper:s.z.object({matcher:s.z.enum(["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(s.z.object({matchExpression:s.z.string(),value:s.z.string()}).array())}).optional()}).array().optional(),steps:s.z.object({stepId:s.z.string(),description:s.z.string(),stepFunction:s.z.object({functionName:s.z.string(),version:s.z.string().optional(),parameters:s.z.record(s.z.string(),s.z.unknown())}),condition:s.z.string().optional(),ignoreError:s.z.boolean().optional()}).array(),result:s.z.string().or(s.z.record(s.z.string(),s.z.unknown())).optional()}),m=s.z.object({StackOne:s.z.string(),info:s.z.object({title:s.z.string(),version:s.z.string(),key:s.z.string(),description:s.z.string().optional()}),baseUrl:s.z.string(),authentication:s.z.record(s.z.string(),s.z.object({type:s.z.string(),label:s.z.string(),authorization:o.AUTHENTICATION_SCHEMA,environments:s.z.object({key:s.z.string(),name:s.z.string()}).array(),support:s.z.object({link:s.z.string(),description:s.z.string().optional()}),configFields:y.array().optional(),setupFields:y.array().optional(),testOperationsIds:s.z.string().array().optional()})).array().optional(),operations:g.array().optional()});function b(e){try{const t=n.parse(e),o=m.parse(t),s={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=z(o),a={baseUrl:o.baseUrl,authentication:f(i)},c=_(o,a);return s.operations=c,s.authentication=i,r.notMissing(c)&&(s.categories=h(Object.values(c))),s}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const f=e=>{const t={};for(const[o,r]of Object.entries(e))if(r&&"object"==typeof r){const{setupFields:e,configFields:n,support:s,testOperationsIds:i,...a}=r;t[o]=f(a)}else t[o]=r;return t},h=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},z=e=>{const t={};for(const o of e.authentication??[]){const[e]=Object.keys(o),r=o[e].environments.reduce(((t,r)=>{const{key:n,name:s}=r,{environments:i,...a}=o[e];return t[n]={...a,envKey:n,envName:s},t}),{});t[e]=r}return t},_=(t,o)=>{const r=t.operations?.reduce(((t,r)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(r),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(r),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(r),a=(t=>{const o={success:d(t.operationType),errors:{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."}}},r=t.responses?.reduce(((t,o)=>(e.isSuccessStatusCode(o.statusCode)?t.success={statusCode:o.statusCode,description:o.description}:t.errors[o.statusCode]={statusCode:o.statusCode,description:o.description},t)),o);return r??o})(r),c=S(r),u=r.inputs||[];return c.enabled&&u?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),t[n??s]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:E(r),scheduledJobs:O(r),inputs:u,steps:r.steps.reduce(((e,t)=>(e[t.stepId]={id:t.stepId,description:t.description,condition:t.condition,ignoreError:t.ignoreError,stepFunction:{functionName:t.stepFunction.functionName,version:t.stepFunction.version,params:{...t.stepFunction.parameters,...k(t.stepFunction.functionName,o,t.stepFunction.parameters),..."map_fields"===t.stepFunction.functionName||"typecast"===t.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},t}),{});return r},I=(e,t)=>{if(!e.inputs)return{};const o=v(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},C=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=s.z.string();break;case"number":o=s.z.number();break;case"boolean":o=s.z.boolean();break;default:o=s.z.any()}t[e.name]=e.required?o:o.optional()})),s.z.object(t)},v=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),r=e.filter((e=>"body"===e.in)),n=e.filter((e=>"headers"===e.in));return s.z.object({path:C(t).optional(),query:C(o).optional(),body:C(r).optional(),headers:C(n).optional()})},S=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},E=e=>{if(r.isMissing(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),n=r.notMissing(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:o.COMPOSITE_ID_LATEST_VERSION,fields:n}}const t=[];for(const o of e.compositeIdentifiers?.fields??[]){const r=o.components.map((t=>{const o=e.fieldConfigs?.find((e=>e.targetFieldKey===t));return{name:t,alias:o?.alias}}));t.push({targetFieldKey:o.targetFieldKey,remote:o.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},O=e=>{if(!r.isMissing(e.scheduledJobs))return e.scheduledJobs},k=(e,t,o={})=>{if("request"===e||"paginated_request"===e){const e=[{receivedStatus:500,targetStatus:502}];return{...t,customErrors:[...o.customErrors&&Array.isArray(o.customErrors)?o.customErrors:[],...e]}}return{}};class F extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,F)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class j extends F{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class T extends F{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class x extends F{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class w extends F{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const N=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:a})=>({projectSecureId:a,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),R=e=>{const t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||r.isMissing(n))return e;const s=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),i={version:t.version??o.COMPOSITE_ID_LATEST_VERSION,aliases:s};return A(n,i,e.logger),{...e,inputs:n}},A=(e,t,o)=>{for(const r in e){const n=e[r];if("string"==typeof n||Array.isArray(n)&&n.every((e=>"string"==typeof e)))q(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)A(e,t,o);else"object"==typeof n&&null!==n&&A(n,t,o)}},M=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},q=(e,t,r,n,s)=>{try{const i=Array.isArray(e),a=i?e:[e];if(0===a.length)return;const{compositeIdComponents:c,nonCompositeIds:u}=((e,t,r,n)=>{const s=[],i=[];for(const a of e)try{const e=o.decodeCompositeId(a,r);s.push(e)}catch(e){n?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:t,inputElement:a,compositeIdentifierConfig:r,error:e}}),i.push(a)}return{compositeIdComponents:s,nonCompositeIds:i}})(a,t,n,s);((e,t,o,r)=>{const n=o.filter((e=>Object.keys(e).length>1));n.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?n:n[0]})})(r,t,c,i),((e,t,o,r,n)=>{o.every(M)&&(n?e[t]=[...o.map((e=>Object.values(e)[0])),...r]:o.length>0&&(e[t]=Object.values(o[0])[0]))})(r,t,c,u,i)}catch(e){((e,t,r)=>{e instanceof o.CoreError&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?r?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):r?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})})(e,t,s)}},P="remote_",$=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",n=e.outputs?.[o];if(r.isMissing(n))return e;const s=Array.isArray(n)?n.map((e=>K(e,t))):K(n,t);return{...e,outputs:{...e.outputs??{},[o]:s}}},K=(e,t)=>{const o=D(e,t),n=G(o);return{...e,...r.isObject(n)?n:{}}},D=(e,t)=>{const r=t.version??o.COMPOSITE_ID_LATEST_VERSION,n={};return t.fields?.forEach((t=>{const s={},i=[];t.components.forEach((t=>{t.alias&&(s[t.name]=t.alias),i.push({key:t.name,value:e[t.name]})}));const a=1===i.length?i[0]:{identifiers:i},c={version:r,aliases:Object.keys(s).length>0?s:void 0},u=o.encodeCompositeId(a,c);n[t.targetFieldKey]=u,t.remote&&(n[`${P}${t.remote}`]=e[t.remote])})),{...e,...n}},U=e=>"id"===e||/.+_id(s)?$/.test(e),L=(e,t,n)=>{const s=t.map((t=>r.isString(t)&&t.length>0&&!o.isCompositeId(t)?((e,t)=>{try{return o.encodeCompositeId({key:e,value:t},{version:o.COMPOSITE_ID_LATEST_VERSION})}catch{return t}})(e,t):t));n[e]=s,n[`${P}${e}`]=t},H=(e,t,r)=>{if(((e,t)=>o.isCompositeId(e)||t.startsWith(P))(t,e))return;const n=o.encodeCompositeId({key:e,value:t},{version:o.COMPOSITE_ID_LATEST_VERSION});r[e]=n,r[`remote_${e}`]=t},V=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>r.isString(e)&&e.length>0)))(t)?L(e,t,o):r.isString(t)&&t.length>0&&H(e,t,o)},G=e=>{if(Array.isArray(e))return e.map((e=>G(e)));if(!r.isObject(e))return e;const t={...e};for(const[o,n]of Object.entries(e))(r.isObject(n)||Array.isArray(n)&&n.length>0&&r.isObject(n[0]))&&(t[o]=G(n)),U(o)&&V(o,n,t);return t},J=(e,t,n,s)=>{const i=r.isMissing(e)?void 0:e.data,a=Object.keys(n).length+1,c=o.isCursorEmpty({cursor:s,ignoreStepIndex:a});if(!r.isObject(e)||r.isMissing(i)||(i?.length??0)<=t)return{result:e,next:r.notMissing(s)&&!c?o.minifyCursor(s):null};const u=s?.remote?.[a]?.pageNumber??1,p=(u-1)*t,d=p+t,l=i.slice(p,d),y=i.length>d||!c,g=o.updateCursor({cursor:s,stepIndex:a,pageNumber:u+1});return{result:{...e,data:l},next:y?o.minifyCursor(g):null}},W=async({block:e,buildStepFunction:t=o.StepFunctionsFactory.build,virtualPaginateResultFn:r=J,encodeResultCompositeIds:n=$,decodeInputCompositeIds:s=R})=>{const i=s(e);return n(await Y({block:i,buildStepFunction:t,virtualPaginateResultFn:r}))},B=async(e,t,r,n,s,a)=>{const c=r[e],u=c.stepFunction,p=a.buildStepFunction({functionName:u.functionName,version:u.version,validateSchemas:!0}).fn;if(((e,t)=>!!e.condition&&!i.safeEvaluate(e.condition,t))(c,n))return X({block:n,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(s.hasFatalError)return X({block:n,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});const d=((e,t,o)=>{const r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[o]?.providerPageCursor,position:t.nextCursor?.remote?.[o]?.position}}:r.params??{}})(c,n,t),l=await p({block:n,params:d});if(!1===l.successful)return((e,t,o,r,n)=>{const s=X({block:e,stepId:t,successful:!1,functionOutput:o});return(r.ignoreError??!1)||(n.hasFatalError=!0,n.errorStatusCode??=o.output?.statusCode??500),s})(n,e,l,c,s);const y=n.operation?.cursor.enabled?o.updateCursor({cursor:n.nextCursor,stepIndex:t,providerPageCursor:l.output?.next,position:l.output?.position}):void 0;return X({block:{...l.block,nextCursor:y},stepId:e,functionOutput:l})},Y=async({block:t,buildStepFunction:n=o.StepFunctionsFactory.build,virtualPaginateResultFn:s=J})=>{const i=t.operation?.steps||{};let a={...t};const c=Object.keys(i),u=((e,t)=>{const o=Number(e.inputs?.page_size);return r.notMissing(e.inputs?.page_size)&&r.isNumber(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(t,25),p={hasFatalError:!1,errorStatusCode:null},d={block:t,buildStepFunction:n,virtualPaginateResultFn:s};for(const[e,t]of c.entries())a=await B(t,e,i,a,p,d);const l=t.operation?.result?Q(t.operation.result,a):void 0;return((t,o,n,s,i)=>{const a=!n.hasFatalError,c=a?t.operation?.responses.success.statusCode??200:n.errorStatusCode??500;return{...o,outputs:r.notMissing(i)&&r.isObject(i.result)?{next:i.next,...i.result}:s,response:{successful:a,statusCode:c,message:a?void 0:t.operation?.responses?.errors?.[c]?.description??e.HttpErrorMessages?.[c]??"Error while processing the request"}}})(t,a,p,l,t.operation?.cursor.enabled?s(l,u,i,a.nextCursor):void 0)},Q=(e,t)=>r.isObject(e)?i.safeEvaluateRecord(e,t):i.safeEvaluate(e,t),X=({block:e,stepId:t,successful:o,functionOutput:r,skipped:n,message:s})=>({...e,steps:{...e.steps,[t]:{successful:o??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:n,message:s}}}),Z=(e,t)=>{const n=e?.next,s=r.notMissing(n)&&"list"===t.operationType?o.expandCursor(n):void 0;if(null===s)throw new w(t,"Invalid cursor.");return s};exports.ConnectSDKError=F,exports.createBlock=a,exports.executeStepFunction=async({block:e,stepFunctionName:t,params:r,buildStepFunction:n=o.StepFunctionsFactory.build})=>{const s=n({functionName:t}).fn,i=await s({block:e,params:r}),a=t===o.StepFunctionName.MAP_FIELDS?{[o.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:i.block.result},errors:i.errors,successful:i.successful}}:{};return{...i.block,steps:{...i?.block?.steps??{},...a}}},exports.getOperationFromUrl=c,exports.parseOperationInputs=I,exports.parseYamlConnector=b,exports.runConnectorOperation=async({account:e,connector:t,category:o,path:n,method:s="get",queryParams:i,body:u,headers:p,logger:d,parseConnector:l=b,getOperationFromUrlFn:y=c,parseOperationInputsFn:g=I,createBlockContextFn:m=N,createBlockFn:f=a,runStepOperationFn:h=W})=>{const z=e.authConfigKey,_=e.environment??"production",C=e.secureId,v=e.projectSecureId,S=e.credentials,E=m({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:z,environment:_,accountSecureId:C,projectSecureId:v});let O;try{O=r.isString(t)?l(t):t}catch{throw new j(E,"Error while parsing connector")}const k=y(O,n,s);if(r.isMissing(k))throw new T(E,"No matching operation found");E.operationType=k.operation.operationType,E.schema=k.operation.schema?.key;const F=Z(i,E);let w;try{w=g(k.operation,{query:i,body:u,headers:p,path:k.params})}catch{throw new x(E,"Error while parsing operation inputs")}const R=await f({inputs:w,context:E,operation:k.operation,credentials:S,nextCursor:F,logger:d});return await h({block:R})},exports.runStepOperation=W;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const __stackone_transport = __toESM(require("@stackone/transport"));
25
+ const path_to_regexp = __toESM(require("path-to-regexp"));
26
+ const __stackone_core = __toESM(require("@stackone/core"));
27
+ const __stackone_utils = __toESM(require("@stackone/utils"));
28
+ const yaml = __toESM(require("yaml"));
29
+ const __stackone_expressions = __toESM(require("@stackone/expressions"));
30
+
31
+ //#region src/blocks/createBlock.ts
32
+ const createBlock = async ({ inputs, context, operation, credentials, nextCursor, logger, getHttpClient = async () => __stackone_transport.HttpClientManager.getInstance() }) => {
33
+ const httpClient = await getHttpClient();
34
+ return {
35
+ inputs,
36
+ fieldConfigs: [],
37
+ context,
38
+ operation,
39
+ credentials,
40
+ nextCursor,
41
+ httpClient,
42
+ logger
43
+ };
44
+ };
45
+
46
+ //#endregion
47
+ //#region src/connectors/operations.ts
48
+ const getOperationFromUrl = (connector, url, method) => {
49
+ const httpMethod = method.toUpperCase();
50
+ if (!connector.operations) return void 0;
51
+ const validOperationUrls = Object.keys(connector.operations);
52
+ const test = testMatcher(url, httpMethod, validOperationUrls);
53
+ if (!test) return void 0;
54
+ return {
55
+ operation: connector.operations?.[test.path],
56
+ params: test.params
57
+ };
58
+ };
59
+ const removeLeadingAndTrailingSlashes = (path) => {
60
+ const withoutLeadingSlash = path.startsWith("/") ? path.slice(1) : path;
61
+ const withoutTrailingSlash = withoutLeadingSlash.endsWith("/") ? withoutLeadingSlash.slice(0, -1) : withoutLeadingSlash;
62
+ return withoutTrailingSlash;
63
+ };
64
+ const testMatcher = (url, method, routes) => {
65
+ const path = removeLeadingAndTrailingSlashes(url);
66
+ for (const r of routes) if (r.startsWith(method)) {
67
+ const cleanRoute = r.replace(`${method} `, "").trim();
68
+ const fn = (0, path_to_regexp.match)(removeLeadingAndTrailingSlashes(cleanRoute));
69
+ const res = fn(removeLeadingAndTrailingSlashes(path));
70
+ if (res !== false) return {
71
+ path: r,
72
+ params: res.params
73
+ };
74
+ }
75
+ return void 0;
76
+ };
77
+
78
+ //#endregion
79
+ //#region ../../node_modules/zod/v4/core/core.js
80
+ /** A special constant with type `never` */
81
+ const NEVER = Object.freeze({ status: "aborted" });
82
+ function $constructor(name, initializer$2, params) {
83
+ function init(inst, def) {
84
+ var _a;
85
+ Object.defineProperty(inst, "_zod", {
86
+ value: inst._zod ?? {},
87
+ enumerable: false
88
+ });
89
+ (_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
90
+ inst._zod.traits.add(name);
91
+ initializer$2(inst, def);
92
+ for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
93
+ inst._zod.constr = _;
94
+ inst._zod.def = def;
95
+ }
96
+ const Parent = params?.Parent ?? Object;
97
+ class Definition extends Parent {}
98
+ Object.defineProperty(Definition, "name", { value: name });
99
+ function _(def) {
100
+ var _a;
101
+ const inst = params?.Parent ? new Definition() : this;
102
+ init(inst, def);
103
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
104
+ for (const fn of inst._zod.deferred) fn();
105
+ return inst;
106
+ }
107
+ Object.defineProperty(_, "init", { value: init });
108
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
109
+ if (params?.Parent && inst instanceof params.Parent) return true;
110
+ return inst?._zod?.traits?.has(name);
111
+ } });
112
+ Object.defineProperty(_, "name", { value: name });
113
+ return _;
114
+ }
115
+ const $brand = Symbol("zod_brand");
116
+ var $ZodAsyncError = class extends Error {
117
+ constructor() {
118
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
119
+ }
120
+ };
121
+ const globalConfig = {};
122
+ function config(newConfig) {
123
+ if (newConfig) Object.assign(globalConfig, newConfig);
124
+ return globalConfig;
125
+ }
126
+
127
+ //#endregion
128
+ //#region ../../node_modules/zod/v4/core/util.js
129
+ function getEnumValues(entries) {
130
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
131
+ const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
132
+ return values;
133
+ }
134
+ function jsonStringifyReplacer(_, value) {
135
+ if (typeof value === "bigint") return value.toString();
136
+ return value;
137
+ }
138
+ function cached(getter) {
139
+ const set = false;
140
+ return { get value() {
141
+ {
142
+ const value = getter();
143
+ Object.defineProperty(this, "value", { value });
144
+ return value;
145
+ }
146
+ } };
147
+ }
148
+ function nullish(input) {
149
+ return input === null || input === void 0;
150
+ }
151
+ function cleanRegex(source) {
152
+ const start = source.startsWith("^") ? 1 : 0;
153
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
154
+ return source.slice(start, end);
155
+ }
156
+ function floatSafeRemainder(val, step) {
157
+ const valDecCount = (val.toString().split(".")[1] || "").length;
158
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
159
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
160
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
161
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
162
+ return valInt % stepInt / 10 ** decCount;
163
+ }
164
+ function defineLazy(object$1, key, getter) {
165
+ const set = false;
166
+ Object.defineProperty(object$1, key, {
167
+ get() {
168
+ {
169
+ const value = getter();
170
+ object$1[key] = value;
171
+ return value;
172
+ }
173
+ },
174
+ set(v) {
175
+ Object.defineProperty(object$1, key, { value: v });
176
+ },
177
+ configurable: true
178
+ });
179
+ }
180
+ function assignProp(target, prop, value) {
181
+ Object.defineProperty(target, prop, {
182
+ value,
183
+ writable: true,
184
+ enumerable: true,
185
+ configurable: true
186
+ });
187
+ }
188
+ function esc(str) {
189
+ return JSON.stringify(str);
190
+ }
191
+ const captureStackTrace = Error.captureStackTrace ? Error.captureStackTrace : (..._args) => {};
192
+ function isObject$3(data) {
193
+ return typeof data === "object" && data !== null && !Array.isArray(data);
194
+ }
195
+ const allowsEval = cached(() => {
196
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
197
+ try {
198
+ const F = Function;
199
+ new F("");
200
+ return true;
201
+ } catch (_) {
202
+ return false;
203
+ }
204
+ });
205
+ function isPlainObject(o) {
206
+ if (isObject$3(o) === false) return false;
207
+ const ctor = o.constructor;
208
+ if (ctor === void 0) return true;
209
+ const prot = ctor.prototype;
210
+ if (isObject$3(prot) === false) return false;
211
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
212
+ return true;
213
+ }
214
+ const propertyKeyTypes = new Set([
215
+ "string",
216
+ "number",
217
+ "symbol"
218
+ ]);
219
+ function escapeRegex(str) {
220
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
221
+ }
222
+ function clone(inst, def, params) {
223
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
224
+ if (!def || params?.parent) cl._zod.parent = inst;
225
+ return cl;
226
+ }
227
+ function normalizeParams(_params) {
228
+ const params = _params;
229
+ if (!params) return {};
230
+ if (typeof params === "string") return { error: () => params };
231
+ if (params?.message !== void 0) {
232
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
233
+ params.error = params.message;
234
+ }
235
+ delete params.message;
236
+ if (typeof params.error === "string") return {
237
+ ...params,
238
+ error: () => params.error
239
+ };
240
+ return params;
241
+ }
242
+ function optionalKeys(shape) {
243
+ return Object.keys(shape).filter((k) => {
244
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
245
+ });
246
+ }
247
+ const NUMBER_FORMAT_RANGES = {
248
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
249
+ int32: [-2147483648, 2147483647],
250
+ uint32: [0, 4294967295],
251
+ float32: [-34028234663852886e22, 34028234663852886e22],
252
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
253
+ };
254
+ function pick(schema, mask) {
255
+ const newShape = {};
256
+ const currDef = schema._zod.def;
257
+ for (const key in mask) {
258
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
259
+ if (!mask[key]) continue;
260
+ newShape[key] = currDef.shape[key];
261
+ }
262
+ return clone(schema, {
263
+ ...schema._zod.def,
264
+ shape: newShape,
265
+ checks: []
266
+ });
267
+ }
268
+ function omit(schema, mask) {
269
+ const newShape = { ...schema._zod.def.shape };
270
+ const currDef = schema._zod.def;
271
+ for (const key in mask) {
272
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
273
+ if (!mask[key]) continue;
274
+ delete newShape[key];
275
+ }
276
+ return clone(schema, {
277
+ ...schema._zod.def,
278
+ shape: newShape,
279
+ checks: []
280
+ });
281
+ }
282
+ function extend(schema, shape) {
283
+ if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
284
+ const def = {
285
+ ...schema._zod.def,
286
+ get shape() {
287
+ const _shape = {
288
+ ...schema._zod.def.shape,
289
+ ...shape
290
+ };
291
+ assignProp(this, "shape", _shape);
292
+ return _shape;
293
+ },
294
+ checks: []
295
+ };
296
+ return clone(schema, def);
297
+ }
298
+ function merge(a, b) {
299
+ return clone(a, {
300
+ ...a._zod.def,
301
+ get shape() {
302
+ const _shape = {
303
+ ...a._zod.def.shape,
304
+ ...b._zod.def.shape
305
+ };
306
+ assignProp(this, "shape", _shape);
307
+ return _shape;
308
+ },
309
+ catchall: b._zod.def.catchall,
310
+ checks: []
311
+ });
312
+ }
313
+ function partial(Class, schema, mask) {
314
+ const oldShape = schema._zod.def.shape;
315
+ const shape = { ...oldShape };
316
+ if (mask) for (const key in mask) {
317
+ if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
318
+ if (!mask[key]) continue;
319
+ shape[key] = Class ? new Class({
320
+ type: "optional",
321
+ innerType: oldShape[key]
322
+ }) : oldShape[key];
323
+ }
324
+ else for (const key in oldShape) shape[key] = Class ? new Class({
325
+ type: "optional",
326
+ innerType: oldShape[key]
327
+ }) : oldShape[key];
328
+ return clone(schema, {
329
+ ...schema._zod.def,
330
+ shape,
331
+ checks: []
332
+ });
333
+ }
334
+ function required(Class, schema, mask) {
335
+ const oldShape = schema._zod.def.shape;
336
+ const shape = { ...oldShape };
337
+ if (mask) for (const key in mask) {
338
+ if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
339
+ if (!mask[key]) continue;
340
+ shape[key] = new Class({
341
+ type: "nonoptional",
342
+ innerType: oldShape[key]
343
+ });
344
+ }
345
+ else for (const key in oldShape) shape[key] = new Class({
346
+ type: "nonoptional",
347
+ innerType: oldShape[key]
348
+ });
349
+ return clone(schema, {
350
+ ...schema._zod.def,
351
+ shape,
352
+ checks: []
353
+ });
354
+ }
355
+ function aborted(x, startIndex = 0) {
356
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
357
+ return false;
358
+ }
359
+ function prefixIssues(path, issues) {
360
+ return issues.map((iss) => {
361
+ var _a;
362
+ (_a = iss).path ?? (_a.path = []);
363
+ iss.path.unshift(path);
364
+ return iss;
365
+ });
366
+ }
367
+ function unwrapMessage(message) {
368
+ return typeof message === "string" ? message : message?.message;
369
+ }
370
+ function finalizeIssue(iss, ctx, config$1) {
371
+ const full = {
372
+ ...iss,
373
+ path: iss.path ?? []
374
+ };
375
+ if (!iss.message) {
376
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
377
+ full.message = message;
378
+ }
379
+ delete full.inst;
380
+ delete full.continue;
381
+ if (!ctx?.reportInput) delete full.input;
382
+ return full;
383
+ }
384
+ function getLengthableOrigin(input) {
385
+ if (Array.isArray(input)) return "array";
386
+ if (typeof input === "string") return "string";
387
+ return "unknown";
388
+ }
389
+ function issue(...args) {
390
+ const [iss, input, inst] = args;
391
+ if (typeof iss === "string") return {
392
+ message: iss,
393
+ code: "custom",
394
+ input,
395
+ inst
396
+ };
397
+ return { ...iss };
398
+ }
399
+
400
+ //#endregion
401
+ //#region ../../node_modules/zod/v4/core/errors.js
402
+ const initializer$1 = (inst, def) => {
403
+ inst.name = "$ZodError";
404
+ Object.defineProperty(inst, "_zod", {
405
+ value: inst._zod,
406
+ enumerable: false
407
+ });
408
+ Object.defineProperty(inst, "issues", {
409
+ value: def,
410
+ enumerable: false
411
+ });
412
+ Object.defineProperty(inst, "message", {
413
+ get() {
414
+ return JSON.stringify(def, jsonStringifyReplacer, 2);
415
+ },
416
+ enumerable: true
417
+ });
418
+ };
419
+ const $ZodError = $constructor("$ZodError", initializer$1);
420
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
421
+ function flattenError(error, mapper = (issue$1) => issue$1.message) {
422
+ const fieldErrors = {};
423
+ const formErrors = [];
424
+ for (const sub of error.issues) if (sub.path.length > 0) {
425
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
426
+ fieldErrors[sub.path[0]].push(mapper(sub));
427
+ } else formErrors.push(mapper(sub));
428
+ return {
429
+ formErrors,
430
+ fieldErrors
431
+ };
432
+ }
433
+ function formatError(error, _mapper) {
434
+ const mapper = _mapper || function(issue$1) {
435
+ return issue$1.message;
436
+ };
437
+ const fieldErrors = { _errors: [] };
438
+ const processError = (error$1) => {
439
+ for (const issue$1 of error$1.issues) if (issue$1.code === "invalid_union" && issue$1.errors.length) issue$1.errors.map((issues) => processError({ issues }));
440
+ else if (issue$1.code === "invalid_key") processError({ issues: issue$1.issues });
441
+ else if (issue$1.code === "invalid_element") processError({ issues: issue$1.issues });
442
+ else if (issue$1.path.length === 0) fieldErrors._errors.push(mapper(issue$1));
443
+ else {
444
+ let curr = fieldErrors;
445
+ let i = 0;
446
+ while (i < issue$1.path.length) {
447
+ const el = issue$1.path[i];
448
+ const terminal = i === issue$1.path.length - 1;
449
+ if (!terminal) curr[el] = curr[el] || { _errors: [] };
450
+ else {
451
+ curr[el] = curr[el] || { _errors: [] };
452
+ curr[el]._errors.push(mapper(issue$1));
453
+ }
454
+ curr = curr[el];
455
+ i++;
456
+ }
457
+ }
458
+ };
459
+ processError(error);
460
+ return fieldErrors;
461
+ }
462
+
463
+ //#endregion
464
+ //#region ../../node_modules/zod/v4/core/parse.js
465
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
466
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
467
+ const result = schema._zod.run({
468
+ value,
469
+ issues: []
470
+ }, ctx);
471
+ if (result instanceof Promise) throw new $ZodAsyncError();
472
+ if (result.issues.length) {
473
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
474
+ captureStackTrace(e, _params?.callee);
475
+ throw e;
476
+ }
477
+ return result.value;
478
+ };
479
+ const parse$2 = /* @__PURE__ */ _parse($ZodRealError);
480
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
481
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
482
+ let result = schema._zod.run({
483
+ value,
484
+ issues: []
485
+ }, ctx);
486
+ if (result instanceof Promise) result = await result;
487
+ if (result.issues.length) {
488
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
489
+ captureStackTrace(e, params?.callee);
490
+ throw e;
491
+ }
492
+ return result.value;
493
+ };
494
+ const parseAsync$1 = /* @__PURE__ */ _parseAsync($ZodRealError);
495
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
496
+ const ctx = _ctx ? {
497
+ ..._ctx,
498
+ async: false
499
+ } : { async: false };
500
+ const result = schema._zod.run({
501
+ value,
502
+ issues: []
503
+ }, ctx);
504
+ if (result instanceof Promise) throw new $ZodAsyncError();
505
+ return result.issues.length ? {
506
+ success: false,
507
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
508
+ } : {
509
+ success: true,
510
+ data: result.value
511
+ };
512
+ };
513
+ const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
514
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
515
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
516
+ let result = schema._zod.run({
517
+ value,
518
+ issues: []
519
+ }, ctx);
520
+ if (result instanceof Promise) result = await result;
521
+ return result.issues.length ? {
522
+ success: false,
523
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
524
+ } : {
525
+ success: true,
526
+ data: result.value
527
+ };
528
+ };
529
+ const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
530
+
531
+ //#endregion
532
+ //#region ../../node_modules/zod/v4/core/regexes.js
533
+ const cuid = /^[cC][^\s-]{8,}$/;
534
+ const cuid2 = /^[0-9a-z]+$/;
535
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
536
+ const xid = /^[0-9a-vA-V]{20}$/;
537
+ const ksuid = /^[A-Za-z0-9]{27}$/;
538
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
539
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
540
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
541
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
542
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
543
+ /** Returns a regex for validating an RFC 4122 UUID.
544
+ *
545
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
546
+ const uuid = (version$1) => {
547
+ if (!version$1) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
548
+ return /* @__PURE__ */ new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version$1}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
549
+ };
550
+ /** Practical email validation */
551
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
552
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
553
+ function emoji() {
554
+ return new RegExp(_emoji$1, "u");
555
+ }
556
+ const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
557
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
558
+ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
559
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
560
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
561
+ const base64url = /^[A-Za-z0-9_-]*$/;
562
+ const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
563
+ const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
564
+ const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
565
+ const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
566
+ function timeSource(args) {
567
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
568
+ const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
569
+ return regex;
570
+ }
571
+ function time$1(args) {
572
+ return /* @__PURE__ */ new RegExp(`^${timeSource(args)}$`);
573
+ }
574
+ function datetime$1(args) {
575
+ const time$2 = timeSource({ precision: args.precision });
576
+ const opts = ["Z"];
577
+ if (args.local) opts.push("");
578
+ if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
579
+ const timeRegex = `${time$2}(?:${opts.join("|")})`;
580
+ return /* @__PURE__ */ new RegExp(`^${dateSource}T(?:${timeRegex})$`);
581
+ }
582
+ const string$1 = (params) => {
583
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
584
+ return /* @__PURE__ */ new RegExp(`^${regex}$`);
585
+ };
586
+ const integer = /^\d+$/;
587
+ const number$1 = /^-?\d+(?:\.\d+)?/i;
588
+ const boolean$1 = /true|false/i;
589
+ const lowercase = /^[^A-Z]*$/;
590
+ const uppercase = /^[^a-z]*$/;
591
+
592
+ //#endregion
593
+ //#region ../../node_modules/zod/v4/core/checks.js
594
+ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
595
+ var _a;
596
+ inst._zod ?? (inst._zod = {});
597
+ inst._zod.def = def;
598
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
599
+ });
600
+ const numericOriginMap = {
601
+ number: "number",
602
+ bigint: "bigint",
603
+ object: "date"
604
+ };
605
+ const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
606
+ $ZodCheck.init(inst, def);
607
+ const origin = numericOriginMap[typeof def.value];
608
+ inst._zod.onattach.push((inst$1) => {
609
+ const bag = inst$1._zod.bag;
610
+ const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
611
+ if (def.value < curr) if (def.inclusive) bag.maximum = def.value;
612
+ else bag.exclusiveMaximum = def.value;
613
+ });
614
+ inst._zod.check = (payload) => {
615
+ if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
616
+ payload.issues.push({
617
+ origin,
618
+ code: "too_big",
619
+ maximum: def.value,
620
+ input: payload.value,
621
+ inclusive: def.inclusive,
622
+ inst,
623
+ continue: !def.abort
624
+ });
625
+ };
626
+ });
627
+ const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
628
+ $ZodCheck.init(inst, def);
629
+ const origin = numericOriginMap[typeof def.value];
630
+ inst._zod.onattach.push((inst$1) => {
631
+ const bag = inst$1._zod.bag;
632
+ const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
633
+ if (def.value > curr) if (def.inclusive) bag.minimum = def.value;
634
+ else bag.exclusiveMinimum = def.value;
635
+ });
636
+ inst._zod.check = (payload) => {
637
+ if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
638
+ payload.issues.push({
639
+ origin,
640
+ code: "too_small",
641
+ minimum: def.value,
642
+ input: payload.value,
643
+ inclusive: def.inclusive,
644
+ inst,
645
+ continue: !def.abort
646
+ });
647
+ };
648
+ });
649
+ const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
650
+ $ZodCheck.init(inst, def);
651
+ inst._zod.onattach.push((inst$1) => {
652
+ var _a;
653
+ (_a = inst$1._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
654
+ });
655
+ inst._zod.check = (payload) => {
656
+ if (typeof payload.value !== typeof def.value) throw new Error("Cannot mix number and bigint in multiple_of check.");
657
+ const isMultiple = typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0;
658
+ if (isMultiple) return;
659
+ payload.issues.push({
660
+ origin: typeof payload.value,
661
+ code: "not_multiple_of",
662
+ divisor: def.value,
663
+ input: payload.value,
664
+ inst,
665
+ continue: !def.abort
666
+ });
667
+ };
668
+ });
669
+ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
670
+ $ZodCheck.init(inst, def);
671
+ def.format = def.format || "float64";
672
+ const isInt = def.format?.includes("int");
673
+ const origin = isInt ? "int" : "number";
674
+ const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
675
+ inst._zod.onattach.push((inst$1) => {
676
+ const bag = inst$1._zod.bag;
677
+ bag.format = def.format;
678
+ bag.minimum = minimum;
679
+ bag.maximum = maximum;
680
+ if (isInt) bag.pattern = integer;
681
+ });
682
+ inst._zod.check = (payload) => {
683
+ const input = payload.value;
684
+ if (isInt) {
685
+ if (!Number.isInteger(input)) {
686
+ payload.issues.push({
687
+ expected: origin,
688
+ format: def.format,
689
+ code: "invalid_type",
690
+ input,
691
+ inst
692
+ });
693
+ return;
694
+ }
695
+ if (!Number.isSafeInteger(input)) {
696
+ if (input > 0) payload.issues.push({
697
+ input,
698
+ code: "too_big",
699
+ maximum: Number.MAX_SAFE_INTEGER,
700
+ note: "Integers must be within the safe integer range.",
701
+ inst,
702
+ origin,
703
+ continue: !def.abort
704
+ });
705
+ else payload.issues.push({
706
+ input,
707
+ code: "too_small",
708
+ minimum: Number.MIN_SAFE_INTEGER,
709
+ note: "Integers must be within the safe integer range.",
710
+ inst,
711
+ origin,
712
+ continue: !def.abort
713
+ });
714
+ return;
715
+ }
716
+ }
717
+ if (input < minimum) payload.issues.push({
718
+ origin: "number",
719
+ input,
720
+ code: "too_small",
721
+ minimum,
722
+ inclusive: true,
723
+ inst,
724
+ continue: !def.abort
725
+ });
726
+ if (input > maximum) payload.issues.push({
727
+ origin: "number",
728
+ input,
729
+ code: "too_big",
730
+ maximum,
731
+ inst
732
+ });
733
+ };
734
+ });
735
+ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
736
+ $ZodCheck.init(inst, def);
737
+ inst._zod.when = (payload) => {
738
+ const val = payload.value;
739
+ return !nullish(val) && val.length !== void 0;
740
+ };
741
+ inst._zod.onattach.push((inst$1) => {
742
+ const curr = inst$1._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
743
+ if (def.maximum < curr) inst$1._zod.bag.maximum = def.maximum;
744
+ });
745
+ inst._zod.check = (payload) => {
746
+ const input = payload.value;
747
+ const length = input.length;
748
+ if (length <= def.maximum) return;
749
+ const origin = getLengthableOrigin(input);
750
+ payload.issues.push({
751
+ origin,
752
+ code: "too_big",
753
+ maximum: def.maximum,
754
+ inclusive: true,
755
+ input,
756
+ inst,
757
+ continue: !def.abort
758
+ });
759
+ };
760
+ });
761
+ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
762
+ $ZodCheck.init(inst, def);
763
+ inst._zod.when = (payload) => {
764
+ const val = payload.value;
765
+ return !nullish(val) && val.length !== void 0;
766
+ };
767
+ inst._zod.onattach.push((inst$1) => {
768
+ const curr = inst$1._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
769
+ if (def.minimum > curr) inst$1._zod.bag.minimum = def.minimum;
770
+ });
771
+ inst._zod.check = (payload) => {
772
+ const input = payload.value;
773
+ const length = input.length;
774
+ if (length >= def.minimum) return;
775
+ const origin = getLengthableOrigin(input);
776
+ payload.issues.push({
777
+ origin,
778
+ code: "too_small",
779
+ minimum: def.minimum,
780
+ inclusive: true,
781
+ input,
782
+ inst,
783
+ continue: !def.abort
784
+ });
785
+ };
786
+ });
787
+ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
788
+ $ZodCheck.init(inst, def);
789
+ inst._zod.when = (payload) => {
790
+ const val = payload.value;
791
+ return !nullish(val) && val.length !== void 0;
792
+ };
793
+ inst._zod.onattach.push((inst$1) => {
794
+ const bag = inst$1._zod.bag;
795
+ bag.minimum = def.length;
796
+ bag.maximum = def.length;
797
+ bag.length = def.length;
798
+ });
799
+ inst._zod.check = (payload) => {
800
+ const input = payload.value;
801
+ const length = input.length;
802
+ if (length === def.length) return;
803
+ const origin = getLengthableOrigin(input);
804
+ const tooBig = length > def.length;
805
+ payload.issues.push({
806
+ origin,
807
+ ...tooBig ? {
808
+ code: "too_big",
809
+ maximum: def.length
810
+ } : {
811
+ code: "too_small",
812
+ minimum: def.length
813
+ },
814
+ inclusive: true,
815
+ exact: true,
816
+ input: payload.value,
817
+ inst,
818
+ continue: !def.abort
819
+ });
820
+ };
821
+ });
822
+ const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
823
+ var _a, _b;
824
+ $ZodCheck.init(inst, def);
825
+ inst._zod.onattach.push((inst$1) => {
826
+ const bag = inst$1._zod.bag;
827
+ bag.format = def.format;
828
+ if (def.pattern) {
829
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
830
+ bag.patterns.add(def.pattern);
831
+ }
832
+ });
833
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
834
+ def.pattern.lastIndex = 0;
835
+ if (def.pattern.test(payload.value)) return;
836
+ payload.issues.push({
837
+ origin: "string",
838
+ code: "invalid_format",
839
+ format: def.format,
840
+ input: payload.value,
841
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
842
+ inst,
843
+ continue: !def.abort
844
+ });
845
+ });
846
+ else (_b = inst._zod).check ?? (_b.check = () => {});
847
+ });
848
+ const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
849
+ $ZodCheckStringFormat.init(inst, def);
850
+ inst._zod.check = (payload) => {
851
+ def.pattern.lastIndex = 0;
852
+ if (def.pattern.test(payload.value)) return;
853
+ payload.issues.push({
854
+ origin: "string",
855
+ code: "invalid_format",
856
+ format: "regex",
857
+ input: payload.value,
858
+ pattern: def.pattern.toString(),
859
+ inst,
860
+ continue: !def.abort
861
+ });
862
+ };
863
+ });
864
+ const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
865
+ def.pattern ?? (def.pattern = lowercase);
866
+ $ZodCheckStringFormat.init(inst, def);
867
+ });
868
+ const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
869
+ def.pattern ?? (def.pattern = uppercase);
870
+ $ZodCheckStringFormat.init(inst, def);
871
+ });
872
+ const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
873
+ $ZodCheck.init(inst, def);
874
+ const escapedRegex = escapeRegex(def.includes);
875
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
876
+ def.pattern = pattern;
877
+ inst._zod.onattach.push((inst$1) => {
878
+ const bag = inst$1._zod.bag;
879
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
880
+ bag.patterns.add(pattern);
881
+ });
882
+ inst._zod.check = (payload) => {
883
+ if (payload.value.includes(def.includes, def.position)) return;
884
+ payload.issues.push({
885
+ origin: "string",
886
+ code: "invalid_format",
887
+ format: "includes",
888
+ includes: def.includes,
889
+ input: payload.value,
890
+ inst,
891
+ continue: !def.abort
892
+ });
893
+ };
894
+ });
895
+ const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
896
+ $ZodCheck.init(inst, def);
897
+ const pattern = /* @__PURE__ */ new RegExp(`^${escapeRegex(def.prefix)}.*`);
898
+ def.pattern ?? (def.pattern = pattern);
899
+ inst._zod.onattach.push((inst$1) => {
900
+ const bag = inst$1._zod.bag;
901
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
902
+ bag.patterns.add(pattern);
903
+ });
904
+ inst._zod.check = (payload) => {
905
+ if (payload.value.startsWith(def.prefix)) return;
906
+ payload.issues.push({
907
+ origin: "string",
908
+ code: "invalid_format",
909
+ format: "starts_with",
910
+ prefix: def.prefix,
911
+ input: payload.value,
912
+ inst,
913
+ continue: !def.abort
914
+ });
915
+ };
916
+ });
917
+ const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
918
+ $ZodCheck.init(inst, def);
919
+ const pattern = /* @__PURE__ */ new RegExp(`.*${escapeRegex(def.suffix)}$`);
920
+ def.pattern ?? (def.pattern = pattern);
921
+ inst._zod.onattach.push((inst$1) => {
922
+ const bag = inst$1._zod.bag;
923
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
924
+ bag.patterns.add(pattern);
925
+ });
926
+ inst._zod.check = (payload) => {
927
+ if (payload.value.endsWith(def.suffix)) return;
928
+ payload.issues.push({
929
+ origin: "string",
930
+ code: "invalid_format",
931
+ format: "ends_with",
932
+ suffix: def.suffix,
933
+ input: payload.value,
934
+ inst,
935
+ continue: !def.abort
936
+ });
937
+ };
938
+ });
939
+ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
940
+ $ZodCheck.init(inst, def);
941
+ inst._zod.check = (payload) => {
942
+ payload.value = def.tx(payload.value);
943
+ };
944
+ });
945
+
946
+ //#endregion
947
+ //#region ../../node_modules/zod/v4/core/doc.js
948
+ var Doc = class {
949
+ constructor(args = []) {
950
+ this.content = [];
951
+ this.indent = 0;
952
+ if (this) this.args = args;
953
+ }
954
+ indented(fn) {
955
+ this.indent += 1;
956
+ fn(this);
957
+ this.indent -= 1;
958
+ }
959
+ write(arg) {
960
+ if (typeof arg === "function") {
961
+ arg(this, { execution: "sync" });
962
+ arg(this, { execution: "async" });
963
+ return;
964
+ }
965
+ const content = arg;
966
+ const lines = content.split("\n").filter((x) => x);
967
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
968
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
969
+ for (const line of dedented) this.content.push(line);
970
+ }
971
+ compile() {
972
+ const F = Function;
973
+ const args = this?.args;
974
+ const content = this?.content ?? [``];
975
+ const lines = [...content.map((x) => ` ${x}`)];
976
+ return new F(...args, lines.join("\n"));
977
+ }
978
+ };
979
+
980
+ //#endregion
981
+ //#region ../../node_modules/zod/v4/core/versions.js
982
+ const version = {
983
+ major: 4,
984
+ minor: 0,
985
+ patch: 0
986
+ };
987
+
988
+ //#endregion
989
+ //#region ../../node_modules/zod/v4/core/schemas.js
990
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
991
+ var _a;
992
+ inst ?? (inst = {});
993
+ inst._zod.def = def;
994
+ inst._zod.bag = inst._zod.bag || {};
995
+ inst._zod.version = version;
996
+ const checks = [...inst._zod.def.checks ?? []];
997
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
998
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
999
+ if (checks.length === 0) {
1000
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
1001
+ inst._zod.deferred?.push(() => {
1002
+ inst._zod.run = inst._zod.parse;
1003
+ });
1004
+ } else {
1005
+ const runChecks = (payload, checks$1, ctx) => {
1006
+ let isAborted = aborted(payload);
1007
+ let asyncResult;
1008
+ for (const ch of checks$1) {
1009
+ if (ch._zod.when) {
1010
+ const shouldRun = ch._zod.when(payload);
1011
+ if (!shouldRun) continue;
1012
+ } else if (isAborted) continue;
1013
+ const currLen = payload.issues.length;
1014
+ const _ = ch._zod.check(payload);
1015
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1016
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1017
+ await _;
1018
+ const nextLen = payload.issues.length;
1019
+ if (nextLen === currLen) return;
1020
+ if (!isAborted) isAborted = aborted(payload, currLen);
1021
+ });
1022
+ else {
1023
+ const nextLen = payload.issues.length;
1024
+ if (nextLen === currLen) continue;
1025
+ if (!isAborted) isAborted = aborted(payload, currLen);
1026
+ }
1027
+ }
1028
+ if (asyncResult) return asyncResult.then(() => {
1029
+ return payload;
1030
+ });
1031
+ return payload;
1032
+ };
1033
+ inst._zod.run = (payload, ctx) => {
1034
+ const result = inst._zod.parse(payload, ctx);
1035
+ if (result instanceof Promise) {
1036
+ if (ctx.async === false) throw new $ZodAsyncError();
1037
+ return result.then((result$1) => runChecks(result$1, checks, ctx));
1038
+ }
1039
+ return runChecks(result, checks, ctx);
1040
+ };
1041
+ }
1042
+ inst["~standard"] = {
1043
+ validate: (value) => {
1044
+ try {
1045
+ const r = safeParse$1(inst, value);
1046
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1047
+ } catch (_) {
1048
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1049
+ }
1050
+ },
1051
+ vendor: "zod",
1052
+ version: 1
1053
+ };
1054
+ });
1055
+ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1056
+ $ZodType.init(inst, def);
1057
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
1058
+ inst._zod.parse = (payload, _) => {
1059
+ if (def.coerce) try {
1060
+ payload.value = String(payload.value);
1061
+ } catch (_$1) {}
1062
+ if (typeof payload.value === "string") return payload;
1063
+ payload.issues.push({
1064
+ expected: "string",
1065
+ code: "invalid_type",
1066
+ input: payload.value,
1067
+ inst
1068
+ });
1069
+ return payload;
1070
+ };
1071
+ });
1072
+ const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
1073
+ $ZodCheckStringFormat.init(inst, def);
1074
+ $ZodString.init(inst, def);
1075
+ });
1076
+ const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
1077
+ def.pattern ?? (def.pattern = guid);
1078
+ $ZodStringFormat.init(inst, def);
1079
+ });
1080
+ const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
1081
+ if (def.version) {
1082
+ const versionMap = {
1083
+ v1: 1,
1084
+ v2: 2,
1085
+ v3: 3,
1086
+ v4: 4,
1087
+ v5: 5,
1088
+ v6: 6,
1089
+ v7: 7,
1090
+ v8: 8
1091
+ };
1092
+ const v = versionMap[def.version];
1093
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1094
+ def.pattern ?? (def.pattern = uuid(v));
1095
+ } else def.pattern ?? (def.pattern = uuid());
1096
+ $ZodStringFormat.init(inst, def);
1097
+ });
1098
+ const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
1099
+ def.pattern ?? (def.pattern = email);
1100
+ $ZodStringFormat.init(inst, def);
1101
+ });
1102
+ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1103
+ $ZodStringFormat.init(inst, def);
1104
+ inst._zod.check = (payload) => {
1105
+ try {
1106
+ const orig = payload.value;
1107
+ const url = new URL(orig);
1108
+ const href = url.href;
1109
+ if (def.hostname) {
1110
+ def.hostname.lastIndex = 0;
1111
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
1112
+ code: "invalid_format",
1113
+ format: "url",
1114
+ note: "Invalid hostname",
1115
+ pattern: hostname.source,
1116
+ input: payload.value,
1117
+ inst,
1118
+ continue: !def.abort
1119
+ });
1120
+ }
1121
+ if (def.protocol) {
1122
+ def.protocol.lastIndex = 0;
1123
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1124
+ code: "invalid_format",
1125
+ format: "url",
1126
+ note: "Invalid protocol",
1127
+ pattern: def.protocol.source,
1128
+ input: payload.value,
1129
+ inst,
1130
+ continue: !def.abort
1131
+ });
1132
+ }
1133
+ if (!orig.endsWith("/") && href.endsWith("/")) payload.value = href.slice(0, -1);
1134
+ else payload.value = href;
1135
+ return;
1136
+ } catch (_) {
1137
+ payload.issues.push({
1138
+ code: "invalid_format",
1139
+ format: "url",
1140
+ input: payload.value,
1141
+ inst,
1142
+ continue: !def.abort
1143
+ });
1144
+ }
1145
+ };
1146
+ });
1147
+ const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
1148
+ def.pattern ?? (def.pattern = emoji());
1149
+ $ZodStringFormat.init(inst, def);
1150
+ });
1151
+ const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
1152
+ def.pattern ?? (def.pattern = nanoid);
1153
+ $ZodStringFormat.init(inst, def);
1154
+ });
1155
+ const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
1156
+ def.pattern ?? (def.pattern = cuid);
1157
+ $ZodStringFormat.init(inst, def);
1158
+ });
1159
+ const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
1160
+ def.pattern ?? (def.pattern = cuid2);
1161
+ $ZodStringFormat.init(inst, def);
1162
+ });
1163
+ const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
1164
+ def.pattern ?? (def.pattern = ulid);
1165
+ $ZodStringFormat.init(inst, def);
1166
+ });
1167
+ const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
1168
+ def.pattern ?? (def.pattern = xid);
1169
+ $ZodStringFormat.init(inst, def);
1170
+ });
1171
+ const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
1172
+ def.pattern ?? (def.pattern = ksuid);
1173
+ $ZodStringFormat.init(inst, def);
1174
+ });
1175
+ const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
1176
+ def.pattern ?? (def.pattern = datetime$1(def));
1177
+ $ZodStringFormat.init(inst, def);
1178
+ });
1179
+ const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
1180
+ def.pattern ?? (def.pattern = date$1);
1181
+ $ZodStringFormat.init(inst, def);
1182
+ });
1183
+ const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
1184
+ def.pattern ?? (def.pattern = time$1(def));
1185
+ $ZodStringFormat.init(inst, def);
1186
+ });
1187
+ const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
1188
+ def.pattern ?? (def.pattern = duration$1);
1189
+ $ZodStringFormat.init(inst, def);
1190
+ });
1191
+ const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
1192
+ def.pattern ?? (def.pattern = ipv4);
1193
+ $ZodStringFormat.init(inst, def);
1194
+ inst._zod.onattach.push((inst$1) => {
1195
+ const bag = inst$1._zod.bag;
1196
+ bag.format = `ipv4`;
1197
+ });
1198
+ });
1199
+ const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
1200
+ def.pattern ?? (def.pattern = ipv6);
1201
+ $ZodStringFormat.init(inst, def);
1202
+ inst._zod.onattach.push((inst$1) => {
1203
+ const bag = inst$1._zod.bag;
1204
+ bag.format = `ipv6`;
1205
+ });
1206
+ inst._zod.check = (payload) => {
1207
+ try {
1208
+ new URL(`http://[${payload.value}]`);
1209
+ } catch {
1210
+ payload.issues.push({
1211
+ code: "invalid_format",
1212
+ format: "ipv6",
1213
+ input: payload.value,
1214
+ inst,
1215
+ continue: !def.abort
1216
+ });
1217
+ }
1218
+ };
1219
+ });
1220
+ const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
1221
+ def.pattern ?? (def.pattern = cidrv4);
1222
+ $ZodStringFormat.init(inst, def);
1223
+ });
1224
+ const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
1225
+ def.pattern ?? (def.pattern = cidrv6);
1226
+ $ZodStringFormat.init(inst, def);
1227
+ inst._zod.check = (payload) => {
1228
+ const [address, prefix] = payload.value.split("/");
1229
+ try {
1230
+ if (!prefix) throw new Error();
1231
+ const prefixNum = Number(prefix);
1232
+ if (`${prefixNum}` !== prefix) throw new Error();
1233
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1234
+ new URL(`http://[${address}]`);
1235
+ } catch {
1236
+ payload.issues.push({
1237
+ code: "invalid_format",
1238
+ format: "cidrv6",
1239
+ input: payload.value,
1240
+ inst,
1241
+ continue: !def.abort
1242
+ });
1243
+ }
1244
+ };
1245
+ });
1246
+ function isValidBase64(data) {
1247
+ if (data === "") return true;
1248
+ if (data.length % 4 !== 0) return false;
1249
+ try {
1250
+ atob(data);
1251
+ return true;
1252
+ } catch {
1253
+ return false;
1254
+ }
1255
+ }
1256
+ const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
1257
+ def.pattern ?? (def.pattern = base64);
1258
+ $ZodStringFormat.init(inst, def);
1259
+ inst._zod.onattach.push((inst$1) => {
1260
+ inst$1._zod.bag.contentEncoding = "base64";
1261
+ });
1262
+ inst._zod.check = (payload) => {
1263
+ if (isValidBase64(payload.value)) return;
1264
+ payload.issues.push({
1265
+ code: "invalid_format",
1266
+ format: "base64",
1267
+ input: payload.value,
1268
+ inst,
1269
+ continue: !def.abort
1270
+ });
1271
+ };
1272
+ });
1273
+ function isValidBase64URL(data) {
1274
+ if (!base64url.test(data)) return false;
1275
+ const base64$1 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1276
+ const padded = base64$1.padEnd(Math.ceil(base64$1.length / 4) * 4, "=");
1277
+ return isValidBase64(padded);
1278
+ }
1279
+ const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
1280
+ def.pattern ?? (def.pattern = base64url);
1281
+ $ZodStringFormat.init(inst, def);
1282
+ inst._zod.onattach.push((inst$1) => {
1283
+ inst$1._zod.bag.contentEncoding = "base64url";
1284
+ });
1285
+ inst._zod.check = (payload) => {
1286
+ if (isValidBase64URL(payload.value)) return;
1287
+ payload.issues.push({
1288
+ code: "invalid_format",
1289
+ format: "base64url",
1290
+ input: payload.value,
1291
+ inst,
1292
+ continue: !def.abort
1293
+ });
1294
+ };
1295
+ });
1296
+ const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
1297
+ def.pattern ?? (def.pattern = e164);
1298
+ $ZodStringFormat.init(inst, def);
1299
+ });
1300
+ function isValidJWT(token, algorithm = null) {
1301
+ try {
1302
+ const tokensParts = token.split(".");
1303
+ if (tokensParts.length !== 3) return false;
1304
+ const [header] = tokensParts;
1305
+ if (!header) return false;
1306
+ const parsedHeader = JSON.parse(atob(header));
1307
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1308
+ if (!parsedHeader.alg) return false;
1309
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1310
+ return true;
1311
+ } catch {
1312
+ return false;
1313
+ }
1314
+ }
1315
+ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
1316
+ $ZodStringFormat.init(inst, def);
1317
+ inst._zod.check = (payload) => {
1318
+ if (isValidJWT(payload.value, def.alg)) return;
1319
+ payload.issues.push({
1320
+ code: "invalid_format",
1321
+ format: "jwt",
1322
+ input: payload.value,
1323
+ inst,
1324
+ continue: !def.abort
1325
+ });
1326
+ };
1327
+ });
1328
+ const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
1329
+ $ZodType.init(inst, def);
1330
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
1331
+ inst._zod.parse = (payload, _ctx) => {
1332
+ if (def.coerce) try {
1333
+ payload.value = Number(payload.value);
1334
+ } catch (_) {}
1335
+ const input = payload.value;
1336
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
1337
+ const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
1338
+ payload.issues.push({
1339
+ expected: "number",
1340
+ code: "invalid_type",
1341
+ input,
1342
+ inst,
1343
+ ...received ? { received } : {}
1344
+ });
1345
+ return payload;
1346
+ };
1347
+ });
1348
+ const $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
1349
+ $ZodCheckNumberFormat.init(inst, def);
1350
+ $ZodNumber.init(inst, def);
1351
+ });
1352
+ const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
1353
+ $ZodType.init(inst, def);
1354
+ inst._zod.pattern = boolean$1;
1355
+ inst._zod.parse = (payload, _ctx) => {
1356
+ if (def.coerce) try {
1357
+ payload.value = Boolean(payload.value);
1358
+ } catch (_) {}
1359
+ const input = payload.value;
1360
+ if (typeof input === "boolean") return payload;
1361
+ payload.issues.push({
1362
+ expected: "boolean",
1363
+ code: "invalid_type",
1364
+ input,
1365
+ inst
1366
+ });
1367
+ return payload;
1368
+ };
1369
+ });
1370
+ const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
1371
+ $ZodType.init(inst, def);
1372
+ inst._zod.parse = (payload) => payload;
1373
+ });
1374
+ const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1375
+ $ZodType.init(inst, def);
1376
+ inst._zod.parse = (payload) => payload;
1377
+ });
1378
+ const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1379
+ $ZodType.init(inst, def);
1380
+ inst._zod.parse = (payload, _ctx) => {
1381
+ payload.issues.push({
1382
+ expected: "never",
1383
+ code: "invalid_type",
1384
+ input: payload.value,
1385
+ inst
1386
+ });
1387
+ return payload;
1388
+ };
1389
+ });
1390
+ function handleArrayResult(result, final, index) {
1391
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1392
+ final.value[index] = result.value;
1393
+ }
1394
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1395
+ $ZodType.init(inst, def);
1396
+ inst._zod.parse = (payload, ctx) => {
1397
+ const input = payload.value;
1398
+ if (!Array.isArray(input)) {
1399
+ payload.issues.push({
1400
+ expected: "array",
1401
+ code: "invalid_type",
1402
+ input,
1403
+ inst
1404
+ });
1405
+ return payload;
1406
+ }
1407
+ payload.value = Array(input.length);
1408
+ const proms = [];
1409
+ for (let i = 0; i < input.length; i++) {
1410
+ const item = input[i];
1411
+ const result = def.element._zod.run({
1412
+ value: item,
1413
+ issues: []
1414
+ }, ctx);
1415
+ if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
1416
+ else handleArrayResult(result, payload, i);
1417
+ }
1418
+ if (proms.length) return Promise.all(proms).then(() => payload);
1419
+ return payload;
1420
+ };
1421
+ });
1422
+ function handleObjectResult(result, final, key) {
1423
+ if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
1424
+ final.value[key] = result.value;
1425
+ }
1426
+ function handleOptionalObjectResult(result, final, key, input) {
1427
+ if (result.issues.length) if (input[key] === void 0) if (key in input) final.value[key] = void 0;
1428
+ else final.value[key] = result.value;
1429
+ else final.issues.push(...prefixIssues(key, result.issues));
1430
+ else if (result.value === void 0) {
1431
+ if (key in input) final.value[key] = void 0;
1432
+ } else final.value[key] = result.value;
1433
+ }
1434
+ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1435
+ $ZodType.init(inst, def);
1436
+ const _normalized = cached(() => {
1437
+ const keys = Object.keys(def.shape);
1438
+ for (const k of keys) if (!(def.shape[k] instanceof $ZodType)) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1439
+ const okeys = optionalKeys(def.shape);
1440
+ return {
1441
+ shape: def.shape,
1442
+ keys,
1443
+ keySet: new Set(keys),
1444
+ numKeys: keys.length,
1445
+ optionalKeys: new Set(okeys)
1446
+ };
1447
+ });
1448
+ defineLazy(inst._zod, "propValues", () => {
1449
+ const shape = def.shape;
1450
+ const propValues = {};
1451
+ for (const key in shape) {
1452
+ const field = shape[key]._zod;
1453
+ if (field.values) {
1454
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1455
+ for (const v of field.values) propValues[key].add(v);
1456
+ }
1457
+ }
1458
+ return propValues;
1459
+ });
1460
+ const generateFastpass = (shape) => {
1461
+ const doc = new Doc([
1462
+ "shape",
1463
+ "payload",
1464
+ "ctx"
1465
+ ]);
1466
+ const normalized = _normalized.value;
1467
+ const parseStr = (key) => {
1468
+ const k = esc(key);
1469
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1470
+ };
1471
+ doc.write(`const input = payload.value;`);
1472
+ const ids = Object.create(null);
1473
+ let counter = 0;
1474
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1475
+ doc.write(`const newResult = {}`);
1476
+ for (const key of normalized.keys) if (normalized.optionalKeys.has(key)) {
1477
+ const id = ids[key];
1478
+ doc.write(`const ${id} = ${parseStr(key)};`);
1479
+ const k = esc(key);
1480
+ doc.write(`
1481
+ if (${id}.issues.length) {
1482
+ if (input[${k}] === undefined) {
1483
+ if (${k} in input) {
1484
+ newResult[${k}] = undefined;
1485
+ }
1486
+ } else {
1487
+ payload.issues = payload.issues.concat(
1488
+ ${id}.issues.map((iss) => ({
1489
+ ...iss,
1490
+ path: iss.path ? [${k}, ...iss.path] : [${k}],
1491
+ }))
1492
+ );
1493
+ }
1494
+ } else if (${id}.value === undefined) {
1495
+ if (${k} in input) newResult[${k}] = undefined;
1496
+ } else {
1497
+ newResult[${k}] = ${id}.value;
1498
+ }
1499
+ `);
1500
+ } else {
1501
+ const id = ids[key];
1502
+ doc.write(`const ${id} = ${parseStr(key)};`);
1503
+ doc.write(`
1504
+ if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1505
+ ...iss,
1506
+ path: iss.path ? [${esc(key)}, ...iss.path] : [${esc(key)}]
1507
+ })));`);
1508
+ doc.write(`newResult[${esc(key)}] = ${id}.value`);
1509
+ }
1510
+ doc.write(`payload.value = newResult;`);
1511
+ doc.write(`return payload;`);
1512
+ const fn = doc.compile();
1513
+ return (payload, ctx) => fn(shape, payload, ctx);
1514
+ };
1515
+ let fastpass;
1516
+ const isObject$4 = isObject$3;
1517
+ const jit = !globalConfig.jitless;
1518
+ const allowsEval$1 = allowsEval;
1519
+ const fastEnabled = jit && allowsEval$1.value;
1520
+ const catchall = def.catchall;
1521
+ let value;
1522
+ inst._zod.parse = (payload, ctx) => {
1523
+ value ?? (value = _normalized.value);
1524
+ const input = payload.value;
1525
+ if (!isObject$4(input)) {
1526
+ payload.issues.push({
1527
+ expected: "object",
1528
+ code: "invalid_type",
1529
+ input,
1530
+ inst
1531
+ });
1532
+ return payload;
1533
+ }
1534
+ const proms = [];
1535
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1536
+ if (!fastpass) fastpass = generateFastpass(def.shape);
1537
+ payload = fastpass(payload, ctx);
1538
+ } else {
1539
+ payload.value = {};
1540
+ const shape = value.shape;
1541
+ for (const key of value.keys) {
1542
+ const el = shape[key];
1543
+ const r = el._zod.run({
1544
+ value: input[key],
1545
+ issues: []
1546
+ }, ctx);
1547
+ const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
1548
+ if (r instanceof Promise) proms.push(r.then((r$1) => isOptional ? handleOptionalObjectResult(r$1, payload, key, input) : handleObjectResult(r$1, payload, key)));
1549
+ else if (isOptional) handleOptionalObjectResult(r, payload, key, input);
1550
+ else handleObjectResult(r, payload, key);
1551
+ }
1552
+ }
1553
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1554
+ const unrecognized = [];
1555
+ const keySet = value.keySet;
1556
+ const _catchall = catchall._zod;
1557
+ const t = _catchall.def.type;
1558
+ for (const key of Object.keys(input)) {
1559
+ if (keySet.has(key)) continue;
1560
+ if (t === "never") {
1561
+ unrecognized.push(key);
1562
+ continue;
1563
+ }
1564
+ const r = _catchall.run({
1565
+ value: input[key],
1566
+ issues: []
1567
+ }, ctx);
1568
+ if (r instanceof Promise) proms.push(r.then((r$1) => handleObjectResult(r$1, payload, key)));
1569
+ else handleObjectResult(r, payload, key);
1570
+ }
1571
+ if (unrecognized.length) payload.issues.push({
1572
+ code: "unrecognized_keys",
1573
+ keys: unrecognized,
1574
+ input,
1575
+ inst
1576
+ });
1577
+ if (!proms.length) return payload;
1578
+ return Promise.all(proms).then(() => {
1579
+ return payload;
1580
+ });
1581
+ };
1582
+ });
1583
+ function handleUnionResults(results, final, inst, ctx) {
1584
+ for (const result of results) if (result.issues.length === 0) {
1585
+ final.value = result.value;
1586
+ return final;
1587
+ }
1588
+ final.issues.push({
1589
+ code: "invalid_union",
1590
+ input: final.value,
1591
+ inst,
1592
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1593
+ });
1594
+ return final;
1595
+ }
1596
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1597
+ $ZodType.init(inst, def);
1598
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1599
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1600
+ defineLazy(inst._zod, "values", () => {
1601
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1602
+ return void 0;
1603
+ });
1604
+ defineLazy(inst._zod, "pattern", () => {
1605
+ if (def.options.every((o) => o._zod.pattern)) {
1606
+ const patterns = def.options.map((o) => o._zod.pattern);
1607
+ return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1608
+ }
1609
+ return void 0;
1610
+ });
1611
+ inst._zod.parse = (payload, ctx) => {
1612
+ let async = false;
1613
+ const results = [];
1614
+ for (const option of def.options) {
1615
+ const result = option._zod.run({
1616
+ value: payload.value,
1617
+ issues: []
1618
+ }, ctx);
1619
+ if (result instanceof Promise) {
1620
+ results.push(result);
1621
+ async = true;
1622
+ } else {
1623
+ if (result.issues.length === 0) return result;
1624
+ results.push(result);
1625
+ }
1626
+ }
1627
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1628
+ return Promise.all(results).then((results$1) => {
1629
+ return handleUnionResults(results$1, payload, inst, ctx);
1630
+ });
1631
+ };
1632
+ });
1633
+ const $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
1634
+ $ZodUnion.init(inst, def);
1635
+ const _super = inst._zod.parse;
1636
+ defineLazy(inst._zod, "propValues", () => {
1637
+ const propValues = {};
1638
+ for (const option of def.options) {
1639
+ const pv = option._zod.propValues;
1640
+ if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1641
+ for (const [k, v] of Object.entries(pv)) {
1642
+ if (!propValues[k]) propValues[k] = /* @__PURE__ */ new Set();
1643
+ for (const val of v) propValues[k].add(val);
1644
+ }
1645
+ }
1646
+ return propValues;
1647
+ });
1648
+ const disc = cached(() => {
1649
+ const opts = def.options;
1650
+ const map = /* @__PURE__ */ new Map();
1651
+ for (const o of opts) {
1652
+ const values = o._zod.propValues[def.discriminator];
1653
+ if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1654
+ for (const v of values) {
1655
+ if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
1656
+ map.set(v, o);
1657
+ }
1658
+ }
1659
+ return map;
1660
+ });
1661
+ inst._zod.parse = (payload, ctx) => {
1662
+ const input = payload.value;
1663
+ if (!isObject$3(input)) {
1664
+ payload.issues.push({
1665
+ code: "invalid_type",
1666
+ expected: "object",
1667
+ input,
1668
+ inst
1669
+ });
1670
+ return payload;
1671
+ }
1672
+ const opt = disc.value.get(input?.[def.discriminator]);
1673
+ if (opt) return opt._zod.run(payload, ctx);
1674
+ if (def.unionFallback) return _super(payload, ctx);
1675
+ payload.issues.push({
1676
+ code: "invalid_union",
1677
+ errors: [],
1678
+ note: "No matching discriminator",
1679
+ input,
1680
+ path: [def.discriminator],
1681
+ inst
1682
+ });
1683
+ return payload;
1684
+ };
1685
+ });
1686
+ const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1687
+ $ZodType.init(inst, def);
1688
+ inst._zod.parse = (payload, ctx) => {
1689
+ const input = payload.value;
1690
+ const left = def.left._zod.run({
1691
+ value: input,
1692
+ issues: []
1693
+ }, ctx);
1694
+ const right = def.right._zod.run({
1695
+ value: input,
1696
+ issues: []
1697
+ }, ctx);
1698
+ const async = left instanceof Promise || right instanceof Promise;
1699
+ if (async) return Promise.all([left, right]).then(([left$1, right$1]) => {
1700
+ return handleIntersectionResults(payload, left$1, right$1);
1701
+ });
1702
+ return handleIntersectionResults(payload, left, right);
1703
+ };
1704
+ });
1705
+ function mergeValues(a, b) {
1706
+ if (a === b) return {
1707
+ valid: true,
1708
+ data: a
1709
+ };
1710
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
1711
+ valid: true,
1712
+ data: a
1713
+ };
1714
+ if (isPlainObject(a) && isPlainObject(b)) {
1715
+ const bKeys = Object.keys(b);
1716
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1717
+ const newObj = {
1718
+ ...a,
1719
+ ...b
1720
+ };
1721
+ for (const key of sharedKeys) {
1722
+ const sharedValue = mergeValues(a[key], b[key]);
1723
+ if (!sharedValue.valid) return {
1724
+ valid: false,
1725
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1726
+ };
1727
+ newObj[key] = sharedValue.data;
1728
+ }
1729
+ return {
1730
+ valid: true,
1731
+ data: newObj
1732
+ };
1733
+ }
1734
+ if (Array.isArray(a) && Array.isArray(b)) {
1735
+ if (a.length !== b.length) return {
1736
+ valid: false,
1737
+ mergeErrorPath: []
1738
+ };
1739
+ const newArray = [];
1740
+ for (let index = 0; index < a.length; index++) {
1741
+ const itemA = a[index];
1742
+ const itemB = b[index];
1743
+ const sharedValue = mergeValues(itemA, itemB);
1744
+ if (!sharedValue.valid) return {
1745
+ valid: false,
1746
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1747
+ };
1748
+ newArray.push(sharedValue.data);
1749
+ }
1750
+ return {
1751
+ valid: true,
1752
+ data: newArray
1753
+ };
1754
+ }
1755
+ return {
1756
+ valid: false,
1757
+ mergeErrorPath: []
1758
+ };
1759
+ }
1760
+ function handleIntersectionResults(result, left, right) {
1761
+ if (left.issues.length) result.issues.push(...left.issues);
1762
+ if (right.issues.length) result.issues.push(...right.issues);
1763
+ if (aborted(result)) return result;
1764
+ const merged = mergeValues(left.value, right.value);
1765
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1766
+ result.value = merged.data;
1767
+ return result;
1768
+ }
1769
+ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
1770
+ $ZodType.init(inst, def);
1771
+ inst._zod.parse = (payload, ctx) => {
1772
+ const input = payload.value;
1773
+ if (!isPlainObject(input)) {
1774
+ payload.issues.push({
1775
+ expected: "record",
1776
+ code: "invalid_type",
1777
+ input,
1778
+ inst
1779
+ });
1780
+ return payload;
1781
+ }
1782
+ const proms = [];
1783
+ if (def.keyType._zod.values) {
1784
+ const values = def.keyType._zod.values;
1785
+ payload.value = {};
1786
+ for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1787
+ const result = def.valueType._zod.run({
1788
+ value: input[key],
1789
+ issues: []
1790
+ }, ctx);
1791
+ if (result instanceof Promise) proms.push(result.then((result$1) => {
1792
+ if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
1793
+ payload.value[key] = result$1.value;
1794
+ }));
1795
+ else {
1796
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1797
+ payload.value[key] = result.value;
1798
+ }
1799
+ }
1800
+ let unrecognized;
1801
+ for (const key in input) if (!values.has(key)) {
1802
+ unrecognized = unrecognized ?? [];
1803
+ unrecognized.push(key);
1804
+ }
1805
+ if (unrecognized && unrecognized.length > 0) payload.issues.push({
1806
+ code: "unrecognized_keys",
1807
+ input,
1808
+ inst,
1809
+ keys: unrecognized
1810
+ });
1811
+ } else {
1812
+ payload.value = {};
1813
+ for (const key of Reflect.ownKeys(input)) {
1814
+ if (key === "__proto__") continue;
1815
+ const keyResult = def.keyType._zod.run({
1816
+ value: key,
1817
+ issues: []
1818
+ }, ctx);
1819
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
1820
+ if (keyResult.issues.length) {
1821
+ payload.issues.push({
1822
+ origin: "record",
1823
+ code: "invalid_key",
1824
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
1825
+ input: key,
1826
+ path: [key],
1827
+ inst
1828
+ });
1829
+ payload.value[keyResult.value] = keyResult.value;
1830
+ continue;
1831
+ }
1832
+ const result = def.valueType._zod.run({
1833
+ value: input[key],
1834
+ issues: []
1835
+ }, ctx);
1836
+ if (result instanceof Promise) proms.push(result.then((result$1) => {
1837
+ if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
1838
+ payload.value[keyResult.value] = result$1.value;
1839
+ }));
1840
+ else {
1841
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
1842
+ payload.value[keyResult.value] = result.value;
1843
+ }
1844
+ }
1845
+ }
1846
+ if (proms.length) return Promise.all(proms).then(() => payload);
1847
+ return payload;
1848
+ };
1849
+ });
1850
+ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1851
+ $ZodType.init(inst, def);
1852
+ const values = getEnumValues(def.entries);
1853
+ inst._zod.values = new Set(values);
1854
+ inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1855
+ inst._zod.parse = (payload, _ctx) => {
1856
+ const input = payload.value;
1857
+ if (inst._zod.values.has(input)) return payload;
1858
+ payload.issues.push({
1859
+ code: "invalid_value",
1860
+ values,
1861
+ input,
1862
+ inst
1863
+ });
1864
+ return payload;
1865
+ };
1866
+ });
1867
+ const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
1868
+ $ZodType.init(inst, def);
1869
+ inst._zod.values = new Set(def.values);
1870
+ inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? o.toString() : String(o)).join("|")})$`);
1871
+ inst._zod.parse = (payload, _ctx) => {
1872
+ const input = payload.value;
1873
+ if (inst._zod.values.has(input)) return payload;
1874
+ payload.issues.push({
1875
+ code: "invalid_value",
1876
+ values: def.values,
1877
+ input,
1878
+ inst
1879
+ });
1880
+ return payload;
1881
+ };
1882
+ });
1883
+ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1884
+ $ZodType.init(inst, def);
1885
+ inst._zod.parse = (payload, _ctx) => {
1886
+ const _out = def.transform(payload.value, payload);
1887
+ if (_ctx.async) {
1888
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1889
+ return output.then((output$1) => {
1890
+ payload.value = output$1;
1891
+ return payload;
1892
+ });
1893
+ }
1894
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1895
+ payload.value = _out;
1896
+ return payload;
1897
+ };
1898
+ });
1899
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1900
+ $ZodType.init(inst, def);
1901
+ inst._zod.optin = "optional";
1902
+ inst._zod.optout = "optional";
1903
+ defineLazy(inst._zod, "values", () => {
1904
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
1905
+ });
1906
+ defineLazy(inst._zod, "pattern", () => {
1907
+ const pattern = def.innerType._zod.pattern;
1908
+ return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1909
+ });
1910
+ inst._zod.parse = (payload, ctx) => {
1911
+ if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
1912
+ if (payload.value === void 0) return payload;
1913
+ return def.innerType._zod.run(payload, ctx);
1914
+ };
1915
+ });
1916
+ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1917
+ $ZodType.init(inst, def);
1918
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1919
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1920
+ defineLazy(inst._zod, "pattern", () => {
1921
+ const pattern = def.innerType._zod.pattern;
1922
+ return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1923
+ });
1924
+ defineLazy(inst._zod, "values", () => {
1925
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
1926
+ });
1927
+ inst._zod.parse = (payload, ctx) => {
1928
+ if (payload.value === null) return payload;
1929
+ return def.innerType._zod.run(payload, ctx);
1930
+ };
1931
+ });
1932
+ const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1933
+ $ZodType.init(inst, def);
1934
+ inst._zod.optin = "optional";
1935
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1936
+ inst._zod.parse = (payload, ctx) => {
1937
+ if (payload.value === void 0) {
1938
+ payload.value = def.defaultValue;
1939
+ /**
1940
+ * $ZodDefault always returns the default value immediately.
1941
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1942
+ return payload;
1943
+ }
1944
+ const result = def.innerType._zod.run(payload, ctx);
1945
+ if (result instanceof Promise) return result.then((result$1) => handleDefaultResult(result$1, def));
1946
+ return handleDefaultResult(result, def);
1947
+ };
1948
+ });
1949
+ function handleDefaultResult(payload, def) {
1950
+ if (payload.value === void 0) payload.value = def.defaultValue;
1951
+ return payload;
1952
+ }
1953
+ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
1954
+ $ZodType.init(inst, def);
1955
+ inst._zod.optin = "optional";
1956
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1957
+ inst._zod.parse = (payload, ctx) => {
1958
+ if (payload.value === void 0) payload.value = def.defaultValue;
1959
+ return def.innerType._zod.run(payload, ctx);
1960
+ };
1961
+ });
1962
+ const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
1963
+ $ZodType.init(inst, def);
1964
+ defineLazy(inst._zod, "values", () => {
1965
+ const v = def.innerType._zod.values;
1966
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1967
+ });
1968
+ inst._zod.parse = (payload, ctx) => {
1969
+ const result = def.innerType._zod.run(payload, ctx);
1970
+ if (result instanceof Promise) return result.then((result$1) => handleNonOptionalResult(result$1, inst));
1971
+ return handleNonOptionalResult(result, inst);
1972
+ };
1973
+ });
1974
+ function handleNonOptionalResult(payload, inst) {
1975
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1976
+ code: "invalid_type",
1977
+ expected: "nonoptional",
1978
+ input: payload.value,
1979
+ inst
1980
+ });
1981
+ return payload;
1982
+ }
1983
+ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
1984
+ $ZodType.init(inst, def);
1985
+ inst._zod.optin = "optional";
1986
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1987
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1988
+ inst._zod.parse = (payload, ctx) => {
1989
+ const result = def.innerType._zod.run(payload, ctx);
1990
+ if (result instanceof Promise) return result.then((result$1) => {
1991
+ payload.value = result$1.value;
1992
+ if (result$1.issues.length) {
1993
+ payload.value = def.catchValue({
1994
+ ...payload,
1995
+ error: { issues: result$1.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1996
+ input: payload.value
1997
+ });
1998
+ payload.issues = [];
1999
+ }
2000
+ return payload;
2001
+ });
2002
+ payload.value = result.value;
2003
+ if (result.issues.length) {
2004
+ payload.value = def.catchValue({
2005
+ ...payload,
2006
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
2007
+ input: payload.value
2008
+ });
2009
+ payload.issues = [];
2010
+ }
2011
+ return payload;
2012
+ };
2013
+ });
2014
+ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
2015
+ $ZodType.init(inst, def);
2016
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2017
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2018
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2019
+ inst._zod.parse = (payload, ctx) => {
2020
+ const left = def.in._zod.run(payload, ctx);
2021
+ if (left instanceof Promise) return left.then((left$1) => handlePipeResult(left$1, def, ctx));
2022
+ return handlePipeResult(left, def, ctx);
2023
+ };
2024
+ });
2025
+ function handlePipeResult(left, def, ctx) {
2026
+ if (aborted(left)) return left;
2027
+ return def.out._zod.run({
2028
+ value: left.value,
2029
+ issues: left.issues
2030
+ }, ctx);
2031
+ }
2032
+ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
2033
+ $ZodType.init(inst, def);
2034
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2035
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2036
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2037
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2038
+ inst._zod.parse = (payload, ctx) => {
2039
+ const result = def.innerType._zod.run(payload, ctx);
2040
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
2041
+ return handleReadonlyResult(result);
2042
+ };
2043
+ });
2044
+ function handleReadonlyResult(payload) {
2045
+ payload.value = Object.freeze(payload.value);
2046
+ return payload;
2047
+ }
2048
+ const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
2049
+ $ZodCheck.init(inst, def);
2050
+ $ZodType.init(inst, def);
2051
+ inst._zod.parse = (payload, _) => {
2052
+ return payload;
2053
+ };
2054
+ inst._zod.check = (payload) => {
2055
+ const input = payload.value;
2056
+ const r = def.fn(input);
2057
+ if (r instanceof Promise) return r.then((r$1) => handleRefineResult(r$1, payload, input, inst));
2058
+ handleRefineResult(r, payload, input, inst);
2059
+ return;
2060
+ };
2061
+ });
2062
+ function handleRefineResult(result, payload, input, inst) {
2063
+ if (!result) {
2064
+ const _iss = {
2065
+ code: "custom",
2066
+ input,
2067
+ inst,
2068
+ path: [...inst._zod.def.path ?? []],
2069
+ continue: !inst._zod.def.abort
2070
+ };
2071
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2072
+ payload.issues.push(issue(_iss));
2073
+ }
2074
+ }
2075
+
2076
+ //#endregion
2077
+ //#region ../../node_modules/zod/v4/core/registries.js
2078
+ const $output = Symbol("ZodOutput");
2079
+ const $input = Symbol("ZodInput");
2080
+ var $ZodRegistry = class {
2081
+ constructor() {
2082
+ this._map = /* @__PURE__ */ new WeakMap();
2083
+ this._idmap = /* @__PURE__ */ new Map();
2084
+ }
2085
+ add(schema, ..._meta) {
2086
+ const meta = _meta[0];
2087
+ this._map.set(schema, meta);
2088
+ if (meta && typeof meta === "object" && "id" in meta) {
2089
+ if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
2090
+ this._idmap.set(meta.id, schema);
2091
+ }
2092
+ return this;
2093
+ }
2094
+ remove(schema) {
2095
+ this._map.delete(schema);
2096
+ return this;
2097
+ }
2098
+ get(schema) {
2099
+ const p = schema._zod.parent;
2100
+ if (p) {
2101
+ const pm = { ...this.get(p) ?? {} };
2102
+ delete pm.id;
2103
+ return {
2104
+ ...pm,
2105
+ ...this._map.get(schema)
2106
+ };
2107
+ }
2108
+ return this._map.get(schema);
2109
+ }
2110
+ has(schema) {
2111
+ return this._map.has(schema);
2112
+ }
2113
+ };
2114
+ function registry() {
2115
+ return new $ZodRegistry();
2116
+ }
2117
+ const globalRegistry = /* @__PURE__ */ registry();
2118
+
2119
+ //#endregion
2120
+ //#region ../../node_modules/zod/v4/core/api.js
2121
+ function _string(Class, params) {
2122
+ return new Class({
2123
+ type: "string",
2124
+ ...normalizeParams(params)
2125
+ });
2126
+ }
2127
+ function _email(Class, params) {
2128
+ return new Class({
2129
+ type: "string",
2130
+ format: "email",
2131
+ check: "string_format",
2132
+ abort: false,
2133
+ ...normalizeParams(params)
2134
+ });
2135
+ }
2136
+ function _guid(Class, params) {
2137
+ return new Class({
2138
+ type: "string",
2139
+ format: "guid",
2140
+ check: "string_format",
2141
+ abort: false,
2142
+ ...normalizeParams(params)
2143
+ });
2144
+ }
2145
+ function _uuid(Class, params) {
2146
+ return new Class({
2147
+ type: "string",
2148
+ format: "uuid",
2149
+ check: "string_format",
2150
+ abort: false,
2151
+ ...normalizeParams(params)
2152
+ });
2153
+ }
2154
+ function _uuidv4(Class, params) {
2155
+ return new Class({
2156
+ type: "string",
2157
+ format: "uuid",
2158
+ check: "string_format",
2159
+ abort: false,
2160
+ version: "v4",
2161
+ ...normalizeParams(params)
2162
+ });
2163
+ }
2164
+ function _uuidv6(Class, params) {
2165
+ return new Class({
2166
+ type: "string",
2167
+ format: "uuid",
2168
+ check: "string_format",
2169
+ abort: false,
2170
+ version: "v6",
2171
+ ...normalizeParams(params)
2172
+ });
2173
+ }
2174
+ function _uuidv7(Class, params) {
2175
+ return new Class({
2176
+ type: "string",
2177
+ format: "uuid",
2178
+ check: "string_format",
2179
+ abort: false,
2180
+ version: "v7",
2181
+ ...normalizeParams(params)
2182
+ });
2183
+ }
2184
+ function _url(Class, params) {
2185
+ return new Class({
2186
+ type: "string",
2187
+ format: "url",
2188
+ check: "string_format",
2189
+ abort: false,
2190
+ ...normalizeParams(params)
2191
+ });
2192
+ }
2193
+ function _emoji(Class, params) {
2194
+ return new Class({
2195
+ type: "string",
2196
+ format: "emoji",
2197
+ check: "string_format",
2198
+ abort: false,
2199
+ ...normalizeParams(params)
2200
+ });
2201
+ }
2202
+ function _nanoid(Class, params) {
2203
+ return new Class({
2204
+ type: "string",
2205
+ format: "nanoid",
2206
+ check: "string_format",
2207
+ abort: false,
2208
+ ...normalizeParams(params)
2209
+ });
2210
+ }
2211
+ function _cuid(Class, params) {
2212
+ return new Class({
2213
+ type: "string",
2214
+ format: "cuid",
2215
+ check: "string_format",
2216
+ abort: false,
2217
+ ...normalizeParams(params)
2218
+ });
2219
+ }
2220
+ function _cuid2(Class, params) {
2221
+ return new Class({
2222
+ type: "string",
2223
+ format: "cuid2",
2224
+ check: "string_format",
2225
+ abort: false,
2226
+ ...normalizeParams(params)
2227
+ });
2228
+ }
2229
+ function _ulid(Class, params) {
2230
+ return new Class({
2231
+ type: "string",
2232
+ format: "ulid",
2233
+ check: "string_format",
2234
+ abort: false,
2235
+ ...normalizeParams(params)
2236
+ });
2237
+ }
2238
+ function _xid(Class, params) {
2239
+ return new Class({
2240
+ type: "string",
2241
+ format: "xid",
2242
+ check: "string_format",
2243
+ abort: false,
2244
+ ...normalizeParams(params)
2245
+ });
2246
+ }
2247
+ function _ksuid(Class, params) {
2248
+ return new Class({
2249
+ type: "string",
2250
+ format: "ksuid",
2251
+ check: "string_format",
2252
+ abort: false,
2253
+ ...normalizeParams(params)
2254
+ });
2255
+ }
2256
+ function _ipv4(Class, params) {
2257
+ return new Class({
2258
+ type: "string",
2259
+ format: "ipv4",
2260
+ check: "string_format",
2261
+ abort: false,
2262
+ ...normalizeParams(params)
2263
+ });
2264
+ }
2265
+ function _ipv6(Class, params) {
2266
+ return new Class({
2267
+ type: "string",
2268
+ format: "ipv6",
2269
+ check: "string_format",
2270
+ abort: false,
2271
+ ...normalizeParams(params)
2272
+ });
2273
+ }
2274
+ function _cidrv4(Class, params) {
2275
+ return new Class({
2276
+ type: "string",
2277
+ format: "cidrv4",
2278
+ check: "string_format",
2279
+ abort: false,
2280
+ ...normalizeParams(params)
2281
+ });
2282
+ }
2283
+ function _cidrv6(Class, params) {
2284
+ return new Class({
2285
+ type: "string",
2286
+ format: "cidrv6",
2287
+ check: "string_format",
2288
+ abort: false,
2289
+ ...normalizeParams(params)
2290
+ });
2291
+ }
2292
+ function _base64(Class, params) {
2293
+ return new Class({
2294
+ type: "string",
2295
+ format: "base64",
2296
+ check: "string_format",
2297
+ abort: false,
2298
+ ...normalizeParams(params)
2299
+ });
2300
+ }
2301
+ function _base64url(Class, params) {
2302
+ return new Class({
2303
+ type: "string",
2304
+ format: "base64url",
2305
+ check: "string_format",
2306
+ abort: false,
2307
+ ...normalizeParams(params)
2308
+ });
2309
+ }
2310
+ function _e164(Class, params) {
2311
+ return new Class({
2312
+ type: "string",
2313
+ format: "e164",
2314
+ check: "string_format",
2315
+ abort: false,
2316
+ ...normalizeParams(params)
2317
+ });
2318
+ }
2319
+ function _jwt(Class, params) {
2320
+ return new Class({
2321
+ type: "string",
2322
+ format: "jwt",
2323
+ check: "string_format",
2324
+ abort: false,
2325
+ ...normalizeParams(params)
2326
+ });
2327
+ }
2328
+ function _isoDateTime(Class, params) {
2329
+ return new Class({
2330
+ type: "string",
2331
+ format: "datetime",
2332
+ check: "string_format",
2333
+ offset: false,
2334
+ local: false,
2335
+ precision: null,
2336
+ ...normalizeParams(params)
2337
+ });
2338
+ }
2339
+ function _isoDate(Class, params) {
2340
+ return new Class({
2341
+ type: "string",
2342
+ format: "date",
2343
+ check: "string_format",
2344
+ ...normalizeParams(params)
2345
+ });
2346
+ }
2347
+ function _isoTime(Class, params) {
2348
+ return new Class({
2349
+ type: "string",
2350
+ format: "time",
2351
+ check: "string_format",
2352
+ precision: null,
2353
+ ...normalizeParams(params)
2354
+ });
2355
+ }
2356
+ function _isoDuration(Class, params) {
2357
+ return new Class({
2358
+ type: "string",
2359
+ format: "duration",
2360
+ check: "string_format",
2361
+ ...normalizeParams(params)
2362
+ });
2363
+ }
2364
+ function _number(Class, params) {
2365
+ return new Class({
2366
+ type: "number",
2367
+ checks: [],
2368
+ ...normalizeParams(params)
2369
+ });
2370
+ }
2371
+ function _int(Class, params) {
2372
+ return new Class({
2373
+ type: "number",
2374
+ check: "number_format",
2375
+ abort: false,
2376
+ format: "safeint",
2377
+ ...normalizeParams(params)
2378
+ });
2379
+ }
2380
+ function _boolean(Class, params) {
2381
+ return new Class({
2382
+ type: "boolean",
2383
+ ...normalizeParams(params)
2384
+ });
2385
+ }
2386
+ function _any(Class) {
2387
+ return new Class({ type: "any" });
2388
+ }
2389
+ function _unknown(Class) {
2390
+ return new Class({ type: "unknown" });
2391
+ }
2392
+ function _never(Class, params) {
2393
+ return new Class({
2394
+ type: "never",
2395
+ ...normalizeParams(params)
2396
+ });
2397
+ }
2398
+ function _lt(value, params) {
2399
+ return new $ZodCheckLessThan({
2400
+ check: "less_than",
2401
+ ...normalizeParams(params),
2402
+ value,
2403
+ inclusive: false
2404
+ });
2405
+ }
2406
+ function _lte(value, params) {
2407
+ return new $ZodCheckLessThan({
2408
+ check: "less_than",
2409
+ ...normalizeParams(params),
2410
+ value,
2411
+ inclusive: true
2412
+ });
2413
+ }
2414
+ function _gt(value, params) {
2415
+ return new $ZodCheckGreaterThan({
2416
+ check: "greater_than",
2417
+ ...normalizeParams(params),
2418
+ value,
2419
+ inclusive: false
2420
+ });
2421
+ }
2422
+ function _gte(value, params) {
2423
+ return new $ZodCheckGreaterThan({
2424
+ check: "greater_than",
2425
+ ...normalizeParams(params),
2426
+ value,
2427
+ inclusive: true
2428
+ });
2429
+ }
2430
+ function _multipleOf(value, params) {
2431
+ return new $ZodCheckMultipleOf({
2432
+ check: "multiple_of",
2433
+ ...normalizeParams(params),
2434
+ value
2435
+ });
2436
+ }
2437
+ function _maxLength(maximum, params) {
2438
+ const ch = new $ZodCheckMaxLength({
2439
+ check: "max_length",
2440
+ ...normalizeParams(params),
2441
+ maximum
2442
+ });
2443
+ return ch;
2444
+ }
2445
+ function _minLength(minimum, params) {
2446
+ return new $ZodCheckMinLength({
2447
+ check: "min_length",
2448
+ ...normalizeParams(params),
2449
+ minimum
2450
+ });
2451
+ }
2452
+ function _length(length, params) {
2453
+ return new $ZodCheckLengthEquals({
2454
+ check: "length_equals",
2455
+ ...normalizeParams(params),
2456
+ length
2457
+ });
2458
+ }
2459
+ function _regex(pattern, params) {
2460
+ return new $ZodCheckRegex({
2461
+ check: "string_format",
2462
+ format: "regex",
2463
+ ...normalizeParams(params),
2464
+ pattern
2465
+ });
2466
+ }
2467
+ function _lowercase(params) {
2468
+ return new $ZodCheckLowerCase({
2469
+ check: "string_format",
2470
+ format: "lowercase",
2471
+ ...normalizeParams(params)
2472
+ });
2473
+ }
2474
+ function _uppercase(params) {
2475
+ return new $ZodCheckUpperCase({
2476
+ check: "string_format",
2477
+ format: "uppercase",
2478
+ ...normalizeParams(params)
2479
+ });
2480
+ }
2481
+ function _includes(includes, params) {
2482
+ return new $ZodCheckIncludes({
2483
+ check: "string_format",
2484
+ format: "includes",
2485
+ ...normalizeParams(params),
2486
+ includes
2487
+ });
2488
+ }
2489
+ function _startsWith(prefix, params) {
2490
+ return new $ZodCheckStartsWith({
2491
+ check: "string_format",
2492
+ format: "starts_with",
2493
+ ...normalizeParams(params),
2494
+ prefix
2495
+ });
2496
+ }
2497
+ function _endsWith(suffix, params) {
2498
+ return new $ZodCheckEndsWith({
2499
+ check: "string_format",
2500
+ format: "ends_with",
2501
+ ...normalizeParams(params),
2502
+ suffix
2503
+ });
2504
+ }
2505
+ function _overwrite(tx) {
2506
+ return new $ZodCheckOverwrite({
2507
+ check: "overwrite",
2508
+ tx
2509
+ });
2510
+ }
2511
+ function _normalize(form) {
2512
+ return _overwrite((input) => input.normalize(form));
2513
+ }
2514
+ function _trim() {
2515
+ return _overwrite((input) => input.trim());
2516
+ }
2517
+ function _toLowerCase() {
2518
+ return _overwrite((input) => input.toLowerCase());
2519
+ }
2520
+ function _toUpperCase() {
2521
+ return _overwrite((input) => input.toUpperCase());
2522
+ }
2523
+ function _array(Class, element, params) {
2524
+ return new Class({
2525
+ type: "array",
2526
+ element,
2527
+ ...normalizeParams(params)
2528
+ });
2529
+ }
2530
+ function _refine(Class, fn, _params) {
2531
+ const schema = new Class({
2532
+ type: "custom",
2533
+ check: "custom",
2534
+ fn,
2535
+ ...normalizeParams(_params)
2536
+ });
2537
+ return schema;
2538
+ }
2539
+
2540
+ //#endregion
2541
+ //#region ../../node_modules/zod/v4/classic/iso.js
2542
+ const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
2543
+ $ZodISODateTime.init(inst, def);
2544
+ ZodStringFormat.init(inst, def);
2545
+ });
2546
+ function datetime(params) {
2547
+ return _isoDateTime(ZodISODateTime, params);
2548
+ }
2549
+ const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
2550
+ $ZodISODate.init(inst, def);
2551
+ ZodStringFormat.init(inst, def);
2552
+ });
2553
+ function date(params) {
2554
+ return _isoDate(ZodISODate, params);
2555
+ }
2556
+ const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
2557
+ $ZodISOTime.init(inst, def);
2558
+ ZodStringFormat.init(inst, def);
2559
+ });
2560
+ function time(params) {
2561
+ return _isoTime(ZodISOTime, params);
2562
+ }
2563
+ const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
2564
+ $ZodISODuration.init(inst, def);
2565
+ ZodStringFormat.init(inst, def);
2566
+ });
2567
+ function duration(params) {
2568
+ return _isoDuration(ZodISODuration, params);
2569
+ }
2570
+
2571
+ //#endregion
2572
+ //#region ../../node_modules/zod/v4/classic/errors.js
2573
+ const initializer = (inst, issues) => {
2574
+ $ZodError.init(inst, issues);
2575
+ inst.name = "ZodError";
2576
+ Object.defineProperties(inst, {
2577
+ format: { value: (mapper) => formatError(inst, mapper) },
2578
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
2579
+ addIssue: { value: (issue$1) => inst.issues.push(issue$1) },
2580
+ addIssues: { value: (issues$1) => inst.issues.push(...issues$1) },
2581
+ isEmpty: { get() {
2582
+ return inst.issues.length === 0;
2583
+ } }
2584
+ });
2585
+ };
2586
+ const ZodError = $constructor("ZodError", initializer);
2587
+ const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
2588
+
2589
+ //#endregion
2590
+ //#region ../../node_modules/zod/v4/classic/parse.js
2591
+ const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
2592
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
2593
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
2594
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
2595
+
2596
+ //#endregion
2597
+ //#region ../../node_modules/zod/v4/classic/schemas.js
2598
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2599
+ $ZodType.init(inst, def);
2600
+ inst.def = def;
2601
+ Object.defineProperty(inst, "_def", { value: def });
2602
+ inst.check = (...checks) => {
2603
+ return inst.clone({
2604
+ ...def,
2605
+ checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
2606
+ check: ch,
2607
+ def: { check: "custom" },
2608
+ onattach: []
2609
+ } } : ch)]
2610
+ });
2611
+ };
2612
+ inst.clone = (def$1, params) => clone(inst, def$1, params);
2613
+ inst.brand = () => inst;
2614
+ inst.register = (reg, meta) => {
2615
+ reg.add(inst, meta);
2616
+ return inst;
2617
+ };
2618
+ inst.parse = (data, params) => parse$1(inst, data, params, { callee: inst.parse });
2619
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
2620
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
2621
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
2622
+ inst.spa = inst.safeParseAsync;
2623
+ inst.refine = (check$1, params) => inst.check(refine(check$1, params));
2624
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
2625
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
2626
+ inst.optional = () => optional(inst);
2627
+ inst.nullable = () => nullable(inst);
2628
+ inst.nullish = () => optional(nullable(inst));
2629
+ inst.nonoptional = (params) => nonoptional(inst, params);
2630
+ inst.array = () => array(inst);
2631
+ inst.or = (arg) => union([inst, arg]);
2632
+ inst.and = (arg) => intersection(inst, arg);
2633
+ inst.transform = (tx) => pipe(inst, transform(tx));
2634
+ inst.default = (def$1) => _default(inst, def$1);
2635
+ inst.prefault = (def$1) => prefault(inst, def$1);
2636
+ inst.catch = (params) => _catch(inst, params);
2637
+ inst.pipe = (target) => pipe(inst, target);
2638
+ inst.readonly = () => readonly(inst);
2639
+ inst.describe = (description) => {
2640
+ const cl = inst.clone();
2641
+ globalRegistry.add(cl, { description });
2642
+ return cl;
2643
+ };
2644
+ Object.defineProperty(inst, "description", {
2645
+ get() {
2646
+ return globalRegistry.get(inst)?.description;
2647
+ },
2648
+ configurable: true
2649
+ });
2650
+ inst.meta = (...args) => {
2651
+ if (args.length === 0) return globalRegistry.get(inst);
2652
+ const cl = inst.clone();
2653
+ globalRegistry.add(cl, args[0]);
2654
+ return cl;
2655
+ };
2656
+ inst.isOptional = () => inst.safeParse(void 0).success;
2657
+ inst.isNullable = () => inst.safeParse(null).success;
2658
+ return inst;
2659
+ });
2660
+ /** @internal */
2661
+ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
2662
+ $ZodString.init(inst, def);
2663
+ ZodType.init(inst, def);
2664
+ const bag = inst._zod.bag;
2665
+ inst.format = bag.format ?? null;
2666
+ inst.minLength = bag.minimum ?? null;
2667
+ inst.maxLength = bag.maximum ?? null;
2668
+ inst.regex = (...args) => inst.check(_regex(...args));
2669
+ inst.includes = (...args) => inst.check(_includes(...args));
2670
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
2671
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
2672
+ inst.min = (...args) => inst.check(_minLength(...args));
2673
+ inst.max = (...args) => inst.check(_maxLength(...args));
2674
+ inst.length = (...args) => inst.check(_length(...args));
2675
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
2676
+ inst.lowercase = (params) => inst.check(_lowercase(params));
2677
+ inst.uppercase = (params) => inst.check(_uppercase(params));
2678
+ inst.trim = () => inst.check(_trim());
2679
+ inst.normalize = (...args) => inst.check(_normalize(...args));
2680
+ inst.toLowerCase = () => inst.check(_toLowerCase());
2681
+ inst.toUpperCase = () => inst.check(_toUpperCase());
2682
+ });
2683
+ const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
2684
+ $ZodString.init(inst, def);
2685
+ _ZodString.init(inst, def);
2686
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
2687
+ inst.url = (params) => inst.check(_url(ZodURL, params));
2688
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
2689
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
2690
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2691
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
2692
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
2693
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
2694
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
2695
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
2696
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
2697
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
2698
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
2699
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
2700
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
2701
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
2702
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
2703
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
2704
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
2705
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
2706
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
2707
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
2708
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
2709
+ inst.datetime = (params) => inst.check(datetime(params));
2710
+ inst.date = (params) => inst.check(date(params));
2711
+ inst.time = (params) => inst.check(time(params));
2712
+ inst.duration = (params) => inst.check(duration(params));
2713
+ });
2714
+ function string(params) {
2715
+ return _string(ZodString, params);
2716
+ }
2717
+ const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
2718
+ $ZodStringFormat.init(inst, def);
2719
+ _ZodString.init(inst, def);
2720
+ });
2721
+ const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
2722
+ $ZodEmail.init(inst, def);
2723
+ ZodStringFormat.init(inst, def);
2724
+ });
2725
+ const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
2726
+ $ZodGUID.init(inst, def);
2727
+ ZodStringFormat.init(inst, def);
2728
+ });
2729
+ const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
2730
+ $ZodUUID.init(inst, def);
2731
+ ZodStringFormat.init(inst, def);
2732
+ });
2733
+ const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
2734
+ $ZodURL.init(inst, def);
2735
+ ZodStringFormat.init(inst, def);
2736
+ });
2737
+ const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
2738
+ $ZodEmoji.init(inst, def);
2739
+ ZodStringFormat.init(inst, def);
2740
+ });
2741
+ const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
2742
+ $ZodNanoID.init(inst, def);
2743
+ ZodStringFormat.init(inst, def);
2744
+ });
2745
+ const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
2746
+ $ZodCUID.init(inst, def);
2747
+ ZodStringFormat.init(inst, def);
2748
+ });
2749
+ const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
2750
+ $ZodCUID2.init(inst, def);
2751
+ ZodStringFormat.init(inst, def);
2752
+ });
2753
+ const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
2754
+ $ZodULID.init(inst, def);
2755
+ ZodStringFormat.init(inst, def);
2756
+ });
2757
+ const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
2758
+ $ZodXID.init(inst, def);
2759
+ ZodStringFormat.init(inst, def);
2760
+ });
2761
+ const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
2762
+ $ZodKSUID.init(inst, def);
2763
+ ZodStringFormat.init(inst, def);
2764
+ });
2765
+ const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
2766
+ $ZodIPv4.init(inst, def);
2767
+ ZodStringFormat.init(inst, def);
2768
+ });
2769
+ const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
2770
+ $ZodIPv6.init(inst, def);
2771
+ ZodStringFormat.init(inst, def);
2772
+ });
2773
+ const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
2774
+ $ZodCIDRv4.init(inst, def);
2775
+ ZodStringFormat.init(inst, def);
2776
+ });
2777
+ const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
2778
+ $ZodCIDRv6.init(inst, def);
2779
+ ZodStringFormat.init(inst, def);
2780
+ });
2781
+ const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
2782
+ $ZodBase64.init(inst, def);
2783
+ ZodStringFormat.init(inst, def);
2784
+ });
2785
+ const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
2786
+ $ZodBase64URL.init(inst, def);
2787
+ ZodStringFormat.init(inst, def);
2788
+ });
2789
+ const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
2790
+ $ZodE164.init(inst, def);
2791
+ ZodStringFormat.init(inst, def);
2792
+ });
2793
+ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
2794
+ $ZodJWT.init(inst, def);
2795
+ ZodStringFormat.init(inst, def);
2796
+ });
2797
+ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
2798
+ $ZodNumber.init(inst, def);
2799
+ ZodType.init(inst, def);
2800
+ inst.gt = (value, params) => inst.check(_gt(value, params));
2801
+ inst.gte = (value, params) => inst.check(_gte(value, params));
2802
+ inst.min = (value, params) => inst.check(_gte(value, params));
2803
+ inst.lt = (value, params) => inst.check(_lt(value, params));
2804
+ inst.lte = (value, params) => inst.check(_lte(value, params));
2805
+ inst.max = (value, params) => inst.check(_lte(value, params));
2806
+ inst.int = (params) => inst.check(int(params));
2807
+ inst.safe = (params) => inst.check(int(params));
2808
+ inst.positive = (params) => inst.check(_gt(0, params));
2809
+ inst.nonnegative = (params) => inst.check(_gte(0, params));
2810
+ inst.negative = (params) => inst.check(_lt(0, params));
2811
+ inst.nonpositive = (params) => inst.check(_lte(0, params));
2812
+ inst.multipleOf = (value, params) => inst.check(_multipleOf(value, params));
2813
+ inst.step = (value, params) => inst.check(_multipleOf(value, params));
2814
+ inst.finite = () => inst;
2815
+ const bag = inst._zod.bag;
2816
+ inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
2817
+ inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
2818
+ inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? .5);
2819
+ inst.isFinite = true;
2820
+ inst.format = bag.format ?? null;
2821
+ });
2822
+ function number(params) {
2823
+ return _number(ZodNumber, params);
2824
+ }
2825
+ const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
2826
+ $ZodNumberFormat.init(inst, def);
2827
+ ZodNumber.init(inst, def);
2828
+ });
2829
+ function int(params) {
2830
+ return _int(ZodNumberFormat, params);
2831
+ }
2832
+ const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
2833
+ $ZodBoolean.init(inst, def);
2834
+ ZodType.init(inst, def);
2835
+ });
2836
+ function boolean(params) {
2837
+ return _boolean(ZodBoolean, params);
2838
+ }
2839
+ const ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
2840
+ $ZodAny.init(inst, def);
2841
+ ZodType.init(inst, def);
2842
+ });
2843
+ function any() {
2844
+ return _any(ZodAny);
2845
+ }
2846
+ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
2847
+ $ZodUnknown.init(inst, def);
2848
+ ZodType.init(inst, def);
2849
+ });
2850
+ function unknown() {
2851
+ return _unknown(ZodUnknown);
2852
+ }
2853
+ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
2854
+ $ZodNever.init(inst, def);
2855
+ ZodType.init(inst, def);
2856
+ });
2857
+ function never(params) {
2858
+ return _never(ZodNever, params);
2859
+ }
2860
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
2861
+ $ZodArray.init(inst, def);
2862
+ ZodType.init(inst, def);
2863
+ inst.element = def.element;
2864
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
2865
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
2866
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
2867
+ inst.length = (len, params) => inst.check(_length(len, params));
2868
+ inst.unwrap = () => inst.element;
2869
+ });
2870
+ function array(element, params) {
2871
+ return _array(ZodArray, element, params);
2872
+ }
2873
+ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
2874
+ $ZodObject.init(inst, def);
2875
+ ZodType.init(inst, def);
2876
+ defineLazy(inst, "shape", () => def.shape);
2877
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
2878
+ inst.catchall = (catchall) => inst.clone({
2879
+ ...inst._zod.def,
2880
+ catchall
2881
+ });
2882
+ inst.passthrough = () => inst.clone({
2883
+ ...inst._zod.def,
2884
+ catchall: unknown()
2885
+ });
2886
+ inst.loose = () => inst.clone({
2887
+ ...inst._zod.def,
2888
+ catchall: unknown()
2889
+ });
2890
+ inst.strict = () => inst.clone({
2891
+ ...inst._zod.def,
2892
+ catchall: never()
2893
+ });
2894
+ inst.strip = () => inst.clone({
2895
+ ...inst._zod.def,
2896
+ catchall: void 0
2897
+ });
2898
+ inst.extend = (incoming) => {
2899
+ return extend(inst, incoming);
2900
+ };
2901
+ inst.merge = (other) => merge(inst, other);
2902
+ inst.pick = (mask) => pick(inst, mask);
2903
+ inst.omit = (mask) => omit(inst, mask);
2904
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
2905
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
2906
+ });
2907
+ function object(shape, params) {
2908
+ const def = {
2909
+ type: "object",
2910
+ get shape() {
2911
+ assignProp(this, "shape", { ...shape });
2912
+ return this.shape;
2913
+ },
2914
+ ...normalizeParams(params)
2915
+ };
2916
+ return new ZodObject(def);
2917
+ }
2918
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
2919
+ $ZodUnion.init(inst, def);
2920
+ ZodType.init(inst, def);
2921
+ inst.options = def.options;
2922
+ });
2923
+ function union(options, params) {
2924
+ return new ZodUnion({
2925
+ type: "union",
2926
+ options,
2927
+ ...normalizeParams(params)
2928
+ });
2929
+ }
2930
+ const ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("ZodDiscriminatedUnion", (inst, def) => {
2931
+ ZodUnion.init(inst, def);
2932
+ $ZodDiscriminatedUnion.init(inst, def);
2933
+ });
2934
+ function discriminatedUnion(discriminator, options, params) {
2935
+ return new ZodDiscriminatedUnion({
2936
+ type: "union",
2937
+ options,
2938
+ discriminator,
2939
+ ...normalizeParams(params)
2940
+ });
2941
+ }
2942
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
2943
+ $ZodIntersection.init(inst, def);
2944
+ ZodType.init(inst, def);
2945
+ });
2946
+ function intersection(left, right) {
2947
+ return new ZodIntersection({
2948
+ type: "intersection",
2949
+ left,
2950
+ right
2951
+ });
2952
+ }
2953
+ const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
2954
+ $ZodRecord.init(inst, def);
2955
+ ZodType.init(inst, def);
2956
+ inst.keyType = def.keyType;
2957
+ inst.valueType = def.valueType;
2958
+ });
2959
+ function record(keyType, valueType, params) {
2960
+ return new ZodRecord({
2961
+ type: "record",
2962
+ keyType,
2963
+ valueType,
2964
+ ...normalizeParams(params)
2965
+ });
2966
+ }
2967
+ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
2968
+ $ZodEnum.init(inst, def);
2969
+ ZodType.init(inst, def);
2970
+ inst.enum = def.entries;
2971
+ inst.options = Object.values(def.entries);
2972
+ const keys = new Set(Object.keys(def.entries));
2973
+ inst.extract = (values, params) => {
2974
+ const newEntries = {};
2975
+ for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
2976
+ else throw new Error(`Key ${value} not found in enum`);
2977
+ return new ZodEnum({
2978
+ ...def,
2979
+ checks: [],
2980
+ ...normalizeParams(params),
2981
+ entries: newEntries
2982
+ });
2983
+ };
2984
+ inst.exclude = (values, params) => {
2985
+ const newEntries = { ...def.entries };
2986
+ for (const value of values) if (keys.has(value)) delete newEntries[value];
2987
+ else throw new Error(`Key ${value} not found in enum`);
2988
+ return new ZodEnum({
2989
+ ...def,
2990
+ checks: [],
2991
+ ...normalizeParams(params),
2992
+ entries: newEntries
2993
+ });
2994
+ };
2995
+ });
2996
+ function _enum(values, params) {
2997
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
2998
+ return new ZodEnum({
2999
+ type: "enum",
3000
+ entries,
3001
+ ...normalizeParams(params)
3002
+ });
3003
+ }
3004
+ const ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
3005
+ $ZodLiteral.init(inst, def);
3006
+ ZodType.init(inst, def);
3007
+ inst.values = new Set(def.values);
3008
+ Object.defineProperty(inst, "value", { get() {
3009
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
3010
+ return def.values[0];
3011
+ } });
3012
+ });
3013
+ function literal(value, params) {
3014
+ return new ZodLiteral({
3015
+ type: "literal",
3016
+ values: Array.isArray(value) ? value : [value],
3017
+ ...normalizeParams(params)
3018
+ });
3019
+ }
3020
+ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3021
+ $ZodTransform.init(inst, def);
3022
+ ZodType.init(inst, def);
3023
+ inst._zod.parse = (payload, _ctx) => {
3024
+ payload.addIssue = (issue$1) => {
3025
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
3026
+ else {
3027
+ const _issue = issue$1;
3028
+ if (_issue.fatal) _issue.continue = false;
3029
+ _issue.code ?? (_issue.code = "custom");
3030
+ _issue.input ?? (_issue.input = payload.value);
3031
+ _issue.inst ?? (_issue.inst = inst);
3032
+ _issue.continue ?? (_issue.continue = true);
3033
+ payload.issues.push(issue(_issue));
3034
+ }
3035
+ };
3036
+ const output = def.transform(payload.value, payload);
3037
+ if (output instanceof Promise) return output.then((output$1) => {
3038
+ payload.value = output$1;
3039
+ return payload;
3040
+ });
3041
+ payload.value = output;
3042
+ return payload;
3043
+ };
3044
+ });
3045
+ function transform(fn) {
3046
+ return new ZodTransform({
3047
+ type: "transform",
3048
+ transform: fn
3049
+ });
3050
+ }
3051
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3052
+ $ZodOptional.init(inst, def);
3053
+ ZodType.init(inst, def);
3054
+ inst.unwrap = () => inst._zod.def.innerType;
3055
+ });
3056
+ function optional(innerType) {
3057
+ return new ZodOptional({
3058
+ type: "optional",
3059
+ innerType
3060
+ });
3061
+ }
3062
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3063
+ $ZodNullable.init(inst, def);
3064
+ ZodType.init(inst, def);
3065
+ inst.unwrap = () => inst._zod.def.innerType;
3066
+ });
3067
+ function nullable(innerType) {
3068
+ return new ZodNullable({
3069
+ type: "nullable",
3070
+ innerType
3071
+ });
3072
+ }
3073
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3074
+ $ZodDefault.init(inst, def);
3075
+ ZodType.init(inst, def);
3076
+ inst.unwrap = () => inst._zod.def.innerType;
3077
+ inst.removeDefault = inst.unwrap;
3078
+ });
3079
+ function _default(innerType, defaultValue) {
3080
+ return new ZodDefault({
3081
+ type: "default",
3082
+ innerType,
3083
+ get defaultValue() {
3084
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
3085
+ }
3086
+ });
3087
+ }
3088
+ const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3089
+ $ZodPrefault.init(inst, def);
3090
+ ZodType.init(inst, def);
3091
+ inst.unwrap = () => inst._zod.def.innerType;
3092
+ });
3093
+ function prefault(innerType, defaultValue) {
3094
+ return new ZodPrefault({
3095
+ type: "prefault",
3096
+ innerType,
3097
+ get defaultValue() {
3098
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
3099
+ }
3100
+ });
3101
+ }
3102
+ const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3103
+ $ZodNonOptional.init(inst, def);
3104
+ ZodType.init(inst, def);
3105
+ inst.unwrap = () => inst._zod.def.innerType;
3106
+ });
3107
+ function nonoptional(innerType, params) {
3108
+ return new ZodNonOptional({
3109
+ type: "nonoptional",
3110
+ innerType,
3111
+ ...normalizeParams(params)
3112
+ });
3113
+ }
3114
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3115
+ $ZodCatch.init(inst, def);
3116
+ ZodType.init(inst, def);
3117
+ inst.unwrap = () => inst._zod.def.innerType;
3118
+ inst.removeCatch = inst.unwrap;
3119
+ });
3120
+ function _catch(innerType, catchValue) {
3121
+ return new ZodCatch({
3122
+ type: "catch",
3123
+ innerType,
3124
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3125
+ });
3126
+ }
3127
+ const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3128
+ $ZodPipe.init(inst, def);
3129
+ ZodType.init(inst, def);
3130
+ inst.in = def.in;
3131
+ inst.out = def.out;
3132
+ });
3133
+ function pipe(in_, out) {
3134
+ return new ZodPipe({
3135
+ type: "pipe",
3136
+ in: in_,
3137
+ out
3138
+ });
3139
+ }
3140
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3141
+ $ZodReadonly.init(inst, def);
3142
+ ZodType.init(inst, def);
3143
+ });
3144
+ function readonly(innerType) {
3145
+ return new ZodReadonly({
3146
+ type: "readonly",
3147
+ innerType
3148
+ });
3149
+ }
3150
+ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3151
+ $ZodCustom.init(inst, def);
3152
+ ZodType.init(inst, def);
3153
+ });
3154
+ function check(fn, params) {
3155
+ const ch = new $ZodCheck({
3156
+ check: "custom",
3157
+ ...normalizeParams(params)
3158
+ });
3159
+ ch._zod.check = fn;
3160
+ return ch;
3161
+ }
3162
+ function refine(fn, _params = {}) {
3163
+ return _refine(ZodCustom, fn, _params);
3164
+ }
3165
+ function superRefine(fn, params) {
3166
+ const ch = check((payload) => {
3167
+ payload.addIssue = (issue$1) => {
3168
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
3169
+ else {
3170
+ const _issue = issue$1;
3171
+ if (_issue.fatal) _issue.continue = false;
3172
+ _issue.code ?? (_issue.code = "custom");
3173
+ _issue.input ?? (_issue.input = payload.value);
3174
+ _issue.inst ?? (_issue.inst = ch);
3175
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
3176
+ payload.issues.push(issue(_issue));
3177
+ }
3178
+ };
3179
+ return fn(payload.value, payload);
3180
+ }, params);
3181
+ return ch;
3182
+ }
3183
+
3184
+ //#endregion
3185
+ //#region src/connectors/constants.ts
3186
+ const DEFAULT_PAGE_SIZE = 25;
3187
+
3188
+ //#endregion
3189
+ //#region src/connectors/responses.ts
3190
+ const getDefaultSuccessOperationResponse = (operationType) => {
3191
+ switch (operationType) {
3192
+ case "list": return {
3193
+ statusCode: 200,
3194
+ description: "The list of records was retrieved."
3195
+ };
3196
+ case "get": return {
3197
+ statusCode: 200,
3198
+ description: "The record with the given identifier was retrieved."
3199
+ };
3200
+ case "create": return {
3201
+ statusCode: 201,
3202
+ description: "The record was created successfully."
3203
+ };
3204
+ case "update": return {
3205
+ statusCode: 200,
3206
+ description: "The record was updated successfully."
3207
+ };
3208
+ case "delete": return {
3209
+ statusCode: 204,
3210
+ description: "The record was deleted successfully."
3211
+ };
3212
+ case "custom": return {
3213
+ statusCode: 200,
3214
+ description: "The operation was executed successfully."
3215
+ };
3216
+ case "unknown": return { statusCode: 200 };
3217
+ default: throw new Error(`Unknown operation type: ${operationType}`);
3218
+ }
3219
+ };
3220
+ const getDefaultErrorOperationResponses = () => {
3221
+ const defaultErrorStatusCodes = {
3222
+ 400: {
3223
+ statusCode: 400,
3224
+ description: "Invalid request."
3225
+ },
3226
+ 401: {
3227
+ statusCode: 401,
3228
+ description: "Unauthorized access."
3229
+ },
3230
+ 403: {
3231
+ statusCode: 403,
3232
+ description: "Forbidden."
3233
+ },
3234
+ 404: {
3235
+ statusCode: 404,
3236
+ description: "Resource not found."
3237
+ },
3238
+ 500: {
3239
+ statusCode: 500,
3240
+ description: "Server error while executing the request."
3241
+ }
3242
+ };
3243
+ return defaultErrorStatusCodes;
3244
+ };
3245
+
3246
+ //#endregion
3247
+ //#region src/connectors/schemas.ts
3248
+ const BASE_AUTH_FIELD = {
3249
+ key: string(),
3250
+ label: string(),
3251
+ required: boolean().optional().default(false),
3252
+ secret: boolean().optional().default(false),
3253
+ readOnly: boolean().optional().default(false),
3254
+ placeholder: string().optional(),
3255
+ description: string().optional(),
3256
+ tooltip: string().optional()
3257
+ };
3258
+ const AUTHENTICATION_FIELD_SCHEMA = discriminatedUnion("type", [object({
3259
+ ...BASE_AUTH_FIELD,
3260
+ type: _enum(["text", "password"])
3261
+ }), object({
3262
+ ...BASE_AUTH_FIELD,
3263
+ type: literal("select"),
3264
+ options: object({
3265
+ value: string(),
3266
+ label: string()
3267
+ }).array()
3268
+ })]);
3269
+ const OPERATION_SCHEMA = object({
3270
+ operationId: string(),
3271
+ categories: string().array(),
3272
+ operationType: _enum([
3273
+ "list",
3274
+ "get",
3275
+ "create",
3276
+ "update",
3277
+ "delete",
3278
+ "custom",
3279
+ "unknown"
3280
+ ]),
3281
+ schema: string().optional(),
3282
+ entrypointUrl: string().optional(),
3283
+ entrypointHttpMethod: string().optional(),
3284
+ description: string(),
3285
+ responses: object({
3286
+ statusCode: number(),
3287
+ description: string()
3288
+ }).array().optional(),
3289
+ inputs: object({
3290
+ name: string(),
3291
+ type: string(),
3292
+ required: boolean(),
3293
+ description: string(),
3294
+ in: string()
3295
+ }).array().optional(),
3296
+ cursor: object({
3297
+ enabled: boolean(),
3298
+ pageSize: number()
3299
+ }).optional(),
3300
+ compositeIdentifiers: object({
3301
+ enabled: boolean(),
3302
+ version: number().optional(),
3303
+ fields: object({
3304
+ targetFieldKey: string(),
3305
+ remote: string().optional(),
3306
+ components: string().array()
3307
+ }).array().optional()
3308
+ }).optional(),
3309
+ scheduledJobs: object({
3310
+ enabled: boolean(),
3311
+ type: _enum(["data_sync"]),
3312
+ schedule: string(),
3313
+ description: string(),
3314
+ requestParams: object({
3315
+ fields: string().array().optional(),
3316
+ expand: string().array().optional(),
3317
+ filter: record(string(), string()).optional()
3318
+ }).optional(),
3319
+ syncFilter: object({
3320
+ name: _enum(["updated_after", "created_after"]),
3321
+ initialLoopbackPeriod: string(),
3322
+ incrementalLoopbackPeriod: string()
3323
+ }).optional()
3324
+ }).array().optional(),
3325
+ fieldConfigs: object({
3326
+ targetFieldKey: string(),
3327
+ alias: string().optional(),
3328
+ expression: string(),
3329
+ type: _enum([
3330
+ "string",
3331
+ "number",
3332
+ "boolean",
3333
+ "datetime_string",
3334
+ "enum"
3335
+ ]),
3336
+ custom: boolean().default(false),
3337
+ hidden: boolean().default(false),
3338
+ enumMapper: object({ matcher: _enum([
3339
+ "country_alpha2code_by_alpha2code",
3340
+ "country_alpha3code_by_alpha3code",
3341
+ "country_code_by_country_code",
3342
+ "country_name_by_country_name",
3343
+ "country_name_by_alpha3code",
3344
+ "country_name_by_alpha2code",
3345
+ "country_name_by_country_code",
3346
+ "country_alpha3code_by_alpha2code",
3347
+ "country_alpha3code_by_country_name",
3348
+ "country_alpha3code_by_country_code",
3349
+ "country_alpha2code_by_alpha3code",
3350
+ "country_alpha2code_by_country_name",
3351
+ "country_alpha2code_by_country_code",
3352
+ "country_code_by_alpha2code",
3353
+ "country_code_by_alpha3code",
3354
+ "country_code_by_country_name",
3355
+ "country_subdivisions_by_alpha2code",
3356
+ "country_subdivision_code_by_subdivision_name",
3357
+ "country_alpha2code_by_citizenship",
3358
+ "country_subdivision_name_by_subdivision_code"
3359
+ ]).or(object({
3360
+ matchExpression: string(),
3361
+ value: string()
3362
+ }).array()) }).optional()
3363
+ }).array().optional(),
3364
+ steps: object({
3365
+ stepId: string(),
3366
+ description: string(),
3367
+ stepFunction: object({
3368
+ functionName: string(),
3369
+ version: string().optional(),
3370
+ parameters: record(string(), unknown())
3371
+ }),
3372
+ condition: string().optional(),
3373
+ ignoreError: boolean().optional()
3374
+ }).array(),
3375
+ result: string().or(record(string(), unknown())).optional()
3376
+ });
3377
+ const CONNECTOR_YAML_SCHEMA = object({
3378
+ StackOne: string(),
3379
+ info: object({
3380
+ title: string(),
3381
+ version: string(),
3382
+ key: string(),
3383
+ description: string().optional()
3384
+ }),
3385
+ baseUrl: string(),
3386
+ authentication: record(string(), object({
3387
+ type: string(),
3388
+ label: string(),
3389
+ authorization: __stackone_core.AUTHENTICATION_SCHEMA,
3390
+ environments: object({
3391
+ key: string(),
3392
+ name: string()
3393
+ }).array(),
3394
+ support: object({
3395
+ link: string(),
3396
+ description: string().optional()
3397
+ }),
3398
+ configFields: AUTHENTICATION_FIELD_SCHEMA.array().optional(),
3399
+ setupFields: AUTHENTICATION_FIELD_SCHEMA.array().optional(),
3400
+ testOperationsIds: string().array().optional()
3401
+ })).array().optional(),
3402
+ operations: OPERATION_SCHEMA.array().optional()
3403
+ });
3404
+
3405
+ //#endregion
3406
+ //#region src/connectors/parsers.ts
3407
+ function parseYamlConnector(yamlFileContents) {
3408
+ try {
3409
+ const yamlConnector = (0, yaml.parse)(yamlFileContents);
3410
+ const parsedYamlConnector = CONNECTOR_YAML_SCHEMA.parse(yamlConnector);
3411
+ const newJsonConnector = {
3412
+ title: parsedYamlConnector.info.title,
3413
+ version: parsedYamlConnector.info.version,
3414
+ key: parsedYamlConnector.info.key,
3415
+ description: parsedYamlConnector.info.description
3416
+ };
3417
+ const authentication = buildAuthenticationFromYaml(parsedYamlConnector);
3418
+ const baseRequestParams = {
3419
+ baseUrl: parsedYamlConnector.baseUrl,
3420
+ authentication: stripAuthenticationSetup(authentication)
3421
+ };
3422
+ const newOperations = buildOperationsFromYaml(parsedYamlConnector, baseRequestParams);
3423
+ newJsonConnector.operations = newOperations;
3424
+ newJsonConnector.authentication = authentication;
3425
+ if ((0, __stackone_utils.notMissing)(newOperations)) newJsonConnector.categories = getConnectorCategoriesFromOperations(Object.values(newOperations));
3426
+ return newJsonConnector;
3427
+ } catch (error) {
3428
+ throw new Error(`Error parsing YAML file: ${error.message}`);
3429
+ }
3430
+ }
3431
+ const stripAuthenticationSetup = (authentication) => {
3432
+ const result = {};
3433
+ for (const [key, value] of Object.entries(authentication)) if (value && typeof value === "object") {
3434
+ const { setupFields: _setupFields, configFields: _configFields, support: _support, testOperationsIds: _testOperationsIds,...rest } = value;
3435
+ result[key] = stripAuthenticationSetup(rest);
3436
+ } else result[key] = value;
3437
+ return result;
3438
+ };
3439
+ const getConnectorCategoriesFromOperations = (operations) => {
3440
+ const categoriesSet = operations.reduce((acc, op) => {
3441
+ for (const category of op.categories) acc.add(category);
3442
+ return acc;
3443
+ }, /* @__PURE__ */ new Set());
3444
+ return Array.from(categoriesSet);
3445
+ };
3446
+ const buildAuthenticationFromYaml = (parsedYamlConnector) => {
3447
+ const authentication = {};
3448
+ for (const auth of parsedYamlConnector.authentication ?? []) {
3449
+ const [authKey] = Object.keys(auth);
3450
+ const authConfig = auth[authKey].environments.reduce((acc, env) => {
3451
+ const { key, name } = env;
3452
+ const { environments: _envs,...authConfig$1 } = auth[authKey];
3453
+ acc[key] = {
3454
+ ...authConfig$1,
3455
+ envKey: key,
3456
+ envName: name
3457
+ };
3458
+ return acc;
3459
+ }, {});
3460
+ authentication[authKey] = authConfig;
3461
+ }
3462
+ return authentication;
3463
+ };
3464
+ const buildOperationKey = (op) => {
3465
+ return op.entrypointUrl && op.entrypointHttpMethod ? `${op.entrypointHttpMethod.toUpperCase()} ${op.entrypointUrl}` : void 0;
3466
+ };
3467
+ const inferOperationKey = (op) => {
3468
+ return op.operationType === "list" ? `GET /${op.schema}` : `GET /${op.schema}/:id`;
3469
+ };
3470
+ const inferEntrypointUrl = (op) => {
3471
+ return op.operationType === "list" ? `/${op.schema}` : `/${op.schema}/:id`;
3472
+ };
3473
+ const buildOperationResponses = (op) => {
3474
+ const defaultOperationResponses = {
3475
+ success: getDefaultSuccessOperationResponse(op.operationType),
3476
+ errors: getDefaultErrorOperationResponses()
3477
+ };
3478
+ const operationResponses = op.responses?.reduce((acc, response) => {
3479
+ const isSuccess = (0, __stackone_transport.isSuccessStatusCode)(response.statusCode);
3480
+ if (isSuccess) acc.success = {
3481
+ statusCode: response.statusCode,
3482
+ description: response.description
3483
+ };
3484
+ else acc.errors[response.statusCode] = {
3485
+ statusCode: response.statusCode,
3486
+ description: response.description
3487
+ };
3488
+ return acc;
3489
+ }, defaultOperationResponses);
3490
+ return operationResponses ?? defaultOperationResponses;
3491
+ };
3492
+ const buildOperationsFromYaml = (parsedYamlConnector, baseRequestParams) => {
3493
+ const newOperations = parsedYamlConnector.operations?.reduce((acc, op) => {
3494
+ const operationKey = buildOperationKey(op);
3495
+ const inferredOperationKey = inferOperationKey(op);
3496
+ const inferredEntrypointUrl = inferEntrypointUrl(op);
3497
+ const operationResponses = buildOperationResponses(op);
3498
+ const cursorConfig = buildCursorConfig(op);
3499
+ const inputs = op.inputs || [];
3500
+ if (cursorConfig.enabled) inputs?.push({
3501
+ type: "string",
3502
+ name: "page_size",
3503
+ in: "query",
3504
+ required: false,
3505
+ description: "Number of items to return per page"
3506
+ });
3507
+ acc[operationKey ?? inferredOperationKey] = {
3508
+ id: op.operationId,
3509
+ categories: op.categories,
3510
+ description: op.description,
3511
+ operationType: op.operationType,
3512
+ entrypointUrl: op.entrypointUrl ?? inferredEntrypointUrl,
3513
+ entrypointHttpMethod: op.entrypointHttpMethod ?? "get",
3514
+ responses: operationResponses,
3515
+ cursor: cursorConfig,
3516
+ compositeIdentifiers: parseCompositeIdentifiersConfig(op),
3517
+ scheduledJobs: parseScheduledJobConfig(op),
3518
+ inputs,
3519
+ steps: op.steps.reduce((acc$1, step) => {
3520
+ acc$1[step.stepId] = {
3521
+ id: step.stepId,
3522
+ description: step.description,
3523
+ condition: step.condition,
3524
+ ignoreError: step.ignoreError,
3525
+ stepFunction: {
3526
+ functionName: step.stepFunction.functionName,
3527
+ version: step.stepFunction.version,
3528
+ params: {
3529
+ ...step.stepFunction.parameters,
3530
+ ...getDefaultRequestStepFunctionsParams(step.stepFunction.functionName, baseRequestParams, step.stepFunction.parameters),
3531
+ ...step.stepFunction.functionName === "map_fields" || step.stepFunction.functionName === "typecast" ? { fields: op.fieldConfigs } : {}
3532
+ }
3533
+ }
3534
+ };
3535
+ return acc$1;
3536
+ }, {}),
3537
+ result: op.result
3538
+ };
3539
+ return acc;
3540
+ }, {});
3541
+ return newOperations;
3542
+ };
3543
+ const parseOperationInputs = (operation, inputs) => {
3544
+ if (!operation.inputs) return {};
3545
+ const inputSchema = createSchemaByFieldLocation(operation.inputs);
3546
+ const parsedInputs = inputSchema.parse(inputs);
3547
+ return {
3548
+ ...parsedInputs.headers ?? {},
3549
+ ...parsedInputs.query ?? {},
3550
+ ...parsedInputs.path ?? {},
3551
+ ...parsedInputs.body ?? {}
3552
+ };
3553
+ };
3554
+ const createDynamicSchema = (fields) => {
3555
+ const schemaObj = {};
3556
+ fields.forEach((field) => {
3557
+ let fieldSchema;
3558
+ switch (field.type.toLowerCase()) {
3559
+ case "string":
3560
+ fieldSchema = string();
3561
+ break;
3562
+ case "number":
3563
+ fieldSchema = number();
3564
+ break;
3565
+ case "boolean":
3566
+ fieldSchema = boolean();
3567
+ break;
3568
+ default: fieldSchema = any();
3569
+ }
3570
+ schemaObj[field.name] = field.required ? fieldSchema : fieldSchema.optional();
3571
+ });
3572
+ return object(schemaObj);
3573
+ };
3574
+ const createSchemaByFieldLocation = (fields) => {
3575
+ const pathFields = fields.filter((field) => field.in === "path");
3576
+ const queryFields = fields.filter((field) => field.in === "query");
3577
+ const bodyFields = fields.filter((field) => field.in === "body");
3578
+ const headersFields = fields.filter((field) => field.in === "headers");
3579
+ return object({
3580
+ path: createDynamicSchema(pathFields).optional(),
3581
+ query: createDynamicSchema(queryFields).optional(),
3582
+ body: createDynamicSchema(bodyFields).optional(),
3583
+ headers: createDynamicSchema(headersFields).optional()
3584
+ });
3585
+ };
3586
+ const buildCursorConfig = (op) => {
3587
+ const isListOperation = op.operationType === "list";
3588
+ const cursorConfig = op.cursor ?? {
3589
+ enabled: isListOperation,
3590
+ pageSize: DEFAULT_PAGE_SIZE
3591
+ };
3592
+ return {
3593
+ enabled: cursorConfig.enabled && isListOperation,
3594
+ pageSize: cursorConfig.pageSize
3595
+ };
3596
+ };
3597
+ const parseCompositeIdentifiersConfig = (op) => {
3598
+ if ((0, __stackone_utils.isMissing)(op.compositeIdentifiers)) {
3599
+ const identifierFieldConfig = op.fieldConfigs?.find((fieldConfig) => fieldConfig.targetFieldKey === "id");
3600
+ const defaultIdentifierFields = (0, __stackone_utils.notMissing)(identifierFieldConfig) ? [{
3601
+ targetFieldKey: identifierFieldConfig.targetFieldKey,
3602
+ remote: "id",
3603
+ components: [{
3604
+ name: identifierFieldConfig.targetFieldKey,
3605
+ alias: identifierFieldConfig.alias
3606
+ }]
3607
+ }] : void 0;
3608
+ return {
3609
+ enabled: true,
3610
+ version: __stackone_core.COMPOSITE_ID_LATEST_VERSION,
3611
+ fields: defaultIdentifierFields
3612
+ };
3613
+ }
3614
+ const mappedFields = [];
3615
+ for (const field of op.compositeIdentifiers?.fields ?? []) {
3616
+ const fieldComponents = field.components.map((component) => {
3617
+ const componentDetail = op.fieldConfigs?.find((fieldConfig) => fieldConfig.targetFieldKey === component);
3618
+ return {
3619
+ name: component,
3620
+ alias: componentDetail?.alias
3621
+ };
3622
+ });
3623
+ mappedFields.push({
3624
+ targetFieldKey: field.targetFieldKey,
3625
+ remote: field.remote,
3626
+ components: fieldComponents
3627
+ });
3628
+ }
3629
+ return {
3630
+ enabled: op.compositeIdentifiers.enabled,
3631
+ version: op.compositeIdentifiers.version,
3632
+ fields: mappedFields.length > 0 ? mappedFields : void 0
3633
+ };
3634
+ };
3635
+ const parseScheduledJobConfig = (op) => {
3636
+ if ((0, __stackone_utils.isMissing)(op.scheduledJobs)) return void 0;
3637
+ return op.scheduledJobs;
3638
+ };
3639
+ const getDefaultRequestStepFunctionsParams = (stepFunctionName, baseRequestParams, functionParams = {}) => {
3640
+ if (stepFunctionName === "request" || stepFunctionName === "paginated_request") {
3641
+ const defaultCustomErrors = [{
3642
+ receivedStatus: 500,
3643
+ targetStatus: 502
3644
+ }];
3645
+ const functionCustomErrors = functionParams.customErrors && Array.isArray(functionParams.customErrors) ? functionParams.customErrors : [];
3646
+ const mergedCustomErrors = [...functionCustomErrors, ...defaultCustomErrors];
3647
+ return {
3648
+ ...baseRequestParams,
3649
+ customErrors: mergedCustomErrors
3650
+ };
3651
+ } else return {};
3652
+ };
3653
+
3654
+ //#endregion
3655
+ //#region src/errors/connectSDKErrors.ts
3656
+ var ConnectSDKError = class ConnectSDKError extends Error {
3657
+ errorType;
3658
+ context;
3659
+ constructor(errorType, context, message) {
3660
+ super(message);
3661
+ this.name = "ConnectSDKError";
3662
+ this.errorType = errorType;
3663
+ this.context = context;
3664
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ConnectSDKError);
3665
+ }
3666
+ toString() {
3667
+ return `${this.name} [${this.errorType}]: ${this.message}`;
3668
+ }
3669
+ };
3670
+ var ConnectorParseError = class extends ConnectSDKError {
3671
+ constructor(context, message) {
3672
+ super("CONNECTOR_PARSE_ERROR", context, message);
3673
+ this.name = "ConnectorParseError";
3674
+ }
3675
+ };
3676
+ var MissingOperationError = class extends ConnectSDKError {
3677
+ constructor(context, message) {
3678
+ super("MISSING_OPERATION_ERROR", context, message);
3679
+ this.name = "MissingOperationError";
3680
+ }
3681
+ };
3682
+ var InvalidOperationInputsError = class extends ConnectSDKError {
3683
+ constructor(context, message) {
3684
+ super("INVALID_OPERATION_INPUTS_ERROR", context, message);
3685
+ this.name = "InvalidOperationInputsError";
3686
+ }
3687
+ };
3688
+ var InvalidCursorError = class extends ConnectSDKError {
3689
+ constructor(context, message) {
3690
+ super("INVALID_CURSOR_ERROR", context, message);
3691
+ this.name = "InvalidCursorError";
3692
+ }
3693
+ };
3694
+
3695
+ //#endregion
3696
+ //#region src/runners/executeStepFunctions.ts
3697
+ const executeStepFunction = async ({ block, stepFunctionName, params, buildStepFunction = __stackone_core.StepFunctionsFactory.build }) => {
3698
+ const stepFunction = buildStepFunction({ functionName: stepFunctionName }).fn;
3699
+ const result = await stepFunction({
3700
+ block,
3701
+ params
3702
+ });
3703
+ const stepSnaphot = stepFunctionName === __stackone_core.StepFunctionName.MAP_FIELDS ? { [__stackone_core.StepFunctionName.MAP_FIELDS.toString()]: {
3704
+ output: { data: result.block.result },
3705
+ errors: result.errors,
3706
+ successful: result.successful
3707
+ } } : {};
3708
+ return {
3709
+ ...result.block,
3710
+ steps: {
3711
+ ...result?.block?.steps ?? {},
3712
+ ...stepSnaphot
3713
+ }
3714
+ };
3715
+ };
3716
+
3717
+ //#endregion
3718
+ //#region src/blocks/createBlockContext.ts
3719
+ const createBlockContext = ({ category, connectorKey, connectorVersion, authConfigKey, environment = "production", operation, accountSecureId, projectSecureId }) => {
3720
+ return {
3721
+ projectSecureId,
3722
+ accountSecureId,
3723
+ connectorKey,
3724
+ connectorVersion,
3725
+ category,
3726
+ service: "",
3727
+ resource: "",
3728
+ schema: operation?.schema?.key,
3729
+ operationType: operation?.operationType ?? "unknown",
3730
+ authenticationType: authConfigKey,
3731
+ environment
3732
+ };
3733
+ };
3734
+
3735
+ //#endregion
3736
+ //#region src/compositeIds/inputs.ts
3737
+ const decodeInputCompositeIdentifiers = (block) => {
3738
+ const compositeIdsConfig = block.operation?.compositeIdentifiers;
3739
+ const blockInputs = { ...block.inputs ?? {} };
3740
+ if (!compositeIdsConfig?.enabled || (0, __stackone_utils.isMissing)(blockInputs)) return block;
3741
+ const aliases = compositeIdsConfig.fields?.reduce((acc, field) => {
3742
+ field.components.forEach((component) => {
3743
+ if (component.alias) acc[component.name] = component.alias;
3744
+ });
3745
+ return acc;
3746
+ }, {});
3747
+ const identifierConfig = {
3748
+ version: compositeIdsConfig.version ?? __stackone_core.COMPOSITE_ID_LATEST_VERSION,
3749
+ aliases
3750
+ };
3751
+ processLevel(blockInputs, identifierConfig, block.logger);
3752
+ return {
3753
+ ...block,
3754
+ inputs: blockInputs
3755
+ };
3756
+ };
3757
+ const processLevel = (input, compositeIdentifierConfig, logger) => {
3758
+ for (const key in input) {
3759
+ const value = input[key];
3760
+ if (typeof value === "string" || Array.isArray(value) && value.every((item) => typeof item === "string")) processCompositeId(value, key, input, compositeIdentifierConfig, logger);
3761
+ else if (Array.isArray(value)) for (const item of value) processLevel(item, compositeIdentifierConfig, logger);
3762
+ else if (typeof value === "object" && value !== null) processLevel(value, compositeIdentifierConfig, logger);
3763
+ }
3764
+ };
3765
+ const processInputElements = (inputArray, key, compositeIdentifierConfig, logger) => {
3766
+ const compositeIdComponents = [];
3767
+ const nonCompositeIds = [];
3768
+ for (const inputElement of inputArray) try {
3769
+ const extractedComponents = (0, __stackone_core.decodeCompositeId)(inputElement, compositeIdentifierConfig);
3770
+ compositeIdComponents.push(extractedComponents);
3771
+ } catch (e) {
3772
+ logger?.debug({
3773
+ message: `Received ${key} with invalid composite ID, assuming it is not a composite ID`,
3774
+ category: "processCompositeId",
3775
+ context: {
3776
+ key,
3777
+ inputElement,
3778
+ compositeIdentifierConfig,
3779
+ error: e
3780
+ }
3781
+ });
3782
+ nonCompositeIds.push(inputElement);
3783
+ }
3784
+ return {
3785
+ compositeIdComponents,
3786
+ nonCompositeIds
3787
+ };
3788
+ };
3789
+ const setDecodedIds = (parentRecord, key, compositeIdComponents, isInputArray) => {
3790
+ const multipleIdsComponents = compositeIdComponents.filter((component) => Object.keys(component).length > 1);
3791
+ if (multipleIdsComponents.length > 0) parentRecord.decoded_ids = {
3792
+ ...parentRecord.decoded_ids ?? {},
3793
+ [key]: isInputArray ? multipleIdsComponents : multipleIdsComponents[0]
3794
+ };
3795
+ };
3796
+ const shouldSimplifyComponent = (component) => {
3797
+ const values = Object.values(component);
3798
+ return values.length === 1 && (typeof values[0] === "string" || typeof values[0] === "number");
3799
+ };
3800
+ const setSimplifiedIds = (parentRecord, key, compositeIdComponents, nonCompositeIds, isInputArray) => {
3801
+ if (!compositeIdComponents.every(shouldSimplifyComponent)) return;
3802
+ if (isInputArray) parentRecord[key] = [...compositeIdComponents.map((component) => Object.values(component)[0]), ...nonCompositeIds];
3803
+ else if (compositeIdComponents.length > 0) parentRecord[key] = Object.values(compositeIdComponents[0])[0];
3804
+ };
3805
+ const handleCompositeIdError = (error, key, logger) => {
3806
+ if (error instanceof __stackone_core.CoreError && error.type === "COMPOSITE_ID_MISSING_HEADER_ERROR") logger?.debug({ message: `Received ${key} with no composite ID header, assuming it is not a composite ID` });
3807
+ else logger?.warning({
3808
+ message: `Error processing composite ID for ${key}, ignoring it`,
3809
+ error
3810
+ });
3811
+ };
3812
+ const processCompositeId = (input, key, parentRecord, compositeIdentifierConfig, logger) => {
3813
+ try {
3814
+ const isInputArray = Array.isArray(input);
3815
+ const inputArray = isInputArray ? input : [input];
3816
+ if (inputArray.length === 0) return;
3817
+ const { compositeIdComponents, nonCompositeIds } = processInputElements(inputArray, key, compositeIdentifierConfig, logger);
3818
+ setDecodedIds(parentRecord, key, compositeIdComponents, isInputArray);
3819
+ setSimplifiedIds(parentRecord, key, compositeIdComponents, nonCompositeIds, isInputArray);
3820
+ } catch (e) {
3821
+ handleCompositeIdError(e, key, logger);
3822
+ }
3823
+ };
3824
+
3825
+ //#endregion
3826
+ //#region src/compositeIds/outputs.ts
3827
+ const REMOTE_FIELD_PREFIX = "remote_";
3828
+ const encodeResultCompositeIdentifiers = (block) => {
3829
+ const compositeIdsConfig = block.operation?.compositeIdentifiers;
3830
+ if (!compositeIdsConfig?.enabled) return block;
3831
+ const outputDataKey = "data";
3832
+ const dataOutput = block.outputs?.[outputDataKey];
3833
+ if ((0, __stackone_utils.isMissing)(dataOutput)) return block;
3834
+ const newData = Array.isArray(dataOutput) ? dataOutput.map((item) => mapCompositeIds(item, compositeIdsConfig)) : mapCompositeIds(dataOutput, compositeIdsConfig);
3835
+ return {
3836
+ ...block,
3837
+ outputs: {
3838
+ ...block.outputs ?? {},
3839
+ [outputDataKey]: newData
3840
+ }
3841
+ };
3842
+ };
3843
+ const mapCompositeIds = (data, config$1) => {
3844
+ const dataEncodedFromConfig = mapConfiguredCompositeIds(data, config$1);
3845
+ const encodedData = mapCompositeIdsFromInference(dataEncodedFromConfig);
3846
+ return {
3847
+ ...data,
3848
+ ...(0, __stackone_utils.isObject)(encodedData) ? encodedData : {}
3849
+ };
3850
+ };
3851
+ const mapConfiguredCompositeIds = (data, config$1) => {
3852
+ const version$1 = config$1.version ?? __stackone_core.COMPOSITE_ID_LATEST_VERSION;
3853
+ const newData = {};
3854
+ config$1.fields?.forEach((field) => {
3855
+ const aliasesMap = {};
3856
+ const components = [];
3857
+ field.components.forEach((component) => {
3858
+ if (component.alias) aliasesMap[component.name] = component.alias;
3859
+ components.push({
3860
+ key: component.name,
3861
+ value: data[component.name]
3862
+ });
3863
+ });
3864
+ const identifier = components.length === 1 ? components[0] : { identifiers: components };
3865
+ const idConfig = {
3866
+ version: version$1,
3867
+ aliases: Object.keys(aliasesMap).length > 0 ? aliasesMap : void 0
3868
+ };
3869
+ const compositeId = (0, __stackone_core.encodeCompositeId)(identifier, idConfig);
3870
+ newData[field.targetFieldKey] = compositeId;
3871
+ if (field.remote) newData[`${REMOTE_FIELD_PREFIX}${field.remote}`] = data[field.remote];
3872
+ });
3873
+ return {
3874
+ ...data,
3875
+ ...newData
3876
+ };
3877
+ };
3878
+ const isIdField = (key) => {
3879
+ return key === "id" || /.+_id(s)?$/.test(key);
3880
+ };
3881
+ const isValidStringArray = (value) => {
3882
+ return Array.isArray(value) && value.every((v) => (0, __stackone_utils.isString)(v) && v.length > 0);
3883
+ };
3884
+ const shouldSkipEncoding = (value, key) => {
3885
+ return (0, __stackone_core.isCompositeId)(value) || key.startsWith(REMOTE_FIELD_PREFIX);
3886
+ };
3887
+ const encodeStringValue = (key, value) => {
3888
+ try {
3889
+ return (0, __stackone_core.encodeCompositeId)({
3890
+ key,
3891
+ value
3892
+ }, { version: __stackone_core.COMPOSITE_ID_LATEST_VERSION });
3893
+ } catch {
3894
+ return value;
3895
+ }
3896
+ };
3897
+ const processStringArrayField = (key, value, result) => {
3898
+ const encodedArray = value.map((v) => {
3899
+ if ((0, __stackone_utils.isString)(v) && v.length > 0 && !(0, __stackone_core.isCompositeId)(v)) return encodeStringValue(key, v);
3900
+ return v;
3901
+ });
3902
+ result[key] = encodedArray;
3903
+ result[`${REMOTE_FIELD_PREFIX}${key}`] = value;
3904
+ };
3905
+ const processStringField = (key, value, result) => {
3906
+ if (shouldSkipEncoding(value, key)) return;
3907
+ const compositeId = (0, __stackone_core.encodeCompositeId)({
3908
+ key,
3909
+ value
3910
+ }, { version: __stackone_core.COMPOSITE_ID_LATEST_VERSION });
3911
+ result[key] = compositeId;
3912
+ result[`remote_${key}`] = value;
3913
+ };
3914
+ const processIdField = (key, value, result) => {
3915
+ if (isValidStringArray(value)) processStringArrayField(key, value, result);
3916
+ else if ((0, __stackone_utils.isString)(value) && value.length > 0) processStringField(key, value, result);
3917
+ };
3918
+ const mapCompositeIdsFromInference = (data) => {
3919
+ if (Array.isArray(data)) return data.map((item) => mapCompositeIdsFromInference(item));
3920
+ if (!(0, __stackone_utils.isObject)(data)) return data;
3921
+ const result = { ...data };
3922
+ for (const [key, value] of Object.entries(data)) {
3923
+ if ((0, __stackone_utils.isObject)(value) || Array.isArray(value) && value.length > 0 && (0, __stackone_utils.isObject)(value[0])) result[key] = mapCompositeIdsFromInference(value);
3924
+ if (isIdField(key)) processIdField(key, value, result);
3925
+ }
3926
+ return result;
3927
+ };
3928
+
3929
+ //#endregion
3930
+ //#region src/pagination/utils.ts
3931
+ const getPageSize = (block, defaultValue) => {
3932
+ const inputPageSize = Number(block.inputs?.page_size);
3933
+ const pageSize = (0, __stackone_utils.notMissing)(block.inputs?.page_size) && (0, __stackone_utils.isNumber)(inputPageSize) && !Number.isNaN(inputPageSize) ? inputPageSize : block.operation?.cursor?.pageSize ?? defaultValue;
3934
+ return pageSize;
3935
+ };
3936
+
3937
+ //#endregion
3938
+ //#region src/pagination/virtualPagination.ts
3939
+ const virtualPaginateResult = (result, pageSize, steps, cursor) => {
3940
+ const data = (0, __stackone_utils.isMissing)(result) ? void 0 : result.data;
3941
+ const resultStepIndex = Object.keys(steps).length + 1;
3942
+ const emptyCursor = (0, __stackone_core.isCursorEmpty)({
3943
+ cursor,
3944
+ ignoreStepIndex: resultStepIndex
3945
+ });
3946
+ if (!(0, __stackone_utils.isObject)(result) || (0, __stackone_utils.isMissing)(data) || (data?.length ?? 0) <= pageSize) return {
3947
+ result,
3948
+ next: (0, __stackone_utils.notMissing)(cursor) && !emptyCursor ? (0, __stackone_core.minifyCursor)(cursor) : null
3949
+ };
3950
+ const pageNumber = cursor?.remote?.[resultStepIndex]?.pageNumber ?? 1;
3951
+ const startIndex = (pageNumber - 1) * pageSize;
3952
+ const endIndex = startIndex + pageSize;
3953
+ const slicedData = data.slice(startIndex, endIndex);
3954
+ const hasMorePages = data.length > endIndex || !emptyCursor;
3955
+ const pageCursor = (0, __stackone_core.updateCursor)({
3956
+ cursor,
3957
+ stepIndex: resultStepIndex,
3958
+ pageNumber: pageNumber + 1
3959
+ });
3960
+ return {
3961
+ result: {
3962
+ ...result,
3963
+ data: slicedData
3964
+ },
3965
+ next: hasMorePages ? (0, __stackone_core.minifyCursor)(pageCursor) : null
3966
+ };
3967
+ };
3968
+
3969
+ //#endregion
3970
+ //#region src/runners/runStepOperation.ts
3971
+ const runStepOperation = async ({ block, buildStepFunction = __stackone_core.StepFunctionsFactory.build, virtualPaginateResultFn = virtualPaginateResult, encodeResultCompositeIds = encodeResultCompositeIdentifiers, decodeInputCompositeIds = decodeInputCompositeIdentifiers }) => {
3972
+ const decodeBlock = decodeInputCompositeIds(block);
3973
+ const resultBlock = await executeStepsWorkflow({
3974
+ block: decodeBlock,
3975
+ buildStepFunction,
3976
+ virtualPaginateResultFn
3977
+ });
3978
+ return encodeResultCompositeIds(resultBlock);
3979
+ };
3980
+ const shouldSkipStepDueToCondition = (step, block) => {
3981
+ return step.condition ? !(0, __stackone_expressions.safeEvaluate)(step.condition, block) : false;
3982
+ };
3983
+ const buildStepParams = (step, blockAcc, stepIndex) => {
3984
+ const fn = step.stepFunction;
3985
+ return blockAcc.operation?.cursor.enabled ? {
3986
+ ...fn.params ?? {},
3987
+ cursor: {
3988
+ token: blockAcc.nextCursor?.remote?.[stepIndex]?.providerPageCursor,
3989
+ position: blockAcc.nextCursor?.remote?.[stepIndex]?.position
3990
+ }
3991
+ } : fn.params ?? {};
3992
+ };
3993
+ const handleStepFailure = (blockAcc, stepId, functionOutput, step, state) => {
3994
+ const updatedBlock = addStepResultToBlock({
3995
+ block: blockAcc,
3996
+ stepId,
3997
+ successful: false,
3998
+ functionOutput
3999
+ });
4000
+ const ignoreError = step.ignoreError ?? false;
4001
+ if (!ignoreError) {
4002
+ state.hasFatalError = true;
4003
+ state.errorStatusCode ??= functionOutput.output?.statusCode ?? 500;
4004
+ }
4005
+ return updatedBlock;
4006
+ };
4007
+ const executeStep = async (stepId, stepIndex, stepsToExecute, blockAcc, state, context) => {
4008
+ const step = stepsToExecute[stepId];
4009
+ const fn = step.stepFunction;
4010
+ const stepFunction = context.buildStepFunction({
4011
+ functionName: fn.functionName,
4012
+ version: fn.version,
4013
+ validateSchemas: true
4014
+ }).fn;
4015
+ if (shouldSkipStepDueToCondition(step, blockAcc)) return addStepResultToBlock({
4016
+ block: blockAcc,
4017
+ stepId,
4018
+ successful: true,
4019
+ skipped: true,
4020
+ message: "Step skipped due to condition not met."
4021
+ });
4022
+ if (state.hasFatalError) return addStepResultToBlock({
4023
+ block: blockAcc,
4024
+ stepId,
4025
+ successful: false,
4026
+ skipped: true,
4027
+ message: "Step skipped due to previous error."
4028
+ });
4029
+ const fnParams = buildStepParams(step, blockAcc, stepIndex);
4030
+ const functionOutput = await stepFunction({
4031
+ block: blockAcc,
4032
+ params: fnParams
4033
+ });
4034
+ if (functionOutput.successful === false) return handleStepFailure(blockAcc, stepId, functionOutput, step, state);
4035
+ const updatedCursor = blockAcc.operation?.cursor.enabled ? (0, __stackone_core.updateCursor)({
4036
+ cursor: blockAcc.nextCursor,
4037
+ stepIndex,
4038
+ providerPageCursor: functionOutput.output?.next,
4039
+ position: functionOutput.output?.position
4040
+ }) : void 0;
4041
+ return addStepResultToBlock({
4042
+ block: {
4043
+ ...functionOutput.block,
4044
+ nextCursor: updatedCursor
4045
+ },
4046
+ stepId,
4047
+ functionOutput
4048
+ });
4049
+ };
4050
+ const buildFinalResponse = (block, blockAcc, state, result, finalData) => {
4051
+ const isSuccessful = !state.hasFatalError;
4052
+ const finalStatusCode = isSuccessful ? block.operation?.responses.success.statusCode ?? 200 : state.errorStatusCode ?? 500;
4053
+ const outputs = (0, __stackone_utils.notMissing)(finalData) && (0, __stackone_utils.isObject)(finalData.result) ? {
4054
+ next: finalData.next,
4055
+ ...finalData.result
4056
+ } : result;
4057
+ return {
4058
+ ...blockAcc,
4059
+ outputs,
4060
+ response: {
4061
+ successful: isSuccessful,
4062
+ statusCode: finalStatusCode,
4063
+ message: !isSuccessful ? block.operation?.responses?.errors?.[finalStatusCode]?.description ?? __stackone_transport.HttpErrorMessages?.[finalStatusCode] ?? "Error while processing the request" : void 0
4064
+ }
4065
+ };
4066
+ };
4067
+ const executeStepsWorkflow = async ({ block, buildStepFunction = __stackone_core.StepFunctionsFactory.build, virtualPaginateResultFn = virtualPaginateResult }) => {
4068
+ const stepsToExecute = block.operation?.steps || {};
4069
+ let blockAcc = { ...block };
4070
+ const stepsIds = Object.keys(stepsToExecute);
4071
+ const pageSize = getPageSize(block, DEFAULT_PAGE_SIZE);
4072
+ const state = {
4073
+ hasFatalError: false,
4074
+ errorStatusCode: null
4075
+ };
4076
+ const context = {
4077
+ block,
4078
+ buildStepFunction,
4079
+ virtualPaginateResultFn
4080
+ };
4081
+ for (const [stepIndex, stepId] of stepsIds.entries()) blockAcc = await executeStep(stepId, stepIndex, stepsToExecute, blockAcc, state, context);
4082
+ const result = block.operation?.result ? evaluateResult(block.operation.result, blockAcc) : void 0;
4083
+ const finalData = block.operation?.cursor.enabled ? virtualPaginateResultFn(result, pageSize, stepsToExecute, blockAcc.nextCursor) : void 0;
4084
+ return buildFinalResponse(block, blockAcc, state, result, finalData);
4085
+ };
4086
+ const evaluateResult = (result, block) => {
4087
+ if ((0, __stackone_utils.isObject)(result)) return (0, __stackone_expressions.safeEvaluateRecord)(result, block);
4088
+ return (0, __stackone_expressions.safeEvaluate)(result, block);
4089
+ };
4090
+ const addStepResultToBlock = ({ block, stepId, successful, functionOutput, skipped, message }) => {
4091
+ return {
4092
+ ...block,
4093
+ steps: {
4094
+ ...block.steps,
4095
+ [stepId]: {
4096
+ successful: successful ?? functionOutput?.successful ?? false,
4097
+ errors: functionOutput?.errors,
4098
+ output: functionOutput?.output,
4099
+ skipped,
4100
+ message
4101
+ }
4102
+ }
4103
+ };
4104
+ };
4105
+
4106
+ //#endregion
4107
+ //#region src/runners/runConnectorOperation.ts
4108
+ const runConnectorOperation = async ({ account, connector, category, path, method = "get", queryParams, body, headers, logger, parseConnector = parseYamlConnector, getOperationFromUrlFn = getOperationFromUrl, parseOperationInputsFn = parseOperationInputs, createBlockContextFn = createBlockContext, createBlockFn = createBlock, runStepOperationFn = runStepOperation }) => {
4109
+ const authConfigKey = account.authConfigKey;
4110
+ const environment = account.environment ?? "production";
4111
+ const accountSecureId = account.secureId;
4112
+ const projectSecureId = account.projectSecureId;
4113
+ const credentials = account.credentials;
4114
+ const blockContext = createBlockContextFn({
4115
+ category,
4116
+ connectorKey: account.providerKey,
4117
+ connectorVersion: account.providerVersion,
4118
+ authConfigKey,
4119
+ environment,
4120
+ accountSecureId,
4121
+ projectSecureId
4122
+ });
4123
+ let parsedConnector;
4124
+ try {
4125
+ parsedConnector = (0, __stackone_utils.isString)(connector) ? parseConnector(connector) : connector;
4126
+ } catch {
4127
+ throw new ConnectorParseError(blockContext, "Error while parsing connector");
4128
+ }
4129
+ const matchingOperation = getOperationFromUrlFn(parsedConnector, path, method);
4130
+ if ((0, __stackone_utils.isMissing)(matchingOperation)) throw new MissingOperationError(blockContext, "No matching operation found");
4131
+ blockContext.operationType = matchingOperation.operation.operationType;
4132
+ blockContext.schema = matchingOperation.operation.schema?.key;
4133
+ const expandedCursor = processCursor(queryParams, blockContext);
4134
+ let operationInputs;
4135
+ try {
4136
+ operationInputs = parseOperationInputsFn(matchingOperation.operation, {
4137
+ query: queryParams,
4138
+ body,
4139
+ headers,
4140
+ path: matchingOperation.params
4141
+ });
4142
+ } catch {
4143
+ throw new InvalidOperationInputsError(blockContext, "Error while parsing operation inputs");
4144
+ }
4145
+ const block = await createBlockFn({
4146
+ inputs: operationInputs,
4147
+ context: blockContext,
4148
+ operation: matchingOperation.operation,
4149
+ credentials,
4150
+ nextCursor: expandedCursor,
4151
+ logger
4152
+ });
4153
+ return await runStepOperationFn({ block });
4154
+ };
4155
+ const processCursor = (queryParams, blockContext) => {
4156
+ const nextCursor = queryParams?.["next"];
4157
+ const expandedCursor = (0, __stackone_utils.notMissing)(nextCursor) && blockContext.operationType === "list" ? (0, __stackone_core.expandCursor)(nextCursor) : void 0;
4158
+ if (expandedCursor === null) throw new InvalidCursorError(blockContext, `Invalid cursor.`);
4159
+ return expandedCursor;
4160
+ };
4161
+
4162
+ //#endregion
4163
+ exports.ConnectSDKError = ConnectSDKError;
4164
+ exports.createBlock = createBlock;
4165
+ exports.executeStepFunction = executeStepFunction;
4166
+ exports.getOperationFromUrl = getOperationFromUrl;
4167
+ exports.parseOperationInputs = parseOperationInputs;
4168
+ exports.parseYamlConnector = parseYamlConnector;
4169
+ exports.runConnectorOperation = runConnectorOperation;
4170
+ exports.runStepOperation = runStepOperation;