@stackone/connect-sdk 1.17.0 → 1.18.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 t,StepFunctionName as e,AUTHENTICATION_SCHEMA as o}from"@stackone/core";import{safeEvaluate as n}from"@stackone/expressions";import{notMissing as r,isString as i,isMissing as s}from"@stackone/utils";import{HttpClientManager as a}from"@stackone/transport";import{match as c}from"path-to-regexp";import{parse as p}from"yaml";import{z as u}from"zod";const l=async({block:o,stepFunctionName:n,params:r,buildStepFunction:i=t.build})=>{const s=i({functionName:n}).fn,a=await s({block:o,params:r}),c=n===e.MAP_FIELDS?{[e.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...c}}},d=async({block:e,buildStepFunction:o=t.build})=>{const r=e.operation?.steps||[];let i={...e};const s=Object.keys(r);for(const t of s){const e=r[t],s=e.stepFunction,a=o({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(e.condition&&!n(e.condition,i)){i={...i,steps:{...i.steps,[t]:{successful:!0,skipped:!0}}};continue}const c=await a({block:i,params:s.params});i={...c.block,steps:{...c.block.steps,[t]:{successful:c.successful,errors:c.errors,output:c.output}}}}const a=e.operation?.result?n(e.operation.result,i):void 0;return{...i,outputs:a}},y=async({inputs:t,context:e,operation:o,credentials:n,logger:r,getHttpClient:i=async()=>a.getInstance()})=>({inputs:t,fieldConfigs:[],context:e,operation:o,credentials:n,httpClient:await i(),logger:r}),m=({category:t,connectorKey:e,connectorVersion:o,authConfigKey:n,environment:r="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:e,connectorVersion:o,category:t,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:n,environment:r}),g=(t,e,o)=>{const n=o.toUpperCase();if(!t.operations)return;const r=Object.keys(t.operations),i=b(e,n,r);return i?{operation:t.operations?.[i.path],params:i.params}:void 0},h=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},b=(t,e,o)=>{const n=h(t);for(const t of o)if(t.startsWith(e)){const o=t.replace(`${e} `,"").trim(),r=c(h(o))(h(n));if(!1!==r)return{path:t,params:r.params}}},_=u.object({key:u.string(),label:u.string(),type:u.string(),required:u.boolean().optional(),secret:u.boolean().optional(),placeholder:u.string().optional(),description:u.string().optional(),tooltip:u.string().optional()}),f=u.object({operationId:u.string(),categories:u.string().array(),operationType:u.string(),schema:u.string().optional(),entrypointUrl:u.string().optional(),entrypointHttpMethod:u.string().optional(),description:u.string(),inputs:u.object({name:u.string(),type:u.string(),required:u.boolean(),description:u.string(),in:u.string()}).array().optional(),fieldConfigs:u.object({targetFieldKey:u.string(),expression:u.string(),type:u.enum(["string","number","boolean","datetime_string","enum"]),isUnified:u.boolean(),enumMapper:u.object({matcher:u.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(u.object({matchExpression:u.string(),value:u.string()}).array())}).optional()}).array().optional(),steps:u.object({stepId:u.string(),description:u.string(),stepFunction:u.object({functionName:u.string(),version:u.string().optional(),parameters:u.record(u.string(),u.unknown())}),condition:u.string().optional()}).array(),result:u.string()}),k=u.object({StackOne:u.string(),info:u.object({title:u.string(),version:u.string(),key:u.string(),description:u.string().optional()}),baseUrl:u.string(),authentication:u.record(u.string(),u.object({type:u.string(),label:u.string(),authorization:o,environments:u.object({key:u.string(),name:u.string()}).array(),support:u.object({link:u.string(),description:u.string().optional()}),configFields:_.array().optional(),setupFields:_.array().optional(),testOperationsIds:u.string().array().optional()})).array().optional(),operations:f.array().optional()});function v(t){try{const e=p(t),o=k.parse(e),n={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=F(o),s={baseUrl:o.baseUrl,authentication:I(i)},a=E(o,s);return n.operations=a,n.authentication=i,r(a)&&(n.categories=j(Object.values(a))),n}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const I=t=>{const e={};for(const[o,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:r,support:i,testOperationsIds:s,...a}=n;e[o]=I(a)}else e[o]=n;return e},j=t=>{const e=t.reduce(((t,e)=>{for(const o of e.categories)t.add(o);return t}),new Set);return Array.from(e)},F=t=>{const e={};for(const o of t.authentication??[]){const[t]=Object.keys(o),n=o[t].environments.reduce(((e,n)=>{const{key:r,name:i}=n,{environments:s,...a}=o[t];return e[r]={...a,envKey:r,envName:i},e}),{});e[t]=n}return e},E=(t,e)=>{const o=t.operations?.reduce(((t,o)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(o),r=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(o),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(o);return t[n??r]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",inputs:o.inputs,steps:o.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,condition:n.condition,stepFunction:{functionName:n.stepFunction.functionName,version:n.stepFunction.version,params:{..."request"===n.stepFunction.functionName?e:{},..."map_fields"===n.stepFunction.functionName||"typecast"===n.stepFunction.functionName?{fields:o.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:o.result},t}),{});return o},S=(t,e)=>{if(!t.inputs)return{};const o=w(t.inputs).parse(e);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},O=t=>{const e={};return t.forEach((t=>{let o;switch(t.type.toLowerCase()){case"string":o=u.string();break;case"number":o=u.number();break;case"boolean":o=u.boolean();break;default:o=u.any()}e[t.name]=t.required?o:o.optional()})),u.object(e)},w=t=>{const e=t.filter((t=>"path"===t.in)),o=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),r=t.filter((t=>"headers"===t.in));return u.object({path:O(e).optional(),query:O(o).optional(),body:O(n).optional(),headers:O(r).optional()})};class T extends Error{constructor(t,e,o){super(o),this.name="ConnectSDKError",this.errorType=t,this.context=e,Error.captureStackTrace&&Error.captureStackTrace(this,T)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class N extends T{constructor(t,e){super("CONNECTOR_PARSE_ERROR",t,e),this.name="ConnectorParseError"}}class C extends T{constructor(t,e){super("MISSING_OPERATION_ERROR",t,e),this.name="MissingOperationError"}}class x extends T{constructor(t,e){super("INVALID_OPERATION_INPUTS_ERROR",t,e),this.name="InvalidOperationInputsError"}}const R=async({account:t,connector:e,category:o,path:n,method:r="get",queryParams:a,body:c,headers:p,logger:u,parseConnector:l=v,getOperationFromUrlFn:h=g,parseOperationInputsFn:b=S,createBlockContextFn:_=m,createBlockFn:f=y,runStepOperationFn:k=d})=>{const I=t.authConfigKey,j=t.environment??"production",F=t.secureId,E=t.projectSecureId,O=t.credentials,w=_({category:o,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:I,environment:j,accountSecureId:F,projectSecureId:E});let T;try{T=i(e)?l(e):e}catch{throw new N(w,"Error while parsing connector")}const R=h(T,n,r);if(s(R))throw new C(w,"No matching operation found");let U;w.operationType=R.operation.operationType,w.schema=R.operation.schema?.key;try{U=b(R.operation,{query:a,body:c,headers:p,path:R.params})}catch{throw new x(w,"Error while parsing operation inputs")}const M=await f({inputs:U,context:w,operation:R.operation,credentials:O,logger:u});return await k({block:M})};export{T as ConnectSDKError,y as createBlock,l as executeStepFunction,g as getOperationFromUrl,S as parseOperationInputs,v as parseYamlConnector,R as runConnectorOperation,d as runStepOperation};
1
+ import{StepFunctionsFactory as t,StepFunctionName as e,AUTHENTICATION_SCHEMA as o}from"@stackone/core";import{safeEvaluate as n}from"@stackone/expressions";import{notMissing as r,isString as i,isMissing as s}from"@stackone/utils";import{HttpClientManager as a}from"@stackone/transport";import{match as c}from"path-to-regexp";import{parse as p}from"yaml";import{z as u}from"zod";const l=async({block:o,stepFunctionName:n,params:r,buildStepFunction:i=t.build})=>{const s=i({functionName:n}).fn,a=await s({block:o,params:r}),c=n===e.MAP_FIELDS?{[e.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...c}}},d=async({block:e,buildStepFunction:o=t.build})=>{const r=e.operation?.steps||[];let i={...e};const s=Object.keys(r);let a=!1;for(const t of s){const e=r[t],s=e.stepFunction,c=o({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(e.condition&&!n(e.condition,i)){i=y({block:i,stepId:t,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(a){i=y({block:i,stepId:t,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const p=await c({block:i,params:s.params});if(!1===p.successful){i=y({block:i,stepId:t,successful:!1,functionOutput:p});(e.ignoreError??!1)||(a=!0)}else i=y({block:p.block,stepId:t,functionOutput:p})}const c=e.operation?.result?n(e.operation.result,i):void 0;return{...i,outputs:c}},y=({block:t,stepId:e,successful:o,functionOutput:n,skipped:r,message:i})=>({...t,steps:{...t.steps,[e]:{successful:o??n?.successful??!1,errors:n?.errors,output:n?.output,skipped:r,message:i}}}),m=async({inputs:t,context:e,operation:o,credentials:n,logger:r,getHttpClient:i=async()=>a.getInstance()})=>({inputs:t,fieldConfigs:[],context:e,operation:o,credentials:n,httpClient:await i(),logger:r}),g=({category:t,connectorKey:e,connectorVersion:o,authConfigKey:n,environment:r="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:e,connectorVersion:o,category:t,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:n,environment:r}),b=(t,e,o)=>{const n=o.toUpperCase();if(!t.operations)return;const r=Object.keys(t.operations),i=_(e,n,r);return i?{operation:t.operations?.[i.path],params:i.params}:void 0},h=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},_=(t,e,o)=>{const n=h(t);for(const t of o)if(t.startsWith(e)){const o=t.replace(`${e} `,"").trim(),r=c(h(o))(h(n));if(!1!==r)return{path:t,params:r.params}}},f=u.object({key:u.string(),label:u.string(),type:u.string(),required:u.boolean().optional(),secret:u.boolean().optional(),placeholder:u.string().optional(),description:u.string().optional(),tooltip:u.string().optional()}),k=u.object({operationId:u.string(),categories:u.string().array(),operationType:u.string(),schema:u.string().optional(),entrypointUrl:u.string().optional(),entrypointHttpMethod:u.string().optional(),description:u.string(),inputs:u.object({name:u.string(),type:u.string(),required:u.boolean(),description:u.string(),in:u.string()}).array().optional(),fieldConfigs:u.object({targetFieldKey:u.string(),expression:u.string(),type:u.enum(["string","number","boolean","datetime_string","enum"]),isUnified:u.boolean(),enumMapper:u.object({matcher:u.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(u.object({matchExpression:u.string(),value:u.string()}).array())}).optional()}).array().optional(),steps:u.object({stepId:u.string(),description:u.string(),stepFunction:u.object({functionName:u.string(),version:u.string().optional(),parameters:u.record(u.string(),u.unknown())}),condition:u.string().optional(),ignoreError:u.boolean().optional()}).array(),result:u.string()}),v=u.object({StackOne:u.string(),info:u.object({title:u.string(),version:u.string(),key:u.string(),description:u.string().optional()}),baseUrl:u.string(),authentication:u.record(u.string(),u.object({type:u.string(),label:u.string(),authorization:o,environments:u.object({key:u.string(),name:u.string()}).array(),support:u.object({link:u.string(),description:u.string().optional()}),configFields:f.array().optional(),setupFields:f.array().optional(),testOperationsIds:u.string().array().optional()})).array().optional(),operations:k.array().optional()});function I(t){try{const e=p(t),o=v.parse(e),n={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=j(o),s={baseUrl:o.baseUrl,authentication:E(i)},a=F(o,s);return n.operations=a,n.authentication=i,r(a)&&(n.categories=S(Object.values(a))),n}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const E=t=>{const e={};for(const[o,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:r,support:i,testOperationsIds:s,...a}=n;e[o]=E(a)}else e[o]=n;return e},S=t=>{const e=t.reduce(((t,e)=>{for(const o of e.categories)t.add(o);return t}),new Set);return Array.from(e)},j=t=>{const e={};for(const o of t.authentication??[]){const[t]=Object.keys(o),n=o[t].environments.reduce(((e,n)=>{const{key:r,name:i}=n,{environments:s,...a}=o[t];return e[r]={...a,envKey:r,envName:i},e}),{});e[t]=n}return e},F=(t,e)=>{const o=t.operations?.reduce(((t,o)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(o),r=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(o),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(o);return t[n??r]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",inputs:o.inputs,steps:o.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,condition:n.condition,ignoreError:n.ignoreError,stepFunction:{functionName:n.stepFunction.functionName,version:n.stepFunction.version,params:{..."request"===n.stepFunction.functionName?e:{},..."map_fields"===n.stepFunction.functionName||"typecast"===n.stepFunction.functionName?{fields:o.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:o.result},t}),{});return o},O=(t,e)=>{if(!t.inputs)return{};const o=T(t.inputs).parse(e);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},w=t=>{const e={};return t.forEach((t=>{let o;switch(t.type.toLowerCase()){case"string":o=u.string();break;case"number":o=u.number();break;case"boolean":o=u.boolean();break;default:o=u.any()}e[t.name]=t.required?o:o.optional()})),u.object(e)},T=t=>{const e=t.filter((t=>"path"===t.in)),o=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),r=t.filter((t=>"headers"===t.in));return u.object({path:w(e).optional(),query:w(o).optional(),body:w(n).optional(),headers:w(r).optional()})};class N extends Error{constructor(t,e,o){super(o),this.name="ConnectSDKError",this.errorType=t,this.context=e,Error.captureStackTrace&&Error.captureStackTrace(this,N)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class C extends N{constructor(t,e){super("CONNECTOR_PARSE_ERROR",t,e),this.name="ConnectorParseError"}}class x extends N{constructor(t,e){super("MISSING_OPERATION_ERROR",t,e),this.name="MissingOperationError"}}class R extends N{constructor(t,e){super("INVALID_OPERATION_INPUTS_ERROR",t,e),this.name="InvalidOperationInputsError"}}const U=async({account:t,connector:e,category:o,path:n,method:r="get",queryParams:a,body:c,headers:p,logger:u,parseConnector:l=I,getOperationFromUrlFn:y=b,parseOperationInputsFn:h=O,createBlockContextFn:_=g,createBlockFn:f=m,runStepOperationFn:k=d})=>{const v=t.authConfigKey,E=t.environment??"production",S=t.secureId,j=t.projectSecureId,F=t.credentials,w=_({category:o,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:v,environment:E,accountSecureId:S,projectSecureId:j});let T;try{T=i(e)?l(e):e}catch{throw new C(w,"Error while parsing connector")}const N=y(T,n,r);if(s(N))throw new x(w,"No matching operation found");let U;w.operationType=N.operation.operationType,w.schema=N.operation.schema?.key;try{U=h(N.operation,{query:a,body:c,headers:p,path:N.params})}catch{throw new R(w,"Error while parsing operation inputs")}const M=await f({inputs:U,context:w,operation:N.operation,credentials:F,logger:u});return await k({block:M})};export{N as ConnectSDKError,m as createBlock,l as executeStepFunction,b as getOperationFromUrl,O as parseOperationInputs,I as parseYamlConnector,U as runConnectorOperation,d as runStepOperation};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@stackone/core"),e=require("@stackone/expressions"),o=require("@stackone/utils"),n=require("@stackone/transport"),r=require("path-to-regexp"),i=require("yaml"),s=require("zod");const a=async({block:o,buildStepFunction:n=t.StepFunctionsFactory.build})=>{const r=o.operation?.steps||[];let i={...o};const s=Object.keys(r);for(const t of s){const o=r[t],s=o.stepFunction,a=n({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(o.condition&&!e.safeEvaluate(o.condition,i)){i={...i,steps:{...i.steps,[t]:{successful:!0,skipped:!0}}};continue}const c=await a({block:i,params:s.params});i={...c.block,steps:{...c.block.steps,[t]:{successful:c.successful,errors:c.errors,output:c.output}}}}const a=o.operation?.result?e.safeEvaluate(o.operation.result,i):void 0;return{...i,outputs:a}},c=async({inputs:t,context:e,operation:o,credentials:r,logger:i,getHttpClient:s=async()=>n.HttpClientManager.getInstance()})=>({inputs:t,fieldConfigs:[],context:e,operation:o,credentials:r,httpClient:await s(),logger:i}),p=({category:t,connectorKey:e,connectorVersion:o,authConfigKey:n,environment:r="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:e,connectorVersion:o,category:t,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:n,environment:r}),u=(t,e,o)=>{const n=o.toUpperCase();if(!t.operations)return;const r=Object.keys(t.operations),i=d(e,n,r);return i?{operation:t.operations?.[i.path],params:i.params}:void 0},l=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},d=(t,e,o)=>{const n=l(t);for(const t of o)if(t.startsWith(e)){const o=t.replace(`${e} `,"").trim(),i=r.match(l(o))(l(n));if(!1!==i)return{path:t,params:i.params}}},y=s.z.object({key:s.z.string(),label:s.z.string(),type:s.z.string(),required:s.z.boolean().optional(),secret:s.z.boolean().optional(),placeholder:s.z.string().optional(),description:s.z.string().optional(),tooltip:s.z.string().optional()}),g=s.z.object({operationId:s.z.string(),categories:s.z.string().array(),operationType:s.z.string(),schema:s.z.string().optional(),entrypointUrl:s.z.string().optional(),entrypointHttpMethod:s.z.string().optional(),description:s.z.string(),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(),fieldConfigs:s.z.object({targetFieldKey:s.z.string(),expression:s.z.string(),type:s.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:s.z.boolean(),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()}).array(),result:s.z.string()}),h=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:t.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 m(t){try{const e=i.parse(t),n=h.parse(e),r={title:n.info.title,version:n.info.version,key:n.info.key,description:n.info.description},s=z(n),a={baseUrl:n.baseUrl,authentication:_(s)},c=f(n,a);return r.operations=c,r.authentication=s,o.notMissing(c)&&(r.categories=b(Object.values(c))),r}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const _=t=>{const e={};for(const[o,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:r,support:i,testOperationsIds:s,...a}=n;e[o]=_(a)}else e[o]=n;return e},b=t=>{const e=t.reduce(((t,e)=>{for(const o of e.categories)t.add(o);return t}),new Set);return Array.from(e)},z=t=>{const e={};for(const o of t.authentication??[]){const[t]=Object.keys(o),n=o[t].environments.reduce(((e,n)=>{const{key:r,name:i}=n,{environments:s,...a}=o[t];return e[r]={...a,envKey:r,envName:i},e}),{});e[t]=n}return e},f=(t,e)=>{const o=t.operations?.reduce(((t,o)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(o),r=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(o),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(o);return t[n??r]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",inputs:o.inputs,steps:o.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,condition:n.condition,stepFunction:{functionName:n.stepFunction.functionName,version:n.stepFunction.version,params:{..."request"===n.stepFunction.functionName?e:{},..."map_fields"===n.stepFunction.functionName||"typecast"===n.stepFunction.functionName?{fields:o.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:o.result},t}),{});return o},k=(t,e)=>{if(!t.inputs)return{};const o=F(t.inputs).parse(e);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},v=t=>{const e={};return t.forEach((t=>{let o;switch(t.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()}e[t.name]=t.required?o:o.optional()})),s.z.object(e)},F=t=>{const e=t.filter((t=>"path"===t.in)),o=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),r=t.filter((t=>"headers"===t.in));return s.z.object({path:v(e).optional(),query:v(o).optional(),body:v(n).optional(),headers:v(r).optional()})};class S extends Error{constructor(t,e,o){super(o),this.name="ConnectSDKError",this.errorType=t,this.context=e,Error.captureStackTrace&&Error.captureStackTrace(this,S)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class I extends S{constructor(t,e){super("CONNECTOR_PARSE_ERROR",t,e),this.name="ConnectorParseError"}}class E extends S{constructor(t,e){super("MISSING_OPERATION_ERROR",t,e),this.name="MissingOperationError"}}class O extends S{constructor(t,e){super("INVALID_OPERATION_INPUTS_ERROR",t,e),this.name="InvalidOperationInputsError"}}exports.ConnectSDKError=S,exports.createBlock=c,exports.executeStepFunction=async({block:e,stepFunctionName:o,params:n,buildStepFunction:r=t.StepFunctionsFactory.build})=>{const i=r({functionName:o}).fn,s=await i({block:e,params:n}),a=o===t.StepFunctionName.MAP_FIELDS?{[t.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:s.block.result},errors:s.errors,successful:s.successful}}:{};return{...s.block,steps:{...s?.block?.steps??{},...a}}},exports.getOperationFromUrl=u,exports.parseOperationInputs=k,exports.parseYamlConnector=m,exports.runConnectorOperation=async({account:t,connector:e,category:n,path:r,method:i="get",queryParams:s,body:l,headers:d,logger:y,parseConnector:g=m,getOperationFromUrlFn:h=u,parseOperationInputsFn:_=k,createBlockContextFn:b=p,createBlockFn:z=c,runStepOperationFn:f=a})=>{const v=t.authConfigKey,F=t.environment??"production",S=t.secureId,j=t.projectSecureId,C=t.credentials,N=b({category:n,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:v,environment:F,accountSecureId:S,projectSecureId:j});let T;try{T=o.isString(e)?g(e):e}catch{throw new I(N,"Error while parsing connector")}const x=h(T,r,i);if(o.isMissing(x))throw new E(N,"No matching operation found");let w;N.operationType=x.operation.operationType,N.schema=x.operation.schema?.key;try{w=_(x.operation,{query:s,body:l,headers:d,path:x.params})}catch{throw new O(N,"Error while parsing operation inputs")}const q=await z({inputs:w,context:N,operation:x.operation,credentials:C,logger:y});return await f({block:q})},exports.runStepOperation=a;
1
+ "use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/utils"),n=require("@stackone/transport"),r=require("path-to-regexp"),i=require("yaml"),s=require("zod");const a=async({block:o,buildStepFunction:n=e.StepFunctionsFactory.build})=>{const r=o.operation?.steps||[];let i={...o};const s=Object.keys(r);let a=!1;for(const e of s){const o=r[e],s=o.stepFunction,p=n({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(o.condition&&!t.safeEvaluate(o.condition,i)){i=c({block:i,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(a){i=c({block:i,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=await p({block:i,params:s.params});if(!1===u.successful){i=c({block:i,stepId:e,successful:!1,functionOutput:u});(o.ignoreError??!1)||(a=!0)}else i=c({block:u.block,stepId:e,functionOutput:u})}const p=o.operation?.result?t.safeEvaluate(o.operation.result,i):void 0;return{...i,outputs:p}},c=({block:e,stepId:t,successful:o,functionOutput:n,skipped:r,message:i})=>({...e,steps:{...e.steps,[t]:{successful:o??n?.successful??!1,errors:n?.errors,output:n?.output,skipped:r,message:i}}}),p=async({inputs:e,context:t,operation:o,credentials:r,logger:i,getHttpClient:s=async()=>n.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,httpClient:await s(),logger:i}),u=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:n,environment:r="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:n,environment:r}),l=(e,t,o)=>{const n=o.toUpperCase();if(!e.operations)return;const r=Object.keys(e.operations),i=y(t,n,r);return i?{operation:e.operations?.[i.path],params:i.params}:void 0},d=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},y=(e,t,o)=>{const n=d(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),i=r.match(d(o))(d(n));if(!1!==i)return{path:e,params:i.params}}},g=s.z.object({key:s.z.string(),label:s.z.string(),type:s.z.string(),required:s.z.boolean().optional(),secret:s.z.boolean().optional(),placeholder:s.z.string().optional(),description:s.z.string().optional(),tooltip:s.z.string().optional()}),m=s.z.object({operationId:s.z.string(),categories:s.z.string().array(),operationType:s.z.string(),schema:s.z.string().optional(),entrypointUrl:s.z.string().optional(),entrypointHttpMethod:s.z.string().optional(),description:s.z.string(),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(),fieldConfigs:s.z.object({targetFieldKey:s.z.string(),expression:s.z.string(),type:s.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:s.z.boolean(),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()}),b=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:e.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:g.array().optional(),setupFields:g.array().optional(),testOperationsIds:s.z.string().array().optional()})).array().optional(),operations:m.array().optional()});function h(e){try{const t=i.parse(e),n=b.parse(t),r={title:n.info.title,version:n.info.version,key:n.info.key,description:n.info.description},s=z(n),a={baseUrl:n.baseUrl,authentication:_(s)},c=k(n,a);return r.operations=c,r.authentication=s,o.notMissing(c)&&(r.categories=f(Object.values(c))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const _=e=>{const t={};for(const[o,n]of Object.entries(e))if(n&&"object"==typeof n){const{setupFields:e,configFields:r,support:i,testOperationsIds:s,...a}=n;t[o]=_(a)}else t[o]=n;return t},f=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),n=o[e].environments.reduce(((t,n)=>{const{key:r,name:i}=n,{environments:s,...a}=o[e];return t[r]={...a,envKey:r,envName:i},t}),{});t[e]=n}return t},k=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),r=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o);return e[n??r]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",inputs:o.inputs,steps:o.steps.reduce(((e,n)=>(e[n.stepId]={id:n.stepId,description:n.description,condition:n.condition,ignoreError:n.ignoreError,stepFunction:{functionName:n.stepFunction.functionName,version:n.stepFunction.version,params:{..."request"===n.stepFunction.functionName?t:{},..."map_fields"===n.stepFunction.functionName||"typecast"===n.stepFunction.functionName?{fields:o.fieldConfigs}:{},...n.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},v=(e,t)=>{if(!e.inputs)return{};const o=S(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},I=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)},S=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),n=e.filter((e=>"body"===e.in)),r=e.filter((e=>"headers"===e.in));return s.z.object({path:I(t).optional(),query:I(o).optional(),body:I(n).optional(),headers:I(r).optional()})};class E extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,E)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class F extends E{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class O extends E{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class j extends E{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}exports.ConnectSDKError=E,exports.createBlock=p,exports.executeStepFunction=async({block:t,stepFunctionName:o,params:n,buildStepFunction:r=e.StepFunctionsFactory.build})=>{const i=r({functionName:o}).fn,s=await i({block:t,params:n}),a=o===e.StepFunctionName.MAP_FIELDS?{[e.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:s.block.result},errors:s.errors,successful:s.successful}}:{};return{...s.block,steps:{...s?.block?.steps??{},...a}}},exports.getOperationFromUrl=l,exports.parseOperationInputs=v,exports.parseYamlConnector=h,exports.runConnectorOperation=async({account:e,connector:t,category:n,path:r,method:i="get",queryParams:s,body:c,headers:d,logger:y,parseConnector:g=h,getOperationFromUrlFn:m=l,parseOperationInputsFn:b=v,createBlockContextFn:_=u,createBlockFn:f=p,runStepOperationFn:z=a})=>{const k=e.authConfigKey,I=e.environment??"production",S=e.secureId,E=e.projectSecureId,C=e.credentials,N=_({category:n,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:k,environment:I,accountSecureId:S,projectSecureId:E});let T;try{T=o.isString(t)?g(t):t}catch{throw new F(N,"Error while parsing connector")}const x=m(T,r,i);if(o.isMissing(x))throw new O(N,"No matching operation found");let w;N.operationType=x.operation.operationType,N.schema=x.operation.schema?.key;try{w=b(x.operation,{query:s,body:c,headers:d,path:x.params})}catch{throw new j(N,"Error while parsing operation inputs")}const q=await f({inputs:w,context:N,operation:x.operation,credentials:C,logger:y});return await z({block:q})},exports.runStepOperation=a;
@@ -93,6 +93,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
93
93
  version?: string | undefined;
94
94
  }>;
95
95
  condition: z.ZodOptional<z.ZodString>;
96
+ ignoreError: z.ZodOptional<z.ZodBoolean>;
96
97
  }, "strip", z.ZodTypeAny, {
97
98
  description: string;
98
99
  stepId: string;
@@ -102,6 +103,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
102
103
  version?: string | undefined;
103
104
  };
104
105
  condition?: string | undefined;
106
+ ignoreError?: boolean | undefined;
105
107
  }, {
106
108
  description: string;
107
109
  stepId: string;
@@ -111,6 +113,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
111
113
  version?: string | undefined;
112
114
  };
113
115
  condition?: string | undefined;
116
+ ignoreError?: boolean | undefined;
114
117
  }>, "many">;
115
118
  result: z.ZodString;
116
119
  }, "strip", z.ZodTypeAny, {
@@ -127,6 +130,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
127
130
  version?: string | undefined;
128
131
  };
129
132
  condition?: string | undefined;
133
+ ignoreError?: boolean | undefined;
130
134
  }[];
131
135
  result: string;
132
136
  schema?: string | undefined;
@@ -165,6 +169,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
165
169
  version?: string | undefined;
166
170
  };
167
171
  condition?: string | undefined;
172
+ ignoreError?: boolean | undefined;
168
173
  }[];
169
174
  result: string;
170
175
  schema?: string | undefined;
@@ -491,6 +496,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
491
496
  version?: string | undefined;
492
497
  }>;
493
498
  condition: z.ZodOptional<z.ZodString>;
499
+ ignoreError: z.ZodOptional<z.ZodBoolean>;
494
500
  }, "strip", z.ZodTypeAny, {
495
501
  description: string;
496
502
  stepId: string;
@@ -500,6 +506,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
500
506
  version?: string | undefined;
501
507
  };
502
508
  condition?: string | undefined;
509
+ ignoreError?: boolean | undefined;
503
510
  }, {
504
511
  description: string;
505
512
  stepId: string;
@@ -509,6 +516,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
509
516
  version?: string | undefined;
510
517
  };
511
518
  condition?: string | undefined;
519
+ ignoreError?: boolean | undefined;
512
520
  }>, "many">;
513
521
  result: z.ZodString;
514
522
  }, "strip", z.ZodTypeAny, {
@@ -525,6 +533,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
525
533
  version?: string | undefined;
526
534
  };
527
535
  condition?: string | undefined;
536
+ ignoreError?: boolean | undefined;
528
537
  }[];
529
538
  result: string;
530
539
  schema?: string | undefined;
@@ -563,6 +572,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
563
572
  version?: string | undefined;
564
573
  };
565
574
  condition?: string | undefined;
575
+ ignoreError?: boolean | undefined;
566
576
  }[];
567
577
  result: string;
568
578
  schema?: string | undefined;
@@ -653,6 +663,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
653
663
  version?: string | undefined;
654
664
  };
655
665
  condition?: string | undefined;
666
+ ignoreError?: boolean | undefined;
656
667
  }[];
657
668
  result: string;
658
669
  schema?: string | undefined;
@@ -743,6 +754,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
743
754
  version?: string | undefined;
744
755
  };
745
756
  condition?: string | undefined;
757
+ ignoreError?: boolean | undefined;
746
758
  }[];
747
759
  result: string;
748
760
  schema?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/connect-sdk",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",