@ooneex/permission 1.1.15 → 1.2.1
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 +3 -3
- package/dist/index.d.ts +8 -9
- package/dist/index.js.map +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -503,18 +503,18 @@ class AdminPermission extends Permission {
|
|
|
503
503
|
|
|
504
504
|
// Set permissions based on role
|
|
505
505
|
switch (user.role) {
|
|
506
|
-
case
|
|
506
|
+
case 'ROLE_SUPER_ADMIN':
|
|
507
507
|
this.ability.can(EPermissionAction.MANAGE, 'all');
|
|
508
508
|
break;
|
|
509
509
|
|
|
510
|
-
case
|
|
510
|
+
case 'ROLE_ADMIN':
|
|
511
511
|
this.ability.can(EPermissionAction.CREATE, 'User');
|
|
512
512
|
this.ability.can(EPermissionAction.READ, 'User');
|
|
513
513
|
this.ability.can(EPermissionAction.UPDATE, 'User');
|
|
514
514
|
this.ability.cannot(EPermissionAction.DELETE, 'User');
|
|
515
515
|
break;
|
|
516
516
|
|
|
517
|
-
case
|
|
517
|
+
case 'ROLE_MODERATOR':
|
|
518
518
|
this.ability.can(EPermissionAction.READ, 'User');
|
|
519
519
|
this.ability.can(EPermissionAction.MODERATE, 'User');
|
|
520
520
|
this.ability.can(EPermissionAction.BAN, 'User');
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { ILogger, LogsEntity } from "@ooneex/logger";
|
|
|
11
11
|
import { IMailer } from "@ooneex/mailer";
|
|
12
12
|
import { IPermission } from "@ooneex/permission";
|
|
13
13
|
import { IRateLimiter } from "@ooneex/rate-limit";
|
|
14
|
-
import { ERole } from "@ooneex/role";
|
|
15
14
|
import { IStorage } from "@ooneex/storage";
|
|
16
15
|
import { LocaleInfoType } from "@ooneex/translation";
|
|
17
16
|
import { HttpMethodType, ScalarType } from "@ooneex/types";
|
|
@@ -34,7 +33,7 @@ type ContextType<T extends ContextConfigType = ContextConfigType> = {
|
|
|
34
33
|
method: HttpMethodType;
|
|
35
34
|
version: number;
|
|
36
35
|
description: string;
|
|
37
|
-
roles?:
|
|
36
|
+
roles?: Uppercase<string>[];
|
|
38
37
|
} | null;
|
|
39
38
|
env: IAppEnv;
|
|
40
39
|
response: IResponse<T["response"]>;
|
|
@@ -136,12 +135,12 @@ interface IPermission2<
|
|
|
136
135
|
A extends string = string,
|
|
137
136
|
S extends string = string
|
|
138
137
|
> {
|
|
139
|
-
allow: () => IPermission2<A, S>;
|
|
140
|
-
setUserPermissions: (context: ContextType) => IPermission2<A, S>;
|
|
141
|
-
build: () => IPermission2<A, S>;
|
|
142
|
-
check: (context: ContextType) => boolean;
|
|
143
|
-
can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;
|
|
144
|
-
cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;
|
|
138
|
+
allow: () => Promise<IPermission2<A, S>> | IPermission2<A, S>;
|
|
139
|
+
setUserPermissions: (context: ContextType) => Promise<IPermission2<A, S>> | IPermission2<A, S>;
|
|
140
|
+
build: () => Promise<IPermission2<A, S>> | IPermission2<A, S>;
|
|
141
|
+
check: (context: ContextType) => Promise<boolean> | boolean;
|
|
142
|
+
can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => Promise<boolean> | boolean;
|
|
143
|
+
cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => Promise<boolean> | boolean;
|
|
145
144
|
}
|
|
146
145
|
declare const decorator: {
|
|
147
146
|
permission: (scope?: EContainerScope) => (target: PermissionClassType) => void;
|
|
@@ -155,7 +154,7 @@ declare abstract class Permission<
|
|
|
155
154
|
private builtAbility;
|
|
156
155
|
constructor();
|
|
157
156
|
abstract setUserPermissions(context: ContextType): this;
|
|
158
|
-
abstract check(context: ContextType): boolean;
|
|
157
|
+
abstract check(context: ContextType): Promise<boolean> | boolean;
|
|
159
158
|
build(): this;
|
|
160
159
|
can(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean;
|
|
161
160
|
cannot(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean;
|
package/dist/index.js.map
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["src/decorators.ts", "src/Permission.ts", "src/PermissionException.ts", "src/types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { container, EContainerScope } from \"@ooneex/container\";\nimport type { PermissionClassType } from \"./types\";\n\nexport const decorator = {\n permission: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: PermissionClassType): void => {\n container.add(target, scope);\n };\n },\n};\n",
|
|
6
|
-
"import { AbilityBuilder, createMongoAbility, type MongoAbility } from \"@casl/ability\";\nimport type { ContextType } from \"../../controller/src/types\";\nimport { PermissionException } from \"./PermissionException\";\nimport type { IPermission, PermissionActionType, Subjects } from \"./types\";\n\nexport abstract class Permission<A extends string = string, S extends string = string> implements IPermission<A, S> {\n protected ability: AbilityBuilder<MongoAbility>;\n private builtAbility: MongoAbility | null = null;\n\n constructor() {\n this.ability = new AbilityBuilder(createMongoAbility);\n }\n\n public abstract allow(): this;\n public abstract setUserPermissions(context: ContextType): this;\n public abstract check(context: ContextType): boolean;\n\n public build(): this {\n this.builtAbility = this.ability.build();\n return this;\n }\n\n public can(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean {\n if (!this.builtAbility) {\n throw new PermissionException(\"Permission must be built before checking abilities\", \"NOT_BUILT\");\n }\n return this.builtAbility.can(action as string, subject as string, field);\n }\n\n public cannot(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean {\n if (!this.builtAbility) {\n throw new PermissionException(\"Permission must be built before checking abilities\", \"NOT_BUILT\");\n }\n return this.builtAbility.cannot(action as string, subject as string, field);\n }\n}\n",
|
|
6
|
+
"import { AbilityBuilder, createMongoAbility, type MongoAbility } from \"@casl/ability\";\nimport type { ContextType } from \"../../controller/src/types\";\nimport { PermissionException } from \"./PermissionException\";\nimport type { IPermission, PermissionActionType, Subjects } from \"./types\";\n\nexport abstract class Permission<A extends string = string, S extends string = string> implements IPermission<A, S> {\n protected ability: AbilityBuilder<MongoAbility>;\n private builtAbility: MongoAbility | null = null;\n\n constructor() {\n this.ability = new AbilityBuilder(createMongoAbility);\n }\n\n public abstract allow(): this;\n public abstract setUserPermissions(context: ContextType): this;\n public abstract check(context: ContextType): Promise<boolean> | boolean;\n\n public build(): this {\n this.builtAbility = this.ability.build();\n return this;\n }\n\n public can(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean {\n if (!this.builtAbility) {\n throw new PermissionException(\"Permission must be built before checking abilities\", \"NOT_BUILT\");\n }\n return this.builtAbility.can(action as string, subject as string, field);\n }\n\n public cannot(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean {\n if (!this.builtAbility) {\n throw new PermissionException(\"Permission must be built before checking abilities\", \"NOT_BUILT\");\n }\n return this.builtAbility.cannot(action as string, subject as string, field);\n }\n}\n",
|
|
7
7
|
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class PermissionException extends Exception {\n constructor(message: string, key: string, data: Record<string, unknown> = {}) {\n super(message, {\n key,\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"PermissionException\";\n }\n}\n",
|
|
8
|
-
"import type { ContextType } from \"../../controller/src/types\";\n\nexport enum EPermissionAction {\n CREATE = \"create\",\n READ = \"read\",\n UPDATE = \"update\",\n DELETE = \"delete\",\n MANAGE = \"manage\", // Special action that allows everything\n VIEW = \"view\",\n EDIT = \"edit\",\n PUBLISH = \"publish\",\n ARCHIVE = \"archive\",\n APPROVE = \"approve\",\n REJECT = \"reject\",\n DOWNLOAD = \"download\",\n UPLOAD = \"upload\",\n SHARE = \"share\",\n COPY = \"copy\",\n MOVE = \"move\",\n EXPORT = \"export\",\n IMPORT = \"import\",\n EXECUTE = \"execute\",\n ASSIGN = \"assign\",\n UNASSIGN = \"unassign\",\n COMMENT = \"comment\",\n RATE = \"rate\",\n LIKE = \"like\",\n DISLIKE = \"dislike\",\n FOLLOW = \"follow\",\n UNFOLLOW = \"unfollow\",\n SUBSCRIBE = \"subscribe\",\n UNSUBSCRIBE = \"unsubscribe\",\n INVITE = \"invite\",\n REVOKE = \"revoke\",\n GRANT = \"grant\",\n DENY = \"deny\",\n BLOCK = \"block\",\n UNBLOCK = \"unblock\",\n REPORT = \"report\",\n MODERATE = \"moderate\",\n BAN = \"ban\",\n UNBAN = \"unban\",\n RESTORE = \"restore\",\n PURGE = \"purge\",\n BACKUP = \"backup\",\n SYNC = \"sync\",\n CONFIGURE = \"configure\",\n MONITOR = \"monitor\",\n AUDIT = \"audit\",\n SEARCH = \"search\",\n FILTER = \"filter\",\n SORT = \"sort\",\n BOOKMARK = \"bookmark\",\n TAG = \"tag\",\n UNTAG = \"untag\",\n LOCK = \"lock\",\n UNLOCK = \"unlock\",\n CLONE = \"clone\",\n FORK = \"fork\",\n MERGE = \"merge\",\n SPLIT = \"split\",\n VALIDATE = \"validate\",\n VERIFY = \"verify\",\n CANCEL = \"cancel\",\n PAUSE = \"pause\",\n RESUME = \"resume\",\n SCHEDULE = \"schedule\",\n UNSCHEDULE = \"unschedule\",\n JOIN = \"join\",\n HIDE = \"hide\",\n}\n\nexport enum EPermissionSubject {\n USER_ENTITY = \"UserEntity\",\n AUTH_USER_ENTITY = \"AuthUserEntity\",\n AUTH_USER = \"AuthUser\",\n SYSTEM_ENTITY = \"SystemEntity\",\n SYSTEM = \"System\",\n USER = \"User\",\n ALL = \"all\",\n}\n\nexport type PermissionActionType = `${EPermissionAction}`;\nexport type Subjects = `${EPermissionSubject}`;\n\n// biome-ignore lint/suspicious/noExplicitAny: trust me\nexport type PermissionClassType = new (...args: any[]) => IPermission;\n\nexport interface IPermission<A extends string = string, S extends string = string> {\n allow: () => IPermission<A, S>;\n setUserPermissions: (context: ContextType) => IPermission<A, S>;\n build: () => IPermission<A, S>;\n check: (context: ContextType) => boolean;\n can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;\n cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;\n}\n"
|
|
8
|
+
"import type { ContextType } from \"../../controller/src/types\";\n\nexport enum EPermissionAction {\n CREATE = \"create\",\n READ = \"read\",\n UPDATE = \"update\",\n DELETE = \"delete\",\n MANAGE = \"manage\", // Special action that allows everything\n VIEW = \"view\",\n EDIT = \"edit\",\n PUBLISH = \"publish\",\n ARCHIVE = \"archive\",\n APPROVE = \"approve\",\n REJECT = \"reject\",\n DOWNLOAD = \"download\",\n UPLOAD = \"upload\",\n SHARE = \"share\",\n COPY = \"copy\",\n MOVE = \"move\",\n EXPORT = \"export\",\n IMPORT = \"import\",\n EXECUTE = \"execute\",\n ASSIGN = \"assign\",\n UNASSIGN = \"unassign\",\n COMMENT = \"comment\",\n RATE = \"rate\",\n LIKE = \"like\",\n DISLIKE = \"dislike\",\n FOLLOW = \"follow\",\n UNFOLLOW = \"unfollow\",\n SUBSCRIBE = \"subscribe\",\n UNSUBSCRIBE = \"unsubscribe\",\n INVITE = \"invite\",\n REVOKE = \"revoke\",\n GRANT = \"grant\",\n DENY = \"deny\",\n BLOCK = \"block\",\n UNBLOCK = \"unblock\",\n REPORT = \"report\",\n MODERATE = \"moderate\",\n BAN = \"ban\",\n UNBAN = \"unban\",\n RESTORE = \"restore\",\n PURGE = \"purge\",\n BACKUP = \"backup\",\n SYNC = \"sync\",\n CONFIGURE = \"configure\",\n MONITOR = \"monitor\",\n AUDIT = \"audit\",\n SEARCH = \"search\",\n FILTER = \"filter\",\n SORT = \"sort\",\n BOOKMARK = \"bookmark\",\n TAG = \"tag\",\n UNTAG = \"untag\",\n LOCK = \"lock\",\n UNLOCK = \"unlock\",\n CLONE = \"clone\",\n FORK = \"fork\",\n MERGE = \"merge\",\n SPLIT = \"split\",\n VALIDATE = \"validate\",\n VERIFY = \"verify\",\n CANCEL = \"cancel\",\n PAUSE = \"pause\",\n RESUME = \"resume\",\n SCHEDULE = \"schedule\",\n UNSCHEDULE = \"unschedule\",\n JOIN = \"join\",\n HIDE = \"hide\",\n}\n\nexport enum EPermissionSubject {\n USER_ENTITY = \"UserEntity\",\n AUTH_USER_ENTITY = \"AuthUserEntity\",\n AUTH_USER = \"AuthUser\",\n SYSTEM_ENTITY = \"SystemEntity\",\n SYSTEM = \"System\",\n USER = \"User\",\n ALL = \"all\",\n}\n\nexport type PermissionActionType = `${EPermissionAction}`;\nexport type Subjects = `${EPermissionSubject}`;\n\n// biome-ignore lint/suspicious/noExplicitAny: trust me\nexport type PermissionClassType = new (...args: any[]) => IPermission;\n\nexport interface IPermission<A extends string = string, S extends string = string> {\n allow: () => Promise<IPermission<A, S>> | IPermission<A, S>;\n setUserPermissions: (context: ContextType) => Promise<IPermission<A, S>> | IPermission<A, S>;\n build: () => Promise<IPermission<A, S>> | IPermission<A, S>;\n check: (context: ContextType) => Promise<boolean> | boolean;\n can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => Promise<boolean> | boolean;\n cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => Promise<boolean> | boolean;\n}\n"
|
|
9
9
|
],
|
|
10
10
|
"mappings": ";;AAAA;AAGO,IAAM,YAAY;AAAA,EACvB,YAAY,CAAC,QAAyB,gBAAgB,cAAc;AAAA,IAClE,OAAO,CAAC,WAAsC;AAAA,MAC5C,UAAU,IAAI,QAAQ,KAAK;AAAA;AAAA;AAGjC;;ACTA;;;ACAA;AACA;AAAA;AAEO,MAAM,4BAA4B,UAAU;AAAA,EACjD,WAAW,CAAC,SAAiB,KAAa,OAAgC,CAAC,GAAG;AAAA,IAC5E,MAAM,SAAS;AAAA,MACb;AAAA,MACA,QAAQ,WAAW,KAAK;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,IACD,KAAK,OAAO;AAAA;AAEhB;;;ADPO,MAAe,WAA8F;AAAA,EACxG;AAAA,EACF,eAAoC;AAAA,EAE5C,WAAW,GAAG;AAAA,IACZ,KAAK,UAAU,IAAI,eAAe,kBAAkB;AAAA;AAAA,EAO/C,KAAK,GAA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;AAAA,EACR,gCAAU;AAAA,EACV,8BAAQ;AAAA,EACR,+BAAS;AAAA,EACT,6BAAO;AAAA,EACP,kCAAY;AAAA,EACZ,gCAAU;AAAA,EACV,8BAAQ;AAAA,EACR,+BAAS;AAAA,EACT,+BAAS;AAAA,EACT,6BAAO;AAAA,EACP,iCAAW;AAAA,EACX,4BAAM;AAAA,EACN,8BAAQ;AAAA,EACR,6BAAO;AAAA,EACP,+BAAS;AAAA,EACT,8BAAQ;AAAA,EACR,6BAAO;AAAA,EACP,8BAAQ;AAAA,EACR,8BAAQ;AAAA,EACR,iCAAW;AAAA,EACX,+BAAS;AAAA,EACT,+BAAS;AAAA,EACT,8BAAQ;AAAA,EACR,+BAAS;AAAA,EACT,iCAAW;AAAA,EACX,mCAAa;AAAA,EACb,6BAAO;AAAA,EACP,6BAAO;AAAA,GAnEG;AAsEL,IAAK;AAAA,CAAL,CAAK,wBAAL;AAAA,EACL,qCAAc;AAAA,EACd,0CAAmB;AAAA,EACnB,mCAAY;AAAA,EACZ,uCAAgB;AAAA,EAChB,gCAAS;AAAA,EACT,8BAAO;AAAA,EACP,6BAAM;AAAA,GAPI;",
|
|
11
11
|
"debugId": "7A183E36D71E4F1964756E2164756E21",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/permission",
|
|
3
3
|
"description": "Fine-grained access control using CASL — define, evaluate, and enforce ability-based permissions with role and resource scoping",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@casl/ability": "^6.7.3",
|
|
32
|
-
"@ooneex/container": "^1.5.
|
|
33
|
-
"@ooneex/exception": "^1.2.
|
|
32
|
+
"@ooneex/container": "^1.5.1",
|
|
33
|
+
"@ooneex/exception": "^1.2.10",
|
|
34
34
|
"@ooneex/http-status": "^1.1.11"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@ooneex/user": "^1.2.
|
|
37
|
+
"@ooneex/user": "^1.2.11"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"authorization",
|