@vertz/errors 0.2.11 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -170,9 +170,164 @@ declare function isAuthValidationError(error: {
170
170
  readonly code: string;
171
171
  }): error is AuthValidationError;
172
172
  /**
173
+ * Session not found error.
174
+ *
175
+ * Returned when a session ID doesn't exist or doesn't belong to the user.
176
+ */
177
+ interface SessionNotFoundError {
178
+ readonly code: "SESSION_NOT_FOUND";
179
+ readonly message: string;
180
+ }
181
+ /**
182
+ * Creates a SessionNotFoundError.
183
+ */
184
+ declare function createSessionNotFoundError(message?: string): SessionNotFoundError;
185
+ /**
186
+ * Type guard for SessionNotFoundError.
187
+ */
188
+ declare function isSessionNotFoundError(error: {
189
+ readonly code: string;
190
+ }): error is SessionNotFoundError;
191
+ /**
192
+ * OAuth error.
193
+ *
194
+ * Returned when an OAuth operation fails (provider not configured, invalid state, etc.).
195
+ */
196
+ interface OAuthError {
197
+ readonly code: "OAUTH_ERROR";
198
+ readonly message: string;
199
+ readonly provider?: string;
200
+ readonly reason?: "provider_not_configured" | "invalid_state" | "token_exchange_failed" | "user_info_failed" | "account_already_linked" | "cannot_unlink_last_method";
201
+ }
202
+ /**
203
+ * Creates an OAuthError.
204
+ */
205
+ declare function createOAuthError(message: string, provider?: string, reason?: OAuthError["reason"]): OAuthError;
206
+ /**
207
+ * Type guard for OAuthError.
208
+ */
209
+ declare function isOAuthError(error: {
210
+ readonly code: string;
211
+ }): error is OAuthError;
212
+ /**
213
+ * MFA required error.
214
+ *
215
+ * Returned when sign-in succeeds but MFA verification is needed.
216
+ */
217
+ interface MfaRequiredError {
218
+ readonly code: "MFA_REQUIRED";
219
+ readonly message: string;
220
+ }
221
+ /**
222
+ * Creates an MfaRequiredError.
223
+ */
224
+ declare function createMfaRequiredError(message?: string): MfaRequiredError;
225
+ /**
226
+ * Type guard for MfaRequiredError.
227
+ */
228
+ declare function isMfaRequiredError(error: {
229
+ readonly code: string;
230
+ }): error is MfaRequiredError;
231
+ /**
232
+ * MFA invalid code error.
233
+ *
234
+ * Returned when an MFA code (TOTP or backup) is incorrect.
235
+ */
236
+ interface MfaInvalidCodeError {
237
+ readonly code: "MFA_INVALID_CODE";
238
+ readonly message: string;
239
+ readonly attemptsRemaining?: number;
240
+ }
241
+ /**
242
+ * Creates an MfaInvalidCodeError.
243
+ */
244
+ declare function createMfaInvalidCodeError(message?: string, attemptsRemaining?: number): MfaInvalidCodeError;
245
+ /**
246
+ * Type guard for MfaInvalidCodeError.
247
+ */
248
+ declare function isMfaInvalidCodeError(error: {
249
+ readonly code: string;
250
+ }): error is MfaInvalidCodeError;
251
+ /**
252
+ * MFA already enabled error.
253
+ *
254
+ * Returned when trying to enable MFA on an account that already has it.
255
+ */
256
+ interface MfaAlreadyEnabledError {
257
+ readonly code: "MFA_ALREADY_ENABLED";
258
+ readonly message: string;
259
+ }
260
+ /**
261
+ * Creates an MfaAlreadyEnabledError.
262
+ */
263
+ declare function createMfaAlreadyEnabledError(message?: string): MfaAlreadyEnabledError;
264
+ /**
265
+ * Type guard for MfaAlreadyEnabledError.
266
+ */
267
+ declare function isMfaAlreadyEnabledError(error: {
268
+ readonly code: string;
269
+ }): error is MfaAlreadyEnabledError;
270
+ /**
271
+ * MFA not enabled error.
272
+ *
273
+ * Returned when trying to disable MFA or regenerate backup codes when MFA is not enabled.
274
+ */
275
+ interface MfaNotEnabledError {
276
+ readonly code: "MFA_NOT_ENABLED";
277
+ readonly message: string;
278
+ }
279
+ /**
280
+ * Creates an MfaNotEnabledError.
281
+ */
282
+ declare function createMfaNotEnabledError(message?: string): MfaNotEnabledError;
283
+ /**
284
+ * Type guard for MfaNotEnabledError.
285
+ */
286
+ declare function isMfaNotEnabledError(error: {
287
+ readonly code: string;
288
+ }): error is MfaNotEnabledError;
289
+ /**
290
+ * Token expired error.
291
+ *
292
+ * Returned when a verification or reset token has expired.
293
+ */
294
+ interface TokenExpiredError {
295
+ readonly code: "TOKEN_EXPIRED";
296
+ readonly message: string;
297
+ }
298
+ /**
299
+ * Creates a TokenExpiredError.
300
+ */
301
+ declare function createTokenExpiredError(message?: string): TokenExpiredError;
302
+ /**
303
+ * Type guard for TokenExpiredError.
304
+ */
305
+ declare function isTokenExpiredError(error: {
306
+ readonly code: string;
307
+ }): error is TokenExpiredError;
308
+ /**
309
+ * Token invalid error.
310
+ *
311
+ * Returned when a verification or reset token is invalid or not found.
312
+ */
313
+ interface TokenInvalidError {
314
+ readonly code: "TOKEN_INVALID";
315
+ readonly message: string;
316
+ }
317
+ /**
318
+ * Creates a TokenInvalidError.
319
+ */
320
+ declare function createTokenInvalidError(message?: string): TokenInvalidError;
321
+ /**
322
+ * Type guard for TokenInvalidError.
323
+ */
324
+ declare function isTokenInvalidError(error: {
325
+ readonly code: string;
326
+ }): error is TokenInvalidError;
327
+ /**
173
328
  * Union type for all auth errors.
174
329
  */
175
- type AuthError = InvalidCredentialsError | UserExistsError | SessionExpiredError | PermissionDeniedError | RateLimitedError | AuthValidationError;
330
+ type AuthError = InvalidCredentialsError | UserExistsError | SessionExpiredError | SessionNotFoundError | PermissionDeniedError | RateLimitedError | AuthValidationError | OAuthError | MfaRequiredError | MfaInvalidCodeError | MfaAlreadyEnabledError | MfaNotEnabledError | TokenExpiredError | TokenInvalidError;
176
331
  /**
177
332
  * Client domain errors.
178
333
  *
@@ -1511,4 +1666,4 @@ type EntityErrorHandlers<R> = {
1511
1666
  */
1512
1667
  declare function matchError<R>(error: FetchErrorType, handlers: FetchErrorHandlers<R>): R;
1513
1668
  declare function matchError<R>(error: EntityErrorType, handlers: EntityErrorHandlers<R>): R;
1514
- export { unwrapOr, unwrap, uniqueViolationToHttpStatus, ok, notNullViolationToHttpStatus, notFoundErrorToHttpStatus, matchError, matchErr, match, map, isUserExistsError, isUnknownError, isUniqueViolation, isUnauthorizedError, isSessionExpiredError, isServiceUnavailableError, isValidationError2 as isSchemaValidationError, isPermissionDeniedError, isParseError, isOk, isNotNullViolation, isMigrationQueryError, isMigrationHistoryNotFound, isMigrationChecksumMismatch, isMethodNotAllowedError, isInvalidCredentialsError, isInternalError, isHttpError, isForbiddenError, isFetchValidationError, isFetchUnprocessableEntityError, isFetchUnauthorizedError, isFetchTimeoutError, isFetchServiceUnavailableError, isFetchRateLimitError, isFetchNotFoundError, isFetchNetworkError, isFetchInternalServerError, isFetchGoneError, isFetchForbiddenError, isFetchConflictError, isFetchBadRequestError, isFKViolation, isErr, isEntityValidationError, isEntityUnauthorizedError, isEntityNotFoundError, isEntityForbiddenError, isEntityConflictError, isNotFoundError2 as isDBNotFoundError, isConflictError, isValidationError as isClientValidationError, isRateLimitedError2 as isClientRateLimitedError, isNotFoundError as isClientNotFoundError, isCheckViolation, isBadRequestError, isAuthValidationError, isRateLimitedError as isAuthRateLimitedError, httpToClientError, flatMap, fkViolationToHttpStatus, err, dbErrorToHttpStatus, createUserExistsError, createUniqueViolation, createUnauthorizedError, createSessionExpiredError, createValidationError2 as createSchemaValidationError, createPermissionDeniedError, createNotNullViolation, createMigrationQueryError, createMigrationHistoryNotFound, createMigrationChecksumMismatch, createInvalidCredentialsError, createHttpError, createForbiddenError, createFKViolation, createNotFoundError2 as createDBNotFoundError, createConflictError, createValidationError as createClientValidationError, createRateLimitedError2 as createClientRateLimitedError, createNotFoundError as createClientNotFoundError, createCheckViolation, createAuthValidationError, createRateLimitedError as createAuthRateLimitedError, checkViolationToHttpStatus, WriteError, ValidationIssue, UserExistsError, UnknownError, UniqueViolation, UnauthorizedError, TimeoutError2 as TimeoutError, SessionExpiredError, ServiceUnavailableError, SerializationError, ValidationError3 as SchemaValidationError, Result, ReadError, QueryError, PoolExhaustedError, PermissionDeniedError, ParseError2 as ParseError, Ok, NotNullViolation, NetworkError2 as NetworkError, MigrationQueryError, MigrationHistoryNotFound, MigrationError, MigrationChecksumMismatch, MethodNotAllowedError, InvalidCredentialsError, InternalError2 as InternalError, InfraErrors, InfraError, HttpError2 as HttpError, ForbiddenError, FetchValidationError, FetchUnprocessableEntityError, FetchUnauthorizedError, FetchTimeoutError, FetchServiceUnavailableError, FetchRateLimitError, FetchNotFoundError, FetchNetworkError, FetchInternalServerError, FetchGoneError, FetchForbiddenError, FetchErrorType, FetchError, FetchConflictError, FetchBadRequestError, FKViolation, Err, EntityValidationError, EntityUnauthorizedError, EntityNotFoundError, EntityForbiddenError, EntityErrorType, EntityError, EntityConflictError, NotFoundError2 as DBNotFoundError, ConnectionError, ConflictError, ValidationError2 as ClientValidationError, RateLimitedError2 as ClientRateLimitedError, NotFoundError as ClientNotFoundError, CheckViolation, BadRequestError, AuthValidationError, RateLimitedError as AuthRateLimitedError, AuthError, AppError, ApiError };
1669
+ export { unwrapOr, unwrap, uniqueViolationToHttpStatus, ok, notNullViolationToHttpStatus, notFoundErrorToHttpStatus, matchError, matchErr, match, map, isUserExistsError, isUnknownError, isUniqueViolation, isUnauthorizedError, isTokenInvalidError, isTokenExpiredError, isSessionNotFoundError, isSessionExpiredError, isServiceUnavailableError, isValidationError2 as isSchemaValidationError, isPermissionDeniedError, isParseError, isOk, isOAuthError, isNotNullViolation, isMigrationQueryError, isMigrationHistoryNotFound, isMigrationChecksumMismatch, isMfaRequiredError, isMfaNotEnabledError, isMfaInvalidCodeError, isMfaAlreadyEnabledError, isMethodNotAllowedError, isInvalidCredentialsError, isInternalError, isHttpError, isForbiddenError, isFetchValidationError, isFetchUnprocessableEntityError, isFetchUnauthorizedError, isFetchTimeoutError, isFetchServiceUnavailableError, isFetchRateLimitError, isFetchNotFoundError, isFetchNetworkError, isFetchInternalServerError, isFetchGoneError, isFetchForbiddenError, isFetchConflictError, isFetchBadRequestError, isFKViolation, isErr, isEntityValidationError, isEntityUnauthorizedError, isEntityNotFoundError, isEntityForbiddenError, isEntityConflictError, isNotFoundError2 as isDBNotFoundError, isConflictError, isValidationError as isClientValidationError, isRateLimitedError2 as isClientRateLimitedError, isNotFoundError as isClientNotFoundError, isCheckViolation, isBadRequestError, isAuthValidationError, isRateLimitedError as isAuthRateLimitedError, httpToClientError, flatMap, fkViolationToHttpStatus, err, dbErrorToHttpStatus, createUserExistsError, createUniqueViolation, createUnauthorizedError, createTokenInvalidError, createTokenExpiredError, createSessionNotFoundError, createSessionExpiredError, createValidationError2 as createSchemaValidationError, createPermissionDeniedError, createOAuthError, createNotNullViolation, createMigrationQueryError, createMigrationHistoryNotFound, createMigrationChecksumMismatch, createMfaRequiredError, createMfaNotEnabledError, createMfaInvalidCodeError, createMfaAlreadyEnabledError, createInvalidCredentialsError, createHttpError, createForbiddenError, createFKViolation, createNotFoundError2 as createDBNotFoundError, createConflictError, createValidationError as createClientValidationError, createRateLimitedError2 as createClientRateLimitedError, createNotFoundError as createClientNotFoundError, createCheckViolation, createAuthValidationError, createRateLimitedError as createAuthRateLimitedError, checkViolationToHttpStatus, WriteError, ValidationIssue, UserExistsError, UnknownError, UniqueViolation, UnauthorizedError, TokenInvalidError, TokenExpiredError, TimeoutError2 as TimeoutError, SessionNotFoundError, SessionExpiredError, ServiceUnavailableError, SerializationError, ValidationError3 as SchemaValidationError, Result, ReadError, QueryError, PoolExhaustedError, PermissionDeniedError, ParseError2 as ParseError, Ok, OAuthError, NotNullViolation, NetworkError2 as NetworkError, MigrationQueryError, MigrationHistoryNotFound, MigrationError, MigrationChecksumMismatch, MfaRequiredError, MfaNotEnabledError, MfaInvalidCodeError, MfaAlreadyEnabledError, MethodNotAllowedError, InvalidCredentialsError, InternalError2 as InternalError, InfraErrors, InfraError, HttpError2 as HttpError, ForbiddenError, FetchValidationError, FetchUnprocessableEntityError, FetchUnauthorizedError, FetchTimeoutError, FetchServiceUnavailableError, FetchRateLimitError, FetchNotFoundError, FetchNetworkError, FetchInternalServerError, FetchGoneError, FetchForbiddenError, FetchErrorType, FetchError, FetchConflictError, FetchBadRequestError, FKViolation, Err, EntityValidationError, EntityUnauthorizedError, EntityNotFoundError, EntityForbiddenError, EntityErrorType, EntityError, EntityConflictError, NotFoundError2 as DBNotFoundError, ConnectionError, ConflictError, ValidationError2 as ClientValidationError, RateLimitedError2 as ClientRateLimitedError, NotFoundError as ClientNotFoundError, CheckViolation, BadRequestError, AuthValidationError, RateLimitedError as AuthRateLimitedError, AuthError, AppError, ApiError };
package/dist/index.js CHANGED
@@ -73,6 +73,81 @@ function createAuthValidationError(message, field, constraint) {
73
73
  function isAuthValidationError(error) {
74
74
  return error.code === "AUTH_VALIDATION_ERROR";
75
75
  }
76
+ function createSessionNotFoundError(message = "Session not found") {
77
+ return {
78
+ code: "SESSION_NOT_FOUND",
79
+ message
80
+ };
81
+ }
82
+ function isSessionNotFoundError(error) {
83
+ return error.code === "SESSION_NOT_FOUND";
84
+ }
85
+ function createOAuthError(message, provider, reason) {
86
+ return {
87
+ code: "OAUTH_ERROR",
88
+ message,
89
+ provider,
90
+ reason
91
+ };
92
+ }
93
+ function isOAuthError(error) {
94
+ return error.code === "OAUTH_ERROR";
95
+ }
96
+ function createMfaRequiredError(message = "MFA verification required") {
97
+ return {
98
+ code: "MFA_REQUIRED",
99
+ message
100
+ };
101
+ }
102
+ function isMfaRequiredError(error) {
103
+ return error.code === "MFA_REQUIRED";
104
+ }
105
+ function createMfaInvalidCodeError(message = "Invalid MFA code", attemptsRemaining) {
106
+ return {
107
+ code: "MFA_INVALID_CODE",
108
+ message,
109
+ attemptsRemaining
110
+ };
111
+ }
112
+ function isMfaInvalidCodeError(error) {
113
+ return error.code === "MFA_INVALID_CODE";
114
+ }
115
+ function createMfaAlreadyEnabledError(message = "MFA is already enabled") {
116
+ return {
117
+ code: "MFA_ALREADY_ENABLED",
118
+ message
119
+ };
120
+ }
121
+ function isMfaAlreadyEnabledError(error) {
122
+ return error.code === "MFA_ALREADY_ENABLED";
123
+ }
124
+ function createMfaNotEnabledError(message = "MFA is not enabled") {
125
+ return {
126
+ code: "MFA_NOT_ENABLED",
127
+ message
128
+ };
129
+ }
130
+ function isMfaNotEnabledError(error) {
131
+ return error.code === "MFA_NOT_ENABLED";
132
+ }
133
+ function createTokenExpiredError(message = "Token has expired") {
134
+ return {
135
+ code: "TOKEN_EXPIRED",
136
+ message
137
+ };
138
+ }
139
+ function isTokenExpiredError(error) {
140
+ return error.code === "TOKEN_EXPIRED";
141
+ }
142
+ function createTokenInvalidError(message = "Invalid token") {
143
+ return {
144
+ code: "TOKEN_INVALID",
145
+ message
146
+ };
147
+ }
148
+ function isTokenInvalidError(error) {
149
+ return error.code === "TOKEN_INVALID";
150
+ }
76
151
  // src/domain/client.ts
77
152
  function createValidationError(message, issues) {
78
153
  return {
@@ -819,16 +894,24 @@ export {
819
894
  isUnknownError,
820
895
  isUniqueViolation,
821
896
  isUnauthorizedError,
897
+ isTokenInvalidError,
898
+ isTokenExpiredError,
899
+ isSessionNotFoundError,
822
900
  isSessionExpiredError,
823
901
  isServiceUnavailableError,
824
902
  isValidationError2 as isSchemaValidationError,
825
903
  isPermissionDeniedError,
826
904
  isParseError,
827
905
  isOk,
906
+ isOAuthError,
828
907
  isNotNullViolation,
829
908
  isMigrationQueryError,
830
909
  isMigrationHistoryNotFound,
831
910
  isMigrationChecksumMismatch,
911
+ isMfaRequiredError,
912
+ isMfaNotEnabledError,
913
+ isMfaInvalidCodeError,
914
+ isMfaAlreadyEnabledError,
832
915
  isMethodNotAllowedError,
833
916
  isInvalidCredentialsError,
834
917
  isInternalError,
@@ -871,13 +954,21 @@ export {
871
954
  createUserExistsError,
872
955
  createUniqueViolation,
873
956
  createUnauthorizedError,
957
+ createTokenInvalidError,
958
+ createTokenExpiredError,
959
+ createSessionNotFoundError,
874
960
  createSessionExpiredError,
875
961
  createValidationError2 as createSchemaValidationError,
876
962
  createPermissionDeniedError,
963
+ createOAuthError,
877
964
  createNotNullViolation,
878
965
  createMigrationQueryError,
879
966
  createMigrationHistoryNotFound,
880
967
  createMigrationChecksumMismatch,
968
+ createMfaRequiredError,
969
+ createMfaNotEnabledError,
970
+ createMfaInvalidCodeError,
971
+ createMfaAlreadyEnabledError,
881
972
  createInvalidCredentialsError,
882
973
  createHttpError,
883
974
  createForbiddenError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertz/errors",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Unified error taxonomy for Vertz - Result types, domain errors, and mapping utilities",