@ooneex/permission 1.1.3 → 1.1.5
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/dist/index.d.ts +1 -1
- package/dist/index.js +140 -2
- package/dist/index.js.map +5 -5
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,6 @@ declare abstract class Permission<
|
|
|
110
110
|
}
|
|
111
111
|
import { Exception } from "@ooneex/exception";
|
|
112
112
|
declare class PermissionException extends Exception {
|
|
113
|
-
constructor(message: string, data?: Record<string, unknown>);
|
|
113
|
+
constructor(message: string, key: string, data?: Record<string, unknown>);
|
|
114
114
|
}
|
|
115
115
|
export { decorator, Subjects, PermissionException, PermissionClassType, PermissionActionType, Permission, IPermission, EPermissionSubject, EPermissionAction };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,142 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
// src/decorators.ts
|
|
3
|
+
import { container, EContainerScope } from "@ooneex/container";
|
|
4
|
+
var decorator = {
|
|
5
|
+
permission: (scope = EContainerScope.Singleton) => {
|
|
6
|
+
return (target) => {
|
|
7
|
+
container.add(target, scope);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
// src/Permission.ts
|
|
12
|
+
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
3
13
|
|
|
4
|
-
|
|
14
|
+
// src/PermissionException.ts
|
|
15
|
+
import { Exception } from "@ooneex/exception";
|
|
16
|
+
import { HttpStatus } from "@ooneex/http-status";
|
|
17
|
+
|
|
18
|
+
class PermissionException extends Exception {
|
|
19
|
+
constructor(message, key, data = {}) {
|
|
20
|
+
super(message, {
|
|
21
|
+
key,
|
|
22
|
+
status: HttpStatus.Code.InternalServerError,
|
|
23
|
+
data
|
|
24
|
+
});
|
|
25
|
+
this.name = "PermissionException";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/Permission.ts
|
|
30
|
+
class Permission {
|
|
31
|
+
ability;
|
|
32
|
+
builtAbility = null;
|
|
33
|
+
constructor() {
|
|
34
|
+
this.ability = new AbilityBuilder(createMongoAbility);
|
|
35
|
+
}
|
|
36
|
+
build() {
|
|
37
|
+
this.builtAbility = this.ability.build();
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
can(action, subject, field) {
|
|
41
|
+
if (!this.builtAbility) {
|
|
42
|
+
throw new PermissionException("Permission must be built before checking abilities", "NOT_BUILT");
|
|
43
|
+
}
|
|
44
|
+
return this.builtAbility.can(action, subject, field);
|
|
45
|
+
}
|
|
46
|
+
cannot(action, subject, field) {
|
|
47
|
+
if (!this.builtAbility) {
|
|
48
|
+
throw new PermissionException("Permission must be built before checking abilities", "NOT_BUILT");
|
|
49
|
+
}
|
|
50
|
+
return this.builtAbility.cannot(action, subject, field);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// src/types.ts
|
|
54
|
+
var EPermissionAction;
|
|
55
|
+
((EPermissionAction2) => {
|
|
56
|
+
EPermissionAction2["CREATE"] = "create";
|
|
57
|
+
EPermissionAction2["READ"] = "read";
|
|
58
|
+
EPermissionAction2["UPDATE"] = "update";
|
|
59
|
+
EPermissionAction2["DELETE"] = "delete";
|
|
60
|
+
EPermissionAction2["MANAGE"] = "manage";
|
|
61
|
+
EPermissionAction2["VIEW"] = "view";
|
|
62
|
+
EPermissionAction2["EDIT"] = "edit";
|
|
63
|
+
EPermissionAction2["PUBLISH"] = "publish";
|
|
64
|
+
EPermissionAction2["ARCHIVE"] = "archive";
|
|
65
|
+
EPermissionAction2["APPROVE"] = "approve";
|
|
66
|
+
EPermissionAction2["REJECT"] = "reject";
|
|
67
|
+
EPermissionAction2["DOWNLOAD"] = "download";
|
|
68
|
+
EPermissionAction2["UPLOAD"] = "upload";
|
|
69
|
+
EPermissionAction2["SHARE"] = "share";
|
|
70
|
+
EPermissionAction2["COPY"] = "copy";
|
|
71
|
+
EPermissionAction2["MOVE"] = "move";
|
|
72
|
+
EPermissionAction2["EXPORT"] = "export";
|
|
73
|
+
EPermissionAction2["IMPORT"] = "import";
|
|
74
|
+
EPermissionAction2["EXECUTE"] = "execute";
|
|
75
|
+
EPermissionAction2["ASSIGN"] = "assign";
|
|
76
|
+
EPermissionAction2["UNASSIGN"] = "unassign";
|
|
77
|
+
EPermissionAction2["COMMENT"] = "comment";
|
|
78
|
+
EPermissionAction2["RATE"] = "rate";
|
|
79
|
+
EPermissionAction2["LIKE"] = "like";
|
|
80
|
+
EPermissionAction2["DISLIKE"] = "dislike";
|
|
81
|
+
EPermissionAction2["FOLLOW"] = "follow";
|
|
82
|
+
EPermissionAction2["UNFOLLOW"] = "unfollow";
|
|
83
|
+
EPermissionAction2["SUBSCRIBE"] = "subscribe";
|
|
84
|
+
EPermissionAction2["UNSUBSCRIBE"] = "unsubscribe";
|
|
85
|
+
EPermissionAction2["INVITE"] = "invite";
|
|
86
|
+
EPermissionAction2["REVOKE"] = "revoke";
|
|
87
|
+
EPermissionAction2["GRANT"] = "grant";
|
|
88
|
+
EPermissionAction2["DENY"] = "deny";
|
|
89
|
+
EPermissionAction2["BLOCK"] = "block";
|
|
90
|
+
EPermissionAction2["UNBLOCK"] = "unblock";
|
|
91
|
+
EPermissionAction2["REPORT"] = "report";
|
|
92
|
+
EPermissionAction2["MODERATE"] = "moderate";
|
|
93
|
+
EPermissionAction2["BAN"] = "ban";
|
|
94
|
+
EPermissionAction2["UNBAN"] = "unban";
|
|
95
|
+
EPermissionAction2["RESTORE"] = "restore";
|
|
96
|
+
EPermissionAction2["PURGE"] = "purge";
|
|
97
|
+
EPermissionAction2["BACKUP"] = "backup";
|
|
98
|
+
EPermissionAction2["SYNC"] = "sync";
|
|
99
|
+
EPermissionAction2["CONFIGURE"] = "configure";
|
|
100
|
+
EPermissionAction2["MONITOR"] = "monitor";
|
|
101
|
+
EPermissionAction2["AUDIT"] = "audit";
|
|
102
|
+
EPermissionAction2["SEARCH"] = "search";
|
|
103
|
+
EPermissionAction2["FILTER"] = "filter";
|
|
104
|
+
EPermissionAction2["SORT"] = "sort";
|
|
105
|
+
EPermissionAction2["BOOKMARK"] = "bookmark";
|
|
106
|
+
EPermissionAction2["TAG"] = "tag";
|
|
107
|
+
EPermissionAction2["UNTAG"] = "untag";
|
|
108
|
+
EPermissionAction2["LOCK"] = "lock";
|
|
109
|
+
EPermissionAction2["UNLOCK"] = "unlock";
|
|
110
|
+
EPermissionAction2["CLONE"] = "clone";
|
|
111
|
+
EPermissionAction2["FORK"] = "fork";
|
|
112
|
+
EPermissionAction2["MERGE"] = "merge";
|
|
113
|
+
EPermissionAction2["SPLIT"] = "split";
|
|
114
|
+
EPermissionAction2["VALIDATE"] = "validate";
|
|
115
|
+
EPermissionAction2["VERIFY"] = "verify";
|
|
116
|
+
EPermissionAction2["CANCEL"] = "cancel";
|
|
117
|
+
EPermissionAction2["PAUSE"] = "pause";
|
|
118
|
+
EPermissionAction2["RESUME"] = "resume";
|
|
119
|
+
EPermissionAction2["SCHEDULE"] = "schedule";
|
|
120
|
+
EPermissionAction2["UNSCHEDULE"] = "unschedule";
|
|
121
|
+
EPermissionAction2["JOIN"] = "join";
|
|
122
|
+
EPermissionAction2["HIDE"] = "hide";
|
|
123
|
+
})(EPermissionAction ||= {});
|
|
124
|
+
var EPermissionSubject;
|
|
125
|
+
((EPermissionSubject2) => {
|
|
126
|
+
EPermissionSubject2["USER_ENTITY"] = "UserEntity";
|
|
127
|
+
EPermissionSubject2["AUTH_USER_ENTITY"] = "AuthUserEntity";
|
|
128
|
+
EPermissionSubject2["AUTH_USER"] = "AuthUser";
|
|
129
|
+
EPermissionSubject2["SYSTEM_ENTITY"] = "SystemEntity";
|
|
130
|
+
EPermissionSubject2["SYSTEM"] = "System";
|
|
131
|
+
EPermissionSubject2["USER"] = "User";
|
|
132
|
+
EPermissionSubject2["ALL"] = "all";
|
|
133
|
+
})(EPermissionSubject ||= {});
|
|
134
|
+
export {
|
|
135
|
+
decorator,
|
|
136
|
+
PermissionException,
|
|
137
|
+
Permission,
|
|
138
|
+
EPermissionSubject,
|
|
139
|
+
EPermissionAction
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//# debugId=7A183E36D71E4F1964756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/decorators.ts", "src/Permission.ts", "src/PermissionException.ts", "src/types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { container, EContainerScope
|
|
6
|
-
"import { AbilityBuilder, createMongoAbility, type MongoAbility } from \"@casl/ability\";\nimport type { IUser } from \"@ooneex/user\";\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(user: IUser | null): this;\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\");\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\");\n }\n return this.builtAbility.cannot(action as string, subject as string, field);\n }\n}\n",
|
|
7
|
-
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class PermissionException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n this.name = \"PermissionException\";\n }\n}\n",
|
|
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 { IUser } from \"@ooneex/user\";\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(user: IUser | null): this;\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
|
+
"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
8
|
"import type { IUser } from \"@ooneex/user\";\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: (user: IUser | null) => IPermission<A, S>;\n build: () => IPermission<A, S>;\n can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;\n cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": ";
|
|
11
|
-
"debugId": "
|
|
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,EAM/C,KAAK,GAAS;AAAA,IACnB,KAAK,eAAe,KAAK,QAAQ,MAAM;AAAA,IACvC,OAAO;AAAA;AAAA,EAGF,GAAG,CAAC,QAAkC,SAAuB,OAAyB;AAAA,IAC3F,IAAI,CAAC,KAAK,cAAc;AAAA,MACtB,MAAM,IAAI,oBAAoB,sDAAsD,WAAW;AAAA,IACjG;AAAA,IACA,OAAO,KAAK,aAAa,IAAI,QAAkB,SAAmB,KAAK;AAAA;AAAA,EAGlE,MAAM,CAAC,QAAkC,SAAuB,OAAyB;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,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
|
+
"debugId": "7A183E36D71E4F1964756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
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.1.5",
|
|
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.1
|
|
33
|
-
"@ooneex/exception": "1.1.
|
|
34
|
-
"@ooneex/http-status": "1.1.
|
|
32
|
+
"@ooneex/container": "1.2.1",
|
|
33
|
+
"@ooneex/exception": "1.1.3",
|
|
34
|
+
"@ooneex/http-status": "1.1.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@ooneex/user": "1.2.
|
|
37
|
+
"@ooneex/user": "1.2.1"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"authorization",
|