@onlineapps/conn-orch-registry 1.1.11 → 1.1.13
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 +1 -2
- package/src/registryClient.js +11 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/conn-orch-registry",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
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": [
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@onlineapps/conn-base-storage": "^1.0.0",
|
|
42
|
-
"@onlineapps/conn-orch-registry": "^1.1.10",
|
|
43
42
|
"amqplib": "^0.10.3",
|
|
44
43
|
"axios": "^1.5.0",
|
|
45
44
|
"dotenv": "^16.1.4",
|
package/src/registryClient.js
CHANGED
|
@@ -19,8 +19,6 @@ const EventEmitter = require('events');
|
|
|
19
19
|
const QueueManager = require('./queueManager');
|
|
20
20
|
const RegistryEventConsumer = require('./registryEventConsumer');
|
|
21
21
|
const { v4: uuidv4 } = require('uuid');
|
|
22
|
-
const fs = require('fs');
|
|
23
|
-
const path = require('path');
|
|
24
22
|
|
|
25
23
|
class ServiceRegistryClient extends EventEmitter {
|
|
26
24
|
/**
|
|
@@ -32,10 +30,11 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
32
30
|
* @param {number} [opts.heartbeatInterval=10000] - Heartbeat interval in milliseconds
|
|
33
31
|
* @param {string} [opts.apiQueue='api_services_queuer'] - Queue name for heartbeat and API traffic
|
|
34
32
|
* @param {string} [opts.registryQueue='registry_office'] - Queue name for registry messages
|
|
33
|
+
* @param {Object} [opts.validationProof=null] - Validation proof object {hash, data} (injected from outside)
|
|
35
34
|
*/
|
|
36
35
|
constructor({ amqpUrl, serviceName, version, specificationEndpoint = '/api/v1/specification',
|
|
37
36
|
heartbeatInterval = 10000, apiQueue = 'api_services_queuer', registryQueue = 'registry.register',
|
|
38
|
-
redis = null, storageConfig = {} }) {
|
|
37
|
+
redis = null, storageConfig = {}, validationProof = null }) {
|
|
39
38
|
super();
|
|
40
39
|
if (!amqpUrl || !serviceName || !version) {
|
|
41
40
|
throw new Error('amqpUrl, serviceName, and version are required');
|
|
@@ -54,8 +53,8 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
54
53
|
this.redis = redis;
|
|
55
54
|
this.storageConfig = storageConfig;
|
|
56
55
|
|
|
57
|
-
// Validation proof (
|
|
58
|
-
this.validationProof =
|
|
56
|
+
// Validation proof (injected via constructor - DEPENDENCY INJECTION)
|
|
57
|
+
this.validationProof = validationProof;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
/**
|
|
@@ -65,10 +64,13 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
65
64
|
async init() {
|
|
66
65
|
await this.queueManager.init();
|
|
67
66
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
// Validation proof is now injected via constructor (not loaded here)
|
|
68
|
+
if (this.validationProof) {
|
|
69
|
+
console.log(`[RegistryClient] ${this.serviceName}: ✅ Validation proof provided via constructor`);
|
|
70
|
+
console.log(`[RegistryClient] ${this.serviceName}: Proof hash: ${this.validationProof.hash.substring(0, 32)}...`);
|
|
71
|
+
} else {
|
|
72
|
+
console.log(`[RegistryClient] ${this.serviceName}: ⚠️ No validation proof - will use Tier 2 validation`);
|
|
73
|
+
}
|
|
72
74
|
|
|
73
75
|
// Create service-specific response queue
|
|
74
76
|
this.serviceResponseQueue = `${this.serviceName}.responses`;
|
|
@@ -94,93 +96,6 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
94
96
|
);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
/**
|
|
98
|
-
* Loads validation proof from .validation-proof.json in service root directory.
|
|
99
|
-
* Called during initialization.
|
|
100
|
-
* @private
|
|
101
|
-
* @returns {Promise<void>}
|
|
102
|
-
*/
|
|
103
|
-
async _loadValidationProof() {
|
|
104
|
-
console.log(`[RegistryClient] ${this.serviceName}: >>> ENTERING _loadValidationProof() <<<`);
|
|
105
|
-
|
|
106
|
-
const proofPath = path.join(process.cwd(), '.validation-proof.json');
|
|
107
|
-
const debugLogPath = path.join(process.cwd(), '.validation-debug.log');
|
|
108
|
-
|
|
109
|
-
console.log(`[RegistryClient] ${this.serviceName}: CWD = ${process.cwd()}`);
|
|
110
|
-
console.log(`[RegistryClient] ${this.serviceName}: Proof path = ${proofPath}`);
|
|
111
|
-
|
|
112
|
-
// Write to file for debugging (append mode)
|
|
113
|
-
const log = (msg) => {
|
|
114
|
-
const timestamp = new Date().toISOString();
|
|
115
|
-
const logLine = `${timestamp} [${this.serviceName}] ${msg}\n`;
|
|
116
|
-
try {
|
|
117
|
-
fs.appendFileSync(debugLogPath, logLine);
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.error(`[RegistryClient] Failed to write debug log: ${err.message}`);
|
|
120
|
-
}
|
|
121
|
-
console.log(`[RegistryClient] ${msg}`);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
log('=== _loadValidationProof() CALLED ===');
|
|
125
|
-
log(`CWD: ${process.cwd()}`);
|
|
126
|
-
log(`Proof path: ${proofPath}`);
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
// Check file existence explicitly
|
|
130
|
-
if (!fs.existsSync(proofPath)) {
|
|
131
|
-
log(`⚠️ Validation proof file NOT FOUND`);
|
|
132
|
-
log(`Service will use Tier 2 validation`);
|
|
133
|
-
this.validationProof = null;
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
log(`✓ Proof file exists, reading...`);
|
|
138
|
-
|
|
139
|
-
// Read and parse file
|
|
140
|
-
const fileContent = fs.readFileSync(proofPath, 'utf8');
|
|
141
|
-
log(`✓ File read, size: ${fileContent.length} bytes`);
|
|
142
|
-
|
|
143
|
-
const proofData = JSON.parse(fileContent);
|
|
144
|
-
log(`✓ JSON parsed successfully`);
|
|
145
|
-
|
|
146
|
-
// Validate structure
|
|
147
|
-
if (!proofData.validationProof) {
|
|
148
|
-
log(`❌ ERROR: Missing 'validationProof' field`);
|
|
149
|
-
log(`Available fields: ${Object.keys(proofData).join(', ')}`);
|
|
150
|
-
this.validationProof = null;
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!proofData.validationData) {
|
|
155
|
-
log(`❌ ERROR: Missing 'validationData' field`);
|
|
156
|
-
log(`Available fields: ${Object.keys(proofData).join(', ')}`);
|
|
157
|
-
this.validationProof = null;
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Store proof
|
|
162
|
-
this.validationProof = {
|
|
163
|
-
hash: proofData.validationProof,
|
|
164
|
-
data: proofData.validationData
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
log(`✅ SUCCESS - Validation proof loaded`);
|
|
168
|
-
log(` Proof hash: ${this.validationProof.hash.substring(0, 32)}...`);
|
|
169
|
-
log(` Validator: ${this.validationProof.data.validator}`);
|
|
170
|
-
log(` Tests passed: ${this.validationProof.data.testsPassed}/${this.validationProof.data.testsRun}`);
|
|
171
|
-
log(` Validated at: ${this.validationProof.data.validatedAt}`);
|
|
172
|
-
|
|
173
|
-
} catch (error) {
|
|
174
|
-
// Non-critical error - service can still register without proof (will trigger Tier 2 validation)
|
|
175
|
-
log(`❌ EXCEPTION while loading validation proof`);
|
|
176
|
-
log(` Error: ${error.message}`);
|
|
177
|
-
log(` Stack: ${error.stack}`);
|
|
178
|
-
log(` Path attempted: ${proofPath}`);
|
|
179
|
-
log(`Service will use Tier 2 validation`);
|
|
180
|
-
this.validationProof = null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
99
|
/**
|
|
185
100
|
* Internal handler for incoming messages from the registry queue.
|
|
186
101
|
* Emits 'apiDescriptionRequest' when appropriate.
|