te.js 2.1.0 → 2.1.1
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 +197 -196
- package/auto-docs/analysis/handler-analyzer.js +58 -58
- package/auto-docs/analysis/source-resolver.js +101 -101
- package/auto-docs/constants.js +37 -37
- package/auto-docs/docs-llm/index.js +7 -7
- package/auto-docs/docs-llm/prompts.js +222 -222
- package/auto-docs/docs-llm/provider.js +132 -132
- package/auto-docs/index.js +146 -146
- package/auto-docs/openapi/endpoint-processor.js +277 -277
- package/auto-docs/openapi/generator.js +107 -107
- package/auto-docs/openapi/level3.js +131 -131
- package/auto-docs/openapi/spec-builders.js +244 -244
- package/auto-docs/ui/docs-ui.js +186 -186
- package/auto-docs/utils/logger.js +17 -17
- package/auto-docs/utils/strip-usage.js +10 -10
- package/cli/docs-command.js +315 -315
- package/cli/fly-command.js +71 -71
- package/cli/index.js +56 -56
- package/database/index.js +165 -165
- package/database/mongodb.js +146 -146
- package/database/redis.js +201 -201
- package/docs/README.md +36 -36
- package/docs/ammo.md +362 -362
- package/docs/api-reference.md +490 -490
- package/docs/auto-docs.md +216 -216
- package/docs/cli.md +152 -152
- package/docs/configuration.md +275 -275
- package/docs/database.md +390 -390
- package/docs/error-handling.md +438 -438
- package/docs/file-uploads.md +333 -333
- package/docs/getting-started.md +214 -214
- package/docs/middleware.md +355 -355
- package/docs/rate-limiting.md +393 -393
- package/docs/routing.md +302 -302
- package/package.json +62 -62
- package/rate-limit/algorithms/fixed-window.js +141 -141
- package/rate-limit/algorithms/sliding-window.js +147 -147
- package/rate-limit/algorithms/token-bucket.js +115 -115
- package/rate-limit/base.js +165 -165
- package/rate-limit/index.js +147 -147
- package/rate-limit/storage/base.js +104 -104
- package/rate-limit/storage/memory.js +101 -101
- package/rate-limit/storage/redis.js +88 -88
- package/server/ammo/body-parser.js +220 -220
- package/server/ammo/dispatch-helper.js +103 -103
- package/server/ammo/enhancer.js +57 -57
- package/server/ammo.js +454 -415
- package/server/endpoint.js +97 -74
- package/server/error.js +9 -9
- package/server/errors/code-context.js +125 -125
- package/server/errors/llm-error-service.js +140 -140
- package/server/files/helper.js +33 -33
- package/server/files/uploader.js +143 -143
- package/server/handler.js +158 -119
- package/server/target.js +185 -175
- package/server/targets/middleware-validator.js +22 -22
- package/server/targets/path-validator.js +21 -21
- package/server/targets/registry.js +160 -160
- package/server/targets/shoot-validator.js +21 -21
- package/te.js +428 -402
- package/utils/auto-register.js +17 -17
- package/utils/configuration.js +64 -64
- package/utils/errors-llm-config.js +84 -84
- package/utils/request-logger.js +43 -43
- package/utils/status-codes.js +82 -82
- package/utils/tejas-entrypoint-html.js +18 -18
package/auto-docs/ui/docs-ui.js
CHANGED
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serves interactive API docs at /docs with try-out functionality.
|
|
3
|
-
* Uses Scalar API Reference (modern UI, try-it-out, themes). MIT.
|
|
4
|
-
* Registers internal routes: GET /docs (HTML page) and GET /docs/openapi.json (spec).
|
|
5
|
-
*
|
|
6
|
-
* @see https://scalar.com/products/api-references/integrations/html-js
|
|
7
|
-
* @see https://scalar.com/products/api-references/configuration
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import Endpoint from '../../server/endpoint.js';
|
|
11
|
-
import targetRegistry from '../../server/targets/registry.js';
|
|
12
|
-
|
|
13
|
-
/** Scalar API Reference browser standalone (IIFE, sets window.Scalar). Pinned for stability. */
|
|
14
|
-
const SCALAR_VERSION = '1.46.0';
|
|
15
|
-
const SCALAR_STANDALONE = `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${SCALAR_VERSION}/dist/browser/standalone.js`;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Default Scalar API Reference config. Use layout: 'classic' to show the test request
|
|
19
|
-
* inline on the same page instead of opening a dialog (modern layout).
|
|
20
|
-
*
|
|
21
|
-
* @see https://scalar.com/products/api-references/configuration
|
|
22
|
-
*/
|
|
23
|
-
const DEFAULT_SCALAR_CONFIG = {
|
|
24
|
-
layout: 'modern',
|
|
25
|
-
theme: 'default',
|
|
26
|
-
showSidebar: true,
|
|
27
|
-
hideDownloadButton: false,
|
|
28
|
-
hideModels: false,
|
|
29
|
-
hideSearch: false,
|
|
30
|
-
hideDarkModeToggle: false,
|
|
31
|
-
hideTestRequestButton: false,
|
|
32
|
-
showDeveloperTools: 'localhost',
|
|
33
|
-
documentDownloadType: 'both',
|
|
34
|
-
defaultOpenAllTags: false,
|
|
35
|
-
defaultOpenFirstTag: true,
|
|
36
|
-
expandAllModelSections: false,
|
|
37
|
-
expandAllResponses: false,
|
|
38
|
-
withDefaultFonts: true,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Build HTML shell for Scalar docs: script tag + inline config and mount logic.
|
|
43
|
-
* @param {string} scriptUrl - URL to Scalar standalone JS
|
|
44
|
-
* @param {string} configJson - JSON string (already escaped for embedding in JS)
|
|
45
|
-
* @returns {string} Full HTML document
|
|
46
|
-
*/
|
|
47
|
-
function buildDocsHtmlShell(scriptUrl, configJson) {
|
|
48
|
-
return `<!DOCTYPE html>
|
|
49
|
-
<html lang="en">
|
|
50
|
-
<head>
|
|
51
|
-
<meta charset="UTF-8" />
|
|
52
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
53
|
-
<title>API Reference</title>
|
|
54
|
-
<style>
|
|
55
|
-
body { margin: 0; min-height: 100vh; font-family: system-ui, sans-serif; }
|
|
56
|
-
#scalar-app { min-height: 100vh; width: 100%; }
|
|
57
|
-
</style>
|
|
58
|
-
</head>
|
|
59
|
-
<body>
|
|
60
|
-
<div id="scalar-app"></div>
|
|
61
|
-
<script src="${scriptUrl}" id="scalar-script"><\/script>
|
|
62
|
-
<script>
|
|
63
|
-
(function() {
|
|
64
|
-
var config = JSON.parse('${configJson}');
|
|
65
|
-
function mount() {
|
|
66
|
-
if (typeof Scalar !== 'undefined' && typeof Scalar.createApiReference === 'function') {
|
|
67
|
-
Scalar.createApiReference('#scalar-app', config);
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
var el = document.getElementById('scalar-script');
|
|
73
|
-
if (el) {
|
|
74
|
-
el.addEventListener('load', function() { mount(); });
|
|
75
|
-
if (el.readyState === 'complete') setTimeout(function() { mount(); }, 0);
|
|
76
|
-
}
|
|
77
|
-
if (!mount()) setTimeout(function() { mount(); }, 100);
|
|
78
|
-
})();
|
|
79
|
-
</script>
|
|
80
|
-
</body>
|
|
81
|
-
</html>`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Builds the HTML page that embeds Scalar and points to the spec URL.
|
|
86
|
-
* @param {string} specUrl - URL to the OpenAPI spec (e.g. '/docs/openapi.json' or full URL).
|
|
87
|
-
* @param {object} [scalarConfig] - Optional Scalar API Reference config (merged with defaults).
|
|
88
|
-
* @returns {string} Full HTML document.
|
|
89
|
-
*/
|
|
90
|
-
function buildDocsPage(specUrl, scalarConfig = {}) {
|
|
91
|
-
const url = specUrl || '/docs/openapi.json';
|
|
92
|
-
const config = { ...DEFAULT_SCALAR_CONFIG, ...scalarConfig, url };
|
|
93
|
-
const configJson = JSON.stringify(config)
|
|
94
|
-
.replace(/</g, '\\u003c')
|
|
95
|
-
.replace(/>/g, '\\u003e');
|
|
96
|
-
return buildDocsHtmlShell(SCALAR_STANDALONE, configJson);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Create endpoint that serves the docs HTML page at GET docsPath.
|
|
101
|
-
* @param {string} docsPath - e.g. '/docs'
|
|
102
|
-
* @param {string} htmlContent - Full HTML document
|
|
103
|
-
* @returns {Endpoint}
|
|
104
|
-
*/
|
|
105
|
-
function createDocsHtmlEndpoint(docsPath, htmlContent) {
|
|
106
|
-
const endpoint = new Endpoint();
|
|
107
|
-
endpoint.setPath('', docsPath);
|
|
108
|
-
endpoint.setMiddlewares([]);
|
|
109
|
-
endpoint.setHandler((ammo) => {
|
|
110
|
-
if (!ammo.GET) return ammo.notAllowed();
|
|
111
|
-
ammo.fire(200, htmlContent, 'text/html');
|
|
112
|
-
});
|
|
113
|
-
return endpoint;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Create endpoint that serves the OpenAPI spec JSON at GET specPath.
|
|
118
|
-
* @param {string} specPath - e.g. '/docs/openapi.json'
|
|
119
|
-
* @param {() => object | Promise<object>} getSpec - Function that returns the current spec
|
|
120
|
-
* @returns {Endpoint}
|
|
121
|
-
*/
|
|
122
|
-
function createSpecJsonEndpoint(specPath, getSpec) {
|
|
123
|
-
const endpoint = new Endpoint();
|
|
124
|
-
endpoint.setPath('', specPath);
|
|
125
|
-
endpoint.setMiddlewares([]);
|
|
126
|
-
endpoint.setHandler(async (ammo) => {
|
|
127
|
-
if (!ammo.GET) return ammo.notAllowed();
|
|
128
|
-
try {
|
|
129
|
-
const spec = await Promise.resolve(getSpec());
|
|
130
|
-
ammo.fire(200, spec);
|
|
131
|
-
} catch (err) {
|
|
132
|
-
ammo.fire(500, {
|
|
133
|
-
error: 'Failed to generate OpenAPI spec',
|
|
134
|
-
message: err?.message,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
return endpoint;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Registers the docs and openapi.json routes (or returns endpoints when mutateRegistry is false).
|
|
143
|
-
* Call this after the OpenAPI spec is available (e.g. after generateOpenAPISpec).
|
|
144
|
-
*
|
|
145
|
-
* @param {object} [options]
|
|
146
|
-
* @param {() => object | Promise<object>} options.getSpec - Function that returns the current OpenAPI spec (sync or async). Used for GET {docsPath}/openapi.json.
|
|
147
|
-
* @param {string} [options.docsPath='/docs'] - Base path for docs (HTML page and spec URL). Routes: GET {docsPath}, GET {docsPath}/openapi.json.
|
|
148
|
-
* @param {string} [options.specUrl] - Override for the spec URL shown in the docs page (default: '{docsPath}/openapi.json'). Use when serving behind a proxy with a different base path.
|
|
149
|
-
* @param {object} [options.scalarConfig] - Optional Scalar API Reference config (e.g. { layout: 'classic' } for try-it on the same page).
|
|
150
|
-
* @param {boolean} [options.mutateRegistry=true] - If true, push endpoints to registry. If false, return [docsEndpoint, specEndpoint] without mutating.
|
|
151
|
-
* @param {object} [registry] - Target registry to register routes on when mutateRegistry is true. Defaults to the module's targetRegistry.
|
|
152
|
-
* @returns {undefined | [Endpoint, Endpoint]} When mutateRegistry is false, returns the two endpoints for the caller to register.
|
|
153
|
-
*/
|
|
154
|
-
export function registerDocRoutes(options = {}, registry = targetRegistry) {
|
|
155
|
-
const {
|
|
156
|
-
getSpec,
|
|
157
|
-
docsPath = '/docs',
|
|
158
|
-
specUrl: specUrlOption,
|
|
159
|
-
scalarConfig,
|
|
160
|
-
mutateRegistry = true,
|
|
161
|
-
} = options;
|
|
162
|
-
|
|
163
|
-
if (typeof getSpec !== 'function') {
|
|
164
|
-
throw new Error(
|
|
165
|
-
'registerDocRoutes requires options.getSpec (function returning the OpenAPI spec)',
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const basePath = docsPath.replace(/\/$/, '');
|
|
170
|
-
const specUrl = specUrlOption ?? `${basePath}/openapi.json`;
|
|
171
|
-
const specPath = `${basePath}/openapi.json`;
|
|
172
|
-
const htmlContent = buildDocsPage(specUrl, scalarConfig);
|
|
173
|
-
|
|
174
|
-
const docsEndpoint = createDocsHtmlEndpoint(docsPath, htmlContent);
|
|
175
|
-
const specEndpoint = createSpecJsonEndpoint(specPath, getSpec);
|
|
176
|
-
|
|
177
|
-
if (mutateRegistry) {
|
|
178
|
-
registry.targets.push(docsEndpoint);
|
|
179
|
-
registry.targets.push(specEndpoint);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
return [docsEndpoint, specEndpoint];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export { buildDocsPage };
|
|
186
|
-
export default registerDocRoutes;
|
|
1
|
+
/**
|
|
2
|
+
* Serves interactive API docs at /docs with try-out functionality.
|
|
3
|
+
* Uses Scalar API Reference (modern UI, try-it-out, themes). MIT.
|
|
4
|
+
* Registers internal routes: GET /docs (HTML page) and GET /docs/openapi.json (spec).
|
|
5
|
+
*
|
|
6
|
+
* @see https://scalar.com/products/api-references/integrations/html-js
|
|
7
|
+
* @see https://scalar.com/products/api-references/configuration
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Endpoint from '../../server/endpoint.js';
|
|
11
|
+
import targetRegistry from '../../server/targets/registry.js';
|
|
12
|
+
|
|
13
|
+
/** Scalar API Reference browser standalone (IIFE, sets window.Scalar). Pinned for stability. */
|
|
14
|
+
const SCALAR_VERSION = '1.46.0';
|
|
15
|
+
const SCALAR_STANDALONE = `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${SCALAR_VERSION}/dist/browser/standalone.js`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default Scalar API Reference config. Use layout: 'classic' to show the test request
|
|
19
|
+
* inline on the same page instead of opening a dialog (modern layout).
|
|
20
|
+
*
|
|
21
|
+
* @see https://scalar.com/products/api-references/configuration
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_SCALAR_CONFIG = {
|
|
24
|
+
layout: 'modern',
|
|
25
|
+
theme: 'default',
|
|
26
|
+
showSidebar: true,
|
|
27
|
+
hideDownloadButton: false,
|
|
28
|
+
hideModels: false,
|
|
29
|
+
hideSearch: false,
|
|
30
|
+
hideDarkModeToggle: false,
|
|
31
|
+
hideTestRequestButton: false,
|
|
32
|
+
showDeveloperTools: 'localhost',
|
|
33
|
+
documentDownloadType: 'both',
|
|
34
|
+
defaultOpenAllTags: false,
|
|
35
|
+
defaultOpenFirstTag: true,
|
|
36
|
+
expandAllModelSections: false,
|
|
37
|
+
expandAllResponses: false,
|
|
38
|
+
withDefaultFonts: true,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Build HTML shell for Scalar docs: script tag + inline config and mount logic.
|
|
43
|
+
* @param {string} scriptUrl - URL to Scalar standalone JS
|
|
44
|
+
* @param {string} configJson - JSON string (already escaped for embedding in JS)
|
|
45
|
+
* @returns {string} Full HTML document
|
|
46
|
+
*/
|
|
47
|
+
function buildDocsHtmlShell(scriptUrl, configJson) {
|
|
48
|
+
return `<!DOCTYPE html>
|
|
49
|
+
<html lang="en">
|
|
50
|
+
<head>
|
|
51
|
+
<meta charset="UTF-8" />
|
|
52
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
53
|
+
<title>API Reference</title>
|
|
54
|
+
<style>
|
|
55
|
+
body { margin: 0; min-height: 100vh; font-family: system-ui, sans-serif; }
|
|
56
|
+
#scalar-app { min-height: 100vh; width: 100%; }
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<div id="scalar-app"></div>
|
|
61
|
+
<script src="${scriptUrl}" id="scalar-script"><\/script>
|
|
62
|
+
<script>
|
|
63
|
+
(function() {
|
|
64
|
+
var config = JSON.parse('${configJson}');
|
|
65
|
+
function mount() {
|
|
66
|
+
if (typeof Scalar !== 'undefined' && typeof Scalar.createApiReference === 'function') {
|
|
67
|
+
Scalar.createApiReference('#scalar-app', config);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
var el = document.getElementById('scalar-script');
|
|
73
|
+
if (el) {
|
|
74
|
+
el.addEventListener('load', function() { mount(); });
|
|
75
|
+
if (el.readyState === 'complete') setTimeout(function() { mount(); }, 0);
|
|
76
|
+
}
|
|
77
|
+
if (!mount()) setTimeout(function() { mount(); }, 100);
|
|
78
|
+
})();
|
|
79
|
+
</script>
|
|
80
|
+
</body>
|
|
81
|
+
</html>`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Builds the HTML page that embeds Scalar and points to the spec URL.
|
|
86
|
+
* @param {string} specUrl - URL to the OpenAPI spec (e.g. '/docs/openapi.json' or full URL).
|
|
87
|
+
* @param {object} [scalarConfig] - Optional Scalar API Reference config (merged with defaults).
|
|
88
|
+
* @returns {string} Full HTML document.
|
|
89
|
+
*/
|
|
90
|
+
function buildDocsPage(specUrl, scalarConfig = {}) {
|
|
91
|
+
const url = specUrl || '/docs/openapi.json';
|
|
92
|
+
const config = { ...DEFAULT_SCALAR_CONFIG, ...scalarConfig, url };
|
|
93
|
+
const configJson = JSON.stringify(config)
|
|
94
|
+
.replace(/</g, '\\u003c')
|
|
95
|
+
.replace(/>/g, '\\u003e');
|
|
96
|
+
return buildDocsHtmlShell(SCALAR_STANDALONE, configJson);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create endpoint that serves the docs HTML page at GET docsPath.
|
|
101
|
+
* @param {string} docsPath - e.g. '/docs'
|
|
102
|
+
* @param {string} htmlContent - Full HTML document
|
|
103
|
+
* @returns {Endpoint}
|
|
104
|
+
*/
|
|
105
|
+
function createDocsHtmlEndpoint(docsPath, htmlContent) {
|
|
106
|
+
const endpoint = new Endpoint();
|
|
107
|
+
endpoint.setPath('', docsPath);
|
|
108
|
+
endpoint.setMiddlewares([]);
|
|
109
|
+
endpoint.setHandler((ammo) => {
|
|
110
|
+
if (!ammo.GET) return ammo.notAllowed();
|
|
111
|
+
ammo.fire(200, htmlContent, 'text/html');
|
|
112
|
+
});
|
|
113
|
+
return endpoint;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create endpoint that serves the OpenAPI spec JSON at GET specPath.
|
|
118
|
+
* @param {string} specPath - e.g. '/docs/openapi.json'
|
|
119
|
+
* @param {() => object | Promise<object>} getSpec - Function that returns the current spec
|
|
120
|
+
* @returns {Endpoint}
|
|
121
|
+
*/
|
|
122
|
+
function createSpecJsonEndpoint(specPath, getSpec) {
|
|
123
|
+
const endpoint = new Endpoint();
|
|
124
|
+
endpoint.setPath('', specPath);
|
|
125
|
+
endpoint.setMiddlewares([]);
|
|
126
|
+
endpoint.setHandler(async (ammo) => {
|
|
127
|
+
if (!ammo.GET) return ammo.notAllowed();
|
|
128
|
+
try {
|
|
129
|
+
const spec = await Promise.resolve(getSpec());
|
|
130
|
+
ammo.fire(200, spec);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
ammo.fire(500, {
|
|
133
|
+
error: 'Failed to generate OpenAPI spec',
|
|
134
|
+
message: err?.message,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return endpoint;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Registers the docs and openapi.json routes (or returns endpoints when mutateRegistry is false).
|
|
143
|
+
* Call this after the OpenAPI spec is available (e.g. after generateOpenAPISpec).
|
|
144
|
+
*
|
|
145
|
+
* @param {object} [options]
|
|
146
|
+
* @param {() => object | Promise<object>} options.getSpec - Function that returns the current OpenAPI spec (sync or async). Used for GET {docsPath}/openapi.json.
|
|
147
|
+
* @param {string} [options.docsPath='/docs'] - Base path for docs (HTML page and spec URL). Routes: GET {docsPath}, GET {docsPath}/openapi.json.
|
|
148
|
+
* @param {string} [options.specUrl] - Override for the spec URL shown in the docs page (default: '{docsPath}/openapi.json'). Use when serving behind a proxy with a different base path.
|
|
149
|
+
* @param {object} [options.scalarConfig] - Optional Scalar API Reference config (e.g. { layout: 'classic' } for try-it on the same page).
|
|
150
|
+
* @param {boolean} [options.mutateRegistry=true] - If true, push endpoints to registry. If false, return [docsEndpoint, specEndpoint] without mutating.
|
|
151
|
+
* @param {object} [registry] - Target registry to register routes on when mutateRegistry is true. Defaults to the module's targetRegistry.
|
|
152
|
+
* @returns {undefined | [Endpoint, Endpoint]} When mutateRegistry is false, returns the two endpoints for the caller to register.
|
|
153
|
+
*/
|
|
154
|
+
export function registerDocRoutes(options = {}, registry = targetRegistry) {
|
|
155
|
+
const {
|
|
156
|
+
getSpec,
|
|
157
|
+
docsPath = '/docs',
|
|
158
|
+
specUrl: specUrlOption,
|
|
159
|
+
scalarConfig,
|
|
160
|
+
mutateRegistry = true,
|
|
161
|
+
} = options;
|
|
162
|
+
|
|
163
|
+
if (typeof getSpec !== 'function') {
|
|
164
|
+
throw new Error(
|
|
165
|
+
'registerDocRoutes requires options.getSpec (function returning the OpenAPI spec)',
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const basePath = docsPath.replace(/\/$/, '');
|
|
170
|
+
const specUrl = specUrlOption ?? `${basePath}/openapi.json`;
|
|
171
|
+
const specPath = `${basePath}/openapi.json`;
|
|
172
|
+
const htmlContent = buildDocsPage(specUrl, scalarConfig);
|
|
173
|
+
|
|
174
|
+
const docsEndpoint = createDocsHtmlEndpoint(docsPath, htmlContent);
|
|
175
|
+
const specEndpoint = createSpecJsonEndpoint(specPath, getSpec);
|
|
176
|
+
|
|
177
|
+
if (mutateRegistry) {
|
|
178
|
+
registry.targets.push(docsEndpoint);
|
|
179
|
+
registry.targets.push(specEndpoint);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return [docsEndpoint, specEndpoint];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { buildDocsPage };
|
|
186
|
+
export default registerDocRoutes;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Verbose logging helper for auto-docs.
|
|
3
|
-
* Returns a no-op when verbose is false or logger has no info method.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a logger that only logs when verbose is true and logger.info exists.
|
|
8
|
-
* @param {object|null} logger - Logger with .info(msg) method
|
|
9
|
-
* @param {boolean} verbose - Whether to log
|
|
10
|
-
* @returns {(msg: string) => void} Function that logs or does nothing
|
|
11
|
-
*/
|
|
12
|
-
export function createVerboseLogger(logger, verbose) {
|
|
13
|
-
if (!verbose || !logger || typeof logger.info !== 'function') {
|
|
14
|
-
return () => {};
|
|
15
|
-
}
|
|
16
|
-
return (msg) => logger.info(msg);
|
|
17
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Verbose logging helper for auto-docs.
|
|
3
|
+
* Returns a no-op when verbose is false or logger has no info method.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a logger that only logs when verbose is true and logger.info exists.
|
|
8
|
+
* @param {object|null} logger - Logger with .info(msg) method
|
|
9
|
+
* @param {boolean} verbose - Whether to log
|
|
10
|
+
* @returns {(msg: string) => void} Function that logs or does nothing
|
|
11
|
+
*/
|
|
12
|
+
export function createVerboseLogger(logger, verbose) {
|
|
13
|
+
if (!verbose || !logger || typeof logger.info !== 'function') {
|
|
14
|
+
return () => {};
|
|
15
|
+
}
|
|
16
|
+
return (msg) => logger.info(msg);
|
|
17
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strip LLM-only fields from response so they are not merged into metadata.
|
|
3
|
-
* @param {object|null} obj - Raw LLM response (may contain _usage, _fallback)
|
|
4
|
-
* @returns {object|null} Same object without _usage and _fallback
|
|
5
|
-
*/
|
|
6
|
-
export function stripLlmUsage(obj) {
|
|
7
|
-
if (!obj || typeof obj !== 'object') return obj;
|
|
8
|
-
const { _usage, _fallback, ...rest } = obj;
|
|
9
|
-
return rest;
|
|
10
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Strip LLM-only fields from response so they are not merged into metadata.
|
|
3
|
+
* @param {object|null} obj - Raw LLM response (may contain _usage, _fallback)
|
|
4
|
+
* @returns {object|null} Same object without _usage and _fallback
|
|
5
|
+
*/
|
|
6
|
+
export function stripLlmUsage(obj) {
|
|
7
|
+
if (!obj || typeof obj !== 'object') return obj;
|
|
8
|
+
const { _usage, _fallback, ...rest } = obj;
|
|
9
|
+
return rest;
|
|
10
|
+
}
|