@mrxsys/mrx-core 2.12.0 → 2.13.0-1-and-293-20260113

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.
Files changed (62) hide show
  1. package/dist/{chunk-m3grz32t.js → chunk-6fs5g367.js} +21 -5
  2. package/dist/{chunk-zv4ta4fb.js → chunk-6vw01zwm.js} +1 -1
  3. package/dist/chunk-gcktbkx5.js +13 -0
  4. package/dist/chunk-kcy9f0ey.js +17 -0
  5. package/dist/{chunk-j7dyc5ks.js → chunk-mhxpm2q3.js} +56 -12
  6. package/dist/{chunk-en814zzk.js → chunk-pmcz5ege.js} +1 -1
  7. package/dist/chunk-pvrb2v8j.js +14 -0
  8. package/dist/{chunk-r7yr9p57.js → chunk-qqv7wea5.js} +7 -4
  9. package/dist/{chunk-sqts8vyk.js → chunk-t2ed3f49.js} +9 -0
  10. package/dist/{chunk-p929454t.js → chunk-yj7yz309.js} +7 -2
  11. package/dist/errors/enums/http-status-codes.d.ts +9 -0
  12. package/dist/errors/enums/index.js +1 -1
  13. package/dist/errors/index.d.ts +1 -1
  14. package/dist/errors/index.js +2 -2
  15. package/dist/modules/database/index.js +4 -4
  16. package/dist/modules/elysia/cache/index.js +2 -2
  17. package/dist/modules/elysia/db-resolver/index.js +5 -5
  18. package/dist/modules/elysia/error/index.js +2 -2
  19. package/dist/modules/elysia/rate-limit/index.js +4 -4
  20. package/dist/modules/jwt/enums/index.js +1 -1
  21. package/dist/modules/jwt/enums/jwt-error-keys.d.ts +8 -3
  22. package/dist/modules/jwt/index.d.ts +1 -1
  23. package/dist/modules/jwt/index.js +31 -11
  24. package/dist/modules/jwt/jwt.d.ts +42 -1
  25. package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +32 -0
  26. package/dist/modules/kv-store/bun-redis/index.js +49 -10
  27. package/dist/modules/kv-store/enums/index.js +1 -1
  28. package/dist/modules/kv-store/enums/kv-store-error-keys.d.ts +7 -3
  29. package/dist/modules/kv-store/ioredis/index.js +45 -6
  30. package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +32 -0
  31. package/dist/modules/kv-store/memory/index.js +2 -2
  32. package/dist/modules/kv-store/memory/memory-store.d.ts +30 -1
  33. package/dist/modules/kv-store/memory/types/memory-store-entry.d.ts +1 -1
  34. package/dist/modules/logger/index.js +23 -22
  35. package/dist/modules/logger/logger.d.ts +1 -1
  36. package/dist/modules/logger/sinks/file-logger.d.ts +14 -0
  37. package/dist/modules/logger/sinks/index.d.ts +1 -2
  38. package/dist/modules/logger/sinks/index.js +9 -34
  39. package/dist/modules/repository/index.js +3 -3
  40. package/dist/modules/repository/repository.d.ts +1 -0
  41. package/dist/modules/singleton-manager/index.js +1 -1
  42. package/dist/modules/singleton-manager/singleton-manager.d.ts +5 -0
  43. package/dist/modules/totp/enums/index.js +1 -1
  44. package/dist/modules/totp/enums/totp-error-keys.d.ts +11 -5
  45. package/dist/modules/totp/hotp.d.ts +15 -2
  46. package/dist/modules/totp/index.d.ts +1 -1
  47. package/dist/modules/totp/index.js +69 -14
  48. package/dist/modules/totp/otp-auth-uri.d.ts +7 -0
  49. package/dist/modules/totp/totp.d.ts +11 -3
  50. package/dist/modules/totp/types/index.d.ts +8 -0
  51. package/dist/modules/totp/types/otp-auth-uri.d.ts +1 -1
  52. package/dist/modules/totp/types/verify-options.d.ts +1 -1
  53. package/dist/modules/totp/utils/base32.d.ts +10 -1
  54. package/dist/modules/totp/utils/create-counter-buffer.d.ts +9 -1
  55. package/dist/modules/totp/utils/dynamic-truncation.d.ts +6 -3
  56. package/dist/modules/totp/utils/index.js +27 -17
  57. package/package.json +9 -9
  58. package/dist/chunk-8pw0syzf.js +0 -9
  59. package/dist/chunk-hwfebx4x.js +0 -11
  60. package/dist/chunk-zn2nm5gg.js +0 -9
  61. package/dist/modules/logger/sinks/file-logger/enums/file-logger-error-keys.d.ts +0 -3
  62. 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
- if (typeof counter === "bigint")
7
- counterView.setBigUint64(0, counter, false);
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
- const code = ((hmacArray[offset] & 127) << 24 | (hmacArray[offset + 1] & 255) << 16 | (hmacArray[offset + 2] & 255) << 8 | hmacArray[offset + 3] & 255) % 10 ** digits;
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
 
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  HTTP_STATUS_CODES
4
- } from "./chunk-sqts8vyk.js";
4
+ } from "./chunk-t2ed3f49.js";
5
5
  import {
6
6
  AppError
7
7
  } from "./chunk-jz3wd472.js";
@@ -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-8pw0syzf.js";
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
- const current = this.get(key);
41
+ this._validateKey(key);
42
+ this._validateAmount(amount);
35
43
  const entry = this._store.get(key);
36
- if (current !== null && typeof current !== "number")
37
- throw new InternalError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
38
- const currentValue = current ?? 0;
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
- const current = this.get(key);
61
+ this._validateKey(key);
62
+ this._validateAmount(amount);
46
63
  const entry = this._store.get(key);
47
- if (current !== null && typeof current !== "number")
48
- throw new InternalError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
49
- const currentValue = current ?? 0;
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 };
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  Repository
4
- } from "./chunk-p929454t.js";
4
+ } from "./chunk-yj7yz309.js";
5
5
  import {
6
6
  TypedEventEmitter
7
7
  } from "./chunk-mvrxngm7.js";
@@ -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.has(name))
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
- if (!this._registry.has(name))
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 this._registry.get(name);
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 };
@@ -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,
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-grfyngq0.js";
6
6
  import {
7
7
  HttpError
8
- } from "./chunk-zv4ta4fb.js";
8
+ } from "./chunk-6vw01zwm.js";
9
9
  import {
10
10
  InternalError
11
11
  } from "./chunk-jz3wd472.js";
@@ -198,7 +198,12 @@ class Repository {
198
198
  });
199
199
  }
200
200
  _isAdaptiveWhereClause(data) {
201
- return Boolean(data && typeof data === "object" && !Array.isArray(data) && Object.keys(data).some((key) => _validOperatorKeys.has(key)));
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);
@@ -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;
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  HTTP_STATUS_CODES
4
- } from "../../chunk-sqts8vyk.js";
4
+ } from "../../chunk-t2ed3f49.js";
5
5
  export {
6
6
  HTTP_STATUS_CODES
7
7
  };
@@ -1,3 +1,3 @@
1
1
  export { AppError } from './app-error';
2
- export { HttpError } from './http-error';
2
+ export { HttpError, type HttpStatusCode, type HttpStatusKey } from './http-error';
3
3
  export { InternalError } from './internal-error';
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  import {
3
3
  HttpError
4
- } from "../chunk-zv4ta4fb.js";
5
- import"../chunk-sqts8vyk.js";
4
+ } from "../chunk-6vw01zwm.js";
5
+ import"../chunk-t2ed3f49.js";
6
6
  import {
7
7
  AppError,
8
8
  InternalError
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  MSSQL,
4
4
  Table
5
- } from "../../chunk-en814zzk.js";
6
- import"../../chunk-p929454t.js";
5
+ } from "../../chunk-pmcz5ege.js";
6
+ import"../../chunk-yj7yz309.js";
7
7
  import"../../chunk-grfyngq0.js";
8
8
  import"../../chunk-mvrxngm7.js";
9
- import"../../chunk-zv4ta4fb.js";
10
- import"../../chunk-sqts8vyk.js";
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-j7dyc5ks.js";
5
- import"../../../chunk-8pw0syzf.js";
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-r7yr9p57.js";
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-en814zzk.js";
12
- import"../../../chunk-p929454t.js";
11
+ } from "../../../chunk-pmcz5ege.js";
12
+ import"../../../chunk-yj7yz309.js";
13
13
  import"../../../chunk-grfyngq0.js";
14
14
  import"../../../chunk-mvrxngm7.js";
15
- import"../../../chunk-zv4ta4fb.js";
16
- import"../../../chunk-sqts8vyk.js";
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-zv4ta4fb.js";
12
- import"../../../chunk-sqts8vyk.js";
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-j7dyc5ks.js";
8
- import"../../../chunk-8pw0syzf.js";
7
+ } from "../../../chunk-mhxpm2q3.js";
8
+ import"../../../chunk-gcktbkx5.js";
9
9
  import {
10
10
  HttpError
11
- } from "../../../chunk-zv4ta4fb.js";
12
- import"../../../chunk-sqts8vyk.js";
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,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  JWT_ERROR_KEYS
4
- } from "../../../chunk-zn2nm5gg.js";
4
+ } from "../../../chunk-pvrb2v8j.js";
5
5
  import {
6
6
  PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS
7
7
  } from "../../../chunk-dmsev7vs.js";
@@ -1,5 +1,10 @@
1
1
  export declare const JWT_ERROR_KEYS: {
2
- readonly JWT_EXPIRATION_PASSED: "mrx.mrx-core.jwt.error.expiration_passed";
3
- readonly JWT_SECRET_NOT_FOUND: "mrx.mrx-core.jwt.error.secret_not_found";
4
- readonly JWT_SIGN_ERROR: "mrx.mrx-core.jwt.error.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-zn2nm5gg.js";
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
- const exp = expiration instanceof Date ? Math.floor(expiration.getTime() / 1000) : typeof expiration === "number" ? Math.floor(Date.now() / 1000) + expiration : Math.floor(Date.now() / 1000) + parseHumanTimeToSeconds(expiration);
20
- if (exp <= Math.floor(Date.now() / 1000))
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: Math.floor(Date.now() / 1000),
28
- iat: Math.floor(Date.now() / 1000),
36
+ nbf: nowSeconds,
37
+ iat: nowSeconds,
29
38
  exp,
30
39
  ...payload
31
40
  };
32
41
  try {
33
- const jwt = new SignJWT(finalPayload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuer(finalPayload.iss).setSubject(finalPayload.sub).setAudience(finalPayload.aud).setJti(finalPayload.jti).setNotBefore(finalPayload.nbf).setIssuedAt(finalPayload.iat).setExpirationTime(exp).sign(new TextEncoder().encode(secret));
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, new TextEncoder().encode(secret));
42
- } catch {
43
- return false;
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
- export declare const verifyJWT: (token: string, secret: string) => Promise<JWTVerifyResult | false>;
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>;
@@ -22,4 +22,36 @@ export declare class BunRedisStore implements KvStore {
22
22
  expire(key: string, ttlSec: number): Promise<boolean>;
23
23
  ttl(key: string): Promise<number>;
24
24
  clean(): Promise<number>;
25
+ /**
26
+ * Validates that a key is a non-empty string with reasonable length.
27
+ *
28
+ * @param key - The key to validate.
29
+ *
30
+ * @throws ({@link InternalError}) – If the key is invalid.
31
+ */
32
+ private _validateKey;
33
+ /**
34
+ * Validates that a TTL value is a positive finite integer.
35
+ *
36
+ * @param ttlSec - The TTL value to validate.
37
+ *
38
+ * @throws ({@link InternalError}) – If the TTL is invalid.
39
+ */
40
+ private _validateTtl;
41
+ /**
42
+ * Validates that an increment/decrement amount is a finite integer.
43
+ *
44
+ * @param amount - The amount to validate.
45
+ *
46
+ * @throws ({@link InternalError}) – If the amount is invalid.
47
+ */
48
+ private _validateAmount;
49
+ /**
50
+ * Sanitizes parsed JSON to prevent prototype pollution attacks.
51
+ *
52
+ * @param value - The parsed value to sanitize.
53
+ *
54
+ * @returns The sanitized value.
55
+ */
56
+ private _sanitizePrototype;
25
57
  }