@stackone/connect-sdk 1.12.0 → 1.12.2

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{StepFunctionName as t,StepFunctionsFactory as e,AUTHENTICATION_SCHEMA as n}from"@stackone/core";import{safeEvaluate as o}from"@stackone/expressions";import{parse as r}from"yaml";import{z as i}from"zod";import{HttpClientManager as s}from"@stackone/transport";import{match as a}from"path-to-regexp";const c=async({block:n,stepFunctionName:o,params:r,buildStepFunction:i=e.build})=>{const s=i({functionName:o}).fn,a=await s({block:n,params:r}),c=o===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}}},p=async({block:t,buildStepFunction:n=e.build})=>{const r=t.operation?.steps||[];let i={...t};const s=Object.keys(r);for(const t of s){const e=r[t].stepFunction,o=n({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=t.operation?.result?o(t.operation.result,i):void 0;return{...i,outputs:a}},u=i.object({key:i.string(),label:i.string(),type:i.string(),required:i.boolean().optional(),secret:i.boolean().optional(),placeholder:i.string().optional(),description:i.string().optional(),tooltip:i.string().optional()}),l=i.object({StackOne:i.string(),info:i.object({title:i.string(),version:i.string(),key:i.string(),description:i.string().optional()}),baseUrl:i.string(),authentication:i.record(i.string(),i.object({type:i.string(),label:i.string(),authorization:n,environments:i.object({key:i.string(),name:i.string()}).array(),support:i.object({link:i.string(),description:i.string().optional()}),configFields:u.array().optional(),setupFields:u.array().optional(),testOperationsIds:i.string().array().optional()})).array().optional(),operations:i.object({operationId:i.string(),categories:i.string().array(),operationType:i.string(),schema:i.string().optional(),entrypointUrl:i.string().optional(),entrypointHttpMethod:i.string().optional(),description:i.string(),inputs:i.object({name:i.string(),type:i.string(),required:i.boolean(),description:i.string(),in:i.string()}).array().optional(),fieldConfigs:i.object({targetFieldKey:i.string(),expression:i.string(),type:i.string(),isUnified:i.boolean()}).array(),steps:i.object({stepId:i.string(),description:i.string(),stepFunction:i.object({functionName:i.string(),version:i.string().optional(),parameters:i.record(i.string(),i.unknown())})}).array(),result:i.string()}).array()});function d(t){try{const e=r(t),n=l.parse(e),o={title:n.info.title,version:n.info.version,key:n.info.key,description:n.info.description},i=f(n),s={baseUrl:n.baseUrl,authentication:g(i)},a=m(n,s);return o.operations=a,o.authentication=i,o.categories=y(Object.values(a)),o}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}}const g=t=>{const e={};for(const[n,o]of Object.entries(t))if(o&&"object"==typeof o){const{setupFields:t,configFields:r,support:i,testOperationsIds:s,...a}=o;e[n]=g(a)}else e[n]=o;return e},y=t=>{const e=t.reduce(((t,e)=>{for(const n of e.categories)t.add(n);return t}),new Set);return Array.from(e)},f=t=>{const e={};for(const n of t.authentication??[]){const[t]=Object.keys(n),o=n[t].environments.reduce(((e,o)=>{const{key:r,name:i}=o,{environments:s,...a}=n[t];return e[r]={...a,envKey:r,envName:i},e}),{});e[t]=o}return e},m=(t,e)=>t.operations.reduce(((t,n)=>{const o=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(n),r=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(n),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(n);return t[o??r]={id:n.operationId,categories:n.categories,description:n.description,operationType:n.operationType,entrypointUrl:n.entrypointUrl??i,entrypointHttpMethod:n.entrypointHttpMethod??"get",inputs:n.inputs,steps:n.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:n.fieldConfigs}:{},...o.stepFunction.parameters}}},t)),{}),result:n.result},t}),{}),b=(t,e)=>{if(!t.inputs)return{};const n=k(t.inputs).parse(e);return{...n.headers??{},...n.query??{},...n.path??{},...n.body??{}}},h=t=>{const e={};return t.forEach((t=>{let n;switch(t.type.toLowerCase()){case"string":n=i.string();break;case"number":n=i.number();break;case"boolean":n=i.boolean();break;default:n=i.any()}e[t.name]=t.required?n:n.optional()})),i.object(e)},k=t=>{const e=t.filter((t=>"path"===t.in)),n=t.filter((t=>"query"===t.in)),o=t.filter((t=>"body"===t.in)),r=t.filter((t=>"headers"===t.in));return i.object({path:h(e).optional(),query:h(n).optional(),body:h(o).optional(),headers:h(r).optional()})},j=async({inputs:t,category:e,connectorKey:n,connectorVersion:o,authConfigKey:r,environment:i="production",operation:a,accountSecureId:c,projectSecureId:p,credentials:u,logger:l,getHttpClient:d=async()=>s.getInstance()})=>{const g=await d();return{inputs:t,fieldConfigs:[],context:{projectSecureId:p,accountSecureId:c,connectorKey:n,connectorVersion:o,category:e,schema:a.schema?.key,service:"",resource:"",operationType:a.operationType,authenticationType:r,environment:i},operation:a,credentials:u,httpClient:g,logger:l}},v=(t,e,n)=>{const o=n.toUpperCase();if(!t.operations)return;const r=Object.keys(t.operations),i=I(e,o,r);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},I=(t,e,n)=>{const o=F(t);for(const t of n)if(t.startsWith(e)){const n=t.replace(`${e} `,"").trim(),r=a(F(n))(F(o));if(!1!==r)return{path:t,params:r.params}}};export{j as createBlock,c as executeStepFunction,v as getOperationFromUrl,b as parseOperationInputs,d as parseYamlConnector,p as runStepOperation};
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};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@stackone/core"),e=require("@stackone/expressions"),n=require("yaml"),o=require("zod"),r=require("@stackone/transport"),i=require("path-to-regexp");const s=o.z.object({key:o.z.string(),label:o.z.string(),type:o.z.string(),required:o.z.boolean().optional(),secret:o.z.boolean().optional(),placeholder:o.z.string().optional(),description:o.z.string().optional(),tooltip:o.z.string().optional()}),a=o.z.object({StackOne:o.z.string(),info:o.z.object({title:o.z.string(),version:o.z.string(),key:o.z.string(),description:o.z.string().optional()}),baseUrl:o.z.string(),authentication:o.z.record(o.z.string(),o.z.object({type:o.z.string(),label:o.z.string(),authorization:t.AUTHENTICATION_SCHEMA,environments:o.z.object({key:o.z.string(),name:o.z.string()}).array(),support:o.z.object({link:o.z.string(),description:o.z.string().optional()}),configFields:s.array().optional(),setupFields:s.array().optional(),testOperationsIds:o.z.string().array().optional()})).array().optional(),operations:o.z.object({operationId:o.z.string(),categories:o.z.string().array(),operationType:o.z.string(),schema:o.z.string().optional(),entrypointUrl:o.z.string().optional(),entrypointHttpMethod:o.z.string().optional(),description:o.z.string(),inputs:o.z.object({name:o.z.string(),type:o.z.string(),required:o.z.boolean(),description:o.z.string(),in:o.z.string()}).array().optional(),fieldConfigs:o.z.object({targetFieldKey:o.z.string(),expression:o.z.string(),type:o.z.string(),isUnified:o.z.boolean()}).array(),steps:o.z.object({stepId:o.z.string(),description:o.z.string(),stepFunction:o.z.object({functionName:o.z.string(),version:o.z.string().optional(),parameters:o.z.record(o.z.string(),o.z.unknown())})}).array(),result:o.z.string()}).array()});const c=t=>{const e={};for(const[n,o]of Object.entries(t))if(o&&"object"==typeof o){const{setupFields:t,configFields:r,support:i,testOperationsIds:s,...a}=o;e[n]=c(a)}else e[n]=o;return e},p=t=>{const e=t.reduce(((t,e)=>{for(const n of e.categories)t.add(n);return t}),new Set);return Array.from(e)},u=t=>{const e={};for(const n of t.authentication??[]){const[t]=Object.keys(n),o=n[t].environments.reduce(((e,o)=>{const{key:r,name:i}=o,{environments:s,...a}=n[t];return e[r]={...a,envKey:r,envName:i},e}),{});e[t]=o}return e},l=(t,e)=>t.operations.reduce(((t,n)=>{const o=(t=>t.entrypointUrl&&t.entrypointHttpMethod?`${t.entrypointHttpMethod.toUpperCase()} ${t.entrypointUrl}`:void 0)(n),r=(t=>"list"===t.operationType?`GET /${t.schema}`:`GET /${t.schema}/:id`)(n),i=(t=>"list"===t.operationType?`/${t.schema}`:`/${t.schema}/:id`)(n);return t[o??r]={id:n.operationId,categories:n.categories,description:n.description,operationType:n.operationType,entrypointUrl:n.entrypointUrl??i,entrypointHttpMethod:n.entrypointHttpMethod??"get",inputs:n.inputs,steps:n.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:n.fieldConfigs}:{},...o.stepFunction.parameters}}},t)),{}),result:n.result},t}),{}),d=t=>{const e={};return t.forEach((t=>{let n;switch(t.type.toLowerCase()){case"string":n=o.z.string();break;case"number":n=o.z.number();break;case"boolean":n=o.z.boolean();break;default:n=o.z.any()}e[t.name]=t.required?n:n.optional()})),o.z.object(e)},g=t=>{const e=t.filter((t=>"path"===t.in)),n=t.filter((t=>"query"===t.in)),r=t.filter((t=>"body"===t.in)),i=t.filter((t=>"headers"===t.in));return o.z.object({path:d(e).optional(),query:d(n).optional(),body:d(r).optional(),headers:d(i).optional()})},y=t=>{const e=t.startsWith("/")?t.slice(1):t;return e.endsWith("/")?e.slice(0,-1):e},z=(t,e,n)=>{const o=y(t);for(const t of n)if(t.startsWith(e)){const n=t.replace(`${e} `,"").trim(),r=i.match(y(n))(y(o));if(!1!==r)return{path:t,params:r.params}}};exports.createBlock=async({inputs:t,category:e,connectorKey:n,connectorVersion:o,authConfigKey:i,environment:s="production",operation:a,accountSecureId:c,projectSecureId:p,credentials:u,logger:l,getHttpClient:d=async()=>r.HttpClientManager.getInstance()})=>{const g=await d();return{inputs:t,fieldConfigs:[],context:{projectSecureId:p,accountSecureId:c,connectorKey:n,connectorVersion:o,category:e,schema:a.schema?.key,service:"",resource:"",operationType:a.operationType,authenticationType:i,environment:s},operation:a,credentials:u,httpClient:g,logger:l}},exports.executeStepFunction=async({block:e,stepFunctionName:n,params:o,buildStepFunction:r=t.StepFunctionsFactory.build})=>{const i=r({functionName:n}).fn,s=await i({block:e,params:o}),a=n===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=(t,e,n)=>{const o=n.toUpperCase();if(!t.operations)return;const r=Object.keys(t.operations),i=z(e,o,r);return i?{operation:t.operations?.[i.path],params:i.params}:void 0},exports.parseOperationInputs=(t,e)=>{if(!t.inputs)return{};const n=g(t.inputs).parse(e);return{...n.headers??{},...n.query??{},...n.path??{},...n.body??{}}},exports.parseYamlConnector=function(t){try{const e=n.parse(t),o=a.parse(e),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=u(o),s={baseUrl:o.baseUrl,authentication:c(i)},d=l(o,s);return r.operations=d,r.authentication=i,r.categories=p(Object.values(d)),r}catch(t){throw new Error(`Error parsing YAML file: ${t.message}`)}},exports.runStepOperation=async({block:n,buildStepFunction:o=t.StepFunctionsFactory.build})=>{const r=n.operation?.steps||[];let i={...n};const s=Object.keys(r);for(const t of s){const e=r[t].stepFunction,n=o({functionName:e.functionName,version:e.version,validateSchemas:!0}).fn,s=await n({block:i,params:e.params});i={...s.block,steps:{...s.block.steps,[t]:{successful:s.successful,errors:s.errors,output:s.output}}}}const a=n.operation?.result?e.safeEvaluate(n.operation.result,i):void 0;return{...i,outputs: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"),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,4 +1,144 @@
1
1
  import { z } from 'zod';
2
+ export declare const OPERATION_SCHEMA: z.ZodObject<{
3
+ operationId: z.ZodString;
4
+ categories: z.ZodArray<z.ZodString, "many">;
5
+ operationType: z.ZodString;
6
+ schema: z.ZodOptional<z.ZodString>;
7
+ entrypointUrl: z.ZodOptional<z.ZodString>;
8
+ entrypointHttpMethod: z.ZodOptional<z.ZodString>;
9
+ description: z.ZodString;
10
+ inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
11
+ name: z.ZodString;
12
+ type: z.ZodString;
13
+ required: z.ZodBoolean;
14
+ description: z.ZodString;
15
+ in: z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ type: string;
18
+ required: boolean;
19
+ description: string;
20
+ name: string;
21
+ in: string;
22
+ }, {
23
+ type: string;
24
+ required: boolean;
25
+ description: string;
26
+ name: string;
27
+ in: string;
28
+ }>, "many">>;
29
+ fieldConfigs: z.ZodArray<z.ZodObject<{
30
+ targetFieldKey: z.ZodString;
31
+ expression: z.ZodString;
32
+ type: z.ZodString;
33
+ isUnified: z.ZodBoolean;
34
+ }, "strip", z.ZodTypeAny, {
35
+ type: string;
36
+ targetFieldKey: string;
37
+ expression: string;
38
+ isUnified: boolean;
39
+ }, {
40
+ type: string;
41
+ targetFieldKey: string;
42
+ expression: string;
43
+ isUnified: boolean;
44
+ }>, "many">;
45
+ steps: z.ZodArray<z.ZodObject<{
46
+ stepId: z.ZodString;
47
+ description: z.ZodString;
48
+ stepFunction: z.ZodObject<{
49
+ functionName: z.ZodString;
50
+ version: z.ZodOptional<z.ZodString>;
51
+ parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
52
+ }, "strip", z.ZodTypeAny, {
53
+ functionName: string;
54
+ parameters: Record<string, unknown>;
55
+ version?: string | undefined;
56
+ }, {
57
+ functionName: string;
58
+ parameters: Record<string, unknown>;
59
+ version?: string | undefined;
60
+ }>;
61
+ }, "strip", z.ZodTypeAny, {
62
+ description: string;
63
+ stepId: string;
64
+ stepFunction: {
65
+ functionName: string;
66
+ parameters: Record<string, unknown>;
67
+ version?: string | undefined;
68
+ };
69
+ }, {
70
+ description: string;
71
+ stepId: string;
72
+ stepFunction: {
73
+ functionName: string;
74
+ parameters: Record<string, unknown>;
75
+ version?: string | undefined;
76
+ };
77
+ }>, "many">;
78
+ result: z.ZodString;
79
+ }, "strip", z.ZodTypeAny, {
80
+ description: string;
81
+ operationId: string;
82
+ categories: string[];
83
+ operationType: string;
84
+ fieldConfigs: {
85
+ type: string;
86
+ targetFieldKey: string;
87
+ expression: string;
88
+ isUnified: boolean;
89
+ }[];
90
+ steps: {
91
+ description: string;
92
+ stepId: string;
93
+ stepFunction: {
94
+ functionName: string;
95
+ parameters: Record<string, unknown>;
96
+ version?: string | undefined;
97
+ };
98
+ }[];
99
+ result: string;
100
+ schema?: string | undefined;
101
+ entrypointUrl?: string | undefined;
102
+ entrypointHttpMethod?: string | undefined;
103
+ inputs?: {
104
+ type: string;
105
+ required: boolean;
106
+ description: string;
107
+ name: string;
108
+ in: string;
109
+ }[] | undefined;
110
+ }, {
111
+ description: string;
112
+ operationId: string;
113
+ categories: string[];
114
+ operationType: string;
115
+ fieldConfigs: {
116
+ type: string;
117
+ targetFieldKey: string;
118
+ expression: string;
119
+ isUnified: boolean;
120
+ }[];
121
+ steps: {
122
+ description: string;
123
+ stepId: string;
124
+ stepFunction: {
125
+ functionName: string;
126
+ parameters: Record<string, unknown>;
127
+ version?: string | undefined;
128
+ };
129
+ }[];
130
+ result: string;
131
+ schema?: string | undefined;
132
+ entrypointUrl?: string | undefined;
133
+ entrypointHttpMethod?: string | undefined;
134
+ inputs?: {
135
+ type: string;
136
+ required: boolean;
137
+ description: string;
138
+ name: string;
139
+ in: string;
140
+ }[] | undefined;
141
+ }>;
2
142
  export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
3
143
  StackOne: z.ZodString;
4
144
  info: z.ZodObject<{
@@ -8,13 +148,13 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
8
148
  description: z.ZodOptional<z.ZodString>;
9
149
  }, "strip", z.ZodTypeAny, {
10
150
  key: string;
11
- title: string;
12
151
  version: string;
152
+ title: string;
13
153
  description?: string | undefined;
14
154
  }, {
15
155
  key: string;
16
- title: string;
17
156
  version: string;
157
+ title: string;
18
158
  description?: string | undefined;
19
159
  }>;
20
160
  baseUrl: z.ZodString;
@@ -206,7 +346,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
206
346
  }[] | undefined;
207
347
  testOperationsIds?: string[] | undefined;
208
348
  }>>, "many">>;
209
- operations: z.ZodArray<z.ZodObject<{
349
+ operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
210
350
  operationId: z.ZodString;
211
351
  categories: z.ZodArray<z.ZodString, "many">;
212
352
  operationType: z.ZodString;
@@ -345,48 +485,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
345
485
  name: string;
346
486
  in: string;
347
487
  }[] | undefined;
348
- }>, "many">;
488
+ }>, "many">>;
349
489
  }, "strip", z.ZodTypeAny, {
350
490
  StackOne: string;
351
491
  info: {
352
492
  key: string;
353
- title: string;
354
493
  version: string;
494
+ title: string;
355
495
  description?: string | undefined;
356
496
  };
357
497
  baseUrl: string;
358
- operations: {
359
- description: string;
360
- operationId: string;
361
- categories: string[];
362
- operationType: string;
363
- fieldConfigs: {
364
- type: string;
365
- targetFieldKey: string;
366
- expression: string;
367
- isUnified: boolean;
368
- }[];
369
- steps: {
370
- description: string;
371
- stepId: string;
372
- stepFunction: {
373
- functionName: string;
374
- parameters: Record<string, unknown>;
375
- version?: string | undefined;
376
- };
377
- }[];
378
- result: string;
379
- schema?: string | undefined;
380
- entrypointUrl?: string | undefined;
381
- entrypointHttpMethod?: string | undefined;
382
- inputs?: {
383
- type: string;
384
- required: boolean;
385
- description: string;
386
- name: string;
387
- in: string;
388
- }[] | undefined;
389
- }[];
390
498
  authentication?: Record<string, {
391
499
  label: string;
392
500
  type: string;
@@ -429,16 +537,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
429
537
  }[] | undefined;
430
538
  testOperationsIds?: string[] | undefined;
431
539
  }>[] | undefined;
432
- }, {
433
- StackOne: string;
434
- info: {
435
- key: string;
436
- title: string;
437
- version: string;
438
- description?: string | undefined;
439
- };
440
- baseUrl: string;
441
- operations: {
540
+ operations?: {
442
541
  description: string;
443
542
  operationId: string;
444
543
  categories: string[];
@@ -469,7 +568,16 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
469
568
  name: string;
470
569
  in: string;
471
570
  }[] | undefined;
472
- }[];
571
+ }[] | undefined;
572
+ }, {
573
+ StackOne: string;
574
+ info: {
575
+ key: string;
576
+ version: string;
577
+ title: string;
578
+ description?: string | undefined;
579
+ };
580
+ baseUrl: string;
473
581
  authentication?: Record<string, {
474
582
  label: string;
475
583
  type: string;
@@ -512,4 +620,36 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
512
620
  }[] | undefined;
513
621
  testOperationsIds?: string[] | undefined;
514
622
  }>[] | undefined;
623
+ operations?: {
624
+ description: string;
625
+ operationId: string;
626
+ categories: string[];
627
+ operationType: string;
628
+ fieldConfigs: {
629
+ type: string;
630
+ targetFieldKey: string;
631
+ expression: string;
632
+ isUnified: boolean;
633
+ }[];
634
+ steps: {
635
+ description: string;
636
+ stepId: string;
637
+ stepFunction: {
638
+ functionName: string;
639
+ parameters: Record<string, unknown>;
640
+ version?: string | undefined;
641
+ };
642
+ }[];
643
+ result: string;
644
+ schema?: string | undefined;
645
+ entrypointUrl?: string | undefined;
646
+ entrypointHttpMethod?: string | undefined;
647
+ inputs?: {
648
+ type: string;
649
+ required: boolean;
650
+ description: string;
651
+ name: string;
652
+ in: string;
653
+ }[] | undefined;
654
+ }[] | undefined;
515
655
  }>;
@@ -0,0 +1,2 @@
1
+ import { Connector } from '@stackone/core';
2
+ export declare const StackOneTestConnectorWithoutOperations: Connector;
@@ -1,5 +1,8 @@
1
1
  export { executeStepFunction } from './runners/executeStepFunctions';
2
2
  export { runStepOperation } from './runners/runStepOperation';
3
+ export { runConnectorOperation } from './runners/runConnectorOperation';
3
4
  export { parseYamlConnector, parseOperationInputs } from './connectors/parsers';
4
5
  export { createBlock } from './blocks/createBlock';
5
6
  export { getOperationFromUrl } from './connectors/operations';
7
+ export { ConnectSDKError } from './errors/connectSDKErrors';
8
+ export { ErrorType } from './errors/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/connect-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.12.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",
@@ -37,7 +37,7 @@
37
37
  "@stackone/open-api": "*",
38
38
  "@stackone/transport": "*",
39
39
  "@stackone/utils": "*",
40
- "path-to-regexp": "^8.2.0",
41
- "yaml": "^2.7.0"
40
+ "path-to-regexp": "8.2.0",
41
+ "yaml": "2.7.1"
42
42
  }
43
43
  }