@stackone/connect-sdk 1.32.0 → 1.33.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.es.mjs CHANGED
@@ -1 +1 @@
1
- import{HttpClientManager as e,isSuccessStatusCode as t,HttpErrorMessages as o}from"@stackone/transport";import{match as r}from"path-to-regexp";import{AUTHENTICATION_SCHEMA as n,COMPOSITE_ID_LATEST_VERSION as s,StepFunctionsFactory as i,StepFunctionName as a,decodeCompositeId as c,CoreError as u,encodeCompositeId as p,isCompositeId as d,isCursorEmpty as l,minifyCursor as y,updateCursor as m,expandCursor as g}from"@stackone/core";import{notMissing as f,isMissing as b,isObject as h,isString as _,isNumber as v}from"@stackone/utils";import{parse as I}from"yaml";import{z as C}from"zod";import{safeEvaluateRecord as k,safeEvaluate as E}from"@stackone/expressions";const F=async({inputs:t,context:o,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>e.getInstance()})=>({inputs:t,fieldConfigs:[],context:o,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),S=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=j(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},w=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},j=(e,t,o)=>{const n=w(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=r(w(o))(w(n));if(!1!==s)return{path:e,params:s.params}}},O=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}`)}},x={key:C.string(),label:C.string(),required:C.boolean().optional().default(!1),secret:C.boolean().optional().default(!1),readOnly:C.boolean().optional().default(!1),placeholder:C.string().optional(),description:C.string().optional(),tooltip:C.string().optional()},R=C.discriminatedUnion("type",[C.object({...x,type:C.enum(["text","password"])}),C.object({...x,type:C.literal("select"),options:C.object({value:C.string(),label:C.string()}).array()})]),T=C.object({operationId:C.string(),categories:C.string().array(),operationType:C.enum(["list","get","create","update","delete","custom","unknown"]),schema:C.string().optional(),entrypointUrl:C.string().optional(),entrypointHttpMethod:C.string().optional(),description:C.string(),responses:C.object({statusCode:C.number(),description:C.string()}).array().optional(),inputs:C.object({name:C.string(),type:C.string(),required:C.boolean(),description:C.string(),in:C.string()}).array().optional(),cursor:C.object({enabled:C.boolean(),pageSize:C.number()}).optional(),compositeIdentifiers:C.object({enabled:C.boolean(),version:C.number().optional(),fields:C.object({targetFieldKey:C.string(),remote:C.string().optional(),components:C.string().array()}).array().optional()}).optional(),fieldConfigs:C.object({targetFieldKey:C.string(),alias:C.string().optional(),expression:C.string(),type:C.enum(["string","number","boolean","datetime_string","enum"]),custom:C.boolean().default(!1),hidden:C.boolean().default(!1),enumMapper:C.object({matcher:C.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(C.object({matchExpression:C.string(),value:C.string()}).array())}).optional()}).array().optional(),steps:C.object({stepId:C.string(),description:C.string(),stepFunction:C.object({functionName:C.string(),version:C.string().optional(),parameters:C.record(C.string(),C.unknown())}),condition:C.string().optional(),ignoreError:C.boolean().optional()}).array(),result:C.string().or(C.record(C.string(),C.unknown())).optional()}),N=C.object({StackOne:C.string(),info:C.object({title:C.string(),version:C.string(),key:C.string(),description:C.string().optional()}),baseUrl:C.string(),authentication:C.record(C.string(),C.object({type:C.string(),label:C.string(),authorization:n,environments:C.object({key:C.string(),name:C.string()}).array(),support:C.object({link:C.string(),description:C.string().optional()}),configFields:R.array().optional(),setupFields:R.array().optional(),testOperationsIds:C.string().array().optional()})).array().optional(),operations:T.array().optional()});function A(e){try{const t=I(e),o=N.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=U(o),s={baseUrl:o.baseUrl,authentication:$(n)},i=q(o,s);return r.operations=i,r.authentication=n,f(i)&&(r.categories=K(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const $=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]=$(a)}else t[o]=r;return t},K=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},U=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},q=(e,o)=>{const r=e.operations?.reduce(((e,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=(e=>{const o={success:O(e.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=e.responses?.reduce(((e,o)=>(t(o.statusCode)?e.success={statusCode:o.statusCode,description:o.description}:e.errors[o.statusCode]={statusCode:o.statusCode,description:o.description},e)),o);return r??o})(r),c=D(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"}),e[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:H(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,...L(t.stepFunction.functionName,o,t.stepFunction.parameters),..."map_fields"===t.stepFunction.functionName||"typecast"===t.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},e}),{});return r},P=(e,t)=>{if(!e.inputs)return{};const o=z(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},M=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=C.string();break;case"number":o=C.number();break;case"boolean":o=C.boolean();break;default:o=C.any()}t[e.name]=e.required?o:o.optional()})),C.object(t)},z=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 C.object({path:M(t).optional(),query:M(o).optional(),body:M(r).optional(),headers:M(n).optional()})},D=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},H=e=>{if(b(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),o=f(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:s,fields:o}}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}},L=(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 V extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,V)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class G extends V{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class W extends V{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class B extends V{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class Y extends V{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const J=async({block:e,stepFunctionName:t,params:o,buildStepFunction:r=i.build})=>{const n=r({functionName:t}).fn,s=await n({block:e,params:o}),c=t===a.MAP_FIELDS?{[a.MAP_FIELDS.toString()]:{output:{data:s.block.result},errors:s.errors,successful:s.successful}}:{};return{...s.block,steps:{...s?.block?.steps??{},...c}}},Q=({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}),X=e=>{const t=e.operation?.compositeIdentifiers,o={...e.inputs??{}};if(!t?.enabled||b(o))return e;const r=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),n={version:t.version??s,aliases:r};return Z(o,n,e.logger),{...e,inputs:o}},Z=(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)))te(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)Z(e,t,o);else"object"==typeof n&&null!==n&&Z(n,t,o)}},ee=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},te=(e,t,o,r,n)=>{try{const s=Array.isArray(e),i=s?e:[e];if(0===i.length)return;const{compositeIdComponents:a,nonCompositeIds:u}=((e,t,o,r)=>{const n=[],s=[];for(const i of e)try{const e=c(i,o);n.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:t,inputElement:i,compositeIdentifierConfig:o,error:e}}),s.push(i)}return{compositeIdComponents:n,nonCompositeIds:s}})(i,t,r,n);((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]})})(o,t,a,s),((e,t,o,r,n)=>{o.every(ee)&&(n?e[t]=[...o.map((e=>Object.values(e)[0])),...r]:o.length>0&&(e[t]=Object.values(o[0])[0]))})(o,t,a,u,s)}catch(e){((e,t,o)=>{e instanceof u&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?o?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):o?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})})(e,t,n)}},oe="remote_",re=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",r=e.outputs?.[o];if(b(r))return e;const n=Array.isArray(r)?r.map((e=>ne(e,t))):ne(r,t);return{...e,outputs:{...e.outputs??{},[o]:n}}},ne=(e,t)=>{const o=se(e,t),r=pe(o);return{...e,...h(r)?r:{}}},se=(e,t)=>{const o=t.version??s,r={};return t.fields?.forEach((t=>{const n={},s=[];t.components.forEach((t=>{t.alias&&(n[t.name]=t.alias),s.push({key:t.name,value:e[t.name]})}));const i=1===s.length?s[0]:{identifiers:s},a={version:o,aliases:Object.keys(n).length>0?n:void 0},c=p(i,a);r[t.targetFieldKey]=c,t.remote&&(r[`${oe}${t.remote}`]=e[t.remote])})),{...e,...r}},ie=e=>"id"===e||/.+_id(s)?$/.test(e),ae=(e,t,o)=>{const r=t.map((t=>_(t)&&t.length>0&&!d(t)?((e,t)=>{try{return p({key:e,value:t},{version:s})}catch{return t}})(e,t):t));o[e]=r,o[`${oe}${e}`]=t},ce=(e,t,o)=>{if(((e,t)=>d(e)||t.startsWith(oe))(t,e))return;const r=p({key:e,value:t},{version:s});o[e]=r,o[`remote_${e}`]=t},ue=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>_(e)&&e.length>0)))(t)?ae(e,t,o):_(t)&&t.length>0&&ce(e,t,o)},pe=e=>{if(Array.isArray(e))return e.map((e=>pe(e)));if(!h(e))return e;const t={...e};for(const[o,r]of Object.entries(e))(h(r)||Array.isArray(r)&&r.length>0&&h(r[0]))&&(t[o]=pe(r)),ie(o)&&ue(o,r,t);return t},de=(e,t,o,r)=>{const n=b(e)?void 0:e.data,s=Object.keys(o).length+1,i=l({cursor:r,ignoreStepIndex:s});if(!h(e)||b(n)||(n?.length??0)<=t)return{result:e,next:f(r)&&!i?y(r):null};const a=r?.remote?.[s]?.pageNumber??1,c=(a-1)*t,u=c+t,p=n.slice(c,u),d=n.length>u||!i,g=m({cursor:r,stepIndex:s,pageNumber:a+1});return{result:{...e,data:p},next:d?y(g):null}},le=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:o=de,encodeResultCompositeIds:r=re,decodeInputCompositeIds:n=X})=>{const s=n(e);return r(await me({block:s,buildStepFunction:t,virtualPaginateResultFn:o}))},ye=async(e,t,o,r,n,s)=>{const i=o[e],a=i.stepFunction,c=s.buildStepFunction({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(((e,t)=>!!e.condition&&!E(e.condition,t))(i,r))return fe({block:r,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(n.hasFatalError)return fe({block:r,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});const u=((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??{}})(i,r,t),p=await c({block:r,params:u});if(!1===p.successful)return((e,t,o,r,n)=>{const s=fe({block:e,stepId:t,successful:!1,functionOutput:o});return(r.ignoreError??!1)||(n.hasFatalError=!0,n.errorStatusCode??=o.output?.statusCode??500),s})(r,e,p,i,n);const d=r.operation?.cursor.enabled?m({cursor:r.nextCursor,stepIndex:t,providerPageCursor:p.output?.next,position:p.output?.position}):void 0;return fe({block:{...p.block,nextCursor:d},stepId:e,functionOutput:p})},me=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:r=de})=>{const n=e.operation?.steps||{};let s={...e};const a=Object.keys(n),c=((e,t)=>{const o=Number(e.inputs?.page_size);return f(e.inputs?.page_size)&&v(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(e,25),u={hasFatalError:!1,errorStatusCode:null},p={block:e,buildStepFunction:t,virtualPaginateResultFn:r};for(const[e,t]of a.entries())s=await ye(t,e,n,s,u,p);const d=e.operation?.result?ge(e.operation.result,s):void 0;return((e,t,r,n,s)=>{const i=!r.hasFatalError,a=i?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500;return{...t,outputs:f(s)&&h(s.result)?{next:s.next,...s.result}:n,response:{successful:i,statusCode:a,message:i?void 0:e.operation?.responses?.errors?.[a]?.description??o?.[a]??"Error while processing the request"}}})(e,s,u,d,e.operation?.cursor.enabled?r(d,c,n,s.nextCursor):void 0)},ge=(e,t)=>h(e)?k(e,t):E(e,t),fe=({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}}}),be=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:u=A,getOperationFromUrlFn:p=S,parseOperationInputsFn:d=P,createBlockContextFn:l=Q,createBlockFn:y=F,runStepOperationFn:m=le})=>{const g=e.authConfigKey,f=e.environment??"production",h=e.secureId,v=e.projectSecureId,I=e.credentials,C=l({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:g,environment:f,accountSecureId:h,projectSecureId:v});let k;try{k=_(t)?u(t):t}catch{throw new G(C,"Error while parsing connector")}const E=p(k,r,n);if(b(E))throw new W(C,"No matching operation found");C.operationType=E.operation.operationType,C.schema=E.operation.schema?.key;const w=he(s,C);let j;try{j=d(E.operation,{query:s,body:i,headers:a,path:E.params})}catch{throw new B(C,"Error while parsing operation inputs")}const O=await y({inputs:j,context:C,operation:E.operation,credentials:I,nextCursor:w,logger:c});return await m({block:O})},he=(e,t)=>{const o=e?.next,r=f(o)&&"list"===t.operationType?g(o):void 0;if(null===r)throw new Y(t,"Invalid cursor.");return r};export{V as ConnectSDKError,F as createBlock,J as executeStepFunction,S as getOperationFromUrl,P as parseOperationInputs,A as parseYamlConnector,be as runConnectorOperation,le as runStepOperation};
1
+ import{HttpClientManager as e,isSuccessStatusCode as t,HttpErrorMessages as o}from"@stackone/transport";import{match as r}from"path-to-regexp";import{AUTHENTICATION_SCHEMA as n,COMPOSITE_ID_LATEST_VERSION as s,StepFunctionsFactory as i,StepFunctionName as a,decodeCompositeId as c,CoreError as p,encodeCompositeId as u,isCompositeId as d,isCursorEmpty as l,minifyCursor as y,updateCursor as m,expandCursor as g}from"@stackone/core";import{notMissing as f,isMissing as b,isObject as h,isString as _,isNumber as v}from"@stackone/utils";import{parse as I}from"yaml";import{z as C}from"zod";import{safeEvaluateRecord as k,safeEvaluate as F}from"@stackone/expressions";const E=async({inputs:t,context:o,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>e.getInstance()})=>({inputs:t,fieldConfigs:[],context:o,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),S=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=j(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},w=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},j=(e,t,o)=>{const n=w(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=r(w(o))(w(n));if(!1!==s)return{path:e,params:s.params}}},O=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}`)}},x={key:C.string(),label:C.string(),required:C.boolean().optional().default(!1),secret:C.boolean().optional().default(!1),readOnly:C.boolean().optional().default(!1),placeholder:C.string().optional(),description:C.string().optional(),tooltip:C.string().optional()},R=C.discriminatedUnion("type",[C.object({...x,type:C.enum(["text","password"])}),C.object({...x,type:C.literal("select"),options:C.object({value:C.string(),label:C.string()}).array()})]),T=C.object({operationId:C.string(),categories:C.string().array(),operationType:C.enum(["list","get","create","update","delete","custom","unknown"]),schema:C.string().optional(),entrypointUrl:C.string().optional(),entrypointHttpMethod:C.string().optional(),description:C.string(),responses:C.object({statusCode:C.number(),description:C.string()}).array().optional(),inputs:C.object({name:C.string(),type:C.string(),required:C.boolean(),description:C.string(),in:C.string()}).array().optional(),cursor:C.object({enabled:C.boolean(),pageSize:C.number()}).optional(),compositeIdentifiers:C.object({enabled:C.boolean(),version:C.number().optional(),fields:C.object({targetFieldKey:C.string(),remote:C.string().optional(),components:C.string().array()}).array().optional()}).optional(),scheduledJobs:C.object({enabled:C.boolean(),type:C.enum(["data_sync"]),schedule:C.string(),description:C.string(),requestParams:C.object({fields:C.string().array().optional(),expand:C.string().array().optional(),filter:C.record(C.string(),C.string()).optional()}).optional(),syncFilter:C.object({name:C.enum(["updated_after","created_after"]),initialLoopbackPeriod:C.string(),incrementalLoopbackPeriod:C.string()}).optional()}).array().optional(),fieldConfigs:C.object({targetFieldKey:C.string(),alias:C.string().optional(),expression:C.string(),type:C.enum(["string","number","boolean","datetime_string","enum"]),custom:C.boolean().default(!1),hidden:C.boolean().default(!1),enumMapper:C.object({matcher:C.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(C.object({matchExpression:C.string(),value:C.string()}).array())}).optional()}).array().optional(),steps:C.object({stepId:C.string(),description:C.string(),stepFunction:C.object({functionName:C.string(),version:C.string().optional(),parameters:C.record(C.string(),C.unknown())}),condition:C.string().optional(),ignoreError:C.boolean().optional()}).array(),result:C.string().or(C.record(C.string(),C.unknown())).optional()}),N=C.object({StackOne:C.string(),info:C.object({title:C.string(),version:C.string(),key:C.string(),description:C.string().optional()}),baseUrl:C.string(),authentication:C.record(C.string(),C.object({type:C.string(),label:C.string(),authorization:n,environments:C.object({key:C.string(),name:C.string()}).array(),support:C.object({link:C.string(),description:C.string().optional()}),configFields:R.array().optional(),setupFields:R.array().optional(),testOperationsIds:C.string().array().optional()})).array().optional(),operations:T.array().optional()});function A(e){try{const t=I(e),o=N.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=P(o),s={baseUrl:o.baseUrl,authentication:$(n)},i=q(o,s);return r.operations=i,r.authentication=n,f(i)&&(r.categories=K(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const $=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]=$(a)}else t[o]=r;return t},K=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},P=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},q=(e,o)=>{const r=e.operations?.reduce(((e,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=(e=>{const o={success:O(e.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=e.responses?.reduce(((e,o)=>(t(o.statusCode)?e.success={statusCode:o.statusCode,description:o.description}:e.errors[o.statusCode]={statusCode:o.statusCode,description:o.description},e)),o);return r??o})(r),c=D(r),p=r.inputs||[];return c.enabled&&p?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),e[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:L(r),scheduledJobs:H(r),inputs:p,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,...V(t.stepFunction.functionName,o,t.stepFunction.parameters),..."map_fields"===t.stepFunction.functionName||"typecast"===t.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},e}),{});return r},U=(e,t)=>{if(!e.inputs)return{};const o=z(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},M=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=C.string();break;case"number":o=C.number();break;case"boolean":o=C.boolean();break;default:o=C.any()}t[e.name]=e.required?o:o.optional()})),C.object(t)},z=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 C.object({path:M(t).optional(),query:M(o).optional(),body:M(r).optional(),headers:M(n).optional()})},D=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},L=e=>{if(b(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),o=f(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:s,fields:o}}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}},H=e=>{if(!b(e.scheduledJobs))return e.scheduledJobs},V=(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 G extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,G)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class J extends G{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class W extends G{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class B extends G{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class Y extends G{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const Q=async({block:e,stepFunctionName:t,params:o,buildStepFunction:r=i.build})=>{const n=r({functionName:t}).fn,s=await n({block:e,params:o}),c=t===a.MAP_FIELDS?{[a.MAP_FIELDS.toString()]:{output:{data:s.block.result},errors:s.errors,successful:s.successful}}:{};return{...s.block,steps:{...s?.block?.steps??{},...c}}},X=({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}),Z=e=>{const t=e.operation?.compositeIdentifiers,o={...e.inputs??{}};if(!t?.enabled||b(o))return e;const r=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),n={version:t.version??s,aliases:r};return ee(o,n,e.logger),{...e,inputs:o}},ee=(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)))oe(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)ee(e,t,o);else"object"==typeof n&&null!==n&&ee(n,t,o)}},te=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},oe=(e,t,o,r,n)=>{try{const s=Array.isArray(e),i=s?e:[e];if(0===i.length)return;const{compositeIdComponents:a,nonCompositeIds:p}=((e,t,o,r)=>{const n=[],s=[];for(const i of e)try{const e=c(i,o);n.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:t,inputElement:i,compositeIdentifierConfig:o,error:e}}),s.push(i)}return{compositeIdComponents:n,nonCompositeIds:s}})(i,t,r,n);((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]})})(o,t,a,s),((e,t,o,r,n)=>{o.every(te)&&(n?e[t]=[...o.map((e=>Object.values(e)[0])),...r]:o.length>0&&(e[t]=Object.values(o[0])[0]))})(o,t,a,p,s)}catch(e){((e,t,o)=>{e instanceof p&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?o?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):o?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})})(e,t,n)}},re="remote_",ne=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",r=e.outputs?.[o];if(b(r))return e;const n=Array.isArray(r)?r.map((e=>se(e,t))):se(r,t);return{...e,outputs:{...e.outputs??{},[o]:n}}},se=(e,t)=>{const o=ie(e,t),r=de(o);return{...e,...h(r)?r:{}}},ie=(e,t)=>{const o=t.version??s,r={};return t.fields?.forEach((t=>{const n={},s=[];t.components.forEach((t=>{t.alias&&(n[t.name]=t.alias),s.push({key:t.name,value:e[t.name]})}));const i=1===s.length?s[0]:{identifiers:s},a={version:o,aliases:Object.keys(n).length>0?n:void 0},c=u(i,a);r[t.targetFieldKey]=c,t.remote&&(r[`${re}${t.remote}`]=e[t.remote])})),{...e,...r}},ae=e=>"id"===e||/.+_id(s)?$/.test(e),ce=(e,t,o)=>{const r=t.map((t=>_(t)&&t.length>0&&!d(t)?((e,t)=>{try{return u({key:e,value:t},{version:s})}catch{return t}})(e,t):t));o[e]=r,o[`${re}${e}`]=t},pe=(e,t,o)=>{if(((e,t)=>d(e)||t.startsWith(re))(t,e))return;const r=u({key:e,value:t},{version:s});o[e]=r,o[`remote_${e}`]=t},ue=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>_(e)&&e.length>0)))(t)?ce(e,t,o):_(t)&&t.length>0&&pe(e,t,o)},de=e=>{if(Array.isArray(e))return e.map((e=>de(e)));if(!h(e))return e;const t={...e};for(const[o,r]of Object.entries(e))(h(r)||Array.isArray(r)&&r.length>0&&h(r[0]))&&(t[o]=de(r)),ae(o)&&ue(o,r,t);return t},le=(e,t,o,r)=>{const n=b(e)?void 0:e.data,s=Object.keys(o).length+1,i=l({cursor:r,ignoreStepIndex:s});if(!h(e)||b(n)||(n?.length??0)<=t)return{result:e,next:f(r)&&!i?y(r):null};const a=r?.remote?.[s]?.pageNumber??1,c=(a-1)*t,p=c+t,u=n.slice(c,p),d=n.length>p||!i,g=m({cursor:r,stepIndex:s,pageNumber:a+1});return{result:{...e,data:u},next:d?y(g):null}},ye=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:o=le,encodeResultCompositeIds:r=ne,decodeInputCompositeIds:n=Z})=>{const s=n(e);return r(await ge({block:s,buildStepFunction:t,virtualPaginateResultFn:o}))},me=async(e,t,o,r,n,s)=>{const i=o[e],a=i.stepFunction,c=s.buildStepFunction({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(((e,t)=>!!e.condition&&!F(e.condition,t))(i,r))return be({block:r,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(n.hasFatalError)return be({block:r,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});const p=((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??{}})(i,r,t),u=await c({block:r,params:p});if(!1===u.successful)return((e,t,o,r,n)=>{const s=be({block:e,stepId:t,successful:!1,functionOutput:o});return(r.ignoreError??!1)||(n.hasFatalError=!0,n.errorStatusCode??=o.output?.statusCode??500),s})(r,e,u,i,n);const d=r.operation?.cursor.enabled?m({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return be({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},ge=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:r=le})=>{const n=e.operation?.steps||{};let s={...e};const a=Object.keys(n),c=((e,t)=>{const o=Number(e.inputs?.page_size);return f(e.inputs?.page_size)&&v(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(e,25),p={hasFatalError:!1,errorStatusCode:null},u={block:e,buildStepFunction:t,virtualPaginateResultFn:r};for(const[e,t]of a.entries())s=await me(t,e,n,s,p,u);const d=e.operation?.result?fe(e.operation.result,s):void 0;return((e,t,r,n,s)=>{const i=!r.hasFatalError,a=i?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500;return{...t,outputs:f(s)&&h(s.result)?{next:s.next,...s.result}:n,response:{successful:i,statusCode:a,message:i?void 0:e.operation?.responses?.errors?.[a]?.description??o?.[a]??"Error while processing the request"}}})(e,s,p,d,e.operation?.cursor.enabled?r(d,c,n,s.nextCursor):void 0)},fe=(e,t)=>h(e)?k(e,t):F(e,t),be=({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}}}),he=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:p=A,getOperationFromUrlFn:u=S,parseOperationInputsFn:d=U,createBlockContextFn:l=X,createBlockFn:y=E,runStepOperationFn:m=ye})=>{const g=e.authConfigKey,f=e.environment??"production",h=e.secureId,v=e.projectSecureId,I=e.credentials,C=l({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:g,environment:f,accountSecureId:h,projectSecureId:v});let k;try{k=_(t)?p(t):t}catch{throw new J(C,"Error while parsing connector")}const F=u(k,r,n);if(b(F))throw new W(C,"No matching operation found");C.operationType=F.operation.operationType,C.schema=F.operation.schema?.key;const w=_e(s,C);let j;try{j=d(F.operation,{query:s,body:i,headers:a,path:F.params})}catch{throw new B(C,"Error while parsing operation inputs")}const O=await y({inputs:j,context:C,operation:F.operation,credentials:I,nextCursor:w,logger:c});return await m({block:O})},_e=(e,t)=>{const o=e?.next,r=f(o)&&"list"===t.operationType?g(o):void 0;if(null===r)throw new Y(t,"Invalid cursor.");return r};export{G as ConnectSDKError,E as createBlock,Q as executeStepFunction,S as getOperationFromUrl,U as parseOperationInputs,A as parseYamlConnector,he as runConnectorOperation,ye as runStepOperation};
package/dist/index.js CHANGED
@@ -1 +1 @@
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(),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=_(o),a={baseUrl:o.baseUrl,authentication:f(i)},c=z(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)},_=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},z=(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),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,...O(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,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 k extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,k)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class F extends k{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class T extends k{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class j extends k{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class x extends k{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const w=({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}),N=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 R(n,i,e.logger),{...e,inputs:n}},R=(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)))M(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)R(e,t,o);else"object"==typeof n&&null!==n&&R(n,t,o)}},A=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},M=(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(A)&&(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)}},q="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=P(e,t),n=V(o);return{...e,...r.isObject(n)?n:{}}},P=(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[`${q}${t.remote}`]=e[t.remote])})),{...e,...n}},D=e=>"id"===e||/.+_id(s)?$/.test(e),U=(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[`${q}${e}`]=t},H=(e,t,r)=>{if(((e,t)=>o.isCompositeId(e)||t.startsWith(q))(t,e))return;const n=o.encodeCompositeId({key:e,value:t},{version:o.COMPOSITE_ID_LATEST_VERSION});r[e]=n,r[`remote_${e}`]=t},L=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>r.isString(e)&&e.length>0)))(t)?U(e,t,o):r.isString(t)&&t.length>0&&H(e,t,o)},V=e=>{if(Array.isArray(e))return e.map((e=>V(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]=V(n)),D(o)&&L(o,n,t);return t},G=(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=G,encodeResultCompositeIds:n=$,decodeInputCompositeIds:s=N})=>{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 Q({block:n,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(s.hasFatalError)return Q({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=Q({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 Q({block:{...l.block,nextCursor:y},stepId:e,functionOutput:l})},Y=async({block:t,buildStepFunction:n=o.StepFunctionsFactory.build,virtualPaginateResultFn:s=G})=>{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?J(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)},J=(e,t)=>r.isObject(e)?i.safeEvaluateRecord(e,t):i.safeEvaluate(e,t),Q=({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}}}),X=(e,t)=>{const n=e?.next,s=r.notMissing(n)&&"list"===t.operationType?o.expandCursor(n):void 0;if(null===s)throw new x(t,"Invalid cursor.");return s};exports.ConnectSDKError=k,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=w,createBlockFn:f=a,runStepOperationFn:h=W})=>{const _=e.authConfigKey,z=e.environment??"production",C=e.secureId,v=e.projectSecureId,S=e.credentials,E=m({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:_,environment:z,accountSecureId:C,projectSecureId:v});let O;try{O=r.isString(t)?l(t):t}catch{throw new F(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 x=X(i,E);let N;try{N=g(k.operation,{query:i,body:u,headers:p,path:k.params})}catch{throw new j(E,"Error while parsing operation inputs")}const R=await f({inputs:N,context:E,operation:k.operation,credentials:S,nextCursor:x,logger:d});return await h({block:R})},exports.runStepOperation=W;
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;
@@ -79,6 +79,68 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
79
79
  remote?: string | undefined;
80
80
  }[] | undefined;
81
81
  }>>;
82
+ scheduledJobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
+ enabled: z.ZodBoolean;
84
+ type: z.ZodEnum<["data_sync"]>;
85
+ schedule: z.ZodString;
86
+ description: z.ZodString;
87
+ requestParams: z.ZodOptional<z.ZodObject<{
88
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
89
+ expand: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
90
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ filter?: Record<string, string> | undefined;
93
+ fields?: string[] | undefined;
94
+ expand?: string[] | undefined;
95
+ }, {
96
+ filter?: Record<string, string> | undefined;
97
+ fields?: string[] | undefined;
98
+ expand?: string[] | undefined;
99
+ }>>;
100
+ syncFilter: z.ZodOptional<z.ZodObject<{
101
+ name: z.ZodEnum<["updated_after", "created_after"]>;
102
+ initialLoopbackPeriod: z.ZodString;
103
+ incrementalLoopbackPeriod: z.ZodString;
104
+ }, "strip", z.ZodTypeAny, {
105
+ name: "updated_after" | "created_after";
106
+ initialLoopbackPeriod: string;
107
+ incrementalLoopbackPeriod: string;
108
+ }, {
109
+ name: "updated_after" | "created_after";
110
+ initialLoopbackPeriod: string;
111
+ incrementalLoopbackPeriod: string;
112
+ }>>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ type: "data_sync";
115
+ description: string;
116
+ enabled: boolean;
117
+ schedule: string;
118
+ requestParams?: {
119
+ filter?: Record<string, string> | undefined;
120
+ fields?: string[] | undefined;
121
+ expand?: string[] | undefined;
122
+ } | undefined;
123
+ syncFilter?: {
124
+ name: "updated_after" | "created_after";
125
+ initialLoopbackPeriod: string;
126
+ incrementalLoopbackPeriod: string;
127
+ } | undefined;
128
+ }, {
129
+ type: "data_sync";
130
+ description: string;
131
+ enabled: boolean;
132
+ schedule: string;
133
+ requestParams?: {
134
+ filter?: Record<string, string> | undefined;
135
+ fields?: string[] | undefined;
136
+ expand?: string[] | undefined;
137
+ } | undefined;
138
+ syncFilter?: {
139
+ name: "updated_after" | "created_after";
140
+ initialLoopbackPeriod: string;
141
+ incrementalLoopbackPeriod: string;
142
+ } | undefined;
143
+ }>, "many">>;
82
144
  fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
145
  targetFieldKey: z.ZodString;
84
146
  alias: z.ZodOptional<z.ZodString>;
@@ -218,6 +280,22 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
218
280
  remote?: string | undefined;
219
281
  }[] | undefined;
220
282
  } | undefined;
283
+ scheduledJobs?: {
284
+ type: "data_sync";
285
+ description: string;
286
+ enabled: boolean;
287
+ schedule: string;
288
+ requestParams?: {
289
+ filter?: Record<string, string> | undefined;
290
+ fields?: string[] | undefined;
291
+ expand?: string[] | undefined;
292
+ } | undefined;
293
+ syncFilter?: {
294
+ name: "updated_after" | "created_after";
295
+ initialLoopbackPeriod: string;
296
+ incrementalLoopbackPeriod: string;
297
+ } | undefined;
298
+ }[] | undefined;
221
299
  fieldConfigs?: {
222
300
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
223
301
  custom: boolean;
@@ -276,6 +354,22 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
276
354
  remote?: string | undefined;
277
355
  }[] | undefined;
278
356
  } | undefined;
357
+ scheduledJobs?: {
358
+ type: "data_sync";
359
+ description: string;
360
+ enabled: boolean;
361
+ schedule: string;
362
+ requestParams?: {
363
+ filter?: Record<string, string> | undefined;
364
+ fields?: string[] | undefined;
365
+ expand?: string[] | undefined;
366
+ } | undefined;
367
+ syncFilter?: {
368
+ name: "updated_after" | "created_after";
369
+ initialLoopbackPeriod: string;
370
+ incrementalLoopbackPeriod: string;
371
+ } | undefined;
372
+ }[] | undefined;
279
373
  fieldConfigs?: {
280
374
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
281
375
  targetFieldKey: string;
@@ -741,6 +835,68 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
741
835
  remote?: string | undefined;
742
836
  }[] | undefined;
743
837
  }>>;
838
+ scheduledJobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
839
+ enabled: z.ZodBoolean;
840
+ type: z.ZodEnum<["data_sync"]>;
841
+ schedule: z.ZodString;
842
+ description: z.ZodString;
843
+ requestParams: z.ZodOptional<z.ZodObject<{
844
+ fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
845
+ expand: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
846
+ filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
847
+ }, "strip", z.ZodTypeAny, {
848
+ filter?: Record<string, string> | undefined;
849
+ fields?: string[] | undefined;
850
+ expand?: string[] | undefined;
851
+ }, {
852
+ filter?: Record<string, string> | undefined;
853
+ fields?: string[] | undefined;
854
+ expand?: string[] | undefined;
855
+ }>>;
856
+ syncFilter: z.ZodOptional<z.ZodObject<{
857
+ name: z.ZodEnum<["updated_after", "created_after"]>;
858
+ initialLoopbackPeriod: z.ZodString;
859
+ incrementalLoopbackPeriod: z.ZodString;
860
+ }, "strip", z.ZodTypeAny, {
861
+ name: "updated_after" | "created_after";
862
+ initialLoopbackPeriod: string;
863
+ incrementalLoopbackPeriod: string;
864
+ }, {
865
+ name: "updated_after" | "created_after";
866
+ initialLoopbackPeriod: string;
867
+ incrementalLoopbackPeriod: string;
868
+ }>>;
869
+ }, "strip", z.ZodTypeAny, {
870
+ type: "data_sync";
871
+ description: string;
872
+ enabled: boolean;
873
+ schedule: string;
874
+ requestParams?: {
875
+ filter?: Record<string, string> | undefined;
876
+ fields?: string[] | undefined;
877
+ expand?: string[] | undefined;
878
+ } | undefined;
879
+ syncFilter?: {
880
+ name: "updated_after" | "created_after";
881
+ initialLoopbackPeriod: string;
882
+ incrementalLoopbackPeriod: string;
883
+ } | undefined;
884
+ }, {
885
+ type: "data_sync";
886
+ description: string;
887
+ enabled: boolean;
888
+ schedule: string;
889
+ requestParams?: {
890
+ filter?: Record<string, string> | undefined;
891
+ fields?: string[] | undefined;
892
+ expand?: string[] | undefined;
893
+ } | undefined;
894
+ syncFilter?: {
895
+ name: "updated_after" | "created_after";
896
+ initialLoopbackPeriod: string;
897
+ incrementalLoopbackPeriod: string;
898
+ } | undefined;
899
+ }>, "many">>;
744
900
  fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
745
901
  targetFieldKey: z.ZodString;
746
902
  alias: z.ZodOptional<z.ZodString>;
@@ -880,6 +1036,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
880
1036
  remote?: string | undefined;
881
1037
  }[] | undefined;
882
1038
  } | undefined;
1039
+ scheduledJobs?: {
1040
+ type: "data_sync";
1041
+ description: string;
1042
+ enabled: boolean;
1043
+ schedule: string;
1044
+ requestParams?: {
1045
+ filter?: Record<string, string> | undefined;
1046
+ fields?: string[] | undefined;
1047
+ expand?: string[] | undefined;
1048
+ } | undefined;
1049
+ syncFilter?: {
1050
+ name: "updated_after" | "created_after";
1051
+ initialLoopbackPeriod: string;
1052
+ incrementalLoopbackPeriod: string;
1053
+ } | undefined;
1054
+ }[] | undefined;
883
1055
  fieldConfigs?: {
884
1056
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
885
1057
  custom: boolean;
@@ -938,6 +1110,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
938
1110
  remote?: string | undefined;
939
1111
  }[] | undefined;
940
1112
  } | undefined;
1113
+ scheduledJobs?: {
1114
+ type: "data_sync";
1115
+ description: string;
1116
+ enabled: boolean;
1117
+ schedule: string;
1118
+ requestParams?: {
1119
+ filter?: Record<string, string> | undefined;
1120
+ fields?: string[] | undefined;
1121
+ expand?: string[] | undefined;
1122
+ } | undefined;
1123
+ syncFilter?: {
1124
+ name: "updated_after" | "created_after";
1125
+ initialLoopbackPeriod: string;
1126
+ incrementalLoopbackPeriod: string;
1127
+ } | undefined;
1128
+ }[] | undefined;
941
1129
  fieldConfigs?: {
942
1130
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
943
1131
  targetFieldKey: string;
@@ -1078,6 +1266,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
1078
1266
  remote?: string | undefined;
1079
1267
  }[] | undefined;
1080
1268
  } | undefined;
1269
+ scheduledJobs?: {
1270
+ type: "data_sync";
1271
+ description: string;
1272
+ enabled: boolean;
1273
+ schedule: string;
1274
+ requestParams?: {
1275
+ filter?: Record<string, string> | undefined;
1276
+ fields?: string[] | undefined;
1277
+ expand?: string[] | undefined;
1278
+ } | undefined;
1279
+ syncFilter?: {
1280
+ name: "updated_after" | "created_after";
1281
+ initialLoopbackPeriod: string;
1282
+ incrementalLoopbackPeriod: string;
1283
+ } | undefined;
1284
+ }[] | undefined;
1081
1285
  fieldConfigs?: {
1082
1286
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
1083
1287
  custom: boolean;
@@ -1218,6 +1422,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
1218
1422
  remote?: string | undefined;
1219
1423
  }[] | undefined;
1220
1424
  } | undefined;
1425
+ scheduledJobs?: {
1426
+ type: "data_sync";
1427
+ description: string;
1428
+ enabled: boolean;
1429
+ schedule: string;
1430
+ requestParams?: {
1431
+ filter?: Record<string, string> | undefined;
1432
+ fields?: string[] | undefined;
1433
+ expand?: string[] | undefined;
1434
+ } | undefined;
1435
+ syncFilter?: {
1436
+ name: "updated_after" | "created_after";
1437
+ initialLoopbackPeriod: string;
1438
+ incrementalLoopbackPeriod: string;
1439
+ } | undefined;
1440
+ }[] | undefined;
1221
1441
  fieldConfigs?: {
1222
1442
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
1223
1443
  targetFieldKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/connect-sdk",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",