@commercelayer/sdk 4.35.0 → 4.37.0

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 (521) hide show
  1. package/lib/cjs/api.d.ts +37 -0
  2. package/lib/cjs/api.js +0 -13
  3. package/lib/cjs/client.d.ts +15 -8
  4. package/lib/cjs/client.js +40 -40
  5. package/lib/cjs/commercelayer.d.ts +3 -4
  6. package/lib/cjs/commercelayer.js +7 -3
  7. package/lib/cjs/common.d.ts +1 -0
  8. package/lib/cjs/common.js +11 -2
  9. package/lib/cjs/config.d.ts +1 -0
  10. package/lib/cjs/config.js +3 -0
  11. package/lib/cjs/debug.js +0 -4
  12. package/lib/cjs/error.d.ts +3 -1
  13. package/lib/cjs/error.js +40 -7
  14. package/lib/cjs/index.d.ts +1 -1
  15. package/lib/cjs/index.js +0 -16
  16. package/lib/cjs/interceptor.d.ts +6 -2
  17. package/lib/cjs/jsonapi.js +9 -2
  18. package/lib/cjs/query.d.ts +9 -15
  19. package/lib/cjs/query.js +3 -2
  20. package/lib/cjs/resource.d.ts +30 -20
  21. package/lib/cjs/resource.js +40 -9
  22. package/lib/cjs/resources/addresses.d.ts +74 -73
  23. package/lib/cjs/resources/addresses.js +3 -11
  24. package/lib/cjs/resources/adjustments.d.ts +20 -19
  25. package/lib/cjs/resources/adjustments.js +3 -11
  26. package/lib/cjs/resources/adyen_gateways.d.ts +35 -34
  27. package/lib/cjs/resources/adyen_gateways.js +3 -11
  28. package/lib/cjs/resources/adyen_payments.d.ts +29 -27
  29. package/lib/cjs/resources/adyen_payments.js +6 -11
  30. package/lib/cjs/resources/application.d.ts +14 -13
  31. package/lib/cjs/resources/application.js +1 -6
  32. package/lib/cjs/resources/attachments.d.ts +81 -80
  33. package/lib/cjs/resources/attachments.js +3 -11
  34. package/lib/cjs/resources/authorizations.d.ts +47 -43
  35. package/lib/cjs/resources/authorizations.js +10 -9
  36. package/lib/cjs/resources/avalara_accounts.d.ts +32 -31
  37. package/lib/cjs/resources/avalara_accounts.js +3 -11
  38. package/lib/cjs/resources/axerve_gateways.d.ts +24 -23
  39. package/lib/cjs/resources/axerve_gateways.js +3 -11
  40. package/lib/cjs/resources/axerve_payments.d.ts +28 -26
  41. package/lib/cjs/resources/axerve_payments.js +6 -11
  42. package/lib/cjs/resources/billing_info_validation_rules.d.ts +17 -16
  43. package/lib/cjs/resources/billing_info_validation_rules.js +3 -11
  44. package/lib/cjs/resources/bing_geocoders.d.ts +16 -15
  45. package/lib/cjs/resources/bing_geocoders.js +3 -11
  46. package/lib/cjs/resources/braintree_gateways.d.ts +34 -33
  47. package/lib/cjs/resources/braintree_gateways.js +3 -11
  48. package/lib/cjs/resources/braintree_payments.d.ts +30 -29
  49. package/lib/cjs/resources/braintree_payments.js +3 -11
  50. package/lib/cjs/resources/bundles.d.ts +57 -54
  51. package/lib/cjs/resources/bundles.js +9 -11
  52. package/lib/cjs/resources/captures.d.ts +37 -34
  53. package/lib/cjs/resources/captures.js +7 -9
  54. package/lib/cjs/resources/carrier_accounts.d.ts +16 -15
  55. package/lib/cjs/resources/carrier_accounts.js +0 -8
  56. package/lib/cjs/resources/checkout_com_gateways.d.ts +25 -24
  57. package/lib/cjs/resources/checkout_com_gateways.js +3 -11
  58. package/lib/cjs/resources/checkout_com_payments.d.ts +41 -38
  59. package/lib/cjs/resources/checkout_com_payments.js +9 -11
  60. package/lib/cjs/resources/cleanups.d.ts +24 -23
  61. package/lib/cjs/resources/cleanups.js +2 -10
  62. package/lib/cjs/resources/coupon_codes_promotion_rules.d.ts +31 -30
  63. package/lib/cjs/resources/coupon_codes_promotion_rules.js +3 -11
  64. package/lib/cjs/resources/coupon_recipients.d.ts +26 -25
  65. package/lib/cjs/resources/coupon_recipients.js +3 -11
  66. package/lib/cjs/resources/coupons.d.ts +39 -38
  67. package/lib/cjs/resources/coupons.js +3 -11
  68. package/lib/cjs/resources/customer_addresses.d.ts +23 -22
  69. package/lib/cjs/resources/customer_addresses.js +3 -11
  70. package/lib/cjs/resources/customer_groups.d.ts +17 -16
  71. package/lib/cjs/resources/customer_groups.js +3 -11
  72. package/lib/cjs/resources/customer_password_resets.d.ts +19 -17
  73. package/lib/cjs/resources/customer_password_resets.js +6 -11
  74. package/lib/cjs/resources/customer_payment_sources.d.ts +37 -36
  75. package/lib/cjs/resources/customer_payment_sources.js +3 -11
  76. package/lib/cjs/resources/customer_subscriptions.d.ts +15 -14
  77. package/lib/cjs/resources/customer_subscriptions.js +3 -11
  78. package/lib/cjs/resources/customers.d.ts +37 -36
  79. package/lib/cjs/resources/customers.js +3 -11
  80. package/lib/cjs/resources/delivery_lead_times.d.ts +27 -26
  81. package/lib/cjs/resources/delivery_lead_times.js +3 -11
  82. package/lib/cjs/resources/event_callbacks.d.ts +15 -14
  83. package/lib/cjs/resources/event_callbacks.js +0 -8
  84. package/lib/cjs/resources/events.d.ts +13 -12
  85. package/lib/cjs/resources/events.js +0 -8
  86. package/lib/cjs/resources/exports.d.ts +27 -26
  87. package/lib/cjs/resources/exports.js +2 -10
  88. package/lib/cjs/resources/external_gateways.d.ts +32 -31
  89. package/lib/cjs/resources/external_gateways.js +3 -11
  90. package/lib/cjs/resources/external_payments.d.ts +23 -22
  91. package/lib/cjs/resources/external_payments.js +3 -11
  92. package/lib/cjs/resources/external_promotions.d.ts +66 -65
  93. package/lib/cjs/resources/external_promotions.js +3 -11
  94. package/lib/cjs/resources/external_tax_calculators.d.ts +19 -18
  95. package/lib/cjs/resources/external_tax_calculators.js +3 -11
  96. package/lib/cjs/resources/fixed_amount_promotions.d.ts +67 -66
  97. package/lib/cjs/resources/fixed_amount_promotions.js +3 -11
  98. package/lib/cjs/resources/fixed_price_promotions.d.ts +71 -70
  99. package/lib/cjs/resources/fixed_price_promotions.js +3 -11
  100. package/lib/cjs/resources/free_gift_promotions.d.ts +70 -69
  101. package/lib/cjs/resources/free_gift_promotions.js +3 -11
  102. package/lib/cjs/resources/free_shipping_promotions.d.ts +63 -62
  103. package/lib/cjs/resources/free_shipping_promotions.js +3 -11
  104. package/lib/cjs/resources/geocoders.d.ts +13 -12
  105. package/lib/cjs/resources/geocoders.js +0 -8
  106. package/lib/cjs/resources/gift_card_recipients.d.ts +26 -25
  107. package/lib/cjs/resources/gift_card_recipients.js +3 -11
  108. package/lib/cjs/resources/gift_cards.d.ts +71 -66
  109. package/lib/cjs/resources/gift_cards.js +15 -11
  110. package/lib/cjs/resources/google_geocoders.d.ts +16 -15
  111. package/lib/cjs/resources/google_geocoders.js +3 -11
  112. package/lib/cjs/resources/imports.d.ts +32 -31
  113. package/lib/cjs/resources/imports.js +2 -10
  114. package/lib/cjs/resources/in_stock_subscriptions.d.ts +38 -35
  115. package/lib/cjs/resources/in_stock_subscriptions.js +9 -11
  116. package/lib/cjs/resources/inventory_models.d.ts +26 -25
  117. package/lib/cjs/resources/inventory_models.js +3 -11
  118. package/lib/cjs/resources/inventory_return_locations.d.ts +22 -21
  119. package/lib/cjs/resources/inventory_return_locations.js +3 -11
  120. package/lib/cjs/resources/inventory_stock_locations.d.ts +25 -24
  121. package/lib/cjs/resources/inventory_stock_locations.js +3 -11
  122. package/lib/cjs/resources/klarna_gateways.d.ts +23 -22
  123. package/lib/cjs/resources/klarna_gateways.js +3 -11
  124. package/lib/cjs/resources/klarna_payments.d.ts +29 -27
  125. package/lib/cjs/resources/klarna_payments.js +6 -11
  126. package/lib/cjs/resources/line_item_options.d.ts +41 -40
  127. package/lib/cjs/resources/line_item_options.js +3 -11
  128. package/lib/cjs/resources/line_items.d.ts +96 -93
  129. package/lib/cjs/resources/line_items.js +9 -11
  130. package/lib/cjs/resources/manual_gateways.d.ts +15 -14
  131. package/lib/cjs/resources/manual_gateways.js +3 -11
  132. package/lib/cjs/resources/manual_tax_calculators.d.ts +21 -20
  133. package/lib/cjs/resources/manual_tax_calculators.js +3 -11
  134. package/lib/cjs/resources/markets.d.ts +62 -59
  135. package/lib/cjs/resources/markets.js +9 -11
  136. package/lib/cjs/resources/merchants.d.ts +19 -18
  137. package/lib/cjs/resources/merchants.js +3 -11
  138. package/lib/cjs/resources/order_amount_promotion_rules.d.ts +34 -33
  139. package/lib/cjs/resources/order_amount_promotion_rules.js +3 -11
  140. package/lib/cjs/resources/order_copies.d.ts +29 -28
  141. package/lib/cjs/resources/order_copies.js +3 -11
  142. package/lib/cjs/resources/order_factories.d.ts +21 -20
  143. package/lib/cjs/resources/order_factories.js +0 -8
  144. package/lib/cjs/resources/order_subscription_items.d.ts +40 -39
  145. package/lib/cjs/resources/order_subscription_items.js +3 -11
  146. package/lib/cjs/resources/order_subscriptions.d.ts +55 -51
  147. package/lib/cjs/resources/order_subscriptions.js +12 -11
  148. package/lib/cjs/resources/order_validation_rules.d.ts +13 -12
  149. package/lib/cjs/resources/order_validation_rules.js +0 -8
  150. package/lib/cjs/resources/orders.d.ts +263 -235
  151. package/lib/cjs/resources/orders.js +84 -11
  152. package/lib/cjs/resources/organization.d.ts +25 -24
  153. package/lib/cjs/resources/organization.js +1 -6
  154. package/lib/cjs/resources/packages.d.ts +31 -30
  155. package/lib/cjs/resources/packages.js +3 -11
  156. package/lib/cjs/resources/parcel_line_items.d.ts +23 -22
  157. package/lib/cjs/resources/parcel_line_items.js +3 -11
  158. package/lib/cjs/resources/parcels.d.ts +94 -93
  159. package/lib/cjs/resources/parcels.js +3 -11
  160. package/lib/cjs/resources/payment_gateways.d.ts +13 -12
  161. package/lib/cjs/resources/payment_gateways.js +0 -8
  162. package/lib/cjs/resources/payment_methods.d.ts +51 -48
  163. package/lib/cjs/resources/payment_methods.js +9 -11
  164. package/lib/cjs/resources/paypal_gateways.d.ts +18 -17
  165. package/lib/cjs/resources/paypal_gateways.js +3 -11
  166. package/lib/cjs/resources/paypal_payments.d.ts +32 -31
  167. package/lib/cjs/resources/paypal_payments.js +3 -11
  168. package/lib/cjs/resources/percentage_discount_promotions.d.ts +70 -69
  169. package/lib/cjs/resources/percentage_discount_promotions.js +3 -11
  170. package/lib/cjs/resources/price_frequency_tiers.d.ts +27 -26
  171. package/lib/cjs/resources/price_frequency_tiers.js +3 -11
  172. package/lib/cjs/resources/price_lists.d.ts +21 -20
  173. package/lib/cjs/resources/price_lists.js +3 -11
  174. package/lib/cjs/resources/price_tiers.d.ts +18 -17
  175. package/lib/cjs/resources/price_tiers.js +0 -8
  176. package/lib/cjs/resources/price_volume_tiers.d.ts +27 -26
  177. package/lib/cjs/resources/price_volume_tiers.js +3 -11
  178. package/lib/cjs/resources/prices.d.ts +40 -39
  179. package/lib/cjs/resources/prices.js +3 -11
  180. package/lib/cjs/resources/promotion_rules.d.ts +12 -11
  181. package/lib/cjs/resources/promotion_rules.js +0 -8
  182. package/lib/cjs/resources/promotions.d.ts +28 -27
  183. package/lib/cjs/resources/promotions.js +0 -8
  184. package/lib/cjs/resources/recurring_order_copies.d.ts +29 -28
  185. package/lib/cjs/resources/recurring_order_copies.js +3 -11
  186. package/lib/cjs/resources/refunds.d.ts +26 -25
  187. package/lib/cjs/resources/refunds.js +0 -8
  188. package/lib/cjs/resources/reserved_stocks.d.ts +14 -13
  189. package/lib/cjs/resources/reserved_stocks.js +0 -8
  190. package/lib/cjs/resources/return_line_items.d.ts +29 -27
  191. package/lib/cjs/resources/return_line_items.js +6 -11
  192. package/lib/cjs/resources/returns.d.ts +59 -49
  193. package/lib/cjs/resources/returns.js +30 -11
  194. package/lib/cjs/resources/satispay_gateways.d.ts +23 -22
  195. package/lib/cjs/resources/satispay_gateways.js +3 -11
  196. package/lib/cjs/resources/satispay_payments.d.ts +31 -29
  197. package/lib/cjs/resources/satispay_payments.js +6 -11
  198. package/lib/cjs/resources/shipments.d.ts +65 -57
  199. package/lib/cjs/resources/shipments.js +22 -9
  200. package/lib/cjs/resources/shipping_categories.d.ts +16 -15
  201. package/lib/cjs/resources/shipping_categories.js +3 -11
  202. package/lib/cjs/resources/shipping_method_tiers.d.ts +18 -17
  203. package/lib/cjs/resources/shipping_method_tiers.js +0 -8
  204. package/lib/cjs/resources/shipping_methods.d.ts +80 -77
  205. package/lib/cjs/resources/shipping_methods.js +9 -11
  206. package/lib/cjs/resources/shipping_weight_tiers.d.ts +26 -25
  207. package/lib/cjs/resources/shipping_weight_tiers.js +3 -11
  208. package/lib/cjs/resources/shipping_zones.d.ts +33 -32
  209. package/lib/cjs/resources/shipping_zones.js +3 -11
  210. package/lib/cjs/resources/sku_list_items.d.ts +27 -26
  211. package/lib/cjs/resources/sku_list_items.js +3 -11
  212. package/lib/cjs/resources/sku_list_promotion_rules.d.ts +38 -37
  213. package/lib/cjs/resources/sku_list_promotion_rules.js +3 -11
  214. package/lib/cjs/resources/sku_lists.d.ts +36 -35
  215. package/lib/cjs/resources/sku_lists.js +3 -11
  216. package/lib/cjs/resources/sku_options.d.ts +44 -43
  217. package/lib/cjs/resources/sku_options.js +3 -11
  218. package/lib/cjs/resources/skus.d.ts +57 -56
  219. package/lib/cjs/resources/skus.js +3 -11
  220. package/lib/cjs/resources/stock_items.d.ts +29 -28
  221. package/lib/cjs/resources/stock_items.js +3 -11
  222. package/lib/cjs/resources/stock_line_items.d.ts +18 -17
  223. package/lib/cjs/resources/stock_line_items.js +0 -8
  224. package/lib/cjs/resources/stock_locations.d.ts +30 -29
  225. package/lib/cjs/resources/stock_locations.js +3 -11
  226. package/lib/cjs/resources/stock_reservations.d.ts +18 -17
  227. package/lib/cjs/resources/stock_reservations.js +0 -8
  228. package/lib/cjs/resources/stock_transfers.d.ts +48 -42
  229. package/lib/cjs/resources/stock_transfers.js +18 -11
  230. package/lib/cjs/resources/stripe_gateways.d.ts +23 -22
  231. package/lib/cjs/resources/stripe_gateways.js +3 -11
  232. package/lib/cjs/resources/stripe_payments.d.ts +35 -32
  233. package/lib/cjs/resources/stripe_payments.js +9 -11
  234. package/lib/cjs/resources/subscription_models.d.ts +27 -26
  235. package/lib/cjs/resources/subscription_models.js +3 -11
  236. package/lib/cjs/resources/tags.d.ts +13 -12
  237. package/lib/cjs/resources/tags.js +3 -11
  238. package/lib/cjs/resources/tax_calculators.d.ts +14 -13
  239. package/lib/cjs/resources/tax_calculators.js +0 -8
  240. package/lib/cjs/resources/tax_categories.d.ts +31 -30
  241. package/lib/cjs/resources/tax_categories.js +3 -11
  242. package/lib/cjs/resources/tax_rules.d.ts +52 -51
  243. package/lib/cjs/resources/tax_rules.js +3 -11
  244. package/lib/cjs/resources/taxjar_accounts.d.ts +22 -21
  245. package/lib/cjs/resources/taxjar_accounts.js +3 -11
  246. package/lib/cjs/resources/transactions.d.ts +24 -23
  247. package/lib/cjs/resources/transactions.js +0 -8
  248. package/lib/cjs/resources/versions.d.ts +14 -14
  249. package/lib/cjs/resources/versions.js +0 -8
  250. package/lib/cjs/resources/voids.d.ts +26 -25
  251. package/lib/cjs/resources/voids.js +0 -8
  252. package/lib/cjs/resources/webhooks.d.ts +28 -26
  253. package/lib/cjs/resources/webhooks.js +6 -11
  254. package/lib/cjs/resources/wire_transfers.d.ts +17 -16
  255. package/lib/cjs/resources/wire_transfers.js +3 -11
  256. package/lib/cjs/static.d.ts +1 -1
  257. package/lib/cjs/util.d.ts +1 -3
  258. package/lib/esm/api.d.ts +37 -0
  259. package/lib/esm/api.js +0 -13
  260. package/lib/esm/client.d.ts +15 -8
  261. package/lib/esm/client.js +40 -40
  262. package/lib/esm/commercelayer.d.ts +3 -4
  263. package/lib/esm/commercelayer.js +7 -3
  264. package/lib/esm/common.d.ts +1 -0
  265. package/lib/esm/common.js +11 -2
  266. package/lib/esm/config.d.ts +1 -0
  267. package/lib/esm/config.js +3 -0
  268. package/lib/esm/debug.js +0 -4
  269. package/lib/esm/error.d.ts +3 -1
  270. package/lib/esm/error.js +35 -5
  271. package/lib/esm/index.d.ts +1 -1
  272. package/lib/esm/index.js +0 -2
  273. package/lib/esm/interceptor.d.ts +6 -2
  274. package/lib/esm/jsonapi.js +9 -2
  275. package/lib/esm/query.d.ts +9 -15
  276. package/lib/esm/query.js +2 -2
  277. package/lib/esm/resource.d.ts +30 -20
  278. package/lib/esm/resource.js +40 -10
  279. package/lib/esm/resources/addresses.d.ts +74 -73
  280. package/lib/esm/resources/addresses.js +3 -11
  281. package/lib/esm/resources/adjustments.d.ts +20 -19
  282. package/lib/esm/resources/adjustments.js +3 -11
  283. package/lib/esm/resources/adyen_gateways.d.ts +35 -34
  284. package/lib/esm/resources/adyen_gateways.js +3 -11
  285. package/lib/esm/resources/adyen_payments.d.ts +29 -27
  286. package/lib/esm/resources/adyen_payments.js +6 -11
  287. package/lib/esm/resources/application.d.ts +14 -13
  288. package/lib/esm/resources/application.js +2 -7
  289. package/lib/esm/resources/attachments.d.ts +81 -80
  290. package/lib/esm/resources/attachments.js +3 -11
  291. package/lib/esm/resources/authorizations.d.ts +47 -43
  292. package/lib/esm/resources/authorizations.js +10 -9
  293. package/lib/esm/resources/avalara_accounts.d.ts +32 -31
  294. package/lib/esm/resources/avalara_accounts.js +3 -11
  295. package/lib/esm/resources/axerve_gateways.d.ts +24 -23
  296. package/lib/esm/resources/axerve_gateways.js +3 -11
  297. package/lib/esm/resources/axerve_payments.d.ts +28 -26
  298. package/lib/esm/resources/axerve_payments.js +6 -11
  299. package/lib/esm/resources/billing_info_validation_rules.d.ts +17 -16
  300. package/lib/esm/resources/billing_info_validation_rules.js +3 -11
  301. package/lib/esm/resources/bing_geocoders.d.ts +16 -15
  302. package/lib/esm/resources/bing_geocoders.js +3 -11
  303. package/lib/esm/resources/braintree_gateways.d.ts +34 -33
  304. package/lib/esm/resources/braintree_gateways.js +3 -11
  305. package/lib/esm/resources/braintree_payments.d.ts +30 -29
  306. package/lib/esm/resources/braintree_payments.js +3 -11
  307. package/lib/esm/resources/bundles.d.ts +57 -54
  308. package/lib/esm/resources/bundles.js +9 -11
  309. package/lib/esm/resources/captures.d.ts +37 -34
  310. package/lib/esm/resources/captures.js +7 -9
  311. package/lib/esm/resources/carrier_accounts.d.ts +16 -15
  312. package/lib/esm/resources/carrier_accounts.js +0 -8
  313. package/lib/esm/resources/checkout_com_gateways.d.ts +25 -24
  314. package/lib/esm/resources/checkout_com_gateways.js +3 -11
  315. package/lib/esm/resources/checkout_com_payments.d.ts +41 -38
  316. package/lib/esm/resources/checkout_com_payments.js +9 -11
  317. package/lib/esm/resources/cleanups.d.ts +24 -23
  318. package/lib/esm/resources/cleanups.js +2 -10
  319. package/lib/esm/resources/coupon_codes_promotion_rules.d.ts +31 -30
  320. package/lib/esm/resources/coupon_codes_promotion_rules.js +3 -11
  321. package/lib/esm/resources/coupon_recipients.d.ts +26 -25
  322. package/lib/esm/resources/coupon_recipients.js +3 -11
  323. package/lib/esm/resources/coupons.d.ts +39 -38
  324. package/lib/esm/resources/coupons.js +3 -11
  325. package/lib/esm/resources/customer_addresses.d.ts +23 -22
  326. package/lib/esm/resources/customer_addresses.js +3 -11
  327. package/lib/esm/resources/customer_groups.d.ts +17 -16
  328. package/lib/esm/resources/customer_groups.js +3 -11
  329. package/lib/esm/resources/customer_password_resets.d.ts +19 -17
  330. package/lib/esm/resources/customer_password_resets.js +6 -11
  331. package/lib/esm/resources/customer_payment_sources.d.ts +37 -36
  332. package/lib/esm/resources/customer_payment_sources.js +3 -11
  333. package/lib/esm/resources/customer_subscriptions.d.ts +15 -14
  334. package/lib/esm/resources/customer_subscriptions.js +3 -11
  335. package/lib/esm/resources/customers.d.ts +37 -36
  336. package/lib/esm/resources/customers.js +3 -11
  337. package/lib/esm/resources/delivery_lead_times.d.ts +27 -26
  338. package/lib/esm/resources/delivery_lead_times.js +3 -11
  339. package/lib/esm/resources/event_callbacks.d.ts +15 -14
  340. package/lib/esm/resources/event_callbacks.js +0 -8
  341. package/lib/esm/resources/events.d.ts +13 -12
  342. package/lib/esm/resources/events.js +0 -8
  343. package/lib/esm/resources/exports.d.ts +27 -26
  344. package/lib/esm/resources/exports.js +2 -10
  345. package/lib/esm/resources/external_gateways.d.ts +32 -31
  346. package/lib/esm/resources/external_gateways.js +3 -11
  347. package/lib/esm/resources/external_payments.d.ts +23 -22
  348. package/lib/esm/resources/external_payments.js +3 -11
  349. package/lib/esm/resources/external_promotions.d.ts +66 -65
  350. package/lib/esm/resources/external_promotions.js +3 -11
  351. package/lib/esm/resources/external_tax_calculators.d.ts +19 -18
  352. package/lib/esm/resources/external_tax_calculators.js +3 -11
  353. package/lib/esm/resources/fixed_amount_promotions.d.ts +67 -66
  354. package/lib/esm/resources/fixed_amount_promotions.js +3 -11
  355. package/lib/esm/resources/fixed_price_promotions.d.ts +71 -70
  356. package/lib/esm/resources/fixed_price_promotions.js +3 -11
  357. package/lib/esm/resources/free_gift_promotions.d.ts +70 -69
  358. package/lib/esm/resources/free_gift_promotions.js +3 -11
  359. package/lib/esm/resources/free_shipping_promotions.d.ts +63 -62
  360. package/lib/esm/resources/free_shipping_promotions.js +3 -11
  361. package/lib/esm/resources/geocoders.d.ts +13 -12
  362. package/lib/esm/resources/geocoders.js +0 -8
  363. package/lib/esm/resources/gift_card_recipients.d.ts +26 -25
  364. package/lib/esm/resources/gift_card_recipients.js +3 -11
  365. package/lib/esm/resources/gift_cards.d.ts +71 -66
  366. package/lib/esm/resources/gift_cards.js +15 -11
  367. package/lib/esm/resources/google_geocoders.d.ts +16 -15
  368. package/lib/esm/resources/google_geocoders.js +3 -11
  369. package/lib/esm/resources/imports.d.ts +32 -31
  370. package/lib/esm/resources/imports.js +2 -10
  371. package/lib/esm/resources/in_stock_subscriptions.d.ts +38 -35
  372. package/lib/esm/resources/in_stock_subscriptions.js +9 -11
  373. package/lib/esm/resources/inventory_models.d.ts +26 -25
  374. package/lib/esm/resources/inventory_models.js +3 -11
  375. package/lib/esm/resources/inventory_return_locations.d.ts +22 -21
  376. package/lib/esm/resources/inventory_return_locations.js +3 -11
  377. package/lib/esm/resources/inventory_stock_locations.d.ts +25 -24
  378. package/lib/esm/resources/inventory_stock_locations.js +3 -11
  379. package/lib/esm/resources/klarna_gateways.d.ts +23 -22
  380. package/lib/esm/resources/klarna_gateways.js +3 -11
  381. package/lib/esm/resources/klarna_payments.d.ts +29 -27
  382. package/lib/esm/resources/klarna_payments.js +6 -11
  383. package/lib/esm/resources/line_item_options.d.ts +41 -40
  384. package/lib/esm/resources/line_item_options.js +3 -11
  385. package/lib/esm/resources/line_items.d.ts +96 -93
  386. package/lib/esm/resources/line_items.js +9 -11
  387. package/lib/esm/resources/manual_gateways.d.ts +15 -14
  388. package/lib/esm/resources/manual_gateways.js +3 -11
  389. package/lib/esm/resources/manual_tax_calculators.d.ts +21 -20
  390. package/lib/esm/resources/manual_tax_calculators.js +3 -11
  391. package/lib/esm/resources/markets.d.ts +62 -59
  392. package/lib/esm/resources/markets.js +9 -11
  393. package/lib/esm/resources/merchants.d.ts +19 -18
  394. package/lib/esm/resources/merchants.js +3 -11
  395. package/lib/esm/resources/order_amount_promotion_rules.d.ts +34 -33
  396. package/lib/esm/resources/order_amount_promotion_rules.js +3 -11
  397. package/lib/esm/resources/order_copies.d.ts +29 -28
  398. package/lib/esm/resources/order_copies.js +3 -11
  399. package/lib/esm/resources/order_factories.d.ts +21 -20
  400. package/lib/esm/resources/order_factories.js +0 -8
  401. package/lib/esm/resources/order_subscription_items.d.ts +40 -39
  402. package/lib/esm/resources/order_subscription_items.js +3 -11
  403. package/lib/esm/resources/order_subscriptions.d.ts +55 -51
  404. package/lib/esm/resources/order_subscriptions.js +12 -11
  405. package/lib/esm/resources/order_validation_rules.d.ts +13 -12
  406. package/lib/esm/resources/order_validation_rules.js +0 -8
  407. package/lib/esm/resources/orders.d.ts +263 -235
  408. package/lib/esm/resources/orders.js +84 -11
  409. package/lib/esm/resources/organization.d.ts +25 -24
  410. package/lib/esm/resources/organization.js +2 -7
  411. package/lib/esm/resources/packages.d.ts +31 -30
  412. package/lib/esm/resources/packages.js +3 -11
  413. package/lib/esm/resources/parcel_line_items.d.ts +23 -22
  414. package/lib/esm/resources/parcel_line_items.js +3 -11
  415. package/lib/esm/resources/parcels.d.ts +94 -93
  416. package/lib/esm/resources/parcels.js +3 -11
  417. package/lib/esm/resources/payment_gateways.d.ts +13 -12
  418. package/lib/esm/resources/payment_gateways.js +0 -8
  419. package/lib/esm/resources/payment_methods.d.ts +51 -48
  420. package/lib/esm/resources/payment_methods.js +9 -11
  421. package/lib/esm/resources/paypal_gateways.d.ts +18 -17
  422. package/lib/esm/resources/paypal_gateways.js +3 -11
  423. package/lib/esm/resources/paypal_payments.d.ts +32 -31
  424. package/lib/esm/resources/paypal_payments.js +3 -11
  425. package/lib/esm/resources/percentage_discount_promotions.d.ts +70 -69
  426. package/lib/esm/resources/percentage_discount_promotions.js +3 -11
  427. package/lib/esm/resources/price_frequency_tiers.d.ts +27 -26
  428. package/lib/esm/resources/price_frequency_tiers.js +3 -11
  429. package/lib/esm/resources/price_lists.d.ts +21 -20
  430. package/lib/esm/resources/price_lists.js +3 -11
  431. package/lib/esm/resources/price_tiers.d.ts +18 -17
  432. package/lib/esm/resources/price_tiers.js +0 -8
  433. package/lib/esm/resources/price_volume_tiers.d.ts +27 -26
  434. package/lib/esm/resources/price_volume_tiers.js +3 -11
  435. package/lib/esm/resources/prices.d.ts +40 -39
  436. package/lib/esm/resources/prices.js +3 -11
  437. package/lib/esm/resources/promotion_rules.d.ts +12 -11
  438. package/lib/esm/resources/promotion_rules.js +0 -8
  439. package/lib/esm/resources/promotions.d.ts +28 -27
  440. package/lib/esm/resources/promotions.js +0 -8
  441. package/lib/esm/resources/recurring_order_copies.d.ts +29 -28
  442. package/lib/esm/resources/recurring_order_copies.js +3 -11
  443. package/lib/esm/resources/refunds.d.ts +26 -25
  444. package/lib/esm/resources/refunds.js +0 -8
  445. package/lib/esm/resources/reserved_stocks.d.ts +14 -13
  446. package/lib/esm/resources/reserved_stocks.js +0 -8
  447. package/lib/esm/resources/return_line_items.d.ts +29 -27
  448. package/lib/esm/resources/return_line_items.js +6 -11
  449. package/lib/esm/resources/returns.d.ts +59 -49
  450. package/lib/esm/resources/returns.js +30 -11
  451. package/lib/esm/resources/satispay_gateways.d.ts +23 -22
  452. package/lib/esm/resources/satispay_gateways.js +3 -11
  453. package/lib/esm/resources/satispay_payments.d.ts +31 -29
  454. package/lib/esm/resources/satispay_payments.js +6 -11
  455. package/lib/esm/resources/shipments.d.ts +65 -57
  456. package/lib/esm/resources/shipments.js +22 -9
  457. package/lib/esm/resources/shipping_categories.d.ts +16 -15
  458. package/lib/esm/resources/shipping_categories.js +3 -11
  459. package/lib/esm/resources/shipping_method_tiers.d.ts +18 -17
  460. package/lib/esm/resources/shipping_method_tiers.js +0 -8
  461. package/lib/esm/resources/shipping_methods.d.ts +80 -77
  462. package/lib/esm/resources/shipping_methods.js +9 -11
  463. package/lib/esm/resources/shipping_weight_tiers.d.ts +26 -25
  464. package/lib/esm/resources/shipping_weight_tiers.js +3 -11
  465. package/lib/esm/resources/shipping_zones.d.ts +33 -32
  466. package/lib/esm/resources/shipping_zones.js +3 -11
  467. package/lib/esm/resources/sku_list_items.d.ts +27 -26
  468. package/lib/esm/resources/sku_list_items.js +3 -11
  469. package/lib/esm/resources/sku_list_promotion_rules.d.ts +38 -37
  470. package/lib/esm/resources/sku_list_promotion_rules.js +3 -11
  471. package/lib/esm/resources/sku_lists.d.ts +36 -35
  472. package/lib/esm/resources/sku_lists.js +3 -11
  473. package/lib/esm/resources/sku_options.d.ts +44 -43
  474. package/lib/esm/resources/sku_options.js +3 -11
  475. package/lib/esm/resources/skus.d.ts +57 -56
  476. package/lib/esm/resources/skus.js +3 -11
  477. package/lib/esm/resources/stock_items.d.ts +29 -28
  478. package/lib/esm/resources/stock_items.js +3 -11
  479. package/lib/esm/resources/stock_line_items.d.ts +18 -17
  480. package/lib/esm/resources/stock_line_items.js +0 -8
  481. package/lib/esm/resources/stock_locations.d.ts +30 -29
  482. package/lib/esm/resources/stock_locations.js +3 -11
  483. package/lib/esm/resources/stock_reservations.d.ts +18 -17
  484. package/lib/esm/resources/stock_reservations.js +0 -8
  485. package/lib/esm/resources/stock_transfers.d.ts +48 -42
  486. package/lib/esm/resources/stock_transfers.js +18 -11
  487. package/lib/esm/resources/stripe_gateways.d.ts +23 -22
  488. package/lib/esm/resources/stripe_gateways.js +3 -11
  489. package/lib/esm/resources/stripe_payments.d.ts +35 -32
  490. package/lib/esm/resources/stripe_payments.js +9 -11
  491. package/lib/esm/resources/subscription_models.d.ts +27 -26
  492. package/lib/esm/resources/subscription_models.js +3 -11
  493. package/lib/esm/resources/tags.d.ts +13 -12
  494. package/lib/esm/resources/tags.js +3 -11
  495. package/lib/esm/resources/tax_calculators.d.ts +14 -13
  496. package/lib/esm/resources/tax_calculators.js +0 -8
  497. package/lib/esm/resources/tax_categories.d.ts +31 -30
  498. package/lib/esm/resources/tax_categories.js +3 -11
  499. package/lib/esm/resources/tax_rules.d.ts +52 -51
  500. package/lib/esm/resources/tax_rules.js +3 -11
  501. package/lib/esm/resources/taxjar_accounts.d.ts +22 -21
  502. package/lib/esm/resources/taxjar_accounts.js +3 -11
  503. package/lib/esm/resources/transactions.d.ts +24 -23
  504. package/lib/esm/resources/transactions.js +0 -8
  505. package/lib/esm/resources/versions.d.ts +14 -14
  506. package/lib/esm/resources/versions.js +0 -8
  507. package/lib/esm/resources/voids.d.ts +26 -25
  508. package/lib/esm/resources/voids.js +0 -8
  509. package/lib/esm/resources/webhooks.d.ts +28 -26
  510. package/lib/esm/resources/webhooks.js +6 -11
  511. package/lib/esm/resources/wire_transfers.d.ts +17 -16
  512. package/lib/esm/resources/wire_transfers.js +3 -11
  513. package/lib/esm/static.d.ts +1 -1
  514. package/lib/esm/util.d.ts +1 -3
  515. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  516. package/lib/tsconfig.tsbuildinfo +1 -1
  517. package/package.json +8 -8
  518. package/lib/cjs/micro.d.ts +0 -4
  519. package/lib/cjs/micro.js +0 -13
  520. package/lib/esm/micro.d.ts +0 -4
  521. package/lib/esm/micro.js +0 -7
@@ -1,7 +1,7 @@
1
1
  import * as api from './api';
2
- import { ApiError } from './error';
2
+ import type { ApiError } from './error';
3
3
  import type { ErrorInterceptor, InterceptorType, RawResponseReader, RequestInterceptor, ResponseInterceptor } from './interceptor';
4
- import { ResourcesInitConfig } from './resource';
4
+ import { type ResourcesInitConfig } from './resource';
5
5
  declare const OPEN_API_SCHEMA_VERSION = "4.12.0";
6
6
  export { OPEN_API_SCHEMA_VERSION };
7
7
  type SdkConfig = {};
@@ -9,7 +9,6 @@ type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
9
9
  type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
10
10
  declare class CommerceLayerClient {
11
11
  #private;
12
- static get openApiSchemaVersion(): string;
13
12
  readonly openApiSchemaVersion = "4.12.0";
14
13
  addresses: api.Addresses;
15
14
  adjustments: api.Adjustments;
@@ -131,7 +130,7 @@ declare class CommerceLayerClient {
131
130
  constructor(config: CommerceLayerInitConfig);
132
131
  get currentOrganization(): string;
133
132
  private localConfig;
134
- config(config: CommerceLayerConfig): void;
133
+ config(config: CommerceLayerConfig): CommerceLayerClient;
135
134
  resources(): readonly string[];
136
135
  isApiError(error: any): error is ApiError;
137
136
  addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
@@ -19,15 +19,16 @@ const debug = Debug('commercelayer');
19
19
  const OPEN_API_SCHEMA_VERSION = '4.12.0';
20
20
  export { OPEN_API_SCHEMA_VERSION };
21
21
  class CommerceLayerClient {
22
- static get openApiSchemaVersion() { return OPEN_API_SCHEMA_VERSION; }
23
22
  // ##__CL_RESOURCES_DEF_STOP__##
24
23
  constructor(config) {
24
+ // static get openApiSchemaVersion(): string { return OPEN_API_SCHEMA_VERSION }
25
25
  this.openApiSchemaVersion = OPEN_API_SCHEMA_VERSION;
26
26
  _CommerceLayerClient_adapter.set(this, void 0);
27
27
  _CommerceLayerClient_organization.set(this, void 0);
28
28
  debug('new commercelayer instance %O', config);
29
29
  __classPrivateFieldSet(this, _CommerceLayerClient_adapter, new ResourceAdapter(config), "f");
30
30
  __classPrivateFieldSet(this, _CommerceLayerClient_organization, config.organization, "f");
31
+ // this.#environment = 'test'
31
32
  // ##__CL_RESOURCES_INIT_START__##
32
33
  // ##__CL_RESOURCES_INIT_TEMPLATE:: ##__TAB__####__TAB__##this.##__RESOURCE_TYPE__## = new api.##__RESOURCE_CLASS__##(this.#adapter)
33
34
  this.addresses = new api.Addresses(__classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f"));
@@ -150,6 +151,8 @@ class CommerceLayerClient {
150
151
  // ##__CL_RESOURCES_INIT_STOP__##
151
152
  }
152
153
  get currentOrganization() { return __classPrivateFieldGet(this, _CommerceLayerClient_organization, "f"); }
154
+ // get currentAccessToken(): string { return this.#adapter?.clientInstance?.currentAccessToken}
155
+ // get environment(): ApiMode { return this.#environment }
153
156
  localConfig(config) {
154
157
  if (config.organization)
155
158
  __classPrivateFieldSet(this, _CommerceLayerClient_organization, config.organization, "f");
@@ -163,6 +166,7 @@ class CommerceLayerClient {
163
166
  if (!config.organization)
164
167
  config.organization = this.currentOrganization;
165
168
  __classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").config(config);
169
+ return this;
166
170
  }
167
171
  resources() {
168
172
  return CommerceLayerStatic.resources();
@@ -178,7 +182,7 @@ class CommerceLayerClient {
178
182
  return __classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").interceptors.response.use(onFulfilled, onRejected);
179
183
  }
180
184
  removeInterceptor(type, id) {
181
- return __classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").interceptors[type].eject(id);
185
+ __classPrivateFieldGet(this, _CommerceLayerClient_adapter, "f").interceptors[type].eject(id);
182
186
  }
183
187
  addRawResponseReader(options) {
184
188
  const reader = {
@@ -199,7 +203,7 @@ class CommerceLayerClient {
199
203
  removeRawResponseReader(reader) {
200
204
  const id = (typeof reader === 'number') ? reader : reader === null || reader === void 0 ? void 0 : reader.id;
201
205
  if (id && (id >= 0))
202
- return this.removeInterceptor('response', id);
206
+ this.removeInterceptor('response', id);
203
207
  }
204
208
  }
205
209
  _CommerceLayerClient_adapter = new WeakMap(), _CommerceLayerClient_organization = new WeakMap();
@@ -2,3 +2,4 @@ import type { ResourceId, ResourceType } from './resource';
2
2
  declare const isResourceId: (resource: any) => resource is ResourceId;
3
3
  declare const isResourceType: (resource: any) => resource is ResourceType;
4
4
  export { isResourceId, isResourceType };
5
+ export type ObjectType = Record<string, any>;
package/lib/esm/common.js CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3
1
  import { resourceList } from './api';
4
2
  const isResourceId = (resource) => {
5
3
  return ((resource === null || resource === void 0 ? void 0 : resource.type) && resource.id) && resourceList.includes(resource.type);
@@ -8,3 +6,14 @@ const isResourceType = (resource) => {
8
6
  return resource && (typeof resource.type !== 'undefined') && resource.type && resourceList.includes(resource.type);
9
7
  };
10
8
  export { isResourceId, isResourceType };
9
+ /*
10
+ // Nullable types
11
+ type StringNullable = string | null
12
+ type NumberNullable = number | null
13
+ type BooleanNullable = boolean | null
14
+ type ResourceNullable<R extends Resource> = R | null
15
+ type ResourceArrayNullable<R extends Resource> = R[] | null
16
+
17
+
18
+ export type { StringNullable, NumberNullable, BooleanNullable, ResourceNullable, ResourceArrayNullable }
19
+ */
@@ -6,6 +6,7 @@ declare const config: {
6
6
  };
7
7
  readonly client: {
8
8
  readonly timeout: 15000;
9
+ readonly requiredAttributes: readonly ["organization", "accessToken"];
9
10
  };
10
11
  };
11
12
  export default config;
package/lib/esm/config.js CHANGED
@@ -1,11 +1,14 @@
1
+ // export type ApiMode = 'test' | 'live'
1
2
  const config = {
2
3
  default: {
4
+ // environment: 'test',
3
5
  domain: 'commercelayer.io',
4
6
  pageNumber: 1,
5
7
  pageSize: 10,
6
8
  },
7
9
  client: {
8
10
  timeout: 15000,
11
+ requiredAttributes: ['organization', 'accessToken'],
9
12
  }
10
13
  };
11
14
  export default config;
package/lib/esm/debug.js CHANGED
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- // import Debug from 'debug'
4
1
  /* Nope debugger */
5
2
  const debuggerFunction = (_pattern, ..._args) => {
6
3
  // console.log(_pattern)
@@ -8,7 +5,6 @@ const debuggerFunction = (_pattern, ..._args) => {
8
5
  let debuggerFactory = (_namespace) => debuggerFunction;
9
6
  /* Try loading 'debug' module */
10
7
  try {
11
- // eslint-disable-next-line @typescript-eslint/no-var-requires
12
8
  const debugModule = require('debug');
13
9
  if (debugModule && (typeof debugModule === 'function'))
14
10
  debuggerFactory = debugModule;
@@ -22,7 +22,9 @@ declare class ApiError extends SdkError {
22
22
  static isApiError(error: any): error is ApiError;
23
23
  errors: any[];
24
24
  status?: number;
25
+ statusText?: string;
25
26
  constructor(error: SdkError);
26
27
  first(): any;
27
28
  }
28
- export { SdkError, ApiError, ErrorType };
29
+ declare const handleError: (error: Error) => never;
30
+ export { SdkError, ApiError, ErrorType, handleError };
package/lib/esm/error.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
1
+ import axios from 'axios';
2
2
  var ErrorType;
3
3
  (function (ErrorType) {
4
4
  ErrorType["CLIENT"] = "client";
@@ -8,7 +8,6 @@ var ErrorType;
8
8
  ErrorType["CANCEL"] = "cancel";
9
9
  })(ErrorType || (ErrorType = {}));
10
10
  class SdkError extends Error {
11
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
12
11
  static isSdkError(error) {
13
12
  return error && [SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
14
13
  }
@@ -20,12 +19,11 @@ class SdkError extends Error {
20
19
  }
21
20
  SdkError.NAME = 'SdkError';
22
21
  class ApiError extends SdkError {
23
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24
22
  static isApiError(error) {
25
23
  return SdkError.isSdkError(error) && (error.name === ApiError.NAME) && (error.type === ErrorType.RESPONSE);
26
24
  }
27
25
  constructor(error) {
28
- super(Object.assign(Object.assign({}, error), { type: ErrorType.RESPONSE }));
26
+ super({ ...error, type: ErrorType.RESPONSE });
29
27
  this.errors = [];
30
28
  this.name = ApiError.NAME; // this.constructor.name
31
29
  }
@@ -35,4 +33,36 @@ class ApiError extends SdkError {
35
33
  }
36
34
  }
37
35
  ApiError.NAME = 'ApiError';
38
- export { SdkError, ApiError, ErrorType };
36
+ const handleError = (error) => {
37
+ let sdkError = new SdkError({ message: error.message });
38
+ if (axios.isAxiosError(error)) {
39
+ if (error.response) {
40
+ // The request was made and the server responded with a status code that falls out of the range of 2xx
41
+ const apiError = new ApiError(sdkError);
42
+ apiError.type = ErrorType.RESPONSE;
43
+ apiError.status = error.response.status;
44
+ apiError.statusText = error.response.statusText;
45
+ apiError.code = String(apiError.status);
46
+ apiError.errors = error.response.data.errors;
47
+ if (!apiError.message && apiError.statusText)
48
+ apiError.message = apiError.statusText;
49
+ sdkError = apiError;
50
+ }
51
+ else if (error.request) {
52
+ // The request was made but no response was received
53
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
54
+ sdkError.type = ErrorType.REQUEST;
55
+ sdkError.request = error.request;
56
+ }
57
+ else {
58
+ // Something happened in setting up the request that triggered an Error
59
+ sdkError.type = ErrorType.CLIENT;
60
+ }
61
+ }
62
+ else if (axios.isCancel(error))
63
+ sdkError.type = ErrorType.CANCEL;
64
+ else
65
+ sdkError.source = error;
66
+ throw sdkError;
67
+ };
68
+ export { SdkError, ApiError, ErrorType, handleError };
@@ -2,6 +2,6 @@ export { default, CommerceLayer } from './commercelayer';
2
2
  export type { CommerceLayerClient } from './commercelayer';
3
3
  export { CommerceLayerStatic } from './static';
4
4
  export type { QueryParamsRetrieve, QueryParamsList, QueryParams } from './query';
5
- export * from './model';
5
+ export type * from './model';
6
6
  export type { RequestObj, ResponseObj, ErrorObj, HeadersObj } from './interceptor';
7
7
  export type { SdkError, ApiError, ErrorType } from './error';
package/lib/esm/index.js CHANGED
@@ -2,5 +2,3 @@
2
2
  export { default, CommerceLayer } from './commercelayer';
3
3
  // Commerce Layer static functions
4
4
  export { CommerceLayerStatic } from './static';
5
- // Resource model types
6
- export * from './model';
@@ -1,4 +1,4 @@
1
- import { AxiosError, AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
1
+ import type { AxiosError, AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, RawAxiosResponseHeaders } from 'axios';
2
2
  type InterceptorManager = {
3
3
  request: AxiosInterceptorManager<AxiosRequestConfig>;
4
4
  response: AxiosInterceptorManager<any>;
@@ -7,7 +7,11 @@ type RequestObj = AxiosRequestConfig;
7
7
  type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
8
8
  type ResponseObj = AxiosResponse;
9
9
  type ResponseInterceptor = (response: ResponseObj) => ResponseObj;
10
- type HeadersObj = AxiosResponseHeaders | RawAxiosResponseHeaders;
10
+ type ApiHeadersList = 'x-ratelimit-limit' | 'x-ratelimit-count' | 'x-ratelimit-period' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
11
+ type ApiHeaders = {
12
+ [key in ApiHeadersList]: string | number | boolean;
13
+ };
14
+ type HeadersObj = (AxiosResponseHeaders | RawAxiosResponseHeaders) & ApiHeaders;
11
15
  type ErrorObj = AxiosError;
12
16
  type ErrorInterceptor = (error: ErrorObj) => ErrorObj;
13
17
  type InterceptorType = 'request' | 'response';
@@ -28,7 +28,11 @@ const denormalizeResource = (res, included) => {
28
28
  debug('denormalize resource: %O, %o', res, included || {});
29
29
  if (!res)
30
30
  return res;
31
- const resource = Object.assign({ id: res.id, type: res.type }, res.attributes);
31
+ const resource = {
32
+ id: res.id,
33
+ type: res.type,
34
+ ...res.attributes,
35
+ };
32
36
  if (res.relationships)
33
37
  Object.keys(res.relationships).forEach(key => {
34
38
  const rel = res.relationships[key].data;
@@ -53,7 +57,10 @@ const normalize = (resource) => {
53
57
  if (['type', 'id'].includes(field))
54
58
  continue;
55
59
  const value = resource[field];
56
- if (value && isResourceType(value) && value.id === null) {
60
+ if (Array.isArray(value) && (value.length === 1) && isResourceType(value[0]) && (value[0].id === null)) {
61
+ relationships[field] = { data: [] };
62
+ }
63
+ else if (value && isResourceType(value) && (value.id === null)) {
57
64
  relationships[field] = { data: null };
58
65
  }
59
66
  else if (value && (isResourceId(value) || (Array.isArray(value) && isResourceId(value[0])))) {
@@ -1,23 +1,17 @@
1
- import { ResourceType } from "./resource";
1
+ import type { ResourceType } from "./resource";
2
+ type QueryFilter = Record<string, string | number | boolean>;
2
3
  interface QueryParamsRetrieve {
3
4
  include?: string[];
4
- fields?: string[] | {
5
- [key: string]: string[];
6
- };
5
+ fields?: string[] | Record<string, string[]>;
7
6
  }
8
7
  interface QueryParamsList extends QueryParamsRetrieve {
9
- sort?: string[] | {
10
- [key: string]: 'asc' | 'desc';
11
- };
12
- filters?: {
13
- [key: string]: string | number | boolean;
14
- };
8
+ sort?: string[] | Record<string, 'asc' | 'desc'>;
9
+ filters?: QueryFilter;
15
10
  pageNumber?: number;
16
11
  pageSize?: number;
17
12
  }
18
13
  type QueryParams = QueryParamsRetrieve | QueryParamsList;
19
- export { QueryParamsRetrieve, QueryParamsList, QueryParams };
20
- declare const generateQueryStringParams: (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType) => {
21
- [key: string]: string;
22
- };
23
- export { generateQueryStringParams };
14
+ export type { QueryParamsRetrieve, QueryParamsList, QueryParams, QueryFilter };
15
+ declare const isParamsList: (params: any) => params is QueryParamsList;
16
+ declare const generateQueryStringParams: (params: QueryParamsRetrieve | QueryParamsList | undefined, res: string | ResourceType) => Record<string, string>;
17
+ export { generateQueryStringParams, isParamsList };
package/lib/esm/query.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import Debug from './debug';
2
2
  const debug = Debug('query');
3
3
  const isParamsList = (params) => {
4
- return (params.filters || params.pageNumber || params.pageSize || params.sort);
4
+ return params && (params.filters || params.pageNumber || params.pageSize || params.sort);
5
5
  };
6
6
  const generateQueryStringParams = (params, res) => {
7
7
  debug('generate query string params: %O, %O', params, res);
@@ -42,4 +42,4 @@ const generateQueryStringParams = (params, res) => {
42
42
  debug('query string params: %O', qp);
43
43
  return qp;
44
44
  };
45
- export { generateQueryStringParams };
45
+ export { generateQueryStringParams, isParamsList };
@@ -1,8 +1,7 @@
1
1
  import { type ApiClientInitConfig } from './client';
2
- import { type QueryParamsRetrieve, type QueryParamsList } from './query';
2
+ import type { QueryParamsRetrieve, QueryParamsList, QueryFilter, QueryParams } from './query';
3
3
  import type { ResourceTypeLock } from './api';
4
4
  import type { InterceptorManager } from './interceptor';
5
- import type { QueryParams } from '.';
6
5
  type ResourceNull = {
7
6
  id: null;
8
7
  } & ResourceType;
@@ -14,23 +13,19 @@ interface ResourceType {
14
13
  interface ResourceId extends ResourceType {
15
14
  readonly id: string;
16
15
  }
17
- interface Resource extends ResourceId {
18
- reference?: string;
19
- reference_origin?: string;
16
+ interface ResourceBase {
17
+ reference?: string | null;
18
+ reference_origin?: string | null;
20
19
  metadata?: Metadata;
20
+ }
21
+ interface Resource extends ResourceBase, ResourceId {
21
22
  readonly created_at: string;
22
23
  readonly updated_at: string;
23
24
  }
24
- interface ResourceCreate {
25
- reference?: string;
26
- reference_origin?: string;
27
- metadata?: Metadata;
25
+ interface ResourceCreate extends ResourceBase {
28
26
  }
29
- interface ResourceUpdate {
27
+ interface ResourceUpdate extends ResourceBase {
30
28
  readonly id: string;
31
- reference?: string;
32
- reference_origin?: string;
33
- metadata?: Metadata;
34
29
  }
35
30
  type ListMeta = {
36
31
  readonly pageCount: number;
@@ -44,8 +39,14 @@ declare class ListResponse<R> extends Array<R> {
44
39
  first(): R | undefined;
45
40
  last(): R | undefined;
46
41
  get(index: number): R | undefined;
42
+ hasNextPage(): boolean;
43
+ hasPrevPage(): boolean;
44
+ getRecordCount(): number;
45
+ getPageCount(): number;
46
+ get recordCount(): number;
47
+ get pageCount(): number;
47
48
  }
48
- export type { Metadata, ResourceType, ResourceId, Resource, ResourceCreate, ResourceUpdate, ListResponse, ResourceRel };
49
+ export type { Metadata, ResourceType, ResourceId, Resource, ResourceCreate, ResourceUpdate, ListResponse, ListMeta, ResourceRel };
49
50
  type ResourceAdapterConfig = {};
50
51
  type ResourcesInitConfig = ResourceAdapterConfig & ApiClientInitConfig;
51
52
  type ResourcesConfig = Partial<ResourcesInitConfig>;
@@ -54,7 +55,7 @@ declare class ResourceAdapter {
54
55
  constructor(config: ResourcesInitConfig);
55
56
  get interceptors(): InterceptorManager;
56
57
  private localConfig;
57
- config(config: ResourcesConfig): void;
58
+ config(config: ResourcesConfig): ResourceAdapter;
58
59
  singleton<R extends Resource>(resource: ResourceType, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
59
60
  retrieve<R extends Resource>(resource: ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
60
61
  list<R extends Resource>(resource: ResourceType, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
@@ -63,13 +64,22 @@ declare class ResourceAdapter {
63
64
  delete(resource: ResourceId, options?: ResourcesConfig): Promise<void>;
64
65
  fetch<R extends Resource>(resource: string | ResourceType, path: string, params?: QueryParams, options?: ResourcesConfig): Promise<R | ListResponse<R>>;
65
66
  }
66
- declare abstract class ApiResource {
67
+ declare abstract class ApiResourceBase<R extends Resource> {
67
68
  static readonly TYPE: ResourceTypeLock;
68
- protected resources: ResourceAdapter;
69
+ protected readonly resources: ResourceAdapter;
69
70
  constructor(adapter: ResourceAdapter);
70
71
  abstract relationship(id: string | ResourceId | null): ResourceRel;
71
- abstract type(): string;
72
- update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Resource>;
72
+ abstract type(): ResourceTypeLock;
73
+ update(resource: ResourceUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
74
+ }
75
+ declare abstract class ApiResource<R extends Resource> extends ApiResourceBase<R> {
76
+ retrieve(id: string | ResourceId, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
77
+ list(params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<R>>;
78
+ count(filter?: QueryFilter | QueryParamsList, options?: ResourcesConfig): Promise<number>;
79
+ }
80
+ declare abstract class ApiSingleton<R extends Resource> extends ApiResourceBase<R> {
81
+ retrieve(params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<R>;
73
82
  }
74
83
  export default ResourceAdapter;
75
- export { ApiResource, type ResourcesConfig, type ResourcesInitConfig };
84
+ export { ApiResource, ApiSingleton };
85
+ export type { ResourcesConfig, ResourcesInitConfig };
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _ResourceAdapter_client, _ResourceAdapter_config;
13
13
  import ApiClient from './client';
14
14
  import { denormalize, normalize } from './jsonapi';
15
- import { generateQueryStringParams } from './query';
15
+ import { generateQueryStringParams, isParamsList } from './query';
16
16
  import config from './config';
17
17
  import Debug from './debug';
18
18
  const debug = Debug('resource');
@@ -24,6 +24,12 @@ class ListResponse extends Array {
24
24
  first() { return this.length ? this[0] : undefined; }
25
25
  last() { return this.length ? this[this.length - 1] : undefined; }
26
26
  get(index) { return (this.length && (index >= 0)) ? this[index] : undefined; }
27
+ hasNextPage() { return (this.meta.currentPage < this.meta.pageCount); }
28
+ hasPrevPage() { return (this.meta.currentPage > 1); }
29
+ getRecordCount() { return this.meta.recordCount; }
30
+ getPageCount() { return this.meta.pageCount; }
31
+ get recordCount() { return this.meta.recordCount; }
32
+ get pageCount() { return this.meta.pageCount; }
27
33
  }
28
34
  class ResourceAdapter {
29
35
  constructor(config) {
@@ -43,13 +49,19 @@ class ResourceAdapter {
43
49
  this.localConfig(config);
44
50
  // Client config
45
51
  __classPrivateFieldGet(this, _ResourceAdapter_client, "f").config(config);
52
+ return this;
46
53
  }
54
+ /*
55
+ get clientInstance(): ApiClient {
56
+ return this.#client
57
+ }
58
+ */
47
59
  async singleton(resource, params, options) {
48
60
  debug('singleton: %o, %O, %O', resource, params || {}, options || {});
49
61
  const queryParams = generateQueryStringParams(params, resource);
50
62
  if (options === null || options === void 0 ? void 0 : options.params)
51
63
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
52
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, Object.assign(Object.assign({}, options), { params: queryParams }));
64
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
53
65
  const r = denormalize(res);
54
66
  return r;
55
67
  }
@@ -58,7 +70,7 @@ class ResourceAdapter {
58
70
  const queryParams = generateQueryStringParams(params, resource);
59
71
  if (options === null || options === void 0 ? void 0 : options.params)
60
72
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
61
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}/${resource.id}`, undefined, Object.assign(Object.assign({}, options), { params: queryParams }));
73
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}/${resource.id}`, undefined, { ...options, params: queryParams });
62
74
  const r = denormalize(res);
63
75
  return r;
64
76
  }
@@ -68,7 +80,7 @@ class ResourceAdapter {
68
80
  const queryParams = generateQueryStringParams(params, resource);
69
81
  if (options === null || options === void 0 ? void 0 : options.params)
70
82
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
71
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, Object.assign(Object.assign({}, options), { params: queryParams }));
83
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', `${resource.type}`, undefined, { ...options, params: queryParams });
72
84
  const r = denormalize(res);
73
85
  const meta = {
74
86
  pageCount: Number((_a = res.meta) === null || _a === void 0 ? void 0 : _a.page_count),
@@ -84,7 +96,7 @@ class ResourceAdapter {
84
96
  if (options === null || options === void 0 ? void 0 : options.params)
85
97
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
86
98
  const data = normalize(resource);
87
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('post', resource.type, data, Object.assign(Object.assign({}, options), { params: queryParams }));
99
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('post', resource.type, data, { ...options, params: queryParams });
88
100
  const r = denormalize(res);
89
101
  return r;
90
102
  }
@@ -94,7 +106,7 @@ class ResourceAdapter {
94
106
  if (options === null || options === void 0 ? void 0 : options.params)
95
107
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
96
108
  const data = normalize(resource);
97
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('patch', `${resource.type}/${resource.id}`, data, Object.assign(Object.assign({}, options), { params: queryParams }));
109
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('patch', `${resource.type}/${resource.id}`, data, { ...options, params: queryParams });
98
110
  const r = denormalize(res);
99
111
  return r;
100
112
  }
@@ -108,7 +120,7 @@ class ResourceAdapter {
108
120
  const queryParams = generateQueryStringParams(params, resource);
109
121
  if (options === null || options === void 0 ? void 0 : options.params)
110
122
  Object.assign(queryParams, options === null || options === void 0 ? void 0 : options.params);
111
- const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', path, undefined, Object.assign(Object.assign({}, options), { params: queryParams }));
123
+ const res = await __classPrivateFieldGet(this, _ResourceAdapter_client, "f").request('get', path, undefined, { ...options, params: queryParams });
112
124
  const r = denormalize(res);
113
125
  if (Array.isArray(r)) {
114
126
  const p = params;
@@ -125,15 +137,33 @@ class ResourceAdapter {
125
137
  }
126
138
  }
127
139
  _ResourceAdapter_client = new WeakMap(), _ResourceAdapter_config = new WeakMap();
128
- class ApiResource {
140
+ class ApiResourceBase {
129
141
  constructor(adapter) {
130
142
  debug('new resource instance: %s', this.type());
131
143
  this.resources = adapter;
132
144
  }
133
145
  // reference, reference_origin and metadata attributes are always updatable
134
146
  async update(resource, params, options) {
135
- return this.resources.update(Object.assign(Object.assign({}, resource), { type: this.type() }), params, options);
147
+ return this.resources.update({ ...resource, type: this.type() }, params, options);
148
+ }
149
+ }
150
+ class ApiResource extends ApiResourceBase {
151
+ async retrieve(id, params, options) {
152
+ return this.resources.retrieve((typeof id === 'string') ? { type: this.type(), id } : id, params, options);
153
+ }
154
+ async list(params, options) {
155
+ return this.resources.list({ type: this.type() }, params, options);
156
+ }
157
+ async count(filter, options) {
158
+ const params = { filters: isParamsList(filter) ? filter.filters : filter, pageNumber: 1, pageSize: 1 };
159
+ const response = await this.list(params, options);
160
+ return Promise.resolve(response.meta.recordCount);
161
+ }
162
+ }
163
+ class ApiSingleton extends ApiResourceBase {
164
+ async retrieve(params, options) {
165
+ return this.resources.singleton({ type: this.type() }, params, options);
136
166
  }
137
167
  }
138
168
  export default ResourceAdapter;
139
- export { ApiResource };
169
+ export { ApiResource, ApiSingleton };