@edirect/documentation 11.0.60

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 (44) hide show
  1. package/README.md +197 -0
  2. package/dist/README.md +197 -0
  3. package/dist/package.json +48 -0
  4. package/dist/src/documentation-root.controller.d.ts +16 -0
  5. package/dist/src/documentation-root.controller.d.ts.map +1 -0
  6. package/dist/src/documentation-root.controller.js +45 -0
  7. package/dist/src/documentation.constants.d.ts +14 -0
  8. package/dist/src/documentation.constants.d.ts.map +1 -0
  9. package/dist/src/documentation.constants.js +15 -0
  10. package/dist/src/documentation.controller.d.ts +29 -0
  11. package/dist/src/documentation.controller.d.ts.map +1 -0
  12. package/dist/src/documentation.controller.js +90 -0
  13. package/dist/src/documentation.module.d.ts +7 -0
  14. package/dist/src/documentation.module.d.ts.map +1 -0
  15. package/dist/src/documentation.module.js +52 -0
  16. package/dist/src/documentation.service.d.ts +39 -0
  17. package/dist/src/documentation.service.d.ts.map +1 -0
  18. package/dist/src/documentation.service.js +215 -0
  19. package/dist/src/documentation.viewer.d.ts +5 -0
  20. package/dist/src/documentation.viewer.d.ts.map +1 -0
  21. package/dist/src/documentation.viewer.js +27 -0
  22. package/dist/src/index.d.ts +4 -0
  23. package/dist/src/index.d.ts.map +1 -0
  24. package/dist/src/index.js +5 -0
  25. package/dist/src/renderers/index.d.ts +5 -0
  26. package/dist/src/renderers/index.d.ts.map +1 -0
  27. package/dist/src/renderers/index.js +18 -0
  28. package/dist/src/renderers/redoc.d.ts +7 -0
  29. package/dist/src/renderers/redoc.d.ts.map +1 -0
  30. package/dist/src/renderers/redoc.js +43 -0
  31. package/dist/src/renderers/scalar.d.ts +8 -0
  32. package/dist/src/renderers/scalar.d.ts.map +1 -0
  33. package/dist/src/renderers/scalar.js +32 -0
  34. package/dist/src/renderers/shared.d.ts +59 -0
  35. package/dist/src/renderers/shared.d.ts.map +1 -0
  36. package/dist/src/renderers/shared.js +235 -0
  37. package/dist/src/renderers/swagger-ui.d.ts +7 -0
  38. package/dist/src/renderers/swagger-ui.d.ts.map +1 -0
  39. package/dist/src/renderers/swagger-ui.js +32 -0
  40. package/dist/src/types/documentation.options.d.ts +101 -0
  41. package/dist/src/types/documentation.options.d.ts.map +1 -0
  42. package/dist/src/types/documentation.options.js +2 -0
  43. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  44. package/package.json +47 -0
package/README.md ADDED
@@ -0,0 +1,197 @@
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/README.md ADDED
@@ -0,0 +1,197 @@
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.)
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@edirect/documentation",
3
+ "version": "11.0.60",
4
+ "packageScope": "@edirect",
5
+ "main": "./dist/src/index.js",
6
+ "types": "./dist/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/src/index.js",
10
+ "default": "./dist/src/index.js",
11
+ "require": "./dist/src/index.js",
12
+ "types": "./dist/src/index.d.ts"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "dependencies": {
20
+ "@nestjs/common": "^11.1.19",
21
+ "@nestjs/swagger": "11.4.2",
22
+ "express": "5.2.1",
23
+ "tslib": "^2.8.1"
24
+ },
25
+ "devDependencies": {
26
+ "@nestjs/core": "11.1.19",
27
+ "@types/express": "^5.0.6",
28
+ "@types/node": "^25.6.2"
29
+ },
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
+ },
47
+ "type": "commonjs"
48
+ }
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,45 @@
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);
@@ -0,0 +1,14 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
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
+ };
@@ -0,0 +1,29 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,90 @@
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);