@authyon/server 0.2.0-beta.3 → 0.2.0-beta.31
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/LICENSE +21 -21
- package/README.md +590 -373
- package/dist/authorization-CALNd7HI.d.cts +145 -0
- package/dist/authorization-Cc-xr0ay.d.ts +145 -0
- package/dist/authyonServerClient-mwY55kc9.d.cts +1709 -0
- package/dist/authyonServerClient-mwY55kc9.d.ts +1709 -0
- package/dist/bff.cjs +1209 -0
- package/dist/bff.d.cts +182 -0
- package/dist/bff.d.ts +182 -0
- package/dist/bff.js +836 -0
- package/dist/chunk-77J4NURK.js +13 -0
- package/dist/chunk-SUL2HLRR.js +361 -0
- package/dist/chunk-V6JQIOSP.js +534 -0
- package/dist/index.cjs +836 -175
- package/dist/index.d.cts +86 -979
- package/dist/index.d.ts +86 -979
- package/dist/index.js +723 -909
- package/dist/next.cjs +338 -0
- package/dist/next.d.cts +27 -0
- package/dist/next.d.ts +27 -0
- package/dist/next.js +48 -0
- package/package.json +80 -58
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
|
|
2
|
+
|
|
3
|
+
type AbilitySubject = string | Record<string, unknown>;
|
|
4
|
+
type AbilityConditions = Record<string, unknown>;
|
|
5
|
+
interface AbilityRule {
|
|
6
|
+
action: string | string[];
|
|
7
|
+
subject: string | string[];
|
|
8
|
+
inverted?: boolean;
|
|
9
|
+
conditions?: AbilityConditions;
|
|
10
|
+
fields?: string[];
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
interface AuthyonPermissionSource {
|
|
14
|
+
permissions?: readonly string[] | null;
|
|
15
|
+
roles?: readonly string[] | null;
|
|
16
|
+
/** OAuth scopes are also accepted and interpreted as Authyon permissions. */
|
|
17
|
+
scope?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** A declarative group of permissions evaluated against an Authyon permission source. */
|
|
20
|
+
interface PermissionGroup {
|
|
21
|
+
/** Permissions that must all be granted. */
|
|
22
|
+
allOf?: readonly string[];
|
|
23
|
+
/** Permissions where at least one must be granted. */
|
|
24
|
+
anyOf?: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
interface AuthyonAbilityOptions {
|
|
27
|
+
rules?: readonly AbilityRule[];
|
|
28
|
+
/** Rules added when the source contains a matching Authyon role. */
|
|
29
|
+
roleRules?: Readonly<Record<string, readonly AbilityRule[]>>;
|
|
30
|
+
roles?: readonly string[] | null;
|
|
31
|
+
detectSubjectType?: (subject: Record<string, unknown>) => string;
|
|
32
|
+
}
|
|
33
|
+
type AbilityEvent = "updated";
|
|
34
|
+
type AbilityListener = (rules: readonly AbilityRule[]) => void;
|
|
35
|
+
/** Isomorphic, deny-by-default authorization engine backed by Authyon permissions. */
|
|
36
|
+
declare class AuthyonAbility {
|
|
37
|
+
private readonly detectSubjectType;
|
|
38
|
+
private currentRules;
|
|
39
|
+
private readonly listeners;
|
|
40
|
+
constructor(rules?: readonly AbilityRule[], detectSubjectType?: (subject: Record<string, unknown>) => string);
|
|
41
|
+
get rules(): readonly AbilityRule[];
|
|
42
|
+
can(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
43
|
+
cannot(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
44
|
+
rulesFor(action: string, subject: string): readonly AbilityRule[];
|
|
45
|
+
update(rules: readonly AbilityRule[]): void;
|
|
46
|
+
on(event: AbilityEvent, listener: AbilityListener): () => void;
|
|
47
|
+
}
|
|
48
|
+
/** Fluent rule builder with CASL-like `can` and `cannot` methods. */
|
|
49
|
+
declare class AuthyonAbilityBuilder {
|
|
50
|
+
readonly rules: AbilityRule[];
|
|
51
|
+
can(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[]): this;
|
|
52
|
+
cannot(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[], reason?: string): this;
|
|
53
|
+
build(options?: Pick<AuthyonAbilityOptions, "detectSubjectType">): AuthyonAbility;
|
|
54
|
+
}
|
|
55
|
+
/** Creates an ability from Authyon permissions, OAuth scope and optional role rules. */
|
|
56
|
+
declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AuthyonAbility;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a source holds an Authyon permission, by Authyon's own rules: the
|
|
59
|
+
* values are compared segment by segment, `*` stands for any one segment, and
|
|
60
|
+
* two values of different lengths never match — except an all-wildcard grant,
|
|
61
|
+
* which is everything, and a grant ending in `**`, which stands for one or
|
|
62
|
+
* more segments (`manager:**` covers `manager:account:read` and
|
|
63
|
+
* `manager:account:credentials:write`). OAuth scopes count as permissions.
|
|
64
|
+
*
|
|
65
|
+
* Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
|
|
66
|
+
* the action `manage` there means "every action on this subject", which is a
|
|
67
|
+
* useful thing to author by hand and a wrong thing to infer from a permission:
|
|
68
|
+
* `subtenants:tree:manage` and `subtenants:tree:switch` are deliberately
|
|
69
|
+
* separate grants on the API side — administering a sub-tenant from above and
|
|
70
|
+
* operating as it are different powers — and reading the first as the second
|
|
71
|
+
* would have this answer yes to a call the API then refuses. Ask this one
|
|
72
|
+
* about anything Authyon will be enforcing.
|
|
73
|
+
*/
|
|
74
|
+
declare function hasPermission(source: AuthyonPermissionSource | readonly string[], requiredPermission: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Checks a permission group with {@link hasPermission}, so the same rules as
|
|
77
|
+
* the API. Empty or omitted groups do not add authorization requirements.
|
|
78
|
+
*/
|
|
79
|
+
declare function hasPermissionGroup(source: AuthyonPermissionSource | readonly string[], group: PermissionGroup): boolean;
|
|
80
|
+
/** Converts Authyon's `subject:action` permission strings to authorization rules. */
|
|
81
|
+
declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
|
|
82
|
+
|
|
83
|
+
interface AbilityRequirement {
|
|
84
|
+
action: string;
|
|
85
|
+
subject: AbilitySubject;
|
|
86
|
+
field?: string;
|
|
87
|
+
}
|
|
88
|
+
interface AuthorizationContext {
|
|
89
|
+
token: string;
|
|
90
|
+
userId?: string;
|
|
91
|
+
ability: AuthyonAbility;
|
|
92
|
+
permissions: readonly string[];
|
|
93
|
+
roles: readonly string[];
|
|
94
|
+
}
|
|
95
|
+
interface AuthorizationOptions extends AuthyonAbilityOptions {
|
|
96
|
+
requirement?: AbilityRequirement;
|
|
97
|
+
/** Uses database-backed validation by default; introspection can be selected when desired. */
|
|
98
|
+
verification?: "validate" | "introspect" | "jwks";
|
|
99
|
+
/** Required for local JWKS verification. Create once and reuse its key cache. */
|
|
100
|
+
jwksVerifier?: JwksTokenVerifier;
|
|
101
|
+
/** Real end-user IP, obtained from trusted application infrastructure. */
|
|
102
|
+
clientIp?: string;
|
|
103
|
+
}
|
|
104
|
+
declare class AuthorizationError extends Error {
|
|
105
|
+
readonly status: 401 | 403 | 503;
|
|
106
|
+
readonly code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable";
|
|
107
|
+
constructor(status: 401 | 403 | 503, code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable", message: string);
|
|
108
|
+
}
|
|
109
|
+
/** Validates a bearer token and creates an Authyon-backed ability for server runtimes. */
|
|
110
|
+
declare function authorizeToken(client: AuthyonServerClient, token: string, options?: AuthorizationOptions): Promise<AuthorizationContext>;
|
|
111
|
+
/** Works with Web Request objects used by Next.js Route Handlers and other Fetch runtimes. */
|
|
112
|
+
declare function authorizeRequest(client: AuthyonServerClient, request: Pick<Request, "headers">, options?: RequestAuthorizationOptions): Promise<AuthorizationContext>;
|
|
113
|
+
interface RequestAuthorizationOptions extends AuthorizationOptions {
|
|
114
|
+
/** Platform-aware resolver. Only read headers that your trusted proxy overwrites. */
|
|
115
|
+
resolveClientIp?: (request: Pick<Request, "headers">) => string | undefined;
|
|
116
|
+
}
|
|
117
|
+
interface ExpressRequestLike {
|
|
118
|
+
headers: Record<string, string | string[] | undefined>;
|
|
119
|
+
ip?: string;
|
|
120
|
+
socket?: {
|
|
121
|
+
remoteAddress?: string;
|
|
122
|
+
};
|
|
123
|
+
authyon?: AuthorizationContext;
|
|
124
|
+
}
|
|
125
|
+
interface ExpressResponseLike {
|
|
126
|
+
status(code: number): ExpressResponseLike;
|
|
127
|
+
json(body: unknown): unknown;
|
|
128
|
+
}
|
|
129
|
+
type ExpressNext = (error?: unknown) => void;
|
|
130
|
+
interface ExpressAuthorizationMiddlewareOptions extends AuthorizationOptions {
|
|
131
|
+
/** Property assigned to the request. Defaults to `authyon`. */
|
|
132
|
+
requestProperty?: string;
|
|
133
|
+
/** Pass authorization errors to Express error middleware instead of writing a JSON response. */
|
|
134
|
+
passErrorsToNext?: boolean;
|
|
135
|
+
/** Trust Express's proxy-aware `request.ip`. Disabled by default. */
|
|
136
|
+
trustProxy?: boolean;
|
|
137
|
+
/** Overrides all built-in IP resolution; return only a trusted, single client IP. */
|
|
138
|
+
resolveClientIp?: (request: ExpressRequestLike) => string | undefined;
|
|
139
|
+
}
|
|
140
|
+
/** Dependency-free middleware compatible with Express and similar Connect frameworks. */
|
|
141
|
+
declare function createExpressAuthorizationMiddleware(client: AuthyonServerClient, options?: ExpressAuthorizationMiddlewareOptions): (request: ExpressRequestLike & Record<string, unknown>, response: ExpressResponseLike, next: ExpressNext) => Promise<void>;
|
|
142
|
+
/** Converts an authorization error into a Fetch Response suitable for Next.js. */
|
|
143
|
+
declare function createAuthorizationErrorResponse(error: unknown): Response;
|
|
144
|
+
|
|
145
|
+
export { type AbilitySubject as A, type ExpressAuthorizationMiddlewareOptions as E, type PermissionGroup as P, type RequestAuthorizationOptions as R, AuthorizationError as a, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRequirement as e, type AbilityRule as f, type AuthorizationContext as g, type AuthorizationOptions as h, AuthyonAbility as i, AuthyonAbilityBuilder as j, type AuthyonAbilityOptions as k, type AuthyonPermissionSource as l, type ExpressNext as m, type ExpressRequestLike as n, type ExpressResponseLike as o, authorizeRequest as p, authorizeToken as q, createAuthorizationErrorResponse as r, createAuthyonAbility as s, createAuthyonRules as t, createExpressAuthorizationMiddleware as u, hasPermission as v, hasPermissionGroup as w };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { J as JwksTokenVerifier, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
|
|
2
|
+
|
|
3
|
+
type AbilitySubject = string | Record<string, unknown>;
|
|
4
|
+
type AbilityConditions = Record<string, unknown>;
|
|
5
|
+
interface AbilityRule {
|
|
6
|
+
action: string | string[];
|
|
7
|
+
subject: string | string[];
|
|
8
|
+
inverted?: boolean;
|
|
9
|
+
conditions?: AbilityConditions;
|
|
10
|
+
fields?: string[];
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
interface AuthyonPermissionSource {
|
|
14
|
+
permissions?: readonly string[] | null;
|
|
15
|
+
roles?: readonly string[] | null;
|
|
16
|
+
/** OAuth scopes are also accepted and interpreted as Authyon permissions. */
|
|
17
|
+
scope?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** A declarative group of permissions evaluated against an Authyon permission source. */
|
|
20
|
+
interface PermissionGroup {
|
|
21
|
+
/** Permissions that must all be granted. */
|
|
22
|
+
allOf?: readonly string[];
|
|
23
|
+
/** Permissions where at least one must be granted. */
|
|
24
|
+
anyOf?: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
interface AuthyonAbilityOptions {
|
|
27
|
+
rules?: readonly AbilityRule[];
|
|
28
|
+
/** Rules added when the source contains a matching Authyon role. */
|
|
29
|
+
roleRules?: Readonly<Record<string, readonly AbilityRule[]>>;
|
|
30
|
+
roles?: readonly string[] | null;
|
|
31
|
+
detectSubjectType?: (subject: Record<string, unknown>) => string;
|
|
32
|
+
}
|
|
33
|
+
type AbilityEvent = "updated";
|
|
34
|
+
type AbilityListener = (rules: readonly AbilityRule[]) => void;
|
|
35
|
+
/** Isomorphic, deny-by-default authorization engine backed by Authyon permissions. */
|
|
36
|
+
declare class AuthyonAbility {
|
|
37
|
+
private readonly detectSubjectType;
|
|
38
|
+
private currentRules;
|
|
39
|
+
private readonly listeners;
|
|
40
|
+
constructor(rules?: readonly AbilityRule[], detectSubjectType?: (subject: Record<string, unknown>) => string);
|
|
41
|
+
get rules(): readonly AbilityRule[];
|
|
42
|
+
can(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
43
|
+
cannot(action: string, subject: AbilitySubject, field?: string): boolean;
|
|
44
|
+
rulesFor(action: string, subject: string): readonly AbilityRule[];
|
|
45
|
+
update(rules: readonly AbilityRule[]): void;
|
|
46
|
+
on(event: AbilityEvent, listener: AbilityListener): () => void;
|
|
47
|
+
}
|
|
48
|
+
/** Fluent rule builder with CASL-like `can` and `cannot` methods. */
|
|
49
|
+
declare class AuthyonAbilityBuilder {
|
|
50
|
+
readonly rules: AbilityRule[];
|
|
51
|
+
can(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[]): this;
|
|
52
|
+
cannot(action: string | string[], subject: string | string[], conditions?: AbilityConditions, fields?: string[], reason?: string): this;
|
|
53
|
+
build(options?: Pick<AuthyonAbilityOptions, "detectSubjectType">): AuthyonAbility;
|
|
54
|
+
}
|
|
55
|
+
/** Creates an ability from Authyon permissions, OAuth scope and optional role rules. */
|
|
56
|
+
declare function createAuthyonAbility(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AuthyonAbility;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a source holds an Authyon permission, by Authyon's own rules: the
|
|
59
|
+
* values are compared segment by segment, `*` stands for any one segment, and
|
|
60
|
+
* two values of different lengths never match — except an all-wildcard grant,
|
|
61
|
+
* which is everything, and a grant ending in `**`, which stands for one or
|
|
62
|
+
* more segments (`manager:**` covers `manager:account:read` and
|
|
63
|
+
* `manager:account:credentials:write`). OAuth scopes count as permissions.
|
|
64
|
+
*
|
|
65
|
+
* Not the same question as {@link AuthyonAbility.can}. An ability is CASL, so
|
|
66
|
+
* the action `manage` there means "every action on this subject", which is a
|
|
67
|
+
* useful thing to author by hand and a wrong thing to infer from a permission:
|
|
68
|
+
* `subtenants:tree:manage` and `subtenants:tree:switch` are deliberately
|
|
69
|
+
* separate grants on the API side — administering a sub-tenant from above and
|
|
70
|
+
* operating as it are different powers — and reading the first as the second
|
|
71
|
+
* would have this answer yes to a call the API then refuses. Ask this one
|
|
72
|
+
* about anything Authyon will be enforcing.
|
|
73
|
+
*/
|
|
74
|
+
declare function hasPermission(source: AuthyonPermissionSource | readonly string[], requiredPermission: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Checks a permission group with {@link hasPermission}, so the same rules as
|
|
77
|
+
* the API. Empty or omitted groups do not add authorization requirements.
|
|
78
|
+
*/
|
|
79
|
+
declare function hasPermissionGroup(source: AuthyonPermissionSource | readonly string[], group: PermissionGroup): boolean;
|
|
80
|
+
/** Converts Authyon's `subject:action` permission strings to authorization rules. */
|
|
81
|
+
declare function createAuthyonRules(source?: AuthyonPermissionSource, options?: AuthyonAbilityOptions): AbilityRule[];
|
|
82
|
+
|
|
83
|
+
interface AbilityRequirement {
|
|
84
|
+
action: string;
|
|
85
|
+
subject: AbilitySubject;
|
|
86
|
+
field?: string;
|
|
87
|
+
}
|
|
88
|
+
interface AuthorizationContext {
|
|
89
|
+
token: string;
|
|
90
|
+
userId?: string;
|
|
91
|
+
ability: AuthyonAbility;
|
|
92
|
+
permissions: readonly string[];
|
|
93
|
+
roles: readonly string[];
|
|
94
|
+
}
|
|
95
|
+
interface AuthorizationOptions extends AuthyonAbilityOptions {
|
|
96
|
+
requirement?: AbilityRequirement;
|
|
97
|
+
/** Uses database-backed validation by default; introspection can be selected when desired. */
|
|
98
|
+
verification?: "validate" | "introspect" | "jwks";
|
|
99
|
+
/** Required for local JWKS verification. Create once and reuse its key cache. */
|
|
100
|
+
jwksVerifier?: JwksTokenVerifier;
|
|
101
|
+
/** Real end-user IP, obtained from trusted application infrastructure. */
|
|
102
|
+
clientIp?: string;
|
|
103
|
+
}
|
|
104
|
+
declare class AuthorizationError extends Error {
|
|
105
|
+
readonly status: 401 | 403 | 503;
|
|
106
|
+
readonly code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable";
|
|
107
|
+
constructor(status: 401 | 403 | 503, code: "authorization.unauthenticated" | "authorization.forbidden" | "authorization.unavailable", message: string);
|
|
108
|
+
}
|
|
109
|
+
/** Validates a bearer token and creates an Authyon-backed ability for server runtimes. */
|
|
110
|
+
declare function authorizeToken(client: AuthyonServerClient, token: string, options?: AuthorizationOptions): Promise<AuthorizationContext>;
|
|
111
|
+
/** Works with Web Request objects used by Next.js Route Handlers and other Fetch runtimes. */
|
|
112
|
+
declare function authorizeRequest(client: AuthyonServerClient, request: Pick<Request, "headers">, options?: RequestAuthorizationOptions): Promise<AuthorizationContext>;
|
|
113
|
+
interface RequestAuthorizationOptions extends AuthorizationOptions {
|
|
114
|
+
/** Platform-aware resolver. Only read headers that your trusted proxy overwrites. */
|
|
115
|
+
resolveClientIp?: (request: Pick<Request, "headers">) => string | undefined;
|
|
116
|
+
}
|
|
117
|
+
interface ExpressRequestLike {
|
|
118
|
+
headers: Record<string, string | string[] | undefined>;
|
|
119
|
+
ip?: string;
|
|
120
|
+
socket?: {
|
|
121
|
+
remoteAddress?: string;
|
|
122
|
+
};
|
|
123
|
+
authyon?: AuthorizationContext;
|
|
124
|
+
}
|
|
125
|
+
interface ExpressResponseLike {
|
|
126
|
+
status(code: number): ExpressResponseLike;
|
|
127
|
+
json(body: unknown): unknown;
|
|
128
|
+
}
|
|
129
|
+
type ExpressNext = (error?: unknown) => void;
|
|
130
|
+
interface ExpressAuthorizationMiddlewareOptions extends AuthorizationOptions {
|
|
131
|
+
/** Property assigned to the request. Defaults to `authyon`. */
|
|
132
|
+
requestProperty?: string;
|
|
133
|
+
/** Pass authorization errors to Express error middleware instead of writing a JSON response. */
|
|
134
|
+
passErrorsToNext?: boolean;
|
|
135
|
+
/** Trust Express's proxy-aware `request.ip`. Disabled by default. */
|
|
136
|
+
trustProxy?: boolean;
|
|
137
|
+
/** Overrides all built-in IP resolution; return only a trusted, single client IP. */
|
|
138
|
+
resolveClientIp?: (request: ExpressRequestLike) => string | undefined;
|
|
139
|
+
}
|
|
140
|
+
/** Dependency-free middleware compatible with Express and similar Connect frameworks. */
|
|
141
|
+
declare function createExpressAuthorizationMiddleware(client: AuthyonServerClient, options?: ExpressAuthorizationMiddlewareOptions): (request: ExpressRequestLike & Record<string, unknown>, response: ExpressResponseLike, next: ExpressNext) => Promise<void>;
|
|
142
|
+
/** Converts an authorization error into a Fetch Response suitable for Next.js. */
|
|
143
|
+
declare function createAuthorizationErrorResponse(error: unknown): Response;
|
|
144
|
+
|
|
145
|
+
export { type AbilitySubject as A, type ExpressAuthorizationMiddlewareOptions as E, type PermissionGroup as P, type RequestAuthorizationOptions as R, AuthorizationError as a, type AbilityConditions as b, type AbilityEvent as c, type AbilityListener as d, type AbilityRequirement as e, type AbilityRule as f, type AuthorizationContext as g, type AuthorizationOptions as h, AuthyonAbility as i, AuthyonAbilityBuilder as j, type AuthyonAbilityOptions as k, type AuthyonPermissionSource as l, type ExpressNext as m, type ExpressRequestLike as n, type ExpressResponseLike as o, authorizeRequest as p, authorizeToken as q, createAuthorizationErrorResponse as r, createAuthyonAbility as s, createAuthyonRules as t, createExpressAuthorizationMiddleware as u, hasPermission as v, hasPermissionGroup as w };
|