@cadenza.io/service 2.17.74 → 2.17.76
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/browser/index.js +85 -53
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +85 -53
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +120 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -1212,39 +1212,12 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1212
1212
|
if (trackedInstance?.isFrontend) {
|
|
1213
1213
|
return true;
|
|
1214
1214
|
}
|
|
1215
|
-
const trackedTransport = this.getRouteableTransport(
|
|
1216
|
-
trackedInstance,
|
|
1217
|
-
this.useSocket ? "socket" : "rest"
|
|
1218
|
-
);
|
|
1219
1215
|
if (this.deputies.has(serviceName) || this.remoteIntents.has(serviceName) || this.remoteSignals.has(serviceName)) {
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
)
|
|
1216
|
+
const connected = this.ensureDependeeClientForInstance(
|
|
1217
|
+
trackedInstance,
|
|
1218
|
+
emit
|
|
1224
1219
|
);
|
|
1225
|
-
if (!
|
|
1226
|
-
communicationTypes.push("signal");
|
|
1227
|
-
}
|
|
1228
|
-
if (trackedTransport) {
|
|
1229
|
-
const clientCreated = this.hasTransportClientCreated(
|
|
1230
|
-
trackedInstance,
|
|
1231
|
-
trackedTransport.uuid
|
|
1232
|
-
);
|
|
1233
|
-
if (!clientCreated) {
|
|
1234
|
-
emit("meta.service_registry.dependee_registered", {
|
|
1235
|
-
serviceName,
|
|
1236
|
-
serviceInstanceId: uuid7,
|
|
1237
|
-
serviceTransportId: trackedTransport.uuid,
|
|
1238
|
-
serviceOrigin: trackedTransport.origin,
|
|
1239
|
-
transportProtocols: trackedTransport.protocols,
|
|
1240
|
-
communicationTypes
|
|
1241
|
-
});
|
|
1242
|
-
this.markTransportClientCreated(
|
|
1243
|
-
trackedInstance,
|
|
1244
|
-
trackedTransport.uuid
|
|
1245
|
-
);
|
|
1246
|
-
}
|
|
1247
|
-
} else {
|
|
1220
|
+
if (!connected) {
|
|
1248
1221
|
emit("meta.service_registry.routeable_transport_missing", {
|
|
1249
1222
|
serviceName,
|
|
1250
1223
|
serviceInstanceId: uuid7,
|
|
@@ -1310,25 +1283,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1310
1283
|
if (!hasRemoteInterest) {
|
|
1311
1284
|
return true;
|
|
1312
1285
|
}
|
|
1313
|
-
|
|
1314
|
-
const communicationTypes = Array.from(
|
|
1315
|
-
new Set(
|
|
1316
|
-
this.deputies.get(ownerInstance.serviceName)?.map((descriptor) => descriptor.communicationType) ?? []
|
|
1317
|
-
)
|
|
1318
|
-
);
|
|
1319
|
-
if (!communicationTypes.includes("signal") && this.remoteSignals.has(ownerInstance.serviceName)) {
|
|
1320
|
-
communicationTypes.push("signal");
|
|
1321
|
-
}
|
|
1322
|
-
emit("meta.service_registry.dependee_registered", {
|
|
1323
|
-
serviceName: ownerInstance.serviceName,
|
|
1324
|
-
serviceInstanceId: ownerInstance.uuid,
|
|
1325
|
-
serviceTransportId: transport.uuid,
|
|
1326
|
-
serviceOrigin: transport.origin,
|
|
1327
|
-
transportProtocols: transport.protocols,
|
|
1328
|
-
communicationTypes
|
|
1329
|
-
});
|
|
1330
|
-
this.markTransportClientCreated(ownerInstance, transport.uuid);
|
|
1331
|
-
}
|
|
1286
|
+
this.ensureDependeeClientForInstance(ownerInstance, emit);
|
|
1332
1287
|
return true;
|
|
1333
1288
|
},
|
|
1334
1289
|
"Handles service transport updates independently from instance rows."
|
|
@@ -1409,7 +1364,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1409
1364
|
).emits("meta.service_registry.registered_global_signals").doOn("global.meta.cadenza_db.gathered_sync_data");
|
|
1410
1365
|
this.handleGlobalIntentRegistrationTask = CadenzaService.createMetaTask(
|
|
1411
1366
|
"Handle global intent registration",
|
|
1412
|
-
(ctx) => {
|
|
1367
|
+
(ctx, emit) => {
|
|
1413
1368
|
const intentToTaskMaps = this.normalizeIntentMaps(ctx);
|
|
1414
1369
|
const sorted = intentToTaskMaps.sort((a, b) => {
|
|
1415
1370
|
if (a.deleted && !b.deleted) return -1;
|
|
@@ -1425,6 +1380,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1425
1380
|
name: map.intentName
|
|
1426
1381
|
});
|
|
1427
1382
|
this.registerRemoteIntentDeputy(map);
|
|
1383
|
+
this.ensureDependeeClientsForService(map.serviceName, emit);
|
|
1428
1384
|
}
|
|
1429
1385
|
return true;
|
|
1430
1386
|
},
|
|
@@ -2850,6 +2806,49 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
2850
2806
|
}
|
|
2851
2807
|
return buildTransportClientKey(transport);
|
|
2852
2808
|
}
|
|
2809
|
+
resolveCommunicationTypesForService(serviceName) {
|
|
2810
|
+
const communicationTypes = Array.from(
|
|
2811
|
+
new Set(
|
|
2812
|
+
this.deputies.get(serviceName)?.map((descriptor) => descriptor.communicationType) ?? []
|
|
2813
|
+
)
|
|
2814
|
+
);
|
|
2815
|
+
if (!communicationTypes.includes("signal") && this.remoteSignals.has(serviceName)) {
|
|
2816
|
+
communicationTypes.push("signal");
|
|
2817
|
+
}
|
|
2818
|
+
return communicationTypes;
|
|
2819
|
+
}
|
|
2820
|
+
ensureDependeeClientForInstance(instance, emit) {
|
|
2821
|
+
if (!instance || instance.uuid === this.serviceInstanceId || instance.isFrontend || !instance.isActive || instance.isNonResponsive || instance.isBlocked) {
|
|
2822
|
+
return false;
|
|
2823
|
+
}
|
|
2824
|
+
if (!this.deputies.has(instance.serviceName) && !this.remoteIntents.has(instance.serviceName) && !this.remoteSignals.has(instance.serviceName)) {
|
|
2825
|
+
return false;
|
|
2826
|
+
}
|
|
2827
|
+
const transport = this.getRouteableTransport(
|
|
2828
|
+
instance,
|
|
2829
|
+
this.useSocket ? "socket" : "rest"
|
|
2830
|
+
);
|
|
2831
|
+
if (!transport || this.hasTransportClientCreated(instance, transport.uuid)) {
|
|
2832
|
+
return false;
|
|
2833
|
+
}
|
|
2834
|
+
emit("meta.service_registry.dependee_registered", {
|
|
2835
|
+
serviceName: instance.serviceName,
|
|
2836
|
+
serviceInstanceId: instance.uuid,
|
|
2837
|
+
serviceTransportId: transport.uuid,
|
|
2838
|
+
serviceOrigin: transport.origin,
|
|
2839
|
+
transportProtocols: transport.protocols,
|
|
2840
|
+
communicationTypes: this.resolveCommunicationTypesForService(
|
|
2841
|
+
instance.serviceName
|
|
2842
|
+
)
|
|
2843
|
+
});
|
|
2844
|
+
this.markTransportClientCreated(instance, transport.uuid);
|
|
2845
|
+
return true;
|
|
2846
|
+
}
|
|
2847
|
+
ensureDependeeClientsForService(serviceName, emit) {
|
|
2848
|
+
for (const instance of this.instances.get(serviceName) ?? []) {
|
|
2849
|
+
this.ensureDependeeClientForInstance(instance, emit);
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2853
2852
|
hasTransportClientCreated(instance, transportId) {
|
|
2854
2853
|
return (instance.clientCreatedTransportIds ?? []).includes(transportId);
|
|
2855
2854
|
}
|
|
@@ -3633,13 +3632,14 @@ var RestController = class _RestController {
|
|
|
3633
3632
|
this.diagnosticsErrorHistoryLimit = 100;
|
|
3634
3633
|
this.diagnosticsMaxClientEntries = 500;
|
|
3635
3634
|
this.destroyedDiagnosticsTtlMs = 15 * 6e4;
|
|
3636
|
-
this.fetchDataWithTimeout = async
|
|
3635
|
+
this.fetchDataWithTimeout = async (url, requestInit, timeoutMs) => {
|
|
3637
3636
|
if (typeof globalThis.fetch !== "function") {
|
|
3638
3637
|
throw new Error("Browser REST controller requires global fetch.");
|
|
3639
3638
|
}
|
|
3640
3639
|
const signal = AbortSignal.timeout(timeoutMs);
|
|
3641
3640
|
const response = await globalThis.fetch(url, { ...requestInit, signal });
|
|
3642
|
-
|
|
3641
|
+
const parsedResponse = await this.parseFetchResponse(response);
|
|
3642
|
+
return parsedResponse.data;
|
|
3643
3643
|
};
|
|
3644
3644
|
CadenzaService.createMetaTask(
|
|
3645
3645
|
"Collect fetch transport diagnostics",
|
|
@@ -3985,6 +3985,38 @@ var RestController = class _RestController {
|
|
|
3985
3985
|
return String(error);
|
|
3986
3986
|
}
|
|
3987
3987
|
}
|
|
3988
|
+
async parseFetchResponse(response) {
|
|
3989
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
3990
|
+
const rawText = await response.text();
|
|
3991
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
3992
|
+
if (rawText.length === 0) {
|
|
3993
|
+
return {
|
|
3994
|
+
ok: response.ok,
|
|
3995
|
+
status: response.status,
|
|
3996
|
+
statusText: response.statusText,
|
|
3997
|
+
headers,
|
|
3998
|
+
data: {}
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
if (!contentType.toLowerCase().includes("application/json")) {
|
|
4002
|
+
throw new Error(
|
|
4003
|
+
`Expected JSON response from ${response.url ?? "remote service"} but received ${contentType || "unknown content type"} (HTTP ${response.status}). Body preview: ${rawText.slice(0, 200)}`
|
|
4004
|
+
);
|
|
4005
|
+
}
|
|
4006
|
+
try {
|
|
4007
|
+
return {
|
|
4008
|
+
ok: response.ok,
|
|
4009
|
+
status: response.status,
|
|
4010
|
+
statusText: response.statusText,
|
|
4011
|
+
headers,
|
|
4012
|
+
data: JSON.parse(rawText)
|
|
4013
|
+
};
|
|
4014
|
+
} catch (error) {
|
|
4015
|
+
throw new Error(
|
|
4016
|
+
`Failed to parse JSON response from ${response.url ?? "remote service"} (HTTP ${response.status}). Body preview: ${rawText.slice(0, 200)}. Parse error: ${this.getErrorMessage(error)}`
|
|
4017
|
+
);
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
3988
4020
|
recordFetchClientError(fetchId, serviceName, url, error) {
|
|
3989
4021
|
const state = this.ensureFetchClientDiagnostics(fetchId, serviceName, url);
|
|
3990
4022
|
const message = this.getErrorMessage(error);
|