1 import { FindParams, HttpTypes, SelectParams } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class Store {
6 /**
7 * @ignore
8 */
9 private client: Client
10
11 /**
12 * @ignore
13 */
14 constructor(client: Client) {
15 this.client = client
16 }
17
18 /**
19 * @tags region
20 */
21 public region = {
22 /**
23 * This method retrieves the paginated list of regions in the store. It sends a request to the
24 * [List Regions API route](https://docs.medusajs.com/api/store/regions/list-regions).
25 *
26 * Related guide: [How to list regions in a storefront](https://docs.medusajs.com/resources/storefront-development/regions/list).
27 *
28 * @param query - Filters and pagination configurations.
29 * @param headers - Headers to pass in the request
30 * @returns The paginated list of regions.
31 *
32 * @example
33 * To retrieve the list of regions:
34 *
35 * ```ts
36 * sdk.store.region.list()
37 * .then(({ regions, count, limit, offset }) => {
38 * console.log(regions)
39 * })
40 * ```
41 *
42 * To configure the pagination, pass the `limit` and `offset` query parameters.
43 *
44 * For example, to retrieve only 10 items and skip 10 items:
45 *
46 * ```ts
47 * sdk.store.region.list({
48 * limit: 10,
49 * offset: 10
50 * })
51 * .then(({ regions, count, limit, offset }) => {
52 * console.log(regions)
53 * })
54 * ```
55 *
56 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
57 * in each region:
58 *
59 * ```ts
60 * sdk.store.region.list({
61 * fields: "id,*countries"
62 * })
63 * .then(({ regions, count, limit, offset }) => {
64 * console.log(regions)
65 * })
66 * ```
67 *
68 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
69 */
70 list: async (
71 query?: FindParams & HttpTypes.StoreRegionFilters,
72 headers?: ClientHeaders
73 ) => {
74 return this.client.fetch<HttpTypes.StoreRegionListResponse>(
75 `/store/regions`,
76 {
77 query,
78 headers,
79 }
80 )
81 },
82 /**
83 * This method retrieves a region by its ID. It sends a request to the [Get Region](https://docs.medusajs.com/api/store/regions/get-a-region)
84 * API route.
85 *
86 * Related guide: [Store and retrieve regions in a storefront](https://docs.medusajs.com/resources/storefront-development/regions/store-retrieve-region).
87 *
88 * @param id - The region's ID.
89 * @param query - Configure the fields to retrieve in the region.
90 * @param headers - Headers to pass in the request
91 * @returns The region.
92 *
93 * @example
94 * To retrieve a region by its ID:
95 *
96 * ```ts
97 * sdk.store.region.retrieve("reg_123")
98 * .then(({ region }) => {
99 * console.log(region)
100 * })
101 * ```
102 *
103 * To specify the fields and relations to retrieve:
104 *
105 * ```ts
106 * sdk.store.region.retrieve(
107 * "reg_123",
108 * {
109 * fields: "id,*countries"
110 * }
111 * )
112 * .then(({ region }) => {
113 * console.log(region)
114 * })
115 * ```
116 *
117 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
118 */
119 retrieve: async (
120 id: string,
121 query?: SelectParams,
122 headers?: ClientHeaders
123 ) => {
124 return this.client.fetch<HttpTypes.StoreRegionResponse>(
125 `/store/regions/${id}`,
126 {
127 query,
128 headers,
129 }
130 )
131 },
132 }
133
134 /**
135 * @tags product
136 */
137 public collection = {
138 /**
139 * This method retrieves a paginated list of product collections. It sends a request to the
140 * [List Collections](https://docs.medusajs.com/api/store/collections/list-collections) API route.
141 *
142 * Related guide: [How to retrieve collections in a storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/list).
143 *
144 * @param query - Filters and pagination configurations.
145 * @param headers - Headers to pass in the request
146 * @returns The paginated list of collections.
147 *
148 * @example
149 * To retrieve the list of collections:
150 *
151 * ```ts
152 * sdk.store.collection.list()
153 * .then(({ collections, count, limit, offset }) => {
154 * console.log(collections)
155 * })
156 * ```
157 *
158 * To configure the pagination, pass the `limit` and `offset` query parameters.
159 *
160 * For example, to retrieve only 10 items and skip 10 items:
161 *
162 * ```ts
163 * sdk.store.collection.list({
164 * limit: 10,
165 * offset: 10
166 * })
167 * .then(({ collections, count, limit, offset }) => {
168 * console.log(collections)
169 * })
170 * ```
171 *
172 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
173 * in each collection:
174 *
175 * ```ts
176 * sdk.store.collection.list({
177 * fields: "id,handle"
178 * })
179 * .then(({ collections, count, limit, offset }) => {
180 * console.log(collections)
181 * })
182 * ```
183 *
184 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
185 */
186 list: async (
187 query?: FindParams & HttpTypes.StoreCollectionListParams,
188 headers?: ClientHeaders
189 ) => {
190 return this.client.fetch<HttpTypes.StoreCollectionListResponse>(
191 `/store/collections`,
192 {
193 query,
194 headers,
195 }
196 )
197 },
198 /**
199 * This method retrieves a collection by its ID. It sends a request to the [Get Collection](https://docs.medusajs.com/api/store/collections/get-a-collection)
200 * API route.
201 *
202 * Related guide: [How to retrieve a collection in a storefront](https://docs.medusajs.com/resources/storefront-development/products/collections/retrieve).
203 *
204 * @param id - The ID of the collection to retrieve.
205 * @param query - Configure the fields to retrieve in the collection.
206 * @param headers - Headers to pass in the request
207 * @returns The collection.
208 *
209 * @example
210 * To retrieve a collection by its ID:
211 *
212 * ```ts
213 * sdk.store.collection.retrieve("pcol_123")
214 * .then(({ collection }) => {
215 * console.log(collection)
216 * })
217 * ```
218 *
219 * To specify the fields and relations to retrieve:
220 *
221 * ```ts
222 * sdk.store.collection.retrieve("pcol_123", {
223 * fields: "id,handle"
224 * })
225 * .then(({ collection }) => {
226 * console.log(collection)
227 * })
228 * ```
229 *
230 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
231 */
232 retrieve: async (
233 id: string,
234 query?: SelectParams,
235 headers?: ClientHeaders
236 ) => {
237 return this.client.fetch<HttpTypes.StoreCollectionResponse>(
238 `/store/collections/${id}`,
239 {
240 query,
241 headers,
242 }
243 )
244 },
245 }
246
247 /**
248 * @tags product
249 */
250 public category = {
251 /**
252 * This method retrieves a paginated list of product categories. It sends a request to the
253 * [List Categories](https://docs.medusajs.com/api/store/product-categories/list-product-categories) API route.
254 *
255 * Related guide: [How to retrieve list of categories in the storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/list).
256 *
257 * @param query - Filters and pagination configurations.
258 * @param headers - Headers to pass in the request.
259 * @returns The paginated list of categories.
260 *
261 * @example
262 * To retrieve the list of categories:
263 *
264 * ```ts
265 * sdk.store.category.list()
266 * .then(({ product_categories, count, offset, limit }) => {
267 * console.log(product_categories)
268 * })
269 * ```
270 *
271 * To configure the pagination, pass the `limit` and `offset` query parameters.
272 *
273 * For example, to retrieve only 10 items and skip 10 items:
274 *
275 * ```ts
276 * sdk.store.category.list({
277 * limit: 10,
278 * offset: 10
279 * })
280 * .then(({ product_categories, count, offset, limit }) => {
281 * console.log(product_categories)
282 * })
283 * ```
284 *
285 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
286 * in each category:
287 *
288 * ```ts
289 * sdk.store.category.list({
290 * fields: "id,*parent_category"
291 * })
292 * .then(({ product_categories, count, offset, limit }) => {
293 * console.log(product_categories)
294 * })
295 * ```
296 *
297 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
298 */
299 list: async (
300 query?: FindParams & HttpTypes.StoreProductCategoryListParams,
301 headers?: ClientHeaders
302 ) => {
303 return this.client.fetch<HttpTypes.StoreProductCategoryListResponse>(
304 `/store/product-categories`,
305 {
306 query,
307 headers,
308 }
309 )
310 },
311 /**
312 * This method retrieves a category by its ID. It sends a request to the
313 * [Retrieve Product Category](https://docs.medusajs.com/api/store/product-categories/get-a-product-category).
314 *
315 * Related guide: [How to retrieve a category in the storefront](https://docs.medusajs.com/resources/storefront-development/products/categories/retrieve).
316 *
317 * @param id - The ID of the category to retrieve.
318 * @param query - Configure the fields to retrieve in the category.
319 * @param headers - Headers to pass in the request
320 * @returns The category.
321 *
322 * @example
323 * To retrieve a category by its ID:
324 *
325 * ```ts
326 * sdk.store.category.retrieve("pcat_123")
327 * .then(({ product_category }) => {
328 * console.log(product_category)
329 * })
330 * ```
331 *
332 * To specify the fields and relations to retrieve:
333 *
334 * ```ts
335 * sdk.store.category.retrieve("pcat_123", {
336 * fields: "id,*parent_category"
337 * })
338 * .then(({ product_category }) => {
339 * console.log(product_category)
340 * })
341 * ```
342 *
343 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
344 */
345 retrieve: async (
346 id: string,
347 query?: HttpTypes.StoreProductCategoryParams,
348 headers?: ClientHeaders
349 ) => {
350 return this.client.fetch<HttpTypes.StoreProductCategoryResponse>(
351 `/store/product-categories/${id}`,
352 {
353 query,
354 headers,
355 }
356 )
357 },
358 }
359
360 /**
361 * @tags product
362 * @since 2.16.0
363 */
364 public productOption = {
365 /**
366 * This method retrieves a paginated list of product options. It sends a request to the
367 * [List Product Options](https://docs.medusajs.com/api/store/product-options/list-product-options) API route.
368 *
369 * @param query - Filters and pagination configurations.
370 * @param headers - Headers to pass in the request.
371 * @returns The paginated list of product options.
372 *
373 * @example
374 * To retrieve the list of product options:
375 *
376 * ```ts
377 * sdk.store.productOption.list()
378 * .then(({ product_options, count, offset, limit }) => {
379 * console.log(product_options)
380 * })
381 * ```
382 *
383 * To configure the pagination, pass the `limit` and `offset` query parameters.
384 *
385 * For example, to retrieve only 10 items and skip 10 items:
386 *
387 * ```ts
388 * sdk.store.productOption.list({
389 * limit: 10,
390 * offset: 10
391 * })
392 * .then(({ product_options, count, offset, limit }) => {
393 * console.log(product_options)
394 * })
395 * ```
396 *
397 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
398 * in each product option:
399 *
400 * ```ts
401 * sdk.store.productOption.list({
402 * fields: "id,title"
403 * })
404 * .then(({ product_options, count, offset, limit }) => {
405 * console.log(product_options)
406 * })
407 * ```
408 *
409 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
410 */
411 list: async (
412 query?: FindParams & HttpTypes.StoreProductOptionListParams,
413 headers?: ClientHeaders
414 ) => {
415 return this.client.fetch<HttpTypes.StoreProductOptionListResponse>(
416 `/store/product-options`,
417 {
418 query,
419 headers,
420 }
421 )
422 },
423 /**
424 * This method retrieves a product option by its ID. It sends a request to the
425 * [Retrieve Product Option](https://docs.medusajs.com/api/store/product-options/get-a-product-option).
426 *
427 * @param id - The product option's ID.
428 * @param query - Configure the fields to retrieve in the product option.
429 * @param headers - Headers to pass in the request.
430 * @returns The product option.
431 *
432 * @example
433 * To retrieve a product option by its ID:
434 *
435 * ```ts
436 * sdk.store.productOption.retrieve("opt_123")
437 * .then(({ product_option }) => {
438 * console.log(product_option)
439 * })
440 * ```
441 *
442 * To specify the fields and relations to retrieve:
443 *
444 * ```ts
445 * sdk.store.productOption.retrieve("opt_123", {
446 * fields: "id,title,values.value"
447 * })
448 * .then(({ product_option }) => {
449 * console.log(product_option)
450 * })
451 * ```
452 *
453 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
454 */
455 retrieve: async (
456 id: string,
457 query?: HttpTypes.StoreProductOptionParams,
458 headers?: ClientHeaders
459 ) => {
460 return this.client.fetch<HttpTypes.StoreProductOptionResponse>(
461 `/store/product-options/${id}`,
462 {
463 query,
464 headers,
465 }
466 )
467 },
468 }
469
470 /**
471 * @tags product
472 */
473 public product = {
474 /**
475 * This method retrieves a list of products. It sends a request to the
476 * [List Products API route](https://docs.medusajs.com/api/store/products/list-products).
477 *
478 * Related guides:
479 *
480 * - [How to list products in a storefront](https://docs.medusajs.com/resources/storefront-development/products/list).
481 * - [How to retrieve a product variant's prices in the storefront](https://docs.medusajs.com/resources/storefront-development/products/price)
482 *
483 * @param query - Filters and pagination configurations.
484 * @param headers - Headers to pass in the request.
485 * @returns The paginated list of products.
486 *
487 * @example
488 * To retrieve the list of products:
489 *
490 * ```ts
491 * sdk.store.product.list()
492 * .then(({ products, count, offset, limit }) => {
493 * console.log(products)
494 * })
495 * ```
496 *
497 * To configure the pagination, pass the `limit` and `offset` query parameters.
498 *
499 * For example, to retrieve only 10 items and skip 10 items:
500 *
501 * ```ts
502 * sdk.store.product.list({
503 * limit: 10,
504 * offset: 10
505 * })
506 * .then(({ products, count, offset, limit }) => {
507 * console.log(products)
508 * })
509 * ```
510 *
511 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
512 * in each product:
513 *
514 * ```ts
515 * sdk.store.product.list({
516 * fields: "id,*collection"
517 * })
518 * .then(({ products, count, offset, limit }) => {
519 * console.log(products)
520 * })
521 * ```
522 *
523 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
524 */
525 list: async (
526 query?: HttpTypes.StoreProductListParams,
527 headers?: ClientHeaders
528 ) => {
529 return this.client.fetch<HttpTypes.StoreProductListResponse>(
530 `/store/products`,
531 {
532 query,
533 headers,
534 }
535 )
536 },
537 /**
538 * This method is used to retrieve a product by its ID. It sends a request to the
539 * [Get Product](https://docs.medusajs.com/api/store/products/get-a-product) API route.
540 *
541 * Related guides:
542 *
543 * - [How to retrieve a product in the storefront](https://docs.medusajs.com/resources/storefront-development/products/retrieve).
544 * - [How to retrieve a product variant's prices in the storefront](https://docs.medusajs.com/resources/storefront-development/products/price)
545 *
546 * @param id - The product's ID.
547 * @param query - Configure the fields to retrieve in the product.
548 * @param headers - Headers to pass in the request
549 * @returns The product.
550 *
551 * @example
552 * To retrieve a product by its ID:
553 *
554 * ```ts
555 * sdk.store.product.retrieve("prod_123")
556 * .then(({ product }) => {
557 * console.log(product)
558 * })
559 * ```
560 *
561 * To specify the fields and relations to retrieve:
562 *
563 * ```ts
564 * sdk.store.product.retrieve("prod_123", {
565 * fields: "id,*collection"
566 * })
567 * .then(({ product }) => {
568 * console.log(product)
569 * })
570 * ```
571 *
572 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
573 */
574 retrieve: async (
575 id: string,
576 query?: HttpTypes.StoreProductParams,
577 headers?: ClientHeaders
578 ) => {
579 return this.client.fetch<HttpTypes.StoreProductResponse>(
580 `/store/products/${id}`,
581 {
582 query,
583 headers,
584 }
585 )
586 },
587 }
588
589 /**
590 * Related guides: [How to implement carts in the storefront](https://docs.medusajs.com/resources/storefront-development/cart).
591 *
592 * @tags cart
593 */
594 public cart = {
595 /**
596 * This method creates a cart. It sends a request to the [Create Cart](https://docs.medusajs.com/api/store/carts/create-cart)
597 * API route.
598 *
599 * Related guide: [How to create a cart in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/create).
600 *
601 * @param body - The details of the cart to create.
602 * @param query - Configure the fields to retrieve in the cart.
603 * @param headers - Headers to pass in the request.
604 * @returns The created cart.
605 *
606 * @example
607 * sdk.store.cart.create({
608 * region_id: "reg_123"
609 * })
610 * .then(({ cart }) => {
611 * console.log(cart)
612 * })
613 */
614 create: async (
615 body: HttpTypes.StoreCreateCart,
616 query?: SelectParams,
617 headers?: ClientHeaders
618 ) => {
619 return this.client.fetch<HttpTypes.StoreCartResponse>(`/store/carts`, {
620 method: "POST",
621 headers,
622 body,
623 query,
624 })
625 },
626 /**
627 * This method updates a cart. It sends a request to the
628 * [Update Cart](https://docs.medusajs.com/api/store/carts/update-a-cart) API route.
629 *
630 * Related guide: [How to update a cart in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/update).
631 *
632 * @param id - The cart's ID.
633 * @param body - The data to update in the cart.
634 * @param query - Configure the fields to retrieve in the cart.
635 * @param headers - Headers to pass in the request.
636 * @returns The updated cart.
637 *
638 * @example
639 * sdk.store.cart.update("cart_123", {
640 * region_id: "reg_123"
641 * })
642 * .then(({ cart }) => {
643 * console.log(cart)
644 * })
645 */
646 update: async (
647 id: string,
648 body: HttpTypes.StoreUpdateCart,
649 query?: SelectParams,
650 headers?: ClientHeaders
651 ) => {
652 return this.client.fetch<HttpTypes.StoreCartResponse>(
653 `/store/carts/${id}`,
654 {
655 method: "POST",
656 headers,
657 body,
658 query,
659 }
660 )
661 },
662 /**
663 * This method retrieves a cart by its ID. It sends a request to the
664 * [Get Cart](https://docs.medusajs.com/api/store/carts/get-a-cart) API route.
665 *
666 * Related guide: [How to retrieve a cart in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/retrieve).
667 *
668 * @param id - The cart's ID.
669 * @param query - Configure the fields to retrieve in the cart.
670 * @param headers - Headers to pass in the request.
671 * @returns The cart's details.
672 *
673 * @example
674 * To retrieve a cart by its ID:
675 *
676 * ```ts
677 * sdk.store.cart.retrieve("cart_123")
678 * .then(({ cart }) => {
679 * console.log(cart)
680 * })
681 * ```
682 *
683 * To specify the fields and relations to retrieve:
684 *
685 * ```ts
686 * sdk.store.cart.retrieve("cart_123", {
687 * fields: "id,*items"
688 * })
689 * .then(({ cart }) => {
690 * console.log(cart)
691 * })
692 * ```
693 *
694 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
695 */
696 retrieve: async (
697 id: string,
698 query?: SelectParams,
699 headers?: ClientHeaders
700 ) => {
701 return this.client.fetch<HttpTypes.StoreCartResponse>(
702 `/store/carts/${id}`,
703 {
704 headers,
705 query,
706 }
707 )
708 },
709 /**
710 * This methods adds a product variant to the cart as a line item. It sends a request to the
711 * [Add Line Item](https://docs.medusajs.com/api/store/carts/add-line-item) API route.
712 *
713 * Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items).
714 *
715 * @param cartId - The cart's ID.
716 * @param body - The details of the item to add.
717 * @param query - Configure the fields to retrieve in the cart.
718 * @param headers - Headers to pass in the request.
719 * @returns The cart's details.
720 *
721 * @example
722 * sdk.store.cart.createLineItem("cart_123", {
723 * variant_id: "variant_123",
724 * quantity: 1
725 * })
726 * .then(({ cart }) => {
727 * console.log(cart)
728 * })
729 */
730 createLineItem: async (
731 cartId: string,
732 body: HttpTypes.StoreAddCartLineItem,
733 query?: SelectParams,
734 headers?: ClientHeaders
735 ) => {
736 return this.client.fetch<HttpTypes.StoreCartResponse>(
737 `/store/carts/${cartId}/line-items`,
738 {
739 method: "POST",
740 headers,
741 body,
742 query,
743 }
744 )
745 },
746 /**
747 * This method updates a line item in a cart. It sends a request to the
748 * [Update Line Item](https://docs.medusajs.com/api/store/carts/update-line-item) API route.
749 *
750 * Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items).
751 *
752 * @param cartId - The cart's ID.
753 * @param lineItemId - The line item's ID.
754 * @param body - The data to update.
755 * @param query - Configure the fields to retrieve in the cart.
756 * @param headers - Headers to pass in the request.
757 * @returns The cart's details.
758 *
759 * @example
760 * sdk.store.cart.updateLineItem(
761 * "cart_123",
762 * "li_123",
763 * {
764 * quantity: 1
765 * }
766 * )
767 * .then(({ cart }) => {
768 * console.log(cart)
769 * })
770 */
771 updateLineItem: async (
772 cartId: string,
773 lineItemId: string,
774 body: HttpTypes.StoreUpdateCartLineItem,
775 query?: SelectParams,
776 headers?: ClientHeaders
777 ) => {
778 return this.client.fetch<HttpTypes.StoreCartResponse>(
779 `/store/carts/${cartId}/line-items/${lineItemId}`,
780 {
781 method: "POST",
782 headers,
783 body,
784 query,
785 }
786 )
787 },
788 /**
789 * This method deletes a line item from a cart. It sends a request to the
790 * [Remove Line Item](https://docs.medusajs.com/api/store/carts/remove-line-item) API route.
791 *
792 * Related guide: [How to manage a cart's line items in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items).
793 *
794 * @param cartId - The cart's ID.
795 * @param lineItemId - The item's ID.
796 * @param query - Configure the fields to retrieve in the cart.
797 * @param headers - Headers to pass in the request.
798 * @returns The deletion's details.
799 *
800 * @example
801 * sdk.store.cart.deleteLineItem(
802 * "cart_123",
803 * "li_123"
804 * )
805 * .then(({ deleted, parent: cart }) => {
806 * console.log(deleted, cart)
807 * })
808 */
809 deleteLineItem: async (
810 cartId: string,
811 lineItemId: string,
812 query?: SelectParams,
813 headers?: ClientHeaders
814 ) => {
815 return this.client.fetch<HttpTypes.StoreLineItemDeleteResponse>(
816 `/store/carts/${cartId}/line-items/${lineItemId}`,
817 {
818 method: "DELETE",
819 query,
820 headers,
821 }
822 )
823 },
824 /**
825 * This method adds a shipping method to a cart. It sends a request to
826 * the [Add Shipping Method](https://docs.medusajs.com/api/store/carts/add-shipping-method) API routes.
827 *
828 * Related guide: [Implement shipping step during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/shipping).
829 *
830 * @param cartId - The cart's ID.
831 * @param body - The shipping method's details.
832 * @param query - Configure the fields to retrieve in the cart.
833 * @param headers - Headers to pass in the request.
834 * @returns The cart's details.
835 *
836 * @example
837 * sdk.store.cart.addShippingMethod("cart_123", {
838 * option_id: "so_123",
839 * data: {
840 * // custom data for fulfillment provider.
841 * }
842 * })
843 * .then(({ cart }) => {
844 * console.log(cart)
845 * })
846 */
847 addShippingMethod: async (
848 cartId: string,
849 body: HttpTypes.StoreAddCartShippingMethods,
850 query?: SelectParams,
851 headers?: ClientHeaders
852 ) => {
853 return this.client.fetch<HttpTypes.StoreCartResponse>(
854 `/store/carts/${cartId}/shipping-methods`,
855 {
856 method: "POST",
857 headers,
858 body,
859 query,
860 }
861 )
862 },
863
864
865 /**
866 * This method adds promotion codes to a cart. It sends a request to the
867 * [Add Promotion Code](https://docs.medusajs.com/api/store/carts/add-promotions) API route.
868 *
869 * Related guide: [How to apply promotions to cart in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items).
870 *
871 * @param cartId - The cart's ID.
872 * @param body - The details of the promotion codes to add.
873 * @param query - Configure the fields to retrieve in the cart.
874 * @param headers - Headers to pass in the request.
875 * @returns The cart's details.
876 *
877 * @example
878 * sdk.store.cart.addPromotions("cart_123", {
879 * promo_codes: ["20OFF"]
880 * })
881 * .then(({ cart }) => {
882 * console.log(cart)
883 * })
884 *
885 * @since 2.13.7
886 */
887 addPromotions: async (
888 cartId: string,
889 body: HttpTypes.StoreCartAddPromotion,
890 query?: SelectParams,
891 headers?: ClientHeaders
892 ) => {
893 return this.client.fetch<HttpTypes.StoreCartResponse>(
894 `/store/carts/${cartId}/promotions`,
895 {
896 method: "POST",
897 headers,
898 body,
899 query,
900 }
901 )
902 },
903
904 /**
905 * This method removes promotion codes from a cart. It sends a request to the
906 * [Remove Promotion Code](https://docs.medusajs.com/api/store/carts/remove-promotions-from-cart) API route.
907 *
908 * Related guide: [How to apply promotions to cart in the storefront](https://docs.medusajs.com/resources/storefront-development/cart/manage-items).
909 *
910 * @param cartId - The cart's ID.
911 * @param body - The details of the promotion codes to remove.
912 * @param query - Configure the fields to retrieve in the cart.
913 * @param headers - Headers to pass in the request.
914 * @returns The cart's details.
915 *
916 * @example
917 * sdk.store.cart.removePromotions("cart_123", {
918 * promo_codes: ["20OFF"]
919 * })
920 * .then(({ cart }) => {
921 * console.log(cart)
922 * })
923 *
924 * @since 2.13.7
925 */
926 removePromotions: async (
927 cartId: string,
928 body: HttpTypes.StoreCartRemovePromotion,
929 query?: SelectParams,
930 headers?: ClientHeaders
931 ) => {
932 return this.client.fetch<HttpTypes.StoreCartResponse>(
933 `/store/carts/${cartId}/promotions`,
934 {
935 method: "DELETE",
936 headers,
937 body,
938 query,
939 }
940 )
941 },
942
943 /**
944 * This method completes a cart and places the order. It's the last step of the checkout flow.
945 * The method sends a request to the [Complete Cart](https://docs.medusajs.com/api/store/carts/complete-cart)
946 * API route.
947 *
948 * Related guide: [Learn how to complete cart in checkout flow](https://docs.medusajs.com/resources/storefront-development/checkout/complete-cart).
949 *
950 * @param cartId - The cart's ID.
951 * @param query - Configure the fields to retrieve in the created order.
952 * @param headers - Headers to pass in the request.
953 * @returns The order's details, if it was placed successfully. Otherwise, the cart is returned with an error.
954 *
955 * @example
956 * sdk.store.cart.complete("cart_123")
957 * .then((data) => {
958 * if(data.type === "cart") {
959 * // an error occurred
960 * console.log(data.error, data.cart)
961 * } else {
962 * // order placed successfully
963 * console.log(data.order)
964 * }
965 * })
966 */
967 complete: async (
968 cartId: string,
969 query?: SelectParams,
970 headers?: ClientHeaders
971 ) => {
972 return this.client.fetch<HttpTypes.StoreCompleteCartResponse>(
973 `/store/carts/${cartId}/complete`,
974 {
975 method: "POST",
976 headers,
977 query,
978 }
979 )
980 },
981
982 /**
983 * This method updates the customer of a cart.
984 *
985 * @param id - The cart's ID.
986 * @param query - Configure the fields to retrieve in the cart.
987 * @param headers - Headers to pass in the request.
988 * @returns The updated cart.
989 *
990 * @example
991 * // TODO must be authenticated as the customer to set the cart's customer
992 * sdk.store.cart.transferCart("cart_123")
993 * .then(({ cart }) => {
994 * console.log(cart)
995 * })
996 */
997 transferCart: async (
998 id: string,
999 query?: SelectParams,
1000 headers?: ClientHeaders
1001 ) => {
1002 return this.client.fetch<HttpTypes.StoreCartResponse>(
1003 `/store/carts/${id}/customer`,
1004 {
1005 method: "POST",
1006 headers,
1007 query,
1008 }
1009 )
1010 },
1011 }
1012
1013 /**
1014 * @tags fulfillment
1015 */
1016 public fulfillment = {
1017 /**
1018 * This method retrieves the list of shipping options for a cart. It sends a request to
1019 * the [List Shipping Options](https://docs.medusajs.com/api/store/shipping-options/list-shipping-options-for-cart)
1020 * API route.
1021 *
1022 * Related guide: [Implement shipping step during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/shipping).
1023 *
1024 * @param query - The cart's details along with configurations of the fields to retrieve in the options.
1025 * @param headers - Headers to pass in the request.
1026 * @returns The shipping options that can be used for the cart.
1027 *
1028 * @example
1029 * sdk.store.fulfillment.listCartOptions({
1030 * cart_id: "cart_123"
1031 * })
1032 * .then(({ shipping_options }) => {
1033 * console.log(shipping_options)
1034 * })
1035 */
1036 listCartOptions: async (
1037 query?: HttpTypes.StoreGetShippingOptionList,
1038 headers?: ClientHeaders
1039 ) => {
1040 return this.client.fetch<HttpTypes.StoreShippingOptionListResponse>(
1041 `/store/shipping-options`,
1042 {
1043 headers,
1044 query,
1045 }
1046 )
1047 },
1048
1049 /**
1050 * This method calculates the price of a shipping option in a cart, which is useful during checkout.
1051 * It sends a request to the [Calculate Shipping Option Price](https://docs.medusajs.com/api/store/shipping-options/calculate-shipping-option-price)
1052 * API route.
1053 *
1054 * @param id - The shipping option's ID.
1055 * @param body - The price calculation's details.
1056 * @param query - Configure the fields to retrieve in the shipping option.
1057 * @param headers - Headers to pass in the request.
1058 * @returns The shipping option's details.
1059 *
1060 * @example
1061 * sdk.store.fulfillment.calculate("so_123", {
1062 * cart_id: "cart_123"
1063 * })
1064 * .then(({ shipping_option }) => {
1065 * console.log(shipping_option)
1066 * })
1067 */
1068 calculate: async (
1069 id: string,
1070 body: HttpTypes.StoreCalculateShippingOptionPrice,
1071 query?: HttpTypes.SelectParams,
1072 headers?: ClientHeaders
1073 ) => {
1074 return await this.client.fetch<HttpTypes.StoreShippingOptionResponse>(
1075 `/store/shipping-options/${id}/calculate`,
1076 {
1077 method: "POST",
1078 headers,
1079 body,
1080 query,
1081 }
1082 )
1083 },
1084 }
1085
1086 /**
1087 * @tags payment
1088 */
1089 public payment = {
1090 /**
1091 * This method retrieves the payment providers available in a region, which is useful during checkout.
1092 * It sends a request to the [List Payment Providers](https://docs.medusajs.com/api/store/payment-providers/list-payment-providers)
1093 * API route.
1094 *
1095 * Related guide: [Implement payment step during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/payment).
1096 *
1097 * @param query - The filters to apply on the retrieved providers, along with configurations of the
1098 * fields to retrieve in the options.
1099 * @param headers - Headers to pass in the request.
1100 * @returns The list of payment providers.
1101 *
1102 * @example
1103 * To retrieve the list of payment providers for a region:
1104 *
1105 * ```ts
1106 * sdk.store.payment.listPaymentProviders({
1107 * region_id: "reg_123"
1108 * })
1109 * .then(({ payment_providers, count, offset, limit }) => {
1110 * console.log(payment_providers)
1111 * })
1112 * ```
1113 *
1114 * To configure the pagination, pass the `limit` and `offset` query parameters.
1115 *
1116 * For example, to retrieve only 10 items and skip 10 items:
1117 *
1118 * ```ts
1119 * sdk.store.payment.listPaymentProviders({
1120 * region_id: "reg_123",
1121 * limit: 10,
1122 * offset: 10
1123 * })
1124 * .then(({ payment_providers, count, offset, limit }) => {
1125 * console.log(payment_providers)
1126 * })
1127 * ```
1128 *
1129 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
1130 * in each provider:
1131 *
1132 * ```ts
1133 * sdk.store.payment.listPaymentProviders({
1134 * region_id: "reg_123",
1135 * limit: 10,
1136 * offset: 10,
1137 * fields: "id"
1138 * })
1139 * .then(({ payment_providers, count, offset, limit }) => {
1140 * console.log(payment_providers)
1141 * })
1142 * ```
1143 *
1144 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
1145 */
1146 listPaymentProviders: async (
1147 query?: FindParams & HttpTypes.StorePaymentProviderFilters,
1148 headers?: ClientHeaders
1149 ) => {
1150 return this.client.fetch<HttpTypes.StorePaymentProviderListResponse>(
1151 `/store/payment-providers`,
1152 {
1153 headers,
1154 query,
1155 }
1156 )
1157 },
1158
1159 /**
1160 * This method creates a payment session of a cart's payment collection, selecting a payment provider.
1161 * It sends a request to the [Initialize Payment Session](https://docs.medusajs.com/api/store/payment-collections/initialize-payment-session)
1162 * API route.
1163 *
1164 * If the cart doesn't have a payment collection, a payment collection is created for the cart by
1165 * sending a request to the [Create Payment Collection](https://docs.medusajs.com/api/store/payment-collections/create-payment-collection)
1166 * API route.
1167 *
1168 * Related guide: [Implement payment step during checkout](https://docs.medusajs.com/resources/storefront-development/checkout/payment).
1169 *
1170 * @param cart - The cart's details.
1171 * @param body - The payment session's details.
1172 * @param query - Configure the fields to retrieve in the payment collection.
1173 * @param headers - Headers to pass in the request.
1174 * @returns The payment collection's details.
1175 *
1176 * @example
1177 * sdk.store.payment.initiatePaymentSession(
1178 * cart, // assuming you already have the cart object.
1179 * {
1180 * provider_id: "pp_stripe_stripe",
1181 * data: {
1182 * // any data relevant for the provider.
1183 * }
1184 * }
1185 * )
1186 * .then(({ payment_collection }) => {
1187 * console.log(payment_collection)
1188 * })
1189 */
1190 initiatePaymentSession: async (
1191 cart: HttpTypes.StoreCart,
1192 body: HttpTypes.StoreInitializePaymentSession,
1193 query?: SelectParams,
1194 headers?: ClientHeaders
1195 ) => {
1196 let paymentCollectionId = (cart as any).payment_collection?.id
1197 if (!paymentCollectionId) {
1198 const collectionBody = {
1199 cart_id: cart.id,
1200 }
1201 paymentCollectionId = (
1202 await this.client.fetch<HttpTypes.StorePaymentCollectionResponse>(
1203 `/store/payment-collections`,
1204 {
1205 method: "POST",
1206 headers,
1207 body: collectionBody,
1208 }
1209 )
1210 ).payment_collection.id
1211 }
1212
1213 return this.client.fetch<HttpTypes.StorePaymentCollectionResponse>(
1214 `/store/payment-collections/${paymentCollectionId}/payment-sessions`,
1215 {
1216 method: "POST",
1217 headers,
1218 body,
1219 query,
1220 }
1221 )
1222 },
1223 }
1224
1225 /**
1226 * @tags order
1227 */
1228 public order = {
1229 /**
1230 * This method retrieves a paginated list of orders matching the specified filters. It
1231 * sends a request to the [List Orders](https://docs.medusajs.com/api/store/orders/list-orders)
1232 * API route.
1233 *
1234 * @param query - Configure the fields to retrieve in the orders.
1235 * @param headers - Headers to pass in the request.
1236 * @returns The paginated list of orders.
1237 *
1238 * @example
1239 * To retrieve the list of orders:
1240 *
1241 * ```ts
1242 * // TODO must be authenticated as the customer to list their orders
1243 * sdk.store.order.list()
1244 * .then(({ orders, count, offset, limit }) => {
1245 * console.log(orders)
1246 * })
1247 * ```
1248 *
1249 * To configure the pagination, pass the `limit` and `offset` query parameters.
1250 *
1251 * For example, to retrieve only 10 items and skip 10 items:
1252 *
1253 * ```ts
1254 * // TODO must be authenticated as the customer to list their orders
1255 * sdk.store.order.list({
1256 * limit: 10,
1257 * offset: 10
1258 * })
1259 * .then(({ orders, count, offset, limit }) => {
1260 * console.log(orders)
1261 * })
1262 * ```
1263 *
1264 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
1265 * in each order:
1266 *
1267 * ```ts
1268 * // TODO must be authenticated as the customer to list their orders
1269 * sdk.store.order.list({
1270 * fields: "id,*items"
1271 * })
1272 * .then(({ orders, count, offset, limit }) => {
1273 * console.log(orders)
1274 * })
1275 * ```
1276 *
1277 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
1278 */
1279 list: async (
1280 query?: HttpTypes.StoreOrderFilters,
1281 headers?: ClientHeaders
1282 ) => {
1283 return this.client.fetch<HttpTypes.StoreOrderListResponse>(
1284 `/store/orders`,
1285 {
1286 query,
1287 headers,
1288 }
1289 )
1290 },
1291 /**
1292 * This method retrieves an order by its ID. It sends a request to the
1293 * [Get Order](https://docs.medusajs.com/api/store/orders/get-an-order) API route.
1294 *
1295 * @param id - The order's ID.
1296 * @param query - Configure the fields to retrieve in the order.
1297 * @param headers - Headers to pass in the request.
1298 * @returns The order's details.
1299 *
1300 * @example
1301 * To retrieve an order by its ID:
1302 *
1303 * ```ts
1304 * sdk.store.order.retrieve("order_123")
1305 * .then(({ order }) => {
1306 * console.log(order)
1307 * })
1308 * ```
1309 *
1310 * To specify the fields and relations to retrieve:
1311 *
1312 * ```ts
1313 * sdk.store.order.retrieve("order_123", {
1314 * fields: "id,*items"
1315 * })
1316 * .then(({ order }) => {
1317 * console.log(order)
1318 * })
1319 * ```
1320 *
1321 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
1322 */
1323 retrieve: async (
1324 id: string,
1325 query?: SelectParams,
1326 headers?: ClientHeaders
1327 ) => {
1328 return this.client.fetch<{ order: HttpTypes.StoreOrder }>(
1329 `/store/orders/${id}`,
1330 {
1331 headers,
1332 query,
1333 }
1334 )
1335 },
1336
1337 /**
1338 * This method requests a order transfer from a guest account to the current, logged in customer account.
1339 *
1340 * Customer requesting the transfer must be logged in.
1341 *
1342 * @param body - The transfer's details.
1343 * @param query - Configure the fields to retrieve in the order.
1344 * @param headers - Headers to pass in the request.
1345 * @returns The order details.
1346 *
1347 * @example
1348 * // TODO must be authenticated as the customer to request the order transfer
1349 * sdk.store.order.requestTransfer(
1350 * "order_123",
1351 * {
1352 * description: "I want to transfer this order to my friend."
1353 * },
1354 * {},
1355 * {
1356 * Authorization: `Bearer ${token}`
1357 * }
1358 * )
1359 * .then(({ order }) => {
1360 * console.log(order)
1361 * })
1362 */
1363 requestTransfer: async (
1364 id: string,
1365 body: HttpTypes.StoreRequestOrderTransfer,
1366 query?: SelectParams,
1367 headers?: ClientHeaders
1368 ) => {
1369 return this.client.fetch<HttpTypes.StoreOrderResponse>(
1370 `/store/orders/${id}/transfer/request`,
1371 {
1372 method: "POST",
1373 headers,
1374 body,
1375 query,
1376 }
1377 )
1378 },
1379 /**
1380 * This method cancels an order transfer request.
1381 *
1382 * Customer requesting the transfer must be logged in.
1383 *
1384 * @param id - The order's ID.
1385 * @param query - Configure the fields to retrieve in the order.
1386 * @param headers - Headers to pass in the request.
1387 * @returns The order details.
1388 *
1389 * @example
1390 * // TODO must be authenticated as the customer to cancel the order transfer
1391 * sdk.store.order.cancelTransfer(
1392 * "order_123",
1393 * {},
1394 * {
1395 * Authorization: `Bearer ${token}`
1396 * }
1397 * )
1398 * .then(({ order }) => {
1399 * console.log(order)
1400 * })
1401 */
1402 cancelTransfer: async (
1403 id: string,
1404 query?: SelectParams,
1405 headers?: ClientHeaders
1406 ) => {
1407 return this.client.fetch<HttpTypes.StoreOrderResponse>(
1408 `/store/orders/${id}/transfer/cancel`,
1409 {
1410 method: "POST",
1411 headers,
1412 query,
1413 }
1414 )
1415 },
1416 /**
1417 * The method called for the original owner to accept the order transfer to a new owner.
1418 *
1419 * @param id - The order's ID.
1420 * @param body - The payload containing the transfer token.
1421 * @param query - Configure the fields to retrieve in the order.
1422 * @param headers - Headers to pass in the request.
1423 * @returns The order details.
1424 *
1425 * @example
1426 * sdk.store.order.acceptTransfer(
1427 * "order_123",
1428 * {
1429 * token: "transfer_token"
1430 * },
1431 * {
1432 * Authorization: `Bearer ${token}`
1433 * }
1434 * )
1435 * .then(({ order }) => {
1436 * console.log(order)
1437 * })
1438 */
1439 acceptTransfer: async (
1440 id: string,
1441 body: HttpTypes.StoreAcceptOrderTransfer,
1442 query?: SelectParams,
1443 headers?: ClientHeaders
1444 ) => {
1445 return this.client.fetch<HttpTypes.StoreOrderResponse>(
1446 `/store/orders/${id}/transfer/accept`,
1447 {
1448 method: "POST",
1449 headers,
1450 body,
1451 query,
1452 }
1453 )
1454 },
1455 /**
1456 * The method called for the original owner to decline the order transfer to a new owner.
1457 *
1458 * @param id - The order's ID.
1459 * @param body - The payload containing the transfer token.
1460 * @param query - Configure the fields to retrieve in the order.
1461 * @param headers - Headers to pass in the request.
1462 * @returns The order details.
1463 *
1464 * @example
1465 * sdk.store.order.declineTransfer(
1466 * "order_123",
1467 * {
1468 * token: "transfer_token"
1469 * },
1470 * {
1471 * Authorization: `Bearer ${token}`
1472 * }
1473 * )
1474 * .then(({ order }) => {
1475 * console.log(order)
1476 * })
1477 */
1478 declineTransfer: async (
1479 id: string,
1480 body: HttpTypes.StoreDeclineOrderTransfer,
1481 query?: SelectParams,
1482 headers?: ClientHeaders
1483 ) => {
1484 return this.client.fetch<HttpTypes.StoreOrderResponse>(
1485 `/store/orders/${id}/transfer/decline`,
1486 {
1487 method: "POST",
1488 headers,
1489 body,
1490 query,
1491 }
1492 )
1493 },
1494 }
1495
1496 /**
1497 * @tags customer
1498 */
1499 public customer = {
1500 /**
1501 * This method registers a customer. It sends a request to the [Register Customer](https://docs.medusajs.com/api/store/customers/register-customer)
1502 * API route.
1503 *
1504 * You must use the {@link Auth.register} method first to retrieve a registration token. Then, pass that
1505 * registration token in the `headers` parameter of this method as an authorization bearer header.
1506 *
1507 * Related guide: [How to register customer in storefront](https://docs.medusajs.com/resources/storefront-development/customers/register)
1508 *
1509 * @param body - The customer's details.
1510 * @param query - Configure the fields to retrieve in the customer.
1511 * @param headers - Headers to pass in the request. This is where you include the authorization JWT registration token.
1512 * @returns The customer's details.
1513 *
1514 * @example
1515 * const token = await sdk.auth.register("customer", "emailpass", {
1516 * "email": "customer@gmail.com",
1517 * "password": "supersecret"
1518 * })
1519 *
1520 * sdk.store.customer.create(
1521 * {
1522 * "email": "customer@gmail.com"
1523 * },
1524 * {},
1525 * {
1526 * Authorization: `Bearer ${token}`
1527 * }
1528 * )
1529 * .then(({ customer }) => {
1530 * console.log(customer)
1531 * })
1532 */
1533 create: async (
1534 body: HttpTypes.StoreCreateCustomer,
1535 query?: SelectParams,
1536 headers?: ClientHeaders
1537 ) => {
1538 return this.client.fetch<HttpTypes.StoreCustomerResponse>(
1539 `/store/customers`,
1540 {
1541 method: "POST",
1542 headers,
1543 body,
1544 query,
1545 }
1546 )
1547 },
1548 /**
1549 * This method updates the logged-in customer's details. The customer must be logged in
1550 * first with the {@link Auth.login} method.
1551 *
1552 * It sends a request to the
1553 * [Update Customer](https://docs.medusajs.com/api/store/customers/update-customer) API route.
1554 *
1555 * Related guide: [How to edit customer's profile in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/profile).
1556 *
1557 * @param body - The customer's details to update.
1558 * @param query - Configure the fields to retrieve in the customer.
1559 * @param headers - Headers to pass in the request.
1560 * @returns The customer's details.
1561 *
1562 * @example
1563 * // TODO must be authenticated as the customer to update their details
1564 * sdk.store.customer.update({
1565 * first_name: "John"
1566 * })
1567 * .then(({ customer }) => {
1568 * console.log(customer)
1569 * })
1570 */
1571 update: async (
1572 body: HttpTypes.StoreUpdateCustomer,
1573 query?: SelectParams,
1574 headers?: ClientHeaders
1575 ) => {
1576 return this.client.fetch<HttpTypes.StoreCustomerResponse>(
1577 `/store/customers/me`,
1578 {
1579 method: "POST",
1580 headers,
1581 body,
1582 query,
1583 }
1584 )
1585 },
1586 /**
1587 * This method retrieves the logged-in customer's details. The customer must be logged in
1588 * first with the {@link Auth.login} method.
1589 *
1590 * It sends a request to the [Get Logged-In Customer](https://docs.medusajs.com/api/store/customers/get-customer)
1591 * API route.
1592 *
1593 * @param query - Configure the fields to retrieve in the customer.
1594 * @param headers - Headers to pass in the request.
1595 * @returns The customer's details.
1596 *
1597 * @example
1598 * // TODO must be authenticated as the customer to retrieve their details
1599 * sdk.store.customer.retrieve()
1600 * .then(({ customer }) => {
1601 * console.log(customer)
1602 * })
1603 */
1604 retrieve: async (query?: SelectParams, headers?: ClientHeaders) => {
1605 return this.client.fetch<HttpTypes.StoreCustomerResponse>(
1606 `/store/customers/me`,
1607 {
1608 query,
1609 headers,
1610 }
1611 )
1612 },
1613 /**
1614 * This method creates an address for the logged-in customer. The customer must be logged in
1615 * first with the {@link Auth.login} method.
1616 *
1617 * It sends a request to the [Create Address](https://docs.medusajs.com/api/store/customers/create-address)
1618 * API route.
1619 *
1620 * Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses)
1621 *
1622 * @param body - The address's details.
1623 * @param query - Configure the fields to retrieve in the customer.
1624 * @param headers - Headers to pass in the request.
1625 * @returns The customer's details.
1626 *
1627 * @example
1628 * // TODO must be authenticated as the customer to create an address
1629 * sdk.store.customer.createAddress({
1630 * country_code: "us"
1631 * })
1632 * .then(({ customer }) => {
1633 * console.log(customer)
1634 * })
1635 */
1636 createAddress: async (
1637 body: HttpTypes.StoreCreateCustomerAddress,
1638 query?: SelectParams,
1639 headers?: ClientHeaders
1640 ) => {
1641 return this.client.fetch<HttpTypes.StoreCustomerResponse>(
1642 `/store/customers/me/addresses`,
1643 {
1644 method: "POST",
1645 headers,
1646 body,
1647 query,
1648 }
1649 )
1650 },
1651 /**
1652 * This method updates the address of the logged-in customer. The customer must be logged in
1653 * first with the {@link Auth.login} method.
1654 *
1655 * It sends a request to the [Update Address](https://docs.medusajs.com/api/store/customers/update-address)
1656 * API route.
1657 *
1658 * Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses)
1659 *
1660 * @param addressId - The ID of the address to update.
1661 * @param body - The details to update in the address.
1662 * @param query - Configure the fields to retrieve in the customer.
1663 * @param headers - Headers to pass in the request.
1664 * @returns The customer's details.
1665 *
1666 * @example
1667 * // TODO must be authenticated as the customer to update their address
1668 * sdk.store.customer.updateAddress(
1669 * "caddr_123",
1670 * {
1671 * country_code: "us"
1672 * }
1673 * )
1674 * .then(({ customer }) => {
1675 * console.log(customer)
1676 * })
1677 */
1678 updateAddress: async (
1679 addressId: string,
1680 body: HttpTypes.StoreUpdateCustomerAddress,
1681 query?: SelectParams,
1682 headers?: ClientHeaders
1683 ) => {
1684 return this.client.fetch<HttpTypes.StoreCustomerResponse>(
1685 `/store/customers/me/addresses/${addressId}`,
1686 {
1687 method: "POST",
1688 headers,
1689 body,
1690 query,
1691 }
1692 )
1693 },
1694 /**
1695 * This method retrieves the logged-in customer's address. The customer must be logged in
1696 * first with the {@link Auth.login} method.
1697 *
1698 * It sends a request to the [List Customer's Address](https://docs.medusajs.com/api/store/customers/list-customers-addresses)
1699 * API route.
1700 *
1701 * Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses)
1702 *
1703 * @param query - Configure the fields to retrieve in the addresses.
1704 * @param headers - Headers to pass in the request.
1705 * @returns The paginated list of addresses.
1706 *
1707 * @example
1708 * To retrieve the list of addresses:
1709 *
1710 * ```ts
1711 * // TODO must be authenticated as the customer to list their addresses
1712 * sdk.store.customer.listAddress()
1713 * .then(({ addresses, count, offset, limit }) => {
1714 * console.log(addresses)
1715 * })
1716 * ```
1717 *
1718 * To configure the pagination, pass the `limit` and `offset` query parameters.
1719 *
1720 * For example, to retrieve only 10 items and skip 10 items:
1721 *
1722 * ```ts
1723 * // TODO must be authenticated as the customer to list their addresses
1724 * sdk.store.customer.listAddress({
1725 * limit: 10,
1726 * offset: 10
1727 * })
1728 * .then(({ addresses, count, offset, limit }) => {
1729 * console.log(addresses)
1730 * })
1731 * ```
1732 *
1733 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
1734 * in each address:
1735 *
1736 * ```ts
1737 * // TODO must be authenticated as the customer to list their addresses
1738 * sdk.store.customer.listAddress({
1739 * fields: "id,country_code"
1740 * })
1741 * .then(({ addresses, count, offset, limit }) => {
1742 * console.log(addresses)
1743 * })
1744 * ```
1745 *
1746 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
1747 */
1748 listAddress: async (
1749 query?: FindParams & HttpTypes.StoreCustomerAddressFilters,
1750 headers?: ClientHeaders
1751 ) => {
1752 return this.client.fetch<HttpTypes.StoreCustomerAddressListResponse>(
1753 `/store/customers/me/addresses`,
1754 {
1755 query,
1756 headers,
1757 }
1758 )
1759 },
1760 /**
1761 * This method retrieves an address of the logged-in customer. The customer must be logged in
1762 * first with the {@link Auth.login} method.
1763 *
1764 * It sends a request to the [Get Address](https://docs.medusajs.com/api/store/customers/get-address)
1765 * API route.
1766 *
1767 * Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses)
1768 *
1769 * @param addressId - The address's ID.
1770 * @param query - Configure the fields to retrieve in the address.
1771 * @param headers - Headers to pass in the request.
1772 * @returns The address's details.
1773 *
1774 * @example
1775 * To retrieve an address by its ID:
1776 *
1777 * ```ts
1778 * // TODO must be authenticated as the customer to retrieve their address
1779 * sdk.store.customer.retrieveAddress(
1780 * "caddr_123"
1781 * )
1782 * .then(({ address }) => {
1783 * console.log(address)
1784 * })
1785 * ```
1786 *
1787 * To specify the fields and relations to retrieve:
1788 *
1789 * ```ts
1790 * // TODO must be authenticated as the customer to retrieve their address
1791 * sdk.store.customer.retrieveAddress(
1792 * "caddr_123",
1793 * {
1794 * fields: "id,country_code"
1795 * }
1796 * )
1797 * .then(({ address }) => {
1798 * console.log(address)
1799 * })
1800 * ```
1801 *
1802 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
1803 */
1804 retrieveAddress: async (
1805 addressId: string,
1806 query?: SelectParams,
1807 headers?: ClientHeaders
1808 ) => {
1809 return this.client.fetch<HttpTypes.StoreCustomerAddressResponse>(
1810 `/store/customers/me/addresses/${addressId}`,
1811 {
1812 query,
1813 headers,
1814 }
1815 )
1816 },
1817 /**
1818 * This method deletes an address of the logged-in customer. The customer must be logged in
1819 * first with the {@link Auth.login} method.
1820 *
1821 * It sends a request to the [Remove Address](https://docs.medusajs.com/api/store/customers/remove-address)
1822 * API route.
1823 *
1824 * Related guides: [How to manage customer's addresses in the storefront](https://docs.medusajs.com/resources/storefront-development/customers/addresses)
1825 *
1826 * @param addressId - The address's ID.
1827 * @param headers - Headers to pass in the request.
1828 * @returns The deletion's details.
1829 *
1830 * @example
1831 * // TODO must be authenticated as the customer to delete their address
1832 * sdk.store.customer.deleteAddress("caddr_123")
1833 * .then(({ deleted, parent: customer }) => {
1834 * console.log(customer)
1835 * })
1836 */
1837 deleteAddress: async (addressId: string, headers?: ClientHeaders) => {
1838 return this.client.fetch<HttpTypes.StoreCustomerAddressDeleteResponse>(
1839 `/store/customers/me/addresses/${addressId}`,
1840 {
1841 method: "DELETE",
1842 headers,
1843 }
1844 )
1845 },
1846 }
1847
1848 /**
1849 * @tags locale
1850 */
1851 public locale = {
1852 /**
1853 * This method retrieves the list of supported locales in the store. It sends a request to the
1854 * [List Locales](https://docs.medusajs.com/api/store/locales/list-locales) API route.
1855 *
1856 * @param headers - Headers to pass in the request.
1857 * @returns The list of supported locales.
1858 *
1859 * @example
1860 * sdk.store.locale.list()
1861 * .then(({ locales }) => {
1862 * console.log(locales)
1863 * })
1864 */
1865 list: async (
1866 headers?: ClientHeaders
1867 ) => {
1868 return this.client.fetch<HttpTypes.StoreLocaleListResponse>(
1869 `/store/locales`,
1870 {
1871 headers,
1872 }
1873 )
1874 },
1875 }
1876 }