@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 CHANGED
@@ -88,13 +88,13 @@ export declare const DjustSDK: {
88
88
  getProductVariantSuppliers({ productVariantId, }: import("./interfaces").GetProductVariantSuppliersParameters): Promise<import("./interfaces").GetProductVariantSuppliersResponse>;
89
89
  getProduct({ productIdentifier, productIdType, locale, }: import("./interfaces").GetProductParameters): Promise<import("./interfaces").GetProductsListResponse>;
90
90
  getProductOffers({ productIdentifier, productIdType, locale, currency, }: import("./interfaces").GetProductOffersParameters): Promise<import("./interfaces").GetProductOffersResponse>;
91
- getProductPaginatedOffers({ productIdentifier, productIdType, currency, locale, withoutPrices, pageable, }: import("./interfaces").GetProductPaginatedOffersParameters): Promise<import("./interfaces").GetProductPaginatedOffersResponse>;
92
- getRelatedProducts({ productIdentifier, productIdType, locale, currency, pageable, }: import("./interfaces").GetRelatedProductsParameters): Promise<import("./interfaces").GetRelatedProductsResponse>;
91
+ getRelatedProducts({ productIdentifier, productIdType, locale, currency, pageable, }: import("./interfaces").GetRelatedProductsParameters): Promise<import("./interfaces").GetRelatedProductsParameters>;
93
92
  getProductReviews({ productIdentifier, productIdType, }: import("./interfaces").GetProductReviewsParameters): Promise<import("./interfaces").GetProductReviewsResponse>;
94
93
  getProductStatReviews({ productIdentifier, productIdType, }: import("./interfaces").GetProductStatReviewsParameters): Promise<import("./interfaces").GetProductStatReviewsResponse>;
95
94
  getProductVariantAttributes({ productIdentifier, productIdType, locale, }: import("./interfaces").GetProductVariantAttributesParameters): Promise<import("./interfaces").GetProductVariantAttributesResponse>;
96
95
  createProductReview({ message, productSku, rating, }: import("./interfaces").CreateProductReviewParameters): Promise<import("./interfaces").CreateProductReviewResponse>;
97
96
  updateProductReview({ productReviewId, message, rating, }: import("./interfaces").UpdateProductReviewParameters): Promise<import("./interfaces").UpdateProductReviewResponse>;
97
+ getProductPaginatedOffers({ productIdentifier, productIdType, currency, locale, withoutPrices, pageable, }: import("./interfaces").GetProductPaginatedOffersParameters): Promise<import("./interfaces").GetProductPaginatedOffersResponse>;
98
98
  getNavigationCategories({ locale, }: import("./interfaces").GetNavigationCategoriesParameters): Promise<import("./interfaces").GetNavigationCategoriesResponse>;
99
99
  getNavigationCategory({ locale, idType, navigationCategoryId, }: import("./interfaces").GetNavigationCategoryParameters): Promise<import("./interfaces").GetNavigationCategoryResponse>;
100
100
  getNavigationCategoryBreadcrumbs({ locale, idType, navigationCategoryId, }: import("./interfaces").GetNavigationCategoryBreadcrumbsParameters): Promise<import("./interfaces").GetNavigationCategoryBreadcrumbsResponse>;
@@ -142,11 +142,11 @@ export declare const DjustSDK: {
142
142
  deleteBuyingList({ buyingListId, }: import("./interfaces").DeleteBuyingListParameters): Promise<void>;
143
143
  deleteBuyingListItems({ buyingListId, itemIds, }: import("./interfaces").DeleteBuyingListItemsParameters): Promise<void>;
144
144
  updateBuyingListOwner({ buyingListId, newOwnerEmail, }: import("./interfaces").UpdateBuyingListOwnerParameters): Promise<void>;
145
- isTokenValid({ token, }: import("./interfaces").IsTokenValidParameters): Promise<boolean>;
146
- refreshToken({ refreshToken, }: import("./interfaces").RefreshTokenParameters): Promise<import("./interfaces").RefreshTokenResponse>;
147
- resetPassword({ newPassword, resetPasswordToken, }: import("./interfaces").ResetPasswordParameters): Promise<void>;
148
- sendResetPasswordEmail({ email, }: import("./interfaces").SendResetPasswordEmailParameters): Promise<void>;
149
- login({ username, password, }: import("./interfaces").LoginParameters): Promise<import("./interfaces").LoginResponse>;
145
+ isTokenValid({ token, }: import("./services/auth/definitions.requests").IsTokenValidParameters): Promise<boolean>;
146
+ refreshToken({ refreshToken, }: import("./services/auth/definitions.requests").RefreshTokenParameters): Promise<import("./interfaces").RefreshTokenResponse>;
147
+ resetPassword({ newPassword, resetPasswordToken, }: import("./services/auth/definitions.requests").ResetPasswordParameters): Promise<void>;
148
+ sendResetPasswordEmail({ email, }: import("./services/auth/definitions.requests").SendResetPasswordEmailParameters): Promise<void>;
149
+ login({ username, password, }: import("./services/auth/definitions.requests").LoginParameters): Promise<import("./interfaces").LoginResponse>;
150
150
  logout(): Promise<void>;
151
151
  };
152
152
  export * from "./interfaces";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Request parameters type definitions
3
+ */
4
+ export interface IsTokenValidParameters {
5
+ token: string;
6
+ }
7
+ export interface RefreshTokenParameters {
8
+ refreshToken: string;
9
+ }
10
+ export interface ResetPasswordParameters {
11
+ newPassword: string;
12
+ resetPasswordToken: string;
13
+ }
14
+ export interface SendResetPasswordEmailParameters {
15
+ email: string;
16
+ redirectUrl: string;
17
+ }
18
+ export interface LoginParameters {
19
+ username: string;
20
+ password: string;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,150 +1,176 @@
1
1
  /**
2
- * @packageDocumentation
2
+ * # Auth Service
3
3
  *
4
- * @document documents/auth.md
5
- */
6
- import { IsTokenValidParameters, LoginParameters, LoginResponse, RefreshTokenParameters, RefreshTokenResponse, ResetPasswordParameters, SendResetPasswordEmailParameters } from "./definitions";
7
- /**
8
- * CART ENDPOINT
4
+ * This module provides all functionalities related to user authentication and authorization.
5
+ *
6
+ * ## Features:
7
+ * - Validate tokens
8
+ * - Refresh tokens
9
+ * - Reset user passwords
10
+ * - Manage user login and logout
11
+ * - Send password reset emails
12
+ *
13
+ * Each function is described with its input parameters, output responses, and example usages.
9
14
  */
15
+ import { LoginResponse, RefreshTokenResponse } from "./definitions";
16
+ import { IsTokenValidParameters, LoginParameters, RefreshTokenParameters, ResetPasswordParameters, SendResetPasswordEmailParameters } from "./definitions.requests";
10
17
  /**
11
- * ##R eturns true if the token is valid and not expired, false otherwise
12
- * ### APICODE(TOK-200)
13
- * @param {IsTokenValidParameters} params - The parameters for the function
14
- * #### token - `string` | <strong style={{ color: 'red' }}>required</strong>
15
- * The token to validate.
16
- *
17
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the token is valid or not
18
- *
19
- * @example
20
- * #### input
21
- * ```typescript
22
- * const isValidToken = await isTokenValid({
23
- * token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
18
+ * 🔐 Validates if a token is still active and unexpired.
19
+ *
20
+ * This function checks whether the provided token is valid, ensuring it has not expired or been invalidated.
21
+ *
22
+ * 🛠 **Endpoint**: `GET /auth/is-token-valid [TOK-200]`
23
+ *
24
+ * | Parameter | Type | Required | Description |
25
+ * |-----------|----------|----------|-------------------------------------|
26
+ * | `token` | `string` | ✅ | The token to validate. |
27
+ *
28
+ * 📤 **Returns**:
29
+ * A `Promise<boolean>` resolving to `true` if the token is valid and active, or `false` otherwise.
30
+ *
31
+ * 🛠 **Example usage**:
32
+ * ```ts
33
+ * const isValid = await isTokenValid({
34
+ * token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
24
35
  * });
36
+ * console.log(isValid); // true
25
37
  * ```
26
- * #### output
27
- * ```json
28
- * true
29
- * ```
38
+ *
39
+ * @param {IsTokenValidParameters} params - The parameters for validating the token.
40
+ * @throws {Error} If the required `token` parameter is missing.
41
+ * @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether the token is valid.
30
42
  */
31
43
  export declare function isTokenValid({ token, }: IsTokenValidParameters): Promise<boolean>;
32
44
  /**
33
- * ## Ask for a new token from a refresh token
34
- * ### APICODE(AUTH-102)
35
- * @param {RefreshTokenParameters} params - The parameters for the function, including:
36
- * #### refreshToken - `string` | <strong style={{ color: 'red' }}>required</strong>
37
- * The refresh token to request a new access token (required)
38
- *
39
- * @returns {Promise<RefreshTokenResponse>} - A promise that resolves to the response containing the new token
40
- *
41
- * @example
42
- * #### input
43
- * ```typescript
44
- * const response = await refreshToken({ refreshToken: 'string' });
45
- * ```
46
- * #### output
47
- * ```json
48
- * {
49
- * "token": {
50
- * "accessToken": "string",
51
- * "expireAt": 0,
52
- * "refreshToken": "string"
53
- * },
54
- * "user": {
55
- * "id": "userID"
56
- * }
57
- * }
45
+ * 🔄 Requests a new access token using a refresh token.
46
+ *
47
+ * This function allows you to obtain a new access token by providing a valid refresh token.
48
+ *
49
+ * 🛠 **Endpoint**: `POST /auth/refresh-token [AUTH-102]`
50
+ *
51
+ * | Parameter | Type | Required | Description |
52
+ * |-----------------|----------|----------|--------------------------------------------------|
53
+ * | `refreshToken` | `string` | ✅ | The refresh token used to request a new access token. |
54
+ *
55
+ * 📤 **Returns**:
56
+ * A `Promise<RefreshTokenResponse>` containing the new access token, its expiry time, and a refreshed token.
57
+ *
58
+ * 🛠 **Example usage**:
59
+ * ```ts
60
+ * const response = await refreshToken({
61
+ * refreshToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
62
+ * });
58
63
  * ```
64
+ *
65
+ * @param {RefreshTokenParameters} params - The parameters for requesting a new token.
66
+ * @throws {Error} If the required `refreshToken` parameter is missing.
67
+ * @returns {Promise<RefreshTokenResponse>} A promise that resolves to the response containing the new token and user details.
59
68
  */
60
69
  export declare function refreshToken({ refreshToken, }: RefreshTokenParameters): Promise<RefreshTokenResponse>;
61
70
  /**
62
- * ## Reset the password of a user
63
- * ### APICODE(PWD-102)
64
- * @param {ResetPasswordParameters} params - The parameters for the function
65
- * #### newPassword - `string` | <strong style={{ color: 'red' }}>required</strong>
66
- * The new password to set for the user.
67
- * #### resetPasswordToken - `string` | <strong style={{ color: 'red' }}>required</strong>
68
- * The token required to authenticate the password reset process.
69
- *
70
- * @returns {Promise<void>} - Resolves to a success message `"OK"` when the password is successfully reset
71
- *
72
- * @example
73
- * #### input
74
- * ```typescript
75
- * await resetPassword({ newPassword: 'string', resetPasswordToken: 'string' });
76
- * ```
77
- * #### output
78
- * ```json
79
- * "OK" (No output, resolves on success)
71
+ * 🔑 Resets the password of a user.
72
+ *
73
+ * This function allows a user to reset their password by providing a new password along with a valid reset token.
74
+ *
75
+ * 🛠 **Endpoint**: `POST /auth/reset-password [PWD-102]`
76
+ *
77
+ * | Parameter | Type | Required | Description |
78
+ * |-----------------------|----------|----------|--------------------------------------------------------------|
79
+ * | `newPassword` | `string` | ✅ | The new password to set for the user. |
80
+ * | `resetPasswordToken` | `string` | ✅ | The token required to authenticate the password reset process. |
81
+ *
82
+ * 📤 **Returns**:
83
+ * A `Promise<void>` that resolves with a success message `"OK"` if the password is successfully reset.
84
+ *
85
+ * 🛠 **Example usage**:
86
+ * ```ts
87
+ * await resetPassword({
88
+ * newPassword: "mySecurePassword2025!",
89
+ * resetPasswordToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
90
+ * });
80
91
  * ```
92
+ *
93
+ * @param {ResetPasswordParameters} params - The parameters required for resetting the password.
94
+ * @throws {Error} If the required parameters `newPassword` or `resetPasswordToken` are missing.
95
+ * @returns {Promise<void>} Resolves to `"OK"` if the password reset is successful.
81
96
  */
82
97
  export declare function resetPassword({ newPassword, resetPasswordToken, }: ResetPasswordParameters): Promise<void>;
83
98
  /**
84
- * ## Send an email to the user with a reset password link
85
- * ### APICODE(PWD-101)
86
- * @param {SendResetPasswordEmailParameters} params - The parameters for the function, including:
87
- * #### email - `string` | <strong style={{ color: 'red' }}>required</strong>
88
- * The email address to send the reset link to.
89
- *
90
- * @returns {Promise<void>} - A promise that resolves when the email is sent
91
- *
92
- * @example
93
- * #### input
94
- * ```typescript
95
- * await sendResetPasswordEmail({ email: 'user@example.com' });
96
- * ```
97
- * #### output
98
- * ```json
99
- * "OK" (No output, resolves on success)
99
+ * 📧 Sends a reset password email to a user.
100
+ *
101
+ * This function sends an email containing a reset password link to the specified email address.
102
+ *
103
+ * 🛠 **Endpoint**: `POST /auth/send-reset-password-email [PWD-101]`
104
+ *
105
+ * | Parameter | Type | Required | Description |
106
+ * |------------|----------|----------|----------------------------------------------------|
107
+ * | `email` | `string` | ✅ | The email address to which the reset link will be sent. |
108
+ *
109
+ * 📤 **Returns**:
110
+ * A `Promise<void>` that resolves when the reset password email is successfully sent.
111
+ *
112
+ * 🛠 **Example usage**:
113
+ * ```ts
114
+ * await sendResetPasswordEmail({
115
+ * email: "user@example.com",
116
+ * });
100
117
  * ```
118
+ *
119
+ * @param {SendResetPasswordEmailParameters} params - The parameters required to send the reset password email.
120
+ * @throws {Error} If the required parameter `email` is missing.
121
+ * @returns {Promise<void>} Resolves when the reset email is successfully sent.
101
122
  */
102
123
  export declare function sendResetPasswordEmail({ email, }: SendResetPasswordEmailParameters): Promise<void>;
103
124
  /**
104
- * ##Login a user
105
- * ### APICODE(AUTH-101)
106
- * @param {LoginParameters} params - The parameters for the function, including:
107
- * #### username - `string` | <strong style={{ color: 'red' }}>required</strong>
108
- * The username of the user to log in.
109
- * #### password - `string` | <strong style={{ color: 'red' }}>required</strong>
110
- * The password of the user to log in.
111
- *
112
- * @returns {Promise<LoginResponse>} - A promise that resolves to the response containing the user's login information
113
- *
114
- * @example
115
- * #### input
116
- * ```typescript
117
- * const loginResponse = await login({ username: 'user@example.com', password: 'password123' });
118
- * ```
119
- * #### output
120
- * ```json
121
- * {
122
- * "token": {
123
- * "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
124
- * "expireAt": 1679022000,
125
- * "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
126
- * },
127
- * "user": {
128
- * "id": "userID"
129
- * }
130
- * }
125
+ * 🔐 Logs in a user.
126
+ *
127
+ * 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.
128
+ *
129
+ * 🛠 **Endpoint**: `POST /auth/token?withUser=true [AUTH-101]`
130
+ *
131
+ * | Parameter | Type | Required | Description |
132
+ * |-------------|----------|----------|--------------------------------------|
133
+ * | `username` | `string` | ✅ | The username of the user to log in. |
134
+ * | `password` | `string` | ✅ | The password of the user to log in. |
135
+ *
136
+ * 📤 **Returns**:
137
+ * A `Promise<LoginResponse>` that resolves to the user's login information, including:
138
+ * - `token` (object): Contains the `accessToken`, `refreshToken`, and `expireAt` timestamp.
139
+ * - `user` (object): Contains the user's `id`.
140
+ *
141
+ * 🛠 **Example usage**:
142
+ * ```ts
143
+ * const loginResponse = await login({
144
+ * username: "user@example.com",
145
+ * password: "password123",
146
+ * });
131
147
  * ```
148
+ *
149
+ * @param {LoginParameters} params - The parameters required for logging in the user.
150
+ * @throws {Error} If the required parameters `username` or `password` are missing.
151
+ * @returns {Promise<LoginResponse>} Resolves to an object containing the user's login information.
132
152
  */
133
153
  export declare function login({ username, password, }: LoginParameters): Promise<LoginResponse>;
134
154
  /**
135
- * ### Logout the user
136
- * ### APICODE(AUTH-103)
155
+ * 🚪 Logs out the user.
137
156
  *
138
- * @returns {Promise<void>} - A promise that resolves when the user is logged out
157
+ * This function logs out the user by revoking their authentication token.
139
158
  *
140
- * @example
141
- * #### input
142
- * ```typescript
143
- * await logout();
144
- * ```
145
- * #### output
146
- * ```json
147
- * "OK" (No output, resolves on success)
159
+ * 🛠 **Endpoint**: `POST /auth/revoke-token [AUTH-103]`
160
+ *
161
+ * | Parameter | Type | Required | Description |
162
+ * |-----------|------|----------|-------------|
163
+ * | *(none)* | - | - | This function does not require any parameters. |
164
+ *
165
+ * 📤 **Returns**:
166
+ * A `Promise<void>` that resolves when the user is successfully logged out. No additional data is returned.
167
+ *
168
+ * 🛠 **Example usage**:
169
+ * ```ts
170
+ * await logout();
148
171
  * ```
172
+ *
173
+ * @throws {Error} If there is an issue with the logout process (e.g., network error).
174
+ * @returns {Promise<void>} Resolves when the logout is successful.
149
175
  */
150
176
  export declare function logout(): Promise<void>;