@ontrails/permits 1.0.0-beta.12 → 1.0.0-beta.14
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/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +44 -5
- package/README.md +175 -0
- package/dist/auth-gate.d.ts +18 -0
- package/dist/auth-gate.d.ts.map +1 -0
- package/dist/auth-gate.js +56 -0
- package/dist/auth-gate.js.map +1 -0
- package/dist/auth-provision.d.ts +11 -0
- package/dist/auth-provision.d.ts.map +1 -0
- package/dist/auth-provision.js +22 -0
- package/dist/auth-provision.js.map +1 -0
- package/dist/connectors/connector.d.ts +26 -0
- package/dist/connectors/connector.d.ts.map +1 -0
- package/dist/connectors/connector.js +2 -0
- package/dist/connectors/connector.js.map +1 -0
- package/dist/connectors/jwt.d.ts +25 -0
- package/dist/connectors/jwt.d.ts.map +1 -0
- package/dist/connectors/jwt.js +148 -0
- package/dist/connectors/jwt.js.map +1 -0
- package/dist/extraction.d.ts +6 -6
- package/dist/extraction.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/permit.d.ts +2 -2
- package/dist/permit.js +2 -2
- package/dist/trails/auth-verify.d.ts +3 -3
- package/dist/trails/auth-verify.d.ts.map +1 -1
- package/dist/trails/auth-verify.js +31 -31
- package/dist/trails/auth-verify.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/{auth-layer.test.ts → auth-gate.test.ts} +16 -16
- package/src/__tests__/{auth-service.test.ts → auth-provision.test.ts} +18 -18
- package/src/__tests__/auth-verify.test.ts +36 -35
- package/src/__tests__/{adapter.test.ts → connector.test.ts} +43 -43
- package/src/__tests__/permit.test.ts +11 -11
- package/src/__tests__/rules.test.ts +17 -17
- package/src/{auth-layer.ts → auth-gate.ts} +10 -10
- package/src/auth-provision.ts +26 -0
- package/src/{adapter.ts → connectors/connector.ts} +7 -7
- package/src/{adapters → connectors}/jwt.ts +10 -8
- package/src/extraction.ts +6 -6
- package/src/index.ts +8 -5
- package/src/permit.ts +2 -2
- package/src/trails/auth-verify.ts +35 -31
- package/tsconfig.tsbuildinfo +1 -1
- package/src/auth-service.ts +0 -25
package/src/extraction.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Normalized input for auth
|
|
2
|
+
* Normalized input for auth connectors.
|
|
3
3
|
*
|
|
4
|
-
* Each
|
|
5
|
-
* them into this shape. No
|
|
4
|
+
* Each trailhead extracts raw credentials from its transport and normalizes
|
|
5
|
+
* them into this shape. No trailhead types (Request, McpSession, etc.) cross
|
|
6
6
|
* into core — only this interface.
|
|
7
7
|
*/
|
|
8
8
|
export interface PermitExtractionInput {
|
|
9
|
-
/** Which
|
|
10
|
-
readonly
|
|
9
|
+
/** Which trailhead produced this extraction */
|
|
10
|
+
readonly trailhead: 'http' | 'mcp' | 'cli';
|
|
11
11
|
/** Bearer token from Authorization header or equivalent */
|
|
12
12
|
readonly bearerToken?: string;
|
|
13
13
|
/** Session identifier from transport handshake */
|
|
14
14
|
readonly sessionId?: string;
|
|
15
|
-
/** Raw headers (HTTP
|
|
15
|
+
/** Raw headers (HTTP trailhead only, typically) */
|
|
16
16
|
readonly headers?: Headers;
|
|
17
17
|
/** Correlation ID for tracing */
|
|
18
18
|
readonly requestId: string;
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export {
|
|
2
|
-
type
|
|
2
|
+
type AuthConnector,
|
|
3
3
|
type AuthCredentials,
|
|
4
4
|
type AuthError,
|
|
5
|
-
} from './
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
} from './connectors/connector.js';
|
|
6
|
+
export {
|
|
7
|
+
createJwtConnector,
|
|
8
|
+
type JwtConnectorOptions,
|
|
9
|
+
} from './connectors/jwt.js';
|
|
10
|
+
export { authGate } from './auth-gate.js';
|
|
11
|
+
export { authProvision } from './auth-provision.js';
|
|
9
12
|
export { authVerify } from './trails/auth-verify.js';
|
|
10
13
|
export { PermitError } from './errors.js';
|
|
11
14
|
export { type PermitExtractionInput } from './extraction.js';
|
package/src/permit.ts
CHANGED
|
@@ -11,8 +11,8 @@ export interface Permit extends BasePermit {
|
|
|
11
11
|
* Type-safe accessor for `ctx.permit` with a downcast to `Permit`.
|
|
12
12
|
*
|
|
13
13
|
* `TrailContext.permit` is typed as `BasePermit` (id + scopes). This accessor
|
|
14
|
-
* returns the full `Permit` when the auth
|
|
15
|
-
* the auth
|
|
14
|
+
* returns the full `Permit` when the auth gate has set one. Safe because
|
|
15
|
+
* the auth gate is the only writer and always sets a full `Permit`.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```typescript
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Result,
|
|
1
|
+
import { Result, TRAILHEAD_KEY, trail } from '@ontrails/core';
|
|
2
2
|
import type { TrailContext } from '@ontrails/core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { authProvision } from '../auth-provision.js';
|
|
6
6
|
import type { PermitExtractionInput } from '../extraction.js';
|
|
7
7
|
import type { Permit } from '../permit.js';
|
|
8
8
|
|
|
@@ -30,45 +30,32 @@ const toOutputPermit = (permit: Permit) => ({
|
|
|
30
30
|
scopes: [...permit.scopes],
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const isTrailhead = (
|
|
34
|
+
value: unknown
|
|
35
|
+
): value is PermitExtractionInput['trailhead'] =>
|
|
34
36
|
value === 'http' || value === 'mcp' || value === 'cli';
|
|
35
37
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const getTrailhead = (
|
|
39
|
+
ctx: TrailContext
|
|
40
|
+
): PermitExtractionInput['trailhead'] => {
|
|
41
|
+
const trailhead = ctx.extensions?.[TRAILHEAD_KEY];
|
|
42
|
+
return isTrailhead(trailhead) ? trailhead : 'http';
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* Infrastructure trail that verifies a bearer token and returns the resolved permit.
|
|
43
47
|
*
|
|
44
|
-
* Reads the auth
|
|
45
|
-
* bootstrap (e.g. JWT with HMAC secret). The mock
|
|
46
|
-
* a null permit, so `testAll(app)` works without configuration.
|
|
48
|
+
* Reads the auth connector from `authProvision` — the connector is configured
|
|
49
|
+
* at bootstrap (e.g. JWT with HMAC secret). The mock connector always
|
|
50
|
+
* succeeds with a null permit, so `testAll(app)` works without configuration.
|
|
47
51
|
*/
|
|
48
52
|
export const authVerify = trail('auth.verify', {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
name: 'Verify a token',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
input: z.object({
|
|
56
|
-
token: z.string().min(1).describe('Bearer token to verify'),
|
|
57
|
-
}),
|
|
58
|
-
intent: 'read',
|
|
59
|
-
metadata: { category: 'infrastructure' },
|
|
60
|
-
output: z.object({
|
|
61
|
-
error: z.string().optional(),
|
|
62
|
-
errorCode: authErrorCodeSchema.optional(),
|
|
63
|
-
permit: permitSchema.optional(),
|
|
64
|
-
valid: z.boolean(),
|
|
65
|
-
}),
|
|
66
|
-
run: async (input, ctx) => {
|
|
67
|
-
const adapter = authService.from(ctx);
|
|
68
|
-
const result = await adapter.authenticate({
|
|
53
|
+
blaze: async (input, ctx) => {
|
|
54
|
+
const connector = authProvision.from(ctx);
|
|
55
|
+
const result = await connector.authenticate({
|
|
69
56
|
bearerToken: input.token,
|
|
70
57
|
requestId: ctx.requestId,
|
|
71
|
-
|
|
58
|
+
trailhead: getTrailhead(ctx),
|
|
72
59
|
});
|
|
73
60
|
|
|
74
61
|
if (result.isErr()) {
|
|
@@ -93,5 +80,22 @@ export const authVerify = trail('auth.verify', {
|
|
|
93
80
|
valid: true,
|
|
94
81
|
});
|
|
95
82
|
},
|
|
96
|
-
|
|
83
|
+
examples: [
|
|
84
|
+
{
|
|
85
|
+
input: { token: 'test-token' },
|
|
86
|
+
name: 'Verify a token',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
input: z.object({
|
|
90
|
+
token: z.string().min(1).describe('Bearer token to verify'),
|
|
91
|
+
}),
|
|
92
|
+
intent: 'read',
|
|
93
|
+
meta: { category: 'infrastructure' },
|
|
94
|
+
output: z.object({
|
|
95
|
+
error: z.string().optional(),
|
|
96
|
+
errorCode: authErrorCodeSchema.optional(),
|
|
97
|
+
permit: permitSchema.optional(),
|
|
98
|
+
valid: z.boolean(),
|
|
99
|
+
}),
|
|
100
|
+
provisions: [authProvision],
|
|
97
101
|
});
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/
|
|
1
|
+
{"root":["./src/auth-gate.ts","./src/auth-provision.ts","./src/errors.ts","./src/extraction.ts","./src/index.ts","./src/permit.ts","./src/rules.ts","./src/testing.ts","./src/connectors/connector.ts","./src/connectors/jwt.ts","./src/trails/auth-verify.ts"],"version":"5.9.3"}
|
package/src/auth-service.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Result, service } from '@ontrails/core';
|
|
2
|
-
|
|
3
|
-
import type { AuthAdapter } from './adapter.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Auth service — manages the auth adapter lifecycle.
|
|
7
|
-
*
|
|
8
|
-
* The v1 factory returns a no-op adapter that always succeeds (null permit).
|
|
9
|
-
* Real adapter configuration will come through `ServiceSpec.config` (TRL-91).
|
|
10
|
-
* The mock factory provides a synthetic adapter that always succeeds.
|
|
11
|
-
*/
|
|
12
|
-
export const authService = service<AuthAdapter>('auth', {
|
|
13
|
-
create: (_svc) =>
|
|
14
|
-
Result.ok({
|
|
15
|
-
// oxlint-disable-next-line require-await -- stub adapter satisfies async interface
|
|
16
|
-
authenticate: async () => Result.ok(null),
|
|
17
|
-
} satisfies AuthAdapter),
|
|
18
|
-
description: 'Authentication adapter',
|
|
19
|
-
metadata: { category: 'infrastructure' },
|
|
20
|
-
mock: () =>
|
|
21
|
-
({
|
|
22
|
-
// oxlint-disable-next-line require-await -- mock adapter satisfies async interface
|
|
23
|
-
authenticate: async () => Result.ok(null),
|
|
24
|
-
}) satisfies AuthAdapter,
|
|
25
|
-
});
|