@stackone/core 1.35.0 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/types/blocks/types.d.ts +2 -0
- package/dist/types/cursor/index.d.ts +4 -0
- package/dist/types/cursor/schemas.d.ts +34 -0
- package/dist/types/cursor/types.d.ts +21 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/logger/codes.d.ts +123 -0
- package/dist/types/logger/types.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as n,getCountrySubDivisionsByAlpha2Code as a,getCountryCodeByCountryName as o,getCountryCodeByAlpha3Code as s,getCountryCodeByAlpha2Code as i,getCountryAlpha2CodeByCountryCode as u,getCountryAlpha2CodeByCountryName as c,getCountryAlpha2CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as d,getCountryAlpha3CodeByCountryName as p,getCountryAlpha3CodeByAlpha2Code as y,getCountryNameByCountryCode as m,getCountryNameByAlpha2Code as _,getCountryNameByAlpha3Code as f,getCountryNameByCountryName as g,getCountryCodeByCountryCode as b,getCountryAlpha3CodeByAlpha3Code as h,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as F,safeParseToBoolean as j,safeParseToNumber as w,safeParseToString as x}from"@stackone/utils";import{z as A}from"zod";import{evaluate as E,safeEvaluateRecord as K}from"@stackone/expressions";import{RequestParameterLocations as T,HttpMethods as C,RequestClientFactory as U,parseRequestParameters as M,createAuthorizationHeaders as O}from"@stackone/transport";const R=A.object({stepsDataToGroup:A.array(A.string()),isSingleRecord:A.boolean().optional()}),D=A.object({data:A.unknown()}),I=(e,t,r)=>Object.entries(e).reduce(((e,[n,a])=>{const o=a?.output?.data;return Array.isArray(o)&&o.length===t?e[n]={output:{data:o[r]}}:e[n]=a,e}),{}),P=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},a={},o=[],s={...e};for(const r of t){const{error:t,value:i}=$(n,e.id,r);t?o.push(t):r.isUnified?s[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...s,unified_custom_fields:Object.keys(a).length>0?a:void 0},errors:o.length>0?o:void 0}},$=(e,t,r)=>{const{expression:n,targetFieldKey:a}=r;if(!n)return{error:{message:"Expression is empty",id:t,targetField:a}};let o;try{o=E(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:a}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:a}}:{value:o}},L=A.object({fields:A.object({targetFieldKey:A.string(),expression:A.string(),type:A.enum(["string","number","boolean","datetime_string","enum"]),isUnified:A.boolean().optional(),enumMapper:A.object({matcher:A.string().or(A.object({matchExpression:A.string(),value:A.string()}).array())}).optional()}).array(),dataSource:A.string()}),q=A.object({data:A.unknown()}),G=(e,t)=>{if(!t)return;const r={},n=[],a={};for(const o of e){const{error:e,value:s}=z(t,t?.id,o);e?n.push(e):o.isUnified?a[o.targetFieldKey]=s:r[o.targetFieldKey]=s}return{record:{...a,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:n.length>0?n:void 0}},z=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return H(r,t,e);case"enum":return N(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},H=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=E(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}},N=(S,F,j)=>{const w=H(S,F,j),x=e(w.value)?w.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:F,targetField:S.targetFieldKey}};const A=S.enumMapper.matcher;if(k(A)){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 b;case"country_name_by_country_name":return g;case"country_name_by_alpha3code":return f;case"country_name_by_alpha2code":return _;case"country_name_by_country_code":return m;case"country_alpha3code_by_alpha2code":return y;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 o;case"country_subdivisions_by_alpha2code":return a;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}})(A);if(e(k)){return{value:{value:(e(x)?k(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${A}" is not supported`,id:F,targetField:S.targetFieldKey}}}for(const e of A){const{matchExpression:t,value:r}=e;if(!0===E(t,j))return{value:{value:r,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},B=A.object({type:A.literal("basic"),username:A.string(),password:A.string(),encoding:A.string().optional()}),Q=A.object({type:A.literal("bearer"),token:A.string()}),Y=A.discriminatedUnion("type",[B,Q]),J=A.object({baseUrl:A.string(),url:A.string(),method:A.enum(C),response:A.object({collection:A.boolean().optional(),indexField:A.string().optional(),dataKey:A.string().optional()}).optional(),args:A.object({name:A.string(),value:A.unknown(),in:A.enum(T),condition:A.string().optional()}).array().optional()}),V=A.object({data:A.unknown().optional(),raw:A.unknown().optional(),statusCode:A.number()}).optional(),W=(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},X=A.object({fields:A.object({targetFieldKey:A.string(),type:A.string(),isUnified:A.boolean().optional()}).array().optional(),dataSource:A.string()}),Z=A.object({data:A.unknown()});var ee;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ee||(ee={}));const te=({value:e,type:t,format:r})=>{if(S(e))return null;switch(t){case ee.String:return x({value:e});case ee.Number:return w({value:e});case ee.Boolean:return j({value:e});case ee.DateTimeString:return F({value:e,format:r});default:return e}},re=e=>Object.values(ee).includes(e),ne=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:a,type:o}=r;re(o)&&(r.isUnified&&e(n[a])?n[a]=te({value:t[a],type:o}):n.unified_custom_fields&&e(n.unified_custom_fields?.[a])&&(n.unified_custom_fields[a]=te({value:t.unified_custom_fields?.[a],type:o})))})),{...n}},ae=(t,r)=>{const n={...t};return r.forEach((r=>{const{targetFieldKey:a,type:o}=r;re(o)&&(r.isUnified&&e(n[a])?n[a]=te({value:t[a],type:o}):n.unified_custom_fields&&e(n.unified_custom_fields?.[a])&&(n.unified_custom_fields[a]=te({value:t.unified_custom_fields?.[a],type:o})))})),{...n}};var oe;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request"}(oe||(oe={}));const se={[oe.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=>ne(e,t))):ne(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:n}=X.parse(t),a=E(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let o;return o=Array.isArray(a)?a.map((e=>ae(e,r))):ae(a,r),{block:{...e},successful:!0,output:{data:o}}},inputSchema:X,outputSchema:Z}},[oe.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 a;if(Array.isArray(e.result)){const o=e.result.length;a=e.result.map(((e,a)=>{const s=I(n,o,a),i=P(e,t,s);return r.push(...i.errors||[]),i.record}))}else{const o=P(e.result,t,n);a=o.record,r.push(...o.errors||[])}return{block:{...e,result:a},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:n,dataSource:a}=L.parse(t),o=E(a,e);if(!n||!a||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let s;if(Array.isArray(o))s=o.map((e=>{const t=G(n,e);return r.push(...t?.errors||[]),t?.record}));else{const e=G(n,o);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:L,outputSchema:q}},[oe.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=U.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,a=n?n.filter((t=>!t.condition||!0===E(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,o=t?K({...t,args:a},e):{},{baseUrl:s,url:i,method:u,response:c,args:l}=J.parse(o),d=o?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,p=Y.parse(d),y=l?M(l):{query:{},body:{},headers:{}},m=O(p),_={...y?.headers??{},...m};let f;try{f=await r.performRequest({httpClient:e.httpClient,url:`${s}${i}`,queryParams:y?.query,method:u,headers:_,body:y?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const g=c?.dataKey?f.data[c?.dataKey]:f.data,b=W(g,c);return{block:e,successful:!0,output:{data:b,raw:f,statusCode:f?.status}}},inputSchema:J,outputSchema:V}},[oe.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:n,isSingleRecord:a}=R.parse(r),o=n.reduce(((r,n)=>{const o=t.steps?.[n]?.output?.data;return o?a?{...r,[n]:{...o}}:(Object.keys(o).forEach((t=>{const a=e(r[t])?r[t]:{};r[t]={...a,[n]:{...o[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:a?o:Object.values(o)}}},inputSchema:R,outputSchema:D}}},ie=(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 a=await e.fn({block:r,params:n});try{e.outputSchema&&e.outputSchema.parse(a.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return a},ue={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:n=se}){const a=n?.[e]?.[`v${t}`];if(!a)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...a,fn:ie(a,e)}:a}},ce={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"}},le=e=>ce[e.toLowerCase()]??null,de=e=>!!ce[e.toLowerCase()];export{Y as AUTHENTICATION_SCHEMA,oe as StepFunctionName,ue as StepFunctionsFactory,le as getCategoryDetails,de as isValidCategory};
|
|
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 f,getCountryNameByAlpha3Code as b,getCountryNameByCountryName as g,getCountryCodeByCountryCode as _,getCountryAlpha3CodeByAlpha3Code as h,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as S,safeParseToDateTimeString as F,safeParseToBoolean as j,safeParseToNumber as w,safeParseToString as x,encodeToBase64 as A,decodeFromBase64 as E,getContentHash as K}from"@stackone/utils";import{z as T}from"zod";import{evaluate as O,safeEvaluateRecord as C}from"@stackone/expressions";import{RequestParameterLocations as U,HttpMethods as M,RequestClientFactory as R,parseRequestParameters as P,createAuthorizationHeaders as D}from"@stackone/transport";const I=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),$=T.object({data:T.unknown()}),L=(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}),{}),N=(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=O(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:o}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:o}}:{value:s}},G=T.object({fields:T.object({targetFieldKey:T.string(),expression:T.string(),type:T.enum(["string","number","boolean","datetime_string","enum"]),isUnified:T.boolean().optional(),enumMapper:T.object({matcher:T.string().or(T.object({matchExpression:T.string(),value:T.string()}).array())}).optional()}).array(),dataSource:T.string()}),z=T.object({data:T.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=O(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},Q=(S,F,j)=>{const w=J(S,F,j),x=e(w.value)?w.value:null;if(void 0===S.enumMapper)return{error:{message:"Enum mapper was not defined",id:F,targetField:S.targetFieldKey}};const A=S.enumMapper.matcher;if(k(A)){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 g;case"country_name_by_alpha3code":return b;case"country_name_by_alpha2code":return f;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}})(A);if(e(k)){return{value:{value:(e(x)?k(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${A}" is not supported`,id:F,targetField:S.targetFieldKey}}}for(const e of A){const{matchExpression:t,value:r}=e;if(!0===O(t,j))return{value:{value:r,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Y=T.object({type:T.literal("basic"),username:T.string(),password:T.string(),encoding:T.string().optional()}),V=T.object({type:T.literal("bearer"),token:T.string()}),W=T.discriminatedUnion("type",[Y,V]),X=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(M),response:T.object({collection:T.boolean().optional(),indexField:T.string().optional(),dataKey:T.string().optional()}).optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(U),condition:T.string().optional()}).array().optional()}),Z=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.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=T.object({fields:T.object({targetFieldKey:T.string(),type:T.string(),isUnified:T.boolean().optional()}).array().optional(),dataSource:T.string()}),re=T.object({data:T.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 x({value:e});case ne.Number:return w({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=O(n,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(o)?o.map((e=>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=L(n,s,o),i=N(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=N(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=O(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=R.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,o=n?n.filter((t=>!t.condition||!0===O(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?C({...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=W.parse(d),m=l?P(l):{query:{},body:{},headers:{}},y=D(p),f={...m?.headers??{},...y};let b;try{b=await r.performRequest({httpClient:e.httpClient,url:`${a}${i}`,queryParams:m?.query,method:u,headers:f,body:m?.body})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500}}}const g=c?.dataKey?b.data[c?.dataKey]:b.data,_=ee(g,c);return{block:e,successful:!0,output:{data:_,raw:b,statusCode:b?.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:$}}},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()],fe=T.object({r:T.record(T.string(),T.object({n:T.number().optional(),c:T.string().optional(),p:T.number().optional()})),v:T.number(),t:T.number()}),be=e=>A(JSON.stringify(ge(e))),ge=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}},_e=e=>{const t=E(e);try{const e=JSON.parse(t),r=fe.parse(e);return he(r)}catch{return null}},he=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}},ve=(e,t)=>{const r="string"==typeof e?_e(e):e,n="string"==typeof t?_e(t):t;if(null===r||null===n)return r===n;const{timestamp:o,...s}=r,{timestamp:a,...i}=n;return K(s)===K(i)};export{W as AUTHENTICATION_SCHEMA,ue as StepFunctionName,de as StepFunctionsFactory,ve as areCursorsEqual,_e as expandCursor,me as getCategoryDetails,ye as isValidCategory,be as minifyCursor};
|
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()}),_=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}},A=e=>Object.values(S).includes(e),F=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:a}=r;A(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;A(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 T;exports.StepFunctionName=void 0,(T=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",T.MAP_FIELDS="map_fields",T.GROUP_DATA="group_data",T.REQUEST="request";const j={[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=>F(e,t))):F(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}=b.parse(i),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,m=f.parse(y),g=p?o.parseRequestParameters(p):{query:{},body:{},headers:{}},_=o.createAuthorizationHeaders(m),h={...g?.headers??{},..._};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:b,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}}},B=(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},E={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=j}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:B(n,e)}:n}},N={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}};exports.AUTHENTICATION_SCHEMA=f,exports.StepFunctionsFactory=E,exports.getCategoryDetails=e=>N[e.toLowerCase()]??null,exports.isValidCategory=e=>!!N[e.toLowerCase()];
|
|
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 N={[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}}},T=(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},E={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=N}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:T(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"}},w=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()}),M=e=>{const{remote:t,version:r,timestamp:o}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:o}])=>[e,{n:t,c:r,p:o}]))),v:r,t:o}},K=t=>{const r=e.decodeFromBase64(t);try{const e=JSON.parse(r),t=w.parse(e);return O(t)}catch{return null}},O=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=E,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?K(t):t,n="string"==typeof r?K(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=K,exports.getCategoryDetails=e=>B[e.toLowerCase()]??null,exports.isValidCategory=e=>!!B[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify(M(t)));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IHttpClient } from '@stackone/transport';
|
|
2
2
|
import { Category } from '../categories/types';
|
|
3
3
|
import { Connector, Operation, OperationType } from '../connector/types';
|
|
4
|
+
import { Cursor } from '../cursor/types';
|
|
4
5
|
import { ILogger } from '../logger/types';
|
|
5
6
|
import type { StepsSnapshots } from '../steps/types';
|
|
6
7
|
export type Block = {
|
|
@@ -16,6 +17,7 @@ export type Block = {
|
|
|
16
17
|
operation?: Operation;
|
|
17
18
|
credentials?: Credentials;
|
|
18
19
|
outputs?: unknown;
|
|
20
|
+
nextCursor?: Cursor;
|
|
19
21
|
response?: {
|
|
20
22
|
statusCode: number;
|
|
21
23
|
successful: boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Cursor } from './types';
|
|
2
|
+
export declare const minifyCursor: (cursor: Cursor) => string;
|
|
3
|
+
export declare const expandCursor: (minifiedCursor: string) => Cursor | null;
|
|
4
|
+
export declare const areCursorsEqual: (first: string | Cursor, second: string | Cursor) => boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const MINIFIED_CURSOR_SCHEMA: z.ZodObject<{
|
|
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>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
n?: number | undefined;
|
|
9
|
+
c?: string | undefined;
|
|
10
|
+
p?: number | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
n?: number | undefined;
|
|
13
|
+
c?: string | undefined;
|
|
14
|
+
p?: number | undefined;
|
|
15
|
+
}>>;
|
|
16
|
+
v: z.ZodNumber;
|
|
17
|
+
t: z.ZodNumber;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
r: Record<string, {
|
|
20
|
+
n?: number | undefined;
|
|
21
|
+
c?: string | undefined;
|
|
22
|
+
p?: number | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
v: number;
|
|
25
|
+
t: number;
|
|
26
|
+
}, {
|
|
27
|
+
r: Record<string, {
|
|
28
|
+
n?: number | undefined;
|
|
29
|
+
c?: string | undefined;
|
|
30
|
+
p?: number | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
v: number;
|
|
33
|
+
t: number;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type Position = {
|
|
2
|
+
pageNumber?: number;
|
|
3
|
+
providerPageCursor?: string;
|
|
4
|
+
position?: number;
|
|
5
|
+
};
|
|
6
|
+
type MinifiedPosition = {
|
|
7
|
+
n?: number;
|
|
8
|
+
c?: string;
|
|
9
|
+
p?: number;
|
|
10
|
+
};
|
|
11
|
+
export type Cursor = {
|
|
12
|
+
remote: Record<number, Position>;
|
|
13
|
+
version: number;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
};
|
|
16
|
+
export type MinifiedCursor = {
|
|
17
|
+
r: Record<number, MinifiedPosition>;
|
|
18
|
+
v: number;
|
|
19
|
+
t: number;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { Connector, Operation, OperationType, OperationResponse, Authentication,
|
|
|
10
10
|
export { AUTHENTICATION_SCHEMA } from './stepFunctions/request/schemas';
|
|
11
11
|
export { ILogger } from './logger/types';
|
|
12
12
|
export type { Account } from './accounts/types';
|
|
13
|
+
export type { Cursor } from './cursor/types';
|
|
14
|
+
export { expandCursor, minifyCursor, areCursorsEqual } from './cursor';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
AccountConnectorNotFoundError = 0,
|
|
3
|
+
AccountCreationError = 1,
|
|
4
|
+
AccountCumulativeLinkedAccountsError = 2,
|
|
5
|
+
AccountIntegrationInactiveError = 3,
|
|
6
|
+
AccountRemoveError = 4,
|
|
7
|
+
AccountSoftDeleteError = 5,
|
|
8
|
+
AccountTriggerTokenCreationError = 6,
|
|
9
|
+
AccountUpdateCredentialsError = 7,
|
|
10
|
+
AccountUpdateError = 8,
|
|
11
|
+
AdvancedLogSettingsError = 9,
|
|
12
|
+
AdvancedLogSettingsParseError = 10,
|
|
13
|
+
AdvancedLogWriteError = 11,
|
|
14
|
+
AsyncCallsHandlerError = 12,
|
|
15
|
+
AsyncCallsInitializationError = 13,
|
|
16
|
+
AsyncCallsQueueLifecycleError = 14,
|
|
17
|
+
AsyncCallsSubscribeError = 15,
|
|
18
|
+
AsyncCallsWorkerError = 16,
|
|
19
|
+
BackgroundCallsConsumerError = 17,
|
|
20
|
+
BundleResponseDataExtractionError = 18,
|
|
21
|
+
CacheClientCommandError = 19,
|
|
22
|
+
CacheClientDeleteError = 20,
|
|
23
|
+
CacheClientError = 21,
|
|
24
|
+
CacheClientInvalidTTL = 22,
|
|
25
|
+
CacheClientListError = 23,
|
|
26
|
+
CacheClientNotInitialized = 24,
|
|
27
|
+
CacheClientPublishError = 25,
|
|
28
|
+
CacheClientReadError = 26,
|
|
29
|
+
CacheClientRedisNotReady = 27,
|
|
30
|
+
CacheClientScriptError = 28,
|
|
31
|
+
CacheClientScriptExecuteError = 29,
|
|
32
|
+
CacheClientScriptLoadError = 30,
|
|
33
|
+
CacheClientSubscribeError = 31,
|
|
34
|
+
CacheClientUnsubscribeError = 32,
|
|
35
|
+
CacheClientWriteError = 33,
|
|
36
|
+
ConcurrencyManagerInitializationError = 34,
|
|
37
|
+
ConcurrencyManagerRedisEventsEmitError = 35,
|
|
38
|
+
ConcurrencyManagerRegistrationFailed = 36,
|
|
39
|
+
ConnectorsRegistryLoadError = 37,
|
|
40
|
+
ConnectorNotFound = 38,
|
|
41
|
+
CursorConfigurationError = 39,
|
|
42
|
+
DataSyncIncrementalRunError = 40,
|
|
43
|
+
DataSyncRequestParamsError = 41,
|
|
44
|
+
DataSyncRunDataDeleteError = 42,
|
|
45
|
+
DataSyncScheduledRunError = 43,
|
|
46
|
+
DecodeBase64Error = 44,
|
|
47
|
+
DynamoDBDeleteItemError = 45,
|
|
48
|
+
DynamoDBGetItemError = 46,
|
|
49
|
+
DynamoDBItemSizeCalculationError = 47,
|
|
50
|
+
DynamoDBItemSizeCheckError = 48,
|
|
51
|
+
DynamoDBPutItemError = 49,
|
|
52
|
+
DynamoDBQueryError = 50,
|
|
53
|
+
EnumValuesParseError = 51,
|
|
54
|
+
EventClientResolveError = 52,
|
|
55
|
+
FeaturesClientError = 53,
|
|
56
|
+
FeaturesClientNotReady = 54,
|
|
57
|
+
FieldConfigListError = 55,
|
|
58
|
+
FieldMappingLambdaInvocationError = 56,
|
|
59
|
+
GetAuthConfigError = 57,
|
|
60
|
+
GlobalExceptionFilterError = 58,
|
|
61
|
+
HttpRequestError = 59,
|
|
62
|
+
HttpTransportInstanceCreateError = 60,
|
|
63
|
+
IntegrationAuthKeyMissing = 61,
|
|
64
|
+
IntegrationCreateError = 62,
|
|
65
|
+
IntegrationRemoveError = 63,
|
|
66
|
+
IntegrationUpdateError = 64,
|
|
67
|
+
InvalidSkipResolveCondition = 65,
|
|
68
|
+
KafkaClientResetError = 66,
|
|
69
|
+
LambdaExecutionError = 67,
|
|
70
|
+
LoadCustomFieldConfigsError = 68,
|
|
71
|
+
LogResponseMiddlewareError = 69,
|
|
72
|
+
MemoryStorePruneError = 70,
|
|
73
|
+
MergeJsonFileError = 71,
|
|
74
|
+
MetadataEvaluationError = 72,
|
|
75
|
+
MigrationError = 73,
|
|
76
|
+
MonitoringJobError = 74,
|
|
77
|
+
MonitoringJobNotFound = 75,
|
|
78
|
+
MonitoringJobRemoveError = 76,
|
|
79
|
+
MonitoringMaintenanceError = 77,
|
|
80
|
+
ObjectSizeCalculationError = 78,
|
|
81
|
+
Oauth2StrategyError = 79,
|
|
82
|
+
OlapClientConsumerError = 80,
|
|
83
|
+
OlapClientIngestionError = 81,
|
|
84
|
+
OlapClientProducerError = 82,
|
|
85
|
+
OlapClientSchemaValidationError = 83,
|
|
86
|
+
OlapRequestLogMiddlewareError = 84,
|
|
87
|
+
OlapRequestLogWriteError = 85,
|
|
88
|
+
OpenIDConnectStrategyError = 86,
|
|
89
|
+
PersistentStoreDeleteAllError = 87,
|
|
90
|
+
PersistentStoreDeleteError = 88,
|
|
91
|
+
PersistentStoreWriteConfigError = 89,
|
|
92
|
+
ProcessorInvalidAction = 90,
|
|
93
|
+
QueueManagerInitializationError = 91,
|
|
94
|
+
QueueManagerJoinAndWaitTurnError = 92,
|
|
95
|
+
QueueManagerLengthError = 93,
|
|
96
|
+
QueueManagerPopError = 94,
|
|
97
|
+
RateLimitManagerInitializationError = 95,
|
|
98
|
+
RateLimiterReleaseRequestFailed = 96,
|
|
99
|
+
RedisClientError = 97,
|
|
100
|
+
RefreshTokenMissingProject = 98,
|
|
101
|
+
S3StorageUploadError = 99,
|
|
102
|
+
ScriptManagerExecutionError = 100,
|
|
103
|
+
ScriptManagerLoadingError = 101,
|
|
104
|
+
SecretsDecryptionError = 102,
|
|
105
|
+
SecretsEncryptionError = 103,
|
|
106
|
+
SecretsKeyRetrievalError = 104,
|
|
107
|
+
SecretsValueEncryptionError = 105,
|
|
108
|
+
SettingsReadError = 106,
|
|
109
|
+
StepFunctionExecutionError = 107,
|
|
110
|
+
TemporaryStoreWriteConfigError = 108,
|
|
111
|
+
TokenMaintenanceError = 109,
|
|
112
|
+
UnifiedRequestInterceptorError = 110,
|
|
113
|
+
UncaughtExceptionError = 111,
|
|
114
|
+
UnhandledRejectionError = 112,
|
|
115
|
+
VersionNotSupported = 113,
|
|
116
|
+
WebhookActiveCheckOperationNotFound = 114,
|
|
117
|
+
WebhookConfigNotFound = 115,
|
|
118
|
+
WebhookEventsInitializationError = 116,
|
|
119
|
+
WebhookProcessorError = 117,
|
|
120
|
+
WebhookReceiverRemoveError = 118,
|
|
121
|
+
WebhookSigningSecretNotFound = 119,
|
|
122
|
+
WriteJsonFileError = 120
|
|
123
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorCode } from './codes';
|
|
1
2
|
export interface ILogger {
|
|
2
3
|
debug({ category, message, traceId, context, }: {
|
|
3
4
|
category?: string;
|
|
@@ -11,17 +12,20 @@ export interface ILogger {
|
|
|
11
12
|
traceId?: string;
|
|
12
13
|
context?: Record<string, unknown>;
|
|
13
14
|
}): void;
|
|
14
|
-
warning({ category, message, traceId, context, }: {
|
|
15
|
+
warning({ category, message, traceId, error, code, context, }: {
|
|
15
16
|
category?: string;
|
|
16
17
|
message: string;
|
|
17
18
|
traceId?: string;
|
|
19
|
+
error?: LogError;
|
|
20
|
+
code?: ErrorCode;
|
|
18
21
|
context?: Record<string, unknown>;
|
|
19
22
|
}): void;
|
|
20
|
-
error({ category, message, traceId, error, context, }: {
|
|
23
|
+
error({ category, message, traceId, error, code, context, }: {
|
|
21
24
|
category?: string;
|
|
22
25
|
message: string;
|
|
23
26
|
traceId?: string;
|
|
24
27
|
error?: LogError;
|
|
28
|
+
code: ErrorCode;
|
|
25
29
|
context?: Record<string, unknown>;
|
|
26
30
|
}): void;
|
|
27
31
|
}
|