This commit is contained in:
JiriUhlir
2026-06-29 09:47:05 +02:00
parent 60cb139a33
commit 9c08dacc69
29 changed files with 3703 additions and 23 deletions
+123 -13
View File
@@ -1,35 +1,145 @@
import express from "express";
import { SapBusinessOneServiceLayer } from "./SapBusinessOneServiceLayer";
export { SessionManager, SapB1Session } from "./auth/SessionManager";
export { SapB1Client, SapB1ClientOptions } from "./client/SapB1Client";
export { buildODataParams, extractNextLink } from "./client/odata";
export { loadSapB1ConfigFromEnv, SapB1Config, SapB1ConfigSchema } from "./config";
export { SapB1Error } from "./errors/SapB1Error";
export { SapBusinessOneServiceLayer } from "./SapBusinessOneServiceLayer";
export * from "./types/entities";
export * from "./types/odata";
const app = express();
const port = Number(process.env.PORT || 3000);
const rootPath = process.env.ROOT_PATH || "";
const serviceName = "SAP Business One";
const serviceId = "sap-bo";
function openApiDocument(basePath = "") {
return {
openapi: "3.0.3",
info: {
title: "SAP Business One connector service",
version: "1.0.0",
description: "Health and documentation wrapper for the SAP Business One Service Layer TypeScript connector."
},
servers: [{ url: basePath || "/" }],
paths: {
"/": {
get: {
summary: "Service metadata",
responses: {
"200": { description: "Service status" }
}
}
},
"/health": {
get: {
summary: "Health check",
responses: {
"200": { description: "Service is ready to accept traffic" }
}
}
},
"/openapi.json": {
get: {
summary: "OpenAPI schema",
responses: {
"200": { description: "OpenAPI document" }
}
}
}
}
};
}
function docsHtml(basePath = "") {
const openApiUrl = `${basePath}/openapi.json`.replace("//", "/");
return `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SAP Business One connector docs</title>
<style>
body { font-family: Arial, sans-serif; margin: 2rem; line-height: 1.5; color: #1f2937; }
code, pre { background: #f3f4f6; border-radius: 4px; padding: 0.2rem 0.35rem; }
a { color: #0f766e; }
</style>
</head>
<body>
<h1>SAP Business One connector</h1>
<p>This service exposes AppFactory health and OpenAPI metadata. The connector itself is used as a TypeScript library.</p>
<ul>
<li><a href="${openApiUrl}">OpenAPI JSON</a></li>
<li><code>GET ${basePath || ""}/health</code></li>
</ul>
<button type="button" id="try-health">Try health</button>
<button type="button" id="try-openapi">Try OpenAPI</button>
<pre id="result" aria-live="polite"></pre>
<script>
const result = document.getElementById("result");
async function show(url) {
const response = await fetch(url);
const contentType = response.headers.get("content-type") || "";
const body = contentType.includes("application/json") ? await response.json() : await response.text();
result.textContent = JSON.stringify({ status: response.status, body }, null, 2);
}
document.getElementById("try-health").addEventListener("click", () => show("${basePath}/health".replace("//", "/")));
document.getElementById("try-openapi").addEventListener("click", () => show("${openApiUrl}"));
</script>
</body>
</html>`;
}
function serviceMetadata() {
return {
name: serviceName,
service: serviceId,
status: "ok"
};
}
app.get("/", (_req, res) => {
res.json({
name: "SAP Business One",
service: "sap-bo",
status: "ok"
});
res.json(serviceMetadata());
});
app.get("/health", (_req, res) => {
res.json({ status: "ok" });
});
app.get("/openapi.json", (_req, res) => {
res.json(openApiDocument(rootPath));
});
app.get("/docs", (_req, res) => {
res.type("html").send(docsHtml(rootPath));
});
if (rootPath) {
app.get(rootPath, (_req, res) => {
res.json({
name: "SAP Business One",
service: "sap-bo",
status: "ok"
});
res.json(serviceMetadata());
});
app.get(rootPath + "/health", (_req, res) => {
res.json({ status: "ok" });
});
app.get(rootPath + "/openapi.json", (_req, res) => {
res.json(openApiDocument(rootPath));
});
app.get(rootPath + "/docs", (_req, res) => {
res.type("html").send(docsHtml(rootPath));
});
}
app.listen(port, "0.0.0.0", () => {
console.log("sap-bo listening on port " + port);
});
if (require.main === module) {
app.listen(port, "0.0.0.0", () => {
console.log(serviceId + " listening on port " + port);
});
}
export { app };