plac-micro-common 1.0.16 → 1.0.19
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/dist/http/{exceptions.filter.js → common/exceptions.filter.js} +1 -1
- package/dist/http/common/index.d.ts +3 -0
- package/dist/http/common/index.js +19 -0
- package/dist/http/common/request_context.interceptor.d.ts +8 -0
- package/dist/http/common/request_context.interceptor.js +83 -0
- package/dist/http/{response.interceptor.js → common/response.interceptor.js} +1 -1
- package/dist/http/decorators/client_ctx.decorator.d.ts +1 -0
- package/dist/http/decorators/client_ctx.decorator.js +20 -0
- package/dist/http/decorators/current_app.decorator.d.ts +1 -0
- package/dist/http/decorators/current_app.decorator.js +8 -0
- package/dist/http/decorators/current_app_client.decorator.d.ts +1 -0
- package/dist/http/decorators/current_app_client.decorator.js +8 -0
- package/dist/http/decorators/index.d.ts +3 -0
- package/dist/http/decorators/index.js +19 -0
- package/dist/http/index.d.ts +3 -2
- package/dist/http/index.js +3 -2
- package/dist/http/service/index.d.ts +1 -0
- package/dist/http/service/index.js +17 -0
- package/dist/http/service/request_context.service.d.ts +6 -0
- package/dist/http/service/request_context.service.js +69 -0
- package/dist/http/types/index.d.ts +21 -0
- package/dist/http/types/index.js +2 -0
- package/package.json +1 -1
- /package/dist/http/{exceptions.filter.d.ts → common/exceptions.filter.d.ts} +0 -0
- /package/dist/http/{response.interceptor.d.ts → common/response.interceptor.d.ts} +0 -0
|
@@ -40,7 +40,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.AllExceptionsFilter = void 0;
|
|
42
42
|
const common_1 = require("@nestjs/common");
|
|
43
|
-
const utils_1 = require("
|
|
43
|
+
const utils_1 = require("../../utils");
|
|
44
44
|
let AllExceptionsFilter = (() => {
|
|
45
45
|
let _classDecorators = [(0, common_1.Catch)()];
|
|
46
46
|
let _classDescriptor;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./exceptions.filter"), exports);
|
|
18
|
+
__exportStar(require("./response.interceptor"), exports);
|
|
19
|
+
__exportStar(require("./request_context.interceptor"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from "@nestjs/common";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { RequestContextService } from "../service";
|
|
4
|
+
export declare class RequestContextInterceptor implements NestInterceptor {
|
|
5
|
+
private readonly rctx;
|
|
6
|
+
constructor(rctx: RequestContextService);
|
|
7
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.RequestContextInterceptor = void 0;
|
|
42
|
+
const common_1 = require("@nestjs/common");
|
|
43
|
+
let RequestContextInterceptor = (() => {
|
|
44
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
var RequestContextInterceptor = _classThis = class {
|
|
49
|
+
constructor(rctx) {
|
|
50
|
+
this.rctx = rctx;
|
|
51
|
+
}
|
|
52
|
+
intercept(context, next) {
|
|
53
|
+
const req = context.switchToHttp().getRequest();
|
|
54
|
+
const xff = req.headers["x-forwarded-for"];
|
|
55
|
+
const ipAddress = (Array.isArray(xff) ? xff[0] : xff?.split(",")[0]) ||
|
|
56
|
+
req.socket?.remoteAddress ||
|
|
57
|
+
req.ip;
|
|
58
|
+
const clientContext = {
|
|
59
|
+
ip_address: ipAddress,
|
|
60
|
+
user_agent: req.headers["user-agent"],
|
|
61
|
+
request_id: req.headers["x-request-id"],
|
|
62
|
+
origin: req.headers["origin"],
|
|
63
|
+
referer: req.headers["referer"],
|
|
64
|
+
};
|
|
65
|
+
this.rctx.set({
|
|
66
|
+
app: req.current_app,
|
|
67
|
+
app_client: req.current_app_client,
|
|
68
|
+
client_context: clientContext,
|
|
69
|
+
});
|
|
70
|
+
return next.handle();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
__setFunctionName(_classThis, "RequestContextInterceptor");
|
|
74
|
+
(() => {
|
|
75
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
76
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
77
|
+
RequestContextInterceptor = _classThis = _classDescriptor.value;
|
|
78
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
79
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
80
|
+
})();
|
|
81
|
+
return RequestContextInterceptor = _classThis;
|
|
82
|
+
})();
|
|
83
|
+
exports.RequestContextInterceptor = RequestContextInterceptor;
|
|
@@ -41,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
41
41
|
exports.ResponseTransformInterceptor = void 0;
|
|
42
42
|
const common_1 = require("@nestjs/common");
|
|
43
43
|
const operators_1 = require("rxjs/operators");
|
|
44
|
-
const utils_1 = require("
|
|
44
|
+
const utils_1 = require("../../utils");
|
|
45
45
|
let ResponseTransformInterceptor = (() => {
|
|
46
46
|
let _classDecorators = [(0, common_1.Injectable)()];
|
|
47
47
|
let _classDescriptor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ClientCtx: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientCtx = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.ClientCtx = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
6
|
+
const req = ctx.switchToHttp().getRequest();
|
|
7
|
+
const x_forwarded_for = req.headers["x-forwarded-for"];
|
|
8
|
+
const ip_address = (Array.isArray(x_forwarded_for)
|
|
9
|
+
? x_forwarded_for[0]
|
|
10
|
+
: x_forwarded_for?.split(",")[0]) ||
|
|
11
|
+
req.socket?.remoteAddress ||
|
|
12
|
+
req.ip;
|
|
13
|
+
return {
|
|
14
|
+
ip_address,
|
|
15
|
+
user_agent: req.headers["user-agent"],
|
|
16
|
+
request_id: req.headers["x-request-id"],
|
|
17
|
+
origin: req.headers["origin"],
|
|
18
|
+
referer: req.headers["referer"],
|
|
19
|
+
};
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CurrentApp: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentApp = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CurrentApp = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
6
|
+
const req = ctx.switchToHttp().getRequest();
|
|
7
|
+
return req.current_app;
|
|
8
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CurrentAppClient: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentAppClient = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CurrentAppClient = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
6
|
+
const req = ctx.switchToHttp().getRequest();
|
|
7
|
+
return req.current_client;
|
|
8
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client_ctx.decorator"), exports);
|
|
18
|
+
__exportStar(require("./current_app.decorator"), exports);
|
|
19
|
+
__exportStar(require("./current_app_client.decorator"), exports);
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./common";
|
|
2
|
+
export * from "./decorators";
|
|
3
|
+
export * from "./types";
|
package/dist/http/index.js
CHANGED
|
@@ -14,5 +14,6 @@ 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("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./request_context.service";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./request_context.service"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.RequestContextService = void 0;
|
|
42
|
+
const common_1 = require("@nestjs/common");
|
|
43
|
+
let RequestContextService = (() => {
|
|
44
|
+
let _classDecorators = [(0, common_1.Injectable)({ scope: common_1.Scope.REQUEST })];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
var RequestContextService = _classThis = class {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.data = {};
|
|
51
|
+
}
|
|
52
|
+
set(partial) {
|
|
53
|
+
this.data = { ...this.data, ...partial };
|
|
54
|
+
}
|
|
55
|
+
get() {
|
|
56
|
+
return this.data;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__setFunctionName(_classThis, "RequestContextService");
|
|
60
|
+
(() => {
|
|
61
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
62
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
63
|
+
RequestContextService = _classThis = _classDescriptor.value;
|
|
64
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
65
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
66
|
+
})();
|
|
67
|
+
return RequestContextService = _classThis;
|
|
68
|
+
})();
|
|
69
|
+
exports.RequestContextService = RequestContextService;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ClientContext {
|
|
2
|
+
ip_address?: string;
|
|
3
|
+
user_agent?: string;
|
|
4
|
+
request_id?: string;
|
|
5
|
+
origin?: string;
|
|
6
|
+
referer?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CurrentAppInfo {
|
|
9
|
+
app_id?: string;
|
|
10
|
+
app_code?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CurrentAppClientInfo {
|
|
13
|
+
app_client_id?: string;
|
|
14
|
+
client_id?: string;
|
|
15
|
+
partner_id?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface RequestContextData {
|
|
18
|
+
app?: CurrentAppInfo;
|
|
19
|
+
app_client?: CurrentAppClientInfo;
|
|
20
|
+
client_context?: ClientContext;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|