@substrat-run/contracts 0.158.0 → 0.159.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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Credential-free authentication diagnostics shared by providers, hosts and log readers.
3
+ * No runtime imports: the platform entry bundles this independently of the vertical.
4
+ * A diagnostic describes a check, never grants authority. Unknown fields are discarded
5
+ * on both write and read; tokens, claims, identities and exception messages have no slot.
6
+ */
7
+ export declare const AUTH_CHECK_STAGES: readonly ['bearer', 'session', 'mcp-audience', 'mcp-caller'];
8
+ export declare const AUTH_CHECK_OUTCOMES: readonly ['accepted', 'refused', 'absent', 'error'];
9
+ export declare const AUTH_CHECK_REASONS: readonly ['verified', 'session-invalid', 'credential-missing', 'discovery-failed', 'key-resolution-failed', 'token-expired', 'token-not-active', 'issuer-invalid', 'audience-invalid', 'claims-invalid', 'signature-invalid', 'token-invalid', 'verification-failed', 'subject-missing', 'assertion-not-access-token', 'delegation-refused', 'token-not-for-app', 'resource-mismatch', 'caller-resolved', 'caller-refused', 'caller-error'];
10
+ export interface AuthCheck {
11
+ stage: (typeof AUTH_CHECK_STAGES)[number];
12
+ outcome: (typeof AUTH_CHECK_OUTCOMES)[number];
13
+ reason: (typeof AUTH_CHECK_REASONS)[number];
14
+ }
15
+ export declare const AUTH_CHECK_CAP = 16;
16
+ export interface AuthRecording {
17
+ authChecks?: AuthCheck[];
18
+ authChecksDropped?: number;
19
+ }
20
+ /** Registered across bundled copies; the host supplies a request-local recorder. */
21
+ export declare const AUTH_DIAGNOSTICS_KEY: unique symbol;
22
+ export interface AuthDiagnosticsSink {
23
+ record(check: AuthCheck): void;
24
+ }
25
+ /** Copy only the bounded vocabulary, including when called from untyped code. */
26
+ export declare function authCheckOf(value: unknown): AuthCheck | undefined;
27
+ /** Old lines and unrecognised future entries read as unrecorded, never as success. */
28
+ export declare function authChecksOf(value: unknown): AuthCheck[];
29
+ export declare function tallyAuthCheck(record: AuthRecording, value: AuthCheck): void;
30
+ /** Best effort. No host, an old host, or a broken sink must not change authentication. */
31
+ export declare function recordAuthCheck(check: AuthCheck): void;
32
+ //# sourceMappingURL=auth-diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-diagnostics.d.ts","sourceRoot":"","sources":["../src/auth-diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,YAAI,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,CAAU,CAAC;AAC9F,eAAO,MAAM,mBAAmB,YAAI,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AACvF,eAAO,MAAM,kBAAkB,YAC7B,UAAU,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAChG,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,kBAAkB,EACzE,gBAAgB,EAAE,mBAAmB,EAAE,eAAe,EAAE,qBAAqB,EAC7E,iBAAiB,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,mBAAmB,EAC1F,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,CAChE,CAAC;AAEX,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,EAAE,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,oFAAoF;AACpF,eAAO,MAAM,oBAAoB,eAA0C,CAAC;AAC5E,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CAChC;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAOjE;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,CAMxD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAM5E;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAStD"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Credential-free authentication diagnostics shared by providers, hosts and log readers.
3
+ * No runtime imports: the platform entry bundles this independently of the vertical.
4
+ * A diagnostic describes a check, never grants authority. Unknown fields are discarded
5
+ * on both write and read; tokens, claims, identities and exception messages have no slot.
6
+ */
7
+ export const AUTH_CHECK_STAGES = ['bearer', 'session', 'mcp-audience', 'mcp-caller'];
8
+ export const AUTH_CHECK_OUTCOMES = ['accepted', 'refused', 'absent', 'error'];
9
+ export const AUTH_CHECK_REASONS = [
10
+ 'verified', 'session-invalid', 'credential-missing', 'discovery-failed', 'key-resolution-failed',
11
+ 'token-expired', 'token-not-active', 'issuer-invalid', 'audience-invalid',
12
+ 'claims-invalid', 'signature-invalid', 'token-invalid', 'verification-failed',
13
+ 'subject-missing', 'assertion-not-access-token', 'delegation-refused', 'token-not-for-app',
14
+ 'resource-mismatch', 'caller-resolved', 'caller-refused', 'caller-error',
15
+ ];
16
+ export const AUTH_CHECK_CAP = 16;
17
+ /** Registered across bundled copies; the host supplies a request-local recorder. */
18
+ export const AUTH_DIAGNOSTICS_KEY = Symbol.for('substrat.auth-diagnostics');
19
+ /** Copy only the bounded vocabulary, including when called from untyped code. */
20
+ export function authCheckOf(value) {
21
+ if (!value || typeof value !== 'object')
22
+ return undefined;
23
+ const v = value;
24
+ if (!AUTH_CHECK_STAGES.includes(v.stage)
25
+ || !AUTH_CHECK_OUTCOMES.includes(v.outcome)
26
+ || !AUTH_CHECK_REASONS.includes(v.reason))
27
+ return undefined;
28
+ return { stage: v.stage, outcome: v.outcome, reason: v.reason };
29
+ }
30
+ /** Old lines and unrecognised future entries read as unrecorded, never as success. */
31
+ export function authChecksOf(value) {
32
+ if (!Array.isArray(value))
33
+ return [];
34
+ return value.slice(0, AUTH_CHECK_CAP).flatMap((v) => {
35
+ const check = authCheckOf(v);
36
+ return check ? [check] : [];
37
+ });
38
+ }
39
+ export function tallyAuthCheck(record, value) {
40
+ const check = authCheckOf(value);
41
+ if (!check)
42
+ return;
43
+ const checks = record.authChecks ??= [];
44
+ if (checks.length < AUTH_CHECK_CAP)
45
+ checks.push(check);
46
+ else
47
+ record.authChecksDropped = (record.authChecksDropped ?? 0) + 1;
48
+ }
49
+ /** Best effort. No host, an old host, or a broken sink must not change authentication. */
50
+ export function recordAuthCheck(check) {
51
+ try {
52
+ const safe = authCheckOf(check);
53
+ if (!safe)
54
+ return;
55
+ const sink = globalThis[AUTH_DIAGNOSTICS_KEY];
56
+ sink?.record(safe);
57
+ }
58
+ catch {
59
+ // Observability never decides whether a caller is admitted.
60
+ }
61
+ }
62
+ //# sourceMappingURL=auth-diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-diagnostics.js","sourceRoot":"","sources":["../src/auth-diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,CAAU,CAAC;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AACvF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB;IAChG,eAAe,EAA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AC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAqB,EAAE,KAAgB;IACpE,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,KAAK,EAAE,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,GAAG,cAAc;QAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;QAClD,MAAM,CAAC,iBAAiB,GAAG,CAAC,MAAM,CAAC,iBAAiB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AACtE,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,eAAe,CAAC,KAAgB;IAC9C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,MAAM,IAAI,GAAI,UAAsC,CAAC,oBAAoB,CAAoC,CAAC;QAC9G,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,4DAA4D;IAC9D,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@substrat-run/contracts",
3
- "version": "0.158.0",
3
+ "version": "0.159.0",
4
4
  "description": "Substrat kernel contract schemas — Zod is the source of truth (master plan D-22); OAS/JSON Schema are emitted artifacts",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,6 +37,10 @@
37
37
  "types": "./dist/assistant-stream.d.ts",
38
38
  "default": "./dist/assistant-stream.js"
39
39
  },
40
+ "./auth-diagnostics": {
41
+ "types": "./dist/auth-diagnostics.d.ts",
42
+ "default": "./dist/auth-diagnostics.js"
43
+ },
40
44
  "./trace-sink": {
41
45
  "types": "./dist/trace-sink.d.ts",
42
46
  "default": "./dist/trace-sink.js"