@@ -20,8 +20,9 @@ import { getRegion } from "./regions"
20
20
* @param cartId - optional - The ID of the cart to retrieve.
21
21
* @returns The cart object if found, or null if not found.
22
22
*/
23
- export async function retrieveCart ( cartId ?: string ) {
23
+ export async function retrieveCart ( cartId ?: string , fields ?: string ) {
24
24
const id = cartId || ( await getCartId ( ) )
25
+ fields ??= "*items, *region, *items.product, *items.variant, *items.thumbnail, *items.metadata, +items.total, *promotions, +shipping_methods.name"
25
26
26
27
if ( ! id ) {
27
28
return null
@@ -39,14 +40,13 @@ export async function retrieveCart(cartId?: string) {
39
40
. fetch < HttpTypes . StoreCartResponse > ( `/store/carts/${ id } ` , {
40
41
method : "GET" ,
41
42
query : {
42
- fields :
43
- "*items, *region, *items.product, *items.variant, *items.thumbnail, *items.metadata, +items.total, *promotions, +shipping_methods.name" ,
43
+ fields
44
44
} ,
45
45
headers,
46
46
next,
47
47
cache : "force-cache" ,
48
48
} )
49
- . then ( ( { cart } ) => cart )
49
+ . then ( ( { cart } : { cart : HttpTypes . StoreCart } ) => cart )
50
50
. catch ( ( ) => null )
51
51
}
52
52
@@ -57,7 +57,7 @@ export async function getOrSetCart(countryCode: string) {
57
57
throw new Error ( `Region not found for country code: ${ countryCode } ` )
58
58
}
59
59
60
- let cart = await retrieveCart ( )
60
+ let cart = await retrieveCart ( undefined , 'id,region_id' )
61
61
62
62
const headers = {
63
63
...( await getAuthHeaders ( ) ) ,
@@ -99,7 +99,7 @@ export async function updateCart(data: HttpTypes.StoreUpdateCart) {
99
99
100
100
return sdk . store . cart
101
101
. update ( cartId , data , { } , headers )
102
- . then ( async ( { cart } ) => {
102
+ . then ( async ( { cart } : { cart : HttpTypes . StoreCart } ) => {
103
103
const cartCacheTag = await getCacheTag ( "carts" )
104
104
revalidateTag ( cartCacheTag )
105
105
0 commit comments