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