(() => {
"use strict";
const list = document.querySelector("#endpoint-list");
const template = document.querySelector("#endpoint-template");
const search = document.querySelector("#search");
const filters = document.querySelector("#service-filters");
const count = document.querySelector("#endpoint-count");
const empty = document.querySelector("#empty");
const sidebar = document.querySelector("#sidebar");
const menu = document.querySelector("#menu");
let manifest;
let activeService = "all";
const escapeHtml = (value) => String(value)
.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
function curlFor(service, endpoint) {
const url = `${service.base_url}${endpoint.path.replaceAll(/{([^}]+)}/g, "<$1>")}`;
const lines = [`curl -X ${endpoint.method} '${url}'`];
if (endpoint.auth === "bearer" || endpoint.auth === "admin") {
lines.push(" -H 'Authorization: Bearer $TOKEN'");
} else if (endpoint.auth === "hmac") {
lines.push(" -H 'X-Api-Key: $API_KEY'",
" -H 'X-Api-Timestamp: $TIMESTAMP'",
" -H 'X-Api-Nonce: $UUID'",
" -H 'X-Api-Signature: $SIGNATURE'");
if (endpoint.method !== "GET") lines.push(" -H 'Idempotency-Key: $UUID'");
}
if (endpoint.body) {
lines.push(" -H 'Content-Type: application/json'",
` -d '${JSON.stringify(endpoint.body)}'`);
}
return lines.join(" \\\n");
}
function endpointId(service, endpoint) {
return `${service.id}-${endpoint.method.toLowerCase()}-${endpoint.path
.replace(/[{}]/g, "").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-|-$/g, "")}`;
}
function render() {
const query = search.value.trim().toLowerCase();
list.replaceChildren();
let shown = 0;
manifest.services.forEach((service) => {
service.endpoints.forEach((endpoint) => {
const haystack = `${service.name} ${endpoint.method} ${endpoint.path} ${endpoint.title} ${endpoint.description} ${endpoint.group}`.toLowerCase();
if ((activeService !== "all" && activeService !== service.id) || !haystack.includes(query)) return;
shown += 1;
const node = template.content.firstElementChild.cloneNode(true);
node.id = endpointId(service, endpoint);
node.dataset.service = service.id;
const summary = node.querySelector(".endpoint-summary");
const method = node.querySelector(".method");
method.textContent = endpoint.method;
method.classList.add(endpoint.method);
node.querySelector(".path").textContent = endpoint.path;
node.querySelector(".endpoint-title").textContent = endpoint.title;
node.querySelector(".auth-badge").textContent = endpoint.auth_label;
node.querySelector(".endpoint-description").textContent = endpoint.description;
node.querySelector(".endpoint-meta").innerHTML =
`${escapeHtml(service.base_url)}${escapeHtml(endpoint.group)}`;
const curl = curlFor(service, endpoint);
node.querySelector(".endpoint-example").innerHTML =
`
${escapeHtml(curl)}