nestjs-ip-filter 0.1.1 → 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 +10 -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 +30 -30
- package/renovate.json +10 -0
- 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/README.md
CHANGED
|
@@ -18,6 +18,9 @@ npm install nestjs-ip-filter
|
|
|
18
18
|
|
|
19
19
|
### Use Regex for the IP list
|
|
20
20
|
|
|
21
|
+
> In Express-based framework, the incoming IP address will have prefix `::ffff:` characters. So if you have put `(^192.168.)` into the whitelist, it won't work because that regex describes it must have number `1` as a first character.
|
|
22
|
+
> So for now, you should put that prefix for your regex string like `(^::ffff:192.168.)`. Will patch the source codes in the near future.
|
|
23
|
+
|
|
21
24
|
You can use the Regex format string for the IP ranges.
|
|
22
25
|
|
|
23
26
|
For a simple example, if you want to allow the private network hosts in `192.168.0.1/16`, you can write the Regex string like the below.
|
|
@@ -48,10 +51,10 @@ But be aware of that you should write the Regex string very carefully to avoid a
|
|
|
48
51
|
|
|
49
52
|
You can initialize the dedicated Guard using non-async or async mode, as the other NestJS packages support.
|
|
50
53
|
|
|
51
|
-
Use `
|
|
54
|
+
Use `register` for the static IP address list.
|
|
52
55
|
|
|
53
56
|
```typescript
|
|
54
|
-
IpFilter.
|
|
57
|
+
IpFilter.register({
|
|
55
58
|
whitelist: [
|
|
56
59
|
'(^::1)',
|
|
57
60
|
'(^192.168.)',
|
|
@@ -60,13 +63,13 @@ IpFilter.forRoot({
|
|
|
60
63
|
}),
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
Or, use `
|
|
66
|
+
Or, use `registerAsync` for the provided IP addresses from the other Provider, such as ConfigModule or RepositoryModule for your database.
|
|
64
67
|
|
|
65
68
|
```typescript
|
|
66
69
|
// If it would like to get the whitelist IPs from a config file,
|
|
67
70
|
// and if MyConfigModule provides that
|
|
68
71
|
|
|
69
|
-
IpFilter.
|
|
72
|
+
IpFilter.registerAsync({
|
|
70
73
|
imports: [ MyConfigModule ],
|
|
71
74
|
inject: [ MyConfigService ],
|
|
72
75
|
useFactory: async (myConfigService: MyConfigService) => ({
|
|
@@ -77,7 +80,7 @@ IpFilter.forRootAsync({
|
|
|
77
80
|
|
|
78
81
|
Yeah, you can use your method to provide some async data.
|
|
79
82
|
|
|
80
|
-
After setting up the `IpFilter` module with the `
|
|
83
|
+
After setting up the `IpFilter` module with the `register*` method, this will accept only the incoming requests for the given whitelist IP addresses.
|
|
81
84
|
|
|
82
85
|
### Blacklist
|
|
83
86
|
|
|
@@ -89,7 +92,7 @@ Use `blacklist` option to let the Guard know the list.
|
|
|
89
92
|
// If it would like to get the whitelist IPs from a config file,
|
|
90
93
|
// and if MyConfigModule provides that
|
|
91
94
|
|
|
92
|
-
IpFilter.
|
|
95
|
+
IpFilter.registerAsync({
|
|
93
96
|
imports: [ MyConfigModule ],
|
|
94
97
|
inject: [ MyConfigService ],
|
|
95
98
|
useFactory: async (myConfigService: MyConfigService) => ({
|
|
@@ -111,7 +114,7 @@ If you want to throw that `IpFilterDenyException` when denial, set the option `u
|
|
|
111
114
|
// If it would like to get the whitelist IPs from a config file,
|
|
112
115
|
// and if MyConfigModule provides that
|
|
113
116
|
|
|
114
|
-
IpFilter.
|
|
117
|
+
IpFilter.registerAsync({
|
|
115
118
|
imports: [ MyConfigModule ],
|
|
116
119
|
inject: [ MyConfigService ],
|
|
117
120
|
useFactory: async (myConfigService: MyConfigService) => ({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export * from './ipfilter-core.module';
|
|
2
1
|
export * from './ipfilter-deny.exception';
|
|
3
2
|
export * from './ipfilter.constants';
|
|
4
3
|
export * from './ipfilter.guard';
|
|
5
4
|
export * from './ipfilter.interface';
|
|
6
5
|
export * from './ipfilter.module';
|
|
7
|
-
export * from './ipfilter.
|
|
6
|
+
export * from './ipfilter.module-definition';
|
|
8
7
|
export * from './ipfilter.service';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,12 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./ipfilter-core.module"), exports);
|
|
14
17
|
__exportStar(require("./ipfilter-deny.exception"), exports);
|
|
15
18
|
__exportStar(require("./ipfilter.constants"), exports);
|
|
16
19
|
__exportStar(require("./ipfilter.guard"), exports);
|
|
17
20
|
__exportStar(require("./ipfilter.interface"), exports);
|
|
18
21
|
__exportStar(require("./ipfilter.module"), exports);
|
|
19
|
-
__exportStar(require("./ipfilter.
|
|
22
|
+
__exportStar(require("./ipfilter.module-definition"), exports);
|
|
20
23
|
__exportStar(require("./ipfilter.service"), exports);
|
|
21
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,uDAAqC;AACrC,mDAAiC;AACjC,uDAAqC;AACrC,oDAAkC;AAClC,+DAA6C;AAC7C,qDAAmC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IPFILTER_TOKEN =
|
|
4
|
-
exports.IPFILTER_MODULE_OPTIONS = Symbol('IpFilterModuleOptions');
|
|
3
|
+
exports.IPFILTER_TOKEN = void 0;
|
|
5
4
|
exports.IPFILTER_TOKEN = Symbol('IpFilterToken');
|
|
6
5
|
//# sourceMappingURL=ipfilter.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfilter.constants.js","sourceRoot":"","sources":["../lib/ipfilter.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,
|
|
1
|
+
{"version":3,"file":"ipfilter.constants.js","sourceRoot":"","sources":["../lib/ipfilter.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
1
|
export declare type IpFilterModuleOptions = {
|
|
3
2
|
whitelist?: string[];
|
|
4
3
|
blacklist?: string[];
|
|
@@ -7,12 +6,3 @@ export declare type IpFilterModuleOptions = {
|
|
|
7
6
|
export interface IpFilterDenyHandler {
|
|
8
7
|
handle(): boolean;
|
|
9
8
|
}
|
|
10
|
-
export interface IpFilterOptionsFactory {
|
|
11
|
-
createIpFilterModuleOptions(): Promise<IpFilterModuleOptions> | IpFilterModuleOptions;
|
|
12
|
-
}
|
|
13
|
-
export interface IpFilterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
14
|
-
inject?: any[];
|
|
15
|
-
useClass?: Type<IpFilterOptionsFactory>;
|
|
16
|
-
useExisting?: Type<IpFilterOptionsFactory>;
|
|
17
|
-
useFactory?: (...args: any[]) => Promise<IpFilterModuleOptions> | IpFilterModuleOptions;
|
|
18
|
-
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
_a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
|
|
7
|
+
//# sourceMappingURL=ipfilter.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfilter.module-definition.js","sourceRoot":"","sources":["../lib/ipfilter.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAG9C,KACX,IAAI,kCAAyB,EAAyB,CAAC,KAAK,EAAE,EADjD,+BAAuB,+BAAE,4BAAoB,2BACK"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare class IpFilter {
|
|
4
|
-
static forRoot(options: IpFilterModuleOptions): DynamicModule;
|
|
5
|
-
static forRootAsync(options: IpFilterModuleAsyncOptions): DynamicModule;
|
|
1
|
+
import { ConfigurableModuleClass } from './ipfilter.module-definition';
|
|
2
|
+
export declare class IpFilter extends ConfigurableModuleClass {
|
|
6
3
|
}
|
package/dist/ipfilter.module.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
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
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.IpFilter = void 0;
|
|
4
10
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
const
|
|
6
|
-
(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
const core_1 = require("@nestjs/core");
|
|
12
|
+
const ipfilter_constants_1 = require("./ipfilter.constants");
|
|
13
|
+
const ipfilter_guard_1 = require("./ipfilter.guard");
|
|
14
|
+
const ipfilter_module_definition_1 = require("./ipfilter.module-definition");
|
|
15
|
+
const ipfilter_service_1 = require("./ipfilter.service");
|
|
16
|
+
const ipFilterServiceProvider = {
|
|
17
|
+
provide: ipfilter_constants_1.IPFILTER_TOKEN,
|
|
18
|
+
useClass: ipfilter_service_1.IpFilterService,
|
|
19
|
+
};
|
|
20
|
+
const ipFilterGuardProvider = {
|
|
21
|
+
provide: core_1.APP_GUARD,
|
|
22
|
+
useClass: ipfilter_guard_1.IpFilterGuard,
|
|
23
|
+
};
|
|
24
|
+
let IpFilter = class IpFilter extends ipfilter_module_definition_1.ConfigurableModuleClass {
|
|
25
|
+
};
|
|
26
|
+
IpFilter = __decorate([
|
|
27
|
+
(0, common_1.Module)({
|
|
28
|
+
providers: [ipFilterServiceProvider, ipFilterGuardProvider],
|
|
29
|
+
exports: [ipFilterServiceProvider],
|
|
30
|
+
})
|
|
31
|
+
], IpFilter);
|
|
21
32
|
exports.IpFilter = IpFilter;
|
|
22
33
|
//# sourceMappingURL=ipfilter.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfilter.module.js","sourceRoot":"","sources":["../lib/ipfilter.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ipfilter.module.js","sourceRoot":"","sources":["../lib/ipfilter.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuD;AACvD,uCAAyC;AACzC,6DAAsD;AACtD,qDAAiD;AACjD,6EAAuE;AACvE,yDAAqD;AAErD,MAAM,uBAAuB,GAAG;IAC9B,OAAO,EAAE,mCAAc;IACvB,QAAQ,EAAE,kCAAe;CAC1B,CAAC;AAEF,MAAM,qBAAqB,GAAG;IAC5B,OAAO,EAAE,gBAAS;IAClB,QAAQ,EAAE,8BAAa;CACxB,CAAC;AAMF,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,oDAAuB;CAAG,CAAA;AAA3C,QAAQ;IAJpB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,uBAAuB,EAAE,qBAAqB,CAAC;QAC3D,OAAO,EAAE,CAAC,uBAAuB,CAAC;KACnC,CAAC;GACW,QAAQ,CAAmC;AAA3C,4BAAQ"}
|
package/dist/ipfilter.service.js
CHANGED
|
@@ -14,7 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.IpFilterService = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
-
const
|
|
17
|
+
const ipfilter_module_definition_1 = require("./ipfilter.module-definition");
|
|
18
18
|
let IpFilterService = class IpFilterService {
|
|
19
19
|
constructor(options) {
|
|
20
20
|
var _a, _b, _c;
|
|
@@ -38,7 +38,7 @@ let IpFilterService = class IpFilterService {
|
|
|
38
38
|
};
|
|
39
39
|
IpFilterService = __decorate([
|
|
40
40
|
(0, common_1.Injectable)(),
|
|
41
|
-
__param(0, (0, common_1.Inject)(
|
|
41
|
+
__param(0, (0, common_1.Inject)(ipfilter_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
42
42
|
__metadata("design:paramtypes", [Object])
|
|
43
43
|
], IpFilterService);
|
|
44
44
|
exports.IpFilterService = IpFilterService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfilter.service.js","sourceRoot":"","sources":["../lib/ipfilter.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,
|
|
1
|
+
{"version":3,"file":"ipfilter.service.js","sourceRoot":"","sources":["../lib/ipfilter.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,6EAAoE;AAGpE,IAAa,eAAe,GAA5B,MAAa,eAAe;IAM1B,YAEW,OAA8B;;QAA9B,YAAO,GAAP,OAAO,CAAuB;QAEvC,IAAI,CAAC,gBAAgB,GAAG,MAAA,OAAO,CAAC,gBAAgB,mCAAI,KAAK,CAAC;QAE1D,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,SAAS,CAAC,SAAmB;QAC/B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,IAAI,SAAS,CAAC,SAAmB;QAC/B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;CACF,CAAA;AA/BY,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,iDAAoB,CAAC,CAAA;;GAPpB,eAAe,CA+B3B;AA/BY,0CAAe"}
|