@steve31415/baselib 3.34.1 → 3.36.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.
@@ -21,10 +21,14 @@ export interface Logger {
21
21
  export interface SerializedError {
22
22
  name: string;
23
23
  message: string;
24
+ /** The error's own `code` (Node's `ECONNREFUSED`, Postgres SQLSTATE, an
25
+ * app error's machine-readable reason), when it is a string or number. */
26
+ code?: string | number;
24
27
  stack?: string;
25
28
  cause?: {
26
29
  name: string;
27
30
  message: string;
31
+ code?: string | number;
28
32
  };
29
33
  }
30
34
  export declare function serializeError(err: unknown): SerializedError;
package/dist/log-core.js CHANGED
@@ -10,11 +10,30 @@
10
10
  // ship-failure check counts. makeEvent also guards the shape of `meta`: every
11
11
  // distinct key is an Axiom column (see "Key-shape guard" below).
12
12
  export const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
13
+ const CODE_MAX = 100;
14
+ /** An Error's `code` property when it is a primitive worth a column: a
15
+ * string (capped) or a finite number. Anything else is dropped, since an
16
+ * object there would mint `meta.error.code.*` keys from data. */
17
+ function errorCode(err) {
18
+ const code = err.code;
19
+ if (typeof code === 'string')
20
+ return truncate(code, CODE_MAX);
21
+ if (typeof code === 'number' && Number.isFinite(code))
22
+ return code;
23
+ return undefined;
24
+ }
13
25
  export function serializeError(err) {
14
26
  if (err instanceof Error) {
15
- const out = { name: err.name, message: err.message, stack: err.stack };
27
+ const out = { name: err.name, message: err.message };
28
+ const code = errorCode(err);
29
+ if (code !== undefined)
30
+ out.code = code;
31
+ out.stack = err.stack;
16
32
  if (err.cause instanceof Error) {
17
33
  out.cause = { name: err.cause.name, message: err.cause.message };
34
+ const causeCode = errorCode(err.cause);
35
+ if (causeCode !== undefined)
36
+ out.cause.code = causeCode;
18
37
  }
19
38
  else if (err.cause !== undefined) {
20
39
  out.cause = { name: 'cause', message: truncate(String(err.cause), 500) };
package/dist/s2s.d.ts CHANGED
@@ -7,8 +7,12 @@ import { type Logger } from './log-core.js';
7
7
  * disables the always-allow rule (fail closed). */
8
8
  export declare function codingAgentSa(): string | undefined;
9
9
  /** caller service-account email → allowed "METHOD /path" patterns.
10
- * Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*"),
11
- * or "*" for everything. */
10
+ * Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*",
11
+ * a prefix: the bare path and everything under it), a single-segment
12
+ * wildcard anywhere else ("GET /api/tasks/*\/card": exactly one non-empty
13
+ * segment in that position, so one task-scoped method can be granted without
14
+ * the whole prefix — 2026-10-12, Radar's grant on Coder's card and decide
15
+ * routes), or "*" for everything. */
12
16
  export type Grants = Record<string, string[]>;
13
17
  export interface ServiceCaller {
14
18
  type: 's2s';
package/dist/s2s.js CHANGED
@@ -40,9 +40,20 @@ export function grantAllows(grants, email, method, path) {
40
40
  const prefix = p.slice(0, -1); // keep the trailing slash
41
41
  return want.startsWith(prefix) || want === p.slice(0, -2);
42
42
  }
43
+ if (p.includes('/*/'))
44
+ return segmentsMatch(p, want);
43
45
  return want === p;
44
46
  });
45
47
  }
48
+ /** "METHOD /a/*\/b" against "METHOD /a/x/b": the same number of segments,
49
+ * each equal or a `*` standing for exactly one non-empty segment. */
50
+ function segmentsMatch(pattern, want) {
51
+ const ps = pattern.split('/');
52
+ const ws = want.split('/');
53
+ if (ps.length !== ws.length)
54
+ return false;
55
+ return ps.every((seg, i) => (seg === '*' ? ws[i].length > 0 : seg === ws[i]));
56
+ }
46
57
  // Fixed-window per-identity rate limiter — a sanity check against runaway
47
58
  // loops and mischief, not a precision tool (per-instance state only).
48
59
  export class RateLimiter {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.34.1",
3
+ "version": "3.36.0",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",