@stackone/core 1.41.0 → 1.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.mjs CHANGED
@@ -1 +1 @@
1
- import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as n,getCountrySubDivisionsByAlpha2Code as o,getCountryCodeByCountryName as s,getCountryCodeByAlpha3Code as a,getCountryCodeByAlpha2Code as i,getCountryAlpha2CodeByCountryCode as u,getCountryAlpha2CodeByCountryName as c,getCountryAlpha2CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as d,getCountryAlpha3CodeByCountryName as p,getCountryAlpha3CodeByAlpha2Code as m,getCountryNameByCountryCode as y,getCountryNameByAlpha2Code as b,getCountryNameByAlpha3Code as g,getCountryNameByCountryName as f,getCountryCodeByCountryCode as _,getCountryAlpha3CodeByAlpha3Code as h,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as F,safeParseToBoolean as j,safeParseToNumber as E,safeParseToString as w,encodeToBase64 as x,decodeFromBase64 as A,getContentHash as T}from"@stackone/utils";import{z as K}from"zod";import{evaluate as C,safeEvaluateRecord as O}from"@stackone/expressions";import{RequestParameterLocations as U,HttpMethods as M,RequestClientFactory as P,parseRequestParameters as R,createAuthorizationHeaders as D}from"@stackone/transport";const I=K.object({stepsDataToGroup:K.array(K.string()),isSingleRecord:K.boolean().optional()}),N=K.object({data:K.unknown()}),$=(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}),{}),L=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},o={},s=[],a={...e};for(const r of t){const{error:t,value:i}=q(n,e.id,r);t?s.push(t):r.isUnified?a[r.targetFieldKey]=i:o[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(o).length>0?o:void 0},errors:s.length>0?s:void 0}},q=(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=C(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}},G=K.object({fields:K.object({targetFieldKey:K.string(),expression:K.string(),type:K.enum(["string","number","boolean","datetime_string","enum"]),isUnified:K.boolean().optional(),enumMapper:K.object({matcher:K.string().or(K.object({matchExpression:K.string(),value:K.string()}).array())}).optional()}).array(),dataSource:K.string()}),z=K.object({data:K.unknown()}),H=(e,t)=>{if(!t)return;const r={},n=[],o={};for(const s of e){const{error:e,value:a}=B(t,t?.id,s);e?n.push(e):s.isUnified?o[s.targetFieldKey]=a:r[s.targetFieldKey]=a}return{record:{...o,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:n.length>0?n:void 0}},B=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return J(r,t,e);case"enum":return Q(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},J=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=C(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}},Q=(S,F,j)=>{const E=J(S,F,j),w=e(E.value)?E.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:F,targetField:S.targetFieldKey}};const x=S.enumMapper.matcher;if(k(x)){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 g;case"country_name_by_alpha2code":return b;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 i;case"country_code_by_alpha3code":return a;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}})(x);if(e(k)){return{value:{value:(e(w)?k(w):null)??"unmapped_value",source_value:w}}}return{error:{message:`The built-in matcher "${x}" is not supported`,id:F,targetField:S.targetFieldKey}}}for(const e of x){const{matchExpression:t,value:r}=e;if(!0===C(t,j))return{value:{value:r,source_value:w}}}return{value:{value:"unmapped_value",source_value:w}}},W=K.object({type:K.literal("basic"),username:K.string(),password:K.string(),encoding:K.string().optional()}),Y=K.object({type:K.literal("bearer"),token:K.string()}),V=K.discriminatedUnion("type",[W,Y]),X=K.object({baseUrl:K.string(),url:K.string(),method:K.enum(M),response:K.object({collection:K.boolean().optional(),indexField:K.string().optional(),dataKey:K.string().optional()}).optional(),args:K.object({name:K.string(),value:K.unknown(),in:K.enum(U),condition:K.string().optional()}).array().optional()}),Z=K.object({data:K.unknown().optional(),raw:K.unknown().optional(),statusCode:K.number()}).optional(),ee=(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},te=K.object({fields:K.object({targetFieldKey:K.string(),type:K.string(),isUnified:K.boolean().optional()}).array().optional(),dataSource:K.string()}),re=K.object({data:K.unknown()});var ne;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ne||(ne={}));const oe=({value:e,type:t,format:r})=>{if(S(e))return null;switch(t){case ne.String:return w({value:e});case ne.Number:return E({value:e});case ne.Boolean:return j({value:e});case ne.DateTimeString:return F({value:e,format:r});default:return e}},se=e=>Object.values(ne).includes(e),ae=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;se(s)&&(r.isUnified&&e(n[o])?n[o]=oe({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=oe({value:t.unified_custom_fields?.[o],type:s})))})),{...n}},ie=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:s}=r;se(s)&&(r.isUnified&&e(n[o])?n[o]=oe({value:t[o],type:s}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=oe({value:t.unified_custom_fields?.[o],type:s})))})),{...n}};var ue;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request"}(ue||(ue={}));const ce={[ue.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=>ae(e,t))):ae(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:n}=te.parse(t),o=C(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(o)?o.map((e=>ie(e,r))):ie(o,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:te,outputSchema:re}},[ue.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 a=$(n,s,o),i=L(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=L(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}=G.parse(t),s=C(o,e);if(!n||!o||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let a;if(Array.isArray(s))a=s.map((e=>{const t=H(n,e);return r.push(...t?.errors||[]),t?.record}));else{const e=H(n,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:G,outputSchema:z}},[ue.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=P.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,o=n?n.filter((t=>!t.condition||!0===C(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?O({...t,args:o},e):{},{baseUrl:a,url:i,method:u,response:c,args:l}=X.parse(s),d=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,p=V.parse(d),m=l?R(l):{query:{},body:{},headers:{}},y=D(p),b={...m?.headers??{},...y};let g;try{g=await r.performRequest({httpClient:e.httpClient,url:`${a}${i}`,queryParams:m?.query,method:u,headers:b,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?g.data[c?.dataKey]:g.data,_=ee(f,c);return{block:e,successful:!0,output:{data:_,raw:g,statusCode:g?.status}}},inputSchema:X,outputSchema:Z}},[ue.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:n,isSingleRecord:o}=I.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:I,outputSchema:N}}},le=(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},de={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:n=ce}){const o=n?.[e]?.[`v${t}`];if(!o)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...o,fn:le(o,e)}:o}},pe={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"}},me=e=>pe[e.toLowerCase()]??null,ye=e=>!!pe[e.toLowerCase()];var be;!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"}(be||(be={}));const ge=K.object({r:K.record(K.string(),K.object({n:K.number().optional(),c:K.string().optional(),p:K.number().optional()})),v:K.number(),t:K.number()}),fe=K.object({remote:K.record(K.string(),K.object({pageNumber:K.number().optional(),providerPageCursor:K.string().optional(),position:K.number().optional()})),version:K.number(),timestamp:K.number()}),_e=e=>x(JSON.stringify(he(e))),he=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}},ve=e=>{try{if(k(e)){const t=A(e),r=JSON.parse(t),n=ge.parse(r);return ke(n)}return fe.parse(e),e}catch{return null}},ke=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}},Se=(e,t)=>{const r="string"==typeof e?ve(e):e,n="string"==typeof t?ve(t):t;if(null===r||null===n)return r===n;const{timestamp:o,...s}=r,{timestamp:a,...i}=n;return T(s)===T(i)};export{V as AUTHENTICATION_SCHEMA,be as LogLevel,ue as StepFunctionName,de as StepFunctionsFactory,Se as areCursorsEqual,ve as expandCursor,me as getCategoryDetails,ye as isValidCategory,_e as minifyCursor};
1
+ import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as n,getCountrySubDivisionsByAlpha2Code as o,getCountryCodeByCountryName as a,getCountryCodeByAlpha3Code as s,getCountryCodeByAlpha2Code as i,getCountryAlpha2CodeByCountryCode as u,getCountryAlpha2CodeByCountryName as c,getCountryAlpha2CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as d,getCountryAlpha3CodeByCountryName as p,getCountryAlpha3CodeByAlpha2Code as m,getCountryNameByCountryCode as y,getCountryNameByAlpha2Code as b,getCountryNameByAlpha3Code as g,getCountryNameByCountryName as f,getCountryCodeByCountryCode as _,getCountryAlpha3CodeByAlpha3Code as h,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as j,safeParseToBoolean as F,safeParseToNumber as x,safeParseToString as w,encodeToBase64 as E,decodeFromBase64 as A,getContentHash as T}from"@stackone/utils";import{z as C}from"zod";import{evaluate as K,safeEvaluateRecord as U}from"@stackone/expressions";import{RequestParameterLocations as O,HttpMethods as P,RequestClientFactory as N,parseRequestParameters as I,createAuthorizationHeaders as R}from"@stackone/transport";const D=C.object({stepsDataToGroup:C.array(C.string()),isSingleRecord:C.boolean().optional()}),q=C.object({data:C.unknown()}),M=(e,t,r)=>Object.entries(e).reduce(((e,[n,o])=>{const a=o?.output?.data;return Array.isArray(a)&&a.length===t?e[n]={output:{data:a[r]}}:e[n]=o,e}),{}),$=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},o={},a=[],s={...e};for(const r of t){const{error:t,value:i}=L(n,e.id,r);t?a.push(t):r.isUnified?s[r.targetFieldKey]=i:o[r.targetFieldKey]=i}return{record:{...s,unified_custom_fields:Object.keys(o).length>0?o:void 0},errors:a.length>0?a:void 0}},L=(e,t,r)=>{const{expression:n,targetFieldKey:o}=r;if(!n)return{error:{message:"Expression is empty",id:t,targetField:o}};let a;try{a=K(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:o}}}return void 0===a?{error:{message:"Expression returned no value",id:t,targetField:o}}:{value:a}},G=C.object({fields:C.object({targetFieldKey:C.string(),expression:C.string(),type:C.enum(["string","number","boolean","datetime_string","enum"]),isUnified:C.boolean().optional(),enumMapper:C.object({matcher:C.string().or(C.object({matchExpression:C.string(),value:C.string()}).array())}).optional()}).array(),dataSource:C.string()}),z=C.object({data:C.unknown()}),H=(e,t)=>{if(!t)return;const r={},n=[],o={};for(const a of e){const{error:e,value:s}=Q(t,t?.id,a);e?n.push(e):a.isUnified?o[a.targetFieldKey]=s:r[a.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:n.length>0?n:void 0}},Q=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return B(r,t,e);case"enum":return J(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 n;try{n=K(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}},J=(S,j,F)=>{const x=B(S,j,F),w=e(x.value)?x.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:j,targetField:S.targetFieldKey}};const E=S.enumMapper.matcher;if(k(E)){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 g;case"country_name_by_alpha2code":return b;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 i;case"country_code_by_alpha3code":return s;case"country_code_by_country_name":return a;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}})(E);if(e(k)){return{value:{value:(e(w)?k(w):null)??"unmapped_value",source_value:w}}}return{error:{message:`The built-in matcher "${E}" is not supported`,id:j,targetField:S.targetFieldKey}}}for(const e of E){const{matchExpression:t,value:r}=e;if(!0===K(t,F))return{value:{value:r,source_value:w}}}return{value:{value:"unmapped_value",source_value:w}}},W=C.object({type:C.literal("basic"),username:C.string().optional(),password:C.string().optional(),encoding:C.string().optional()}),Y=C.object({type:C.literal("bearer"),token:C.string()}),V=C.discriminatedUnion("type",[W,Y]),X=C.object({baseUrl:C.string(),url:C.string(),method:C.enum(P),response:C.object({indexField:C.string().optional(),dataKey:C.string().optional(),nextKey:C.string().optional()}).optional(),iterator:C.object({key:C.string(),in:C.enum(O)}),cursor:C.object({token:C.string().optional().nullable(),position:C.number().optional().nullable()}).optional(),args:C.object({name:C.string(),value:C.unknown(),in:C.enum(O),condition:C.string().optional()}).array().optional()}),Z=C.object({data:C.unknown().optional(),raw:C.unknown().optional(),statusCode:C.number(),next:C.string().optional().nullable(),position:C.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=C.object({type:C.literal("basic"),username:C.string().optional(),password:C.string().optional(),encoding:C.string().optional()}),re=C.object({type:C.literal("bearer"),token:C.string()}),ne=C.discriminatedUnion("type",[te,re]),oe=C.object({baseUrl:C.string(),url:C.string(),method:C.enum(P),response:C.object({collection:C.boolean().optional(),indexField:C.string().optional(),dataKey:C.string().optional()}).optional(),args:C.object({name:C.string(),value:C.unknown(),in:C.enum(O),condition:C.string().optional()}).array().optional()}),ae=C.object({data:C.unknown().optional(),raw:C.unknown().optional(),statusCode:C.number()}).optional(),se=(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},ie=C.object({fields:C.object({targetFieldKey:C.string(),type:C.string(),isUnified:C.boolean().optional()}).array().optional(),dataSource:C.string()}),ue=C.object({data:C.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 w({value:e});case ce.Number:return x({value:e});case ce.Boolean:return F({value:e});case ce.DateTimeString:return j({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:a}=r;de(a)&&(r.isUnified&&e(n[o])?n[o]=le({value:t[o],type:a}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:a})))})),{...n}},me=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:o,type:a}=r;de(a)&&(r.isUnified&&e(n[o])?n[o]=le({value:t[o],type:a}):n.unified_custom_fields&&e(n.unified_custom_fields?.[o])&&(n.unified_custom_fields[o]=le({value:t.unified_custom_fields?.[o],type:a})))})),{...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 be={[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}=ie.parse(t),o=K(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let a;return a=Array.isArray(o)?o.map((e=>me(e,r))):me(o,r),{block:{...e},successful:!0,output:{data:a}}},inputSchema:ie,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 a=e.result.length;o=e.result.map(((e,o)=>{const s=M(n,a,o),i=$(e,t,s);return r.push(...i.errors||[]),i.record}))}else{const a=$(e.result,t,n);o=a.record,r.push(...a.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}=G.parse(t),a=K(o,e);if(!n||!o||"disabled"===e?.debug?.custom_mappings||!a)return{block:e,successful:!0};let s;if(Array.isArray(a))s=a.map((e=>{const t=H(n,e);return r.push(...t?.errors||[]),t?.record}));else{const e=H(n,a);s=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:s},errors:Object.keys(r).length>0?r:void 0}},inputSchema:G,outputSchema:z}},[ye.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=N.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,o=n?n.filter((t=>!t.condition||!0===K(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,a=t?U({...t,args:o},e):{},{baseUrl:s,url:i,method:u,response:c,args:l}=oe.parse(a),d=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,p=ne.parse(d),m=l?I(l):{query:{},body:{},headers:{}},y=R(p),b={...m?.headers??{},...y};let g;try{g=await r.performRequest({httpClient:e.httpClient,url:`${s}${i}`,queryParams:m?.query,method:u,headers:b,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?g.data[c?.dataKey]:g.data,_=se(f,c);return{block:e,successful:!0,output:{data:_,raw:g,statusCode:g?.status}}},inputSchema:oe,outputSchema:ae}},[ye.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:n,isSingleRecord:o}=D.parse(r),a=n.reduce(((r,n)=>{const a=t.steps?.[n]?.output?.data;return a?o?{...r,[n]:{...a}}:(Object.keys(a).forEach((t=>{const o=e(r[t])?r[t]:{};r[t]={...o,[n]:{...a[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:o?a:Object.values(a)}}},inputSchema:D,outputSchema:q}},[ye.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:r})=>{const n=N.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:o}=r,a=Number(t.inputs?.page_size),s=Number.isNaN(a)?25:a,i=o?o.filter((e=>!e.condition||!0===K(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,u=r?U({...r,args:i},t):{},{baseUrl:c,url:l,method:d,response:p,iterator:m,cursor:y,args:b}=X.parse(u),g=u?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,f=V.parse(g),_=b?I(b):{query:{},body:{},headers:{}},h=R(f),v={..._?.headers??{},...h};let k=y?.token??null,j=null,F=null,x=[],w=[];const E=[];let A=s,T=y?.position??0,C=!0,O=!0;do{let e;C?C=!1:T=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}}}j=k,w=p?.dataKey?e.data[p?.dataKey]:e.data;const r=w?.slice(T,A);A-=r.length,T+=r.length,E.push(e),x=x.concat(r),F=e?.status,k=p?.nextKey?e.data[p?.nextKey]:void 0,r.length===w.length&&0===A&&(T=0,j=k),O=S(k)&&x.length<s}while(e(k)&&x.length<s&&w?.length>0);const P=ee(x,p);return{block:t,successful:!0,output:{data:P,raw:E,statusCode:F,next:O?void 0:j,position:O?void 0:T}}},inputSchema:X,outputSchema:Z}}},ge=(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=be}){const o=n?.[e]?.[`v${t}`];if(!o)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...o,fn:ge(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=C.object({r:C.record(C.string(),C.object({n:C.number().optional().nullable(),c:C.string().optional().nullable(),p:C.number().optional().nullable()})),v:C.number(),t:C.number()}),je=C.object({remote:C.record(C.string(),C.object({pageNumber:C.number().optional(),providerPageCursor:C.string().optional(),position:C.number().optional()})),version:C.number(),timestamp:C.number()}),Fe=e=>E(JSON.stringify(xe(e))),xe=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}},we=e=>{try{if(k(e)){const t=A(e),r=JSON.parse(t),n=Se.parse(r);return Ee(n)}return je.parse(e),e}catch{return null}},Ee=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}},Ae=(e,t)=>{const r="string"==typeof e?we(e):e,n="string"==typeof t?we(t):t;if(null===r||null===n)return r===n;const{timestamp:o,...a}=r,{timestamp:s,...i}=n;return T(a)===T(i)},Te=({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),Ce=({cursor:e,stepIndex:t,pageNumber:r,providerPageCursor:n,position:o})=>{const a={pageNumber:r??void 0,providerPageCursor:n??void 0,position:o??void 0},s=S(r)&&S(n)&&S(o);return S(e)?{remote:s?{}:{[t]:a},version:2,timestamp:Date.now()}:s?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}};export{ne as AUTHENTICATION_SCHEMA,ke as LogLevel,ye as StepFunctionName,fe as StepFunctionsFactory,Ae as areCursorsEqual,we as expandCursor,he as getCategoryDetails,Te as isCursorEmpty,ve as isValidCategory,Fe as minifyCursor,Ce 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()}),a=t.z.object({data:t.z.unknown()}),s=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const a=n?.output?.data;return Array.isArray(a)&&a.length===t?e[o]={output:{data:a[r]}}:e[o]=n,e}),{}),i=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},a=[],s={...e};for(const r of t){const{error:t,value:i}=u(o,e.id,r);t?a.push(t):r.isUnified?s[r.targetFieldKey]=i:n[r.targetFieldKey]=i}return{record:{...s,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:a.length>0?a:void 0}},u=(e,t,o)=>{const{expression:n,targetFieldKey:a}=o;if(!n)return{error:{message:"Expression is empty",id:t,targetField:a}};let s;try{s=r.evaluate(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:a}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:a}}:{value:s}},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 a of e){const{error:e,value:s}=p(t,t?.id,a);e?o.push(e):a.isUnified?n[a.targetFieldKey]=s:r[a.targetFieldKey]=s}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 y(r,t,e);case"enum":return m(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},y=(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}},m=(t,o,n)=>{const a=y(t,o,n),s=e.notMissing(a.value)?a.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(s)?r(s):null)??"unmapped_value",source_value:s}}}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,n))return{value:{value:o,source_value:s}}}return{value:{value:"unmapped_value",source_value:s}}},g=t.z.object({type:t.z.literal("basic"),username:t.z.string(),password:t.z.string(),encoding:t.z.string().optional()}),b=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),f=t.z.discriminatedUnion("type",[g,b]),_=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()}),h=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number()}).optional(),v=(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},C=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()}),z=t.z.object({data:t.z.unknown()});var S;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(S||(S={}));const k=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case S.String:return e.safeParseToString({value:t});case S.Number:return e.safeParseToNumber({value:t});case S.Boolean:return e.safeParseToBoolean({value:t});case S.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},F=e=>Object.values(S).includes(e),A=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:a}=r;F(a)&&(r.isUnified&&e.notMissing(o[n])?o[n]=k({value:t[n],type:a}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=k({value:t.unified_custom_fields?.[n],type:a})))})),{...o}},x=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:a}=r;F(a)&&(r.isUnified&&e.notMissing(o[n])?o[n]=k({value:t[n],type:a}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=k({value:t.unified_custom_fields?.[n],type:a})))})),{...o}};var j;exports.StepFunctionName=void 0,(j=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",j.MAP_FIELDS="map_fields",j.GROUP_DATA="group_data",j.REQUEST="request";const T={[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=>A(e,t))):A(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:n}=C.parse(t),a=r.evaluate(n,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(a)?a.map((e=>x(e,o))):x(a,o),{block:{...e},successful:!0,output:{data:s}}},inputSchema:C,outputSchema:z}},[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 a=e.result.length;n=e.result.map(((e,n)=>{const u=s(o,a,n),c=i(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const a=i(e.result,t,o);n=a.record,r.push(...a.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:a}=c.parse(t),s=r.evaluate(a,e);if(!n||!a||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let i;if(Array.isArray(s))i=s.map((e=>{const t=d(n,e);return o.push(...t?.errors||[]),t?.record}));else{const e=d(n,s);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: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:a}=t,s=a?a.filter((t=>!t.condition||!0===r.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,i=t?r.safeEvaluateRecord({...t,args:s},e):{},{baseUrl:u,url:c,method:l,response:d,args:p}=_.parse(i),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,m=f.parse(y),g=p?o.parseRequestParameters(p):{query:{},body:{},headers:{}},b=o.createAuthorizationHeaders(m),h={...g?.headers??{},...b};let C;try{C=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 z=d?.dataKey?C.data[d?.dataKey]:C.data,S=v(z,d);return{block:e,successful:!0,output:{data:S,raw:C,statusCode:C?.status}}},inputSchema:_,outputSchema:h}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:a}=n.parse(r),s=o.reduce(((r,o)=>{const n=t.steps?.[o]?.output?.data;return n?a?{...r,[o]:{...n}}:(Object.keys(n).forEach((t=>{const a=e.notMissing(r[t])?r[t]:{};r[t]={...a,[o]:{...n[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:a?s:Object.values(s)}}},inputSchema:n,outputSchema:a}}},E=(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},N={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=T}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:E(n,e)}:n}},B={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 w;exports.LogLevel=void 0,(w=exports.LogLevel||(exports.LogLevel={}))[w.Trace=0]="Trace",w[w.Debug=1]="Debug",w[w.Info=2]="Info",w[w.Warning=3]="Warning",w[w.Error=4]="Error";const M=t.z.object({r:t.z.record(t.z.string(),t.z.object({n:t.z.number().optional(),c:t.z.string().optional(),p:t.z.number().optional()})),v:t.z.number(),t:t.z.number()}),K=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()}),O=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}},D=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),n=M.parse(o);return P(n)}return K.parse(t),t}catch{return null}},P=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}};exports.AUTHENTICATION_SCHEMA=f,exports.StepFunctionsFactory=N,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?D(t):t,n="string"==typeof r?D(r):r;if(null===o||null===n)return o===n;const{timestamp:a,...s}=o,{timestamp:i,...u}=n;return e.getContentHash(s)===e.getContentHash(u)},exports.expandCursor=D,exports.getCategoryDetails=e=>B[e.toLowerCase()]??null,exports.isValidCategory=e=>!!B[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify(O(t)));
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()}),a=(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}),{}),i=(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}=u(o,e.id,r);t?s.push(t):r.isUnified?a[r.targetFieldKey]=i:n[r.targetFieldKey]=i}return{record:{...a,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 a;try{a=r.evaluate(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:s}}}return void 0===a?{error:{message:"Expression returned no value",id:t,targetField:s}}:{value:a}},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:a}=p(t,t?.id,s);e?o.push(e):s.isUnified?n[s.targetFieldKey]=a:r[s.targetFieldKey]=a}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 y(r,t,e);case"enum":return g(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},y=(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}},g=(t,o,n)=>{const s=y(t,o,n),a=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 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,n))return{value:{value:o,source_value:a}}}return{value:{value:"unmapped_value",source_value:a}}},m=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",[m,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(),z=(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},v=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",[v,C]),k=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()}),x=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number()}).optional(),F=(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},A=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()}),j=t.z.object({data:t.z.unknown()});var N;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(N||(N={}));const E=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case N.String:return e.safeParseToString({value:t});case N.Number:return e.safeParseToNumber({value:t});case N.Boolean:return e.safeParseToBoolean({value:t});case N.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},T=e=>Object.values(N).includes(e),M=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;T(s)&&(r.isUnified&&e.notMissing(o[n])?o[n]=E({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=E({value:t.unified_custom_fields?.[n],type:s})))})),{...o}},w=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;T(s)&&(r.isUnified&&e.notMissing(o[n])?o[n]=E({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=E({value:t.unified_custom_fields?.[n],type:s})))})),{...o}};var P;exports.StepFunctionName=void 0,(P=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",P.MAP_FIELDS="map_fields",P.GROUP_DATA="group_data",P.REQUEST="request",P.PAGINATED_REQUEST="paginated_request";const B={[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=>M(e,t))):M(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:n}=A.parse(t),s=r.evaluate(n,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let a;return a=Array.isArray(s)?s.map((e=>w(e,o))):w(s,o),{block:{...e},successful:!0,output:{data:a}}},inputSchema:A,outputSchema:j}},[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=a(o,s,n),c=i(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const s=i(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),a=r.evaluate(s,e);if(!n||!s||"disabled"===e?.debug?.custom_mappings||!a)return{block:e,successful:!0};let i;if(Array.isArray(a))i=a.map((e=>{const t=d(n,e);return o.push(...t?.errors||[]),t?.record}));else{const e=d(n,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: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,a=s?s.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):{},{baseUrl:u,url:c,method:l,response:d,args:p}=k.parse(i),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,g=S.parse(y),m=p?o.parseRequestParameters(p):{query:{},body:{},headers:{}},b=o.createAuthorizationHeaders(g),h={...m?.headers??{},...b};let f;try{f=await n.performRequest({httpClient:e.httpClient,url:`${u}${c}`,queryParams:m?.query,method:l,headers:h,body:m?.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,z=F(_,d);return{block:e,successful:!0,output:{data:z,raw:f,statusCode:f?.status}}},inputSchema:k,outputSchema:x}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=n.parse(r),a=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?a:Object.values(a)}}},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:a}=n,i=Number(t.inputs?.page_size),u=Number.isNaN(i)?25:i,c=a?a.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:y,response:g,iterator:m,cursor:b,args:_}=f.parse(l),v=l?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,C=h.parse(v),S=_?o.parseRequestParameters(_):{query:{},body:{},headers:{}},k=o.createAuthorizationHeaders(C),x={...S?.headers??{},...k};let F=b?.token??null,A=null,j=null,N=[],E=[];const T=[];let M=u,w=b?.position??0,P=!0,B=!0;do{let r;P?P=!1:w=0,null!==F&&("query"===m.in?S.query[m.key]=F.toString():"body"===m.in&&(S.body[m.key]=F));try{r=await s.performRequest({httpClient:t.httpClient,url:`${d}${p}`,queryParams:S?.query,method:y,headers:x,body:S?.body})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500}}}A=F,E=g?.dataKey?r.data[g?.dataKey]:r.data;const o=E?.slice(w,M);M-=o.length,w+=o.length,T.push(r),N=N.concat(o),j=r?.status,F=g?.nextKey?r.data[g?.nextKey]:void 0,o.length===E.length&&0===M&&(w=0,A=F),B=e.isMissing(F)&&N.length<u}while(e.notMissing(F)&&N.length<u&&E?.length>0);const q=z(N,g);return{block:t,successful:!0,output:{data:q,raw:T,statusCode:j,next:B?void 0:A,position:B?void 0:w}}},inputSchema:f,outputSchema:_}}},q=(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},K={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=B}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:q(n,e)}:n}},R={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 D;exports.LogLevel=void 0,(D=exports.LogLevel||(exports.LogLevel={}))[D.Trace=0]="Trace",D[D.Debug=1]="Debug",D[D.Info=2]="Info",D[D.Warning=3]="Warning",D[D.Error=4]="Error";const U=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()}),O=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}},L=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),n=U.parse(o);return H(n)}return O.parse(t),t}catch{return null}},H=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}};exports.AUTHENTICATION_SCHEMA=S,exports.StepFunctionsFactory=K,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?L(t):t,n="string"==typeof r?L(r):r;if(null===o||null===n)return o===n;const{timestamp:s,...a}=o,{timestamp:i,...u}=n;return e.getContentHash(a)===e.getContentHash(u)},exports.expandCursor=L,exports.getCategoryDetails=e=>R[e.toLowerCase()]??null,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=>!!R[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify(I(t))),exports.updateCursor=({cursor:t,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const a={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},i=e.isMissing(o)&&e.isMissing(n)&&e.isMissing(s);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}}};
@@ -51,9 +51,14 @@ export type OperationResponse = {
51
51
  export type AuthenticationField = {
52
52
  key: string;
53
53
  label: string;
54
- type: 'text' | 'password';
55
- required?: boolean;
56
- secret?: boolean;
54
+ type: 'text' | 'password' | 'select';
55
+ options?: {
56
+ value: string;
57
+ label: string;
58
+ }[];
59
+ required: boolean;
60
+ secret: boolean;
61
+ readOnly: boolean;
57
62
  placeholder?: string;
58
63
  description?: string;
59
64
  tooltip?: string;
@@ -2,3 +2,14 @@ import { Cursor } from './types';
2
2
  export declare const minifyCursor: (cursor: Cursor) => string;
3
3
  export declare const expandCursor: (minifiedCursor: unknown) => Cursor | null;
4
4
  export declare const areCursorsEqual: (first: string | Cursor, second: string | Cursor) => boolean;
5
+ export declare const isCursorEmpty: ({ cursor, ignoreStepIndex, }: {
6
+ cursor?: Cursor | null;
7
+ ignoreStepIndex?: number;
8
+ }) => boolean;
9
+ export declare const updateCursor: ({ cursor, stepIndex, pageNumber, providerPageCursor, position, }: {
10
+ cursor?: Cursor | null;
11
+ stepIndex: number;
12
+ pageNumber?: number | null;
13
+ providerPageCursor?: string | null;
14
+ position?: number | null;
15
+ }) => Cursor;
@@ -1,33 +1,33 @@
1
1
  import { z } from 'zod';
2
2
  export declare const MINIFIED_CURSOR_SCHEMA: z.ZodObject<{
3
3
  r: z.ZodRecord<z.ZodString, z.ZodObject<{
4
- n: z.ZodOptional<z.ZodNumber>;
5
- c: z.ZodOptional<z.ZodString>;
6
- p: z.ZodOptional<z.ZodNumber>;
4
+ n: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
5
+ c: z.ZodNullable<z.ZodOptional<z.ZodString>>;
6
+ p: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
7
7
  }, "strip", z.ZodTypeAny, {
8
- n?: number | undefined;
9
- c?: string | undefined;
10
- p?: number | undefined;
8
+ n?: number | null | undefined;
9
+ c?: string | null | undefined;
10
+ p?: number | null | undefined;
11
11
  }, {
12
- n?: number | undefined;
13
- c?: string | undefined;
14
- p?: number | undefined;
12
+ n?: number | null | undefined;
13
+ c?: string | null | undefined;
14
+ p?: number | null | undefined;
15
15
  }>>;
16
16
  v: z.ZodNumber;
17
17
  t: z.ZodNumber;
18
18
  }, "strip", z.ZodTypeAny, {
19
19
  r: Record<string, {
20
- n?: number | undefined;
21
- c?: string | undefined;
22
- p?: number | undefined;
20
+ n?: number | null | undefined;
21
+ c?: string | null | undefined;
22
+ p?: number | null | undefined;
23
23
  }>;
24
24
  v: number;
25
25
  t: number;
26
26
  }, {
27
27
  r: Record<string, {
28
- n?: number | undefined;
29
- c?: string | undefined;
30
- p?: number | undefined;
28
+ n?: number | null | undefined;
29
+ c?: string | null | undefined;
30
+ p?: number | null | undefined;
31
31
  }>;
32
32
  v: number;
33
33
  t: number;
@@ -1,12 +1,12 @@
1
1
  type Position = {
2
- pageNumber?: number;
3
- providerPageCursor?: string;
4
- position?: number;
2
+ pageNumber?: number | null;
3
+ providerPageCursor?: string | null;
4
+ position?: number | null;
5
5
  };
6
6
  type MinifiedPosition = {
7
- n?: number;
8
- c?: string;
9
- p?: number;
7
+ n?: number | null;
8
+ c?: string | null;
9
+ p?: number | null;
10
10
  };
11
11
  export type Cursor = {
12
12
  remote: Record<number, Position>;
@@ -11,4 +11,4 @@ export { AUTHENTICATION_SCHEMA } from './stepFunctions/request/schemas';
11
11
  export { ILogger, LogError, LogLevel, Log } from './logger/types';
12
12
  export type { Account } from './accounts/types';
13
13
  export type { Cursor } from './cursor/types';
14
- export { expandCursor, minifyCursor, areCursorsEqual } from './cursor';
14
+ export { expandCursor, minifyCursor, areCursorsEqual, isCursorEmpty, updateCursor } from './cursor';
@@ -0,0 +1,2 @@
1
+ import type { StepFunction } from '../types';
2
+ export declare const paginatedRequestStepFunction: StepFunction;
@@ -0,0 +1,145 @@
1
+ import { z } from 'zod';
2
+ export declare const AUTHENTICATION_SCHEMA: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3
+ type: z.ZodLiteral<"basic">;
4
+ username: z.ZodOptional<z.ZodString>;
5
+ password: z.ZodOptional<z.ZodString>;
6
+ encoding: z.ZodOptional<z.ZodString>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ type: "basic";
9
+ username?: string | undefined;
10
+ password?: string | undefined;
11
+ encoding?: string | undefined;
12
+ }, {
13
+ type: "basic";
14
+ username?: string | undefined;
15
+ password?: string | undefined;
16
+ encoding?: string | undefined;
17
+ }>, z.ZodObject<{
18
+ type: z.ZodLiteral<"bearer">;
19
+ token: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ type: "bearer";
22
+ token: string;
23
+ }, {
24
+ type: "bearer";
25
+ token: string;
26
+ }>]>;
27
+ export declare const PAGINATED_REQUEST_INPUT_PARAMS: z.ZodObject<{
28
+ baseUrl: z.ZodString;
29
+ url: z.ZodString;
30
+ method: z.ZodEnum<["get", "post", "put", "delete", "patch"]>;
31
+ response: z.ZodOptional<z.ZodObject<{
32
+ indexField: z.ZodOptional<z.ZodString>;
33
+ dataKey: z.ZodOptional<z.ZodString>;
34
+ nextKey: z.ZodOptional<z.ZodString>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ indexField?: string | undefined;
37
+ dataKey?: string | undefined;
38
+ nextKey?: string | undefined;
39
+ }, {
40
+ indexField?: string | undefined;
41
+ dataKey?: string | undefined;
42
+ nextKey?: string | undefined;
43
+ }>>;
44
+ iterator: z.ZodObject<{
45
+ key: z.ZodString;
46
+ in: z.ZodEnum<["query", "body", "headers"]>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ key: string;
49
+ in: "query" | "body" | "headers";
50
+ }, {
51
+ key: string;
52
+ in: "query" | "body" | "headers";
53
+ }>;
54
+ cursor: z.ZodOptional<z.ZodObject<{
55
+ token: z.ZodNullable<z.ZodOptional<z.ZodString>>;
56
+ position: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ token?: string | null | undefined;
59
+ position?: number | null | undefined;
60
+ }, {
61
+ token?: string | null | undefined;
62
+ position?: number | null | undefined;
63
+ }>>;
64
+ args: z.ZodOptional<z.ZodArray<z.ZodObject<{
65
+ name: z.ZodString;
66
+ value: z.ZodUnknown;
67
+ in: z.ZodEnum<["query", "body", "headers"]>;
68
+ condition: z.ZodOptional<z.ZodString>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ in: "query" | "body" | "headers";
71
+ name: string;
72
+ value?: unknown;
73
+ condition?: string | undefined;
74
+ }, {
75
+ in: "query" | "body" | "headers";
76
+ name: string;
77
+ value?: unknown;
78
+ condition?: string | undefined;
79
+ }>, "many">>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ baseUrl: string;
82
+ url: string;
83
+ method: "get" | "post" | "put" | "delete" | "patch";
84
+ iterator: {
85
+ key: string;
86
+ in: "query" | "body" | "headers";
87
+ };
88
+ response?: {
89
+ indexField?: string | undefined;
90
+ dataKey?: string | undefined;
91
+ nextKey?: string | undefined;
92
+ } | undefined;
93
+ cursor?: {
94
+ token?: string | null | undefined;
95
+ position?: number | null | undefined;
96
+ } | undefined;
97
+ args?: {
98
+ in: "query" | "body" | "headers";
99
+ name: string;
100
+ value?: unknown;
101
+ condition?: string | undefined;
102
+ }[] | undefined;
103
+ }, {
104
+ baseUrl: string;
105
+ url: string;
106
+ method: "get" | "post" | "put" | "delete" | "patch";
107
+ iterator: {
108
+ key: string;
109
+ in: "query" | "body" | "headers";
110
+ };
111
+ response?: {
112
+ indexField?: string | undefined;
113
+ dataKey?: string | undefined;
114
+ nextKey?: string | undefined;
115
+ } | undefined;
116
+ cursor?: {
117
+ token?: string | null | undefined;
118
+ position?: number | null | undefined;
119
+ } | undefined;
120
+ args?: {
121
+ in: "query" | "body" | "headers";
122
+ name: string;
123
+ value?: unknown;
124
+ condition?: string | undefined;
125
+ }[] | undefined;
126
+ }>;
127
+ export declare const PAGINATED_REQUEST_OUTPUT: z.ZodOptional<z.ZodObject<{
128
+ data: z.ZodOptional<z.ZodUnknown>;
129
+ raw: z.ZodOptional<z.ZodUnknown>;
130
+ statusCode: z.ZodNumber;
131
+ next: z.ZodNullable<z.ZodOptional<z.ZodString>>;
132
+ position: z.ZodOptional<z.ZodNumber>;
133
+ }, "strip", z.ZodTypeAny, {
134
+ statusCode: number;
135
+ position?: number | undefined;
136
+ data?: unknown;
137
+ raw?: unknown;
138
+ next?: string | null | undefined;
139
+ }, {
140
+ statusCode: number;
141
+ position?: number | undefined;
142
+ data?: unknown;
143
+ raw?: unknown;
144
+ next?: string | null | undefined;
145
+ }>>;
@@ -1,18 +1,18 @@
1
1
  import { z } from 'zod';
2
2
  export declare const AUTHENTICATION_SCHEMA: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3
3
  type: z.ZodLiteral<"basic">;
4
- username: z.ZodString;
5
- password: z.ZodString;
4
+ username: z.ZodOptional<z.ZodString>;
5
+ password: z.ZodOptional<z.ZodString>;
6
6
  encoding: z.ZodOptional<z.ZodString>;
7
7
  }, "strip", z.ZodTypeAny, {
8
8
  type: "basic";
9
- username: string;
10
- password: string;
9
+ username?: string | undefined;
10
+ password?: string | undefined;
11
11
  encoding?: string | undefined;
12
12
  }, {
13
13
  type: "basic";
14
- username: string;
15
- password: string;
14
+ username?: string | undefined;
15
+ password?: string | undefined;
16
16
  encoding?: string | undefined;
17
17
  }>, z.ZodObject<{
18
18
  type: z.ZodLiteral<"bearer">;
@@ -2,7 +2,8 @@ export declare enum StepFunctionName {
2
2
  TYPECAST = "typecast",
3
3
  MAP_FIELDS = "map_fields",
4
4
  GROUP_DATA = "group_data",
5
- REQUEST = "request"
5
+ REQUEST = "request",
6
+ PAGINATED_REQUEST = "paginated_request"
6
7
  }
7
8
  export declare const stepFunctions: {
8
9
  typecast: {
@@ -250,4 +251,128 @@ export declare const stepFunctions: {
250
251
  }>;
251
252
  };
252
253
  };
254
+ paginated_request: {
255
+ v1: {
256
+ fn: import("./types").StepFunction;
257
+ inputSchema: import("zod").ZodObject<{
258
+ baseUrl: import("zod").ZodString;
259
+ url: import("zod").ZodString;
260
+ method: import("zod").ZodEnum<["get", "post", "put", "delete", "patch"]>;
261
+ response: import("zod").ZodOptional<import("zod").ZodObject<{
262
+ indexField: import("zod").ZodOptional<import("zod").ZodString>;
263
+ dataKey: import("zod").ZodOptional<import("zod").ZodString>;
264
+ nextKey: import("zod").ZodOptional<import("zod").ZodString>;
265
+ }, "strip", import("zod").ZodTypeAny, {
266
+ indexField?: string | undefined;
267
+ dataKey?: string | undefined;
268
+ nextKey?: string | undefined;
269
+ }, {
270
+ indexField?: string | undefined;
271
+ dataKey?: string | undefined;
272
+ nextKey?: string | undefined;
273
+ }>>;
274
+ iterator: import("zod").ZodObject<{
275
+ key: import("zod").ZodString;
276
+ in: import("zod").ZodEnum<["query", "body", "headers"]>;
277
+ }, "strip", import("zod").ZodTypeAny, {
278
+ in: "query" | "body" | "headers";
279
+ key: string;
280
+ }, {
281
+ in: "query" | "body" | "headers";
282
+ key: string;
283
+ }>;
284
+ cursor: import("zod").ZodOptional<import("zod").ZodObject<{
285
+ token: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodString>>;
286
+ position: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodNumber>>;
287
+ }, "strip", import("zod").ZodTypeAny, {
288
+ token?: string | null | undefined;
289
+ position?: number | null | undefined;
290
+ }, {
291
+ token?: string | null | undefined;
292
+ position?: number | null | undefined;
293
+ }>>;
294
+ args: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
295
+ name: import("zod").ZodString;
296
+ value: import("zod").ZodUnknown;
297
+ in: import("zod").ZodEnum<["query", "body", "headers"]>;
298
+ condition: import("zod").ZodOptional<import("zod").ZodString>;
299
+ }, "strip", import("zod").ZodTypeAny, {
300
+ name: string;
301
+ in: "query" | "body" | "headers";
302
+ value?: unknown;
303
+ condition?: string | undefined;
304
+ }, {
305
+ name: string;
306
+ in: "query" | "body" | "headers";
307
+ value?: unknown;
308
+ condition?: string | undefined;
309
+ }>, "many">>;
310
+ }, "strip", import("zod").ZodTypeAny, {
311
+ baseUrl: string;
312
+ url: string;
313
+ method: "get" | "post" | "put" | "delete" | "patch";
314
+ iterator: {
315
+ in: "query" | "body" | "headers";
316
+ key: string;
317
+ };
318
+ response?: {
319
+ indexField?: string | undefined;
320
+ dataKey?: string | undefined;
321
+ nextKey?: string | undefined;
322
+ } | undefined;
323
+ args?: {
324
+ name: string;
325
+ in: "query" | "body" | "headers";
326
+ value?: unknown;
327
+ condition?: string | undefined;
328
+ }[] | undefined;
329
+ cursor?: {
330
+ token?: string | null | undefined;
331
+ position?: number | null | undefined;
332
+ } | undefined;
333
+ }, {
334
+ baseUrl: string;
335
+ url: string;
336
+ method: "get" | "post" | "put" | "delete" | "patch";
337
+ iterator: {
338
+ in: "query" | "body" | "headers";
339
+ key: string;
340
+ };
341
+ response?: {
342
+ indexField?: string | undefined;
343
+ dataKey?: string | undefined;
344
+ nextKey?: string | undefined;
345
+ } | undefined;
346
+ args?: {
347
+ name: string;
348
+ in: "query" | "body" | "headers";
349
+ value?: unknown;
350
+ condition?: string | undefined;
351
+ }[] | undefined;
352
+ cursor?: {
353
+ token?: string | null | undefined;
354
+ position?: number | null | undefined;
355
+ } | undefined;
356
+ }>;
357
+ outputSchema: import("zod").ZodOptional<import("zod").ZodObject<{
358
+ data: import("zod").ZodOptional<import("zod").ZodUnknown>;
359
+ raw: import("zod").ZodOptional<import("zod").ZodUnknown>;
360
+ statusCode: import("zod").ZodNumber;
361
+ next: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodString>>;
362
+ position: import("zod").ZodOptional<import("zod").ZodNumber>;
363
+ }, "strip", import("zod").ZodTypeAny, {
364
+ statusCode: number;
365
+ data?: unknown;
366
+ raw?: unknown;
367
+ position?: number | undefined;
368
+ next?: string | null | undefined;
369
+ }, {
370
+ statusCode: number;
371
+ data?: unknown;
372
+ raw?: unknown;
373
+ position?: number | undefined;
374
+ next?: string | null | undefined;
375
+ }>>;
376
+ };
377
+ };
253
378
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.41.0",
3
+ "version": "1.42.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",