@nest-boot/auth 8.0.5-beta.2 → 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 +33 -22
- 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 -6
- 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 +35 -32
- 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-api-key-options.interface.d.ts +1 -1
- 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 +38 -45
- package/dist/services/invitation.service.js.map +1 -1
- package/dist/services/member.service.d.ts +2 -4
- package/dist/services/member.service.js +63 -60
- package/dist/services/member.service.js.map +1 -1
- package/dist/services/session.service.d.ts +1 -4
- package/dist/services/session.service.js +12 -16
- 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 +46 -44
- 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 +51 -76
- package/dist/services/workspace-api-key.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +2 -4
- package/dist/services/workspace.service.js +36 -30
- 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/user.constants.d.ts +5 -5
- package/dist/user.constants.js +11 -13
- package/dist/user.constants.js.map +1 -1
- package/dist/utils/api-key-permissions.util.d.ts +2 -0
- package/dist/utils/api-key-permissions.util.js +10 -2
- 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/dist/workspace.constants.d.ts +7 -7
- package/dist/workspace.constants.js +18 -18
- package/dist/workspace.constants.js.map +1 -1
- package/package.json +8 -8
- 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 -52
- package/dist/services/access-control.service.js +0 -201
- 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":""}
|
package/dist/user.constants.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ export declare const DEFAULT_USER_ROLE = "user";
|
|
|
3
3
|
/** Roles classified as administrators by default. */
|
|
4
4
|
export declare const DEFAULT_USER_ADMIN_ROLES: readonly ["admin"];
|
|
5
5
|
/** Permissions available to the default user roles. */
|
|
6
|
-
export declare const DEFAULT_USER_PERMISSIONS: readonly ["user:create", "user:
|
|
7
|
-
/**
|
|
6
|
+
export declare const DEFAULT_USER_PERMISSIONS: readonly ["user:create", "user:read", "user:set-roles", "user:set-permissions", "user:ban", "user:impersonate", "user:impersonate-admin", "user:delete", "user:set-password", "user:set-email", "user:update", "session:read", "session:revoke", "user-api-key:read", "user-api-key:write", "workspace:create"];
|
|
7
|
+
/** Explicit default grants for user-scoped administration and workspace creation. */
|
|
8
8
|
export declare const DEFAULT_USER_ROLES: {
|
|
9
9
|
/** Grants every default user permission. */
|
|
10
|
-
readonly admin: readonly ["user:create", "user:
|
|
11
|
-
/**
|
|
12
|
-
readonly user: readonly [];
|
|
10
|
+
readonly admin: readonly ["user:create", "user:read", "user:set-roles", "user:set-permissions", "user:ban", "user:impersonate", "user:impersonate-admin", "user:delete", "user:set-password", "user:set-email", "user:update", "session:read", "session:revoke", "user-api-key:read", "user-api-key:write", "workspace:create"];
|
|
11
|
+
/** Allows signed-in users to create workspaces, without user-administration grants. */
|
|
12
|
+
readonly user: readonly ["workspace:create"];
|
|
13
13
|
};
|
package/dist/user.constants.js
CHANGED
|
@@ -5,29 +5,27 @@ export const DEFAULT_USER_ADMIN_ROLES = ["admin"];
|
|
|
5
5
|
/** Permissions available to the default user roles. */
|
|
6
6
|
export const DEFAULT_USER_PERMISSIONS = [
|
|
7
7
|
"user:create",
|
|
8
|
-
"user:
|
|
9
|
-
"user:set-
|
|
8
|
+
"user:read",
|
|
9
|
+
"user:set-roles",
|
|
10
|
+
"user:set-permissions",
|
|
10
11
|
"user:ban",
|
|
11
12
|
"user:impersonate",
|
|
12
|
-
"user:impersonate-
|
|
13
|
+
"user:impersonate-admin",
|
|
13
14
|
"user:delete",
|
|
14
15
|
"user:set-password",
|
|
15
16
|
"user:set-email",
|
|
16
|
-
"user:get",
|
|
17
17
|
"user:update",
|
|
18
|
-
"session:
|
|
18
|
+
"session:read",
|
|
19
19
|
"session:revoke",
|
|
20
|
-
"
|
|
21
|
-
"api-key:
|
|
22
|
-
"
|
|
23
|
-
"api-key:update",
|
|
24
|
-
"api-key:delete",
|
|
20
|
+
"user-api-key:read",
|
|
21
|
+
"user-api-key:write",
|
|
22
|
+
"workspace:create",
|
|
25
23
|
];
|
|
26
|
-
/**
|
|
24
|
+
/** Explicit default grants for user-scoped administration and workspace creation. */
|
|
27
25
|
export const DEFAULT_USER_ROLES = {
|
|
28
26
|
/** Grants every default user permission. */
|
|
29
27
|
admin: DEFAULT_USER_PERMISSIONS,
|
|
30
|
-
/**
|
|
31
|
-
user: [],
|
|
28
|
+
/** Allows signed-in users to create workspaces, without user-administration grants. */
|
|
29
|
+
user: ["workspace:create"],
|
|
32
30
|
};
|
|
33
31
|
//# sourceMappingURL=user.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.constants.js","sourceRoot":"","sources":["../src/user.constants.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAO,CAAU,CAAC;AAE3D,uDAAuD;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,aAAa;IACb,WAAW;IACX,
|
|
1
|
+
{"version":3,"file":"user.constants.js","sourceRoot":"","sources":["../src/user.constants.ts"],"names":[],"mappings":"AAEA,yCAAyC;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,OAAO,CAAU,CAAC;AAE3D,uDAAuD;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,aAAa;IACb,WAAW;IACX,gBAAgB;IAChB,sBAAsB;IACtB,UAAU;IACV,kBAAkB;IAClB,wBAAwB;IACxB,aAAa;IACb,mBAAmB;IACnB,gBAAgB;IAChB,aAAa;IACb,cAAc;IACd,gBAAgB;IAChB,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;CACV,CAAC;AAEX,qFAAqF;AACrF,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,4CAA4C;IAC5C,KAAK,EAAE,wBAAwB;IAC/B,uFAAuF;IACvF,IAAI,EAAE,CAAC,kBAAkB,CAAC;CACQ,CAAC"}
|
|
@@ -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. */
|
|
@@ -17,11 +19,17 @@ export function resolveApiKeyPermissionCatalog(options, scope) {
|
|
|
17
19
|
defaults: Object.freeze([
|
|
18
20
|
...(options.apiKey?.[scope]?.defaultPermissions ?? []),
|
|
19
21
|
]),
|
|
20
|
-
allowed: Object.freeze(permissions.filter((permission) => allowlist.has(permission)
|
|
21
|
-
(scope !== "workspace" || permission !== "invitation:create"))),
|
|
22
|
+
allowed: Object.freeze(permissions.filter((permission) => allowlist.has(permission))),
|
|
22
23
|
});
|
|
23
24
|
scopes[scope] = catalog;
|
|
24
25
|
catalogs.set(options, scopes);
|
|
25
26
|
return catalog;
|
|
26
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
|
+
}
|
|
27
35
|
//# sourceMappingURL=api-key-permissions.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-permissions.util.js","sourceRoot":"","sources":["../../src/utils/api-key-permissions.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAQzB,CAAC;AAEJ,yFAAyF;AACzF,MAAM,UAAU,8BAA8B,CAC5C,OAA0B,EAC1B,KAA2B;IAM3B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC3C,MAAM,MAAM,G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xC,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":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAI5D,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,+FAA+F;AAC/F,MAAM,UAAU,mBAAmB,CAAC,OAA0B;IAC5D,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,YAAY,eAAe,CAAC;IACvD,MAAM,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IACtE,MAAM,iBAAiB,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,MAAM,GACV,IAAI;QACJ,aAAa,EAAE,MAAM,KAAK,QAAQ;QAClC,aAAa,CAAC,IAAI,EAAE,EAAE,KAAK,IAAI,CAAC,EAAE;QAClC,aAAa,CAAC,SAAS,EAAE,EAAE,KAAK,iBAAiB,EAAE,EAAE;QACnD,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,IAAI,CAAC;IACX,MAAM,SAAS,GACb,iBAAiB;QACjB,CAAC,MAAM,IAAI,CAAC,YAAY,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,iBAAiB,CAAC,EAAE,CAAC,CAAC;QACzE,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;AAIhD,oGAAoG;AACpG,MAAM,UAAU,aAAa,CAC3B,OAA0D,EAC1D,OAAuB,EACvB,OAAkE,EAClE,SAA2C;IAE3C,MAAM,YAAY,GAAyC,EAAE,CAAC;IAC9D,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,MAAM,YAAY,GAAG,GAAG,EAAE;QACxB,IAAI,CAAC,MAAM;YACT,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAC1E,CAAC,CAAC;IACF,MAAM,KAAK,GAAiB,MAAM,CAAC,MAAM,CAAC;QACxC,GAAG,CACD,UAA8C,EAC9C,GAAG,IAAwC;YAE3C,YAAY,EAAE,CAAC;YACf,IACE,CAAC,UAAU;gBACX,OAAO,UAAU,KAAK,QAAQ;gBAC9B,CAAC,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC;oBACnC,CAAC,OAAO,UAAU,CAAC,SAAS,KAAK,QAAQ,CAAC;gB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AC,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;AAC9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@@ -3,13 +3,13 @@ export declare const DEFAULT_WORKSPACE_ROLE = "member";
|
|
|
3
3
|
/** Role assigned to workspace creators by default. */
|
|
4
4
|
export declare const DEFAULT_WORKSPACE_CREATOR_ROLE = "owner";
|
|
5
5
|
/** Permissions available to the default workspace roles. */
|
|
6
|
-
export declare const DEFAULT_WORKSPACE_PERMISSIONS: readonly ["workspace:
|
|
7
|
-
/**
|
|
6
|
+
export declare const DEFAULT_WORKSPACE_PERMISSIONS: readonly ["workspace:read", "workspace:update", "workspace:delete", "member:read", "member:write", "member:set-roles", "member:set-permissions", "member:invite", "workspace-api-key:read", "workspace-api-key:write"];
|
|
7
|
+
/** Explicit grants for workspace administration and ordinary membership. */
|
|
8
8
|
export declare const DEFAULT_WORKSPACE_ROLES: {
|
|
9
9
|
/** Grants every default workspace permission. */
|
|
10
|
-
readonly owner: readonly ["workspace:
|
|
11
|
-
/** Grants
|
|
12
|
-
readonly admin: readonly ["workspace:update", "member:
|
|
13
|
-
/**
|
|
14
|
-
readonly member: readonly [];
|
|
10
|
+
readonly owner: readonly ["workspace:read", "workspace:update", "workspace:delete", "member:read", "member:write", "member:set-roles", "member:set-permissions", "member:invite", "workspace-api-key:read", "workspace-api-key:write"];
|
|
11
|
+
/** Grants membership/invitation administration without workspace deletion or key management. */
|
|
12
|
+
readonly admin: readonly ["workspace:read", "workspace:update", "member:read", "member:write", "member:set-roles", "member:set-permissions", "member:invite"];
|
|
13
|
+
/** Allows members to read workspace and member profiles, but not invitations. */
|
|
14
|
+
readonly member: readonly ["workspace:read", "member:read"];
|
|
15
15
|
};
|
|
@@ -4,32 +4,32 @@ export const DEFAULT_WORKSPACE_ROLE = "member";
|
|
|
4
4
|
export const DEFAULT_WORKSPACE_CREATOR_ROLE = "owner";
|
|
5
5
|
/** Permissions available to the default workspace roles. */
|
|
6
6
|
export const DEFAULT_WORKSPACE_PERMISSIONS = [
|
|
7
|
+
"workspace:read",
|
|
7
8
|
"workspace:update",
|
|
8
9
|
"workspace:delete",
|
|
9
|
-
"member:
|
|
10
|
-
"member:
|
|
11
|
-
"member:
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"api-key:read",
|
|
15
|
-
"api-key:
|
|
16
|
-
"api-key:update",
|
|
17
|
-
"api-key:delete",
|
|
10
|
+
"member:read",
|
|
11
|
+
"member:write",
|
|
12
|
+
"member:set-roles",
|
|
13
|
+
"member:set-permissions",
|
|
14
|
+
"member:invite",
|
|
15
|
+
"workspace-api-key:read",
|
|
16
|
+
"workspace-api-key:write",
|
|
18
17
|
];
|
|
19
|
-
/**
|
|
18
|
+
/** Explicit grants for workspace administration and ordinary membership. */
|
|
20
19
|
export const DEFAULT_WORKSPACE_ROLES = {
|
|
21
20
|
/** Grants every default workspace permission. */
|
|
22
21
|
owner: DEFAULT_WORKSPACE_PERMISSIONS,
|
|
23
|
-
/** Grants
|
|
22
|
+
/** Grants membership/invitation administration without workspace deletion or key management. */
|
|
24
23
|
admin: [
|
|
24
|
+
"workspace:read",
|
|
25
25
|
"workspace:update",
|
|
26
|
-
"member:
|
|
27
|
-
"member:
|
|
28
|
-
"member:
|
|
29
|
-
"
|
|
30
|
-
"
|
|
26
|
+
"member:read",
|
|
27
|
+
"member:write",
|
|
28
|
+
"member:set-roles",
|
|
29
|
+
"member:set-permissions",
|
|
30
|
+
"member:invite",
|
|
31
31
|
],
|
|
32
|
-
/**
|
|
33
|
-
member: [],
|
|
32
|
+
/** Allows members to read workspace and member profiles, but not invitations. */
|
|
33
|
+
member: ["workspace:read", "member:read"],
|
|
34
34
|
};
|
|
35
35
|
//# sourceMappingURL=workspace.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.constants.js","sourceRoot":"","sources":["../src/workspace.constants.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AAE/C,sDAAsD;AACtD,MAAM,CAAC,MAAM,8BAA8B,GAAG,OAAO,CAAC;AAEtD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,kBAAkB;IAClB,kBAAkB;IAClB,
|
|
1
|
+
{"version":3,"file":"workspace.constants.js","sourceRoot":"","sources":["../src/workspace.constants.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AAE/C,sDAAsD;AACtD,MAAM,CAAC,MAAM,8BAA8B,GAAG,OAAO,CAAC;AAEtD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,wBAAwB;IACxB,eAAe;IACf,wBAAwB;IACxB,yBAAyB;CACjB,CAAC;AAEX,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,iDAAiD;IACjD,KAAK,EAAE,6BAA6B;IACpC,gGAAgG;IAChG,KAAK,EAAE;QACL,gBAAgB;QAChB,kBAAkB;QAClB,aAAa;QACb,cAAc;QACd,kBAAkB;QAClB,wBAAwB;QACxB,eAAe;KAChB;IACD,iFAAiF;IACjF,MAAM,EAAE,CAAC,gBAAgB,EAAE,aAAa,CAAC;CACP,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",
|
|
56
|
-
"@nest-boot/
|
|
55
|
+
"@nest-boot/eslint-config": "^8.0.1-beta.0",
|
|
57
56
|
"@nest-boot/hash": "^8.0.1-beta.0",
|
|
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
61
|
"@nest-boot/tsconfig": "^8.0.0-beta.4",
|
|
62
|
-
"@nest-boot/
|
|
63
|
-
"@nest-boot/
|
|
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",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"graphql": "^16.0.0",
|
|
78
78
|
"zod": "^4.0.0",
|
|
79
79
|
"@nest-boot/graphql-connection": "^8.0.1-beta.3",
|
|
80
|
+
"@nest-boot/hash": "^8.0.1-beta.0",
|
|
80
81
|
"@nest-boot/mailer": "^8.0.1-beta.0",
|
|
82
|
+
"@nest-boot/middleware": "^8.0.1-beta.0",
|
|
81
83
|
"@nest-boot/request-context": "^8.0.1-beta.0",
|
|
82
|
-
"@nest-boot/validator": "^8.0.4-beta.0",
|
|
83
|
-
"@nest-boot/hash": "^8.0.1-beta.0",
|
|
84
84
|
"@nest-boot/graphql": "^8.0.1-beta.0",
|
|
85
|
-
"@nest-boot/
|
|
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>;
|