@uns-kit/core 0.0.1

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/app-config.d.ts +177 -0
  4. package/dist/app-config.js +1 -0
  5. package/dist/base-path.d.ts +1 -0
  6. package/dist/base-path.js +5 -0
  7. package/dist/config/project.config.extension.d.ts +3 -0
  8. package/dist/config/project.config.extension.js +3 -0
  9. package/dist/config-file.d.ts +12 -0
  10. package/dist/config-file.js +44 -0
  11. package/dist/examples/data-example.d.ts +1 -0
  12. package/dist/examples/data-example.js +44 -0
  13. package/dist/examples/load-test-data.d.ts +1 -0
  14. package/dist/examples/load-test-data.js +72 -0
  15. package/dist/examples/table-example.d.ts +4 -0
  16. package/dist/examples/table-example.js +52 -0
  17. package/dist/examples/uns-gateway.d.ts +1 -0
  18. package/dist/examples/uns-gateway.js +5 -0
  19. package/dist/graphql/schema.d.ts +377 -0
  20. package/dist/graphql/schema.js +13 -0
  21. package/dist/index.d.ts +5 -0
  22. package/dist/index.js +4 -0
  23. package/dist/logger.d.ts +2 -0
  24. package/dist/logger.js +18 -0
  25. package/dist/tools/auth/auth-client.d.ts +23 -0
  26. package/dist/tools/auth/auth-client.js +172 -0
  27. package/dist/tools/auth/index.d.ts +1 -0
  28. package/dist/tools/auth/index.js +1 -0
  29. package/dist/tools/auth/secure-store.d.ts +17 -0
  30. package/dist/tools/auth/secure-store.js +110 -0
  31. package/dist/tools/base-path.d.ts +1 -0
  32. package/dist/tools/base-path.js +5 -0
  33. package/dist/tools/generate-config-schema.d.ts +1 -0
  34. package/dist/tools/generate-config-schema.js +23 -0
  35. package/dist/tools/initialize.d.ts +1 -0
  36. package/dist/tools/initialize.js +103 -0
  37. package/dist/tools/make.d.ts +1 -0
  38. package/dist/tools/make.js +27 -0
  39. package/dist/tools/pull-request.d.ts +1 -0
  40. package/dist/tools/pull-request.js +157 -0
  41. package/dist/tools/refresh-uns.d.ts +1 -0
  42. package/dist/tools/refresh-uns.js +109 -0
  43. package/dist/tools/schema.d.ts +208 -0
  44. package/dist/tools/schema.js +1 -0
  45. package/dist/tools/update-rtt.d.ts +1 -0
  46. package/dist/tools/update-rtt.js +169 -0
  47. package/dist/tools/update-tools.d.ts +1 -0
  48. package/dist/tools/update-tools.js +72 -0
  49. package/dist/uns/handover-manager-event-emitter.d.ts +6 -0
  50. package/dist/uns/handover-manager-event-emitter.js +19 -0
  51. package/dist/uns/handover-manager.d.ts +34 -0
  52. package/dist/uns/handover-manager.js +227 -0
  53. package/dist/uns/process-config.d.ts +10 -0
  54. package/dist/uns/process-config.js +12 -0
  55. package/dist/uns/process-name-service.d.ts +7 -0
  56. package/dist/uns/process-name-service.js +28 -0
  57. package/dist/uns/status-monitor.d.ts +35 -0
  58. package/dist/uns/status-monitor.js +82 -0
  59. package/dist/uns/uns-event-emitter.d.ts +6 -0
  60. package/dist/uns/uns-event-emitter.js +19 -0
  61. package/dist/uns/uns-interfaces.d.ts +156 -0
  62. package/dist/uns/uns-interfaces.js +5 -0
  63. package/dist/uns/uns-measurements.d.ts +95 -0
  64. package/dist/uns/uns-measurements.js +146 -0
  65. package/dist/uns/uns-packet.d.ts +28 -0
  66. package/dist/uns/uns-packet.js +223 -0
  67. package/dist/uns/uns-proxy-process.d.ts +56 -0
  68. package/dist/uns/uns-proxy-process.js +179 -0
  69. package/dist/uns/uns-proxy.d.ts +31 -0
  70. package/dist/uns/uns-proxy.js +120 -0
  71. package/dist/uns/uns-tags.d.ts +1 -0
  72. package/dist/uns/uns-tags.js +1 -0
  73. package/dist/uns/uns-topic-matcher.d.ts +9 -0
  74. package/dist/uns/uns-topic-matcher.js +34 -0
  75. package/dist/uns/uns-topics.d.ts +1 -0
  76. package/dist/uns/uns-topics.js +1 -0
  77. package/dist/uns-config/config-schema.d.ts +7 -0
  78. package/dist/uns-config/config-schema.js +5 -0
  79. package/dist/uns-config/host-placeholders.d.ts +139 -0
  80. package/dist/uns-config/host-placeholders.js +70 -0
  81. package/dist/uns-config/schema-tolls.d.ts +2 -0
  82. package/dist/uns-config/schema-tolls.js +4 -0
  83. package/dist/uns-config/schema-tools.d.ts +2 -0
  84. package/dist/uns-config/schema-tools.js +18 -0
  85. package/dist/uns-config/secret-placeholders.d.ts +128 -0
  86. package/dist/uns-config/secret-placeholders.js +64 -0
  87. package/dist/uns-config/secret-resolver.d.ts +77 -0
  88. package/dist/uns-config/secret-resolver.js +285 -0
  89. package/dist/uns-config/uns-core-schema.d.ts +705 -0
  90. package/dist/uns-config/uns-core-schema.js +25 -0
  91. package/dist/uns-grpc/uns-gateway-cli.d.ts +2 -0
  92. package/dist/uns-grpc/uns-gateway-cli.js +32 -0
  93. package/dist/uns-grpc/uns-gateway-server.d.ts +47 -0
  94. package/dist/uns-grpc/uns-gateway-server.js +424 -0
  95. package/dist/uns-mqtt/mqtt-interfaces.d.ts +22 -0
  96. package/dist/uns-mqtt/mqtt-interfaces.js +1 -0
  97. package/dist/uns-mqtt/mqtt-proxy.d.ts +34 -0
  98. package/dist/uns-mqtt/mqtt-proxy.js +245 -0
  99. package/dist/uns-mqtt/mqtt-topic-builder.d.ts +51 -0
  100. package/dist/uns-mqtt/mqtt-topic-builder.js +70 -0
  101. package/dist/uns-mqtt/mqtt-worker-init.d.ts +1 -0
  102. package/dist/uns-mqtt/mqtt-worker-init.js +5 -0
  103. package/dist/uns-mqtt/mqtt-worker.d.ts +20 -0
  104. package/dist/uns-mqtt/mqtt-worker.js +120 -0
  105. package/dist/uns-mqtt/throttled-queue.d.ts +166 -0
  106. package/dist/uns-mqtt/throttled-queue.js +388 -0
  107. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts +107 -0
  108. package/dist/uns-mqtt/uns-mqtt-proxy.js +349 -0
  109. package/dist/uns-mqtt/ws-proxy.d.ts +38 -0
  110. package/dist/uns-mqtt/ws-proxy.js +86 -0
  111. package/package.json +48 -0
@@ -0,0 +1,95 @@
1
+ export type MeasurementUnit = PhysicalMeasurements | DataSizeMeasurements | (string & {});
2
+ export declare enum DataSizeMeasurements {
3
+ Bit = "bit",
4
+ Byte = "B",
5
+ KiloByte = "kB",
6
+ MegaByte = "MB",
7
+ GigaByte = "GB",
8
+ TeraByte = "TB",
9
+ PetaByte = "PB",
10
+ ExaByte = "EB",
11
+ ZettaByte = "ZB",
12
+ YottaByte = "YB"
13
+ }
14
+ export declare enum CounterMeasurements {
15
+ Kilo = "k",
16
+ Mega = "M",
17
+ Giga = "G"
18
+ }
19
+ export declare enum PhysicalMeasurements {
20
+ None = "",
21
+ MiliMeter = "mm",
22
+ Meter = "m",
23
+ KiloMeter = "km",
24
+ Feet = "ft",
25
+ Second = "s",
26
+ Minute = "min",
27
+ Hour = "h",
28
+ Day = "day",
29
+ Hertz = "Hz",
30
+ CubicMeter = "m^3",
31
+ Liter = "l",
32
+ Gallon = "gal",
33
+ Psi = "psi",
34
+ Pascal = "Pa",
35
+ Bar = "bar",
36
+ Celsius = "\u00B0C",
37
+ Fahrenheit = "\u00B0F",
38
+ Kelvin = "K",
39
+ Milijoule = "mJ",
40
+ Joule = "J",
41
+ Kilojoule = "kJ",
42
+ Megajoule = "MJ",
43
+ Gigajoule = "GJ",
44
+ Terajoule = "TJ",
45
+ Newton = "N",
46
+ Bit = "bit",
47
+ Byte = "byte",
48
+ B = "B",
49
+ MilimeterPerSecond = "mm/s",
50
+ MeterPerSecond = "m/s",
51
+ MeterPerMinute = "m/min",
52
+ CentiMeterPerSecond = "cm/s",
53
+ MeterPerHour = "m/h",
54
+ KilometerPerHour = "km/h",
55
+ RevolutionsPerMinute = "rpm",
56
+ Percent = "percent",
57
+ PartsPerMillion = "ppm",
58
+ PartsPerBillion = "ppb",
59
+ PartsPerTrillion = "ppt",
60
+ Decibel = "dB",
61
+ Degree = "\u00B0",
62
+ Radian = "rad",
63
+ Miligram = "mg",
64
+ Gram = "g",
65
+ Kilogram = "kg",
66
+ MetricTon = "t",
67
+ MiliVolt = "mV",
68
+ Volt = "V",
69
+ KiloVolt = "kV",
70
+ MegaVolt = "MV",
71
+ MiliAmpere = "mA",
72
+ Ampere = "A",
73
+ KiloAmpere = "kA",
74
+ MegaAmpere = "MA",
75
+ MiliWatt = "mW",
76
+ Watt = "W",
77
+ KiloWatt = "kW",
78
+ MegaWatt = "MW",
79
+ MiliWattHour = "mWh",
80
+ WattHour = "Wh",
81
+ KiloWattHour = "kWh",
82
+ MegaWattHour = "MWh",
83
+ MiliVoltAmpere = "mVA",
84
+ VoltAmpere = "VA",
85
+ KiloVoltAmpere = "kVA",
86
+ MegaVoltAmpere = "MVA",
87
+ MiliVoltAmpereReactive = "mVAR",
88
+ VoltAmpereReactive = "VAR",
89
+ KiloVoltAmpereReactive = "kVAR",
90
+ MegaVoltAmpereReactive = "MVAR",
91
+ CubicMeterPerHour = "m^3/h",
92
+ CubicMeterPerSecond = "m^3/s",
93
+ MegaGramPerHour = "Mg/h",
94
+ MetricTonPerHour = "t/h"
95
+ }
@@ -0,0 +1,146 @@
1
+ // Data Size
2
+ export var DataSizeMeasurements;
3
+ (function (DataSizeMeasurements) {
4
+ DataSizeMeasurements["Bit"] = "bit";
5
+ DataSizeMeasurements["Byte"] = "B";
6
+ DataSizeMeasurements["KiloByte"] = "kB";
7
+ DataSizeMeasurements["MegaByte"] = "MB";
8
+ DataSizeMeasurements["GigaByte"] = "GB";
9
+ DataSizeMeasurements["TeraByte"] = "TB";
10
+ DataSizeMeasurements["PetaByte"] = "PB";
11
+ DataSizeMeasurements["ExaByte"] = "EB";
12
+ DataSizeMeasurements["ZettaByte"] = "ZB";
13
+ DataSizeMeasurements["YottaByte"] = "YB";
14
+ })(DataSizeMeasurements || (DataSizeMeasurements = {}));
15
+ // Counter Measurements
16
+ export var CounterMeasurements;
17
+ (function (CounterMeasurements) {
18
+ CounterMeasurements["Kilo"] = "k";
19
+ CounterMeasurements["Mega"] = "M";
20
+ CounterMeasurements["Giga"] = "G";
21
+ })(CounterMeasurements || (CounterMeasurements = {}));
22
+ // Physical Measurements
23
+ export var PhysicalMeasurements;
24
+ (function (PhysicalMeasurements) {
25
+ PhysicalMeasurements["None"] = "";
26
+ // Length
27
+ // -------------------------------------------------
28
+ PhysicalMeasurements["MiliMeter"] = "mm";
29
+ PhysicalMeasurements["Meter"] = "m";
30
+ PhysicalMeasurements["KiloMeter"] = "km";
31
+ PhysicalMeasurements["Feet"] = "ft";
32
+ // Time
33
+ // -------------------------------------------------
34
+ PhysicalMeasurements["Second"] = "s";
35
+ PhysicalMeasurements["Minute"] = "min";
36
+ PhysicalMeasurements["Hour"] = "h";
37
+ PhysicalMeasurements["Day"] = "day";
38
+ // Frequency
39
+ // -------------------------------------------------
40
+ PhysicalMeasurements["Hertz"] = "Hz";
41
+ // Volume
42
+ // -------------------------------------------------
43
+ PhysicalMeasurements["CubicMeter"] = "m^3";
44
+ PhysicalMeasurements["Liter"] = "l";
45
+ PhysicalMeasurements["Gallon"] = "gal";
46
+ // Pressure
47
+ // -------------------------------------------------
48
+ PhysicalMeasurements["Psi"] = "psi";
49
+ PhysicalMeasurements["Pascal"] = "Pa";
50
+ PhysicalMeasurements["Bar"] = "bar";
51
+ // Temperature
52
+ // -------------------------------------------------
53
+ PhysicalMeasurements["Celsius"] = "\u00B0C";
54
+ PhysicalMeasurements["Fahrenheit"] = "\u00B0F";
55
+ PhysicalMeasurements["Kelvin"] = "K";
56
+ // Energy
57
+ // -------------------------------------------------
58
+ PhysicalMeasurements["Milijoule"] = "mJ";
59
+ PhysicalMeasurements["Joule"] = "J";
60
+ PhysicalMeasurements["Kilojoule"] = "kJ";
61
+ PhysicalMeasurements["Megajoule"] = "MJ";
62
+ PhysicalMeasurements["Gigajoule"] = "GJ";
63
+ PhysicalMeasurements["Terajoule"] = "TJ";
64
+ // Force
65
+ // -------------------------------------------------
66
+ PhysicalMeasurements["Newton"] = "N";
67
+ // Data
68
+ // -------------------------------------------------
69
+ PhysicalMeasurements["Bit"] = "bit";
70
+ PhysicalMeasurements["Byte"] = "byte";
71
+ PhysicalMeasurements["B"] = "B";
72
+ // Speed
73
+ // -------------------------------------------------
74
+ PhysicalMeasurements["MilimeterPerSecond"] = "mm/s";
75
+ PhysicalMeasurements["MeterPerSecond"] = "m/s";
76
+ PhysicalMeasurements["MeterPerMinute"] = "m/min";
77
+ PhysicalMeasurements["CentiMeterPerSecond"] = "cm/s";
78
+ PhysicalMeasurements["MeterPerHour"] = "m/h";
79
+ PhysicalMeasurements["KilometerPerHour"] = "km/h";
80
+ // Rotational Speed
81
+ // -------------------------------------------------
82
+ PhysicalMeasurements["RevolutionsPerMinute"] = "rpm";
83
+ // Percentage
84
+ // -------------------------------------------------
85
+ PhysicalMeasurements["Percent"] = "percent";
86
+ // Parts Per
87
+ // -------------------------------------------------
88
+ PhysicalMeasurements["PartsPerMillion"] = "ppm";
89
+ PhysicalMeasurements["PartsPerBillion"] = "ppb";
90
+ PhysicalMeasurements["PartsPerTrillion"] = "ppt";
91
+ // Other Angular Units
92
+ // -------------------------------------------------
93
+ PhysicalMeasurements["Decibel"] = "dB";
94
+ PhysicalMeasurements["Degree"] = "\u00B0";
95
+ PhysicalMeasurements["Radian"] = "rad";
96
+ // Mass
97
+ // -------------------------------------------------
98
+ PhysicalMeasurements["Miligram"] = "mg";
99
+ PhysicalMeasurements["Gram"] = "g";
100
+ PhysicalMeasurements["Kilogram"] = "kg";
101
+ PhysicalMeasurements["MetricTon"] = "t";
102
+ // Electric Potential
103
+ // -------------------------------------------------
104
+ PhysicalMeasurements["MiliVolt"] = "mV";
105
+ PhysicalMeasurements["Volt"] = "V";
106
+ PhysicalMeasurements["KiloVolt"] = "kV";
107
+ PhysicalMeasurements["MegaVolt"] = "MV";
108
+ // Electric Current
109
+ // -------------------------------------------------
110
+ PhysicalMeasurements["MiliAmpere"] = "mA";
111
+ PhysicalMeasurements["Ampere"] = "A";
112
+ PhysicalMeasurements["KiloAmpere"] = "kA";
113
+ PhysicalMeasurements["MegaAmpere"] = "MA";
114
+ // Power
115
+ // -------------------------------------------------
116
+ PhysicalMeasurements["MiliWatt"] = "mW";
117
+ PhysicalMeasurements["Watt"] = "W";
118
+ PhysicalMeasurements["KiloWatt"] = "kW";
119
+ PhysicalMeasurements["MegaWatt"] = "MW";
120
+ // Energy per unit time
121
+ // -------------------------------------------------
122
+ PhysicalMeasurements["MiliWattHour"] = "mWh";
123
+ PhysicalMeasurements["WattHour"] = "Wh";
124
+ PhysicalMeasurements["KiloWattHour"] = "kWh";
125
+ PhysicalMeasurements["MegaWattHour"] = "MWh";
126
+ // Apparent Power
127
+ // -------------------------------------------------
128
+ PhysicalMeasurements["MiliVoltAmpere"] = "mVA";
129
+ PhysicalMeasurements["VoltAmpere"] = "VA";
130
+ PhysicalMeasurements["KiloVoltAmpere"] = "kVA";
131
+ PhysicalMeasurements["MegaVoltAmpere"] = "MVA";
132
+ // Reactive Power
133
+ // -------------------------------------------------
134
+ PhysicalMeasurements["MiliVoltAmpereReactive"] = "mVAR";
135
+ PhysicalMeasurements["VoltAmpereReactive"] = "VAR";
136
+ PhysicalMeasurements["KiloVoltAmpereReactive"] = "kVAR";
137
+ PhysicalMeasurements["MegaVoltAmpereReactive"] = "MVAR";
138
+ // Flow Rates
139
+ // -------------------------------------------------
140
+ PhysicalMeasurements["CubicMeterPerHour"] = "m^3/h";
141
+ PhysicalMeasurements["CubicMeterPerSecond"] = "m^3/s";
142
+ // Other
143
+ // -------------------------------------------------
144
+ PhysicalMeasurements["MegaGramPerHour"] = "Mg/h";
145
+ PhysicalMeasurements["MetricTonPerHour"] = "t/h";
146
+ })(PhysicalMeasurements || (PhysicalMeasurements = {}));
@@ -0,0 +1,28 @@
1
+ import { IUnsPacket, ISO8601, IUnsMessage, IUnsPackatParameters } from "./uns-interfaces.js";
2
+ export declare class UnsPacket {
3
+ /**
4
+ * The given TypeScript function parseMqttPacket is used to parse an MQTT packet,
5
+ * which is presumed to be in JSON format. The goal is to transform this string into
6
+ * a structured object that adheres to the IUnsPacket interface, or return null
7
+ * if parsing fails.
8
+ *
9
+ * @param mqttPacket
10
+ * @param instanceName
11
+ * @returns IUnsPacket
12
+ */
13
+ static parseMqttPacket(mqttPacket: string, instanceName?: string): IUnsPacket | null;
14
+ /**
15
+ * Validates the data and event objects to ensure they have the required properties
16
+ * and that those properties have the correct types.
17
+ *
18
+ * @param data - The data object to validate
19
+ * @param event - The event object to validate
20
+ * @returns boolean | null
21
+ */
22
+ private static validateMessageComponents;
23
+ static unsPacketFromUnsMessage(message: IUnsMessage, unsPackatParameters?: IUnsPackatParameters): Promise<IUnsPacket>;
24
+ private static generateHmac;
25
+ static formatToISO8601(date: Date): ISO8601;
26
+ private static compressString;
27
+ private static decompressString;
28
+ }
@@ -0,0 +1,223 @@
1
+ import * as crypto from "crypto";
2
+ import * as zlib from "zlib";
3
+ import logger from '../logger.js';
4
+ import { isIOS8601Type } from "./uns-interfaces.js";
5
+ // Version of the packet library
6
+ const unsPacketVersion = "1.2.0";
7
+ export class UnsPacket {
8
+ /**
9
+ * The given TypeScript function parseMqttPacket is used to parse an MQTT packet,
10
+ * which is presumed to be in JSON format. The goal is to transform this string into
11
+ * a structured object that adheres to the IUnsPacket interface, or return null
12
+ * if parsing fails.
13
+ *
14
+ * @param mqttPacket
15
+ * @param instanceName
16
+ * @returns IUnsPacket
17
+ */
18
+ static parseMqttPacket(mqttPacket, instanceName) {
19
+ try {
20
+ const parsedMqttPacket = JSON.parse(mqttPacket);
21
+ // Check uns packet
22
+ if (parsedMqttPacket && parsedMqttPacket.version) {
23
+ const version = parsedMqttPacket.version;
24
+ const command = parsedMqttPacket.message.command;
25
+ const event = parsedMqttPacket.message.event;
26
+ const data = parsedMqttPacket.message.data;
27
+ const table = parsedMqttPacket.message.table;
28
+ const expiresAt = parsedMqttPacket.message.expiresAt;
29
+ const createdAt = parsedMqttPacket.message.createdAt;
30
+ // Validate data and event objects
31
+ UnsPacket.validateMessageComponents(data, event, table);
32
+ const message = {
33
+ ...(command !== undefined && { command }),
34
+ ...(data !== undefined && { data }),
35
+ ...(table !== undefined && { table }),
36
+ ...(event !== undefined && { event }),
37
+ ...(expiresAt !== undefined && { expiresAt }),
38
+ ...(createdAt !== undefined && { createdAt }),
39
+ };
40
+ const messageSignature = parsedMqttPacket.messageSignature;
41
+ const interval = parsedMqttPacket.interval;
42
+ const unsPacket = {
43
+ message,
44
+ messageSignature,
45
+ version,
46
+ interval
47
+ };
48
+ return unsPacket;
49
+ }
50
+ else {
51
+ logger.debug("Version number not specified in the mqtt packet");
52
+ }
53
+ }
54
+ catch (error) {
55
+ if (instanceName) {
56
+ logger.error(`${instanceName} - Could not parse packet: ${error}`);
57
+ }
58
+ else {
59
+ logger.error(`Could not parse packet: ${error}`);
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Validates the data and event objects to ensure they have the required properties
65
+ * and that those properties have the correct types.
66
+ *
67
+ * @param data - The data object to validate
68
+ * @param event - The event object to validate
69
+ * @returns boolean | null
70
+ */
71
+ static validateMessageComponents(data, event, table) {
72
+ if (data) {
73
+ if (data.dataGroup) {
74
+ if (!/^[A-Za-z0-9_]+$/.test(data.dataGroup)) {
75
+ throw new Error(`dataGroup must be a valid name (alphanumeric and underscores only, no spaces or special characters)`);
76
+ }
77
+ }
78
+ if (!data.time)
79
+ throw new Error(`Time is not defined in data object`);
80
+ if (!isIOS8601Type(data.time))
81
+ throw new Error(`Time is not ISO8601`);
82
+ }
83
+ // Check event object
84
+ if (event) {
85
+ if (event.dataGroup) {
86
+ if (!/^[A-Za-z0-9_]+$/.test(event.dataGroup)) {
87
+ throw new Error(`dataGroup must be a valid name (alphanumeric and underscores only, no spaces or special characters)`);
88
+ }
89
+ }
90
+ if (!event.time) {
91
+ throw new Error(`Time is not defined in data object`);
92
+ }
93
+ if (!isIOS8601Type(event.time))
94
+ throw new Error(`Time is not ISO8601`);
95
+ }
96
+ // Check table object
97
+ if (table) {
98
+ if (table.dataGroup) {
99
+ if (!/^[A-Za-z0-9_]+$/.test(table.dataGroup)) {
100
+ throw new Error(`dataGroup must be a valid name (alphanumeric and underscores only, no spaces or special characters)`);
101
+ }
102
+ }
103
+ if (!table.time) {
104
+ throw new Error(`Time is not defined in data object`);
105
+ }
106
+ if (!isIOS8601Type(table.time)) {
107
+ throw new Error(`Time is not ISO8601`);
108
+ }
109
+ const oldTable = table;
110
+ if (oldTable.tableName) {
111
+ logger.debug(`The 'tableName' property is deprecated. Use 'dataGroup' instead.`);
112
+ }
113
+ else if (table.values) {
114
+ Object.entries(table.values).forEach(([key, value]) => {
115
+ if (typeof value !== "number" &&
116
+ typeof value !== "string" &&
117
+ value !== null &&
118
+ value !== undefined) {
119
+ throw new Error(`Value for key '${key}' in table.values must be of type number, string, null, or undefined`);
120
+ }
121
+ });
122
+ }
123
+ else {
124
+ throw new Error(`No values for table`);
125
+ }
126
+ }
127
+ return true;
128
+ }
129
+ static async unsPacketFromUnsMessage(message, unsPackatParameters) {
130
+ try {
131
+ // Validate the packet in message
132
+ if (UnsPacket.validateMessageComponents(message.data, message.event, message.table)) {
133
+ if (unsPackatParameters) {
134
+ // if (
135
+ // unsPackatParameters.compressCommand &&
136
+ // unsPackatParameters.compressCommand == true
137
+ // ) {
138
+ // message.command = (
139
+ // await this.compressString(message.command)
140
+ // ).toString();
141
+ // }
142
+ }
143
+ // HMAC
144
+ // const algorithm = "sha256";
145
+ // const key = "your-secret-key";
146
+ // const packetMessage = JSON.stringify(message);
147
+ // const hmacHash = this.generateHmac(algorithm, key, packetMessage);
148
+ // const unsPacket: IUnsPacket = {
149
+ // message,
150
+ // messageSignature: hmacHash,
151
+ // version: unsPacketVersion
152
+ // };
153
+ let data = undefined;
154
+ if (message.data && message.data.value !== undefined) {
155
+ data = {
156
+ ...message.data,
157
+ valueType: typeof message.data.value
158
+ };
159
+ }
160
+ ;
161
+ const extendedMessage = {
162
+ command: message.command,
163
+ data,
164
+ table: message.table,
165
+ event: message.event,
166
+ expiresAt: message.expiresAt,
167
+ createdAt: message.createdAt,
168
+ };
169
+ const unsPacket = {
170
+ message: extendedMessage,
171
+ version: unsPacketVersion,
172
+ };
173
+ return unsPacket;
174
+ }
175
+ }
176
+ catch (error) {
177
+ logger.error(`Could not create packet from message: ${error}`);
178
+ }
179
+ }
180
+ static generateHmac(algorithm, key, data) {
181
+ const hmac = crypto.createHmac(algorithm, key);
182
+ hmac.update(data);
183
+ return hmac.digest("hex");
184
+ }
185
+ static formatToISO8601(date) {
186
+ const year = date.getUTCFullYear();
187
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
188
+ const day = String(date.getUTCDate()).padStart(2, "0");
189
+ const hours = String(date.getUTCHours()).padStart(2, "0");
190
+ const minutes = String(date.getUTCMinutes()).padStart(2, "0");
191
+ const seconds = String(date.getUTCSeconds()).padStart(2, "0");
192
+ const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
193
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;
194
+ }
195
+ static compressString(input) {
196
+ return new Promise((resolve, reject) => {
197
+ zlib.deflate(input, (err, buffer) => {
198
+ if (err) {
199
+ reject(err);
200
+ }
201
+ else {
202
+ const base64String = buffer.toString("base64");
203
+ resolve(base64String);
204
+ }
205
+ });
206
+ });
207
+ }
208
+ // Function to decompress a Buffer back to a string
209
+ static decompressString(base64Compressed) {
210
+ return new Promise((resolve, reject) => {
211
+ // Decode the base64 string to a Buffer
212
+ const compressedBuffer = Buffer.from(base64Compressed, "base64");
213
+ zlib.inflate(compressedBuffer, (err, buffer) => {
214
+ if (err) {
215
+ reject(err);
216
+ }
217
+ else {
218
+ resolve(buffer.toString());
219
+ }
220
+ });
221
+ });
222
+ }
223
+ }
@@ -0,0 +1,56 @@
1
+ import { IUnsParameters, IUnsProcessParameters } from "./uns-interfaces.js";
2
+ import UnsMqttProxy from "../uns-mqtt/uns-mqtt-proxy.js";
3
+ /**
4
+ * UnsProxyProcess is responsible for managing the process lifecycle,
5
+ * configuring MQTT (subscriptions and publishing for status updates), and
6
+ * handling UNS proxy instances.
7
+ *
8
+ * It leverages HandoverManager for handover events and StatusMonitor for health reporting.
9
+ */
10
+ export type UnsProxyProcessPluginMethod = (this: UnsProxyProcess, ...args: unknown[]) => unknown;
11
+ export type UnsProxyProcessPluginMethods = Record<string, UnsProxyProcessPluginMethod>;
12
+ export interface UnsProxyProcessPluginApi {
13
+ version: number;
14
+ define(methods: UnsProxyProcessPluginMethods): void;
15
+ UnsProxyProcess: typeof UnsProxyProcess;
16
+ }
17
+ export type UnsProxyProcessPlugin = (api: UnsProxyProcessPluginApi) => void;
18
+ declare class UnsProxyProcess {
19
+ private active;
20
+ private processStatusTopic;
21
+ private processName;
22
+ private unsMqttProxies;
23
+ private unsApiProxies;
24
+ private unsTemporalProxies;
25
+ private processMqttProxy;
26
+ private handoverManager;
27
+ private statusMonitor;
28
+ static pluginApiVersion: number;
29
+ private static registered;
30
+ private static registeredMethodNames;
31
+ private static applied;
32
+ static use(plugin: UnsProxyProcessPlugin): typeof UnsProxyProcess;
33
+ private static applyPlugin;
34
+ private static applyAll;
35
+ private mqttInputHandler;
36
+ constructor(mqttHost: string, unsProxyProcessParameters?: IUnsProcessParameters);
37
+ /**
38
+ * Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.
39
+ * Determines handover and force start modes based on process arguments.
40
+ */
41
+ private initHandoverManager;
42
+ /**
43
+ * Creates a new UNS proxy instance and stores it for future management.
44
+ */
45
+ createUnsMqttProxy(mqttHost: string, instanceName: string, instanceMode: string, handover: boolean, unsParameters?: IUnsParameters): Promise<UnsMqttProxy>;
46
+ waitForProcessConnection(): Promise<void>;
47
+ /**
48
+ * Shuts down the process by clearing intervals, timeouts, and removing
49
+ * MQTT event listeners, and stopping the StatusMonitor.
50
+ */
51
+ shutdown(): void;
52
+ }
53
+ interface UnsProxyProcess {
54
+ }
55
+ export default UnsProxyProcess;
56
+ export { UnsProxyProcess };