@emeryld/rrroutes-openapi 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -10
- package/dist/docs/LeafDocsPage.d.ts +4 -22
- package/dist/docs/docs.d.ts +5 -7
- package/dist/docs/schemaIntrospection.d.ts +1 -1
- package/dist/docs/serializer.d.ts +8 -7
- package/dist/index.cjs +430 -643
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -87
- package/dist/index.mjs +433 -643
- package/dist/index.mjs.map +1 -1
- package/dist/public/assets/docs.js +260 -21
- package/dist/web/app.d.ts +1 -8
- package/dist/web/main.d.ts +1 -1
- package/dist/web/utils/grouping.d.ts +2 -8
- package/dist/web/utils/security.d.ts +21 -0
- package/dist/web/utils/types.d.ts +17 -0
- package/dist/web/v2/AppShell.d.ts +7 -0
- package/dist/web/v2/components/JsonInput.d.ts +10 -0
- package/dist/web/v2/components/JsonViewer.d.ts +12 -0
- package/dist/web/v2/components/MethodBadge.d.ts +4 -0
- package/dist/web/v2/components/New/HttpMethodChip.d.ts +7 -0
- package/dist/web/v2/components/New/ListToolBar.d.ts +11 -0
- package/dist/web/v2/components/New/MethodFiltersChips.d.ts +7 -0
- package/dist/web/v2/components/New/RequestStatusChip.d.ts +6 -0
- package/dist/web/v2/components/New/SplitPageLayout.d.ts +7 -0
- package/dist/web/v2/components/New/StabilityChip.d.ts +7 -0
- package/dist/web/v2/components/New/StatusRangeFilter.d.ts +8 -0
- package/dist/web/v2/components/RecordItem.d.ts +34 -0
- package/dist/web/v2/components/ResizableSidePanel.d.ts +12 -0
- package/dist/web/v2/components/SchemaTable.d.ts +5 -0
- package/dist/web/v2/components/SectionHeader.d.ts +9 -0
- package/dist/web/v2/endpoints/EndpointDetailsPanel.d.ts +5 -0
- package/dist/web/v2/endpoints/EndpointList.d.ts +12 -0
- package/dist/web/v2/endpoints/EndpointsPage.d.ts +1 -0
- package/dist/web/v2/endpoints/endpoints.utils.d.ts +3 -0
- package/dist/web/v2/stores/clientStore.d.ts +48 -0
- package/dist/web/v2/stores/endpointsStore.d.ts +20 -0
- package/dist/web/v2/stores/logsStore.d.ts +5 -0
- package/dist/web/v2/theme.d.ts +21 -0
- package/dist/web/v2/types/types.base.d.ts +30 -0
- package/dist/web/v2/types/types.cacheLog.d.ts +165 -0
- package/dist/web/v2/types/types.endpoint.d.ts +326 -0
- package/dist/web/v2/types/types.log.d.ts +119 -0
- package/dist/web/v2/types/types.preset.d.ts +251 -0
- package/dist/web/v2/types/types.requestLog.d.ts +264 -0
- package/package.json +15 -5
- package/dist/docs/presets.d.ts +0 -14
- package/dist/public/assets/docs.css +0 -1
- package/dist/web/components/Analytics.d.ts +0 -68
- package/dist/web/components/CopyablePre.d.ts +0 -7
- package/dist/web/components/EndpointCard.d.ts +0 -10
- package/dist/web/components/Filters.d.ts +0 -9
- package/dist/web/components/FiltersBar.d.ts +0 -25
- package/dist/web/components/HelperEnumInput.d.ts +0 -11
- package/dist/web/components/HistoryView.d.ts +0 -7
- package/dist/web/components/LogsView.d.ts +0 -1
- package/dist/web/components/PlaygroundOverlay.d.ts +0 -94
- package/dist/web/components/PresetsView.d.ts +0 -15
- package/dist/web/components/RequestLogs.d.ts +0 -10
- package/dist/web/components/SchemaTable.d.ts +0 -4
- package/dist/web/components/ui/Button.d.ts +0 -8
- package/dist/web/components/ui/Clickable.d.ts +0 -7
- package/dist/web/components/ui/Tag.d.ts +0 -9
- package/dist/web/components/ui/Text.d.ts +0 -8
- package/dist/web/components/ui/index.d.ts +0 -4
- package/dist/web/historyStore.d.ts +0 -68
- package/dist/web/logsStore.d.ts +0 -51
- package/dist/web/types.d.ts +0 -5
- package/dist/webhooks.d.ts +0 -181
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
introspectSchema: () => introspectSchema,
|
|
34
35
|
mountRRRoutesDocs: () => mountRRRoutesDocs,
|
|
35
36
|
renderLeafDocsHTML: () => renderLeafDocsHTML2,
|
|
37
|
+
requiredRoutes: () => leaves,
|
|
36
38
|
serializeLeaf: () => serializeLeaf
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -45,6 +47,9 @@ var import_node_url = require("url");
|
|
|
45
47
|
// src/docs/LeafDocsPage.tsx
|
|
46
48
|
var import_server = require("react-dom/server");
|
|
47
49
|
|
|
50
|
+
// src/docs/serializer.ts
|
|
51
|
+
var import_rrroutes_contract = require("@emeryld/rrroutes-contract");
|
|
52
|
+
|
|
48
53
|
// src/docs/schemaIntrospection.ts
|
|
49
54
|
var z = __toESM(require("zod"), 1);
|
|
50
55
|
function getDef(schema) {
|
|
@@ -190,10 +195,10 @@ function serializeLeaf(leaf) {
|
|
|
190
195
|
hasQuery: !!cfg.querySchema,
|
|
191
196
|
hasParams: !!cfg.paramsSchema,
|
|
192
197
|
hasOutput: !!cfg.outputSchema,
|
|
193
|
-
bodySchema: introspectSchema(cfg.bodySchema),
|
|
194
|
-
querySchema: introspectSchema(cfg.querySchema),
|
|
195
|
-
paramsSchema: introspectSchema(cfg.paramsSchema),
|
|
196
|
-
outputSchema: introspectSchema(cfg.outputSchema)
|
|
198
|
+
bodySchema: cfg.bodySchema ? introspectSchema((0, import_rrroutes_contract.routeSchemaParse)(cfg.bodySchema)) : void 0,
|
|
199
|
+
querySchema: cfg.querySchema ? introspectSchema((0, import_rrroutes_contract.routeSchemaParse)(cfg.querySchema)) : void 0,
|
|
200
|
+
paramsSchema: cfg.paramsSchema ? introspectSchema((0, import_rrroutes_contract.routeSchemaParse)(cfg.paramsSchema)) : void 0,
|
|
201
|
+
outputSchema: cfg.outputSchema ? introspectSchema((0, import_rrroutes_contract.routeSchemaParse)(cfg.outputSchema)) : void 0
|
|
197
202
|
}
|
|
198
203
|
};
|
|
199
204
|
}
|
|
@@ -210,25 +215,17 @@ function normalizeDocsBase(base) {
|
|
|
210
215
|
if (base === "/") return "/";
|
|
211
216
|
return base.endsWith("/") && base.length > 1 ? base.slice(0, -1) : base;
|
|
212
217
|
}
|
|
213
|
-
function normalizeBaseUrlSuffix(suffix) {
|
|
214
|
-
if (!suffix) return "";
|
|
215
|
-
const trimmed = suffix.endsWith("/") && suffix.length > 1 ? suffix.slice(0, -1) : suffix;
|
|
216
|
-
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
217
|
-
}
|
|
218
218
|
var DocsDocument = ({
|
|
219
219
|
leavesJson,
|
|
220
|
-
presetsJson,
|
|
221
220
|
assetBase,
|
|
222
221
|
docsBase,
|
|
223
|
-
historyJson,
|
|
224
|
-
logsJson,
|
|
225
|
-
baseUrlSuffix,
|
|
226
|
-
webhooks,
|
|
227
222
|
cspNonce
|
|
228
223
|
}) => {
|
|
229
224
|
const cssHref = `${assetBase}/docs.css`;
|
|
230
225
|
const jsSrc = `${assetBase}/docs.js`;
|
|
231
|
-
const configJson = serializeConfig({
|
|
226
|
+
const configJson = serializeConfig({
|
|
227
|
+
docsBasePath: docsBase
|
|
228
|
+
});
|
|
232
229
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("html", { lang: "en", children: [
|
|
233
230
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("head", { children: [
|
|
234
231
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { charSet: "UTF-8" }),
|
|
@@ -247,33 +244,6 @@ var DocsDocument = ({
|
|
|
247
244
|
dangerouslySetInnerHTML: { __html: leavesJson }
|
|
248
245
|
}
|
|
249
246
|
),
|
|
250
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
251
|
-
"script",
|
|
252
|
-
{
|
|
253
|
-
id: "preset-data",
|
|
254
|
-
type: "application/json",
|
|
255
|
-
nonce: cspNonce,
|
|
256
|
-
dangerouslySetInnerHTML: { __html: presetsJson }
|
|
257
|
-
}
|
|
258
|
-
),
|
|
259
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
260
|
-
"script",
|
|
261
|
-
{
|
|
262
|
-
id: "history-data",
|
|
263
|
-
type: "application/json",
|
|
264
|
-
nonce: cspNonce,
|
|
265
|
-
dangerouslySetInnerHTML: { __html: historyJson }
|
|
266
|
-
}
|
|
267
|
-
),
|
|
268
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
269
|
-
"script",
|
|
270
|
-
{
|
|
271
|
-
id: "logs-data",
|
|
272
|
-
type: "application/json",
|
|
273
|
-
nonce: cspNonce,
|
|
274
|
-
dangerouslySetInnerHTML: { __html: logsJson }
|
|
275
|
-
}
|
|
276
|
-
),
|
|
277
247
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
278
248
|
"script",
|
|
279
249
|
{
|
|
@@ -287,627 +257,39 @@ var DocsDocument = ({
|
|
|
287
257
|
] })
|
|
288
258
|
] });
|
|
289
259
|
};
|
|
290
|
-
function serializeLeaves(
|
|
291
|
-
return JSON.stringify(
|
|
292
|
-
}
|
|
293
|
-
function serializePresets(presets) {
|
|
294
|
-
return JSON.stringify(Array.isArray(presets) ? presets : []).replace(/<\//g, "<\\/");
|
|
295
|
-
}
|
|
296
|
-
function serializeHistorySeeds(historySeeds) {
|
|
297
|
-
return JSON.stringify(Array.isArray(historySeeds) ? historySeeds : []).replace(/<\//g, "<\\/");
|
|
298
|
-
}
|
|
299
|
-
function serializeLogSeeds(logSeeds) {
|
|
300
|
-
return JSON.stringify(Array.isArray(logSeeds) ? logSeeds : []).replace(/<\//g, "<\\/");
|
|
260
|
+
function serializeLeaves(leaves2) {
|
|
261
|
+
return JSON.stringify(leaves2.map(serializeLeaf)).replace(/<\//g, "<\\/");
|
|
301
262
|
}
|
|
302
263
|
function serializeConfig(config) {
|
|
303
264
|
return JSON.stringify(config).replace(/<\//g, "<\\/");
|
|
304
265
|
}
|
|
305
|
-
function createLeafDocsDocument(
|
|
266
|
+
function createLeafDocsDocument(leaves2, options = {}) {
|
|
306
267
|
const assetBase = normalizeBase(options.assetBasePath ?? DEFAULT_ASSET_BASE);
|
|
307
|
-
const leavesJson = serializeLeaves(
|
|
308
|
-
const presetsJson = serializePresets(options.presets);
|
|
268
|
+
const leavesJson = serializeLeaves(leaves2);
|
|
309
269
|
const docsBase = normalizeDocsBase(options.docsBasePath);
|
|
310
|
-
const historyJson = serializeHistorySeeds(options.historySeeds);
|
|
311
|
-
const logsJson = serializeLogSeeds(options.logSeeds);
|
|
312
|
-
const baseUrlSuffix = normalizeBaseUrlSuffix(options.baseUrlSuffix);
|
|
313
|
-
const webhooks = options.webhooks;
|
|
314
270
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
315
271
|
DocsDocument,
|
|
316
272
|
{
|
|
317
273
|
leavesJson,
|
|
318
|
-
presetsJson,
|
|
319
274
|
assetBase,
|
|
320
275
|
docsBase,
|
|
321
|
-
historyJson,
|
|
322
|
-
logsJson,
|
|
323
|
-
baseUrlSuffix,
|
|
324
|
-
webhooks,
|
|
325
276
|
cspNonce: options.cspNonce
|
|
326
277
|
}
|
|
327
278
|
);
|
|
328
279
|
}
|
|
329
|
-
function renderLeafDocsHTML(
|
|
330
|
-
const doc = createLeafDocsDocument(
|
|
280
|
+
function renderLeafDocsHTML(leaves2, options = {}) {
|
|
281
|
+
const doc = createLeafDocsDocument(leaves2, options);
|
|
331
282
|
const html = (0, import_server.renderToStaticMarkup)(doc);
|
|
332
283
|
return `<!DOCTYPE html>${html}`;
|
|
333
284
|
}
|
|
334
285
|
|
|
335
286
|
// src/docs/docs.ts
|
|
336
|
-
function renderLeafDocsHTML2(
|
|
337
|
-
return renderLeafDocsHTML(
|
|
287
|
+
function renderLeafDocsHTML2(leaves2, options = {}) {
|
|
288
|
+
return renderLeafDocsHTML(leaves2, options);
|
|
338
289
|
}
|
|
339
290
|
|
|
340
|
-
// src/
|
|
341
|
-
var
|
|
342
|
-
var logTypeSchema = import_zod.z.enum(["debug", "info", "warn", "error", "system"]);
|
|
343
|
-
var historyFeedEntrySchema = import_zod.z.object({
|
|
344
|
-
id: import_zod.z.string(),
|
|
345
|
-
requestId: import_zod.z.string().optional(),
|
|
346
|
-
timestamp: import_zod.z.number(),
|
|
347
|
-
method: import_zod.z.string(),
|
|
348
|
-
path: import_zod.z.string(),
|
|
349
|
-
fullUrl: import_zod.z.string().optional(),
|
|
350
|
-
params: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).optional(),
|
|
351
|
-
query: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).optional(),
|
|
352
|
-
body: import_zod.z.string().optional(),
|
|
353
|
-
output: import_zod.z.string().optional(),
|
|
354
|
-
status: import_zod.z.number().optional(),
|
|
355
|
-
durationMs: import_zod.z.number(),
|
|
356
|
-
error: import_zod.z.string().optional()
|
|
357
|
-
});
|
|
358
|
-
var logFeedEntrySchema = import_zod.z.object({
|
|
359
|
-
id: import_zod.z.string(),
|
|
360
|
-
type: logTypeSchema,
|
|
361
|
-
message: import_zod.z.string(),
|
|
362
|
-
timestamp: import_zod.z.number(),
|
|
363
|
-
requestId: import_zod.z.string().optional(),
|
|
364
|
-
tags: import_zod.z.array(import_zod.z.string()).optional(),
|
|
365
|
-
metadata: import_zod.z.string().optional()
|
|
366
|
-
});
|
|
367
|
-
var historyFeedQuerySchema = import_zod.z.object({
|
|
368
|
-
cursor: import_zod.z.string().optional(),
|
|
369
|
-
limit: import_zod.z.number().int().positive().optional(),
|
|
370
|
-
methods: import_zod.z.array(import_zod.z.string()).optional(),
|
|
371
|
-
path: import_zod.z.string().optional(),
|
|
372
|
-
status: import_zod.z.string().optional(),
|
|
373
|
-
text: import_zod.z.string().optional(),
|
|
374
|
-
from: import_zod.z.number().optional(),
|
|
375
|
-
to: import_zod.z.number().optional(),
|
|
376
|
-
sortBy: import_zod.z.enum(["timestamp", "path", "duration"]).optional(),
|
|
377
|
-
sortDir: import_zod.z.enum(["asc", "desc"]).optional()
|
|
378
|
-
});
|
|
379
|
-
var logFeedQuerySchema = import_zod.z.object({
|
|
380
|
-
cursor: import_zod.z.string().optional(),
|
|
381
|
-
limit: import_zod.z.number().int().positive().optional(),
|
|
382
|
-
types: import_zod.z.array(logTypeSchema).optional(),
|
|
383
|
-
tags: import_zod.z.array(import_zod.z.string()).optional(),
|
|
384
|
-
requestId: import_zod.z.string().optional(),
|
|
385
|
-
text: import_zod.z.string().optional(),
|
|
386
|
-
from: import_zod.z.number().optional(),
|
|
387
|
-
to: import_zod.z.number().optional(),
|
|
388
|
-
sortDir: import_zod.z.enum(["asc", "desc"]).optional()
|
|
389
|
-
});
|
|
390
|
-
var webhookPageSchema = (itemSchema) => import_zod.z.object({
|
|
391
|
-
items: import_zod.z.array(itemSchema).default([]),
|
|
392
|
-
nextCursor: import_zod.z.string().optional(),
|
|
393
|
-
prevCursor: import_zod.z.string().optional(),
|
|
394
|
-
total: import_zod.z.number().optional()
|
|
395
|
-
});
|
|
396
|
-
var historyWebhookResponseSchema = webhookPageSchema(historyFeedEntrySchema);
|
|
397
|
-
var logWebhookResponseSchema = webhookPageSchema(logFeedEntrySchema);
|
|
398
|
-
|
|
399
|
-
// src/index.ts
|
|
400
|
-
var trimTrailingSlash = (value) => value.endsWith("/") && value.length > 1 ? value.slice(0, -1) : value;
|
|
401
|
-
function mountRRRoutesDocs({
|
|
402
|
-
router,
|
|
403
|
-
leaves,
|
|
404
|
-
presets = [],
|
|
405
|
-
options = {}
|
|
406
|
-
}) {
|
|
407
|
-
const prefix = options.prefix ? trimTrailingSlash(options.prefix) : "";
|
|
408
|
-
const docsPath = options.path ?? "/__rrroutes/docs";
|
|
409
|
-
const normalizedDocsPath = trimTrailingSlash(docsPath);
|
|
410
|
-
const assetsMountPath = trimTrailingSlash(
|
|
411
|
-
options.assetBasePath ?? `${normalizedDocsPath}/assets`
|
|
412
|
-
);
|
|
413
|
-
const webhookBaseInput = options.logWebhook?.basePath ?? `${normalizedDocsPath}/webhooks`;
|
|
414
|
-
const webhookBasePath = trimTrailingSlash(
|
|
415
|
-
webhookBaseInput.startsWith("/") ? webhookBaseInput : `/${webhookBaseInput}`
|
|
416
|
-
);
|
|
417
|
-
const defaultHistoryLimit = 200;
|
|
418
|
-
const defaultLogLimit = 400;
|
|
419
|
-
const redactLogEntry = createLogRedactor(options.redactLogEntry);
|
|
420
|
-
const seededHistory = normalizeHistorySeeds(options.historySeeds, defaultHistoryLimit);
|
|
421
|
-
const seededLogs = normalizeLogSeeds(options.logSeeds, defaultLogLimit, redactLogEntry);
|
|
422
|
-
const inMemoryHistory = seededHistory.slice();
|
|
423
|
-
const inMemoryLogs = seededLogs.slice();
|
|
424
|
-
const historySeedsForUi = seededHistory.map((entry) => ({
|
|
425
|
-
...entry,
|
|
426
|
-
fullUrl: entry.fullUrl || entry.path
|
|
427
|
-
}));
|
|
428
|
-
const webhookPaths = {
|
|
429
|
-
history: `${webhookBasePath}/history`,
|
|
430
|
-
logs: `${webhookBasePath}/logs`
|
|
431
|
-
};
|
|
432
|
-
const webhookSchemas = {
|
|
433
|
-
history: {
|
|
434
|
-
query: historyFeedQuerySchema,
|
|
435
|
-
response: historyWebhookResponseSchema,
|
|
436
|
-
entry: historyFeedEntrySchema
|
|
437
|
-
},
|
|
438
|
-
logs: {
|
|
439
|
-
query: logFeedQuerySchema,
|
|
440
|
-
response: logWebhookResponseSchema,
|
|
441
|
-
entry: logFeedEntrySchema
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
const webhookLeaves = {
|
|
445
|
-
history: {
|
|
446
|
-
method: "get",
|
|
447
|
-
path: webhookPaths.history,
|
|
448
|
-
cfg: {
|
|
449
|
-
summary: "RRRoutes docs history feed",
|
|
450
|
-
description: "Returns request history for the docs UI.",
|
|
451
|
-
querySchema: historyFeedQuerySchema,
|
|
452
|
-
outputSchema: historyWebhookResponseSchema,
|
|
453
|
-
tags: ["rrroutes", "docs"]
|
|
454
|
-
}
|
|
455
|
-
},
|
|
456
|
-
logs: {
|
|
457
|
-
method: "get",
|
|
458
|
-
path: webhookPaths.logs,
|
|
459
|
-
cfg: {
|
|
460
|
-
summary: "RRRoutes docs request logs",
|
|
461
|
-
description: "Returns request logs for the docs UI.",
|
|
462
|
-
querySchema: logFeedQuerySchema,
|
|
463
|
-
outputSchema: logWebhookResponseSchema,
|
|
464
|
-
tags: ["rrroutes", "docs"]
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
const publicDir = resolvePublicDir();
|
|
469
|
-
const assetsDir = import_node_path.default.join(publicDir, "assets");
|
|
470
|
-
const cspEnabled = options.csp !== false;
|
|
471
|
-
const authConfig = options.auth;
|
|
472
|
-
const authEnabled = authConfig?.enabled !== false;
|
|
473
|
-
const docsPassword = resolveDocsPassword(authConfig);
|
|
474
|
-
const authRealm = authConfig?.realm || "RRRoutes Docs";
|
|
475
|
-
if (authEnabled) {
|
|
476
|
-
const guard = docsPassword ? createPasswordGuard(docsPassword, authRealm) : createMissingPasswordGuard();
|
|
477
|
-
[normalizedDocsPath, assetsMountPath, webhookBasePath].forEach((p) => {
|
|
478
|
-
router.use(p, guard);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
router.use(assetsMountPath, (0, import_express.static)(assetsDir, { immutable: true, maxAge: "365d" }));
|
|
482
|
-
const usingFakeHistory = !options.logWebhook?.history;
|
|
483
|
-
const usingFakeLogs = !options.logWebhook?.logs;
|
|
484
|
-
if (usingFakeHistory || usingFakeLogs) {
|
|
485
|
-
router.use((req, res, next) => {
|
|
486
|
-
if (req.path.startsWith(webhookBasePath) || req.path.startsWith(assetsMountPath) || req.path.startsWith(normalizedDocsPath)) {
|
|
487
|
-
return next();
|
|
488
|
-
}
|
|
489
|
-
const start = Date.now();
|
|
490
|
-
const requestIdHeader = req.headers["x-request-id"] || req.headers["x-requestid"] || req.headers["x-request_id"];
|
|
491
|
-
const requestId = Array.isArray(requestIdHeader) ? requestIdHeader[0] : requestIdHeader;
|
|
492
|
-
res.once("finish", () => {
|
|
493
|
-
const timestamp = Date.now();
|
|
494
|
-
const durationMs = Math.max(timestamp - start, 0);
|
|
495
|
-
const methodUpper = String(req.method || "GET").toUpperCase();
|
|
496
|
-
const pathOnly = req.path || req.originalUrl || "";
|
|
497
|
-
const status = res.statusCode;
|
|
498
|
-
const errorMsg = status >= 400 ? `${status}` : void 0;
|
|
499
|
-
if (usingFakeHistory) {
|
|
500
|
-
inMemoryHistory.unshift({
|
|
501
|
-
id: (0, import_crypto.randomBytes)(8).toString("hex"),
|
|
502
|
-
requestId: requestId ? String(requestId) : void 0,
|
|
503
|
-
timestamp,
|
|
504
|
-
method: methodUpper,
|
|
505
|
-
path: pathOnly,
|
|
506
|
-
fullUrl: req.originalUrl || pathOnly,
|
|
507
|
-
params: {},
|
|
508
|
-
query: coerceQueryRecord(req.query),
|
|
509
|
-
body: coercePayload(req.body),
|
|
510
|
-
output: "",
|
|
511
|
-
status,
|
|
512
|
-
durationMs,
|
|
513
|
-
error: errorMsg
|
|
514
|
-
});
|
|
515
|
-
if (inMemoryHistory.length > defaultHistoryLimit) inMemoryHistory.length = defaultHistoryLimit;
|
|
516
|
-
}
|
|
517
|
-
if (usingFakeLogs) {
|
|
518
|
-
const logType = status >= 500 ? "error" : status >= 400 ? "warn" : "info";
|
|
519
|
-
const metadata = JSON.stringify({
|
|
520
|
-
query: req.query,
|
|
521
|
-
durationMs
|
|
522
|
-
});
|
|
523
|
-
const redacted = redactLogEntry({
|
|
524
|
-
id: (0, import_crypto.randomBytes)(8).toString("hex"),
|
|
525
|
-
type: logType,
|
|
526
|
-
message: `${methodUpper} ${pathOnly} -> ${status}`,
|
|
527
|
-
timestamp,
|
|
528
|
-
requestId: requestId ? String(requestId) : void 0,
|
|
529
|
-
tags: [],
|
|
530
|
-
metadata
|
|
531
|
-
});
|
|
532
|
-
if (redacted) {
|
|
533
|
-
inMemoryLogs.unshift(redacted);
|
|
534
|
-
if (inMemoryLogs.length > defaultLogLimit) inMemoryLogs.length = defaultLogLimit;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
next();
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
router.get(webhookPaths.history, async (req, res) => {
|
|
542
|
-
const handler = options.logWebhook?.history;
|
|
543
|
-
try {
|
|
544
|
-
applyDocsSecurityHeaders(res);
|
|
545
|
-
const query = parseHistoryWebhookQuery(req);
|
|
546
|
-
if (!handler) {
|
|
547
|
-
const filtered2 = applyHistoryQuery(inMemoryHistory, query, defaultHistoryLimit);
|
|
548
|
-
res.json(filtered2);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
const result = await handler({ query, req, res });
|
|
552
|
-
const normalized = normalizeWebhookPage(result);
|
|
553
|
-
const filtered = applyHistoryQuery(normalized.items, query, defaultHistoryLimit);
|
|
554
|
-
res.json(filtered);
|
|
555
|
-
} catch (err) {
|
|
556
|
-
console.error("Failed to serve history webhook", err);
|
|
557
|
-
res.status(500).json({ error: "Failed to load history feed" });
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
router.get(webhookPaths.logs, async (req, res) => {
|
|
561
|
-
const handler = options.logWebhook?.logs;
|
|
562
|
-
try {
|
|
563
|
-
applyDocsSecurityHeaders(res);
|
|
564
|
-
const query = parseLogWebhookQuery(req);
|
|
565
|
-
if (!handler) {
|
|
566
|
-
const filtered2 = applyLogsQuery(inMemoryLogs, query, defaultLogLimit);
|
|
567
|
-
res.json(filtered2);
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
const result = await handler({ query, req, res });
|
|
571
|
-
const normalized = normalizeWebhookPage(result);
|
|
572
|
-
const redacted = applyLogRedaction(normalized.items, redactLogEntry);
|
|
573
|
-
const filtered = applyLogsQuery(redacted, query, defaultLogLimit);
|
|
574
|
-
res.json(filtered);
|
|
575
|
-
} catch (err) {
|
|
576
|
-
console.error("Failed to serve log webhook", err);
|
|
577
|
-
res.status(500).json({ error: "Failed to load logs feed" });
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
const docsRoutePaths = [normalizedDocsPath, `${normalizedDocsPath}/`, `${normalizedDocsPath}/*id`];
|
|
581
|
-
router.get(docsRoutePaths, (req, res) => {
|
|
582
|
-
const preparedLeaves = Array.isArray(leaves) ? leaves.filter((leaf) => leaf.cfg.docsHidden !== true) : [];
|
|
583
|
-
const preparedPresets = Array.isArray(presets) ? presets : [];
|
|
584
|
-
const onRequestResult = options.onRequest?.({ req, res, leaves: preparedLeaves, presets: preparedPresets }) ?? {};
|
|
585
|
-
const finalLeaves = onRequestResult.leaves ?? preparedLeaves;
|
|
586
|
-
const finalPresets = onRequestResult.presets ?? preparedPresets;
|
|
587
|
-
const hasCustomHtml = typeof onRequestResult.html === "string";
|
|
588
|
-
let nonce = onRequestResult.nonce;
|
|
589
|
-
if (!nonce && cspEnabled && !hasCustomHtml) {
|
|
590
|
-
nonce = (0, import_crypto.randomBytes)(16).toString("base64");
|
|
591
|
-
}
|
|
592
|
-
const html = hasCustomHtml ? onRequestResult.html : renderLeafDocsHTML2(finalLeaves, {
|
|
593
|
-
cspNonce: nonce,
|
|
594
|
-
assetBasePath: `${prefix}${assetsMountPath}`,
|
|
595
|
-
docsBasePath: `${prefix}${normalizedDocsPath}`,
|
|
596
|
-
baseUrlSuffix: prefix,
|
|
597
|
-
historySeeds: historySeedsForUi,
|
|
598
|
-
logSeeds: seededLogs,
|
|
599
|
-
presets: normalizePresets(finalPresets),
|
|
600
|
-
webhooks: {
|
|
601
|
-
history: `${prefix}${webhookPaths.history}`,
|
|
602
|
-
logs: `${prefix}${webhookPaths.logs}`
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
applyDocsSecurityHeaders(res);
|
|
606
|
-
if (cspEnabled && nonce) {
|
|
607
|
-
res.setHeader(
|
|
608
|
-
"Content-Security-Policy",
|
|
609
|
-
[
|
|
610
|
-
"default-src 'self'",
|
|
611
|
-
`script-src 'self' 'nonce-${nonce}'`,
|
|
612
|
-
`style-src 'self' 'nonce-${nonce}'`,
|
|
613
|
-
"img-src 'self' data:",
|
|
614
|
-
"connect-src 'self'",
|
|
615
|
-
"font-src 'self'",
|
|
616
|
-
"frame-ancestors 'self'"
|
|
617
|
-
].join("; ")
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
res.send(html);
|
|
621
|
-
});
|
|
622
|
-
return { path: docsPath, webhooks: webhookPaths, webhookLeaves, webhookSchemas };
|
|
623
|
-
}
|
|
624
|
-
function resolvePublicDir() {
|
|
625
|
-
const moduleDir = typeof __dirname !== "undefined" ? __dirname : import_node_path.default.dirname((0, import_node_url.fileURLToPath)(__import_meta_url));
|
|
626
|
-
const fromModule = import_node_path.default.resolve(moduleDir, "../public");
|
|
627
|
-
if (import_node_fs.default.existsSync(fromModule)) return fromModule;
|
|
628
|
-
const fallback = import_node_path.default.resolve(moduleDir, "../dist/public");
|
|
629
|
-
if (import_node_fs.default.existsSync(fallback)) return fallback;
|
|
630
|
-
return fromModule;
|
|
631
|
-
}
|
|
632
|
-
function normalizePresets(presets) {
|
|
633
|
-
if (!Array.isArray(presets)) return [];
|
|
634
|
-
return presets.map((preset) => ({
|
|
635
|
-
name: preset.name,
|
|
636
|
-
description: preset.description,
|
|
637
|
-
tags: Array.isArray(preset.tags) ? preset.tags.slice() : [],
|
|
638
|
-
docsGroup: preset.docsGroup,
|
|
639
|
-
ops: Array.isArray(preset.ops) ? preset.ops.map((op) => ({
|
|
640
|
-
method: typeof op.method === "string" ? op.method.toUpperCase() : "",
|
|
641
|
-
path: typeof op.path === "string" ? op.path : "",
|
|
642
|
-
body: op.body,
|
|
643
|
-
query: op.query,
|
|
644
|
-
params: op.params
|
|
645
|
-
})) : []
|
|
646
|
-
}));
|
|
647
|
-
}
|
|
648
|
-
function parseHistoryWebhookQuery(req) {
|
|
649
|
-
const query = req.query || {};
|
|
650
|
-
const methods = parseStringList(query.methods);
|
|
651
|
-
const path2 = typeof query.path === "string" ? query.path : void 0;
|
|
652
|
-
const status = typeof query.status === "string" ? query.status : void 0;
|
|
653
|
-
const text = typeof query.text === "string" ? query.text : void 0;
|
|
654
|
-
const cursor = typeof query.cursor === "string" ? query.cursor : void 0;
|
|
655
|
-
const sortBy = isSortKey(query.sortBy) ? query.sortBy : void 0;
|
|
656
|
-
const sortDir = isSortDir(query.sortDir) ? query.sortDir : void 0;
|
|
657
|
-
const limit = parseLimit(query.limit);
|
|
658
|
-
const from = parseDateInput(query.from);
|
|
659
|
-
const to = parseDateInput(query.to);
|
|
660
|
-
return {
|
|
661
|
-
cursor,
|
|
662
|
-
methods,
|
|
663
|
-
path: path2,
|
|
664
|
-
status,
|
|
665
|
-
text,
|
|
666
|
-
limit,
|
|
667
|
-
from,
|
|
668
|
-
to,
|
|
669
|
-
sortBy,
|
|
670
|
-
sortDir
|
|
671
|
-
};
|
|
672
|
-
}
|
|
673
|
-
function parseLogWebhookQuery(req) {
|
|
674
|
-
const query = req.query || {};
|
|
675
|
-
const types = parseStringList(query.types);
|
|
676
|
-
const tags = parseStringList(query.tags);
|
|
677
|
-
const requestId = typeof query.requestId === "string" ? query.requestId : void 0;
|
|
678
|
-
const text = typeof query.text === "string" ? query.text : void 0;
|
|
679
|
-
const cursor = typeof query.cursor === "string" ? query.cursor : void 0;
|
|
680
|
-
const limit = parseLimit(query.limit);
|
|
681
|
-
const from = parseDateInput(query.from);
|
|
682
|
-
const to = parseDateInput(query.to);
|
|
683
|
-
const sortDir = isSortDir(query.sortDir) ? query.sortDir : void 0;
|
|
684
|
-
return {
|
|
685
|
-
cursor,
|
|
686
|
-
types,
|
|
687
|
-
tags,
|
|
688
|
-
requestId,
|
|
689
|
-
text,
|
|
690
|
-
limit,
|
|
691
|
-
from,
|
|
692
|
-
to,
|
|
693
|
-
sortDir
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
function parseStringList(value) {
|
|
697
|
-
if (typeof value !== "string") return void 0;
|
|
698
|
-
const parts = value.split(",").map((p) => p.trim()).filter(Boolean);
|
|
699
|
-
return parts.length ? parts : void 0;
|
|
700
|
-
}
|
|
701
|
-
function parseLimit(value) {
|
|
702
|
-
if (value === void 0) return void 0;
|
|
703
|
-
const num = Number(value);
|
|
704
|
-
if (!Number.isFinite(num) || num <= 0) return void 0;
|
|
705
|
-
return num;
|
|
706
|
-
}
|
|
707
|
-
function parseDateInput(value) {
|
|
708
|
-
if (typeof value !== "string") return void 0;
|
|
709
|
-
const numeric = Number(value);
|
|
710
|
-
if (Number.isFinite(numeric)) return numeric;
|
|
711
|
-
const timestamp = Date.parse(value);
|
|
712
|
-
if (Number.isNaN(timestamp)) return void 0;
|
|
713
|
-
return timestamp;
|
|
714
|
-
}
|
|
715
|
-
function isSortKey(value) {
|
|
716
|
-
return value === "timestamp" || value === "path" || value === "duration";
|
|
717
|
-
}
|
|
718
|
-
function isSortDir(value) {
|
|
719
|
-
return value === "asc" || value === "desc";
|
|
720
|
-
}
|
|
721
|
-
function normalizeWebhookPage(page) {
|
|
722
|
-
if (!page || typeof page !== "object") return { items: [] };
|
|
723
|
-
return {
|
|
724
|
-
items: Array.isArray(page.items) ? page.items : [],
|
|
725
|
-
nextCursor: page.nextCursor,
|
|
726
|
-
prevCursor: page.prevCursor,
|
|
727
|
-
total: page.total
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
function applyHistoryQuery(items, query, hardLimit) {
|
|
731
|
-
const fromTs = typeof query.from === "number" ? query.from : void 0;
|
|
732
|
-
const toTs = typeof query.to === "number" ? query.to : void 0;
|
|
733
|
-
const methods = query.methods ? new Set(query.methods.map((m) => m.toUpperCase())) : void 0;
|
|
734
|
-
const pathNeedle = (query.path || "").toLowerCase();
|
|
735
|
-
const textNeedle = (query.text || "").toLowerCase();
|
|
736
|
-
const statusNeedle = (query.status || "").trim();
|
|
737
|
-
const filtered = (Array.isArray(items) ? items : []).filter((entry) => {
|
|
738
|
-
if (methods?.size && !methods.has(String(entry.method || "").toUpperCase())) return false;
|
|
739
|
-
if (pathNeedle && !String(entry.path || "").toLowerCase().includes(pathNeedle)) return false;
|
|
740
|
-
if (statusNeedle) {
|
|
741
|
-
const statusStr = entry.status !== void 0 && entry.status !== null ? String(entry.status) : "ERR";
|
|
742
|
-
if (!statusStr.startsWith(statusNeedle)) return false;
|
|
743
|
-
}
|
|
744
|
-
if (Number.isFinite(fromTs) && entry.timestamp < fromTs) return false;
|
|
745
|
-
if (Number.isFinite(toTs) && entry.timestamp > toTs) return false;
|
|
746
|
-
if (textNeedle) {
|
|
747
|
-
const haystack = [
|
|
748
|
-
entry.path,
|
|
749
|
-
entry.fullUrl,
|
|
750
|
-
entry.body,
|
|
751
|
-
entry.output,
|
|
752
|
-
entry.error,
|
|
753
|
-
JSON.stringify(entry.params || {}),
|
|
754
|
-
JSON.stringify(entry.query || {})
|
|
755
|
-
].filter(Boolean).join(" ").toLowerCase();
|
|
756
|
-
if (!haystack.includes(textNeedle)) return false;
|
|
757
|
-
}
|
|
758
|
-
return true;
|
|
759
|
-
});
|
|
760
|
-
const sortBy = query.sortBy || "timestamp";
|
|
761
|
-
const direction = query.sortDir === "asc" ? 1 : -1;
|
|
762
|
-
const sorted = filtered.slice().sort((a, b) => {
|
|
763
|
-
let delta = 0;
|
|
764
|
-
if (sortBy === "path") {
|
|
765
|
-
delta = String(a.path || "").localeCompare(String(b.path || ""));
|
|
766
|
-
} else if (sortBy === "duration") {
|
|
767
|
-
delta = (a.durationMs || 0) - (b.durationMs || 0);
|
|
768
|
-
} else {
|
|
769
|
-
delta = (a.timestamp || 0) - (b.timestamp || 0);
|
|
770
|
-
}
|
|
771
|
-
return delta * direction;
|
|
772
|
-
});
|
|
773
|
-
return paginateItems(sorted, query.cursor, query.limit, hardLimit, 25);
|
|
774
|
-
}
|
|
775
|
-
function applyLogsQuery(items, query, hardLimit) {
|
|
776
|
-
const fromTs = typeof query.from === "number" ? query.from : void 0;
|
|
777
|
-
const toTs = typeof query.to === "number" ? query.to : void 0;
|
|
778
|
-
const textNeedle = (query.text || "").toLowerCase();
|
|
779
|
-
const requestIdNeedle = (query.requestId || "").toLowerCase();
|
|
780
|
-
const types = query.types ? new Set(query.types) : void 0;
|
|
781
|
-
const tags = query.tags ? new Set(query.tags) : void 0;
|
|
782
|
-
const filtered = (Array.isArray(items) ? items : []).filter((entry) => {
|
|
783
|
-
if (types?.size && !types.has(entry.type)) return false;
|
|
784
|
-
const entryTags = Array.isArray(entry.tags) ? entry.tags : [];
|
|
785
|
-
if (tags?.size && !entryTags.some((tag) => tags.has(tag))) return false;
|
|
786
|
-
if (requestIdNeedle && !(entry.requestId || "").toLowerCase().includes(requestIdNeedle))
|
|
787
|
-
return false;
|
|
788
|
-
if (Number.isFinite(fromTs) && entry.timestamp < fromTs) return false;
|
|
789
|
-
if (Number.isFinite(toTs) && entry.timestamp > toTs) return false;
|
|
790
|
-
if (textNeedle) {
|
|
791
|
-
const haystack = [
|
|
792
|
-
entry.message,
|
|
793
|
-
entry.requestId,
|
|
794
|
-
entryTags.join(" "),
|
|
795
|
-
typeof entry.metadata === "string" ? entry.metadata : JSON.stringify(entry.metadata || "")
|
|
796
|
-
].filter(Boolean).join(" ").toLowerCase();
|
|
797
|
-
if (!haystack.includes(textNeedle)) return false;
|
|
798
|
-
}
|
|
799
|
-
return true;
|
|
800
|
-
});
|
|
801
|
-
const direction = query.sortDir === "asc" ? 1 : -1;
|
|
802
|
-
const sorted = filtered.slice().sort((a, b) => (a.timestamp - b.timestamp) * direction);
|
|
803
|
-
return paginateItems(sorted, query.cursor, query.limit, hardLimit, 50);
|
|
804
|
-
}
|
|
805
|
-
function paginateItems(items, cursor, limit, hardLimit, fallbackLimit) {
|
|
806
|
-
const safeLimit = clampLimit(limit, hardLimit, fallbackLimit);
|
|
807
|
-
const start = parseCursor(cursor);
|
|
808
|
-
const end = start + safeLimit;
|
|
809
|
-
const slice = items.slice(start, end);
|
|
810
|
-
const nextCursor = end < items.length ? String(end) : void 0;
|
|
811
|
-
const prevCursor = start > 0 ? String(Math.max(start - safeLimit, 0)) : void 0;
|
|
812
|
-
return {
|
|
813
|
-
items: slice,
|
|
814
|
-
nextCursor,
|
|
815
|
-
prevCursor,
|
|
816
|
-
total: items.length
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
function clampLimit(value, hardLimit, fallback) {
|
|
820
|
-
if (!Number.isFinite(value)) return Math.min(hardLimit, fallback);
|
|
821
|
-
const safe = Math.max(1, Math.min(hardLimit, value));
|
|
822
|
-
return safe;
|
|
823
|
-
}
|
|
824
|
-
function parseCursor(cursor) {
|
|
825
|
-
const num = Number(cursor);
|
|
826
|
-
if (Number.isFinite(num) && num >= 0) return Math.floor(num);
|
|
827
|
-
return 0;
|
|
828
|
-
}
|
|
829
|
-
function normalizeHistorySeeds(seeds, hardLimit) {
|
|
830
|
-
if (!Array.isArray(seeds)) return [];
|
|
831
|
-
return seeds.slice(0, hardLimit).map((entry, idx) => ({
|
|
832
|
-
id: entry.id || (0, import_crypto.randomBytes)(8).toString("hex"),
|
|
833
|
-
requestId: typeof entry.requestId === "string" ? entry.requestId : void 0,
|
|
834
|
-
timestamp: entry.timestamp ?? Date.now() - idx * 1e3,
|
|
835
|
-
method: entry.method || "GET",
|
|
836
|
-
path: entry.path || "/",
|
|
837
|
-
fullUrl: entry.fullUrl || entry.path || "/",
|
|
838
|
-
params: entry.params || {},
|
|
839
|
-
query: entry.query || {},
|
|
840
|
-
body: entry.body || "",
|
|
841
|
-
output: entry.output || "",
|
|
842
|
-
status: entry.status,
|
|
843
|
-
durationMs: entry.durationMs ?? 0,
|
|
844
|
-
error: entry.error
|
|
845
|
-
})).filter((entry) => entry.method && entry.path);
|
|
846
|
-
}
|
|
847
|
-
function normalizeLogSeeds(seeds, hardLimit, redactor) {
|
|
848
|
-
if (!Array.isArray(seeds)) return [];
|
|
849
|
-
const normalized = seeds.slice(0, hardLimit).map((entry, idx) => ({
|
|
850
|
-
id: entry.id || (0, import_crypto.randomBytes)(8).toString("hex"),
|
|
851
|
-
type: entry.type || "info",
|
|
852
|
-
message: entry.message || "",
|
|
853
|
-
timestamp: entry.timestamp ?? Date.now() - idx * 1e3,
|
|
854
|
-
requestId: entry.requestId,
|
|
855
|
-
tags: Array.isArray(entry.tags) ? entry.tags : [],
|
|
856
|
-
metadata: entry.metadata
|
|
857
|
-
})).filter((entry) => entry.message);
|
|
858
|
-
return applyLogRedaction(normalized, redactor);
|
|
859
|
-
}
|
|
860
|
-
function coerceQueryRecord(query) {
|
|
861
|
-
if (!query || typeof query !== "object") return {};
|
|
862
|
-
return Object.fromEntries(
|
|
863
|
-
Object.entries(query).map(([key, value]) => [key, coerceValue(value)])
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
function coercePayload(body) {
|
|
867
|
-
if (body === void 0 || body === null) return "";
|
|
868
|
-
if (typeof body === "string") return body;
|
|
869
|
-
try {
|
|
870
|
-
return JSON.stringify(body);
|
|
871
|
-
} catch {
|
|
872
|
-
return String(body);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
function coerceValue(value) {
|
|
876
|
-
if (value === void 0 || value === null) return "";
|
|
877
|
-
if (Array.isArray(value)) return value.map(coerceValue).join(",");
|
|
878
|
-
if (typeof value === "object") {
|
|
879
|
-
try {
|
|
880
|
-
return JSON.stringify(value);
|
|
881
|
-
} catch {
|
|
882
|
-
return String(value);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
return String(value);
|
|
886
|
-
}
|
|
887
|
-
function createLogRedactor(redactor) {
|
|
888
|
-
if (!redactor) return (entry) => entry;
|
|
889
|
-
return (entry) => {
|
|
890
|
-
try {
|
|
891
|
-
return redactor(entry) ?? null;
|
|
892
|
-
} catch (err) {
|
|
893
|
-
console.error("Log redaction failed \u2013 dropping log entry", err);
|
|
894
|
-
return null;
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
function applyLogRedaction(entries, redactor) {
|
|
899
|
-
if (!Array.isArray(entries)) return [];
|
|
900
|
-
const next = [];
|
|
901
|
-
for (const entry of entries) {
|
|
902
|
-
const redacted = redactor(entry);
|
|
903
|
-
if (redacted) next.push(redacted);
|
|
904
|
-
}
|
|
905
|
-
return next;
|
|
906
|
-
}
|
|
907
|
-
function resolveDocsPassword(auth) {
|
|
908
|
-
if (auth?.password) return auth.password;
|
|
909
|
-
return void 0;
|
|
910
|
-
}
|
|
291
|
+
// src/web/utils/security.ts
|
|
292
|
+
var import_node_net = __toESM(require("net"), 1);
|
|
911
293
|
function createPasswordGuard(password, realm) {
|
|
912
294
|
const trimmed = password.trim();
|
|
913
295
|
return (req, res, next) => {
|
|
@@ -917,19 +299,40 @@ function createPasswordGuard(password, realm) {
|
|
|
917
299
|
}
|
|
918
300
|
applyDocsSecurityHeaders(res);
|
|
919
301
|
res.setHeader("WWW-Authenticate", `Basic realm="${realm}"`);
|
|
920
|
-
res.status(401).send(
|
|
302
|
+
res.status(401).send(
|
|
303
|
+
renderAuthErrorPage(
|
|
304
|
+
"Docs are password protected. Provide the configured password."
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function createCookieGuard(cookieName, cookieSecret) {
|
|
310
|
+
return (req, res, next) => {
|
|
311
|
+
const cookies = req.cookies;
|
|
312
|
+
const value = cookies?.[cookieName];
|
|
313
|
+
const valid = cookieSecret ? value === cookieSecret : Boolean(value);
|
|
314
|
+
if (valid) {
|
|
315
|
+
return next();
|
|
316
|
+
}
|
|
317
|
+
applyDocsSecurityHeaders(res);
|
|
318
|
+
res.status(401).send(
|
|
319
|
+
renderAuthErrorPage(
|
|
320
|
+
"Docs are protected. You must be authenticated to access this page."
|
|
321
|
+
)
|
|
322
|
+
);
|
|
921
323
|
};
|
|
922
324
|
}
|
|
923
325
|
function createMissingPasswordGuard() {
|
|
924
326
|
return (_req, res) => {
|
|
925
327
|
applyDocsSecurityHeaders(res);
|
|
926
|
-
res.status(500).send(renderAuthErrorPage("Provide
|
|
328
|
+
res.status(500).send(renderAuthErrorPage("Provide auth configuration to mounted docs"));
|
|
927
329
|
};
|
|
928
330
|
}
|
|
929
331
|
function extractPassword(authHeader) {
|
|
930
332
|
if (!authHeader) return void 0;
|
|
931
333
|
const header = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
932
|
-
if (typeof header !== "string" || !header.startsWith("Basic "))
|
|
334
|
+
if (typeof header !== "string" || !header.startsWith("Basic "))
|
|
335
|
+
return void 0;
|
|
933
336
|
const token = header.slice("Basic ".length);
|
|
934
337
|
try {
|
|
935
338
|
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
@@ -940,6 +343,64 @@ function extractPassword(authHeader) {
|
|
|
940
343
|
return void 0;
|
|
941
344
|
}
|
|
942
345
|
}
|
|
346
|
+
function createIpAllowListGuard(allowed) {
|
|
347
|
+
const ranges = allowed.map((raw) => raw.trim()).filter(Boolean).map(parseIpPattern).filter((r) => r !== null);
|
|
348
|
+
return (req, res, next) => {
|
|
349
|
+
const rawIp = req.ip || req.connection && req.connection.remoteAddress || "";
|
|
350
|
+
const ip = normalizeIp(rawIp);
|
|
351
|
+
if (!ip || !isIpAllowed(ip, ranges)) {
|
|
352
|
+
applyDocsSecurityHeaders(res);
|
|
353
|
+
res.status(403).send(
|
|
354
|
+
renderAuthErrorPage(
|
|
355
|
+
"Access to docs is restricted from this IP address."
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
next();
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function normalizeIp(ip) {
|
|
364
|
+
if (!ip) return "";
|
|
365
|
+
if (ip.startsWith("::ffff:")) return ip.slice(7);
|
|
366
|
+
if (ip === "::1") return "127.0.0.1";
|
|
367
|
+
return ip;
|
|
368
|
+
}
|
|
369
|
+
function parseIpPattern(raw) {
|
|
370
|
+
if (raw.includes("/")) {
|
|
371
|
+
const cidr = parseCidr(raw);
|
|
372
|
+
if (!cidr) return null;
|
|
373
|
+
return { kind: "cidr", base: cidr.base, mask: cidr.mask };
|
|
374
|
+
}
|
|
375
|
+
return { kind: "exact", value: normalizeIp(raw) };
|
|
376
|
+
}
|
|
377
|
+
function parseCidr(raw) {
|
|
378
|
+
const [baseIp, bitsStr] = raw.split("/");
|
|
379
|
+
const bits = Number(bitsStr);
|
|
380
|
+
if (!Number.isInteger(bits) || bits < 0 || bits > 32) return null;
|
|
381
|
+
if (import_node_net.default.isIP(baseIp) !== 4) return null;
|
|
382
|
+
const baseLong = ipToLong(baseIp);
|
|
383
|
+
if (baseLong == null) return null;
|
|
384
|
+
const mask = bits === 0 ? 0 : ~0 << 32 - bits >>> 0;
|
|
385
|
+
return { base: (baseLong & mask) >>> 0, mask };
|
|
386
|
+
}
|
|
387
|
+
function ipToLong(ip) {
|
|
388
|
+
const parts = ip.split(".").map((n) => Number(n));
|
|
389
|
+
if (parts.length !== 4) return null;
|
|
390
|
+
if (parts.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return null;
|
|
391
|
+
return (parts[0] << 24 >>> 0) + (parts[1] << 16 >>> 0) + (parts[2] << 8 >>> 0) + parts[3];
|
|
392
|
+
}
|
|
393
|
+
function isIpAllowed(ip, ranges) {
|
|
394
|
+
const ipv4 = import_node_net.default.isIP(ip) === 4 ? ipToLong(ip) : null;
|
|
395
|
+
for (const r of ranges) {
|
|
396
|
+
if (r.kind === "exact") {
|
|
397
|
+
if (ip === r.value) return true;
|
|
398
|
+
} else if (r.kind === "cidr" && ipv4 != null) {
|
|
399
|
+
if ((ipv4 & r.mask) === r.base) return true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
943
404
|
function renderAuthErrorPage(message) {
|
|
944
405
|
return `<!DOCTYPE html>
|
|
945
406
|
<html lang="en">
|
|
@@ -968,11 +429,337 @@ function applyDocsSecurityHeaders(res) {
|
|
|
968
429
|
res.setHeader("Referrer-Policy", "same-origin");
|
|
969
430
|
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
|
970
431
|
res.setHeader("Cache-Control", "no-store");
|
|
432
|
+
res.setHeader(
|
|
433
|
+
"Strict-Transport-Security",
|
|
434
|
+
"max-age=31536000; includeSubDomains"
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/web/utils/types.ts
|
|
439
|
+
var import_rrroutes_contract7 = require("@emeryld/rrroutes-contract");
|
|
440
|
+
|
|
441
|
+
// src/web/v2/types/types.cacheLog.ts
|
|
442
|
+
var import_rrroutes_contract2 = require("@emeryld/rrroutes-contract");
|
|
443
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
444
|
+
|
|
445
|
+
// src/web/v2/types/types.base.ts
|
|
446
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
447
|
+
var METHODS = ["get", "post", "put", "patch", "delete"];
|
|
448
|
+
var baseEntitySchema = import_zod.default.object({
|
|
449
|
+
id: import_zod.default.string(),
|
|
450
|
+
name: import_zod.default.string(),
|
|
451
|
+
description: import_zod.default.string().optional(),
|
|
452
|
+
groupId: import_zod.default.string().optional(),
|
|
453
|
+
tags: import_zod.default.string().array().optional(),
|
|
454
|
+
createdAt: import_zod.default.number(),
|
|
455
|
+
updatedAt: import_zod.default.number()
|
|
456
|
+
});
|
|
457
|
+
var baseQuerySchema = import_zod.default.object({
|
|
458
|
+
beforeDate: import_zod.default.string().optional(),
|
|
459
|
+
afterDate: import_zod.default.string().optional(),
|
|
460
|
+
orderBy: import_zod.default.enum(["timestamp", "duration", "level", "path"]).default("timestamp"),
|
|
461
|
+
orderDirection: import_zod.default.enum(["asc", "desc"]).default("desc"),
|
|
462
|
+
searchQuery: import_zod.default.string().optional(),
|
|
463
|
+
groups: import_zod.default.string().array().optional(),
|
|
464
|
+
tags: import_zod.default.string().array().optional(),
|
|
465
|
+
cursor: import_zod.default.string().optional()
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// src/web/v2/types/types.cacheLog.ts
|
|
469
|
+
var operationEnum = import_zod2.default.enum(["hit", "miss", "set", "delete"]);
|
|
470
|
+
var cacheLogSchema = baseEntitySchema.extend({
|
|
471
|
+
operation: operationEnum,
|
|
472
|
+
// on hit, value = value retrieved
|
|
473
|
+
// on miss, value = null
|
|
474
|
+
// on set, value = value set
|
|
475
|
+
// on delete, value = value deleted
|
|
476
|
+
value: import_zod2.default.any().nullable(),
|
|
477
|
+
size: import_zod2.default.number().optional()
|
|
478
|
+
});
|
|
479
|
+
var cacheLogQuerySchema = baseQuerySchema.extend({
|
|
480
|
+
operations: operationEnum.array().optional()
|
|
481
|
+
});
|
|
482
|
+
var cacheLeaves = (0, import_rrroutes_contract2.resource)("cache").get({
|
|
483
|
+
feed: true,
|
|
484
|
+
outputSchema: cacheLogSchema.array(),
|
|
485
|
+
querySchema: cacheLogQuerySchema,
|
|
486
|
+
outputMetaSchema: import_zod2.default.object({
|
|
487
|
+
totalCount: import_zod2.default.number().optional()
|
|
488
|
+
})
|
|
489
|
+
}).post({
|
|
490
|
+
querySchema: cacheLogQuerySchema
|
|
491
|
+
}).done();
|
|
492
|
+
|
|
493
|
+
// src/web/v2/types/types.endpoint.ts
|
|
494
|
+
var import_rrroutes_contract5 = require("@emeryld/rrroutes-contract");
|
|
495
|
+
var import_zod5 = __toESM(require("zod"), 1);
|
|
496
|
+
|
|
497
|
+
// src/web/v2/types/types.requestLog.ts
|
|
498
|
+
var import_rrroutes_contract4 = require("@emeryld/rrroutes-contract");
|
|
499
|
+
var import_zod4 = __toESM(require("zod"), 1);
|
|
500
|
+
|
|
501
|
+
// src/web/v2/types/types.log.ts
|
|
502
|
+
var import_rrroutes_contract3 = require("@emeryld/rrroutes-contract");
|
|
503
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
504
|
+
var levelSchema = import_zod3.default.enum(["info", "warning", "error", "debug", "trace"]);
|
|
505
|
+
var logSchema = baseEntitySchema.extend({
|
|
506
|
+
level: levelSchema,
|
|
507
|
+
meta: import_zod3.default.json()
|
|
508
|
+
});
|
|
509
|
+
var logQuerySchema = baseQuerySchema.extend({
|
|
510
|
+
level: levelSchema.array().optional()
|
|
511
|
+
});
|
|
512
|
+
var logLeaves = (0, import_rrroutes_contract3.resource)("logs").get({
|
|
513
|
+
feed: true,
|
|
514
|
+
outputSchema: logSchema.array(),
|
|
515
|
+
querySchema: logQuerySchema,
|
|
516
|
+
outputMetaSchema: import_zod3.default.object({
|
|
517
|
+
totalCount: import_zod3.default.number().optional()
|
|
518
|
+
})
|
|
519
|
+
}).done();
|
|
520
|
+
|
|
521
|
+
// src/web/v2/types/types.requestLog.ts
|
|
522
|
+
var requestSchema = baseEntitySchema.extend({
|
|
523
|
+
status: import_zod4.default.number(),
|
|
524
|
+
body: import_zod4.default.any().optional(),
|
|
525
|
+
fullUrl: import_zod4.default.string(),
|
|
526
|
+
path: import_zod4.default.string(),
|
|
527
|
+
method: import_zod4.default.enum(METHODS),
|
|
528
|
+
query: import_zod4.default.record(import_zod4.default.string(), import_zod4.default.any()).optional(),
|
|
529
|
+
params: import_zod4.default.record(import_zod4.default.string(), import_zod4.default.any()).optional(),
|
|
530
|
+
output: import_zod4.default.any().optional(),
|
|
531
|
+
headers: import_zod4.default.record(import_zod4.default.string(), import_zod4.default.any()).optional(),
|
|
532
|
+
error: import_zod4.default.string().optional(),
|
|
533
|
+
durationMs: import_zod4.default.number()
|
|
534
|
+
});
|
|
535
|
+
var requestQuerySchema = baseQuerySchema.extend({
|
|
536
|
+
methods: import_zod4.default.enum(METHODS).array().default([]),
|
|
537
|
+
statuses: import_zod4.default.number().array().default([]),
|
|
538
|
+
path: import_zod4.default.string().optional()
|
|
539
|
+
});
|
|
540
|
+
var requestLogLeaves = (0, import_rrroutes_contract4.resource)("requests").get({
|
|
541
|
+
feed: true,
|
|
542
|
+
outputSchema: requestSchema.array(),
|
|
543
|
+
querySchema: requestQuerySchema,
|
|
544
|
+
outputMetaSchema: import_zod4.default.object({
|
|
545
|
+
totalCount: import_zod4.default.number().optional()
|
|
546
|
+
})
|
|
547
|
+
}).sub(
|
|
548
|
+
(0, import_rrroutes_contract4.resource)(":requestId", void 0, import_zod4.default.string()).get({
|
|
549
|
+
outputSchema: requestSchema.extend({
|
|
550
|
+
// Related by groupId
|
|
551
|
+
// Do I just use the existing feed endpoints with filter: groupId=?
|
|
552
|
+
logs: import_zod4.default.array(logSchema),
|
|
553
|
+
caches: import_zod4.default.array(cacheLogSchema)
|
|
554
|
+
})
|
|
555
|
+
}).done()
|
|
556
|
+
).done();
|
|
557
|
+
|
|
558
|
+
// src/web/v2/types/types.endpoint.ts
|
|
559
|
+
var nodeKind = [
|
|
560
|
+
"object",
|
|
561
|
+
"string",
|
|
562
|
+
"number",
|
|
563
|
+
"array",
|
|
564
|
+
"enum",
|
|
565
|
+
"literal",
|
|
566
|
+
"union"
|
|
567
|
+
];
|
|
568
|
+
var serializableSchemaSchema = import_zod5.default.lazy(
|
|
569
|
+
() => import_zod5.default.object({
|
|
570
|
+
kind: import_zod5.default.enum(nodeKind),
|
|
571
|
+
optional: import_zod5.default.boolean().optional(),
|
|
572
|
+
nullable: import_zod5.default.boolean().optional(),
|
|
573
|
+
description: import_zod5.default.string().optional(),
|
|
574
|
+
// object
|
|
575
|
+
properties: import_zod5.default.record(import_zod5.default.string(), serializableSchemaSchema).optional(),
|
|
576
|
+
// array
|
|
577
|
+
element: serializableSchemaSchema.optional(),
|
|
578
|
+
// union
|
|
579
|
+
union: import_zod5.default.array(serializableSchemaSchema).optional(),
|
|
580
|
+
// literal
|
|
581
|
+
literal: import_zod5.default.unknown().optional(),
|
|
582
|
+
// enum
|
|
583
|
+
enumValues: import_zod5.default.array(import_zod5.default.string()).optional()
|
|
584
|
+
})
|
|
585
|
+
);
|
|
586
|
+
var STABILITIES = [
|
|
587
|
+
"experimental",
|
|
588
|
+
"beta",
|
|
589
|
+
"stable",
|
|
590
|
+
"deprecated"
|
|
591
|
+
];
|
|
592
|
+
var stabilityEnum = import_zod5.default.enum(STABILITIES);
|
|
593
|
+
var endpointSchema = baseEntitySchema.extend({
|
|
594
|
+
method: import_zod5.default.enum(METHODS),
|
|
595
|
+
path: import_zod5.default.string(),
|
|
596
|
+
contract: import_zod5.default.object({
|
|
597
|
+
body: serializableSchemaSchema.optional(),
|
|
598
|
+
query: serializableSchemaSchema.optional(),
|
|
599
|
+
output: serializableSchemaSchema.optional(),
|
|
600
|
+
params: serializableSchemaSchema.optional(),
|
|
601
|
+
bodyFiles: import_zod5.default.object({ name: import_zod5.default.string(), maxCount: import_zod5.default.number() })
|
|
602
|
+
}),
|
|
603
|
+
feed: import_zod5.default.boolean().optional(),
|
|
604
|
+
summary: import_zod5.default.string().optional(),
|
|
605
|
+
stability: stabilityEnum,
|
|
606
|
+
hidden: import_zod5.default.boolean().optional(),
|
|
607
|
+
meta: import_zod5.default.record(import_zod5.default.string(), import_zod5.default.string())
|
|
608
|
+
});
|
|
609
|
+
var endpointFilterSchema = baseQuerySchema.extend({
|
|
610
|
+
methods: import_zod5.default.enum(METHODS).array().optional(),
|
|
611
|
+
path: import_zod5.default.string().optional(),
|
|
612
|
+
stability: stabilityEnum.array().optional()
|
|
613
|
+
});
|
|
614
|
+
var endpointLeaves = (0, import_rrroutes_contract5.resource)("endpoints").get({
|
|
615
|
+
feed: true,
|
|
616
|
+
querySchema: endpointFilterSchema,
|
|
617
|
+
outputSchema: endpointSchema.array(),
|
|
618
|
+
outputMetaSchema: import_zod5.default.object({
|
|
619
|
+
totalCount: import_zod5.default.number().optional()
|
|
620
|
+
})
|
|
621
|
+
}).sub(
|
|
622
|
+
(0, import_rrroutes_contract5.resource)(":endpointId", void 0, import_zod5.default.string()).get({
|
|
623
|
+
outputSchema: endpointSchema.extend({
|
|
624
|
+
// Related by groupId. Just use the existing feed endpoints with filter: groupId=?
|
|
625
|
+
requests: import_zod5.default.array(requestSchema),
|
|
626
|
+
// Summary stats: return with the feed?
|
|
627
|
+
volumeTS: import_zod5.default.array(
|
|
628
|
+
import_zod5.default.object({
|
|
629
|
+
timestamp: import_zod5.default.string(),
|
|
630
|
+
count: import_zod5.default.number()
|
|
631
|
+
})
|
|
632
|
+
),
|
|
633
|
+
averageDurationMs: import_zod5.default.number(),
|
|
634
|
+
successRate: import_zod5.default.number(),
|
|
635
|
+
// Add id as query param to the existing feed endpoints? This way "requests" field can also be only Ids
|
|
636
|
+
latestErrorRequestIds: import_zod5.default.array(import_zod5.default.string())
|
|
637
|
+
})
|
|
638
|
+
}).done()
|
|
639
|
+
).done();
|
|
640
|
+
|
|
641
|
+
// src/web/v2/types/types.preset.ts
|
|
642
|
+
var import_rrroutes_contract6 = require("@emeryld/rrroutes-contract");
|
|
643
|
+
var import_zod6 = __toESM(require("zod"), 1);
|
|
644
|
+
var presetSchema = baseEntitySchema.extend({
|
|
645
|
+
operations: import_zod6.default.array(
|
|
646
|
+
import_zod6.default.object({
|
|
647
|
+
endpointId: import_zod6.default.string().optional(),
|
|
648
|
+
method: import_zod6.default.enum(METHODS),
|
|
649
|
+
path: import_zod6.default.string(),
|
|
650
|
+
body: import_zod6.default.json().optional(),
|
|
651
|
+
extraHeaders: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.any()).optional(),
|
|
652
|
+
query: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.any()).optional()
|
|
653
|
+
})
|
|
654
|
+
)
|
|
655
|
+
});
|
|
656
|
+
var presetQuerySchema = baseQuerySchema.extend({
|
|
657
|
+
name: import_zod6.default.string().optional(),
|
|
658
|
+
tags: import_zod6.default.string().array().optional(),
|
|
659
|
+
group: import_zod6.default.string().optional()
|
|
660
|
+
});
|
|
661
|
+
var presetLeaves = (0, import_rrroutes_contract6.resource)("presets").get({
|
|
662
|
+
feed: true,
|
|
663
|
+
querySchema: presetQuerySchema.array(),
|
|
664
|
+
outputMetaSchema: import_zod6.default.object({
|
|
665
|
+
totalCount: import_zod6.default.number().optional()
|
|
666
|
+
}),
|
|
667
|
+
outputSchema: presetSchema
|
|
668
|
+
}).post({
|
|
669
|
+
bodySchema: presetSchema,
|
|
670
|
+
outputSchema: presetSchema
|
|
671
|
+
}).put({
|
|
672
|
+
bodySchema: presetSchema,
|
|
673
|
+
outputSchema: presetSchema
|
|
674
|
+
}).done();
|
|
675
|
+
|
|
676
|
+
// src/web/utils/types.ts
|
|
677
|
+
var allLeaves = (0, import_rrroutes_contract7.resource)().sub(
|
|
678
|
+
(0, import_rrroutes_contract7.resource)("___rrroutes").sub(
|
|
679
|
+
endpointLeaves,
|
|
680
|
+
requestLogLeaves,
|
|
681
|
+
logLeaves,
|
|
682
|
+
cacheLeaves,
|
|
683
|
+
presetLeaves
|
|
684
|
+
).done()
|
|
685
|
+
).done();
|
|
686
|
+
var leaves = (0, import_rrroutes_contract7.finalize)(allLeaves);
|
|
687
|
+
|
|
688
|
+
// src/index.ts
|
|
689
|
+
function resolvePublicDir() {
|
|
690
|
+
const moduleDir = typeof __dirname !== "undefined" ? __dirname : import_node_path.default.dirname((0, import_node_url.fileURLToPath)(__import_meta_url));
|
|
691
|
+
const fromModule = import_node_path.default.resolve(moduleDir, "../public");
|
|
692
|
+
if (import_node_fs.default.existsSync(fromModule)) return fromModule;
|
|
693
|
+
const fallback = import_node_path.default.resolve(moduleDir, "../dist/public");
|
|
694
|
+
if (import_node_fs.default.existsSync(fallback)) return fallback;
|
|
695
|
+
return fromModule;
|
|
696
|
+
}
|
|
697
|
+
function mountRRRoutesDocs({
|
|
698
|
+
router,
|
|
699
|
+
leaves: leaves2,
|
|
700
|
+
auth = {}
|
|
701
|
+
}) {
|
|
702
|
+
const docsPath = "/__rrroutes/docs";
|
|
703
|
+
const publicDir = resolvePublicDir();
|
|
704
|
+
const assetsDir = import_node_path.default.join(publicDir, "assets");
|
|
705
|
+
const cspEnabled = auth.csp !== false;
|
|
706
|
+
const authEnabled = auth.enabled !== false;
|
|
707
|
+
const docsPassword = auth.password;
|
|
708
|
+
const authRealm = auth.realm || "RRRoutes Docs";
|
|
709
|
+
const allowedIps = auth.allowedIps ?? [];
|
|
710
|
+
const cookieName = auth.cookieName;
|
|
711
|
+
const cookieSecret = auth?.cookieSecret;
|
|
712
|
+
const customGuard = auth?.guardMiddleware;
|
|
713
|
+
const ipGuard = allowedIps.length > 0 ? createIpAllowListGuard(allowedIps) : void 0;
|
|
714
|
+
const authGuard = !authEnabled ? (_req, _res, next) => next() : customGuard ? customGuard : cookieName ? createCookieGuard(cookieName, cookieSecret) : docsPassword ? createPasswordGuard(docsPassword, authRealm) : createMissingPasswordGuard();
|
|
715
|
+
[docsPath, `${docsPath}/assets`, `__rrroutes/`].forEach((p) => {
|
|
716
|
+
if (ipGuard) router.use(p, ipGuard);
|
|
717
|
+
router.use(p, authGuard);
|
|
718
|
+
});
|
|
719
|
+
router.use(
|
|
720
|
+
`${docsPath}/assets`,
|
|
721
|
+
(0, import_express.static)(assetsDir, { immutable: true, maxAge: "365d" })
|
|
722
|
+
);
|
|
723
|
+
const docsRoutePaths = [docsPath, `${docsPath}/`, `${docsPath}/*id`];
|
|
724
|
+
router.get(docsRoutePaths, (_req, res) => {
|
|
725
|
+
const nonce = cspEnabled ? (0, import_crypto.randomBytes)(16).toString("base64") : void 0;
|
|
726
|
+
const html = renderLeafDocsHTML2(
|
|
727
|
+
leaves2.filter((leaf) => leaf.cfg.docsHidden !== true),
|
|
728
|
+
{
|
|
729
|
+
cspNonce: nonce,
|
|
730
|
+
assetBasePath: `${`${docsPath}/assets`}`,
|
|
731
|
+
docsBasePath: `${docsPath}`
|
|
732
|
+
}
|
|
733
|
+
);
|
|
734
|
+
applyDocsSecurityHeaders(res);
|
|
735
|
+
if (cspEnabled && nonce) {
|
|
736
|
+
res.setHeader(
|
|
737
|
+
"Content-Security-Policy",
|
|
738
|
+
[
|
|
739
|
+
"default-src 'self'",
|
|
740
|
+
`script-src 'self' 'nonce-${nonce}'`,
|
|
741
|
+
`style-src 'self' 'nonce-${nonce}'`,
|
|
742
|
+
"img-src 'self' data:",
|
|
743
|
+
"connect-src 'self'",
|
|
744
|
+
"font-src 'self'",
|
|
745
|
+
"frame-ancestors 'self'",
|
|
746
|
+
"object-src 'none'",
|
|
747
|
+
"base-uri 'self'"
|
|
748
|
+
].join("; ")
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
res.send(html);
|
|
752
|
+
});
|
|
753
|
+
return {
|
|
754
|
+
path: docsPath
|
|
755
|
+
};
|
|
971
756
|
}
|
|
972
757
|
// Annotate the CommonJS export names for ESM import in node:
|
|
973
758
|
0 && (module.exports = {
|
|
759
|
+
introspectSchema,
|
|
974
760
|
mountRRRoutesDocs,
|
|
975
761
|
renderLeafDocsHTML,
|
|
762
|
+
requiredRoutes,
|
|
976
763
|
serializeLeaf
|
|
977
764
|
});
|
|
978
765
|
//# sourceMappingURL=index.cjs.map
|