@stackone/core 1.51.0 → 1.52.4
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/index.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{LogLevel}from"@stackone/logger";import{encodeToBase64 as e,isMissing as t,decodeFromBase64 as r,getContentHash as o,isString as n,notMissing as s,getCountrySubDivisionNameBySubDivisionCode as a,getCountryAlpha2CodeByCitizenship as i,getCountrySubDivisionCodeBySubDivisionName as u,getCountrySubDivisionsByAlpha2Code as c,getCountryCodeByCountryName as l,getCountryCodeByAlpha3Code as d,getCountryCodeByAlpha2Code as p,getCountryAlpha2CodeByCountryCode as m,getCountryAlpha2CodeByCountryName as g,getCountryAlpha2CodeByAlpha3Code as y,getCountryAlpha3CodeByCountryCode as b,getCountryAlpha3CodeByCountryName as f,getCountryAlpha3CodeByAlpha2Code as h,getCountryNameByCountryCode as _,getCountryNameByAlpha2Code as v,getCountryNameByAlpha3Code as k,getCountryNameByCountryName as S,getCountryCodeByCountryCode as E,getCountryAlpha3CodeByAlpha3Code as I,getCountryAlpha2CodeByAlpha2Code as w,safeParseToDateTimeString as x,safeParseToBoolean as C,safeParseToNumber as j,safeParseToString as F}from"@stackone/utils";import{z as T}from"zod";import{evaluate as A,safeEvaluateRecord as O}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as P,RequestParameterLocations as R,HttpMethods as D,RequestClientFactory as K,parseRequestParameters as N,createAuthorizationHeaders as M}from"@stackone/transport";const $={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"}},U=e=>$[e.toLowerCase()]??null,q=e=>!!$[e.toLowerCase()],L=e("so1!"),z=":",H=",",G=new RegExp(`(?<!\\\\)${z}`,"g"),B=new RegExp(`(?<!\\\\)${H}`,"g"),Q=1;class W 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,W)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class Y extends W{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class J extends Y{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class V extends Y{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class X extends Y{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Z extends Y{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const ee=(e,t={version:1})=>{if(1===t.version)return ae(re(e,t.aliases));throw new Z(`Cannot generate ID, unsupported version number: ${t.version}`)},te=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(B).forEach((e=>{const[r,n]=e.split(G),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},re=(e,r={})=>{if((e=>!t(e)&&"value"in e&&void 0!==e.value)(e))return oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!0});if((e=>!t(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(H);throw new X},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(z),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,se=(e,t)=>{if(1===t.version)return ie(e);throw new Z(`Cannot decode ID, unsupported version number: ${t.version}`)},ae=t=>`${L}${e(t)}`,ie=e=>{if(!e.startsWith(L))throw new J(`Trying to decode an ID without the header: ${e}`);const t=e.split(L)[1];if(!t)throw new V(`Trying to decode an ID without a body: ${e}`);return r(t)},ue=e=>[H,z].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[H,z].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),le=e=>!t(e)&&e.startsWith(L),de=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()}),pe=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()}),me=t=>e(JSON.stringify(ge(t))),ge=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}},ye=e=>{try{if(n(e)){const t=r(e),o=JSON.parse(t),n=de.parse(o);return be(n)}return pe.parse(e),e}catch{return null}},be=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}},fe=(e,t)=>{const r="string"==typeof e?ye(e):e,n="string"==typeof t?ye(t):t;if(null===r||null===n)return r===n;const{timestamp:s,...a}=r,{timestamp:i,...u}=n;return o(a)===o(u)},he=({cursor:e,ignoreStepIndex:r})=>!!t(e)||Object.keys(e?.remote??{}).reduce(((o,n)=>{const s=e?.remote?.[n];return(t(r)||n!==r.toString())&&(o=o&&t(s.pageNumber)&&t(s.position)&&t(s.providerPageCursor)),o}),!0),_e=({cursor:e,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const a={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},i=t(o)&&t(n)&&t(s);return t(e)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete e.remote[r],e):{...e,remote:{...e.remote,[r]:a}}},ve=e=>e instanceof W,ke=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),Se=T.object({data:T.unknown()}),Ee=(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}),{}),Ie=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],a={...e};for(const r of t){const{error:t,value:i}=we(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},we=(e,t,r)=>{const{expression:o,targetFieldKey:n}=r;if(!o)return{error:{message:"Expression is empty",id:t,targetField:n}};let s;try{s=A(o,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:s}},xe=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()}),Ce=T.object({data:T.unknown()}),je=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:a}=Fe(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=a:n[s.targetFieldKey]=a}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},Fe=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Te(r,t,e);case"enum":return Ae(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Te=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let o;try{o=A(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:o}},Ae=(e,t,r)=>{const o=Te(e,t,r),x=s(o.value)?o.value:null;if(void 0===e.enumMapper)return{error:{message:"Enum mapper was not defined",id:t,targetField:e.targetFieldKey}};const C=e.enumMapper.matcher;if(n(C)){const r=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return w;case"country_alpha3code_by_alpha3code":return I;case"country_code_by_country_code":return E;case"country_name_by_country_name":return S;case"country_name_by_alpha3code":return k;case"country_name_by_alpha2code":return v;case"country_name_by_country_code":return _;case"country_alpha3code_by_alpha2code":return h;case"country_alpha3code_by_country_name":return f;case"country_alpha3code_by_country_code":return b;case"country_alpha2code_by_alpha3code":return y;case"country_alpha2code_by_country_name":return g;case"country_alpha2code_by_country_code":return m;case"country_code_by_alpha2code":return p;case"country_code_by_alpha3code":return d;case"country_code_by_country_name":return l;case"country_subdivisions_by_alpha2code":return c;case"country_subdivision_code_by_subdivision_name":return u;case"country_alpha2code_by_citizenship":return i;case"country_subdivision_name_by_subdivision_code":return a;default:return}})(C);if(s(r)){return{value:{value:(s(x)?r(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${C}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(const e of C){const{matchExpression:t,value:o}=e;if(!0===A(t,r))return{value:{value:o,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Oe=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),Pe=T.object({type:T.literal("bearer"),token:T.string()}),Re=T.discriminatedUnion("type",[Oe,Pe]),De=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(R)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Ke=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),Ne=(e,t)=>{const r=De.parse(e),o=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=Re.parse(o),s=r.args?N(r.args):{query:{},body:{},headers:{}},a=M(n),i={...s?.headers??{},...a},u=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:s,requestHeaders:i,pageSize:u}}},Me=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},$e=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,n=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-n.length,r.pagePosition=r.pagePosition+n.length,r.raw.push(e),r.data=r.data.concat(n),r.lastStatusCode=e?.status,{resultData:o,slicedData:n}},Ue=(e,r,o,n,s,a)=>{const i=r?.nextKey?e.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,n.length===s.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=t(o.nextIterator)&&o.data.length<a},qe=(e,t,r)=>s(e.nextIterator)&&e.data.length<t&&r?.length>0,Le=(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},ze=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),He=T.object({type:T.literal("bearer"),token:T.string()}),Ge=T.discriminatedUnion("type",[ze,He]),Be=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(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Qe=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional()}).optional(),We=(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},Ye=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()}),Je=T.object({data:T.unknown()});var Ve;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(Ve||(Ve={}));const Xe=({value:e,type:r,format:o})=>{if(t(e))return null;switch(r){case Ve.String:return F({value:e});case Ve.Number:return j({value:e});case Ve.Boolean:return C({value:e});case Ve.DateTimeString:return x({value:e,format:o});default:return e}},Ze=e=>Object.values(Ve).includes(e),et=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}},tt=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}};var rt;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(rt||(rt={}));const ot={[rt.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=>et(e,t))):et(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:o}=Ye.parse(t),n=A(o,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(n)?n.map((e=>tt(e,r))):tt(n,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:Ye,outputSchema:Je}},[rt.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 a=Ee(o,s,n),i=Ie(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=Ie(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 r=[],{fields:o,dataSource:n}=xe.parse(t),s=A(n,e);if(!o||!n||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let a;if(Array.isArray(s))a=s.map((e=>{const t=je(o,e);return r.push(...t?.errors||[]),t?.record}));else{const e=je(o,s);a=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(r).length>0?r:void 0}},inputSchema:xe,outputSchema:Ce}},[rt.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:o}=t,n=o?o.filter((t=>!t.condition||!0===A(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?O({...t,args:n},e):{},a={...s,customErrors:t?.customErrors},{baseUrl:i,url:u,method:c,response:l,customErrors:d,args:p}=Be.parse(a),m=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,g=Ge.parse(m),y=p?N(p):{query:{},body:{},headers:{}},b=M(g),f={...y?.headers??{},...b};let h;try{h=await r.performRequest({httpClient:e.httpClient,url:`${i}${u}`,queryParams:y?.query,method:c,headers:f,body:y?.body,customErrorConfigs:d})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const _=l?.dataKey?h.data[l?.dataKey]:h.data,v=We(_,l);return{block:e,successful:!0,output:{data:v,raw:h,statusCode:h?.status,message:h?.message}}},inputSchema:Be,outputSchema:Qe}},[rt.GROUP_DATA]:{v1:{fn:async({block:e,params:t})=>{const{stepsDataToGroup:r,isSingleRecord:o}=ke.parse(t),n=r.reduce(((t,r)=>{const n=e.steps?.[r]?.output?.data;return n?o?{...t,[r]:{...n}}:(Object.keys(n).forEach((e=>{const o=s(t[e])?t[e]:{};t[e]={...o,[r]:{...n[e]}}})),t):t}),{});return{block:{...e},successful:!0,output:{data:o?n:Object.values(n)}}},inputSchema:ke,outputSchema:Se}},[rt.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const o=((e,t)=>{const{args:r}=e,o=r?r.filter((e=>!e.condition||!0===A(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?O({...e,args:o},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:n,preparedRequest:s}=Ne(o,e),a=(i=n.cursor,u=s.pageSize,{nextIterator:i?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:u,pagePosition:i?.position??0,firstPage:!0,noMoreData:!0});var i,u,c,l,d;do{a.firstPage?a.firstPage=!1:a.pagePosition=0,c=s.parsedArgs,l=n.iterator,null!==(d=a.nextIterator)&&("query"===l.in?c.query[l.key]=d.toString():"body"===l.in&&(c.body[l.key]=d));const t=await Me(r,e,n,s);if("successful"in t&&!1===t.successful)return t;const o=t;a.lastUsedIterator=a.nextIterator;const{resultData:i,slicedData:u}=$e(o,n.response,a);Ue(o,n.response,a,u,i,s.pageSize)}while(qe(a,s.pageSize,a.data));return((e,t,r)=>({block:e,successful:!0,output:{data:Le(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,a,n.response)},inputSchema:De,outputSchema:Ke}}},nt=(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},st={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=ot}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:nt(n,e)}:n}};export{Ge as AUTHENTICATION_SCHEMA,Q as COMPOSITE_ID_LATEST_VERSION,W as CoreError,rt as StepFunctionName,st as StepFunctionsFactory,fe as areCursorsEqual,te as decodeCompositeId,ee as encodeCompositeId,ye as expandCursor,U as getCategoryDetails,le as isCompositeId,ve as isCoreError,he as isCursorEmpty,q as isValidCategory,me as minifyCursor,_e as updateCursor};
|
|
1
|
+
import{encodeToBase64 as e,isMissing as t,decodeFromBase64 as r,getContentHash as o,isString as n,notMissing as s,getCountrySubDivisionNameBySubDivisionCode as a,getCountryAlpha2CodeByCitizenship as i,getCountrySubDivisionCodeBySubDivisionName as u,getCountrySubDivisionsByAlpha2Code as c,getCountryCodeByCountryName as l,getCountryCodeByAlpha3Code as d,getCountryCodeByAlpha2Code as p,getCountryAlpha2CodeByCountryCode as m,getCountryAlpha2CodeByCountryName as g,getCountryAlpha2CodeByAlpha3Code as y,getCountryAlpha3CodeByCountryCode as b,getCountryAlpha3CodeByCountryName as f,getCountryAlpha3CodeByAlpha2Code as h,getCountryNameByCountryCode as _,getCountryNameByAlpha2Code as v,getCountryNameByAlpha3Code as S,getCountryNameByCountryName as k,getCountryCodeByCountryCode as E,getCountryAlpha3CodeByAlpha3Code as I,getCountryAlpha2CodeByAlpha2Code as w,safeParseToDateTimeString as x,safeParseToBoolean as C,safeParseToNumber as j,safeParseToString as F}from"@stackone/utils";import{z as T}from"zod";import{evaluate as A,safeEvaluateRecord as O}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as P,RequestParameterLocations as R,HttpMethods as D,RequestClientFactory as K,parseRequestParameters as N,createAuthorizationHeaders as M}from"@stackone/transport";const $={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"}},U=e=>$[e.toLowerCase()]??null,q=e=>!!$[e.toLowerCase()],L=e("so1!"),z=":",H=",",G=new RegExp(`(?<!\\\\)${z}`,"g"),B=new RegExp(`(?<!\\\\)${H}`,"g"),Q=1;class W 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,W)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class Y extends W{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class J extends Y{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class V extends Y{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class X extends Y{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Z extends Y{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const ee=(e,t={version:1})=>{if(1===t.version)return ae(re(e,t.aliases));throw new Z(`Cannot generate ID, unsupported version number: ${t.version}`)},te=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(B).forEach((e=>{const[r,n]=e.split(G),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},re=(e,r={})=>{if((e=>!t(e)&&"value"in e&&void 0!==e.value)(e))return oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!0});if((e=>!t(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(H);throw new X},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(z),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,se=(e,t)=>{if(1===t.version)return ie(e);throw new Z(`Cannot decode ID, unsupported version number: ${t.version}`)},ae=t=>`${L}${e(t)}`,ie=e=>{if(!e.startsWith(L))throw new J(`Trying to decode an ID without the header: ${e}`);const t=e.split(L)[1];if(!t)throw new V(`Trying to decode an ID without a body: ${e}`);return r(t)},ue=e=>[H,z].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[H,z].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),le=e=>!t(e)&&e.startsWith(L),de=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()}),pe=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()}),me=t=>e(JSON.stringify(ge(t))),ge=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}},ye=e=>{try{if(n(e)){const t=r(e),o=JSON.parse(t),n=de.parse(o);return be(n)}return pe.parse(e),e}catch{return null}},be=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}},fe=(e,t)=>{const r="string"==typeof e?ye(e):e,n="string"==typeof t?ye(t):t;if(null===r||null===n)return r===n;const{timestamp:s,...a}=r,{timestamp:i,...u}=n;return o(a)===o(u)},he=({cursor:e,ignoreStepIndex:r})=>!!t(e)||Object.keys(e?.remote??{}).reduce(((o,n)=>{const s=e?.remote?.[n];return(t(r)||n!==r.toString())&&(o=o&&t(s.pageNumber)&&t(s.position)&&t(s.providerPageCursor)),o}),!0),_e=({cursor:e,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const a={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},i=t(o)&&t(n)&&t(s);return t(e)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete e.remote[r],e):{...e,remote:{...e.remote,[r]:a}}},ve=e=>e instanceof W,Se=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),ke=T.object({data:T.unknown()}),Ee=(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}),{}),Ie=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],a={...e};for(const r of t){const{error:t,value:i}=we(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},we=(e,t,r)=>{const{expression:o,targetFieldKey:n}=r;if(!o)return{error:{message:"Expression is empty",id:t,targetField:n}};let s;try{s=A(o,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:s}},xe=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()}),Ce=T.object({data:T.unknown()}),je=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:a}=Fe(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=a:n[s.targetFieldKey]=a}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},Fe=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Te(r,t,e);case"enum":return Ae(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Te=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let o;try{o=A(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:o}},Ae=(e,t,r)=>{const o=Te(e,t,r),x=s(o.value)?o.value:null;if(void 0===e.enumMapper)return{error:{message:"Enum mapper was not defined",id:t,targetField:e.targetFieldKey}};const C=e.enumMapper.matcher;if(n(C)){const r=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return w;case"country_alpha3code_by_alpha3code":return I;case"country_code_by_country_code":return E;case"country_name_by_country_name":return k;case"country_name_by_alpha3code":return S;case"country_name_by_alpha2code":return v;case"country_name_by_country_code":return _;case"country_alpha3code_by_alpha2code":return h;case"country_alpha3code_by_country_name":return f;case"country_alpha3code_by_country_code":return b;case"country_alpha2code_by_alpha3code":return y;case"country_alpha2code_by_country_name":return g;case"country_alpha2code_by_country_code":return m;case"country_code_by_alpha2code":return p;case"country_code_by_alpha3code":return d;case"country_code_by_country_name":return l;case"country_subdivisions_by_alpha2code":return c;case"country_subdivision_code_by_subdivision_name":return u;case"country_alpha2code_by_citizenship":return i;case"country_subdivision_name_by_subdivision_code":return a;default:return}})(C);if(s(r)){return{value:{value:(s(x)?r(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${C}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(const e of C){const{matchExpression:t,value:o}=e;if(!0===A(t,r))return{value:{value:o,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Oe=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),Pe=T.object({type:T.literal("bearer"),token:T.string()}),Re=T.discriminatedUnion("type",[Oe,Pe]),De=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(R)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Ke=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),Ne=(e,t)=>{const r=De.parse(e),o=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=Re.parse(o),s=r.args?N(r.args):{query:{},body:{},headers:{}},a=M(n),i={...s?.headers??{},...a},u=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:s,requestHeaders:i,pageSize:u}}},Me=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},$e=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,n=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-n.length,r.pagePosition=r.pagePosition+n.length,r.raw.push(e),r.data=r.data.concat(n),r.lastStatusCode=e?.status,{resultData:o,slicedData:n}},Ue=(e,r,o,n,s,a)=>{const i=r?.nextKey?e.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,n.length===s.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=t(o.nextIterator)&&o.data.length<a},qe=(e,t,r)=>s(e.nextIterator)&&e.data.length<t&&r?.length>0,Le=(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},ze=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),He=T.object({type:T.literal("bearer"),token:T.string()}),Ge=T.discriminatedUnion("type",[ze,He]),Be=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(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Qe=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional()}).optional(),We=(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},Ye=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()}),Je=T.object({data:T.unknown()});var Ve;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(Ve||(Ve={}));const Xe=({value:e,type:r,format:o})=>{if(t(e))return null;switch(r){case Ve.String:return F({value:e});case Ve.Number:return j({value:e});case Ve.Boolean:return C({value:e});case Ve.DateTimeString:return x({value:e,format:o});default:return e}},Ze=e=>Object.values(Ve).includes(e),et=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}},tt=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}};var rt;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(rt||(rt={}));const ot={[rt.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=>et(e,t))):et(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:o}=Ye.parse(t),n=A(o,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(n)?n.map((e=>tt(e,r))):tt(n,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:Ye,outputSchema:Je}},[rt.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 a=Ee(o,s,n),i=Ie(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=Ie(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 r=[],{fields:o,dataSource:n}=xe.parse(t),s=A(n,e);if(!o||!n||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let a;if(Array.isArray(s))a=s.map((e=>{const t=je(o,e);return r.push(...t?.errors||[]),t?.record}));else{const e=je(o,s);a=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(r).length>0?r:void 0}},inputSchema:xe,outputSchema:Ce}},[rt.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:o}=t,n=o?o.filter((t=>!t.condition||!0===A(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?O({...t,args:n},e):{},a={...s,customErrors:t?.customErrors},{baseUrl:i,url:u,method:c,response:l,customErrors:d,args:p}=Be.parse(a),m=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,g=Ge.parse(m),y=p?N(p):{query:{},body:{},headers:{}},b=M(g),f={...y?.headers??{},...b};let h;try{h=await r.performRequest({httpClient:e.httpClient,url:`${i}${u}`,queryParams:y?.query,method:c,headers:f,body:y?.body,customErrorConfigs:d})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const _=l?.dataKey?h.data[l?.dataKey]:h.data,v=We(_,l);return{block:e,successful:!0,output:{data:v,raw:h,statusCode:h?.status,message:h?.message}}},inputSchema:Be,outputSchema:Qe}},[rt.GROUP_DATA]:{v1:{fn:async({block:e,params:t})=>{const{stepsDataToGroup:r,isSingleRecord:o}=Se.parse(t),n=r.reduce(((t,r)=>{const n=e.steps?.[r]?.output?.data;return n?o?{...t,[r]:{...n}}:(Object.keys(n).forEach((e=>{const o=s(t[e])?t[e]:{};t[e]={...o,[r]:{...n[e]}}})),t):t}),{});return{block:{...e},successful:!0,output:{data:o?n:Object.values(n)}}},inputSchema:Se,outputSchema:ke}},[rt.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const o=((e,t)=>{const{args:r}=e,o=r?r.filter((e=>!e.condition||!0===A(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?O({...e,args:o},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:n,preparedRequest:s}=Ne(o,e),a=(i=n.cursor,u=s.pageSize,{nextIterator:i?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:u,pagePosition:i?.position??0,firstPage:!0,noMoreData:!0});var i,u,c,l,d;do{a.firstPage?a.firstPage=!1:a.pagePosition=0,c=s.parsedArgs,l=n.iterator,null!==(d=a.nextIterator)&&("query"===l.in?c.query[l.key]=d.toString():"body"===l.in&&(c.body[l.key]=d));const t=await Me(r,e,n,s);if("successful"in t&&!1===t.successful)return t;const o=t;a.lastUsedIterator=a.nextIterator;const{resultData:i,slicedData:u}=$e(o,n.response,a);Ue(o,n.response,a,u,i,s.pageSize)}while(qe(a,s.pageSize,a.data));return((e,t,r)=>({block:e,successful:!0,output:{data:Le(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,a,n.response)},inputSchema:De,outputSchema:Ke}}},nt=(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},st={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=ot}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:nt(n,e)}:n}};export{Ge as AUTHENTICATION_SCHEMA,Q as COMPOSITE_ID_LATEST_VERSION,W as CoreError,rt as StepFunctionName,st as StepFunctionsFactory,fe as areCursorsEqual,te as decodeCompositeId,ee as encodeCompositeId,ye as expandCursor,U as getCategoryDetails,le as isCompositeId,ve as isCoreError,he as isCursorEmpty,q as isValidCategory,me as minifyCursor,_e as updateCursor};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@stackone/logger"),t=require("@stackone/utils"),r=require("zod"),o=require("@stackone/expressions"),s=require("@stackone/transport");const n={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"}},a=t.encodeToBase64("so1!"),i=":",u=",",c=new RegExp(`(?<!\\\\)${i}`,"g"),l=new RegExp(`(?<!\\\\)${u}`,"g");class d extends Error{constructor({category:e,name:t,type:r,context:o,message:s}){super(s),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,d)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class p extends d{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class g extends p{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class m extends p{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class y extends p{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class b extends p{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const f=(e,r={})=>{if((e=>!t.isMissing(e)&&"value"in e&&void 0!==e.value)(e))return h({identifier:e,compositeIdAliases:r,isSoleIdentifier:!0});if((e=>!t.isMissing(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>h({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(u);throw new y},h=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,S(e.value)].filter(Boolean).join(i),_=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,C=(e,t)=>{if(1===t.version)return z(e);throw new b(`Cannot decode ID, unsupported version number: ${t.version}`)},v=e=>`${a}${t.encodeToBase64(e)}`,z=e=>{if(!e.startsWith(a))throw new g(`Trying to decode an ID without the header: ${e}`);const r=e.split(a)[1];if(!r)throw new m(`Trying to decode an ID without a body: ${e}`);return t.decodeFromBase64(r)},S=e=>[u,i].reduce(((e,t)=>e.replace(t,"\\"+t)),e),E=e=>[u,i].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),x=r.z.object({r:r.z.record(r.z.string(),r.z.object({n:r.z.number().optional().nullable(),c:r.z.string().optional().nullable(),p:r.z.number().optional().nullable()})),v:r.z.number(),t:r.z.number()}),I=r.z.object({remote:r.z.record(r.z.string(),r.z.object({pageNumber:r.z.number().optional(),providerPageCursor:r.z.string().optional(),position:r.z.number().optional()})),version:r.z.number(),timestamp:r.z.number()}),k=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}},A=e=>{try{if(t.isString(e)){const r=t.decodeFromBase64(e),o=JSON.parse(r),s=x.parse(o);return w(s)}return I.parse(e),e}catch{return null}},w=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}},F=r.z.object({stepsDataToGroup:r.z.array(r.z.string()),isSingleRecord:r.z.boolean().optional()}),M=r.z.object({data:r.z.unknown()}),T=(e,t,r)=>Object.entries(e).reduce(((e,[o,s])=>{const n=s?.output?.data;return Array.isArray(n)&&n.length===t?e[o]={output:{data:n[r]}}:e[o]=s,e}),{}),R=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},s={},n=[],a={...e};for(const r of t){const{error:t,value:i}=N(o,e.id,r);t?n.push(t):r.custom?s[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:n.length>0?n:void 0}},N=(e,t,r)=>{const{expression:s,targetFieldKey:n}=r;if(!s)return{error:{message:"Expression is empty",id:t,targetField:n}};let a;try{a=o.evaluate(s,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===a?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:a}},j=r.z.object({fields:r.z.object({targetFieldKey:r.z.string(),alias:r.z.string().optional(),expression:r.z.string(),type:r.z.enum(["string","number","boolean","datetime_string","enum"]),custom:r.z.boolean().default(!1),hidden:r.z.boolean().default(!1),enumMapper:r.z.object({matcher:r.z.string().or(r.z.object({matchExpression:r.z.string(),value:r.z.string()}).array())}).optional()}).array(),dataSource:r.z.string()}),O=r.z.object({data:r.z.unknown()}),P=(e,t)=>{if(!t)return;const r={},o=[],s={};for(const n of e){const{error:e,value:a}=D(t,t?.id,n);e?o.push(e):n.custom?r[n.targetFieldKey]=a:s[n.targetFieldKey]=a}return{record:{...s,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},D=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return B(r,t,e);case"enum":return q(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},B=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let s;try{s=o.evaluate(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:s}},q=(e,r,s)=>{const n=B(e,r,s),a=t.notMissing(n.value)?n.value:null;if(void 0===e.enumMapper)return{error:{message:"Enum mapper was not defined",id:r,targetField:e.targetFieldKey}};const i=e.enumMapper.matcher;if(t.isString(i)){const o=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return t.getCountryAlpha2CodeByAlpha2Code;case"country_alpha3code_by_alpha3code":return t.getCountryAlpha3CodeByAlpha3Code;case"country_code_by_country_code":return t.getCountryCodeByCountryCode;case"country_name_by_country_name":return t.getCountryNameByCountryName;case"country_name_by_alpha3code":return t.getCountryNameByAlpha3Code;case"country_name_by_alpha2code":return t.getCountryNameByAlpha2Code;case"country_name_by_country_code":return t.getCountryNameByCountryCode;case"country_alpha3code_by_alpha2code":return t.getCountryAlpha3CodeByAlpha2Code;case"country_alpha3code_by_country_name":return t.getCountryAlpha3CodeByCountryName;case"country_alpha3code_by_country_code":return t.getCountryAlpha3CodeByCountryCode;case"country_alpha2code_by_alpha3code":return t.getCountryAlpha2CodeByAlpha3Code;case"country_alpha2code_by_country_name":return t.getCountryAlpha2CodeByCountryName;case"country_alpha2code_by_country_code":return t.getCountryAlpha2CodeByCountryCode;case"country_code_by_alpha2code":return t.getCountryCodeByAlpha2Code;case"country_code_by_alpha3code":return t.getCountryCodeByAlpha3Code;case"country_code_by_country_name":return t.getCountryCodeByCountryName;case"country_subdivisions_by_alpha2code":return t.getCountrySubDivisionsByAlpha2Code;case"country_subdivision_code_by_subdivision_name":return t.getCountrySubDivisionCodeBySubDivisionName;case"country_alpha2code_by_citizenship":return t.getCountryAlpha2CodeByCitizenship;case"country_subdivision_name_by_subdivision_code":return t.getCountrySubDivisionNameBySubDivisionCode;default:return}})(i);if(t.notMissing(o)){return{value:{value:(t.notMissing(a)?o(a):null)??"unmapped_value",source_value:a}}}return{error:{message:`The built-in matcher "${i}" is not supported`,id:r,targetField:e.targetFieldKey}}}for(const e of i){const{matchExpression:t,value:r}=e;if(!0===o.evaluate(t,s))return{value:{value:r,source_value:a}}}return{value:{value:"unmapped_value",source_value:a}}},K=r.z.object({type:r.z.literal("basic"),username:r.z.string().optional(),password:r.z.string().optional(),encoding:r.z.string().optional()}),U=r.z.object({type:r.z.literal("bearer"),token:r.z.string()}),$=r.z.discriminatedUnion("type",[K,U]),L=r.z.object({baseUrl:r.z.string(),url:r.z.string(),method:r.z.enum(s.HttpMethods),response:r.z.object({indexField:r.z.string().optional(),dataKey:r.z.string().optional(),nextKey:r.z.string().optional()}).optional(),iterator:r.z.object({key:r.z.string(),in:r.z.enum(s.RequestParameterLocations)}),cursor:r.z.object({token:r.z.string().optional().nullable(),position:r.z.number().optional().nullable()}).optional(),customErrors:s.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:r.z.object({name:r.z.string(),value:r.z.unknown(),in:r.z.enum(s.RequestParameterLocations),condition:r.z.string().optional()}).array().optional()}),H=r.z.object({data:r.z.unknown().optional(),raw:r.z.unknown().optional(),statusCode:r.z.number(),message:r.z.string().optional(),next:r.z.string().optional().nullable(),position:r.z.number().optional()}).optional(),G=(e,t)=>{const r=L.parse(e),o=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=$.parse(o),a=r.args?s.parseRequestParameters(r.args):{query:{},body:{},headers:{}},i=s.createAuthorizationHeaders(n),u={...a?.headers??{},...i},c=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:a,requestHeaders:u,pageSize:c}}},Q=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},V=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,s=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-s.length,r.pagePosition=r.pagePosition+s.length,r.raw.push(e),r.data=r.data.concat(s),r.lastStatusCode=e?.status,{resultData:o,slicedData:s}},W=(e,r,o,s,n,a)=>{const i=r?.nextKey?e.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,s.length===n.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=t.isMissing(o.nextIterator)&&o.data.length<a},Y=(e,r,o)=>t.notMissing(e.nextIterator)&&e.data.length<r&&o?.length>0,J=(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},X=r.z.object({type:r.z.literal("basic"),username:r.z.string().optional(),password:r.z.string().optional(),encoding:r.z.string().optional()}),Z=r.z.object({type:r.z.literal("bearer"),token:r.z.string()}),ee=r.z.discriminatedUnion("type",[X,Z]),te=r.z.object({baseUrl:r.z.string(),url:r.z.string(),method:r.z.enum(s.HttpMethods),response:r.z.object({collection:r.z.boolean().optional(),indexField:r.z.string().optional(),dataKey:r.z.string().optional()}).optional(),customErrors:s.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:r.z.object({name:r.z.string(),value:r.z.unknown(),in:r.z.enum(s.RequestParameterLocations),condition:r.z.string().optional()}).array().optional()}),re=r.z.object({data:r.z.unknown().optional(),raw:r.z.unknown().optional(),statusCode:r.z.number(),message:r.z.string().optional()}).optional(),oe=(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},se=r.z.object({fields:r.z.object({targetFieldKey:r.z.string(),alias:r.z.string().optional(),type:r.z.string(),custom:r.z.boolean().default(!1),hidden:r.z.boolean().default(!1)}).array().optional(),dataSource:r.z.string()}),ne=r.z.object({data:r.z.unknown()});var ae;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ae||(ae={}));const ie=({value:e,type:r,format:o})=>{if(t.isMissing(e))return null;switch(r){case ae.String:return t.safeParseToString({value:e});case ae.Number:return t.safeParseToNumber({value:e});case ae.Boolean:return t.safeParseToBoolean({value:e});case ae.DateTimeString:return t.safeParseToDateTimeString({value:e,format:o});default:return e}},ue=e=>Object.values(ae).includes(e),ce=(e,r)=>{const o={...e};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ue(n)&&(!r.custom&&t.notMissing(o[s])?o[s]=ie({value:e[s],type:n}):o.unified_custom_fields&&t.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ie({value:e.unified_custom_fields?.[s],type:n})))})),{...o}},le=(e,r)=>{const o={...e};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ue(n)&&(!r.custom&&t.notMissing(o[s])?o[s]=ie({value:e[s],type:n}):o.unified_custom_fields&&t.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ie({value:e.unified_custom_fields?.[s],type:n})))})),{...o}};var de;exports.StepFunctionName=void 0,(de=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",de.MAP_FIELDS="map_fields",de.GROUP_DATA="group_data",de.REQUEST="request",de.PAGINATED_REQUEST="paginated_request";const pe={[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=>ce(e,t))):ce(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:s}=se.parse(t),n=o.evaluate(s,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let a;return a=Array.isArray(n)?n.map((e=>le(e,r))):le(n,r),{block:{...e},successful:!0,output:{data:a}}},inputSchema:se,outputSchema:ne}},[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 s;if(Array.isArray(e.result)){const n=e.result.length;s=e.result.map(((e,s)=>{const a=T(o,n,s),i=R(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const n=R(e.result,t,o);s=n.record,r.push(...n.errors||[])}return{block:{...e,result:s},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:s,dataSource:n}=j.parse(t),a=o.evaluate(n,e);if(!s||!n||"disabled"===e?.debug?.custom_mappings||!a)return{block:e,successful:!0};let i;if(Array.isArray(a))i=a.map((e=>{const t=P(s,e);return r.push(...t?.errors||[]),t?.record}));else{const e=P(s,a);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:j,outputSchema:O}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=s.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,a=n?n.filter((t=>!t.condition||!0===o.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,i=t?o.safeEvaluateRecord({...t,args:a},e):{},u={...i,customErrors:t?.customErrors},{baseUrl:c,url:l,method:d,response:p,customErrors:g,args:m}=te.parse(u),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=ee.parse(y),f=m?s.parseRequestParameters(m):{query:{},body:{},headers:{}},h=s.createAuthorizationHeaders(b),_={...f?.headers??{},...h};let C;try{C=await r.performRequest({httpClient:e.httpClient,url:`${c}${l}`,queryParams:f?.query,method:d,headers:_,body:f?.body,customErrorConfigs:g})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const v=p?.dataKey?C.data[p?.dataKey]:C.data,z=oe(v,p);return{block:e,successful:!0,output:{data:z,raw:C,statusCode:C?.status,message:C?.message}}},inputSchema:te,outputSchema:re}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:e,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=F.parse(r),n=o.reduce(((r,o)=>{const n=e.steps?.[o]?.output?.data;return n?s?{...r,[o]:{...n}}:(Object.keys(n).forEach((e=>{const s=t.notMissing(r[e])?r[e]:{};r[e]={...s,[o]:{...n[e]}}})),r):r}),{});return{block:{...e},successful:!0,output:{data:s?n:Object.values(n)}}},inputSchema:F,outputSchema:M}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=s.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const n=((e,t)=>{const{args:r}=e,s=r?r.filter((e=>!e.condition||!0===o.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?o.safeEvaluateRecord({...e,args:s},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:a,preparedRequest:i}=G(n,e),u=(c=a.cursor,l=i.pageSize,{nextIterator:c?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:l,pagePosition:c?.position??0,firstPage:!0,noMoreData:!0});var c,l,d,p,g;do{u.firstPage?u.firstPage=!1:u.pagePosition=0,d=i.parsedArgs,p=a.iterator,null!==(g=u.nextIterator)&&("query"===p.in?d.query[p.key]=g.toString():"body"===p.in&&(d.body[p.key]=g));const t=await Q(r,e,a,i);if("successful"in t&&!1===t.successful)return t;const o=t;u.lastUsedIterator=u.nextIterator;const{resultData:s,slicedData:n}=V(o,a.response,u);W(o,a.response,u,n,s,i.pageSize)}while(Y(u,i.pageSize,u.data));return((e,t,r)=>({block:e,successful:!0,output:{data:J(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,u,a.response)},inputSchema:L,outputSchema:H}}},ge=(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 s=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(s.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return s},me={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=pe}){const s=o?.[e]?.[`v${t}`];if(!s)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...s,fn:ge(s,e)}:s}};Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return e.LogLevel}}),exports.AUTHENTICATION_SCHEMA=ee,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=d,exports.StepFunctionsFactory=me,exports.areCursorsEqual=(e,r)=>{const o="string"==typeof e?A(e):e,s="string"==typeof r?A(r):r;if(null===o||null===s)return o===s;const{timestamp:n,...a}=o,{timestamp:i,...u}=s;return t.getContentHash(a)===t.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=C(e,t),o={};return r?(r.split(l).forEach((e=>{const[r,s]=e.split(c),n=_(r,t.aliases??{});o[n]=E(s)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return v(f(e,t.aliases));throw new b(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=A,exports.getCategoryDetails=e=>n[e.toLowerCase()]??null,exports.isCompositeId=e=>!t.isMissing(e)&&e.startsWith(a),exports.isCoreError=e=>e instanceof d,exports.isCursorEmpty=({cursor:e,ignoreStepIndex:r})=>!!t.isMissing(e)||Object.keys(e?.remote??{}).reduce(((o,s)=>{const n=e?.remote?.[s];return(t.isMissing(r)||s!==r.toString())&&(o=o&&t.isMissing(n.pageNumber)&&t.isMissing(n.position)&&t.isMissing(n.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!n[e.toLowerCase()],exports.minifyCursor=e=>t.encodeToBase64(JSON.stringify(k(e))),exports.updateCursor=({cursor:e,stepIndex:r,pageNumber:o,providerPageCursor:s,position:n})=>{const a={pageNumber:o??void 0,providerPageCursor:s??void 0,position:n??void 0},i=t.isMissing(o)&&t.isMissing(s)&&t.isMissing(n);return t.isMissing(e)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete e.remote[r],e):{...e,remote:{...e.remote,[r]:a}}};
|
|
1
|
+
"use strict";var e=require("@stackone/utils"),t=require("zod"),r=require("@stackone/expressions"),o=require("@stackone/transport");const s={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"}},n=e.encodeToBase64("so1!"),a=":",i=",",u=new RegExp(`(?<!\\\\)${a}`,"g"),c=new RegExp(`(?<!\\\\)${i}`,"g");class l extends Error{constructor({category:e,name:t,type:r,context:o,message:s}){super(s),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,l)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class d extends l{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class p extends d{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class g extends d{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class m extends d{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class y extends d{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const b=(t,r={})=>{if((t=>!e.isMissing(t)&&"value"in t&&void 0!==t.value)(t))return f({identifier:t,compositeIdAliases:r,isSoleIdentifier:!0});if((t=>!e.isMissing(t)&&"identifiers"in t&&void 0!==t.identifiers)(t))return t.identifiers.map((e=>f({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(i);throw new m},f=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,z(e.value)].filter(Boolean).join(a),h=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,_=(e,t)=>{if(1===t.version)return v(e);throw new y(`Cannot decode ID, unsupported version number: ${t.version}`)},C=t=>`${n}${e.encodeToBase64(t)}`,v=t=>{if(!t.startsWith(n))throw new p(`Trying to decode an ID without the header: ${t}`);const r=t.split(n)[1];if(!r)throw new g(`Trying to decode an ID without a body: ${t}`);return e.decodeFromBase64(r)},z=e=>[i,a].reduce(((e,t)=>e.replace(t,"\\"+t)),e),S=e=>[i,a].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),E=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()}),x=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()}),I=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}},k=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),s=E.parse(o);return A(s)}return x.parse(t),t}catch{return null}},A=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}},w=t.z.object({stepsDataToGroup:t.z.array(t.z.string()),isSingleRecord:t.z.boolean().optional()}),F=t.z.object({data:t.z.unknown()}),M=(e,t,r)=>Object.entries(e).reduce(((e,[o,s])=>{const n=s?.output?.data;return Array.isArray(n)&&n.length===t?e[o]={output:{data:n[r]}}:e[o]=s,e}),{}),T=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},s={},n=[],a={...e};for(const r of t){const{error:t,value:i}=R(o,e.id,r);t?n.push(t):r.custom?s[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:n.length>0?n:void 0}},R=(e,t,o)=>{const{expression:s,targetFieldKey:n}=o;if(!s)return{error:{message:"Expression is empty",id:t,targetField:n}};let a;try{a=r.evaluate(s,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===a?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:a}},N=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()}),j=t.z.object({data:t.z.unknown()}),O=(e,t)=>{if(!t)return;const r={},o=[],s={};for(const n of e){const{error:e,value:a}=P(t,t?.id,n);e?o.push(e):n.custom?r[n.targetFieldKey]=a:s[n.targetFieldKey]=a}return{record:{...s,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 D(r,t,e);case"enum":return B(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},D=(e,t,o)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let s;try{s=r.evaluate(e.expression,o)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:s}},B=(t,o,s)=>{const n=D(t,o,s),a=e.notMissing(n.value)?n.value:null;if(void 0===t.enumMapper)return{error:{message:"Enum mapper was not defined",id:o,targetField:t.targetFieldKey}};const i=t.enumMapper.matcher;if(e.isString(i)){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}})(i);if(e.notMissing(r)){return{value:{value:(e.notMissing(a)?r(a):null)??"unmapped_value",source_value:a}}}return{error:{message:`The built-in matcher "${i}" is not supported`,id:o,targetField:t.targetFieldKey}}}for(const e of i){const{matchExpression:t,value:o}=e;if(!0===r.evaluate(t,s))return{value:{value:o,source_value:a}}}return{value:{value:"unmapped_value",source_value:a}}},q=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),K=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),U=t.z.discriminatedUnion("type",[q,K]),$=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(),customErrors:o.CUSTOM_ERROR_CONFIG_SCHEMA.array().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()}),H=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),message:t.z.string().optional(),next:t.z.string().optional().nullable(),position:t.z.number().optional()}).optional(),L=(e,t)=>{const r=$.parse(e),s=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=U.parse(s),a=r.args?o.parseRequestParameters(r.args):{query:{},body:{},headers:{}},i=o.createAuthorizationHeaders(n),u={...a?.headers??{},...i},c=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:a,requestHeaders:u,pageSize:c}}},G=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},Q=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,s=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-s.length,r.pagePosition=r.pagePosition+s.length,r.raw.push(e),r.data=r.data.concat(s),r.lastStatusCode=e?.status,{resultData:o,slicedData:s}},V=(t,r,o,s,n,a)=>{const i=r?.nextKey?t.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,s.length===n.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=e.isMissing(o.nextIterator)&&o.data.length<a},W=(t,r,o)=>e.notMissing(t.nextIterator)&&t.data.length<r&&o?.length>0,Y=(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},J=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),X=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),Z=t.z.discriminatedUnion("type",[J,X]),ee=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(),customErrors:o.CUSTOM_ERROR_CONFIG_SCHEMA.array().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()}),te=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),message:t.z.string().optional()}).optional(),re=(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},oe=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()}),se=t.z.object({data:t.z.unknown()});var ne;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ne||(ne={}));const ae=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case ne.String:return e.safeParseToString({value:t});case ne.Number:return e.safeParseToNumber({value:t});case ne.Boolean:return e.safeParseToBoolean({value:t});case ne.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},ie=e=>Object.values(ne).includes(e),ue=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ie(n)&&(!r.custom&&e.notMissing(o[s])?o[s]=ae({value:t[s],type:n}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ae({value:t.unified_custom_fields?.[s],type:n})))})),{...o}},ce=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ie(n)&&(!r.custom&&e.notMissing(o[s])?o[s]=ae({value:t[s],type:n}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ae({value:t.unified_custom_fields?.[s],type:n})))})),{...o}};var le;exports.StepFunctionName=void 0,(le=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",le.MAP_FIELDS="map_fields",le.GROUP_DATA="group_data",le.REQUEST="request",le.PAGINATED_REQUEST="paginated_request";const de={[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=>ue(e,t))):ue(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:s}=oe.parse(t),n=r.evaluate(s,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let a;return a=Array.isArray(n)?n.map((e=>ce(e,o))):ce(n,o),{block:{...e},successful:!0,output:{data:a}}},inputSchema:oe,outputSchema:se}},[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 s;if(Array.isArray(e.result)){const n=e.result.length;s=e.result.map(((e,s)=>{const a=M(o,n,s),i=T(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const n=T(e.result,t,o);s=n.record,r.push(...n.errors||[])}return{block:{...e,result:s},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const o=[],{fields:s,dataSource:n}=N.parse(t),a=r.evaluate(n,e);if(!s||!n||"disabled"===e?.debug?.custom_mappings||!a)return{block:e,successful:!0};let i;if(Array.isArray(a))i=a.map((e=>{const t=O(s,e);return o.push(...t?.errors||[]),t?.record}));else{const e=O(s,a);i=e?.record,o.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:i},errors:Object.keys(o).length>0?o:void 0}},inputSchema:N,outputSchema:j}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const s=o.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,a=n?n.filter((t=>!t.condition||!0===r.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,i=t?r.safeEvaluateRecord({...t,args:a},e):{},u={...i,customErrors:t?.customErrors},{baseUrl:c,url:l,method:d,response:p,customErrors:g,args:m}=ee.parse(u),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=Z.parse(y),f=m?o.parseRequestParameters(m):{query:{},body:{},headers:{}},h=o.createAuthorizationHeaders(b),_={...f?.headers??{},...h};let C;try{C=await s.performRequest({httpClient:e.httpClient,url:`${c}${l}`,queryParams:f?.query,method:d,headers:_,body:f?.body,customErrorConfigs:g})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const v=p?.dataKey?C.data[p?.dataKey]:C.data,z=re(v,p);return{block:e,successful:!0,output:{data:z,raw:C,statusCode:C?.status,message:C?.message}}},inputSchema:ee,outputSchema:te}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=w.parse(r),n=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?n:Object.values(n)}}},inputSchema:w,outputSchema:F}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const s=o.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const n=((e,t)=>{const{args:o}=e,s=o?o.filter((e=>!e.condition||!0===r.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?r.safeEvaluateRecord({...e,args:s},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:a,preparedRequest:i}=L(n,e),u=(c=a.cursor,l=i.pageSize,{nextIterator:c?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:l,pagePosition:c?.position??0,firstPage:!0,noMoreData:!0});var c,l,d,p,g;do{u.firstPage?u.firstPage=!1:u.pagePosition=0,d=i.parsedArgs,p=a.iterator,null!==(g=u.nextIterator)&&("query"===p.in?d.query[p.key]=g.toString():"body"===p.in&&(d.body[p.key]=g));const t=await G(s,e,a,i);if("successful"in t&&!1===t.successful)return t;const r=t;u.lastUsedIterator=u.nextIterator;const{resultData:o,slicedData:n}=Q(r,a.response,u);V(r,a.response,u,n,o,i.pageSize)}while(W(u,i.pageSize,u.data));return((e,t,r)=>({block:e,successful:!0,output:{data:Y(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,u,a.response)},inputSchema:$,outputSchema:H}}},pe=(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 s=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(s.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return s},ge={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=de}){const s=o?.[e]?.[`v${t}`];if(!s)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...s,fn:pe(s,e)}:s}};exports.AUTHENTICATION_SCHEMA=Z,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=l,exports.StepFunctionsFactory=ge,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?k(t):t,s="string"==typeof r?k(r):r;if(null===o||null===s)return o===s;const{timestamp:n,...a}=o,{timestamp:i,...u}=s;return e.getContentHash(a)===e.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=_(e,t),o={};return r?(r.split(c).forEach((e=>{const[r,s]=e.split(u),n=h(r,t.aliases??{});o[n]=S(s)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return C(b(e,t.aliases));throw new y(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=k,exports.getCategoryDetails=e=>s[e.toLowerCase()]??null,exports.isCompositeId=t=>!e.isMissing(t)&&t.startsWith(n),exports.isCoreError=e=>e instanceof l,exports.isCursorEmpty=({cursor:t,ignoreStepIndex:r})=>!!e.isMissing(t)||Object.keys(t?.remote??{}).reduce(((o,s)=>{const n=t?.remote?.[s];return(e.isMissing(r)||s!==r.toString())&&(o=o&&e.isMissing(n.pageNumber)&&e.isMissing(n.position)&&e.isMissing(n.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!s[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify(I(t))),exports.updateCursor=({cursor:t,stepIndex:r,pageNumber:o,providerPageCursor:s,position:n})=>{const a={pageNumber:o??void 0,providerPageCursor:s??void 0,position:n??void 0},i=e.isMissing(o)&&e.isMissing(s)&&e.isMissing(n);return e.isMissing(t)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete t.remote[r],t):{...t,remote:{...t.remote,[r]:a}}};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { ILogger, Log, LogError, LogLevel } from '@stackone/logger';
|
|
2
1
|
export type { Account } from './accounts/types';
|
|
3
2
|
export { Block, BlockContext, BlockIndexedRecord, FieldConfig, } from './blocks/types';
|
|
4
3
|
export { getCategoryDetails, isValidCategory } from './categories';
|