@easydocs/nestjs 0.4.2 → 0.5.2
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 +18 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -28,11 +28,26 @@ That's it. A global interceptor is automatically registered. Every controller re
|
|
|
28
28
|
|
|
29
29
|
## Per-controller or per-route
|
|
30
30
|
|
|
31
|
+
`EasyDocsInterceptor` requires the `EASYDOCS_CAPTURER` DI token to be provided. The easiest way is to still import `EasyDocsModule.forRoot()` globally (which registers the token), then apply the interceptor manually on specific controllers instead of relying on the global one.
|
|
32
|
+
|
|
33
|
+
If you want full control without `forRoot()`, provide the token yourself:
|
|
34
|
+
|
|
31
35
|
```ts
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
36
|
+
import { Module } from '@nestjs/common'
|
|
37
|
+
import { UseInterceptors, Controller } from '@nestjs/common'
|
|
38
|
+
import { EasyDocsInterceptor, EASYDOCS_CAPTURER } from '@easydocs/nestjs'
|
|
39
|
+
import { createCapturer, parseConfig } from '@easydocs/core'
|
|
40
|
+
|
|
41
|
+
@Module({
|
|
42
|
+
providers: [
|
|
43
|
+
{
|
|
44
|
+
provide: EASYDOCS_CAPTURER,
|
|
45
|
+
useValue: createCapturer(parseConfig({ project: 'my-api' })),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
export class UsersModule {}
|
|
34
50
|
|
|
35
|
-
// Skip the forRoot() import and use selectively:
|
|
36
51
|
@UseInterceptors(EasyDocsInterceptor)
|
|
37
52
|
@Controller('users')
|
|
38
53
|
export class UsersController {}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
-
import { EasyDocsConfig } from '@easydocs/core';
|
|
2
|
+
import { EasyDocsConfig, Capturer } from '@easydocs/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
|
|
5
5
|
declare class EasyDocsModule {
|
|
6
6
|
static forRoot(config?: EasyDocsConfig): DynamicModule;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
declare const
|
|
9
|
+
declare const EASYDOCS_CAPTURER: unique symbol;
|
|
10
10
|
declare class EasyDocsInterceptor implements NestInterceptor {
|
|
11
|
-
private readonly
|
|
12
|
-
constructor(
|
|
11
|
+
private readonly capturer;
|
|
12
|
+
constructor(capturer: Capturer);
|
|
13
13
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export {
|
|
16
|
+
export { EASYDOCS_CAPTURER, EasyDocsInterceptor, EasyDocsModule };
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23
23
|
// src/index.ts
|
|
24
24
|
var index_exports = {};
|
|
25
25
|
__export(index_exports, {
|
|
26
|
-
|
|
26
|
+
EASYDOCS_CAPTURER: () => EASYDOCS_CAPTURER,
|
|
27
27
|
EasyDocsInterceptor: () => EasyDocsInterceptor,
|
|
28
28
|
EasyDocsModule: () => EasyDocsModule
|
|
29
29
|
});
|
|
@@ -54,11 +54,11 @@ function _ts_param(paramIndex, decorator) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
__name(_ts_param, "_ts_param");
|
|
57
|
-
var
|
|
57
|
+
var EASYDOCS_CAPTURER = /* @__PURE__ */ Symbol("EASYDOCS_CAPTURER");
|
|
58
58
|
var _EasyDocsInterceptor = class _EasyDocsInterceptor {
|
|
59
|
-
constructor(
|
|
60
|
-
__publicField(this, "
|
|
61
|
-
this.
|
|
59
|
+
constructor(capturer) {
|
|
60
|
+
__publicField(this, "capturer");
|
|
61
|
+
this.capturer = capturer;
|
|
62
62
|
}
|
|
63
63
|
intercept(context, next) {
|
|
64
64
|
const startedAt = Date.now();
|
|
@@ -66,19 +66,18 @@ var _EasyDocsInterceptor = class _EasyDocsInterceptor {
|
|
|
66
66
|
const req = http.getRequest();
|
|
67
67
|
const res = http.getResponse();
|
|
68
68
|
return next.handle().pipe((0, import_rxjs.tap)((responseBody) => {
|
|
69
|
-
|
|
70
|
-
(0, import_core.capture)({
|
|
69
|
+
this.capturer.capture((0, import_core.buildCaptureEvent)({
|
|
71
70
|
method: req.method,
|
|
72
|
-
path:
|
|
71
|
+
path: req.route?.path ?? req.path,
|
|
73
72
|
query: req.query,
|
|
74
73
|
params: req.params,
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
requestBody: req.body,
|
|
75
|
+
responseBody,
|
|
77
76
|
status: res.statusCode,
|
|
78
77
|
requestHeaders: req.headers,
|
|
79
78
|
responseHeaders: res.getHeaders(),
|
|
80
79
|
durationMs: Date.now() - startedAt
|
|
81
|
-
}
|
|
80
|
+
}));
|
|
82
81
|
}));
|
|
83
82
|
}
|
|
84
83
|
};
|
|
@@ -86,14 +85,15 @@ __name(_EasyDocsInterceptor, "EasyDocsInterceptor");
|
|
|
86
85
|
var EasyDocsInterceptor = _EasyDocsInterceptor;
|
|
87
86
|
EasyDocsInterceptor = _ts_decorate([
|
|
88
87
|
(0, import_common.Injectable)(),
|
|
89
|
-
_ts_param(0, (0, import_common.Inject)(
|
|
88
|
+
_ts_param(0, (0, import_common.Inject)(EASYDOCS_CAPTURER)),
|
|
90
89
|
_ts_metadata("design:type", Function),
|
|
91
90
|
_ts_metadata("design:paramtypes", [
|
|
92
|
-
typeof
|
|
91
|
+
typeof Capturer === "undefined" ? Object : Capturer
|
|
93
92
|
])
|
|
94
93
|
], EasyDocsInterceptor);
|
|
95
94
|
|
|
96
95
|
// src/module.ts
|
|
96
|
+
var import_core3 = require("@easydocs/core");
|
|
97
97
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
98
98
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
99
99
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -103,13 +103,14 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
103
103
|
__name(_ts_decorate2, "_ts_decorate");
|
|
104
104
|
var _EasyDocsModule = class _EasyDocsModule {
|
|
105
105
|
static forRoot(config = {}) {
|
|
106
|
+
const capturer = (0, import_core3.createCapturer)((0, import_core3.parseConfig)(config));
|
|
106
107
|
return {
|
|
107
108
|
module: _EasyDocsModule,
|
|
108
109
|
global: true,
|
|
109
110
|
providers: [
|
|
110
111
|
{
|
|
111
|
-
provide:
|
|
112
|
-
useValue:
|
|
112
|
+
provide: EASYDOCS_CAPTURER,
|
|
113
|
+
useValue: capturer
|
|
113
114
|
},
|
|
114
115
|
{
|
|
115
116
|
provide: import_core2.APP_INTERCEPTOR,
|
|
@@ -126,7 +127,7 @@ EasyDocsModule = _ts_decorate2([
|
|
|
126
127
|
], EasyDocsModule);
|
|
127
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
129
|
0 && (module.exports = {
|
|
129
|
-
|
|
130
|
+
EASYDOCS_CAPTURER,
|
|
130
131
|
EasyDocsInterceptor,
|
|
131
132
|
EasyDocsModule
|
|
132
133
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/module.ts","../src/interceptor.ts"],"sourcesContent":["export { EasyDocsModule } from './module'\nexport { EasyDocsInterceptor,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/module.ts","../src/interceptor.ts"],"sourcesContent":["export { EasyDocsModule } from './module'\nexport { EasyDocsInterceptor, EASYDOCS_CAPTURER } from './interceptor'\n","import { Module, DynamicModule } from '@nestjs/common'\nimport { APP_INTERCEPTOR } from '@nestjs/core'\nimport { EasyDocsInterceptor, EASYDOCS_CAPTURER } from './interceptor'\nimport { parseConfig, createCapturer } from '@easydocs/core'\nimport type { EasyDocsConfig } from '@easydocs/core'\n\n@Module({})\nexport class EasyDocsModule {\n static forRoot(config: EasyDocsConfig = {}): DynamicModule {\n const capturer = createCapturer(parseConfig(config))\n return {\n module: EasyDocsModule,\n global: true,\n providers: [\n {\n provide: EASYDOCS_CAPTURER,\n useValue: capturer,\n },\n {\n provide: APP_INTERCEPTOR,\n useClass: EasyDocsInterceptor,\n },\n ],\n }\n }\n}\n","import {\n Injectable,\n NestInterceptor,\n ExecutionContext,\n CallHandler,\n Inject,\n} from '@nestjs/common'\nimport { Observable, tap } from 'rxjs'\nimport { buildCaptureEvent } from '@easydocs/core'\nimport type { Capturer } from '@easydocs/core'\n\ninterface HttpRequest {\n method: string\n path: string\n route?: { path?: string }\n query: Record<string, string>\n params: Record<string, string>\n body: unknown\n headers: Record<string, string>\n}\n\ninterface HttpResponse {\n statusCode: number\n getHeaders(): Record<string, unknown>\n}\n\nexport const EASYDOCS_CAPTURER = Symbol('EASYDOCS_CAPTURER')\n\n@Injectable()\nexport class EasyDocsInterceptor implements NestInterceptor {\n constructor(@Inject(EASYDOCS_CAPTURER) private readonly capturer: Capturer) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n const startedAt = Date.now()\n const http = context.switchToHttp()\n const req = http.getRequest<HttpRequest>()\n const res = http.getResponse<HttpResponse>()\n\n return next.handle().pipe(\n tap((responseBody: unknown) => {\n this.capturer.capture(\n buildCaptureEvent({\n method: req.method,\n path: req.route?.path ?? req.path,\n query: req.query as Record<string, unknown>,\n params: req.params as Record<string, unknown>,\n requestBody: req.body,\n responseBody,\n status: res.statusCode,\n requestHeaders: req.headers as Record<string, unknown>,\n responseHeaders: res.getHeaders() as Record<string, unknown>,\n durationMs: Date.now() - startedAt,\n })\n )\n })\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,IAAAA,iBAAsC;AACtC,IAAAC,eAAgC;;;ACDhC,oBAMO;AACP,kBAAgC;AAChC,kBAAkC;;;;;;;;;;;;;;;;;;AAkB3B,IAAMC,oBAAoBC,uBAAO,mBAAA;AAGjC,IAAMC,uBAAN,MAAMA,qBAAAA;EACX,YAAwDC,UAAoB;;SAApBA,WAAAA;EAAqB;EAE7EC,UAAUC,SAA2BC,MAAwC;AAC3E,UAAMC,YAAYC,KAAKC,IAAG;AAC1B,UAAMC,OAAOL,QAAQM,aAAY;AACjC,UAAMC,MAAMF,KAAKG,WAAU;AAC3B,UAAMC,MAAMJ,KAAKK,YAAW;AAE5B,WAAOT,KAAKU,OAAM,EAAGC,SACnBC,iBAAI,CAACC,iBAAAA;AACH,WAAKhB,SAASiB,YACZC,+BAAkB;QAChBC,QAAQV,IAAIU;QACZC,MAAMX,IAAIY,OAAOD,QAAQX,IAAIW;QAC7BE,OAAOb,IAAIa;QACXC,QAAQd,IAAIc;QACZC,aAAaf,IAAIgB;QACjBT;QACAU,QAAQf,IAAIgB;QACZC,gBAAgBnB,IAAIoB;QACpBC,iBAAiBnB,IAAIoB,WAAU;QAC/BC,YAAY3B,KAAKC,IAAG,IAAKF;MAC3B,CAAA,CAAA;IAEJ,CAAA,CAAA;EAEJ;AACF;AA5BaL;AAAN,IAAMA,sBAAN;;;;;;;;;;;AD1BP,IAAAkC,eAA4C;;;;;;;;AAIrC,IAAMC,kBAAN,MAAMA,gBAAAA;EACX,OAAOC,QAAQC,SAAyB,CAAC,GAAkB;AACzD,UAAMC,eAAWC,iCAAeC,0BAAYH,MAAAA,CAAAA;AAC5C,WAAO;MACLI,QAAQN;MACRO,QAAQ;MACRC,WAAW;QACT;UACEC,SAASC;UACTC,UAAUR;QACZ;QACA;UACEM,SAASG;UACTC,UAAUC;QACZ;;IAEJ;EACF;AACF;AAlBad;AAAN,IAAMA,iBAAN;;;;","names":["import_common","import_core","EASYDOCS_CAPTURER","Symbol","EasyDocsInterceptor","capturer","intercept","context","next","startedAt","Date","now","http","switchToHttp","req","getRequest","res","getResponse","handle","pipe","tap","responseBody","capture","buildCaptureEvent","method","path","route","query","params","requestBody","body","status","statusCode","requestHeaders","headers","responseHeaders","getHeaders","durationMs","import_core","EasyDocsModule","forRoot","config","capturer","createCapturer","parseConfig","module","global","providers","provide","EASYDOCS_CAPTURER","useValue","APP_INTERCEPTOR","useClass","EasyDocsInterceptor"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easydocs/nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"README.md"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@easydocs/core": "0.
|
|
19
|
+
"@easydocs/core": "0.5.2"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@nestjs/common": ">=10.0.0",
|
|
@@ -29,7 +29,13 @@
|
|
|
29
29
|
"rxjs": "^7.8.0",
|
|
30
30
|
"tsup": "^8.3.0",
|
|
31
31
|
"typescript": "^5",
|
|
32
|
-
"
|
|
32
|
+
"vite": "8.0.13",
|
|
33
|
+
"vitest": "^4.1.6"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/RubenGlez/easydocs",
|
|
38
|
+
"directory": ""
|
|
33
39
|
},
|
|
34
40
|
"scripts": {
|
|
35
41
|
"build": "tsup",
|