@guren/server 2.10.0 → 2.11.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/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
- package/dist/Hash-CzrwKeDp.js +133 -0
- package/dist/HttpException-BkS3euNG.js +161 -0
- package/dist/Job-BVT813DO.js +441 -0
- package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
- package/dist/MessageSigner-Bd25ZJAV.js +93 -0
- package/dist/Random-DbIJ22KQ.js +191 -0
- package/dist/address-D0Iq-XIH.js +20 -0
- package/dist/auth/index.js +2 -122
- package/dist/auth-C7sVmYgc.js +1954 -0
- package/dist/authorization/index.js +2 -38
- package/dist/authorization-Dbcuc5ZK.js +610 -0
- package/dist/broadcasting/index.js +2 -26
- package/dist/broadcasting-Dw-FhyjN.js +1055 -0
- package/dist/cache/index.js +2 -17
- package/dist/cache/types.d.ts +4 -4
- package/dist/cache-BYnZf2FR.js +812 -0
- package/dist/client-Dd7vLcqp.js +27 -0
- package/dist/console/Output.d.ts +18 -18
- package/dist/encryption/index.js +5 -96
- package/dist/encryption-fOWQaKqX.js +250 -0
- package/dist/endpoint-D-20PiHY.js +46 -0
- package/dist/endpoint-D6GIqOpe.js +31 -0
- package/dist/errors-quJOkkCn.js +81 -0
- package/dist/events/index.js +2 -28
- package/dist/events-aIH_bWRx.js +410 -0
- package/dist/health/index.js +2 -24
- package/dist/health-VWdWXRwh.js +345 -0
- package/dist/hot-disposables-WsTX2ySN.js +281 -0
- package/dist/hot-reload/testing.d.ts +1 -1
- package/dist/http/resources/Resource.d.ts +23 -3
- package/dist/i18n/index.js +2 -30
- package/dist/i18n-mcWi7LCd.js +617 -0
- package/dist/index.js +7515 -7276
- package/dist/lambda/index.js +114 -71
- package/dist/logging/index.js +2 -24
- package/dist/logging-CPaRMuPP.js +518 -0
- package/dist/loopback-guard-D0Kc7-xc.js +224 -0
- package/dist/mail/index.js +2 -27
- package/dist/mail-DfEfSQEr.js +699 -0
- package/dist/mcp/index.js +2 -10
- package/dist/notifications/index.js +2 -33
- package/dist/notifications-BGqmUNZ8.js +759 -0
- package/dist/queue/index.js +3 -42
- package/dist/queue-CXrRK85G.js +948 -0
- package/dist/redis/index.js +672 -642
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime/index.js +472 -616
- package/dist/scheduling/index.js +2 -29
- package/dist/scheduling-CPiEdtQd.js +839 -0
- package/dist/storage/index.js +2 -15
- package/dist/storage-tWHMv2H_.js +841 -0
- package/dist/support/expiry.js +69 -12
- package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
- package/dist/vite/index.js +118 -181
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite-dev-server-BSJkduhZ.js +131 -0
- package/package.json +6 -5
- package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
- package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
- package/dist/chunk-2SC566CD.js +0 -376
- package/dist/chunk-2V3YID4H.js +0 -20
- package/dist/chunk-3KV5X2FL.js +0 -31
- package/dist/chunk-63SKW5PS.js +0 -457
- package/dist/chunk-6J6B5KOB.js +0 -425
- package/dist/chunk-A5JJ7XTH.js +0 -24
- package/dist/chunk-AZOYI43J.js +0 -18
- package/dist/chunk-B5E5VBDI.js +0 -115
- package/dist/chunk-DAQKYKLH.js +0 -182
- package/dist/chunk-DRNPVBAA.js +0 -1002
- package/dist/chunk-EI5GYMAT.js +0 -853
- package/dist/chunk-H3B23O6T.js +0 -271
- package/dist/chunk-HPET6XY5.js +0 -853
- package/dist/chunk-HR2KZ3WL.js +0 -616
- package/dist/chunk-IOTWFHZU.js +0 -558
- package/dist/chunk-K6CUBJX6.js +0 -642
- package/dist/chunk-KTNJG7R7.js +0 -911
- package/dist/chunk-LAJQCSSF.js +0 -355
- package/dist/chunk-LHR6OHI7.js +0 -189
- package/dist/chunk-N7PLD7MB.js +0 -729
- package/dist/chunk-Q2P6YLRR.js +0 -24
- package/dist/chunk-QQKTH5KX.js +0 -114
- package/dist/chunk-SFQP6O52.js +0 -126
- package/dist/chunk-SQR7277M.js +0 -911
- package/dist/chunk-T2FFUU6J.js +0 -484
- package/dist/chunk-TVV5YNEC.js +0 -1842
- package/dist/chunk-UY3AZSYL.js +0 -14
- package/dist/chunk-V4DNC2ER.js +0 -114
- package/dist/chunk-VSA3QY5Q.js +0 -274
- package/dist/chunk-YSOJKAAU.js +0 -427
- package/dist/errors-PUNHAFL2.js +0 -34
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Redis from "ioredis";
|
|
2
|
+
//#region src/redis/client.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a Redis client with the given options.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // Using URL
|
|
9
|
+
* const redis = createRedisClient({ url: 'redis://localhost:6379' })
|
|
10
|
+
*
|
|
11
|
+
* // Using host/port
|
|
12
|
+
* const redis = createRedisClient({ host: 'localhost', port: 6379 })
|
|
13
|
+
*
|
|
14
|
+
* // With key prefix
|
|
15
|
+
* const redis = createRedisClient({
|
|
16
|
+
* url: process.env.REDIS_URL,
|
|
17
|
+
* keyPrefix: 'myapp:',
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function createRedisClient(options = {}) {
|
|
22
|
+
const { url, ...redisOptions } = options;
|
|
23
|
+
if (url) return new Redis(url, redisOptions);
|
|
24
|
+
return new Redis(redisOptions);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createRedisClient as n, Redis as t };
|
package/dist/console/Output.d.ts
CHANGED
|
@@ -3,24 +3,24 @@ import type { OutputInterface } from './types.js';
|
|
|
3
3
|
* ANSI color codes.
|
|
4
4
|
*/
|
|
5
5
|
declare const COLORS: {
|
|
6
|
-
readonly reset:
|
|
7
|
-
readonly bold:
|
|
8
|
-
readonly dim:
|
|
9
|
-
readonly black:
|
|
10
|
-
readonly red:
|
|
11
|
-
readonly green:
|
|
12
|
-
readonly yellow:
|
|
13
|
-
readonly blue:
|
|
14
|
-
readonly magenta:
|
|
15
|
-
readonly cyan:
|
|
16
|
-
readonly white:
|
|
17
|
-
readonly bgRed:
|
|
18
|
-
readonly bgGreen:
|
|
19
|
-
readonly bgYellow:
|
|
20
|
-
readonly bgBlue:
|
|
21
|
-
readonly bgMagenta:
|
|
22
|
-
readonly bgCyan:
|
|
23
|
-
readonly bgWhite:
|
|
6
|
+
readonly reset: '\u001B[0m';
|
|
7
|
+
readonly bold: '\u001B[1m';
|
|
8
|
+
readonly dim: '\u001B[2m';
|
|
9
|
+
readonly black: '\u001B[30m';
|
|
10
|
+
readonly red: '\u001B[31m';
|
|
11
|
+
readonly green: '\u001B[32m';
|
|
12
|
+
readonly yellow: '\u001B[33m';
|
|
13
|
+
readonly blue: '\u001B[34m';
|
|
14
|
+
readonly magenta: '\u001B[35m';
|
|
15
|
+
readonly cyan: '\u001B[36m';
|
|
16
|
+
readonly white: '\u001B[37m';
|
|
17
|
+
readonly bgRed: '\u001B[41m';
|
|
18
|
+
readonly bgGreen: '\u001B[42m';
|
|
19
|
+
readonly bgYellow: '\u001B[43m';
|
|
20
|
+
readonly bgBlue: '\u001B[44m';
|
|
21
|
+
readonly bgMagenta: '\u001B[45m';
|
|
22
|
+
readonly bgCyan: '\u001B[46m';
|
|
23
|
+
readonly bgWhite: '\u001B[47m';
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* Console output handler.
|
package/dist/encryption/index.js
CHANGED
|
@@ -1,96 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
generateKey,
|
|
7
|
-
getEncrypter,
|
|
8
|
-
setEncrypter,
|
|
9
|
-
signUrl,
|
|
10
|
-
verifySignedUrl
|
|
11
|
-
} from "../chunk-H3B23O6T.js";
|
|
12
|
-
import {
|
|
13
|
-
MessageSigner,
|
|
14
|
-
deriveAppKey,
|
|
15
|
-
deriveAppKeyring,
|
|
16
|
-
encodeDerivedKey,
|
|
17
|
-
generateAppKey,
|
|
18
|
-
getAppKeyringFromEnv,
|
|
19
|
-
normalizeAppKey,
|
|
20
|
-
parseAppKey,
|
|
21
|
-
parsePreviousAppKeys
|
|
22
|
-
} from "../chunk-SFQP6O52.js";
|
|
23
|
-
import {
|
|
24
|
-
check,
|
|
25
|
-
hash,
|
|
26
|
-
hashPassword,
|
|
27
|
-
hmac,
|
|
28
|
-
md5,
|
|
29
|
-
needsRehash,
|
|
30
|
-
secureCompare,
|
|
31
|
-
sha256,
|
|
32
|
-
sha512,
|
|
33
|
-
verifyHmac,
|
|
34
|
-
verifyPassword
|
|
35
|
-
} from "../chunk-QQKTH5KX.js";
|
|
36
|
-
import {
|
|
37
|
-
generateOtp,
|
|
38
|
-
generatePassword,
|
|
39
|
-
generateSlug,
|
|
40
|
-
pick,
|
|
41
|
-
random,
|
|
42
|
-
randomBase64,
|
|
43
|
-
randomBase64Url,
|
|
44
|
-
randomHex,
|
|
45
|
-
randomInt,
|
|
46
|
-
randomString,
|
|
47
|
-
sample,
|
|
48
|
-
shuffle,
|
|
49
|
-
urlSafeToken,
|
|
50
|
-
uuid
|
|
51
|
-
} from "../chunk-V4DNC2ER.js";
|
|
52
|
-
export {
|
|
53
|
-
Encrypter,
|
|
54
|
-
MessageSigner,
|
|
55
|
-
check,
|
|
56
|
-
createEncrypter,
|
|
57
|
-
decrypt,
|
|
58
|
-
deriveAppKey,
|
|
59
|
-
deriveAppKeyring,
|
|
60
|
-
encodeDerivedKey,
|
|
61
|
-
encrypt,
|
|
62
|
-
generateAppKey,
|
|
63
|
-
generateKey,
|
|
64
|
-
generateOtp,
|
|
65
|
-
generatePassword,
|
|
66
|
-
generateSlug,
|
|
67
|
-
getAppKeyringFromEnv,
|
|
68
|
-
getEncrypter,
|
|
69
|
-
hash,
|
|
70
|
-
hashPassword,
|
|
71
|
-
hmac,
|
|
72
|
-
md5,
|
|
73
|
-
needsRehash,
|
|
74
|
-
normalizeAppKey,
|
|
75
|
-
parseAppKey,
|
|
76
|
-
parsePreviousAppKeys,
|
|
77
|
-
pick,
|
|
78
|
-
random,
|
|
79
|
-
randomBase64,
|
|
80
|
-
randomBase64Url,
|
|
81
|
-
randomHex,
|
|
82
|
-
randomInt,
|
|
83
|
-
randomString,
|
|
84
|
-
sample,
|
|
85
|
-
secureCompare,
|
|
86
|
-
setEncrypter,
|
|
87
|
-
sha256,
|
|
88
|
-
sha512,
|
|
89
|
-
shuffle,
|
|
90
|
-
signUrl,
|
|
91
|
-
urlSafeToken,
|
|
92
|
-
uuid,
|
|
93
|
-
verifyHmac,
|
|
94
|
-
verifyPassword,
|
|
95
|
-
verifySignedUrl
|
|
96
|
-
};
|
|
1
|
+
import { a as generateAppKey, c as parseAppKey, i as encodeDerivedKey, l as parsePreviousAppKeys, n as deriveAppKey, o as getAppKeyringFromEnv, r as deriveAppKeyring, s as normalizeAppKey, t as MessageSigner } from "../MessageSigner-Bd25ZJAV.js";
|
|
2
|
+
import { a as md5, c as sha256, d as verifyPassword, i as hmac, l as sha512, n as hash, o as needsRehash, r as hashPassword, s as secureCompare, t as check, u as verifyHmac } from "../Hash-CzrwKeDp.js";
|
|
3
|
+
import { a as random, c as randomHex, d as sample, f as shuffle, i as pick, l as randomInt, m as uuid, n as generatePassword, o as randomBase64, p as urlSafeToken, r as generateSlug, s as randomBase64Url, t as generateOtp, u as randomString } from "../Random-DbIJ22KQ.js";
|
|
4
|
+
import { a as decrypt, c as getEncrypter, i as createEncrypter, l as setEncrypter, n as verifySignedUrl, o as encrypt, r as Encrypter, s as generateKey, t as signUrl } from "../encryption-fOWQaKqX.js";
|
|
5
|
+
export { Encrypter, MessageSigner, check, createEncrypter, decrypt, deriveAppKey, deriveAppKeyring, encodeDerivedKey, encrypt, generateAppKey, generateKey, generateOtp, generatePassword, generateSlug, getAppKeyringFromEnv, getEncrypter, hash, hashPassword, hmac, md5, needsRehash, normalizeAppKey, parseAppKey, parsePreviousAppKeys, pick, random, randomBase64, randomBase64Url, randomHex, randomInt, randomString, sample, secureCompare, setEncrypter, sha256, sha512, shuffle, signUrl, urlSafeToken, uuid, verifyHmac, verifyPassword, verifySignedUrl };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { a as generateAppKey, s as normalizeAppKey, t as MessageSigner } from "./MessageSigner-Bd25ZJAV.js";
|
|
2
|
+
import { createCipheriv, createDecipheriv, createHmac, randomBytes } from "crypto";
|
|
3
|
+
//#region src/encryption/Encrypter.ts
|
|
4
|
+
/**
|
|
5
|
+
* GCM authentication tag length, in bytes.
|
|
6
|
+
*
|
|
7
|
+
* Pinned on both sides. Node and Bun accept 4-, 8-, 12-, 13-, 14-, 15- and
|
|
8
|
+
* 16-byte GCM tags, and `setAuthTag()` adopts whatever length it is handed — so
|
|
9
|
+
* a payload rewritten with a 4-byte tag would be accepted, dropping forgery
|
|
10
|
+
* resistance from 2^128 to 2^32. Everything this class writes uses the full
|
|
11
|
+
* tag, so nothing legitimate is rejected by requiring it.
|
|
12
|
+
*/
|
|
13
|
+
const GCM_TAG_BYTES = 16;
|
|
14
|
+
/**
|
|
15
|
+
* Encrypter for secure data encryption using AES.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const encrypter = new Encrypter({ key: 'base64-encoded-32-byte-key' })
|
|
20
|
+
*
|
|
21
|
+
* // Encrypt
|
|
22
|
+
* const encrypted = encrypter.encrypt({ userId: 123, role: 'admin' })
|
|
23
|
+
*
|
|
24
|
+
* // Decrypt
|
|
25
|
+
* const data = encrypter.decrypt(encrypted)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
var Encrypter = class {
|
|
29
|
+
/**
|
|
30
|
+
* Encryption key.
|
|
31
|
+
*/
|
|
32
|
+
key;
|
|
33
|
+
previousKeys;
|
|
34
|
+
/**
|
|
35
|
+
* Cipher algorithm.
|
|
36
|
+
*/
|
|
37
|
+
cipher;
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.key = Buffer.from(normalizeAppKey(config.key).slice(7), "base64");
|
|
40
|
+
this.previousKeys = (config.previousKeys ?? []).map((key) => Buffer.from(normalizeAppKey(key).slice(7), "base64"));
|
|
41
|
+
this.cipher = config.cipher ?? "aes-256-gcm";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Encrypt a value.
|
|
45
|
+
*/
|
|
46
|
+
encrypt(value, options = {}) {
|
|
47
|
+
const data = options.serialize !== false ? JSON.stringify(value) : String(value);
|
|
48
|
+
if (this.cipher === "aes-256-gcm") return this.encryptGcm(data);
|
|
49
|
+
return this.encryptCbc(data);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Decrypt a value.
|
|
53
|
+
*/
|
|
54
|
+
decrypt(payload, options = {}) {
|
|
55
|
+
const deserialize = options.deserialize !== false;
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
|
|
59
|
+
} catch {
|
|
60
|
+
throw new Error("Invalid encrypted payload.");
|
|
61
|
+
}
|
|
62
|
+
let decrypted;
|
|
63
|
+
if (parsed.tag) decrypted = this.decryptGcm(parsed);
|
|
64
|
+
else if (parsed.mac) decrypted = this.decryptCbc(parsed);
|
|
65
|
+
else throw new Error("Invalid encrypted payload format.");
|
|
66
|
+
if (deserialize) try {
|
|
67
|
+
return JSON.parse(decrypted);
|
|
68
|
+
} catch {
|
|
69
|
+
return decrypted;
|
|
70
|
+
}
|
|
71
|
+
return decrypted;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Encrypt a string (no serialization).
|
|
75
|
+
*/
|
|
76
|
+
encryptString(value) {
|
|
77
|
+
return this.encrypt(value, { serialize: false });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Decrypt a string (no deserialization).
|
|
81
|
+
*/
|
|
82
|
+
decryptString(payload) {
|
|
83
|
+
return this.decrypt(payload, { deserialize: false });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Encrypt using AES-256-GCM.
|
|
87
|
+
*/
|
|
88
|
+
encryptGcm(data) {
|
|
89
|
+
const iv = randomBytes(12);
|
|
90
|
+
const cipher = createCipheriv("aes-256-gcm", this.key, iv, { authTagLength: GCM_TAG_BYTES });
|
|
91
|
+
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
92
|
+
const tag = cipher.getAuthTag();
|
|
93
|
+
const payload = {
|
|
94
|
+
iv: iv.toString("base64"),
|
|
95
|
+
value: encrypted.toString("base64"),
|
|
96
|
+
tag: tag.toString("base64")
|
|
97
|
+
};
|
|
98
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Decrypt using AES-256-GCM.
|
|
102
|
+
*/
|
|
103
|
+
decryptGcm(payload) {
|
|
104
|
+
const iv = Buffer.from(payload.iv, "base64");
|
|
105
|
+
const encrypted = Buffer.from(payload.value, "base64");
|
|
106
|
+
const tag = Buffer.from(payload.tag, "base64");
|
|
107
|
+
if (tag.length !== GCM_TAG_BYTES) throw new Error("Invalid authentication tag length.");
|
|
108
|
+
return this.tryDecryptWithKeys((key) => {
|
|
109
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv, { authTagLength: GCM_TAG_BYTES });
|
|
110
|
+
decipher.setAuthTag(tag);
|
|
111
|
+
return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Encrypt using AES-256-CBC with HMAC.
|
|
116
|
+
*/
|
|
117
|
+
encryptCbc(data) {
|
|
118
|
+
const iv = randomBytes(16);
|
|
119
|
+
const cipher = createCipheriv("aes-256-cbc", this.key, iv);
|
|
120
|
+
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
121
|
+
const mac = this.createMac(iv, encrypted);
|
|
122
|
+
const payload = {
|
|
123
|
+
iv: iv.toString("base64"),
|
|
124
|
+
value: encrypted.toString("base64"),
|
|
125
|
+
mac
|
|
126
|
+
};
|
|
127
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Decrypt using AES-256-CBC with HMAC verification.
|
|
131
|
+
*/
|
|
132
|
+
decryptCbc(payload) {
|
|
133
|
+
return this.tryDecryptWithKeys((key) => {
|
|
134
|
+
const iv = Buffer.from(payload.iv, "base64");
|
|
135
|
+
const encrypted = Buffer.from(payload.value, "base64");
|
|
136
|
+
const expectedMac = this.createMac(iv, encrypted, key);
|
|
137
|
+
if (!this.secureCompare(payload.mac, expectedMac)) throw new Error("MAC verification failed.");
|
|
138
|
+
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
139
|
+
return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create HMAC for CBC mode.
|
|
144
|
+
*/
|
|
145
|
+
createMac(iv, encrypted, key = this.key) {
|
|
146
|
+
const hmac = createHmac("sha256", key);
|
|
147
|
+
hmac.update(iv);
|
|
148
|
+
hmac.update(encrypted);
|
|
149
|
+
return hmac.digest("hex");
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Constant-time string comparison.
|
|
153
|
+
*/
|
|
154
|
+
secureCompare(a, b) {
|
|
155
|
+
if (a.length !== b.length) return false;
|
|
156
|
+
let result = 0;
|
|
157
|
+
for (let i = 0; i < a.length; i++) result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
158
|
+
return result === 0;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the encryption key (base64).
|
|
162
|
+
*/
|
|
163
|
+
getKey() {
|
|
164
|
+
return this.key.toString("base64");
|
|
165
|
+
}
|
|
166
|
+
tryDecryptWithKeys(run) {
|
|
167
|
+
const keys = [this.key, ...this.previousKeys];
|
|
168
|
+
let lastError;
|
|
169
|
+
for (const key of keys) try {
|
|
170
|
+
return run(key);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
lastError = error;
|
|
173
|
+
}
|
|
174
|
+
throw lastError ?? /* @__PURE__ */ new Error("Failed to decrypt payload.");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Generate a random encryption key.
|
|
179
|
+
*/
|
|
180
|
+
function generateKey() {
|
|
181
|
+
return generateAppKey();
|
|
182
|
+
}
|
|
183
|
+
let globalEncrypter = null;
|
|
184
|
+
/**
|
|
185
|
+
* Create an encrypter instance.
|
|
186
|
+
*/
|
|
187
|
+
function createEncrypter(config) {
|
|
188
|
+
return new Encrypter(config);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Set the global encrypter.
|
|
192
|
+
*/
|
|
193
|
+
function setEncrypter(encrypter) {
|
|
194
|
+
globalEncrypter = encrypter;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the global encrypter.
|
|
198
|
+
*/
|
|
199
|
+
function getEncrypter() {
|
|
200
|
+
if (!globalEncrypter) throw new Error("Encrypter not initialized. Call setEncrypter() first.");
|
|
201
|
+
return globalEncrypter;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Encrypt a value using the global encrypter.
|
|
205
|
+
*/
|
|
206
|
+
function encrypt(value, options) {
|
|
207
|
+
return getEncrypter().encrypt(value, options);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Decrypt a value using the global encrypter.
|
|
211
|
+
*/
|
|
212
|
+
function decrypt(payload, options) {
|
|
213
|
+
return getEncrypter().decrypt(payload, options);
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/encryption/signed-url.ts
|
|
217
|
+
const PURPOSE = "signed-url";
|
|
218
|
+
const SIGNATURE_PARAM = "signature";
|
|
219
|
+
const EXPIRES_PARAM = "expires";
|
|
220
|
+
function canonicalizeUrl(value) {
|
|
221
|
+
const url = new URL(value);
|
|
222
|
+
url.searchParams.delete(SIGNATURE_PARAM);
|
|
223
|
+
const params = Array.from(url.searchParams.entries()).sort(([left], [right]) => left.localeCompare(right));
|
|
224
|
+
url.search = "";
|
|
225
|
+
for (const [key, paramValue] of params) url.searchParams.append(key, paramValue);
|
|
226
|
+
return {
|
|
227
|
+
canonical: `${url.pathname}${url.search}`,
|
|
228
|
+
url
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function signUrl(value, keyring, options = {}) {
|
|
232
|
+
const url = new URL(value);
|
|
233
|
+
if (typeof options.expiresIn === "number") url.searchParams.set(EXPIRES_PARAM, String(Math.floor((Date.now() + options.expiresIn) / 1e3)));
|
|
234
|
+
const { canonical } = canonicalizeUrl(url.toString());
|
|
235
|
+
const signature = new MessageSigner(keyring).sign({ url: canonical }, { purpose: PURPOSE });
|
|
236
|
+
url.searchParams.set(SIGNATURE_PARAM, signature);
|
|
237
|
+
return url.toString();
|
|
238
|
+
}
|
|
239
|
+
function verifySignedUrl(value, keyring, options = {}) {
|
|
240
|
+
const url = new URL(value);
|
|
241
|
+
const signature = url.searchParams.get(SIGNATURE_PARAM);
|
|
242
|
+
if (!signature) return false;
|
|
243
|
+
const expires = url.searchParams.get(EXPIRES_PARAM);
|
|
244
|
+
if (options.requireExpiration && !expires) return false;
|
|
245
|
+
if (expires && Number(expires) < Math.floor(Date.now() / 1e3)) return false;
|
|
246
|
+
const { canonical } = canonicalizeUrl(value);
|
|
247
|
+
return new MessageSigner(keyring).verify(signature, { purpose: PURPOSE })?.url === canonical;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
export { decrypt as a, getEncrypter as c, createEncrypter as i, setEncrypter as l, verifySignedUrl as n, encrypt as o, Encrypter as r, generateKey as s, signUrl as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { t as createLoopbackGuard } from "./loopback-guard-D0Kc7-xc.js";
|
|
2
|
+
//#region src/mcp/endpoint.ts
|
|
3
|
+
const MCP_ENDPOINT_PATH = "/_guren/mcp";
|
|
4
|
+
/**
|
|
5
|
+
* Whether the MCP endpoint is mounted for this process.
|
|
6
|
+
*
|
|
7
|
+
* Opt-in via `GUREN_MCP=1` and never active in production: the endpoint
|
|
8
|
+
* exposes project introspection and code generation, so it must not be
|
|
9
|
+
* reachable unless the developer asked for it.
|
|
10
|
+
*
|
|
11
|
+
* The environment reads below are deliberately written as plain member
|
|
12
|
+
* access. Do not "harden" them with optional chaining: the deploy plugins
|
|
13
|
+
* bundle server code with `--define 'process.env.NODE_ENV="production"'`,
|
|
14
|
+
* and a define matches one exact expression. Inserting `?.` produces a
|
|
15
|
+
* different expression that no define touches, leaving this gate a runtime
|
|
16
|
+
* read — and on hosts where the platform's environment is not in
|
|
17
|
+
* `process.env` by the time the module graph evaluates (workerd is the
|
|
18
|
+
* documented case; see the comment on the Cloudflare plugin's `define`),
|
|
19
|
+
* that runtime read answers "not production" and the gate silently reopens.
|
|
20
|
+
* A test in `tests/mcp/endpoint.test.ts` reads this file and fails on any
|
|
21
|
+
* optional chain after `process.env`, because nothing observable at runtime
|
|
22
|
+
* distinguishes the two forms.
|
|
23
|
+
*
|
|
24
|
+
* The `typeof process` check covers the only runtimes without `process`;
|
|
25
|
+
* every runtime the framework supports that has `process` has `process.env`.
|
|
26
|
+
*/
|
|
27
|
+
function isMcpEndpointEnabled() {
|
|
28
|
+
if (typeof process === "undefined") return false;
|
|
29
|
+
if (process.env.NODE_ENV === "production") return false;
|
|
30
|
+
return process.env.GUREN_MCP === "1";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Restricts the MCP endpoint to the developer's own machine.
|
|
34
|
+
*
|
|
35
|
+
* The endpoint is exempt from CSRF — agent clients carry no token — so
|
|
36
|
+
* the loopback guard takes over that job: web pages are rejected unless
|
|
37
|
+
* their `Origin` is loopback (the check the MCP specification asks local
|
|
38
|
+
* servers for), and every caller is rejected unless its socket peer is
|
|
39
|
+
* loopback. The guard fails closed when the runtime reports no peer at
|
|
40
|
+
* all; see `http/middleware/loopback-guard.ts` for the opt-out.
|
|
41
|
+
*/
|
|
42
|
+
function createMcpAccessGuard() {
|
|
43
|
+
return createLoopbackGuard("the MCP endpoint");
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createMcpAccessGuard as n, isMcpEndpointEnabled as r, MCP_ENDPOINT_PATH as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as createLoopbackGuard } from "./loopback-guard-D0Kc7-xc.js";
|
|
2
|
+
//#region src/docs-viewer/endpoint.ts
|
|
3
|
+
const DOCS_VIEWER_PATH = "/_guren/docs";
|
|
4
|
+
/**
|
|
5
|
+
* Whether the docs viewer is mounted for this process.
|
|
6
|
+
*
|
|
7
|
+
* Opt-in via `GUREN_DOCS=1` and never active in production: the viewer
|
|
8
|
+
* renders the project's private knowledge bundle, so it must not be
|
|
9
|
+
* reachable unless the developer asked for it.
|
|
10
|
+
*
|
|
11
|
+
* The environment reads use plain member access so that the deploy plugins'
|
|
12
|
+
* `--define 'process.env.NODE_ENV="production"'` settles the production
|
|
13
|
+
* branch at bundle time; an optional chain is a different expression and no
|
|
14
|
+
* define matches it. See `mcp/endpoint.ts` for the full reasoning — and do
|
|
15
|
+
* not add optional chaining back, a test reads this file for it.
|
|
16
|
+
*/
|
|
17
|
+
function isDocsViewerEnabled() {
|
|
18
|
+
if (typeof process === "undefined") return false;
|
|
19
|
+
if (process.env.NODE_ENV === "production") return false;
|
|
20
|
+
return process.env.GUREN_DOCS === "1";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Restricts the docs viewer to the developer's own machine: cross-origin
|
|
24
|
+
* browser requests are rejected, and so is any request whose socket peer
|
|
25
|
+
* is not loopback — including one whose peer the runtime cannot report.
|
|
26
|
+
*/
|
|
27
|
+
function createDocsViewerAccessGuard() {
|
|
28
|
+
return createLoopbackGuard("the docs viewer");
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createDocsViewerAccessGuard as n, isDocsViewerEnabled as r, DOCS_VIEWER_PATH as t };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
import { t as HttpException } from "./HttpException-BkS3euNG.js";
|
|
3
|
+
//#region src/errors/exceptions/ValidationException.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validation exception.
|
|
6
|
+
*
|
|
7
|
+
* Thrown when request validation fails.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* throw new ValidationException({
|
|
12
|
+
* email: ['Email is required', 'Email must be valid'],
|
|
13
|
+
* password: ['Password is too short'],
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
var ValidationException = class ValidationException extends HttpException {
|
|
18
|
+
constructor(errors, message = "The given data was invalid.") {
|
|
19
|
+
super(422, message, errors);
|
|
20
|
+
this.name = "ValidationException";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create from Zod error.
|
|
24
|
+
*/
|
|
25
|
+
static fromZodError(zodError) {
|
|
26
|
+
const errors = {};
|
|
27
|
+
for (const issue of zodError.issues) {
|
|
28
|
+
const path = issue.path.join(".");
|
|
29
|
+
if (!errors[path]) errors[path] = [];
|
|
30
|
+
errors[path].push(issue.message);
|
|
31
|
+
}
|
|
32
|
+
return new ValidationException(errors);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get errors for a specific field.
|
|
36
|
+
*/
|
|
37
|
+
getFieldErrors(field) {
|
|
38
|
+
return this.errors?.[field] ?? [];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a field has errors.
|
|
42
|
+
*/
|
|
43
|
+
hasFieldError(field) {
|
|
44
|
+
return (this.errors?.[field]?.length ?? 0) > 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the first error for a field.
|
|
48
|
+
*/
|
|
49
|
+
getFirstError(field) {
|
|
50
|
+
return this.errors?.[field]?.[0] ?? null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get all error messages as a flat array.
|
|
54
|
+
*/
|
|
55
|
+
getAllMessages() {
|
|
56
|
+
if (!this.errors) return [];
|
|
57
|
+
return Object.values(this.errors).flat();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a ValidationException from a plain messages object.
|
|
61
|
+
*
|
|
62
|
+
* Useful for business-logic validation (e.g. duplicate email checks)
|
|
63
|
+
* where Zod is not involved.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* throw ValidationException.withMessages({ email: 'Email already registered' })
|
|
68
|
+
* throw ValidationException.withMessages({ email: ['Must be unique', 'Must be corporate'] })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
static withMessages(messages) {
|
|
72
|
+
const errors = {};
|
|
73
|
+
for (const [key, value] of Object.entries(messages)) errors[key] = Array.isArray(value) ? value : [value];
|
|
74
|
+
return new ValidationException(errors);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/errors/index.ts
|
|
79
|
+
var errors_exports = /* @__PURE__ */ __exportAll({ ValidationException: () => ValidationException });
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ValidationException as n, errors_exports as t };
|
package/dist/events/index.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
ApplicationStarted,
|
|
4
|
-
Event,
|
|
5
|
-
EventManager,
|
|
6
|
-
JobFailed,
|
|
7
|
-
JobProcessed,
|
|
8
|
-
Listener,
|
|
9
|
-
RequestFinished,
|
|
10
|
-
RequestReceived,
|
|
11
|
-
UserAuthenticated,
|
|
12
|
-
UserLoggedOut,
|
|
13
|
-
createEventManager
|
|
14
|
-
} from "../chunk-LAJQCSSF.js";
|
|
15
|
-
export {
|
|
16
|
-
ApplicationShutdown,
|
|
17
|
-
ApplicationStarted,
|
|
18
|
-
Event,
|
|
19
|
-
EventManager,
|
|
20
|
-
JobFailed,
|
|
21
|
-
JobProcessed,
|
|
22
|
-
Listener,
|
|
23
|
-
RequestFinished,
|
|
24
|
-
RequestReceived,
|
|
25
|
-
UserAuthenticated,
|
|
26
|
-
UserLoggedOut,
|
|
27
|
-
createEventManager
|
|
28
|
-
};
|
|
1
|
+
import { a as RequestFinished, c as UserLoggedOut, d as createEventManager, f as Event, i as JobProcessed, l as Listener, n as ApplicationStarted, o as RequestReceived, r as JobFailed, s as UserAuthenticated, t as ApplicationShutdown, u as EventManager } from "../events-aIH_bWRx.js";
|
|
2
|
+
export { ApplicationShutdown, ApplicationStarted, Event, EventManager, JobFailed, JobProcessed, Listener, RequestFinished, RequestReceived, UserAuthenticated, UserLoggedOut, createEventManager };
|