@commercelayer/sdk 6.0.0-alfa.1 → 6.0.0-alfa.11

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 (537) hide show
  1. package/lib/cjs/api.d.ts +0 -3
  2. package/lib/cjs/api.js +0 -10
  3. package/lib/cjs/client.d.ts +6 -14
  4. package/lib/cjs/client.js +39 -73
  5. package/lib/cjs/commercelayer.d.ts +128 -127
  6. package/lib/cjs/commercelayer.js +268 -156
  7. package/lib/cjs/common.js +0 -11
  8. package/lib/cjs/config.d.ts +3 -0
  9. package/lib/cjs/config.js +3 -2
  10. package/lib/cjs/debug.js +0 -21
  11. package/lib/cjs/error.d.ts +6 -7
  12. package/lib/cjs/error.js +35 -33
  13. package/lib/cjs/fetch.d.ts +13 -0
  14. package/lib/cjs/fetch.js +67 -0
  15. package/lib/cjs/index.js +0 -2
  16. package/lib/cjs/interceptor.d.ts +24 -12
  17. package/lib/cjs/jsonapi.js +10 -7
  18. package/lib/cjs/model.d.ts +0 -3
  19. package/lib/cjs/model.js +0 -1
  20. package/lib/cjs/query.d.ts +3 -2
  21. package/lib/cjs/query.js +25 -7
  22. package/lib/cjs/resource.d.ts +4 -4
  23. package/lib/cjs/resource.js +14 -30
  24. package/lib/cjs/resources/addresses.d.ts +1 -0
  25. package/lib/cjs/resources/addresses.js +4 -1
  26. package/lib/cjs/resources/adjustments.d.ts +1 -0
  27. package/lib/cjs/resources/adjustments.js +4 -1
  28. package/lib/cjs/resources/adyen_gateways.d.ts +1 -0
  29. package/lib/cjs/resources/adyen_gateways.js +4 -1
  30. package/lib/cjs/resources/adyen_payments.d.ts +1 -0
  31. package/lib/cjs/resources/adyen_payments.js +4 -1
  32. package/lib/cjs/resources/application.d.ts +1 -0
  33. package/lib/cjs/resources/application.js +4 -1
  34. package/lib/cjs/resources/attachments.d.ts +1 -0
  35. package/lib/cjs/resources/attachments.js +4 -1
  36. package/lib/cjs/resources/authorizations.d.ts +1 -0
  37. package/lib/cjs/resources/authorizations.js +4 -1
  38. package/lib/cjs/resources/avalara_accounts.d.ts +1 -0
  39. package/lib/cjs/resources/avalara_accounts.js +4 -1
  40. package/lib/cjs/resources/axerve_gateways.d.ts +1 -0
  41. package/lib/cjs/resources/axerve_gateways.js +4 -1
  42. package/lib/cjs/resources/axerve_payments.d.ts +1 -0
  43. package/lib/cjs/resources/axerve_payments.js +4 -1
  44. package/lib/cjs/resources/billing_info_validation_rules.d.ts +1 -0
  45. package/lib/cjs/resources/billing_info_validation_rules.js +4 -1
  46. package/lib/cjs/resources/bing_geocoders.d.ts +1 -0
  47. package/lib/cjs/resources/bing_geocoders.js +4 -1
  48. package/lib/cjs/resources/braintree_gateways.d.ts +1 -0
  49. package/lib/cjs/resources/braintree_gateways.js +4 -1
  50. package/lib/cjs/resources/braintree_payments.d.ts +1 -0
  51. package/lib/cjs/resources/braintree_payments.js +4 -1
  52. package/lib/cjs/resources/bundles.d.ts +1 -0
  53. package/lib/cjs/resources/bundles.js +4 -1
  54. package/lib/cjs/resources/buy_x_pay_y_promotions.d.ts +1 -0
  55. package/lib/cjs/resources/buy_x_pay_y_promotions.js +4 -1
  56. package/lib/cjs/resources/captures.d.ts +1 -0
  57. package/lib/cjs/resources/captures.js +4 -1
  58. package/lib/cjs/resources/carrier_accounts.d.ts +1 -0
  59. package/lib/cjs/resources/carrier_accounts.js +4 -1
  60. package/lib/cjs/resources/checkout_com_gateways.d.ts +1 -0
  61. package/lib/cjs/resources/checkout_com_gateways.js +4 -1
  62. package/lib/cjs/resources/checkout_com_payments.d.ts +1 -0
  63. package/lib/cjs/resources/checkout_com_payments.js +4 -1
  64. package/lib/cjs/resources/cleanups.d.ts +1 -0
  65. package/lib/cjs/resources/cleanups.js +4 -1
  66. package/lib/cjs/resources/coupon_codes_promotion_rules.d.ts +1 -0
  67. package/lib/cjs/resources/coupon_codes_promotion_rules.js +4 -1
  68. package/lib/cjs/resources/coupon_recipients.d.ts +1 -0
  69. package/lib/cjs/resources/coupon_recipients.js +4 -1
  70. package/lib/cjs/resources/coupons.d.ts +1 -0
  71. package/lib/cjs/resources/coupons.js +4 -1
  72. package/lib/cjs/resources/custom_promotion_rules.d.ts +1 -0
  73. package/lib/cjs/resources/custom_promotion_rules.js +4 -1
  74. package/lib/cjs/resources/customer_addresses.d.ts +1 -0
  75. package/lib/cjs/resources/customer_addresses.js +4 -1
  76. package/lib/cjs/resources/customer_groups.d.ts +1 -0
  77. package/lib/cjs/resources/customer_groups.js +4 -1
  78. package/lib/cjs/resources/customer_password_resets.d.ts +1 -0
  79. package/lib/cjs/resources/customer_password_resets.js +4 -1
  80. package/lib/cjs/resources/customer_payment_sources.d.ts +1 -0
  81. package/lib/cjs/resources/customer_payment_sources.js +4 -1
  82. package/lib/cjs/resources/customer_subscriptions.d.ts +1 -0
  83. package/lib/cjs/resources/customer_subscriptions.js +4 -1
  84. package/lib/cjs/resources/customers.d.ts +1 -0
  85. package/lib/cjs/resources/customers.js +4 -1
  86. package/lib/cjs/resources/delivery_lead_times.d.ts +1 -0
  87. package/lib/cjs/resources/delivery_lead_times.js +4 -1
  88. package/lib/cjs/resources/event_callbacks.d.ts +1 -0
  89. package/lib/cjs/resources/event_callbacks.js +4 -1
  90. package/lib/cjs/resources/events.d.ts +4 -3
  91. package/lib/cjs/resources/events.js +8 -5
  92. package/lib/cjs/resources/exports.d.ts +1 -0
  93. package/lib/cjs/resources/exports.js +4 -1
  94. package/lib/cjs/resources/external_gateways.d.ts +1 -0
  95. package/lib/cjs/resources/external_gateways.js +4 -1
  96. package/lib/cjs/resources/external_payments.d.ts +1 -0
  97. package/lib/cjs/resources/external_payments.js +4 -1
  98. package/lib/cjs/resources/external_promotions.d.ts +1 -0
  99. package/lib/cjs/resources/external_promotions.js +4 -1
  100. package/lib/cjs/resources/external_tax_calculators.d.ts +1 -0
  101. package/lib/cjs/resources/external_tax_calculators.js +4 -1
  102. package/lib/cjs/resources/fixed_amount_promotions.d.ts +1 -0
  103. package/lib/cjs/resources/fixed_amount_promotions.js +4 -1
  104. package/lib/cjs/resources/fixed_price_promotions.d.ts +1 -0
  105. package/lib/cjs/resources/fixed_price_promotions.js +4 -1
  106. package/lib/cjs/resources/free_gift_promotions.d.ts +1 -0
  107. package/lib/cjs/resources/free_gift_promotions.js +4 -1
  108. package/lib/cjs/resources/free_shipping_promotions.d.ts +1 -0
  109. package/lib/cjs/resources/free_shipping_promotions.js +4 -1
  110. package/lib/cjs/resources/geocoders.d.ts +1 -0
  111. package/lib/cjs/resources/geocoders.js +4 -1
  112. package/lib/cjs/resources/gift_card_recipients.d.ts +1 -0
  113. package/lib/cjs/resources/gift_card_recipients.js +4 -1
  114. package/lib/cjs/resources/gift_cards.d.ts +1 -0
  115. package/lib/cjs/resources/gift_cards.js +4 -1
  116. package/lib/cjs/resources/google_geocoders.d.ts +1 -0
  117. package/lib/cjs/resources/google_geocoders.js +4 -1
  118. package/lib/cjs/resources/imports.d.ts +1 -0
  119. package/lib/cjs/resources/imports.js +4 -1
  120. package/lib/cjs/resources/in_stock_subscriptions.d.ts +1 -0
  121. package/lib/cjs/resources/in_stock_subscriptions.js +4 -1
  122. package/lib/cjs/resources/inventory_models.d.ts +1 -0
  123. package/lib/cjs/resources/inventory_models.js +4 -1
  124. package/lib/cjs/resources/inventory_return_locations.d.ts +1 -0
  125. package/lib/cjs/resources/inventory_return_locations.js +4 -1
  126. package/lib/cjs/resources/inventory_stock_locations.d.ts +1 -0
  127. package/lib/cjs/resources/inventory_stock_locations.js +4 -1
  128. package/lib/cjs/resources/klarna_gateways.d.ts +1 -0
  129. package/lib/cjs/resources/klarna_gateways.js +4 -1
  130. package/lib/cjs/resources/klarna_payments.d.ts +1 -0
  131. package/lib/cjs/resources/klarna_payments.js +4 -1
  132. package/lib/cjs/resources/line_item_options.d.ts +1 -0
  133. package/lib/cjs/resources/line_item_options.js +4 -1
  134. package/lib/cjs/resources/line_items.d.ts +1 -0
  135. package/lib/cjs/resources/line_items.js +4 -1
  136. package/lib/cjs/resources/manual_gateways.d.ts +1 -0
  137. package/lib/cjs/resources/manual_gateways.js +4 -1
  138. package/lib/cjs/resources/manual_tax_calculators.d.ts +1 -0
  139. package/lib/cjs/resources/manual_tax_calculators.js +4 -1
  140. package/lib/cjs/resources/markets.d.ts +1 -0
  141. package/lib/cjs/resources/markets.js +4 -1
  142. package/lib/cjs/resources/merchants.d.ts +1 -0
  143. package/lib/cjs/resources/merchants.js +4 -1
  144. package/lib/cjs/resources/order_amount_promotion_rules.d.ts +1 -0
  145. package/lib/cjs/resources/order_amount_promotion_rules.js +4 -1
  146. package/lib/cjs/resources/order_copies.d.ts +1 -0
  147. package/lib/cjs/resources/order_copies.js +4 -1
  148. package/lib/cjs/resources/order_factories.d.ts +1 -0
  149. package/lib/cjs/resources/order_factories.js +4 -1
  150. package/lib/cjs/resources/order_subscription_items.d.ts +1 -0
  151. package/lib/cjs/resources/order_subscription_items.js +4 -1
  152. package/lib/cjs/resources/order_subscriptions.d.ts +1 -0
  153. package/lib/cjs/resources/order_subscriptions.js +4 -1
  154. package/lib/cjs/resources/order_validation_rules.d.ts +1 -0
  155. package/lib/cjs/resources/order_validation_rules.js +4 -1
  156. package/lib/cjs/resources/orders.d.ts +1 -0
  157. package/lib/cjs/resources/orders.js +4 -1
  158. package/lib/cjs/resources/organization.d.ts +2 -0
  159. package/lib/cjs/resources/organization.js +4 -1
  160. package/lib/cjs/resources/packages.d.ts +1 -0
  161. package/lib/cjs/resources/packages.js +4 -1
  162. package/lib/cjs/resources/parcel_line_items.d.ts +1 -0
  163. package/lib/cjs/resources/parcel_line_items.js +4 -1
  164. package/lib/cjs/resources/parcels.d.ts +1 -0
  165. package/lib/cjs/resources/parcels.js +4 -1
  166. package/lib/cjs/resources/payment_gateways.d.ts +1 -0
  167. package/lib/cjs/resources/payment_gateways.js +4 -1
  168. package/lib/cjs/resources/payment_methods.d.ts +1 -0
  169. package/lib/cjs/resources/payment_methods.js +4 -1
  170. package/lib/cjs/resources/payment_options.d.ts +1 -0
  171. package/lib/cjs/resources/payment_options.js +4 -1
  172. package/lib/cjs/resources/paypal_gateways.d.ts +1 -0
  173. package/lib/cjs/resources/paypal_gateways.js +4 -1
  174. package/lib/cjs/resources/paypal_payments.d.ts +1 -0
  175. package/lib/cjs/resources/paypal_payments.js +4 -1
  176. package/lib/cjs/resources/percentage_discount_promotions.d.ts +1 -0
  177. package/lib/cjs/resources/percentage_discount_promotions.js +4 -1
  178. package/lib/cjs/resources/price_frequency_tiers.d.ts +1 -0
  179. package/lib/cjs/resources/price_frequency_tiers.js +4 -1
  180. package/lib/cjs/resources/price_lists.d.ts +1 -0
  181. package/lib/cjs/resources/price_lists.js +4 -1
  182. package/lib/cjs/resources/price_tiers.d.ts +1 -0
  183. package/lib/cjs/resources/price_tiers.js +4 -1
  184. package/lib/cjs/resources/price_volume_tiers.d.ts +1 -0
  185. package/lib/cjs/resources/price_volume_tiers.js +4 -1
  186. package/lib/cjs/resources/prices.d.ts +1 -0
  187. package/lib/cjs/resources/prices.js +4 -1
  188. package/lib/cjs/resources/promotion_rules.d.ts +1 -0
  189. package/lib/cjs/resources/promotion_rules.js +4 -1
  190. package/lib/cjs/resources/promotions.d.ts +1 -0
  191. package/lib/cjs/resources/promotions.js +4 -1
  192. package/lib/cjs/resources/recurring_order_copies.d.ts +1 -0
  193. package/lib/cjs/resources/recurring_order_copies.js +4 -1
  194. package/lib/cjs/resources/refunds.d.ts +1 -0
  195. package/lib/cjs/resources/refunds.js +4 -1
  196. package/lib/cjs/resources/reserved_stocks.d.ts +1 -0
  197. package/lib/cjs/resources/reserved_stocks.js +4 -1
  198. package/lib/cjs/resources/resource_errors.d.ts +1 -0
  199. package/lib/cjs/resources/resource_errors.js +4 -1
  200. package/lib/cjs/resources/return_line_items.d.ts +1 -0
  201. package/lib/cjs/resources/return_line_items.js +4 -1
  202. package/lib/cjs/resources/returns.d.ts +1 -0
  203. package/lib/cjs/resources/returns.js +4 -1
  204. package/lib/cjs/resources/satispay_gateways.d.ts +1 -0
  205. package/lib/cjs/resources/satispay_gateways.js +4 -1
  206. package/lib/cjs/resources/satispay_payments.d.ts +1 -0
  207. package/lib/cjs/resources/satispay_payments.js +4 -1
  208. package/lib/cjs/resources/shipments.d.ts +4 -0
  209. package/lib/cjs/resources/shipments.js +8 -1
  210. package/lib/cjs/resources/shipping_categories.d.ts +1 -0
  211. package/lib/cjs/resources/shipping_categories.js +4 -1
  212. package/lib/cjs/resources/shipping_method_tiers.d.ts +1 -0
  213. package/lib/cjs/resources/shipping_method_tiers.js +4 -1
  214. package/lib/cjs/resources/shipping_methods.d.ts +1 -0
  215. package/lib/cjs/resources/shipping_methods.js +4 -1
  216. package/lib/cjs/resources/shipping_weight_tiers.d.ts +1 -0
  217. package/lib/cjs/resources/shipping_weight_tiers.js +4 -1
  218. package/lib/cjs/resources/shipping_zones.d.ts +1 -0
  219. package/lib/cjs/resources/shipping_zones.js +4 -1
  220. package/lib/cjs/resources/sku_list_items.d.ts +1 -0
  221. package/lib/cjs/resources/sku_list_items.js +4 -1
  222. package/lib/cjs/resources/sku_list_promotion_rules.d.ts +1 -0
  223. package/lib/cjs/resources/sku_list_promotion_rules.js +4 -1
  224. package/lib/cjs/resources/sku_lists.d.ts +1 -0
  225. package/lib/cjs/resources/sku_lists.js +4 -1
  226. package/lib/cjs/resources/sku_options.d.ts +1 -0
  227. package/lib/cjs/resources/sku_options.js +4 -1
  228. package/lib/cjs/resources/skus.d.ts +1 -0
  229. package/lib/cjs/resources/skus.js +4 -1
  230. package/lib/cjs/resources/stock_items.d.ts +1 -0
  231. package/lib/cjs/resources/stock_items.js +4 -1
  232. package/lib/cjs/resources/stock_line_items.d.ts +1 -0
  233. package/lib/cjs/resources/stock_line_items.js +4 -1
  234. package/lib/cjs/resources/stock_locations.d.ts +1 -0
  235. package/lib/cjs/resources/stock_locations.js +4 -1
  236. package/lib/cjs/resources/stock_reservations.d.ts +1 -0
  237. package/lib/cjs/resources/stock_reservations.js +4 -1
  238. package/lib/cjs/resources/stock_transfers.d.ts +1 -0
  239. package/lib/cjs/resources/stock_transfers.js +4 -1
  240. package/lib/cjs/resources/stripe_gateways.d.ts +1 -0
  241. package/lib/cjs/resources/stripe_gateways.js +4 -1
  242. package/lib/cjs/resources/stripe_payments.d.ts +1 -0
  243. package/lib/cjs/resources/stripe_payments.js +4 -1
  244. package/lib/cjs/resources/subscription_models.d.ts +1 -0
  245. package/lib/cjs/resources/subscription_models.js +4 -1
  246. package/lib/cjs/resources/tags.d.ts +1 -0
  247. package/lib/cjs/resources/tags.js +4 -1
  248. package/lib/cjs/resources/tax_calculators.d.ts +1 -0
  249. package/lib/cjs/resources/tax_calculators.js +4 -1
  250. package/lib/cjs/resources/tax_categories.d.ts +1 -0
  251. package/lib/cjs/resources/tax_categories.js +4 -1
  252. package/lib/cjs/resources/tax_rules.d.ts +1 -0
  253. package/lib/cjs/resources/tax_rules.js +4 -1
  254. package/lib/cjs/resources/taxjar_accounts.d.ts +1 -0
  255. package/lib/cjs/resources/taxjar_accounts.js +4 -1
  256. package/lib/cjs/resources/transactions.d.ts +1 -0
  257. package/lib/cjs/resources/transactions.js +4 -1
  258. package/lib/cjs/resources/versions.d.ts +1 -0
  259. package/lib/cjs/resources/versions.js +4 -1
  260. package/lib/cjs/resources/voids.d.ts +1 -0
  261. package/lib/cjs/resources/voids.js +4 -1
  262. package/lib/cjs/resources/webhooks.d.ts +1 -0
  263. package/lib/cjs/resources/webhooks.js +4 -1
  264. package/lib/cjs/resources/wire_transfers.d.ts +1 -0
  265. package/lib/cjs/resources/wire_transfers.js +4 -1
  266. package/lib/cjs/static.js +0 -1
  267. package/lib/cjs/util.js +0 -1
  268. package/lib/esm/api.d.ts +0 -3
  269. package/lib/esm/api.js +0 -10
  270. package/lib/esm/client.d.ts +6 -14
  271. package/lib/esm/client.js +37 -73
  272. package/lib/esm/commercelayer.d.ts +128 -127
  273. package/lib/esm/commercelayer.js +266 -278
  274. package/lib/esm/common.js +0 -11
  275. package/lib/esm/config.d.ts +3 -0
  276. package/lib/esm/config.js +3 -2
  277. package/lib/esm/debug.js +0 -21
  278. package/lib/esm/error.d.ts +6 -7
  279. package/lib/esm/error.js +35 -31
  280. package/lib/esm/fetch.d.ts +13 -0
  281. package/lib/esm/fetch.js +46 -0
  282. package/lib/esm/index.js +0 -2
  283. package/lib/esm/interceptor.d.ts +24 -12
  284. package/lib/esm/jsonapi.js +10 -7
  285. package/lib/esm/model.d.ts +0 -3
  286. package/lib/esm/model.js +0 -1
  287. package/lib/esm/query.d.ts +3 -2
  288. package/lib/esm/query.js +24 -7
  289. package/lib/esm/resource.d.ts +4 -4
  290. package/lib/esm/resource.js +14 -30
  291. package/lib/esm/resources/addresses.d.ts +1 -0
  292. package/lib/esm/resources/addresses.js +4 -1
  293. package/lib/esm/resources/adjustments.d.ts +1 -0
  294. package/lib/esm/resources/adjustments.js +4 -1
  295. package/lib/esm/resources/adyen_gateways.d.ts +1 -0
  296. package/lib/esm/resources/adyen_gateways.js +4 -1
  297. package/lib/esm/resources/adyen_payments.d.ts +1 -0
  298. package/lib/esm/resources/adyen_payments.js +4 -1
  299. package/lib/esm/resources/application.d.ts +1 -0
  300. package/lib/esm/resources/application.js +4 -1
  301. package/lib/esm/resources/attachments.d.ts +1 -0
  302. package/lib/esm/resources/attachments.js +4 -1
  303. package/lib/esm/resources/authorizations.d.ts +1 -0
  304. package/lib/esm/resources/authorizations.js +4 -1
  305. package/lib/esm/resources/avalara_accounts.d.ts +1 -0
  306. package/lib/esm/resources/avalara_accounts.js +4 -1
  307. package/lib/esm/resources/axerve_gateways.d.ts +1 -0
  308. package/lib/esm/resources/axerve_gateways.js +4 -1
  309. package/lib/esm/resources/axerve_payments.d.ts +1 -0
  310. package/lib/esm/resources/axerve_payments.js +4 -1
  311. package/lib/esm/resources/billing_info_validation_rules.d.ts +1 -0
  312. package/lib/esm/resources/billing_info_validation_rules.js +4 -1
  313. package/lib/esm/resources/bing_geocoders.d.ts +1 -0
  314. package/lib/esm/resources/bing_geocoders.js +4 -1
  315. package/lib/esm/resources/braintree_gateways.d.ts +1 -0
  316. package/lib/esm/resources/braintree_gateways.js +4 -1
  317. package/lib/esm/resources/braintree_payments.d.ts +1 -0
  318. package/lib/esm/resources/braintree_payments.js +4 -1
  319. package/lib/esm/resources/bundles.d.ts +1 -0
  320. package/lib/esm/resources/bundles.js +4 -1
  321. package/lib/esm/resources/buy_x_pay_y_promotions.d.ts +1 -0
  322. package/lib/esm/resources/buy_x_pay_y_promotions.js +4 -1
  323. package/lib/esm/resources/captures.d.ts +1 -0
  324. package/lib/esm/resources/captures.js +4 -1
  325. package/lib/esm/resources/carrier_accounts.d.ts +1 -0
  326. package/lib/esm/resources/carrier_accounts.js +4 -1
  327. package/lib/esm/resources/checkout_com_gateways.d.ts +1 -0
  328. package/lib/esm/resources/checkout_com_gateways.js +4 -1
  329. package/lib/esm/resources/checkout_com_payments.d.ts +1 -0
  330. package/lib/esm/resources/checkout_com_payments.js +4 -1
  331. package/lib/esm/resources/cleanups.d.ts +1 -0
  332. package/lib/esm/resources/cleanups.js +4 -1
  333. package/lib/esm/resources/coupon_codes_promotion_rules.d.ts +1 -0
  334. package/lib/esm/resources/coupon_codes_promotion_rules.js +4 -1
  335. package/lib/esm/resources/coupon_recipients.d.ts +1 -0
  336. package/lib/esm/resources/coupon_recipients.js +4 -1
  337. package/lib/esm/resources/coupons.d.ts +1 -0
  338. package/lib/esm/resources/coupons.js +4 -1
  339. package/lib/esm/resources/custom_promotion_rules.d.ts +1 -0
  340. package/lib/esm/resources/custom_promotion_rules.js +4 -1
  341. package/lib/esm/resources/customer_addresses.d.ts +1 -0
  342. package/lib/esm/resources/customer_addresses.js +4 -1
  343. package/lib/esm/resources/customer_groups.d.ts +1 -0
  344. package/lib/esm/resources/customer_groups.js +4 -1
  345. package/lib/esm/resources/customer_password_resets.d.ts +1 -0
  346. package/lib/esm/resources/customer_password_resets.js +4 -1
  347. package/lib/esm/resources/customer_payment_sources.d.ts +1 -0
  348. package/lib/esm/resources/customer_payment_sources.js +4 -1
  349. package/lib/esm/resources/customer_subscriptions.d.ts +1 -0
  350. package/lib/esm/resources/customer_subscriptions.js +4 -1
  351. package/lib/esm/resources/customers.d.ts +1 -0
  352. package/lib/esm/resources/customers.js +4 -1
  353. package/lib/esm/resources/delivery_lead_times.d.ts +1 -0
  354. package/lib/esm/resources/delivery_lead_times.js +4 -1
  355. package/lib/esm/resources/event_callbacks.d.ts +1 -0
  356. package/lib/esm/resources/event_callbacks.js +4 -1
  357. package/lib/esm/resources/events.d.ts +4 -3
  358. package/lib/esm/resources/events.js +8 -5
  359. package/lib/esm/resources/exports.d.ts +1 -0
  360. package/lib/esm/resources/exports.js +4 -1
  361. package/lib/esm/resources/external_gateways.d.ts +1 -0
  362. package/lib/esm/resources/external_gateways.js +4 -1
  363. package/lib/esm/resources/external_payments.d.ts +1 -0
  364. package/lib/esm/resources/external_payments.js +4 -1
  365. package/lib/esm/resources/external_promotions.d.ts +1 -0
  366. package/lib/esm/resources/external_promotions.js +4 -1
  367. package/lib/esm/resources/external_tax_calculators.d.ts +1 -0
  368. package/lib/esm/resources/external_tax_calculators.js +4 -1
  369. package/lib/esm/resources/fixed_amount_promotions.d.ts +1 -0
  370. package/lib/esm/resources/fixed_amount_promotions.js +4 -1
  371. package/lib/esm/resources/fixed_price_promotions.d.ts +1 -0
  372. package/lib/esm/resources/fixed_price_promotions.js +4 -1
  373. package/lib/esm/resources/free_gift_promotions.d.ts +1 -0
  374. package/lib/esm/resources/free_gift_promotions.js +4 -1
  375. package/lib/esm/resources/free_shipping_promotions.d.ts +1 -0
  376. package/lib/esm/resources/free_shipping_promotions.js +4 -1
  377. package/lib/esm/resources/geocoders.d.ts +1 -0
  378. package/lib/esm/resources/geocoders.js +4 -1
  379. package/lib/esm/resources/gift_card_recipients.d.ts +1 -0
  380. package/lib/esm/resources/gift_card_recipients.js +4 -1
  381. package/lib/esm/resources/gift_cards.d.ts +1 -0
  382. package/lib/esm/resources/gift_cards.js +4 -1
  383. package/lib/esm/resources/google_geocoders.d.ts +1 -0
  384. package/lib/esm/resources/google_geocoders.js +4 -1
  385. package/lib/esm/resources/imports.d.ts +1 -0
  386. package/lib/esm/resources/imports.js +4 -1
  387. package/lib/esm/resources/in_stock_subscriptions.d.ts +1 -0
  388. package/lib/esm/resources/in_stock_subscriptions.js +4 -1
  389. package/lib/esm/resources/inventory_models.d.ts +1 -0
  390. package/lib/esm/resources/inventory_models.js +4 -1
  391. package/lib/esm/resources/inventory_return_locations.d.ts +1 -0
  392. package/lib/esm/resources/inventory_return_locations.js +4 -1
  393. package/lib/esm/resources/inventory_stock_locations.d.ts +1 -0
  394. package/lib/esm/resources/inventory_stock_locations.js +4 -1
  395. package/lib/esm/resources/klarna_gateways.d.ts +1 -0
  396. package/lib/esm/resources/klarna_gateways.js +4 -1
  397. package/lib/esm/resources/klarna_payments.d.ts +1 -0
  398. package/lib/esm/resources/klarna_payments.js +4 -1
  399. package/lib/esm/resources/line_item_options.d.ts +1 -0
  400. package/lib/esm/resources/line_item_options.js +4 -1
  401. package/lib/esm/resources/line_items.d.ts +1 -0
  402. package/lib/esm/resources/line_items.js +4 -1
  403. package/lib/esm/resources/manual_gateways.d.ts +1 -0
  404. package/lib/esm/resources/manual_gateways.js +4 -1
  405. package/lib/esm/resources/manual_tax_calculators.d.ts +1 -0
  406. package/lib/esm/resources/manual_tax_calculators.js +4 -1
  407. package/lib/esm/resources/markets.d.ts +1 -0
  408. package/lib/esm/resources/markets.js +4 -1
  409. package/lib/esm/resources/merchants.d.ts +1 -0
  410. package/lib/esm/resources/merchants.js +4 -1
  411. package/lib/esm/resources/order_amount_promotion_rules.d.ts +1 -0
  412. package/lib/esm/resources/order_amount_promotion_rules.js +4 -1
  413. package/lib/esm/resources/order_copies.d.ts +1 -0
  414. package/lib/esm/resources/order_copies.js +4 -1
  415. package/lib/esm/resources/order_factories.d.ts +1 -0
  416. package/lib/esm/resources/order_factories.js +4 -1
  417. package/lib/esm/resources/order_subscription_items.d.ts +1 -0
  418. package/lib/esm/resources/order_subscription_items.js +4 -1
  419. package/lib/esm/resources/order_subscriptions.d.ts +1 -0
  420. package/lib/esm/resources/order_subscriptions.js +4 -1
  421. package/lib/esm/resources/order_validation_rules.d.ts +1 -0
  422. package/lib/esm/resources/order_validation_rules.js +4 -1
  423. package/lib/esm/resources/orders.d.ts +1 -0
  424. package/lib/esm/resources/orders.js +4 -1
  425. package/lib/esm/resources/organization.d.ts +2 -0
  426. package/lib/esm/resources/organization.js +4 -1
  427. package/lib/esm/resources/packages.d.ts +1 -0
  428. package/lib/esm/resources/packages.js +4 -1
  429. package/lib/esm/resources/parcel_line_items.d.ts +1 -0
  430. package/lib/esm/resources/parcel_line_items.js +4 -1
  431. package/lib/esm/resources/parcels.d.ts +1 -0
  432. package/lib/esm/resources/parcels.js +4 -1
  433. package/lib/esm/resources/payment_gateways.d.ts +1 -0
  434. package/lib/esm/resources/payment_gateways.js +4 -1
  435. package/lib/esm/resources/payment_methods.d.ts +1 -0
  436. package/lib/esm/resources/payment_methods.js +4 -1
  437. package/lib/esm/resources/payment_options.d.ts +1 -0
  438. package/lib/esm/resources/payment_options.js +4 -1
  439. package/lib/esm/resources/paypal_gateways.d.ts +1 -0
  440. package/lib/esm/resources/paypal_gateways.js +4 -1
  441. package/lib/esm/resources/paypal_payments.d.ts +1 -0
  442. package/lib/esm/resources/paypal_payments.js +4 -1
  443. package/lib/esm/resources/percentage_discount_promotions.d.ts +1 -0
  444. package/lib/esm/resources/percentage_discount_promotions.js +4 -1
  445. package/lib/esm/resources/price_frequency_tiers.d.ts +1 -0
  446. package/lib/esm/resources/price_frequency_tiers.js +4 -1
  447. package/lib/esm/resources/price_lists.d.ts +1 -0
  448. package/lib/esm/resources/price_lists.js +4 -1
  449. package/lib/esm/resources/price_tiers.d.ts +1 -0
  450. package/lib/esm/resources/price_tiers.js +4 -1
  451. package/lib/esm/resources/price_volume_tiers.d.ts +1 -0
  452. package/lib/esm/resources/price_volume_tiers.js +4 -1
  453. package/lib/esm/resources/prices.d.ts +1 -0
  454. package/lib/esm/resources/prices.js +4 -1
  455. package/lib/esm/resources/promotion_rules.d.ts +1 -0
  456. package/lib/esm/resources/promotion_rules.js +4 -1
  457. package/lib/esm/resources/promotions.d.ts +1 -0
  458. package/lib/esm/resources/promotions.js +4 -1
  459. package/lib/esm/resources/recurring_order_copies.d.ts +1 -0
  460. package/lib/esm/resources/recurring_order_copies.js +4 -1
  461. package/lib/esm/resources/refunds.d.ts +1 -0
  462. package/lib/esm/resources/refunds.js +4 -1
  463. package/lib/esm/resources/reserved_stocks.d.ts +1 -0
  464. package/lib/esm/resources/reserved_stocks.js +4 -1
  465. package/lib/esm/resources/resource_errors.d.ts +1 -0
  466. package/lib/esm/resources/resource_errors.js +4 -1
  467. package/lib/esm/resources/return_line_items.d.ts +1 -0
  468. package/lib/esm/resources/return_line_items.js +4 -1
  469. package/lib/esm/resources/returns.d.ts +1 -0
  470. package/lib/esm/resources/returns.js +4 -1
  471. package/lib/esm/resources/satispay_gateways.d.ts +1 -0
  472. package/lib/esm/resources/satispay_gateways.js +4 -1
  473. package/lib/esm/resources/satispay_payments.d.ts +1 -0
  474. package/lib/esm/resources/satispay_payments.js +4 -1
  475. package/lib/esm/resources/shipments.d.ts +4 -0
  476. package/lib/esm/resources/shipments.js +8 -1
  477. package/lib/esm/resources/shipping_categories.d.ts +1 -0
  478. package/lib/esm/resources/shipping_categories.js +4 -1
  479. package/lib/esm/resources/shipping_method_tiers.d.ts +1 -0
  480. package/lib/esm/resources/shipping_method_tiers.js +4 -1
  481. package/lib/esm/resources/shipping_methods.d.ts +1 -0
  482. package/lib/esm/resources/shipping_methods.js +4 -1
  483. package/lib/esm/resources/shipping_weight_tiers.d.ts +1 -0
  484. package/lib/esm/resources/shipping_weight_tiers.js +4 -1
  485. package/lib/esm/resources/shipping_zones.d.ts +1 -0
  486. package/lib/esm/resources/shipping_zones.js +4 -1
  487. package/lib/esm/resources/sku_list_items.d.ts +1 -0
  488. package/lib/esm/resources/sku_list_items.js +4 -1
  489. package/lib/esm/resources/sku_list_promotion_rules.d.ts +1 -0
  490. package/lib/esm/resources/sku_list_promotion_rules.js +4 -1
  491. package/lib/esm/resources/sku_lists.d.ts +1 -0
  492. package/lib/esm/resources/sku_lists.js +4 -1
  493. package/lib/esm/resources/sku_options.d.ts +1 -0
  494. package/lib/esm/resources/sku_options.js +4 -1
  495. package/lib/esm/resources/skus.d.ts +1 -0
  496. package/lib/esm/resources/skus.js +4 -1
  497. package/lib/esm/resources/stock_items.d.ts +1 -0
  498. package/lib/esm/resources/stock_items.js +4 -1
  499. package/lib/esm/resources/stock_line_items.d.ts +1 -0
  500. package/lib/esm/resources/stock_line_items.js +4 -1
  501. package/lib/esm/resources/stock_locations.d.ts +1 -0
  502. package/lib/esm/resources/stock_locations.js +4 -1
  503. package/lib/esm/resources/stock_reservations.d.ts +1 -0
  504. package/lib/esm/resources/stock_reservations.js +4 -1
  505. package/lib/esm/resources/stock_transfers.d.ts +1 -0
  506. package/lib/esm/resources/stock_transfers.js +4 -1
  507. package/lib/esm/resources/stripe_gateways.d.ts +1 -0
  508. package/lib/esm/resources/stripe_gateways.js +4 -1
  509. package/lib/esm/resources/stripe_payments.d.ts +1 -0
  510. package/lib/esm/resources/stripe_payments.js +4 -1
  511. package/lib/esm/resources/subscription_models.d.ts +1 -0
  512. package/lib/esm/resources/subscription_models.js +4 -1
  513. package/lib/esm/resources/tags.d.ts +1 -0
  514. package/lib/esm/resources/tags.js +4 -1
  515. package/lib/esm/resources/tax_calculators.d.ts +1 -0
  516. package/lib/esm/resources/tax_calculators.js +4 -1
  517. package/lib/esm/resources/tax_categories.d.ts +1 -0
  518. package/lib/esm/resources/tax_categories.js +4 -1
  519. package/lib/esm/resources/tax_rules.d.ts +1 -0
  520. package/lib/esm/resources/tax_rules.js +4 -1
  521. package/lib/esm/resources/taxjar_accounts.d.ts +1 -0
  522. package/lib/esm/resources/taxjar_accounts.js +4 -1
  523. package/lib/esm/resources/transactions.d.ts +1 -0
  524. package/lib/esm/resources/transactions.js +4 -1
  525. package/lib/esm/resources/versions.d.ts +1 -0
  526. package/lib/esm/resources/versions.js +4 -1
  527. package/lib/esm/resources/voids.d.ts +1 -0
  528. package/lib/esm/resources/voids.js +4 -1
  529. package/lib/esm/resources/webhooks.d.ts +1 -0
  530. package/lib/esm/resources/webhooks.js +4 -1
  531. package/lib/esm/resources/wire_transfers.d.ts +1 -0
  532. package/lib/esm/resources/wire_transfers.js +4 -1
  533. package/lib/esm/static.js +0 -1
  534. package/lib/esm/util.js +1 -27
  535. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  536. package/lib/tsconfig.tsbuildinfo +1 -1
  537. package/package.json +10 -14
package/lib/esm/debug.js CHANGED
@@ -1,35 +1,14 @@
1
- /* Nope debugger */
2
1
  const debuggerFunction = (_pattern, ..._args) => {
3
- // console.log(_pattern)
4
2
  };
5
3
  let debuggerFactory = (_namespace) => debuggerFunction;
6
- /* Try loading 'debug' module */
7
4
  try {
8
5
  const debugModule = require('debug');
9
6
  if (debugModule && (typeof debugModule === 'function'))
10
7
  debuggerFactory = debugModule;
11
8
  }
12
9
  catch (error) {
13
- //
14
10
  }
15
11
  const debugPrefix = 'clsdk';
16
- /* Retrieve the name of the caller 'module' */
17
- /*
18
- const caller = (): string => {
19
-
20
- const err = new Error()
21
-
22
- Error.prepareStackTrace = (_, stack) => stack
23
- const stack = err.stack as unknown as NodeJS.CallSite[]
24
- Error.prepareStackTrace = undefined
25
-
26
- const fileName = stack[2].getFileName() || '/'
27
-
28
- return fileName.replace(/^.*[\\/]/, '').replace('.ts', '')
29
-
30
- }
31
- */
32
- /* Return a debugger for the defined namespace */
33
12
  const debug = (namespace) => {
34
13
  return debuggerFactory(`${debugPrefix}:${namespace}`);
35
14
  };
@@ -1,10 +1,10 @@
1
1
  declare enum ErrorType {
2
- CLIENT = "client",// Error instantiating the client
3
- REQUEST = "request",// Error preparing API request
4
- RESPONSE = "response",// Error response from API
5
- CANCEL = "cancel",// Forced request abort using interceptor
6
- PARSE = "parse",// Error parsing API resource
7
- GENERIC = "generic"
2
+ CLIENT = "client",
3
+ REQUEST = "request",
4
+ RESPONSE = "response",
5
+ CANCEL = "cancel",
6
+ PARSE = "parse",
7
+ TIMEOUT = "timeout"
8
8
  }
9
9
  declare class SdkError extends Error {
10
10
  static NAME: string;
@@ -12,7 +12,6 @@ declare class SdkError extends Error {
12
12
  type: ErrorType;
13
13
  code?: string;
14
14
  source?: Error;
15
- request?: any;
16
15
  constructor(error: {
17
16
  message: string;
18
17
  type?: ErrorType;
package/lib/esm/error.js CHANGED
@@ -1,4 +1,4 @@
1
- import axios from 'axios';
1
+ import { FetchError } from './fetch';
2
2
  var ErrorType;
3
3
  (function (ErrorType) {
4
4
  ErrorType["CLIENT"] = "client";
@@ -6,7 +6,7 @@ var ErrorType;
6
6
  ErrorType["RESPONSE"] = "response";
7
7
  ErrorType["CANCEL"] = "cancel";
8
8
  ErrorType["PARSE"] = "parse";
9
- ErrorType["GENERIC"] = "generic";
9
+ ErrorType["TIMEOUT"] = "timeout";
10
10
  })(ErrorType || (ErrorType = {}));
11
11
  class SdkError extends Error {
12
12
  static NAME = 'SdkError';
@@ -16,11 +16,10 @@ class SdkError extends Error {
16
16
  type;
17
17
  code;
18
18
  source;
19
- request;
20
19
  constructor(error) {
21
20
  super(error.message);
22
- this.name = SdkError.NAME; // this.constructor.name
23
- this.type = error.type || ErrorType.GENERIC;
21
+ this.name = SdkError.NAME;
22
+ this.type = error.type || ErrorType.CLIENT;
24
23
  }
25
24
  }
26
25
  class ApiError extends SdkError {
@@ -33,42 +32,47 @@ class ApiError extends SdkError {
33
32
  statusText;
34
33
  constructor(error) {
35
34
  super({ ...error, type: ErrorType.RESPONSE });
36
- this.name = ApiError.NAME; // this.constructor.name
35
+ this.name = ApiError.NAME;
37
36
  }
38
37
  first() {
39
38
  return (this.errors?.length > 0) ? this.errors[0] : undefined;
40
39
  }
41
40
  }
41
+ const isRequestError = (error) => {
42
+ return error instanceof TypeError;
43
+ };
44
+ const isCancelError = (error) => {
45
+ return (error instanceof DOMException) && (error.name === 'AbortError');
46
+ };
47
+ const isTimeoutError = (error) => {
48
+ return (error instanceof DOMException) && (error.name === 'TimeoutError');
49
+ };
42
50
  const handleError = (error) => {
43
51
  let sdkError = new SdkError({ message: error.message });
44
- if (axios.isAxiosError(error)) {
45
- if (error.response) {
46
- // The request was made and the server responded with a status code that falls out of the range of 2xx
47
- const apiError = new ApiError(sdkError);
48
- apiError.type = ErrorType.RESPONSE;
49
- apiError.status = error.response.status;
50
- apiError.statusText = error.response.statusText;
51
- apiError.code = String(apiError.status);
52
- apiError.errors = error.response.data.errors;
53
- if (!apiError.message && apiError.statusText)
54
- apiError.message = apiError.statusText;
55
- sdkError = apiError;
56
- }
57
- else if (error.request) {
58
- // The request was made but no response was received
59
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
60
- sdkError.type = ErrorType.REQUEST;
61
- sdkError.request = error.request;
62
- }
63
- else {
64
- // Something happened in setting up the request that triggered an Error
65
- sdkError.type = ErrorType.CLIENT;
66
- }
52
+ if (FetchError.isFetchError(error)) {
53
+ const apiError = new ApiError(sdkError);
54
+ apiError.type = ErrorType.RESPONSE;
55
+ apiError.status = error.status;
56
+ apiError.statusText = error.statusText;
57
+ apiError.code = String(apiError.status);
58
+ apiError.errors = error.errors || [];
59
+ if (!apiError.message && apiError.statusText)
60
+ apiError.message = apiError.statusText;
61
+ sdkError = apiError;
62
+ }
63
+ else if (isRequestError(error)) {
64
+ sdkError.type = ErrorType.REQUEST;
67
65
  }
68
- else if (axios.isCancel(error))
66
+ else if (isCancelError(error)) {
69
67
  sdkError.type = ErrorType.CANCEL;
70
- else
68
+ }
69
+ else if (isTimeoutError(error)) {
70
+ sdkError.type = ErrorType.TIMEOUT;
71
+ }
72
+ else {
73
+ sdkError.type = ErrorType.CLIENT;
71
74
  sdkError.source = error;
75
+ }
72
76
  throw sdkError;
73
77
  };
74
78
  export { SdkError, ApiError, ErrorType, handleError };
@@ -0,0 +1,13 @@
1
+ import type { DocWithData } from 'jsonapi-typescript';
2
+ import type { InterceptorManager } from './interceptor';
3
+ export type FetchResponse = DocWithData;
4
+ export type FetchOptions = RequestInit;
5
+ export declare class FetchError extends Error {
6
+ #private;
7
+ static isFetchError: (error: any) => error is FetchError;
8
+ constructor(status: number, statusText: string, body?: any);
9
+ get errors(): any[] | undefined;
10
+ get status(): number;
11
+ get statusText(): string;
12
+ }
13
+ export declare const fetchURL: (url: URL, options: FetchOptions, interceptors?: InterceptorManager) => Promise<FetchResponse>;
@@ -0,0 +1,46 @@
1
+ import Debug from './debug';
2
+ const debug = Debug('fetch');
3
+ export class FetchError extends Error {
4
+ static isFetchError = (error) => {
5
+ return error instanceof FetchError;
6
+ };
7
+ #errors;
8
+ #status;
9
+ #statusText;
10
+ constructor(status, statusText, body) {
11
+ super(statusText);
12
+ this.#status = status;
13
+ this.#statusText = statusText;
14
+ if (body)
15
+ this.#errors = body.errors;
16
+ }
17
+ get errors() { return this.#errors; }
18
+ get status() { return this.#status; }
19
+ get statusText() { return this.#statusText; }
20
+ }
21
+ export const fetchURL = async (url, options, interceptors) => {
22
+ debug('fetch: %s, %O', url, options || {});
23
+ if (interceptors?.request?.onSuccess)
24
+ ({ url, options } = await interceptors.request.onSuccess({ url, options }));
25
+ const request = new Request(url, options);
26
+ let response = await fetch(request);
27
+ if (response.ok) {
28
+ if (interceptors?.rawReader?.onSuccess)
29
+ await interceptors.rawReader.onSuccess(response);
30
+ if (interceptors?.response?.onSuccess)
31
+ response = await interceptors.response.onSuccess(response);
32
+ }
33
+ else {
34
+ if (interceptors?.rawReader?.onFailure)
35
+ await interceptors.rawReader.onFailure(response);
36
+ }
37
+ const responseBody = await response.json().catch(() => { });
38
+ if (!response.ok) {
39
+ let error = new FetchError(response.status, response.statusText, responseBody);
40
+ if (interceptors?.response?.onFailure)
41
+ error = await interceptors.response.onFailure(error);
42
+ if (error)
43
+ throw error;
44
+ }
45
+ return responseBody;
46
+ };
package/lib/esm/index.js CHANGED
@@ -1,4 +1,2 @@
1
- // SDK
2
1
  export { default, CommerceLayer } from './commercelayer';
3
- // Commerce Layer static functions
4
2
  export { CommerceLayerStatic } from './static';
@@ -1,25 +1,37 @@
1
- import type { AxiosError, AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
1
+ import type { FetchError, FetchOptions } from "./fetch";
2
+ type InterceptorEventManager<S extends (RequestInterceptor | ResponseInterceptor), F extends (ErrorInterceptor | ResponseInterceptor)> = {
3
+ onSuccess?: S;
4
+ onFailure?: F;
5
+ };
6
+ type RequestEventManager = InterceptorEventManager<RequestInterceptor, ErrorInterceptor>;
7
+ type ResponseEventManager = InterceptorEventManager<ResponseInterceptor, ErrorInterceptor>;
8
+ type ErrorEventManager = InterceptorEventManager<ResponseInterceptor, ResponseInterceptor>;
2
9
  type InterceptorManager = {
3
- request: AxiosInterceptorManager<AxiosRequestConfig>;
4
- response: AxiosInterceptorManager<any>;
10
+ request?: RequestEventManager;
11
+ response?: ResponseEventManager;
12
+ rawReader?: ErrorEventManager;
13
+ };
14
+ type RequestObj = {
15
+ url: URL;
16
+ options: FetchOptions;
5
17
  };
6
- type RequestObj = AxiosRequestConfig;
7
18
  type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
8
- type ResponseObj = AxiosResponse;
9
- type ResponseInterceptor = (response: ResponseObj) => ResponseObj;
19
+ type ResponseObj = Response;
20
+ type ResponseInterceptor = (response: ResponseObj) => ResponseObj | Promise<ResponseObj>;
10
21
  type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-count' | 'x-ratelimit-period' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
11
22
  type ApiHeaders = {
12
23
  [key in ApiHeadersList]: string | number | boolean;
13
24
  };
14
- type HeadersObj = (AxiosResponseHeaders | RawAxiosResponseHeaders) & ApiHeaders;
15
- type ErrorObj = AxiosError;
16
- type ErrorInterceptor = (error: ErrorObj) => ErrorObj;
25
+ type HeadersObj = Record<string, string> | ApiHeaders;
26
+ type ErrorObj = FetchError;
27
+ type ErrorInterceptor = (error: ErrorObj) => ErrorObj | Promise<ErrorObj>;
17
28
  type InterceptorType = 'request' | 'response';
18
29
  export type { InterceptorManager, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, InterceptorType };
19
30
  export type { RequestObj, ResponseObj, ErrorObj, HeadersObj };
20
31
  type RawResponseReader = {
21
- id: number | undefined;
22
- rawResponse: ResponseObj | undefined;
23
- headers: HeadersObj | undefined;
32
+ id?: number;
33
+ rawResponse?: any;
34
+ headers?: HeadersObj;
35
+ ok: boolean;
24
36
  };
25
37
  export type { RawResponseReader };
@@ -1,7 +1,7 @@
1
1
  import { isResourceId, isResourceType } from './common';
2
+ import config from './config';
2
3
  import Debug from './debug';
3
4
  const debug = Debug('jsonapi');
4
- // DENORMALIZATION
5
5
  const denormalize = (response) => {
6
6
  let denormalizedResponse;
7
7
  if (response.links)
@@ -24,7 +24,7 @@ const findIncluded = (rel, included = []) => {
24
24
  });
25
25
  return inc || rel;
26
26
  };
27
- const denormalizeResource = (res, included) => {
27
+ const denormalizeResource = (res, included, chain = []) => {
28
28
  debug('denormalize resource: %O, %o', res, included || {});
29
29
  if (!res)
30
30
  return res;
@@ -37,10 +37,14 @@ const denormalizeResource = (res, included) => {
37
37
  Object.keys(res.relationships).forEach(key => {
38
38
  const rel = res.relationships[key].data;
39
39
  if (rel) {
40
- if (Array.isArray(rel))
41
- resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included));
42
- else
43
- resource[key] = denormalizeResource(findIncluded(rel, included), included);
40
+ if (chain.filter(r => (r.id === rel.id) && (r.type === rel.type)).length >= config.jsonapi.maxResourceIncluded)
41
+ resource[key] = rel;
42
+ else {
43
+ if (Array.isArray(rel))
44
+ resource[key] = rel.map((r) => denormalizeResource(findIncluded(r, included), included, [...chain, r]));
45
+ else
46
+ resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
47
+ }
44
48
  }
45
49
  else if (rel === null)
46
50
  resource[key] = null;
@@ -48,7 +52,6 @@ const denormalizeResource = (res, included) => {
48
52
  debug('denormalized resource: %O', resource);
49
53
  return resource;
50
54
  };
51
- // NORMALIZATION
52
55
  const normalize = (resource) => {
53
56
  debug('normalize resource: %O', resource);
54
57
  const attributes = {};
@@ -1,6 +1,3 @@
1
- /**
2
- * ©2024 Commerce Layer Inc.
3
- **/
4
1
  export type { Address, AddressCreate, AddressUpdate } from './resources/addresses';
5
2
  export type { Adjustment, AdjustmentCreate, AdjustmentUpdate } from './resources/adjustments';
6
3
  export type { AdyenGateway, AdyenGatewayCreate, AdyenGatewayUpdate } from './resources/adyen_gateways';
package/lib/esm/model.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- // ##__MODEL_TYPES_STOP__##
@@ -1,5 +1,5 @@
1
1
  import type { ResourceType } from "./resource";
2
- type QueryFilter = Record<string, string | number | boolean | object>;
2
+ type QueryFilter = Record<string, string | number | boolean | object | Array<string | number>>;
3
3
  interface QueryParamsRetrieve {
4
4
  include?: string[];
5
5
  fields?: string[] | Record<string, string[]>;
@@ -14,4 +14,5 @@ type QueryParams = QueryParamsRetrieve | QueryParamsList;
14
14
  export type { QueryParamsRetrieve, QueryParamsList, QueryParams, QueryFilter };
15
15
  declare const isParamsList: (params: any) => params is QueryParamsList;
16
16
  declare const generateQueryStringParams: (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType) => Record<string, string>;
17
- export { generateQueryStringParams, isParamsList };
17
+ declare const generateSearchString: (params?: QueryParams, questionMark?: boolean) => string;
18
+ export { generateQueryStringParams, isParamsList, generateSearchString };
package/lib/esm/query.js CHANGED
@@ -1,5 +1,8 @@
1
+ import { ErrorType, SdkError } from "./error";
1
2
  import Debug from './debug';
2
3
  const debug = Debug('query');
4
+ const arrayFilters = ['_any', '_all', '_in'];
5
+ const objectFilters = ['_jcont'];
3
6
  const isParamsList = (params) => {
4
7
  return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
5
8
  };
@@ -8,10 +11,8 @@ const generateQueryStringParams = (params, res) => {
8
11
  const qp = {};
9
12
  if (!params)
10
13
  return qp;
11
- // Include
12
14
  if (params.include)
13
15
  qp.include = params.include.join(',');
14
- // Fields
15
16
  if (params.fields) {
16
17
  if (Array.isArray(params.fields))
17
18
  params.fields = { [res.type || res]: params.fields };
@@ -20,26 +21,42 @@ const generateQueryStringParams = (params, res) => {
20
21
  });
21
22
  }
22
23
  if (isParamsList(params)) {
23
- // Sort
24
24
  if (params.sort) {
25
25
  if (Array.isArray(params.sort))
26
26
  qp.sort = params.sort.join(',');
27
27
  else
28
28
  qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === 'desc' ? '-' : ''}${k}`).join(',');
29
29
  }
30
- // Page
31
30
  if (params.pageNumber)
32
31
  qp['page[number]'] = String(params.pageNumber);
33
32
  if (params.pageSize)
34
33
  qp['page[size]'] = String(params.pageSize);
35
- // Filters
36
34
  if (params.filters) {
37
35
  Object.entries(params.filters).forEach(([p, v]) => {
38
- qp[`filter[q][${p}]`] = (typeof v === 'object') ? JSON.stringify(v) : String(v);
36
+ const filter = p.substring(p.lastIndexOf('_'));
37
+ let val;
38
+ if (Array.isArray(v)) {
39
+ if (!arrayFilters.includes(filter))
40
+ throw new SdkError({ message: `Wrong ${filter} filter: Array value is supported only for the following filters: ${arrayFilters.join(', ')}`, type: ErrorType.REQUEST });
41
+ val = v.join(',');
42
+ }
43
+ else if (typeof v === 'object') {
44
+ if (!objectFilters.includes(filter))
45
+ throw new SdkError({ message: `Wrong ${filter} filter: Object value is supported only for the following filters: ${objectFilters.join(', ')}`, type: ErrorType.REQUEST });
46
+ val = JSON.stringify(v);
47
+ }
48
+ else
49
+ val = String(v);
50
+ qp[`filter[q][${p}]`] = val;
39
51
  });
40
52
  }
41
53
  }
42
54
  debug('query string params: %O', qp);
43
55
  return qp;
44
56
  };
45
- export { generateQueryStringParams, isParamsList };
57
+ const generateSearchString = (params, questionMark = true) => {
58
+ if (!params || (Object.keys(params).length === 0))
59
+ return '';
60
+ return `${questionMark ? '?' : ''}${Object.entries(params).map(([key, val]) => `${key}=${String(val)}`).join('&')}`;
61
+ };
62
+ export { generateQueryStringParams, isParamsList, generateSearchString };
@@ -1,7 +1,6 @@
1
- import { type ApiClientInitConfig } from './client';
1
+ import ApiClient, { type ApiClientInitConfig } from './client';
2
2
  import type { QueryParamsRetrieve, QueryParamsList, QueryFilter, QueryParams } from './query';
3
3
  import type { ResourceTypeLock } from './api';
4
- import type { InterceptorManager } from './interceptor';
5
4
  type ResourceNull = {
6
5
  id: null;
7
6
  } & ResourceType;
@@ -53,9 +52,9 @@ type ResourcesConfig = Partial<ResourcesInitConfig>;
53
52
  declare class ResourceAdapter {
54
53
  #private;
55
54
  constructor(config: ResourcesInitConfig);
56
- get interceptors(): InterceptorManager;
57
55
  private localConfig;
58
56
  config(config: ResourcesConfig): ResourceAdapter;
57
+ get client(): Readonly<ApiClient>;
59
58
  singleton<R extends Resource>(resource: ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
60
59
  retrieve<R extends Resource>(resource: ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
61
60
  list<R extends Resource>(resource: ResourceType, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
@@ -69,8 +68,9 @@ declare abstract class ApiResourceBase<R extends Resource> {
69
68
  protected readonly resources: ResourceAdapter;
70
69
  constructor(adapter: ResourceAdapter);
71
70
  abstract relationship(id: string | ResourceId | null): ResourceRel;
71
+ protected relationshipOneToOne<RR extends ResourceRel>(id: string | ResourceId | null): RR;
72
+ protected relationshipOneToMany<RR extends ResourceRel>(...ids: string[]): RR[];
72
73
  abstract type(): ResourceTypeLock;
73
- parse(resource: string): R | R[];
74
74
  update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
75
75
  }
76
76
  declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
@@ -2,7 +2,6 @@ import ApiClient from './client';
2
2
  import { denormalize, normalize } from './jsonapi';
3
3
  import { generateQueryStringParams, isParamsList } from './query';
4
4
  import config from './config';
5
- import { ErrorType, SdkError } from './error';
6
5
  import Debug from './debug';
7
6
  const debug = Debug('resource');
8
7
  class ListResponse extends Array {
@@ -28,29 +27,23 @@ class ResourceAdapter {
28
27
  this.#client = ApiClient.create(config);
29
28
  this.localConfig(config);
30
29
  }
31
- get interceptors() { return this.#client.interceptors; }
32
30
  localConfig(config) {
33
- // if (typeof config.xyz !== 'undefined') this.#config.xyz = config.xyz
34
31
  }
35
32
  config(config) {
36
33
  debug('config %o', config);
37
- // ResourceAdapter config
38
34
  this.localConfig(config);
39
- // Client config
40
35
  this.#client.config(config);
41
36
  return this;
42
37
  }
43
- /*
44
- get clientInstance(): ApiClient {
45
- return this.#client
38
+ get client() {
39
+ return this.#client;
46
40
  }
47
- */
48
41
  async singleton(resource, params, options) {
49
42
  debug('singleton: %o, %O, %O', resource, params || {}, options || {});
50
43
  const queryParams = generateQueryStringParams(params, resource);
51
44
  if (options?.params)
52
45
  Object.assign(queryParams, options?.params);
53
- const res = await this.#client.request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
46
+ const res = await this.#client.request('GET', `${resource.type}`, undefined, { ...options, params: queryParams });
54
47
  const r = denormalize(res);
55
48
  return r;
56
49
  }
@@ -59,7 +52,7 @@ class ResourceAdapter {
59
52
  const queryParams = generateQueryStringParams(params, resource);
60
53
  if (options?.params)
61
54
  Object.assign(queryParams, options?.params);
62
- const res = await this.#client.request('get', `${resource.type}/${resource.id}`, undefined, { ...options, params: queryParams });
55
+ const res = await this.#client.request('GET', `${resource.type}/${resource.id}`, undefined, { ...options, params: queryParams });
63
56
  const r = denormalize(res);
64
57
  return r;
65
58
  }
@@ -68,7 +61,7 @@ class ResourceAdapter {
68
61
  const queryParams = generateQueryStringParams(params, resource);
69
62
  if (options?.params)
70
63
  Object.assign(queryParams, options?.params);
71
- const res = await this.#client.request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
64
+ const res = await this.#client.request('GET', `${resource.type}`, undefined, { ...options, params: queryParams });
72
65
  const r = denormalize(res);
73
66
  const meta = {
74
67
  pageCount: Number(res.meta?.page_count),
@@ -84,7 +77,7 @@ class ResourceAdapter {
84
77
  if (options?.params)
85
78
  Object.assign(queryParams, options?.params);
86
79
  const data = normalize(resource);
87
- const res = await this.#client.request('post', resource.type, data, { ...options, params: queryParams });
80
+ const res = await this.#client.request('POST', resource.type, data, { ...options, params: queryParams });
88
81
  const r = denormalize(res);
89
82
  return r;
90
83
  }
@@ -94,20 +87,20 @@ class ResourceAdapter {
94
87
  if (options?.params)
95
88
  Object.assign(queryParams, options?.params);
96
89
  const data = normalize(resource);
97
- const res = await this.#client.request('patch', `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
90
+ const res = await this.#client.request('PATCH', `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
98
91
  const r = denormalize(res);
99
92
  return r;
100
93
  }
101
94
  async delete(resource, options) {
102
95
  debug('delete: %o, %O', resource, options || {});
103
- await this.#client.request('delete', `${resource.type}/${resource.id}`, undefined, options);
96
+ await this.#client.request('DELETE', `${resource.type}/${resource.id}`, undefined, options);
104
97
  }
105
98
  async fetch(resource, path, params, options) {
106
99
  debug('fetch: %o, %O, %O', path, params || {}, options || {});
107
100
  const queryParams = generateQueryStringParams(params, resource);
108
101
  if (options?.params)
109
102
  Object.assign(queryParams, options?.params);
110
- const res = await this.#client.request('get', path, undefined, { ...options, params: queryParams });
103
+ const res = await this.#client.request('GET', path, undefined, { ...options, params: queryParams });
111
104
  const r = denormalize(res);
112
105
  if (Array.isArray(r)) {
113
106
  const p = params;
@@ -130,21 +123,12 @@ class ApiResourceBase {
130
123
  debug('new resource instance: %s', this.type());
131
124
  this.resources = adapter;
132
125
  }
133
- parse(resource) {
134
- try {
135
- const res = JSON.parse(resource);
136
- if (res.data?.type !== this.type())
137
- throw new SdkError({ message: `Invalid resource type [${res.data?.type}]`, type: ErrorType.PARSE });
138
- return denormalize(res);
139
- }
140
- catch (error) {
141
- if (SdkError.isSdkError(error))
142
- throw error;
143
- else
144
- throw new SdkError({ message: `Payload parse error [${error.message}]`, type: ErrorType.PARSE });
145
- }
126
+ relationshipOneToOne(id) {
127
+ return (((id === null) || (typeof id === 'string')) ? { id, type: this.type() } : { id: id.id, type: this.type() });
128
+ }
129
+ relationshipOneToMany(...ids) {
130
+ return (((ids === null) || (ids.length === 0) || (ids[0] === null)) ? [{ id: null, type: this.type() }] : ids.map(id => { return { id, type: this.type() }; }));
146
131
  }
147
- // reference, reference_origin and metadata attributes are always updatable
148
132
  async update(resource, params, options) {
149
133
  return this.resources.update({ ...resource, type: this.type() }, params, options);
150
134
  }
@@ -97,6 +97,7 @@ declare class Addresses extends ApiResource<Address> {
97
97
  versions(addressId: string | Address, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
98
98
  isAddress(resource: any): resource is Address;
99
99
  relationship(id: string | ResourceId | null): AddressRel;
100
+ relationshipToMany(...ids: string[]): AddressRel[];
100
101
  type(): AddressType;
101
102
  }
102
103
  export default Addresses;
@@ -30,7 +30,10 @@ class Addresses extends ApiResource {
30
30
  return resource.type && (resource.type === Addresses.TYPE);
31
31
  }
32
32
  relationship(id) {
33
- return ((id === null) || (typeof id === 'string')) ? { id, type: Addresses.TYPE } : { id: id.id, type: Addresses.TYPE };
33
+ return super.relationshipOneToOne(id);
34
+ }
35
+ relationshipToMany(...ids) {
36
+ return super.relationshipOneToMany(...ids);
34
37
  }
35
38
  type() {
36
39
  return Addresses.TYPE;
@@ -36,6 +36,7 @@ declare class Adjustments extends ApiResource<Adjustment> {
36
36
  versions(adjustmentId: string | Adjustment, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
37
37
  isAdjustment(resource: any): resource is Adjustment;
38
38
  relationship(id: string | ResourceId | null): AdjustmentRel;
39
+ relationshipToMany(...ids: string[]): AdjustmentRel[];
39
40
  type(): AdjustmentType;
40
41
  }
41
42
  export default Adjustments;
@@ -18,7 +18,10 @@ class Adjustments extends ApiResource {
18
18
  return resource.type && (resource.type === Adjustments.TYPE);
19
19
  }
20
20
  relationship(id) {
21
- return ((id === null) || (typeof id === 'string')) ? { id, type: Adjustments.TYPE } : { id: id.id, type: Adjustments.TYPE };
21
+ return super.relationshipOneToOne(id);
22
+ }
23
+ relationshipToMany(...ids) {
24
+ return super.relationshipOneToMany(...ids);
22
25
  }
23
26
  type() {
24
27
  return Adjustments.TYPE;
@@ -54,6 +54,7 @@ declare class AdyenGateways extends ApiResource<AdyenGateway> {
54
54
  adyen_payments(adyenGatewayId: string | AdyenGateway, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<AdyenPayment>>;
55
55
  isAdyenGateway(resource: any): resource is AdyenGateway;
56
56
  relationship(id: string | ResourceId | null): AdyenGatewayRel;
57
+ relationshipToMany(...ids: string[]): AdyenGatewayRel[];
57
58
  type(): AdyenGatewayType;
58
59
  }
59
60
  export default AdyenGateways;
@@ -26,7 +26,10 @@ class AdyenGateways extends ApiResource {
26
26
  return resource.type && (resource.type === AdyenGateways.TYPE);
27
27
  }
28
28
  relationship(id) {
29
- return ((id === null) || (typeof id === 'string')) ? { id, type: AdyenGateways.TYPE } : { id: id.id, type: AdyenGateways.TYPE };
29
+ return super.relationshipOneToOne(id);
30
+ }
31
+ relationshipToMany(...ids) {
32
+ return super.relationshipOneToMany(...ids);
30
33
  }
31
34
  type() {
32
35
  return AdyenGateways.TYPE;
@@ -45,6 +45,7 @@ declare class AdyenPayments extends ApiResource<AdyenPayment> {
45
45
  _details(id: string | AdyenPayment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<AdyenPayment>;
46
46
  isAdyenPayment(resource: any): resource is AdyenPayment;
47
47
  relationship(id: string | ResourceId | null): AdyenPaymentRel;
48
+ relationshipToMany(...ids: string[]): AdyenPaymentRel[];
48
49
  type(): AdyenPaymentType;
49
50
  }
50
51
  export default AdyenPayments;