@mahmoud-auth/common 0.0.0-stage → 0.1.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/dist/auth/index.d.ts +2 -0
  4. package/dist/auth/index.js +18 -0
  5. package/dist/auth/types/and/index.d.ts +6 -0
  6. package/dist/auth/types/and/index.js +2 -0
  7. package/dist/auth/types/condition/index.d.ts +9 -0
  8. package/dist/auth/types/condition/index.js +2 -0
  9. package/dist/auth/types/context.type.d.ts +9 -0
  10. package/dist/auth/types/context.type.js +2 -0
  11. package/dist/auth/types/index.d.ts +9 -0
  12. package/dist/auth/types/index.js +25 -0
  13. package/dist/auth/types/not/index.d.ts +6 -0
  14. package/dist/auth/types/not/index.js +2 -0
  15. package/dist/auth/types/or/index.d.ts +6 -0
  16. package/dist/auth/types/or/index.js +2 -0
  17. package/dist/auth/types/permission/index.d.ts +10 -0
  18. package/dist/auth/types/permission/index.js +2 -0
  19. package/dist/auth/types/resource.type.d.ts +7 -0
  20. package/dist/auth/types/resource.type.js +2 -0
  21. package/dist/auth/types/rule.type.d.ts +4 -0
  22. package/dist/auth/types/rule.type.js +2 -0
  23. package/dist/auth/types/tree-node.type.d.ts +16 -0
  24. package/dist/auth/types/tree-node.type.js +3 -0
  25. package/dist/auth/utils/and/index.d.ts +3 -0
  26. package/dist/auth/utils/and/index.js +9 -0
  27. package/dist/auth/utils/condition/index.d.ts +3 -0
  28. package/dist/auth/utils/condition/index.js +9 -0
  29. package/dist/auth/utils/index.d.ts +6 -0
  30. package/dist/auth/utils/index.js +22 -0
  31. package/dist/auth/utils/not/index.d.ts +3 -0
  32. package/dist/auth/utils/not/index.js +9 -0
  33. package/dist/auth/utils/null/index.d.ts +1 -0
  34. package/dist/auth/utils/null/index.js +7 -0
  35. package/dist/auth/utils/or/index.d.ts +3 -0
  36. package/dist/auth/utils/or/index.js +9 -0
  37. package/dist/auth/utils/permission/index.d.ts +3 -0
  38. package/dist/auth/utils/permission/index.js +9 -0
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.js +17 -0
  41. package/package.json +32 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Mahmoud Project contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @mahmoud-auth/common
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared authorization rules, resource tokens, and context types used by the Mahmoud NestJS packages.
4
+
5
+ ```sh
6
+ npm install @mahmoud-auth/common
7
+ ```
8
+
9
+ This package exposes its public API from the package root. It requires `@nestjs/common` as a peer dependency.
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './utils';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,6 @@
1
+ import { RuleNode } from '../rule.type';
2
+ export interface IAndRule extends RuleNode {
3
+ type: 'and';
4
+ children: RuleNode[];
5
+ }
6
+ export type ITreeAndNode = IAndRule;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { IAuthorizationContext } from "../context.type";
2
+ import { RuleNode } from '../rule.type';
3
+ export type IConditionExecute = (context: IAuthorizationContext) => boolean | Promise<boolean>;
4
+ export interface IConditionRule extends RuleNode {
5
+ type: 'condition';
6
+ execute: IConditionExecute;
7
+ description?: string;
8
+ }
9
+ export type ITreeConditionNode = Pick<IConditionRule, 'type' | 'description'>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Type } from "@nestjs/common";
2
+ export type ExtensionResolver = <TExtension>(extension: Type<TExtension>) => InstanceType<Type<TExtension>>;
3
+ export interface IAuthorizationContext<TRequest = Request> {
4
+ user: unknown;
5
+ data?: unknown;
6
+ request: () => TRequest;
7
+ use: ExtensionResolver;
8
+ get<T>(resource: Type<T>): Promise<T | undefined>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export * from './rule.type';
2
+ export * from './resource.type';
3
+ export * from './context.type';
4
+ export * from './tree-node.type';
5
+ export * from './and';
6
+ export * from './condition';
7
+ export * from './not';
8
+ export * from './or';
9
+ export * from './permission';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./rule.type"), exports);
18
+ __exportStar(require("./resource.type"), exports);
19
+ __exportStar(require("./context.type"), exports);
20
+ __exportStar(require("./tree-node.type"), exports);
21
+ __exportStar(require("./and"), exports);
22
+ __exportStar(require("./condition"), exports);
23
+ __exportStar(require("./not"), exports);
24
+ __exportStar(require("./or"), exports);
25
+ __exportStar(require("./permission"), exports);
@@ -0,0 +1,6 @@
1
+ import { RuleNode } from '../rule.type';
2
+ export interface INotRule extends RuleNode {
3
+ type: 'not';
4
+ child: RuleNode;
5
+ }
6
+ export type ITreeNotNode = INotRule;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { RuleNode } from '../rule.type';
2
+ export interface IOrRule extends RuleNode {
3
+ type: 'or';
4
+ children: RuleNode[];
5
+ }
6
+ export type ITreeOrNode = IOrRule;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { IResourceToken } from "../resource.type";
2
+ import { RuleNode } from '../rule.type';
3
+ export interface IPermissionRule<T = unknown> extends RuleNode {
4
+ type: 'permission';
5
+ resource: IResourceToken<T>;
6
+ action: string;
7
+ }
8
+ export type ITreePermissionNode = Pick<IPermissionRule, 'type'> & {
9
+ target: string;
10
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { Type } from "@nestjs/common";
2
+ export interface IResourceToken<T, TActions extends string[] = string[]> {
3
+ name: string;
4
+ model: Type<T>;
5
+ actions: TActions;
6
+ mahmoudId: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type RuleType = 'permission' | 'condition' | 'and' | 'or' | 'not';
2
+ export interface RuleNode {
3
+ readonly type: RuleType;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { RuleNode } from './rule.type';
2
+ export interface ITreeNode {
3
+ id: string;
4
+ resource: string;
5
+ action: string;
6
+ rule: RuleNode;
7
+ }
8
+ export interface ITreeEdge {
9
+ from: string;
10
+ to: string;
11
+ type: 'requires';
12
+ }
13
+ export interface IAuthorizationGraphDto {
14
+ nodes: ITreeNode[];
15
+ edges: ITreeEdge[];
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,3 @@
1
+ import { IAndRule, ITreeAndNode, RuleNode } from "../../types";
2
+ export declare const isAndRule: (rule: RuleNode) => rule is IAndRule;
3
+ export declare const isTreeAndNode: (rule: RuleNode) => rule is ITreeAndNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTreeAndNode = exports.isAndRule = void 0;
4
+ const isAndRule = (rule) => {
5
+ return rule.type === 'and';
6
+ };
7
+ exports.isAndRule = isAndRule;
8
+ const isTreeAndNode = (rule) => (0, exports.isAndRule)(rule);
9
+ exports.isTreeAndNode = isTreeAndNode;
@@ -0,0 +1,3 @@
1
+ import { IConditionRule, ITreeConditionNode, RuleNode } from "../../types";
2
+ export declare const isConditionRule: (rule: RuleNode) => rule is IConditionRule;
3
+ export declare const isTreeConditionNode: (rule: RuleNode) => rule is ITreeConditionNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTreeConditionNode = exports.isConditionRule = void 0;
4
+ const isConditionRule = (rule) => {
5
+ return rule.type === 'condition';
6
+ };
7
+ exports.isConditionRule = isConditionRule;
8
+ const isTreeConditionNode = (rule) => (0, exports.isConditionRule)(rule);
9
+ exports.isTreeConditionNode = isTreeConditionNode;
@@ -0,0 +1,6 @@
1
+ export * from './and';
2
+ export * from './condition';
3
+ export * from './not';
4
+ export * from './or';
5
+ export * from './permission';
6
+ export * from './null';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./and"), exports);
18
+ __exportStar(require("./condition"), exports);
19
+ __exportStar(require("./not"), exports);
20
+ __exportStar(require("./or"), exports);
21
+ __exportStar(require("./permission"), exports);
22
+ __exportStar(require("./null"), exports);
@@ -0,0 +1,3 @@
1
+ import { INotRule, ITreeNotNode, RuleNode } from "../../types";
2
+ export declare const isNotRule: (rule: RuleNode) => rule is INotRule;
3
+ export declare const isTreeNotNode: (rule: RuleNode) => rule is ITreeNotNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTreeNotNode = exports.isNotRule = void 0;
4
+ const isNotRule = (rule) => {
5
+ return rule.type === 'not';
6
+ };
7
+ exports.isNotRule = isNotRule;
8
+ const isTreeNotNode = (rule) => (0, exports.isNotRule)(rule);
9
+ exports.isTreeNotNode = isTreeNotNode;
@@ -0,0 +1 @@
1
+ export declare const isNotNull: <T>(arrayItem: T) => arrayItem is NonNullable<T>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotNull = void 0;
4
+ const isNotNull = (arrayItem) => {
5
+ return arrayItem != null;
6
+ };
7
+ exports.isNotNull = isNotNull;
@@ -0,0 +1,3 @@
1
+ import { IOrRule, ITreeOrNode, RuleNode } from "../../types";
2
+ export declare const isOrRule: (rule: RuleNode) => rule is IOrRule;
3
+ export declare const isTreeOrNode: (rule: RuleNode) => rule is ITreeOrNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTreeOrNode = exports.isOrRule = void 0;
4
+ const isOrRule = (rule) => {
5
+ return rule.type === 'or';
6
+ };
7
+ exports.isOrRule = isOrRule;
8
+ const isTreeOrNode = (rule) => (0, exports.isOrRule)(rule);
9
+ exports.isTreeOrNode = isTreeOrNode;
@@ -0,0 +1,3 @@
1
+ import { IPermissionRule, ITreePermissionNode, RuleNode } from "../../types";
2
+ export declare const isPermissionRule: (rule: RuleNode) => rule is IPermissionRule;
3
+ export declare const isTreePermissionNode: (rule: RuleNode) => rule is ITreePermissionNode;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTreePermissionNode = exports.isPermissionRule = void 0;
4
+ const isPermissionRule = (rule) => {
5
+ return rule.type === 'permission';
6
+ };
7
+ exports.isPermissionRule = isPermissionRule;
8
+ const isTreePermissionNode = (rule) => (0, exports.isPermissionRule)(rule);
9
+ exports.isTreePermissionNode = isTreePermissionNode;
@@ -0,0 +1 @@
1
+ export * from './auth';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth"), exports);
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@mahmoud-auth/common",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Shared authorization and resource types for Mahmoud NestJS packages.",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md", "LICENSE"],
15
+ "scripts": {
16
+ "clean": "rimraf dist",
17
+ "build": "rimraf dist && tsc -p tsconfig.build.json",
18
+ "prepack": "npm run build"
19
+ },
20
+ "peerDependencies": {
21
+ "@nestjs/common": "^11.0.0"
22
+ },
23
+ "engines": {
24
+ "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/shahariko-lab/nestjs-rebac.git",
32
+ "directory": "packages/mahmoud/common"
33
+ }
34
+ }