@stackone/connect-sdk 1.12.1 → 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 +1 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{StepFunctionsFactory as t,StepFunctionName as e,AUTHENTICATION_SCHEMA as
|
|
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"),
|
|
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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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';
|