@stackone/connect-sdk 1.11.0 → 1.12.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{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
|
|
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};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@stackone/core"),e=require("@stackone/expressions"),n=require("yaml"),
|
|
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,9 +1,10 @@
|
|
|
1
1
|
import { Block, Category, ILogger, Operation } from '@stackone/core';
|
|
2
2
|
import { IHttpClient } from '@stackone/transport';
|
|
3
|
-
export declare const createBlock: ({ inputs, category,
|
|
3
|
+
export declare const createBlock: ({ inputs, category, connectorKey, connectorVersion, authConfigKey, environment, operation, accountSecureId, projectSecureId, credentials, logger, getHttpClient, }: {
|
|
4
4
|
inputs?: Record<string, unknown>;
|
|
5
5
|
category: Category;
|
|
6
|
-
|
|
6
|
+
connectorKey: string;
|
|
7
|
+
connectorVersion: string;
|
|
7
8
|
authConfigKey: string;
|
|
8
9
|
environment?: string;
|
|
9
10
|
operation: Operation;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ErrorType } from './types';
|
|
2
|
+
export declare class ConnectSDKError extends Error {
|
|
3
|
+
readonly errorType: ErrorType;
|
|
4
|
+
constructor(errorType: ErrorType, message?: string);
|
|
5
|
+
toString(): string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ConnectorParseError extends ConnectSDKError {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class MissingOperationError extends ConnectSDKError {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidOperationInputsError extends ConnectSDKError {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ErrorType = 'CONNECTOR_PARSE_ERROR' | 'MISSING_OPERATION_ERROR' | 'INVALID_OPERATION_INPUTS_ERROR';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Account, Block, Category, Connector, ILogger } from '@stackone/core';
|
|
2
|
+
import { HttpMethod } from '@stackone/transport';
|
|
3
|
+
import { createBlock } from '../blocks/createBlock';
|
|
4
|
+
import { getOperationFromUrl } from '../connectors/operations';
|
|
5
|
+
import { parseOperationInputs, parseYamlConnector } from '../connectors/parsers';
|
|
6
|
+
import { runStepOperation } from './runStepOperation';
|
|
7
|
+
export declare const runConnectorOperation: ({ account, connector, category, path, method, queryParams, logger, parseConnector, getOperationFromUrlFn, parseOperationInputsFn, createBlockFn, runStepOperationFn, }: {
|
|
8
|
+
account: Account;
|
|
9
|
+
connector: Connector | string;
|
|
10
|
+
category: Category;
|
|
11
|
+
path: string;
|
|
12
|
+
method?: HttpMethod;
|
|
13
|
+
queryParams: unknown;
|
|
14
|
+
logger?: ILogger;
|
|
15
|
+
parseConnector?: typeof parseYamlConnector;
|
|
16
|
+
getOperationFromUrlFn?: typeof getOperationFromUrl;
|
|
17
|
+
parseOperationInputsFn?: typeof parseOperationInputs;
|
|
18
|
+
createBlockFn?: typeof createBlock;
|
|
19
|
+
runStepOperationFn?: typeof runStepOperation;
|
|
20
|
+
}) => Promise<Block>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/connect-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.mjs",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@stackone/expressions": "*",
|
|
37
37
|
"@stackone/open-api": "*",
|
|
38
38
|
"@stackone/transport": "*",
|
|
39
|
+
"@stackone/utils": "*",
|
|
39
40
|
"path-to-regexp": "^8.2.0",
|
|
40
41
|
"yaml": "^2.7.0"
|
|
41
42
|
}
|