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

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 +7460 -792
  2. package/lib/api.js +7331 -132
  3. package/lib/client.cjs +253 -78
  4. package/lib/client.js +252 -72
  5. package/lib/commercelayer.cjs +777 -31
  6. package/lib/commercelayer.js +773 -23
  7. package/lib/common.cjs +143 -7
  8. package/lib/common.js +141 -5
  9. package/lib/config.cjs +2 -3
  10. package/lib/config.js +2 -3
  11. package/lib/debug.cjs +12 -6
  12. package/lib/debug.js +12 -6
  13. package/lib/enum.cjs +9 -10
  14. package/lib/enum.js +9 -10
  15. package/lib/error.cjs +75 -26
  16. package/lib/error.js +74 -25
  17. package/lib/fetch.cjs +85 -33
  18. package/lib/fetch.js +87 -31
  19. package/lib/index.cjs +8104 -23
  20. package/lib/index.d.cts +1 -1
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +7977 -4
  23. package/lib/jsonapi.cjs +188 -21
  24. package/lib/jsonapi.js +186 -14
  25. package/lib/query.cjs +75 -17
  26. package/lib/query.js +77 -15
  27. package/lib/resource.cjs +660 -71
  28. package/lib/resource.js +646 -51
  29. package/lib/resources/addresses.cjs +794 -6
  30. package/lib/resources/addresses.js +794 -6
  31. package/lib/resources/adjustments.cjs +794 -6
  32. package/lib/resources/adjustments.js +794 -6
  33. package/lib/resources/adyen_gateways.cjs +794 -6
  34. package/lib/resources/adyen_gateways.js +794 -6
  35. package/lib/resources/adyen_payments.cjs +794 -6
  36. package/lib/resources/adyen_payments.js +794 -6
  37. package/lib/resources/applications.cjs +786 -6
  38. package/lib/resources/applications.js +786 -6
  39. package/lib/resources/attachments.cjs +794 -6
  40. package/lib/resources/attachments.js +794 -6
  41. package/lib/resources/authorizations.cjs +794 -6
  42. package/lib/resources/authorizations.js +794 -6
  43. package/lib/resources/avalara_accounts.cjs +794 -6
  44. package/lib/resources/avalara_accounts.js +794 -6
  45. package/lib/resources/axerve_gateways.cjs +794 -6
  46. package/lib/resources/axerve_gateways.js +794 -6
  47. package/lib/resources/axerve_payments.cjs +794 -6
  48. package/lib/resources/axerve_payments.js +794 -6
  49. package/lib/resources/bing_geocoders.cjs +794 -6
  50. package/lib/resources/bing_geocoders.js +794 -6
  51. package/lib/resources/braintree_gateways.cjs +794 -6
  52. package/lib/resources/braintree_gateways.js +794 -6
  53. package/lib/resources/braintree_payments.cjs +794 -6
  54. package/lib/resources/braintree_payments.js +794 -6
  55. package/lib/resources/bundles.cjs +794 -6
  56. package/lib/resources/bundles.js +794 -6
  57. package/lib/resources/buy_x_pay_y_promotions.cjs +794 -6
  58. package/lib/resources/buy_x_pay_y_promotions.js +794 -6
  59. package/lib/resources/captures.cjs +794 -6
  60. package/lib/resources/captures.js +794 -6
  61. package/lib/resources/carrier_accounts.cjs +794 -6
  62. package/lib/resources/carrier_accounts.js +794 -6
  63. package/lib/resources/checkout_com_gateways.cjs +794 -6
  64. package/lib/resources/checkout_com_gateways.js +794 -6
  65. package/lib/resources/checkout_com_payments.cjs +794 -6
  66. package/lib/resources/checkout_com_payments.js +794 -6
  67. package/lib/resources/cleanups.cjs +794 -6
  68. package/lib/resources/cleanups.js +794 -6
  69. package/lib/resources/coupon_codes_promotion_rules.cjs +794 -6
  70. package/lib/resources/coupon_codes_promotion_rules.js +794 -6
  71. package/lib/resources/coupon_recipients.cjs +794 -6
  72. package/lib/resources/coupon_recipients.js +794 -6
  73. package/lib/resources/coupons.cjs +794 -6
  74. package/lib/resources/coupons.js +794 -6
  75. package/lib/resources/custom_promotion_rules.cjs +794 -6
  76. package/lib/resources/custom_promotion_rules.js +794 -6
  77. package/lib/resources/customer_addresses.cjs +794 -6
  78. package/lib/resources/customer_addresses.js +794 -6
  79. package/lib/resources/customer_groups.cjs +794 -6
  80. package/lib/resources/customer_groups.js +794 -6
  81. package/lib/resources/customer_password_resets.cjs +794 -6
  82. package/lib/resources/customer_password_resets.js +794 -6
  83. package/lib/resources/customer_payment_sources.cjs +794 -6
  84. package/lib/resources/customer_payment_sources.js +794 -6
  85. package/lib/resources/customer_subscriptions.cjs +794 -6
  86. package/lib/resources/customer_subscriptions.js +794 -6
  87. package/lib/resources/customers.cjs +794 -6
  88. package/lib/resources/customers.js +794 -6
  89. package/lib/resources/delivery_lead_times.cjs +794 -6
  90. package/lib/resources/delivery_lead_times.js +794 -6
  91. package/lib/resources/discount_engine_items.cjs +794 -6
  92. package/lib/resources/discount_engine_items.js +794 -6
  93. package/lib/resources/discount_engines.cjs +794 -6
  94. package/lib/resources/discount_engines.js +794 -6
  95. package/lib/resources/easypost_pickups.cjs +794 -6
  96. package/lib/resources/easypost_pickups.js +794 -6
  97. package/lib/resources/event_callbacks.cjs +794 -6
  98. package/lib/resources/event_callbacks.js +794 -6
  99. package/lib/resources/events.cjs +794 -6
  100. package/lib/resources/events.js +794 -6
  101. package/lib/resources/exports.cjs +794 -6
  102. package/lib/resources/exports.js +794 -6
  103. package/lib/resources/external_gateways.cjs +794 -6
  104. package/lib/resources/external_gateways.js +794 -6
  105. package/lib/resources/external_payments.cjs +794 -6
  106. package/lib/resources/external_payments.js +794 -6
  107. package/lib/resources/external_promotions.cjs +794 -6
  108. package/lib/resources/external_promotions.js +794 -6
  109. package/lib/resources/external_tax_calculators.cjs +794 -6
  110. package/lib/resources/external_tax_calculators.js +794 -6
  111. package/lib/resources/fixed_amount_promotions.cjs +794 -6
  112. package/lib/resources/fixed_amount_promotions.js +794 -6
  113. package/lib/resources/fixed_price_promotions.cjs +794 -6
  114. package/lib/resources/fixed_price_promotions.js +794 -6
  115. package/lib/resources/flex_promotions.cjs +794 -6
  116. package/lib/resources/flex_promotions.js +794 -6
  117. package/lib/resources/free_gift_promotions.cjs +794 -6
  118. package/lib/resources/free_gift_promotions.js +794 -6
  119. package/lib/resources/free_shipping_promotions.cjs +794 -6
  120. package/lib/resources/free_shipping_promotions.js +794 -6
  121. package/lib/resources/geocoders.cjs +794 -6
  122. package/lib/resources/geocoders.js +794 -6
  123. package/lib/resources/gift_card_recipients.cjs +794 -6
  124. package/lib/resources/gift_card_recipients.js +794 -6
  125. package/lib/resources/gift_cards.cjs +794 -6
  126. package/lib/resources/gift_cards.js +794 -6
  127. package/lib/resources/google_geocoders.cjs +794 -6
  128. package/lib/resources/google_geocoders.js +794 -6
  129. package/lib/resources/imports.cjs +794 -6
  130. package/lib/resources/imports.js +794 -6
  131. package/lib/resources/in_stock_subscriptions.cjs +794 -6
  132. package/lib/resources/in_stock_subscriptions.js +794 -6
  133. package/lib/resources/inventory_models.cjs +794 -6
  134. package/lib/resources/inventory_models.js +794 -6
  135. package/lib/resources/inventory_return_locations.cjs +794 -6
  136. package/lib/resources/inventory_return_locations.js +794 -6
  137. package/lib/resources/inventory_stock_locations.cjs +794 -6
  138. package/lib/resources/inventory_stock_locations.js +794 -6
  139. package/lib/resources/klarna_gateways.cjs +794 -6
  140. package/lib/resources/klarna_gateways.js +794 -6
  141. package/lib/resources/klarna_payments.cjs +794 -6
  142. package/lib/resources/klarna_payments.js +794 -6
  143. package/lib/resources/line_item_options.cjs +794 -6
  144. package/lib/resources/line_item_options.js +794 -6
  145. package/lib/resources/line_items.cjs +794 -6
  146. package/lib/resources/line_items.js +794 -6
  147. package/lib/resources/links.cjs +794 -6
  148. package/lib/resources/links.js +794 -6
  149. package/lib/resources/manual_gateways.cjs +794 -6
  150. package/lib/resources/manual_gateways.js +794 -6
  151. package/lib/resources/manual_tax_calculators.cjs +794 -6
  152. package/lib/resources/manual_tax_calculators.js +794 -6
  153. package/lib/resources/markets.cjs +794 -6
  154. package/lib/resources/markets.js +794 -6
  155. package/lib/resources/merchants.cjs +794 -6
  156. package/lib/resources/merchants.js +794 -6
  157. package/lib/resources/notifications.cjs +794 -6
  158. package/lib/resources/notifications.js +794 -6
  159. package/lib/resources/order_amount_promotion_rules.cjs +794 -6
  160. package/lib/resources/order_amount_promotion_rules.js +794 -6
  161. package/lib/resources/order_copies.cjs +794 -6
  162. package/lib/resources/order_copies.js +794 -6
  163. package/lib/resources/order_factories.cjs +794 -6
  164. package/lib/resources/order_factories.js +794 -6
  165. package/lib/resources/order_subscription_items.cjs +794 -6
  166. package/lib/resources/order_subscription_items.js +794 -6
  167. package/lib/resources/order_subscriptions.cjs +794 -6
  168. package/lib/resources/order_subscriptions.js +794 -6
  169. package/lib/resources/orders.cjs +794 -6
  170. package/lib/resources/orders.js +794 -6
  171. package/lib/resources/organizations.cjs +786 -6
  172. package/lib/resources/organizations.js +786 -6
  173. package/lib/resources/packages.cjs +794 -6
  174. package/lib/resources/packages.js +794 -6
  175. package/lib/resources/parcel_line_items.cjs +794 -6
  176. package/lib/resources/parcel_line_items.js +794 -6
  177. package/lib/resources/parcels.cjs +794 -6
  178. package/lib/resources/parcels.js +794 -6
  179. package/lib/resources/payment_gateways.cjs +794 -6
  180. package/lib/resources/payment_gateways.js +794 -6
  181. package/lib/resources/payment_methods.cjs +794 -6
  182. package/lib/resources/payment_methods.js +794 -6
  183. package/lib/resources/payment_options.cjs +794 -6
  184. package/lib/resources/payment_options.js +794 -6
  185. package/lib/resources/paypal_gateways.cjs +794 -6
  186. package/lib/resources/paypal_gateways.js +794 -6
  187. package/lib/resources/paypal_payments.cjs +794 -6
  188. package/lib/resources/paypal_payments.js +794 -6
  189. package/lib/resources/percentage_discount_promotions.cjs +794 -6
  190. package/lib/resources/percentage_discount_promotions.js +794 -6
  191. package/lib/resources/pickups.cjs +794 -6
  192. package/lib/resources/pickups.js +794 -6
  193. package/lib/resources/price_frequency_tiers.cjs +794 -6
  194. package/lib/resources/price_frequency_tiers.js +794 -6
  195. package/lib/resources/price_list_schedulers.cjs +794 -6
  196. package/lib/resources/price_list_schedulers.js +794 -6
  197. package/lib/resources/price_lists.cjs +794 -6
  198. package/lib/resources/price_lists.js +794 -6
  199. package/lib/resources/price_tiers.cjs +794 -6
  200. package/lib/resources/price_tiers.js +794 -6
  201. package/lib/resources/price_volume_tiers.cjs +794 -6
  202. package/lib/resources/price_volume_tiers.js +794 -6
  203. package/lib/resources/prices.cjs +794 -6
  204. package/lib/resources/prices.js +794 -6
  205. package/lib/resources/promotion_rules.cjs +794 -6
  206. package/lib/resources/promotion_rules.js +794 -6
  207. package/lib/resources/promotions.cjs +794 -6
  208. package/lib/resources/promotions.js +794 -6
  209. package/lib/resources/recurring_order_copies.cjs +794 -6
  210. package/lib/resources/recurring_order_copies.js +794 -6
  211. package/lib/resources/refunds.cjs +794 -6
  212. package/lib/resources/refunds.js +794 -6
  213. package/lib/resources/reserved_stocks.cjs +794 -6
  214. package/lib/resources/reserved_stocks.js +794 -6
  215. package/lib/resources/resource_errors.cjs +794 -6
  216. package/lib/resources/resource_errors.js +794 -6
  217. package/lib/resources/return_line_items.cjs +794 -6
  218. package/lib/resources/return_line_items.js +794 -6
  219. package/lib/resources/returns.cjs +794 -6
  220. package/lib/resources/returns.js +794 -6
  221. package/lib/resources/satispay_gateways.cjs +794 -6
  222. package/lib/resources/satispay_gateways.js +794 -6
  223. package/lib/resources/satispay_payments.cjs +794 -6
  224. package/lib/resources/satispay_payments.js +794 -6
  225. package/lib/resources/shipments.cjs +794 -6
  226. package/lib/resources/shipments.js +794 -6
  227. package/lib/resources/shipping_categories.cjs +794 -6
  228. package/lib/resources/shipping_categories.js +794 -6
  229. package/lib/resources/shipping_method_tiers.cjs +794 -6
  230. package/lib/resources/shipping_method_tiers.js +794 -6
  231. package/lib/resources/shipping_methods.cjs +794 -6
  232. package/lib/resources/shipping_methods.js +794 -6
  233. package/lib/resources/shipping_weight_tiers.cjs +794 -6
  234. package/lib/resources/shipping_weight_tiers.js +794 -6
  235. package/lib/resources/shipping_zones.cjs +794 -6
  236. package/lib/resources/shipping_zones.js +794 -6
  237. package/lib/resources/sku_list_items.cjs +794 -6
  238. package/lib/resources/sku_list_items.js +794 -6
  239. package/lib/resources/sku_list_promotion_rules.cjs +794 -6
  240. package/lib/resources/sku_list_promotion_rules.js +794 -6
  241. package/lib/resources/sku_lists.cjs +794 -6
  242. package/lib/resources/sku_lists.js +794 -6
  243. package/lib/resources/sku_options.cjs +794 -6
  244. package/lib/resources/sku_options.js +794 -6
  245. package/lib/resources/skus.cjs +794 -6
  246. package/lib/resources/skus.js +794 -6
  247. package/lib/resources/stock_items.cjs +794 -6
  248. package/lib/resources/stock_items.js +794 -6
  249. package/lib/resources/stock_line_items.cjs +794 -6
  250. package/lib/resources/stock_line_items.js +794 -6
  251. package/lib/resources/stock_locations.cjs +794 -6
  252. package/lib/resources/stock_locations.js +794 -6
  253. package/lib/resources/stock_reservations.cjs +794 -6
  254. package/lib/resources/stock_reservations.js +794 -6
  255. package/lib/resources/stock_transfers.cjs +794 -6
  256. package/lib/resources/stock_transfers.js +794 -6
  257. package/lib/resources/stores.cjs +794 -6
  258. package/lib/resources/stores.js +794 -6
  259. package/lib/resources/stripe_gateways.cjs +794 -6
  260. package/lib/resources/stripe_gateways.js +794 -6
  261. package/lib/resources/stripe_payments.cjs +794 -6
  262. package/lib/resources/stripe_payments.js +794 -6
  263. package/lib/resources/stripe_tax_accounts.cjs +794 -6
  264. package/lib/resources/stripe_tax_accounts.js +794 -6
  265. package/lib/resources/subscription_models.cjs +794 -6
  266. package/lib/resources/subscription_models.js +794 -6
  267. package/lib/resources/tags.cjs +794 -6
  268. package/lib/resources/tags.js +794 -6
  269. package/lib/resources/talon_one_accounts.cjs +794 -6
  270. package/lib/resources/talon_one_accounts.js +794 -6
  271. package/lib/resources/tax_calculators.cjs +794 -6
  272. package/lib/resources/tax_calculators.js +794 -6
  273. package/lib/resources/tax_categories.cjs +794 -6
  274. package/lib/resources/tax_categories.js +794 -6
  275. package/lib/resources/tax_rules.cjs +794 -6
  276. package/lib/resources/tax_rules.js +794 -6
  277. package/lib/resources/taxjar_accounts.cjs +794 -6
  278. package/lib/resources/taxjar_accounts.js +794 -6
  279. package/lib/resources/transactions.cjs +794 -6
  280. package/lib/resources/transactions.js +794 -6
  281. package/lib/resources/versions.cjs +794 -6
  282. package/lib/resources/versions.js +794 -6
  283. package/lib/resources/vertex_accounts.cjs +794 -6
  284. package/lib/resources/vertex_accounts.js +794 -6
  285. package/lib/resources/voids.cjs +794 -6
  286. package/lib/resources/voids.js +794 -6
  287. package/lib/resources/webhooks.cjs +794 -6
  288. package/lib/resources/webhooks.js +794 -6
  289. package/lib/resources/wire_transfers.cjs +794 -6
  290. package/lib/resources/wire_transfers.js +794 -6
  291. package/lib/static.cjs +753 -20
  292. package/lib/static.js +739 -6
  293. package/lib/util.cjs +5 -6
  294. package/lib/util.js +5 -6
  295. package/package.json +1 -1
  296. package/lib/chunk-AQ5VUG5P.js +0 -12
  297. package/lib/chunk-JE77HYXB.cjs +0 -17
@@ -1,28 +1,780 @@
1
- import { __publicField } from './chunk-AQ5VUG5P.js';
2
- import { getResources } from './enum';
3
- import { isApiError } from './error';
4
- import { ApiResourceAdapter } from './resource';
5
- import Debug from './debug';
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
+ });
6
7
 
7
- const debug = Debug("commercelayer");
8
- 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);
8
+ // src/enum.ts
9
+ var apiResources = [
10
+ // ##__API_RESOURCE_LIST_START__##
11
+ "addresses",
12
+ "adjustments",
13
+ "adyen_gateways",
14
+ "adyen_payments",
15
+ "applications",
16
+ "attachments",
17
+ "authorizations",
18
+ "avalara_accounts",
19
+ "axerve_gateways",
20
+ "axerve_payments",
21
+ "bing_geocoders",
22
+ "braintree_gateways",
23
+ "braintree_payments",
24
+ "bundles",
25
+ "buy_x_pay_y_promotions",
26
+ "captures",
27
+ "carrier_accounts",
28
+ "checkout_com_gateways",
29
+ "checkout_com_payments",
30
+ "cleanups",
31
+ "coupon_codes_promotion_rules",
32
+ "coupon_recipients",
33
+ "coupons",
34
+ "custom_promotion_rules",
35
+ "customer_addresses",
36
+ "customer_groups",
37
+ "customer_password_resets",
38
+ "customer_payment_sources",
39
+ "customer_subscriptions",
40
+ "customers",
41
+ "delivery_lead_times",
42
+ "discount_engine_items",
43
+ "discount_engines",
44
+ "easypost_pickups",
45
+ "event_callbacks",
46
+ "events",
47
+ "exports",
48
+ "external_gateways",
49
+ "external_payments",
50
+ "external_promotions",
51
+ "external_tax_calculators",
52
+ "fixed_amount_promotions",
53
+ "fixed_price_promotions",
54
+ "flex_promotions",
55
+ "free_gift_promotions",
56
+ "free_shipping_promotions",
57
+ "geocoders",
58
+ "gift_card_recipients",
59
+ "gift_cards",
60
+ "google_geocoders",
61
+ "imports",
62
+ "in_stock_subscriptions",
63
+ "inventory_models",
64
+ "inventory_return_locations",
65
+ "inventory_stock_locations",
66
+ "klarna_gateways",
67
+ "klarna_payments",
68
+ "line_item_options",
69
+ "line_items",
70
+ "links",
71
+ "manual_gateways",
72
+ "manual_tax_calculators",
73
+ "markets",
74
+ "merchants",
75
+ "notifications",
76
+ "order_amount_promotion_rules",
77
+ "order_copies",
78
+ "order_factories",
79
+ "order_subscription_items",
80
+ "order_subscriptions",
81
+ "orders",
82
+ "organizations",
83
+ "packages",
84
+ "parcel_line_items",
85
+ "parcels",
86
+ "payment_gateways",
87
+ "payment_methods",
88
+ "payment_options",
89
+ "paypal_gateways",
90
+ "paypal_payments",
91
+ "percentage_discount_promotions",
92
+ "pickups",
93
+ "price_frequency_tiers",
94
+ "price_list_schedulers",
95
+ "price_lists",
96
+ "price_tiers",
97
+ "price_volume_tiers",
98
+ "prices",
99
+ "promotion_rules",
100
+ "promotions",
101
+ "recurring_order_copies",
102
+ "refunds",
103
+ "reserved_stocks",
104
+ "resource_errors",
105
+ "return_line_items",
106
+ "returns",
107
+ "satispay_gateways",
108
+ "satispay_payments",
109
+ "shipments",
110
+ "shipping_categories",
111
+ "shipping_method_tiers",
112
+ "shipping_methods",
113
+ "shipping_weight_tiers",
114
+ "shipping_zones",
115
+ "sku_list_items",
116
+ "sku_list_promotion_rules",
117
+ "sku_lists",
118
+ "sku_options",
119
+ "skus",
120
+ "stock_items",
121
+ "stock_line_items",
122
+ "stock_locations",
123
+ "stock_reservations",
124
+ "stock_transfers",
125
+ "stores",
126
+ "stripe_gateways",
127
+ "stripe_payments",
128
+ "stripe_tax_accounts",
129
+ "subscription_models",
130
+ "tags",
131
+ "talon_one_accounts",
132
+ "tax_calculators",
133
+ "tax_categories",
134
+ "tax_rules",
135
+ "taxjar_accounts",
136
+ "transactions",
137
+ "versions",
138
+ "vertex_accounts",
139
+ "voids",
140
+ "webhooks",
141
+ "wire_transfers"
142
+ // ##__API_RESOURCE_LIST_STOP__##
143
+ ];
144
+ var resourceList = apiResources;
145
+ function getResources(sort) {
146
+ return sort ? [...resourceList].sort() : resourceList;
147
+ }
148
+
149
+ // src/debug.ts
150
+ var debuggerFunction = (_pattern, ..._args) => {
151
+ };
152
+ var debuggerFactory = (_namespace) => debuggerFunction;
153
+ try {
154
+ const debugModule = __require("debug");
155
+ if (debugModule && typeof debugModule === "function") debuggerFactory = debugModule;
156
+ } catch (error) {
157
+ }
158
+ var debugPrefix = "clsdk";
159
+ var debug = (namespace) => {
160
+ return debuggerFactory(`${debugPrefix}:${namespace}`);
161
+ };
162
+ var debug_default = debug;
163
+
164
+ // src/fetch.ts
165
+ var debug2 = debug_default("fetch");
166
+ var FetchError = class _FetchError extends Error {
167
+ static isFetchError = (error) => {
168
+ return error instanceof _FetchError;
169
+ };
170
+ #errors;
171
+ #status;
172
+ #statusText;
173
+ #request;
174
+ constructor(status, statusText, body, request) {
175
+ super(statusText);
176
+ this.#status = status;
177
+ this.#statusText = statusText;
178
+ if (body) this.#errors = body.errors;
179
+ if (request) this.#request = request;
180
+ }
181
+ get errors() {
182
+ return this.#errors;
183
+ }
184
+ get status() {
185
+ return this.#status;
186
+ }
187
+ get statusText() {
188
+ return this.#statusText;
189
+ }
190
+ get request() {
191
+ return this.#request;
192
+ }
193
+ };
194
+ var fetchURL = async (url, requestOptions, clientOptions) => {
195
+ debug2("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
196
+ const interceptors = clientOptions?.interceptors;
197
+ if (interceptors?.request?.onSuccess) ({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
198
+ const fetchClient = clientOptions?.fetch || fetch;
199
+ let response = await fetchClient(url, requestOptions);
200
+ if (response.ok) {
201
+ if (interceptors?.rawReader?.onSuccess) await interceptors.rawReader.onSuccess(response);
202
+ if (interceptors?.response?.onSuccess) response = await interceptors.response.onSuccess(response);
203
+ } else {
204
+ if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
205
+ }
206
+ const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
207
+ debug2("response: %O", json);
208
+ return json;
209
+ }).catch((err) => {
210
+ debug2("error: %s", err.message);
211
+ if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: "parse" /* PARSE */ });
212
+ }) : void 0;
213
+ if (!response.ok) {
214
+ let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
215
+ if (interceptors?.response?.onFailure) error = await interceptors.response.onFailure(error);
216
+ if (error) throw error;
217
+ }
218
+ return responseBody;
219
+ };
220
+
221
+ // src/error.ts
222
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
223
+ ErrorType2["CLIENT"] = "client";
224
+ ErrorType2["REQUEST"] = "request";
225
+ ErrorType2["RESPONSE"] = "response";
226
+ ErrorType2["CANCEL"] = "cancel";
227
+ ErrorType2["PARSE"] = "parse";
228
+ ErrorType2["TIMEOUT"] = "timeout";
229
+ ErrorType2["TOKEN_REFRESH"] = "token-refresh";
230
+ return ErrorType2;
231
+ })(ErrorType || {});
232
+ var SdkError = class _SdkError extends Error {
233
+ static NAME = "SdkError";
234
+ static isSdkError(error) {
235
+ return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
236
+ }
237
+ type;
238
+ code;
239
+ source;
240
+ constructor(error) {
241
+ super(error.message);
242
+ this.name = _SdkError.NAME;
243
+ this.type = error.type || "client" /* CLIENT */;
244
+ }
245
+ };
246
+ var ApiError = class _ApiError extends SdkError {
247
+ static NAME = "ApiError";
248
+ static isApiError(error) {
249
+ return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
250
+ }
251
+ errors = [];
252
+ status;
253
+ statusText;
254
+ // constructor(error: SdkError)
255
+ constructor(error) {
256
+ super({ ...error, type: "response" /* RESPONSE */ });
257
+ this.name = _ApiError.NAME;
258
+ }
259
+ first() {
260
+ return this.errors?.length > 0 ? this.errors[0] : void 0;
261
+ }
262
+ };
263
+ var isRequestError = (error) => {
264
+ return error instanceof TypeError && error.message !== "fetch failed";
265
+ };
266
+ var isCancelError = (error) => {
267
+ return error instanceof DOMException && error.name === "AbortError";
268
+ };
269
+ var isTimeoutError = (error) => {
270
+ return error instanceof DOMException && error.name === "TimeoutError";
271
+ };
272
+ var isExpiredTokenError = (error) => {
273
+ const invalidTokenCodes = [
274
+ "INVALID_TOKEN"
275
+ /*, 'UNAUTHORIZED' */
276
+ ];
277
+ return ApiError.isApiError(error) && error.status === 401 && (invalidTokenCodes.includes(error.code || "") || error.errors && error.errors.length > 0 && invalidTokenCodes.includes(error.errors[0].code));
278
+ };
279
+ var handleError = (error) => {
280
+ if (SdkError.isSdkError(error) || ApiError.isApiError(error)) throw error;
281
+ let sdkError = new SdkError({ message: error.message });
282
+ if (FetchError.isFetchError(error)) {
283
+ const apiError = new ApiError(sdkError);
284
+ apiError.type = "response" /* RESPONSE */;
285
+ apiError.status = error.status;
286
+ apiError.statusText = error.statusText;
287
+ apiError.code = String(apiError.status);
288
+ apiError.errors = error.errors || [];
289
+ if (!apiError.message && apiError.statusText) apiError.message = apiError.statusText;
290
+ sdkError = apiError;
291
+ } else if (isRequestError(error)) {
292
+ sdkError.type = "request" /* REQUEST */;
293
+ } else if (isCancelError(error)) {
294
+ sdkError.type = "cancel" /* CANCEL */;
295
+ } else if (isTimeoutError(error)) {
296
+ sdkError.type = "timeout" /* TIMEOUT */;
297
+ } else {
298
+ sdkError.type = "client" /* CLIENT */;
299
+ sdkError.source = error;
300
+ }
301
+ throw sdkError;
302
+ };
303
+ function isApiError(error) {
304
+ return ApiError.isApiError(error);
305
+ }
306
+
307
+ // src/config.ts
308
+ var config = {
309
+ default: {
310
+ domain: "commercelayer.io",
311
+ pageNumber: 1,
312
+ pageSize: 10
313
+ },
314
+ client: {
315
+ timeout: 15e3,
316
+ requiredAttributes: ["organization", "accessToken"]
317
+ },
318
+ jsonapi: {
319
+ maxResourceIncluded: 2
320
+ }
321
+ };
322
+ var config_default = config;
323
+
324
+ // src/util.ts
325
+ var extractTokenData = (token) => {
326
+ try {
327
+ const data = JSON.parse(atob(token.split(".")[1]));
328
+ return {
329
+ organization: data.organization.slug,
330
+ domain: data.iss ? String(data.iss).replace("https://auth.", "") : void 0,
331
+ expiration: data.exp
332
+ };
333
+ } catch (err) {
334
+ return void 0;
335
+ }
336
+ };
337
+ var isTokenExpired = (token) => {
338
+ try {
339
+ const tokenData = extractTokenData(token);
340
+ return tokenData?.expiration ? tokenData.expiration * 1e3 - Date.now() < 0 : false;
341
+ } catch (err) {
342
+ return false;
343
+ }
344
+ };
345
+
346
+ // src/client.ts
347
+ var debug3 = debug_default("client");
348
+ var baseURL = (organization, domain) => {
349
+ return `https://${organization.toLowerCase()}.${domain || config_default.default.domain}/api`;
350
+ };
351
+ var ApiClient = class _ApiClient {
352
+ static create(options) {
353
+ if ((!options.organization || !options.domain) && options.accessToken) {
354
+ const tokenData = extractTokenData(options.accessToken);
355
+ if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
356
+ if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
357
+ }
358
+ for (const attr of config_default.client.requiredAttributes)
359
+ if (!options[attr]) throw new SdkError({ message: `Undefined '${attr}' parameter` });
360
+ return new _ApiClient(options);
361
+ }
362
+ #baseUrl;
363
+ #accessToken;
364
+ #organization;
365
+ #domain;
366
+ #clientConfig;
367
+ #interceptors;
368
+ constructor(options) {
369
+ debug3("new client instance %O", options);
370
+ this.#baseUrl = baseURL(options.organization ?? "", options.domain);
371
+ this.#accessToken = options.accessToken;
372
+ this.#organization = options.organization ?? "";
373
+ this.#domain = options.domain;
374
+ const fetchConfig = {
375
+ timeout: options.timeout || config_default.client.timeout,
376
+ fetch: options.fetch,
377
+ refreshToken: options.refreshToken
378
+ };
379
+ const customHeaders = this.customHeaders(options.headers);
380
+ const headers = {
381
+ ...customHeaders,
382
+ "Accept": "application/vnd.api+json",
383
+ "Content-Type": "application/vnd.api+json",
384
+ "Authorization": "Bearer " + this.#accessToken
385
+ };
386
+ if (options.userAgent) headers["User-Agent"] = options.userAgent;
387
+ fetchConfig.headers = headers;
388
+ this.#clientConfig = fetchConfig;
389
+ debug3("fetch config: %O", fetchConfig);
390
+ this.#interceptors = {};
391
+ }
392
+ get interceptors() {
393
+ return this.#interceptors;
394
+ }
395
+ get requestHeaders() {
396
+ if (!this.#clientConfig.headers) this.#clientConfig.headers = {};
397
+ return this.#clientConfig.headers;
398
+ }
399
+ /*
400
+ set requestHeaders(headers: RequestHeaders) {
401
+ this.#clientConfig.headers = { ...this.#clientConfig.headers, ...headers }
402
+ }
403
+ */
404
+ config(config2) {
405
+ debug3("config %o", config2);
406
+ const def = this.#clientConfig;
407
+ if (!def.headers) def.headers = {};
408
+ if (config2.timeout) def.timeout = config2.timeout;
409
+ if (config2.userAgent) this.userAgent(config2.userAgent);
410
+ if (config2.fetch) this.#clientConfig.fetch = config2.fetch;
411
+ if (config2.refreshToken) this.#clientConfig.refreshToken = config2.refreshToken;
412
+ if (config2.organization || config2.domain) this.#baseUrl = baseURL(config2.organization || this.#organization, config2.domain || this.#domain);
413
+ if (config2.organization) this.#organization = config2.organization;
414
+ if (config2.domain) this.#domain = config2.domain;
415
+ if (config2.accessToken) {
416
+ this.#accessToken = config2.accessToken;
417
+ def.headers.Authorization = "Bearer " + this.#accessToken;
418
+ }
419
+ if (config2.headers) def.headers = { ...def.headers, ...this.customHeaders(config2.headers) };
420
+ return this;
421
+ }
422
+ userAgent(userAgent) {
423
+ if (userAgent) this.requestHeaders["User-Agent"] = userAgent;
424
+ return this;
425
+ }
426
+ async request(method, path, body, options) {
427
+ debug3("request %s %s, %O, %O", method, path, body || {}, options || {});
428
+ if (options?.userAgent) debug3("User-Agent header ignored in request config");
429
+ const baseUrl = options?.organization ? baseURL(options.organization, options.domain) : this.#baseUrl;
430
+ const url = new URL(`${baseUrl}/${path}`);
431
+ const bodyData = body ? JSON.stringify({ data: body }) : void 0;
432
+ const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
433
+ const accessToken = options?.accessToken || this.#accessToken;
434
+ if (accessToken) headers.Authorization = "Bearer " + accessToken;
435
+ const refreshToken = options?.refreshToken || this.#clientConfig.refreshToken;
436
+ const fetchFunction = options?.fetch || this.#clientConfig.fetch;
437
+ const requestOptions = { method, body: bodyData, headers };
438
+ const timeout = options?.timeout || this.#clientConfig.timeout;
439
+ if (timeout) {
440
+ if (AbortSignal?.timeout) requestOptions.signal = AbortSignal.timeout(timeout);
441
+ else debug3("Timeout not set. Undefined function: %s", "AbortSignal.timeout");
442
+ }
443
+ if (options?.params) Object.entries(options?.params).forEach(([name, value]) => {
444
+ url.searchParams.append(name, String(value));
445
+ });
446
+ const clientOptions = {
447
+ interceptors: this.interceptors,
448
+ fetch: fetchFunction
449
+ };
450
+ try {
451
+ return await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
452
+ } catch (err) {
453
+ if (isExpiredTokenError(err) && refreshToken && isTokenExpired(accessToken)) {
454
+ debug3("Access token has expired");
455
+ const newAccessToken = await refreshToken(this.#accessToken).catch((e) => {
456
+ debug3("Refresh token error: %s", e.message);
457
+ const tokenError = new SdkError({ message: "Error refreshing access token", type: "token-refresh" /* TOKEN_REFRESH */ });
458
+ tokenError.source = e;
459
+ throw tokenError;
460
+ });
461
+ if (newAccessToken) {
462
+ debug3("Access token refreshed");
463
+ this.config({ accessToken: newAccessToken });
464
+ this.#accessToken = newAccessToken;
465
+ if (requestOptions.headers) requestOptions.headers.Authorization = `Bearer ${newAccessToken}`;
466
+ const response = await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
467
+ return response;
468
+ }
469
+ } else throw err;
470
+ }
471
+ }
472
+ customHeaders(headers) {
473
+ const customHeaders = {};
474
+ if (headers) {
475
+ for (const [name, value] of Object.entries(headers))
476
+ if (!["accept", "content-type", "authorization", "user-agent"].includes(name.toLowerCase())) customHeaders[name] = value;
477
+ }
478
+ return customHeaders;
479
+ }
480
+ get currentAccessToken() {
481
+ return this.#accessToken;
482
+ }
483
+ get currentOrganization() {
484
+ return this.#organization;
485
+ }
486
+ };
487
+ var client_default = ApiClient;
488
+
489
+ // src/common.ts
490
+ var isResourceId = (resource) => {
491
+ return resource?.type && resource.id && resourceList.includes(resource.type);
492
+ };
493
+ var isResourceType = (resource) => {
494
+ return resource && typeof resource.type !== "undefined" && resource.type && resourceList.includes(resource.type);
495
+ };
496
+
497
+ // src/jsonapi.ts
498
+ var debug4 = debug_default("jsonapi");
499
+ var denormalize = (response) => {
500
+ if (!response) return response;
501
+ let denormalizedResponse;
502
+ if (response.links) delete response.links;
503
+ const data = response.data;
504
+ const included = response.included;
505
+ if (!data) denormalizedResponse = data;
506
+ else {
507
+ if (Array.isArray(data)) denormalizedResponse = data.map((res) => denormalizeResource(res, included));
508
+ else denormalizedResponse = denormalizeResource(data, included);
509
+ }
510
+ return denormalizedResponse;
511
+ };
512
+ var findIncluded = (rel, included = []) => {
513
+ const inc = included.find((inc2) => {
514
+ return rel.id === inc2.id && rel.type === inc2.type;
515
+ });
516
+ return inc || rel;
517
+ };
518
+ var denormalizeResource = (res, included, chain = []) => {
519
+ debug4("denormalize resource: %O, %o", res, included || {});
520
+ if (!res) return res;
521
+ const resource = {
522
+ id: res.id,
523
+ type: res.type,
524
+ ...res.attributes
525
+ };
526
+ if (res.relationships) Object.keys(res.relationships).forEach((key) => {
527
+ const rel = res.relationships[key].data;
528
+ if (rel) {
529
+ if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config_default.jsonapi.maxResourceIncluded) resource[key] = rel;
530
+ else {
531
+ if (Array.isArray(rel)) resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
532
+ else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
533
+ }
534
+ } else if (rel === null) resource[key] = null;
535
+ });
536
+ debug4("denormalized resource: %O", resource);
537
+ return resource;
538
+ };
539
+ var normalize = (resource) => {
540
+ debug4("normalize resource: %O", resource);
541
+ const attributes = {};
542
+ const relationships = {};
543
+ for (const field in resource) {
544
+ if (["type", "id"].includes(field)) continue;
545
+ const value = resource[field];
546
+ if (Array.isArray(value) && value.length === 1 && isResourceType(value[0]) && value[0].id === null) {
547
+ relationships[field] = { data: [] };
548
+ } else if (value && isResourceType(value) && value.id === null) {
549
+ relationships[field] = { data: null };
550
+ } else if (value && (isResourceId(value) || Array.isArray(value) && isResourceId(value[0]))) {
551
+ relationships[field] = { data: value };
552
+ } else attributes[field] = value;
553
+ }
554
+ const normalized = {
555
+ type: resource.type,
556
+ attributes,
557
+ relationships
558
+ };
559
+ if (isResourceId(resource)) normalized.id = resource.id;
560
+ debug4("normalized resource: %O", normalized);
561
+ return normalized;
562
+ };
563
+
564
+ // src/query.ts
565
+ var debug5 = debug_default("query");
566
+ var arrayFilters = ["_any", "_all", "_in", "_not_in_or_null"];
567
+ var isArrayFilter = (filter) => {
568
+ return arrayFilters.some((f) => filter.endsWith(f));
569
+ };
570
+ var objectFilters = ["_jcont"];
571
+ var isObjectFilter = (filter) => {
572
+ return objectFilters.some((f) => filter.endsWith(f));
573
+ };
574
+ var isParamsList = (params) => {
575
+ return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
576
+ };
577
+ var generateQueryStringParams = (params, res) => {
578
+ debug5("generate query string params: %O, %O", params, res);
579
+ const qp = {};
580
+ if (!params) return qp;
581
+ if (params.include) qp.include = params.include.join(",");
582
+ if (params.fields) {
583
+ if (Array.isArray(params.fields)) params.fields = { [res.type || res]: params.fields };
584
+ Object.entries(params.fields).forEach(([p, v]) => {
585
+ qp[`fields[${p}]`] = v.join(",");
586
+ });
587
+ }
588
+ if (isParamsList(params)) {
589
+ if (params.sort) {
590
+ if (Array.isArray(params.sort)) qp.sort = params.sort.join(",");
591
+ else qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === "desc" ? "-" : ""}${k}`).join(",");
592
+ }
593
+ if (params.pageNumber) qp["page[number]"] = String(params.pageNumber);
594
+ if (params.pageSize) qp["page[size]"] = String(params.pageSize);
595
+ if (params.filters) {
596
+ Object.entries(params.filters).forEach(([p, v]) => {
597
+ let val;
598
+ if (Array.isArray(v)) {
599
+ if (!isArrayFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`, type: "request" /* REQUEST */ });
600
+ val = v.join(",");
601
+ } else if (typeof v === "object") {
602
+ if (!isObjectFilter(p)) throw new SdkError({ message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`, type: "request" /* REQUEST */ });
603
+ val = JSON.stringify(v);
604
+ } else val = String(v);
605
+ qp[`filter[q][${p}]`] = val;
606
+ });
607
+ }
608
+ }
609
+ debug5("query string params: %O", qp);
610
+ return qp;
611
+ };
612
+
613
+ // src/resource.ts
614
+ var debug6 = debug_default("resource");
615
+ var ListResponse = class extends Array {
616
+ meta;
617
+ constructor(meta, data) {
618
+ super(...data || []);
619
+ this.meta = meta;
620
+ }
621
+ first() {
622
+ return this.length ? this[0] : void 0;
623
+ }
624
+ last() {
625
+ return this.length ? this[this.length - 1] : void 0;
626
+ }
627
+ get(index) {
628
+ return this.length && index >= 0 ? this[index] : void 0;
14
629
  }
630
+ hasNextPage() {
631
+ return this.meta.currentPage < this.meta.pageCount;
632
+ }
633
+ hasPrevPage() {
634
+ return this.meta.currentPage > 1;
635
+ }
636
+ getRecordCount() {
637
+ return this.meta.recordCount;
638
+ }
639
+ getPageCount() {
640
+ return this.meta.pageCount;
641
+ }
642
+ get recordCount() {
643
+ return this.meta.recordCount;
644
+ }
645
+ get pageCount() {
646
+ return this.meta.pageCount;
647
+ }
648
+ };
649
+ var ApiResourceAdapter = class _ApiResourceAdapter {
650
+ static adapter;
651
+ constructor() {
652
+ }
653
+ static init(config2) {
654
+ return _ApiResourceAdapter.adapter = new ResourceAdapter(config2);
655
+ }
656
+ static get(config2) {
657
+ if (config2) return _ApiResourceAdapter.init(config2);
658
+ else {
659
+ if (_ApiResourceAdapter.adapter) return _ApiResourceAdapter.adapter;
660
+ else throw new SdkError({ message: "Commerce Layer not initialized" });
661
+ }
662
+ }
663
+ static config(config2) {
664
+ _ApiResourceAdapter.get().config(config2);
665
+ }
666
+ };
667
+ var ResourceAdapter = class {
668
+ #client;
669
+ #config = {};
670
+ constructor(config2) {
671
+ this.#client = client_default.create(config2);
672
+ this.localConfig(config2);
673
+ }
674
+ localConfig(config2) {
675
+ }
676
+ config(config2) {
677
+ debug6("config %o", config2);
678
+ this.localConfig(config2);
679
+ this.#client.config(config2);
680
+ return this;
681
+ }
682
+ get client() {
683
+ return this.#client;
684
+ }
685
+ async singleton(resource, params, options, path) {
686
+ debug6("singleton: %o, %O, %O", resource, params || {}, options || {});
687
+ const queryParams = generateQueryStringParams(params, resource);
688
+ if (options?.params) Object.assign(queryParams, options?.params);
689
+ const res = await this.#client.request("GET", `${path || resource.type}`, void 0, { ...options, params: queryParams });
690
+ const r = denormalize(res);
691
+ return r;
692
+ }
693
+ async retrieve(resource, params, options) {
694
+ debug6("retrieve: %o, %O, %O", resource, params || {}, options || {});
695
+ const queryParams = generateQueryStringParams(params, resource);
696
+ if (options?.params) Object.assign(queryParams, options?.params);
697
+ const res = await this.#client.request("GET", `${resource.type}/${resource.id}`, void 0, { ...options, params: queryParams });
698
+ const r = denormalize(res);
699
+ return r;
700
+ }
701
+ async list(resource, params, options) {
702
+ debug6("list: %o, %O, %O", resource, params || {}, options || {});
703
+ const queryParams = generateQueryStringParams(params, resource);
704
+ if (options?.params) Object.assign(queryParams, options?.params);
705
+ if (!queryParams["page[number]"]) queryParams["page[number]"] = "1";
706
+ const res = await this.#client.request("GET", `${resource.type}`, void 0, { ...options, params: queryParams });
707
+ const r = denormalize(res);
708
+ const meta = {
709
+ pageCount: Number(res.meta?.page_count),
710
+ recordCount: Number(res.meta?.record_count),
711
+ currentPage: params?.pageNumber || config_default.default.pageNumber,
712
+ recordsPerPage: params?.pageSize || config_default.default.pageSize
713
+ };
714
+ return new ListResponse(meta, r);
715
+ }
716
+ async create(resource, params, options) {
717
+ debug6("create: %o, %O, %O", resource, params || {}, options || {});
718
+ const queryParams = generateQueryStringParams(params, resource);
719
+ if (options?.params) Object.assign(queryParams, options?.params);
720
+ const data = normalize(resource);
721
+ const res = await this.#client.request("POST", resource.type, data, { ...options, params: queryParams });
722
+ const r = denormalize(res);
723
+ return r;
724
+ }
725
+ async update(resource, params, options) {
726
+ debug6("update: %o, %O, %O", resource, params || {}, options || {});
727
+ const queryParams = generateQueryStringParams(params, resource);
728
+ if (options?.params) Object.assign(queryParams, options?.params);
729
+ const data = normalize(resource);
730
+ const res = await this.#client.request("PATCH", `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
731
+ const r = denormalize(res);
732
+ return r;
733
+ }
734
+ async delete(resource, options) {
735
+ debug6("delete: %o, %O", resource, options || {});
736
+ await this.#client.request("DELETE", `${resource.type}/${resource.id}`, void 0, options);
737
+ }
738
+ async fetch(resource, path, params, options) {
739
+ debug6("fetch: %o, %O, %O", path, params || {}, options || {});
740
+ const queryParams = generateQueryStringParams(params, resource);
741
+ if (options?.params) Object.assign(queryParams, options?.params);
742
+ const res = await this.#client.request("GET", path, void 0, { ...options, params: queryParams });
743
+ const r = denormalize(res);
744
+ if (Array.isArray(r)) {
745
+ const p = params;
746
+ const meta = {
747
+ pageCount: Number(res.meta?.page_count),
748
+ recordCount: Number(res.meta?.record_count),
749
+ currentPage: p?.pageNumber || config_default.default.pageNumber,
750
+ recordsPerPage: p?.pageSize || config_default.default.pageSize
751
+ };
752
+ return new ListResponse(meta, r);
753
+ } else return r;
754
+ }
755
+ };
756
+
757
+ // src/commercelayer.ts
758
+ var debug7 = debug_default("commercelayer");
759
+ var OPEN_API_SCHEMA_VERSION = "7.8.3";
760
+ var CommerceLayerClient = class _CommerceLayerClient {
15
761
  static get openApiSchemaVersion() {
16
762
  return OPEN_API_SCHEMA_VERSION;
17
763
  }
764
+ openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
765
+ static cl;
18
766
  // ##__CL_RESOURCES_DEF_START__##
19
767
  // ##__CL_RESOURCES_DEF_TEMPLATE:: ##__TAB__#####__RESOURCE_TYPE__##?: api.##__RESOURCE_CLASS__##
20
768
  // ##__CL_RESOURCES_DEF_STOP__##
21
- static get(config) {
22
- if (config) return _CommerceLayerClient.cl = new _CommerceLayerClient(config);
769
+ static get(config2) {
770
+ if (config2) return _CommerceLayerClient.cl = new _CommerceLayerClient(config2);
23
771
  else if (!_CommerceLayerClient.cl) throw new Error("CommerceLayer client not initialized");
24
772
  return _CommerceLayerClient.cl;
25
773
  }
774
+ constructor(config2) {
775
+ debug7("new commercelayer instance %O", config2);
776
+ ApiResourceAdapter.init(config2);
777
+ }
26
778
  // ##__CL_RESOURCES_LEAZY_LOADING_START__##
27
779
  // ##__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)) }
28
780
  // ##__CL_RESOURCES_LEAZY_LOADING_STOP__##
@@ -36,12 +788,12 @@ const _CommerceLayerClient = class _CommerceLayerClient {
36
788
  get interceptors() {
37
789
  return ApiResourceAdapter.get().client?.interceptors;
38
790
  }
39
- localConfig(config) {
791
+ localConfig(config2) {
40
792
  }
41
- config(config) {
42
- debug("config %o", config);
43
- this.localConfig(config);
44
- ApiResourceAdapter.config(config);
793
+ config(config2) {
794
+ debug7("config %o", config2);
795
+ this.localConfig(config2);
796
+ ApiResourceAdapter.config(config2);
45
797
  return this;
46
798
  }
47
799
  resources(sort) {
@@ -94,10 +846,8 @@ const _CommerceLayerClient = class _CommerceLayerClient {
94
846
  this.interceptors.rawReader = void 0;
95
847
  }
96
848
  };
97
- __publicField(_CommerceLayerClient, "cl");
98
- let CommerceLayerClient = _CommerceLayerClient;
99
- const CommerceLayer = (config) => {
100
- return CommerceLayerClient.get(config);
849
+ var CommerceLayer = (config2) => {
850
+ return CommerceLayerClient.get(config2);
101
851
  };
102
852
  var commercelayer_default = CommerceLayer;
103
853