@stackone/connect-sdk 1.12.2 → 1.14.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 r}from"@stackone/core";import{safeEvaluate as n}from"@stackone/expressions";import{notMissing as o,isString as s,isMissing as i}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:r,stepFunctionName:n,params:o,buildStepFunction:s=t.build})=>{const i=s({functionName:n}).fn,a=await i({block:r,params:o}),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:r=t.build})=>{const o=e.operation?.steps||[];let s={...e};const i=Object.keys(o);for(const t of i){const e=o[t].stepFunction,n=r({functionName:e.functionName,version:e.version,validateSchemas:!0}).fn,i=await n({block:s,params:e.params});s={...i.block,steps:{...i.block.steps,[t]:{successful:i.successful,errors:i.errors,output:i.output}}}}const a=e.operation?.result?n(e.operation.result,s):void 0;return{...s,outputs:a}},g=async({inputs:t,category:e,connectorKey:r,connectorVersion:n,authConfigKey:o,environment:s="production",operation:i,accountSecureId:c,projectSecureId:p,credentials:u,logger:l,getHttpClient:d=async()=>a.getInstance()})=>{const g=await d();return{inputs:t,fieldConfigs:[],context:{projectSecureId:p,accountSecureId:c,connectorKey:r,connectorVersion:n,category:e,schema:i.schema?.key,service:"",resource:"",operationType:i.operationType,authenticationType:o,environment:s},operation:i,credentials:u,httpClient:g,logger:l}},y=(t,e,r)=>{const n=r.toUpperCase();if(!t.operations)return;const o=Object.keys(t.operations),s=f(e,n,o);return s?{operation:t.operations?.[s.path],params:s.params}:void 0},m=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},f=(t,e,r)=>{const n=m(t);for(const t of r)if(t.startsWith(e)){const r=t.replace(`${e} `,"").trim(),o=c(m(r))(m(n));if(!1!==o)return{path:t,params:o.params}}},h=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()}),b=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.string(),isUnified:u.boolean()}).array(),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())})}).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:r,environments:u.object({key:u.string(),name:u.string()}).array(),support:u.object({link:u.string(),description:u.string().optional()}),configFields:h.array().optional(),setupFields:h.array().optional(),testOperationsIds:u.string().array().optional()})).array().optional(),operations:b.array().optional()});function I(t){try{const e=p(t),r=k.parse(e),n={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},s=S(r),i={baseUrl:r.baseUrl,authentication:v(s)},a=j(r,i);return n.operations=a,n.authentication=s,o(a)&&(n.categories=F(Object.values(a))),n}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const v=t=>{const e={};for(const[r,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:o,support:s,testOperationsIds:i,...a}=n;e[r]=v(a)}else e[r]=n;return e},F=t=>{const e=t.reduce(((t,e)=>{for(const r of e.categories)t.add(r);return t}),new Set);return Array.from(e)},S=t=>{const e={};for(const r of t.authentication??[]){const[t]=Object.keys(r),n=r[t].environments.reduce(((e,n)=>{const{key:o,name:s}=n,{environments:i,...a}=r[t];return e[o]={...a,envKey:o,envName:s},e}),{});e[t]=n}return e},j=(t,e)=>{const r=t.operations?.reduce(((t,r)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(r),o=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(r),s=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(r);return t[n??o]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??s,entrypointHttpMethod:r.entrypointHttpMethod??"get",inputs:r.inputs,steps:r.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,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:r.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:r.result},t}),{});return r},E=(t,e)=>{if(!t.inputs)return{};const r=w(t.inputs).parse(e);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},O=t=>{const e={};return t.forEach((t=>{let r;switch(t.type.toLowerCase()){case"string":r=u.string();break;case"number":r=u.number();break;case"boolean":r=u.boolean();break;default:r=u.any()}e[t.name]=t.required?r:r.optional()})),u.object(e)},w=t=>{const e=t.filter((t=>"path"===t.in)),r=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),o=t.filter((t=>"headers"===t.in));return u.object({path:O(e).optional(),query:O(r).optional(),body:O(n).optional(),headers:O(o).optional()})};class N extends Error{constructor(t,e){super(e),this.name="ConnectSDKError",this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,N)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class T extends N{constructor(t){super("CONNECTOR_PARSE_ERROR",t),this.name="ConnectorParseError"}}class C extends N{constructor(t){super("MISSING_OPERATION_ERROR",t),this.name="MissingOperationError"}}class R extends N{constructor(t){super("INVALID_OPERATION_INPUTS_ERROR",t),this.name="InvalidOperationInputsError"}}const U=async({account:t,connector:e,category:r,path:n,method:o="get",queryParams:a,logger:c,parseConnector:p=I,getOperationFromUrlFn:u=y,parseOperationInputsFn:l=E,createBlockFn:m=g,runStepOperationFn:f=d})=>{const h=t.authConfigKey,b=t.environment??"production",k=t.secureId,v=t.projectSecureId,F=t.credentials;let S;try{S=s(e)?p(e):e}catch{throw new T("Error while parsing connector")}const j=u(S,n,o);if(i(j))throw new C("No matching operation found");let O;try{O=l(j.operation,{query:a,path:j.params})}catch{throw new R("Error while parsing operation inputs")}const w=await m({inputs:O,category:r,connectorKey:S.key,connectorVersion:S.version,authConfigKey:h,environment:b,operation:j.operation,accountSecureId:k,projectSecureId:v,credentials:F,logger:c});return await f({block:w})};export{N as ConnectSDKError,g as createBlock,l as executeStepFunction,y as getOperationFromUrl,E as parseOperationInputs,I as parseYamlConnector,U as runConnectorOperation,d as runStepOperation};
1
+ import{StepFunctionsFactory as t,StepFunctionName as e,AUTHENTICATION_SCHEMA as r}from"@stackone/core";import{safeEvaluate as o}from"@stackone/expressions";import{notMissing as n,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:r,stepFunctionName:o,params:n,buildStepFunction:i=t.build})=>{const s=i({functionName:o}).fn,a=await s({block:r,params:n}),c=o===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:r=t.build})=>{const n=e.operation?.steps||[];let i={...e};const s=Object.keys(n);for(const t of s){const e=n[t].stepFunction,o=r({functionName:e.functionName,version:e.version,validateSchemas:!0}).fn,s=await o({block:i,params:e.params});i={...s.block,steps:{...s.block.steps,[t]:{successful:s.successful,errors:s.errors,output:s.output}}}}const a=e.operation?.result?o(e.operation.result,i):void 0;return{...i,outputs:a}},g=async({inputs:t,context:e,operation:r,credentials:o,logger:n,getHttpClient:i=async()=>a.getInstance()})=>({inputs:t,fieldConfigs:[],context:e,operation:r,credentials:o,httpClient:await i(),logger:n}),y=({category:t,connectorKey:e,connectorVersion:r,authConfigKey:o,environment:n="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:e,connectorVersion:r,category:t,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:o,environment:n}),m=(t,e,r)=>{const o=r.toUpperCase();if(!t.operations)return;const n=Object.keys(t.operations),i=h(e,o,n);return i?{operation:t.operations?.[i.path],params:i.params}:void 0},f=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},h=(t,e,r)=>{const o=f(t);for(const t of r)if(t.startsWith(e)){const r=t.replace(`${e} `,"").trim(),n=c(f(r))(f(o));if(!1!==n)return{path:t,params:n.params}}},b=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.string().or(u.object({matchExpression:u.string(),value:u.string()}).array())}).optional()}).array(),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())})}).array(),result:u.string()}),I=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:r,environments:u.object({key:u.string(),name:u.string()}).array(),support:u.object({link:u.string(),description:u.string().optional()}),configFields:b.array().optional(),setupFields:b.array().optional(),testOperationsIds:u.string().array().optional()})).array().optional(),operations:k.array().optional()});function v(t){try{const e=p(t),r=I.parse(e),o={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},i=E(r),s={baseUrl:r.baseUrl,authentication:j(i)},a=S(r,s);return o.operations=a,o.authentication=i,n(a)&&(o.categories=F(Object.values(a))),o}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const j=t=>{const e={};for(const[r,o]of Object.entries(t))if(o&&"object"==typeof o){const{setupFields:t,configFields:n,support:i,testOperationsIds:s,...a}=o;e[r]=j(a)}else e[r]=o;return e},F=t=>{const e=t.reduce(((t,e)=>{for(const r of e.categories)t.add(r);return t}),new Set);return Array.from(e)},E=t=>{const e={};for(const r of t.authentication??[]){const[t]=Object.keys(r),o=r[t].environments.reduce(((e,o)=>{const{key:n,name:i}=o,{environments:s,...a}=r[t];return e[n]={...a,envKey:n,envName:i},e}),{});e[t]=o}return e},S=(t,e)=>{const r=t.operations?.reduce(((t,r)=>{const o=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(r),n=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(r),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(r);return t[o??n]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",inputs:r.inputs,steps:r.steps.reduce(((t,o)=>(t[o.stepId]={id:o.stepId,description:o.description,stepFunction:{functionName:o.stepFunction.functionName,version:o.stepFunction.version,params:{..."request"===o.stepFunction.functionName?e:{},..."map_fields"===o.stepFunction.functionName||"typecast"===o.stepFunction.functionName?{fields:r.fieldConfigs}:{},...o.stepFunction.parameters}}},t)),{}),result:r.result},t}),{});return r},O=(t,e)=>{if(!t.inputs)return{};const r=T(t.inputs).parse(e);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},w=t=>{const e={};return t.forEach((t=>{let r;switch(t.type.toLowerCase()){case"string":r=u.string();break;case"number":r=u.number();break;case"boolean":r=u.boolean();break;default:r=u.any()}e[t.name]=t.required?r:r.optional()})),u.object(e)},T=t=>{const e=t.filter((t=>"path"===t.in)),r=t.filter((t=>"query"===t.in)),o=t.filter((t=>"body"===t.in)),n=t.filter((t=>"headers"===t.in));return u.object({path:w(e).optional(),query:w(r).optional(),body:w(o).optional(),headers:w(n).optional()})};class N extends Error{constructor(t,e,r){super(r),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:r,path:o,method:n="get",queryParams:a,logger:c,parseConnector:p=v,getOperationFromUrlFn:u=m,parseOperationInputsFn:l=O,createBlockContextFn:f=y,createBlockFn:h=g,runStepOperationFn:b=d})=>{const k=t.authConfigKey,I=t.environment??"production",j=t.secureId,F=t.projectSecureId,E=t.credentials,S=f({category:r,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:k,environment:I,accountSecureId:j,projectSecureId:F});let w;try{w=i(e)?p(e):e}catch{throw new C(S,"Error while parsing connector")}const T=u(w,o,n);if(s(T))throw new x(S,"No matching operation found");let N;S.operationType=T.operation.operationType,S.schema=T.operation.schema?.key;try{N=l(T.operation,{query:a,path:T.params})}catch{throw new R(S,"Error while parsing operation inputs")}const U=await h({inputs:N,context:S,operation:T.operation,credentials:E,logger:c});return await b({block:U})};export{N as ConnectSDKError,g as createBlock,l as executeStepFunction,m as getOperationFromUrl,O as parseOperationInputs,v 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"),r=require("@stackone/utils"),n=require("@stackone/transport"),o=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=async({block:r,buildStepFunction:n=t.StepFunctionsFactory.build})=>{const o=r.operation?.steps||[];let s={...r};const i=Object.keys(o);for(const t of i){const e=o[t].stepFunction,r=n({functionName:e.functionName,version:e.version,validateSchemas:!0}).fn,i=await r({block:s,params:e.params});s={...i.block,steps:{...i.block.steps,[t]:{successful:i.successful,errors:i.errors,output:i.output}}}}const a=r.operation?.result?e.safeEvaluate(r.operation.result,s):void 0;return{...s,outputs:a}},c=async({inputs:t,category:e,connectorKey:r,connectorVersion:o,authConfigKey:s,environment:i="production",operation:a,accountSecureId:c,projectSecureId:p,credentials:u,logger:l,getHttpClient:d=async()=>n.HttpClientManager.getInstance()})=>{const g=await d();return{inputs:t,fieldConfigs:[],context:{projectSecureId:p,accountSecureId:c,connectorKey:r,connectorVersion:o,category:e,schema:a.schema?.key,service:"",resource:"",operationType:a.operationType,authenticationType:s,environment:i},operation:a,credentials:u,httpClient:g,logger:l}},p=(t,e,r)=>{const n=r.toUpperCase();if(!t.operations)return;const o=Object.keys(t.operations),s=l(e,n,o);return s?{operation:t.operations?.[s.path],params:s.params}:void 0},u=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},l=(t,e,r)=>{const n=u(t);for(const t of r)if(t.startsWith(e)){const r=t.replace(`${e} `,"").trim(),s=o.match(u(r))(u(n));if(!1!==s)return{path:t,params:s.params}}},d=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()}),g=i.z.object({operationId:i.z.string(),categories:i.z.string().array(),operationType:i.z.string(),schema:i.z.string().optional(),entrypointUrl:i.z.string().optional(),entrypointHttpMethod:i.z.string().optional(),description:i.z.string(),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.string(),isUnified:i.z.boolean()}).array(),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())})}).array(),result:i.z.string()}),y=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:t.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:d.array().optional(),setupFields:d.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:g.array().optional()});function z(t){try{const e=s.parse(t),n=y.parse(e),o={title:n.info.title,version:n.info.version,key:n.info.key,description:n.info.description},i=h(n),a={baseUrl:n.baseUrl,authentication:m(i)},c=b(n,a);return o.operations=c,o.authentication=i,r.notMissing(c)&&(o.categories=f(Object.values(c))),o}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const m=t=>{const e={};for(const[r,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:o,support:s,testOperationsIds:i,...a}=n;e[r]=m(a)}else e[r]=n;return e},f=t=>{const e=t.reduce(((t,e)=>{for(const r of e.categories)t.add(r);return t}),new Set);return Array.from(e)},h=t=>{const e={};for(const r of t.authentication??[]){const[t]=Object.keys(r),n=r[t].environments.reduce(((e,n)=>{const{key:o,name:s}=n,{environments:i,...a}=r[t];return e[o]={...a,envKey:o,envName:s},e}),{});e[t]=n}return e},b=(t,e)=>{const r=t.operations?.reduce(((t,r)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(r),o=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(r),s=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(r);return t[n??o]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??s,entrypointHttpMethod:r.entrypointHttpMethod??"get",inputs:r.inputs,steps:r.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,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:r.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:r.result},t}),{});return r},k=(t,e)=>{if(!t.inputs)return{};const r=F(t.inputs).parse(e);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},S=t=>{const e={};return t.forEach((t=>{let r;switch(t.type.toLowerCase()){case"string":r=i.z.string();break;case"number":r=i.z.number();break;case"boolean":r=i.z.boolean();break;default:r=i.z.any()}e[t.name]=t.required?r:r.optional()})),i.z.object(e)},F=t=>{const e=t.filter((t=>"path"===t.in)),r=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),o=t.filter((t=>"headers"===t.in));return i.z.object({path:S(e).optional(),query:S(r).optional(),body:S(n).optional(),headers:S(o).optional()})};class I extends Error{constructor(t,e){super(e),this.name="ConnectSDKError",this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,I)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class v extends I{constructor(t){super("CONNECTOR_PARSE_ERROR",t),this.name="ConnectorParseError"}}class E extends I{constructor(t){super("MISSING_OPERATION_ERROR",t),this.name="MissingOperationError"}}class O extends I{constructor(t){super("INVALID_OPERATION_INPUTS_ERROR",t),this.name="InvalidOperationInputsError"}}exports.ConnectSDKError=I,exports.createBlock=c,exports.executeStepFunction=async({block:e,stepFunctionName:r,params:n,buildStepFunction:o=t.StepFunctionsFactory.build})=>{const s=o({functionName:r}).fn,i=await s({block:e,params:n}),a=r===t.StepFunctionName.MAP_FIELDS?{[t.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=p,exports.parseOperationInputs=k,exports.parseYamlConnector=z,exports.runConnectorOperation=async({account:t,connector:e,category:n,path:o,method:s="get",queryParams:i,logger:u,parseConnector:l=z,getOperationFromUrlFn:d=p,parseOperationInputsFn:g=k,createBlockFn:y=c,runStepOperationFn:m=a})=>{const f=t.authConfigKey,h=t.environment??"production",b=t.secureId,S=t.projectSecureId,F=t.credentials;let I;try{I=r.isString(e)?l(e):e}catch{throw new v("Error while parsing connector")}const j=d(I,o,s);if(r.isMissing(j))throw new E("No matching operation found");let N;try{N=g(j.operation,{query:i,path:j.params})}catch{throw new O("Error while parsing operation inputs")}const C=await y({inputs:N,category:n,connectorKey:I.key,connectorVersion:I.version,authConfigKey:f,environment:h,operation:j.operation,accountSecureId:b,projectSecureId:S,credentials:F,logger:u});return await m({block:C})},exports.runStepOperation=a;
1
+ "use strict";var t=require("@stackone/core"),e=require("@stackone/expressions"),r=require("@stackone/utils"),n=require("@stackone/transport"),o=require("path-to-regexp"),i=require("yaml"),s=require("zod");const a=async({block:r,buildStepFunction:n=t.StepFunctionsFactory.build})=>{const o=r.operation?.steps||[];let i={...r};const s=Object.keys(o);for(const t of s){const e=o[t].stepFunction,r=n({functionName:e.functionName,version:e.version,validateSchemas:!0}).fn,s=await r({block:i,params:e.params});i={...s.block,steps:{...s.block.steps,[t]:{successful:s.successful,errors:s.errors,output:s.output}}}}const a=r.operation?.result?e.safeEvaluate(r.operation.result,i):void 0;return{...i,outputs:a}},c=async({inputs:t,context:e,operation:r,credentials:o,logger:i,getHttpClient:s=async()=>n.HttpClientManager.getInstance()})=>({inputs:t,fieldConfigs:[],context:e,operation:r,credentials:o,httpClient:await s(),logger:i}),p=({category:t,connectorKey:e,connectorVersion:r,authConfigKey:n,environment:o="production",operation:i,accountSecureId:s,projectSecureId:a})=>({projectSecureId:a,accountSecureId:s,connectorKey:e,connectorVersion:r,category:t,service:"",resource:"",schema:i?.schema?.key,operationType:i?.operationType??"unknown",authenticationType:n,environment:o}),u=(t,e,r)=>{const n=r.toUpperCase();if(!t.operations)return;const o=Object.keys(t.operations),i=d(e,n,o);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,r)=>{const n=l(t);for(const t of r)if(t.startsWith(e)){const r=t.replace(`${e} `,"").trim(),i=o.match(l(r))(l(n));if(!1!==i)return{path:t,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()}),y=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.string().or(s.z.object({matchExpression:s.z.string(),value:s.z.string()}).array())}).optional()}).array(),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())})}).array(),result:s.z.string()}),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: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:g.array().optional(),setupFields:g.array().optional(),testOperationsIds:s.z.string().array().optional()})).array().optional(),operations:y.array().optional()});function z(t){try{const e=i.parse(t),n=m.parse(e),o={title:n.info.title,version:n.info.version,key:n.info.key,description:n.info.description},s=b(n),a={baseUrl:n.baseUrl,authentication:h(s)},c=k(n,a);return o.operations=c,o.authentication=s,r.notMissing(c)&&(o.categories=f(Object.values(c))),o}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const h=t=>{const e={};for(const[r,n]of Object.entries(t))if(n&&"object"==typeof n){const{setupFields:t,configFields:o,support:i,testOperationsIds:s,...a}=n;e[r]=h(a)}else e[r]=n;return e},f=t=>{const e=t.reduce(((t,e)=>{for(const r of e.categories)t.add(r);return t}),new Set);return Array.from(e)},b=t=>{const e={};for(const r of t.authentication??[]){const[t]=Object.keys(r),n=r[t].environments.reduce(((e,n)=>{const{key:o,name:i}=n,{environments:s,...a}=r[t];return e[o]={...a,envKey:o,envName:i},e}),{});e[t]=n}return e},k=(t,e)=>{const r=t.operations?.reduce(((t,r)=>{const n=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(r),o=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(r),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(r);return t[n??o]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",inputs:r.inputs,steps:r.steps.reduce(((t,n)=>(t[n.stepId]={id:n.stepId,description:n.description,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:r.fieldConfigs}:{},...n.stepFunction.parameters}}},t)),{}),result:r.result},t}),{});return r},F=(t,e)=>{if(!t.inputs)return{};const r=I(t.inputs).parse(e);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},S=t=>{const e={};return t.forEach((t=>{let r;switch(t.type.toLowerCase()){case"string":r=s.z.string();break;case"number":r=s.z.number();break;case"boolean":r=s.z.boolean();break;default:r=s.z.any()}e[t.name]=t.required?r:r.optional()})),s.z.object(e)},I=t=>{const e=t.filter((t=>"path"===t.in)),r=t.filter((t=>"query"===t.in)),n=t.filter((t=>"body"===t.in)),o=t.filter((t=>"headers"===t.in));return s.z.object({path:S(e).optional(),query:S(r).optional(),body:S(n).optional(),headers:S(o).optional()})};class v extends Error{constructor(t,e,r){super(r),this.name="ConnectSDKError",this.errorType=t,this.context=e,Error.captureStackTrace&&Error.captureStackTrace(this,v)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class E extends v{constructor(t,e){super("CONNECTOR_PARSE_ERROR",t,e),this.name="ConnectorParseError"}}class O extends v{constructor(t,e){super("MISSING_OPERATION_ERROR",t,e),this.name="MissingOperationError"}}class j extends v{constructor(t,e){super("INVALID_OPERATION_INPUTS_ERROR",t,e),this.name="InvalidOperationInputsError"}}exports.ConnectSDKError=v,exports.createBlock=c,exports.executeStepFunction=async({block:e,stepFunctionName:r,params:n,buildStepFunction:o=t.StepFunctionsFactory.build})=>{const i=o({functionName:r}).fn,s=await i({block:e,params:n}),a=r===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=F,exports.parseYamlConnector=z,exports.runConnectorOperation=async({account:t,connector:e,category:n,path:o,method:i="get",queryParams:s,logger:l,parseConnector:d=z,getOperationFromUrlFn:g=u,parseOperationInputsFn:y=F,createBlockContextFn:m=p,createBlockFn:h=c,runStepOperationFn:f=a})=>{const b=t.authConfigKey,k=t.environment??"production",S=t.secureId,I=t.projectSecureId,v=t.credentials,C=m({category:n,connectorKey:t.providerKey,connectorVersion:t.providerVersion,authConfigKey:b,environment:k,accountSecureId:S,projectSecureId:I});let N;try{N=r.isString(e)?d(e):e}catch{throw new E(C,"Error while parsing connector")}const T=g(N,o,i);if(r.isMissing(T))throw new O(C,"No matching operation found");let x;C.operationType=T.operation.operationType,C.schema=T.operation.schema?.key;try{x=y(T.operation,{query:s,path:T.params})}catch{throw new j(C,"Error while parsing operation inputs")}const w=await h({inputs:x,context:C,operation:T.operation,credentials:v,logger:l});return await f({block:w})},exports.runStepOperation=a;
@@ -1,15 +1,9 @@
1
- import { Block, Category, ILogger, Operation } from '@stackone/core';
1
+ import { Block, BlockContext, ILogger, Operation } from '@stackone/core';
2
2
  import { IHttpClient } from '@stackone/transport';
3
- export declare const createBlock: ({ inputs, category, connectorKey, connectorVersion, authConfigKey, environment, operation, accountSecureId, projectSecureId, credentials, logger, getHttpClient, }: {
3
+ export declare const createBlock: ({ inputs, context, operation, credentials, logger, getHttpClient, }: {
4
4
  inputs?: Record<string, unknown>;
5
- category: Category;
6
- connectorKey: string;
7
- connectorVersion: string;
8
- authConfigKey: string;
9
- environment?: string;
5
+ context: BlockContext;
10
6
  operation: Operation;
11
- accountSecureId: string;
12
- projectSecureId: string;
13
7
  credentials?: Record<string, unknown>;
14
8
  logger?: ILogger;
15
9
  getHttpClient?: () => Promise<IHttpClient>;
@@ -0,0 +1,11 @@
1
+ import { BlockContext, Category, Operation } from '@stackone/core';
2
+ export declare const createBlockContext: ({ category, connectorKey, connectorVersion, authConfigKey, environment, operation, accountSecureId, projectSecureId, }: {
3
+ category: Category;
4
+ connectorKey: string;
5
+ connectorVersion: string;
6
+ authConfigKey: string;
7
+ environment?: string;
8
+ operation?: Operation;
9
+ accountSecureId: string;
10
+ projectSecureId: string;
11
+ }) => BlockContext;
@@ -29,18 +29,52 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
29
29
  fieldConfigs: z.ZodArray<z.ZodObject<{
30
30
  targetFieldKey: z.ZodString;
31
31
  expression: z.ZodString;
32
- type: z.ZodString;
32
+ type: z.ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
33
33
  isUnified: z.ZodBoolean;
34
+ enumMapper: z.ZodOptional<z.ZodObject<{
35
+ matcher: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
36
+ matchExpression: z.ZodString;
37
+ value: z.ZodString;
38
+ }, "strip", z.ZodTypeAny, {
39
+ value: string;
40
+ matchExpression: string;
41
+ }, {
42
+ value: string;
43
+ matchExpression: string;
44
+ }>, "many">]>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ matcher: string | {
47
+ value: string;
48
+ matchExpression: string;
49
+ }[];
50
+ }, {
51
+ matcher: string | {
52
+ value: string;
53
+ matchExpression: string;
54
+ }[];
55
+ }>>;
34
56
  }, "strip", z.ZodTypeAny, {
35
- type: string;
57
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
36
58
  targetFieldKey: string;
37
59
  expression: string;
38
60
  isUnified: boolean;
61
+ enumMapper?: {
62
+ matcher: string | {
63
+ value: string;
64
+ matchExpression: string;
65
+ }[];
66
+ } | undefined;
39
67
  }, {
40
- type: string;
68
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
41
69
  targetFieldKey: string;
42
70
  expression: string;
43
71
  isUnified: boolean;
72
+ enumMapper?: {
73
+ matcher: string | {
74
+ value: string;
75
+ matchExpression: string;
76
+ }[];
77
+ } | undefined;
44
78
  }>, "many">;
45
79
  steps: z.ZodArray<z.ZodObject<{
46
80
  stepId: z.ZodString;
@@ -82,10 +116,16 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
82
116
  categories: string[];
83
117
  operationType: string;
84
118
  fieldConfigs: {
85
- type: string;
119
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
86
120
  targetFieldKey: string;
87
121
  expression: string;
88
122
  isUnified: boolean;
123
+ enumMapper?: {
124
+ matcher: string | {
125
+ value: string;
126
+ matchExpression: string;
127
+ }[];
128
+ } | undefined;
89
129
  }[];
90
130
  steps: {
91
131
  description: string;
@@ -113,10 +153,16 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
113
153
  categories: string[];
114
154
  operationType: string;
115
155
  fieldConfigs: {
116
- type: string;
156
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
117
157
  targetFieldKey: string;
118
158
  expression: string;
119
159
  isUnified: boolean;
160
+ enumMapper?: {
161
+ matcher: string | {
162
+ value: string;
163
+ matchExpression: string;
164
+ }[];
165
+ } | undefined;
120
166
  }[];
121
167
  steps: {
122
168
  description: string;
@@ -376,18 +422,52 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
376
422
  fieldConfigs: z.ZodArray<z.ZodObject<{
377
423
  targetFieldKey: z.ZodString;
378
424
  expression: z.ZodString;
379
- type: z.ZodString;
425
+ type: z.ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
380
426
  isUnified: z.ZodBoolean;
427
+ enumMapper: z.ZodOptional<z.ZodObject<{
428
+ matcher: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
429
+ matchExpression: z.ZodString;
430
+ value: z.ZodString;
431
+ }, "strip", z.ZodTypeAny, {
432
+ value: string;
433
+ matchExpression: string;
434
+ }, {
435
+ value: string;
436
+ matchExpression: string;
437
+ }>, "many">]>;
438
+ }, "strip", z.ZodTypeAny, {
439
+ matcher: string | {
440
+ value: string;
441
+ matchExpression: string;
442
+ }[];
443
+ }, {
444
+ matcher: string | {
445
+ value: string;
446
+ matchExpression: string;
447
+ }[];
448
+ }>>;
381
449
  }, "strip", z.ZodTypeAny, {
382
- type: string;
450
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
383
451
  targetFieldKey: string;
384
452
  expression: string;
385
453
  isUnified: boolean;
454
+ enumMapper?: {
455
+ matcher: string | {
456
+ value: string;
457
+ matchExpression: string;
458
+ }[];
459
+ } | undefined;
386
460
  }, {
387
- type: string;
461
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
388
462
  targetFieldKey: string;
389
463
  expression: string;
390
464
  isUnified: boolean;
465
+ enumMapper?: {
466
+ matcher: string | {
467
+ value: string;
468
+ matchExpression: string;
469
+ }[];
470
+ } | undefined;
391
471
  }>, "many">;
392
472
  steps: z.ZodArray<z.ZodObject<{
393
473
  stepId: z.ZodString;
@@ -429,10 +509,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
429
509
  categories: string[];
430
510
  operationType: string;
431
511
  fieldConfigs: {
432
- type: string;
512
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
433
513
  targetFieldKey: string;
434
514
  expression: string;
435
515
  isUnified: boolean;
516
+ enumMapper?: {
517
+ matcher: string | {
518
+ value: string;
519
+ matchExpression: string;
520
+ }[];
521
+ } | undefined;
436
522
  }[];
437
523
  steps: {
438
524
  description: string;
@@ -460,10 +546,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
460
546
  categories: string[];
461
547
  operationType: string;
462
548
  fieldConfigs: {
463
- type: string;
549
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
464
550
  targetFieldKey: string;
465
551
  expression: string;
466
552
  isUnified: boolean;
553
+ enumMapper?: {
554
+ matcher: string | {
555
+ value: string;
556
+ matchExpression: string;
557
+ }[];
558
+ } | undefined;
467
559
  }[];
468
560
  steps: {
469
561
  description: string;
@@ -543,10 +635,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
543
635
  categories: string[];
544
636
  operationType: string;
545
637
  fieldConfigs: {
546
- type: string;
638
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
547
639
  targetFieldKey: string;
548
640
  expression: string;
549
641
  isUnified: boolean;
642
+ enumMapper?: {
643
+ matcher: string | {
644
+ value: string;
645
+ matchExpression: string;
646
+ }[];
647
+ } | undefined;
550
648
  }[];
551
649
  steps: {
552
650
  description: string;
@@ -626,10 +724,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
626
724
  categories: string[];
627
725
  operationType: string;
628
726
  fieldConfigs: {
629
- type: string;
727
+ type: "string" | "number" | "boolean" | "datetime_string" | "enum";
630
728
  targetFieldKey: string;
631
729
  expression: string;
632
730
  isUnified: boolean;
731
+ enumMapper?: {
732
+ matcher: string | {
733
+ value: string;
734
+ matchExpression: string;
735
+ }[];
736
+ } | undefined;
633
737
  }[];
634
738
  steps: {
635
739
  description: string;
@@ -1,15 +1,17 @@
1
+ import { BlockContext } from '@stackone/core';
1
2
  import { ErrorType } from './types';
2
3
  export declare class ConnectSDKError extends Error {
3
4
  readonly errorType: ErrorType;
4
- constructor(errorType: ErrorType, message?: string);
5
+ readonly context: BlockContext;
6
+ constructor(errorType: ErrorType, context: BlockContext, message?: string);
5
7
  toString(): string;
6
8
  }
7
9
  export declare class ConnectorParseError extends ConnectSDKError {
8
- constructor(message?: string);
10
+ constructor(context: BlockContext, message?: string);
9
11
  }
10
12
  export declare class MissingOperationError extends ConnectSDKError {
11
- constructor(message?: string);
13
+ constructor(context: BlockContext, message?: string);
12
14
  }
13
15
  export declare class InvalidOperationInputsError extends ConnectSDKError {
14
- constructor(message?: string);
16
+ constructor(context: BlockContext, message?: string);
15
17
  }
@@ -1,10 +1,11 @@
1
1
  import { Account, Block, Category, Connector, ILogger } from '@stackone/core';
2
2
  import { HttpMethod } from '@stackone/transport';
3
3
  import { createBlock } from '../blocks/createBlock';
4
+ import { createBlockContext } from '../blocks/createBlockContext';
4
5
  import { getOperationFromUrl } from '../connectors/operations';
5
6
  import { parseOperationInputs, parseYamlConnector } from '../connectors/parsers';
6
7
  import { runStepOperation } from './runStepOperation';
7
- export declare const runConnectorOperation: ({ account, connector, category, path, method, queryParams, logger, parseConnector, getOperationFromUrlFn, parseOperationInputsFn, createBlockFn, runStepOperationFn, }: {
8
+ export declare const runConnectorOperation: ({ account, connector, category, path, method, queryParams, logger, parseConnector, getOperationFromUrlFn, parseOperationInputsFn, createBlockContextFn, createBlockFn, runStepOperationFn, }: {
8
9
  account: Account;
9
10
  connector: Connector | string;
10
11
  category: Category;
@@ -15,6 +16,7 @@ export declare const runConnectorOperation: ({ account, connector, category, pat
15
16
  parseConnector?: typeof parseYamlConnector;
16
17
  getOperationFromUrlFn?: typeof getOperationFromUrl;
17
18
  parseOperationInputsFn?: typeof parseOperationInputs;
19
+ createBlockContextFn?: typeof createBlockContext;
18
20
  createBlockFn?: typeof createBlock;
19
21
  runStepOperationFn?: typeof runStepOperation;
20
22
  }) => Promise<Block>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/connect-sdk",
3
- "version": "1.12.2",
3
+ "version": "1.14.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",