@uns-kit/api 2.0.24 → 2.0.26
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 +77 -77
- 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 +52 -52
- package/dist/uns-api-proxy.d.ts +58 -58
- package/dist/uns-api-proxy.js +514 -514
- package/package.json +2 -2
package/dist/uns-api-plugin.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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
|
-
retain: true,
|
|
22
|
-
properties: { messageExpiryInterval: 120000 },
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
unsApiProxy.event.on("unsProxyProducedApiEndpoints", (event) => {
|
|
26
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedApiEndpoints), {
|
|
27
|
-
retain: true,
|
|
28
|
-
properties: { messageExpiryInterval: 120000 },
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
unsApiProxy.event.on("unsProxyProducedApiCatchAll", (event) => {
|
|
32
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedCatchall), {
|
|
33
|
-
retain: true,
|
|
34
|
-
properties: { messageExpiryInterval: 120000 },
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
unsApiProxy.event.on("mqttProxyStatus", (event) => {
|
|
38
|
-
const time = UnsPacket.formatToISO8601(new Date());
|
|
39
|
-
const unsMessage = { data: { time, value: event.value, uom: event.uom } };
|
|
40
|
-
UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {
|
|
41
|
-
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
internals.unsApiProxies.push(unsApiProxy);
|
|
45
|
-
getApiProxies(this).push(unsApiProxy);
|
|
46
|
-
return unsApiProxy;
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
UnsProxyProcess.use(unsApiPlugin);
|
|
51
|
-
export default unsApiPlugin;
|
|
52
|
-
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
|
+
retain: true,
|
|
22
|
+
properties: { messageExpiryInterval: 120000 },
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
unsApiProxy.event.on("unsProxyProducedApiEndpoints", (event) => {
|
|
26
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedApiEndpoints), {
|
|
27
|
+
retain: true,
|
|
28
|
+
properties: { messageExpiryInterval: 120000 },
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
unsApiProxy.event.on("unsProxyProducedApiCatchAll", (event) => {
|
|
32
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedCatchall), {
|
|
33
|
+
retain: true,
|
|
34
|
+
properties: { messageExpiryInterval: 120000 },
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
unsApiProxy.event.on("mqttProxyStatus", (event) => {
|
|
38
|
+
const time = UnsPacket.formatToISO8601(new Date());
|
|
39
|
+
const unsMessage = { data: { time, value: event.value, uom: event.uom } };
|
|
40
|
+
UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {
|
|
41
|
+
internals.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
internals.unsApiProxies.push(unsApiProxy);
|
|
45
|
+
getApiProxies(this).push(unsApiProxy);
|
|
46
|
+
return unsApiProxy;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
UnsProxyProcess.use(unsApiPlugin);
|
|
51
|
+
export default unsApiPlugin;
|
|
52
|
+
export { UnsApiProxy };
|
package/dist/uns-api-proxy.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
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 } 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
|
-
registerCatchAll(topicPrefix: string, options?: {
|
|
42
|
-
apiBase?: string;
|
|
43
|
-
apiBasePath?: string;
|
|
44
|
-
swaggerPath?: string;
|
|
45
|
-
swaggerDoc?: Record<string, unknown>;
|
|
46
|
-
apiDescription?: string;
|
|
47
|
-
tags?: string[];
|
|
48
|
-
queryParams?: IGetEndpointOptions["queryParams"];
|
|
49
|
-
}): Promise<void>;
|
|
50
|
-
post(..._args: any[]): any;
|
|
51
|
-
private emitStatusMetrics;
|
|
52
|
-
private registerHealthEndpoint;
|
|
53
|
-
private extractBearerToken;
|
|
54
|
-
private getPublicKeyFromJwks;
|
|
55
|
-
private fetchJwksKeys;
|
|
56
|
-
private certFromX5c;
|
|
57
|
-
stop(): Promise<void>;
|
|
58
|
-
}
|
|
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 } 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
|
+
registerCatchAll(topicPrefix: string, options?: {
|
|
42
|
+
apiBase?: string;
|
|
43
|
+
apiBasePath?: string;
|
|
44
|
+
swaggerPath?: string;
|
|
45
|
+
swaggerDoc?: Record<string, unknown>;
|
|
46
|
+
apiDescription?: string;
|
|
47
|
+
tags?: string[];
|
|
48
|
+
queryParams?: IGetEndpointOptions["queryParams"];
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
post(..._args: any[]): any;
|
|
51
|
+
private emitStatusMetrics;
|
|
52
|
+
private registerHealthEndpoint;
|
|
53
|
+
private extractBearerToken;
|
|
54
|
+
private getPublicKeyFromJwks;
|
|
55
|
+
private fetchJwksKeys;
|
|
56
|
+
private certFromX5c;
|
|
57
|
+
stop(): Promise<void>;
|
|
58
|
+
}
|