@edirect/documentation 11.0.62-beta.2 → 11.0.62

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.
Files changed (43) hide show
  1. package/package.json +5 -23
  2. package/dist/README.md +0 -197
  3. package/dist/package.json +0 -29
  4. package/dist/src/documentation-root.controller.d.ts +0 -16
  5. package/dist/src/documentation-root.controller.d.ts.map +0 -1
  6. package/dist/src/documentation-root.controller.js +0 -45
  7. package/dist/src/documentation.constants.d.ts +0 -14
  8. package/dist/src/documentation.constants.d.ts.map +0 -1
  9. package/dist/src/documentation.constants.js +0 -15
  10. package/dist/src/documentation.controller.d.ts +0 -29
  11. package/dist/src/documentation.controller.d.ts.map +0 -1
  12. package/dist/src/documentation.controller.js +0 -90
  13. package/dist/src/documentation.module.d.ts +0 -7
  14. package/dist/src/documentation.module.d.ts.map +0 -1
  15. package/dist/src/documentation.module.js +0 -52
  16. package/dist/src/documentation.service.d.ts +0 -39
  17. package/dist/src/documentation.service.d.ts.map +0 -1
  18. package/dist/src/documentation.service.js +0 -215
  19. package/dist/src/documentation.viewer.d.ts +0 -5
  20. package/dist/src/documentation.viewer.d.ts.map +0 -1
  21. package/dist/src/documentation.viewer.js +0 -27
  22. package/dist/src/index.d.ts +0 -4
  23. package/dist/src/index.d.ts.map +0 -1
  24. package/dist/src/index.js +0 -5
  25. package/dist/src/renderers/index.d.ts +0 -5
  26. package/dist/src/renderers/index.d.ts.map +0 -1
  27. package/dist/src/renderers/index.js +0 -18
  28. package/dist/src/renderers/redoc.d.ts +0 -7
  29. package/dist/src/renderers/redoc.d.ts.map +0 -1
  30. package/dist/src/renderers/redoc.js +0 -43
  31. package/dist/src/renderers/scalar.d.ts +0 -8
  32. package/dist/src/renderers/scalar.d.ts.map +0 -1
  33. package/dist/src/renderers/scalar.js +0 -32
  34. package/dist/src/renderers/shared.d.ts +0 -59
  35. package/dist/src/renderers/shared.d.ts.map +0 -1
  36. package/dist/src/renderers/shared.js +0 -235
  37. package/dist/src/renderers/swagger-ui.d.ts +0 -7
  38. package/dist/src/renderers/swagger-ui.d.ts.map +0 -1
  39. package/dist/src/renderers/swagger-ui.js +0 -32
  40. package/dist/src/types/documentation.options.d.ts +0 -101
  41. package/dist/src/types/documentation.options.d.ts.map +0 -1
  42. package/dist/src/types/documentation.options.js +0 -2
  43. package/dist/tsconfig.lib.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/documentation",
3
- "version": "11.0.62-beta.2",
4
- "packageScope": "@edirect",
3
+ "version": "11.0.62",
5
4
  "main": "./dist/src/index.js",
6
5
  "types": "./dist/src/index.d.ts",
7
6
  "exports": {
@@ -17,31 +16,14 @@
17
16
  "dist"
18
17
  ],
19
18
  "dependencies": {
20
- "@nestjs/common": "^11.1.19",
21
- "@nestjs/swagger": "11.4.2",
19
+ "@nestjs/common": "^11.2.1",
20
+ "@nestjs/swagger": "11.4.7",
22
21
  "express": "5.2.1",
23
22
  "tslib": "^2.8.1"
24
23
  },
25
24
  "devDependencies": {
26
- "@nestjs/core": "11.1.19",
27
25
  "@types/express": "^5.0.6",
28
- "@types/node": "^25.6.2"
26
+ "@types/node": "^26.2.0"
29
27
  },
30
- "nx": {
31
- "name": "@edirect/documentation",
32
- "targets": {
33
- "build": {
34
- "executor": "@nx/js:tsc",
35
- "options": {
36
- "main": "{workspaceRoot}/packages/edirect-documentation/src/index.ts",
37
- "tsConfig": "{workspaceRoot}/packages/edirect-documentation/tsconfig.lib.json",
38
- "outputPath": "{workspaceRoot}/packages/edirect-documentation/dist",
39
- "assets": [
40
- "{workspaceRoot}/packages/edirect-documentation/package.json",
41
- "{workspaceRoot}/packages/edirect-documentation/README.md"
42
- ]
43
- }
44
- }
45
- }
46
- }
28
+ "type": "commonjs"
47
29
  }
package/dist/README.md DELETED
@@ -1,197 +0,0 @@
1
- # @edirect/documentation
2
-
3
- Self-contained NestJS module that serves **code-first** OpenAPI documentation at `/docs`, with a
4
- bolttech app bar and pluggable renderers.
5
-
6
- - **Multi-renderer** — Redoc (default), Scalar, or Swagger UI, picked per service.
7
- - **Version switching** — declare multiple API versions; the viewer renders a version dropdown.
8
- - **Deprecated badge** — mark a version `deprecated` and it shows an amber badge in the app bar.
9
- - **bolttech app bar** — one slim, sticky bar shared across renderers: logo, workspace breadcrumb,
10
- environment badge, version switch, support link, and OpenAPI download.
11
- - **Code-first** — specs are generated lazily from the live Nest application via `@nestjs/swagger`;
12
- no hand-written OpenAPI files to maintain.
13
-
14
- ## Installation
15
-
16
- ```bash
17
- pnpm add @edirect/documentation
18
- ```
19
-
20
- Peer libraries used at runtime (already present in any Nest service): `@nestjs/common`,
21
- `@nestjs/swagger`, `express`.
22
-
23
- ## Quick start
24
-
25
- The module is `@Global`. Register it in your `AppModule`, then bind the running app once after
26
- bootstrap so declarative versions can be generated lazily.
27
-
28
- ```ts
29
- // app.module.ts
30
- import { Module } from '@nestjs/common';
31
- import { DocumentationModule } from '@edirect/documentation';
32
-
33
- @Module({
34
- imports: [
35
- DocumentationModule.forRoot({
36
- title: 'Messaging Service',
37
- workspace: 'Shared Services',
38
- support: 'shared-services@bolttech.io',
39
- versions: [
40
- { slug: 'v2', label: 'v2', version: '2.0', isDefault: true, paths: ['/v2'] },
41
- ],
42
- }),
43
- ],
44
- })
45
- export class AppModule {}
46
- ```
47
-
48
- ```ts
49
- // main.ts
50
- import { NestFactory } from '@nestjs/core';
51
- import { DocumentationService } from '@edirect/documentation';
52
- import { AppModule } from './app.module';
53
-
54
- async function bootstrap() {
55
- const app = await NestFactory.create(AppModule);
56
-
57
- // REQUIRED — without this the declarative versions cannot be generated.
58
- app.get(DocumentationService).useApp(app);
59
-
60
- await app.listen(3000);
61
- }
62
- bootstrap();
63
- ```
64
-
65
- Open `http://localhost:3000/docs`.
66
-
67
- ### Async configuration
68
-
69
- Use `forRootAsync` when options depend on config/DI. Because the resolved `root` value is unknown at
70
- module-build time, opt into the `/` route with `mountRoot: true`.
71
-
72
- ```ts
73
- DocumentationModule.forRootAsync({
74
- imports: [ConfigModule],
75
- inject: [ConfigService],
76
- mountRoot: true, // only needed if you want root: 'redirect' | 'serve'
77
- useFactory: (config: ConfigService) => ({
78
- enabled: config.get('DOCS_ENABLED') !== 'false',
79
- title: config.get('SERVICE_NAME'),
80
- root: 'redirect',
81
- versions: [{ slug: 'v2', isDefault: true, paths: ['/v2'] }],
82
- }),
83
- });
84
- ```
85
-
86
- ## Routes
87
-
88
- | Route | Description |
89
- | --- | --- |
90
- | `GET /docs` | HTML viewer (renderer of your choice). Honors `?spec=<slug>` to switch version. |
91
- | `GET /docs/spec` | JSON index of registered specs (`{ default, specs: [{ slug, url, ... }] }`). |
92
- | `GET /docs/spec/:slug` | OpenAPI JSON for a spec, with `ETag` + `Cache-Control` and `304` support. |
93
- | `GET /` | Only when `root` is `redirect` or `serve` (and `mountRoot: true` for async). |
94
-
95
- When `enabled: false`, every docs route responds `404`.
96
-
97
- ## Options
98
-
99
- | Option | Type | Default | Description |
100
- | --- | --- | --- | --- |
101
- | `enabled` | `boolean` | `true` | Master switch. `false` → all docs routes return `404`. |
102
- | `title` | `string` | `'API Documentation'` | Page title and OpenAPI `info.title`. |
103
- | `description` | `string` | — | Default description for generated versions. |
104
- | `workspace` | `string` | — | Domain/workspace shown before the title in the breadcrumb. |
105
- | `support` | `string` | — | Support email or URL shown in the app bar. |
106
- | `renderer` | `'redoc' \| 'scalar' \| 'swagger-ui'` | `'redoc'` | Which viewer to render. |
107
- | `logo` | `{ url; altText? }` | bolttech logo | Brand logo in the app bar. |
108
- | `brand.accent` | `string` (hex or CSS keyword) | bolttech cyan `#00bac7` | Accent color; validated, invalid values are ignored. |
109
- | `bearerAuth` | `boolean` | `true` | Adds a bearer security scheme to every generated version. |
110
- | `servers` | `string[]` | — | Servers advertised in every generated version. |
111
- | `root` | `'off' \| 'redirect' \| 'serve'` | `'off'` | `/` behavior. Default never claims `/`. |
112
- | `versions` | `DocumentationVersionOptions[]` | — | Declarative versions, generated lazily from the app. |
113
- | `specs` | `DocumentationSpec[]` | — | Pre-built OpenAPI documents registered as-is. |
114
-
115
- `DocumentationVersionOptions`: `slug` (required), `label`, `description`, `version`, `order`,
116
- `isDefault`, `enabled`, `deprecated`, `paths` (keep only routes under these prefixes), `include`
117
- (restrict generation to given Nest modules), `configure(builder)` (customize the `DocumentBuilder`).
118
-
119
- > Note: the actual runtime defaults are `renderer: 'redoc'` and `root: 'off'`.
120
-
121
- ## Recipes
122
-
123
- ### Multiple versions
124
-
125
- ```ts
126
- DocumentationModule.forRoot({
127
- title: 'Policy Service',
128
- versions: [
129
- { slug: 'v2', label: 'v2', version: '2.0', order: 1, isDefault: true, paths: ['/v2'] },
130
- { slug: 'v1', label: 'v1', version: '1.0', order: 2, deprecated: true, paths: ['/v1'] },
131
- ],
132
- });
133
- ```
134
-
135
- ### Mark a version deprecated
136
-
137
- Set `deprecated: true` on the version — the app bar shows an amber **Deprecated** badge when that
138
- version is selected.
139
-
140
- ### Custom accent / logo / workspace
141
-
142
- ```ts
143
- DocumentationModule.forRoot({
144
- workspace: 'Payments',
145
- brand: { accent: '#7c3aed' },
146
- logo: { url: 'https://example.com/logo.svg', altText: 'Acme' },
147
- versions: [{ slug: 'v2', isDefault: true }],
148
- });
149
- ```
150
-
151
- ### Turn off in production
152
-
153
- ```ts
154
- DocumentationModule.forRoot({
155
- enabled: process.env.NODE_ENV !== 'production',
156
- versions: [{ slug: 'v2', isDefault: true }],
157
- });
158
- ```
159
-
160
- ### Redirect root to the docs
161
-
162
- ```ts
163
- DocumentationModule.forRoot({ root: 'redirect', versions: [{ slug: 'v2', isDefault: true }] });
164
- // forRootAsync: also pass `mountRoot: true`.
165
- ```
166
-
167
- ### Pre-built spec (escape hatch)
168
-
169
- ```ts
170
- DocumentationModule.forRoot({
171
- specs: [
172
- {
173
- slug: 'partner',
174
- label: 'Partner API',
175
- isDefault: true,
176
- document: () => loadPartnerOpenApi(), // OpenAPIObject or a (possibly async) factory
177
- },
178
- ],
179
- });
180
- ```
181
-
182
- ## Security notes
183
-
184
- - **Pinned CDN + SRI** — Redoc `2.5.3`, Scalar `1.62.1`, and `swagger-ui-dist` `5.32.8` are loaded
185
- from jsDelivr at fixed versions with Subresource Integrity hashes (see `renderers/shared.ts`,
186
- `CDN`). Versions cannot drift to `latest`, and a compromised CDN cannot inject script. **When
187
- bumping a renderer, change the version and the `integrity` hash together.**
188
- - **`noindex`** — the viewer emits `<meta name="robots" content="noindex, nofollow">`.
189
- - **`enabled` gate** — set `enabled: false` to make every docs route return `404` (e.g. production).
190
- - **Auth** — the module does not gate `/docs` itself. If docs should require authentication, the
191
- consumer scopes them in its own auth middleware/guard.
192
-
193
- ## Gotcha
194
-
195
- `app.get(DocumentationService).useApp(app)` is **required** in `main.ts`. Declarative `versions`
196
- are generated lazily from the live app — without `useApp`, they cannot be built and the service logs
197
- a warning shortly after boot. (`specs` registered as pre-built documents do not need it.)
package/dist/package.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "@edirect/documentation",
3
- "version": "11.0.62-beta.2",
4
- "main": "./dist/src/index.js",
5
- "types": "./dist/src/index.d.ts",
6
- "exports": {
7
- ".": {
8
- "import": "./dist/src/index.js",
9
- "default": "./dist/src/index.js",
10
- "require": "./dist/src/index.js",
11
- "types": "./dist/src/index.d.ts"
12
- },
13
- "./package.json": "./package.json"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "dependencies": {
19
- "@nestjs/common": "^11.1.19",
20
- "@nestjs/swagger": "11.4.2",
21
- "express": "5.2.1",
22
- "tslib": "^2.8.1"
23
- },
24
- "devDependencies": {
25
- "@types/express": "^5.0.6",
26
- "@types/node": "^25.6.2"
27
- },
28
- "type": "commonjs"
29
- }
@@ -1,16 +0,0 @@
1
- import type { Response } from 'express';
2
- import { DocumentationService } from './documentation.service';
3
- import type { DocumentationModuleOptions } from './types/documentation.options';
4
- /**
5
- * Handles the application root (`/`). Registered by the module ONLY when `root` is
6
- * `redirect` or `serve` — with the default (`off`) this controller is never mounted, so
7
- * installing the module does not claim `/` or affect a service's own root route.
8
- */
9
- export declare class DocumentationRootController {
10
- private readonly options;
11
- private readonly documentationService;
12
- private readonly basePath;
13
- constructor(options: DocumentationModuleOptions, documentationService: DocumentationService);
14
- root(res: Response): void | Response<any, Record<string, any>>;
15
- }
16
- //# sourceMappingURL=documentation-root.controller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentation-root.controller.d.ts","sourceRoot":"","sources":["../../src/documentation-root.controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF;;;;GAIG;AACH,qBACa,2BAA2B;IAIL,OAAO,CAAC,QAAQ,CAAC,OAAO;IACvD,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAJvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;gBAGC,OAAO,EAAE,0BAA0B,EAClE,oBAAoB,EAAE,oBAAoB;IAI7D,IAAI,CAAQ,GAAG,EAAE,QAAQ;CAW1B"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentationRootController = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const documentation_constants_1 = require("./documentation.constants");
7
- const documentation_service_1 = require("./documentation.service");
8
- const documentation_viewer_1 = require("./documentation.viewer");
9
- /**
10
- * Handles the application root (`/`). Registered by the module ONLY when `root` is
11
- * `redirect` or `serve` — with the default (`off`) this controller is never mounted, so
12
- * installing the module does not claim `/` or affect a service's own root route.
13
- */
14
- let DocumentationRootController = class DocumentationRootController {
15
- options;
16
- documentationService;
17
- basePath = `/${documentation_constants_1.DOCS_BASE_PATH}`;
18
- constructor(options, documentationService) {
19
- this.options = options;
20
- this.documentationService = documentationService;
21
- }
22
- root(res) {
23
- if (this.options.enabled === false)
24
- throw new common_1.NotFoundException();
25
- if (this.options.root === 'serve') {
26
- return res.type('text/html').send((0, documentation_viewer_1.renderDocsViewer)(this.options, this.documentationService));
27
- }
28
- if (this.options.root === 'redirect')
29
- return res.redirect(302, this.basePath);
30
- throw new common_1.NotFoundException();
31
- }
32
- };
33
- exports.DocumentationRootController = DocumentationRootController;
34
- tslib_1.__decorate([
35
- (0, common_1.Get)(),
36
- tslib_1.__param(0, (0, common_1.Res)()),
37
- tslib_1.__metadata("design:type", Function),
38
- tslib_1.__metadata("design:paramtypes", [Object]),
39
- tslib_1.__metadata("design:returntype", void 0)
40
- ], DocumentationRootController.prototype, "root", null);
41
- exports.DocumentationRootController = DocumentationRootController = tslib_1.__decorate([
42
- (0, common_1.Controller)(),
43
- tslib_1.__param(0, (0, common_1.Inject)(documentation_constants_1.DOCUMENTATION_OPTIONS)),
44
- tslib_1.__metadata("design:paramtypes", [Object, documentation_service_1.DocumentationService])
45
- ], DocumentationRootController);
@@ -1,14 +0,0 @@
1
- import { DocumentRenderer } from './types/documentation.options';
2
- export declare const DOCUMENTATION_OPTIONS: unique symbol;
3
- /** Base path where the documentation is mounted, isolated from the API routes. */
4
- export declare const DOCS_BASE_PATH = "docs";
5
- /** Default viewer when a consumer does not pick one. */
6
- export declare const DEFAULT_RENDERER: DocumentRenderer;
7
- /** Default brand accent (bolttech cyan) when a consumer does not override it. */
8
- export declare const DEFAULT_ACCENT = "#00bac7";
9
- /** Default bolttech brand logo shown in the header when a consumer does not provide one. */
10
- export declare const DEFAULT_LOGO: {
11
- url: string;
12
- altText: string;
13
- };
14
- //# sourceMappingURL=documentation.constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentation.constants.d.ts","sourceRoot":"","sources":["../../src/documentation.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AAErE,kFAAkF;AAClF,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,EAAE,gBAA0B,CAAC;AAE1D,iFAAiF;AACjF,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,4FAA4F;AAC5F,eAAO,MAAM,YAAY;;;CAGxB,CAAC"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_LOGO = exports.DEFAULT_ACCENT = exports.DEFAULT_RENDERER = exports.DOCS_BASE_PATH = exports.DOCUMENTATION_OPTIONS = void 0;
4
- exports.DOCUMENTATION_OPTIONS = Symbol('DOCUMENTATION_OPTIONS');
5
- /** Base path where the documentation is mounted, isolated from the API routes. */
6
- exports.DOCS_BASE_PATH = 'docs';
7
- /** Default viewer when a consumer does not pick one. */
8
- exports.DEFAULT_RENDERER = 'redoc';
9
- /** Default brand accent (bolttech cyan) when a consumer does not override it. */
10
- exports.DEFAULT_ACCENT = '#00bac7';
11
- /** Default bolttech brand logo shown in the header when a consumer does not provide one. */
12
- exports.DEFAULT_LOGO = {
13
- url: 'https://www.datocms-assets.com/24091/1620295990-bolttech-logo-footer.svg',
14
- altText: 'bolttech',
15
- };
@@ -1,29 +0,0 @@
1
- import type { Request, Response } from 'express';
2
- import { DocumentationService } from './documentation.service';
3
- import type { DocumentationModuleOptions } from './types/documentation.options';
4
- export declare class DocumentationController {
5
- private readonly options;
6
- private readonly documentationService;
7
- private readonly basePath;
8
- constructor(options: DocumentationModuleOptions, documentationService: DocumentationService);
9
- /** 404s every docs route when the module is disabled (e.g. turned off in production). */
10
- private ensureEnabled;
11
- viewer(res: Response, spec?: string): Response<any, Record<string, any>>;
12
- index(): {
13
- default: string | null;
14
- specs: {
15
- url: string;
16
- slug: string;
17
- label: string;
18
- description?: string;
19
- version?: string;
20
- isDefault: boolean;
21
- deprecated: boolean;
22
- }[];
23
- };
24
- spec(slug: string, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
25
- /** Strong ETag per generated document, cached on the (stable) document instance. */
26
- private readonly etagCache;
27
- private etagFor;
28
- }
29
- //# sourceMappingURL=documentation.controller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentation.controller.d.ts","sourceRoot":"","sources":["../../src/documentation.controller.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF,qBACa,uBAAuB;IAID,OAAO,CAAC,QAAQ,CAAC,OAAO;IACvD,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAJvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;gBAGC,OAAO,EAAE,0BAA0B,EAClE,oBAAoB,EAAE,oBAAoB;IAG7D,yFAAyF;IACzF,OAAO,CAAC,aAAa;IAKrB,MAAM,CAAQ,GAAG,EAAE,QAAQ,EAAiB,IAAI,CAAC,EAAE,MAAM;IAQzD,KAAK;;;;;;;;;;;;IAYC,IAAI,CAAgB,IAAI,EAAE,MAAM,EAAS,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ;IAejF,oFAAoF;IACpF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiC;IAC3D,OAAO,CAAC,OAAO;CAQhB"}
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentationController = void 0;
4
- const tslib_1 = require("tslib");
5
- const crypto_1 = require("crypto");
6
- const common_1 = require("@nestjs/common");
7
- const documentation_constants_1 = require("./documentation.constants");
8
- const documentation_service_1 = require("./documentation.service");
9
- const documentation_viewer_1 = require("./documentation.viewer");
10
- let DocumentationController = class DocumentationController {
11
- options;
12
- documentationService;
13
- basePath = `/${documentation_constants_1.DOCS_BASE_PATH}`;
14
- constructor(options, documentationService) {
15
- this.options = options;
16
- this.documentationService = documentationService;
17
- }
18
- /** 404s every docs route when the module is disabled (e.g. turned off in production). */
19
- ensureEnabled() {
20
- if (this.options.enabled === false)
21
- throw new common_1.NotFoundException();
22
- }
23
- viewer(res, spec) {
24
- this.ensureEnabled();
25
- return res
26
- .type('text/html')
27
- .send((0, documentation_viewer_1.renderDocsViewer)(this.options, this.documentationService, spec));
28
- }
29
- index() {
30
- this.ensureEnabled();
31
- return {
32
- default: this.documentationService.getDefaultSlug(),
33
- specs: this.documentationService.list().map((spec) => ({
34
- ...spec,
35
- url: `${this.basePath}/spec/${spec.slug}`,
36
- })),
37
- };
38
- }
39
- async spec(slug, req, res) {
40
- this.ensureEnabled();
41
- const document = await this.documentationService.get(slug);
42
- if (!document)
43
- throw new common_1.NotFoundException(`Unknown documentation spec '${slug}'`);
44
- const etag = this.etagFor(document);
45
- res.setHeader('ETag', etag);
46
- res.setHeader('Cache-Control', 'public, max-age=300, must-revalidate');
47
- if (req.headers['if-none-match'] === etag)
48
- return res.status(304).end();
49
- return res.type('application/json').send(JSON.stringify(document));
50
- }
51
- /** Strong ETag per generated document, cached on the (stable) document instance. */
52
- etagCache = new WeakMap();
53
- etagFor(document) {
54
- let etag = this.etagCache.get(document);
55
- if (!etag) {
56
- etag = `"${(0, crypto_1.createHash)('sha256').update(JSON.stringify(document)).digest('base64')}"`;
57
- this.etagCache.set(document, etag);
58
- }
59
- return etag;
60
- }
61
- };
62
- exports.DocumentationController = DocumentationController;
63
- tslib_1.__decorate([
64
- (0, common_1.Get)(documentation_constants_1.DOCS_BASE_PATH),
65
- tslib_1.__param(0, (0, common_1.Res)()),
66
- tslib_1.__param(1, (0, common_1.Query)('spec')),
67
- tslib_1.__metadata("design:type", Function),
68
- tslib_1.__metadata("design:paramtypes", [Object, String]),
69
- tslib_1.__metadata("design:returntype", void 0)
70
- ], DocumentationController.prototype, "viewer", null);
71
- tslib_1.__decorate([
72
- (0, common_1.Get)(`${documentation_constants_1.DOCS_BASE_PATH}/spec`),
73
- tslib_1.__metadata("design:type", Function),
74
- tslib_1.__metadata("design:paramtypes", []),
75
- tslib_1.__metadata("design:returntype", void 0)
76
- ], DocumentationController.prototype, "index", null);
77
- tslib_1.__decorate([
78
- (0, common_1.Get)(`${documentation_constants_1.DOCS_BASE_PATH}/spec/:slug`),
79
- tslib_1.__param(0, (0, common_1.Param)('slug')),
80
- tslib_1.__param(1, (0, common_1.Req)()),
81
- tslib_1.__param(2, (0, common_1.Res)()),
82
- tslib_1.__metadata("design:type", Function),
83
- tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
84
- tslib_1.__metadata("design:returntype", Promise)
85
- ], DocumentationController.prototype, "spec", null);
86
- exports.DocumentationController = DocumentationController = tslib_1.__decorate([
87
- (0, common_1.Controller)(),
88
- tslib_1.__param(0, (0, common_1.Inject)(documentation_constants_1.DOCUMENTATION_OPTIONS)),
89
- tslib_1.__metadata("design:paramtypes", [Object, documentation_service_1.DocumentationService])
90
- ], DocumentationController);
@@ -1,7 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { DocumentationModuleAsyncOptions, DocumentationModuleOptions } from './types/documentation.options';
3
- export declare class DocumentationModule {
4
- static forRoot(options?: DocumentationModuleOptions): DynamicModule;
5
- static forRootAsync(options: DocumentationModuleAsyncOptions): DynamicModule;
6
- }
7
- //# sourceMappingURL=documentation.module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentation.module.d.ts","sourceRoot":"","sources":["../../src/documentation.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAwB,MAAM,gBAAgB,CAAC;AAMrE,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAEvC,qBAEa,mBAAmB;IAC9B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,0BAA+B,GAAG,aAAa;IAgBvE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,+BAA+B,GAAG,aAAa;CAqB7E"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var DocumentationModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DocumentationModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const documentation_root_controller_1 = require("./documentation-root.controller");
8
- const documentation_constants_1 = require("./documentation.constants");
9
- const documentation_controller_1 = require("./documentation.controller");
10
- const documentation_service_1 = require("./documentation.service");
11
- let DocumentationModule = DocumentationModule_1 = class DocumentationModule {
12
- static forRoot(options = {}) {
13
- // Default `off`: do not claim `/` so installing the module never affects a new
14
- // service's own root route. Only mount the root controller when opted in.
15
- const controllers = [documentation_controller_1.DocumentationController];
16
- if (options.root === 'redirect' || options.root === 'serve') {
17
- controllers.push(documentation_root_controller_1.DocumentationRootController);
18
- }
19
- return {
20
- module: DocumentationModule_1,
21
- controllers,
22
- providers: [{ provide: documentation_constants_1.DOCUMENTATION_OPTIONS, useValue: options }, documentation_service_1.DocumentationService],
23
- exports: [documentation_service_1.DocumentationService],
24
- };
25
- }
26
- static forRootAsync(options) {
27
- // Async options are resolved at runtime, so the root behavior is not known at module
28
- // build time. Opt into the root route explicitly via `mountRoot: true`.
29
- const controllers = [documentation_controller_1.DocumentationController];
30
- if (options.mountRoot)
31
- controllers.push(documentation_root_controller_1.DocumentationRootController);
32
- return {
33
- module: DocumentationModule_1,
34
- imports: options.imports ?? [],
35
- controllers,
36
- providers: [
37
- {
38
- provide: documentation_constants_1.DOCUMENTATION_OPTIONS,
39
- useFactory: options.useFactory,
40
- inject: options.inject ?? [],
41
- },
42
- documentation_service_1.DocumentationService,
43
- ],
44
- exports: [documentation_service_1.DocumentationService],
45
- };
46
- }
47
- };
48
- exports.DocumentationModule = DocumentationModule;
49
- exports.DocumentationModule = DocumentationModule = DocumentationModule_1 = tslib_1.__decorate([
50
- (0, common_1.Global)(),
51
- (0, common_1.Module)({})
52
- ], DocumentationModule);
@@ -1,39 +0,0 @@
1
- import { INestApplication, OnApplicationBootstrap } from '@nestjs/common';
2
- import type { OpenAPIObject } from '@nestjs/swagger';
3
- import type { DocumentationModuleOptions, DocumentationSpec, DocumentationVersionOptions, SpecSummary } from './types/documentation.options';
4
- export declare class DocumentationService implements OnApplicationBootstrap {
5
- private readonly options;
6
- private readonly logger;
7
- private readonly specs;
8
- private app?;
9
- private hasVersions;
10
- constructor(options: DocumentationModuleOptions);
11
- /**
12
- * Binds the running application so declarative versions can be generated lazily.
13
- * Call once after bootstrap: `app.get(DocumentationService).useApp(app)`.
14
- */
15
- useApp(app: INestApplication): this;
16
- /** Warn (a little after boot) if declarative versions exist but `useApp` was never called. */
17
- onApplicationBootstrap(): void;
18
- /** Eagerly generates and caches every registered spec so the first viewer hit is fast. */
19
- private prewarm;
20
- /** Registers a declarative version whose document is generated on first access. */
21
- registerVersion(version: DocumentationVersionOptions): void;
22
- /** Idempotent: re-registering the same slug replaces the previous entry. */
23
- register(spec: DocumentationSpec): void;
24
- unregister(slug: string): void;
25
- has(slug: string): boolean;
26
- list(): SpecSummary[];
27
- getDefaultSlug(): string | null;
28
- get(slug: string): Promise<OpenAPIObject | null>;
29
- private buildVersionDocument;
30
- /** Builds a version-scoped OpenAPI document keeping only paths under the given prefix(es). */
31
- static pickByPathPrefix(document: OpenAPIObject, prefix: string | string[]): OpenAPIObject;
32
- /**
33
- * Drops `components` entries that are not reachable (transitively) from the document's
34
- * paths — so a version-scoped document does not ship the whole platform's schemas.
35
- * `securitySchemes` (referenced by name, not `$ref`) are always kept.
36
- */
37
- static pruneComponents(document: OpenAPIObject): OpenAPIObject;
38
- }
39
- //# sourceMappingURL=documentation.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"documentation.service.d.ts","sourceRoot":"","sources":["../../src/documentation.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAEhB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,KAAK,EACV,0BAA0B,EAC1B,iBAAiB,EACjB,2BAA2B,EAE3B,WAAW,EACZ,MAAM,+BAA+B,CAAC;AAcvC,qBACa,oBAAqB,YAAW,sBAAsB;IAMtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IALnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAC3D,OAAO,CAAC,GAAG,CAAC,CAAmB;IAC/B,OAAO,CAAC,WAAW,CAAS;gBAEgC,OAAO,EAAE,0BAA0B;IAK/F;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI;IAMnC,8FAA8F;IAC9F,sBAAsB,IAAI,IAAI;IAa9B,0FAA0F;YAC5E,OAAO;IAMrB,mFAAmF;IACnF,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,IAAI;IAe3D,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IA6BvC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,IAAI,IAAI,WAAW,EAAE;IAarB,cAAc,IAAI,MAAM,GAAG,IAAI;IAKzB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAiBtD,OAAO,CAAC,oBAAoB;IA4B5B,8FAA8F;IAC9F,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa;IAW1F;;;;OAIG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa;CAuD/D"}