@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.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +18 -0
- package/dist/auth/types/and/index.d.ts +6 -0
- package/dist/auth/types/and/index.js +2 -0
- package/dist/auth/types/condition/index.d.ts +9 -0
- package/dist/auth/types/condition/index.js +2 -0
- package/dist/auth/types/context.type.d.ts +9 -0
- package/dist/auth/types/context.type.js +2 -0
- package/dist/auth/types/index.d.ts +9 -0
- package/dist/auth/types/index.js +25 -0
- package/dist/auth/types/not/index.d.ts +6 -0
- package/dist/auth/types/not/index.js +2 -0
- package/dist/auth/types/or/index.d.ts +6 -0
- package/dist/auth/types/or/index.js +2 -0
- package/dist/auth/types/permission/index.d.ts +10 -0
- package/dist/auth/types/permission/index.js +2 -0
- package/dist/auth/types/resource.type.d.ts +7 -0
- package/dist/auth/types/resource.type.js +2 -0
- package/dist/auth/types/rule.type.d.ts +4 -0
- package/dist/auth/types/rule.type.js +2 -0
- package/dist/auth/types/tree-node.type.d.ts +16 -0
- package/dist/auth/types/tree-node.type.js +3 -0
- package/dist/auth/utils/and/index.d.ts +3 -0
- package/dist/auth/utils/and/index.js +9 -0
- package/dist/auth/utils/condition/index.d.ts +3 -0
- package/dist/auth/utils/condition/index.js +9 -0
- package/dist/auth/utils/index.d.ts +6 -0
- package/dist/auth/utils/index.js +22 -0
- package/dist/auth/utils/not/index.d.ts +3 -0
- package/dist/auth/utils/not/index.js +9 -0
- package/dist/auth/utils/null/index.d.ts +1 -0
- package/dist/auth/utils/null/index.js +7 -0
- package/dist/auth/utils/or/index.d.ts +3 -0
- package/dist/auth/utils/or/index.js +9 -0
- package/dist/auth/utils/permission/index.d.ts +3 -0
- package/dist/auth/utils/permission/index.js +9 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- 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
|
-
#
|
|
1
|
+
# @mahmoud-auth/common
|
|
2
2
|
|
|
3
|
-
|
|
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,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,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,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,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,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,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,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,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,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,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,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,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;
|
package/dist/index.d.ts
ADDED
|
@@ -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.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
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
|
+
}
|