@ahksolution/permissions-sdk 1.0.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/README.md +290 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +19 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/permissions-client.module.d.ts +74 -0
- package/dist/client/permissions-client.module.d.ts.map +1 -0
- package/dist/client/permissions-client.module.js +109 -0
- package/dist/client/permissions-client.module.js.map +1 -0
- package/dist/client/permissions-grpc.client.d.ts +45 -0
- package/dist/client/permissions-grpc.client.d.ts.map +1 -0
- package/dist/client/permissions-grpc.client.js +182 -0
- package/dist/client/permissions-grpc.client.js.map +1 -0
- package/dist/constants.d.ts +44 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +48 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +18 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/require-permissions.decorator.d.ts +51 -0
- package/dist/decorators/require-permissions.decorator.d.ts.map +1 -0
- package/dist/decorators/require-permissions.decorator.js +69 -0
- package/dist/decorators/require-permissions.decorator.js.map +1 -0
- package/dist/guards/index.d.ts +2 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +18 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/permissions.guard.d.ts +55 -0
- package/dist/guards/permissions.guard.d.ts.map +1 -0
- package/dist/guards/permissions.guard.js +139 -0
- package/dist/guards/permissions.guard.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/proto/permissions.proto +150 -0
- package/dist/types/evaluation.types.d.ts +80 -0
- package/dist/types/evaluation.types.d.ts.map +1 -0
- package/dist/types/evaluation.types.js +14 -0
- package/dist/types/evaluation.types.js.map +1 -0
- package/dist/types/grpc.types.d.ts +97 -0
- package/dist/types/grpc.types.d.ts.map +1 -0
- package/dist/types/grpc.types.js +15 -0
- package/dist/types/grpc.types.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/permission.types.d.ts +51 -0
- package/dist/types/permission.types.d.ts.map +1 -0
- package/dist/types/permission.types.js +8 -0
- package/dist/types/permission.types.js.map +1 -0
- package/package.json +60 -0
- package/src/proto/permissions.proto +150 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var PermissionsGuard_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PermissionsGuard = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
16
|
+
const permissions_grpc_client_1 = require("../client/permissions-grpc.client");
|
|
17
|
+
const types_1 = require("../types");
|
|
18
|
+
/**
|
|
19
|
+
* NestJS Guard that checks permissions via the Permissions gRPC Service
|
|
20
|
+
*
|
|
21
|
+
* This guard:
|
|
22
|
+
* 1. Extracts permission requirements from the @RequirePermissions decorator
|
|
23
|
+
* 2. Gets the user ID from the request (expects JWT auth to have run first)
|
|
24
|
+
* 3. Calls the permissions microservice via gRPC to verify access
|
|
25
|
+
* 4. Throws ForbiddenException if permission is denied
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Use globally
|
|
30
|
+
* @Module({
|
|
31
|
+
* providers: [
|
|
32
|
+
* {
|
|
33
|
+
* provide: APP_GUARD,
|
|
34
|
+
* useClass: PermissionsGuard,
|
|
35
|
+
* },
|
|
36
|
+
* ],
|
|
37
|
+
* })
|
|
38
|
+
* export class AppModule {}
|
|
39
|
+
*
|
|
40
|
+
* // Or use on specific controllers/routes
|
|
41
|
+
* @Controller('orders')
|
|
42
|
+
* @UseGuards(JwtAuthGuard, PermissionsGuard)
|
|
43
|
+
* export class OrdersController { ... }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
let PermissionsGuard = PermissionsGuard_1 = class PermissionsGuard {
|
|
47
|
+
reflector;
|
|
48
|
+
permissionsClient;
|
|
49
|
+
logger = new common_1.Logger(PermissionsGuard_1.name);
|
|
50
|
+
constructor(reflector, permissionsClient) {
|
|
51
|
+
this.reflector = reflector;
|
|
52
|
+
this.permissionsClient = permissionsClient;
|
|
53
|
+
}
|
|
54
|
+
async canActivate(context) {
|
|
55
|
+
const metadata = this.getPermissionsMetadata(context);
|
|
56
|
+
if (metadata === undefined || metadata.permissions.length === 0) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const request = context.switchToHttp().getRequest();
|
|
60
|
+
const { user } = request;
|
|
61
|
+
if (user === undefined || user.id === '') {
|
|
62
|
+
this.logger.warn('Permission check failed: No authenticated user found');
|
|
63
|
+
throw new common_1.ForbiddenException('Authentication required');
|
|
64
|
+
}
|
|
65
|
+
const { permissions, options } = metadata;
|
|
66
|
+
const mode = options.mode ?? 'all';
|
|
67
|
+
try {
|
|
68
|
+
const hasPermission = await this.evaluatePermissions(user.id, [...permissions], mode, request, options.includeResourceContext ?? false);
|
|
69
|
+
if (!hasPermission) {
|
|
70
|
+
const errorMessage = options.errorMessage ??
|
|
71
|
+
`Access denied. Required permission(s): ${permissions.join(', ')}`;
|
|
72
|
+
this.logger.debug(`Permission denied for user ${user.id}: ${permissions.join(', ')} (mode: ${mode})`);
|
|
73
|
+
throw new common_1.ForbiddenException(errorMessage);
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof common_1.ForbiddenException) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
this.logger.error(`Permission check failed for user ${user.id}`, error instanceof Error ? error.stack : String(error));
|
|
82
|
+
throw new common_1.ForbiddenException('Permission check failed');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get permission metadata from the handler or class
|
|
87
|
+
*/
|
|
88
|
+
getPermissionsMetadata(context) {
|
|
89
|
+
return this.reflector.getAllAndOverride(types_1.PERMISSIONS_METADATA_KEY, [context.getHandler(), context.getClass()]);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Evaluate permissions based on mode
|
|
93
|
+
*/
|
|
94
|
+
async evaluatePermissions(userId, permissions, mode, request, includeResourceContext) {
|
|
95
|
+
const requestContext = this.buildRequestContext(request);
|
|
96
|
+
const resourceContext = includeResourceContext ? this.buildResourceContext(request) : undefined;
|
|
97
|
+
if (permissions.length === 1) {
|
|
98
|
+
const [firstPermission] = permissions;
|
|
99
|
+
const result = await this.permissionsClient.checkPermission(userId, firstPermission, {
|
|
100
|
+
request: requestContext,
|
|
101
|
+
resource: resourceContext,
|
|
102
|
+
});
|
|
103
|
+
return result.allowed;
|
|
104
|
+
}
|
|
105
|
+
if (mode === 'all') {
|
|
106
|
+
return await this.permissionsClient.hasAllPermissions(userId, permissions);
|
|
107
|
+
}
|
|
108
|
+
return await this.permissionsClient.hasAnyPermission(userId, permissions);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build request context from the HTTP request
|
|
112
|
+
*/
|
|
113
|
+
buildRequestContext(request) {
|
|
114
|
+
const userAgent = request.headers?.['user-agent'];
|
|
115
|
+
return {
|
|
116
|
+
ip: request.ip,
|
|
117
|
+
userAgent: Array.isArray(userAgent) ? userAgent[0] : userAgent,
|
|
118
|
+
method: request.method,
|
|
119
|
+
path: request.path ?? request.url,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Build resource context from request params/query
|
|
124
|
+
*/
|
|
125
|
+
buildResourceContext(request) {
|
|
126
|
+
return {
|
|
127
|
+
id: request.params?.id,
|
|
128
|
+
...request.params,
|
|
129
|
+
...request.query,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.PermissionsGuard = PermissionsGuard;
|
|
134
|
+
exports.PermissionsGuard = PermissionsGuard = PermissionsGuard_1 = __decorate([
|
|
135
|
+
(0, common_1.Injectable)(),
|
|
136
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
137
|
+
permissions_grpc_client_1.PermissionsGrpcClient])
|
|
138
|
+
], PermissionsGuard);
|
|
139
|
+
//# sourceMappingURL=permissions.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.guard.js","sourceRoot":"","sources":["../../src/guards/permissions.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AACxB,uCAAyC;AAEzC,+EAA0E;AAE1E,oCAAoD;AAwBpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAIR;IACA;IAJF,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAE5D,YACmB,SAAoB,EACpB,iBAAwC;QADxC,cAAS,GAA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/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
// Client
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
19
|
+
// Guards
|
|
20
|
+
__exportStar(require("./guards"), exports);
|
|
21
|
+
// Decorators
|
|
22
|
+
__exportStar(require("./decorators"), exports);
|
|
23
|
+
// Types
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
// Constants
|
|
26
|
+
__exportStar(require("./constants"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS;AACT,2CAAyB;AAEzB,SAAS;AACT,2CAAyB;AAEzB,aAAa;AACb,+CAA6B;AAE7B,QAAQ;AACR,0CAAwB;AAExB,YAAY;AACZ,8CAA4B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package permissions;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Permissions Service
|
|
7
|
+
* Provides gRPC endpoints for permission evaluation in a microservice architecture.
|
|
8
|
+
* Supports RBAC (Role-Based Access Control) and ABAC (Attribute-Based Access Control).
|
|
9
|
+
*/
|
|
10
|
+
service PermissionsService {
|
|
11
|
+
/**
|
|
12
|
+
* Check a single permission for a user with optional ABAC context
|
|
13
|
+
*/
|
|
14
|
+
rpc CheckPermission(CheckPermissionRequest) returns (CheckPermissionResponse);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check multiple permissions at once for efficiency
|
|
18
|
+
*/
|
|
19
|
+
rpc CheckBulkPermissions(CheckBulkPermissionsRequest) returns (CheckBulkPermissionsResponse);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get all effective permissions for a user (computed from roles + custom assignments)
|
|
23
|
+
*/
|
|
24
|
+
rpc GetEffectivePermissions(GetEffectivePermissionsRequest) returns (GetEffectivePermissionsResponse);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Simple boolean check - does user have this permission?
|
|
28
|
+
*/
|
|
29
|
+
rpc HasPermission(HasPermissionRequest) returns (HasPermissionResponse);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if user has ALL of the specified permissions
|
|
33
|
+
*/
|
|
34
|
+
rpc HasAllPermissions(HasMultiplePermissionsRequest) returns (HasPermissionResponse);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if user has ANY of the specified permissions
|
|
38
|
+
*/
|
|
39
|
+
rpc HasAnyPermission(HasMultiplePermissionsRequest) returns (HasPermissionResponse);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Request Messages
|
|
44
|
+
// ============================================================================
|
|
45
|
+
|
|
46
|
+
message CheckPermissionRequest {
|
|
47
|
+
string user_id = 1;
|
|
48
|
+
string permission_code = 2;
|
|
49
|
+
optional ResourceContext resource_context = 3;
|
|
50
|
+
optional RequestContext request_context = 4;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
message CheckBulkPermissionsRequest {
|
|
54
|
+
string user_id = 1;
|
|
55
|
+
repeated string permission_codes = 2;
|
|
56
|
+
optional ResourceContext resource_context = 3;
|
|
57
|
+
optional RequestContext request_context = 4;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
message GetEffectivePermissionsRequest {
|
|
61
|
+
string user_id = 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
message HasPermissionRequest {
|
|
65
|
+
string user_id = 1;
|
|
66
|
+
string permission_code = 2;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
message HasMultiplePermissionsRequest {
|
|
70
|
+
string user_id = 1;
|
|
71
|
+
repeated string permission_codes = 2;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Response Messages
|
|
76
|
+
// ============================================================================
|
|
77
|
+
|
|
78
|
+
message CheckPermissionResponse {
|
|
79
|
+
bool allowed = 1;
|
|
80
|
+
EvaluationSource source = 2;
|
|
81
|
+
repeated string matched_roles = 3;
|
|
82
|
+
repeated string matched_policies = 4;
|
|
83
|
+
string reason = 5;
|
|
84
|
+
int32 evaluation_time_ms = 6;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
message CheckBulkPermissionsResponse {
|
|
88
|
+
map<string, CheckPermissionResponse> results = 1;
|
|
89
|
+
int32 total_time_ms = 2;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
message GetEffectivePermissionsResponse {
|
|
93
|
+
repeated string permissions = 1;
|
|
94
|
+
repeated RoleInfo roles = 2;
|
|
95
|
+
int32 version = 3;
|
|
96
|
+
string computed_at = 4;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
message HasPermissionResponse {
|
|
100
|
+
bool has_permission = 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Shared Types
|
|
105
|
+
// ============================================================================
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Source of the permission decision
|
|
109
|
+
*/
|
|
110
|
+
enum EvaluationSource {
|
|
111
|
+
EVALUATION_SOURCE_UNSPECIFIED = 0;
|
|
112
|
+
EVALUATION_SOURCE_RBAC = 1;
|
|
113
|
+
EVALUATION_SOURCE_ABAC = 2;
|
|
114
|
+
EVALUATION_SOURCE_BREAK_GLASS = 3;
|
|
115
|
+
EVALUATION_SOURCE_DENIED = 4;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Role information
|
|
120
|
+
*/
|
|
121
|
+
message RoleInfo {
|
|
122
|
+
string id = 1;
|
|
123
|
+
string code = 2;
|
|
124
|
+
string name = 3;
|
|
125
|
+
bool is_system = 4;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Resource context for ABAC evaluation
|
|
130
|
+
* Contains attributes about the resource being accessed
|
|
131
|
+
*/
|
|
132
|
+
message ResourceContext {
|
|
133
|
+
optional string id = 1;
|
|
134
|
+
optional string type = 2;
|
|
135
|
+
optional string owner_id = 3;
|
|
136
|
+
optional string department = 4;
|
|
137
|
+
map<string, string> attributes = 5;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Request context for ABAC evaluation
|
|
142
|
+
* Contains attributes about the request itself
|
|
143
|
+
*/
|
|
144
|
+
message RequestContext {
|
|
145
|
+
optional string ip = 1;
|
|
146
|
+
optional string user_agent = 2;
|
|
147
|
+
optional string method = 3;
|
|
148
|
+
optional string path = 4;
|
|
149
|
+
map<string, string> attributes = 5;
|
|
150
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source of permission grant decision
|
|
3
|
+
*/
|
|
4
|
+
export type EvaluationSource = 'rbac' | 'abac' | 'break-glass' | 'denied';
|
|
5
|
+
/**
|
|
6
|
+
* Maps proto enum values to TypeScript types
|
|
7
|
+
*/
|
|
8
|
+
export declare const EVALUATION_SOURCE_MAP: {
|
|
9
|
+
readonly EVALUATION_SOURCE_UNSPECIFIED: "denied";
|
|
10
|
+
readonly EVALUATION_SOURCE_RBAC: "rbac";
|
|
11
|
+
readonly EVALUATION_SOURCE_ABAC: "abac";
|
|
12
|
+
readonly EVALUATION_SOURCE_BREAK_GLASS: "break-glass";
|
|
13
|
+
readonly EVALUATION_SOURCE_DENIED: "denied";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Resource context for ABAC evaluation
|
|
17
|
+
* Contains attributes about the resource being accessed
|
|
18
|
+
*/
|
|
19
|
+
export interface ResourceContext {
|
|
20
|
+
readonly id?: string;
|
|
21
|
+
readonly type?: string;
|
|
22
|
+
readonly ownerId?: string;
|
|
23
|
+
readonly department?: string;
|
|
24
|
+
readonly [key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Request context for ABAC evaluation
|
|
28
|
+
* Contains attributes about the request itself
|
|
29
|
+
*/
|
|
30
|
+
export interface RequestContext {
|
|
31
|
+
readonly ip?: string;
|
|
32
|
+
readonly userAgent?: string;
|
|
33
|
+
readonly method?: string;
|
|
34
|
+
readonly path?: string;
|
|
35
|
+
readonly [key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Context passed to evaluators when checking permissions
|
|
39
|
+
*/
|
|
40
|
+
export interface EvaluationContext {
|
|
41
|
+
readonly userId: string;
|
|
42
|
+
readonly permissionCode: string;
|
|
43
|
+
readonly resource?: ResourceContext;
|
|
44
|
+
readonly request?: RequestContext;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of permission evaluation
|
|
48
|
+
*/
|
|
49
|
+
export interface EvaluationResult {
|
|
50
|
+
readonly allowed: boolean;
|
|
51
|
+
readonly source: EvaluationSource;
|
|
52
|
+
readonly matchedRoles?: readonly string[];
|
|
53
|
+
readonly matchedPolicies?: readonly string[];
|
|
54
|
+
readonly reason: string;
|
|
55
|
+
readonly evaluationTimeMs: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bulk permission check request
|
|
59
|
+
*/
|
|
60
|
+
export interface BulkPermissionCheck {
|
|
61
|
+
readonly userId: string;
|
|
62
|
+
readonly permissionCodes: readonly string[];
|
|
63
|
+
readonly resource?: ResourceContext;
|
|
64
|
+
readonly request?: RequestContext;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Bulk permission check result
|
|
68
|
+
*/
|
|
69
|
+
export interface BulkPermissionResult {
|
|
70
|
+
readonly results: ReadonlyMap<string, EvaluationResult>;
|
|
71
|
+
readonly totalTimeMs: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Bulk permission result as a record (for JSON serialization)
|
|
75
|
+
*/
|
|
76
|
+
export interface BulkPermissionResultRecord {
|
|
77
|
+
readonly results: Record<string, EvaluationResult>;
|
|
78
|
+
readonly totalTimeMs: number;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=evaluation.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation.types.d.ts","sourceRoot":"","sources":["../../src/types/evaluation.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;CAMxB,CAAC;AAEX;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED;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,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVALUATION_SOURCE_MAP = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Maps proto enum values to TypeScript types
|
|
6
|
+
*/
|
|
7
|
+
exports.EVALUATION_SOURCE_MAP = {
|
|
8
|
+
EVALUATION_SOURCE_UNSPECIFIED: 'denied',
|
|
9
|
+
EVALUATION_SOURCE_RBAC: 'rbac',
|
|
10
|
+
EVALUATION_SOURCE_ABAC: 'abac',
|
|
11
|
+
EVALUATION_SOURCE_BREAK_GLASS: 'break-glass',
|
|
12
|
+
EVALUATION_SOURCE_DENIED: 'denied',
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=evaluation.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation.types.js","sourceRoot":"","sources":["../../src/types/evaluation.types.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACU,QAAA,qBAAqB,GAAG;IACnC,6BAA6B,EAAE,QAAQ;IACvC,sBAAsB,EAAE,MAAM;IAC9B,sBAAsB,EAAE,MAAM;IAC9B,6BAA6B,EAAE,aAAa;IAC5C,wBAAwB,EAAE,QAAQ;CAC1B,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* gRPC Resource context message
|
|
4
|
+
*/
|
|
5
|
+
export interface GrpcResourceContext {
|
|
6
|
+
id?: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
ownerId?: string;
|
|
9
|
+
department?: string;
|
|
10
|
+
attributes?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* gRPC Request context message
|
|
14
|
+
*/
|
|
15
|
+
export interface GrpcRequestContext {
|
|
16
|
+
ip?: string;
|
|
17
|
+
userAgent?: string;
|
|
18
|
+
method?: string;
|
|
19
|
+
path?: string;
|
|
20
|
+
attributes?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* gRPC Role info message
|
|
24
|
+
*/
|
|
25
|
+
export interface GrpcRoleInfo {
|
|
26
|
+
id: string;
|
|
27
|
+
code: string;
|
|
28
|
+
name: string;
|
|
29
|
+
isSystem: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* gRPC Evaluation source enum (as number from proto)
|
|
33
|
+
*/
|
|
34
|
+
export declare enum GrpcEvaluationSource {
|
|
35
|
+
EVALUATION_SOURCE_UNSPECIFIED = 0,
|
|
36
|
+
EVALUATION_SOURCE_RBAC = 1,
|
|
37
|
+
EVALUATION_SOURCE_ABAC = 2,
|
|
38
|
+
EVALUATION_SOURCE_BREAK_GLASS = 3,
|
|
39
|
+
EVALUATION_SOURCE_DENIED = 4
|
|
40
|
+
}
|
|
41
|
+
export interface CheckPermissionRequest {
|
|
42
|
+
userId: string;
|
|
43
|
+
permissionCode: string;
|
|
44
|
+
resourceContext?: GrpcResourceContext;
|
|
45
|
+
requestContext?: GrpcRequestContext;
|
|
46
|
+
}
|
|
47
|
+
export interface CheckBulkPermissionsRequest {
|
|
48
|
+
userId: string;
|
|
49
|
+
permissionCodes: string[];
|
|
50
|
+
resourceContext?: GrpcResourceContext;
|
|
51
|
+
requestContext?: GrpcRequestContext;
|
|
52
|
+
}
|
|
53
|
+
export interface GetEffectivePermissionsRequest {
|
|
54
|
+
userId: string;
|
|
55
|
+
}
|
|
56
|
+
export interface HasPermissionRequest {
|
|
57
|
+
userId: string;
|
|
58
|
+
permissionCode: string;
|
|
59
|
+
}
|
|
60
|
+
export interface HasMultiplePermissionsRequest {
|
|
61
|
+
userId: string;
|
|
62
|
+
permissionCodes: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface CheckPermissionResponse {
|
|
65
|
+
allowed: boolean;
|
|
66
|
+
source: GrpcEvaluationSource;
|
|
67
|
+
matchedRoles: string[];
|
|
68
|
+
matchedPolicies: string[];
|
|
69
|
+
reason: string;
|
|
70
|
+
evaluationTimeMs: number;
|
|
71
|
+
}
|
|
72
|
+
export interface CheckBulkPermissionsResponse {
|
|
73
|
+
results: Record<string, CheckPermissionResponse>;
|
|
74
|
+
totalTimeMs: number;
|
|
75
|
+
}
|
|
76
|
+
export interface GetEffectivePermissionsResponse {
|
|
77
|
+
permissions: string[];
|
|
78
|
+
roles: GrpcRoleInfo[];
|
|
79
|
+
version: number;
|
|
80
|
+
computedAt: string;
|
|
81
|
+
}
|
|
82
|
+
export interface HasPermissionResponse {
|
|
83
|
+
hasPermission: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* gRPC Permissions Service client interface
|
|
87
|
+
* This interface is used by NestJS microservices to define the client methods
|
|
88
|
+
*/
|
|
89
|
+
export interface PermissionsGrpcService {
|
|
90
|
+
checkPermission: (request: CheckPermissionRequest) => Observable<CheckPermissionResponse>;
|
|
91
|
+
checkBulkPermissions: (request: CheckBulkPermissionsRequest) => Observable<CheckBulkPermissionsResponse>;
|
|
92
|
+
getEffectivePermissions: (request: GetEffectivePermissionsRequest) => Observable<GetEffectivePermissionsResponse>;
|
|
93
|
+
hasPermission: (request: HasPermissionRequest) => Observable<HasPermissionResponse>;
|
|
94
|
+
hasAllPermissions: (request: HasMultiplePermissionsRequest) => Observable<HasPermissionResponse>;
|
|
95
|
+
hasAnyPermission: (request: HasMultiplePermissionsRequest) => Observable<HasPermissionResponse>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=grpc.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc.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AAqB,CAAC,CAAC;IACpF,iBAAiB,EAAE,CAAC,OAAO,EAAE,6BAA6B,KAAK,UAAU,CAAC,qBAAqB,CAAC,CAAC;IACjG,gBAAgB,EAAE,CAAC,OAAO,EAAE,6BAA6B,KAAK,UAAU,CAAC,qBAAqB,CAAC,CAAC;CACjG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GrpcEvaluationSource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* gRPC Evaluation source enum (as number from proto)
|
|
6
|
+
*/
|
|
7
|
+
var GrpcEvaluationSource;
|
|
8
|
+
(function (GrpcEvaluationSource) {
|
|
9
|
+
GrpcEvaluationSource[GrpcEvaluationSource["EVALUATION_SOURCE_UNSPECIFIED"] = 0] = "EVALUATION_SOURCE_UNSPECIFIED";
|
|
10
|
+
GrpcEvaluationSource[GrpcEvaluationSource["EVALUATION_SOURCE_RBAC"] = 1] = "EVALUATION_SOURCE_RBAC";
|
|
11
|
+
GrpcEvaluationSource[GrpcEvaluationSource["EVALUATION_SOURCE_ABAC"] = 2] = "EVALUATION_SOURCE_ABAC";
|
|
12
|
+
GrpcEvaluationSource[GrpcEvaluationSource["EVALUATION_SOURCE_BREAK_GLASS"] = 3] = "EVALUATION_SOURCE_BREAK_GLASS";
|
|
13
|
+
GrpcEvaluationSource[GrpcEvaluationSource["EVALUATION_SOURCE_DENIED"] = 4] = "EVALUATION_SOURCE_DENIED";
|
|
14
|
+
})(GrpcEvaluationSource || (exports.GrpcEvaluationSource = GrpcEvaluationSource = {}));
|
|
15
|
+
//# sourceMappingURL=grpc.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc.types.js","sourceRoot":"","sources":["../../src/types/grpc.types.ts"],"names":[],"mappings":";;;AAkCA;;GAEG;AACH,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,iHAAiC,CAAA;IACjC,mGAA0B,CAAA;IAC1B,mGAA0B,CAAA;IAC1B,iHAAiC,CAAA;IACjC,uGAA4B,CAAA;AAC9B,CAAC,EANW,oBAAoB,oCAApB,oBAAoB,QAM/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./evaluation.types"), exports);
|
|
18
|
+
__exportStar(require("./grpc.types"), exports);
|
|
19
|
+
__exportStar(require("./permission.types"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,+CAA6B;AAC7B,qDAAmC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role information with associated permission codes
|
|
3
|
+
*/
|
|
4
|
+
export interface RoleInfo {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly isSystem: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* User's effective permissions computed from roles and custom assignments
|
|
12
|
+
*/
|
|
13
|
+
export interface EffectivePermissions {
|
|
14
|
+
readonly permissions: readonly string[];
|
|
15
|
+
readonly roles: readonly RoleInfo[];
|
|
16
|
+
readonly version: number;
|
|
17
|
+
readonly computedAt: Date;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for the RequirePermissions decorator
|
|
21
|
+
*/
|
|
22
|
+
export interface RequirePermissionsOptions {
|
|
23
|
+
/**
|
|
24
|
+
* How to evaluate multiple permissions
|
|
25
|
+
* - 'all': User must have ALL listed permissions (AND logic)
|
|
26
|
+
* - 'any': User must have at least ONE permission (OR logic)
|
|
27
|
+
* @default 'all'
|
|
28
|
+
*/
|
|
29
|
+
readonly mode?: 'all' | 'any';
|
|
30
|
+
/**
|
|
31
|
+
* Custom error message when permission is denied
|
|
32
|
+
*/
|
|
33
|
+
readonly errorMessage?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to include resource context from request params
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
readonly includeResourceContext?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Metadata key for storing permission requirements
|
|
42
|
+
*/
|
|
43
|
+
export declare const PERMISSIONS_METADATA_KEY = "permissions:required";
|
|
44
|
+
/**
|
|
45
|
+
* Metadata structure for permission requirements
|
|
46
|
+
*/
|
|
47
|
+
export interface PermissionsMetadata {
|
|
48
|
+
readonly permissions: readonly string[];
|
|
49
|
+
readonly options: RequirePermissionsOptions;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=permission.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.types.d.ts","sourceRoot":"","sources":["../../src/types/permission.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;CAC7C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMISSIONS_METADATA_KEY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Metadata key for storing permission requirements
|
|
6
|
+
*/
|
|
7
|
+
exports.PERMISSIONS_METADATA_KEY = 'permissions:required';
|
|
8
|
+
//# sourceMappingURL=permission.types.js.map
|