@stackone/connect-sdk 1.31.1 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{StepFunctionsFactory as e,StepFunctionName as t,COMPOSITE_ID_LATEST_VERSION as o,decodeCompositeId as r,CoreError as n,encodeCompositeId as s,isCompositeId as i,isCursorEmpty as a,minifyCursor as c,updateCursor as p,AUTHENTICATION_SCHEMA as u,expandCursor as d}from"@stackone/core";import{safeEvaluate as l,safeEvaluateRecord as y}from"@stackone/expressions";import{HttpErrorMessages as m,HttpClientManager as g,isSuccessStatusCode as f}from"@stackone/transport";import{isMissing as b,isObject as h,isString as _,notMissing as v,isNumber as I}from"@stackone/utils";import{match as k}from"path-to-regexp";import{parse as C}from"yaml";import{z as E}from"zod";const w=async({block:o,stepFunctionName:r,params:n,buildStepFunction:s=e.build})=>{const i=s({functionName:r}).fn,a=await i({block:o,params:n}),c=r===t.MAP_FIELDS?{[t.MAP_FIELDS.toString()]:{output:{data:a.block.result},errors:a.errors,successful:a.successful}}:{};return{...a.block,steps:{...a?.block?.steps??{},...c}}},F=e=>{const t=e.operation?.compositeIdentifiers,r={...e.inputs??{}};if(!t?.enabled||b(r))return e;const n=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),s={version:t.version??o,aliases:n};return S(r,s,e.logger),{...e,inputs:r}},S=(e,t,o)=>{for(const r in e){const n=e[r];if("string"==typeof n||Array.isArray(n)&&n.every((e=>"string"==typeof e)))j(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)S(e,t,o);else"object"==typeof n&&null!==n&&S(n,t,o)}},j=(e,t,o,s,i)=>{try{const n=Array.isArray(e),a=n?e:[e];if(0===a.length)return;const c=[],p=[];for(const e of a)try{const t=r(e,s);c.push(t)}catch(o){i?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:t,inputElement:e,compositeIdentifierConfig:s,error:o}}),p.push(e)}const u=c?.filter((e=>Object.keys(e).length>1));u.length>0&&(o.decoded_ids={...o.decoded_ids??{},[t]:n?u:u[0]});const d=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])};c.every(d)&&(n?o[t]=[...c.map((e=>Object.values(e)[0])),...p]:c.length>0&&(o[t]=Object.values(c[0])[0]))}catch(e){e instanceof n&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?i?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):i?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})}},O="remote_",x=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",r=e.outputs?.[o];if(b(r))return e;const n=Array.isArray(r)?r.map((e=>T(e,t))):T(r,t);return{...e,outputs:{...e.outputs??{},[o]:n}}},T=(e,t)=>{const o=R(e,t),r=N(o);return{...e,...h(r)?r:{}}},R=(e,t)=>{const r=t.version??o,n={};return t.fields?.forEach((t=>{const o={},i=[];t.components.forEach((t=>{t.alias&&(o[t.name]=t.alias),i.push({key:t.name,value:e[t.name]})}));const a=1===i.length?i[0]:{identifiers:i},c={version:r,aliases:Object.keys(o).length>0?o:void 0},p=s(a,c);n[t.targetFieldKey]=p,t.remote&&(n[`${O}${t.remote}`]=e[t.remote])})),{...e,...n}},N=e=>{if(Array.isArray(e))return e.map((e=>N(e)));if(!h(e))return e;const t={...e};for(const[r,n]of Object.entries(e))if((h(n)||Array.isArray(n)&&n.length>0&&h(n[0]))&&(t[r]=N(n)),"id"===r||/.+_id(s)?$/.test(r))if(Array.isArray(n)&&n.every((e=>_(e)&&e.length>0))){const e=n.map((e=>{if(_(e)&&e.length>0&&!i(e))try{return s({key:r,value:e},{version:o})}catch{return e}return e}));t[r]=e,t[`${O}${r}`]=n}else if(_(n)&&n.length>0){if(i(n)||r.startsWith(O))continue;const e=s({key:r,value:n},{version:o});t[r]=e,t[`remote_${r}`]=n}return t},A=(e,t,o,r)=>{const n=b(e)?void 0:e.data,s=Object.keys(o).length+1,i=a({cursor:r,ignoreStepIndex:s});if(!h(e)||b(n)||(n?.length??0)<=t)return{result:e,next:v(r)&&!i?c(r):null};const u=r?.remote?.[s]?.pageNumber??1,d=(u-1)*t,l=d+t,y=n.slice(d,l),m=n.length>l||!i,g=p({cursor:r,stepIndex:s,pageNumber:u+1});return{result:{...e,data:y},next:m?c(g):null}},$=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=A,encodeResultCompositeIds:n=x,decodeInputCompositeIds:s=F})=>{const i=s(t);return n(await K({block:i,buildStepFunction:o,virtualPaginateResultFn:r}))},K=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=A})=>{const n=t.operation?.steps||{};let s={...t};const i=Object.keys(n),a=((e,t)=>{const o=Number(e.inputs?.page_size);return v(e.inputs?.page_size)&&I(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(t,25);let c=!1,u=null;for(const[e,t]of i.entries()){const r=n[t],i=r.stepFunction,a=o({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(r.condition&&!l(r.condition,s)){s=q({block:s,stepId:t,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(c){s=q({block:s,stepId:t,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const d=s.operation?.cursor.enabled?{...i.params,cursor:{token:s.nextCursor?.remote?.[e]?.providerPageCursor,position:s.nextCursor?.remote?.[e]?.position}}:i.params,y=await a({block:s,params:d});if(!1===y.successful){s=q({block:s,stepId:t,successful:!1,functionOutput:y});(r.ignoreError??!1)||(c=!0,u??=y.output?.statusCode??500)}else{const o=s.operation?.cursor.enabled?p({cursor:s.nextCursor,stepIndex:e,providerPageCursor:y.output?.next,position:y.output?.position}):void 0;s=q({block:{...y.block,nextCursor:o},stepId:t,functionOutput:y})}}const d=t.operation?.result?U(t.operation.result,s):void 0,y=t.operation?.cursor.enabled?r(d,a,n,s.nextCursor):void 0,g=!c,f=g?t.operation?.responses.success.statusCode??200:u??500,b=v(y)&&h(y.result)?{next:y.next,...y.result}:d;return{...s,outputs:b,response:{successful:g,statusCode:f,message:g?void 0:t.operation?.responses?.errors?.[f]?.description??m?.[f]??"Error while processing the request"}}},U=(e,t)=>h(e)?y(e,t):l(e,t),q=({block:e,stepId:t,successful:o,functionOutput:r,skipped:n,message:s})=>({...e,steps:{...e.steps,[t]:{successful:o??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:n,message:s}}}),P=async({inputs:e,context:t,operation:o,credentials:r,nextCursor:n,logger:s,getHttpClient:i=async()=>g.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,nextCursor:n,httpClient:await i(),logger:s}),M=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:a})=>({projectSecureId:a,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),z=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=H(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},D=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},H=(e,t,o)=>{const r=D(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),n=k(D(o))(D(r));if(!1!==n)return{path:e,params:n.params}}},L=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"unknown":return{statusCode:200};default:throw new Error(`Unknown operation type: ${e}`)}},V={key:E.string(),label:E.string(),required:E.boolean().optional().default(!1),secret:E.boolean().optional().default(!1),readOnly:E.boolean().optional().default(!1),placeholder:E.string().optional(),description:E.string().optional(),tooltip:E.string().optional()},G=E.discriminatedUnion("type",[E.object({...V,type:E.enum(["text","password"])}),E.object({...V,type:E.literal("select"),options:E.object({value:E.string(),label:E.string()}).array()})]),W=E.object({operationId:E.string(),categories:E.string().array(),operationType:E.enum(["list","get","create","update","delete","custom","unknown"]),schema:E.string().optional(),entrypointUrl:E.string().optional(),entrypointHttpMethod:E.string().optional(),description:E.string(),responses:E.object({statusCode:E.number(),description:E.string()}).array().optional(),inputs:E.object({name:E.string(),type:E.string(),required:E.boolean(),description:E.string(),in:E.string()}).array().optional(),cursor:E.object({enabled:E.boolean(),pageSize:E.number()}).optional(),compositeIdentifiers:E.object({enabled:E.boolean(),version:E.number().optional(),fields:E.object({targetFieldKey:E.string(),remote:E.string().optional(),components:E.string().array()}).array().optional()}).optional(),fieldConfigs:E.object({targetFieldKey:E.string(),alias:E.string().optional(),expression:E.string(),type:E.enum(["string","number","boolean","datetime_string","enum"]),custom:E.boolean().default(!1),hidden:E.boolean().default(!1),enumMapper:E.object({matcher:E.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"]).or(E.object({matchExpression:E.string(),value:E.string()}).array())}).optional()}).array().optional(),steps:E.object({stepId:E.string(),description:E.string(),stepFunction:E.object({functionName:E.string(),version:E.string().optional(),parameters:E.record(E.string(),E.unknown())}),condition:E.string().optional(),ignoreError:E.boolean().optional()}).array(),result:E.string().or(E.record(E.string(),E.unknown())).optional()}),B=E.object({StackOne:E.string(),info:E.object({title:E.string(),version:E.string(),key:E.string(),description:E.string().optional()}),baseUrl:E.string(),authentication:E.record(E.string(),E.object({type:E.string(),label:E.string(),authorization:u,environments:E.object({key:E.string(),name:E.string()}).array(),support:E.object({link:E.string(),description:E.string().optional()}),configFields:G.array().optional(),setupFields:G.array().optional(),testOperationsIds:E.string().array().optional()})).array().optional(),operations:W.array().optional()});function Y(e){try{const t=C(e),o=B.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=X(o),s={baseUrl:o.baseUrl,authentication:J(n)},i=Z(o,s);return r.operations=i,r.authentication=n,v(i)&&(r.categories=Q(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const J=e=>{const t={};for(const[o,r]of Object.entries(e))if(r&&"object"==typeof r){const{setupFields:e,configFields:n,support:s,testOperationsIds:i,...a}=r;t[o]=J(a)}else t[o]=r;return t},Q=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},X=e=>{const t={};for(const o of e.authentication??[]){const[e]=Object.keys(o),r=o[e].environments.reduce(((t,r)=>{const{key:n,name:s}=r,{environments:i,...a}=o[e];return t[n]={...a,envKey:n,envName:s},t}),{});t[e]=r}return t},Z=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const r=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),n=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),s=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),i=(e=>{const t={success:L(e.operationType),errors:{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."}}},o=e.responses?.reduce(((e,t)=>(f(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return o??t})(o),a=re(o),c=o.inputs||[];return a.enabled&&c?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),e[r??n]={id:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??s,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:i,cursor:a,compositeIdentifiers:ne(o),inputs:c,steps:o.steps.reduce(((e,r)=>(e[r.stepId]={id:r.stepId,description:r.description,condition:r.condition,ignoreError:r.ignoreError,stepFunction:{functionName:r.stepFunction.functionName,version:r.stepFunction.version,params:{...r.stepFunction.parameters,...se(r.stepFunction.functionName,t,r.stepFunction.parameters),..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{}}}},e)),{}),result:o.result},e}),{});return o},ee=(e,t)=>{if(!e.inputs)return{};const o=oe(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},te=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=E.string();break;case"number":o=E.number();break;case"boolean":o=E.boolean();break;default:o=E.any()}t[e.name]=e.required?o:o.optional()})),E.object(t)},oe=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),r=e.filter((e=>"body"===e.in)),n=e.filter((e=>"headers"===e.in));return E.object({path:te(t).optional(),query:te(o).optional(),body:te(r).optional(),headers:te(n).optional()})},re=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},ne=e=>{if(b(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),r=v(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:o,fields:r}}const t=[];for(const o of e.compositeIdentifiers?.fields??[]){const r=o.components.map((t=>{const o=e.fieldConfigs?.find((e=>e.targetFieldKey===t));return{name:t,alias:o?.alias}}));t.push({targetFieldKey:o.targetFieldKey,remote:o.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},se=(e,t,o={})=>{if("request"===e||"paginated_request"===e){const e=[{receivedStatus:500,targetStatus:502}];return{...t,customErrors:[...o.customErrors&&Array.isArray(o.customErrors)?o.customErrors:[],...e]}}return{}};class ie extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,ie)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class ae extends ie{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class ce extends ie{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class pe extends ie{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class ue extends ie{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const de=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:p=Y,getOperationFromUrlFn:u=z,parseOperationInputsFn:d=ee,createBlockContextFn:l=M,createBlockFn:y=P,runStepOperationFn:m=$})=>{const g=e.authConfigKey,f=e.environment??"production",h=e.secureId,v=e.projectSecureId,I=e.credentials,k=l({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:g,environment:f,accountSecureId:h,projectSecureId:v});let C;try{C=_(t)?p(t):t}catch{throw new ae(k,"Error while parsing connector")}const E=u(C,r,n);if(b(E))throw new ce(k,"No matching operation found");k.operationType=E.operation.operationType,k.schema=E.operation.schema?.key;const w=le(s,k);let F;try{F=d(E.operation,{query:s,body:i,headers:a,path:E.params})}catch{throw new pe(k,"Error while parsing operation inputs")}const S=await y({inputs:F,context:k,operation:E.operation,credentials:I,nextCursor:w,logger:c});return await m({block:S})},le=(e,t)=>{const o=e?.next,r=v(o)&&"list"===t.operationType?d(o):void 0;if(null===r)throw new ue(t,"Invalid cursor.");return r};export{ie as ConnectSDKError,P as createBlock,w as executeStepFunction,z as getOperationFromUrl,ee as parseOperationInputs,Y as parseYamlConnector,de as runConnectorOperation,$ as runStepOperation};
|
|
1
|
+
import{HttpClientManager as e,isSuccessStatusCode as t,HttpErrorMessages as o}from"@stackone/transport";import{match as r}from"path-to-regexp";import{AUTHENTICATION_SCHEMA as n,COMPOSITE_ID_LATEST_VERSION as s,StepFunctionsFactory as i,StepFunctionName as a,decodeCompositeId as c,CoreError as p,encodeCompositeId as u,isCompositeId as d,isCursorEmpty as l,minifyCursor as y,updateCursor as m,expandCursor as g}from"@stackone/core";import{notMissing as f,isMissing as b,isObject as h,isString as _,isNumber as v}from"@stackone/utils";import{parse as I}from"yaml";import{z as C}from"zod";import{safeEvaluateRecord as k,safeEvaluate as F}from"@stackone/expressions";const E=async({inputs:t,context:o,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>e.getInstance()})=>({inputs:t,fieldConfigs:[],context:o,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),S=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=j(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},w=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},j=(e,t,o)=>{const n=w(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=r(w(o))(w(n));if(!1!==s)return{path:e,params:s.params}}},O=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"unknown":return{statusCode:200};default:throw new Error(`Unknown operation type: ${e}`)}},x={key:C.string(),label:C.string(),required:C.boolean().optional().default(!1),secret:C.boolean().optional().default(!1),readOnly:C.boolean().optional().default(!1),placeholder:C.string().optional(),description:C.string().optional(),tooltip:C.string().optional()},R=C.discriminatedUnion("type",[C.object({...x,type:C.enum(["text","password"])}),C.object({...x,type:C.literal("select"),options:C.object({value:C.string(),label:C.string()}).array()})]),T=C.object({operationId:C.string(),categories:C.string().array(),operationType:C.enum(["list","get","create","update","delete","custom","unknown"]),schema:C.string().optional(),entrypointUrl:C.string().optional(),entrypointHttpMethod:C.string().optional(),description:C.string(),responses:C.object({statusCode:C.number(),description:C.string()}).array().optional(),inputs:C.object({name:C.string(),type:C.string(),required:C.boolean(),description:C.string(),in:C.string()}).array().optional(),cursor:C.object({enabled:C.boolean(),pageSize:C.number()}).optional(),compositeIdentifiers:C.object({enabled:C.boolean(),version:C.number().optional(),fields:C.object({targetFieldKey:C.string(),remote:C.string().optional(),components:C.string().array()}).array().optional()}).optional(),scheduledJobs:C.object({enabled:C.boolean(),type:C.enum(["data_sync"]),schedule:C.string(),description:C.string(),requestParams:C.object({fields:C.string().array().optional(),expand:C.string().array().optional(),filter:C.record(C.string(),C.string()).optional()}).optional(),syncFilter:C.object({name:C.enum(["updated_after","created_after"]),initialLoopbackPeriod:C.string(),incrementalLoopbackPeriod:C.string()}).optional()}).array().optional(),fieldConfigs:C.object({targetFieldKey:C.string(),alias:C.string().optional(),expression:C.string(),type:C.enum(["string","number","boolean","datetime_string","enum"]),custom:C.boolean().default(!1),hidden:C.boolean().default(!1),enumMapper:C.object({matcher:C.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"]).or(C.object({matchExpression:C.string(),value:C.string()}).array())}).optional()}).array().optional(),steps:C.object({stepId:C.string(),description:C.string(),stepFunction:C.object({functionName:C.string(),version:C.string().optional(),parameters:C.record(C.string(),C.unknown())}),condition:C.string().optional(),ignoreError:C.boolean().optional()}).array(),result:C.string().or(C.record(C.string(),C.unknown())).optional()}),N=C.object({StackOne:C.string(),info:C.object({title:C.string(),version:C.string(),key:C.string(),description:C.string().optional()}),baseUrl:C.string(),authentication:C.record(C.string(),C.object({type:C.string(),label:C.string(),authorization:n,environments:C.object({key:C.string(),name:C.string()}).array(),support:C.object({link:C.string(),description:C.string().optional()}),configFields:R.array().optional(),setupFields:R.array().optional(),testOperationsIds:C.string().array().optional()})).array().optional(),operations:T.array().optional()});function A(e){try{const t=I(e),o=N.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=P(o),s={baseUrl:o.baseUrl,authentication:$(n)},i=q(o,s);return r.operations=i,r.authentication=n,f(i)&&(r.categories=K(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const $=e=>{const t={};for(const[o,r]of Object.entries(e))if(r&&"object"==typeof r){const{setupFields:e,configFields:n,support:s,testOperationsIds:i,...a}=r;t[o]=$(a)}else t[o]=r;return t},K=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},P=e=>{const t={};for(const o of e.authentication??[]){const[e]=Object.keys(o),r=o[e].environments.reduce(((t,r)=>{const{key:n,name:s}=r,{environments:i,...a}=o[e];return t[n]={...a,envKey:n,envName:s},t}),{});t[e]=r}return t},q=(e,o)=>{const r=e.operations?.reduce(((e,r)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(r),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(r),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(r),a=(e=>{const o={success:O(e.operationType),errors:{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."}}},r=e.responses?.reduce(((e,o)=>(t(o.statusCode)?e.success={statusCode:o.statusCode,description:o.description}:e.errors[o.statusCode]={statusCode:o.statusCode,description:o.description},e)),o);return r??o})(r),c=D(r),p=r.inputs||[];return c.enabled&&p?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),e[n??s]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:L(r),scheduledJobs:H(r),inputs:p,steps:r.steps.reduce(((e,t)=>(e[t.stepId]={id:t.stepId,description:t.description,condition:t.condition,ignoreError:t.ignoreError,stepFunction:{functionName:t.stepFunction.functionName,version:t.stepFunction.version,params:{...t.stepFunction.parameters,...V(t.stepFunction.functionName,o,t.stepFunction.parameters),..."map_fields"===t.stepFunction.functionName||"typecast"===t.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},e}),{});return r},U=(e,t)=>{if(!e.inputs)return{};const o=z(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},M=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=C.string();break;case"number":o=C.number();break;case"boolean":o=C.boolean();break;default:o=C.any()}t[e.name]=e.required?o:o.optional()})),C.object(t)},z=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),r=e.filter((e=>"body"===e.in)),n=e.filter((e=>"headers"===e.in));return C.object({path:M(t).optional(),query:M(o).optional(),body:M(r).optional(),headers:M(n).optional()})},D=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},L=e=>{if(b(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),o=f(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:s,fields:o}}const t=[];for(const o of e.compositeIdentifiers?.fields??[]){const r=o.components.map((t=>{const o=e.fieldConfigs?.find((e=>e.targetFieldKey===t));return{name:t,alias:o?.alias}}));t.push({targetFieldKey:o.targetFieldKey,remote:o.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},H=e=>{if(!b(e.scheduledJobs))return e.scheduledJobs},V=(e,t,o={})=>{if("request"===e||"paginated_request"===e){const e=[{receivedStatus:500,targetStatus:502}];return{...t,customErrors:[...o.customErrors&&Array.isArray(o.customErrors)?o.customErrors:[],...e]}}return{}};class G extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,G)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class J extends G{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class W extends G{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class B extends G{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class Y extends G{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const Q=async({block:e,stepFunctionName:t,params:o,buildStepFunction:r=i.build})=>{const n=r({functionName:t}).fn,s=await n({block:e,params:o}),c=t===a.MAP_FIELDS?{[a.MAP_FIELDS.toString()]:{output:{data:s.block.result},errors:s.errors,successful:s.successful}}:{};return{...s.block,steps:{...s?.block?.steps??{},...c}}},X=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:a})=>({projectSecureId:a,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),Z=e=>{const t=e.operation?.compositeIdentifiers,o={...e.inputs??{}};if(!t?.enabled||b(o))return e;const r=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),n={version:t.version??s,aliases:r};return ee(o,n,e.logger),{...e,inputs:o}},ee=(e,t,o)=>{for(const r in e){const n=e[r];if("string"==typeof n||Array.isArray(n)&&n.every((e=>"string"==typeof e)))oe(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)ee(e,t,o);else"object"==typeof n&&null!==n&&ee(n,t,o)}},te=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},oe=(e,t,o,r,n)=>{try{const s=Array.isArray(e),i=s?e:[e];if(0===i.length)return;const{compositeIdComponents:a,nonCompositeIds:p}=((e,t,o,r)=>{const n=[],s=[];for(const i of e)try{const e=c(i,o);n.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:i,compositeIdentifierConfig:o,error:e}}),s.push(i)}return{compositeIdComponents:n,nonCompositeIds:s}})(i,t,r,n);((e,t,o,r)=>{const n=o.filter((e=>Object.keys(e).length>1));n.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?n:n[0]})})(o,t,a,s),((e,t,o,r,n)=>{o.every(te)&&(n?e[t]=[...o.map((e=>Object.values(e)[0])),...r]:o.length>0&&(e[t]=Object.values(o[0])[0]))})(o,t,a,p,s)}catch(e){((e,t,o)=>{e instanceof p&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?o?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):o?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})})(e,t,n)}},re="remote_",ne=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",r=e.outputs?.[o];if(b(r))return e;const n=Array.isArray(r)?r.map((e=>se(e,t))):se(r,t);return{...e,outputs:{...e.outputs??{},[o]:n}}},se=(e,t)=>{const o=ie(e,t),r=de(o);return{...e,...h(r)?r:{}}},ie=(e,t)=>{const o=t.version??s,r={};return t.fields?.forEach((t=>{const n={},s=[];t.components.forEach((t=>{t.alias&&(n[t.name]=t.alias),s.push({key:t.name,value:e[t.name]})}));const i=1===s.length?s[0]:{identifiers:s},a={version:o,aliases:Object.keys(n).length>0?n:void 0},c=u(i,a);r[t.targetFieldKey]=c,t.remote&&(r[`${re}${t.remote}`]=e[t.remote])})),{...e,...r}},ae=e=>"id"===e||/.+_id(s)?$/.test(e),ce=(e,t,o)=>{const r=t.map((t=>_(t)&&t.length>0&&!d(t)?((e,t)=>{try{return u({key:e,value:t},{version:s})}catch{return t}})(e,t):t));o[e]=r,o[`${re}${e}`]=t},pe=(e,t,o)=>{if(((e,t)=>d(e)||t.startsWith(re))(t,e))return;const r=u({key:e,value:t},{version:s});o[e]=r,o[`remote_${e}`]=t},ue=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>_(e)&&e.length>0)))(t)?ce(e,t,o):_(t)&&t.length>0&&pe(e,t,o)},de=e=>{if(Array.isArray(e))return e.map((e=>de(e)));if(!h(e))return e;const t={...e};for(const[o,r]of Object.entries(e))(h(r)||Array.isArray(r)&&r.length>0&&h(r[0]))&&(t[o]=de(r)),ae(o)&&ue(o,r,t);return t},le=(e,t,o,r)=>{const n=b(e)?void 0:e.data,s=Object.keys(o).length+1,i=l({cursor:r,ignoreStepIndex:s});if(!h(e)||b(n)||(n?.length??0)<=t)return{result:e,next:f(r)&&!i?y(r):null};const a=r?.remote?.[s]?.pageNumber??1,c=(a-1)*t,p=c+t,u=n.slice(c,p),d=n.length>p||!i,g=m({cursor:r,stepIndex:s,pageNumber:a+1});return{result:{...e,data:u},next:d?y(g):null}},ye=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:o=le,encodeResultCompositeIds:r=ne,decodeInputCompositeIds:n=Z})=>{const s=n(e);return r(await ge({block:s,buildStepFunction:t,virtualPaginateResultFn:o}))},me=async(e,t,o,r,n,s)=>{const i=o[e],a=i.stepFunction,c=s.buildStepFunction({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(((e,t)=>!!e.condition&&!F(e.condition,t))(i,r))return be({block:r,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(n.hasFatalError)return be({block:r,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});const p=((e,t,o)=>{const r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[o]?.providerPageCursor,position:t.nextCursor?.remote?.[o]?.position}}:r.params??{}})(i,r,t),u=await c({block:r,params:p});if(!1===u.successful)return((e,t,o,r,n)=>{const s=be({block:e,stepId:t,successful:!1,functionOutput:o});return(r.ignoreError??!1)||(n.hasFatalError=!0,n.errorStatusCode??=o.output?.statusCode??500),s})(r,e,u,i,n);const d=r.operation?.cursor.enabled?m({cursor:r.nextCursor,stepIndex:t,providerPageCursor:u.output?.next,position:u.output?.position}):void 0;return be({block:{...u.block,nextCursor:d},stepId:e,functionOutput:u})},ge=async({block:e,buildStepFunction:t=i.build,virtualPaginateResultFn:r=le})=>{const n=e.operation?.steps||{};let s={...e};const a=Object.keys(n),c=((e,t)=>{const o=Number(e.inputs?.page_size);return f(e.inputs?.page_size)&&v(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(e,25),p={hasFatalError:!1,errorStatusCode:null},u={block:e,buildStepFunction:t,virtualPaginateResultFn:r};for(const[e,t]of a.entries())s=await me(t,e,n,s,p,u);const d=e.operation?.result?fe(e.operation.result,s):void 0;return((e,t,r,n,s)=>{const i=!r.hasFatalError,a=i?e.operation?.responses.success.statusCode??200:r.errorStatusCode??500;return{...t,outputs:f(s)&&h(s.result)?{next:s.next,...s.result}:n,response:{successful:i,statusCode:a,message:i?void 0:e.operation?.responses?.errors?.[a]?.description??o?.[a]??"Error while processing the request"}}})(e,s,p,d,e.operation?.cursor.enabled?r(d,c,n,s.nextCursor):void 0)},fe=(e,t)=>h(e)?k(e,t):F(e,t),be=({block:e,stepId:t,successful:o,functionOutput:r,skipped:n,message:s})=>({...e,steps:{...e.steps,[t]:{successful:o??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:n,message:s}}}),he=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:p=A,getOperationFromUrlFn:u=S,parseOperationInputsFn:d=U,createBlockContextFn:l=X,createBlockFn:y=E,runStepOperationFn:m=ye})=>{const g=e.authConfigKey,f=e.environment??"production",h=e.secureId,v=e.projectSecureId,I=e.credentials,C=l({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:g,environment:f,accountSecureId:h,projectSecureId:v});let k;try{k=_(t)?p(t):t}catch{throw new J(C,"Error while parsing connector")}const F=u(k,r,n);if(b(F))throw new W(C,"No matching operation found");C.operationType=F.operation.operationType,C.schema=F.operation.schema?.key;const w=_e(s,C);let j;try{j=d(F.operation,{query:s,body:i,headers:a,path:F.params})}catch{throw new B(C,"Error while parsing operation inputs")}const O=await y({inputs:j,context:C,operation:F.operation,credentials:I,nextCursor:w,logger:c});return await m({block:O})},_e=(e,t)=>{const o=e?.next,r=f(o)&&"list"===t.operationType?g(o):void 0;if(null===r)throw new Y(t,"Invalid cursor.");return r};export{G as ConnectSDKError,E as createBlock,Q as executeStepFunction,S as getOperationFromUrl,U as parseOperationInputs,A as parseYamlConnector,he as runConnectorOperation,ye as runStepOperation};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/transport"),r=require("@stackone/utils"),n=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=t=>{const o=t.operation?.compositeIdentifiers,n={...t.inputs??{}};if(!o?.enabled||r.isMissing(n))return t;const s=o.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),i={version:o.version??e.COMPOSITE_ID_LATEST_VERSION,aliases:s};return c(n,i,t.logger),{...t,inputs:n}},c=(e,t,o)=>{for(const r in e){const n=e[r];if("string"==typeof n||Array.isArray(n)&&n.every((e=>"string"==typeof e)))u(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)c(e,t,o);else"object"==typeof n&&null!==n&&c(n,t,o)}},u=(t,o,r,n,s)=>{try{const i=Array.isArray(t),a=i?t:[t];if(0===a.length)return;const c=[],u=[];for(const t of a)try{const o=e.decodeCompositeId(t,n);c.push(o)}catch(e){s?.debug({message:`Received ${o} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:o,inputElement:t,compositeIdentifierConfig:n,error:e}}),u.push(t)}const p=c?.filter((e=>Object.keys(e).length>1));p.length>0&&(r.decoded_ids={...r.decoded_ids??{},[o]:i?p:p[0]});const d=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])};c.every(d)&&(i?r[o]=[...c.map((e=>Object.values(e)[0])),...u]:c.length>0&&(r[o]=Object.values(c[0])[0]))}catch(t){t instanceof e.CoreError&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===t.type?s?.debug({message:`Received ${o} with no composite ID header, assuming it is not a composite ID`}):s?.warning({message:`Error processing composite ID for ${o}, ignoring it`,error:t})}},p="remote_",d=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",n=e.outputs?.[o];if(r.isMissing(n))return e;const s=Array.isArray(n)?n.map((e=>l(e,t))):l(n,t);return{...e,outputs:{...e.outputs??{},[o]:s}}},l=(e,t)=>{const o=y(e,t),n=g(o);return{...e,...r.isObject(n)?n:{}}},y=(t,o)=>{const r=o.version??e.COMPOSITE_ID_LATEST_VERSION,n={};return o.fields?.forEach((o=>{const s={},i=[];o.components.forEach((e=>{e.alias&&(s[e.name]=e.alias),i.push({key:e.name,value:t[e.name]})}));const a=1===i.length?i[0]:{identifiers:i},c={version:r,aliases:Object.keys(s).length>0?s:void 0},u=e.encodeCompositeId(a,c);n[o.targetFieldKey]=u,o.remote&&(n[`${p}${o.remote}`]=t[o.remote])})),{...t,...n}},g=t=>{if(Array.isArray(t))return t.map((e=>g(e)));if(!r.isObject(t))return t;const o={...t};for(const[n,s]of Object.entries(t))if((r.isObject(s)||Array.isArray(s)&&s.length>0&&r.isObject(s[0]))&&(o[n]=g(s)),"id"===n||/.+_id(s)?$/.test(n))if(Array.isArray(s)&&s.every((e=>r.isString(e)&&e.length>0))){const t=s.map((t=>{if(r.isString(t)&&t.length>0&&!e.isCompositeId(t))try{return e.encodeCompositeId({key:n,value:t},{version:e.COMPOSITE_ID_LATEST_VERSION})}catch{return t}return t}));o[n]=t,o[`${p}${n}`]=s}else if(r.isString(s)&&s.length>0){if(e.isCompositeId(s)||n.startsWith(p))continue;const t=e.encodeCompositeId({key:n,value:s},{version:e.COMPOSITE_ID_LATEST_VERSION});o[n]=t,o[`remote_${n}`]=s}return o},m=(t,o,n,s)=>{const i=r.isMissing(t)?void 0:t.data,a=Object.keys(n).length+1,c=e.isCursorEmpty({cursor:s,ignoreStepIndex:a});if(!r.isObject(t)||r.isMissing(i)||(i?.length??0)<=o)return{result:t,next:r.notMissing(s)&&!c?e.minifyCursor(s):null};const u=s?.remote?.[a]?.pageNumber??1,p=(u-1)*o,d=p+o,l=i.slice(p,d),y=i.length>d||!c,g=e.updateCursor({cursor:s,stepIndex:a,pageNumber:u+1});return{result:{...t,data:l},next:y?e.minifyCursor(g):null}},f=async({block:t,buildStepFunction:o=e.StepFunctionsFactory.build,virtualPaginateResultFn:r=m,encodeResultCompositeIds:n=d,decodeInputCompositeIds:s=a})=>{const i=s(t);return n(await b({block:i,buildStepFunction:o,virtualPaginateResultFn:r}))},b=async({block:n,buildStepFunction:s=e.StepFunctionsFactory.build,virtualPaginateResultFn:i=m})=>{const a=n.operation?.steps||{};let c={...n};const u=Object.keys(a),p=((e,t)=>{const o=Number(e.inputs?.page_size);return r.notMissing(e.inputs?.page_size)&&r.isNumber(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(n,25);let d=!1,l=null;for(const[o,r]of u.entries()){const n=a[r],i=n.stepFunction,u=s({functionName:i.functionName,version:i.version,validateSchemas:!0}).fn;if(n.condition&&!t.safeEvaluate(n.condition,c)){c=_({block:c,stepId:r,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(d){c=_({block:c,stepId:r,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const p=c.operation?.cursor.enabled?{...i.params,cursor:{token:c.nextCursor?.remote?.[o]?.providerPageCursor,position:c.nextCursor?.remote?.[o]?.position}}:i.params,y=await u({block:c,params:p});if(!1===y.successful){c=_({block:c,stepId:r,successful:!1,functionOutput:y});(n.ignoreError??!1)||(d=!0,l??=y.output?.statusCode??500)}else{const t=c.operation?.cursor.enabled?e.updateCursor({cursor:c.nextCursor,stepIndex:o,providerPageCursor:y.output?.next,position:y.output?.position}):void 0;c=_({block:{...y.block,nextCursor:t},stepId:r,functionOutput:y})}}const y=n.operation?.result?h(n.operation.result,c):void 0,g=n.operation?.cursor.enabled?i(y,p,a,c.nextCursor):void 0,f=!d,b=f?n.operation?.responses.success.statusCode??200:l??500,z=r.notMissing(g)&&r.isObject(g.result)?{next:g.next,...g.result}:y;return{...c,outputs:z,response:{successful:f,statusCode:b,message:f?void 0:n.operation?.responses?.errors?.[b]?.description??o.HttpErrorMessages?.[b]??"Error while processing the request"}}},h=(e,o)=>r.isObject(e)?t.safeEvaluateRecord(e,o):t.safeEvaluate(e,o),_=({block:e,stepId:t,successful:o,functionOutput:r,skipped:n,message:s})=>({...e,steps:{...e.steps,[t]:{successful:o??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:n,message:s}}}),z=async({inputs:e,context:t,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>o.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),I=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:a})=>({projectSecureId:a,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),C=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=S(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},v=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},S=(e,t,o)=>{const r=v(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=n.match(v(o))(v(r));if(!1!==s)return{path:e,params:s.params}}},E=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"unknown":return{statusCode:200};default:throw new Error(`Unknown operation type: ${e}`)}},O={key:i.z.string(),label:i.z.string(),required:i.z.boolean().optional().default(!1),secret:i.z.boolean().optional().default(!1),readOnly:i.z.boolean().optional().default(!1),placeholder:i.z.string().optional(),description:i.z.string().optional(),tooltip:i.z.string().optional()},k=i.z.discriminatedUnion("type",[i.z.object({...O,type:i.z.enum(["text","password"])}),i.z.object({...O,type:i.z.literal("select"),options:i.z.object({value:i.z.string(),label:i.z.string()}).array()})]),F=i.z.object({operationId:i.z.string(),categories:i.z.string().array(),operationType:i.z.enum(["list","get","create","update","delete","custom","unknown"]),schema:i.z.string().optional(),entrypointUrl:i.z.string().optional(),entrypointHttpMethod:i.z.string().optional(),description:i.z.string(),responses:i.z.object({statusCode:i.z.number(),description:i.z.string()}).array().optional(),inputs:i.z.object({name:i.z.string(),type:i.z.string(),required:i.z.boolean(),description:i.z.string(),in:i.z.string()}).array().optional(),cursor:i.z.object({enabled:i.z.boolean(),pageSize:i.z.number()}).optional(),compositeIdentifiers:i.z.object({enabled:i.z.boolean(),version:i.z.number().optional(),fields:i.z.object({targetFieldKey:i.z.string(),remote:i.z.string().optional(),components:i.z.string().array()}).array().optional()}).optional(),fieldConfigs:i.z.object({targetFieldKey:i.z.string(),alias:i.z.string().optional(),expression:i.z.string(),type:i.z.enum(["string","number","boolean","datetime_string","enum"]),custom:i.z.boolean().default(!1),hidden:i.z.boolean().default(!1),enumMapper:i.z.object({matcher:i.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"]).or(i.z.object({matchExpression:i.z.string(),value:i.z.string()}).array())}).optional()}).array().optional(),steps:i.z.object({stepId:i.z.string(),description:i.z.string(),stepFunction:i.z.object({functionName:i.z.string(),version:i.z.string().optional(),parameters:i.z.record(i.z.string(),i.z.unknown())}),condition:i.z.string().optional(),ignoreError:i.z.boolean().optional()}).array(),result:i.z.string().or(i.z.record(i.z.string(),i.z.unknown())).optional()}),T=i.z.object({StackOne:i.z.string(),info:i.z.object({title:i.z.string(),version:i.z.string(),key:i.z.string(),description:i.z.string().optional()}),baseUrl:i.z.string(),authentication:i.z.record(i.z.string(),i.z.object({type:i.z.string(),label:i.z.string(),authorization:e.AUTHENTICATION_SCHEMA,environments:i.z.object({key:i.z.string(),name:i.z.string()}).array(),support:i.z.object({link:i.z.string(),description:i.z.string().optional()}),configFields:k.array().optional(),setupFields:k.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:F.array().optional()});function j(e){try{const t=s.parse(e),o=T.parse(t),n={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=N(o),a={baseUrl:o.baseUrl,authentication:x(i)},c=R(o,a);return n.operations=c,n.authentication=i,r.notMissing(c)&&(n.categories=w(Object.values(c))),n}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const x=e=>{const t={};for(const[o,r]of Object.entries(e))if(r&&"object"==typeof r){const{setupFields:e,configFields:n,support:s,testOperationsIds:i,...a}=r;t[o]=x(a)}else t[o]=r;return t},w=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},N=e=>{const t={};for(const o of e.authentication??[]){const[e]=Object.keys(o),r=o[e].environments.reduce(((t,r)=>{const{key:n,name:s}=r,{environments:i,...a}=o[e];return t[n]={...a,envKey:n,envName:s},t}),{});t[e]=r}return t},R=(e,t)=>{const r=e.operations?.reduce(((e,r)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(r),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(r),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(r),a=(e=>{const t={success:E(e.operationType),errors:{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."}}},r=e.responses?.reduce(((e,t)=>(o.isSuccessStatusCode(t.statusCode)?e.success={statusCode:t.statusCode,description:t.description}:e.errors[t.statusCode]={statusCode:t.statusCode,description:t.description},e)),t);return r??t})(r),c=$(r),u=r.inputs||[];return c.enabled&&u?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),e[n??s]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:K(r),inputs:u,steps:r.steps.reduce(((e,o)=>(e[o.stepId]={id:o.stepId,description:o.description,condition:o.condition,ignoreError:o.ignoreError,stepFunction:{functionName:o.stepFunction.functionName,version:o.stepFunction.version,params:{...o.stepFunction.parameters,...P(o.stepFunction.functionName,t,o.stepFunction.parameters),..."map_fields"===o.stepFunction.functionName||"typecast"===o.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},e}),{});return r},A=(e,t)=>{if(!e.inputs)return{};const o=q(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},M=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=i.z.string();break;case"number":o=i.z.number();break;case"boolean":o=i.z.boolean();break;default:o=i.z.any()}t[e.name]=e.required?o:o.optional()})),i.z.object(t)},q=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),r=e.filter((e=>"body"===e.in)),n=e.filter((e=>"headers"===e.in));return i.z.object({path:M(t).optional(),query:M(o).optional(),body:M(r).optional(),headers:M(n).optional()})},$=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},K=t=>{if(r.isMissing(t.compositeIdentifiers)){const o=t.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),n=r.notMissing(o)?[{targetFieldKey:o.targetFieldKey,remote:"id",components:[{name:o.targetFieldKey,alias:o.alias}]}]:void 0;return{enabled:!0,version:e.COMPOSITE_ID_LATEST_VERSION,fields:n}}const o=[];for(const e of t.compositeIdentifiers?.fields??[]){const r=e.components.map((e=>{const o=t.fieldConfigs?.find((t=>t.targetFieldKey===e));return{name:e,alias:o?.alias}}));o.push({targetFieldKey:e.targetFieldKey,remote:e.remote,components:r})}return{enabled:t.compositeIdentifiers.enabled,version:t.compositeIdentifiers.version,fields:o.length>0?o:void 0}},P=(e,t,o={})=>{if("request"===e||"paginated_request"===e){const e=[{receivedStatus:500,targetStatus:502}];return{...t,customErrors:[...o.customErrors&&Array.isArray(o.customErrors)?o.customErrors:[],...e]}}return{}};class D extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,D)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class U extends D{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class H extends D{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class L extends D{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class V extends D{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const G=(t,o)=>{const n=t?.next,s=r.notMissing(n)&&"list"===o.operationType?e.expandCursor(n):void 0;if(null===s)throw new V(o,"Invalid cursor.");return s};exports.ConnectSDKError=D,exports.createBlock=z,exports.executeStepFunction=async({block:t,stepFunctionName:o,params:r,buildStepFunction:n=e.StepFunctionsFactory.build})=>{const s=n({functionName:o}).fn,i=await s({block:t,params:r}),a=o===e.StepFunctionName.MAP_FIELDS?{[e.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:i.block.result},errors:i.errors,successful:i.successful}}:{};return{...i.block,steps:{...i?.block?.steps??{},...a}}},exports.getOperationFromUrl=C,exports.parseOperationInputs=A,exports.parseYamlConnector=j,exports.runConnectorOperation=async({account:e,connector:t,category:o,path:n,method:s="get",queryParams:i,body:a,headers:c,logger:u,parseConnector:p=j,getOperationFromUrlFn:d=C,parseOperationInputsFn:l=A,createBlockContextFn:y=I,createBlockFn:g=z,runStepOperationFn:m=f})=>{const b=e.authConfigKey,h=e.environment??"production",_=e.secureId,v=e.projectSecureId,S=e.credentials,E=y({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:b,environment:h,accountSecureId:_,projectSecureId:v});let O;try{O=r.isString(t)?p(t):t}catch{throw new U(E,"Error while parsing connector")}const k=d(O,n,s);if(r.isMissing(k))throw new H(E,"No matching operation found");E.operationType=k.operation.operationType,E.schema=k.operation.schema?.key;const F=G(i,E);let T;try{T=l(k.operation,{query:i,body:a,headers:c,path:k.params})}catch{throw new L(E,"Error while parsing operation inputs")}const x=await g({inputs:T,context:E,operation:k.operation,credentials:S,nextCursor:F,logger:u});return await m({block:x})},exports.runStepOperation=f;
|
|
1
|
+
"use strict";var e=require("@stackone/transport"),t=require("path-to-regexp"),o=require("@stackone/core"),r=require("@stackone/utils"),n=require("yaml"),s=require("zod"),i=require("@stackone/expressions");const a=async({inputs:t,context:o,operation:r,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>e.HttpClientManager.getInstance()})=>({inputs:t,fieldConfigs:[],context:o,operation:r,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),c=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=p(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},u=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},p=(e,o,r)=>{const n=u(e);for(const e of r)if(e.startsWith(o)){const r=e.replace(`${o} `,"").trim(),s=t.match(u(r))(u(n));if(!1!==s)return{path:e,params:s.params}}},d=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"unknown":return{statusCode:200};default:throw new Error(`Unknown operation type: ${e}`)}},l={key:s.z.string(),label:s.z.string(),required:s.z.boolean().optional().default(!1),secret:s.z.boolean().optional().default(!1),readOnly:s.z.boolean().optional().default(!1),placeholder:s.z.string().optional(),description:s.z.string().optional(),tooltip:s.z.string().optional()},y=s.z.discriminatedUnion("type",[s.z.object({...l,type:s.z.enum(["text","password"])}),s.z.object({...l,type:s.z.literal("select"),options:s.z.object({value:s.z.string(),label:s.z.string()}).array()})]),g=s.z.object({operationId:s.z.string(),categories:s.z.string().array(),operationType:s.z.enum(["list","get","create","update","delete","custom","unknown"]),schema:s.z.string().optional(),entrypointUrl:s.z.string().optional(),entrypointHttpMethod:s.z.string().optional(),description:s.z.string(),responses:s.z.object({statusCode:s.z.number(),description:s.z.string()}).array().optional(),inputs:s.z.object({name:s.z.string(),type:s.z.string(),required:s.z.boolean(),description:s.z.string(),in:s.z.string()}).array().optional(),cursor:s.z.object({enabled:s.z.boolean(),pageSize:s.z.number()}).optional(),compositeIdentifiers:s.z.object({enabled:s.z.boolean(),version:s.z.number().optional(),fields:s.z.object({targetFieldKey:s.z.string(),remote:s.z.string().optional(),components:s.z.string().array()}).array().optional()}).optional(),scheduledJobs:s.z.object({enabled:s.z.boolean(),type:s.z.enum(["data_sync"]),schedule:s.z.string(),description:s.z.string(),requestParams:s.z.object({fields:s.z.string().array().optional(),expand:s.z.string().array().optional(),filter:s.z.record(s.z.string(),s.z.string()).optional()}).optional(),syncFilter:s.z.object({name:s.z.enum(["updated_after","created_after"]),initialLoopbackPeriod:s.z.string(),incrementalLoopbackPeriod:s.z.string()}).optional()}).array().optional(),fieldConfigs:s.z.object({targetFieldKey:s.z.string(),alias:s.z.string().optional(),expression:s.z.string(),type:s.z.enum(["string","number","boolean","datetime_string","enum"]),custom:s.z.boolean().default(!1),hidden:s.z.boolean().default(!1),enumMapper:s.z.object({matcher:s.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"]).or(s.z.object({matchExpression:s.z.string(),value:s.z.string()}).array())}).optional()}).array().optional(),steps:s.z.object({stepId:s.z.string(),description:s.z.string(),stepFunction:s.z.object({functionName:s.z.string(),version:s.z.string().optional(),parameters:s.z.record(s.z.string(),s.z.unknown())}),condition:s.z.string().optional(),ignoreError:s.z.boolean().optional()}).array(),result:s.z.string().or(s.z.record(s.z.string(),s.z.unknown())).optional()}),m=s.z.object({StackOne:s.z.string(),info:s.z.object({title:s.z.string(),version:s.z.string(),key:s.z.string(),description:s.z.string().optional()}),baseUrl:s.z.string(),authentication:s.z.record(s.z.string(),s.z.object({type:s.z.string(),label:s.z.string(),authorization:o.AUTHENTICATION_SCHEMA,environments:s.z.object({key:s.z.string(),name:s.z.string()}).array(),support:s.z.object({link:s.z.string(),description:s.z.string().optional()}),configFields:y.array().optional(),setupFields:y.array().optional(),testOperationsIds:s.z.string().array().optional()})).array().optional(),operations:g.array().optional()});function b(e){try{const t=n.parse(e),o=m.parse(t),s={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},i=z(o),a={baseUrl:o.baseUrl,authentication:f(i)},c=_(o,a);return s.operations=c,s.authentication=i,r.notMissing(c)&&(s.categories=h(Object.values(c))),s}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const f=e=>{const t={};for(const[o,r]of Object.entries(e))if(r&&"object"==typeof r){const{setupFields:e,configFields:n,support:s,testOperationsIds:i,...a}=r;t[o]=f(a)}else t[o]=r;return t},h=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},z=e=>{const t={};for(const o of e.authentication??[]){const[e]=Object.keys(o),r=o[e].environments.reduce(((t,r)=>{const{key:n,name:s}=r,{environments:i,...a}=o[e];return t[n]={...a,envKey:n,envName:s},t}),{});t[e]=r}return t},_=(t,o)=>{const r=t.operations?.reduce(((t,r)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(r),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(r),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(r),a=(t=>{const o={success:d(t.operationType),errors:{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."}}},r=t.responses?.reduce(((t,o)=>(e.isSuccessStatusCode(o.statusCode)?t.success={statusCode:o.statusCode,description:o.description}:t.errors[o.statusCode]={statusCode:o.statusCode,description:o.description},t)),o);return r??o})(r),c=S(r),u=r.inputs||[];return c.enabled&&u?.push({type:"string",name:"page_size",in:"query",required:!1,description:"Number of items to return per page"}),t[n??s]={id:r.operationId,categories:r.categories,description:r.description,operationType:r.operationType,entrypointUrl:r.entrypointUrl??i,entrypointHttpMethod:r.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:E(r),scheduledJobs:O(r),inputs:u,steps:r.steps.reduce(((e,t)=>(e[t.stepId]={id:t.stepId,description:t.description,condition:t.condition,ignoreError:t.ignoreError,stepFunction:{functionName:t.stepFunction.functionName,version:t.stepFunction.version,params:{...t.stepFunction.parameters,...k(t.stepFunction.functionName,o,t.stepFunction.parameters),..."map_fields"===t.stepFunction.functionName||"typecast"===t.stepFunction.functionName?{fields:r.fieldConfigs}:{}}}},e)),{}),result:r.result},t}),{});return r},I=(e,t)=>{if(!e.inputs)return{};const o=v(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},C=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=s.z.string();break;case"number":o=s.z.number();break;case"boolean":o=s.z.boolean();break;default:o=s.z.any()}t[e.name]=e.required?o:o.optional()})),s.z.object(t)},v=e=>{const t=e.filter((e=>"path"===e.in)),o=e.filter((e=>"query"===e.in)),r=e.filter((e=>"body"===e.in)),n=e.filter((e=>"headers"===e.in));return s.z.object({path:C(t).optional(),query:C(o).optional(),body:C(r).optional(),headers:C(n).optional()})},S=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},E=e=>{if(r.isMissing(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),n=r.notMissing(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,alias:t.alias}]}]:void 0;return{enabled:!0,version:o.COMPOSITE_ID_LATEST_VERSION,fields:n}}const t=[];for(const o of e.compositeIdentifiers?.fields??[]){const r=o.components.map((t=>{const o=e.fieldConfigs?.find((e=>e.targetFieldKey===t));return{name:t,alias:o?.alias}}));t.push({targetFieldKey:o.targetFieldKey,remote:o.remote,components:r})}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:t.length>0?t:void 0}},O=e=>{if(!r.isMissing(e.scheduledJobs))return e.scheduledJobs},k=(e,t,o={})=>{if("request"===e||"paginated_request"===e){const e=[{receivedStatus:500,targetStatus:502}];return{...t,customErrors:[...o.customErrors&&Array.isArray(o.customErrors)?o.customErrors:[],...e]}}return{}};class F extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,F)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class j extends F{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class T extends F{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class x extends F{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class w extends F{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const N=({category:e,connectorKey:t,connectorVersion:o,authConfigKey:r,environment:n="production",operation:s,accountSecureId:i,projectSecureId:a})=>({projectSecureId:a,accountSecureId:i,connectorKey:t,connectorVersion:o,category:e,service:"",resource:"",schema:s?.schema?.key,operationType:s?.operationType??"unknown",authenticationType:r,environment:n}),R=e=>{const t=e.operation?.compositeIdentifiers,n={...e.inputs??{}};if(!t?.enabled||r.isMissing(n))return e;const s=t.fields?.reduce(((e,t)=>(t.components.forEach((t=>{t.alias&&(e[t.name]=t.alias)})),e)),{}),i={version:t.version??o.COMPOSITE_ID_LATEST_VERSION,aliases:s};return A(n,i,e.logger),{...e,inputs:n}},A=(e,t,o)=>{for(const r in e){const n=e[r];if("string"==typeof n||Array.isArray(n)&&n.every((e=>"string"==typeof e)))q(n,r,e,t,o);else if(Array.isArray(n))for(const e of n)A(e,t,o);else"object"==typeof n&&null!==n&&A(n,t,o)}},M=e=>{const t=Object.values(e);return 1===t.length&&("string"==typeof t[0]||"number"==typeof t[0])},q=(e,t,r,n,s)=>{try{const i=Array.isArray(e),a=i?e:[e];if(0===a.length)return;const{compositeIdComponents:c,nonCompositeIds:u}=((e,t,r,n)=>{const s=[],i=[];for(const a of e)try{const e=o.decodeCompositeId(a,r);s.push(e)}catch(e){n?.debug({message:`Received ${t} with invalid composite ID, assuming it is not a composite ID`,category:"processCompositeId",context:{key:t,inputElement:a,compositeIdentifierConfig:r,error:e}}),i.push(a)}return{compositeIdComponents:s,nonCompositeIds:i}})(a,t,n,s);((e,t,o,r)=>{const n=o.filter((e=>Object.keys(e).length>1));n.length>0&&(e.decoded_ids={...e.decoded_ids??{},[t]:r?n:n[0]})})(r,t,c,i),((e,t,o,r,n)=>{o.every(M)&&(n?e[t]=[...o.map((e=>Object.values(e)[0])),...r]:o.length>0&&(e[t]=Object.values(o[0])[0]))})(r,t,c,u,i)}catch(e){((e,t,r)=>{e instanceof o.CoreError&&"COMPOSITE_ID_MISSING_HEADER_ERROR"===e.type?r?.debug({message:`Received ${t} with no composite ID header, assuming it is not a composite ID`}):r?.warning({message:`Error processing composite ID for ${t}, ignoring it`,error:e})})(e,t,s)}},P="remote_",$=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",n=e.outputs?.[o];if(r.isMissing(n))return e;const s=Array.isArray(n)?n.map((e=>K(e,t))):K(n,t);return{...e,outputs:{...e.outputs??{},[o]:s}}},K=(e,t)=>{const o=D(e,t),n=G(o);return{...e,...r.isObject(n)?n:{}}},D=(e,t)=>{const r=t.version??o.COMPOSITE_ID_LATEST_VERSION,n={};return t.fields?.forEach((t=>{const s={},i=[];t.components.forEach((t=>{t.alias&&(s[t.name]=t.alias),i.push({key:t.name,value:e[t.name]})}));const a=1===i.length?i[0]:{identifiers:i},c={version:r,aliases:Object.keys(s).length>0?s:void 0},u=o.encodeCompositeId(a,c);n[t.targetFieldKey]=u,t.remote&&(n[`${P}${t.remote}`]=e[t.remote])})),{...e,...n}},U=e=>"id"===e||/.+_id(s)?$/.test(e),L=(e,t,n)=>{const s=t.map((t=>r.isString(t)&&t.length>0&&!o.isCompositeId(t)?((e,t)=>{try{return o.encodeCompositeId({key:e,value:t},{version:o.COMPOSITE_ID_LATEST_VERSION})}catch{return t}})(e,t):t));n[e]=s,n[`${P}${e}`]=t},H=(e,t,r)=>{if(((e,t)=>o.isCompositeId(e)||t.startsWith(P))(t,e))return;const n=o.encodeCompositeId({key:e,value:t},{version:o.COMPOSITE_ID_LATEST_VERSION});r[e]=n,r[`remote_${e}`]=t},V=(e,t,o)=>{(e=>Array.isArray(e)&&e.every((e=>r.isString(e)&&e.length>0)))(t)?L(e,t,o):r.isString(t)&&t.length>0&&H(e,t,o)},G=e=>{if(Array.isArray(e))return e.map((e=>G(e)));if(!r.isObject(e))return e;const t={...e};for(const[o,n]of Object.entries(e))(r.isObject(n)||Array.isArray(n)&&n.length>0&&r.isObject(n[0]))&&(t[o]=G(n)),U(o)&&V(o,n,t);return t},J=(e,t,n,s)=>{const i=r.isMissing(e)?void 0:e.data,a=Object.keys(n).length+1,c=o.isCursorEmpty({cursor:s,ignoreStepIndex:a});if(!r.isObject(e)||r.isMissing(i)||(i?.length??0)<=t)return{result:e,next:r.notMissing(s)&&!c?o.minifyCursor(s):null};const u=s?.remote?.[a]?.pageNumber??1,p=(u-1)*t,d=p+t,l=i.slice(p,d),y=i.length>d||!c,g=o.updateCursor({cursor:s,stepIndex:a,pageNumber:u+1});return{result:{...e,data:l},next:y?o.minifyCursor(g):null}},W=async({block:e,buildStepFunction:t=o.StepFunctionsFactory.build,virtualPaginateResultFn:r=J,encodeResultCompositeIds:n=$,decodeInputCompositeIds:s=R})=>{const i=s(e);return n(await Y({block:i,buildStepFunction:t,virtualPaginateResultFn:r}))},B=async(e,t,r,n,s,a)=>{const c=r[e],u=c.stepFunction,p=a.buildStepFunction({functionName:u.functionName,version:u.version,validateSchemas:!0}).fn;if(((e,t)=>!!e.condition&&!i.safeEvaluate(e.condition,t))(c,n))return X({block:n,stepId:e,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});if(s.hasFatalError)return X({block:n,stepId:e,successful:!1,skipped:!0,message:"Step skipped due to previous error."});const d=((e,t,o)=>{const r=e.stepFunction;return t.operation?.cursor.enabled?{...r.params??{},cursor:{token:t.nextCursor?.remote?.[o]?.providerPageCursor,position:t.nextCursor?.remote?.[o]?.position}}:r.params??{}})(c,n,t),l=await p({block:n,params:d});if(!1===l.successful)return((e,t,o,r,n)=>{const s=X({block:e,stepId:t,successful:!1,functionOutput:o});return(r.ignoreError??!1)||(n.hasFatalError=!0,n.errorStatusCode??=o.output?.statusCode??500),s})(n,e,l,c,s);const y=n.operation?.cursor.enabled?o.updateCursor({cursor:n.nextCursor,stepIndex:t,providerPageCursor:l.output?.next,position:l.output?.position}):void 0;return X({block:{...l.block,nextCursor:y},stepId:e,functionOutput:l})},Y=async({block:t,buildStepFunction:n=o.StepFunctionsFactory.build,virtualPaginateResultFn:s=J})=>{const i=t.operation?.steps||{};let a={...t};const c=Object.keys(i),u=((e,t)=>{const o=Number(e.inputs?.page_size);return r.notMissing(e.inputs?.page_size)&&r.isNumber(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(t,25),p={hasFatalError:!1,errorStatusCode:null},d={block:t,buildStepFunction:n,virtualPaginateResultFn:s};for(const[e,t]of c.entries())a=await B(t,e,i,a,p,d);const l=t.operation?.result?Q(t.operation.result,a):void 0;return((t,o,n,s,i)=>{const a=!n.hasFatalError,c=a?t.operation?.responses.success.statusCode??200:n.errorStatusCode??500;return{...o,outputs:r.notMissing(i)&&r.isObject(i.result)?{next:i.next,...i.result}:s,response:{successful:a,statusCode:c,message:a?void 0:t.operation?.responses?.errors?.[c]?.description??e.HttpErrorMessages?.[c]??"Error while processing the request"}}})(t,a,p,l,t.operation?.cursor.enabled?s(l,u,i,a.nextCursor):void 0)},Q=(e,t)=>r.isObject(e)?i.safeEvaluateRecord(e,t):i.safeEvaluate(e,t),X=({block:e,stepId:t,successful:o,functionOutput:r,skipped:n,message:s})=>({...e,steps:{...e.steps,[t]:{successful:o??r?.successful??!1,errors:r?.errors,output:r?.output,skipped:n,message:s}}}),Z=(e,t)=>{const n=e?.next,s=r.notMissing(n)&&"list"===t.operationType?o.expandCursor(n):void 0;if(null===s)throw new w(t,"Invalid cursor.");return s};exports.ConnectSDKError=F,exports.createBlock=a,exports.executeStepFunction=async({block:e,stepFunctionName:t,params:r,buildStepFunction:n=o.StepFunctionsFactory.build})=>{const s=n({functionName:t}).fn,i=await s({block:e,params:r}),a=t===o.StepFunctionName.MAP_FIELDS?{[o.StepFunctionName.MAP_FIELDS.toString()]:{output:{data:i.block.result},errors:i.errors,successful:i.successful}}:{};return{...i.block,steps:{...i?.block?.steps??{},...a}}},exports.getOperationFromUrl=c,exports.parseOperationInputs=I,exports.parseYamlConnector=b,exports.runConnectorOperation=async({account:e,connector:t,category:o,path:n,method:s="get",queryParams:i,body:u,headers:p,logger:d,parseConnector:l=b,getOperationFromUrlFn:y=c,parseOperationInputsFn:g=I,createBlockContextFn:m=N,createBlockFn:f=a,runStepOperationFn:h=W})=>{const z=e.authConfigKey,_=e.environment??"production",C=e.secureId,v=e.projectSecureId,S=e.credentials,E=m({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:z,environment:_,accountSecureId:C,projectSecureId:v});let O;try{O=r.isString(t)?l(t):t}catch{throw new j(E,"Error while parsing connector")}const k=y(O,n,s);if(r.isMissing(k))throw new T(E,"No matching operation found");E.operationType=k.operation.operationType,E.schema=k.operation.schema?.key;const F=Z(i,E);let w;try{w=g(k.operation,{query:i,body:u,headers:p,path:k.params})}catch{throw new x(E,"Error while parsing operation inputs")}const R=await f({inputs:w,context:E,operation:k.operation,credentials:S,nextCursor:F,logger:d});return await h({block:R})},exports.runStepOperation=W;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Block, BlockContext, Cursor,
|
|
1
|
+
import { Block, BlockContext, Cursor, Operation } from '@stackone/core';
|
|
2
|
+
import { ILogger } from '@stackone/logger';
|
|
2
3
|
import { IHttpClient } from '@stackone/transport';
|
|
3
4
|
export declare const createBlock: ({ inputs, context, operation, credentials, nextCursor, logger, getHttpClient, }: {
|
|
4
5
|
inputs?: Record<string, unknown>;
|
|
@@ -79,6 +79,68 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
79
79
|
remote?: string | undefined;
|
|
80
80
|
}[] | undefined;
|
|
81
81
|
}>>;
|
|
82
|
+
scheduledJobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
83
|
+
enabled: z.ZodBoolean;
|
|
84
|
+
type: z.ZodEnum<["data_sync"]>;
|
|
85
|
+
schedule: z.ZodString;
|
|
86
|
+
description: z.ZodString;
|
|
87
|
+
requestParams: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
89
|
+
expand: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
90
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
filter?: Record<string, string> | undefined;
|
|
93
|
+
fields?: string[] | undefined;
|
|
94
|
+
expand?: string[] | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
filter?: Record<string, string> | undefined;
|
|
97
|
+
fields?: string[] | undefined;
|
|
98
|
+
expand?: string[] | undefined;
|
|
99
|
+
}>>;
|
|
100
|
+
syncFilter: z.ZodOptional<z.ZodObject<{
|
|
101
|
+
name: z.ZodEnum<["updated_after", "created_after"]>;
|
|
102
|
+
initialLoopbackPeriod: z.ZodString;
|
|
103
|
+
incrementalLoopbackPeriod: z.ZodString;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
name: "updated_after" | "created_after";
|
|
106
|
+
initialLoopbackPeriod: string;
|
|
107
|
+
incrementalLoopbackPeriod: string;
|
|
108
|
+
}, {
|
|
109
|
+
name: "updated_after" | "created_after";
|
|
110
|
+
initialLoopbackPeriod: string;
|
|
111
|
+
incrementalLoopbackPeriod: string;
|
|
112
|
+
}>>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
type: "data_sync";
|
|
115
|
+
description: string;
|
|
116
|
+
enabled: boolean;
|
|
117
|
+
schedule: string;
|
|
118
|
+
requestParams?: {
|
|
119
|
+
filter?: Record<string, string> | undefined;
|
|
120
|
+
fields?: string[] | undefined;
|
|
121
|
+
expand?: string[] | undefined;
|
|
122
|
+
} | undefined;
|
|
123
|
+
syncFilter?: {
|
|
124
|
+
name: "updated_after" | "created_after";
|
|
125
|
+
initialLoopbackPeriod: string;
|
|
126
|
+
incrementalLoopbackPeriod: string;
|
|
127
|
+
} | undefined;
|
|
128
|
+
}, {
|
|
129
|
+
type: "data_sync";
|
|
130
|
+
description: string;
|
|
131
|
+
enabled: boolean;
|
|
132
|
+
schedule: string;
|
|
133
|
+
requestParams?: {
|
|
134
|
+
filter?: Record<string, string> | undefined;
|
|
135
|
+
fields?: string[] | undefined;
|
|
136
|
+
expand?: string[] | undefined;
|
|
137
|
+
} | undefined;
|
|
138
|
+
syncFilter?: {
|
|
139
|
+
name: "updated_after" | "created_after";
|
|
140
|
+
initialLoopbackPeriod: string;
|
|
141
|
+
incrementalLoopbackPeriod: string;
|
|
142
|
+
} | undefined;
|
|
143
|
+
}>, "many">>;
|
|
82
144
|
fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
83
145
|
targetFieldKey: z.ZodString;
|
|
84
146
|
alias: z.ZodOptional<z.ZodString>;
|
|
@@ -218,6 +280,22 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
218
280
|
remote?: string | undefined;
|
|
219
281
|
}[] | undefined;
|
|
220
282
|
} | undefined;
|
|
283
|
+
scheduledJobs?: {
|
|
284
|
+
type: "data_sync";
|
|
285
|
+
description: string;
|
|
286
|
+
enabled: boolean;
|
|
287
|
+
schedule: string;
|
|
288
|
+
requestParams?: {
|
|
289
|
+
filter?: Record<string, string> | undefined;
|
|
290
|
+
fields?: string[] | undefined;
|
|
291
|
+
expand?: string[] | undefined;
|
|
292
|
+
} | undefined;
|
|
293
|
+
syncFilter?: {
|
|
294
|
+
name: "updated_after" | "created_after";
|
|
295
|
+
initialLoopbackPeriod: string;
|
|
296
|
+
incrementalLoopbackPeriod: string;
|
|
297
|
+
} | undefined;
|
|
298
|
+
}[] | undefined;
|
|
221
299
|
fieldConfigs?: {
|
|
222
300
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
223
301
|
custom: boolean;
|
|
@@ -276,6 +354,22 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
276
354
|
remote?: string | undefined;
|
|
277
355
|
}[] | undefined;
|
|
278
356
|
} | undefined;
|
|
357
|
+
scheduledJobs?: {
|
|
358
|
+
type: "data_sync";
|
|
359
|
+
description: string;
|
|
360
|
+
enabled: boolean;
|
|
361
|
+
schedule: string;
|
|
362
|
+
requestParams?: {
|
|
363
|
+
filter?: Record<string, string> | undefined;
|
|
364
|
+
fields?: string[] | undefined;
|
|
365
|
+
expand?: string[] | undefined;
|
|
366
|
+
} | undefined;
|
|
367
|
+
syncFilter?: {
|
|
368
|
+
name: "updated_after" | "created_after";
|
|
369
|
+
initialLoopbackPeriod: string;
|
|
370
|
+
incrementalLoopbackPeriod: string;
|
|
371
|
+
} | undefined;
|
|
372
|
+
}[] | undefined;
|
|
279
373
|
fieldConfigs?: {
|
|
280
374
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
281
375
|
targetFieldKey: string;
|
|
@@ -741,6 +835,68 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
741
835
|
remote?: string | undefined;
|
|
742
836
|
}[] | undefined;
|
|
743
837
|
}>>;
|
|
838
|
+
scheduledJobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
839
|
+
enabled: z.ZodBoolean;
|
|
840
|
+
type: z.ZodEnum<["data_sync"]>;
|
|
841
|
+
schedule: z.ZodString;
|
|
842
|
+
description: z.ZodString;
|
|
843
|
+
requestParams: z.ZodOptional<z.ZodObject<{
|
|
844
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
845
|
+
expand: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
846
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
847
|
+
}, "strip", z.ZodTypeAny, {
|
|
848
|
+
filter?: Record<string, string> | undefined;
|
|
849
|
+
fields?: string[] | undefined;
|
|
850
|
+
expand?: string[] | undefined;
|
|
851
|
+
}, {
|
|
852
|
+
filter?: Record<string, string> | undefined;
|
|
853
|
+
fields?: string[] | undefined;
|
|
854
|
+
expand?: string[] | undefined;
|
|
855
|
+
}>>;
|
|
856
|
+
syncFilter: z.ZodOptional<z.ZodObject<{
|
|
857
|
+
name: z.ZodEnum<["updated_after", "created_after"]>;
|
|
858
|
+
initialLoopbackPeriod: z.ZodString;
|
|
859
|
+
incrementalLoopbackPeriod: z.ZodString;
|
|
860
|
+
}, "strip", z.ZodTypeAny, {
|
|
861
|
+
name: "updated_after" | "created_after";
|
|
862
|
+
initialLoopbackPeriod: string;
|
|
863
|
+
incrementalLoopbackPeriod: string;
|
|
864
|
+
}, {
|
|
865
|
+
name: "updated_after" | "created_after";
|
|
866
|
+
initialLoopbackPeriod: string;
|
|
867
|
+
incrementalLoopbackPeriod: string;
|
|
868
|
+
}>>;
|
|
869
|
+
}, "strip", z.ZodTypeAny, {
|
|
870
|
+
type: "data_sync";
|
|
871
|
+
description: string;
|
|
872
|
+
enabled: boolean;
|
|
873
|
+
schedule: string;
|
|
874
|
+
requestParams?: {
|
|
875
|
+
filter?: Record<string, string> | undefined;
|
|
876
|
+
fields?: string[] | undefined;
|
|
877
|
+
expand?: string[] | undefined;
|
|
878
|
+
} | undefined;
|
|
879
|
+
syncFilter?: {
|
|
880
|
+
name: "updated_after" | "created_after";
|
|
881
|
+
initialLoopbackPeriod: string;
|
|
882
|
+
incrementalLoopbackPeriod: string;
|
|
883
|
+
} | undefined;
|
|
884
|
+
}, {
|
|
885
|
+
type: "data_sync";
|
|
886
|
+
description: string;
|
|
887
|
+
enabled: boolean;
|
|
888
|
+
schedule: string;
|
|
889
|
+
requestParams?: {
|
|
890
|
+
filter?: Record<string, string> | undefined;
|
|
891
|
+
fields?: string[] | undefined;
|
|
892
|
+
expand?: string[] | undefined;
|
|
893
|
+
} | undefined;
|
|
894
|
+
syncFilter?: {
|
|
895
|
+
name: "updated_after" | "created_after";
|
|
896
|
+
initialLoopbackPeriod: string;
|
|
897
|
+
incrementalLoopbackPeriod: string;
|
|
898
|
+
} | undefined;
|
|
899
|
+
}>, "many">>;
|
|
744
900
|
fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
745
901
|
targetFieldKey: z.ZodString;
|
|
746
902
|
alias: z.ZodOptional<z.ZodString>;
|
|
@@ -880,6 +1036,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
880
1036
|
remote?: string | undefined;
|
|
881
1037
|
}[] | undefined;
|
|
882
1038
|
} | undefined;
|
|
1039
|
+
scheduledJobs?: {
|
|
1040
|
+
type: "data_sync";
|
|
1041
|
+
description: string;
|
|
1042
|
+
enabled: boolean;
|
|
1043
|
+
schedule: string;
|
|
1044
|
+
requestParams?: {
|
|
1045
|
+
filter?: Record<string, string> | undefined;
|
|
1046
|
+
fields?: string[] | undefined;
|
|
1047
|
+
expand?: string[] | undefined;
|
|
1048
|
+
} | undefined;
|
|
1049
|
+
syncFilter?: {
|
|
1050
|
+
name: "updated_after" | "created_after";
|
|
1051
|
+
initialLoopbackPeriod: string;
|
|
1052
|
+
incrementalLoopbackPeriod: string;
|
|
1053
|
+
} | undefined;
|
|
1054
|
+
}[] | undefined;
|
|
883
1055
|
fieldConfigs?: {
|
|
884
1056
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
885
1057
|
custom: boolean;
|
|
@@ -938,6 +1110,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
938
1110
|
remote?: string | undefined;
|
|
939
1111
|
}[] | undefined;
|
|
940
1112
|
} | undefined;
|
|
1113
|
+
scheduledJobs?: {
|
|
1114
|
+
type: "data_sync";
|
|
1115
|
+
description: string;
|
|
1116
|
+
enabled: boolean;
|
|
1117
|
+
schedule: string;
|
|
1118
|
+
requestParams?: {
|
|
1119
|
+
filter?: Record<string, string> | undefined;
|
|
1120
|
+
fields?: string[] | undefined;
|
|
1121
|
+
expand?: string[] | undefined;
|
|
1122
|
+
} | undefined;
|
|
1123
|
+
syncFilter?: {
|
|
1124
|
+
name: "updated_after" | "created_after";
|
|
1125
|
+
initialLoopbackPeriod: string;
|
|
1126
|
+
incrementalLoopbackPeriod: string;
|
|
1127
|
+
} | undefined;
|
|
1128
|
+
}[] | undefined;
|
|
941
1129
|
fieldConfigs?: {
|
|
942
1130
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
943
1131
|
targetFieldKey: string;
|
|
@@ -1078,6 +1266,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
1078
1266
|
remote?: string | undefined;
|
|
1079
1267
|
}[] | undefined;
|
|
1080
1268
|
} | undefined;
|
|
1269
|
+
scheduledJobs?: {
|
|
1270
|
+
type: "data_sync";
|
|
1271
|
+
description: string;
|
|
1272
|
+
enabled: boolean;
|
|
1273
|
+
schedule: string;
|
|
1274
|
+
requestParams?: {
|
|
1275
|
+
filter?: Record<string, string> | undefined;
|
|
1276
|
+
fields?: string[] | undefined;
|
|
1277
|
+
expand?: string[] | undefined;
|
|
1278
|
+
} | undefined;
|
|
1279
|
+
syncFilter?: {
|
|
1280
|
+
name: "updated_after" | "created_after";
|
|
1281
|
+
initialLoopbackPeriod: string;
|
|
1282
|
+
incrementalLoopbackPeriod: string;
|
|
1283
|
+
} | undefined;
|
|
1284
|
+
}[] | undefined;
|
|
1081
1285
|
fieldConfigs?: {
|
|
1082
1286
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
1083
1287
|
custom: boolean;
|
|
@@ -1218,6 +1422,22 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
1218
1422
|
remote?: string | undefined;
|
|
1219
1423
|
}[] | undefined;
|
|
1220
1424
|
} | undefined;
|
|
1425
|
+
scheduledJobs?: {
|
|
1426
|
+
type: "data_sync";
|
|
1427
|
+
description: string;
|
|
1428
|
+
enabled: boolean;
|
|
1429
|
+
schedule: string;
|
|
1430
|
+
requestParams?: {
|
|
1431
|
+
filter?: Record<string, string> | undefined;
|
|
1432
|
+
fields?: string[] | undefined;
|
|
1433
|
+
expand?: string[] | undefined;
|
|
1434
|
+
} | undefined;
|
|
1435
|
+
syncFilter?: {
|
|
1436
|
+
name: "updated_after" | "created_after";
|
|
1437
|
+
initialLoopbackPeriod: string;
|
|
1438
|
+
incrementalLoopbackPeriod: string;
|
|
1439
|
+
} | undefined;
|
|
1440
|
+
}[] | undefined;
|
|
1221
1441
|
fieldConfigs?: {
|
|
1222
1442
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
1223
1443
|
targetFieldKey: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { executeStepFunction } from './runners/executeStepFunctions';
|
|
2
|
-
export { runStepOperation } from './runners/runStepOperation';
|
|
3
|
-
export { runConnectorOperation } from './runners/runConnectorOperation';
|
|
4
|
-
export { parseYamlConnector, parseOperationInputs } from './connectors/parsers';
|
|
5
1
|
export { createBlock } from './blocks/createBlock';
|
|
6
2
|
export { getOperationFromUrl } from './connectors/operations';
|
|
3
|
+
export { parseOperationInputs, parseYamlConnector } from './connectors/parsers';
|
|
7
4
|
export { ConnectSDKError } from './errors/connectSDKErrors';
|
|
8
5
|
export { ErrorType } from './errors/types';
|
|
6
|
+
export { executeStepFunction } from './runners/executeStepFunctions';
|
|
7
|
+
export { runConnectorOperation } from './runners/runConnectorOperation';
|
|
8
|
+
export { runStepOperation } from './runners/runStepOperation';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Account, Block, Category, Connector
|
|
1
|
+
import { Account, Block, Category, Connector } from '@stackone/core';
|
|
2
|
+
import { ILogger } from '@stackone/logger';
|
|
2
3
|
import { HttpMethod } from '@stackone/transport';
|
|
3
4
|
import { createBlock } from '../blocks/createBlock';
|
|
4
5
|
import { createBlockContext } from '../blocks/createBlockContext';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/connect-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.mjs",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@stackone/core": "*",
|
|
36
36
|
"@stackone/expressions": "*",
|
|
37
|
+
"@stackone/logger": "*",
|
|
37
38
|
"@stackone/open-api": "*",
|
|
38
39
|
"@stackone/transport": "*",
|
|
39
40
|
"@stackone/utils": "*",
|
|
40
41
|
"path-to-regexp": "8.2.0",
|
|
41
42
|
"yaml": "2.7.1"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|