@uns-kit/api 2.0.40 → 2.0.41
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/LICENSE +21 -21
- package/README.md +172 -172
- package/dist/api-interfaces.d.ts +1 -1
- package/dist/app.d.ts +48 -48
- package/dist/app.js +150 -150
- package/dist/uns-api-plugin.js +43 -43
- package/dist/uns-api-proxy.d.ts +70 -70
- package/dist/uns-api-proxy.js +650 -650
- package/package.json +2 -2
package/dist/app.js
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
import express from "express";
|
|
5
|
-
import * as http from "http";
|
|
6
|
-
import * as path from "path";
|
|
7
|
-
import cookieParser from "cookie-parser";
|
|
8
|
-
import { basePath } from "@uns-kit/core/base-path.js";
|
|
9
|
-
import logger from "@uns-kit/core/logger.js";
|
|
10
|
-
import os from 'os';
|
|
11
|
-
const normalizeBasePrefix = (value) => {
|
|
12
|
-
if (!value)
|
|
13
|
-
return "";
|
|
14
|
-
const trimmed = value.trim();
|
|
15
|
-
if (!trimmed)
|
|
16
|
-
return "";
|
|
17
|
-
const withLeading = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
18
|
-
return withLeading.replace(/\/+$/, "");
|
|
19
|
-
};
|
|
20
|
-
const buildSwaggerPath = (base, processName, instanceName) => {
|
|
21
|
-
const processSegment = `/${processName}`;
|
|
22
|
-
let baseWithProcess = base || "/";
|
|
23
|
-
if (!baseWithProcess.endsWith(processSegment)) {
|
|
24
|
-
baseWithProcess = `${baseWithProcess}${processSegment}`;
|
|
25
|
-
}
|
|
26
|
-
return `${baseWithProcess}/${instanceName}/swagger.json`.replace(/\/{2,}/g, "/");
|
|
27
|
-
};
|
|
28
|
-
export default class App {
|
|
29
|
-
expressApplication;
|
|
30
|
-
server;
|
|
31
|
-
port;
|
|
32
|
-
router;
|
|
33
|
-
processName;
|
|
34
|
-
instanceName;
|
|
35
|
-
apiBasePrefix;
|
|
36
|
-
swaggerBasePrefix;
|
|
37
|
-
swaggerSpec;
|
|
38
|
-
swaggerDocs = new Map();
|
|
39
|
-
constructor(port, processName, instanceName, appContext, mountConfig) {
|
|
40
|
-
this.router = express.Router();
|
|
41
|
-
this.port = port;
|
|
42
|
-
this.expressApplication = express();
|
|
43
|
-
this.server = http.createServer(this.expressApplication);
|
|
44
|
-
this.processName = processName;
|
|
45
|
-
this.instanceName = instanceName;
|
|
46
|
-
this.apiBasePrefix =
|
|
47
|
-
normalizeBasePrefix(mountConfig?.apiBasePrefix ?? process.env.UNS_API_BASE_PATH) || "/api";
|
|
48
|
-
const rawSwaggerBase = normalizeBasePrefix(mountConfig?.swaggerBasePrefix ?? process.env.UNS_SWAGGER_BASE_PATH) ||
|
|
49
|
-
this.apiBasePrefix;
|
|
50
|
-
// If someone passed ".../api" as swagger base, strip that to avoid duplicated segments
|
|
51
|
-
this.swaggerBasePrefix = rawSwaggerBase.endsWith("/api")
|
|
52
|
-
? rawSwaggerBase.replace(/\/api\/?$/, "") || "/"
|
|
53
|
-
: rawSwaggerBase;
|
|
54
|
-
// Add context
|
|
55
|
-
this.expressApplication.use((req, _res, next) => {
|
|
56
|
-
req.appContext = appContext;
|
|
57
|
-
next();
|
|
58
|
-
});
|
|
59
|
-
// Body parser (req.body)
|
|
60
|
-
this.expressApplication.use(express.json());
|
|
61
|
-
this.expressApplication.use(express.urlencoded({ extended: false }));
|
|
62
|
-
// Add cookie parser
|
|
63
|
-
this.expressApplication.use(cookieParser());
|
|
64
|
-
// Static / public folder
|
|
65
|
-
const publicHome = process.env.PUBLIC_HOME === null || process.env.PUBLIC_HOME === undefined
|
|
66
|
-
? "public"
|
|
67
|
-
: process.env.PUBLIC_HOME;
|
|
68
|
-
this.expressApplication.use(express.static(path.join(basePath, publicHome)));
|
|
69
|
-
// Map routes
|
|
70
|
-
this.router.use((_req, _res, next) => {
|
|
71
|
-
logger.info("Time: ", Date.now());
|
|
72
|
-
next();
|
|
73
|
-
});
|
|
74
|
-
if (!mountConfig?.disableDefaultApiMount) {
|
|
75
|
-
this.expressApplication.use(this.apiBasePrefix, this.router);
|
|
76
|
-
}
|
|
77
|
-
// Swagger specs
|
|
78
|
-
this.swaggerSpec = {
|
|
79
|
-
openapi: "3.0.0",
|
|
80
|
-
info: {
|
|
81
|
-
title: "UNS API",
|
|
82
|
-
version: "1.0.0",
|
|
83
|
-
},
|
|
84
|
-
paths: {},
|
|
85
|
-
servers: this.swaggerBasePrefix ? [{ url: this.swaggerBasePrefix }] : undefined,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
static getExternalIPv4() {
|
|
89
|
-
const interfaces = os.networkInterfaces();
|
|
90
|
-
for (const name of Object.keys(interfaces)) {
|
|
91
|
-
for (const iface of interfaces[name] || []) {
|
|
92
|
-
if (iface.family === 'IPv4' && !iface.internal) {
|
|
93
|
-
return iface.address;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
getSwaggerSpec() {
|
|
100
|
-
return this.swaggerSpec;
|
|
101
|
-
}
|
|
102
|
-
registerSwaggerDoc(path, doc) {
|
|
103
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
104
|
-
this.swaggerDocs.set(normalizedPath, doc);
|
|
105
|
-
this.expressApplication.get(normalizedPath, (_req, res) => res.json(doc));
|
|
106
|
-
}
|
|
107
|
-
async start() {
|
|
108
|
-
// Listen on provided port, on all network interfaces.
|
|
109
|
-
this.server.listen(this.port);
|
|
110
|
-
this.server.on("error", (error) => {
|
|
111
|
-
if (error.syscall !== "listen") {
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
const bind = typeof this.port === "string"
|
|
115
|
-
? `Pipe ${this.port}`
|
|
116
|
-
: `Port ${this.port}`;
|
|
117
|
-
// handle specific listen errors with friendly messages
|
|
118
|
-
switch (error.code) {
|
|
119
|
-
case "EACCES":
|
|
120
|
-
logger.error(`${bind} requires elevated privileges`);
|
|
121
|
-
process.exit(1);
|
|
122
|
-
break;
|
|
123
|
-
case "EADDRINUSE":
|
|
124
|
-
logger.error(`${bind} is already in use`);
|
|
125
|
-
process.exit(1);
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
this.server.on("listening", () => {
|
|
132
|
-
App.bind(this);
|
|
133
|
-
const addressInfo = this.server.address();
|
|
134
|
-
let ip;
|
|
135
|
-
let port;
|
|
136
|
-
if (addressInfo && typeof addressInfo === "object") {
|
|
137
|
-
ip = App.getExternalIPv4();
|
|
138
|
-
port = addressInfo.port;
|
|
139
|
-
}
|
|
140
|
-
else if (typeof addressInfo === "string") {
|
|
141
|
-
ip = App.getExternalIPv4();
|
|
142
|
-
port = "";
|
|
143
|
-
}
|
|
144
|
-
logger.info(`API listening on http://${ip}:${port}${this.apiBasePrefix}`);
|
|
145
|
-
const swaggerPath = buildSwaggerPath(this.swaggerBasePrefix, this.processName, this.instanceName);
|
|
146
|
-
logger.info(`Swagger openAPI on http://${ip}:${port}${swaggerPath}`);
|
|
147
|
-
this.expressApplication.get(swaggerPath, (req, res) => res.json(this.getSwaggerSpec()));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Module dependencies.
|
|
3
|
+
*/
|
|
4
|
+
import express from "express";
|
|
5
|
+
import * as http from "http";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import cookieParser from "cookie-parser";
|
|
8
|
+
import { basePath } from "@uns-kit/core/base-path.js";
|
|
9
|
+
import logger from "@uns-kit/core/logger.js";
|
|
10
|
+
import os from 'os';
|
|
11
|
+
const normalizeBasePrefix = (value) => {
|
|
12
|
+
if (!value)
|
|
13
|
+
return "";
|
|
14
|
+
const trimmed = value.trim();
|
|
15
|
+
if (!trimmed)
|
|
16
|
+
return "";
|
|
17
|
+
const withLeading = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
18
|
+
return withLeading.replace(/\/+$/, "");
|
|
19
|
+
};
|
|
20
|
+
const buildSwaggerPath = (base, processName, instanceName) => {
|
|
21
|
+
const processSegment = `/${processName}`;
|
|
22
|
+
let baseWithProcess = base || "/";
|
|
23
|
+
if (!baseWithProcess.endsWith(processSegment)) {
|
|
24
|
+
baseWithProcess = `${baseWithProcess}${processSegment}`;
|
|
25
|
+
}
|
|
26
|
+
return `${baseWithProcess}/${instanceName}/swagger.json`.replace(/\/{2,}/g, "/");
|
|
27
|
+
};
|
|
28
|
+
export default class App {
|
|
29
|
+
expressApplication;
|
|
30
|
+
server;
|
|
31
|
+
port;
|
|
32
|
+
router;
|
|
33
|
+
processName;
|
|
34
|
+
instanceName;
|
|
35
|
+
apiBasePrefix;
|
|
36
|
+
swaggerBasePrefix;
|
|
37
|
+
swaggerSpec;
|
|
38
|
+
swaggerDocs = new Map();
|
|
39
|
+
constructor(port, processName, instanceName, appContext, mountConfig) {
|
|
40
|
+
this.router = express.Router();
|
|
41
|
+
this.port = port;
|
|
42
|
+
this.expressApplication = express();
|
|
43
|
+
this.server = http.createServer(this.expressApplication);
|
|
44
|
+
this.processName = processName;
|
|
45
|
+
this.instanceName = instanceName;
|
|
46
|
+
this.apiBasePrefix =
|
|
47
|
+
normalizeBasePrefix(mountConfig?.apiBasePrefix ?? process.env.UNS_API_BASE_PATH) || "/api";
|
|
48
|
+
const rawSwaggerBase = normalizeBasePrefix(mountConfig?.swaggerBasePrefix ?? process.env.UNS_SWAGGER_BASE_PATH) ||
|
|
49
|
+
this.apiBasePrefix;
|
|
50
|
+
// If someone passed ".../api" as swagger base, strip that to avoid duplicated segments
|
|
51
|
+
this.swaggerBasePrefix = rawSwaggerBase.endsWith("/api")
|
|
52
|
+
? rawSwaggerBase.replace(/\/api\/?$/, "") || "/"
|
|
53
|
+
: rawSwaggerBase;
|
|
54
|
+
// Add context
|
|
55
|
+
this.expressApplication.use((req, _res, next) => {
|
|
56
|
+
req.appContext = appContext;
|
|
57
|
+
next();
|
|
58
|
+
});
|
|
59
|
+
// Body parser (req.body)
|
|
60
|
+
this.expressApplication.use(express.json());
|
|
61
|
+
this.expressApplication.use(express.urlencoded({ extended: false }));
|
|
62
|
+
// Add cookie parser
|
|
63
|
+
this.expressApplication.use(cookieParser());
|
|
64
|
+
// Static / public folder
|
|
65
|
+
const publicHome = process.env.PUBLIC_HOME === null || process.env.PUBLIC_HOME === undefined
|
|
66
|
+
? "public"
|
|
67
|
+
: process.env.PUBLIC_HOME;
|
|
68
|
+
this.expressApplication.use(express.static(path.join(basePath, publicHome)));
|
|
69
|
+
// Map routes
|
|
70
|
+
this.router.use((_req, _res, next) => {
|
|
71
|
+
logger.info("Time: ", Date.now());
|
|
72
|
+
next();
|
|
73
|
+
});
|
|
74
|
+
if (!mountConfig?.disableDefaultApiMount) {
|
|
75
|
+
this.expressApplication.use(this.apiBasePrefix, this.router);
|
|
76
|
+
}
|
|
77
|
+
// Swagger specs
|
|
78
|
+
this.swaggerSpec = {
|
|
79
|
+
openapi: "3.0.0",
|
|
80
|
+
info: {
|
|
81
|
+
title: "UNS API",
|
|
82
|
+
version: "1.0.0",
|
|
83
|
+
},
|
|
84
|
+
paths: {},
|
|
85
|
+
servers: this.swaggerBasePrefix ? [{ url: this.swaggerBasePrefix }] : undefined,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
static getExternalIPv4() {
|
|
89
|
+
const interfaces = os.networkInterfaces();
|
|
90
|
+
for (const name of Object.keys(interfaces)) {
|
|
91
|
+
for (const iface of interfaces[name] || []) {
|
|
92
|
+
if (iface.family === 'IPv4' && !iface.internal) {
|
|
93
|
+
return iface.address;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
getSwaggerSpec() {
|
|
100
|
+
return this.swaggerSpec;
|
|
101
|
+
}
|
|
102
|
+
registerSwaggerDoc(path, doc) {
|
|
103
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
104
|
+
this.swaggerDocs.set(normalizedPath, doc);
|
|
105
|
+
this.expressApplication.get(normalizedPath, (_req, res) => res.json(doc));
|
|
106
|
+
}
|
|
107
|
+
async start() {
|
|
108
|
+
// Listen on provided port, on all network interfaces.
|
|
109
|
+
this.server.listen(this.port);
|
|
110
|
+
this.server.on("error", (error) => {
|
|
111
|
+
if (error.syscall !== "listen") {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
const bind = typeof this.port === "string"
|
|
115
|
+
? `Pipe ${this.port}`
|
|
116
|
+
: `Port ${this.port}`;
|
|
117
|
+
// handle specific listen errors with friendly messages
|
|
118
|
+
switch (error.code) {
|
|
119
|
+
case "EACCES":
|
|
120
|
+
logger.error(`${bind} requires elevated privileges`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
break;
|
|
123
|
+
case "EADDRINUSE":
|
|
124
|
+
logger.error(`${bind} is already in use`);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
this.server.on("listening", () => {
|
|
132
|
+
App.bind(this);
|
|
133
|
+
const addressInfo = this.server.address();
|
|
134
|
+
let ip;
|
|
135
|
+
let port;
|
|
136
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
137
|
+
ip = App.getExternalIPv4();
|
|
138
|
+
port = addressInfo.port;
|
|
139
|
+
}
|
|
140
|
+
else if (typeof addressInfo === "string") {
|
|
141
|
+
ip = App.getExternalIPv4();
|
|
142
|
+
port = "";
|
|
143
|
+
}
|
|
144
|
+
logger.info(`API listening on http://${ip}:${port}${this.apiBasePrefix}`);
|
|
145
|
+
const swaggerPath = buildSwaggerPath(this.swaggerBasePrefix, this.processName, this.instanceName);
|
|
146
|
+
logger.info(`Swagger openAPI on http://${ip}:${port}${swaggerPath}`);
|
|
147
|
+
this.expressApplication.get(swaggerPath, (req, res) => res.json(this.getSwaggerSpec()));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
package/dist/uns-api-plugin.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process.js";
|
|
2
|
-
import UnsApiProxy from "./uns-api-proxy.js";
|
|
3
|
-
import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
|
|
4
|
-
const apiProxyRegistry = new WeakMap();
|
|
5
|
-
const getApiProxies = (instance) => {
|
|
6
|
-
let proxies = apiProxyRegistry.get(instance);
|
|
7
|
-
if (!proxies) {
|
|
8
|
-
proxies = [];
|
|
9
|
-
apiProxyRegistry.set(instance, proxies);
|
|
10
|
-
}
|
|
11
|
-
return proxies;
|
|
12
|
-
};
|
|
13
|
-
const unsApiPlugin = ({ define }) => {
|
|
14
|
-
define({
|
|
15
|
-
async createApiProxy(instanceName, options) {
|
|
16
|
-
await this.waitForProcessConnection();
|
|
17
|
-
const internals = this;
|
|
18
|
-
const unsApiProxy = new UnsApiProxy(internals.processName, instanceName, options);
|
|
19
|
-
unsApiProxy.event.on("unsProxyProducedTopics", (event) => {
|
|
20
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedTopics));
|
|
21
|
-
});
|
|
22
|
-
unsApiProxy.event.on("unsProxyProducedApiEndpoints", (event) => {
|
|
23
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedApiEndpoints));
|
|
24
|
-
});
|
|
25
|
-
unsApiProxy.event.on("unsProxyProducedApiCatchAll", (event) => {
|
|
26
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedCatchall));
|
|
27
|
-
});
|
|
28
|
-
unsApiProxy.event.on("mqttProxyStatus", (event) => {
|
|
29
|
-
const time = UnsPacket.formatToISO8601(new Date());
|
|
30
|
-
const unsMessage = { data: { time, value: event.value, uom: event.uom } };
|
|
31
|
-
UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {
|
|
32
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
internals.unsApiProxies.push(unsApiProxy);
|
|
36
|
-
getApiProxies(this).push(unsApiProxy);
|
|
37
|
-
return unsApiProxy;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
UnsProxyProcess.use(unsApiPlugin);
|
|
42
|
-
export default unsApiPlugin;
|
|
43
|
-
export { UnsApiProxy };
|
|
1
|
+
import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process.js";
|
|
2
|
+
import UnsApiProxy from "./uns-api-proxy.js";
|
|
3
|
+
import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
|
|
4
|
+
const apiProxyRegistry = new WeakMap();
|
|
5
|
+
const getApiProxies = (instance) => {
|
|
6
|
+
let proxies = apiProxyRegistry.get(instance);
|
|
7
|
+
if (!proxies) {
|
|
8
|
+
proxies = [];
|
|
9
|
+
apiProxyRegistry.set(instance, proxies);
|
|
10
|
+
}
|
|
11
|
+
return proxies;
|
|
12
|
+
};
|
|
13
|
+
const unsApiPlugin = ({ define }) => {
|
|
14
|
+
define({
|
|
15
|
+
async createApiProxy(instanceName, options) {
|
|
16
|
+
await this.waitForProcessConnection();
|
|
17
|
+
const internals = this;
|
|
18
|
+
const unsApiProxy = new UnsApiProxy(internals.processName, instanceName, options);
|
|
19
|
+
unsApiProxy.event.on("unsProxyProducedTopics", (event) => {
|
|
20
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedTopics));
|
|
21
|
+
});
|
|
22
|
+
unsApiProxy.event.on("unsProxyProducedApiEndpoints", (event) => {
|
|
23
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedApiEndpoints));
|
|
24
|
+
});
|
|
25
|
+
unsApiProxy.event.on("unsProxyProducedApiCatchAll", (event) => {
|
|
26
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedCatchall));
|
|
27
|
+
});
|
|
28
|
+
unsApiProxy.event.on("mqttProxyStatus", (event) => {
|
|
29
|
+
const time = UnsPacket.formatToISO8601(new Date());
|
|
30
|
+
const unsMessage = { data: { time, value: event.value, uom: event.uom } };
|
|
31
|
+
UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {
|
|
32
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
internals.unsApiProxies.push(unsApiProxy);
|
|
36
|
+
getApiProxies(this).push(unsApiProxy);
|
|
37
|
+
return unsApiProxy;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
UnsProxyProcess.use(unsApiPlugin);
|
|
42
|
+
export default unsApiPlugin;
|
|
43
|
+
export { UnsApiProxy };
|
package/dist/uns-api-proxy.d.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { UnsAttribute } from "@uns-kit/core/uns/uns-interfaces.js";
|
|
2
|
-
import UnsProxy from "@uns-kit/core/uns/uns-proxy.js";
|
|
3
|
-
import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
|
|
4
|
-
import { IApiProxyOptions, IGetEndpointOptions, IPostEndpointOptions } from "@uns-kit/core/uns/uns-interfaces.js";
|
|
5
|
-
import { UnsAsset } from "@uns-kit/core/uns/uns-asset.js";
|
|
6
|
-
import { UnsObjectType, UnsObjectId } from "@uns-kit/core/uns/uns-object.js";
|
|
7
|
-
export default class UnsApiProxy extends UnsProxy {
|
|
8
|
-
instanceName: string;
|
|
9
|
-
private topicBuilder;
|
|
10
|
-
private processName;
|
|
11
|
-
protected processStatusTopic: string;
|
|
12
|
-
private app;
|
|
13
|
-
private options;
|
|
14
|
-
private apiBasePrefix;
|
|
15
|
-
private swaggerBasePrefix;
|
|
16
|
-
private jwksCache?;
|
|
17
|
-
private catchAllRouteRegistered;
|
|
18
|
-
private startedAt;
|
|
19
|
-
private statusInterval;
|
|
20
|
-
private readonly statusIntervalMs;
|
|
21
|
-
constructor(processName: string, instanceName: string, options: IApiProxyOptions);
|
|
22
|
-
/**
|
|
23
|
-
* Unregister endpoint
|
|
24
|
-
* @param topic - The API topic
|
|
25
|
-
* @param attribute - The attribute for the topic.
|
|
26
|
-
* @param method - The HTTP method (e.g., "GET", "POST", "PUT", "DELETE").
|
|
27
|
-
*/
|
|
28
|
-
unregister(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, method: "GET" | "POST" | "PUT" | "DELETE"): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Register a GET endpoint with optional JWT path filter.
|
|
31
|
-
* @param topic - The API topic
|
|
32
|
-
* @param attribute - The attribute for the topic.
|
|
33
|
-
* @param options.description - Optional description.
|
|
34
|
-
* @param options.tags - Optional tags.
|
|
35
|
-
*/
|
|
36
|
-
get(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, options?: IGetEndpointOptions): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Register a catch-all API mapping for a topic prefix (e.g., "sij/acroni/#").
|
|
39
|
-
* Does not create individual API attribute nodes; the controller treats this as a fallback.
|
|
40
|
-
*
|
|
41
|
-
* This is intended for use by the uns-api-global microservice, which acts as a
|
|
42
|
-
* catch-all gateway for an entire topic namespace. Regular microservices should
|
|
43
|
-
* NOT call this — use registerGetEndpoint() for individual attribute endpoints instead.
|
|
44
|
-
*/
|
|
45
|
-
registerCatchAll(topicPrefix: string, options?: {
|
|
46
|
-
apiBase?: string;
|
|
47
|
-
apiBasePath?: string;
|
|
48
|
-
swaggerPath?: string;
|
|
49
|
-
swaggerDoc?: Record<string, unknown>;
|
|
50
|
-
apiDescription?: string;
|
|
51
|
-
tags?: string[];
|
|
52
|
-
queryParams?: IGetEndpointOptions["queryParams"];
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Register a POST endpoint.
|
|
56
|
-
* @param topic - The API topic
|
|
57
|
-
* @param attribute - The attribute for the topic.
|
|
58
|
-
* @param options.apiDescription - Optional description.
|
|
59
|
-
* @param options.tags - Optional tags.
|
|
60
|
-
* @param options.requestBody - Optional request body schema for Swagger.
|
|
61
|
-
*/
|
|
62
|
-
post(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, options?: IPostEndpointOptions): Promise<void>;
|
|
63
|
-
private emitStatusMetrics;
|
|
64
|
-
private registerHealthEndpoint;
|
|
65
|
-
private extractBearerToken;
|
|
66
|
-
private getPublicKeyFromJwks;
|
|
67
|
-
private fetchJwksKeys;
|
|
68
|
-
private certFromX5c;
|
|
69
|
-
stop(): Promise<void>;
|
|
70
|
-
}
|
|
1
|
+
import { UnsAttribute } from "@uns-kit/core/uns/uns-interfaces.js";
|
|
2
|
+
import UnsProxy from "@uns-kit/core/uns/uns-proxy.js";
|
|
3
|
+
import { UnsTopics } from "@uns-kit/core/uns/uns-topics.js";
|
|
4
|
+
import { IApiProxyOptions, IGetEndpointOptions, IPostEndpointOptions } from "@uns-kit/core/uns/uns-interfaces.js";
|
|
5
|
+
import { UnsAsset } from "@uns-kit/core/uns/uns-asset.js";
|
|
6
|
+
import { UnsObjectType, UnsObjectId } from "@uns-kit/core/uns/uns-object.js";
|
|
7
|
+
export default class UnsApiProxy extends UnsProxy {
|
|
8
|
+
instanceName: string;
|
|
9
|
+
private topicBuilder;
|
|
10
|
+
private processName;
|
|
11
|
+
protected processStatusTopic: string;
|
|
12
|
+
private app;
|
|
13
|
+
private options;
|
|
14
|
+
private apiBasePrefix;
|
|
15
|
+
private swaggerBasePrefix;
|
|
16
|
+
private jwksCache?;
|
|
17
|
+
private catchAllRouteRegistered;
|
|
18
|
+
private startedAt;
|
|
19
|
+
private statusInterval;
|
|
20
|
+
private readonly statusIntervalMs;
|
|
21
|
+
constructor(processName: string, instanceName: string, options: IApiProxyOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Unregister endpoint
|
|
24
|
+
* @param topic - The API topic
|
|
25
|
+
* @param attribute - The attribute for the topic.
|
|
26
|
+
* @param method - The HTTP method (e.g., "GET", "POST", "PUT", "DELETE").
|
|
27
|
+
*/
|
|
28
|
+
unregister(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, method: "GET" | "POST" | "PUT" | "DELETE"): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Register a GET endpoint with optional JWT path filter.
|
|
31
|
+
* @param topic - The API topic
|
|
32
|
+
* @param attribute - The attribute for the topic.
|
|
33
|
+
* @param options.description - Optional description.
|
|
34
|
+
* @param options.tags - Optional tags.
|
|
35
|
+
*/
|
|
36
|
+
get(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, options?: IGetEndpointOptions): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Register a catch-all API mapping for a topic prefix (e.g., "sij/acroni/#").
|
|
39
|
+
* Does not create individual API attribute nodes; the controller treats this as a fallback.
|
|
40
|
+
*
|
|
41
|
+
* This is intended for use by the uns-api-global microservice, which acts as a
|
|
42
|
+
* catch-all gateway for an entire topic namespace. Regular microservices should
|
|
43
|
+
* NOT call this — use registerGetEndpoint() for individual attribute endpoints instead.
|
|
44
|
+
*/
|
|
45
|
+
registerCatchAll(topicPrefix: string, options?: {
|
|
46
|
+
apiBase?: string;
|
|
47
|
+
apiBasePath?: string;
|
|
48
|
+
swaggerPath?: string;
|
|
49
|
+
swaggerDoc?: Record<string, unknown>;
|
|
50
|
+
apiDescription?: string;
|
|
51
|
+
tags?: string[];
|
|
52
|
+
queryParams?: IGetEndpointOptions["queryParams"];
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Register a POST endpoint.
|
|
56
|
+
* @param topic - The API topic
|
|
57
|
+
* @param attribute - The attribute for the topic.
|
|
58
|
+
* @param options.apiDescription - Optional description.
|
|
59
|
+
* @param options.tags - Optional tags.
|
|
60
|
+
* @param options.requestBody - Optional request body schema for Swagger.
|
|
61
|
+
*/
|
|
62
|
+
post(topic: UnsTopics, asset: UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: UnsAttribute, options?: IPostEndpointOptions): Promise<void>;
|
|
63
|
+
private emitStatusMetrics;
|
|
64
|
+
private registerHealthEndpoint;
|
|
65
|
+
private extractBearerToken;
|
|
66
|
+
private getPublicKeyFromJwks;
|
|
67
|
+
private fetchJwksKeys;
|
|
68
|
+
private certFromX5c;
|
|
69
|
+
stop(): Promise<void>;
|
|
70
|
+
}
|