@mrxsys/mrx-core 2.12.0 → 2.13.0-1-and-295-20260130
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/{chunk-m3grz32t.js → chunk-6fs5g367.js} +21 -5
- package/dist/{chunk-zv4ta4fb.js → chunk-6vw01zwm.js} +1 -1
- package/dist/chunk-gcktbkx5.js +13 -0
- package/dist/{chunk-en814zzk.js → chunk-jncnz1ye.js} +1 -1
- package/dist/chunk-kcy9f0ey.js +17 -0
- package/dist/{chunk-j7dyc5ks.js → chunk-mhxpm2q3.js} +56 -12
- package/dist/chunk-pvrb2v8j.js +14 -0
- package/dist/{chunk-r7yr9p57.js → chunk-qqv7wea5.js} +7 -4
- package/dist/{chunk-p929454t.js → chunk-saxgy6vj.js} +14 -9
- package/dist/{chunk-sqts8vyk.js → chunk-t2ed3f49.js} +9 -0
- package/dist/errors/enums/http-status-codes.d.ts +9 -0
- package/dist/errors/enums/index.js +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +2 -2
- package/dist/modules/database/index.js +4 -4
- package/dist/modules/elysia/cache/index.js +2 -2
- package/dist/modules/elysia/db-resolver/index.js +5 -5
- package/dist/modules/elysia/error/index.js +2 -2
- package/dist/modules/elysia/rate-limit/index.js +4 -4
- package/dist/modules/jwt/enums/index.js +1 -1
- package/dist/modules/jwt/enums/jwt-error-keys.d.ts +8 -3
- package/dist/modules/jwt/index.d.ts +1 -1
- package/dist/modules/jwt/index.js +31 -11
- package/dist/modules/jwt/jwt.d.ts +42 -1
- package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +32 -0
- package/dist/modules/kv-store/bun-redis/index.js +49 -10
- package/dist/modules/kv-store/enums/index.js +1 -1
- package/dist/modules/kv-store/enums/kv-store-error-keys.d.ts +7 -3
- package/dist/modules/kv-store/ioredis/index.js +45 -6
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +32 -0
- package/dist/modules/kv-store/memory/index.js +2 -2
- package/dist/modules/kv-store/memory/memory-store.d.ts +30 -1
- package/dist/modules/kv-store/memory/types/memory-store-entry.d.ts +1 -1
- package/dist/modules/logger/index.js +32 -22
- package/dist/modules/logger/logger.d.ts +1 -1
- package/dist/modules/logger/sinks/file-logger.d.ts +14 -0
- package/dist/modules/logger/sinks/index.d.ts +1 -2
- package/dist/modules/logger/sinks/index.js +8 -33
- package/dist/modules/repository/index.js +3 -3
- package/dist/modules/repository/repository.d.ts +2 -1
- package/dist/modules/singleton-manager/index.js +1 -1
- package/dist/modules/singleton-manager/singleton-manager.d.ts +5 -0
- package/dist/modules/totp/enums/index.js +1 -1
- package/dist/modules/totp/enums/totp-error-keys.d.ts +11 -5
- package/dist/modules/totp/hotp.d.ts +15 -2
- package/dist/modules/totp/index.d.ts +1 -1
- package/dist/modules/totp/index.js +71 -18
- package/dist/modules/totp/otp-auth-uri.d.ts +7 -0
- package/dist/modules/totp/totp.d.ts +11 -3
- package/dist/modules/totp/types/index.d.ts +8 -0
- package/dist/modules/totp/types/otp-auth-uri.d.ts +1 -1
- package/dist/modules/totp/types/verify-options.d.ts +1 -1
- package/dist/modules/totp/utils/base32.d.ts +10 -1
- package/dist/modules/totp/utils/create-counter-buffer.d.ts +9 -1
- package/dist/modules/totp/utils/dynamic-truncation.d.ts +6 -3
- package/dist/modules/totp/utils/index.js +27 -17
- package/package.json +74 -74
- package/dist/chunk-8pw0syzf.js +0 -9
- package/dist/chunk-hwfebx4x.js +0 -11
- package/dist/chunk-zn2nm5gg.js +0 -9
- package/dist/modules/logger/sinks/file-logger/enums/file-logger-error-keys.d.ts +0 -3
- package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +0 -25
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
TOTP_ERROR_KEYS
|
|
4
|
+
} from "./chunk-kcy9f0ey.js";
|
|
5
|
+
import {
|
|
6
|
+
InternalError
|
|
7
|
+
} from "./chunk-jz3wd472.js";
|
|
8
|
+
|
|
2
9
|
// source/modules/totp/utils/create-counter-buffer.ts
|
|
3
10
|
var createCounterBuffer = (counter) => {
|
|
4
11
|
const counterBuffer = new ArrayBuffer(8);
|
|
5
12
|
const counterView = new DataView(counterBuffer);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else
|
|
9
|
-
counterView.setUint32(4, counter, false);
|
|
13
|
+
const counterBigInt = typeof counter === "bigint" ? counter : BigInt(Math.floor(counter));
|
|
14
|
+
counterView.setBigUint64(0, counterBigInt, false);
|
|
10
15
|
return counterBuffer;
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
// source/modules/totp/utils/dynamic-truncation.ts
|
|
19
|
+
var _DIGIT_MODULO = {
|
|
20
|
+
6: 1e6,
|
|
21
|
+
8: 1e8
|
|
22
|
+
};
|
|
14
23
|
var dynamicTruncation = (hmacArray, digits) => {
|
|
24
|
+
if (hmacArray.length < 20)
|
|
25
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_HMAC_LENGTH, "HMAC must be at least 20 bytes");
|
|
26
|
+
const modulo = _DIGIT_MODULO[digits];
|
|
27
|
+
if (modulo === undefined)
|
|
28
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_DIGITS, "Digits must be 6 or 8");
|
|
15
29
|
const offset = hmacArray[hmacArray.length - 1] & 15;
|
|
16
|
-
|
|
30
|
+
if (offset + 4 > hmacArray.length)
|
|
31
|
+
throw new InternalError(TOTP_ERROR_KEYS.INVALID_HMAC_LENGTH, "HMAC too short for computed offset");
|
|
32
|
+
const code = ((hmacArray[offset] & 127) << 24 | (hmacArray[offset + 1] & 255) << 16 | (hmacArray[offset + 2] & 255) << 8 | hmacArray[offset + 3] & 255) % modulo;
|
|
17
33
|
return code.toString().padStart(digits, "0");
|
|
18
34
|
};
|
|
19
35
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/kv-store/enums/kv-store-error-keys.ts
|
|
3
|
+
var KV_STORE_ERROR_KEYS = {
|
|
4
|
+
CLOSING_CONNECTION_FAILED: "nowarajs.kv-store.error.closing_connection_failed",
|
|
5
|
+
CONNECTION_FAILED: "nowarajs.kv-store.error.connection_failed",
|
|
6
|
+
INVALID_AMOUNT: "nowarajs.kv-store.error.invalid_amount",
|
|
7
|
+
INVALID_KEY: "nowarajs.kv-store.error.invalid_key",
|
|
8
|
+
INVALID_TTL: "nowarajs.kv-store.error.invalid_ttl",
|
|
9
|
+
NOT_INTEGER: "nowarajs.kv-store.error.not_integer",
|
|
10
|
+
STORE_FULL: "nowarajs.kv-store.error.store_full"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { KV_STORE_ERROR_KEYS };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/totp/enums/totp-error-keys.ts
|
|
3
|
+
var TOTP_ERROR_KEYS = {
|
|
4
|
+
INVALID_ALGORITHM: "nowarajs.totp.error.invalid_algorithm",
|
|
5
|
+
INVALID_BASE32_CHARACTER: "nowarajs.totp.error.invalid_base32_character",
|
|
6
|
+
INVALID_DIGITS: "nowarajs.totp.error.invalid_digits",
|
|
7
|
+
INVALID_HMAC_LENGTH: "nowarajs.totp.error.invalid_hmac_length",
|
|
8
|
+
INVALID_OTP_AUTH_URI: "nowarajs.totp.error.invalid_otp_auth_uri",
|
|
9
|
+
INVALID_PERIOD: "nowarajs.totp.error.invalid_period",
|
|
10
|
+
INVALID_SECRET_LENGTH: "nowarajs.totp.error.invalid_secret_length",
|
|
11
|
+
INVALID_WINDOW: "nowarajs.totp.error.invalid_window",
|
|
12
|
+
MISSING_LABEL: "nowarajs.totp.error.missing_label",
|
|
13
|
+
MISSING_SECRET: "nowarajs.totp.error.missing_secret",
|
|
14
|
+
WEAK_SECRET: "nowarajs.totp.error.weak_secret"
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { TOTP_ERROR_KEYS };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
KV_STORE_ERROR_KEYS
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-gcktbkx5.js";
|
|
5
5
|
import {
|
|
6
6
|
InternalError
|
|
7
7
|
} from "./chunk-jz3wd472.js";
|
|
@@ -10,12 +10,15 @@ import {
|
|
|
10
10
|
class MemoryStore {
|
|
11
11
|
_store = new Map;
|
|
12
12
|
_cleanupInterval;
|
|
13
|
+
_maxSize;
|
|
13
14
|
_cleanupTimer = null;
|
|
14
|
-
constructor(cleanupIntervalMs) {
|
|
15
|
+
constructor(cleanupIntervalMs, maxSize) {
|
|
15
16
|
this._cleanupInterval = cleanupIntervalMs ?? 300000;
|
|
17
|
+
this._maxSize = maxSize ?? Infinity;
|
|
16
18
|
this._startCleanup();
|
|
17
19
|
}
|
|
18
20
|
get(key) {
|
|
21
|
+
this._validateKey(key);
|
|
19
22
|
const entry = this._store.get(key);
|
|
20
23
|
if (!entry)
|
|
21
24
|
return null;
|
|
@@ -27,35 +30,60 @@ class MemoryStore {
|
|
|
27
30
|
return entry.value;
|
|
28
31
|
}
|
|
29
32
|
set(key, value, ttlSec) {
|
|
33
|
+
this._validateKey(key);
|
|
34
|
+
this._validateTtl(ttlSec);
|
|
35
|
+
if (this._store.size >= this._maxSize && !this._store.has(key))
|
|
36
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.STORE_FULL);
|
|
30
37
|
const expiresAt = ttlSec ? Date.now() + ttlSec * 1000 : -1;
|
|
31
38
|
this._store.set(key, { value, expiresAt });
|
|
32
39
|
}
|
|
33
40
|
increment(key, amount = 1) {
|
|
34
|
-
|
|
41
|
+
this._validateKey(key);
|
|
42
|
+
this._validateAmount(amount);
|
|
35
43
|
const entry = this._store.get(key);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
let currentValue = 0;
|
|
46
|
+
let expiresAt = -1;
|
|
47
|
+
if (entry)
|
|
48
|
+
if (entry.expiresAt !== -1 && now > entry.expiresAt) {
|
|
49
|
+
this._store.delete(key);
|
|
50
|
+
} else {
|
|
51
|
+
if (entry.value !== null && typeof entry.value !== "number")
|
|
52
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
53
|
+
currentValue = entry.value ?? 0;
|
|
54
|
+
({ expiresAt } = entry);
|
|
55
|
+
}
|
|
39
56
|
const newValue = currentValue + amount;
|
|
40
|
-
const expiresAt = entry ? entry.expiresAt : -1;
|
|
41
57
|
this._store.set(key, { value: newValue, expiresAt });
|
|
42
58
|
return newValue;
|
|
43
59
|
}
|
|
44
60
|
decrement(key, amount = 1) {
|
|
45
|
-
|
|
61
|
+
this._validateKey(key);
|
|
62
|
+
this._validateAmount(amount);
|
|
46
63
|
const entry = this._store.get(key);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
let currentValue = 0;
|
|
66
|
+
let expiresAt = -1;
|
|
67
|
+
if (entry)
|
|
68
|
+
if (entry.expiresAt !== -1 && now > entry.expiresAt) {
|
|
69
|
+
this._store.delete(key);
|
|
70
|
+
} else {
|
|
71
|
+
if (entry.value !== null && typeof entry.value !== "number")
|
|
72
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
73
|
+
currentValue = entry.value ?? 0;
|
|
74
|
+
({ expiresAt } = entry);
|
|
75
|
+
}
|
|
50
76
|
const newValue = currentValue - amount;
|
|
51
|
-
const expiresAt = entry ? entry.expiresAt : -1;
|
|
52
77
|
this._store.set(key, { value: newValue, expiresAt });
|
|
53
78
|
return newValue;
|
|
54
79
|
}
|
|
55
80
|
del(key) {
|
|
81
|
+
this._validateKey(key);
|
|
56
82
|
return this._store.delete(key);
|
|
57
83
|
}
|
|
58
84
|
expire(key, ttlSec) {
|
|
85
|
+
this._validateKey(key);
|
|
86
|
+
this._validateTtl(ttlSec);
|
|
59
87
|
const entry = this._store.get(key);
|
|
60
88
|
if (!entry)
|
|
61
89
|
return false;
|
|
@@ -63,6 +91,7 @@ class MemoryStore {
|
|
|
63
91
|
return true;
|
|
64
92
|
}
|
|
65
93
|
ttl(key) {
|
|
94
|
+
this._validateKey(key);
|
|
66
95
|
const entry = this._store.get(key);
|
|
67
96
|
if (!entry)
|
|
68
97
|
return -1;
|
|
@@ -82,6 +111,7 @@ class MemoryStore {
|
|
|
82
111
|
this._cleanupTimer = setInterval(() => {
|
|
83
112
|
this._removeExpiredEntries();
|
|
84
113
|
}, this._cleanupInterval);
|
|
114
|
+
this._cleanupTimer.unref();
|
|
85
115
|
}
|
|
86
116
|
_removeExpiredEntries() {
|
|
87
117
|
const now = Date.now();
|
|
@@ -96,6 +126,20 @@ class MemoryStore {
|
|
|
96
126
|
}
|
|
97
127
|
this._store.clear();
|
|
98
128
|
}
|
|
129
|
+
_validateKey(key) {
|
|
130
|
+
if (!key || typeof key !== "string" || key.length > 1024 || key.includes("\x00"))
|
|
131
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.INVALID_KEY);
|
|
132
|
+
}
|
|
133
|
+
_validateTtl(ttlSec) {
|
|
134
|
+
if (ttlSec === undefined)
|
|
135
|
+
return;
|
|
136
|
+
if (!Number.isFinite(ttlSec) || ttlSec <= 0 || !Number.isInteger(ttlSec))
|
|
137
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.INVALID_TTL);
|
|
138
|
+
}
|
|
139
|
+
_validateAmount(amount) {
|
|
140
|
+
if (!Number.isFinite(amount) || !Number.isInteger(amount))
|
|
141
|
+
throw new InternalError(KV_STORE_ERROR_KEYS.INVALID_AMOUNT);
|
|
142
|
+
}
|
|
99
143
|
}
|
|
100
144
|
|
|
101
145
|
export { MemoryStore };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/jwt/enums/jwt-error-keys.ts
|
|
3
|
+
var JWT_ERROR_KEYS = {
|
|
4
|
+
JWT_EXPIRATION_PASSED: "nowarajs.jwt.error.expiration_passed",
|
|
5
|
+
JWT_SECRET_TOO_WEAK: "nowarajs.jwt.error.secret_too_weak",
|
|
6
|
+
JWT_SIGN_ERROR: "nowarajs.jwt.error.sign_error",
|
|
7
|
+
JWT_EXPIRED: "nowarajs.jwt.error.token_expired",
|
|
8
|
+
JWT_CLAIM_VALIDATION_FAILED: "nowarajs.jwt.error.claim_validation_failed",
|
|
9
|
+
JWT_INVALID_SIGNATURE: "nowarajs.jwt.error.invalid_signature",
|
|
10
|
+
JWT_MALFORMED: "nowarajs.jwt.error.malformed_token",
|
|
11
|
+
JWT_VERIFICATION_FAILED: "nowarajs.jwt.error.verification_failed"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { JWT_ERROR_KEYS };
|
|
@@ -15,18 +15,21 @@ class SingletonManager {
|
|
|
15
15
|
this._registry.set(name, instance);
|
|
16
16
|
}
|
|
17
17
|
static unregister(name) {
|
|
18
|
-
if (!this._registry.
|
|
18
|
+
if (!this._registry.delete(name))
|
|
19
19
|
throw new InternalError(SINGLETON_MANAGER_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED, { name });
|
|
20
|
-
this._registry.delete(name);
|
|
21
20
|
}
|
|
22
21
|
static get(name) {
|
|
23
|
-
|
|
22
|
+
const instance = this._registry.get(name);
|
|
23
|
+
if (!instance)
|
|
24
24
|
throw new InternalError(SINGLETON_MANAGER_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED, { name });
|
|
25
|
-
return
|
|
25
|
+
return instance;
|
|
26
26
|
}
|
|
27
27
|
static has(name) {
|
|
28
28
|
return this._registry.has(name);
|
|
29
29
|
}
|
|
30
|
+
static clear() {
|
|
31
|
+
this._registry.clear();
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export { SingletonManager };
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-grfyngq0.js";
|
|
6
6
|
import {
|
|
7
7
|
HttpError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6vw01zwm.js";
|
|
9
9
|
import {
|
|
10
10
|
InternalError
|
|
11
11
|
} from "./chunk-jz3wd472.js";
|
|
@@ -92,7 +92,7 @@ class Repository {
|
|
|
92
92
|
kStream.pipe(passThrough);
|
|
93
93
|
return makeStreamAsyncIterable(passThrough);
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
find(options) {
|
|
96
96
|
const query = this.knex(this.table.name);
|
|
97
97
|
this._applyQueryOptions(query, options);
|
|
98
98
|
const limit = options?.limit || _DEFAULT_LIMIT;
|
|
@@ -100,7 +100,7 @@ class Repository {
|
|
|
100
100
|
query.limit(limit).offset(offset);
|
|
101
101
|
return this._executeQuery(query, options?.throwIfNoResult);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
count(options) {
|
|
104
104
|
const query = this.knex(this.table.name).count({ count: "*" });
|
|
105
105
|
if (options?.filters)
|
|
106
106
|
this._applyFilter(query, options?.filters);
|
|
@@ -108,13 +108,13 @@ class Repository {
|
|
|
108
108
|
query.transacting(options.transaction);
|
|
109
109
|
return this._executeQuery(query, options?.throwIfNoResult).then((result) => result[0].count);
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
insert(data, options) {
|
|
112
112
|
const query = this.knex(this.table.name).insert(data).returning(options?.selectedFields ?? "*");
|
|
113
113
|
if (options?.transaction)
|
|
114
114
|
query.transacting(options.transaction);
|
|
115
115
|
return this._executeQuery(query);
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
update(data, options) {
|
|
118
118
|
const query = this.knex(this.table.name).update(data);
|
|
119
119
|
this._applyQueryOptions(query, options);
|
|
120
120
|
if (options.limit)
|
|
@@ -123,7 +123,7 @@ class Repository {
|
|
|
123
123
|
query.offset(options.offset);
|
|
124
124
|
return this._executeQuery(query, options?.throwIfNoResult);
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
delete(options) {
|
|
127
127
|
const query = this.knex(this.table.name).delete();
|
|
128
128
|
this._applyQueryOptions(query, options);
|
|
129
129
|
return this._executeQuery(query, options?.throwIfNoResult);
|
|
@@ -148,13 +148,13 @@ class Repository {
|
|
|
148
148
|
for (const field of this.table.fields)
|
|
149
149
|
if (prop)
|
|
150
150
|
query2.orWhere(field, "like", `%${prop}%`);
|
|
151
|
-
} else if (key === "$q" && this._isGlobalSearchObject(prop))
|
|
151
|
+
} else if (key === "$q" && this._isGlobalSearchObject(prop))
|
|
152
152
|
if (Array.isArray(prop.selectedFields))
|
|
153
153
|
for (const field of prop.selectedFields)
|
|
154
154
|
query2.orWhere(field, "like", `%${prop.value}%`);
|
|
155
155
|
else
|
|
156
156
|
query2.orWhere(prop.selectedFields, "like", `%${prop.value}%`);
|
|
157
|
-
|
|
157
|
+
else {
|
|
158
158
|
if (prop !== null && typeof prop === "object" && Object.keys(prop).length === 0)
|
|
159
159
|
continue;
|
|
160
160
|
if (prop !== undefined)
|
|
@@ -198,7 +198,12 @@ class Repository {
|
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
_isAdaptiveWhereClause(data) {
|
|
201
|
-
|
|
201
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
202
|
+
return false;
|
|
203
|
+
for (const key in data)
|
|
204
|
+
if (_validOperatorKeys.has(key))
|
|
205
|
+
return true;
|
|
206
|
+
return false;
|
|
202
207
|
}
|
|
203
208
|
_isGlobalSearchObject(data) {
|
|
204
209
|
return Boolean(data && typeof data === "object" && "selectedFields" in data && "value" in data);
|
|
@@ -15,6 +15,15 @@ var HTTP_STATUS_CODES = {
|
|
|
15
15
|
MULTI_STATUS: 207,
|
|
16
16
|
ALREADY_REPORTED: 208,
|
|
17
17
|
IM_USED: 226,
|
|
18
|
+
MULTIPLE_CHOICES: 300,
|
|
19
|
+
MOVED_PERMANENTLY: 301,
|
|
20
|
+
FOUND: 302,
|
|
21
|
+
SEE_OTHER: 303,
|
|
22
|
+
NOT_MODIFIED: 304,
|
|
23
|
+
USE_PROXY: 305,
|
|
24
|
+
SWITCH_PROXY: 306,
|
|
25
|
+
TEMPORARY_REDIRECT: 307,
|
|
26
|
+
PERMANENT_REDIRECT: 308,
|
|
18
27
|
BAD_REQUEST: 400,
|
|
19
28
|
UNAUTHORIZED: 401,
|
|
20
29
|
PAYMENT_REQUIRED: 402,
|
|
@@ -13,6 +13,15 @@ export declare const HTTP_STATUS_CODES: {
|
|
|
13
13
|
readonly MULTI_STATUS: 207;
|
|
14
14
|
readonly ALREADY_REPORTED: 208;
|
|
15
15
|
readonly IM_USED: 226;
|
|
16
|
+
readonly MULTIPLE_CHOICES: 300;
|
|
17
|
+
readonly MOVED_PERMANENTLY: 301;
|
|
18
|
+
readonly FOUND: 302;
|
|
19
|
+
readonly SEE_OTHER: 303;
|
|
20
|
+
readonly NOT_MODIFIED: 304;
|
|
21
|
+
readonly USE_PROXY: 305;
|
|
22
|
+
readonly SWITCH_PROXY: 306;
|
|
23
|
+
readonly TEMPORARY_REDIRECT: 307;
|
|
24
|
+
readonly PERMANENT_REDIRECT: 308;
|
|
16
25
|
readonly BAD_REQUEST: 400;
|
|
17
26
|
readonly UNAUTHORIZED: 401;
|
|
18
27
|
readonly PAYMENT_REQUIRED: 402;
|
package/dist/errors/index.d.ts
CHANGED
package/dist/errors/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
MSSQL,
|
|
4
4
|
Table
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import"../../chunk-
|
|
5
|
+
} from "../../chunk-jncnz1ye.js";
|
|
6
|
+
import"../../chunk-saxgy6vj.js";
|
|
7
7
|
import"../../chunk-grfyngq0.js";
|
|
8
8
|
import"../../chunk-mvrxngm7.js";
|
|
9
|
-
import"../../chunk-
|
|
10
|
-
import"../../chunk-
|
|
9
|
+
import"../../chunk-6vw01zwm.js";
|
|
10
|
+
import"../../chunk-t2ed3f49.js";
|
|
11
11
|
import"../../chunk-jz3wd472.js";
|
|
12
12
|
import"../../chunk-642xajvx.js";
|
|
13
13
|
export {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
MemoryStore
|
|
4
|
-
} from "../../../chunk-
|
|
5
|
-
import"../../../chunk-
|
|
4
|
+
} from "../../../chunk-mhxpm2q3.js";
|
|
5
|
+
import"../../../chunk-gcktbkx5.js";
|
|
6
6
|
import"../../../chunk-jz3wd472.js";
|
|
7
7
|
|
|
8
8
|
// source/modules/elysia/cache/cache.ts
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
SingletonManager
|
|
4
|
-
} from "../../../chunk-
|
|
4
|
+
} from "../../../chunk-qqv7wea5.js";
|
|
5
5
|
import"../../../chunk-y5dtkmnp.js";
|
|
6
6
|
import {
|
|
7
7
|
DB_RESOLVER_ERROR_KEYS
|
|
8
8
|
} from "../../../chunk-ayyrgqyv.js";
|
|
9
9
|
import {
|
|
10
10
|
MSSQL
|
|
11
|
-
} from "../../../chunk-
|
|
12
|
-
import"../../../chunk-
|
|
11
|
+
} from "../../../chunk-jncnz1ye.js";
|
|
12
|
+
import"../../../chunk-saxgy6vj.js";
|
|
13
13
|
import"../../../chunk-grfyngq0.js";
|
|
14
14
|
import"../../../chunk-mvrxngm7.js";
|
|
15
|
-
import"../../../chunk-
|
|
16
|
-
import"../../../chunk-
|
|
15
|
+
import"../../../chunk-6vw01zwm.js";
|
|
16
|
+
import"../../../chunk-t2ed3f49.js";
|
|
17
17
|
import {
|
|
18
18
|
InternalError
|
|
19
19
|
} from "../../../chunk-jz3wd472.js";
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
import"../../../chunk-10w8mg8e.js";
|
|
9
9
|
import {
|
|
10
10
|
HttpError
|
|
11
|
-
} from "../../../chunk-
|
|
12
|
-
import"../../../chunk-
|
|
11
|
+
} from "../../../chunk-6vw01zwm.js";
|
|
12
|
+
import"../../../chunk-t2ed3f49.js";
|
|
13
13
|
import {
|
|
14
14
|
InternalError
|
|
15
15
|
} from "../../../chunk-jz3wd472.js";
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
} from "../../../chunk-2z8amjqt.js";
|
|
5
5
|
import {
|
|
6
6
|
MemoryStore
|
|
7
|
-
} from "../../../chunk-
|
|
8
|
-
import"../../../chunk-
|
|
7
|
+
} from "../../../chunk-mhxpm2q3.js";
|
|
8
|
+
import"../../../chunk-gcktbkx5.js";
|
|
9
9
|
import {
|
|
10
10
|
HttpError
|
|
11
|
-
} from "../../../chunk-
|
|
12
|
-
import"../../../chunk-
|
|
11
|
+
} from "../../../chunk-6vw01zwm.js";
|
|
12
|
+
import"../../../chunk-t2ed3f49.js";
|
|
13
13
|
import"../../../chunk-jz3wd472.js";
|
|
14
14
|
|
|
15
15
|
// source/modules/elysia/rate-limit/rate-limit.ts
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export declare const JWT_ERROR_KEYS: {
|
|
2
|
-
readonly JWT_EXPIRATION_PASSED: "
|
|
3
|
-
readonly
|
|
4
|
-
readonly JWT_SIGN_ERROR: "
|
|
2
|
+
readonly JWT_EXPIRATION_PASSED: "nowarajs.jwt.error.expiration_passed";
|
|
3
|
+
readonly JWT_SECRET_TOO_WEAK: "nowarajs.jwt.error.secret_too_weak";
|
|
4
|
+
readonly JWT_SIGN_ERROR: "nowarajs.jwt.error.sign_error";
|
|
5
|
+
readonly JWT_EXPIRED: "nowarajs.jwt.error.token_expired";
|
|
6
|
+
readonly JWT_CLAIM_VALIDATION_FAILED: "nowarajs.jwt.error.claim_validation_failed";
|
|
7
|
+
readonly JWT_INVALID_SIGNATURE: "nowarajs.jwt.error.invalid_signature";
|
|
8
|
+
readonly JWT_MALFORMED: "nowarajs.jwt.error.malformed_token";
|
|
9
|
+
readonly JWT_VERIFICATION_FAILED: "nowarajs.jwt.error.verification_failed";
|
|
5
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { signJWT, verifyJWT } from './jwt';
|
|
1
|
+
export { signJWT, verifyJWT, type VerifyOptions } from './jwt';
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
JWT_ERROR_KEYS
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-pvrb2v8j.js";
|
|
5
5
|
import {
|
|
6
6
|
parseHumanTimeToSeconds
|
|
7
7
|
} from "../../chunk-awphtyzp.js";
|
|
8
8
|
import"../../chunk-dmsev7vs.js";
|
|
9
|
+
import {
|
|
10
|
+
HttpError
|
|
11
|
+
} from "../../chunk-6vw01zwm.js";
|
|
12
|
+
import"../../chunk-t2ed3f49.js";
|
|
9
13
|
import {
|
|
10
14
|
InternalError
|
|
11
15
|
} from "../../chunk-jz3wd472.js";
|
|
@@ -13,34 +17,50 @@ import {
|
|
|
13
17
|
// source/modules/jwt/jwt.ts
|
|
14
18
|
import {
|
|
15
19
|
SignJWT,
|
|
20
|
+
errors,
|
|
16
21
|
jwtVerify
|
|
17
22
|
} from "jose";
|
|
23
|
+
var _textEncoder = new TextEncoder;
|
|
18
24
|
var signJWT = (secret, payload, expiration = 60 * 15) => {
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
if (secret.length < 32)
|
|
26
|
+
throw new InternalError(JWT_ERROR_KEYS.JWT_SECRET_TOO_WEAK);
|
|
27
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
28
|
+
const exp = expiration instanceof Date ? Math.floor(expiration.getTime() / 1000) : typeof expiration === "number" ? nowSeconds + expiration : nowSeconds + parseHumanTimeToSeconds(expiration);
|
|
29
|
+
if (exp <= nowSeconds)
|
|
21
30
|
throw new InternalError(JWT_ERROR_KEYS.JWT_EXPIRATION_PASSED);
|
|
22
31
|
const finalPayload = {
|
|
23
32
|
iss: "Core-Issuer",
|
|
24
33
|
sub: "",
|
|
25
34
|
aud: ["Core-Audience"],
|
|
26
35
|
jti: Bun.randomUUIDv7(),
|
|
27
|
-
nbf:
|
|
28
|
-
iat:
|
|
36
|
+
nbf: nowSeconds,
|
|
37
|
+
iat: nowSeconds,
|
|
29
38
|
exp,
|
|
30
39
|
...payload
|
|
31
40
|
};
|
|
32
41
|
try {
|
|
33
|
-
|
|
34
|
-
return jwt;
|
|
42
|
+
return new SignJWT(finalPayload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(_textEncoder.encode(secret));
|
|
35
43
|
} catch (error) {
|
|
36
44
|
throw new InternalError(JWT_ERROR_KEYS.JWT_SIGN_ERROR, error);
|
|
37
45
|
}
|
|
38
46
|
};
|
|
39
|
-
var verifyJWT = async (token, secret) => {
|
|
47
|
+
var verifyJWT = async (token, secret, options) => {
|
|
40
48
|
try {
|
|
41
|
-
return await jwtVerify(token,
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
return await jwtVerify(token, _textEncoder.encode(secret), {
|
|
50
|
+
algorithms: ["HS256"],
|
|
51
|
+
...options?.issuer && { issuer: options.issuer },
|
|
52
|
+
...options?.audience && { audience: options.audience }
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error instanceof errors.JWTExpired)
|
|
56
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_EXPIRED, "UNAUTHORIZED", error);
|
|
57
|
+
if (error instanceof errors.JWTClaimValidationFailed)
|
|
58
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_CLAIM_VALIDATION_FAILED, "UNAUTHORIZED", error);
|
|
59
|
+
if (error instanceof errors.JWSSignatureVerificationFailed)
|
|
60
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_INVALID_SIGNATURE, "UNAUTHORIZED", error);
|
|
61
|
+
if (error instanceof errors.JWTInvalid)
|
|
62
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_MALFORMED, "UNAUTHORIZED", error);
|
|
63
|
+
throw new HttpError(JWT_ERROR_KEYS.JWT_VERIFICATION_FAILED, "UNAUTHORIZED", error);
|
|
44
64
|
}
|
|
45
65
|
};
|
|
46
66
|
export {
|
|
@@ -1,3 +1,44 @@
|
|
|
1
1
|
import { type JWTPayload, type JWTVerifyResult } from 'jose';
|
|
2
|
+
export interface VerifyOptions {
|
|
3
|
+
issuer?: string;
|
|
4
|
+
audience?: string | string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Signs a JWT with the given payload and expiration
|
|
8
|
+
*
|
|
9
|
+
* @param secret - The secret key used for HS256 signing (minimum 32 characters)
|
|
10
|
+
* @param payload - The JWT payload claims
|
|
11
|
+
* @param expiration - Token expiration as seconds offset, Date, or human-readable string (default: 15 minutes)
|
|
12
|
+
*
|
|
13
|
+
* @throws ({@link InternalError}) – If secret is too short, expiration is in the past, or signing fails
|
|
14
|
+
*
|
|
15
|
+
* @returns A Promise resolving to the signed JWT string
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const token = await signJWT('my-secret-key-at-least-32-chars!', { userId: 123 }, '1 hour');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
2
22
|
export declare const signJWT: (secret: string, payload: JWTPayload, expiration?: number | string | Date) => Promise<string>;
|
|
3
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Verifies a JWT token and throws HttpError on failure
|
|
25
|
+
*
|
|
26
|
+
* @param token - The JWT token string to verify
|
|
27
|
+
* @param secret - The secret key used for HS256 verification
|
|
28
|
+
* @param options - Optional verification options for issuer/audience validation
|
|
29
|
+
*
|
|
30
|
+
* @throws ({@link HttpError}) – 401 if token is expired, invalid signature, malformed, or claim validation fails
|
|
31
|
+
*
|
|
32
|
+
* @returns The verification result with payload and protected header
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* try {
|
|
37
|
+
* const result = await verifyJWT(token, secret);
|
|
38
|
+
* console.log(result.payload);
|
|
39
|
+
* } catch (error) {
|
|
40
|
+
* // HttpError with appropriate message
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const verifyJWT: (token: string, secret: string, options?: VerifyOptions) => Promise<JWTVerifyResult>;
|