@guren/server 1.0.0-rc.9 → 1.1.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.
Files changed (70) hide show
  1. package/dist/{Application-DtWDHXr1.d.ts → Application-BnsyCKXY.d.ts} +79 -8
  2. package/dist/AuthManager-SfhCNkAU.d.ts +79 -0
  3. package/dist/{BroadcastManager-AkIWUGJo.d.ts → BroadcastManager-CGWl9rUO.d.ts} +5 -0
  4. package/dist/{ConsoleKernel-CqCVrdZs.d.ts → ConsoleKernel-BDtBETjm.d.ts} +1 -1
  5. package/dist/{Gate-CNkBYf8m.d.ts → Gate-CynjZCtS.d.ts} +5 -0
  6. package/dist/{I18nManager-Dtgzsf5n.d.ts → I18nManager-BiSoczfV.d.ts} +6 -1
  7. package/dist/McpServiceProvider-JW6PDVMD.js +7 -0
  8. package/dist/api-token-BSSCLlFW.d.ts +541 -0
  9. package/dist/auth/index.d.ts +9 -327
  10. package/dist/auth/index.js +59 -6684
  11. package/dist/authorization/index.d.ts +2 -2
  12. package/dist/authorization/index.js +19 -604
  13. package/dist/broadcasting/index.d.ts +2 -2
  14. package/dist/broadcasting/index.js +12 -895
  15. package/dist/cache/index.js +8 -809
  16. package/dist/chunk-2T6JN4VR.js +1563 -0
  17. package/dist/chunk-44F7JQ7I.js +950 -0
  18. package/dist/chunk-74HTZG3V.js +331 -0
  19. package/dist/chunk-A3ISJVEV.js +598 -0
  20. package/dist/chunk-CSDKWLFD.js +652 -0
  21. package/dist/chunk-CSRQTEQA.js +839 -0
  22. package/dist/chunk-DAQKYKLH.js +182 -0
  23. package/dist/chunk-EDRGAM6G.js +647 -0
  24. package/dist/chunk-EGU5KB7V.js +818 -0
  25. package/dist/chunk-H32L2NE3.js +372 -0
  26. package/dist/chunk-HKQSAFSN.js +837 -0
  27. package/dist/chunk-IOTWFHZU.js +558 -0
  28. package/dist/chunk-ONSDE37A.js +125 -0
  29. package/dist/chunk-QH4NUKSV.js +255 -0
  30. package/dist/chunk-QQKTH5KX.js +114 -0
  31. package/dist/chunk-R2TCP7D7.js +409 -0
  32. package/dist/chunk-SIP34GBE.js +380 -0
  33. package/dist/chunk-THSX7OOR.js +454 -0
  34. package/dist/chunk-UY3AZSYL.js +14 -0
  35. package/dist/chunk-VT5KRDPH.js +134 -0
  36. package/dist/chunk-WJJ5CTNI.js +907 -0
  37. package/dist/chunk-WVY45EIW.js +359 -0
  38. package/dist/chunk-ZRBLZY3M.js +462 -0
  39. package/dist/client-CKXJLsTe.d.ts +232 -0
  40. package/dist/email-verification-CAeArjui.d.ts +327 -0
  41. package/dist/encryption/index.js +48 -556
  42. package/dist/errors-JOOPDDQ6.js +34 -0
  43. package/dist/events/index.js +14 -316
  44. package/dist/health/index.js +12 -367
  45. package/dist/i18n/index.d.ts +2 -2
  46. package/dist/i18n/index.js +14 -583
  47. package/dist/index.d.ts +37 -239
  48. package/dist/index.js +2931 -19222
  49. package/dist/lambda/index.d.ts +9 -7
  50. package/dist/lambda/index.js +4 -9
  51. package/dist/logging/index.js +12 -545
  52. package/dist/mail/index.d.ts +29 -1
  53. package/dist/mail/index.js +15 -684
  54. package/dist/mcp/index.d.ts +7 -5
  55. package/dist/mcp/index.js +5 -378
  56. package/dist/notifications/index.d.ts +8 -6
  57. package/dist/notifications/index.js +13 -730
  58. package/dist/queue/index.d.ts +37 -7
  59. package/dist/queue/index.js +22 -940
  60. package/dist/redis/index.d.ts +366 -0
  61. package/dist/redis/index.js +597 -0
  62. package/dist/runtime/index.d.ts +8 -6
  63. package/dist/runtime/index.js +26 -244
  64. package/dist/scheduling/index.js +14 -822
  65. package/dist/storage/index.d.ts +1 -0
  66. package/dist/storage/index.js +6 -824
  67. package/dist/vite/index.d.ts +2 -2
  68. package/dist/vite/index.js +5 -1
  69. package/package.json +15 -7
  70. package/dist/api-token-JOif2CtG.d.ts +0 -1792
@@ -0,0 +1,255 @@
1
+ // src/http/dev-banner.ts
2
+ import chalk from "chalk";
3
+ import figlet from "figlet";
4
+ import standard from "figlet/importable-fonts/Standard.js";
5
+
6
+ // package.json
7
+ var package_default = {
8
+ name: "@guren/server",
9
+ version: "1.1.0",
10
+ type: "module",
11
+ license: "MIT",
12
+ repository: {
13
+ type: "git",
14
+ url: "https://github.com/gurenjs/guren",
15
+ directory: "packages/server"
16
+ },
17
+ homepage: "https://github.com/gurenjs/guren#readme",
18
+ bugs: {
19
+ url: "https://github.com/gurenjs/guren/issues"
20
+ },
21
+ publishConfig: {
22
+ access: "public"
23
+ },
24
+ files: [
25
+ "dist"
26
+ ],
27
+ main: "dist/index.js",
28
+ types: "dist/index.d.ts",
29
+ exports: {
30
+ ".": {
31
+ types: "./dist/index.d.ts",
32
+ default: "./dist/index.js"
33
+ },
34
+ "./auth": {
35
+ types: "./dist/auth/index.d.ts",
36
+ default: "./dist/auth/index.js"
37
+ },
38
+ "./authorization": {
39
+ types: "./dist/authorization/index.d.ts",
40
+ default: "./dist/authorization/index.js"
41
+ },
42
+ "./broadcasting": {
43
+ types: "./dist/broadcasting/index.d.ts",
44
+ default: "./dist/broadcasting/index.js"
45
+ },
46
+ "./cache": {
47
+ types: "./dist/cache/index.d.ts",
48
+ default: "./dist/cache/index.js"
49
+ },
50
+ "./encryption": {
51
+ types: "./dist/encryption/index.d.ts",
52
+ default: "./dist/encryption/index.js"
53
+ },
54
+ "./events": {
55
+ types: "./dist/events/index.d.ts",
56
+ default: "./dist/events/index.js"
57
+ },
58
+ "./health": {
59
+ types: "./dist/health/index.d.ts",
60
+ default: "./dist/health/index.js"
61
+ },
62
+ "./i18n": {
63
+ types: "./dist/i18n/index.d.ts",
64
+ default: "./dist/i18n/index.js"
65
+ },
66
+ "./logging": {
67
+ types: "./dist/logging/index.d.ts",
68
+ default: "./dist/logging/index.js"
69
+ },
70
+ "./mail": {
71
+ types: "./dist/mail/index.d.ts",
72
+ default: "./dist/mail/index.js"
73
+ },
74
+ "./notifications": {
75
+ types: "./dist/notifications/index.d.ts",
76
+ default: "./dist/notifications/index.js"
77
+ },
78
+ "./queue": {
79
+ types: "./dist/queue/index.d.ts",
80
+ default: "./dist/queue/index.js"
81
+ },
82
+ "./runtime": {
83
+ types: "./dist/runtime/index.d.ts",
84
+ default: "./dist/runtime/index.js"
85
+ },
86
+ "./scheduling": {
87
+ types: "./dist/scheduling/index.d.ts",
88
+ default: "./dist/scheduling/index.js"
89
+ },
90
+ "./storage": {
91
+ types: "./dist/storage/index.d.ts",
92
+ default: "./dist/storage/index.js"
93
+ },
94
+ "./vite": {
95
+ types: "./dist/vite/index.d.ts",
96
+ default: "./dist/vite/index.js"
97
+ },
98
+ "./mcp": {
99
+ types: "./dist/mcp/index.d.ts",
100
+ default: "./dist/mcp/index.js"
101
+ },
102
+ "./lambda": {
103
+ types: "./dist/lambda/index.d.ts",
104
+ default: "./dist/lambda/index.js"
105
+ },
106
+ "./redis": {
107
+ types: "./dist/redis/index.d.ts",
108
+ default: "./dist/redis/index.js"
109
+ }
110
+ },
111
+ scripts: {
112
+ build: "NODE_OPTIONS='--max-old-space-size=8192' tsup",
113
+ dev: "bun --watch src/index.ts",
114
+ typecheck: "tsc --noEmit",
115
+ test: "bun test"
116
+ },
117
+ dependencies: {
118
+ "@guren/orm": "^1.0.1",
119
+ "@modelcontextprotocol/sdk": "^1.27.1",
120
+ chalk: "^5.3.0",
121
+ consola: "^3.4.2",
122
+ figlet: "^1.7.0",
123
+ hono: "^4.12.29",
124
+ ioredis: "^5.11.1",
125
+ nodemailer: "^9.0.1"
126
+ },
127
+ peerDependencies: {
128
+ "@aws-sdk/client-s3": "^3.0.0",
129
+ "@aws-sdk/client-sqs": "^3.0.0",
130
+ "@aws-sdk/s3-request-presigner": "^3.0.0",
131
+ vite: ">=7.0.0",
132
+ "@guren/inertia-client": "^1.0.0"
133
+ },
134
+ peerDependenciesMeta: {
135
+ "@aws-sdk/client-s3": {
136
+ optional: true
137
+ },
138
+ "@aws-sdk/client-sqs": {
139
+ optional: true
140
+ },
141
+ "@aws-sdk/s3-request-presigner": {
142
+ optional: true
143
+ },
144
+ "@guren/inertia-client": {
145
+ optional: true
146
+ }
147
+ },
148
+ devDependencies: {
149
+ "@types/ioredis": "^5.0.0",
150
+ "@types/node": "^20.14.10",
151
+ "@types/nodemailer": "^8.0.1",
152
+ tsup: "^8.5.0",
153
+ typescript: "^5.4.0",
154
+ vite: "^8.0.0"
155
+ }
156
+ };
157
+
158
+ // src/http/dev-banner.ts
159
+ figlet.parseFont("Standard", standard);
160
+ function generateAsciiArt(text) {
161
+ try {
162
+ const rendered = figlet.textSync(text, {
163
+ font: "Standard",
164
+ horizontalLayout: "default",
165
+ verticalLayout: "default"
166
+ });
167
+ return rendered;
168
+ } catch (error) {
169
+ console.error("Failed to generate FIGlet banner, falling back to plain text:", error);
170
+ return text.toUpperCase();
171
+ }
172
+ }
173
+ var GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
174
+ var GUREN_VERSION = package_default.version;
175
+ function logDevServerBanner({
176
+ hostname,
177
+ port,
178
+ assetsUrl = "http://localhost:5173"
179
+ }) {
180
+ const localUrl = `http://localhost:${port}`;
181
+ const boundUrl = `http://${hostname}:${port}`;
182
+ const boundLabel = hostname === "0.0.0.0" || hostname === "::" ? " (all interfaces)" : "";
183
+ const header = [
184
+ GUREN_ASCII_ART,
185
+ chalk.magentaBright.bold(
186
+ `Guren v${GUREN_VERSION} ignites \u2014 burning bright like a crimson lotus.`
187
+ ),
188
+ ""
189
+ ];
190
+ const detail = (label, value) => `${chalk.magentaBright(" \u2022")} ${chalk.bold(label.padEnd(14))}: ${chalk.cyanBright(value)}`;
191
+ const banner = [
192
+ ...header,
193
+ detail("App URL", localUrl),
194
+ detail("Bound address", `${boundUrl}${boundLabel}`),
195
+ detail("Asset server", `${assetsUrl} (Vite)`),
196
+ "",
197
+ chalk.yellowBright("Press Ctrl+C to douse the flames."),
198
+ ""
199
+ ].join("\n");
200
+ console.log(banner);
201
+ }
202
+
203
+ // src/http/vite-dev-server.ts
204
+ async function startViteDevServer(options = {}) {
205
+ const { root = process.cwd(), config = {}, host = true, port } = options;
206
+ const { createServer } = await import("vite");
207
+ const mergedConfig = {
208
+ clearScreen: false,
209
+ ...config,
210
+ root: config.root ?? root,
211
+ server: {
212
+ host,
213
+ port,
214
+ ...config.server ?? {}
215
+ }
216
+ };
217
+ const server = await createServer(mergedConfig);
218
+ await server.listen();
219
+ const resolved = server.resolvedUrls;
220
+ const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${server.config.server.port ?? port ?? 5173}`];
221
+ const networkUrls = resolved?.network ?? [];
222
+ return {
223
+ server,
224
+ localUrl: localUrls[0],
225
+ networkUrls
226
+ };
227
+ }
228
+
229
+ // src/support/import-map.ts
230
+ function parseImportMap(value, options = {}) {
231
+ if (!value) {
232
+ return {};
233
+ }
234
+ try {
235
+ const parsed = JSON.parse(value);
236
+ const result = {};
237
+ for (const [key, entry] of Object.entries(parsed)) {
238
+ if (typeof entry === "string" && entry.length > 0) {
239
+ result[key] = entry;
240
+ }
241
+ }
242
+ return result;
243
+ } catch (error) {
244
+ const label = options.context ?? "import map";
245
+ console.warn(`Failed to parse ${label}. Expected JSON object.`, error);
246
+ return {};
247
+ }
248
+ }
249
+
250
+ export {
251
+ parseImportMap,
252
+ GUREN_ASCII_ART,
253
+ logDevServerBanner,
254
+ startViteDevServer
255
+ };
@@ -0,0 +1,114 @@
1
+ // src/encryption/Hash.ts
2
+ import {
3
+ createHash,
4
+ createHmac,
5
+ randomBytes,
6
+ scrypt,
7
+ timingSafeEqual
8
+ } from "crypto";
9
+ import { promisify } from "util";
10
+ var scryptAsync = promisify(scrypt);
11
+ function hash(value, algorithm = "sha256", encoding = "hex") {
12
+ return createHash(algorithm).update(value).digest(encoding);
13
+ }
14
+ function hmac(value, key, options = {}) {
15
+ const { algorithm = "sha256", encoding = "hex" } = options;
16
+ return createHmac(algorithm, key).update(value).digest(encoding);
17
+ }
18
+ function verifyHmac(value, signature, key, options = {}) {
19
+ const expected = hmac(value, key, options);
20
+ return secureCompare(signature, expected);
21
+ }
22
+ function sha256(value) {
23
+ return hash(value, "sha256");
24
+ }
25
+ function sha512(value) {
26
+ return hash(value, "sha512");
27
+ }
28
+ function md5(value) {
29
+ return hash(value, "md5");
30
+ }
31
+ async function hashPassword(password, options = {}) {
32
+ const {
33
+ cost = 16384,
34
+ // N
35
+ memory = 8,
36
+ // r (block size)
37
+ saltLength = 16,
38
+ keyLength = 64
39
+ } = options;
40
+ const salt = randomBytes(saltLength);
41
+ const derived = await scryptAsync(password, salt, keyLength, {
42
+ N: cost,
43
+ r: memory,
44
+ p: 1
45
+ });
46
+ const params = `N=${cost},r=${memory},p=1`;
47
+ return `$scrypt$${params}$${salt.toString("base64")}$${derived.toString("base64")}`;
48
+ }
49
+ async function verifyPassword(password, hash2) {
50
+ if (!hash2.startsWith("$scrypt$")) {
51
+ throw new Error("Invalid password hash format.");
52
+ }
53
+ const parts = hash2.split("$");
54
+ if (parts.length !== 5) {
55
+ throw new Error("Invalid password hash format.");
56
+ }
57
+ const [, , paramsStr, saltB64, hashB64] = parts;
58
+ const params = {};
59
+ for (const param of paramsStr.split(",")) {
60
+ const [key, value] = param.split("=");
61
+ params[key] = parseInt(value, 10);
62
+ }
63
+ const salt = Buffer.from(saltB64, "base64");
64
+ const expectedHash = Buffer.from(hashB64, "base64");
65
+ const derived = await scryptAsync(password, salt, expectedHash.length, {
66
+ N: params.N,
67
+ r: params.r,
68
+ p: params.p ?? 1
69
+ });
70
+ return timingSafeEqual(derived, expectedHash);
71
+ }
72
+ function needsRehash(hash2, options = {}) {
73
+ const { cost = 16384, memory = 8 } = options;
74
+ if (!hash2.startsWith("$scrypt$")) {
75
+ return true;
76
+ }
77
+ const parts = hash2.split("$");
78
+ if (parts.length !== 5) {
79
+ return true;
80
+ }
81
+ const paramsStr = parts[2];
82
+ const params = {};
83
+ for (const param of paramsStr.split(",")) {
84
+ const [key, value] = param.split("=");
85
+ params[key] = parseInt(value, 10);
86
+ }
87
+ return params.N !== cost || params.r !== memory;
88
+ }
89
+ function secureCompare(a, b) {
90
+ if (a.length !== b.length) {
91
+ return false;
92
+ }
93
+ const bufA = Buffer.from(a);
94
+ const bufB = Buffer.from(b);
95
+ return timingSafeEqual(bufA, bufB);
96
+ }
97
+ function check(value, hash2, algorithm = "sha256") {
98
+ const computed = createHash(algorithm).update(value).digest("hex");
99
+ return secureCompare(computed, hash2);
100
+ }
101
+
102
+ export {
103
+ hash,
104
+ hmac,
105
+ verifyHmac,
106
+ sha256,
107
+ sha512,
108
+ md5,
109
+ hashPassword,
110
+ verifyPassword,
111
+ needsRehash,
112
+ secureCompare,
113
+ check
114
+ };