@commercelayer/provisioning-sdk 2.4.1 → 2.5.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 +15 -4
- package/lib/index.d.ts +15 -4
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +9 -9
package/lib/index.d.mts
CHANGED
|
@@ -375,6 +375,11 @@ interface RoleUpdate extends ResourceUpdate {
|
|
|
375
375
|
* @example ```"Custom role"```
|
|
376
376
|
*/
|
|
377
377
|
name?: Nullable<string>;
|
|
378
|
+
/**
|
|
379
|
+
* Send this attribute if you want to update the role base permissions.
|
|
380
|
+
* @example ```"true"```
|
|
381
|
+
*/
|
|
382
|
+
_add_missing_base_permissions?: Nullable<boolean>;
|
|
378
383
|
}
|
|
379
384
|
declare class Roles extends ApiResource<Role> {
|
|
380
385
|
static readonly TYPE: RoleType;
|
|
@@ -385,6 +390,7 @@ declare class Roles extends ApiResource<Role> {
|
|
|
385
390
|
memberships(roleId: string | Role, params?: QueryParamsList<Membership>, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
|
|
386
391
|
api_credentials(roleId: string | Role, params?: QueryParamsList<ApiCredential>, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
|
|
387
392
|
versions(roleId: string | Role, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
|
|
393
|
+
_add_missing_base_permissions(id: string | Role, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
|
|
388
394
|
isRole(resource: any): resource is Role;
|
|
389
395
|
relationship(id: string | ResourceId | null): RoleRel$3;
|
|
390
396
|
relationshipToMany(...ids: string[]): RoleRel$3[];
|
|
@@ -608,7 +614,7 @@ interface Organization extends Resource {
|
|
|
608
614
|
subscription_info: Record<string, any>;
|
|
609
615
|
/**
|
|
610
616
|
* The organization's configuration.
|
|
611
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
617
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
612
618
|
*/
|
|
613
619
|
config?: Nullable<Record<string, any>>;
|
|
614
620
|
/**
|
|
@@ -672,6 +678,11 @@ interface Organization extends Resource {
|
|
|
672
678
|
* @example ```"true"```
|
|
673
679
|
*/
|
|
674
680
|
orders_number_as_reference: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Enables raising of API errors in case the provided coupon code is invalid, default is true.
|
|
683
|
+
* @example ```"true"```
|
|
684
|
+
*/
|
|
685
|
+
orders_invalid_coupon_errors: boolean;
|
|
675
686
|
/**
|
|
676
687
|
* The maximum number of SKUs allowed for bundles, default is 10.
|
|
677
688
|
* @example ```"10"```
|
|
@@ -834,7 +845,7 @@ interface OrganizationCreate extends ResourceCreate {
|
|
|
834
845
|
region?: Nullable<string>;
|
|
835
846
|
/**
|
|
836
847
|
* The organization's configuration.
|
|
837
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
848
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
838
849
|
*/
|
|
839
850
|
config?: Nullable<Record<string, any>>;
|
|
840
851
|
}
|
|
@@ -886,7 +897,7 @@ interface OrganizationUpdate extends ResourceUpdate {
|
|
|
886
897
|
gtm_id_test?: Nullable<string>;
|
|
887
898
|
/**
|
|
888
899
|
* The organization's configuration.
|
|
889
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
900
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
890
901
|
*/
|
|
891
902
|
config?: Nullable<Record<string, any>>;
|
|
892
903
|
}
|
|
@@ -1389,7 +1400,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1389
1400
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1390
1401
|
declare class CommerceLayerProvisioningClient {
|
|
1391
1402
|
#private;
|
|
1392
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1403
|
+
readonly openApiSchemaVersion = "1.0.11";
|
|
1393
1404
|
constructor(config: CommerceLayerInitConfig);
|
|
1394
1405
|
get api_credentials(): ApiCredentials;
|
|
1395
1406
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.d.ts
CHANGED
|
@@ -375,6 +375,11 @@ interface RoleUpdate extends ResourceUpdate {
|
|
|
375
375
|
* @example ```"Custom role"```
|
|
376
376
|
*/
|
|
377
377
|
name?: Nullable<string>;
|
|
378
|
+
/**
|
|
379
|
+
* Send this attribute if you want to update the role base permissions.
|
|
380
|
+
* @example ```"true"```
|
|
381
|
+
*/
|
|
382
|
+
_add_missing_base_permissions?: Nullable<boolean>;
|
|
378
383
|
}
|
|
379
384
|
declare class Roles extends ApiResource<Role> {
|
|
380
385
|
static readonly TYPE: RoleType;
|
|
@@ -385,6 +390,7 @@ declare class Roles extends ApiResource<Role> {
|
|
|
385
390
|
memberships(roleId: string | Role, params?: QueryParamsList<Membership>, options?: ResourcesConfig): Promise<ListResponse<Membership>>;
|
|
386
391
|
api_credentials(roleId: string | Role, params?: QueryParamsList<ApiCredential>, options?: ResourcesConfig): Promise<ListResponse<ApiCredential>>;
|
|
387
392
|
versions(roleId: string | Role, params?: QueryParamsList<Version>, options?: ResourcesConfig): Promise<ListResponse<Version>>;
|
|
393
|
+
_add_missing_base_permissions(id: string | Role, params?: QueryParamsRetrieve<Role>, options?: ResourcesConfig): Promise<Role>;
|
|
388
394
|
isRole(resource: any): resource is Role;
|
|
389
395
|
relationship(id: string | ResourceId | null): RoleRel$3;
|
|
390
396
|
relationshipToMany(...ids: string[]): RoleRel$3[];
|
|
@@ -608,7 +614,7 @@ interface Organization extends Resource {
|
|
|
608
614
|
subscription_info: Record<string, any>;
|
|
609
615
|
/**
|
|
610
616
|
* The organization's configuration.
|
|
611
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
617
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
612
618
|
*/
|
|
613
619
|
config?: Nullable<Record<string, any>>;
|
|
614
620
|
/**
|
|
@@ -672,6 +678,11 @@ interface Organization extends Resource {
|
|
|
672
678
|
* @example ```"true"```
|
|
673
679
|
*/
|
|
674
680
|
orders_number_as_reference: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Enables raising of API errors in case the provided coupon code is invalid, default is true.
|
|
683
|
+
* @example ```"true"```
|
|
684
|
+
*/
|
|
685
|
+
orders_invalid_coupon_errors: boolean;
|
|
675
686
|
/**
|
|
676
687
|
* The maximum number of SKUs allowed for bundles, default is 10.
|
|
677
688
|
* @example ```"10"```
|
|
@@ -834,7 +845,7 @@ interface OrganizationCreate extends ResourceCreate {
|
|
|
834
845
|
region?: Nullable<string>;
|
|
835
846
|
/**
|
|
836
847
|
* The organization's configuration.
|
|
837
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
848
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
838
849
|
*/
|
|
839
850
|
config?: Nullable<Record<string, any>>;
|
|
840
851
|
}
|
|
@@ -886,7 +897,7 @@ interface OrganizationUpdate extends ResourceUpdate {
|
|
|
886
897
|
gtm_id_test?: Nullable<string>;
|
|
887
898
|
/**
|
|
888
899
|
* The organization's configuration.
|
|
889
|
-
* @example ```{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
900
|
+
* @example ```{"mfe":{"language":"it-IT","default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:access_token","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"optional_billing_info":false,"thankyou_page":"https://example.com/thanks/:lang/:order_id","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}```
|
|
890
901
|
*/
|
|
891
902
|
config?: Nullable<Record<string, any>>;
|
|
892
903
|
}
|
|
@@ -1389,7 +1400,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1389
1400
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1390
1401
|
declare class CommerceLayerProvisioningClient {
|
|
1391
1402
|
#private;
|
|
1392
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1403
|
+
readonly openApiSchemaVersion = "1.0.11";
|
|
1393
1404
|
constructor(config: CommerceLayerInitConfig);
|
|
1394
1405
|
get api_credentials(): ApiCredentials;
|
|
1395
1406
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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 L=(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))(L||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,O.NAME].includes(e.name)&&Object.values(L).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 _=h("client"),Ce=s=>`https://provisioning.${s||f.default.domain}/api`,U,b,R,B,_e=class _e{constructor(e){u(this,U);u(this,b);u(this,R);u(this,B);_("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),_("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 _e(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){_("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){_("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&_("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)},z=i?.accessToken||n(this,b);z&&(T.Authorization="Bearer "+z);let k={method:e,body:a,headers:T},Be=i?.timeout||n(this,R).timeout;Be&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(Be):_("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,$])=>{p.searchParams.append(w,String($))});let Ke={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await be(p,k,Ke).catch(w=>Pe(w))}catch(w){if(er(w)&&n(this,R).refreshToken&&rr(n(this,b))){_("Access token has expired");let $=await n(this,R).refreshToken(n(this,b)).catch(ge=>{_("Refresh token error: %s",ge.message);let ne=new m({message:"Error refreshing access token",type:"token-refresh"});throw ne.source=ge,ne});if($)return _("Access token refreshed"),this.config({accessToken:$}),k.headers&&(k.headers.Authorization=`Bearer ${$}`),await be(p,k,Ke).catch(ne=>Pe(ne))}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,b)}};U=new WeakMap,b=new WeakMap,R=new WeakMap,B=new WeakMap;var Te=_e,tr=Te;var Q=s=>s?.type&&s.id&&j.includes(s.type),Ae=s=>s&&typeof s.type<"u"&&s.type&&j.includes(s.type);var pe=h("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=>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&&Ae(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ae(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"],_r=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(!_r(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 xe}};var A=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,ve=class{constructor(e){u(this,g);u(this,Ee,{});c(this,g,tr.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,t,i){let o=!("id"in e)||P.isSingleton(e.type);A("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 M(T)}async list(e,r,t){A("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=M(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){A("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 M(p)}async update(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);A("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),z=await n(this,g).request("PATCH",a,T,{...t,params:p});return M(z)}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,t,i){A("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=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||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ye(z,a)}else return a}async action(e,r,t,i){A("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){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 M(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=ve;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 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 ze=x,Me=ze;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 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===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Ie=v,Ne=Ie;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:"users"},`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 we=E,Le=we;var I=class I extends y{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 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===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="organizations";var Ue=I,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 Fe=S,$e=Fe;var F=class F extends Re{async update(e,r,t){return this.resources.update({...e,type:F.TYPE},r,t,this.path())}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="users";var Ve=F,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","users","versions"],le=["users"];var pr=h("commercelayer"),xe="1.0.8";var d,G,Z,X,ee,re,te,se,ie,oe,Je=class{constructor(e){this.openApiSchemaVersion=xe;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 Me(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 Le(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 $e(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});
|
|
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"),Y,D,H,ae=class ae extends Error{constructor(r,t,i){super(t);u(this,Y);u(this,D);u(this,H);c(this,D,r),c(this,H,t),i&&c(this,Y,i.errors)}get errors(){return n(this,Y)}get status(){return n(this,D)}get statusText(){return n(this,H)}};Y=new WeakMap,D=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 L=(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))(L||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,O.NAME].includes(e.name)&&Object.values(L).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 _=h("client"),Ce=s=>`https://provisioning.${s||f.default.domain}/api`,U,b,R,B,_e=class _e{constructor(e){u(this,U);u(this,b);u(this,R);u(this,B);_("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),_("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 _e(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){_("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){_("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&_("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)},M=i?.accessToken||n(this,b);M&&(T.Authorization="Bearer "+M);let k={method:e,body:a,headers:T},Be=i?.timeout||n(this,R).timeout;Be&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(Be):_("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,$])=>{p.searchParams.append(w,String($))});let Ke={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await be(p,k,Ke).catch(w=>Pe(w))}catch(w){if(er(w)&&n(this,R).refreshToken&&rr(n(this,b))){_("Access token has expired");let $=await n(this,R).refreshToken(n(this,b)).catch(ge=>{_("Refresh token error: %s",ge.message);let ne=new m({message:"Error refreshing access token",type:"token-refresh"});throw ne.source=ge,ne});if($)return _("Access token refreshed"),this.config({accessToken:$}),k.headers&&(k.headers.Authorization=`Bearer ${$}`),await be(p,k,Ke).catch(ne=>Pe(ne))}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,b)}};U=new WeakMap,b=new WeakMap,R=new WeakMap,B=new WeakMap;var Te=_e,tr=Te;var Q=s=>s?.type&&s.id&&j.includes(s.type),Ae=s=>s&&typeof s.type<"u"&&s.type&&j.includes(s.type);var pe=h("jsonapi"),I=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&&Ae(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ae(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"],_r=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(!_r(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 xe}};var A=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,ve=class{constructor(e){u(this,g);u(this,Ee,{});c(this,g,tr.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,t,i){let o=!("id"in e)||P.isSingleton(e.type);A("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 I(T)}async list(e,r,t){A("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=I(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){A("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 I(p)}async update(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);A("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),M=await n(this,g).request("PATCH",a,T,{...t,params:p});return I(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,t,i){A("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=I(p);if(Array.isArray(a)){let T=t,M={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(M,a)}else return a}async action(e,r,t,i){A("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){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 I(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=ve;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 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 ze=x,Me=ze;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 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===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Ie=v,Ne=Ie;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:"users"},`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 we=E,Le=we;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 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 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"},`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 z=class z extends y{async create(e,r,t){return this.resources.create({...e,type:z.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:z.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)}async _add_missing_base_permissions(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:z.TYPE,_add_missing_base_permissions:!0},r,t)}isRole(e){return e.type&&e.type===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="roles";var Fe=z,$e=Fe;var F=class F extends Re{async update(e,r,t){return this.resources.update({...e,type:F.TYPE},r,t,this.path())}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="users";var Ve=F,Ye=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 De=K,He=De;var j=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","users","versions"],le=["users"];var pr=h("commercelayer"),xe="1.0.11";var d,G,Z,X,ee,re,te,se,ie,oe,Je=class{constructor(e){this.openApiSchemaVersion=xe;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 Me(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 Le(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 $e(n(this,d)))}get user(){return n(this,ie)||c(this,ie,new Ye(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 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,x.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 x=B,yr=s=>s instanceof TypeError,dr=s=>s instanceof DOMException&&s.name==="AbortError",Rr=s=>s instanceof DOMException&&s.name==="TimeoutError",Xe=s=>x.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)||x.isApiError(s))throw s;let e=new y({message:s.message});if(D.isFetchError(s)){let r=new x(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 _=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);_("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),_("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){_("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){_("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&_("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)},M=i?.accessToken||n(this,P);M&&(T.Authorization="Bearer "+M);let w={method:e,body:a,headers:T},We=i?.timeout||n(this,g).timeout;We&&(AbortSignal?.timeout?w.signal=AbortSignal.timeout(We):_("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Be={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await fe(p,w,Be).catch(L=>be(L))}catch(L){if(Xe(L)&&n(this,g).refreshToken&&er(n(this,P))){_("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(ge=>{_("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 _("Access token refreshed"),this.config({accessToken:V}),w.headers&&(w.headers.Authorization=`Bearer ${V}`),await fe(p,w,Be).catch(ae=>be(ae))}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,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),_e=s=>s&&typeof s.type<"u"&&s.type&&q.includes(s.type);var ce=f("jsonapi"),I=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&&_e(o[0])&&o[0].id===null?r[i]={data:[]}:o&&_e(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)),Ae=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),F=(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(",")})),Ae(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 A={resources:s=>s?[...q].sort():q,singletons:s=>s?[...me].sort():me,isSingleton:s=>me.includes(s),isSdkError:s=>y.isSdkError(s),isApiError:s=>x.isApiError(s),init:s=>xe(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,ve=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)||A.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(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 I(T)}async list(e,r,t){O("list: %o, %O, %O",e,r||{},t||{});let i=F(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=I(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=F(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 I(p)}async update(e,r,t,i){let o=!("id"in e)||A.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=le(e),M=await n(this,h).request("PATCH",a,T,{...t,params:p});return I(M)}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=F(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=I(p);if(Array.isArray(a)){let T=t,M={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(M,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 I(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:Ae(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=ve;var v=class v extends d{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 ze=v,Me=ze;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 Ie=E,Ne=Ie;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:"users"},`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 z=class z extends d{async create(e,r,t){return this.resources.create({...e,type:z.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:z.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.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===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var we=z,Le=we;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 Fe=k,$e=Fe;var $=class $ extends Re{async update(e,r,t){return this.resources.update({...e,type:$.TYPE},r,t,this.path())}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="users";var Ve=$,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","users","versions"],me=["users"];var ar=f("commercelayer"),Oe="1.0.8";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 Me(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 Le(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 $e(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 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 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),xe=pr;export{pr as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,xe 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"),D,H,J,pe=class pe extends Error{constructor(r,t,i){super(t);u(this,D);u(this,H);u(this,J);c(this,H,r),c(this,J,t),i&&c(this,D,i.errors)}get errors(){return n(this,D)}get status(){return n(this,H)}get statusText(){return n(this,J)}};D=new WeakMap,H=new WeakMap,J=new WeakMap,pe.isFetchError=r=>r instanceof pe;var Y=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 Y(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,x.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 x=B,yr=s=>s instanceof TypeError,dr=s=>s instanceof DOMException&&s.name==="AbortError",Rr=s=>s instanceof DOMException&&s.name==="TimeoutError",Xe=s=>x.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)||x.isApiError(s))throw s;let e=new y({message:s.message});if(Y.isFetchError(s)){let r=new x(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 _=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);_("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),_("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){_("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){_("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&_("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)},I=i?.accessToken||n(this,P);I&&(T.Authorization="Bearer "+I);let w={method:e,body:a,headers:T},We=i?.timeout||n(this,g).timeout;We&&(AbortSignal?.timeout?w.signal=AbortSignal.timeout(We):_("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Be={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await fe(p,w,Be).catch(L=>be(L))}catch(L){if(Xe(L)&&n(this,g).refreshToken&&er(n(this,P))){_("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(ge=>{_("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 _("Access token refreshed"),this.config({accessToken:V}),w.headers&&(w.headers.Authorization=`Bearer ${V}`),await fe(p,w,Be).catch(ae=>be(ae))}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,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),_e=s=>s&&typeof s.type<"u"&&s.type&&q.includes(s.type);var ce=f("jsonapi"),N=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&&_e(o[0])&&o[0].id===null?r[i]={data:[]}:o&&_e(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)),Ae=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),F=(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(",")})),Ae(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 A={resources:s=>s?[...q].sort():q,singletons:s=>s?[...me].sort():me,isSingleton:s=>me.includes(s),isSdkError:s=>y.isSdkError(s),isApiError:s=>x.isApiError(s),init:s=>xe(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,ve=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)||A.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(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 N(T)}async list(e,r,t){O("list: %o, %O, %O",e,r||{},t||{});let i=F(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=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 ye(a,p)}async create(e,r,t){O("create: %o, %O, %O",e,r||{},t||{});let i=F(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 N(p)}async update(e,r,t,i){let o=!("id"in e)||A.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=le(e),I=await n(this,h).request("PATCH",a,T,{...t,params:p});return N(I)}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=F(t,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 T=t,I={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(I,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 N(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:Ae(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=ve;var v=class v extends d{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 ze=v,Me=ze;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 Ie=E,Ne=Ie;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:"users"},`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 z=class z extends d{async create(e,r,t){return this.resources.create({...e,type:z.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:z.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.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===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var we=z,Le=we;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 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===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="organizations";var Ue=S,Qe=Ue;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"},`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===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="permissions";var je=k,qe=je;var M=class M extends d{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 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)}async _add_missing_base_permissions(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:M.TYPE,_add_missing_base_permissions:!0},r,t)}isRole(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="roles";var Fe=M,$e=Fe;var $=class $ extends Re{async update(e,r,t){return this.resources.update({...e,type:$.TYPE},r,t,this.path())}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="users";var Ve=$,Ye=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 De=G,He=De;var q=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","users","versions"],me=["users"];var ar=f("commercelayer"),Oe="1.0.11";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 Me(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 Le(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 $e(n(this,R)))}get user(){return n(this,oe)||c(this,oe,new Ye(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 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 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),xe=pr;export{pr as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,xe as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/provisioning-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -34,25 +34,25 @@
|
|
|
34
34
|
"node": ">=20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/preset-env": "^7.26.
|
|
38
|
-
"@babel/preset-typescript": "^7.
|
|
37
|
+
"@babel/preset-env": "^7.26.9",
|
|
38
|
+
"@babel/preset-typescript": "^7.27.0",
|
|
39
39
|
"@commercelayer/eslint-config-ts": "1.4.5",
|
|
40
|
-
"@commercelayer/js-auth": "^6.7.
|
|
40
|
+
"@commercelayer/js-auth": "^6.7.2",
|
|
41
41
|
"@semantic-release/changelog": "^6.0.3",
|
|
42
42
|
"@semantic-release/git": "^10.0.1",
|
|
43
43
|
"@types/debug": "^4.1.12",
|
|
44
44
|
"@types/jest": "^29.5.14",
|
|
45
|
-
"@types/node": "^22.
|
|
45
|
+
"@types/node": "^22.14.0",
|
|
46
46
|
"dotenv": "^16.4.7",
|
|
47
47
|
"eslint": "^8.57.1",
|
|
48
48
|
"jest": "^29.7.0",
|
|
49
49
|
"json-typescript": "^1.1.2",
|
|
50
50
|
"jsonapi-typescript": "^0.1.3",
|
|
51
51
|
"lodash.isequal": "^4.5.0",
|
|
52
|
-
"semantic-release": "^24.2.
|
|
53
|
-
"tsup": "^8.
|
|
54
|
-
"tsx": "^4.19.
|
|
55
|
-
"typescript": "^5.
|
|
52
|
+
"semantic-release": "^24.2.3",
|
|
53
|
+
"tsup": "^8.4.0",
|
|
54
|
+
"tsx": "^4.19.3",
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
56
|
},
|
|
57
57
|
"repository": "github:commercelayer/provisioning-sdk",
|
|
58
58
|
"bugs": "https://github.com/commercelayer/provisioning-sdk/issues",
|