@commercelayer/sdk 5.0.0-alpha.1 → 5.0.0-alpha.4

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 (219) hide show
  1. package/README.md +69 -33
  2. package/lib/api.d.ts +1 -103
  3. package/lib/client.d.ts +1 -31
  4. package/lib/client.js +1 -1
  5. package/lib/commercelayer.d.ts +1 -122
  6. package/lib/commercelayer.js +1 -1
  7. package/lib/common.d.ts +1 -4
  8. package/lib/config.d.ts +1 -11
  9. package/lib/debug.d.ts +1 -3
  10. package/lib/debug.js +1 -1
  11. package/lib/error.d.ts +1 -26
  12. package/lib/error.js +1 -1
  13. package/lib/index.d.ts +1 -7
  14. package/lib/interceptor.d.ts +1 -19
  15. package/lib/jsonapi.d.ts +1 -5
  16. package/lib/jsonapi.js +1 -1
  17. package/lib/model.d.ts +1 -101
  18. package/lib/query.d.ts +1 -23
  19. package/lib/query.js +1 -1
  20. package/lib/resource.d.ts +1 -76
  21. package/lib/resource.js +1 -1
  22. package/lib/resources/addresses.d.ts +1 -88
  23. package/lib/resources/addresses.js +1 -1
  24. package/lib/resources/adjustments.d.ts +1 -35
  25. package/lib/resources/adjustments.js +1 -1
  26. package/lib/resources/adyen_gateways.d.ts +1 -47
  27. package/lib/resources/adyen_gateways.js +1 -1
  28. package/lib/resources/adyen_payments.d.ts +1 -44
  29. package/lib/resources/adyen_payments.js +1 -1
  30. package/lib/resources/application.d.ts +1 -21
  31. package/lib/resources/application.js +1 -1
  32. package/lib/resources/attachments.d.ts +1 -156
  33. package/lib/resources/attachments.js +1 -1
  34. package/lib/resources/authorizations.d.ts +1 -57
  35. package/lib/resources/authorizations.js +1 -1
  36. package/lib/resources/avalara_accounts.d.ts +1 -52
  37. package/lib/resources/avalara_accounts.js +1 -1
  38. package/lib/resources/billing_info_validation_rules.d.ts +1 -32
  39. package/lib/resources/billing_info_validation_rules.js +1 -1
  40. package/lib/resources/bing_geocoders.d.ts +1 -35
  41. package/lib/resources/bing_geocoders.js +1 -1
  42. package/lib/resources/braintree_gateways.d.ts +1 -56
  43. package/lib/resources/braintree_gateways.js +1 -1
  44. package/lib/resources/braintree_payments.d.ts +1 -47
  45. package/lib/resources/braintree_payments.js +1 -1
  46. package/lib/resources/bundles.d.ts +1 -74
  47. package/lib/resources/bundles.js +1 -1
  48. package/lib/resources/captures.d.ts +1 -48
  49. package/lib/resources/captures.js +1 -1
  50. package/lib/resources/carrier_accounts.d.ts +1 -26
  51. package/lib/resources/carrier_accounts.js +1 -1
  52. package/lib/resources/checkout_com_gateways.d.ts +1 -45
  53. package/lib/resources/checkout_com_gateways.js +1 -1
  54. package/lib/resources/checkout_com_payments.d.ts +1 -50
  55. package/lib/resources/checkout_com_payments.js +1 -1
  56. package/lib/resources/coupon_codes_promotion_rules.d.ts +1 -59
  57. package/lib/resources/coupon_codes_promotion_rules.js +1 -1
  58. package/lib/resources/coupon_recipients.d.ts +1 -44
  59. package/lib/resources/coupon_recipients.js +1 -1
  60. package/lib/resources/coupons.d.ts +1 -45
  61. package/lib/resources/coupons.js +1 -1
  62. package/lib/resources/customer_addresses.d.ts +1 -41
  63. package/lib/resources/customer_addresses.js +1 -1
  64. package/lib/resources/customer_groups.d.ts +1 -36
  65. package/lib/resources/customer_groups.js +1 -1
  66. package/lib/resources/customer_password_resets.d.ts +1 -33
  67. package/lib/resources/customer_password_resets.js +1 -1
  68. package/lib/resources/customer_payment_sources.d.ts +1 -70
  69. package/lib/resources/customer_payment_sources.js +1 -1
  70. package/lib/resources/customer_subscriptions.d.ts +1 -28
  71. package/lib/resources/customer_subscriptions.js +1 -1
  72. package/lib/resources/customers.d.ts +1 -60
  73. package/lib/resources/customers.js +1 -1
  74. package/lib/resources/delivery_lead_times.d.ts +1 -51
  75. package/lib/resources/delivery_lead_times.js +1 -1
  76. package/lib/resources/event_callbacks.d.ts +1 -24
  77. package/lib/resources/event_callbacks.js +1 -1
  78. package/lib/resources/external_gateways.d.ts +1 -49
  79. package/lib/resources/external_gateways.js +1 -1
  80. package/lib/resources/external_payments.d.ts +1 -43
  81. package/lib/resources/external_payments.js +1 -1
  82. package/lib/resources/external_promotions.d.ts +1 -86
  83. package/lib/resources/external_promotions.js +1 -1
  84. package/lib/resources/external_tax_calculators.d.ts +1 -44
  85. package/lib/resources/external_tax_calculators.js +1 -1
  86. package/lib/resources/fixed_amount_promotions.d.ts +1 -88
  87. package/lib/resources/fixed_amount_promotions.js +1 -1
  88. package/lib/resources/fixed_price_promotions.d.ts +1 -99
  89. package/lib/resources/fixed_price_promotions.js +1 -1
  90. package/lib/resources/free_gift_promotions.d.ts +1 -97
  91. package/lib/resources/free_gift_promotions.js +1 -1
  92. package/lib/resources/free_shipping_promotions.d.ts +1 -83
  93. package/lib/resources/free_shipping_promotions.js +1 -1
  94. package/lib/resources/geocoders.d.ts +1 -24
  95. package/lib/resources/geocoders.js +1 -1
  96. package/lib/resources/gift_card_recipients.d.ts +1 -44
  97. package/lib/resources/gift_card_recipients.js +1 -1
  98. package/lib/resources/gift_cards.d.ts +1 -82
  99. package/lib/resources/gift_cards.js +1 -1
  100. package/lib/resources/google_geocoders.d.ts +1 -35
  101. package/lib/resources/google_geocoders.js +1 -1
  102. package/lib/resources/imports.d.ts +1 -40
  103. package/lib/resources/imports.js +1 -1
  104. package/lib/resources/in_stock_subscriptions.d.ts +1 -59
  105. package/lib/resources/in_stock_subscriptions.js +1 -1
  106. package/lib/resources/inventory_models.d.ts +1 -42
  107. package/lib/resources/inventory_models.js +1 -1
  108. package/lib/resources/inventory_return_locations.d.ts +1 -43
  109. package/lib/resources/inventory_return_locations.js +1 -1
  110. package/lib/resources/inventory_stock_locations.d.ts +1 -46
  111. package/lib/resources/inventory_stock_locations.js +1 -1
  112. package/lib/resources/klarna_gateways.d.ts +1 -44
  113. package/lib/resources/klarna_gateways.js +1 -1
  114. package/lib/resources/klarna_payments.d.ts +1 -41
  115. package/lib/resources/klarna_payments.js +1 -1
  116. package/lib/resources/line_item_options.d.ts +1 -57
  117. package/lib/resources/line_item_options.js +1 -1
  118. package/lib/resources/line_items.d.ts +1 -125
  119. package/lib/resources/line_items.js +1 -1
  120. package/lib/resources/manual_gateways.d.ts +1 -33
  121. package/lib/resources/manual_gateways.js +1 -1
  122. package/lib/resources/manual_tax_calculators.d.ts +1 -49
  123. package/lib/resources/manual_tax_calculators.js +1 -1
  124. package/lib/resources/markets.d.ts +1 -81
  125. package/lib/resources/markets.js +1 -1
  126. package/lib/resources/merchants.d.ts +1 -38
  127. package/lib/resources/merchants.js +1 -1
  128. package/lib/resources/order_amount_promotion_rules.d.ts +1 -56
  129. package/lib/resources/order_amount_promotion_rules.js +1 -1
  130. package/lib/resources/order_copies.d.ts +1 -45
  131. package/lib/resources/order_copies.js +1 -1
  132. package/lib/resources/order_subscriptions.d.ts +1 -67
  133. package/lib/resources/order_subscriptions.js +1 -1
  134. package/lib/resources/order_validation_rules.d.ts +1 -20
  135. package/lib/resources/order_validation_rules.js +1 -1
  136. package/lib/resources/orders.d.ts +1 -271
  137. package/lib/resources/orders.js +1 -1
  138. package/lib/resources/organization.d.ts +1 -32
  139. package/lib/resources/organization.js +1 -1
  140. package/lib/resources/packages.d.ts +1 -56
  141. package/lib/resources/packages.js +1 -1
  142. package/lib/resources/parcel_line_items.d.ts +1 -49
  143. package/lib/resources/parcel_line_items.js +1 -1
  144. package/lib/resources/parcels.d.ts +1 -108
  145. package/lib/resources/parcels.js +1 -1
  146. package/lib/resources/payment_gateways.d.ts +1 -21
  147. package/lib/resources/payment_gateways.js +1 -1
  148. package/lib/resources/payment_methods.d.ts +1 -59
  149. package/lib/resources/payment_methods.js +1 -1
  150. package/lib/resources/paypal_gateways.d.ts +1 -39
  151. package/lib/resources/paypal_gateways.js +1 -1
  152. package/lib/resources/paypal_payments.d.ts +1 -47
  153. package/lib/resources/paypal_payments.js +1 -1
  154. package/lib/resources/percentage_discount_promotions.d.ts +1 -97
  155. package/lib/resources/percentage_discount_promotions.js +1 -1
  156. package/lib/resources/price_lists.d.ts +1 -39
  157. package/lib/resources/price_lists.js +1 -1
  158. package/lib/resources/prices.d.ts +1 -57
  159. package/lib/resources/prices.js +1 -1
  160. package/lib/resources/promotion_rules.d.ts +1 -24
  161. package/lib/resources/promotion_rules.js +1 -1
  162. package/lib/resources/promotions.d.ts +1 -41
  163. package/lib/resources/promotions.js +1 -1
  164. package/lib/resources/refunds.d.ts +1 -34
  165. package/lib/resources/refunds.js +1 -1
  166. package/lib/resources/return_line_items.d.ts +1 -49
  167. package/lib/resources/return_line_items.js +1 -1
  168. package/lib/resources/returns.d.ts +1 -72
  169. package/lib/resources/returns.js +1 -1
  170. package/lib/resources/shipments.d.ts +1 -89
  171. package/lib/resources/shipments.js +1 -1
  172. package/lib/resources/shipping_categories.d.ts +1 -33
  173. package/lib/resources/shipping_categories.js +1 -1
  174. package/lib/resources/shipping_methods.d.ts +1 -74
  175. package/lib/resources/shipping_methods.js +1 -1
  176. package/lib/resources/shipping_zones.d.ts +1 -48
  177. package/lib/resources/shipping_zones.js +1 -1
  178. package/lib/resources/sku_list_items.d.ts +1 -47
  179. package/lib/resources/sku_list_items.js +1 -1
  180. package/lib/resources/sku_list_promotion_rules.d.ts +1 -68
  181. package/lib/resources/sku_list_promotion_rules.js +1 -1
  182. package/lib/resources/sku_lists.d.ts +1 -49
  183. package/lib/resources/sku_lists.js +1 -1
  184. package/lib/resources/sku_options.d.ts +1 -56
  185. package/lib/resources/sku_options.js +1 -1
  186. package/lib/resources/skus.d.ts +1 -78
  187. package/lib/resources/skus.js +1 -1
  188. package/lib/resources/stock_items.d.ts +1 -49
  189. package/lib/resources/stock_items.js +1 -1
  190. package/lib/resources/stock_line_items.d.ts +1 -29
  191. package/lib/resources/stock_line_items.js +1 -1
  192. package/lib/resources/stock_locations.d.ts +1 -57
  193. package/lib/resources/stock_locations.js +1 -1
  194. package/lib/resources/stock_transfers.d.ts +1 -71
  195. package/lib/resources/stock_transfers.js +1 -1
  196. package/lib/resources/stripe_gateways.d.ts +1 -38
  197. package/lib/resources/stripe_gateways.js +1 -1
  198. package/lib/resources/stripe_payments.d.ts +1 -42
  199. package/lib/resources/stripe_payments.js +1 -1
  200. package/lib/resources/tax_calculators.d.ts +1 -27
  201. package/lib/resources/tax_calculators.js +1 -1
  202. package/lib/resources/tax_categories.d.ts +1 -59
  203. package/lib/resources/tax_categories.js +1 -1
  204. package/lib/resources/tax_rules.d.ts +1 -69
  205. package/lib/resources/tax_rules.js +1 -1
  206. package/lib/resources/taxjar_accounts.d.ts +1 -43
  207. package/lib/resources/taxjar_accounts.js +1 -1
  208. package/lib/resources/transactions.d.ts +1 -31
  209. package/lib/resources/transactions.js +1 -1
  210. package/lib/resources/voids.d.ts +1 -34
  211. package/lib/resources/voids.js +1 -1
  212. package/lib/resources/webhooks.d.ts +1 -42
  213. package/lib/resources/webhooks.js +1 -1
  214. package/lib/resources/wire_transfers.d.ts +1 -32
  215. package/lib/resources/wire_transfers.js +1 -1
  216. package/lib/static.d.ts +1 -6
  217. package/lib/static.js +1 -1
  218. package/lib/util.d.ts +1 -2
  219. package/package.json +19 -22
package/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Commerce Layer JS SDK
2
2
 
3
- A JavaScript Library wrapper that makes it quick and easy to interact with the [Commerce Layer API](https://docs.commercelayer.io/api/).
3
+ [![Version](https://img.shields.io/npm/v/@commercelayer/sdk.svg)](https://npmjs.org/package/@commercelayer/sdk)
4
+ [![Downloads/week](https://img.shields.io/npm/dw/@commercelayer/sdk.svg)](https://npmjs.org/package/@commercelayer/sdk)
5
+ [![License](https://img.shields.io/npm/l/@commercelayer/sdk.svg)](https://github.com/commercelayer/commercelayer-sdk/blob/master/package.json)
6
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
7
+ [![Release](https://github.com/commercelayer/commercelayer-sdk/actions/workflows/semantic-release.yml/badge.svg)](https://github.com/commercelayer/commercelayer-sdk/actions/workflows/semantic-release.yml)
8
+ [![CodeQL](https://github.com/commercelayer/commercelayer-cli/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/commercelayer/commercelayer-cli/actions/workflows/codeql-analysis.yml)
9
+
10
+ A JavaScript Library wrapper that makes it quick and easy to interact with the [Commerce Layer API](https://docs.commercelayer.io/developers/).
4
11
 
5
12
  ### What is Commerce Layer?
6
13
 
@@ -18,7 +25,7 @@ To get started with Commerce Layer JS SDK you need to install it and then get th
18
25
 
19
26
  Commerce Layer JS SDK is available as an [npm package](https://www.npmjs.com/package/@commercelayer/sdk):
20
27
 
21
- ```
28
+ ```shell
22
29
  // npm
23
30
  npm install @commercelayer/sdk
24
31
 
@@ -28,7 +35,9 @@ yarn add @commercelayer/sdk
28
35
 
29
36
  ## Authentication
30
37
 
31
- All requests to Commerce Layer API must be authenticated with an [OAuth2](https://oauth.net/2/) bearer token. Hence, before starting to use this SDK you need to get a valid access token. Check [our documentation](https://docs.commercelayer.io/api/authentication) for more information about the available authorization flows.
38
+ All requests to Commerce Layer API must be authenticated with an [OAuth2](https://oauth.net/2/) bearer token.
39
+ Hence, before starting to use this SDK you need to get a valid access token.
40
+ Check [our documentation](https://docs.commercelayer.io/developers/authentication) for more information about the available authorization flows.
32
41
 
33
42
  > Feel free to use [Commerce Layer JS Auth](https://github.com/commercelayer/commercelayer-js-auth), a JavaScript library that helps you wrap our authentication API.
34
43
 
@@ -36,7 +45,7 @@ All requests to Commerce Layer API must be authenticated with an [OAuth2](https:
36
45
 
37
46
  You can use the ES6 default import with the SDK as follow:
38
47
 
39
- ```
48
+ ```typescript
40
49
  import CommerceLayer from '@commercelayer/sdk'
41
50
 
42
51
  const cl = CommerceLayer({
@@ -45,49 +54,59 @@ const cl = CommerceLayer({
45
54
  })
46
55
  ```
47
56
 
48
- > In the following examples, we will use only the the specific resources we're going to access (SKUs and shipping categories). Check our [API reference](https://docs.commercelayer.io/api/) for the complete list of available resources and their attributes.
57
+ > In the following examples, we will use only the the specific resources we're going to access (SKUs and shipping categories).
58
+ Check our [API reference](https://docs.commercelayer.io/developers/v/api-reference/) for the complete list of available
59
+ resources and their attributes.
49
60
 
50
61
  # Usage
51
62
 
52
63
  The code snippets below show how to use the Commerce Layer JS SDK when performing the standard CRUD operations provided by our REST API on the SKU resource.
53
64
 
54
65
  - ### Create
66
+
55
67
  - [How to create an SKU](#how-to-create-an-sku)
56
- - ### Retrieve
68
+
69
+ - ### Retrieve / List
70
+
57
71
  - [How to fetch a single SKU](#how-to-fetch-a-single-sku)
58
72
  - [How to fetch a collection of SKUs](#how-to-fetch-a-collection-of-skus)
59
73
  - [How to paginate a collection of SKUs](#how-to-paginate-a-collection-of-skus)
60
74
  - [How to iterate through a collection of SKUs](#how-to-iterate-through-a-collection-of-skus)
61
- - [How to build complex queries](#how-to-build-complex-queries)
75
+ <!-- - [How to build complex queries](#how-to-build-complex-queries) -->
76
+ - [How to fetch resource relationships](#how-to-fetch-resource-relationships)
77
+
62
78
  - ### Update
79
+
63
80
  - [How to update an existing SKU](#how-to-update-an-existing-sku)
81
+
64
82
  - ### Delete
83
+
65
84
  - [How to delete an existing SKU](#how-to-delete-an-existing-sku)
66
85
 
67
86
  ## Create
68
87
 
69
88
  ### How to create an SKU
70
89
 
71
- ```
90
+ ```typescript
72
91
  // selects the shipping category (it's a required relationship for the SKU resource)
73
92
  const shippingCategories = await cl.shipping_categories.list({ filters: { name_eq: 'Merchandising' } })
74
93
 
75
94
  const attributes = {
76
- code: 'TSHIRTMM000000FFFFFFXL',
77
- name: 'Black Men T-shirt with White Logo (XL)',
78
- shipping_category: cl.shipping_categories.relationship(shippingCategories[0].id), // assigns the relationship
95
+ code: 'TSHIRTMM000000FFFFFFXL',
96
+ name: 'Black Men T-shirt with White Logo (XL)',
97
+ shipping_category: cl.shipping_categories.relationship(shippingCategories[0].id), // assigns the relationship
79
98
  }
80
99
 
81
100
  const newSku = await cl.skus.create(attributes)
82
101
  ```
83
102
 
84
- Check our API reference for more information on how to [create an SKU](https://docs.commercelayer.io/api/resources/skus/create_sku).
103
+ Check our API reference for more information on how to [create an SKU](https://docs.commercelayer.io/developers/v/api-reference/skus/create).
85
104
 
86
- ## Retrieve
105
+ ## Retrieve / List
87
106
 
88
107
  ### How to fetch a single SKU
89
108
 
90
- ```
109
+ ```typescript
91
110
  // Fetches the SKU by ID
92
111
  const sku = await cl.skus.retrieve('BxAkSVqKEn')
93
112
 
@@ -101,11 +120,11 @@ Check our API reference for more information on how to [create an SKU](https://d
101
120
  const sku = (await cl.skus.list()).last()
102
121
  ```
103
122
 
104
- Check our API reference for more information on how to [retrieve an SKU](https://docs.commercelayer.io/api/resources/skus/retrieve_sku).
123
+ Check our API reference for more information on how to [retrieve an SKU](https://docs.commercelayer.io/developers/v/api-reference/skus/retrieve).
105
124
 
106
125
  ### How to fetch a collection of SKUs
107
126
 
108
- ```
127
+ ```typescript
109
128
  // LISTING RESULTS
110
129
 
111
130
  // Fetches all the SKUs
@@ -144,29 +163,32 @@ Check our API reference for more information on how to [retrieve an SKU](https:/
144
163
  const skus = await cl.skus.list({ filters: { name_cont: 'White Logo' } })
145
164
 
146
165
  // Filters all the SKUs fetching only the ones created between two specific dates
147
- const skus = await cl.skus.list({ filters: { created_at_gt: '2018-01-01', created_at_lt: '2018-01-31'} }) // filters combined according to an AND logic
166
+ // (filters combined according to an AND logic)
167
+ const skus = await cl.skus.list({ filters: { created_at_gt: '2018-01-01', created_at_lt: '2018-01-31'} })
148
168
 
149
169
  // Filters all the SKUs fetching only the ones created or updated after a specific date
150
- const skus = await cl.skus.list({ filters: { updated_at_or_created_at_gt: '2019-10-10' } }) // attributes combined according to an OR logic
170
+ // (attributes combined according to an OR logic)
171
+ const skus = await cl.skus.list({ filters: { updated_at_or_created_at_gt: '2019-10-10' } })
151
172
 
152
- // Filters all the SKUs fetching only the ones whose name contains the string "Black" and whose shipping category name starts with the string "MERCH"
173
+ // Filters all the SKUs fetching only the ones whose name contains the string "Black" and whose shipping category
174
+ // name starts with the string "MERCH"
153
175
  const skus = await cl.skus.list({ filters: { name_cont: 'Black', shipping_category_name_start: 'MERCH'} })
154
176
  ```
155
177
 
156
178
  When fetching a collection of resources you can leverage the `meta` attribute to get its `meta` information:
157
179
 
158
- ```
180
+ ```typescript
159
181
  const skus = await cl.skus.list()
160
182
  const meta = skus.meta
161
183
  ```
162
184
 
163
- Check our API reference for more information on how to [list all SKUs](https://docs.commercelayer.io/api/resources/skus/list_skus), [sort the results](https://docs.commercelayer.io/api/sorting-results), use [sparse fieldsets](https://docs.commercelayer.io/api/sparse-fieldsets), [include associations](https://docs.commercelayer.io/api/including-associations), and [filter data](https://docs.commercelayer.io/api/filtering-data).
185
+ Check our API reference for more information on how to [list all SKUs](https://docs.commercelayer.io/developers/v/api-reference/skus/list), [sort the results](https://docs.commercelayer.io/developers/sorting-results), use [sparse fieldsets](https://docs.commercelayer.io/developers/sparse-fieldsets), [include associations](https://docs.commercelayer.io/developers/including-associations), and [filter data](https://docs.commercelayer.io/developers/filtering-data).
164
186
 
165
187
  ### How to paginate a collection of SKUs
166
188
 
167
189
  When you fetch a collection of resources, you get paginated results:
168
190
 
169
- ```
191
+ ```typescript
170
192
  // Fetches the SKUs, setting the page number to 3 and the page size to 5
171
193
  const skus = await cl.skus.list({ pageNumber: 3, pageSize: 5 })
172
194
 
@@ -179,23 +201,36 @@ When you fetch a collection of resources, you get paginated results:
179
201
 
180
202
  > The default page number is **1**. The default page size is **10**. The maximum page size allowed is **25**.
181
203
 
182
- Check our API reference for more information on how [pagination](https://docs.commercelayer.io/api/pagination) works.
204
+ Check our API reference for more information on how [pagination](https://docs.commercelayer.io/developers/pagination) works.
183
205
 
184
206
  ### How to iterate through a collection of SKUs
185
207
 
186
208
  To execute a function for every item of a collection, use the `map()` method:
187
209
 
188
- ```
189
- // Fetches the whole list of SKUs and prints their names and codes to console
210
+ ```typescript
211
+ // Fetches the whole list of SKUs (1st page) and prints their names and codes to console
190
212
  const skus = await cl.skus.list()
191
213
  skus.map(p => console.log('Product: ' + p.name + ' - Code: ' + p.code))
192
214
  ```
193
215
 
216
+ ### How to fetch resource relationships
217
+
218
+ Many resources have relationships with other resources and instead of including these associations as seen above, you can fetch them directly.
219
+ In this way, in case of 1-to-N relationship, you can filter or sort the resulting collection as for standard resources.
220
+
221
+ ```typescript
222
+ // Fetches 1-to-1 related resource: billing address of an order
223
+ const billingAddress = cl.orders.billing_address('xYZkjABcde')
224
+
225
+ // Fetches 1-to-N related resources: orders associated to a customer
226
+ const orders = cl.customers.orders('XyzKjAbCDe', { fields: ['status', 'number'] })
227
+ ```
228
+
194
229
  ## Update
195
230
 
196
231
  ### How to update an existing SKU
197
232
 
198
- ```
233
+ ```typescript
199
234
  const sku = {
200
235
  id: 'xYZkjABcde',
201
236
  description: 'Updated description.',
@@ -205,23 +240,24 @@ To execute a function for every item of a collection, use the `map()` method:
205
240
  cl.skus.update(sku) // updates the SKU on the server
206
241
  ```
207
242
 
208
- Check our API reference for more information on how to [update an SKU](https://docs.commercelayer.io/api/resources/skus/update_sku).
243
+ Check our API reference for more information on how to [update an SKU](https://docs.commercelayer.io/developers/v/api-reference/skus/update).
209
244
 
210
245
  ## Delete
211
246
 
212
247
  ### How to delete an existing SKU
213
248
 
214
- ```
249
+ ```typescript
215
250
  cl.skus.delete('xYZkjABcde') // persisted deletion
216
251
  ```
217
252
 
218
- Check our API reference for more information on how to [delete an SKU](https://docs.commercelayer.io/api/resources/skus/delete_sku).
253
+ Check our API reference for more information on how to [delete an SKU](https://docs.commercelayer.io/developers/v/api-reference/skus/delete).
219
254
 
220
255
  # Overriding credentials
221
256
 
222
- If needed, Commerce Layer JS SDK lets you change the client configuration set it at a request level. To do that, just use the `config()` method or pass the `options` parameter and authenticate the API call with the desired credentials:
257
+ If needed, Commerce Layer JS SDK lets you change the client configuration set it at a request level.
258
+ To do that, just use the `config()` method or pass the `options` parameter and authenticate the API call with the desired credentials:
223
259
 
224
- ```
260
+ ```typescript
225
261
  // Permanently change configuration at client level
226
262
  cl.config({ organization: 'you-organization-slug', accessToken: 'your-access-token' })
227
263
  const skus = await cl.skus.list()
@@ -236,7 +272,7 @@ If needed, Commerce Layer JS SDK lets you change the client configuration set it
236
272
 
237
273
  Commerce Layer API returns specific errors (with extra information) on each attribute of a single resource. You can inspect them to properly handle validation errors (if any). To do that, use the `errors` attribute of the catched error:
238
274
 
239
- ```
275
+ ```typescript
240
276
  // logs error messages to console:
241
277
 
242
278
  const attributes = { code: 'TSHIRTMM000000FFFFFFXL', name: '' }
@@ -274,7 +310,7 @@ Commerce Layer API returns specific errors (with extra information) on each attr
274
310
 
275
311
  ```
276
312
 
277
- Check our API reference for more information about the [errors](https://docs.commercelayer.io/api/handling-errors) returned by the API.
313
+ Check our API reference for more information about the [errors](https://docs.commercelayer.io/developers/handling-errors) returned by the API.
278
314
 
279
315
  ---
280
316
 
package/lib/api.d.ts CHANGED
@@ -1,103 +1 @@
1
- /**
2
- * ©2022 Commerce Layer Inc.
3
- * OpenAPI schema, version 2.8.1
4
- **/
5
- export { default as Addresses } from './resources/addresses';
6
- export { default as Adjustments } from './resources/adjustments';
7
- export { default as AdyenGateways } from './resources/adyen_gateways';
8
- export { default as AdyenPayments } from './resources/adyen_payments';
9
- export { default as Applications } from './resources/application';
10
- export { default as Attachments } from './resources/attachments';
11
- export { default as Authorizations } from './resources/authorizations';
12
- export { default as AvalaraAccounts } from './resources/avalara_accounts';
13
- export { default as BillingInfoValidationRules } from './resources/billing_info_validation_rules';
14
- export { default as BingGeocoders } from './resources/bing_geocoders';
15
- export { default as BraintreeGateways } from './resources/braintree_gateways';
16
- export { default as BraintreePayments } from './resources/braintree_payments';
17
- export { default as Bundles } from './resources/bundles';
18
- export { default as Captures } from './resources/captures';
19
- export { default as CarrierAccounts } from './resources/carrier_accounts';
20
- export { default as CheckoutComGateways } from './resources/checkout_com_gateways';
21
- export { default as CheckoutComPayments } from './resources/checkout_com_payments';
22
- export { default as CouponCodesPromotionRules } from './resources/coupon_codes_promotion_rules';
23
- export { default as CouponRecipients } from './resources/coupon_recipients';
24
- export { default as Coupons } from './resources/coupons';
25
- export { default as CustomerAddresses } from './resources/customer_addresses';
26
- export { default as CustomerGroups } from './resources/customer_groups';
27
- export { default as CustomerPasswordResets } from './resources/customer_password_resets';
28
- export { default as CustomerPaymentSources } from './resources/customer_payment_sources';
29
- export { default as CustomerSubscriptions } from './resources/customer_subscriptions';
30
- export { default as Customers } from './resources/customers';
31
- export { default as DeliveryLeadTimes } from './resources/delivery_lead_times';
32
- export { default as EventCallbacks } from './resources/event_callbacks';
33
- export { default as ExternalGateways } from './resources/external_gateways';
34
- export { default as ExternalPayments } from './resources/external_payments';
35
- export { default as ExternalPromotions } from './resources/external_promotions';
36
- export { default as ExternalTaxCalculators } from './resources/external_tax_calculators';
37
- export { default as FixedAmountPromotions } from './resources/fixed_amount_promotions';
38
- export { default as FixedPricePromotions } from './resources/fixed_price_promotions';
39
- export { default as FreeGiftPromotions } from './resources/free_gift_promotions';
40
- export { default as FreeShippingPromotions } from './resources/free_shipping_promotions';
41
- export { default as Geocoders } from './resources/geocoders';
42
- export { default as GiftCardRecipients } from './resources/gift_card_recipients';
43
- export { default as GiftCards } from './resources/gift_cards';
44
- export { default as GoogleGeocoders } from './resources/google_geocoders';
45
- export { default as Imports } from './resources/imports';
46
- export { default as InStockSubscriptions } from './resources/in_stock_subscriptions';
47
- export { default as InventoryModels } from './resources/inventory_models';
48
- export { default as InventoryReturnLocations } from './resources/inventory_return_locations';
49
- export { default as InventoryStockLocations } from './resources/inventory_stock_locations';
50
- export { default as KlarnaGateways } from './resources/klarna_gateways';
51
- export { default as KlarnaPayments } from './resources/klarna_payments';
52
- export { default as LineItemOptions } from './resources/line_item_options';
53
- export { default as LineItems } from './resources/line_items';
54
- export { default as ManualGateways } from './resources/manual_gateways';
55
- export { default as ManualTaxCalculators } from './resources/manual_tax_calculators';
56
- export { default as Markets } from './resources/markets';
57
- export { default as Merchants } from './resources/merchants';
58
- export { default as OrderAmountPromotionRules } from './resources/order_amount_promotion_rules';
59
- export { default as OrderCopies } from './resources/order_copies';
60
- export { default as OrderSubscriptions } from './resources/order_subscriptions';
61
- export { default as OrderValidationRules } from './resources/order_validation_rules';
62
- export { default as Orders } from './resources/orders';
63
- export { default as Organizations } from './resources/organization';
64
- export { default as Packages } from './resources/packages';
65
- export { default as ParcelLineItems } from './resources/parcel_line_items';
66
- export { default as Parcels } from './resources/parcels';
67
- export { default as PaymentGateways } from './resources/payment_gateways';
68
- export { default as PaymentMethods } from './resources/payment_methods';
69
- export { default as PaypalGateways } from './resources/paypal_gateways';
70
- export { default as PaypalPayments } from './resources/paypal_payments';
71
- export { default as PercentageDiscountPromotions } from './resources/percentage_discount_promotions';
72
- export { default as PriceLists } from './resources/price_lists';
73
- export { default as Prices } from './resources/prices';
74
- export { default as PromotionRules } from './resources/promotion_rules';
75
- export { default as Promotions } from './resources/promotions';
76
- export { default as Refunds } from './resources/refunds';
77
- export { default as ReturnLineItems } from './resources/return_line_items';
78
- export { default as Returns } from './resources/returns';
79
- export { default as Shipments } from './resources/shipments';
80
- export { default as ShippingCategories } from './resources/shipping_categories';
81
- export { default as ShippingMethods } from './resources/shipping_methods';
82
- export { default as ShippingZones } from './resources/shipping_zones';
83
- export { default as SkuListItems } from './resources/sku_list_items';
84
- export { default as SkuListPromotionRules } from './resources/sku_list_promotion_rules';
85
- export { default as SkuLists } from './resources/sku_lists';
86
- export { default as SkuOptions } from './resources/sku_options';
87
- export { default as Skus } from './resources/skus';
88
- export { default as StockItems } from './resources/stock_items';
89
- export { default as StockLineItems } from './resources/stock_line_items';
90
- export { default as StockLocations } from './resources/stock_locations';
91
- export { default as StockTransfers } from './resources/stock_transfers';
92
- export { default as StripeGateways } from './resources/stripe_gateways';
93
- export { default as StripePayments } from './resources/stripe_payments';
94
- export { default as TaxCalculators } from './resources/tax_calculators';
95
- export { default as TaxCategories } from './resources/tax_categories';
96
- export { default as TaxRules } from './resources/tax_rules';
97
- export { default as TaxjarAccounts } from './resources/taxjar_accounts';
98
- export { default as Transactions } from './resources/transactions';
99
- export { default as Voids } from './resources/voids';
100
- export { default as Webhooks } from './resources/webhooks';
101
- export { default as WireTransfers } from './resources/wire_transfers';
102
- export declare type ResourceTypeLock = 'addresses' | 'adjustments' | 'adyen_gateways' | 'adyen_payments' | 'application' | 'attachments' | 'authorizations' | 'avalara_accounts' | 'billing_info_validation_rules' | 'bing_geocoders' | 'braintree_gateways' | 'braintree_payments' | 'bundles' | 'captures' | 'carrier_accounts' | 'checkout_com_gateways' | 'checkout_com_payments' | 'coupon_codes_promotion_rules' | 'coupon_recipients' | 'coupons' | 'customer_addresses' | 'customer_groups' | 'customer_password_resets' | 'customer_payment_sources' | 'customer_subscriptions' | 'customers' | 'delivery_lead_times' | 'event_callbacks' | 'external_gateways' | 'external_payments' | 'external_promotions' | 'external_tax_calculators' | 'fixed_amount_promotions' | 'fixed_price_promotions' | 'free_gift_promotions' | 'free_shipping_promotions' | 'geocoders' | 'gift_card_recipients' | 'gift_cards' | 'google_geocoders' | 'imports' | 'in_stock_subscriptions' | 'inventory_models' | 'inventory_return_locations' | 'inventory_stock_locations' | 'klarna_gateways' | 'klarna_payments' | 'line_item_options' | 'line_items' | 'manual_gateways' | 'manual_tax_calculators' | 'markets' | 'merchants' | 'order_amount_promotion_rules' | 'order_copies' | 'order_subscriptions' | 'order_validation_rules' | 'orders' | 'organization' | 'packages' | 'parcel_line_items' | 'parcels' | 'payment_gateways' | 'payment_methods' | 'paypal_gateways' | 'paypal_payments' | 'percentage_discount_promotions' | 'price_lists' | 'prices' | 'promotion_rules' | 'promotions' | 'refunds' | 'return_line_items' | 'returns' | 'shipments' | 'shipping_categories' | 'shipping_methods' | 'shipping_zones' | 'sku_list_items' | 'sku_list_promotion_rules' | 'sku_lists' | 'sku_options' | 'skus' | 'stock_items' | 'stock_line_items' | 'stock_locations' | 'stock_transfers' | 'stripe_gateways' | 'stripe_payments' | 'tax_calculators' | 'tax_categories' | 'tax_rules' | 'taxjar_accounts' | 'transactions' | 'voids' | 'webhooks' | 'wire_transfers';
103
- export declare const resourceList: readonly ["addresses", "adjustments", "adyen_gateways", "adyen_payments", "application", "attachments", "authorizations", "avalara_accounts", "billing_info_validation_rules", "bing_geocoders", "braintree_gateways", "braintree_payments", "bundles", "captures", "carrier_accounts", "checkout_com_gateways", "checkout_com_payments", "coupon_codes_promotion_rules", "coupon_recipients", "coupons", "customer_addresses", "customer_groups", "customer_password_resets", "customer_payment_sources", "customer_subscriptions", "customers", "delivery_lead_times", "event_callbacks", "external_gateways", "external_payments", "external_promotions", "external_tax_calculators", "fixed_amount_promotions", "fixed_price_promotions", "free_gift_promotions", "free_shipping_promotions", "geocoders", "gift_card_recipients", "gift_cards", "google_geocoders", "imports", "in_stock_subscriptions", "inventory_models", "inventory_return_locations", "inventory_stock_locations", "klarna_gateways", "klarna_payments", "line_item_options", "line_items", "manual_gateways", "manual_tax_calculators", "markets", "merchants", "order_amount_promotion_rules", "order_copies", "order_subscriptions", "order_validation_rules", "orders", "organization", "packages", "parcel_line_items", "parcels", "payment_gateways", "payment_methods", "paypal_gateways", "paypal_payments", "percentage_discount_promotions", "price_lists", "prices", "promotion_rules", "promotions", "refunds", "return_line_items", "returns", "shipments", "shipping_categories", "shipping_methods", "shipping_zones", "sku_list_items", "sku_list_promotion_rules", "sku_lists", "sku_options", "skus", "stock_items", "stock_line_items", "stock_locations", "stock_transfers", "stripe_gateways", "stripe_payments", "tax_calculators", "tax_categories", "tax_rules", "taxjar_accounts", "transactions", "voids", "webhooks", "wire_transfers"];
1
+ export{default as Addresses}from'./resources/addresses';export{default as Adjustments}from'./resources/adjustments';export{default as AdyenGateways}from'./resources/adyen_gateways';export{default as AdyenPayments}from'./resources/adyen_payments';export{default as Applications}from'./resources/application';export{default as Attachments}from'./resources/attachments';export{default as Authorizations}from'./resources/authorizations';export{default as AvalaraAccounts}from'./resources/avalara_accounts';export{default as BillingInfoValidationRules}from'./resources/billing_info_validation_rules';export{default as BingGeocoders}from'./resources/bing_geocoders';export{default as BraintreeGateways}from'./resources/braintree_gateways';export{default as BraintreePayments}from'./resources/braintree_payments';export{default as Bundles}from'./resources/bundles';export{default as Captures}from'./resources/captures';export{default as CarrierAccounts}from'./resources/carrier_accounts';export{default as CheckoutComGateways}from'./resources/checkout_com_gateways';export{default as CheckoutComPayments}from'./resources/checkout_com_payments';export{default as CouponCodesPromotionRules}from'./resources/coupon_codes_promotion_rules';export{default as CouponRecipients}from'./resources/coupon_recipients';export{default as Coupons}from'./resources/coupons';export{default as CustomerAddresses}from'./resources/customer_addresses';export{default as CustomerGroups}from'./resources/customer_groups';export{default as CustomerPasswordResets}from'./resources/customer_password_resets';export{default as CustomerPaymentSources}from'./resources/customer_payment_sources';export{default as CustomerSubscriptions}from'./resources/customer_subscriptions';export{default as Customers}from'./resources/customers';export{default as DeliveryLeadTimes}from'./resources/delivery_lead_times';export{default as EventCallbacks}from'./resources/event_callbacks';export{default as ExternalGateways}from'./resources/external_gateways';export{default as ExternalPayments}from'./resources/external_payments';export{default as ExternalPromotions}from'./resources/external_promotions';export{default as ExternalTaxCalculators}from'./resources/external_tax_calculators';export{default as FixedAmountPromotions}from'./resources/fixed_amount_promotions';export{default as FixedPricePromotions}from'./resources/fixed_price_promotions';export{default as FreeGiftPromotions}from'./resources/free_gift_promotions';export{default as FreeShippingPromotions}from'./resources/free_shipping_promotions';export{default as Geocoders}from'./resources/geocoders';export{default as GiftCardRecipients}from'./resources/gift_card_recipients';export{default as GiftCards}from'./resources/gift_cards';export{default as GoogleGeocoders}from'./resources/google_geocoders';export{default as Imports}from'./resources/imports';export{default as InStockSubscriptions}from'./resources/in_stock_subscriptions';export{default as InventoryModels}from'./resources/inventory_models';export{default as InventoryReturnLocations}from'./resources/inventory_return_locations';export{default as InventoryStockLocations}from'./resources/inventory_stock_locations';export{default as KlarnaGateways}from'./resources/klarna_gateways';export{default as KlarnaPayments}from'./resources/klarna_payments';export{default as LineItemOptions}from'./resources/line_item_options';export{default as LineItems}from'./resources/line_items';export{default as ManualGateways}from'./resources/manual_gateways';export{default as ManualTaxCalculators}from'./resources/manual_tax_calculators';export{default as Markets}from'./resources/markets';export{default as Merchants}from'./resources/merchants';export{default as OrderAmountPromotionRules}from'./resources/order_amount_promotion_rules';export{default as OrderCopies}from'./resources/order_copies';export{default as OrderSubscriptions}from'./resources/order_subscriptions';export{default as OrderValidationRules}from'./resources/order_validation_rules';export{default as Orders}from'./resources/orders';export{default as Organizations}from'./resources/organization';export{default as Packages}from'./resources/packages';export{default as ParcelLineItems}from'./resources/parcel_line_items';export{default as Parcels}from'./resources/parcels';export{default as PaymentGateways}from'./resources/payment_gateways';export{default as PaymentMethods}from'./resources/payment_methods';export{default as PaypalGateways}from'./resources/paypal_gateways';export{default as PaypalPayments}from'./resources/paypal_payments';export{default as PercentageDiscountPromotions}from'./resources/percentage_discount_promotions';export{default as PriceLists}from'./resources/price_lists';export{default as Prices}from'./resources/prices';export{default as PromotionRules}from'./resources/promotion_rules';export{default as Promotions}from'./resources/promotions';export{default as Refunds}from'./resources/refunds';export{default as ReturnLineItems}from'./resources/return_line_items';export{default as Returns}from'./resources/returns';export{default as Shipments}from'./resources/shipments';export{default as ShippingCategories}from'./resources/shipping_categories';export{default as ShippingMethods}from'./resources/shipping_methods';export{default as ShippingZones}from'./resources/shipping_zones';export{default as SkuListItems}from'./resources/sku_list_items';export{default as SkuListPromotionRules}from'./resources/sku_list_promotion_rules';export{default as SkuLists}from'./resources/sku_lists';export{default as SkuOptions}from'./resources/sku_options';export{default as Skus}from'./resources/skus';export{default as StockItems}from'./resources/stock_items';export{default as StockLineItems}from'./resources/stock_line_items';export{default as StockLocations}from'./resources/stock_locations';export{default as StockTransfers}from'./resources/stock_transfers';export{default as StripeGateways}from'./resources/stripe_gateways';export{default as StripePayments}from'./resources/stripe_payments';export{default as TaxCalculators}from'./resources/tax_calculators';export{default as TaxCategories}from'./resources/tax_categories';export{default as TaxRules}from'./resources/tax_rules';export{default as TaxjarAccounts}from'./resources/taxjar_accounts';export{default as Transactions}from'./resources/transactions';export{default as Voids}from'./resources/voids';export{default as Webhooks}from'./resources/webhooks';export{default as WireTransfers}from'./resources/wire_transfers';export declare type ResourceTypeLock='addresses'|'adjustments'|'adyen_gateways'|'adyen_payments'|'application'|'attachments'|'authorizations'|'avalara_accounts'|'billing_info_validation_rules'|'bing_geocoders'|'braintree_gateways'|'braintree_payments'|'bundles'|'captures'|'carrier_accounts'|'checkout_com_gateways'|'checkout_com_payments'|'coupon_codes_promotion_rules'|'coupon_recipients'|'coupons'|'customer_addresses'|'customer_groups'|'customer_password_resets'|'customer_payment_sources'|'customer_subscriptions'|'customers'|'delivery_lead_times'|'event_callbacks'|'external_gateways'|'external_payments'|'external_promotions'|'external_tax_calculators'|'fixed_amount_promotions'|'fixed_price_promotions'|'free_gift_promotions'|'free_shipping_promotions'|'geocoders'|'gift_card_recipients'|'gift_cards'|'google_geocoders'|'imports'|'in_stock_subscriptions'|'inventory_models'|'inventory_return_locations'|'inventory_stock_locations'|'klarna_gateways'|'klarna_payments'|'line_item_options'|'line_items'|'manual_gateways'|'manual_tax_calculators'|'markets'|'merchants'|'order_amount_promotion_rules'|'order_copies'|'order_subscriptions'|'order_validation_rules'|'orders'|'organization'|'packages'|'parcel_line_items'|'parcels'|'payment_gateways'|'payment_methods'|'paypal_gateways'|'paypal_payments'|'percentage_discount_promotions'|'price_lists'|'prices'|'promotion_rules'|'promotions'|'refunds'|'return_line_items'|'returns'|'shipments'|'shipping_categories'|'shipping_methods'|'shipping_zones'|'sku_list_items'|'sku_list_promotion_rules'|'sku_lists'|'sku_options'|'skus'|'stock_items'|'stock_line_items'|'stock_locations'|'stock_transfers'|'stripe_gateways'|'stripe_payments'|'tax_calculators'|'tax_categories'|'tax_rules'|'taxjar_accounts'|'transactions'|'voids'|'webhooks'|'wire_transfers';export declare const resourceList:readonly["addresses","adjustments","adyen_gateways","adyen_payments","application","attachments","authorizations","avalara_accounts","billing_info_validation_rules","bing_geocoders","braintree_gateways","braintree_payments","bundles","captures","carrier_accounts","checkout_com_gateways","checkout_com_payments","coupon_codes_promotion_rules","coupon_recipients","coupons","customer_addresses","customer_groups","customer_password_resets","customer_payment_sources","customer_subscriptions","customers","delivery_lead_times","event_callbacks","external_gateways","external_payments","external_promotions","external_tax_calculators","fixed_amount_promotions","fixed_price_promotions","free_gift_promotions","free_shipping_promotions","geocoders","gift_card_recipients","gift_cards","google_geocoders","imports","in_stock_subscriptions","inventory_models","inventory_return_locations","inventory_stock_locations","klarna_gateways","klarna_payments","line_item_options","line_items","manual_gateways","manual_tax_calculators","markets","merchants","order_amount_promotion_rules","order_copies","order_subscriptions","order_validation_rules","orders","organization","packages","parcel_line_items","parcels","payment_gateways","payment_methods","paypal_gateways","paypal_payments","percentage_discount_promotions","price_lists","prices","promotion_rules","promotions","refunds","return_line_items","returns","shipments","shipping_categories","shipping_methods","shipping_zones","sku_list_items","sku_list_promotion_rules","sku_lists","sku_options","skus","stock_items","stock_line_items","stock_locations","stock_transfers","stripe_gateways","stripe_payments","tax_calculators","tax_categories","tax_rules","taxjar_accounts","transactions","voids","webhooks","wire_transfers"];
package/lib/client.d.ts CHANGED
@@ -1,32 +1,2 @@
1
1
  /// <reference types="node" />
2
- import { AxiosProxyConfig, Method } from 'axios';
3
- import type { InterceptorManager } from './interceptor';
4
- import type { Agent as HttpAgent } from 'http';
5
- import type { Agent as HttpsAgent } from 'https';
6
- declare type ProxyConfig = AxiosProxyConfig | false;
7
- declare type RequestConfig = {
8
- timeout?: number;
9
- params?: {
10
- [key: string]: string | number | boolean;
11
- };
12
- httpAgent?: HttpAgent;
13
- httpsAgent?: HttpsAgent;
14
- proxy?: ProxyConfig;
15
- };
16
- declare type ApiClientInitConfig = {
17
- organization: string;
18
- domain?: string;
19
- accessToken: string;
20
- } & RequestConfig;
21
- declare type ApiClientConfig = Partial<ApiClientInitConfig>;
22
- declare class ApiClient {
23
- #private;
24
- static create(options: ApiClientInitConfig): ApiClient;
25
- baseUrl: string;
26
- interceptors: InterceptorManager;
27
- private constructor();
28
- config(config: ApiClientConfig): void;
29
- request(method: Method, path: string, body?: any, options?: ApiClientConfig): Promise<any>;
30
- }
31
- export default ApiClient;
32
- export { ApiClientInitConfig, ApiClientConfig, RequestConfig };
2
+ import{AxiosProxyConfig,Method}from'axios';import type{InterceptorManager}from'./interceptor';import type{Agent as HttpAgent}from'http';import type{Agent as HttpsAgent}from'https';declare type ProxyConfig=AxiosProxyConfig|false;declare type RequestConfig={timeout?:number;params?:{[key:string]:string|number|boolean;};httpAgent?:HttpAgent;httpsAgent?:HttpsAgent;proxy?:ProxyConfig;};declare type ApiClientInitConfig={organization:string;domain?:string;accessToken:string;}&RequestConfig;declare type ApiClientConfig=Partial<ApiClientInitConfig>;declare class ApiClient{#private;static create(options:ApiClientInitConfig):ApiClient;baseUrl:string;interceptors:InterceptorManager;private constructor();config(config:ApiClientConfig):void;request(method:Method,path:string,body?:any,options?:ApiClientConfig):Promise<any>;}export default ApiClient;export{ApiClientInitConfig,ApiClientConfig,RequestConfig};
package/lib/client.js CHANGED
@@ -1 +1 @@
1
- var d=this&&this.__classPrivateFieldSet||function(r,t,e,s,a){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?r!==t||!a:!t.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?a.call(r,e):a?a.value=e:t.set(r,e),e},n=this&&this.__classPrivateFieldGet||function(r,t,e,s){if(e==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?r!==t||!s:!t.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?s:e==="a"?s.call(r):s?s.value:t.get(r)},o,i;import u from"axios";import{SdkError as T,ApiError as b,ErrorType as c}from"./error";import f from"./config";import z from"./debug";const p=z(),m=(r,t)=>`https://${r.toLowerCase()}.${t||f.default.domain}/api`,C=r=>{let t=new T({message:r.message,type:c.GENERIC});if(u.isAxiosError(r))if(r.response){const e=new b(t);e.type=c.RESPONSE,e.status=r.response.status,e.code=String(e.status),e.errors=r.response.data.errors,t=e}else r.request?(t.type=c.REQUEST,t.request=r.request):t.type=c.CLIENT;else u.isCancel(r)?t.type=c.CANCEL:t.source=r;throw t};class l{constructor(t){o.set(this,void 0),i.set(this,void 0),p("new client instance %O",t),this.baseUrl=m(t.organization,t.domain),d(this,o,t.accessToken,"f");const e={timeout:t.timeout||f.client.timeout,proxy:t.proxy,httpAgent:t.httpAgent,httpsAgent:t.httpsAgent},s={baseURL:this.baseUrl,timeout:f.client.timeout,headers:{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+n(this,o,"f")},...e};p("axios options: %O",s),d(this,i,u.create(s),"f"),this.interceptors=n(this,i,"f").interceptors}static create(t){if(!t?.organization)throw new Error("Undefined 'organization' parameter");if(!t?.accessToken)throw new Error("Undefined 'accessToken' parameter");return new l(t)}config(t){p("config %o",t);const e=n(this,i,"f").defaults;t.timeout&&(e.timeout=t.timeout),t.proxy&&(e.proxy=t.proxy),t.httpAgent&&(e.httpAgent=t.httpAgent),t.httpsAgent&&(e.httpsAgent=t.httpsAgent),t.organization&&(this.baseUrl=m(t.organization,t.domain)),t.accessToken&&(d(this,o,t.accessToken,"f"),e.headers.common.Authorization="Bearer "+n(this,o,"f"))}async request(t,e,s,a){p("request %s %s, %O, %O",t,e,s||{},a||{});const y=s?{data:s}:void 0,E=e,v=a?.organization?m(a.organization,a.domain):void 0,w=a?.accessToken||n(this,o,"f"),A=w?{Authorization:"Bearer "+w}:void 0,g={method:t,baseURL:v,url:E,data:y,headers:A,...a};return p("request params: %O",g),n(this,i,"f").request(g).then(h=>h.data).catch(h=>C(h))}}o=new WeakMap,i=new WeakMap;export default l;
1
+ import p from"axios";import{SdkError as E,ApiError as y,ErrorType as i}from"./error";import c from"./config";import w from"./debug";const n=w("client"),h=(r,e)=>`https://${r.toLowerCase()}.${e||c.default.domain}/api`,T=r=>{let e=new E({message:r.message,type:i.GENERIC});if(p.isAxiosError(r))if(r.response){const t=new y(e);t.type=i.RESPONSE,t.status=r.response.status,t.code=String(t.status),t.errors=r.response.data.errors,e=t}else r.request?(e.type=i.REQUEST,e.request=r.request):e.type=i.CLIENT;else p.isCancel(r)?e.type=i.CANCEL:e.source=r;throw e};class m{static create(e){if(!e?.organization)throw new Error("Undefined 'organization' parameter");if(!e?.accessToken)throw new Error("Undefined 'accessToken' parameter");return new m(e)}baseUrl;#e;#t;interceptors;constructor(e){n("new client instance %O",e),this.baseUrl=h(e.organization,e.domain),this.#e=e.accessToken;const t={timeout:e.timeout||c.client.timeout,proxy:e.proxy,httpAgent:e.httpAgent,httpsAgent:e.httpsAgent},s={baseURL:this.baseUrl,timeout:c.client.timeout,headers:{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:"Bearer "+this.#e},...t};n("axios options: %O",s),this.#t=p.create(s),this.interceptors=this.#t.interceptors}config(e){n("config %o",e);const t=this.#t.defaults;e.timeout&&(t.timeout=e.timeout),e.proxy&&(t.proxy=e.proxy),e.httpAgent&&(t.httpAgent=e.httpAgent),e.httpsAgent&&(t.httpsAgent=e.httpsAgent),e.organization&&(this.baseUrl=h(e.organization,e.domain)),e.accessToken&&(this.#e=e.accessToken,t.headers.common.Authorization="Bearer "+this.#e)}async request(e,t,s,o){n("request %s %s, %O, %O",e,t,s||{},o||{});const g=s?{data:s}:void 0,l=t,A=o?.organization?h(o.organization,o.domain):void 0,u=o?.accessToken||this.#e,f=u?{Authorization:"Bearer "+u}:void 0,d={method:e,baseURL:A,url:l,data:g,headers:f,...o};return n("request params: %O",d),this.#t.request(d).then(a=>a.data).catch(a=>T(a))}}export default m;
@@ -1,122 +1 @@
1
- import * as api from './api';
2
- import { ApiError } from './error';
3
- import type { ErrorInterceptor, InterceptorType, RawResponseReader, RequestInterceptor, ResponseInterceptor } from './interceptor';
4
- import { ResourcesInitConfig } from './resource';
5
- declare type SdkConfig = {};
6
- declare type CommerceLayerInitConfig = SdkConfig & ResourcesInitConfig;
7
- declare type CommerceLayerConfig = Partial<CommerceLayerInitConfig>;
8
- declare class CommerceLayerClient {
9
- #private;
10
- static get openApiSchemaVersion(): string;
11
- addresses: api.Addresses;
12
- adjustments: api.Adjustments;
13
- adyen_gateways: api.AdyenGateways;
14
- adyen_payments: api.AdyenPayments;
15
- application: api.Applications;
16
- attachments: api.Attachments;
17
- authorizations: api.Authorizations;
18
- avalara_accounts: api.AvalaraAccounts;
19
- billing_info_validation_rules: api.BillingInfoValidationRules;
20
- bing_geocoders: api.BingGeocoders;
21
- braintree_gateways: api.BraintreeGateways;
22
- braintree_payments: api.BraintreePayments;
23
- bundles: api.Bundles;
24
- captures: api.Captures;
25
- carrier_accounts: api.CarrierAccounts;
26
- checkout_com_gateways: api.CheckoutComGateways;
27
- checkout_com_payments: api.CheckoutComPayments;
28
- coupon_codes_promotion_rules: api.CouponCodesPromotionRules;
29
- coupon_recipients: api.CouponRecipients;
30
- coupons: api.Coupons;
31
- customer_addresses: api.CustomerAddresses;
32
- customer_groups: api.CustomerGroups;
33
- customer_password_resets: api.CustomerPasswordResets;
34
- customer_payment_sources: api.CustomerPaymentSources;
35
- customer_subscriptions: api.CustomerSubscriptions;
36
- customers: api.Customers;
37
- delivery_lead_times: api.DeliveryLeadTimes;
38
- event_callbacks: api.EventCallbacks;
39
- external_gateways: api.ExternalGateways;
40
- external_payments: api.ExternalPayments;
41
- external_promotions: api.ExternalPromotions;
42
- external_tax_calculators: api.ExternalTaxCalculators;
43
- fixed_amount_promotions: api.FixedAmountPromotions;
44
- fixed_price_promotions: api.FixedPricePromotions;
45
- free_gift_promotions: api.FreeGiftPromotions;
46
- free_shipping_promotions: api.FreeShippingPromotions;
47
- geocoders: api.Geocoders;
48
- gift_card_recipients: api.GiftCardRecipients;
49
- gift_cards: api.GiftCards;
50
- google_geocoders: api.GoogleGeocoders;
51
- imports: api.Imports;
52
- in_stock_subscriptions: api.InStockSubscriptions;
53
- inventory_models: api.InventoryModels;
54
- inventory_return_locations: api.InventoryReturnLocations;
55
- inventory_stock_locations: api.InventoryStockLocations;
56
- klarna_gateways: api.KlarnaGateways;
57
- klarna_payments: api.KlarnaPayments;
58
- line_item_options: api.LineItemOptions;
59
- line_items: api.LineItems;
60
- manual_gateways: api.ManualGateways;
61
- manual_tax_calculators: api.ManualTaxCalculators;
62
- markets: api.Markets;
63
- merchants: api.Merchants;
64
- order_amount_promotion_rules: api.OrderAmountPromotionRules;
65
- order_copies: api.OrderCopies;
66
- order_subscriptions: api.OrderSubscriptions;
67
- order_validation_rules: api.OrderValidationRules;
68
- orders: api.Orders;
69
- organization: api.Organizations;
70
- packages: api.Packages;
71
- parcel_line_items: api.ParcelLineItems;
72
- parcels: api.Parcels;
73
- payment_gateways: api.PaymentGateways;
74
- payment_methods: api.PaymentMethods;
75
- paypal_gateways: api.PaypalGateways;
76
- paypal_payments: api.PaypalPayments;
77
- percentage_discount_promotions: api.PercentageDiscountPromotions;
78
- price_lists: api.PriceLists;
79
- prices: api.Prices;
80
- promotion_rules: api.PromotionRules;
81
- promotions: api.Promotions;
82
- refunds: api.Refunds;
83
- return_line_items: api.ReturnLineItems;
84
- returns: api.Returns;
85
- shipments: api.Shipments;
86
- shipping_categories: api.ShippingCategories;
87
- shipping_methods: api.ShippingMethods;
88
- shipping_zones: api.ShippingZones;
89
- sku_list_items: api.SkuListItems;
90
- sku_list_promotion_rules: api.SkuListPromotionRules;
91
- sku_lists: api.SkuLists;
92
- sku_options: api.SkuOptions;
93
- skus: api.Skus;
94
- stock_items: api.StockItems;
95
- stock_line_items: api.StockLineItems;
96
- stock_locations: api.StockLocations;
97
- stock_transfers: api.StockTransfers;
98
- stripe_gateways: api.StripeGateways;
99
- stripe_payments: api.StripePayments;
100
- tax_calculators: api.TaxCalculators;
101
- tax_categories: api.TaxCategories;
102
- tax_rules: api.TaxRules;
103
- taxjar_accounts: api.TaxjarAccounts;
104
- transactions: api.Transactions;
105
- voids: api.Voids;
106
- webhooks: api.Webhooks;
107
- wire_transfers: api.WireTransfers;
108
- constructor(config: CommerceLayerInitConfig);
109
- get currentOrganization(): string;
110
- private localConfig;
111
- config(config: CommerceLayerConfig): void;
112
- resources(): readonly string[];
113
- isApiError(error: any): error is ApiError;
114
- addRequestInterceptor(onFulfilled?: RequestInterceptor, onRejected?: ErrorInterceptor): number;
115
- addResponseInterceptor(onFulfilled?: ResponseInterceptor, onRejected?: ErrorInterceptor): number;
116
- removeInterceptor(type: InterceptorType, id: number): void;
117
- addRawResponseReader(): RawResponseReader;
118
- removeRawResponseReader(reader: number | RawResponseReader): void;
119
- }
120
- declare const CommerceLayer: (config: CommerceLayerInitConfig) => CommerceLayerClient;
121
- export default CommerceLayer;
122
- export type { CommerceLayerClient, CommerceLayerConfig, CommerceLayerInitConfig };
1
+ import*as api from'./api';import{ApiError}from'./error';import type{ErrorInterceptor,InterceptorType,RawResponseReader,RequestInterceptor,ResponseInterceptor}from'./interceptor';import{ResourcesInitConfig}from'./resource';declare type SdkConfig={};declare type CommerceLayerInitConfig=SdkConfig&ResourcesInitConfig;declare type CommerceLayerConfig=Partial<CommerceLayerInitConfig>;declare class CommerceLayerClient{#private;static get openApiSchemaVersion():string;addresses:api.Addresses;adjustments:api.Adjustments;adyen_gateways:api.AdyenGateways;adyen_payments:api.AdyenPayments;application:api.Applications;attachments:api.Attachments;authorizations:api.Authorizations;avalara_accounts:api.AvalaraAccounts;billing_info_validation_rules:api.BillingInfoValidationRules;bing_geocoders:api.BingGeocoders;braintree_gateways:api.BraintreeGateways;braintree_payments:api.BraintreePayments;bundles:api.Bundles;captures:api.Captures;carrier_accounts:api.CarrierAccounts;checkout_com_gateways:api.CheckoutComGateways;checkout_com_payments:api.CheckoutComPayments;coupon_codes_promotion_rules:api.CouponCodesPromotionRules;coupon_recipients:api.CouponRecipients;coupons:api.Coupons;customer_addresses:api.CustomerAddresses;customer_groups:api.CustomerGroups;customer_password_resets:api.CustomerPasswordResets;customer_payment_sources:api.CustomerPaymentSources;customer_subscriptions:api.CustomerSubscriptions;customers:api.Customers;delivery_lead_times:api.DeliveryLeadTimes;event_callbacks:api.EventCallbacks;external_gateways:api.ExternalGateways;external_payments:api.ExternalPayments;external_promotions:api.ExternalPromotions;external_tax_calculators:api.ExternalTaxCalculators;fixed_amount_promotions:api.FixedAmountPromotions;fixed_price_promotions:api.FixedPricePromotions;free_gift_promotions:api.FreeGiftPromotions;free_shipping_promotions:api.FreeShippingPromotions;geocoders:api.Geocoders;gift_card_recipients:api.GiftCardRecipients;gift_cards:api.GiftCards;google_geocoders:api.GoogleGeocoders;imports:api.Imports;in_stock_subscriptions:api.InStockSubscriptions;inventory_models:api.InventoryModels;inventory_return_locations:api.InventoryReturnLocations;inventory_stock_locations:api.InventoryStockLocations;klarna_gateways:api.KlarnaGateways;klarna_payments:api.KlarnaPayments;line_item_options:api.LineItemOptions;line_items:api.LineItems;manual_gateways:api.ManualGateways;manual_tax_calculators:api.ManualTaxCalculators;markets:api.Markets;merchants:api.Merchants;order_amount_promotion_rules:api.OrderAmountPromotionRules;order_copies:api.OrderCopies;order_subscriptions:api.OrderSubscriptions;order_validation_rules:api.OrderValidationRules;orders:api.Orders;organization:api.Organizations;packages:api.Packages;parcel_line_items:api.ParcelLineItems;parcels:api.Parcels;payment_gateways:api.PaymentGateways;payment_methods:api.PaymentMethods;paypal_gateways:api.PaypalGateways;paypal_payments:api.PaypalPayments;percentage_discount_promotions:api.PercentageDiscountPromotions;price_lists:api.PriceLists;prices:api.Prices;promotion_rules:api.PromotionRules;promotions:api.Promotions;refunds:api.Refunds;return_line_items:api.ReturnLineItems;returns:api.Returns;shipments:api.Shipments;shipping_categories:api.ShippingCategories;shipping_methods:api.ShippingMethods;shipping_zones:api.ShippingZones;sku_list_items:api.SkuListItems;sku_list_promotion_rules:api.SkuListPromotionRules;sku_lists:api.SkuLists;sku_options:api.SkuOptions;skus:api.Skus;stock_items:api.StockItems;stock_line_items:api.StockLineItems;stock_locations:api.StockLocations;stock_transfers:api.StockTransfers;stripe_gateways:api.StripeGateways;stripe_payments:api.StripePayments;tax_calculators:api.TaxCalculators;tax_categories:api.TaxCategories;tax_rules:api.TaxRules;taxjar_accounts:api.TaxjarAccounts;transactions:api.Transactions;voids:api.Voids;webhooks:api.Webhooks;wire_transfers:api.WireTransfers;constructor(config:CommerceLayerInitConfig);get currentOrganization():string;private localConfig;config(config:CommerceLayerConfig):void;resources():readonly string[];isApiError(error:any):error is ApiError;addRequestInterceptor(onFulfilled?:RequestInterceptor,onRejected?:ErrorInterceptor):number;addResponseInterceptor(onFulfilled?:ResponseInterceptor,onRejected?:ErrorInterceptor):number;removeInterceptor(type:InterceptorType,id:number):void;addRawResponseReader():RawResponseReader;removeRawResponseReader(reader:number|RawResponseReader):void;}declare const CommerceLayer:(config:CommerceLayerInitConfig)=>CommerceLayerClient;export default CommerceLayer;export type{CommerceLayerClient,CommerceLayerConfig,CommerceLayerInitConfig};