@stackone/connect-sdk 1.26.0 → 1.28.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,isCursorEmpty as o,minifyCursor as r,updateCursor as n,AUTHENTICATION_SCHEMA as s,COMPOSITE_ID_LATEST_VERSION as i,expandCursor as a}from"@stackone/core";import{safeEvaluate as c,safeEvaluateRecord as p}from"@stackone/expressions";import{notMissing as u,isNumber as d,isMissing as l,isObject as y,isString as g}from"@stackone/utils";import{HttpClientManager as m,isSuccessStatusCode as b}from"@stackone/transport";import{match as f}from"path-to-regexp";import{parse as h}from"yaml";import{z as _}from"zod";const v=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}}},k=(e,t,s,i)=>{const a=l(e)?void 0:e.data,c=Object.keys(s).length+1,p=o({cursor:i,ignoreStepIndex:c});if(!y(e)||l(a)||(a?.length??0)<=t)return{result:e,next:u(i)&&!p?r(i):null};const d=i?.remote?.[c]?.pageNumber??1,g=(d-1)*t,m=g+t,b=a.slice(g,m),f=a.length>m||!p,h=n({cursor:i,stepIndex:c,pageNumber:d+1});return{result:{...e,data:b},next:f?r(h):null}},C=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=k})=>await I({block:t,buildStepFunction:o,virtualPaginateResultFn:r}),I=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=k})=>{const s=t.operation?.steps||{};let i={...t};const a=Object.keys(s),p=((e,t)=>{const o=Number(e.inputs?.page_size);return u(e.inputs?.page_size)&&d(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(t,25);let l=!1,g=null;for(const[e,t]of a.entries()){const r=s[t],a=r.stepFunction,p=o({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(r.condition&&!c(r.condition,i)){i=x({block:i,stepId:t,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(l){i=x({block:i,stepId:t,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=i.operation?.cursor.enabled?{...a.params,cursor:{token:i.nextCursor?.remote?.[e]?.providerPageCursor,position:i.nextCursor?.remote?.[e]?.position}}:a.params,d=await p({block:i,params:u});if(!1===d.successful){i=x({block:i,stepId:t,successful:!1,functionOutput:d});(r.ignoreError??!1)||(l=!0,g??=d.output?.statusCode??500)}else{const o=i.operation?.cursor.enabled?n({cursor:i.nextCursor,stepIndex:e,providerPageCursor:d.output?.next,position:d.output?.position}):void 0;i=x({block:{...d.block,nextCursor:o},stepId:t,functionOutput:d})}}const m=t.operation?.result?w(t.operation.result,i):void 0,b=t.operation?.cursor.enabled?r(m,p,s,i.nextCursor):void 0,f=!l,h=f?t.operation?.responses.success.statusCode??200:g??500,_=u(b)&&y(b.result)?{next:b.next,...b.result}:m;return{...i,outputs:_,response:{successful:f,statusCode:h,message:f?void 0:t.operation?.responses?.errors?.[h]?.description??"Error while processing the request"}}},w=(e,t)=>y(e)?p(e,t):c(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}}}),F=async({inputs:e,context:t,operation:o,credentials:r,nextCursor:n,logger:s,getHttpClient:i=async()=>m.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,nextCursor:n,httpClient:await i(),logger:s}),S=({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}),j=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=O(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},E=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},O=(e,t,o)=>{const r=E(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),n=f(E(o))(E(r));if(!1!==n)return{path:e,params:n.params}}},T=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}`)}},N={key:_.string(),label:_.string(),required:_.boolean().optional().default(!1),secret:_.boolean().optional().default(!1),readOnly:_.boolean().optional().default(!1),placeholder:_.string().optional(),description:_.string().optional(),tooltip:_.string().optional()},R=_.discriminatedUnion("type",[_.object({...N,type:_.enum(["text","password"])}),_.object({...N,type:_.literal("select"),options:_.object({value:_.string(),label:_.string()}).array()})]),U=_.object({operationId:_.string(),categories:_.string().array(),operationType:_.enum(["list","get","create","update","delete","custom","unknown"]),schema:_.string().optional(),entrypointUrl:_.string().optional(),entrypointHttpMethod:_.string().optional(),description:_.string(),responses:_.object({statusCode:_.number(),description:_.string()}).array().optional(),inputs:_.object({name:_.string(),type:_.string(),required:_.boolean(),description:_.string(),in:_.string()}).array().optional(),cursor:_.object({enabled:_.boolean(),pageSize:_.number()}).optional(),compositeIdentifiers:_.object({enabled:_.boolean(),version:_.number().optional(),fields:_.object({targetFieldKey:_.string(),remote:_.string().optional(),components:_.object({name:_.string(),expression:_.string(),alias:_.string().optional()}).array()}).array().optional()}).optional(),fieldConfigs:_.object({targetFieldKey:_.string(),expression:_.string(),type:_.enum(["string","number","boolean","datetime_string","enum"]),isUnified:_.boolean(),enumMapper:_.object({matcher:_.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(_.object({matchExpression:_.string(),value:_.string()}).array())}).optional()}).array().optional(),steps:_.object({stepId:_.string(),description:_.string(),stepFunction:_.object({functionName:_.string(),version:_.string().optional(),parameters:_.record(_.string(),_.unknown())}),condition:_.string().optional(),ignoreError:_.boolean().optional()}).array(),result:_.string().or(_.record(_.string(),_.unknown())).optional()}),q=_.object({StackOne:_.string(),info:_.object({title:_.string(),version:_.string(),key:_.string(),description:_.string().optional()}),baseUrl:_.string(),authentication:_.record(_.string(),_.object({type:_.string(),label:_.string(),authorization:s,environments:_.object({key:_.string(),name:_.string()}).array(),support:_.object({link:_.string(),description:_.string().optional()}),configFields:R.array().optional(),setupFields:R.array().optional(),testOperationsIds:_.string().array().optional()})).array().optional(),operations:U.array().optional()});function K(e){try{const t=h(e),o=q.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=$(o),s={baseUrl:o.baseUrl,authentication:P(n)},i=M(o,s);return r.operations=i,r.authentication=n,u(i)&&(r.categories=z(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const P=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]=P(a)}else t[o]=r;return t},z=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},$=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},M=(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:T(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)=>(b(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=V(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:D(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:{..."request"===r.stepFunction.functionName||"paginated_request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},A=(e,t)=>{if(!e.inputs)return{};const o=L(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},H=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=_.string();break;case"number":o=_.number();break;case"boolean":o=_.boolean();break;default:o=_.any()}t[e.name]=e.required?o:o.optional()})),_.object(t)},L=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 _.object({path:H(t).optional(),query:H(o).optional(),body:H(r).optional(),headers:H(n).optional()})},V=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},D=e=>{if(l(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),o=u(t)?[{targetFieldKey:t.targetFieldKey,remote:"id",components:[{name:t.targetFieldKey,expression:t.expression}]}]:void 0;return{enabled:!0,version:i,fields:o}}return{enabled:e.compositeIdentifiers.enabled,version:e.compositeIdentifiers.version,fields:e.compositeIdentifiers.fields}};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 W extends G{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class B extends G{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class Y extends G{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class J extends G{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const Q=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:p=K,getOperationFromUrlFn:u=j,parseOperationInputsFn:d=A,createBlockContextFn:y=S,createBlockFn:m=F,runStepOperationFn:b=C})=>{const f=e.authConfigKey,h=e.environment??"production",_=e.secureId,v=e.projectSecureId,k=e.credentials,I=y({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:f,environment:h,accountSecureId:_,projectSecureId:v});let w;try{w=g(t)?p(t):t}catch{throw new W(I,"Error while parsing connector")}const x=u(w,r,n);if(l(x))throw new B(I,"No matching operation found");I.operationType=x.operation.operationType,I.schema=x.operation.schema?.key;const E=X(s,I);let O;try{O=d(x.operation,{query:s,body:i,headers:a,path:x.params})}catch{throw new Y(I,"Error while parsing operation inputs")}const T=await m({inputs:O,context:I,operation:x.operation,credentials:k,nextCursor:E,logger:c});return await b({block:T})},X=(e,t)=>{const o=e?.next,r=u(o)&&"list"===t.operationType?a(o):void 0;if(null===r)throw new J(t,"Invalid cursor.");return r};export{G as ConnectSDKError,F as createBlock,v as executeStepFunction,j as getOperationFromUrl,A as parseOperationInputs,K as parseYamlConnector,Q as runConnectorOperation,C as runStepOperation};
|
|
1
|
+
import{StepFunctionsFactory as e,StepFunctionName as t,COMPOSITE_ID_LATEST_VERSION as o,encodeCompositeId as r,isCursorEmpty as n,minifyCursor as s,updateCursor as i,AUTHENTICATION_SCHEMA as a,expandCursor as c}from"@stackone/core";import{safeEvaluate as p,safeEvaluateRecord as u}from"@stackone/expressions";import{isMissing as d,notMissing as l,isNumber as y,isObject as m,isString as g}from"@stackone/utils";import{HttpClientManager as b,isSuccessStatusCode as f}from"@stackone/transport";import{match as h}from"path-to-regexp";import{parse as _}from"yaml";import{z as v}from"zod";const k=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}}},C=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const o="data",r=e.outputs?.[o];if(d(r))return e;const n=Array.isArray(r)?r.map((e=>I(e,t))):I(r,t);return{...e,outputs:{...e.outputs??{},[o]:n}}},I=(e,t)=>{const n=t.version??o,s={};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:n,aliases:Object.keys(o).length>0?o:void 0},p=r(a,c);s[t.targetFieldKey]=p,t.remote&&(s[`remote_${t.remote}`]=e[t.remote])})),{...e,...s}},F=(e,t,o,r)=>{const a=d(e)?void 0:e.data,c=Object.keys(o).length+1,p=n({cursor:r,ignoreStepIndex:c});if(!m(e)||d(a)||(a?.length??0)<=t)return{result:e,next:l(r)&&!p?s(r):null};const u=r?.remote?.[c]?.pageNumber??1,y=(u-1)*t,g=y+t,b=a.slice(y,g),f=a.length>g||!p,h=i({cursor:r,stepIndex:c,pageNumber:u+1});return{result:{...e,data:b},next:f?s(h):null}},w=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=F,encodeResultCompositeIds:n=C})=>n(await S({block:t,buildStepFunction:o,virtualPaginateResultFn:r})),S=async({block:t,buildStepFunction:o=e.build,virtualPaginateResultFn:r=F})=>{const n=t.operation?.steps||{};let s={...t};const a=Object.keys(n),c=((e,t)=>{const o=Number(e.inputs?.page_size);return l(e.inputs?.page_size)&&y(o)&&!Number.isNaN(o)?o:e.operation?.cursor?.pageSize??t})(t,25);let u=!1,d=null;for(const[e,t]of a.entries()){const r=n[t],a=r.stepFunction,c=o({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(r.condition&&!p(r.condition,s)){s=E({block:s,stepId:t,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(u){s=E({block:s,stepId:t,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const l=s.operation?.cursor.enabled?{...a.params,cursor:{token:s.nextCursor?.remote?.[e]?.providerPageCursor,position:s.nextCursor?.remote?.[e]?.position}}:a.params,y=await c({block:s,params:l});if(!1===y.successful){s=E({block:s,stepId:t,successful:!1,functionOutput:y});(r.ignoreError??!1)||(u=!0,d??=y.output?.statusCode??500)}else{const o=s.operation?.cursor.enabled?i({cursor:s.nextCursor,stepIndex:e,providerPageCursor:y.output?.next,position:y.output?.position}):void 0;s=E({block:{...y.block,nextCursor:o},stepId:t,functionOutput:y})}}const g=t.operation?.result?x(t.operation.result,s):void 0,b=t.operation?.cursor.enabled?r(g,c,n,s.nextCursor):void 0,f=!u,h=f?t.operation?.responses.success.statusCode??200:d??500,_=l(b)&&m(b.result)?{next:b.next,...b.result}:g;return{...s,outputs:_,response:{successful:f,statusCode:h,message:f?void 0:t.operation?.responses?.errors?.[h]?.description??"Error while processing the request"}}},x=(e,t)=>m(e)?u(e,t):p(e,t),E=({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}}}),j=async({inputs:e,context:t,operation:o,credentials:r,nextCursor:n,logger:s,getHttpClient:i=async()=>b.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:r,nextCursor:n,httpClient:await i(),logger:s}),O=({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}),T=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=R(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},N=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},R=(e,t,o)=>{const r=N(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),n=h(N(o))(N(r));if(!1!==n)return{path:e,params:n.params}}},K=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}`)}},U={key:v.string(),label:v.string(),required:v.boolean().optional().default(!1),secret:v.boolean().optional().default(!1),readOnly:v.boolean().optional().default(!1),placeholder:v.string().optional(),description:v.string().optional(),tooltip:v.string().optional()},q=v.discriminatedUnion("type",[v.object({...U,type:v.enum(["text","password"])}),v.object({...U,type:v.literal("select"),options:v.object({value:v.string(),label:v.string()}).array()})]),P=v.object({operationId:v.string(),categories:v.string().array(),operationType:v.enum(["list","get","create","update","delete","custom","unknown"]),schema:v.string().optional(),entrypointUrl:v.string().optional(),entrypointHttpMethod:v.string().optional(),description:v.string(),responses:v.object({statusCode:v.number(),description:v.string()}).array().optional(),inputs:v.object({name:v.string(),type:v.string(),required:v.boolean(),description:v.string(),in:v.string()}).array().optional(),cursor:v.object({enabled:v.boolean(),pageSize:v.number()}).optional(),compositeIdentifiers:v.object({enabled:v.boolean(),version:v.number().optional(),fields:v.object({targetFieldKey:v.string(),remote:v.string().optional(),components:v.string().array()}).array().optional()}).optional(),fieldConfigs:v.object({targetFieldKey:v.string(),alias:v.string().optional(),expression:v.string(),type:v.enum(["string","number","boolean","datetime_string","enum"]),custom:v.boolean().default(!1),hidden:v.boolean().default(!1),enumMapper:v.object({matcher:v.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(v.object({matchExpression:v.string(),value:v.string()}).array())}).optional()}).array().optional(),steps:v.object({stepId:v.string(),description:v.string(),stepFunction:v.object({functionName:v.string(),version:v.string().optional(),parameters:v.record(v.string(),v.unknown())}),condition:v.string().optional(),ignoreError:v.boolean().optional()}).array(),result:v.string().or(v.record(v.string(),v.unknown())).optional()}),$=v.object({StackOne:v.string(),info:v.object({title:v.string(),version:v.string(),key:v.string(),description:v.string().optional()}),baseUrl:v.string(),authentication:v.record(v.string(),v.object({type:v.string(),label:v.string(),authorization:a,environments:v.object({key:v.string(),name:v.string()}).array(),support:v.object({link:v.string(),description:v.string().optional()}),configFields:q.array().optional(),setupFields:q.array().optional(),testOperationsIds:v.string().array().optional()})).array().optional(),operations:P.array().optional()});function z(e){try{const t=_(e),o=$.parse(t),r={title:o.info.title,version:o.info.version,key:o.info.key,description:o.info.description},n=H(o),s={baseUrl:o.baseUrl,authentication:A(n)},i=L(o,s);return r.operations=i,r.authentication=n,l(i)&&(r.categories=M(Object.values(i))),r}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const A=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(a)}else t[o]=r;return t},M=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},H=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},L=(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:K(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=W(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:B(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:{..."request"===r.stepFunction.functionName||"paginated_request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},V=(e,t)=>{if(!e.inputs)return{};const o=G(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},D=e=>{const t={};return e.forEach((e=>{let o;switch(e.type.toLowerCase()){case"string":o=v.string();break;case"number":o=v.number();break;case"boolean":o=v.boolean();break;default:o=v.any()}t[e.name]=e.required?o:o.optional()})),v.object(t)},G=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 v.object({path:D(t).optional(),query:D(o).optional(),body:D(r).optional(),headers:D(n).optional()})},W=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},B=e=>{if(d(e.compositeIdentifiers)){const t=e.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),r=l(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}};class Y extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,Y)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class J extends Y{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class Q extends Y{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class X extends Y{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class Z extends Y{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const ee=async({account:e,connector:t,category:o,path:r,method:n="get",queryParams:s,body:i,headers:a,logger:c,parseConnector:p=z,getOperationFromUrlFn:u=T,parseOperationInputsFn:l=V,createBlockContextFn:y=O,createBlockFn:m=j,runStepOperationFn:b=w})=>{const f=e.authConfigKey,h=e.environment??"production",_=e.secureId,v=e.projectSecureId,k=e.credentials,C=y({category:o,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:f,environment:h,accountSecureId:_,projectSecureId:v});let I;try{I=g(t)?p(t):t}catch{throw new J(C,"Error while parsing connector")}const F=u(I,r,n);if(d(F))throw new Q(C,"No matching operation found");C.operationType=F.operation.operationType,C.schema=F.operation.schema?.key;const S=te(s,C);let x;try{x=l(F.operation,{query:s,body:i,headers:a,path:F.params})}catch{throw new X(C,"Error while parsing operation inputs")}const E=await m({inputs:x,context:C,operation:F.operation,credentials:k,nextCursor:S,logger:c});return await b({block:E})},te=(e,t)=>{const o=e?.next,r=l(o)&&"list"===t.operationType?c(o):void 0;if(null===r)throw new Z(t,"Invalid cursor.");return r};export{Y as ConnectSDKError,j as createBlock,k as executeStepFunction,T as getOperationFromUrl,V as parseOperationInputs,z as parseYamlConnector,ee as runConnectorOperation,w as runStepOperation};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/utils"),r=require("@stackone/transport"),n=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=(t,r,n,s)=>{const i=o.isMissing(t)?void 0:t.data,a=Object.keys(n).length+1,c=e.isCursorEmpty({cursor:s,ignoreStepIndex:a});if(!o.isObject(t)||o.isMissing(i)||(i?.length??0)<=r)return{result:t,next:o.notMissing(s)&&!c?e.minifyCursor(s):null};const p=s?.remote?.[a]?.pageNumber??1,u=(p-1)*r,d=u+r,l=i.slice(u,d),y=i.length>d||!c,g=e.updateCursor({cursor:s,stepIndex:a,pageNumber:p+1});return{result:{...t,data:l},next:y?e.minifyCursor(g):null}},c=async({block:t,buildStepFunction:o=e.StepFunctionsFactory.build,virtualPaginateResultFn:r=a})=>await p({block:t,buildStepFunction:o,virtualPaginateResultFn:r}),p=async({block:r,buildStepFunction:n=e.StepFunctionsFactory.build,virtualPaginateResultFn:s=a})=>{const i=r.operation?.steps||{};let c={...r};const p=Object.keys(i),l=((e,t)=>{const r=Number(e.inputs?.page_size);return o.notMissing(e.inputs?.page_size)&&o.isNumber(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??t})(r,25);let y=!1,g=null;for(const[o,r]of p.entries()){const s=i[r],a=s.stepFunction,p=n({functionName:a.functionName,version:a.version,validateSchemas:!0}).fn;if(s.condition&&!t.safeEvaluate(s.condition,c)){c=d({block:c,stepId:r,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(y){c=d({block:c,stepId:r,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=c.operation?.cursor.enabled?{...a.params,cursor:{token:c.nextCursor?.remote?.[o]?.providerPageCursor,position:c.nextCursor?.remote?.[o]?.position}}:a.params,l=await p({block:c,params:u});if(!1===l.successful){c=d({block:c,stepId:r,successful:!1,functionOutput:l});(s.ignoreError??!1)||(y=!0,g??=l.output?.statusCode??500)}else{const t=c.operation?.cursor.enabled?e.updateCursor({cursor:c.nextCursor,stepIndex:o,providerPageCursor:l.output?.next,position:l.output?.position}):void 0;c=d({block:{...l.block,nextCursor:t},stepId:r,functionOutput:l})}}const b=r.operation?.result?u(r.operation.result,c):void 0,m=r.operation?.cursor.enabled?s(b,l,i,c.nextCursor):void 0,z=!y,h=z?r.operation?.responses.success.statusCode??200:g??500,f=o.notMissing(m)&&o.isObject(m.result)?{next:m.next,...m.result}:b;return{...c,outputs:f,response:{successful:z,statusCode:h,message:z?void 0:r.operation?.responses?.errors?.[h]?.description??"Error while processing the request"}}},u=(e,r)=>o.isObject(e)?t.safeEvaluateRecord(e,r):t.safeEvaluate(e,r),d=({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}}}),l=async({inputs:e,context:t,operation:o,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>r.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),y=({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}),g=(e,t,o)=>{const r=o.toUpperCase();if(!e.operations)return;const n=Object.keys(e.operations),s=m(t,r,n);return s?{operation:e.operations?.[s.path],params:s.params}:void 0},b=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},m=(e,t,o)=>{const r=b(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=n.match(b(o))(b(r));if(!1!==s)return{path:e,params:s.params}}},z=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}`)}},h={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()},f=i.z.discriminatedUnion("type",[i.z.object({...h,type:i.z.enum(["text","password"])}),i.z.object({...h,type:i.z.literal("select"),options:i.z.object({value:i.z.string(),label:i.z.string()}).array()})]),_=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.object({name:i.z.string(),expression:i.z.string(),alias:i.z.string().optional()}).array()}).array().optional()}).optional(),fieldConfigs:i.z.object({targetFieldKey:i.z.string(),expression:i.z.string(),type:i.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:i.z.boolean(),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()}),C=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:f.array().optional(),setupFields:f.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:_.array().optional()});function v(e){try{const t=s.parse(e),r=C.parse(t),n={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},i=S(r),a={baseUrl:r.baseUrl,authentication:k(i)},c=x(r,a);return n.operations=c,n.authentication=i,o.notMissing(c)&&(n.categories=I(Object.values(c))),n}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const k=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]=k(a)}else t[o]=r;return t},I=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},S=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},x=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),a=(e=>{const t={success:z(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)=>(r.isSuccessStatusCode(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),c=O(o),p=o.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:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:j(o),inputs:p,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:{..."request"===r.stepFunction.functionName||"paginated_request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},F=(e,t)=>{if(!e.inputs)return{};const o=w(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},E=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)},w=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:E(t).optional(),query:E(o).optional(),body:E(r).optional(),headers:E(n).optional()})},O=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},j=t=>{if(o.isMissing(t.compositeIdentifiers)){const r=t.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),n=o.notMissing(r)?[{targetFieldKey:r.targetFieldKey,remote:"id",components:[{name:r.targetFieldKey,expression:r.expression}]}]:void 0;return{enabled:!0,version:e.COMPOSITE_ID_LATEST_VERSION,fields:n}}return{enabled:t.compositeIdentifiers.enabled,version:t.compositeIdentifiers.version,fields:t.compositeIdentifiers.fields}};class T extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,T)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class N extends T{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class M extends T{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class R extends T{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class q extends T{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const U=(t,r)=>{const n=t?.next,s=o.notMissing(n)&&"list"===r.operationType?e.expandCursor(n):void 0;if(null===s)throw new q(r,"Invalid cursor.");return s};exports.ConnectSDKError=T,exports.createBlock=l,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=g,exports.parseOperationInputs=F,exports.parseYamlConnector=v,exports.runConnectorOperation=async({account:e,connector:t,category:r,path:n,method:s="get",queryParams:i,body:a,headers:p,logger:u,parseConnector:d=v,getOperationFromUrlFn:b=g,parseOperationInputsFn:m=F,createBlockContextFn:z=y,createBlockFn:h=l,runStepOperationFn:f=c})=>{const _=e.authConfigKey,C=e.environment??"production",k=e.secureId,I=e.projectSecureId,S=e.credentials,x=z({category:r,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:_,environment:C,accountSecureId:k,projectSecureId:I});let E;try{E=o.isString(t)?d(t):t}catch{throw new N(x,"Error while parsing connector")}const w=b(E,n,s);if(o.isMissing(w))throw new M(x,"No matching operation found");x.operationType=w.operation.operationType,x.schema=w.operation.schema?.key;const O=U(i,x);let j;try{j=m(w.operation,{query:i,body:a,headers:p,path:w.params})}catch{throw new R(x,"Error while parsing operation inputs")}const T=await h({inputs:j,context:x,operation:w.operation,credentials:S,nextCursor:O,logger:u});return await f({block:T})},exports.runStepOperation=c;
|
|
1
|
+
"use strict";var e=require("@stackone/core"),t=require("@stackone/expressions"),o=require("@stackone/utils"),r=require("@stackone/transport"),n=require("path-to-regexp"),s=require("yaml"),i=require("zod");const a=e=>{const t=e.operation?.compositeIdentifiers;if(!t?.enabled)return e;const r="data",n=e.outputs?.[r];if(o.isMissing(n))return e;const s=Array.isArray(n)?n.map((e=>c(e,t))):c(n,t);return{...e,outputs:{...e.outputs??{},[r]:s}}},c=(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},p=e.encodeCompositeId(a,c);n[o.targetFieldKey]=p,o.remote&&(n[`remote_${o.remote}`]=t[o.remote])})),{...t,...n}},p=(t,r,n,s)=>{const i=o.isMissing(t)?void 0:t.data,a=Object.keys(n).length+1,c=e.isCursorEmpty({cursor:s,ignoreStepIndex:a});if(!o.isObject(t)||o.isMissing(i)||(i?.length??0)<=r)return{result:t,next:o.notMissing(s)&&!c?e.minifyCursor(s):null};const p=s?.remote?.[a]?.pageNumber??1,u=(p-1)*r,d=u+r,l=i.slice(u,d),y=i.length>d||!c,g=e.updateCursor({cursor:s,stepIndex:a,pageNumber:p+1});return{result:{...t,data:l},next:y?e.minifyCursor(g):null}},u=async({block:t,buildStepFunction:o=e.StepFunctionsFactory.build,virtualPaginateResultFn:r=p,encodeResultCompositeIds:n=a})=>n(await d({block:t,buildStepFunction:o,virtualPaginateResultFn:r})),d=async({block:r,buildStepFunction:n=e.StepFunctionsFactory.build,virtualPaginateResultFn:s=p})=>{const i=r.operation?.steps||{};let a={...r};const c=Object.keys(i),u=((e,t)=>{const r=Number(e.inputs?.page_size);return o.notMissing(e.inputs?.page_size)&&o.isNumber(r)&&!Number.isNaN(r)?r:e.operation?.cursor?.pageSize??t})(r,25);let d=!1,g=null;for(const[o,r]of c.entries()){const s=i[r],c=s.stepFunction,p=n({functionName:c.functionName,version:c.version,validateSchemas:!0}).fn;if(s.condition&&!t.safeEvaluate(s.condition,a)){a=y({block:a,stepId:r,successful:!0,skipped:!0,message:"Step skipped due to condition not met."});continue}if(d){a=y({block:a,stepId:r,successful:!1,skipped:!0,message:"Step skipped due to previous error."});continue}const u=a.operation?.cursor.enabled?{...c.params,cursor:{token:a.nextCursor?.remote?.[o]?.providerPageCursor,position:a.nextCursor?.remote?.[o]?.position}}:c.params,l=await p({block:a,params:u});if(!1===l.successful){a=y({block:a,stepId:r,successful:!1,functionOutput:l});(s.ignoreError??!1)||(d=!0,g??=l.output?.statusCode??500)}else{const t=a.operation?.cursor.enabled?e.updateCursor({cursor:a.nextCursor,stepIndex:o,providerPageCursor:l.output?.next,position:l.output?.position}):void 0;a=y({block:{...l.block,nextCursor:t},stepId:r,functionOutput:l})}}const m=r.operation?.result?l(r.operation.result,a):void 0,b=r.operation?.cursor.enabled?s(m,u,i,a.nextCursor):void 0,f=!d,h=f?r.operation?.responses.success.statusCode??200:g??500,z=o.notMissing(b)&&o.isObject(b.result)?{next:b.next,...b.result}:m;return{...a,outputs:z,response:{successful:f,statusCode:h,message:f?void 0:r.operation?.responses?.errors?.[h]?.description??"Error while processing the request"}}},l=(e,r)=>o.isObject(e)?t.safeEvaluateRecord(e,r):t.safeEvaluate(e,r),y=({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}}}),g=async({inputs:e,context:t,operation:o,credentials:n,nextCursor:s,logger:i,getHttpClient:a=async()=>r.HttpClientManager.getInstance()})=>({inputs:e,fieldConfigs:[],context:t,operation:o,credentials:n,nextCursor:s,httpClient:await a(),logger:i}),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}),b=(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},f=e=>{const t=e.startsWith("/")?e.slice(1):e;return t.endsWith("/")?t.slice(0,-1):t},h=(e,t,o)=>{const r=f(e);for(const e of o)if(e.startsWith(t)){const o=e.replace(`${t} `,"").trim(),s=n.match(f(o))(f(r));if(!1!==s)return{path:e,params:s.params}}},z=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}`)}},_={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()},C=i.z.discriminatedUnion("type",[i.z.object({..._,type:i.z.enum(["text","password"])}),i.z.object({..._,type:i.z.literal("select"),options:i.z.object({value:i.z.string(),label:i.z.string()}).array()})]),v=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()}),I=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:C.array().optional(),setupFields:C.array().optional(),testOperationsIds:i.z.string().array().optional()})).array().optional(),operations:v.array().optional()});function k(e){try{const t=s.parse(e),r=I.parse(t),n={title:r.info.title,version:r.info.version,key:r.info.key,description:r.info.description},i=E(r),a={baseUrl:r.baseUrl,authentication:S(i)},c=x(r,a);return n.operations=c,n.authentication=i,o.notMissing(c)&&(n.categories=F(Object.values(c))),n}catch(e){throw new Error(`Error parsing YAML file: ${e.message}`)}}const S=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]=S(a)}else t[o]=r;return t},F=e=>{const t=e.reduce(((e,t)=>{for(const o of t.categories)e.add(o);return e}),new Set);return Array.from(t)},E=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},x=(e,t)=>{const o=e.operations?.reduce(((e,o)=>{const n=(e=>e.entrypointUrl&&e.entrypointHttpMethod?`${e.entrypointHttpMethod.toUpperCase()} ${e.entrypointUrl}`:void 0)(o),s=(e=>"list"===e.operationType?`GET /${e.schema}`:`GET /${e.schema}/:id`)(o),i=(e=>"list"===e.operationType?`/${e.schema}`:`/${e.schema}/:id`)(o),a=(e=>{const t={success:z(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)=>(r.isSuccessStatusCode(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),c=j(o),p=o.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:o.operationId,categories:o.categories,description:o.description,operationType:o.operationType,entrypointUrl:o.entrypointUrl??i,entrypointHttpMethod:o.entrypointHttpMethod??"get",responses:a,cursor:c,compositeIdentifiers:N(o),inputs:p,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:{..."request"===r.stepFunction.functionName||"paginated_request"===r.stepFunction.functionName?t:{},..."map_fields"===r.stepFunction.functionName||"typecast"===r.stepFunction.functionName?{fields:o.fieldConfigs}:{},...r.stepFunction.parameters}}},e)),{}),result:o.result},e}),{});return o},O=(e,t)=>{if(!e.inputs)return{};const o=T(e.inputs).parse(t);return{...o.headers??{},...o.query??{},...o.path??{},...o.body??{}}},w=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)},T=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:w(t).optional(),query:w(o).optional(),body:w(r).optional(),headers:w(n).optional()})},j=e=>{const t="list"===e.operationType,o=e.cursor??{enabled:t,pageSize:25};return{enabled:o.enabled&&t,pageSize:o.pageSize}},N=t=>{if(o.isMissing(t.compositeIdentifiers)){const r=t.fieldConfigs?.find((e=>"id"===e.targetFieldKey)),n=o.notMissing(r)?[{targetFieldKey:r.targetFieldKey,remote:"id",components:[{name:r.targetFieldKey,alias:r.alias}]}]:void 0;return{enabled:!0,version:e.COMPOSITE_ID_LATEST_VERSION,fields:n}}const r=[];for(const e of t.compositeIdentifiers?.fields??[]){const o=e.components.map((e=>{const o=t.fieldConfigs?.find((t=>t.targetFieldKey===e));return{name:e,alias:o?.alias}}));r.push({targetFieldKey:e.targetFieldKey,remote:e.remote,components:o})}return{enabled:t.compositeIdentifiers.enabled,version:t.compositeIdentifiers.version,fields:r.length>0?r:void 0}};class M extends Error{constructor(e,t,o){super(o),this.name="ConnectSDKError",this.errorType=e,this.context=t,Error.captureStackTrace&&Error.captureStackTrace(this,M)}toString(){return`${this.name} [${this.errorType}]: ${this.message}`}}class R extends M{constructor(e,t){super("CONNECTOR_PARSE_ERROR",e,t),this.name="ConnectorParseError"}}class q extends M{constructor(e,t){super("MISSING_OPERATION_ERROR",e,t),this.name="MissingOperationError"}}class K extends M{constructor(e,t){super("INVALID_OPERATION_INPUTS_ERROR",e,t),this.name="InvalidOperationInputsError"}}class U extends M{constructor(e,t){super("INVALID_CURSOR_ERROR",e,t),this.name="InvalidCursorError"}}const A=(t,r)=>{const n=t?.next,s=o.notMissing(n)&&"list"===r.operationType?e.expandCursor(n):void 0;if(null===s)throw new U(r,"Invalid cursor.");return s};exports.ConnectSDKError=M,exports.createBlock=g,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=b,exports.parseOperationInputs=O,exports.parseYamlConnector=k,exports.runConnectorOperation=async({account:e,connector:t,category:r,path:n,method:s="get",queryParams:i,body:a,headers:c,logger:p,parseConnector:d=k,getOperationFromUrlFn:l=b,parseOperationInputsFn:y=O,createBlockContextFn:f=m,createBlockFn:h=g,runStepOperationFn:z=u})=>{const _=e.authConfigKey,C=e.environment??"production",v=e.secureId,I=e.projectSecureId,S=e.credentials,F=f({category:r,connectorKey:e.providerKey,connectorVersion:e.providerVersion,authConfigKey:_,environment:C,accountSecureId:v,projectSecureId:I});let E;try{E=o.isString(t)?d(t):t}catch{throw new R(F,"Error while parsing connector")}const x=l(E,n,s);if(o.isMissing(x))throw new q(F,"No matching operation found");F.operationType=x.operation.operationType,F.schema=x.operation.schema?.key;const w=A(i,F);let T;try{T=y(x.operation,{query:i,body:a,headers:c,path:x.params})}catch{throw new K(F,"Error while parsing operation inputs")}const j=await h({inputs:T,context:F,operation:x.operation,credentials:S,nextCursor:w,logger:p});return await z({block:j})},exports.runStepOperation=u;
|
|
@@ -52,34 +52,14 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
52
52
|
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
53
53
|
targetFieldKey: z.ZodString;
|
|
54
54
|
remote: z.ZodOptional<z.ZodString>;
|
|
55
|
-
components: z.ZodArray<z.
|
|
56
|
-
name: z.ZodString;
|
|
57
|
-
expression: z.ZodString;
|
|
58
|
-
alias: z.ZodOptional<z.ZodString>;
|
|
59
|
-
}, "strip", z.ZodTypeAny, {
|
|
60
|
-
name: string;
|
|
61
|
-
expression: string;
|
|
62
|
-
alias?: string | undefined;
|
|
63
|
-
}, {
|
|
64
|
-
name: string;
|
|
65
|
-
expression: string;
|
|
66
|
-
alias?: string | undefined;
|
|
67
|
-
}>, "many">;
|
|
55
|
+
components: z.ZodArray<z.ZodString, "many">;
|
|
68
56
|
}, "strip", z.ZodTypeAny, {
|
|
69
57
|
targetFieldKey: string;
|
|
70
|
-
components:
|
|
71
|
-
name: string;
|
|
72
|
-
expression: string;
|
|
73
|
-
alias?: string | undefined;
|
|
74
|
-
}[];
|
|
58
|
+
components: string[];
|
|
75
59
|
remote?: string | undefined;
|
|
76
60
|
}, {
|
|
77
61
|
targetFieldKey: string;
|
|
78
|
-
components:
|
|
79
|
-
name: string;
|
|
80
|
-
expression: string;
|
|
81
|
-
alias?: string | undefined;
|
|
82
|
-
}[];
|
|
62
|
+
components: string[];
|
|
83
63
|
remote?: string | undefined;
|
|
84
64
|
}>, "many">>;
|
|
85
65
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -87,11 +67,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
87
67
|
version?: number | undefined;
|
|
88
68
|
fields?: {
|
|
89
69
|
targetFieldKey: string;
|
|
90
|
-
components:
|
|
91
|
-
name: string;
|
|
92
|
-
expression: string;
|
|
93
|
-
alias?: string | undefined;
|
|
94
|
-
}[];
|
|
70
|
+
components: string[];
|
|
95
71
|
remote?: string | undefined;
|
|
96
72
|
}[] | undefined;
|
|
97
73
|
}, {
|
|
@@ -99,19 +75,17 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
99
75
|
version?: number | undefined;
|
|
100
76
|
fields?: {
|
|
101
77
|
targetFieldKey: string;
|
|
102
|
-
components:
|
|
103
|
-
name: string;
|
|
104
|
-
expression: string;
|
|
105
|
-
alias?: string | undefined;
|
|
106
|
-
}[];
|
|
78
|
+
components: string[];
|
|
107
79
|
remote?: string | undefined;
|
|
108
80
|
}[] | undefined;
|
|
109
81
|
}>>;
|
|
110
82
|
fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
111
83
|
targetFieldKey: z.ZodString;
|
|
84
|
+
alias: z.ZodOptional<z.ZodString>;
|
|
112
85
|
expression: z.ZodString;
|
|
113
86
|
type: z.ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
|
|
114
|
-
|
|
87
|
+
custom: z.ZodDefault<z.ZodBoolean>;
|
|
88
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
115
89
|
enumMapper: z.ZodOptional<z.ZodObject<{
|
|
116
90
|
matcher: z.ZodUnion<[z.ZodEnum<["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"]>, z.ZodArray<z.ZodObject<{
|
|
117
91
|
matchExpression: z.ZodString;
|
|
@@ -136,9 +110,11 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
136
110
|
}>>;
|
|
137
111
|
}, "strip", z.ZodTypeAny, {
|
|
138
112
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
113
|
+
custom: boolean;
|
|
139
114
|
targetFieldKey: string;
|
|
140
115
|
expression: string;
|
|
141
|
-
|
|
116
|
+
hidden: boolean;
|
|
117
|
+
alias?: string | undefined;
|
|
142
118
|
enumMapper?: {
|
|
143
119
|
matcher: "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" | {
|
|
144
120
|
value: string;
|
|
@@ -149,7 +125,9 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
149
125
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
150
126
|
targetFieldKey: string;
|
|
151
127
|
expression: string;
|
|
152
|
-
|
|
128
|
+
custom?: boolean | undefined;
|
|
129
|
+
alias?: string | undefined;
|
|
130
|
+
hidden?: boolean | undefined;
|
|
153
131
|
enumMapper?: {
|
|
154
132
|
matcher: "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" | {
|
|
155
133
|
value: string;
|
|
@@ -236,19 +214,17 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
236
214
|
version?: number | undefined;
|
|
237
215
|
fields?: {
|
|
238
216
|
targetFieldKey: string;
|
|
239
|
-
components:
|
|
240
|
-
name: string;
|
|
241
|
-
expression: string;
|
|
242
|
-
alias?: string | undefined;
|
|
243
|
-
}[];
|
|
217
|
+
components: string[];
|
|
244
218
|
remote?: string | undefined;
|
|
245
219
|
}[] | undefined;
|
|
246
220
|
} | undefined;
|
|
247
221
|
fieldConfigs?: {
|
|
248
222
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
223
|
+
custom: boolean;
|
|
249
224
|
targetFieldKey: string;
|
|
250
225
|
expression: string;
|
|
251
|
-
|
|
226
|
+
hidden: boolean;
|
|
227
|
+
alias?: string | undefined;
|
|
252
228
|
enumMapper?: {
|
|
253
229
|
matcher: "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" | {
|
|
254
230
|
value: string;
|
|
@@ -296,11 +272,7 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
296
272
|
version?: number | undefined;
|
|
297
273
|
fields?: {
|
|
298
274
|
targetFieldKey: string;
|
|
299
|
-
components:
|
|
300
|
-
name: string;
|
|
301
|
-
expression: string;
|
|
302
|
-
alias?: string | undefined;
|
|
303
|
-
}[];
|
|
275
|
+
components: string[];
|
|
304
276
|
remote?: string | undefined;
|
|
305
277
|
}[] | undefined;
|
|
306
278
|
} | undefined;
|
|
@@ -308,7 +280,9 @@ export declare const OPERATION_SCHEMA: z.ZodObject<{
|
|
|
308
280
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
309
281
|
targetFieldKey: string;
|
|
310
282
|
expression: string;
|
|
311
|
-
|
|
283
|
+
custom?: boolean | undefined;
|
|
284
|
+
alias?: string | undefined;
|
|
285
|
+
hidden?: boolean | undefined;
|
|
312
286
|
enumMapper?: {
|
|
313
287
|
matcher: "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" | {
|
|
314
288
|
value: string;
|
|
@@ -740,34 +714,14 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
740
714
|
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
741
715
|
targetFieldKey: z.ZodString;
|
|
742
716
|
remote: z.ZodOptional<z.ZodString>;
|
|
743
|
-
components: z.ZodArray<z.
|
|
744
|
-
name: z.ZodString;
|
|
745
|
-
expression: z.ZodString;
|
|
746
|
-
alias: z.ZodOptional<z.ZodString>;
|
|
747
|
-
}, "strip", z.ZodTypeAny, {
|
|
748
|
-
name: string;
|
|
749
|
-
expression: string;
|
|
750
|
-
alias?: string | undefined;
|
|
751
|
-
}, {
|
|
752
|
-
name: string;
|
|
753
|
-
expression: string;
|
|
754
|
-
alias?: string | undefined;
|
|
755
|
-
}>, "many">;
|
|
717
|
+
components: z.ZodArray<z.ZodString, "many">;
|
|
756
718
|
}, "strip", z.ZodTypeAny, {
|
|
757
719
|
targetFieldKey: string;
|
|
758
|
-
components:
|
|
759
|
-
name: string;
|
|
760
|
-
expression: string;
|
|
761
|
-
alias?: string | undefined;
|
|
762
|
-
}[];
|
|
720
|
+
components: string[];
|
|
763
721
|
remote?: string | undefined;
|
|
764
722
|
}, {
|
|
765
723
|
targetFieldKey: string;
|
|
766
|
-
components:
|
|
767
|
-
name: string;
|
|
768
|
-
expression: string;
|
|
769
|
-
alias?: string | undefined;
|
|
770
|
-
}[];
|
|
724
|
+
components: string[];
|
|
771
725
|
remote?: string | undefined;
|
|
772
726
|
}>, "many">>;
|
|
773
727
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -775,11 +729,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
775
729
|
version?: number | undefined;
|
|
776
730
|
fields?: {
|
|
777
731
|
targetFieldKey: string;
|
|
778
|
-
components:
|
|
779
|
-
name: string;
|
|
780
|
-
expression: string;
|
|
781
|
-
alias?: string | undefined;
|
|
782
|
-
}[];
|
|
732
|
+
components: string[];
|
|
783
733
|
remote?: string | undefined;
|
|
784
734
|
}[] | undefined;
|
|
785
735
|
}, {
|
|
@@ -787,19 +737,17 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
787
737
|
version?: number | undefined;
|
|
788
738
|
fields?: {
|
|
789
739
|
targetFieldKey: string;
|
|
790
|
-
components:
|
|
791
|
-
name: string;
|
|
792
|
-
expression: string;
|
|
793
|
-
alias?: string | undefined;
|
|
794
|
-
}[];
|
|
740
|
+
components: string[];
|
|
795
741
|
remote?: string | undefined;
|
|
796
742
|
}[] | undefined;
|
|
797
743
|
}>>;
|
|
798
744
|
fieldConfigs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
799
745
|
targetFieldKey: z.ZodString;
|
|
746
|
+
alias: z.ZodOptional<z.ZodString>;
|
|
800
747
|
expression: z.ZodString;
|
|
801
748
|
type: z.ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
|
|
802
|
-
|
|
749
|
+
custom: z.ZodDefault<z.ZodBoolean>;
|
|
750
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
803
751
|
enumMapper: z.ZodOptional<z.ZodObject<{
|
|
804
752
|
matcher: z.ZodUnion<[z.ZodEnum<["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"]>, z.ZodArray<z.ZodObject<{
|
|
805
753
|
matchExpression: z.ZodString;
|
|
@@ -824,9 +772,11 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
824
772
|
}>>;
|
|
825
773
|
}, "strip", z.ZodTypeAny, {
|
|
826
774
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
775
|
+
custom: boolean;
|
|
827
776
|
targetFieldKey: string;
|
|
828
777
|
expression: string;
|
|
829
|
-
|
|
778
|
+
hidden: boolean;
|
|
779
|
+
alias?: string | undefined;
|
|
830
780
|
enumMapper?: {
|
|
831
781
|
matcher: "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" | {
|
|
832
782
|
value: string;
|
|
@@ -837,7 +787,9 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
837
787
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
838
788
|
targetFieldKey: string;
|
|
839
789
|
expression: string;
|
|
840
|
-
|
|
790
|
+
custom?: boolean | undefined;
|
|
791
|
+
alias?: string | undefined;
|
|
792
|
+
hidden?: boolean | undefined;
|
|
841
793
|
enumMapper?: {
|
|
842
794
|
matcher: "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" | {
|
|
843
795
|
value: string;
|
|
@@ -924,19 +876,17 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
924
876
|
version?: number | undefined;
|
|
925
877
|
fields?: {
|
|
926
878
|
targetFieldKey: string;
|
|
927
|
-
components:
|
|
928
|
-
name: string;
|
|
929
|
-
expression: string;
|
|
930
|
-
alias?: string | undefined;
|
|
931
|
-
}[];
|
|
879
|
+
components: string[];
|
|
932
880
|
remote?: string | undefined;
|
|
933
881
|
}[] | undefined;
|
|
934
882
|
} | undefined;
|
|
935
883
|
fieldConfigs?: {
|
|
936
884
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
885
|
+
custom: boolean;
|
|
937
886
|
targetFieldKey: string;
|
|
938
887
|
expression: string;
|
|
939
|
-
|
|
888
|
+
hidden: boolean;
|
|
889
|
+
alias?: string | undefined;
|
|
940
890
|
enumMapper?: {
|
|
941
891
|
matcher: "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" | {
|
|
942
892
|
value: string;
|
|
@@ -984,11 +934,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
984
934
|
version?: number | undefined;
|
|
985
935
|
fields?: {
|
|
986
936
|
targetFieldKey: string;
|
|
987
|
-
components:
|
|
988
|
-
name: string;
|
|
989
|
-
expression: string;
|
|
990
|
-
alias?: string | undefined;
|
|
991
|
-
}[];
|
|
937
|
+
components: string[];
|
|
992
938
|
remote?: string | undefined;
|
|
993
939
|
}[] | undefined;
|
|
994
940
|
} | undefined;
|
|
@@ -996,7 +942,9 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
996
942
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
997
943
|
targetFieldKey: string;
|
|
998
944
|
expression: string;
|
|
999
|
-
|
|
945
|
+
custom?: boolean | undefined;
|
|
946
|
+
alias?: string | undefined;
|
|
947
|
+
hidden?: boolean | undefined;
|
|
1000
948
|
enumMapper?: {
|
|
1001
949
|
matcher: "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" | {
|
|
1002
950
|
value: string;
|
|
@@ -1126,19 +1074,17 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
1126
1074
|
version?: number | undefined;
|
|
1127
1075
|
fields?: {
|
|
1128
1076
|
targetFieldKey: string;
|
|
1129
|
-
components:
|
|
1130
|
-
name: string;
|
|
1131
|
-
expression: string;
|
|
1132
|
-
alias?: string | undefined;
|
|
1133
|
-
}[];
|
|
1077
|
+
components: string[];
|
|
1134
1078
|
remote?: string | undefined;
|
|
1135
1079
|
}[] | undefined;
|
|
1136
1080
|
} | undefined;
|
|
1137
1081
|
fieldConfigs?: {
|
|
1138
1082
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
1083
|
+
custom: boolean;
|
|
1139
1084
|
targetFieldKey: string;
|
|
1140
1085
|
expression: string;
|
|
1141
|
-
|
|
1086
|
+
hidden: boolean;
|
|
1087
|
+
alias?: string | undefined;
|
|
1142
1088
|
enumMapper?: {
|
|
1143
1089
|
matcher: "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" | {
|
|
1144
1090
|
value: string;
|
|
@@ -1268,11 +1214,7 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
1268
1214
|
version?: number | undefined;
|
|
1269
1215
|
fields?: {
|
|
1270
1216
|
targetFieldKey: string;
|
|
1271
|
-
components:
|
|
1272
|
-
name: string;
|
|
1273
|
-
expression: string;
|
|
1274
|
-
alias?: string | undefined;
|
|
1275
|
-
}[];
|
|
1217
|
+
components: string[];
|
|
1276
1218
|
remote?: string | undefined;
|
|
1277
1219
|
}[] | undefined;
|
|
1278
1220
|
} | undefined;
|
|
@@ -1280,7 +1222,9 @@ export declare const CONNECTOR_YAML_SCHEMA: z.ZodObject<{
|
|
|
1280
1222
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
1281
1223
|
targetFieldKey: string;
|
|
1282
1224
|
expression: string;
|
|
1283
|
-
|
|
1225
|
+
custom?: boolean | undefined;
|
|
1226
|
+
alias?: string | undefined;
|
|
1227
|
+
hidden?: boolean | undefined;
|
|
1284
1228
|
enumMapper?: {
|
|
1285
1229
|
matcher: "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" | {
|
|
1286
1230
|
value: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Block, StepFunctionsFactory } from '@stackone/core';
|
|
2
|
+
import { encodeResultCompositeIdentifiers } from '../compositeIds/outputs';
|
|
2
3
|
import { virtualPaginateResult } from '../pagination/virtualPagination';
|
|
3
|
-
export declare const runStepOperation: ({ block, buildStepFunction, virtualPaginateResultFn, }: {
|
|
4
|
+
export declare const runStepOperation: ({ block, buildStepFunction, virtualPaginateResultFn, encodeResultCompositeIds, }: {
|
|
4
5
|
block: Block;
|
|
5
6
|
buildStepFunction?: typeof StepFunctionsFactory.build;
|
|
6
7
|
virtualPaginateResultFn?: typeof virtualPaginateResult;
|
|
8
|
+
encodeResultCompositeIds?: typeof encodeResultCompositeIdentifiers;
|
|
7
9
|
}) => Promise<Block>;
|