@ubs-platform/users-mona-roles 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.json +18 -0
- package/README.md +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/backend-global-ubs-roles.module.d.ts +2 -0
- package/dist/lib/backend-global-ubs-roles.module.js +16 -0
- package/dist/lib/backend-global-ubs-roles.module.js.map +1 -0
- package/dist/lib/decorator/roles.decorator.d.ts +1 -0
- package/dist/lib/decorator/roles.decorator.js +6 -0
- package/dist/lib/decorator/roles.decorator.js.map +1 -0
- package/dist/lib/guards/role-guard.guard.d.ts +7 -0
- package/dist/lib/guards/role-guard.guard.js +31 -0
- package/dist/lib/guards/role-guard.guard.js.map +1 -0
- package/dist/lib/match-role.d.ts +1 -0
- package/dist/lib/match-role.js +8 -0
- package/dist/lib/match-role.js.map +1 -0
- package/jest.config.ts +11 -0
- package/package.json +32 -0
- package/tsconfig.json +27 -0
- package/tsconfig.lib.json +16 -0
package/.eslintrc.json
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"extends": ["../../.eslintrc.base.json"],
|
3
|
+
"ignorePatterns": ["!**/*"],
|
4
|
+
"overrides": [
|
5
|
+
{
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
7
|
+
"rules": {}
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
11
|
+
"rules": {}
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"files": ["*.js", "*.jsx"],
|
15
|
+
"rules": {}
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const tslib_1 = require("tslib");
|
4
|
+
tslib_1.__exportStar(require("./lib/backend-global-ubs-roles.module"), exports);
|
5
|
+
tslib_1.__exportStar(require("./lib/guards/role-guard.guard"), exports);
|
6
|
+
tslib_1.__exportStar(require("./lib/decorator/roles.decorator"), exports);
|
7
|
+
tslib_1.__exportStar(require("./lib/match-role"), exports);
|
8
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gFAAsD;AACtD,wEAA6C;AAC7C,0EAA+C;AAC/C,2DAAgC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BackendGlobalUbsRolesModule = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const common_1 = require("@nestjs/common");
|
6
|
+
let BackendGlobalUbsRolesModule = class BackendGlobalUbsRolesModule {
|
7
|
+
};
|
8
|
+
exports.BackendGlobalUbsRolesModule = BackendGlobalUbsRolesModule;
|
9
|
+
exports.BackendGlobalUbsRolesModule = BackendGlobalUbsRolesModule = tslib_1.__decorate([
|
10
|
+
(0, common_1.Module)({
|
11
|
+
controllers: [],
|
12
|
+
providers: [],
|
13
|
+
exports: [],
|
14
|
+
})
|
15
|
+
], BackendGlobalUbsRolesModule);
|
16
|
+
//# sourceMappingURL=backend-global-ubs-roles.module.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"backend-global-ubs-roles.module.js","sourceRoot":"","sources":["../../src/lib/backend-global-ubs-roles.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAwC;AAOjC,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;CAAG,CAAA;AAA9B,kEAA2B;sCAA3B,2BAA2B;IALvC,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,EAAE;QACf,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,2BAA2B,CAAG"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const Roles: import("@nestjs/core").ReflectableDecorator<string[], string[]>;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"roles.decorator.js","sourceRoot":"","sources":["../../../src/lib/decorator/roles.decorator.ts"],"names":[],"mappings":";;;AACA,uCAAyC;AAE5B,QAAA,KAAK,GAAG,gBAAS,CAAC,eAAe,EAAY,CAAC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
2
|
+
import { Reflector } from '@nestjs/core';
|
3
|
+
export declare class RolesGuard implements CanActivate {
|
4
|
+
private reflector;
|
5
|
+
constructor(reflector: Reflector);
|
6
|
+
canActivate(context: ExecutionContext): boolean;
|
7
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RolesGuard = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const common_1 = require("@nestjs/common");
|
6
|
+
const core_1 = require("@nestjs/core");
|
7
|
+
const roles_decorator_1 = require("../decorator/roles.decorator");
|
8
|
+
const match_role_1 = require("../match-role");
|
9
|
+
let RolesGuard = class RolesGuard {
|
10
|
+
constructor(reflector) {
|
11
|
+
this.reflector = reflector;
|
12
|
+
}
|
13
|
+
canActivate(context) {
|
14
|
+
const roles = this.reflector.get(roles_decorator_1.Roles, context.getHandler());
|
15
|
+
if (!roles) {
|
16
|
+
return true;
|
17
|
+
}
|
18
|
+
else {
|
19
|
+
roles.push('ADMIN');
|
20
|
+
}
|
21
|
+
const request = context.switchToHttp().getRequest();
|
22
|
+
const user = request.user;
|
23
|
+
return (0, match_role_1.matchRoles)(roles, user.roles);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
exports.RolesGuard = RolesGuard;
|
27
|
+
exports.RolesGuard = RolesGuard = tslib_1.__decorate([
|
28
|
+
(0, common_1.Injectable)(),
|
29
|
+
tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
|
30
|
+
], RolesGuard);
|
31
|
+
//# sourceMappingURL=role-guard.guard.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"role-guard.guard.js","sourceRoot":"","sources":["../../../src/lib/guards/role-guard.guard.ts"],"names":[],"mappings":";;;;AAAA,2CAA2E;AAC3E,uCAAyC;AACzC,kEAAqD;AACrD,8CAA2C;AAIpC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C,WAAW,CAAC,OAAyB;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,uBAAK,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,OAAO,CAAC,IAA0B,CAAC;QAChD,OAAO,IAAA,uBAAU,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF,CAAA;AAdY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;6CAEoB,gBAAS;GAD7B,UAAU,CActB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function matchRoles(roles: string[], userRoles: string[]): boolean;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.matchRoles = void 0;
|
4
|
+
function matchRoles(roles, userRoles) {
|
5
|
+
return roles.reduce((a, b) => a || userRoles.includes(b), false);
|
6
|
+
}
|
7
|
+
exports.matchRoles = matchRoles;
|
8
|
+
//# sourceMappingURL=match-role.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"match-role.js","sourceRoot":"","sources":["../../src/lib/match-role.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,KAAe,EAAE,SAAmB;IAC7D,OAAQ,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAE;AACrE,CAAC;AAFD,gCAEC"}
|
package/jest.config.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
/* eslint-disable */
|
2
|
+
export default {
|
3
|
+
displayName: 'roles',
|
4
|
+
preset: '../../jest.preset.js',
|
5
|
+
testEnvironment: 'node',
|
6
|
+
transform: {
|
7
|
+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
8
|
+
},
|
9
|
+
moduleFileExtensions: ['ts', 'js', 'html'],
|
10
|
+
coverageDirectory: '../../coverage/libs/roles',
|
11
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"name": "@ubs-platform/users-mona-roles",
|
3
|
+
"version": "1.0.1",
|
4
|
+
"private": false,
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"author": "Unlimited Bundle Systems",
|
7
|
+
"homepage": "https://github.com/ubs-platform/users-mona-roles",
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "https://github.com/ubs-platform/users-mona-roles"
|
11
|
+
},
|
12
|
+
"scripts": {
|
13
|
+
"build": "tsc",
|
14
|
+
"build-publish": "npm run build && npm publish"
|
15
|
+
},
|
16
|
+
"peerDependencies": {
|
17
|
+
"@nestjs/common": "^10.0.2",
|
18
|
+
"@nestjs/core": "^10.0.2",
|
19
|
+
"@ubs-platform/users-common": "1.0.8"
|
20
|
+
},
|
21
|
+
"dependencies": {
|
22
|
+
"tslib": "^2.3.0",
|
23
|
+
"crypto-promise": "^2.1.0"
|
24
|
+
},
|
25
|
+
"devDependencies": {
|
26
|
+
"typescript": "~5.3.2",
|
27
|
+
"@types/node": "~18.16.9"
|
28
|
+
},
|
29
|
+
"publishConfig": {
|
30
|
+
"access": "public"
|
31
|
+
}
|
32
|
+
}
|
package/tsconfig.json
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"compileOnSave": false,
|
3
|
+
"compilerOptions": {
|
4
|
+
"rootDir": "./src",
|
5
|
+
"sourceMap": true,
|
6
|
+
"moduleResolution": "node",
|
7
|
+
"emitDecoratorMetadata": true,
|
8
|
+
"experimentalDecorators": true,
|
9
|
+
"importHelpers": true,
|
10
|
+
"target": "es2015",
|
11
|
+
"module": "commonjs",
|
12
|
+
"outDir": "./dist",
|
13
|
+
"lib": ["es2020", "dom"],
|
14
|
+
"skipLibCheck": true,
|
15
|
+
"skipDefaultLibCheck": true,
|
16
|
+
"declaration": true,
|
17
|
+
"types": ["node"]
|
18
|
+
},
|
19
|
+
"exclude": [
|
20
|
+
"node_modules",
|
21
|
+
"tmp",
|
22
|
+
"jest.config.ts",
|
23
|
+
"src/**/*.spec.ts",
|
24
|
+
"src/**/*.test.ts"
|
25
|
+
],
|
26
|
+
"include": ["src/**/*.ts"]
|
27
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../dist/out-tsc",
|
5
|
+
"declaration": true,
|
6
|
+
"types": ["node"],
|
7
|
+
"target": "es2021",
|
8
|
+
"strictNullChecks": true,
|
9
|
+
"noImplicitAny": true,
|
10
|
+
"strictBindCallApply": true,
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
12
|
+
"noFallthroughCasesInSwitch": true
|
13
|
+
},
|
14
|
+
"include": ["src/**/*.ts"],
|
15
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
|
16
|
+
}
|