@illustrisinteractive/sentinel-nest 0.0.5 → 0.0.7
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/dist/bin/resource.js +1 -0
- package/dist/bin/resource.js.map +1 -1
- package/dist/models/SecuredResource.d.ts +1 -0
- package/dist/src/models/SecuredResource.d.ts +1 -0
- package/dist/src/sentinel/resources/NewResource3.d.ts +4 -0
- package/dist/src/sentinel/resources/NewResource3.js +18 -0
- package/dist/src/sentinel/resources/NewResource3.js.map +1 -0
- package/dist/src/sentinel/resources/TestResource.d.ts +4 -0
- package/dist/src/sentinel/resources/TestResource.js +18 -0
- package/dist/src/sentinel/resources/TestResource.js.map +1 -0
- package/dist/src/sentinel.guard.d.ts +2 -1
- package/dist/src/sentinel.guard.js +9 -10
- package/dist/src/sentinel.guard.js.map +1 -1
- package/dist/src/sentinel.module.js +2 -3
- package/dist/src/sentinel.module.js.map +1 -1
- package/dist/src/sentinel.service.js +2 -2
- package/dist/src/sentinel.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/bin/resource.ts +1 -0
- package/src/main.ts +2 -2
- package/src/models/SecuredResource.ts +1 -0
- package/src/models/SentinelConfig.d.ts +4 -4
- package/src/sentinel/resources/.sentinel/NewResource2.d.ts +4 -0
- package/src/sentinel/resources/.sentinel/NewResource2.js +13 -0
- package/src/sentinel/resources/.sentinel/NewResource2.js.map +1 -0
- package/src/sentinel/resources/.sentinel/NewResource3.d.ts +4 -0
- package/src/sentinel/resources/.sentinel/NewResource3.js +18 -0
- package/src/sentinel/resources/.sentinel/NewResource3.js.map +1 -0
- package/src/sentinel/resources/.sentinel/TestResource.d.ts +5 -0
- package/src/sentinel/resources/.sentinel/TestResource.js +19 -0
- package/src/sentinel/resources/.sentinel/TestResource.js.map +1 -0
- package/src/sentinel/resources/.sentinel/tsconfig.tsbuildinfo +1 -0
- package/src/sentinel/resources/NewResource3.ts +18 -0
- package/src/sentinel/resources/TestResource.ts +18 -0
- package/src/sentinel/resources/tsconfig.json +26 -0
- package/src/sentinel/sentinel.config.json +39 -0
- package/src/sentinel.guard.ts +13 -6
- package/src/sentinel.module.ts +2 -3
- package/src/sentinel.service.ts +2 -6
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"resolvePackageJsonExports": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"removeComments": true,
|
|
10
|
+
"emitDecoratorMetadata": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"target": "ES2023",
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"outDir": ".sentinel/",
|
|
16
|
+
"baseUrl": "./",
|
|
17
|
+
"incremental": true,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"strictNullChecks": true,
|
|
20
|
+
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
"noImplicitAny": false,
|
|
22
|
+
"strictBindCallApply": false,
|
|
23
|
+
"noFallthroughCasesInSwitch": false,
|
|
24
|
+
"allowJs": true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-workspace",
|
|
3
|
+
"sourceRoot": "apps/my-workspace/src",
|
|
4
|
+
"sentinelConfigPath": "apps/my-workspace/src\\sentinel",
|
|
5
|
+
"resources": [
|
|
6
|
+
{
|
|
7
|
+
"name": "TestResource",
|
|
8
|
+
"actions": {
|
|
9
|
+
"manage": {
|
|
10
|
+
"description": "Allows all Actions in this Secured Resource."
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "NewResource",
|
|
16
|
+
"actions": {
|
|
17
|
+
"manage": {
|
|
18
|
+
"description": "Allows all Actions in this Secured Resource."
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "NewResource2",
|
|
24
|
+
"actions": {
|
|
25
|
+
"manage": {
|
|
26
|
+
"description": "Allows all Actions in this Secured Resource."
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "NewResource3",
|
|
32
|
+
"actions": {
|
|
33
|
+
"manage": {
|
|
34
|
+
"description": "Allows all Actions in this Secured Resource."
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
package/src/sentinel.guard.ts
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CanActivate,
|
|
3
3
|
ExecutionContext,
|
|
4
|
-
Inject,
|
|
5
4
|
Injectable,
|
|
5
|
+
Logger,
|
|
6
6
|
} from '@nestjs/common';
|
|
7
7
|
import { SentinelService } from './sentinel.service';
|
|
8
8
|
import { type Metadata } from '@grpc/grpc-js';
|
|
9
9
|
import { type Request } from 'express';
|
|
10
10
|
import { SentinelModel } from './models/SentinelModel';
|
|
11
11
|
import { Reflector } from '@nestjs/core';
|
|
12
|
-
import { Can
|
|
12
|
+
import { Can } from '../src/can.decorator';
|
|
13
|
+
import { SecuredResourceAction } from './main';
|
|
13
14
|
@Injectable()
|
|
14
15
|
export class SentinelGuard implements CanActivate {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly sentinelService: SentinelService,
|
|
18
|
+
private reflector: Reflector,
|
|
19
|
+
) {}
|
|
17
20
|
canActivate(context: ExecutionContext): boolean {
|
|
18
21
|
const requiredActions = this.reflector.get<SecuredResourceAction[]>(
|
|
19
22
|
Can,
|
|
20
23
|
context.getHandler(),
|
|
21
24
|
);
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
if (!requiredActions || requiredActions.length == 0) {
|
|
26
|
+
Logger.warn(
|
|
27
|
+
'It seems like you used SentinelGuard without passing a SecuredResourceAction to look out for. Handler: ${context.getHandler().name}',
|
|
28
|
+
);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
24
31
|
|
|
25
32
|
let sentinelAuth = '';
|
|
26
33
|
if (context.getType() == 'rpc') {
|
package/src/sentinel.module.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
4
4
|
import { PrismaService } from './prisma.service';
|
|
5
5
|
import { ConfigurableModuleClass } from './sentinel.module-definition';
|
|
6
6
|
import { JwtModule } from '@nestjs/jwt';
|
|
7
|
-
import { SentinelGuard } from './sentinel.guard';
|
|
8
7
|
|
|
9
8
|
@Module({
|
|
10
9
|
imports: [
|
|
@@ -21,7 +20,7 @@ import { SentinelGuard } from './sentinel.guard';
|
|
|
21
20
|
}),
|
|
22
21
|
],
|
|
23
22
|
controllers: [],
|
|
24
|
-
providers: [PrismaService, SentinelService
|
|
25
|
-
exports: [PrismaService, SentinelService
|
|
23
|
+
providers: [PrismaService, SentinelService],
|
|
24
|
+
exports: [PrismaService, SentinelService],
|
|
26
25
|
})
|
|
27
26
|
export class SentinelModule extends ConfigurableModuleClass {}
|
package/src/sentinel.service.ts
CHANGED
|
@@ -52,9 +52,7 @@ export class SentinelService implements OnModuleInit {
|
|
|
52
52
|
for (const resource of this.resources) {
|
|
53
53
|
for (const action of Object.keys(resource.actions)) {
|
|
54
54
|
if (
|
|
55
|
-
model.permissions.find(
|
|
56
|
-
(permissions) => permissions.action == resource.actions[action],
|
|
57
|
-
)
|
|
55
|
+
model.permissions.find((permissions) => permissions.action == action)
|
|
58
56
|
) {
|
|
59
57
|
can(action, resource.name);
|
|
60
58
|
} else cannot(action, resource.name);
|
|
@@ -97,9 +95,7 @@ export class SentinelService implements OnModuleInit {
|
|
|
97
95
|
for (const resource of this.resources) {
|
|
98
96
|
for (const action of Object.keys(resource.actions)) {
|
|
99
97
|
if (
|
|
100
|
-
model.permissions.find(
|
|
101
|
-
(permissions) => permissions.action == resource.actions[action],
|
|
102
|
-
)
|
|
98
|
+
model.permissions.find((permissions) => permissions.action == action)
|
|
103
99
|
) {
|
|
104
100
|
can(action, resource.name);
|
|
105
101
|
} else cannot(action, resource.name);
|