node-red-contrib-uos-nats 0.1.45 → 0.1.47

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/lib/subjects.js CHANGED
@@ -9,3 +9,9 @@ export function readVariablesQuery(providerId) {
9
9
  export function providerDefinitionChanged(providerId) {
10
10
  return `${VERSION_PREFIX}.${LOCATION_PREFIX}.${providerId}.def.evt.changed`;
11
11
  }
12
+ export function registryProviderQuery(providerId) {
13
+ return `${VERSION_PREFIX}.${LOCATION_PREFIX}.registry.providers.${providerId}.def.qry.read`;
14
+ }
15
+ export function readProviderDefinitionQuery(providerId) {
16
+ return `${VERSION_PREFIX}.${LOCATION_PREFIX}.${providerId}.def.qry.read`;
17
+ }
@@ -140,17 +140,24 @@ module.exports = function (RED) {
140
140
  // Retry Definition Fetch via NATS if Map is empty AND no manual defs
141
141
  if (defMap.size === 0 && this.manualDefs.length === 0) {
142
142
  try {
143
- this.warn(`Attempting to fetch definitions via NATS for ${this.providerId}...`);
144
- const defMsg = await nc.request(`v1.loc.${this.providerId}.def.qry.read`, new Uint8Array(0), { timeout: 2000 });
145
- // We need to decode this manually or use a helper
146
- // Importing payloads to use our new decode function
147
- // Assuming payloads is already loaded above
148
-
143
+ // Strategy 1: Direct Provider Query (Standard for many providers)
144
+ this.warn(`Attempting NATS Discovery (Direct) for ${this.providerId}...`);
145
+ const defMsg = await nc.request(subjects.readProviderDefinitionQuery(this.providerId), new Uint8Array(0), { timeout: 1000 });
149
146
  const defs = payloads.decodeProviderDefinition(defMsg.data);
150
- this.warn(`NATS Fallback: Loaded ${defs.length} definitions.`);
147
+ this.warn(`NATS Direct Discovery: Loaded ${defs.length} variables.`);
151
148
  defs.forEach((def) => defMap.set(def.id, def));
152
- } catch (err) {
153
- this.warn(`NATS Fallback failed: ${err.message}`);
149
+ } catch (firstErr) {
150
+ // Strategy 2: Registry Query (Central lookup, often requires different perms or used by Hub)
151
+ try {
152
+ this.warn(`NATS Direct failed (${firstErr.message}), trying Registry Discovery...`);
153
+ // Note: 'registryProviderQuery' accesses the central registry which might proxy the definition
154
+ const regMsg = await nc.request(subjects.registryProviderQuery(this.providerId), new Uint8Array(0), { timeout: 2000 });
155
+ const defs = payloads.decodeProviderDefinition(regMsg.data);
156
+ this.warn(`NATS Registry Discovery: Loaded ${defs.length} variables.`);
157
+ defs.forEach((def) => defMap.set(def.id, def));
158
+ } catch (secondErr) {
159
+ this.warn(`All Discovery methods failed (REST, NATS Direct, NATS Registry). Please use Manual Definitions (Name:ID). Error: ${secondErr.message}`);
160
+ }
154
161
  }
155
162
  }
156
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
4
4
  "description": "Node-RED nodes for u-OS Data Hub via NATS",
5
5
  "repository": {
6
6
  "type": "git",