@ultimat3/core 31.42.1 → 31.44.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/README.md +19 -5
- package/package.json +2 -2
- package/src/env.ts +10 -6
- package/src/ids.ts +10 -3
- package/src/index.ts +2 -0
- package/src/outbound-errors.ts +6 -6
- package/src/url-userinfo.ts +34 -0
package/README.md
CHANGED
|
@@ -396,18 +396,26 @@ request-scoped and never logged — `actorLabel()` stays id-only.
|
|
|
396
396
|
## Env fails once, completely
|
|
397
397
|
|
|
398
398
|
```ts
|
|
399
|
-
|
|
399
|
+
import { defineEnv, type EnvSchema } from '@ultimat3/core';
|
|
400
|
+
|
|
401
|
+
export const envSchema = {
|
|
400
402
|
DATABASE_URL: { type: 'url', secret: true },
|
|
401
403
|
PORT: { type: 'port', default: 3000 },
|
|
402
404
|
REGION: { type: 'enum', values: ['us', 'eu'] },
|
|
403
405
|
SENTRY_DSN: { type: 'url', required: false },
|
|
404
406
|
NATS_URL: { type: 'url', role: 'sync' }, // only required for ROLE=sync
|
|
405
|
-
}
|
|
407
|
+
} satisfies EnvSchema;
|
|
408
|
+
export const env = defineEnv(envSchema);
|
|
406
409
|
```
|
|
407
410
|
|
|
411
|
+
The `envSchema` export is the one declaration form: `x env`, `x secrets` and `x deploy` read it,
|
|
412
|
+
and an app's `undeclared-env` guard refuses a `defineEnv` handed anything else.
|
|
413
|
+
|
|
408
414
|
Every missing or malformed key is listed in one `X_ENV_MISSING`. `secret: true` keys are
|
|
409
|
-
redacted in logs
|
|
410
|
-
|
|
415
|
+
redacted in logs. `maskedEnvValues(schema, values)` — what `x env check --json` prints — masks every
|
|
416
|
+
`secret: true` key **and** every key `isRedactedKey` names (`DATABASE_URL`, `STRIPE_KEY`), and cuts
|
|
417
|
+
the password from any other value's URL userinfo; the env summary (`describeEnv()`, internal) emits
|
|
418
|
+
declarations only, safe for `x.manifest.json`. Omit `required` for required — `required: false` is the only
|
|
411
419
|
loosening. Never declare an env var for *which deploy this is* — that is `ULTIMATE_ENV`, below.
|
|
412
420
|
|
|
413
421
|
`.env.example` is a **projection** of that schema, never a second list:
|
|
@@ -478,6 +486,12 @@ such as `cardPin` or `pinCode`) and a stored hash of any of them (`passwordHash`
|
|
|
478
486
|
leaves `idempotencyToken`, a paging token, `maxTokens`, an error `code`, `spinner`, `isPinned`,
|
|
479
487
|
`sessionStart` and `cookieName` readable — a redacted field is one an operator cannot correlate on.
|
|
480
488
|
|
|
489
|
+
A URL's userinfo has one cut too: `replaceUrlUserinfo(text, render)` ends it at the **last** `@`
|
|
490
|
+
before the authority's `/`, `?` or `#` — where a URL parser ends it — so `u:hunter@2secret@host`
|
|
491
|
+
loses the whole password, never just `hunter`. `redactUrlPassword(text)` keeps the user and prints
|
|
492
|
+
`user:[redacted]@host`; `x config`, `x repro`, `maskedEnvValues` and an `X_OUTBOUND_*` cause all
|
|
493
|
+
cut through it.
|
|
494
|
+
|
|
481
495
|
`LOG_LEVEL` is refused when it is not one of `LOG_LEVELS` (lowercase), exactly as
|
|
482
496
|
`structuredLogger({ level })` refuses it; unset or empty is `info`.
|
|
483
497
|
|
|
@@ -588,7 +602,7 @@ match with `sealAll()`; uniqueness cannot be held across keys.
|
|
|
588
602
|
barrel's and `./page`'s `systemClock` is a plain `Clock` — browser code reads it and nothing there
|
|
589
603
|
waits; the sleeping one is `./adapter`'s `systemClock` (`sleep-clock.ts`, server-only).
|
|
590
604
|
- `uuidV7()` is UUIDv7: time-prefixed, monotonic within a millisecond, never backwards on clock
|
|
591
|
-
skew. `typedId<'post'>()` brands it so a post id cannot be passed where a user id is wanted.
|
|
605
|
+
skew. A clock before 1970 (a `frozenClock` may read one) mints at timestamp 0, still monotonic. `typedId<'post'>()` brands it so a post id cannot be passed where a user id is wanted.
|
|
592
606
|
- `withSpan('action.publishPost', fn)` builds no record until something subscribes to `span.end`.
|
|
593
607
|
Traces cross process boundaries via `traceparent()` / `parseTraceparent()`, whose ids come from
|
|
594
608
|
`traceId()` / `spanId()` — **never `uuidV7()`**, whose dashed 36 characters every collector
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/core",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.44.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.
|
|
57
|
+
"@ultimat3/schema": "31.44.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/env.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
import { numeric } from '@ultimat3/schema';
|
|
6
6
|
import { describeValue, renderFixShellArg } from './error-render';
|
|
7
7
|
import { EnvMissingError } from './errors';
|
|
8
|
-
import { REDACTED, redactKeys } from './logger';
|
|
8
|
+
import { isRedactedKey, REDACTED, redactKeys } from './logger';
|
|
9
9
|
import { type Role, resolveRole } from './roles';
|
|
10
|
+
import { redactUrlPassword } from './url-userinfo';
|
|
10
11
|
|
|
11
12
|
export type EnvVarType = 'string' | 'url' | 'number' | 'integer' | 'port' | 'boolean' | 'enum';
|
|
12
13
|
|
|
@@ -252,10 +253,11 @@ export function defineEnv<const S extends EnvSchema>(schema: S, options?: EnvOpt
|
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
/**
|
|
255
|
-
* The resolved values with every `secret: true` key
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
256
|
+
* The resolved values with every `secret: true` key AND every credential-named key (`isRedactedKey`,
|
|
257
|
+
* the logger's and `x config`'s rule) replaced, and any other string's URL password cut from its
|
|
258
|
+
* userinfo. `checkEnv().values` carries the REAL values because `defineEnv()` has to return them —
|
|
259
|
+
* so anything that PRINTS a report (`x env check --json`, a doctor line, a log field) renders this
|
|
260
|
+
* instead, and the masking lives in one place rather than at each printer.
|
|
259
261
|
*/
|
|
260
262
|
export function maskedEnvValues(
|
|
261
263
|
schema: EnvSchema,
|
|
@@ -263,7 +265,9 @@ export function maskedEnvValues(
|
|
|
263
265
|
): Readonly<Record<string, unknown>> {
|
|
264
266
|
const out: Record<string, unknown> = {};
|
|
265
267
|
for (const [key, value] of Object.entries(values)) {
|
|
266
|
-
|
|
268
|
+
if (value === undefined) out[key] = value;
|
|
269
|
+
else if (schema[key]?.secret === true || isRedactedKey(key)) out[key] = REDACTED;
|
|
270
|
+
else out[key] = typeof value === 'string' ? redactUrlPassword(value) : value;
|
|
267
271
|
}
|
|
268
272
|
return Object.freeze(out);
|
|
269
273
|
}
|
package/src/ids.ts
CHANGED
|
@@ -105,17 +105,24 @@ function hexOf(byteLength: number): string {
|
|
|
105
105
|
* UUIDv7 per RFC 9562: 48-bit unix ms, version 7, 12-bit monotonic counter, 62 random bits.
|
|
106
106
|
* Strictly increasing lexicographically even within the same millisecond, and never goes
|
|
107
107
|
* backwards when the wall clock does.
|
|
108
|
+
*
|
|
109
|
+
* A pre-1970 clock mints at timestamp 0 (the field's floor), still monotonic: `frozenClock`
|
|
110
|
+
* accepts such an instant on purpose — a test pinned to 1969 — and an id that cannot encode it
|
|
111
|
+
* sorts first rather than refusing every context built on that clock. An Invalid Date and an
|
|
112
|
+
* instant past 2^48-1 ms are still refused (`X_INVARIANT`).
|
|
108
113
|
*/
|
|
109
114
|
export function uuidV7(clock: Clock = systemClock): string {
|
|
110
|
-
|
|
115
|
+
const read = clock.now().getTime();
|
|
116
|
+
// `Math.max` keeps `NaN` as `NaN`, so an Invalid Date still reaches the refusal below.
|
|
117
|
+
let epochMs = Math.max(read, 0);
|
|
111
118
|
// Before the clamp and before `lastEpochMs` is written: an Invalid Date minted `…-0NaN-7…` and
|
|
112
119
|
// stored `NaN` as the high-water mark, so the next id skipped the clamp and could sort first.
|
|
113
120
|
// `assert` only on the failing branch: its messages would otherwise be built on every id.
|
|
114
121
|
if (!(epochMs >= 0 && epochMs <= MAX_EPOCH_MS)) {
|
|
115
122
|
assert(
|
|
116
123
|
false,
|
|
117
|
-
`uuidV7's clock read ${String(
|
|
118
|
-
"uuidV7(frozenClock('2026-01-01T00:00:00Z')) // a clock at a valid instant
|
|
124
|
+
`uuidV7's clock read ${String(read)} ms: a UUIDv7 holds up to 2^48-1 unix ms, so an Invalid Date or an instant past the year 10889 has no encoding`,
|
|
125
|
+
"uuidV7(frozenClock('2026-01-01T00:00:00Z')) // a clock at a valid instant",
|
|
119
126
|
);
|
|
120
127
|
}
|
|
121
128
|
if (epochMs < lastEpochMs) epochMs = lastEpochMs;
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export type {
|
|
|
29
29
|
ActorOrigin,
|
|
30
30
|
} from './actor';
|
|
31
31
|
export {
|
|
32
|
+
ACTOR_KINDS,
|
|
32
33
|
actorFact,
|
|
33
34
|
actorLabel,
|
|
34
35
|
actorOf,
|
|
@@ -1001,6 +1002,7 @@ export type { ToolDescriptionSource } from './tool-description';
|
|
|
1001
1002
|
// A projected tool's description: `@ultimat3/mcp`'s and `@ultimat3/ai`'s, one tier apart from neither.
|
|
1002
1003
|
export { toolDescription } from './tool-description';
|
|
1003
1004
|
export { trimTrailingSlashes } from './trailing-slashes';
|
|
1005
|
+
export { redactUrlPassword, replaceUrlUserinfo } from './url-userinfo';
|
|
1004
1006
|
export {
|
|
1005
1007
|
frameworkVersion,
|
|
1006
1008
|
readPackageVersion,
|
package/src/outbound-errors.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { renderFixShellArg, renderThrowable } from './error-render';
|
|
6
6
|
import { registerErrorRetry } from './error-retry';
|
|
7
7
|
import { UltimateError } from './errors';
|
|
8
|
+
import { replaceUrlUserinfo } from './url-userinfo';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The eleven codes' retry classes, registered HERE and not in `error-retry.ts`'s core table: that
|
|
@@ -67,14 +68,13 @@ export function outboundTimeout(
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
|
-
* A transport failure in its own words with every
|
|
71
|
-
*
|
|
72
|
-
*
|
|
71
|
+
* A transport failure in its own words with every URL's userinfo cut (`//…@`) and every query
|
|
72
|
+
* string cut (`?…`): a runtime's message may quote the URL it was dialling, a proxy URL keeps its
|
|
73
|
+
* credential before the LAST `@` (`replaceUrlUserinfo`), and a signed URL keeps it in the query.
|
|
74
|
+
* Userinfo first: a `?` the query cut stops at would otherwise end an authority early.
|
|
73
75
|
*/
|
|
74
76
|
export const transportText = (error: unknown): string =>
|
|
75
|
-
renderThrowable(error)
|
|
76
|
-
.replaceAll(/\?[^\s"'`)]*/g, '?…')
|
|
77
|
-
.replaceAll(/\/\/[^\s"'`/?#@]*@/g, '//…@');
|
|
77
|
+
replaceUrlUserinfo(renderThrowable(error), () => '…').replaceAll(/\?[^\s"'`)]*/g, '?…');
|
|
78
78
|
|
|
79
79
|
/** The refusals that say the CALLER's bound ran out, not the vendor: a breaker hears nothing. */
|
|
80
80
|
const CALLER_BOUND = new WeakSet<UltimateError>();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Single responsibility: find every URL's userinfo in a string and hand it to a renderer — the one
|
|
2
|
+
// rule the redactors share. A URL parser ends the userinfo at the LAST `@` before the authority's
|
|
3
|
+
// end, so a password holding a raw `@` (`u:hunter@2secret@host`) is cut whole, never at its first.
|
|
4
|
+
|
|
5
|
+
import { REDACTED } from './secret';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An authority: after `//`, up to the first `/`, `?` or `#` (WHATWG's end), or anything prose ends
|
|
9
|
+
* a URL with — whitespace, a quote, a bracket. Greedy, so the last `@` inside it is the parser's.
|
|
10
|
+
*/
|
|
11
|
+
const AUTHORITY = /\/\/([^\s"'`<>()/?#]*)/g;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Every `//userinfo@host` in `text` rewritten as `//render(userinfo)@host`; a URL with no `@` in
|
|
15
|
+
* its authority, and an `@` past the path, query or fragment, are left as written. The renderer
|
|
16
|
+
* decides how much survives: the user alone, a marker, nothing.
|
|
17
|
+
*/
|
|
18
|
+
export function replaceUrlUserinfo(text: string, render: (userinfo: string) => string): string {
|
|
19
|
+
return text.replace(AUTHORITY, (whole: string, authority: string) => {
|
|
20
|
+
const at = authority.lastIndexOf('@');
|
|
21
|
+
return at < 0 ? whole : `//${render(authority.slice(0, at))}${authority.slice(at)}`;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `scheme://user:password@host` → `scheme://user:[redacted]@host`, for every URL in `text`. The
|
|
27
|
+
* user stays — it is no secret — and the password runs to the userinfo's LAST `@`, raw `@` and `:`
|
|
28
|
+
* included. What `x config` and `maskedEnvValues` print.
|
|
29
|
+
*/
|
|
30
|
+
export const redactUrlPassword = (text: string): string =>
|
|
31
|
+
replaceUrlUserinfo(text, (userinfo) => {
|
|
32
|
+
const colon = userinfo.indexOf(':');
|
|
33
|
+
return colon < 0 ? userinfo : `${userinfo.slice(0, colon)}:${REDACTED}`;
|
|
34
|
+
});
|