@knsdev/node-utils 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +363 -0
- package/dist/CLengths.d.ts +60 -0
- package/dist/CLengths.d.ts.map +1 -0
- package/dist/CLengths.js +60 -0
- package/dist/CLengths.js.map +1 -0
- package/dist/Cookies.d.ts +33 -0
- package/dist/Cookies.d.ts.map +1 -0
- package/dist/Cookies.js +54 -0
- package/dist/Cookies.js.map +1 -0
- package/dist/EApiCodes.d.ts +2 -0
- package/dist/EApiCodes.d.ts.map +1 -0
- package/dist/EApiCodes.js +2 -0
- package/dist/EApiCodes.js.map +1 -0
- package/dist/ErrorClasses.d.ts +78 -0
- package/dist/ErrorClasses.d.ts.map +1 -0
- package/dist/ErrorClasses.js +118 -0
- package/dist/ErrorClasses.js.map +1 -0
- package/dist/FBUtils.d.ts +22 -0
- package/dist/FBUtils.d.ts.map +1 -0
- package/dist/FBUtils.js +68 -0
- package/dist/FBUtils.js.map +1 -0
- package/dist/GoogleUtils.d.ts +43 -0
- package/dist/GoogleUtils.d.ts.map +1 -0
- package/dist/GoogleUtils.js +79 -0
- package/dist/GoogleUtils.js.map +1 -0
- package/dist/HMACUtils.d.ts +40 -0
- package/dist/HMACUtils.d.ts.map +1 -0
- package/dist/HMACUtils.js +62 -0
- package/dist/HMACUtils.js.map +1 -0
- package/dist/HttpCodes.d.ts +26 -0
- package/dist/HttpCodes.d.ts.map +1 -0
- package/dist/HttpCodes.js +25 -0
- package/dist/HttpCodes.js.map +1 -0
- package/dist/IDUtils.d.ts +28 -0
- package/dist/IDUtils.d.ts.map +1 -0
- package/dist/IDUtils.js +47 -0
- package/dist/IDUtils.js.map +1 -0
- package/dist/JwtUtils.d.ts +51 -0
- package/dist/JwtUtils.d.ts.map +1 -0
- package/dist/JwtUtils.js +78 -0
- package/dist/JwtUtils.js.map +1 -0
- package/dist/Nums.d.ts +101 -0
- package/dist/Nums.d.ts.map +1 -0
- package/dist/Nums.js +141 -0
- package/dist/Nums.js.map +1 -0
- package/dist/PassUtils.d.ts +59 -0
- package/dist/PassUtils.d.ts.map +1 -0
- package/dist/PassUtils.js +84 -0
- package/dist/PassUtils.js.map +1 -0
- package/dist/Rand.d.ts +44 -0
- package/dist/Rand.d.ts.map +1 -0
- package/dist/Rand.js +72 -0
- package/dist/Rand.js.map +1 -0
- package/dist/TurnstileValidator.d.ts +57 -0
- package/dist/TurnstileValidator.d.ts.map +1 -0
- package/dist/TurnstileValidator.js +99 -0
- package/dist/TurnstileValidator.js.map +1 -0
- package/dist/bnUtils.d.ts +15 -0
- package/dist/bnUtils.d.ts.map +1 -0
- package/dist/bnUtils.js +67 -0
- package/dist/bnUtils.js.map +1 -0
- package/dist/getEnvv.d.ts +21 -0
- package/dist/getEnvv.d.ts.map +1 -0
- package/dist/getEnvv.js +68 -0
- package/dist/getEnvv.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/tryCatch.d.ts +23 -0
- package/dist/tryCatch.d.ts.map +1 -0
- package/dist/tryCatch.js +29 -0
- package/dist/tryCatch.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +7 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +11 -0
- package/dist/validators.js.map +1 -0
- package/dist/zod.d.ts +12 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +33 -0
- package/dist/zod.js.map +1 -0
- package/dist/zodTypes.d.ts +2 -0
- package/dist/zodTypes.d.ts.map +1 -0
- package/dist/zodTypes.js +2 -0
- package/dist/zodTypes.js.map +1 -0
- package/package.json +2 -3
- package/dist/l.d.ts +0 -2
- package/dist/l.d.ts.map +0 -1
- package/dist/l.js +0 -2
- package/dist/l.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# @knsdev/node-utils
|
|
2
|
+
|
|
3
|
+
TypeScript utilities for Node.js APIs: JWT (HS256), bcrypt passwords, Express cookies, OAuth (Google / Facebook), Cloudflare Turnstile, HMAC, validation helpers, Zod schemas, and small math/random helpers. Published as **ES modules** (`"type": "module"`).
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- **Node.js** with native `fetch` (or a compatible runtime).
|
|
8
|
+
- **Express** is a peer-style dependency for [`CookieUtils`](#cookieutils-express) typings and `res.cookie`; install `express` in your app if you use cookies.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @knsdev/node-utils
|
|
14
|
+
# or
|
|
15
|
+
npm install @knsdev/node-utils
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Build from source (for contributors):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm install
|
|
22
|
+
pnpm run build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## How to import
|
|
26
|
+
|
|
27
|
+
The package exposes **per-file subpaths** (no root barrel in `exports`):
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { JwtUtils } from "@knsdev/node-utils/JwtUtils.js";
|
|
31
|
+
import { tryCatch } from "@knsdev/node-utils/tryCatch.js";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use the `.js` extension in import specifiers (NodeNext / TypeScript convention for ESM). Paths map to compiled files under `dist/` (e.g. `JwtUtils.ts` → `JwtUtils.js`).
|
|
35
|
+
|
|
36
|
+
For local monorepos, you can also re-export from the included [`src/index.ts`](src/index.ts) if your bundler resolves it.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Modules and usage
|
|
41
|
+
|
|
42
|
+
### `tryCatch` / `tryCatch2`
|
|
43
|
+
|
|
44
|
+
Async and sync helpers that return a **tuple** `[data, error]` instead of throwing.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { tryCatch, tryCatch2 } from "@knsdev/node-utils/tryCatch.js";
|
|
48
|
+
|
|
49
|
+
const [user, err] = await tryCatch(fetch("https://api.example.com/user"));
|
|
50
|
+
if (err) {
|
|
51
|
+
console.error(err);
|
|
52
|
+
} else {
|
|
53
|
+
console.log(await user.json());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [parsed, parseErr] = tryCatch2(() => JSON.parse('{"a":1}'));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `getEnvv`
|
|
60
|
+
|
|
61
|
+
Read `process.env` with a small schema: `string`, `int`, `float`, `boolean`, or `appEnv` (`dev` | `test` | `prod`). Throws a single `Error` listing missing keys and value problems.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { getEnvv } from "@knsdev/node-utils/getEnvv.js";
|
|
65
|
+
|
|
66
|
+
const env = getEnvv({
|
|
67
|
+
PORT: "int",
|
|
68
|
+
DATABASE_URL: "string",
|
|
69
|
+
APP_ENV: "appEnv",
|
|
70
|
+
DEBUG: "boolean",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// env.PORT is number, env.APP_ENV is 'dev' | 'test' | 'prod', etc.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `JwtUtils`
|
|
77
|
+
|
|
78
|
+
HS256 sign/verify via `jsonwebtoken`. Throwing variants use your API error types (`InternalServerError`, `Unauthorized`, `BadRequest`).
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { JwtUtils } from "@knsdev/node-utils/JwtUtils.js";
|
|
82
|
+
|
|
83
|
+
type Session = { sub: string; role: string };
|
|
84
|
+
|
|
85
|
+
const token = JwtUtils.signOrThrow<Session>(
|
|
86
|
+
process.env.JWT_SECRET!,
|
|
87
|
+
{ sub: "user-1", role: "user" },
|
|
88
|
+
15 * 60 * 1000, // 15 minutes (ignored if payload already has `exp`)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const payload = JwtUtils.verifyOrThrow<Session>(process.env.JWT_SECRET!, token);
|
|
92
|
+
|
|
93
|
+
const signResult = JwtUtils.sign<Session>(secret, payload, 3600_000);
|
|
94
|
+
if (signResult.error) {
|
|
95
|
+
/* handle */
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `PasswordUtils`
|
|
100
|
+
|
|
101
|
+
Bcrypt hash/compare and simple length checks.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { PasswordUtils } from "@knsdev/node-utils/PassUtils.js";
|
|
105
|
+
|
|
106
|
+
const hashResult = await PasswordUtils.hashPassword("correct horse battery staple");
|
|
107
|
+
if (hashResult.success) {
|
|
108
|
+
console.log(hashResult.hashedPassword);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const ok = await PasswordUtils.comparePassword("plain", storedHash);
|
|
112
|
+
|
|
113
|
+
if (!PasswordUtils.validateStrength(pw, 8, 128)) {
|
|
114
|
+
/* reject */
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (PasswordUtils.isBcryptHash(value)) {
|
|
118
|
+
/* already a hash */
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `CookieUtils` (Express)
|
|
123
|
+
|
|
124
|
+
HTTP-only cookies with secure defaults: `secure` follows environment (`dev` allows insecure unless `sameSite === 'none'`).
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import type { Response } from "express";
|
|
128
|
+
import { CookieUtils } from "@knsdev/node-utils/Cookies.js";
|
|
129
|
+
|
|
130
|
+
function setSessionCookie(res: Response, token: string) {
|
|
131
|
+
CookieUtils.setCookie(
|
|
132
|
+
res,
|
|
133
|
+
"session",
|
|
134
|
+
token,
|
|
135
|
+
7 * 24 * 60 * 60 * 1000,
|
|
136
|
+
".example.com",
|
|
137
|
+
"prod",
|
|
138
|
+
"/",
|
|
139
|
+
"lax",
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function logout(res: Response) {
|
|
144
|
+
CookieUtils.clearCookie(res, "session", ".example.com", "prod");
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `HMACUtils`
|
|
149
|
+
|
|
150
|
+
SHA-256 HMAC (hex) and timing-safe comparison.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { HMACUtils } from "@knsdev/node-utils/HMACUtils.js";
|
|
154
|
+
|
|
155
|
+
const { data: digest, error } = HMACUtils.hash(process.env.WEBHOOK_SECRET!, rawBody);
|
|
156
|
+
const valid =
|
|
157
|
+
digest !== null && HMACUtils.compare(digest, signatureFromHeader);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### `IDUtils` / `validateUUID`
|
|
161
|
+
|
|
162
|
+
Crypto random UUID (v4) and validation; `validateOrThrow` raises `BadRequest` with `'ID__INVALID'`.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { IDUtils } from "@knsdev/node-utils/IDUtils.js";
|
|
166
|
+
import { validateUUID } from "@knsdev/node-utils/validators.js";
|
|
167
|
+
|
|
168
|
+
const id = IDUtils.gen();
|
|
169
|
+
|
|
170
|
+
if (IDUtils.validate(req.params.id)) {
|
|
171
|
+
/* narrowed to string */
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
IDUtils.validateOrThrow(req.params.id); // throws BadRequest if invalid
|
|
175
|
+
|
|
176
|
+
if (validateUUID(someInput)) {
|
|
177
|
+
/* someInput is string */
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `Rand`
|
|
182
|
+
|
|
183
|
+
Random integers/floats (crypto vs `Math.random`), UUIDs, and Base58 strings.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { randInt, randUuid, randStr, srandInt } from "@knsdev/node-utils/Rand.js";
|
|
187
|
+
|
|
188
|
+
const code = randInt(100000, 999999);
|
|
189
|
+
const apiKey = randStr(32);
|
|
190
|
+
const id = randUuid();
|
|
191
|
+
const quickDemo = srandInt(1, 6); // non-crypto, for low-stakes UI
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### `Nums`
|
|
195
|
+
|
|
196
|
+
Clamping, safe parsing, formatting, percentages.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import {
|
|
200
|
+
clamp,
|
|
201
|
+
parseIntSafe,
|
|
202
|
+
formatWithCommas,
|
|
203
|
+
percentage,
|
|
204
|
+
toNumber,
|
|
205
|
+
} from "@knsdev/node-utils/Nums.js";
|
|
206
|
+
|
|
207
|
+
const n = clamp(Number(input), 0, 100);
|
|
208
|
+
const page = parseIntSafe(query.page, 10) ?? 1;
|
|
209
|
+
const label = formatWithCommas(12345.67, "en-US", 2);
|
|
210
|
+
const pct = percentage(3, 10, 1); // 30.0
|
|
211
|
+
const x = toNumber(unknownValue, 0);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### `HttpCodes` / `ErrorClasses` / `EApiCodes`
|
|
215
|
+
|
|
216
|
+
HTTP status constants and errors for APIs: `ApiError` plus `BadRequest`, `Unauthorized`, `Forbidden`, `NotFound`, `TooManyRequests`, `InternalServerError`. Messages use the `EApiCodes` string union (machine-friendly codes for clients).
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { HttpCodes } from "@knsdev/node-utils/HttpCodes.js";
|
|
220
|
+
import {
|
|
221
|
+
BadRequest,
|
|
222
|
+
Unauthorized,
|
|
223
|
+
NotFound,
|
|
224
|
+
} from "@knsdev/node-utils/ErrorClasses.js";
|
|
225
|
+
import type { EApiCodes } from "@knsdev/node-utils/EApiCodes.js";
|
|
226
|
+
|
|
227
|
+
function handler() {
|
|
228
|
+
throw new BadRequest("EMAIL__INVALID");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function requireUser(token: string | undefined) {
|
|
232
|
+
if (!token) throw new Unauthorized("UNAUTHORIZED");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Example Express error middleware pattern:
|
|
236
|
+
// if (err instanceof ApiError) res.status(err.status).json({ code: err.message });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### `GoogleUtils`
|
|
240
|
+
|
|
241
|
+
Verify Google **ID tokens** with `jose`, or exchange an **authorization code** for tokens and then resolve the user.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { GoogleUtils } from "@knsdev/node-utils/GoogleUtils.js";
|
|
245
|
+
|
|
246
|
+
const fromIdToken = await GoogleUtils.getUserFromJwt(idToken, process.env.GOOGLE_CLIENT_ID!);
|
|
247
|
+
|
|
248
|
+
const fromCode = await GoogleUtils.getUserFromCode(
|
|
249
|
+
code,
|
|
250
|
+
process.env.GOOGLE_CLIENT_ID!,
|
|
251
|
+
process.env.GOOGLE_CLIENT_SECRET!,
|
|
252
|
+
"https://your.app/oauth/callback",
|
|
253
|
+
);
|
|
254
|
+
// Returns { oauth_id, name, email, picture } or null on failure
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### `FacebookUtils`
|
|
258
|
+
|
|
259
|
+
Validates a user access token via Graph API `debug_token`, then loads `/me` (POST bodies to avoid putting secrets in query strings). Returns normalized profile or `null`.
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
import { FacebookUtils } from "@knsdev/node-utils/FBUtils.js";
|
|
263
|
+
|
|
264
|
+
const profile = await FacebookUtils.getUserFromJwt(
|
|
265
|
+
accessToken,
|
|
266
|
+
process.env.FB_APP_ID!,
|
|
267
|
+
process.env.FB_APP_SECRET!,
|
|
268
|
+
);
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### `TurnstileValidator`
|
|
272
|
+
|
|
273
|
+
Server-side [Cloudflare Turnstile](https://developers.cloudflare.com/turnstile/) verification. Tuple API or throwing `BadRequest` with `'CAPTCHA__VALIDATION_FAILED'`.
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
import { TurnstileValidator } from "@knsdev/node-utils/TurnstileValidator.js";
|
|
277
|
+
|
|
278
|
+
const [success, failure] = await TurnstileValidator.validate(
|
|
279
|
+
process.env.TURNSTILE_SECRET!,
|
|
280
|
+
tokenFromClient,
|
|
281
|
+
req.ip,
|
|
282
|
+
{ expectedAction: "login", expectedHostname: "your.app" },
|
|
283
|
+
10_000,
|
|
284
|
+
"prod",
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (failure) {
|
|
288
|
+
console.error(failure["error-codes"]);
|
|
289
|
+
} else {
|
|
290
|
+
console.log(success.hostname, success.challenge_ts);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Or throw on any failure:
|
|
294
|
+
const result = await TurnstileValidator.validateOrThrow(
|
|
295
|
+
secret,
|
|
296
|
+
tokenFromClient,
|
|
297
|
+
req.ip,
|
|
298
|
+
{},
|
|
299
|
+
10_000,
|
|
300
|
+
"prod",
|
|
301
|
+
);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### `bnUtils`
|
|
305
|
+
|
|
306
|
+
Bengali digit substitution and English month → Bengali month names.
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
import { bnNum, monthToBn } from "@knsdev/node-utils/bnUtils.js";
|
|
310
|
+
|
|
311
|
+
bnNum(2025); // Bengali digits for "2025"
|
|
312
|
+
monthToBn("january");
|
|
313
|
+
monthToBn(3);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### `types`
|
|
317
|
+
|
|
318
|
+
Shared string unions (app envs, roles, themes, etc.) for use across your app.
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
import type { TAppEnvs, TUserRoles } from "@knsdev/node-utils/types.js";
|
|
322
|
+
|
|
323
|
+
function configure(env: TAppEnvs) {
|
|
324
|
+
/* ... */
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### `zod` (optional)
|
|
329
|
+
|
|
330
|
+
Prebuilt Zod schemas aligned with `EApiCodes` / length constants (password, email, slug, 6-digit codes, Turnstile token, etc.).
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
import { z_EMAIL, z_PASSWORD } from "@knsdev/node-utils/zod.js";
|
|
334
|
+
import { z } from "zod";
|
|
335
|
+
|
|
336
|
+
const LoginBody = z.object({
|
|
337
|
+
email: z_EMAIL,
|
|
338
|
+
password: z_PASSWORD,
|
|
339
|
+
});
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Dependencies (summary)
|
|
345
|
+
|
|
346
|
+
| Area | Packages |
|
|
347
|
+
|-----------------|-----------------------------------|
|
|
348
|
+
| JWT | `jsonwebtoken` |
|
|
349
|
+
| Google ID token | `jose` |
|
|
350
|
+
| Passwords | `bcrypt` |
|
|
351
|
+
| Schemas | `zod` |
|
|
352
|
+
| Cookies | `express` (types / `Response`) |
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## License
|
|
357
|
+
|
|
358
|
+
MIT — see [LICENSE](LICENSE).
|
|
359
|
+
|
|
360
|
+
## Links
|
|
361
|
+
|
|
362
|
+
- [Repository](https://github.com/KnsDev330/node-utils)
|
|
363
|
+
- [Issues](https://github.com/KnsDev330/node-utils/issues)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare class CLengths {
|
|
2
|
+
static readonly ID = 36;
|
|
3
|
+
static readonly UUID = 36;
|
|
4
|
+
static readonly REFRESH_TOKEN = 64;
|
|
5
|
+
static readonly ACCOUNT_VERIFY_TOKEN = 64;
|
|
6
|
+
static readonly GENERAL_TOKEN = 64;
|
|
7
|
+
static readonly GENERAL_CODE = 6;
|
|
8
|
+
static readonly Code_8_digits = 8;
|
|
9
|
+
static readonly Code_6_digits = 6;
|
|
10
|
+
static readonly Code_4_digits = 4;
|
|
11
|
+
static readonly SLUG: {
|
|
12
|
+
min: number;
|
|
13
|
+
max: number;
|
|
14
|
+
};
|
|
15
|
+
static readonly TURNSTILE_TOKEN: {
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
};
|
|
19
|
+
static readonly FIRST_NAME: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
};
|
|
23
|
+
static readonly LAST_NAME: {
|
|
24
|
+
min: number;
|
|
25
|
+
max: number;
|
|
26
|
+
};
|
|
27
|
+
static readonly NAME: {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
};
|
|
31
|
+
static readonly USERNAME: {
|
|
32
|
+
min: number;
|
|
33
|
+
max: number;
|
|
34
|
+
};
|
|
35
|
+
static readonly DESIGNATION: {
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
};
|
|
39
|
+
static readonly BIO: {
|
|
40
|
+
min: number;
|
|
41
|
+
max: number;
|
|
42
|
+
};
|
|
43
|
+
static readonly PASSWORD: {
|
|
44
|
+
min: number;
|
|
45
|
+
max: number;
|
|
46
|
+
};
|
|
47
|
+
static readonly CONFIRM_PASSWORD: {
|
|
48
|
+
min: number;
|
|
49
|
+
max: number;
|
|
50
|
+
};
|
|
51
|
+
static readonly EMAIL: {
|
|
52
|
+
min: number;
|
|
53
|
+
max: number;
|
|
54
|
+
};
|
|
55
|
+
static readonly PHONE: {
|
|
56
|
+
min: number;
|
|
57
|
+
max: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=CLengths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CLengths.d.ts","sourceRoot":"","sources":["../src/CLengths.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACpB,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM;IACxB,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM;IAC1B,MAAM,CAAC,QAAQ,CAAC,aAAa,MAAM;IACnC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,MAAM;IAC1C,MAAM,CAAC,QAAQ,CAAC,aAAa,MAAM;IACnC,MAAM,CAAC,QAAQ,CAAC,YAAY,KAAK;IACjC,MAAM,CAAC,QAAQ,CAAC,aAAa,KAAK;IAClC,MAAM,CAAC,QAAQ,CAAC,aAAa,KAAK;IAClC,MAAM,CAAC,QAAQ,CAAC,aAAa,KAAK;IAElC,MAAM,CAAC,QAAQ,CAAC,IAAI;;;MAGnB;IACD,MAAM,CAAC,QAAQ,CAAC,eAAe;;;MAG9B;IACD,MAAM,CAAC,QAAQ,CAAC,UAAU;;;MAGzB;IACD,MAAM,CAAC,QAAQ,CAAC,SAAS;;;MAGxB;IACD,MAAM,CAAC,QAAQ,CAAC,IAAI;;;MAGnB;IACD,MAAM,CAAC,QAAQ,CAAC,QAAQ;;;MAGvB;IACD,MAAM,CAAC,QAAQ,CAAC,WAAW;;;MAG1B;IACD,MAAM,CAAC,QAAQ,CAAC,GAAG;;;MAGlB;IACD,MAAM,CAAC,QAAQ,CAAC,QAAQ;;;MAGvB;IACD,MAAM,CAAC,QAAQ,CAAC,gBAAgB;;;MAG/B;IACD,MAAM,CAAC,QAAQ,CAAC,KAAK;;;MAGpB;IACD,MAAM,CAAC,QAAQ,CAAC,KAAK;;;MAGpB;CACD"}
|
package/dist/CLengths.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export class CLengths {
|
|
2
|
+
static ID = 36;
|
|
3
|
+
static UUID = 36;
|
|
4
|
+
static REFRESH_TOKEN = 64;
|
|
5
|
+
static ACCOUNT_VERIFY_TOKEN = 64;
|
|
6
|
+
static GENERAL_TOKEN = 64;
|
|
7
|
+
static GENERAL_CODE = 6;
|
|
8
|
+
static Code_8_digits = 8;
|
|
9
|
+
static Code_6_digits = 6;
|
|
10
|
+
static Code_4_digits = 4;
|
|
11
|
+
static SLUG = {
|
|
12
|
+
min: 1,
|
|
13
|
+
max: 255,
|
|
14
|
+
};
|
|
15
|
+
static TURNSTILE_TOKEN = {
|
|
16
|
+
min: 1,
|
|
17
|
+
max: 2048,
|
|
18
|
+
};
|
|
19
|
+
static FIRST_NAME = {
|
|
20
|
+
min: 1,
|
|
21
|
+
max: 50
|
|
22
|
+
};
|
|
23
|
+
static LAST_NAME = {
|
|
24
|
+
min: 0,
|
|
25
|
+
max: 50
|
|
26
|
+
};
|
|
27
|
+
static NAME = {
|
|
28
|
+
min: 1,
|
|
29
|
+
max: 100,
|
|
30
|
+
};
|
|
31
|
+
static USERNAME = {
|
|
32
|
+
min: 3,
|
|
33
|
+
max: 36
|
|
34
|
+
};
|
|
35
|
+
static DESIGNATION = {
|
|
36
|
+
min: 1,
|
|
37
|
+
max: 255
|
|
38
|
+
};
|
|
39
|
+
static BIO = {
|
|
40
|
+
min: 1,
|
|
41
|
+
max: 1024
|
|
42
|
+
};
|
|
43
|
+
static PASSWORD = {
|
|
44
|
+
min: 8,
|
|
45
|
+
max: 128
|
|
46
|
+
};
|
|
47
|
+
static CONFIRM_PASSWORD = {
|
|
48
|
+
min: 8,
|
|
49
|
+
max: 128
|
|
50
|
+
};
|
|
51
|
+
static EMAIL = {
|
|
52
|
+
min: 5,
|
|
53
|
+
max: 255
|
|
54
|
+
};
|
|
55
|
+
static PHONE = {
|
|
56
|
+
min: 7,
|
|
57
|
+
max: 15
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=CLengths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CLengths.js","sourceRoot":"","sources":["../src/CLengths.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAQ;IACpB,MAAM,CAAU,EAAE,GAAG,EAAE,CAAC;IACxB,MAAM,CAAU,IAAI,GAAG,EAAE,CAAC;IAC1B,MAAM,CAAU,aAAa,GAAG,EAAE,CAAC;IACnC,MAAM,CAAU,oBAAoB,GAAG,EAAE,CAAC;IAC1C,MAAM,CAAU,aAAa,GAAG,EAAE,CAAC;IACnC,MAAM,CAAU,YAAY,GAAG,CAAC,CAAC;IACjC,MAAM,CAAU,aAAa,GAAG,CAAC,CAAC;IAClC,MAAM,CAAU,aAAa,GAAG,CAAC,CAAC;IAClC,MAAM,CAAU,aAAa,GAAG,CAAC,CAAC;IAElC,MAAM,CAAU,IAAI,GAAG;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,eAAe,GAAG;QACjC,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;KACT,CAAA;IACD,MAAM,CAAU,UAAU,GAAG;QAC5B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACP,CAAA;IACD,MAAM,CAAU,SAAS,GAAG;QAC3B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACP,CAAA;IACD,MAAM,CAAU,IAAI,GAAG;QACtB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,QAAQ,GAAG;QAC1B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACP,CAAA;IACD,MAAM,CAAU,WAAW,GAAG;QAC7B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,GAAG,GAAG;QACrB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,IAAI;KACT,CAAA;IACD,MAAM,CAAU,QAAQ,GAAG;QAC1B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,gBAAgB,GAAG;QAClC,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,KAAK,GAAG;QACvB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,GAAG;KACR,CAAA;IACD,MAAM,CAAU,KAAK,GAAG;QACvB,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;KACP,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Response } from "express";
|
|
2
|
+
declare class cookieUtils {
|
|
3
|
+
/**
|
|
4
|
+
* Set an HTTP-only cookie with common security defaults.
|
|
5
|
+
* @param res - Express response object.
|
|
6
|
+
* @param name - Cookie name.
|
|
7
|
+
* @param value - Cookie value.
|
|
8
|
+
* @param maxAgeMs - Cookie max age in milliseconds (Express `maxAge`).
|
|
9
|
+
* @param domain - Cookie domain.
|
|
10
|
+
* @param APP_ENV - Current application environment.
|
|
11
|
+
* @param path - Cookie path.
|
|
12
|
+
* @param sameSite - SameSite policy.
|
|
13
|
+
* @returns Nothing.
|
|
14
|
+
*/
|
|
15
|
+
readonly setCookie: (res: Response, name: string, value: string, maxAgeMs: number, domain: string, APP_ENV: "dev" | "test" | "prod", path?: string, sameSite?: "lax" | "strict" | "none") => void;
|
|
16
|
+
/**
|
|
17
|
+
* Clear an HTTP-only cookie by setting it expired immediately.
|
|
18
|
+
* @param res - Express response object.
|
|
19
|
+
* @param name - Cookie name.
|
|
20
|
+
* @param domain - Cookie domain.
|
|
21
|
+
* @param APP_ENV - Current application environment.
|
|
22
|
+
* @param path - Cookie path.
|
|
23
|
+
* @param sameSite - SameSite policy.
|
|
24
|
+
* @returns Nothing.
|
|
25
|
+
*/
|
|
26
|
+
readonly clearCookie: (res: Response, name: string, domain: string, APP_ENV: "dev" | "test" | "prod", path?: string, sameSite?: "lax" | "strict" | "none") => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Singleton instance of cookie helper utilities.
|
|
30
|
+
*/
|
|
31
|
+
export declare const CookieUtils: cookieUtils;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cookies.d.ts","sourceRoot":"","sources":["../src/Cookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,cAAM,WAAW;IAChB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,GAAI,KAAK,QAAQ,EAAE,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,UAAU,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,OAAM,MAAY,EAAE,WAAU,KAAK,GAAG,QAAQ,GAAG,MAAc,UAYpM;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,WAAW,GAAI,KAAK,QAAQ,EAAE,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,SAAS,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,OAAM,MAAY,EAAE,WAAU,KAAK,GAAG,QAAQ,GAAG,MAAc,UAYrK;CACD;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
package/dist/Cookies.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {} from "express";
|
|
2
|
+
class cookieUtils {
|
|
3
|
+
/**
|
|
4
|
+
* Set an HTTP-only cookie with common security defaults.
|
|
5
|
+
* @param res - Express response object.
|
|
6
|
+
* @param name - Cookie name.
|
|
7
|
+
* @param value - Cookie value.
|
|
8
|
+
* @param maxAgeMs - Cookie max age in milliseconds (Express `maxAge`).
|
|
9
|
+
* @param domain - Cookie domain.
|
|
10
|
+
* @param APP_ENV - Current application environment.
|
|
11
|
+
* @param path - Cookie path.
|
|
12
|
+
* @param sameSite - SameSite policy.
|
|
13
|
+
* @returns Nothing.
|
|
14
|
+
*/
|
|
15
|
+
setCookie = (res, name, value, maxAgeMs, domain, APP_ENV, path = '/', sameSite = 'lax') => {
|
|
16
|
+
// If sameSite is 'none', secure must be true for most modern browsers
|
|
17
|
+
const isSecure = sameSite === 'none' ? true : APP_ENV !== 'dev';
|
|
18
|
+
res.cookie(name, value, {
|
|
19
|
+
httpOnly: true,
|
|
20
|
+
secure: isSecure,
|
|
21
|
+
maxAge: maxAgeMs,
|
|
22
|
+
path: path,
|
|
23
|
+
sameSite: sameSite,
|
|
24
|
+
domain: domain
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Clear an HTTP-only cookie by setting it expired immediately.
|
|
29
|
+
* @param res - Express response object.
|
|
30
|
+
* @param name - Cookie name.
|
|
31
|
+
* @param domain - Cookie domain.
|
|
32
|
+
* @param APP_ENV - Current application environment.
|
|
33
|
+
* @param path - Cookie path.
|
|
34
|
+
* @param sameSite - SameSite policy.
|
|
35
|
+
* @returns Nothing.
|
|
36
|
+
*/
|
|
37
|
+
clearCookie = (res, name, domain, APP_ENV, path = '/', sameSite = 'lax') => {
|
|
38
|
+
const isSecure = sameSite === 'none' ? true : APP_ENV !== 'dev';
|
|
39
|
+
res.cookie(name, 'invalid', {
|
|
40
|
+
httpOnly: true,
|
|
41
|
+
secure: isSecure,
|
|
42
|
+
maxAge: 0,
|
|
43
|
+
expires: new Date(0),
|
|
44
|
+
path: path,
|
|
45
|
+
sameSite: sameSite,
|
|
46
|
+
domain: domain
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Singleton instance of cookie helper utilities.
|
|
52
|
+
*/
|
|
53
|
+
export const CookieUtils = new cookieUtils();
|
|
54
|
+
//# sourceMappingURL=Cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cookies.js","sourceRoot":"","sources":["../src/Cookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW;IAChB;;;;;;;;;;;OAWG;IACM,SAAS,GAAG,CAAC,GAAa,EAAE,IAAY,EAAE,KAAa,EAAE,QAAgB,EAAE,MAAc,EAAE,OAAgC,EAAE,OAAe,GAAG,EAAE,WAAsC,KAAK,EAAE,EAAE;QACxM,sEAAsE;QACtE,MAAM,QAAQ,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC;QAEhE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;YACvB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE,MAAM;SACd,CAAC,CAAC;IACJ,CAAC,CAAA;IAED;;;;;;;;;OASG;IACM,WAAW,GAAG,CAAC,GAAa,EAAE,IAAY,EAAE,MAAc,EAAE,OAAgC,EAAE,OAAe,GAAG,EAAE,WAAsC,KAAK,EAAE,EAAE;QACzK,MAAM,QAAQ,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC;QAEhE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE;YAC3B,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,CAAC;YACT,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC;YACpB,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE,MAAM;SACd,CAAC,CAAC;IACJ,CAAC,CAAA;CACD;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type EApiCodes = `API_ERROR` | `CREATED` | `UPDATED` | `DELETED` | `FETCHED` | `VALIDATED` | `AUTHENTICATED` | `SUCCESS` | `BAD_REQUEST` | `AUTHORIZED` | `UNAUTHORIZED` | `FORBIDDEN` | `NOT_FOUND` | `INTERNAL_SERVER_ERROR` | `TOO_MANY_REQUESTS` | `JWT__ENCRYPTION_FAILED` | `JWT__INVALID_OR_EXPIRED` | `CAPTCHA__VALIDATION_FAILED` | `PASSWORD__INVALID` | `PASSWORD__MIN_LENGTH` | `PASSWORD__MAX_LENGTH` | `GENERAL_TOKEN__INVALID` | `GENERAL_TOKEN__LENGTH` | `CODE_6_DIGITS__INVALID` | `CODE_6_DIGITS__LENGTH` | `CODE_6_DIGITS__INVALID_FORMAT` | `EMAIL__INVALID` | `EMAIL__MIN_LENGTH` | `EMAIL__MAX_LENGTH` | `FIRST_NAME__INVALID` | `FIRST_NAME__MIN_LENGTH` | `FIRST_NAME__MAX_LENGTH` | `LAST_NAME__INVALID` | `LAST_NAME__MAX_LENGTH` | `TURNSTILE_TOKEN__INVALID` | `TURNSTILE_TOKEN__MIN_LENGTH` | `TURNSTILE_TOKEN__MAX_LENGTH` | `CONFIRM_PASSWORD__DONT_MATCH` | `LOGOUT_OTHER_SESSIONS__INVALID` | `REMEMBER_ME__INVALID` | `SLUG__MIN_LENGTH` | `SLUG__MAX_LENGTH` | `SLUG__NAME__MIN_LENGTH` | `SLUG__NAME__MAX_LENGTH` | `SLUG__DESCRIPTION__MIN_LENGTH` | `SLUG__DESCRIPTION__MAX_LENGTH` | `SLUG__INVALID` | `USERNAME__INVALID` | `USERNAME__MIN_LENGTH` | `USERNAME__MAX_LENGTH` | `DESIGNATION__INVALID` | `DESIGNATION_MAX_LENGTH` | `BIO__INVALID` | `BIO_MAX_LENGTH` | `PROFILE_VISIBILITY__INVALID` | `ID__INVALID`;
|
|
2
|
+
//# sourceMappingURL=EApiCodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EApiCodes.d.ts","sourceRoot":"","sources":["../src/EApiCodes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,WAAW,GAClC,SAAS,GACT,SAAS,GACT,SAAS,GACT,SAAS,GACT,WAAW,GACX,eAAe,GACf,SAAS,GACT,aAAa,GACb,YAAY,GACZ,cAAc,GACd,WAAW,GACX,WAAW,GACX,uBAAuB,GACvB,mBAAmB,GACnB,wBAAwB,GACxB,yBAAyB,GACzB,4BAA4B,GAC5B,mBAAmB,GACnB,sBAAsB,GACtB,sBAAsB,GACtB,wBAAwB,GACxB,uBAAuB,GACvB,wBAAwB,GACxB,uBAAuB,GACvB,+BAA+B,GAC/B,gBAAgB,GAChB,mBAAmB,GACnB,mBAAmB,GACnB,qBAAqB,GACrB,wBAAwB,GACxB,wBAAwB,GACxB,oBAAoB,GACpB,uBAAuB,GACvB,0BAA0B,GAC1B,6BAA6B,GAC7B,6BAA6B,GAC7B,8BAA8B,GAC9B,gCAAgC,GAChC,sBAAsB,GACtB,kBAAkB,GAClB,kBAAkB,GAClB,wBAAwB,GACxB,wBAAwB,GACxB,+BAA+B,GAC/B,+BAA+B,GAC/B,eAAe,GACf,mBAAmB,GACnB,sBAAsB,GACtB,sBAAsB,GACtB,sBAAsB,GACtB,wBAAwB,GACxB,cAAc,GACd,gBAAgB,GAChB,6BAA6B,GAC7B,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EApiCodes.js","sourceRoot":"","sources":["../src/EApiCodes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { EApiCodes } from "./EApiCodes.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base error type for API responses.
|
|
4
|
+
* Extends {@link Error} with an HTTP status code and an API error code.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ApiError extends Error {
|
|
7
|
+
status: number;
|
|
8
|
+
message: EApiCodes;
|
|
9
|
+
retryAfterDate: Date | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* @param status - HTTP status code associated with the error.
|
|
12
|
+
* @param message - API error code (defaults to `API_ERROR`).
|
|
13
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
14
|
+
* @param retryAfterDate - Optional date used for rate-limit responses (e.g. `429`).
|
|
15
|
+
*/
|
|
16
|
+
constructor(status: number, message?: EApiCodes, stack?: string, retryAfterDate?: Date);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 500 Internal Server Error.
|
|
20
|
+
*/
|
|
21
|
+
export declare class InternalServerError extends ApiError {
|
|
22
|
+
/**
|
|
23
|
+
* @param message - API error code (defaults to `INTERNAL_SERVER_ERROR`).
|
|
24
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
25
|
+
*/
|
|
26
|
+
constructor(message?: EApiCodes, stack?: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 429 Too Many Requests.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TooManyRequests extends ApiError {
|
|
32
|
+
/**
|
|
33
|
+
* @param message - API error code (defaults to `TOO_MANY_REQUESTS`).
|
|
34
|
+
* @param retryAfterDate - Optional date when clients may retry.
|
|
35
|
+
*/
|
|
36
|
+
constructor(message?: EApiCodes, retryAfterDate?: Date);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 400 Bad Request.
|
|
40
|
+
*/
|
|
41
|
+
export declare class BadRequest extends ApiError {
|
|
42
|
+
/**
|
|
43
|
+
* @param message - API error code (defaults to `BAD_REQUEST`).
|
|
44
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
45
|
+
*/
|
|
46
|
+
constructor(message?: EApiCodes, stack?: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 403 Forbidden.
|
|
50
|
+
*/
|
|
51
|
+
export declare class Forbidden extends ApiError {
|
|
52
|
+
/**
|
|
53
|
+
* @param message - API error code (defaults to `FORBIDDEN`).
|
|
54
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
55
|
+
*/
|
|
56
|
+
constructor(message?: EApiCodes, stack?: string);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 401 Unauthorized.
|
|
60
|
+
*/
|
|
61
|
+
export declare class Unauthorized extends ApiError {
|
|
62
|
+
/**
|
|
63
|
+
* @param message - API error code (defaults to `UNAUTHORIZED`).
|
|
64
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
65
|
+
*/
|
|
66
|
+
constructor(message?: EApiCodes, stack?: string);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 404 Not Found.
|
|
70
|
+
*/
|
|
71
|
+
export declare class NotFound extends ApiError {
|
|
72
|
+
/**
|
|
73
|
+
* @param message - API error code (defaults to `NOT_FOUND`).
|
|
74
|
+
* @param stack - Optional stack trace override (empty string means "use default").
|
|
75
|
+
*/
|
|
76
|
+
constructor(message?: EApiCodes, stack?: string);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ErrorClasses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorClasses.d.ts","sourceRoot":"","sources":["../src/ErrorClasses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,SAAS,CAAC;IACnB,cAAc,EAAE,IAAI,GAAG,SAAS,CAAC;IAEjC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,SAAK,EAAE,cAAc,CAAC,EAAE,IAAI;CAQlF;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAChD;;;OAGG;gBACS,OAAO,GAAE,SAAmC,EAAE,KAAK,SAAK;CAKpE;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;IAC5C;;;OAGG;gBACS,OAAO,GAAE,SAA+B,EAAE,cAAc,CAAC,EAAE,IAAI;CAG3E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IACvC;;;OAGG;gBACS,OAAO,GAAE,SAAyB,EAAE,KAAK,SAAK;CAK1D;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,QAAQ;IACtC;;;OAGG;gBACS,OAAO,GAAE,SAAuB,EAAE,KAAK,SAAK;CAKxD;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IACzC;;;OAGG;gBACS,OAAO,GAAE,SAA0B,EAAE,KAAK,SAAK;CAK3D;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,QAAQ;IACrC;;;OAGG;gBACS,OAAO,GAAE,SAAuB,EAAE,KAAK,SAAK;CAKxD"}
|