@commercelayer/provisioning-sdk
Version:
Commerce Layer Provisioning SDK
2 lines (1 loc) • 23.4 kB
JavaScript
var er=t=>{throw TypeError(t)};var yr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var rr=(t,e,r)=>e.has(t)||er("Cannot "+r);var n=(t,e,r)=>(rr(t,e,"read from private field"),r?r.call(t):e.get(t)),c=(t,e,r)=>e.has(t)?er("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),l=(t,e,r,s)=>(rr(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r);var dr=(t,...e)=>{},sr=t=>dr;try{let t=yr("debug");t&&typeof t=="function"&&(sr=t)}catch{}var Rr="clsdk",gr=t=>sr(`${Rr}:${t}`),b=gr;var fe=b("fetch"),H,J,W,ce=class ce extends Error{constructor(r,s,i){super(s);c(this,H);c(this,J);c(this,W);l(this,J,r),l(this,W,s),i&&l(this,H,i.errors)}get errors(){return n(this,H)}get status(){return n(this,J)}get statusText(){return n(this,W)}};H=new WeakMap,J=new WeakMap,W=new WeakMap,ce.isFetchError=r=>r instanceof ce;var D=ce,Pe=async(t,e,r)=>{fe("fetch: %s, %O, native[%s]",t,e||{},r?.fetch?"no":"yes");let s=r?.interceptors;s?.request?.onSuccess&&({url:t,options:e}=await s.request.onSuccess({url:t,options:e}));let o=await(r?.fetch||fetch)(t,e);o.ok?(s?.rawReader?.onSuccess&&await s.rawReader.onSuccess(o),s?.response?.onSuccess&&(o=await s.response.onSuccess(o))):s?.rawReader?.onFailure&&await s.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("error: %s",a.message),o.ok)throw new y({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new D(o.status,o.statusText,p);if(s?.response?.onFailure&&(a=await s.response.onFailure(a)),a)throw a}return p};var Q=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(Q||{}),B=class B extends Error{static isSdkError(e){return e&&[B.NAME,O.NAME].includes(e.name)&&Object.values(Q).includes(e.type)}constructor(e){super(e.message),this.name=B.NAME,this.type=e.type||"client"}};B.NAME="SdkError";var y=B,K=class K extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=K.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===K.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};K.NAME="ApiError";var O=K,hr=t=>t instanceof TypeError,br=t=>t instanceof DOMException&&t.name==="AbortError",fr=t=>t instanceof DOMException&&t.name==="TimeoutError",tr=t=>O.isApiError(t)&&t.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(t.code||"")||t.errors&&t.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(t.errors[0].code)),_e=t=>{if(y.isSdkError(t)||O.isApiError(t))throw t;let e=new y({message:t.message});if(D.isFetchError(t)){let r=new O(e);r.type="response",r.status=t.status,r.statusText=t.statusText,r.code=String(r.status),r.errors=t.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else hr(t)?e.type="request":br(t)?e.type="cancel":fr(t)?e.type="timeout":(e.type="client",e.source=t);throw e};var Pr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Pr;var ir=t=>{try{return JSON.parse(atob(t.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var C=b("client"),Te=t=>`https://provisioning.${t||f.default.domain}/api`,j,P,g,G,Ae=class Ae{constructor(e){c(this,j);c(this,P);c(this,g);c(this,G);C("new client instance %O",e),l(this,j,Te(e.domain)),l(this,P,e.accessToken);let r={timeout:e.timeout||f.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,l(this,g,r),C("fetch config: %O",r),l(this,G,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,G)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){C("config %o",e);let r=n(this,g);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,g).fetch=e.fetch),e.refreshToken&&(n(this,g).refreshToken=e.refreshToken),e.domain&&l(this,j,Te(e.domain)),e.accessToken&&(l(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,s,i){C("request %s %s, %O, %O",e,r,s||{},i||{}),i?.userAgent&&C("User-Agent header ignored in request config");let o=i?.domain?Te(i.domain):n(this,j),p=new URL(`${o}/${r}`),a=s?JSON.stringify({data:s}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,P);I&&(T.Authorization="Bearer "+I);let U={method:e,body:a,headers:T},Ze=i?.timeout||n(this,g).timeout;Ze&&(AbortSignal?.timeout?U.signal=AbortSignal.timeout(Ze):C("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Xe={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await Pe(p,U,Xe).catch(L=>_e(L))}catch(L){if(tr(L)&&n(this,g).refreshToken&&ir(n(this,P))){C("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(be=>{C("Refresh token error: %s",be.message);let le=new y({message:"Error refreshing access token",type:"token-refresh"});throw le.source=be,le});if(V)return C("Access token refreshed"),this.config({accessToken:V}),U.headers&&(U.headers.Authorization=`Bearer ${V}`),await Pe(p,U,Xe).catch(le=>_e(le))}else throw L}}customHeaders(e){let r={};if(e)for(let[s,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(s.toLowerCase())||(r[s]=i);return r}get currentAccessToken(){return n(this,P)}};j=new WeakMap,P=new WeakMap,g=new WeakMap,G=new WeakMap;var Ce=Ae,or=Ce;var q=t=>t?.type&&t.id&&$.includes(t.type),Me=t=>t&&typeof t.type<"u"&&t.type&&$.includes(t.type);var ue=b("jsonapi"),S=t=>{let e;t.links&&delete t.links;let r=t.data,s=t.included;return r?Array.isArray(r)?e=r.map(i=>me(i,s)):e=me(r,s):e=r,e},nr=(t,e=[])=>e.find(s=>t.id===s.id&&t.type===s.type)||t,me=(t,e,r=[])=>{if(ue("denormalize resource: %O, %o",t,e||{}),!t)return t;let s={id:t.id,type:t.type,...t.attributes};return t.relationships&&Object.keys(t.relationships).forEach(i=>{let o=t.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?s[i]=o:Array.isArray(o)?s[i]=o.map(p=>me(nr(p,e),e,[...r,p])):s[i]=me(nr(o,e),e,[...r,o]):o===null&&(s[i]=null)}),ue("denormalized resource: %O",s),s},ye=t=>{ue("normalize resource: %O",t);let e={},r={};for(let i in t){if(["type","id"].includes(i))continue;let o=t[i];Array.isArray(o)&&o.length===1&&Me(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Me(o)&&o.id===null?r[i]={data:null}:o&&(q(o)||Array.isArray(o)&&q(o[0]))?r[i]={data:o}:e[i]=o}let s={type:t.type,attributes:e,relationships:r};return q(t)&&(s.id=t.id),ue("normalized resource: %O",s),s};var ar=b("query"),pr=["_any","_all","_in","_not_in_or_null"],_r=t=>pr.some(e=>t.endsWith(e)),lr=["_jcont"],Tr=t=>lr.some(e=>t.endsWith(e)),Oe=t=>t&&(t.filters||t.pageNumber||t.pageSize||t.sort),F=(t,e)=>{ar("generate query string params: %O, %O",t,e);let r={};return t&&(t.include&&(r.include=t.include.join(",")),t.fields&&(Array.isArray(t.fields)&&(t.fields={[e.type||e]:t.fields}),Object.entries(t.fields).forEach(([s,i])=>{r[`fields[${s}]`]=i.join(",")})),Oe(t)&&(t.sort&&(Array.isArray(t.sort)?r.sort=t.sort.join(","):r.sort=Object.entries(t.sort).map(([s,i])=>`${i==="desc"?"-":""}${s}`).join(",")),t.pageNumber&&(r["page[number]"]=String(t.pageNumber)),t.pageSize&&(r["page[size]"]=String(t.pageSize)),t.filters&&Object.entries(t.filters).forEach(([s,i])=>{let o;if(Array.isArray(i)){if(!_r(s))throw new y({message:`Incorrect filter [${s}]: Array value is supported only for the following filters: ${pr.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Tr(s))throw new y({message:`Incorrect filter [${s}]: Object value is supported only for the following filters: ${lr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${s}]`]=o})),ar("query string params: %O",r)),r};var A={resources:t=>t?[...$].sort():$,singletons:t=>t?[...de].sort():de,isSingleton:t=>de.includes(t),isSdkError:t=>y.isSdkError(t),isApiError:t=>O.isApiError(t),init:t=>ve(t),get schemaVersion(){return xe}};var M=b("resource"),Re=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var h,Ee,ze=class{constructor(e){c(this,h);c(this,Ee,{});l(this,h,or.create(e)),this.localConfig(e)}localConfig(e){}config(e){return M("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...s,params:p});return S(T)}async list(e,r,s){M("list: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...s,params:i}),p=S(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||f.default.pageNumber,recordsPerPage:r?.pageSize||f.default.pageSize};return new Re(a,p)}async create(e,r,s){M("create: %o, %O, %O",e,r||{},s||{});let i=F(r,e);s?.params&&Object.assign(i,s?.params);let o=ye(e),p=await n(this,h).request("POST",e.type,o,{...s,params:i});return S(p)}async update(e,r,s,i){let o=!("id"in e)||A.isSingleton(e.type);M("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},s||{});let p=F(r,e);s?.params&&Object.assign(p,s?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ye(e),I=await n(this,h).request("PATCH",a,T,{...s,params:p});return S(I)}async delete(e,r){M("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,s,i){M("fetch: %o, %O, %O",r,s||{},i||{});let o=F(s,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=S(p);if(Array.isArray(a)){let T=s,I={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new Re(I,a)}else return a}async action(e,r,s,i){M("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=s&&q(s)?ye(s):s;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var ge=class{constructor(e){M("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new y({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return S(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,s){return this.resources.update({...e,type:this.type()},r,s,this.path())}},d=class extends ge{async retrieve(e,r,s){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,s)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let s={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(s,r);return Promise.resolve(i.meta.recordCount)}},he=class extends ge{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},cr=ze;var x=class x extends d{async create(e,r,s){return this.resources.create({...e,type:x.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:x.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,s)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ne=x,Ie=Ne;var v=class v extends d{async create(e,r,s){return this.resources.create({...e,type:v.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:v.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async api_credential(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,s)}async membership(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`application_memberships/${i}/membership_profile`,r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,s)}isApplicationMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Se=v,ke=Se;var _=class _ extends d{async create(e,r,s){return this.resources.create({...e,type:_.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:_.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:_.TYPE}:e,r)}async user(e,r,s){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,s)}async _disable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_disable:!0},r,s)}async _enable(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:_.TYPE,_enable:!0},r,s)}isIdentityProvider(e){return e.type&&e.type===_.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return _.TYPE}};_.TYPE="identity_providers";var we=_,Ue=we;var z=class z extends d{async create(e,r,s){return this.resources.create({...e,type:z.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:z.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async resend(e,r){let s=e.id||e;await this.resources.action("POST",`memberships/${s}/resend`,{},r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,s)}async membership_profile(e,r,s){let i=e.id||e;return this.resources.fetch({type:"membership_profiles"},`memberships/${i}/membership_profile`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,s)}isMembership(e){return e.type&&e.type===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var Le=z,Qe=Le;var E=class E extends d{async create(e,r,s){return this.resources.create({...e,type:E.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:E.TYPE},r,s)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`membership_profiles/${i}/organization`,r,s)}async application_memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`membership_profiles/${i}/application_memberships`,r,s)}isMembershipProfile(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="membership_profiles";var je=E,qe=je;var k=class k extends d{async create(e,r,s){return this.resources.create({...e,type:k.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:k.TYPE},r,s)}async transfer_ownership(e,r,s){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,s)}async roles(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,s)}isOrganization(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="organizations";var $e=k,Fe=$e;var w=class w extends d{async create(e,r,s){return this.resources.create({...e,type:w.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:w.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,s)}async role(e,r,s){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,s)}isPermission(e){return e.type&&e.type===w.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return w.TYPE}};w.TYPE="permissions";var Ye=w,Ve=Ye;var N=class N extends d{async create(e,r,s){return this.resources.create({...e,type:N.TYPE},r,s)}async update(e,r,s){return this.resources.update({...e,type:N.TYPE},r,s)}async organization(e,r,s){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,s)}async permissions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,s)}async memberships(e,r,s){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,s)}async api_credentials(e,r,s){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,s)}async versions(e,r,s){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,s)}async _add_missing_base_permissions(e,r,s){return this.resources.update({id:typeof e=="string"?e:e.id,type:N.TYPE,_add_missing_base_permissions:!0},r,s)}isRole(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="roles";var De=N,He=De;var Y=class Y extends he{async update(e,r,s){return this.resources.update({...e,type:Y.TYPE},r,s,this.path())}isUser(e){return e.type&&e.type===Y.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Y.TYPE}path(){return"user"}};Y.TYPE="users";var Je=Y,We=Je;var Z=class Z extends d{isVersion(e){return e.type&&e.type===Z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return Z.TYPE}};Z.TYPE="versions";var Be=Z,Ke=Be;var $=["api_credentials","application_memberships","identity_providers","memberships","membership_profiles","organizations","permissions","roles","users","versions"],de=["users"];var ur=b("commercelayer"),xe="1.0.15";var R,X,ee,re,se,te,ie,oe,ne,ae,pe,Ge=class{constructor(e){this.openApiSchemaVersion=xe;c(this,R);c(this,X);c(this,ee);c(this,re);c(this,se);c(this,te);c(this,ie);c(this,oe);c(this,ne);c(this,ae);c(this,pe);ur("new commercelayer provisioning instance %O",e),l(this,R,new cr(e))}get api_credentials(){return n(this,X)||l(this,X,new Ie(n(this,R)))}get application_memberships(){return n(this,ee)||l(this,ee,new ke(n(this,R)))}get identity_providers(){return n(this,re)||l(this,re,new Ue(n(this,R)))}get memberships(){return n(this,se)||l(this,se,new Qe(n(this,R)))}get membership_profiles(){return n(this,te)||l(this,te,new qe(n(this,R)))}get organizations(){return n(this,ie)||l(this,ie,new Fe(n(this,R)))}get permissions(){return n(this,oe)||l(this,oe,new Ve(n(this,R)))}get roles(){return n(this,ne)||l(this,ne,new He(n(this,R)))}get user(){return n(this,ae)||l(this,ae,new We(n(this,R)))}get versions(){return n(this,pe)||l(this,pe,new Ke(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ur("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return A.resources()}singletons(){return A.singletons()}isSingleton(e){return A.isSingleton(e)}isApiError(e){return A.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function s(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:s,onFailure:s},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,se=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap,ae=new WeakMap,pe=new WeakMap;var mr=t=>new Ge(t),ve=mr;export{mr as CommerceLayerProvisioning,A as CommerceLayerProvisioningStatic,ve as default};