@nest-boot/auth 8.0.7-beta.2 → 8.0.7-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 +24 -2
- package/dist/{abilities/auth.ability.d.ts → auth.ability.d.ts} +3 -1
- package/dist/auth.ability.js +23 -0
- package/dist/auth.ability.js.map +1 -0
- package/dist/auth.guard.d.ts +12 -16
- package/dist/auth.guard.js +33 -56
- package/dist/auth.guard.js.map +1 -1
- package/dist/decorators/can.decorator.d.ts +3 -3
- package/dist/decorators/can.decorator.js +5 -5
- package/dist/decorators/can.decorator.js.map +1 -1
- package/dist/features/invitations/invitation.service.d.ts +4 -3
- package/dist/features/invitations/invitation.service.js +17 -15
- package/dist/features/invitations/invitation.service.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/api-key-authentication.service.d.ts +3 -3
- package/dist/infrastructure/api-key-authentication.service.js.map +1 -1
- package/dist/infrastructure/api-key-lifecycle.d.ts +3 -3
- package/dist/infrastructure/auth-ability.factory.d.ts +1 -1
- package/dist/infrastructure/auth-ability.factory.js +1 -1
- package/dist/infrastructure/auth-ability.factory.js.map +1 -1
- package/dist/infrastructure/request-identity.d.ts +4 -4
- package/dist/infrastructure/request-identity.js +1 -1
- package/dist/infrastructure/request-identity.js.map +1 -1
- package/dist/interfaces/can-metadata.interface.d.ts +3 -3
- package/dist/interfaces/request-identity-patch.interface.d.ts +2 -2
- package/dist/objects/password-policy.object.d.ts +7 -0
- package/dist/objects/password-policy.object.js +30 -0
- package/dist/objects/password-policy.object.js.map +1 -0
- package/dist/resolvers/auth.resolver.d.ts +3 -0
- package/dist/resolvers/auth.resolver.js +14 -2
- package/dist/resolvers/auth.resolver.js.map +1 -1
- package/dist/resolvers/user-api-key.resolver.d.ts +3 -2
- package/dist/resolvers/user-api-key.resolver.js.map +1 -1
- package/dist/resolvers/user.resolver.d.ts +9 -7
- package/dist/resolvers/user.resolver.js +25 -19
- package/dist/resolvers/user.resolver.js.map +1 -1
- package/dist/resolvers/workspace-api-key.resolver.d.ts +3 -2
- package/dist/resolvers/workspace-api-key.resolver.js.map +1 -1
- package/dist/resolvers/workspace.resolver.d.ts +6 -4
- package/dist/resolvers/workspace.resolver.js +13 -10
- package/dist/resolvers/workspace.resolver.js.map +1 -1
- package/dist/services/account.service.d.ts +3 -2
- package/dist/services/account.service.js +16 -2
- package/dist/services/account.service.js.map +1 -1
- package/dist/services/auth.service.d.ts +3 -0
- package/dist/services/auth.service.js +4 -0
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/member.service.d.ts +3 -2
- package/dist/services/member.service.js +26 -26
- package/dist/services/member.service.js.map +1 -1
- package/dist/services/session.service.d.ts +3 -2
- package/dist/services/session.service.js +19 -11
- package/dist/services/session.service.js.map +1 -1
- package/dist/services/user-api-key.service.d.ts +7 -5
- package/dist/services/user-api-key.service.js +24 -16
- package/dist/services/user-api-key.service.js.map +1 -1
- package/dist/services/user.service.d.ts +6 -2
- package/dist/services/user.service.js +39 -30
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/workspace-api-key.service.d.ts +7 -5
- package/dist/services/workspace-api-key.service.js +24 -16
- package/dist/services/workspace-api-key.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +3 -2
- package/dist/services/workspace.service.js +12 -11
- package/dist/services/workspace.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/api-key-metadata.type.d.ts +6 -0
- package/dist/types/api-key-metadata.type.js +2 -0
- package/dist/types/api-key-metadata.type.js.map +1 -0
- package/dist/types/can-subject-callback.type.d.ts +3 -0
- package/dist/types/can-subject-callback.type.js +2 -0
- package/dist/types/can-subject-callback.type.js.map +1 -0
- package/dist/utils/authorize.util.d.ts +3 -0
- package/dist/utils/authorize.util.js +6 -0
- package/dist/utils/authorize.util.js.map +1 -0
- package/dist/utils/build-request-ability.util.d.ts +1 -1
- package/dist/utils/can.util.d.ts +1 -1
- package/dist/utils/can.util.js +3 -5
- package/dist/utils/can.util.js.map +1 -1
- package/dist/utils/get-auth-ability.util.d.ts +6 -0
- package/dist/utils/get-auth-ability.util.js +19 -0
- package/dist/utils/get-auth-ability.util.js.map +1 -0
- package/dist/utils/get-current-api-key.util.d.ts +2 -2
- package/dist/utils/get-current-api-key.util.js.map +1 -1
- package/dist/utils/omit-credentials.util.d.ts +2 -0
- package/dist/utils/omit-credentials.util.js +10 -0
- package/dist/utils/omit-credentials.util.js.map +1 -0
- package/package.json +4 -4
- package/dist/abilities/auth.ability.js +0 -13
- package/dist/abilities/auth.ability.js.map +0 -1
- package/dist/abilities/index.d.ts +0 -1
- package/dist/abilities/index.js +0 -2
- package/dist/abilities/index.js.map +0 -1
- package/dist/types/can-subject-factory.type.d.ts +0 -3
- package/dist/types/can-subject-factory.type.js +0 -2
- package/dist/types/can-subject-factory.type.js.map +0 -1
- package/dist/types/can-subject.type.d.ts +0 -5
- package/dist/types/can-subject.type.js +0 -2
- package/dist/types/can-subject.type.js.map +0 -1
- package/dist/utils/assert-can.util.d.ts +0 -3
- package/dist/utils/assert-can.util.js +0 -8
- package/dist/utils/assert-can.util.js.map +0 -1
- package/dist/utils/get-ability.util.d.ts +0 -5
- package/dist/utils/get-ability.util.js +0 -20
- package/dist/utils/get-ability.util.js.map +0 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ApiKey } from "./api-key.type.js";
|
|
2
|
+
/**
|
|
3
|
+
* API-key fields without the credential hash.
|
|
4
|
+
* Management services return snapshots; use service methods to persist changes.
|
|
5
|
+
*/
|
|
6
|
+
export type ApiKeyMetadata<Key extends ApiKey = ApiKey> = Key extends ApiKey ? Omit<Key, "key"> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-metadata.type.js","sourceRoot":"","sources":["../../src/types/api-key-metadata.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Subject } from "@casl/ability";
|
|
2
|
+
/** Callback that resolves a permission subject from the current handler instance and decorated method parameters. */
|
|
3
|
+
export type CanSubjectCallback<T extends Subject = Subject, TSelf = unknown, TArgs extends unknown[] = unknown[]> = (self: TSelf, ...args: TArgs) => T | Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"can-subject-callback.type.js","sourceRoot":"","sources":["../../src/types/can-subject-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getAuthAbility } from "./get-auth-ability.util.js";
|
|
2
|
+
/** Throws ForbiddenException unless the current request permits the action. */
|
|
3
|
+
export function authorize(action, subject, field) {
|
|
4
|
+
getAuthAbility().authorize(action, subject, field);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=authorize.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.util.js","sourceRoot":"","sources":["../../src/utils/authorize.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,OAAgB,EAChB,KAAc;IAEd,cAAc,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthAbility } from "../
|
|
1
|
+
import type { AuthAbility } from "../auth.ability.js";
|
|
2
2
|
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
3
3
|
/** Builds one ability from the current identity and credential-limited permission snapshot. */
|
|
4
4
|
export declare function buildRequestAbility(options: AuthModuleOptions): AuthAbility;
|
package/dist/utils/can.util.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Subject } from "@casl/ability";
|
|
2
|
-
/** Checks
|
|
2
|
+
/** Checks the current request's ability on every call. */
|
|
3
3
|
export declare function can(action: string, subject: Subject, field?: string): boolean;
|
package/dist/utils/can.util.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/** Checks
|
|
1
|
+
import { getAuthAbility } from "./get-auth-ability.util.js";
|
|
2
|
+
/** Checks the current request's ability on every call. */
|
|
3
3
|
export function can(action, subject, field) {
|
|
4
|
-
const ability =
|
|
5
|
-
if (!ability)
|
|
6
|
-
return false;
|
|
4
|
+
const ability = getAuthAbility();
|
|
7
5
|
return field === undefined
|
|
8
6
|
? ability.can(action, subject)
|
|
9
7
|
: ability.can(action, subject, field);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,0DAA0D;AAC1D,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,KAAc;IAClE,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuthAbility } from "../auth.ability.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current request's prepared ability or throws ForbiddenException.
|
|
4
|
+
* Retrieve the instance again after identity changes; do not cache it across requests.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAuthAbility(): AuthAbility;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RequestContext } from "@nest-boot/request-context";
|
|
2
|
+
import { ForbiddenException } from "@nestjs/common";
|
|
3
|
+
import { AuthAbility } from "../auth.ability.js";
|
|
4
|
+
import { User } from "../entities/user.entity.js";
|
|
5
|
+
import { getCurrentApiKey } from "./get-current-api-key.util.js";
|
|
6
|
+
/**
|
|
7
|
+
* Returns the current request's prepared ability or throws ForbiddenException.
|
|
8
|
+
* Retrieve the instance again after identity changes; do not cache it across requests.
|
|
9
|
+
*/
|
|
10
|
+
export function getAuthAbility() {
|
|
11
|
+
if (!RequestContext.isActive() ||
|
|
12
|
+
(!RequestContext.get(User) && !getCurrentApiKey()))
|
|
13
|
+
throw new ForbiddenException("Permission ability is not available");
|
|
14
|
+
const ability = RequestContext.get(AuthAbility);
|
|
15
|
+
if (!ability)
|
|
16
|
+
throw new ForbiddenException("Permission ability is not available");
|
|
17
|
+
return ability;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=get-auth-ability.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-auth-ability.util.js","sourceRoot":"","sources":["../../src/utils/get-auth-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,oBAAoB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,IACE,CAAC,cAAc,CAAC,QAAQ,EAAE;QAC1B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAElD,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApiKeyMetadata } from "../types/api-key-metadata.type.js";
|
|
2
2
|
/** Returns the current API credential without resolving a database entity. @internal */
|
|
3
|
-
export declare function getCurrentApiKey():
|
|
3
|
+
export declare function getCurrentApiKey(): ApiKeyMetadata | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-api-key.util.js","sourceRoot":"","sources":["../../src/utils/get-current-api-key.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,wFAAwF;AACxF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAC,QAAQ,EAAE;QAC9B,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"get-current-api-key.util.js","sourceRoot":"","sources":["../../src/utils/get-current-api-key.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,wFAAwF;AACxF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAC,QAAQ,EAAE;QAC9B,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAiB,OAAO,CAAC,IAAI,IAAI,CAAC;QACvD,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Copies public entity fields without credentials or ORM identity-map state. @internal */
|
|
2
|
+
export function omitCredentials(entity, keys) {
|
|
3
|
+
const result = { ...entity };
|
|
4
|
+
for (const key of keys)
|
|
5
|
+
Reflect.deleteProperty(result, key);
|
|
6
|
+
// Keep entity prototypes for GraphQL and consumers that discriminate ownership by class.
|
|
7
|
+
Object.setPrototypeOf(result, Object.getPrototypeOf(entity));
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=omit-credentials.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit-credentials.util.js","sourceRoot":"","sources":["../../src/utils/omit-credentials.util.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,IAAoB;IAEpB,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC7B,KAAK,MAAM,GAAG,IAAI,IAAI;QAAE,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5D,yFAAyF;IACzF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/auth",
|
|
3
|
-
"version": "8.0.7-beta.
|
|
3
|
+
"version": "8.0.7-beta.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/nest-boot/nest-boot.git",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"zod": "^4.3.6",
|
|
54
54
|
"@nest-boot/eslint-config": "^8.0.2-beta.0",
|
|
55
55
|
"@nest-boot/graphql-connection": "^8.0.2-beta.1",
|
|
56
|
-
"@nest-boot/mailer": "^8.0.2-beta.0",
|
|
57
|
-
"@nest-boot/hash": "^8.0.2-beta.0",
|
|
58
56
|
"@nest-boot/eslint-plugin": "^8.0.1-beta.1",
|
|
57
|
+
"@nest-boot/hash": "^8.0.2-beta.0",
|
|
59
58
|
"@nest-boot/middleware": "^8.0.2-beta.0",
|
|
59
|
+
"@nest-boot/mailer": "^8.0.2-beta.0",
|
|
60
60
|
"@nest-boot/tsconfig": "^8.0.0-beta.4",
|
|
61
61
|
"@nest-boot/request-context": "^8.0.2-beta.0",
|
|
62
62
|
"@nest-boot/validator": "^8.0.5-beta.0",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"graphql": "^16.0.0",
|
|
78
78
|
"zod": "^4.0.0",
|
|
79
79
|
"@nest-boot/graphql-connection": "^8.0.2-beta.1",
|
|
80
|
-
"@nest-boot/middleware": "^8.0.2-beta.0",
|
|
81
80
|
"@nest-boot/hash": "^8.0.2-beta.0",
|
|
81
|
+
"@nest-boot/middleware": "^8.0.2-beta.0",
|
|
82
82
|
"@nest-boot/mailer": "^8.0.2-beta.0",
|
|
83
83
|
"@nest-boot/validator": "^8.0.5-beta.0",
|
|
84
84
|
"@nest-boot/graphql": "^8.0.2-beta.0",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Ability, fieldPatternMatcher, mongoQueryMatcher, } from "@casl/ability";
|
|
2
|
-
/** CASL ability for the authenticated request and its selected workspace. */
|
|
3
|
-
export class AuthAbility extends Ability {
|
|
4
|
-
/** Creates an 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=auth.ability.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.ability.js","sourceRoot":"","sources":["../../src/abilities/auth.ability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGP,mBAAmB,EAEnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAEvB,6EAA6E;AAC7E,MAAM,OAAO,WAAY,SAAQ,OAAiC;IAChE,qEAAqE;IACrE,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 +0,0 @@
|
|
|
1
|
-
export * from "./auth.ability.js";
|
package/dist/abilities/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
/** Factory that resolves a permission subject from the current handler instance and decorated method parameters. */
|
|
3
|
-
export type CanSubjectFactory<T extends Subject = Subject, TSelf = unknown, TArgs extends unknown[] = unknown[]> = (self: TSelf, ...args: TArgs) => T | Promise<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"can-subject-factory.type.js","sourceRoot":"","sources":["../../src/types/can-subject-factory.type.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Subject } from "@casl/ability";
|
|
2
|
-
import type { Type } from "@nestjs/common";
|
|
3
|
-
import type { CanSubjectFactory } from "./can-subject-factory.type.js";
|
|
4
|
-
/** Permission subject type or subject resolver factory. */
|
|
5
|
-
export type CanSubject<T extends Subject = Subject> = Type<T> | CanSubjectFactory<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"can-subject.type.js","sourceRoot":"","sources":["../../src/types/can-subject.type.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|