Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,9 +1,13 @@
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { parseEnabledLocales } from "@hivegrid/i18n";
|
||||
import { Hono, type Context } from "hono";
|
||||
import { getApiAppDependencies } from "../app-dependencies.js";
|
||||
import type { ApiEnv } from "../api-types.js";
|
||||
import { getApiRuntimeConfig } from "../config.js";
|
||||
import { createOpenApiDocument } from "../openapi.js";
|
||||
import { apiLogger } from "../logger.js";
|
||||
import { escapeHtml } from "./shared.js";
|
||||
import { checkCachedApiReadiness } from "../readiness-cache.js";
|
||||
import { getApiDocsCopy } from "./api-docs-i18n.js";
|
||||
|
||||
function apiHealthResponse(c: Context<ApiEnv>) {
|
||||
return c.json({
|
||||
@@ -20,14 +24,19 @@ export function registerSystemRoutes(app: Hono<ApiEnv>) {
|
||||
|
||||
app.get("/readyz", async (c) => {
|
||||
try {
|
||||
await getApiAppDependencies().checkReadiness();
|
||||
await checkCachedApiReadiness();
|
||||
return c.json({
|
||||
status: "ready",
|
||||
service: "api",
|
||||
revision: getApiRuntimeConfig().revision,
|
||||
requestId: c.get("requestId"),
|
||||
});
|
||||
} catch {
|
||||
} catch (error) {
|
||||
const code = error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
||||
apiLogger.error(
|
||||
{ dependency: "database", error: { name: error instanceof Error ? error.name : "Error", ...(code ? { code } : {}) } },
|
||||
"API readiness dependency unavailable"
|
||||
);
|
||||
return c.json(
|
||||
{
|
||||
status: "not_ready",
|
||||
@@ -48,16 +57,41 @@ export function registerSystemRoutes(app: Hono<ApiEnv>) {
|
||||
});
|
||||
|
||||
app.get("/v1/docs", (c) => {
|
||||
const appName = getApiRuntimeConfig().appName;
|
||||
const runtimeConfig = getApiRuntimeConfig();
|
||||
const appName = runtimeConfig.appName;
|
||||
const enabledLocales = parseEnabledLocales(process.env.I18N_ENABLED_LOCALES, {
|
||||
allowReviewLocales: runtimeConfig.nodeEnv !== "production" || process.env.SENTRY_ENVIRONMENT?.trim().toLowerCase() === "staging",
|
||||
});
|
||||
const { locale, copy } = getApiDocsCopy(c.req.header("accept-language"), enabledLocales);
|
||||
const browserCopy = JSON.stringify(copy).replaceAll("<", "\\u003c");
|
||||
const nonce = randomBytes(18).toString("base64url");
|
||||
c.header("cache-control", "no-store");
|
||||
c.header("content-language", locale);
|
||||
c.header(
|
||||
"content-security-policy",
|
||||
[
|
||||
"default-src 'none'",
|
||||
"base-uri 'none'",
|
||||
"connect-src 'self'",
|
||||
"font-src 'self'",
|
||||
"form-action 'none'",
|
||||
"frame-ancestors 'none'",
|
||||
"img-src 'self' data:",
|
||||
`script-src 'nonce-${nonce}' 'strict-dynamic'`,
|
||||
"script-src-attr 'none'",
|
||||
`style-src 'nonce-${nonce}'`,
|
||||
"style-src-attr 'none'",
|
||||
].join("; ")
|
||||
);
|
||||
|
||||
return c.html(`<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="${locale}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>API Documentation | ${escapeHtml(appName)}</title>
|
||||
<meta property="og:title" content="API Documentation | ${escapeHtml(appName)}">
|
||||
<title>${escapeHtml(copy.pageTitle)} | ${escapeHtml(appName)}</title>
|
||||
<meta property="og:title" content="${escapeHtml(copy.pageTitle)} | ${escapeHtml(appName)}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
<style nonce="${nonce}">
|
||||
:root { color-scheme: dark; }
|
||||
body { margin: 0; background: #0f172a; color: #e2e8f0; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
||||
header { border-bottom: 1px solid #334155; padding: 20px 24px; }
|
||||
@@ -89,25 +123,26 @@ export function registerSystemRoutes(app: Hono<ApiEnv>) {
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>API Documentation</h1>
|
||||
<h1>${escapeHtml(copy.heading)}</h1>
|
||||
<div class="toolbar">
|
||||
<span class="muted">Swagger-style OpenAPI 3.1 explorer for the canonical API host.</span>
|
||||
<span class="muted">${escapeHtml(copy.description)}</span>
|
||||
<a href="/v1/openapi.json">OpenAPI JSON</a>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<nav class="nav" id="operation-nav" aria-label="API operations">
|
||||
<span class="muted">Loading /v1/openapi.json...</span>
|
||||
<nav class="nav" id="operation-nav" aria-label="${escapeHtml(copy.operationsLabel)}">
|
||||
<span class="muted">${escapeHtml(copy.loadingSpec)}</span>
|
||||
</nav>
|
||||
<section>
|
||||
<div id="operation-detail" class="operation"></div>
|
||||
<details id="raw-panel">
|
||||
<summary>Raw OpenAPI JSON</summary>
|
||||
<summary>${escapeHtml(copy.rawSpec)}</summary>
|
||||
<pre id="openapi-json"></pre>
|
||||
</details>
|
||||
</section>
|
||||
</main>
|
||||
<script>
|
||||
<script nonce="${nonce}">
|
||||
const copy = ${browserCopy};
|
||||
const nav = document.getElementById("operation-nav");
|
||||
const detail = document.getElementById("operation-detail");
|
||||
const raw = document.getElementById("openapi-json");
|
||||
@@ -154,19 +189,19 @@ export function registerSystemRoutes(app: Hono<ApiEnv>) {
|
||||
const responses = Object.entries(entry.operation.responses ?? {});
|
||||
detail.innerHTML = '<div class="operation-header"><span class="method">' + escapeText(entry.method) + '</span><span class="path">' + escapeText(entry.path) + '</span></div>'
|
||||
+ '<div class="section grid">'
|
||||
+ '<span class="badge">' + escapeText(entry.operation.operationId ?? "operation") + '</span>'
|
||||
+ '<p>' + escapeText(entry.operation.description ?? "No description.") + '</p>'
|
||||
+ '<h2>Parameters</h2>'
|
||||
+ (parameters.length ? parameters.map((parameter) => '<div class="row"><code>' + escapeText(parameter.in) + ' ' + escapeText(parameter.name) + '</code><span>' + escapeText(parameter.description ?? "") + '</span></div>').join("") : '<p class="muted">No parameters.</p>')
|
||||
+ '<h2>Responses</h2>'
|
||||
+ (responses.length ? responses.map(([status, response]) => '<div class="row"><code>' + escapeText(status) + '</code><span>' + escapeText(response.description ?? "") + '</span></div>').join("") : '<p class="muted">No documented responses.</p>')
|
||||
+ '<h2>Try request</h2>'
|
||||
+ '<span class="badge">' + escapeText(entry.operation.operationId ?? copy.operationFallback) + '</span>'
|
||||
+ '<p>' + escapeText(entry.operation.description ?? copy.noDescription) + '</p>'
|
||||
+ '<h2>' + escapeText(copy.parameters) + '</h2>'
|
||||
+ (parameters.length ? parameters.map((parameter) => '<div class="row"><code>' + escapeText(parameter.in) + ' ' + escapeText(parameter.name) + '</code><span>' + escapeText(parameter.description ?? "") + '</span></div>').join("") : '<p class="muted">' + escapeText(copy.noParameters) + '</p>')
|
||||
+ '<h2>' + escapeText(copy.responses) + '</h2>'
|
||||
+ (responses.length ? responses.map(([status, response]) => '<div class="row"><code>' + escapeText(status) + '</code><span>' + escapeText(response.description ?? "") + '</span></div>').join("") : '<p class="muted">' + escapeText(copy.noResponses) + '</p>')
|
||||
+ '<h2>' + escapeText(copy.tryRequest) + '</h2>'
|
||||
+ '<div class="try-grid">'
|
||||
+ '<label>x-api-key<input id="try-api-key" type="password" autocomplete="off" placeholder="Paste tenant API key"></label>'
|
||||
+ '<label>Query string<input id="try-query" type="text" placeholder="limit=10&fields=id,name"></label>'
|
||||
+ '<button id="try-button" type="button">Send request</button>'
|
||||
+ '<label>' + escapeText(copy.apiKeyLabel) + '<input id="try-api-key" type="password" autocomplete="off" placeholder="' + escapeText(copy.apiKeyPlaceholder) + '"></label>'
|
||||
+ '<label>' + escapeText(copy.queryLabel) + '<input id="try-query" type="text" placeholder="' + escapeText(copy.queryPlaceholder) + '"></label>'
|
||||
+ '<button id="try-button" type="button">' + escapeText(copy.sendRequest) + '</button>'
|
||||
+ '</div>'
|
||||
+ '<pre id="try-result" aria-live="polite">Response appears here.</pre>'
|
||||
+ '<pre id="try-result" aria-live="polite">' + escapeText(copy.responsePlaceholder) + '</pre>'
|
||||
+ '</div>';
|
||||
document.getElementById("try-button")?.addEventListener("click", sendTryRequest);
|
||||
}
|
||||
@@ -185,7 +220,7 @@ export function registerSystemRoutes(app: Hono<ApiEnv>) {
|
||||
}
|
||||
const result = document.getElementById("try-result");
|
||||
const apiKey = document.getElementById("try-api-key")?.value.trim() ?? "";
|
||||
result.textContent = "Loading...";
|
||||
result.textContent = copy.loading;
|
||||
fetch(buildTryRequestUrl(currentEntry), {
|
||||
method: currentEntry.method,
|
||||
headers: apiKey ? { "x-api-key": apiKey } : {},
|
||||
|
||||
Reference in new issue
Block a user