@oondemand/oon-core-back 0.3.52 → 0.3.53
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/package.json +1 -1
- package/src/api/core.routes.js +76 -0
package/package.json
CHANGED
package/src/api/core.routes.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
1
3
|
const express = require("express");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
2
6
|
const registry = require("../core/registry");
|
|
3
7
|
const ctx = require("../core/context");
|
|
8
|
+
const corePackage = require("../../package.json");
|
|
4
9
|
|
|
5
10
|
const router = express.Router();
|
|
11
|
+
const startedAt = new Date().toISOString();
|
|
6
12
|
|
|
7
13
|
function modelSummary(entry) {
|
|
8
14
|
return {
|
|
@@ -31,10 +37,79 @@ function appSummary() {
|
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
function firstValue(...values) {
|
|
41
|
+
return values.find((candidate) => typeof candidate === "string" && candidate.trim())?.trim();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function packageVersion(file) {
|
|
45
|
+
try {
|
|
46
|
+
const payload = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
47
|
+
return typeof payload.version === "string" && payload.version.trim()
|
|
48
|
+
? payload.version.trim()
|
|
49
|
+
: undefined;
|
|
50
|
+
} catch (_error) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function centralVersion() {
|
|
56
|
+
const manifestRoot = ctx.config.appManifestPath
|
|
57
|
+
? path.dirname(ctx.config.appManifestPath)
|
|
58
|
+
: undefined;
|
|
59
|
+
const candidates = [
|
|
60
|
+
manifestRoot ? path.join(manifestRoot, "package.json") : undefined,
|
|
61
|
+
path.join(process.cwd(), "package.json"),
|
|
62
|
+
path.join(process.cwd(), "..", "package.json"),
|
|
63
|
+
].filter(Boolean);
|
|
64
|
+
const detected = candidates.map(packageVersion).find(Boolean);
|
|
65
|
+
const configuredServiceVersion = ctx.config.serviceVersion !== "0.0.0"
|
|
66
|
+
? ctx.config.serviceVersion
|
|
67
|
+
: undefined;
|
|
68
|
+
|
|
69
|
+
return firstValue(
|
|
70
|
+
process.env.OON_CENTRAL_VERSION,
|
|
71
|
+
process.env.CENTRAL_VERSION,
|
|
72
|
+
detected,
|
|
73
|
+
configuredServiceVersion,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function runtimeSummary() {
|
|
78
|
+
return {
|
|
79
|
+
core: {
|
|
80
|
+
backendVersion: corePackage.version,
|
|
81
|
+
},
|
|
82
|
+
central: {
|
|
83
|
+
version: centralVersion(),
|
|
84
|
+
},
|
|
85
|
+
deployment: {
|
|
86
|
+
commit: firstValue(
|
|
87
|
+
process.env.OON_BUILD_COMMIT,
|
|
88
|
+
process.env.CENTRAL_COMMIT_SHA,
|
|
89
|
+
process.env.SOURCE_COMMIT_SHA,
|
|
90
|
+
process.env.GITHUB_SHA,
|
|
91
|
+
),
|
|
92
|
+
releaseId: firstValue(process.env.OON_RELEASE_ID, process.env.RELEASE_ID),
|
|
93
|
+
builtAt: firstValue(
|
|
94
|
+
process.env.OON_BUILD_TIME,
|
|
95
|
+
process.env.BUILD_TIME,
|
|
96
|
+
process.env.SOURCE_UPDATED_AT,
|
|
97
|
+
),
|
|
98
|
+
startedAt,
|
|
99
|
+
environment: firstValue(
|
|
100
|
+
process.env.OON_ENVIRONMENT,
|
|
101
|
+
process.env.DEPLOY_ENVIRONMENT,
|
|
102
|
+
process.env.NODE_ENV,
|
|
103
|
+
),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
34
108
|
router.get("/metadata", (_req, res) => {
|
|
35
109
|
res.json({
|
|
36
110
|
service: { name: ctx.config.serviceName, version: ctx.config.serviceVersion },
|
|
37
111
|
app: appSummary(),
|
|
112
|
+
runtime: runtimeSummary(),
|
|
38
113
|
models: registry.listModels().map(modelSummary),
|
|
39
114
|
collections: registry.listCollections(),
|
|
40
115
|
documents: registry.listDocuments(),
|
|
@@ -76,3 +151,4 @@ router.get("/menus", (_req, res) => res.json({ results: registry.listMenus() }))
|
|
|
76
151
|
router.get("/features", (_req, res) => res.json({ results: registry.listFeatures() }));
|
|
77
152
|
|
|
78
153
|
module.exports = router;
|
|
154
|
+
module.exports.runtimeSummary = runtimeSummary;
|