@ultimat3/core 31.31.0 → 31.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.31.0",
3
+ "version": "31.32.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -54,6 +54,6 @@
54
54
  "test": "bun test"
55
55
  },
56
56
  "dependencies": {
57
- "@ultimat3/schema": "31.31.0"
57
+ "@ultimat3/schema": "31.32.0"
58
58
  }
59
59
  }
package/src/cursor.ts CHANGED
@@ -101,8 +101,10 @@ export function resetCursorSigning(): void {
101
101
  export function usesDevCursorSecret(options?: {
102
102
  readonly env?: Readonly<Record<string, string | undefined>> | undefined;
103
103
  }): boolean {
104
- if (options?.env === undefined) return currentSecret() === DEV_CURSOR_SECRET;
105
- return (configured || options.env[CURSOR_SECRET_KEY] || DEV_CURSOR_SECRET) === DEV_CURSOR_SECRET;
104
+ // `timingSafeEqual` though the other side is published: the left side is the live secret.
105
+ if (options?.env === undefined) return timingSafeEqual(currentSecret(), DEV_CURSOR_SECRET);
106
+ const secret = configured || options.env[CURSOR_SECRET_KEY] || DEV_CURSOR_SECRET;
107
+ return timingSafeEqual(secret, DEV_CURSOR_SECRET);
106
108
  }
107
109
 
108
110
  /** `base64url(payload).signature`. Opaque by contract: callers must never parse it. */
@@ -2,6 +2,7 @@
2
2
  // key (`ULTIMATE_ENV`), one spelling per value — the twin of `roles.ts`: `ROLE` says what the
3
3
  // process does, `ULTIMATE_ENV` says which deploy it belongs to.
4
4
 
5
+ import { renderFixShellArg } from './error-render';
5
6
  import { type CodedErrorInit, UltimateError } from './errors';
6
7
 
7
8
  export class EnvironmentInvalidError extends UltimateError {
@@ -63,7 +64,9 @@ export function resolveEnvironment(options?: ResolveEnvironmentOptions): Environ
63
64
  if (read.ok) return read.environment;
64
65
  throw new EnvironmentInvalidError({
65
66
  cause: `${ENVIRONMENT_KEY}="${read.declared}" is not one of ${ENVIRONMENTS.join(' | ')}`,
66
- fix: `export ${ENVIRONMENT_KEY}=${ENVIRONMENTS.join('|')} — one of those exact values`,
67
+ // A command that runs, never `KEY=a|b|c`, which a shell reads as two pipes. `production` is
68
+ // the fail-closed pick: it refuses every published dev secret, so a wrong guess stops a boot.
69
+ fix: `export ${renderFixShellArg(ENVIRONMENT_KEY, 'ULTIMATE_ENV')}=production # or whichever of ${ENVIRONMENTS.join(', ')} this deploy is, spelled exactly`,
67
70
  meta: { key: ENVIRONMENT_KEY, received: read.declared, allowed: ENVIRONMENTS },
68
71
  });
69
72
  }
@@ -78,11 +78,14 @@ export function parseSentryDsn(dsn: string): SentryDsn {
78
78
  }
79
79
 
80
80
  /** The protocol's own level names. `warning`/`error`/`fatal` happen to be the same three words. */
81
- const LEVELS = Object.freeze<Record<ErrorSeverity, string>>({
82
- warning: 'warning',
83
- error: 'error',
84
- fatal: 'fatal',
85
- });
81
+ // Null-prototype: a key that arrives untyped never answers an `Object.prototype` member.
82
+ const LEVELS = Object.freeze<Record<ErrorSeverity, string>>(
83
+ Object.assign(Object.create(null), {
84
+ warning: 'warning',
85
+ error: 'error',
86
+ fatal: 'fatal',
87
+ } satisfies Record<ErrorSeverity, string>),
88
+ );
86
89
 
87
90
  export interface SentryEnvelopeOptions {
88
91
  readonly dsn: string;
@@ -315,5 +315,10 @@ export function probeImage(bytes: Uint8Array): ImageInfo {
315
315
  const { width, height } = probeSize(bytes, format);
316
316
  // Before any allocation downstream: a hostile header is refused here, not at malloc.
317
317
  assertPixelBudget(width, height, format);
318
- return { format, width, height, mimeType: IMAGE_MIME_TYPES[format] };
318
+ // `format` is the sniff's own closed answer; the guard keeps the exported, mutable table's
319
+ // prototype from ever answering as a media type.
320
+ const mimeType = Object.hasOwn(IMAGE_MIME_TYPES, format)
321
+ ? IMAGE_MIME_TYPES[format]
322
+ : 'application/octet-stream';
323
+ return { format, width, height, mimeType };
319
324
  }
package/src/logger.ts CHANGED
@@ -23,15 +23,18 @@ export const LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'fatal', '
23
23
 
24
24
  export type LogLevel = (typeof LOG_LEVELS)[number];
25
25
 
26
- const LEVEL_WEIGHT = Object.freeze<Record<LogLevel, number>>({
27
- trace: 10,
28
- debug: 20,
29
- info: 30,
30
- warn: 40,
31
- error: 50,
32
- fatal: 60,
33
- silent: 100,
34
- });
26
+ // Null-prototype: a key that arrives untyped never answers an `Object.prototype` member.
27
+ const LEVEL_WEIGHT = Object.freeze<Record<LogLevel, number>>(
28
+ Object.assign(Object.create(null), {
29
+ trace: 10,
30
+ debug: 20,
31
+ info: 30,
32
+ warn: 40,
33
+ error: 50,
34
+ fatal: 60,
35
+ silent: 100,
36
+ } satisfies Record<LogLevel, number>),
37
+ );
35
38
 
36
39
  export interface Logger {
37
40
  readonly level: LogLevel;
@@ -28,14 +28,17 @@ import {
28
28
  } from './telemetry';
29
29
 
30
30
  /** OTLP's `SeverityNumber`: the first number of each band. */
31
- const SEVERITY = Object.freeze<Record<LogRecordEvent['level'], number>>({
32
- trace: 1,
33
- debug: 5,
34
- info: 9,
35
- warn: 13,
36
- error: 17,
37
- fatal: 21,
38
- });
31
+ // Null-prototype: a key that arrives untyped never answers an `Object.prototype` member.
32
+ const SEVERITY = Object.freeze<Record<LogRecordEvent['level'], number>>(
33
+ Object.assign(Object.create(null), {
34
+ trace: 1,
35
+ debug: 5,
36
+ info: 9,
37
+ warn: 13,
38
+ error: 17,
39
+ fatal: 21,
40
+ } satisfies Record<LogRecordEvent['level'], number>),
41
+ );
39
42
 
40
43
  /** One record as the exporter holds it: the event, and the span it was written under. */
41
44
  export interface ExportedLogRecord {
@@ -28,19 +28,25 @@ import type {
28
28
  } from './telemetry';
29
29
 
30
30
  /** OTLP's `SpanKind` enum; `UNSPECIFIED` is 0 and Ultimate never emits it. */
31
- const SPAN_KIND = Object.freeze<Record<SpanKind, number>>({
32
- internal: 1,
33
- server: 2,
34
- client: 3,
35
- producer: 4,
36
- consumer: 5,
37
- });
31
+ // Null-prototype: a key that arrives untyped never answers an `Object.prototype` member.
32
+ const SPAN_KIND = Object.freeze<Record<SpanKind, number>>(
33
+ Object.assign(Object.create(null), {
34
+ internal: 1,
35
+ server: 2,
36
+ client: 3,
37
+ producer: 4,
38
+ consumer: 5,
39
+ } satisfies Record<SpanKind, number>),
40
+ );
38
41
 
39
- const STATUS_CODE = Object.freeze<Record<SpanStatusCode, number>>({
40
- unset: 0,
41
- ok: 1,
42
- error: 2,
43
- });
42
+ // Null-prototype: a key that arrives untyped never answers an `Object.prototype` member.
43
+ const STATUS_CODE = Object.freeze<Record<SpanStatusCode, number>>(
44
+ Object.assign(Object.create(null), {
45
+ unset: 0,
46
+ ok: 1,
47
+ error: 2,
48
+ } satisfies Record<SpanStatusCode, number>),
49
+ );
44
50
 
45
51
  interface OtlpSpanJson {
46
52
  readonly traceId: string;
package/src/registrar.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  // the same tier, so each owner announces its registrar here at import time and callers ask
4
4
  // by kind. Same shape as `defineService` and `registerErrorCodes`.
5
5
 
6
+ import { renderFixShellArg } from './error-render';
6
7
  import { UltimateError } from './errors';
7
8
 
8
9
  /**
@@ -410,7 +411,7 @@ export function registerPrimitiveRegistrar(kind: PrimitiveKind, registrar: Modul
410
411
  // One command, because a `fix:` is pasted verbatim: collapsing every range on the package
411
412
  // to one resolved version is the repair. `bun pm why <package>` names the dependents when
412
413
  // a range genuinely disagrees and the update cannot converge on its own.
413
- fix: `bun update ${PRIMITIVE_PACKAGES[kind]}`,
414
+ fix: `bun update ${renderFixShellArg(PRIMITIVE_PACKAGES[kind], '<the @ultimat3 package the cause names>')}`,
414
415
  meta: { kind },
415
416
  });
416
417
  }
@@ -432,7 +433,7 @@ export function primitiveRegistrar(kind: PrimitiveKind): ModuleRegistrar {
432
433
  throw new UltimateError({
433
434
  code: 'X_REGISTRAR_MISSING',
434
435
  cause: `no ${kind} registrar is loaded, so ${kind} primitives cannot be registered`,
435
- fix: `bun add ${PRIMITIVE_PACKAGES[kind]}`,
436
+ fix: `bun add ${renderFixShellArg(PRIMITIVE_PACKAGES[kind], '<the @ultimat3 package the cause names>')}`,
436
437
  meta: { kind },
437
438
  });
438
439
  }
@@ -72,7 +72,7 @@ export class SecretsKeyMissingError extends UltimateError {
72
72
  input.source !== undefined
73
73
  ? 'export const runtime = { secretSource } # apps/<app>/runtime.ts — that source must answer a master key (check the KMS key or Vault path it reads); delete it to fall back to ULTIMATE_SECRETS_KEY, then .secrets.key'
74
74
  : ENV_VAR_NAME.test(input.envVar)
75
- ? `export ${input.envVar}="$(cat ${renderFixShellArg(input.keyPath, '<the key file the cause names>')})" # in a repo that has no key yet: x secrets init`
75
+ ? `export ${renderFixShellArg(input.envVar, 'ULTIMATE_SECRETS_KEY')}="$(cat ${renderFixShellArg(input.keyPath, '<the key file the cause names>')})" # in a repo that has no key yet: x secrets init`
76
76
  : "set the variable this error's cause names to the contents of the key file beside it, in whatever way this shell spells an assignment — in a repo that has no key yet: x secrets init",
77
77
  meta: {
78
78
  keyPath: input.keyPath,