@illustrisinteractive/sentinel-nest 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@illustrisinteractive/sentinel-nest",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "author": "John Dela Vega <john@luminotion.com>",
6
6
  "license": "MIT",
@@ -1,4 +1,6 @@
1
+ import { SetMetadata } from '@nestjs/common';
1
2
  import { SecuredResourceAction } from './main';
2
- import { Reflector } from '@nestjs/core';
3
3
 
4
- export const Can = Reflector.createDecorator<SecuredResourceAction[]>();
4
+ export const CAN_KEY = 'can';
5
+ export const Can = (...actions: SecuredResourceAction[]) =>
6
+ SetMetadata(CAN_KEY, actions);
@@ -1,26 +1,22 @@
1
- import {
2
- CanActivate,
3
- ExecutionContext,
4
- Inject,
5
- Injectable,
6
- } from '@nestjs/common';
1
+ import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
7
2
  import { SentinelService } from './sentinel.service';
8
3
  import { type Metadata } from '@grpc/grpc-js';
9
4
  import { type Request } from 'express';
10
5
  import { SentinelModel } from './models/SentinelModel';
11
6
  import { Reflector } from '@nestjs/core';
12
- import { Can, SecuredResourceAction } from './main';
7
+ import { SecuredResourceAction } from './main';
8
+ import { CAN_KEY } from './can.decorator';
13
9
 
14
10
  @Injectable()
15
11
  export class SentinelGuard implements CanActivate {
16
12
  constructor(
17
13
  private readonly sentinelService: SentinelService,
18
- @Inject(Reflector) private reflector: Reflector,
14
+ private reflector: Reflector,
19
15
  ) {}
20
16
  canActivate(context: ExecutionContext): boolean {
21
17
  const requiredActions = this.reflector.getAllAndOverride<
22
18
  SecuredResourceAction[]
23
- >(Can, [context.getHandler(), context.getClass()]);
19
+ >(CAN_KEY, [context.getHandler(), context.getClass()]);
24
20
 
25
21
  if (requiredActions.length == 0) return true;
26
22