@stackone/core 1.44.0 → 1.46.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 +1 -1
- package/dist/index.js +1 -1
- package/dist/types/blocks/types.d.ts +3 -1
- package/dist/types/compositeIds/types.d.ts +3 -3
- package/dist/types/stepFunctions/mapFields/schemas.d.ts +15 -5
- package/dist/types/stepFunctions/stepFunctionsList.d.ts +30 -10
- package/dist/types/stepFunctions/typecast/schemas.d.ts +15 -5
- package/package.json +1 -1
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as n,getCountrySubDivisionsByAlpha2Code as o,getCountryCodeByCountryName as s,getCountryCodeByAlpha3Code as i,getCountryCodeByAlpha2Code as a,getCountryAlpha2CodeByCountryCode as u,getCountryAlpha2CodeByCountryName as c,getCountryAlpha2CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as d,getCountryAlpha3CodeByCountryName as p,getCountryAlpha3CodeByAlpha2Code as m,getCountryNameByCountryCode as y,getCountryNameByAlpha2Code as g,getCountryNameByAlpha3Code as b,getCountryNameByCountryName as f,getCountryCodeByCountryCode as _,getCountryAlpha3CodeByAlpha3Code as h,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as E,safeParseToBoolean as I,safeParseToNumber as w,safeParseToString as x,encodeToBase64 as j,decodeFromBase64 as F,getContentHash as C}from"@stackone/utils";import{z as T}from"zod";import{evaluate as O,safeEvaluateRecord as R}from"@stackone/expressions";import{RequestParameterLocations as A,HttpMethods as D,RequestClientFactory as K,parseRequestParameters as N,createAuthorizationHeaders as P}from"@stackone/transport";const U=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),$=T.object({data:T.unknown()}),M=(e,t,r)=>Object.entries(e).reduce(((e,[n,o])=>{const s=o?.output?.data;return Array.isArray(s)&&s.length===t?e[n]={output:{data:s[r]}}:e[n]=o,e}),{}),q=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},o={},s=[],i={...e};for(const r of t){const{error:t,value:a}=G(n,e.id,r);t?s.push(t):r.isUnified?i[r.targetFieldKey]=a:o[r.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(o).length>0?o:void 0},errors:s.length>0?s:void 0}},G=(e,t,r)=>{const{expression:n,targetFieldKey:o}=r;if(!n)return{error:{message:"Expression is empty",id:t,targetField:o}};let s;try{s=O(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:o}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:o}}:{value:s}},L=T.object({fields:T.object({targetFieldKey:T.string(),expression:T.string(),type:T.enum(["string","number","boolean","datetime_string","enum"]),isUnified:T.boolean().optional(),enumMapper:T.object({matcher:T.string().or(T.object({matchExpression:T.string(),value:T.string()}).array())}).optional()}).array(),dataSource:T.string()}),B=T.object({data:T.unknown()}),H=(e,t)=>{if(!t)return;const r={},n=[],o={};for(const s of e){const{error:e,value:i}=z(t,t?.id,s);e?n.push(e):s.isUnified?o[s.targetFieldKey]=i:r[s.targetFieldKey]=i}return{record:{...o,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:n.length>0?n:void 0}},z=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Q(r,t,e);case"enum":return W(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Q=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=O(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},W=(S,E,I)=>{const w=Q(S,E,I),x=e(w.value)?w.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:E,targetField:S.targetFieldKey}};const j=S.enumMapper.matcher;if(k(j)){const k=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return v;case"country_alpha3code_by_alpha3code":return h;case"country_code_by_country_code":return _;case"country_name_by_country_name":return f;case"country_name_by_alpha3code":return b;case"country_name_by_alpha2code":return g;case"country_name_by_country_code":return y;case"country_alpha3code_by_alpha2code":return m;case"country_alpha3code_by_country_name":return p;case"country_alpha3code_by_country_code":return d;case"country_alpha2code_by_alpha3code":return l;case"country_alpha2code_by_country_name":return c;case"country_alpha2code_by_country_code":return u;case"country_code_by_alpha2code":return a;case"country_code_by_alpha3code":return i;case"country_code_by_country_name":return s;case"country_subdivisions_by_alpha2code":return o;case"country_subdivision_code_by_subdivision_name":return n;case"country_alpha2code_by_citizenship":return r;case"country_subdivision_name_by_subdivision_code":return t;default:return}})(j);if(e(k)){return{value:{value:(e(x)?k(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${j}" is not supported`,id:E,targetField:S.targetFieldKey}}}for(const e of j){const{matchExpression:t,value:r}=e;if(!0===O(t,I))return{value:{value:r,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Y=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),J=T.object({type:T.literal("bearer"),token:T.string()}),V=T.discriminatedUnion("type",[Y,J]),X=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({indexField:T.string().optional(),dataKey:T.string().optional(),nextKey:T.string().optional()}).optional(),iterator:T.object({key:T.string(),in:T.enum(A)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(A),condition:T.string().optional()}).array().optional()}),Z=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),ee=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const n=t.indexField;return n&&r[n]&&(e[r[n]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},te=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),re=T.object({type:T.literal("bearer"),token:T.string()}),ne=T.discriminatedUnion("type",[te,re]),oe=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({collection:T.boolean().optional(),indexField:T.string().optional(),dataKey:T.string().optional()}).optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(A),condition:T.string().optional()}).array().optional()}),se=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number()}).optional(),ie=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const n=t.indexField;return n&&r[n]&&(e[r[n]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},ae=T.object({fields:T.object({targetFieldKey:T.string(),type:T.string(),isUnified:T.boolean().optional()}).array().optional(),dataSource:T.string()}),ue=T.object({data:T.unknown()});var ce;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ce||(ce={}));const le=({value:e,type:t,format:r})=>{if(S(e))return null;switch(t){case ce.String:return x({value:e});case ce.Number:return w({value:e});case ce.Boolean:return I({value:e});case ce.DateTimeString:return E({value:e,format:r});default:return e}},de=e=>Object.values(ce).includes(e),pe=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;de(s)&&(r.isUnified&&e(n[o])?n[o]=le({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:s})))})),{...n}},me=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;de(s)&&(r.isUnified&&e(n[o])?n[o]=le({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:s})))})),{...n}};var ye;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(ye||(ye={}));const ge={[ye.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>pe(e,t))):pe(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:n}=ae.parse(t),o=O(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(o)?o.map((e=>me(e,r))):me(o,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:ae,outputSchema:ue}},[ye.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],n=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!n)return{block:e,successful:!0};let o;if(Array.isArray(e.result)){const s=e.result.length;o=e.result.map(((e,o)=>{const i=M(n,s,o),a=q(e,t,i);return r.push(...a.errors||[]),a.record}))}else{const s=q(e.result,t,n);o=s.record,r.push(...s.errors||[])}return{block:{...e,result:o},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:n,dataSource:o}=L.parse(t),s=O(o,e);if(!n||!o||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let i;if(Array.isArray(s))i=s.map((e=>{const t=H(n,e);return r.push(...t?.errors||[]),t?.record}));else{const e=H(n,s);i=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:i},errors:Object.keys(r).length>0?r:void 0}},inputSchema:L,outputSchema:B}},[ye.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,o=n?n.filter((t=>!t.condition||!0===O(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?R({...t,args:o},e):{},{baseUrl:i,url:a,method:u,response:c,args:l}=oe.parse(s),d=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,p=ne.parse(d),m=l?N(l):{query:{},body:{},headers:{}},y=P(p),g={...m?.headers??{},...y};let b;try{b=await r.performRequest({httpClient:e.httpClient,url:`${i}${a}`,queryParams:m?.query,method:u,headers:g,body:m?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const f=c?.dataKey?b.data[c?.dataKey]:b.data,_=ie(f,c);return{block:e,successful:!0,output:{data:_,raw:b,statusCode:b?.status}}},inputSchema:oe,outputSchema:se}},[ye.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:n,isSingleRecord:o}=U.parse(r),s=n.reduce(((r,n)=>{const s=t.steps?.[n]?.output?.data;return s?o?{...r,[n]:{...s}}:(Object.keys(s).forEach((t=>{const o=e(r[t])?r[t]:{};r[t]={...o,[n]:{...s[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:o?s:Object.values(s)}}},inputSchema:U,outputSchema:$}},[ye.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:r})=>{const n=K.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:o}=r,s=Number(t.inputs?.page_size),i=Number.isNaN(s)?25:s,a=o?o.filter((e=>!e.condition||!0===O(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,u=r?R({...r,args:a},t):{},{baseUrl:c,url:l,method:d,response:p,iterator:m,cursor:y,args:g}=X.parse(u),b=u?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,f=V.parse(b),_=g?N(g):{query:{},body:{},headers:{}},h=P(f),v={..._?.headers??{},...h};let k=y?.token??null,E=null,I=null,w=[],x=[];const j=[];let F=i,C=y?.position??0,T=!0,A=!0;do{let e;T?T=!1:C=0,null!==k&&("query"===m.in?_.query[m.key]=k.toString():"body"===m.in&&(_.body[m.key]=k));try{e=await n.performRequest({httpClient:t.httpClient,url:`${c}${l}`,queryParams:_?.query,method:d,headers:v,body:_?.body})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500}}}E=k,x=p?.dataKey?e.data[p?.dataKey]:e.data;const r=x?.slice(C,F);F-=r.length,C+=r.length,j.push(e),w=w.concat(r),I=e?.status,k=p?.nextKey?e.data[p?.nextKey]:void 0,r.length===x.length&&0===F&&(C=0,E=k),A=S(k)&&w.length<i}while(e(k)&&w.length<i&&x?.length>0);const D=ee(w,p);return{block:t,successful:!0,output:{data:D,raw:j,statusCode:I,next:A?void 0:E,position:A?void 0:C}}},inputSchema:X,outputSchema:Z}}},be=(e,t)=>async({block:r,params:n})=>{try{e.inputSchema&&e.inputSchema.parse(n)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const o=await e.fn({block:r,params:n});try{e.outputSchema&&e.outputSchema.parse(o.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return o},fe={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:n=ge}){const o=n?.[e]?.[`v${t}`];if(!o)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...o,fn:be(o,e)}:o}},_e={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}},he=e=>_e[e.toLowerCase()]??null,ve=e=>!!_e[e.toLowerCase()];var ke;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Info=2]="Info",e[e.Warning=3]="Warning",e[e.Error=4]="Error"}(ke||(ke={}));const Se=T.object({r:T.record(T.string(),T.object({n:T.number().optional().nullable(),c:T.string().optional().nullable(),p:T.number().optional().nullable()})),v:T.number(),t:T.number()}),Ee=T.object({remote:T.record(T.string(),T.object({pageNumber:T.number().optional(),providerPageCursor:T.string().optional(),position:T.number().optional()})),version:T.number(),timestamp:T.number()}),Ie=e=>j(JSON.stringify(we(e))),we=e=>{const{remote:t,version:r,timestamp:n}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:n}])=>[e,{n:t,c:r,p:n}]))),v:r,t:n}},xe=e=>{try{if(k(e)){const t=F(e),r=JSON.parse(t),n=Se.parse(r);return je(n)}return Ee.parse(e),e}catch{return null}},je=e=>{const{r:t,v:r,t:n}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:n}])=>[e,{pageNumber:t,providerPageCursor:r,position:n}]))),version:r,timestamp:n}},Fe=(e,t)=>{const r="string"==typeof e?xe(e):e,n="string"==typeof t?xe(t):t;if(null===r||null===n)return r===n;const{timestamp:o,...s}=r,{timestamp:i,...a}=n;return C(s)===C(a)},Ce=({cursor:e,ignoreStepIndex:t})=>!!S(e)||Object.keys(e?.remote??{}).reduce(((r,n)=>{const o=e?.remote?.[n];return(S(t)||n!==t.toString())&&(r=r&&S(o.pageNumber)&&S(o.position)&&S(o.providerPageCursor)),r}),!0),Te=({cursor:e,stepIndex:t,pageNumber:r,providerPageCursor:n,position:o})=>{const s={pageNumber:r??void 0,providerPageCursor:n??void 0,position:o??void 0},i=S(r)&&S(n)&&S(o);return S(e)?{remote:i?{}:{[t]:s},version:2,timestamp:Date.now()}:i?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:s}}};class Oe extends Error{constructor({category:e,name:t,type:r,context:n,message:o}){super(o),this.name=t??"CoreError",this.type=r,this.category=e,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,Oe)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const Re=e=>e instanceof Oe,Ae=j("so1!"),De=":",Ke=",",Ne=new RegExp(`(?<!\\\\)${De}`,"g"),Pe=new RegExp(`(?<!\\\\)${Ke}`,"g"),Ue=1;class $e extends Oe{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class Me extends $e{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class qe extends $e{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class Ge extends $e{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Le extends $e{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const Be=(e,t={version:1})=>{if(1===t.version)return Je(ze(e,t.aliases));throw new Le(`Cannot generate ID, unsupported version number: ${t.version}`)},He=(e,t={version:1})=>{const r=Ye(e,t),n={};return r?(r.split(Pe).forEach((e=>{const[r,o]=e.split(Ne),s=We(r,t.aliases??{});n[s]=Ze(o)})),n):n},ze=(e,t={})=>{if((e=>!S(e)&&"value"in e&&void 0!==e.value)(e))return Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if((e=>!S(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1}))).join(Ke);throw new Ge},Qe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,Xe(e.value)].filter(Boolean).join(De),We=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,Ye=(e,t)=>{if(1===t.version)return Ve(e);throw new Le(`Cannot decode ID, unsupported version number: ${t.version}`)},Je=e=>`${Ae}${j(e)}`,Ve=e=>{if(!e.startsWith(Ae))throw new Me(`Trying to decode an ID without the header: ${e}`);const t=e.split(Ae)[1];if(!t)throw new qe(`Trying to decode an ID without a body: ${e}`);return F(t)},Xe=e=>[Ke,De].reduce(((e,t)=>e.replace(t,"\\"+t)),e),Ze=e=>[Ke,De].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e);export{ne as AUTHENTICATION_SCHEMA,Ue as COMPOSITE_ID_LATEST_VERSION,Oe as CoreError,ke as LogLevel,ye as StepFunctionName,fe as StepFunctionsFactory,Fe as areCursorsEqual,He as decodeCompositeId,Be as encodeCompositeId,xe as expandCursor,he as getCategoryDetails,Re as isCoreError,Ce as isCursorEmpty,ve as isValidCategory,Ie as minifyCursor,Te as updateCursor};
|
|
1
|
+
import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as n,getCountrySubDivisionsByAlpha2Code as o,getCountryCodeByCountryName as s,getCountryCodeByAlpha3Code as i,getCountryCodeByAlpha2Code as a,getCountryAlpha2CodeByCountryCode as u,getCountryAlpha2CodeByCountryName as c,getCountryAlpha2CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as d,getCountryAlpha3CodeByCountryName as p,getCountryAlpha3CodeByAlpha2Code as m,getCountryNameByCountryCode as g,getCountryNameByAlpha2Code as y,getCountryNameByAlpha3Code as b,getCountryNameByCountryName as f,getCountryCodeByCountryCode as h,getCountryAlpha3CodeByAlpha3Code as _,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as E,safeParseToBoolean as I,safeParseToNumber as w,safeParseToString as x,encodeToBase64 as j,decodeFromBase64 as F,getContentHash as C}from"@stackone/utils";import{z as T}from"zod";import{evaluate as O,safeEvaluateRecord as R}from"@stackone/expressions";import{RequestParameterLocations as A,HttpMethods as D,RequestClientFactory as K,parseRequestParameters as N,createAuthorizationHeaders as P}from"@stackone/transport";const $=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),M=T.object({data:T.unknown()}),U=(e,t,r)=>Object.entries(e).reduce(((e,[n,o])=>{const s=o?.output?.data;return Array.isArray(s)&&s.length===t?e[n]={output:{data:s[r]}}:e[n]=o,e}),{}),q=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},o={},s=[],i={...e};for(const r of t){const{error:t,value:a}=G(n,e.id,r);t?s.push(t):r.custom?o[r.targetFieldKey]=a:i[r.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(o).length>0?o:void 0},errors:s.length>0?s:void 0}},G=(e,t,r)=>{const{expression:n,targetFieldKey:o}=r;if(!n)return{error:{message:"Expression is empty",id:t,targetField:o}};let s;try{s=O(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:o}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:o}}:{value:s}},L=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),expression:T.string(),type:T.enum(["string","number","boolean","datetime_string","enum"]),custom:T.boolean().default(!1),hidden:T.boolean().default(!1),enumMapper:T.object({matcher:T.string().or(T.object({matchExpression:T.string(),value:T.string()}).array())}).optional()}).array(),dataSource:T.string()}),B=T.object({data:T.unknown()}),H=(e,t)=>{if(!t)return;const r={},n=[],o={};for(const s of e){const{error:e,value:i}=z(t,t?.id,s);e?n.push(e):s.custom?r[s.targetFieldKey]=i:o[s.targetFieldKey]=i}return{record:{...o,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:n.length>0?n:void 0}},z=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Q(r,t,e);case"enum":return W(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Q=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=O(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},W=(S,E,I)=>{const w=Q(S,E,I),x=e(w.value)?w.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:E,targetField:S.targetFieldKey}};const j=S.enumMapper.matcher;if(k(j)){const k=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return v;case"country_alpha3code_by_alpha3code":return _;case"country_code_by_country_code":return h;case"country_name_by_country_name":return f;case"country_name_by_alpha3code":return b;case"country_name_by_alpha2code":return y;case"country_name_by_country_code":return g;case"country_alpha3code_by_alpha2code":return m;case"country_alpha3code_by_country_name":return p;case"country_alpha3code_by_country_code":return d;case"country_alpha2code_by_alpha3code":return l;case"country_alpha2code_by_country_name":return c;case"country_alpha2code_by_country_code":return u;case"country_code_by_alpha2code":return a;case"country_code_by_alpha3code":return i;case"country_code_by_country_name":return s;case"country_subdivisions_by_alpha2code":return o;case"country_subdivision_code_by_subdivision_name":return n;case"country_alpha2code_by_citizenship":return r;case"country_subdivision_name_by_subdivision_code":return t;default:return}})(j);if(e(k)){return{value:{value:(e(x)?k(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${j}" is not supported`,id:E,targetField:S.targetFieldKey}}}for(const e of j){const{matchExpression:t,value:r}=e;if(!0===O(t,I))return{value:{value:r,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Y=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),J=T.object({type:T.literal("bearer"),token:T.string()}),V=T.discriminatedUnion("type",[Y,J]),X=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({indexField:T.string().optional(),dataKey:T.string().optional(),nextKey:T.string().optional()}).optional(),iterator:T.object({key:T.string(),in:T.enum(A)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(A),condition:T.string().optional()}).array().optional()}),Z=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),ee=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const n=t.indexField;return n&&r[n]&&(e[r[n]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},te=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),re=T.object({type:T.literal("bearer"),token:T.string()}),ne=T.discriminatedUnion("type",[te,re]),oe=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({collection:T.boolean().optional(),indexField:T.string().optional(),dataKey:T.string().optional()}).optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(A),condition:T.string().optional()}).array().optional()}),se=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number()}).optional(),ie=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const n=t.indexField;return n&&r[n]&&(e[r[n]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},ae=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),type:T.string(),custom:T.boolean().default(!1),hidden:T.boolean().default(!1)}).array().optional(),dataSource:T.string()}),ue=T.object({data:T.unknown()});var ce;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ce||(ce={}));const le=({value:e,type:t,format:r})=>{if(S(e))return null;switch(t){case ce.String:return x({value:e});case ce.Number:return w({value:e});case ce.Boolean:return I({value:e});case ce.DateTimeString:return E({value:e,format:r});default:return e}},de=e=>Object.values(ce).includes(e),pe=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;de(s)&&(!r.custom&&e(n[o])?n[o]=le({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:s})))})),{...n}},me=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;de(s)&&(!r.custom&&e(n[o])?n[o]=le({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:s})))})),{...n}};var ge;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(ge||(ge={}));const ye={[ge.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>pe(e,t))):pe(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:n}=ae.parse(t),o=O(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(o)?o.map((e=>me(e,r))):me(o,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:ae,outputSchema:ue}},[ge.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],n=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!n)return{block:e,successful:!0};let o;if(Array.isArray(e.result)){const s=e.result.length;o=e.result.map(((e,o)=>{const i=U(n,s,o),a=q(e,t,i);return r.push(...a.errors||[]),a.record}))}else{const s=q(e.result,t,n);o=s.record,r.push(...s.errors||[])}return{block:{...e,result:o},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:n,dataSource:o}=L.parse(t),s=O(o,e);if(!n||!o||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let i;if(Array.isArray(s))i=s.map((e=>{const t=H(n,e);return r.push(...t?.errors||[]),t?.record}));else{const e=H(n,s);i=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:i},errors:Object.keys(r).length>0?r:void 0}},inputSchema:L,outputSchema:B}},[ge.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,o=n?n.filter((t=>!t.condition||!0===O(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?R({...t,args:o},e):{},{baseUrl:i,url:a,method:u,response:c,args:l}=oe.parse(s),d=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,p=ne.parse(d),m=l?N(l):{query:{},body:{},headers:{}},g=P(p),y={...m?.headers??{},...g};let b;try{b=await r.performRequest({httpClient:e.httpClient,url:`${i}${a}`,queryParams:m?.query,method:u,headers:y,body:m?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const f=c?.dataKey?b.data[c?.dataKey]:b.data,h=ie(f,c);return{block:e,successful:!0,output:{data:h,raw:b,statusCode:b?.status}}},inputSchema:oe,outputSchema:se}},[ge.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:n,isSingleRecord:o}=$.parse(r),s=n.reduce(((r,n)=>{const s=t.steps?.[n]?.output?.data;return s?o?{...r,[n]:{...s}}:(Object.keys(s).forEach((t=>{const o=e(r[t])?r[t]:{};r[t]={...o,[n]:{...s[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:o?s:Object.values(s)}}},inputSchema:$,outputSchema:M}},[ge.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:r})=>{const n=K.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:o}=r,s=Number(t.inputs?.page_size),i=Number.isNaN(s)?25:s,a=o?o.filter((e=>!e.condition||!0===O(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,u=r?R({...r,args:a},t):{},{baseUrl:c,url:l,method:d,response:p,iterator:m,cursor:g,args:y}=X.parse(u),b=u?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,f=V.parse(b),h=y?N(y):{query:{},body:{},headers:{}},_=P(f),v={...h?.headers??{},..._};let k=g?.token??null,E=null,I=null,w=[],x=[];const j=[];let F=i,C=g?.position??0,T=!0,A=!0;do{let e;T?T=!1:C=0,null!==k&&("query"===m.in?h.query[m.key]=k.toString():"body"===m.in&&(h.body[m.key]=k));try{e=await n.performRequest({httpClient:t.httpClient,url:`${c}${l}`,queryParams:h?.query,method:d,headers:v,body:h?.body})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500}}}E=k,x=p?.dataKey?e.data[p?.dataKey]:e.data;const r=x?.slice(C,F);F-=r.length,C+=r.length,j.push(e),w=w.concat(r),I=e?.status,k=p?.nextKey?e.data[p?.nextKey]:void 0,r.length===x.length&&0===F&&(C=0,E=k),A=S(k)&&w.length<i}while(e(k)&&w.length<i&&x?.length>0);const D=ee(w,p);return{block:t,successful:!0,output:{data:D,raw:j,statusCode:I,next:A?void 0:E,position:A?void 0:C}}},inputSchema:X,outputSchema:Z}}},be=(e,t)=>async({block:r,params:n})=>{try{e.inputSchema&&e.inputSchema.parse(n)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const o=await e.fn({block:r,params:n});try{e.outputSchema&&e.outputSchema.parse(o.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return o},fe={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:n=ye}){const o=n?.[e]?.[`v${t}`];if(!o)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...o,fn:be(o,e)}:o}},he={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}},_e=e=>he[e.toLowerCase()]??null,ve=e=>!!he[e.toLowerCase()];var ke;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Info=2]="Info",e[e.Warning=3]="Warning",e[e.Error=4]="Error"}(ke||(ke={}));const Se=T.object({r:T.record(T.string(),T.object({n:T.number().optional().nullable(),c:T.string().optional().nullable(),p:T.number().optional().nullable()})),v:T.number(),t:T.number()}),Ee=T.object({remote:T.record(T.string(),T.object({pageNumber:T.number().optional(),providerPageCursor:T.string().optional(),position:T.number().optional()})),version:T.number(),timestamp:T.number()}),Ie=e=>j(JSON.stringify(we(e))),we=e=>{const{remote:t,version:r,timestamp:n}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:n}])=>[e,{n:t,c:r,p:n}]))),v:r,t:n}},xe=e=>{try{if(k(e)){const t=F(e),r=JSON.parse(t),n=Se.parse(r);return je(n)}return Ee.parse(e),e}catch{return null}},je=e=>{const{r:t,v:r,t:n}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:n}])=>[e,{pageNumber:t,providerPageCursor:r,position:n}]))),version:r,timestamp:n}},Fe=(e,t)=>{const r="string"==typeof e?xe(e):e,n="string"==typeof t?xe(t):t;if(null===r||null===n)return r===n;const{timestamp:o,...s}=r,{timestamp:i,...a}=n;return C(s)===C(a)},Ce=({cursor:e,ignoreStepIndex:t})=>!!S(e)||Object.keys(e?.remote??{}).reduce(((r,n)=>{const o=e?.remote?.[n];return(S(t)||n!==t.toString())&&(r=r&&S(o.pageNumber)&&S(o.position)&&S(o.providerPageCursor)),r}),!0),Te=({cursor:e,stepIndex:t,pageNumber:r,providerPageCursor:n,position:o})=>{const s={pageNumber:r??void 0,providerPageCursor:n??void 0,position:o??void 0},i=S(r)&&S(n)&&S(o);return S(e)?{remote:i?{}:{[t]:s},version:2,timestamp:Date.now()}:i?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:s}}};class Oe extends Error{constructor({category:e,name:t,type:r,context:n,message:o}){super(o),this.name=t??"CoreError",this.type=r,this.category=e,this.context=n,Error.captureStackTrace&&Error.captureStackTrace(this,Oe)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const Re=e=>e instanceof Oe,Ae=j("so1!"),De=":",Ke=",",Ne=new RegExp(`(?<!\\\\)${De}`,"g"),Pe=new RegExp(`(?<!\\\\)${Ke}`,"g"),$e=1;class Me extends Oe{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class Ue extends Me{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class qe extends Me{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class Ge extends Me{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Le extends Me{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const Be=(e,t={version:1})=>{if(1===t.version)return Je(ze(e,t.aliases));throw new Le(`Cannot generate ID, unsupported version number: ${t.version}`)},He=(e,t={version:1})=>{const r=Ye(e,t),n={};return r?(r.split(Pe).forEach((e=>{const[r,o]=e.split(Ne),s=We(r,t.aliases??{});n[s]=Ze(o)})),n):n},ze=(e,t={})=>{if((e=>!S(e)&&"value"in e&&void 0!==e.value)(e))return Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if((e=>!S(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1}))).join(Ke);throw new Ge},Qe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,Xe(e.value)].filter(Boolean).join(De),We=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,Ye=(e,t)=>{if(1===t.version)return Ve(e);throw new Le(`Cannot decode ID, unsupported version number: ${t.version}`)},Je=e=>`${Ae}${j(e)}`,Ve=e=>{if(!e.startsWith(Ae))throw new Ue(`Trying to decode an ID without the header: ${e}`);const t=e.split(Ae)[1];if(!t)throw new qe(`Trying to decode an ID without a body: ${e}`);return F(t)},Xe=e=>[Ke,De].reduce(((e,t)=>e.replace(t,"\\"+t)),e),Ze=e=>[Ke,De].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e);export{ne as AUTHENTICATION_SCHEMA,$e as COMPOSITE_ID_LATEST_VERSION,Oe as CoreError,ke as LogLevel,ge as StepFunctionName,fe as StepFunctionsFactory,Fe as areCursorsEqual,He as decodeCompositeId,Be as encodeCompositeId,xe as expandCursor,_e as getCategoryDetails,Re as isCoreError,Ce as isCursorEmpty,ve as isValidCategory,Ie as minifyCursor,Te as updateCursor};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@stackone/utils"),t=require("zod"),r=require("@stackone/expressions"),o=require("@stackone/transport");const n=t.z.object({stepsDataToGroup:t.z.array(t.z.string()),isSingleRecord:t.z.boolean().optional()}),s=t.z.object({data:t.z.unknown()}),i=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const s=n?.output?.data;return Array.isArray(s)&&s.length===t?e[o]={output:{data:s[r]}}:e[o]=n,e}),{}),a=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],i={...e};for(const r of t){const{error:t,value:a}=u(o,e.id,r);t?s.push(t):r.isUnified?i[r.targetFieldKey]=a:n[r.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},u=(e,t,o)=>{const{expression:n,targetFieldKey:s}=o;if(!n)return{error:{message:"Expression is empty",id:t,targetField:s}};let i;try{i=r.evaluate(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:s}}}return void 0===i?{error:{message:"Expression returned no value",id:t,targetField:s}}:{value:i}},c=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),expression:t.z.string(),type:t.z.enum(["string","number","boolean","datetime_string","enum"]),isUnified:t.z.boolean().optional(),enumMapper:t.z.object({matcher:t.z.string().or(t.z.object({matchExpression:t.z.string(),value:t.z.string()}).array())}).optional()}).array(),dataSource:t.z.string()}),l=t.z.object({data:t.z.unknown()}),d=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:i}=p(t,t?.id,s);e?o.push(e):s.isUnified?n[s.targetFieldKey]=i:r[s.targetFieldKey]=i}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},p=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return m(r,t,e);case"enum":return y(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},m=(e,t,o)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=r.evaluate(e.expression,o)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},y=(t,o,n)=>{const s=m(t,o,n),i=e.notMissing(s.value)?s.value:null;if(void 0===t.enumMapper)return{error:{message:"Enum mapper was not defined",id:o,targetField:t.targetFieldKey}};const a=t.enumMapper.matcher;if(e.isString(a)){const r=(t=>{switch(t){case"country_alpha2code_by_alpha2code":return e.getCountryAlpha2CodeByAlpha2Code;case"country_alpha3code_by_alpha3code":return e.getCountryAlpha3CodeByAlpha3Code;case"country_code_by_country_code":return e.getCountryCodeByCountryCode;case"country_name_by_country_name":return e.getCountryNameByCountryName;case"country_name_by_alpha3code":return e.getCountryNameByAlpha3Code;case"country_name_by_alpha2code":return e.getCountryNameByAlpha2Code;case"country_name_by_country_code":return e.getCountryNameByCountryCode;case"country_alpha3code_by_alpha2code":return e.getCountryAlpha3CodeByAlpha2Code;case"country_alpha3code_by_country_name":return e.getCountryAlpha3CodeByCountryName;case"country_alpha3code_by_country_code":return e.getCountryAlpha3CodeByCountryCode;case"country_alpha2code_by_alpha3code":return e.getCountryAlpha2CodeByAlpha3Code;case"country_alpha2code_by_country_name":return e.getCountryAlpha2CodeByCountryName;case"country_alpha2code_by_country_code":return e.getCountryAlpha2CodeByCountryCode;case"country_code_by_alpha2code":return e.getCountryCodeByAlpha2Code;case"country_code_by_alpha3code":return e.getCountryCodeByAlpha3Code;case"country_code_by_country_name":return e.getCountryCodeByCountryName;case"country_subdivisions_by_alpha2code":return e.getCountrySubDivisionsByAlpha2Code;case"country_subdivision_code_by_subdivision_name":return e.getCountrySubDivisionCodeBySubDivisionName;case"country_alpha2code_by_citizenship":return e.getCountryAlpha2CodeByCitizenship;case"country_subdivision_name_by_subdivision_code":return e.getCountrySubDivisionNameBySubDivisionCode;default:return}})(a);if(e.notMissing(r)){return{value:{value:(e.notMissing(i)?r(i):null)??"unmapped_value",source_value:i}}}return{error:{message:`The built-in matcher "${a}" is not supported`,id:o,targetField:t.targetFieldKey}}}for(const e of a){const{matchExpression:t,value:o}=e;if(!0===r.evaluate(t,n))return{value:{value:o,source_value:i}}}return{value:{value:"unmapped_value",source_value:i}}},g=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),b=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),h=t.z.discriminatedUnion("type",[g,b]),f=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({indexField:t.z.string().optional(),dataKey:t.z.string().optional(),nextKey:t.z.string().optional()}).optional(),iterator:t.z.object({key:t.z.string(),in:t.z.enum(o.RequestParameterLocations)}),cursor:t.z.object({token:t.z.string().optional().nullable(),position:t.z.number().optional().nullable()}).optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),_=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),next:t.z.string().optional().nullable(),position:t.z.number().optional()}).optional(),v=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},z=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),C=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),S=t.z.discriminatedUnion("type",[z,C]),x=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({collection:t.z.boolean().optional(),indexField:t.z.string().optional(),dataKey:t.z.string().optional()}).optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),E=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number()}).optional(),k=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},I=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),type:t.z.string(),isUnified:t.z.boolean().optional()}).array().optional(),dataSource:t.z.string()}),A=t.z.object({data:t.z.unknown()});var F;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(F||(F={}));const T=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case F.String:return e.safeParseToString({value:t});case F.Number:return e.safeParseToNumber({value:t});case F.Boolean:return e.safeParseToBoolean({value:t});case F.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},w=e=>Object.values(F).includes(e),N=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(r.isUnified&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}},j=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(r.isUnified&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}};var M;exports.StepFunctionName=void 0,(M=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",M.MAP_FIELDS="map_fields",M.GROUP_DATA="group_data",M.REQUEST="request",M.PAGINATED_REQUEST="paginated_request";const R={[exports.StepFunctionName.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>N(e,t))):N(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:n}=I.parse(t),s=r.evaluate(n,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let i;return i=Array.isArray(s)?s.map((e=>j(e,o))):j(s,o),{block:{...e},successful:!0,output:{data:i}}},inputSchema:I,outputSchema:A}},[exports.StepFunctionName.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const s=e.result.length;n=e.result.map(((e,n)=>{const u=i(o,s,n),c=a(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const s=a(e.result,t,o);n=s.record,r.push(...s.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const o=[],{fields:n,dataSource:s}=c.parse(t),i=r.evaluate(s,e);if(!n||!s||"disabled"===e?.debug?.custom_mappings||!i)return{block:e,successful:!0};let a;if(Array.isArray(i))a=i.map((e=>{const t=d(n,e);return o.push(...t?.errors||[]),t?.record}));else{const e=d(n,i);a=e?.record,o.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(o).length>0?o:void 0}},inputSchema:c,outputSchema:l}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const n=o.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:s}=t,i=s?s.filter((t=>!t.condition||!0===r.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,a=t?r.safeEvaluateRecord({...t,args:i},e):{},{baseUrl:u,url:c,method:l,response:d,args:p}=x.parse(a),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,y=S.parse(m),g=p?o.parseRequestParameters(p):{query:{},body:{},headers:{}},b=o.createAuthorizationHeaders(y),h={...g?.headers??{},...b};let f;try{f=await n.performRequest({httpClient:e.httpClient,url:`${u}${c}`,queryParams:g?.query,method:l,headers:h,body:g?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const _=d?.dataKey?f.data[d?.dataKey]:f.data,v=k(_,d);return{block:e,successful:!0,output:{data:v,raw:f,statusCode:f?.status}}},inputSchema:x,outputSchema:E}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=n.parse(r),i=o.reduce(((r,o)=>{const n=t.steps?.[o]?.output?.data;return n?s?{...r,[o]:{...n}}:(Object.keys(n).forEach((t=>{const s=e.notMissing(r[t])?r[t]:{};r[t]={...s,[o]:{...n[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:s?i:Object.values(i)}}},inputSchema:n,outputSchema:s}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:n})=>{const s=o.RequestClientFactory.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:i}=n,a=Number(t.inputs?.page_size),u=Number.isNaN(a)?25:a,c=i?i.filter((e=>!e.condition||!0===r.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,l=n?r.safeEvaluateRecord({...n,args:c},t):{},{baseUrl:d,url:p,method:m,response:y,iterator:g,cursor:b,args:_}=f.parse(l),z=l?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,C=h.parse(z),S=_?o.parseRequestParameters(_):{query:{},body:{},headers:{}},x=o.createAuthorizationHeaders(C),E={...S?.headers??{},...x};let k=b?.token??null,I=null,A=null,F=[],T=[];const w=[];let N=u,j=b?.position??0,M=!0,R=!0;do{let r;M?M=!1:j=0,null!==k&&("query"===g.in?S.query[g.key]=k.toString():"body"===g.in&&(S.body[g.key]=k));try{r=await s.performRequest({httpClient:t.httpClient,url:`${d}${p}`,queryParams:S?.query,method:m,headers:E,body:S?.body})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500}}}I=k,T=y?.dataKey?r.data[y?.dataKey]:r.data;const o=T?.slice(j,N);N-=o.length,j+=o.length,w.push(r),F=F.concat(o),A=r?.status,k=y?.nextKey?r.data[y?.nextKey]:void 0,o.length===T.length&&0===N&&(j=0,I=k),R=e.isMissing(k)&&F.length<u}while(e.notMissing(k)&&F.length<u&&T?.length>0);const O=v(F,y);return{block:t,successful:!0,output:{data:O,raw:w,statusCode:A,next:R?void 0:I,position:R?void 0:j}}},inputSchema:f,outputSchema:_}}},O=(e,t)=>async({block:r,params:o})=>{try{e.inputSchema&&e.inputSchema.parse(o)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const n=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(n.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return n},P={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=R}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:O(n,e)}:n}},D={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}};var B;exports.LogLevel=void 0,(B=exports.LogLevel||(exports.LogLevel={}))[B.Trace=0]="Trace",B[B.Debug=1]="Debug",B[B.Info=2]="Info",B[B.Warning=3]="Warning",B[B.Error=4]="Error";const K=t.z.object({r:t.z.record(t.z.string(),t.z.object({n:t.z.number().optional().nullable(),c:t.z.string().optional().nullable(),p:t.z.number().optional().nullable()})),v:t.z.number(),t:t.z.number()}),U=t.z.object({remote:t.z.record(t.z.string(),t.z.object({pageNumber:t.z.number().optional(),providerPageCursor:t.z.string().optional(),position:t.z.number().optional()})),version:t.z.number(),timestamp:t.z.number()}),q=e=>{const{remote:t,version:r,timestamp:o}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:o}])=>[e,{n:t,c:r,p:o}]))),v:r,t:o}},$=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),n=K.parse(o);return L(n)}return U.parse(t),t}catch{return null}},L=e=>{const{r:t,v:r,t:o}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:o}])=>[e,{pageNumber:t,providerPageCursor:r,position:o}]))),version:r,timestamp:o}};class H extends Error{constructor({category:e,name:t,type:r,context:o,message:n}){super(n),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,H)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const G=e.encodeToBase64("so1!"),Q=":",V=",",W=new RegExp(`(?<!\\\\)${Q}`,"g"),Y=new RegExp(`(?<!\\\\)${V}`,"g");class J extends H{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class X extends J{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class Z extends J{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class ee extends J{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class te extends J{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const re=(t,r={})=>{if((t=>!e.isMissing(t)&&"value"in t&&void 0!==t.value)(t))return oe({identifier:t,compositeIdAliases:r,isSoleIdentifier:!0});if((t=>!e.isMissing(t)&&"identifiers"in t&&void 0!==t.identifiers)(t))return t.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(V);throw new ee},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(Q),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,se=(e,t)=>{if(1===t.version)return ae(e);throw new te(`Cannot decode ID, unsupported version number: ${t.version}`)},ie=t=>`${G}${e.encodeToBase64(t)}`,ae=t=>{if(!t.startsWith(G))throw new X(`Trying to decode an ID without the header: ${t}`);const r=t.split(G)[1];if(!r)throw new Z(`Trying to decode an ID without a body: ${t}`);return e.decodeFromBase64(r)},ue=e=>[V,Q].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[V,Q].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e);exports.AUTHENTICATION_SCHEMA=S,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=H,exports.StepFunctionsFactory=P,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?$(t):t,n="string"==typeof r?$(r):r;if(null===o||null===n)return o===n;const{timestamp:s,...i}=o,{timestamp:a,...u}=n;return e.getContentHash(i)===e.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(Y).forEach((e=>{const[r,n]=e.split(W),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return ie(re(e,t.aliases));throw new te(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=$,exports.getCategoryDetails=e=>D[e.toLowerCase()]??null,exports.isCoreError=e=>e instanceof H,exports.isCursorEmpty=({cursor:t,ignoreStepIndex:r})=>!!e.isMissing(t)||Object.keys(t?.remote??{}).reduce(((o,n)=>{const s=t?.remote?.[n];return(e.isMissing(r)||n!==r.toString())&&(o=o&&e.isMissing(s.pageNumber)&&e.isMissing(s.position)&&e.isMissing(s.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!D[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify(q(t))),exports.updateCursor=({cursor:t,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const i={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},a=e.isMissing(o)&&e.isMissing(n)&&e.isMissing(s);return e.isMissing(t)?{remote:a?{}:{[r]:i},version:2,timestamp:Date.now()}:a?(delete t.remote[r],t):{...t,remote:{...t.remote,[r]:i}}};
|
|
1
|
+
"use strict";var e=require("@stackone/utils"),t=require("zod"),r=require("@stackone/expressions"),o=require("@stackone/transport");const n=t.z.object({stepsDataToGroup:t.z.array(t.z.string()),isSingleRecord:t.z.boolean().optional()}),s=t.z.object({data:t.z.unknown()}),i=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const s=n?.output?.data;return Array.isArray(s)&&s.length===t?e[o]={output:{data:s[r]}}:e[o]=n,e}),{}),a=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],i={...e};for(const r of t){const{error:t,value:a}=u(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=a:i[r.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},u=(e,t,o)=>{const{expression:n,targetFieldKey:s}=o;if(!n)return{error:{message:"Expression is empty",id:t,targetField:s}};let i;try{i=r.evaluate(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:s}}}return void 0===i?{error:{message:"Expression returned no value",id:t,targetField:s}}:{value:i}},c=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),alias:t.z.string().optional(),expression:t.z.string(),type:t.z.enum(["string","number","boolean","datetime_string","enum"]),custom:t.z.boolean().default(!1),hidden:t.z.boolean().default(!1),enumMapper:t.z.object({matcher:t.z.string().or(t.z.object({matchExpression:t.z.string(),value:t.z.string()}).array())}).optional()}).array(),dataSource:t.z.string()}),l=t.z.object({data:t.z.unknown()}),d=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:i}=p(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=i:n[s.targetFieldKey]=i}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},p=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return m(r,t,e);case"enum":return y(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},m=(e,t,o)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=r.evaluate(e.expression,o)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},y=(t,o,n)=>{const s=m(t,o,n),i=e.notMissing(s.value)?s.value:null;if(void 0===t.enumMapper)return{error:{message:"Enum mapper was not defined",id:o,targetField:t.targetFieldKey}};const a=t.enumMapper.matcher;if(e.isString(a)){const r=(t=>{switch(t){case"country_alpha2code_by_alpha2code":return e.getCountryAlpha2CodeByAlpha2Code;case"country_alpha3code_by_alpha3code":return e.getCountryAlpha3CodeByAlpha3Code;case"country_code_by_country_code":return e.getCountryCodeByCountryCode;case"country_name_by_country_name":return e.getCountryNameByCountryName;case"country_name_by_alpha3code":return e.getCountryNameByAlpha3Code;case"country_name_by_alpha2code":return e.getCountryNameByAlpha2Code;case"country_name_by_country_code":return e.getCountryNameByCountryCode;case"country_alpha3code_by_alpha2code":return e.getCountryAlpha3CodeByAlpha2Code;case"country_alpha3code_by_country_name":return e.getCountryAlpha3CodeByCountryName;case"country_alpha3code_by_country_code":return e.getCountryAlpha3CodeByCountryCode;case"country_alpha2code_by_alpha3code":return e.getCountryAlpha2CodeByAlpha3Code;case"country_alpha2code_by_country_name":return e.getCountryAlpha2CodeByCountryName;case"country_alpha2code_by_country_code":return e.getCountryAlpha2CodeByCountryCode;case"country_code_by_alpha2code":return e.getCountryCodeByAlpha2Code;case"country_code_by_alpha3code":return e.getCountryCodeByAlpha3Code;case"country_code_by_country_name":return e.getCountryCodeByCountryName;case"country_subdivisions_by_alpha2code":return e.getCountrySubDivisionsByAlpha2Code;case"country_subdivision_code_by_subdivision_name":return e.getCountrySubDivisionCodeBySubDivisionName;case"country_alpha2code_by_citizenship":return e.getCountryAlpha2CodeByCitizenship;case"country_subdivision_name_by_subdivision_code":return e.getCountrySubDivisionNameBySubDivisionCode;default:return}})(a);if(e.notMissing(r)){return{value:{value:(e.notMissing(i)?r(i):null)??"unmapped_value",source_value:i}}}return{error:{message:`The built-in matcher "${a}" is not supported`,id:o,targetField:t.targetFieldKey}}}for(const e of a){const{matchExpression:t,value:o}=e;if(!0===r.evaluate(t,n))return{value:{value:o,source_value:i}}}return{value:{value:"unmapped_value",source_value:i}}},g=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),b=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),h=t.z.discriminatedUnion("type",[g,b]),f=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({indexField:t.z.string().optional(),dataKey:t.z.string().optional(),nextKey:t.z.string().optional()}).optional(),iterator:t.z.object({key:t.z.string(),in:t.z.enum(o.RequestParameterLocations)}),cursor:t.z.object({token:t.z.string().optional().nullable(),position:t.z.number().optional().nullable()}).optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),_=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),next:t.z.string().optional().nullable(),position:t.z.number().optional()}).optional(),v=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},z=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),C=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),S=t.z.discriminatedUnion("type",[z,C]),x=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({collection:t.z.boolean().optional(),indexField:t.z.string().optional(),dataKey:t.z.string().optional()}).optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),E=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number()}).optional(),k=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},I=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),alias:t.z.string().optional(),type:t.z.string(),custom:t.z.boolean().default(!1),hidden:t.z.boolean().default(!1)}).array().optional(),dataSource:t.z.string()}),A=t.z.object({data:t.z.unknown()});var F;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(F||(F={}));const T=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case F.String:return e.safeParseToString({value:t});case F.Number:return e.safeParseToNumber({value:t});case F.Boolean:return e.safeParseToBoolean({value:t});case F.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},w=e=>Object.values(F).includes(e),N=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(!r.custom&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}},j=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(!r.custom&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}};var M;exports.StepFunctionName=void 0,(M=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",M.MAP_FIELDS="map_fields",M.GROUP_DATA="group_data",M.REQUEST="request",M.PAGINATED_REQUEST="paginated_request";const R={[exports.StepFunctionName.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>N(e,t))):N(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:n}=I.parse(t),s=r.evaluate(n,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let i;return i=Array.isArray(s)?s.map((e=>j(e,o))):j(s,o),{block:{...e},successful:!0,output:{data:i}}},inputSchema:I,outputSchema:A}},[exports.StepFunctionName.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const s=e.result.length;n=e.result.map(((e,n)=>{const u=i(o,s,n),c=a(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const s=a(e.result,t,o);n=s.record,r.push(...s.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const o=[],{fields:n,dataSource:s}=c.parse(t),i=r.evaluate(s,e);if(!n||!s||"disabled"===e?.debug?.custom_mappings||!i)return{block:e,successful:!0};let a;if(Array.isArray(i))a=i.map((e=>{const t=d(n,e);return o.push(...t?.errors||[]),t?.record}));else{const e=d(n,i);a=e?.record,o.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(o).length>0?o:void 0}},inputSchema:c,outputSchema:l}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const n=o.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:s}=t,i=s?s.filter((t=>!t.condition||!0===r.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,a=t?r.safeEvaluateRecord({...t,args:i},e):{},{baseUrl:u,url:c,method:l,response:d,args:p}=x.parse(a),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,y=S.parse(m),g=p?o.parseRequestParameters(p):{query:{},body:{},headers:{}},b=o.createAuthorizationHeaders(y),h={...g?.headers??{},...b};let f;try{f=await n.performRequest({httpClient:e.httpClient,url:`${u}${c}`,queryParams:g?.query,method:l,headers:h,body:g?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const _=d?.dataKey?f.data[d?.dataKey]:f.data,v=k(_,d);return{block:e,successful:!0,output:{data:v,raw:f,statusCode:f?.status}}},inputSchema:x,outputSchema:E}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=n.parse(r),i=o.reduce(((r,o)=>{const n=t.steps?.[o]?.output?.data;return n?s?{...r,[o]:{...n}}:(Object.keys(n).forEach((t=>{const s=e.notMissing(r[t])?r[t]:{};r[t]={...s,[o]:{...n[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:s?i:Object.values(i)}}},inputSchema:n,outputSchema:s}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:n})=>{const s=o.RequestClientFactory.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:i}=n,a=Number(t.inputs?.page_size),u=Number.isNaN(a)?25:a,c=i?i.filter((e=>!e.condition||!0===r.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,l=n?r.safeEvaluateRecord({...n,args:c},t):{},{baseUrl:d,url:p,method:m,response:y,iterator:g,cursor:b,args:_}=f.parse(l),z=l?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,C=h.parse(z),S=_?o.parseRequestParameters(_):{query:{},body:{},headers:{}},x=o.createAuthorizationHeaders(C),E={...S?.headers??{},...x};let k=b?.token??null,I=null,A=null,F=[],T=[];const w=[];let N=u,j=b?.position??0,M=!0,R=!0;do{let r;M?M=!1:j=0,null!==k&&("query"===g.in?S.query[g.key]=k.toString():"body"===g.in&&(S.body[g.key]=k));try{r=await s.performRequest({httpClient:t.httpClient,url:`${d}${p}`,queryParams:S?.query,method:m,headers:E,body:S?.body})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500}}}I=k,T=y?.dataKey?r.data[y?.dataKey]:r.data;const o=T?.slice(j,N);N-=o.length,j+=o.length,w.push(r),F=F.concat(o),A=r?.status,k=y?.nextKey?r.data[y?.nextKey]:void 0,o.length===T.length&&0===N&&(j=0,I=k),R=e.isMissing(k)&&F.length<u}while(e.notMissing(k)&&F.length<u&&T?.length>0);const O=v(F,y);return{block:t,successful:!0,output:{data:O,raw:w,statusCode:A,next:R?void 0:I,position:R?void 0:j}}},inputSchema:f,outputSchema:_}}},O=(e,t)=>async({block:r,params:o})=>{try{e.inputSchema&&e.inputSchema.parse(o)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const n=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(n.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return n},P={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=R}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:O(n,e)}:n}},D={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}};var B;exports.LogLevel=void 0,(B=exports.LogLevel||(exports.LogLevel={}))[B.Trace=0]="Trace",B[B.Debug=1]="Debug",B[B.Info=2]="Info",B[B.Warning=3]="Warning",B[B.Error=4]="Error";const K=t.z.object({r:t.z.record(t.z.string(),t.z.object({n:t.z.number().optional().nullable(),c:t.z.string().optional().nullable(),p:t.z.number().optional().nullable()})),v:t.z.number(),t:t.z.number()}),q=t.z.object({remote:t.z.record(t.z.string(),t.z.object({pageNumber:t.z.number().optional(),providerPageCursor:t.z.string().optional(),position:t.z.number().optional()})),version:t.z.number(),timestamp:t.z.number()}),$=e=>{const{remote:t,version:r,timestamp:o}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:o}])=>[e,{n:t,c:r,p:o}]))),v:r,t:o}},U=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),n=K.parse(o);return L(n)}return q.parse(t),t}catch{return null}},L=e=>{const{r:t,v:r,t:o}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:o}])=>[e,{pageNumber:t,providerPageCursor:r,position:o}]))),version:r,timestamp:o}};class H extends Error{constructor({category:e,name:t,type:r,context:o,message:n}){super(n),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,H)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const G=e.encodeToBase64("so1!"),Q=":",V=",",W=new RegExp(`(?<!\\\\)${Q}`,"g"),Y=new RegExp(`(?<!\\\\)${V}`,"g");class J extends H{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class X extends J{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class Z extends J{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class ee extends J{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class te extends J{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const re=(t,r={})=>{if((t=>!e.isMissing(t)&&"value"in t&&void 0!==t.value)(t))return oe({identifier:t,compositeIdAliases:r,isSoleIdentifier:!0});if((t=>!e.isMissing(t)&&"identifiers"in t&&void 0!==t.identifiers)(t))return t.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(V);throw new ee},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(Q),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,se=(e,t)=>{if(1===t.version)return ae(e);throw new te(`Cannot decode ID, unsupported version number: ${t.version}`)},ie=t=>`${G}${e.encodeToBase64(t)}`,ae=t=>{if(!t.startsWith(G))throw new X(`Trying to decode an ID without the header: ${t}`);const r=t.split(G)[1];if(!r)throw new Z(`Trying to decode an ID without a body: ${t}`);return e.decodeFromBase64(r)},ue=e=>[V,Q].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[V,Q].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e);exports.AUTHENTICATION_SCHEMA=S,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=H,exports.StepFunctionsFactory=P,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?U(t):t,n="string"==typeof r?U(r):r;if(null===o||null===n)return o===n;const{timestamp:s,...i}=o,{timestamp:a,...u}=n;return e.getContentHash(i)===e.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(Y).forEach((e=>{const[r,n]=e.split(W),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return ie(re(e,t.aliases));throw new te(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=U,exports.getCategoryDetails=e=>D[e.toLowerCase()]??null,exports.isCoreError=e=>e instanceof H,exports.isCursorEmpty=({cursor:t,ignoreStepIndex:r})=>!!e.isMissing(t)||Object.keys(t?.remote??{}).reduce(((o,n)=>{const s=t?.remote?.[n];return(e.isMissing(r)||n!==r.toString())&&(o=o&&e.isMissing(s.pageNumber)&&e.isMissing(s.position)&&e.isMissing(s.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!D[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify($(t))),exports.updateCursor=({cursor:t,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const i={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},a=e.isMissing(o)&&e.isMissing(n)&&e.isMissing(s);return e.isMissing(t)?{remote:a?{}:{[r]:i},version:2,timestamp:Date.now()}:a?(delete t.remote[r],t):{...t,remote:{...t.remote,[r]:i}}};
|
|
@@ -56,8 +56,10 @@ export type EnumMatcherExpression = {
|
|
|
56
56
|
export type FieldConfig = {
|
|
57
57
|
expression?: string;
|
|
58
58
|
targetFieldKey: string;
|
|
59
|
+
alias?: string;
|
|
59
60
|
type: string;
|
|
60
|
-
|
|
61
|
+
custom: boolean;
|
|
62
|
+
hidden: boolean;
|
|
61
63
|
enumMapper?: {
|
|
62
64
|
matcher: string | EnumMatcherExpression[];
|
|
63
65
|
};
|
|
@@ -13,16 +13,16 @@ export type CompositeIdentifierConfig = {
|
|
|
13
13
|
export type CompositeIdError = 'COMPOSITE_ID_MISSING_HEADER_ERROR' | 'COMPOSITE_ID_MISSING_BODY_ERROR' | 'COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR' | 'COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR';
|
|
14
14
|
type ComponentConfig = {
|
|
15
15
|
name: string;
|
|
16
|
-
expression: string;
|
|
17
16
|
alias?: string;
|
|
18
17
|
};
|
|
19
18
|
type ComponentFieldConfig = {
|
|
19
|
+
targetFieldKey: string;
|
|
20
|
+
remote?: string;
|
|
20
21
|
components: ComponentConfig[];
|
|
21
|
-
remote: string;
|
|
22
22
|
};
|
|
23
23
|
export type CompositeIdentifierConnectorConfig = {
|
|
24
24
|
enabled: boolean;
|
|
25
|
-
version
|
|
25
|
+
version?: number;
|
|
26
26
|
fields?: ComponentFieldConfig[];
|
|
27
27
|
};
|
|
28
28
|
export {};
|
|
@@ -2,9 +2,11 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
|
|
3
3
|
fields: z.ZodArray<z.ZodObject<{
|
|
4
4
|
targetFieldKey: z.ZodString;
|
|
5
|
+
alias: z.ZodOptional<z.ZodString>;
|
|
5
6
|
expression: z.ZodString;
|
|
6
7
|
type: z.ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
|
|
7
|
-
|
|
8
|
+
custom: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
8
10
|
enumMapper: z.ZodOptional<z.ZodObject<{
|
|
9
11
|
matcher: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
|
|
10
12
|
matchExpression: z.ZodString;
|
|
@@ -31,7 +33,9 @@ export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
|
|
|
31
33
|
targetFieldKey: string;
|
|
32
34
|
expression: string;
|
|
33
35
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
34
|
-
|
|
36
|
+
custom: boolean;
|
|
37
|
+
hidden: boolean;
|
|
38
|
+
alias?: string | undefined;
|
|
35
39
|
enumMapper?: {
|
|
36
40
|
matcher: string | {
|
|
37
41
|
value: string;
|
|
@@ -42,7 +46,9 @@ export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
|
|
|
42
46
|
targetFieldKey: string;
|
|
43
47
|
expression: string;
|
|
44
48
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
45
|
-
|
|
49
|
+
alias?: string | undefined;
|
|
50
|
+
custom?: boolean | undefined;
|
|
51
|
+
hidden?: boolean | undefined;
|
|
46
52
|
enumMapper?: {
|
|
47
53
|
matcher: string | {
|
|
48
54
|
value: string;
|
|
@@ -56,7 +62,9 @@ export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
|
|
|
56
62
|
targetFieldKey: string;
|
|
57
63
|
expression: string;
|
|
58
64
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
59
|
-
|
|
65
|
+
custom: boolean;
|
|
66
|
+
hidden: boolean;
|
|
67
|
+
alias?: string | undefined;
|
|
60
68
|
enumMapper?: {
|
|
61
69
|
matcher: string | {
|
|
62
70
|
value: string;
|
|
@@ -70,7 +78,9 @@ export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
|
|
|
70
78
|
targetFieldKey: string;
|
|
71
79
|
expression: string;
|
|
72
80
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
73
|
-
|
|
81
|
+
alias?: string | undefined;
|
|
82
|
+
custom?: boolean | undefined;
|
|
83
|
+
hidden?: boolean | undefined;
|
|
74
84
|
enumMapper?: {
|
|
75
85
|
matcher: string | {
|
|
76
86
|
value: string;
|
|
@@ -15,16 +15,22 @@ export declare const stepFunctions: {
|
|
|
15
15
|
inputSchema: import("zod").ZodObject<{
|
|
16
16
|
fields: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
17
17
|
targetFieldKey: import("zod").ZodString;
|
|
18
|
+
alias: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
19
|
type: import("zod").ZodString;
|
|
19
|
-
|
|
20
|
+
custom: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
21
|
+
hidden: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
20
22
|
}, "strip", import("zod").ZodTypeAny, {
|
|
21
23
|
targetFieldKey: string;
|
|
22
24
|
type: string;
|
|
23
|
-
|
|
25
|
+
custom: boolean;
|
|
26
|
+
hidden: boolean;
|
|
27
|
+
alias?: string | undefined;
|
|
24
28
|
}, {
|
|
25
29
|
targetFieldKey: string;
|
|
26
30
|
type: string;
|
|
27
|
-
|
|
31
|
+
alias?: string | undefined;
|
|
32
|
+
custom?: boolean | undefined;
|
|
33
|
+
hidden?: boolean | undefined;
|
|
28
34
|
}>, "many">>;
|
|
29
35
|
dataSource: import("zod").ZodString;
|
|
30
36
|
}, "strip", import("zod").ZodTypeAny, {
|
|
@@ -32,14 +38,18 @@ export declare const stepFunctions: {
|
|
|
32
38
|
fields?: {
|
|
33
39
|
targetFieldKey: string;
|
|
34
40
|
type: string;
|
|
35
|
-
|
|
41
|
+
custom: boolean;
|
|
42
|
+
hidden: boolean;
|
|
43
|
+
alias?: string | undefined;
|
|
36
44
|
}[] | undefined;
|
|
37
45
|
}, {
|
|
38
46
|
dataSource: string;
|
|
39
47
|
fields?: {
|
|
40
48
|
targetFieldKey: string;
|
|
41
49
|
type: string;
|
|
42
|
-
|
|
50
|
+
alias?: string | undefined;
|
|
51
|
+
custom?: boolean | undefined;
|
|
52
|
+
hidden?: boolean | undefined;
|
|
43
53
|
}[] | undefined;
|
|
44
54
|
}>;
|
|
45
55
|
outputSchema: import("zod").ZodObject<{
|
|
@@ -60,9 +70,11 @@ export declare const stepFunctions: {
|
|
|
60
70
|
inputSchema: import("zod").ZodObject<{
|
|
61
71
|
fields: import("zod").ZodArray<import("zod").ZodObject<{
|
|
62
72
|
targetFieldKey: import("zod").ZodString;
|
|
73
|
+
alias: import("zod").ZodOptional<import("zod").ZodString>;
|
|
63
74
|
expression: import("zod").ZodString;
|
|
64
75
|
type: import("zod").ZodEnum<["string", "number", "boolean", "datetime_string", "enum"]>;
|
|
65
|
-
|
|
76
|
+
custom: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
77
|
+
hidden: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
66
78
|
enumMapper: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
67
79
|
matcher: import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodArray<import("zod").ZodObject<{
|
|
68
80
|
matchExpression: import("zod").ZodString;
|
|
@@ -88,8 +100,10 @@ export declare const stepFunctions: {
|
|
|
88
100
|
}, "strip", import("zod").ZodTypeAny, {
|
|
89
101
|
targetFieldKey: string;
|
|
90
102
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
103
|
+
custom: boolean;
|
|
104
|
+
hidden: boolean;
|
|
91
105
|
expression: string;
|
|
92
|
-
|
|
106
|
+
alias?: string | undefined;
|
|
93
107
|
enumMapper?: {
|
|
94
108
|
matcher: string | {
|
|
95
109
|
value: string;
|
|
@@ -100,7 +114,9 @@ export declare const stepFunctions: {
|
|
|
100
114
|
targetFieldKey: string;
|
|
101
115
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
102
116
|
expression: string;
|
|
103
|
-
|
|
117
|
+
alias?: string | undefined;
|
|
118
|
+
custom?: boolean | undefined;
|
|
119
|
+
hidden?: boolean | undefined;
|
|
104
120
|
enumMapper?: {
|
|
105
121
|
matcher: string | {
|
|
106
122
|
value: string;
|
|
@@ -113,8 +129,10 @@ export declare const stepFunctions: {
|
|
|
113
129
|
fields: {
|
|
114
130
|
targetFieldKey: string;
|
|
115
131
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
132
|
+
custom: boolean;
|
|
133
|
+
hidden: boolean;
|
|
116
134
|
expression: string;
|
|
117
|
-
|
|
135
|
+
alias?: string | undefined;
|
|
118
136
|
enumMapper?: {
|
|
119
137
|
matcher: string | {
|
|
120
138
|
value: string;
|
|
@@ -128,7 +146,9 @@ export declare const stepFunctions: {
|
|
|
128
146
|
targetFieldKey: string;
|
|
129
147
|
type: "string" | "number" | "boolean" | "datetime_string" | "enum";
|
|
130
148
|
expression: string;
|
|
131
|
-
|
|
149
|
+
alias?: string | undefined;
|
|
150
|
+
custom?: boolean | undefined;
|
|
151
|
+
hidden?: boolean | undefined;
|
|
132
152
|
enumMapper?: {
|
|
133
153
|
matcher: string | {
|
|
134
154
|
value: string;
|
|
@@ -2,16 +2,22 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const TYPECAST_INPUT_PARAMS: z.ZodObject<{
|
|
3
3
|
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
4
4
|
targetFieldKey: z.ZodString;
|
|
5
|
+
alias: z.ZodOptional<z.ZodString>;
|
|
5
6
|
type: z.ZodString;
|
|
6
|
-
|
|
7
|
+
custom: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
7
9
|
}, "strip", z.ZodTypeAny, {
|
|
8
10
|
targetFieldKey: string;
|
|
9
11
|
type: string;
|
|
10
|
-
|
|
12
|
+
custom: boolean;
|
|
13
|
+
hidden: boolean;
|
|
14
|
+
alias?: string | undefined;
|
|
11
15
|
}, {
|
|
12
16
|
targetFieldKey: string;
|
|
13
17
|
type: string;
|
|
14
|
-
|
|
18
|
+
alias?: string | undefined;
|
|
19
|
+
custom?: boolean | undefined;
|
|
20
|
+
hidden?: boolean | undefined;
|
|
15
21
|
}>, "many">>;
|
|
16
22
|
dataSource: z.ZodString;
|
|
17
23
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -19,14 +25,18 @@ export declare const TYPECAST_INPUT_PARAMS: z.ZodObject<{
|
|
|
19
25
|
fields?: {
|
|
20
26
|
targetFieldKey: string;
|
|
21
27
|
type: string;
|
|
22
|
-
|
|
28
|
+
custom: boolean;
|
|
29
|
+
hidden: boolean;
|
|
30
|
+
alias?: string | undefined;
|
|
23
31
|
}[] | undefined;
|
|
24
32
|
}, {
|
|
25
33
|
dataSource: string;
|
|
26
34
|
fields?: {
|
|
27
35
|
targetFieldKey: string;
|
|
28
36
|
type: string;
|
|
29
|
-
|
|
37
|
+
alias?: string | undefined;
|
|
38
|
+
custom?: boolean | undefined;
|
|
39
|
+
hidden?: boolean | undefined;
|
|
30
40
|
}[] | undefined;
|
|
31
41
|
}>;
|
|
32
42
|
export declare const TYPECAST_OUTPUT: z.ZodObject<{
|