@commercelayer/provisioning-sdk 2.3.1 → 2.3.2
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/LICENSE +1 -1
- package/lib/index.d.mts +20 -8
- package/lib/index.d.ts +20 -8
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
package/lib/index.d.mts
CHANGED
|
@@ -629,6 +629,11 @@ interface Organization extends Resource {
|
|
|
629
629
|
* Enables the purge of cached single resources when list is purged.
|
|
630
630
|
*/
|
|
631
631
|
api_purge_single_resource: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* The maximum length for the regular expressions, default is 5000.
|
|
634
|
+
* @example ```"5000"```
|
|
635
|
+
*/
|
|
636
|
+
api_max_regex_length: number;
|
|
632
637
|
/**
|
|
633
638
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
634
639
|
* @example ```"true"```
|
|
@@ -702,6 +707,10 @@ interface Organization extends Resource {
|
|
|
702
707
|
* @example ```"true"```
|
|
703
708
|
*/
|
|
704
709
|
imports_purge_cache: boolean;
|
|
710
|
+
/**
|
|
711
|
+
* Disables the interruption of the import in case its errors exceeds the 10% threshold, default is false.
|
|
712
|
+
*/
|
|
713
|
+
imports_skip_errors: boolean;
|
|
705
714
|
/**
|
|
706
715
|
* The maximum number of active concurrent promotions allowed for your organization, default is 10.
|
|
707
716
|
* @example ```"10"```
|
|
@@ -719,6 +728,11 @@ interface Organization extends Resource {
|
|
|
719
728
|
* Enables raising of API errors in case of discount engine failure, default is false.
|
|
720
729
|
*/
|
|
721
730
|
discount_engines_errors: boolean;
|
|
731
|
+
/**
|
|
732
|
+
* The maximum length for the tag name, default is 25.
|
|
733
|
+
* @example ```"25"```
|
|
734
|
+
*/
|
|
735
|
+
tags_max_name_length: number;
|
|
722
736
|
/**
|
|
723
737
|
* Enables raising of API errors in case of tax calculation failure, default is false.
|
|
724
738
|
*/
|
|
@@ -991,7 +1005,7 @@ declare class ApiCredentials extends ApiResource<ApiCredential> {
|
|
|
991
1005
|
type(): ApiCredentialType;
|
|
992
1006
|
}
|
|
993
1007
|
|
|
994
|
-
type UserType = '
|
|
1008
|
+
type UserType = 'users';
|
|
995
1009
|
type UserRel = ResourceRel & {
|
|
996
1010
|
type: UserType;
|
|
997
1011
|
};
|
|
@@ -1022,7 +1036,6 @@ interface User extends Resource {
|
|
|
1022
1036
|
* The user 2FA setting.
|
|
1023
1037
|
*/
|
|
1024
1038
|
otp_required_for_login: boolean;
|
|
1025
|
-
identity_providers?: Nullable<IdentityProvider[]>;
|
|
1026
1039
|
}
|
|
1027
1040
|
interface UserUpdate extends SingletonUpdate {
|
|
1028
1041
|
/**
|
|
@@ -1049,7 +1062,6 @@ interface UserUpdate extends SingletonUpdate {
|
|
|
1049
1062
|
declare class Users extends ApiSingleton<User> {
|
|
1050
1063
|
static readonly TYPE: UserType;
|
|
1051
1064
|
update(resource: UserUpdate, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1052
|
-
identity_providers(userId: string | User, params?: QueryParamsList<IdentityProvider>, options?: ResourcesConfig): Promise<ListResponse<IdentityProvider>>;
|
|
1053
1065
|
isUser(resource: any): resource is User;
|
|
1054
1066
|
relationship(id: string | ResourceId | null): UserRel;
|
|
1055
1067
|
relationshipToMany(...ids: string[]): UserRel[];
|
|
@@ -1254,14 +1266,14 @@ declare class IdentityProviders extends ApiResource<IdentityProvider> {
|
|
|
1254
1266
|
type(): IdentityProviderType;
|
|
1255
1267
|
}
|
|
1256
1268
|
|
|
1257
|
-
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | '
|
|
1269
|
+
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'users' | 'versions';
|
|
1258
1270
|
declare const resourceList: ResourceTypeLock[];
|
|
1259
1271
|
declare const singletonList: ResourceTypeLock[];
|
|
1260
1272
|
type RetrievableResourceType = ResourceTypeLock;
|
|
1261
1273
|
type RetrievableResource = Resource & {
|
|
1262
1274
|
type: RetrievableResourceType;
|
|
1263
1275
|
};
|
|
1264
|
-
type ListableResourceType = Exclude<ResourceTypeLock, '
|
|
1276
|
+
type ListableResourceType = Exclude<ResourceTypeLock, 'users'>;
|
|
1265
1277
|
type ListableResource = Resource & {
|
|
1266
1278
|
type: ListableResourceType;
|
|
1267
1279
|
};
|
|
@@ -1292,7 +1304,7 @@ type ResourceFields = {
|
|
|
1292
1304
|
organizations: Organization;
|
|
1293
1305
|
permissions: Permission;
|
|
1294
1306
|
roles: Role;
|
|
1295
|
-
|
|
1307
|
+
users: User;
|
|
1296
1308
|
versions: Version;
|
|
1297
1309
|
};
|
|
1298
1310
|
type ResourceSortFields = {
|
|
@@ -1303,7 +1315,7 @@ type ResourceSortFields = {
|
|
|
1303
1315
|
organizations: OrganizationSort;
|
|
1304
1316
|
permissions: PermissionSort;
|
|
1305
1317
|
roles: RoleSort;
|
|
1306
|
-
|
|
1318
|
+
users: UserSort;
|
|
1307
1319
|
versions: VersionSort;
|
|
1308
1320
|
};
|
|
1309
1321
|
|
|
@@ -1342,7 +1354,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1342
1354
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1343
1355
|
declare class CommerceLayerProvisioningClient {
|
|
1344
1356
|
#private;
|
|
1345
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1357
|
+
readonly openApiSchemaVersion = "1.0.7";
|
|
1346
1358
|
constructor(config: CommerceLayerInitConfig);
|
|
1347
1359
|
get api_credentials(): ApiCredentials;
|
|
1348
1360
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.d.ts
CHANGED
|
@@ -629,6 +629,11 @@ interface Organization extends Resource {
|
|
|
629
629
|
* Enables the purge of cached single resources when list is purged.
|
|
630
630
|
*/
|
|
631
631
|
api_purge_single_resource: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* The maximum length for the regular expressions, default is 5000.
|
|
634
|
+
* @example ```"5000"```
|
|
635
|
+
*/
|
|
636
|
+
api_max_regex_length: number;
|
|
632
637
|
/**
|
|
633
638
|
* Indicates if the phone attribute is required for addresses, default is true.
|
|
634
639
|
* @example ```"true"```
|
|
@@ -702,6 +707,10 @@ interface Organization extends Resource {
|
|
|
702
707
|
* @example ```"true"```
|
|
703
708
|
*/
|
|
704
709
|
imports_purge_cache: boolean;
|
|
710
|
+
/**
|
|
711
|
+
* Disables the interruption of the import in case its errors exceeds the 10% threshold, default is false.
|
|
712
|
+
*/
|
|
713
|
+
imports_skip_errors: boolean;
|
|
705
714
|
/**
|
|
706
715
|
* The maximum number of active concurrent promotions allowed for your organization, default is 10.
|
|
707
716
|
* @example ```"10"```
|
|
@@ -719,6 +728,11 @@ interface Organization extends Resource {
|
|
|
719
728
|
* Enables raising of API errors in case of discount engine failure, default is false.
|
|
720
729
|
*/
|
|
721
730
|
discount_engines_errors: boolean;
|
|
731
|
+
/**
|
|
732
|
+
* The maximum length for the tag name, default is 25.
|
|
733
|
+
* @example ```"25"```
|
|
734
|
+
*/
|
|
735
|
+
tags_max_name_length: number;
|
|
722
736
|
/**
|
|
723
737
|
* Enables raising of API errors in case of tax calculation failure, default is false.
|
|
724
738
|
*/
|
|
@@ -991,7 +1005,7 @@ declare class ApiCredentials extends ApiResource<ApiCredential> {
|
|
|
991
1005
|
type(): ApiCredentialType;
|
|
992
1006
|
}
|
|
993
1007
|
|
|
994
|
-
type UserType = '
|
|
1008
|
+
type UserType = 'users';
|
|
995
1009
|
type UserRel = ResourceRel & {
|
|
996
1010
|
type: UserType;
|
|
997
1011
|
};
|
|
@@ -1022,7 +1036,6 @@ interface User extends Resource {
|
|
|
1022
1036
|
* The user 2FA setting.
|
|
1023
1037
|
*/
|
|
1024
1038
|
otp_required_for_login: boolean;
|
|
1025
|
-
identity_providers?: Nullable<IdentityProvider[]>;
|
|
1026
1039
|
}
|
|
1027
1040
|
interface UserUpdate extends SingletonUpdate {
|
|
1028
1041
|
/**
|
|
@@ -1049,7 +1062,6 @@ interface UserUpdate extends SingletonUpdate {
|
|
|
1049
1062
|
declare class Users extends ApiSingleton<User> {
|
|
1050
1063
|
static readonly TYPE: UserType;
|
|
1051
1064
|
update(resource: UserUpdate, params?: QueryParamsRetrieve<User>, options?: ResourcesConfig): Promise<User>;
|
|
1052
|
-
identity_providers(userId: string | User, params?: QueryParamsList<IdentityProvider>, options?: ResourcesConfig): Promise<ListResponse<IdentityProvider>>;
|
|
1053
1065
|
isUser(resource: any): resource is User;
|
|
1054
1066
|
relationship(id: string | ResourceId | null): UserRel;
|
|
1055
1067
|
relationshipToMany(...ids: string[]): UserRel[];
|
|
@@ -1254,14 +1266,14 @@ declare class IdentityProviders extends ApiResource<IdentityProvider> {
|
|
|
1254
1266
|
type(): IdentityProviderType;
|
|
1255
1267
|
}
|
|
1256
1268
|
|
|
1257
|
-
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | '
|
|
1269
|
+
type ResourceTypeLock = 'api_credentials' | 'application_memberships' | 'identity_providers' | 'memberships' | 'organizations' | 'permissions' | 'roles' | 'users' | 'versions';
|
|
1258
1270
|
declare const resourceList: ResourceTypeLock[];
|
|
1259
1271
|
declare const singletonList: ResourceTypeLock[];
|
|
1260
1272
|
type RetrievableResourceType = ResourceTypeLock;
|
|
1261
1273
|
type RetrievableResource = Resource & {
|
|
1262
1274
|
type: RetrievableResourceType;
|
|
1263
1275
|
};
|
|
1264
|
-
type ListableResourceType = Exclude<ResourceTypeLock, '
|
|
1276
|
+
type ListableResourceType = Exclude<ResourceTypeLock, 'users'>;
|
|
1265
1277
|
type ListableResource = Resource & {
|
|
1266
1278
|
type: ListableResourceType;
|
|
1267
1279
|
};
|
|
@@ -1292,7 +1304,7 @@ type ResourceFields = {
|
|
|
1292
1304
|
organizations: Organization;
|
|
1293
1305
|
permissions: Permission;
|
|
1294
1306
|
roles: Role;
|
|
1295
|
-
|
|
1307
|
+
users: User;
|
|
1296
1308
|
versions: Version;
|
|
1297
1309
|
};
|
|
1298
1310
|
type ResourceSortFields = {
|
|
@@ -1303,7 +1315,7 @@ type ResourceSortFields = {
|
|
|
1303
1315
|
organizations: OrganizationSort;
|
|
1304
1316
|
permissions: PermissionSort;
|
|
1305
1317
|
roles: RoleSort;
|
|
1306
|
-
|
|
1318
|
+
users: UserSort;
|
|
1307
1319
|
versions: VersionSort;
|
|
1308
1320
|
};
|
|
1309
1321
|
|
|
@@ -1342,7 +1354,7 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
|
|
|
1342
1354
|
type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
|
|
1343
1355
|
declare class CommerceLayerProvisioningClient {
|
|
1344
1356
|
#private;
|
|
1345
|
-
readonly openApiSchemaVersion = "1.0.
|
|
1357
|
+
readonly openApiSchemaVersion = "1.0.7";
|
|
1346
1358
|
constructor(config: CommerceLayerInitConfig);
|
|
1347
1359
|
get api_credentials(): ApiCredentials;
|
|
1348
1360
|
get application_memberships(): ApplicationMemberships;
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var he=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var Ge=s=>{throw TypeError(s)};var mr=(s,e)=>{for(var r in e)he(s,r,{get:e[r],enumerable:!0})},yr=(s,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ur(e))!lr.call(s,i)&&i!==r&&he(s,i,{get:()=>e[i],enumerable:!(t=cr(e,i))||t.enumerable});return s};var dr=s=>yr(he({},"__esModule",{value:!0}),s);var Ze=(s,e,r)=>e.has(s)||Ge("Cannot "+r);var n=(s,e,r)=>(Ze(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ge("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ze(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var Or={};mr(Or,{CommerceLayerProvisioning:()=>We,CommerceLayerProvisioningStatic:()=>P,default:()=>me});module.exports=dr(Or);var Rr=(s,...e)=>{},Xe=s=>Rr;try{let s=require("debug");s&&typeof s=="function"&&(Xe=s)}catch{}var gr="clsdk",hr=s=>Xe(`${gr}:${s}`),h=hr;var fe=h("fetch"),D,Y,H,ae=class ae extends Error{constructor(r,t,i){super(t);u(this,D);u(this,Y);u(this,H);c(this,Y,r),c(this,H,t),i&&c(this,D,i.errors)}get errors(){return n(this,D)}get status(){return n(this,Y)}get statusText(){return n(this,H)}};D=new WeakMap,Y=new WeakMap,H=new WeakMap,ae.isFetchError=r=>r instanceof ae;var V=ae,be=async(s,e,r)=>{fe("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("error: %s",a.message),o.ok)throw new m({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new V(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var w=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(w||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,O.NAME].includes(e.name)&&Object.values(w).includes(e.type)}constructor(e){super(e.message),this.name=J.NAME,this.type=e.type||"client"}};J.NAME="SdkError";var m=J,W=class W extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=W.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===W.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};W.NAME="ApiError";var O=W,fr=s=>s instanceof TypeError,br=s=>s instanceof DOMException&&s.name==="AbortError",Pr=s=>s instanceof DOMException&&s.name==="TimeoutError",er=s=>O.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),Pe=s=>{if(m.isSdkError(s)||O.isApiError(s))throw s;let e=new m({message:s.message});if(V.isFetchError(s)){let r=new O(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else fr(s)?e.type="request":br(s)?e.type="cancel":Pr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var Cr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Cr;var rr=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=h("client"),Ce=s=>`https://provisioning.${s||f.default.domain}/api`,U,b,R,B,Ae=class Ae{constructor(e){u(this,U);u(this,b);u(this,R);u(this,B);A("new client instance %O",e),c(this,U,Ce(e.domain)),c(this,b,e.accessToken);let r={timeout:e.timeout||f.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,b)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,R,r),A("fetch config: %O",r),c(this,B,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){A("config %o",e);let r=n(this,R);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,R).fetch=e.fetch),e.refreshToken&&(n(this,R).refreshToken=e.refreshToken),e.domain&&c(this,U,Ce(e.domain)),e.accessToken&&(c(this,b,e.accessToken),r.headers.Authorization="Bearer "+n(this,b)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Ce(i.domain):n(this,U),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},I=i?.accessToken||n(this,b);I&&(T.Authorization="Bearer "+I);let k={method:e,body:a,headers:T},Be=i?.timeout||n(this,R).timeout;Be&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(Be):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,F])=>{p.searchParams.append(L,String(F))});let Ke={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await be(p,k,Ke).catch(L=>Pe(L))}catch(L){if(er(L)&&n(this,R).refreshToken&&rr(n(this,b))){A("Access token has expired");let F=await n(this,R).refreshToken(n(this,b)).catch(ge=>{A("Refresh token error: %s",ge.message);let ne=new m({message:"Error refreshing access token",type:"token-refresh"});throw ne.source=ge,ne});if(F)return A("Access token refreshed"),this.config({accessToken:F}),k.headers&&(k.headers.Authorization=`Bearer ${F}`),await be(p,k,Ke).catch(ne=>Pe(ne))}else throw L}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,b)}};U=new WeakMap,b=new WeakMap,R=new WeakMap,B=new WeakMap;var Te=Ae,tr=Te;var Q=s=>s?.type&&s.id&&j.includes(s.type),_e=s=>s&&typeof s.type<"u"&&s.type&&j.includes(s.type);var pe=h("jsonapi"),z=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ce(i,t)):e=ce(r,t):e=r,e},sr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ce=(s,e,r=[])=>{if(pe("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ce(sr(p,e),e,[...r,p])):t[i]=ce(sr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),pe("denormalized resource: %O",t),t},ue=s=>{pe("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&_e(o[0])&&o[0].id===null?r[i]={data:[]}:o&&_e(o)&&o.id===null?r[i]={data:null}:o&&(Q(o)||Array.isArray(o)&&Q(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return Q(s)&&(t.id=s.id),pe("normalized resource: %O",t),t};var ir=h("query"),or=["_any","_all","_in","_not_in_or_null"],Tr=s=>or.some(e=>s.endsWith(e)),nr=["_jcont"],Ar=s=>nr.some(e=>s.endsWith(e)),Oe=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),q=(s,e)=>{ir("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),Oe(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!Tr(t))throw new m({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Ar(t))throw new m({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${nr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),ir("query string params: %O",r)),r};var P={resources:s=>s?[...j].sort():j,singletons:s=>s?[...le].sort():le,isSingleton:s=>le.includes(s),isSdkError:s=>m.isSdkError(s),isApiError:s=>O.isApiError(s),init:s=>me(s),get schemaVersion(){return ve}};var _=h("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var g,Ee,xe=class{constructor(e){u(this,g);u(this,Ee,{});c(this,g,tr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return _("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,g).request("GET",a,void 0,{...t,params:p});return z(T)}async list(e,r,t){_("list: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...t,params:i}),p=z(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||f.default.pageNumber,recordsPerPage:r?.pageSize||f.default.pageSize};return new ye(a,p)}async create(e,r,t){_("create: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=ue(e),p=await n(this,g).request("POST",e.type,o,{...t,params:i});return z(p)}async update(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ue(e),I=await n(this,g).request("PATCH",a,T,{...t,params:p});return z(I)}async delete(e,r){_("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){_("fetch: %o, %O, %O",r,t||{},i||{});let o=q(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,g).request("GET",r,void 0,{...i,params:o}),a=z(p);if(Array.isArray(a)){let T=t,I={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ye(I,a)}else return a}async action(e,r,t,i){_("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&Q(t)?ue(t):t;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){_("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return z(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},y=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},ar=xe;var v=class v extends y{async create(e,r,t){return this.resources.create({...e,type:v.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:v.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="api_credentials";var Ie=v,ze=Ie;var x=class x extends y{async create(e,r,t){return this.resources.create({...e,type:x.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:x.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="application_memberships";var Me=x,Ne=Me;var C=class C extends y{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"user"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var E=class E extends y{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="memberships";var Le=E,we=Le;var M=class M extends y{async create(e,r,t){return this.resources.create({...e,type:M.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:M.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===M.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return M.TYPE}};M.TYPE="organizations";var Ue=M,Qe=Ue;var N=class N extends y{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="permissions";var je=N,qe=je;var S=class S extends y{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="roles";var $e=S,Fe=$e;var $=class $ extends Re{async update(e,r,t){return this.resources.update({...e,type:$.TYPE},r,t)}async identity_providers(e,r,t){let i=e.id||e;return this.resources.fetch({type:"identity_providers"},`user/${i}/identity_providers`,r,t)}isUser(e){return e.type&&e.type===$.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return $.TYPE}path(){return"user"}};$.TYPE="user";var Ve=$,De=Ve;var K=class K extends y{isVersion(e){return e.type&&e.type===K.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return K.TYPE}};K.TYPE="versions";var Ye=K,He=Ye;var j=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","user","versions"],le=["user"];var pr=h("commercelayer"),ve="1.0.6";var d,G,Z,X,ee,re,te,se,ie,oe,Je=class{constructor(e){this.openApiSchemaVersion=ve;u(this,d);u(this,G);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);pr("new commercelayer provisioning instance %O",e),c(this,d,new ar(e))}get api_credentials(){return n(this,G)||c(this,G,new ze(n(this,d)))}get application_memberships(){return n(this,Z)||c(this,Z,new Ne(n(this,d)))}get identity_providers(){return n(this,X)||c(this,X,new ke(n(this,d)))}get memberships(){return n(this,ee)||c(this,ee,new we(n(this,d)))}get organizations(){return n(this,re)||c(this,re,new Qe(n(this,d)))}get permissions(){return n(this,te)||c(this,te,new qe(n(this,d)))}get roles(){return n(this,se)||c(this,se,new Fe(n(this,d)))}get user(){return n(this,ie)||c(this,ie,new De(n(this,d)))}get versions(){return n(this,oe)||c(this,oe,new He(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return pr("config %o",e),this.localConfig(e),n(this,d).config(e),this}resources(){return P.resources()}singletons(){return P.singletons()}isSingleton(e){return P.isSingleton(e)}isApiError(e){return P.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,G=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap;var We=s=>new Je(s),me=We;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
|
1
|
+
"use strict";var he=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var Ge=s=>{throw TypeError(s)};var mr=(s,e)=>{for(var r in e)he(s,r,{get:e[r],enumerable:!0})},yr=(s,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ur(e))!lr.call(s,i)&&i!==r&&he(s,i,{get:()=>e[i],enumerable:!(t=cr(e,i))||t.enumerable});return s};var dr=s=>yr(he({},"__esModule",{value:!0}),s);var Ze=(s,e,r)=>e.has(s)||Ge("Cannot "+r);var n=(s,e,r)=>(Ze(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ge("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ze(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var Or={};mr(Or,{CommerceLayerProvisioning:()=>We,CommerceLayerProvisioningStatic:()=>P,default:()=>me});module.exports=dr(Or);var Rr=(s,...e)=>{},Xe=s=>Rr;try{let s=require("debug");s&&typeof s=="function"&&(Xe=s)}catch{}var gr="clsdk",hr=s=>Xe(`${gr}:${s}`),h=hr;var fe=h("fetch"),D,Y,H,ae=class ae extends Error{constructor(r,t,i){super(t);u(this,D);u(this,Y);u(this,H);c(this,Y,r),c(this,H,t),i&&c(this,D,i.errors)}get errors(){return n(this,D)}get status(){return n(this,Y)}get statusText(){return n(this,H)}};D=new WeakMap,Y=new WeakMap,H=new WeakMap,ae.isFetchError=r=>r instanceof ae;var V=ae,be=async(s,e,r)=>{fe("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(fe("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(fe("error: %s",a.message),o.ok)throw new m({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new V(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var L=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(L||{}),J=class J extends Error{static isSdkError(e){return e&&[J.NAME,O.NAME].includes(e.name)&&Object.values(L).includes(e.type)}constructor(e){super(e.message),this.name=J.NAME,this.type=e.type||"client"}};J.NAME="SdkError";var m=J,W=class W extends m{constructor(r){super({...r,type:"response"});this.errors=[];this.name=W.NAME}static isApiError(r){return m.isSdkError(r)&&r.name===W.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};W.NAME="ApiError";var O=W,fr=s=>s instanceof TypeError,br=s=>s instanceof DOMException&&s.name==="AbortError",Pr=s=>s instanceof DOMException&&s.name==="TimeoutError",er=s=>O.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),Pe=s=>{if(m.isSdkError(s)||O.isApiError(s))throw s;let e=new m({message:s.message});if(V.isFetchError(s)){let r=new O(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else fr(s)?e.type="request":br(s)?e.type="cancel":Pr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var Cr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},f=Cr;var rr=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=h("client"),Ce=s=>`https://provisioning.${s||f.default.domain}/api`,U,b,R,B,Ae=class Ae{constructor(e){u(this,U);u(this,b);u(this,R);u(this,B);A("new client instance %O",e),c(this,U,Ce(e.domain)),c(this,b,e.accessToken);let r={timeout:e.timeout||f.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,b)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,R,r),A("fetch config: %O",r),c(this,B,{})}static create(e){for(let r of f.client.requiredAttributes)if(!e||!e[r])throw new m({message:`Undefined '${r}' parameter`});return new Ae(e)}get interceptors(){return n(this,B)}get requestHeaders(){return n(this,R).headers||(n(this,R).headers={}),n(this,R).headers}config(e){A("config %o",e);let r=n(this,R);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,R).fetch=e.fetch),e.refreshToken&&(n(this,R).refreshToken=e.refreshToken),e.domain&&c(this,U,Ce(e.domain)),e.accessToken&&(c(this,b,e.accessToken),r.headers.Authorization="Bearer "+n(this,b)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Ce(i.domain):n(this,U),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},z=i?.accessToken||n(this,b);z&&(T.Authorization="Bearer "+z);let k={method:e,body:a,headers:T},Be=i?.timeout||n(this,R).timeout;Be&&(AbortSignal?.timeout?k.signal=AbortSignal.timeout(Be):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,$])=>{p.searchParams.append(w,String($))});let Ke={interceptors:this.interceptors,fetch:i?.fetch||n(this,R).fetch};try{return await be(p,k,Ke).catch(w=>Pe(w))}catch(w){if(er(w)&&n(this,R).refreshToken&&rr(n(this,b))){A("Access token has expired");let $=await n(this,R).refreshToken(n(this,b)).catch(ge=>{A("Refresh token error: %s",ge.message);let ne=new m({message:"Error refreshing access token",type:"token-refresh"});throw ne.source=ge,ne});if($)return A("Access token refreshed"),this.config({accessToken:$}),k.headers&&(k.headers.Authorization=`Bearer ${$}`),await be(p,k,Ke).catch(ne=>Pe(ne))}else throw w}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,b)}};U=new WeakMap,b=new WeakMap,R=new WeakMap,B=new WeakMap;var Te=Ae,tr=Te;var Q=s=>s?.type&&s.id&&j.includes(s.type),_e=s=>s&&typeof s.type<"u"&&s.type&&j.includes(s.type);var pe=h("jsonapi"),M=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ce(i,t)):e=ce(r,t):e=r,e},sr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ce=(s,e,r=[])=>{if(pe("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=f.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ce(sr(p,e),e,[...r,p])):t[i]=ce(sr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),pe("denormalized resource: %O",t),t},ue=s=>{pe("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&_e(o[0])&&o[0].id===null?r[i]={data:[]}:o&&_e(o)&&o.id===null?r[i]={data:null}:o&&(Q(o)||Array.isArray(o)&&Q(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return Q(s)&&(t.id=s.id),pe("normalized resource: %O",t),t};var ir=h("query"),or=["_any","_all","_in","_not_in_or_null"],Tr=s=>or.some(e=>s.endsWith(e)),nr=["_jcont"],Ar=s=>nr.some(e=>s.endsWith(e)),Oe=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),q=(s,e)=>{ir("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),Oe(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!Tr(t))throw new m({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!Ar(t))throw new m({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${nr.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),ir("query string params: %O",r)),r};var P={resources:s=>s?[...j].sort():j,singletons:s=>s?[...le].sort():le,isSingleton:s=>le.includes(s),isSdkError:s=>m.isSdkError(s),isApiError:s=>O.isApiError(s),init:s=>me(s),get schemaVersion(){return xe}};var _=h("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var g,Ee,ve=class{constructor(e){u(this,g);u(this,Ee,{});c(this,g,tr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return _("config %o",e),this.localConfig(e),n(this,g).config(e),this}get client(){return n(this,g)}async retrieve(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,g).request("GET",a,void 0,{...t,params:p});return M(T)}async list(e,r,t){_("list: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,g).request("GET",`${e.type}`,void 0,{...t,params:i}),p=M(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||f.default.pageNumber,recordsPerPage:r?.pageSize||f.default.pageSize};return new ye(a,p)}async create(e,r,t){_("create: %o, %O, %O",e,r||{},t||{});let i=q(r,e);t?.params&&Object.assign(i,t?.params);let o=ue(e),p=await n(this,g).request("POST",e.type,o,{...t,params:i});return M(p)}async update(e,r,t,i){let o=!("id"in e)||P.isSingleton(e.type);_("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=q(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=ue(e),z=await n(this,g).request("PATCH",a,T,{...t,params:p});return M(z)}async delete(e,r){_("delete: %o, %O",e,r||{}),await n(this,g).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){_("fetch: %o, %O, %O",r,t||{},i||{});let o=q(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,g).request("GET",r,void 0,{...i,params:o}),a=M(p);if(Array.isArray(a)){let T=t,z={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||f.default.pageNumber,recordsPerPage:T?.pageSize||f.default.pageSize};return new ye(z,a)}else return a}async action(e,r,t,i){_("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&Q(t)?ue(t):t;await n(this,g).request(e,r,p,{...i,params:o})}};g=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){_("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new m({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return M(r)}catch(r){throw m.isSdkError(r)?r:new m({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},y=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:Oe(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},ar=ve;var x=class x extends y{async create(e,r,t){return this.resources.create({...e,type:x.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:x.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var ze=x,Me=ze;var v=class v extends y{async create(e,r,t){return this.resources.create({...e,type:v.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:v.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="application_memberships";var Ie=v,Ne=Ie;var C=class C extends y{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var E=class E extends y{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="memberships";var we=E,Le=we;var I=class I extends y{async create(e,r,t){return this.resources.create({...e,type:I.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:I.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="organizations";var Ue=I,Qe=Ue;var N=class N extends y{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="permissions";var je=N,qe=je;var S=class S extends y{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="roles";var Fe=S,$e=Fe;var F=class F extends Re{async update(e,r,t){return this.resources.update({...e,type:F.TYPE},r,t,this.path())}isUser(e){return e.type&&e.type===F.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return F.TYPE}path(){return"user"}};F.TYPE="users";var Ve=F,De=Ve;var K=class K extends y{isVersion(e){return e.type&&e.type===K.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return K.TYPE}};K.TYPE="versions";var Ye=K,He=Ye;var j=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","users","versions"],le=["users"];var pr=h("commercelayer"),xe="1.0.7";var d,G,Z,X,ee,re,te,se,ie,oe,Je=class{constructor(e){this.openApiSchemaVersion=xe;u(this,d);u(this,G);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);pr("new commercelayer provisioning instance %O",e),c(this,d,new ar(e))}get api_credentials(){return n(this,G)||c(this,G,new Me(n(this,d)))}get application_memberships(){return n(this,Z)||c(this,Z,new Ne(n(this,d)))}get identity_providers(){return n(this,X)||c(this,X,new ke(n(this,d)))}get memberships(){return n(this,ee)||c(this,ee,new Le(n(this,d)))}get organizations(){return n(this,re)||c(this,re,new Qe(n(this,d)))}get permissions(){return n(this,te)||c(this,te,new qe(n(this,d)))}get roles(){return n(this,se)||c(this,se,new $e(n(this,d)))}get user(){return n(this,ie)||c(this,ie,new De(n(this,d)))}get versions(){return n(this,oe)||c(this,oe,new He(n(this,d)))}get currentAccessToken(){return n(this,d)?.client?.currentAccessToken}get interceptors(){return n(this,d).client.interceptors}localConfig(e){}config(e){return pr("config %o",e),this.localConfig(e),n(this,d).config(e),this}resources(){return P.resources()}singletons(){return P.singletons()}isSingleton(e){return P.isSingleton(e)}isApiError(e){return P.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};d=new WeakMap,G=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap;var We=s=>new Je(s),me=We;0&&(module.exports={CommerceLayerProvisioning,CommerceLayerProvisioningStatic});
|
package/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ke=s=>{throw TypeError(s)};var cr=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ge=(s,e,r)=>e.has(s)||Ke("Cannot "+r);var n=(s,e,r)=>(Ge(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ge(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var ur=(s,...e)=>{},Ze=s=>ur;try{let s=cr("debug");s&&typeof s=="function"&&(Ze=s)}catch{}var lr="clsdk",mr=s=>Ze(`${lr}:${s}`),f=mr;var he=f("fetch"),Y,H,J,pe=class pe extends Error{constructor(r,t,i){super(t);u(this,Y);u(this,H);u(this,J);c(this,H,r),c(this,J,t),i&&c(this,Y,i.errors)}get errors(){return n(this,Y)}get status(){return n(this,H)}get statusText(){return n(this,J)}};Y=new WeakMap,H=new WeakMap,J=new WeakMap,pe.isFetchError=r=>r instanceof pe;var D=pe,fe=async(s,e,r)=>{he("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(he("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(he("error: %s",a.message),o.ok)throw new y({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new D(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var U=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(U||{}),W=class W extends Error{static isSdkError(e){return e&&[W.NAME,v.NAME].includes(e.name)&&Object.values(U).includes(e.type)}constructor(e){super(e.message),this.name=W.NAME,this.type=e.type||"client"}};W.NAME="SdkError";var y=W,B=class B extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=B.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===B.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};B.NAME="ApiError";var v=B,yr=s=>s instanceof TypeError,dr=s=>s instanceof DOMException&&s.name==="AbortError",Rr=s=>s instanceof DOMException&&s.name==="TimeoutError",Xe=s=>v.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),be=s=>{if(y.isSdkError(s)||v.isApiError(s))throw s;let e=new y({message:s.message});if(D.isFetchError(s)){let r=new v(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else yr(s)?e.type="request":dr(s)?e.type="cancel":Rr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var gr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=gr;var er=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=f("client"),Pe=s=>`https://provisioning.${s||b.default.domain}/api`,Q,P,g,K,Te=class Te{constructor(e){u(this,Q);u(this,P);u(this,g);u(this,K);A("new client instance %O",e),c(this,Q,Pe(e.domain)),c(this,P,e.accessToken);let r={timeout:e.timeout||b.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,g,r),A("fetch config: %O",r),c(this,K,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Te(e)}get interceptors(){return n(this,K)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){A("config %o",e);let r=n(this,g);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,g).fetch=e.fetch),e.refreshToken&&(n(this,g).refreshToken=e.refreshToken),e.domain&&c(this,Q,Pe(e.domain)),e.accessToken&&(c(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Pe(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},z=i?.accessToken||n(this,P);z&&(T.Authorization="Bearer "+z);let L={method:e,body:a,headers:T},We=i?.timeout||n(this,g).timeout;We&&(AbortSignal?.timeout?L.signal=AbortSignal.timeout(We):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([w,V])=>{p.searchParams.append(w,String(V))});let Be={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await fe(p,L,Be).catch(w=>be(w))}catch(w){if(Xe(w)&&n(this,g).refreshToken&&er(n(this,P))){A("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(ge=>{A("Refresh token error: %s",ge.message);let ae=new y({message:"Error refreshing access token",type:"token-refresh"});throw ae.source=ge,ae});if(V)return A("Access token refreshed"),this.config({accessToken:V}),L.headers&&(L.headers.Authorization=`Bearer ${V}`),await fe(p,L,Be).catch(ae=>be(ae))}else throw w}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,P)}};Q=new WeakMap,P=new WeakMap,g=new WeakMap,K=new WeakMap;var Ce=Te,rr=Ce;var j=s=>s?.type&&s.id&&q.includes(s.type),Ae=s=>s&&typeof s.type<"u"&&s.type&&q.includes(s.type);var ce=f("jsonapi"),M=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ue(i,t)):e=ue(r,t):e=r,e},tr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ue=(s,e,r=[])=>{if(ce("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ue(tr(p,e),e,[...r,p])):t[i]=ue(tr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),ce("denormalized resource: %O",t),t},le=s=>{ce("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&Ae(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ae(o)&&o.id===null?r[i]={data:null}:o&&(j(o)||Array.isArray(o)&&j(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return j(s)&&(t.id=s.id),ce("normalized resource: %O",t),t};var sr=f("query"),ir=["_any","_all","_in","_not_in_or_null"],hr=s=>ir.some(e=>s.endsWith(e)),or=["_jcont"],fr=s=>or.some(e=>s.endsWith(e)),_e=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),$=(s,e)=>{sr("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),_e(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!hr(t))throw new y({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${ir.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!fr(t))throw new y({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),sr("query string params: %O",r)),r};var _={resources:s=>s?[...q].sort():q,singletons:s=>s?[...me].sort():me,isSingleton:s=>me.includes(s),isSdkError:s=>y.isSdkError(s),isApiError:s=>v.isApiError(s),init:s=>ve(s),get schemaVersion(){return Oe}};var O=f("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var h,Ee,xe=class{constructor(e){u(this,h);u(this,Ee,{});c(this,h,rr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return O("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=$(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...t,params:p});return M(T)}async list(e,r,t){O("list: %o, %O, %O",e,r||{},t||{});let i=$(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...t,params:i}),p=M(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||b.default.pageNumber,recordsPerPage:r?.pageSize||b.default.pageSize};return new ye(a,p)}async create(e,r,t){O("create: %o, %O, %O",e,r||{},t||{});let i=$(r,e);t?.params&&Object.assign(i,t?.params);let o=le(e),p=await n(this,h).request("POST",e.type,o,{...t,params:i});return M(p)}async update(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=$(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=le(e),z=await n(this,h).request("PATCH",a,T,{...t,params:p});return M(z)}async delete(e,r){O("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){O("fetch: %o, %O, %O",r,t||{},i||{});let o=$(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=M(p);if(Array.isArray(a)){let T=t,z={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||b.default.pageNumber,recordsPerPage:T?.pageSize||b.default.pageSize};return new ye(z,a)}else return a}async action(e,r,t,i){O("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&j(t)?le(t):t;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){O("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new y({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return M(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},d=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:_e(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},nr=xe;var x=class x extends d{async create(e,r,t){return this.resources.create({...e,type:x.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:x.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:x.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===x.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return x.TYPE}};x.TYPE="api_credentials";var Ie=x,ze=Ie;var E=class E extends d{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="application_memberships";var Me=E,Ne=Me;var C=class C extends d{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"user"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var I=class I extends d{async create(e,r,t){return this.resources.create({...e,type:I.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:I.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:I.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===I.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return I.TYPE}};I.TYPE="memberships";var Le=I,we=Le;var N=class N extends d{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="organizations";var Ue=N,Qe=Ue;var S=class S extends d{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="permissions";var je=S,qe=je;var k=class k extends d{async create(e,r,t){return this.resources.create({...e,type:k.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:k.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="roles";var $e=k,Fe=$e;var F=class F extends Re{async update(e,r,t){return this.resources.update({...e,type:F.TYPE},r,t)}async identity_providers(e,r,t){let i=e.id||e;return this.resources.fetch({type:"identity_providers"},`user/${i}/identity_providers`,r,t)}isUser(e){return e.type&&e.type===F.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return F.TYPE}path(){return"user"}};F.TYPE="user";var Ve=F,De=Ve;var G=class G extends d{isVersion(e){return e.type&&e.type===G.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return G.TYPE}};G.TYPE="versions";var Ye=G,He=Ye;var q=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","user","versions"],me=["user"];var ar=f("commercelayer"),Oe="1.0.6";var R,Z,X,ee,re,te,se,ie,oe,ne,Je=class{constructor(e){this.openApiSchemaVersion=Oe;u(this,R);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);u(this,ne);ar("new commercelayer provisioning instance %O",e),c(this,R,new nr(e))}get api_credentials(){return n(this,Z)||c(this,Z,new ze(n(this,R)))}get application_memberships(){return n(this,X)||c(this,X,new Ne(n(this,R)))}get identity_providers(){return n(this,ee)||c(this,ee,new ke(n(this,R)))}get memberships(){return n(this,re)||c(this,re,new we(n(this,R)))}get organizations(){return n(this,te)||c(this,te,new Qe(n(this,R)))}get permissions(){return n(this,se)||c(this,se,new qe(n(this,R)))}get roles(){return n(this,ie)||c(this,ie,new Fe(n(this,R)))}get user(){return n(this,oe)||c(this,oe,new De(n(this,R)))}get versions(){return n(this,ne)||c(this,ne,new He(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ar("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return _.resources()}singletons(){return _.singletons()}isSingleton(e){return _.isSingleton(e)}isApiError(e){return _.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap;var pr=s=>new Je(s),ve=pr;export{pr as CommerceLayerProvisioning,_ as CommerceLayerProvisioningStatic,ve as default};
|
|
1
|
+
var Ke=s=>{throw TypeError(s)};var cr=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ge=(s,e,r)=>e.has(s)||Ke("Cannot "+r);var n=(s,e,r)=>(Ge(s,e,"read from private field"),r?r.call(s):e.get(s)),u=(s,e,r)=>e.has(s)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,r),c=(s,e,r,t)=>(Ge(s,e,"write to private field"),t?t.call(s,r):e.set(s,r),r);var ur=(s,...e)=>{},Ze=s=>ur;try{let s=cr("debug");s&&typeof s=="function"&&(Ze=s)}catch{}var lr="clsdk",mr=s=>Ze(`${lr}:${s}`),f=mr;var he=f("fetch"),Y,H,J,pe=class pe extends Error{constructor(r,t,i){super(t);u(this,Y);u(this,H);u(this,J);c(this,H,r),c(this,J,t),i&&c(this,Y,i.errors)}get errors(){return n(this,Y)}get status(){return n(this,H)}get statusText(){return n(this,J)}};Y=new WeakMap,H=new WeakMap,J=new WeakMap,pe.isFetchError=r=>r instanceof pe;var D=pe,fe=async(s,e,r)=>{he("fetch: %s, %O, native[%s]",s,e||{},r?.fetch?"no":"yes");let t=r?.interceptors;t?.request?.onSuccess&&({url:s,options:e}=await t.request.onSuccess({url:s,options:e}));let o=await(r?.fetch||fetch)(s,e);o.ok?(t?.rawReader?.onSuccess&&await t.rawReader.onSuccess(o),t?.response?.onSuccess&&(o=await t.response.onSuccess(o))):t?.rawReader?.onFailure&&await t.rawReader.onFailure(o);let p=o.body&&o.status!==204?await o.text().then(a=>(he("response: %O",a),a?.trim()?JSON.parse(a):a)).catch(a=>{if(he("error: %s",a.message),o.ok)throw new y({message:"Error parsing API response body",type:"parse"})}):void 0;if(!o.ok){let a=new D(o.status,o.statusText,p);if(t?.response?.onFailure&&(a=await t.response.onFailure(a)),a)throw a}return p};var U=(a=>(a.CLIENT="client",a.REQUEST="request",a.RESPONSE="response",a.CANCEL="cancel",a.PARSE="parse",a.TIMEOUT="timeout",a.TOKEN_REFRESH="token-refresh",a))(U||{}),W=class W extends Error{static isSdkError(e){return e&&[W.NAME,x.NAME].includes(e.name)&&Object.values(U).includes(e.type)}constructor(e){super(e.message),this.name=W.NAME,this.type=e.type||"client"}};W.NAME="SdkError";var y=W,B=class B extends y{constructor(r){super({...r,type:"response"});this.errors=[];this.name=B.NAME}static isApiError(r){return y.isSdkError(r)&&r.name===B.NAME&&r.type==="response"}first(){return this.errors?.length>0?this.errors[0]:void 0}};B.NAME="ApiError";var x=B,yr=s=>s instanceof TypeError,dr=s=>s instanceof DOMException&&s.name==="AbortError",Rr=s=>s instanceof DOMException&&s.name==="TimeoutError",Xe=s=>x.isApiError(s)&&s.status===401&&(["INVALID_TOKEN","UNAUTHORIZED"].includes(s.code||"")||s.errors&&s.errors.length>0&&["INVALID_TOKEN","UNAUTHORIZED"].includes(s.errors[0].code)),be=s=>{if(y.isSdkError(s)||x.isApiError(s))throw s;let e=new y({message:s.message});if(D.isFetchError(s)){let r=new x(e);r.type="response",r.status=s.status,r.statusText=s.statusText,r.code=String(r.status),r.errors=s.errors||[],!r.message&&r.statusText&&(r.message=r.statusText),e=r}else yr(s)?e.type="request":dr(s)?e.type="cancel":Rr(s)?e.type="timeout":(e.type="client",e.source=s);throw e};var gr={default:{domain:"commercelayer.io",pageNumber:1,pageSize:10},client:{timeout:15e3,requiredAttributes:["accessToken"]},jsonapi:{maxResourceIncluded:2}},b=gr;var er=s=>{try{return JSON.parse(atob(s.split(".")[1])).exp*1e3-Date.now()<0}catch{return!1}};var A=f("client"),Pe=s=>`https://provisioning.${s||b.default.domain}/api`,Q,P,g,K,Te=class Te{constructor(e){u(this,Q);u(this,P);u(this,g);u(this,K);A("new client instance %O",e),c(this,Q,Pe(e.domain)),c(this,P,e.accessToken);let r={timeout:e.timeout||b.client.timeout,fetch:e.fetch,refreshToken:e.refreshToken},i={...this.customHeaders(e.headers),Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,P)};e.userAgent&&(i["User-Agent"]=e.userAgent),r.headers=i,c(this,g,r),A("fetch config: %O",r),c(this,K,{})}static create(e){for(let r of b.client.requiredAttributes)if(!e||!e[r])throw new y({message:`Undefined '${r}' parameter`});return new Te(e)}get interceptors(){return n(this,K)}get requestHeaders(){return n(this,g).headers||(n(this,g).headers={}),n(this,g).headers}config(e){A("config %o",e);let r=n(this,g);return r.headers||(r.headers={}),e.timeout&&(r.timeout=e.timeout),e.userAgent&&this.userAgent(e.userAgent),e.fetch&&(n(this,g).fetch=e.fetch),e.refreshToken&&(n(this,g).refreshToken=e.refreshToken),e.domain&&c(this,Q,Pe(e.domain)),e.accessToken&&(c(this,P,e.accessToken),r.headers.Authorization="Bearer "+n(this,P)),e.headers&&(r.headers={...r.headers,...this.customHeaders(e.headers)}),this}userAgent(e){return e&&(this.requestHeaders["User-Agent"]=e),this}async request(e,r,t,i){A("request %s %s, %O, %O",e,r,t||{},i||{}),i?.userAgent&&A("User-Agent header ignored in request config");let o=i?.domain?Pe(i.domain):n(this,Q),p=new URL(`${o}/${r}`),a=t?JSON.stringify({data:t}):void 0,T={...this.requestHeaders,...this.customHeaders(i?.headers)},M=i?.accessToken||n(this,P);M&&(T.Authorization="Bearer "+M);let w={method:e,body:a,headers:T},We=i?.timeout||n(this,g).timeout;We&&(AbortSignal?.timeout?w.signal=AbortSignal.timeout(We):A("Timeout not set. Undefined function: %s","AbortSignal.timeout")),i?.params&&Object.entries(i?.params).forEach(([L,V])=>{p.searchParams.append(L,String(V))});let Be={interceptors:this.interceptors,fetch:i?.fetch||n(this,g).fetch};try{return await fe(p,w,Be).catch(L=>be(L))}catch(L){if(Xe(L)&&n(this,g).refreshToken&&er(n(this,P))){A("Access token has expired");let V=await n(this,g).refreshToken(n(this,P)).catch(ge=>{A("Refresh token error: %s",ge.message);let ae=new y({message:"Error refreshing access token",type:"token-refresh"});throw ae.source=ge,ae});if(V)return A("Access token refreshed"),this.config({accessToken:V}),w.headers&&(w.headers.Authorization=`Bearer ${V}`),await fe(p,w,Be).catch(ae=>be(ae))}else throw L}}customHeaders(e){let r={};if(e)for(let[t,i]of Object.entries(e))["accept","content-type","authorization","user-agent"].includes(t.toLowerCase())||(r[t]=i);return r}get currentAccessToken(){return n(this,P)}};Q=new WeakMap,P=new WeakMap,g=new WeakMap,K=new WeakMap;var Ce=Te,rr=Ce;var j=s=>s?.type&&s.id&&q.includes(s.type),Ae=s=>s&&typeof s.type<"u"&&s.type&&q.includes(s.type);var ce=f("jsonapi"),I=s=>{let e;s.links&&delete s.links;let r=s.data,t=s.included;return r?Array.isArray(r)?e=r.map(i=>ue(i,t)):e=ue(r,t):e=r,e},tr=(s,e=[])=>e.find(t=>s.id===t.id&&s.type===t.type)||s,ue=(s,e,r=[])=>{if(ce("denormalize resource: %O, %o",s,e||{}),!s)return s;let t={id:s.id,type:s.type,...s.attributes};return s.relationships&&Object.keys(s.relationships).forEach(i=>{let o=s.relationships[i].data;o?r.filter(p=>p.id===o.id&&p.type===o.type).length>=b.jsonapi.maxResourceIncluded?t[i]=o:Array.isArray(o)?t[i]=o.map(p=>ue(tr(p,e),e,[...r,p])):t[i]=ue(tr(o,e),e,[...r,o]):o===null&&(t[i]=null)}),ce("denormalized resource: %O",t),t},le=s=>{ce("normalize resource: %O",s);let e={},r={};for(let i in s){if(["type","id"].includes(i))continue;let o=s[i];Array.isArray(o)&&o.length===1&&Ae(o[0])&&o[0].id===null?r[i]={data:[]}:o&&Ae(o)&&o.id===null?r[i]={data:null}:o&&(j(o)||Array.isArray(o)&&j(o[0]))?r[i]={data:o}:e[i]=o}let t={type:s.type,attributes:e,relationships:r};return j(s)&&(t.id=s.id),ce("normalized resource: %O",t),t};var sr=f("query"),ir=["_any","_all","_in","_not_in_or_null"],hr=s=>ir.some(e=>s.endsWith(e)),or=["_jcont"],fr=s=>or.some(e=>s.endsWith(e)),_e=s=>s&&(s.filters||s.pageNumber||s.pageSize||s.sort),F=(s,e)=>{sr("generate query string params: %O, %O",s,e);let r={};return s&&(s.include&&(r.include=s.include.join(",")),s.fields&&(Array.isArray(s.fields)&&(s.fields={[e.type||e]:s.fields}),Object.entries(s.fields).forEach(([t,i])=>{r[`fields[${t}]`]=i.join(",")})),_e(s)&&(s.sort&&(Array.isArray(s.sort)?r.sort=s.sort.join(","):r.sort=Object.entries(s.sort).map(([t,i])=>`${i==="desc"?"-":""}${t}`).join(",")),s.pageNumber&&(r["page[number]"]=String(s.pageNumber)),s.pageSize&&(r["page[size]"]=String(s.pageSize)),s.filters&&Object.entries(s.filters).forEach(([t,i])=>{let o;if(Array.isArray(i)){if(!hr(t))throw new y({message:`Incorrect filter [${t}]: Array value is supported only for the following filters: ${ir.join(", ")}`,type:"request"});o=i.join(",")}else if(typeof i=="object"){if(!fr(t))throw new y({message:`Incorrect filter [${t}]: Object value is supported only for the following filters: ${or.join(", ")}`,type:"request"});o=JSON.stringify(i)}else o=String(i);r[`filter[q][${t}]`]=o})),sr("query string params: %O",r)),r};var _={resources:s=>s?[...q].sort():q,singletons:s=>s?[...me].sort():me,isSingleton:s=>me.includes(s),isSdkError:s=>y.isSdkError(s),isApiError:s=>x.isApiError(s),init:s=>xe(s),get schemaVersion(){return Oe}};var O=f("resource"),ye=class extends Array{constructor(e,r){super(...r||[]),this.meta=e}first(){return this.length?this[0]:void 0}last(){return this.length?this[this.length-1]:void 0}get(e){return this.length&&e>=0?this[e]:void 0}hasNextPage(){return this.meta.currentPage<this.meta.pageCount}hasPrevPage(){return this.meta.currentPage>1}getRecordCount(){return this.meta.recordCount}getPageCount(){return this.meta.pageCount}get recordCount(){return this.meta.recordCount}get pageCount(){return this.meta.pageCount}};var h,Ee,ve=class{constructor(e){u(this,h);u(this,Ee,{});c(this,h,rr.create(e)),this.localConfig(e)}localConfig(e){}config(e){return O("config %o",e),this.localConfig(e),n(this,h).config(e),this}get client(){return n(this,h)}async retrieve(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("retrieve:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=await n(this,h).request("GET",a,void 0,{...t,params:p});return I(T)}async list(e,r,t){O("list: %o, %O, %O",e,r||{},t||{});let i=F(r,e);t?.params&&Object.assign(i,t?.params);let o=await n(this,h).request("GET",`${e.type}`,void 0,{...t,params:i}),p=I(o),a={pageCount:Number(o.meta?.page_count),recordCount:Number(o.meta?.record_count),currentPage:r?.pageNumber||b.default.pageNumber,recordsPerPage:r?.pageSize||b.default.pageSize};return new ye(a,p)}async create(e,r,t){O("create: %o, %O, %O",e,r||{},t||{});let i=F(r,e);t?.params&&Object.assign(i,t?.params);let o=le(e),p=await n(this,h).request("POST",e.type,o,{...t,params:i});return I(p)}async update(e,r,t,i){let o=!("id"in e)||_.isSingleton(e.type);O("update:%s %o, %O, %O",o?" singleton,":"",e,r||{},t||{});let p=F(r,e);t?.params&&Object.assign(p,t?.params);let a=`${i||e.type}${o?"":`/${e.id}`}`,T=le(e),M=await n(this,h).request("PATCH",a,T,{...t,params:p});return I(M)}async delete(e,r){O("delete: %o, %O",e,r||{}),await n(this,h).request("DELETE",`${e.type}/${e.id}`,void 0,r)}async fetch(e,r,t,i){O("fetch: %o, %O, %O",r,t||{},i||{});let o=F(t,e);i?.params&&Object.assign(o,i?.params);let p=await n(this,h).request("GET",r,void 0,{...i,params:o}),a=I(p);if(Array.isArray(a)){let T=t,M={pageCount:Number(p.meta?.page_count),recordCount:Number(p.meta?.record_count),currentPage:T?.pageNumber||b.default.pageNumber,recordsPerPage:T?.pageSize||b.default.pageSize};return new ye(M,a)}else return a}async action(e,r,t,i){O("action: %o %o, %O",e,r,i||{});let o={};i?.params&&Object.assign(o,i?.params);let p=t&&j(t)?le(t):t;await n(this,h).request(e,r,p,{...i,params:o})}};h=new WeakMap,Ee=new WeakMap;var de=class{constructor(e){O("new resource instance: %s",this.type()),this.resources=e}relationshipOneToOne(e){return e===null||typeof e=="string"?{id:e,type:this.type()}:{id:e.id,type:this.type()}}relationshipOneToMany(...e){return e===null||e.length===0||e[0]===null?[{id:null,type:this.type()}]:e.map(r=>({id:r,type:this.type()}))}path(){return this.type()}parse(e){try{let r=JSON.parse(e);if(r.data?.type!==this.type())throw new y({message:`Invalid resource type [${r.data?.type}]`,type:"parse"});return I(r)}catch(r){throw y.isSdkError(r)?r:new y({message:`Payload parse error [${r.message}]`,type:"parse"})}}async update(e,r,t){return this.resources.update({...e,type:this.type()},r,t,this.path())}},d=class extends de{async retrieve(e,r,t){return this.resources.retrieve(typeof e=="string"?{type:this.type(),id:e}:e,r,t)}async list(e,r){return this.resources.list({type:this.type()},e,r)}async count(e,r){let t={filters:_e(e)?e.filters:e,pageNumber:1,pageSize:1},i=await this.list(t,r);return Promise.resolve(i.meta.recordCount)}},Re=class extends de{async retrieve(e,r){return this.resources.retrieve({type:this.type()},e,r,this.path())}},nr=ve;var v=class v extends d{async create(e,r,t){return this.resources.create({...e,type:v.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:v.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:v.TYPE}:e,r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`api_credentials/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`api_credentials/${i}/role`,r,t)}isApiCredential(e){return e.type&&e.type===v.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return v.TYPE}};v.TYPE="api_credentials";var ze=v,Me=ze;var E=class E extends d{async create(e,r,t){return this.resources.create({...e,type:E.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:E.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:E.TYPE}:e,r)}async api_credential(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`application_memberships/${i}/api_credential`,r,t)}async membership(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`application_memberships/${i}/membership`,r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`application_memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`application_memberships/${i}/role`,r,t)}isApplicationMembership(e){return e.type&&e.type===E.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return E.TYPE}};E.TYPE="application_memberships";var Ie=E,Ne=Ie;var C=class C extends d{async create(e,r,t){return this.resources.create({...e,type:C.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:C.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:C.TYPE}:e,r)}async user(e,r,t){let i=e.id||e;return this.resources.fetch({type:"users"},`identity_providers/${i}/user`,r,t)}async _disable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_disable:!0},r,t)}async _enable(e,r,t){return this.resources.update({id:typeof e=="string"?e:e.id,type:C.TYPE,_enable:!0},r,t)}isIdentityProvider(e){return e.type&&e.type===C.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return C.TYPE}};C.TYPE="identity_providers";var Se=C,ke=Se;var z=class z extends d{async create(e,r,t){return this.resources.create({...e,type:z.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:z.TYPE},r,t)}async delete(e,r){await this.resources.delete(typeof e=="string"?{id:e,type:z.TYPE}:e,r)}async resend(e,r){let t=e.id||e;await this.resources.action("POST",`memberships/${t}/resend`,{},r)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`memberships/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`memberships/${i}/role`,r,t)}async application_memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"application_memberships"},`memberships/${i}/application_memberships`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`memberships/${i}/versions`,r,t)}isMembership(e){return e.type&&e.type===z.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return z.TYPE}};z.TYPE="memberships";var we=z,Le=we;var N=class N extends d{async create(e,r,t){return this.resources.create({...e,type:N.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:N.TYPE},r,t)}async transfer_ownership(e,r,t){let i=e.id||e;await this.resources.action("PATCH",`organizations/${i}/transfer_ownership`,{...r},t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`organizations/${i}/memberships`,r,t)}async roles(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`organizations/${i}/roles`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`organizations/${i}/permissions`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`organizations/${i}/api_credentials`,r,t)}isOrganization(e){return e.type&&e.type===N.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return N.TYPE}};N.TYPE="organizations";var Ue=N,Qe=Ue;var S=class S extends d{async create(e,r,t){return this.resources.create({...e,type:S.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:S.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`permissions/${i}/organization`,r,t)}async role(e,r,t){let i=e.id||e;return this.resources.fetch({type:"roles"},`permissions/${i}/role`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`permissions/${i}/versions`,r,t)}isPermission(e){return e.type&&e.type===S.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return S.TYPE}};S.TYPE="permissions";var je=S,qe=je;var k=class k extends d{async create(e,r,t){return this.resources.create({...e,type:k.TYPE},r,t)}async update(e,r,t){return this.resources.update({...e,type:k.TYPE},r,t)}async organization(e,r,t){let i=e.id||e;return this.resources.fetch({type:"organizations"},`roles/${i}/organization`,r,t)}async permissions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"permissions"},`roles/${i}/permissions`,r,t)}async memberships(e,r,t){let i=e.id||e;return this.resources.fetch({type:"memberships"},`roles/${i}/memberships`,r,t)}async api_credentials(e,r,t){let i=e.id||e;return this.resources.fetch({type:"api_credentials"},`roles/${i}/api_credentials`,r,t)}async versions(e,r,t){let i=e.id||e;return this.resources.fetch({type:"versions"},`roles/${i}/versions`,r,t)}isRole(e){return e.type&&e.type===k.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return k.TYPE}};k.TYPE="roles";var Fe=k,$e=Fe;var $=class $ extends Re{async update(e,r,t){return this.resources.update({...e,type:$.TYPE},r,t,this.path())}isUser(e){return e.type&&e.type===$.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return $.TYPE}path(){return"user"}};$.TYPE="users";var Ve=$,De=Ve;var G=class G extends d{isVersion(e){return e.type&&e.type===G.TYPE}relationship(e){return super.relationshipOneToOne(e)}relationshipToMany(...e){return super.relationshipOneToMany(...e)}type(){return G.TYPE}};G.TYPE="versions";var Ye=G,He=Ye;var q=["api_credentials","application_memberships","identity_providers","memberships","organizations","permissions","roles","users","versions"],me=["users"];var ar=f("commercelayer"),Oe="1.0.7";var R,Z,X,ee,re,te,se,ie,oe,ne,Je=class{constructor(e){this.openApiSchemaVersion=Oe;u(this,R);u(this,Z);u(this,X);u(this,ee);u(this,re);u(this,te);u(this,se);u(this,ie);u(this,oe);u(this,ne);ar("new commercelayer provisioning instance %O",e),c(this,R,new nr(e))}get api_credentials(){return n(this,Z)||c(this,Z,new Me(n(this,R)))}get application_memberships(){return n(this,X)||c(this,X,new Ne(n(this,R)))}get identity_providers(){return n(this,ee)||c(this,ee,new ke(n(this,R)))}get memberships(){return n(this,re)||c(this,re,new Le(n(this,R)))}get organizations(){return n(this,te)||c(this,te,new Qe(n(this,R)))}get permissions(){return n(this,se)||c(this,se,new qe(n(this,R)))}get roles(){return n(this,ie)||c(this,ie,new $e(n(this,R)))}get user(){return n(this,oe)||c(this,oe,new De(n(this,R)))}get versions(){return n(this,ne)||c(this,ne,new He(n(this,R)))}get currentAccessToken(){return n(this,R)?.client?.currentAccessToken}get interceptors(){return n(this,R).client.interceptors}localConfig(e){}config(e){return ar("config %o",e),this.localConfig(e),n(this,R).config(e),this}resources(){return _.resources()}singletons(){return _.singletons()}isSingleton(e){return _.isSingleton(e)}isApiError(e){return _.isApiError(e)}addRequestInterceptor(e,r){return this.interceptors.request={onSuccess:e,onFailure:r},1}addResponseInterceptor(e,r){return this.interceptors.response={onSuccess:e,onFailure:r},1}removeInterceptor(e,r=1){this.interceptors[e]=void 0}removeInterceptors(){this.removeInterceptor("request"),this.removeInterceptor("response"),this.removeRawResponseReader()}addRawResponseReader(e){let r={id:0,rawResponse:void 0,headers:void 0,ok:!0};async function t(i){if(r.rawResponse=await i?.clone().json().catch(()=>{}),r.ok=i.ok,e?.headers){let o={};i.headers.forEach((p,a)=>{o[a]=p}),r.headers=o}return i}return this.interceptors.rawReader={onSuccess:t,onFailure:t},r.id=1,r}removeRawResponseReader(){this.interceptors.rawReader=void 0}};R=new WeakMap,Z=new WeakMap,X=new WeakMap,ee=new WeakMap,re=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,oe=new WeakMap,ne=new WeakMap;var pr=s=>new Je(s),xe=pr;export{pr as CommerceLayerProvisioning,_ as CommerceLayerProvisioningStatic,xe as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/provisioning-sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage",
|
|
9
9
|
"build": "tsup",
|
|
10
10
|
"generate": "tsx gen/generator.ts",
|
|
11
|
-
"generate-local": "
|
|
11
|
+
"generate-local": "pnpm generate --local",
|
|
12
12
|
"lint": "eslint ./src --ext .ts",
|
|
13
13
|
"lintspec": "eslint ./specs/resources/ --ext .spec.ts",
|
|
14
14
|
"semantic-release": "semantic-release",
|