@adonis-agora/agent 0.7.0 → 0.8.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/CHANGELOG.md +18 -0
- package/dist/src/ai-tool-ref.d.ts +3 -2
- package/dist/src/ai-tool-ref.d.ts.map +1 -1
- package/dist/src/ai-tool-ref.js +15 -11
- package/dist/src/ai-tool-ref.js.map +1 -1
- package/dist/src/authz/agora-context.d.ts +24 -0
- package/dist/src/authz/agora-context.d.ts.map +1 -0
- package/dist/src/authz/agora-context.js +16 -0
- package/dist/src/authz/agora-context.js.map +1 -0
- package/dist/src/authz/authz-actor-resolver.d.ts +35 -0
- package/dist/src/authz/authz-actor-resolver.d.ts.map +1 -0
- package/dist/src/authz/authz-actor-resolver.js +41 -0
- package/dist/src/authz/authz-actor-resolver.js.map +1 -0
- package/dist/src/authz/index.d.ts +2 -0
- package/dist/src/authz/index.d.ts.map +1 -1
- package/dist/src/authz/index.js +1 -0
- package/dist/src/authz/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @adonis-agora/agent
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#23](https://github.com/DavideCarvalho/adonis-agent/pull/23) [`19c9ffd`](https://github.com/DavideCarvalho/adonis-agent/commit/19c9ffd9c285c7cab4e487c8bda73f7ce668be9e) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Add `authzActorResolver` (exported from `@adonis-agora/agent/authz`) — resolve the agent `Actor` from the Agora context populated by authkit (`userRef`, `tenantId`) plus authz `effectiveRoles` (the union global ∪ app ∪ store). Structural, zero hard dependency; authkit+authz apps can drop hand-written actor resolvers. Fail-closed: no identity in context → 401.
|
|
8
|
+
|
|
9
|
+
## 0.7.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#21](https://github.com/DavideCarvalho/adonis-agent/pull/21) [`d02b26b`](https://github.com/DavideCarvalho/adonis-agent/commit/d02b26bea2acd8d6f7daac166116a6813d321a02) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Internal: simplify `readAiToolMeta` metadata resolution
|
|
14
|
+
|
|
15
|
+
Refactor the tool-metadata lookup so the two authoring mechanisms (`@AiTool`
|
|
16
|
+
decorator and `static tool`) and the two subjects (the value, its constructor)
|
|
17
|
+
are composed explicitly — `metaOn(target) ?? metaOn(ctor)` — instead of a flat
|
|
18
|
+
four-way fallback chain. No behavior or API change; discovery of both forms is
|
|
19
|
+
unchanged (mutation-proven).
|
|
20
|
+
|
|
3
21
|
## 0.7.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -51,14 +51,15 @@ export type ToolClass = abstract new (...args: never[]) => ToolHandler;
|
|
|
51
51
|
*/
|
|
52
52
|
export declare function AiTool(options: AiToolOptions): <T extends ToolClass>(target: T) => T;
|
|
53
53
|
/**
|
|
54
|
-
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported
|
|
54
|
+
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported:
|
|
55
55
|
*
|
|
56
56
|
* 1. The `@AiTool({ … })` decorator (stamps {@link AI_TOOL_META_KEY}).
|
|
57
57
|
* 2. A decorator-free `static tool = { name, kind, description, input, … }` config on the class — the
|
|
58
58
|
* same shape, mirroring `@adonis-agora/durable`'s `static workflow`. Preferred where you'd rather
|
|
59
59
|
* not rely on decorators.
|
|
60
60
|
*
|
|
61
|
-
* Accepts either the class itself or an instance
|
|
61
|
+
* Accepts either the class itself or an instance: each mechanism is tried on the value, then on its
|
|
62
|
+
* constructor (so an instance resolves the class's metadata).
|
|
62
63
|
*/
|
|
63
64
|
export declare function readAiToolMeta(target: unknown): AiToolMeta | undefined;
|
|
64
65
|
/** A tool expressed as data + handler (from {@link defineTool}), not an `@AiTool` class. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-tool-ref.d.ts","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAgD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAmD,CAAC;AAE1F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,KAAK,EAAE,gBAAgB,CAAC;IACxB,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wGAAwG;AACxG,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC,2FAA2F;AAC3F,MAAM,MAAM,SAAS,GAAG,QAAQ,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,WAAW,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,IACnC,CAAC,SAAS,SAAS,EAAE,QAAQ,CAAC,KAAG,CAAC,CAQ3C;
|
|
1
|
+
{"version":3,"file":"ai-tool-ref.d.ts","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EA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tF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EACpC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAChE,qBAAqB,CAcvB"}
|
package/dist/src/ai-tool-ref.js
CHANGED
|
@@ -31,6 +31,13 @@ export function AiTool(options) {
|
|
|
31
31
|
return target;
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
/** Read the `@AiTool` decorator's stamped {@link AI_TOOL_META_KEY} metadata off a value, if present. */
|
|
35
|
+
function decoratorMeta(target) {
|
|
36
|
+
if (target === null || (typeof target !== 'function' && typeof target !== 'object')) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return target[AI_TOOL_META_KEY];
|
|
40
|
+
}
|
|
34
41
|
/** Read a class's tool metadata off its `static tool = { name, kind, … }` config, if any. */
|
|
35
42
|
function staticToolMeta(target) {
|
|
36
43
|
if (typeof target !== 'function')
|
|
@@ -41,30 +48,27 @@ function staticToolMeta(target) {
|
|
|
41
48
|
}
|
|
42
49
|
return undefined;
|
|
43
50
|
}
|
|
51
|
+
/** Resolve either authoring mechanism — `@AiTool` decorator or `static tool` — from one value. */
|
|
52
|
+
function metaOn(target) {
|
|
53
|
+
return decoratorMeta(target) ?? staticToolMeta(target);
|
|
54
|
+
}
|
|
44
55
|
/**
|
|
45
|
-
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported
|
|
56
|
+
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported:
|
|
46
57
|
*
|
|
47
58
|
* 1. The `@AiTool({ … })` decorator (stamps {@link AI_TOOL_META_KEY}).
|
|
48
59
|
* 2. A decorator-free `static tool = { name, kind, description, input, … }` config on the class — the
|
|
49
60
|
* same shape, mirroring `@adonis-agora/durable`'s `static workflow`. Preferred where you'd rather
|
|
50
61
|
* not rely on decorators.
|
|
51
62
|
*
|
|
52
|
-
* Accepts either the class itself or an instance
|
|
63
|
+
* Accepts either the class itself or an instance: each mechanism is tried on the value, then on its
|
|
64
|
+
* constructor (so an instance resolves the class's metadata).
|
|
53
65
|
*/
|
|
54
66
|
export function readAiToolMeta(target) {
|
|
55
67
|
if (target === null || (typeof target !== 'function' && typeof target !== 'object')) {
|
|
56
68
|
return undefined;
|
|
57
69
|
}
|
|
58
|
-
const direct = target[AI_TOOL_META_KEY];
|
|
59
|
-
if (direct !== undefined) {
|
|
60
|
-
return direct;
|
|
61
|
-
}
|
|
62
70
|
const ctor = target.constructor;
|
|
63
|
-
|
|
64
|
-
if (fromCtor !== undefined) {
|
|
65
|
-
return fromCtor;
|
|
66
|
-
}
|
|
67
|
-
return staticToolMeta(target) ?? staticToolMeta(ctor);
|
|
71
|
+
return metaOn(target) ?? metaOn(ctor);
|
|
68
72
|
}
|
|
69
73
|
/** Narrows an arbitrary module export to a branded functional tool for boot-time registration. */
|
|
70
74
|
export function isBrandedFunctionalTool(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-tool-ref.js","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAEvF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AA8B1F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,OAAO,CAAsB,MAAS,EAAK,EAAE;QAC3C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE;YAC9C,KAAK,EAAE,OAAO;YACd,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,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B,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;IACF,OAAO;QACL,CAAC,gBAAgB,CAAC,EAAE,IAAI;QACxB,IAAI;QACJ,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAU,EAAE,GAAG,CAAC,CAAC,EAAE;KAChF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural, dependency-free reader for the Agora runtime context — mirrors
|
|
3
|
+
* `@adonis-agora/authz`'s `agora/context.ts`. The Agora context library publishes a READ accessor
|
|
4
|
+
* on the well-known symbol slot. We never import that package; when the slot is absent (context not
|
|
5
|
+
* installed) the reader degrades to `undefined` and the caller fails closed.
|
|
6
|
+
*/
|
|
7
|
+
/** The symbol slot the Agora context library writes its read accessor into. */
|
|
8
|
+
export declare const AGORA_CONTEXT_ACCESSOR: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* The slice of the context accessor this package reads. `userRef` and `tenantId` are direct
|
|
11
|
+
* accessor fields (authkit writes them via the `set` slot); we never read `globalRoles` here —
|
|
12
|
+
* authz's `effectiveRoles` does that internally.
|
|
13
|
+
*/
|
|
14
|
+
export interface AgoraContextAccessor {
|
|
15
|
+
tenantId?: string;
|
|
16
|
+
userRef?: {
|
|
17
|
+
type?: string;
|
|
18
|
+
id?: string | number;
|
|
19
|
+
};
|
|
20
|
+
get?: () => unknown;
|
|
21
|
+
}
|
|
22
|
+
/** Read the active Agora context accessor from the global slot, if present. */
|
|
23
|
+
export declare function readContextAccessor(): AgoraContextAccessor | undefined;
|
|
24
|
+
//# sourceMappingURL=agora-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agora-context.d.ts","sourceRoot":"","sources":["../../../src/authz/agora-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,eAAwC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAClD,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC;CACrB;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,IAAI,oBAAoB,GAAG,SAAS,CAItE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural, dependency-free reader for the Agora runtime context — mirrors
|
|
3
|
+
* `@adonis-agora/authz`'s `agora/context.ts`. The Agora context library publishes a READ accessor
|
|
4
|
+
* on the well-known symbol slot. We never import that package; when the slot is absent (context not
|
|
5
|
+
* installed) the reader degrades to `undefined` and the caller fails closed.
|
|
6
|
+
*/
|
|
7
|
+
/** The symbol slot the Agora context library writes its read accessor into. */
|
|
8
|
+
export const AGORA_CONTEXT_ACCESSOR = Symbol.for('@agora/context:accessor');
|
|
9
|
+
/** Read the active Agora context accessor from the global slot, if present. */
|
|
10
|
+
export function readContextAccessor() {
|
|
11
|
+
const slot = globalThis[AGORA_CONTEXT_ACCESSOR];
|
|
12
|
+
if (slot == null || typeof slot !== 'object')
|
|
13
|
+
return undefined;
|
|
14
|
+
return slot;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=agora-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agora-context.js","sourceRoot":"","sources":["../../../src/authz/agora-context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAa5E,+EAA+E;AAC/E,MAAM,UAAU,mBAAmB;IACjC,MAAM,IAAI,GAAI,UAAsC,CAAC,sBAAsB,CAAC,CAAC;IAC7E,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC/D,OAAO,IAA4B,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ActorResolver } from '../spi/actor-resolver.js';
|
|
2
|
+
import type { Actor } from '../types.js';
|
|
3
|
+
import type { AuthzTenantScope } from './authz-tool-authorizer.js';
|
|
4
|
+
/**
|
|
5
|
+
* The structural slice of `@adonis-agora/authz`'s `AuthzService` this resolver needs: the user's
|
|
6
|
+
* effective roles (authz's union of global (context) ∪ app (`resolveRoles`) ∪ store (DB)). Typed
|
|
7
|
+
* structurally so `@adonis-agora/authz` stays an OPTIONAL lazy peer — zero import of the package.
|
|
8
|
+
*/
|
|
9
|
+
export interface AuthzRolesSourceLike {
|
|
10
|
+
effectiveRoles(user: unknown, scope?: AuthzTenantScope): Promise<string[]>;
|
|
11
|
+
}
|
|
12
|
+
/** Options for {@link AuthzActorResolver} / {@link authzActorResolver}. */
|
|
13
|
+
export interface AuthzActorResolverConfig {
|
|
14
|
+
/** The `@adonis-agora/authz` `AuthzService` (or any structural match) the resolver reads roles from. */
|
|
15
|
+
authz: AuthzRolesSourceLike;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An {@link ActorResolver} that reads the caller from the Agora context authkit populates
|
|
19
|
+
* (`userRef`, `tenantId`) and takes the caller's roles from authz (`effectiveRoles`). It ignores
|
|
20
|
+
* the transport `req` and reads the active Agora context store, so it needs no `ctx.auth` and is
|
|
21
|
+
* framework-agnostic.
|
|
22
|
+
*
|
|
23
|
+
* Security posture — FAIL-CLOSED: no `userRef.id` in context → throws (the provider replies 401).
|
|
24
|
+
* An identity is never fabricated. The context `userRef` is passed straight to `effectiveRoles`;
|
|
25
|
+
* authz reads its `.id`/`.type` and re-reads `globalRoles` from the same context, so global roles
|
|
26
|
+
* (e.g. `ADMIN`) land in the result with no extra wiring.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AuthzActorResolver implements ActorResolver {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(config: AuthzActorResolverConfig);
|
|
31
|
+
resolve(_req: unknown): Promise<Actor>;
|
|
32
|
+
}
|
|
33
|
+
/** Factory for {@link AuthzActorResolver}. */
|
|
34
|
+
export declare function authzActorResolver(config: AuthzActorResolverConfig): ActorResolver;
|
|
35
|
+
//# sourceMappingURL=authz-actor-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authz-actor-resolver.d.ts","sourceRoot":"","sources":["../../../src/authz/authz-actor-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC5E;AAED,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,wGAAwG;IACxG,KAAK,EAAE,oBAAoB,CAAC;CAC7B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,YAAW,aAAa;;gBAG1C,MAAM,EAAE,wBAAwB;IAItC,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;CAsB7C;AAED,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,aAAa,CAElF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readContextAccessor } from './agora-context.js';
|
|
2
|
+
/**
|
|
3
|
+
* An {@link ActorResolver} that reads the caller from the Agora context authkit populates
|
|
4
|
+
* (`userRef`, `tenantId`) and takes the caller's roles from authz (`effectiveRoles`). It ignores
|
|
5
|
+
* the transport `req` and reads the active Agora context store, so it needs no `ctx.auth` and is
|
|
6
|
+
* framework-agnostic.
|
|
7
|
+
*
|
|
8
|
+
* Security posture — FAIL-CLOSED: no `userRef.id` in context → throws (the provider replies 401).
|
|
9
|
+
* An identity is never fabricated. The context `userRef` is passed straight to `effectiveRoles`;
|
|
10
|
+
* authz reads its `.id`/`.type` and re-reads `globalRoles` from the same context, so global roles
|
|
11
|
+
* (e.g. `ADMIN`) land in the result with no extra wiring.
|
|
12
|
+
*/
|
|
13
|
+
export class AuthzActorResolver {
|
|
14
|
+
#authz;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.#authz = config.authz;
|
|
17
|
+
}
|
|
18
|
+
async resolve(_req) {
|
|
19
|
+
const accessor = readContextAccessor();
|
|
20
|
+
const ref = accessor?.userRef;
|
|
21
|
+
if (ref?.id === undefined || ref.id === null || String(ref.id).length === 0) {
|
|
22
|
+
throw new Error('authzActorResolver: no authenticated identity in @agora/context. The agent route must ' +
|
|
23
|
+
'sit behind authkit auth middleware (which populates the context), with the ' +
|
|
24
|
+
'@adonis-agora/context provider registered.');
|
|
25
|
+
}
|
|
26
|
+
const scope = accessor?.tenantId
|
|
27
|
+
? { tenantId: accessor.tenantId }
|
|
28
|
+
: undefined;
|
|
29
|
+
const roles = await this.#authz.effectiveRoles(ref, scope);
|
|
30
|
+
return {
|
|
31
|
+
id: String(ref.id),
|
|
32
|
+
roles,
|
|
33
|
+
...(accessor?.tenantId ? { tenantRef: accessor.tenantId } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Factory for {@link AuthzActorResolver}. */
|
|
38
|
+
export function authzActorResolver(config) {
|
|
39
|
+
return new AuthzActorResolver(config);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=authz-actor-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authz-actor-resolver.js","sourceRoot":"","sources":["../../../src/authz/authz-actor-resolver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAkBzD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IACpB,MAAM,CAAuB;IAEtC,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAa;QACzB,MAAM,QAAQ,GAAG,mBAAmB,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,QAAQ,EAAE,OAAO,CAAC;QAC9B,IAAI,GAAG,EAAE,EAAE,KAAK,SAAS,IAAI,GAAG,CAAC,EAAE,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,KAAK,CACb,wFAAwF;gBACtF,6EAA6E;gBAC7E,4CAA4C,CAC/C,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAiC,QAAQ,EAAE,QAAQ;YAC5D,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;YACjC,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAE3D,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,KAAK;YACL,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;IACJ,CAAC;CACF;AAED,8CAA8C;AAC9C,MAAM,UAAU,kBAAkB,CAAC,MAAgC;IACjE,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { AuthzToolAuthorizer, authzToolAuthorizer, defaultUserFromActor, } from './authz-tool-authorizer.js';
|
|
2
2
|
export type { AuthzToolAuthorizerConfig, AuthzServiceLike, AuthzTenantScope, } from './authz-tool-authorizer.js';
|
|
3
|
+
export { AuthzActorResolver, authzActorResolver } from './authz-actor-resolver.js';
|
|
4
|
+
export type { AuthzActorResolverConfig, AuthzRolesSourceLike } from './authz-actor-resolver.js';
|
|
3
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACnF,YAAY,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/src/authz/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authz/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/package.json
CHANGED