@hichchi/nest-connector 0.0.1-beta.2 → 0.0.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/auth.cjs.default.js +1 -0
- package/auth.cjs.js +1283 -0
- package/auth.cjs.mjs +2 -0
- package/auth.d.ts +1 -0
- package/auth.esm.js +1279 -0
- package/crud.cjs.default.js +1 -0
- package/crud.cjs.js +32 -0
- package/crud.cjs.mjs +2 -0
- package/crud.d.ts +1 -0
- package/crud.esm.js +32 -0
- package/error.responses.cjs.js +564 -0
- package/error.responses.esm.js +561 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +178 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -1
- package/index.esm.js +126 -0
- package/package.json +27 -6
- package/{auth → src/auth}/enums/auth-error-response.enum.d.ts +1 -0
- package/src/auth/index.d.ts +5 -0
- package/src/auth/interfaces/dtos/bulk-update-body.interface.d.ts +5 -0
- package/src/auth/interfaces/dtos/ids-body.interface.d.ts +4 -0
- package/{auth → src/auth}/interfaces/dtos/index.d.ts +2 -0
- package/src/auth/interfaces/google-profile.interface.d.ts +195 -0
- package/{auth → src/auth}/interfaces/index.d.ts +1 -0
- package/{auth → src/auth}/interfaces/user.interface.d.ts +2 -1
- package/{auth → src/auth}/responses/auth.error.responses.d.ts +1 -1
- package/src/crud/crud.d.ts +3 -0
- package/src/crud/enums/crud-endpoint.enum.d.ts +5 -0
- package/src/crud/enums/index.d.ts +1 -0
- package/{crud → src/crud}/index.d.ts +1 -0
- package/{crud → src/crud}/interfaces/index.d.ts +3 -1
- package/src/crud/interfaces/pagination-options.interface.d.ts +4 -0
- package/{crud → src/crud}/interfaces/pagination.interface.d.ts +4 -3
- package/src/crud/interfaces/with-id.interface.d.ts +7 -0
- package/src/crud/types/filter-options.type.d.ts +5 -0
- package/src/crud/types/index.d.ts +4 -0
- package/src/crud/types/search-options.type.d.ts +9 -0
- package/src/crud/types/sort-options.type.d.ts +10 -0
- package/src/crud/types/types.d.ts +35 -0
- package/src/index.d.ts +1 -0
- package/CHANGELOG.md +0 -33
- package/README.md +0 -3678
- package/auth/enums/auth-endpoint.enum.js +0 -180
- package/auth/enums/auth-endpoint.enum.js.map +0 -1
- package/auth/enums/auth-error-response.enum.js +0 -385
- package/auth/enums/auth-error-response.enum.js.map +0 -1
- package/auth/enums/auth-field.enum.js +0 -43
- package/auth/enums/auth-field.enum.js.map +0 -1
- package/auth/enums/auth-method.enum.js +0 -31
- package/auth/enums/auth-method.enum.js.map +0 -1
- package/auth/enums/auth-provider.enum.js +0 -36
- package/auth/enums/auth-provider.enum.js.map +0 -1
- package/auth/enums/auth-strategy.enum.js +0 -50
- package/auth/enums/auth-strategy.enum.js.map +0 -1
- package/auth/enums/auth-success-response.enum.js +0 -81
- package/auth/enums/auth-success-response.enum.js.map +0 -1
- package/auth/enums/index.js +0 -11
- package/auth/enums/index.js.map +0 -1
- package/auth/index.js +0 -9
- package/auth/index.js.map +0 -1
- package/auth/interfaces/dtos/bulk-delete-body.interface.js +0 -3
- package/auth/interfaces/dtos/bulk-delete-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/email-verify-body.interface.js +0 -3
- package/auth/interfaces/dtos/email-verify-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/get-auth-response-body.interface.js +0 -3
- package/auth/interfaces/dtos/get-auth-response-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/index.js +0 -15
- package/auth/interfaces/dtos/index.js.map +0 -1
- package/auth/interfaces/dtos/refresh-token-body.interface.js +0 -3
- package/auth/interfaces/dtos/refresh-token-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/request-reset-body.interface.js +0 -3
- package/auth/interfaces/dtos/request-reset-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/resend-email-verify-body.interface.js +0 -3
- package/auth/interfaces/dtos/resend-email-verify-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/reset-password-body.interface.js +0 -3
- package/auth/interfaces/dtos/reset-password-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/reset-password-token-verify-body.interface.js +0 -3
- package/auth/interfaces/dtos/reset-password-token-verify-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/sign-in-body.interface.js +0 -3
- package/auth/interfaces/dtos/sign-in-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/sign-up-body.interface.js +0 -3
- package/auth/interfaces/dtos/sign-up-body.interface.js.map +0 -1
- package/auth/interfaces/dtos/update-password-body.interface.js +0 -3
- package/auth/interfaces/dtos/update-password-body.interface.js.map +0 -1
- package/auth/interfaces/index.js +0 -11
- package/auth/interfaces/index.js.map +0 -1
- package/auth/interfaces/response.interfaces.js +0 -3
- package/auth/interfaces/response.interfaces.js.map +0 -1
- package/auth/interfaces/role.interface.js +0 -3
- package/auth/interfaces/role.interface.js.map +0 -1
- package/auth/interfaces/token-response.interface.js +0 -3
- package/auth/interfaces/token-response.interface.js.map +0 -1
- package/auth/interfaces/tokens.interface.js +0 -3
- package/auth/interfaces/tokens.interface.js.map +0 -1
- package/auth/interfaces/user-session.interface.js +0 -3
- package/auth/interfaces/user-session.interface.js.map +0 -1
- package/auth/interfaces/user.interface.js +0 -3
- package/auth/interfaces/user.interface.js.map +0 -1
- package/auth/responses/auth.error.responses.js +0 -329
- package/auth/responses/auth.error.responses.js.map +0 -1
- package/auth/responses/auth.success.responses.js +0 -109
- package/auth/responses/auth.success.responses.js.map +0 -1
- package/auth/responses/index.js +0 -6
- package/auth/responses/index.js.map +0 -1
- package/auth/types/index.js +0 -5
- package/auth/types/index.js.map +0 -1
- package/auth/types/types.js +0 -4
- package/auth/types/types.js.map +0 -1
- package/auth/utils/auth.utils.js +0 -63
- package/auth/utils/auth.utils.js.map +0 -1
- package/auth/utils/index.js +0 -5
- package/auth/utils/index.js.map +0 -1
- package/common/builders/index.js +0 -5
- package/common/builders/index.js.map +0 -1
- package/common/builders/success-response.dto.js +0 -114
- package/common/builders/success-response.dto.js.map +0 -1
- package/common/constants.js +0 -17
- package/common/constants.js.map +0 -1
- package/common/enums/common-error-response-code.enum.js +0 -120
- package/common/enums/common-error-response-code.enum.js.map +0 -1
- package/common/enums/common-success-response-code.enum.js +0 -30
- package/common/enums/common-success-response-code.enum.js.map +0 -1
- package/common/enums/endpoint.enum.js +0 -34
- package/common/enums/endpoint.enum.js.map +0 -1
- package/common/enums/gateways.enum.js +0 -37
- package/common/enums/gateways.enum.js.map +0 -1
- package/common/enums/http-status.enums.js +0 -144
- package/common/enums/http-status.enums.js.map +0 -1
- package/common/enums/index.js +0 -9
- package/common/enums/index.js.map +0 -1
- package/common/index.js +0 -10
- package/common/index.js.map +0 -1
- package/common/interfaces/index.js +0 -6
- package/common/interfaces/index.js.map +0 -1
- package/common/interfaces/response.interfaces.js +0 -3
- package/common/interfaces/response.interfaces.js.map +0 -1
- package/common/interfaces/user-info.interface.js +0 -4
- package/common/interfaces/user-info.interface.js.map +0 -1
- package/common/responses/error.responses.js +0 -151
- package/common/responses/error.responses.js.map +0 -1
- package/common/responses/index.js +0 -6
- package/common/responses/index.js.map +0 -1
- package/common/responses/success.responses.js +0 -69
- package/common/responses/success.responses.js.map +0 -1
- package/common/types/index.js +0 -6
- package/common/types/index.js.map +0 -1
- package/common/types/response-code.js +0 -3
- package/common/types/response-code.js.map +0 -1
- package/common/types/types.js +0 -4
- package/common/types/types.js.map +0 -1
- package/crud/index.js +0 -6
- package/crud/index.js.map +0 -1
- package/crud/interfaces/index.js +0 -7
- package/crud/interfaces/index.js.map +0 -1
- package/crud/interfaces/model.interface.js +0 -3
- package/crud/interfaces/model.interface.js.map +0 -1
- package/crud/interfaces/pagination.interface.js +0 -3
- package/crud/interfaces/pagination.interface.js.map +0 -1
- package/crud/interfaces/response.interfaces.js +0 -3
- package/crud/interfaces/response.interfaces.js.map +0 -1
- package/crud/types/index.d.ts +0 -1
- package/crud/types/index.js +0 -5
- package/crud/types/index.js.map +0 -1
- package/crud/types/types.d.ts +0 -77
- package/crud/types/types.js +0 -4
- package/crud/types/types.js.map +0 -1
- package/index.js +0 -5
- package/index.js.map +0 -1
- package/readme-top.md +0 -167
- /package/{auth/index.d.ts → src/auth/auth.d.ts} +0 -0
- /package/{auth → src/auth}/enums/auth-endpoint.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/auth-field.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/auth-method.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/auth-provider.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/auth-strategy.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/auth-success-response.enum.d.ts +0 -0
- /package/{auth → src/auth}/enums/index.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/bulk-delete-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/email-verify-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/get-auth-response-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/refresh-token-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/request-reset-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/resend-email-verify-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/reset-password-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/reset-password-token-verify-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/sign-in-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/sign-up-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/dtos/update-password-body.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/response.interfaces.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/role.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/token-response.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/tokens.interface.d.ts +0 -0
- /package/{auth → src/auth}/interfaces/user-session.interface.d.ts +0 -0
- /package/{auth → src/auth}/responses/auth.success.responses.d.ts +0 -0
- /package/{auth → src/auth}/responses/index.d.ts +0 -0
- /package/{auth → src/auth}/types/index.d.ts +0 -0
- /package/{auth → src/auth}/types/types.d.ts +0 -0
- /package/{auth → src/auth}/utils/auth.utils.d.ts +0 -0
- /package/{auth → src/auth}/utils/index.d.ts +0 -0
- /package/{common → src/common}/builders/index.d.ts +0 -0
- /package/{common → src/common}/builders/success-response.dto.d.ts +0 -0
- /package/{common → src/common}/constants.d.ts +0 -0
- /package/{common → src/common}/enums/common-error-response-code.enum.d.ts +0 -0
- /package/{common → src/common}/enums/common-success-response-code.enum.d.ts +0 -0
- /package/{common → src/common}/enums/endpoint.enum.d.ts +0 -0
- /package/{common → src/common}/enums/gateways.enum.d.ts +0 -0
- /package/{common → src/common}/enums/http-status.enums.d.ts +0 -0
- /package/{common → src/common}/enums/index.d.ts +0 -0
- /package/{common → src/common}/index.d.ts +0 -0
- /package/{common → src/common}/interfaces/index.d.ts +0 -0
- /package/{common → src/common}/interfaces/response.interfaces.d.ts +0 -0
- /package/{common → src/common}/interfaces/user-info.interface.d.ts +0 -0
- /package/{common → src/common}/responses/error.responses.d.ts +0 -0
- /package/{common → src/common}/responses/index.d.ts +0 -0
- /package/{common → src/common}/responses/success.responses.d.ts +0 -0
- /package/{common → src/common}/types/index.d.ts +0 -0
- /package/{common → src/common}/types/response-code.d.ts +0 -0
- /package/{common → src/common}/types/types.d.ts +0 -0
- /package/{crud → src/crud}/interfaces/model.interface.d.ts +0 -0
- /package/{crud → src/crud}/interfaces/response.interfaces.d.ts +0 -0
package/auth.cjs.js
ADDED
|
@@ -0,0 +1,1283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var error_responses = require('./error.responses.cjs.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Authentication Endpoints Enum
|
|
7
|
+
*
|
|
8
|
+
* This enum defines all authentication-related endpoints used in the application.
|
|
9
|
+
* Each value represents a specific API endpoint path segment for authentication operations.
|
|
10
|
+
*
|
|
11
|
+
* Enum Values:
|
|
12
|
+
* - `SIGN_UP`: User registration endpoint.
|
|
13
|
+
* - `SIGN_IN`: Local authentication endpoint.
|
|
14
|
+
* - `GOOGLE_SIGN_IN`: Initiates Google OAuth flow.
|
|
15
|
+
* - `GOOGLE_CALLBACK`: Callback endpoint for Google OAuth.
|
|
16
|
+
* - `AUTHENTICATE_SOCIAL`: Process social authentication data.
|
|
17
|
+
* - `REFRESH_TOKEN`: Obtain a new access token using refresh token.
|
|
18
|
+
* - `REQUEST_PASSWORD_RESET`: Request password reset link/code.
|
|
19
|
+
* - `RESET_PASSWORD_VERIFY`: Verify password reset token/code.
|
|
20
|
+
* - `RESEND_EMAIL_VERIFICATION`: Send verification email again.
|
|
21
|
+
* - `VERIFY_EMAIL`: Confirm email verification.
|
|
22
|
+
* - `RESET_PASSWORD`: Set new password after verification.
|
|
23
|
+
* - `ME`: Get current authenticated user info.
|
|
24
|
+
* - `CHANGE_PASSWORD`: Update user's password.
|
|
25
|
+
* - `SIGN_OUT`: End user session/invalidate tokens.
|
|
26
|
+
*/
|
|
27
|
+
exports.AuthEndpoint = void 0;
|
|
28
|
+
(function (AuthEndpoint) {
|
|
29
|
+
/**
|
|
30
|
+
* User registration endpoint
|
|
31
|
+
*
|
|
32
|
+
* Handles new user account creation with provided credentials and profile information.
|
|
33
|
+
* This endpoint accepts user registration data including email, password, and optional
|
|
34
|
+
* profile details, then creates a new account in the system.
|
|
35
|
+
*
|
|
36
|
+
* The endpoint may also trigger email verification, depending on configuration.
|
|
37
|
+
*/
|
|
38
|
+
AuthEndpoint["SIGN_UP"] = "sign-up";
|
|
39
|
+
/**
|
|
40
|
+
* Local authentication endpoint
|
|
41
|
+
*
|
|
42
|
+
* Authenticates users with username/email and password, returning authentication tokens.
|
|
43
|
+
* This endpoint validates the provided credentials against stored user data and,
|
|
44
|
+
* if valid, generates and returns access and refresh tokens for the authenticated session.
|
|
45
|
+
*
|
|
46
|
+
* The endpoint also sets authentication cookies if configured to do so.
|
|
47
|
+
*/
|
|
48
|
+
AuthEndpoint["SIGN_IN"] = "sign-in";
|
|
49
|
+
/**
|
|
50
|
+
* Initiates Google OAuth flow
|
|
51
|
+
*
|
|
52
|
+
* Redirects users to Google's authentication page to begin the OAuth process.
|
|
53
|
+
* This endpoint starts the OAuth 2.0 flow with Google by redirecting the user
|
|
54
|
+
* to Google's authentication page. It accepts a redirectUrl parameter that
|
|
55
|
+
* specifies where to redirect after successful authentication.
|
|
56
|
+
*
|
|
57
|
+
* The URL is stored in the OAuth state parameter to be used by the callback endpoint.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link GOOGLE_CALLBACK} - The endpoint that handles the OAuth callback
|
|
60
|
+
*/
|
|
61
|
+
AuthEndpoint["GOOGLE_SIGN_IN"] = "google-sign-in";
|
|
62
|
+
/**
|
|
63
|
+
* Callback endpoint for Google OAuth
|
|
64
|
+
*
|
|
65
|
+
* Receives and processes authentication data after successful Google authentication.
|
|
66
|
+
* This endpoint is called by Google's OAuth service after the user has successfully
|
|
67
|
+
* authenticated. It extracts the authentication code, exchanges it for tokens,
|
|
68
|
+
* and redirects the user to the original redirectUrl specified in the initial request,
|
|
69
|
+
* passing the access token as a query parameter.
|
|
70
|
+
*
|
|
71
|
+
* @see {@link GOOGLE_SIGN_IN} - The endpoint that initiates the OAuth flow
|
|
72
|
+
*/
|
|
73
|
+
AuthEndpoint["GOOGLE_CALLBACK"] = "google-callback";
|
|
74
|
+
/**
|
|
75
|
+
* Get authentication response from an existing token
|
|
76
|
+
*
|
|
77
|
+
* This endpoint allows clients to retrieve a complete authentication response
|
|
78
|
+
* using a previously issued JWT access token. It verifies the token,
|
|
79
|
+
* retrieves the associated user information, generates new tokens,
|
|
80
|
+
* and returns comprehensive authentication data.
|
|
81
|
+
*
|
|
82
|
+
* This is useful for clients that need to exchange an existing token
|
|
83
|
+
* for a complete authentication response containing user details and session information.
|
|
84
|
+
*/
|
|
85
|
+
AuthEndpoint["GET_AUTH_RESPONSE"] = "get-auth-response";
|
|
86
|
+
/**
|
|
87
|
+
* Obtain a new access token using refresh token
|
|
88
|
+
*
|
|
89
|
+
* Allows clients to get a new access token without requiring re-authentication.
|
|
90
|
+
* This endpoint accepts a valid refresh token and, if the token is valid and
|
|
91
|
+
* not expired, issues new access and refresh tokens for continued authentication.
|
|
92
|
+
*
|
|
93
|
+
* This enables longer user sessions without requiring frequent logins while still
|
|
94
|
+
* maintaining security by using short-lived access tokens.
|
|
95
|
+
*/
|
|
96
|
+
AuthEndpoint["REFRESH_TOKEN"] = "refresh-token";
|
|
97
|
+
/**
|
|
98
|
+
* Request password reset link/code
|
|
99
|
+
*
|
|
100
|
+
* Initiates the password recovery process by sending reset instructions.
|
|
101
|
+
* This endpoint accepts an email address, validates that it belongs to a registered
|
|
102
|
+
* user, and sends a password reset link or code to that email address. For security,
|
|
103
|
+
* it typically returns a success response regardless of whether the email exists
|
|
104
|
+
* in the system to prevent email enumeration attacks.
|
|
105
|
+
*/
|
|
106
|
+
AuthEndpoint["REQUEST_PASSWORD_RESET"] = "request-password-reset";
|
|
107
|
+
/**
|
|
108
|
+
* Verify password reset token/code
|
|
109
|
+
*
|
|
110
|
+
* Validates the reset token before allowing password change.
|
|
111
|
+
* This endpoint accepts a password reset token and verifies its validity without
|
|
112
|
+
* actually resetting the password. This allows client applications to verify
|
|
113
|
+
* a token before showing the password reset form to the user, improving user experience
|
|
114
|
+
* by providing immediate feedback about expired or invalid tokens.
|
|
115
|
+
*/
|
|
116
|
+
AuthEndpoint["RESET_PASSWORD_VERIFY"] = "reset-password-verify";
|
|
117
|
+
/**
|
|
118
|
+
* Send verification email again
|
|
119
|
+
*
|
|
120
|
+
* Allows users to request a new verification email if the original expired or was lost.
|
|
121
|
+
* This endpoint accepts an email address and, if it belongs to an unverified user,
|
|
122
|
+
* generates a new verification token and sends a verification email to that address.
|
|
123
|
+
* For security reasons, it typically returns a success response regardless of whether
|
|
124
|
+
* the email exists or is already verified.
|
|
125
|
+
*/
|
|
126
|
+
AuthEndpoint["RESEND_EMAIL_VERIFICATION"] = "resend-email-verification";
|
|
127
|
+
/**
|
|
128
|
+
* Confirm email verification
|
|
129
|
+
*
|
|
130
|
+
* Processes the verification link clicked from email to confirm user's email address.
|
|
131
|
+
* This endpoint is typically accessed via a link in the verification email sent to users.
|
|
132
|
+
* It accepts a verification token, validates it, marks the user's email as verified if
|
|
133
|
+
* the token is valid, and redirects the user to a configured URL with a query parameter
|
|
134
|
+
* indicating whether the verification was successful.
|
|
135
|
+
*/
|
|
136
|
+
AuthEndpoint["VERIFY_EMAIL"] = "verify-email";
|
|
137
|
+
/**
|
|
138
|
+
* Set new password after verification
|
|
139
|
+
*
|
|
140
|
+
* Allows users to create a new password after identity verification.
|
|
141
|
+
* This endpoint accepts a valid password reset token and a new password, then
|
|
142
|
+
* updates the user's password if the token is valid. It should typically be called
|
|
143
|
+
* after the token has been verified using the RESET_PASSWORD_VERIFY endpoint.
|
|
144
|
+
* The endpoint invalidates the reset token after successful password reset to
|
|
145
|
+
* prevent reuse.
|
|
146
|
+
*/
|
|
147
|
+
AuthEndpoint["RESET_PASSWORD"] = "reset-password";
|
|
148
|
+
/**
|
|
149
|
+
* Get current authenticated user info
|
|
150
|
+
*
|
|
151
|
+
* Returns the profile and relevant information for the currently authenticated user.
|
|
152
|
+
* This endpoint requires a valid JWT token and returns the user information associated
|
|
153
|
+
* with that token. It allows client applications to retrieve up-to-date user data
|
|
154
|
+
* for displaying profile information, checking permissions, or verifying authentication
|
|
155
|
+
* status.
|
|
156
|
+
*/
|
|
157
|
+
AuthEndpoint["ME"] = "me";
|
|
158
|
+
/**
|
|
159
|
+
* Update user's password
|
|
160
|
+
*
|
|
161
|
+
* Allows authenticated users to change their password (requires current password).
|
|
162
|
+
* This endpoint requires a valid JWT token and accepts both the current password
|
|
163
|
+
* (for verification) and the new password. It validates the current password against
|
|
164
|
+
* the stored credentials, and if valid, updates the user's password to the new value.
|
|
165
|
+
* This endpoint is used for routine password changes by authenticated users, not for
|
|
166
|
+
* password reset after forgetting credentials.
|
|
167
|
+
*/
|
|
168
|
+
AuthEndpoint["CHANGE_PASSWORD"] = "change-password";
|
|
169
|
+
/**
|
|
170
|
+
* End user session/invalidate tokens
|
|
171
|
+
*
|
|
172
|
+
* Handles user logout by invalidating active authentication tokens.
|
|
173
|
+
* This endpoint requires a valid JWT token and invalidates the current authentication
|
|
174
|
+
* session by blacklisting or removing the refresh token, clearing authentication cookies
|
|
175
|
+
* if they're being used, and performing any other cleanup necessary to terminate the
|
|
176
|
+
* user session securely. After calling this endpoint, client applications should also
|
|
177
|
+
* remove any locally stored tokens.
|
|
178
|
+
*/
|
|
179
|
+
AuthEndpoint["SIGN_OUT"] = "sign-out";
|
|
180
|
+
})(exports.AuthEndpoint || (exports.AuthEndpoint = {}));
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Authentication Error Response Codes Enum
|
|
184
|
+
*
|
|
185
|
+
* This enum defines all error response codes related to authentication operations.
|
|
186
|
+
* Each code represents a specific error condition that can occur during authentication
|
|
187
|
+
* processes. The naming convention includes HTTP status codes (e.g., 400, 401, 403)
|
|
188
|
+
* followed by a descriptive identifier.
|
|
189
|
+
*
|
|
190
|
+
* The codes are organized by HTTP status categories:
|
|
191
|
+
* - `400` series: Client errors (Bad Request, Unauthorized, Forbidden, Not Found, Conflict)
|
|
192
|
+
* - `500` series: Server errors (Internal Server Error, Not Implemented)
|
|
193
|
+
*
|
|
194
|
+
* Each prefix (`AUTH_` or `USER_`) indicates the domain of the error:
|
|
195
|
+
* - `AUTH_`: Authentication service errors
|
|
196
|
+
* - `USER_`: User management errors
|
|
197
|
+
*
|
|
198
|
+
* Enum Values:
|
|
199
|
+
* - `AUTH_400_EMAIL_ALREADY_VERIFIED`: Email already verified error.
|
|
200
|
+
* - `AUTH_400_REDIRECT_URL_REQUIRED`: Redirect URL required error.
|
|
201
|
+
* - `AUTH_401_CORS`: CORS error.
|
|
202
|
+
* - `AUTH_401_INVALID_USERNAME_PASSWORD`: Invalid username/password combination.
|
|
203
|
+
* - `AUTH_401_INVALID_EMAIL_PASSWORD`: Invalid email/password combination.
|
|
204
|
+
* - `AUTH_401_INVALID_PASSWORD`: Invalid password.
|
|
205
|
+
* - `AUTH_401_NOT_LOGGED_IN`: User not logged in.
|
|
206
|
+
* - `AUTH_401_NOT_LOCAL`: Non-local authentication attempt.
|
|
207
|
+
* - `AUTH_401_SOCIAL_SIGN_IN`: Social sign-in error.
|
|
208
|
+
* - `AUTH_401_EMAIL_NOT_VERIFIED`: Email not verified.
|
|
209
|
+
* - `AUTH_401_NOT_ACTIVE`: Account not active.
|
|
210
|
+
* - `AUTH_401_TOKEN_NOT_SET`: Authentication token not set.
|
|
211
|
+
* - `AUTH_401_REFRESH_TOKEN_NOT_SET`: Refresh token not set.
|
|
212
|
+
* - `AUTH_401_INVALID_TOKEN`: Invalid authentication token.
|
|
213
|
+
* - `AUTH_401_EXPIRED_TOKEN`: Expired authentication token.
|
|
214
|
+
* - `AUTH_401_INVALID_VERIFICATION_TOKEN`: Invalid email verification token.
|
|
215
|
+
* - `AUTH_401_INVALID_PASSWORD_RESET_TOKEN`: Invalid password reset token.
|
|
216
|
+
* - `AUTH_401_INVALID_REFRESH_TOKEN`: Invalid refresh token.
|
|
217
|
+
* - `AUTH_401_EXPIRED_REFRESH_TOKEN`: Expired refresh token.
|
|
218
|
+
* - `AUTH_401_EXPIRED_OR_INVALID_PASSWORD_RESET_TOKEN`: Expired or invalid password reset token.
|
|
219
|
+
* - `AUTH_401_UNKNOWN`: Unknown authentication error.
|
|
220
|
+
* - `AUTH_403_PENDING`: Pending account approval.
|
|
221
|
+
* - `AUTH_403_ACCOUNT_DISABLED`: Account disabled.
|
|
222
|
+
* - `AUTH_403_ROLE_FORBIDDEN`: Insufficient role.
|
|
223
|
+
* - `AUTH_403_PERMISSION_FORBIDDEN`: Insufficient role permissions.
|
|
224
|
+
* - `AUTH_404_EMAIL`: Email not found.
|
|
225
|
+
* - `AUTH_500_SIGN_UP`: Sign up error.
|
|
226
|
+
* - `AUTH_500_SOCIAL_SIGN_UP`: Social sign up error.
|
|
227
|
+
* - `AUTH_500_SIGN_IN`: Sign in error.
|
|
228
|
+
* - `AUTH_500_SOCIAL_SIGN_IN`: Social sign in error.
|
|
229
|
+
* - `AUTH_500_SOCIAL_SIGN_IN_CALLBACK`: Social sign in callback error.
|
|
230
|
+
* - `AUTH_500_SIGN_OUT`: Sign out error.
|
|
231
|
+
* - `AUTH_500_SEND_EMAIL_VERIFICATION`: Email verification sending error.
|
|
232
|
+
* - `AUTH_500_VERIFY_EMAIL`: Email verification error.
|
|
233
|
+
* - `AUTH_500_REQUEST_PASSWORD_RESET`: Password reset request error.
|
|
234
|
+
* - `AUTH_500_PASSWORD_RESET`: Password reset error.
|
|
235
|
+
* - `AUTH_500`: Generic authentication error.
|
|
236
|
+
* - `AUTH_501_NOT_IMPLEMENTED`: Feature not implemented.
|
|
237
|
+
* - `USER_400_EMPTY_EMAIL`: Empty email field.
|
|
238
|
+
* - `USER_400_EMPTY_FNAME`: Empty first name field.
|
|
239
|
+
* - `USER_400_EMPTY_LNAME`: Empty last name field.
|
|
240
|
+
* - `USER_400_EMPTY_UNAME`: Empty username field.
|
|
241
|
+
* - `USER_400_EMPTY_PASSWORD`: Empty password field.
|
|
242
|
+
* - `USER_400_INVALID_EMAIL`: Invalid email format.
|
|
243
|
+
* - `USER_400_NOT_EMPTY_UNAME`: Username should not be empty.
|
|
244
|
+
* - `USER_400_NOT_EMPTY_PASSWORD`: Password should not be empty.
|
|
245
|
+
* - `USER_400_NOT_EMPTY_SALT`: Salt should not be empty.
|
|
246
|
+
* - `USER_403_SIGN_UP`: Sign up forbidden.
|
|
247
|
+
* - `USER_404_ID`: User not found.
|
|
248
|
+
* - `USER_409_EXIST_UNAME`: Username already exists.
|
|
249
|
+
* - `USER_500_CREATE`: User creation error.
|
|
250
|
+
*/
|
|
251
|
+
exports.AuthErrorResponseCode = void 0;
|
|
252
|
+
(function (AuthErrorResponseCode) {
|
|
253
|
+
/**
|
|
254
|
+
* Email already verified error (400 Bad Request)
|
|
255
|
+
*
|
|
256
|
+
* Occurs when attempting to verify an email that has already been verified.
|
|
257
|
+
*/
|
|
258
|
+
AuthErrorResponseCode["AUTH_400_EMAIL_ALREADY_VERIFIED"] = "AUTH_400_EMAIL_ALREADY_VERIFIED";
|
|
259
|
+
/**
|
|
260
|
+
* Redirect URL required error (400 Bad Request)
|
|
261
|
+
*
|
|
262
|
+
* Occurs when a redirect URL is required for an operation but not provided.
|
|
263
|
+
*/
|
|
264
|
+
AuthErrorResponseCode["AUTH_400_REDIRECT_URL_REQUIRED"] = "AUTH_400_REDIRECT_URL_REQUIRED";
|
|
265
|
+
/**
|
|
266
|
+
* CORS error (401 Unauthorized)
|
|
267
|
+
*
|
|
268
|
+
* Occurs when a cross-origin request is not allowed due to security restrictions.
|
|
269
|
+
*/
|
|
270
|
+
AuthErrorResponseCode["AUTH_401_CORS"] = "AUTH_401_CORS";
|
|
271
|
+
/**
|
|
272
|
+
* Invalid username/password combination (401 Unauthorized)
|
|
273
|
+
*
|
|
274
|
+
* Occurs when authentication fails due to incorrect username and password combination.
|
|
275
|
+
*/
|
|
276
|
+
AuthErrorResponseCode["AUTH_401_INVALID_USERNAME_PASSWORD"] = "AUTH_401_INVALID_USERNAME_PASSWORD";
|
|
277
|
+
/**
|
|
278
|
+
* Invalid email/password combination (401 Unauthorized)
|
|
279
|
+
*
|
|
280
|
+
* Occurs when authentication fails due to incorrect email and password combination.
|
|
281
|
+
*/
|
|
282
|
+
AuthErrorResponseCode["AUTH_401_INVALID_EMAIL_PASSWORD"] = "AUTH_401_INVALID_EMAIL_PASSWORD";
|
|
283
|
+
/**
|
|
284
|
+
* Invalid password (401 Unauthorized)
|
|
285
|
+
*
|
|
286
|
+
* Occurs when authentication fails due to incorrect password.
|
|
287
|
+
*/
|
|
288
|
+
AuthErrorResponseCode["AUTH_401_INVALID_PASSWORD"] = "AUTH_401_INVALID_PASSWORD";
|
|
289
|
+
/**
|
|
290
|
+
* User not logged in (401 Unauthorized)
|
|
291
|
+
*
|
|
292
|
+
* Occurs when accessing a protected resource without authentication.
|
|
293
|
+
*/
|
|
294
|
+
AuthErrorResponseCode["AUTH_401_NOT_LOGGED_IN"] = "AUTH_401_NOT_LOGGED_IN";
|
|
295
|
+
/**
|
|
296
|
+
* Non-local authentication attempt (401 Unauthorized)
|
|
297
|
+
*
|
|
298
|
+
* Occurs when attempting to use local authentication methods for an account
|
|
299
|
+
* that was created using social authentication.
|
|
300
|
+
*/
|
|
301
|
+
AuthErrorResponseCode["AUTH_401_NOT_LOCAL"] = "AUTH_401_NOT_LOCAL";
|
|
302
|
+
/**
|
|
303
|
+
* Social sign-in error (401 Unauthorized)
|
|
304
|
+
*
|
|
305
|
+
* Occurs when there is an issue with social authentication process.
|
|
306
|
+
*/
|
|
307
|
+
AuthErrorResponseCode["AUTH_401_SOCIAL_SIGN_IN"] = "AUTH_401_SOCIAL_SIGN_IN";
|
|
308
|
+
/**
|
|
309
|
+
* Email not verified (401 Unauthorized)
|
|
310
|
+
*
|
|
311
|
+
* Occurs when attempting to access resources that require email verification
|
|
312
|
+
* before the user has verified their email address.
|
|
313
|
+
*/
|
|
314
|
+
AuthErrorResponseCode["AUTH_401_EMAIL_NOT_VERIFIED"] = "AUTH_401_EMAIL_NOT_VERIFIED";
|
|
315
|
+
/**
|
|
316
|
+
* Account not active (401 Unauthorized)
|
|
317
|
+
*
|
|
318
|
+
* Occurs when attempting to authenticate with an inactive account.
|
|
319
|
+
*/
|
|
320
|
+
AuthErrorResponseCode["AUTH_401_NOT_ACTIVE"] = "AUTH_401_NOT_ACTIVE";
|
|
321
|
+
/**
|
|
322
|
+
* Authentication token not set (401 Unauthorized)
|
|
323
|
+
*
|
|
324
|
+
* Occurs when no authentication token is provided for a protected resource.
|
|
325
|
+
*/
|
|
326
|
+
AuthErrorResponseCode["AUTH_401_TOKEN_NOT_SET"] = "AUTH_401_TOKEN_NOT_SET";
|
|
327
|
+
/**
|
|
328
|
+
* Refresh token not set (401 Unauthorized)
|
|
329
|
+
*
|
|
330
|
+
* Occurs when attempting to refresh an access token without providing a refresh token.
|
|
331
|
+
*/
|
|
332
|
+
AuthErrorResponseCode["AUTH_401_REFRESH_TOKEN_NOT_SET"] = "AUTH_401_REFRESH_TOKEN_NOT_SET";
|
|
333
|
+
/**
|
|
334
|
+
* Invalid authentication token (401 Unauthorized)
|
|
335
|
+
*
|
|
336
|
+
* Occurs when the provided authentication token is malformed or invalid.
|
|
337
|
+
*/
|
|
338
|
+
AuthErrorResponseCode["AUTH_401_INVALID_TOKEN"] = "AUTH_401_INVALID_TOKEN";
|
|
339
|
+
/**
|
|
340
|
+
* Expired authentication token (401 Unauthorized)
|
|
341
|
+
*
|
|
342
|
+
* Occurs when the provided authentication token has expired.
|
|
343
|
+
*/
|
|
344
|
+
AuthErrorResponseCode["AUTH_401_EXPIRED_TOKEN"] = "AUTH_401_EXPIRED_TOKEN";
|
|
345
|
+
/**
|
|
346
|
+
* Invalid email verification token (401 Unauthorized)
|
|
347
|
+
*
|
|
348
|
+
* Occurs when attempting to verify an email with an invalid token.
|
|
349
|
+
*/
|
|
350
|
+
AuthErrorResponseCode["AUTH_401_INVALID_VERIFICATION_TOKEN"] = "AUTH_401_INVALID_VERIFICATION_TOKEN";
|
|
351
|
+
/**
|
|
352
|
+
* Invalid password reset token (401 Unauthorized)
|
|
353
|
+
*
|
|
354
|
+
* Occurs when attempting to reset a password with an invalid token.
|
|
355
|
+
*/
|
|
356
|
+
AuthErrorResponseCode["AUTH_401_INVALID_PASSWORD_RESET_TOKEN"] = "AUTH_401_INVALID_PASSWORD_RESET_TOKEN";
|
|
357
|
+
/**
|
|
358
|
+
* Invalid refresh token (401 Unauthorized)
|
|
359
|
+
*
|
|
360
|
+
* Occurs when attempting to refresh an access token with an invalid refresh token.
|
|
361
|
+
*/
|
|
362
|
+
AuthErrorResponseCode["AUTH_401_INVALID_REFRESH_TOKEN"] = "AUTH_401_INVALID_REFRESH_TOKEN";
|
|
363
|
+
/**
|
|
364
|
+
* Expired refresh token (401 Unauthorized)
|
|
365
|
+
*
|
|
366
|
+
* Occurs when attempting to refresh an access token with an expired refresh token.
|
|
367
|
+
*/
|
|
368
|
+
AuthErrorResponseCode["AUTH_401_EXPIRED_REFRESH_TOKEN"] = "AUTH_401_EXPIRED_REFRESH_TOKEN";
|
|
369
|
+
/**
|
|
370
|
+
* Expired or invalid password reset token (401 Unauthorized)
|
|
371
|
+
*
|
|
372
|
+
* Occurs when attempting to reset a password with a token that is either invalid or expired.
|
|
373
|
+
*/
|
|
374
|
+
AuthErrorResponseCode["AUTH_401_EXPIRED_OR_INVALID_PASSWORD_RESET_TOKEN"] = "AUTH_401_EXPIRED_OR_INVALID_PASSWORD_RESET_TOKEN";
|
|
375
|
+
/**
|
|
376
|
+
* Unknown authentication error (401 Unauthorized)
|
|
377
|
+
*
|
|
378
|
+
* Generic authentication error when the specific cause cannot be determined.
|
|
379
|
+
*/
|
|
380
|
+
AuthErrorResponseCode["AUTH_401_UNKNOWN"] = "AUTH_401_UNKNOWN";
|
|
381
|
+
/**
|
|
382
|
+
* Pending account approval (403 Forbidden)
|
|
383
|
+
*
|
|
384
|
+
* Occurs when attempting to access resources with an account that is still pending approval.
|
|
385
|
+
*/
|
|
386
|
+
AuthErrorResponseCode["AUTH_403_PENDING"] = "AUTH_403_PENDING";
|
|
387
|
+
/**
|
|
388
|
+
* Account disabled (403 Forbidden)
|
|
389
|
+
*
|
|
390
|
+
* Occurs when attempting to authenticate with a disabled account.
|
|
391
|
+
*/
|
|
392
|
+
AuthErrorResponseCode["AUTH_403_ACCOUNT_DISABLED"] = "AUTH_403_ACCOUNT_DISABLED";
|
|
393
|
+
/**
|
|
394
|
+
* Insufficient role (403 Forbidden)
|
|
395
|
+
*
|
|
396
|
+
* Occurs when a user attempts to access a resource that requires higher privileges.
|
|
397
|
+
*/
|
|
398
|
+
AuthErrorResponseCode["AUTH_403_ROLE_FORBIDDEN"] = "AUTH_403_ROLE_FORBIDDEN";
|
|
399
|
+
/**
|
|
400
|
+
* Insufficient role permissions (403 Forbidden)
|
|
401
|
+
*
|
|
402
|
+
* Occurs when a user attempts to access a resource that requires higher privileges.
|
|
403
|
+
*/
|
|
404
|
+
AuthErrorResponseCode["AUTH_403_PERMISSION_FORBIDDEN"] = "AUTH_403_PERMISSION_FORBIDDEN";
|
|
405
|
+
AuthErrorResponseCode["AUTH_403_SUB_DOMAIN_NOT_ALLOWED"] = "AUTH_403_SUB_DOMAIN_NOT_ALLOWED";
|
|
406
|
+
/**
|
|
407
|
+
* Email not found (404 Not Found)
|
|
408
|
+
*
|
|
409
|
+
* Occurs when attempting operations on an email address that doesn't exist in the system.
|
|
410
|
+
*/
|
|
411
|
+
AuthErrorResponseCode["AUTH_404_EMAIL"] = "AUTH_404_EMAIL";
|
|
412
|
+
/**
|
|
413
|
+
* Sign up error (500 Internal Server Error)
|
|
414
|
+
*
|
|
415
|
+
* Occurs when there is a server-side error during the registration process.
|
|
416
|
+
*/
|
|
417
|
+
AuthErrorResponseCode["AUTH_500_SIGN_UP"] = "AUTH_500_SIGN_UP";
|
|
418
|
+
/**
|
|
419
|
+
* Social sign up error (500 Internal Server Error)
|
|
420
|
+
*
|
|
421
|
+
* Occurs when there is a server-side error during social registration.
|
|
422
|
+
*/
|
|
423
|
+
AuthErrorResponseCode["AUTH_500_SOCIAL_SIGN_UP"] = "AUTH_500_SOCIAL_SIGN_UP";
|
|
424
|
+
/**
|
|
425
|
+
* Sign in error (500 Internal Server Error)
|
|
426
|
+
*
|
|
427
|
+
* Occurs when there is a server-side error during the authentication process.
|
|
428
|
+
*/
|
|
429
|
+
AuthErrorResponseCode["AUTH_500_SIGN_IN"] = "AUTH_500_SIGN_IN";
|
|
430
|
+
/**
|
|
431
|
+
* Social sign in error (500 Internal Server Error)
|
|
432
|
+
*
|
|
433
|
+
* Occurs when there is a server-side error during social authentication.
|
|
434
|
+
*/
|
|
435
|
+
AuthErrorResponseCode["AUTH_500_SOCIAL_SIGN_IN"] = "AUTH_500_SOCIAL_SIGN_IN";
|
|
436
|
+
/**
|
|
437
|
+
* Social sign in callback error (500 Internal Server Error)
|
|
438
|
+
*
|
|
439
|
+
* Occurs when there is a server-side error processing the social authentication callback.
|
|
440
|
+
*/
|
|
441
|
+
AuthErrorResponseCode["AUTH_500_SOCIAL_SIGN_IN_CALLBACK"] = "AUTH_500_SOCIAL_SIGN_IN_CALLBACK";
|
|
442
|
+
/**
|
|
443
|
+
* Sign out error (500 Internal Server Error)
|
|
444
|
+
*
|
|
445
|
+
* Occurs when there is a server-side error during the sign-out process,
|
|
446
|
+
* such as failure to clear sessions, tokens, or other authentication data.
|
|
447
|
+
*/
|
|
448
|
+
AuthErrorResponseCode["AUTH_500_SIGN_OUT"] = "AUTH_500_SIGN_OUT";
|
|
449
|
+
/**
|
|
450
|
+
* Email verification sending error (500 Internal Server Error)
|
|
451
|
+
*
|
|
452
|
+
* Occurs when there is a server-side error sending the verification email.
|
|
453
|
+
*/
|
|
454
|
+
AuthErrorResponseCode["AUTH_500_SEND_EMAIL_VERIFICATION"] = "AUTH_500_SEND_EMAIL_VERIFICATION";
|
|
455
|
+
/**
|
|
456
|
+
* Email verification error (500 Internal Server Error)
|
|
457
|
+
*
|
|
458
|
+
* Occurs when there is a server-side error processing the email verification.
|
|
459
|
+
*/
|
|
460
|
+
AuthErrorResponseCode["AUTH_500_VERIFY_EMAIL"] = "AUTH_500_VERIFY_EMAIL";
|
|
461
|
+
/**
|
|
462
|
+
* Password reset request error (500 Internal Server Error)
|
|
463
|
+
*
|
|
464
|
+
* Occurs when there is a server-side error processing a password reset request.
|
|
465
|
+
*/
|
|
466
|
+
AuthErrorResponseCode["AUTH_500_REQUEST_PASSWORD_RESET"] = "AUTH_500_REQUEST_PASSWORD_RESET";
|
|
467
|
+
/**
|
|
468
|
+
* Password reset error (500 Internal Server Error)
|
|
469
|
+
*
|
|
470
|
+
* Occurs when there is a server-side error processing a password reset.
|
|
471
|
+
*/
|
|
472
|
+
AuthErrorResponseCode["AUTH_500_PASSWORD_RESET"] = "AUTH_500_PASSWORD_RESET";
|
|
473
|
+
/**
|
|
474
|
+
* Generic authentication error (500 Internal Server Error)
|
|
475
|
+
*
|
|
476
|
+
* Generic server-side error in the authentication service.
|
|
477
|
+
*/
|
|
478
|
+
AuthErrorResponseCode["AUTH_500"] = "AUTH_500";
|
|
479
|
+
/**
|
|
480
|
+
* Feature not implemented (501 Not Implemented)
|
|
481
|
+
*
|
|
482
|
+
* Occurs when attempting to use an authentication feature that is not yet implemented.
|
|
483
|
+
*/
|
|
484
|
+
AuthErrorResponseCode["AUTH_501_NOT_IMPLEMENTED"] = "AUTH_501_NOT_IMPLEMENTED";
|
|
485
|
+
/**
|
|
486
|
+
* Empty email field (400 Bad Request)
|
|
487
|
+
*
|
|
488
|
+
* Occurs when the email field is required but not provided.
|
|
489
|
+
*/
|
|
490
|
+
AuthErrorResponseCode["USER_400_EMPTY_EMAIL"] = "USER_400_EMPTY_EMAIL";
|
|
491
|
+
/**
|
|
492
|
+
* Empty first name field (400 Bad Request)
|
|
493
|
+
*
|
|
494
|
+
* Occurs when the first name field is required but not provided.
|
|
495
|
+
*/
|
|
496
|
+
AuthErrorResponseCode["USER_400_EMPTY_FNAME"] = "USER_400_EMPTY_FNAME";
|
|
497
|
+
/**
|
|
498
|
+
* Empty last name field (400 Bad Request)
|
|
499
|
+
*
|
|
500
|
+
* Occurs when the last name field is required but not provided.
|
|
501
|
+
*/
|
|
502
|
+
AuthErrorResponseCode["USER_400_EMPTY_LNAME"] = "USER_400_EMPTY_LNAME";
|
|
503
|
+
/**
|
|
504
|
+
* Empty username field (400 Bad Request)
|
|
505
|
+
*
|
|
506
|
+
* Occurs when the username field is required but not provided.
|
|
507
|
+
*/
|
|
508
|
+
AuthErrorResponseCode["USER_400_EMPTY_UNAME"] = "USER_400_EMPTY_UNAME";
|
|
509
|
+
/**
|
|
510
|
+
* Empty password field (400 Bad Request)
|
|
511
|
+
*
|
|
512
|
+
* Occurs when the password field is required but not provided.
|
|
513
|
+
*/
|
|
514
|
+
AuthErrorResponseCode["USER_400_EMPTY_PASSWORD"] = "USER_400_EMPTY_PASSWORD";
|
|
515
|
+
/**
|
|
516
|
+
* Invalid email format (400 Bad Request)
|
|
517
|
+
*
|
|
518
|
+
* Occurs when the provided email address doesn't match a valid email format.
|
|
519
|
+
*/
|
|
520
|
+
AuthErrorResponseCode["USER_400_INVALID_EMAIL"] = "USER_400_INVALID_EMAIL";
|
|
521
|
+
/**
|
|
522
|
+
* Username should not be empty (400 Bad Request)
|
|
523
|
+
*
|
|
524
|
+
* Validation error when username is expected to have a value.
|
|
525
|
+
*/
|
|
526
|
+
AuthErrorResponseCode["USER_400_NOT_EMPTY_UNAME"] = "USER_400_NOT_EMPTY_UNAME";
|
|
527
|
+
/**
|
|
528
|
+
* Password should not be empty (400 Bad Request)
|
|
529
|
+
*
|
|
530
|
+
* Validation error when password is expected to have a value.
|
|
531
|
+
*/
|
|
532
|
+
AuthErrorResponseCode["USER_400_NOT_EMPTY_PASSWORD"] = "USER_400_NOT_EMPTY_PASSWORD";
|
|
533
|
+
/**
|
|
534
|
+
* Salt should not be empty (400 Bad Request)
|
|
535
|
+
*
|
|
536
|
+
* Validation error when password salt is expected to have a value.
|
|
537
|
+
*/
|
|
538
|
+
AuthErrorResponseCode["USER_400_NOT_EMPTY_SALT"] = "USER_400_NOT_EMPTY_SALT";
|
|
539
|
+
/**
|
|
540
|
+
* Sign up forbidden (403 Forbidden)
|
|
541
|
+
*
|
|
542
|
+
* Occurs when registration is currently not allowed or restricted.
|
|
543
|
+
*/
|
|
544
|
+
AuthErrorResponseCode["USER_403_SIGN_UP"] = "USER_403_SIGN_UP";
|
|
545
|
+
/**
|
|
546
|
+
* User not found (404 Not Found)
|
|
547
|
+
*
|
|
548
|
+
* Occurs when attempting operations on a user that doesn't exist.
|
|
549
|
+
*/
|
|
550
|
+
AuthErrorResponseCode["USER_404_ID"] = "USER_404_ID";
|
|
551
|
+
/**
|
|
552
|
+
* Username already exists (409 Conflict)
|
|
553
|
+
*
|
|
554
|
+
* Occurs when attempting to create a user with a username that is already taken.
|
|
555
|
+
*/
|
|
556
|
+
AuthErrorResponseCode["USER_409_EXIST_UNAME"] = "USER_409_EXIST_UNAME";
|
|
557
|
+
/**
|
|
558
|
+
* User creation error (500 Internal Server Error)
|
|
559
|
+
*
|
|
560
|
+
* Occurs when there is a server-side error creating a new user account.
|
|
561
|
+
*/
|
|
562
|
+
AuthErrorResponseCode["USER_500_CREATE"] = "USER_500_CREATE";
|
|
563
|
+
})(exports.AuthErrorResponseCode || (exports.AuthErrorResponseCode = {}));
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Enum representing authentication fields used for user identification.
|
|
567
|
+
*
|
|
568
|
+
* This enum is used to specify the type of identifier required
|
|
569
|
+
* for authentication processes. Each value represents a different
|
|
570
|
+
* approach to identifying users during authentication.
|
|
571
|
+
*
|
|
572
|
+
* Enum Values:
|
|
573
|
+
* - `USERNAME`: Authentication using the user's unique username.
|
|
574
|
+
* - `EMAIL`: Authentication using the user's email address.
|
|
575
|
+
* - `BOTH`: Authentication using either username or email address.
|
|
576
|
+
*/
|
|
577
|
+
exports.AuthField = void 0;
|
|
578
|
+
(function (AuthField) {
|
|
579
|
+
/**
|
|
580
|
+
* Username-based authentication
|
|
581
|
+
*
|
|
582
|
+
* Users authenticate using their unique username.
|
|
583
|
+
* This is useful for applications where email addresses are not required
|
|
584
|
+
* or where users prefer to sign in with a chosen identifier.
|
|
585
|
+
*/
|
|
586
|
+
AuthField["USERNAME"] = "username";
|
|
587
|
+
/**
|
|
588
|
+
* Email-based authentication
|
|
589
|
+
*
|
|
590
|
+
* Users authenticate using their email address.
|
|
591
|
+
* This is the most common approach as email addresses are unique
|
|
592
|
+
* and provide a way to contact users for account verification and recovery.
|
|
593
|
+
*/
|
|
594
|
+
AuthField["EMAIL"] = "email";
|
|
595
|
+
/**
|
|
596
|
+
* Combined username/email authentication
|
|
597
|
+
*
|
|
598
|
+
* Users can authenticate using either their username or email address.
|
|
599
|
+
* This provides flexibility for users to sign in with whichever identifier they remember.
|
|
600
|
+
* Implementation requires checking both fields when authenticating.
|
|
601
|
+
*/
|
|
602
|
+
AuthField["BOTH"] = "both";
|
|
603
|
+
})(exports.AuthField || (exports.AuthField = {}));
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Enumeration representing the supported authentication methods.
|
|
607
|
+
*
|
|
608
|
+
* This enum provides two authentication strategies:
|
|
609
|
+
* - `COOKIE`: Utilizes cookies for storing and transmitting authentication tokens.
|
|
610
|
+
* - `JWT`: Employs JSON Web Tokens for authentication, typically passed via headers.
|
|
611
|
+
*
|
|
612
|
+
* Use this enum to specify the desired authentication method in your application.
|
|
613
|
+
*/
|
|
614
|
+
exports.AuthMethod = void 0;
|
|
615
|
+
(function (AuthMethod) {
|
|
616
|
+
/**
|
|
617
|
+
* Cookie-based authentication
|
|
618
|
+
*
|
|
619
|
+
* Authentication tokens are stored in HTTP cookies and automatically included in requests.
|
|
620
|
+
* This method provides better security against XSS attacks but requires proper cookie configuration.
|
|
621
|
+
*/
|
|
622
|
+
AuthMethod["COOKIE"] = "cookie";
|
|
623
|
+
/**
|
|
624
|
+
* JWT-based authentication
|
|
625
|
+
*
|
|
626
|
+
* Authentication tokens are typically stored client-side (localStorage/sessionStorage) and
|
|
627
|
+
* manually included in request headers. This method provides more flexibility but requires
|
|
628
|
+
* careful implementation to prevent token theft via XSS.
|
|
629
|
+
*/
|
|
630
|
+
AuthMethod["JWT"] = "jwt";
|
|
631
|
+
})(exports.AuthMethod || (exports.AuthMethod = {}));
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Authentication Success Response Codes Enum
|
|
635
|
+
*
|
|
636
|
+
* This enum defines success response codes specific to authentication operations.
|
|
637
|
+
* Each code represents a specific successful outcome from an authentication-related action.
|
|
638
|
+
* The naming convention includes HTTP status codes (e.g., 200, 201) for clarity.
|
|
639
|
+
*
|
|
640
|
+
* Enum Values:
|
|
641
|
+
* - `AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY`: Account created but requires email verification.
|
|
642
|
+
* - `AUTH_201_ACCOUNT_CREATED`: Account successfully created without verification requirement.
|
|
643
|
+
* - `AUTH_201_EMAIL_VERIFIED`: Email address successfully verified.
|
|
644
|
+
* - `AUTH_200_EMAIL_VERIFICATION_SENT`: Email verification message sent successfully.
|
|
645
|
+
* - `AUTH_200_PASSWORD_RESET_EMAIL_SENT`: Password reset email sent successfully.
|
|
646
|
+
* - `AUTH_200_PASSWORD_RESET_TOKEN_VALID`: Password reset token validated successfully.
|
|
647
|
+
* - `AUTH_200_PASSWORD_RESET_SUCCESS`: Password reset completed successfully.
|
|
648
|
+
* - `AUTH_200_SIGNED_OUT`: User successfully signed out of the system.
|
|
649
|
+
*/
|
|
650
|
+
exports.AuthSuccessResponseCode = void 0;
|
|
651
|
+
(function (AuthSuccessResponseCode) {
|
|
652
|
+
/**
|
|
653
|
+
* Account created but requires email verification
|
|
654
|
+
*
|
|
655
|
+
* Indicates a new user account was successfully created, but the user
|
|
656
|
+
* must verify their email address before they can fully access the system.
|
|
657
|
+
*/
|
|
658
|
+
AuthSuccessResponseCode["AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY"] = "AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY";
|
|
659
|
+
/**
|
|
660
|
+
* Account successfully created without verification requirement
|
|
661
|
+
*
|
|
662
|
+
* Indicates a new user account was successfully created and is immediately
|
|
663
|
+
* active without requiring additional verification steps.
|
|
664
|
+
*/
|
|
665
|
+
AuthSuccessResponseCode["AUTH_201_ACCOUNT_CREATED"] = "AUTH_201_ACCOUNT_CREATED";
|
|
666
|
+
/**
|
|
667
|
+
* Email address successfully verified
|
|
668
|
+
*
|
|
669
|
+
* Indicates that a user's email address has been successfully verified,
|
|
670
|
+
* enabling full access to account features that require verification.
|
|
671
|
+
*/
|
|
672
|
+
AuthSuccessResponseCode["AUTH_201_EMAIL_VERIFIED"] = "AUTH_201_EMAIL_VERIFIED";
|
|
673
|
+
/**
|
|
674
|
+
* Email verification message sent successfully
|
|
675
|
+
*
|
|
676
|
+
* Indicates that an email containing verification instructions has been
|
|
677
|
+
* successfully sent to the user's email address.
|
|
678
|
+
*/
|
|
679
|
+
AuthSuccessResponseCode["AUTH_200_EMAIL_VERIFICATION_SENT"] = "AUTH_200_EMAIL_VERIFICATION_SENT";
|
|
680
|
+
/**
|
|
681
|
+
* Password reset email sent successfully
|
|
682
|
+
*
|
|
683
|
+
* Indicates that an email containing password reset instructions has been
|
|
684
|
+
* successfully sent to the user's email address.
|
|
685
|
+
*/
|
|
686
|
+
AuthSuccessResponseCode["AUTH_200_PASSWORD_RESET_EMAIL_SENT"] = "AUTH_200_PASSWORD_RESET_EMAIL_SENT";
|
|
687
|
+
/**
|
|
688
|
+
* Password reset token validated successfully
|
|
689
|
+
*
|
|
690
|
+
* Indicates that a password reset token provided by the user has been
|
|
691
|
+
* verified and is valid for proceeding with the password reset process.
|
|
692
|
+
*/
|
|
693
|
+
AuthSuccessResponseCode["AUTH_200_PASSWORD_RESET_TOKEN_VALID"] = "AUTH_200_PASSWORD_RESET_TOKEN_VALID";
|
|
694
|
+
/**
|
|
695
|
+
* Password reset completed successfully
|
|
696
|
+
*
|
|
697
|
+
* Indicates that a user's password has been successfully reset and updated
|
|
698
|
+
* in the system. The user can now login with their new password.
|
|
699
|
+
*/
|
|
700
|
+
AuthSuccessResponseCode["AUTH_200_PASSWORD_RESET_SUCCESS"] = "AUTH_200_PASSWORD_RESET_SUCCESS";
|
|
701
|
+
/**
|
|
702
|
+
* User signed out successfully
|
|
703
|
+
*
|
|
704
|
+
* Indicates that a user has been successfully signed out of the system,
|
|
705
|
+
* their session has been terminated, and authentication tokens have been
|
|
706
|
+
* invalidated. Any authentication cookies would also be cleared.
|
|
707
|
+
*/
|
|
708
|
+
AuthSuccessResponseCode["AUTH_200_SIGNED_OUT"] = "AUTH_200_SIGNED_OUT";
|
|
709
|
+
})(exports.AuthSuccessResponseCode || (exports.AuthSuccessResponseCode = {}));
|
|
710
|
+
|
|
711
|
+
// noinspection JSUnusedGlobalSymbols
|
|
712
|
+
/**
|
|
713
|
+
* Enum representing the different authentication strategies available.
|
|
714
|
+
*
|
|
715
|
+
* This enum is used to specify the type of authentication mechanism
|
|
716
|
+
* employed within the application. Each strategy corresponds to a
|
|
717
|
+
* distinct method of authenticating users.
|
|
718
|
+
*
|
|
719
|
+
* Enum Values:
|
|
720
|
+
* - `LOCAL`: Authentication using local credentials (e.g., username and password).
|
|
721
|
+
* - `JWT`: Authentication using JSON Web Tokens.
|
|
722
|
+
* - `GOOGLE`: Authentication via Google OAuth.
|
|
723
|
+
* - `FACEBOOK`: Authentication via Facebook OAuth.
|
|
724
|
+
*/
|
|
725
|
+
exports.AuthStrategy = void 0;
|
|
726
|
+
(function (AuthStrategy) {
|
|
727
|
+
/**
|
|
728
|
+
* Local authentication strategy
|
|
729
|
+
*
|
|
730
|
+
* Authenticates users using username/email and password stored in the application's database.
|
|
731
|
+
* This is the most basic form of authentication that doesn't rely on third-party services.
|
|
732
|
+
*/
|
|
733
|
+
AuthStrategy["LOCAL"] = "local";
|
|
734
|
+
/**
|
|
735
|
+
* JWT authentication strategy
|
|
736
|
+
*
|
|
737
|
+
* Uses JSON Web Tokens for authentication and authorization. Tokens contain encoded user
|
|
738
|
+
* information and are validated on the server side. Typically used for stateless authentication
|
|
739
|
+
* in RESTful APIs.
|
|
740
|
+
*/
|
|
741
|
+
AuthStrategy["JWT"] = "jwt";
|
|
742
|
+
/**
|
|
743
|
+
* Google OAuth authentication strategy
|
|
744
|
+
*
|
|
745
|
+
* Allows users to sign in using their Google accounts. This strategy delegates the authentication
|
|
746
|
+
* process to Google's identity service and receives user information upon successful authentication.
|
|
747
|
+
*/
|
|
748
|
+
AuthStrategy["GOOGLE"] = "google";
|
|
749
|
+
/**
|
|
750
|
+
* Facebook OAuth authentication strategy
|
|
751
|
+
*
|
|
752
|
+
* Enables authentication through Facebook accounts. Similar to Google OAuth, this strategy
|
|
753
|
+
* relies on Facebook's identity provider to authenticate users and return their profile information.
|
|
754
|
+
*/
|
|
755
|
+
AuthStrategy["FACEBOOK"] = "facebook";
|
|
756
|
+
})(exports.AuthStrategy || (exports.AuthStrategy = {}));
|
|
757
|
+
|
|
758
|
+
// noinspection JSUnusedGlobalSymbols
|
|
759
|
+
/**
|
|
760
|
+
* Sign Up Type Enum
|
|
761
|
+
*
|
|
762
|
+
* This enum represents the different methods by which a user can sign up in the application.
|
|
763
|
+
* It is used to track how a user account was created and to apply different business rules
|
|
764
|
+
* based on the sign up method (e.g., email verification requirements).
|
|
765
|
+
*/
|
|
766
|
+
exports.AuthProvider = void 0;
|
|
767
|
+
(function (AuthProvider) {
|
|
768
|
+
/**
|
|
769
|
+
* Local Sign Up with email and password
|
|
770
|
+
*
|
|
771
|
+
* Users who sign up directly on the application with an email and password.
|
|
772
|
+
* These users typically need to verify their email address.
|
|
773
|
+
*/
|
|
774
|
+
AuthProvider["LOCAL"] = "local";
|
|
775
|
+
/**
|
|
776
|
+
* Google OAuth Sign Up
|
|
777
|
+
*
|
|
778
|
+
* Users who sign up by authenticating through their Google account.
|
|
779
|
+
* These users typically have pre-verified email addresses.
|
|
780
|
+
*/
|
|
781
|
+
AuthProvider["GOOGLE"] = "google";
|
|
782
|
+
/**
|
|
783
|
+
* Facebook OAuth Sign Up
|
|
784
|
+
*
|
|
785
|
+
* Users who sign up by authenticating through their Facebook account.
|
|
786
|
+
* These users typically have pre-verified email addresses.
|
|
787
|
+
*/
|
|
788
|
+
AuthProvider["FACEBOOK"] = "facebook";
|
|
789
|
+
})(exports.AuthProvider || (exports.AuthProvider = {}));
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Collection of standardized authentication error responses
|
|
793
|
+
*
|
|
794
|
+
* This constant maps each authentication error code to its corresponding
|
|
795
|
+
* standardized error response object. The responses include HTTP status codes,
|
|
796
|
+
* error codes, and human-readable messages.
|
|
797
|
+
*
|
|
798
|
+
* Key features:
|
|
799
|
+
* - Standardized error response format following the ErrorResponse interface
|
|
800
|
+
* - Comprehensive coverage of authentication error scenarios
|
|
801
|
+
* - Organized by HTTP status code (400, 401, 403, 404, 500, 501)
|
|
802
|
+
* - Includes both authentication service errors (AUTH_) and user management errors (USER_)
|
|
803
|
+
* - Human-readable error messages suitable for end-users
|
|
804
|
+
*
|
|
805
|
+
* The error responses are organized into categories based on HTTP status codes:
|
|
806
|
+
* - 400 Bad Request: Client errors related to invalid input or request format
|
|
807
|
+
* - 401 Unauthorized: Authentication failures and token-related errors
|
|
808
|
+
* - 403 Forbidden: Access denied due to insufficient permissions
|
|
809
|
+
* - 404 Not Found: Resource not found errors
|
|
810
|
+
* - 500 Internal Server Error: Server-side errors during authentication operations
|
|
811
|
+
* - 501 Not Implemented: Features that are not yet implemented
|
|
812
|
+
*
|
|
813
|
+
* The object is organized by error code, with each code mapping to an ErrorResponse
|
|
814
|
+
* object that follows the standardized format defined by the ErrorResponse interface.
|
|
815
|
+
*
|
|
816
|
+
* @example
|
|
817
|
+
* ```typescript
|
|
818
|
+
* // Using an error response in an exception
|
|
819
|
+
* import { AuthErrors } from '@hichchi/nest-connector/auth';
|
|
820
|
+
* import { UnauthorizedException } from '@nestjs/common';
|
|
821
|
+
*
|
|
822
|
+
* // In an authentication service
|
|
823
|
+
* if (!user.isEmailVerified) {
|
|
824
|
+
* throw new UnauthorizedException(AuthErrors.AUTH_401_EMAIL_NOT_VERIFIED);
|
|
825
|
+
* }
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```typescript
|
|
830
|
+
* // Using an error response in a custom exception filter
|
|
831
|
+
* import { AuthErrors } from '@hichchi/nest-connector/auth';
|
|
832
|
+
* import { ExceptionFilter, Catch, ArgumentsHost, UnauthorizedException } from '@nestjs/common';
|
|
833
|
+
*
|
|
834
|
+
* @Catch(UnauthorizedException)
|
|
835
|
+
* export class AuthExceptionFilter implements ExceptionFilter {
|
|
836
|
+
* catch(exception: UnauthorizedException, host: ArgumentsHost) {
|
|
837
|
+
* const response = host.switchToHttp().getResponse();
|
|
838
|
+
* const status = exception.getStatus();
|
|
839
|
+
*
|
|
840
|
+
* // Use a standard error response
|
|
841
|
+
* response
|
|
842
|
+
* .status(status)
|
|
843
|
+
* .json(AuthErrors.AUTH_401_NOT_LOGGED_IN);
|
|
844
|
+
* }
|
|
845
|
+
* }
|
|
846
|
+
* ```
|
|
847
|
+
*
|
|
848
|
+
* @type {{ [key in AuthErrorResponseCode]: ErrorResponse }}
|
|
849
|
+
*
|
|
850
|
+
* @see {@link AuthErrorResponseCode} For all available error codes
|
|
851
|
+
* @see {@link ErrorResponse} For the structure of error response objects
|
|
852
|
+
* @see {@link AuthSuccessResponses} Complementary success responses for authentication
|
|
853
|
+
*/
|
|
854
|
+
const AuthErrors = {
|
|
855
|
+
[exports.AuthErrorResponseCode.AUTH_400_EMAIL_ALREADY_VERIFIED]: {
|
|
856
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
857
|
+
code: exports.AuthErrorResponseCode.AUTH_400_EMAIL_ALREADY_VERIFIED,
|
|
858
|
+
message: "Email already verified!"
|
|
859
|
+
},
|
|
860
|
+
[exports.AuthErrorResponseCode.AUTH_400_REDIRECT_URL_REQUIRED]: {
|
|
861
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
862
|
+
code: exports.AuthErrorResponseCode.AUTH_400_REDIRECT_URL_REQUIRED,
|
|
863
|
+
message: "Redirect URL is required",
|
|
864
|
+
description: "Redirect URL is required"
|
|
865
|
+
},
|
|
866
|
+
[exports.AuthErrorResponseCode.AUTH_401_CORS]: {
|
|
867
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
868
|
+
code: exports.AuthErrorResponseCode.AUTH_401_CORS,
|
|
869
|
+
message: "Access blocked by CORS!"
|
|
870
|
+
},
|
|
871
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_USERNAME_PASSWORD]: {
|
|
872
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
873
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_USERNAME_PASSWORD,
|
|
874
|
+
message: "Invalid username or password!"
|
|
875
|
+
},
|
|
876
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_EMAIL_PASSWORD]: {
|
|
877
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
878
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_EMAIL_PASSWORD,
|
|
879
|
+
message: "Invalid e-mail or password!"
|
|
880
|
+
},
|
|
881
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_PASSWORD]: {
|
|
882
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
883
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_PASSWORD,
|
|
884
|
+
message: "Invalid password!"
|
|
885
|
+
},
|
|
886
|
+
[exports.AuthErrorResponseCode.AUTH_401_NOT_LOGGED_IN]: {
|
|
887
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
888
|
+
code: exports.AuthErrorResponseCode.AUTH_401_NOT_LOGGED_IN,
|
|
889
|
+
message: "User must be logged in to access this resource!"
|
|
890
|
+
},
|
|
891
|
+
[exports.AuthErrorResponseCode.AUTH_401_NOT_LOCAL]: {
|
|
892
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
893
|
+
code: exports.AuthErrorResponseCode.AUTH_401_NOT_LOCAL,
|
|
894
|
+
message: "Cannot sign in with password for accounts signed up with social media!"
|
|
895
|
+
},
|
|
896
|
+
[exports.AuthErrorResponseCode.AUTH_401_SOCIAL_SIGN_IN]: {
|
|
897
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
898
|
+
code: exports.AuthErrorResponseCode.AUTH_401_SOCIAL_SIGN_IN,
|
|
899
|
+
message: "Cannot sign in with social media account!"
|
|
900
|
+
},
|
|
901
|
+
[exports.AuthErrorResponseCode.AUTH_401_EMAIL_NOT_VERIFIED]: {
|
|
902
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
903
|
+
code: exports.AuthErrorResponseCode.AUTH_401_EMAIL_NOT_VERIFIED,
|
|
904
|
+
message: "User e-mail not verified!"
|
|
905
|
+
},
|
|
906
|
+
[exports.AuthErrorResponseCode.AUTH_401_NOT_ACTIVE]: {
|
|
907
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
908
|
+
code: exports.AuthErrorResponseCode.AUTH_401_NOT_ACTIVE,
|
|
909
|
+
message: "Your account has been disabled. Contact us if you think this is a mistake!"
|
|
910
|
+
},
|
|
911
|
+
[exports.AuthErrorResponseCode.AUTH_401_TOKEN_NOT_SET]: {
|
|
912
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
913
|
+
code: exports.AuthErrorResponseCode.AUTH_401_TOKEN_NOT_SET,
|
|
914
|
+
message: "Cannot find a token!"
|
|
915
|
+
},
|
|
916
|
+
[exports.AuthErrorResponseCode.AUTH_401_REFRESH_TOKEN_NOT_SET]: {
|
|
917
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
918
|
+
code: exports.AuthErrorResponseCode.AUTH_401_REFRESH_TOKEN_NOT_SET,
|
|
919
|
+
message: "Cannot find a refresh token!"
|
|
920
|
+
},
|
|
921
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_TOKEN]: {
|
|
922
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
923
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_TOKEN,
|
|
924
|
+
message: "Invalid token received!"
|
|
925
|
+
},
|
|
926
|
+
[exports.AuthErrorResponseCode.AUTH_401_EXPIRED_TOKEN]: {
|
|
927
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
928
|
+
code: exports.AuthErrorResponseCode.AUTH_401_EXPIRED_TOKEN,
|
|
929
|
+
message: "Expired token received!"
|
|
930
|
+
},
|
|
931
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_VERIFICATION_TOKEN]: {
|
|
932
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
933
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_VERIFICATION_TOKEN,
|
|
934
|
+
message: "Invalid or expired verification token received!"
|
|
935
|
+
},
|
|
936
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_PASSWORD_RESET_TOKEN]: {
|
|
937
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
938
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_PASSWORD_RESET_TOKEN,
|
|
939
|
+
message: "Invalid or expired password reset token token received!"
|
|
940
|
+
},
|
|
941
|
+
[exports.AuthErrorResponseCode.AUTH_401_INVALID_REFRESH_TOKEN]: {
|
|
942
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
943
|
+
code: exports.AuthErrorResponseCode.AUTH_401_INVALID_REFRESH_TOKEN,
|
|
944
|
+
message: "Invalid refresh token received!"
|
|
945
|
+
},
|
|
946
|
+
[exports.AuthErrorResponseCode.AUTH_401_EXPIRED_REFRESH_TOKEN]: {
|
|
947
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
948
|
+
code: exports.AuthErrorResponseCode.AUTH_401_EXPIRED_REFRESH_TOKEN,
|
|
949
|
+
message: "Expired refresh token received!"
|
|
950
|
+
},
|
|
951
|
+
[exports.AuthErrorResponseCode.AUTH_401_EXPIRED_OR_INVALID_PASSWORD_RESET_TOKEN]: {
|
|
952
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
953
|
+
code: exports.AuthErrorResponseCode.AUTH_401_EXPIRED_OR_INVALID_PASSWORD_RESET_TOKEN,
|
|
954
|
+
message: "Expired or invalid password reset token received!"
|
|
955
|
+
},
|
|
956
|
+
[exports.AuthErrorResponseCode.AUTH_401_UNKNOWN]: {
|
|
957
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
958
|
+
code: exports.AuthErrorResponseCode.AUTH_401_UNKNOWN,
|
|
959
|
+
message: "Unknown error occurred!"
|
|
960
|
+
},
|
|
961
|
+
[exports.AuthErrorResponseCode.AUTH_403_PENDING]: {
|
|
962
|
+
statusCode: error_responses.HttpClientErrorStatus.UNAUTHORIZED,
|
|
963
|
+
code: exports.AuthErrorResponseCode.AUTH_403_PENDING,
|
|
964
|
+
message: "Please verify your e-mail address to continue. If you didn't receive the email you can click " + "the resend verification button to receive it again!"
|
|
965
|
+
},
|
|
966
|
+
[exports.AuthErrorResponseCode.AUTH_403_ACCOUNT_DISABLED]: {
|
|
967
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
968
|
+
code: exports.AuthErrorResponseCode.AUTH_403_ACCOUNT_DISABLED,
|
|
969
|
+
message: "Account disabled!"
|
|
970
|
+
},
|
|
971
|
+
[exports.AuthErrorResponseCode.AUTH_403_ROLE_FORBIDDEN]: {
|
|
972
|
+
statusCode: error_responses.HttpClientErrorStatus.FORBIDDEN,
|
|
973
|
+
code: exports.AuthErrorResponseCode.AUTH_403_ROLE_FORBIDDEN,
|
|
974
|
+
message: "You don't have privileges to access this resource!"
|
|
975
|
+
},
|
|
976
|
+
[exports.AuthErrorResponseCode.AUTH_403_PERMISSION_FORBIDDEN]: {
|
|
977
|
+
statusCode: error_responses.HttpClientErrorStatus.FORBIDDEN,
|
|
978
|
+
code: exports.AuthErrorResponseCode.AUTH_403_PERMISSION_FORBIDDEN,
|
|
979
|
+
message: "You don't have privileges to access this resource!"
|
|
980
|
+
},
|
|
981
|
+
[exports.AuthErrorResponseCode.AUTH_403_SUB_DOMAIN_NOT_ALLOWED]: {
|
|
982
|
+
statusCode: error_responses.HttpClientErrorStatus.FORBIDDEN,
|
|
983
|
+
code: exports.AuthErrorResponseCode.AUTH_403_SUB_DOMAIN_NOT_ALLOWED,
|
|
984
|
+
message: "You don't have privileges to access this resource!"
|
|
985
|
+
},
|
|
986
|
+
[exports.AuthErrorResponseCode.AUTH_404_EMAIL]: {
|
|
987
|
+
statusCode: error_responses.HttpClientErrorStatus.NOT_FOUND,
|
|
988
|
+
code: exports.AuthErrorResponseCode.AUTH_404_EMAIL,
|
|
989
|
+
message: "Cannot find a user account with this e-mail!"
|
|
990
|
+
},
|
|
991
|
+
[exports.AuthErrorResponseCode.AUTH_500_SIGN_UP]: {
|
|
992
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
993
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SIGN_UP,
|
|
994
|
+
message: "Error occurred while signing up!"
|
|
995
|
+
},
|
|
996
|
+
[exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_UP]: {
|
|
997
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
998
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_UP,
|
|
999
|
+
message: "Error occurred while signing up with social media account!"
|
|
1000
|
+
},
|
|
1001
|
+
[exports.AuthErrorResponseCode.AUTH_500_SIGN_IN]: {
|
|
1002
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1003
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SIGN_IN,
|
|
1004
|
+
message: "Error occurred while signing in!"
|
|
1005
|
+
},
|
|
1006
|
+
[exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_IN]: {
|
|
1007
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1008
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_IN,
|
|
1009
|
+
message: "Error occurred while signing in with social media account!"
|
|
1010
|
+
},
|
|
1011
|
+
[exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_IN_CALLBACK]: {
|
|
1012
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1013
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SOCIAL_SIGN_IN_CALLBACK,
|
|
1014
|
+
message: "Error occurred while signing in with social media account!"
|
|
1015
|
+
},
|
|
1016
|
+
[exports.AuthErrorResponseCode.AUTH_500_SIGN_OUT]: {
|
|
1017
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1018
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SIGN_OUT,
|
|
1019
|
+
message: "Error occurred while signing out!"
|
|
1020
|
+
},
|
|
1021
|
+
[exports.AuthErrorResponseCode.AUTH_500_SEND_EMAIL_VERIFICATION]: {
|
|
1022
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1023
|
+
code: exports.AuthErrorResponseCode.AUTH_500_SEND_EMAIL_VERIFICATION,
|
|
1024
|
+
message: "Error occurred while sending email verification!"
|
|
1025
|
+
},
|
|
1026
|
+
[exports.AuthErrorResponseCode.AUTH_500_VERIFY_EMAIL]: {
|
|
1027
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1028
|
+
code: exports.AuthErrorResponseCode.AUTH_500_VERIFY_EMAIL,
|
|
1029
|
+
message: "Error occurred while verifying email!"
|
|
1030
|
+
},
|
|
1031
|
+
[exports.AuthErrorResponseCode.AUTH_500_REQUEST_PASSWORD_RESET]: {
|
|
1032
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1033
|
+
code: exports.AuthErrorResponseCode.AUTH_500_REQUEST_PASSWORD_RESET,
|
|
1034
|
+
message: "Error occurred while requesting password reset!"
|
|
1035
|
+
},
|
|
1036
|
+
[exports.AuthErrorResponseCode.AUTH_500_PASSWORD_RESET]: {
|
|
1037
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1038
|
+
code: exports.AuthErrorResponseCode.AUTH_500_PASSWORD_RESET,
|
|
1039
|
+
message: "Error occurred while resetting password!"
|
|
1040
|
+
},
|
|
1041
|
+
[exports.AuthErrorResponseCode.AUTH_500]: {
|
|
1042
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1043
|
+
code: exports.AuthErrorResponseCode.AUTH_500,
|
|
1044
|
+
message: "Error occurred!"
|
|
1045
|
+
},
|
|
1046
|
+
[exports.AuthErrorResponseCode.AUTH_501_NOT_IMPLEMENTED]: {
|
|
1047
|
+
statusCode: error_responses.HttpServerErrorStatus.NOT_IMPLEMENTED,
|
|
1048
|
+
code: exports.AuthErrorResponseCode.AUTH_501_NOT_IMPLEMENTED,
|
|
1049
|
+
message: "API Not implemented!"
|
|
1050
|
+
},
|
|
1051
|
+
[exports.AuthErrorResponseCode.USER_400_EMPTY_EMAIL]: {
|
|
1052
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1053
|
+
code: exports.AuthErrorResponseCode.USER_400_EMPTY_EMAIL,
|
|
1054
|
+
message: "Email cannot be empty!"
|
|
1055
|
+
},
|
|
1056
|
+
[exports.AuthErrorResponseCode.USER_400_EMPTY_FNAME]: {
|
|
1057
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1058
|
+
code: exports.AuthErrorResponseCode.USER_400_EMPTY_FNAME,
|
|
1059
|
+
message: "User first name cannot be empty!"
|
|
1060
|
+
},
|
|
1061
|
+
[exports.AuthErrorResponseCode.USER_400_EMPTY_LNAME]: {
|
|
1062
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1063
|
+
code: exports.AuthErrorResponseCode.USER_400_EMPTY_LNAME,
|
|
1064
|
+
message: "User last name cannot be empty!"
|
|
1065
|
+
},
|
|
1066
|
+
[exports.AuthErrorResponseCode.USER_400_EMPTY_UNAME]: {
|
|
1067
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1068
|
+
code: exports.AuthErrorResponseCode.USER_400_EMPTY_UNAME,
|
|
1069
|
+
message: "User username cannot be empty!"
|
|
1070
|
+
},
|
|
1071
|
+
[exports.AuthErrorResponseCode.USER_400_EMPTY_PASSWORD]: {
|
|
1072
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1073
|
+
code: exports.AuthErrorResponseCode.USER_400_EMPTY_PASSWORD,
|
|
1074
|
+
message: "User password cannot be empty!"
|
|
1075
|
+
},
|
|
1076
|
+
[exports.AuthErrorResponseCode.USER_400_INVALID_EMAIL]: {
|
|
1077
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1078
|
+
code: exports.AuthErrorResponseCode.USER_400_INVALID_EMAIL,
|
|
1079
|
+
message: "Invalid e-mail address!"
|
|
1080
|
+
},
|
|
1081
|
+
[exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_UNAME]: {
|
|
1082
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1083
|
+
code: exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_UNAME,
|
|
1084
|
+
message: "User username cannot be updated!"
|
|
1085
|
+
},
|
|
1086
|
+
[exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_PASSWORD]: {
|
|
1087
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1088
|
+
code: exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_PASSWORD,
|
|
1089
|
+
message: "User password cannot be updated!"
|
|
1090
|
+
},
|
|
1091
|
+
[exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_SALT]: {
|
|
1092
|
+
statusCode: error_responses.HttpClientErrorStatus.BAD_REQUEST,
|
|
1093
|
+
code: exports.AuthErrorResponseCode.USER_400_NOT_EMPTY_SALT,
|
|
1094
|
+
message: "User salt cannot be inserted/updated!"
|
|
1095
|
+
},
|
|
1096
|
+
[exports.AuthErrorResponseCode.USER_403_SIGN_UP]: {
|
|
1097
|
+
statusCode: error_responses.HttpClientErrorStatus.FORBIDDEN,
|
|
1098
|
+
code: exports.AuthErrorResponseCode.USER_403_SIGN_UP,
|
|
1099
|
+
message: "User sign up is disabled!"
|
|
1100
|
+
},
|
|
1101
|
+
[exports.AuthErrorResponseCode.USER_404_ID]: {
|
|
1102
|
+
statusCode: error_responses.HttpClientErrorStatus.NOT_FOUND,
|
|
1103
|
+
code: exports.AuthErrorResponseCode.USER_404_ID,
|
|
1104
|
+
message: "Cannot find a user with given id!"
|
|
1105
|
+
},
|
|
1106
|
+
[exports.AuthErrorResponseCode.USER_409_EXIST_UNAME]: {
|
|
1107
|
+
statusCode: error_responses.HttpClientErrorStatus.CONFLICT,
|
|
1108
|
+
code: exports.AuthErrorResponseCode.USER_409_EXIST_UNAME,
|
|
1109
|
+
message: "User with given username already exist!"
|
|
1110
|
+
},
|
|
1111
|
+
[exports.AuthErrorResponseCode.USER_500_CREATE]: {
|
|
1112
|
+
statusCode: error_responses.HttpServerErrorStatus.INTERNAL_SERVER_ERROR,
|
|
1113
|
+
code: exports.AuthErrorResponseCode.USER_500_CREATE,
|
|
1114
|
+
message: "Error occurred while creating user!"
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Collection of standardized authentication success responses
|
|
1120
|
+
*
|
|
1121
|
+
* This constant maps each authentication success response code to its corresponding
|
|
1122
|
+
* standardized success response object. The responses include HTTP status codes,
|
|
1123
|
+
* success codes, and human-readable messages.
|
|
1124
|
+
*
|
|
1125
|
+
* Key features:
|
|
1126
|
+
* - Standardized success response format following the SuccessResponse interface
|
|
1127
|
+
* - Comprehensive coverage of authentication success scenarios
|
|
1128
|
+
* - Organized by HTTP status code (200, 201)
|
|
1129
|
+
* - Human-readable success messages suitable for end-users
|
|
1130
|
+
* - Consistent response structure across the authentication system
|
|
1131
|
+
*
|
|
1132
|
+
* The success responses are organized into categories based on HTTP status codes:
|
|
1133
|
+
* - 200 OK: General success responses for operations like verification, password reset, sign out
|
|
1134
|
+
* - 201 Created: Success responses for resource creation operations like account creation
|
|
1135
|
+
*
|
|
1136
|
+
* The object is organized by success code, with each code mapping to a SuccessResponse
|
|
1137
|
+
* object that follows the standardized format defined by the SuccessResponse interface.
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* // Using a success response in a controller
|
|
1142
|
+
* import { AuthSuccessResponses } from '@hichchi/nest-connector/auth';
|
|
1143
|
+
* import { Controller, Post, Body } from '@nestjs/common';
|
|
1144
|
+
*
|
|
1145
|
+
* @Controller('auth')
|
|
1146
|
+
* export class AuthController {
|
|
1147
|
+
* constructor(private readonly authService: AuthService) {}
|
|
1148
|
+
*
|
|
1149
|
+
* @Post('register')
|
|
1150
|
+
* async register(@Body() registerDto: RegisterDto) {
|
|
1151
|
+
* await this.authService.register(registerDto);
|
|
1152
|
+
* return AuthSuccessResponses.AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY;
|
|
1153
|
+
* }
|
|
1154
|
+
* }
|
|
1155
|
+
* ```
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```typescript
|
|
1159
|
+
* // Using a success response in a service
|
|
1160
|
+
* import { AuthSuccessResponses } from '@hichchi/nest-connector/auth';
|
|
1161
|
+
* import { Injectable } from '@nestjs/common';
|
|
1162
|
+
*
|
|
1163
|
+
* @Injectable()
|
|
1164
|
+
* export class AuthService {
|
|
1165
|
+
* async verifyEmail(token: string) {
|
|
1166
|
+
* // Verify email logic...
|
|
1167
|
+
* return AuthSuccessResponses.AUTH_201_EMAIL_VERIFIED;
|
|
1168
|
+
* }
|
|
1169
|
+
* }
|
|
1170
|
+
* ```
|
|
1171
|
+
*
|
|
1172
|
+
* @type {{ [key in AuthSuccessResponseCode]: SuccessResponse }}
|
|
1173
|
+
*
|
|
1174
|
+
* @see {@link AuthSuccessResponseCode} For all available success codes
|
|
1175
|
+
* @see {@link SuccessResponse} For the structure of success response objects
|
|
1176
|
+
* @see {@link AuthErrors} Complementary error responses for authentication
|
|
1177
|
+
*/
|
|
1178
|
+
const AuthSuccessResponses = {
|
|
1179
|
+
[exports.AuthSuccessResponseCode.AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY]: {
|
|
1180
|
+
statusCode: error_responses.HttpSuccessStatus.CREATED,
|
|
1181
|
+
code: exports.AuthSuccessResponseCode.AUTH_201_ACCOUNT_CREATED_REQUIRE_VERIFY,
|
|
1182
|
+
message: "Account created successfully. Please verify your email to activate your account."
|
|
1183
|
+
},
|
|
1184
|
+
[exports.AuthSuccessResponseCode.AUTH_201_ACCOUNT_CREATED]: {
|
|
1185
|
+
statusCode: error_responses.HttpSuccessStatus.CREATED,
|
|
1186
|
+
code: exports.AuthSuccessResponseCode.AUTH_201_ACCOUNT_CREATED,
|
|
1187
|
+
message: "Account created successfully."
|
|
1188
|
+
},
|
|
1189
|
+
[exports.AuthSuccessResponseCode.AUTH_201_EMAIL_VERIFIED]: {
|
|
1190
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1191
|
+
code: exports.AuthSuccessResponseCode.AUTH_201_EMAIL_VERIFIED,
|
|
1192
|
+
message: "Email verified successfully. You can now sign in."
|
|
1193
|
+
},
|
|
1194
|
+
[exports.AuthSuccessResponseCode.AUTH_200_EMAIL_VERIFICATION_SENT]: {
|
|
1195
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1196
|
+
code: exports.AuthSuccessResponseCode.AUTH_200_EMAIL_VERIFICATION_SENT,
|
|
1197
|
+
message: "Verification email sent successfully"
|
|
1198
|
+
},
|
|
1199
|
+
[exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_EMAIL_SENT]: {
|
|
1200
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1201
|
+
code: exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_EMAIL_SENT,
|
|
1202
|
+
message: "Password reset email sent successfully"
|
|
1203
|
+
},
|
|
1204
|
+
[exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_TOKEN_VALID]: {
|
|
1205
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1206
|
+
code: exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_TOKEN_VALID,
|
|
1207
|
+
message: "Password reset token is valid"
|
|
1208
|
+
},
|
|
1209
|
+
[exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_SUCCESS]: {
|
|
1210
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1211
|
+
code: exports.AuthSuccessResponseCode.AUTH_200_PASSWORD_RESET_SUCCESS,
|
|
1212
|
+
message: "Password reset successfully"
|
|
1213
|
+
},
|
|
1214
|
+
[exports.AuthSuccessResponseCode.AUTH_200_SIGNED_OUT]: {
|
|
1215
|
+
statusCode: error_responses.HttpSuccessStatus.OK,
|
|
1216
|
+
code: exports.AuthSuccessResponseCode.AUTH_200_SIGNED_OUT,
|
|
1217
|
+
message: "Successfully signed out"
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* Type guard function to check if a role is a Role object or a string
|
|
1223
|
+
*
|
|
1224
|
+
* This utility function determines whether the provided role parameter is a Role object
|
|
1225
|
+
* (containing properties like name, permissions, etc.) or just a string representation
|
|
1226
|
+
* of the role name. It's commonly used in authentication and authorization logic to
|
|
1227
|
+
* handle different role formats consistently.
|
|
1228
|
+
*
|
|
1229
|
+
* The function performs a type-safe check by verifying that the role exists and
|
|
1230
|
+
* contains a "name" property, which is characteristic of Role objects.
|
|
1231
|
+
*
|
|
1232
|
+
* @template R - The type of role string (defaults to string)
|
|
1233
|
+
* @param role - The role to check, can be a Role object, string, or null
|
|
1234
|
+
* @returns True if the role is a Role object, false if it's a string or null
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```typescript
|
|
1238
|
+
* // With a Role object
|
|
1239
|
+
* const roleObject: Role = {
|
|
1240
|
+
* name: 'admin',
|
|
1241
|
+
* permissions: ['users.read', 'users.write']
|
|
1242
|
+
* };
|
|
1243
|
+
*
|
|
1244
|
+
* if (isRoleObject(roleObject)) {
|
|
1245
|
+
* console.log('Role name:', roleObject.name);
|
|
1246
|
+
* console.log('Permissions:', roleObject.permissions);
|
|
1247
|
+
* }
|
|
1248
|
+
* ```
|
|
1249
|
+
*
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```typescript
|
|
1252
|
+
* // With a string role
|
|
1253
|
+
* const roleString = 'admin';
|
|
1254
|
+
*
|
|
1255
|
+
* if (isRoleObject(roleString)) {
|
|
1256
|
+
* // This won't execute because roleString is just a string
|
|
1257
|
+
* console.log('Role object:', roleString.name);
|
|
1258
|
+
* } else {
|
|
1259
|
+
* console.log('Role string:', roleString);
|
|
1260
|
+
* }
|
|
1261
|
+
* ```
|
|
1262
|
+
*
|
|
1263
|
+
* @example
|
|
1264
|
+
* ```typescript
|
|
1265
|
+
* // In a permission check function
|
|
1266
|
+
* function hasPermission(userRole: Role | string, requiredPermission: string): boolean {
|
|
1267
|
+
* if (isRoleObject(userRole)) {
|
|
1268
|
+
* return userRole.permissions?.includes(requiredPermission) ?? false;
|
|
1269
|
+
* }
|
|
1270
|
+
* // Handle string role case
|
|
1271
|
+
* return false;
|
|
1272
|
+
* }
|
|
1273
|
+
* ```
|
|
1274
|
+
*
|
|
1275
|
+
* @see {@link Role} Interface defining the structure of role objects
|
|
1276
|
+
*/
|
|
1277
|
+
function isRoleObject(role) {
|
|
1278
|
+
return Boolean(role) && Boolean("name" in role);
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
exports.AuthErrors = AuthErrors;
|
|
1282
|
+
exports.AuthSuccessResponses = AuthSuccessResponses;
|
|
1283
|
+
exports.isRoleObject = isRoleObject;
|