@stackone/core 1.71.0 → 1.72.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.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ZodType, z } from "@stackone/utils";
|
|
2
|
+
import { IOlapClient } from "@stackone/olap";
|
|
2
3
|
import http from "node:http";
|
|
3
4
|
import https from "node:https";
|
|
4
5
|
import * as zod_v40 from "zod/v4";
|
|
@@ -437,6 +438,9 @@ declare const stepFunctions: {
|
|
|
437
438
|
token: zod_v40.ZodString;
|
|
438
439
|
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
439
440
|
scopes: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
441
|
+
scopeDelimiter: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
442
|
+
customHeaders: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
443
|
+
pkce: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
440
444
|
}, zod_v4_core0.$strict>]>>;
|
|
441
445
|
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
442
446
|
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
@@ -738,6 +742,21 @@ type Authentication = {
|
|
|
738
742
|
};
|
|
739
743
|
};
|
|
740
744
|
//#endregion
|
|
745
|
+
//#region src/settings/types.d.ts
|
|
746
|
+
type Settings = {
|
|
747
|
+
olap: OlapSettings;
|
|
748
|
+
};
|
|
749
|
+
type OlapSettings = {
|
|
750
|
+
logs?: {
|
|
751
|
+
enabled: boolean;
|
|
752
|
+
};
|
|
753
|
+
advanced?: {
|
|
754
|
+
enabled?: boolean;
|
|
755
|
+
ttl?: number;
|
|
756
|
+
errorsOnly?: boolean;
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
//#endregion
|
|
741
760
|
//#region src/blocks/types.d.ts
|
|
742
761
|
type Block = {
|
|
743
762
|
inputs?: {
|
|
@@ -748,6 +767,8 @@ type Block = {
|
|
|
748
767
|
debug?: DebugParams;
|
|
749
768
|
steps?: StepsSnapshots;
|
|
750
769
|
httpClient?: IHttpClient;
|
|
770
|
+
olapClient?: IOlapClient;
|
|
771
|
+
settings?: Settings;
|
|
751
772
|
logger?: ILogger;
|
|
752
773
|
operation?: Operation;
|
|
753
774
|
credentials?: Credentials;
|
|
@@ -771,6 +792,7 @@ type BlockContext = {
|
|
|
771
792
|
operationType: OperationType;
|
|
772
793
|
authenticationType: string;
|
|
773
794
|
environment: string;
|
|
795
|
+
actionRunId?: string;
|
|
774
796
|
service: string;
|
|
775
797
|
resource: string;
|
|
776
798
|
subResource?: string;
|
|
@@ -869,6 +891,9 @@ declare const AUTHENTICATION_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
869
891
|
token: z.ZodString;
|
|
870
892
|
includeBearer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
871
893
|
scopes: z.ZodOptional<z.ZodString>;
|
|
894
|
+
scopeDelimiter: z.ZodOptional<z.ZodString>;
|
|
895
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
896
|
+
pkce: z.ZodOptional<z.ZodBoolean>;
|
|
872
897
|
}, z.core.$strict>]>;
|
|
873
898
|
//#endregion
|
|
874
899
|
//#region src/accounts/types.d.ts
|
|
@@ -883,4 +908,4 @@ type Account = {
|
|
|
883
908
|
projectSecureId: string;
|
|
884
909
|
};
|
|
885
910
|
//#endregion
|
|
886
|
-
export { AUTHENTICATION_SCHEMA, type Account, type Assets, type Authentication, type AuthenticationConfig, type AuthenticationField, type Block, type BlockContext, type BlockIndexedRecord, COMPOSITE_ID_LATEST_VERSION, type Category, type CompositeIdentifier, type CompositeIdentifierConfig, type CompositeIdentifierConnectorConfig, type Connector, CoreError, type Cursor, type FieldConfig, type Input, type InputLocation, type Operation, type OperationResponse, type OperationType, type Schema, type SchemaField, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestOperationConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
|
911
|
+
export { AUTHENTICATION_SCHEMA, type Account, type Assets, type Authentication, type AuthenticationConfig, type AuthenticationField, type Block, type BlockContext, type BlockIndexedRecord, COMPOSITE_ID_LATEST_VERSION, type Category, type CompositeIdentifier, type CompositeIdentifierConfig, type CompositeIdentifierConnectorConfig, type Connector, CoreError, type Cursor, type FieldConfig, type Input, type InputLocation, type Operation, type OperationResponse, type OperationType, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestOperationConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IOlapClient } from "@stackone/olap";
|
|
1
2
|
import { ZodType, z } from "@stackone/utils";
|
|
2
3
|
import http from "node:http";
|
|
3
4
|
import https from "node:https";
|
|
@@ -437,6 +438,9 @@ declare const stepFunctions: {
|
|
|
437
438
|
token: zod_v40.ZodString;
|
|
438
439
|
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
439
440
|
scopes: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
441
|
+
scopeDelimiter: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
442
|
+
customHeaders: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
443
|
+
pkce: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
440
444
|
}, zod_v4_core0.$strict>]>>;
|
|
441
445
|
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
442
446
|
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
@@ -738,6 +742,21 @@ type Authentication = {
|
|
|
738
742
|
};
|
|
739
743
|
};
|
|
740
744
|
//#endregion
|
|
745
|
+
//#region src/settings/types.d.ts
|
|
746
|
+
type Settings = {
|
|
747
|
+
olap: OlapSettings;
|
|
748
|
+
};
|
|
749
|
+
type OlapSettings = {
|
|
750
|
+
logs?: {
|
|
751
|
+
enabled: boolean;
|
|
752
|
+
};
|
|
753
|
+
advanced?: {
|
|
754
|
+
enabled?: boolean;
|
|
755
|
+
ttl?: number;
|
|
756
|
+
errorsOnly?: boolean;
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
//#endregion
|
|
741
760
|
//#region src/blocks/types.d.ts
|
|
742
761
|
type Block = {
|
|
743
762
|
inputs?: {
|
|
@@ -748,6 +767,8 @@ type Block = {
|
|
|
748
767
|
debug?: DebugParams;
|
|
749
768
|
steps?: StepsSnapshots;
|
|
750
769
|
httpClient?: IHttpClient;
|
|
770
|
+
olapClient?: IOlapClient;
|
|
771
|
+
settings?: Settings;
|
|
751
772
|
logger?: ILogger;
|
|
752
773
|
operation?: Operation;
|
|
753
774
|
credentials?: Credentials;
|
|
@@ -771,6 +792,7 @@ type BlockContext = {
|
|
|
771
792
|
operationType: OperationType;
|
|
772
793
|
authenticationType: string;
|
|
773
794
|
environment: string;
|
|
795
|
+
actionRunId?: string;
|
|
774
796
|
service: string;
|
|
775
797
|
resource: string;
|
|
776
798
|
subResource?: string;
|
|
@@ -869,6 +891,9 @@ declare const AUTHENTICATION_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
869
891
|
token: z.ZodString;
|
|
870
892
|
includeBearer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
871
893
|
scopes: z.ZodOptional<z.ZodString>;
|
|
894
|
+
scopeDelimiter: z.ZodOptional<z.ZodString>;
|
|
895
|
+
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
896
|
+
pkce: z.ZodOptional<z.ZodBoolean>;
|
|
872
897
|
}, z.core.$strict>]>;
|
|
873
898
|
//#endregion
|
|
874
899
|
//#region src/accounts/types.d.ts
|
|
@@ -883,4 +908,4 @@ type Account = {
|
|
|
883
908
|
projectSecureId: string;
|
|
884
909
|
};
|
|
885
910
|
//#endregion
|
|
886
|
-
export { AUTHENTICATION_SCHEMA, type Account, type Assets, type Authentication, type AuthenticationConfig, type AuthenticationField, type Block, type BlockContext, type BlockIndexedRecord, COMPOSITE_ID_LATEST_VERSION, type Category, type CompositeIdentifier, type CompositeIdentifierConfig, type CompositeIdentifierConnectorConfig, type Connector, CoreError, type Cursor, type FieldConfig, type Input, type InputLocation, type Operation, type OperationResponse, type OperationType, type Schema, type SchemaField, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestOperationConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
|
911
|
+
export { AUTHENTICATION_SCHEMA, type Account, type Assets, type Authentication, type AuthenticationConfig, type AuthenticationField, type Block, type BlockContext, type BlockIndexedRecord, COMPOSITE_ID_LATEST_VERSION, type Category, type CompositeIdentifier, type CompositeIdentifierConfig, type CompositeIdentifierConnectorConfig, type Connector, CoreError, type Cursor, type FieldConfig, type Input, type InputLocation, type Operation, type OperationResponse, type OperationType, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestOperationConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@stackone/utils`)),l=s(require(`@stackone/expressions`)),u=s(require(`@stackone/transport`)),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`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`},action:{title:`Action`,key:`action`,description:`Action`}},f=e=>{let t=d[e.toLowerCase()];return t??null},p=e=>!!d[e.toLowerCase()],m=`so1!`,h=(0,c.encodeToBase64)(m),g=`:`,_=`,`,v=RegExp(`(?<!\\\\)${g}`,`g`),y=RegExp(`(?<!\\\\)${_}`,`g`),b=1;var x=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},S=class extends x{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},C=class extends S{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},w=class extends S{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},T=class extends S{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},E=class extends S{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const D=e=>!(0,c.isMissing)(e)&&`value`in e&&e.value!==void 0,O=e=>!(0,c.isMissing)(e)&&`identifiers`in e&&e.identifiers!==void 0,k=(e,t={version:b})=>{if(t.version===1)return F(j(e,t.aliases));throw new E(`Cannot generate ID, unsupported version number: ${t.version}`)},A=(e,t={version:b})=>{let n=P(e,t),r={};return n&&n.split(y).forEach(e=>{let[n,i]=e.split(v),a=N(n,t.aliases??{});r[a]=ee(i)}),r},j=(e,t={})=>{if(D(e))return M({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(O(e))return e.identifiers.map(e=>M({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(_);throw new T},M=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,L(e.value)].filter(Boolean).join(g)},N=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,P=(e,t)=>{if(t.version===1)return I(e);throw new E(`Cannot decode ID, unsupported version number: ${t.version}`)},F=e=>`${h}${(0,c.encodeToBase64)(e)}`,I=e=>{if(!e.startsWith(h))throw new C(`Trying to decode an ID without the header: ${e}`);let t=e.split(h)[1];if(!t)throw new w(`Trying to decode an ID without a body: ${e}`);return(0,c.decodeFromBase64)(t)},L=e=>[_,g].reduce((e,t)=>e.replace(t,`\\`+t),e),ee=e=>[_,g].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),te=e=>(0,c.isMissing)(e)?!1:e.startsWith(h),ne=(0,c.zStrictObject)({r:c.z.record(c.z.string(),(0,c.zStrictObject)({n:c.z.number().optional().nullable(),c:c.z.string().optional().nullable(),p:c.z.number().optional().nullable()})),v:c.z.number(),t:c.z.number()}),re=(0,c.zStrictObject)({remote:c.z.record(c.z.string(),(0,c.zStrictObject)({pageNumber:c.z.number().optional(),providerPageCursor:c.z.string().optional(),position:c.z.number().optional()})),version:c.z.number(),timestamp:c.z.number()}),ie=e=>(0,c.encodeToBase64)(JSON.stringify(ae(e))),ae=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},R=e=>{try{if((0,c.isString)(e)){let t=(0,c.decodeFromBase64)(e),n=JSON.parse(t),r=ne.parse(n);return oe(r)}else return re.parse(e),e}catch{return null}},oe=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},se=(e,t)=>{let n=typeof e==`string`?R(e):e,r=typeof t==`string`?R(t):t;if(n===null||r===null)return n===r;let{timestamp:i,...a}=n,{timestamp:o,...s}=r;return(0,c.getContentHash)(a)===(0,c.getContentHash)(s)},ce=({cursor:e,ignoreStepIndex:t})=>(0,c.isMissing)(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return((0,c.isMissing)(t)||r!==t.toString())&&(n=n&&(0,c.isMissing)(i.pageNumber)&&(0,c.isMissing)(i.position)&&(0,c.isMissing)(i.providerPageCursor)),n},!0),le=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=(0,c.isMissing)(n)&&(0,c.isMissing)(r)&&(0,c.isMissing)(i);return(0,c.isMissing)(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},ue=e=>e instanceof x,z=c.z.object({stepsDataToGroup:c.z.array(c.z.string()),isSingleRecord:c.z.boolean().optional()}),de=c.z.object({data:c.z.unknown()}),fe=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=z.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=(0,c.notMissing)(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},pe=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=me(r,a,i),s=B(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=B(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},me=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),B=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=he(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},he=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=(0,l.evaluate)(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},ge=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return c.getCountryAlpha2CodeByAlpha2Code;case`country_alpha3code_by_alpha3code`:return c.getCountryAlpha3CodeByAlpha3Code;case`country_code_by_country_code`:return c.getCountryCodeByCountryCode;case`country_name_by_country_name`:return c.getCountryNameByCountryName;case`country_name_by_alpha3code`:return c.getCountryNameByAlpha3Code;case`country_name_by_alpha2code`:return c.getCountryNameByAlpha2Code;case`country_name_by_country_code`:return c.getCountryNameByCountryCode;case`country_alpha3code_by_alpha2code`:return c.getCountryAlpha3CodeByAlpha2Code;case`country_alpha3code_by_country_name`:return c.getCountryAlpha3CodeByCountryName;case`country_alpha3code_by_country_code`:return c.getCountryAlpha3CodeByCountryCode;case`country_alpha2code_by_alpha3code`:return c.getCountryAlpha2CodeByAlpha3Code;case`country_alpha2code_by_country_name`:return c.getCountryAlpha2CodeByCountryName;case`country_alpha2code_by_country_code`:return c.getCountryAlpha2CodeByCountryCode;case`country_code_by_alpha2code`:return c.getCountryCodeByAlpha2Code;case`country_code_by_alpha3code`:return c.getCountryCodeByAlpha3Code;case`country_code_by_country_name`:return c.getCountryCodeByCountryName;case`country_subdivisions_by_alpha2code`:return c.getCountrySubDivisionsByAlpha2Code;case`country_subdivision_code_by_subdivision_name`:return c.getCountrySubDivisionCodeBySubDivisionName;case`country_alpha2code_by_citizenship`:return c.getCountryAlpha2CodeByCitizenship;case`country_subdivision_name_by_subdivision_code`:return c.getCountrySubDivisionNameBySubDivisionCode;case`document_file_format_from_extension`:return c.getDocumentFileFormatFromExtension;default:return}},V=(0,c.zStrictObject)({targetFieldKey:c.z.string(),alias:c.z.string().optional(),expression:c.z.string().optional(),values:c.z.unknown().optional(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),enumMapper:(0,c.zStrictObject)({matcher:c.z.string().or((0,c.zStrictObject)({matchExpression:c.z.string(),value:c.z.string()}).array())}).optional(),properties:c.z.lazy(()=>V).array().optional()}),H=c.z.object({fields:V.array(),dataSource:c.z.string(),externalSources:c.z.record(c.z.string(),c.z.string()).optional()}),_e=c.z.object({data:c.z.unknown()}),ve=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=H.parse(t),o=(0,l.evaluate)(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!o)return{block:e,successful:!0};let s=Object.keys(a??{})?.reduce((t,n)=>(t[n]=(0,l.evaluate)(a?.[n],e),t),{}),c;if(Array.isArray(o))c=o.map(e=>{let t=U(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=U(r,{...o,external:s});c=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:c},errors:Object.keys(n).length>0?n:void 0}},ye=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=W(r,t),a=U(e.properties,i);return(0,c.notMissing)(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},be=(e,t,n)=>{if(e.expression)try{let r=(0,l.evaluate)(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=U(e.properties,t);return(0,c.notMissing)(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=U(e.properties,r);return(0,c.notMissing)(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},xe=(e,t,n)=>{let r=(0,c.notMissing)(e.values)?e.values:t,i=U(e.properties,r);return(0,c.notMissing)(i?.errors)&&n.push(...i.errors),i?.record},Se=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?ye(e,t,n):e.array&&e.expression?be(e,t,n):xe(e,t,n)},U=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=Se(a,t,r),e===void 0)continue}else{let{error:n,value:i}=Ce(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}let a=Object.keys(n).length>0?{unified_custom_fields:n}:{};return{record:{...i,...a},errors:r.length>0?r:void 0}},W=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if((0,l.isValidExpression)(e))try{return(0,l.evaluate)(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>W(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=W(r,t);return n}return e},Ce=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return G(n,t,e);case`enum`:return we(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},G=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=(0,l.evaluate)(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},we=(e,t,n)=>{let r=G(e,t,n),i=(0,c.notMissing)(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if((0,c.isString)(a)){let n=ge(a);if((0,c.notMissing)(n)){let e=(0,c.notMissing)(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=(0,l.evaluate)(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},Te=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Ee=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),De=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Oe=(0,c.zStrictObject)({type:c.z.literal(`oauth2`),authorizationUrl:c.z.string().optional(),authorizationParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenUrl:c.z.string().optional(),tokenParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenExpiresIn:c.z.number().optional(),tokenRefreshExpiresIn:c.z.number().optional(),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0),scopes:c.z.string().optional()}),ke=c.z.discriminatedUnion(`type`,[Te,Ee,De,Oe]),K=c.z.object({baseUrl:c.z.string(),url:c.z.string(),method:c.z.enum(u.HttpMethods),response:(0,c.zStrictObject)({indexField:c.z.string().optional(),dataKey:c.z.string().optional(),nextKey:c.z.string().optional()}).optional(),iterator:(0,c.zStrictObject)({key:c.z.string(),in:c.z.enum(u.RequestParameterLocations)}),cursor:(0,c.zStrictObject)({token:c.z.string().optional().nullable(),position:c.z.number().optional().nullable()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:(0,c.zStrictObject)({name:c.z.string(),value:c.z.unknown(),in:c.z.enum(u.RequestParameterLocations),condition:c.z.string().optional()}).array().optional()}),Ae=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional(),next:c.z.string().optional().nullable(),position:c.z.number().optional()}).optional(),je=25,Me=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?je:i,o=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?(0,l.safeEvaluateRecord)({...t,args:o},e):{},d={...s,customErrors:t?.customErrors},{baseUrl:f,url:p,method:m,response:h,iterator:g,cursor:_,customErrors:v,args:y}=K.parse(d),b=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,x=ke.parse(b),S=y?(0,u.parseRequestParameters)(y):{query:{},body:{},headers:{}},C=(0,u.createAuthorizationHeaders)(x),w={...S?.headers??{},...C},T=e.connector?.rateLimit,E=e.connector?.concurrency,D=T!==void 0||E!==void 0?{rateLimit:T,concurrency:E}:void 0,O=_?.token??null,k=null,A=null,j=[],M=[],N=[],P=a,F=_?.position??0,I=!0,L=!0;do{I?I=!1:F=0,O!==null&&(g.in===`query`?S.query[g.key]=O.toString():g.in===`body`&&(S.body[g.key]=O));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${f}${p}`,queryParams:S?.query,method:m,headers:w,body:S?.body,customErrorConfigs:v,requestConfig:D})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}k=O,M=h?.dataKey?t.data[h?.dataKey]:t.data;let r=M?.slice(F,F+P);P-=r.length,F+=r.length,N.push(t),j=j.concat(r),A=t?.status,O=h?.nextKey?t.data[h?.nextKey]:void 0,r.length===M.length&&P===0&&(F=0,k=O),L=(0,c.isMissing)(O)&&j.length<a}while((0,c.notMissing)(O)&&j.length<a&&M?.length>0);let ee=Ne(j,h);return{block:e,successful:!0,output:{data:ee,raw:N,statusCode:A,next:L?void 0:k,position:L?void 0:F}}},Ne=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Pe=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Fe=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),Ie=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Le=(0,c.zStrictObject)({type:c.z.literal(`oauth2`),authorizationUrl:c.z.string().optional(),authorizationParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenUrl:c.z.string().optional(),tokenParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenExpiresIn:c.z.number().optional(),tokenRefreshExpiresIn:c.z.number().optional(),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0),scopes:c.z.string().optional()}),q=c.z.discriminatedUnion(`type`,[Pe,Fe,Ie,Le]),Re=c.z.object({baseUrl:c.z.string().optional(),url:c.z.string(),method:c.z.enum(u.HttpMethods),authorization:q.optional(),response:(0,c.zStrictObject)({collection:c.z.boolean().optional(),indexField:c.z.string().optional(),dataKey:c.z.string().optional()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:(0,c.zStrictObject)({name:c.z.string(),value:c.z.unknown(),in:c.z.enum(u.RequestParameterLocations),condition:c.z.string().optional()}).array().optional()}),ze=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional()}).optional(),Be=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?(0,l.safeEvaluateRecord)({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:d,method:f,response:p,authorization:m,customErrors:h,args:g}=Re.parse(o),_=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=g?(0,u.parseRequestParameters)(g):{query:{},body:{},headers:{}},y=(0,c.notMissing)(m)?m:q.parse(_),b=(0,u.createAuthorizationHeaders)(y),x={...v?.headers??{},...b},S=e.connector?.rateLimit,C=e.connector?.concurrency,w=S!==void 0||C!==void 0?{rateLimit:S,concurrency:C}:void 0,T;try{T=await n.performRequest({httpClient:e.httpClient,url:`${s}${d}`,queryParams:v?.query,method:f,headers:x,body:v?.body,customErrorConfigs:h,requestConfig:w})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let E=p?.dataKey?T.data[p?.dataKey]:T.data,D=Ve(E,p);return{block:e,successful:!0,output:{data:D,raw:T,statusCode:T?.status,message:T?.message}}},Ve=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},He=c.z.object({values:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).or(c.z.array(c.z.unknown()))}),Ue=c.z.object({data:c.z.unknown()}),We=async({block:e,params:t})=>{let{values:n}=He.parse(t),r=Array.isArray(n)?n.map(t=>Ge(t,e)):Ge(n,e);return{block:{...e},successful:!0,output:{data:r}}},Ge=(e,t)=>(0,c.isString)(e)?(0,l.safeEvaluate)(e,t):(0,c.isObject)(e)?(0,l.safeEvaluateRecord)(e,t):e,Ke=c.z.object({targetFieldKey:c.z.string(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),properties:c.z.lazy(()=>Ke).array().optional()}),J=c.z.object({fields:Ke.array().optional(),dataSource:c.z.string()}),qe=c.z.object({data:c.z.unknown()});let Y=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const X=({value:e,type:t,format:n})=>{if((0,c.isMissing)(e))return null;switch(t){case Y.String:return(0,c.safeParseToString)({value:e});case Y.Number:return(0,c.safeParseToNumber)({value:e});case Y.Boolean:return(0,c.safeParseToBoolean)({value:e});case Y.DateTimeString:return(0,c.safeParseToDateTimeString)({value:e,format:n});default:return e}},Je=e=>{let t=Object.values(Y);return t.includes(e)},Ye=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>Xe(e,t)):Xe(e.result,t),{block:{...e,result:n},successful:!0}},Xe=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Je(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=X({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=X({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},Ze=async({block:e,params:t})=>{let{fields:n,dataSource:r}=J.parse(t),i=(0,l.evaluate)(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Z(e,n)):Z(i,n),{block:{...e},successful:!0,output:{data:a}}},Qe=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Z(t,e.properties):t):typeof t==`object`&&t?Z(t,e.properties):t,Z=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i,array:a}=t;i===`object`?!t.custom&&(0,c.notMissing)(n[r])?n[r]=Qe(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Qe(t,e.unified_custom_fields?.[r])):Je(i)&&(!t.custom&&(0,c.notMissing)(n[r])?(!a||!Array.isArray(n[r]))&&(n[r]=X({value:e[r],type:i})):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(!a||!Array.isArray(n.unified_custom_fields[r]))&&(n.unified_custom_fields[r]=X({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let Q=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const $={[Q.TYPECAST]:{v1:{fn:Ye},v2:{fn:Ze,inputSchema:J,outputSchema:qe}},[Q.MAP_FIELDS]:{v1:{fn:pe},v2:{fn:ve,inputSchema:H,outputSchema:_e}},[Q.REQUEST]:{v1:{fn:Be,inputSchema:Re,outputSchema:ze}},[Q.GROUP_DATA]:{v1:{fn:fe,inputSchema:z,outputSchema:de}},[Q.PAGINATED_REQUEST]:{v1:{fn:Me,inputSchema:K,outputSchema:Ae}},[Q.STATIC_VALUES]:{v1:{fn:We,inputSchema:He,outputSchema:Ue}}},$e=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch(e){return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid: ${e?.message}`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},et={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=$}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:$e(i,e)}:i}};exports.AUTHENTICATION_SCHEMA=q,exports.COMPOSITE_ID_LATEST_VERSION=b,exports.CoreError=x,exports.StepFunctionName=Q,exports.StepFunctionsFactory=et,exports.StepFunctionsRegistry=$,exports.areCursorsEqual=se,exports.decodeCompositeId=A,exports.encodeCompositeId=k,exports.expandCursor=R,exports.getCategoryDetails=f,exports.isCompositeId=te,exports.isCoreError=ue,exports.isCursorEmpty=ce,exports.isValidCategory=p,exports.minifyCursor=ie,exports.updateCursor=le;
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@stackone/utils`)),l=s(require(`@stackone/expressions`)),u=s(require(`@stackone/transport`)),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`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`},action:{title:`Action`,key:`action`,description:`Action`}},f=e=>{let t=d[e.toLowerCase()];return t??null},p=e=>!!d[e.toLowerCase()],m=`so1!`,h=(0,c.encodeToBase64)(m),g=`:`,_=`,`,v=RegExp(`(?<!\\\\)${g}`,`g`),y=RegExp(`(?<!\\\\)${_}`,`g`),b=1;var x=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},S=class extends x{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},C=class extends S{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},w=class extends S{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},T=class extends S{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},E=class extends S{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const D=e=>!(0,c.isMissing)(e)&&`value`in e&&e.value!==void 0,O=e=>!(0,c.isMissing)(e)&&`identifiers`in e&&e.identifiers!==void 0,k=(e,t={version:b})=>{if(t.version===1)return F(j(e,t.aliases));throw new E(`Cannot generate ID, unsupported version number: ${t.version}`)},A=(e,t={version:b})=>{let n=P(e,t),r={};return n&&n.split(y).forEach(e=>{let[n,i]=e.split(v),a=N(n,t.aliases??{});r[a]=ee(i)}),r},j=(e,t={})=>{if(D(e))return M({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(O(e))return e.identifiers.map(e=>M({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(_);throw new T},M=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,L(e.value)].filter(Boolean).join(g)},N=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,P=(e,t)=>{if(t.version===1)return I(e);throw new E(`Cannot decode ID, unsupported version number: ${t.version}`)},F=e=>`${h}${(0,c.encodeToBase64)(e)}`,I=e=>{if(!e.startsWith(h))throw new C(`Trying to decode an ID without the header: ${e}`);let t=e.split(h)[1];if(!t)throw new w(`Trying to decode an ID without a body: ${e}`);return(0,c.decodeFromBase64)(t)},L=e=>[_,g].reduce((e,t)=>e.replace(t,`\\`+t),e),ee=e=>[_,g].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),te=e=>(0,c.isMissing)(e)?!1:e.startsWith(h),ne=(0,c.zStrictObject)({r:c.z.record(c.z.string(),(0,c.zStrictObject)({n:c.z.number().optional().nullable(),c:c.z.string().optional().nullable(),p:c.z.number().optional().nullable()})),v:c.z.number(),t:c.z.number()}),re=(0,c.zStrictObject)({remote:c.z.record(c.z.string(),(0,c.zStrictObject)({pageNumber:c.z.number().optional(),providerPageCursor:c.z.string().optional(),position:c.z.number().optional()})),version:c.z.number(),timestamp:c.z.number()}),ie=e=>(0,c.encodeToBase64)(JSON.stringify(ae(e))),ae=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},R=e=>{try{if((0,c.isString)(e)){let t=(0,c.decodeFromBase64)(e),n=JSON.parse(t),r=ne.parse(n);return oe(r)}else return re.parse(e),e}catch{return null}},oe=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},se=(e,t)=>{let n=typeof e==`string`?R(e):e,r=typeof t==`string`?R(t):t;if(n===null||r===null)return n===r;let{timestamp:i,...a}=n,{timestamp:o,...s}=r;return(0,c.getContentHash)(a)===(0,c.getContentHash)(s)},ce=({cursor:e,ignoreStepIndex:t})=>(0,c.isMissing)(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return((0,c.isMissing)(t)||r!==t.toString())&&(n=n&&(0,c.isMissing)(i.pageNumber)&&(0,c.isMissing)(i.position)&&(0,c.isMissing)(i.providerPageCursor)),n},!0),le=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=(0,c.isMissing)(n)&&(0,c.isMissing)(r)&&(0,c.isMissing)(i);return(0,c.isMissing)(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},ue=e=>e instanceof x,z=c.z.object({stepsDataToGroup:c.z.array(c.z.string()),isSingleRecord:c.z.boolean().optional()}),de=c.z.object({data:c.z.unknown()}),fe=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=z.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=(0,c.notMissing)(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},pe=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=me(r,a,i),s=B(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=B(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},me=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),B=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=he(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},he=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=(0,l.evaluate)(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},ge=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return c.getCountryAlpha2CodeByAlpha2Code;case`country_alpha3code_by_alpha3code`:return c.getCountryAlpha3CodeByAlpha3Code;case`country_code_by_country_code`:return c.getCountryCodeByCountryCode;case`country_name_by_country_name`:return c.getCountryNameByCountryName;case`country_name_by_alpha3code`:return c.getCountryNameByAlpha3Code;case`country_name_by_alpha2code`:return c.getCountryNameByAlpha2Code;case`country_name_by_country_code`:return c.getCountryNameByCountryCode;case`country_alpha3code_by_alpha2code`:return c.getCountryAlpha3CodeByAlpha2Code;case`country_alpha3code_by_country_name`:return c.getCountryAlpha3CodeByCountryName;case`country_alpha3code_by_country_code`:return c.getCountryAlpha3CodeByCountryCode;case`country_alpha2code_by_alpha3code`:return c.getCountryAlpha2CodeByAlpha3Code;case`country_alpha2code_by_country_name`:return c.getCountryAlpha2CodeByCountryName;case`country_alpha2code_by_country_code`:return c.getCountryAlpha2CodeByCountryCode;case`country_code_by_alpha2code`:return c.getCountryCodeByAlpha2Code;case`country_code_by_alpha3code`:return c.getCountryCodeByAlpha3Code;case`country_code_by_country_name`:return c.getCountryCodeByCountryName;case`country_subdivisions_by_alpha2code`:return c.getCountrySubDivisionsByAlpha2Code;case`country_subdivision_code_by_subdivision_name`:return c.getCountrySubDivisionCodeBySubDivisionName;case`country_alpha2code_by_citizenship`:return c.getCountryAlpha2CodeByCitizenship;case`country_subdivision_name_by_subdivision_code`:return c.getCountrySubDivisionNameBySubDivisionCode;case`document_file_format_from_extension`:return c.getDocumentFileFormatFromExtension;default:return}},V=(0,c.zStrictObject)({targetFieldKey:c.z.string(),alias:c.z.string().optional(),expression:c.z.string().optional(),values:c.z.unknown().optional(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),enumMapper:(0,c.zStrictObject)({matcher:c.z.string().or((0,c.zStrictObject)({matchExpression:c.z.string(),value:c.z.string()}).array())}).optional(),properties:c.z.lazy(()=>V).array().optional()}),H=c.z.object({fields:V.array(),dataSource:c.z.string(),externalSources:c.z.record(c.z.string(),c.z.string()).optional()}),_e=c.z.object({data:c.z.unknown()}),ve=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=H.parse(t),o=(0,l.evaluate)(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!o)return{block:e,successful:!0};let s=Object.keys(a??{})?.reduce((t,n)=>(t[n]=(0,l.evaluate)(a?.[n],e),t),{}),c;if(Array.isArray(o))c=o.map(e=>{let t=U(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=U(r,{...o,external:s});c=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:c},errors:Object.keys(n).length>0?n:void 0}},ye=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=W(r,t),a=U(e.properties,i);return(0,c.notMissing)(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},be=(e,t,n)=>{if(e.expression)try{let r=(0,l.evaluate)(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=U(e.properties,t);return(0,c.notMissing)(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=U(e.properties,r);return(0,c.notMissing)(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},xe=(e,t,n)=>{let r=(0,c.notMissing)(e.values)?e.values:t,i=U(e.properties,r);return(0,c.notMissing)(i?.errors)&&n.push(...i.errors),i?.record},Se=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?ye(e,t,n):e.array&&e.expression?be(e,t,n):xe(e,t,n)},U=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=Se(a,t,r),e===void 0)continue}else{let{error:n,value:i}=Ce(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}let a=Object.keys(n).length>0?{unified_custom_fields:n}:{};return{record:{...i,...a},errors:r.length>0?r:void 0}},W=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if((0,l.isValidExpression)(e))try{return(0,l.evaluate)(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>W(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=W(r,t);return n}return e},Ce=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return G(n,t,e);case`enum`:return we(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},G=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=(0,l.evaluate)(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},we=(e,t,n)=>{let r=G(e,t,n),i=(0,c.notMissing)(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if((0,c.isString)(a)){let n=ge(a);if((0,c.notMissing)(n)){let e=(0,c.notMissing)(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=(0,l.evaluate)(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},Te=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Ee=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),De=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Oe=(0,c.zStrictObject)({type:c.z.literal(`oauth2`),authorizationUrl:c.z.string().optional(),authorizationParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenUrl:c.z.string().optional(),tokenParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenExpiresIn:c.z.number().optional(),tokenRefreshExpiresIn:c.z.number().optional(),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0),scopes:c.z.string().optional(),scopeDelimiter:c.z.string().optional(),customHeaders:c.z.record(c.z.string(),c.z.string()).optional(),pkce:c.z.boolean().optional()}),ke=c.z.discriminatedUnion(`type`,[Te,Ee,De,Oe]),K=c.z.object({baseUrl:c.z.string(),url:c.z.string(),method:c.z.enum(u.HttpMethods),response:(0,c.zStrictObject)({indexField:c.z.string().optional(),dataKey:c.z.string().optional(),nextKey:c.z.string().optional()}).optional(),iterator:(0,c.zStrictObject)({key:c.z.string(),in:c.z.enum(u.RequestParameterLocations)}),cursor:(0,c.zStrictObject)({token:c.z.string().optional().nullable(),position:c.z.number().optional().nullable()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:(0,c.zStrictObject)({name:c.z.string(),value:c.z.unknown(),in:c.z.enum(u.RequestParameterLocations),condition:c.z.string().optional()}).array().optional()}),Ae=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional(),next:c.z.string().optional().nullable(),position:c.z.number().optional()}).optional(),je=25,Me=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?je:i,o=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?(0,l.safeEvaluateRecord)({...t,args:o},e):{},d={...s,customErrors:t?.customErrors},{baseUrl:f,url:p,method:m,response:h,iterator:g,cursor:_,customErrors:v,args:y}=K.parse(d),b=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,x=ke.parse(b),S=y?(0,u.parseRequestParameters)(y):{query:{},body:{},headers:{}},C=(0,u.createAuthorizationHeaders)(x),w={...S?.headers??{},...C},T=e.connector?.rateLimit,E=e.connector?.concurrency,D=T!==void 0||E!==void 0?{rateLimit:T,concurrency:E}:void 0,O=_?.token??null,k=null,A=null,j=[],M=[],N=[],P=a,F=_?.position??0,I=!0,L=!0;do{I?I=!1:F=0,O!==null&&(g.in===`query`?S.query[g.key]=O.toString():g.in===`body`&&(S.body[g.key]=O));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${f}${p}`,queryParams:S?.query,method:m,headers:w,body:S?.body,customErrorConfigs:v,requestConfig:D})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}k=O,M=h?.dataKey?t.data[h?.dataKey]:t.data;let r=M?.slice(F,F+P);P-=r.length,F+=r.length,N.push(t),j=j.concat(r),A=t?.status,O=h?.nextKey?t.data[h?.nextKey]:void 0,r.length===M.length&&P===0&&(F=0,k=O),L=(0,c.isMissing)(O)&&j.length<a}while((0,c.notMissing)(O)&&j.length<a&&M?.length>0);let ee=Ne(j,h);return{block:e,successful:!0,output:{data:ee,raw:N,statusCode:A,next:L?void 0:k,position:L?void 0:F}}},Ne=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},Pe=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Fe=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),Ie=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Le=(0,c.zStrictObject)({type:c.z.literal(`oauth2`),authorizationUrl:c.z.string().optional(),authorizationParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenUrl:c.z.string().optional(),tokenParams:c.z.record(c.z.string(),c.z.string()).optional(),tokenExpiresIn:c.z.number().optional(),tokenRefreshExpiresIn:c.z.number().optional(),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0),scopes:c.z.string().optional(),scopeDelimiter:c.z.string().optional(),customHeaders:c.z.record(c.z.string(),c.z.string()).optional(),pkce:c.z.boolean().optional()}),q=c.z.discriminatedUnion(`type`,[Pe,Fe,Ie,Le]),Re=c.z.object({baseUrl:c.z.string().optional(),url:c.z.string(),method:c.z.enum(u.HttpMethods),authorization:q.optional(),response:(0,c.zStrictObject)({collection:c.z.boolean().optional(),indexField:c.z.string().optional(),dataKey:c.z.string().optional()}).optional(),customErrors:u.CUSTOM_ERROR_CONFIG_SCHEMA.array().optional(),args:(0,c.zStrictObject)({name:c.z.string(),value:c.z.unknown(),in:c.z.enum(u.RequestParameterLocations),condition:c.z.string().optional()}).array().optional()}),ze=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional()}).optional(),Be=async({block:e,params:t})=>{let n=u.RequestClientFactory.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||(0,l.evaluate)(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?(0,l.safeEvaluateRecord)({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:d,method:f,response:p,authorization:m,customErrors:h,args:g}=Re.parse(o),_=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=g?(0,u.parseRequestParameters)(g):{query:{},body:{},headers:{}},y=(0,c.notMissing)(m)?m:q.parse(_),b=(0,u.createAuthorizationHeaders)(y),x={...v?.headers??{},...b},S=e.connector?.rateLimit,C=e.connector?.concurrency,w=S!==void 0||C!==void 0?{rateLimit:S,concurrency:C}:void 0,T;try{T=await n.performRequest({httpClient:e.httpClient,url:`${s}${d}`,queryParams:v?.query,method:f,headers:x,body:v?.body,customErrorConfigs:h,requestConfig:w})}catch(t){let n=t;return{block:e,successful:!1,errors:[(0,u.serializeHttpResponseError)(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let E=p?.dataKey?T.data[p?.dataKey]:T.data,D=Ve(E,p);return{block:e,successful:!0,output:{data:D,raw:T,statusCode:T?.status,message:T?.message}}},Ve=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},He=c.z.object({values:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).or(c.z.array(c.z.unknown()))}),Ue=c.z.object({data:c.z.unknown()}),We=async({block:e,params:t})=>{let{values:n}=He.parse(t),r=Array.isArray(n)?n.map(t=>Ge(t,e)):Ge(n,e);return{block:{...e},successful:!0,output:{data:r}}},Ge=(e,t)=>(0,c.isString)(e)?(0,l.safeEvaluate)(e,t):(0,c.isObject)(e)?(0,l.safeEvaluateRecord)(e,t):e,Ke=c.z.object({targetFieldKey:c.z.string(),type:c.z.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:c.z.boolean().default(!1),custom:c.z.boolean().default(!1),hidden:c.z.boolean().default(!1),properties:c.z.lazy(()=>Ke).array().optional()}),J=c.z.object({fields:Ke.array().optional(),dataSource:c.z.string()}),qe=c.z.object({data:c.z.unknown()});let Y=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const X=({value:e,type:t,format:n})=>{if((0,c.isMissing)(e))return null;switch(t){case Y.String:return(0,c.safeParseToString)({value:e});case Y.Number:return(0,c.safeParseToNumber)({value:e});case Y.Boolean:return(0,c.safeParseToBoolean)({value:e});case Y.DateTimeString:return(0,c.safeParseToDateTimeString)({value:e,format:n});default:return e}},Je=e=>{let t=Object.values(Y);return t.includes(e)},Ye=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>Xe(e,t)):Xe(e.result,t),{block:{...e,result:n},successful:!0}},Xe=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Je(i)&&(!t.custom&&(0,c.notMissing)(n[r])?n[r]=X({value:e[r],type:i}):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=X({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},Ze=async({block:e,params:t})=>{let{fields:n,dataSource:r}=J.parse(t),i=(0,l.evaluate)(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Z(e,n)):Z(i,n),{block:{...e},successful:!0,output:{data:a}}},Qe=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Z(t,e.properties):t):typeof t==`object`&&t?Z(t,e.properties):t,Z=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i,array:a}=t;i===`object`?!t.custom&&(0,c.notMissing)(n[r])?n[r]=Qe(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Qe(t,e.unified_custom_fields?.[r])):Je(i)&&(!t.custom&&(0,c.notMissing)(n[r])?(!a||!Array.isArray(n[r]))&&(n[r]=X({value:e[r],type:i})):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(!a||!Array.isArray(n.unified_custom_fields[r]))&&(n.unified_custom_fields[r]=X({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let Q=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const $={[Q.TYPECAST]:{v1:{fn:Ye},v2:{fn:Ze,inputSchema:J,outputSchema:qe}},[Q.MAP_FIELDS]:{v1:{fn:pe},v2:{fn:ve,inputSchema:H,outputSchema:_e}},[Q.REQUEST]:{v1:{fn:Be,inputSchema:Re,outputSchema:ze}},[Q.GROUP_DATA]:{v1:{fn:fe,inputSchema:z,outputSchema:de}},[Q.PAGINATED_REQUEST]:{v1:{fn:Me,inputSchema:K,outputSchema:Ae}},[Q.STATIC_VALUES]:{v1:{fn:We,inputSchema:He,outputSchema:Ue}}},$e=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch(e){return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid: ${e?.message}`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},et={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=$}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:$e(i,e)}:i}};exports.AUTHENTICATION_SCHEMA=q,exports.COMPOSITE_ID_LATEST_VERSION=b,exports.CoreError=x,exports.StepFunctionName=Q,exports.StepFunctionsFactory=et,exports.StepFunctionsRegistry=$,exports.areCursorsEqual=se,exports.decodeCompositeId=A,exports.encodeCompositeId=k,exports.expandCursor=R,exports.getCategoryDetails=f,exports.isCompositeId=te,exports.isCoreError=ue,exports.isCursorEmpty=ce,exports.isValidCategory=p,exports.minifyCursor=ie,exports.updateCursor=le;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{decodeFromBase64 as e,encodeToBase64 as t,getContentHash as n,getCountryAlpha2CodeByAlpha2Code as r,getCountryAlpha2CodeByAlpha3Code as i,getCountryAlpha2CodeByCitizenship as a,getCountryAlpha2CodeByCountryCode as o,getCountryAlpha2CodeByCountryName as s,getCountryAlpha3CodeByAlpha2Code as c,getCountryAlpha3CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as u,getCountryAlpha3CodeByCountryName as d,getCountryCodeByAlpha2Code as f,getCountryCodeByAlpha3Code as p,getCountryCodeByCountryCode as m,getCountryCodeByCountryName as h,getCountryNameByAlpha2Code as g,getCountryNameByAlpha3Code as _,getCountryNameByCountryCode as v,getCountryNameByCountryName as y,getCountrySubDivisionCodeBySubDivisionName as b,getCountrySubDivisionNameBySubDivisionCode as x,getCountrySubDivisionsByAlpha2Code as S,getDocumentFileFormatFromExtension as C,isMissing as w,isObject as ee,isString as T,notMissing as E,safeParseToBoolean as D,safeParseToDateTimeString as O,safeParseToNumber as k,safeParseToString as A,z as j,zStrictObject as M}from"@stackone/utils";import{evaluate as N,isValidExpression as P,safeEvaluate as F,safeEvaluateRecord as I}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as L,HttpMethods as R,RequestClientFactory as te,RequestParameterLocations as z,createAuthorizationHeaders as ne,parseRequestParameters as re,serializeHttpResponseError as ie}from"@stackone/transport";const ae={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`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`},action:{title:`Action`,key:`action`,description:`Action`}},oe=e=>{let t=ae[e.toLowerCase()];return t??null},se=e=>!!ae[e.toLowerCase()],ce=`so1!`,B=t(ce),V=`:`,H=`,`,le=RegExp(`(?<!\\\\)${V}`,`g`),ue=RegExp(`(?<!\\\\)${H}`,`g`),U=1;var W=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},G=class extends W{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},de=class extends G{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},fe=class extends G{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},pe=class extends G{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},me=class extends G{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const he=e=>!w(e)&&`value`in e&&e.value!==void 0,ge=e=>!w(e)&&`identifiers`in e&&e.identifiers!==void 0,_e=(e,t={version:U})=>{if(t.version===1)return Ce(ye(e,t.aliases));throw new me(`Cannot generate ID, unsupported version number: ${t.version}`)},ve=(e,t={version:U})=>{let n=Se(e,t),r={};return n&&n.split(ue).forEach(e=>{let[n,i]=e.split(le),a=xe(n,t.aliases??{});r[a]=Ee(i)}),r},ye=(e,t={})=>{if(he(e))return be({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(ge(e))return e.identifiers.map(e=>be({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(H);throw new pe},be=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,Te(e.value)].filter(Boolean).join(V)},xe=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,Se=(e,t)=>{if(t.version===1)return we(e);throw new me(`Cannot decode ID, unsupported version number: ${t.version}`)},Ce=e=>`${B}${t(e)}`,we=t=>{if(!t.startsWith(B))throw new de(`Trying to decode an ID without the header: ${t}`);let n=t.split(B)[1];if(!n)throw new fe(`Trying to decode an ID without a body: ${t}`);return e(n)},Te=e=>[H,V].reduce((e,t)=>e.replace(t,`\\`+t),e),Ee=e=>[H,V].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),De=e=>w(e)?!1:e.startsWith(B),Oe=M({r:j.record(j.string(),M({n:j.number().optional().nullable(),c:j.string().optional().nullable(),p:j.number().optional().nullable()})),v:j.number(),t:j.number()}),ke=M({remote:j.record(j.string(),M({pageNumber:j.number().optional(),providerPageCursor:j.string().optional(),position:j.number().optional()})),version:j.number(),timestamp:j.number()}),Ae=e=>t(JSON.stringify(je(e))),je=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},K=t=>{try{if(T(t)){let n=e(t),r=JSON.parse(n),i=Oe.parse(r);return Me(i)}else return ke.parse(t),t}catch{return null}},Me=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},Ne=(e,t)=>{let r=typeof e==`string`?K(e):e,i=typeof t==`string`?K(t):t;if(r===null||i===null)return r===i;let{timestamp:a,...o}=r,{timestamp:s,...c}=i;return n(o)===n(c)},Pe=({cursor:e,ignoreStepIndex:t})=>w(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return(w(t)||r!==t.toString())&&(n=n&&w(i.pageNumber)&&w(i.position)&&w(i.providerPageCursor)),n},!0),Fe=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=w(n)&&w(r)&&w(i);return w(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},Ie=e=>e instanceof W,Le=j.object({stepsDataToGroup:j.array(j.string()),isSingleRecord:j.boolean().optional()}),Re=j.object({data:j.unknown()}),ze=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=Le.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=E(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},Be=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=Ve(r,a,i),s=He(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=He(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},Ve=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),He=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=Ue(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},Ue=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=N(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},We=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return r;case`country_alpha3code_by_alpha3code`:return l;case`country_code_by_country_code`:return m;case`country_name_by_country_name`:return y;case`country_name_by_alpha3code`:return _;case`country_name_by_alpha2code`:return g;case`country_name_by_country_code`:return v;case`country_alpha3code_by_alpha2code`:return c;case`country_alpha3code_by_country_name`:return d;case`country_alpha3code_by_country_code`:return u;case`country_alpha2code_by_alpha3code`:return i;case`country_alpha2code_by_country_name`:return s;case`country_alpha2code_by_country_code`:return o;case`country_code_by_alpha2code`:return f;case`country_code_by_alpha3code`:return p;case`country_code_by_country_name`:return h;case`country_subdivisions_by_alpha2code`:return S;case`country_subdivision_code_by_subdivision_name`:return b;case`country_alpha2code_by_citizenship`:return a;case`country_subdivision_name_by_subdivision_code`:return x;case`document_file_format_from_extension`:return C;default:return}},Ge=M({targetFieldKey:j.string(),alias:j.string().optional(),expression:j.string().optional(),values:j.unknown().optional(),type:j.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:j.boolean().default(!1),custom:j.boolean().default(!1),hidden:j.boolean().default(!1),enumMapper:M({matcher:j.string().or(M({matchExpression:j.string(),value:j.string()}).array())}).optional(),properties:j.lazy(()=>Ge).array().optional()}),Ke=j.object({fields:Ge.array(),dataSource:j.string(),externalSources:j.record(j.string(),j.string()).optional()}),qe=j.object({data:j.unknown()}),Je=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=Ke.parse(t),o=N(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!o)return{block:e,successful:!0};let s=Object.keys(a??{})?.reduce((t,n)=>(t[n]=N(a?.[n],e),t),{}),c;if(Array.isArray(o))c=o.map(e=>{let t=q(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=q(r,{...o,external:s});c=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:c},errors:Object.keys(n).length>0?n:void 0}},Ye=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=J(r,t),a=q(e.properties,i);return E(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},Xe=(e,t,n)=>{if(e.expression)try{let r=N(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=q(e.properties,t);return E(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=q(e.properties,r);return E(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},Ze=(e,t,n)=>{let r=E(e.values)?e.values:t,i=q(e.properties,r);return E(i?.errors)&&n.push(...i.errors),i?.record},Qe=(e,t,n)=>{if(!w(e.properties))return e.array&&Array.isArray(e.values)?Ye(e,t,n):e.array&&e.expression?Xe(e,t,n):Ze(e,t,n)},q=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=Qe(a,t,r),e===void 0)continue}else{let{error:n,value:i}=$e(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}let a=Object.keys(n).length>0?{unified_custom_fields:n}:{};return{record:{...i,...a},errors:r.length>0?r:void 0}},J=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if(P(e))try{return N(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>J(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=J(r,t);return n}return e},$e=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return et(n,t,e);case`enum`:return tt(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},et=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=N(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},tt=(e,t,n)=>{let r=et(e,t,n),i=E(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if(T(a)){let n=We(a);if(E(n)){let e=E(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=N(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},nt=M({type:j.literal(`none`)}),rt=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),it=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),at=M({type:j.literal(`oauth2`),authorizationUrl:j.string().optional(),authorizationParams:j.record(j.string(),j.string()).optional(),tokenUrl:j.string().optional(),tokenParams:j.record(j.string(),j.string()).optional(),tokenExpiresIn:j.number().optional(),tokenRefreshExpiresIn:j.number().optional(),token:j.string(),includeBearer:j.boolean().optional().default(!0),scopes:j.string().optional()}),ot=j.discriminatedUnion(`type`,[nt,rt,it,at]),st=j.object({baseUrl:j.string(),url:j.string(),method:j.enum(R),response:M({indexField:j.string().optional(),dataKey:j.string().optional(),nextKey:j.string().optional()}).optional(),iterator:M({key:j.string(),in:j.enum(z)}),cursor:M({token:j.string().optional().nullable(),position:j.number().optional().nullable()}).optional(),customErrors:L.array().optional(),args:M({name:j.string(),value:j.unknown(),in:j.enum(z),condition:j.string().optional()}).array().optional()}),ct=M({data:j.unknown().optional(),raw:j.unknown().optional(),statusCode:j.number(),message:j.string().optional(),next:j.string().optional().nullable(),position:j.number().optional()}).optional(),lt=25,ut=async({block:e,params:t})=>{let n=te.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?lt:i,o=r?r.filter(t=>!t.condition||N(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?I({...t,args:o},e):{},c={...s,customErrors:t?.customErrors},{baseUrl:l,url:u,method:d,response:f,iterator:p,cursor:m,customErrors:h,args:g}=st.parse(c),_=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=ot.parse(_),y=g?re(g):{query:{},body:{},headers:{}},b=ne(v),x={...y?.headers??{},...b},S=e.connector?.rateLimit,C=e.connector?.concurrency,ee=S!==void 0||C!==void 0?{rateLimit:S,concurrency:C}:void 0,T=m?.token??null,D=null,O=null,k=[],A=[],j=[],M=a,P=m?.position??0,F=!0,L=!0;do{F?F=!1:P=0,T!==null&&(p.in===`query`?y.query[p.key]=T.toString():p.in===`body`&&(y.body[p.key]=T));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${l}${u}`,queryParams:y?.query,method:d,headers:x,body:y?.body,customErrorConfigs:h,requestConfig:ee})}catch(t){let n=t;return{block:e,successful:!1,errors:[ie(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}D=T,A=f?.dataKey?t.data[f?.dataKey]:t.data;let r=A?.slice(P,P+M);M-=r.length,P+=r.length,j.push(t),k=k.concat(r),O=t?.status,T=f?.nextKey?t.data[f?.nextKey]:void 0,r.length===A.length&&M===0&&(P=0,D=T),L=w(T)&&k.length<a}while(E(T)&&k.length<a&&A?.length>0);let R=dt(k,f);return{block:e,successful:!0,output:{data:R,raw:j,statusCode:O,next:L?void 0:D,position:L?void 0:P}}},dt=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},ft=M({type:j.literal(`none`)}),pt=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),mt=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),ht=M({type:j.literal(`oauth2`),authorizationUrl:j.string().optional(),authorizationParams:j.record(j.string(),j.string()).optional(),tokenUrl:j.string().optional(),tokenParams:j.record(j.string(),j.string()).optional(),tokenExpiresIn:j.number().optional(),tokenRefreshExpiresIn:j.number().optional(),token:j.string(),includeBearer:j.boolean().optional().default(!0),scopes:j.string().optional()}),Y=j.discriminatedUnion(`type`,[ft,pt,mt,ht]),gt=j.object({baseUrl:j.string().optional(),url:j.string(),method:j.enum(R),authorization:Y.optional(),response:M({collection:j.boolean().optional(),indexField:j.string().optional(),dataKey:j.string().optional()}).optional(),customErrors:L.array().optional(),args:M({name:j.string(),value:j.unknown(),in:j.enum(z),condition:j.string().optional()}).array().optional()}),_t=M({data:j.unknown().optional(),raw:j.unknown().optional(),statusCode:j.number(),message:j.string().optional()}).optional(),vt=async({block:e,params:t})=>{let n=te.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||N(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?I({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:l,response:u,authorization:d,customErrors:f,args:p}=gt.parse(o),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,h=p?re(p):{query:{},body:{},headers:{}},g=E(d)?d:Y.parse(m),_=ne(g),v={...h?.headers??{},..._},y=e.connector?.rateLimit,b=e.connector?.concurrency,x=y!==void 0||b!==void 0?{rateLimit:y,concurrency:b}:void 0,S;try{S=await n.performRequest({httpClient:e.httpClient,url:`${s}${c}`,queryParams:h?.query,method:l,headers:v,body:h?.body,customErrorConfigs:f,requestConfig:x})}catch(t){let n=t;return{block:e,successful:!1,errors:[ie(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let C=u?.dataKey?S.data[u?.dataKey]:S.data,w=yt(C,u);return{block:e,successful:!0,output:{data:w,raw:S,statusCode:S?.status,message:S?.message}}},yt=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},bt=j.object({values:j.string().or(j.record(j.string(),j.unknown())).or(j.array(j.unknown()))}),xt=j.object({data:j.unknown()}),St=async({block:e,params:t})=>{let{values:n}=bt.parse(t),r=Array.isArray(n)?n.map(t=>Ct(t,e)):Ct(n,e);return{block:{...e},successful:!0,output:{data:r}}},Ct=(e,t)=>T(e)?F(e,t):ee(e)?I(e,t):e,wt=j.object({targetFieldKey:j.string(),type:j.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:j.boolean().default(!1),custom:j.boolean().default(!1),hidden:j.boolean().default(!1),properties:j.lazy(()=>wt).array().optional()}),Tt=j.object({fields:wt.array().optional(),dataSource:j.string()}),Et=j.object({data:j.unknown()});let X=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Z=({value:e,type:t,format:n})=>{if(w(e))return null;switch(t){case X.String:return A({value:e});case X.Number:return k({value:e});case X.Boolean:return D({value:e});case X.DateTimeString:return O({value:e,format:n});default:return e}},Dt=e=>{let t=Object.values(X);return t.includes(e)},Ot=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>kt(e,t)):kt(e.result,t),{block:{...e,result:n},successful:!0}},kt=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Dt(i)&&(!t.custom&&E(n[r])?n[r]=Z({value:e[r],type:i}):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Z({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},At=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Tt.parse(t),i=N(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Q(e,n)):Q(i,n),{block:{...e},successful:!0,output:{data:a}}},jt=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Q(t,e.properties):t):typeof t==`object`&&t?Q(t,e.properties):t,Q=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i,array:a}=t;i===`object`?!t.custom&&E(n[r])?n[r]=jt(t,e[r]):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=jt(t,e.unified_custom_fields?.[r])):Dt(i)&&(!t.custom&&E(n[r])?(!a||!Array.isArray(n[r]))&&(n[r]=Z({value:e[r],type:i})):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(!a||!Array.isArray(n.unified_custom_fields[r]))&&(n.unified_custom_fields[r]=Z({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const Mt={[$.TYPECAST]:{v1:{fn:Ot},v2:{fn:At,inputSchema:Tt,outputSchema:Et}},[$.MAP_FIELDS]:{v1:{fn:Be},v2:{fn:Je,inputSchema:Ke,outputSchema:qe}},[$.REQUEST]:{v1:{fn:vt,inputSchema:gt,outputSchema:_t}},[$.GROUP_DATA]:{v1:{fn:ze,inputSchema:Le,outputSchema:Re}},[$.PAGINATED_REQUEST]:{v1:{fn:ut,inputSchema:st,outputSchema:ct}},[$.STATIC_VALUES]:{v1:{fn:St,inputSchema:bt,outputSchema:xt}}},Nt=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch(e){return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid: ${e?.message}`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},Pt={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=Mt}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:Nt(i,e)}:i}};export{Y as AUTHENTICATION_SCHEMA,U as COMPOSITE_ID_LATEST_VERSION,W as CoreError,$ as StepFunctionName,Pt as StepFunctionsFactory,Mt as StepFunctionsRegistry,Ne as areCursorsEqual,ve as decodeCompositeId,_e as encodeCompositeId,K as expandCursor,oe as getCategoryDetails,De as isCompositeId,Ie as isCoreError,Pe as isCursorEmpty,se as isValidCategory,Ae as minifyCursor,Fe as updateCursor};
|
|
1
|
+
import{decodeFromBase64 as e,encodeToBase64 as t,getContentHash as n,getCountryAlpha2CodeByAlpha2Code as r,getCountryAlpha2CodeByAlpha3Code as i,getCountryAlpha2CodeByCitizenship as a,getCountryAlpha2CodeByCountryCode as o,getCountryAlpha2CodeByCountryName as s,getCountryAlpha3CodeByAlpha2Code as c,getCountryAlpha3CodeByAlpha3Code as l,getCountryAlpha3CodeByCountryCode as u,getCountryAlpha3CodeByCountryName as d,getCountryCodeByAlpha2Code as f,getCountryCodeByAlpha3Code as p,getCountryCodeByCountryCode as m,getCountryCodeByCountryName as h,getCountryNameByAlpha2Code as g,getCountryNameByAlpha3Code as _,getCountryNameByCountryCode as v,getCountryNameByCountryName as y,getCountrySubDivisionCodeBySubDivisionName as b,getCountrySubDivisionNameBySubDivisionCode as x,getCountrySubDivisionsByAlpha2Code as S,getDocumentFileFormatFromExtension as C,isMissing as w,isObject as ee,isString as T,notMissing as E,safeParseToBoolean as D,safeParseToDateTimeString as O,safeParseToNumber as k,safeParseToString as A,z as j,zStrictObject as M}from"@stackone/utils";import{evaluate as N,isValidExpression as P,safeEvaluate as F,safeEvaluateRecord as I}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as L,HttpMethods as R,RequestClientFactory as te,RequestParameterLocations as z,createAuthorizationHeaders as ne,parseRequestParameters as re,serializeHttpResponseError as ie}from"@stackone/transport";const ae={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`},internal:{title:`Internal`,key:`internal`,description:`Category for internal operations`},action:{title:`Action`,key:`action`,description:`Action`}},oe=e=>{let t=ae[e.toLowerCase()];return t??null},se=e=>!!ae[e.toLowerCase()],ce=`so1!`,B=t(ce),V=`:`,H=`,`,le=RegExp(`(?<!\\\\)${V}`,`g`),ue=RegExp(`(?<!\\\\)${H}`,`g`),U=1;var W=class e extends Error{type;category;context;constructor({category:t,name:n,type:r,context:i,message:a}){super(a),this.name=n??`CoreError`,this.type=r,this.category=t,this.context=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}toString(){let e=this.message?`: ${this.message}`:``;return`${this.category}-${this.name} [${this.type}]${e}`}},G=class extends W{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},de=class extends G{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},fe=class extends G{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},pe=class extends G{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},me=class extends G{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const he=e=>!w(e)&&`value`in e&&e.value!==void 0,ge=e=>!w(e)&&`identifiers`in e&&e.identifiers!==void 0,_e=(e,t={version:U})=>{if(t.version===1)return Ce(ye(e,t.aliases));throw new me(`Cannot generate ID, unsupported version number: ${t.version}`)},ve=(e,t={version:U})=>{let n=Se(e,t),r={};return n&&n.split(ue).forEach(e=>{let[n,i]=e.split(le),a=xe(n,t.aliases??{});r[a]=Ee(i)}),r},ye=(e,t={})=>{if(he(e))return be({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(ge(e))return e.identifiers.map(e=>be({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(H);throw new pe},be=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,Te(e.value)].filter(Boolean).join(V)},xe=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,Se=(e,t)=>{if(t.version===1)return we(e);throw new me(`Cannot decode ID, unsupported version number: ${t.version}`)},Ce=e=>`${B}${t(e)}`,we=t=>{if(!t.startsWith(B))throw new de(`Trying to decode an ID without the header: ${t}`);let n=t.split(B)[1];if(!n)throw new fe(`Trying to decode an ID without a body: ${t}`);return e(n)},Te=e=>[H,V].reduce((e,t)=>e.replace(t,`\\`+t),e),Ee=e=>[H,V].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),De=e=>w(e)?!1:e.startsWith(B),Oe=M({r:j.record(j.string(),M({n:j.number().optional().nullable(),c:j.string().optional().nullable(),p:j.number().optional().nullable()})),v:j.number(),t:j.number()}),ke=M({remote:j.record(j.string(),M({pageNumber:j.number().optional(),providerPageCursor:j.string().optional(),position:j.number().optional()})),version:j.number(),timestamp:j.number()}),Ae=e=>t(JSON.stringify(je(e))),je=e=>{let{remote:t,version:n,timestamp:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{pageNumber:t,providerPageCursor:n,position:r}])=>[e,{n:t,c:n,p:r}])),a={r:i,v:n,t:r};return a},K=t=>{try{if(T(t)){let n=e(t),r=JSON.parse(n),i=Oe.parse(r);return Me(i)}else return ke.parse(t),t}catch{return null}},Me=e=>{let{r:t,v:n,t:r}=e,i=Object.fromEntries(Object.entries(t).map(([e,{n:t,c:n,p:r}])=>[e,{pageNumber:t,providerPageCursor:n,position:r}])),a={remote:i,version:n,timestamp:r};return a},Ne=(e,t)=>{let r=typeof e==`string`?K(e):e,i=typeof t==`string`?K(t):t;if(r===null||i===null)return r===i;let{timestamp:a,...o}=r,{timestamp:s,...c}=i;return n(o)===n(c)},Pe=({cursor:e,ignoreStepIndex:t})=>w(e)?!0:Object.keys(e?.remote??{}).reduce((n,r)=>{let i=e?.remote?.[r];return(w(t)||r!==t.toString())&&(n=n&&w(i.pageNumber)&&w(i.position)&&w(i.providerPageCursor)),n},!0),Fe=({cursor:e,stepIndex:t,pageNumber:n,providerPageCursor:r,position:i})=>{let a={pageNumber:n??void 0,providerPageCursor:r??void 0,position:i??void 0},o=w(n)&&w(r)&&w(i);return w(e)?{remote:o?{}:{[t]:a},version:2,timestamp:Date.now()}:o?(delete e.remote[t],e):{...e,remote:{...e.remote,[t]:a}}},Ie=e=>e instanceof W,Le=j.object({stepsDataToGroup:j.array(j.string()),isSingleRecord:j.boolean().optional()}),Re=j.object({data:j.unknown()}),ze=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=Le.parse(t),i=n.reduce((t,n)=>{let i=e.steps?.[n]?.output?.data;return i?r?{...t,[n]:{...i}}:(Object.keys(i).forEach(e=>{let r=E(t[e])?t[e]:{};t[e]={...r,[n]:{...i[e]}}}),t):t},{});return{block:{...e},successful:!0,output:{data:r?i:Object.values(i)}}},Be=async({block:e})=>{let t=e?.fieldConfigs,n=[],r=e.steps;if(!t||e?.debug?.custom_mappings===`disabled`||!r)return{block:e,successful:!0};let i;if(Array.isArray(e.result)){let a=e.result.length;i=e.result.map((e,i)=>{let o=Ve(r,a,i),s=He(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=He(e.result,t,r);i=a.record,n.push(...a.errors||[])}return{block:{...e,result:i},successful:!0,errors:Object.keys(n).length>0?n:void 0}},Ve=(e,t,n)=>Object.entries(e).reduce((e,[r,i])=>{let a=i?.output?.data;return Array.isArray(a)&&a.length===t?e[r]={output:{data:a[n]}}:e[r]=i,e},{}),He=(e,t,n)=>{if(!e||!n)return{record:e};let r={unified:{...e},...typeof n==`object`?n:{}},i={},a=[],o={...e};for(let n of t){let{error:t,value:s}=Ue(r,e.id,n);if(t){a.push(t);continue}n.custom?i[n.targetFieldKey]=s:o[n.targetFieldKey]=s}return{record:{...o,unified_custom_fields:Object.keys(i).length>0?i:void 0},errors:a.length>0?a:void 0}},Ue=(e,t,n)=>{let{expression:r,targetFieldKey:i}=n;if(!r)return{error:{message:`Expression is empty`,id:t,targetField:i}};let a;try{a=N(r,e)}catch{return{error:{message:`Invalid expression`,id:t,targetField:i}}}return a===void 0?{error:{message:`Expression returned no value`,id:t,targetField:i}}:{value:a}},We=e=>{switch(e){case`country_alpha2code_by_alpha2code`:return r;case`country_alpha3code_by_alpha3code`:return l;case`country_code_by_country_code`:return m;case`country_name_by_country_name`:return y;case`country_name_by_alpha3code`:return _;case`country_name_by_alpha2code`:return g;case`country_name_by_country_code`:return v;case`country_alpha3code_by_alpha2code`:return c;case`country_alpha3code_by_country_name`:return d;case`country_alpha3code_by_country_code`:return u;case`country_alpha2code_by_alpha3code`:return i;case`country_alpha2code_by_country_name`:return s;case`country_alpha2code_by_country_code`:return o;case`country_code_by_alpha2code`:return f;case`country_code_by_alpha3code`:return p;case`country_code_by_country_name`:return h;case`country_subdivisions_by_alpha2code`:return S;case`country_subdivision_code_by_subdivision_name`:return b;case`country_alpha2code_by_citizenship`:return a;case`country_subdivision_name_by_subdivision_code`:return x;case`document_file_format_from_extension`:return C;default:return}},Ge=M({targetFieldKey:j.string(),alias:j.string().optional(),expression:j.string().optional(),values:j.unknown().optional(),type:j.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:j.boolean().default(!1),custom:j.boolean().default(!1),hidden:j.boolean().default(!1),enumMapper:M({matcher:j.string().or(M({matchExpression:j.string(),value:j.string()}).array())}).optional(),properties:j.lazy(()=>Ge).array().optional()}),Ke=j.object({fields:Ge.array(),dataSource:j.string(),externalSources:j.record(j.string(),j.string()).optional()}),qe=j.object({data:j.unknown()}),Je=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=Ke.parse(t),o=N(i,e);if(!r||!i||e?.debug?.custom_mappings===`disabled`||!o)return{block:e,successful:!0};let s=Object.keys(a??{})?.reduce((t,n)=>(t[n]=N(a?.[n],e),t),{}),c;if(Array.isArray(o))c=o.map(e=>{let t=q(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=q(r,{...o,external:s});c=e?.record,n.push(...e?.errors||[])}return{block:{...e},successful:!0,output:{data:c},errors:Object.keys(n).length>0?n:void 0}},Ye=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=J(r,t),a=q(e.properties,i);return E(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},Xe=(e,t,n)=>{if(e.expression)try{let r=N(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=q(e.properties,t);return E(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=q(e.properties,r);return E(t?.errors)&&n.push(...t.errors),t?.record}}catch{n.push({message:`Invalid expression`,id:t?.id,targetField:e.targetFieldKey});return}},Ze=(e,t,n)=>{let r=E(e.values)?e.values:t,i=q(e.properties,r);return E(i?.errors)&&n.push(...i.errors),i?.record},Qe=(e,t,n)=>{if(!w(e.properties))return e.array&&Array.isArray(e.values)?Ye(e,t,n):e.array&&e.expression?Xe(e,t,n):Ze(e,t,n)},q=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=Qe(a,t,r),e===void 0)continue}else{let{error:n,value:i}=$e(t,t?.id,a);if(e=i,n){r.push(n);continue}}a.custom?n[a.targetFieldKey]=e:i[a.targetFieldKey]=e}let a=Object.keys(n).length>0?{unified_custom_fields:n}:{};return{record:{...i,...a},errors:r.length>0?r:void 0}},J=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if(P(e))try{return N(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>J(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=J(r,t);return n}return e},$e=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return et(n,t,e);case`enum`:return tt(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},et=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=N(e.expression,n)}catch{return{error:{message:`Invalid expression`,id:t,targetField:e.targetFieldKey}}}return r===void 0?{error:{message:`Expression returned no value`,id:t,targetField:e.targetFieldKey}}:{value:r}},tt=(e,t,n)=>{let r=et(e,t,n),i=E(r.value)?r.value:null;if(e.enumMapper===void 0)return{error:{message:`Enum mapper was not defined`,id:t,targetField:e.targetFieldKey}};let a=e.enumMapper.matcher;if(T(a)){let n=We(a);if(E(n)){let e=E(i)?n(i):null;return{value:{value:e??`unmapped_value`,source_value:i}}}else return{error:{message:`The built-in matcher "${a}" is not supported`,id:t,targetField:e.targetFieldKey}}}for(let e of a){let{matchExpression:t,value:r}=e,a=N(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},nt=M({type:j.literal(`none`)}),rt=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),it=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),at=M({type:j.literal(`oauth2`),authorizationUrl:j.string().optional(),authorizationParams:j.record(j.string(),j.string()).optional(),tokenUrl:j.string().optional(),tokenParams:j.record(j.string(),j.string()).optional(),tokenExpiresIn:j.number().optional(),tokenRefreshExpiresIn:j.number().optional(),token:j.string(),includeBearer:j.boolean().optional().default(!0),scopes:j.string().optional(),scopeDelimiter:j.string().optional(),customHeaders:j.record(j.string(),j.string()).optional(),pkce:j.boolean().optional()}),ot=j.discriminatedUnion(`type`,[nt,rt,it,at]),st=j.object({baseUrl:j.string(),url:j.string(),method:j.enum(R),response:M({indexField:j.string().optional(),dataKey:j.string().optional(),nextKey:j.string().optional()}).optional(),iterator:M({key:j.string(),in:j.enum(z)}),cursor:M({token:j.string().optional().nullable(),position:j.number().optional().nullable()}).optional(),customErrors:L.array().optional(),args:M({name:j.string(),value:j.unknown(),in:j.enum(z),condition:j.string().optional()}).array().optional()}),ct=M({data:j.unknown().optional(),raw:j.unknown().optional(),statusCode:j.number(),message:j.string().optional(),next:j.string().optional().nullable(),position:j.number().optional()}).optional(),lt=25,ut=async({block:e,params:t})=>{let n=te.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?lt:i,o=r?r.filter(t=>!t.condition||N(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?I({...t,args:o},e):{},c={...s,customErrors:t?.customErrors},{baseUrl:l,url:u,method:d,response:f,iterator:p,cursor:m,customErrors:h,args:g}=st.parse(c),_=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=ot.parse(_),y=g?re(g):{query:{},body:{},headers:{}},b=ne(v),x={...y?.headers??{},...b},S=e.connector?.rateLimit,C=e.connector?.concurrency,ee=S!==void 0||C!==void 0?{rateLimit:S,concurrency:C}:void 0,T=m?.token??null,D=null,O=null,k=[],A=[],j=[],M=a,P=m?.position??0,F=!0,L=!0;do{F?F=!1:P=0,T!==null&&(p.in===`query`?y.query[p.key]=T.toString():p.in===`body`&&(y.body[p.key]=T));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${l}${u}`,queryParams:y?.query,method:d,headers:x,body:y?.body,customErrorConfigs:h,requestConfig:ee})}catch(t){let n=t;return{block:e,successful:!1,errors:[ie(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}D=T,A=f?.dataKey?t.data[f?.dataKey]:t.data;let r=A?.slice(P,P+M);M-=r.length,P+=r.length,j.push(t),k=k.concat(r),O=t?.status,T=f?.nextKey?t.data[f?.nextKey]:void 0,r.length===A.length&&M===0&&(P=0,D=T),L=w(T)&&k.length<a}while(E(T)&&k.length<a&&A?.length>0);let R=dt(k,f);return{block:e,successful:!0,output:{data:R,raw:j,statusCode:O,next:L?void 0:D,position:L?void 0:P}}},dt=(e,t)=>{if(t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},ft=M({type:j.literal(`none`)}),pt=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),mt=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),ht=M({type:j.literal(`oauth2`),authorizationUrl:j.string().optional(),authorizationParams:j.record(j.string(),j.string()).optional(),tokenUrl:j.string().optional(),tokenParams:j.record(j.string(),j.string()).optional(),tokenExpiresIn:j.number().optional(),tokenRefreshExpiresIn:j.number().optional(),token:j.string(),includeBearer:j.boolean().optional().default(!0),scopes:j.string().optional(),scopeDelimiter:j.string().optional(),customHeaders:j.record(j.string(),j.string()).optional(),pkce:j.boolean().optional()}),Y=j.discriminatedUnion(`type`,[ft,pt,mt,ht]),gt=j.object({baseUrl:j.string().optional(),url:j.string(),method:j.enum(R),authorization:Y.optional(),response:M({collection:j.boolean().optional(),indexField:j.string().optional(),dataKey:j.string().optional()}).optional(),customErrors:L.array().optional(),args:M({name:j.string(),value:j.unknown(),in:j.enum(z),condition:j.string().optional()}).array().optional()}),_t=M({data:j.unknown().optional(),raw:j.unknown().optional(),statusCode:j.number(),message:j.string().optional()}).optional(),vt=async({block:e,params:t})=>{let n=te.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||N(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?I({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:l,response:u,authorization:d,customErrors:f,args:p}=gt.parse(o),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,h=p?re(p):{query:{},body:{},headers:{}},g=E(d)?d:Y.parse(m),_=ne(g),v={...h?.headers??{},..._},y=e.connector?.rateLimit,b=e.connector?.concurrency,x=y!==void 0||b!==void 0?{rateLimit:y,concurrency:b}:void 0,S;try{S=await n.performRequest({httpClient:e.httpClient,url:`${s}${c}`,queryParams:h?.query,method:l,headers:v,body:h?.body,customErrorConfigs:f,requestConfig:x})}catch(t){let n=t;return{block:e,successful:!1,errors:[ie(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let C=u?.dataKey?S.data[u?.dataKey]:S.data,w=yt(C,u);return{block:e,successful:!0,output:{data:w,raw:S,statusCode:S?.status,message:S?.message}}},yt=(e,t)=>{if(t?.collection&&t?.indexField&&Array.isArray(e))return e.reduce((e,n)=>{let r=t.indexField;return r&&n[r]&&(e[n[r]]=n),e},{});if(!t?.collection&&t?.indexField){let n=t.indexField;return n&&e[n]?{[e[n]]:e}:e}return e},bt=j.object({values:j.string().or(j.record(j.string(),j.unknown())).or(j.array(j.unknown()))}),xt=j.object({data:j.unknown()}),St=async({block:e,params:t})=>{let{values:n}=bt.parse(t),r=Array.isArray(n)?n.map(t=>Ct(t,e)):Ct(n,e);return{block:{...e},successful:!0,output:{data:r}}},Ct=(e,t)=>T(e)?F(e,t):ee(e)?I(e,t):e,wt=j.object({targetFieldKey:j.string(),type:j.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:j.boolean().default(!1),custom:j.boolean().default(!1),hidden:j.boolean().default(!1),properties:j.lazy(()=>wt).array().optional()}),Tt=j.object({fields:wt.array().optional(),dataSource:j.string()}),Et=j.object({data:j.unknown()});let X=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Z=({value:e,type:t,format:n})=>{if(w(e))return null;switch(t){case X.String:return A({value:e});case X.Number:return k({value:e});case X.Boolean:return D({value:e});case X.DateTimeString:return O({value:e,format:n});default:return e}},Dt=e=>{let t=Object.values(X);return t.includes(e)},Ot=async({block:e})=>{let t=e?.fieldConfigs;if(!t||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let n;return n=Array.isArray(e.result)?e.result.map(e=>kt(e,t)):kt(e.result,t),{block:{...e,result:n},successful:!0}},kt=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Dt(i)&&(!t.custom&&E(n[r])?n[r]=Z({value:e[r],type:i}):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Z({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},At=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Tt.parse(t),i=N(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>Q(e,n)):Q(i,n),{block:{...e},successful:!0,output:{data:a}}},jt=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?Q(t,e.properties):t):typeof t==`object`&&t?Q(t,e.properties):t,Q=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i,array:a}=t;i===`object`?!t.custom&&E(n[r])?n[r]=jt(t,e[r]):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=jt(t,e.unified_custom_fields?.[r])):Dt(i)&&(!t.custom&&E(n[r])?(!a||!Array.isArray(n[r]))&&(n[r]=Z({value:e[r],type:i})):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(!a||!Array.isArray(n.unified_custom_fields[r]))&&(n.unified_custom_fields[r]=Z({value:e.unified_custom_fields?.[r],type:i})))}),{...n}};let $=function(e){return e.TYPECAST=`typecast`,e.MAP_FIELDS=`map_fields`,e.GROUP_DATA=`group_data`,e.REQUEST=`request`,e.PAGINATED_REQUEST=`paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const Mt={[$.TYPECAST]:{v1:{fn:Ot},v2:{fn:At,inputSchema:Tt,outputSchema:Et}},[$.MAP_FIELDS]:{v1:{fn:Be},v2:{fn:Je,inputSchema:Ke,outputSchema:qe}},[$.REQUEST]:{v1:{fn:vt,inputSchema:gt,outputSchema:_t}},[$.GROUP_DATA]:{v1:{fn:ze,inputSchema:Le,outputSchema:Re}},[$.PAGINATED_REQUEST]:{v1:{fn:ut,inputSchema:st,outputSchema:ct}},[$.STATIC_VALUES]:{v1:{fn:St,inputSchema:bt,outputSchema:xt}}},Nt=(e,t)=>async({block:n,params:r})=>{try{e.inputSchema&&e.inputSchema.parse(r)}catch(e){return{block:n,successful:!1,errors:[{message:`Input parameters for ${t} are invalid: ${e?.message}`}]}}let i=await e.fn({block:n,params:r});try{e.outputSchema&&e.outputSchema.parse(i.output)}catch{return{block:n,successful:!1,errors:[{message:`Output data of ${t} has unexpected format`}]}}return i},Pt={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=Mt}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:Nt(i,e)}:i}};export{Y as AUTHENTICATION_SCHEMA,U as COMPOSITE_ID_LATEST_VERSION,W as CoreError,$ as StepFunctionName,Pt as StepFunctionsFactory,Mt as StepFunctionsRegistry,Ne as areCursorsEqual,ve as decodeCompositeId,_e as encodeCompositeId,K as expandCursor,oe as getCategoryDetails,De as isCompositeId,Ie as isCoreError,Pe as isCursorEmpty,se as isValidCategory,Ae as minifyCursor,Fe as updateCursor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.72.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"license": "ISC",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@stackone/expressions": "*",
|
|
45
|
+
"@stackone/olap": "*",
|
|
45
46
|
"@stackone/transport": "*",
|
|
46
47
|
"@stackone/utils": "*"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"tsdown": "
|
|
50
|
+
"tsdown": "0.12.9"
|
|
50
51
|
},
|
|
51
52
|
"tsdown": {
|
|
52
53
|
"dts": true,
|