@commercengine/storefront-sdk 0.2.1 → 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.
- package/dist/index.d.ts +76 -26
- package/dist/index.js +150 -61
- package/dist/lib/auth.d.ts +106 -221
- package/dist/lib/auth.js +223 -680
- package/dist/lib/cart.d.ts +78 -80
- package/dist/lib/cart.js +183 -214
- package/dist/lib/catalog.d.ts +36 -69
- package/dist/lib/catalog.js +109 -118
- package/dist/lib/client.d.ts +38 -43
- package/dist/lib/client.js +88 -145
- package/dist/lib/customer.d.ts +91 -0
- package/dist/lib/customer.js +156 -0
- package/dist/lib/helper.d.ts +28 -0
- package/dist/lib/helper.js +43 -0
- package/dist/lib/jwt-utils.d.ts +75 -0
- package/dist/lib/jwt-utils.js +84 -0
- package/dist/lib/middleware.d.ts +83 -0
- package/dist/lib/middleware.js +257 -0
- package/dist/lib/order.d.ts +73 -0
- package/dist/lib/order.js +128 -0
- package/dist/lib/shipping.d.ts +15 -0
- package/dist/lib/shipping.js +20 -0
- package/dist/types/storefront-api-types.d.ts +359 -0
- package/dist/types/storefront-api-types.js +3 -0
- package/dist/types/storefront.d.ts +7976 -7369
- package/package.json +21 -12
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { StorefrontAPIClient, StorefrontAPIConfig } from "./client";
|
|
2
|
-
import
|
|
2
|
+
import { AddProfileImageContent, AddProfileImageFormData, AddProfileImagePathParams, ApiResult, ChangePasswordBody, ChangePasswordContent, CheckVerificationStatusBody, CheckVerificationStatusContent, CreateNotificationPreferencesBody, CreateNotificationPreferencesContent, CreateNotificationPreferencesPathParams, DeactivateUserPathParams, DeactivateUserResponse, ForgotPasswordBody, ForgotPasswordContent, GenerateOtpBody, GenerateOtpContent, GetAnonymousTokenContent, GetNotificationPreferencesContent, GetNotificationPreferencesPathParams, GetProfileImageContent, GetProfileImagePathParams, GetUserDetailContent, GetUserDetailPathParams, LoginWithEmailBody, LoginWithEmailContent, LoginWithPasswordBody, LoginWithPasswordContent, LoginWithPhoneBody, LoginWithPhoneContent, LoginWithWhatsappBody, LoginWithWhatsappContent, LogoutContent, RefreshTokenBody, RefreshTokenContent, RegisterWithEmailBody, RegisterWithEmailContent, RegisterWithPhoneBody, RegisterWithPhoneContent, RemoveProfileImagePathParams, RemoveProfileImageResponse, ResetPasswordBody, ResetPasswordContent, UpdateNotificationPreferencesBody, UpdateNotificationPreferencesContent, UpdateNotificationPreferencesPathParams, UpdateProfileImageContent, UpdateProfileImageFormData, UpdateProfileImagePathParams, UpdateUserBody, UpdateUserContent, UpdateUserPathParams, VerifyOtpBody, VerifyOtpContent } from "../types/storefront-api-types";
|
|
3
3
|
/**
|
|
4
4
|
* Client for interacting with authentication endpoints
|
|
5
5
|
*/
|
|
6
6
|
export declare class AuthClient extends StorefrontAPIClient {
|
|
7
|
-
|
|
8
|
-
private autoRefreshTimer;
|
|
9
|
-
constructor(config: StorefrontAPIConfig, tokenStorage?: TokenStorage);
|
|
10
|
-
setToken(token: string): void;
|
|
11
|
-
protected setRefreshToken(token: string): void;
|
|
12
|
-
clearToken(): void;
|
|
13
|
-
private setupAutoRefresh;
|
|
14
|
-
private clearAutoRefresh;
|
|
15
|
-
private handleTokenRefresh;
|
|
16
|
-
private getTokenExpiry;
|
|
7
|
+
constructor(config: StorefrontAPIConfig);
|
|
17
8
|
/**
|
|
18
|
-
* Get
|
|
19
|
-
*
|
|
20
|
-
* @param options - Options for anonymous authentication
|
|
21
|
-
* @returns Promise with user info and tokens
|
|
9
|
+
* Get anonymous token for guest users
|
|
22
10
|
*/
|
|
23
|
-
getAnonymousToken(
|
|
24
|
-
apiKey?: string;
|
|
25
|
-
}): Promise<{
|
|
26
|
-
user: components["schemas"]["AnonymousUser"];
|
|
27
|
-
access_token: string;
|
|
28
|
-
refresh_token: string;
|
|
29
|
-
}>;
|
|
11
|
+
getAnonymousToken(): Promise<ApiResult<GetAnonymousTokenContent>>;
|
|
30
12
|
/**
|
|
31
13
|
* Login with phone number
|
|
32
14
|
*
|
|
@@ -35,10 +17,16 @@ export declare class AuthClient extends StorefrontAPIClient {
|
|
|
35
17
|
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
36
18
|
* @returns Promise with OTP token and action
|
|
37
19
|
*/
|
|
38
|
-
loginWithPhone(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
loginWithPhone(body: LoginWithPhoneBody): Promise<ApiResult<LoginWithPhoneContent>>;
|
|
21
|
+
/**
|
|
22
|
+
* Login with WhatsApp
|
|
23
|
+
*
|
|
24
|
+
* @param phoneNumber - Phone number (without country code)
|
|
25
|
+
* @param countryCode - Country code (defaults to +91)
|
|
26
|
+
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
27
|
+
* @returns Promise with OTP token and action
|
|
28
|
+
*/
|
|
29
|
+
loginWithWhatsApp(body: LoginWithWhatsappBody): Promise<ApiResult<LoginWithWhatsappContent>>;
|
|
42
30
|
/**
|
|
43
31
|
* Login with email
|
|
44
32
|
*
|
|
@@ -46,26 +34,37 @@ export declare class AuthClient extends StorefrontAPIClient {
|
|
|
46
34
|
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
47
35
|
* @returns Promise with OTP token and action
|
|
48
36
|
*/
|
|
49
|
-
loginWithEmail(
|
|
50
|
-
otp_token: string;
|
|
51
|
-
otp_action: string;
|
|
52
|
-
}>;
|
|
37
|
+
loginWithEmail(body: LoginWithEmailBody): Promise<ApiResult<LoginWithEmailContent>>;
|
|
53
38
|
/**
|
|
54
39
|
* Login with password
|
|
55
40
|
*
|
|
56
|
-
* @param
|
|
41
|
+
* @param credentials - Login credentials
|
|
42
|
+
* @returns Promise with user info and tokens
|
|
43
|
+
*/
|
|
44
|
+
loginWithPassword(body: LoginWithPasswordBody): Promise<ApiResult<LoginWithPasswordContent>>;
|
|
45
|
+
/**
|
|
46
|
+
* Forgot password
|
|
47
|
+
*
|
|
48
|
+
* @param email - Email address
|
|
57
49
|
* @returns Promise with user info and tokens
|
|
58
50
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
forgotPassword(body: ForgotPasswordBody): Promise<ApiResult<ForgotPasswordContent>>;
|
|
52
|
+
/**
|
|
53
|
+
* Reset password
|
|
54
|
+
*
|
|
55
|
+
* @param email - Email address
|
|
56
|
+
* @returns Promise with user info and tokens
|
|
57
|
+
*/
|
|
58
|
+
resetPassword(body: ResetPasswordBody): Promise<ApiResult<ResetPasswordContent>>;
|
|
59
|
+
/**
|
|
60
|
+
* Change password
|
|
61
|
+
*
|
|
62
|
+
* @param oldPassword - Old password
|
|
63
|
+
* @param newPassword - New password
|
|
64
|
+
* @param newPasswordConfirmation - New password confirmation
|
|
65
|
+
* @returns Promise with new access token and refresh token
|
|
66
|
+
*/
|
|
67
|
+
changePassword(body: ChangePasswordBody): Promise<ApiResult<ChangePasswordContent>>;
|
|
69
68
|
/**
|
|
70
69
|
* Verify OTP
|
|
71
70
|
*
|
|
@@ -74,229 +73,115 @@ export declare class AuthClient extends StorefrontAPIClient {
|
|
|
74
73
|
* @param otpAction - OTP action from login request
|
|
75
74
|
* @returns Promise with user info and tokens
|
|
76
75
|
*/
|
|
77
|
-
verifyOtp(
|
|
78
|
-
user?: components["schemas"]["User"];
|
|
79
|
-
access_token?: string;
|
|
80
|
-
refresh_token?: string;
|
|
81
|
-
}>;
|
|
76
|
+
verifyOtp(body: VerifyOtpBody): Promise<ApiResult<VerifyOtpContent>>;
|
|
82
77
|
/**
|
|
83
78
|
* Register with phone
|
|
84
79
|
*
|
|
85
80
|
* @param options - Registration details
|
|
86
81
|
* @returns Promise with user info and tokens
|
|
87
82
|
*/
|
|
88
|
-
registerWithPhone(
|
|
89
|
-
country_code?: string;
|
|
90
|
-
phone: string;
|
|
91
|
-
first_name: string;
|
|
92
|
-
last_name?: string;
|
|
93
|
-
email: string;
|
|
94
|
-
otp_token?: string;
|
|
95
|
-
}): Promise<{
|
|
96
|
-
user: components["schemas"]["User"];
|
|
97
|
-
access_token: string;
|
|
98
|
-
refresh_token: string;
|
|
99
|
-
}>;
|
|
83
|
+
registerWithPhone(body: RegisterWithPhoneBody): Promise<ApiResult<RegisterWithPhoneContent>>;
|
|
100
84
|
/**
|
|
101
85
|
* Register with email
|
|
102
86
|
*
|
|
103
87
|
* @param options - Registration details
|
|
104
88
|
* @returns Promise with user info and tokens
|
|
105
89
|
*/
|
|
106
|
-
registerWithEmail(
|
|
107
|
-
email: string;
|
|
108
|
-
first_name: string;
|
|
109
|
-
last_name?: string;
|
|
110
|
-
phone: string;
|
|
111
|
-
otp_token?: string;
|
|
112
|
-
}): Promise<{
|
|
113
|
-
user: components["schemas"]["User"];
|
|
114
|
-
access_token: string;
|
|
115
|
-
refresh_token: string;
|
|
116
|
-
}>;
|
|
90
|
+
registerWithEmail(body: RegisterWithEmailBody): Promise<ApiResult<RegisterWithEmailContent>>;
|
|
117
91
|
/**
|
|
118
|
-
* Refresh token
|
|
119
|
-
*
|
|
120
|
-
* @
|
|
121
|
-
* @returns Promise with new tokens
|
|
92
|
+
* Refresh the access token using a refresh token
|
|
93
|
+
* @param refreshToken - The refresh token to use for refreshing the access token
|
|
94
|
+
* @returns Promise with the new access token and refresh token
|
|
122
95
|
*/
|
|
123
|
-
refreshToken(
|
|
124
|
-
access_token: string;
|
|
125
|
-
refresh_token: string;
|
|
126
|
-
}>;
|
|
96
|
+
refreshToken(body: RefreshTokenBody): Promise<ApiResult<RefreshTokenContent>>;
|
|
127
97
|
/**
|
|
128
98
|
* Logout
|
|
129
99
|
*
|
|
130
100
|
* @returns Promise that resolves when logout is complete
|
|
131
101
|
*/
|
|
132
|
-
logout(): Promise<
|
|
102
|
+
logout(): Promise<ApiResult<LogoutContent>>;
|
|
133
103
|
/**
|
|
134
|
-
*
|
|
135
|
-
* to implement token refresh for 401 errors
|
|
104
|
+
* Get user details
|
|
136
105
|
*
|
|
137
|
-
* @
|
|
106
|
+
* @param userId - User ID
|
|
107
|
+
* @returns Promise with user details
|
|
138
108
|
*/
|
|
139
|
-
|
|
109
|
+
getUserDetails(pathParams: GetUserDetailPathParams): Promise<ApiResult<GetUserDetailContent>>;
|
|
140
110
|
/**
|
|
141
|
-
*
|
|
142
|
-
* This wraps any API call in logic that will catch authentication errors,
|
|
143
|
-
* attempt to refresh the token, and retry the request once
|
|
111
|
+
* Update user details
|
|
144
112
|
*
|
|
145
|
-
* @param
|
|
146
|
-
* @returns Promise with
|
|
147
|
-
*/
|
|
148
|
-
executeWithTokenRefresh<T>(requestFn: () => Promise<T>): Promise<T>;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Interface for client storage implementations (tokens and cart ID)
|
|
152
|
-
*/
|
|
153
|
-
export interface ClientStorage {
|
|
154
|
-
getAccessToken(): string | null;
|
|
155
|
-
setAccessToken(token: string): void;
|
|
156
|
-
getRefreshToken(): string | null;
|
|
157
|
-
setRefreshToken(token: string): void;
|
|
158
|
-
clearTokens(): void;
|
|
159
|
-
getCartId(): string | null;
|
|
160
|
-
setCartId(cartId: string): void;
|
|
161
|
-
clearCartId(): void;
|
|
162
|
-
}
|
|
163
|
-
export type TokenStorage = ClientStorage;
|
|
164
|
-
/**
|
|
165
|
-
* Default in-memory implementation of client storage
|
|
166
|
-
*/
|
|
167
|
-
export declare class MemoryTokenStorage implements ClientStorage {
|
|
168
|
-
private accessToken;
|
|
169
|
-
private refreshToken;
|
|
170
|
-
private cartId;
|
|
171
|
-
getAccessToken(): string | null;
|
|
172
|
-
setAccessToken(token: string): void;
|
|
173
|
-
getRefreshToken(): string | null;
|
|
174
|
-
setRefreshToken(token: string): void;
|
|
175
|
-
clearTokens(): void;
|
|
176
|
-
getCartId(): string | null;
|
|
177
|
-
setCartId(cartId: string): void;
|
|
178
|
-
clearCartId(): void;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Browser storage implementation using localStorage
|
|
182
|
-
*/
|
|
183
|
-
export declare class BrowserTokenStorage implements ClientStorage {
|
|
184
|
-
private accessTokenKey;
|
|
185
|
-
private refreshTokenKey;
|
|
186
|
-
private cartIdKey;
|
|
187
|
-
constructor(prefix?: string);
|
|
188
|
-
getAccessToken(): string | null;
|
|
189
|
-
setAccessToken(token: string): void;
|
|
190
|
-
getRefreshToken(): string | null;
|
|
191
|
-
setRefreshToken(token: string): void;
|
|
192
|
-
clearTokens(): void;
|
|
193
|
-
getCartId(): string | null;
|
|
194
|
-
setCartId(cartId: string): void;
|
|
195
|
-
clearCartId(): void;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Cookie-based token storage for browser or server environments
|
|
199
|
-
*/
|
|
200
|
-
export declare class CookieTokenStorage implements ClientStorage {
|
|
201
|
-
private accessTokenKey;
|
|
202
|
-
private refreshTokenKey;
|
|
203
|
-
private cartIdKey;
|
|
204
|
-
private cookieOptions;
|
|
205
|
-
constructor(prefix?: string, cookieOptions?: {
|
|
206
|
-
path: string;
|
|
207
|
-
secure: boolean;
|
|
208
|
-
sameSite: string;
|
|
209
|
-
httpOnly: boolean;
|
|
210
|
-
maxAge: number;
|
|
211
|
-
});
|
|
212
|
-
/**
|
|
213
|
-
* Get access token from cookies
|
|
214
|
-
* Works in both browser and Next.js server components
|
|
215
|
-
*/
|
|
216
|
-
getAccessToken(): string | null;
|
|
217
|
-
/**
|
|
218
|
-
* Set access token in cookies
|
|
219
|
-
* Works in browser environment
|
|
220
|
-
*/
|
|
221
|
-
setAccessToken(token: string): void;
|
|
222
|
-
/**
|
|
223
|
-
* Get refresh token from cookies
|
|
224
|
-
* Works in both browser and Next.js server components
|
|
225
|
-
*/
|
|
226
|
-
getRefreshToken(): string | null;
|
|
227
|
-
/**
|
|
228
|
-
* Set refresh token in cookies
|
|
229
|
-
* Works in browser environment
|
|
230
|
-
*/
|
|
231
|
-
setRefreshToken(token: string): void;
|
|
232
|
-
/**
|
|
233
|
-
* Clear all tokens from cookies
|
|
234
|
-
*/
|
|
235
|
-
clearTokens(): void;
|
|
236
|
-
/**
|
|
237
|
-
* Get cart ID from cookies
|
|
238
|
-
* Works in both browser and Next.js server components
|
|
113
|
+
* @param userId - User ID
|
|
114
|
+
* @returns Promise with user details
|
|
239
115
|
*/
|
|
240
|
-
|
|
116
|
+
updateUserDetails(pathParams: UpdateUserPathParams, body: UpdateUserBody): Promise<ApiResult<UpdateUserContent>>;
|
|
241
117
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
118
|
+
* Add profile image
|
|
119
|
+
*
|
|
120
|
+
* @param userId - User ID
|
|
121
|
+
* @returns Promise with user details
|
|
244
122
|
*/
|
|
245
|
-
|
|
123
|
+
addProfileImage(pathParams: AddProfileImagePathParams, formData: AddProfileImageFormData): Promise<ApiResult<AddProfileImageContent>>;
|
|
246
124
|
/**
|
|
247
|
-
*
|
|
125
|
+
* Update profile image
|
|
126
|
+
*
|
|
127
|
+
* @param userId - User ID
|
|
128
|
+
* @returns Promise with user details
|
|
248
129
|
*/
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Next.js specific cookie storage implementation
|
|
253
|
-
* Works with the Next.js cookies API
|
|
254
|
-
*/
|
|
255
|
-
export declare class NextCookieTokenStorage implements ClientStorage {
|
|
256
|
-
private accessTokenKey;
|
|
257
|
-
private refreshTokenKey;
|
|
258
|
-
private cartIdKey;
|
|
259
|
-
private cookieStore;
|
|
260
|
-
constructor(cookieStore: any, prefix?: string);
|
|
130
|
+
updateProfileImage(pathParams: UpdateProfileImagePathParams, formData: UpdateProfileImageFormData): Promise<ApiResult<UpdateProfileImageContent>>;
|
|
261
131
|
/**
|
|
262
|
-
*
|
|
132
|
+
* Delete profile image
|
|
133
|
+
*
|
|
134
|
+
* @param userId - User ID
|
|
135
|
+
* @returns Promise with user details
|
|
263
136
|
*/
|
|
264
|
-
|
|
137
|
+
deleteProfileImage(pathParams: RemoveProfileImagePathParams): Promise<ApiResult<RemoveProfileImageResponse>>;
|
|
265
138
|
/**
|
|
266
|
-
*
|
|
139
|
+
* Get profile image
|
|
140
|
+
*
|
|
141
|
+
* @param userId - User ID
|
|
142
|
+
* @returns Promise with user details
|
|
267
143
|
*/
|
|
268
|
-
|
|
144
|
+
getProfileImage(pathParams: GetProfileImagePathParams): Promise<ApiResult<GetProfileImageContent>>;
|
|
269
145
|
/**
|
|
270
|
-
*
|
|
146
|
+
* Deactivate user account
|
|
147
|
+
*
|
|
148
|
+
* @param userId - User ID
|
|
149
|
+
* @returns Promise with user details
|
|
271
150
|
*/
|
|
272
|
-
|
|
151
|
+
deactivateUserAccount(pathParams: DeactivateUserPathParams): Promise<ApiResult<DeactivateUserResponse>>;
|
|
273
152
|
/**
|
|
274
|
-
*
|
|
153
|
+
* Get user notification preferences
|
|
154
|
+
*
|
|
155
|
+
* @param userId - User ID
|
|
156
|
+
* @returns Promise with user details
|
|
275
157
|
*/
|
|
276
|
-
|
|
158
|
+
getUserNotificationPreferences(pathParams: GetNotificationPreferencesPathParams): Promise<ApiResult<GetNotificationPreferencesContent>>;
|
|
277
159
|
/**
|
|
278
|
-
*
|
|
160
|
+
* Update user notification preferences
|
|
161
|
+
*
|
|
162
|
+
* @param userId - User ID
|
|
163
|
+
* @returns Promise with user details
|
|
279
164
|
*/
|
|
280
|
-
|
|
165
|
+
updateUserNotificationPreferences(pathParams: UpdateNotificationPreferencesPathParams, body: UpdateNotificationPreferencesBody): Promise<ApiResult<UpdateNotificationPreferencesContent>>;
|
|
281
166
|
/**
|
|
282
|
-
*
|
|
167
|
+
* Create user notification preference
|
|
168
|
+
*
|
|
169
|
+
* @param userId - User ID
|
|
170
|
+
* @returns Promise with user details
|
|
283
171
|
*/
|
|
284
|
-
|
|
172
|
+
createUserNotificationPreference(pathParams: CreateNotificationPreferencesPathParams, body: CreateNotificationPreferencesBody): Promise<ApiResult<CreateNotificationPreferencesContent>>;
|
|
285
173
|
/**
|
|
286
|
-
*
|
|
174
|
+
* Generate OTP
|
|
175
|
+
*
|
|
176
|
+
* @param body - OTP generation body
|
|
177
|
+
* @returns Promise with OTP generation response
|
|
287
178
|
*/
|
|
288
|
-
|
|
179
|
+
generateOtp(body: GenerateOtpBody): Promise<ApiResult<GenerateOtpContent>>;
|
|
289
180
|
/**
|
|
290
|
-
*
|
|
181
|
+
* Check whether email or phone is already verified
|
|
182
|
+
*
|
|
183
|
+
* @param body - OTP generation body
|
|
184
|
+
* @returns Promise with OTP generation response
|
|
291
185
|
*/
|
|
292
|
-
|
|
186
|
+
checkEmailOrPhoneIsVerified(body: CheckVerificationStatusBody): Promise<ApiResult<CheckVerificationStatusContent>>;
|
|
293
187
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Helper to create a token storage instance based on environment
|
|
296
|
-
* Automatically selects the best storage method based on context
|
|
297
|
-
*/
|
|
298
|
-
export declare function createTokenStorage(options?: {
|
|
299
|
-
prefix?: string;
|
|
300
|
-
cookieStore?: any;
|
|
301
|
-
useLocalStorage?: boolean;
|
|
302
|
-
}): TokenStorage;
|