@ooneex/permission 1.1.2 → 1.1.3

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 CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{container as r,EContainerScope as g}from"@ooneex/container";var f={permission:(t=g.Singleton)=>{return(p)=>{r.add(p,t)}}};import{AbilityBuilder as x,createMongoAbility as e}from"@casl/ability";import{Exception as h}from"@ooneex/exception";import{HttpStatus as d}from"@ooneex/http-status";class b extends h{constructor(t,p={}){super(t,{status:d.Code.InternalServerError,data:p});this.name="PermissionException"}}class y{ability;builtAbility=null;constructor(){this.ability=new x(e)}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};
2
+ import{container as r,EContainerScope as g,injectable as f}from"@ooneex/container";var h={permission:(p=g.Singleton)=>{return(t)=>{f()(t),r.add(t,p)}}};import{AbilityBuilder as e,createMongoAbility as w}from"@casl/ability";import{Exception as d}from"@ooneex/exception";import{HttpStatus as x}from"@ooneex/http-status";class b extends d{constructor(p,t={}){super(p,{status:x.Code.InternalServerError,data:t});this.name="PermissionException"}}class y{ability;builtAbility=null;constructor(){this.ability=new e(w)}build(){return this.builtAbility=this.ability.build(),this}can(p,t,u){if(!this.builtAbility)throw new b("Permission must be built before checking abilities");return this.builtAbility.can(p,t,u)}cannot(p,t,u){if(!this.builtAbility)throw new b("Permission must be built before checking abilities");return this.builtAbility.cannot(p,t,u)}}var C;((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"})(C||={});var I;((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"})(I||={});export{h as decorator,b as PermissionException,y as Permission,I as EPermissionSubject,C as EPermissionAction};
3
3
 
4
- //# debugId=A85316E63625015764756E2164756E21
4
+ //# debugId=C15BC651FA62561564756E2164756E21
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 } 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",
5
+ "import { container, EContainerScope, injectable } from \"@ooneex/container\";\nimport type { PermissionClassType } from \"./types\";\n\nexport const decorator = {\n permission: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: PermissionClassType): void => {\n injectable()(target);\n container.add(target, scope);\n };\n },\n};\n",
6
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
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<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": ";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,MACF,CAAC,EACD,KAAK,KAAO,sBAEhB,CDNO,MAAe,CAA8F,CACxG,QACF,aAAoC,KAE5C,WAAW,EAAG,CACZ,KAAK,QAAU,IAAI,EAAe,CAAkB,EAM/C,KAAK,EAAS,CAEnB,OADA,KAAK,aAAe,KAAK,QAAQ,MAAM,EAChC,KAGF,GAAG,CAAC,EAAkC,EAAuB,EAAyB,CAC3F,GAAI,CAAC,KAAK,aACR,MAAM,IAAI,EAAoB,oDAAoD,EAEpF,OAAO,KAAK,aAAa,IAAI,EAAkB,EAAmB,CAAK,EAGlE,MAAM,CAAC,EAAkC,EAAuB,EAAyB,CAC9F,GAAI,CAAC,KAAK,aACR,MAAM,IAAI,EAAoB,oDAAoD,EAEpF,OAAO,KAAK,aAAa,OAAO,EAAkB,EAAmB,CAAK,EAE9E,CEhCO,IAAK,GAAL,CAAK,IAAL,CACL,SAAS,SACT,OAAO,OACP,SAAS,SACT,SAAS,SACT,SAAS,SACT,OAAO,OACP,OAAO,OACP,UAAU,UACV,UAAU,UACV,UAAU,UACV,SAAS,SACT,WAAW,WACX,SAAS,SACT,QAAQ,QACR,OAAO,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AAgB,eAChB,SAAS,SACT,OAAO,OACP,MAAM,QAPI",
11
+ "debugId": "C15BC651FA62561564756E2164756E21",
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.2",
4
+ "version": "1.1.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -34,7 +34,7 @@
34
34
  "@ooneex/http-status": "1.1.2"
35
35
  },
36
36
  "devDependencies": {
37
- "@ooneex/user": "1.1.2"
37
+ "@ooneex/user": "1.2.0"
38
38
  },
39
39
  "keywords": [
40
40
  "authorization",