@commercengine/storefront-sdk 0.3.0 → 0.3.1

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.
@@ -1,100 +1,53 @@
1
1
  import { StorefrontAPIClient } from "./client";
2
- import type { components } from "../types/storefront";
3
- import { ClientStorage } from "./auth";
2
+ import { AddToWishlistBody, AddToWishlistContent, AddToWishlistPathParams, ApiResult, ApplyCouponBody, ApplyCouponContent, ApplyCouponPathParams, CreateCartAddressBody, CreateCartAddressContent, CreateCartAddressPathParams, CreateCartBody, DeleteCartPathParams, DeleteCartResponse, DeleteFromWishlistBody, DeleteFromWishlistContent, DeleteFromWishlistPathParams, DeleteUserCartPathParams, DeleteUserCartResponse, GetCartContent, GetCartPathParams, GetUserCartContent, GetUserCartPathParams, GetWishlistContent, GetWishlistPathParams, RedeemCreditBalanceBody, RedeemCreditBalanceContent, RedeemCreditBalancePathParams, RedeemGiftCardBody, RedeemGiftCardContent, RedeemGiftCardPathParams, RedeemLoyaltyPointsBody, RedeemLoyaltyPointsContent, RedeemLoyaltyPointsPathParams, RemoveCouponContent, RemoveCouponPathParams, RemoveCreditBalanceContent, RemoveCreditBalancePathParams, RemoveGiftCardContent, RemoveGiftCardPathParams, RemoveLoyaltyPointsContent, RemoveLoyaltyPointsPathParams, UpdateCartBody, UpdateCartContent, UpdateCartPathParams, UpdateShippingMethodBody, UpdateShippingMethodContent, UpdateShippingMethodPathParams } from "../types/storefront-api-types";
3
+ import { CreateCartContent } from "../types/storefront-api-types";
4
4
  /**
5
5
  * Client for interacting with cart endpoints
6
6
  */
7
7
  export declare class CartClient extends StorefrontAPIClient {
8
- private clientStorage;
9
- /**
10
- * Set the client storage implementation to use for cart ID management
11
- *
12
- * @param storage - The client storage instance
13
- */
14
- setClientStorage(storage: ClientStorage): void;
15
- /**
16
- * Get the stored cart ID
17
- *
18
- * @returns Promise that resolves to the cart ID or null if not found
19
- */
20
- getCartId(): Promise<string | null>;
21
- /**
22
- * Set the cart ID in storage
23
- *
24
- * @param cartId - The cart ID to store
25
- */
26
- setCartId(cartId: string): Promise<void>;
27
- /**
28
- * Clear the stored cart ID
29
- */
30
- clearCartId(): Promise<void>;
31
8
  /**
32
9
  * Create a new cart
33
10
  *
34
11
  * @param payload - Object containing the items to add to the cart
35
12
  * @returns Promise with the created cart
36
13
  */
37
- createCart(payload: {
38
- items: components["schemas"]["UpdateCartItem"][];
39
- }): Promise<{
40
- cart: components["schemas"]["Cart"];
41
- }>;
14
+ createCart(payload: CreateCartBody): Promise<ApiResult<CreateCartContent>>;
42
15
  /**
43
16
  * Get cart details - either by ID or using the stored cart ID
44
17
  *
45
- * @param cartId - Optional cart ID (if not provided, uses stored cart ID)
18
+ * @param cartId - The ID of the cart
46
19
  * @returns Promise with cart details
47
- * @throws Error if no cartId is provided and none is stored
48
20
  */
49
- getCart(cartId?: string): Promise<{
50
- cart: components["schemas"]["Cart"];
51
- }>;
21
+ getCart(cartId: GetCartPathParams): Promise<ApiResult<GetCartContent>>;
52
22
  /**
53
23
  * Delete a cart - either by ID or using the stored cart ID
54
24
  *
55
- * @param cartId - Optional cart ID (if not provided, uses stored cart ID)
25
+ * @param cartId - The ID of the cart
56
26
  * @returns Promise that resolves when the cart is deleted
57
- * @throws Error if no cartId is provided and none is stored
58
27
  */
59
- deleteCart(cartId?: string): Promise<void>;
60
- /**
61
- * Add item to cart - either by specified ID or stored cart ID
62
- * Will create a new cart if no cart ID is available
63
- *
64
- * @param item - The item to add to the cart
65
- * @param cartId - Optional cart ID (if not provided, uses stored cart ID or creates a new cart)
66
- * @returns Promise with updated or created cart
67
- */
68
- addItem(item: components["schemas"]["UpdateCartItem"], cartId?: string): Promise<{
69
- cart: components["schemas"]["Cart"];
70
- }>;
28
+ deleteCart(cartId: DeleteCartPathParams): Promise<ApiResult<DeleteCartResponse>>;
71
29
  /**
72
30
  * Update cart items (add, update quantity, remove)
73
31
  *
74
- * @param cartId - The ID of the cart or undefined to use stored cart ID
75
- * @param item - The item data
32
+ * @param cartId - The cart id
33
+ * @param body - The body of the request
76
34
  * @returns Promise with updated cart
77
- * @throws Error if no cartId is provided and none is stored
78
35
  */
79
- updateCartItem(cartId: string | undefined, item: components["schemas"]["UpdateCartItem"]): Promise<{
80
- cart: components["schemas"]["Cart"];
81
- }>;
36
+ addDeleteCartItem(cartId: UpdateCartPathParams, body: UpdateCartBody): Promise<ApiResult<UpdateCartContent>>;
82
37
  /**
83
38
  * Get cart details by user ID
84
39
  *
85
40
  * @param userId - The ID of the user
86
41
  * @returns Promise with cart details
87
42
  */
88
- getUserCart(userId: string): Promise<{
89
- cart: components["schemas"]["Cart"];
90
- }>;
43
+ getUserCart(userId: GetUserCartPathParams): Promise<ApiResult<GetUserCartContent>>;
91
44
  /**
92
45
  * Delete a cart by user ID
93
46
  *
94
47
  * @param userId - The ID of the user
95
48
  * @returns Promise that resolves when the cart is deleted
96
49
  */
97
- deleteUserCart(userId: string): Promise<void>;
50
+ deleteUserCart(userId: DeleteUserCartPathParams): Promise<ApiResult<DeleteUserCartResponse>>;
98
51
  /**
99
52
  * Update cart addresses
100
53
  *
@@ -102,15 +55,7 @@ export declare class CartClient extends StorefrontAPIClient {
102
55
  * @param addressData - The address data
103
56
  * @returns Promise with updated cart
104
57
  */
105
- updateCartAddress(cartId: string, addressData: {
106
- billing_address_id: string;
107
- shipping_address_id: string;
108
- } | {
109
- billing_address: components["schemas"]["CustomerAddress"];
110
- shipping_address: components["schemas"]["CustomerAddress"];
111
- }): Promise<{
112
- cart: components["schemas"]["Cart"];
113
- }>;
58
+ updateCartAddress(cartId: CreateCartAddressPathParams, addressData: CreateCartAddressBody): Promise<ApiResult<CreateCartAddressContent>>;
114
59
  /**
115
60
  * Apply a coupon to the cart
116
61
  *
@@ -118,18 +63,14 @@ export declare class CartClient extends StorefrontAPIClient {
118
63
  * @param couponCode - The coupon code
119
64
  * @returns Promise with updated cart
120
65
  */
121
- applyCoupon(cartId: string, couponCode: string): Promise<{
122
- cart: components["schemas"]["Cart"];
123
- }>;
66
+ applyCoupon(cartId: ApplyCouponPathParams, couponCode: ApplyCouponBody): Promise<ApiResult<ApplyCouponContent>>;
124
67
  /**
125
68
  * Remove a coupon from the cart
126
69
  *
127
70
  * @param cartId - The ID of the cart
128
71
  * @returns Promise with updated cart
129
72
  */
130
- removeCoupon(cartId: string): Promise<{
131
- cart: components["schemas"]["Cart"];
132
- }>;
73
+ removeCoupon(cartId: RemoveCouponPathParams): Promise<ApiResult<RemoveCouponContent>>;
133
74
  /**
134
75
  * Redeem loyalty points
135
76
  *
@@ -137,16 +78,73 @@ export declare class CartClient extends StorefrontAPIClient {
137
78
  * @param points - The number of points to redeem
138
79
  * @returns Promise with updated cart
139
80
  */
140
- redeemLoyaltyPoints(cartId: string, points: number): Promise<{
141
- cart: components["schemas"]["Cart"];
142
- }>;
81
+ redeemLoyaltyPoints(cartId: RedeemLoyaltyPointsPathParams, points: RedeemLoyaltyPointsBody): Promise<ApiResult<RedeemLoyaltyPointsContent>>;
143
82
  /**
144
83
  * Remove loyalty points
145
84
  *
146
85
  * @param cartId - The ID of the cart
147
86
  * @returns Promise with updated cart
148
87
  */
149
- removeLoyaltyPoints(cartId: string): Promise<{
150
- cart: components["schemas"]["Cart"];
151
- }>;
88
+ removeLoyaltyPoints(cartId: RemoveLoyaltyPointsPathParams): Promise<ApiResult<RemoveLoyaltyPointsContent>>;
89
+ /**
90
+ * Update shipping method
91
+ *
92
+ * @param cartId - The ID of the cart
93
+ * @param body - The body of the request
94
+ * @returns Promise with updated cart
95
+ */
96
+ updateShippingMethod(cartId: UpdateShippingMethodPathParams, body: UpdateShippingMethodBody): Promise<ApiResult<UpdateShippingMethodContent>>;
97
+ /**
98
+ * Use credit balance
99
+ *
100
+ * @param cartId - The ID of the cart
101
+ * @param body - The body of the request
102
+ * @returns Promise with updated cart
103
+ */
104
+ redeemCreditBalance(cartId: RedeemCreditBalancePathParams, body: RedeemCreditBalanceBody): Promise<ApiResult<RedeemCreditBalanceContent>>;
105
+ /**
106
+ * Remove credit balance
107
+ *
108
+ * @param cartId - The ID of the cart
109
+ * @returns Promise with updated cart
110
+ */
111
+ removeCreditBalance(cartId: RemoveCreditBalancePathParams): Promise<ApiResult<RemoveCreditBalanceContent>>;
112
+ /**
113
+ * Redeem gift card
114
+ *
115
+ * @param cartId - The ID of the cart
116
+ * @param body - The body of the request
117
+ * @returns Promise with updated cart
118
+ */
119
+ redeemGiftCard(cartId: RedeemGiftCardPathParams, body: RedeemGiftCardBody): Promise<ApiResult<RedeemGiftCardContent>>;
120
+ /**
121
+ * Remove gift card
122
+ *
123
+ * @param cartId - The ID of the cart
124
+ * @returns Promise with updated cart
125
+ */
126
+ removeGiftCard(cartId: RemoveGiftCardPathParams): Promise<ApiResult<RemoveGiftCardContent>>;
127
+ /**
128
+ * Get wishlist items
129
+ *
130
+ * @param userId - The ID of the user
131
+ * @returns Promise with wishlist items
132
+ */
133
+ getWishlist(userId: GetWishlistPathParams): Promise<ApiResult<GetWishlistContent>>;
134
+ /**
135
+ * Add item to wishlist
136
+ *
137
+ * @param userId - The ID of the user
138
+ * @param itemId - The ID of the item
139
+ * @returns Promise with updated wishlist
140
+ */
141
+ addToWishlist(userId: AddToWishlistPathParams, itemId: AddToWishlistBody): Promise<ApiResult<AddToWishlistContent>>;
142
+ /**
143
+ * Remove item from wishlist
144
+ *
145
+ * @param userId - The ID of the user
146
+ * @param itemId - The ID of the item
147
+ * @returns Promise with updated wishlist
148
+ */
149
+ removeFromWishlist(userId: DeleteFromWishlistPathParams, body: DeleteFromWishlistBody): Promise<ApiResult<DeleteFromWishlistContent>>;
152
150
  }