@nathapp/nestjs-common 1.0.1-rc.9 → 1.0.1
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 +12 -16
- package/dist/config/index.d.ts +4 -1
- package/dist/config/index.js +7 -1
- package/dist/config/index.js.map +1 -0
- package/dist/config/server-security.config.d.ts +19 -0
- package/dist/config/server-security.config.js +65 -0
- package/dist/config/server-security.config.js.map +1 -0
- package/dist/config/utils/joi-util.js +1 -0
- package/dist/config/utils/joi-util.js.map +1 -0
- package/dist/config/utils/validate-util.d.ts +1 -0
- package/dist/config/utils/validate-util.js +3 -2
- package/dist/config/utils/validate-util.js.map +1 -0
- package/dist/constant/common-constant.d.ts +1 -0
- package/dist/constant/common-constant.js +5 -0
- package/dist/constant/common-constant.js.map +1 -0
- package/dist/constant/index.d.ts +2 -0
- package/dist/constant/index.js +6 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/decorator/client-info.decorator.d.ts +10 -1
- package/dist/decorator/client-info.decorator.js +7 -6
- package/dist/decorator/client-info.decorator.js.map +1 -0
- package/dist/decorator/index.d.ts +2 -2
- package/dist/decorator/index.js +3 -2
- package/dist/decorator/index.js.map +1 -0
- package/dist/decorator/real-ip.decorator.js +3 -2
- package/dist/decorator/real-ip.decorator.js.map +1 -0
- package/dist/exception/app-exception-code.enum.d.ts +3 -1
- package/dist/exception/app-exception-code.enum.js +5 -2
- package/dist/exception/app-exception-code.enum.js.map +1 -0
- package/dist/exception/app-exception.filter.js +3 -2
- package/dist/exception/app-exception.filter.js.map +1 -0
- package/dist/exception/app.exception.js +1 -0
- package/dist/exception/app.exception.js.map +1 -0
- package/dist/exception/default-i18n-validation-exception.filter.d.ts +11 -0
- package/dist/exception/default-i18n-validation-exception.filter.js +43 -0
- package/dist/exception/default-i18n-validation-exception.filter.js.map +1 -0
- package/dist/exception/global-exception.filter.d.ts +12 -0
- package/dist/exception/global-exception.filter.js +49 -5
- package/dist/exception/global-exception.filter.js.map +1 -0
- package/dist/exception/i18n-validation-exception.filter.d.ts +13 -0
- package/dist/exception/i18n-validation-exception.filter.js +88 -0
- package/dist/exception/i18n-validation-exception.filter.js.map +1 -0
- package/dist/exception/index.d.ts +4 -1
- package/dist/exception/index.js +9 -1
- package/dist/exception/index.js.map +1 -0
- package/dist/exception/micro-service.exception.d.ts +6 -0
- package/dist/exception/micro-service.exception.js +16 -0
- package/dist/exception/micro-service.exception.js.map +1 -0
- package/dist/exception/user-not-found.exception.js +1 -0
- package/dist/exception/user-not-found.exception.js.map +1 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.js +3 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/request.d.ts +3 -0
- package/dist/http/request.js +3 -0
- package/dist/http/request.js.map +1 -0
- package/dist/http/response.d.ts +3 -0
- package/dist/http/response.js +3 -0
- package/dist/http/response.js.map +1 -0
- package/dist/i18n/i18n-core.module.js +4 -2
- package/dist/i18n/i18n-core.module.js.map +1 -0
- package/dist/i18n/i18n.constants.js +1 -0
- package/dist/i18n/i18n.constants.js.map +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -0
- package/dist/interceptor/index.d.ts +2 -0
- package/dist/interceptor/index.js +6 -0
- package/dist/interceptor/index.js.map +1 -0
- package/dist/interceptor/serializable.interceptor.d.ts +19 -0
- package/dist/interceptor/serializable.interceptor.js +106 -0
- package/dist/interceptor/serializable.interceptor.js.map +1 -0
- package/dist/ip/index.d.ts +2 -0
- package/dist/ip/index.js +7 -0
- package/dist/ip/index.js.map +1 -0
- package/dist/ip/is.d.ts +17 -0
- package/dist/ip/is.js +37 -0
- package/dist/ip/is.js.map +1 -0
- package/dist/ip/request-ip.d.ts +8 -0
- package/dist/ip/request-ip.js +180 -0
- package/dist/ip/request-ip.js.map +1 -0
- package/dist/logging/empty-logger.d.ts +8 -0
- package/dist/logging/empty-logger.js +12 -0
- package/dist/logging/empty-logger.js.map +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +8 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger-utils.d.ts +2 -0
- package/dist/logging/logger-utils.js +11 -0
- package/dist/logging/logger-utils.js.map +1 -0
- package/dist/middleware/index.d.ts +4 -1
- package/dist/middleware/index.js +12 -1
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/json-body.middleware.js +3 -2
- package/dist/middleware/json-body.middleware.js.map +1 -0
- package/dist/middleware/log.provider.d.ts +34 -0
- package/dist/middleware/log.provider.js +143 -0
- package/dist/middleware/log.provider.js.map +1 -0
- package/dist/middleware/logger-option.factory.d.ts +15 -0
- package/dist/middleware/logger-option.factory.js +63 -0
- package/dist/middleware/logger-option.factory.js.map +1 -0
- package/dist/middleware/logger.middleware.d.ts +8 -0
- package/dist/middleware/logger.middleware.js +92 -0
- package/dist/middleware/logger.middleware.js.map +1 -0
- package/dist/middleware/raw-body.middleware.js +3 -2
- package/dist/middleware/raw-body.middleware.js.map +1 -0
- package/dist/module/configurable-module-cls.interface.d.ts +5 -0
- package/dist/module/configurable-module-cls.interface.js +3 -0
- package/dist/module/configurable-module-cls.interface.js.map +1 -0
- package/dist/module/configurable-module-host.interface.d.ts +5 -0
- package/dist/module/configurable-module-host.interface.js +3 -0
- package/dist/module/configurable-module-host.interface.js.map +1 -0
- package/dist/module/configurable-module.builder.d.ts +26 -0
- package/dist/module/configurable-module.builder.js +191 -0
- package/dist/module/configurable-module.builder.js.map +1 -0
- package/dist/module/index.d.ts +5 -0
- package/dist/module/index.js +10 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/module.interface.d.ts +8 -0
- package/dist/module/module.interface.js +8 -0
- package/dist/module/module.interface.js.map +1 -0
- package/dist/serialize/index.d.ts +4 -2
- package/dist/serialize/index.js +21 -3
- package/dist/serialize/index.js.map +1 -0
- package/dist/serialize/json-response.d.ts +1 -1
- package/dist/serialize/json-response.js +2 -1
- package/dist/serialize/json-response.js.map +1 -0
- package/dist/serialize/localize.string.d.ts +6 -0
- package/dist/serialize/localize.string.js +35 -1
- package/dist/serialize/localize.string.js.map +1 -0
- package/dist/serialize/serializable.d.ts +2 -0
- package/dist/serialize/serializable.js +7 -0
- package/dist/serialize/serializable.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/package-utils.d.ts +2 -0
- package/dist/utils/package-utils.js +18 -0
- package/dist/utils/package-utils.js.map +1 -0
- package/dist/validation/i18n-validation.constraint.d.ts +9 -0
- package/dist/validation/i18n-validation.constraint.js +13 -0
- package/dist/validation/i18n-validation.constraint.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.js +20 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/match.constraint.d.ts +8 -0
- package/dist/validation/match.constraint.js +39 -0
- package/dist/validation/match.constraint.js.map +1 -0
- package/dist/validation/validation.d.ts +28 -0
- package/dist/validation/validation.js +77 -0
- package/dist/validation/validation.js.map +1 -0
- package/index.d.ts +1 -1
- package/index.js +16 -5
- package/package.json +28 -23
- package/.eslintrc.js +0 -24
- package/lib/config/README.md +0 -7
|
@@ -0,0 +1,88 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.I18nValidationExceptionFilter = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const iterare_1 = require("iterare");
|
|
15
|
+
const nestjs_i18n_1 = require("nestjs-i18n");
|
|
16
|
+
const utils_1 = require("nestjs-i18n/dist/utils");
|
|
17
|
+
let I18nValidationExceptionFilter = class I18nValidationExceptionFilter {
|
|
18
|
+
constructor(i18nService, options = {
|
|
19
|
+
detailedErrors: true,
|
|
20
|
+
}) {
|
|
21
|
+
this.i18nService = i18nService;
|
|
22
|
+
this.options = options;
|
|
23
|
+
}
|
|
24
|
+
catch(exception, host) {
|
|
25
|
+
var _a;
|
|
26
|
+
const i18n = nestjs_i18n_1.I18nContext.current();
|
|
27
|
+
const ctx = host.switchToHttp();
|
|
28
|
+
const service = (i18n === null || i18n === void 0 ? void 0 : i18n.service) || this.i18nService;
|
|
29
|
+
const lang = (i18n === null || i18n === void 0 ? void 0 : i18n.lang) || ctx.getRequest().i18nLang;
|
|
30
|
+
const errors = (0, utils_1.formatI18nErrors)((_a = exception.errors) !== null && _a !== void 0 ? _a : [], service, {
|
|
31
|
+
lang,
|
|
32
|
+
});
|
|
33
|
+
const normalizedErrors = this.normalizeValidationErrors(errors);
|
|
34
|
+
switch (host.getType()) {
|
|
35
|
+
case 'http':
|
|
36
|
+
const response = host.switchToHttp().getResponse();
|
|
37
|
+
const responseBody = this.buildResponseBody(host, exception, normalizedErrors);
|
|
38
|
+
response
|
|
39
|
+
.status(this.options.errorHttpStatusCode || exception.getStatus())
|
|
40
|
+
.send(responseBody);
|
|
41
|
+
break;
|
|
42
|
+
case 'graphql':
|
|
43
|
+
exception.errors = normalizedErrors;
|
|
44
|
+
return exception;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
isWithErrorFormatter(options) {
|
|
48
|
+
return 'errorFormatter' in options;
|
|
49
|
+
}
|
|
50
|
+
normalizeValidationErrors(validationErrors) {
|
|
51
|
+
if (this.isWithErrorFormatter(this.options) &&
|
|
52
|
+
!('detailedErrors' in this.options))
|
|
53
|
+
return this.options.errorFormatter(validationErrors);
|
|
54
|
+
if (!this.isWithErrorFormatter(this.options) &&
|
|
55
|
+
!this.options.detailedErrors)
|
|
56
|
+
return this.flattenValidationErrors(validationErrors);
|
|
57
|
+
return validationErrors;
|
|
58
|
+
}
|
|
59
|
+
flattenValidationErrors(validationErrors) {
|
|
60
|
+
return (0, iterare_1.default)(validationErrors)
|
|
61
|
+
.map((error) => (0, utils_1.mapChildrenToValidationErrors)(error))
|
|
62
|
+
.flatten()
|
|
63
|
+
.filter((item) => !!item.constraints)
|
|
64
|
+
.map((item) => Object.values(item.constraints))
|
|
65
|
+
.flatten()
|
|
66
|
+
.toArray();
|
|
67
|
+
}
|
|
68
|
+
buildResponseBody(host, exc, errors) {
|
|
69
|
+
if ('responseBodyFormatter' in this.options) {
|
|
70
|
+
return this.options.responseBodyFormatter(host, exc, errors);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return {
|
|
74
|
+
statusCode: this.options.errorHttpStatusCode === undefined
|
|
75
|
+
? exc.getStatus()
|
|
76
|
+
: this.options.errorHttpStatusCode,
|
|
77
|
+
message: exc.getResponse(),
|
|
78
|
+
errors,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.I18nValidationExceptionFilter = I18nValidationExceptionFilter;
|
|
84
|
+
exports.I18nValidationExceptionFilter = I18nValidationExceptionFilter = __decorate([
|
|
85
|
+
(0, common_1.Catch)(nestjs_i18n_1.I18nValidationException),
|
|
86
|
+
__metadata("design:paramtypes", [nestjs_i18n_1.I18nService, Object])
|
|
87
|
+
], I18nValidationExceptionFilter);
|
|
88
|
+
//# sourceMappingURL=i18n-validation-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-validation-exception.filter.js","sourceRoot":"","sources":["../../lib/exception/i18n-validation-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,qCAA8B;AAC9B,6CAA2M;AAC3M,kDAAyF;AAOlF,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACxC,YACmB,WAAwB,EACxB,UAAgD;QAC/D,cAAc,EAAE,IAAI;KACrB;QAHgB,gBAAW,GAAX,WAAW,CAAa;QACxB,YAAO,GAAP,OAAO,CAEvB;IACA,CAAC;IACJ,KAAK,CAAC,SAAkC,EAAE,IAAmB;;QAC3D,MAAM,IAAI,GAAG,yBAAW,CAAC,OAAO,EAAE,CAAC;QAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,KAAI,IAAI,CAAC,WAAW,CAAC;QAClD,MAAM,IAAI,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,KAAI,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC;QAErD,MAAM,MAAM,GAAG,IAAA,wBAAgB,EAAC,MAAA,SAAS,CAAC,MAAM,mCAAI,EAAE,EAAE,OAAO,EAAE;YAC/D,IAAI;SACL,CAAC,CAAC;QAEH,MAAM,gBAAgB,GAAG,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;QAEhE,QAAQ,IAAI,CAAC,OAAO,EAAY,EAAE,CAAC;YACjC,KAAK,MAAM;gBACT,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC;gBACnD,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CACzC,IAAI,EACJ,SAAS,EACT,gBAAgB,CACjB,CAAC;gBACF,QAAQ;qBACL,MAAM,CAAC,I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,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,UAAU,EACR,IAAI,CAAC,OAAO,CAAC,mBAAmB,KAAK,SAAS;oBAC5C,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE;oBACjB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB;gBACtC,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE;gBAC1B,MAAM;aACP,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AA3FY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,cAAK,EAAC,qCAAuB,CAAC;qCAGG,yBAAW;GAFhC,6BAA6B,CA2FzC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CommonExceptionCode } from "./app-exception-code.enum";
|
|
2
2
|
import { AppExceptionFilter } from "./app-exception.filter";
|
|
3
3
|
import { AppException } from "./app.exception";
|
|
4
|
+
import { DefaultI18nValidationExceptionFilter, defaultResponseFormatter } from "./default-i18n-validation-exception.filter";
|
|
4
5
|
import { GlobalExceptionsFilter } from "./global-exception.filter";
|
|
6
|
+
import { I18nValidationExceptionFilter, I18nValidationExceptionFilterOptions } from "./i18n-validation-exception.filter";
|
|
7
|
+
import { HttpMicroServiceException } from "./micro-service.exception";
|
|
5
8
|
import { UsernameNotFoundException } from "./user-not-found.exception";
|
|
6
|
-
export { AppException, AppExceptionFilter, GlobalExceptionsFilter, UsernameNotFoundException, CommonExceptionCode };
|
|
9
|
+
export { AppException, AppExceptionFilter, GlobalExceptionsFilter, UsernameNotFoundException, CommonExceptionCode, HttpMicroServiceException, defaultResponseFormatter, DefaultI18nValidationExceptionFilter, I18nValidationExceptionFilterOptions, I18nValidationExceptionFilter };
|
package/dist/exception/index.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommonExceptionCode = exports.UsernameNotFoundException = exports.GlobalExceptionsFilter = exports.AppExceptionFilter = exports.AppException = void 0;
|
|
3
|
+
exports.I18nValidationExceptionFilter = exports.DefaultI18nValidationExceptionFilter = exports.defaultResponseFormatter = exports.HttpMicroServiceException = exports.CommonExceptionCode = exports.UsernameNotFoundException = exports.GlobalExceptionsFilter = exports.AppExceptionFilter = exports.AppException = void 0;
|
|
4
4
|
const app_exception_code_enum_1 = require("./app-exception-code.enum");
|
|
5
5
|
Object.defineProperty(exports, "CommonExceptionCode", { enumerable: true, get: function () { return app_exception_code_enum_1.CommonExceptionCode; } });
|
|
6
6
|
const app_exception_filter_1 = require("./app-exception.filter");
|
|
7
7
|
Object.defineProperty(exports, "AppExceptionFilter", { enumerable: true, get: function () { return app_exception_filter_1.AppExceptionFilter; } });
|
|
8
8
|
const app_exception_1 = require("./app.exception");
|
|
9
9
|
Object.defineProperty(exports, "AppException", { enumerable: true, get: function () { return app_exception_1.AppException; } });
|
|
10
|
+
const default_i18n_validation_exception_filter_1 = require("./default-i18n-validation-exception.filter");
|
|
11
|
+
Object.defineProperty(exports, "DefaultI18nValidationExceptionFilter", { enumerable: true, get: function () { return default_i18n_validation_exception_filter_1.DefaultI18nValidationExceptionFilter; } });
|
|
12
|
+
Object.defineProperty(exports, "defaultResponseFormatter", { enumerable: true, get: function () { return default_i18n_validation_exception_filter_1.defaultResponseFormatter; } });
|
|
10
13
|
const global_exception_filter_1 = require("./global-exception.filter");
|
|
11
14
|
Object.defineProperty(exports, "GlobalExceptionsFilter", { enumerable: true, get: function () { return global_exception_filter_1.GlobalExceptionsFilter; } });
|
|
15
|
+
const i18n_validation_exception_filter_1 = require("./i18n-validation-exception.filter");
|
|
16
|
+
Object.defineProperty(exports, "I18nValidationExceptionFilter", { enumerable: true, get: function () { return i18n_validation_exception_filter_1.I18nValidationExceptionFilter; } });
|
|
17
|
+
const micro_service_exception_1 = require("./micro-service.exception");
|
|
18
|
+
Object.defineProperty(exports, "HttpMicroServiceException", { enumerable: true, get: function () { return micro_service_exception_1.HttpMicroServiceException; } });
|
|
12
19
|
const user_not_found_exception_1 = require("./user-not-found.exception");
|
|
13
20
|
Object.defineProperty(exports, "UsernameNotFoundException", { enumerable: true, get: function () { return user_not_found_exception_1.UsernameNotFoundException; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/exception/index.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAS8B,oGATrF,6CAAmB,OASqF;AARjH,iEAA4D;AAQrC,mGARd,yCAAkB,OAQc;AAPzC,mDAA+C;AAOtC,6FAPA,4BAAY,OAOA;AANrB,yGAA4H;AAO1H,qHAPO,+EAAoC,OAOP;AADwG,yGAN/F,mEAAwB,OAM+F;AALtK,uEAAmE;AAKxB,uGALlC,gDAAsB,OAKkC;AAJjE,yFAAyH;AAK3C,8GALrE,gEAA6B,OAKqE;AAJ3G,uEAAsE;AAG6C,0GAH1G,mDAAyB,OAG0G;AAF5I,yEAAuE;AAEJ,0GAF1D,oDAAyB,OAE0D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMicroServiceException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class HttpMicroServiceException extends common_1.HttpException {
|
|
6
|
+
constructor(ret, message) {
|
|
7
|
+
super({ ret, message }, 200);
|
|
8
|
+
this._ret = ret;
|
|
9
|
+
this.message = message;
|
|
10
|
+
}
|
|
11
|
+
get ret() {
|
|
12
|
+
return this._ret;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.HttpMicroServiceException = HttpMicroServiceException;
|
|
16
|
+
//# sourceMappingURL=micro-service.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"micro-service.exception.js","sourceRoot":"","sources":["../../lib/exception/micro-service.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAE/C,MAAa,yBAA0B,SAAQ,sBAAa;IAG1D,YAAY,GAAW,EAAE,OAAe;QACtC,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AAZD,8DAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-not-found.exception.js","sourceRoot":"","sources":["../../lib/exception/user-not-found.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAE/C,MAAa,yBAA0B,SAAQ,sBAAa;IAC1D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAJD,8DAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/http/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../lib/http/request.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../lib/http/response.ts"],"names":[],"mappings":""}
|
|
@@ -37,10 +37,10 @@ let I18nCoreModule = I18nCoreModule_1 = class I18nCoreModule {
|
|
|
37
37
|
return options;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
I18nCoreModule =
|
|
40
|
+
exports.I18nCoreModule = I18nCoreModule;
|
|
41
|
+
exports.I18nCoreModule = I18nCoreModule = I18nCoreModule_1 = __decorate([
|
|
41
42
|
(0, common_1.Module)({})
|
|
42
43
|
], I18nCoreModule);
|
|
43
|
-
exports.I18nCoreModule = I18nCoreModule;
|
|
44
44
|
const defaultResolvers = [
|
|
45
45
|
{
|
|
46
46
|
use: nestjs_i18n_1.QueryResolver,
|
|
@@ -49,6 +49,7 @@ const defaultResolvers = [
|
|
|
49
49
|
new nestjs_i18n_1.HeaderResolver(["lang"]),
|
|
50
50
|
nestjs_i18n_1.AcceptLanguageResolver,
|
|
51
51
|
new nestjs_i18n_1.CookieResolver(["lang"]),
|
|
52
|
+
new nestjs_i18n_1.GrpcMetadataResolver(["lang"]),
|
|
52
53
|
];
|
|
53
54
|
const defaultLoader = nestjs_i18n_1.I18nJsonLoader;
|
|
54
55
|
const defaultPath = process.env.NODE_ENV == "development" ? "src/i18n/" : "dist/i18n/";
|
|
@@ -74,3 +75,4 @@ const defaultAsyncOptions = {
|
|
|
74
75
|
};
|
|
75
76
|
},
|
|
76
77
|
};
|
|
78
|
+
//# sourceMappingURL=i18n-core.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-core.module.js","sourceRoot":"","sources":["../../lib/i18n/i18n-core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,6CAUqB;AACrB,+BAA4B;AAOrB,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,OAAqB;QAClC,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,OAAO,EAAE,CAAC,wBAAU,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;YAChE,OAAO,EAAE,CAAC,wBAAU,CAAC;SACtB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAA0B;QAC5C,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,OAAO,EAAE;gBACP,wBAAU,CAAC,YAAY,CA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AAC,GAAG,CAAC,mBAAmB,IAAI,MAAM;KACjD;CACF,CAAC;AAEF,MAAM,mBAAmB,GAA8B;IACrD,SAAS,EAAE,gBAAgB;IAC3B,MAAM,EAAE,aAAa;IACrB,UAAU,EAAE,GAAG,EAAE;QACf,OAAO;YACL,gBAAgB,EAAE,cAAc,CAAC,gBAAgB;YACjD,aAAa,EAAE;gBACb,IAAI,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,WAAW,CAAC;gBACtE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,MAAM;aACjD;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=i18n.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.constants.js","sourceRoot":"","sources":["../../lib/i18n/i18n.constants.ts"],"names":[],"mappings":""}
|
package/dist/i18n/index.js
CHANGED
|
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.I18nCoreModule = void 0;
|
|
4
4
|
const i18n_core_module_1 = require("./i18n-core.module");
|
|
5
5
|
Object.defineProperty(exports, "I18nCoreModule", { enumerable: true, get: function () { return i18n_core_module_1.I18nCoreModule; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/i18n/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAE3C,+FAFA,iCAAc,OAEA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
export * from "./config";
|
|
2
|
+
export * from "./constant";
|
|
1
3
|
export * from "./decorator";
|
|
2
4
|
export * from "./exception";
|
|
5
|
+
export * from "./http";
|
|
3
6
|
export * from "./i18n";
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
7
|
+
export * from "./interceptor";
|
|
8
|
+
export * from "./ip";
|
|
9
|
+
export * from "./logging";
|
|
6
10
|
export * from "./middleware";
|
|
11
|
+
export * from "./module";
|
|
12
|
+
export * from "./serialize";
|
|
13
|
+
export * from "./utils";
|
|
14
|
+
export * from "./validation";
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config"), exports);
|
|
18
|
+
__exportStar(require("./constant"), exports);
|
|
17
19
|
__exportStar(require("./decorator"), exports);
|
|
18
20
|
__exportStar(require("./exception"), exports);
|
|
21
|
+
__exportStar(require("./http"), exports);
|
|
19
22
|
__exportStar(require("./i18n"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
21
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./interceptor"), exports);
|
|
24
|
+
__exportStar(require("./ip"), exports);
|
|
25
|
+
__exportStar(require("./logging"), exports);
|
|
22
26
|
__exportStar(require("./middleware"), exports);
|
|
27
|
+
__exportStar(require("./module"), exports);
|
|
28
|
+
__exportStar(require("./serialize"), exports);
|
|
29
|
+
__exportStar(require("./utils"), exports);
|
|
30
|
+
__exportStar(require("./validation"), exports);
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B;AAC5B,yCAAuB;AACvB,yCAAuB;AACvB,gDAA8B;AAC9B,uCAAqB;AACrB,4CAA0B;AAC1B,+CAA6B;AAC7B,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,+CAA6B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializableInterceptor = void 0;
|
|
4
|
+
const serializable_interceptor_1 = require("./serializable.interceptor");
|
|
5
|
+
Object.defineProperty(exports, "SerializableInterceptor", { enumerable: true, get: function () { return serializable_interceptor_1.SerializableInterceptor; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interceptor/index.ts"],"names":[],"mappings":";;;AAAA,yEAAqE;AAGnE,wGAHO,kDAAuB,OAGP"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CallHandler, ClassSerializerInterceptor, ClassSerializerInterceptorOptions, ExecutionContext, PlainLiteralObject, StreamableFile } from "@nestjs/common";
|
|
2
|
+
import { ClassTransformOptions } from "class-transformer";
|
|
3
|
+
import { Observable } from "rxjs";
|
|
4
|
+
import { LocaleObject, LocaleString } from "../serialize";
|
|
5
|
+
export declare class SerializableInterceptor extends ClassSerializerInterceptor {
|
|
6
|
+
protected readonly reflector: any;
|
|
7
|
+
protected readonly defaultOptions: ClassSerializerInterceptorOptions;
|
|
8
|
+
private fallbackLanguage;
|
|
9
|
+
constructor(reflector: any, defaultOptions?: ClassSerializerInterceptorOptions);
|
|
10
|
+
intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any>;
|
|
11
|
+
customSerialize(response: PlainLiteralObject | Array<PlainLiteralObject>, options: ClassTransformOptions, lang: string): PlainLiteralObject | PlainLiteralObject[] | StreamableFile;
|
|
12
|
+
serializeObject(obj: PlainLiteralObject, options: ClassTransformOptions, lang: string): PlainLiteralObject;
|
|
13
|
+
transformObject(obj: PlainLiteralObject, lang: string): PlainLiteralObject;
|
|
14
|
+
transformLocaleString(obj: LocaleString, lang: string): string;
|
|
15
|
+
transformLocaleObject(obj: LocaleObject, lang: string): "" | PlainLiteralObject;
|
|
16
|
+
isObject: (fn: any) => fn is object;
|
|
17
|
+
isNil: (val: any) => val is null | undefined;
|
|
18
|
+
isUndefined: (obj: any) => obj is undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SerializableInterceptor = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const class_transformer_1 = require("class-transformer");
|
|
18
|
+
const rxjs_1 = require("rxjs");
|
|
19
|
+
const serialize_1 = require("../serialize");
|
|
20
|
+
const constant_1 = require("../constant");
|
|
21
|
+
let SerializableInterceptor = class SerializableInterceptor extends common_1.ClassSerializerInterceptor {
|
|
22
|
+
constructor(reflector, defaultOptions = {}) {
|
|
23
|
+
super(reflector, defaultOptions);
|
|
24
|
+
this.reflector = reflector;
|
|
25
|
+
this.defaultOptions = defaultOptions;
|
|
26
|
+
this.fallbackLanguage = 'en_US';
|
|
27
|
+
this.isObject = (fn) => !this.isNil(fn) && typeof fn === 'object';
|
|
28
|
+
this.isNil = (val) => this.isUndefined(val) || val === null;
|
|
29
|
+
this.isUndefined = (obj) => typeof obj === 'undefined';
|
|
30
|
+
}
|
|
31
|
+
intercept(context, next) {
|
|
32
|
+
const ctx = context.switchToHttp();
|
|
33
|
+
const lang = ctx.getRequest().i18nLang;
|
|
34
|
+
const contextOptions = this.getContextOptions(context);
|
|
35
|
+
const options = {
|
|
36
|
+
...this.defaultOptions,
|
|
37
|
+
...contextOptions,
|
|
38
|
+
};
|
|
39
|
+
return next
|
|
40
|
+
.handle()
|
|
41
|
+
.pipe((0, rxjs_1.map)((res) => this.customSerialize(res, options, lang)));
|
|
42
|
+
}
|
|
43
|
+
customSerialize(response, options, lang) {
|
|
44
|
+
if (!this.isObject(response) || response instanceof common_1.StreamableFile) {
|
|
45
|
+
return response;
|
|
46
|
+
}
|
|
47
|
+
return Array.isArray(response)
|
|
48
|
+
? response.map((item) => this.serializeObject(item, options, lang))
|
|
49
|
+
: this.serializeObject(response, options, lang);
|
|
50
|
+
}
|
|
51
|
+
serializeObject(obj, options, lang) {
|
|
52
|
+
const data = obj instanceof serialize_1.Serializable ? (0, class_transformer_1.instanceToInstance)(obj, options) : obj;
|
|
53
|
+
return this.transformToPlain(this.transformObject(data, lang), options);
|
|
54
|
+
}
|
|
55
|
+
transformObject(obj, lang) {
|
|
56
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
57
|
+
if (this.isObject(value)) {
|
|
58
|
+
if (value instanceof serialize_1.LocaleString) {
|
|
59
|
+
obj[key] = this.transformLocaleString(value, lang);
|
|
60
|
+
}
|
|
61
|
+
else if (value instanceof serialize_1.LocaleObject) {
|
|
62
|
+
const result = this.transformLocaleObject(value, lang);
|
|
63
|
+
if (result) {
|
|
64
|
+
obj[key] = result;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
delete obj[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
obj[key] = this.transformObject(value, lang);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (Array.isArray(obj)) {
|
|
75
|
+
obj[key] = value.map((item) => this.transformObject(item, lang));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
transformLocaleString(obj, lang) {
|
|
81
|
+
if (!obj)
|
|
82
|
+
return "";
|
|
83
|
+
if (obj[lang])
|
|
84
|
+
return obj[lang];
|
|
85
|
+
if (obj[this.fallbackLanguage])
|
|
86
|
+
return obj[this.fallbackLanguage];
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
transformLocaleObject(obj, lang) {
|
|
90
|
+
if (!obj)
|
|
91
|
+
return '';
|
|
92
|
+
let value = obj[lang];
|
|
93
|
+
if (!value) {
|
|
94
|
+
value = obj[this.fallbackLanguage];
|
|
95
|
+
}
|
|
96
|
+
return value ? this.transformObject(value, lang) : undefined;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.SerializableInterceptor = SerializableInterceptor;
|
|
100
|
+
exports.SerializableInterceptor = SerializableInterceptor = __decorate([
|
|
101
|
+
(0, common_1.Injectable)(),
|
|
102
|
+
__param(0, (0, common_1.Inject)(constant_1.REFLECTOR)),
|
|
103
|
+
__param(1, (0, common_1.Optional)()),
|
|
104
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
105
|
+
], SerializableInterceptor);
|
|
106
|
+
//# sourceMappingURL=serializable.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializable.interceptor.js","sourceRoot":"","sources":["../../lib/interceptor/serializable.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgM;AAChM,yDAA8E;AAC9E,+BAAuC;AACvC,4CAAwE;AACxE,0CAAwC;AAIjC,IAAM,uB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,EAAC,oBAAS,CAAC,CAAA;IACjB,WAAA,IAAA,iBAAQ,GAAE,CAAA;;GALF,uBAAuB,CA6FnC"}
|
package/dist/ip/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestIpMiddleware = exports.getClientIp = void 0;
|
|
4
|
+
const request_ip_1 = require("./request-ip");
|
|
5
|
+
Object.defineProperty(exports, "getClientIp", { enumerable: true, get: function () { return request_ip_1.getClientIp; } });
|
|
6
|
+
Object.defineProperty(exports, "RequestIpMiddleware", { enumerable: true, get: function () { return request_ip_1.mw; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/ip/index.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAG7C,4FAHO,wBAAW,OAGP;AACL,oGAJc,eAAE,OAIG"}
|
package/dist/ip/is.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function existy(value: any): boolean;
|
|
2
|
+
declare function ip(value: any): boolean;
|
|
3
|
+
declare function object(value: any): boolean;
|
|
4
|
+
declare function string(value: any): boolean;
|
|
5
|
+
declare const is: {
|
|
6
|
+
existy: typeof existy;
|
|
7
|
+
ip: typeof ip;
|
|
8
|
+
object: typeof object;
|
|
9
|
+
string: typeof string;
|
|
10
|
+
not: {
|
|
11
|
+
existy: (...args: any[]) => boolean;
|
|
12
|
+
ip: (...args: any[]) => boolean;
|
|
13
|
+
object: (...args: any[]) => boolean;
|
|
14
|
+
string: (...args: any[]) => boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default is;
|
package/dist/ip/is.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const regexes = {
|
|
4
|
+
ipv4: /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/,
|
|
5
|
+
ipv6: /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i,
|
|
6
|
+
};
|
|
7
|
+
function not(func) {
|
|
8
|
+
return function (...args) {
|
|
9
|
+
return !func.apply(null, Array.prototype.slice.call(args));
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function existy(value) {
|
|
13
|
+
return value != null;
|
|
14
|
+
}
|
|
15
|
+
function ip(value) {
|
|
16
|
+
return ((existy(value) && regexes.ipv4.test(value)) || regexes.ipv6.test(value));
|
|
17
|
+
}
|
|
18
|
+
function object(value) {
|
|
19
|
+
return Object(value) === value;
|
|
20
|
+
}
|
|
21
|
+
function string(value) {
|
|
22
|
+
return Object.prototype.toString.call(value) === '[object String]';
|
|
23
|
+
}
|
|
24
|
+
const is = {
|
|
25
|
+
existy: existy,
|
|
26
|
+
ip: ip,
|
|
27
|
+
object: object,
|
|
28
|
+
string: string,
|
|
29
|
+
not: {
|
|
30
|
+
existy: not(existy),
|
|
31
|
+
ip: not(ip),
|
|
32
|
+
object: not(object),
|
|
33
|
+
string: not(string),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
exports.default = is;
|
|
37
|
+
//# sourceMappingURL=is.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is.js","sourceRoot":"","sources":["../../lib/ip/is.ts"],"names":[],"mappings":";;AAIA,MAAM,OAAO,GAAG;IACd,IAAI,EAAE,yFAAyF;IAC/F,IAAI,EAAE,oKAAoK;CAC3K,CAAC;AAOF,SAAS,GAAG,CAAC,IAAc;IACzB,OAAO,UAAU,GAAG,IAAW;QAC7B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC;AAOD,SAAS,MAAM,CAAC,KAAU;IACxB,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC;AAOD,SAAS,EAAE,CAAC,KAAU;IACpB,OAAO,CACL,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CACxE,CAAC;AACJ,CAAC;AAOD,SAAS,MAAM,CAAC,KAAU;IACxB,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AACjC,CAAC;AAOD,SAAS,MAAM,CAAC,KAAU;IACxB,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AACrE,CAAC;AAED,MAAM,EAAE,GAAG;IACT,MAAM,EAAE,MAAM;IACd,EAAE,EAAE,EAAE;IACN,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,GAAG,EAAE;QACH,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;QACX,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;KACpB;CACF,CAAC;AAEF,kBAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function getClientIpFromXForwardedFor(value: string): string | null;
|
|
2
|
+
declare function getClientIpByHeader(req: any, header: string): string | undefined | null;
|
|
3
|
+
declare function getClientIp(req: any): string;
|
|
4
|
+
declare function mw(options: {
|
|
5
|
+
attributeName?: string;
|
|
6
|
+
prioritize?: string[];
|
|
7
|
+
}): any;
|
|
8
|
+
export { getClientIpFromXForwardedFor, getClientIpByHeader, getClientIp, mw, };
|