@stackone/connect-sdk 1.60.0 → 1.61.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.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +6 -6
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ZodType } from "@stackone/utils";
|
|
2
|
+
import { IOlapClient } from "@stackone/olap";
|
|
2
3
|
import http from "node:http";
|
|
3
4
|
import https from "node:https";
|
|
4
5
|
|
|
@@ -467,6 +468,21 @@ type Authentication = {
|
|
|
467
468
|
};
|
|
468
469
|
};
|
|
469
470
|
//#endregion
|
|
471
|
+
//#region ../core/src/settings/types.d.ts
|
|
472
|
+
type Settings = {
|
|
473
|
+
olap: OlapSettings;
|
|
474
|
+
};
|
|
475
|
+
type OlapSettings = {
|
|
476
|
+
logs?: {
|
|
477
|
+
enabled: boolean;
|
|
478
|
+
};
|
|
479
|
+
advanced?: {
|
|
480
|
+
enabled?: boolean;
|
|
481
|
+
ttl?: number;
|
|
482
|
+
errorsOnly?: boolean;
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
//#endregion
|
|
470
486
|
//#region ../core/src/blocks/types.d.ts
|
|
471
487
|
type Block = {
|
|
472
488
|
inputs?: {
|
|
@@ -477,6 +493,8 @@ type Block = {
|
|
|
477
493
|
debug?: DebugParams;
|
|
478
494
|
steps?: StepsSnapshots;
|
|
479
495
|
httpClient?: IHttpClient;
|
|
496
|
+
olapClient?: IOlapClient;
|
|
497
|
+
settings?: Settings;
|
|
480
498
|
logger?: ILogger;
|
|
481
499
|
operation?: Operation;
|
|
482
500
|
credentials?: Credentials;
|
|
@@ -500,6 +518,7 @@ type BlockContext = {
|
|
|
500
518
|
operationType: OperationType;
|
|
501
519
|
authenticationType: string;
|
|
502
520
|
environment: string;
|
|
521
|
+
actionRunId?: string;
|
|
503
522
|
service: string;
|
|
504
523
|
resource: string;
|
|
505
524
|
subResource?: string;
|
|
@@ -571,8 +590,10 @@ declare const createBlock: ({
|
|
|
571
590
|
operation,
|
|
572
591
|
credentials,
|
|
573
592
|
nextCursor,
|
|
593
|
+
settings,
|
|
574
594
|
logger,
|
|
575
|
-
getHttpClient
|
|
595
|
+
getHttpClient,
|
|
596
|
+
getOlapClient
|
|
576
597
|
}: {
|
|
577
598
|
connector: Connector;
|
|
578
599
|
inputs?: Record<string, unknown>;
|
|
@@ -580,8 +601,10 @@ declare const createBlock: ({
|
|
|
580
601
|
operation?: Operation;
|
|
581
602
|
credentials?: Record<string, unknown>;
|
|
582
603
|
nextCursor?: Cursor;
|
|
604
|
+
settings?: Settings;
|
|
583
605
|
logger?: ILogger;
|
|
584
606
|
getHttpClient?: () => Promise<IHttpClient>;
|
|
607
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
585
608
|
}) => Promise<Block>;
|
|
586
609
|
//#endregion
|
|
587
610
|
//#region src/connectors/fileReader.d.ts
|
|
@@ -743,6 +766,7 @@ type BaseRunActionParams = {
|
|
|
743
766
|
queryParams?: unknown;
|
|
744
767
|
body?: unknown;
|
|
745
768
|
headers?: Record<string, string>;
|
|
769
|
+
settings?: Settings;
|
|
746
770
|
logger?: ILogger;
|
|
747
771
|
parseConnector?: typeof parseYamlConnector;
|
|
748
772
|
parseOperationInputsFn?: typeof parseOperationInputs;
|
|
@@ -753,6 +777,7 @@ type BaseRunActionParams = {
|
|
|
753
777
|
getOperationForRefreshAuthenticationFn?: typeof getOperationForRefreshAuthentication;
|
|
754
778
|
getTestOperationsFn?: typeof getTestOperations;
|
|
755
779
|
getHttpClient: () => Promise<IHttpClient>;
|
|
780
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
756
781
|
};
|
|
757
782
|
type OperationIdMode = BaseRunActionParams & {
|
|
758
783
|
mode: 'operation_id';
|
|
@@ -796,6 +821,7 @@ declare const runConnectorAction: ({
|
|
|
796
821
|
headers,
|
|
797
822
|
logger,
|
|
798
823
|
getHttpClient,
|
|
824
|
+
getOlapClient,
|
|
799
825
|
parseConnector,
|
|
800
826
|
parseOperationInputsFn,
|
|
801
827
|
createBlockContextFn,
|
|
@@ -811,6 +837,7 @@ declare const runConnectorAction: ({
|
|
|
811
837
|
headers?: Record<string, string>;
|
|
812
838
|
logger?: ILogger;
|
|
813
839
|
getHttpClient: () => Promise<IHttpClient>;
|
|
840
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
814
841
|
parseConnector?: typeof parseYamlConnector;
|
|
815
842
|
parseOperationInputsFn?: typeof parseOperationInputs;
|
|
816
843
|
createBlockContextFn?: typeof createBlockContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IOlapClient } from "@stackone/olap";
|
|
1
2
|
import { ZodType } from "@stackone/utils";
|
|
2
3
|
import http from "node:http";
|
|
3
4
|
import https from "node:https";
|
|
@@ -467,6 +468,21 @@ type Authentication = {
|
|
|
467
468
|
};
|
|
468
469
|
};
|
|
469
470
|
//#endregion
|
|
471
|
+
//#region ../core/src/settings/types.d.ts
|
|
472
|
+
type Settings = {
|
|
473
|
+
olap: OlapSettings;
|
|
474
|
+
};
|
|
475
|
+
type OlapSettings = {
|
|
476
|
+
logs?: {
|
|
477
|
+
enabled: boolean;
|
|
478
|
+
};
|
|
479
|
+
advanced?: {
|
|
480
|
+
enabled?: boolean;
|
|
481
|
+
ttl?: number;
|
|
482
|
+
errorsOnly?: boolean;
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
//#endregion
|
|
470
486
|
//#region ../core/src/blocks/types.d.ts
|
|
471
487
|
type Block = {
|
|
472
488
|
inputs?: {
|
|
@@ -477,6 +493,8 @@ type Block = {
|
|
|
477
493
|
debug?: DebugParams;
|
|
478
494
|
steps?: StepsSnapshots;
|
|
479
495
|
httpClient?: IHttpClient;
|
|
496
|
+
olapClient?: IOlapClient;
|
|
497
|
+
settings?: Settings;
|
|
480
498
|
logger?: ILogger;
|
|
481
499
|
operation?: Operation;
|
|
482
500
|
credentials?: Credentials;
|
|
@@ -500,6 +518,7 @@ type BlockContext = {
|
|
|
500
518
|
operationType: OperationType;
|
|
501
519
|
authenticationType: string;
|
|
502
520
|
environment: string;
|
|
521
|
+
actionRunId?: string;
|
|
503
522
|
service: string;
|
|
504
523
|
resource: string;
|
|
505
524
|
subResource?: string;
|
|
@@ -571,8 +590,10 @@ declare const createBlock: ({
|
|
|
571
590
|
operation,
|
|
572
591
|
credentials,
|
|
573
592
|
nextCursor,
|
|
593
|
+
settings,
|
|
574
594
|
logger,
|
|
575
|
-
getHttpClient
|
|
595
|
+
getHttpClient,
|
|
596
|
+
getOlapClient
|
|
576
597
|
}: {
|
|
577
598
|
connector: Connector;
|
|
578
599
|
inputs?: Record<string, unknown>;
|
|
@@ -580,8 +601,10 @@ declare const createBlock: ({
|
|
|
580
601
|
operation?: Operation;
|
|
581
602
|
credentials?: Record<string, unknown>;
|
|
582
603
|
nextCursor?: Cursor;
|
|
604
|
+
settings?: Settings;
|
|
583
605
|
logger?: ILogger;
|
|
584
606
|
getHttpClient?: () => Promise<IHttpClient>;
|
|
607
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
585
608
|
}) => Promise<Block>;
|
|
586
609
|
//#endregion
|
|
587
610
|
//#region src/connectors/fileReader.d.ts
|
|
@@ -743,6 +766,7 @@ type BaseRunActionParams = {
|
|
|
743
766
|
queryParams?: unknown;
|
|
744
767
|
body?: unknown;
|
|
745
768
|
headers?: Record<string, string>;
|
|
769
|
+
settings?: Settings;
|
|
746
770
|
logger?: ILogger;
|
|
747
771
|
parseConnector?: typeof parseYamlConnector;
|
|
748
772
|
parseOperationInputsFn?: typeof parseOperationInputs;
|
|
@@ -753,6 +777,7 @@ type BaseRunActionParams = {
|
|
|
753
777
|
getOperationForRefreshAuthenticationFn?: typeof getOperationForRefreshAuthentication;
|
|
754
778
|
getTestOperationsFn?: typeof getTestOperations;
|
|
755
779
|
getHttpClient: () => Promise<IHttpClient>;
|
|
780
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
756
781
|
};
|
|
757
782
|
type OperationIdMode = BaseRunActionParams & {
|
|
758
783
|
mode: 'operation_id';
|
|
@@ -796,6 +821,7 @@ declare const runConnectorAction: ({
|
|
|
796
821
|
headers,
|
|
797
822
|
logger,
|
|
798
823
|
getHttpClient,
|
|
824
|
+
getOlapClient,
|
|
799
825
|
parseConnector,
|
|
800
826
|
parseOperationInputsFn,
|
|
801
827
|
createBlockContextFn,
|
|
@@ -811,6 +837,7 @@ declare const runConnectorAction: ({
|
|
|
811
837
|
headers?: Record<string, string>;
|
|
812
838
|
logger?: ILogger;
|
|
813
839
|
getHttpClient: () => Promise<IHttpClient>;
|
|
840
|
+
getOlapClient?: () => Promise<IOlapClient>;
|
|
814
841
|
parseConnector?: typeof parseYamlConnector;
|
|
815
842
|
parseOperationInputsFn?: typeof parseOperationInputs;
|
|
816
843
|
createBlockContextFn?: typeof createBlockContext;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@stackone/utils`)),l=s(require(`fs`)),u=s(require(`path`)),d=s(require(`path-to-regexp`)),f=s(require(`@stackone/core`)),p=s(require(`@stackone/transport`)),m=s(require(`yaml`)),h=s(require(`@stackone/expressions`)),g=async({connector:e,inputs:t,context:n,operation:r,credentials:i,nextCursor:a,
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@stackone/utils`)),l=s(require(`fs`)),u=s(require(`path`)),d=s(require(`path-to-regexp`)),f=s(require(`@stackone/core`)),p=s(require(`@stackone/transport`)),m=s(require(`yaml`)),h=s(require(`@stackone/expressions`)),g=async({connector:e,inputs:t,context:n,operation:r,credentials:i,nextCursor:a,settings:o,logger:s,getHttpClient:l,getOlapClient:u})=>{if((0,c.isMissing)(l))throw Error(`getHttpClient function is required`);let d=await l(),f=u?await u():void 0;return{connector:e,inputs:t,fieldConfigs:[],context:n,operation:r,credentials:i,nextCursor:a,httpClient:d,olapClient:f,settings:o,logger:s}},_=e=>{if(!e.endsWith(`.s1.yaml`))throw Error(`File must have .s1.yaml extension`);try{let t=(0,l.readFileSync)(e,`utf8`);if(!t.includes(`:`)||!t.includes(`$ref:`))return t;let n=t.split(`
|
|
2
2
|
`),r=v(n,(0,u.dirname)(e));return r.join(`
|
|
3
3
|
`)}catch(e){throw Error(`Failed to process YAML file: ${e.message}`)}},v=(e,t)=>{let n=[];for(let r of e)if(y(r)){let e=r.match(/^(\s*)/)?.[1]?.length||0,i=r.split(`:`)[1]?.trim(),a=b(i,t),o=a.map(t=>` `.repeat(e)+t);n.push(...o)}else n.push(r);return n},y=e=>e.includes(`$ref:`),b=(e,t)=>{let n=(0,u.resolve)((0,u.join)(t,`${e.replaceAll(`'`,``)}.s1.partial.yaml`));try{let e=(0,l.readFileSync)(n,`utf8`);return e.split(`
|
|
4
|
-
`).filter(e=>e.trim()!==``)}catch(t){throw Error(`Failed to load partial file '${e}': ${t.message}`)}},x=(e,t,n)=>{let r=n.toUpperCase();if(!e.operations)return;let i=Object.values(e.operations).filter(e=>(0,c.notMissing)(e.endpoint)).map(e=>({operationId:e.id,endpoint:e.endpoint})),a=C(t,r,i);if(a)return{operation:e.operations?.[a.operationId],params:a.params}},S=e=>{let t=e.startsWith(`/`)?e.slice(1):e,n=t.endsWith(`/`)?t.slice(0,-1):t;return n},C=(e,t,n)=>{let r=S(e);for(let e of n)if(e.endpoint?.startsWith(t)){let n=e.endpoint.replace(`${t} `,``).trim(),i=(0,d.match)(S(n)),a=i(S(r));if(a!==!1)return{operationId:e.operationId,path:e.endpoint,params:a.params}}},w=(e,t)=>t?.startsWith(`${e}_`)?t:`${e}_${t}`,ee=(e,t)=>{let n=`${e.key}_`,r=t.startsWith(n)?t:`${n}${t}`;return e.operations?.[r]};var T=class e extends Error{errorType;constructor(t,n){super(n),this.name=`InternalConnectSDKError`,this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},E=class extends T{line;constructor(e,t){super(`INVALID_YAML_FILE_ERROR`,t),this.name=`InvalidYamlFileError`,this.line=e??1}},D=class extends T{issues;constructor(e,t){super(`SCHEMA_VALIDATION_ERROR`,t),this.name=`SchemaValidationError`,this.issues=e}},O=class extends T{operationId;stepId;functionName;functionVersion;constructor(e,t,n,r=`1`){let i=`Invalid Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the function name and version are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION`,i),this.name=`InvalidStepFunctionError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r}},k=class extends T{operationId;stepId;functionName;functionVersion;issues;constructor(e,t,n,r=`1`,i){let a=`Invalid parameters for Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the parameters are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION_PARAMS`,a),this.name=`InvalidStepFunctionParamsError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r,this.issues=i,this.message=a}};const A=25,j=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},te=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},ne={key:c.z.string(),label:c.z.string(),required:c.z.boolean().optional().default(!1),secret:c.z.boolean().optional().default(!1),readOnly:c.z.boolean().optional().default(!1),placeholder:c.z.string().optional(),description:c.z.string().optional(),tooltip:c.z.string().optional()},re=c.z.discriminatedUnion(`type`,[(0,c.zStrictObject)({...ne,type:c.z.enum([`text`,`password`])}),(0,c.zStrictObject)({...ne,type:c.z.literal(`select`),options:(0,c.zStrictObject)({value:c.z.string(),label:c.z.string()}).array()})]),M=(0,c.zStrictObject)({targetFieldKey:c.z.string(),alias:c.z.string().optional(),expression:c.z.string().optional(),values:c.z.unknown().optional(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),enumMapper:(0,c.zStrictObject)({matcher:c.z.enum([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`,`document_file_format_from_extension`]).or((0,c.zStrictObject)({matchExpression:c.z.string(),value:c.z.string()}).array())}).optional(),properties:c.z.lazy(()=>M).array().optional()}),N=(0,c.zStrictObject)({name:c.z.string(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`object`]),required:c.z.boolean(),description:c.z.string(),array:c.z.boolean().optional().default(!1),in:c.z.enum([`body`,`query`,`path`,`headers`]),properties:c.z.lazy(()=>N.omit({in:!0})).array().optional()}),P=(0,c.zStrictObject)({operationId:c.z.string(),categories:c.z.string().array(),operationType:c.z.enum([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:c.z.string().optional(),schemaType:c.z.enum([`native`,`unified`]).optional().default(`native`),entrypointUrl:c.z.string().optional(),entrypointHttpMethod:c.z.string().optional(),label:c.z.string(),description:c.z.string(),tags:c.z.string().array().optional(),context:c.z.string().optional(),responses:(0,c.zStrictObject)({statusCode:c.z.number(),description:c.z.string()}).array().optional(),inputs:N.array().optional(),cursor:(0,c.zStrictObject)({enabled:c.z.boolean(),pageSize:c.z.number()}).optional(),compositeIdentifiers:(0,c.zStrictObject)({enabled:c.z.boolean(),version:c.z.number().optional(),fields:(0,c.zStrictObject)({targetFieldKey:c.z.string(),remote:c.z.string().optional(),components:c.z.string().array()}).array().optional()}).optional(),scheduledJobs:(0,c.zStrictObject)({enabled:c.z.boolean(),type:c.z.enum([`data_sync`]),schedule:c.z.string(),description:c.z.string(),requestParams:(0,c.zStrictObject)({fields:c.z.string().array().optional(),expand:c.z.string().array().optional(),filter:c.z.record(c.z.string(),c.z.string()).optional()}).optional(),syncFilter:(0,c.zStrictObject)({name:c.z.enum([`updated_after`,`created_after`]),initialLoopbackPeriod:c.z.string(),incrementalLoopbackPeriod:c.z.string()}).optional()}).array().optional(),fieldConfigs:M.array().optional(),steps:(0,c.zStrictObject)({stepId:c.z.string(),description:c.z.string(),stepFunction:(0,c.zStrictObject)({functionName:c.z.string(),version:c.z.string().optional(),parameters:c.z.record(c.z.string(),c.z.unknown())}),condition:c.z.string().optional(),ignoreError:c.z.boolean().optional()}).array(),result:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).optional()}),ie=(0,c.zStrictObject)({schedule:c.z.string().optional(),operation:P.extend({operationType:c.z.literal(`refresh_token`)})}),ae=(0,c.zStrictObject)({mainRatelimit:c.z.number(),subPools:c.z.array((0,c.zStrictObject)({subPoolKey:c.z.string(),urlPattern:c.z.string(),rateLimit:c.z.number()})).optional(),mappedRateLimitErrors:c.z.array((0,c.zStrictObject)({errorStatus:c.z.number(),errorMessage:c.z.string(),errorMessagePath:c.z.string().optional(),retryAfterPath:c.z.string().optional(),retryAfterUnit:c.z.union([c.z.literal(`seconds`),c.z.literal(`milliseconds`),c.z.literal(`date`)]).optional(),retryAfterValue:c.z.number().optional()})).optional()}),oe=(0,c.zStrictObject)({mainMaxConcurrency:c.z.number(),subPools:c.z.array((0,c.zStrictObject)({subPoolKey:c.z.string(),urlPattern:c.z.string(),maxConcurrency:c.z.number()})).optional()}),se=(0,c.zStrictObject)({StackOne:c.z.string(),info:(0,c.zStrictObject)({title:c.z.string(),version:c.z.string(),key:c.z.string(),assets:(0,c.zStrictObject)({icon:c.z.string()}),description:c.z.string()}),context:c.z.string().optional(),baseUrl:c.z.string(),authentication:c.z.record(c.z.string(),(0,c.zStrictObject)({type:c.z.string(),label:c.z.string(),authorization:f.AUTHENTICATION_SCHEMA,environments:(0,c.zStrictObject)({key:c.z.string(),name:c.z.string()}).array(),support:(0,c.zStrictObject)({link:c.z.string(),description:c.z.string().optional()}),configFields:re.array().optional(),setupFields:re.array().optional(),refreshAuthentication:ie.optional(),testOperations:(0,c.zStrictObject)({operation:c.z.string().or(P),condition:c.z.string().optional(),required:c.z.boolean().default(!0)}).array().optional()})).array().optional(),operations:P.array().optional(),rateLimit:ae.optional(),concurrency:oe.optional()}).strict();function F(e){try{let t=(0,m.parse)(e),n=Ce(se,t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},i=ue(n),a={baseUrl:n.baseUrl,authentication:I(i)},o=ge(n,a);return r.operations=o,ce(n.info.key,i,o,a),r.authentication=i,(0,c.notMissing)(o)&&(r.categories=le(Object.values(o))),r}catch(e){if(e instanceof T)throw e;let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;throw new E(r,t)}}const I=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=I(c)}else t[n]=r;return t},ce=(e,t,n,r)=>{if(!(!t||!n))for(let i of Object.values(t))for(let t of Object.values(i)){let i=t.testOperations;t.testOperations=i?.map(t=>{if((0,c.notMissing)(t.operation))if(typeof t.operation==`string`){let r=w(e,t.operation),i=Object.values(n).find(e=>e.id===r);if(i)return{...t,operation:i}}else{let n=w(e,t.operation.operationId),i=L(n,t.operation,r);return{...t,operation:i}}return t})}},le=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},ue=e=>{let t={};for(let n of e.authentication??[]){let[r]=Object.keys(n),i=n[r].environments.reduce((t,i)=>{let{key:a,name:o}=i,{environments:s,refreshAuthentication:l,testOperations:u,...d}=n[r],f=(0,c.notMissing)(l)?{schedule:l.schedule,operation:L(w(e.info.key,l.operation.operationId),l.operation)}:void 0;return t[a]={...d,refreshAuthentication:f,envKey:a,envName:o,testOperations:u},t},{});t[r]=i}return t},de=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,fe=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,pe=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},me=e=>{if(!(e.operationType===`refresh_token`||(0,c.isMissing)(e.schema)))return e.operationType===`list`?`/${e.schema}`:`/${e.schema}/:id`},he=e=>{let t={success:j(e.operationType),errors:te()},n=e.responses?.reduce((e,t)=>{let n=(0,p.isSuccessStatusCode)(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},ge=(e,t)=>{let n=e.operations?.reduce((n,r)=>{let i=de(r),a=fe(r),o=i??a,s=w(e.info.key,r.operationId);return n[s]=L(s,r,t,o),n},{});return n},L=(e,t,n,r)=>{let i=me(t),a=he(t),o=ye(t),s=t.inputs||[];o.enabled&&(s?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`,array:!1}),s?.push({type:`string`,name:`next`,in:`query`,required:!1,description:`Token for the next page of results`,array:!1}));let c=pe(t);return{id:e,categories:t.categories,label:t.label,description:t.description,operationType:t.operationType,schemaType:t.schemaType??`native`,entrypointUrl:t.entrypointUrl??i,entrypointHttpMethod:c,endpoint:r,tags:t.tags,context:t.context,responses:a,cursor:o,compositeIdentifiers:be(t),scheduledJobs:xe(t),inputs:s,steps:t.steps.reduce((e,r)=>{let{customErrors:i,...a}=r.stepFunction.parameters??{},o={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...Se({stepFunctionName:r.stepFunction.functionName,baseRequestParams:n,customErrors:i}),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:a.fields??t.fieldConfigs}:{},...a}}};return _e(t.operationId,o),e[r.stepId]=o,e},{}),result:t.result}},_e=(e,t)=>{let n=t.stepFunction.version??`1`,r=f.StepFunctionsRegistry[t.stepFunction.functionName]?.[`v${n}`];if(!r)throw new O(e,t.id,t.stepFunction.functionName,n);let i=r.inputSchema;i&&we(i,t.stepFunction.params,e,t.id,t.stepFunction.functionName,n)},R=(e,t)=>{if(!e.inputs)return{};let n=ve(e.inputs),r=c.z.object(n).parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},ve=e=>{let t=e.reduce((e,t)=>(e[t.in]||(e[t.in]=[]),e[t.in].push(t),e),{}),n={};for(let[e,r]of Object.entries(t)){let t={};for(let e of r){let n=z(e);e.description&&(n=n.describe(e.description)),e.required||(n=n.optional()),t[e.name]=n}Object.keys(t).length>0&&(n[e]=c.z.object(t))}return n},z=e=>{let t;switch(e.type){case`string`:case`datetime_string`:t=c.z.string();break;case`number`:t=c.z.number();break;case`boolean`:t=c.z.boolean();break;case`object`:if(e.properties&&e.properties.length>0){let n={};for(let t of e.properties){let e=z(t);t.description&&(e=e.describe(t.description)),t.required||(e=e.optional()),n[t.name]=e}t=c.z.object(n)}else t=c.z.record(c.z.string(),c.z.unknown());break;default:t=c.z.unknown()}return e.array&&(t=c.z.array(t)),t},ye=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:A};return{enabled:n.enabled&&t,pageSize:n.pageSize}},be=e=>{if(e.operationType===`refresh_token`)return{enabled:!1};if((0,c.isMissing)(e.compositeIdentifiers)){let t=e.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=(0,c.notMissing)(t)?[{targetFieldKey:t.targetFieldKey,remote:`id`,components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:f.COMPOSITE_ID_LATEST_VERSION,fields:n}}let t=[];for(let n of e.compositeIdentifiers?.fields??[]){let r=n.components.map(t=>{let n=e.fieldConfigs?.find(e=>e.targetFieldKey===t);return{name:t,alias:n?.alias}});t.push({targetFieldKey:n.targetFieldKey,remote:n.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},xe=e=>{if(!(0,c.isMissing)(e.scheduledJobs))return e.scheduledJobs},Se=({stepFunctionName:e,baseRequestParams:t,customErrors:n={}})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n&&Array.isArray(n)?n:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},Ce=(e,t)=>{let n=e.safeParse(t);if(n.success)return n.data;{let e=n.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new D(e,`Invalid connector schema`)}},we=(e,t,n,r,i,a)=>{let o=e.safeParse(t);if(o.success)return o.data;{let e=o.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new k(n,r,i,a,e)}},B=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if((0,c.notMissing)(r))return{operation:r,params:{}}},Te=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=B(e,t,n);return(0,c.notMissing)(r)},Ee=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},De=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},Oe=e=>{try{let t=F(e);return{success:!0,connector:t}}catch(t){if(t instanceof D){let n=t.issues,r=[];return n.forEach(t=>{let n=t?.keys?.[0],i=(0,c.isMissing)(n)?t.path:[...t.path,n],a=ke(i,e);r.push({line:a,message:t.message,field:i.join(`.`)})}),{success:!1,errors:r}}else if(t instanceof E)return{success:!1,errors:[{line:t.line,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]};else if(t instanceof O){let n=V(t.operationId,t.stepId,t.functionName,!1,e);return{success:!1,errors:[{line:n,message:t.message,field:void 0}]}}else if(t instanceof k){let n=t.issues,r=[];return n.forEach(n=>{let i=n?.keys?.[0],a=(0,c.isMissing)(i)?n.path:[...n.path,i],o=V(t.operationId,t.stepId,t.functionName,!0,e);r.push({line:o,message:n.message,field:a.join(`.`)})}),{success:!1,errors:r}}}return{success:!1,errors:[{line:1,message:`An unknown error occurred while parsing the connector.`,field:void 0}]}},ke=(e,t)=>{let n=t.split(`
|
|
5
|
-
`),r=0,i=-1,a=0;for(let t=0;t<n.length;t++){let o=n[t],s=o.match(/^(\s*)/)?.[1]?.length||0,l=o.replace(`- `,``).trim();if(l.startsWith(`#`)||l===``||s<=i)continue;let u=(0,c.notMissing)(e[r])?`${String(e[r])}`:``;if((0,c.isMissing)(u))return a+1;if(isNaN(Number(u))){if(l.startsWith(`${u}:`)){if(r===e.length-1)return t+1;i=s,a=t,r++}}else{let e=parseInt(u,10),i=-1;for(let o=t;o<n.length;o++){let s=n[o],c=s.trim();if(c.startsWith(`-`)&&i++,i===e){r++,a=t,t--;break}else t++}}}return a+1},
|
|
6
|
-
`),o=1,s=null,l=null;for(let i=0;i<a.length;i++){let u=a[i],d=u.trim();if((0,c.isMissing)(s)&&d===`- operationId: ${e}`){s=e,o=i+1;continue}if((0,c.notMissing)(s)&&(0,c.isMissing)(l)&&d===`- stepId: ${t}`){l=t,o=i+1;continue}if((0,c.notMissing)(s)&&(0,c.notMissing)(l)&&!r&&d.startsWith(`functionName: ${n}`)||(0,c.notMissing)(s)&&(0,c.notMissing)(l)&&r&&d===`parameters:`)return o=i+1,o}return o};var H=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},Ae=class extends H{constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},U=class extends H{constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},je=class extends H{constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},Me=class extends H{constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const W=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.title,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},Ne=(e,t)=>e.map(e=>W(e,t)),Pe=`stackone://internal//`,G=`${Pe}refresh_token`,Fe=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=f.StepFunctionsFactory.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===f.StepFunctionName.MAP_FIELDS?{[f.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},K=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),Ie=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,Le=e=>{let t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||(0,c.isMissing)(n))return e;let r=t.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),i={version:t.version??f.COMPOSITE_ID_LATEST_VERSION,aliases:r};return q(n,i,e.logger),{...e,inputs:n}},q=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))Ue(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)q(e,t,n);else typeof i==`object`&&i&&q(i,t,n)}},Re=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=(0,f.decodeCompositeId)(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},ze=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},Be=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},Ve=(e,t,n,r,i)=>{n.every(Be)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},He=(e,t,n)=>{e instanceof f.CoreError&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},Ue=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=Re(o,t,r,i);ze(n,t,s,a),Ve(n,t,s,c,a)}catch(e){He(e,t,i)}},J=`remote_`,We=e=>{let t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;let n=`data`,r=e.outputs?.[n];if((0,c.isMissing)(r))return e;let i=Array.isArray(r)?r.map(e=>Ge(e,t)):Ge(r,t);return{...e,outputs:{...e.outputs??{},[n]:i}}},Ge=(e,t)=>{let n=Ke(e,t),r=Y(n);return{...e,...(0,c.isObject)(r)?r:{}}},Ke=(e,t)=>{let n=t.version??f.COMPOSITE_ID_LATEST_VERSION,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=(0,f.encodeCompositeId)(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${J}${t.remote}`]=e[t.remote])}),{...e,...r}},qe=e=>e===`id`||/.+_id(s)?$/.test(e),Je=e=>Array.isArray(e)&&e.every(e=>(0,c.isString)(e)&&e.length>0),Ye=(e,t)=>(0,f.isCompositeId)(e)||t.startsWith(J),Xe=(e,t)=>{try{return(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION})}catch{return t}},Ze=(e,t,n)=>{let r=t.map(t=>(0,c.isString)(t)&&t.length>0&&!(0,f.isCompositeId)(t)?Xe(e,t):t);n[e]=r,n[`${J}${e}`]=t},Qe=(e,t,n)=>{if(Ye(t,e))return;let r=(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION});n[e]=r,n[`remote_${e}`]=t},$e=(e,t,n)=>{Je(t)?Ze(e,t,n):(0,c.isString)(t)&&t.length>0&&Qe(e,t,n)},Y=e=>{if(Array.isArray(e))return e.map(e=>Y(e));if(!(0,c.isObject)(e))return e;let t={...e};for(let[n,r]of Object.entries(e))((0,c.isObject)(r)||Array.isArray(r)&&r.length>0&&(0,c.isObject)(r[0]))&&(t[n]=Y(r)),qe(n)&&$e(n,r,t);return t},et=(e,t)=>{let n=Number(e.inputs?.page_size),r=(0,c.notMissing)(e.inputs?.page_size)&&(0,c.isNumber)(n)&&!Number.isNaN(n)?n:e.operation?.cursor?.pageSize??t;return r},tt=(e,t,n,r)=>{let i=(0,c.isMissing)(e)?void 0:e.data,a=Object.keys(n).length+1,o=(0,f.isCursorEmpty)({cursor:r,ignoreStepIndex:a});if(!(0,c.isObject)(e)||(0,c.isMissing)(i)||(i?.length??0)<=t)return{result:e,next:(0,c.notMissing)(r)&&!o?(0,f.minifyCursor)(r):null};let s=r?.remote?.[a]?.pageNumber??1,l=(s-1)*t,u=l+t,d=i.slice(l,u),p=i.length>u||!o,m=(0,f.updateCursor)({cursor:r,stepIndex:a,pageNumber:s+1});return{result:{...e,data:d},next:p?(0,f.minifyCursor)(m):null}},X=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=tt,encodeResultCompositeIds:r=We,decodeInputCompositeIds:i=Le})=>{let a=i(e),o=await st({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},nt=(e,t)=>e.condition?!(0,h.safeEvaluate)(e.condition,t):!1,rt=(e,t,n)=>{let r=e.stepFunction,i=f.StepFunctionsRegistry[e.stepFunction.functionName]?.[`v${e.stepFunction.version??1}`],a=(0,c.notMissing)(i?.inputSchema?.shape)?`cursor`in i?.inputSchema?.shape:!1;return t.operation?.cursor.enabled&&a?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},it=(e,t,n,r,i)=>{let a=Z({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},at=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(nt(o,r))return Z({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Z({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=rt(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return it(r,e,u,o,i);let d=r.operation?.cursor.enabled?(0,f.updateCursor)({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Z({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},ot=(e,t,n,r,i)=>{let a=!n.hasFatalError,o=a?e.operation?.responses.success.statusCode??200:n.errorStatusCode??500,s=(0,c.notMissing)(i)&&(0,c.isObject)(i.result)?{next:i.next,...i.result}:r;return{...t,outputs:s,response:{successful:a,statusCode:o,message:a?void 0:e.operation?.responses?.errors?.[o]?.description??p.HttpErrorMessages?.[o]??`Error while processing the request`}}},st=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=tt})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=et(e,A),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await at(t,e,r,i,s,c);let l=e.operation?.result?ct(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return ot(e,i,s,l,u)},ct=(e,t)=>(0,c.isObject)(e)?(0,h.safeEvaluateRecord)(e,t):(0,h.safeEvaluate)(e,t),Z=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),Q=async e=>{let{pathParams:t={},queryParams:n={},body:r={},headers:i={},parseConnector:a=F,parseOperationInputsFn:o=R,createBlockContextFn:s=K,createBlockFn:l=g,runStepOperationFn:u=X,getOperationFromUrlFn:d=x,getOperationForRefreshAuthenticationFn:f=B,getTestOperationsFn:p=Ie,mode:m,account:_,connector:v,getHttpClient:y,logger:b,category:S,...C}=e,w=_.authConfigKey,T=_.environment??`production`,E=_.secureId,D=_.projectSecureId,O=_.credentials,k=s({category:S??`action`,connectorKey:_.providerKey,connectorVersion:_.providerVersion,authConfigKey:w,environment:T,accountSecureId:E,projectSecureId:D}),A;try{A=(0,c.isString)(v)?a(v):v}catch{throw new Ae(k,`Error while parsing connector`)}let j={connector:A,context:k,credentials:O,logger:b,getHttpClient:y};if(m===`operation_id`){let{operationId:e}=C,a=ee(A,e);if((0,c.isMissing)(a))throw new U(k,`No matching operation found`);return await $({operation:a,blockContext:k,queryParams:n,pathParams:t,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:j,runStepOperationFn:u})}else if(m===`test_operations`){let e=p(A,w,T);if((0,c.isMissing)(e)||e.length===0)return lt(l,j);k.operationType=`test`;for(let t of e){let e=await l({...j,inputs:void 0,operation:t.operation,nextCursor:void 0}),n=(0,c.notMissing)(t.condition)?(0,h.evaluate)(t.condition,e):!0;if(!n)continue;let r=await u({block:e});if(((0,c.isMissing)(r?.response?.successful)||!r.response.successful)&&t.required)return b?.error({code:`TestOperationFailed`,message:`Test operation "${t.operation.id}" failed with error: ${r?.response?.message}`}),ut(l,j)}return lt(l,j)}else if(m===`refresh_authentication`){let e=f(A,w,T);if((0,c.isMissing)(e))throw new U(k,`No matching operation found`);return await $({operation:e.operation,blockContext:k,queryParams:n,pathParams:e.params,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:j,runStepOperationFn:u})}else if(m===`path`){let{path:e,method:t}=C,a=d(A,e,t);if((0,c.isMissing)(a))throw new U(k,`No matching operation found`);return await $({operation:a.operation,blockContext:k,queryParams:n,pathParams:a.params,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:j,runStepOperationFn:u})}else return ut(l,j)},$=async e=>{let{operation:t,blockContext:n,queryParams:r,pathParams:i,body:a,headers:o,parseOperationInputsFn:s,createBlockFn:c,createBlockParams:l,runStepOperationFn:u}=e;n.operationType=t.operationType,n.schema=t.schema?.key;let d=dt(r,n),f;try{f=s(t,{path:i,query:r,body:a,headers:o})}catch{throw new je(n,`Error while parsing operation inputs`)}let p=await c({...l,inputs:f,operation:t,nextCursor:d});return await u({block:p})},lt=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!0,statusCode:200}}},ut=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!1,statusCode:500}}},dt=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new Me(t,`Invalid cursor.`);return r},ft=async({operationId:e,account:t,connector:n,pathParams:r={},queryParams:i={},body:a={},headers:o={},logger:s,getHttpClient:c,parseConnector:l=F,parseOperationInputsFn:u=R,createBlockContextFn:d=K,createBlockFn:f=g,runStepOperationFn:p=X})=>Q({mode:`operation_id`,operationId:e,account:t,connector:n,pathParams:r,queryParams:i,body:a,headers:o,logger:s,getHttpClient:c,parseConnector:l,parseOperationInputsFn:u,createBlockContextFn:d,createBlockFn:f,runStepOperationFn:p}),pt=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=F,getOperationFromUrlFn:d=x,getOperationForRefreshAuthenticationFn:f=B,parseOperationInputsFn:p=R,createBlockContextFn:m=K,createBlockFn:h=g,runStepOperationFn:_=X})=>{let v=mt(r),y=v?await Q({mode:`refresh_authentication`,account:e,connector:t,getOperationForRefreshAuthenticationFn:f,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:_}):await Q({mode:`path`,account:e,category:n,connector:t,path:r,method:i,queryParams:a,body:o,headers:s,getOperationFromUrlFn:d,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:_});return y},mt=e=>e===G,ht=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=F,getTestOperationsFn:a=Ie,createBlockContextFn:o=K,createBlockFn:s=g,runStepOperationFn:c=X})=>{let l=await Q({mode:`test_operations`,account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i,getTestOperationsFn:a,createBlockContextFn:o,createBlockFn:s,runStepOperationFn:c});return l?.response?.successful??!1};exports.ConnectSDKError=H,exports.REFRESH_TOKEN_OPERATION_PATH=G,exports.createBlock=g,exports.executeStepFunction=Fe,exports.getActionsMeta=W,exports.getActionsMetaFromConnectors=Ne,exports.getOperationFromUrl=x,exports.getRefreshTokenExpiresIn=De,exports.getTokenExpiresIn=Ee,exports.loadConnector=_,exports.parseOperationInputs=R,exports.parseYamlConnector=F,exports.runAction=Q,exports.runConnectorAction=ft,exports.runConnectorOperation=pt,exports.runStepOperation=X,exports.runTestOperations=ht,exports.supportsRefreshAuthentication=Te,exports.validateYamlConnector=Oe;
|
|
4
|
+
`).filter(e=>e.trim()!==``)}catch(t){throw Error(`Failed to load partial file '${e}': ${t.message}`)}},x=(e,t,n)=>{let r=n.toUpperCase();if(!e.operations)return;let i=Object.values(e.operations).filter(e=>(0,c.notMissing)(e.endpoint)).map(e=>({operationId:e.id,endpoint:e.endpoint})),a=C(t,r,i);if(a)return{operation:e.operations?.[a.operationId],params:a.params}},S=e=>{let t=e.startsWith(`/`)?e.slice(1):e,n=t.endsWith(`/`)?t.slice(0,-1):t;return n},C=(e,t,n)=>{let r=S(e);for(let e of n)if(e.endpoint?.startsWith(t)){let n=e.endpoint.replace(`${t} `,``).trim(),i=(0,d.match)(S(n)),a=i(S(r));if(a!==!1)return{operationId:e.operationId,path:e.endpoint,params:a.params}}},w=(e,t)=>t?.startsWith(`${e}_`)?t:`${e}_${t}`,ee=(e,t)=>{let n=`${e.key}_`,r=t.startsWith(n)?t:`${n}${t}`;return e.operations?.[r]};var T=class e extends Error{errorType;constructor(t,n){super(n),this.name=`InternalConnectSDKError`,this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},E=class extends T{line;constructor(e,t){super(`INVALID_YAML_FILE_ERROR`,t),this.name=`InvalidYamlFileError`,this.line=e??1}},D=class extends T{issues;constructor(e,t){super(`SCHEMA_VALIDATION_ERROR`,t),this.name=`SchemaValidationError`,this.issues=e}},O=class extends T{operationId;stepId;functionName;functionVersion;constructor(e,t,n,r=`1`){let i=`Invalid Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the function name and version are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION`,i),this.name=`InvalidStepFunctionError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r}},k=class extends T{operationId;stepId;functionName;functionVersion;issues;constructor(e,t,n,r=`1`,i){let a=`Invalid parameters for Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the parameters are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION_PARAMS`,a),this.name=`InvalidStepFunctionParamsError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r,this.issues=i,this.message=a}};const A=25,j=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},M=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},N={key:c.z.string(),label:c.z.string(),required:c.z.boolean().optional().default(!1),secret:c.z.boolean().optional().default(!1),readOnly:c.z.boolean().optional().default(!1),placeholder:c.z.string().optional(),description:c.z.string().optional(),tooltip:c.z.string().optional()},P=c.z.discriminatedUnion(`type`,[(0,c.zStrictObject)({...N,type:c.z.enum([`text`,`password`])}),(0,c.zStrictObject)({...N,type:c.z.literal(`select`),options:(0,c.zStrictObject)({value:c.z.string(),label:c.z.string()}).array()})]),te=(0,c.zStrictObject)({targetFieldKey:c.z.string(),alias:c.z.string().optional(),expression:c.z.string().optional(),values:c.z.unknown().optional(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),enumMapper:(0,c.zStrictObject)({matcher:c.z.enum([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`,`document_file_format_from_extension`]).or((0,c.zStrictObject)({matchExpression:c.z.string(),value:c.z.string()}).array())}).optional(),properties:c.z.lazy(()=>te).array().optional()}),ne=(0,c.zStrictObject)({name:c.z.string(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`object`]),required:c.z.boolean(),description:c.z.string(),array:c.z.boolean().optional().default(!1),in:c.z.enum([`body`,`query`,`path`,`headers`]),properties:c.z.lazy(()=>ne.omit({in:!0})).array().optional()}),F=(0,c.zStrictObject)({operationId:c.z.string(),categories:c.z.string().array(),operationType:c.z.enum([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:c.z.string().optional(),schemaType:c.z.enum([`native`,`unified`]).optional().default(`native`),entrypointUrl:c.z.string().optional(),entrypointHttpMethod:c.z.string().optional(),label:c.z.string(),description:c.z.string(),tags:c.z.string().array().optional(),context:c.z.string().optional(),responses:(0,c.zStrictObject)({statusCode:c.z.number(),description:c.z.string()}).array().optional(),inputs:ne.array().optional(),cursor:(0,c.zStrictObject)({enabled:c.z.boolean(),pageSize:c.z.number()}).optional(),compositeIdentifiers:(0,c.zStrictObject)({enabled:c.z.boolean(),version:c.z.number().optional(),fields:(0,c.zStrictObject)({targetFieldKey:c.z.string(),remote:c.z.string().optional(),components:c.z.string().array()}).array().optional()}).optional(),scheduledJobs:(0,c.zStrictObject)({enabled:c.z.boolean(),type:c.z.enum([`data_sync`]),schedule:c.z.string(),description:c.z.string(),requestParams:(0,c.zStrictObject)({fields:c.z.string().array().optional(),expand:c.z.string().array().optional(),filter:c.z.record(c.z.string(),c.z.string()).optional()}).optional(),syncFilter:(0,c.zStrictObject)({name:c.z.enum([`updated_after`,`created_after`]),initialLoopbackPeriod:c.z.string(),incrementalLoopbackPeriod:c.z.string()}).optional()}).array().optional(),fieldConfigs:te.array().optional(),steps:(0,c.zStrictObject)({stepId:c.z.string(),description:c.z.string(),stepFunction:(0,c.zStrictObject)({functionName:c.z.string(),version:c.z.string().optional(),parameters:c.z.record(c.z.string(),c.z.unknown())}),condition:c.z.string().optional(),ignoreError:c.z.boolean().optional()}).array(),result:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).optional()}),re=(0,c.zStrictObject)({schedule:c.z.string().optional(),operation:F.extend({operationType:c.z.literal(`refresh_token`)})}),ie=(0,c.zStrictObject)({mainRatelimit:c.z.number(),subPools:c.z.array((0,c.zStrictObject)({subPoolKey:c.z.string(),urlPattern:c.z.string(),rateLimit:c.z.number()})).optional(),mappedRateLimitErrors:c.z.array((0,c.zStrictObject)({errorStatus:c.z.number(),errorMessage:c.z.string(),errorMessagePath:c.z.string().optional(),retryAfterPath:c.z.string().optional(),retryAfterUnit:c.z.union([c.z.literal(`seconds`),c.z.literal(`milliseconds`),c.z.literal(`date`)]).optional(),retryAfterValue:c.z.number().optional()})).optional()}),ae=(0,c.zStrictObject)({mainMaxConcurrency:c.z.number(),subPools:c.z.array((0,c.zStrictObject)({subPoolKey:c.z.string(),urlPattern:c.z.string(),maxConcurrency:c.z.number()})).optional()}),oe=(0,c.zStrictObject)({StackOne:c.z.string(),info:(0,c.zStrictObject)({title:c.z.string(),version:c.z.string(),key:c.z.string(),assets:(0,c.zStrictObject)({icon:c.z.string()}),description:c.z.string()}),context:c.z.string().optional(),baseUrl:c.z.string(),authentication:c.z.record(c.z.string(),(0,c.zStrictObject)({type:c.z.string(),label:c.z.string(),authorization:f.AUTHENTICATION_SCHEMA,environments:(0,c.zStrictObject)({key:c.z.string(),name:c.z.string()}).array(),support:(0,c.zStrictObject)({link:c.z.string(),description:c.z.string().optional()}),configFields:P.array().optional(),setupFields:P.array().optional(),refreshAuthentication:re.optional(),testOperations:(0,c.zStrictObject)({operation:c.z.string().or(F),condition:c.z.string().optional(),required:c.z.boolean().default(!0)}).array().optional()})).array().optional(),operations:F.array().optional(),rateLimit:ie.optional(),concurrency:ae.optional()}).strict();function I(e){try{let t=(0,m.parse)(e),n=Se(oe,t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},i=le(n),a={baseUrl:n.baseUrl,authentication:L(i)},o=he(n,a);return r.operations=o,se(n.info.key,i,o,a),r.authentication=i,(0,c.notMissing)(o)&&(r.categories=ce(Object.values(o))),r}catch(e){if(e instanceof T)throw e;let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;throw new E(r,t)}}const L=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=L(c)}else t[n]=r;return t},se=(e,t,n,r)=>{if(!(!t||!n))for(let i of Object.values(t))for(let t of Object.values(i)){let i=t.testOperations;t.testOperations=i?.map(t=>{if((0,c.notMissing)(t.operation))if(typeof t.operation==`string`){let r=w(e,t.operation),i=Object.values(n).find(e=>e.id===r);if(i)return{...t,operation:i}}else{let n=w(e,t.operation.operationId),i=R(n,t.operation,r);return{...t,operation:i}}return t})}},ce=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},le=e=>{let t={};for(let n of e.authentication??[]){let[r]=Object.keys(n),i=n[r].environments.reduce((t,i)=>{let{key:a,name:o}=i,{environments:s,refreshAuthentication:l,testOperations:u,...d}=n[r],f=(0,c.notMissing)(l)?{schedule:l.schedule,operation:R(w(e.info.key,l.operation.operationId),l.operation)}:void 0;return t[a]={...d,refreshAuthentication:f,envKey:a,envName:o,testOperations:u},t},{});t[r]=i}return t},ue=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,de=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,fe=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},pe=e=>{if(!(e.operationType===`refresh_token`||(0,c.isMissing)(e.schema)))return e.operationType===`list`?`/${e.schema}`:`/${e.schema}/:id`},me=e=>{let t={success:j(e.operationType),errors:M()},n=e.responses?.reduce((e,t)=>{let n=(0,p.isSuccessStatusCode)(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},he=(e,t)=>{let n=e.operations?.reduce((n,r)=>{let i=ue(r),a=de(r),o=i??a,s=w(e.info.key,r.operationId);return n[s]=R(s,r,t,o),n},{});return n},R=(e,t,n,r)=>{let i=pe(t),a=me(t),o=ve(t),s=t.inputs||[];o.enabled&&(s?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`,array:!1}),s?.push({type:`string`,name:`next`,in:`query`,required:!1,description:`Token for the next page of results`,array:!1}));let c=fe(t);return{id:e,categories:t.categories,label:t.label,description:t.description,operationType:t.operationType,schemaType:t.schemaType??`native`,entrypointUrl:t.entrypointUrl??i,entrypointHttpMethod:c,endpoint:r,tags:t.tags,context:t.context,responses:a,cursor:o,compositeIdentifiers:ye(t),scheduledJobs:be(t),inputs:s,steps:t.steps.reduce((e,r)=>{let{customErrors:i,...a}=r.stepFunction.parameters??{},o={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...xe({stepFunctionName:r.stepFunction.functionName,baseRequestParams:n,customErrors:i}),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:a.fields??t.fieldConfigs}:{},...a}}};return ge(t.operationId,o),e[r.stepId]=o,e},{}),result:t.result}},ge=(e,t)=>{let n=t.stepFunction.version??`1`,r=f.StepFunctionsRegistry[t.stepFunction.functionName]?.[`v${n}`];if(!r)throw new O(e,t.id,t.stepFunction.functionName,n);let i=r.inputSchema;i&&Ce(i,t.stepFunction.params,e,t.id,t.stepFunction.functionName,n)},z=(e,t)=>{if(!e.inputs)return{};let n=_e(e.inputs),r=c.z.object(n).parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},_e=e=>{let t=e.reduce((e,t)=>(e[t.in]||(e[t.in]=[]),e[t.in].push(t),e),{}),n={};for(let[e,r]of Object.entries(t)){let t={};for(let e of r){let n=B(e);e.description&&(n=n.describe(e.description)),e.required||(n=n.optional()),t[e.name]=n}Object.keys(t).length>0&&(n[e]=c.z.object(t))}return n},B=e=>{let t;switch(e.type){case`string`:case`datetime_string`:t=c.z.string();break;case`number`:t=c.z.number();break;case`boolean`:t=c.z.boolean();break;case`object`:if(e.properties&&e.properties.length>0){let n={};for(let t of e.properties){let e=B(t);t.description&&(e=e.describe(t.description)),t.required||(e=e.optional()),n[t.name]=e}t=c.z.object(n)}else t=c.z.record(c.z.string(),c.z.unknown());break;default:t=c.z.unknown()}return e.array&&(t=c.z.array(t)),t},ve=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:A};return{enabled:n.enabled&&t,pageSize:n.pageSize}},ye=e=>{if(e.operationType===`refresh_token`)return{enabled:!1};if((0,c.isMissing)(e.compositeIdentifiers)){let t=e.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=(0,c.notMissing)(t)?[{targetFieldKey:t.targetFieldKey,remote:`id`,components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:f.COMPOSITE_ID_LATEST_VERSION,fields:n}}let t=[];for(let n of e.compositeIdentifiers?.fields??[]){let r=n.components.map(t=>{let n=e.fieldConfigs?.find(e=>e.targetFieldKey===t);return{name:t,alias:n?.alias}});t.push({targetFieldKey:n.targetFieldKey,remote:n.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},be=e=>{if(!(0,c.isMissing)(e.scheduledJobs))return e.scheduledJobs},xe=({stepFunctionName:e,baseRequestParams:t,customErrors:n={}})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n&&Array.isArray(n)?n:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},Se=(e,t)=>{let n=e.safeParse(t);if(n.success)return n.data;{let e=n.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new D(e,`Invalid connector schema`)}},Ce=(e,t,n,r,i,a)=>{let o=e.safeParse(t);if(o.success)return o.data;{let e=o.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new k(n,r,i,a,e)}},V=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if((0,c.notMissing)(r))return{operation:r,params:{}}},we=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=V(e,t,n);return(0,c.notMissing)(r)},Te=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},Ee=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},De=e=>{try{let t=I(e);return{success:!0,connector:t}}catch(t){if(t instanceof D){let n=t.issues,r=[];return n.forEach(t=>{let n=t?.keys?.[0],i=(0,c.isMissing)(n)?t.path:[...t.path,n],a=Oe(i,e);r.push({line:a,message:t.message,field:i.join(`.`)})}),{success:!1,errors:r}}else if(t instanceof E)return{success:!1,errors:[{line:t.line,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]};else if(t instanceof O){let n=H(t.operationId,t.stepId,t.functionName,!1,e);return{success:!1,errors:[{line:n,message:t.message,field:void 0}]}}else if(t instanceof k){let n=t.issues,r=[];return n.forEach(n=>{let i=n?.keys?.[0],a=(0,c.isMissing)(i)?n.path:[...n.path,i],o=H(t.operationId,t.stepId,t.functionName,!0,e);r.push({line:o,message:n.message,field:a.join(`.`)})}),{success:!1,errors:r}}}return{success:!1,errors:[{line:1,message:`An unknown error occurred while parsing the connector.`,field:void 0}]}},Oe=(e,t)=>{let n=t.split(`
|
|
5
|
+
`),r=0,i=-1,a=0;for(let t=0;t<n.length;t++){let o=n[t],s=o.match(/^(\s*)/)?.[1]?.length||0,l=o.replace(`- `,``).trim();if(l.startsWith(`#`)||l===``||s<=i)continue;let u=(0,c.notMissing)(e[r])?`${String(e[r])}`:``;if((0,c.isMissing)(u))return a+1;if(isNaN(Number(u))){if(l.startsWith(`${u}:`)){if(r===e.length-1)return t+1;i=s,a=t,r++}}else{let e=parseInt(u,10),i=-1;for(let o=t;o<n.length;o++){let s=n[o],c=s.trim();if(c.startsWith(`-`)&&i++,i===e){r++,a=t,t--;break}else t++}}}return a+1},H=(e,t,n,r,i)=>{let a=i.split(`
|
|
6
|
+
`),o=1,s=null,l=null;for(let i=0;i<a.length;i++){let u=a[i],d=u.trim();if((0,c.isMissing)(s)&&d===`- operationId: ${e}`){s=e,o=i+1;continue}if((0,c.notMissing)(s)&&(0,c.isMissing)(l)&&d===`- stepId: ${t}`){l=t,o=i+1;continue}if((0,c.notMissing)(s)&&(0,c.notMissing)(l)&&!r&&d.startsWith(`functionName: ${n}`)||(0,c.notMissing)(s)&&(0,c.notMissing)(l)&&r&&d===`parameters:`)return o=i+1,o}return o};var U=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},ke=class extends U{constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},W=class extends U{constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},Ae=class extends U{constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},je=class extends U{constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const Me=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.title,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},Ne=(e,t)=>e.map(e=>Me(e,t)),Pe=`stackone://internal//`,Fe=`${Pe}refresh_token`,Ie=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=f.StepFunctionsFactory.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===f.StepFunctionName.MAP_FIELDS?{[f.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},G=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i,actionRunId:(0,c.generateActionRunId)()}),Le=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,Re=e=>{let t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||(0,c.isMissing)(n))return e;let r=t.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),i={version:t.version??f.COMPOSITE_ID_LATEST_VERSION,aliases:r};return K(n,i,e.logger),{...e,inputs:n}},K=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))We(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)K(e,t,n);else typeof i==`object`&&i&&K(i,t,n)}},ze=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=(0,f.decodeCompositeId)(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},Be=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},Ve=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},He=(e,t,n,r,i)=>{n.every(Ve)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},Ue=(e,t,n)=>{e instanceof f.CoreError&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},We=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=ze(o,t,r,i);Be(n,t,s,a),He(n,t,s,c,a)}catch(e){Ue(e,t,i)}},q=`remote_`,Ge=e=>{let t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;let n=`data`,r=e.outputs?.[n];if((0,c.isMissing)(r))return e;let i=Array.isArray(r)?r.map(e=>Ke(e,t)):Ke(r,t);return{...e,outputs:{...e.outputs??{},[n]:i}}},Ke=(e,t)=>{let n=qe(e,t),r=J(n);return{...e,...(0,c.isObject)(r)?r:{}}},qe=(e,t)=>{let n=t.version??f.COMPOSITE_ID_LATEST_VERSION,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=(0,f.encodeCompositeId)(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${q}${t.remote}`]=e[t.remote])}),{...e,...r}},Je=e=>e===`id`||/.+_id(s)?$/.test(e),Ye=e=>Array.isArray(e)&&e.every(e=>(0,c.isString)(e)&&e.length>0),Xe=(e,t)=>(0,f.isCompositeId)(e)||t.startsWith(q),Ze=(e,t)=>{try{return(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION})}catch{return t}},Qe=(e,t,n)=>{let r=t.map(t=>(0,c.isString)(t)&&t.length>0&&!(0,f.isCompositeId)(t)?Ze(e,t):t);n[e]=r,n[`${q}${e}`]=t},$e=(e,t,n)=>{if(Xe(t,e))return;let r=(0,f.encodeCompositeId)({key:e,value:t},{version:f.COMPOSITE_ID_LATEST_VERSION});n[e]=r,n[`remote_${e}`]=t},et=(e,t,n)=>{Ye(t)?Qe(e,t,n):(0,c.isString)(t)&&t.length>0&&$e(e,t,n)},J=e=>{if(Array.isArray(e))return e.map(e=>J(e));if(!(0,c.isObject)(e))return e;let t={...e};for(let[n,r]of Object.entries(e))((0,c.isObject)(r)||Array.isArray(r)&&r.length>0&&(0,c.isObject)(r[0]))&&(t[n]=J(r)),Je(n)&&et(n,r,t);return t},tt=(e,t)=>{let n=Number(e.inputs?.page_size),r=(0,c.notMissing)(e.inputs?.page_size)&&(0,c.isNumber)(n)&&!Number.isNaN(n)?n:e.operation?.cursor?.pageSize??t;return r},nt=(e,t,n,r)=>{let i=(0,c.isMissing)(e)?void 0:e.data,a=Object.keys(n).length+1,o=(0,f.isCursorEmpty)({cursor:r,ignoreStepIndex:a});if(!(0,c.isObject)(e)||(0,c.isMissing)(i)||(i?.length??0)<=t)return{result:e,next:(0,c.notMissing)(r)&&!o?(0,f.minifyCursor)(r):null};let s=r?.remote?.[a]?.pageNumber??1,l=(s-1)*t,u=l+t,d=i.slice(l,u),p=i.length>u||!o,m=(0,f.updateCursor)({cursor:r,stepIndex:a,pageNumber:s+1});return{result:{...e,data:d},next:p?(0,f.minifyCursor)(m):null}},rt=e=>{let t=e.settings?.olap;return(0,c.isMissing)(t)?{}:{logs:t.logs?{enabled:t.logs.enabled}:void 0,advanced:t.advanced?{enabled:t.advanced.enabled,ttl:t.advanced.ttl,errorsOnly:t.advanced.errorsOnly}:void 0}},Y=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=nt,encodeResultCompositeIds:r=Ge,decodeInputCompositeIds:i=Re})=>{let a=i(e),o=await lt({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},it=(e,t)=>e.condition?!(0,h.safeEvaluate)(e.condition,t):!1,at=(e,t,n)=>{let r=e.stepFunction,i=f.StepFunctionsRegistry[e.stepFunction.functionName]?.[`v${e.stepFunction.version??1}`],a=(0,c.notMissing)(i?.inputSchema?.shape)?`cursor`in i?.inputSchema?.shape:!1;return t.operation?.cursor.enabled&&a?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},ot=(e,t,n,r,i)=>{let a=X({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},st=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(it(o,r))return X({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return X({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=at(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return ot(r,e,u,o,i);let d=r.operation?.cursor.enabled?(0,f.updateCursor)({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return X({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},ct=(e,t,n,r,i)=>{let a=!n.hasFatalError,o=a?e.operation?.responses.success.statusCode??200:n.errorStatusCode??500,s=(0,c.notMissing)(i)&&(0,c.isObject)(i.result)?{next:i.next,...i.result}:r;return{...t,outputs:s,response:{successful:a,statusCode:o,message:a?void 0:e.operation?.responses?.errors?.[o]?.description??p.HttpErrorMessages?.[o]??`Error while processing the request`}}},lt=async({block:e,buildStepFunction:t=f.StepFunctionsFactory.build,virtualPaginateResultFn:n=nt})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=tt(e,A),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await st(t,e,r,i,s,c),dt({block:i,stepId:t});let l=e.operation?.result?ut(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return ct(e,i,s,l,u)},ut=(e,t)=>(0,c.isObject)(e)?(0,h.safeEvaluateRecord)(e,t):(0,h.safeEvaluate)(e,t),X=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),dt=({block:e,stepId:t})=>{let n=e.olapClient;if((0,c.isMissing)(n?.recordStep))return;let r=rt(e);n.recordStep({stepId:t,status:e.steps?.[t]?.successful?`success`:`error`},r)},Z=async e=>{let{pathParams:t={},queryParams:n={},body:r={},headers:i={},parseConnector:a=I,parseOperationInputsFn:o=z,createBlockContextFn:s=G,createBlockFn:l=g,runStepOperationFn:u=Y,getOperationFromUrlFn:d=x,getOperationForRefreshAuthenticationFn:f=V,getTestOperationsFn:p=Le,mode:m,account:_,connector:v,getHttpClient:y,getOlapClient:b,settings:S,logger:C,category:w,...T}=e,E=_.authConfigKey,D=_.environment??`production`,O=_.secureId,k=_.projectSecureId,A=_.credentials,j=s({category:w??`action`,connectorKey:_.providerKey,connectorVersion:_.providerVersion,authConfigKey:E,environment:D,accountSecureId:O,projectSecureId:k}),M;try{M=(0,c.isString)(v)?a(v):v}catch{throw new ke(j,`Error while parsing connector`)}let N={connector:M,context:j,credentials:A,settings:S,logger:C,getHttpClient:y,getOlapClient:b};if(m===`operation_id`){let{operationId:e}=T,a=ee(M,e);if((0,c.isMissing)(a))throw new W(j,`No matching operation found`);let s=await Q({operation:a,blockContext:j,queryParams:n,pathParams:t,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:N,runStepOperationFn:u});return $({block:s}),s}else if(m===`test_operations`){let e=p(M,E,D);if((0,c.isMissing)(e)||e.length===0){let e=await ft(l,N);return $({block:e}),e}j.operationType=`test`;for(let t of e){let e=await l({...N,inputs:void 0,operation:t.operation,nextCursor:void 0}),n=(0,c.notMissing)(t.condition)?(0,h.evaluate)(t.condition,e):!0;if(!n)continue;let r=await u({block:e});if(((0,c.isMissing)(r?.response?.successful)||!r.response.successful)&&t.required){C?.error({code:`TestOperationFailed`,message:`Test operation "${t.operation.id}" failed with error: ${r?.response?.message}`});let e=await pt(l,N);return $({block:e}),e}}let t=await ft(l,N);return $({block:t}),t}else if(m===`refresh_authentication`){let e=f(M,E,D);if((0,c.isMissing)(e))throw new W(j,`No matching operation found`);let t=await Q({operation:e.operation,blockContext:j,queryParams:n,pathParams:e.params,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:N,runStepOperationFn:u});return $({block:t}),t}else if(m===`path`){let{path:e,method:t}=T,a=d(M,e,t);if((0,c.isMissing)(a))throw new W(j,`No matching operation found`);let s=await Q({operation:a.operation,blockContext:j,queryParams:n,pathParams:a.params,body:r,headers:i,parseOperationInputsFn:o,createBlockFn:l,createBlockParams:N,runStepOperationFn:u});return $({block:s}),s}else{let e=await pt(l,N);return $({block:e}),e}},Q=async e=>{let{operation:t,blockContext:n,queryParams:r,pathParams:i,body:a,headers:o,parseOperationInputsFn:s,createBlockFn:c,createBlockParams:l,runStepOperationFn:u}=e;n.operationType=t.operationType,n.schema=t.schema?.key;let d=mt(r,n),f;try{f=s(t,{path:i,query:r,body:a,headers:o})}catch{throw new Ae(n,`Error while parsing operation inputs`)}let p=await c({...l,inputs:f,operation:t,nextCursor:d});return await u({block:p})},ft=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!0,statusCode:200}}},pt=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!1,statusCode:500}}},mt=(e,t)=>{let n=e?.next,r=(0,c.notMissing)(n)&&t.operationType===`list`?(0,f.expandCursor)(n):void 0;if(r===null)throw new je(t,`Invalid cursor.`);return r},$=({block:e})=>{let t=e.olapClient;if((0,c.isMissing)(t?.recordAction))return;let n=rt(e);t.recordAction({status:e.response?.successful?`success`:`error`,message:e.response?.message,outputs:e.outputs},n)},ht=async({operationId:e,account:t,connector:n,pathParams:r={},queryParams:i={},body:a={},headers:o={},logger:s,getHttpClient:c,getOlapClient:l,parseConnector:u=I,parseOperationInputsFn:d=z,createBlockContextFn:f=G,createBlockFn:p=g,runStepOperationFn:m=Y})=>Z({mode:`operation_id`,operationId:e,account:t,connector:n,pathParams:r,queryParams:i,body:a,headers:o,logger:s,getHttpClient:c,getOlapClient:l,parseConnector:u,parseOperationInputsFn:d,createBlockContextFn:f,createBlockFn:p,runStepOperationFn:m}),gt=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=I,getOperationFromUrlFn:d=x,getOperationForRefreshAuthenticationFn:f=V,parseOperationInputsFn:p=z,createBlockContextFn:m=G,createBlockFn:h=g,runStepOperationFn:_=Y})=>{let v=_t(r),y=v?await Z({mode:`refresh_authentication`,account:e,connector:t,getOperationForRefreshAuthenticationFn:f,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:_}):await Z({mode:`path`,account:e,category:n,connector:t,path:r,method:i,queryParams:a,body:o,headers:s,getOperationFromUrlFn:d,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:_});return y},_t=e=>e===Fe,vt=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=I,getTestOperationsFn:a=Le,createBlockContextFn:o=G,createBlockFn:s=g,runStepOperationFn:c=Y})=>{let l=await Z({mode:`test_operations`,account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i,getTestOperationsFn:a,createBlockContextFn:o,createBlockFn:s,runStepOperationFn:c});return l?.response?.successful??!1};exports.ConnectSDKError=U,exports.REFRESH_TOKEN_OPERATION_PATH=Fe,exports.createBlock=g,exports.executeStepFunction=Ie,exports.getActionsMeta=Me,exports.getActionsMetaFromConnectors=Ne,exports.getOperationFromUrl=x,exports.getRefreshTokenExpiresIn=Ee,exports.getTokenExpiresIn=Te,exports.loadConnector=_,exports.parseOperationInputs=z,exports.parseYamlConnector=I,exports.runAction=Z,exports.runConnectorAction=ht,exports.runConnectorOperation=gt,exports.runStepOperation=Y,exports.runTestOperations=vt,exports.supportsRefreshAuthentication=we,exports.validateYamlConnector=De;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`),r=
|
|
3
|
-
`)}catch(e){throw Error(`Failed to process YAML file: ${e.message}`)}},
|
|
4
|
-
`).filter(e=>e.trim()!==``)}catch(t){throw Error(`Failed to load partial file '${e}': ${t.message}`)}},A=(e,t,n)=>{let r=n.toUpperCase();if(!e.operations)return;let a=Object.values(e.operations).filter(e=>i(e.endpoint)).map(e=>({operationId:e.id,endpoint:e.endpoint})),o=oe(t,r,a);if(o)return{operation:e.operations?.[o.operationId],params:o.params}},j=e=>{let t=e.startsWith(`/`)?e.slice(1):e,n=t.endsWith(`/`)?t.slice(0,-1):t;return n},oe=(e,t,n)=>{let r=j(e);for(let e of n)if(e.endpoint?.startsWith(t)){let n=e.endpoint.replace(`${t} `,``).trim(),i=d(j(n)),a=i(j(r));if(a!==!1)return{operationId:e.operationId,path:e.endpoint,params:a.params}}},M=(e,t)=>t?.startsWith(`${e}_`)?t:`${e}_${t}`,se=(e,t)=>{let n=`${e.key}_`,r=t.startsWith(n)?t:`${n}${t}`;return e.operations?.[r]};var N=class e extends Error{errorType;constructor(t,n){super(n),this.name=`InternalConnectSDKError`,this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},P=class extends N{line;constructor(e,t){super(`INVALID_YAML_FILE_ERROR`,t),this.name=`InvalidYamlFileError`,this.line=e??1}},ce=class extends N{issues;constructor(e,t){super(`SCHEMA_VALIDATION_ERROR`,t),this.name=`SchemaValidationError`,this.issues=e}},F=class extends N{operationId;stepId;functionName;functionVersion;constructor(e,t,n,r=`1`){let i=`Invalid Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the function name and version are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION`,i),this.name=`InvalidStepFunctionError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r}},le=class extends N{operationId;stepId;functionName;functionVersion;issues;constructor(e,t,n,r=`1`,i){let a=`Invalid parameters for Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the parameters are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION_PARAMS`,a),this.name=`InvalidStepFunctionParamsError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r,this.issues=i,this.message=a}};const ue=25,de=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},fe=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},I={key:a.string(),label:a.string(),required:a.boolean().optional().default(!1),secret:a.boolean().optional().default(!1),readOnly:a.boolean().optional().default(!1),placeholder:a.string().optional(),description:a.string().optional(),tooltip:a.string().optional()},L=a.discriminatedUnion(`type`,[o({...I,type:a.enum([`text`,`password`])}),o({...I,type:a.literal(`select`),options:o({value:a.string(),label:a.string()}).array()})]),pe=o({targetFieldKey:a.string(),alias:a.string().optional(),expression:a.string().optional(),values:a.unknown().optional(),type:a.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:a.boolean().default(!1),custom:a.boolean().default(!1),hidden:a.boolean().default(!1),enumMapper:o({matcher:a.enum([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`,`document_file_format_from_extension`]).or(o({matchExpression:a.string(),value:a.string()}).array())}).optional(),properties:a.lazy(()=>pe).array().optional()}),me=o({name:a.string(),type:a.enum([`string`,`number`,`boolean`,`datetime_string`,`object`]),required:a.boolean(),description:a.string(),array:a.boolean().optional().default(!1),in:a.enum([`body`,`query`,`path`,`headers`]),properties:a.lazy(()=>me.omit({in:!0})).array().optional()}),R=o({operationId:a.string(),categories:a.string().array(),operationType:a.enum([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:a.string().optional(),schemaType:a.enum([`native`,`unified`]).optional().default(`native`),entrypointUrl:a.string().optional(),entrypointHttpMethod:a.string().optional(),label:a.string(),description:a.string(),tags:a.string().array().optional(),context:a.string().optional(),responses:o({statusCode:a.number(),description:a.string()}).array().optional(),inputs:me.array().optional(),cursor:o({enabled:a.boolean(),pageSize:a.number()}).optional(),compositeIdentifiers:o({enabled:a.boolean(),version:a.number().optional(),fields:o({targetFieldKey:a.string(),remote:a.string().optional(),components:a.string().array()}).array().optional()}).optional(),scheduledJobs:o({enabled:a.boolean(),type:a.enum([`data_sync`]),schedule:a.string(),description:a.string(),requestParams:o({fields:a.string().array().optional(),expand:a.string().array().optional(),filter:a.record(a.string(),a.string()).optional()}).optional(),syncFilter:o({name:a.enum([`updated_after`,`created_after`]),initialLoopbackPeriod:a.string(),incrementalLoopbackPeriod:a.string()}).optional()}).array().optional(),fieldConfigs:pe.array().optional(),steps:o({stepId:a.string(),description:a.string(),stepFunction:o({functionName:a.string(),version:a.string().optional(),parameters:a.record(a.string(),a.unknown())}),condition:a.string().optional(),ignoreError:a.boolean().optional()}).array(),result:a.string().or(a.record(a.string(),a.unknown())).optional()}),he=o({schedule:a.string().optional(),operation:R.extend({operationType:a.literal(`refresh_token`)})}),ge=o({mainRatelimit:a.number(),subPools:a.array(o({subPoolKey:a.string(),urlPattern:a.string(),rateLimit:a.number()})).optional(),mappedRateLimitErrors:a.array(o({errorStatus:a.number(),errorMessage:a.string(),errorMessagePath:a.string().optional(),retryAfterPath:a.string().optional(),retryAfterUnit:a.union([a.literal(`seconds`),a.literal(`milliseconds`),a.literal(`date`)]).optional(),retryAfterValue:a.number().optional()})).optional()}),_e=o({mainMaxConcurrency:a.number(),subPools:a.array(o({subPoolKey:a.string(),urlPattern:a.string(),maxConcurrency:a.number()})).optional()}),ve=o({StackOne:a.string(),info:o({title:a.string(),version:a.string(),key:a.string(),assets:o({icon:a.string()}),description:a.string()}),context:a.string().optional(),baseUrl:a.string(),authentication:a.record(a.string(),o({type:a.string(),label:a.string(),authorization:f,environments:o({key:a.string(),name:a.string()}).array(),support:o({link:a.string(),description:a.string().optional()}),configFields:L.array().optional(),setupFields:L.array().optional(),refreshAuthentication:he.optional(),testOperations:o({operation:a.string().or(R),condition:a.string().optional(),required:a.boolean().default(!0)}).array().optional()})).array().optional(),operations:R.array().optional(),rateLimit:ge.optional(),concurrency:_e.optional()}).strict();function z(e){try{let t=T(e),n=Ie(ve,t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},a=Se(n),o={baseUrl:n.baseUrl,authentication:ye(a)},s=Oe(n,o);return r.operations=s,be(n.info.key,a,s,o),r.authentication=a,i(s)&&(r.categories=xe(Object.values(s))),r}catch(e){if(e instanceof N)throw e;let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;throw new P(r,t)}}const ye=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=ye(c)}else t[n]=r;return t},be=(e,t,n,r)=>{if(!(!t||!n))for(let a of Object.values(t))for(let t of Object.values(a)){let a=t.testOperations;t.testOperations=a?.map(t=>{if(i(t.operation))if(typeof t.operation==`string`){let r=M(e,t.operation),i=Object.values(n).find(e=>e.id===r);if(i)return{...t,operation:i}}else{let n=M(e,t.operation.operationId),i=B(n,t.operation,r);return{...t,operation:i}}return t})}},xe=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},Se=e=>{let t={};for(let n of e.authentication??[]){let[r]=Object.keys(n),a=n[r].environments.reduce((t,a)=>{let{key:o,name:s}=a,{environments:c,refreshAuthentication:l,testOperations:u,...d}=n[r],f=i(l)?{schedule:l.schedule,operation:B(M(e.info.key,l.operation.operationId),l.operation)}:void 0;return t[o]={...d,refreshAuthentication:f,envKey:o,envName:s,testOperations:u},t},{});t[r]=a}return t},Ce=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,we=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,Te=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},Ee=t=>{if(!(t.operationType===`refresh_token`||e(t.schema)))return t.operationType===`list`?`/${t.schema}`:`/${t.schema}/:id`},De=e=>{let t={success:de(e.operationType),errors:fe()},n=e.responses?.reduce((e,t)=>{let n=te(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},Oe=(e,t)=>{let n=e.operations?.reduce((n,r)=>{let i=Ce(r),a=we(r),o=i??a,s=M(e.info.key,r.operationId);return n[s]=B(s,r,t,o),n},{});return n},B=(e,t,n,r)=>{let i=Ee(t),a=De(t),o=Me(t),s=t.inputs||[];o.enabled&&(s?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`,array:!1}),s?.push({type:`string`,name:`next`,in:`query`,required:!1,description:`Token for the next page of results`,array:!1}));let c=Te(t);return{id:e,categories:t.categories,label:t.label,description:t.description,operationType:t.operationType,schemaType:t.schemaType??`native`,entrypointUrl:t.entrypointUrl??i,entrypointHttpMethod:c,endpoint:r,tags:t.tags,context:t.context,responses:a,cursor:o,compositeIdentifiers:Ne(t),scheduledJobs:Pe(t),inputs:s,steps:t.steps.reduce((e,r)=>{let{customErrors:i,...a}=r.stepFunction.parameters??{},o={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...Fe({stepFunctionName:r.stepFunction.functionName,baseRequestParams:n,customErrors:i}),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:a.fields??t.fieldConfigs}:{},...a}}};return ke(t.operationId,o),e[r.stepId]=o,e},{}),result:t.result}},ke=(e,t)=>{let n=t.stepFunction.version??`1`,r=_[t.stepFunction.functionName]?.[`v${n}`];if(!r)throw new F(e,t.id,t.stepFunction.functionName,n);let i=r.inputSchema;i&&Le(i,t.stepFunction.params,e,t.id,t.stepFunction.functionName,n)},V=(e,t)=>{if(!e.inputs)return{};let n=Ae(e.inputs),r=a.object(n).parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},Ae=e=>{let t=e.reduce((e,t)=>(e[t.in]||(e[t.in]=[]),e[t.in].push(t),e),{}),n={};for(let[e,r]of Object.entries(t)){let t={};for(let e of r){let n=je(e);e.description&&(n=n.describe(e.description)),e.required||(n=n.optional()),t[e.name]=n}Object.keys(t).length>0&&(n[e]=a.object(t))}return n},je=e=>{let t;switch(e.type){case`string`:case`datetime_string`:t=a.string();break;case`number`:t=a.number();break;case`boolean`:t=a.boolean();break;case`object`:if(e.properties&&e.properties.length>0){let n={};for(let t of e.properties){let e=je(t);t.description&&(e=e.describe(t.description)),t.required||(e=e.optional()),n[t.name]=e}t=a.object(n)}else t=a.record(a.string(),a.unknown());break;default:t=a.unknown()}return e.array&&(t=a.array(t)),t},Me=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:ue};return{enabled:n.enabled&&t,pageSize:n.pageSize}},Ne=t=>{if(t.operationType===`refresh_token`)return{enabled:!1};if(e(t.compositeIdentifiers)){let e=t.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=i(e)?[{targetFieldKey:e.targetFieldKey,remote:`id`,components:[{name:e.targetFieldKey,alias:e.alias}]}]:void 0;return{enabled:!0,version:p,fields:n}}let n=[];for(let e of t.compositeIdentifiers?.fields??[]){let r=e.components.map(e=>{let n=t.fieldConfigs?.find(t=>t.targetFieldKey===e);return{name:e,alias:n?.alias}});n.push({targetFieldKey:e.targetFieldKey,remote:e.remote,components:r})}return{enabled:t.compositeIdentifiers.enabled,version:t.compositeIdentifiers.version,fields:n.length>0?n:void 0}},Pe=t=>{if(!e(t.scheduledJobs))return t.scheduledJobs},Fe=({stepFunctionName:e,baseRequestParams:t,customErrors:n={}})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n&&Array.isArray(n)?n:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},Ie=(e,t)=>{let n=e.safeParse(t);if(n.success)return n.data;{let e=n.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new ce(e,`Invalid connector schema`)}},Le=(e,t,n,r,i,a)=>{let o=e.safeParse(t);if(o.success)return o.data;{let e=o.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new le(n,r,i,a,e)}},H=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if(i(r))return{operation:r,params:{}}},Re=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=H(e,t,n);return i(r)},ze=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},Be=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},Ve=t=>{try{let e=z(t);return{success:!0,connector:e}}catch(n){if(n instanceof ce){let r=n.issues,i=[];return r.forEach(n=>{let r=n?.keys?.[0],a=e(r)?n.path:[...n.path,r],o=He(a,t);i.push({line:o,message:n.message,field:a.join(`.`)})}),{success:!1,errors:i}}else if(n instanceof P)return{success:!1,errors:[{line:n.line,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]};else if(n instanceof F){let e=U(n.operationId,n.stepId,n.functionName,!1,t);return{success:!1,errors:[{line:e,message:n.message,field:void 0}]}}else if(n instanceof le){let r=n.issues,i=[];return r.forEach(r=>{let a=r?.keys?.[0],o=e(a)?r.path:[...r.path,a],s=U(n.operationId,n.stepId,n.functionName,!0,t);i.push({line:s,message:r.message,field:o.join(`.`)})}),{success:!1,errors:i}}}return{success:!1,errors:[{line:1,message:`An unknown error occurred while parsing the connector.`,field:void 0}]}},He=(t,n)=>{let r=n.split(`
|
|
5
|
-
`),
|
|
6
|
-
`),c=1,l=null,u=null;for(let o=0;o<s.length;o++){let d=s[o],f=d.trim();if(e(l)&&f===`- operationId: ${t}`){l=t,c=o+1;continue}if(i(l)&&e(u)&&f===`- stepId: ${n}`){u=n,c=o+1;continue}if(i(l)&&i(u)&&!a&&f.startsWith(`functionName: ${r}`)||i(l)&&i(u)&&a&&f===`parameters:`)return c=o+1,c}return c};var W=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},Ue=class extends W{constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},G=class extends W{constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},We=class extends W{constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},Ge=class extends W{constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const Ke=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.title,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},qe=(e,t)=>e.map(e=>Ke(e,t)),Je=`stackone://internal//`,Ye=`${Je}refresh_token`,Xe=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=g.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===h.MAP_FIELDS?{[h.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},K=({category:e,connectorKey:t,connectorVersion:n,authConfigKey:r,environment:i=`production`,operation:a,accountSecureId:o,projectSecureId:s})=>({projectSecureId:s,accountSecureId:o,connectorKey:t,connectorVersion:n,category:e,service:``,resource:``,schema:a?.schema?.key,operationType:a?.operationType??`unknown`,authenticationType:r,environment:i}),Ze=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,Qe=t=>{let n=t.operation?.compositeIdentifiers,r={...t.inputs??{}};if(!n?.enabled||e(r))return t;let i=n.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),a={version:n.version??p,aliases:i};return q(r,a,t.logger),{...t,inputs:r}},q=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))it(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)q(e,t,n);else typeof i==`object`&&i&&q(i,t,n)}},$e=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=v(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},et=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},tt=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},nt=(e,t,n,r,i)=>{n.every(tt)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},rt=(e,t,n)=>{e instanceof m&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},it=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=$e(o,t,r,i);et(n,t,s,a),nt(n,t,s,c,a)}catch(e){rt(e,t,i)}},J=`remote_`,at=t=>{let n=t.operation?.compositeIdentifiers;if(!n?.enabled)return t;let r=`data`,i=t.outputs?.[r];if(e(i))return t;let a=Array.isArray(i)?i.map(e=>ot(e,n)):ot(i,n);return{...t,outputs:{...t.outputs??{},[r]:a}}},ot=(e,t)=>{let r=st(e,t),i=Y(r);return{...e,...n(i)?i:{}}},st=(e,t)=>{let n=t.version??p,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=y(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${J}${t.remote}`]=e[t.remote])}),{...e,...r}},ct=e=>e===`id`||/.+_id(s)?$/.test(e),lt=e=>Array.isArray(e)&&e.every(e=>r(e)&&e.length>0),ut=(e,t)=>x(e)||t.startsWith(J),dt=(e,t)=>{try{return y({key:e,value:t},{version:p})}catch{return t}},ft=(e,t,n)=>{let i=t.map(t=>r(t)&&t.length>0&&!x(t)?dt(e,t):t);n[e]=i,n[`${J}${e}`]=t},pt=(e,t,n)=>{if(ut(t,e))return;let r=y({key:e,value:t},{version:p});n[e]=r,n[`remote_${e}`]=t},mt=(e,t,n)=>{lt(t)?ft(e,t,n):r(t)&&t.length>0&&pt(e,t,n)},Y=e=>{if(Array.isArray(e))return e.map(e=>Y(e));if(!n(e))return e;let t={...e};for(let[r,i]of Object.entries(e))(n(i)||Array.isArray(i)&&i.length>0&&n(i[0]))&&(t[r]=Y(i)),ct(r)&&mt(r,i,t);return t},ht=(e,n)=>{let r=Number(e.inputs?.page_size),a=i(e.inputs?.page_size)&&t(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??n;return a},gt=(t,r,a,o)=>{let s=e(t)?void 0:t.data,c=Object.keys(a).length+1,l=S({cursor:o,ignoreStepIndex:c});if(!n(t)||e(s)||(s?.length??0)<=r)return{result:t,next:i(o)&&!l?C(o):null};let u=o?.remote?.[c]?.pageNumber??1,d=(u-1)*r,f=d+r,p=s.slice(d,f),m=s.length>f||!l,h=w({cursor:o,stepIndex:c,pageNumber:u+1});return{result:{...t,data:p},next:m?C(h):null}},X=async({block:e,buildStepFunction:t=g.build,virtualPaginateResultFn:n=gt,encodeResultCompositeIds:r=at,decodeInputCompositeIds:i=Qe})=>{let a=i(e),o=await St({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},_t=(e,t)=>e.condition?!E(e.condition,t):!1,vt=(e,t,n)=>{let r=e.stepFunction,a=_[e.stepFunction.functionName]?.[`v${e.stepFunction.version??1}`],o=i(a?.inputSchema?.shape)?`cursor`in a?.inputSchema?.shape:!1;return t.operation?.cursor.enabled&&o?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},yt=(e,t,n,r,i)=>{let a=Z({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},bt=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(_t(o,r))return Z({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return Z({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=vt(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return yt(r,e,u,o,i);let d=r.operation?.cursor.enabled?w({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return Z({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},xt=(e,t,r,a,o)=>{let s=!r.hasFatalError,c=s?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500,l=i(o)&&n(o.result)?{next:o.next,...o.result}:a;return{...t,outputs:l,response:{successful:s,statusCode:c,message:s?void 0:e.operation?.responses?.errors?.[c]?.description??ee?.[c]??`Error while processing the request`}}},St=async({block:e,buildStepFunction:t=g.build,virtualPaginateResultFn:n=gt})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=ht(e,ue),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await bt(t,e,r,i,s,c);let l=e.operation?.result?Ct(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return xt(e,i,s,l,u)},Ct=(e,t)=>n(e)?D(e,t):E(e,t),Z=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),Q=async t=>{let{pathParams:n={},queryParams:a={},body:o={},headers:s={},parseConnector:c=z,parseOperationInputsFn:l=V,createBlockContextFn:u=K,createBlockFn:d=O,runStepOperationFn:f=X,getOperationFromUrlFn:p=A,getOperationForRefreshAuthenticationFn:m=H,getTestOperationsFn:h=Ze,mode:g,account:_,connector:v,getHttpClient:y,logger:b,category:x,...S}=t,C=_.authConfigKey,w=_.environment??`production`,ee=_.secureId,te=_.projectSecureId,T=_.credentials,E=u({category:x??`action`,connectorKey:_.providerKey,connectorVersion:_.providerVersion,authConfigKey:C,environment:w,accountSecureId:ee,projectSecureId:te}),D;try{D=r(v)?c(v):v}catch{throw new Ue(E,`Error while parsing connector`)}let k={connector:D,context:E,credentials:T,logger:b,getHttpClient:y};if(g===`operation_id`){let{operationId:t}=S,r=se(D,t);if(e(r))throw new G(E,`No matching operation found`);return await $({operation:r,blockContext:E,queryParams:a,pathParams:n,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f})}else if(g===`test_operations`){let t=h(D,C,w);if(e(t)||t.length===0)return wt(d,k);E.operationType=`test`;for(let n of t){let t=await d({...k,inputs:void 0,operation:n.operation,nextCursor:void 0}),r=i(n.condition)?ne(n.condition,t):!0;if(!r)continue;let a=await f({block:t});if((e(a?.response?.successful)||!a.response.successful)&&n.required)return b?.error({code:`TestOperationFailed`,message:`Test operation "${n.operation.id}" failed with error: ${a?.response?.message}`}),Tt(d,k)}return wt(d,k)}else if(g===`refresh_authentication`){let t=m(D,C,w);if(e(t))throw new G(E,`No matching operation found`);return await $({operation:t.operation,blockContext:E,queryParams:a,pathParams:t.params,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f})}else if(g===`path`){let{path:t,method:n}=S,r=p(D,t,n);if(e(r))throw new G(E,`No matching operation found`);return await $({operation:r.operation,blockContext:E,queryParams:a,pathParams:r.params,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f})}else return Tt(d,k)},$=async e=>{let{operation:t,blockContext:n,queryParams:r,pathParams:i,body:a,headers:o,parseOperationInputsFn:s,createBlockFn:c,createBlockParams:l,runStepOperationFn:u}=e;n.operationType=t.operationType,n.schema=t.schema?.key;let d=Et(r,n),f;try{f=s(t,{path:i,query:r,body:a,headers:o})}catch{throw new We(n,`Error while parsing operation inputs`)}let p=await c({...l,inputs:f,operation:t,nextCursor:d});return await u({block:p})},wt=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!0,statusCode:200}}},Tt=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!1,statusCode:500}}},Et=(e,t)=>{let n=e?.next,r=i(n)&&t.operationType===`list`?b(n):void 0;if(r===null)throw new Ge(t,`Invalid cursor.`);return r},Dt=async({operationId:e,account:t,connector:n,pathParams:r={},queryParams:i={},body:a={},headers:o={},logger:s,getHttpClient:c,parseConnector:l=z,parseOperationInputsFn:u=V,createBlockContextFn:d=K,createBlockFn:f=O,runStepOperationFn:p=X})=>Q({mode:`operation_id`,operationId:e,account:t,connector:n,pathParams:r,queryParams:i,body:a,headers:o,logger:s,getHttpClient:c,parseConnector:l,parseOperationInputsFn:u,createBlockContextFn:d,createBlockFn:f,runStepOperationFn:p}),Ot=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=z,getOperationFromUrlFn:d=A,getOperationForRefreshAuthenticationFn:f=H,parseOperationInputsFn:p=V,createBlockContextFn:m=K,createBlockFn:h=O,runStepOperationFn:g=X})=>{let _=kt(r),v=_?await Q({mode:`refresh_authentication`,account:e,connector:t,getOperationForRefreshAuthenticationFn:f,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:g}):await Q({mode:`path`,account:e,category:n,connector:t,path:r,method:i,queryParams:a,body:o,headers:s,getOperationFromUrlFn:d,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:g});return v},kt=e=>e===Ye,At=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=z,getTestOperationsFn:a=Ze,createBlockContextFn:o=K,createBlockFn:s=O,runStepOperationFn:c=X})=>{let l=await Q({mode:`test_operations`,account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i,getTestOperationsFn:a,createBlockContextFn:o,createBlockFn:s,runStepOperationFn:c});return l?.response?.successful??!1};export{W as ConnectSDKError,Ye as REFRESH_TOKEN_OPERATION_PATH,O as createBlock,Xe as executeStepFunction,Ke as getActionsMeta,qe as getActionsMetaFromConnectors,A as getOperationFromUrl,Be as getRefreshTokenExpiresIn,ze as getTokenExpiresIn,k as loadConnector,V as parseOperationInputs,z as parseYamlConnector,Q as runAction,Dt as runConnectorAction,Ot as runConnectorOperation,X as runStepOperation,At as runTestOperations,Re as supportsRefreshAuthentication,Ve as validateYamlConnector};
|
|
1
|
+
import{generateActionRunId as e,isMissing as t,isNumber as n,isObject as r,isString as i,notMissing as a,z as o,zStrictObject as s}from"@stackone/utils";import{readFileSync as c}from"fs";import{dirname as l,join as u,resolve as d}from"path";import{match as f}from"path-to-regexp";import{AUTHENTICATION_SCHEMA as p,COMPOSITE_ID_LATEST_VERSION as m,CoreError as h,StepFunctionName as g,StepFunctionsFactory as _,StepFunctionsRegistry as v,decodeCompositeId as ee,encodeCompositeId as y,expandCursor as b,isCompositeId as x,isCursorEmpty as te,minifyCursor as S,updateCursor as C}from"@stackone/core";import{HttpErrorMessages as w,isSuccessStatusCode as ne}from"@stackone/transport";import{parse as re}from"yaml";import{evaluate as ie,safeEvaluate as T,safeEvaluateRecord as E}from"@stackone/expressions";const D=async({connector:e,inputs:n,context:r,operation:i,credentials:a,nextCursor:o,settings:s,logger:c,getHttpClient:l,getOlapClient:u})=>{if(t(l))throw Error(`getHttpClient function is required`);let d=await l(),f=u?await u():void 0;return{connector:e,inputs:n,fieldConfigs:[],context:r,operation:i,credentials:a,nextCursor:o,httpClient:d,olapClient:f,settings:s,logger:c}},O=e=>{if(!e.endsWith(`.s1.yaml`))throw Error(`File must have .s1.yaml extension`);try{let t=c(e,`utf8`);if(!t.includes(`:`)||!t.includes(`$ref:`))return t;let n=t.split(`
|
|
2
|
+
`),r=k(n,l(e));return r.join(`
|
|
3
|
+
`)}catch(e){throw Error(`Failed to process YAML file: ${e.message}`)}},k=(e,t)=>{let n=[];for(let r of e)if(ae(r)){let e=r.match(/^(\s*)/)?.[1]?.length||0,i=r.split(`:`)[1]?.trim(),a=oe(i,t),o=a.map(t=>` `.repeat(e)+t);n.push(...o)}else n.push(r);return n},ae=e=>e.includes(`$ref:`),oe=(e,t)=>{let n=d(u(t,`${e.replaceAll(`'`,``)}.s1.partial.yaml`));try{let e=c(n,`utf8`);return e.split(`
|
|
4
|
+
`).filter(e=>e.trim()!==``)}catch(t){throw Error(`Failed to load partial file '${e}': ${t.message}`)}},A=(e,t,n)=>{let r=n.toUpperCase();if(!e.operations)return;let i=Object.values(e.operations).filter(e=>a(e.endpoint)).map(e=>({operationId:e.id,endpoint:e.endpoint})),o=se(t,r,i);if(o)return{operation:e.operations?.[o.operationId],params:o.params}},j=e=>{let t=e.startsWith(`/`)?e.slice(1):e,n=t.endsWith(`/`)?t.slice(0,-1):t;return n},se=(e,t,n)=>{let r=j(e);for(let e of n)if(e.endpoint?.startsWith(t)){let n=e.endpoint.replace(`${t} `,``).trim(),i=f(j(n)),a=i(j(r));if(a!==!1)return{operationId:e.operationId,path:e.endpoint,params:a.params}}},M=(e,t)=>t?.startsWith(`${e}_`)?t:`${e}_${t}`,ce=(e,t)=>{let n=`${e.key}_`,r=t.startsWith(n)?t:`${n}${t}`;return e.operations?.[r]};var N=class e extends Error{errorType;constructor(t,n){super(n),this.name=`InternalConnectSDKError`,this.errorType=t,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},P=class extends N{line;constructor(e,t){super(`INVALID_YAML_FILE_ERROR`,t),this.name=`InvalidYamlFileError`,this.line=e??1}},le=class extends N{issues;constructor(e,t){super(`SCHEMA_VALIDATION_ERROR`,t),this.name=`SchemaValidationError`,this.issues=e}},ue=class extends N{operationId;stepId;functionName;functionVersion;constructor(e,t,n,r=`1`){let i=`Invalid Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the function name and version are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION`,i),this.name=`InvalidStepFunctionError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r}},F=class extends N{operationId;stepId;functionName;functionVersion;issues;constructor(e,t,n,r=`1`,i){let a=`Invalid parameters for Step Function: '${n}' (v${r}) on step '${t}'. Please ensure the parameters are correct in the operation '${e}'.`;super(`INVALID_STEP_FUNCTION_PARAMS`,a),this.name=`InvalidStepFunctionParamsError`,this.operationId=e,this.stepId=t,this.functionName=n,this.functionVersion=r,this.issues=i,this.message=a}};const de=25,fe=e=>{switch(e){case`list`:return{statusCode:200,description:`The list of records was retrieved.`};case`get`:return{statusCode:200,description:`The record with the given identifier was retrieved.`};case`create`:return{statusCode:201,description:`The record was created successfully.`};case`update`:return{statusCode:200,description:`The record was updated successfully.`};case`delete`:return{statusCode:204,description:`The record was deleted successfully.`};case`custom`:return{statusCode:200,description:`The operation was executed successfully.`};case`refresh_token`:return{statusCode:200,description:`The refresh token operation was executed successfully.`};case`unknown`:return{statusCode:200};default:throw Error(`Unknown operation type: ${e}`)}},pe=()=>{let e={400:{statusCode:400,description:`Invalid request.`},401:{statusCode:401,description:`Unauthorized access.`},403:{statusCode:403,description:`Forbidden.`},404:{statusCode:404,description:`Resource not found.`},500:{statusCode:500,description:`Server error while executing the request.`}};return e},me={key:o.string(),label:o.string(),required:o.boolean().optional().default(!1),secret:o.boolean().optional().default(!1),readOnly:o.boolean().optional().default(!1),placeholder:o.string().optional(),description:o.string().optional(),tooltip:o.string().optional()},he=o.discriminatedUnion(`type`,[s({...me,type:o.enum([`text`,`password`])}),s({...me,type:o.literal(`select`),options:s({value:o.string(),label:o.string()}).array()})]),ge=s({targetFieldKey:o.string(),alias:o.string().optional(),expression:o.string().optional(),values:o.unknown().optional(),type:o.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:o.boolean().default(!1),custom:o.boolean().default(!1),hidden:o.boolean().default(!1),enumMapper:s({matcher:o.enum([`country_alpha2code_by_alpha2code`,`country_alpha3code_by_alpha3code`,`country_code_by_country_code`,`country_name_by_country_name`,`country_name_by_alpha3code`,`country_name_by_alpha2code`,`country_name_by_country_code`,`country_alpha3code_by_alpha2code`,`country_alpha3code_by_country_name`,`country_alpha3code_by_country_code`,`country_alpha2code_by_alpha3code`,`country_alpha2code_by_country_name`,`country_alpha2code_by_country_code`,`country_code_by_alpha2code`,`country_code_by_alpha3code`,`country_code_by_country_name`,`country_subdivisions_by_alpha2code`,`country_subdivision_code_by_subdivision_name`,`country_alpha2code_by_citizenship`,`country_subdivision_name_by_subdivision_code`,`document_file_format_from_extension`]).or(s({matchExpression:o.string(),value:o.string()}).array())}).optional(),properties:o.lazy(()=>ge).array().optional()}),_e=s({name:o.string(),type:o.enum([`string`,`number`,`boolean`,`datetime_string`,`object`]),required:o.boolean(),description:o.string(),array:o.boolean().optional().default(!1),in:o.enum([`body`,`query`,`path`,`headers`]),properties:o.lazy(()=>_e.omit({in:!0})).array().optional()}),I=s({operationId:o.string(),categories:o.string().array(),operationType:o.enum([`list`,`get`,`create`,`update`,`delete`,`custom`,`refresh_token`,`unknown`]),schema:o.string().optional(),schemaType:o.enum([`native`,`unified`]).optional().default(`native`),entrypointUrl:o.string().optional(),entrypointHttpMethod:o.string().optional(),label:o.string(),description:o.string(),tags:o.string().array().optional(),context:o.string().optional(),responses:s({statusCode:o.number(),description:o.string()}).array().optional(),inputs:_e.array().optional(),cursor:s({enabled:o.boolean(),pageSize:o.number()}).optional(),compositeIdentifiers:s({enabled:o.boolean(),version:o.number().optional(),fields:s({targetFieldKey:o.string(),remote:o.string().optional(),components:o.string().array()}).array().optional()}).optional(),scheduledJobs:s({enabled:o.boolean(),type:o.enum([`data_sync`]),schedule:o.string(),description:o.string(),requestParams:s({fields:o.string().array().optional(),expand:o.string().array().optional(),filter:o.record(o.string(),o.string()).optional()}).optional(),syncFilter:s({name:o.enum([`updated_after`,`created_after`]),initialLoopbackPeriod:o.string(),incrementalLoopbackPeriod:o.string()}).optional()}).array().optional(),fieldConfigs:ge.array().optional(),steps:s({stepId:o.string(),description:o.string(),stepFunction:s({functionName:o.string(),version:o.string().optional(),parameters:o.record(o.string(),o.unknown())}),condition:o.string().optional(),ignoreError:o.boolean().optional()}).array(),result:o.string().or(o.record(o.string(),o.unknown())).optional()}),ve=s({schedule:o.string().optional(),operation:I.extend({operationType:o.literal(`refresh_token`)})}),ye=s({mainRatelimit:o.number(),subPools:o.array(s({subPoolKey:o.string(),urlPattern:o.string(),rateLimit:o.number()})).optional(),mappedRateLimitErrors:o.array(s({errorStatus:o.number(),errorMessage:o.string(),errorMessagePath:o.string().optional(),retryAfterPath:o.string().optional(),retryAfterUnit:o.union([o.literal(`seconds`),o.literal(`milliseconds`),o.literal(`date`)]).optional(),retryAfterValue:o.number().optional()})).optional()}),be=s({mainMaxConcurrency:o.number(),subPools:o.array(s({subPoolKey:o.string(),urlPattern:o.string(),maxConcurrency:o.number()})).optional()}),xe=s({StackOne:o.string(),info:s({title:o.string(),version:o.string(),key:o.string(),assets:s({icon:o.string()}),description:o.string()}),context:o.string().optional(),baseUrl:o.string(),authentication:o.record(o.string(),s({type:o.string(),label:o.string(),authorization:p,environments:s({key:o.string(),name:o.string()}).array(),support:s({link:o.string(),description:o.string().optional()}),configFields:he.array().optional(),setupFields:he.array().optional(),refreshAuthentication:ve.optional(),testOperations:s({operation:o.string().or(I),condition:o.string().optional(),required:o.boolean().default(!0)}).array().optional()})).array().optional(),operations:I.array().optional(),rateLimit:ye.optional(),concurrency:be.optional()}).strict();function L(e){try{let t=re(e),n=Re(xe,t),r={title:n.info.title,version:n.info.version,key:n.info.key,assets:n.info.assets,description:n.info.description,context:n.context,rateLimit:n.rateLimit,concurrency:n.concurrency},i=we(n),o={baseUrl:n.baseUrl,authentication:R(i)},s=Ae(n,o);return r.operations=s,Se(n.info.key,i,s,o),r.authentication=i,a(s)&&(r.categories=Ce(Object.values(s))),r}catch(e){if(e instanceof N)throw e;let t=e.message,n=t.match(/at line (\d+)/),r=n?parseInt(n[1],10):1;throw new P(r,t)}}const R=e=>{let t={};for(let[n,r]of Object.entries(e))if(r&&typeof r==`object`){let{setupFields:e,configFields:i,support:a,refreshAuthentication:o,testOperations:s,...c}=r;t[n]=R(c)}else t[n]=r;return t},Se=(e,t,n,r)=>{if(!(!t||!n))for(let i of Object.values(t))for(let t of Object.values(i)){let i=t.testOperations;t.testOperations=i?.map(t=>{if(a(t.operation))if(typeof t.operation==`string`){let r=M(e,t.operation),i=Object.values(n).find(e=>e.id===r);if(i)return{...t,operation:i}}else{let n=M(e,t.operation.operationId),i=z(n,t.operation,r);return{...t,operation:i}}return t})}},Ce=e=>{let t=e.reduce((e,t)=>{for(let n of t.categories)e.add(n);return e},new Set);return Array.from(t)},we=e=>{let t={};for(let n of e.authentication??[]){let[r]=Object.keys(n),i=n[r].environments.reduce((t,i)=>{let{key:o,name:s}=i,{environments:c,refreshAuthentication:l,testOperations:u,...d}=n[r],f=a(l)?{schedule:l.schedule,operation:z(M(e.info.key,l.operation.operationId),l.operation)}:void 0;return t[o]={...d,refreshAuthentication:f,envKey:o,envName:s,testOperations:u},t},{});t[r]=i}return t},Te=e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0,Ee=e=>e.operationType===`list`?`GET /${e.schema}`:`GET /${e.schema}/:id`,De=e=>{if(e.operationType!==`refresh_token`)return e.entrypointHttpMethod??`get`},Oe=e=>{if(!(e.operationType===`refresh_token`||t(e.schema)))return e.operationType===`list`?`/${e.schema}`:`/${e.schema}/:id`},ke=e=>{let t={success:fe(e.operationType),errors:pe()},n=e.responses?.reduce((e,t)=>{let n=ne(t.statusCode);return n?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e},t);return n??t},Ae=(e,t)=>{let n=e.operations?.reduce((n,r)=>{let i=Te(r),a=Ee(r),o=i??a,s=M(e.info.key,r.operationId);return n[s]=z(s,r,t,o),n},{});return n},z=(e,t,n,r)=>{let i=Oe(t),a=ke(t),o=Pe(t),s=t.inputs||[];o.enabled&&(s?.push({type:`string`,name:`page_size`,in:`query`,required:!1,description:`Number of items to return per page`,array:!1}),s?.push({type:`string`,name:`next`,in:`query`,required:!1,description:`Token for the next page of results`,array:!1}));let c=De(t);return{id:e,categories:t.categories,label:t.label,description:t.description,operationType:t.operationType,schemaType:t.schemaType??`native`,entrypointUrl:t.entrypointUrl??i,entrypointHttpMethod:c,endpoint:r,tags:t.tags,context:t.context,responses:a,cursor:o,compositeIdentifiers:Fe(t),scheduledJobs:Ie(t),inputs:s,steps:t.steps.reduce((e,r)=>{let{customErrors:i,...a}=r.stepFunction.parameters??{},o={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...Le({stepFunctionName:r.stepFunction.functionName,baseRequestParams:n,customErrors:i}),...r.stepFunction.functionName===`map_fields`||r.stepFunction.functionName===`typecast`?{fields:a.fields??t.fieldConfigs}:{},...a}}};return je(t.operationId,o),e[r.stepId]=o,e},{}),result:t.result}},je=(e,t)=>{let n=t.stepFunction.version??`1`,r=v[t.stepFunction.functionName]?.[`v${n}`];if(!r)throw new ue(e,t.id,t.stepFunction.functionName,n);let i=r.inputSchema;i&&ze(i,t.stepFunction.params,e,t.id,t.stepFunction.functionName,n)},B=(e,t)=>{if(!e.inputs)return{};let n=Me(e.inputs),r=o.object(n).parse(t);return{...r.headers??{},...r.query??{},...r.path??{},...r.body??{}}},Me=e=>{let t=e.reduce((e,t)=>(e[t.in]||(e[t.in]=[]),e[t.in].push(t),e),{}),n={};for(let[e,r]of Object.entries(t)){let t={};for(let e of r){let n=Ne(e);e.description&&(n=n.describe(e.description)),e.required||(n=n.optional()),t[e.name]=n}Object.keys(t).length>0&&(n[e]=o.object(t))}return n},Ne=e=>{let t;switch(e.type){case`string`:case`datetime_string`:t=o.string();break;case`number`:t=o.number();break;case`boolean`:t=o.boolean();break;case`object`:if(e.properties&&e.properties.length>0){let n={};for(let t of e.properties){let e=Ne(t);t.description&&(e=e.describe(t.description)),t.required||(e=e.optional()),n[t.name]=e}t=o.object(n)}else t=o.record(o.string(),o.unknown());break;default:t=o.unknown()}return e.array&&(t=o.array(t)),t},Pe=e=>{let t=e.operationType===`list`,n=e.cursor??{enabled:t,pageSize:de};return{enabled:n.enabled&&t,pageSize:n.pageSize}},Fe=e=>{if(e.operationType===`refresh_token`)return{enabled:!1};if(t(e.compositeIdentifiers)){let t=e.fieldConfigs?.find(e=>e.targetFieldKey===`id`),n=a(t)?[{targetFieldKey:t.targetFieldKey,remote:`id`,components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:m,fields:n}}let n=[];for(let t of e.compositeIdentifiers?.fields??[]){let r=t.components.map(t=>{let n=e.fieldConfigs?.find(e=>e.targetFieldKey===t);return{name:t,alias:n?.alias}});n.push({targetFieldKey:t.targetFieldKey,remote:t.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:n.length>0?n:void 0}},Ie=e=>{if(!t(e.scheduledJobs))return e.scheduledJobs},Le=({stepFunctionName:e,baseRequestParams:t,customErrors:n={}})=>{if(e===`request`||e===`paginated_request`){let e=[{receivedStatus:500,targetStatus:502}],r=n&&Array.isArray(n)?n:[],i=[...r,...e];return{...t,customErrors:i}}else return{}},Re=(e,t)=>{let n=e.safeParse(t);if(n.success)return n.data;{let e=n.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new le(e,`Invalid connector schema`)}},ze=(e,t,n,r,i,a)=>{let o=e.safeParse(t);if(o.success)return o.data;{let e=o.error.issues.map(e=>({code:e.code,message:e.message,input:e.input,path:e.path,keys:e?.keys??[]}));throw new F(n,r,i,a,e)}},V=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return;let r=e.authentication?.[t]?.[n]?.refreshAuthentication?.operation;if(a(r))return{operation:r,params:{}}},Be=(e,t,n)=>{if(e.authentication?.[t]?.[n]?.authorization.type!==`oauth2`)return!1;let r=V(e,t,n);return a(r)},Ve=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenExpiresIn},He=(e,t,n)=>{let r=e.authentication?.[t]?.[n]?.authorization;if(r?.type===`oauth2`)return r?.tokenRefreshExpiresIn},Ue=e=>{try{let t=L(e);return{success:!0,connector:t}}catch(n){if(n instanceof le){let r=n.issues,i=[];return r.forEach(n=>{let r=n?.keys?.[0],a=t(r)?n.path:[...n.path,r],o=We(a,e);i.push({line:o,message:n.message,field:a.join(`.`)})}),{success:!1,errors:i}}else if(n instanceof P)return{success:!1,errors:[{line:n.line,message:`The YAML connector file is not valid. Please check the syntax and structure.`,field:void 0}]};else if(n instanceof ue){let t=Ge(n.operationId,n.stepId,n.functionName,!1,e);return{success:!1,errors:[{line:t,message:n.message,field:void 0}]}}else if(n instanceof F){let r=n.issues,i=[];return r.forEach(r=>{let a=r?.keys?.[0],o=t(a)?r.path:[...r.path,a],s=Ge(n.operationId,n.stepId,n.functionName,!0,e);i.push({line:s,message:r.message,field:o.join(`.`)})}),{success:!1,errors:i}}}return{success:!1,errors:[{line:1,message:`An unknown error occurred while parsing the connector.`,field:void 0}]}},We=(e,n)=>{let r=n.split(`
|
|
5
|
+
`),i=0,o=-1,s=0;for(let n=0;n<r.length;n++){let c=r[n],l=c.match(/^(\s*)/)?.[1]?.length||0,u=c.replace(`- `,``).trim();if(u.startsWith(`#`)||u===``||l<=o)continue;let d=a(e[i])?`${String(e[i])}`:``;if(t(d))return s+1;if(isNaN(Number(d))){if(u.startsWith(`${d}:`)){if(i===e.length-1)return n+1;o=l,s=n,i++}}else{let e=parseInt(d,10),t=-1;for(let a=n;a<r.length;a++){let o=r[a],c=o.trim();if(c.startsWith(`-`)&&t++,t===e){i++,s=n,n--;break}else n++}}}return s+1},Ge=(e,n,r,i,o)=>{let s=o.split(`
|
|
6
|
+
`),c=1,l=null,u=null;for(let o=0;o<s.length;o++){let d=s[o],f=d.trim();if(t(l)&&f===`- operationId: ${e}`){l=e,c=o+1;continue}if(a(l)&&t(u)&&f===`- stepId: ${n}`){u=n,c=o+1;continue}if(a(l)&&a(u)&&!i&&f.startsWith(`functionName: ${r}`)||a(l)&&a(u)&&i&&f===`parameters:`)return c=o+1,c}return c};var H=class e extends Error{errorType;context;constructor(t,n,r){super(r),this.name=`ConnectSDKError`,this.errorType=t,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}},Ke=class extends H{constructor(e,t){super(`CONNECTOR_PARSE_ERROR`,e,t),this.name=`ConnectorParseError`}},U=class extends H{constructor(e,t){super(`MISSING_OPERATION_ERROR`,e,t),this.name=`MissingOperationError`}},qe=class extends H{constructor(e,t){super(`INVALID_OPERATION_INPUTS_ERROR`,e,t),this.name=`InvalidOperationInputsError`}},Je=class extends H{constructor(e,t){super(`INVALID_CURSOR_ERROR`,e,t),this.name=`InvalidCursorError`}};const Ye=(e,t)=>{let n=Object.keys(e.authentication??{}).map(t=>({type:`custom`,label:e.authentication?.[t].production?.label||`Custom`,key:t})),r=Object.values(e?.operations??{}).map(e=>({id:e.id,description:e.description.replace(/\b\w/g,e=>e.toUpperCase()),label:e.label.replace(/\b\w/g,e=>e.toUpperCase()),schema_type:e.schemaType,tags:e.tags,authentication:n,operation_details:t?.includes(`operation_details`)?e:void 0}));return{version:e.version,name:e.title,key:e.key,icon:e.assets?.icon,description:e.description,authentication:n,actions:r}},Xe=(e,t)=>e.map(e=>Ye(e,t)),Ze=`stackone://internal//`,Qe=`${Ze}refresh_token`,$e=async({block:e,stepFunctionName:t,params:n,buildStepFunction:r=_.build})=>{let i=r({functionName:t}).fn,a=await i({block:e,params:n}),o=t===g.MAP_FIELDS?{[g.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...o}}},W=({category:t,connectorKey:n,connectorVersion:r,authConfigKey:i,environment:a=`production`,operation:o,accountSecureId:s,projectSecureId:c})=>({projectSecureId:c,accountSecureId:s,connectorKey:n,connectorVersion:r,category:t,service:``,resource:``,schema:o?.schema?.key,operationType:o?.operationType??`unknown`,authenticationType:i,environment:a,actionRunId:e()}),et=(e,t,n)=>e.authentication?.[t]?.[n]?.testOperations,tt=e=>{let n=e.operation?.compositeIdentifiers,r={...e.inputs??{}};if(!n?.enabled||t(r))return e;let i=n.fields?.reduce((e,t)=>(t.components.forEach(t=>{t.alias&&(e[t.name]=t.alias)}),e),{}),a={version:n.version??m,aliases:i};return G(r,a,e.logger),{...e,inputs:r}},G=(e,t,n)=>{for(let r in e){let i=e[r];if(typeof i==`string`||Array.isArray(i)&&i.every(e=>typeof e==`string`))st(i,r,e,t,n);else if(Array.isArray(i))for(let e of i)G(e,t,n);else typeof i==`object`&&i&&G(i,t,n)}},nt=(e,t,n,r)=>{let i=[],a=[];for(let o of e)try{let e=ee(o,n);i.push(e)}catch(e){r?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:`processCompositeId`,context:{key:t,inputElement:o,compositeIdentifierConfig:n,error:e}}),a.push(o)}return{compositeIdComponents:i,nonCompositeIds:a}},rt=(e,t,n,r)=>{let i=n.filter(e=>Object.keys(e).length>1);i.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?i:i[0]})},it=e=>{let t=Object.values(e);return t.length===1&&(typeof t[0]==`string`||typeof t[0]==`number`)},at=(e,t,n,r,i)=>{n.every(it)&&(i?e[t]=[...n.map(e=>Object.values(e)[0]),...r]:n.length>0&&(e[t]=Object.values(n[0])[0]))},ot=(e,t,n)=>{e instanceof h&&e.type===`COMPOSITE_ID_MISSING_HEADER_ERROR`?n?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):n?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})},st=(e,t,n,r,i)=>{try{let a=Array.isArray(e),o=a?e:[e];if(o.length===0)return;let{compositeIdComponents:s,nonCompositeIds:c}=nt(o,t,r,i);rt(n,t,s,a),at(n,t,s,c,a)}catch(e){ot(e,t,i)}},K=`remote_`,ct=e=>{let n=e.operation?.compositeIdentifiers;if(!n?.enabled)return e;let r=`data`,i=e.outputs?.[r];if(t(i))return e;let a=Array.isArray(i)?i.map(e=>lt(e,n)):lt(i,n);return{...e,outputs:{...e.outputs??{},[r]:a}}},lt=(e,t)=>{let n=ut(e,t),i=q(n);return{...e,...r(i)?i:{}}},ut=(e,t)=>{let n=t.version??m,r={};return t.fields?.forEach(t=>{let i={},a=[];t.components.forEach(t=>{t.alias&&(i[t.name]=t.alias),a.push({key:t.name,value:e[t.name]})});let o=a.length===1?a[0]:{identifiers:a},s={version:n,aliases:Object.keys(i).length>0?i:void 0},c=y(o,s);r[t.targetFieldKey]=c,t.remote&&(r[`${K}${t.remote}`]=e[t.remote])}),{...e,...r}},dt=e=>e===`id`||/.+_id(s)?$/.test(e),ft=e=>Array.isArray(e)&&e.every(e=>i(e)&&e.length>0),pt=(e,t)=>x(e)||t.startsWith(K),mt=(e,t)=>{try{return y({key:e,value:t},{version:m})}catch{return t}},ht=(e,t,n)=>{let r=t.map(t=>i(t)&&t.length>0&&!x(t)?mt(e,t):t);n[e]=r,n[`${K}${e}`]=t},gt=(e,t,n)=>{if(pt(t,e))return;let r=y({key:e,value:t},{version:m});n[e]=r,n[`remote_${e}`]=t},_t=(e,t,n)=>{ft(t)?ht(e,t,n):i(t)&&t.length>0&>(e,t,n)},q=e=>{if(Array.isArray(e))return e.map(e=>q(e));if(!r(e))return e;let t={...e};for(let[n,i]of Object.entries(e))(r(i)||Array.isArray(i)&&i.length>0&&r(i[0]))&&(t[n]=q(i)),dt(n)&&_t(n,i,t);return t},vt=(e,t)=>{let r=Number(e.inputs?.page_size),i=a(e.inputs?.page_size)&&n(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??t;return i},J=(e,n,i,o)=>{let s=t(e)?void 0:e.data,c=Object.keys(i).length+1,l=te({cursor:o,ignoreStepIndex:c});if(!r(e)||t(s)||(s?.length??0)<=n)return{result:e,next:a(o)&&!l?S(o):null};let u=o?.remote?.[c]?.pageNumber??1,d=(u-1)*n,f=d+n,p=s.slice(d,f),m=s.length>f||!l,h=C({cursor:o,stepIndex:c,pageNumber:u+1});return{result:{...e,data:p},next:m?S(h):null}},yt=e=>{let n=e.settings?.olap;return t(n)?{}:{logs:n.logs?{enabled:n.logs.enabled}:void 0,advanced:n.advanced?{enabled:n.advanced.enabled,ttl:n.advanced.ttl,errorsOnly:n.advanced.errorsOnly}:void 0}},Y=async({block:e,buildStepFunction:t=_.build,virtualPaginateResultFn:n=J,encodeResultCompositeIds:r=ct,decodeInputCompositeIds:i=tt})=>{let a=i(e),o=await Tt({block:a,buildStepFunction:t,virtualPaginateResultFn:n});return r(o)},bt=(e,t)=>e.condition?!T(e.condition,t):!1,xt=(e,t,n)=>{let r=e.stepFunction,i=v[e.stepFunction.functionName]?.[`v${e.stepFunction.version??1}`],o=a(i?.inputSchema?.shape)?`cursor`in i?.inputSchema?.shape:!1;return t.operation?.cursor.enabled&&o?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[n]?.providerPageCursor,position:t.nextCursor?.remote?.[n]?.position}}:r.params??{}},St=(e,t,n,r,i)=>{let a=X({block:e,stepId:t,successful:!1,functionOutput:n}),o=r.ignoreError??!1;return o||(i.hasFatalError=!0,i.errorStatusCode??=n.output?.statusCode??500),a},Ct=async(e,t,n,r,i,a)=>{let o=n[e],s=o.stepFunction,c=a.buildStepFunction({functionName:s.functionName,version:s.version,validateSchemas:!0}).fn;if(bt(o,r))return X({block:r,stepId:e,successful:!0,skipped:!0,message:`Step skipped due to condition not met.`});if(i.hasFatalError)return X({block:r,stepId:e,successful:!1,skipped:!0,message:`Step skipped due to previous error.`});let l=xt(o,r,t),u=await c({block:r,params:l});if(u.successful===!1)return St(r,e,u,o,i);let d=r.operation?.cursor.enabled?C({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return X({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},wt=(e,t,n,i,o)=>{let s=!n.hasFatalError,c=s?e.operation?.responses.success.statusCode??200:n.errorStatusCode??500,l=a(o)&&r(o.result)?{next:o.next,...o.result}:i;return{...t,outputs:l,response:{successful:s,statusCode:c,message:s?void 0:e.operation?.responses?.errors?.[c]?.description??w?.[c]??`Error while processing the request`}}},Tt=async({block:e,buildStepFunction:t=_.build,virtualPaginateResultFn:n=J})=>{let r=e.operation?.steps||{},i={...e},a=Object.keys(r),o=vt(e,de),s={hasFatalError:!1,errorStatusCode:null},c={block:e,buildStepFunction:t,virtualPaginateResultFn:n};for(let[e,t]of a.entries())i=await Ct(t,e,r,i,s,c),Dt({block:i,stepId:t});let l=e.operation?.result?Et(e.operation.result,i):void 0,u=e.operation?.cursor.enabled?n(l,o,r,i.nextCursor):void 0;return wt(e,i,s,l,u)},Et=(e,t)=>r(e)?E(e,t):T(e,t),X=({block:e,stepId:t,successful:n,functionOutput:r,skipped:i,message:a})=>({...e,steps:{...e.steps,[t]:{successful:n??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:i,message:a}}}),Dt=({block:e,stepId:n})=>{let r=e.olapClient;if(t(r?.recordStep))return;let i=yt(e);r.recordStep({stepId:n,status:e.steps?.[n]?.successful?`success`:`error`},i)},Z=async e=>{let{pathParams:n={},queryParams:r={},body:o={},headers:s={},parseConnector:c=L,parseOperationInputsFn:l=B,createBlockContextFn:u=W,createBlockFn:d=D,runStepOperationFn:f=Y,getOperationFromUrlFn:p=A,getOperationForRefreshAuthenticationFn:m=V,getTestOperationsFn:h=et,mode:g,account:_,connector:v,getHttpClient:ee,getOlapClient:y,settings:b,logger:x,category:te,...S}=e,C=_.authConfigKey,w=_.environment??`production`,ne=_.secureId,re=_.projectSecureId,T=_.credentials,E=u({category:te??`action`,connectorKey:_.providerKey,connectorVersion:_.providerVersion,authConfigKey:C,environment:w,accountSecureId:ne,projectSecureId:re}),O;try{O=i(v)?c(v):v}catch{throw new Ke(E,`Error while parsing connector`)}let k={connector:O,context:E,credentials:T,settings:b,logger:x,getHttpClient:ee,getOlapClient:y};if(g===`operation_id`){let{operationId:e}=S,i=ce(O,e);if(t(i))throw new U(E,`No matching operation found`);let a=await Q({operation:i,blockContext:E,queryParams:r,pathParams:n,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f});return $({block:a}),a}else if(g===`test_operations`){let e=h(O,C,w);if(t(e)||e.length===0){let e=await Ot(d,k);return $({block:e}),e}E.operationType=`test`;for(let n of e){let e=await d({...k,inputs:void 0,operation:n.operation,nextCursor:void 0}),r=a(n.condition)?ie(n.condition,e):!0;if(!r)continue;let i=await f({block:e});if((t(i?.response?.successful)||!i.response.successful)&&n.required){x?.error({code:`TestOperationFailed`,message:`Test operation "${n.operation.id}" failed with error: ${i?.response?.message}`});let e=await kt(d,k);return $({block:e}),e}}let n=await Ot(d,k);return $({block:n}),n}else if(g===`refresh_authentication`){let e=m(O,C,w);if(t(e))throw new U(E,`No matching operation found`);let n=await Q({operation:e.operation,blockContext:E,queryParams:r,pathParams:e.params,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f});return $({block:n}),n}else if(g===`path`){let{path:e,method:n}=S,i=p(O,e,n);if(t(i))throw new U(E,`No matching operation found`);let a=await Q({operation:i.operation,blockContext:E,queryParams:r,pathParams:i.params,body:o,headers:s,parseOperationInputsFn:l,createBlockFn:d,createBlockParams:k,runStepOperationFn:f});return $({block:a}),a}else{let e=await kt(d,k);return $({block:e}),e}},Q=async e=>{let{operation:t,blockContext:n,queryParams:r,pathParams:i,body:a,headers:o,parseOperationInputsFn:s,createBlockFn:c,createBlockParams:l,runStepOperationFn:u}=e;n.operationType=t.operationType,n.schema=t.schema?.key;let d=At(r,n),f;try{f=s(t,{path:i,query:r,body:a,headers:o})}catch{throw new qe(n,`Error while parsing operation inputs`)}let p=await c({...l,inputs:f,operation:t,nextCursor:d});return await u({block:p})},Ot=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!0,statusCode:200}}},kt=async(e,t)=>{let n=await e({...t,inputs:void 0,operation:void 0,nextCursor:void 0});return{...n,response:{successful:!1,statusCode:500}}},At=(e,t)=>{let n=e?.next,r=a(n)&&t.operationType===`list`?b(n):void 0;if(r===null)throw new Je(t,`Invalid cursor.`);return r},$=({block:e})=>{let n=e.olapClient;if(t(n?.recordAction))return;let r=yt(e);n.recordAction({status:e.response?.successful?`success`:`error`,message:e.response?.message,outputs:e.outputs},r)},jt=async({operationId:e,account:t,connector:n,pathParams:r={},queryParams:i={},body:a={},headers:o={},logger:s,getHttpClient:c,getOlapClient:l,parseConnector:u=L,parseOperationInputsFn:d=B,createBlockContextFn:f=W,createBlockFn:p=D,runStepOperationFn:m=Y})=>Z({mode:`operation_id`,operationId:e,account:t,connector:n,pathParams:r,queryParams:i,body:a,headers:o,logger:s,getHttpClient:c,getOlapClient:l,parseConnector:u,parseOperationInputsFn:d,createBlockContextFn:f,createBlockFn:p,runStepOperationFn:m}),Mt=async({account:e,connector:t,category:n,path:r,method:i=`get`,queryParams:a={},body:o,headers:s,logger:c,getHttpClient:l,parseConnector:u=L,getOperationFromUrlFn:d=A,getOperationForRefreshAuthenticationFn:f=V,parseOperationInputsFn:p=B,createBlockContextFn:m=W,createBlockFn:h=D,runStepOperationFn:g=Y})=>{let _=Nt(r),v=_?await Z({mode:`refresh_authentication`,account:e,connector:t,getOperationForRefreshAuthenticationFn:f,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:g}):await Z({mode:`path`,account:e,category:n,connector:t,path:r,method:i,queryParams:a,body:o,headers:s,getOperationFromUrlFn:d,parseConnector:u,logger:c,getHttpClient:l,parseOperationInputsFn:p,createBlockContextFn:m,createBlockFn:h,runStepOperationFn:g});return v},Nt=e=>e===Qe,Pt=async({account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i=L,getTestOperationsFn:a=et,createBlockContextFn:o=W,createBlockFn:s=D,runStepOperationFn:c=Y})=>{let l=await Z({mode:`test_operations`,account:e,connector:t,logger:n,getHttpClient:r,parseConnector:i,getTestOperationsFn:a,createBlockContextFn:o,createBlockFn:s,runStepOperationFn:c});return l?.response?.successful??!1};export{H as ConnectSDKError,Qe as REFRESH_TOKEN_OPERATION_PATH,D as createBlock,$e as executeStepFunction,Ye as getActionsMeta,Xe as getActionsMetaFromConnectors,A as getOperationFromUrl,He as getRefreshTokenExpiresIn,Ve as getTokenExpiresIn,O as loadConnector,B as parseOperationInputs,L as parseYamlConnector,Z as runAction,jt as runConnectorAction,Mt as runConnectorOperation,Y as runStepOperation,Pt as runTestOperations,Be as supportsRefreshAuthentication,Ue as validateYamlConnector};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/connect-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@stackone/core": "*",
|
|
45
45
|
"@stackone/expressions": "*",
|
|
46
46
|
"@stackone/logger": "*",
|
|
47
|
+
"@stackone/olap": "*",
|
|
47
48
|
"@stackone/transport": "*",
|
|
48
49
|
"@stackone/utils": "*",
|
|
49
50
|
"path-to-regexp": "8.2.0",
|