@guren/server 2.32.0 → 2.34.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 (44) hide show
  1. package/dist/{Gate-COWQbA96.js → Gate-C252SwRR.js} +13 -5
  2. package/dist/{McpServiceProvider-DwIbM1zn.js → McpServiceProvider-CXOokGax.js} +3 -1
  3. package/dist/{Resource-LQT1L4j0.js → Resource-BBKaFgXf.js} +41 -30
  4. package/dist/agent/scopes.d.ts +7 -0
  5. package/dist/{api-token-BbgDEd6j.js → api-token-DJcqSybf.js} +186 -1
  6. package/dist/auth/AuthManager.d.ts +4 -1
  7. package/dist/auth/TokenGuard.d.ts +4 -1
  8. package/dist/auth/api-token.d.ts +11 -1
  9. package/dist/auth/index.js +2 -2
  10. package/dist/{auth-DRMeSwev.js → auth-Bj9uEHuC.js} +15 -23
  11. package/dist/authorization/Gate.d.ts +5 -4
  12. package/dist/authorization/index.js +2 -2
  13. package/dist/{authorization-DEHuBps5.js → authorization-C81TXOWD.js} +1 -1
  14. package/dist/broadcasting/index.js +1 -1
  15. package/dist/{broadcasting-CcevVE5Y.js → broadcasting-3pvO94xV.js} +2 -1
  16. package/dist/{dev-banner-BGRan2PN.js → dev-banner-B_QaY29h.js} +1 -1
  17. package/dist/errors/ExceptionHandler.d.ts +2 -1
  18. package/dist/errors/debug-page.d.ts +1 -1
  19. package/dist/errors/redact-query-params.d.ts +16 -0
  20. package/dist/health/index.js +1 -1
  21. package/dist/{health-Bg0Xj3aD.js → health-Wi_05kkf.js} +2 -1
  22. package/dist/http/Application.d.ts +12 -0
  23. package/dist/index.js +54 -139
  24. package/dist/internal/agent-principal.d.ts +12 -3
  25. package/dist/internal/redact-query-params.d.ts +1 -0
  26. package/dist/internal/redact-query-params.js +2 -0
  27. package/dist/internal/testing.d.ts +2 -1
  28. package/dist/internal/testing.js +2 -2
  29. package/dist/lambda/index.js +3 -2
  30. package/dist/mcp/index.js +1 -1
  31. package/dist/mvc/Controller.d.ts +5 -5
  32. package/dist/mvc/inertia/InertiaEngine.d.ts +6 -0
  33. package/dist/notifications/index.js +1 -1
  34. package/dist/{notifications-R7Uj-aT7.js → notifications-DV5Yr6Fl.js} +2 -1
  35. package/dist/queue/index.js +1 -1
  36. package/dist/{queue-CO07wib_.js → queue-K4Bi6NRy.js} +17 -11
  37. package/dist/redact-query-params-Ba-sAfcP.js +106 -0
  38. package/dist/runtime/index.js +1 -1
  39. package/dist/{runtime-error-capture-DzllKc0d.js → runtime-error-capture-DLRXwp0d.js} +2 -2
  40. package/dist/{runtime-errors-D229wyoc.js → runtime-errors-Dh7nA2-p.js} +1 -1
  41. package/dist/scheduling/index.js +1 -1
  42. package/dist/{scheduling-DNV5tj44.js → scheduling-iLkx4gID.js} +2 -1
  43. package/dist/support/default-headers.d.ts +6 -0
  44. package/package.json +5 -1
@@ -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-R7Uj-aT7.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-DV5Yr6Fl.js";
2
2
  export { DatabaseChannel, MailChannel, MemoryChannel, Notification, NotificationManager, SlackChannel, clearNotificationRegistry, createNotificationManager, getNotification, getNotificationManager, registerNotification, resolveNotifiableType, setNotificationManager };
@@ -1,4 +1,5 @@
1
1
  import { g as warnDeprecatedSetter, h as warnDeprecatedGetter, i as bindAmbient, n as ambientBinding } from "./default-application-s9SE-Er7.js";
2
+ import { t as redactQueryParams } from "./redact-query-params-Ba-sAfcP.js";
2
3
  import { l as registerJob, p as reportRegistryCollision, t as Job } from "./Job-0Prk8k0z.js";
3
4
  import { t as parseMailAddress } from "./address-D0Iq-XIH.js";
4
5
  //#region src/notifications/Notification.ts
@@ -136,7 +137,7 @@ var NotificationManager = class {
136
137
  try {
137
138
  await this.channel(channelName).send(notifiable, notification);
138
139
  } catch (error) {
139
- console.error(`Failed to send notification via ${channelName}:`, error);
140
+ console.error(`Failed to send notification via ${channelName}:`, redactQueryParams(error));
140
141
  throw error;
141
142
  }
142
143
  }));
@@ -1,3 +1,3 @@
1
1
  import { a as getJob, d as resolveQueueDriver, f as setQueueDriver, l as registerJob, n as clearJobRegistry, o as getQueueDriver, r as clearQueueDriver, s as getRegisteredJobs, t as Job, u as resolveJobName } from "../Job-0Prk8k0z.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-CO07wib_.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-K4Bi6NRy.js";
3
3
  export { FailedJobReporter, Job, MemoryDriver, QueueManager, RedisDriver, SqsDriver, SyncDriver, Worker, clearJobRegistry, clearQueueDriver, createQueueManager, createSqsAdapter, getJob, getQueueDriver, getRegisteredJobs, processJob, registerJob, resolveJobName, resolveQueueDriver, setQueueDriver };
@@ -1,4 +1,5 @@
1
1
  import { t as warnOnce } from "./warn-once-p-IlMjra.js";
2
+ import { n as redactedMessage, t as redactQueryParams } from "./redact-query-params-Ba-sAfcP.js";
2
3
  import { a as getJob, i as enqueueJob } from "./Job-0Prk8k0z.js";
3
4
  import { t as describeDriverMap } from "./driver-map-BhITaLcy.js";
4
5
  import { t as deserializeQueuedJob } from "./serialize-CKXek0Tr.js";
@@ -32,11 +33,12 @@ var MemoryDriver = class {
32
33
  this.jobs.delete(jobId);
33
34
  }
34
35
  async fail(job, error) {
36
+ const { message, stack } = redactQueryParams(error);
35
37
  const failedJob = {
36
38
  ...job,
37
39
  failedAt: /* @__PURE__ */ new Date(),
38
- error: error.message,
39
- stack: error.stack
40
+ error: message,
41
+ stack
40
42
  };
41
43
  this.failedJobs.set(job.id, failedJob);
42
44
  this.jobs.delete(job.id);
@@ -117,11 +119,12 @@ var SyncDriver = class {
117
119
  }
118
120
  async delete() {}
119
121
  async fail(job, error) {
122
+ const { message, stack } = redactQueryParams(error);
120
123
  this.failedJobs.set(job.id, {
121
124
  ...job,
122
125
  failedAt: /* @__PURE__ */ new Date(),
123
- error: error.message,
124
- stack: error.stack
126
+ error: message,
127
+ stack
125
128
  });
126
129
  }
127
130
  async size() {
@@ -332,7 +335,8 @@ var RedisDriver = class {
332
335
  await this.run("gurenQueueDelete", this.jobKey(jobId), jobId, reservationToken ?? "", this.prefix);
333
336
  }
334
337
  async fail(job, error) {
335
- await this.run("gurenQueueFail", this.jobKey(job.id), this.pendingKey(job.queue), this.reservedKey(job.queue), this.failedKey(job.queue), job.id, job.reservationToken ?? "", (/* @__PURE__ */ new Date()).toISOString(), error.message, error.stack ?? "", job.attempts);
338
+ const { message, stack } = redactQueryParams(error);
339
+ await this.run("gurenQueueFail", this.jobKey(job.id), this.pendingKey(job.queue), this.reservedKey(job.queue), this.failedKey(job.queue), job.id, job.reservationToken ?? "", (/* @__PURE__ */ new Date()).toISOString(), message, stack ?? "", job.attempts);
336
340
  }
337
341
  async size(queue) {
338
342
  return this.redis.zcard(this.pendingKey(queue));
@@ -554,11 +558,12 @@ var SqsDriver = class {
554
558
  await this.acknowledge(jobId);
555
559
  }
556
560
  async fail(job, error) {
561
+ const { message, stack } = redactQueryParams(error);
557
562
  const failedJob = {
558
563
  ...job,
559
564
  failedAt: /* @__PURE__ */ new Date(),
560
- error: error.message,
561
- stack: error.stack
565
+ error: message,
566
+ stack
562
567
  };
563
568
  this.failedJobs.set(job.id, failedJob);
564
569
  try {
@@ -723,7 +728,8 @@ var Worker = class {
723
728
  this.currentJob = null;
724
729
  }
725
730
  }
726
- async handleFailedJob(job, error, JobClass) {
731
+ async handleFailedJob(job, thrown, JobClass) {
732
+ const error = redactQueryParams(thrown);
727
733
  const willRetry = job.attempts < job.maxAttempts;
728
734
  if (willRetry) {
729
735
  const delay = JobClass.calculateRetryDelay(job.attempts);
@@ -733,9 +739,9 @@ var Worker = class {
733
739
  await this.driver.fail(job, error);
734
740
  try {
735
741
  const instance = this.instantiate(JobClass);
736
- if (instance.failed) await instance.failed(job.payload, error);
742
+ if (instance.failed) await instance.failed(job.payload, thrown);
737
743
  } catch (failedError) {
738
- console.error(`Error in job.failed() handler:`, failedError);
744
+ console.error(`Error in job.failed() handler:`, redactQueryParams(failedError));
739
745
  }
740
746
  }
741
747
  console.error(JSON.stringify({
@@ -821,7 +827,7 @@ function defaultLogHandler(info) {
821
827
  attempt: info.attempt,
822
828
  maxAttempts: info.maxAttempts,
823
829
  willRetry: info.willRetry,
824
- error: info.error.message,
830
+ error: redactedMessage(info.error),
825
831
  failedAt: info.failedAt.toISOString()
826
832
  }));
827
833
  }
@@ -0,0 +1,106 @@
1
+ //#region src/errors/redact-query-params.ts
2
+ /**
3
+ * Strips SQL bound parameters out of an exception before anything prints it:
4
+ * drizzle's `DrizzleQueryError` writes `Failed query: <sql>\nparams: <values>`
5
+ * into its message and stack and keeps the values on `.params`, so a failed
6
+ * INSERT would hand a password hash to the 500 body, the debug page and the log.
7
+ * The shape is detected structurally, since the app may load its own drizzle.
8
+ */
9
+ const QUERY_PREFIX = "Failed query: ";
10
+ const PARAMS_SEPARATOR = "\nparams: ";
11
+ const REDACTED = "[redacted";
12
+ const PARAM_KEYS = /* @__PURE__ */ new Set([
13
+ "params",
14
+ "parameters",
15
+ "args"
16
+ ]);
17
+ function marker(count) {
18
+ return count === void 0 ? `${REDACTED}]` : `${REDACTED} ${count} value${count === 1 ? "" : "s"}]`;
19
+ }
20
+ /** drizzle's own shape, which says where the values start and how many there are. */
21
+ function drizzleShape(error) {
22
+ const { query, params } = error;
23
+ return typeof query === "string" && Array.isArray(params) ? {
24
+ query,
25
+ count: params.length
26
+ } : void 0;
27
+ }
28
+ /** mysql2 formats the values into the statement client-side and keeps it on `err.sql`. */
29
+ function isMysqlDriverError(error) {
30
+ return typeof error.sql === "string" && ("sqlState" in error || "sqlMessage" in error);
31
+ }
32
+ function isSensitive(error, key, value) {
33
+ if (key === "sql") return isMysqlDriverError(error);
34
+ return PARAM_KEYS.has(key) && Array.isArray(value) && typeof error.query === "string";
35
+ }
36
+ /** A message is cut to its end; a stack only up to its first frame. */
37
+ function redactText(text, shape, stack = false) {
38
+ const prefix = shape ? `${QUERY_PREFIX}${shape.query}${PARAMS_SEPARATOR}` : void 0;
39
+ const known = prefix ? text.indexOf(prefix) : -1;
40
+ let start;
41
+ if (known !== -1) start = known + prefix.length;
42
+ else {
43
+ const query = text.indexOf(QUERY_PREFIX);
44
+ const separator = query === -1 ? -1 : text.indexOf(PARAMS_SEPARATOR, query);
45
+ if (separator === -1) return text;
46
+ start = separator + 9;
47
+ }
48
+ if (text.startsWith(REDACTED, start)) return text;
49
+ const frames = stack ? text.indexOf("\n at ", start) : -1;
50
+ return text.slice(0, start) + marker(known !== -1 ? shape.count : void 0) + text.slice(frames === -1 ? text.length : frames);
51
+ }
52
+ function redactStack(error, message) {
53
+ const { stack } = error;
54
+ if (typeof stack !== "string") return stack;
55
+ const at = message === error.message ? -1 : stack.indexOf(error.message);
56
+ if (at !== -1) return stack.slice(0, at) + message + stack.slice(at + error.message.length);
57
+ return redactText(stack, drizzleShape(error), true);
58
+ }
59
+ function needsRedaction(error, seen) {
60
+ if (seen.has(error)) return false;
61
+ seen.add(error);
62
+ if (Reflect.ownKeys(error).some((key) => {
63
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
64
+ return "value" in descriptor && isSensitive(error, key, descriptor.value);
65
+ })) return true;
66
+ if (redactText(error.message) !== error.message) return true;
67
+ if (typeof error.stack === "string" && redactText(error.stack, void 0, true) !== error.stack) return true;
68
+ const { cause } = error;
69
+ return cause instanceof Error && needsRedaction(cause, seen);
70
+ }
71
+ function redactCopy(error, seen) {
72
+ const existing = seen.get(error);
73
+ if (existing) return existing;
74
+ const copy = /* @__PURE__ */ new Error();
75
+ Object.setPrototypeOf(copy, Object.getPrototypeOf(error));
76
+ seen.set(error, copy);
77
+ const message = redactText(error.message, drizzleShape(error));
78
+ for (const key of Reflect.ownKeys(error)) {
79
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
80
+ if ("value" in descriptor) {
81
+ const { value } = descriptor;
82
+ if (key === "message") descriptor.value = message;
83
+ else if (key === "stack") descriptor.value = redactStack(error, message);
84
+ else if (key === "cause" && value instanceof Error) descriptor.value = redactCopy(value, seen);
85
+ else if (isSensitive(error, key, value)) descriptor.value = marker(Array.isArray(value) ? value.length : void 0);
86
+ }
87
+ Object.defineProperty(copy, key, descriptor);
88
+ }
89
+ return copy;
90
+ }
91
+ /**
92
+ * The value itself unless it is an error that, or whose cause chain, carries
93
+ * bound parameters; then a copy with the same prototype and own properties
94
+ * whose message, stack, parameter fields and causes are redacted. Being a copy,
95
+ * it carries no `#private` field a custom renderer or `toResponse()` reads.
96
+ */
97
+ function redactQueryParams(error) {
98
+ if (!(error instanceof Error) || !needsRedaction(error, /* @__PURE__ */ new Set())) return error;
99
+ return redactCopy(error, /* @__PURE__ */ new Map());
100
+ }
101
+ /** `error.message` with bound parameters redacted, for a log line that prints the message alone. */
102
+ function redactedMessage(error) {
103
+ return error instanceof Error ? redactQueryParams(error).message : void 0;
104
+ }
105
+ //#endregion
106
+ export { redactedMessage as n, redactQueryParams as t };
@@ -2,7 +2,7 @@ import { a as trimTrailingSlashes, n as isRealPathWithin, t as isPathWithin } fr
2
2
  import { n as parseImportMap } from "../inertia-defaults-BjrcT7za.js";
3
3
  import { n as hash } from "../Hash-D2DFd8xX.js";
4
4
  import { a as getManifestCss, c as isViteProduction, d as startViteDevServer, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-DO0pU1vm.js";
5
- import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-BGRan2PN.js";
5
+ import { r as logDevServerBanner, t as GUREN_ASCII_ART } from "../dev-banner-B_QaY29h.js";
6
6
  import { createRequire } from "node:module";
7
7
  import { dirname, extname, join, resolve } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
@@ -1,5 +1,5 @@
1
- import { t as createLoopbackGuard } from "./loopback-guard-CG8xB4v0.js";
2
1
  import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
2
+ import { t as createLoopbackGuard } from "./loopback-guard-CG8xB4v0.js";
3
3
  //#region src/mcp/endpoint.ts
4
4
  const MCP_ENDPOINT_PATH = "/_guren/mcp";
5
5
  /** Where the Dev Center saves a plan review's feedback (RFC 0030 §8), its one write route. */
@@ -46,7 +46,7 @@ let loading;
46
46
  * a call no define can settle. `tests/mcp/runtime-errors.test.ts` pins the form.
47
47
  */
48
48
  function loadRuntimeErrorsModule() {
49
- if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && isMcpEndpointEnabled()) return loading ??= import("./runtime-errors-D229wyoc.js");
49
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && isMcpEndpointEnabled()) return loading ??= import("./runtime-errors-Dh7nA2-p.js");
50
50
  }
51
51
  /** Only ExceptionHandler calls this, after applying its dontReport policy. */
52
52
  function captureRuntimeError(error, ctx, status) {
@@ -1,5 +1,5 @@
1
- import { n as RUNTIME_ERRORS_PATH, t as RUNTIME_ERRORS_BINDING } from "./runtime-error-capture-DzllKc0d.js";
2
1
  import { r as tryGetRequestContainer } from "./request-container-BbuH0JJy.js";
2
+ import { n as RUNTIME_ERRORS_PATH, t as RUNTIME_ERRORS_BINDING } from "./runtime-error-capture-DLRXwp0d.js";
3
3
  import { realpathSync, statSync } from "node:fs";
4
4
  import { routePath } from "hono/route";
5
5
  //#region src/mcp/runtime-errors.ts
@@ -1,2 +1,2 @@
1
- import { a as ScheduledTask, c as isDue, d as parseCron, f as toTimezone, i as Schedule, l as isDueInTimezone, n as createScheduler, o as getNextOccurrence, p as MemorySchedulerLock, r as PendingSchedule, s as getNextOccurrences, t as Scheduler, u as matchesCron } from "../scheduling-DNV5tj44.js";
1
+ import { a as ScheduledTask, c as isDue, d as parseCron, f as toTimezone, i as Schedule, l as isDueInTimezone, n as createScheduler, o as getNextOccurrence, p as MemorySchedulerLock, r as PendingSchedule, s as getNextOccurrences, t as Scheduler, u as matchesCron } from "../scheduling-iLkx4gID.js";
2
2
  export { MemorySchedulerLock, PendingSchedule, Schedule, ScheduledTask, Scheduler, createScheduler, getNextOccurrence, getNextOccurrences, isDue, isDueInTimezone, matchesCron, parseCron, toTimezone };
@@ -1,4 +1,5 @@
1
1
  import { t as warnOnce } from "./warn-once-p-IlMjra.js";
2
+ import { n as redactedMessage } from "./redact-query-params-Ba-sAfcP.js";
2
3
  import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposables-W2fH-GID.js";
3
4
  //#region src/scheduling/MemorySchedulerLock.ts
4
5
  /**
@@ -700,7 +701,7 @@ function createScheduler(options) {
700
701
  return new Scheduler(options);
701
702
  }
702
703
  function describe(error) {
703
- return error instanceof Error ? error.message : String(error);
704
+ return redactedMessage(error) ?? String(error);
704
705
  }
705
706
  //#endregion
706
707
  export { ScheduledTask as a, isDue as c, parseCron as d, toTimezone as f, Schedule as i, isDueInTimezone as l, createScheduler as n, getNextOccurrence as o, MemorySchedulerLock as p, PendingSchedule as r, getNextOccurrences as s, Scheduler as t, matchesCron as u };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The caller's headers with each default set only where the caller named none. Header
3
+ * names are case-insensitive, so a caller's `content-type` replaces `Content-Type`
4
+ * rather than joining it; spreading a `Headers` or a pair list would drop it.
5
+ */
6
+ export declare function withDefaultHeaders(init: HeadersInit | undefined, defaults: Record<string, string>): Headers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.32.0",
3
+ "version": "2.34.0",
4
4
  "description": "HTTP layer of the Guren framework, on Hono: routing, controllers, middleware, auth, sessions, queues and the AWS Lambda adapter. Applications import it through @guren/core.",
5
5
  "keywords": [
6
6
  "guren",
@@ -148,6 +148,10 @@
148
148
  "types": "./dist/internal/inertia-page.d.ts",
149
149
  "default": "./dist/internal/inertia-page.js"
150
150
  },
151
+ "./internal/redact-query-params": {
152
+ "types": "./dist/internal/redact-query-params.d.ts",
153
+ "default": "./dist/internal/redact-query-params.js"
154
+ },
151
155
  "./jsx-runtime": {
152
156
  "types": "./dist/jsx-runtime.d.ts",
153
157
  "default": "./dist/jsx-runtime.js"