@guren/server 2.3.0 → 2.4.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/broadcasting/index.js +2 -1
- package/dist/{chunk-SIP34GBE.js → chunk-2SC566CD.js} +14 -18
- package/dist/{chunk-4VE3LYOM.js → chunk-DRNPVBAA.js} +20 -5
- package/dist/{chunk-LVJCZCAV.js → chunk-H3B23O6T.js} +10 -118
- package/dist/{chunk-6IGN233M.js → chunk-NENDACRP.js} +16 -4
- package/dist/chunk-V4DNC2ER.js +114 -0
- package/dist/encryption/index.js +17 -15
- package/dist/health/index.js +1 -1
- package/dist/http/Application.d.ts +55 -1
- package/dist/http/FormRequest.d.ts +10 -7
- package/dist/http/dev-banner.d.ts +11 -0
- package/dist/http/middleware/validation-errors-cookie.d.ts +31 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +301 -82
- package/dist/redis/index.js +6 -4
- package/dist/runtime/index.js +2 -2
- package/dist/support/inertia-defaults.d.ts +13 -0
- package/package.json +2 -2
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
createTypedBroadcaster,
|
|
10
10
|
getBroadcastManager,
|
|
11
11
|
setBroadcastManager
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-DRNPVBAA.js";
|
|
13
13
|
import "../chunk-B5E5VBDI.js";
|
|
14
|
+
import "../chunk-V4DNC2ER.js";
|
|
14
15
|
export {
|
|
15
16
|
BroadcastManager,
|
|
16
17
|
Channel,
|
|
@@ -105,26 +105,22 @@ var HealthManager = class {
|
|
|
105
105
|
return async (ctx, next) => {
|
|
106
106
|
const report = options.checks ? await this.checkOnly(options.checks) : await this.check();
|
|
107
107
|
const statusCode = report.status === "healthy" ? 200 : report.status === "degraded" ? 200 : 503;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
ctx.json({
|
|
111
|
-
status: report.status,
|
|
112
|
-
timestamp: report.timestamp.toISOString()
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
ctx.status(statusCode);
|
|
116
|
-
ctx.json({
|
|
108
|
+
ctx.res = ctx.json(
|
|
109
|
+
{
|
|
117
110
|
status: report.status,
|
|
118
111
|
timestamp: report.timestamp.toISOString(),
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
...options.detailed === false ? {} : {
|
|
113
|
+
checks: report.checks.map((check) => ({
|
|
114
|
+
name: check.name,
|
|
115
|
+
status: check.status,
|
|
116
|
+
message: check.message,
|
|
117
|
+
duration: check.duration,
|
|
118
|
+
meta: check.meta
|
|
119
|
+
}))
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
statusCode
|
|
123
|
+
);
|
|
128
124
|
};
|
|
129
125
|
}
|
|
130
126
|
/**
|
|
@@ -2,6 +2,9 @@ import {
|
|
|
2
2
|
claimHotDisposable,
|
|
3
3
|
isHotReloadRuntime
|
|
4
4
|
} from "./chunk-B5E5VBDI.js";
|
|
5
|
+
import {
|
|
6
|
+
randomHex
|
|
7
|
+
} from "./chunk-V4DNC2ER.js";
|
|
5
8
|
|
|
6
9
|
// src/broadcasting/channels/Channel.ts
|
|
7
10
|
var Channel = class {
|
|
@@ -520,6 +523,14 @@ function formatValidationErrors(error, fallbackMessage = "The provided data is i
|
|
|
520
523
|
}
|
|
521
524
|
|
|
522
525
|
// src/broadcasting/BroadcastManager.ts
|
|
526
|
+
function resolveClientUserId(user) {
|
|
527
|
+
if (typeof user !== "object" || user === null) return void 0;
|
|
528
|
+
const candidate = user;
|
|
529
|
+
for (const value of [candidate.id, candidate.sub, candidate.userId]) {
|
|
530
|
+
if (typeof value === "string" || typeof value === "number") return value;
|
|
531
|
+
}
|
|
532
|
+
return void 0;
|
|
533
|
+
}
|
|
523
534
|
var BroadcastManager = class {
|
|
524
535
|
/**
|
|
525
536
|
* Default driver name.
|
|
@@ -689,6 +700,7 @@ var BroadcastManager = class {
|
|
|
689
700
|
authorizedChannels.push(channelName);
|
|
690
701
|
}
|
|
691
702
|
}
|
|
703
|
+
const clientUserId = resolveClientUserId(user);
|
|
692
704
|
let controller = null;
|
|
693
705
|
let client = null;
|
|
694
706
|
let pingTimer = null;
|
|
@@ -718,7 +730,9 @@ var BroadcastManager = class {
|
|
|
718
730
|
controller = streamController;
|
|
719
731
|
client = {
|
|
720
732
|
id: clientId,
|
|
721
|
-
|
|
733
|
+
// Recorded so `POST /broadcasting/auth` can refuse to attach
|
|
734
|
+
// channels to a stream belonging to someone else.
|
|
735
|
+
userId: clientUserId,
|
|
722
736
|
channels: /* @__PURE__ */ new Set(),
|
|
723
737
|
send: (event, data) => {
|
|
724
738
|
const message = `event: ${event}
|
|
@@ -774,13 +788,16 @@ data: ${JSON.stringify(data)}
|
|
|
774
788
|
}
|
|
775
789
|
const clientId = typeof payload.clientId === "string" ? payload.clientId : void 0;
|
|
776
790
|
const results = {};
|
|
791
|
+
const requesterId = resolveClientUserId(user);
|
|
792
|
+
const target = clientId ? this.sseClients.get(clientId) : void 0;
|
|
793
|
+
const attachTo = target && (target.userId === void 0 || target.userId === requesterId) ? target : void 0;
|
|
777
794
|
for (const ch of channels) {
|
|
778
795
|
const authResult = await this.authorize(ch, user);
|
|
779
796
|
if (authResult === false || authResult === null) {
|
|
780
797
|
results[ch] = { authorized: false };
|
|
781
798
|
continue;
|
|
782
799
|
}
|
|
783
|
-
const subscribed =
|
|
800
|
+
const subscribed = attachTo ? this.subscribeClient(attachTo.id, ch) : false;
|
|
784
801
|
if (authResult === true) {
|
|
785
802
|
results[ch] = { authorized: true, subscribed };
|
|
786
803
|
} else {
|
|
@@ -918,9 +935,7 @@ data: ${JSON.stringify(data)}
|
|
|
918
935
|
* Generate a unique client ID.
|
|
919
936
|
*/
|
|
920
937
|
generateClientId(prefix = "sse") {
|
|
921
|
-
|
|
922
|
-
const random = Math.random().toString(36).substring(2, 10);
|
|
923
|
-
return `${prefix}_${timestamp}${random}`;
|
|
938
|
+
return `${prefix}_${randomHex(16)}`;
|
|
924
939
|
}
|
|
925
940
|
};
|
|
926
941
|
var globalBroadcastManager = null;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/encryption/Encrypter.ts
|
|
8
8
|
import { createCipheriv, createDecipheriv, randomBytes, createHmac } from "crypto";
|
|
9
|
+
var GCM_TAG_BYTES = 16;
|
|
9
10
|
var Encrypter = class {
|
|
10
11
|
/**
|
|
11
12
|
* Encryption key.
|
|
@@ -79,7 +80,7 @@ var Encrypter = class {
|
|
|
79
80
|
*/
|
|
80
81
|
encryptGcm(data) {
|
|
81
82
|
const iv = randomBytes(12);
|
|
82
|
-
const cipher = createCipheriv("aes-256-gcm", this.key, iv);
|
|
83
|
+
const cipher = createCipheriv("aes-256-gcm", this.key, iv, { authTagLength: GCM_TAG_BYTES });
|
|
83
84
|
const encrypted = Buffer.concat([
|
|
84
85
|
cipher.update(data, "utf8"),
|
|
85
86
|
cipher.final()
|
|
@@ -96,11 +97,14 @@ var Encrypter = class {
|
|
|
96
97
|
* Decrypt using AES-256-GCM.
|
|
97
98
|
*/
|
|
98
99
|
decryptGcm(payload) {
|
|
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
|
+
if (tag.length !== GCM_TAG_BYTES) {
|
|
104
|
+
throw new Error("Invalid authentication tag length.");
|
|
105
|
+
}
|
|
99
106
|
return this.tryDecryptWithKeys((key) => {
|
|
100
|
-
const
|
|
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);
|
|
107
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv, { authTagLength: GCM_TAG_BYTES });
|
|
104
108
|
decipher.setAuthTag(tag);
|
|
105
109
|
const decrypted = Buffer.concat([
|
|
106
110
|
decipher.update(encrypted),
|
|
@@ -254,104 +258,6 @@ function verifySignedUrl(value, keyring, options = {}) {
|
|
|
254
258
|
return payload?.url === canonical;
|
|
255
259
|
}
|
|
256
260
|
|
|
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 unbiasedRandomChars(length, chars) {
|
|
268
|
-
if (!Number.isInteger(length) || length < 0) {
|
|
269
|
-
throw new RangeError(`Random string length must be a non-negative integer, received ${length}.`);
|
|
270
|
-
}
|
|
271
|
-
const limit = 256 - 256 % chars.length;
|
|
272
|
-
let result = "";
|
|
273
|
-
while (result.length < length) {
|
|
274
|
-
const remaining = length - result.length;
|
|
275
|
-
const bytes = randomBytes2(Math.ceil(remaining * 256 / limit) + 8);
|
|
276
|
-
for (const byte of bytes) {
|
|
277
|
-
if (byte < limit) {
|
|
278
|
-
result += chars[byte % chars.length];
|
|
279
|
-
if (result.length === length) break;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
function randomString(length, options = {}) {
|
|
286
|
-
const { charset = "alphanumeric" } = options;
|
|
287
|
-
return unbiasedRandomChars(length, CHARSETS[charset]);
|
|
288
|
-
}
|
|
289
|
-
function random(length) {
|
|
290
|
-
return randomBytes2(length);
|
|
291
|
-
}
|
|
292
|
-
function randomHex(length) {
|
|
293
|
-
return randomBytes2(length).toString("hex");
|
|
294
|
-
}
|
|
295
|
-
function randomBase64(length) {
|
|
296
|
-
return randomBytes2(length).toString("base64");
|
|
297
|
-
}
|
|
298
|
-
function randomBase64Url(length) {
|
|
299
|
-
return randomBytes2(length).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
300
|
-
}
|
|
301
|
-
function uuid() {
|
|
302
|
-
return randomUUID();
|
|
303
|
-
}
|
|
304
|
-
function randomInt(min, max) {
|
|
305
|
-
return cryptoRandomInt(min, max + 1);
|
|
306
|
-
}
|
|
307
|
-
function urlSafeToken(length = 32) {
|
|
308
|
-
return randomBase64Url(Math.ceil(length * 0.75)).slice(0, length);
|
|
309
|
-
}
|
|
310
|
-
function generatePassword(length = 16, options = {}) {
|
|
311
|
-
const {
|
|
312
|
-
uppercase = true,
|
|
313
|
-
lowercase = true,
|
|
314
|
-
numbers = true,
|
|
315
|
-
symbols = true
|
|
316
|
-
} = options;
|
|
317
|
-
let chars = "";
|
|
318
|
-
if (uppercase) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
319
|
-
if (lowercase) chars += "abcdefghijklmnopqrstuvwxyz";
|
|
320
|
-
if (numbers) chars += "0123456789";
|
|
321
|
-
if (symbols) chars += "!@#$%^&*()-_=+[]{}|;:,.<>?";
|
|
322
|
-
if (chars.length === 0) {
|
|
323
|
-
chars = CHARSETS.alphanumeric;
|
|
324
|
-
}
|
|
325
|
-
return unbiasedRandomChars(length, chars);
|
|
326
|
-
}
|
|
327
|
-
function generateOtp(length = 6) {
|
|
328
|
-
return randomString(length, { charset: "numeric" });
|
|
329
|
-
}
|
|
330
|
-
function generateSlug(length = 10) {
|
|
331
|
-
return randomString(length, { charset: "hex" });
|
|
332
|
-
}
|
|
333
|
-
function shuffle(array) {
|
|
334
|
-
const result = [...array];
|
|
335
|
-
for (let i = result.length - 1; i > 0; i--) {
|
|
336
|
-
const j = randomInt(0, i);
|
|
337
|
-
[result[i], result[j]] = [result[j], result[i]];
|
|
338
|
-
}
|
|
339
|
-
return result;
|
|
340
|
-
}
|
|
341
|
-
function pick(array) {
|
|
342
|
-
if (array.length === 0) {
|
|
343
|
-
throw new Error("Cannot pick from empty array.");
|
|
344
|
-
}
|
|
345
|
-
return array[randomInt(0, array.length - 1)];
|
|
346
|
-
}
|
|
347
|
-
function sample(array, count) {
|
|
348
|
-
if (count > array.length) {
|
|
349
|
-
throw new Error("Sample count exceeds array length.");
|
|
350
|
-
}
|
|
351
|
-
const shuffled = shuffle(array);
|
|
352
|
-
return shuffled.slice(0, count);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
261
|
export {
|
|
356
262
|
Encrypter,
|
|
357
263
|
generateKey,
|
|
@@ -361,19 +267,5 @@ export {
|
|
|
361
267
|
encrypt,
|
|
362
268
|
decrypt,
|
|
363
269
|
signUrl,
|
|
364
|
-
verifySignedUrl
|
|
365
|
-
randomString,
|
|
366
|
-
random,
|
|
367
|
-
randomHex,
|
|
368
|
-
randomBase64,
|
|
369
|
-
randomBase64Url,
|
|
370
|
-
uuid,
|
|
371
|
-
randomInt,
|
|
372
|
-
urlSafeToken,
|
|
373
|
-
generatePassword,
|
|
374
|
-
generateOtp,
|
|
375
|
-
generateSlug,
|
|
376
|
-
shuffle,
|
|
377
|
-
pick,
|
|
378
|
-
sample
|
|
270
|
+
verifySignedUrl
|
|
379
271
|
};
|
|
@@ -6,7 +6,7 @@ import standard from "figlet/importable-fonts/Standard.js";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@guren/server",
|
|
9
|
-
version: "2.
|
|
9
|
+
version: "2.4.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
license: "MIT",
|
|
12
12
|
repository: {
|
|
@@ -119,7 +119,7 @@ var package_default = {
|
|
|
119
119
|
test: "bun test"
|
|
120
120
|
},
|
|
121
121
|
dependencies: {
|
|
122
|
-
"@guren/orm": "^2.2.
|
|
122
|
+
"@guren/orm": "^2.2.2",
|
|
123
123
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
124
124
|
chalk: "^5.3.0",
|
|
125
125
|
consola: "^3.4.2",
|
|
@@ -176,14 +176,20 @@ function generateAsciiArt(text) {
|
|
|
176
176
|
}
|
|
177
177
|
var GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
|
|
178
178
|
var GUREN_VERSION = package_default.version;
|
|
179
|
+
function isWildcardHost(hostname) {
|
|
180
|
+
return hostname === "0.0.0.0" || hostname === "::";
|
|
181
|
+
}
|
|
182
|
+
function formatHostPort(hostname, port) {
|
|
183
|
+
return `${hostname.includes(":") ? `[${hostname}]` : hostname}:${port}`;
|
|
184
|
+
}
|
|
179
185
|
function logDevServerBanner({
|
|
180
186
|
hostname,
|
|
181
187
|
port,
|
|
182
188
|
assetsUrl = "http://localhost:5173"
|
|
183
189
|
}) {
|
|
184
190
|
const localUrl = `http://localhost:${port}`;
|
|
185
|
-
const boundUrl = `http://${hostname
|
|
186
|
-
const boundLabel = hostname
|
|
191
|
+
const boundUrl = `http://${formatHostPort(hostname, port)}`;
|
|
192
|
+
const boundLabel = isWildcardHost(hostname) ? " (all interfaces)" : "";
|
|
187
193
|
const header = [
|
|
188
194
|
GUREN_ASCII_ART,
|
|
189
195
|
chalk.magentaBright.bold(
|
|
@@ -254,9 +260,15 @@ function parseImportMap(value, options = {}) {
|
|
|
254
260
|
}
|
|
255
261
|
}
|
|
256
262
|
|
|
263
|
+
// src/support/inertia-defaults.ts
|
|
264
|
+
var DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
|
|
265
|
+
|
|
257
266
|
export {
|
|
258
267
|
parseImportMap,
|
|
268
|
+
DEFAULT_DEV_STYLES_ENTRY,
|
|
259
269
|
GUREN_ASCII_ART,
|
|
270
|
+
isWildcardHost,
|
|
271
|
+
formatHostPort,
|
|
260
272
|
logDevServerBanner,
|
|
261
273
|
startViteDevServer
|
|
262
274
|
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/encryption/Random.ts
|
|
2
|
+
import { randomBytes, randomUUID, randomInt as cryptoRandomInt } from "crypto";
|
|
3
|
+
var CHARSETS = {
|
|
4
|
+
alphanumeric: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
5
|
+
alphabetic: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
6
|
+
numeric: "0123456789",
|
|
7
|
+
hex: "0123456789abcdef",
|
|
8
|
+
"base64": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
9
|
+
"url-safe": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
10
|
+
};
|
|
11
|
+
function unbiasedRandomChars(length, chars) {
|
|
12
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
13
|
+
throw new RangeError(`Random string length must be a non-negative integer, received ${length}.`);
|
|
14
|
+
}
|
|
15
|
+
const limit = 256 - 256 % chars.length;
|
|
16
|
+
let result = "";
|
|
17
|
+
while (result.length < length) {
|
|
18
|
+
const remaining = length - result.length;
|
|
19
|
+
const bytes = randomBytes(Math.ceil(remaining * 256 / limit) + 8);
|
|
20
|
+
for (const byte of bytes) {
|
|
21
|
+
if (byte < limit) {
|
|
22
|
+
result += chars[byte % chars.length];
|
|
23
|
+
if (result.length === length) break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function randomString(length, options = {}) {
|
|
30
|
+
const { charset = "alphanumeric" } = options;
|
|
31
|
+
return unbiasedRandomChars(length, CHARSETS[charset]);
|
|
32
|
+
}
|
|
33
|
+
function random(length) {
|
|
34
|
+
return randomBytes(length);
|
|
35
|
+
}
|
|
36
|
+
function randomHex(length) {
|
|
37
|
+
return randomBytes(length).toString("hex");
|
|
38
|
+
}
|
|
39
|
+
function randomBase64(length) {
|
|
40
|
+
return randomBytes(length).toString("base64");
|
|
41
|
+
}
|
|
42
|
+
function randomBase64Url(length) {
|
|
43
|
+
return randomBytes(length).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
44
|
+
}
|
|
45
|
+
function uuid() {
|
|
46
|
+
return randomUUID();
|
|
47
|
+
}
|
|
48
|
+
function randomInt(min, max) {
|
|
49
|
+
return cryptoRandomInt(min, max + 1);
|
|
50
|
+
}
|
|
51
|
+
function urlSafeToken(length = 32) {
|
|
52
|
+
return randomBase64Url(Math.ceil(length * 0.75)).slice(0, length);
|
|
53
|
+
}
|
|
54
|
+
function generatePassword(length = 16, options = {}) {
|
|
55
|
+
const {
|
|
56
|
+
uppercase = true,
|
|
57
|
+
lowercase = true,
|
|
58
|
+
numbers = true,
|
|
59
|
+
symbols = true
|
|
60
|
+
} = options;
|
|
61
|
+
let chars = "";
|
|
62
|
+
if (uppercase) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
63
|
+
if (lowercase) chars += "abcdefghijklmnopqrstuvwxyz";
|
|
64
|
+
if (numbers) chars += "0123456789";
|
|
65
|
+
if (symbols) chars += "!@#$%^&*()-_=+[]{}|;:,.<>?";
|
|
66
|
+
if (chars.length === 0) {
|
|
67
|
+
chars = CHARSETS.alphanumeric;
|
|
68
|
+
}
|
|
69
|
+
return unbiasedRandomChars(length, chars);
|
|
70
|
+
}
|
|
71
|
+
function generateOtp(length = 6) {
|
|
72
|
+
return randomString(length, { charset: "numeric" });
|
|
73
|
+
}
|
|
74
|
+
function generateSlug(length = 10) {
|
|
75
|
+
return randomString(length, { charset: "hex" });
|
|
76
|
+
}
|
|
77
|
+
function shuffle(array) {
|
|
78
|
+
const result = [...array];
|
|
79
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
80
|
+
const j = randomInt(0, i);
|
|
81
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function pick(array) {
|
|
86
|
+
if (array.length === 0) {
|
|
87
|
+
throw new Error("Cannot pick from empty array.");
|
|
88
|
+
}
|
|
89
|
+
return array[randomInt(0, array.length - 1)];
|
|
90
|
+
}
|
|
91
|
+
function sample(array, count) {
|
|
92
|
+
if (count > array.length) {
|
|
93
|
+
throw new Error("Sample count exceeds array length.");
|
|
94
|
+
}
|
|
95
|
+
const shuffled = shuffle(array);
|
|
96
|
+
return shuffled.slice(0, count);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
randomString,
|
|
101
|
+
random,
|
|
102
|
+
randomHex,
|
|
103
|
+
randomBase64,
|
|
104
|
+
randomBase64Url,
|
|
105
|
+
uuid,
|
|
106
|
+
randomInt,
|
|
107
|
+
urlSafeToken,
|
|
108
|
+
generatePassword,
|
|
109
|
+
generateOtp,
|
|
110
|
+
generateSlug,
|
|
111
|
+
shuffle,
|
|
112
|
+
pick,
|
|
113
|
+
sample
|
|
114
|
+
};
|
package/dist/encryption/index.js
CHANGED
|
@@ -4,25 +4,11 @@ import {
|
|
|
4
4
|
decrypt,
|
|
5
5
|
encrypt,
|
|
6
6
|
generateKey,
|
|
7
|
-
generateOtp,
|
|
8
|
-
generatePassword,
|
|
9
|
-
generateSlug,
|
|
10
7
|
getEncrypter,
|
|
11
|
-
pick,
|
|
12
|
-
random,
|
|
13
|
-
randomBase64,
|
|
14
|
-
randomBase64Url,
|
|
15
|
-
randomHex,
|
|
16
|
-
randomInt,
|
|
17
|
-
randomString,
|
|
18
|
-
sample,
|
|
19
8
|
setEncrypter,
|
|
20
|
-
shuffle,
|
|
21
9
|
signUrl,
|
|
22
|
-
urlSafeToken,
|
|
23
|
-
uuid,
|
|
24
10
|
verifySignedUrl
|
|
25
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-H3B23O6T.js";
|
|
26
12
|
import {
|
|
27
13
|
MessageSigner,
|
|
28
14
|
deriveAppKey,
|
|
@@ -47,6 +33,22 @@ import {
|
|
|
47
33
|
verifyHmac,
|
|
48
34
|
verifyPassword
|
|
49
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";
|
|
50
52
|
export {
|
|
51
53
|
Encrypter,
|
|
52
54
|
MessageSigner,
|
package/dist/health/index.js
CHANGED
|
@@ -105,6 +105,40 @@ export interface ApplicationListenOptions {
|
|
|
105
105
|
hostname?: string;
|
|
106
106
|
assetsUrl?: string;
|
|
107
107
|
vite?: StartViteDevServerOptions | false;
|
|
108
|
+
/**
|
|
109
|
+
* What to do when the requested port is already taken.
|
|
110
|
+
*
|
|
111
|
+
* `true` walks forward through the next 20 ports; `false` fails fast with
|
|
112
|
+
* the original EADDRINUSE. Unset walks outside production, matching the loop
|
|
113
|
+
* this option replaces.
|
|
114
|
+
*
|
|
115
|
+
* `GUREN_STRICT_PORT=1` forces fail-fast regardless, and `port: 0` never
|
|
116
|
+
* walks — the OS is already picking a free port.
|
|
117
|
+
*/
|
|
118
|
+
portFallback?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Where the server actually ended up listening.
|
|
122
|
+
*
|
|
123
|
+
* Returned by {@link Application.listen} so callers never have to infer the
|
|
124
|
+
* port from the port they asked for — with a port walk or `PORT=0` in play,
|
|
125
|
+
* those are different numbers, and scraping the human-readable dev banner is
|
|
126
|
+
* the only alternative.
|
|
127
|
+
*
|
|
128
|
+
* Read-only because {@link Application.address} hands back the very object
|
|
129
|
+
* `listen()` returned: a caller that adjusted its own copy would change what
|
|
130
|
+
* every later reader sees.
|
|
131
|
+
*/
|
|
132
|
+
export interface ListenAddress {
|
|
133
|
+
/**
|
|
134
|
+
* The port the socket is bound to — what the runtime reports, falling back
|
|
135
|
+
* to the port the successful `Bun.serve` call was made with.
|
|
136
|
+
*/
|
|
137
|
+
readonly port: number;
|
|
138
|
+
/** The hostname the socket is bound to. */
|
|
139
|
+
readonly hostname: string;
|
|
140
|
+
/** A URL that reaches the server, with a wildcard bind resolved to localhost. */
|
|
141
|
+
readonly url: string;
|
|
108
142
|
}
|
|
109
143
|
/**
|
|
110
144
|
* Application wires an app-local router into a running Hono instance.
|
|
@@ -121,6 +155,7 @@ export declare class Application {
|
|
|
121
155
|
private readonly authManager;
|
|
122
156
|
private viteDevServer?;
|
|
123
157
|
private bunServer?;
|
|
158
|
+
private boundAddress?;
|
|
124
159
|
private viteTeardownRegistered;
|
|
125
160
|
private bunTeardownRegistered;
|
|
126
161
|
private autoSessionAttached;
|
|
@@ -178,7 +213,26 @@ export declare class Application {
|
|
|
178
213
|
/**
|
|
179
214
|
* Convenience helper to start a Bun server when available.
|
|
180
215
|
*/
|
|
181
|
-
listen(options?: ApplicationListenOptions): Promise<
|
|
216
|
+
listen(options?: ApplicationListenOptions): Promise<ListenAddress>;
|
|
217
|
+
/**
|
|
218
|
+
* The address {@link Application.listen} bound, or `undefined` before it has
|
|
219
|
+
* been called and once this app's server has been superseded or torn down.
|
|
220
|
+
*
|
|
221
|
+
* The same object `listen()` returned, so callers that need the address
|
|
222
|
+
* later — an OpenAPI `servers` entry, an absolute URL, a health report —
|
|
223
|
+
* read it here instead of threading it out of the entrypoint.
|
|
224
|
+
*
|
|
225
|
+
* The stored value is preferred over re-reading the live server, because
|
|
226
|
+
* `listen()` resolves the port through a fallback the socket no longer
|
|
227
|
+
* carries.
|
|
228
|
+
*
|
|
229
|
+
* Liveness is only as good as the signal available: a server stopped through
|
|
230
|
+
* the framework — a later `listen()`, the process-exit teardown — clears the
|
|
231
|
+
* slot this reads, but one stopped by calling `stop()` on the Bun server
|
|
232
|
+
* directly does not, and this keeps reporting its address. Treat it as
|
|
233
|
+
* "where `listen()` put this app", not as a health check.
|
|
234
|
+
*/
|
|
235
|
+
get address(): ListenAddress | undefined;
|
|
182
236
|
/**
|
|
183
237
|
* Register a service provider.
|
|
184
238
|
*/
|
|
@@ -24,17 +24,16 @@ import type { ValidationRule } from './validation/types.js';
|
|
|
24
24
|
* }
|
|
25
25
|
* }
|
|
26
26
|
*
|
|
27
|
-
* authorize() {
|
|
28
|
-
* return this.user() !== null
|
|
27
|
+
* async authorize() {
|
|
28
|
+
* return (await this.user()) !== null
|
|
29
29
|
* }
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
32
32
|
* // In controller:
|
|
33
|
-
* const data = await this.
|
|
33
|
+
* const data = await new StorePostRequest().handle(this.ctx)
|
|
34
34
|
* // data is typed as StorePostData
|
|
35
35
|
* ```
|
|
36
|
-
|
|
37
|
-
/**
|
|
36
|
+
*
|
|
38
37
|
* @deprecated Legacy compatibility layer — prefer schema-first validation
|
|
39
38
|
* via `this.validateBody()` / `validateQuery()` / `validateParams()`.
|
|
40
39
|
*/
|
|
@@ -62,11 +61,15 @@ export declare abstract class FormRequest<T = Record<string, unknown>> {
|
|
|
62
61
|
attributes(): Record<string, string>;
|
|
63
62
|
/**
|
|
64
63
|
* Get the authenticated user from the request context.
|
|
64
|
+
*
|
|
65
|
+
* Awaiting is load-bearing: `this.user() !== null` compiles and is always
|
|
66
|
+
* true, because an unawaited call is a pending promise.
|
|
65
67
|
*/
|
|
66
|
-
protected user():
|
|
68
|
+
protected user<TUser = unknown>(): Promise<TUser | null>;
|
|
67
69
|
/**
|
|
68
70
|
* Handle the form request: authorize, parse body, validate, return typed data.
|
|
69
|
-
*
|
|
71
|
+
* Call it from a controller with the request context:
|
|
72
|
+
* `const data = await new StorePostRequest().handle(this.ctx)`.
|
|
70
73
|
*/
|
|
71
74
|
handle(ctx: Context): Promise<T>;
|
|
72
75
|
private parseBody;
|
|
@@ -4,4 +4,15 @@ export interface DevBannerOptions {
|
|
|
4
4
|
port: number;
|
|
5
5
|
assetsUrl?: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* A wildcard bind answers on every interface but is not itself dialable on
|
|
9
|
+
* every platform.
|
|
10
|
+
*
|
|
11
|
+
* Lives here rather than beside its other caller because the banner and
|
|
12
|
+
* `Application.listen()`'s returned address are two renderings of one fact,
|
|
13
|
+
* and a platform caveat added to only one of them is the drift this replaces.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isWildcardHost(hostname: string): boolean;
|
|
16
|
+
/** `host:port`, bracketing an IPv6 literal so the result is dialable. */
|
|
17
|
+
export declare function formatHostPort(hostname: string, port: number): string;
|
|
7
18
|
export declare function logDevServerBanner({ hostname, port, assetsUrl, }: DevBannerOptions): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Context, MiddlewareHandler } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Cookie flash for Inertia validation errors on apps with no session.
|
|
4
|
+
*
|
|
5
|
+
* The Laravel-style flow flashes errors to the session and redirects back,
|
|
6
|
+
* but sessions are only mounted when `createApp({ auth })` is configured — a
|
|
7
|
+
* fresh scaffold has none yet. Dropping the errors silently turns every
|
|
8
|
+
* validation failure into "the form did nothing", so without a session the
|
|
9
|
+
* flattened errors ride across the one redirect in a short-lived HttpOnly
|
|
10
|
+
* cookie instead: display-only data, no store required, working on every
|
|
11
|
+
* runtime (Bun, Workers, Lambda).
|
|
12
|
+
*/
|
|
13
|
+
export declare const VALIDATION_ERRORS_COOKIE = "guren_validation_errors";
|
|
14
|
+
/**
|
|
15
|
+
* The `Set-Cookie` value that flashes `errors` across the next redirect.
|
|
16
|
+
*/
|
|
17
|
+
export declare function validationErrorsSetCookie(errors: Record<string, string>): string;
|
|
18
|
+
/**
|
|
19
|
+
* The flashed errors carried by the current request, if any. Reading consumes
|
|
20
|
+
* the flash: the cleanup middleware expires the cookie on this response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readValidationErrorsCookie(ctx: Context): Record<string, string> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Expires the flash cookie on the response whose render consumed it,
|
|
25
|
+
* restoring the show-once semantics a session flash has. Runs post-`next()`,
|
|
26
|
+
* so a thrown `ValidationException` (whose renderer may be *setting* a fresh
|
|
27
|
+
* cookie on its 303) never reaches the deletion — and the `getSetCookie`
|
|
28
|
+
* guard covers any other path that just wrote the cookie on this same
|
|
29
|
+
* response.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createValidationErrorsCookieCleanup(): MiddlewareHandler;
|