@stackone/core 1.21.0 → 1.22.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{evaluate as e}from"@stackone/expressions";import{isDate as r,isString as t,isBoolean as s,isNumber as n,isObject as i,isMissing as o,notMissing as u}from"@stackone/utils";import*as l from"date-fns";var a;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.REQUEST="request",e.GROUP_RESULTS="group_results"}(a||(a={}));const c=async({block:e})=>{const r=e?.fieldConfigs,t=[],s=e.steps;if(!r||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successfull:!0};let n;if(Array.isArray(e.result)){const i=e.result.length;n=e.result.map(((e,n)=>{const o=d(s,i,n),u=y(e,r,o);return t.push(...u.errors||[]),u.record}))}else{const i=y(e.result,r,s);n=i.record,t.push(...i.errors||[])}return{block:{...e,result:n},successfull:!0,errors:Object.keys(t).length>0?t:void 0}},d=(e,r,t)=>Object.entries(e).reduce(((e,[s,n])=>{const i=n?.output?.data;return Array.isArray(i)&&i.length===r?e[s]={output:{data:i[t]}}:e[s]=n,e}),{}),y=(e,r,t)=>{if(!e||!t)return{record:e};const s={unified:{...e},..."object"==typeof t?t:{}},n={},i=[],o={...e};for(const t of r){const{error:r,value:u}=f(s,e.id,t);r?i.push(r):t.isUnified?o[t.targetFieldKey]=u:n[t.targetFieldKey]=u}return{record:{...o,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:i.length>0?i:void 0}},f=(r,t,s)=>{const{expression:n,targetFieldKey:i}=s;if(!n)return{error:{message:"Expression is empty",id:t,targetField:i}};let o;try{o=e(n,r)}catch(e){return{error:{message:"Invalid expression",id:t,targetField:i}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:i}}:{value:o}},m="yyyy-MM-dd",g=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],p=({value:e})=>{const r=l.parseISO(e);if(l.isValid(r))return r;const t=new Date;for(const r of g){const s=l.parse(e,r,t);if(l.isValid(s))return s.setUTCHours(0,0,0,0),s}return null},v=({value:e,format:s=m})=>{const n=(({value:e,format:s=m})=>{if(r(e))return e;if(!t(e))return null;try{const r=l.parse(e,s,new Date);return l.isValid(r)?r:p({value:e})}catch(e){return null}})({value:e,format:s});return n?n.toISOString():null};var M;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(M||(M={}));const S=({value:e,type:u,format:l})=>{if(o(e))return null;switch(u){case M.String:return(({value:e})=>t(e)?e:r(e)?e.toISOString():i(e)?JSON.stringify(e):String(e))({value:e});case M.Number:return(({value:e})=>{if(n(e))return e;if(r(e))return null;const t=Number(e);return isNaN(t)?null:t})({value:e});case M.Boolean:return(({value:e})=>s(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case M.DateTimeString:return v({value:e,format:l});default:return e}},k=async({block:e})=>{const r=e?.fieldConfigs;if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successfull:!0};let t;return t=Array.isArray(e.result)?e.result.map((e=>b(e,r))):b(e.result,r),{block:{...e,result:t},successfull:!0}},b=(e,r)=>{const t={...e};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;(e=>Object.values(M).includes(e))(n)&&(r.isUnified&&u(t[s])?t[s]=S({value:e[s],type:n}):t.unified_custom_fields&&u(t.unified_custom_fields?.[s])&&(t.unified_custom_fields[s]=S({value:e.unified_custom_fields?.[s],type:n})))})),{...t}},_={build({functionName:e}){switch(e){case a.TYPECAST:return k;case a.MAP_FIELDS:return c;default:throw new Error(`Unknown step function: ${e}`)}}},h={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=e=>h[e.toLowerCase()]??null,E=e=>!!h[e.toLowerCase()];export{a as StepFunctionName,_ as StepFunctionsFactory,A as getCategoryDetails,E as isValidCategory};
1
+ import{evaluate as e}from"@stackone/expressions";import{z as t}from"zod";import{isDate as r,isString as s,isBoolean as n,isNumber as i,isObject as o,isMissing as a,notMissing as u}from"@stackone/utils";import*as l from"date-fns";const c=(e,t,r)=>Object.entries(e).reduce(((e,[s,n])=>{const i=n?.output?.data;return Array.isArray(i)&&i.length===t?e[s]={output:{data:i[r]}}:e[s]=n,e}),{}),d=(e,t,r)=>{if(!e||!r)return{record:e};const s={unified:{...e},..."object"==typeof r?r:{}},n={},i=[],o={...e};for(const r of t){const{error:t,value:a}=f(s,e.id,r);t?i.push(t):r.isUnified?o[r.targetFieldKey]=a:n[r.targetFieldKey]=a}return{record:{...o,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:i.length>0?i:void 0}},f=(t,r,s)=>{const{expression:n,targetFieldKey:i}=s;if(!n)return{error:{message:"Expression is empty",id:r,targetField:i}};let o;try{o=e(n,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:i}}}return void 0===o?{error:{message:"Expression returned no value",id:r,targetField:i}}:{value:o}},y=t.object({fields:t.object({expression:t.string(),targetFieldKey:t.string(),type:t.string(),isUnified:t.boolean().optional()}).array(),dataSource:t.string()}),p=t.object({data:t.unknown()}),m=(e,t)=>{if(!t)return;const r={},s=[],n={};for(const i of e){const{error:e,value:o}=g(t,t?.id,i);e?s.push(e):i.isUnified?n[i.targetFieldKey]=o:r[i.targetFieldKey]=o}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:s.length>0?s:void 0}},g=(t,r,s)=>{const{expression:n,targetFieldKey:i}=s;if(!n)return{error:{message:"Expression is empty",id:r,targetField:i}};let o;try{o=e(n,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:i}}}return void 0===o?{error:{message:"Expression returned no value",id:r,targetField:i}}:{value:o}},b=t.object({fields:t.object({targetFieldKey:t.string(),type:t.string(),isUnified:t.boolean().optional()}).array().optional(),dataSource:t.string()}),v=t.object({data:t.unknown()}),h="yyyy-MM-dd",k=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],S=({value:e})=>{const t=l.parseISO(e);if(l.isValid(t))return t;const r=new Date;for(const t of k){const s=l.parse(e,t,r);if(l.isValid(s))return s.setUTCHours(0,0,0,0),s}return null},_=({value:e,format:t=h})=>{const n=(({value:e,format:t=h})=>{if(r(e))return e;if(!s(e))return null;try{const r=l.parse(e,t,new Date);return l.isValid(r)?r:S({value:e})}catch(e){return null}})({value:e,format:t});return n?n.toISOString():null};var M;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(M||(M={}));const F=({value:e,type:t,format:u})=>{if(a(e))return null;switch(t){case M.String:return(({value:e})=>s(e)?e:r(e)?e.toISOString():o(e)?JSON.stringify(e):String(e))({value:e});case M.Number:return(({value:e})=>{if(i(e))return e;if(r(e))return null;const t=Number(e);return isNaN(t)?null:t})({value:e});case M.Boolean:return(({value:e})=>n(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case M.DateTimeString:return _({value:e,format:u});default:return e}},A=e=>Object.values(M).includes(e),j=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:s,type:n}=t;A(n)&&(t.isUnified&&u(r[s])?r[s]=F({value:e[s],type:n}):r.unified_custom_fields&&u(r.unified_custom_fields?.[s])&&(r.unified_custom_fields[s]=F({value:e.unified_custom_fields?.[s],type:n})))})),{...r}},x=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:s,type:n}=t;A(n)&&(t.isUnified&&u(r[s])?r[s]=F({value:e[s],type:n}):r.unified_custom_fields&&u(r.unified_custom_fields?.[s])&&(r.unified_custom_fields[s]=F({value:e.unified_custom_fields?.[s],type:n})))})),{...r}};var w;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields"}(w||(w={}));const E={[w.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=>j(e,t))):j(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:t,params:r})=>{const{fields:s,dataSource:n}=b.parse(r),i=e(n,t);if(!s||"disabled"===t?.debug?.custom_mappings)return{block:t,successful:!0};let o;return o=Array.isArray(i)?i.map((e=>x(e,s))):x(i,s),{block:{...t},successful:!0,output:{data:o}}},inputSchema:b,outputSchema:v}},[w.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],s=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const i=e.result.length;n=e.result.map(((e,n)=>{const o=c(s,i,n),a=d(e,t,o);return r.push(...a.errors||[]),a.record}))}else{const i=d(e.result,t,s);n=i.record,r.push(...i.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:t,params:r})=>{const s=[],{fields:n,dataSource:i}=y.parse(r),o=e(i,t);if(!n||!i||"disabled"===t?.debug?.custom_mappings||!o)return{block:t,successful:!0};let a;if(Array.isArray(o))a=o.map((e=>{const t=m(n,e);return s.push(...t?.errors||[]),t?.record}));else{const e=m(n,o);a=e?.record,s.push(...e?.errors||[])}return{block:{...t},successful:!0,output:{data:a},errors:Object.keys(s).length>0?s:void 0}},inputSchema:y,outputSchema:p}}},O=(e,t)=>async({block:r,params:s})=>{try{e.inputSchema&&e.inputSchema.parse(s)}catch(e){return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const n=await e.fn({block:r,params:s});try{e.outputSchema&&e.outputSchema.parse(n.output)}catch(e){return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return n},I={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:s=E}){const n=s?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:O(n,e)}:n}},K={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"}},C=e=>K[e.toLowerCase()]??null,T=e=>!!K[e.toLowerCase()];export{w as StepFunctionName,I as StepFunctionsFactory,C as getCategoryDetails,T as isValidCategory};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@stackone/expressions"),t=require("@stackone/utils");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s,n=r(require("date-fns"));exports.StepFunctionName=void 0,(s=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",s.MAP_FIELDS="map_fields",s.REQUEST="request",s.GROUP_RESULTS="group_results";const i=async({block:e})=>{const t=e?.fieldConfigs,r=[],s=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successfull:!0};let n;if(Array.isArray(e.result)){const i=e.result.length;n=e.result.map(((e,n)=>{const a=o(s,i,n),l=u(e,t,a);return r.push(...l.errors||[]),l.record}))}else{const i=u(e.result,t,s);n=i.record,r.push(...i.errors||[])}return{block:{...e,result:n},successfull:!0,errors:Object.keys(r).length>0?r:void 0}},o=(e,t,r)=>Object.entries(e).reduce(((e,[s,n])=>{const i=n?.output?.data;return Array.isArray(i)&&i.length===t?e[s]={output:{data:i[r]}}:e[s]=n,e}),{}),u=(e,t,r)=>{if(!e||!r)return{record:e};const s={unified:{...e},..."object"==typeof r?r:{}},n={},i=[],o={...e};for(const r of t){const{error:t,value:u}=a(s,e.id,r);t?i.push(t):r.isUnified?o[r.targetFieldKey]=u:n[r.targetFieldKey]=u}return{record:{...o,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:i.length>0?i:void 0}},a=(t,r,s)=>{const{expression:n,targetFieldKey:i}=s;if(!n)return{error:{message:"Expression is empty",id:r,targetField:i}};let o;try{o=e.evaluate(n,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:i}}}return void 0===o?{error:{message:"Expression returned no value",id:r,targetField:i}}:{value:o}},l="yyyy-MM-dd",c=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],d=({value:e})=>{const t=n.parseISO(e);if(n.isValid(t))return t;const r=new Date;for(const t of c){const s=n.parse(e,t,r);if(n.isValid(s))return s.setUTCHours(0,0,0,0),s}return null},y=({value:e,format:r=l})=>{const s=(({value:e,format:r=l})=>{if(t.isDate(e))return e;if(!t.isString(e))return null;try{const t=n.parse(e,r,new Date);return n.isValid(t)?t:d({value:e})}catch(e){return null}})({value:e,format:r});return s?s.toISOString():null};var f;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(f||(f={}));const p=({value:e,type:r,format:s})=>{if(t.isMissing(e))return null;switch(r){case f.String:return(({value:e})=>t.isString(e)?e:t.isDate(e)?e.toISOString():t.isObject(e)?JSON.stringify(e):String(e))({value:e});case f.Number:return(({value:e})=>{if(t.isNumber(e))return e;if(t.isDate(e))return null;const r=Number(e);return isNaN(r)?null:r})({value:e});case f.Boolean:return(({value:e})=>t.isBoolean(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case f.DateTimeString:return y({value:e,format:s});default:return e}},g=async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successfull:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>m(e,t))):m(e.result,t),{block:{...e,result:r},successfull:!0}},m=(e,r)=>{const s={...e};return r.forEach((r=>{const{targetFieldKey:n,type:i}=r;(e=>Object.values(f).includes(e))(i)&&(r.isUnified&&t.notMissing(s[n])?s[n]=p({value:e[n],type:i}):s.unified_custom_fields&&t.notMissing(s.unified_custom_fields?.[n])&&(s.unified_custom_fields[n]=p({value:e.unified_custom_fields?.[n],type:i})))})),{...s}},S={build({functionName:e}){switch(e){case exports.StepFunctionName.TYPECAST:return g;case exports.StepFunctionName.MAP_FIELDS:return i;default:throw new Error(`Unknown step function: ${e}`)}}},v={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"}};exports.StepFunctionsFactory=S,exports.getCategoryDetails=e=>v[e.toLowerCase()]??null,exports.isValidCategory=e=>!!v[e.toLowerCase()];
1
+ "use strict";var e=require("@stackone/expressions"),t=require("zod"),r=require("@stackone/utils");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=s(require("date-fns"));const n=(e,t,r)=>Object.entries(e).reduce(((e,[s,i])=>{const n=i?.output?.data;return Array.isArray(n)&&n.length===t?e[s]={output:{data:n[r]}}:e[s]=i,e}),{}),a=(e,t,r)=>{if(!e||!r)return{record:e};const s={unified:{...e},..."object"==typeof r?r:{}},i={},n=[],a={...e};for(const r of t){const{error:t,value:u}=o(s,e.id,r);t?n.push(t):r.isUnified?a[r.targetFieldKey]=u:i[r.targetFieldKey]=u}return{record:{...a,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:n.length>0?n:void 0}},o=(t,r,s)=>{const{expression:i,targetFieldKey:n}=s;if(!i)return{error:{message:"Expression is empty",id:r,targetField:n}};let a;try{a=e.evaluate(i,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:n}}}return void 0===a?{error:{message:"Expression returned no value",id:r,targetField:n}}:{value:a}},u=t.z.object({fields:t.z.object({expression:t.z.string(),targetFieldKey:t.z.string(),type:t.z.string(),isUnified:t.z.boolean().optional()}).array(),dataSource:t.z.string()}),c=t.z.object({data:t.z.unknown()}),l=(e,t)=>{if(!t)return;const r={},s=[],i={};for(const n of e){const{error:e,value:a}=d(t,t?.id,n);e?s.push(e):n.isUnified?i[n.targetFieldKey]=a:r[n.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:s.length>0?s:void 0}},d=(t,r,s)=>{const{expression:i,targetFieldKey:n}=s;if(!i)return{error:{message:"Expression is empty",id:r,targetField:n}};let a;try{a=e.evaluate(i,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:n}}}return void 0===a?{error:{message:"Expression returned no value",id:r,targetField:n}}:{value:a}},f=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()}),p=t.z.object({data:t.z.unknown()}),y="yyyy-MM-dd",g=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],m=({value:e})=>{const t=i.parseISO(e);if(i.isValid(t))return t;const r=new Date;for(const t of g){const s=i.parse(e,t,r);if(i.isValid(s))return s.setUTCHours(0,0,0,0),s}return null},v=({value:e,format:t=y})=>{const s=(({value:e,format:t=y})=>{if(r.isDate(e))return e;if(!r.isString(e))return null;try{const r=i.parse(e,t,new Date);return i.isValid(r)?r:m({value:e})}catch(e){return null}})({value:e,format:t});return s?s.toISOString():null};var b;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(b||(b={}));const S=({value:e,type:t,format:s})=>{if(r.isMissing(e))return null;switch(t){case b.String:return(({value:e})=>r.isString(e)?e:r.isDate(e)?e.toISOString():r.isObject(e)?JSON.stringify(e):String(e))({value:e});case b.Number:return(({value:e})=>{if(r.isNumber(e))return e;if(r.isDate(e))return null;const t=Number(e);return isNaN(t)?null:t})({value:e});case b.Boolean:return(({value:e})=>r.isBoolean(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case b.DateTimeString:return v({value:e,format:s});default:return e}},h=e=>Object.values(b).includes(e),k=(e,t)=>{const s={...e};return t.forEach((t=>{const{targetFieldKey:i,type:n}=t;h(n)&&(t.isUnified&&r.notMissing(s[i])?s[i]=S({value:e[i],type:n}):s.unified_custom_fields&&r.notMissing(s.unified_custom_fields?.[i])&&(s.unified_custom_fields[i]=S({value:e.unified_custom_fields?.[i],type:n})))})),{...s}},M=(e,t)=>{const s={...e};return t.forEach((t=>{const{targetFieldKey:i,type:n}=t;h(n)&&(t.isUnified&&r.notMissing(s[i])?s[i]=S({value:e[i],type:n}):s.unified_custom_fields&&r.notMissing(s.unified_custom_fields?.[i])&&(s.unified_custom_fields[i]=S({value:e.unified_custom_fields?.[i],type:n})))})),{...s}};var F;exports.StepFunctionName=void 0,(F=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",F.MAP_FIELDS="map_fields";const _={[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=>k(e,t))):k(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:t,params:r})=>{const{fields:s,dataSource:i}=f.parse(r),n=e.evaluate(i,t);if(!s||"disabled"===t?.debug?.custom_mappings)return{block:t,successful:!0};let a;return a=Array.isArray(n)?n.map((e=>M(e,s))):M(n,s),{block:{...t},successful:!0,output:{data:a}}},inputSchema:f,outputSchema:p}},[exports.StepFunctionName.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],s=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){const o=e.result.length;i=e.result.map(((e,i)=>{const u=n(s,o,i),c=a(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const n=a(e.result,t,s);i=n.record,r.push(...n.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:t,params:r})=>{const s=[],{fields:i,dataSource:n}=u.parse(r),a=e.evaluate(n,t);if(!i||!n||"disabled"===t?.debug?.custom_mappings||!a)return{block:t,successful:!0};let o;if(Array.isArray(a))o=a.map((e=>{const t=l(i,e);return s.push(...t?.errors||[]),t?.record}));else{const e=l(i,a);o=e?.record,s.push(...e?.errors||[])}return{block:{...t},successful:!0,output:{data:o},errors:Object.keys(s).length>0?s:void 0}},inputSchema:u,outputSchema:c}}},j=(e,t)=>async({block:r,params:s})=>{try{e.inputSchema&&e.inputSchema.parse(s)}catch(e){return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const i=await e.fn({block:r,params:s});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch(e){return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},x={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:s=_}){const i=s?.[e]?.[`v${t}`];if(!i)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...i,fn:j(i,e)}:i}},z={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"}};exports.StepFunctionsFactory=x,exports.getCategoryDetails=e=>z[e.toLowerCase()]??null,exports.isValidCategory=e=>!!z[e.toLowerCase()];
@@ -1,5 +1,6 @@
1
1
  export { Block, BlockIndexedRecord, BlockContext, FieldConfig, } from './blocks/types';
2
- export { StepFunction, StepFunctionParams, StepFunctionName } from './stepFunctions/types';
2
+ export { StepFunction, StepFunctionParams } from './stepFunctions/types';
3
+ export { StepFunctionName } from './stepFunctions/stepFunctionsList';
3
4
  export { StepsSnapshots, Step } from './steps/types';
4
5
  export { StepFunctionsFactory } from './stepFunctions/factory';
5
6
  export { Schema, SchemaField } from './schema/types';
@@ -1,7 +1,10 @@
1
- import { StepFunctionName } from './types';
2
- import type { StepFunction } from './types';
1
+ import { StepFunctionName } from './stepFunctionsList';
2
+ import type { StepFunctionInstance } from './types';
3
3
  export declare const StepFunctionsFactory: {
4
- build({ functionName }: {
4
+ build({ functionName, version, validateSchemas, stepFunctionsList, }: {
5
5
  functionName: StepFunctionName;
6
- }): StepFunction;
6
+ version?: string;
7
+ validateSchemas?: boolean;
8
+ stepFunctionsList?: Record<string, Record<string, StepFunctionInstance>>;
9
+ }): StepFunctionInstance;
7
10
  };
@@ -0,0 +1,2 @@
1
+ import type { StepFunction } from '../types';
2
+ export declare const mapFieldsStepFunction: StepFunction;
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ export declare const MAP_FIELDS_INPUT_PARAMS: z.ZodObject<{
3
+ fields: z.ZodArray<z.ZodObject<{
4
+ expression: z.ZodString;
5
+ targetFieldKey: z.ZodString;
6
+ type: z.ZodString;
7
+ isUnified: z.ZodOptional<z.ZodBoolean>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ expression: string;
10
+ targetFieldKey: string;
11
+ type: string;
12
+ isUnified?: boolean | undefined;
13
+ }, {
14
+ expression: string;
15
+ targetFieldKey: string;
16
+ type: string;
17
+ isUnified?: boolean | undefined;
18
+ }>, "many">;
19
+ dataSource: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ fields: {
22
+ expression: string;
23
+ targetFieldKey: string;
24
+ type: string;
25
+ isUnified?: boolean | undefined;
26
+ }[];
27
+ dataSource: string;
28
+ }, {
29
+ fields: {
30
+ expression: string;
31
+ targetFieldKey: string;
32
+ type: string;
33
+ isUnified?: boolean | undefined;
34
+ }[];
35
+ dataSource: string;
36
+ }>;
37
+ export declare const MAP_FIELDS_OUTPUT: z.ZodObject<{
38
+ data: z.ZodUnknown;
39
+ }, "strip", z.ZodTypeAny, {
40
+ data?: unknown;
41
+ }, {
42
+ data?: unknown;
43
+ }>;
@@ -0,0 +1,101 @@
1
+ export declare enum StepFunctionName {
2
+ TYPECAST = "typecast",
3
+ MAP_FIELDS = "map_fields"
4
+ }
5
+ export declare const stepFunctions: {
6
+ typecast: {
7
+ v1: {
8
+ fn: import("./types").StepFunction;
9
+ };
10
+ v2: {
11
+ fn: import("./types").StepFunction;
12
+ inputSchema: import("zod").ZodObject<{
13
+ fields: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
14
+ targetFieldKey: import("zod").ZodString;
15
+ type: import("zod").ZodString;
16
+ isUnified: import("zod").ZodOptional<import("zod").ZodBoolean>;
17
+ }, "strip", import("zod").ZodTypeAny, {
18
+ targetFieldKey: string;
19
+ type: string;
20
+ isUnified?: boolean | undefined;
21
+ }, {
22
+ targetFieldKey: string;
23
+ type: string;
24
+ isUnified?: boolean | undefined;
25
+ }>, "many">>;
26
+ dataSource: import("zod").ZodString;
27
+ }, "strip", import("zod").ZodTypeAny, {
28
+ dataSource: string;
29
+ fields?: {
30
+ targetFieldKey: string;
31
+ type: string;
32
+ isUnified?: boolean | undefined;
33
+ }[] | undefined;
34
+ }, {
35
+ dataSource: string;
36
+ fields?: {
37
+ targetFieldKey: string;
38
+ type: string;
39
+ isUnified?: boolean | undefined;
40
+ }[] | undefined;
41
+ }>;
42
+ outputSchema: import("zod").ZodObject<{
43
+ data: import("zod").ZodUnknown;
44
+ }, "strip", import("zod").ZodTypeAny, {
45
+ data?: unknown;
46
+ }, {
47
+ data?: unknown;
48
+ }>;
49
+ };
50
+ };
51
+ map_fields: {
52
+ v1: {
53
+ fn: import("./types").StepFunction;
54
+ };
55
+ v2: {
56
+ fn: import("./types").StepFunction;
57
+ inputSchema: import("zod").ZodObject<{
58
+ fields: import("zod").ZodArray<import("zod").ZodObject<{
59
+ expression: import("zod").ZodString;
60
+ targetFieldKey: import("zod").ZodString;
61
+ type: import("zod").ZodString;
62
+ isUnified: import("zod").ZodOptional<import("zod").ZodBoolean>;
63
+ }, "strip", import("zod").ZodTypeAny, {
64
+ targetFieldKey: string;
65
+ type: string;
66
+ expression: string;
67
+ isUnified?: boolean | undefined;
68
+ }, {
69
+ targetFieldKey: string;
70
+ type: string;
71
+ expression: string;
72
+ isUnified?: boolean | undefined;
73
+ }>, "many">;
74
+ dataSource: import("zod").ZodString;
75
+ }, "strip", import("zod").ZodTypeAny, {
76
+ fields: {
77
+ targetFieldKey: string;
78
+ type: string;
79
+ expression: string;
80
+ isUnified?: boolean | undefined;
81
+ }[];
82
+ dataSource: string;
83
+ }, {
84
+ fields: {
85
+ targetFieldKey: string;
86
+ type: string;
87
+ expression: string;
88
+ isUnified?: boolean | undefined;
89
+ }[];
90
+ dataSource: string;
91
+ }>;
92
+ outputSchema: import("zod").ZodObject<{
93
+ data: import("zod").ZodUnknown;
94
+ }, "strip", import("zod").ZodTypeAny, {
95
+ data?: unknown;
96
+ }, {
97
+ data?: unknown;
98
+ }>;
99
+ };
100
+ };
101
+ };
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ export declare const TYPECAST_INPUT_PARAMS: z.ZodObject<{
3
+ fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
4
+ targetFieldKey: z.ZodString;
5
+ type: z.ZodString;
6
+ isUnified: z.ZodOptional<z.ZodBoolean>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ targetFieldKey: string;
9
+ type: string;
10
+ isUnified?: boolean | undefined;
11
+ }, {
12
+ targetFieldKey: string;
13
+ type: string;
14
+ isUnified?: boolean | undefined;
15
+ }>, "many">>;
16
+ dataSource: z.ZodString;
17
+ }, "strip", z.ZodTypeAny, {
18
+ dataSource: string;
19
+ fields?: {
20
+ targetFieldKey: string;
21
+ type: string;
22
+ isUnified?: boolean | undefined;
23
+ }[] | undefined;
24
+ }, {
25
+ dataSource: string;
26
+ fields?: {
27
+ targetFieldKey: string;
28
+ type: string;
29
+ isUnified?: boolean | undefined;
30
+ }[] | undefined;
31
+ }>;
32
+ export declare const TYPECAST_OUTPUT: z.ZodObject<{
33
+ data: z.ZodUnknown;
34
+ }, "strip", z.ZodTypeAny, {
35
+ data?: unknown;
36
+ }, {
37
+ data?: unknown;
38
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { StepFunction } from '../types';
2
+ export declare const typecastStepFunction: StepFunction;
@@ -1,11 +1,7 @@
1
+ import { ZodTypeAny } from 'zod';
1
2
  import type { Block } from '../blocks/types';
2
3
  import { StepError } from '../steps/types';
3
- export declare enum StepFunctionName {
4
- TYPECAST = "typecast",
5
- MAP_FIELDS = "map_fields",
6
- REQUEST = "request",
7
- GROUP_RESULTS = "group_results"
8
- }
4
+ import { StepFunctionName } from './stepFunctionsList';
9
5
  export type StepFunction = ({ block, params, }: {
10
6
  block: Readonly<Block>;
11
7
  params?: StepFunctionParams;
@@ -18,9 +14,14 @@ export type StepFunctionMeta = {
18
14
  params?: StepFunctionParams;
19
15
  version?: string;
20
16
  };
17
+ export type StepFunctionInstance = {
18
+ fn: StepFunction;
19
+ inputSchema?: ZodTypeAny;
20
+ outputSchema?: ZodTypeAny;
21
+ };
21
22
  export type StepFunctionOutput = {
22
23
  block: Block;
23
- successfull: boolean;
24
+ successful: boolean;
24
25
  errors?: StepError[];
25
26
  output?: {
26
27
  [name: string]: unknown;
@@ -3,7 +3,7 @@ export type StepSnapshot = {
3
3
  output?: {
4
4
  [name: string]: unknown;
5
5
  };
6
- successfull: boolean;
6
+ successful: boolean;
7
7
  errors?: StepError[];
8
8
  };
9
9
  export type StepsSnapshots = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.mjs",
@@ -24,8 +24,8 @@
24
24
  "code:check:fix": "biome check --write ./src ./*.mjs",
25
25
  "lint": "npm run code:check",
26
26
  "lint:fix": "npm run code:check:fix",
27
- "test": "vitest run --silent",
28
- "test:watch": "vitest watch --silent",
27
+ "test": "FORCE_COLOR=1 vitest run --silent",
28
+ "test:watch": "FORCE_COLOR=1 vitest watch --silent",
29
29
  "publish-release": "npm publish --access=public"
30
30
  },
31
31
  "keywords": [],
@@ -36,8 +36,5 @@
36
36
  "@stackone/transport": "*",
37
37
  "@stackone/utils": "*",
38
38
  "date-fns": "^3.4.0"
39
- },
40
- "devDependencies": {
41
- "@types/jsonpath": "^0.2.4"
42
39
  }
43
40
  }