@commercengine/storefront-sdk 0.3.11 → 0.4.0

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.
package/dist/lib/auth.js DELETED
@@ -1,324 +0,0 @@
1
- import { StorefrontAPIClient } from "./client";
2
- /**
3
- * Client for interacting with authentication endpoints
4
- */
5
- export class AuthClient extends StorefrontAPIClient {
6
- /**
7
- * Get anonymous token for guest users
8
- */
9
- async getAnonymousToken() {
10
- return this.executeRequest(() => this.client.POST("/auth/anonymous"));
11
- }
12
- /**
13
- * Login with phone number
14
- *
15
- * @param phoneNumber - Phone number (without country code)
16
- * @param countryCode - Country code (defaults to +91)
17
- * @param registerIfNotExists - Whether to register if user doesn't exist
18
- * @returns Promise with OTP token and action
19
- */
20
- async loginWithPhone(body) {
21
- return this.executeRequest(() => this.client.POST("/auth/login/phone", {
22
- body: body,
23
- }));
24
- }
25
- /**
26
- * Login with WhatsApp
27
- *
28
- * @param phoneNumber - Phone number (without country code)
29
- * @param countryCode - Country code (defaults to +91)
30
- * @param registerIfNotExists - Whether to register if user doesn't exist
31
- * @returns Promise with OTP token and action
32
- */
33
- async loginWithWhatsApp(body) {
34
- return this.executeRequest(() => this.client.POST("/auth/login/whatsapp", {
35
- body: body,
36
- }));
37
- }
38
- /**
39
- * Login with email
40
- *
41
- * @param email - Email address
42
- * @param registerIfNotExists - Whether to register if user doesn't exist
43
- * @returns Promise with OTP token and action
44
- */
45
- async loginWithEmail(body) {
46
- return this.executeRequest(() => this.client.POST("/auth/login/email", {
47
- body: body,
48
- }));
49
- }
50
- /**
51
- * Login with password
52
- *
53
- * @param credentials - Login credentials
54
- * @returns Promise with user info and tokens
55
- */
56
- async loginWithPassword(body) {
57
- return this.executeRequest(() => this.client.POST("/auth/login/password", {
58
- body: body,
59
- }));
60
- }
61
- /**
62
- * Forgot password
63
- *
64
- * @param email - Email address
65
- * @returns Promise with user info and tokens
66
- */
67
- async forgotPassword(body) {
68
- return this.executeRequest(() => this.client.POST("/auth/forgot-password", {
69
- body: body,
70
- }));
71
- }
72
- /**
73
- * Reset password
74
- *
75
- * @param email - Email address
76
- * @returns Promise with user info and tokens
77
- */
78
- async resetPassword(body) {
79
- return this.executeRequest(() => this.client.POST("/auth/reset-password", {
80
- body: body,
81
- }));
82
- }
83
- /**
84
- * Change password
85
- *
86
- * @param oldPassword - Old password
87
- * @param newPassword - New password
88
- * @param newPasswordConfirmation - New password confirmation
89
- * @returns Promise with new access token and refresh token
90
- */
91
- async changePassword(body) {
92
- return this.executeRequest(() => this.client.POST("/auth/change-password", {
93
- body: body,
94
- }));
95
- }
96
- /**
97
- * Verify OTP
98
- *
99
- * @param otp - One-time password
100
- * @param otpToken - OTP token from login request
101
- * @param otpAction - OTP action from login request
102
- * @returns Promise with user info and tokens
103
- */
104
- async verifyOtp(body) {
105
- return this.executeRequest(() => this.client.POST("/auth/verify-otp", {
106
- body: body,
107
- }));
108
- }
109
- /**
110
- * Register with phone
111
- *
112
- * @param options - Registration details
113
- * @returns Promise with user info and tokens
114
- */
115
- async registerWithPhone(body) {
116
- return this.executeRequest(() => this.client.POST("/auth/register/phone", {
117
- body: body,
118
- }));
119
- }
120
- /**
121
- * Register with email
122
- *
123
- * @param options - Registration details
124
- * @returns Promise with user info and tokens
125
- */
126
- async registerWithEmail(body) {
127
- return this.executeRequest(() => this.client.POST("/auth/register/email", {
128
- body: body,
129
- }));
130
- }
131
- /**
132
- * Refresh the access token using a refresh token
133
- * @param refreshToken - The refresh token to use for refreshing the access token
134
- * @returns Promise with the new access token and refresh token
135
- */
136
- async refreshToken(body) {
137
- return this.executeRequest(() => this.client.POST("/auth/refresh-token", {
138
- body: body,
139
- }));
140
- }
141
- /**
142
- * Logout
143
- *
144
- * @returns Promise that resolves when logout is complete
145
- */
146
- async logout() {
147
- return this.executeRequest(() => this.client.POST("/auth/logout"));
148
- }
149
- /**
150
- * Get user details
151
- *
152
- * @param userId - User ID
153
- * @returns Promise with user details
154
- */
155
- async getUserDetails(pathParams) {
156
- return this.executeRequest(() => this.client.GET("/auth/user/{id}", {
157
- params: {
158
- path: pathParams,
159
- },
160
- }));
161
- }
162
- /**
163
- * Update user details
164
- *
165
- * @param userId - User ID
166
- * @returns Promise with user details
167
- */
168
- async updateUserDetails(pathParams, body) {
169
- return this.executeRequest(() => this.client.PUT("/auth/user/{id}", {
170
- params: {
171
- path: pathParams,
172
- },
173
- body: body,
174
- }));
175
- }
176
- /**
177
- * Add profile image
178
- *
179
- * @param userId - User ID
180
- * @returns Promise with user details
181
- */
182
- async addProfileImage(pathParams, formData) {
183
- return this.executeRequest(() => this.client.POST("/auth/user/{id}/profile-image", {
184
- params: {
185
- path: pathParams,
186
- },
187
- body: formData,
188
- bodySerializer: (body) => {
189
- const fd = new FormData();
190
- for (const [key, value] of Object.entries(body)) {
191
- if (value !== undefined && value !== null) {
192
- fd.append(key, value);
193
- }
194
- }
195
- return fd;
196
- }
197
- }));
198
- }
199
- /**
200
- * Update profile image
201
- *
202
- * @param userId - User ID
203
- * @returns Promise with user details
204
- */
205
- async updateProfileImage(pathParams, formData) {
206
- return this.executeRequest(() => this.client.PUT("/auth/user/{id}/profile-image", {
207
- params: {
208
- path: pathParams,
209
- },
210
- body: formData,
211
- bodySerializer: (body) => {
212
- const fd = new FormData();
213
- for (const [key, value] of Object.entries(body)) {
214
- if (value !== undefined && value !== null) {
215
- fd.append(key, value);
216
- }
217
- }
218
- return fd;
219
- }
220
- }));
221
- }
222
- /**
223
- * Delete profile image
224
- *
225
- * @param userId - User ID
226
- * @returns Promise with user details
227
- */
228
- async deleteProfileImage(pathParams) {
229
- return this.executeRequest(() => this.client.DELETE("/auth/user/{id}/profile-image", {
230
- params: {
231
- path: pathParams,
232
- },
233
- }));
234
- }
235
- /**
236
- * Get profile image
237
- *
238
- * @param userId - User ID
239
- * @returns Promise with user details
240
- */
241
- async getProfileImage(pathParams) {
242
- return this.executeRequest(() => this.client.GET("/auth/user/{id}/profile-image", {
243
- params: {
244
- path: pathParams,
245
- },
246
- }));
247
- }
248
- /**
249
- * Deactivate user account
250
- *
251
- * @param userId - User ID
252
- * @returns Promise with user details
253
- */
254
- async deactivateUserAccount(pathParams) {
255
- return this.executeRequest(() => this.client.PUT("/auth/user/{id}/deactivate", {
256
- params: {
257
- path: pathParams,
258
- },
259
- }));
260
- }
261
- /**
262
- * Get user notification preferences
263
- *
264
- * @param userId - User ID
265
- * @returns Promise with user details
266
- */
267
- async getUserNotificationPreferences(pathParams) {
268
- return this.executeRequest(() => this.client.GET("/auth/user/{id}/notification-preferences", {
269
- params: {
270
- path: pathParams,
271
- },
272
- }));
273
- }
274
- /**
275
- * Update user notification preferences
276
- *
277
- * @param userId - User ID
278
- * @returns Promise with user details
279
- */
280
- async updateUserNotificationPreferences(pathParams, body) {
281
- return this.executeRequest(() => this.client.PUT("/auth/user/{id}/notification-preferences", {
282
- params: {
283
- path: pathParams,
284
- },
285
- body: body,
286
- }));
287
- }
288
- /**
289
- * Create user notification preference
290
- *
291
- * @param userId - User ID
292
- * @returns Promise with user details
293
- */
294
- async createUserNotificationPreference(pathParams, body) {
295
- return this.executeRequest(() => this.client.POST("/auth/user/{id}/notification-preferences", {
296
- params: {
297
- path: pathParams,
298
- },
299
- body: body,
300
- }));
301
- }
302
- /**
303
- * Generate OTP
304
- *
305
- * @param body - OTP generation body
306
- * @returns Promise with OTP generation response
307
- */
308
- async generateOtp(body) {
309
- return this.executeRequest(() => this.client.POST("/auth/generate-otp", {
310
- body: body,
311
- }));
312
- }
313
- /**
314
- * Check whether email or phone is already verified
315
- *
316
- * @param body - OTP generation body
317
- * @returns Promise with OTP generation response
318
- */
319
- async checkEmailOrPhoneIsVerified(body) {
320
- return this.executeRequest(() => this.client.POST("/auth/verified-email-phone", {
321
- body: body,
322
- }));
323
- }
324
- }
@@ -1,163 +0,0 @@
1
- import { StorefrontAPIClient } from "./client";
2
- import type { AddToWishlistBody, AddToWishlistContent, AddToWishlistPathParams, ApiResult, ApplyCouponBody, ApplyCouponContent, ApplyCouponPathParams, CreateCartContent, 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, ListCouponsContent, ListPromotionsContent, ListCouponsHeaderParams, ListPromotionsHeaderParams } from "../types/storefront-api-types";
3
- /**
4
- * Client for interacting with cart endpoints
5
- */
6
- export declare class CartClient extends StorefrontAPIClient {
7
- /**
8
- * Create a new cart
9
- *
10
- * @param payload - Object containing the items to add to the cart
11
- * @returns Promise with the created cart
12
- */
13
- createCart(payload: CreateCartBody): Promise<ApiResult<CreateCartContent>>;
14
- /**
15
- * Get cart details - either by ID or using the stored cart ID
16
- *
17
- * @param cartId - The ID of the cart
18
- * @returns Promise with cart details
19
- */
20
- getCart(cartId: GetCartPathParams): Promise<ApiResult<GetCartContent>>;
21
- /**
22
- * Delete a cart - either by ID or using the stored cart ID
23
- *
24
- * @param cartId - The ID of the cart
25
- * @returns Promise that resolves when the cart is deleted
26
- */
27
- deleteCart(cartId: DeleteCartPathParams): Promise<ApiResult<DeleteCartResponse>>;
28
- /**
29
- * Update cart items (add, update quantity, remove)
30
- *
31
- * @param cartId - The cart id
32
- * @param body - The body of the request
33
- * @returns Promise with updated cart
34
- */
35
- addDeleteCartItem(cartId: UpdateCartPathParams, body: UpdateCartBody): Promise<ApiResult<UpdateCartContent>>;
36
- /**
37
- * Get cart details by user ID
38
- *
39
- * @param userId - The ID of the user
40
- * @returns Promise with cart details
41
- */
42
- getUserCart(userId: GetUserCartPathParams): Promise<ApiResult<GetUserCartContent>>;
43
- /**
44
- * Delete a cart by user ID
45
- *
46
- * @param userId - The ID of the user
47
- * @returns Promise that resolves when the cart is deleted
48
- */
49
- deleteUserCart(userId: DeleteUserCartPathParams): Promise<ApiResult<DeleteUserCartResponse>>;
50
- /**
51
- * Update cart addresses
52
- *
53
- * @param cartId - The ID of the cart
54
- * @param addressData - The address data
55
- * @returns Promise with updated cart
56
- */
57
- updateCartAddress(cartId: CreateCartAddressPathParams, addressData: CreateCartAddressBody): Promise<ApiResult<CreateCartAddressContent>>;
58
- /**
59
- * Apply a coupon to the cart
60
- *
61
- * @param cartId - The ID of the cart
62
- * @param couponCode - The coupon code
63
- * @returns Promise with updated cart
64
- */
65
- applyCoupon(cartId: ApplyCouponPathParams, couponCode: ApplyCouponBody): Promise<ApiResult<ApplyCouponContent>>;
66
- /**
67
- * Remove a coupon from the cart
68
- *
69
- * @param cartId - The ID of the cart
70
- * @returns Promise with updated cart
71
- */
72
- removeCoupon(cartId: RemoveCouponPathParams): Promise<ApiResult<RemoveCouponContent>>;
73
- /**
74
- * Redeem loyalty points
75
- *
76
- * @param cartId - The ID of the cart
77
- * @param points - The number of points to redeem
78
- * @returns Promise with updated cart
79
- */
80
- redeemLoyaltyPoints(cartId: RedeemLoyaltyPointsPathParams, points: RedeemLoyaltyPointsBody): Promise<ApiResult<RedeemLoyaltyPointsContent>>;
81
- /**
82
- * Remove loyalty points
83
- *
84
- * @param cartId - The ID of the cart
85
- * @returns Promise with updated cart
86
- */
87
- removeLoyaltyPoints(cartId: RemoveLoyaltyPointsPathParams): Promise<ApiResult<RemoveLoyaltyPointsContent>>;
88
- /**
89
- * Update shipping method
90
- *
91
- * @param cartId - The ID of the cart
92
- * @param body - The body of the request
93
- * @returns Promise with updated cart
94
- */
95
- updateShippingMethod(cartId: UpdateShippingMethodPathParams, body: UpdateShippingMethodBody): Promise<ApiResult<UpdateShippingMethodContent>>;
96
- /**
97
- * Use credit balance
98
- *
99
- * @param cartId - The ID of the cart
100
- * @param body - The body of the request
101
- * @returns Promise with updated cart
102
- */
103
- redeemCreditBalance(cartId: RedeemCreditBalancePathParams, body: RedeemCreditBalanceBody): Promise<ApiResult<RedeemCreditBalanceContent>>;
104
- /**
105
- * Remove credit balance
106
- *
107
- * @param cartId - The ID of the cart
108
- * @returns Promise with updated cart
109
- */
110
- removeCreditBalance(cartId: RemoveCreditBalancePathParams): Promise<ApiResult<RemoveCreditBalanceContent>>;
111
- /**
112
- * Redeem gift card
113
- *
114
- * @param cartId - The ID of the cart
115
- * @param body - The body of the request
116
- * @returns Promise with updated cart
117
- */
118
- redeemGiftCard(cartId: RedeemGiftCardPathParams, body: RedeemGiftCardBody): Promise<ApiResult<RedeemGiftCardContent>>;
119
- /**
120
- * Remove gift card
121
- *
122
- * @param cartId - The ID of the cart
123
- * @returns Promise with updated cart
124
- */
125
- removeGiftCard(cartId: RemoveGiftCardPathParams): Promise<ApiResult<RemoveGiftCardContent>>;
126
- /**
127
- * Get wishlist items
128
- *
129
- * @param userId - The ID of the user
130
- * @returns Promise with wishlist items
131
- */
132
- getWishlist(userId: GetWishlistPathParams): Promise<ApiResult<GetWishlistContent>>;
133
- /**
134
- * Add item to wishlist
135
- *
136
- * @param userId - The ID of the user
137
- * @param itemId - The ID of the item
138
- * @returns Promise with updated wishlist
139
- */
140
- addToWishlist(userId: AddToWishlistPathParams, itemId: AddToWishlistBody): Promise<ApiResult<AddToWishlistContent>>;
141
- /**
142
- * Remove item from wishlist
143
- *
144
- * @param userId - The ID of the user
145
- * @param itemId - The ID of the item
146
- * @returns Promise with updated wishlist
147
- */
148
- removeFromWishlist(userId: DeleteFromWishlistPathParams, body: DeleteFromWishlistBody): Promise<ApiResult<DeleteFromWishlistContent>>;
149
- /**
150
- * Get all available coupons
151
- *
152
- * @param headers - Optional header parameters (customer_group_id, etc.)
153
- * @returns Promise with all available coupons
154
- */
155
- getAvailableCoupons(headers?: ListCouponsHeaderParams): Promise<ApiResult<ListCouponsContent>>;
156
- /**
157
- * Get all available promotions
158
- *
159
- * @param headers - Optional header parameters (customer_group_id, etc.)
160
- * @returns Promise with all available promotions
161
- */
162
- getAvailablePromotions(headers?: ListPromotionsHeaderParams): Promise<ApiResult<ListPromotionsContent>>;
163
- }