@ooneex/permission 1.1.12 → 1.1.14
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 +61 -9
- package/dist/index.js.map +3 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
import { EContainerScope } from "@ooneex/container";
|
|
2
|
+
import { IAnalytics } from "@ooneex/analytics";
|
|
3
|
+
import { IAppEnv } from "@ooneex/app-env";
|
|
4
|
+
import { ICache } from "@ooneex/cache";
|
|
5
|
+
import { IDatabase } from "@ooneex/database";
|
|
6
|
+
import { Header } from "@ooneex/http-header";
|
|
7
|
+
import { IRequest, RequestConfigType } from "@ooneex/http-request";
|
|
8
|
+
import { IRequestFile } from "@ooneex/http-request-file";
|
|
9
|
+
import { IResponse } from "@ooneex/http-response";
|
|
10
|
+
import { ILogger, LogsEntity } from "@ooneex/logger";
|
|
11
|
+
import { IMailer } from "@ooneex/mailer";
|
|
12
|
+
import { IPermission } from "@ooneex/permission";
|
|
13
|
+
import { IRateLimiter } from "@ooneex/rate-limit";
|
|
14
|
+
import { ERole } from "@ooneex/role";
|
|
15
|
+
import { IStorage } from "@ooneex/storage";
|
|
16
|
+
import { LocaleInfoType } from "@ooneex/translation";
|
|
17
|
+
import { HttpMethodType, ScalarType } from "@ooneex/types";
|
|
2
18
|
import { IUser } from "@ooneex/user";
|
|
19
|
+
type ContextConfigType = {
|
|
20
|
+
response: Record<string, any>;
|
|
21
|
+
} & Partial<RequestConfigType>;
|
|
22
|
+
type ContextType<T extends ContextConfigType = ContextConfigType> = {
|
|
23
|
+
logger: ILogger<Record<string, ScalarType>> | ILogger<LogsEntity>;
|
|
24
|
+
exceptionLogger?: ILogger;
|
|
25
|
+
analytics?: IAnalytics;
|
|
26
|
+
cache?: ICache;
|
|
27
|
+
storage?: IStorage;
|
|
28
|
+
mailer?: IMailer;
|
|
29
|
+
rateLimiter?: IRateLimiter;
|
|
30
|
+
database: IDatabase;
|
|
31
|
+
route?: {
|
|
32
|
+
name: string;
|
|
33
|
+
path: `/${string}`;
|
|
34
|
+
method: HttpMethodType;
|
|
35
|
+
version: number;
|
|
36
|
+
description: string;
|
|
37
|
+
roles?: ERole[];
|
|
38
|
+
} | null;
|
|
39
|
+
env: IAppEnv;
|
|
40
|
+
response: IResponse<T["response"]>;
|
|
41
|
+
request: IRequest<Omit<RequestConfigType, "response">>;
|
|
42
|
+
params: T["params"];
|
|
43
|
+
payload: T["payload"];
|
|
44
|
+
queries: T["queries"];
|
|
45
|
+
method: HttpMethodType;
|
|
46
|
+
header: Header;
|
|
47
|
+
files: Record<string, IRequestFile>;
|
|
48
|
+
ip: string | null;
|
|
49
|
+
host: string;
|
|
50
|
+
lang: LocaleInfoType;
|
|
51
|
+
user: IUser | null;
|
|
52
|
+
permission?: IPermission;
|
|
53
|
+
};
|
|
3
54
|
declare enum EPermissionAction {
|
|
4
55
|
CREATE = "create",
|
|
5
56
|
READ = "read",
|
|
@@ -80,14 +131,15 @@ declare enum EPermissionSubject {
|
|
|
80
131
|
}
|
|
81
132
|
type PermissionActionType = `${EPermissionAction}`;
|
|
82
133
|
type Subjects = `${EPermissionSubject}`;
|
|
83
|
-
type PermissionClassType = new (...args: any[]) =>
|
|
84
|
-
interface
|
|
134
|
+
type PermissionClassType = new (...args: any[]) => IPermission2;
|
|
135
|
+
interface IPermission2<
|
|
85
136
|
A extends string = string,
|
|
86
137
|
S extends string = string
|
|
87
138
|
> {
|
|
88
|
-
allow: () =>
|
|
89
|
-
setUserPermissions: (
|
|
90
|
-
build: () =>
|
|
139
|
+
allow: () => IPermission2<A, S>;
|
|
140
|
+
setUserPermissions: (context: ContextType) => IPermission2<A, S>;
|
|
141
|
+
build: () => IPermission2<A, S>;
|
|
142
|
+
check: (context: ContextType) => boolean;
|
|
91
143
|
can: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;
|
|
92
144
|
cannot: (action: PermissionActionType | A, subject: Subjects | S, field?: string) => boolean;
|
|
93
145
|
}
|
|
@@ -95,15 +147,15 @@ declare const decorator: {
|
|
|
95
147
|
permission: (scope?: EContainerScope) => (target: PermissionClassType) => void;
|
|
96
148
|
};
|
|
97
149
|
import { AbilityBuilder, MongoAbility } from "@casl/ability";
|
|
98
|
-
import { IUser as IUser2 } from "@ooneex/user";
|
|
99
150
|
declare abstract class Permission<
|
|
100
151
|
A extends string = string,
|
|
101
152
|
S extends string = string
|
|
102
|
-
> implements
|
|
153
|
+
> implements IPermission2<A, S> {
|
|
103
154
|
protected ability: AbilityBuilder<MongoAbility>;
|
|
104
155
|
private builtAbility;
|
|
105
156
|
constructor();
|
|
106
|
-
abstract setUserPermissions(
|
|
157
|
+
abstract setUserPermissions(context: ContextType): this;
|
|
158
|
+
abstract check(context: ContextType): boolean;
|
|
107
159
|
build(): this;
|
|
108
160
|
can(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean;
|
|
109
161
|
cannot(action: PermissionActionType | A, subject: Subjects | S, field?: string): boolean;
|
|
@@ -112,4 +164,4 @@ import { Exception } from "@ooneex/exception";
|
|
|
112
164
|
declare class PermissionException extends Exception {
|
|
113
165
|
constructor(message: string, key: string, data?: Record<string, unknown>);
|
|
114
166
|
}
|
|
115
|
-
export { decorator, Subjects, PermissionException, PermissionClassType, PermissionActionType, Permission, IPermission, EPermissionSubject, EPermissionAction };
|
|
167
|
+
export { decorator, Subjects, PermissionException, PermissionClassType, PermissionActionType, Permission, IPermission2 as IPermission, EPermissionSubject, EPermissionAction };
|
package/dist/index.js.map
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
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 {
|
|
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",
|
|
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 {
|
|
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"
|
|
9
9
|
],
|
|
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,
|
|
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,WAA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AAW;AAAA,EACX,kCAAY;AAAA,EACZ,oCAAc;AAAA,EACd,+BAAS;AAAA,EACT,+BAAS;AAAA,EACT,8BAAQ;AAAA,EACR,6BAAO;AAAA,EACP,8BAAQ;AAAA,EACR,gCAAU;AAAA,EACV,+BAAS;AAAA,EACT,iCAAW;AAAA,EACX,4BAAM;AAAA,EACN,8BAAQ;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",
|
|
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.14",
|
|
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.4.
|
|
33
|
-
"@ooneex/exception": "^1.2.
|
|
34
|
-
"@ooneex/http-status": "^1.1.
|
|
32
|
+
"@ooneex/container": "^1.4.5",
|
|
33
|
+
"@ooneex/exception": "^1.2.8",
|
|
34
|
+
"@ooneex/http-status": "^1.1.10"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@ooneex/user": "^1.2.
|
|
37
|
+
"@ooneex/user": "^1.2.9"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"authorization",
|