@commercelayer/sdk 7.0.0-beta.18 → 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 (293) hide show
  1. package/lib/api.cjs +791 -7460
  2. package/lib/api.js +131 -7331
  3. package/lib/client.cjs +31 -215
  4. package/lib/client.js +23 -212
  5. package/lib/commercelayer.cjs +30 -778
  6. package/lib/commercelayer.js +22 -774
  7. package/lib/common.cjs +6 -143
  8. package/lib/common.js +4 -141
  9. package/lib/config.cjs +1 -2
  10. package/lib/config.js +1 -2
  11. package/lib/debug.cjs +5 -13
  12. package/lib/debug.js +5 -13
  13. package/lib/enum.cjs +8 -9
  14. package/lib/enum.js +8 -9
  15. package/lib/error.cjs +15 -67
  16. package/lib/error.js +14 -66
  17. package/lib/fetch.cjs +13 -72
  18. package/lib/fetch.js +11 -74
  19. package/lib/index.cjs +22 -8104
  20. package/lib/index.js +3 -7977
  21. package/lib/jsonapi.cjs +20 -188
  22. package/lib/jsonapi.js +13 -186
  23. package/lib/query.cjs +16 -75
  24. package/lib/query.js +14 -77
  25. package/lib/resource.cjs +57 -651
  26. package/lib/resource.js +37 -637
  27. package/lib/resources/addresses.cjs +11 -801
  28. package/lib/resources/addresses.js +11 -801
  29. package/lib/resources/adjustments.cjs +9 -799
  30. package/lib/resources/adjustments.js +9 -799
  31. package/lib/resources/adyen_gateways.cjs +9 -799
  32. package/lib/resources/adyen_gateways.js +9 -799
  33. package/lib/resources/adyen_payments.cjs +11 -801
  34. package/lib/resources/adyen_payments.js +11 -801
  35. package/lib/resources/applications.cjs +6 -788
  36. package/lib/resources/applications.js +6 -788
  37. package/lib/resources/attachments.cjs +9 -799
  38. package/lib/resources/attachments.js +9 -799
  39. package/lib/resources/authorizations.cjs +12 -802
  40. package/lib/resources/authorizations.js +12 -802
  41. package/lib/resources/avalara_accounts.cjs +9 -799
  42. package/lib/resources/avalara_accounts.js +9 -799
  43. package/lib/resources/axerve_gateways.cjs +9 -799
  44. package/lib/resources/axerve_gateways.js +9 -799
  45. package/lib/resources/axerve_payments.cjs +10 -800
  46. package/lib/resources/axerve_payments.js +10 -800
  47. package/lib/resources/bing_geocoders.cjs +9 -799
  48. package/lib/resources/bing_geocoders.js +9 -799
  49. package/lib/resources/braintree_gateways.cjs +9 -799
  50. package/lib/resources/braintree_gateways.js +9 -799
  51. package/lib/resources/braintree_payments.cjs +9 -799
  52. package/lib/resources/braintree_payments.js +9 -799
  53. package/lib/resources/bundles.cjs +13 -803
  54. package/lib/resources/bundles.js +13 -803
  55. package/lib/resources/buy_x_pay_y_promotions.cjs +13 -803
  56. package/lib/resources/buy_x_pay_y_promotions.js +13 -803
  57. package/lib/resources/captures.cjs +11 -801
  58. package/lib/resources/captures.js +11 -801
  59. package/lib/resources/carrier_accounts.cjs +9 -799
  60. package/lib/resources/carrier_accounts.js +9 -799
  61. package/lib/resources/checkout_com_gateways.cjs +9 -799
  62. package/lib/resources/checkout_com_gateways.js +9 -799
  63. package/lib/resources/checkout_com_payments.cjs +11 -801
  64. package/lib/resources/checkout_com_payments.js +11 -801
  65. package/lib/resources/cleanups.cjs +10 -800
  66. package/lib/resources/cleanups.js +10 -800
  67. package/lib/resources/coupon_codes_promotion_rules.cjs +9 -799
  68. package/lib/resources/coupon_codes_promotion_rules.js +9 -799
  69. package/lib/resources/coupon_recipients.cjs +9 -799
  70. package/lib/resources/coupon_recipients.js +9 -799
  71. package/lib/resources/coupons.cjs +11 -801
  72. package/lib/resources/coupons.js +11 -801
  73. package/lib/resources/custom_promotion_rules.cjs +9 -799
  74. package/lib/resources/custom_promotion_rules.js +9 -799
  75. package/lib/resources/customer_addresses.cjs +9 -799
  76. package/lib/resources/customer_addresses.js +9 -799
  77. package/lib/resources/customer_groups.cjs +9 -799
  78. package/lib/resources/customer_groups.js +9 -799
  79. package/lib/resources/customer_password_resets.cjs +10 -800
  80. package/lib/resources/customer_password_resets.js +10 -800
  81. package/lib/resources/customer_payment_sources.cjs +9 -799
  82. package/lib/resources/customer_payment_sources.js +9 -799
  83. package/lib/resources/customer_subscriptions.cjs +9 -799
  84. package/lib/resources/customer_subscriptions.js +9 -799
  85. package/lib/resources/customers.cjs +11 -801
  86. package/lib/resources/customers.js +11 -801
  87. package/lib/resources/delivery_lead_times.cjs +9 -799
  88. package/lib/resources/delivery_lead_times.js +9 -799
  89. package/lib/resources/discount_engine_items.cjs +6 -796
  90. package/lib/resources/discount_engine_items.js +6 -796
  91. package/lib/resources/discount_engines.cjs +6 -796
  92. package/lib/resources/discount_engines.js +6 -796
  93. package/lib/resources/easypost_pickups.cjs +10 -800
  94. package/lib/resources/easypost_pickups.js +10 -800
  95. package/lib/resources/event_callbacks.cjs +6 -796
  96. package/lib/resources/event_callbacks.js +6 -796
  97. package/lib/resources/events.cjs +8 -798
  98. package/lib/resources/events.js +8 -798
  99. package/lib/resources/exports.cjs +10 -800
  100. package/lib/resources/exports.js +10 -800
  101. package/lib/resources/external_gateways.cjs +10 -800
  102. package/lib/resources/external_gateways.js +10 -800
  103. package/lib/resources/external_payments.cjs +9 -799
  104. package/lib/resources/external_payments.js +9 -799
  105. package/lib/resources/external_promotions.cjs +14 -804
  106. package/lib/resources/external_promotions.js +14 -804
  107. package/lib/resources/external_tax_calculators.cjs +10 -800
  108. package/lib/resources/external_tax_calculators.js +10 -800
  109. package/lib/resources/fixed_amount_promotions.cjs +13 -803
  110. package/lib/resources/fixed_amount_promotions.js +13 -803
  111. package/lib/resources/fixed_price_promotions.cjs +13 -803
  112. package/lib/resources/fixed_price_promotions.js +13 -803
  113. package/lib/resources/flex_promotions.cjs +13 -803
  114. package/lib/resources/flex_promotions.js +13 -803
  115. package/lib/resources/free_gift_promotions.cjs +13 -803
  116. package/lib/resources/free_gift_promotions.js +13 -803
  117. package/lib/resources/free_shipping_promotions.cjs +13 -803
  118. package/lib/resources/free_shipping_promotions.js +13 -803
  119. package/lib/resources/geocoders.cjs +6 -796
  120. package/lib/resources/geocoders.js +6 -796
  121. package/lib/resources/gift_card_recipients.cjs +9 -799
  122. package/lib/resources/gift_card_recipients.js +9 -799
  123. package/lib/resources/gift_cards.cjs +15 -805
  124. package/lib/resources/gift_cards.js +15 -805
  125. package/lib/resources/google_geocoders.cjs +9 -799
  126. package/lib/resources/google_geocoders.js +9 -799
  127. package/lib/resources/imports.cjs +10 -800
  128. package/lib/resources/imports.js +10 -800
  129. package/lib/resources/in_stock_subscriptions.cjs +11 -801
  130. package/lib/resources/in_stock_subscriptions.js +11 -801
  131. package/lib/resources/inventory_models.cjs +9 -799
  132. package/lib/resources/inventory_models.js +9 -799
  133. package/lib/resources/inventory_return_locations.cjs +9 -799
  134. package/lib/resources/inventory_return_locations.js +9 -799
  135. package/lib/resources/inventory_stock_locations.cjs +9 -799
  136. package/lib/resources/inventory_stock_locations.js +9 -799
  137. package/lib/resources/klarna_gateways.cjs +9 -799
  138. package/lib/resources/klarna_gateways.js +9 -799
  139. package/lib/resources/klarna_payments.cjs +10 -800
  140. package/lib/resources/klarna_payments.js +10 -800
  141. package/lib/resources/line_item_options.cjs +11 -801
  142. package/lib/resources/line_item_options.js +11 -801
  143. package/lib/resources/line_items.cjs +14 -804
  144. package/lib/resources/line_items.js +14 -804
  145. package/lib/resources/links.cjs +11 -801
  146. package/lib/resources/links.js +11 -801
  147. package/lib/resources/manual_gateways.cjs +9 -799
  148. package/lib/resources/manual_gateways.js +9 -799
  149. package/lib/resources/manual_tax_calculators.cjs +9 -799
  150. package/lib/resources/manual_tax_calculators.js +9 -799
  151. package/lib/resources/markets.cjs +11 -801
  152. package/lib/resources/markets.js +11 -801
  153. package/lib/resources/merchants.cjs +9 -799
  154. package/lib/resources/merchants.js +9 -799
  155. package/lib/resources/notifications.cjs +9 -799
  156. package/lib/resources/notifications.js +9 -799
  157. package/lib/resources/order_amount_promotion_rules.cjs +9 -799
  158. package/lib/resources/order_amount_promotion_rules.js +9 -799
  159. package/lib/resources/order_copies.cjs +9 -799
  160. package/lib/resources/order_copies.js +9 -799
  161. package/lib/resources/order_factories.cjs +6 -796
  162. package/lib/resources/order_factories.js +6 -796
  163. package/lib/resources/order_subscription_items.cjs +9 -799
  164. package/lib/resources/order_subscription_items.js +9 -799
  165. package/lib/resources/order_subscriptions.cjs +15 -805
  166. package/lib/resources/order_subscriptions.js +15 -805
  167. package/lib/resources/orders.cjs +42 -832
  168. package/lib/resources/orders.js +42 -832
  169. package/lib/resources/organizations.cjs +6 -788
  170. package/lib/resources/organizations.js +6 -788
  171. package/lib/resources/packages.cjs +9 -799
  172. package/lib/resources/packages.js +9 -799
  173. package/lib/resources/parcel_line_items.cjs +9 -799
  174. package/lib/resources/parcel_line_items.js +9 -799
  175. package/lib/resources/parcels.cjs +9 -799
  176. package/lib/resources/parcels.js +9 -799
  177. package/lib/resources/payment_gateways.cjs +6 -796
  178. package/lib/resources/payment_gateways.js +6 -796
  179. package/lib/resources/payment_methods.cjs +11 -801
  180. package/lib/resources/payment_methods.js +11 -801
  181. package/lib/resources/payment_options.cjs +9 -799
  182. package/lib/resources/payment_options.js +9 -799
  183. package/lib/resources/paypal_gateways.cjs +9 -799
  184. package/lib/resources/paypal_gateways.js +9 -799
  185. package/lib/resources/paypal_payments.cjs +9 -799
  186. package/lib/resources/paypal_payments.js +9 -799
  187. package/lib/resources/percentage_discount_promotions.cjs +13 -803
  188. package/lib/resources/percentage_discount_promotions.js +13 -803
  189. package/lib/resources/pickups.cjs +6 -796
  190. package/lib/resources/pickups.js +6 -796
  191. package/lib/resources/price_frequency_tiers.cjs +9 -799
  192. package/lib/resources/price_frequency_tiers.js +9 -799
  193. package/lib/resources/price_list_schedulers.cjs +11 -801
  194. package/lib/resources/price_list_schedulers.js +11 -801
  195. package/lib/resources/price_lists.cjs +9 -799
  196. package/lib/resources/price_lists.js +9 -799
  197. package/lib/resources/price_tiers.cjs +6 -796
  198. package/lib/resources/price_tiers.js +6 -796
  199. package/lib/resources/price_volume_tiers.cjs +9 -799
  200. package/lib/resources/price_volume_tiers.js +9 -799
  201. package/lib/resources/prices.cjs +9 -799
  202. package/lib/resources/prices.js +9 -799
  203. package/lib/resources/promotion_rules.cjs +6 -796
  204. package/lib/resources/promotion_rules.js +6 -796
  205. package/lib/resources/promotions.cjs +6 -796
  206. package/lib/resources/promotions.js +6 -796
  207. package/lib/resources/recurring_order_copies.cjs +9 -799
  208. package/lib/resources/recurring_order_copies.js +9 -799
  209. package/lib/resources/refunds.cjs +8 -798
  210. package/lib/resources/refunds.js +8 -798
  211. package/lib/resources/reserved_stocks.cjs +6 -796
  212. package/lib/resources/reserved_stocks.js +6 -796
  213. package/lib/resources/resource_errors.cjs +6 -796
  214. package/lib/resources/resource_errors.js +6 -796
  215. package/lib/resources/return_line_items.cjs +10 -800
  216. package/lib/resources/return_line_items.js +10 -800
  217. package/lib/resources/returns.cjs +22 -812
  218. package/lib/resources/returns.js +22 -812
  219. package/lib/resources/satispay_gateways.cjs +9 -799
  220. package/lib/resources/satispay_gateways.js +9 -799
  221. package/lib/resources/satispay_payments.cjs +10 -800
  222. package/lib/resources/satispay_payments.js +10 -800
  223. package/lib/resources/shipments.cjs +24 -814
  224. package/lib/resources/shipments.js +24 -814
  225. package/lib/resources/shipping_categories.cjs +9 -799
  226. package/lib/resources/shipping_categories.js +9 -799
  227. package/lib/resources/shipping_method_tiers.cjs +6 -796
  228. package/lib/resources/shipping_method_tiers.js +6 -796
  229. package/lib/resources/shipping_methods.cjs +12 -802
  230. package/lib/resources/shipping_methods.js +12 -802
  231. package/lib/resources/shipping_weight_tiers.cjs +9 -799
  232. package/lib/resources/shipping_weight_tiers.js +9 -799
  233. package/lib/resources/shipping_zones.cjs +9 -799
  234. package/lib/resources/shipping_zones.js +9 -799
  235. package/lib/resources/sku_list_items.cjs +9 -799
  236. package/lib/resources/sku_list_items.js +9 -799
  237. package/lib/resources/sku_list_promotion_rules.cjs +9 -799
  238. package/lib/resources/sku_list_promotion_rules.js +9 -799
  239. package/lib/resources/sku_lists.cjs +9 -799
  240. package/lib/resources/sku_lists.js +9 -799
  241. package/lib/resources/sku_options.cjs +11 -801
  242. package/lib/resources/sku_options.js +11 -801
  243. package/lib/resources/skus.cjs +11 -801
  244. package/lib/resources/skus.js +11 -801
  245. package/lib/resources/stock_items.cjs +10 -800
  246. package/lib/resources/stock_items.js +10 -800
  247. package/lib/resources/stock_line_items.cjs +12 -802
  248. package/lib/resources/stock_line_items.js +12 -802
  249. package/lib/resources/stock_locations.cjs +9 -799
  250. package/lib/resources/stock_locations.js +9 -799
  251. package/lib/resources/stock_reservations.cjs +10 -800
  252. package/lib/resources/stock_reservations.js +10 -800
  253. package/lib/resources/stock_transfers.cjs +15 -805
  254. package/lib/resources/stock_transfers.js +15 -805
  255. package/lib/resources/stores.cjs +9 -799
  256. package/lib/resources/stores.js +9 -799
  257. package/lib/resources/stripe_gateways.cjs +9 -799
  258. package/lib/resources/stripe_gateways.js +9 -799
  259. package/lib/resources/stripe_payments.cjs +11 -801
  260. package/lib/resources/stripe_payments.js +11 -801
  261. package/lib/resources/stripe_tax_accounts.cjs +9 -799
  262. package/lib/resources/stripe_tax_accounts.js +9 -799
  263. package/lib/resources/subscription_models.cjs +9 -799
  264. package/lib/resources/subscription_models.js +9 -799
  265. package/lib/resources/tags.cjs +9 -799
  266. package/lib/resources/tags.js +9 -799
  267. package/lib/resources/talon_one_accounts.cjs +9 -799
  268. package/lib/resources/talon_one_accounts.js +9 -799
  269. package/lib/resources/tax_calculators.cjs +6 -796
  270. package/lib/resources/tax_calculators.js +6 -796
  271. package/lib/resources/tax_categories.cjs +9 -799
  272. package/lib/resources/tax_categories.js +9 -799
  273. package/lib/resources/tax_rules.cjs +9 -799
  274. package/lib/resources/tax_rules.js +9 -799
  275. package/lib/resources/taxjar_accounts.cjs +9 -799
  276. package/lib/resources/taxjar_accounts.js +9 -799
  277. package/lib/resources/transactions.cjs +6 -796
  278. package/lib/resources/transactions.js +6 -796
  279. package/lib/resources/versions.cjs +6 -796
  280. package/lib/resources/versions.js +6 -796
  281. package/lib/resources/vertex_accounts.cjs +10 -800
  282. package/lib/resources/vertex_accounts.js +10 -800
  283. package/lib/resources/voids.cjs +8 -798
  284. package/lib/resources/voids.js +8 -798
  285. package/lib/resources/webhooks.cjs +12 -802
  286. package/lib/resources/webhooks.js +12 -802
  287. package/lib/resources/wire_transfers.cjs +9 -799
  288. package/lib/resources/wire_transfers.js +9 -799
  289. package/lib/static.cjs +19 -753
  290. package/lib/static.js +5 -739
  291. package/lib/util.cjs +4 -5
  292. package/lib/util.js +4 -5
  293. package/package.json +4 -4
package/lib/error.js CHANGED
@@ -1,57 +1,5 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
1
+ import { FetchError } from './fetch';
7
2
 
8
- // src/debug.ts
9
- var debuggerFunction = (_pattern, ..._args) => {
10
- };
11
- var debuggerFactory = (_namespace) => debuggerFunction;
12
- try {
13
- const debugModule = __require("debug");
14
- if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
15
- } catch (error) {
16
- }
17
- var debugPrefix = "clsdk";
18
- var debug = (namespace) => {
19
- return debuggerFactory(`${debugPrefix}:${namespace}`);
20
- };
21
- var debug_default = debug;
22
-
23
- // src/fetch.ts
24
- debug_default("fetch");
25
- var FetchError = class _FetchError extends Error {
26
- static isFetchError = (error) => {
27
- return error instanceof _FetchError;
28
- };
29
- #errors;
30
- #status;
31
- #statusText;
32
- #request;
33
- constructor(status, statusText, body, request) {
34
- super(statusText);
35
- this.#status = status;
36
- this.#statusText = statusText;
37
- if (body) this.#errors = body.errors;
38
- if (request) this.#request = request;
39
- }
40
- get errors() {
41
- return this.#errors;
42
- }
43
- get status() {
44
- return this.#status;
45
- }
46
- get statusText() {
47
- return this.#statusText;
48
- }
49
- get request() {
50
- return this.#request;
51
- }
52
- };
53
-
54
- // src/error.ts
55
3
  var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
56
4
  ErrorType2["CLIENT"] = "client";
57
5
  ErrorType2["REQUEST"] = "request";
@@ -62,24 +10,24 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
62
10
  ErrorType2["TOKEN_REFRESH"] = "token-refresh";
63
11
  return ErrorType2;
64
12
  })(ErrorType || {});
65
- var SdkError = class _SdkError extends Error {
13
+ class SdkError extends Error {
66
14
  static NAME = "SdkError";
67
15
  static isSdkError(error) {
68
- return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
16
+ return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
69
17
  }
70
18
  type;
71
19
  code;
72
20
  source;
73
21
  constructor(error) {
74
22
  super(error.message);
75
- this.name = _SdkError.NAME;
23
+ this.name = SdkError.NAME;
76
24
  this.type = error.type || "client" /* CLIENT */;
77
25
  }
78
- };
79
- var ApiError = class _ApiError extends SdkError {
26
+ }
27
+ class ApiError extends SdkError {
80
28
  static NAME = "ApiError";
81
29
  static isApiError(error) {
82
- return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
30
+ return SdkError.isSdkError(error) && error.name === ApiError.NAME && error.type === "response" /* RESPONSE */;
83
31
  }
84
32
  errors = [];
85
33
  status;
@@ -87,29 +35,29 @@ var ApiError = class _ApiError extends SdkError {
87
35
  // constructor(error: SdkError)
88
36
  constructor(error) {
89
37
  super({ ...error, type: "response" /* RESPONSE */ });
90
- this.name = _ApiError.NAME;
38
+ this.name = ApiError.NAME;
91
39
  }
92
40
  first() {
93
41
  return this.errors?.length > 0 ? this.errors[0] : void 0;
94
42
  }
95
- };
96
- var isRequestError = (error) => {
43
+ }
44
+ const isRequestError = (error) => {
97
45
  return error instanceof TypeError && error.message !== "fetch failed";
98
46
  };
99
- var isCancelError = (error) => {
47
+ const isCancelError = (error) => {
100
48
  return error instanceof DOMException && error.name === "AbortError";
101
49
  };
102
- var isTimeoutError = (error) => {
50
+ const isTimeoutError = (error) => {
103
51
  return error instanceof DOMException && error.name === "TimeoutError";
104
52
  };
105
- var isExpiredTokenError = (error) => {
53
+ const isExpiredTokenError = (error) => {
106
54
  const invalidTokenCodes = [
107
55
  "INVALID_TOKEN"
108
56
  /*, 'UNAUTHORIZED' */
109
57
  ];
110
58
  return ApiError.isApiError(error) && error.status === 401 && (invalidTokenCodes.includes(error.code || "") || error.errors && error.errors.length > 0 && invalidTokenCodes.includes(error.errors[0].code));
111
59
  };
112
- var handleError = (error) => {
60
+ const handleError = (error) => {
113
61
  if (SdkError.isSdkError(error) || ApiError.isApiError(error)) throw error;
114
62
  let sdkError = new SdkError({ message: error.message });
115
63
  if (FetchError.isFetchError(error)) {
package/lib/fetch.cjs CHANGED
@@ -1,75 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
- }) : x)(function(x) {
6
- if (typeof require !== "undefined") return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
3
+ var error = require('./error');
4
+ var Debug = require('./debug');
9
5
 
10
- // src/error.ts
11
- var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
12
- ErrorType2["CLIENT"] = "client";
13
- ErrorType2["REQUEST"] = "request";
14
- ErrorType2["RESPONSE"] = "response";
15
- ErrorType2["CANCEL"] = "cancel";
16
- ErrorType2["PARSE"] = "parse";
17
- ErrorType2["TIMEOUT"] = "timeout";
18
- ErrorType2["TOKEN_REFRESH"] = "token-refresh";
19
- return ErrorType2;
20
- })(ErrorType || {});
21
- var SdkError = class _SdkError extends Error {
22
- static NAME = "SdkError";
23
- static isSdkError(error) {
24
- return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
25
- }
26
- type;
27
- code;
28
- source;
29
- constructor(error) {
30
- super(error.message);
31
- this.name = _SdkError.NAME;
32
- this.type = error.type || "client" /* CLIENT */;
33
- }
34
- };
35
- var ApiError = class _ApiError extends SdkError {
36
- static NAME = "ApiError";
37
- static isApiError(error) {
38
- return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
39
- }
40
- errors = [];
41
- status;
42
- statusText;
43
- // constructor(error: SdkError)
44
- constructor(error) {
45
- super({ ...error, type: "response" /* RESPONSE */ });
46
- this.name = _ApiError.NAME;
47
- }
48
- first() {
49
- return this.errors?.length > 0 ? this.errors[0] : void 0;
50
- }
51
- };
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
52
7
 
53
- // src/debug.ts
54
- var debuggerFunction = (_pattern, ..._args) => {
55
- };
56
- var debuggerFactory = (_namespace) => debuggerFunction;
57
- try {
58
- const debugModule = __require("debug");
59
- if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
60
- } catch (error) {
61
- }
62
- var debugPrefix = "clsdk";
63
- var debug = (namespace) => {
64
- return debuggerFactory(`${debugPrefix}:${namespace}`);
65
- };
66
- var debug_default = debug;
8
+ var Debug__default = /*#__PURE__*/_interopDefault(Debug);
67
9
 
68
- // src/fetch.ts
69
- var debug2 = debug_default("fetch");
70
- var FetchError = class _FetchError extends Error {
10
+ const debug = Debug__default.default("fetch");
11
+ class FetchError extends Error {
71
12
  static isFetchError = (error) => {
72
- return error instanceof _FetchError;
13
+ return error instanceof FetchError;
73
14
  };
74
15
  #errors;
75
16
  #status;
@@ -94,9 +35,9 @@ var FetchError = class _FetchError extends Error {
94
35
  get request() {
95
36
  return this.#request;
96
37
  }
97
- };
98
- var fetchURL = async (url, requestOptions, clientOptions) => {
99
- debug2("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
38
+ }
39
+ const fetchURL = async (url, requestOptions, clientOptions) => {
40
+ debug("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
100
41
  const interceptors = clientOptions?.interceptors;
101
42
  if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
102
43
  const fetchClient = clientOptions?.fetch || fetch;
@@ -108,11 +49,11 @@ var fetchURL = async (url, requestOptions, clientOptions) => {
108
49
  if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
109
50
  }
110
51
  const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
111
- debug2("response: %O", json);
52
+ debug("response: %O", json);
112
53
  return json;
113
54
  }).catch((err) => {
114
- debug2("error: %s", err.message);
115
- if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: "parse" /* PARSE */ });
55
+ debug("error: %s", err.message);
56
+ if (response.ok) throw new error.SdkError({ message: "Error parsing API response body", type: error.ErrorType.PARSE });
116
57
  }) : void 0;
117
58
  if (!response.ok) {
118
59
  let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
package/lib/fetch.js CHANGED
@@ -1,73 +1,10 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
1
+ import { SdkError, ErrorType } from './error';
2
+ import Debug from './debug';
7
3
 
8
- // src/error.ts
9
- var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
10
- ErrorType2["CLIENT"] = "client";
11
- ErrorType2["REQUEST"] = "request";
12
- ErrorType2["RESPONSE"] = "response";
13
- ErrorType2["CANCEL"] = "cancel";
14
- ErrorType2["PARSE"] = "parse";
15
- ErrorType2["TIMEOUT"] = "timeout";
16
- ErrorType2["TOKEN_REFRESH"] = "token-refresh";
17
- return ErrorType2;
18
- })(ErrorType || {});
19
- var SdkError = class _SdkError extends Error {
20
- static NAME = "SdkError";
21
- static isSdkError(error) {
22
- return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
23
- }
24
- type;
25
- code;
26
- source;
27
- constructor(error) {
28
- super(error.message);
29
- this.name = _SdkError.NAME;
30
- this.type = error.type || "client" /* CLIENT */;
31
- }
32
- };
33
- var ApiError = class _ApiError extends SdkError {
34
- static NAME = "ApiError";
35
- static isApiError(error) {
36
- return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
37
- }
38
- errors = [];
39
- status;
40
- statusText;
41
- // constructor(error: SdkError)
42
- constructor(error) {
43
- super({ ...error, type: "response" /* RESPONSE */ });
44
- this.name = _ApiError.NAME;
45
- }
46
- first() {
47
- return this.errors?.length > 0 ? this.errors[0] : void 0;
48
- }
49
- };
50
-
51
- // src/debug.ts
52
- var debuggerFunction = (_pattern, ..._args) => {
53
- };
54
- var debuggerFactory = (_namespace) => debuggerFunction;
55
- try {
56
- const debugModule = __require("debug");
57
- if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
58
- } catch (error) {
59
- }
60
- var debugPrefix = "clsdk";
61
- var debug = (namespace) => {
62
- return debuggerFactory(`${debugPrefix}:${namespace}`);
63
- };
64
- var debug_default = debug;
65
-
66
- // src/fetch.ts
67
- var debug2 = debug_default("fetch");
68
- var FetchError = class _FetchError extends Error {
4
+ const debug = Debug("fetch");
5
+ class FetchError extends Error {
69
6
  static isFetchError = (error) => {
70
- return error instanceof _FetchError;
7
+ return error instanceof FetchError;
71
8
  };
72
9
  #errors;
73
10
  #status;
@@ -92,9 +29,9 @@ var FetchError = class _FetchError extends Error {
92
29
  get request() {
93
30
  return this.#request;
94
31
  }
95
- };
96
- var fetchURL = async (url, requestOptions, clientOptions) => {
97
- debug2("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
32
+ }
33
+ const fetchURL = async (url, requestOptions, clientOptions) => {
34
+ debug("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
98
35
  const interceptors = clientOptions?.interceptors;
99
36
  if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
100
37
  const fetchClient = clientOptions?.fetch || fetch;
@@ -106,11 +43,11 @@ var fetchURL = async (url, requestOptions, clientOptions) => {
106
43
  if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
107
44
  }
108
45
  const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
109
- debug2("response: %O", json);
46
+ debug("response: %O", json);
110
47
  return json;
111
48
  }).catch((err) => {
112
- debug2("error: %s", err.message);
113
- if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: "parse" /* PARSE */ });
49
+ debug("error: %s", err.message);
50
+ if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: ErrorType.PARSE });
114
51
  }) : void 0;
115
52
  if (!response.ok) {
116
53
  let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);