@takentrade/takentrade-libs 4.1.2 → 4.1.3
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
CHANGED
|
@@ -12,9 +12,20 @@ npm install @takentrade/takentrade-libs
|
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { CacheModule } from '@takentrade/takentrade-libs';
|
|
15
|
+
import { ConfigService } from '@nestjs/config';
|
|
15
16
|
|
|
16
17
|
@Module({
|
|
17
|
-
imports: [
|
|
18
|
+
imports: [
|
|
19
|
+
CacheModule.registerAsync({
|
|
20
|
+
inject: [ConfigService],
|
|
21
|
+
useFactory: (configService: ConfigService) => ({
|
|
22
|
+
host: configService.get<string>('redis.host'),
|
|
23
|
+
port: configService.get<number>('redis.port'),
|
|
24
|
+
username: configService.get<string>('redis.username'),
|
|
25
|
+
password: configService.get<string>('redis.password'),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
18
29
|
})
|
|
19
30
|
export class AppModule {}
|
|
20
31
|
```
|
|
@@ -32,7 +32,9 @@ let TntBaseAuthGuard = TntBaseAuthGuard_1 = class TntBaseAuthGuard extends (0, p
|
|
|
32
32
|
void status;
|
|
33
33
|
if (err || !user) {
|
|
34
34
|
const request = context.switchToHttp().getRequest();
|
|
35
|
-
const message = err instanceof Error
|
|
35
|
+
const message = err instanceof Error
|
|
36
|
+
? err.message
|
|
37
|
+
: (info?.message ?? 'Authentication failed');
|
|
36
38
|
this.logger.error(`JWT validation error on ${request.method ?? 'UNKNOWN'} ${request.url ?? 'UNKNOWN'}: ${message}`);
|
|
37
39
|
if (info?.name === 'TokenExpiredError') {
|
|
38
40
|
throw new common_1.UnauthorizedException('Token has expired');
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, InjectionToken, ModuleMetadata } from '@nestjs/common';
|
|
2
2
|
import { CacheOptions } from './cache.interface';
|
|
3
3
|
export declare class CacheModule {
|
|
4
|
-
static
|
|
4
|
+
static registerAsync(options: {
|
|
5
|
+
imports?: ModuleMetadata['imports'];
|
|
6
|
+
inject?: InjectionToken[];
|
|
7
|
+
useFactory: (...args: any[]) => Promise<CacheOptions> | CacheOptions;
|
|
8
|
+
}): DynamicModule;
|
|
5
9
|
}
|
|
@@ -12,11 +12,18 @@ const common_1 = require("@nestjs/common");
|
|
|
12
12
|
const config_1 = require("@nestjs/config");
|
|
13
13
|
const cache_service_1 = require("./cache.service");
|
|
14
14
|
let CacheModule = CacheModule_1 = class CacheModule {
|
|
15
|
-
static
|
|
15
|
+
static registerAsync(options) {
|
|
16
16
|
return {
|
|
17
17
|
module: CacheModule_1,
|
|
18
|
-
imports: [config_1.ConfigModule],
|
|
19
|
-
providers: [
|
|
18
|
+
imports: [...(options.imports ?? []), config_1.ConfigModule],
|
|
19
|
+
providers: [
|
|
20
|
+
cache_service_1.CacheService,
|
|
21
|
+
{
|
|
22
|
+
provide: 'options',
|
|
23
|
+
inject: options.inject ?? [],
|
|
24
|
+
useFactory: options.useFactory,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
20
27
|
exports: [cache_service_1.CacheService],
|
|
21
28
|
};
|
|
22
29
|
}
|