@medusajs/js-sdk 0.0.2-snapshot-20241021074955 → 0.0.2-snapshot-20241021145551

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