@stackone/core 1.20.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 n,isNumber as s,isObject as u,isMissing as i,notMissing as o}from"@stackone/utils";import*as a from"date-fns";var l;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields"}(l||(l={}));const d=async({block:e})=>{const r=e?.fieldConfigs,t=[],n=e.steps;if(!r||"disabled"===e?.debug?.custom_mappings||!n)return e;let s;if(Array.isArray(e.result)){const u=e.result.length;s=e.result.map(((e,s)=>{const i=c(n,u,s),o=y(e,r,i);return t.push(...o.errors||[]),o.record}))}else{const u=y(e.result,r,n);s=u.record,t.push(...u.errors||[])}const u={output:{data:s},errors:Object.keys(t).length>0?t:void 0};return{...e,result:s,steps:{...n,[l.MAP_FIELDS.toString()]:u}}},c=(e,r,t)=>Object.entries(e).reduce(((e,[n,s])=>{const u=s?.output?.data;return Array.isArray(u)&&u.length===r?e[n]={output:{data:u[t]}}:e[n]=s,e}),{}),y=(e,r,t)=>{if(!e||!t)return{record:e};const n={unified:{...e},..."object"==typeof t?t:{}},s={},u=[],i={...e};for(const t of r){const{error:r,value:o}=f(n,e.id,t);r?u.push(r):t.isUnified?i[t.targetFieldKey]=o:s[t.targetFieldKey]=o}return{record:{...i,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:u.length>0?u:void 0}},f=(r,t,n)=>{const{expression:s,targetFieldKey:u}=n;if(!s)return{error:{message:"Expression is empty",id:t,targetField:u}};let i;try{i=e(s,r)}catch(e){return{error:{message:"Invalid expression",id:t,targetField:u}}}return void 0===i?{error:{message:"Expression returned no value",id:t,targetField:u}}:{value:i}},m="yyyy-MM-dd",p=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],g=({value:e})=>{const r=a.parseISO(e);if(a.isValid(r))return r;const t=new Date;for(const r of p){const n=a.parse(e,r,t);if(a.isValid(n))return n.setUTCHours(0,0,0,0),n}return null},v=({value:e,format:n=m})=>{const s=(({value:e,format:n=m})=>{if(r(e))return e;if(!t(e))return null;try{const r=a.parse(e,n,new Date);return a.isValid(r)?r:g({value:e})}catch(e){return null}})({value:e,format:n});return s?s.toISOString():null};var M;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(M||(M={}));const b=({value:e,type:o,format:a})=>{if(i(e))return null;switch(o){case M.String:return(({value:e})=>t(e)?e:r(e)?e.toISOString():u(e)?JSON.stringify(e):String(e))({value:e});case M.Number:return(({value:e})=>{if(s(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 v({value:e,format:a});default:return e}},S=async({block:e})=>{const r=e?.fieldConfigs;if(!r||"disabled"===e?.debug?.custom_mappings)return e;let t;return t=Array.isArray(e.result)?e.result.map((e=>_(e,r))):_(e.result,r),{...e,result:t}},_=(e,r)=>{const t={...e};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;(e=>Object.values(M).includes(e))(s)&&(r.isUnified&&o(t[n])?t[n]=b({value:e[n],type:s}):t.unified_custom_fields&&o(t.unified_custom_fields?.[n])&&(t.unified_custom_fields[n]=b({value:e.unified_custom_fields?.[n],type:s})))})),{...t}},h={build({functionName:e}){switch(e){case l.TYPECAST:return S;case l.MAP_FIELDS:return d;default:throw new Error(`Unknown step function: ${e}`)}}};export{l as StepFunctionName,h as StepFunctionsFactory};
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 n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var n,s=r(require("date-fns"));exports.StepFunctionName=void 0,(n=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",n.MAP_FIELDS="map_fields";const i=async({block:e})=>{const t=e?.fieldConfigs,r=[],n=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!n)return e;let s;if(Array.isArray(e.result)){const i=e.result.length;s=e.result.map(((e,s)=>{const a=u(n,i,s),l=o(e,t,a);return r.push(...l.errors||[]),l.record}))}else{const i=o(e.result,t,n);s=i.record,r.push(...i.errors||[])}const i={output:{data:s},errors:Object.keys(r).length>0?r:void 0};return{...e,result:s,steps:{...n,[exports.StepFunctionName.MAP_FIELDS.toString()]:i}}},u=(e,t,r)=>Object.entries(e).reduce(((e,[n,s])=>{const i=s?.output?.data;return Array.isArray(i)&&i.length===t?e[n]={output:{data:i[r]}}:e[n]=s,e}),{}),o=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},s={},i=[],u={...e};for(const r of t){const{error:t,value:o}=a(n,e.id,r);t?i.push(t):r.isUnified?u[r.targetFieldKey]=o:s[r.targetFieldKey]=o}return{record:{...u,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:i.length>0?i:void 0}},a=(t,r,n)=>{const{expression:s,targetFieldKey:i}=n;if(!s)return{error:{message:"Expression is empty",id:r,targetField:i}};let u;try{u=e.evaluate(s,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:i}}}return void 0===u?{error:{message:"Expression returned no value",id:r,targetField:i}}:{value:u}},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=s.parseISO(e);if(s.isValid(t))return t;const r=new Date;for(const t of c){const n=s.parse(e,t,r);if(s.isValid(n))return n.setUTCHours(0,0,0,0),n}return null},y=({value:e,format:r=l})=>{const n=(({value:e,format:r=l})=>{if(t.isDate(e))return e;if(!t.isString(e))return null;try{const t=s.parse(e,r,new Date);return s.isValid(t)?t:d({value:e})}catch(e){return null}})({value:e,format:r});return n?n.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:n})=>{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:n});default:return e}},g=async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return e;let r;return r=Array.isArray(e.result)?e.result.map((e=>m(e,t))):m(e.result,t),{...e,result:r}},m=(e,r)=>{const n={...e};return r.forEach((r=>{const{targetFieldKey:s,type:i}=r;(e=>Object.values(f).includes(e))(i)&&(r.isUnified&&t.notMissing(n[s])?n[s]=p({value:e[s],type:i}):n.unified_custom_fields&&t.notMissing(n.unified_custom_fields?.[s])&&(n.unified_custom_fields[s]=p({value:e.unified_custom_fields?.[s],type:i})))})),{...n}},v={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}`)}}};exports.StepFunctionsFactory=v;
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,20 +1,37 @@
1
+ import type { IHttpClient } from '@stackone/transport';
2
+ import { Category } from '../categories/types';
3
+ import { Connector, Operation, OperationType } from '../connector/types';
4
+ import { ILogger } from '../logger/types';
1
5
  import type { StepsSnapshots } from '../steps/types';
2
6
  export type Block = {
3
- fieldConfigs?: FieldConfig[];
4
- result?: BlockIndexedRecord[] | BlockIndexedRecord;
7
+ inputs?: {
8
+ [key: string]: unknown;
9
+ };
10
+ connector?: Connector;
5
11
  context: BlockContext;
6
12
  debug?: DebugParams;
7
13
  steps?: StepsSnapshots;
14
+ httpClient?: IHttpClient;
15
+ logger?: ILogger;
16
+ operation?: Operation;
17
+ credentials?: Credentials;
18
+ outputs?: unknown;
19
+ fieldConfigs?: FieldConfig[];
20
+ result?: BlockIndexedRecord[] | BlockIndexedRecord;
8
21
  };
9
22
  export type BlockContext = {
10
23
  projectSecureId: string;
11
24
  accountSecureId: string;
12
25
  connector: string;
26
+ category: Category;
27
+ schema?: string;
28
+ operationType: OperationType;
29
+ authenticationType: string;
30
+ environment: string;
13
31
  service: string;
14
32
  resource: string;
15
33
  subResource?: string;
16
34
  childResource?: string;
17
- operationType: string;
18
35
  };
19
36
  export type BlockIndexedRecord = {
20
37
  id: string;
@@ -33,3 +50,4 @@ export type FieldConfig = {
33
50
  export type DebugParams = {
34
51
  custom_mappings?: 'disabled' | 'enabled';
35
52
  };
53
+ export type Credentials = Record<string, unknown>;
@@ -0,0 +1,3 @@
1
+ import { CategoryDetails } from './types';
2
+ export declare const getCategoryDetails: (category: string) => CategoryDetails | null;
3
+ export declare const isValidCategory: (category: string) => boolean;
@@ -0,0 +1,6 @@
1
+ export type Category = 'hris' | 'crm' | 'ats' | 'lms' | 'marketing' | 'filestorage';
2
+ export type CategoryDetails = {
3
+ title: string;
4
+ key: Category;
5
+ description: string;
6
+ };
@@ -0,0 +1,53 @@
1
+ import { HttpMethod } from '@stackone/transport';
2
+ import { Category } from '../categories/types';
3
+ import { Schema } from '../schema/types';
4
+ import { Step } from '../steps/types';
5
+ export type Connector = {
6
+ title: string;
7
+ version: string;
8
+ key: string;
9
+ description?: string;
10
+ categories: Category[];
11
+ authentication?: Authentication;
12
+ operations?: {
13
+ [entrypointUrl: string]: Operation;
14
+ };
15
+ };
16
+ export type OperationType = 'list' | 'get' | 'create' | 'update' | 'delete' | 'custom';
17
+ export type InputLocation = 'body' | 'query' | 'path' | 'headers';
18
+ export type Input = {
19
+ name: string;
20
+ type: string;
21
+ required: boolean;
22
+ description: string;
23
+ in: InputLocation;
24
+ };
25
+ export type Operation = {
26
+ id: string;
27
+ description: string;
28
+ schema?: Schema;
29
+ operationType: OperationType;
30
+ entrypointUrl: string;
31
+ entrypointHttpMethod: HttpMethod;
32
+ inputs?: Input[];
33
+ steps: {
34
+ [stepId: string]: Step;
35
+ };
36
+ result?: string;
37
+ };
38
+ export type AuthenticationConfig = {
39
+ envKey: string;
40
+ envName: string;
41
+ type: 'custom' | 'oauth2' | 'oidc';
42
+ label: string;
43
+ authorization: {
44
+ type: 'basic' | 'bearer';
45
+ [authParam: string]: unknown;
46
+ };
47
+ };
48
+ export type Authentication = {
49
+ [authType: string]: {
50
+ production: AuthenticationConfig;
51
+ [envKey: string]: AuthenticationConfig;
52
+ };
53
+ };
@@ -1,4 +1,9 @@
1
1
  export { Block, BlockIndexedRecord, BlockContext, FieldConfig, } from './blocks/types';
2
- export { StepFunction, StepFunctionParams, StepFunctionName } from './stepFunctions/types';
3
- export { StepsSnapshots } from './steps/types';
2
+ export { StepFunction, StepFunctionParams } from './stepFunctions/types';
3
+ export { StepFunctionName } from './stepFunctions/stepFunctionsList';
4
+ export { StepsSnapshots, Step } from './steps/types';
4
5
  export { StepFunctionsFactory } from './stepFunctions/factory';
6
+ export { Schema, SchemaField } from './schema/types';
7
+ export { Category } from './categories/types';
8
+ export { getCategoryDetails, isValidCategory } from './categories';
9
+ export { Connector, Operation, OperationType } from './connector/types';
@@ -0,0 +1,34 @@
1
+ export interface ILogger {
2
+ debug({ category, message, traceId, context, }: {
3
+ category?: string;
4
+ message: string;
5
+ traceId?: string;
6
+ context?: Record<string, unknown>;
7
+ }): void;
8
+ info({ category, message, traceId, context, }: {
9
+ category?: string;
10
+ message: string;
11
+ traceId?: string;
12
+ context?: Record<string, unknown>;
13
+ }): void;
14
+ warning({ category, message, traceId, context, }: {
15
+ category?: string;
16
+ message: string;
17
+ traceId?: string;
18
+ context?: Record<string, unknown>;
19
+ }): void;
20
+ error({ category, message, traceId, error, context, }: {
21
+ category?: string;
22
+ message: string;
23
+ traceId?: string;
24
+ error?: LogError;
25
+ context?: Record<string, unknown>;
26
+ }): void;
27
+ }
28
+ export type LogError = Error & {
29
+ response?: {
30
+ data?: unknown;
31
+ };
32
+ context?: Record<string, unknown>;
33
+ url?: string;
34
+ };
@@ -0,0 +1,17 @@
1
+ import { Category } from '../categories/types';
2
+ export type Schema = {
3
+ name: string;
4
+ key: string;
5
+ version: string;
6
+ description?: string;
7
+ category: Category;
8
+ fields: {
9
+ [name: string]: SchemaField;
10
+ };
11
+ };
12
+ export type SchemaField = {
13
+ name: string;
14
+ type: string;
15
+ required: boolean;
16
+ description?: string;
17
+ };
@@ -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,11 @@
1
+ import { HttpMethod, HttpResponse, IHttpClient } from '@stackone/transport';
2
+ export interface IRequestClient {
3
+ performRequest: ({ httpClient, url, method, headers, body, }: {
4
+ httpClient: IHttpClient;
5
+ url: string;
6
+ method: HttpMethod;
7
+ headers: Record<string, string>;
8
+ body: unknown;
9
+ }) => Promise<HttpResponse>;
10
+ }
11
+ export type RequestClientType = 'rest' | 'soap';
@@ -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,12 +1,29 @@
1
+ import { ZodTypeAny } from 'zod';
1
2
  import type { Block } from '../blocks/types';
2
- export declare enum StepFunctionName {
3
- TYPECAST = "typecast",
4
- MAP_FIELDS = "map_fields"
5
- }
3
+ import { StepError } from '../steps/types';
4
+ import { StepFunctionName } from './stepFunctionsList';
6
5
  export type StepFunction = ({ block, params, }: {
7
6
  block: Readonly<Block>;
8
7
  params?: StepFunctionParams;
9
- }) => Promise<Block>;
8
+ }) => Promise<StepFunctionOutput>;
10
9
  export type StepFunctionParams = {
11
10
  [key: string]: unknown;
12
11
  };
12
+ export type StepFunctionMeta = {
13
+ functionName: StepFunctionName;
14
+ params?: StepFunctionParams;
15
+ version?: string;
16
+ };
17
+ export type StepFunctionInstance = {
18
+ fn: StepFunction;
19
+ inputSchema?: ZodTypeAny;
20
+ outputSchema?: ZodTypeAny;
21
+ };
22
+ export type StepFunctionOutput = {
23
+ block: Block;
24
+ successful: boolean;
25
+ errors?: StepError[];
26
+ output?: {
27
+ [name: string]: unknown;
28
+ };
29
+ };
@@ -1,12 +1,26 @@
1
+ import { StepFunctionMeta } from '../stepFunctions/types';
1
2
  export type StepSnapshot = {
2
3
  output?: {
3
- data: unknown;
4
+ [name: string]: unknown;
4
5
  };
6
+ successful: boolean;
5
7
  errors?: StepError[];
6
8
  };
7
9
  export type StepsSnapshots = {
8
- [key: string]: StepSnapshot;
10
+ [stepId: string]: StepSnapshot;
9
11
  };
10
12
  export type StepError = {
11
13
  [key: string]: unknown;
12
14
  };
15
+ export type StepOutput = {
16
+ name: string;
17
+ value: string;
18
+ };
19
+ export type Step = {
20
+ id: string;
21
+ description: string;
22
+ stepFunction: StepFunctionMeta;
23
+ ignoreErrors?: boolean;
24
+ async?: boolean;
25
+ successCriteria?: string;
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.20.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
  }