@stackone/core 2.1.0 → 2.3.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 +182 -5
- package/dist/index.d.ts +182 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -52,6 +52,11 @@ declare const isCompositeId: (value?: string | null) => boolean;
|
|
|
52
52
|
//#region src/compositeIds/constants.d.ts
|
|
53
53
|
declare const COMPOSITE_ID_LATEST_VERSION = 1;
|
|
54
54
|
//#endregion
|
|
55
|
+
//#region src/connector/inputEnumRegistry.d.ts
|
|
56
|
+
declare const INPUT_ENUM_REGISTRY: Record<string, string[]>;
|
|
57
|
+
declare const getInputEnumValues: (ref: string) => string[] | undefined;
|
|
58
|
+
declare const isValidEnumRef: (ref: string) => boolean;
|
|
59
|
+
//#endregion
|
|
55
60
|
//#region ../logger/src/types.d.ts
|
|
56
61
|
interface ILogger {
|
|
57
62
|
debug({
|
|
@@ -294,6 +299,8 @@ declare enum StepFunctionName {
|
|
|
294
299
|
GROUP_DATA = "group_data",
|
|
295
300
|
REQUEST = "request",
|
|
296
301
|
PAGINATED_REQUEST = "paginated_request",
|
|
302
|
+
SOAP_REQUEST = "soap_request",
|
|
303
|
+
SOAP_PAGINATED_REQUEST = "soap_paginated_request",
|
|
297
304
|
STATIC_VALUES = "static_values",
|
|
298
305
|
}
|
|
299
306
|
declare const stepFunctions: {
|
|
@@ -507,6 +514,167 @@ declare const stepFunctions: {
|
|
|
507
514
|
}, zod_v4_core0.$strict>>;
|
|
508
515
|
};
|
|
509
516
|
};
|
|
517
|
+
soap_request: {
|
|
518
|
+
v1: {
|
|
519
|
+
fn: StepFunction;
|
|
520
|
+
inputSchema: zod_v40.ZodObject<{
|
|
521
|
+
baseUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
522
|
+
url: zod_v40.ZodString;
|
|
523
|
+
method: zod_v40.ZodEnum<{
|
|
524
|
+
get: "get";
|
|
525
|
+
post: "post";
|
|
526
|
+
put: "put";
|
|
527
|
+
delete: "delete";
|
|
528
|
+
patch: "patch";
|
|
529
|
+
}>;
|
|
530
|
+
authorization: zod_v40.ZodOptional<zod_v40.ZodDiscriminatedUnion<[zod_v40.ZodObject<{
|
|
531
|
+
type: zod_v40.ZodLiteral<"none">;
|
|
532
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
533
|
+
type: zod_v40.ZodLiteral<"basic">;
|
|
534
|
+
username: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
535
|
+
password: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
536
|
+
encoding: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
537
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
538
|
+
type: zod_v40.ZodLiteral<"bearer">;
|
|
539
|
+
token: zod_v40.ZodString;
|
|
540
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
541
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
542
|
+
type: zod_v40.ZodLiteral<"oauth2">;
|
|
543
|
+
authorizationUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
544
|
+
authorizationParams: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
545
|
+
tokenUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
546
|
+
tokenParams: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
547
|
+
tokenExpiresIn: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
548
|
+
tokenRefreshExpiresIn: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
549
|
+
token: zod_v40.ZodString;
|
|
550
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
551
|
+
scopes: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
552
|
+
scopeDelimiter: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
553
|
+
customHeaders: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
554
|
+
pkce: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
555
|
+
}, zod_v4_core0.$strict>]>>;
|
|
556
|
+
envelope: zod_v40.ZodOptional<zod_v40.ZodUnion<readonly [zod_v40.ZodString, zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodUnknown>]>>;
|
|
557
|
+
namespaces: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
558
|
+
namespaceIdentifier: zod_v40.ZodString;
|
|
559
|
+
namespace: zod_v40.ZodString;
|
|
560
|
+
}, zod_v4_core0.$strict>>>;
|
|
561
|
+
soapOperation: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
562
|
+
soapAction: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
563
|
+
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
564
|
+
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
565
|
+
indexField: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
566
|
+
dataKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
567
|
+
}, zod_v4_core0.$strict>>;
|
|
568
|
+
customErrors: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
569
|
+
receivedStatus: zod_v40.ZodNumber;
|
|
570
|
+
targetStatus: zod_v40.ZodNumber;
|
|
571
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
572
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
573
|
+
}, zod_v4_core0.$strict>>>;
|
|
574
|
+
args: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
575
|
+
name: zod_v40.ZodString;
|
|
576
|
+
value: zod_v40.ZodUnknown;
|
|
577
|
+
in: zod_v40.ZodEnum<{
|
|
578
|
+
query: "query";
|
|
579
|
+
body: "body";
|
|
580
|
+
headers: "headers";
|
|
581
|
+
}>;
|
|
582
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
583
|
+
}, zod_v4_core0.$strict>>>;
|
|
584
|
+
}, zod_v4_core0.$strip>;
|
|
585
|
+
outputSchema: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
586
|
+
data: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
587
|
+
raw: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
588
|
+
statusCode: zod_v40.ZodNumber;
|
|
589
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
590
|
+
}, zod_v4_core0.$strict>>;
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
soap_paginated_request: {
|
|
594
|
+
v1: {
|
|
595
|
+
fn: StepFunction;
|
|
596
|
+
inputSchema: zod_v40.ZodObject<{
|
|
597
|
+
baseUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
598
|
+
url: zod_v40.ZodString;
|
|
599
|
+
method: zod_v40.ZodEnum<{
|
|
600
|
+
get: "get";
|
|
601
|
+
post: "post";
|
|
602
|
+
put: "put";
|
|
603
|
+
delete: "delete";
|
|
604
|
+
patch: "patch";
|
|
605
|
+
}>;
|
|
606
|
+
authorization: zod_v40.ZodOptional<zod_v40.ZodDiscriminatedUnion<[zod_v40.ZodObject<{
|
|
607
|
+
type: zod_v40.ZodLiteral<"none">;
|
|
608
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
609
|
+
type: zod_v40.ZodLiteral<"basic">;
|
|
610
|
+
username: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
611
|
+
password: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
612
|
+
encoding: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
613
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
614
|
+
type: zod_v40.ZodLiteral<"bearer">;
|
|
615
|
+
token: zod_v40.ZodString;
|
|
616
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
617
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
618
|
+
type: zod_v40.ZodLiteral<"oauth2">;
|
|
619
|
+
token: zod_v40.ZodString;
|
|
620
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
621
|
+
}, zod_v4_core0.$strict>]>>;
|
|
622
|
+
envelope: zod_v40.ZodOptional<zod_v40.ZodUnion<readonly [zod_v40.ZodString, zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodUnknown>]>>;
|
|
623
|
+
namespaces: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
624
|
+
namespaceIdentifier: zod_v40.ZodString;
|
|
625
|
+
namespace: zod_v40.ZodString;
|
|
626
|
+
}, zod_v4_core0.$strict>>>;
|
|
627
|
+
soapOperation: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
628
|
+
soapAction: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
629
|
+
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
630
|
+
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
631
|
+
indexField: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
632
|
+
dataKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
633
|
+
nextKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
634
|
+
nextKeyIn: zod_v40.ZodOptional<zod_v40.ZodEnum<{
|
|
635
|
+
data: "data";
|
|
636
|
+
headers: "headers";
|
|
637
|
+
}>>;
|
|
638
|
+
}, zod_v4_core0.$strict>>;
|
|
639
|
+
iterator: zod_v40.ZodObject<{
|
|
640
|
+
key: zod_v40.ZodString;
|
|
641
|
+
in: zod_v40.ZodEnum<{
|
|
642
|
+
query: "query";
|
|
643
|
+
body: "body";
|
|
644
|
+
headers: "headers";
|
|
645
|
+
}>;
|
|
646
|
+
}, zod_v4_core0.$strict>;
|
|
647
|
+
cursor: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
648
|
+
token: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodString>>;
|
|
649
|
+
position: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodNumber>>;
|
|
650
|
+
}, zod_v4_core0.$strict>>;
|
|
651
|
+
customErrors: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
652
|
+
receivedStatus: zod_v40.ZodNumber;
|
|
653
|
+
targetStatus: zod_v40.ZodNumber;
|
|
654
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
655
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
656
|
+
}, zod_v4_core0.$strict>>>;
|
|
657
|
+
args: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
658
|
+
name: zod_v40.ZodString;
|
|
659
|
+
value: zod_v40.ZodUnknown;
|
|
660
|
+
in: zod_v40.ZodEnum<{
|
|
661
|
+
query: "query";
|
|
662
|
+
body: "body";
|
|
663
|
+
headers: "headers";
|
|
664
|
+
}>;
|
|
665
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
666
|
+
}, zod_v4_core0.$strict>>>;
|
|
667
|
+
}, zod_v4_core0.$strip>;
|
|
668
|
+
outputSchema: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
669
|
+
data: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
670
|
+
raw: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
671
|
+
statusCode: zod_v40.ZodNumber;
|
|
672
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
673
|
+
next: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodString>>;
|
|
674
|
+
position: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
675
|
+
}, zod_v4_core0.$strict>>;
|
|
676
|
+
};
|
|
677
|
+
};
|
|
510
678
|
static_values: {
|
|
511
679
|
v1: {
|
|
512
680
|
fn: StepFunction;
|
|
@@ -759,8 +927,9 @@ type Connector = {
|
|
|
759
927
|
version: string;
|
|
760
928
|
key: string;
|
|
761
929
|
assets: Assets;
|
|
762
|
-
|
|
930
|
+
resources?: string;
|
|
763
931
|
description: string;
|
|
932
|
+
details?: string;
|
|
764
933
|
categories?: Category[];
|
|
765
934
|
authentication?: Authentication;
|
|
766
935
|
actions?: {
|
|
@@ -775,24 +944,32 @@ type Assets = {
|
|
|
775
944
|
};
|
|
776
945
|
type ActionType = 'list' | 'get' | 'create' | 'update' | 'delete' | 'custom' | 'refresh_token' | 'test' | 'unknown';
|
|
777
946
|
type InputLocation = 'body' | 'query' | 'path' | 'headers';
|
|
947
|
+
type EnumOneOf = {
|
|
948
|
+
values: string[];
|
|
949
|
+
} | {
|
|
950
|
+
ref: string;
|
|
951
|
+
};
|
|
778
952
|
type Input = {
|
|
779
953
|
name: string;
|
|
780
|
-
type: 'string' | 'number' | 'boolean' | 'datetime_string' | 'object';
|
|
954
|
+
type: 'string' | 'number' | 'boolean' | 'datetime_string' | 'object' | 'enum';
|
|
781
955
|
required: boolean;
|
|
782
956
|
description: string;
|
|
783
957
|
in: InputLocation;
|
|
784
958
|
array?: boolean;
|
|
785
959
|
properties?: Omit<Input, 'in'>[];
|
|
960
|
+
oneOf?: EnumOneOf;
|
|
786
961
|
};
|
|
787
962
|
type Action = {
|
|
788
963
|
id: string;
|
|
789
964
|
categories: Category[];
|
|
790
965
|
label: string;
|
|
791
966
|
description: string;
|
|
967
|
+
details?: string;
|
|
968
|
+
examples?: Record<string, unknown>[];
|
|
792
969
|
schema?: Schema;
|
|
793
970
|
schemaType: 'native' | 'unified';
|
|
794
971
|
endpoint?: string;
|
|
795
|
-
|
|
972
|
+
resources?: string;
|
|
796
973
|
actionType: ActionType;
|
|
797
974
|
tags?: string[];
|
|
798
975
|
releaseStage?: ReleaseStage;
|
|
@@ -952,7 +1129,7 @@ declare const StepFunctionsFactory: {
|
|
|
952
1129
|
}): StepFunctionInstance;
|
|
953
1130
|
};
|
|
954
1131
|
//#endregion
|
|
955
|
-
//#region src/stepFunctions/
|
|
1132
|
+
//#region src/stepFunctions/shared/schemas.d.ts
|
|
956
1133
|
declare const AUTHORIZATION_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
957
1134
|
type: z.ZodLiteral<"none">;
|
|
958
1135
|
}, z.core.$strict>, z.ZodObject<{
|
|
@@ -992,4 +1169,4 @@ type Account = {
|
|
|
992
1169
|
projectSecureId: string;
|
|
993
1170
|
};
|
|
994
1171
|
//#endregion
|
|
995
|
-
export { AUTHORIZATION_SCHEMA, type Account, type Action, type ActionResponse, type ActionType, 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 ReleaseStage, ReleaseStages, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestActionConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
|
1172
|
+
export { AUTHORIZATION_SCHEMA, type Account, type Action, type ActionResponse, type ActionType, 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 EnumOneOf, type FieldConfig, INPUT_ENUM_REGISTRY, type Input, type InputLocation, type ReleaseStage, ReleaseStages, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestActionConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, getInputEnumValues, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, isValidEnumRef, minifyCursor, updateCursor };
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ declare const isCompositeId: (value?: string | null) => boolean;
|
|
|
52
52
|
//#region src/compositeIds/constants.d.ts
|
|
53
53
|
declare const COMPOSITE_ID_LATEST_VERSION = 1;
|
|
54
54
|
//#endregion
|
|
55
|
+
//#region src/connector/inputEnumRegistry.d.ts
|
|
56
|
+
declare const INPUT_ENUM_REGISTRY: Record<string, string[]>;
|
|
57
|
+
declare const getInputEnumValues: (ref: string) => string[] | undefined;
|
|
58
|
+
declare const isValidEnumRef: (ref: string) => boolean;
|
|
59
|
+
//#endregion
|
|
55
60
|
//#region ../logger/src/types.d.ts
|
|
56
61
|
interface ILogger {
|
|
57
62
|
debug({
|
|
@@ -294,6 +299,8 @@ declare enum StepFunctionName {
|
|
|
294
299
|
GROUP_DATA = "group_data",
|
|
295
300
|
REQUEST = "request",
|
|
296
301
|
PAGINATED_REQUEST = "paginated_request",
|
|
302
|
+
SOAP_REQUEST = "soap_request",
|
|
303
|
+
SOAP_PAGINATED_REQUEST = "soap_paginated_request",
|
|
297
304
|
STATIC_VALUES = "static_values",
|
|
298
305
|
}
|
|
299
306
|
declare const stepFunctions: {
|
|
@@ -507,6 +514,167 @@ declare const stepFunctions: {
|
|
|
507
514
|
}, zod_v4_core0.$strict>>;
|
|
508
515
|
};
|
|
509
516
|
};
|
|
517
|
+
soap_request: {
|
|
518
|
+
v1: {
|
|
519
|
+
fn: StepFunction;
|
|
520
|
+
inputSchema: zod_v40.ZodObject<{
|
|
521
|
+
baseUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
522
|
+
url: zod_v40.ZodString;
|
|
523
|
+
method: zod_v40.ZodEnum<{
|
|
524
|
+
get: "get";
|
|
525
|
+
post: "post";
|
|
526
|
+
put: "put";
|
|
527
|
+
delete: "delete";
|
|
528
|
+
patch: "patch";
|
|
529
|
+
}>;
|
|
530
|
+
authorization: zod_v40.ZodOptional<zod_v40.ZodDiscriminatedUnion<[zod_v40.ZodObject<{
|
|
531
|
+
type: zod_v40.ZodLiteral<"none">;
|
|
532
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
533
|
+
type: zod_v40.ZodLiteral<"basic">;
|
|
534
|
+
username: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
535
|
+
password: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
536
|
+
encoding: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
537
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
538
|
+
type: zod_v40.ZodLiteral<"bearer">;
|
|
539
|
+
token: zod_v40.ZodString;
|
|
540
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
541
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
542
|
+
type: zod_v40.ZodLiteral<"oauth2">;
|
|
543
|
+
authorizationUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
544
|
+
authorizationParams: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
545
|
+
tokenUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
546
|
+
tokenParams: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
547
|
+
tokenExpiresIn: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
548
|
+
tokenRefreshExpiresIn: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
549
|
+
token: zod_v40.ZodString;
|
|
550
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
551
|
+
scopes: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
552
|
+
scopeDelimiter: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
553
|
+
customHeaders: zod_v40.ZodOptional<zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodString>>;
|
|
554
|
+
pkce: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
555
|
+
}, zod_v4_core0.$strict>]>>;
|
|
556
|
+
envelope: zod_v40.ZodOptional<zod_v40.ZodUnion<readonly [zod_v40.ZodString, zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodUnknown>]>>;
|
|
557
|
+
namespaces: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
558
|
+
namespaceIdentifier: zod_v40.ZodString;
|
|
559
|
+
namespace: zod_v40.ZodString;
|
|
560
|
+
}, zod_v4_core0.$strict>>>;
|
|
561
|
+
soapOperation: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
562
|
+
soapAction: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
563
|
+
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
564
|
+
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
565
|
+
indexField: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
566
|
+
dataKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
567
|
+
}, zod_v4_core0.$strict>>;
|
|
568
|
+
customErrors: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
569
|
+
receivedStatus: zod_v40.ZodNumber;
|
|
570
|
+
targetStatus: zod_v40.ZodNumber;
|
|
571
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
572
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
573
|
+
}, zod_v4_core0.$strict>>>;
|
|
574
|
+
args: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
575
|
+
name: zod_v40.ZodString;
|
|
576
|
+
value: zod_v40.ZodUnknown;
|
|
577
|
+
in: zod_v40.ZodEnum<{
|
|
578
|
+
query: "query";
|
|
579
|
+
body: "body";
|
|
580
|
+
headers: "headers";
|
|
581
|
+
}>;
|
|
582
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
583
|
+
}, zod_v4_core0.$strict>>>;
|
|
584
|
+
}, zod_v4_core0.$strip>;
|
|
585
|
+
outputSchema: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
586
|
+
data: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
587
|
+
raw: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
588
|
+
statusCode: zod_v40.ZodNumber;
|
|
589
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
590
|
+
}, zod_v4_core0.$strict>>;
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
soap_paginated_request: {
|
|
594
|
+
v1: {
|
|
595
|
+
fn: StepFunction;
|
|
596
|
+
inputSchema: zod_v40.ZodObject<{
|
|
597
|
+
baseUrl: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
598
|
+
url: zod_v40.ZodString;
|
|
599
|
+
method: zod_v40.ZodEnum<{
|
|
600
|
+
get: "get";
|
|
601
|
+
post: "post";
|
|
602
|
+
put: "put";
|
|
603
|
+
delete: "delete";
|
|
604
|
+
patch: "patch";
|
|
605
|
+
}>;
|
|
606
|
+
authorization: zod_v40.ZodOptional<zod_v40.ZodDiscriminatedUnion<[zod_v40.ZodObject<{
|
|
607
|
+
type: zod_v40.ZodLiteral<"none">;
|
|
608
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
609
|
+
type: zod_v40.ZodLiteral<"basic">;
|
|
610
|
+
username: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
611
|
+
password: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
612
|
+
encoding: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
613
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
614
|
+
type: zod_v40.ZodLiteral<"bearer">;
|
|
615
|
+
token: zod_v40.ZodString;
|
|
616
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
617
|
+
}, zod_v4_core0.$strict>, zod_v40.ZodObject<{
|
|
618
|
+
type: zod_v40.ZodLiteral<"oauth2">;
|
|
619
|
+
token: zod_v40.ZodString;
|
|
620
|
+
includeBearer: zod_v40.ZodDefault<zod_v40.ZodOptional<zod_v40.ZodBoolean>>;
|
|
621
|
+
}, zod_v4_core0.$strict>]>>;
|
|
622
|
+
envelope: zod_v40.ZodOptional<zod_v40.ZodUnion<readonly [zod_v40.ZodString, zod_v40.ZodRecord<zod_v40.ZodString, zod_v40.ZodUnknown>]>>;
|
|
623
|
+
namespaces: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
624
|
+
namespaceIdentifier: zod_v40.ZodString;
|
|
625
|
+
namespace: zod_v40.ZodString;
|
|
626
|
+
}, zod_v4_core0.$strict>>>;
|
|
627
|
+
soapOperation: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
628
|
+
soapAction: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
629
|
+
response: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
630
|
+
collection: zod_v40.ZodOptional<zod_v40.ZodBoolean>;
|
|
631
|
+
indexField: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
632
|
+
dataKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
633
|
+
nextKey: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
634
|
+
nextKeyIn: zod_v40.ZodOptional<zod_v40.ZodEnum<{
|
|
635
|
+
data: "data";
|
|
636
|
+
headers: "headers";
|
|
637
|
+
}>>;
|
|
638
|
+
}, zod_v4_core0.$strict>>;
|
|
639
|
+
iterator: zod_v40.ZodObject<{
|
|
640
|
+
key: zod_v40.ZodString;
|
|
641
|
+
in: zod_v40.ZodEnum<{
|
|
642
|
+
query: "query";
|
|
643
|
+
body: "body";
|
|
644
|
+
headers: "headers";
|
|
645
|
+
}>;
|
|
646
|
+
}, zod_v4_core0.$strict>;
|
|
647
|
+
cursor: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
648
|
+
token: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodString>>;
|
|
649
|
+
position: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodNumber>>;
|
|
650
|
+
}, zod_v4_core0.$strict>>;
|
|
651
|
+
customErrors: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
652
|
+
receivedStatus: zod_v40.ZodNumber;
|
|
653
|
+
targetStatus: zod_v40.ZodNumber;
|
|
654
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
655
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
656
|
+
}, zod_v4_core0.$strict>>>;
|
|
657
|
+
args: zod_v40.ZodOptional<zod_v40.ZodArray<zod_v40.ZodObject<{
|
|
658
|
+
name: zod_v40.ZodString;
|
|
659
|
+
value: zod_v40.ZodUnknown;
|
|
660
|
+
in: zod_v40.ZodEnum<{
|
|
661
|
+
query: "query";
|
|
662
|
+
body: "body";
|
|
663
|
+
headers: "headers";
|
|
664
|
+
}>;
|
|
665
|
+
condition: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
666
|
+
}, zod_v4_core0.$strict>>>;
|
|
667
|
+
}, zod_v4_core0.$strip>;
|
|
668
|
+
outputSchema: zod_v40.ZodOptional<zod_v40.ZodObject<{
|
|
669
|
+
data: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
670
|
+
raw: zod_v40.ZodOptional<zod_v40.ZodUnknown>;
|
|
671
|
+
statusCode: zod_v40.ZodNumber;
|
|
672
|
+
message: zod_v40.ZodOptional<zod_v40.ZodString>;
|
|
673
|
+
next: zod_v40.ZodNullable<zod_v40.ZodOptional<zod_v40.ZodString>>;
|
|
674
|
+
position: zod_v40.ZodOptional<zod_v40.ZodNumber>;
|
|
675
|
+
}, zod_v4_core0.$strict>>;
|
|
676
|
+
};
|
|
677
|
+
};
|
|
510
678
|
static_values: {
|
|
511
679
|
v1: {
|
|
512
680
|
fn: StepFunction;
|
|
@@ -759,8 +927,9 @@ type Connector = {
|
|
|
759
927
|
version: string;
|
|
760
928
|
key: string;
|
|
761
929
|
assets: Assets;
|
|
762
|
-
|
|
930
|
+
resources?: string;
|
|
763
931
|
description: string;
|
|
932
|
+
details?: string;
|
|
764
933
|
categories?: Category[];
|
|
765
934
|
authentication?: Authentication;
|
|
766
935
|
actions?: {
|
|
@@ -775,24 +944,32 @@ type Assets = {
|
|
|
775
944
|
};
|
|
776
945
|
type ActionType = 'list' | 'get' | 'create' | 'update' | 'delete' | 'custom' | 'refresh_token' | 'test' | 'unknown';
|
|
777
946
|
type InputLocation = 'body' | 'query' | 'path' | 'headers';
|
|
947
|
+
type EnumOneOf = {
|
|
948
|
+
values: string[];
|
|
949
|
+
} | {
|
|
950
|
+
ref: string;
|
|
951
|
+
};
|
|
778
952
|
type Input = {
|
|
779
953
|
name: string;
|
|
780
|
-
type: 'string' | 'number' | 'boolean' | 'datetime_string' | 'object';
|
|
954
|
+
type: 'string' | 'number' | 'boolean' | 'datetime_string' | 'object' | 'enum';
|
|
781
955
|
required: boolean;
|
|
782
956
|
description: string;
|
|
783
957
|
in: InputLocation;
|
|
784
958
|
array?: boolean;
|
|
785
959
|
properties?: Omit<Input, 'in'>[];
|
|
960
|
+
oneOf?: EnumOneOf;
|
|
786
961
|
};
|
|
787
962
|
type Action = {
|
|
788
963
|
id: string;
|
|
789
964
|
categories: Category[];
|
|
790
965
|
label: string;
|
|
791
966
|
description: string;
|
|
967
|
+
details?: string;
|
|
968
|
+
examples?: Record<string, unknown>[];
|
|
792
969
|
schema?: Schema;
|
|
793
970
|
schemaType: 'native' | 'unified';
|
|
794
971
|
endpoint?: string;
|
|
795
|
-
|
|
972
|
+
resources?: string;
|
|
796
973
|
actionType: ActionType;
|
|
797
974
|
tags?: string[];
|
|
798
975
|
releaseStage?: ReleaseStage;
|
|
@@ -952,7 +1129,7 @@ declare const StepFunctionsFactory: {
|
|
|
952
1129
|
}): StepFunctionInstance;
|
|
953
1130
|
};
|
|
954
1131
|
//#endregion
|
|
955
|
-
//#region src/stepFunctions/
|
|
1132
|
+
//#region src/stepFunctions/shared/schemas.d.ts
|
|
956
1133
|
declare const AUTHORIZATION_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
957
1134
|
type: z.ZodLiteral<"none">;
|
|
958
1135
|
}, z.core.$strict>, z.ZodObject<{
|
|
@@ -992,4 +1169,4 @@ type Account = {
|
|
|
992
1169
|
projectSecureId: string;
|
|
993
1170
|
};
|
|
994
1171
|
//#endregion
|
|
995
|
-
export { AUTHORIZATION_SCHEMA, type Account, type Action, type ActionResponse, type ActionType, 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 ReleaseStage, ReleaseStages, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestActionConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, minifyCursor, updateCursor };
|
|
1172
|
+
export { AUTHORIZATION_SCHEMA, type Account, type Action, type ActionResponse, type ActionType, 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 EnumOneOf, type FieldConfig, INPUT_ENUM_REGISTRY, type Input, type InputLocation, type ReleaseStage, ReleaseStages, type Schema, type SchemaField, type Settings, type Step, type StepFunction, StepFunctionName, type StepFunctionOutput, type StepFunctionParams, StepFunctionsFactory, stepFunctions as StepFunctionsRegistry, type StepsSnapshots, type SupportConfig, type TestActionConfig, areCursorsEqual, decodeCompositeId, encodeCompositeId, expandCursor, getCategoryDetails, getInputEnumValues, isCompositeId, isCoreError, isCursorEmpty, isValidCategory, isValidEnumRef, 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 actions`},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=[`preview`,`beta`,`ga`,`deprecated`],re=(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()}),ie=(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()}),ae=e=>(0,c.encodeToBase64)(JSON.stringify(oe(e))),oe=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=re.parse(n);return se(r)}else return ie.parse(e),e}catch{return null}},se=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},ce=(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)},le=({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),ue=({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}}},de=e=>e instanceof x,z=c.z.object({stepsDataToGroup:c.z.array(c.z.string()),isSingleRecord:c.z.boolean().optional()}),fe=c.z.object({data:c.z.unknown()}),pe=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)}}},me=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=he(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}},he=(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}=ge(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}},ge=(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}},_e=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()}),ve=c.z.object({data:c.z.unknown()}),ye=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}},be=(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)},xe=(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}},Se=(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},Ce=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?be(e,t,n):e.array&&e.expression?xe(e,t,n):Se(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=Ce(a,t,r),e===void 0)continue}else{let{error:n,value:i}=we(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},we=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return G(n,t,e);case`enum`:return Te(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}},Te=(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=_e(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}}},Ee=[`data`,`headers`],De=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Oe=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),ke=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Ae=(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()}),je=c.z.discriminatedUnion(`type`,[De,Oe,ke,Ae]),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(),nextKeyIn:c.z.enum(Ee).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()}),Me=(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(),Ne=25,Pe=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)?Ne: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=je.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=Fe({result:t,response:h}),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=Re(j,h);return{block:e,successful:!0,output:{data:ee,raw:N,statusCode:A,next:L?void 0:k,position:L?void 0:F}}},Fe=({result:e,response:t})=>{if((0,c.isMissing)(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?Ie(e.headers,r):Le(e.data,r)},Ie=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},Le=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`||!e)return null;let n=e[t];return(0,c.isMissing)(n)?null:typeof n==`string`||typeof n==`number`?n:null},Re=(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},ze=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Be=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),Ve=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),He=(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`,[ze,Be,Ve,He]),Ue=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()}),We=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional()}).optional(),Ge=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}=Ue.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=Ke(E,p);return{block:e,successful:!0,output:{data:D,raw:T,statusCode:T?.status,message:T?.message}}},Ke=(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},qe=c.z.object({values:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).or(c.z.array(c.z.unknown()))}),Je=c.z.object({data:c.z.unknown()}),Ye=async({block:e,params:t})=>{let{values:n}=qe.parse(t),r=Array.isArray(n)?n.map(t=>J(t,e)):J(n,e);return{block:{...e},successful:!0,output:{data:r}}},J=(e,t)=>(0,c.isString)(e)?(0,l.safeEvaluate)(e,t):(0,c.isObject)(e)?(0,l.safeEvaluateRecord)(e,t):e,Xe=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(()=>Xe).array().optional()}),Ze=c.z.object({fields:Xe.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}},$e=e=>{let t=Object.values(Y);return t.includes(e)},et=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=>tt(e,t)):tt(e.result,t),{block:{...e,result:n},successful:!0}},tt=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;$e(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}},nt=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Ze.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}}},rt=(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]=rt(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=rt(t,e.unified_custom_fields?.[r])):$e(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:et},v2:{fn:nt,inputSchema:Ze,outputSchema:Qe}},[Q.MAP_FIELDS]:{v1:{fn:me},v2:{fn:ye,inputSchema:H,outputSchema:ve}},[Q.REQUEST]:{v1:{fn:Ge,inputSchema:Ue,outputSchema:We}},[Q.GROUP_DATA]:{v1:{fn:pe,inputSchema:z,outputSchema:fe}},[Q.PAGINATED_REQUEST]:{v1:{fn:Pe,inputSchema:K,outputSchema:Me}},[Q.STATIC_VALUES]:{v1:{fn:Ye,inputSchema:qe,outputSchema:Je}}},it=(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},at={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:it(i,e)}:i}};exports.AUTHORIZATION_SCHEMA=q,exports.COMPOSITE_ID_LATEST_VERSION=b,exports.CoreError=x,exports.ReleaseStages=ne,exports.StepFunctionName=Q,exports.StepFunctionsFactory=at,exports.StepFunctionsRegistry=$,exports.areCursorsEqual=ce,exports.decodeCompositeId=A,exports.encodeCompositeId=k,exports.expandCursor=R,exports.getCategoryDetails=f,exports.isCompositeId=te,exports.isCoreError=de,exports.isCursorEmpty=le,exports.isValidCategory=p,exports.minifyCursor=ae,exports.updateCursor=ue;
|
|
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 actions`},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]=R(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),R=e=>[_,g].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),z=e=>(0,c.isMissing)(e)?!1:e.startsWith(h),B={employment_status:[`active`,`inactive`,`terminated`,`pending`,`leave`],employment_type:[`full_time`,`part_time`,`contractor`,`intern`,`temporary`],gender:[`male`,`female`,`non_binary`,`other`,`prefer_not_to_say`],marital_status:[`single`,`married`,`divorced`,`widowed`,`domestic_partnership`]},V=e=>B[e],H=e=>e in B,ee=[`preview`,`beta`,`ga`,`deprecated`],te=(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()}),ne=(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()}),re=e=>(0,c.encodeToBase64)(JSON.stringify(ie(e))),ie=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},U=e=>{try{if((0,c.isString)(e)){let t=(0,c.decodeFromBase64)(e),n=JSON.parse(t),r=te.parse(n);return ae(r)}else return ne.parse(e),e}catch{return null}},ae=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},oe=(e,t)=>{let n=typeof e==`string`?U(e):e,r=typeof t==`string`?U(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)},se=({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),ce=({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}}},le=e=>e instanceof x,W=c.z.object({stepsDataToGroup:c.z.array(c.z.string()),isSingleRecord:c.z.boolean().optional()}),ue=c.z.object({data:c.z.unknown()}),de=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=W.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)}}},fe=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=pe(r,a,i),s=me(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=me(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}},pe=(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},{}),me=(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}},_e=(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(()=>_e).array().optional()}),ve=c.z.object({fields:_e.array(),dataSource:c.z.string(),externalSources:c.z.record(c.z.string(),c.z.string()).optional()}),ye=c.z.object({data:c.z.unknown()}),be=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=ve.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=G(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=G(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}},xe=(e,t,n)=>{if(Array.isArray(e.values))return e.values.map(r=>{let i=K(r,t),a=G(e.properties,i);return(0,c.notMissing)(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},Se=(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=G(e.properties,t);return(0,c.notMissing)(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=G(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}},Ce=(e,t,n)=>{let r=(0,c.notMissing)(e.values)?e.values:t,i=G(e.properties,r);return(0,c.notMissing)(i?.errors)&&n.push(...i.errors),i?.record},we=(e,t,n)=>{if(!(0,c.isMissing)(e.properties))return e.array&&Array.isArray(e.values)?xe(e,t,n):e.array&&e.expression?Se(e,t,n):Ce(e,t,n)},G=(e,t)=>{if(!t)return;let n={},r=[],i={};for(let a of e){let e;if(a.type===`object`){if(e=we(a,t,r),e===void 0)continue}else{let{error:n,value:i}=Te(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}},K=(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=>K(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=K(r,t);return n}return e},Te=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return Ee(n,t,e);case`enum`:return De(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},Ee=(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}},De=(e,t,n)=>{let r=Ee(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}}},Oe=[`data`,`headers`],ke=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Ae=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),je=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Me=(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()}),Ne=c.z.discriminatedUnion(`type`,[ke,Ae,je,Me]),Pe=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(),nextKeyIn:c.z.enum(Oe).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()}),Fe=(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(),Ie=25,Le=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)?Ie: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}=Pe.parse(d),b=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,x=Ne.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=Re({result:t,response:h}),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 R=Ve(j,h);return{block:e,successful:!0,output:{data:R,raw:N,statusCode:A,next:L?void 0:k,position:L?void 0:F}}},Re=({result:e,response:t})=>{if((0,c.isMissing)(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?ze(e.headers,r):Be(e.data,r)},ze=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},Be=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`||!e)return null;let n=e[t];return(0,c.isMissing)(n)?null:typeof n==`string`||typeof n==`number`?n:null},Ve=(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},He=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Ue=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),We=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),Ge=(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`,[He,Ue,We,Ge]),qe=c.z.object({baseUrl:c.z.string().optional(),url:c.z.string(),method:c.z.enum(u.HttpMethods),authorization:Ke.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()}),Je=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional()}).optional(),Ye=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}=qe.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:Ke.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=Xe(E,p);return{block:e,successful:!0,output:{data:D,raw:T,statusCode:T?.status,message:T?.message}}},Xe=(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},Ze=(0,c.zStrictObject)({type:c.z.literal(`none`)}),Qe=(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),$e=(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),et=(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`,[Ze,Qe,$e,et]),tt=[`data`,`headers`],nt=c.z.object({baseUrl:c.z.string().optional(),url:c.z.string(),method:c.z.enum(u.HttpMethods),authorization:c.z.discriminatedUnion(`type`,[(0,c.zStrictObject)({type:c.z.literal(`none`)}),(0,c.zStrictObject)({type:c.z.literal(`basic`),username:c.z.string().optional(),password:c.z.string().optional(),encoding:c.z.string().optional()}),(0,c.zStrictObject)({type:c.z.literal(`bearer`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)}),(0,c.zStrictObject)({type:c.z.literal(`oauth2`),token:c.z.string(),includeBearer:c.z.boolean().optional().default(!0)})]).optional(),envelope:c.z.union([c.z.string(),c.z.record(c.z.string(),c.z.unknown())]).optional(),namespaces:c.z.strictObject({namespaceIdentifier:c.z.string(),namespace:c.z.string()}).array().optional(),soapOperation:c.z.string().optional(),soapAction:c.z.string().optional(),response:(0,c.zStrictObject)({collection:c.z.boolean().optional(),indexField:c.z.string().optional(),dataKey:c.z.string().optional(),nextKey:c.z.string().optional(),nextKeyIn:c.z.enum(tt).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()}),rt=(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(),it=25,at=async({block:e,params:t})=>{let n=u.RequestClientFactory.build(`soap`);if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?it: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:_,authorization:v,customErrors:y,args:b,soapOperation:x,namespaces:S,envelope:C,soapAction:w}=nt.parse(d),T=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,E=b?(0,u.parseRequestParameters)(b):{query:{},body:{},headers:{}},D=(0,c.notMissing)(v)?v:q.parse(T),O=(0,u.createAuthorizationHeaders)(D),k={...E?.headers??{},...O},A=e.connector?.rateLimit,j=e.connector?.concurrency,M={...(A!==void 0||j!==void 0)&&{rateLimit:A,concurrency:j},soapOperation:x,namespaces:S,envelope:C,soapAction:w,soapContext:{username:e.credentials?.username,password:e.credentials?.password}},N=_?.token??null,P=null,F=null,I=[],L=[],R=[],z=a,B=_?.position??0,V=!0,H;do{V?V=!1:B=0,N!==null&&(g.in===`query`?E.query[g.key]=N.toString():g.in===`body`&&(E.body[g.key]=N));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${f}${p}`,queryParams:E?.query,method:m,headers:k,body:E?.body,customErrorConfigs:y,requestConfig:M})}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}}}P=N,L=h?.dataKey?t.data[h?.dataKey]:t.data,Array.isArray(L)||(L=L?[L]:[]);let r=L?.slice(B,B+z);z-=r.length,B+=r.length,R.push(t),I=I.concat(r),F=t?.status,N=ot({result:t,response:h}),r.length===L.length&&z===0&&(B=0,P=N),H=(0,c.isMissing)(N)&&I.length<a}while((0,c.notMissing)(N)&&I.length<a&&L?.length>0);let ee=lt(I,h);return{block:e,successful:!0,output:{data:ee,raw:R,statusCode:F,next:H?void 0:P,position:H?void 0:B}}},ot=({result:e,response:t})=>{if((0,c.isMissing)(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?st(e.headers,r):ct(e.data,r)},st=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},ct=(e,t)=>{if((0,c.isMissing)(e)||typeof e!=`object`||!e)return null;let n=e[t];return(0,c.isMissing)(n)?null:typeof n==`string`||typeof n==`number`?n:null},lt=(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},J=c.z.object({baseUrl:c.z.string().optional(),url:c.z.string(),method:c.z.enum(u.HttpMethods),authorization:q.optional(),envelope:c.z.union([c.z.string(),c.z.record(c.z.string(),c.z.unknown())]).optional(),namespaces:c.z.strictObject({namespaceIdentifier:c.z.string(),namespace:c.z.string()}).array().optional(),soapOperation:c.z.string().optional(),soapAction:c.z.string().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()}),ut=(0,c.zStrictObject)({data:c.z.unknown().optional(),raw:c.z.unknown().optional(),statusCode:c.z.number(),message:c.z.string().optional()}).optional(),dt=async({block:e,params:t})=>{let n=u.RequestClientFactory.build(`soap`);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,soapOperation:_,namespaces:v,envelope:y,soapAction:b}=J.parse(o),x=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,S=g?(0,u.parseRequestParameters)(g):{query:{},body:{},headers:{}},C=(0,c.notMissing)(m)?m:q.parse(x),w=(0,u.createAuthorizationHeaders)(C),T={...S?.headers??{},...w},E=e.connector?.rateLimit,D=e.connector?.concurrency,O={...(E!==void 0||D!==void 0)&&{rateLimit:E,concurrency:D},soapOperation:_,namespaces:v,envelope:y,soapAction:b,soapContext:{username:e.credentials?.username,password:e.credentials?.password}},k;try{k=await n.performRequest({httpClient:e.httpClient,url:`${s}${d}`,queryParams:S?.query,method:f,headers:T,body:S?.body,customErrorConfigs:h,requestConfig:O})}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 A=p?.dataKey?k.data[p?.dataKey]:k.data,j=ft(A,p);return{block:e,successful:!0,output:{data:j,raw:k,statusCode:k?.status,message:k?.message}}},ft=(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},pt=c.z.object({values:c.z.string().or(c.z.record(c.z.string(),c.z.unknown())).or(c.z.array(c.z.unknown()))}),mt=c.z.object({data:c.z.unknown()}),ht=async({block:e,params:t})=>{let{values:n}=pt.parse(t),r=Array.isArray(n)?n.map(t=>gt(t,e)):gt(n,e);return{block:{...e},successful:!0,output:{data:r}}},gt=(e,t)=>(0,c.isString)(e)?(0,l.safeEvaluate)(e,t):(0,c.isObject)(e)?(0,l.safeEvaluateRecord)(e,t):e,_t=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(()=>_t).array().optional()}),vt=c.z.object({fields:_t.array().optional(),dataSource:c.z.string()}),yt=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}},bt=e=>{let t=Object.values(Y);return t.includes(e)},xt=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=>St(e,t)):St(e.result,t),{block:{...e,result:n},successful:!0}},St=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;bt(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}},Ct=async({block:e,params:t})=>{let{fields:n,dataSource:r}=vt.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}}},wt=(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]=wt(t,e[r]):n.unified_custom_fields&&(0,c.notMissing)(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=wt(t,e.unified_custom_fields?.[r])):bt(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.SOAP_REQUEST=`soap_request`,e.SOAP_PAGINATED_REQUEST=`soap_paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const $={[Q.TYPECAST]:{v1:{fn:xt},v2:{fn:Ct,inputSchema:vt,outputSchema:yt}},[Q.MAP_FIELDS]:{v1:{fn:fe},v2:{fn:be,inputSchema:ve,outputSchema:ye}},[Q.REQUEST]:{v1:{fn:Ye,inputSchema:qe,outputSchema:Je}},[Q.GROUP_DATA]:{v1:{fn:de,inputSchema:W,outputSchema:ue}},[Q.PAGINATED_REQUEST]:{v1:{fn:Le,inputSchema:Pe,outputSchema:Fe}},[Q.SOAP_REQUEST]:{v1:{fn:dt,inputSchema:J,outputSchema:ut}},[Q.SOAP_PAGINATED_REQUEST]:{v1:{fn:at,inputSchema:nt,outputSchema:rt}},[Q.STATIC_VALUES]:{v1:{fn:ht,inputSchema:pt,outputSchema:mt}}},Tt=(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:Tt(i,e)}:i}};exports.AUTHORIZATION_SCHEMA=q,exports.COMPOSITE_ID_LATEST_VERSION=b,exports.CoreError=x,exports.INPUT_ENUM_REGISTRY=B,exports.ReleaseStages=ee,exports.StepFunctionName=Q,exports.StepFunctionsFactory=Et,exports.StepFunctionsRegistry=$,exports.areCursorsEqual=oe,exports.decodeCompositeId=A,exports.encodeCompositeId=k,exports.expandCursor=U,exports.getCategoryDetails=f,exports.getInputEnumValues=V,exports.isCompositeId=z,exports.isCoreError=le,exports.isCursorEmpty=se,exports.isValidCategory=p,exports.isValidEnumRef=H,exports.minifyCursor=re,exports.updateCursor=ce;
|
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 actions`},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=[`preview`,`beta`,`ga`,`deprecated`],ke=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()}),Ae=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()}),je=e=>t(JSON.stringify(Me(e))),Me=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=ke.parse(r);return Ne(i)}else return Ae.parse(t),t}catch{return null}},Ne=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},Pe=(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)},Fe=({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),Ie=({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}}},Le=e=>e instanceof W,Re=j.object({stepsDataToGroup:j.array(j.string()),isSingleRecord:j.boolean().optional()}),ze=j.object({data:j.unknown()}),Be=async({block:e,params:t})=>{let{stepsDataToGroup:n,isSingleRecord:r}=Re.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)}}},Ve=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=He(r,a,i),s=Ue(e,t,o);return n.push(...s.errors||[]),s.record})}else{let a=Ue(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}},He=(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},{}),Ue=(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}=We(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}},We=(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}},Ge=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}},Ke=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(()=>Ke).array().optional()}),qe=j.object({fields:Ke.array(),dataSource:j.string(),externalSources:j.record(j.string(),j.string()).optional()}),Je=j.object({data:j.unknown()}),Ye=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=qe.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}},Xe=(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)},Ze=(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}},Qe=(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},$e=(e,t,n)=>{if(!w(e.properties))return e.array&&Array.isArray(e.values)?Xe(e,t,n):e.array&&e.expression?Ze(e,t,n):Qe(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=$e(a,t,r),e===void 0)continue}else{let{error:n,value:i}=et(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},et=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return tt(n,t,e);case`enum`:return nt(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},tt=(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}},nt=(e,t,n)=>{let r=tt(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=Ge(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}}},rt=[`data`,`headers`],it=M({type:j.literal(`none`)}),at=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),ot=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),st=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()}),ct=j.discriminatedUnion(`type`,[it,at,ot,st]),lt=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(),nextKeyIn:j.enum(rt).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()}),ut=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(),dt=25,ft=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)?dt: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}=lt.parse(c),_=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=ct.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=pt({result:t,response:f}),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=gt(k,f);return{block:e,successful:!0,output:{data:R,raw:j,statusCode:O,next:L?void 0:D,position:L?void 0:P}}},pt=({result:e,response:t})=>{if(w(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?mt(e.headers,r):ht(e.data,r)},mt=(e,t)=>{if(w(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},ht=(e,t)=>{if(w(e)||typeof e!=`object`||!e)return null;let n=e[t];return w(n)?null:typeof n==`string`||typeof n==`number`?n:null},gt=(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},_t=M({type:j.literal(`none`)}),vt=M({type:j.literal(`basic`),username:j.string().optional(),password:j.string().optional(),encoding:j.string().optional()}),yt=M({type:j.literal(`bearer`),token:j.string(),includeBearer:j.boolean().optional().default(!0)}),bt=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`,[_t,vt,yt,bt]),xt=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()}),St=M({data:j.unknown().optional(),raw:j.unknown().optional(),statusCode:j.number(),message:j.string().optional()}).optional(),Ct=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}=xt.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=wt(C,u);return{block:e,successful:!0,output:{data:w,raw:S,statusCode:S?.status,message:S?.message}}},wt=(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},Tt=j.object({values:j.string().or(j.record(j.string(),j.unknown())).or(j.array(j.unknown()))}),Et=j.object({data:j.unknown()}),Dt=async({block:e,params:t})=>{let{values:n}=Tt.parse(t),r=Array.isArray(n)?n.map(t=>Ot(t,e)):Ot(n,e);return{block:{...e},successful:!0,output:{data:r}}},Ot=(e,t)=>T(e)?F(e,t):ee(e)?I(e,t):e,kt=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(()=>kt).array().optional()}),At=j.object({fields:kt.array().optional(),dataSource:j.string()}),jt=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}},Mt=e=>{let t=Object.values(X);return t.includes(e)},Nt=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=>Pt(e,t)):Pt(e.result,t),{block:{...e,result:n},successful:!0}},Pt=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Mt(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}},Ft=async({block:e,params:t})=>{let{fields:n,dataSource:r}=At.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}}},It=(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]=It(t,e[r]):n.unified_custom_fields&&E(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=It(t,e.unified_custom_fields?.[r])):Mt(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 Lt={[$.TYPECAST]:{v1:{fn:Nt},v2:{fn:Ft,inputSchema:At,outputSchema:jt}},[$.MAP_FIELDS]:{v1:{fn:Ve},v2:{fn:Ye,inputSchema:qe,outputSchema:Je}},[$.REQUEST]:{v1:{fn:Ct,inputSchema:xt,outputSchema:St}},[$.GROUP_DATA]:{v1:{fn:Be,inputSchema:Re,outputSchema:ze}},[$.PAGINATED_REQUEST]:{v1:{fn:ft,inputSchema:lt,outputSchema:ut}},[$.STATIC_VALUES]:{v1:{fn:Dt,inputSchema:Tt,outputSchema:Et}}},Rt=(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},zt={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=Lt}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:Rt(i,e)}:i}};export{Y as AUTHORIZATION_SCHEMA,U as COMPOSITE_ID_LATEST_VERSION,W as CoreError,Oe as ReleaseStages,$ as StepFunctionName,zt as StepFunctionsFactory,Lt as StepFunctionsRegistry,Pe as areCursorsEqual,ve as decodeCompositeId,_e as encodeCompositeId,K as expandCursor,oe as getCategoryDetails,De as isCompositeId,Le as isCoreError,Fe as isCursorEmpty,se as isValidCategory,je as minifyCursor,Ie 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 T,isString as E,notMissing as D,safeParseToBoolean as O,safeParseToDateTimeString as k,safeParseToNumber as A,safeParseToString as j,z as M,zStrictObject as N}from"@stackone/utils";import{evaluate as P,isValidExpression as F,safeEvaluate as I,safeEvaluateRecord as L}from"@stackone/expressions";import{CUSTOM_ERROR_CONFIG_SCHEMA as R,HttpMethods as z,RequestClientFactory as B,RequestParameterLocations as V,createAuthorizationHeaders as H,parseRequestParameters as U,serializeHttpResponseError as W}from"@stackone/transport";const G={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 actions`},action:{title:`Action`,key:`action`,description:`Action`}},ee=e=>{let t=G[e.toLowerCase()];return t??null},K=e=>!!G[e.toLowerCase()],te=`so1!`,q=t(te),J=`:`,Y=`,`,ne=RegExp(`(?<!\\\\)${J}`,`g`),re=RegExp(`(?<!\\\\)${Y}`,`g`),ie=1;var ae=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}`}},X=class extends ae{constructor(e,t,n){super({category:`CompositeId`,name:t??`BaseCompositeIdError`,type:e,message:n})}},oe=class extends X{constructor(e){super(`COMPOSITE_ID_MISSING_HEADER_ERROR`,`CompositeIdMissingHeaderError`,e??`Invalid compositeId, missing header`)}},se=class extends X{constructor(e){super(`COMPOSITE_ID_MISSING_BODY_ERROR`,`CompositeIdMissingBodyError`,e??`Invalid compositeId, missing body`)}},ce=class extends X{constructor(e){super(`COMPOSITE_ID_UNKNOWN_IDENTIFIER_ERROR`,`CompositeIdUnknownIdentifierError`,e??`Invalid compositeId, unknown identifier`)}},le=class extends X{constructor(e){super(`COMPOSITE_ID_UNSUPPORTED_VERSION_ERROR`,`CompositeIdUnsupportedVersionError`,e??`Invalid compositeId, unsupported version`)}};const ue=e=>!w(e)&&`value`in e&&e.value!==void 0,de=e=>!w(e)&&`identifiers`in e&&e.identifiers!==void 0,fe=(e,t={version:ie})=>{if(t.version===1)return ve(me(e,t.aliases));throw new le(`Cannot generate ID, unsupported version number: ${t.version}`)},pe=(e,t={version:ie})=>{let n=_e(e,t),r={};return n&&n.split(re).forEach(e=>{let[n,i]=e.split(ne),a=ge(n,t.aliases??{});r[a]=xe(i)}),r},me=(e,t={})=>{if(ue(e))return he({identifier:e,compositeIdAliases:t,isSoleIdentifier:!0});if(de(e))return e.identifiers.map(e=>he({identifier:e,compositeIdAliases:t,isSoleIdentifier:!1})).join(Y);throw new ce},he=({identifier:e,compositeIdAliases:t,isSoleIdentifier:n})=>{let r=n?`id`:t[e.key]||e.key;return[r,be(e.value)].filter(Boolean).join(J)},ge=(e,t)=>Object.keys(t).find(n=>t[n]===e)??e,_e=(e,t)=>{if(t.version===1)return ye(e);throw new le(`Cannot decode ID, unsupported version number: ${t.version}`)},ve=e=>`${q}${t(e)}`,ye=t=>{if(!t.startsWith(q))throw new oe(`Trying to decode an ID without the header: ${t}`);let n=t.split(q)[1];if(!n)throw new se(`Trying to decode an ID without a body: ${t}`);return e(n)},be=e=>[Y,J].reduce((e,t)=>e.replace(t,`\\`+t),e),xe=e=>[Y,J].reduce((e,t)=>{let n=`\\`+t;return e.replace(RegExp(`\\\\`+n,`g`),t)},e),Se=e=>w(e)?!1:e.startsWith(q),Ce={employment_status:[`active`,`inactive`,`terminated`,`pending`,`leave`],employment_type:[`full_time`,`part_time`,`contractor`,`intern`,`temporary`],gender:[`male`,`female`,`non_binary`,`other`,`prefer_not_to_say`],marital_status:[`single`,`married`,`divorced`,`widowed`,`domestic_partnership`]},we=e=>Ce[e],Te=e=>e in Ce,Ee=[`preview`,`beta`,`ga`,`deprecated`],De=N({r:M.record(M.string(),N({n:M.number().optional().nullable(),c:M.string().optional().nullable(),p:M.number().optional().nullable()})),v:M.number(),t:M.number()}),Oe=N({remote:M.record(M.string(),N({pageNumber:M.number().optional(),providerPageCursor:M.string().optional(),position:M.number().optional()})),version:M.number(),timestamp:M.number()}),ke=e=>t(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},je=t=>{try{if(E(t)){let n=e(t),r=JSON.parse(n),i=De.parse(r);return Me(i)}else return Oe.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`?je(e):e,i=typeof t==`string`?je(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 ae,Le=M.object({stepsDataToGroup:M.array(M.string()),isSingleRecord:M.boolean().optional()}),Re=M.object({data:M.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=D(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=P(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=N({targetFieldKey:M.string(),alias:M.string().optional(),expression:M.string().optional(),values:M.unknown().optional(),type:M.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:M.boolean().default(!1),custom:M.boolean().default(!1),hidden:M.boolean().default(!1),enumMapper:N({matcher:M.string().or(N({matchExpression:M.string(),value:M.string()}).array())}).optional(),properties:M.lazy(()=>Ge).array().optional()}),Ke=M.object({fields:Ge.array(),dataSource:M.string(),externalSources:M.record(M.string(),M.string()).optional()}),qe=M.object({data:M.unknown()}),Je=async({block:e,params:t})=>{let n=[],{fields:r,dataSource:i,externalSources:a}=Ke.parse(t),o=P(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]=P(a?.[n],e),t),{}),c;if(Array.isArray(o))c=o.map(e=>{let t=Z(r,{...e,external:s});return n.push(...t?.errors||[]),t?.record});else{let e=Z(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=$e(r,t),a=Z(e.properties,i);return D(a?.errors)&&n.push(...a.errors),a?.record}).filter(Boolean)},Xe=(e,t,n)=>{if(e.expression)try{let r=P(e.expression,t);if(Array.isArray(r))return r.map(t=>{let r=Z(e.properties,t);return D(r?.errors)&&n.push(...r.errors),r?.record}).filter(Boolean);{let t=Z(e.properties,r);return D(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=D(e.values)?e.values:t,i=Z(e.properties,r);return D(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)},Z=(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}=et(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}},$e=(e,t)=>{if(e==null)return e;if(typeof e==`string`){if(F(e))try{return P(e,t)}catch{return e}return e}if(Array.isArray(e))return e.map(e=>$e(e,t));if(typeof e==`object`){let n={...e};for(let[e,r]of Object.entries(n))n[e]=$e(r,t);return n}return e},et=(e,t,n)=>{switch(n.type){case`string`:case`number`:case`boolean`:case`datetime_string`:return tt(n,t,e);case`enum`:return nt(n,t,e);default:return{error:{message:`Invalid type`,id:t,targetField:n.targetFieldKey}}}},tt=(e,t,n)=>{if(!e.expression)return{error:{message:`Expression is empty`,id:t,targetField:e.targetFieldKey}};let r;try{r=P(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}},nt=(e,t,n)=>{let r=tt(e,t,n),i=D(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(E(a)){let n=We(a);if(D(n)){let e=D(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=P(t,n);if(a===!0)return{value:{value:r,source_value:i}}}return{value:{value:`unmapped_value`,source_value:i}}},rt=[`data`,`headers`],it=N({type:M.literal(`none`)}),at=N({type:M.literal(`basic`),username:M.string().optional(),password:M.string().optional(),encoding:M.string().optional()}),ot=N({type:M.literal(`bearer`),token:M.string(),includeBearer:M.boolean().optional().default(!0)}),st=N({type:M.literal(`oauth2`),authorizationUrl:M.string().optional(),authorizationParams:M.record(M.string(),M.string()).optional(),tokenUrl:M.string().optional(),tokenParams:M.record(M.string(),M.string()).optional(),tokenExpiresIn:M.number().optional(),tokenRefreshExpiresIn:M.number().optional(),token:M.string(),includeBearer:M.boolean().optional().default(!0),scopes:M.string().optional(),scopeDelimiter:M.string().optional(),customHeaders:M.record(M.string(),M.string()).optional(),pkce:M.boolean().optional()}),ct=M.discriminatedUnion(`type`,[it,at,ot,st]),lt=M.object({baseUrl:M.string(),url:M.string(),method:M.enum(z),response:N({indexField:M.string().optional(),dataKey:M.string().optional(),nextKey:M.string().optional(),nextKeyIn:M.enum(rt).optional()}).optional(),iterator:N({key:M.string(),in:M.enum(V)}),cursor:N({token:M.string().optional().nullable(),position:M.number().optional().nullable()}).optional(),customErrors:R.array().optional(),args:N({name:M.string(),value:M.unknown(),in:M.enum(V),condition:M.string().optional()}).array().optional()}),ut=N({data:M.unknown().optional(),raw:M.unknown().optional(),statusCode:M.number(),message:M.string().optional(),next:M.string().optional().nullable(),position:M.number().optional()}).optional(),dt=25,ft=async({block:e,params:t})=>{let n=B.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)?dt:i,o=r?r.filter(t=>!t.condition||P(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?L({...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}=lt.parse(c),_=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,v=ct.parse(_),y=g?U(g):{query:{},body:{},headers:{}},b=H(v),x={...y?.headers??{},...b},S=e.connector?.rateLimit,C=e.connector?.concurrency,T=S!==void 0||C!==void 0?{rateLimit:S,concurrency:C}:void 0,E=m?.token??null,O=null,k=null,A=[],j=[],M=[],N=a,F=m?.position??0,I=!0,R=!0;do{I?I=!1:F=0,E!==null&&(p.in===`query`?y.query[p.key]=E.toString():p.in===`body`&&(y.body[p.key]=E));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:T})}catch(t){let n=t;return{block:e,successful:!1,errors:[W(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}O=E,j=f?.dataKey?t.data[f?.dataKey]:t.data;let r=j?.slice(F,F+N);N-=r.length,F+=r.length,M.push(t),A=A.concat(r),k=t?.status,E=pt({result:t,response:f}),r.length===j.length&&N===0&&(F=0,O=E),R=w(E)&&A.length<a}while(D(E)&&A.length<a&&j?.length>0);let z=gt(A,f);return{block:e,successful:!0,output:{data:z,raw:M,statusCode:k,next:R?void 0:O,position:R?void 0:F}}},pt=({result:e,response:t})=>{if(w(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?mt(e.headers,r):ht(e.data,r)},mt=(e,t)=>{if(w(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},ht=(e,t)=>{if(w(e)||typeof e!=`object`||!e)return null;let n=e[t];return w(n)?null:typeof n==`string`||typeof n==`number`?n:null},gt=(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},_t=N({type:M.literal(`none`)}),vt=N({type:M.literal(`basic`),username:M.string().optional(),password:M.string().optional(),encoding:M.string().optional()}),yt=N({type:M.literal(`bearer`),token:M.string(),includeBearer:M.boolean().optional().default(!0)}),bt=N({type:M.literal(`oauth2`),authorizationUrl:M.string().optional(),authorizationParams:M.record(M.string(),M.string()).optional(),tokenUrl:M.string().optional(),tokenParams:M.record(M.string(),M.string()).optional(),tokenExpiresIn:M.number().optional(),tokenRefreshExpiresIn:M.number().optional(),token:M.string(),includeBearer:M.boolean().optional().default(!0),scopes:M.string().optional(),scopeDelimiter:M.string().optional(),customHeaders:M.record(M.string(),M.string()).optional(),pkce:M.boolean().optional()}),xt=M.discriminatedUnion(`type`,[_t,vt,yt,bt]),St=M.object({baseUrl:M.string().optional(),url:M.string(),method:M.enum(z),authorization:xt.optional(),response:N({collection:M.boolean().optional(),indexField:M.string().optional(),dataKey:M.string().optional()}).optional(),customErrors:R.array().optional(),args:N({name:M.string(),value:M.unknown(),in:M.enum(V),condition:M.string().optional()}).array().optional()}),Ct=N({data:M.unknown().optional(),raw:M.unknown().optional(),statusCode:M.number(),message:M.string().optional()}).optional(),wt=async({block:e,params:t})=>{let n=B.build();if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||P(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?L({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:l,response:u,authorization:d,customErrors:f,args:p}=St.parse(o),m=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,h=p?U(p):{query:{},body:{},headers:{}},g=D(d)?d:xt.parse(m),_=H(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:[W(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let C=u?.dataKey?S.data[u?.dataKey]:S.data,w=Tt(C,u);return{block:e,successful:!0,output:{data:w,raw:S,statusCode:S?.status,message:S?.message}}},Tt=(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},Et=N({type:M.literal(`none`)}),Dt=N({type:M.literal(`basic`),username:M.string().optional(),password:M.string().optional(),encoding:M.string().optional()}),Ot=N({type:M.literal(`bearer`),token:M.string(),includeBearer:M.boolean().optional().default(!0)}),kt=N({type:M.literal(`oauth2`),authorizationUrl:M.string().optional(),authorizationParams:M.record(M.string(),M.string()).optional(),tokenUrl:M.string().optional(),tokenParams:M.record(M.string(),M.string()).optional(),tokenExpiresIn:M.number().optional(),tokenRefreshExpiresIn:M.number().optional(),token:M.string(),includeBearer:M.boolean().optional().default(!0),scopes:M.string().optional(),scopeDelimiter:M.string().optional(),customHeaders:M.record(M.string(),M.string()).optional(),pkce:M.boolean().optional()}),At=M.discriminatedUnion(`type`,[Et,Dt,Ot,kt]),jt=[`data`,`headers`],Mt=M.object({baseUrl:M.string().optional(),url:M.string(),method:M.enum(z),authorization:M.discriminatedUnion(`type`,[N({type:M.literal(`none`)}),N({type:M.literal(`basic`),username:M.string().optional(),password:M.string().optional(),encoding:M.string().optional()}),N({type:M.literal(`bearer`),token:M.string(),includeBearer:M.boolean().optional().default(!0)}),N({type:M.literal(`oauth2`),token:M.string(),includeBearer:M.boolean().optional().default(!0)})]).optional(),envelope:M.union([M.string(),M.record(M.string(),M.unknown())]).optional(),namespaces:M.strictObject({namespaceIdentifier:M.string(),namespace:M.string()}).array().optional(),soapOperation:M.string().optional(),soapAction:M.string().optional(),response:N({collection:M.boolean().optional(),indexField:M.string().optional(),dataKey:M.string().optional(),nextKey:M.string().optional(),nextKeyIn:M.enum(jt).optional()}).optional(),iterator:N({key:M.string(),in:M.enum(V)}),cursor:N({token:M.string().optional().nullable(),position:M.number().optional().nullable()}).optional(),customErrors:R.array().optional(),args:N({name:M.string(),value:M.unknown(),in:M.enum(V),condition:M.string().optional()}).array().optional()}),Nt=N({data:M.unknown().optional(),raw:M.unknown().optional(),statusCode:M.number(),message:M.string().optional(),next:M.string().optional().nullable(),position:M.number().optional()}).optional(),Pt=25,Ft=async({block:e,params:t})=>{let n=B.build(`soap`);if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=Number(e.inputs?.page_size),a=Number.isNaN(i)?Pt:i,o=r?r.filter(t=>!t.condition||P(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,s=t?L({...t,args:o},e):{},c={...s,customErrors:t?.customErrors},{baseUrl:l,url:u,method:d,response:f,iterator:p,cursor:m,authorization:h,customErrors:g,args:_,soapOperation:v,namespaces:y,envelope:b,soapAction:x}=Mt.parse(c),S=s?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,C=_?U(_):{query:{},body:{},headers:{}},T=D(h)?h:At.parse(S),E=H(T),O={...C?.headers??{},...E},k=e.connector?.rateLimit,A=e.connector?.concurrency,j={...(k!==void 0||A!==void 0)&&{rateLimit:k,concurrency:A},soapOperation:v,namespaces:y,envelope:b,soapAction:x,soapContext:{username:e.credentials?.username,password:e.credentials?.password}},M=m?.token??null,N=null,F=null,I=[],R=[],z=[],V=a,G=m?.position??0,ee=!0,K;do{ee?ee=!1:G=0,M!==null&&(p.in===`query`?C.query[p.key]=M.toString():p.in===`body`&&(C.body[p.key]=M));let t;try{t=await n.performRequest({httpClient:e.httpClient,url:`${l}${u}`,queryParams:C?.query,method:d,headers:O,body:C?.body,customErrorConfigs:g,requestConfig:j})}catch(t){let n=t;return{block:e,successful:!1,errors:[W(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}N=M,R=f?.dataKey?t.data[f?.dataKey]:t.data,Array.isArray(R)||(R=R?[R]:[]);let r=R?.slice(G,G+V);V-=r.length,G+=r.length,z.push(t),I=I.concat(r),F=t?.status,M=It({result:t,response:f}),r.length===R.length&&V===0&&(G=0,N=M),K=w(M)&&I.length<a}while(D(M)&&I.length<a&&R?.length>0);let te=zt(I,f);return{block:e,successful:!0,output:{data:te,raw:z,statusCode:F,next:K?void 0:N,position:K?void 0:G}}},It=({result:e,response:t})=>{if(w(t?.nextKey))return null;let n=t?.nextKeyIn??`data`,r=t?.nextKey;return n===`headers`?Lt(e.headers,r):Rt(e.data,r)},Lt=(e,t)=>{if(w(e)||typeof e!=`object`)return null;let n=t.toLowerCase(),[,r]=Object.entries(e).find(([e])=>e?.toLowerCase()===n)??[];if(Array.isArray(r)){let e=r.find(e=>typeof e==`string`&&e!==``||typeof e==`number`);return typeof e==`string`||typeof e==`number`?e:null}return typeof r==`string`&&r!==``||typeof r==`number`?r:null},Rt=(e,t)=>{if(w(e)||typeof e!=`object`||!e)return null;let n=e[t];return w(n)?null:typeof n==`string`||typeof n==`number`?n:null},zt=(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},Bt=M.object({baseUrl:M.string().optional(),url:M.string(),method:M.enum(z),authorization:At.optional(),envelope:M.union([M.string(),M.record(M.string(),M.unknown())]).optional(),namespaces:M.strictObject({namespaceIdentifier:M.string(),namespace:M.string()}).array().optional(),soapOperation:M.string().optional(),soapAction:M.string().optional(),response:N({collection:M.boolean().optional(),indexField:M.string().optional(),dataKey:M.string().optional()}).optional(),customErrors:R.array().optional(),args:N({name:M.string(),value:M.unknown(),in:M.enum(V),condition:M.string().optional()}).array().optional()}),Vt=N({data:M.unknown().optional(),raw:M.unknown().optional(),statusCode:M.number(),message:M.string().optional()}).optional(),Ht=async({block:e,params:t})=>{let n=B.build(`soap`);if(!e.httpClient)throw Error(`HTTP client is not configured`);let{args:r}=t,i=r?r.filter(t=>!t.condition||P(t.condition,e)===!0).map(e=>({...e,condition:void 0})):void 0,a=t?L({...t,args:i},e):{},o={...a,customErrors:t?.customErrors},{baseUrl:s,url:c,method:l,response:u,authorization:d,customErrors:f,args:p,soapOperation:m,namespaces:h,envelope:g,soapAction:_}=Bt.parse(o),v=a?.authentication?.[e.context.authenticationType]?.[e.context.environment]?.authorization,y=p?U(p):{query:{},body:{},headers:{}},b=D(d)?d:At.parse(v),x=H(b),S={...y?.headers??{},...x},C=e.connector?.rateLimit,w=e.connector?.concurrency,T={...(C!==void 0||w!==void 0)&&{rateLimit:C,concurrency:w},soapOperation:m,namespaces:h,envelope:g,soapAction:_,soapContext:{username:e.credentials?.username,password:e.credentials?.password}},E;try{E=await n.performRequest({httpClient:e.httpClient,url:`${s}${c}`,queryParams:y?.query,method:l,headers:S,body:y?.body,customErrorConfigs:f,requestConfig:T})}catch(t){let n=t;return{block:e,successful:!1,errors:[W(t)],output:{statusCode:n?.response?.status??500,message:n?.response?.message}}}let O=u?.dataKey?E.data[u?.dataKey]:E.data,k=Ut(O,u);return{block:e,successful:!0,output:{data:k,raw:E,statusCode:E?.status,message:E?.message}}},Ut=(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},Wt=M.object({values:M.string().or(M.record(M.string(),M.unknown())).or(M.array(M.unknown()))}),Gt=M.object({data:M.unknown()}),Kt=async({block:e,params:t})=>{let{values:n}=Wt.parse(t),r=Array.isArray(n)?n.map(t=>qt(t,e)):qt(n,e);return{block:{...e},successful:!0,output:{data:r}}},qt=(e,t)=>E(e)?I(e,t):T(e)?L(e,t):e,Jt=M.object({targetFieldKey:M.string(),type:M.enum([`string`,`number`,`boolean`,`datetime_string`,`enum`,`object`]),array:M.boolean().default(!1),custom:M.boolean().default(!1),hidden:M.boolean().default(!1),properties:M.lazy(()=>Jt).array().optional()}),Yt=M.object({fields:Jt.array().optional(),dataSource:M.string()}),Xt=M.object({data:M.unknown()});let Q=function(e){return e.String=`string`,e.Number=`number`,e.Boolean=`boolean`,e.DateTimeString=`datetime_string`,e}({});const Zt=({value:e,type:t,format:n})=>{if(w(e))return null;switch(t){case Q.String:return j({value:e});case Q.Number:return A({value:e});case Q.Boolean:return O({value:e});case Q.DateTimeString:return k({value:e,format:n});default:return e}},Qt=e=>{let t=Object.values(Q);return t.includes(e)},$t=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=>en(e,t)):en(e.result,t),{block:{...e,result:n},successful:!0}},en=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i}=t;Qt(i)&&(!t.custom&&D(n[r])?n[r]=Zt({value:e[r],type:i}):n.unified_custom_fields&&D(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=Zt({value:e.unified_custom_fields?.[r],type:i})))}),{...n}},tn=async({block:e,params:t})=>{let{fields:n,dataSource:r}=Yt.parse(t),i=P(r,e);if(!n||e?.debug?.custom_mappings===`disabled`)return{block:e,successful:!0};let a;return a=Array.isArray(i)?i.map(e=>rn(e,n)):rn(i,n),{block:{...e},successful:!0,output:{data:a}}},nn=(e,t)=>!e.properties||!t?t:Array.isArray(t)?t.map(t=>typeof t==`object`&&t?rn(t,e.properties):t):typeof t==`object`&&t?rn(t,e.properties):t,rn=(e,t)=>{let n={...e};return t.forEach(t=>{let{targetFieldKey:r,type:i,array:a}=t;i===`object`?!t.custom&&D(n[r])?n[r]=nn(t,e[r]):n.unified_custom_fields&&D(n.unified_custom_fields?.[r])&&(n.unified_custom_fields[r]=nn(t,e.unified_custom_fields?.[r])):Qt(i)&&(!t.custom&&D(n[r])?(!a||!Array.isArray(n[r]))&&(n[r]=Zt({value:e[r],type:i})):n.unified_custom_fields&&D(n.unified_custom_fields?.[r])&&(!a||!Array.isArray(n.unified_custom_fields[r]))&&(n.unified_custom_fields[r]=Zt({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.SOAP_REQUEST=`soap_request`,e.SOAP_PAGINATED_REQUEST=`soap_paginated_request`,e.STATIC_VALUES=`static_values`,e}({});const an={[$.TYPECAST]:{v1:{fn:$t},v2:{fn:tn,inputSchema:Yt,outputSchema:Xt}},[$.MAP_FIELDS]:{v1:{fn:Be},v2:{fn:Je,inputSchema:Ke,outputSchema:qe}},[$.REQUEST]:{v1:{fn:wt,inputSchema:St,outputSchema:Ct}},[$.GROUP_DATA]:{v1:{fn:ze,inputSchema:Le,outputSchema:Re}},[$.PAGINATED_REQUEST]:{v1:{fn:ft,inputSchema:lt,outputSchema:ut}},[$.SOAP_REQUEST]:{v1:{fn:Ht,inputSchema:Bt,outputSchema:Vt}},[$.SOAP_PAGINATED_REQUEST]:{v1:{fn:Ft,inputSchema:Mt,outputSchema:Nt}},[$.STATIC_VALUES]:{v1:{fn:Kt,inputSchema:Wt,outputSchema:Gt}}},on=(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},sn={build({functionName:e,version:t=`1`,validateSchemas:n=!1,stepFunctionsList:r=an}){let i=r?.[e]?.[`v${t}`];if(!i)throw Error(`Unknown step function: ${e} v${t}`);return n?{...i,fn:on(i,e)}:i}};export{At as AUTHORIZATION_SCHEMA,ie as COMPOSITE_ID_LATEST_VERSION,ae as CoreError,Ce as INPUT_ENUM_REGISTRY,Ee as ReleaseStages,$ as StepFunctionName,sn as StepFunctionsFactory,an as StepFunctionsRegistry,Ne as areCursorsEqual,pe as decodeCompositeId,fe as encodeCompositeId,je as expandCursor,ee as getCategoryDetails,we as getInputEnumValues,Se as isCompositeId,Ie as isCoreError,Pe as isCursorEmpty,K as isValidCategory,Te as isValidEnumRef,ke as minifyCursor,Fe as updateCursor};
|