@easydocs/nestjs 0.1.4

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 EasyDocs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # @easydocs/nestjs
2
+
3
+ EasyDocs module for [NestJS](https://nestjs.com/).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @easydocs/nestjs
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Module } from '@nestjs/common'
15
+ import { EasyDocsModule } from '@easydocs/nestjs'
16
+
17
+ @Module({
18
+ imports: [
19
+ EasyDocsModule.forRoot({
20
+ ai: { provider: 'anthropic' },
21
+ }),
22
+ ],
23
+ })
24
+ export class AppModule {}
25
+ ```
26
+
27
+ That's it. A global interceptor is automatically registered. Every controller response is captured in the background.
28
+
29
+ ## Per-controller or per-route
30
+
31
+ ```ts
32
+ import { UseInterceptors } from '@nestjs/common'
33
+ import { EasyDocsInterceptor } from '@easydocs/nestjs'
34
+
35
+ // Skip the forRoot() import and use selectively:
36
+ @UseInterceptors(EasyDocsInterceptor)
37
+ @Controller('users')
38
+ export class UsersController {}
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ ```ts
44
+ EasyDocsModule.forRoot({
45
+ ai: {
46
+ provider: 'openai', // 'openai' | 'anthropic' | 'ollama'
47
+ model: 'gpt-4o',
48
+ apiKey: process.env.OPENAI_API_KEY,
49
+ },
50
+ capture: {
51
+ ignoreRoutes: ['/health', '/api/metrics'],
52
+ },
53
+ })
54
+ ```
55
+
56
+ ## View your docs
57
+
58
+ ```bash
59
+ npm install -D @easydocs/dashboard
60
+ npx easydocs dashboard
61
+
62
+ # Or export to a file
63
+ npx easydocs export > openapi.json
64
+ ```
65
+
66
+ See [@easydocs/core](../core) for the full configuration reference.
@@ -0,0 +1,16 @@
1
+ import { DynamicModule, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
2
+ import { EasyDocsConfig } from '@easydocs/core';
3
+ import { Observable } from 'rxjs';
4
+
5
+ declare class EasyDocsModule {
6
+ static forRoot(config?: EasyDocsConfig): DynamicModule;
7
+ }
8
+
9
+ declare const EASYDOCS_CONFIG: unique symbol;
10
+ declare class EasyDocsInterceptor implements NestInterceptor {
11
+ private readonly config;
12
+ constructor(config: EasyDocsConfig);
13
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
14
+ }
15
+
16
+ export { EASYDOCS_CONFIG, EasyDocsInterceptor, EasyDocsModule };
package/dist/index.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
+
29
+ // src/index.ts
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ EASYDOCS_CONFIG: () => EASYDOCS_CONFIG,
33
+ EasyDocsInterceptor: () => EasyDocsInterceptor,
34
+ EasyDocsModule: () => EasyDocsModule
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/module.ts
39
+ var import_common2 = require("@nestjs/common");
40
+ var import_core2 = require("@nestjs/core");
41
+
42
+ // src/interceptor.ts
43
+ var import_common = require("@nestjs/common");
44
+ var import_rxjs = require("rxjs");
45
+ var import_core = require("@easydocs/core");
46
+ var EASYDOCS_CONFIG = /* @__PURE__ */ Symbol("EASYDOCS_CONFIG");
47
+ var EasyDocsInterceptor = class {
48
+ constructor(config) {
49
+ this.config = config;
50
+ }
51
+ intercept(context, next) {
52
+ const startedAt = Date.now();
53
+ const http = context.switchToHttp();
54
+ const req = http.getRequest();
55
+ const res = http.getResponse();
56
+ return next.handle().pipe(
57
+ (0, import_rxjs.tap)((responseBody) => {
58
+ const routePath = req.route?.path ?? req.path;
59
+ (0, import_core.capture)(
60
+ {
61
+ method: req.method,
62
+ path: routePath,
63
+ query: req.query,
64
+ params: req.params,
65
+ body: req.body,
66
+ response: responseBody,
67
+ status: res.statusCode,
68
+ requestHeaders: req.headers,
69
+ responseHeaders: res.getHeaders(),
70
+ durationMs: Date.now() - startedAt
71
+ },
72
+ this.config
73
+ );
74
+ })
75
+ );
76
+ }
77
+ };
78
+ EasyDocsInterceptor = __decorateClass([
79
+ (0, import_common.Injectable)(),
80
+ __decorateParam(0, (0, import_common.Inject)(EASYDOCS_CONFIG))
81
+ ], EasyDocsInterceptor);
82
+
83
+ // src/module.ts
84
+ var EasyDocsModule = class {
85
+ static forRoot(config = {}) {
86
+ return {
87
+ module: EasyDocsModule,
88
+ global: true,
89
+ providers: [
90
+ {
91
+ provide: EASYDOCS_CONFIG,
92
+ useValue: config
93
+ },
94
+ {
95
+ provide: import_core2.APP_INTERCEPTOR,
96
+ useClass: EasyDocsInterceptor
97
+ }
98
+ ]
99
+ };
100
+ }
101
+ };
102
+ EasyDocsModule = __decorateClass([
103
+ (0, import_common2.Module)({})
104
+ ], EasyDocsModule);
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ EASYDOCS_CONFIG,
108
+ EasyDocsInterceptor,
109
+ EasyDocsModule
110
+ });
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/module.ts","../src/interceptor.ts"],"sourcesContent":["export { EasyDocsModule } from './module'\nexport { EasyDocsInterceptor, EASYDOCS_CONFIG } from './interceptor'\n","import { Module, DynamicModule } from '@nestjs/common'\nimport { APP_INTERCEPTOR } from '@nestjs/core'\nimport { EasyDocsInterceptor, EASYDOCS_CONFIG } from './interceptor'\nimport type { EasyDocsConfig } from '@easydocs/core'\n\n@Module({})\nexport class EasyDocsModule {\n static forRoot(config: EasyDocsConfig = {}): DynamicModule {\n return {\n module: EasyDocsModule,\n global: true,\n providers: [\n {\n provide: EASYDOCS_CONFIG,\n useValue: config,\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 { capture } from '@easydocs/core'\nimport type { EasyDocsConfig, HttpMethod } 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_CONFIG = Symbol('EASYDOCS_CONFIG')\n\n@Injectable()\nexport class EasyDocsInterceptor implements NestInterceptor {\n constructor(@Inject(EASYDOCS_CONFIG) private readonly config: EasyDocsConfig) {}\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 const routePath = req.route?.path ?? req.path\n\n capture(\n {\n method: req.method as HttpMethod,\n path: routePath,\n query: req.query as Record<string, string>,\n params: req.params as Record<string, string>,\n body: req.body,\n response: responseBody,\n status: res.statusCode,\n requestHeaders: req.headers as Record<string, string>,\n responseHeaders: res.getHeaders() as Record<string, string>,\n durationMs: Date.now() - startedAt,\n },\n this.config\n )\n })\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAAsC;AACtC,IAAAC,eAAgC;;;ACDhC,oBAMO;AACP,kBAAgC;AAChC,kBAAwB;AAkBjB,IAAM,kBAAkB,uBAAO,iBAAiB;AAGhD,IAAM,sBAAN,MAAqD;AAAA,EAC1D,YAAsD,QAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE/E,UAAU,SAA2B,MAAwC;AAC3E,UAAM,YAAY,KAAK,IAAI;AAC3B,UAAM,OAAO,QAAQ,aAAa;AAClC,UAAM,MAAM,KAAK,WAAwB;AACzC,UAAM,MAAM,KAAK,YAA0B;AAE3C,WAAO,KAAK,OAAO,EAAE;AAAA,UACnB,iBAAI,CAAC,iBAA0B;AAC7B,cAAM,YAAY,IAAI,OAAO,QAAQ,IAAI;AAEzC;AAAA,UACE;AAAA,YACE,QAAQ,IAAI;AAAA,YACZ,MAAM;AAAA,YACN,OAAO,IAAI;AAAA,YACX,QAAQ,IAAI;AAAA,YACZ,MAAM,IAAI;AAAA,YACV,UAAU;AAAA,YACV,QAAQ,IAAI;AAAA,YACZ,gBAAgB,IAAI;AAAA,YACpB,iBAAiB,IAAI,WAAW;AAAA,YAChC,YAAY,KAAK,IAAI,IAAI;AAAA,UAC3B;AAAA,UACA,KAAK;AAAA,QACP;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AA/Ba,sBAAN;AAAA,MADN,0BAAW;AAAA,EAEG,6CAAO,eAAe;AAAA,GADxB;;;ADvBN,IAAM,iBAAN,MAAqB;AAAA,EAC1B,OAAO,QAAQ,SAAyB,CAAC,GAAkB;AACzD,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,WAAW;AAAA,QACT;AAAA,UACE,SAAS;AAAA,UACT,UAAU;AAAA,QACZ;AAAA,QACA;AAAA,UACE,SAAS;AAAA,UACT,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAjBa,iBAAN;AAAA,MADN,uBAAO,CAAC,CAAC;AAAA,GACG;","names":["import_common","import_core"]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@easydocs/nestjs",
3
+ "version": "0.1.4",
4
+ "files": [
5
+ "dist",
6
+ "README.md"
7
+ ],
8
+ "description": "EasyDocs module for NestJS",
9
+ "type": "commonjs",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "dependencies": {
19
+ "@easydocs/core": "0.1.4"
20
+ },
21
+ "peerDependencies": {
22
+ "@nestjs/common": ">=10.0.0",
23
+ "@nestjs/core": ">=10.0.0",
24
+ "rxjs": ">=7.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@nestjs/common": "^11.0.0",
28
+ "@nestjs/core": "^11.0.0",
29
+ "rxjs": "^7.8.0",
30
+ "tsup": "^8.3.0",
31
+ "typescript": "^5"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "dev": "tsup --watch",
36
+ "typecheck": "tsc --noEmit"
37
+ }
38
+ }