@medusajs/js-sdk 0.0.2-snapshot-20241021074955 → 0.0.2-snapshot-20241022103339
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/admin/exchange.d.ts +0 -4
- package/dist/admin/exchange.d.ts.map +1 -1
- package/dist/admin/exchange.js +0 -30
- package/dist/admin/exchange.js.map +1 -1
- package/dist/auth/index.d.ts +156 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +152 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -1
- package/dist/esm/admin/exchange.d.ts +0 -4
- package/dist/esm/admin/exchange.d.ts.map +1 -1
- package/dist/esm/admin/exchange.js +0 -38
- package/dist/esm/admin/exchange.js.map +1 -1
- package/dist/esm/auth/index.d.ts +156 -0
- package/dist/esm/auth/index.d.ts.map +1 -1
- package/dist/esm/auth/index.js +152 -1
- package/dist/esm/auth/index.js.map +1 -1
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +2 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/store/index.d.ts +973 -83
- package/dist/esm/store/index.d.ts.map +1 -1
- package/dist/esm/store/index.js +946 -0
- package/dist/esm/store/index.js.map +1 -1
- package/dist/esm/types.d.ts +6 -1
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/store/index.d.ts +973 -83
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +946 -0
- package/dist/store/index.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/store/index.js
CHANGED
@@ -2,14 +2,102 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Store = void 0;
|
4
4
|
class Store {
|
5
|
+
/**
|
6
|
+
* @ignore
|
7
|
+
*/
|
5
8
|
constructor(client) {
|
6
9
|
this.region = {
|
10
|
+
/**
|
11
|
+
* This method retrieves the paginated list of regions in the store. It sends a request to the
|
12
|
+
* [List Regions API route](https://docs.medusajs.com/v2/api/store#regions_getregions).
|
13
|
+
*
|
14
|
+
* Related guide: [How to list regions in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/regions/list).
|
15
|
+
*
|
16
|
+
* @param query - Filters and pagination configurations.
|
17
|
+
* @param headers - Headers to pass in the request
|
18
|
+
* @returns The paginated list of regions.
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* To retrieve the list of regions:
|
22
|
+
*
|
23
|
+
* ```ts
|
24
|
+
* sdk.store.region.list()
|
25
|
+
* .then(({ regions, count, limit, offset }) => {
|
26
|
+
* console.log(regions)
|
27
|
+
* })
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
31
|
+
*
|
32
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
33
|
+
*
|
34
|
+
* ```ts
|
35
|
+
* sdk.store.region.list({
|
36
|
+
* limit: 10,
|
37
|
+
* offset: 10
|
38
|
+
* })
|
39
|
+
* .then(({ regions, count, limit, offset }) => {
|
40
|
+
* console.log(regions)
|
41
|
+
* })
|
42
|
+
* ```
|
43
|
+
*
|
44
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
45
|
+
* in each region:
|
46
|
+
*
|
47
|
+
* ```ts
|
48
|
+
* sdk.store.region.list({
|
49
|
+
* fields: "id,*countries"
|
50
|
+
* })
|
51
|
+
* .then(({ regions, count, limit, offset }) => {
|
52
|
+
* console.log(regions)
|
53
|
+
* })
|
54
|
+
* ```
|
55
|
+
*
|
56
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
57
|
+
*/
|
7
58
|
list: async (query, headers) => {
|
8
59
|
return this.client.fetch(`/store/regions`, {
|
9
60
|
query,
|
10
61
|
headers,
|
11
62
|
});
|
12
63
|
},
|
64
|
+
/**
|
65
|
+
* This method retrieves a region by its ID. It sends a request to the [Get Region](https://docs.medusajs.com/v2/api/store#regions_getregionsid)
|
66
|
+
* API route.
|
67
|
+
*
|
68
|
+
* Related guide: [Store and retrieve regions in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/regions/store-retrieve-region).
|
69
|
+
*
|
70
|
+
* @param id - The region's ID.
|
71
|
+
* @param query - Configure the fields to retrieve in the region.
|
72
|
+
* @param headers - Headers to pass in the request
|
73
|
+
* @returns The region.
|
74
|
+
*
|
75
|
+
* @example
|
76
|
+
* To retrieve a region by its ID:
|
77
|
+
*
|
78
|
+
* ```ts
|
79
|
+
* sdk.store.region.retrieve("reg_123")
|
80
|
+
* .then(({ region }) => {
|
81
|
+
* console.log(region)
|
82
|
+
* })
|
83
|
+
* ```
|
84
|
+
*
|
85
|
+
* To specify the fields and relations to retrieve:
|
86
|
+
*
|
87
|
+
* ```ts
|
88
|
+
* sdk.store.region.retrieve(
|
89
|
+
* "reg_123",
|
90
|
+
* {
|
91
|
+
* fields: "id,*countries"
|
92
|
+
* }
|
93
|
+
* )
|
94
|
+
* .then(({ region }) => {
|
95
|
+
* console.log(region)
|
96
|
+
* })
|
97
|
+
* ```
|
98
|
+
*
|
99
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
100
|
+
*/
|
13
101
|
retrieve: async (id, query, headers) => {
|
14
102
|
return this.client.fetch(`/store/regions/${id}`, {
|
15
103
|
query,
|
@@ -18,12 +106,94 @@ class Store {
|
|
18
106
|
},
|
19
107
|
};
|
20
108
|
this.collection = {
|
109
|
+
/**
|
110
|
+
* This method retrieves a paginated list of product collections. It sends a request to the
|
111
|
+
* [List Collections](https://docs.medusajs.com/v2/api/store#collections_getcollections) API route.
|
112
|
+
*
|
113
|
+
* Related guide: [How to retrieve collections in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/collections/list).
|
114
|
+
*
|
115
|
+
* @param query - Filters and pagination configurations.
|
116
|
+
* @param headers - Headers to pass in the request
|
117
|
+
* @returns The paginated list of collections.
|
118
|
+
*
|
119
|
+
* @example
|
120
|
+
* To retrieve the list of collections:
|
121
|
+
*
|
122
|
+
* ```ts
|
123
|
+
* sdk.store.collection.list()
|
124
|
+
* .then(({ collections, count, limit, offset }) => {
|
125
|
+
* console.log(collections)
|
126
|
+
* })
|
127
|
+
* ```
|
128
|
+
*
|
129
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
130
|
+
*
|
131
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
132
|
+
*
|
133
|
+
* ```ts
|
134
|
+
* sdk.store.collection.list({
|
135
|
+
* limit: 10,
|
136
|
+
* offset: 10
|
137
|
+
* })
|
138
|
+
* .then(({ collections, count, limit, offset }) => {
|
139
|
+
* console.log(collections)
|
140
|
+
* })
|
141
|
+
* ```
|
142
|
+
*
|
143
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
144
|
+
* in each collection:
|
145
|
+
*
|
146
|
+
* ```ts
|
147
|
+
* sdk.store.collection.list({
|
148
|
+
* fields: "id,handle"
|
149
|
+
* })
|
150
|
+
* .then(({ collections, count, limit, offset }) => {
|
151
|
+
* console.log(collections)
|
152
|
+
* })
|
153
|
+
* ```
|
154
|
+
*
|
155
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
156
|
+
*/
|
21
157
|
list: async (query, headers) => {
|
22
158
|
return this.client.fetch(`/store/collections`, {
|
23
159
|
query,
|
24
160
|
headers,
|
25
161
|
});
|
26
162
|
},
|
163
|
+
/**
|
164
|
+
* This method retrieves a collection by its ID. It sends a request to the [Get Collection](https://docs.medusajs.com/v2/api/store#collections_getcollectionsid)
|
165
|
+
* API route.
|
166
|
+
*
|
167
|
+
* Related guide: [How to retrieve a collection in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/collections/retrieve).
|
168
|
+
*
|
169
|
+
* @param id - The ID of the collection to retrieve.
|
170
|
+
* @param query - Configure the fields to retrieve in the collection.
|
171
|
+
* @param headers - Headers to pass in the request
|
172
|
+
* @returns The collection.
|
173
|
+
*
|
174
|
+
* @example
|
175
|
+
* To retrieve a collection by its ID:
|
176
|
+
*
|
177
|
+
* ```ts
|
178
|
+
* sdk.store.collection.retrieve("pcol_123")
|
179
|
+
* .then(({ collection }) => {
|
180
|
+
* console.log(collection)
|
181
|
+
* })
|
182
|
+
* ```
|
183
|
+
*
|
184
|
+
* To specify the fields and relations to retrieve:
|
185
|
+
*
|
186
|
+
* ```ts
|
187
|
+
* sdk.store.collection.retrieve("pcol_123", {
|
188
|
+
* fields: "id,handle"
|
189
|
+
* })
|
190
|
+
* .then(({ collection }) => {
|
191
|
+
* console.log(collection)
|
192
|
+
* })
|
193
|
+
* ```
|
194
|
+
*
|
195
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
196
|
+
*/
|
27
197
|
retrieve: async (id, query, headers) => {
|
28
198
|
return this.client.fetch(`/store/collections/${id}`, {
|
29
199
|
query,
|
@@ -32,12 +202,94 @@ class Store {
|
|
32
202
|
},
|
33
203
|
};
|
34
204
|
this.category = {
|
205
|
+
/**
|
206
|
+
* This method retrieves a paginated list of product categories. It sends a request to the
|
207
|
+
* [List Categories](https://docs.medusajs.com/v2/api/store#product-categories_getproductcategories) API route.
|
208
|
+
*
|
209
|
+
* Related guide: [How to retrieve list of categories in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/categories/list).
|
210
|
+
*
|
211
|
+
* @param query - Filters and pagination configurations.
|
212
|
+
* @param headers - Headers to pass in the request.
|
213
|
+
* @returns The paginated list of categoreis.
|
214
|
+
*
|
215
|
+
* @example
|
216
|
+
* To retrieve the list of categoreis:
|
217
|
+
*
|
218
|
+
* ```ts
|
219
|
+
* sdk.store.category.list()
|
220
|
+
* .then(({ product_categories, count, offset, limit }) => {
|
221
|
+
* console.log(product_categories)
|
222
|
+
* })
|
223
|
+
* ```
|
224
|
+
*
|
225
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
226
|
+
*
|
227
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
228
|
+
*
|
229
|
+
* ```ts
|
230
|
+
* sdk.store.category.list({
|
231
|
+
* limit: 10,
|
232
|
+
* offset: 10
|
233
|
+
* })
|
234
|
+
* .then(({ product_categories, count, offset, limit }) => {
|
235
|
+
* console.log(product_categories)
|
236
|
+
* })
|
237
|
+
* ```
|
238
|
+
*
|
239
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
240
|
+
* in each category:
|
241
|
+
*
|
242
|
+
* ```ts
|
243
|
+
* sdk.store.category.list({
|
244
|
+
* fields: "id,*parent_category"
|
245
|
+
* })
|
246
|
+
* .then(({ product_categories, count, offset, limit }) => {
|
247
|
+
* console.log(product_categories)
|
248
|
+
* })
|
249
|
+
* ```
|
250
|
+
*
|
251
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
252
|
+
*/
|
35
253
|
list: async (query, headers) => {
|
36
254
|
return this.client.fetch(`/store/product-categories`, {
|
37
255
|
query,
|
38
256
|
headers,
|
39
257
|
});
|
40
258
|
},
|
259
|
+
/**
|
260
|
+
* This method retrieves a category by its ID. It sends a request to the
|
261
|
+
* [Retrieve Product Category](https://docs.medusajs.com/v2/api/store#product-categories_getproductcategoriesid).
|
262
|
+
*
|
263
|
+
* Related guide: [How to retrieve a category in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/categories/retrieve).
|
264
|
+
*
|
265
|
+
* @param id - The ID of the category to retrieve.
|
266
|
+
* @param query - Configure the fields to retrieve in the category.
|
267
|
+
* @param headers - Headers to pass in the request
|
268
|
+
* @returns The category.
|
269
|
+
*
|
270
|
+
* @example
|
271
|
+
* To retrieve a category by its ID:
|
272
|
+
*
|
273
|
+
* ```ts
|
274
|
+
* sdk.store.category.retrieve("pcat_123")
|
275
|
+
* .then(({ product_category }) => {
|
276
|
+
* console.log(product_category)
|
277
|
+
* })
|
278
|
+
* ```
|
279
|
+
*
|
280
|
+
* To specify the fields and relations to retrieve:
|
281
|
+
*
|
282
|
+
* ```ts
|
283
|
+
* sdk.store.category.retrieve("pcat_123", {
|
284
|
+
* fields: "id,*parent_category"
|
285
|
+
* })
|
286
|
+
* .then(({ product_category }) => {
|
287
|
+
* console.log(product_category)
|
288
|
+
* })
|
289
|
+
* ```
|
290
|
+
*
|
291
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
292
|
+
*/
|
41
293
|
retrieve: async (id, query, headers) => {
|
42
294
|
return this.client.fetch(`/store/product-categories/${id}`, {
|
43
295
|
query,
|
@@ -46,12 +298,100 @@ class Store {
|
|
46
298
|
},
|
47
299
|
};
|
48
300
|
this.product = {
|
301
|
+
/**
|
302
|
+
* This method retrieves a list of products. It sends a request to the
|
303
|
+
* [List Products API route](https://docs.medusajs.com/v2/api/store#products_getproducts).
|
304
|
+
*
|
305
|
+
* Related guides:
|
306
|
+
*
|
307
|
+
* - [How to list products in a storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/list).
|
308
|
+
* - [How to retrieve a product variant's prices in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/price)
|
309
|
+
*
|
310
|
+
* @param query - Filters and pagination configurations.
|
311
|
+
* @param headers - Headers to pass in the request.
|
312
|
+
* @returns The paginated list of products.
|
313
|
+
*
|
314
|
+
* @example
|
315
|
+
* To retrieve the list of products:
|
316
|
+
*
|
317
|
+
* ```ts
|
318
|
+
* sdk.store.product.list()
|
319
|
+
* .then(({ products, count, offset, limit }) => {
|
320
|
+
* console.log(products)
|
321
|
+
* })
|
322
|
+
* ```
|
323
|
+
*
|
324
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
325
|
+
*
|
326
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
327
|
+
*
|
328
|
+
* ```ts
|
329
|
+
* sdk.store.product.list({
|
330
|
+
* limit: 10,
|
331
|
+
* offset: 10
|
332
|
+
* })
|
333
|
+
* .then(({ products, count, offset, limit }) => {
|
334
|
+
* console.log(products)
|
335
|
+
* })
|
336
|
+
* ```
|
337
|
+
*
|
338
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
339
|
+
* in each product:
|
340
|
+
*
|
341
|
+
* ```ts
|
342
|
+
* sdk.store.product.list({
|
343
|
+
* fields: "id,*collection"
|
344
|
+
* })
|
345
|
+
* .then(({ products, count, offset, limit }) => {
|
346
|
+
* console.log(products)
|
347
|
+
* })
|
348
|
+
* ```
|
349
|
+
*
|
350
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
351
|
+
*/
|
49
352
|
list: async (query, headers) => {
|
50
353
|
return this.client.fetch(`/store/products`, {
|
51
354
|
query,
|
52
355
|
headers,
|
53
356
|
});
|
54
357
|
},
|
358
|
+
/**
|
359
|
+
* This method is used to retrieve a product by its ID. It sends a request to the
|
360
|
+
* [Get Product](https://docs.medusajs.com/v2/api/store#products_getproductsid) API route.
|
361
|
+
*
|
362
|
+
* Related guides:
|
363
|
+
*
|
364
|
+
* - [How to retrieve a product in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/retrieve).
|
365
|
+
* - [How to retrieve a product variant's prices in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/products/price)
|
366
|
+
*
|
367
|
+
* @param id - The product's ID.
|
368
|
+
* @param query - Configure the fields to retrieve in the product.
|
369
|
+
* @param headers - Headers to pass in the request
|
370
|
+
* @returns The product.
|
371
|
+
*
|
372
|
+
* @example
|
373
|
+
* To retrieve a product by its ID:
|
374
|
+
*
|
375
|
+
* ```ts
|
376
|
+
* sdk.store.product.retrieve("prod_123")
|
377
|
+
* .then(({ product }) => {
|
378
|
+
* console.log(product)
|
379
|
+
* })
|
380
|
+
* ```
|
381
|
+
*
|
382
|
+
* To specify the fields and relations to retrieve:
|
383
|
+
*
|
384
|
+
* ```ts
|
385
|
+
* sdk.store.product.retrieve("prod_123", {
|
386
|
+
* fields: "id,*collection"
|
387
|
+
* })
|
388
|
+
* .then(({ product }) => {
|
389
|
+
* console.log(product)
|
390
|
+
* })
|
391
|
+
* ```
|
392
|
+
*
|
393
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
394
|
+
*/
|
55
395
|
retrieve: async (id, query, headers) => {
|
56
396
|
return this.client.fetch(`/store/products/${id}`, {
|
57
397
|
query,
|
@@ -59,7 +399,29 @@ class Store {
|
|
59
399
|
});
|
60
400
|
},
|
61
401
|
};
|
402
|
+
/**
|
403
|
+
* Related guides: [How to implement carts in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart).
|
404
|
+
*/
|
62
405
|
this.cart = {
|
406
|
+
/**
|
407
|
+
* This method creates a cart. It sends a request to the [Create Cart](https://docs.medusajs.com/v2/api/store#carts_postcarts)
|
408
|
+
* API route.
|
409
|
+
*
|
410
|
+
* Related guide: [How to create a cart in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/create).
|
411
|
+
*
|
412
|
+
* @param body - The details of the cart to create.
|
413
|
+
* @param query - Configure the fields to retrieve in the cart.
|
414
|
+
* @param headers - Headers to pass in the request.
|
415
|
+
* @returns The created cart.
|
416
|
+
*
|
417
|
+
* @example
|
418
|
+
* sdk.store.cart.create({
|
419
|
+
* region_id: "reg_123"
|
420
|
+
* })
|
421
|
+
* .then(({ cart }) => {
|
422
|
+
* console.log(cart)
|
423
|
+
* })
|
424
|
+
*/
|
63
425
|
create: async (body, query, headers) => {
|
64
426
|
return this.client.fetch(`/store/carts`, {
|
65
427
|
method: "POST",
|
@@ -68,6 +430,26 @@ class Store {
|
|
68
430
|
query,
|
69
431
|
});
|
70
432
|
},
|
433
|
+
/**
|
434
|
+
* This method updates a cart. It sends a request to the
|
435
|
+
* [Update Cart](https://docs.medusajs.com/v2/api/store#carts_postcartsid) API route.
|
436
|
+
*
|
437
|
+
* Related guide: [How to update a cart in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/update).
|
438
|
+
*
|
439
|
+
* @param id - The cart's ID.
|
440
|
+
* @param body - The data to update in the cart.
|
441
|
+
* @param query - Configure the fields to retrieve in the cart.
|
442
|
+
* @param headers - Headers to pass in the request.
|
443
|
+
* @returns The updated cart.
|
444
|
+
*
|
445
|
+
* @example
|
446
|
+
* sdk.store.cart.update("cart_123", {
|
447
|
+
* region_id: "reg_123"
|
448
|
+
* })
|
449
|
+
* .then(({ cart }) => {
|
450
|
+
* console.log(cart)
|
451
|
+
* })
|
452
|
+
*/
|
71
453
|
update: async (id, body, query, headers) => {
|
72
454
|
return this.client.fetch(`/store/carts/${id}`, {
|
73
455
|
method: "POST",
|
@@ -76,12 +458,67 @@ class Store {
|
|
76
458
|
query,
|
77
459
|
});
|
78
460
|
},
|
461
|
+
/**
|
462
|
+
* This method retrieves a cart by its ID. It sends a request to the
|
463
|
+
* [Get Cart](https://docs.medusajs.com/v2/api/store#carts_getcartsid) API route.
|
464
|
+
*
|
465
|
+
* Related guide: [How to retrieve a cart in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/retrieve).
|
466
|
+
*
|
467
|
+
* @param id - The cart's ID.
|
468
|
+
* @param query - Configure the fields to retrieve in the cart.
|
469
|
+
* @param headers - Headers to pass in the request.
|
470
|
+
* @returns The cart's details.
|
471
|
+
*
|
472
|
+
* @example
|
473
|
+
* To retrieve a cart by its ID:
|
474
|
+
*
|
475
|
+
* ```ts
|
476
|
+
* sdk.store.cart.retrieve("cart_123")
|
477
|
+
* .then(({ cart }) => {
|
478
|
+
* console.log(cart)
|
479
|
+
* })
|
480
|
+
* ```
|
481
|
+
*
|
482
|
+
* To specify the fields and relations to retrieve:
|
483
|
+
*
|
484
|
+
* ```ts
|
485
|
+
* sdk.store.cart.retrieve("cart_123", {
|
486
|
+
* fields: "id,*items"
|
487
|
+
* })
|
488
|
+
* .then(({ cart }) => {
|
489
|
+
* console.log(cart)
|
490
|
+
* })
|
491
|
+
* ```
|
492
|
+
*
|
493
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
494
|
+
*/
|
79
495
|
retrieve: async (id, query, headers) => {
|
80
496
|
return this.client.fetch(`/store/carts/${id}`, {
|
81
497
|
headers,
|
82
498
|
query,
|
83
499
|
});
|
84
500
|
},
|
501
|
+
/**
|
502
|
+
* This methods adds a product variant to the cart as a line item. It sends a request to the
|
503
|
+
* [Add Line Item](https://docs.medusajs.com/v2/api/store#carts_postcartsidlineitems) API route.
|
504
|
+
*
|
505
|
+
* Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/manage-items).
|
506
|
+
*
|
507
|
+
* @param cartId - The cart's ID.
|
508
|
+
* @param body - The details of the item to add.
|
509
|
+
* @param query - Configure the fields to retrieve in the cart.
|
510
|
+
* @param headers - Headers to pass in the request.
|
511
|
+
* @returns The cart's details.
|
512
|
+
*
|
513
|
+
* @example
|
514
|
+
* sdk.store.cart.createLineItem("cart_123", {
|
515
|
+
* variant_id: "variant_123",
|
516
|
+
* quantity: 1
|
517
|
+
* })
|
518
|
+
* .then(({ cart }) => {
|
519
|
+
* console.log(cart)
|
520
|
+
* })
|
521
|
+
*/
|
85
522
|
createLineItem: async (cartId, body, query, headers) => {
|
86
523
|
return this.client.fetch(`/store/carts/${cartId}/line-items`, {
|
87
524
|
method: "POST",
|
@@ -90,6 +527,31 @@ class Store {
|
|
90
527
|
query,
|
91
528
|
});
|
92
529
|
},
|
530
|
+
/**
|
531
|
+
* This method updates a line item in a cart. It sends a request to the
|
532
|
+
* [Update Line Item](https://docs.medusajs.com/v2/api/store#carts_postcartsidlineitemsline_id) API route.
|
533
|
+
*
|
534
|
+
* Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/manage-items).
|
535
|
+
*
|
536
|
+
* @param cartId - The cart's ID.
|
537
|
+
* @param lineItemId - The line item's ID.
|
538
|
+
* @param body - The data to update.
|
539
|
+
* @param query - Configure the fields to retrieve in the cart.
|
540
|
+
* @param headers - Headers to pass in the request.
|
541
|
+
* @returns The cart's details.
|
542
|
+
*
|
543
|
+
* @example
|
544
|
+
* sdk.store.cart.updateLineItem(
|
545
|
+
* "cart_123",
|
546
|
+
* "li_123",
|
547
|
+
* {
|
548
|
+
* quantity: 1
|
549
|
+
* }
|
550
|
+
* )
|
551
|
+
* .then(({ cart }) => {
|
552
|
+
* console.log(cart)
|
553
|
+
* })
|
554
|
+
*/
|
93
555
|
updateLineItem: async (cartId, lineItemId, body, query, headers) => {
|
94
556
|
return this.client.fetch(`/store/carts/${cartId}/line-items/${lineItemId}`, {
|
95
557
|
method: "POST",
|
@@ -98,12 +560,55 @@ class Store {
|
|
98
560
|
query,
|
99
561
|
});
|
100
562
|
},
|
563
|
+
/**
|
564
|
+
* This method deletes a line item from a cart. It sends a request to the
|
565
|
+
* [Remove Line Item](https://docs.medusajs.com/v2/api/store#carts_deletecartsidlineitemsline_id) API route.
|
566
|
+
*
|
567
|
+
* Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/cart/manage-items).
|
568
|
+
*
|
569
|
+
* @param cartId - The cart's ID.
|
570
|
+
* @param lineItemId - The item's ID.
|
571
|
+
* @param headers - Headers to pass in the request.
|
572
|
+
* @returns The deletion's details.
|
573
|
+
*
|
574
|
+
* @example
|
575
|
+
* sdk.store.cart.deleteLineItem(
|
576
|
+
* "cart_123",
|
577
|
+
* "li_123"
|
578
|
+
* )
|
579
|
+
* .then(({ deleted, parent: cart }) => {
|
580
|
+
* console.log(deleted, cart)
|
581
|
+
* })
|
582
|
+
*/
|
101
583
|
deleteLineItem: async (cartId, lineItemId, headers) => {
|
102
584
|
return this.client.fetch(`/store/carts/${cartId}/line-items/${lineItemId}`, {
|
103
585
|
method: "DELETE",
|
104
586
|
headers,
|
105
587
|
});
|
106
588
|
},
|
589
|
+
/**
|
590
|
+
* This method adds a shipping method to a cart. It sends a request to
|
591
|
+
* the [Add Shipping Method](https://docs.medusajs.com/v2/api/store#carts_postcartsidshippingmethods) API routes.
|
592
|
+
*
|
593
|
+
* Related guide: [Implement shipping step during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/shipping).
|
594
|
+
*
|
595
|
+
* @param cartId - The cart's ID.
|
596
|
+
* @param body - The shipping method's details.
|
597
|
+
* @param query - Configure the fields to retrieve in the cart.
|
598
|
+
* @param headers - Headers to pass in the request.
|
599
|
+
* @returns The cart's details.
|
600
|
+
*
|
601
|
+
* @example
|
602
|
+
* sdk.store.cart.addShippingMethod("cart_123", {
|
603
|
+
* option_id: "so_123",
|
604
|
+
* data: {
|
605
|
+
* // custom data for fulfillment provider.
|
606
|
+
* }
|
607
|
+
* })
|
608
|
+
* .then(({ cart }) => {
|
609
|
+
* console.log(cart)
|
610
|
+
* })
|
611
|
+
*/
|
107
612
|
addShippingMethod: async (cartId, body, query, headers) => {
|
108
613
|
return this.client.fetch(`/store/carts/${cartId}/shipping-methods`, {
|
109
614
|
method: "POST",
|
@@ -112,6 +617,30 @@ class Store {
|
|
112
617
|
query,
|
113
618
|
});
|
114
619
|
},
|
620
|
+
/**
|
621
|
+
* This method completes a cart and places the order. It's the last step of the checkout flow.
|
622
|
+
* The method sends a request to the [Complete Cart](https://docs.medusajs.com/v2/api/store#carts_postcartsidcomplete)
|
623
|
+
* API route.
|
624
|
+
*
|
625
|
+
* Related guide: [Learn how to complete cart in checkout flow](https://docs.medusajs.com/v2/resources/storefront-development/checkout/complete-cart).
|
626
|
+
*
|
627
|
+
* @param cartId - The cart's ID.
|
628
|
+
* @param query - Configure the fields to retrieve in the created order.
|
629
|
+
* @param headers - Headers to pass in the request.
|
630
|
+
* @returns The order's details, if it was placed successfully. Otherwise, the cart is returned with an error.
|
631
|
+
*
|
632
|
+
* @example
|
633
|
+
* sdk.store.cart.complete("cart_123")
|
634
|
+
* .then((data) => {
|
635
|
+
* if(data.type === "cart") {
|
636
|
+
* // an error occurred
|
637
|
+
* console.log(data.error, data.cart)
|
638
|
+
* } else {
|
639
|
+
* // order placed successfully
|
640
|
+
* console.log(data.order)
|
641
|
+
* }
|
642
|
+
* })
|
643
|
+
*/
|
115
644
|
complete: async (cartId, query, headers) => {
|
116
645
|
return this.client.fetch(`/store/carts/${cartId}/complete`, {
|
117
646
|
method: "POST",
|
@@ -121,6 +650,25 @@ class Store {
|
|
121
650
|
},
|
122
651
|
};
|
123
652
|
this.fulfillment = {
|
653
|
+
/**
|
654
|
+
* This method retrieves the list of shipping options for a cart. It sends a request to
|
655
|
+
* the [List Shipping Options](https://docs.medusajs.com/v2/api/store#shipping-options_getshippingoptions)
|
656
|
+
* API route.
|
657
|
+
*
|
658
|
+
* Related guide: [Implement shipping step during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/shipping).
|
659
|
+
*
|
660
|
+
* @param query - The cart's details along with configurations of the fields to retrieve in the options.
|
661
|
+
* @param headers - Headers to pass in the request.
|
662
|
+
* @returns The shipping options that can be used for the cart.
|
663
|
+
*
|
664
|
+
* @example
|
665
|
+
* sdk.store.fulfillment.listCartOptions({
|
666
|
+
* cart_id: "cart_123"
|
667
|
+
* })
|
668
|
+
* .then(({ shipping_options }) => {
|
669
|
+
* console.log(shipping_options)
|
670
|
+
* })
|
671
|
+
*/
|
124
672
|
listCartOptions: async (query, headers) => {
|
125
673
|
return this.client.fetch(`/store/shipping-options`, {
|
126
674
|
headers,
|
@@ -129,12 +677,99 @@ class Store {
|
|
129
677
|
},
|
130
678
|
};
|
131
679
|
this.payment = {
|
680
|
+
/**
|
681
|
+
* This method retrieves the payment providers available in a region, which is useful during checkout.
|
682
|
+
* It sends a request to the [List Payment Providers](https://docs.medusajs.com/v2/api/store#payment-providers_getpaymentproviders)
|
683
|
+
* API route.
|
684
|
+
*
|
685
|
+
* Related guide: [Implement payment step during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment).
|
686
|
+
*
|
687
|
+
* @param query - The filters to apply on the retrieved providers, along with configurations of the
|
688
|
+
* fields to retrieve in the options.
|
689
|
+
* @param headers - Headers to pass in the request.
|
690
|
+
* @returns The list of payment providers.
|
691
|
+
*
|
692
|
+
* @example
|
693
|
+
* To retrieve the list of payment providers for a region:
|
694
|
+
*
|
695
|
+
* ```ts
|
696
|
+
* sdk.store.payment.listPaymentProviders({
|
697
|
+
* region_id: "reg_123"
|
698
|
+
* })
|
699
|
+
* .then(({ payment_providers, count, offset, limit }) => {
|
700
|
+
* console.log(payment_providers)
|
701
|
+
* })
|
702
|
+
* ```
|
703
|
+
*
|
704
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
705
|
+
*
|
706
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
707
|
+
*
|
708
|
+
* ```ts
|
709
|
+
* sdk.store.payment.listPaymentProviders({
|
710
|
+
* region_id: "reg_123",
|
711
|
+
* limit: 10,
|
712
|
+
* offset: 10
|
713
|
+
* })
|
714
|
+
* .then(({ payment_providers, count, offset, limit }) => {
|
715
|
+
* console.log(payment_providers)
|
716
|
+
* })
|
717
|
+
* ```
|
718
|
+
*
|
719
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
720
|
+
* in each provider:
|
721
|
+
*
|
722
|
+
* ```ts
|
723
|
+
* sdk.store.payment.listPaymentProviders({
|
724
|
+
* region_id: "reg_123",
|
725
|
+
* limit: 10,
|
726
|
+
* offset: 10,
|
727
|
+
* fields: "id"
|
728
|
+
* })
|
729
|
+
* .then(({ payment_providers, count, offset, limit }) => {
|
730
|
+
* console.log(payment_providers)
|
731
|
+
* })
|
732
|
+
* ```
|
733
|
+
*
|
734
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
735
|
+
*/
|
132
736
|
listPaymentProviders: async (query, headers) => {
|
133
737
|
return this.client.fetch(`/store/payment-providers`, {
|
134
738
|
headers,
|
135
739
|
query,
|
136
740
|
});
|
137
741
|
},
|
742
|
+
/**
|
743
|
+
* This method creates a payment session of a cart's payment collection, selecting a payment provider.
|
744
|
+
* It sends a request to the [Initialize Payment Session](https://docs.medusajs.com/v2/api/store#payment-collections_postpaymentcollectionsidpaymentsessions)
|
745
|
+
* API route.
|
746
|
+
*
|
747
|
+
* If the cart doesn't have a payment collection, a payment collection is created for the cart by
|
748
|
+
* sending a request to the [Create Payment Collection](https://docs.medusajs.com/v2/api/store#payment-collections_postpaymentcollections)
|
749
|
+
* API route.
|
750
|
+
*
|
751
|
+
* Related guide: [Implement payment step during checkout](https://docs.medusajs.com/v2/resources/storefront-development/checkout/payment).
|
752
|
+
*
|
753
|
+
* @param cart - The cart's details.
|
754
|
+
* @param body - The payment session's details.
|
755
|
+
* @param query - Configure the fields to retrieve in the payment collection.
|
756
|
+
* @param headers - Headers to pass in the request.
|
757
|
+
* @returns The payment collection's details.
|
758
|
+
*
|
759
|
+
* @example
|
760
|
+
* sdk.store.payment.initiatePaymentSession(
|
761
|
+
* cart, // assuming you already have the cart object.
|
762
|
+
* {
|
763
|
+
* provider_id: "pp_stripe_stripe",
|
764
|
+
* data: {
|
765
|
+
* // any data relevant for the provider.
|
766
|
+
* }
|
767
|
+
* }
|
768
|
+
* )
|
769
|
+
* .then(({ payment_collection }) => {
|
770
|
+
* console.log(payment_collection)
|
771
|
+
* })
|
772
|
+
*/
|
138
773
|
initiatePaymentSession: async (cart, body, query, headers) => {
|
139
774
|
let paymentCollectionId = cart.payment_collection?.id;
|
140
775
|
if (!paymentCollectionId) {
|
@@ -156,12 +791,91 @@ class Store {
|
|
156
791
|
},
|
157
792
|
};
|
158
793
|
this.order = {
|
794
|
+
/**
|
795
|
+
* This method retrieves a paginated list of orders matching the specified filters. It
|
796
|
+
* sends a request to the [List Orders](https://docs.medusajs.com/v2/api/store#orders_getorders)
|
797
|
+
* API route.
|
798
|
+
*
|
799
|
+
* @param query - Configure the fields to retrieve in the orders.
|
800
|
+
* @param headers - Headers to pass in the request.
|
801
|
+
* @returns The paginated list of orders.
|
802
|
+
*
|
803
|
+
* @example
|
804
|
+
* To retrieve the list of orders:
|
805
|
+
*
|
806
|
+
* ```ts
|
807
|
+
* sdk.store.order.list()
|
808
|
+
* .then(({ orders, count, offset, limit }) => {
|
809
|
+
* console.log(orders)
|
810
|
+
* })
|
811
|
+
* ```
|
812
|
+
*
|
813
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
814
|
+
*
|
815
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
816
|
+
*
|
817
|
+
* ```ts
|
818
|
+
* sdk.store.order.list({
|
819
|
+
* limit: 10,
|
820
|
+
* offset: 10
|
821
|
+
* })
|
822
|
+
* .then(({ orders, count, offset, limit }) => {
|
823
|
+
* console.log(orders)
|
824
|
+
* })
|
825
|
+
* ```
|
826
|
+
*
|
827
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
828
|
+
* in each order:
|
829
|
+
*
|
830
|
+
* ```ts
|
831
|
+
* sdk.store.order.list({
|
832
|
+
* fields: "id,*items"
|
833
|
+
* })
|
834
|
+
* .then(({ orders, count, offset, limit }) => {
|
835
|
+
* console.log(orders)
|
836
|
+
* })
|
837
|
+
* ```
|
838
|
+
*
|
839
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
840
|
+
*/
|
159
841
|
list: async (query, headers) => {
|
160
842
|
return this.client.fetch(`/store/orders`, {
|
161
843
|
query,
|
162
844
|
headers,
|
163
845
|
});
|
164
846
|
},
|
847
|
+
/**
|
848
|
+
* This method retrieves an order by its ID. It sends a request to the
|
849
|
+
* [Get Order](https://docs.medusajs.com/v2/api/store#orders_getordersid) API route.
|
850
|
+
*
|
851
|
+
* @param id - The order's ID.
|
852
|
+
* @param query - Configure the fields to retrieve in the order.
|
853
|
+
* @param headers - Headers to pass in the request.
|
854
|
+
* @returns The order's details.
|
855
|
+
*
|
856
|
+
* @example
|
857
|
+
* To retrieve an order by its ID:
|
858
|
+
*
|
859
|
+
* ```ts
|
860
|
+
* sdk.store.order.retrieve("order_123")
|
861
|
+
* .then(({ order }) => {
|
862
|
+
* console.log(order)
|
863
|
+
* })
|
864
|
+
* ```
|
865
|
+
*
|
866
|
+
* To specify the fields and relations to retrieve:
|
867
|
+
*
|
868
|
+
* ```ts
|
869
|
+
* sdk.store.order.retrieve("order_123", {
|
870
|
+
* fields: "id,*items"
|
871
|
+
* })
|
872
|
+
* .then(({ order }) => {
|
873
|
+
* console.log(order)
|
874
|
+
* })
|
875
|
+
* ```
|
876
|
+
*
|
877
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
878
|
+
*/
|
165
879
|
retrieve: async (id, query, headers) => {
|
166
880
|
return this.client.fetch(`/store/orders/${id}`, {
|
167
881
|
headers,
|
@@ -170,6 +884,39 @@ class Store {
|
|
170
884
|
},
|
171
885
|
};
|
172
886
|
this.customer = {
|
887
|
+
/**
|
888
|
+
* This method registers a customer. It sends a request to the [Register Customer](https://docs.medusajs.com/v2/api/store#customers_postcustomers)
|
889
|
+
* API route.
|
890
|
+
*
|
891
|
+
* You must use the {@link Auth.register} method first to retrieve a registration token. Then, pass that
|
892
|
+
* registration token in the `headers` parameter of this method as an authorization bearer header.
|
893
|
+
*
|
894
|
+
* Related guide: [How to register customer in storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/register)
|
895
|
+
*
|
896
|
+
* @param body - The customer's details.
|
897
|
+
* @param query - Configure the fields to retrieve in the customer.
|
898
|
+
* @param headers - Headers to pass in the request. This is where you include the authorization JWT registration token.
|
899
|
+
* @returns The customer's details.
|
900
|
+
*
|
901
|
+
* @example
|
902
|
+
* const token = await sdk.auth.register("customer", "emailpass", {
|
903
|
+
* "email": "customer@gmail.com",
|
904
|
+
* "password": "supersecret"
|
905
|
+
* })
|
906
|
+
*
|
907
|
+
* sdk.store.customer.create(
|
908
|
+
* {
|
909
|
+
* "email": "customer@gmail.com"
|
910
|
+
* },
|
911
|
+
* {},
|
912
|
+
* {
|
913
|
+
* authorization: `Bearer ${token}`
|
914
|
+
* }
|
915
|
+
* )
|
916
|
+
* .then(({ customer }) => {
|
917
|
+
* console.log(customer)
|
918
|
+
* })
|
919
|
+
*/
|
173
920
|
create: async (body, query, headers) => {
|
174
921
|
return this.client.fetch(`/store/customers`, {
|
175
922
|
method: "POST",
|
@@ -178,6 +925,28 @@ class Store {
|
|
178
925
|
query,
|
179
926
|
});
|
180
927
|
},
|
928
|
+
/**
|
929
|
+
* This method updates the logged-in customer's details. The customer must be logged in
|
930
|
+
* first with the {@link Auth.login} method.
|
931
|
+
*
|
932
|
+
* It sends a request to the
|
933
|
+
* [Update Customer](https://docs.medusajs.com/v2/api/store#customers_postcustomersme) API route.
|
934
|
+
*
|
935
|
+
* Related guide: [How to edit customer's profile in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/profile).
|
936
|
+
*
|
937
|
+
* @param body - The customer's details to update.
|
938
|
+
* @param query - Configure the fields to retrieve in the customer.
|
939
|
+
* @param headers - Headers to pass in the request.
|
940
|
+
* @returns The customer's details.
|
941
|
+
*
|
942
|
+
* @example
|
943
|
+
* sdk.store.customer.update({
|
944
|
+
* first_name: "John"
|
945
|
+
* })
|
946
|
+
* .then(({ customer }) => {
|
947
|
+
* console.log(customer)
|
948
|
+
* })
|
949
|
+
*/
|
181
950
|
update: async (body, query, headers) => {
|
182
951
|
return this.client.fetch(`/store/customers/me`, {
|
183
952
|
method: "POST",
|
@@ -186,12 +955,51 @@ class Store {
|
|
186
955
|
query,
|
187
956
|
});
|
188
957
|
},
|
958
|
+
/**
|
959
|
+
* This method retrieves the logged-in customer's details. The customer must be logged in
|
960
|
+
* first with the {@link Auth.login} method.
|
961
|
+
*
|
962
|
+
* It sends a request to the [Get Logged-In Customer](https://docs.medusajs.com/v2/api/store#customers_getcustomersme)
|
963
|
+
* API route.
|
964
|
+
*
|
965
|
+
* @param query - Configure the fields to retrieve in the customer.
|
966
|
+
* @param headers - Headers to pass in the request.
|
967
|
+
* @returns The customer's details.
|
968
|
+
*
|
969
|
+
* @example
|
970
|
+
* sdk.store.customer.retrieve()
|
971
|
+
* .then(({ customer }) => {
|
972
|
+
* console.log(customer)
|
973
|
+
* })
|
974
|
+
*/
|
189
975
|
retrieve: async (query, headers) => {
|
190
976
|
return this.client.fetch(`/store/customers/me`, {
|
191
977
|
query,
|
192
978
|
headers,
|
193
979
|
});
|
194
980
|
},
|
981
|
+
/**
|
982
|
+
* This method creates an address for the logged-in customer. The customer must be logged in
|
983
|
+
* first with the {@link Auth.login} method.
|
984
|
+
*
|
985
|
+
* It sends a request to the [Create Address](https://docs.medusajs.com/v2/api/store#customers_postcustomersmeaddresses)
|
986
|
+
* API route.
|
987
|
+
*
|
988
|
+
* Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses)
|
989
|
+
*
|
990
|
+
* @param body - The address's details.
|
991
|
+
* @param query - Configure the fields to retrieve in the customer.
|
992
|
+
* @param headers - Headers to pass in the request.
|
993
|
+
* @returns The customer's details.
|
994
|
+
*
|
995
|
+
* @example
|
996
|
+
* sdk.store.customer.createAddress({
|
997
|
+
* country_code: "us"
|
998
|
+
* })
|
999
|
+
* .then(({ customer }) => {
|
1000
|
+
* console.log(customer)
|
1001
|
+
* })
|
1002
|
+
*/
|
195
1003
|
createAddress: async (body, query, headers) => {
|
196
1004
|
return this.client.fetch(`/store/customers/me/addresses`, {
|
197
1005
|
method: "POST",
|
@@ -200,6 +1008,32 @@ class Store {
|
|
200
1008
|
query,
|
201
1009
|
});
|
202
1010
|
},
|
1011
|
+
/**
|
1012
|
+
* This method updates the address of the logged-in customer. The customer must be logged in
|
1013
|
+
* first with the {@link Auth.login} method.
|
1014
|
+
*
|
1015
|
+
* It sends a request to the [Update Address](https://docs.medusajs.com/v2/api/store#customers_postcustomersmeaddressesaddress_id)
|
1016
|
+
* API route.
|
1017
|
+
*
|
1018
|
+
* Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses)
|
1019
|
+
*
|
1020
|
+
* @param addressId - The ID of the address to update.
|
1021
|
+
* @param body - The details to update in the address.
|
1022
|
+
* @param query - Configure the fields to retrieve in the customer.
|
1023
|
+
* @param headers - Headers to pass in the request.
|
1024
|
+
* @returns The customer's details.
|
1025
|
+
*
|
1026
|
+
* @example
|
1027
|
+
* sdk.store.customer.updateAddress(
|
1028
|
+
* "caddr_123",
|
1029
|
+
* {
|
1030
|
+
* country_code: "us"
|
1031
|
+
* }
|
1032
|
+
* )
|
1033
|
+
* .then(({ customer }) => {
|
1034
|
+
* console.log(customer)
|
1035
|
+
* })
|
1036
|
+
*/
|
203
1037
|
updateAddress: async (addressId, body, query, headers) => {
|
204
1038
|
return this.client.fetch(`/store/customers/me/addresses/${addressId}`, {
|
205
1039
|
method: "POST",
|
@@ -208,18 +1042,130 @@ class Store {
|
|
208
1042
|
query,
|
209
1043
|
});
|
210
1044
|
},
|
1045
|
+
/**
|
1046
|
+
* This method retrieves the logged-in customer's address. The customer must be logged in
|
1047
|
+
* first with the {@link Auth.login} method.
|
1048
|
+
*
|
1049
|
+
* It sends a request to the [List Customer's Address](https://docs.medusajs.com/v2/api/store#customers_getcustomersmeaddresses)
|
1050
|
+
* API route.
|
1051
|
+
*
|
1052
|
+
* Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses)
|
1053
|
+
*
|
1054
|
+
* @param query - Configure the fields to retrieve in the addresses.
|
1055
|
+
* @param headers - Headers to pass in the request.
|
1056
|
+
* @returns The paginated list of addresses.
|
1057
|
+
*
|
1058
|
+
* @example
|
1059
|
+
* To retrieve the list of addresses:
|
1060
|
+
*
|
1061
|
+
* ```ts
|
1062
|
+
* sdk.store.customer.listAddress()
|
1063
|
+
* .then(({ addresses, count, offset, limit }) => {
|
1064
|
+
* console.log(addresses)
|
1065
|
+
* })
|
1066
|
+
* ```
|
1067
|
+
*
|
1068
|
+
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
1069
|
+
*
|
1070
|
+
* For example, to retrieve only 10 items and skip 10 items:
|
1071
|
+
*
|
1072
|
+
* ```ts
|
1073
|
+
* sdk.store.customer.listAddress({
|
1074
|
+
* limit: 10,
|
1075
|
+
* offset: 10
|
1076
|
+
* })
|
1077
|
+
* .then(({ addresses, count, offset, limit }) => {
|
1078
|
+
* console.log(addresses)
|
1079
|
+
* })
|
1080
|
+
* ```
|
1081
|
+
*
|
1082
|
+
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
1083
|
+
* in each address:
|
1084
|
+
*
|
1085
|
+
* ```ts
|
1086
|
+
* sdk.store.customer.listAddress({
|
1087
|
+
* fields: "id,country_code"
|
1088
|
+
* })
|
1089
|
+
* .then(({ addresses, count, offset, limit }) => {
|
1090
|
+
* console.log(addresses)
|
1091
|
+
* })
|
1092
|
+
* ```
|
1093
|
+
*
|
1094
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
1095
|
+
*/
|
211
1096
|
listAddress: async (query, headers) => {
|
212
1097
|
return this.client.fetch(`/store/customers/me/addresses`, {
|
213
1098
|
query,
|
214
1099
|
headers,
|
215
1100
|
});
|
216
1101
|
},
|
1102
|
+
/**
|
1103
|
+
* This method retrieves an address of the logged-in customer. The customer must be logged in
|
1104
|
+
* first with the {@link Auth.login} method.
|
1105
|
+
*
|
1106
|
+
* It sends a request to the [Get Address](https://docs.medusajs.com/v2/api/store#customers_getcustomersmeaddressesaddress_id)
|
1107
|
+
* API route.
|
1108
|
+
*
|
1109
|
+
* Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses)
|
1110
|
+
*
|
1111
|
+
* @param addressId - The address's ID.
|
1112
|
+
* @param query - Configure the fields to retrieve in the address.
|
1113
|
+
* @param headers - Headers to pass in the request.
|
1114
|
+
* @returns The address's details.
|
1115
|
+
*
|
1116
|
+
* @example
|
1117
|
+
* To retrieve an address by its ID:
|
1118
|
+
*
|
1119
|
+
* ```ts
|
1120
|
+
* sdk.store.customer.retrieveAddress(
|
1121
|
+
* "caddr_123"
|
1122
|
+
* )
|
1123
|
+
* .then(({ address }) => {
|
1124
|
+
* console.log(address)
|
1125
|
+
* })
|
1126
|
+
* ```
|
1127
|
+
*
|
1128
|
+
* To specify the fields and relations to retrieve:
|
1129
|
+
*
|
1130
|
+
* ```ts
|
1131
|
+
* sdk.store.customer.retrieveAddress(
|
1132
|
+
* "caddr_123",
|
1133
|
+
* {
|
1134
|
+
* fields: "id,country_code"
|
1135
|
+
* }
|
1136
|
+
* )
|
1137
|
+
* .then(({ address }) => {
|
1138
|
+
* console.log(address)
|
1139
|
+
* })
|
1140
|
+
* ```
|
1141
|
+
*
|
1142
|
+
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/v2/api/store#select-fields-and-relations).
|
1143
|
+
*/
|
217
1144
|
retrieveAddress: async (addressId, query, headers) => {
|
218
1145
|
return this.client.fetch(`/store/customers/me/addresses/${addressId}`, {
|
219
1146
|
query,
|
220
1147
|
headers,
|
221
1148
|
});
|
222
1149
|
},
|
1150
|
+
/**
|
1151
|
+
* This method deletes an address of the logged-in customer. The customer must be logged in
|
1152
|
+
* first with the {@link Auth.login} method.
|
1153
|
+
*
|
1154
|
+
* It sends a request to the [Remove Address](https://docs.medusajs.com/v2/api/store#customers_deletecustomersmeaddressesaddress_id)
|
1155
|
+
* API route.
|
1156
|
+
*
|
1157
|
+
* Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/v2/resources/storefront-development/customers/addresses)
|
1158
|
+
*
|
1159
|
+
* @param addressId - The address's ID.
|
1160
|
+
* @param headers - Headers to pass in the request.
|
1161
|
+
* @returns The deletion's details.
|
1162
|
+
*
|
1163
|
+
* @example
|
1164
|
+
* sdk.store.customer.deleteAddress("caddr_123")
|
1165
|
+
* .then(({ deleted, parent: customer }) => {
|
1166
|
+
* console.log(customer)
|
1167
|
+
* })
|
1168
|
+
*/
|
223
1169
|
deleteAddress: async (addressId, headers) => {
|
224
1170
|
return this.client.fetch(`/store/customers/me/addresses/${addressId}`, {
|
225
1171
|
method: "DELETE",
|