@ooneex/permission 0.0.14 → 0.0.15
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.js +2 -139
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,141 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
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";
|
|
2
|
+
import{container as r,EContainerScope as h}from"@ooneex/container";var f={permission:(t=h.Singleton)=>{return(p)=>{r.add(p,t)}}};import{AbilityBuilder as e,createMongoAbility as x}from"@casl/ability";import{Exception as g}from"@ooneex/exception";import{HttpStatus as d}from"@ooneex/http-status";class b extends g{constructor(t,p={}){super(t,{status:d.Code.InternalServerError,data:p});this.name="PermissionException"}}class y{ability;builtAbility=null;constructor(){this.ability=new e(x)}build(){return this.builtAbility=this.ability.build(),this}can(t,p,u){if(!this.builtAbility)throw new b("Permission must be built before checking abilities");return this.builtAbility.can(t,p,u)}cannot(t,p,u){if(!this.builtAbility)throw new b("Permission must be built before checking abilities");return this.builtAbility.cannot(t,p,u)}}var w;((l)=>{l.CREATE="create";l.READ="read";l.UPDATE="update";l.DELETE="delete";l.MANAGE="manage";l.VIEW="view";l.EDIT="edit";l.PUBLISH="publish";l.ARCHIVE="archive";l.APPROVE="approve";l.REJECT="reject";l.DOWNLOAD="download";l.UPLOAD="upload";l.SHARE="share";l.COPY="copy";l.MOVE="move";l.EXPORT="export";l.IMPORT="import";l.EXECUTE="execute";l.ASSIGN="assign";l.UNASSIGN="unassign";l.COMMENT="comment";l.RATE="rate";l.LIKE="like";l.DISLIKE="dislike";l.FOLLOW="follow";l.UNFOLLOW="unfollow";l.SUBSCRIBE="subscribe";l.UNSUBSCRIBE="unsubscribe";l.INVITE="invite";l.REVOKE="revoke";l.GRANT="grant";l.DENY="deny";l.BLOCK="block";l.UNBLOCK="unblock";l.REPORT="report";l.MODERATE="moderate";l.BAN="ban";l.UNBAN="unban";l.RESTORE="restore";l.PURGE="purge";l.BACKUP="backup";l.SYNC="sync";l.CONFIGURE="configure";l.MONITOR="monitor";l.AUDIT="audit";l.SEARCH="search";l.FILTER="filter";l.SORT="sort";l.BOOKMARK="bookmark";l.TAG="tag";l.UNTAG="untag";l.LOCK="lock";l.UNLOCK="unlock";l.CLONE="clone";l.FORK="fork";l.MERGE="merge";l.SPLIT="split";l.VALIDATE="validate";l.VERIFY="verify";l.CANCEL="cancel";l.PAUSE="pause";l.RESUME="resume";l.SCHEDULE="schedule";l.UNSCHEDULE="unschedule";l.JOIN="join";l.HIDE="hide"})(w||={});var C;((a)=>{a.USER_ENTITY="UserEntity";a.AUTH_USER_ENTITY="AuthUserEntity";a.AUTH_USER="AuthUser";a.SYSTEM_ENTITY="SystemEntity";a.SYSTEM="System";a.USER="User";a.ALL="all"})(C||={});export{f as decorator,b as PermissionException,y as Permission,C as EPermissionSubject,w as EPermissionAction};
|
|
13
3
|
|
|
14
|
-
|
|
15
|
-
import { Exception } from "@ooneex/exception";
|
|
16
|
-
import { HttpStatus } from "@ooneex/http-status";
|
|
17
|
-
|
|
18
|
-
class PermissionException extends Exception {
|
|
19
|
-
constructor(message, data = {}) {
|
|
20
|
-
super(message, {
|
|
21
|
-
status: HttpStatus.Code.InternalServerError,
|
|
22
|
-
data
|
|
23
|
-
});
|
|
24
|
-
this.name = "PermissionException";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// src/Permission.ts
|
|
29
|
-
class Permission {
|
|
30
|
-
ability;
|
|
31
|
-
builtAbility = null;
|
|
32
|
-
constructor() {
|
|
33
|
-
this.ability = new AbilityBuilder(createMongoAbility);
|
|
34
|
-
}
|
|
35
|
-
build() {
|
|
36
|
-
this.builtAbility = this.ability.build();
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
can(action, subject, field) {
|
|
40
|
-
if (!this.builtAbility) {
|
|
41
|
-
throw new PermissionException("Permission must be built before checking abilities");
|
|
42
|
-
}
|
|
43
|
-
return this.builtAbility.can(action, subject, field);
|
|
44
|
-
}
|
|
45
|
-
cannot(action, subject, field) {
|
|
46
|
-
if (!this.builtAbility) {
|
|
47
|
-
throw new PermissionException("Permission must be built before checking abilities");
|
|
48
|
-
}
|
|
49
|
-
return this.builtAbility.cannot(action, subject, field);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// src/types.ts
|
|
53
|
-
var EPermissionAction;
|
|
54
|
-
((EPermissionAction2) => {
|
|
55
|
-
EPermissionAction2["CREATE"] = "create";
|
|
56
|
-
EPermissionAction2["READ"] = "read";
|
|
57
|
-
EPermissionAction2["UPDATE"] = "update";
|
|
58
|
-
EPermissionAction2["DELETE"] = "delete";
|
|
59
|
-
EPermissionAction2["MANAGE"] = "manage";
|
|
60
|
-
EPermissionAction2["VIEW"] = "view";
|
|
61
|
-
EPermissionAction2["EDIT"] = "edit";
|
|
62
|
-
EPermissionAction2["PUBLISH"] = "publish";
|
|
63
|
-
EPermissionAction2["ARCHIVE"] = "archive";
|
|
64
|
-
EPermissionAction2["APPROVE"] = "approve";
|
|
65
|
-
EPermissionAction2["REJECT"] = "reject";
|
|
66
|
-
EPermissionAction2["DOWNLOAD"] = "download";
|
|
67
|
-
EPermissionAction2["UPLOAD"] = "upload";
|
|
68
|
-
EPermissionAction2["SHARE"] = "share";
|
|
69
|
-
EPermissionAction2["COPY"] = "copy";
|
|
70
|
-
EPermissionAction2["MOVE"] = "move";
|
|
71
|
-
EPermissionAction2["EXPORT"] = "export";
|
|
72
|
-
EPermissionAction2["IMPORT"] = "import";
|
|
73
|
-
EPermissionAction2["EXECUTE"] = "execute";
|
|
74
|
-
EPermissionAction2["ASSIGN"] = "assign";
|
|
75
|
-
EPermissionAction2["UNASSIGN"] = "unassign";
|
|
76
|
-
EPermissionAction2["COMMENT"] = "comment";
|
|
77
|
-
EPermissionAction2["RATE"] = "rate";
|
|
78
|
-
EPermissionAction2["LIKE"] = "like";
|
|
79
|
-
EPermissionAction2["DISLIKE"] = "dislike";
|
|
80
|
-
EPermissionAction2["FOLLOW"] = "follow";
|
|
81
|
-
EPermissionAction2["UNFOLLOW"] = "unfollow";
|
|
82
|
-
EPermissionAction2["SUBSCRIBE"] = "subscribe";
|
|
83
|
-
EPermissionAction2["UNSUBSCRIBE"] = "unsubscribe";
|
|
84
|
-
EPermissionAction2["INVITE"] = "invite";
|
|
85
|
-
EPermissionAction2["REVOKE"] = "revoke";
|
|
86
|
-
EPermissionAction2["GRANT"] = "grant";
|
|
87
|
-
EPermissionAction2["DENY"] = "deny";
|
|
88
|
-
EPermissionAction2["BLOCK"] = "block";
|
|
89
|
-
EPermissionAction2["UNBLOCK"] = "unblock";
|
|
90
|
-
EPermissionAction2["REPORT"] = "report";
|
|
91
|
-
EPermissionAction2["MODERATE"] = "moderate";
|
|
92
|
-
EPermissionAction2["BAN"] = "ban";
|
|
93
|
-
EPermissionAction2["UNBAN"] = "unban";
|
|
94
|
-
EPermissionAction2["RESTORE"] = "restore";
|
|
95
|
-
EPermissionAction2["PURGE"] = "purge";
|
|
96
|
-
EPermissionAction2["BACKUP"] = "backup";
|
|
97
|
-
EPermissionAction2["SYNC"] = "sync";
|
|
98
|
-
EPermissionAction2["CONFIGURE"] = "configure";
|
|
99
|
-
EPermissionAction2["MONITOR"] = "monitor";
|
|
100
|
-
EPermissionAction2["AUDIT"] = "audit";
|
|
101
|
-
EPermissionAction2["SEARCH"] = "search";
|
|
102
|
-
EPermissionAction2["FILTER"] = "filter";
|
|
103
|
-
EPermissionAction2["SORT"] = "sort";
|
|
104
|
-
EPermissionAction2["BOOKMARK"] = "bookmark";
|
|
105
|
-
EPermissionAction2["TAG"] = "tag";
|
|
106
|
-
EPermissionAction2["UNTAG"] = "untag";
|
|
107
|
-
EPermissionAction2["LOCK"] = "lock";
|
|
108
|
-
EPermissionAction2["UNLOCK"] = "unlock";
|
|
109
|
-
EPermissionAction2["CLONE"] = "clone";
|
|
110
|
-
EPermissionAction2["FORK"] = "fork";
|
|
111
|
-
EPermissionAction2["MERGE"] = "merge";
|
|
112
|
-
EPermissionAction2["SPLIT"] = "split";
|
|
113
|
-
EPermissionAction2["VALIDATE"] = "validate";
|
|
114
|
-
EPermissionAction2["VERIFY"] = "verify";
|
|
115
|
-
EPermissionAction2["CANCEL"] = "cancel";
|
|
116
|
-
EPermissionAction2["PAUSE"] = "pause";
|
|
117
|
-
EPermissionAction2["RESUME"] = "resume";
|
|
118
|
-
EPermissionAction2["SCHEDULE"] = "schedule";
|
|
119
|
-
EPermissionAction2["UNSCHEDULE"] = "unschedule";
|
|
120
|
-
EPermissionAction2["JOIN"] = "join";
|
|
121
|
-
EPermissionAction2["HIDE"] = "hide";
|
|
122
|
-
})(EPermissionAction ||= {});
|
|
123
|
-
var EPermissionSubject;
|
|
124
|
-
((EPermissionSubject2) => {
|
|
125
|
-
EPermissionSubject2["USER_ENTITY"] = "UserEntity";
|
|
126
|
-
EPermissionSubject2["AUTH_USER_ENTITY"] = "AuthUserEntity";
|
|
127
|
-
EPermissionSubject2["AUTH_USER"] = "AuthUser";
|
|
128
|
-
EPermissionSubject2["SYSTEM_ENTITY"] = "SystemEntity";
|
|
129
|
-
EPermissionSubject2["SYSTEM"] = "System";
|
|
130
|
-
EPermissionSubject2["USER"] = "User";
|
|
131
|
-
EPermissionSubject2["ALL"] = "all";
|
|
132
|
-
})(EPermissionSubject ||= {});
|
|
133
|
-
export {
|
|
134
|
-
decorator,
|
|
135
|
-
PermissionException,
|
|
136
|
-
Permission,
|
|
137
|
-
EPermissionSubject,
|
|
138
|
-
EPermissionAction
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
//# debugId=F064C0004E35C3E064756E2164756E21
|
|
4
|
+
//# debugId=2AFA4E169117EE2564756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
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",
|
|
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<S extends string = string> {\n allow: () => IPermission<S>;\n forbid: () => IPermission<S>;\n setUserPermissions: (user: IUser | null) => IPermission<S>;\n check: () => Promise<boolean>;\n build: () => IPermission<S>;\n can: (action: PermissionActionType, subject: Subjects | S, field?: string) => boolean;\n cannot: (action: PermissionActionType, subject: Subjects | S, field?: string) => boolean;\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";AAAA,oBAAS,qBAAW,0BAGb,IAAM,EAAY,CACvB,WAAY,CAAC,EAAyB,EAAgB,YAAc,CAClE,MAAO,CAAC,IAAsC,CAC5C,EAAU,IAAI,EAAQ,CAAK,GAGjC,ECTA,yBAAS,wBAAgB,sBCAzB,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA4B,CAAU,CACjD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,M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