@guren/server 2.18.0 → 2.20.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 (36) hide show
  1. package/dist/{Job-DxQK8h3P.js → Job-CvDwk2Gj.js} +14 -6
  2. package/dist/Logger-DFifRAtc.js +114 -0
  3. package/dist/auth/index.js +1 -1
  4. package/dist/{auth-Gg54ppQi.js → auth-BXcHQwHf.js} +123 -40
  5. package/dist/cache/index.js +1 -1
  6. package/dist/cache/types.d.ts +5 -1
  7. package/dist/{cache-BOOIr324.js → cache-DUhlolkJ.js} +18 -3
  8. package/dist/client-C5Wj9P9o.js +70 -0
  9. package/dist/console/Command.d.ts +2 -0
  10. package/dist/container/Container.d.ts +9 -0
  11. package/dist/container/bindings.d.ts +3 -0
  12. package/dist/http/Application.d.ts +2 -0
  13. package/dist/http/middleware/cookie-session-store.d.ts +38 -0
  14. package/dist/http/middleware/index.d.ts +6 -0
  15. package/dist/http/middleware/session-manager.d.ts +86 -0
  16. package/dist/http/middleware/session.d.ts +40 -2
  17. package/dist/index.d.ts +4 -2
  18. package/dist/index.js +236 -23
  19. package/dist/lambda/index.js +6 -5
  20. package/dist/logging/index.js +2 -1
  21. package/dist/{logging-zOY1XCtq.js → logging-DXmqqUl4.js} +2 -114
  22. package/dist/mail/index.js +1 -1
  23. package/dist/{mail-76DWy9lj.js → mail-9CrvJyBZ.js} +1 -1
  24. package/dist/notifications/index.js +1 -1
  25. package/dist/{notifications-okWFs9ly.js → notifications-D0VXkFLF.js} +1 -1
  26. package/dist/providers/AuthServiceProvider.d.ts +18 -1
  27. package/dist/queue/index.js +2 -2
  28. package/dist/{queue-CcXCjuJI.js → queue-zPPYZdif.js} +1 -1
  29. package/dist/redis/index.js +1 -62
  30. package/dist/redis/lazy-client.d.ts +8 -0
  31. package/dist/runtime/index.js +3 -3
  32. package/dist/runtime/serverless.d.ts +15 -0
  33. package/dist/serverless-D96rJb6x.js +22 -0
  34. package/dist/{vite-manifest-DhbXfFct.js → vite-manifest-BZQ-75hf.js} +2 -2
  35. package/package.json +2 -2
  36. package/dist/client-C4TEr_Dd.js +0 -9
@@ -1,3 +1,4 @@
1
+ import { r as isPromiseLike, t as Logger } from "./Logger-DFifRAtc.js";
1
2
  import * as path$1 from "node:path";
2
3
  import * as fs from "node:fs";
3
4
  //#region src/logging/types.ts
@@ -13,119 +14,6 @@ const LOG_LEVEL_PRIORITY = {
13
14
  debug: 7
14
15
  };
15
16
  //#endregion
16
- //#region src/logging/Logger.ts
17
- const DEFAULT_FILTER_KEYS = [
18
- "password",
19
- "password_confirmation",
20
- "token",
21
- "secret",
22
- "credit_card",
23
- "creditCard",
24
- "card_number",
25
- "cardNumber",
26
- "cvv",
27
- "ssn",
28
- "authorization"
29
- ];
30
- /** Recursively replace values of sensitive keys in a log context object. */
31
- function filterSensitiveData(data, filterKeys, replacement = "[FILTERED]") {
32
- if (filterKeys.length === 0) return data;
33
- return filterObject(data, new Set(filterKeys.map((k) => k.toLowerCase())), replacement);
34
- }
35
- function filterObject(obj, keySet, replacement) {
36
- const result = {};
37
- for (const [key, value] of Object.entries(obj)) if (keySet.has(key.toLowerCase())) result[key] = replacement;
38
- else if (value !== null && typeof value === "object" && !Array.isArray(value)) result[key] = filterObject(value, keySet, replacement);
39
- else if (Array.isArray(value)) result[key] = value.map((item) => item !== null && typeof item === "object" && !Array.isArray(item) ? filterObject(item, keySet, replacement) : item);
40
- else result[key] = value;
41
- return result;
42
- }
43
- const reportLoggingError = (error) => {
44
- console.error("Logging error:", error);
45
- };
46
- /**
47
- * Whether a channel's `log()` handed back something to wait on. A duck-typed
48
- * check rather than `instanceof Promise`: a promise created in another realm
49
- * (a `node:vm` context, a worker's module graph) satisfies the channel
50
- * contract and would otherwise slip past the reporter as an unhandled rejection.
51
- */
52
- function isPromiseLike(value) {
53
- return typeof value === "object" && value !== null && typeof value.then === "function";
54
- }
55
- /** Logger instance for writing log entries. */
56
- var Logger = class Logger {
57
- channels;
58
- baseContext;
59
- filterKeys;
60
- replacement;
61
- constructor(channels, context = {}, options = {}) {
62
- this.channels = channels;
63
- this.baseContext = context;
64
- this.filterKeys = options.filterKeys ?? DEFAULT_FILTER_KEYS;
65
- this.replacement = options.replacement ?? "[FILTERED]";
66
- }
67
- emergency(message, context = {}) {
68
- this.log("emergency", message, context);
69
- }
70
- alert(message, context = {}) {
71
- this.log("alert", message, context);
72
- }
73
- critical(message, context = {}) {
74
- this.log("critical", message, context);
75
- }
76
- error(message, context = {}) {
77
- this.log("error", message, context);
78
- }
79
- warning(message, context = {}) {
80
- this.log("warning", message, context);
81
- }
82
- warn(message, context = {}) {
83
- this.warning(message, context);
84
- }
85
- notice(message, context = {}) {
86
- this.log("notice", message, context);
87
- }
88
- info(message, context = {}) {
89
- this.log("info", message, context);
90
- }
91
- debug(message, context = {}) {
92
- this.log("debug", message, context);
93
- }
94
- log(level, message, context = {}) {
95
- const merged = {
96
- ...this.baseContext,
97
- ...context
98
- };
99
- const entry = {
100
- level,
101
- message,
102
- context: this.filterKeys.length > 0 ? filterSensitiveData(merged, this.filterKeys, this.replacement) : merged,
103
- timestamp: /* @__PURE__ */ new Date()
104
- };
105
- for (const channel of this.channels) try {
106
- const pending = channel.log(entry);
107
- if (isPromiseLike(pending)) Promise.resolve(pending).catch(reportLoggingError);
108
- } catch (error) {
109
- reportLoggingError(error);
110
- }
111
- }
112
- withContext(context) {
113
- return new Logger(this.channels, {
114
- ...this.baseContext,
115
- ...context
116
- }, {
117
- filterKeys: this.filterKeys,
118
- replacement: this.replacement
119
- });
120
- }
121
- child(context) {
122
- return this.withContext(context);
123
- }
124
- async close() {
125
- for (const channel of this.channels) if (channel.close) await channel.close();
126
- }
127
- };
128
- //#endregion
129
17
  //#region src/logging/channels/ConsoleChannel.ts
130
18
  const LEVEL_COLORS = {
131
19
  emergency: "\x1B[41m\x1B[37m",
@@ -469,4 +357,4 @@ function getLogManager() {
469
357
  return globalLogManager;
470
358
  }
471
359
  //#endregion
472
- export { DailyFileChannel as a, matchDailyFileDate as c, Logger as d, filterSensitiveData as f, setLogManager as i, FileChannel as l, createLogManager as n, dailyFileDateStamp as o, LOG_LEVEL_PRIORITY as p, getLogManager as r, dailyFilePath as s, LogManager as t, ConsoleChannel as u };
360
+ export { DailyFileChannel as a, matchDailyFileDate as c, LOG_LEVEL_PRIORITY as d, setLogManager as i, FileChannel as l, createLogManager as n, dailyFileDateStamp as o, getLogManager as r, dailyFilePath as s, LogManager as t, ConsoleChannel as u };
@@ -1,2 +1,2 @@
1
- import { a as MailManager, c as MemoryTransport, i as setMailManager, l as ResendTransport, n as getMailManager, o as createMailManager, r as mail, s as LogTransport, t as Mail, u as SmtpTransport } from "../mail-76DWy9lj.js";
1
+ import { a as MailManager, c as MemoryTransport, i as setMailManager, l as ResendTransport, n as getMailManager, o as createMailManager, r as mail, s as LogTransport, t as Mail, u as SmtpTransport } from "../mail-9CrvJyBZ.js";
2
2
  export { LogTransport, Mail, MailManager, MemoryTransport, ResendTransport, SmtpTransport, createMailManager, getMailManager, mail, setMailManager };
@@ -1,4 +1,4 @@
1
- import { i as getQueueDriver, o as registerJob, t as Job } from "./Job-DxQK8h3P.js";
1
+ import { i as getQueueDriver, o as registerJob, t as Job } from "./Job-CvDwk2Gj.js";
2
2
  import { t as parseMailAddress } from "./address-D0Iq-XIH.js";
3
3
  import nodemailer from "nodemailer";
4
4
  //#region src/mail/transports/SmtpTransport.ts
@@ -1,2 +1,2 @@
1
- import { a as NotificationManager, c as setNotificationManager, d as getNotification, f as registerNotification, i as MailChannel, l as resolveNotifiableType, n as SlackChannel, o as createNotificationManager, p as Notification, r as DatabaseChannel, s as getNotificationManager, t as MemoryChannel, u as clearNotificationRegistry } from "../notifications-okWFs9ly.js";
1
+ import { a as NotificationManager, c as setNotificationManager, d as getNotification, f as registerNotification, i as MailChannel, l as resolveNotifiableType, n as SlackChannel, o as createNotificationManager, p as Notification, r as DatabaseChannel, s as getNotificationManager, t as MemoryChannel, u as clearNotificationRegistry } from "../notifications-D0VXkFLF.js";
2
2
  export { DatabaseChannel, MailChannel, MemoryChannel, Notification, NotificationManager, SlackChannel, clearNotificationRegistry, createNotificationManager, getNotification, getNotificationManager, registerNotification, resolveNotifiableType, setNotificationManager };
@@ -1,4 +1,4 @@
1
- import { o as registerJob, t as Job } from "./Job-DxQK8h3P.js";
1
+ import { o as registerJob, t as Job } from "./Job-CvDwk2Gj.js";
2
2
  import { t as parseMailAddress } from "./address-D0Iq-XIH.js";
3
3
  //#region src/notifications/Notification.ts
4
4
  /**
@@ -1,5 +1,22 @@
1
1
  import { ServiceProvider } from '../container/ServiceProvider.js';
2
- /** Sets up authentication guards, session middleware, and auth context. */
2
+ /**
3
+ * Sets up authentication guards, session middleware, and auth context. The
4
+ * session store may come from a `session` container binding (RFC 0020 §1),
5
+ * which an app's SessionProvider must make in `register()`: the middleware is
6
+ * built in `boot()`, before any user provider's own boot runs.
7
+ */
3
8
  export declare class AuthServiceProvider extends ServiceProvider {
9
+ private app;
10
+ private attachedSession;
11
+ private sessionMiddleware;
4
12
  register(): void;
13
+ /**
14
+ * Every provider has registered, so the manager, a double configuration, a
15
+ * missing driver, and a bad APP_KEY (the cookie signer) all fail here, not
16
+ * on the first request. Only the store itself stays lazy. A *deferred*
17
+ * SessionProvider activates on a make() after boot, so that one shape keeps
18
+ * the first-request build.
19
+ */
20
+ boot(): void;
21
+ private buildSessionMiddleware;
5
22
  }
@@ -1,3 +1,3 @@
1
- import { a as getRegisteredJobs, c as setQueueDriver, i as getQueueDriver, n as clearJobRegistry, o as registerJob, r as getJob, s as resolveJobName, t as Job } from "../Job-DxQK8h3P.js";
2
- import { a as processJob, c as RedisDriver, i as Worker, l as SyncDriver, n as createQueueManager, o as SqsDriver, r as FailedJobReporter, s as createSqsAdapter, t as QueueManager, u as MemoryDriver } from "../queue-CcXCjuJI.js";
1
+ import { a as getRegisteredJobs, c as setQueueDriver, i as getQueueDriver, n as clearJobRegistry, o as registerJob, r as getJob, s as resolveJobName, t as Job } from "../Job-CvDwk2Gj.js";
2
+ import { a as processJob, c as RedisDriver, i as Worker, l as SyncDriver, n as createQueueManager, o as SqsDriver, r as FailedJobReporter, s as createSqsAdapter, t as QueueManager, u as MemoryDriver } from "../queue-zPPYZdif.js";
3
3
  export { FailedJobReporter, Job, MemoryDriver, QueueManager, RedisDriver, SqsDriver, SyncDriver, Worker, clearJobRegistry, createQueueManager, createSqsAdapter, getJob, getQueueDriver, getRegisteredJobs, processJob, registerJob, resolveJobName, setQueueDriver };
@@ -1,4 +1,4 @@
1
- import { c as setQueueDriver, r as getJob } from "./Job-DxQK8h3P.js";
1
+ import { c as setQueueDriver, r as getJob } from "./Job-CvDwk2Gj.js";
2
2
  //#region src/queue/drivers/MemoryDriver.ts
3
3
  /** In-memory queue driver for development and testing. */
4
4
  var MemoryDriver = class {
@@ -1,66 +1,5 @@
1
1
  import { toDate, toOptionalExpiry } from "../support/expiry.js";
2
- import { n as createRedisClient, t as Redis } from "../client-C4TEr_Dd.js";
3
- //#region src/redis/scan-keys.ts
4
- /** Cursor-based SCAN rather than the O(N), server-blocking KEYS. */
5
- async function scanKeys(redis, pattern) {
6
- const keys = [];
7
- let cursor = "0";
8
- do {
9
- const [newCursor, foundKeys] = await redis.scan(cursor, "MATCH", pattern, "COUNT", 100);
10
- cursor = newCursor;
11
- keys.push(...foundKeys);
12
- } while (cursor !== "0");
13
- return keys;
14
- }
15
- //#endregion
16
- //#region src/redis/RedisSessionStore.ts
17
- var RedisSessionStore = class {
18
- redis;
19
- prefix;
20
- constructor(redis, options = {}) {
21
- this.redis = redis;
22
- this.prefix = options.prefix ?? "session:";
23
- }
24
- async read(id) {
25
- const key = this.prefix + id;
26
- const data = await this.redis.get(key);
27
- if (!data) return;
28
- try {
29
- return JSON.parse(data);
30
- } catch {
31
- return;
32
- }
33
- }
34
- async write(id, data, ttlSeconds) {
35
- const key = this.prefix + id;
36
- const serialized = JSON.stringify(data);
37
- await this.redis.setex(key, ttlSeconds, serialized);
38
- }
39
- async destroy(id) {
40
- const key = this.prefix + id;
41
- await this.redis.del(key);
42
- }
43
- /** EXPIRE on a missing key is a no-op, never a resurrection. */
44
- async touch(id, ttlSeconds) {
45
- const key = this.prefix + id;
46
- await this.redis.expire(key, ttlSeconds);
47
- }
48
- /** Debugging/admin. */
49
- async keys() {
50
- return (await scanKeys(this.redis, this.prefix + "*")).map((key) => key.slice(this.prefix.length));
51
- }
52
- async size() {
53
- return (await this.keys()).length;
54
- }
55
- async clear() {
56
- const keys = await this.keys();
57
- if (keys.length > 0) {
58
- const prefixedKeys = keys.map((key) => this.prefix + key);
59
- await this.redis.del(...prefixedKeys);
60
- }
61
- }
62
- };
63
- //#endregion
2
+ import { i as scanKeys, n as createRedisClient, r as RedisSessionStore, t as Redis } from "../client-C5Wj9P9o.js";
64
3
  //#region src/redis/RedisRateLimitStore.ts
65
4
  /**
66
5
  * Returns [count, resetAt]. Exported for the in-memory fake in tests, which
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The one rule for a `client` option that may be an ioredis instance or a
3
+ * function returning one: the function runs here, not where the config object
4
+ * was declared, so a declared-but-unselected store never dials. Cache and
5
+ * session both resolve through it — a second copy is how the two subsystems
6
+ * come to disagree about what `client` accepts.
7
+ */
8
+ export declare function resolveLazyRedisClient(client: unknown, label: string): unknown;
@@ -1,6 +1,6 @@
1
1
  import { n as trimTrailingSlashes } from "../trim-slashes-BLY9hKAa.js";
2
2
  import { n as hash } from "../Hash-D2DFd8xX.js";
3
- import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-DhbXfFct.js";
3
+ import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-BZQ-75hf.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { realpath } from "node:fs/promises";
6
6
  import { dirname, extname, join, resolve, sep } from "node:path";
@@ -220,7 +220,7 @@ function registerDevAssets(app, options) {
220
220
  jsx: "transform",
221
221
  jsxFactory: "React.createElement",
222
222
  jsxFragment: "React.Fragment",
223
- define: { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "development") }
223
+ define: { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development") }
224
224
  };
225
225
  const transpile = {
226
226
  tsx: new Bun.Transpiler({
@@ -351,7 +351,7 @@ function createJsxRuntimeShim(helpers, runtimeUrl) {
351
351
  }).join("\n")}\n`;
352
352
  }
353
353
  function isDev() {
354
- return (process.env.NODE_ENV ?? "development") !== "production";
354
+ return process.env.NODE_ENV !== "production";
355
355
  }
356
356
  function deriveCssRoute(prefix) {
357
357
  const base = prefix.endsWith("/js") ? prefix.slice(0, -3) : prefix;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The one place server decides "which serverless runtime is this". Kept
3
+ * import-free so the session middleware and the Lambda adapter can both read
4
+ * it without either dragging the other in. plugin-cloudflare's
5
+ * `isWorkersRuntime()` reads the same user agent.
6
+ */
7
+ export type ServerlessRuntimeId = 'cloudflare' | 'lambda' | 'vercel';
8
+ /** The deploy targets' names as the CLI checks report them; the CLI reads these. */
9
+ export declare const SERVERLESS_RUNTIME_LABELS: Readonly<Record<ServerlessRuntimeId, string>>;
10
+ export interface ServerlessRuntime {
11
+ readonly id: ServerlessRuntimeId;
12
+ /** The platform's env seen through a local emulator; what that means is the caller's call. */
13
+ readonly emulator?: 'sam-local' | 'vercel-dev';
14
+ }
15
+ export declare function detectServerlessRuntime(): ServerlessRuntime | undefined;
@@ -0,0 +1,22 @@
1
+ //#region src/runtime/serverless.ts
2
+ /** The deploy targets' names as the CLI checks report them; the CLI reads these. */
3
+ const SERVERLESS_RUNTIME_LABELS = {
4
+ cloudflare: "Cloudflare Workers",
5
+ lambda: "AWS Lambda",
6
+ vercel: "Vercel"
7
+ };
8
+ function detectServerlessRuntime() {
9
+ if (typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") return { id: "cloudflare" };
10
+ if (typeof process === "undefined") return;
11
+ const env = process.env;
12
+ if (env.AWS_LAMBDA_FUNCTION_NAME) return env.AWS_SAM_LOCAL ? {
13
+ id: "lambda",
14
+ emulator: "sam-local"
15
+ } : { id: "lambda" };
16
+ if (env.VERCEL) return env.VERCEL_ENV === "development" ? {
17
+ id: "vercel",
18
+ emulator: "vercel-dev"
19
+ } : { id: "vercel" };
20
+ }
21
+ //#endregion
22
+ export { detectServerlessRuntime as n, SERVERLESS_RUNTIME_LABELS as t };
@@ -34,7 +34,7 @@ function parseImportMap(value, options = {}) {
34
34
  const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
35
35
  //#endregion
36
36
  //#region package.json
37
- var version = "2.18.0";
37
+ var version = "2.20.0";
38
38
  //#endregion
39
39
  //#region src/http/dev-banner.ts
40
40
  figlet.parseFont("Standard", standard);
@@ -138,7 +138,7 @@ const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
138
138
  * `NODE_ENV` is `production` (E2E runs do exactly this).
139
139
  */
140
140
  function isViteProduction(devServerUrl = process.env.VITE_DEV_SERVER_URL) {
141
- return (process.env.NODE_ENV ?? "development") === "production" && typeof devServerUrl !== "string";
141
+ return process.env.NODE_ENV === "production" && typeof devServerUrl !== "string";
142
142
  }
143
143
  function normalizeDevServerUrl(value) {
144
144
  if (!value) return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.18.0",
3
+ "version": "2.20.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -142,7 +142,7 @@
142
142
  "test": "bun test"
143
143
  },
144
144
  "dependencies": {
145
- "@guren/orm": "^2.6.3",
145
+ "@guren/orm": "^2.7.0",
146
146
  "@modelcontextprotocol/sdk": "^1.30.0",
147
147
  "chalk": "^5.3.0",
148
148
  "consola": "^3.4.2",
@@ -1,9 +0,0 @@
1
- import Redis from "ioredis";
2
- //#region src/redis/client.ts
3
- function createRedisClient(options = {}) {
4
- const { url, ...redisOptions } = options;
5
- if (url) return new Redis(url, redisOptions);
6
- return new Redis(redisOptions);
7
- }
8
- //#endregion
9
- export { createRedisClient as n, Redis as t };