@cadenza.io/service 1.10.0 → 1.10.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.
- package/dist/index.js +62 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -338,16 +338,16 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
338
338
|
"Handle Instance Update",
|
|
339
339
|
(ctx, emit) => {
|
|
340
340
|
var _a2;
|
|
341
|
-
const {
|
|
342
|
-
const { id, serviceName, address, port, exposed } =
|
|
341
|
+
const { service_instance } = ctx;
|
|
342
|
+
const { id, serviceName, address, port, exposed } = service_instance;
|
|
343
343
|
if (!this.instances.has(serviceName))
|
|
344
344
|
this.instances.set(serviceName, []);
|
|
345
345
|
const instances = this.instances.get(serviceName);
|
|
346
346
|
const existing = instances.find((i) => i.id === id);
|
|
347
347
|
if (existing) {
|
|
348
|
-
Object.assign(existing,
|
|
348
|
+
Object.assign(existing, service_instance);
|
|
349
349
|
} else {
|
|
350
|
-
if (this.deputies.has(serviceName) || this.remoteSignals.has(serviceName) || this.remoteSignals.has("*")) {
|
|
350
|
+
if (this.deputies.has(serviceName) || this.remoteSignals.has(serviceName) || this.remoteSignals.has("*") && this.serviceName !== serviceName) {
|
|
351
351
|
const communicationTypes = Array.from(
|
|
352
352
|
new Set(
|
|
353
353
|
(_a2 = this.deputies.get(serviceName).map((d) => d.communicationType)) != null ? _a2 : []
|
|
@@ -364,7 +364,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
364
364
|
protocol: exposed ? "https" : "http",
|
|
365
365
|
communicationTypes
|
|
366
366
|
});
|
|
367
|
-
|
|
367
|
+
service_instance.clientCreated = true;
|
|
368
368
|
for (const instance of this.instances.get(serviceName)) {
|
|
369
369
|
if (instance.clientCreated) continue;
|
|
370
370
|
instance.clientCreated = true;
|
|
@@ -378,7 +378,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
instances.push(
|
|
381
|
+
instances.push(service_instance);
|
|
382
382
|
}
|
|
383
383
|
return true;
|
|
384
384
|
},
|
|
@@ -1344,53 +1344,58 @@ var SocketController = class _SocketController {
|
|
|
1344
1344
|
if (!ctx.__useSocket) {
|
|
1345
1345
|
return;
|
|
1346
1346
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
limiter
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1347
|
+
console.log("SocketServer: Setting up", ctx);
|
|
1348
|
+
try {
|
|
1349
|
+
const server = new import_socket.Server((_a2 = ctx.__httpsServer) != null ? _a2 : ctx.__httpServer);
|
|
1350
|
+
ctx.__socketServer = server;
|
|
1351
|
+
const profile = (_b2 = ctx.__securityProfile) != null ? _b2 : "medium";
|
|
1352
|
+
server.use((socket, next) => {
|
|
1353
|
+
var _a3;
|
|
1354
|
+
const origin = socket.handshake.headers.origin;
|
|
1355
|
+
const allowedOrigins = ["*"];
|
|
1356
|
+
const networkType = (_a3 = ctx.__networkType) != null ? _a3 : "internal";
|
|
1357
|
+
let effectiveOrigin = origin || "unknown";
|
|
1358
|
+
if (networkType === "internal") effectiveOrigin = "internal";
|
|
1359
|
+
if (profile !== "low" && !allowedOrigins.includes(effectiveOrigin) && !allowedOrigins.includes("*")) {
|
|
1360
|
+
return next(new Error("Unauthorized origin"));
|
|
1361
|
+
}
|
|
1362
|
+
const limiterOptions = {
|
|
1363
|
+
low: { points: Infinity, duration: 300 },
|
|
1364
|
+
medium: { points: 100, duration: 300 },
|
|
1365
|
+
high: { points: 50, duration: 60, blockDuration: 300 }
|
|
1366
|
+
};
|
|
1367
|
+
const limiter = new import_rate_limiter_flexible2.RateLimiterMemory(limiterOptions[profile]);
|
|
1368
|
+
socket.use((packet, next2) => {
|
|
1369
|
+
limiter.consume(socket.handshake.address).then(() => next2()).catch((rej) => {
|
|
1370
|
+
if (rej.msBeforeNext > 0) {
|
|
1371
|
+
socket.emit("error", {
|
|
1372
|
+
message: "Rate limit exceeded",
|
|
1373
|
+
retryAfter: rej.msBeforeNext / 1e3
|
|
1374
|
+
});
|
|
1375
|
+
} else {
|
|
1376
|
+
socket.disconnect(true);
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1376
1379
|
});
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1380
|
+
socket.use((packet, next2) => {
|
|
1381
|
+
if (profile !== "low") {
|
|
1382
|
+
const sanitize = (data) => {
|
|
1383
|
+
if (typeof data === "string") return (0, import_xss.default)(data);
|
|
1384
|
+
if (typeof data === "object") {
|
|
1385
|
+
for (const key in data) {
|
|
1386
|
+
data[key] = sanitize(data[key]);
|
|
1387
|
+
}
|
|
1385
1388
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1389
|
+
return data;
|
|
1390
|
+
};
|
|
1391
|
+
packet[1] = sanitize(packet[1]);
|
|
1392
|
+
}
|
|
1393
|
+
next2();
|
|
1394
|
+
});
|
|
1392
1395
|
});
|
|
1393
|
-
})
|
|
1396
|
+
} catch (err) {
|
|
1397
|
+
console.error("Socket setup error:", err);
|
|
1398
|
+
}
|
|
1394
1399
|
}).then(
|
|
1395
1400
|
CadenzaService.createMetaTask(
|
|
1396
1401
|
"Start SocketServer",
|
|
@@ -1649,6 +1654,9 @@ var SignalController = class _SignalController {
|
|
|
1649
1654
|
const firstChar = __signalName.charAt(0);
|
|
1650
1655
|
if (firstChar === firstChar.toUpperCase() && firstChar !== firstChar.toLowerCase() || firstChar === "*") {
|
|
1651
1656
|
const serviceName = __signalName.split(".")[0];
|
|
1657
|
+
if (CadenzaService.serviceRegistry.serviceName === serviceName) {
|
|
1658
|
+
return false;
|
|
1659
|
+
}
|
|
1652
1660
|
ctx.__listenerServiceName = CadenzaService.serviceRegistry.serviceName;
|
|
1653
1661
|
ctx.__emitterSignalName = __signalName.split(".").slice(1).join(".");
|
|
1654
1662
|
ctx.__signalName = "meta.signal_controller.foreign_signal_registered";
|
|
@@ -3630,8 +3638,8 @@ var CadenzaService = class {
|
|
|
3630
3638
|
if ((_g = options.cadenzaDB) == null ? void 0 : _g.connect) {
|
|
3631
3639
|
import_core3.default.broker.emit("meta.initializing_service", {
|
|
3632
3640
|
// Seed the CadenzaDB
|
|
3633
|
-
|
|
3634
|
-
|
|
3641
|
+
service_instance: {
|
|
3642
|
+
uuid: "cadenza-db",
|
|
3635
3643
|
serviceName: "CadenzaDB",
|
|
3636
3644
|
address: (_h = options.cadenzaDB) == null ? void 0 : _h.address,
|
|
3637
3645
|
port: (_i = options.cadenzaDB) == null ? void 0 : _i.port,
|
|
@@ -3648,8 +3656,8 @@ var CadenzaService = class {
|
|
|
3648
3656
|
(_j = options.relatedServices) == null ? void 0 : _j.forEach((service) => {
|
|
3649
3657
|
var _a3;
|
|
3650
3658
|
import_core3.default.broker.emit("meta.initializing_service", {
|
|
3651
|
-
|
|
3652
|
-
|
|
3659
|
+
service_instance: {
|
|
3660
|
+
uuid: service[0],
|
|
3653
3661
|
serviceName: service[1],
|
|
3654
3662
|
address: service[2].split(":")[0],
|
|
3655
3663
|
port: (_a3 = service[2].split(":")[1]) != null ? _a3 : 3e3,
|