@onlineapps/conn-orch-registry 1.1.49 → 1.1.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-orch-registry",
3
- "version": "1.1.49",
3
+ "version": "1.1.50",
4
4
  "license": "MIT",
5
5
  "description": "Connector-registry-client provides the core communication mechanism for microservices in this environment. It enables them to interact with a services_registry to receive and fulfill tasks by submitting heartbeats or their API descriptions.",
6
6
  "keywords": [
@@ -37,7 +37,7 @@ class ServiceRegistryClient extends EventEmitter {
37
37
  */
38
38
  constructor({ amqpUrl, serviceName, version, specificationEndpoint = '/api/v1/specification',
39
39
  heartbeatInterval = 10000, apiQueue = 'api_services_queuer', registryQueue = 'registry.register',
40
- redis = null, storageConfig = {}, validationProof = null }) {
40
+ registryUrl = null, redis = null, storageConfig = {}, validationProof = null }) {
41
41
  super();
42
42
  if (!amqpUrl || !serviceName || !version) {
43
43
  throw new Error('amqpUrl, serviceName, and version are required');
@@ -49,6 +49,7 @@ class ServiceRegistryClient extends EventEmitter {
49
49
  this.heartbeatInterval = heartbeatInterval;
50
50
  this.apiQueue = apiQueue;
51
51
  this.registryQueue = registryQueue;
52
+ this.registryUrl = registryUrl;
52
53
  this.queueManager = new QueueManager(amqpUrl, serviceName);
53
54
  this.heartbeatTimer = null;
54
55
 
@@ -706,27 +707,41 @@ class ServiceRegistryClient extends EventEmitter {
706
707
  * @returns {Promise<{serviceName: string, status: 'active'|'inactive', version?: string, fingerprint?: string, bucket?: string, path?: string, updatedAt?: string} | null>}
707
708
  */
708
709
  async getService(serviceName) {
709
- if (!this.eventConsumer) {
710
- throw new Error('[RegistryClient] getService - Event consumer not initialized. Fix: call subscribeToChanges() before service discovery.');
711
- }
712
710
  if (!serviceName || typeof serviceName !== 'string') {
713
711
  throw new Error('[RegistryClient] getService - serviceName is required and must be a string');
714
712
  }
715
713
 
716
- const info = this.eventConsumer.getServiceInfo(serviceName);
717
- if (!info) {
714
+ if (!this.registryUrl || typeof this.registryUrl !== 'string') {
715
+ throw new Error('[RegistryClient] getService - Missing required config: registryUrl. Fix: pass wrapper.registry.url into ServiceRegistryClient.');
716
+ }
717
+
718
+ // Primary source of truth for service availability is the central registry HTTP API.
719
+ // This avoids relying on optional event subscriptions and ensures deterministic routing.
720
+ const url = `${this.registryUrl.replace(/\/$/, '')}/services`;
721
+ let response;
722
+ try {
723
+ response = await fetch(url, { method: 'GET' });
724
+ } catch (err) {
725
+ throw new Error(`[RegistryClient] getService - Registry HTTP request failed (${url}). Problem: ${err.message}`);
726
+ }
727
+
728
+ if (!response.ok) {
729
+ throw new Error(`[RegistryClient] getService - Registry HTTP request failed (${url}). Status: ${response.status}`);
730
+ }
731
+
732
+ const data = await response.json();
733
+ const entry = data && data.services ? data.services[serviceName] : null;
734
+ if (!entry) {
718
735
  return null;
719
736
  }
720
737
 
721
- const normalizedStatus = info.status === 'ACTIVE' ? 'active' : 'inactive';
738
+ // Registry stores status as 'active'/'inactive' (lowercase).
722
739
  return {
723
740
  serviceName,
724
- status: normalizedStatus,
725
- version: info.version,
726
- fingerprint: info.fingerprint,
727
- bucket: info.bucket,
728
- path: info.path,
729
- updatedAt: info.updatedAt
741
+ status: entry.status,
742
+ version: entry.version,
743
+ lastHeartbeatAt: entry.lastHeartbeatAt,
744
+ isAvailable: entry.isAvailable
730
745
  };
731
746
  }
732
747