@ontrails/permits 1.0.0-beta.14 → 1.0.0-beta.15
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 +7 -0
- package/README.md +14 -14
- package/dist/auth-layer.d.ts +3 -3
- package/dist/auth-layer.js +3 -3
- package/dist/auth-resource.d.ts +11 -0
- package/dist/auth-resource.d.ts.map +1 -0
- package/dist/{auth-provision.js → auth-resource.js} +5 -5
- package/dist/auth-resource.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/permit.d.ts +2 -2
- package/dist/permit.js +2 -2
- package/dist/rules.d.ts +2 -2
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js.map +1 -1
- package/dist/testing.d.ts +4 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +5 -5
- package/dist/testing.js.map +1 -1
- package/dist/trails/auth-verify.d.ts +2 -2
- package/dist/trails/auth-verify.d.ts.map +1 -1
- package/dist/trails/auth-verify.js +4 -4
- package/dist/trails/auth-verify.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/{auth-gate.test.ts → auth-layer.test.ts} +11 -11
- package/src/__tests__/{auth-provision.test.ts → auth-resource.test.ts} +9 -9
- package/src/__tests__/auth-verify.test.ts +7 -7
- package/src/__tests__/permit.test.ts +1 -1
- package/src/__tests__/testing.test.ts +13 -13
- package/src/{auth-gate.ts → auth-layer.ts} +9 -9
- package/src/{auth-provision.ts → auth-resource.ts} +4 -4
- package/src/index.ts +3 -3
- package/src/permit.ts +2 -2
- package/src/rules.ts +2 -2
- package/src/testing.ts +5 -5
- package/src/trails/auth-verify.ts +4 -4
- package/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/adapter.d.ts +0 -26
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/adapters/jwt.d.ts +0 -25
- package/dist/adapters/jwt.d.ts.map +0 -1
- package/dist/adapters/jwt.js +0 -148
- package/dist/adapters/jwt.js.map +0 -1
- package/dist/auth-gate.d.ts +0 -18
- package/dist/auth-gate.d.ts.map +0 -1
- package/dist/auth-gate.js +0 -56
- package/dist/auth-gate.js.map +0 -1
- package/dist/auth-provision.d.ts +0 -11
- package/dist/auth-provision.d.ts.map +0 -1
- package/dist/auth-provision.js.map +0 -1
- package/dist/auth-service.d.ts +0 -10
- package/dist/auth-service.d.ts.map +0 -1
- package/dist/auth-service.js +0 -21
- package/dist/auth-service.js.map +0 -1
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { createPermitForTrail, createTestPermit } from '../testing';
|
|
4
4
|
|
|
5
|
-
describe('
|
|
5
|
+
describe('createTestPermit()', () => {
|
|
6
6
|
test('returns a Permit with the given scopes', () => {
|
|
7
|
-
const permit =
|
|
7
|
+
const permit = createTestPermit({ scopes: ['user:read', 'user:write'] });
|
|
8
8
|
expect(permit.scopes).toEqual(['user:read', 'user:write']);
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test('generates a unique id when not specified', () => {
|
|
12
|
-
const a =
|
|
13
|
-
const b =
|
|
12
|
+
const a = createTestPermit();
|
|
13
|
+
const b = createTestPermit();
|
|
14
14
|
expect(a.id).not.toBe(b.id);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
test('uses the provided id when specified', () => {
|
|
18
|
-
const permit =
|
|
18
|
+
const permit = createTestPermit({ id: 'custom-id' });
|
|
19
19
|
expect(permit.id).toBe('custom-id');
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('returns empty scopes when no options provided', () => {
|
|
23
|
-
const permit =
|
|
23
|
+
const permit = createTestPermit();
|
|
24
24
|
expect(permit.scopes).toEqual([]);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('includes roles when provided', () => {
|
|
28
|
-
const permit =
|
|
28
|
+
const permit = createTestPermit({ roles: ['admin', 'editor'] });
|
|
29
29
|
expect(permit.roles).toEqual(['admin', 'editor']);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test('includes tenantId when provided', () => {
|
|
33
|
-
const permit =
|
|
33
|
+
const permit = createTestPermit({ tenantId: 'tenant_abc' });
|
|
34
34
|
expect(permit.tenantId).toBe('tenant_abc');
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
describe('
|
|
38
|
+
describe('createPermitForTrail()', () => {
|
|
39
39
|
test('extracts scopes from trail permit requirement', () => {
|
|
40
40
|
const trail = { permit: { scopes: ['entity:read', 'entity:write'] } };
|
|
41
|
-
const permit =
|
|
41
|
+
const permit = createPermitForTrail(trail);
|
|
42
42
|
expect(permit).toBeDefined();
|
|
43
43
|
expect(permit?.scopes).toEqual(['entity:read', 'entity:write']);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test('returns undefined for public trails', () => {
|
|
47
47
|
const trail = { permit: 'public' as const };
|
|
48
|
-
const permit =
|
|
48
|
+
const permit = createPermitForTrail(trail);
|
|
49
49
|
expect(permit).toBeUndefined();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test('returns undefined when no permit declared', () => {
|
|
53
53
|
const trail = {};
|
|
54
|
-
const permit =
|
|
54
|
+
const permit = createPermitForTrail(trail);
|
|
55
55
|
expect(permit).toBeUndefined();
|
|
56
56
|
});
|
|
57
57
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Result } from '@ontrails/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Layer } from '@ontrails/core';
|
|
3
3
|
|
|
4
4
|
import { PermitError } from './errors.js';
|
|
5
5
|
import { getPermit } from './permit.js';
|
|
@@ -25,25 +25,25 @@ const findMissing = (
|
|
|
25
25
|
): readonly string[] => required.filter((s) => !held.includes(s));
|
|
26
26
|
|
|
27
27
|
// ---------------------------------------------------------------------------
|
|
28
|
-
// Auth
|
|
28
|
+
// Auth layer
|
|
29
29
|
// ---------------------------------------------------------------------------
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* A {@link
|
|
32
|
+
* A {@link Layer} that enforces permit scopes declared on trails.
|
|
33
33
|
*
|
|
34
|
-
* The
|
|
34
|
+
* The layer reads the trail's `permit` field (a `PermitRequirement`):
|
|
35
35
|
*
|
|
36
|
-
* - If `permit` is `'public'` or `undefined` the
|
|
37
|
-
* - If `permit` has `scopes`, the
|
|
36
|
+
* - If `permit` is `'public'` or `undefined` the layer passes through.
|
|
37
|
+
* - If `permit` has `scopes`, the layer checks that `ctx.permit` contains
|
|
38
38
|
* all required scopes. A superset is fine; missing scopes produce a
|
|
39
39
|
* `PermitError`.
|
|
40
40
|
*
|
|
41
|
-
* Because `ctx.cross()` re-enters `executeTrail` (which applies
|
|
42
|
-
* this
|
|
41
|
+
* Because `ctx.cross()` re-enters `executeTrail` (which applies layers),
|
|
42
|
+
* this layer automatically re-checks on every invocation in a crossing chain.
|
|
43
43
|
* No special crossing-chain handling is needed — it is built into the
|
|
44
44
|
* architecture.
|
|
45
45
|
*/
|
|
46
|
-
export const
|
|
46
|
+
export const authLayer: Layer = {
|
|
47
47
|
description: 'Enforces permit scopes declared on trails',
|
|
48
48
|
name: 'auth',
|
|
49
49
|
wrap: (_trail, impl) => {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Result,
|
|
1
|
+
import { Result, resource } from '@ontrails/core';
|
|
2
2
|
|
|
3
3
|
import type { AuthConnector } from './connectors/connector.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Auth
|
|
6
|
+
* Auth resource — manages the auth connector lifecycle.
|
|
7
7
|
*
|
|
8
8
|
* The v1 factory returns a no-op connector that always succeeds (null permit).
|
|
9
|
-
* Real connector configuration will come through `
|
|
9
|
+
* Real connector configuration will come through `ResourceSpec.config`
|
|
10
10
|
* (TRL-91). The mock factory provides a synthetic connector that always
|
|
11
11
|
* succeeds.
|
|
12
12
|
*/
|
|
13
|
-
export const
|
|
13
|
+
export const authResource = resource<AuthConnector>('auth', {
|
|
14
14
|
create: (_svc) =>
|
|
15
15
|
Result.ok({
|
|
16
16
|
// oxlint-disable-next-line require-await -- stub connector satisfies async interface
|
package/src/index.ts
CHANGED
|
@@ -7,11 +7,11 @@ export {
|
|
|
7
7
|
createJwtConnector,
|
|
8
8
|
type JwtConnectorOptions,
|
|
9
9
|
} from './connectors/jwt.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { authLayer } from './auth-layer.js';
|
|
11
|
+
export { authResource } from './auth-resource.js';
|
|
12
12
|
export { authVerify } from './trails/auth-verify.js';
|
|
13
13
|
export { PermitError } from './errors.js';
|
|
14
14
|
export { type PermitExtractionInput } from './extraction.js';
|
|
15
15
|
export { type Permit, getPermit } from './permit.js';
|
|
16
16
|
export { validatePermits, type PermitDiagnostic } from './rules.js';
|
|
17
|
-
export {
|
|
17
|
+
export { createTestPermit, createPermitForTrail } from './testing.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 layer has set one. Safe because
|
|
15
|
+
* the auth layer is the only writer and always sets a full `Permit`.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```typescript
|
package/src/rules.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface PermitDiagnostic {
|
|
|
16
16
|
// Helpers
|
|
17
17
|
// ---------------------------------------------------------------------------
|
|
18
18
|
|
|
19
|
-
type AnyTrail = Trail<unknown, unknown>;
|
|
19
|
+
type AnyTrail = Trail<unknown, unknown, unknown>;
|
|
20
20
|
type Rule = (trails: readonly AnyTrail[]) => readonly PermitDiagnostic[];
|
|
21
21
|
|
|
22
22
|
/** Check whether a trail has any permit declaration (scopes object or 'public'). */
|
|
@@ -179,5 +179,5 @@ const allRules: readonly Rule[] = [
|
|
|
179
179
|
* means the topo passes all permit governance checks.
|
|
180
180
|
*/
|
|
181
181
|
export const validatePermits = (
|
|
182
|
-
trails: readonly Trail<unknown, unknown>[]
|
|
182
|
+
trails: readonly Trail<unknown, unknown, unknown>[]
|
|
183
183
|
): readonly PermitDiagnostic[] => allRules.flatMap((rule) => rule(trails));
|
package/src/testing.ts
CHANGED
|
@@ -3,10 +3,10 @@ import type { PermitRequirement } from '@ontrails/core';
|
|
|
3
3
|
import type { Permit } from './permit.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Create a synthetic test permit with exactly the declared scopes.
|
|
7
7
|
* No admin permit, no wildcard — tests get only what the trail declares.
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const createTestPermit = (options?: {
|
|
10
10
|
readonly id?: string;
|
|
11
11
|
readonly scopes?: readonly string[];
|
|
12
12
|
readonly roles?: readonly string[];
|
|
@@ -22,13 +22,13 @@ export const mintTestPermit = (options?: {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a test permit matching a trail's permit requirement.
|
|
25
|
-
* Extracts scopes from the requirement and
|
|
25
|
+
* Extracts scopes from the requirement and creates a permit with exactly those scopes.
|
|
26
26
|
*/
|
|
27
|
-
export const
|
|
27
|
+
export const createPermitForTrail = (trail: {
|
|
28
28
|
readonly permit?: PermitRequirement | undefined;
|
|
29
29
|
}): Permit | undefined => {
|
|
30
30
|
if (!trail.permit || trail.permit === 'public') {
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return createTestPermit({ scopes: trail.permit.scopes });
|
|
34
34
|
};
|
|
@@ -2,7 +2,7 @@ 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 { authResource } from '../auth-resource.js';
|
|
6
6
|
import type { PermitExtractionInput } from '../extraction.js';
|
|
7
7
|
import type { Permit } from '../permit.js';
|
|
8
8
|
|
|
@@ -45,13 +45,13 @@ const getTrailhead = (
|
|
|
45
45
|
/**
|
|
46
46
|
* Infrastructure trail that verifies a bearer token and returns the resolved permit.
|
|
47
47
|
*
|
|
48
|
-
* Reads the auth connector from `
|
|
48
|
+
* Reads the auth connector from `authResource` — the connector is configured
|
|
49
49
|
* at bootstrap (e.g. JWT with HMAC secret). The mock connector always
|
|
50
50
|
* succeeds with a null permit, so `testAll(app)` works without configuration.
|
|
51
51
|
*/
|
|
52
52
|
export const authVerify = trail('auth.verify', {
|
|
53
53
|
blaze: async (input, ctx) => {
|
|
54
|
-
const connector =
|
|
54
|
+
const connector = authResource.from(ctx);
|
|
55
55
|
const result = await connector.authenticate({
|
|
56
56
|
bearerToken: input.token,
|
|
57
57
|
requestId: ctx.requestId,
|
|
@@ -97,5 +97,5 @@ export const authVerify = trail('auth.verify', {
|
|
|
97
97
|
permit: permitSchema.optional(),
|
|
98
98
|
valid: z.boolean(),
|
|
99
99
|
}),
|
|
100
|
-
|
|
100
|
+
resources: [authResource],
|
|
101
101
|
});
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/auth-
|
|
1
|
+
{"root":["./src/auth-layer.ts","./src/auth-resource.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/dist/adapter.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Result } from '@ontrails/core';
|
|
2
|
-
import type { PermitExtractionInput } from './extraction.js';
|
|
3
|
-
import type { Permit } from './permit.js';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use {@link PermitExtractionInput} instead. Kept as an alias
|
|
6
|
-
* for backward compatibility during migration.
|
|
7
|
-
*/
|
|
8
|
-
export type AuthCredentials = PermitExtractionInput;
|
|
9
|
-
/** Errors from auth adapters. */
|
|
10
|
-
export interface AuthError {
|
|
11
|
-
readonly code: 'expired_token' | 'insufficient_scope' | 'invalid_token' | 'missing_credentials';
|
|
12
|
-
readonly message: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Auth adapter port. Given extraction input, produce a permit or an error.
|
|
16
|
-
*
|
|
17
|
-
* The adapter receives the full {@link PermitExtractionInput} — surface,
|
|
18
|
-
* headers, requestId, and credential fields — so it can make richer
|
|
19
|
-
* decisions (e.g., rate-limit by surface or correlate via requestId).
|
|
20
|
-
*
|
|
21
|
-
* Deliberately narrow — no session management, no token refresh.
|
|
22
|
-
*/
|
|
23
|
-
export interface AuthAdapter {
|
|
24
|
-
readonly authenticate: (input: PermitExtractionInput) => Promise<Result<Permit | null, AuthError>>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAEpD,iCAAiC;AACjC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EACT,eAAe,GACf,oBAAoB,GACpB,eAAe,GACf,qBAAqB,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,YAAY,EAAE,CACrB,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;CAChD"}
|
package/dist/adapter.js
DELETED
package/dist/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":""}
|
package/dist/adapters/jwt.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AuthAdapter } from '../adapter.js';
|
|
2
|
-
/** Configuration for the JWT auth adapter. */
|
|
3
|
-
export interface JwtAdapterOptions {
|
|
4
|
-
/** HMAC secret for HS256 verification. */
|
|
5
|
-
readonly secret?: string;
|
|
6
|
-
/** JWKS endpoint for RS256/ES256 (not yet implemented). */
|
|
7
|
-
readonly jwksUrl?: string;
|
|
8
|
-
/** Expected issuer claim. */
|
|
9
|
-
readonly issuer?: string;
|
|
10
|
-
/** Expected audience claim. */
|
|
11
|
-
readonly audience?: string;
|
|
12
|
-
/** Claim containing scopes (default: 'scope'). */
|
|
13
|
-
readonly scopesClaim?: string;
|
|
14
|
-
/** Claim containing roles (default: 'roles'). */
|
|
15
|
-
readonly rolesClaim?: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Create a JWT auth adapter using Bun's native crypto.
|
|
19
|
-
*
|
|
20
|
-
* Verifies HS256-signed JWTs, extracts claims into a Permit, and checks
|
|
21
|
-
* issuer/audience when configured. Returns `Result.ok(null)` when no
|
|
22
|
-
* credentials are provided.
|
|
23
|
-
*/
|
|
24
|
-
export declare const createJwtAdapter: (options: JwtAdapterOptions) => AuthAdapter;
|
|
25
|
-
//# sourceMappingURL=jwt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/adapters/jwt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAI5D,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AA2LD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,WAe7D,CAAC"}
|
package/dist/adapters/jwt.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Result } from '@ontrails/core';
|
|
2
|
-
// ---------------------------------------------------------------------------
|
|
3
|
-
// Helpers (defined before callers)
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
const authErr = (code, message) => Result.err({ code, message });
|
|
6
|
-
/** Base64url-decode a string to bytes. */
|
|
7
|
-
const base64urlDecode = (input) => {
|
|
8
|
-
const padded = input
|
|
9
|
-
.replaceAll('-', '+')
|
|
10
|
-
.replaceAll('_', '/')
|
|
11
|
-
.padEnd(input.length + ((4 - (input.length % 4)) % 4), '=');
|
|
12
|
-
const binary = atob(padded);
|
|
13
|
-
const bytes = new Uint8Array(binary.length);
|
|
14
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
15
|
-
bytes[i] = binary.codePointAt(i) ?? 0;
|
|
16
|
-
}
|
|
17
|
-
return bytes;
|
|
18
|
-
};
|
|
19
|
-
/** Decode a JWT payload without verifying the signature. */
|
|
20
|
-
const decodePayload = (token) => {
|
|
21
|
-
const parts = token.split('.');
|
|
22
|
-
if (parts.length !== 3) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const json = new TextDecoder().decode(base64urlDecode(parts[1] ?? ''));
|
|
27
|
-
return JSON.parse(json);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
/** Import a secret as an HMAC CryptoKey. */
|
|
34
|
-
const importHmacKey = (secret) => {
|
|
35
|
-
const encoder = new TextEncoder();
|
|
36
|
-
return crypto.subtle.importKey('raw', encoder.encode(secret), { hash: 'SHA-256', name: 'HMAC' }, false, ['verify']);
|
|
37
|
-
};
|
|
38
|
-
/** Verify the HMAC-SHA256 signature of a JWT. */
|
|
39
|
-
const verifyHmacSignature = (token, key) => {
|
|
40
|
-
const lastDot = token.lastIndexOf('.');
|
|
41
|
-
if (lastDot === -1) {
|
|
42
|
-
return Promise.resolve(false);
|
|
43
|
-
}
|
|
44
|
-
const data = token.slice(0, lastDot);
|
|
45
|
-
const signature = base64urlDecode(token.slice(lastDot + 1));
|
|
46
|
-
const encoder = new TextEncoder();
|
|
47
|
-
return crypto.subtle.verify('HMAC', key, signature.buffer, encoder.encode(data));
|
|
48
|
-
};
|
|
49
|
-
/** Validate standard claims (exp, iss, aud). */
|
|
50
|
-
const validateClaims = (payload, options) => {
|
|
51
|
-
if (payload.exp !== undefined &&
|
|
52
|
-
payload.exp < Math.floor(Date.now() / 1000)) {
|
|
53
|
-
return { code: 'expired_token', message: 'Token has expired' };
|
|
54
|
-
}
|
|
55
|
-
if (options.issuer && payload.iss !== options.issuer) {
|
|
56
|
-
return { code: 'invalid_token', message: 'Issuer mismatch' };
|
|
57
|
-
}
|
|
58
|
-
if (options.audience) {
|
|
59
|
-
const { aud } = payload;
|
|
60
|
-
const matches = Array.isArray(aud)
|
|
61
|
-
? aud.includes(options.audience)
|
|
62
|
-
: aud === options.audience;
|
|
63
|
-
if (!matches) {
|
|
64
|
-
return { code: 'invalid_token', message: 'Audience mismatch' };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
};
|
|
69
|
-
/** Extract scopes from a payload claim (space-separated string or array). */
|
|
70
|
-
const extractScopes = (payload, claim) => {
|
|
71
|
-
const raw = payload[claim];
|
|
72
|
-
if (typeof raw === 'string') {
|
|
73
|
-
return raw.split(' ').filter(Boolean);
|
|
74
|
-
}
|
|
75
|
-
if (Array.isArray(raw)) {
|
|
76
|
-
return raw.filter((s) => typeof s === 'string' && s.length > 0);
|
|
77
|
-
}
|
|
78
|
-
return [];
|
|
79
|
-
};
|
|
80
|
-
/** Extract roles from a payload claim (string array). */
|
|
81
|
-
const extractRoles = (payload, claim) => {
|
|
82
|
-
const raw = payload[claim];
|
|
83
|
-
if (!Array.isArray(raw)) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
return raw.filter((r) => typeof r === 'string');
|
|
87
|
-
};
|
|
88
|
-
/** Build a Permit from a validated JWT payload. */
|
|
89
|
-
const buildPermit = (payload, options) => {
|
|
90
|
-
if (!payload.sub) {
|
|
91
|
-
return authErr('invalid_token', 'Missing subject claim (sub)');
|
|
92
|
-
}
|
|
93
|
-
const roles = extractRoles(payload, options.rolesClaim ?? 'roles');
|
|
94
|
-
return Result.ok({
|
|
95
|
-
id: payload.sub,
|
|
96
|
-
scopes: extractScopes(payload, options.scopesClaim ?? 'scope'),
|
|
97
|
-
...(roles ? { roles } : {}),
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
/** Verify the signature and return the decoded payload, or an error. */
|
|
101
|
-
const decodeAndVerify = async (token, secret) => {
|
|
102
|
-
const payload = decodePayload(token);
|
|
103
|
-
if (!payload) {
|
|
104
|
-
return authErr('invalid_token', 'Malformed JWT');
|
|
105
|
-
}
|
|
106
|
-
try {
|
|
107
|
-
const key = await importHmacKey(secret);
|
|
108
|
-
const valid = await verifyHmacSignature(token, key);
|
|
109
|
-
return valid
|
|
110
|
-
? Result.ok(payload)
|
|
111
|
-
: authErr('invalid_token', 'Invalid signature');
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
return authErr('invalid_token', 'Malformed token signature');
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
/** Validate claims and build a permit from a verified payload. */
|
|
118
|
-
const payloadToPermit = (payload, options) => {
|
|
119
|
-
const claimError = validateClaims(payload, options);
|
|
120
|
-
if (claimError) {
|
|
121
|
-
return Result.err(claimError);
|
|
122
|
-
}
|
|
123
|
-
return buildPermit(payload, options);
|
|
124
|
-
};
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Factory
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
/**
|
|
129
|
-
* Create a JWT auth adapter using Bun's native crypto.
|
|
130
|
-
*
|
|
131
|
-
* Verifies HS256-signed JWTs, extracts claims into a Permit, and checks
|
|
132
|
-
* issuer/audience when configured. Returns `Result.ok(null)` when no
|
|
133
|
-
* credentials are provided.
|
|
134
|
-
*/
|
|
135
|
-
export const createJwtAdapter = (options) => {
|
|
136
|
-
const authenticate = async (input) => {
|
|
137
|
-
if (!input.bearerToken) {
|
|
138
|
-
return Result.ok(null);
|
|
139
|
-
}
|
|
140
|
-
if (!options.secret) {
|
|
141
|
-
return authErr('invalid_token', 'No secret configured');
|
|
142
|
-
}
|
|
143
|
-
const decoded = await decodeAndVerify(input.bearerToken, options.secret);
|
|
144
|
-
return decoded.isErr() ? decoded : payloadToPermit(decoded.value, options);
|
|
145
|
-
};
|
|
146
|
-
return { authenticate };
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=jwt.js.map
|
package/dist/adapters/jwt.js.map
DEL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,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,OAAO,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACzE,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7E,CAAC,CAAC;IAEF,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC,CAAC"}
|
package/dist/auth-gate.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Gate } from '@ontrails/core';
|
|
2
|
-
/**
|
|
3
|
-
* A {@link Gate} that enforces permit scopes declared on trails.
|
|
4
|
-
*
|
|
5
|
-
* The gate reads the trail's `permit` field (a `PermitRequirement`):
|
|
6
|
-
*
|
|
7
|
-
* - If `permit` is `'public'` or `undefined` the gate passes through.
|
|
8
|
-
* - If `permit` has `scopes`, the gate checks that `ctx.permit` contains
|
|
9
|
-
* all required scopes. A superset is fine; missing scopes produce a
|
|
10
|
-
* `PermitError`.
|
|
11
|
-
*
|
|
12
|
-
* Because `ctx.cross()` re-enters `executeTrail` (which applies gates),
|
|
13
|
-
* this gate automatically re-checks on every invocation in a crossing chain.
|
|
14
|
-
* No special crossing-chain handling is needed — it is built into the
|
|
15
|
-
* architecture.
|
|
16
|
-
*/
|
|
17
|
-
export declare const authGate: Gate;
|
|
18
|
-
//# sourceMappingURL=auth-gate.d.ts.map
|
package/dist/auth-gate.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-gate.d.ts","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA6B3C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,EAAE,IAkCtB,CAAC"}
|
package/dist/auth-gate.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Result } from '@ontrails/core';
|
|
2
|
-
import { PermitError } from './errors.js';
|
|
3
|
-
import { getPermit } from './permit.js';
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Helpers (defined before callers — no use-before-define)
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Returns `true` when the permit requirement means "no enforcement needed."
|
|
9
|
-
* Either the trail hasn't declared a permit posture or has explicitly
|
|
10
|
-
* opted out with `'public'`.
|
|
11
|
-
*/
|
|
12
|
-
const isPassThrough = (requirement) => requirement === undefined || requirement === 'public';
|
|
13
|
-
/** Returns scopes present in `required` but absent from `held`. */
|
|
14
|
-
const findMissing = (required, held) => required.filter((s) => !held.includes(s));
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// Auth gate
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
* A {@link Gate} that enforces permit scopes declared on trails.
|
|
20
|
-
*
|
|
21
|
-
* The gate reads the trail's `permit` field (a `PermitRequirement`):
|
|
22
|
-
*
|
|
23
|
-
* - If `permit` is `'public'` or `undefined` the gate passes through.
|
|
24
|
-
* - If `permit` has `scopes`, the gate checks that `ctx.permit` contains
|
|
25
|
-
* all required scopes. A superset is fine; missing scopes produce a
|
|
26
|
-
* `PermitError`.
|
|
27
|
-
*
|
|
28
|
-
* Because `ctx.cross()` re-enters `executeTrail` (which applies gates),
|
|
29
|
-
* this gate automatically re-checks on every invocation in a crossing chain.
|
|
30
|
-
* No special crossing-chain handling is needed — it is built into the
|
|
31
|
-
* architecture.
|
|
32
|
-
*/
|
|
33
|
-
export const authGate = {
|
|
34
|
-
description: 'Enforces permit scopes declared on trails',
|
|
35
|
-
name: 'auth',
|
|
36
|
-
wrap: (_trail, impl) => {
|
|
37
|
-
const requirement = _trail.permit;
|
|
38
|
-
if (isPassThrough(requirement)) {
|
|
39
|
-
return impl;
|
|
40
|
-
}
|
|
41
|
-
return (input, ctx) => {
|
|
42
|
-
const permit = getPermit(ctx);
|
|
43
|
-
if (!permit) {
|
|
44
|
-
return Promise.resolve(Result.err(new PermitError('No permit provided')));
|
|
45
|
-
}
|
|
46
|
-
const missing = findMissing(requirement.scopes, permit.scopes);
|
|
47
|
-
if (missing.length > 0) {
|
|
48
|
-
return Promise.resolve(Result.err(new PermitError(`Missing scopes: ${missing.join(', ')}`, {
|
|
49
|
-
context: { missing, required: requirement.scopes },
|
|
50
|
-
})));
|
|
51
|
-
}
|
|
52
|
-
return Promise.resolve(impl(input, ctx));
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
//# sourceMappingURL=auth-gate.js.map
|
package/dist/auth-gate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-gate.js","sourceRoot":"","sources":["../src/auth-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,8EAA8E;AAC9E,0DAA0D;AAC1D,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,aAAa,GAAG,CACpB,WAAoB,EACiB,EAAE,CACvC,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,QAAQ,CAAC;AAExD,mEAAmE;AACnE,MAAM,WAAW,GAAG,CAClB,QAA2B,EAC3B,IAAuB,EACJ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAElE,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAS;IAC5B,WAAW,EAAE,2CAA2C;IACxD,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACrB,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;QAElC,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACpB,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;YAE9B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,OAAO,CAAC,OAAO,CACpB,MAAM,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,oBAAoB,CAAC,CAAC,CAClD,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YAE/D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvB,OAAO,OAAO,CAAC,OAAO,CACpB,MAAM,CAAC,GAAG,CACR,IAAI,WAAW,CAAC,mBAAmB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;oBACvD,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE;iBACnD,CAAC,CACH,CACF,CAAC;YACJ,CAAC;YAED,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/auth-provision.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AuthConnector } from './connectors/connector.js';
|
|
2
|
-
/**
|
|
3
|
-
* Auth provision — manages the auth connector lifecycle.
|
|
4
|
-
*
|
|
5
|
-
* The v1 factory returns a no-op connector that always succeeds (null permit).
|
|
6
|
-
* Real connector configuration will come through `ProvisionSpec.config`
|
|
7
|
-
* (TRL-91). The mock factory provides a synthetic connector that always
|
|
8
|
-
* succeeds.
|
|
9
|
-
*/
|
|
10
|
-
export declare const authProvision: import("@ontrails/core").Provision<AuthConnector>;
|
|
11
|
-
//# sourceMappingURL=auth-provision.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-provision.d.ts","sourceRoot":"","sources":["../src/auth-provision.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,mDAaxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-provision.js","sourceRoot":"","sources":["../src/auth-provision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAInD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAgB,MAAM,EAAE;IAC5D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACf,MAAM,CAAC,EAAE,CAAC;QACR,qFAAqF;QACrF,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;KAClB,CAAC;IAC5B,WAAW,EAAE,0BAA0B;IACvC,IAAI,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;IACpC,IAAI,EAAE,GAAG,EAAE,CACT,CAAC;QACC,qFAAqF;QACrF,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;KAC1C,CAAyB;CAC7B,CAAC,CAAC"}
|
package/dist/auth-service.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AuthAdapter } from './adapter.js';
|
|
2
|
-
/**
|
|
3
|
-
* Auth service — manages the auth adapter lifecycle.
|
|
4
|
-
*
|
|
5
|
-
* The v1 factory returns a no-op adapter that always succeeds (null permit).
|
|
6
|
-
* Real adapter configuration will come through `ServiceSpec.config` (TRL-91).
|
|
7
|
-
* The mock factory provides a synthetic adapter that always succeeds.
|
|
8
|
-
*/
|
|
9
|
-
export declare const authService: import("@ontrails/core").Service<AuthAdapter>;
|
|
10
|
-
//# sourceMappingURL=auth-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-service.d.ts","sourceRoot":"","sources":["../src/auth-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,+CAatB,CAAC"}
|
package/dist/auth-service.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Result, service } from '@ontrails/core';
|
|
2
|
-
/**
|
|
3
|
-
* Auth service — manages the auth adapter lifecycle.
|
|
4
|
-
*
|
|
5
|
-
* The v1 factory returns a no-op adapter that always succeeds (null permit).
|
|
6
|
-
* Real adapter configuration will come through `ServiceSpec.config` (TRL-91).
|
|
7
|
-
* The mock factory provides a synthetic adapter that always succeeds.
|
|
8
|
-
*/
|
|
9
|
-
export const authService = service('auth', {
|
|
10
|
-
create: (_svc) => Result.ok({
|
|
11
|
-
// oxlint-disable-next-line require-await -- stub adapter satisfies async interface
|
|
12
|
-
authenticate: async () => Result.ok(null),
|
|
13
|
-
}),
|
|
14
|
-
description: 'Authentication adapter',
|
|
15
|
-
metadata: { category: 'infrastructure' },
|
|
16
|
-
mock: () => ({
|
|
17
|
-
// oxlint-disable-next-line require-await -- mock adapter satisfies async interface
|
|
18
|
-
authenticate: async () => Result.ok(null),
|
|
19
|
-
}),
|
|
20
|
-
});
|
|
21
|
-
//# sourceMappingURL=auth-service.js.map
|
package/dist/auth-service.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../src/auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAIjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAc,MAAM,EAAE;IACtD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACf,MAAM,CAAC,EAAE,CAAC;QACR,mFAAmF;QACnF,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;KACpB,CAAC;IAC1B,WAAW,EAAE,wBAAwB;IACrC,QAAQ,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;IACxC,IAAI,EAAE,GAAG,EAAE,CACT,CAAC;QACC,mFAAmF;QACnF,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;KAC1C,CAAuB;CAC3B,CAAC,CAAC"}
|