@ultimat3/core 31.25.0 → 31.27.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 +1 -1
- package/package.json +2 -2
- package/src/exports/observability.ts +1 -0
- package/src/framework-env.ts +1 -1
- package/src/in-process-fetch.ts +38 -7
- package/src/index.ts +1 -0
- package/src/logger.ts +5 -0
- package/src/map-bounded.ts +10 -0
- package/src/registrar.ts +1 -0
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ JSON.stringify({ dsn }); // the value never prints: a Secret redacts by value, a
|
|
|
75
75
|
| an app's role-scoped boot line — `bootWarning({ code, roles, once?, message, fields })`, said only where a booting role can act on it, `once: 'process'` or `'build'` (the boot installs the per-build store with `installBootWarnings`, on `@ultimat3/core/adapter`) | `boot-warning.ts` |
|
|
76
76
|
| `Clock` — the only source of "now" | `clock.ts` |
|
|
77
77
|
| UUIDv7, nanoid, branded ids | `ids.ts` |
|
|
78
|
-
| structured JSON logging + redaction; `installLogSink(sink)` — the test seam that sends every default-writer line to a sink instead of the process's streams until the release it returns runs (a stack: releases in any order; `undefined` is the streams) (a test preload drops them; a test asserting on the process logger collects them). The tee is the bus: every such line, redacted, is the `log.record` event — `subscribe('log.record', handler)` | `logger.ts` |
|
|
78
|
+
| structured JSON logging + redaction; `installLogSink(sink)` — the test seam that sends every default-writer line to a sink instead of the process's streams until the release it returns runs (a stack: releases in any order; `undefined` is the streams) (a test preload drops them; a test asserting on the process logger collects them). The tee is the bus: every such line, redacted, is the `log.record` event — `subscribe('log.record', handler)`; `setLogStream('stderr')` moves default-writer lines below `error` off stdout, `currentLogStream()` reads it back so a caller that sets it for a span restores it | `logger.ts` |
|
|
79
79
|
| a condition that KEEPS failing, said rarely: `outageLog({ event, level })` → `failed()` writes on failures 1, 2, 4, 8, …, `recovered()` one `<event> recovered` line with `after`; `failureStreak({ event, recoveredEvent, level?, fields? })` → `failed(error, fields?)` writes once per CAUSE (code, or uncoded message; a new one carries `previous`), `passed()` one `recoveredEvent` line with `failures`, `reset()` for a restarted loop; `failureFields(error)` — the `error`/`code`/`cause`/`fix` a failure line carries | `outage-log.ts` |
|
|
80
80
|
| `teeLogLines(tee)` → its release: a COPY of every process-logger line (redacted, as written) handed to `tee(line, level)` beside the streams, never instead of them. A set: each release removes only its own tee; a tee that throws loses only its copy. `x dev`'s `dev.log` is the caller | `logger.ts` |
|
|
81
81
|
| `redactValues([{ pattern, replace }])` — redaction by VALUE: every match of each `g` pattern becomes `replace` in a log line's message and field strings and in the Sentry envelope's exception value, `fix`, `stack`, extras and `meta`, a span's exception event and status, and failure bundles. Bumps the same generation as `redactKeys`, so a logger bound before it re-redacts. A sticky pattern, an empty match or a repeated group holding a repeating quantifier (`(a+)+`, `(a+){2,40}`) is refused at registration — `RedactPatternUnsafeError` (`X_REDACT_PATTERN_UNSAFE`) — and the list with it. Ships no pattern; `RedactValueMatcher` is the type | `logger-redact.ts`, `redact-values.ts` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/core",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.27.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.27.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -105,6 +105,7 @@ export { SEMCONV, SEMCONV_METRICS, SEMCONV_VALUES } from '../instrument-semconv'
|
|
|
105
105
|
export { callerStack, captureStatementStacks, resetStatementStacks } from '../instrument-stacks';
|
|
106
106
|
export type { LogFields, Logger, LoggerOptions, LogLevel, RedactValueMatcher } from '../logger';
|
|
107
107
|
export {
|
|
108
|
+
currentLogStream,
|
|
108
109
|
isRedactedKey,
|
|
109
110
|
LOG_LEVELS,
|
|
110
111
|
logger,
|
package/src/framework-env.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const FRAMEWORK_ENV: readonly FrameworkEnvName[] = [
|
|
|
53
53
|
...contract('cli', 'APP_URL', 'SITE_ORIGIN', 'SYNC_URL', 'HOST', 'PORT', 'METRICS_PORT'),
|
|
54
54
|
...contract('cli', 'NODE_ENV', 'TRUSTED_PROXY_HOPS', 'WORKER_QUEUES', 'SENTRY_DSN'),
|
|
55
55
|
...contract('cli', 'S3_ENDPOINT', 'S3_BUCKET', 'S3_REGION', 'S3_FORCE_PATH_STYLE'),
|
|
56
|
-
...contract('cli', 'SCRAPE_CDP_URL'),
|
|
56
|
+
...contract('cli', 'SCRAPE_CDP_URL', 'TLS_CERT', 'TLS_KEY'),
|
|
57
57
|
...toggles('cli', 'OTEL_SDK_DISABLED'),
|
|
58
58
|
...internal('cli', 'ULTIMATE_SEED_TIER', 'ULTIMATE_STATE_DIR', 'ULTIMATE_BUILD_CAPTURE'),
|
|
59
59
|
...internal('cli', 'ULTIMATE_DEV_CHILD', 'ULTIMATE_DEV_SUPERVISOR_PID', 'X_ENV'),
|
package/src/in-process-fetch.ts
CHANGED
|
@@ -10,19 +10,45 @@
|
|
|
10
10
|
import { asyncContext } from './async-context';
|
|
11
11
|
import type { FetchLike } from './client-dispatch';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** The scope: who answers, and which urls are its to answer (every one, when unsaid). */
|
|
14
|
+
interface InProcess {
|
|
15
|
+
readonly fetchImpl: FetchLike;
|
|
16
|
+
readonly owns?: ((url: string) => boolean) | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const scope = asyncContext<InProcess>('the in-process dispatch');
|
|
14
20
|
|
|
15
21
|
const INSTALLED: unique symbol = Symbol.for('ultimate.in-process-fetch');
|
|
16
22
|
|
|
23
|
+
/**
|
|
24
|
+
* A `Request` object as the dispatcher's `(url, init)`: its method, headers and body carried, with
|
|
25
|
+
* `init` laid over it as `fetch` itself would — a bare `init ?? {}` sent a POST as a bodyless GET.
|
|
26
|
+
*/
|
|
27
|
+
async function asInit(input: Request, init: RequestInit | undefined): Promise<RequestInit> {
|
|
28
|
+
const request = init === undefined ? input : new Request(input, init);
|
|
29
|
+
const bodyless = request.method === 'GET' || request.method === 'HEAD';
|
|
30
|
+
return {
|
|
31
|
+
method: request.method,
|
|
32
|
+
headers: request.headers,
|
|
33
|
+
redirect: request.redirect,
|
|
34
|
+
signal: request.signal,
|
|
35
|
+
...(bodyless ? {} : { body: await request.arrayBuffer() }),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
/** Wrap `globalThis.fetch` once per process; a re-wrap after someone replaced it wraps theirs. */
|
|
18
40
|
function install(): void {
|
|
19
41
|
const current = globalThis.fetch as typeof fetch & { [INSTALLED]?: true };
|
|
20
42
|
if (current[INSTALLED] === true) return;
|
|
21
|
-
const wrapped = (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
43
|
+
const wrapped = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
22
44
|
const inProcess = scope.get();
|
|
23
45
|
if (inProcess === undefined) return current(input, init);
|
|
24
46
|
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
25
|
-
|
|
47
|
+
// A url the scope does not own — another host — goes where it would have gone without one.
|
|
48
|
+
if (inProcess.owns !== undefined && !inProcess.owns(url)) return current(input, init);
|
|
49
|
+
if (typeof input === 'string' || input instanceof URL)
|
|
50
|
+
return inProcess.fetchImpl(url, init ?? {});
|
|
51
|
+
return inProcess.fetchImpl(url, await asInit(input, init));
|
|
26
52
|
};
|
|
27
53
|
globalThis.fetch = Object.assign(wrapped, current, { [INSTALLED]: true as const });
|
|
28
54
|
}
|
|
@@ -30,10 +56,15 @@ function install(): void {
|
|
|
30
56
|
/**
|
|
31
57
|
* Run `fn` with every `fetch` inside it — so every `clientTransport` call, `queryClient()` and
|
|
32
58
|
* `rpc()` included — answered by `fetchImpl`: the app's own HTTP pipeline handed a `Request`,
|
|
33
|
-
* rather than the network.
|
|
34
|
-
*
|
|
59
|
+
* rather than the network. `owns` narrows that to the urls it answers true for (the app's own
|
|
60
|
+
* origin); the rest reach the fetch this wrapped. A caller's explicit `fetchImpl` never reaches
|
|
61
|
+
* `globalThis.fetch` at all, so a test's double is never overridden by an ambient scope.
|
|
35
62
|
*/
|
|
36
|
-
export function withInProcessFetch<T>(
|
|
63
|
+
export function withInProcessFetch<T>(
|
|
64
|
+
fetchImpl: FetchLike,
|
|
65
|
+
fn: () => T,
|
|
66
|
+
owns?: (url: string) => boolean,
|
|
67
|
+
): T {
|
|
37
68
|
install();
|
|
38
|
-
return scope.run(fetchImpl, fn);
|
|
69
|
+
return scope.run({ fetchImpl, owns }, fn);
|
|
39
70
|
}
|
package/src/index.ts
CHANGED
package/src/logger.ts
CHANGED
|
@@ -83,6 +83,11 @@ export function setLogStream(stream: 'stdout' | 'stderr'): void {
|
|
|
83
83
|
logStream = stream;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** The stream `setLogStream` last chose: what a caller that sets it for a span puts back after. */
|
|
87
|
+
export function currentLogStream(): 'stdout' | 'stderr' {
|
|
88
|
+
return logStream;
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
/** What `installLogSink` installs: one complete JSON line, and the level it was written at. */
|
|
87
92
|
export type LogSink = (line: string, level: LogLevel) => void;
|
|
88
93
|
|
package/src/map-bounded.ts
CHANGED
|
@@ -43,6 +43,16 @@ export async function mapBounded<T, R>(
|
|
|
43
43
|
fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,
|
|
44
44
|
options: MapBoundedOptions & { readonly settle?: 'first' | undefined },
|
|
45
45
|
): Promise<R[]>;
|
|
46
|
+
/**
|
|
47
|
+
* A value typed `MapBoundedOptions` itself — the 31.23 call shape, before `settle` split the
|
|
48
|
+
* overloads. Its `settle` is not known statically, so neither answer is: narrow with
|
|
49
|
+
* `settle: 'first'` or `'all'` at the call for an exact result type.
|
|
50
|
+
*/
|
|
51
|
+
export async function mapBounded<T, R>(
|
|
52
|
+
items: readonly T[],
|
|
53
|
+
fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,
|
|
54
|
+
options: MapBoundedOptions,
|
|
55
|
+
): Promise<R[] | PromiseSettledResult<R>[]>;
|
|
46
56
|
export async function mapBounded<T, R>(
|
|
47
57
|
items: readonly T[],
|
|
48
58
|
fn: (item: T, index: number, signal: AbortSignal) => R | Promise<R>,
|
package/src/registrar.ts
CHANGED
|
@@ -98,6 +98,7 @@ export const PRIMITIVE_FACTORIES = Object.freeze<readonly PrimitiveFactory[]>(
|
|
|
98
98
|
{ factory: 'subjectExport', pkg: '@ultimat3/jobs', kind: 'job' },
|
|
99
99
|
{ factory: 'webhook', pkg: '@ultimat3/jobs', kind: 'job' },
|
|
100
100
|
{ factory: 'webhookReceiver', pkg: '@ultimat3/jobs', kind: 'job' },
|
|
101
|
+
{ factory: 'inboundMail', pkg: '@ultimat3/mail', kind: 'job' },
|
|
101
102
|
{ factory: 'mcpConfirmations', pkg: '@ultimat3/mcp', kind: 'action' },
|
|
102
103
|
{ factory: 'notifier', pkg: '@ultimat3/notify', kind: 'job' },
|
|
103
104
|
{ factory: 'pushRegister', pkg: '@ultimat3/notify', kind: 'action' },
|