@stackone/connect-sdk 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.mjs CHANGED
@@ -1 +1 @@
1
- import{StepFunctionsFactory as e,StepFunctionName as t,AUTHENTICATION_SCHEMA as o,expandCursor as r}from"@stackone/core";import{safeEvaluate as n,safeEvaluateRecord as s}from"@stackone/expressions";import{isObject as i,notMissing as c,isString as a,isMissing as p}from"@stackone/utils";import{HttpClientManager as u,isSuccessStatusCode as d}from"@stackone/transport";import{match as l}from"path-to-regexp";import{parse as y}from"yaml";import{z as m}from"zod";const h=async({block:o,stepFunctionName:r,params:n,buildStepFunction:s=e.build})=>{const i=s({functionName:r}).fn,c=await i({block:o,params:n}),a=r===t.MAP_FIELDS?{[t.MAP_FIELDS.toString()]:{output:{data:c.block.result},errors:c.errors,successful:c.successful}}:{};return{...c.block,steps:{...c?.block?.steps??{},...a}}},g=async({block:t,buildStepFunction:o=e.build})=>await b({block:t,buildStepFunction:o}),b=async({block:t,buildStepFunction:o=e.build})=>{const r=t.operation?.steps||[];let s={...t};const i=Object.keys(r);let c=!1,a=null;for(const e of i){const t=r[e],i=t.stepFunction,p=o({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(t.condition&&!n(t.condition,s)){s=_({block:s,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(c){s=_({block:s,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=await p({block:s,params:i.params});if(!1===u.successful){s=_({block:s,stepId:e,successful:!1,functionOutput:u});(t.ignoreError??!1)||(c=!0,a??=u.output?.statusCode??500)}else s=_({block:u.block,stepId:e,functionOutput:u})}const p=t.operation?.result?f(t.operation.result,s):void 0,u=!c,d=u?t.operation?.responses.success.statusCode??200:a??500;return{...s,outputs:p,response:{successful:u,statusCode:d,message:u?void 0:t.operation?.responses?.errors?.[d]?.description??"Error while processing the request"}}},f=(e,t)=>i(e)?s(e,t):n(e,t),_=({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}}}),k=async({inputs:e,context:t,operation:o,credentials:r,nextCursor:n,logger:s,getHttpClient:i=async()=>u.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,nextCursor:n,httpClient:await i(),logger:s}),C=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:c})=>({projectSecureId:c,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),v=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=I(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},I=(e,t,o)=>{const r=w(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),n=l(w(o))(w(r));if(!1!==n)return{path:e,params:n.params}}},E=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}`)}},S=m.object({key:m.string(),label:m.string(),type:m.string(),required:m.boolean().optional(),secret:m.boolean().optional(),placeholder:m.string().optional(),description:m.string().optional(),tooltip:m.string().optional()}),F=m.object({operationId:m.string(),categories:m.string().array(),operationType:m.enum(["list","get","create","update","delete","custom","unknown"]),schema:m.string().optional(),entrypointUrl:m.string().optional(),entrypointHttpMethod:m.string().optional(),description:m.string(),responses:m.object({statusCode:m.number(),description:m.string()}).array().optional(),inputs:m.object({name:m.string(),type:m.string(),required:m.boolean(),description:m.string(),in:m.string()}).array().optional(),fieldConfigs:m.object({targetFieldKey:m.string(),expression:m.string(),type:m.enum(["string","number","boolean","datetime_string","enum"]),isUnified:m.boolean(),enumMapper:m.object({matcher:m.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(m.object({matchExpression:m.string(),value:m.string()}).array())}).optional()}).array().optional(),steps:m.object({stepId:m.string(),description:m.string(),stepFunction:m.object({functionName:m.string(),version:m.string().optional(),parameters:m.record(m.string(),m.unknown())}),condition:m.string().optional(),ignoreError:m.boolean().optional()}).array(),result:m.string().or(m.record(m.string(),m.unknown())).optional()}),T=m.object({StackOne:m.string(),info:m.object({title:m.string(),version:m.string(),key:m.string(),description:m.string().optional()}),baseUrl:m.string(),authentication:m.record(m.string(),m.object({type:m.string(),label:m.string(),authorization:o,environments:m.object({key:m.string(),name:m.string()}).array(),support:m.object({link:m.string(),description:m.string().optional()}),configFields:S.array().optional(),setupFields:S.array().optional(),testOperationsIds:m.string().array().optional()})).array().optional(),operations:F.array().optional()});function O(e){try{const t=y(e),o=T.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=N(o),s={baseUrl:o.baseUrl,authentication:j(n)},i=R(o,s);return r.operations=i,r.authentication=n,c(i)&&(r.categories=x(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const j=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,...c}=r;t[o]=j(c)}else t[o]=r;return t},x=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},N=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,...c}=o[e];return t[n]={...c,envKey:n,envName:s},t}),{});t[e]=r}return t},R=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const r=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),n=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),s=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),i=(e=>{const t={success:E(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."}}},o=e.responses?.reduce(((e,t)=>(d(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return o??t})(o);return e[r??n]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??s,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:i,inputs:o.inputs,steps:o.steps.reduce(((e,r)=>(e[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{..."request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},U=(e,t)=>{if(!e.inputs)return{};const o=$(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},q=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=m.string();break;case"number":o=m.number();break;case"boolean":o=m.boolean();break;default:o=m.any()}t[e.name]=e.required?o:o.optional()})),m.object(t)},$=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 m.object({path:q(t).optional(),query:q(o).optional(),body:q(r).optional(),headers:q(n).optional()})};class M extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,M)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class K extends M{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class A extends M{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class P extends M{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class H extends M{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const L=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:c,logger:u,parseConnector:d=O,getOperationFromUrlFn:l=v,parseOperationInputsFn:y=U,createBlockContextFn:m=C,createBlockFn:h=k,runStepOperationFn:b=g})=>{const f=e.authConfigKey,_=e.environment??"production",w=e.secureId,I=e.projectSecureId,E=e.credentials,S=m({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:f,environment:_,accountSecureId:w,projectSecureId:I});let F;try{F=a(t)?d(t):t}catch{throw new K(S,"Error while parsing connector")}const T=l(F,r,n);if(p(T))throw new A(S,"No matching operation found");S.operationType=T.operation.operationType,S.schema=T.operation.schema?.key;const j=V(s,S);let x;try{x=y(T.operation,{query:s,body:i,headers:c,path:T.params})}catch{throw new P(S,"Error while parsing operation inputs")}const N=await h({inputs:x,context:S,operation:T.operation,credentials:E,nextCursor:j,logger:u});return await b({block:N})},V=(e,t)=>{const o=e?.next,n=c(o)&&"list"===t.operationType?r(o):void 0;if(null===n)throw new H(t,"Invalid cursor.");return n};export{M as ConnectSDKError,k as createBlock,h as executeStepFunction,v as getOperationFromUrl,U as parseOperationInputs,O as parseYamlConnector,L as runConnectorOperation,g as runStepOperation};
1
+ import{StepFunctionsFactory as e,StepFunctionName as t,AUTHENTICATION_SCHEMA as o,expandCursor as r}from"@stackone/core";import{safeEvaluate as n,safeEvaluateRecord as s}from"@stackone/expressions";import{isObject as i,notMissing as a,isString as c,isMissing as p}from"@stackone/utils";import{HttpClientManager as u,isSuccessStatusCode as d}from"@stackone/transport";import{match as l}from"path-to-regexp";import{parse as y}from"yaml";import{z as g}from"zod";const m=async({block:o,stepFunctionName:r,params:n,buildStepFunction:s=e.build})=>{const i=s({functionName:r}).fn,a=await i({block:o,params:n}),c=r===t.MAP_FIELDS?{[t.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...c}}},b=async({block:t,buildStepFunction:o=e.build})=>await h({block:t,buildStepFunction:o}),h=async({block:t,buildStepFunction:o=e.build})=>{const r=t.operation?.steps||[];let s={...t};const i=Object.keys(r);let a=!1,c=null;for(const e of i){const t=r[e],i=t.stepFunction,p=o({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(t.condition&&!n(t.condition,s)){s=_({block:s,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(a){s=_({block:s,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=await p({block:s,params:i.params});if(!1===u.successful){s=_({block:s,stepId:e,successful:!1,functionOutput:u});(t.ignoreError??!1)||(a=!0,c??=u.output?.statusCode??500)}else s=_({block:u.block,stepId:e,functionOutput:u})}const p=t.operation?.result?f(t.operation.result,s):void 0,u=!a,d=u?t.operation?.responses.success.statusCode??200:c??500;return{...s,outputs:p,response:{successful:u,statusCode:d,message:u?void 0:t.operation?.responses?.errors?.[d]?.description??"Error while processing the request"}}},f=(e,t)=>i(e)?s(e,t):n(e,t),_=({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}}}),k=async({inputs:e,context:t,operation:o,credentials:r,nextCursor:n,logger:s,getHttpClient:i=async()=>u.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,nextCursor:n,httpClient:await i(),logger:s}),C=({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}),v=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=I(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},I=(e,t,o)=>{const r=w(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),n=l(w(o))(w(r));if(!1!==n)return{path:e,params:n.params}}},S=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}`)}},E=g.object({key:g.string(),label:g.string(),type:g.string(),required:g.boolean().optional(),secret:g.boolean().optional(),placeholder:g.string().optional(),description:g.string().optional(),tooltip:g.string().optional()}),T=g.object({operationId:g.string(),categories:g.string().array(),operationType:g.enum(["list","get","create","update","delete","custom","unknown"]),schema:g.string().optional(),entrypointUrl:g.string().optional(),entrypointHttpMethod:g.string().optional(),description:g.string(),responses:g.object({statusCode:g.number(),description:g.string()}).array().optional(),inputs:g.object({name:g.string(),type:g.string(),required:g.boolean(),description:g.string(),in:g.string()}).array().optional(),cursor:g.object({enabled:g.boolean(),pageSize:g.number()}).optional(),fieldConfigs:g.object({targetFieldKey:g.string(),expression:g.string(),type:g.enum(["string","number","boolean","datetime_string","enum"]),isUnified:g.boolean(),enumMapper:g.object({matcher:g.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(g.object({matchExpression:g.string(),value:g.string()}).array())}).optional()}).array().optional(),steps:g.object({stepId:g.string(),description:g.string(),stepFunction:g.object({functionName:g.string(),version:g.string().optional(),parameters:g.record(g.string(),g.unknown())}),condition:g.string().optional(),ignoreError:g.boolean().optional()}).array(),result:g.string().or(g.record(g.string(),g.unknown())).optional()}),F=g.object({StackOne:g.string(),info:g.object({title:g.string(),version:g.string(),key:g.string(),description:g.string().optional()}),baseUrl:g.string(),authentication:g.record(g.string(),g.object({type:g.string(),label:g.string(),authorization:o,environments:g.object({key:g.string(),name:g.string()}).array(),support:g.object({link:g.string(),description:g.string().optional()}),configFields:E.array().optional(),setupFields:E.array().optional(),testOperationsIds:g.string().array().optional()})).array().optional(),operations:T.array().optional()});function j(e){try{const t=y(e),o=F.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=N(o),s={baseUrl:o.baseUrl,authentication:O(n)},i=R(o,s);return r.operations=i,r.authentication=n,a(i)&&(r.categories=x(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const O=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]=O(a)}else t[o]=r;return t},x=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},N=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},R=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const r=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),n=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),s=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),i=(e=>{const t={success:S(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."}}},o=e.responses?.reduce(((e,t)=>(d(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return o??t})(o);return e[r??n]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??s,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:i,cursor:M(o),inputs:o.inputs,steps:o.steps.reduce(((e,r)=>(e[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{..."request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},U=(e,t)=>{if(!e.inputs)return{};const o=$(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},q=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=g.string();break;case"number":o=g.number();break;case"boolean":o=g.boolean();break;default:o=g.any()}t[e.name]=e.required?o:o.optional()})),g.object(t)},$=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 g.object({path:q(t).optional(),query:q(o).optional(),body:q(r).optional(),headers:q(n).optional()})},M=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}};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 A extends K{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class z extends K{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class P extends K{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class H extends K{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const L=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:u,parseConnector:d=j,getOperationFromUrlFn:l=v,parseOperationInputsFn:y=U,createBlockContextFn:g=C,createBlockFn:m=k,runStepOperationFn:h=b})=>{const f=e.authConfigKey,_=e.environment??"production",w=e.secureId,I=e.projectSecureId,S=e.credentials,E=g({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:f,environment:_,accountSecureId:w,projectSecureId:I});let T;try{T=c(t)?d(t):t}catch{throw new A(E,"Error while parsing connector")}const F=l(T,r,n);if(p(F))throw new z(E,"No matching operation found");E.operationType=F.operation.operationType,E.schema=F.operation.schema?.key;const O=V(s,E);let x;try{x=y(F.operation,{query:s,body:i,headers:a,path:F.params})}catch{throw new P(E,"Error while parsing operation inputs")}const N=await m({inputs:x,context:E,operation:F.operation,credentials:S,nextCursor:O,logger:u});return await h({block:N})},V=(e,t)=>{const o=e?.next,n=a(o)&&"list"===t.operationType?r(o):void 0;if(null===n)throw new H(t,"Invalid cursor.");return n};export{K as ConnectSDKError,k as createBlock,m as executeStepFunction,v as getOperationFromUrl,U as parseOperationInputs,j as parseYamlConnector,L as runConnectorOperation,b as runStepOperation};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/utils"),r=require("@stackone/transport"),n=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=async({block:t,buildStepFunction:o=e.StepFunctionsFactory.build})=>await c({block:t,buildStepFunction:o}),c=async({block:o,buildStepFunction:r=e.StepFunctionsFactory.build})=>{const n=o.operation?.steps||[];let s={...o};const i=Object.keys(n);let a=!1,c=null;for(const e of i){const o=n[e],i=o.stepFunction,p=r({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(o.condition&&!t.safeEvaluate(o.condition,s)){s=u({block:s,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(a){s=u({block:s,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const d=await p({block:s,params:i.params});if(!1===d.successful){s=u({block:s,stepId:e,successful:!1,functionOutput:d});(o.ignoreError??!1)||(a=!0,c??=d.output?.statusCode??500)}else s=u({block:d.block,stepId:e,functionOutput:d})}const d=o.operation?.result?p(o.operation.result,s):void 0,l=!a,y=l?o.operation?.responses.success.statusCode??200:c??500;return{...s,outputs:d,response:{successful:l,statusCode:y,message:l?void 0:o.operation?.responses?.errors?.[y]?.description??"Error while processing the request"}}},p=(e,r)=>o.isObject(e)?t.safeEvaluateRecord(e,r):t.safeEvaluate(e,r),u=({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}}}),d=async({inputs:e,context:t,operation:o,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>r.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),l=({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}),y=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=h(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},g=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},h=(e,t,o)=>{const r=g(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=n.match(g(o))(g(r));if(!1!==s)return{path:e,params:s.params}}},b=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}`)}},m=i.z.object({key:i.z.string(),label:i.z.string(),type:i.z.string(),required:i.z.boolean().optional(),secret:i.z.boolean().optional(),placeholder:i.z.string().optional(),description:i.z.string().optional(),tooltip:i.z.string().optional()}),_=i.z.object({operationId:i.z.string(),categories:i.z.string().array(),operationType:i.z.enum(["list","get","create","update","delete","custom","unknown"]),schema:i.z.string().optional(),entrypointUrl:i.z.string().optional(),entrypointHttpMethod:i.z.string().optional(),description:i.z.string(),responses:i.z.object({statusCode:i.z.number(),description:i.z.string()}).array().optional(),inputs:i.z.object({name:i.z.string(),type:i.z.string(),required:i.z.boolean(),description:i.z.string(),in:i.z.string()}).array().optional(),fieldConfigs:i.z.object({targetFieldKey:i.z.string(),expression:i.z.string(),type:i.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:i.z.boolean(),enumMapper:i.z.object({matcher:i.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(i.z.object({matchExpression:i.z.string(),value:i.z.string()}).array())}).optional()}).array().optional(),steps:i.z.object({stepId:i.z.string(),description:i.z.string(),stepFunction:i.z.object({functionName:i.z.string(),version:i.z.string().optional(),parameters:i.z.record(i.z.string(),i.z.unknown())}),condition:i.z.string().optional(),ignoreError:i.z.boolean().optional()}).array(),result:i.z.string().or(i.z.record(i.z.string(),i.z.unknown())).optional()}),f=i.z.object({StackOne:i.z.string(),info:i.z.object({title:i.z.string(),version:i.z.string(),key:i.z.string(),description:i.z.string().optional()}),baseUrl:i.z.string(),authentication:i.z.record(i.z.string(),i.z.object({type:i.z.string(),label:i.z.string(),authorization:e.AUTHENTICATION_SCHEMA,environments:i.z.object({key:i.z.string(),name:i.z.string()}).array(),support:i.z.object({link:i.z.string(),description:i.z.string().optional()}),configFields:m.array().optional(),setupFields:m.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:_.array().optional()});function z(e){try{const t=s.parse(e),r=f.parse(t),n={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},i=v(r),a={baseUrl:r.baseUrl,authentication:k(i)},c=S(r,a);return n.operations=c,n.authentication=i,o.notMissing(c)&&(n.categories=C(Object.values(c))),n}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const k=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]=k(a)}else t[o]=r;return t},C=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},v=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},S=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),a=(e=>{const t={success:b(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."}}},o=e.responses?.reduce(((e,t)=>(r.isSuccessStatusCode(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return o??t})(o);return e[n??s]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:a,inputs:o.inputs,steps:o.steps.reduce(((e,r)=>(e[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{..."request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},I=(e,t)=>{if(!e.inputs)return{};const o=E(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},w=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=i.z.string();break;case"number":o=i.z.number();break;case"boolean":o=i.z.boolean();break;default:o=i.z.any()}t[e.name]=e.required?o:o.optional()})),i.z.object(t)},E=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 i.z.object({path:w(t).optional(),query:w(o).optional(),body:w(r).optional(),headers:w(n).optional()})};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 O 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 j extends F{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const N=(t,r)=>{const n=t?.next,s=o.notMissing(n)&&"list"===r.operationType?e.expandCursor(n):void 0;if(null===s)throw new j(r,"Invalid cursor.");return s};exports.ConnectSDKError=F,exports.createBlock=d,exports.executeStepFunction=async({block:t,stepFunctionName:o,params:r,buildStepFunction:n=e.StepFunctionsFactory.build})=>{const s=n({functionName:o}).fn,i=await s({block:t,params:r}),a=o===e.StepFunctionName.MAP_FIELDS?{[e.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=y,exports.parseOperationInputs=I,exports.parseYamlConnector=z,exports.runConnectorOperation=async({account:e,connector:t,category:r,path:n,method:s="get",queryParams:i,body:c,headers:p,logger:u,parseConnector:g=z,getOperationFromUrlFn:h=y,parseOperationInputsFn:b=I,createBlockContextFn:m=l,createBlockFn:_=d,runStepOperationFn:f=a})=>{const k=e.authConfigKey,C=e.environment??"production",v=e.secureId,S=e.projectSecureId,w=e.credentials,E=m({category:r,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:k,environment:C,accountSecureId:v,projectSecureId:S});let F;try{F=o.isString(t)?g(t):t}catch{throw new O(E,"Error while parsing connector")}const j=h(F,n,s);if(o.isMissing(j))throw new T(E,"No matching operation found");E.operationType=j.operation.operationType,E.schema=j.operation.schema?.key;const R=N(i,E);let q;try{q=b(j.operation,{query:i,body:c,headers:p,path:j.params})}catch{throw new x(E,"Error while parsing operation inputs")}const U=await _({inputs:q,context:E,operation:j.operation,credentials:w,nextCursor:R,logger:u});return await f({block:U})},exports.runStepOperation=a;
1
+ "use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/utils"),r=require("@stackone/transport"),n=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=async({block:t,buildStepFunction:o=e.StepFunctionsFactory.build})=>await c({block:t,buildStepFunction:o}),c=async({block:o,buildStepFunction:r=e.StepFunctionsFactory.build})=>{const n=o.operation?.steps||[];let s={...o};const i=Object.keys(n);let a=!1,c=null;for(const e of i){const o=n[e],i=o.stepFunction,p=r({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(o.condition&&!t.safeEvaluate(o.condition,s)){s=u({block:s,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(a){s=u({block:s,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const d=await p({block:s,params:i.params});if(!1===d.successful){s=u({block:s,stepId:e,successful:!1,functionOutput:d});(o.ignoreError??!1)||(a=!0,c??=d.output?.statusCode??500)}else s=u({block:d.block,stepId:e,functionOutput:d})}const d=o.operation?.result?p(o.operation.result,s):void 0,l=!a,y=l?o.operation?.responses.success.statusCode??200:c??500;return{...s,outputs:d,response:{successful:l,statusCode:y,message:l?void 0:o.operation?.responses?.errors?.[y]?.description??"Error while processing the request"}}},p=(e,r)=>o.isObject(e)?t.safeEvaluateRecord(e,r):t.safeEvaluate(e,r),u=({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}}}),d=async({inputs:e,context:t,operation:o,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>r.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),l=({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}),y=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=b(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},g=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},b=(e,t,o)=>{const r=g(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=n.match(g(o))(g(r));if(!1!==s)return{path:e,params:s.params}}},h=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}`)}},m=i.z.object({key:i.z.string(),label:i.z.string(),type:i.z.string(),required:i.z.boolean().optional(),secret:i.z.boolean().optional(),placeholder:i.z.string().optional(),description:i.z.string().optional(),tooltip:i.z.string().optional()}),z=i.z.object({operationId:i.z.string(),categories:i.z.string().array(),operationType:i.z.enum(["list","get","create","update","delete","custom","unknown"]),schema:i.z.string().optional(),entrypointUrl:i.z.string().optional(),entrypointHttpMethod:i.z.string().optional(),description:i.z.string(),responses:i.z.object({statusCode:i.z.number(),description:i.z.string()}).array().optional(),inputs:i.z.object({name:i.z.string(),type:i.z.string(),required:i.z.boolean(),description:i.z.string(),in:i.z.string()}).array().optional(),cursor:i.z.object({enabled:i.z.boolean(),pageSize:i.z.number()}).optional(),fieldConfigs:i.z.object({targetFieldKey:i.z.string(),expression:i.z.string(),type:i.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:i.z.boolean(),enumMapper:i.z.object({matcher:i.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(i.z.object({matchExpression:i.z.string(),value:i.z.string()}).array())}).optional()}).array().optional(),steps:i.z.object({stepId:i.z.string(),description:i.z.string(),stepFunction:i.z.object({functionName:i.z.string(),version:i.z.string().optional(),parameters:i.z.record(i.z.string(),i.z.unknown())}),condition:i.z.string().optional(),ignoreError:i.z.boolean().optional()}).array(),result:i.z.string().or(i.z.record(i.z.string(),i.z.unknown())).optional()}),_=i.z.object({StackOne:i.z.string(),info:i.z.object({title:i.z.string(),version:i.z.string(),key:i.z.string(),description:i.z.string().optional()}),baseUrl:i.z.string(),authentication:i.z.record(i.z.string(),i.z.object({type:i.z.string(),label:i.z.string(),authorization:e.AUTHENTICATION_SCHEMA,environments:i.z.object({key:i.z.string(),name:i.z.string()}).array(),support:i.z.object({link:i.z.string(),description:i.z.string().optional()}),configFields:m.array().optional(),setupFields:m.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:z.array().optional()});function f(e){try{const t=s.parse(e),r=_.parse(t),n={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},i=v(r),a={baseUrl:r.baseUrl,authentication:k(i)},c=S(r,a);return n.operations=c,n.authentication=i,o.notMissing(c)&&(n.categories=C(Object.values(c))),n}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const k=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]=k(a)}else t[o]=r;return t},C=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},v=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},S=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),a=(e=>{const t={success:h(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."}}},o=e.responses?.reduce(((e,t)=>(r.isSuccessStatusCode(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return o??t})(o);return e[n??s]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:a,cursor:F(o),inputs:o.inputs,steps:o.steps.reduce(((e,r)=>(e[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{..."request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},I=(e,t)=>{if(!e.inputs)return{};const o=E(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},w=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=i.z.string();break;case"number":o=i.z.number();break;case"boolean":o=i.z.boolean();break;default:o=i.z.any()}t[e.name]=e.required?o:o.optional()})),i.z.object(t)},E=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 i.z.object({path:w(t).optional(),query:w(o).optional(),body:w(r).optional(),headers:w(n).optional()})},F=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}};class O extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,O)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class T extends O{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class x extends O{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class j extends O{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class N extends O{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const R=(t,r)=>{const n=t?.next,s=o.notMissing(n)&&"list"===r.operationType?e.expandCursor(n):void 0;if(null===s)throw new N(r,"Invalid cursor.");return s};exports.ConnectSDKError=O,exports.createBlock=d,exports.executeStepFunction=async({block:t,stepFunctionName:o,params:r,buildStepFunction:n=e.StepFunctionsFactory.build})=>{const s=n({functionName:o}).fn,i=await s({block:t,params:r}),a=o===e.StepFunctionName.MAP_FIELDS?{[e.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=y,exports.parseOperationInputs=I,exports.parseYamlConnector=f,exports.runConnectorOperation=async({account:e,connector:t,category:r,path:n,method:s="get",queryParams:i,body:c,headers:p,logger:u,parseConnector:g=f,getOperationFromUrlFn:b=y,parseOperationInputsFn:h=I,createBlockContextFn:m=l,createBlockFn:z=d,runStepOperationFn:_=a})=>{const k=e.authConfigKey,C=e.environment??"production",v=e.secureId,S=e.projectSecureId,w=e.credentials,E=m({category:r,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:k,environment:C,accountSecureId:v,projectSecureId:S});let F;try{F=o.isString(t)?g(t):t}catch{throw new T(E,"Error while parsing connector")}const O=b(F,n,s);if(o.isMissing(O))throw new x(E,"No matching operation found");E.operationType=O.operation.operationType,E.schema=O.operation.schema?.key;const N=R(i,E);let q;try{q=h(O.operation,{query:i,body:c,headers:p,path:O.params})}catch{throw new j(E,"Error while parsing operation inputs")}const U=await z({inputs:q,context:E,operation:O.operation,credentials:w,nextCursor:N,logger:u});return await _({block:U})},exports.runStepOperation=a;
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_PAGE_SIZE = 25;
@@ -36,6 +36,16 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
36
36
  name: string;
37
37
  in: string;
38
38
  }>, "many">>;
39
+ cursor: z.ZodOptional<z.ZodObject<{
40
+ enabled: z.ZodBoolean;
41
+ pageSize: z.ZodNumber;
42
+ }, "strip", z.ZodTypeAny, {
43
+ enabled: boolean;
44
+ pageSize: number;
45
+ }, {
46
+ enabled: boolean;
47
+ pageSize: number;
48
+ }>>;
39
49
  fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
40
50
  targetFieldKey: z.ZodString;
41
51
  expression: z.ZodString;
@@ -156,6 +166,10 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
156
166
  name: string;
157
167
  in: string;
158
168
  }[] | undefined;
169
+ cursor?: {
170
+ enabled: boolean;
171
+ pageSize: number;
172
+ } | undefined;
159
173
  fieldConfigs?: {
160
174
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
161
175
  targetFieldKey: string;
@@ -199,6 +213,10 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
199
213
  name: string;
200
214
  in: string;
201
215
  }[] | undefined;
216
+ cursor?: {
217
+ enabled: boolean;
218
+ pageSize: number;
219
+ } | undefined;
202
220
  fieldConfigs?: {
203
221
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
204
222
  targetFieldKey: string;
@@ -457,6 +475,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
457
475
  name: string;
458
476
  in: string;
459
477
  }>, "many">>;
478
+ cursor: z.ZodOptional<z.ZodObject<{
479
+ enabled: z.ZodBoolean;
480
+ pageSize: z.ZodNumber;
481
+ }, "strip", z.ZodTypeAny, {
482
+ enabled: boolean;
483
+ pageSize: number;
484
+ }, {
485
+ enabled: boolean;
486
+ pageSize: number;
487
+ }>>;
460
488
  fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
461
489
  targetFieldKey: z.ZodString;
462
490
  expression: z.ZodString;
@@ -577,6 +605,10 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
577
605
  name: string;
578
606
  in: string;
579
607
  }[] | undefined;
608
+ cursor?: {
609
+ enabled: boolean;
610
+ pageSize: number;
611
+ } | undefined;
580
612
  fieldConfigs?: {
581
613
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
582
614
  targetFieldKey: string;
@@ -620,6 +652,10 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
620
652
  name: string;
621
653
  in: string;
622
654
  }[] | undefined;
655
+ cursor?: {
656
+ enabled: boolean;
657
+ pageSize: number;
658
+ } | undefined;
623
659
  fieldConfigs?: {
624
660
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
625
661
  targetFieldKey: string;
@@ -715,6 +751,10 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
715
751
  name: string;
716
752
  in: string;
717
753
  }[] | undefined;
754
+ cursor?: {
755
+ enabled: boolean;
756
+ pageSize: number;
757
+ } | undefined;
718
758
  fieldConfigs?: {
719
759
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
720
760
  targetFieldKey: string;
@@ -810,6 +850,10 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
810
850
  name: string;
811
851
  in: string;
812
852
  }[] | undefined;
853
+ cursor?: {
854
+ enabled: boolean;
855
+ pageSize: number;
856
+ } | undefined;
813
857
  fieldConfigs?: {
814
858
  type: "string" | "number" | "boolean" | "datetime_string" | "enum";
815
859
  targetFieldKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/connect-sdk",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",