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