@commercelayer/sdk 7.0.0-beta.17 → 7.0.0-beta.19

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 (297) hide show
  1. package/lib/api.cjs +0 -1
  2. package/lib/api.js +0 -1
  3. package/lib/client.cjs +45 -54
  4. package/lib/client.js +45 -54
  5. package/lib/commercelayer.cjs +11 -13
  6. package/lib/commercelayer.js +11 -13
  7. package/lib/common.cjs +0 -1
  8. package/lib/common.js +0 -1
  9. package/lib/config.cjs +0 -2
  10. package/lib/config.js +0 -2
  11. package/lib/debug.cjs +0 -2
  12. package/lib/debug.js +0 -2
  13. package/lib/enum.cjs +0 -2
  14. package/lib/enum.js +0 -2
  15. package/lib/error.cjs +19 -22
  16. package/lib/error.js +19 -22
  17. package/lib/fetch.cjs +17 -24
  18. package/lib/fetch.js +17 -24
  19. package/lib/index.cjs +0 -1
  20. package/lib/index.d.cts +1 -1
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +0 -1
  23. package/lib/jsonapi.cjs +0 -1
  24. package/lib/jsonapi.js +0 -1
  25. package/lib/query.cjs +0 -1
  26. package/lib/query.js +0 -1
  27. package/lib/resource.cjs +21 -26
  28. package/lib/resource.js +21 -26
  29. package/lib/resources/addresses.cjs +10 -12
  30. package/lib/resources/addresses.js +10 -12
  31. package/lib/resources/adjustments.cjs +8 -10
  32. package/lib/resources/adjustments.js +8 -10
  33. package/lib/resources/adyen_gateways.cjs +8 -10
  34. package/lib/resources/adyen_gateways.js +8 -10
  35. package/lib/resources/adyen_payments.cjs +10 -12
  36. package/lib/resources/adyen_payments.js +10 -12
  37. package/lib/resources/applications.cjs +5 -7
  38. package/lib/resources/applications.js +5 -7
  39. package/lib/resources/attachments.cjs +8 -10
  40. package/lib/resources/attachments.js +8 -10
  41. package/lib/resources/authorizations.cjs +11 -13
  42. package/lib/resources/authorizations.js +11 -13
  43. package/lib/resources/avalara_accounts.cjs +8 -10
  44. package/lib/resources/avalara_accounts.js +8 -10
  45. package/lib/resources/axerve_gateways.cjs +8 -10
  46. package/lib/resources/axerve_gateways.js +8 -10
  47. package/lib/resources/axerve_payments.cjs +9 -11
  48. package/lib/resources/axerve_payments.js +9 -11
  49. package/lib/resources/bing_geocoders.cjs +8 -10
  50. package/lib/resources/bing_geocoders.js +8 -10
  51. package/lib/resources/braintree_gateways.cjs +8 -10
  52. package/lib/resources/braintree_gateways.js +8 -10
  53. package/lib/resources/braintree_payments.cjs +8 -10
  54. package/lib/resources/braintree_payments.js +8 -10
  55. package/lib/resources/bundles.cjs +12 -14
  56. package/lib/resources/bundles.js +12 -14
  57. package/lib/resources/buy_x_pay_y_promotions.cjs +12 -14
  58. package/lib/resources/buy_x_pay_y_promotions.js +12 -14
  59. package/lib/resources/captures.cjs +10 -12
  60. package/lib/resources/captures.js +10 -12
  61. package/lib/resources/carrier_accounts.cjs +8 -10
  62. package/lib/resources/carrier_accounts.js +8 -10
  63. package/lib/resources/checkout_com_gateways.cjs +8 -10
  64. package/lib/resources/checkout_com_gateways.js +8 -10
  65. package/lib/resources/checkout_com_payments.cjs +10 -12
  66. package/lib/resources/checkout_com_payments.js +10 -12
  67. package/lib/resources/cleanups.cjs +9 -11
  68. package/lib/resources/cleanups.js +9 -11
  69. package/lib/resources/coupon_codes_promotion_rules.cjs +8 -10
  70. package/lib/resources/coupon_codes_promotion_rules.js +8 -10
  71. package/lib/resources/coupon_recipients.cjs +8 -10
  72. package/lib/resources/coupon_recipients.js +8 -10
  73. package/lib/resources/coupons.cjs +10 -12
  74. package/lib/resources/coupons.js +10 -12
  75. package/lib/resources/custom_promotion_rules.cjs +8 -10
  76. package/lib/resources/custom_promotion_rules.js +8 -10
  77. package/lib/resources/customer_addresses.cjs +8 -10
  78. package/lib/resources/customer_addresses.js +8 -10
  79. package/lib/resources/customer_groups.cjs +8 -10
  80. package/lib/resources/customer_groups.js +8 -10
  81. package/lib/resources/customer_password_resets.cjs +9 -11
  82. package/lib/resources/customer_password_resets.js +9 -11
  83. package/lib/resources/customer_payment_sources.cjs +8 -10
  84. package/lib/resources/customer_payment_sources.js +8 -10
  85. package/lib/resources/customer_subscriptions.cjs +8 -10
  86. package/lib/resources/customer_subscriptions.js +8 -10
  87. package/lib/resources/customers.cjs +10 -12
  88. package/lib/resources/customers.js +10 -12
  89. package/lib/resources/delivery_lead_times.cjs +8 -10
  90. package/lib/resources/delivery_lead_times.js +8 -10
  91. package/lib/resources/discount_engine_items.cjs +5 -7
  92. package/lib/resources/discount_engine_items.js +5 -7
  93. package/lib/resources/discount_engines.cjs +5 -7
  94. package/lib/resources/discount_engines.js +5 -7
  95. package/lib/resources/easypost_pickups.cjs +9 -11
  96. package/lib/resources/easypost_pickups.js +9 -11
  97. package/lib/resources/event_callbacks.cjs +5 -7
  98. package/lib/resources/event_callbacks.js +5 -7
  99. package/lib/resources/events.cjs +7 -9
  100. package/lib/resources/events.js +7 -9
  101. package/lib/resources/exports.cjs +9 -11
  102. package/lib/resources/exports.js +9 -11
  103. package/lib/resources/external_gateways.cjs +9 -11
  104. package/lib/resources/external_gateways.js +9 -11
  105. package/lib/resources/external_payments.cjs +8 -10
  106. package/lib/resources/external_payments.js +8 -10
  107. package/lib/resources/external_promotions.cjs +13 -15
  108. package/lib/resources/external_promotions.js +13 -15
  109. package/lib/resources/external_tax_calculators.cjs +9 -11
  110. package/lib/resources/external_tax_calculators.js +9 -11
  111. package/lib/resources/fixed_amount_promotions.cjs +12 -14
  112. package/lib/resources/fixed_amount_promotions.js +12 -14
  113. package/lib/resources/fixed_price_promotions.cjs +12 -14
  114. package/lib/resources/fixed_price_promotions.js +12 -14
  115. package/lib/resources/flex_promotions.cjs +12 -14
  116. package/lib/resources/flex_promotions.js +12 -14
  117. package/lib/resources/free_gift_promotions.cjs +12 -14
  118. package/lib/resources/free_gift_promotions.js +12 -14
  119. package/lib/resources/free_shipping_promotions.cjs +12 -14
  120. package/lib/resources/free_shipping_promotions.js +12 -14
  121. package/lib/resources/geocoders.cjs +5 -7
  122. package/lib/resources/geocoders.js +5 -7
  123. package/lib/resources/gift_card_recipients.cjs +8 -10
  124. package/lib/resources/gift_card_recipients.js +8 -10
  125. package/lib/resources/gift_cards.cjs +14 -16
  126. package/lib/resources/gift_cards.js +14 -16
  127. package/lib/resources/google_geocoders.cjs +8 -10
  128. package/lib/resources/google_geocoders.js +8 -10
  129. package/lib/resources/imports.cjs +9 -11
  130. package/lib/resources/imports.js +9 -11
  131. package/lib/resources/in_stock_subscriptions.cjs +10 -12
  132. package/lib/resources/in_stock_subscriptions.js +10 -12
  133. package/lib/resources/inventory_models.cjs +8 -10
  134. package/lib/resources/inventory_models.js +8 -10
  135. package/lib/resources/inventory_return_locations.cjs +8 -10
  136. package/lib/resources/inventory_return_locations.js +8 -10
  137. package/lib/resources/inventory_stock_locations.cjs +8 -10
  138. package/lib/resources/inventory_stock_locations.js +8 -10
  139. package/lib/resources/klarna_gateways.cjs +8 -10
  140. package/lib/resources/klarna_gateways.js +8 -10
  141. package/lib/resources/klarna_payments.cjs +9 -11
  142. package/lib/resources/klarna_payments.js +9 -11
  143. package/lib/resources/line_item_options.cjs +10 -12
  144. package/lib/resources/line_item_options.js +10 -12
  145. package/lib/resources/line_items.cjs +13 -15
  146. package/lib/resources/line_items.js +13 -15
  147. package/lib/resources/links.cjs +10 -12
  148. package/lib/resources/links.js +10 -12
  149. package/lib/resources/manual_gateways.cjs +8 -10
  150. package/lib/resources/manual_gateways.js +8 -10
  151. package/lib/resources/manual_tax_calculators.cjs +8 -10
  152. package/lib/resources/manual_tax_calculators.js +8 -10
  153. package/lib/resources/markets.cjs +10 -12
  154. package/lib/resources/markets.js +10 -12
  155. package/lib/resources/merchants.cjs +8 -10
  156. package/lib/resources/merchants.js +8 -10
  157. package/lib/resources/notifications.cjs +8 -10
  158. package/lib/resources/notifications.js +8 -10
  159. package/lib/resources/order_amount_promotion_rules.cjs +8 -10
  160. package/lib/resources/order_amount_promotion_rules.js +8 -10
  161. package/lib/resources/order_copies.cjs +8 -10
  162. package/lib/resources/order_copies.js +8 -10
  163. package/lib/resources/order_factories.cjs +5 -7
  164. package/lib/resources/order_factories.js +5 -7
  165. package/lib/resources/order_subscription_items.cjs +8 -10
  166. package/lib/resources/order_subscription_items.js +8 -10
  167. package/lib/resources/order_subscriptions.cjs +14 -16
  168. package/lib/resources/order_subscriptions.js +14 -16
  169. package/lib/resources/orders.cjs +41 -43
  170. package/lib/resources/orders.js +41 -43
  171. package/lib/resources/organizations.cjs +5 -7
  172. package/lib/resources/organizations.js +5 -7
  173. package/lib/resources/packages.cjs +8 -10
  174. package/lib/resources/packages.js +8 -10
  175. package/lib/resources/parcel_line_items.cjs +8 -10
  176. package/lib/resources/parcel_line_items.js +8 -10
  177. package/lib/resources/parcels.cjs +8 -10
  178. package/lib/resources/parcels.js +8 -10
  179. package/lib/resources/payment_gateways.cjs +5 -7
  180. package/lib/resources/payment_gateways.js +5 -7
  181. package/lib/resources/payment_methods.cjs +10 -12
  182. package/lib/resources/payment_methods.js +10 -12
  183. package/lib/resources/payment_options.cjs +8 -10
  184. package/lib/resources/payment_options.js +8 -10
  185. package/lib/resources/paypal_gateways.cjs +8 -10
  186. package/lib/resources/paypal_gateways.js +8 -10
  187. package/lib/resources/paypal_payments.cjs +8 -10
  188. package/lib/resources/paypal_payments.js +8 -10
  189. package/lib/resources/percentage_discount_promotions.cjs +12 -14
  190. package/lib/resources/percentage_discount_promotions.js +12 -14
  191. package/lib/resources/pickups.cjs +5 -7
  192. package/lib/resources/pickups.js +5 -7
  193. package/lib/resources/price_frequency_tiers.cjs +8 -10
  194. package/lib/resources/price_frequency_tiers.js +8 -10
  195. package/lib/resources/price_list_schedulers.cjs +10 -12
  196. package/lib/resources/price_list_schedulers.js +10 -12
  197. package/lib/resources/price_lists.cjs +8 -10
  198. package/lib/resources/price_lists.js +8 -10
  199. package/lib/resources/price_tiers.cjs +5 -7
  200. package/lib/resources/price_tiers.js +5 -7
  201. package/lib/resources/price_volume_tiers.cjs +8 -10
  202. package/lib/resources/price_volume_tiers.js +8 -10
  203. package/lib/resources/prices.cjs +8 -10
  204. package/lib/resources/prices.js +8 -10
  205. package/lib/resources/promotion_rules.cjs +5 -7
  206. package/lib/resources/promotion_rules.js +5 -7
  207. package/lib/resources/promotions.cjs +5 -7
  208. package/lib/resources/promotions.js +5 -7
  209. package/lib/resources/recurring_order_copies.cjs +8 -10
  210. package/lib/resources/recurring_order_copies.js +8 -10
  211. package/lib/resources/refunds.cjs +7 -9
  212. package/lib/resources/refunds.js +7 -9
  213. package/lib/resources/reserved_stocks.cjs +5 -7
  214. package/lib/resources/reserved_stocks.js +5 -7
  215. package/lib/resources/resource_errors.cjs +5 -7
  216. package/lib/resources/resource_errors.js +5 -7
  217. package/lib/resources/return_line_items.cjs +9 -11
  218. package/lib/resources/return_line_items.js +9 -11
  219. package/lib/resources/returns.cjs +21 -23
  220. package/lib/resources/returns.js +21 -23
  221. package/lib/resources/satispay_gateways.cjs +8 -10
  222. package/lib/resources/satispay_gateways.js +8 -10
  223. package/lib/resources/satispay_payments.cjs +9 -11
  224. package/lib/resources/satispay_payments.js +9 -11
  225. package/lib/resources/shipments.cjs +23 -25
  226. package/lib/resources/shipments.js +23 -25
  227. package/lib/resources/shipping_categories.cjs +8 -10
  228. package/lib/resources/shipping_categories.js +8 -10
  229. package/lib/resources/shipping_method_tiers.cjs +5 -7
  230. package/lib/resources/shipping_method_tiers.js +5 -7
  231. package/lib/resources/shipping_methods.cjs +11 -13
  232. package/lib/resources/shipping_methods.js +11 -13
  233. package/lib/resources/shipping_weight_tiers.cjs +8 -10
  234. package/lib/resources/shipping_weight_tiers.js +8 -10
  235. package/lib/resources/shipping_zones.cjs +8 -10
  236. package/lib/resources/shipping_zones.js +8 -10
  237. package/lib/resources/sku_list_items.cjs +8 -10
  238. package/lib/resources/sku_list_items.js +8 -10
  239. package/lib/resources/sku_list_promotion_rules.cjs +8 -10
  240. package/lib/resources/sku_list_promotion_rules.js +8 -10
  241. package/lib/resources/sku_lists.cjs +8 -10
  242. package/lib/resources/sku_lists.js +8 -10
  243. package/lib/resources/sku_options.cjs +10 -12
  244. package/lib/resources/sku_options.js +10 -12
  245. package/lib/resources/skus.cjs +10 -12
  246. package/lib/resources/skus.js +10 -12
  247. package/lib/resources/stock_items.cjs +9 -11
  248. package/lib/resources/stock_items.js +9 -11
  249. package/lib/resources/stock_line_items.cjs +11 -13
  250. package/lib/resources/stock_line_items.js +11 -13
  251. package/lib/resources/stock_locations.cjs +8 -10
  252. package/lib/resources/stock_locations.js +8 -10
  253. package/lib/resources/stock_reservations.cjs +9 -11
  254. package/lib/resources/stock_reservations.js +9 -11
  255. package/lib/resources/stock_transfers.cjs +14 -16
  256. package/lib/resources/stock_transfers.js +14 -16
  257. package/lib/resources/stores.cjs +8 -10
  258. package/lib/resources/stores.js +8 -10
  259. package/lib/resources/stripe_gateways.cjs +8 -10
  260. package/lib/resources/stripe_gateways.js +8 -10
  261. package/lib/resources/stripe_payments.cjs +10 -12
  262. package/lib/resources/stripe_payments.js +10 -12
  263. package/lib/resources/stripe_tax_accounts.cjs +8 -10
  264. package/lib/resources/stripe_tax_accounts.js +8 -10
  265. package/lib/resources/subscription_models.cjs +8 -10
  266. package/lib/resources/subscription_models.js +8 -10
  267. package/lib/resources/tags.cjs +8 -10
  268. package/lib/resources/tags.js +8 -10
  269. package/lib/resources/talon_one_accounts.cjs +8 -10
  270. package/lib/resources/talon_one_accounts.js +8 -10
  271. package/lib/resources/tax_calculators.cjs +5 -7
  272. package/lib/resources/tax_calculators.js +5 -7
  273. package/lib/resources/tax_categories.cjs +8 -10
  274. package/lib/resources/tax_categories.js +8 -10
  275. package/lib/resources/tax_rules.cjs +8 -10
  276. package/lib/resources/tax_rules.js +8 -10
  277. package/lib/resources/taxjar_accounts.cjs +8 -10
  278. package/lib/resources/taxjar_accounts.js +8 -10
  279. package/lib/resources/transactions.cjs +5 -7
  280. package/lib/resources/transactions.js +5 -7
  281. package/lib/resources/versions.cjs +5 -7
  282. package/lib/resources/versions.js +5 -7
  283. package/lib/resources/vertex_accounts.cjs +9 -11
  284. package/lib/resources/vertex_accounts.js +9 -11
  285. package/lib/resources/voids.cjs +7 -9
  286. package/lib/resources/voids.js +7 -9
  287. package/lib/resources/webhooks.cjs +11 -13
  288. package/lib/resources/webhooks.js +11 -13
  289. package/lib/resources/wire_transfers.cjs +8 -10
  290. package/lib/resources/wire_transfers.js +8 -10
  291. package/lib/static.cjs +0 -1
  292. package/lib/static.js +0 -1
  293. package/lib/util.cjs +0 -2
  294. package/lib/util.js +0 -2
  295. package/package.json +4 -4
  296. package/lib/chunk-AQ5VUG5P.js +0 -12
  297. package/lib/chunk-JE77HYXB.cjs +0 -17
package/lib/api.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('./chunk-JE77HYXB.cjs');
4
3
  var addresses = require('./resources/addresses');
5
4
  var adjustments = require('./resources/adjustments');
6
5
  var adyen_gateways = require('./resources/adyen_gateways');
package/lib/api.js CHANGED
@@ -1,4 +1,3 @@
1
- import './chunk-AQ5VUG5P.js';
2
1
  export { default as addresses } from './resources/addresses';
3
2
  export { default as adjustments } from './resources/adjustments';
4
3
  export { default as adyen_gateways } from './resources/adyen_gateways';
package/lib/client.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var chunkJE77HYXB_cjs = require('./chunk-JE77HYXB.cjs');
4
3
  var error = require('./error');
5
4
  var config = require('./config');
6
5
  var fetch = require('./fetch');
@@ -12,24 +11,33 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
  var config__default = /*#__PURE__*/_interopDefault(config);
13
12
  var Debug__default = /*#__PURE__*/_interopDefault(Debug);
14
13
 
15
- var _baseUrl, _accessToken, _organization, _domain, _clientConfig, _interceptors;
16
14
  const debug = Debug__default.default("client");
17
15
  const baseURL = (organization, domain) => {
18
16
  return `https://${organization.toLowerCase()}.${domain || config__default.default.default.domain}/api`;
19
17
  };
20
- const _ApiClient = class _ApiClient {
18
+ class ApiClient {
19
+ static create(options) {
20
+ if ((!options.organization || !options.domain) && options.accessToken) {
21
+ const tokenData = util.extractTokenData(options.accessToken);
22
+ if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
23
+ if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
24
+ }
25
+ for (const attr of config__default.default.client.requiredAttributes)
26
+ if (!options[attr]) throw new error.SdkError({ message: `Undefined '${attr}' parameter` });
27
+ return new ApiClient(options);
28
+ }
29
+ #baseUrl;
30
+ #accessToken;
31
+ #organization;
32
+ #domain;
33
+ #clientConfig;
34
+ #interceptors;
21
35
  constructor(options) {
22
- chunkJE77HYXB_cjs.__privateAdd(this, _baseUrl);
23
- chunkJE77HYXB_cjs.__privateAdd(this, _accessToken);
24
- chunkJE77HYXB_cjs.__privateAdd(this, _organization);
25
- chunkJE77HYXB_cjs.__privateAdd(this, _domain);
26
- chunkJE77HYXB_cjs.__privateAdd(this, _clientConfig);
27
- chunkJE77HYXB_cjs.__privateAdd(this, _interceptors);
28
36
  debug("new client instance %O", options);
29
- chunkJE77HYXB_cjs.__privateSet(this, _baseUrl, baseURL(options.organization ?? "", options.domain));
30
- chunkJE77HYXB_cjs.__privateSet(this, _accessToken, options.accessToken);
31
- chunkJE77HYXB_cjs.__privateSet(this, _organization, options.organization ?? "");
32
- chunkJE77HYXB_cjs.__privateSet(this, _domain, options.domain);
37
+ this.#baseUrl = baseURL(options.organization ?? "", options.domain);
38
+ this.#accessToken = options.accessToken;
39
+ this.#organization = options.organization ?? "";
40
+ this.#domain = options.domain;
33
41
  const fetchConfig = {
34
42
  timeout: options.timeout || config__default.default.client.timeout,
35
43
  fetch: options.fetch,
@@ -40,30 +48,20 @@ const _ApiClient = class _ApiClient {
40
48
  ...customHeaders,
41
49
  "Accept": "application/vnd.api+json",
42
50
  "Content-Type": "application/vnd.api+json",
43
- "Authorization": "Bearer " + chunkJE77HYXB_cjs.__privateGet(this, _accessToken)
51
+ "Authorization": "Bearer " + this.#accessToken
44
52
  };
45
53
  if (options.userAgent) headers["User-Agent"] = options.userAgent;
46
54
  fetchConfig.headers = headers;
47
- chunkJE77HYXB_cjs.__privateSet(this, _clientConfig, fetchConfig);
55
+ this.#clientConfig = fetchConfig;
48
56
  debug("fetch config: %O", fetchConfig);
49
- chunkJE77HYXB_cjs.__privateSet(this, _interceptors, {});
50
- }
51
- static create(options) {
52
- if ((!options.organization || !options.domain) && options.accessToken) {
53
- const tokenData = util.extractTokenData(options.accessToken);
54
- if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
55
- if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
56
- }
57
- for (const attr of config__default.default.client.requiredAttributes)
58
- if (!options[attr]) throw new error.SdkError({ message: `Undefined '${attr}' parameter` });
59
- return new _ApiClient(options);
57
+ this.#interceptors = {};
60
58
  }
61
59
  get interceptors() {
62
- return chunkJE77HYXB_cjs.__privateGet(this, _interceptors);
60
+ return this.#interceptors;
63
61
  }
64
62
  get requestHeaders() {
65
- if (!chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).headers) chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).headers = {};
66
- return chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).headers;
63
+ if (!this.#clientConfig.headers) this.#clientConfig.headers = {};
64
+ return this.#clientConfig.headers;
67
65
  }
68
66
  /*
69
67
  set requestHeaders(headers: RequestHeaders) {
@@ -72,18 +70,18 @@ const _ApiClient = class _ApiClient {
72
70
  */
73
71
  config(config2) {
74
72
  debug("config %o", config2);
75
- const def = chunkJE77HYXB_cjs.__privateGet(this, _clientConfig);
73
+ const def = this.#clientConfig;
76
74
  if (!def.headers) def.headers = {};
77
75
  if (config2.timeout) def.timeout = config2.timeout;
78
76
  if (config2.userAgent) this.userAgent(config2.userAgent);
79
- if (config2.fetch) chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).fetch = config2.fetch;
80
- if (config2.refreshToken) chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).refreshToken = config2.refreshToken;
81
- if (config2.organization || config2.domain) chunkJE77HYXB_cjs.__privateSet(this, _baseUrl, baseURL(config2.organization || chunkJE77HYXB_cjs.__privateGet(this, _organization), config2.domain || chunkJE77HYXB_cjs.__privateGet(this, _domain)));
82
- if (config2.organization) chunkJE77HYXB_cjs.__privateSet(this, _organization, config2.organization);
83
- if (config2.domain) chunkJE77HYXB_cjs.__privateSet(this, _domain, config2.domain);
77
+ if (config2.fetch) this.#clientConfig.fetch = config2.fetch;
78
+ if (config2.refreshToken) this.#clientConfig.refreshToken = config2.refreshToken;
79
+ if (config2.organization || config2.domain) this.#baseUrl = baseURL(config2.organization || this.#organization, config2.domain || this.#domain);
80
+ if (config2.organization) this.#organization = config2.organization;
81
+ if (config2.domain) this.#domain = config2.domain;
84
82
  if (config2.accessToken) {
85
- chunkJE77HYXB_cjs.__privateSet(this, _accessToken, config2.accessToken);
86
- def.headers.Authorization = "Bearer " + chunkJE77HYXB_cjs.__privateGet(this, _accessToken);
83
+ this.#accessToken = config2.accessToken;
84
+ def.headers.Authorization = "Bearer " + this.#accessToken;
87
85
  }
88
86
  if (config2.headers) def.headers = { ...def.headers, ...this.customHeaders(config2.headers) };
89
87
  return this;
@@ -95,16 +93,16 @@ const _ApiClient = class _ApiClient {
95
93
  async request(method, path, body, options) {
96
94
  debug("request %s %s, %O, %O", method, path, body || {}, options || {});
97
95
  if (options?.userAgent) debug("User-Agent header ignored in request config");
98
- const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : chunkJE77HYXB_cjs.__privateGet(this, _baseUrl);
96
+ const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : this.#baseUrl;
99
97
  const url = new URL(`${baseUrl}/${path}`);
100
98
  const bodyData = body ? JSON.stringify({ data: body }) : void 0;
101
99
  const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
102
- const accessToken = options?.accessToken || chunkJE77HYXB_cjs.__privateGet(this, _accessToken);
100
+ const accessToken = options?.accessToken || this.#accessToken;
103
101
  if (accessToken) headers.Authorization = "Bearer " + accessToken;
104
- const refreshToken = options?.refreshToken || chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).refreshToken;
105
- const fetchFunction = options?.fetch || chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).fetch;
102
+ const refreshToken = options?.refreshToken || this.#clientConfig.refreshToken;
103
+ const fetchFunction = options?.fetch || this.#clientConfig.fetch;
106
104
  const requestOptions = { method, body: bodyData, headers };
107
- const timeout = options?.timeout || chunkJE77HYXB_cjs.__privateGet(this, _clientConfig).timeout;
105
+ const timeout = options?.timeout || this.#clientConfig.timeout;
108
106
  if (timeout) {
109
107
  if (AbortSignal?.timeout) requestOptions.signal = AbortSignal.timeout(timeout);
110
108
  else debug("Timeout not set. Undefined function: %s", "AbortSignal.timeout");
@@ -121,7 +119,7 @@ const _ApiClient = class _ApiClient {
121
119
  } catch (err) {
122
120
  if (error.isExpiredTokenError(err) && refreshToken && util.isTokenExpired(accessToken)) {
123
121
  debug("Access token has expired");
124
- const newAccessToken = await refreshToken(chunkJE77HYXB_cjs.__privateGet(this, _accessToken)).catch((e) => {
122
+ const newAccessToken = await refreshToken(this.#accessToken).catch((e) => {
125
123
  debug("Refresh token error: %s", e.message);
126
124
  const tokenError = new error.SdkError({ message: "Error refreshing access token", type: error.ErrorType.TOKEN_REFRESH });
127
125
  tokenError.source = e;
@@ -130,7 +128,7 @@ const _ApiClient = class _ApiClient {
130
128
  if (newAccessToken) {
131
129
  debug("Access token refreshed");
132
130
  this.config({ accessToken: newAccessToken });
133
- chunkJE77HYXB_cjs.__privateSet(this, _accessToken, newAccessToken);
131
+ this.#accessToken = newAccessToken;
134
132
  if (requestOptions.headers) requestOptions.headers.Authorization = `Bearer ${newAccessToken}`;
135
133
  const response = await fetch.fetchURL(url, requestOptions, clientOptions).catch((error$1) => error.handleError(error$1));
136
134
  return response;
@@ -147,19 +145,12 @@ const _ApiClient = class _ApiClient {
147
145
  return customHeaders;
148
146
  }
149
147
  get currentAccessToken() {
150
- return chunkJE77HYXB_cjs.__privateGet(this, _accessToken);
148
+ return this.#accessToken;
151
149
  }
152
150
  get currentOrganization() {
153
- return chunkJE77HYXB_cjs.__privateGet(this, _organization);
151
+ return this.#organization;
154
152
  }
155
- };
156
- _baseUrl = new WeakMap();
157
- _accessToken = new WeakMap();
158
- _organization = new WeakMap();
159
- _domain = new WeakMap();
160
- _clientConfig = new WeakMap();
161
- _interceptors = new WeakMap();
162
- let ApiClient = _ApiClient;
153
+ }
163
154
  var client_default = ApiClient;
164
155
 
165
156
  module.exports = client_default;
package/lib/client.js CHANGED
@@ -1,28 +1,36 @@
1
- import { __privateAdd, __privateSet, __privateGet } from './chunk-AQ5VUG5P.js';
2
1
  import { SdkError, handleError, isExpiredTokenError, ErrorType } from './error';
3
2
  import config from './config';
4
3
  import { fetchURL } from './fetch';
5
4
  import { extractTokenData, isTokenExpired } from './util';
6
5
  import Debug from './debug';
7
6
 
8
- var _baseUrl, _accessToken, _organization, _domain, _clientConfig, _interceptors;
9
7
  const debug = Debug("client");
10
8
  const baseURL = (organization, domain) => {
11
9
  return `https://${organization.toLowerCase()}.${domain || config.default.domain}/api`;
12
10
  };
13
- const _ApiClient = class _ApiClient {
11
+ class ApiClient {
12
+ static create(options) {
13
+ if ((!options.organization || !options.domain) && options.accessToken) {
14
+ const tokenData = extractTokenData(options.accessToken);
15
+ if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
16
+ if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
17
+ }
18
+ for (const attr of config.client.requiredAttributes)
19
+ if (!options[attr]) throw new SdkError({ message: `Undefined '${attr}' parameter` });
20
+ return new ApiClient(options);
21
+ }
22
+ #baseUrl;
23
+ #accessToken;
24
+ #organization;
25
+ #domain;
26
+ #clientConfig;
27
+ #interceptors;
14
28
  constructor(options) {
15
- __privateAdd(this, _baseUrl);
16
- __privateAdd(this, _accessToken);
17
- __privateAdd(this, _organization);
18
- __privateAdd(this, _domain);
19
- __privateAdd(this, _clientConfig);
20
- __privateAdd(this, _interceptors);
21
29
  debug("new client instance %O", options);
22
- __privateSet(this, _baseUrl, baseURL(options.organization ?? "", options.domain));
23
- __privateSet(this, _accessToken, options.accessToken);
24
- __privateSet(this, _organization, options.organization ?? "");
25
- __privateSet(this, _domain, options.domain);
30
+ this.#baseUrl = baseURL(options.organization ?? "", options.domain);
31
+ this.#accessToken = options.accessToken;
32
+ this.#organization = options.organization ?? "";
33
+ this.#domain = options.domain;
26
34
  const fetchConfig = {
27
35
  timeout: options.timeout || config.client.timeout,
28
36
  fetch: options.fetch,
@@ -33,30 +41,20 @@ const _ApiClient = class _ApiClient {
33
41
  ...customHeaders,
34
42
  "Accept": "application/vnd.api+json",
35
43
  "Content-Type": "application/vnd.api+json",
36
- "Authorization": "Bearer " + __privateGet(this, _accessToken)
44
+ "Authorization": "Bearer " + this.#accessToken
37
45
  };
38
46
  if (options.userAgent) headers["User-Agent"] = options.userAgent;
39
47
  fetchConfig.headers = headers;
40
- __privateSet(this, _clientConfig, fetchConfig);
48
+ this.#clientConfig = fetchConfig;
41
49
  debug("fetch config: %O", fetchConfig);
42
- __privateSet(this, _interceptors, {});
43
- }
44
- static create(options) {
45
- if ((!options.organization || !options.domain) && options.accessToken) {
46
- const tokenData = extractTokenData(options.accessToken);
47
- if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
48
- if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
49
- }
50
- for (const attr of config.client.requiredAttributes)
51
- if (!options[attr]) throw new SdkError({ message: `Undefined '${attr}' parameter` });
52
- return new _ApiClient(options);
50
+ this.#interceptors = {};
53
51
  }
54
52
  get interceptors() {
55
- return __privateGet(this, _interceptors);
53
+ return this.#interceptors;
56
54
  }
57
55
  get requestHeaders() {
58
- if (!__privateGet(this, _clientConfig).headers) __privateGet(this, _clientConfig).headers = {};
59
- return __privateGet(this, _clientConfig).headers;
56
+ if (!this.#clientConfig.headers) this.#clientConfig.headers = {};
57
+ return this.#clientConfig.headers;
60
58
  }
61
59
  /*
62
60
  set requestHeaders(headers: RequestHeaders) {
@@ -65,18 +63,18 @@ const _ApiClient = class _ApiClient {
65
63
  */
66
64
  config(config2) {
67
65
  debug("config %o", config2);
68
- const def = __privateGet(this, _clientConfig);
66
+ const def = this.#clientConfig;
69
67
  if (!def.headers) def.headers = {};
70
68
  if (config2.timeout) def.timeout = config2.timeout;
71
69
  if (config2.userAgent) this.userAgent(config2.userAgent);
72
- if (config2.fetch) __privateGet(this, _clientConfig).fetch = config2.fetch;
73
- if (config2.refreshToken) __privateGet(this, _clientConfig).refreshToken = config2.refreshToken;
74
- if (config2.organization || config2.domain) __privateSet(this, _baseUrl, baseURL(config2.organization || __privateGet(this, _organization), config2.domain || __privateGet(this, _domain)));
75
- if (config2.organization) __privateSet(this, _organization, config2.organization);
76
- if (config2.domain) __privateSet(this, _domain, config2.domain);
70
+ if (config2.fetch) this.#clientConfig.fetch = config2.fetch;
71
+ if (config2.refreshToken) this.#clientConfig.refreshToken = config2.refreshToken;
72
+ if (config2.organization || config2.domain) this.#baseUrl = baseURL(config2.organization || this.#organization, config2.domain || this.#domain);
73
+ if (config2.organization) this.#organization = config2.organization;
74
+ if (config2.domain) this.#domain = config2.domain;
77
75
  if (config2.accessToken) {
78
- __privateSet(this, _accessToken, config2.accessToken);
79
- def.headers.Authorization = "Bearer " + __privateGet(this, _accessToken);
76
+ this.#accessToken = config2.accessToken;
77
+ def.headers.Authorization = "Bearer " + this.#accessToken;
80
78
  }
81
79
  if (config2.headers) def.headers = { ...def.headers, ...this.customHeaders(config2.headers) };
82
80
  return this;
@@ -88,16 +86,16 @@ const _ApiClient = class _ApiClient {
88
86
  async request(method, path, body, options) {
89
87
  debug("request %s %s, %O, %O", method, path, body || {}, options || {});
90
88
  if (options?.userAgent) debug("User-Agent header ignored in request config");
91
- const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : __privateGet(this, _baseUrl);
89
+ const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : this.#baseUrl;
92
90
  const url = new URL(`${baseUrl}/${path}`);
93
91
  const bodyData = body ? JSON.stringify({ data: body }) : void 0;
94
92
  const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
95
- const accessToken = options?.accessToken || __privateGet(this, _accessToken);
93
+ const accessToken = options?.accessToken || this.#accessToken;
96
94
  if (accessToken) headers.Authorization = "Bearer " + accessToken;
97
- const refreshToken = options?.refreshToken || __privateGet(this, _clientConfig).refreshToken;
98
- const fetchFunction = options?.fetch || __privateGet(this, _clientConfig).fetch;
95
+ const refreshToken = options?.refreshToken || this.#clientConfig.refreshToken;
96
+ const fetchFunction = options?.fetch || this.#clientConfig.fetch;
99
97
  const requestOptions = { method, body: bodyData, headers };
100
- const timeout = options?.timeout || __privateGet(this, _clientConfig).timeout;
98
+ const timeout = options?.timeout || this.#clientConfig.timeout;
101
99
  if (timeout) {
102
100
  if (AbortSignal?.timeout) requestOptions.signal = AbortSignal.timeout(timeout);
103
101
  else debug("Timeout not set. Undefined function: %s", "AbortSignal.timeout");
@@ -114,7 +112,7 @@ const _ApiClient = class _ApiClient {
114
112
  } catch (err) {
115
113
  if (isExpiredTokenError(err) && refreshToken && isTokenExpired(accessToken)) {
116
114
  debug("Access token has expired");
117
- const newAccessToken = await refreshToken(__privateGet(this, _accessToken)).catch((e) => {
115
+ const newAccessToken = await refreshToken(this.#accessToken).catch((e) => {
118
116
  debug("Refresh token error: %s", e.message);
119
117
  const tokenError = new SdkError({ message: "Error refreshing access token", type: ErrorType.TOKEN_REFRESH });
120
118
  tokenError.source = e;
@@ -123,7 +121,7 @@ const _ApiClient = class _ApiClient {
123
121
  if (newAccessToken) {
124
122
  debug("Access token refreshed");
125
123
  this.config({ accessToken: newAccessToken });
126
- __privateSet(this, _accessToken, newAccessToken);
124
+ this.#accessToken = newAccessToken;
127
125
  if (requestOptions.headers) requestOptions.headers.Authorization = `Bearer ${newAccessToken}`;
128
126
  const response = await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
129
127
  return response;
@@ -140,19 +138,12 @@ const _ApiClient = class _ApiClient {
140
138
  return customHeaders;
141
139
  }
142
140
  get currentAccessToken() {
143
- return __privateGet(this, _accessToken);
141
+ return this.#accessToken;
144
142
  }
145
143
  get currentOrganization() {
146
- return __privateGet(this, _organization);
144
+ return this.#organization;
147
145
  }
148
- };
149
- _baseUrl = new WeakMap();
150
- _accessToken = new WeakMap();
151
- _organization = new WeakMap();
152
- _domain = new WeakMap();
153
- _clientConfig = new WeakMap();
154
- _interceptors = new WeakMap();
155
- let ApiClient = _ApiClient;
146
+ }
156
147
  var client_default = ApiClient;
157
148
 
158
149
  export { client_default as default };
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var chunkJE77HYXB_cjs = require('./chunk-JE77HYXB.cjs');
6
5
  var _enum = require('./enum');
7
6
  var error = require('./error');
8
7
  var resource = require('./resource');
@@ -14,22 +13,23 @@ var Debug__default = /*#__PURE__*/_interopDefault(Debug);
14
13
 
15
14
  const debug = Debug__default.default("commercelayer");
16
15
  const OPEN_API_SCHEMA_VERSION = "7.8.3";
17
- const _CommerceLayerClient = class _CommerceLayerClient {
18
- constructor(config) {
19
- chunkJE77HYXB_cjs.__publicField(this, "openApiSchemaVersion", OPEN_API_SCHEMA_VERSION);
20
- debug("new commercelayer instance %O", config);
21
- resource.ApiResourceAdapter.init(config);
22
- }
16
+ class CommerceLayerClient {
23
17
  static get openApiSchemaVersion() {
24
18
  return OPEN_API_SCHEMA_VERSION;
25
19
  }
20
+ openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
21
+ static cl;
26
22
  // ##__CL_RESOURCES_DEF_START__##
27
23
  // ##__CL_RESOURCES_DEF_TEMPLATE:: ##__TAB__#####__RESOURCE_TYPE__##?: api.##__RESOURCE_CLASS__##
28
24
  // ##__CL_RESOURCES_DEF_STOP__##
29
25
  static get(config) {
30
- if (config) return _CommerceLayerClient.cl = new _CommerceLayerClient(config);
31
- else if (!_CommerceLayerClient.cl) throw new Error("CommerceLayer client not initialized");
32
- return _CommerceLayerClient.cl;
26
+ if (config) return CommerceLayerClient.cl = new CommerceLayerClient(config);
27
+ else if (!CommerceLayerClient.cl) throw new Error("CommerceLayer client not initialized");
28
+ return CommerceLayerClient.cl;
29
+ }
30
+ constructor(config) {
31
+ debug("new commercelayer instance %O", config);
32
+ resource.ApiResourceAdapter.init(config);
33
33
  }
34
34
  // ##__CL_RESOURCES_LEAZY_LOADING_START__##
35
35
  // ##__CL_RESOURCES_LEAZY_LOADING_TEMPLATE:: ##__TAB__##get ##__RESOURCE_TYPE__##(): api.##__RESOURCE_CLASS__## { return this.###__RESOURCE_TYPE__## || (this.###__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)) }
@@ -101,9 +101,7 @@ const _CommerceLayerClient = class _CommerceLayerClient {
101
101
  removeRawResponseReader() {
102
102
  this.interceptors.rawReader = void 0;
103
103
  }
104
- };
105
- chunkJE77HYXB_cjs.__publicField(_CommerceLayerClient, "cl");
106
- let CommerceLayerClient = _CommerceLayerClient;
104
+ }
107
105
  const CommerceLayer = (config) => {
108
106
  return CommerceLayerClient.get(config);
109
107
  };
@@ -1,4 +1,3 @@
1
- import { __publicField } from './chunk-AQ5VUG5P.js';
2
1
  import { getResources } from './enum';
3
2
  import { isApiError } from './error';
4
3
  import { ApiResourceAdapter } from './resource';
@@ -6,22 +5,23 @@ import Debug from './debug';
6
5
 
7
6
  const debug = Debug("commercelayer");
8
7
  const OPEN_API_SCHEMA_VERSION = "7.8.3";
9
- const _CommerceLayerClient = class _CommerceLayerClient {
10
- constructor(config) {
11
- __publicField(this, "openApiSchemaVersion", OPEN_API_SCHEMA_VERSION);
12
- debug("new commercelayer instance %O", config);
13
- ApiResourceAdapter.init(config);
14
- }
8
+ class CommerceLayerClient {
15
9
  static get openApiSchemaVersion() {
16
10
  return OPEN_API_SCHEMA_VERSION;
17
11
  }
12
+ openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
13
+ static cl;
18
14
  // ##__CL_RESOURCES_DEF_START__##
19
15
  // ##__CL_RESOURCES_DEF_TEMPLATE:: ##__TAB__#####__RESOURCE_TYPE__##?: api.##__RESOURCE_CLASS__##
20
16
  // ##__CL_RESOURCES_DEF_STOP__##
21
17
  static get(config) {
22
- if (config) return _CommerceLayerClient.cl = new _CommerceLayerClient(config);
23
- else if (!_CommerceLayerClient.cl) throw new Error("CommerceLayer client not initialized");
24
- return _CommerceLayerClient.cl;
18
+ if (config) return CommerceLayerClient.cl = new CommerceLayerClient(config);
19
+ else if (!CommerceLayerClient.cl) throw new Error("CommerceLayer client not initialized");
20
+ return CommerceLayerClient.cl;
21
+ }
22
+ constructor(config) {
23
+ debug("new commercelayer instance %O", config);
24
+ ApiResourceAdapter.init(config);
25
25
  }
26
26
  // ##__CL_RESOURCES_LEAZY_LOADING_START__##
27
27
  // ##__CL_RESOURCES_LEAZY_LOADING_TEMPLATE:: ##__TAB__##get ##__RESOURCE_TYPE__##(): api.##__RESOURCE_CLASS__## { return this.###__RESOURCE_TYPE__## || (this.###__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)) }
@@ -93,9 +93,7 @@ const _CommerceLayerClient = class _CommerceLayerClient {
93
93
  removeRawResponseReader() {
94
94
  this.interceptors.rawReader = void 0;
95
95
  }
96
- };
97
- __publicField(_CommerceLayerClient, "cl");
98
- let CommerceLayerClient = _CommerceLayerClient;
96
+ }
99
97
  const CommerceLayer = (config) => {
100
98
  return CommerceLayerClient.get(config);
101
99
  };
package/lib/common.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('./chunk-JE77HYXB.cjs');
4
3
  var _enum = require('./enum');
5
4
 
6
5
  const isResourceId = (resource) => {
package/lib/common.js CHANGED
@@ -1,4 +1,3 @@
1
- import './chunk-AQ5VUG5P.js';
2
1
  import { resourceList } from './enum';
3
2
 
4
3
  const isResourceId = (resource) => {
package/lib/config.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('./chunk-JE77HYXB.cjs');
4
-
5
3
  const config = {
6
4
  default: {
7
5
  domain: "commercelayer.io",
package/lib/config.js CHANGED
@@ -1,5 +1,3 @@
1
- import './chunk-AQ5VUG5P.js';
2
-
3
1
  const config = {
4
2
  default: {
5
3
  domain: "commercelayer.io",
package/lib/debug.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('./chunk-JE77HYXB.cjs');
4
-
5
3
  const debuggerFunction = (_pattern, ..._args) => {
6
4
  };
7
5
  let debuggerFactory = (_namespace) => debuggerFunction;
package/lib/debug.js CHANGED
@@ -1,5 +1,3 @@
1
- import './chunk-AQ5VUG5P.js';
2
-
3
1
  const debuggerFunction = (_pattern, ..._args) => {
4
2
  };
5
3
  let debuggerFactory = (_namespace) => debuggerFunction;
package/lib/enum.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- require('./chunk-JE77HYXB.cjs');
4
-
5
3
  const apiResources = [
6
4
  // ##__API_RESOURCE_LIST_START__##
7
5
  "addresses",
package/lib/enum.js CHANGED
@@ -1,5 +1,3 @@
1
- import './chunk-AQ5VUG5P.js';
2
-
3
1
  const apiResources = [
4
2
  // ##__API_RESOURCE_LIST_START__##
5
3
  "addresses",
package/lib/error.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var chunkJE77HYXB_cjs = require('./chunk-JE77HYXB.cjs');
4
3
  var fetch = require('./fetch');
5
4
 
6
5
  var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
@@ -13,39 +12,37 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
13
12
  ErrorType2["TOKEN_REFRESH"] = "token-refresh";
14
13
  return ErrorType2;
15
14
  })(ErrorType || {});
16
- const _SdkError = class _SdkError extends Error {
15
+ class SdkError extends Error {
16
+ static NAME = "SdkError";
17
+ static isSdkError(error) {
18
+ return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
19
+ }
20
+ type;
21
+ code;
22
+ source;
17
23
  constructor(error) {
18
24
  super(error.message);
19
- chunkJE77HYXB_cjs.__publicField(this, "type");
20
- chunkJE77HYXB_cjs.__publicField(this, "code");
21
- chunkJE77HYXB_cjs.__publicField(this, "source");
22
- this.name = _SdkError.NAME;
25
+ this.name = SdkError.NAME;
23
26
  this.type = error.type || "client" /* CLIENT */;
24
27
  }
25
- static isSdkError(error) {
26
- return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
28
+ }
29
+ class ApiError extends SdkError {
30
+ static NAME = "ApiError";
31
+ static isApiError(error) {
32
+ return SdkError.isSdkError(error) && error.name === ApiError.NAME && error.type === "response" /* RESPONSE */;
27
33
  }
28
- };
29
- chunkJE77HYXB_cjs.__publicField(_SdkError, "NAME", "SdkError");
30
- let SdkError = _SdkError;
31
- const _ApiError = class _ApiError extends SdkError {
34
+ errors = [];
35
+ status;
36
+ statusText;
32
37
  // constructor(error: SdkError)
33
38
  constructor(error) {
34
39
  super({ ...error, type: "response" /* RESPONSE */ });
35
- chunkJE77HYXB_cjs.__publicField(this, "errors", []);
36
- chunkJE77HYXB_cjs.__publicField(this, "status");
37
- chunkJE77HYXB_cjs.__publicField(this, "statusText");
38
- this.name = _ApiError.NAME;
39
- }
40
- static isApiError(error) {
41
- return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
40
+ this.name = ApiError.NAME;
42
41
  }
43
42
  first() {
44
43
  return this.errors?.length > 0 ? this.errors[0] : void 0;
45
44
  }
46
- };
47
- chunkJE77HYXB_cjs.__publicField(_ApiError, "NAME", "ApiError");
48
- let ApiError = _ApiError;
45
+ }
49
46
  const isRequestError = (error) => {
50
47
  return error instanceof TypeError && error.message !== "fetch failed";
51
48
  };