@nest-boot/auth 8.0.5-beta.3 → 8.0.5-beta.4
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/README.md +13 -7
- package/dist/abilities/auth.ability.d.ts +6 -0
- package/dist/abilities/{user.ability.js → auth.ability.js} +4 -4
- package/dist/abilities/auth.ability.js.map +1 -0
- package/dist/abilities/index.d.ts +1 -2
- package/dist/abilities/index.js +1 -2
- package/dist/abilities/index.js.map +1 -1
- package/dist/auth-module-options.interface.d.ts +3 -0
- package/dist/auth.guard.d.ts +3 -9
- package/dist/auth.guard.js +13 -38
- package/dist/auth.guard.js.map +1 -1
- package/dist/auth.module.js +0 -3
- package/dist/auth.module.js.map +1 -1
- package/dist/decorators/can.decorator.d.ts +3 -11
- package/dist/decorators/can.decorator.js +8 -14
- package/dist/decorators/can.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +0 -2
- package/dist/decorators/index.js +0 -2
- package/dist/decorators/index.js.map +1 -1
- package/dist/entities/account.entity.d.ts +1 -1
- package/dist/entities/account.entity.js +1 -1
- package/dist/entities/invitation.entity.d.ts +2 -0
- package/dist/entities/invitation.entity.js +9 -0
- package/dist/entities/invitation.entity.js.map +1 -1
- package/dist/entities/member.entity.d.ts +2 -0
- package/dist/entities/member.entity.js +9 -0
- package/dist/entities/member.entity.js.map +1 -1
- package/dist/entities/workspace-api-key.entity.d.ts +2 -0
- package/dist/entities/workspace-api-key.entity.js +9 -0
- package/dist/entities/workspace-api-key.entity.js.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/api-key-lifecycle.d.ts +14 -0
- package/dist/infrastructure/api-key-lifecycle.js +19 -0
- package/dist/infrastructure/api-key-lifecycle.js.map +1 -1
- package/dist/infrastructure/auth-ability.factory.d.ts +4 -9
- package/dist/infrastructure/auth-ability.factory.js +23 -21
- package/dist/infrastructure/auth-ability.factory.js.map +1 -1
- package/dist/infrastructure/auth-service.providers.js +9 -11
- package/dist/infrastructure/auth-service.providers.js.map +1 -1
- package/dist/infrastructure/request-identity.d.ts +16 -4
- package/dist/infrastructure/request-identity.js +61 -40
- package/dist/infrastructure/request-identity.js.map +1 -1
- package/dist/interfaces/ability-context.interface.d.ts +16 -0
- package/dist/interfaces/ability-context.interface.js +2 -0
- package/dist/interfaces/ability-context.interface.js.map +1 -0
- package/dist/interfaces/ability-rules.interface.d.ts +8 -2
- package/dist/interfaces/auth-module-user-options.interface.d.ts +0 -3
- package/dist/interfaces/auth-module-workspace-options.interface.d.ts +0 -3
- package/dist/interfaces/{user-can-metadata.interface.d.ts → can-metadata.interface.d.ts} +2 -2
- package/dist/interfaces/can-metadata.interface.js +2 -0
- package/dist/interfaces/can-metadata.interface.js.map +1 -0
- package/dist/permission.constants.d.ts +2 -4
- package/dist/permission.constants.js +2 -4
- package/dist/permission.constants.js.map +1 -1
- package/dist/resolvers/auth.resolver.d.ts +2 -4
- package/dist/resolvers/auth.resolver.js +5 -16
- package/dist/resolvers/auth.resolver.js.map +1 -1
- package/dist/services/account.service.d.ts +1 -3
- package/dist/services/account.service.js +4 -7
- package/dist/services/account.service.js.map +1 -1
- package/dist/services/invitation.service.d.ts +1 -3
- package/dist/services/invitation.service.js +32 -32
- package/dist/services/invitation.service.js.map +1 -1
- package/dist/services/member.service.d.ts +1 -3
- package/dist/services/member.service.js +50 -51
- package/dist/services/member.service.js.map +1 -1
- package/dist/services/session.service.d.ts +1 -4
- package/dist/services/session.service.js +11 -15
- package/dist/services/session.service.js.map +1 -1
- package/dist/services/user-api-key.service.d.ts +3 -7
- package/dist/services/user-api-key.service.js +52 -73
- package/dist/services/user-api-key.service.js.map +1 -1
- package/dist/services/user-deletion.service.js.map +1 -1
- package/dist/services/user.service.d.ts +1 -3
- package/dist/services/user.service.js +38 -42
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/workspace-api-key.service.d.ts +3 -7
- package/dist/services/workspace-api-key.service.js +50 -71
- package/dist/services/workspace-api-key.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +1 -3
- package/dist/services/workspace.service.js +22 -24
- package/dist/services/workspace.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/build-ability-callback.type.d.ts +4 -0
- package/dist/types/build-ability-callback.type.js +2 -0
- package/dist/types/build-ability-callback.type.js.map +1 -0
- package/dist/utils/api-key-permissions.util.d.ts +2 -0
- package/dist/utils/api-key-permissions.util.js +9 -0
- package/dist/utils/api-key-permissions.util.js.map +1 -1
- package/dist/utils/assert-can.util.d.ts +3 -0
- package/dist/utils/assert-can.util.js +8 -0
- package/dist/utils/assert-can.util.js.map +1 -0
- package/dist/utils/build-request-ability.util.d.ts +3 -6
- package/dist/utils/build-request-ability.util.js +25 -15
- package/dist/utils/build-request-ability.util.js.map +1 -1
- package/dist/utils/can.util.d.ts +2 -3
- package/dist/utils/can.util.js +9 -7
- package/dist/utils/can.util.js.map +1 -1
- package/dist/utils/extend-ability.util.d.ts +5 -1
- package/dist/utils/extend-ability.util.js +13 -6
- package/dist/utils/extend-ability.util.js.map +1 -1
- package/dist/utils/get-ability.util.d.ts +5 -0
- package/dist/utils/get-ability.util.js +20 -0
- package/dist/utils/get-ability.util.js.map +1 -0
- package/dist/utils/permission-grants.util.d.ts +9 -0
- package/dist/utils/permission-grants.util.js +25 -0
- package/dist/utils/permission-grants.util.js.map +1 -0
- package/package.json +9 -9
- package/dist/abilities/user.ability.d.ts +0 -8
- package/dist/abilities/user.ability.js.map +0 -1
- package/dist/abilities/workspace.ability.d.ts +0 -8
- package/dist/abilities/workspace.ability.js +0 -13
- package/dist/abilities/workspace.ability.js.map +0 -1
- package/dist/decorators/user-can.decorator.d.ts +0 -13
- package/dist/decorators/user-can.decorator.js +0 -21
- package/dist/decorators/user-can.decorator.js.map +0 -1
- package/dist/decorators/workspace-can.decorator.d.ts +0 -13
- package/dist/decorators/workspace-can.decorator.js +0 -21
- package/dist/decorators/workspace-can.decorator.js.map +0 -1
- package/dist/interfaces/can-options.interface.d.ts +0 -5
- package/dist/interfaces/can-options.interface.js +0 -2
- package/dist/interfaces/can-options.interface.js.map +0 -1
- package/dist/interfaces/user-can-metadata.interface.js +0 -2
- package/dist/interfaces/user-can-metadata.interface.js.map +0 -1
- package/dist/interfaces/workspace-can-metadata.interface.d.ts +0 -9
- package/dist/interfaces/workspace-can-metadata.interface.js +0 -2
- package/dist/interfaces/workspace-can-metadata.interface.js.map +0 -1
- package/dist/services/access-control.service.d.ts +0 -54
- package/dist/services/access-control.service.js +0 -208
- package/dist/services/access-control.service.js.map +0 -1
- package/dist/types/build-user-ability-callback.type.d.ts +0 -10
- package/dist/types/build-user-ability-callback.type.js +0 -2
- package/dist/types/build-user-ability-callback.type.js.map +0 -1
- package/dist/types/build-workspace-ability-callback.type.d.ts +0 -10
- package/dist/types/build-workspace-ability-callback.type.js +0 -2
- package/dist/types/build-workspace-ability-callback.type.js.map +0 -1
- package/dist/utils/get-user-ability.util.d.ts +0 -3
- package/dist/utils/get-user-ability.util.js +0 -14
- package/dist/utils/get-user-ability.util.js.map +0 -1
- package/dist/utils/get-workspace-ability.util.d.ts +0 -3
- package/dist/utils/get-workspace-ability.util.js +0 -14
- package/dist/utils/get-workspace-ability.util.js.map +0 -1
- package/dist/utils/user-can.util.d.ts +0 -3
- package/dist/utils/user-can.util.js +0 -9
- package/dist/utils/user-can.util.js.map +0 -1
- package/dist/utils/workspace-can.util.d.ts +0 -3
- package/dist/utils/workspace-can.util.js +0 -10
- package/dist/utils/workspace-can.util.js.map +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AbilityContext } from "../interfaces/ability-context.interface.js";
|
|
2
|
+
import type { AbilityRules } from "../interfaces/ability-rules.interface.js";
|
|
3
|
+
/** Synchronously extends one request ability with permission-bound business rules. */
|
|
4
|
+
export type BuildAbilityCallback<UserPermission extends string = string, WorkspacePermission extends string = string> = (rules: AbilityRules<UserPermission, WorkspacePermission>, context: AbilityContext<UserPermission, WorkspacePermission>) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-ability-callback.type.js","sourceRoot":"","sources":["../../src/types/build-ability-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -5,3 +5,5 @@ export declare function resolveApiKeyPermissionCatalog(options: AuthModuleOption
|
|
|
5
5
|
readonly allowed: readonly string[];
|
|
6
6
|
readonly defaults: readonly string[];
|
|
7
7
|
};
|
|
8
|
+
/** Applies scope defaults, validates catalog values, and enforces the configured key ceiling. @internal */
|
|
9
|
+
export declare function normalizeApiKeyPermissions(options: AuthModuleOptions, scope: "user" | "workspace", requested: readonly string[] | null | undefined): string[];
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { normalizeAuthPermissions } from "./auth-role.util.js";
|
|
2
|
+
import { assertPermissionCeiling } from "./permission-grants.util.js";
|
|
1
3
|
import { resolveAuthCatalog } from "./resolve-auth-catalog.util.js";
|
|
2
4
|
const catalogs = new WeakMap();
|
|
3
5
|
/** Returns the owner's complete enum catalog and the subset configurable on API keys. */
|
|
@@ -23,4 +25,11 @@ export function resolveApiKeyPermissionCatalog(options, scope) {
|
|
|
23
25
|
catalogs.set(options, scopes);
|
|
24
26
|
return catalog;
|
|
25
27
|
}
|
|
28
|
+
/** Applies scope defaults, validates catalog values, and enforces the configured key ceiling. @internal */
|
|
29
|
+
export function normalizeApiKeyPermissions(options, scope, requested) {
|
|
30
|
+
const { permissions, allowed, defaults } = resolveApiKeyPermissionCatalog(options, scope);
|
|
31
|
+
const normalized = normalizeAuthPermissions(requested === undefined ? defaults : (requested ?? []), permissions, scope === "user" ? "User API key" : "Workspace API key");
|
|
32
|
+
assertPermissionCeiling(normalized, allowed, "API key permissions exceed configured allowedPermissions");
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
26
35
|
//# sourceMappingURL=api-key-permissions.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-permissions.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GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;YACtB,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,kBAAkB,IAAI,EAAE,CAAC;SACvD,CAAC;QACF,OAAO,EAAE,MAAM,CAAC,MAAM,CACpB,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAC9D;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,0BAA0B,CACxC,OAA0B,EAC1B,KAA2B,EAC3B,SAA+C;IAE/C,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,8BAA8B,CACvE,OAAO,EACP,KAAK,CACN,CAAC;IACF,MAAM,UAAU,GAAG,wBAAwB,CACzC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EACtD,WAAW,EACX,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,mBAAmB,CACxD,CAAC;IACF,uBAAuB,CACrB,UAAU,EACV,OAAO,EACP,0DAA0D,CAC3D,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ForbiddenException } from "@nestjs/common";
|
|
2
|
+
import { can } from "./can.util.js";
|
|
3
|
+
/** Throws unless the current request ability permits the action, object, or field. */
|
|
4
|
+
export function assertCan(action, subject, field) {
|
|
5
|
+
if (!can(action, subject, field))
|
|
6
|
+
throw new ForbiddenException(`You are not allowed to ${action} this resource`);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=assert-can.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-can.util.js","sourceRoot":"","sources":["../../src/utils/assert-can.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,sFAAsF;AACtF,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,OAAgB,EAChB,KAAc;IAEd,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;QAC9B,MAAM,IAAI,kBAAkB,CAC1B,0BAA0B,MAAM,gBAAgB,CACjD,CAAC;AACN,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { WorkspaceAbility } from "../abilities/workspace.ability.js";
|
|
1
|
+
import type { AuthAbility } from "../abilities/auth.ability.js";
|
|
3
2
|
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
4
|
-
/** Builds
|
|
5
|
-
export declare function
|
|
6
|
-
/** Builds workspace abilities only while the request has an active workspace identity. */
|
|
7
|
-
export declare function buildRequestWorkspaceAbility(options: AuthModuleOptions): WorkspaceAbility | null;
|
|
3
|
+
/** Builds one ability from the current identity and credential-limited permission snapshot. */
|
|
4
|
+
export declare function buildRequestAbility(options: AuthModuleOptions): AuthAbility;
|
|
@@ -6,20 +6,30 @@ import { WorkspaceApiKey } from "../entities/workspace-api-key.entity.js";
|
|
|
6
6
|
import { AuthAbilityFactory } from "../infrastructure/auth-ability.factory.js";
|
|
7
7
|
import { getCurrentApiKey } from "./get-current-api-key.util.js";
|
|
8
8
|
import { resolveRequestPermissions } from "./resolve-request-permissions.util.js";
|
|
9
|
-
/** Builds
|
|
10
|
-
export function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
/** Builds one ability from the current identity and credential-limited permission snapshot. */
|
|
10
|
+
export function buildRequestAbility(options) {
|
|
11
|
+
const apiKey = getCurrentApiKey();
|
|
12
|
+
const workspaceKey = apiKey instanceof WorkspaceApiKey;
|
|
13
|
+
const user = workspaceKey ? null : (RequestContext.get(User) ?? null);
|
|
14
|
+
const selectedWorkspace = RequestContext.get(Workspace);
|
|
15
|
+
const currentMember = RequestContext.get(Member);
|
|
16
|
+
const member = user &&
|
|
17
|
+
currentMember?.status === "ACTIVE" &&
|
|
18
|
+
currentMember.user?.id === user.id &&
|
|
19
|
+
currentMember.workspace?.id === selectedWorkspace?.id
|
|
20
|
+
? currentMember
|
|
21
|
+
: null;
|
|
22
|
+
const workspace = selectedWorkspace &&
|
|
23
|
+
(member || (workspaceKey && apiKey.workspace?.id === selectedWorkspace.id))
|
|
24
|
+
? selectedWorkspace
|
|
25
|
+
: null;
|
|
26
|
+
const permissions = resolveRequestPermissions(options);
|
|
27
|
+
return AuthAbilityFactory.createAbility({
|
|
28
|
+
user,
|
|
29
|
+
workspace,
|
|
30
|
+
member,
|
|
31
|
+
userPermissions: user ? permissions.user : [],
|
|
32
|
+
workspacePermissions: workspace ? permissions.workspace : [],
|
|
33
|
+
}, options);
|
|
24
34
|
}
|
|
25
35
|
//# sourceMappingURL=build-request-ability.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-request-ability.util.js","sourceRoot":"","sources":["../../src/utils/build-request-ability.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"build-request-ability.util.js","sourceRoot":"","sources":["../../src/utils/build-request-ability.util.ts"],"names":[],"m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CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,IAAI,CAAC;IACX,MAAM,WAAW,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACvD,OAAO,kBAAkB,CAAC,aAAa,CACrC;QACE,IAAI;QACJ,SAAS;QACT,MAAM;QACN,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QAC7C,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;KAC7D,EACD,OAAO,CACR,CAAC;AACJ,CAAC"}
|
package/dist/utils/can.util.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Subject } from "@casl/ability";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function can(action: string, subject: Subject, options?: CanOptions): boolean;
|
|
2
|
+
/** Checks an action, object, or field against the current request ability. */
|
|
3
|
+
export declare function can(action: string, subject: Subject, field?: string): boolean;
|
package/dist/utils/can.util.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { readRequestAbility } from "./get-ability.util.js";
|
|
2
|
+
/** Checks an action, object, or field against the current request ability. */
|
|
3
|
+
export function can(action, subject, field) {
|
|
4
|
+
const ability = readRequestAbility();
|
|
5
|
+
if (!ability)
|
|
6
|
+
return false;
|
|
7
|
+
return field === undefined
|
|
8
|
+
? ability.can(action, subject)
|
|
9
|
+
: ability.can(action, subject, field);
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=can.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,8EAA8E;AAC9E,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,KAAc;IAClE,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;QAC9B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { Ability, AbilityBuilder, AbilityTuple, MongoQuery } from "@casl/ability";
|
|
2
|
+
import type { AbilityContext } from "../interfaces/ability-context.interface.js";
|
|
2
3
|
import type { AbilityRules } from "../interfaces/ability-rules.interface.js";
|
|
3
4
|
/** Runs synchronous extensions without exposing the builder, mutable rules, or a build function. */
|
|
4
|
-
export declare function extendAbility(builder: AbilityBuilder<Ability<AbilityTuple, MongoQuery>>,
|
|
5
|
+
export declare function extendAbility(builder: AbilityBuilder<Ability<AbilityTuple, MongoQuery>>, context: AbilityContext, catalog: {
|
|
6
|
+
user: readonly string[];
|
|
7
|
+
workspace: readonly string[];
|
|
8
|
+
}, configure: (rules: AbilityRules) => unknown): void;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { entities } from "../entities/index.js";
|
|
2
2
|
/** Runs synchronous extensions without exposing the builder, mutable rules, or a build function. */
|
|
3
|
-
export function extendAbility(builder,
|
|
4
|
-
const granted = new Set(permissions);
|
|
5
|
-
const known = new Set(catalog);
|
|
3
|
+
export function extendAbility(builder, context, catalog, configure) {
|
|
6
4
|
const restrictions = [];
|
|
7
5
|
let active = true;
|
|
8
6
|
const assertActive = () => {
|
|
@@ -12,8 +10,17 @@ export function extendAbility(builder, permissions, catalog, configure) {
|
|
|
12
10
|
const rules = Object.freeze({
|
|
13
11
|
can(permission, ...rule) {
|
|
14
12
|
assertActive();
|
|
15
|
-
if (!
|
|
16
|
-
|
|
13
|
+
if (!permission ||
|
|
14
|
+
typeof permission !== "object" ||
|
|
15
|
+
(typeof permission.user === "string") ===
|
|
16
|
+
(typeof permission.workspace === "string"))
|
|
17
|
+
throw new Error("Ability grants require exactly one user or workspace permission");
|
|
18
|
+
const scope = typeof permission.user === "string" ? "user" : "workspace";
|
|
19
|
+
const name = permission.user ?? permission.workspace;
|
|
20
|
+
if (typeof name !== "string")
|
|
21
|
+
throw new Error("Ability grants require a permission name");
|
|
22
|
+
if (!catalog[scope].includes(name))
|
|
23
|
+
throw new Error(`Unknown ${scope} ability permission: ${name}`);
|
|
17
24
|
const subjects = Array.isArray(rule[1]) ? rule[1] : [rule[1]];
|
|
18
25
|
if (subjects.some((target) => target === "all" ||
|
|
19
26
|
entities.some((entity) => typeof target === "string"
|
|
@@ -23,7 +30,7 @@ export function extendAbility(builder, permissions, catalog, configure) {
|
|
|
23
30
|
("modelName" in target && target.modelName === entity.name) ||
|
|
24
31
|
target.prototype instanceof entity)))
|
|
25
32
|
throw new Error("Custom grants cannot target built-in auth subjects or all");
|
|
26
|
-
if (
|
|
33
|
+
if (context[scope === "user" ? "userPermissions" : "workspacePermissions"].includes(name))
|
|
27
34
|
addRule(builder, copyRule(rule), false);
|
|
28
35
|
},
|
|
29
36
|
cannot(...rule) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extend-ability.util.js","sourceRoot":"","sources":["../../src/utils/extend-ability.util.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"extend-ability.util.js","sourceRoot":"","sources":["../../src/utils/extend-ability.util.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAI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E,OAAO,EAAE,kBAAkB,EAAE,UAAU,CAE/C,EACD,QAAiB;IAEjB,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IACpD,IACE,OAAO,kBAAkB,KAAK,QAAQ;QACtC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,EACjC,CAAC;QACD,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,IAAwC;IAExC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAC/B,KAAK,GAAG,CAAC;QACP,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACpB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;YACZ,CAAC,CAAC,KAAK;QACT,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CACW,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AuthAbility } from "../abilities/auth.ability.js";
|
|
2
|
+
/** Reads the prepared ability only while its authenticated identity is available. @internal */
|
|
3
|
+
export declare function readRequestAbility(): AuthAbility | null;
|
|
4
|
+
/** Reads the current request ability, rejecting missing identity or authorization context. */
|
|
5
|
+
export declare function getAbility(): AuthAbility;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RequestContext } from "@nest-boot/request-context";
|
|
2
|
+
import { ForbiddenException } from "@nestjs/common";
|
|
3
|
+
import { AuthAbility } from "../abilities/auth.ability.js";
|
|
4
|
+
import { User } from "../entities/user.entity.js";
|
|
5
|
+
import { getCurrentApiKey } from "./get-current-api-key.util.js";
|
|
6
|
+
/** Reads the prepared ability only while its authenticated identity is available. @internal */
|
|
7
|
+
export function readRequestAbility() {
|
|
8
|
+
if (!RequestContext.isActive() ||
|
|
9
|
+
(!RequestContext.get(User) && !getCurrentApiKey()))
|
|
10
|
+
return null;
|
|
11
|
+
return RequestContext.get(AuthAbility) ?? null;
|
|
12
|
+
}
|
|
13
|
+
/** Reads the current request ability, rejecting missing identity or authorization context. */
|
|
14
|
+
export function getAbility() {
|
|
15
|
+
const ability = readRequestAbility();
|
|
16
|
+
if (!ability)
|
|
17
|
+
throw new ForbiddenException("Permission ability is not available");
|
|
18
|
+
return ability;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=get-ability.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-ability.util.js","sourceRoot":"","sources":["../../src/utils/get-ability.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,+FAA+F;AAC/F,MAAM,UAAU,kBAAkB;IAChC,IACE,CAAC,cAAc,CAAC,QAAQ,EAAE;QAC1B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAElD,OAAO,IAAI,CAAC;IACd,OAAO,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;AACjD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
2
|
+
/** Checks delegation against the shared, credential-limited permission snapshot. @internal */
|
|
3
|
+
export declare function canGrantPermissions(options: AuthModuleOptions, scope: "user" | "workspace", requested: readonly string[]): boolean;
|
|
4
|
+
/** Rejects delegation outside the caller's effective permission source. @internal */
|
|
5
|
+
export declare function assertCanGrantPermissions(options: AuthModuleOptions, scope: "user" | "workspace", requested: readonly string[]): void;
|
|
6
|
+
/** Rejects access to or delegation of keys broader than the authenticating credential. @internal */
|
|
7
|
+
export declare function assertApiKeyPermissionCeiling(options: AuthModuleOptions, requested: readonly string[]): void;
|
|
8
|
+
/** Shared subset check for configured, owner, and credential permission ceilings. @internal */
|
|
9
|
+
export declare function assertPermissionCeiling(requested: readonly string[], allowed: readonly string[], message: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ForbiddenException } from "@nestjs/common";
|
|
2
|
+
import { resolveRequestPermissions } from "./resolve-request-permissions.util.js";
|
|
3
|
+
/** Checks delegation against the shared, credential-limited permission snapshot. @internal */
|
|
4
|
+
export function canGrantPermissions(options, scope, requested) {
|
|
5
|
+
const allowed = new Set(resolveRequestPermissions(options)[scope]);
|
|
6
|
+
return requested.every((permission) => allowed.has(permission));
|
|
7
|
+
}
|
|
8
|
+
/** Rejects delegation outside the caller's effective permission source. @internal */
|
|
9
|
+
export function assertCanGrantPermissions(options, scope, requested) {
|
|
10
|
+
assertPermissionCeiling(requested, resolveRequestPermissions(options)[scope], `${scope === "user" ? "User" : "Workspace"} permissions exceed issuer permissions`);
|
|
11
|
+
}
|
|
12
|
+
/** Rejects access to or delegation of keys broader than the authenticating credential. @internal */
|
|
13
|
+
export function assertApiKeyPermissionCeiling(options, requested) {
|
|
14
|
+
const ceiling = resolveRequestPermissions(options).apiKey;
|
|
15
|
+
if (ceiling !== null)
|
|
16
|
+
assertPermissionCeiling(requested, ceiling, "API key permissions exceed authenticating API key permissions");
|
|
17
|
+
}
|
|
18
|
+
/** Shared subset check for configured, owner, and credential permission ceilings. @internal */
|
|
19
|
+
export function assertPermissionCeiling(requested, allowed, message) {
|
|
20
|
+
const permissions = new Set(allowed);
|
|
21
|
+
const excessive = requested.filter((permission) => !permissions.has(permission));
|
|
22
|
+
if (excessive.length)
|
|
23
|
+
throw new ForbiddenException(`${message}: ${excessive.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=permission-grants.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-grants.util.js","sourceRoot":"","sources":["../../src/utils/permission-grants.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,8FAA8F;AAC9F,MAAM,UAAU,mBAAmB,CACjC,OAA0B,EAC1B,KAA2B,EAC3B,SAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,yBAAyB,CACvC,OAA0B,EAC1B,KAA2B,EAC3B,SAA4B;IAE5B,uBAAuB,CACrB,SAAS,EACT,yBAAyB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,EACzC,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,wCAAwC,CACnF,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,6BAA6B,CAC3C,OAA0B,EAC1B,SAA4B;IAE5B,MAAM,OAAO,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC1D,IAAI,OAAO,KAAK,IAAI;QAClB,uBAAuB,CACrB,SAAS,EACT,OAAO,EACP,+DAA+D,CAChE,CAAC;AACN,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,uBAAuB,CACrC,SAA4B,EAC5B,OAA0B,EAC1B,OAAe;IAEf,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAChC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAC7C,CAAC;IACF,IAAI,SAAS,CAAC,MAAM;QAClB,MAAM,IAAI,kBAAkB,CAAC,GAAG,OAAO,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/auth",
|
|
3
|
-
"version": "8.0.5-beta.
|
|
3
|
+
"version": "8.0.5-beta.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/nest-boot/nest-boot.git",
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
"@nestjs/graphql": "^14.0.0",
|
|
52
52
|
"graphql": "^16.11.0",
|
|
53
53
|
"zod": "^4.3.6",
|
|
54
|
-
"@nest-boot/eslint-config": "^8.0.1-beta.0",
|
|
55
54
|
"@nest-boot/eslint-plugin": "^8.0.1-beta.0",
|
|
55
|
+
"@nest-boot/eslint-config": "^8.0.1-beta.0",
|
|
56
56
|
"@nest-boot/hash": "^8.0.1-beta.0",
|
|
57
|
-
"@nest-boot/graphql-connection": "^8.0.1-beta.3",
|
|
58
57
|
"@nest-boot/mailer": "^8.0.1-beta.0",
|
|
58
|
+
"@nest-boot/graphql-connection": "^8.0.1-beta.3",
|
|
59
59
|
"@nest-boot/middleware": "^8.0.1-beta.0",
|
|
60
60
|
"@nest-boot/request-context": "^8.0.1-beta.0",
|
|
61
|
-
"@nest-boot/validator": "^8.0.4-beta.0",
|
|
62
61
|
"@nest-boot/tsconfig": "^8.0.0-beta.4",
|
|
63
|
-
"@nest-boot/graphql": "^8.0.1-beta.0"
|
|
62
|
+
"@nest-boot/graphql": "^8.0.1-beta.0",
|
|
63
|
+
"@nest-boot/validator": "^8.0.4-beta.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@casl/ability": "^7.0.0",
|
|
@@ -76,13 +76,13 @@
|
|
|
76
76
|
"@nestjs/graphql": "^14.0.0",
|
|
77
77
|
"graphql": "^16.0.0",
|
|
78
78
|
"zod": "^4.0.0",
|
|
79
|
+
"@nest-boot/graphql-connection": "^8.0.1-beta.3",
|
|
79
80
|
"@nest-boot/hash": "^8.0.1-beta.0",
|
|
80
81
|
"@nest-boot/mailer": "^8.0.1-beta.0",
|
|
81
|
-
"@nest-boot/request-context": "^8.0.1-beta.0",
|
|
82
|
-
"@nest-boot/graphql-connection": "^8.0.1-beta.3",
|
|
83
|
-
"@nest-boot/validator": "^8.0.4-beta.0",
|
|
84
82
|
"@nest-boot/middleware": "^8.0.1-beta.0",
|
|
85
|
-
"@nest-boot/
|
|
83
|
+
"@nest-boot/request-context": "^8.0.1-beta.0",
|
|
84
|
+
"@nest-boot/graphql": "^8.0.1-beta.0",
|
|
85
|
+
"@nest-boot/validator": "^8.0.4-beta.0"
|
|
86
86
|
},
|
|
87
87
|
"publishConfig": {
|
|
88
88
|
"access": "public"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Ability, type AbilityOptions, type AbilityTuple, type MongoQuery, type RawRuleFrom } from "@casl/ability";
|
|
2
|
-
/** CASL ability containing user-scoped authorization rules. */
|
|
3
|
-
export declare class UserAbility extends Ability<AbilityTuple, MongoQuery> {
|
|
4
|
-
/** Keeps user and workspace abilities nominally distinct. */
|
|
5
|
-
private readonly userAbilityBrand;
|
|
6
|
-
/** Creates a user ability with CASL's Mongo-style condition matching. */
|
|
7
|
-
constructor(rules?: RawRuleFrom<AbilityTuple, MongoQuery>[], options?: AbilityOptions<AbilityTuple, MongoQuery>);
|
|
8
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.ability.js","sourceRoot":"","sources":["../../src/abilities/user.ability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGP,mBAAmB,EAEnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAEvB,+DAA+D;AAC/D,MAAM,OAAO,WAAY,SAAQ,OAAiC;IAIhE,yEAAyE;IACzE,YACE,QAAiD,EAAE,EACnD,UAAoD,EAAE;QAEtD,KAAK,CAAC,KAAK,EAAE;YACX,iBAAiB,EAAE,iBAAiB;YACpC,YAAY,EAAE,mBAAmB;YACjC,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Ability, type AbilityOptions, type AbilityTuple, type MongoQuery, type RawRuleFrom } from "@casl/ability";
|
|
2
|
-
/** CASL ability containing workspace-scoped authorization rules. */
|
|
3
|
-
export declare class WorkspaceAbility extends Ability<AbilityTuple, MongoQuery> {
|
|
4
|
-
/** Keeps workspace and user abilities nominally distinct. */
|
|
5
|
-
private readonly workspaceAbilityBrand;
|
|
6
|
-
/** Creates a workspace ability with CASL's Mongo-style condition matching. */
|
|
7
|
-
constructor(rules?: RawRuleFrom<AbilityTuple, MongoQuery>[], options?: AbilityOptions<AbilityTuple, MongoQuery>);
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Ability, fieldPatternMatcher, mongoQueryMatcher, } from "@casl/ability";
|
|
2
|
-
/** CASL ability containing workspace-scoped authorization rules. */
|
|
3
|
-
export class WorkspaceAbility extends Ability {
|
|
4
|
-
/** Creates a workspace ability with CASL's Mongo-style condition matching. */
|
|
5
|
-
constructor(rules = [], options = {}) {
|
|
6
|
-
super(rules, {
|
|
7
|
-
conditionsMatcher: mongoQueryMatcher,
|
|
8
|
-
fieldMatcher: fieldPatternMatcher,
|
|
9
|
-
...options,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=workspace.ability.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.ability.js","sourceRoot":"","sources":["../../src/abilities/workspace.ability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGP,mBAAmB,EAEnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAEvB,oEAAoE;AACpE,MAAM,OAAO,gBAAiB,SAAQ,OAAiC;IAIrE,8EAA8E;IAC9E,YACE,QAAiD,EAAE,EACnD,UAAoD,EAAE;QAEtD,KAAK,CAAC,KAAK,EAAE;YACX,iBAAiB,EAAE,iBAAiB;YACpC,YAAY,EAAE,mBAAmB;YACjC,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
import type { CustomDecorator } from "@nestjs/common";
|
|
3
|
-
import { USER_CAN_METADATA } from "../permission.constants.js";
|
|
4
|
-
import type { CanSubject } from "../types/can-subject.type.js";
|
|
5
|
-
/**
|
|
6
|
-
* Declares a permission required in the user authorization scope. When this
|
|
7
|
-
* decorator is repeated, every declared permission must be allowed.
|
|
8
|
-
*
|
|
9
|
-
* @param action - Permission action that must be allowed.
|
|
10
|
-
* @param subject - Permission subject type or subject resolver factory to check.
|
|
11
|
-
* @returns Nest custom metadata decorator.
|
|
12
|
-
*/
|
|
13
|
-
export declare function UserCan<T extends Subject = Subject>(action: string, subject: CanSubject<T>): CustomDecorator<typeof USER_CAN_METADATA>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { USER_CAN_METADATA } from "../permission.constants.js";
|
|
2
|
-
import { appendMetadata } from "../utils/append-metadata.util.js";
|
|
3
|
-
/**
|
|
4
|
-
* Declares a permission required in the user authorization scope. When this
|
|
5
|
-
* decorator is repeated, every declared permission must be allowed.
|
|
6
|
-
*
|
|
7
|
-
* @param action - Permission action that must be allowed.
|
|
8
|
-
* @param subject - Permission subject type or subject resolver factory to check.
|
|
9
|
-
* @returns Nest custom metadata decorator.
|
|
10
|
-
*/
|
|
11
|
-
export function UserCan(action, subject) {
|
|
12
|
-
if (!subject) {
|
|
13
|
-
throw new TypeError("Permission subject is required.");
|
|
14
|
-
}
|
|
15
|
-
const metadata = {
|
|
16
|
-
action,
|
|
17
|
-
subject,
|
|
18
|
-
};
|
|
19
|
-
return appendMetadata(USER_CAN_METADATA, metadata);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=user-can.decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-can.decorator.js","sourceRoot":"","sources":["../../src/decorators/user-can.decorator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CACrB,MAAc,EACd,OAAsB;IAEtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,QAAQ,GAAuB;QACnC,MAAM;QACN,OAAO;KACR,CAAC;IAEF,OAAO,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
import type { CustomDecorator } from "@nestjs/common";
|
|
3
|
-
import { WORKSPACE_CAN_METADATA } from "../permission.constants.js";
|
|
4
|
-
import type { CanSubject } from "../types/can-subject.type.js";
|
|
5
|
-
/**
|
|
6
|
-
* Declares a permission required in the workspace authorization scope. When
|
|
7
|
-
* this decorator is repeated, every declared permission must be allowed.
|
|
8
|
-
*
|
|
9
|
-
* @param action - Permission action that must be allowed.
|
|
10
|
-
* @param subject - Permission subject type or subject resolver factory to check.
|
|
11
|
-
* @returns Nest custom metadata decorator.
|
|
12
|
-
*/
|
|
13
|
-
export declare function WorkspaceCan<T extends Subject = Subject>(action: string, subject: CanSubject<T>): CustomDecorator<typeof WORKSPACE_CAN_METADATA>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { WORKSPACE_CAN_METADATA } from "../permission.constants.js";
|
|
2
|
-
import { appendMetadata } from "../utils/append-metadata.util.js";
|
|
3
|
-
/**
|
|
4
|
-
* Declares a permission required in the workspace authorization scope. When
|
|
5
|
-
* this decorator is repeated, every declared permission must be allowed.
|
|
6
|
-
*
|
|
7
|
-
* @param action - Permission action that must be allowed.
|
|
8
|
-
* @param subject - Permission subject type or subject resolver factory to check.
|
|
9
|
-
* @returns Nest custom metadata decorator.
|
|
10
|
-
*/
|
|
11
|
-
export function WorkspaceCan(action, subject) {
|
|
12
|
-
if (!subject) {
|
|
13
|
-
throw new TypeError("Permission subject is required.");
|
|
14
|
-
}
|
|
15
|
-
const metadata = {
|
|
16
|
-
action,
|
|
17
|
-
subject,
|
|
18
|
-
};
|
|
19
|
-
return appendMetadata(WORKSPACE_CAN_METADATA, metadata);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=workspace-can.decorator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-can.decorator.js","sourceRoot":"","sources":["../../src/decorators/workspace-can.decorator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,OAAsB;IAEtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,QAAQ,GAA4B;QACxC,MAAM;QACN,OAAO;KACR,CAAC;IAEF,OAAO,cAAc,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"can-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/can-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-can-metadata.interface.js","sourceRoot":"","sources":["../../src/interfaces/user-can-metadata.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
import type { CanSubject } from "../types/can-subject.type.js";
|
|
3
|
-
/** Internal route metadata produced by the `WorkspaceCan` decorator. */
|
|
4
|
-
export interface WorkspaceCanMetadata<T extends Subject = Subject> {
|
|
5
|
-
/** Permission action that must be allowed. */
|
|
6
|
-
action: string;
|
|
7
|
-
/** Permission subject type or subject resolver factory to check. */
|
|
8
|
-
subject: CanSubject<T>;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-can-metadata.interface.js","sourceRoot":"","sources":["../../src/interfaces/workspace-can-metadata.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
import { UserAbility } from "../abilities/user.ability.js";
|
|
3
|
-
import { WorkspaceAbility } from "../abilities/workspace.ability.js";
|
|
4
|
-
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
5
|
-
import { Member } from "../entities/member.entity.js";
|
|
6
|
-
import { Session } from "../entities/session.entity.js";
|
|
7
|
-
import { User } from "../entities/user.entity.js";
|
|
8
|
-
import { Workspace } from "../entities/workspace.entity.js";
|
|
9
|
-
import type { ApiKey } from "../types/api-key.type.js";
|
|
10
|
-
/** Enforces user and workspace permissions prepared for the current request. */
|
|
11
|
-
export declare class AccessControlService {
|
|
12
|
-
private readonly options;
|
|
13
|
-
/** Creates the authorization service. */
|
|
14
|
-
constructor(options: AuthModuleOptions);
|
|
15
|
-
/** Returns whether the current principal may perform a user-scoped action. */
|
|
16
|
-
userCan(action: string, subject: Subject): boolean;
|
|
17
|
-
/** Returns the prepared ability only while its user identity is available. */
|
|
18
|
-
getUserAbility(): UserAbility | null;
|
|
19
|
-
/** Throws unless the current principal may perform a user-scoped action. */
|
|
20
|
-
assertUserCan(action: string, subject: Subject): void;
|
|
21
|
-
/** Returns whether the current principal may perform a workspace action. */
|
|
22
|
-
workspaceCan(action: string, subject: Subject): boolean;
|
|
23
|
-
/** Returns the prepared ability only while its workspace identity is available. */
|
|
24
|
-
getWorkspaceAbility(): WorkspaceAbility | null;
|
|
25
|
-
/** Throws unless the current principal may perform a workspace action. */
|
|
26
|
-
assertWorkspaceCan(action: string, subject: Subject): void;
|
|
27
|
-
/** Throws unless the supplied user is the authenticated user. */
|
|
28
|
-
assertCurrentUser(user: User): void;
|
|
29
|
-
/** Authorizes an explicit self-service path without granting a general resource ability. */
|
|
30
|
-
assertUserSession(user: User): void;
|
|
31
|
-
/** Throws unless the supplied session is the authenticated session. */
|
|
32
|
-
assertCurrentSession(session: Session): void;
|
|
33
|
-
/** Throws unless the supplied workspace is selected for the current request. */
|
|
34
|
-
assertCurrentWorkspace(workspace: Workspace): void;
|
|
35
|
-
/** Throws unless the supplied member is the current workspace member. */
|
|
36
|
-
assertCurrentMember(member: Member | null | undefined): void;
|
|
37
|
-
/** Throws when a user grant exceeds the current principal's permissions. */
|
|
38
|
-
assertCanGrantUserPermissions(requestedPermissions: readonly string[]): void;
|
|
39
|
-
/** Checks the same grant ceiling used when assigning user permissions. */
|
|
40
|
-
canGrantUserPermissions(requestedPermissions: readonly string[]): boolean;
|
|
41
|
-
private getUserGrantPermissions;
|
|
42
|
-
/** Throws when a workspace grant exceeds the current principal's permissions. */
|
|
43
|
-
assertCanGrantWorkspacePermissions(requestedPermissions: readonly string[]): void;
|
|
44
|
-
/** Checks the same grant ceiling used when assigning workspace permissions. */
|
|
45
|
-
canGrantWorkspacePermissions(requestedPermissions: readonly string[]): boolean;
|
|
46
|
-
private getWorkspaceGrantPermissions;
|
|
47
|
-
/** Rejects access to or delegation of credentials broader than the authenticating API key. */
|
|
48
|
-
assertApiKeyPermissionCeiling(permissions: readonly string[]): void;
|
|
49
|
-
/** Returns the credential ceiling shared by API-key queries, options, and writes. */
|
|
50
|
-
getApiKeyPermissionCeiling(): readonly string[] | null;
|
|
51
|
-
/** Checks API-key ownership independently of the application's database policies. */
|
|
52
|
-
assertApiKeyOwner(apiKey: ApiKey): void;
|
|
53
|
-
private isWorkspaceApiKey;
|
|
54
|
-
}
|