@jini-ai/http-kit 0.6.16 → 0.6.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @jini-ai/http-kit
2
2
 
3
+ ## 0.6.19
4
+
5
+ - Tests: the route adapter's app fixture is a real `express()` app typed as `Express`, replacing the `app as any` casts.
6
+ - Extend the exception-log class guard to core, CMS, agent runtime, MCP, DB, chat, plugins and UI, including JSX and structured logs; reject caught values aliased to `message`.
7
+
8
+ - Redact exception logs with the shared core redactor while preserving correlation IDs and error codes.
9
+
10
+ ## 0.6.17
11
+
12
+ ### Patch Changes
13
+
14
+ - Version bump only.
15
+
3
16
  ## 0.6.16
4
17
 
5
18
  ### Patch Changes
package/dist/adapter.js CHANGED
@@ -3,14 +3,17 @@
3
3
  * `handle`, and response serialization into a single Express route handler. This is the only
4
4
  * file in the module that knows about Express `req`/`res` on the mounting side.
5
5
  */
6
+ import { inspect } from 'node:util';
7
+ import { redactSecrets } from '@jini-ai/core';
6
8
  import { randomUUID } from 'node:crypto';
7
9
  import { createApiError } from '@jini-ai/protocol';
8
10
  import { rawInput } from './request.js';
9
11
  import { sendApiError, sendJson, statusForError } from './response.js';
10
12
  import { guardSameOrigin } from './origin.js';
11
13
  function defaultInternalErrorSink(context) {
14
+ // Exceptions can echo credentials; inspect preserves stacks and codes before shared redaction.
12
15
  // eslint-disable-next-line no-console
13
- console.error(`[@jini-ai/http-kit] internal error (${context.method.toUpperCase()} ${context.path}, correlationId=${context.correlationId})`, context.error);
16
+ console.error(`[@jini-ai/http-kit] internal error (${context.method.toUpperCase()} ${context.path}, correlationId=${context.correlationId})`, redactSecrets({ input: inspect(context.error) }, { redactPii: false }));
14
17
  }
15
18
  /**
16
19
  * Thrown by a route's `handle` — or by anything it calls, at any depth — to bypass the SEC-005
@@ -54,6 +54,8 @@ export declare function createMemoryCounterStore(_required: Record<string, never
54
54
  * delays. Counter updates and periodic eviction run in arrival order across
55
55
  * storage awaits. Rejected checks do not consume more of the budget.
56
56
  * @param required - Host profile, clock and dedicated counter store.
57
+ * @param options - Optional live max resolver, awaited within the check queue. Window duration
58
+ * and burst stay fixed; changing the max never resets counts. Resolver failures reject checks.
57
59
  * @returns An async limiter. Storage failures reject the caller's check.
58
60
  * Invalid keys reject with TypeError before storage or queue state is touched.
59
61
  * @example const result = await limiter.check({ key: clientIp });
@@ -62,7 +64,11 @@ export declare function createRateLimiter({ profile, clock, store }: {
62
64
  profile: RateLimitProfile;
63
65
  clock: Clock;
64
66
  store: CounterStore;
65
- }, _optional?: Record<string, never>): RateLimiter;
67
+ }, { getMax }?: {
68
+ getMax?: (required: {
69
+ key: string;
70
+ }, optional: Record<string, never>) => number | Promise<number>;
71
+ }): RateLimiter;
66
72
  /** Structural request shape; transport/framework trust configuration stays outside. */
67
73
  export interface ClientIpSource {
68
74
  readonly socket: {
@@ -21,21 +21,28 @@ export function createMemoryCounterStore(_required, _optional = {}) {
21
21
  * delays. Counter updates and periodic eviction run in arrival order across
22
22
  * storage awaits. Rejected checks do not consume more of the budget.
23
23
  * @param required - Host profile, clock and dedicated counter store.
24
+ * @param options - Optional live max resolver, awaited within the check queue. Window duration
25
+ * and burst stay fixed; changing the max never resets counts. Resolver failures reject checks.
24
26
  * @returns An async limiter. Storage failures reject the caller's check.
25
27
  * Invalid keys reject with TypeError before storage or queue state is touched.
26
28
  * @example const result = await limiter.check({ key: clientIp });
27
29
  */
28
- export function createRateLimiter({ profile, clock, store }, _optional = {}) {
30
+ export function createRateLimiter({ profile, clock, store }, { getMax } = {}) {
29
31
  const windowMs = profile.windowSeconds * 1000;
30
- const effectiveMax = profile.max + profile.burst;
31
32
  let lastSweepMs = null;
32
33
  let pending = Promise.resolve();
34
+ /** Read the current budget without changing the active window; invalid policy fails closed. */
35
+ async function budgetFor(key) {
36
+ const max = getMax ? await getMax({ key }, {}) : profile.max;
37
+ if (!Number.isInteger(max) || max < 0)
38
+ throw new RangeError('rate limit max must be a non-negative integer');
39
+ return max + profile.burst;
40
+ }
33
41
  // Expiry sweeps prevent attacker-controlled keys (for example rotating anonymous source IPs)
34
42
  // from accumulating forever. Work is O(tracked keys) only once per window; per-request full
35
43
  // scans would replace a memory-exhaustion risk with linear request latency. Active key volume
36
44
  // still determines memory use, and separate in-memory processes each retain their own budget.
37
- async function consume(key) {
38
- const nowMs = clock.nowMs();
45
+ async function sweepExpired(nowMs) {
39
46
  if (lastSweepMs === null) {
40
47
  lastSweepMs = nowMs;
41
48
  }
@@ -51,8 +58,17 @@ export function createRateLimiter({ profile, clock, store }, _optional = {}) {
51
58
  else {
52
59
  // The active window needs no expiry sweep.
53
60
  }
61
+ }
62
+ async function consume(key) {
63
+ // Resolve inside the serialized check: a settings change must not reset consumed counters
64
+ // or create independent queues over the same store. Resolver failures fail closed.
65
+ const effectiveMax = await budgetFor(key);
66
+ const nowMs = clock.nowMs();
67
+ await sweepExpired(nowMs);
54
68
  const existing = await store.get({ key });
55
69
  if (!existing || nowMs - existing.windowStartMs >= windowMs) {
70
+ if (effectiveMax === 0)
71
+ return { allowed: false, retryAfterSeconds: Math.ceil(windowMs / 1000) };
56
72
  await store.set({ key, state: { windowStartMs: nowMs, count: 1 } });
57
73
  return { allowed: true };
58
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/http-kit",
3
- "version": "0.6.16",
3
+ "version": "0.6.19",
4
4
  "description": "Generic Express transport primitives, request parsing, response serialization, origin guards and route-pack mounting.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -71,14 +71,14 @@
71
71
  "@types/express": "^4.17.21",
72
72
  "@vitest/coverage-v8": "^2.1.9",
73
73
  "express": "^4.21.0",
74
- "@jini-ai/core": "0.6.16",
75
- "@jini-ai/platform": "0.6.16",
76
- "@jini-ai/protocol": "0.6.16"
74
+ "@jini-ai/platform": "0.6.19",
75
+ "@jini-ai/protocol": "0.6.19",
76
+ "@jini-ai/core": "0.6.19"
77
77
  },
78
78
  "dependencies": {
79
- "@jini-ai/platform": "^0.6.16",
80
- "@jini-ai/core": "^0.6.16",
81
- "@jini-ai/protocol": "^0.6.16"
79
+ "@jini-ai/protocol": "^0.6.19",
80
+ "@jini-ai/platform": "^0.6.19",
81
+ "@jini-ai/core": "^0.6.19"
82
82
  },
83
83
  "scripts": {
84
84
  "build": "tsc -p tsconfig.json",