@commercelayer/provisioning-sdk 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +50 -13
- package/lib/index.d.ts +50 -13
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +6 -6
package/lib/index.d.mts
CHANGED
|
@@ -416,9 +416,14 @@ interface MembershipProfile extends Resource {
|
|
|
416
416
|
*/
|
|
417
417
|
name: string;
|
|
418
418
|
/**
|
|
419
|
-
*
|
|
419
|
+
* Reflects the organization's access scope, either test_access or all_access.
|
|
420
420
|
*/
|
|
421
421
|
test_enabled: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
424
|
+
* @example ```"live_access"```
|
|
425
|
+
*/
|
|
426
|
+
access_scope: 'live_access' | 'test_access' | 'all_access';
|
|
422
427
|
organization?: Nullable<Organization>;
|
|
423
428
|
application_memberships?: Nullable<ApplicationMembership[]>;
|
|
424
429
|
}
|
|
@@ -429,9 +434,10 @@ interface MembershipProfileCreate extends ResourceCreate {
|
|
|
429
434
|
*/
|
|
430
435
|
name: string;
|
|
431
436
|
/**
|
|
432
|
-
*
|
|
437
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
438
|
+
* @example ```"live_access"```
|
|
433
439
|
*/
|
|
434
|
-
|
|
440
|
+
access_scope: 'live_access' | 'test_access' | 'all_access';
|
|
435
441
|
organization: OrganizationRel$4;
|
|
436
442
|
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
|
|
437
443
|
}
|
|
@@ -442,9 +448,10 @@ interface MembershipProfileUpdate extends ResourceUpdate {
|
|
|
442
448
|
*/
|
|
443
449
|
name?: Nullable<string>;
|
|
444
450
|
/**
|
|
445
|
-
*
|
|
451
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
452
|
+
* @example ```"live_access"```
|
|
446
453
|
*/
|
|
447
|
-
|
|
454
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
448
455
|
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
|
|
449
456
|
}
|
|
450
457
|
declare class MembershipProfiles extends ApiResource<MembershipProfile> {
|
|
@@ -575,9 +582,14 @@ interface Membership extends Resource {
|
|
|
575
582
|
*/
|
|
576
583
|
owner: boolean;
|
|
577
584
|
/**
|
|
578
|
-
*
|
|
585
|
+
* Reflects the organization's access scope, either test_access or all_access.
|
|
586
|
+
*/
|
|
587
|
+
test_enabled: boolean;
|
|
588
|
+
/**
|
|
589
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
590
|
+
* @example ```"live_access"```
|
|
579
591
|
*/
|
|
580
|
-
|
|
592
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
581
593
|
organization?: Nullable<Organization>;
|
|
582
594
|
role?: Nullable<Role>;
|
|
583
595
|
application_memberships?: Nullable<ApplicationMembership[]>;
|
|
@@ -591,9 +603,10 @@ interface MembershipCreate extends ResourceCreate {
|
|
|
591
603
|
*/
|
|
592
604
|
user_email: string;
|
|
593
605
|
/**
|
|
594
|
-
*
|
|
606
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
607
|
+
* @example ```"live_access"```
|
|
595
608
|
*/
|
|
596
|
-
|
|
609
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
597
610
|
organization: OrganizationRel$2;
|
|
598
611
|
role: RoleRel$1;
|
|
599
612
|
application_memberships?: Nullable<ApplicationMembershipRel[]>;
|
|
@@ -601,9 +614,10 @@ interface MembershipCreate extends ResourceCreate {
|
|
|
601
614
|
}
|
|
602
615
|
interface MembershipUpdate extends ResourceUpdate {
|
|
603
616
|
/**
|
|
604
|
-
*
|
|
617
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
618
|
+
* @example ```"live_access"```
|
|
605
619
|
*/
|
|
606
|
-
|
|
620
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
607
621
|
role?: Nullable<RoleRel$1>;
|
|
608
622
|
application_memberships?: Nullable<ApplicationMembershipRel[]>;
|
|
609
623
|
membership_profile?: Nullable<MembershipProfileRel>;
|
|
@@ -739,13 +753,27 @@ interface Organization extends Resource {
|
|
|
739
753
|
* @example ```"5000"```
|
|
740
754
|
*/
|
|
741
755
|
api_max_regex_length: number;
|
|
756
|
+
/**
|
|
757
|
+
* Indicates if AVS checking will be enforced during payment workflow by passing specific attributes, default is true.
|
|
758
|
+
* @example ```"true"```
|
|
759
|
+
*/
|
|
760
|
+
addresses_avs_check: boolean;
|
|
742
761
|
/**
|
|
743
762
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
744
763
|
* @example ```"true"```
|
|
745
764
|
*/
|
|
746
765
|
addresses_phone_required: boolean;
|
|
747
766
|
/**
|
|
748
|
-
*
|
|
767
|
+
* Indicates if a sales channel application without customer can read and update just guest orders.
|
|
768
|
+
* @example ```"true"```
|
|
769
|
+
*/
|
|
770
|
+
orders_sales_channel_guest_only: boolean;
|
|
771
|
+
/**
|
|
772
|
+
* The minimum lapse in fraction of seconds to be observed between two consecutive shipments rebuilt. If shipments rebuilt is triggered within the minimum lapse, the update is performed, but no rebuilt is done.
|
|
773
|
+
*/
|
|
774
|
+
orders_min_rebuild_shipments_lapse: number;
|
|
775
|
+
/**
|
|
776
|
+
* The minimum lapse in fraction of seconds to be observed between two consecutive order refreshes. If refresh is triggered within the minimum lapse, the update is performed, but no order refresh is done.
|
|
749
777
|
*/
|
|
750
778
|
orders_min_refresh_lapse: number;
|
|
751
779
|
/**
|
|
@@ -781,6 +809,10 @@ interface Organization extends Resource {
|
|
|
781
809
|
* @example ```"true"```
|
|
782
810
|
*/
|
|
783
811
|
orders_invalid_gift_card_errors: boolean;
|
|
812
|
+
/**
|
|
813
|
+
* Enables the validation of the generated stock line items and stock transfers before placing the order, default is false.
|
|
814
|
+
*/
|
|
815
|
+
orders_validate_shipping_stock: boolean;
|
|
784
816
|
/**
|
|
785
817
|
* The maximum number of SKUs allowed for bundles, default is 10.
|
|
786
818
|
* @example ```"10"```
|
|
@@ -894,6 +926,11 @@ interface Organization extends Resource {
|
|
|
894
926
|
* Enables raising of API errors in case of external promotion failure, default is false.
|
|
895
927
|
*/
|
|
896
928
|
external_promotions_errors: boolean;
|
|
929
|
+
/**
|
|
930
|
+
* Enables raising of API errors in case of external price failure, default is true.
|
|
931
|
+
* @example ```"true"```
|
|
932
|
+
*/
|
|
933
|
+
external_prices_errors: boolean;
|
|
897
934
|
memberships?: Nullable<Membership[]>;
|
|
898
935
|
roles?: Nullable<Role[]>;
|
|
899
936
|
permissions?: Nullable<Permission[]>;
|
|
@@ -1509,7 +1546,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1509
1546
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1510
1547
|
declare class CommerceLayerProvisioningClient {
|
|
1511
1548
|
#private;
|
|
1512
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1549
|
+
readonly openApiSchemaVersion = "1.0.15";
|
|
1513
1550
|
constructor(config: CommerceLayerInitConfig);
|
|
1514
1551
|
get api_credentials(): ApiCredentials;
|
|
1515
1552
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.d.ts
CHANGED
|
@@ -416,9 +416,14 @@ interface MembershipProfile extends Resource {
|
|
|
416
416
|
*/
|
|
417
417
|
name: string;
|
|
418
418
|
/**
|
|
419
|
-
*
|
|
419
|
+
* Reflects the organization's access scope, either test_access or all_access.
|
|
420
420
|
*/
|
|
421
421
|
test_enabled: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
424
|
+
* @example ```"live_access"```
|
|
425
|
+
*/
|
|
426
|
+
access_scope: 'live_access' | 'test_access' | 'all_access';
|
|
422
427
|
organization?: Nullable<Organization>;
|
|
423
428
|
application_memberships?: Nullable<ApplicationMembership[]>;
|
|
424
429
|
}
|
|
@@ -429,9 +434,10 @@ interface MembershipProfileCreate extends ResourceCreate {
|
|
|
429
434
|
*/
|
|
430
435
|
name: string;
|
|
431
436
|
/**
|
|
432
|
-
*
|
|
437
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
438
|
+
* @example ```"live_access"```
|
|
433
439
|
*/
|
|
434
|
-
|
|
440
|
+
access_scope: 'live_access' | 'test_access' | 'all_access';
|
|
435
441
|
organization: OrganizationRel$4;
|
|
436
442
|
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
|
|
437
443
|
}
|
|
@@ -442,9 +448,10 @@ interface MembershipProfileUpdate extends ResourceUpdate {
|
|
|
442
448
|
*/
|
|
443
449
|
name?: Nullable<string>;
|
|
444
450
|
/**
|
|
445
|
-
*
|
|
451
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
452
|
+
* @example ```"live_access"```
|
|
446
453
|
*/
|
|
447
|
-
|
|
454
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
448
455
|
application_memberships?: Nullable<ApplicationMembershipRel$2[]>;
|
|
449
456
|
}
|
|
450
457
|
declare class MembershipProfiles extends ApiResource<MembershipProfile> {
|
|
@@ -575,9 +582,14 @@ interface Membership extends Resource {
|
|
|
575
582
|
*/
|
|
576
583
|
owner: boolean;
|
|
577
584
|
/**
|
|
578
|
-
*
|
|
585
|
+
* Reflects the organization's access scope, either test_access or all_access.
|
|
586
|
+
*/
|
|
587
|
+
test_enabled: boolean;
|
|
588
|
+
/**
|
|
589
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
590
|
+
* @example ```"live_access"```
|
|
579
591
|
*/
|
|
580
|
-
|
|
592
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
581
593
|
organization?: Nullable<Organization>;
|
|
582
594
|
role?: Nullable<Role>;
|
|
583
595
|
application_memberships?: Nullable<ApplicationMembership[]>;
|
|
@@ -591,9 +603,10 @@ interface MembershipCreate extends ResourceCreate {
|
|
|
591
603
|
*/
|
|
592
604
|
user_email: string;
|
|
593
605
|
/**
|
|
594
|
-
*
|
|
606
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
607
|
+
* @example ```"live_access"```
|
|
595
608
|
*/
|
|
596
|
-
|
|
609
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
597
610
|
organization: OrganizationRel$2;
|
|
598
611
|
role: RoleRel$1;
|
|
599
612
|
application_memberships?: Nullable<ApplicationMembershipRel[]>;
|
|
@@ -601,9 +614,10 @@ interface MembershipCreate extends ResourceCreate {
|
|
|
601
614
|
}
|
|
602
615
|
interface MembershipUpdate extends ResourceUpdate {
|
|
603
616
|
/**
|
|
604
|
-
*
|
|
617
|
+
* The access scope for applications. One of `live_access` (default), `test_access`, `all_access`.
|
|
618
|
+
* @example ```"live_access"```
|
|
605
619
|
*/
|
|
606
|
-
|
|
620
|
+
access_scope?: Nullable<'live_access' | 'test_access' | 'all_access'>;
|
|
607
621
|
role?: Nullable<RoleRel$1>;
|
|
608
622
|
application_memberships?: Nullable<ApplicationMembershipRel[]>;
|
|
609
623
|
membership_profile?: Nullable<MembershipProfileRel>;
|
|
@@ -739,13 +753,27 @@ interface Organization extends Resource {
|
|
|
739
753
|
* @example ```"5000"```
|
|
740
754
|
*/
|
|
741
755
|
api_max_regex_length: number;
|
|
756
|
+
/**
|
|
757
|
+
* Indicates if AVS checking will be enforced during payment workflow by passing specific attributes, default is true.
|
|
758
|
+
* @example ```"true"```
|
|
759
|
+
*/
|
|
760
|
+
addresses_avs_check: boolean;
|
|
742
761
|
/**
|
|
743
762
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
744
763
|
* @example ```"true"```
|
|
745
764
|
*/
|
|
746
765
|
addresses_phone_required: boolean;
|
|
747
766
|
/**
|
|
748
|
-
*
|
|
767
|
+
* Indicates if a sales channel application without customer can read and update just guest orders.
|
|
768
|
+
* @example ```"true"```
|
|
769
|
+
*/
|
|
770
|
+
orders_sales_channel_guest_only: boolean;
|
|
771
|
+
/**
|
|
772
|
+
* The minimum lapse in fraction of seconds to be observed between two consecutive shipments rebuilt. If shipments rebuilt is triggered within the minimum lapse, the update is performed, but no rebuilt is done.
|
|
773
|
+
*/
|
|
774
|
+
orders_min_rebuild_shipments_lapse: number;
|
|
775
|
+
/**
|
|
776
|
+
* The minimum lapse in fraction of seconds to be observed between two consecutive order refreshes. If refresh is triggered within the minimum lapse, the update is performed, but no order refresh is done.
|
|
749
777
|
*/
|
|
750
778
|
orders_min_refresh_lapse: number;
|
|
751
779
|
/**
|
|
@@ -781,6 +809,10 @@ interface Organization extends Resource {
|
|
|
781
809
|
* @example ```"true"```
|
|
782
810
|
*/
|
|
783
811
|
orders_invalid_gift_card_errors: boolean;
|
|
812
|
+
/**
|
|
813
|
+
* Enables the validation of the generated stock line items and stock transfers before placing the order, default is false.
|
|
814
|
+
*/
|
|
815
|
+
orders_validate_shipping_stock: boolean;
|
|
784
816
|
/**
|
|
785
817
|
* The maximum number of SKUs allowed for bundles, default is 10.
|
|
786
818
|
* @example ```"10"```
|
|
@@ -894,6 +926,11 @@ interface Organization extends Resource {
|
|
|
894
926
|
* Enables raising of API errors in case of external promotion failure, default is false.
|
|
895
927
|
*/
|
|
896
928
|
external_promotions_errors: boolean;
|
|
929
|
+
/**
|
|
930
|
+
* Enables raising of API errors in case of external price failure, default is true.
|
|
931
|
+
* @example ```"true"```
|
|
932
|
+
*/
|
|
933
|
+
external_prices_errors: boolean;
|
|
897
934
|
memberships?: Nullable<Membership[]>;
|
|
898
935
|
roles?: Nullable<Role[]>;
|
|
899
936
|
permissions?: Nullable<Permission[]>;
|
|
@@ -1509,7 +1546,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1509
1546
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1510
1547
|
declare class CommerceLayerProvisioningClient {
|
|
1511
1548
|
#private;
|
|
1512
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1549
|
+
readonly openApiSchemaVersion = "1.0.15";
|
|
1513
1550
|
constructor(config: CommerceLayerInitConfig);
|
|
1514
1551
|
get api_credentials(): ApiCredentials;
|
|
1515
1552
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var fe=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var Rr=Object.prototype.hasOwnProperty;var rr=t=>{throw TypeError(t)};var gr=(t,e)=>{for(var r in e)fe(t,r,{get:e[r],enumerable:!0})},hr=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of dr(e))!Rr.call(t,i)&&i!==r&&fe(t,i,{get:()=>e[i],enumerable:!(s=yr(e,i))||s.enumerable});return t};var br=t=>hr(fe({},"__esModule",{value:!0}),t);var sr=(t,e,r)=>e.has(t)||rr("Cannot "+r);var n=(t,e,r)=>(sr(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>e.has(t)?rr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),l=(t,e,r,s)=>(sr(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var zr={};gr(zr,{CommerceLayerProvisioning:()=>Ze,CommerceLayerProvisioningStatic:()=>P,default:()=>de});module.exports=br(zr);var fr=(t,...e)=>{},tr=t=>fr;try{let t=require("debug");t&&typeof t=="function"&&(tr=t)}catch{}var Pr="clsdk",_r=t=>tr(`${Pr}:${t}`),h=_r;var Pe=h("fetch"),D,H,J,le=class le extends Error{constructor(r,s,i){super(s);c(this,D);c(this,H);c(this,J);l(this,H,r),l(this,J,s),i&&l(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,le.isFetchError=r=>r instanceof le;var V=le,_e=async(t,e,r)=>{Pe("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(Pe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(Pe("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(s?.response?.onFailure&&(a=await s.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||{}),W=class W extends Error{static isSdkError(e){return e&&[W.NAME,M.NAME].includes(e.name)&&Object.values(L).includes(e.type)}constructor(e){super(e.message),this.name=W.NAME,this.type=e.type||"client"}};W.NAME="SdkError";var m=W,B=class B extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=B.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===B.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};B.NAME="ApiError";var M=B,Tr=t=>t instanceof TypeError,Cr=t=>t instanceof DOMException&&t.name==="AbortError",Ar=t=>t instanceof DOMException&&t.name==="TimeoutError",ir=t=>M.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),Te=t=>{if(m.isSdkError(t)||M.isApiError(t))throw t;let e=new m({message:t.message});if(V.isFetchError(t)){let r=new M(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else Tr(t)?e.type="request":Cr(t)?e.type="cancel":Ar(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var Mr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=Mr;var or=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var C=h("client"),Ce=t=>`https://provisioning.${t||b.default.domain}/api`,Q,f,R,K,Me=class Me{constructor(e){c(this,Q);c(this,f);c(this,R);c(this,K);C("new client instance %O",e),l(this,Q,Ce(e.domain)),l(this,f,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,f)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,l(this,R,r),C("fetch config: %O",r),l(this,K,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Me(e)}get interceptors(){return n(this,K)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){C("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&&l(this,Q,Ce(e.domain)),e.accessToken&&(l(this,f,e.accessToken),r.headers.Authorization="Bearer "+n(this,f)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){C("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&C("User-Agent header ignored in request config");let o=i?.domain?Ce(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},N=i?.accessToken||n(this,f);N&&(T.Authorization="Bearer "+N);let w={method:e,body:a,headers:T},Xe=i?.timeout||n(this,R).timeout;Xe&&(AbortSignal?.timeout?w.signal=AbortSignal.timeout(Xe):C("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([U,Y])=>{p.searchParams.append(U,String(Y))});let er={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await _e(p,w,er).catch(U=>Te(U))}catch(U){if(ir(U)&&n(this,R).refreshToken&&or(n(this,f))){C("Access token has expired");let Y=await n(this,R).refreshToken(n(this,f)).catch(be=>{C("Refresh token error: %s",be.message);let pe=new m({message:"Error refreshing access token",type:"token-refresh"});throw pe.source=be,pe});if(Y)return C("Access token refreshed"),this.config({accessToken:Y}),w.headers&&(w.headers.Authorization=`Bearer ${Y}`),await _e(p,w,er).catch(pe=>Te(pe))}else throw U}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,f)}};Q=new WeakMap,f=new WeakMap,R=new WeakMap,K=new WeakMap;var Ae=Me,nr=Ae;var j=t=>t?.type&&t.id&&q.includes(t.type),Oe=t=>t&&typeof t.type<"u"&&t.type&&q.includes(t.type);var ce=h("jsonapi"),I=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>ue(i,s)):e=ue(r,s):e=r,e},ar=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,ue=(t,e,r=[])=>{if(ce("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>ue(ar(p,e),e,[...r,p])):s[i]=ue(ar(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ce("denormalized resource: %O",s),s},me=t=>{ce("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Oe(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Oe(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 s={type:t.type,attributes:e,relationships:r};return j(t)&&(s.id=t.id),ce("normalized resource: %O",s),s};var pr=h("query"),lr=["_any","_all","_in","_not_in_or_null"],Or=t=>lr.some(e=>t.endsWith(e)),cr=["_jcont"],xr=t=>cr.some(e=>t.endsWith(e)),xe=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),$=(t,e)=>{pr("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),xe(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!Or(s))throw new m({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${lr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!xr(s))throw new m({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${cr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),pr("query string params: %O",r)),r};var P={resources:t=>t?[...q].sort():q,singletons:t=>t?[...ye].sort():ye,isSingleton:t=>ye.includes(t),isSdkError:t=>m.isSdkError(t),isApiError:t=>M.isApiError(t),init:t=>de(t),get schemaVersion(){return ve}};var A=h("resource"),Re=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,ze=class{constructor(e){c(this,g);c(this,Ee,{});l(this,g,nr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return A("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=$(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,g).request("GET",a,void 0,{...s,params:p});return I(T)}async list(e,r,s){A("list: %o, %O, %O",e,r||{},s||{});let i=$(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...s,params:i}),p=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 Re(a,p)}async create(e,r,s){A("create: %o, %O, %O",e,r||{},s||{});let i=$(r,e);s?.params&&Object.assign(i,s?.params);let o=me(e),p=await n(this,g).request("POST",e.type,o,{...s,params:i});return I(p)}async update(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=$(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=me(e),N=await n(this,g).request("PATCH",a,T,{...s,params:p});return I(N)}async delete(e,r){A("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){A("fetch: %o, %O, %O",r,s||{},i||{});let o=$(s,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=s,N={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 Re(N,a)}else return a}async action(e,r,s,i){A("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&j(s)?me(s):s;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,Ee=new WeakMap;var ge=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,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},y=class extends ge{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:xe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},he=class extends ge{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},ur=ze;var O=class O extends y{async create(e,r,s){return this.resources.create({...e,type:O.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:O.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:O.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===O.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return O.TYPE}};O.TYPE="api_credentials";var Ne=O,Ie=Ne;var x=class x extends y{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`application_memberships/${i}/membership_profile`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="application_memberships";var Se=x,ke=Se;var _=class _ extends y{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async user(e,r,s){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,s)}async _disable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_disable:!0},r,s)}async _enable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_enable:!0},r,s)}isIdentityProvider(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="identity_providers";var we=_,Ue=we;var v=class v extends y{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`memberships/${i}/membership_profile`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="memberships";var Le=v,Qe=Le;var z=class z extends y{async create(e,r,s){return this.resources.create({...e,type:z.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:z.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`membership_profiles/${i}/organization`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`membership_profiles/${i}/application_memberships`,r,s)}isMembershipProfile(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="membership_profiles";var je=z,qe=je;var S=class S extends y{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="organizations";var $e=S,Fe=$e;var k=class k extends y{async create(e,r,s){return this.resources.create({...e,type:k.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:k.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="permissions";var Ye=k,Ve=Ye;var E=class E extends y{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}async _add_missing_base_permissions(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:E.TYPE,_add_missing_base_permissions:!0},r,s)}isRole(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="roles";var De=E,He=De;var F=class F extends he{async update(e,r,s){return this.resources.update({...e,type:F.TYPE},r,s,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 Je=F,We=Je;var G=class G extends y{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 Be=G,Ke=Be;var q=["api_credentials","application_memberships","identity_providers","memberships","membership_profiles","organizations","permissions","roles","users","versions"],ye=["users"];var mr=h("commercelayer"),ve="1.0.13";var d,Z,X,ee,re,se,te,ie,oe,ne,ae,Ge=class{constructor(e){this.openApiSchemaVersion=ve;c(this,d);c(this,Z);c(this,X);c(this,ee);c(this,re);c(this,se);c(this,te);c(this,ie);c(this,oe);c(this,ne);c(this,ae);mr("new commercelayer provisioning instance %O",e),l(this,d,new ur(e))}get api_credentials(){return n(this,Z)||l(this,Z,new Ie(n(this,d)))}get application_memberships(){return n(this,X)||l(this,X,new ke(n(this,d)))}get identity_providers(){return n(this,ee)||l(this,ee,new Ue(n(this,d)))}get memberships(){return n(this,re)||l(this,re,new Qe(n(this,d)))}get membership_profiles(){return n(this,se)||l(this,se,new qe(n(this,d)))}get organizations(){return n(this,te)||l(this,te,new Fe(n(this,d)))}get permissions(){return n(this,ie)||l(this,ie,new Ve(n(this,d)))}get roles(){return n(this,oe)||l(this,oe,new He(n(this,d)))}get user(){return n(this,ne)||l(this,ne,new We(n(this,d)))}get versions(){return n(this,ae)||l(this,ae,new Ke(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return mr("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 s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap,ae=new WeakMap;var Ze=t=>new Ge(t),de=Ze;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var Rr=Object.prototype.hasOwnProperty;var rr=t=>{throw TypeError(t)};var gr=(t,e)=>{for(var r in e)fe(t,r,{get:e[r],enumerable:!0})},hr=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of dr(e))!Rr.call(t,i)&&i!==r&&fe(t,i,{get:()=>e[i],enumerable:!(s=yr(e,i))||s.enumerable});return t};var br=t=>hr(fe({},"__esModule",{value:!0}),t);var sr=(t,e,r)=>e.has(t)||rr("Cannot "+r);var n=(t,e,r)=>(sr(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>e.has(t)?rr("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),l=(t,e,r,s)=>(sr(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var zr={};gr(zr,{CommerceLayerProvisioning:()=>Ze,CommerceLayerProvisioningStatic:()=>P,default:()=>de});module.exports=br(zr);var fr=(t,...e)=>{},tr=t=>fr;try{let t=require("debug");t&&typeof t=="function"&&(tr=t)}catch{}var Pr="clsdk",_r=t=>tr(`${Pr}:${t}`),h=_r;var Pe=h("fetch"),D,H,J,le=class le extends Error{constructor(r,s,i){super(s);c(this,D);c(this,H);c(this,J);l(this,H,r),l(this,J,s),i&&l(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,le.isFetchError=r=>r instanceof le;var V=le,_e=async(t,e,r)=>{Pe("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(Pe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(Pe("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(s?.response?.onFailure&&(a=await s.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||{}),W=class W extends Error{static isSdkError(e){return e&&[W.NAME,M.NAME].includes(e.name)&&Object.values(L).includes(e.type)}constructor(e){super(e.message),this.name=W.NAME,this.type=e.type||"client"}};W.NAME="SdkError";var m=W,B=class B extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=B.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===B.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};B.NAME="ApiError";var M=B,Tr=t=>t instanceof TypeError,Cr=t=>t instanceof DOMException&&t.name==="AbortError",Ar=t=>t instanceof DOMException&&t.name==="TimeoutError",ir=t=>M.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),Te=t=>{if(m.isSdkError(t)||M.isApiError(t))throw t;let e=new m({message:t.message});if(V.isFetchError(t)){let r=new M(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else Tr(t)?e.type="request":Cr(t)?e.type="cancel":Ar(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var Mr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=Mr;var or=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var C=h("client"),Ce=t=>`https://provisioning.${t||b.default.domain}/api`,Q,f,R,K,Me=class Me{constructor(e){c(this,Q);c(this,f);c(this,R);c(this,K);C("new client instance %O",e),l(this,Q,Ce(e.domain)),l(this,f,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,f)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,l(this,R,r),C("fetch config: %O",r),l(this,K,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Me(e)}get interceptors(){return n(this,K)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){C("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&&l(this,Q,Ce(e.domain)),e.accessToken&&(l(this,f,e.accessToken),r.headers.Authorization="Bearer "+n(this,f)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){C("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&C("User-Agent header ignored in request config");let o=i?.domain?Ce(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},N=i?.accessToken||n(this,f);N&&(T.Authorization="Bearer "+N);let w={method:e,body:a,headers:T},Xe=i?.timeout||n(this,R).timeout;Xe&&(AbortSignal?.timeout?w.signal=AbortSignal.timeout(Xe):C("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([U,Y])=>{p.searchParams.append(U,String(Y))});let er={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await _e(p,w,er).catch(U=>Te(U))}catch(U){if(ir(U)&&n(this,R).refreshToken&&or(n(this,f))){C("Access token has expired");let Y=await n(this,R).refreshToken(n(this,f)).catch(be=>{C("Refresh token error: %s",be.message);let pe=new m({message:"Error refreshing access token",type:"token-refresh"});throw pe.source=be,pe});if(Y)return C("Access token refreshed"),this.config({accessToken:Y}),w.headers&&(w.headers.Authorization=`Bearer ${Y}`),await _e(p,w,er).catch(pe=>Te(pe))}else throw U}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,f)}};Q=new WeakMap,f=new WeakMap,R=new WeakMap,K=new WeakMap;var Ae=Me,nr=Ae;var j=t=>t?.type&&t.id&&q.includes(t.type),Oe=t=>t&&typeof t.type<"u"&&t.type&&q.includes(t.type);var ce=h("jsonapi"),I=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>ue(i,s)):e=ue(r,s):e=r,e},ar=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,ue=(t,e,r=[])=>{if(ce("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>ue(ar(p,e),e,[...r,p])):s[i]=ue(ar(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ce("denormalized resource: %O",s),s},me=t=>{ce("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Oe(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Oe(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 s={type:t.type,attributes:e,relationships:r};return j(t)&&(s.id=t.id),ce("normalized resource: %O",s),s};var pr=h("query"),lr=["_any","_all","_in","_not_in_or_null"],Or=t=>lr.some(e=>t.endsWith(e)),cr=["_jcont"],xr=t=>cr.some(e=>t.endsWith(e)),xe=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),$=(t,e)=>{pr("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),xe(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!Or(s))throw new m({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${lr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!xr(s))throw new m({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${cr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),pr("query string params: %O",r)),r};var P={resources:t=>t?[...q].sort():q,singletons:t=>t?[...ye].sort():ye,isSingleton:t=>ye.includes(t),isSdkError:t=>m.isSdkError(t),isApiError:t=>M.isApiError(t),init:t=>de(t),get schemaVersion(){return ve}};var A=h("resource"),Re=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,ze=class{constructor(e){c(this,g);c(this,Ee,{});l(this,g,nr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return A("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=$(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,g).request("GET",a,void 0,{...s,params:p});return I(T)}async list(e,r,s){A("list: %o, %O, %O",e,r||{},s||{});let i=$(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...s,params:i}),p=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 Re(a,p)}async create(e,r,s){A("create: %o, %O, %O",e,r||{},s||{});let i=$(r,e);s?.params&&Object.assign(i,s?.params);let o=me(e),p=await n(this,g).request("POST",e.type,o,{...s,params:i});return I(p)}async update(e,r,s,i){let o=!("id"in e)||P.isSingleton(e.type);A("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=$(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=me(e),N=await n(this,g).request("PATCH",a,T,{...s,params:p});return I(N)}async delete(e,r){A("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){A("fetch: %o, %O, %O",r,s||{},i||{});let o=$(s,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=s,N={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 Re(N,a)}else return a}async action(e,r,s,i){A("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&j(s)?me(s):s;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,Ee=new WeakMap;var ge=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,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},y=class extends ge{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:xe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},he=class extends ge{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},ur=ze;var O=class O extends y{async create(e,r,s){return this.resources.create({...e,type:O.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:O.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:O.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===O.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return O.TYPE}};O.TYPE="api_credentials";var Ne=O,Ie=Ne;var x=class x extends y{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`application_memberships/${i}/membership_profile`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="application_memberships";var Se=x,ke=Se;var _=class _ extends y{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async user(e,r,s){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,s)}async _disable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_disable:!0},r,s)}async _enable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_enable:!0},r,s)}isIdentityProvider(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="identity_providers";var we=_,Ue=we;var v=class v extends y{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`memberships/${i}/membership_profile`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="memberships";var Le=v,Qe=Le;var z=class z extends y{async create(e,r,s){return this.resources.create({...e,type:z.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:z.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`membership_profiles/${i}/organization`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`membership_profiles/${i}/application_memberships`,r,s)}isMembershipProfile(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="membership_profiles";var je=z,qe=je;var S=class S extends y{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="organizations";var $e=S,Fe=$e;var k=class k extends y{async create(e,r,s){return this.resources.create({...e,type:k.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:k.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="permissions";var Ye=k,Ve=Ye;var E=class E extends y{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}async _add_missing_base_permissions(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:E.TYPE,_add_missing_base_permissions:!0},r,s)}isRole(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="roles";var De=E,He=De;var F=class F extends he{async update(e,r,s){return this.resources.update({...e,type:F.TYPE},r,s,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 Je=F,We=Je;var G=class G extends y{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 Be=G,Ke=Be;var q=["api_credentials","application_memberships","identity_providers","memberships","membership_profiles","organizations","permissions","roles","users","versions"],ye=["users"];var mr=h("commercelayer"),ve="1.0.15";var d,Z,X,ee,re,se,te,ie,oe,ne,ae,Ge=class{constructor(e){this.openApiSchemaVersion=ve;c(this,d);c(this,Z);c(this,X);c(this,ee);c(this,re);c(this,se);c(this,te);c(this,ie);c(this,oe);c(this,ne);c(this,ae);mr("new commercelayer provisioning instance %O",e),l(this,d,new ur(e))}get api_credentials(){return n(this,Z)||l(this,Z,new Ie(n(this,d)))}get application_memberships(){return n(this,X)||l(this,X,new ke(n(this,d)))}get identity_providers(){return n(this,ee)||l(this,ee,new Ue(n(this,d)))}get memberships(){return n(this,re)||l(this,re,new Qe(n(this,d)))}get membership_profiles(){return n(this,se)||l(this,se,new qe(n(this,d)))}get organizations(){return n(this,te)||l(this,te,new Fe(n(this,d)))}get permissions(){return n(this,ie)||l(this,ie,new Ve(n(this,d)))}get roles(){return n(this,oe)||l(this,oe,new He(n(this,d)))}get user(){return n(this,ne)||l(this,ne,new We(n(this,d)))}get versions(){return n(this,ae)||l(this,ae,new Ke(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return mr("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 s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap,ae=new WeakMap;var Ze=t=>new Ge(t),de=Ze;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var er=t=>{throw TypeError(t)};var yr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var rr=(t,e,r)=>e.has(t)||er("Cannot "+r);var n=(t,e,r)=>(rr(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>e.has(t)?er("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),l=(t,e,r,s)=>(rr(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var dr=(t,...e)=>{},sr=t=>dr;try{let t=yr("debug");t&&typeof t=="function"&&(sr=t)}catch{}var Rr="clsdk",gr=t=>sr(`${Rr}:${t}`),b=gr;var fe=b("fetch"),H,J,W,ce=class ce extends Error{constructor(r,s,i){super(s);c(this,H);c(this,J);c(this,W);l(this,J,r),l(this,W,s),i&&l(this,H,i.errors)}get errors(){return n(this,H)}get status(){return n(this,J)}get statusText(){return n(this,W)}};H=new WeakMap,J=new WeakMap,W=new WeakMap,ce.isFetchError=r=>r instanceof ce;var D=ce,Pe=async(t,e,r)=>{fe("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("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(s?.response?.onFailure&&(a=await s.response.onFailure(a)),a)throw a}return p};var Q=(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))(Q||{}),B=class B extends Error{static isSdkError(e){return e&&[B.NAME,O.NAME].includes(e.name)&&Object.values(Q).includes(e.type)}constructor(e){super(e.message),this.name=B.NAME,this.type=e.type||"client"}};B.NAME="SdkError";var y=B,K=class K extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=K.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===K.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};K.NAME="ApiError";var O=K,hr=t=>t instanceof TypeError,br=t=>t instanceof DOMException&&t.name==="AbortError",fr=t=>t instanceof DOMException&&t.name==="TimeoutError",tr=t=>O.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),_e=t=>{if(y.isSdkError(t)||O.isApiError(t))throw t;let e=new y({message:t.message});if(D.isFetchError(t)){let r=new O(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else hr(t)?e.type="request":br(t)?e.type="cancel":fr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var Pr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Pr;var ir=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var C=b("client"),Te=t=>`https://provisioning.${t||f.default.domain}/api`,j,P,g,G,Ae=class Ae{constructor(e){c(this,j);c(this,P);c(this,g);c(this,G);C("new client instance %O",e),l(this,j,Te(e.domain)),l(this,P,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,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,l(this,g,r),C("fetch config: %O",r),l(this,G,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,G)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){C("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&&l(this,j,Te(e.domain)),e.accessToken&&(l(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){C("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&C("User-Agent header ignored in request config");let o=i?.domain?Te(i.domain):n(this,j),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,P);I&&(T.Authorization="Bearer "+I);let U={method:e,body:a,headers:T},Ze=i?.timeout||n(this,g).timeout;Ze&&(AbortSignal?.timeout?U.signal=AbortSignal.timeout(Ze):C("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await Pe(p,U,Xe).catch(L=>_e(L))}catch(L){if(tr(L)&&n(this,g).refreshToken&&ir(n(this,P))){C("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(be=>{C("Refresh token error: %s",be.message);let le=new y({message:"Error refreshing access token",type:"token-refresh"});throw le.source=be,le});if(V)return C("Access token refreshed"),this.config({accessToken:V}),U.headers&&(U.headers.Authorization=`Bearer ${V}`),await Pe(p,U,Xe).catch(le=>_e(le))}else throw L}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,P)}};j=new WeakMap,P=new WeakMap,g=new WeakMap,G=new WeakMap;var Ce=Ae,or=Ce;var q=t=>t?.type&&t.id&&$.includes(t.type),Me=t=>t&&typeof t.type<"u"&&t.type&&$.includes(t.type);var ue=b("jsonapi"),S=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>me(i,s)):e=me(r,s):e=r,e},nr=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,me=(t,e,r=[])=>{if(ue("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>me(nr(p,e),e,[...r,p])):s[i]=me(nr(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ue("denormalized resource: %O",s),s},ye=t=>{ue("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Me(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Me(o)&&o.id===null?r[i]={data:null}:o&&(q(o)||Array.isArray(o)&&q(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return q(t)&&(s.id=t.id),ue("normalized resource: %O",s),s};var ar=b("query"),pr=["_any","_all","_in","_not_in_or_null"],_r=t=>pr.some(e=>t.endsWith(e)),lr=["_jcont"],Tr=t=>lr.some(e=>t.endsWith(e)),Oe=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),F=(t,e)=>{ar("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),Oe(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!_r(s))throw new y({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${pr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Tr(s))throw new y({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${lr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),ar("query string params: %O",r)),r};var A={resources:t=>t?[...$].sort():$,singletons:t=>t?[...de].sort():de,isSingleton:t=>de.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>O.isApiError(t),init:t=>ve(t),get schemaVersion(){return xe}};var M=b("resource"),Re=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,ze=class{constructor(e){c(this,h);c(this,Ee,{});l(this,h,or.create(e)),this.localConfig(e)}localConfig(e){}config(e){return M("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...s,params:p});return S(T)}async list(e,r,s){M("list: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...s,params:i}),p=S(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 Re(a,p)}async create(e,r,s){M("create: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=ye(e),p=await n(this,h).request("POST",e.type,o,{...s,params:i});return S(p)}async update(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ye(e),I=await n(this,h).request("PATCH",a,T,{...s,params:p});return S(I)}async delete(e,r){M("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){M("fetch: %o, %O, %O",r,s||{},i||{});let o=F(s,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=S(p);if(Array.isArray(a)){let T=s,I={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new Re(I,a)}else return a}async action(e,r,s,i){M("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&q(s)?ye(s):s;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var ge=class{constructor(e){M("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 S(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},d=class extends ge{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},he=class extends ge{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},cr=ze;var x=class x extends d{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ne=x,Ie=Ne;var v=class v extends d{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`application_memberships/${i}/membership_profile`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Se=v,ke=Se;var _=class _ extends d{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async user(e,r,s){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,s)}async _disable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_disable:!0},r,s)}async _enable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_enable:!0},r,s)}isIdentityProvider(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="identity_providers";var we=_,Ue=we;var z=class z extends d{async create(e,r,s){return this.resources.create({...e,type:z.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:z.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`memberships/${i}/membership_profile`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var Le=z,Qe=Le;var E=class E extends d{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`membership_profiles/${i}/organization`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`membership_profiles/${i}/application_memberships`,r,s)}isMembershipProfile(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="membership_profiles";var je=E,qe=je;var k=class k extends d{async create(e,r,s){return this.resources.create({...e,type:k.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:k.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="organizations";var $e=k,Fe=$e;var w=class w extends d{async create(e,r,s){return this.resources.create({...e,type:w.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:w.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===w.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return w.TYPE}};w.TYPE="permissions";var Ye=w,Ve=Ye;var N=class N extends d{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}async _add_missing_base_permissions(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:N.TYPE,_add_missing_base_permissions:!0},r,s)}isRole(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="roles";var De=N,He=De;var Y=class Y extends he{async update(e,r,s){return this.resources.update({...e,type:Y.TYPE},r,s,this.path())}isUser(e){return e.type&&e.type===Y.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Y.TYPE}path(){return"user"}};Y.TYPE="users";var Je=Y,We=Je;var Z=class Z extends d{isVersion(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="versions";var Be=Z,Ke=Be;var $=["api_credentials","application_memberships","identity_providers","memberships","membership_profiles","organizations","permissions","roles","users","versions"],de=["users"];var ur=b("commercelayer"),xe="1.0.13";var R,X,ee,re,se,te,ie,oe,ne,ae,pe,Ge=class{constructor(e){this.openApiSchemaVersion=xe;c(this,R);c(this,X);c(this,ee);c(this,re);c(this,se);c(this,te);c(this,ie);c(this,oe);c(this,ne);c(this,ae);c(this,pe);ur("new commercelayer provisioning instance %O",e),l(this,R,new cr(e))}get api_credentials(){return n(this,X)||l(this,X,new Ie(n(this,R)))}get application_memberships(){return n(this,ee)||l(this,ee,new ke(n(this,R)))}get identity_providers(){return n(this,re)||l(this,re,new Ue(n(this,R)))}get memberships(){return n(this,se)||l(this,se,new Qe(n(this,R)))}get membership_profiles(){return n(this,te)||l(this,te,new qe(n(this,R)))}get organizations(){return n(this,ie)||l(this,ie,new Fe(n(this,R)))}get permissions(){return n(this,oe)||l(this,oe,new Ve(n(this,R)))}get roles(){return n(this,ne)||l(this,ne,new He(n(this,R)))}get user(){return n(this,ae)||l(this,ae,new We(n(this,R)))}get versions(){return n(this,pe)||l(this,pe,new Ke(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ur("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 s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap,ae=new WeakMap,pe=new WeakMap;var mr=t=>new Ge(t),ve=mr;export{mr as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,ve as default};
|
|
1
|
+
var er=t=>{throw TypeError(t)};var yr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var rr=(t,e,r)=>e.has(t)||er("Cannot "+r);var n=(t,e,r)=>(rr(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>e.has(t)?er("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),l=(t,e,r,s)=>(rr(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var dr=(t,...e)=>{},sr=t=>dr;try{let t=yr("debug");t&&typeof t=="function"&&(sr=t)}catch{}var Rr="clsdk",gr=t=>sr(`${Rr}:${t}`),b=gr;var fe=b("fetch"),H,J,W,ce=class ce extends Error{constructor(r,s,i){super(s);c(this,H);c(this,J);c(this,W);l(this,J,r),l(this,W,s),i&&l(this,H,i.errors)}get errors(){return n(this,H)}get status(){return n(this,J)}get statusText(){return n(this,W)}};H=new WeakMap,J=new WeakMap,W=new WeakMap,ce.isFetchError=r=>r instanceof ce;var D=ce,Pe=async(t,e,r)=>{fe("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("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(s?.response?.onFailure&&(a=await s.response.onFailure(a)),a)throw a}return p};var Q=(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))(Q||{}),B=class B extends Error{static isSdkError(e){return e&&[B.NAME,O.NAME].includes(e.name)&&Object.values(Q).includes(e.type)}constructor(e){super(e.message),this.name=B.NAME,this.type=e.type||"client"}};B.NAME="SdkError";var y=B,K=class K extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=K.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===K.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};K.NAME="ApiError";var O=K,hr=t=>t instanceof TypeError,br=t=>t instanceof DOMException&&t.name==="AbortError",fr=t=>t instanceof DOMException&&t.name==="TimeoutError",tr=t=>O.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),_e=t=>{if(y.isSdkError(t)||O.isApiError(t))throw t;let e=new y({message:t.message});if(D.isFetchError(t)){let r=new O(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else hr(t)?e.type="request":br(t)?e.type="cancel":fr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var Pr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Pr;var ir=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var C=b("client"),Te=t=>`https://provisioning.${t||f.default.domain}/api`,j,P,g,G,Ae=class Ae{constructor(e){c(this,j);c(this,P);c(this,g);c(this,G);C("new client instance %O",e),l(this,j,Te(e.domain)),l(this,P,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,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,l(this,g,r),C("fetch config: %O",r),l(this,G,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,G)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){C("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&&l(this,j,Te(e.domain)),e.accessToken&&(l(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){C("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&C("User-Agent header ignored in request config");let o=i?.domain?Te(i.domain):n(this,j),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,P);I&&(T.Authorization="Bearer "+I);let U={method:e,body:a,headers:T},Ze=i?.timeout||n(this,g).timeout;Ze&&(AbortSignal?.timeout?U.signal=AbortSignal.timeout(Ze):C("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await Pe(p,U,Xe).catch(L=>_e(L))}catch(L){if(tr(L)&&n(this,g).refreshToken&&ir(n(this,P))){C("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(be=>{C("Refresh token error: %s",be.message);let le=new y({message:"Error refreshing access token",type:"token-refresh"});throw le.source=be,le});if(V)return C("Access token refreshed"),this.config({accessToken:V}),U.headers&&(U.headers.Authorization=`Bearer ${V}`),await Pe(p,U,Xe).catch(le=>_e(le))}else throw L}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,P)}};j=new WeakMap,P=new WeakMap,g=new WeakMap,G=new WeakMap;var Ce=Ae,or=Ce;var q=t=>t?.type&&t.id&&$.includes(t.type),Me=t=>t&&typeof t.type<"u"&&t.type&&$.includes(t.type);var ue=b("jsonapi"),S=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>me(i,s)):e=me(r,s):e=r,e},nr=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,me=(t,e,r=[])=>{if(ue("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>me(nr(p,e),e,[...r,p])):s[i]=me(nr(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ue("denormalized resource: %O",s),s},ye=t=>{ue("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Me(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Me(o)&&o.id===null?r[i]={data:null}:o&&(q(o)||Array.isArray(o)&&q(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return q(t)&&(s.id=t.id),ue("normalized resource: %O",s),s};var ar=b("query"),pr=["_any","_all","_in","_not_in_or_null"],_r=t=>pr.some(e=>t.endsWith(e)),lr=["_jcont"],Tr=t=>lr.some(e=>t.endsWith(e)),Oe=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),F=(t,e)=>{ar("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),Oe(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!_r(s))throw new y({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${pr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Tr(s))throw new y({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${lr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),ar("query string params: %O",r)),r};var A={resources:t=>t?[...$].sort():$,singletons:t=>t?[...de].sort():de,isSingleton:t=>de.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>O.isApiError(t),init:t=>ve(t),get schemaVersion(){return xe}};var M=b("resource"),Re=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,ze=class{constructor(e){c(this,h);c(this,Ee,{});l(this,h,or.create(e)),this.localConfig(e)}localConfig(e){}config(e){return M("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...s,params:p});return S(T)}async list(e,r,s){M("list: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...s,params:i}),p=S(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 Re(a,p)}async create(e,r,s){M("create: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=ye(e),p=await n(this,h).request("POST",e.type,o,{...s,params:i});return S(p)}async update(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ye(e),I=await n(this,h).request("PATCH",a,T,{...s,params:p});return S(I)}async delete(e,r){M("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){M("fetch: %o, %O, %O",r,s||{},i||{});let o=F(s,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=S(p);if(Array.isArray(a)){let T=s,I={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new Re(I,a)}else return a}async action(e,r,s,i){M("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&q(s)?ye(s):s;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var ge=class{constructor(e){M("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 S(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},d=class extends ge{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},he=class extends ge{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},cr=ze;var x=class x extends d{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ne=x,Ie=Ne;var v=class v extends d{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`application_memberships/${i}/membership_profile`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Se=v,ke=Se;var _=class _ extends d{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async user(e,r,s){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,s)}async _disable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_disable:!0},r,s)}async _enable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_enable:!0},r,s)}isIdentityProvider(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="identity_providers";var we=_,Ue=we;var z=class z extends d{async create(e,r,s){return this.resources.create({...e,type:z.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:z.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`memberships/${i}/membership_profile`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var Le=z,Qe=Le;var E=class E extends d{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`membership_profiles/${i}/organization`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`membership_profiles/${i}/application_memberships`,r,s)}isMembershipProfile(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="membership_profiles";var je=E,qe=je;var k=class k extends d{async create(e,r,s){return this.resources.create({...e,type:k.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:k.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="organizations";var $e=k,Fe=$e;var w=class w extends d{async create(e,r,s){return this.resources.create({...e,type:w.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:w.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===w.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return w.TYPE}};w.TYPE="permissions";var Ye=w,Ve=Ye;var N=class N extends d{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}async _add_missing_base_permissions(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:N.TYPE,_add_missing_base_permissions:!0},r,s)}isRole(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="roles";var De=N,He=De;var Y=class Y extends he{async update(e,r,s){return this.resources.update({...e,type:Y.TYPE},r,s,this.path())}isUser(e){return e.type&&e.type===Y.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Y.TYPE}path(){return"user"}};Y.TYPE="users";var Je=Y,We=Je;var Z=class Z extends d{isVersion(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="versions";var Be=Z,Ke=Be;var $=["api_credentials","application_memberships","identity_providers","memberships","membership_profiles","organizations","permissions","roles","users","versions"],de=["users"];var ur=b("commercelayer"),xe="1.0.15";var R,X,ee,re,se,te,ie,oe,ne,ae,pe,Ge=class{constructor(e){this.openApiSchemaVersion=xe;c(this,R);c(this,X);c(this,ee);c(this,re);c(this,se);c(this,te);c(this,ie);c(this,oe);c(this,ne);c(this,ae);c(this,pe);ur("new commercelayer provisioning instance %O",e),l(this,R,new cr(e))}get api_credentials(){return n(this,X)||l(this,X,new Ie(n(this,R)))}get application_memberships(){return n(this,ee)||l(this,ee,new ke(n(this,R)))}get identity_providers(){return n(this,re)||l(this,re,new Ue(n(this,R)))}get memberships(){return n(this,se)||l(this,se,new Qe(n(this,R)))}get membership_profiles(){return n(this,te)||l(this,te,new qe(n(this,R)))}get organizations(){return n(this,ie)||l(this,ie,new Fe(n(this,R)))}get permissions(){return n(this,oe)||l(this,oe,new Ve(n(this,R)))}get roles(){return n(this,ne)||l(this,ne,new He(n(this,R)))}get user(){return n(this,ae)||l(this,ae,new We(n(this,R)))}get versions(){return n(this,pe)||l(this,pe,new Ke(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ur("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 s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap,ae=new WeakMap,pe=new WeakMap;var mr=t=>new Ge(t),ve=mr;export{mr as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,ve as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/provisioning-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"node": ">=20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/preset-env": "^7.28.
|
|
37
|
+
"@babel/preset-env": "^7.28.3",
|
|
38
38
|
"@babel/preset-typescript": "^7.27.1",
|
|
39
39
|
"@commercelayer/eslint-config-ts": "1.4.5",
|
|
40
40
|
"@commercelayer/js-auth": "^6.7.2",
|
|
@@ -42,16 +42,16 @@
|
|
|
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.18.10",
|
|
46
46
|
"dotenv": "^16.6.1",
|
|
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
|
-
"semantic-release": "^24.2.
|
|
51
|
+
"semantic-release": "^24.2.9",
|
|
52
52
|
"tsup": "^8.5.0",
|
|
53
|
-
"tsx": "^4.20.
|
|
54
|
-
"typescript": "^5.
|
|
53
|
+
"tsx": "^4.20.6",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
55
|
},
|
|
56
56
|
"repository": "github:commercelayer/provisioning-sdk",
|
|
57
57
|
"bugs": "https://github.com/commercelayer/provisioning-sdk/issues",
|