@plyaz/types 1.27.2 → 1.27.4

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.
@@ -2,6 +2,20 @@ import { z } from 'zod';
2
2
 
3
3
  // @plyaz package - Built with tsup
4
4
 
5
+ // src/errors/enums.ts
6
+ var ERROR_SEVERITY = {
7
+ /** Low severity - does not impact functionality significantly. */
8
+ Low: "low",
9
+ /** Medium severity - minor disruption or warning. */
10
+ Medium: "medium",
11
+ /** High severity - major issue requiring attention. */
12
+ High: "high"};
13
+ var ERROR_CATEGORY = {
14
+ /** Authentication-related error (e.g., invalid credentials, expired token). */
15
+ Authentication: "authentication",
16
+ /** Authorization-related error (e.g., insufficient permissions). */
17
+ Authorization: "authorization"};
18
+
5
19
  // src/http/constants.ts
6
20
  var HTTP_STATUS = {
7
21
  /**
@@ -17,8 +31,9 @@ var HTTP_STATUS = {
17
31
  */
18
32
  LOCKED: 423};
19
33
 
20
- // src/auth/types.ts
21
- var AUTH_ERROR_CODES = {
34
+ // src/errors/codes.ts
35
+ var ERROR_CODES = {
36
+ // Authentication
22
37
  INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS",
23
38
  TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED",
24
39
  TOKEN_INVALID: "AUTH_TOKEN_INVALID",
@@ -90,90 +105,116 @@ var TOKEN_TYPE = /* @__PURE__ */ ((TOKEN_TYPE2) => {
90
105
  return TOKEN_TYPE2;
91
106
  })(TOKEN_TYPE || {});
92
107
  var AUTH_ERROR_DEFINITIONS = {
93
- [AUTH_ERROR_CODES.INVALID_CREDENTIALS]: {
108
+ [ERROR_CODES.INVALID_CREDENTIALS]: {
109
+ code: ERROR_CODES.INVALID_CREDENTIALS,
94
110
  status: HTTP_STATUS.UNAUTHORIZED,
95
- message: "Wrong email/password.",
96
- severity: "medium",
111
+ category: ERROR_CATEGORY.Authentication,
112
+ userMessage: "errors.auth.invalid_credentials",
113
+ severity: ERROR_SEVERITY.Medium,
97
114
  retryable: false
98
115
  },
99
- [AUTH_ERROR_CODES.TOKEN_EXPIRED]: {
116
+ [ERROR_CODES.TOKEN_EXPIRED]: {
117
+ code: ERROR_CODES.TOKEN_EXPIRED,
100
118
  status: HTTP_STATUS.UNAUTHORIZED,
101
- message: "Access/refresh token expired.",
102
- severity: "medium",
119
+ category: ERROR_CATEGORY.Authentication,
120
+ userMessage: "errors.auth.token_expired",
121
+ severity: ERROR_SEVERITY.Medium,
103
122
  retryable: false
104
123
  },
105
- [AUTH_ERROR_CODES.TOKEN_INVALID]: {
124
+ [ERROR_CODES.TOKEN_INVALID]: {
125
+ code: ERROR_CODES.TOKEN_INVALID,
106
126
  status: HTTP_STATUS.UNAUTHORIZED,
107
- message: "Token signature invalid.",
108
- severity: "high",
127
+ category: ERROR_CATEGORY.Authentication,
128
+ userMessage: "errors.auth.token_invalid",
129
+ severity: ERROR_SEVERITY.High,
109
130
  retryable: false
110
131
  },
111
- [AUTH_ERROR_CODES.TOKEN_REVOKED]: {
132
+ [ERROR_CODES.TOKEN_REVOKED]: {
133
+ code: ERROR_CODES.TOKEN_REVOKED,
112
134
  status: HTTP_STATUS.UNAUTHORIZED,
113
- message: "Token has been revoked.",
114
- severity: "medium",
135
+ category: ERROR_CATEGORY.Authentication,
136
+ userMessage: "errors.auth.token_revoked",
137
+ severity: ERROR_SEVERITY.Medium,
115
138
  retryable: false
116
139
  },
117
- [AUTH_ERROR_CODES.SESSION_EXPIRED]: {
140
+ [ERROR_CODES.SESSION_EXPIRED]: {
141
+ code: ERROR_CODES.SESSION_EXPIRED,
118
142
  status: HTTP_STATUS.UNAUTHORIZED,
119
- message: "Session no longer valid.",
120
- severity: "medium",
143
+ category: ERROR_CATEGORY.Authentication,
144
+ userMessage: "errors.auth.session_expired",
145
+ severity: ERROR_SEVERITY.Medium,
121
146
  retryable: false
122
147
  },
123
- [AUTH_ERROR_CODES.MFA_REQUIRED]: {
148
+ [ERROR_CODES.MFA_REQUIRED]: {
149
+ code: ERROR_CODES.MFA_REQUIRED,
124
150
  status: HTTP_STATUS.FORBIDDEN,
125
- // 403 Forbidden is appropriate here
126
- message: "MFA verification needed.",
127
- severity: "low",
151
+ category: ERROR_CATEGORY.Authorization,
152
+ userMessage: "errors.auth.mfa_required",
153
+ severity: ERROR_SEVERITY.Low,
128
154
  retryable: false
129
155
  },
130
- [AUTH_ERROR_CODES.MFA_INVALID]: {
156
+ [ERROR_CODES.MFA_INVALID]: {
157
+ code: ERROR_CODES.MFA_INVALID,
131
158
  status: HTTP_STATUS.UNAUTHORIZED,
132
- message: "MFA code incorrect.",
133
- severity: "medium",
159
+ category: ERROR_CATEGORY.Authentication,
160
+ userMessage: "errors.auth.mfa_invalid",
161
+ severity: ERROR_SEVERITY.Medium,
134
162
  retryable: false
135
163
  },
136
- [AUTH_ERROR_CODES.INSUFFICIENT_PERMISSIONS]: {
164
+ [ERROR_CODES.INSUFFICIENT_PERMISSIONS]: {
165
+ code: ERROR_CODES.INSUFFICIENT_PERMISSIONS,
137
166
  status: HTTP_STATUS.FORBIDDEN,
138
- message: "User lacks required permission.",
139
- severity: "medium",
167
+ category: ERROR_CATEGORY.Authorization,
168
+ userMessage: "errors.auth.insufficient_permissions",
169
+ severity: ERROR_SEVERITY.Medium,
140
170
  retryable: false
141
171
  },
142
- [AUTH_ERROR_CODES.ROLE_REQUIRED]: {
172
+ [ERROR_CODES.ROLE_REQUIRED]: {
173
+ code: ERROR_CODES.ROLE_REQUIRED,
143
174
  status: HTTP_STATUS.FORBIDDEN,
144
- message: "User lacks required role.",
145
- severity: "medium",
175
+ category: ERROR_CATEGORY.Authorization,
176
+ userMessage: "errors.auth.role_required",
177
+ severity: ERROR_SEVERITY.Medium,
146
178
  retryable: false
147
179
  },
148
- [AUTH_ERROR_CODES.WALLET_SIGNATURE_INVALID]: {
180
+ [ERROR_CODES.WALLET_SIGNATURE_INVALID]: {
181
+ code: ERROR_CODES.WALLET_SIGNATURE_INVALID,
149
182
  status: HTTP_STATUS.UNAUTHORIZED,
150
- message: "Web3 signature verification failed.",
151
- severity: "high",
183
+ category: ERROR_CATEGORY.Authentication,
184
+ userMessage: "errors.auth.wallet_signature_invalid",
185
+ severity: ERROR_SEVERITY.High,
152
186
  retryable: false
153
187
  },
154
- [AUTH_ERROR_CODES.NONCE_EXPIRED]: {
188
+ [ERROR_CODES.NONCE_EXPIRED]: {
189
+ code: ERROR_CODES.NONCE_EXPIRED,
155
190
  status: HTTP_STATUS.UNAUTHORIZED,
156
- message: "SIWE nonce has expired.",
157
- severity: "medium",
191
+ category: ERROR_CATEGORY.Authentication,
192
+ userMessage: "errors.auth.nonce_expired",
193
+ severity: ERROR_SEVERITY.Medium,
158
194
  retryable: false
159
195
  },
160
- [AUTH_ERROR_CODES.NONCE_ALREADY_USED]: {
196
+ [ERROR_CODES.NONCE_ALREADY_USED]: {
197
+ code: ERROR_CODES.NONCE_ALREADY_USED,
161
198
  status: HTTP_STATUS.UNAUTHORIZED,
162
- message: "Replay attack detected.",
163
- severity: "high",
199
+ category: ERROR_CATEGORY.Authentication,
200
+ userMessage: "errors.auth.nonce_already_used",
201
+ severity: ERROR_SEVERITY.High,
164
202
  retryable: false
165
203
  },
166
- [AUTH_ERROR_CODES.ACCOUNT_LOCKED]: {
204
+ [ERROR_CODES.ACCOUNT_LOCKED]: {
205
+ code: ERROR_CODES.ACCOUNT_LOCKED,
167
206
  status: HTTP_STATUS.LOCKED,
168
- // 423 Locked is perfect for this
169
- message: "Too many failed attempts.",
170
- severity: "high",
207
+ category: ERROR_CATEGORY.Authorization,
208
+ userMessage: "errors.auth.account_locked",
209
+ severity: ERROR_SEVERITY.High,
171
210
  retryable: false
172
211
  },
173
- [AUTH_ERROR_CODES.ACCOUNT_SUSPENDED]: {
212
+ [ERROR_CODES.ACCOUNT_SUSPENDED]: {
213
+ code: ERROR_CODES.ACCOUNT_SUSPENDED,
174
214
  status: HTTP_STATUS.FORBIDDEN,
175
- message: "Account has been suspended.",
176
- severity: "high",
215
+ category: ERROR_CATEGORY.Authorization,
216
+ userMessage: "errors.auth.account_suspended",
217
+ severity: ERROR_SEVERITY.High,
177
218
  retryable: false
178
219
  }
179
220
  };