@guren/server 1.0.0-rc.9 → 1.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/dist/{Application-DtWDHXr1.d.ts → Application-BnsyCKXY.d.ts} +79 -8
- package/dist/AuthManager-SfhCNkAU.d.ts +79 -0
- package/dist/{BroadcastManager-AkIWUGJo.d.ts → BroadcastManager-CGWl9rUO.d.ts} +5 -0
- package/dist/{ConsoleKernel-CqCVrdZs.d.ts → ConsoleKernel-BDtBETjm.d.ts} +1 -1
- package/dist/{Gate-CNkBYf8m.d.ts → Gate-CynjZCtS.d.ts} +5 -0
- package/dist/{I18nManager-Dtgzsf5n.d.ts → I18nManager-BiSoczfV.d.ts} +6 -1
- package/dist/McpServiceProvider-JW6PDVMD.js +7 -0
- package/dist/api-token-BSSCLlFW.d.ts +541 -0
- package/dist/auth/index.d.ts +9 -327
- package/dist/auth/index.js +59 -6684
- package/dist/authorization/index.d.ts +2 -2
- package/dist/authorization/index.js +19 -604
- package/dist/broadcasting/index.d.ts +2 -2
- package/dist/broadcasting/index.js +12 -895
- package/dist/cache/index.js +8 -809
- package/dist/chunk-2T6JN4VR.js +1563 -0
- package/dist/chunk-44F7JQ7I.js +950 -0
- package/dist/chunk-74HTZG3V.js +331 -0
- package/dist/chunk-A3ISJVEV.js +598 -0
- package/dist/chunk-CSDKWLFD.js +652 -0
- package/dist/chunk-CSRQTEQA.js +839 -0
- package/dist/chunk-DAQKYKLH.js +182 -0
- package/dist/chunk-EDRGAM6G.js +647 -0
- package/dist/chunk-EGU5KB7V.js +818 -0
- package/dist/chunk-H32L2NE3.js +372 -0
- package/dist/chunk-HKQSAFSN.js +837 -0
- package/dist/chunk-IOTWFHZU.js +558 -0
- package/dist/chunk-ONSDE37A.js +125 -0
- package/dist/chunk-QQKTH5KX.js +114 -0
- package/dist/chunk-R2TCP7D7.js +409 -0
- package/dist/chunk-SIP34GBE.js +380 -0
- package/dist/chunk-THSX7OOR.js +454 -0
- package/dist/chunk-UY3AZSYL.js +14 -0
- package/dist/chunk-VT5KRDPH.js +134 -0
- package/dist/chunk-VXXZIXAP.js +255 -0
- package/dist/chunk-WJJ5CTNI.js +907 -0
- package/dist/chunk-WVY45EIW.js +359 -0
- package/dist/chunk-ZRBLZY3M.js +462 -0
- package/dist/client-CKXJLsTe.d.ts +232 -0
- package/dist/email-verification-CAeArjui.d.ts +327 -0
- package/dist/encryption/index.js +48 -556
- package/dist/errors-JOOPDDQ6.js +34 -0
- package/dist/events/index.js +14 -316
- package/dist/health/index.js +12 -367
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +14 -583
- package/dist/index.d.ts +37 -239
- package/dist/index.js +2873 -19166
- package/dist/lambda/index.d.ts +9 -7
- package/dist/lambda/index.js +4 -9
- package/dist/logging/index.js +12 -545
- package/dist/mail/index.d.ts +29 -1
- package/dist/mail/index.js +15 -684
- package/dist/mcp/index.d.ts +7 -5
- package/dist/mcp/index.js +5 -378
- package/dist/notifications/index.d.ts +8 -6
- package/dist/notifications/index.js +13 -730
- package/dist/queue/index.d.ts +37 -7
- package/dist/queue/index.js +22 -940
- package/dist/redis/index.d.ts +366 -0
- package/dist/redis/index.js +597 -0
- package/dist/runtime/index.d.ts +8 -6
- package/dist/runtime/index.js +26 -244
- package/dist/scheduling/index.js +14 -822
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +6 -824
- package/package.json +15 -7
- package/dist/api-token-JOif2CtG.d.ts +0 -1792
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MessageSigner,
|
|
3
|
+
generateAppKey,
|
|
4
|
+
normalizeAppKey
|
|
5
|
+
} from "./chunk-ONSDE37A.js";
|
|
6
|
+
|
|
7
|
+
// src/encryption/Encrypter.ts
|
|
8
|
+
import { createCipheriv, createDecipheriv, randomBytes, createHmac } from "crypto";
|
|
9
|
+
var Encrypter = class {
|
|
10
|
+
/**
|
|
11
|
+
* Encryption key.
|
|
12
|
+
*/
|
|
13
|
+
key;
|
|
14
|
+
previousKeys;
|
|
15
|
+
/**
|
|
16
|
+
* Cipher algorithm.
|
|
17
|
+
*/
|
|
18
|
+
cipher;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.key = Buffer.from(normalizeAppKey(config.key).slice("base64:".length), "base64");
|
|
21
|
+
this.previousKeys = (config.previousKeys ?? []).map(
|
|
22
|
+
(key) => Buffer.from(normalizeAppKey(key).slice("base64:".length), "base64")
|
|
23
|
+
);
|
|
24
|
+
this.cipher = config.cipher ?? "aes-256-gcm";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Encrypt a value.
|
|
28
|
+
*/
|
|
29
|
+
encrypt(value, options = {}) {
|
|
30
|
+
const serialize = options.serialize !== false;
|
|
31
|
+
const data = serialize ? JSON.stringify(value) : String(value);
|
|
32
|
+
if (this.cipher === "aes-256-gcm") {
|
|
33
|
+
return this.encryptGcm(data);
|
|
34
|
+
}
|
|
35
|
+
return this.encryptCbc(data);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Decrypt a value.
|
|
39
|
+
*/
|
|
40
|
+
decrypt(payload, options = {}) {
|
|
41
|
+
const deserialize = options.deserialize !== false;
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
|
|
45
|
+
} catch {
|
|
46
|
+
throw new Error("Invalid encrypted payload.");
|
|
47
|
+
}
|
|
48
|
+
let decrypted;
|
|
49
|
+
if (parsed.tag) {
|
|
50
|
+
decrypted = this.decryptGcm(parsed);
|
|
51
|
+
} else if (parsed.mac) {
|
|
52
|
+
decrypted = this.decryptCbc(parsed);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error("Invalid encrypted payload format.");
|
|
55
|
+
}
|
|
56
|
+
if (deserialize) {
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(decrypted);
|
|
59
|
+
} catch {
|
|
60
|
+
return decrypted;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return decrypted;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Encrypt a string (no serialization).
|
|
67
|
+
*/
|
|
68
|
+
encryptString(value) {
|
|
69
|
+
return this.encrypt(value, { serialize: false });
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Decrypt a string (no deserialization).
|
|
73
|
+
*/
|
|
74
|
+
decryptString(payload) {
|
|
75
|
+
return this.decrypt(payload, { deserialize: false });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Encrypt using AES-256-GCM.
|
|
79
|
+
*/
|
|
80
|
+
encryptGcm(data) {
|
|
81
|
+
const iv = randomBytes(12);
|
|
82
|
+
const cipher = createCipheriv("aes-256-gcm", this.key, iv);
|
|
83
|
+
const encrypted = Buffer.concat([
|
|
84
|
+
cipher.update(data, "utf8"),
|
|
85
|
+
cipher.final()
|
|
86
|
+
]);
|
|
87
|
+
const tag = cipher.getAuthTag();
|
|
88
|
+
const payload = {
|
|
89
|
+
iv: iv.toString("base64"),
|
|
90
|
+
value: encrypted.toString("base64"),
|
|
91
|
+
tag: tag.toString("base64")
|
|
92
|
+
};
|
|
93
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Decrypt using AES-256-GCM.
|
|
97
|
+
*/
|
|
98
|
+
decryptGcm(payload) {
|
|
99
|
+
return this.tryDecryptWithKeys((key) => {
|
|
100
|
+
const iv = Buffer.from(payload.iv, "base64");
|
|
101
|
+
const encrypted = Buffer.from(payload.value, "base64");
|
|
102
|
+
const tag = Buffer.from(payload.tag, "base64");
|
|
103
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
104
|
+
decipher.setAuthTag(tag);
|
|
105
|
+
const decrypted = Buffer.concat([
|
|
106
|
+
decipher.update(encrypted),
|
|
107
|
+
decipher.final()
|
|
108
|
+
]);
|
|
109
|
+
return decrypted.toString("utf8");
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Encrypt using AES-256-CBC with HMAC.
|
|
114
|
+
*/
|
|
115
|
+
encryptCbc(data) {
|
|
116
|
+
const iv = randomBytes(16);
|
|
117
|
+
const cipher = createCipheriv("aes-256-cbc", this.key, iv);
|
|
118
|
+
const encrypted = Buffer.concat([
|
|
119
|
+
cipher.update(data, "utf8"),
|
|
120
|
+
cipher.final()
|
|
121
|
+
]);
|
|
122
|
+
const mac = this.createMac(iv, encrypted);
|
|
123
|
+
const payload = {
|
|
124
|
+
iv: iv.toString("base64"),
|
|
125
|
+
value: encrypted.toString("base64"),
|
|
126
|
+
mac
|
|
127
|
+
};
|
|
128
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Decrypt using AES-256-CBC with HMAC verification.
|
|
132
|
+
*/
|
|
133
|
+
decryptCbc(payload) {
|
|
134
|
+
return this.tryDecryptWithKeys((key) => {
|
|
135
|
+
const iv = Buffer.from(payload.iv, "base64");
|
|
136
|
+
const encrypted = Buffer.from(payload.value, "base64");
|
|
137
|
+
const expectedMac = this.createMac(iv, encrypted, key);
|
|
138
|
+
if (!this.secureCompare(payload.mac, expectedMac)) {
|
|
139
|
+
throw new Error("MAC verification failed.");
|
|
140
|
+
}
|
|
141
|
+
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
142
|
+
const decrypted = Buffer.concat([
|
|
143
|
+
decipher.update(encrypted),
|
|
144
|
+
decipher.final()
|
|
145
|
+
]);
|
|
146
|
+
return decrypted.toString("utf8");
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create HMAC for CBC mode.
|
|
151
|
+
*/
|
|
152
|
+
createMac(iv, encrypted, key = this.key) {
|
|
153
|
+
const hmac2 = createHmac("sha256", key);
|
|
154
|
+
hmac2.update(iv);
|
|
155
|
+
hmac2.update(encrypted);
|
|
156
|
+
return hmac2.digest("hex");
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Constant-time string comparison.
|
|
160
|
+
*/
|
|
161
|
+
secureCompare(a, b) {
|
|
162
|
+
if (a.length !== b.length) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
let result = 0;
|
|
166
|
+
for (let i = 0; i < a.length; i++) {
|
|
167
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
168
|
+
}
|
|
169
|
+
return result === 0;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the encryption key (base64).
|
|
173
|
+
*/
|
|
174
|
+
getKey() {
|
|
175
|
+
return this.key.toString("base64");
|
|
176
|
+
}
|
|
177
|
+
tryDecryptWithKeys(run) {
|
|
178
|
+
const keys = [this.key, ...this.previousKeys];
|
|
179
|
+
let lastError;
|
|
180
|
+
for (const key of keys) {
|
|
181
|
+
try {
|
|
182
|
+
return run(key);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
lastError = error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
throw lastError ?? new Error("Failed to decrypt payload.");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function generateKey() {
|
|
191
|
+
return generateAppKey();
|
|
192
|
+
}
|
|
193
|
+
var globalEncrypter = null;
|
|
194
|
+
function createEncrypter(config) {
|
|
195
|
+
return new Encrypter(config);
|
|
196
|
+
}
|
|
197
|
+
function setEncrypter(encrypter) {
|
|
198
|
+
globalEncrypter = encrypter;
|
|
199
|
+
}
|
|
200
|
+
function getEncrypter() {
|
|
201
|
+
if (!globalEncrypter) {
|
|
202
|
+
throw new Error("Encrypter not initialized. Call setEncrypter() first.");
|
|
203
|
+
}
|
|
204
|
+
return globalEncrypter;
|
|
205
|
+
}
|
|
206
|
+
function encrypt(value, options) {
|
|
207
|
+
return getEncrypter().encrypt(value, options);
|
|
208
|
+
}
|
|
209
|
+
function decrypt(payload, options) {
|
|
210
|
+
return getEncrypter().decrypt(payload, options);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/encryption/signed-url.ts
|
|
214
|
+
var PURPOSE = "signed-url";
|
|
215
|
+
var SIGNATURE_PARAM = "signature";
|
|
216
|
+
var EXPIRES_PARAM = "expires";
|
|
217
|
+
function canonicalizeUrl(value) {
|
|
218
|
+
const url = new URL(value);
|
|
219
|
+
url.searchParams.delete(SIGNATURE_PARAM);
|
|
220
|
+
const params = Array.from(url.searchParams.entries()).sort(([left], [right]) => left.localeCompare(right));
|
|
221
|
+
url.search = "";
|
|
222
|
+
for (const [key, paramValue] of params) {
|
|
223
|
+
url.searchParams.append(key, paramValue);
|
|
224
|
+
}
|
|
225
|
+
return { canonical: `${url.pathname}${url.search}`, url };
|
|
226
|
+
}
|
|
227
|
+
function signUrl(value, keyring, options = {}) {
|
|
228
|
+
const url = new URL(value);
|
|
229
|
+
if (typeof options.expiresIn === "number") {
|
|
230
|
+
url.searchParams.set(EXPIRES_PARAM, String(Math.floor((Date.now() + options.expiresIn) / 1e3)));
|
|
231
|
+
}
|
|
232
|
+
const { canonical } = canonicalizeUrl(url.toString());
|
|
233
|
+
const signer = new MessageSigner(keyring);
|
|
234
|
+
const signature = signer.sign({ url: canonical }, { purpose: PURPOSE });
|
|
235
|
+
url.searchParams.set(SIGNATURE_PARAM, signature);
|
|
236
|
+
return url.toString();
|
|
237
|
+
}
|
|
238
|
+
function verifySignedUrl(value, keyring, options = {}) {
|
|
239
|
+
const url = new URL(value);
|
|
240
|
+
const signature = url.searchParams.get(SIGNATURE_PARAM);
|
|
241
|
+
if (!signature) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
const expires = url.searchParams.get(EXPIRES_PARAM);
|
|
245
|
+
if (options.requireExpiration && !expires) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
if (expires && Number(expires) < Math.floor(Date.now() / 1e3)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
const { canonical } = canonicalizeUrl(value);
|
|
252
|
+
const signer = new MessageSigner(keyring);
|
|
253
|
+
const payload = signer.verify(signature, { purpose: PURPOSE });
|
|
254
|
+
return payload?.url === canonical;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/encryption/Random.ts
|
|
258
|
+
import { randomBytes as randomBytes2, randomUUID, randomInt as cryptoRandomInt } from "crypto";
|
|
259
|
+
var CHARSETS = {
|
|
260
|
+
alphanumeric: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
261
|
+
alphabetic: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
262
|
+
numeric: "0123456789",
|
|
263
|
+
hex: "0123456789abcdef",
|
|
264
|
+
"base64": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
265
|
+
"url-safe": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
266
|
+
};
|
|
267
|
+
function randomString(length, options = {}) {
|
|
268
|
+
const { charset = "alphanumeric" } = options;
|
|
269
|
+
const chars = CHARSETS[charset];
|
|
270
|
+
const bytes = randomBytes2(length);
|
|
271
|
+
let result = "";
|
|
272
|
+
for (let i = 0; i < length; i++) {
|
|
273
|
+
result += chars[bytes[i] % chars.length];
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
function random(length) {
|
|
278
|
+
return randomBytes2(length);
|
|
279
|
+
}
|
|
280
|
+
function randomHex(length) {
|
|
281
|
+
return randomBytes2(length).toString("hex");
|
|
282
|
+
}
|
|
283
|
+
function randomBase64(length) {
|
|
284
|
+
return randomBytes2(length).toString("base64");
|
|
285
|
+
}
|
|
286
|
+
function randomBase64Url(length) {
|
|
287
|
+
return randomBytes2(length).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
288
|
+
}
|
|
289
|
+
function uuid() {
|
|
290
|
+
return randomUUID();
|
|
291
|
+
}
|
|
292
|
+
function randomInt(min, max) {
|
|
293
|
+
return cryptoRandomInt(min, max + 1);
|
|
294
|
+
}
|
|
295
|
+
function urlSafeToken(length = 32) {
|
|
296
|
+
return randomBase64Url(Math.ceil(length * 0.75)).slice(0, length);
|
|
297
|
+
}
|
|
298
|
+
function generatePassword(length = 16, options = {}) {
|
|
299
|
+
const {
|
|
300
|
+
uppercase = true,
|
|
301
|
+
lowercase = true,
|
|
302
|
+
numbers = true,
|
|
303
|
+
symbols = true
|
|
304
|
+
} = options;
|
|
305
|
+
let chars = "";
|
|
306
|
+
if (uppercase) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
307
|
+
if (lowercase) chars += "abcdefghijklmnopqrstuvwxyz";
|
|
308
|
+
if (numbers) chars += "0123456789";
|
|
309
|
+
if (symbols) chars += "!@#$%^&*()-_=+[]{}|;:,.<>?";
|
|
310
|
+
if (chars.length === 0) {
|
|
311
|
+
chars = CHARSETS.alphanumeric;
|
|
312
|
+
}
|
|
313
|
+
const bytes = randomBytes2(length);
|
|
314
|
+
let result = "";
|
|
315
|
+
for (let i = 0; i < length; i++) {
|
|
316
|
+
result += chars[bytes[i] % chars.length];
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
function generateOtp(length = 6) {
|
|
321
|
+
return randomString(length, { charset: "numeric" });
|
|
322
|
+
}
|
|
323
|
+
function generateSlug(length = 10) {
|
|
324
|
+
return randomString(length, { charset: "hex" });
|
|
325
|
+
}
|
|
326
|
+
function shuffle(array) {
|
|
327
|
+
const result = [...array];
|
|
328
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
329
|
+
const j = randomInt(0, i);
|
|
330
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
function pick(array) {
|
|
335
|
+
if (array.length === 0) {
|
|
336
|
+
throw new Error("Cannot pick from empty array.");
|
|
337
|
+
}
|
|
338
|
+
return array[randomInt(0, array.length - 1)];
|
|
339
|
+
}
|
|
340
|
+
function sample(array, count) {
|
|
341
|
+
if (count > array.length) {
|
|
342
|
+
throw new Error("Sample count exceeds array length.");
|
|
343
|
+
}
|
|
344
|
+
const shuffled = shuffle(array);
|
|
345
|
+
return shuffled.slice(0, count);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export {
|
|
349
|
+
Encrypter,
|
|
350
|
+
generateKey,
|
|
351
|
+
createEncrypter,
|
|
352
|
+
setEncrypter,
|
|
353
|
+
getEncrypter,
|
|
354
|
+
encrypt,
|
|
355
|
+
decrypt,
|
|
356
|
+
signUrl,
|
|
357
|
+
verifySignedUrl,
|
|
358
|
+
randomString,
|
|
359
|
+
random,
|
|
360
|
+
randomHex,
|
|
361
|
+
randomBase64,
|
|
362
|
+
randomBase64Url,
|
|
363
|
+
uuid,
|
|
364
|
+
randomInt,
|
|
365
|
+
urlSafeToken,
|
|
366
|
+
generatePassword,
|
|
367
|
+
generateOtp,
|
|
368
|
+
generateSlug,
|
|
369
|
+
shuffle,
|
|
370
|
+
pick,
|
|
371
|
+
sample
|
|
372
|
+
};
|