@commercelayer/provisioning-sdk 2.0.0-beta.16 → 2.0.0-beta.17

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 CHANGED
@@ -219,12 +219,12 @@ interface Version extends Resource {
219
219
  event: string;
220
220
  /**
221
221
  * The object changes payload..
222
- * @example ```"[object Object]"```
222
+ * @example ```"{"name":["previous","new"]}"```
223
223
  */
224
224
  changes: Record<string, any>;
225
225
  /**
226
226
  * Information about who triggered the change, only showed when it's from a JWT token..
227
- * @example ```"[object Object]"```
227
+ * @example ```"{"application":{"id":"DNOPYiZYpn","kind":"integration","public":true}}"```
228
228
  */
229
229
  who: Record<string, any>;
230
230
  }
@@ -268,7 +268,7 @@ interface Permission extends Resource {
268
268
  subject: string;
269
269
  /**
270
270
  * An object that contains additional restrictions..
271
- * @example ```"[object Object]"```
271
+ * @example ```"{"foo":"bar"}"```
272
272
  */
273
273
  restrictions: Record<string, any>;
274
274
  organization?: Nullable<Organization>;
@@ -406,7 +406,7 @@ interface ApplicationMembership extends Resource {
406
406
  readonly type: ApplicationMembershipType;
407
407
  /**
408
408
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
409
- * @example ```"[object Object]"```
409
+ * @example ```"{"market_id_in":[202,203]}"```
410
410
  */
411
411
  filters?: Nullable<Record<string, any>>;
412
412
  api_credential?: Nullable<ApiCredential>;
@@ -417,7 +417,7 @@ interface ApplicationMembership extends Resource {
417
417
  interface ApplicationMembershipCreate extends ResourceCreate {
418
418
  /**
419
419
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
420
- * @example ```"[object Object]"```
420
+ * @example ```"{"market_id_in":[202,203]}"```
421
421
  */
422
422
  filters?: Nullable<Record<string, any>>;
423
423
  api_credential: ApiCredentialRel$1;
@@ -428,7 +428,7 @@ interface ApplicationMembershipCreate extends ResourceCreate {
428
428
  interface ApplicationMembershipUpdate extends ResourceUpdate {
429
429
  /**
430
430
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
431
- * @example ```"[object Object]"```
431
+ * @example ```"{"market_id_in":[202,203]}"```
432
432
  */
433
433
  filters?: Nullable<Record<string, any>>;
434
434
  role?: Nullable<RoleRel$2>;
@@ -548,7 +548,7 @@ interface Organization extends Resource {
548
548
  domain: string;
549
549
  /**
550
550
  * The organization's configuration..
551
- * @example ```"[object Object]"```
551
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
552
552
  */
553
553
  config?: Nullable<Record<string, any>>;
554
554
  /**
@@ -624,7 +624,7 @@ interface Organization extends Resource {
624
624
  can_switch_live: boolean;
625
625
  /**
626
626
  * Information about the current subscription such as the plan type, limits and subscription totals counter..
627
- * @example ```"[object Object]"```
627
+ * @example ```"{"plan_type":"growth","limits":{"markets":5,"skus":10000,"organizations":2,"memberships":5},"totals":{"organizations":1,"markets":0,"memberships":2,"skus":0}}"```
628
628
  */
629
629
  subscription_info: Record<string, any>;
630
630
  memberships?: Nullable<Membership[]>;
@@ -640,7 +640,7 @@ interface OrganizationCreate extends ResourceCreate {
640
640
  name: string;
641
641
  /**
642
642
  * The organization's configuration..
643
- * @example ```"[object Object]"```
643
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
644
644
  */
645
645
  config?: Nullable<Record<string, any>>;
646
646
  /**
@@ -709,7 +709,7 @@ interface OrganizationUpdate extends ResourceUpdate {
709
709
  name?: Nullable<string>;
710
710
  /**
711
711
  * The organization's configuration..
712
- * @example ```"[object Object]"```
712
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
713
713
  */
714
714
  config?: Nullable<Record<string, any>>;
715
715
  /**
@@ -1063,7 +1063,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
1063
1063
  type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
1064
1064
  declare class CommerceLayerProvisioningClient {
1065
1065
  #private;
1066
- readonly openApiSchemaVersion = "1.0.4";
1066
+ readonly openApiSchemaVersion = "1.0.5";
1067
1067
  constructor(config: CommerceLayerInitConfig);
1068
1068
  get api_credentials(): ApiCredentials;
1069
1069
  get application_memberships(): ApplicationMemberships;
package/lib/index.d.ts CHANGED
@@ -219,12 +219,12 @@ interface Version extends Resource {
219
219
  event: string;
220
220
  /**
221
221
  * The object changes payload..
222
- * @example ```"[object Object]"```
222
+ * @example ```"{"name":["previous","new"]}"```
223
223
  */
224
224
  changes: Record<string, any>;
225
225
  /**
226
226
  * Information about who triggered the change, only showed when it's from a JWT token..
227
- * @example ```"[object Object]"```
227
+ * @example ```"{"application":{"id":"DNOPYiZYpn","kind":"integration","public":true}}"```
228
228
  */
229
229
  who: Record<string, any>;
230
230
  }
@@ -268,7 +268,7 @@ interface Permission extends Resource {
268
268
  subject: string;
269
269
  /**
270
270
  * An object that contains additional restrictions..
271
- * @example ```"[object Object]"```
271
+ * @example ```"{"foo":"bar"}"```
272
272
  */
273
273
  restrictions: Record<string, any>;
274
274
  organization?: Nullable<Organization>;
@@ -406,7 +406,7 @@ interface ApplicationMembership extends Resource {
406
406
  readonly type: ApplicationMembershipType;
407
407
  /**
408
408
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
409
- * @example ```"[object Object]"```
409
+ * @example ```"{"market_id_in":[202,203]}"```
410
410
  */
411
411
  filters?: Nullable<Record<string, any>>;
412
412
  api_credential?: Nullable<ApiCredential>;
@@ -417,7 +417,7 @@ interface ApplicationMembership extends Resource {
417
417
  interface ApplicationMembershipCreate extends ResourceCreate {
418
418
  /**
419
419
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
420
- * @example ```"[object Object]"```
420
+ * @example ```"{"market_id_in":[202,203]}"```
421
421
  */
422
422
  filters?: Nullable<Record<string, any>>;
423
423
  api_credential: ApiCredentialRel$1;
@@ -428,7 +428,7 @@ interface ApplicationMembershipCreate extends ResourceCreate {
428
428
  interface ApplicationMembershipUpdate extends ResourceUpdate {
429
429
  /**
430
430
  * Set of key-value pairs that contains restrictions and scopes of the application membership..
431
- * @example ```"[object Object]"```
431
+ * @example ```"{"market_id_in":[202,203]}"```
432
432
  */
433
433
  filters?: Nullable<Record<string, any>>;
434
434
  role?: Nullable<RoleRel$2>;
@@ -548,7 +548,7 @@ interface Organization extends Resource {
548
548
  domain: string;
549
549
  /**
550
550
  * The organization's configuration..
551
- * @example ```"[object Object]"```
551
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
552
552
  */
553
553
  config?: Nullable<Record<string, any>>;
554
554
  /**
@@ -624,7 +624,7 @@ interface Organization extends Resource {
624
624
  can_switch_live: boolean;
625
625
  /**
626
626
  * Information about the current subscription such as the plan type, limits and subscription totals counter..
627
- * @example ```"[object Object]"```
627
+ * @example ```"{"plan_type":"growth","limits":{"markets":5,"skus":10000,"organizations":2,"memberships":5},"totals":{"organizations":1,"markets":0,"memberships":2,"skus":0}}"```
628
628
  */
629
629
  subscription_info: Record<string, any>;
630
630
  memberships?: Nullable<Membership[]>;
@@ -640,7 +640,7 @@ interface OrganizationCreate extends ResourceCreate {
640
640
  name: string;
641
641
  /**
642
642
  * The organization's configuration..
643
- * @example ```"[object Object]"```
643
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
644
644
  */
645
645
  config?: Nullable<Record<string, any>>;
646
646
  /**
@@ -709,7 +709,7 @@ interface OrganizationUpdate extends ResourceUpdate {
709
709
  name?: Nullable<string>;
710
710
  /**
711
711
  * The organization's configuration..
712
- * @example ```"[object Object]"```
712
+ * @example ```"{"mfe":{"default":{"links":{"cart":"https://cart.example.com/:order_id?accessToken=:access_token","checkout":"https://checkout.example.com/:order_id?accessToken=:accessToken","identity":"https://example.com/login","microstore":"https://example.com/microstore/?accessToken=:access_token","my_account":"https://example.com/my-custom-account?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:lang/:orderId","billing_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"shipping_countries":[{"value":"ES","label":"Espana"},{"value":"IT","label":"Italia"},{"value":"US","label":"Unites States of America"}],"billing_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"shipping_states":{"FR":[{"value":"PA","label":"Paris"},{"value":"LY","label":"Lyon"},{"value":"NI","label":"Nice"},{"value":"MA","label":"Marseille"},{"value":"BO","label":"Bordeaux"}]},"default_country":"US"},"urls":{"privacy":"https://example.com/privacy/:lang","terms":"https://example.com/terms/:lang"}},"market:id:ZKcv13rT":{"links":{"cart":"https://example.com/custom-cart/:order_id?accessToken=:access_token"},"checkout":{"thankyou_page":"https://example.com/thanks/:order_id"}}}}"```
713
713
  */
714
714
  config?: Nullable<Record<string, any>>;
715
715
  /**
@@ -1063,7 +1063,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
1063
1063
  type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
1064
1064
  declare class CommerceLayerProvisioningClient {
1065
1065
  #private;
1066
- readonly openApiSchemaVersion = "1.0.4";
1066
+ readonly openApiSchemaVersion = "1.0.5";
1067
1067
  constructor(config: CommerceLayerInitConfig);
1068
1068
  get api_credentials(): ApiCredentials;
1069
1069
  get application_memberships(): ApplicationMemberships;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ue=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var rr=Object.getOwnPropertyNames;var sr=Object.prototype.hasOwnProperty;var tr=(t,e)=>{for(var r in e)ue(t,r,{get:e[r],enumerable:!0})},ir=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of rr(e))!sr.call(t,i)&&i!==r&&ue(t,i,{get:()=>e[i],enumerable:!(s=er(e,i))||s.enumerable});return t};var or=t=>ir(ue({},"__esModule",{value:!0}),t);var je=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var n=(t,e,r)=>(je(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},p=(t,e,r,s)=>(je(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var Rr={};tr(Rr,{CommerceLayerProvisioning:()=>Ue,CommerceLayerProvisioningStatic:()=>b,default:()=>ne});module.exports=or(Rr);var nr=(t,...e)=>{},$e=t=>nr;try{let t=require("debug");t&&typeof t=="function"&&($e=t)}catch{}var ar="clsdk",pr=t=>$e(`${ar}:${t}`),g=pr;var cr=g("fetch"),k,q,j,ee=class ee extends Error{constructor(r,s,i){super(s);c(this,k,void 0);c(this,q,void 0);c(this,j,void 0);p(this,q,r),p(this,j,s),i&&p(this,k,i.errors)}get errors(){return n(this,k)}get status(){return n(this,q)}get statusText(){return n(this,j)}};k=new WeakMap,q=new WeakMap,j=new WeakMap,ee.isFetchError=r=>r instanceof ee;var U=ee,Ve=async(t,e,r)=>{cr("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 a=await o.json().catch(()=>{});if(!o.ok){let u=new U(o.status,o.statusText,a);if(s?.response?.onFailure&&(u=await s.response.onFailure(u)),u)throw u}return a};var re=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a))(re||{}),$=class $ extends Error{static isSdkError(e){return e&&[$.NAME,S.NAME].includes(e.name)&&Object.values(re).includes(e.type)}constructor(e){super(e.message),this.name=$.NAME,this.type=e.type||"client"}};$.NAME="SdkError";var m=$,V=class V extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=V.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===V.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};V.NAME="ApiError";var S=V,lr=t=>t instanceof TypeError,ur=t=>t instanceof DOMException&&t.name==="AbortError",mr=t=>t instanceof DOMException&&t.name==="TimeoutError",Fe=t=>{let e=new m({message:t.message});if(U.isFetchError(t)){let r=new S(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 lr(t)?e.type="request":ur(t)?e.type="cancel":mr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var yr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},h=yr;var F=g("client"),me=t=>`https://provisioning.${t||h.default.domain}/api`,_,T,f,D,Re=class Re{constructor(e){c(this,_,void 0);c(this,T,void 0);c(this,f,void 0);c(this,D,void 0);F("new client instance %O",e),p(this,_,me(e.domain)),p(this,T,e.accessToken);let r={timeout:e.timeout||h.client.timeout},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,T)},o=e.userAgent;o&&(i["User-Agent"]=o),r.headers=i,p(this,f,r),F("fetch config: %O",r),p(this,D,{})}static create(e){for(let r of h.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Re(e)}get interceptors(){return n(this,D)}get requestHeaders(){return n(this,f).headers||(n(this,f).headers={}),n(this,f).headers}config(e){F("config %o",e);let r=n(this,f);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,f).fetch=e.fetch),e.domain&&p(this,_,me(e.domain)),e.accessToken&&(p(this,T,e.accessToken),r.headers.Authorization="Bearer "+n(this,T)),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){F("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&F("User-Agent header ignored in request config");let o=i?.domain?me(i.domain):n(this,_),a=new URL(`${o}/${r}`),u=s?JSON.stringify({data:s}):void 0,C={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,T);I&&(C.Authorization="Bearer "+I);let ke={method:e,body:u,headers:C},qe=i?.timeout||n(this,f).timeout;qe&&(ke.signal=AbortSignal.timeout(qe)),i?.params&&Object.entries(i?.params).forEach(([le,Ze])=>{a.searchParams.append(le,String(Ze))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,f).fetch};return await Ve(a,ke,Xe).catch(le=>Fe(le))}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}};_=new WeakMap,T=new WeakMap,f=new WeakMap,D=new WeakMap;var ye=Re,De=ye;var v=t=>t?.type&&t.id&&L.includes(t.type),de=t=>t&&typeof t.type<"u"&&t.type&&L.includes(t.type);var se=g("jsonapi"),M=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>te(i,s)):e=te(r,s):e=r,e},Ye=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,te=(t,e,r=[])=>{if(se("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(a=>a.id===o.id&&a.type===o.type).length>=h.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(a=>te(Ye(a,e),e,[...r,a])):s[i]=te(Ye(o,e),e,[...r,o]):o===null&&(s[i]=null)}),se("denormalized resource: %O",s),s},ie=t=>{se("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&&de(o[0])&&o[0].id===null?r[i]={data:[]}:o&&de(o)&&o.id===null?r[i]={data:null}:o&&(v(o)||Array.isArray(o)&&v(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return v(t)&&(s.id=t.id),se("normalized resource: %O",s),s};var He=g("query"),We=["_any","_all","_in"],Je=["_jcont"],ge=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),Q=(t,e)=>{He("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(",")})),ge(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=s.substring(s.lastIndexOf("_")),a;if(Array.isArray(i)){if(!We.includes(o))throw new m({message:`Wrong ${o} filter: Array value is supported only for the following filters: ${We.join(", ")}`,type:"request"});a=i.join(",")}else if(typeof i=="object"){if(!Je.includes(o))throw new m({message:`Wrong ${o} filter: Object value is supported only for the following filters: ${Je.join(", ")}`,type:"request"});a=JSON.stringify(i)}else a=String(i);r[`filter[q][${s}]`]=a})),He("query string params: %O",r)),r};var b={resources:t=>t?[...L].sort():L,singletons:t=>t?[...oe].sort():oe,isSingleton:t=>oe.includes(t),isSdkError:t=>m.isSdkError(t),isApiError:t=>S.isApiError(t),init:t=>ne(t),get schemaVersion(){return he}};var P=g("resource"),ae=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 d,be,fe=class{constructor(e){c(this,d,void 0);c(this,be,{});p(this,d,De.create(e)),this.localConfig(e)}localConfig(e){}config(e){return P("config %o",e),this.localConfig(e),n(this,d).config(e),this}get client(){return n(this,d)}async retrieve(e,r,s){let i=!("id"in e)||b.isSingleton(e.type);P("retrieve:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=Q(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,u=await n(this,d).request("GET",a,void 0,{...s,params:o});return M(u)}async list(e,r,s){P("list: %o, %O, %O",e,r||{},s||{});let i=Q(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,d).request("GET",`${e.type}`,void 0,{...s,params:i}),a=M(o),u={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||h.default.pageNumber,recordsPerPage:r?.pageSize||h.default.pageSize};return new ae(u,a)}async create(e,r,s){P("create: %o, %O, %O",e,r||{},s||{});let i=Q(r,e);s?.params&&Object.assign(i,s?.params);let o=ie(e),a=await n(this,d).request("POST",e.type,o,{...s,params:i});return M(a)}async update(e,r,s){let i=!("id"in e)||b.isSingleton(e.type);P("update:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=Q(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,u=ie(e),C=await n(this,d).request("PATCH",a,u,{...s,params:o});return M(C)}async delete(e,r){P("delete: %o, %O",e,r||{}),await n(this,d).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){P("fetch: %o, %O, %O",r,s||{},i||{});let o=Q(s,e);i?.params&&Object.assign(o,i?.params);let a=await n(this,d).request("GET",r,void 0,{...i,params:o}),u=M(a);if(Array.isArray(u)){let C=s,I={pageCount:Number(a.meta?.page_count),recordCount:Number(a.meta?.record_count),currentPage:C?.pageNumber||h.default.pageNumber,recordsPerPage:C?.pageSize||h.default.pageSize};return new ae(I,u)}else return u}async action(e,r,s,i){P("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let a=s&&v(s)?ie(s):s;await n(this,d).request(e,r,a,{...i,params:o})}};d=new WeakMap,be=new WeakMap;var pe=class{constructor(e){P("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()}))}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return M(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s)}},y=class extends pe{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:ge(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ce=class extends pe{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r)}},Ge=fe;var A=class A extends y{async create(e,r,s){return this.resources.create({...e,type:A.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:A.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:A.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===A.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return A.TYPE}};A.TYPE="api_credentials";var Pe=A,Ce=Pe;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 api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===O.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return O.TYPE}};O.TYPE="application_memberships";var Te=O,Ae=Te;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 resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="memberships";var Oe=x,xe=Oe;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 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===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="organizations";var Me=z,ze=Me;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"},`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===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="permissions";var Ee=E,Ne=Ee;var N=class N extends y{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="roles";var Se=N,_e=Se;var w=class w extends ce{async update(e,r,s){let i=await this.retrieve(r,s);return this.resources.update({...e,id:i.id,type:w.TYPE},r,s)}isUser(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="user";var ve=w,Le=ve;var Y=class Y extends y{isVersion(e){return e.type&&e.type===Y.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Y.TYPE}};Y.TYPE="versions";var Qe=Y,we=Qe;var L=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],oe=["user"];var Ke=g("commercelayer"),he="1.0.4";var R,H,W,J,B,G,K,X,Z,Ie=class{constructor(e){this.openApiSchemaVersion=he;c(this,R,void 0);c(this,H,void 0);c(this,W,void 0);c(this,J,void 0);c(this,B,void 0);c(this,G,void 0);c(this,K,void 0);c(this,X,void 0);c(this,Z,void 0);Ke("new commercelayer provisioning instance %O",e),p(this,R,new Ge(e))}get api_credentials(){return n(this,H)||p(this,H,new Ce(n(this,R)))}get application_memberships(){return n(this,W)||p(this,W,new Ae(n(this,R)))}get memberships(){return n(this,J)||p(this,J,new xe(n(this,R)))}get organizations(){return n(this,B)||p(this,B,new ze(n(this,R)))}get permissions(){return n(this,G)||p(this,G,new Ne(n(this,R)))}get roles(){return n(this,K)||p(this,K,new _e(n(this,R)))}get user(){return n(this,X)||p(this,X,new Le(n(this,R)))}get versions(){return n(this,Z)||p(this,Z,new we(n(this,R)))}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return Ke("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return b.resources()}singletons(){return b.singletons()}isSingleton(e){return b.isSingleton(e)}isApiError(e){return b.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}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((a,u)=>{o[u]=a}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(e=1){this.interceptors.rawReader=void 0}};R=new WeakMap,H=new WeakMap,W=new WeakMap,J=new WeakMap,B=new WeakMap,G=new WeakMap,K=new WeakMap,X=new WeakMap,Z=new WeakMap;var Ue=t=>new Ie(t),ne=Ue;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
1
+ "use strict";var ue=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var rr=Object.getOwnPropertyNames;var sr=Object.prototype.hasOwnProperty;var tr=(t,e)=>{for(var r in e)ue(t,r,{get:e[r],enumerable:!0})},ir=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of rr(e))!sr.call(t,i)&&i!==r&&ue(t,i,{get:()=>e[i],enumerable:!(s=er(e,i))||s.enumerable});return t};var or=t=>ir(ue({},"__esModule",{value:!0}),t);var je=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var n=(t,e,r)=>(je(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},p=(t,e,r,s)=>(je(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var Rr={};tr(Rr,{CommerceLayerProvisioning:()=>Ue,CommerceLayerProvisioningStatic:()=>b,default:()=>ne});module.exports=or(Rr);var nr=(t,...e)=>{},$e=t=>nr;try{let t=require("debug");t&&typeof t=="function"&&($e=t)}catch{}var ar="clsdk",pr=t=>$e(`${ar}:${t}`),g=pr;var cr=g("fetch"),k,q,j,ee=class ee extends Error{constructor(r,s,i){super(s);c(this,k,void 0);c(this,q,void 0);c(this,j,void 0);p(this,q,r),p(this,j,s),i&&p(this,k,i.errors)}get errors(){return n(this,k)}get status(){return n(this,q)}get statusText(){return n(this,j)}};k=new WeakMap,q=new WeakMap,j=new WeakMap,ee.isFetchError=r=>r instanceof ee;var U=ee,Ve=async(t,e,r)=>{cr("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 a=await o.json().catch(()=>{});if(!o.ok){let u=new U(o.status,o.statusText,a);if(s?.response?.onFailure&&(u=await s.response.onFailure(u)),u)throw u}return a};var re=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a))(re||{}),$=class $ extends Error{static isSdkError(e){return e&&[$.NAME,S.NAME].includes(e.name)&&Object.values(re).includes(e.type)}constructor(e){super(e.message),this.name=$.NAME,this.type=e.type||"client"}};$.NAME="SdkError";var m=$,V=class V extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=V.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===V.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};V.NAME="ApiError";var S=V,lr=t=>t instanceof TypeError,ur=t=>t instanceof DOMException&&t.name==="AbortError",mr=t=>t instanceof DOMException&&t.name==="TimeoutError",Fe=t=>{let e=new m({message:t.message});if(U.isFetchError(t)){let r=new S(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 lr(t)?e.type="request":ur(t)?e.type="cancel":mr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var yr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},h=yr;var F=g("client"),me=t=>`https://provisioning.${t||h.default.domain}/api`,_,T,f,D,Re=class Re{constructor(e){c(this,_,void 0);c(this,T,void 0);c(this,f,void 0);c(this,D,void 0);F("new client instance %O",e),p(this,_,me(e.domain)),p(this,T,e.accessToken);let r={timeout:e.timeout||h.client.timeout},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,T)},o=e.userAgent;o&&(i["User-Agent"]=o),r.headers=i,p(this,f,r),F("fetch config: %O",r),p(this,D,{})}static create(e){for(let r of h.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Re(e)}get interceptors(){return n(this,D)}get requestHeaders(){return n(this,f).headers||(n(this,f).headers={}),n(this,f).headers}config(e){F("config %o",e);let r=n(this,f);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,f).fetch=e.fetch),e.domain&&p(this,_,me(e.domain)),e.accessToken&&(p(this,T,e.accessToken),r.headers.Authorization="Bearer "+n(this,T)),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){F("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&F("User-Agent header ignored in request config");let o=i?.domain?me(i.domain):n(this,_),a=new URL(`${o}/${r}`),u=s?JSON.stringify({data:s}):void 0,C={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,T);I&&(C.Authorization="Bearer "+I);let ke={method:e,body:u,headers:C},qe=i?.timeout||n(this,f).timeout;qe&&(ke.signal=AbortSignal.timeout(qe)),i?.params&&Object.entries(i?.params).forEach(([le,Ze])=>{a.searchParams.append(le,String(Ze))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,f).fetch};return await Ve(a,ke,Xe).catch(le=>Fe(le))}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}};_=new WeakMap,T=new WeakMap,f=new WeakMap,D=new WeakMap;var ye=Re,De=ye;var v=t=>t?.type&&t.id&&L.includes(t.type),de=t=>t&&typeof t.type<"u"&&t.type&&L.includes(t.type);var se=g("jsonapi"),M=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>te(i,s)):e=te(r,s):e=r,e},Ye=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,te=(t,e,r=[])=>{if(se("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(a=>a.id===o.id&&a.type===o.type).length>=h.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(a=>te(Ye(a,e),e,[...r,a])):s[i]=te(Ye(o,e),e,[...r,o]):o===null&&(s[i]=null)}),se("denormalized resource: %O",s),s},ie=t=>{se("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&&de(o[0])&&o[0].id===null?r[i]={data:[]}:o&&de(o)&&o.id===null?r[i]={data:null}:o&&(v(o)||Array.isArray(o)&&v(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return v(t)&&(s.id=t.id),se("normalized resource: %O",s),s};var He=g("query"),We=["_any","_all","_in"],Je=["_jcont"],ge=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),Q=(t,e)=>{He("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(",")})),ge(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=s.substring(s.lastIndexOf("_")),a;if(Array.isArray(i)){if(!We.includes(o))throw new m({message:`Wrong ${o} filter: Array value is supported only for the following filters: ${We.join(", ")}`,type:"request"});a=i.join(",")}else if(typeof i=="object"){if(!Je.includes(o))throw new m({message:`Wrong ${o} filter: Object value is supported only for the following filters: ${Je.join(", ")}`,type:"request"});a=JSON.stringify(i)}else a=String(i);r[`filter[q][${s}]`]=a})),He("query string params: %O",r)),r};var b={resources:t=>t?[...L].sort():L,singletons:t=>t?[...oe].sort():oe,isSingleton:t=>oe.includes(t),isSdkError:t=>m.isSdkError(t),isApiError:t=>S.isApiError(t),init:t=>ne(t),get schemaVersion(){return he}};var P=g("resource"),ae=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 d,be,fe=class{constructor(e){c(this,d,void 0);c(this,be,{});p(this,d,De.create(e)),this.localConfig(e)}localConfig(e){}config(e){return P("config %o",e),this.localConfig(e),n(this,d).config(e),this}get client(){return n(this,d)}async retrieve(e,r,s){let i=!("id"in e)||b.isSingleton(e.type);P("retrieve:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=Q(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,u=await n(this,d).request("GET",a,void 0,{...s,params:o});return M(u)}async list(e,r,s){P("list: %o, %O, %O",e,r||{},s||{});let i=Q(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,d).request("GET",`${e.type}`,void 0,{...s,params:i}),a=M(o),u={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||h.default.pageNumber,recordsPerPage:r?.pageSize||h.default.pageSize};return new ae(u,a)}async create(e,r,s){P("create: %o, %O, %O",e,r||{},s||{});let i=Q(r,e);s?.params&&Object.assign(i,s?.params);let o=ie(e),a=await n(this,d).request("POST",e.type,o,{...s,params:i});return M(a)}async update(e,r,s){let i=!("id"in e)||b.isSingleton(e.type);P("update:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=Q(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,u=ie(e),C=await n(this,d).request("PATCH",a,u,{...s,params:o});return M(C)}async delete(e,r){P("delete: %o, %O",e,r||{}),await n(this,d).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){P("fetch: %o, %O, %O",r,s||{},i||{});let o=Q(s,e);i?.params&&Object.assign(o,i?.params);let a=await n(this,d).request("GET",r,void 0,{...i,params:o}),u=M(a);if(Array.isArray(u)){let C=s,I={pageCount:Number(a.meta?.page_count),recordCount:Number(a.meta?.record_count),currentPage:C?.pageNumber||h.default.pageNumber,recordsPerPage:C?.pageSize||h.default.pageSize};return new ae(I,u)}else return u}async action(e,r,s,i){P("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let a=s&&v(s)?ie(s):s;await n(this,d).request(e,r,a,{...i,params:o})}};d=new WeakMap,be=new WeakMap;var pe=class{constructor(e){P("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()}))}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return M(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s)}},y=class extends pe{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:ge(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ce=class extends pe{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r)}},Ge=fe;var A=class A extends y{async create(e,r,s){return this.resources.create({...e,type:A.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:A.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:A.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===A.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return A.TYPE}};A.TYPE="api_credentials";var Pe=A,Ce=Pe;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 api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===O.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return O.TYPE}};O.TYPE="application_memberships";var Te=O,Ae=Te;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 resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="memberships";var Oe=x,xe=Oe;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 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===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="organizations";var Me=z,ze=Me;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"},`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===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="permissions";var Ee=E,Ne=Ee;var N=class N extends y{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="roles";var Se=N,_e=Se;var w=class w extends ce{async update(e,r,s){let i=await this.retrieve(r,s);return this.resources.update({...e,id:i.id,type:w.TYPE},r,s)}isUser(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="user";var ve=w,Le=ve;var Y=class Y extends y{isVersion(e){return e.type&&e.type===Y.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Y.TYPE}};Y.TYPE="versions";var Qe=Y,we=Qe;var L=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],oe=["user"];var Ke=g("commercelayer"),he="1.0.5";var R,H,W,J,B,G,K,X,Z,Ie=class{constructor(e){this.openApiSchemaVersion=he;c(this,R,void 0);c(this,H,void 0);c(this,W,void 0);c(this,J,void 0);c(this,B,void 0);c(this,G,void 0);c(this,K,void 0);c(this,X,void 0);c(this,Z,void 0);Ke("new commercelayer provisioning instance %O",e),p(this,R,new Ge(e))}get api_credentials(){return n(this,H)||p(this,H,new Ce(n(this,R)))}get application_memberships(){return n(this,W)||p(this,W,new Ae(n(this,R)))}get memberships(){return n(this,J)||p(this,J,new xe(n(this,R)))}get organizations(){return n(this,B)||p(this,B,new ze(n(this,R)))}get permissions(){return n(this,G)||p(this,G,new Ne(n(this,R)))}get roles(){return n(this,K)||p(this,K,new _e(n(this,R)))}get user(){return n(this,X)||p(this,X,new Le(n(this,R)))}get versions(){return n(this,Z)||p(this,Z,new we(n(this,R)))}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return Ke("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return b.resources()}singletons(){return b.singletons()}isSingleton(e){return b.isSingleton(e)}isApiError(e){return b.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}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((a,u)=>{o[u]=a}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(e=1){this.interceptors.rawReader=void 0}};R=new WeakMap,H=new WeakMap,W=new WeakMap,J=new WeakMap,B=new WeakMap,G=new WeakMap,K=new WeakMap,X=new WeakMap,Z=new WeakMap;var Ue=t=>new Ie(t),ne=Ue;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
package/lib/index.mjs CHANGED
@@ -1 +1 @@
1
- var er=(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 qe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var n=(t,e,r)=>(qe(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},p=(t,e,r,s)=>(qe(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var rr=(t,...e)=>{},je=t=>rr;try{let t=er("debug");t&&typeof t=="function"&&(je=t)}catch{}var sr="clsdk",tr=t=>je(`${sr}:${t}`),h=tr;var ir=h("fetch"),q,j,$,re=class re extends Error{constructor(r,s,i){super(s);c(this,q,void 0);c(this,j,void 0);c(this,$,void 0);p(this,j,r),p(this,$,s),i&&p(this,q,i.errors)}get errors(){return n(this,q)}get status(){return n(this,j)}get statusText(){return n(this,$)}};q=new WeakMap,j=new WeakMap,$=new WeakMap,re.isFetchError=r=>r instanceof re;var k=re,$e=async(t,e,r)=>{ir("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 a=await o.json().catch(()=>{});if(!o.ok){let m=new k(o.status,o.statusText,a);if(s?.response?.onFailure&&(m=await s.response.onFailure(m)),m)throw m}return a};var se=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a))(se||{}),V=class V extends Error{static isSdkError(e){return e&&[V.NAME,_.NAME].includes(e.name)&&Object.values(se).includes(e.type)}constructor(e){super(e.message),this.name=V.NAME,this.type=e.type||"client"}};V.NAME="SdkError";var y=V,F=class F extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=F.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===F.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};F.NAME="ApiError";var _=F,or=t=>t instanceof TypeError,nr=t=>t instanceof DOMException&&t.name==="AbortError",ar=t=>t instanceof DOMException&&t.name==="TimeoutError",Ve=t=>{let e=new y({message:t.message});if(k.isFetchError(t)){let r=new _(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 or(t)?e.type="request":nr(t)?e.type="cancel":ar(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 D=h("client"),ue=t=>`https://provisioning.${t||f.default.domain}/api`,v,A,b,Y,ye=class ye{constructor(e){c(this,v,void 0);c(this,A,void 0);c(this,b,void 0);c(this,Y,void 0);D("new client instance %O",e),p(this,v,ue(e.domain)),p(this,A,e.accessToken);let r={timeout:e.timeout||f.client.timeout},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,A)},o=e.userAgent;o&&(i["User-Agent"]=o),r.headers=i,p(this,b,r),D("fetch config: %O",r),p(this,Y,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new ye(e)}get interceptors(){return n(this,Y)}get requestHeaders(){return n(this,b).headers||(n(this,b).headers={}),n(this,b).headers}config(e){D("config %o",e);let r=n(this,b);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,b).fetch=e.fetch),e.domain&&p(this,v,ue(e.domain)),e.accessToken&&(p(this,A,e.accessToken),r.headers.Authorization="Bearer "+n(this,A)),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){D("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&D("User-Agent header ignored in request config");let o=i?.domain?ue(i.domain):n(this,v),a=new URL(`${o}/${r}`),m=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},U=i?.accessToken||n(this,A);U&&(T.Authorization="Bearer "+U);let Ue={method:e,body:m,headers:T},ke=i?.timeout||n(this,b).timeout;ke&&(Ue.signal=AbortSignal.timeout(ke)),i?.params&&Object.entries(i?.params).forEach(([le,Ze])=>{a.searchParams.append(le,String(Ze))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,b).fetch};return await $e(a,Ue,Xe).catch(le=>Ve(le))}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}};v=new WeakMap,A=new WeakMap,b=new WeakMap,Y=new WeakMap;var me=ye,Fe=me;var L=t=>t?.type&&t.id&&Q.includes(t.type),Re=t=>t&&typeof t.type<"u"&&t.type&&Q.includes(t.type);var te=h("jsonapi"),z=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>ie(i,s)):e=ie(r,s):e=r,e},De=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,ie=(t,e,r=[])=>{if(te("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(a=>a.id===o.id&&a.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(a=>ie(De(a,e),e,[...r,a])):s[i]=ie(De(o,e),e,[...r,o]):o===null&&(s[i]=null)}),te("denormalized resource: %O",s),s},oe=t=>{te("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&&Re(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Re(o)&&o.id===null?r[i]={data:null}:o&&(L(o)||Array.isArray(o)&&L(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return L(t)&&(s.id=t.id),te("normalized resource: %O",s),s};var Ye=h("query"),He=["_any","_all","_in"],We=["_jcont"],de=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),w=(t,e)=>{Ye("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(",")})),de(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=s.substring(s.lastIndexOf("_")),a;if(Array.isArray(i)){if(!He.includes(o))throw new y({message:`Wrong ${o} filter: Array value is supported only for the following filters: ${He.join(", ")}`,type:"request"});a=i.join(",")}else if(typeof i=="object"){if(!We.includes(o))throw new y({message:`Wrong ${o} filter: Object value is supported only for the following filters: ${We.join(", ")}`,type:"request"});a=JSON.stringify(i)}else a=String(i);r[`filter[q][${s}]`]=a})),Ye("query string params: %O",r)),r};var P={resources:t=>t?[...Q].sort():Q,singletons:t=>t?[...ne].sort():ne,isSingleton:t=>ne.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>_.isApiError(t),init:t=>he(t),get schemaVersion(){return ge}};var C=h("resource"),ae=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,be,fe=class{constructor(e){c(this,g,void 0);c(this,be,{});p(this,g,Fe.create(e)),this.localConfig(e)}localConfig(e){}config(e){return C("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,s){let i=!("id"in e)||P.isSingleton(e.type);C("retrieve:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=w(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,m=await n(this,g).request("GET",a,void 0,{...s,params:o});return z(m)}async list(e,r,s){C("list: %o, %O, %O",e,r||{},s||{});let i=w(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...s,params:i}),a=z(o),m={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 ae(m,a)}async create(e,r,s){C("create: %o, %O, %O",e,r||{},s||{});let i=w(r,e);s?.params&&Object.assign(i,s?.params);let o=oe(e),a=await n(this,g).request("POST",e.type,o,{...s,params:i});return z(a)}async update(e,r,s){let i=!("id"in e)||P.isSingleton(e.type);C("update:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=w(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,m=oe(e),T=await n(this,g).request("PATCH",a,m,{...s,params:o});return z(T)}async delete(e,r){C("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){C("fetch: %o, %O, %O",r,s||{},i||{});let o=w(s,e);i?.params&&Object.assign(o,i?.params);let a=await n(this,g).request("GET",r,void 0,{...i,params:o}),m=z(a);if(Array.isArray(m)){let T=s,U={pageCount:Number(a.meta?.page_count),recordCount:Number(a.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ae(U,m)}else return m}async action(e,r,s,i){C("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let a=s&&L(s)?oe(s):s;await n(this,g).request(e,r,a,{...i,params:o})}};g=new WeakMap,be=new WeakMap;var pe=class{constructor(e){C("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()}))}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 z(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)}},R=class extends pe{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:de(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ce=class extends pe{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r)}},Be=fe;var O=class O extends R{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 Pe=O,Ce=Pe;var x=class x extends R{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 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 Te=x,Ae=Te;var M=class M extends R{async create(e,r,s){return this.resources.create({...e,type:M.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:M.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:M.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===M.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return M.TYPE}};M.TYPE="memberships";var Oe=M,xe=Oe;var E=class E extends R{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async 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===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="organizations";var Me=E,ze=Me;var N=class N extends R{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"},`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===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="permissions";var Ee=N,Ne=Ee;var S=class S extends R{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="roles";var Se=S,_e=Se;var I=class I extends ce{async update(e,r,s){let i=await this.retrieve(r,s);return this.resources.update({...e,id:i.id,type:I.TYPE},r,s)}isUser(e){return e.type&&e.type===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="user";var ve=I,Le=ve;var H=class H extends R{isVersion(e){return e.type&&e.type===H.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return H.TYPE}};H.TYPE="versions";var Qe=H,we=Qe;var Q=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],ne=["user"];var Ge=h("commercelayer"),ge="1.0.4";var d,W,J,B,G,K,X,Z,ee,Ie=class{constructor(e){this.openApiSchemaVersion=ge;c(this,d,void 0);c(this,W,void 0);c(this,J,void 0);c(this,B,void 0);c(this,G,void 0);c(this,K,void 0);c(this,X,void 0);c(this,Z,void 0);c(this,ee,void 0);Ge("new commercelayer provisioning instance %O",e),p(this,d,new Be(e))}get api_credentials(){return n(this,W)||p(this,W,new Ce(n(this,d)))}get application_memberships(){return n(this,J)||p(this,J,new Ae(n(this,d)))}get memberships(){return n(this,B)||p(this,B,new xe(n(this,d)))}get organizations(){return n(this,G)||p(this,G,new ze(n(this,d)))}get permissions(){return n(this,K)||p(this,K,new Ne(n(this,d)))}get roles(){return n(this,X)||p(this,X,new _e(n(this,d)))}get user(){return n(this,Z)||p(this,Z,new Le(n(this,d)))}get versions(){return n(this,ee)||p(this,ee,new we(n(this,d)))}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return Ge("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}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((a,m)=>{o[m]=a}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(e=1){this.interceptors.rawReader=void 0}};d=new WeakMap,W=new WeakMap,J=new WeakMap,B=new WeakMap,G=new WeakMap,K=new WeakMap,X=new WeakMap,Z=new WeakMap,ee=new WeakMap;var Ke=t=>new Ie(t),he=Ke;export{Ke as CommerceLayerProvisioning,P as CommerceLayerProvisioningStatic,he as default};
1
+ var er=(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 qe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)};var n=(t,e,r)=>(qe(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},p=(t,e,r,s)=>(qe(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var rr=(t,...e)=>{},je=t=>rr;try{let t=er("debug");t&&typeof t=="function"&&(je=t)}catch{}var sr="clsdk",tr=t=>je(`${sr}:${t}`),h=tr;var ir=h("fetch"),q,j,$,re=class re extends Error{constructor(r,s,i){super(s);c(this,q,void 0);c(this,j,void 0);c(this,$,void 0);p(this,j,r),p(this,$,s),i&&p(this,q,i.errors)}get errors(){return n(this,q)}get status(){return n(this,j)}get statusText(){return n(this,$)}};q=new WeakMap,j=new WeakMap,$=new WeakMap,re.isFetchError=r=>r instanceof re;var k=re,$e=async(t,e,r)=>{ir("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 a=await o.json().catch(()=>{});if(!o.ok){let m=new k(o.status,o.statusText,a);if(s?.response?.onFailure&&(m=await s.response.onFailure(m)),m)throw m}return a};var se=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a))(se||{}),V=class V extends Error{static isSdkError(e){return e&&[V.NAME,_.NAME].includes(e.name)&&Object.values(se).includes(e.type)}constructor(e){super(e.message),this.name=V.NAME,this.type=e.type||"client"}};V.NAME="SdkError";var y=V,F=class F extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=F.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===F.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};F.NAME="ApiError";var _=F,or=t=>t instanceof TypeError,nr=t=>t instanceof DOMException&&t.name==="AbortError",ar=t=>t instanceof DOMException&&t.name==="TimeoutError",Ve=t=>{let e=new y({message:t.message});if(k.isFetchError(t)){let r=new _(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 or(t)?e.type="request":nr(t)?e.type="cancel":ar(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 D=h("client"),ue=t=>`https://provisioning.${t||f.default.domain}/api`,v,A,b,Y,ye=class ye{constructor(e){c(this,v,void 0);c(this,A,void 0);c(this,b,void 0);c(this,Y,void 0);D("new client instance %O",e),p(this,v,ue(e.domain)),p(this,A,e.accessToken);let r={timeout:e.timeout||f.client.timeout},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,A)},o=e.userAgent;o&&(i["User-Agent"]=o),r.headers=i,p(this,b,r),D("fetch config: %O",r),p(this,Y,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new ye(e)}get interceptors(){return n(this,Y)}get requestHeaders(){return n(this,b).headers||(n(this,b).headers={}),n(this,b).headers}config(e){D("config %o",e);let r=n(this,b);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,b).fetch=e.fetch),e.domain&&p(this,v,ue(e.domain)),e.accessToken&&(p(this,A,e.accessToken),r.headers.Authorization="Bearer "+n(this,A)),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){D("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&D("User-Agent header ignored in request config");let o=i?.domain?ue(i.domain):n(this,v),a=new URL(`${o}/${r}`),m=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},U=i?.accessToken||n(this,A);U&&(T.Authorization="Bearer "+U);let Ue={method:e,body:m,headers:T},ke=i?.timeout||n(this,b).timeout;ke&&(Ue.signal=AbortSignal.timeout(ke)),i?.params&&Object.entries(i?.params).forEach(([le,Ze])=>{a.searchParams.append(le,String(Ze))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,b).fetch};return await $e(a,Ue,Xe).catch(le=>Ve(le))}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}};v=new WeakMap,A=new WeakMap,b=new WeakMap,Y=new WeakMap;var me=ye,Fe=me;var L=t=>t?.type&&t.id&&Q.includes(t.type),Re=t=>t&&typeof t.type<"u"&&t.type&&Q.includes(t.type);var te=h("jsonapi"),z=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>ie(i,s)):e=ie(r,s):e=r,e},De=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,ie=(t,e,r=[])=>{if(te("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(a=>a.id===o.id&&a.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(a=>ie(De(a,e),e,[...r,a])):s[i]=ie(De(o,e),e,[...r,o]):o===null&&(s[i]=null)}),te("denormalized resource: %O",s),s},oe=t=>{te("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&&Re(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Re(o)&&o.id===null?r[i]={data:null}:o&&(L(o)||Array.isArray(o)&&L(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return L(t)&&(s.id=t.id),te("normalized resource: %O",s),s};var Ye=h("query"),He=["_any","_all","_in"],We=["_jcont"],de=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),w=(t,e)=>{Ye("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(",")})),de(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=s.substring(s.lastIndexOf("_")),a;if(Array.isArray(i)){if(!He.includes(o))throw new y({message:`Wrong ${o} filter: Array value is supported only for the following filters: ${He.join(", ")}`,type:"request"});a=i.join(",")}else if(typeof i=="object"){if(!We.includes(o))throw new y({message:`Wrong ${o} filter: Object value is supported only for the following filters: ${We.join(", ")}`,type:"request"});a=JSON.stringify(i)}else a=String(i);r[`filter[q][${s}]`]=a})),Ye("query string params: %O",r)),r};var P={resources:t=>t?[...Q].sort():Q,singletons:t=>t?[...ne].sort():ne,isSingleton:t=>ne.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>_.isApiError(t),init:t=>he(t),get schemaVersion(){return ge}};var C=h("resource"),ae=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,be,fe=class{constructor(e){c(this,g,void 0);c(this,be,{});p(this,g,Fe.create(e)),this.localConfig(e)}localConfig(e){}config(e){return C("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,s){let i=!("id"in e)||P.isSingleton(e.type);C("retrieve:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=w(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,m=await n(this,g).request("GET",a,void 0,{...s,params:o});return z(m)}async list(e,r,s){C("list: %o, %O, %O",e,r||{},s||{});let i=w(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...s,params:i}),a=z(o),m={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 ae(m,a)}async create(e,r,s){C("create: %o, %O, %O",e,r||{},s||{});let i=w(r,e);s?.params&&Object.assign(i,s?.params);let o=oe(e),a=await n(this,g).request("POST",e.type,o,{...s,params:i});return z(a)}async update(e,r,s){let i=!("id"in e)||P.isSingleton(e.type);C("update:%s %o, %O, %O",i?" singleton,":"",e,r||{},s||{});let o=w(r,e);s?.params&&Object.assign(o,s?.params);let a=`${e.type}${i?"":`/${e.id}`}`,m=oe(e),T=await n(this,g).request("PATCH",a,m,{...s,params:o});return z(T)}async delete(e,r){C("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){C("fetch: %o, %O, %O",r,s||{},i||{});let o=w(s,e);i?.params&&Object.assign(o,i?.params);let a=await n(this,g).request("GET",r,void 0,{...i,params:o}),m=z(a);if(Array.isArray(m)){let T=s,U={pageCount:Number(a.meta?.page_count),recordCount:Number(a.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ae(U,m)}else return m}async action(e,r,s,i){C("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let a=s&&L(s)?oe(s):s;await n(this,g).request(e,r,a,{...i,params:o})}};g=new WeakMap,be=new WeakMap;var pe=class{constructor(e){C("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()}))}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 z(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)}},R=class extends pe{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:de(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},ce=class extends pe{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r)}},Be=fe;var O=class O extends R{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 Pe=O,Ce=Pe;var x=class x extends R{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 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 Te=x,Ae=Te;var M=class M extends R{async create(e,r,s){return this.resources.create({...e,type:M.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:M.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:M.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===M.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return M.TYPE}};M.TYPE="memberships";var Oe=M,xe=Oe;var E=class E extends R{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async 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===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="organizations";var Me=E,ze=Me;var N=class N extends R{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"},`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===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="permissions";var Ee=N,Ne=Ee;var S=class S extends R{async create(e,r,s){return this.resources.create({...e,type:S.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:S.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}isRole(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="roles";var Se=S,_e=Se;var I=class I extends ce{async update(e,r,s){let i=await this.retrieve(r,s);return this.resources.update({...e,id:i.id,type:I.TYPE},r,s)}isUser(e){return e.type&&e.type===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="user";var ve=I,Le=ve;var H=class H extends R{isVersion(e){return e.type&&e.type===H.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return H.TYPE}};H.TYPE="versions";var Qe=H,we=Qe;var Q=["api_credentials","application_memberships","memberships","organizations","permissions","roles","user","versions"],ne=["user"];var Ge=h("commercelayer"),ge="1.0.5";var d,W,J,B,G,K,X,Z,ee,Ie=class{constructor(e){this.openApiSchemaVersion=ge;c(this,d,void 0);c(this,W,void 0);c(this,J,void 0);c(this,B,void 0);c(this,G,void 0);c(this,K,void 0);c(this,X,void 0);c(this,Z,void 0);c(this,ee,void 0);Ge("new commercelayer provisioning instance %O",e),p(this,d,new Be(e))}get api_credentials(){return n(this,W)||p(this,W,new Ce(n(this,d)))}get application_memberships(){return n(this,J)||p(this,J,new Ae(n(this,d)))}get memberships(){return n(this,B)||p(this,B,new xe(n(this,d)))}get organizations(){return n(this,G)||p(this,G,new ze(n(this,d)))}get permissions(){return n(this,K)||p(this,K,new Ne(n(this,d)))}get roles(){return n(this,X)||p(this,X,new _e(n(this,d)))}get user(){return n(this,Z)||p(this,Z,new Le(n(this,d)))}get versions(){return n(this,ee)||p(this,ee,new we(n(this,d)))}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return Ge("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}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((a,m)=>{o[m]=a}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(e=1){this.interceptors.rawReader=void 0}};d=new WeakMap,W=new WeakMap,J=new WeakMap,B=new WeakMap,G=new WeakMap,K=new WeakMap,X=new WeakMap,Z=new WeakMap,ee=new WeakMap;var Ke=t=>new Ie(t),he=Ke;export{Ke as CommerceLayerProvisioning,P as CommerceLayerProvisioningStatic,he as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/provisioning-sdk",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.17",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "lib/index.mjs",
@@ -42,17 +42,17 @@
42
42
  "@semantic-release/git": "^10.0.1",
43
43
  "@types/debug": "^4.1.12",
44
44
  "@types/jest": "^29.5.12",
45
- "@types/node": "^20.12.6",
45
+ "@types/node": "^20.12.7",
46
46
  "dotenv": "^16.4.5",
47
47
  "eslint": "^8.57.0",
48
48
  "jest": "^29.7.0",
49
49
  "json-typescript": "^1.1.2",
50
50
  "jsonapi-typescript": "^0.1.3",
51
51
  "lodash.isequal": "^4.5.0",
52
- "semantic-release": "^23.0.7",
52
+ "semantic-release": "^23.0.8",
53
53
  "tsup": "^8.0.2",
54
54
  "tsx": "^4.7.2",
55
- "typescript": "^5.4.4"
55
+ "typescript": "^5.4.5"
56
56
  },
57
57
  "repository": "github:commercelayer/provisioning-sdk",
58
58
  "bugs": "https://github.com/commercelayer/provisioning-sdk/issues",