permissions-contractx 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/LICENSE +21 -0
- package/README.md +1397 -0
- package/dist/constants/contractx-permissions.constants.d.ts +310 -0
- package/dist/constants/contractx-permissions.constants.d.ts.map +1 -0
- package/dist/constants/contractx-permissions.constants.js +1061 -0
- package/dist/constants/contractx-roles.constants.d.ts +295 -0
- package/dist/constants/contractx-roles.constants.d.ts.map +1 -0
- package/dist/constants/contractx-roles.constants.js +238 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +18 -0
- package/dist/constants/security.constants.d.ts +77 -0
- package/dist/constants/security.constants.d.ts.map +1 -0
- package/dist/constants/security.constants.js +139 -0
- package/dist/decorators/current-user.decorator.d.ts +73 -0
- package/dist/decorators/current-user.decorator.d.ts.map +1 -0
- package/dist/decorators/current-user.decorator.js +91 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +20 -0
- package/dist/decorators/permissions.decorator.d.ts +97 -0
- package/dist/decorators/permissions.decorator.d.ts.map +1 -0
- package/dist/decorators/permissions.decorator.js +106 -0
- package/dist/decorators/public.decorator.d.ts +18 -0
- package/dist/decorators/public.decorator.d.ts.map +1 -0
- package/dist/decorators/public.decorator.js +22 -0
- package/dist/decorators/roles.decorator.d.ts +79 -0
- package/dist/decorators/roles.decorator.d.ts.map +1 -0
- package/dist/decorators/roles.decorator.js +87 -0
- package/dist/guards/index.d.ts +4 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +19 -0
- package/dist/guards/jwt-auth.guard.d.ts +21 -0
- package/dist/guards/jwt-auth.guard.d.ts.map +1 -0
- package/dist/guards/jwt-auth.guard.js +115 -0
- package/dist/guards/permissions.guard.d.ts +14 -0
- package/dist/guards/permissions.guard.d.ts.map +1 -0
- package/dist/guards/permissions.guard.js +77 -0
- package/dist/guards/roles.guard.d.ts +13 -0
- package/dist/guards/roles.guard.d.ts.map +1 -0
- package/dist/guards/roles.guard.js +59 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +17 -0
- package/dist/interfaces/jwt-payload.interface.d.ts +93 -0
- package/dist/interfaces/jwt-payload.interface.d.ts.map +1 -0
- package/dist/interfaces/jwt-payload.interface.js +2 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +17 -0
- package/dist/modules/permissions-contractx.module.d.ts +41 -0
- package/dist/modules/permissions-contractx.module.d.ts.map +1 -0
- package/dist/modules/permissions-contractx.module.js +215 -0
- package/dist/services/contractx-authorization.service.d.ts +107 -0
- package/dist/services/contractx-authorization.service.d.ts.map +1 -0
- package/dist/services/contractx-authorization.service.js +362 -0
- package/dist/services/contractx-document-compliance.service.d.ts +85 -0
- package/dist/services/contractx-document-compliance.service.d.ts.map +1 -0
- package/dist/services/contractx-document-compliance.service.js +536 -0
- package/dist/services/contractx-validation.service.d.ts +76 -0
- package/dist/services/contractx-validation.service.d.ts.map +1 -0
- package/dist/services/contractx-validation.service.js +305 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +20 -0
- package/dist/services/user-context.service.d.ts +114 -0
- package/dist/services/user-context.service.d.ts.map +1 -0
- package/dist/services/user-context.service.js +199 -0
- package/dist/test-document-compliance.d.ts +7 -0
- package/dist/test-document-compliance.d.ts.map +1 -0
- package/dist/test-document-compliance.js +118 -0
- package/package.json +405 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ===================================================================
|
|
3
|
+
// ContractX ODS (Operational Data Store) Security Constants
|
|
4
|
+
// ===================================================================
|
|
5
|
+
//
|
|
6
|
+
// Complete ODS implementation with:
|
|
7
|
+
// - 16 specialized roles from Excel specification
|
|
8
|
+
// - 23 system modules with full CRUD+Show+Filter permissions
|
|
9
|
+
// - Complete tenant isolation support
|
|
10
|
+
// - Exact permission matrix implementation
|
|
11
|
+
//
|
|
12
|
+
// Version: 2.0.0 - ODS Complete Implementation
|
|
13
|
+
// ===================================================================
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MODULE_CONSTANTS = exports.ROLE_GROUPS = exports.PERMISSION_CATEGORIES = exports.ROLE_HIERARCHY = exports.CONTRACTX_ROLES = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* ODS Roles - Exact 16 roles from Excel specification
|
|
18
|
+
* Implements complete role hierarchy for client/provider contract management
|
|
19
|
+
*/
|
|
20
|
+
exports.CONTRACTX_ROLES = {
|
|
21
|
+
// === SYSTEM ROLE ===
|
|
22
|
+
SUPERADMIN: 'superadmin', // ID: 1 - Full access to all modules
|
|
23
|
+
// === CLIENT-SIDE ROLES ===
|
|
24
|
+
CLIENT_CONTRACT_ADMIN: 'client_contract_admin', // ID: 2 - Full contract management for assigned client
|
|
25
|
+
CLIENT_PERFORMANCE_RESP: 'client_performance_resp', // ID: 3 - Performance responsibility role
|
|
26
|
+
CLIENT_FINANCE_RESP: 'client_finance_resp', // ID: 4 - Financial responsibility role
|
|
27
|
+
CLIENT_REPORTS_RESP: 'client_reports_resp', // ID: 5 - Reporting responsibility role
|
|
28
|
+
CLIENT_RELATIONSHIP_RESP: 'client_relationship_resp', // ID: 6 - Relationship management role
|
|
29
|
+
CLIENT_RISK_RESP: 'client_risk_resp', // ID: 7 - Risk management role
|
|
30
|
+
// === PROVIDER-SIDE ROLES ===
|
|
31
|
+
PROVIDER_CONTRACT_ADMIN: 'provider_contract_admin', // ID: 8 - Provider contract administrator
|
|
32
|
+
PROVIDER_PERFORMANCE_RESP: 'provider_performance_resp', // ID: 9 - Provider performance responsibility
|
|
33
|
+
PROVIDER_FINANCE_RESP: 'provider_finance_resp', // ID: 10 - Provider financial responsibility
|
|
34
|
+
PROVIDER_REPORTS_RESP: 'provider_reports_resp', // ID: 11 - Provider reporting responsibility
|
|
35
|
+
PROVIDER_RELATIONSHIP_RESP: 'provider_relationship_resp', // ID: 12 - Provider relationship management
|
|
36
|
+
PROVIDER_RISK_RESP: 'provider_risk_resp', // ID: 13 - Provider risk management
|
|
37
|
+
// === SYSTEM SUPPORT ROLE ===
|
|
38
|
+
SUPPORT: 'support', // ID: 17 - Support role with broad access (moved from 14 to 17)
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* ODS Role Hierarchy Levels - Exact hierarchy from Excel specification
|
|
42
|
+
* Higher numbers indicate higher privileges
|
|
43
|
+
*/
|
|
44
|
+
exports.ROLE_HIERARCHY = {
|
|
45
|
+
[exports.CONTRACTX_ROLES.SUPERADMIN]: 100, // System-wide super admin
|
|
46
|
+
[exports.CONTRACTX_ROLES.SUPPORT]: 85, // Support role with broad access
|
|
47
|
+
// Client-side roles
|
|
48
|
+
[exports.CONTRACTX_ROLES.CLIENT_CONTRACT_ADMIN]: 80, // Full contract management for client
|
|
49
|
+
[exports.CONTRACTX_ROLES.CLIENT_PERFORMANCE_RESP]: 70, // Client performance responsibility
|
|
50
|
+
[exports.CONTRACTX_ROLES.CLIENT_FINANCE_RESP]: 70, // Client financial responsibility
|
|
51
|
+
[exports.CONTRACTX_ROLES.CLIENT_REPORTS_RESP]: 65, // Client reporting responsibility
|
|
52
|
+
[exports.CONTRACTX_ROLES.CLIENT_RELATIONSHIP_RESP]: 65, // Client relationship management
|
|
53
|
+
[exports.CONTRACTX_ROLES.CLIENT_RISK_RESP]: 65, // Client risk management
|
|
54
|
+
// Provider-side roles
|
|
55
|
+
[exports.CONTRACTX_ROLES.PROVIDER_CONTRACT_ADMIN]: 80, // Provider contract administrator
|
|
56
|
+
[exports.CONTRACTX_ROLES.PROVIDER_PERFORMANCE_RESP]: 70, // Provider performance responsibility
|
|
57
|
+
[exports.CONTRACTX_ROLES.PROVIDER_FINANCE_RESP]: 70, // Provider financial responsibility
|
|
58
|
+
[exports.CONTRACTX_ROLES.PROVIDER_REPORTS_RESP]: 65, // Provider reporting responsibility
|
|
59
|
+
[exports.CONTRACTX_ROLES.PROVIDER_RELATIONSHIP_RESP]: 65, // Provider relationship management
|
|
60
|
+
[exports.CONTRACTX_ROLES.PROVIDER_RISK_RESP]: 65, // Provider risk management
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Permission Categories for organization
|
|
64
|
+
*/
|
|
65
|
+
exports.PERMISSION_CATEGORIES = {
|
|
66
|
+
USER_MANAGEMENT: 'User Management',
|
|
67
|
+
ROLE_MANAGEMENT: 'Role Management',
|
|
68
|
+
PERMISSION_MANAGEMENT: 'Permission Management',
|
|
69
|
+
CLIENT_MANAGEMENT: 'Client Management',
|
|
70
|
+
PROVIDER_MANAGEMENT: 'Provider Management',
|
|
71
|
+
CONTRACT_MANAGEMENT: 'Contract Management',
|
|
72
|
+
DOCUMENT_MANAGEMENT: 'Document Management',
|
|
73
|
+
DELIVERABLE_MANAGEMENT: 'Deliverable Management',
|
|
74
|
+
PERFORMANCE_MANAGEMENT: 'Performance Management',
|
|
75
|
+
FINANCIAL_MANAGEMENT: 'Financial Management',
|
|
76
|
+
COMMUNICATION_MANAGEMENT: 'Communication Management',
|
|
77
|
+
SYSTEM_ADMINISTRATION: 'System Administration',
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* ODS Role Groups for easy assignment and management
|
|
81
|
+
*/
|
|
82
|
+
exports.ROLE_GROUPS = {
|
|
83
|
+
ADMIN_ROLES: [
|
|
84
|
+
exports.CONTRACTX_ROLES.SUPERADMIN,
|
|
85
|
+
exports.CONTRACTX_ROLES.CLIENT_CONTRACT_ADMIN,
|
|
86
|
+
exports.CONTRACTX_ROLES.PROVIDER_CONTRACT_ADMIN,
|
|
87
|
+
],
|
|
88
|
+
CLIENT_ROLES: [
|
|
89
|
+
exports.CONTRACTX_ROLES.CLIENT_CONTRACT_ADMIN,
|
|
90
|
+
exports.CONTRACTX_ROLES.CLIENT_PERFORMANCE_RESP,
|
|
91
|
+
exports.CONTRACTX_ROLES.CLIENT_FINANCE_RESP,
|
|
92
|
+
exports.CONTRACTX_ROLES.CLIENT_REPORTS_RESP,
|
|
93
|
+
exports.CONTRACTX_ROLES.CLIENT_RELATIONSHIP_RESP,
|
|
94
|
+
exports.CONTRACTX_ROLES.CLIENT_RISK_RESP,
|
|
95
|
+
],
|
|
96
|
+
PROVIDER_ROLES: [
|
|
97
|
+
exports.CONTRACTX_ROLES.PROVIDER_CONTRACT_ADMIN,
|
|
98
|
+
exports.CONTRACTX_ROLES.PROVIDER_PERFORMANCE_RESP,
|
|
99
|
+
exports.CONTRACTX_ROLES.PROVIDER_FINANCE_RESP,
|
|
100
|
+
exports.CONTRACTX_ROLES.PROVIDER_REPORTS_RESP,
|
|
101
|
+
exports.CONTRACTX_ROLES.PROVIDER_RELATIONSHIP_RESP,
|
|
102
|
+
exports.CONTRACTX_ROLES.PROVIDER_RISK_RESP,
|
|
103
|
+
],
|
|
104
|
+
MANAGER_ROLES: [
|
|
105
|
+
exports.CONTRACTX_ROLES.CLIENT_CONTRACT_ADMIN,
|
|
106
|
+
exports.CONTRACTX_ROLES.PROVIDER_CONTRACT_ADMIN,
|
|
107
|
+
exports.CONTRACTX_ROLES.CLIENT_PERFORMANCE_RESP,
|
|
108
|
+
exports.CONTRACTX_ROLES.PROVIDER_PERFORMANCE_RESP,
|
|
109
|
+
exports.CONTRACTX_ROLES.CLIENT_FINANCE_RESP,
|
|
110
|
+
exports.CONTRACTX_ROLES.PROVIDER_FINANCE_RESP,
|
|
111
|
+
],
|
|
112
|
+
VIEWER_ROLES: [
|
|
113
|
+
exports.CONTRACTX_ROLES.CLIENT_REPORTS_RESP,
|
|
114
|
+
exports.CONTRACTX_ROLES.PROVIDER_REPORTS_RESP,
|
|
115
|
+
],
|
|
116
|
+
RESPONSIBILITY_ROLES: [
|
|
117
|
+
exports.CONTRACTX_ROLES.CLIENT_PERFORMANCE_RESP,
|
|
118
|
+
exports.CONTRACTX_ROLES.CLIENT_FINANCE_RESP,
|
|
119
|
+
exports.CONTRACTX_ROLES.CLIENT_REPORTS_RESP,
|
|
120
|
+
exports.CONTRACTX_ROLES.CLIENT_RELATIONSHIP_RESP,
|
|
121
|
+
exports.CONTRACTX_ROLES.CLIENT_RISK_RESP,
|
|
122
|
+
exports.CONTRACTX_ROLES.PROVIDER_PERFORMANCE_RESP,
|
|
123
|
+
exports.CONTRACTX_ROLES.PROVIDER_FINANCE_RESP,
|
|
124
|
+
exports.CONTRACTX_ROLES.PROVIDER_REPORTS_RESP,
|
|
125
|
+
exports.CONTRACTX_ROLES.PROVIDER_RELATIONSHIP_RESP,
|
|
126
|
+
exports.CONTRACTX_ROLES.PROVIDER_RISK_RESP,
|
|
127
|
+
],
|
|
128
|
+
SYSTEM_ROLES: [
|
|
129
|
+
exports.CONTRACTX_ROLES.SUPERADMIN,
|
|
130
|
+
exports.CONTRACTX_ROLES.SUPPORT,
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Module constants for metadata
|
|
135
|
+
*/
|
|
136
|
+
exports.MODULE_CONSTANTS = {
|
|
137
|
+
MODULE_OPTIONS_TOKEN: 'PERMISSIONS_CONTRACTX_MODULE_OPTIONS',
|
|
138
|
+
JWT_CONFIG_TOKEN: 'PERMISSIONS_CONTRACTX_JWT_CONFIG',
|
|
139
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { JwtPayload } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Parameter decorator to inject the current authenticated user into a route handler
|
|
4
|
+
*
|
|
5
|
+
* @param data - Optional property name to extract from user object
|
|
6
|
+
* @param ctx - Execution context
|
|
7
|
+
* @returns The user object or specific property
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Get full user object
|
|
12
|
+
* @Get('profile')
|
|
13
|
+
* getProfile(@CurrentUser() user: JwtPayload) {
|
|
14
|
+
* return user;
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* // Get specific user property
|
|
18
|
+
* @Post('action')
|
|
19
|
+
* performAction(@CurrentUser('sub') userId: string) {
|
|
20
|
+
* // Only gets the user ID
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const CurrentUser: (...dataOrPipes: (keyof JwtPayload | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | undefined)[]) => ParameterDecorator;
|
|
25
|
+
/**
|
|
26
|
+
* Decorator to get current user's ID
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* @Post('create')
|
|
31
|
+
* createResource(@UserId() userId: string) {
|
|
32
|
+
* // Gets user.sub as userId
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const UserId: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
37
|
+
/**
|
|
38
|
+
* Decorator to get current user's roles
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* @Get('roles')
|
|
43
|
+
* getUserRoles(@UserRoles() roles: string[]) {
|
|
44
|
+
* return { roles };
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const UserRoles: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
49
|
+
/**
|
|
50
|
+
* Decorator to get current user's permissions
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* @Get('permissions')
|
|
55
|
+
* getUserPermissions(@UserPermissions() permissions: string[]) {
|
|
56
|
+
* return { permissions };
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const UserPermissions: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
61
|
+
/**
|
|
62
|
+
* Decorator to get current user's client ID
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* @Get('client-data')
|
|
67
|
+
* getClientData(@UserClientId() clientId: string) {
|
|
68
|
+
* // Gets user.clientId
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const UserClientId: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
73
|
+
//# sourceMappingURL=current-user.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-user.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/current-user.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,+MAOvB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM,mDAKlB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,mDAKrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,mDAK3B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,mDAKxB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserClientId = exports.UserPermissions = exports.UserRoles = exports.UserId = exports.CurrentUser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* Parameter decorator to inject the current authenticated user into a route handler
|
|
7
|
+
*
|
|
8
|
+
* @param data - Optional property name to extract from user object
|
|
9
|
+
* @param ctx - Execution context
|
|
10
|
+
* @returns The user object or specific property
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Get full user object
|
|
15
|
+
* @Get('profile')
|
|
16
|
+
* getProfile(@CurrentUser() user: JwtPayload) {
|
|
17
|
+
* return user;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Get specific user property
|
|
21
|
+
* @Post('action')
|
|
22
|
+
* performAction(@CurrentUser('sub') userId: string) {
|
|
23
|
+
* // Only gets the user ID
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
28
|
+
const request = ctx.switchToHttp().getRequest();
|
|
29
|
+
const user = request.user;
|
|
30
|
+
return data ? user?.[data] : user;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Decorator to get current user's ID
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* @Post('create')
|
|
38
|
+
* createResource(@UserId() userId: string) {
|
|
39
|
+
* // Gets user.sub as userId
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
exports.UserId = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
44
|
+
const request = ctx.switchToHttp().getRequest();
|
|
45
|
+
return request.user?.sub;
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Decorator to get current user's roles
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* @Get('roles')
|
|
53
|
+
* getUserRoles(@UserRoles() roles: string[]) {
|
|
54
|
+
* return { roles };
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
exports.UserRoles = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
59
|
+
const request = ctx.switchToHttp().getRequest();
|
|
60
|
+
return request.user?.role || [];
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Decorator to get current user's permissions
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* @Get('permissions')
|
|
68
|
+
* getUserPermissions(@UserPermissions() permissions: string[]) {
|
|
69
|
+
* return { permissions };
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
exports.UserPermissions = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
74
|
+
const request = ctx.switchToHttp().getRequest();
|
|
75
|
+
return request.user?.permissions || [];
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Decorator to get current user's client ID
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* @Get('client-data')
|
|
83
|
+
* getClientData(@UserClientId() clientId: string) {
|
|
84
|
+
* // Gets user.clientId
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
exports.UserClientId = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
89
|
+
const request = ctx.switchToHttp().getRequest();
|
|
90
|
+
return request.user?.clientId;
|
|
91
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,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("./public.decorator"), exports);
|
|
18
|
+
__exportStar(require("./roles.decorator"), exports);
|
|
19
|
+
__exportStar(require("./permissions.decorator"), exports);
|
|
20
|
+
__exportStar(require("./current-user.decorator"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key for required permissions
|
|
3
|
+
*/
|
|
4
|
+
export declare const PERMISSIONS_KEY = "permissions";
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to specify required permissions for accessing a route.
|
|
7
|
+
* Can be applied at controller or method level.
|
|
8
|
+
* User must have all specified permissions (AND logic).
|
|
9
|
+
*
|
|
10
|
+
* @param permissions - Array of permission codes required to access the route
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @RequirePermissions('users.create', 'users.update')
|
|
15
|
+
* @Post('users')
|
|
16
|
+
* createUser() {
|
|
17
|
+
* // User must have both users.create AND users.update permissions
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const RequirePermissions: (...permissions: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Decorator requiring any of the specified permissions (OR logic)
|
|
24
|
+
*
|
|
25
|
+
* @param permissions - Array of permission codes, user needs at least one
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* @RequireAnyPermission('users.read', 'users.show')
|
|
30
|
+
* @Get('users/:id')
|
|
31
|
+
* getUser() {
|
|
32
|
+
* // User needs either users.read OR users.show permission
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const RequireAnyPermission: (...permissions: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Decorator for read access (show, read, filter)
|
|
39
|
+
*
|
|
40
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* @ReadAccess('users')
|
|
45
|
+
* @Get('users')
|
|
46
|
+
* getUsers() {
|
|
47
|
+
* // User needs users.read, users.show, or users.filter permission
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare const ReadAccess: (module: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Decorator for write access (create, update)
|
|
54
|
+
*
|
|
55
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* @WriteAccess('users')
|
|
60
|
+
* @Put('users/:id')
|
|
61
|
+
* updateUser() {
|
|
62
|
+
* // User needs users.create or users.update permission
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare const WriteAccess: (module: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Decorator for delete access
|
|
69
|
+
*
|
|
70
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* @DeleteAccess('users')
|
|
75
|
+
* @Delete('users/:id')
|
|
76
|
+
* deleteUser() {
|
|
77
|
+
* // User needs users.delete permission
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare const DeleteAccess: (module: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Decorator for full CRUD access to a module
|
|
84
|
+
*
|
|
85
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* @FullAccess('users')
|
|
90
|
+
* @Controller('users')
|
|
91
|
+
* export class UsersController {
|
|
92
|
+
* // All methods require full user module access
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const FullAccess: (module: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
97
|
+
//# sourceMappingURL=permissions.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/permissions.decorator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,GAAI,GAAG,aAAa,MAAM,EAAE,qDAChB,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAAI,GAAG,aAAa,MAAM,EAAE,qDACjB,CAAC;AAE7C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,qDAKtC,CAAC;AAEJ;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,qDAIvC,CAAC;AAEJ;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,qDACH,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,qDAQtC,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullAccess = exports.DeleteAccess = exports.WriteAccess = exports.ReadAccess = exports.RequireAnyPermission = exports.RequirePermissions = exports.PERMISSIONS_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* Metadata key for required permissions
|
|
7
|
+
*/
|
|
8
|
+
exports.PERMISSIONS_KEY = 'permissions';
|
|
9
|
+
/**
|
|
10
|
+
* Decorator to specify required permissions for accessing a route.
|
|
11
|
+
* Can be applied at controller or method level.
|
|
12
|
+
* User must have all specified permissions (AND logic).
|
|
13
|
+
*
|
|
14
|
+
* @param permissions - Array of permission codes required to access the route
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @RequirePermissions('users.create', 'users.update')
|
|
19
|
+
* @Post('users')
|
|
20
|
+
* createUser() {
|
|
21
|
+
* // User must have both users.create AND users.update permissions
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const RequirePermissions = (...permissions) => (0, common_1.SetMetadata)(exports.PERMISSIONS_KEY, permissions);
|
|
26
|
+
exports.RequirePermissions = RequirePermissions;
|
|
27
|
+
/**
|
|
28
|
+
* Decorator requiring any of the specified permissions (OR logic)
|
|
29
|
+
*
|
|
30
|
+
* @param permissions - Array of permission codes, user needs at least one
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* @RequireAnyPermission('users.read', 'users.show')
|
|
35
|
+
* @Get('users/:id')
|
|
36
|
+
* getUser() {
|
|
37
|
+
* // User needs either users.read OR users.show permission
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
const RequireAnyPermission = (...permissions) => (0, common_1.SetMetadata)('anyPermissions', permissions);
|
|
42
|
+
exports.RequireAnyPermission = RequireAnyPermission;
|
|
43
|
+
/**
|
|
44
|
+
* Decorator for read access (show, read, filter)
|
|
45
|
+
*
|
|
46
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* @ReadAccess('users')
|
|
51
|
+
* @Get('users')
|
|
52
|
+
* getUsers() {
|
|
53
|
+
* // User needs users.read, users.show, or users.filter permission
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
const ReadAccess = (module) => (0, exports.RequireAnyPermission)(`${module}.read`, `${module}.show`, `${module}.filter`);
|
|
58
|
+
exports.ReadAccess = ReadAccess;
|
|
59
|
+
/**
|
|
60
|
+
* Decorator for write access (create, update)
|
|
61
|
+
*
|
|
62
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* @WriteAccess('users')
|
|
67
|
+
* @Put('users/:id')
|
|
68
|
+
* updateUser() {
|
|
69
|
+
* // User needs users.create or users.update permission
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
const WriteAccess = (module) => (0, exports.RequireAnyPermission)(`${module}.create`, `${module}.update`);
|
|
74
|
+
exports.WriteAccess = WriteAccess;
|
|
75
|
+
/**
|
|
76
|
+
* Decorator for delete access
|
|
77
|
+
*
|
|
78
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* @DeleteAccess('users')
|
|
83
|
+
* @Delete('users/:id')
|
|
84
|
+
* deleteUser() {
|
|
85
|
+
* // User needs users.delete permission
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
const DeleteAccess = (module) => (0, exports.RequirePermissions)(`${module}.delete`);
|
|
90
|
+
exports.DeleteAccess = DeleteAccess;
|
|
91
|
+
/**
|
|
92
|
+
* Decorator for full CRUD access to a module
|
|
93
|
+
*
|
|
94
|
+
* @param module - Module name (e.g., 'users', 'contracts')
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* @FullAccess('users')
|
|
99
|
+
* @Controller('users')
|
|
100
|
+
* export class UsersController {
|
|
101
|
+
* // All methods require full user module access
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
const FullAccess = (module) => (0, exports.RequireAnyPermission)(`${module}.create`, `${module}.read`, `${module}.update`, `${module}.delete`, `${module}.show`, `${module}.filter`);
|
|
106
|
+
exports.FullAccess = FullAccess;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key for public routes
|
|
3
|
+
*/
|
|
4
|
+
export declare const IS_PUBLIC_KEY = "isPublic";
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to mark routes as public (no authentication required)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Public()
|
|
11
|
+
* @Get('health')
|
|
12
|
+
* getHealth() {
|
|
13
|
+
* return { status: 'OK' };
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
|
|
18
|
+
//# sourceMappingURL=public.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/public.decorator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,MAAM,wDAAyC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* Metadata key for public routes
|
|
7
|
+
*/
|
|
8
|
+
exports.IS_PUBLIC_KEY = 'isPublic';
|
|
9
|
+
/**
|
|
10
|
+
* Decorator to mark routes as public (no authentication required)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Public()
|
|
15
|
+
* @Get('health')
|
|
16
|
+
* getHealth() {
|
|
17
|
+
* return { status: 'OK' };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
22
|
+
exports.Public = Public;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key for required roles
|
|
3
|
+
*/
|
|
4
|
+
export declare const ROLES_KEY = "roles";
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to specify required roles for accessing a route.
|
|
7
|
+
* Can be applied at controller or method level.
|
|
8
|
+
* User must have at least one of the specified roles (OR logic).
|
|
9
|
+
*
|
|
10
|
+
* @param roles - Array of role names required to access the route
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Roles('superadmin', 'client_contract_admin')
|
|
15
|
+
* @Get('admin-data')
|
|
16
|
+
* getAdminData() {
|
|
17
|
+
* // Only users with superadmin OR client_contract_admin role
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const Roles: (...roles: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Decorator for ContractX specific admin roles
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* @AdminOnly()
|
|
28
|
+
* @Delete(':id')
|
|
29
|
+
* deleteResource() {
|
|
30
|
+
* // Only admin roles can access
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const AdminOnly: () => import("@nestjs/common").CustomDecorator<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Decorator for client-side roles only
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @ClientOnly()
|
|
41
|
+
* @Get('client-data')
|
|
42
|
+
* getClientData() {
|
|
43
|
+
* // Only client-side roles can access
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const ClientOnly: () => import("@nestjs/common").CustomDecorator<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Decorator for provider-side roles only
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* @ProviderOnly()
|
|
54
|
+
* @Get('provider-data')
|
|
55
|
+
* getProviderData() {
|
|
56
|
+
* // Only provider-side roles can access
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const ProviderOnly: () => import("@nestjs/common").CustomDecorator<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Decorator for superadmin access only
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* @SuperAdminOnly()
|
|
67
|
+
* @Post('system/configure')
|
|
68
|
+
* configureSystem() {
|
|
69
|
+
* // Only superadmin can access
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const SuperAdminOnly: () => import("@nestjs/common").CustomDecorator<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Alias for Roles decorator for backward compatibility
|
|
76
|
+
* @deprecated Use Roles instead
|
|
77
|
+
*/
|
|
78
|
+
export declare const RequireRoles: (...roles: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
79
|
+
//# sourceMappingURL=roles.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/roles.decorator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,GAAI,GAAG,OAAO,MAAM,EAAE,qDAAkC,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,wDAIrB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,wDAOtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,wDAOxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,wDAA4B,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,YAAY,aAhFO,MAAM,EAAE,qDAgFP,CAAC"}
|