@commercelayer/sdk 5.35.0 → 6.0.0-alfa.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.
Files changed (138) hide show
  1. package/lib/cjs/client.js +5 -5
  2. package/lib/cjs/commercelayer.d.ts +2 -2
  3. package/lib/cjs/commercelayer.js +3 -3
  4. package/lib/cjs/common.js +1 -1
  5. package/lib/cjs/error.js +1 -2
  6. package/lib/cjs/interceptor.d.ts +2 -2
  7. package/lib/cjs/resource.js +21 -24
  8. package/lib/esm/client.js +19 -30
  9. package/lib/esm/commercelayer.d.ts +2 -2
  10. package/lib/esm/commercelayer.js +260 -149
  11. package/lib/esm/common.js +1 -1
  12. package/lib/esm/error.js +10 -5
  13. package/lib/esm/interceptor.d.ts +2 -2
  14. package/lib/esm/resource.js +37 -50
  15. package/lib/esm/resources/addresses.js +1 -1
  16. package/lib/esm/resources/adjustments.js +1 -1
  17. package/lib/esm/resources/adyen_gateways.js +1 -1
  18. package/lib/esm/resources/adyen_payments.js +1 -1
  19. package/lib/esm/resources/application.js +1 -1
  20. package/lib/esm/resources/attachments.js +1 -1
  21. package/lib/esm/resources/authorizations.js +1 -1
  22. package/lib/esm/resources/avalara_accounts.js +1 -1
  23. package/lib/esm/resources/axerve_gateways.js +1 -1
  24. package/lib/esm/resources/axerve_payments.js +1 -1
  25. package/lib/esm/resources/billing_info_validation_rules.js +1 -1
  26. package/lib/esm/resources/bing_geocoders.js +1 -1
  27. package/lib/esm/resources/braintree_gateways.js +1 -1
  28. package/lib/esm/resources/braintree_payments.js +1 -1
  29. package/lib/esm/resources/bundles.js +1 -1
  30. package/lib/esm/resources/buy_x_pay_y_promotions.js +1 -1
  31. package/lib/esm/resources/captures.js +1 -1
  32. package/lib/esm/resources/carrier_accounts.js +1 -1
  33. package/lib/esm/resources/checkout_com_gateways.js +1 -1
  34. package/lib/esm/resources/checkout_com_payments.js +1 -1
  35. package/lib/esm/resources/cleanups.js +1 -1
  36. package/lib/esm/resources/coupon_codes_promotion_rules.js +1 -1
  37. package/lib/esm/resources/coupon_recipients.js +1 -1
  38. package/lib/esm/resources/coupons.js +1 -1
  39. package/lib/esm/resources/custom_promotion_rules.js +1 -1
  40. package/lib/esm/resources/customer_addresses.js +1 -1
  41. package/lib/esm/resources/customer_groups.js +1 -1
  42. package/lib/esm/resources/customer_password_resets.js +1 -1
  43. package/lib/esm/resources/customer_payment_sources.js +1 -1
  44. package/lib/esm/resources/customer_subscriptions.js +1 -1
  45. package/lib/esm/resources/customers.js +1 -1
  46. package/lib/esm/resources/delivery_lead_times.js +1 -1
  47. package/lib/esm/resources/event_callbacks.js +1 -1
  48. package/lib/esm/resources/events.js +1 -1
  49. package/lib/esm/resources/exports.js +1 -1
  50. package/lib/esm/resources/external_gateways.js +1 -1
  51. package/lib/esm/resources/external_payments.js +1 -1
  52. package/lib/esm/resources/external_promotions.js +1 -1
  53. package/lib/esm/resources/external_tax_calculators.js +1 -1
  54. package/lib/esm/resources/fixed_amount_promotions.js +1 -1
  55. package/lib/esm/resources/fixed_price_promotions.js +1 -1
  56. package/lib/esm/resources/free_gift_promotions.js +1 -1
  57. package/lib/esm/resources/free_shipping_promotions.js +1 -1
  58. package/lib/esm/resources/geocoders.js +1 -1
  59. package/lib/esm/resources/gift_card_recipients.js +1 -1
  60. package/lib/esm/resources/gift_cards.js +1 -1
  61. package/lib/esm/resources/google_geocoders.js +1 -1
  62. package/lib/esm/resources/imports.js +1 -1
  63. package/lib/esm/resources/in_stock_subscriptions.js +1 -1
  64. package/lib/esm/resources/inventory_models.js +1 -1
  65. package/lib/esm/resources/inventory_return_locations.js +1 -1
  66. package/lib/esm/resources/inventory_stock_locations.js +1 -1
  67. package/lib/esm/resources/klarna_gateways.js +1 -1
  68. package/lib/esm/resources/klarna_payments.js +1 -1
  69. package/lib/esm/resources/line_item_options.js +1 -1
  70. package/lib/esm/resources/line_items.js +1 -1
  71. package/lib/esm/resources/manual_gateways.js +1 -1
  72. package/lib/esm/resources/manual_tax_calculators.js +1 -1
  73. package/lib/esm/resources/markets.js +1 -1
  74. package/lib/esm/resources/merchants.js +1 -1
  75. package/lib/esm/resources/order_amount_promotion_rules.js +1 -1
  76. package/lib/esm/resources/order_copies.js +1 -1
  77. package/lib/esm/resources/order_factories.js +1 -1
  78. package/lib/esm/resources/order_subscription_items.js +1 -1
  79. package/lib/esm/resources/order_subscriptions.js +1 -1
  80. package/lib/esm/resources/order_validation_rules.js +1 -1
  81. package/lib/esm/resources/orders.js +1 -1
  82. package/lib/esm/resources/organization.js +1 -1
  83. package/lib/esm/resources/packages.js +1 -1
  84. package/lib/esm/resources/parcel_line_items.js +1 -1
  85. package/lib/esm/resources/parcels.js +1 -1
  86. package/lib/esm/resources/payment_gateways.js +1 -1
  87. package/lib/esm/resources/payment_methods.js +1 -1
  88. package/lib/esm/resources/payment_options.js +1 -1
  89. package/lib/esm/resources/paypal_gateways.js +1 -1
  90. package/lib/esm/resources/paypal_payments.js +1 -1
  91. package/lib/esm/resources/percentage_discount_promotions.js +1 -1
  92. package/lib/esm/resources/price_frequency_tiers.js +1 -1
  93. package/lib/esm/resources/price_lists.js +1 -1
  94. package/lib/esm/resources/price_tiers.js +1 -1
  95. package/lib/esm/resources/price_volume_tiers.js +1 -1
  96. package/lib/esm/resources/prices.js +1 -1
  97. package/lib/esm/resources/promotion_rules.js +1 -1
  98. package/lib/esm/resources/promotions.js +1 -1
  99. package/lib/esm/resources/recurring_order_copies.js +1 -1
  100. package/lib/esm/resources/refunds.js +1 -1
  101. package/lib/esm/resources/reserved_stocks.js +1 -1
  102. package/lib/esm/resources/resource_errors.js +1 -1
  103. package/lib/esm/resources/return_line_items.js +1 -1
  104. package/lib/esm/resources/returns.js +1 -1
  105. package/lib/esm/resources/satispay_gateways.js +1 -1
  106. package/lib/esm/resources/satispay_payments.js +1 -1
  107. package/lib/esm/resources/shipments.js +1 -1
  108. package/lib/esm/resources/shipping_categories.js +1 -1
  109. package/lib/esm/resources/shipping_method_tiers.js +1 -1
  110. package/lib/esm/resources/shipping_methods.js +1 -1
  111. package/lib/esm/resources/shipping_weight_tiers.js +1 -1
  112. package/lib/esm/resources/shipping_zones.js +1 -1
  113. package/lib/esm/resources/sku_list_items.js +1 -1
  114. package/lib/esm/resources/sku_list_promotion_rules.js +1 -1
  115. package/lib/esm/resources/sku_lists.js +1 -1
  116. package/lib/esm/resources/sku_options.js +1 -1
  117. package/lib/esm/resources/skus.js +1 -1
  118. package/lib/esm/resources/stock_items.js +1 -1
  119. package/lib/esm/resources/stock_line_items.js +1 -1
  120. package/lib/esm/resources/stock_locations.js +1 -1
  121. package/lib/esm/resources/stock_reservations.js +1 -1
  122. package/lib/esm/resources/stock_transfers.js +1 -1
  123. package/lib/esm/resources/stripe_gateways.js +1 -1
  124. package/lib/esm/resources/stripe_payments.js +1 -1
  125. package/lib/esm/resources/subscription_models.js +1 -1
  126. package/lib/esm/resources/tags.js +1 -1
  127. package/lib/esm/resources/tax_calculators.js +1 -1
  128. package/lib/esm/resources/tax_categories.js +1 -1
  129. package/lib/esm/resources/tax_rules.js +1 -1
  130. package/lib/esm/resources/taxjar_accounts.js +1 -1
  131. package/lib/esm/resources/transactions.js +1 -1
  132. package/lib/esm/resources/versions.js +1 -1
  133. package/lib/esm/resources/voids.js +1 -1
  134. package/lib/esm/resources/webhooks.js +1 -1
  135. package/lib/esm/resources/wire_transfers.js +1 -1
  136. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  137. package/lib/tsconfig.tsbuildinfo +1 -1
  138. package/package.json +6 -6
package/lib/cjs/client.js CHANGED
@@ -120,16 +120,16 @@ class ApiClient {
120
120
  async request(method, path, body, options) {
121
121
  debug('request %s %s, %O, %O', method, path, body || {}, options || {});
122
122
  // Ignored params alerts (in debug mode)
123
- if (options === null || options === void 0 ? void 0 : options.adapter)
123
+ if (options?.adapter)
124
124
  debug('Adapter ignored in request config');
125
- if (options === null || options === void 0 ? void 0 : options.userAgent)
125
+ if (options?.userAgent)
126
126
  debug('User-Agent header ignored in request config');
127
127
  const data = body ? { data: body } : undefined;
128
128
  const url = path;
129
129
  // Runtime request parameters
130
- const baseUrl = (options === null || options === void 0 ? void 0 : options.organization) ? baseURL(options.organization, options.domain) : undefined;
131
- const accessToken = (options === null || options === void 0 ? void 0 : options.accessToken) || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
132
- const headers = this.customHeaders(options === null || options === void 0 ? void 0 : options.headers);
130
+ const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : undefined;
131
+ const accessToken = options?.accessToken || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
132
+ const headers = this.customHeaders(options?.headers);
133
133
  if (accessToken)
134
134
  headers.Authorization = 'Bearer ' + accessToken;
135
135
  const requestParams = { method, baseURL: baseUrl, url, data, ...options, headers };
@@ -139,8 +139,8 @@ declare class CommerceLayerClient {
139
139
  singletons(): readonly string[];
140
140
  isSingleton(resource: api.ResourceTypeLock): boolean;
141
141
  isApiError(error: any): error is ApiError;
142
- addRequestInterceptor(onFulfilled?: RequestInterceptor | null, onRejected?: ErrorInterceptor | null): number;
143
- addResponseInterceptor(onFulfilled?: ResponseInterceptor | null, onRejected?: ErrorInterceptor | null): number;
142
+ addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
143
+ addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
144
144
  removeInterceptor(type: InterceptorType, id: number): void;
145
145
  addRawResponseReader(options?: {
146
146
  headers: boolean;
@@ -230,8 +230,8 @@ class CommerceLayerClient {
230
230
  headers: undefined,
231
231
  };
232
232
  function rawResponseInterceptor(response) {
233
- reader.rawResponse = response === null || response === void 0 ? void 0 : response.data;
234
- if (options === null || options === void 0 ? void 0 : options.headers)
233
+ reader.rawResponse = response?.data;
234
+ if (options?.headers)
235
235
  reader.headers = response.headers;
236
236
  return response;
237
237
  }
@@ -240,7 +240,7 @@ class CommerceLayerClient {
240
240
  return reader;
241
241
  }
242
242
  removeRawResponseReader(reader) {
243
- const id = (typeof reader === 'number') ? reader : reader === null || reader === void 0 ? void 0 : reader.id;
243
+ const id = (typeof reader === 'number') ? reader : reader?.id;
244
244
  if (id && (id >= 0))
245
245
  this.removeInterceptor('response', id);
246
246
  }
package/lib/cjs/common.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isResourceType = exports.isResourceId = void 0;
4
4
  const api_1 = require("./api");
5
5
  const isResourceId = (resource) => {
6
- return ((resource === null || resource === void 0 ? void 0 : resource.type) && resource.id) && api_1.resourceList.includes(resource.type);
6
+ return (resource?.type && resource.id) && api_1.resourceList.includes(resource.type);
7
7
  };
8
8
  exports.isResourceId = isResourceId;
9
9
  const isResourceType = (resource) => {
package/lib/cjs/error.js CHANGED
@@ -36,8 +36,7 @@ class ApiError extends SdkError {
36
36
  this.name = ApiError.NAME; // this.constructor.name
37
37
  }
38
38
  first() {
39
- var _a;
40
- return (((_a = this.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) ? this.errors[0] : undefined;
39
+ return (this.errors?.length > 0) ? this.errors[0] : undefined;
41
40
  }
42
41
  }
43
42
  exports.ApiError = ApiError;
@@ -6,14 +6,14 @@ type InterceptorManager = {
6
6
  type RequestObj = AxiosRequestConfig;
7
7
  type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
8
8
  type ResponseObj = AxiosResponse;
9
- type ResponseInterceptor = (response: ResponseObj) => ResponseObj | Promise<ResponseObj>;
9
+ type ResponseInterceptor = (response: ResponseObj) => ResponseObj;
10
10
  type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-count' | 'x-ratelimit-period' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
11
11
  type ApiHeaders = {
12
12
  [key in ApiHeadersList]: string | number | boolean;
13
13
  };
14
14
  type HeadersObj = (AxiosResponseHeaders | RawAxiosResponseHeaders) & ApiHeaders;
15
15
  type ErrorObj = AxiosError;
16
- type ErrorInterceptor = (error: ErrorObj) => ErrorObj | Promise<ErrorObj>;
16
+ type ErrorInterceptor = (error: ErrorObj) => ErrorObj;
17
17
  type InterceptorType = 'request' | 'response';
18
18
  export type { InterceptorManager, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, InterceptorType };
19
19
  export type { RequestObj, ResponseObj, ErrorObj, HeadersObj };
@@ -63,8 +63,8 @@ class ResourceAdapter {
63
63
  async singleton(resource, params, options) {
64
64
  debug('singleton: %o, %O, %O', resource, params || {}, options || {});
65
65
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
66
- if (options === null || options === void 0 ? void 0 : options.params)
67
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
66
+ if (options?.params)
67
+ Object.assign(queryParams, options?.params);
68
68
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
69
69
  const r = (0, jsonapi_1.denormalize)(res);
70
70
  return r;
@@ -72,33 +72,32 @@ class ResourceAdapter {
72
72
  async retrieve(resource, params, options) {
73
73
  debug('retrieve: %o, %O, %O', resource, params || {}, options || {});
74
74
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
75
- if (options === null || options === void 0 ? void 0 : options.params)
76
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
75
+ if (options?.params)
76
+ Object.assign(queryParams, options?.params);
77
77
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}/${resource.id}`, undefined, { ...options, params: queryParams });
78
78
  const r = (0, jsonapi_1.denormalize)(res);
79
79
  return r;
80
80
  }
81
81
  async list(resource, params, options) {
82
- var _a, _b;
83
82
  debug('list: %o, %O, %O', resource, params || {}, options || {});
84
83
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
85
- if (options === null || options === void 0 ? void 0 : options.params)
86
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
84
+ if (options?.params)
85
+ Object.assign(queryParams, options?.params);
87
86
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
88
87
  const r = (0, jsonapi_1.denormalize)(res);
89
88
  const meta = {
90
- pageCount: Number((_a = res.meta) === null || _a === void 0 ? void 0 : _a.page_count),
91
- recordCount: Number((_b = res.meta) === null || _b === void 0 ? void 0 : _b.record_count),
92
- currentPage: (params === null || params === void 0 ? void 0 : params.pageNumber) || config_1.default.default.pageNumber,
93
- recordsPerPage: (params === null || params === void 0 ? void 0 : params.pageSize) || config_1.default.default.pageSize
89
+ pageCount: Number(res.meta?.page_count),
90
+ recordCount: Number(res.meta?.record_count),
91
+ currentPage: params?.pageNumber || config_1.default.default.pageNumber,
92
+ recordsPerPage: params?.pageSize || config_1.default.default.pageSize
94
93
  };
95
94
  return new ListResponse(meta, r);
96
95
  }
97
96
  async create(resource, params, options) {
98
97
  debug('create: %o, %O, %O', resource, params || {}, options || {});
99
98
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
100
- if (options === null || options === void 0 ? void 0 : options.params)
101
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
99
+ if (options?.params)
100
+ Object.assign(queryParams, options?.params);
102
101
  const data = (0, jsonapi_1.normalize)(resource);
103
102
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('post', resource.type, data, { ...options, params: queryParams });
104
103
  const r = (0, jsonapi_1.denormalize)(res);
@@ -107,8 +106,8 @@ class ResourceAdapter {
107
106
  async update(resource, params, options) {
108
107
  debug('update: %o, %O, %O', resource, params || {}, options || {});
109
108
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
110
- if (options === null || options === void 0 ? void 0 : options.params)
111
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
109
+ if (options?.params)
110
+ Object.assign(queryParams, options?.params);
112
111
  const data = (0, jsonapi_1.normalize)(resource);
113
112
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('patch', `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
114
113
  const r = (0, jsonapi_1.denormalize)(res);
@@ -119,20 +118,19 @@ class ResourceAdapter {
119
118
  await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('delete', `${resource.type}/${resource.id}`, undefined, options);
120
119
  }
121
120
  async fetch(resource, path, params, options) {
122
- var _a, _b;
123
121
  debug('fetch: %o, %O, %O', path, params || {}, options || {});
124
122
  const queryParams = (0, query_1.generateQueryStringParams)(params, resource);
125
- if (options === null || options === void 0 ? void 0 : options.params)
126
- Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
123
+ if (options?.params)
124
+ Object.assign(queryParams, options?.params);
127
125
  const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', path, undefined, { ...options, params: queryParams });
128
126
  const r = (0, jsonapi_1.denormalize)(res);
129
127
  if (Array.isArray(r)) {
130
128
  const p = params;
131
129
  const meta = {
132
- pageCount: Number((_a = res.meta) === null || _a === void 0 ? void 0 : _a.page_count),
133
- recordCount: Number((_b = res.meta) === null || _b === void 0 ? void 0 : _b.record_count),
134
- currentPage: (p === null || p === void 0 ? void 0 : p.pageNumber) || config_1.default.default.pageNumber,
135
- recordsPerPage: (p === null || p === void 0 ? void 0 : p.pageSize) || config_1.default.default.pageSize
130
+ pageCount: Number(res.meta?.page_count),
131
+ recordCount: Number(res.meta?.record_count),
132
+ currentPage: p?.pageNumber || config_1.default.default.pageNumber,
133
+ recordsPerPage: p?.pageSize || config_1.default.default.pageSize
136
134
  };
137
135
  return new ListResponse(meta, r);
138
136
  }
@@ -147,11 +145,10 @@ class ApiResourceBase {
147
145
  this.resources = adapter;
148
146
  }
149
147
  parse(resource, options) {
150
- var _a;
151
148
  try {
152
149
  const res = JSON.parse(resource);
153
150
  // Resource type always checked
154
- const rtype = (_a = res.data) === null || _a === void 0 ? void 0 : _a.type;
151
+ const rtype = res.data?.type;
155
152
  if (rtype !== this.type())
156
153
  throw new error_1.SdkError({ message: `Invalid resource type [${rtype}]`, type: error_1.ErrorType.PARSE });
157
154
  // Parse options
package/lib/esm/client.js CHANGED
@@ -1,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _ApiClient_accessToken, _ApiClient_client;
13
1
  import axios from 'axios';
14
2
  import { SdkError, handleError } from './error';
15
3
  import config from './config';
@@ -28,12 +16,14 @@ class ApiClient {
28
16
  throw new SdkError({ message: `Undefined '${attr}' parameter` });
29
17
  return new ApiClient(options);
30
18
  }
19
+ baseUrl;
20
+ #accessToken;
21
+ #client;
22
+ interceptors;
31
23
  constructor(options) {
32
- _ApiClient_accessToken.set(this, void 0);
33
- _ApiClient_client.set(this, void 0);
34
24
  debug('new client instance %O', options);
35
25
  this.baseUrl = baseURL(options.organization, options.domain);
36
- __classPrivateFieldSet(this, _ApiClient_accessToken, options.accessToken, "f");
26
+ this.#accessToken = options.accessToken;
37
27
  const axiosConfig = {
38
28
  timeout: options.timeout || config.client.timeout,
39
29
  proxy: options.proxy,
@@ -47,7 +37,7 @@ class ApiClient {
47
37
  ...customHeaders,
48
38
  'Accept': 'application/vnd.api+json',
49
39
  'Content-Type': 'application/vnd.api+json',
50
- 'Authorization': 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f")
40
+ 'Authorization': 'Bearer ' + this.#accessToken
51
41
  };
52
42
  // Set User-Agent
53
43
  let userAgent = options.userAgent; // || `SDK-core axios/${axios.VERSION}`
@@ -65,12 +55,12 @@ class ApiClient {
65
55
  if (options.adapter)
66
56
  axiosOptions.adapter = options.adapter;
67
57
  debug('axios options: %O', axiosOptions);
68
- __classPrivateFieldSet(this, _ApiClient_client, axios.create(axiosOptions), "f");
69
- this.interceptors = __classPrivateFieldGet(this, _ApiClient_client, "f").interceptors;
58
+ this.#client = axios.create(axiosOptions);
59
+ this.interceptors = this.#client.interceptors;
70
60
  }
71
61
  config(config) {
72
62
  debug('config %o', config);
73
- const def = __classPrivateFieldGet(this, _ApiClient_client, "f").defaults;
63
+ const def = this.#client.defaults;
74
64
  // Axios config
75
65
  if (config.timeout)
76
66
  def.timeout = config.timeout;
@@ -88,8 +78,8 @@ class ApiClient {
88
78
  if (config.organization)
89
79
  this.baseUrl = baseURL(config.organization, config.domain);
90
80
  if (config.accessToken) {
91
- __classPrivateFieldSet(this, _ApiClient_accessToken, config.accessToken, "f");
92
- def.headers.common.Authorization = 'Bearer ' + __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
81
+ this.#accessToken = config.accessToken;
82
+ def.headers.common.Authorization = 'Bearer ' + this.#accessToken;
93
83
  }
94
84
  if (config.headers)
95
85
  def.headers.common = this.customHeaders(config.headers);
@@ -103,34 +93,34 @@ class ApiClient {
103
93
  if (axios.VERSION)
104
94
  ua += ` axios/${axios.VERSION}`;
105
95
  }
106
- __classPrivateFieldGet(this, _ApiClient_client, "f").defaults.headers['User-Agent'] = ua;
96
+ this.#client.defaults.headers['User-Agent'] = ua;
107
97
  }
108
98
  return this;
109
99
  }
110
100
  adapter(adapter) {
111
101
  if (adapter)
112
- __classPrivateFieldGet(this, _ApiClient_client, "f").defaults.adapter = adapter;
102
+ this.#client.defaults.adapter = adapter;
113
103
  return this;
114
104
  }
115
105
  async request(method, path, body, options) {
116
106
  debug('request %s %s, %O, %O', method, path, body || {}, options || {});
117
107
  // Ignored params alerts (in debug mode)
118
- if (options === null || options === void 0 ? void 0 : options.adapter)
108
+ if (options?.adapter)
119
109
  debug('Adapter ignored in request config');
120
- if (options === null || options === void 0 ? void 0 : options.userAgent)
110
+ if (options?.userAgent)
121
111
  debug('User-Agent header ignored in request config');
122
112
  const data = body ? { data: body } : undefined;
123
113
  const url = path;
124
114
  // Runtime request parameters
125
- const baseUrl = (options === null || options === void 0 ? void 0 : options.organization) ? baseURL(options.organization, options.domain) : undefined;
126
- const accessToken = (options === null || options === void 0 ? void 0 : options.accessToken) || __classPrivateFieldGet(this, _ApiClient_accessToken, "f");
127
- const headers = this.customHeaders(options === null || options === void 0 ? void 0 : options.headers);
115
+ const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : undefined;
116
+ const accessToken = options?.accessToken || this.#accessToken;
117
+ const headers = this.customHeaders(options?.headers);
128
118
  if (accessToken)
129
119
  headers.Authorization = 'Bearer ' + accessToken;
130
120
  const requestParams = { method, baseURL: baseUrl, url, data, ...options, headers };
131
121
  debug('request params: %O', requestParams);
132
122
  // const start = Date.now()
133
- return __classPrivateFieldGet(this, _ApiClient_client, "f").request(requestParams)
123
+ return this.#client.request(requestParams)
134
124
  .then(response => response.data)
135
125
  .catch((error) => handleError(error));
136
126
  // .finally(() => console.log(`<<-- ${method} ${path} ${Date.now() - start}`))
@@ -145,5 +135,4 @@ class ApiClient {
145
135
  return customHeaders;
146
136
  }
147
137
  }
148
- _ApiClient_accessToken = new WeakMap(), _ApiClient_client = new WeakMap();
149
138
  export default ApiClient;
@@ -139,8 +139,8 @@ declare class CommerceLayerClient {
139
139
  singletons(): readonly string[];
140
140
  isSingleton(resource: api.ResourceTypeLock): boolean;
141
141
  isApiError(error: any): error is ApiError;
142
- addRequestInterceptor(onFulfilled?: RequestInterceptor | null, onRejected?: ErrorInterceptor | null): number;
143
- addResponseInterceptor(onFulfilled?: ResponseInterceptor | null, onRejected?: ErrorInterceptor | null): number;
142
+ addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
143
+ addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
144
144
  removeInterceptor(type: InterceptorType, id: number): void;
145
145
  addRawResponseReader(options?: {
146
146
  headers: boolean;