nestjs-ip-filter 0.1.3 → 0.2.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/README.md +7 -7
- package/dist/index.d.ts +1 -2
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/ipfilter.constants.d.ts +0 -1
- package/dist/ipfilter.constants.js +1 -2
- package/dist/ipfilter.constants.js.map +1 -1
- package/dist/ipfilter.interface.d.ts +0 -10
- package/dist/ipfilter.module-definition.d.ts +2 -0
- package/dist/ipfilter.module-definition.js +7 -0
- package/dist/ipfilter.module-definition.js.map +1 -0
- package/dist/ipfilter.module.d.ts +2 -5
- package/dist/ipfilter.module.js +27 -16
- package/dist/ipfilter.module.js.map +1 -1
- package/dist/ipfilter.service.js +2 -2
- package/dist/ipfilter.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/index.ts +1 -2
- package/lib/ipfilter.constants.ts +0 -1
- package/lib/ipfilter.interface.ts +0 -18
- package/lib/ipfilter.module-definition.ts +5 -0
- package/lib/ipfilter.module.ts +19 -20
- package/lib/ipfilter.service.ts +2 -2
- package/package.json +18 -18
- package/dist/ipfilter-core.module.d.ts +0 -24
- package/dist/ipfilter-core.module.js +0 -87
- package/dist/ipfilter-core.module.js.map +0 -1
- package/dist/ipfilter.providers.d.ts +0 -3
- package/dist/ipfilter.providers.js +0 -13
- package/dist/ipfilter.providers.js.map +0 -1
- package/lib/ipfilter-core.module.ts +0 -94
- package/lib/ipfilter.providers.ts +0 -13
package/lib/ipfilter.module.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { DynamicModule, Module } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from './ipfilter.
|
|
2
|
+
import { APP_GUARD } from '@nestjs/core';
|
|
3
|
+
import { IPFILTER_TOKEN } from './ipfilter.constants';
|
|
4
|
+
import { IpFilterGuard } from './ipfilter.guard';
|
|
5
|
+
import { ConfigurableModuleClass } from './ipfilter.module-definition';
|
|
6
|
+
import { IpFilterService } from './ipfilter.service';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module: IpFilter,
|
|
13
|
-
imports: [IpFilterCoreModule.forRoot(options)],
|
|
14
|
-
};
|
|
15
|
-
}
|
|
8
|
+
const ipFilterServiceProvider = {
|
|
9
|
+
provide: IPFILTER_TOKEN,
|
|
10
|
+
useClass: IpFilterService,
|
|
11
|
+
};
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const ipFilterGuardProvider = {
|
|
14
|
+
provide: APP_GUARD,
|
|
15
|
+
useClass: IpFilterGuard,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
@Module({
|
|
19
|
+
providers: [ipFilterServiceProvider, ipFilterGuardProvider],
|
|
20
|
+
exports: [ipFilterServiceProvider],
|
|
21
|
+
})
|
|
22
|
+
export class IpFilter extends ConfigurableModuleClass {}
|
package/lib/ipfilter.service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Inject, Injectable } from '@nestjs/common';
|
|
2
2
|
import { IpFilterModuleOptions } from './ipfilter.interface';
|
|
3
|
-
import {
|
|
3
|
+
import { MODULE_OPTIONS_TOKEN } from './ipfilter.module-definition';
|
|
4
4
|
|
|
5
5
|
@Injectable()
|
|
6
6
|
export class IpFilterService {
|
|
@@ -10,7 +10,7 @@ export class IpFilterService {
|
|
|
10
10
|
private _blacklist: string[];
|
|
11
11
|
|
|
12
12
|
constructor(
|
|
13
|
-
@Inject(
|
|
13
|
+
@Inject(MODULE_OPTIONS_TOKEN)
|
|
14
14
|
readonly options: IpFilterModuleOptions,
|
|
15
15
|
) {
|
|
16
16
|
this.useDenyException = options.useDenyException ?? false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-ip-filter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A NestJS Guard for filtering IP addresses",
|
|
5
5
|
"author": "Deokgyu Yang <secugyu@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -34,35 +34,35 @@
|
|
|
34
34
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nestjs/common": "
|
|
38
|
-
"@nestjs/core": "
|
|
39
|
-
"@nestjs/platform-express": "
|
|
37
|
+
"@nestjs/common": "9.0.0",
|
|
38
|
+
"@nestjs/core": "9.0.0",
|
|
39
|
+
"@nestjs/platform-express": "9.0.0",
|
|
40
40
|
"@supercharge/request-ip": "1.2.0",
|
|
41
41
|
"reflect-metadata": "0.1.13",
|
|
42
42
|
"rimraf": "3.0.2",
|
|
43
|
-
"rxjs": "7.5.
|
|
43
|
+
"rxjs": "7.5.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@nestjs/cli": "
|
|
47
|
-
"@nestjs/schematics": "
|
|
48
|
-
"@nestjs/testing": "
|
|
46
|
+
"@nestjs/cli": "9.0.0",
|
|
47
|
+
"@nestjs/schematics": "9.0.0",
|
|
48
|
+
"@nestjs/testing": "9.0.0",
|
|
49
49
|
"@types/express": "4.17.13",
|
|
50
|
-
"@types/jest": "28.1.
|
|
51
|
-
"@types/node": "
|
|
50
|
+
"@types/jest": "28.1.5",
|
|
51
|
+
"@types/node": "18.0.4",
|
|
52
52
|
"@types/supertest": "2.0.12",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
54
|
-
"@typescript-eslint/parser": "5.
|
|
55
|
-
"eslint": "8.
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "5.30.6",
|
|
54
|
+
"@typescript-eslint/parser": "5.30.6",
|
|
55
|
+
"eslint": "8.19.0",
|
|
56
56
|
"eslint-config-google": "0.14.0",
|
|
57
57
|
"eslint-config-prettier": "8.5.0",
|
|
58
|
-
"eslint-plugin-prettier": "4.
|
|
59
|
-
"jest": "28.1.
|
|
58
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
59
|
+
"jest": "28.1.3",
|
|
60
60
|
"prettier": "2.7.1",
|
|
61
61
|
"source-map-support": "0.5.21",
|
|
62
|
-
"supertest": "6.2.
|
|
63
|
-
"ts-jest": "28.0.
|
|
62
|
+
"supertest": "6.2.4",
|
|
63
|
+
"ts-jest": "28.0.6",
|
|
64
64
|
"ts-loader": "9.3.1",
|
|
65
|
-
"ts-node": "10.
|
|
65
|
+
"ts-node": "10.9.1",
|
|
66
66
|
"tsconfig-paths": "4.0.0",
|
|
67
67
|
"typescript": "4.7.4"
|
|
68
68
|
},
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Provider, Type } from '@nestjs/common';
|
|
2
|
-
import { IpFilterModuleAsyncOptions, IpFilterModuleOptions } from './ipfilter.interface';
|
|
3
|
-
import { IpFilterGuard } from './ipfilter.guard';
|
|
4
|
-
export declare class IpFilterCoreModule {
|
|
5
|
-
static forRoot(options: IpFilterModuleOptions): {
|
|
6
|
-
module: typeof IpFilterCoreModule;
|
|
7
|
-
providers: (Provider<any> | {
|
|
8
|
-
provide: string;
|
|
9
|
-
useClass: typeof IpFilterGuard;
|
|
10
|
-
})[];
|
|
11
|
-
exports: Provider<any>[];
|
|
12
|
-
};
|
|
13
|
-
static forRootAsync(options: IpFilterModuleAsyncOptions): {
|
|
14
|
-
module: typeof IpFilterCoreModule;
|
|
15
|
-
imports: (Type<any> | import("@nestjs/common").DynamicModule | Promise<import("@nestjs/common").DynamicModule> | import("@nestjs/common").ForwardReference<any>)[];
|
|
16
|
-
providers: (Provider<any> | {
|
|
17
|
-
provide: string;
|
|
18
|
-
useClass: typeof IpFilterGuard;
|
|
19
|
-
})[];
|
|
20
|
-
exports: import("@nestjs/common").FactoryProvider<any>[];
|
|
21
|
-
};
|
|
22
|
-
private static createAsyncProviders;
|
|
23
|
-
private static createAsyncOptionsProvider;
|
|
24
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var IpFilterCoreModule_1;
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.IpFilterCoreModule = void 0;
|
|
11
|
-
const common_1 = require("@nestjs/common");
|
|
12
|
-
const ipfilter_constants_1 = require("./ipfilter.constants");
|
|
13
|
-
const ipfilter_providers_1 = require("./ipfilter.providers");
|
|
14
|
-
const ipfilter_service_1 = require("./ipfilter.service");
|
|
15
|
-
const core_1 = require("@nestjs/core");
|
|
16
|
-
const ipfilter_guard_1 = require("./ipfilter.guard");
|
|
17
|
-
let IpFilterCoreModule = IpFilterCoreModule_1 = class IpFilterCoreModule {
|
|
18
|
-
static forRoot(options) {
|
|
19
|
-
const ipFilterServiceProvider = (0, ipfilter_providers_1.createIpFilterProviders)(options);
|
|
20
|
-
const ipFilterGuardProvider = {
|
|
21
|
-
provide: core_1.APP_GUARD,
|
|
22
|
-
useClass: ipfilter_guard_1.IpFilterGuard,
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
module: IpFilterCoreModule_1,
|
|
26
|
-
providers: [ipFilterGuardProvider, ipFilterServiceProvider],
|
|
27
|
-
exports: [ipFilterServiceProvider],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
static forRootAsync(options) {
|
|
31
|
-
const provider = {
|
|
32
|
-
inject: [ipfilter_constants_1.IPFILTER_MODULE_OPTIONS],
|
|
33
|
-
provide: ipfilter_constants_1.IPFILTER_TOKEN,
|
|
34
|
-
useFactory: (options) => new ipfilter_service_1.IpFilterService(options),
|
|
35
|
-
};
|
|
36
|
-
const ipFilterGuardProvider = {
|
|
37
|
-
provide: core_1.APP_GUARD,
|
|
38
|
-
useClass: ipfilter_guard_1.IpFilterGuard,
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
module: IpFilterCoreModule_1,
|
|
42
|
-
imports: options.imports,
|
|
43
|
-
providers: [
|
|
44
|
-
...this.createAsyncProviders(options),
|
|
45
|
-
ipFilterGuardProvider,
|
|
46
|
-
provider,
|
|
47
|
-
],
|
|
48
|
-
exports: [provider],
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
static createAsyncProviders(options) {
|
|
52
|
-
if (options.useExisting || options.useFactory) {
|
|
53
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
54
|
-
}
|
|
55
|
-
const useClass = options.useClass;
|
|
56
|
-
return [
|
|
57
|
-
this.createAsyncOptionsProvider(options),
|
|
58
|
-
{
|
|
59
|
-
provide: useClass,
|
|
60
|
-
useClass,
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
static createAsyncOptionsProvider(options) {
|
|
65
|
-
if (options.useFactory) {
|
|
66
|
-
return {
|
|
67
|
-
inject: options.inject || [],
|
|
68
|
-
provide: ipfilter_constants_1.IPFILTER_MODULE_OPTIONS,
|
|
69
|
-
useFactory: options.useFactory,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const inject = [
|
|
73
|
-
(options.useClass || options.useExisting),
|
|
74
|
-
];
|
|
75
|
-
return {
|
|
76
|
-
provide: ipfilter_constants_1.IPFILTER_MODULE_OPTIONS,
|
|
77
|
-
useFactory: async (optionsFactory) => await optionsFactory.createIpFilterModuleOptions(),
|
|
78
|
-
inject,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
IpFilterCoreModule = IpFilterCoreModule_1 = __decorate([
|
|
83
|
-
(0, common_1.Global)(),
|
|
84
|
-
(0, common_1.Module)({})
|
|
85
|
-
], IpFilterCoreModule);
|
|
86
|
-
exports.IpFilterCoreModule = IpFilterCoreModule;
|
|
87
|
-
//# sourceMappingURL=ipfilter-core.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ipfilter-core.module.js","sourceRoot":"","sources":["../lib/ipfilter-core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAgE;AAMhE,6DAA+E;AAC/E,6DAA+D;AAC/D,yDAAqD;AACrD,uCAAyC;AACzC,qDAAiD;AAIjD,IAAa,kBAAkB,0BAA/B,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,OAA8B;QAC3C,MAAM,uBAAuB,GAAG,IAAA,4CAAuB,EAAC,OAAO,CAAC,CAAC;QACjE,MAAM,qBAAqB,GAAG;YAC5B,OAAO,EAAE,gBAAS;YAClB,QAAQ,EAAE,8BAAa;SACxB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,SAAS,EAAE,CAAC,qBAAqB,EAAE,uBAAuB,CAAC;YAC3D,OAAO,EAAE,CAAC,uBAAuB,CAAC;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAmC;QACrD,MAAM,QAAQ,GAAa;YACzB,MAAM,EAAE,CAAC,4CAAuB,CAAC;YACjC,OAAO,EAAE,mCAAc;YACvB,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAC7C,IAAI,kCAAe,CAAC,OAAO,CAAC;SAC/B,CAAC;QACF,MAAM,qBAAqB,GAAG;YAC5B,OAAO,EAAE,gBAAS;YAClB,QAAQ,EAAE,8BAAa;SACxB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE;gBACT,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;gBACrC,qBAAqB;gBACrB,QAAQ;aACT;YACD,OAAO,EAAE,CAAC,QAAQ,CAAC;SACpB,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,oBAAoB,CACjC,OAAmC;QAEnC,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE;YAC7C,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;SACnD;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAwC,CAAC;QAElE,OAAO;YACL,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YACxC;gBACE,OAAO,EAAE,QAAQ;gBACjB,QAAQ;aACT;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,0BAA0B,CACvC,OAAmC;QAEnC,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,OAAO;gBACL,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;gBAC5B,OAAO,EAAE,4CAAuB;gBAChC,UAAU,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC;SACH;QAED,MAAM,MAAM,GAAG;YACb,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAiC;SAC1E,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,4CAAuB;YAChC,UAAU,EAAE,KAAK,EAAE,cAAsC,EAAE,EAAE,CAC3D,MAAM,cAAc,CAAC,2BAA2B,EAAE;YACpD,MAAM;SACP,CAAC;IACJ,CAAC;CACF,CAAA;AA/EY,kBAAkB;IAF9B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CA+E9B;AA/EY,gDAAkB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createIpFilterProviders = void 0;
|
|
4
|
-
const ipfilter_constants_1 = require("./ipfilter.constants");
|
|
5
|
-
const ipfilter_service_1 = require("./ipfilter.service");
|
|
6
|
-
function createIpFilterProviders(options) {
|
|
7
|
-
return {
|
|
8
|
-
provide: ipfilter_constants_1.IPFILTER_TOKEN,
|
|
9
|
-
useValue: new ipfilter_service_1.IpFilterService(options),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
exports.createIpFilterProviders = createIpFilterProviders;
|
|
13
|
-
//# sourceMappingURL=ipfilter.providers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ipfilter.providers.js","sourceRoot":"","sources":["../lib/ipfilter.providers.ts"],"names":[],"mappings":";;;AAEA,6DAAsD;AACtD,yDAAqD;AAErD,SAAgB,uBAAuB,CACrC,OAA8B;IAE9B,OAAO;QACL,OAAO,EAAE,mCAAc;QACvB,QAAQ,EAAE,IAAI,kCAAe,CAAC,OAAO,CAAC;KACvC,CAAC;AACJ,CAAC;AAPD,0DAOC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Global, Module, Provider, Type } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
IpFilterModuleAsyncOptions,
|
|
4
|
-
IpFilterModuleOptions,
|
|
5
|
-
IpFilterOptionsFactory,
|
|
6
|
-
} from './ipfilter.interface';
|
|
7
|
-
import { IPFILTER_MODULE_OPTIONS, IPFILTER_TOKEN } from './ipfilter.constants';
|
|
8
|
-
import { createIpFilterProviders } from './ipfilter.providers';
|
|
9
|
-
import { IpFilterService } from './ipfilter.service';
|
|
10
|
-
import { APP_GUARD } from '@nestjs/core';
|
|
11
|
-
import { IpFilterGuard } from './ipfilter.guard';
|
|
12
|
-
|
|
13
|
-
@Global()
|
|
14
|
-
@Module({})
|
|
15
|
-
export class IpFilterCoreModule {
|
|
16
|
-
static forRoot(options: IpFilterModuleOptions) {
|
|
17
|
-
const ipFilterServiceProvider = createIpFilterProviders(options);
|
|
18
|
-
const ipFilterGuardProvider = {
|
|
19
|
-
provide: APP_GUARD,
|
|
20
|
-
useClass: IpFilterGuard,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
module: IpFilterCoreModule,
|
|
25
|
-
providers: [ipFilterGuardProvider, ipFilterServiceProvider],
|
|
26
|
-
exports: [ipFilterServiceProvider],
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static forRootAsync(options: IpFilterModuleAsyncOptions) {
|
|
31
|
-
const provider: Provider = {
|
|
32
|
-
inject: [IPFILTER_MODULE_OPTIONS],
|
|
33
|
-
provide: IPFILTER_TOKEN,
|
|
34
|
-
useFactory: (options: IpFilterModuleOptions) =>
|
|
35
|
-
new IpFilterService(options),
|
|
36
|
-
};
|
|
37
|
-
const ipFilterGuardProvider = {
|
|
38
|
-
provide: APP_GUARD,
|
|
39
|
-
useClass: IpFilterGuard,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
module: IpFilterCoreModule,
|
|
44
|
-
imports: options.imports,
|
|
45
|
-
providers: [
|
|
46
|
-
...this.createAsyncProviders(options),
|
|
47
|
-
ipFilterGuardProvider,
|
|
48
|
-
provider,
|
|
49
|
-
],
|
|
50
|
-
exports: [provider],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private static createAsyncProviders(
|
|
55
|
-
options: IpFilterModuleAsyncOptions,
|
|
56
|
-
): Provider[] {
|
|
57
|
-
if (options.useExisting || options.useFactory) {
|
|
58
|
-
return [this.createAsyncOptionsProvider(options)];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const useClass = options.useClass as Type<IpFilterOptionsFactory>;
|
|
62
|
-
|
|
63
|
-
return [
|
|
64
|
-
this.createAsyncOptionsProvider(options),
|
|
65
|
-
{
|
|
66
|
-
provide: useClass,
|
|
67
|
-
useClass,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private static createAsyncOptionsProvider(
|
|
73
|
-
options: IpFilterModuleAsyncOptions,
|
|
74
|
-
): Provider {
|
|
75
|
-
if (options.useFactory) {
|
|
76
|
-
return {
|
|
77
|
-
inject: options.inject || [],
|
|
78
|
-
provide: IPFILTER_MODULE_OPTIONS,
|
|
79
|
-
useFactory: options.useFactory,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const inject = [
|
|
84
|
-
(options.useClass || options.useExisting) as Type<IpFilterOptionsFactory>,
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
provide: IPFILTER_MODULE_OPTIONS,
|
|
89
|
-
useFactory: async (optionsFactory: IpFilterOptionsFactory) =>
|
|
90
|
-
await optionsFactory.createIpFilterModuleOptions(),
|
|
91
|
-
inject,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Provider } from '@nestjs/common';
|
|
2
|
-
import { IpFilterModuleOptions } from './ipfilter.interface';
|
|
3
|
-
import { IPFILTER_TOKEN } from './ipfilter.constants';
|
|
4
|
-
import { IpFilterService } from './ipfilter.service';
|
|
5
|
-
|
|
6
|
-
export function createIpFilterProviders(
|
|
7
|
-
options: IpFilterModuleOptions,
|
|
8
|
-
): Provider {
|
|
9
|
-
return {
|
|
10
|
-
provide: IPFILTER_TOKEN,
|
|
11
|
-
useValue: new IpFilterService(options),
|
|
12
|
-
};
|
|
13
|
-
}
|