@commercelayer/provisioning-sdk 2.2.1 → 2.3.1
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/lib/index.d.mts +234 -8
- package/lib/index.d.ts +234 -8
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +1 -1
package/lib/index.d.mts
CHANGED
|
@@ -138,6 +138,8 @@ interface ResourceCreate extends ResourceBase {
|
|
|
138
138
|
interface ResourceUpdate extends ResourceBase {
|
|
139
139
|
readonly id: string;
|
|
140
140
|
}
|
|
141
|
+
interface SingletonUpdate extends ResourceBase {
|
|
142
|
+
}
|
|
141
143
|
type ListMeta = {
|
|
142
144
|
readonly pageCount: number;
|
|
143
145
|
readonly recordCount: number;
|
|
@@ -173,7 +175,7 @@ declare class ResourceAdapter {
|
|
|
173
175
|
retrieve<R extends Resource>(resource: ResourceId | ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): Promise<R>;
|
|
174
176
|
list<R extends Resource>(resource: ResourceType, params?: QueryParamsList<R>, options?: ResourcesConfig): Promise<ListResponse<R>>;
|
|
175
177
|
create<C extends ResourceCreate, R extends Resource>(resource: C & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
|
|
176
|
-
update<U extends ResourceUpdate, R extends Resource>(resource: U &
|
|
178
|
+
update<U extends (ResourceUpdate | SingletonUpdate), R extends Resource>(resource: U & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): Promise<R>;
|
|
177
179
|
delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
178
180
|
fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams<R>, options?: ResourcesConfig): Promise<R | ListResponse<R>>;
|
|
179
181
|
action(cmd: Extract<Method, 'POST' | 'PATCH'>, path: string, payload?: any, options?: ResourcesConfig): Promise<void>;
|
|
@@ -618,6 +620,15 @@ interface Organization extends Resource {
|
|
|
618
620
|
* Enables the rules engine for flex promotions and price list rules.
|
|
619
621
|
*/
|
|
620
622
|
api_rules_engine: boolean;
|
|
623
|
+
/**
|
|
624
|
+
* Forces the usage of the new Authentication API.
|
|
625
|
+
* @example ```"true"```
|
|
626
|
+
*/
|
|
627
|
+
api_new_auth: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Enables the purge of cached single resources when list is purged.
|
|
630
|
+
*/
|
|
631
|
+
api_purge_single_resource: boolean;
|
|
621
632
|
/**
|
|
622
633
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
623
634
|
* @example ```"true"```
|
|
@@ -686,6 +697,11 @@ interface Organization extends Resource {
|
|
|
686
697
|
* @example ```"10"```
|
|
687
698
|
*/
|
|
688
699
|
imports_max_concurrent_count: number;
|
|
700
|
+
/**
|
|
701
|
+
* Enables purging of cached resources upon succeeded imports.
|
|
702
|
+
* @example ```"true"```
|
|
703
|
+
*/
|
|
704
|
+
imports_purge_cache: boolean;
|
|
689
705
|
/**
|
|
690
706
|
* The maximum number of active concurrent promotions allowed for your organization, default is 10.
|
|
691
707
|
* @example ```"10"```
|
|
@@ -695,6 +711,14 @@ interface Organization extends Resource {
|
|
|
695
711
|
* Enables triggering of webhooks during imports, default is false.
|
|
696
712
|
*/
|
|
697
713
|
imports_trigger_webhooks: number;
|
|
714
|
+
/**
|
|
715
|
+
* Enables the use of an external discount engine in place of the standard one, default is false.
|
|
716
|
+
*/
|
|
717
|
+
discount_engines_enabled: boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Enables raising of API errors in case of discount engine failure, default is false.
|
|
720
|
+
*/
|
|
721
|
+
discount_engines_errors: boolean;
|
|
698
722
|
/**
|
|
699
723
|
* Enables raising of API errors in case of tax calculation failure, default is false.
|
|
700
724
|
*/
|
|
@@ -998,8 +1022,9 @@ interface User extends Resource {
|
|
|
998
1022
|
* The user 2FA setting.
|
|
999
1023
|
*/
|
|
1000
1024
|
otp_required_for_login: boolean;
|
|
1025
|
+
identity_providers?: Nullable<IdentityProvider[]>;
|
|
1001
1026
|
}
|
|
1002
|
-
interface UserUpdate extends
|
|
1027
|
+
interface UserUpdate extends SingletonUpdate {
|
|
1003
1028
|
/**
|
|
1004
1029
|
* The user email.
|
|
1005
1030
|
* @example ```"user@commercelayer.io"```
|
|
@@ -1024,6 +1049,7 @@ interface UserUpdate extends ResourceUpdate {
|
|
|
1024
1049
|
declare class Users extends ApiSingleton<User> {
|
|
1025
1050
|
static readonly TYPE: UserType;
|
|
1026
1051
|
update(resource: UserUpdate, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1052
|
+
identity_providers(userId: string | User, params?: QueryParamsList<IdentityProvider>, options?: ResourcesConfig): Promise<ListResponse<IdentityProvider>>;
|
|
1027
1053
|
isUser(resource: any): resource is User;
|
|
1028
1054
|
relationship(id: string | ResourceId | null): UserRel;
|
|
1029
1055
|
relationshipToMany(...ids: string[]): UserRel[];
|
|
@@ -1031,7 +1057,204 @@ declare class Users extends ApiSingleton<User> {
|
|
|
1031
1057
|
path(): string;
|
|
1032
1058
|
}
|
|
1033
1059
|
|
|
1034
|
-
type
|
|
1060
|
+
type IdentityProviderType = 'identity_providers';
|
|
1061
|
+
type IdentityProviderRel = ResourceRel & {
|
|
1062
|
+
type: IdentityProviderType;
|
|
1063
|
+
};
|
|
1064
|
+
type IdentityProviderSort = Pick<IdentityProvider, 'id' | 'name' | 'client_id' | 'client_secret' | 'issuer' | 'status' | 'domains' | 'token_url' | 'authorize_url' | 'jwks_url' | 'txt_record' | 'organization' | 'disabled_at'> & ResourceSort;
|
|
1065
|
+
interface IdentityProvider extends Resource {
|
|
1066
|
+
readonly type: IdentityProviderType;
|
|
1067
|
+
/**
|
|
1068
|
+
* The name of the Identity provider.
|
|
1069
|
+
* @example ```"Org auth0"```
|
|
1070
|
+
*/
|
|
1071
|
+
name: string;
|
|
1072
|
+
/**
|
|
1073
|
+
* The client ID used for the auth workflow.
|
|
1074
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1075
|
+
*/
|
|
1076
|
+
client_id: string;
|
|
1077
|
+
/**
|
|
1078
|
+
* The client secret used for the auth workflow.
|
|
1079
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1080
|
+
*/
|
|
1081
|
+
client_secret: string;
|
|
1082
|
+
/**
|
|
1083
|
+
* The issuer used for the auth workflow.
|
|
1084
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1085
|
+
*/
|
|
1086
|
+
issuer: string;
|
|
1087
|
+
/**
|
|
1088
|
+
* The identity provider status. One of `pending` (default), `verified` or `error`.
|
|
1089
|
+
* @example ```"pending"```
|
|
1090
|
+
*/
|
|
1091
|
+
status: 'pending' | 'verified' | 'error';
|
|
1092
|
+
/**
|
|
1093
|
+
* The list of domains in scope (comma-separated).
|
|
1094
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1095
|
+
*/
|
|
1096
|
+
domains: string;
|
|
1097
|
+
/**
|
|
1098
|
+
* The token URL used for the auth workflow.
|
|
1099
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1100
|
+
*/
|
|
1101
|
+
token_url: string;
|
|
1102
|
+
/**
|
|
1103
|
+
* The authorize URL used for the auth workflow.
|
|
1104
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1105
|
+
*/
|
|
1106
|
+
authorize_url: string;
|
|
1107
|
+
/**
|
|
1108
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1109
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1110
|
+
*/
|
|
1111
|
+
jwks_url: string;
|
|
1112
|
+
/**
|
|
1113
|
+
* The TXT record value used to check the domain.
|
|
1114
|
+
* @example ```"cl-verification=a6CDk5v"```
|
|
1115
|
+
*/
|
|
1116
|
+
txt_record: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* The organization identifier for authorize params.
|
|
1119
|
+
* @example ```"org_76gsfs5gd"```
|
|
1120
|
+
*/
|
|
1121
|
+
organization?: Nullable<string>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Time at which this resource was disabled.
|
|
1124
|
+
* @example ```"2018-01-01T12:00:00.000Z"```
|
|
1125
|
+
*/
|
|
1126
|
+
disabled_at: string;
|
|
1127
|
+
user?: Nullable<User>;
|
|
1128
|
+
}
|
|
1129
|
+
interface IdentityProviderCreate extends ResourceCreate {
|
|
1130
|
+
/**
|
|
1131
|
+
* The name of the Identity provider.
|
|
1132
|
+
* @example ```"Org auth0"```
|
|
1133
|
+
*/
|
|
1134
|
+
name: string;
|
|
1135
|
+
/**
|
|
1136
|
+
* The client ID used for the auth workflow.
|
|
1137
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1138
|
+
*/
|
|
1139
|
+
client_id: string;
|
|
1140
|
+
/**
|
|
1141
|
+
* The client secret used for the auth workflow.
|
|
1142
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1143
|
+
*/
|
|
1144
|
+
client_secret: string;
|
|
1145
|
+
/**
|
|
1146
|
+
* The issuer used for the auth workflow.
|
|
1147
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1148
|
+
*/
|
|
1149
|
+
issuer: string;
|
|
1150
|
+
/**
|
|
1151
|
+
* The list of domains in scope (comma-separated).
|
|
1152
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1153
|
+
*/
|
|
1154
|
+
domains: string;
|
|
1155
|
+
/**
|
|
1156
|
+
* The token URL used for the auth workflow.
|
|
1157
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1158
|
+
*/
|
|
1159
|
+
token_url: string;
|
|
1160
|
+
/**
|
|
1161
|
+
* The authorize URL used for the auth workflow.
|
|
1162
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1163
|
+
*/
|
|
1164
|
+
authorize_url: string;
|
|
1165
|
+
/**
|
|
1166
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1167
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1168
|
+
*/
|
|
1169
|
+
jwks_url: string;
|
|
1170
|
+
/**
|
|
1171
|
+
* The organization identifier for authorize params.
|
|
1172
|
+
* @example ```"org_76gsfs5gd"```
|
|
1173
|
+
*/
|
|
1174
|
+
organization?: Nullable<string>;
|
|
1175
|
+
/**
|
|
1176
|
+
* Send this attribute if you want to mark this resource as disabled.
|
|
1177
|
+
* @example ```"true"```
|
|
1178
|
+
*/
|
|
1179
|
+
_disable?: Nullable<boolean>;
|
|
1180
|
+
/**
|
|
1181
|
+
* Send this attribute if you want to mark this resource as enabled.
|
|
1182
|
+
* @example ```"true"```
|
|
1183
|
+
*/
|
|
1184
|
+
_enable?: Nullable<boolean>;
|
|
1185
|
+
}
|
|
1186
|
+
interface IdentityProviderUpdate extends ResourceUpdate {
|
|
1187
|
+
/**
|
|
1188
|
+
* The name of the Identity provider.
|
|
1189
|
+
* @example ```"Org auth0"```
|
|
1190
|
+
*/
|
|
1191
|
+
name?: Nullable<string>;
|
|
1192
|
+
/**
|
|
1193
|
+
* The client ID used for the auth workflow.
|
|
1194
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1195
|
+
*/
|
|
1196
|
+
client_id?: Nullable<string>;
|
|
1197
|
+
/**
|
|
1198
|
+
* The client secret used for the auth workflow.
|
|
1199
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1200
|
+
*/
|
|
1201
|
+
client_secret?: Nullable<string>;
|
|
1202
|
+
/**
|
|
1203
|
+
* The issuer used for the auth workflow.
|
|
1204
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1205
|
+
*/
|
|
1206
|
+
issuer?: Nullable<string>;
|
|
1207
|
+
/**
|
|
1208
|
+
* The list of domains in scope (comma-separated).
|
|
1209
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1210
|
+
*/
|
|
1211
|
+
domains?: Nullable<string>;
|
|
1212
|
+
/**
|
|
1213
|
+
* The token URL used for the auth workflow.
|
|
1214
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1215
|
+
*/
|
|
1216
|
+
token_url?: Nullable<string>;
|
|
1217
|
+
/**
|
|
1218
|
+
* The authorize URL used for the auth workflow.
|
|
1219
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1220
|
+
*/
|
|
1221
|
+
authorize_url?: Nullable<string>;
|
|
1222
|
+
/**
|
|
1223
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1224
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1225
|
+
*/
|
|
1226
|
+
jwks_url?: Nullable<string>;
|
|
1227
|
+
/**
|
|
1228
|
+
* The organization identifier for authorize params.
|
|
1229
|
+
* @example ```"org_76gsfs5gd"```
|
|
1230
|
+
*/
|
|
1231
|
+
organization?: Nullable<string>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Send this attribute if you want to mark this resource as disabled.
|
|
1234
|
+
* @example ```"true"```
|
|
1235
|
+
*/
|
|
1236
|
+
_disable?: Nullable<boolean>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Send this attribute if you want to mark this resource as enabled.
|
|
1239
|
+
* @example ```"true"```
|
|
1240
|
+
*/
|
|
1241
|
+
_enable?: Nullable<boolean>;
|
|
1242
|
+
}
|
|
1243
|
+
declare class IdentityProviders extends ApiResource<IdentityProvider> {
|
|
1244
|
+
static readonly TYPE: IdentityProviderType;
|
|
1245
|
+
create(resource: IdentityProviderCreate, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1246
|
+
update(resource: IdentityProviderUpdate, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1247
|
+
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
1248
|
+
user(identityProviderId: string | IdentityProvider, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1249
|
+
_disable(id: string | IdentityProvider, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1250
|
+
_enable(id: string | IdentityProvider, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1251
|
+
isIdentityProvider(resource: any): resource is IdentityProvider;
|
|
1252
|
+
relationship(id: string | ResourceId | null): IdentityProviderRel;
|
|
1253
|
+
relationshipToMany(...ids: string[]): IdentityProviderRel[];
|
|
1254
|
+
type(): IdentityProviderType;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'user' | 'versions';
|
|
1035
1258
|
declare const resourceList: ResourceTypeLock[];
|
|
1036
1259
|
declare const singletonList: ResourceTypeLock[];
|
|
1037
1260
|
type RetrievableResourceType = ResourceTypeLock;
|
|
@@ -1042,15 +1265,15 @@ type ListableResourceType = Exclude<ResourceTypeLock, 'user'>;
|
|
|
1042
1265
|
type ListableResource = Resource & {
|
|
1043
1266
|
type: ListableResourceType;
|
|
1044
1267
|
};
|
|
1045
|
-
type CreatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1268
|
+
type CreatableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1046
1269
|
type CreatableResource = Resource & {
|
|
1047
1270
|
type: CreatableResourceType;
|
|
1048
1271
|
};
|
|
1049
|
-
type UpdatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1272
|
+
type UpdatableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1050
1273
|
type UpdatableResource = Resource & {
|
|
1051
1274
|
type: UpdatableResourceType;
|
|
1052
1275
|
};
|
|
1053
|
-
type DeletableResourceType = 'api_credentials' | 'application_memberships' | 'memberships';
|
|
1276
|
+
type DeletableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships';
|
|
1054
1277
|
type DeletableResource = Resource & {
|
|
1055
1278
|
type: DeletableResourceType;
|
|
1056
1279
|
};
|
|
@@ -1064,6 +1287,7 @@ type VersionableResource = Resource & {
|
|
|
1064
1287
|
type ResourceFields = {
|
|
1065
1288
|
api_credentials: ApiCredential;
|
|
1066
1289
|
application_memberships: ApplicationMembership;
|
|
1290
|
+
identity_providers: IdentityProvider;
|
|
1067
1291
|
memberships: Membership;
|
|
1068
1292
|
organizations: Organization;
|
|
1069
1293
|
permissions: Permission;
|
|
@@ -1074,6 +1298,7 @@ type ResourceFields = {
|
|
|
1074
1298
|
type ResourceSortFields = {
|
|
1075
1299
|
api_credentials: ApiCredentialSort;
|
|
1076
1300
|
application_memberships: ApplicationMembershipSort;
|
|
1301
|
+
identity_providers: IdentityProviderSort;
|
|
1077
1302
|
memberships: MembershipSort;
|
|
1078
1303
|
organizations: OrganizationSort;
|
|
1079
1304
|
permissions: PermissionSort;
|
|
@@ -1117,10 +1342,11 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1117
1342
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1118
1343
|
declare class CommerceLayerProvisioningClient {
|
|
1119
1344
|
#private;
|
|
1120
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1345
|
+
readonly openApiSchemaVersion = "1.0.6";
|
|
1121
1346
|
constructor(config: CommerceLayerInitConfig);
|
|
1122
1347
|
get api_credentials(): ApiCredentials;
|
|
1123
1348
|
get application_memberships(): ApplicationMemberships;
|
|
1349
|
+
get identity_providers(): IdentityProviders;
|
|
1124
1350
|
get memberships(): Memberships;
|
|
1125
1351
|
get organizations(): Organizations;
|
|
1126
1352
|
get permissions(): Permissions;
|
|
@@ -1156,4 +1382,4 @@ declare const CommerceLayerProvisioningStatic: {
|
|
|
1156
1382
|
readonly schemaVersion: string;
|
|
1157
1383
|
};
|
|
1158
1384
|
|
|
1159
|
-
export { type ApiCredential, type ApiCredentialCreate, type ApiCredentialSort, type ApiCredentialUpdate, ApiCredentials, ApiError, ApiResource, ApiSingleton, type ApplicationMembership, type ApplicationMembershipCreate, type ApplicationMembershipSort, type ApplicationMembershipUpdate, ApplicationMemberships, type CommerceLayerConfig, type CommerceLayerInitConfig, CommerceLayerProvisioning, CommerceLayerProvisioningClient, CommerceLayerProvisioningStatic, type CreatableResource, type CreatableResourceType, type DeletableResource, type DeletableResourceType, type ErrorObj, ErrorType, type HeadersObj, type ListMeta, ListResponse, type ListableResource, type ListableResourceType, type Membership, type MembershipCreate, type MembershipSort, type MembershipUpdate, Memberships, type Metadata, type Organization, type OrganizationCreate, type OrganizationSort, type OrganizationUpdate, Organizations, type Permission, type PermissionCreate, type PermissionSort, type PermissionUpdate, Permissions, type QueryArrayFields, type QueryArraySortable, type QueryFilter, type QueryInclude, type QueryPageNumber, type QueryPageSize, type QueryParams, type QueryParamsList, type QueryParamsRetrieve, type QueryRecordFields, type QueryRecordSortable, type RequestObj, type Resource, type ResourceCreate, type ResourceFields, type ResourceFilter, type ResourceId, type ResourceRel, type ResourceSort, type ResourceSortFields, type ResourceType, type ResourceTypeLock, type ResourceUpdate, type ResourcesConfig, type ResourcesInitConfig, type ResponseObj, type RetrievableResource, type RetrievableResourceType, type Role, type RoleCreate, type RoleSort, type RoleUpdate, Roles, SdkError, type UpdatableResource, type UpdatableResourceType, type User, type UserSort, type UserUpdate, Users, type Version, type VersionSort, type VersionableResource, type VersionableResourceType, Versions, apiResourceAdapter, CommerceLayerProvisioning as default, generateQueryStringParams, generateSearchString, isParamsList, resourceList, singletonList };
|
|
1385
|
+
export { type ApiCredential, type ApiCredentialCreate, type ApiCredentialSort, type ApiCredentialUpdate, ApiCredentials, ApiError, ApiResource, ApiSingleton, type ApplicationMembership, type ApplicationMembershipCreate, type ApplicationMembershipSort, type ApplicationMembershipUpdate, ApplicationMemberships, type CommerceLayerConfig, type CommerceLayerInitConfig, CommerceLayerProvisioning, CommerceLayerProvisioningClient, CommerceLayerProvisioningStatic, type CreatableResource, type CreatableResourceType, type DeletableResource, type DeletableResourceType, type ErrorObj, ErrorType, type HeadersObj, type IdentityProvider, type IdentityProviderCreate, type IdentityProviderSort, type IdentityProviderUpdate, IdentityProviders, type ListMeta, ListResponse, type ListableResource, type ListableResourceType, type Membership, type MembershipCreate, type MembershipSort, type MembershipUpdate, Memberships, type Metadata, type Organization, type OrganizationCreate, type OrganizationSort, type OrganizationUpdate, Organizations, type Permission, type PermissionCreate, type PermissionSort, type PermissionUpdate, Permissions, type QueryArrayFields, type QueryArraySortable, type QueryFilter, type QueryInclude, type QueryPageNumber, type QueryPageSize, type QueryParams, type QueryParamsList, type QueryParamsRetrieve, type QueryRecordFields, type QueryRecordSortable, type RequestObj, type Resource, type ResourceCreate, type ResourceFields, type ResourceFilter, type ResourceId, type ResourceRel, type ResourceSort, type ResourceSortFields, type ResourceType, type ResourceTypeLock, type ResourceUpdate, type ResourcesConfig, type ResourcesInitConfig, type ResponseObj, type RetrievableResource, type RetrievableResourceType, type Role, type RoleCreate, type RoleSort, type RoleUpdate, Roles, SdkError, type SingletonUpdate, type UpdatableResource, type UpdatableResourceType, type User, type UserSort, type UserUpdate, Users, type Version, type VersionSort, type VersionableResource, type VersionableResourceType, Versions, apiResourceAdapter, CommerceLayerProvisioning as default, generateQueryStringParams, generateSearchString, isParamsList, resourceList, singletonList };
|
package/lib/index.d.ts
CHANGED
|
@@ -138,6 +138,8 @@ interface ResourceCreate extends ResourceBase {
|
|
|
138
138
|
interface ResourceUpdate extends ResourceBase {
|
|
139
139
|
readonly id: string;
|
|
140
140
|
}
|
|
141
|
+
interface SingletonUpdate extends ResourceBase {
|
|
142
|
+
}
|
|
141
143
|
type ListMeta = {
|
|
142
144
|
readonly pageCount: number;
|
|
143
145
|
readonly recordCount: number;
|
|
@@ -173,7 +175,7 @@ declare class ResourceAdapter {
|
|
|
173
175
|
retrieve<R extends Resource>(resource: ResourceId | ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): Promise<R>;
|
|
174
176
|
list<R extends Resource>(resource: ResourceType, params?: QueryParamsList<R>, options?: ResourcesConfig): Promise<ListResponse<R>>;
|
|
175
177
|
create<C extends ResourceCreate, R extends Resource>(resource: C & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig): Promise<R>;
|
|
176
|
-
update<U extends ResourceUpdate, R extends Resource>(resource: U &
|
|
178
|
+
update<U extends (ResourceUpdate | SingletonUpdate), R extends Resource>(resource: U & ResourceType, params?: QueryParamsRetrieve<R>, options?: ResourcesConfig, path?: string): Promise<R>;
|
|
177
179
|
delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
178
180
|
fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams<R>, options?: ResourcesConfig): Promise<R | ListResponse<R>>;
|
|
179
181
|
action(cmd: Extract<Method, 'POST' | 'PATCH'>, path: string, payload?: any, options?: ResourcesConfig): Promise<void>;
|
|
@@ -618,6 +620,15 @@ interface Organization extends Resource {
|
|
|
618
620
|
* Enables the rules engine for flex promotions and price list rules.
|
|
619
621
|
*/
|
|
620
622
|
api_rules_engine: boolean;
|
|
623
|
+
/**
|
|
624
|
+
* Forces the usage of the new Authentication API.
|
|
625
|
+
* @example ```"true"```
|
|
626
|
+
*/
|
|
627
|
+
api_new_auth: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Enables the purge of cached single resources when list is purged.
|
|
630
|
+
*/
|
|
631
|
+
api_purge_single_resource: boolean;
|
|
621
632
|
/**
|
|
622
633
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
623
634
|
* @example ```"true"```
|
|
@@ -686,6 +697,11 @@ interface Organization extends Resource {
|
|
|
686
697
|
* @example ```"10"```
|
|
687
698
|
*/
|
|
688
699
|
imports_max_concurrent_count: number;
|
|
700
|
+
/**
|
|
701
|
+
* Enables purging of cached resources upon succeeded imports.
|
|
702
|
+
* @example ```"true"```
|
|
703
|
+
*/
|
|
704
|
+
imports_purge_cache: boolean;
|
|
689
705
|
/**
|
|
690
706
|
* The maximum number of active concurrent promotions allowed for your organization, default is 10.
|
|
691
707
|
* @example ```"10"```
|
|
@@ -695,6 +711,14 @@ interface Organization extends Resource {
|
|
|
695
711
|
* Enables triggering of webhooks during imports, default is false.
|
|
696
712
|
*/
|
|
697
713
|
imports_trigger_webhooks: number;
|
|
714
|
+
/**
|
|
715
|
+
* Enables the use of an external discount engine in place of the standard one, default is false.
|
|
716
|
+
*/
|
|
717
|
+
discount_engines_enabled: boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Enables raising of API errors in case of discount engine failure, default is false.
|
|
720
|
+
*/
|
|
721
|
+
discount_engines_errors: boolean;
|
|
698
722
|
/**
|
|
699
723
|
* Enables raising of API errors in case of tax calculation failure, default is false.
|
|
700
724
|
*/
|
|
@@ -998,8 +1022,9 @@ interface User extends Resource {
|
|
|
998
1022
|
* The user 2FA setting.
|
|
999
1023
|
*/
|
|
1000
1024
|
otp_required_for_login: boolean;
|
|
1025
|
+
identity_providers?: Nullable<IdentityProvider[]>;
|
|
1001
1026
|
}
|
|
1002
|
-
interface UserUpdate extends
|
|
1027
|
+
interface UserUpdate extends SingletonUpdate {
|
|
1003
1028
|
/**
|
|
1004
1029
|
* The user email.
|
|
1005
1030
|
* @example ```"user@commercelayer.io"```
|
|
@@ -1024,6 +1049,7 @@ interface UserUpdate extends ResourceUpdate {
|
|
|
1024
1049
|
declare class Users extends ApiSingleton<User> {
|
|
1025
1050
|
static readonly TYPE: UserType;
|
|
1026
1051
|
update(resource: UserUpdate, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1052
|
+
identity_providers(userId: string | User, params?: QueryParamsList<IdentityProvider>, options?: ResourcesConfig): Promise<ListResponse<IdentityProvider>>;
|
|
1027
1053
|
isUser(resource: any): resource is User;
|
|
1028
1054
|
relationship(id: string | ResourceId | null): UserRel;
|
|
1029
1055
|
relationshipToMany(...ids: string[]): UserRel[];
|
|
@@ -1031,7 +1057,204 @@ declare class Users extends ApiSingleton<User> {
|
|
|
1031
1057
|
path(): string;
|
|
1032
1058
|
}
|
|
1033
1059
|
|
|
1034
|
-
type
|
|
1060
|
+
type IdentityProviderType = 'identity_providers';
|
|
1061
|
+
type IdentityProviderRel = ResourceRel & {
|
|
1062
|
+
type: IdentityProviderType;
|
|
1063
|
+
};
|
|
1064
|
+
type IdentityProviderSort = Pick<IdentityProvider, 'id' | 'name' | 'client_id' | 'client_secret' | 'issuer' | 'status' | 'domains' | 'token_url' | 'authorize_url' | 'jwks_url' | 'txt_record' | 'organization' | 'disabled_at'> & ResourceSort;
|
|
1065
|
+
interface IdentityProvider extends Resource {
|
|
1066
|
+
readonly type: IdentityProviderType;
|
|
1067
|
+
/**
|
|
1068
|
+
* The name of the Identity provider.
|
|
1069
|
+
* @example ```"Org auth0"```
|
|
1070
|
+
*/
|
|
1071
|
+
name: string;
|
|
1072
|
+
/**
|
|
1073
|
+
* The client ID used for the auth workflow.
|
|
1074
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1075
|
+
*/
|
|
1076
|
+
client_id: string;
|
|
1077
|
+
/**
|
|
1078
|
+
* The client secret used for the auth workflow.
|
|
1079
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1080
|
+
*/
|
|
1081
|
+
client_secret: string;
|
|
1082
|
+
/**
|
|
1083
|
+
* The issuer used for the auth workflow.
|
|
1084
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1085
|
+
*/
|
|
1086
|
+
issuer: string;
|
|
1087
|
+
/**
|
|
1088
|
+
* The identity provider status. One of `pending` (default), `verified` or `error`.
|
|
1089
|
+
* @example ```"pending"```
|
|
1090
|
+
*/
|
|
1091
|
+
status: 'pending' | 'verified' | 'error';
|
|
1092
|
+
/**
|
|
1093
|
+
* The list of domains in scope (comma-separated).
|
|
1094
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1095
|
+
*/
|
|
1096
|
+
domains: string;
|
|
1097
|
+
/**
|
|
1098
|
+
* The token URL used for the auth workflow.
|
|
1099
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1100
|
+
*/
|
|
1101
|
+
token_url: string;
|
|
1102
|
+
/**
|
|
1103
|
+
* The authorize URL used for the auth workflow.
|
|
1104
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1105
|
+
*/
|
|
1106
|
+
authorize_url: string;
|
|
1107
|
+
/**
|
|
1108
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1109
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1110
|
+
*/
|
|
1111
|
+
jwks_url: string;
|
|
1112
|
+
/**
|
|
1113
|
+
* The TXT record value used to check the domain.
|
|
1114
|
+
* @example ```"cl-verification=a6CDk5v"```
|
|
1115
|
+
*/
|
|
1116
|
+
txt_record: string;
|
|
1117
|
+
/**
|
|
1118
|
+
* The organization identifier for authorize params.
|
|
1119
|
+
* @example ```"org_76gsfs5gd"```
|
|
1120
|
+
*/
|
|
1121
|
+
organization?: Nullable<string>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Time at which this resource was disabled.
|
|
1124
|
+
* @example ```"2018-01-01T12:00:00.000Z"```
|
|
1125
|
+
*/
|
|
1126
|
+
disabled_at: string;
|
|
1127
|
+
user?: Nullable<User>;
|
|
1128
|
+
}
|
|
1129
|
+
interface IdentityProviderCreate extends ResourceCreate {
|
|
1130
|
+
/**
|
|
1131
|
+
* The name of the Identity provider.
|
|
1132
|
+
* @example ```"Org auth0"```
|
|
1133
|
+
*/
|
|
1134
|
+
name: string;
|
|
1135
|
+
/**
|
|
1136
|
+
* The client ID used for the auth workflow.
|
|
1137
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1138
|
+
*/
|
|
1139
|
+
client_id: string;
|
|
1140
|
+
/**
|
|
1141
|
+
* The client secret used for the auth workflow.
|
|
1142
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1143
|
+
*/
|
|
1144
|
+
client_secret: string;
|
|
1145
|
+
/**
|
|
1146
|
+
* The issuer used for the auth workflow.
|
|
1147
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1148
|
+
*/
|
|
1149
|
+
issuer: string;
|
|
1150
|
+
/**
|
|
1151
|
+
* The list of domains in scope (comma-separated).
|
|
1152
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1153
|
+
*/
|
|
1154
|
+
domains: string;
|
|
1155
|
+
/**
|
|
1156
|
+
* The token URL used for the auth workflow.
|
|
1157
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1158
|
+
*/
|
|
1159
|
+
token_url: string;
|
|
1160
|
+
/**
|
|
1161
|
+
* The authorize URL used for the auth workflow.
|
|
1162
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1163
|
+
*/
|
|
1164
|
+
authorize_url: string;
|
|
1165
|
+
/**
|
|
1166
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1167
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1168
|
+
*/
|
|
1169
|
+
jwks_url: string;
|
|
1170
|
+
/**
|
|
1171
|
+
* The organization identifier for authorize params.
|
|
1172
|
+
* @example ```"org_76gsfs5gd"```
|
|
1173
|
+
*/
|
|
1174
|
+
organization?: Nullable<string>;
|
|
1175
|
+
/**
|
|
1176
|
+
* Send this attribute if you want to mark this resource as disabled.
|
|
1177
|
+
* @example ```"true"```
|
|
1178
|
+
*/
|
|
1179
|
+
_disable?: Nullable<boolean>;
|
|
1180
|
+
/**
|
|
1181
|
+
* Send this attribute if you want to mark this resource as enabled.
|
|
1182
|
+
* @example ```"true"```
|
|
1183
|
+
*/
|
|
1184
|
+
_enable?: Nullable<boolean>;
|
|
1185
|
+
}
|
|
1186
|
+
interface IdentityProviderUpdate extends ResourceUpdate {
|
|
1187
|
+
/**
|
|
1188
|
+
* The name of the Identity provider.
|
|
1189
|
+
* @example ```"Org auth0"```
|
|
1190
|
+
*/
|
|
1191
|
+
name?: Nullable<string>;
|
|
1192
|
+
/**
|
|
1193
|
+
* The client ID used for the auth workflow.
|
|
1194
|
+
* @example ```"a6CDk5v1ZV99GrtOcfYVEZRnDDt"```
|
|
1195
|
+
*/
|
|
1196
|
+
client_id?: Nullable<string>;
|
|
1197
|
+
/**
|
|
1198
|
+
* The client secret used for the auth workflow.
|
|
1199
|
+
* @example ```"s6CD55v1ZV99ArtOcfYVEZRnDDf"```
|
|
1200
|
+
*/
|
|
1201
|
+
client_secret?: Nullable<string>;
|
|
1202
|
+
/**
|
|
1203
|
+
* The issuer used for the auth workflow.
|
|
1204
|
+
* @example ```"https://dev.auth987.com/"```
|
|
1205
|
+
*/
|
|
1206
|
+
issuer?: Nullable<string>;
|
|
1207
|
+
/**
|
|
1208
|
+
* The list of domains in scope (comma-separated).
|
|
1209
|
+
* @example ```"dev.auth987.com,stg.auth987.com"```
|
|
1210
|
+
*/
|
|
1211
|
+
domains?: Nullable<string>;
|
|
1212
|
+
/**
|
|
1213
|
+
* The token URL used for the auth workflow.
|
|
1214
|
+
* @example ```"https://dev.auth987.com/oauth/token"```
|
|
1215
|
+
*/
|
|
1216
|
+
token_url?: Nullable<string>;
|
|
1217
|
+
/**
|
|
1218
|
+
* The authorize URL used for the auth workflow.
|
|
1219
|
+
* @example ```"https://dev.auth987.com/authorize"```
|
|
1220
|
+
*/
|
|
1221
|
+
authorize_url?: Nullable<string>;
|
|
1222
|
+
/**
|
|
1223
|
+
* The JWKS key store URL used for the auth workflow.
|
|
1224
|
+
* @example ```"https://dev.auth987.com/.well-known/jwks.json"```
|
|
1225
|
+
*/
|
|
1226
|
+
jwks_url?: Nullable<string>;
|
|
1227
|
+
/**
|
|
1228
|
+
* The organization identifier for authorize params.
|
|
1229
|
+
* @example ```"org_76gsfs5gd"```
|
|
1230
|
+
*/
|
|
1231
|
+
organization?: Nullable<string>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Send this attribute if you want to mark this resource as disabled.
|
|
1234
|
+
* @example ```"true"```
|
|
1235
|
+
*/
|
|
1236
|
+
_disable?: Nullable<boolean>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Send this attribute if you want to mark this resource as enabled.
|
|
1239
|
+
* @example ```"true"```
|
|
1240
|
+
*/
|
|
1241
|
+
_enable?: Nullable<boolean>;
|
|
1242
|
+
}
|
|
1243
|
+
declare class IdentityProviders extends ApiResource<IdentityProvider> {
|
|
1244
|
+
static readonly TYPE: IdentityProviderType;
|
|
1245
|
+
create(resource: IdentityProviderCreate, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1246
|
+
update(resource: IdentityProviderUpdate, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1247
|
+
delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
|
|
1248
|
+
user(identityProviderId: string | IdentityProvider, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1249
|
+
_disable(id: string | IdentityProvider, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1250
|
+
_enable(id: string | IdentityProvider, params?: QueryParamsRetrieve<IdentityProvider>, options?: ResourcesConfig): Promise<IdentityProvider>;
|
|
1251
|
+
isIdentityProvider(resource: any): resource is IdentityProvider;
|
|
1252
|
+
relationship(id: string | ResourceId | null): IdentityProviderRel;
|
|
1253
|
+
relationshipToMany(...ids: string[]): IdentityProviderRel[];
|
|
1254
|
+
type(): IdentityProviderType;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'user' | 'versions';
|
|
1035
1258
|
declare const resourceList: ResourceTypeLock[];
|
|
1036
1259
|
declare const singletonList: ResourceTypeLock[];
|
|
1037
1260
|
type RetrievableResourceType = ResourceTypeLock;
|
|
@@ -1042,15 +1265,15 @@ type ListableResourceType = Exclude<ResourceTypeLock, 'user'>;
|
|
|
1042
1265
|
type ListableResource = Resource & {
|
|
1043
1266
|
type: ListableResourceType;
|
|
1044
1267
|
};
|
|
1045
|
-
type CreatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1268
|
+
type CreatableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1046
1269
|
type CreatableResource = Resource & {
|
|
1047
1270
|
type: CreatableResourceType;
|
|
1048
1271
|
};
|
|
1049
|
-
type UpdatableResourceType = 'api_credentials' | 'application_memberships' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1272
|
+
type UpdatableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles';
|
|
1050
1273
|
type UpdatableResource = Resource & {
|
|
1051
1274
|
type: UpdatableResourceType;
|
|
1052
1275
|
};
|
|
1053
|
-
type DeletableResourceType = 'api_credentials' | 'application_memberships' | 'memberships';
|
|
1276
|
+
type DeletableResourceType = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships';
|
|
1054
1277
|
type DeletableResource = Resource & {
|
|
1055
1278
|
type: DeletableResourceType;
|
|
1056
1279
|
};
|
|
@@ -1064,6 +1287,7 @@ type VersionableResource = Resource & {
|
|
|
1064
1287
|
type ResourceFields = {
|
|
1065
1288
|
api_credentials: ApiCredential;
|
|
1066
1289
|
application_memberships: ApplicationMembership;
|
|
1290
|
+
identity_providers: IdentityProvider;
|
|
1067
1291
|
memberships: Membership;
|
|
1068
1292
|
organizations: Organization;
|
|
1069
1293
|
permissions: Permission;
|
|
@@ -1074,6 +1298,7 @@ type ResourceFields = {
|
|
|
1074
1298
|
type ResourceSortFields = {
|
|
1075
1299
|
api_credentials: ApiCredentialSort;
|
|
1076
1300
|
application_memberships: ApplicationMembershipSort;
|
|
1301
|
+
identity_providers: IdentityProviderSort;
|
|
1077
1302
|
memberships: MembershipSort;
|
|
1078
1303
|
organizations: OrganizationSort;
|
|
1079
1304
|
permissions: PermissionSort;
|
|
@@ -1117,10 +1342,11 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1117
1342
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1118
1343
|
declare class CommerceLayerProvisioningClient {
|
|
1119
1344
|
#private;
|
|
1120
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1345
|
+
readonly openApiSchemaVersion = "1.0.6";
|
|
1121
1346
|
constructor(config: CommerceLayerInitConfig);
|
|
1122
1347
|
get api_credentials(): ApiCredentials;
|
|
1123
1348
|
get application_memberships(): ApplicationMemberships;
|
|
1349
|
+
get identity_providers(): IdentityProviders;
|
|
1124
1350
|
get memberships(): Memberships;
|
|
1125
1351
|
get organizations(): Organizations;
|
|
1126
1352
|
get permissions(): Permissions;
|
|
@@ -1156,4 +1382,4 @@ declare const CommerceLayerProvisioningStatic: {
|
|
|
1156
1382
|
readonly schemaVersion: string;
|
|
1157
1383
|
};
|
|
1158
1384
|
|
|
1159
|
-
export { type ApiCredential, type ApiCredentialCreate, type ApiCredentialSort, type ApiCredentialUpdate, ApiCredentials, ApiError, ApiResource, ApiSingleton, type ApplicationMembership, type ApplicationMembershipCreate, type ApplicationMembershipSort, type ApplicationMembershipUpdate, ApplicationMemberships, type CommerceLayerConfig, type CommerceLayerInitConfig, CommerceLayerProvisioning, CommerceLayerProvisioningClient, CommerceLayerProvisioningStatic, type CreatableResource, type CreatableResourceType, type DeletableResource, type DeletableResourceType, type ErrorObj, ErrorType, type HeadersObj, type ListMeta, ListResponse, type ListableResource, type ListableResourceType, type Membership, type MembershipCreate, type MembershipSort, type MembershipUpdate, Memberships, type Metadata, type Organization, type OrganizationCreate, type OrganizationSort, type OrganizationUpdate, Organizations, type Permission, type PermissionCreate, type PermissionSort, type PermissionUpdate, Permissions, type QueryArrayFields, type QueryArraySortable, type QueryFilter, type QueryInclude, type QueryPageNumber, type QueryPageSize, type QueryParams, type QueryParamsList, type QueryParamsRetrieve, type QueryRecordFields, type QueryRecordSortable, type RequestObj, type Resource, type ResourceCreate, type ResourceFields, type ResourceFilter, type ResourceId, type ResourceRel, type ResourceSort, type ResourceSortFields, type ResourceType, type ResourceTypeLock, type ResourceUpdate, type ResourcesConfig, type ResourcesInitConfig, type ResponseObj, type RetrievableResource, type RetrievableResourceType, type Role, type RoleCreate, type RoleSort, type RoleUpdate, Roles, SdkError, type UpdatableResource, type UpdatableResourceType, type User, type UserSort, type UserUpdate, Users, type Version, type VersionSort, type VersionableResource, type VersionableResourceType, Versions, apiResourceAdapter, CommerceLayerProvisioning as default, generateQueryStringParams, generateSearchString, isParamsList, resourceList, singletonList };
|
|
1385
|
+
export { type ApiCredential, type ApiCredentialCreate, type ApiCredentialSort, type ApiCredentialUpdate, ApiCredentials, ApiError, ApiResource, ApiSingleton, type ApplicationMembership, type ApplicationMembershipCreate, type ApplicationMembershipSort, type ApplicationMembershipUpdate, ApplicationMemberships, type CommerceLayerConfig, type CommerceLayerInitConfig, CommerceLayerProvisioning, CommerceLayerProvisioningClient, CommerceLayerProvisioningStatic, type CreatableResource, type CreatableResourceType, type DeletableResource, type DeletableResourceType, type ErrorObj, ErrorType, type HeadersObj, type IdentityProvider, type IdentityProviderCreate, type IdentityProviderSort, type IdentityProviderUpdate, IdentityProviders, type ListMeta, ListResponse, type ListableResource, type ListableResourceType, type Membership, type MembershipCreate, type MembershipSort, type MembershipUpdate, Memberships, type Metadata, type Organization, type OrganizationCreate, type OrganizationSort, type OrganizationUpdate, Organizations, type Permission, type PermissionCreate, type PermissionSort, type PermissionUpdate, Permissions, type QueryArrayFields, type QueryArraySortable, type QueryFilter, type QueryInclude, type QueryPageNumber, type QueryPageSize, type QueryParams, type QueryParamsList, type QueryParamsRetrieve, type QueryRecordFields, type QueryRecordSortable, type RequestObj, type Resource, type ResourceCreate, type ResourceFields, type ResourceFilter, type ResourceId, type ResourceRel, type ResourceSort, type ResourceSortFields, type ResourceType, type ResourceTypeLock, type ResourceUpdate, type ResourcesConfig, type ResourcesInitConfig, type ResponseObj, type RetrievableResource, type RetrievableResourceType, type Role, type RoleCreate, type RoleSort, type RoleUpdate, Roles, SdkError, type SingletonUpdate, type UpdatableResource, type UpdatableResourceType, type User, type UserSort, type UserUpdate, Users, type Version, type VersionSort, type VersionableResource, type VersionableResourceType, Versions, apiResourceAdapter, CommerceLayerProvisioning as default, generateQueryStringParams, generateSearchString, isParamsList, resourceList, singletonList };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var de=Object.defineProperty;var or=Object.getOwnPropertyDescriptor;var nr=Object.getOwnPropertyNames;var ar=Object.prototype.hasOwnProperty;var Je=t=>{throw TypeError(t)};var pr=(t,e)=>{for(var r in e)de(t,r,{get:e[r],enumerable:!0})},cr=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of nr(e))!ar.call(t,i)&&i!==r&&de(t,i,{get:()=>e[i],enumerable:!(s=or(e,i))||s.enumerable});return t};var ur=t=>cr(de({},"__esModule",{value:!0}),t);var We=(t,e,r)=>e.has(t)||Je("Cannot "+r);var n=(t,e,r)=>(We(t,e,"read from private field"),r?r.call(t):e.get(t)),u=(t,e,r)=>e.has(t)?Je("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),c=(t,e,r,s)=>(We(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var Cr={};pr(Cr,{CommerceLayerProvisioning:()=>De,CommerceLayerProvisioningStatic:()=>P,default:()=>ue});module.exports=ur(Cr);var lr=(t,...e)=>{},Be=t=>lr;try{let t=require("debug");t&&typeof t=="function"&&(Be=t)}catch{}var mr="clsdk",yr=t=>Be(`${mr}:${t}`),h=yr;var ge=h("fetch"),V,D,Y,oe=class oe extends Error{constructor(r,s,i){super(s);u(this,V);u(this,D);u(this,Y);c(this,D,r),c(this,Y,s),i&&c(this,V,i.errors)}get errors(){return n(this,V)}get status(){return n(this,D)}get statusText(){return n(this,Y)}};V=new WeakMap,D=new WeakMap,Y=new WeakMap,oe.isFetchError=r=>r instanceof oe;var $=oe,he=async(t,e,r)=>{ge("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(ge("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(ge("error: %s",a.message),o.ok)throw new m({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new $(o.status,o.statusText,p);if(s?.response?.onFailure&&(a=await s.response.onFailure(a)),a)throw a}return p};var w=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(w||{}),H=class H extends Error{static isSdkError(e){return e&&[H.NAME,O.NAME].includes(e.name)&&Object.values(w).includes(e.type)}constructor(e){super(e.message),this.name=H.NAME,this.type=e.type||"client"}};H.NAME="SdkError";var m=H,J=class J extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=J.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===J.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};J.NAME="ApiError";var O=J,Rr=t=>t instanceof TypeError,dr=t=>t instanceof DOMException&&t.name==="AbortError",gr=t=>t instanceof DOMException&&t.name==="TimeoutError",Ke=t=>O.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),fe=t=>{if(m.isSdkError(t)||O.isApiError(t))throw t;let e=new m({message:t.message});if($.isFetchError(t)){let r=new O(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else Rr(t)?e.type="request":dr(t)?e.type="cancel":gr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var hr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=hr;var Ge=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var T=h("client"),be=t=>`https://provisioning.${t||f.default.domain}/api`,I,b,d,W,Ce=class Ce{constructor(e){u(this,I);u(this,b);u(this,d);u(this,W);T("new client instance %O",e),c(this,I,be(e.domain)),c(this,b,e.accessToken);let r={timeout:e.timeout||f.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,b)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,d,r),T("fetch config: %O",r),c(this,W,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Ce(e)}get interceptors(){return n(this,W)}get requestHeaders(){return n(this,d).headers||(n(this,d).headers={}),n(this,d).headers}config(e){T("config %o",e);let r=n(this,d);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,d).fetch=e.fetch),e.refreshToken&&(n(this,d).refreshToken=e.refreshToken),e.domain&&c(this,I,be(e.domain)),e.accessToken&&(c(this,b,e.accessToken),r.headers.Authorization="Bearer "+n(this,b)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){T("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&T("User-Agent header ignored in request config");let o=i?.domain?be(i.domain):n(this,I),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,C={...this.requestHeaders,...this.customHeaders(i?.headers)},M=i?.accessToken||n(this,b);M&&(C.Authorization="Bearer "+M);let L={method:e,body:a,headers:C},Ye=i?.timeout||n(this,d).timeout;Ye&&(AbortSignal?.timeout?L.signal=AbortSignal.timeout(Ye):T("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([k,F])=>{p.searchParams.append(k,String(F))});let He={interceptors:this.interceptors,fetch:i?.fetch||n(this,d).fetch};try{return await he(p,L,He).catch(k=>fe(k))}catch(k){if(Ke(k)&&n(this,d).refreshToken&&Ge(n(this,b))){T("Access token has expired");let F=await n(this,d).refreshToken(n(this,b)).catch(Re=>{T("Refresh token error: %s",Re.message);let ie=new m({message:"Error refreshing access token",type:"token-refresh"});throw ie.source=Re,ie});if(F)return T("Access token refreshed"),this.config({accessToken:F}),L.headers&&(L.headers.Authorization=`Bearer ${F}`),await he(p,L,He).catch(ie=>fe(ie))}else throw k}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,b)}};I=new WeakMap,b=new WeakMap,d=new WeakMap,W=new WeakMap;var Pe=Ce,Ze=Pe;var Q=t=>t?.type&&t.id&&U.includes(t.type),Te=t=>t&&typeof t.type<"u"&&t.type&&U.includes(t.type);var ne=h("jsonapi"),z=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>ae(i,s)):e=ae(r,s):e=r,e},Xe=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,ae=(t,e,r=[])=>{if(ne("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>ae(Xe(p,e),e,[...r,p])):s[i]=ae(Xe(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ne("denormalized resource: %O",s),s},pe=t=>{ne("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Te(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Te(o)&&o.id===null?r[i]={data:null}:o&&(Q(o)||Array.isArray(o)&&Q(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return Q(t)&&(s.id=t.id),ne("normalized resource: %O",s),s};var er=h("query"),rr=["_any","_all","_in","_not_in_or_null"],fr=t=>rr.some(e=>t.endsWith(e)),sr=["_jcont"],br=t=>sr.some(e=>t.endsWith(e)),Ae=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),j=(t,e)=>{er("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),Ae(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!fr(s))throw new m({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${rr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!br(s))throw new m({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${sr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),er("query string params: %O",r)),r};var P={resources:t=>t?[...U].sort():U,singletons:t=>t?[...ce].sort():ce,isSingleton:t=>ce.includes(t),isSdkError:t=>m.isSdkError(t),isApiError:t=>O.isApiError(t),init:t=>ue(t),get schemaVersion(){return Oe}};var A=h("resource"),le=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var g,_e,xe=class{constructor(e){u(this,g);u(this,_e,{});c(this,g,Ze.create(e)),this.localConfig(e)}localConfig(e){}config(e){return A("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=j(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,C=await n(this,g).request("GET",a,void 0,{...s,params:p});return z(C)}async list(e,r,s){A("list: %o, %O, %O",e,r||{},s||{});let i=j(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...s,params:i}),p=z(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||f.default.pageNumber,recordsPerPage:r?.pageSize||f.default.pageSize};return new le(a,p)}async create(e,r,s){A("create: %o, %O, %O",e,r||{},s||{});let i=j(r,e);s?.params&&Object.assign(i,s?.params);let o=pe(e),p=await n(this,g).request("POST",e.type,o,{...s,params:i});return z(p)}async update(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=j(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,C=pe(e),M=await n(this,g).request("PATCH",a,C,{...s,params:p});return z(M)}async delete(e,r){A("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){A("fetch: %o, %O, %O",r,s||{},i||{});let o=j(s,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,g).request("GET",r,void 0,{...i,params:o}),a=z(p);if(Array.isArray(a)){let C=s,M={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:C?.pageNumber||f.default.pageNumber,recordsPerPage:C?.pageSize||f.default.pageSize};return new le(M,a)}else return a}async action(e,r,s,i){A("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&Q(s)?pe(s):s;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,_e=new WeakMap;var me=class{constructor(e){A("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return z(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},y=class extends me{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:Ae(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ye=class extends me{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},tr=xe;var x=class x extends y{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ee=x,Me=Ee;var _=class _ extends y{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="application_memberships";var ze=_,Ne=ze;var E=class E extends y{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="memberships";var Se=E,ve=Se;var N=class N extends y{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="organizations";var Le=N,ke=Le;var S=class S extends y{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="permissions";var we=S,Ie=we;var v=class v extends y{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="roles";var Qe=v,Ue=Qe;var q=class q extends ye{async update(e,r,s){let i=e.id||(await this.retrieve()).id;return this.resources.update({...e,id:i,type:q.TYPE},r,s)}isUser(e){return e.type&&e.type===q.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return q.TYPE}path(){return"user"}};q.TYPE="user";var je=q,qe=je;var B=class B extends y{isVersion(e){return e.type&&e.type===B.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return B.TYPE}};B.TYPE="versions";var Fe=B,$e=Fe;var U=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],ce=["user"];var ir=h("commercelayer"),Oe="1.0.5";var R,K,G,Z,X,ee,re,se,te,Ve=class{constructor(e){this.openApiSchemaVersion=Oe;u(this,R);u(this,K);u(this,G);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,se);u(this,te);ir("new commercelayer provisioning instance %O",e),c(this,R,new tr(e))}get api_credentials(){return n(this,K)||c(this,K,new Me(n(this,R)))}get application_memberships(){return n(this,G)||c(this,G,new Ne(n(this,R)))}get memberships(){return n(this,Z)||c(this,Z,new ve(n(this,R)))}get organizations(){return n(this,X)||c(this,X,new ke(n(this,R)))}get permissions(){return n(this,ee)||c(this,ee,new Ie(n(this,R)))}get roles(){return n(this,re)||c(this,re,new Ue(n(this,R)))}get user(){return n(this,se)||c(this,se,new qe(n(this,R)))}get versions(){return n(this,te)||c(this,te,new $e(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ir("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return P.resources()}singletons(){return P.singletons()}isSingleton(e){return P.isSingleton(e)}isApiError(e){return P.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,K=new WeakMap,G=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap;var De=t=>new Ve(t),ue=De;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
|
1
|
+
"use strict";var he=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var Ge=s=>{throw TypeError(s)};var mr=(s,e)=>{for(var r in e)he(s,r,{get:e[r],enumerable:!0})},yr=(s,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ur(e))!lr.call(s,i)&&i!==r&&he(s,i,{get:()=>e[i],enumerable:!(t=cr(e,i))||t.enumerable});return s};var dr=s=>yr(he({},"__esModule",{value:!0}),s);var Ze=(s,e,r)=>e.has(s)||Ge("Cannot "+r);var n=(s,e,r)=>(Ze(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ge("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ze(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var Or={};mr(Or,{CommerceLayerProvisioning:()=>We,CommerceLayerProvisioningStatic:()=>P,default:()=>me});module.exports=dr(Or);var Rr=(s,...e)=>{},Xe=s=>Rr;try{let s=require("debug");s&&typeof s=="function"&&(Xe=s)}catch{}var gr="clsdk",hr=s=>Xe(`${gr}:${s}`),h=hr;var fe=h("fetch"),D,Y,H,ae=class ae extends Error{constructor(r,t,i){super(t);u(this,D);u(this,Y);u(this,H);c(this,Y,r),c(this,H,t),i&&c(this,D,i.errors)}get errors(){return n(this,D)}get status(){return n(this,Y)}get statusText(){return n(this,H)}};D=new WeakMap,Y=new WeakMap,H=new WeakMap,ae.isFetchError=r=>r instanceof ae;var V=ae,be=async(s,e,r)=>{fe("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("error: %s",a.message),o.ok)throw new m({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new V(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var w=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(w||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,O.NAME].includes(e.name)&&Object.values(w).includes(e.type)}constructor(e){super(e.message),this.name=J.NAME,this.type=e.type||"client"}};J.NAME="SdkError";var m=J,W=class W extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=W.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===W.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};W.NAME="ApiError";var O=W,fr=s=>s instanceof TypeError,br=s=>s instanceof DOMException&&s.name==="AbortError",Pr=s=>s instanceof DOMException&&s.name==="TimeoutError",er=s=>O.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),Pe=s=>{if(m.isSdkError(s)||O.isApiError(s))throw s;let e=new m({message:s.message});if(V.isFetchError(s)){let r=new O(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else fr(s)?e.type="request":br(s)?e.type="cancel":Pr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var Cr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Cr;var rr=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=h("client"),Ce=s=>`https://provisioning.${s||f.default.domain}/api`,U,b,R,B,Ae=class Ae{constructor(e){u(this,U);u(this,b);u(this,R);u(this,B);A("new client instance %O",e),c(this,U,Ce(e.domain)),c(this,b,e.accessToken);let r={timeout:e.timeout||f.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,b)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,R,r),A("fetch config: %O",r),c(this,B,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){A("config %o",e);let r=n(this,R);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,R).fetch=e.fetch),e.refreshToken&&(n(this,R).refreshToken=e.refreshToken),e.domain&&c(this,U,Ce(e.domain)),e.accessToken&&(c(this,b,e.accessToken),r.headers.Authorization="Bearer "+n(this,b)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Ce(i.domain):n(this,U),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,b);I&&(T.Authorization="Bearer "+I);let k={method:e,body:a,headers:T},Be=i?.timeout||n(this,R).timeout;Be&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(Be):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,F])=>{p.searchParams.append(L,String(F))});let Ke={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await be(p,k,Ke).catch(L=>Pe(L))}catch(L){if(er(L)&&n(this,R).refreshToken&&rr(n(this,b))){A("Access token has expired");let F=await n(this,R).refreshToken(n(this,b)).catch(ge=>{A("Refresh token error: %s",ge.message);let ne=new m({message:"Error refreshing access token",type:"token-refresh"});throw ne.source=ge,ne});if(F)return A("Access token refreshed"),this.config({accessToken:F}),k.headers&&(k.headers.Authorization=`Bearer ${F}`),await be(p,k,Ke).catch(ne=>Pe(ne))}else throw L}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,b)}};U=new WeakMap,b=new WeakMap,R=new WeakMap,B=new WeakMap;var Te=Ae,tr=Te;var Q=s=>s?.type&&s.id&&j.includes(s.type),_e=s=>s&&typeof s.type<"u"&&s.type&&j.includes(s.type);var pe=h("jsonapi"),z=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ce(i,t)):e=ce(r,t):e=r,e},sr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ce=(s,e,r=[])=>{if(pe("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ce(sr(p,e),e,[...r,p])):t[i]=ce(sr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),pe("denormalized resource: %O",t),t},ue=s=>{pe("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&_e(o[0])&&o[0].id===null?r[i]={data:[]}:o&&_e(o)&&o.id===null?r[i]={data:null}:o&&(Q(o)||Array.isArray(o)&&Q(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return Q(s)&&(t.id=s.id),pe("normalized resource: %O",t),t};var ir=h("query"),or=["_any","_all","_in","_not_in_or_null"],Tr=s=>or.some(e=>s.endsWith(e)),nr=["_jcont"],Ar=s=>nr.some(e=>s.endsWith(e)),Oe=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),q=(s,e)=>{ir("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),Oe(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!Tr(t))throw new m({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Ar(t))throw new m({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${nr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),ir("query string params: %O",r)),r};var P={resources:s=>s?[...j].sort():j,singletons:s=>s?[...le].sort():le,isSingleton:s=>le.includes(s),isSdkError:s=>m.isSdkError(s),isApiError:s=>O.isApiError(s),init:s=>me(s),get schemaVersion(){return ve}};var _=h("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var g,Ee,xe=class{constructor(e){u(this,g);u(this,Ee,{});c(this,g,tr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return _("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,g).request("GET",a,void 0,{...t,params:p});return z(T)}async list(e,r,t){_("list: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...t,params:i}),p=z(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||f.default.pageNumber,recordsPerPage:r?.pageSize||f.default.pageSize};return new ye(a,p)}async create(e,r,t){_("create: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=ue(e),p=await n(this,g).request("POST",e.type,o,{...t,params:i});return z(p)}async update(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ue(e),I=await n(this,g).request("PATCH",a,T,{...t,params:p});return z(I)}async delete(e,r){_("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){_("fetch: %o, %O, %O",r,t||{},i||{});let o=q(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,g).request("GET",r,void 0,{...i,params:o}),a=z(p);if(Array.isArray(a)){let T=t,I={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ye(I,a)}else return a}async action(e,r,t,i){_("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&Q(t)?ue(t):t;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){_("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return z(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},y=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},ar=xe;var v=class v extends y{async create(e,r,t){return this.resources.create({...e,type:v.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:v.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="api_credentials";var Ie=v,ze=Ie;var x=class x extends y{async create(e,r,t){return this.resources.create({...e,type:x.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:x.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="application_memberships";var Me=x,Ne=Me;var C=class C extends y{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"user"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var E=class E extends y{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="memberships";var Le=E,we=Le;var M=class M extends y{async create(e,r,t){return this.resources.create({...e,type:M.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:M.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===M.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return M.TYPE}};M.TYPE="organizations";var Ue=M,Qe=Ue;var N=class N extends y{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="permissions";var je=N,qe=je;var S=class S extends y{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="roles";var $e=S,Fe=$e;var $=class $ extends Re{async update(e,r,t){return this.resources.update({...e,type:$.TYPE},r,t)}async identity_providers(e,r,t){let i=e.id||e;return this.resources.fetch({type:"identity_providers"},`user/${i}/identity_providers`,r,t)}isUser(e){return e.type&&e.type===$.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return $.TYPE}path(){return"user"}};$.TYPE="user";var Ve=$,De=Ve;var K=class K extends y{isVersion(e){return e.type&&e.type===K.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return K.TYPE}};K.TYPE="versions";var Ye=K,He=Ye;var j=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","user","versions"],le=["user"];var pr=h("commercelayer"),ve="1.0.6";var d,G,Z,X,ee,re,te,se,ie,oe,Je=class{constructor(e){this.openApiSchemaVersion=ve;u(this,d);u(this,G);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);pr("new commercelayer provisioning instance %O",e),c(this,d,new ar(e))}get api_credentials(){return n(this,G)||c(this,G,new ze(n(this,d)))}get application_memberships(){return n(this,Z)||c(this,Z,new Ne(n(this,d)))}get identity_providers(){return n(this,X)||c(this,X,new ke(n(this,d)))}get memberships(){return n(this,ee)||c(this,ee,new we(n(this,d)))}get organizations(){return n(this,re)||c(this,re,new Qe(n(this,d)))}get permissions(){return n(this,te)||c(this,te,new qe(n(this,d)))}get roles(){return n(this,se)||c(this,se,new Fe(n(this,d)))}get user(){return n(this,ie)||c(this,ie,new De(n(this,d)))}get versions(){return n(this,oe)||c(this,oe,new He(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return pr("config %o",e),this.localConfig(e),n(this,d).config(e),this}resources(){return P.resources()}singletons(){return P.singletons()}isSingleton(e){return P.isSingleton(e)}isApiError(e){return P.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,G=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap;var We=s=>new Je(s),me=We;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var He=t=>{throw TypeError(t)};var or=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Je=(t,e,r)=>e.has(t)||He("Cannot "+r);var n=(t,e,r)=>(Je(t,e,"read from private field"),r?r.call(t):e.get(t)),u=(t,e,r)=>e.has(t)?He("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),c=(t,e,r,s)=>(Je(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var nr=(t,...e)=>{},We=t=>nr;try{let t=or("debug");t&&typeof t=="function"&&(We=t)}catch{}var ar="clsdk",pr=t=>We(`${ar}:${t}`),f=pr;var de=f("fetch"),D,Y,H,ne=class ne extends Error{constructor(r,s,i){super(s);u(this,D);u(this,Y);u(this,H);c(this,Y,r),c(this,H,s),i&&c(this,D,i.errors)}get errors(){return n(this,D)}get status(){return n(this,Y)}get statusText(){return n(this,H)}};D=new WeakMap,Y=new WeakMap,H=new WeakMap,ne.isFetchError=r=>r instanceof ne;var V=ne,ge=async(t,e,r)=>{de("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(de("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(de("error: %s",a.message),o.ok)throw new y({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new V(o.status,o.statusText,p);if(s?.response?.onFailure&&(a=await s.response.onFailure(a)),a)throw a}return p};var I=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(I||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,x.NAME].includes(e.name)&&Object.values(I).includes(e.type)}constructor(e){super(e.message),this.name=J.NAME,this.type=e.type||"client"}};J.NAME="SdkError";var y=J,W=class W extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=W.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===W.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};W.NAME="ApiError";var x=W,cr=t=>t instanceof TypeError,ur=t=>t instanceof DOMException&&t.name==="AbortError",lr=t=>t instanceof DOMException&&t.name==="TimeoutError",Be=t=>x.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),he=t=>{if(y.isSdkError(t)||x.isApiError(t))throw t;let e=new y({message:t.message});if(V.isFetchError(t)){let r=new x(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else cr(t)?e.type="request":ur(t)?e.type="cancel":lr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var mr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=mr;var Ke=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var T=f("client"),fe=t=>`https://provisioning.${t||b.default.domain}/api`,Q,P,g,B,Pe=class Pe{constructor(e){u(this,Q);u(this,P);u(this,g);u(this,B);T("new client instance %O",e),c(this,Q,fe(e.domain)),c(this,P,e.accessToken);let r={timeout:e.timeout||b.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,g,r),T("fetch config: %O",r),c(this,B,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Pe(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){T("config %o",e);let r=n(this,g);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,g).fetch=e.fetch),e.refreshToken&&(n(this,g).refreshToken=e.refreshToken),e.domain&&c(this,Q,fe(e.domain)),e.accessToken&&(c(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){T("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&T("User-Agent header ignored in request config");let o=i?.domain?fe(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,C={...this.requestHeaders,...this.customHeaders(i?.headers)},z=i?.accessToken||n(this,P);z&&(C.Authorization="Bearer "+z);let k={method:e,body:a,headers:C},De=i?.timeout||n(this,g).timeout;De&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(De):T("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,$])=>{p.searchParams.append(w,String($))});let Ye={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await ge(p,k,Ye).catch(w=>he(w))}catch(w){if(Be(w)&&n(this,g).refreshToken&&Ke(n(this,P))){T("Access token has expired");let $=await n(this,g).refreshToken(n(this,P)).catch(Re=>{T("Refresh token error: %s",Re.message);let oe=new y({message:"Error refreshing access token",type:"token-refresh"});throw oe.source=Re,oe});if($)return T("Access token refreshed"),this.config({accessToken:$}),k.headers&&(k.headers.Authorization=`Bearer ${$}`),await ge(p,k,Ye).catch(oe=>he(oe))}else throw w}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,P)}};Q=new WeakMap,P=new WeakMap,g=new WeakMap,B=new WeakMap;var be=Pe,Ge=be;var U=t=>t?.type&&t.id&&j.includes(t.type),Ce=t=>t&&typeof t.type<"u"&&t.type&&j.includes(t.type);var ae=f("jsonapi"),N=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>pe(i,s)):e=pe(r,s):e=r,e},Ze=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,pe=(t,e,r=[])=>{if(ae("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>pe(Ze(p,e),e,[...r,p])):s[i]=pe(Ze(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ae("denormalized resource: %O",s),s},ce=t=>{ae("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Ce(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ce(o)&&o.id===null?r[i]={data:null}:o&&(U(o)||Array.isArray(o)&&U(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return U(t)&&(s.id=t.id),ae("normalized resource: %O",s),s};var Xe=f("query"),er=["_any","_all","_in","_not_in_or_null"],yr=t=>er.some(e=>t.endsWith(e)),rr=["_jcont"],Rr=t=>rr.some(e=>t.endsWith(e)),Te=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),q=(t,e)=>{Xe("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),Te(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!yr(s))throw new y({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${er.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Rr(s))throw new y({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${rr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),Xe("query string params: %O",r)),r};var A={resources:t=>t?[...j].sort():j,singletons:t=>t?[...ue].sort():ue,isSingleton:t=>ue.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>x.isApiError(t),init:t=>Oe(t),get schemaVersion(){return Ae}};var O=f("resource"),le=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var h,_e,xe=class{constructor(e){u(this,h);u(this,_e,{});c(this,h,Ge.create(e)),this.localConfig(e)}localConfig(e){}config(e){return O("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=q(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,C=await n(this,h).request("GET",a,void 0,{...s,params:p});return N(C)}async list(e,r,s){O("list: %o, %O, %O",e,r||{},s||{});let i=q(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...s,params:i}),p=N(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||b.default.pageNumber,recordsPerPage:r?.pageSize||b.default.pageSize};return new le(a,p)}async create(e,r,s){O("create: %o, %O, %O",e,r||{},s||{});let i=q(r,e);s?.params&&Object.assign(i,s?.params);let o=ce(e),p=await n(this,h).request("POST",e.type,o,{...s,params:i});return N(p)}async update(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=q(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,C=ce(e),z=await n(this,h).request("PATCH",a,C,{...s,params:p});return N(z)}async delete(e,r){O("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){O("fetch: %o, %O, %O",r,s||{},i||{});let o=q(s,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=N(p);if(Array.isArray(a)){let C=s,z={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:C?.pageNumber||b.default.pageNumber,recordsPerPage:C?.pageSize||b.default.pageSize};return new le(z,a)}else return a}async action(e,r,s,i){O("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&U(s)?ce(s):s;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,_e=new WeakMap;var me=class{constructor(e){O("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new y({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return N(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},R=class extends me{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:Te(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ye=class extends me{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},sr=xe;var _=class _ extends R{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="api_credentials";var Ee=_,Me=Ee;var E=class E extends R{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="application_memberships";var ze=E,Ne=ze;var M=class M extends R{async create(e,r,s){return this.resources.create({...e,type:M.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:M.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:M.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===M.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return M.TYPE}};M.TYPE="memberships";var Se=M,ve=Se;var S=class S extends R{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="organizations";var Le=S,ke=Le;var v=class v extends R{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="permissions";var we=v,Ie=we;var L=class L extends R{async create(e,r,s){return this.resources.create({...e,type:L.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:L.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===L.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return L.TYPE}};L.TYPE="roles";var Qe=L,Ue=Qe;var F=class F extends ye{async update(e,r,s){let i=e.id||(await this.retrieve()).id;return this.resources.update({...e,id:i,type:F.TYPE},r,s)}isUser(e){return e.type&&e.type===F.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return F.TYPE}path(){return"user"}};F.TYPE="user";var je=F,qe=je;var K=class K extends R{isVersion(e){return e.type&&e.type===K.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return K.TYPE}};K.TYPE="versions";var Fe=K,$e=Fe;var j=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],ue=["user"];var tr=f("commercelayer"),Ae="1.0.5";var d,G,Z,X,ee,re,se,te,ie,Ve=class{constructor(e){this.openApiSchemaVersion=Ae;u(this,d);u(this,G);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,se);u(this,te);u(this,ie);tr("new commercelayer provisioning instance %O",e),c(this,d,new sr(e))}get api_credentials(){return n(this,G)||c(this,G,new Me(n(this,d)))}get application_memberships(){return n(this,Z)||c(this,Z,new Ne(n(this,d)))}get memberships(){return n(this,X)||c(this,X,new ve(n(this,d)))}get organizations(){return n(this,ee)||c(this,ee,new ke(n(this,d)))}get permissions(){return n(this,re)||c(this,re,new Ie(n(this,d)))}get roles(){return n(this,se)||c(this,se,new Ue(n(this,d)))}get user(){return n(this,te)||c(this,te,new qe(n(this,d)))}get versions(){return n(this,ie)||c(this,ie,new $e(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return tr("config %o",e),this.localConfig(e),n(this,d).config(e),this}resources(){return A.resources()}singletons(){return A.singletons()}isSingleton(e){return A.isSingleton(e)}isApiError(e){return A.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,G=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap;var ir=t=>new Ve(t),Oe=ir;export{ir as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,Oe as default};
|
|
1
|
+
var Ke=s=>{throw TypeError(s)};var cr=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ge=(s,e,r)=>e.has(s)||Ke("Cannot "+r);var n=(s,e,r)=>(Ge(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ge(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var ur=(s,...e)=>{},Ze=s=>ur;try{let s=cr("debug");s&&typeof s=="function"&&(Ze=s)}catch{}var lr="clsdk",mr=s=>Ze(`${lr}:${s}`),f=mr;var he=f("fetch"),Y,H,J,pe=class pe extends Error{constructor(r,t,i){super(t);u(this,Y);u(this,H);u(this,J);c(this,H,r),c(this,J,t),i&&c(this,Y,i.errors)}get errors(){return n(this,Y)}get status(){return n(this,H)}get statusText(){return n(this,J)}};Y=new WeakMap,H=new WeakMap,J=new WeakMap,pe.isFetchError=r=>r instanceof pe;var D=pe,fe=async(s,e,r)=>{he("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(he("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(he("error: %s",a.message),o.ok)throw new y({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new D(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var U=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(U||{}),W=class W extends Error{static isSdkError(e){return e&&[W.NAME,v.NAME].includes(e.name)&&Object.values(U).includes(e.type)}constructor(e){super(e.message),this.name=W.NAME,this.type=e.type||"client"}};W.NAME="SdkError";var y=W,B=class B extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=B.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===B.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};B.NAME="ApiError";var v=B,yr=s=>s instanceof TypeError,dr=s=>s instanceof DOMException&&s.name==="AbortError",Rr=s=>s instanceof DOMException&&s.name==="TimeoutError",Xe=s=>v.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),be=s=>{if(y.isSdkError(s)||v.isApiError(s))throw s;let e=new y({message:s.message});if(D.isFetchError(s)){let r=new v(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else yr(s)?e.type="request":dr(s)?e.type="cancel":Rr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var gr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=gr;var er=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=f("client"),Pe=s=>`https://provisioning.${s||b.default.domain}/api`,Q,P,g,K,Te=class Te{constructor(e){u(this,Q);u(this,P);u(this,g);u(this,K);A("new client instance %O",e),c(this,Q,Pe(e.domain)),c(this,P,e.accessToken);let r={timeout:e.timeout||b.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,g,r),A("fetch config: %O",r),c(this,K,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Te(e)}get interceptors(){return n(this,K)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){A("config %o",e);let r=n(this,g);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,g).fetch=e.fetch),e.refreshToken&&(n(this,g).refreshToken=e.refreshToken),e.domain&&c(this,Q,Pe(e.domain)),e.accessToken&&(c(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Pe(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},z=i?.accessToken||n(this,P);z&&(T.Authorization="Bearer "+z);let L={method:e,body:a,headers:T},We=i?.timeout||n(this,g).timeout;We&&(AbortSignal?.timeout?L.signal=AbortSignal.timeout(We):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,V])=>{p.searchParams.append(w,String(V))});let Be={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await fe(p,L,Be).catch(w=>be(w))}catch(w){if(Xe(w)&&n(this,g).refreshToken&&er(n(this,P))){A("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(ge=>{A("Refresh token error: %s",ge.message);let ae=new y({message:"Error refreshing access token",type:"token-refresh"});throw ae.source=ge,ae});if(V)return A("Access token refreshed"),this.config({accessToken:V}),L.headers&&(L.headers.Authorization=`Bearer ${V}`),await fe(p,L,Be).catch(ae=>be(ae))}else throw w}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,P)}};Q=new WeakMap,P=new WeakMap,g=new WeakMap,K=new WeakMap;var Ce=Te,rr=Ce;var j=s=>s?.type&&s.id&&q.includes(s.type),Ae=s=>s&&typeof s.type<"u"&&s.type&&q.includes(s.type);var ce=f("jsonapi"),M=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ue(i,t)):e=ue(r,t):e=r,e},tr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ue=(s,e,r=[])=>{if(ce("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ue(tr(p,e),e,[...r,p])):t[i]=ue(tr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),ce("denormalized resource: %O",t),t},le=s=>{ce("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&Ae(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ae(o)&&o.id===null?r[i]={data:null}:o&&(j(o)||Array.isArray(o)&&j(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return j(s)&&(t.id=s.id),ce("normalized resource: %O",t),t};var sr=f("query"),ir=["_any","_all","_in","_not_in_or_null"],hr=s=>ir.some(e=>s.endsWith(e)),or=["_jcont"],fr=s=>or.some(e=>s.endsWith(e)),_e=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),$=(s,e)=>{sr("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),_e(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!hr(t))throw new y({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${ir.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!fr(t))throw new y({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),sr("query string params: %O",r)),r};var _={resources:s=>s?[...q].sort():q,singletons:s=>s?[...me].sort():me,isSingleton:s=>me.includes(s),isSdkError:s=>y.isSdkError(s),isApiError:s=>v.isApiError(s),init:s=>ve(s),get schemaVersion(){return Oe}};var O=f("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var h,Ee,xe=class{constructor(e){u(this,h);u(this,Ee,{});c(this,h,rr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return O("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=$(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...t,params:p});return M(T)}async list(e,r,t){O("list: %o, %O, %O",e,r||{},t||{});let i=$(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...t,params:i}),p=M(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||b.default.pageNumber,recordsPerPage:r?.pageSize||b.default.pageSize};return new ye(a,p)}async create(e,r,t){O("create: %o, %O, %O",e,r||{},t||{});let i=$(r,e);t?.params&&Object.assign(i,t?.params);let o=le(e),p=await n(this,h).request("POST",e.type,o,{...t,params:i});return M(p)}async update(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=$(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=le(e),z=await n(this,h).request("PATCH",a,T,{...t,params:p});return M(z)}async delete(e,r){O("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){O("fetch: %o, %O, %O",r,t||{},i||{});let o=$(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=M(p);if(Array.isArray(a)){let T=t,z={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||b.default.pageNumber,recordsPerPage:T?.pageSize||b.default.pageSize};return new ye(z,a)}else return a}async action(e,r,t,i){O("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&j(t)?le(t):t;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){O("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new y({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return M(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},d=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:_e(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},nr=xe;var x=class x extends d{async create(e,r,t){return this.resources.create({...e,type:x.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:x.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ie=x,ze=Ie;var E=class E extends d{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="application_memberships";var Me=E,Ne=Me;var C=class C extends d{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"user"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var I=class I extends d{async create(e,r,t){return this.resources.create({...e,type:I.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:I.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:I.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="memberships";var Le=I,we=Le;var N=class N extends d{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="organizations";var Ue=N,Qe=Ue;var S=class S extends d{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="permissions";var je=S,qe=je;var k=class k extends d{async create(e,r,t){return this.resources.create({...e,type:k.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:k.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="roles";var $e=k,Fe=$e;var F=class F extends Re{async update(e,r,t){return this.resources.update({...e,type:F.TYPE},r,t)}async identity_providers(e,r,t){let i=e.id||e;return this.resources.fetch({type:"identity_providers"},`user/${i}/identity_providers`,r,t)}isUser(e){return e.type&&e.type===F.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return F.TYPE}path(){return"user"}};F.TYPE="user";var Ve=F,De=Ve;var G=class G extends d{isVersion(e){return e.type&&e.type===G.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return G.TYPE}};G.TYPE="versions";var Ye=G,He=Ye;var q=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","user","versions"],me=["user"];var ar=f("commercelayer"),Oe="1.0.6";var R,Z,X,ee,re,te,se,ie,oe,ne,Je=class{constructor(e){this.openApiSchemaVersion=Oe;u(this,R);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);u(this,ne);ar("new commercelayer provisioning instance %O",e),c(this,R,new nr(e))}get api_credentials(){return n(this,Z)||c(this,Z,new ze(n(this,R)))}get application_memberships(){return n(this,X)||c(this,X,new Ne(n(this,R)))}get identity_providers(){return n(this,ee)||c(this,ee,new ke(n(this,R)))}get memberships(){return n(this,re)||c(this,re,new we(n(this,R)))}get organizations(){return n(this,te)||c(this,te,new Qe(n(this,R)))}get permissions(){return n(this,se)||c(this,se,new qe(n(this,R)))}get roles(){return n(this,ie)||c(this,ie,new Fe(n(this,R)))}get user(){return n(this,oe)||c(this,oe,new De(n(this,R)))}get versions(){return n(this,ne)||c(this,ne,new He(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ar("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return _.resources()}singletons(){return _.singletons()}isSingleton(e){return _.isSingleton(e)}isApiError(e){return _.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap;var pr=s=>new Je(s),ve=pr;export{pr as CommerceLayerProvisioning,_ as CommerceLayerProvisioningStatic,ve as default};
|