@stackone/core 1.49.2 → 1.51.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/README.md +1 -1
- package/dist/index.es.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/types/blocks/types.d.ts +1 -1
- package/dist/types/connector/types.d.ts +22 -0
- package/dist/types/index.d.ts +15 -15
- package/package.json +2 -2
- package/dist/types/logger/types.d.ts +0 -53
package/README.md
CHANGED
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{notMissing as e,getCountrySubDivisionNameBySubDivisionCode as t,getCountryAlpha2CodeByCitizenship as r,getCountrySubDivisionCodeBySubDivisionName as o,getCountrySubDivisionsByAlpha2Code as n,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 g,getCountryNameByAlpha2Code as y,getCountryNameByAlpha3Code as b,getCountryNameByCountryName as f,getCountryCodeByCountryCode as h,getCountryAlpha3CodeByAlpha3Code as _,getCountryAlpha2CodeByAlpha2Code as v,isString as k,isMissing as E,safeParseToDateTimeString as S,safeParseToBoolean as I,safeParseToNumber as w,safeParseToString as x,encodeToBase64 as j,decodeFromBase64 as C,getContentHash as F}from"@stackone/utils";import{z as T}from"zod";import{evaluate as O,safeEvaluateRecord as R}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as A,RequestParameterLocations as D,HttpMethods as K,RequestClientFactory as N,parseRequestParameters as P,createAuthorizationHeaders as $}from"@stackone/transport";const M=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),U=T.object({data:T.unknown()}),q=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const s=n?.output?.data;return Array.isArray(s)&&s.length===t?e[o]={output:{data:s[r]}}:e[o]=n,e}),{}),G=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],a={...e};for(const r of t){const{error:t,value:i}=L(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},L=(e,t,r)=>{const{expression:o,targetFieldKey:n}=r;if(!o)return{error:{message:"Expression is empty",id:t,targetField:n}};let s;try{s=O(o,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:s}},B=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),expression:T.string(),type:T.enum(["string","number","boolean","datetime_string","enum"]),custom:T.boolean().default(!1),hidden:T.boolean().default(!1),enumMapper:T.object({matcher:T.string().or(T.object({matchExpression:T.string(),value:T.string()}).array())}).optional()}).array(),dataSource:T.string()}),H=T.object({data:T.unknown()}),z=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:a}=W(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=a:n[s.targetFieldKey]=a}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},W=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Q(r,t,e);case"enum":return Y(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Q=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let o;try{o=O(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:o}},Y=(E,S,I)=>{const w=Q(E,S,I),x=e(w.value)?w.value:null;if(void 0===E.enumMapper)return{error:{message:"Enum mapper was not defined",id:S,targetField:E.targetFieldKey}};const j=E.enumMapper.matcher;if(k(j)){const k=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return v;case"country_alpha3code_by_alpha3code":return _;case"country_code_by_country_code":return h;case"country_name_by_country_name":return f;case"country_name_by_alpha3code":return b;case"country_name_by_alpha2code":return y;case"country_name_by_country_code":return g;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 n;case"country_subdivision_code_by_subdivision_name":return o;case"country_alpha2code_by_citizenship":return r;case"country_subdivision_name_by_subdivision_code":return t;default:return}})(j);if(e(k)){return{value:{value:(e(x)?k(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${j}" is not supported`,id:S,targetField:E.targetFieldKey}}}for(const e of j){const{matchExpression:t,value:r}=e;if(!0===O(t,I))return{value:{value:r,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},J=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),V=T.object({type:T.literal("bearer"),token:T.string()}),X=T.discriminatedUnion("type",[J,V]),Z=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(K),response:T.object({indexField:T.string().optional(),dataKey:T.string().optional(),nextKey:T.string().optional()}).optional(),iterator:T.object({key:T.string(),in:T.enum(D)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),customErrors:A.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(D),condition:T.string().optional()}).array().optional()}),ee=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),te=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},re=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),oe=T.object({type:T.literal("bearer"),token:T.string()}),ne=T.discriminatedUnion("type",[re,oe]),se=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(K),response:T.object({collection:T.boolean().optional(),indexField:T.string().optional(),dataKey:T.string().optional()}).optional(),customErrors:A.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(D),condition:T.string().optional()}).array().optional()}),ae=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional()}).optional(),ie=(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},ue=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),type:T.string(),custom:T.boolean().default(!1),hidden:T.boolean().default(!1)}).array().optional(),dataSource:T.string()}),ce=T.object({data:T.unknown()});var le;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(le||(le={}));const de=({value:e,type:t,format:r})=>{if(E(e))return null;switch(t){case le.String:return x({value:e});case le.Number:return w({value:e});case le.Boolean:return I({value:e});case le.DateTimeString:return S({value:e,format:r});default:return e}},pe=e=>Object.values(le).includes(e),me=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;pe(s)&&(!r.custom&&e(o[n])?o[n]=de({value:t[n],type:s}):o.unified_custom_fields&&e(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=de({value:t.unified_custom_fields?.[n],type:s})))})),{...o}},ge=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;pe(s)&&(!r.custom&&e(o[n])?o[n]=de({value:t[n],type:s}):o.unified_custom_fields&&e(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=de({value:t.unified_custom_fields?.[n],type:s})))})),{...o}};var ye;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(ye||(ye={}));const be={[ye.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>me(e,t))):me(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:o}=ue.parse(t),n=O(o,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(n)?n.map((e=>ge(e,r))):ge(n,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:ue,outputSchema:ce}},[ye.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const s=e.result.length;n=e.result.map(((e,n)=>{const a=q(o,s,n),i=G(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=G(e.result,t,o);n=s.record,r.push(...s.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:o,dataSource:n}=B.parse(t),s=O(n,e);if(!o||!n||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let a;if(Array.isArray(s))a=s.map((e=>{const t=z(o,e);return r.push(...t?.errors||[]),t?.record}));else{const e=z(o,s);a=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(r).length>0?r:void 0}},inputSchema:B,outputSchema:H}},[ye.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=N.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:o}=t,n=o?o.filter((t=>!t.condition||!0===O(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?R({...t,args:n},e):{},a={...s,customErrors:t?.customErrors},{baseUrl:i,url:u,method:c,response:l,customErrors:d,args:p}=se.parse(a),m=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,g=ne.parse(m),y=p?P(p):{query:{},body:{},headers:{}},b=$(g),f={...y?.headers??{},...b};let h;try{h=await r.performRequest({httpClient:e.httpClient,url:`${i}${u}`,queryParams:y?.query,method:c,headers:f,body:y?.body,customErrorConfigs:d})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const _=l?.dataKey?h.data[l?.dataKey]:h.data,v=ie(_,l);return{block:e,successful:!0,output:{data:v,raw:h,statusCode:h?.status,message:h?.message}}},inputSchema:se,outputSchema:ae}},[ye.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:n}=M.parse(r),s=o.reduce(((r,o)=>{const s=t.steps?.[o]?.output?.data;return s?n?{...r,[o]:{...s}}:(Object.keys(s).forEach((t=>{const n=e(r[t])?r[t]:{};r[t]={...n,[o]:{...s[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:n?s:Object.values(s)}}},inputSchema:M,outputSchema:U}},[ye.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:r})=>{const o=N.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:n}=r,s=Number(t.inputs?.page_size),a=Number.isNaN(s)?25:s,i=n?n.filter((e=>!e.condition||!0===O(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,u=r?R({...r,args:i},t):{},c={...u,customErrors:r?.customErrors},{baseUrl:l,url:d,method:p,response:m,iterator:g,cursor:y,customErrors:b,args:f}=Z.parse(c),h=u?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,_=X.parse(h),v=f?P(f):{query:{},body:{},headers:{}},k=$(_),S={...v?.headers??{},...k};let I=y?.token??null,w=null,x=null,j=[],C=[];const F=[];let T=a,A=y?.position??0,D=!0,K=!0;do{let e;D?D=!1:A=0,null!==I&&("query"===g.in?v.query[g.key]=I.toString():"body"===g.in&&(v.body[g.key]=I));try{e=await o.performRequest({httpClient:t.httpClient,url:`${l}${d}`,queryParams:v?.query,method:p,headers:S,body:v?.body,customErrorConfigs:b})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}w=I,C=m?.dataKey?e.data[m?.dataKey]:e.data;const r=C?.slice(A,T);T-=r.length,A+=r.length,F.push(e),j=j.concat(r),x=e?.status,I=m?.nextKey?e.data[m?.nextKey]:void 0,r.length===C.length&&0===T&&(A=0,w=I),K=E(I)&&j.length<a}while(e(I)&&j.length<a&&C?.length>0);const M=te(j,m);return{block:t,successful:!0,output:{data:M,raw:F,statusCode:x,next:K?void 0:w,position:K?void 0:A}}},inputSchema:Z,outputSchema:ee}}},fe=(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},he={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=be}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:fe(n,e)}:n}},_e={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}},ve=e=>_e[e.toLowerCase()]??null,ke=e=>!!_e[e.toLowerCase()];var Ee;!function(e){e[e.Trace=0]="Trace",e[e.Debug=1]="Debug",e[e.Info=2]="Info",e[e.Warning=3]="Warning",e[e.Error=4]="Error"}(Ee||(Ee={}));const Se=T.object({r:T.record(T.string(),T.object({n:T.number().optional().nullable(),c:T.string().optional().nullable(),p:T.number().optional().nullable()})),v:T.number(),t:T.number()}),Ie=T.object({remote:T.record(T.string(),T.object({pageNumber:T.number().optional(),providerPageCursor:T.string().optional(),position:T.number().optional()})),version:T.number(),timestamp:T.number()}),we=e=>j(JSON.stringify(xe(e))),xe=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}},je=e=>{try{if(k(e)){const t=C(e),r=JSON.parse(t),o=Se.parse(r);return Ce(o)}return Ie.parse(e),e}catch{return null}},Ce=e=>{const{r:t,v:r,t:o}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:o}])=>[e,{pageNumber:t,providerPageCursor:r,position:o}]))),version:r,timestamp:o}},Fe=(e,t)=>{const r="string"==typeof e?je(e):e,o="string"==typeof t?je(t):t;if(null===r||null===o)return r===o;const{timestamp:n,...s}=r,{timestamp:a,...i}=o;return F(s)===F(i)},Te=({cursor:e,ignoreStepIndex:t})=>!!E(e)||Object.keys(e?.remote??{}).reduce(((r,o)=>{const n=e?.remote?.[o];return(E(t)||o!==t.toString())&&(r=r&&E(n.pageNumber)&&E(n.position)&&E(n.providerPageCursor)),r}),!0),Oe=({cursor:e,stepIndex:t,pageNumber:r,providerPageCursor:o,position:n})=>{const s={pageNumber:r??void 0,providerPageCursor:o??void 0,position:n??void 0},a=E(r)&&E(o)&&E(n);return E(e)?{remote:a?{}:{[t]:s},version:2,timestamp:Date.now()}:a?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:s}}};class Re extends Error{constructor({category:e,name:t,type:r,context:o,message:n}){super(n),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,Re)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const Ae=e=>e instanceof Re,De=j("so1!"),Ke=":",Ne=",",Pe=new RegExp(`(?<!\\\\)${Ke}`,"g"),$e=new RegExp(`(?<!\\\\)${Ne}`,"g"),Me=1;class Ue extends Re{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class qe extends Ue{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class Ge extends Ue{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class Le extends Ue{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Be extends Ue{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const He=(e,t={version:1})=>{if(1===t.version)return Ve(We(e,t.aliases));throw new Be(`Cannot generate ID, unsupported version number: ${t.version}`)},ze=(e,t={version:1})=>{const r=Je(e,t),o={};return r?(r.split($e).forEach((e=>{const[r,n]=e.split(Pe),s=Ye(r,t.aliases??{});o[s]=et(n)})),o):o},We=(e,t={})=>{if((e=>!E(e)&&"value"in e&&void 0!==e.value)(e))return Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if((e=>!E(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>Qe({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1}))).join(Ne);throw new Le},Qe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,Ze(e.value)].filter(Boolean).join(Ke),Ye=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,Je=(e,t)=>{if(1===t.version)return Xe(e);throw new Be(`Cannot decode ID, unsupported version number: ${t.version}`)},Ve=e=>`${De}${j(e)}`,Xe=e=>{if(!e.startsWith(De))throw new qe(`Trying to decode an ID without the header: ${e}`);const t=e.split(De)[1];if(!t)throw new Ge(`Trying to decode an ID without a body: ${e}`);return C(t)},Ze=e=>[Ne,Ke].reduce(((e,t)=>e.replace(t,"\\"+t)),e),et=e=>[Ne,Ke].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),tt=e=>!E(e)&&e.startsWith(De);export{ne as AUTHENTICATION_SCHEMA,Me as COMPOSITE_ID_LATEST_VERSION,Re as CoreError,Ee as LogLevel,ye as StepFunctionName,he as StepFunctionsFactory,Fe as areCursorsEqual,ze as decodeCompositeId,He as encodeCompositeId,je as expandCursor,ve as getCategoryDetails,tt as isCompositeId,Ae as isCoreError,Te as isCursorEmpty,ke as isValidCategory,we as minifyCursor,Oe as updateCursor};
|
|
1
|
+
export{LogLevel}from"@stackone/logger";import{encodeToBase64 as e,isMissing as t,decodeFromBase64 as r,getContentHash as o,isString as n,notMissing as s,getCountrySubDivisionNameBySubDivisionCode as a,getCountryAlpha2CodeByCitizenship as i,getCountrySubDivisionCodeBySubDivisionName as u,getCountrySubDivisionsByAlpha2Code as c,getCountryCodeByCountryName as l,getCountryCodeByAlpha3Code as d,getCountryCodeByAlpha2Code as p,getCountryAlpha2CodeByCountryCode as m,getCountryAlpha2CodeByCountryName as g,getCountryAlpha2CodeByAlpha3Code as y,getCountryAlpha3CodeByCountryCode as b,getCountryAlpha3CodeByCountryName as f,getCountryAlpha3CodeByAlpha2Code as h,getCountryNameByCountryCode as _,getCountryNameByAlpha2Code as v,getCountryNameByAlpha3Code as k,getCountryNameByCountryName as S,getCountryCodeByCountryCode as E,getCountryAlpha3CodeByAlpha3Code as I,getCountryAlpha2CodeByAlpha2Code as w,safeParseToDateTimeString as x,safeParseToBoolean as C,safeParseToNumber as j,safeParseToString as F}from"@stackone/utils";import{z as T}from"zod";import{evaluate as A,safeEvaluateRecord as O}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as P,RequestParameterLocations as R,HttpMethods as D,RequestClientFactory as K,parseRequestParameters as N,createAuthorizationHeaders as M}from"@stackone/transport";const $={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}},U=e=>$[e.toLowerCase()]??null,q=e=>!!$[e.toLowerCase()],L=e("so1!"),z=":",H=",",G=new RegExp(`(?<!\\\\)${z}`,"g"),B=new RegExp(`(?<!\\\\)${H}`,"g"),Q=1;class W extends Error{constructor({category:e,name:t,type:r,context:o,message:n}){super(n),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,W)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class Y extends W{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class J extends Y{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class V extends Y{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class X extends Y{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class Z extends Y{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const ee=(e,t={version:1})=>{if(1===t.version)return ae(re(e,t.aliases));throw new Z(`Cannot generate ID, unsupported version number: ${t.version}`)},te=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(B).forEach((e=>{const[r,n]=e.split(G),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},re=(e,r={})=>{if((e=>!t(e)&&"value"in e&&void 0!==e.value)(e))return oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!0});if((e=>!t(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(H);throw new X},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(z),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,se=(e,t)=>{if(1===t.version)return ie(e);throw new Z(`Cannot decode ID, unsupported version number: ${t.version}`)},ae=t=>`${L}${e(t)}`,ie=e=>{if(!e.startsWith(L))throw new J(`Trying to decode an ID without the header: ${e}`);const t=e.split(L)[1];if(!t)throw new V(`Trying to decode an ID without a body: ${e}`);return r(t)},ue=e=>[H,z].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[H,z].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),le=e=>!t(e)&&e.startsWith(L),de=T.object({r:T.record(T.string(),T.object({n:T.number().optional().nullable(),c:T.string().optional().nullable(),p:T.number().optional().nullable()})),v:T.number(),t:T.number()}),pe=T.object({remote:T.record(T.string(),T.object({pageNumber:T.number().optional(),providerPageCursor:T.string().optional(),position:T.number().optional()})),version:T.number(),timestamp:T.number()}),me=t=>e(JSON.stringify(ge(t))),ge=e=>{const{remote:t,version:r,timestamp:o}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:o}])=>[e,{n:t,c:r,p:o}]))),v:r,t:o}},ye=e=>{try{if(n(e)){const t=r(e),o=JSON.parse(t),n=de.parse(o);return be(n)}return pe.parse(e),e}catch{return null}},be=e=>{const{r:t,v:r,t:o}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:o}])=>[e,{pageNumber:t,providerPageCursor:r,position:o}]))),version:r,timestamp:o}},fe=(e,t)=>{const r="string"==typeof e?ye(e):e,n="string"==typeof t?ye(t):t;if(null===r||null===n)return r===n;const{timestamp:s,...a}=r,{timestamp:i,...u}=n;return o(a)===o(u)},he=({cursor:e,ignoreStepIndex:r})=>!!t(e)||Object.keys(e?.remote??{}).reduce(((o,n)=>{const s=e?.remote?.[n];return(t(r)||n!==r.toString())&&(o=o&&t(s.pageNumber)&&t(s.position)&&t(s.providerPageCursor)),o}),!0),_e=({cursor:e,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const a={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},i=t(o)&&t(n)&&t(s);return t(e)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete e.remote[r],e):{...e,remote:{...e.remote,[r]:a}}},ve=e=>e instanceof W,ke=T.object({stepsDataToGroup:T.array(T.string()),isSingleRecord:T.boolean().optional()}),Se=T.object({data:T.unknown()}),Ee=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const s=n?.output?.data;return Array.isArray(s)&&s.length===t?e[o]={output:{data:s[r]}}:e[o]=n,e}),{}),Ie=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],a={...e};for(const r of t){const{error:t,value:i}=we(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},we=(e,t,r)=>{const{expression:o,targetFieldKey:n}=r;if(!o)return{error:{message:"Expression is empty",id:t,targetField:n}};let s;try{s=A(o,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:s}},xe=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),expression:T.string(),type:T.enum(["string","number","boolean","datetime_string","enum"]),custom:T.boolean().default(!1),hidden:T.boolean().default(!1),enumMapper:T.object({matcher:T.string().or(T.object({matchExpression:T.string(),value:T.string()}).array())}).optional()}).array(),dataSource:T.string()}),Ce=T.object({data:T.unknown()}),je=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:a}=Fe(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=a:n[s.targetFieldKey]=a}return{record:{...n,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},Fe=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return Te(r,t,e);case"enum":return Ae(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},Te=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let o;try{o=A(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===o?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:o}},Ae=(e,t,r)=>{const o=Te(e,t,r),x=s(o.value)?o.value:null;if(void 0===e.enumMapper)return{error:{message:"Enum mapper was not defined",id:t,targetField:e.targetFieldKey}};const C=e.enumMapper.matcher;if(n(C)){const r=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return w;case"country_alpha3code_by_alpha3code":return I;case"country_code_by_country_code":return E;case"country_name_by_country_name":return S;case"country_name_by_alpha3code":return k;case"country_name_by_alpha2code":return v;case"country_name_by_country_code":return _;case"country_alpha3code_by_alpha2code":return h;case"country_alpha3code_by_country_name":return f;case"country_alpha3code_by_country_code":return b;case"country_alpha2code_by_alpha3code":return y;case"country_alpha2code_by_country_name":return g;case"country_alpha2code_by_country_code":return m;case"country_code_by_alpha2code":return p;case"country_code_by_alpha3code":return d;case"country_code_by_country_name":return l;case"country_subdivisions_by_alpha2code":return c;case"country_subdivision_code_by_subdivision_name":return u;case"country_alpha2code_by_citizenship":return i;case"country_subdivision_name_by_subdivision_code":return a;default:return}})(C);if(s(r)){return{value:{value:(s(x)?r(x):null)??"unmapped_value",source_value:x}}}return{error:{message:`The built-in matcher "${C}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(const e of C){const{matchExpression:t,value:o}=e;if(!0===A(t,r))return{value:{value:o,source_value:x}}}return{value:{value:"unmapped_value",source_value:x}}},Oe=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),Pe=T.object({type:T.literal("bearer"),token:T.string()}),Re=T.discriminatedUnion("type",[Oe,Pe]),De=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({indexField:T.string().optional(),dataKey:T.string().optional(),nextKey:T.string().optional()}).optional(),iterator:T.object({key:T.string(),in:T.enum(R)}),cursor:T.object({token:T.string().optional().nullable(),position:T.number().optional().nullable()}).optional(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Ke=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional(),next:T.string().optional().nullable(),position:T.number().optional()}).optional(),Ne=(e,t)=>{const r=De.parse(e),o=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=Re.parse(o),s=r.args?N(r.args):{query:{},body:{},headers:{}},a=M(n),i={...s?.headers??{},...a},u=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:s,requestHeaders:i,pageSize:u}}},Me=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},$e=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,n=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-n.length,r.pagePosition=r.pagePosition+n.length,r.raw.push(e),r.data=r.data.concat(n),r.lastStatusCode=e?.status,{resultData:o,slicedData:n}},Ue=(e,r,o,n,s,a)=>{const i=r?.nextKey?e.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,n.length===s.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=t(o.nextIterator)&&o.data.length<a},qe=(e,t,r)=>s(e.nextIterator)&&e.data.length<t&&r?.length>0,Le=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},ze=T.object({type:T.literal("basic"),username:T.string().optional(),password:T.string().optional(),encoding:T.string().optional()}),He=T.object({type:T.literal("bearer"),token:T.string()}),Ge=T.discriminatedUnion("type",[ze,He]),Be=T.object({baseUrl:T.string(),url:T.string(),method:T.enum(D),response:T.object({collection:T.boolean().optional(),indexField:T.string().optional(),dataKey:T.string().optional()}).optional(),customErrors:P.array().optional(),args:T.object({name:T.string(),value:T.unknown(),in:T.enum(R),condition:T.string().optional()}).array().optional()}),Qe=T.object({data:T.unknown().optional(),raw:T.unknown().optional(),statusCode:T.number(),message:T.string().optional()}).optional(),We=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},Ye=T.object({fields:T.object({targetFieldKey:T.string(),alias:T.string().optional(),type:T.string(),custom:T.boolean().default(!1),hidden:T.boolean().default(!1)}).array().optional(),dataSource:T.string()}),Je=T.object({data:T.unknown()});var Ve;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(Ve||(Ve={}));const Xe=({value:e,type:r,format:o})=>{if(t(e))return null;switch(r){case Ve.String:return F({value:e});case Ve.Number:return j({value:e});case Ve.Boolean:return C({value:e});case Ve.DateTimeString:return x({value:e,format:o});default:return e}},Ze=e=>Object.values(Ve).includes(e),et=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}},tt=(e,t)=>{const r={...e};return t.forEach((t=>{const{targetFieldKey:o,type:n}=t;Ze(n)&&(!t.custom&&s(r[o])?r[o]=Xe({value:e[o],type:n}):r.unified_custom_fields&&s(r.unified_custom_fields?.[o])&&(r.unified_custom_fields[o]=Xe({value:e.unified_custom_fields?.[o],type:n})))})),{...r}};var rt;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields",e.GROUP_DATA="group_data",e.REQUEST="request",e.PAGINATED_REQUEST="paginated_request"}(rt||(rt={}));const ot={[rt.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>et(e,t))):et(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:o}=Ye.parse(t),n=A(o,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let s;return s=Array.isArray(n)?n.map((e=>tt(e,r))):tt(n,r),{block:{...e},successful:!0,output:{data:s}}},inputSchema:Ye,outputSchema:Je}},[rt.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const s=e.result.length;n=e.result.map(((e,n)=>{const a=Ee(o,s,n),i=Ie(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const s=Ie(e.result,t,o);n=s.record,r.push(...s.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:o,dataSource:n}=xe.parse(t),s=A(n,e);if(!o||!n||"disabled"===e?.debug?.custom_mappings||!s)return{block:e,successful:!0};let a;if(Array.isArray(s))a=s.map((e=>{const t=je(o,e);return r.push(...t?.errors||[]),t?.record}));else{const e=je(o,s);a=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(r).length>0?r:void 0}},inputSchema:xe,outputSchema:Ce}},[rt.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:o}=t,n=o?o.filter((t=>!t.condition||!0===A(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,s=t?O({...t,args:n},e):{},a={...s,customErrors:t?.customErrors},{baseUrl:i,url:u,method:c,response:l,customErrors:d,args:p}=Be.parse(a),m=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,g=Ge.parse(m),y=p?N(p):{query:{},body:{},headers:{}},b=M(g),f={...y?.headers??{},...b};let h;try{h=await r.performRequest({httpClient:e.httpClient,url:`${i}${u}`,queryParams:y?.query,method:c,headers:f,body:y?.body,customErrorConfigs:d})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const _=l?.dataKey?h.data[l?.dataKey]:h.data,v=We(_,l);return{block:e,successful:!0,output:{data:v,raw:h,statusCode:h?.status,message:h?.message}}},inputSchema:Be,outputSchema:Qe}},[rt.GROUP_DATA]:{v1:{fn:async({block:e,params:t})=>{const{stepsDataToGroup:r,isSingleRecord:o}=ke.parse(t),n=r.reduce(((t,r)=>{const n=e.steps?.[r]?.output?.data;return n?o?{...t,[r]:{...n}}:(Object.keys(n).forEach((e=>{const o=s(t[e])?t[e]:{};t[e]={...o,[r]:{...n[e]}}})),t):t}),{});return{block:{...e},successful:!0,output:{data:o?n:Object.values(n)}}},inputSchema:ke,outputSchema:Se}},[rt.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=K.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const o=((e,t)=>{const{args:r}=e,o=r?r.filter((e=>!e.condition||!0===A(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?O({...e,args:o},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:n,preparedRequest:s}=Ne(o,e),a=(i=n.cursor,u=s.pageSize,{nextIterator:i?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:u,pagePosition:i?.position??0,firstPage:!0,noMoreData:!0});var i,u,c,l,d;do{a.firstPage?a.firstPage=!1:a.pagePosition=0,c=s.parsedArgs,l=n.iterator,null!==(d=a.nextIterator)&&("query"===l.in?c.query[l.key]=d.toString():"body"===l.in&&(c.body[l.key]=d));const t=await Me(r,e,n,s);if("successful"in t&&!1===t.successful)return t;const o=t;a.lastUsedIterator=a.nextIterator;const{resultData:i,slicedData:u}=$e(o,n.response,a);Ue(o,n.response,a,u,i,s.pageSize)}while(qe(a,s.pageSize,a.data));return((e,t,r)=>({block:e,successful:!0,output:{data:Le(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,a,n.response)},inputSchema:De,outputSchema:Ke}}},nt=(e,t)=>async({block:r,params:o})=>{try{e.inputSchema&&e.inputSchema.parse(o)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const n=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(n.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return n},st={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=ot}){const n=o?.[e]?.[`v${t}`];if(!n)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...n,fn:nt(n,e)}:n}};export{Ge as AUTHENTICATION_SCHEMA,Q as COMPOSITE_ID_LATEST_VERSION,W as CoreError,rt as StepFunctionName,st as StepFunctionsFactory,fe as areCursorsEqual,te as decodeCompositeId,ee as encodeCompositeId,ye as expandCursor,U as getCategoryDetails,le as isCompositeId,ve as isCoreError,he as isCursorEmpty,q as isValidCategory,me as minifyCursor,_e as updateCursor};
|
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()}),s=t.z.object({data:t.z.unknown()}),i=(e,t,r)=>Object.entries(e).reduce(((e,[o,n])=>{const s=n?.output?.data;return Array.isArray(s)&&s.length===t?e[o]={output:{data:s[r]}}:e[o]=n,e}),{}),a=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},n={},s=[],i={...e};for(const r of t){const{error:t,value:a}=u(o,e.id,r);t?s.push(t):r.custom?n[r.targetFieldKey]=a:i[r.targetFieldKey]=a}return{record:{...i,unified_custom_fields:Object.keys(n).length>0?n:void 0},errors:s.length>0?s:void 0}},u=(e,t,o)=>{const{expression:n,targetFieldKey:s}=o;if(!n)return{error:{message:"Expression is empty",id:t,targetField:s}};let i;try{i=r.evaluate(n,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:s}}}return void 0===i?{error:{message:"Expression returned no value",id:t,targetField:s}}:{value:i}},c=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),alias:t.z.string().optional(),expression:t.z.string(),type:t.z.enum(["string","number","boolean","datetime_string","enum"]),custom:t.z.boolean().default(!1),hidden:t.z.boolean().default(!1),enumMapper:t.z.object({matcher:t.z.string().or(t.z.object({matchExpression:t.z.string(),value:t.z.string()}).array())}).optional()}).array(),dataSource:t.z.string()}),l=t.z.object({data:t.z.unknown()}),d=(e,t)=>{if(!t)return;const r={},o=[],n={};for(const s of e){const{error:e,value:i}=p(t,t?.id,s);e?o.push(e):s.custom?r[s.targetFieldKey]=i:n[s.targetFieldKey]=i}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 m(r,t,e);case"enum":return g(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},m=(e,t,o)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let n;try{n=r.evaluate(e.expression,o)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===n?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:n}},g=(t,o,n)=>{const s=m(t,o,n),i=e.notMissing(s.value)?s.value:null;if(void 0===t.enumMapper)return{error:{message:"Enum mapper was not defined",id:o,targetField:t.targetFieldKey}};const a=t.enumMapper.matcher;if(e.isString(a)){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}})(a);if(e.notMissing(r)){return{value:{value:(e.notMissing(i)?r(i):null)??"unmapped_value",source_value:i}}}return{error:{message:`The built-in matcher "${a}" is not supported`,id:o,targetField:t.targetFieldKey}}}for(const e of a){const{matchExpression:t,value:o}=e;if(!0===r.evaluate(t,n))return{value:{value:o,source_value:i}}}return{value:{value:"unmapped_value",source_value:i}}},y=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),b=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),h=t.z.discriminatedUnion("type",[y,b]),f=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({indexField:t.z.string().optional(),dataKey:t.z.string().optional(),nextKey:t.z.string().optional()}).optional(),iterator:t.z.object({key:t.z.string(),in:t.z.enum(o.RequestParameterLocations)}),cursor:t.z.object({token:t.z.string().optional().nullable(),position:t.z.number().optional().nullable()}).optional(),customErrors:o.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),_=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),message:t.z.string().optional(),next:t.z.string().optional().nullable(),position:t.z.number().optional()}).optional(),v=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},C=t.z.object({type:t.z.literal("basic"),username:t.z.string().optional(),password:t.z.string().optional(),encoding:t.z.string().optional()}),z=t.z.object({type:t.z.literal("bearer"),token:t.z.string()}),S=t.z.discriminatedUnion("type",[C,z]),E=t.z.object({baseUrl:t.z.string(),url:t.z.string(),method:t.z.enum(o.HttpMethods),response:t.z.object({collection:t.z.boolean().optional(),indexField:t.z.string().optional(),dataKey:t.z.string().optional()}).optional(),customErrors:o.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:t.z.object({name:t.z.string(),value:t.z.unknown(),in:t.z.enum(o.RequestParameterLocations),condition:t.z.string().optional()}).array().optional()}),x=t.z.object({data:t.z.unknown().optional(),raw:t.z.unknown().optional(),statusCode:t.z.number(),message:t.z.string().optional()}).optional(),k=(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},I=t.z.object({fields:t.z.object({targetFieldKey:t.z.string(),alias:t.z.string().optional(),type:t.z.string(),custom:t.z.boolean().default(!1),hidden:t.z.boolean().default(!1)}).array().optional(),dataSource:t.z.string()}),A=t.z.object({data:t.z.unknown()});var F;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(F||(F={}));const T=({value:t,type:r,format:o})=>{if(e.isMissing(t))return null;switch(r){case F.String:return e.safeParseToString({value:t});case F.Number:return e.safeParseToNumber({value:t});case F.Boolean:return e.safeParseToBoolean({value:t});case F.DateTimeString:return e.safeParseToDateTimeString({value:t,format:o});default:return t}},w=e=>Object.values(F).includes(e),M=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(!r.custom&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}},N=(t,r)=>{const o={...t};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;w(s)&&(!r.custom&&e.notMissing(o[n])?o[n]=T({value:t[n],type:s}):o.unified_custom_fields&&e.notMissing(o.unified_custom_fields?.[n])&&(o.unified_custom_fields[n]=T({value:t.unified_custom_fields?.[n],type:s})))})),{...o}};var R;exports.StepFunctionName=void 0,(R=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",R.MAP_FIELDS="map_fields",R.GROUP_DATA="group_data",R.REQUEST="request",R.PAGINATED_REQUEST="paginated_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=>M(e,t))):M(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:o,dataSource:n}=I.parse(t),s=r.evaluate(n,e);if(!o||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let i;return i=Array.isArray(s)?s.map((e=>N(e,o))):N(s,o),{block:{...e},successful:!0,output:{data:i}}},inputSchema:I,outputSchema:A}},[exports.StepFunctionName.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let n;if(Array.isArray(e.result)){const s=e.result.length;n=e.result.map(((e,n)=>{const u=i(o,s,n),c=a(e,t,u);return r.push(...c.errors||[]),c.record}))}else{const s=a(e.result,t,o);n=s.record,r.push(...s.errors||[])}return{block:{...e,result:n},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const o=[],{fields:n,dataSource:s}=c.parse(t),i=r.evaluate(s,e);if(!n||!s||"disabled"===e?.debug?.custom_mappings||!i)return{block:e,successful:!0};let a;if(Array.isArray(i))a=i.map((e=>{const t=d(n,e);return o.push(...t?.errors||[]),t?.record}));else{const e=d(n,i);a=e?.record,o.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:a},errors:Object.keys(o).length>0?o:void 0}},inputSchema:c,outputSchema:l}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const n=o.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:s}=t,i=s?s.filter((t=>!t.condition||!0===r.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,a=t?r.safeEvaluateRecord({...t,args:i},e):{},u={...a,customErrors:t?.customErrors},{baseUrl:c,url:l,method:d,response:p,customErrors:m,args:g}=E.parse(u),y=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=S.parse(y),h=g?o.parseRequestParameters(g):{query:{},body:{},headers:{}},f=o.createAuthorizationHeaders(b),_={...h?.headers??{},...f};let v;try{v=await n.performRequest({httpClient:e.httpClient,url:`${c}${l}`,queryParams:h?.query,method:d,headers:_,body:h?.body,customErrorConfigs:m})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const C=p?.dataKey?v.data[p?.dataKey]:v.data,z=k(C,p);return{block:e,successful:!0,output:{data:z,raw:v,statusCode:v?.status,message:v?.message}}},inputSchema:E,outputSchema:x}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:t,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=n.parse(r),i=o.reduce(((r,o)=>{const n=t.steps?.[o]?.output?.data;return n?s?{...r,[o]:{...n}}:(Object.keys(n).forEach((t=>{const s=e.notMissing(r[t])?r[t]:{};r[t]={...s,[o]:{...n[t]}}})),r):r}),{});return{block:{...t},successful:!0,output:{data:s?i:Object.values(i)}}},inputSchema:n,outputSchema:s}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:t,params:n})=>{const s=o.RequestClientFactory.build();if(!t.httpClient)throw new Error("HTTP client is not configured");const{args:i}=n,a=Number(t.inputs?.page_size),u=Number.isNaN(a)?25:a,c=i?i.filter((e=>!e.condition||!0===r.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0,l=n?r.safeEvaluateRecord({...n,args:c},t):{},d={...l,customErrors:n?.customErrors},{baseUrl:p,url:m,method:g,response:y,iterator:b,cursor:_,customErrors:C,args:z}=f.parse(d),S=l?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,E=h.parse(S),x=z?o.parseRequestParameters(z):{query:{},body:{},headers:{}},k=o.createAuthorizationHeaders(E),I={...x?.headers??{},...k};let A=_?.token??null,F=null,T=null,w=[],M=[];const N=[];let R=u,j=_?.position??0,O=!0,P=!0;do{let r;O?O=!1:j=0,null!==A&&("query"===b.in?x.query[b.key]=A.toString():"body"===b.in&&(x.body[b.key]=A));try{r=await s.performRequest({httpClient:t.httpClient,url:`${p}${m}`,queryParams:x?.query,method:g,headers:I,body:x?.body,customErrorConfigs:C})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}F=A,M=y?.dataKey?r.data[y?.dataKey]:r.data;const o=M?.slice(j,R);R-=o.length,j+=o.length,N.push(r),w=w.concat(o),T=r?.status,A=y?.nextKey?r.data[y?.nextKey]:void 0,o.length===M.length&&0===R&&(j=0,F=A),P=e.isMissing(A)&&w.length<u}while(e.notMissing(A)&&w.length<u&&M?.length>0);const D=v(w,y);return{block:t,successful:!0,output:{data:D,raw:N,statusCode:T,next:P?void 0:F,position:P?void 0:j}}},inputSchema:f,outputSchema:_}}},O=(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},P={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:O(n,e)}:n}},D={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}};var B;exports.LogLevel=void 0,(B=exports.LogLevel||(exports.LogLevel={}))[B.Trace=0]="Trace",B[B.Debug=1]="Debug",B[B.Info=2]="Info",B[B.Warning=3]="Warning",B[B.Error=4]="Error";const K=t.z.object({r:t.z.record(t.z.string(),t.z.object({n:t.z.number().optional().nullable(),c:t.z.string().optional().nullable(),p:t.z.number().optional().nullable()})),v:t.z.number(),t:t.z.number()}),q=t.z.object({remote:t.z.record(t.z.string(),t.z.object({pageNumber:t.z.number().optional(),providerPageCursor:t.z.string().optional(),position:t.z.number().optional()})),version:t.z.number(),timestamp:t.z.number()}),$=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}},U=t=>{try{if(e.isString(t)){const r=e.decodeFromBase64(t),o=JSON.parse(r),n=K.parse(o);return L(n)}return q.parse(t),t}catch{return null}},L=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}};class H extends Error{constructor({category:e,name:t,type:r,context:o,message:n}){super(n),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,H)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}const G=e.encodeToBase64("so1!"),W=":",Q=",",V=new RegExp(`(?<!\\\\)${W}`,"g"),Y=new RegExp(`(?<!\\\\)${Q}`,"g");class J extends H{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class X extends J{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class Z extends J{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class ee extends J{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class te extends J{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const re=(t,r={})=>{if((t=>!e.isMissing(t)&&"value"in t&&void 0!==t.value)(t))return oe({identifier:t,compositeIdAliases:r,isSoleIdentifier:!0});if((t=>!e.isMissing(t)&&"identifiers"in t&&void 0!==t.identifiers)(t))return t.identifiers.map((e=>oe({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(Q);throw new ee},oe=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,ue(e.value)].filter(Boolean).join(W),ne=(e,t)=>Object.keys(t).find((r=>t[r]===e))||e,se=(e,t)=>{if(1===t.version)return ae(e);throw new te(`Cannot decode ID, unsupported version number: ${t.version}`)},ie=t=>`${G}${e.encodeToBase64(t)}`,ae=t=>{if(!t.startsWith(G))throw new X(`Trying to decode an ID without the header: ${t}`);const r=t.split(G)[1];if(!r)throw new Z(`Trying to decode an ID without a body: ${t}`);return e.decodeFromBase64(r)},ue=e=>[Q,W].reduce(((e,t)=>e.replace(t,"\\"+t)),e),ce=e=>[Q,W].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e);exports.AUTHENTICATION_SCHEMA=S,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=H,exports.StepFunctionsFactory=P,exports.areCursorsEqual=(t,r)=>{const o="string"==typeof t?U(t):t,n="string"==typeof r?U(r):r;if(null===o||null===n)return o===n;const{timestamp:s,...i}=o,{timestamp:a,...u}=n;return e.getContentHash(i)===e.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=se(e,t),o={};return r?(r.split(Y).forEach((e=>{const[r,n]=e.split(V),s=ne(r,t.aliases??{});o[s]=ce(n)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return ie(re(e,t.aliases));throw new te(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=U,exports.getCategoryDetails=e=>D[e.toLowerCase()]??null,exports.isCompositeId=t=>!e.isMissing(t)&&t.startsWith(G),exports.isCoreError=e=>e instanceof H,exports.isCursorEmpty=({cursor:t,ignoreStepIndex:r})=>!!e.isMissing(t)||Object.keys(t?.remote??{}).reduce(((o,n)=>{const s=t?.remote?.[n];return(e.isMissing(r)||n!==r.toString())&&(o=o&&e.isMissing(s.pageNumber)&&e.isMissing(s.position)&&e.isMissing(s.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!D[e.toLowerCase()],exports.minifyCursor=t=>e.encodeToBase64(JSON.stringify($(t))),exports.updateCursor=({cursor:t,stepIndex:r,pageNumber:o,providerPageCursor:n,position:s})=>{const i={pageNumber:o??void 0,providerPageCursor:n??void 0,position:s??void 0},a=e.isMissing(o)&&e.isMissing(n)&&e.isMissing(s);return e.isMissing(t)?{remote:a?{}:{[r]:i},version:2,timestamp:Date.now()}:a?(delete t.remote[r],t):{...t,remote:{...t.remote,[r]:i}}};
|
|
1
|
+
"use strict";var e=require("@stackone/logger"),t=require("@stackone/utils"),r=require("zod"),o=require("@stackone/expressions"),s=require("@stackone/transport");const n={hris:{title:"HRIS",key:"hris",description:"Human Resource Information System"},crm:{title:"CRM",key:"crm",description:"Customer Relationship Management"},ats:{title:"ATS",key:"ats",description:"Applicant Tracking System"},lms:{title:"LMS",key:"lms",description:"Learning Management System"},marketing:{title:"Marketing",key:"marketing",description:"Marketing"},filestorage:{title:"File Storage",key:"filestorage",description:"File Storage"}},a=t.encodeToBase64("so1!"),i=":",u=",",c=new RegExp(`(?<!\\\\)${i}`,"g"),l=new RegExp(`(?<!\\\\)${u}`,"g");class d extends Error{constructor({category:e,name:t,type:r,context:o,message:s}){super(s),this.name=t??"CoreError",this.type=r,this.category=e,this.context=o,Error.captureStackTrace&&Error.captureStackTrace(this,d)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.category}-${this.name} [${this.type}]${e}`}}class p extends d{constructor(e,t,r){super({category:"CompositeId",name:t??"BaseCompositeIdError",type:e,message:r})}}class g extends p{constructor(e){super("COMPOSITE_ID_MISSING_HEADER_ERROR","CompositeIdMissingHeaderError",e??"Invalid compositeId, missing header")}}class m extends p{constructor(e){super("COMPOSITE_ID_MISSING_BODY_ERROR","CompositeIdMissingBodyError",e??"Invalid compositeId, missing body")}}class y extends p{constructor(e){super("COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR","CompositeIdUnknownIdentifierError",e??"Invalid compositeId, unknown identifier")}}class b extends p{constructor(e){super("COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR","CompositeIdUnsupportedVersionError",e??"Invalid compositeId, unsupported version")}}const f=(e,r={})=>{if((e=>!t.isMissing(e)&&"value"in e&&void 0!==e.value)(e))return h({identifier:e,compositeIdAliases:r,isSoleIdentifier:!0});if((e=>!t.isMissing(e)&&"identifiers"in e&&void 0!==e.identifiers)(e))return e.identifiers.map((e=>h({identifier:e,compositeIdAliases:r,isSoleIdentifier:!1}))).join(u);throw new y},h=({identifier:e,compositeIdAliases:t,isSoleIdentifier:r})=>[r?"id":t[e.key]||e.key,S(e.value)].filter(Boolean).join(i),_=(e,t)=>Object.keys(t).find((r=>t[r]===e))??e,C=(e,t)=>{if(1===t.version)return z(e);throw new b(`Cannot decode ID, unsupported version number: ${t.version}`)},v=e=>`${a}${t.encodeToBase64(e)}`,z=e=>{if(!e.startsWith(a))throw new g(`Trying to decode an ID without the header: ${e}`);const r=e.split(a)[1];if(!r)throw new m(`Trying to decode an ID without a body: ${e}`);return t.decodeFromBase64(r)},S=e=>[u,i].reduce(((e,t)=>e.replace(t,"\\"+t)),e),E=e=>[u,i].reduce(((e,t)=>{const r="\\"+t;return e.replace(new RegExp("\\\\"+r,"g"),t)}),e),x=r.z.object({r:r.z.record(r.z.string(),r.z.object({n:r.z.number().optional().nullable(),c:r.z.string().optional().nullable(),p:r.z.number().optional().nullable()})),v:r.z.number(),t:r.z.number()}),I=r.z.object({remote:r.z.record(r.z.string(),r.z.object({pageNumber:r.z.number().optional(),providerPageCursor:r.z.string().optional(),position:r.z.number().optional()})),version:r.z.number(),timestamp:r.z.number()}),k=e=>{const{remote:t,version:r,timestamp:o}=e;return{r:Object.fromEntries(Object.entries(t).map((([e,{pageNumber:t,providerPageCursor:r,position:o}])=>[e,{n:t,c:r,p:o}]))),v:r,t:o}},A=e=>{try{if(t.isString(e)){const r=t.decodeFromBase64(e),o=JSON.parse(r),s=x.parse(o);return w(s)}return I.parse(e),e}catch{return null}},w=e=>{const{r:t,v:r,t:o}=e;return{remote:Object.fromEntries(Object.entries(t).map((([e,{n:t,c:r,p:o}])=>[e,{pageNumber:t,providerPageCursor:r,position:o}]))),version:r,timestamp:o}},F=r.z.object({stepsDataToGroup:r.z.array(r.z.string()),isSingleRecord:r.z.boolean().optional()}),M=r.z.object({data:r.z.unknown()}),T=(e,t,r)=>Object.entries(e).reduce(((e,[o,s])=>{const n=s?.output?.data;return Array.isArray(n)&&n.length===t?e[o]={output:{data:n[r]}}:e[o]=s,e}),{}),R=(e,t,r)=>{if(!e||!r)return{record:e};const o={unified:{...e},..."object"==typeof r?r:{}},s={},n=[],a={...e};for(const r of t){const{error:t,value:i}=N(o,e.id,r);t?n.push(t):r.custom?s[r.targetFieldKey]=i:a[r.targetFieldKey]=i}return{record:{...a,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:n.length>0?n:void 0}},N=(e,t,r)=>{const{expression:s,targetFieldKey:n}=r;if(!s)return{error:{message:"Expression is empty",id:t,targetField:n}};let a;try{a=o.evaluate(s,e)}catch{return{error:{message:"Invalid expression",id:t,targetField:n}}}return void 0===a?{error:{message:"Expression returned no value",id:t,targetField:n}}:{value:a}},j=r.z.object({fields:r.z.object({targetFieldKey:r.z.string(),alias:r.z.string().optional(),expression:r.z.string(),type:r.z.enum(["string","number","boolean","datetime_string","enum"]),custom:r.z.boolean().default(!1),hidden:r.z.boolean().default(!1),enumMapper:r.z.object({matcher:r.z.string().or(r.z.object({matchExpression:r.z.string(),value:r.z.string()}).array())}).optional()}).array(),dataSource:r.z.string()}),O=r.z.object({data:r.z.unknown()}),P=(e,t)=>{if(!t)return;const r={},o=[],s={};for(const n of e){const{error:e,value:a}=D(t,t?.id,n);e?o.push(e):n.custom?r[n.targetFieldKey]=a:s[n.targetFieldKey]=a}return{record:{...s,unified_custom_fields:Object.keys(r).length>0?r:void 0},errors:o.length>0?o:void 0}},D=(e,t,r)=>{switch(r.type){case"string":case"number":case"boolean":case"datetime_string":return B(r,t,e);case"enum":return q(r,t,e);default:return{error:{message:"Invalid type",id:t,targetField:r.targetFieldKey}}}},B=(e,t,r)=>{if(!e.expression)return{error:{message:"Expression is empty",id:t,targetField:e.targetFieldKey}};let s;try{s=o.evaluate(e.expression,r)}catch{return{error:{message:"Invalid expression",id:t,targetField:e.targetFieldKey}}}return void 0===s?{error:{message:"Expression returned no value",id:t,targetField:e.targetFieldKey}}:{value:s}},q=(e,r,s)=>{const n=B(e,r,s),a=t.notMissing(n.value)?n.value:null;if(void 0===e.enumMapper)return{error:{message:"Enum mapper was not defined",id:r,targetField:e.targetFieldKey}};const i=e.enumMapper.matcher;if(t.isString(i)){const o=(e=>{switch(e){case"country_alpha2code_by_alpha2code":return t.getCountryAlpha2CodeByAlpha2Code;case"country_alpha3code_by_alpha3code":return t.getCountryAlpha3CodeByAlpha3Code;case"country_code_by_country_code":return t.getCountryCodeByCountryCode;case"country_name_by_country_name":return t.getCountryNameByCountryName;case"country_name_by_alpha3code":return t.getCountryNameByAlpha3Code;case"country_name_by_alpha2code":return t.getCountryNameByAlpha2Code;case"country_name_by_country_code":return t.getCountryNameByCountryCode;case"country_alpha3code_by_alpha2code":return t.getCountryAlpha3CodeByAlpha2Code;case"country_alpha3code_by_country_name":return t.getCountryAlpha3CodeByCountryName;case"country_alpha3code_by_country_code":return t.getCountryAlpha3CodeByCountryCode;case"country_alpha2code_by_alpha3code":return t.getCountryAlpha2CodeByAlpha3Code;case"country_alpha2code_by_country_name":return t.getCountryAlpha2CodeByCountryName;case"country_alpha2code_by_country_code":return t.getCountryAlpha2CodeByCountryCode;case"country_code_by_alpha2code":return t.getCountryCodeByAlpha2Code;case"country_code_by_alpha3code":return t.getCountryCodeByAlpha3Code;case"country_code_by_country_name":return t.getCountryCodeByCountryName;case"country_subdivisions_by_alpha2code":return t.getCountrySubDivisionsByAlpha2Code;case"country_subdivision_code_by_subdivision_name":return t.getCountrySubDivisionCodeBySubDivisionName;case"country_alpha2code_by_citizenship":return t.getCountryAlpha2CodeByCitizenship;case"country_subdivision_name_by_subdivision_code":return t.getCountrySubDivisionNameBySubDivisionCode;default:return}})(i);if(t.notMissing(o)){return{value:{value:(t.notMissing(a)?o(a):null)??"unmapped_value",source_value:a}}}return{error:{message:`The built-in matcher "${i}" is not supported`,id:r,targetField:e.targetFieldKey}}}for(const e of i){const{matchExpression:t,value:r}=e;if(!0===o.evaluate(t,s))return{value:{value:r,source_value:a}}}return{value:{value:"unmapped_value",source_value:a}}},K=r.z.object({type:r.z.literal("basic"),username:r.z.string().optional(),password:r.z.string().optional(),encoding:r.z.string().optional()}),U=r.z.object({type:r.z.literal("bearer"),token:r.z.string()}),$=r.z.discriminatedUnion("type",[K,U]),L=r.z.object({baseUrl:r.z.string(),url:r.z.string(),method:r.z.enum(s.HttpMethods),response:r.z.object({indexField:r.z.string().optional(),dataKey:r.z.string().optional(),nextKey:r.z.string().optional()}).optional(),iterator:r.z.object({key:r.z.string(),in:r.z.enum(s.RequestParameterLocations)}),cursor:r.z.object({token:r.z.string().optional().nullable(),position:r.z.number().optional().nullable()}).optional(),customErrors:s.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:r.z.object({name:r.z.string(),value:r.z.unknown(),in:r.z.enum(s.RequestParameterLocations),condition:r.z.string().optional()}).array().optional()}),H=r.z.object({data:r.z.unknown().optional(),raw:r.z.unknown().optional(),statusCode:r.z.number(),message:r.z.string().optional(),next:r.z.string().optional().nullable(),position:r.z.number().optional()}).optional(),G=(e,t)=>{const r=L.parse(e),o=e?.authentication?.[t.context.authenticationType]?.[t.context.environment]?.authorization,n=$.parse(o),a=r.args?s.parseRequestParameters(r.args):{query:{},body:{},headers:{}},i=s.createAuthorizationHeaders(n),u={...a?.headers??{},...i},c=(e=>{const t=Number(e.inputs?.page_size);return Number.isNaN(t)?25:t})(t);return{requestConfig:r,preparedRequest:{parsedArgs:a,requestHeaders:u,pageSize:c}}},Q=async(e,t,r,o)=>{if(!t.httpClient)throw new Error("HTTP client is not configured");try{return await e.performRequest({httpClient:t.httpClient,url:`${r.baseUrl}${r.url}`,queryParams:o.parsedArgs?.query,method:r.method,headers:o.requestHeaders,body:o.parsedArgs?.body,customErrorConfigs:r.customErrors})}catch(e){const r=e;return{block:t,successful:!1,errors:[e],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}},V=(e,t,r)=>{const o=t?.dataKey?e.data[t?.dataKey]:e.data,s=o?.slice(r.pagePosition,r.recordsLeft)??[];return r.recordsLeft=r.recordsLeft-s.length,r.pagePosition=r.pagePosition+s.length,r.raw.push(e),r.data=r.data.concat(s),r.lastStatusCode=e?.status,{resultData:o,slicedData:s}},W=(e,r,o,s,n,a)=>{const i=r?.nextKey?e.data[r?.nextKey]:void 0;o.nextIterator="string"==typeof i||"number"==typeof i?i:null,s.length===n.length&&0===o.recordsLeft&&(o.pagePosition=0,o.lastUsedIterator=o.nextIterator),o.noMoreData=t.isMissing(o.nextIterator)&&o.data.length<a},Y=(e,r,o)=>t.notMissing(e.nextIterator)&&e.data.length<r&&o?.length>0,J=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},X=r.z.object({type:r.z.literal("basic"),username:r.z.string().optional(),password:r.z.string().optional(),encoding:r.z.string().optional()}),Z=r.z.object({type:r.z.literal("bearer"),token:r.z.string()}),ee=r.z.discriminatedUnion("type",[X,Z]),te=r.z.object({baseUrl:r.z.string(),url:r.z.string(),method:r.z.enum(s.HttpMethods),response:r.z.object({collection:r.z.boolean().optional(),indexField:r.z.string().optional(),dataKey:r.z.string().optional()}).optional(),customErrors:s.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:r.z.object({name:r.z.string(),value:r.z.unknown(),in:r.z.enum(s.RequestParameterLocations),condition:r.z.string().optional()}).array().optional()}),re=r.z.object({data:r.z.unknown().optional(),raw:r.z.unknown().optional(),statusCode:r.z.number(),message:r.z.string().optional()}).optional(),oe=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce(((e,r)=>{const o=t.indexField;return o&&r[o]&&(e[r[o]]=r),e}),{});if(!t?.collection&&t?.indexField){const r=t.indexField;return r&&e[r]?{[e[r]]:e}:e}return e},se=r.z.object({fields:r.z.object({targetFieldKey:r.z.string(),alias:r.z.string().optional(),type:r.z.string(),custom:r.z.boolean().default(!1),hidden:r.z.boolean().default(!1)}).array().optional(),dataSource:r.z.string()}),ne=r.z.object({data:r.z.unknown()});var ae;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(ae||(ae={}));const ie=({value:e,type:r,format:o})=>{if(t.isMissing(e))return null;switch(r){case ae.String:return t.safeParseToString({value:e});case ae.Number:return t.safeParseToNumber({value:e});case ae.Boolean:return t.safeParseToBoolean({value:e});case ae.DateTimeString:return t.safeParseToDateTimeString({value:e,format:o});default:return e}},ue=e=>Object.values(ae).includes(e),ce=(e,r)=>{const o={...e};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ue(n)&&(!r.custom&&t.notMissing(o[s])?o[s]=ie({value:e[s],type:n}):o.unified_custom_fields&&t.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ie({value:e.unified_custom_fields?.[s],type:n})))})),{...o}},le=(e,r)=>{const o={...e};return r.forEach((r=>{const{targetFieldKey:s,type:n}=r;ue(n)&&(!r.custom&&t.notMissing(o[s])?o[s]=ie({value:e[s],type:n}):o.unified_custom_fields&&t.notMissing(o.unified_custom_fields?.[s])&&(o.unified_custom_fields[s]=ie({value:e.unified_custom_fields?.[s],type:n})))})),{...o}};var de;exports.StepFunctionName=void 0,(de=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",de.MAP_FIELDS="map_fields",de.GROUP_DATA="group_data",de.REQUEST="request",de.PAGINATED_REQUEST="paginated_request";const pe={[exports.StepFunctionName.TYPECAST]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let r;return r=Array.isArray(e.result)?e.result.map((e=>ce(e,t))):ce(e.result,t),{block:{...e,result:r},successful:!0}}},v2:{fn:async({block:e,params:t})=>{const{fields:r,dataSource:s}=se.parse(t),n=o.evaluate(s,e);if(!r||"disabled"===e?.debug?.custom_mappings)return{block:e,successful:!0};let a;return a=Array.isArray(n)?n.map((e=>le(e,r))):le(n,r),{block:{...e},successful:!0,output:{data:a}}},inputSchema:se,outputSchema:ne}},[exports.StepFunctionName.MAP_FIELDS]:{v1:{fn:async({block:e})=>{const t=e?.fieldConfigs,r=[],o=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!o)return{block:e,successful:!0};let s;if(Array.isArray(e.result)){const n=e.result.length;s=e.result.map(((e,s)=>{const a=T(o,n,s),i=R(e,t,a);return r.push(...i.errors||[]),i.record}))}else{const n=R(e.result,t,o);s=n.record,r.push(...n.errors||[])}return{block:{...e,result:s},successful:!0,errors:Object.keys(r).length>0?r:void 0}}},v2:{fn:async({block:e,params:t})=>{const r=[],{fields:s,dataSource:n}=j.parse(t),a=o.evaluate(n,e);if(!s||!n||"disabled"===e?.debug?.custom_mappings||!a)return{block:e,successful:!0};let i;if(Array.isArray(a))i=a.map((e=>{const t=P(s,e);return r.push(...t?.errors||[]),t?.record}));else{const e=P(s,a);i=e?.record,r.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:i},errors:Object.keys(r).length>0?r:void 0}},inputSchema:j,outputSchema:O}},[exports.StepFunctionName.REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=s.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const{args:n}=t,a=n?n.filter((t=>!t.condition||!0===o.evaluate(t.condition,e))).map((e=>({...e,condition:void 0}))):void 0,i=t?o.safeEvaluateRecord({...t,args:a},e):{},u={...i,customErrors:t?.customErrors},{baseUrl:c,url:l,method:d,response:p,customErrors:g,args:m}=te.parse(u),y=i?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,b=ee.parse(y),f=m?s.parseRequestParameters(m):{query:{},body:{},headers:{}},h=s.createAuthorizationHeaders(b),_={...f?.headers??{},...h};let C;try{C=await r.performRequest({httpClient:e.httpClient,url:`${c}${l}`,queryParams:f?.query,method:d,headers:_,body:f?.body,customErrorConfigs:g})}catch(t){const r=t;return{block:e,successful:!1,errors:[t],output:{statusCode:r?.response?.status??500,message:r?.response?.message}}}const v=p?.dataKey?C.data[p?.dataKey]:C.data,z=oe(v,p);return{block:e,successful:!0,output:{data:z,raw:C,statusCode:C?.status,message:C?.message}}},inputSchema:te,outputSchema:re}},[exports.StepFunctionName.GROUP_DATA]:{v1:{fn:async({block:e,params:r})=>{const{stepsDataToGroup:o,isSingleRecord:s}=F.parse(r),n=o.reduce(((r,o)=>{const n=e.steps?.[o]?.output?.data;return n?s?{...r,[o]:{...n}}:(Object.keys(n).forEach((e=>{const s=t.notMissing(r[e])?r[e]:{};r[e]={...s,[o]:{...n[e]}}})),r):r}),{});return{block:{...e},successful:!0,output:{data:s?n:Object.values(n)}}},inputSchema:F,outputSchema:M}},[exports.StepFunctionName.PAGINATED_REQUEST]:{v1:{fn:async({block:e,params:t})=>{const r=s.RequestClientFactory.build();if(!e.httpClient)throw new Error("HTTP client is not configured");const n=((e,t)=>{const{args:r}=e,s=r?r.filter((e=>!e.condition||!0===o.evaluate(e.condition,t))).map((e=>({...e,condition:void 0}))):void 0;return{...e?o.safeEvaluateRecord({...e,args:s},t):{},customErrors:e?.customErrors}})(t??{},e),{requestConfig:a,preparedRequest:i}=G(n,e),u=(c=a.cursor,l=i.pageSize,{nextIterator:c?.token??null,lastUsedIterator:null,lastStatusCode:null,data:[],raw:[],recordsLeft:l,pagePosition:c?.position??0,firstPage:!0,noMoreData:!0});var c,l,d,p,g;do{u.firstPage?u.firstPage=!1:u.pagePosition=0,d=i.parsedArgs,p=a.iterator,null!==(g=u.nextIterator)&&("query"===p.in?d.query[p.key]=g.toString():"body"===p.in&&(d.body[p.key]=g));const t=await Q(r,e,a,i);if("successful"in t&&!1===t.successful)return t;const o=t;u.lastUsedIterator=u.nextIterator;const{resultData:s,slicedData:n}=V(o,a.response,u);W(o,a.response,u,n,s,i.pageSize)}while(Y(u,i.pageSize,u.data));return((e,t,r)=>({block:e,successful:!0,output:{data:J(t.data,r),raw:t.raw,statusCode:t.lastStatusCode,next:t.noMoreData?void 0:t.lastUsedIterator,position:t.noMoreData?void 0:t.pagePosition}}))(e,u,a.response)},inputSchema:L,outputSchema:H}}},ge=(e,t)=>async({block:r,params:o})=>{try{e.inputSchema&&e.inputSchema.parse(o)}catch{return{block:r,successful:!1,errors:[{message:`Input parameters for ${t} are invalid`}]}}const s=await e.fn({block:r,params:o});try{e.outputSchema&&e.outputSchema.parse(s.output)}catch{return{block:r,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return s},me={build({functionName:e,version:t="1",validateSchemas:r=!1,stepFunctionsList:o=pe}){const s=o?.[e]?.[`v${t}`];if(!s)throw new Error(`Unknown step function: ${e} v${t}`);return r?{...s,fn:ge(s,e)}:s}};Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return e.LogLevel}}),exports.AUTHENTICATION_SCHEMA=ee,exports.COMPOSITE_ID_LATEST_VERSION=1,exports.CoreError=d,exports.StepFunctionsFactory=me,exports.areCursorsEqual=(e,r)=>{const o="string"==typeof e?A(e):e,s="string"==typeof r?A(r):r;if(null===o||null===s)return o===s;const{timestamp:n,...a}=o,{timestamp:i,...u}=s;return t.getContentHash(a)===t.getContentHash(u)},exports.decodeCompositeId=(e,t={version:1})=>{const r=C(e,t),o={};return r?(r.split(l).forEach((e=>{const[r,s]=e.split(c),n=_(r,t.aliases??{});o[n]=E(s)})),o):o},exports.encodeCompositeId=(e,t={version:1})=>{if(1===t.version)return v(f(e,t.aliases));throw new b(`Cannot generate ID, unsupported version number: ${t.version}`)},exports.expandCursor=A,exports.getCategoryDetails=e=>n[e.toLowerCase()]??null,exports.isCompositeId=e=>!t.isMissing(e)&&e.startsWith(a),exports.isCoreError=e=>e instanceof d,exports.isCursorEmpty=({cursor:e,ignoreStepIndex:r})=>!!t.isMissing(e)||Object.keys(e?.remote??{}).reduce(((o,s)=>{const n=e?.remote?.[s];return(t.isMissing(r)||s!==r.toString())&&(o=o&&t.isMissing(n.pageNumber)&&t.isMissing(n.position)&&t.isMissing(n.providerPageCursor)),o}),!0),exports.isValidCategory=e=>!!n[e.toLowerCase()],exports.minifyCursor=e=>t.encodeToBase64(JSON.stringify(k(e))),exports.updateCursor=({cursor:e,stepIndex:r,pageNumber:o,providerPageCursor:s,position:n})=>{const a={pageNumber:o??void 0,providerPageCursor:s??void 0,position:n??void 0},i=t.isMissing(o)&&t.isMissing(s)&&t.isMissing(n);return t.isMissing(e)?{remote:i?{}:{[r]:a},version:2,timestamp:Date.now()}:i?(delete e.remote[r],e):{...e,remote:{...e.remote,[r]:a}}};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ILogger } from '@stackone/logger';
|
|
1
2
|
import type { IHttpClient } from '@stackone/transport';
|
|
2
3
|
import { Category } from '../categories/types';
|
|
3
4
|
import { Connector, Operation, OperationType } from '../connector/types';
|
|
4
5
|
import { Cursor } from '../cursor/types';
|
|
5
|
-
import { ILogger } from '../logger/types';
|
|
6
6
|
import type { StepsSnapshots } from '../steps/types';
|
|
7
7
|
export type Block = {
|
|
8
8
|
inputs?: {
|
|
@@ -45,6 +45,27 @@ export type Operation = {
|
|
|
45
45
|
pageSize: number;
|
|
46
46
|
};
|
|
47
47
|
compositeIdentifiers: CompositeIdentifierConnectorConfig;
|
|
48
|
+
scheduledJobs?: ScheduledJobConfig[];
|
|
49
|
+
};
|
|
50
|
+
type ScheduledJobConfig = {
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
type: ScheduledJobType;
|
|
53
|
+
schedule: string;
|
|
54
|
+
description: string;
|
|
55
|
+
requestParams?: ScheduledJobRequestParams;
|
|
56
|
+
syncFilter?: SyncFilterConfig;
|
|
57
|
+
};
|
|
58
|
+
type ScheduledJobRequestParams = {
|
|
59
|
+
fields?: string[];
|
|
60
|
+
expand?: string[];
|
|
61
|
+
filter?: Record<string, string>;
|
|
62
|
+
};
|
|
63
|
+
type ScheduledJobType = 'data_sync';
|
|
64
|
+
type SyncFilterName = 'updated_after' | 'created_after';
|
|
65
|
+
type SyncFilterConfig = {
|
|
66
|
+
name: SyncFilterName;
|
|
67
|
+
initialLoopbackPeriod: string;
|
|
68
|
+
incrementalLoopbackPeriod: string;
|
|
48
69
|
};
|
|
49
70
|
export type OperationResponse = {
|
|
50
71
|
statusCode: number;
|
|
@@ -89,3 +110,4 @@ export type Authentication = {
|
|
|
89
110
|
[envKey: string]: AuthenticationConfig;
|
|
90
111
|
};
|
|
91
112
|
};
|
|
113
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { StepFunction, StepFunctionParams, StepFunctionOutput } from './stepFunctions/types';
|
|
3
|
-
export { StepFunctionName } from './stepFunctions/stepFunctionsList';
|
|
4
|
-
export { StepsSnapshots, Step } from './steps/types';
|
|
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, OperationResponse, Authentication, Input, InputLocation, AuthenticationField, SupportConfig, AuthenticationConfig, } from './connector/types';
|
|
10
|
-
export { AUTHENTICATION_SCHEMA } from './stepFunctions/request/schemas';
|
|
11
|
-
export { ILogger, LogError, LogLevel, Log } from './logger/types';
|
|
1
|
+
export { ILogger, Log, LogError, LogLevel } from '@stackone/logger';
|
|
12
2
|
export type { Account } from './accounts/types';
|
|
3
|
+
export { Block, BlockContext, BlockIndexedRecord, FieldConfig, } from './blocks/types';
|
|
4
|
+
export { getCategoryDetails, isValidCategory } from './categories';
|
|
5
|
+
export { Category } from './categories/types';
|
|
6
|
+
export { decodeCompositeId, encodeCompositeId, isCompositeId } from './compositeIds';
|
|
7
|
+
export { COMPOSITE_ID_LATEST_VERSION } from './compositeIds/constants';
|
|
8
|
+
export { CompositeIdentifier, CompositeIdentifierConfig, CompositeIdentifierConnectorConfig, } from './compositeIds/types';
|
|
9
|
+
export { Authentication, AuthenticationConfig, AuthenticationField, Connector, Input, InputLocation, Operation, OperationResponse, OperationType, SupportConfig, } from './connector/types';
|
|
10
|
+
export { areCursorsEqual, expandCursor, isCursorEmpty, minifyCursor, updateCursor } from './cursor';
|
|
13
11
|
export type { Cursor } from './cursor/types';
|
|
14
|
-
export { expandCursor, minifyCursor, areCursorsEqual, isCursorEmpty, updateCursor } from './cursor';
|
|
15
12
|
export { CoreError } from './errors/coreError';
|
|
16
13
|
export { isCoreError } from './errors/typeguards';
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
14
|
+
export { Schema, SchemaField } from './schema/types';
|
|
15
|
+
export { StepFunctionsFactory } from './stepFunctions/factory';
|
|
16
|
+
export { AUTHENTICATION_SCHEMA } from './stepFunctions/request/schemas';
|
|
17
|
+
export { StepFunctionName } from './stepFunctions/stepFunctionsList';
|
|
18
|
+
export { StepFunction, StepFunctionOutput, StepFunctionParams } from './stepFunctions/types';
|
|
19
|
+
export { Step, StepsSnapshots } from './steps/types';
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
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, error, code, context, }: {
|
|
15
|
-
category?: string;
|
|
16
|
-
message: string;
|
|
17
|
-
traceId?: string;
|
|
18
|
-
error?: LogError;
|
|
19
|
-
code?: string;
|
|
20
|
-
context?: Record<string, unknown>;
|
|
21
|
-
}): void;
|
|
22
|
-
error({ category, message, traceId, error, code, context, }: {
|
|
23
|
-
category?: string;
|
|
24
|
-
message: string;
|
|
25
|
-
traceId?: string;
|
|
26
|
-
error?: LogError;
|
|
27
|
-
code: string;
|
|
28
|
-
context?: Record<string, unknown>;
|
|
29
|
-
}): void;
|
|
30
|
-
}
|
|
31
|
-
export type LogError = Error & {
|
|
32
|
-
response?: {
|
|
33
|
-
data?: unknown;
|
|
34
|
-
};
|
|
35
|
-
context?: Record<string, unknown>;
|
|
36
|
-
url?: string;
|
|
37
|
-
};
|
|
38
|
-
export declare enum LogLevel {
|
|
39
|
-
Trace = 0,
|
|
40
|
-
Debug = 1,
|
|
41
|
-
Info = 2,
|
|
42
|
-
Warning = 3,
|
|
43
|
-
Error = 4
|
|
44
|
-
}
|
|
45
|
-
export type Log = {
|
|
46
|
-
level: LogLevel;
|
|
47
|
-
category?: string;
|
|
48
|
-
message: string;
|
|
49
|
-
traceId?: string;
|
|
50
|
-
error?: LogError;
|
|
51
|
-
code?: string;
|
|
52
|
-
context?: Record<string, unknown>;
|
|
53
|
-
};
|