@djust-b2b/djust-front-sdk 1.15.0 → 1.16.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/lib/index.d.ts +7 -7
- package/lib/services/auth/definitions.requests.d.ts +21 -0
- package/lib/services/auth/definitions.requests.js +2 -0
- package/lib/services/auth/index.d.ts +146 -120
- package/lib/services/auth/index.js +144 -119
- package/lib/services/cart/index.d.ts +185 -254
- package/lib/services/cart/index.js +198 -257
- package/lib/services/custom-field/index.d.ts +55 -100
- package/lib/services/custom-field/index.js +55 -105
- package/lib/services/customer-user/index.d.ts +107 -125
- package/lib/services/customer-user/index.js +107 -125
- package/lib/services/navigation-category/index.d.ts +68 -119
- package/lib/services/navigation-category/index.js +68 -119
- package/lib/services/product/index.d.ts +296 -1687
- package/lib/services/product/index.js +312 -1706
- package/lib/services/product-variant/index.d.ts +53 -160
- package/lib/services/product-variant/index.js +53 -160
- package/package.json +1 -1
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* # Auth Service
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* This module provides all functionalities related to user authentication and authorization.
|
|
6
|
+
*
|
|
7
|
+
* ## Features:
|
|
8
|
+
* - Validate tokens
|
|
9
|
+
* - Refresh tokens
|
|
10
|
+
* - Reset user passwords
|
|
11
|
+
* - Manage user login and logout
|
|
12
|
+
* - Send password reset emails
|
|
13
|
+
*
|
|
14
|
+
* Each function is described with its input parameters, output responses, and example usages.
|
|
6
15
|
*/
|
|
7
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
17
|
exports.isTokenValid = isTokenValid;
|
|
@@ -14,28 +23,30 @@ exports.logout = logout;
|
|
|
14
23
|
const parameters_validation_1 = require("../../helpers/parameters-validation");
|
|
15
24
|
const fetch_instance_1 = require("../../settings/fetch-instance");
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
26
|
+
* 🔐 Validates if a token is still active and unexpired.
|
|
27
|
+
*
|
|
28
|
+
* This function checks whether the provided token is valid, ensuring it has not expired or been invalidated.
|
|
29
|
+
*
|
|
30
|
+
* 🛠 **Endpoint**: `GET /auth/is-token-valid [TOK-200]`
|
|
31
|
+
*
|
|
32
|
+
* | Parameter | Type | Required | Description |
|
|
33
|
+
* |-----------|----------|----------|-------------------------------------|
|
|
34
|
+
* | `token` | `string` | ✅ | The token to validate. |
|
|
35
|
+
*
|
|
36
|
+
* 📤 **Returns**:
|
|
37
|
+
* A `Promise<boolean>` resolving to `true` if the token is valid and active, or `false` otherwise.
|
|
38
|
+
*
|
|
39
|
+
* 🛠 **Example usage**:
|
|
40
|
+
* ```ts
|
|
41
|
+
* const isValid = await isTokenValid({
|
|
42
|
+
* token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
|
|
33
43
|
* });
|
|
44
|
+
* console.log(isValid); // true
|
|
34
45
|
* ```
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
46
|
+
*
|
|
47
|
+
* @param {IsTokenValidParameters} params - The parameters for validating the token.
|
|
48
|
+
* @throws {Error} If the required `token` parameter is missing.
|
|
49
|
+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether the token is valid.
|
|
39
50
|
*/
|
|
40
51
|
async function isTokenValid({ token, }) {
|
|
41
52
|
(0, parameters_validation_1.required)({ token });
|
|
@@ -49,32 +60,29 @@ async function isTokenValid({ token, }) {
|
|
|
49
60
|
return response === null || response === void 0 ? void 0 : response.data;
|
|
50
61
|
}
|
|
51
62
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* "expireAt": 0,
|
|
71
|
-
* "refreshToken": "string"
|
|
72
|
-
* },
|
|
73
|
-
* "user": {
|
|
74
|
-
* "id": "userID"
|
|
75
|
-
* }
|
|
76
|
-
* }
|
|
63
|
+
* 🔄 Requests a new access token using a refresh token.
|
|
64
|
+
*
|
|
65
|
+
* This function allows you to obtain a new access token by providing a valid refresh token.
|
|
66
|
+
*
|
|
67
|
+
* 🛠 **Endpoint**: `POST /auth/refresh-token [AUTH-102]`
|
|
68
|
+
*
|
|
69
|
+
* | Parameter | Type | Required | Description |
|
|
70
|
+
* |-----------------|----------|----------|--------------------------------------------------|
|
|
71
|
+
* | `refreshToken` | `string` | ✅ | The refresh token used to request a new access token. |
|
|
72
|
+
*
|
|
73
|
+
* 📤 **Returns**:
|
|
74
|
+
* A `Promise<RefreshTokenResponse>` containing the new access token, its expiry time, and a refreshed token.
|
|
75
|
+
*
|
|
76
|
+
* 🛠 **Example usage**:
|
|
77
|
+
* ```ts
|
|
78
|
+
* const response = await refreshToken({
|
|
79
|
+
* refreshToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
80
|
+
* });
|
|
77
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param {RefreshTokenParameters} params - The parameters for requesting a new token.
|
|
84
|
+
* @throws {Error} If the required `refreshToken` parameter is missing.
|
|
85
|
+
* @returns {Promise<RefreshTokenResponse>} A promise that resolves to the response containing the new token and user details.
|
|
78
86
|
*/
|
|
79
87
|
async function refreshToken({ refreshToken, }) {
|
|
80
88
|
(0, parameters_validation_1.required)({ refreshToken });
|
|
@@ -88,25 +96,31 @@ async function refreshToken({ refreshToken, }) {
|
|
|
88
96
|
return data;
|
|
89
97
|
}
|
|
90
98
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
99
|
+
* 🔑 Resets the password of a user.
|
|
100
|
+
*
|
|
101
|
+
* This function allows a user to reset their password by providing a new password along with a valid reset token.
|
|
102
|
+
*
|
|
103
|
+
* 🛠 **Endpoint**: `POST /auth/reset-password [PWD-102]`
|
|
104
|
+
*
|
|
105
|
+
* | Parameter | Type | Required | Description |
|
|
106
|
+
* |-----------------------|----------|----------|--------------------------------------------------------------|
|
|
107
|
+
* | `newPassword` | `string` | ✅ | The new password to set for the user. |
|
|
108
|
+
* | `resetPasswordToken` | `string` | ✅ | The token required to authenticate the password reset process. |
|
|
109
|
+
*
|
|
110
|
+
* 📤 **Returns**:
|
|
111
|
+
* A `Promise<void>` that resolves with a success message `"OK"` if the password is successfully reset.
|
|
112
|
+
*
|
|
113
|
+
* 🛠 **Example usage**:
|
|
114
|
+
* ```ts
|
|
115
|
+
* await resetPassword({
|
|
116
|
+
* newPassword: "mySecurePassword2025!",
|
|
117
|
+
* resetPasswordToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
118
|
+
* });
|
|
109
119
|
* ```
|
|
120
|
+
*
|
|
121
|
+
* @param {ResetPasswordParameters} params - The parameters required for resetting the password.
|
|
122
|
+
* @throws {Error} If the required parameters `newPassword` or `resetPasswordToken` are missing.
|
|
123
|
+
* @returns {Promise<void>} Resolves to `"OK"` if the password reset is successful.
|
|
110
124
|
*/
|
|
111
125
|
async function resetPassword({ newPassword, resetPasswordToken, }) {
|
|
112
126
|
(0, parameters_validation_1.required)({ newPassword, resetPasswordToken });
|
|
@@ -120,23 +134,29 @@ async function resetPassword({ newPassword, resetPasswordToken, }) {
|
|
|
120
134
|
});
|
|
121
135
|
}
|
|
122
136
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* ```
|
|
138
|
-
*
|
|
137
|
+
* 📧 Sends a reset password email to a user.
|
|
138
|
+
*
|
|
139
|
+
* This function sends an email containing a reset password link to the specified email address.
|
|
140
|
+
*
|
|
141
|
+
* 🛠 **Endpoint**: `POST /auth/send-reset-password-email [PWD-101]`
|
|
142
|
+
*
|
|
143
|
+
* | Parameter | Type | Required | Description |
|
|
144
|
+
* |------------|----------|----------|----------------------------------------------------|
|
|
145
|
+
* | `email` | `string` | ✅ | The email address to which the reset link will be sent. |
|
|
146
|
+
*
|
|
147
|
+
* 📤 **Returns**:
|
|
148
|
+
* A `Promise<void>` that resolves when the reset password email is successfully sent.
|
|
149
|
+
*
|
|
150
|
+
* 🛠 **Example usage**:
|
|
151
|
+
* ```ts
|
|
152
|
+
* await sendResetPasswordEmail({
|
|
153
|
+
* email: "user@example.com",
|
|
154
|
+
* });
|
|
139
155
|
* ```
|
|
156
|
+
*
|
|
157
|
+
* @param {SendResetPasswordEmailParameters} params - The parameters required to send the reset password email.
|
|
158
|
+
* @throws {Error} If the required parameter `email` is missing.
|
|
159
|
+
* @returns {Promise<void>} Resolves when the reset email is successfully sent.
|
|
140
160
|
*/
|
|
141
161
|
async function sendResetPasswordEmail({ email, }) {
|
|
142
162
|
(0, parameters_validation_1.required)({ email });
|
|
@@ -149,34 +169,33 @@ async function sendResetPasswordEmail({ email, }) {
|
|
|
149
169
|
});
|
|
150
170
|
}
|
|
151
171
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* },
|
|
175
|
-
* "user": {
|
|
176
|
-
* "id": "userID"
|
|
177
|
-
* }
|
|
178
|
-
* }
|
|
172
|
+
* 🔐 Logs in a user.
|
|
173
|
+
*
|
|
174
|
+
* This function allows a user to log in by providing their username and password, and returns their login information, including an access token and user details.
|
|
175
|
+
*
|
|
176
|
+
* 🛠 **Endpoint**: `POST /auth/token?withUser=true [AUTH-101]`
|
|
177
|
+
*
|
|
178
|
+
* | Parameter | Type | Required | Description |
|
|
179
|
+
* |-------------|----------|----------|--------------------------------------|
|
|
180
|
+
* | `username` | `string` | ✅ | The username of the user to log in. |
|
|
181
|
+
* | `password` | `string` | ✅ | The password of the user to log in. |
|
|
182
|
+
*
|
|
183
|
+
* 📤 **Returns**:
|
|
184
|
+
* A `Promise<LoginResponse>` that resolves to the user's login information, including:
|
|
185
|
+
* - `token` (object): Contains the `accessToken`, `refreshToken`, and `expireAt` timestamp.
|
|
186
|
+
* - `user` (object): Contains the user's `id`.
|
|
187
|
+
*
|
|
188
|
+
* 🛠 **Example usage**:
|
|
189
|
+
* ```ts
|
|
190
|
+
* const loginResponse = await login({
|
|
191
|
+
* username: "user@example.com",
|
|
192
|
+
* password: "password123",
|
|
193
|
+
* });
|
|
179
194
|
* ```
|
|
195
|
+
*
|
|
196
|
+
* @param {LoginParameters} params - The parameters required for logging in the user.
|
|
197
|
+
* @throws {Error} If the required parameters `username` or `password` are missing.
|
|
198
|
+
* @returns {Promise<LoginResponse>} Resolves to an object containing the user's login information.
|
|
180
199
|
*/
|
|
181
200
|
async function login({ username, password, }) {
|
|
182
201
|
(0, parameters_validation_1.required)({ username, password });
|
|
@@ -191,20 +210,26 @@ async function login({ username, password, }) {
|
|
|
191
210
|
return data;
|
|
192
211
|
}
|
|
193
212
|
/**
|
|
194
|
-
*
|
|
195
|
-
* ### APICODE(AUTH-103)
|
|
213
|
+
* 🚪 Logs out the user.
|
|
196
214
|
*
|
|
197
|
-
*
|
|
215
|
+
* This function logs out the user by revoking their authentication token.
|
|
198
216
|
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
217
|
+
* 🛠 **Endpoint**: `POST /auth/revoke-token [AUTH-103]`
|
|
218
|
+
*
|
|
219
|
+
* | Parameter | Type | Required | Description |
|
|
220
|
+
* |-----------|------|----------|-------------|
|
|
221
|
+
* | *(none)* | - | - | This function does not require any parameters. |
|
|
222
|
+
*
|
|
223
|
+
* 📤 **Returns**:
|
|
224
|
+
* A `Promise<void>` that resolves when the user is successfully logged out. No additional data is returned.
|
|
225
|
+
*
|
|
226
|
+
* 🛠 **Example usage**:
|
|
227
|
+
* ```ts
|
|
228
|
+
* await logout();
|
|
207
229
|
* ```
|
|
230
|
+
*
|
|
231
|
+
* @throws {Error} If there is an issue with the logout process (e.g., network error).
|
|
232
|
+
* @returns {Promise<void>} Resolves when the logout is successful.
|
|
208
233
|
*/
|
|
209
234
|
async function logout() {
|
|
210
235
|
await (0, fetch_instance_1.enhancedFetch)({
|