@naylence/runtime 0.3.5-test.941 → 0.3.5-test.943

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.
Files changed (33) hide show
  1. package/dist/browser/index.cjs +390 -8
  2. package/dist/browser/index.mjs +390 -8
  3. package/dist/cjs/naylence/fame/connector/broadcast-channel-connector-factory.js +12 -0
  4. package/dist/cjs/naylence/fame/connector/broadcast-channel-connector.browser.js +69 -1
  5. package/dist/cjs/naylence/fame/connector/inpage-connector-factory.js +12 -0
  6. package/dist/cjs/naylence/fame/connector/inpage-connector.js +159 -1
  7. package/dist/cjs/naylence/fame/connector/transport-frame.js +101 -0
  8. package/dist/cjs/naylence/fame/grants/broadcast-channel-connection-grant.js +28 -0
  9. package/dist/cjs/naylence/fame/grants/inpage-connection-grant.js +28 -0
  10. package/dist/cjs/naylence/fame/node/upstream-session-manager.js +2 -2
  11. package/dist/cjs/version.js +2 -2
  12. package/dist/esm/naylence/fame/connector/broadcast-channel-connector-factory.js +12 -0
  13. package/dist/esm/naylence/fame/connector/broadcast-channel-connector.browser.js +69 -1
  14. package/dist/esm/naylence/fame/connector/inpage-connector-factory.js +12 -0
  15. package/dist/esm/naylence/fame/connector/inpage-connector.js +159 -1
  16. package/dist/esm/naylence/fame/connector/transport-frame.js +94 -0
  17. package/dist/esm/naylence/fame/grants/broadcast-channel-connection-grant.js +28 -0
  18. package/dist/esm/naylence/fame/grants/inpage-connection-grant.js +28 -0
  19. package/dist/esm/naylence/fame/node/upstream-session-manager.js +2 -2
  20. package/dist/esm/version.js +2 -2
  21. package/dist/node/index.cjs +390 -8
  22. package/dist/node/index.mjs +390 -8
  23. package/dist/node/node.cjs +406 -8
  24. package/dist/node/node.mjs +406 -8
  25. package/dist/types/naylence/fame/connector/broadcast-channel-connector-factory.d.ts +2 -0
  26. package/dist/types/naylence/fame/connector/broadcast-channel-connector.browser.d.ts +4 -0
  27. package/dist/types/naylence/fame/connector/inpage-connector-factory.d.ts +2 -0
  28. package/dist/types/naylence/fame/connector/inpage-connector.d.ts +11 -1
  29. package/dist/types/naylence/fame/connector/transport-frame.d.ts +58 -0
  30. package/dist/types/naylence/fame/grants/broadcast-channel-connection-grant.d.ts +6 -0
  31. package/dist/types/naylence/fame/grants/inpage-connection-grant.d.ts +8 -0
  32. package/dist/types/version.d.ts +1 -1
  33. package/package.json +1 -1
@@ -6,6 +6,7 @@ const errors_js_1 = require("../errors/errors.js");
6
6
  const logging_js_1 = require("../util/logging.js");
7
7
  const bounded_async_queue_js_1 = require("../util/bounded-async-queue.js");
8
8
  const core_1 = require("@naylence/core");
9
+ const transport_frame_js_1 = require("./transport-frame.js");
9
10
  const logger = (0, logging_js_1.getLogger)('naylence.fame.connector.broadcast_channel_connector');
10
11
  exports.BROADCAST_CHANNEL_CONNECTOR_TYPE = 'broadcast-channel-connector';
11
12
  const DEFAULT_CHANNEL = 'naylence-fabric';
@@ -71,9 +72,20 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
71
72
  this.inbox = new bounded_async_queue_js_1.BoundedAsyncQueue(preferredCapacity);
72
73
  this.connectorId = BroadcastChannelConnector.generateConnectorId();
73
74
  this.channel = new BroadcastChannel(this.channelName);
75
+ // Set local and remote node IDs (defaults to connector ID for backwards compatibility)
76
+ this.localNodeId =
77
+ typeof config.localNodeId === 'string' && config.localNodeId.trim().length > 0
78
+ ? config.localNodeId.trim()
79
+ : this.connectorId;
80
+ this.remoteNodeId =
81
+ typeof config.remoteNodeId === 'string' && config.remoteNodeId.trim().length > 0
82
+ ? config.remoteNodeId.trim()
83
+ : '*'; // Accept from any remote if not specified
74
84
  logger.debug('broadcast_channel_connector_created', {
75
85
  channel: this.channelName,
76
86
  connector_id: this.connectorId,
87
+ local_node_id: this.localNodeId,
88
+ remote_node_id: this.remoteNodeId,
77
89
  inbox_capacity: preferredCapacity,
78
90
  timestamp: new Date().toISOString(),
79
91
  });
@@ -106,6 +118,46 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
106
118
  if (busMessage.senderId === this.connectorId) {
107
119
  return;
108
120
  }
121
+ // Try to unwrap as transport frame
122
+ const unwrapped = (0, transport_frame_js_1.unwrapTransportFrame)(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
123
+ if (unwrapped) {
124
+ // Successfully unwrapped transport frame
125
+ logger.debug('broadcast_channel_transport_frame_received', {
126
+ channel: this.channelName,
127
+ sender_id: busMessage.senderId,
128
+ connector_id: this.connectorId,
129
+ local_node_id: this.localNodeId,
130
+ remote_node_id: this.remoteNodeId,
131
+ payload_length: unwrapped.byteLength,
132
+ });
133
+ if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
134
+ return;
135
+ }
136
+ try {
137
+ if (typeof this.inbox.tryEnqueue === 'function') {
138
+ const accepted = this.inbox.tryEnqueue(unwrapped);
139
+ if (accepted) {
140
+ return;
141
+ }
142
+ }
143
+ this.inbox.enqueue(unwrapped);
144
+ }
145
+ catch (error) {
146
+ if (error instanceof bounded_async_queue_js_1.QueueFullError) {
147
+ logger.warning('broadcast_channel_receive_queue_full', {
148
+ channel: this.channelName,
149
+ });
150
+ }
151
+ else {
152
+ logger.error('broadcast_channel_receive_error', {
153
+ channel: this.channelName,
154
+ error: error instanceof Error ? error.message : String(error),
155
+ });
156
+ }
157
+ }
158
+ return;
159
+ }
160
+ // Fall back to legacy format (no transport frame)
109
161
  const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
110
162
  if (!payload) {
111
163
  logger.debug('broadcast_channel_payload_rejected', {
@@ -244,10 +296,26 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
244
296
  logger.debug('broadcast_channel_message_sending', {
245
297
  channel: this.channelName,
246
298
  sender_id: this.connectorId,
299
+ local_node_id: this.localNodeId,
300
+ remote_node_id: this.remoteNodeId,
247
301
  });
302
+ // Only use transport framing if both localNodeId and remoteNodeId are explicitly set
303
+ // (not using default values). This ensures backwards compatibility.
304
+ const useTransportFrame = this.localNodeId !== this.connectorId ||
305
+ this.remoteNodeId !== '*';
306
+ let payload;
307
+ if (useTransportFrame) {
308
+ // Wrap payload in transport frame
309
+ const frame = (0, transport_frame_js_1.wrapTransportFrame)(data, this.localNodeId, this.remoteNodeId);
310
+ payload = (0, transport_frame_js_1.serializeTransportFrame)(frame);
311
+ }
312
+ else {
313
+ // Legacy format: send raw payload
314
+ payload = data;
315
+ }
248
316
  this.channel.postMessage({
249
317
  senderId: this.connectorId,
250
- payload: data,
318
+ payload,
251
319
  });
252
320
  }
253
321
  async _transportReceive() {
@@ -84,6 +84,8 @@ class InPageConnectorFactory extends connector_factory_js_1.ConnectorFactory {
84
84
  type: inpage_connector_js_1.INPAGE_CONNECTOR_TYPE,
85
85
  channelName,
86
86
  inboxCapacity,
87
+ localNodeId: normalized.localNodeId,
88
+ remoteNodeId: normalized.remoteNodeId,
87
89
  };
88
90
  const connector = new inpage_connector_js_1.InPageConnector(connectorConfig, baseConfig);
89
91
  if (options.authorization) {
@@ -152,6 +154,16 @@ class InPageConnectorFactory extends connector_factory_js_1.ConnectorFactory {
152
154
  if (candidate.authorizationContext !== undefined) {
153
155
  normalized.authorizationContext = candidate.authorizationContext;
154
156
  }
157
+ // Handle localNodeId
158
+ const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
159
+ if (typeof localNodeId === 'string' && localNodeId.trim().length > 0) {
160
+ normalized.localNodeId = localNodeId.trim();
161
+ }
162
+ // Handle remoteNodeId
163
+ const remoteNodeId = candidate.remoteNodeId ?? candidate['remote_node_id'];
164
+ if (typeof remoteNodeId === 'string' && remoteNodeId.trim().length > 0) {
165
+ normalized.remoteNodeId = remoteNodeId.trim();
166
+ }
155
167
  normalized.channelName = normalized.channelName ?? DEFAULT_CHANNEL;
156
168
  normalized.inboxCapacity =
157
169
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;
@@ -9,6 +9,8 @@ const base_async_connector_js_1 = require("./base-async-connector.js");
9
9
  const errors_js_1 = require("../errors/errors.js");
10
10
  const logging_js_1 = require("../util/logging.js");
11
11
  const bounded_async_queue_js_1 = require("../util/bounded-async-queue.js");
12
+ const core_1 = require("@naylence/core");
13
+ const transport_frame_js_1 = require("./transport-frame.js");
12
14
  const logger = (0, logging_js_1.getLogger)('naylence.fame.connector.inpage_connector');
13
15
  exports.INPAGE_CONNECTOR_TYPE = 'inpage-connector';
14
16
  const DEFAULT_CHANNEL = 'naylence-fabric';
@@ -67,6 +69,7 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
67
69
  ensureBrowserEnvironment();
68
70
  super(baseConfig);
69
71
  this.listenerRegistered = false;
72
+ this.visibilityChangeListenerRegistered = false;
70
73
  this.channelName =
71
74
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
72
75
  ? config.channelName.trim()
@@ -78,9 +81,20 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
78
81
  : DEFAULT_INBOX_CAPACITY;
79
82
  this.inbox = new bounded_async_queue_js_1.BoundedAsyncQueue(preferredCapacity);
80
83
  this.connectorId = InPageConnector.generateConnectorId();
84
+ // Set local and remote node IDs (defaults to connector ID for backwards compatibility)
85
+ this.localNodeId =
86
+ typeof config.localNodeId === 'string' && config.localNodeId.trim().length > 0
87
+ ? config.localNodeId.trim()
88
+ : this.connectorId;
89
+ this.remoteNodeId =
90
+ typeof config.remoteNodeId === 'string' && config.remoteNodeId.trim().length > 0
91
+ ? config.remoteNodeId.trim()
92
+ : '*'; // Accept from any remote if not specified
81
93
  logger.debug('inpage_connector_initialized', {
82
94
  channel: this.channelName,
83
95
  connector_id: this.connectorId,
96
+ local_node_id: this.localNodeId,
97
+ remote_node_id: this.remoteNodeId,
84
98
  });
85
99
  this.onMsg = (event) => {
86
100
  const messageEvent = event;
@@ -114,6 +128,43 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
114
128
  if (busMessage.senderId === this.connectorId) {
115
129
  return;
116
130
  }
131
+ // Try to unwrap as transport frame
132
+ const unwrapped = (0, transport_frame_js_1.unwrapTransportFrame)(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
133
+ if (unwrapped) {
134
+ // Successfully unwrapped transport frame
135
+ logger.debug('inpage_transport_frame_received', {
136
+ channel: this.channelName,
137
+ sender_id: busMessage.senderId,
138
+ connector_id: this.connectorId,
139
+ local_node_id: this.localNodeId,
140
+ remote_node_id: this.remoteNodeId,
141
+ payload_length: unwrapped.byteLength,
142
+ });
143
+ try {
144
+ if (typeof this.inbox.tryEnqueue === 'function') {
145
+ const accepted = this.inbox.tryEnqueue(unwrapped);
146
+ if (accepted) {
147
+ return;
148
+ }
149
+ }
150
+ this.inbox.enqueue(unwrapped);
151
+ }
152
+ catch (error) {
153
+ if (error instanceof bounded_async_queue_js_1.QueueFullError) {
154
+ logger.warning('inpage_receive_queue_full', {
155
+ channel: this.channelName,
156
+ });
157
+ }
158
+ else {
159
+ logger.error('inpage_receive_error', {
160
+ channel: this.channelName,
161
+ error: error instanceof Error ? error.message : String(error),
162
+ });
163
+ }
164
+ }
165
+ return;
166
+ }
167
+ // Fall back to legacy format (no transport frame)
117
168
  const payload = InPageConnector.coercePayload(busMessage.payload);
118
169
  if (!payload) {
119
170
  logger.debug('inpage_payload_rejected', {
@@ -154,6 +205,92 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
154
205
  };
155
206
  getSharedBus().addEventListener(this.channelName, this.onMsg);
156
207
  this.listenerRegistered = true;
208
+ // Setup visibility change monitoring
209
+ this.visibilityChangeHandler = () => {
210
+ const isHidden = document.hidden;
211
+ logger.debug('inpage_visibility_changed', {
212
+ channel: this.channelName,
213
+ connector_id: this.connectorId,
214
+ visibility: isHidden ? 'hidden' : 'visible',
215
+ timestamp: new Date().toISOString(),
216
+ });
217
+ // Pause/resume connector based on visibility
218
+ if (isHidden && this.state === core_1.ConnectorState.STARTED) {
219
+ this.pause().catch((err) => {
220
+ logger.warning('inpage_pause_failed', {
221
+ channel: this.channelName,
222
+ connector_id: this.connectorId,
223
+ error: err instanceof Error ? err.message : String(err),
224
+ });
225
+ });
226
+ }
227
+ else if (!isHidden && this.state === core_1.ConnectorState.PAUSED) {
228
+ this.resume().catch((err) => {
229
+ logger.warning('inpage_resume_failed', {
230
+ channel: this.channelName,
231
+ connector_id: this.connectorId,
232
+ error: err instanceof Error ? err.message : String(err),
233
+ });
234
+ });
235
+ }
236
+ };
237
+ if (typeof document !== 'undefined') {
238
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
239
+ this.visibilityChangeListenerRegistered = true;
240
+ // Track page lifecycle events to detect browser unload/discard
241
+ if (typeof window !== 'undefined') {
242
+ const lifecycleLogger = (event) => {
243
+ logger.info('inpage_page_lifecycle', {
244
+ channel: this.channelName,
245
+ connector_id: this.connectorId,
246
+ event_type: event.type,
247
+ visibility_state: document.visibilityState,
248
+ timestamp: new Date().toISOString(),
249
+ });
250
+ };
251
+ window.addEventListener('beforeunload', lifecycleLogger);
252
+ window.addEventListener('unload', lifecycleLogger);
253
+ window.addEventListener('pagehide', lifecycleLogger);
254
+ window.addEventListener('pageshow', lifecycleLogger);
255
+ document.addEventListener('freeze', lifecycleLogger);
256
+ document.addEventListener('resume', lifecycleLogger);
257
+ }
258
+ // Log initial state with detailed visibility info
259
+ logger.debug('inpage_initial_visibility', {
260
+ channel: this.channelName,
261
+ connector_id: this.connectorId,
262
+ visibility: document.hidden ? 'hidden' : 'visible',
263
+ document_hidden: document.hidden,
264
+ visibility_state: document.visibilityState,
265
+ has_focus: document.hasFocus(),
266
+ timestamp: new Date().toISOString(),
267
+ });
268
+ }
269
+ }
270
+ /**
271
+ * Override start() to check initial visibility state
272
+ */
273
+ async start(inboundHandler) {
274
+ await super.start(inboundHandler);
275
+ // After transitioning to STARTED, check if tab is already hidden
276
+ if (typeof document !== 'undefined' && document.hidden) {
277
+ logger.debug('inpage_start_in_hidden_tab', {
278
+ channel: this.channelName,
279
+ connector_id: this.connectorId,
280
+ document_hidden: document.hidden,
281
+ visibility_state: document.visibilityState,
282
+ has_focus: document.hasFocus(),
283
+ timestamp: new Date().toISOString(),
284
+ });
285
+ // Immediately pause if tab is hidden at start time
286
+ await this.pause().catch((err) => {
287
+ logger.warning('inpage_initial_pause_failed', {
288
+ channel: this.channelName,
289
+ connector_id: this.connectorId,
290
+ error: err instanceof Error ? err.message : String(err),
291
+ });
292
+ });
293
+ }
157
294
  }
158
295
  // Allow listeners to feed envelopes directly into the in-page receive queue.
159
296
  async pushToReceive(rawOrEnvelope) {
@@ -186,11 +323,27 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
186
323
  logger.debug('inpage_message_sending', {
187
324
  channel: this.channelName,
188
325
  sender_id: this.connectorId,
326
+ local_node_id: this.localNodeId,
327
+ remote_node_id: this.remoteNodeId,
189
328
  });
329
+ // Only use transport framing if both localNodeId and remoteNodeId are explicitly set
330
+ // (not using default values). This ensures backwards compatibility.
331
+ const useTransportFrame = this.localNodeId !== this.connectorId ||
332
+ this.remoteNodeId !== '*';
333
+ let payload;
334
+ if (useTransportFrame) {
335
+ // Wrap payload in transport frame
336
+ const frame = (0, transport_frame_js_1.wrapTransportFrame)(data, this.localNodeId, this.remoteNodeId);
337
+ payload = (0, transport_frame_js_1.serializeTransportFrame)(frame);
338
+ }
339
+ else {
340
+ // Legacy format: send raw payload
341
+ payload = data;
342
+ }
190
343
  const event = new MessageEvent(this.channelName, {
191
344
  data: {
192
345
  senderId: this.connectorId,
193
- payload: data,
346
+ payload,
194
347
  },
195
348
  });
196
349
  getSharedBus().dispatchEvent(event);
@@ -203,6 +356,11 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
203
356
  getSharedBus().removeEventListener(this.channelName, this.onMsg);
204
357
  this.listenerRegistered = false;
205
358
  }
359
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
360
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
361
+ this.visibilityChangeListenerRegistered = false;
362
+ this.visibilityChangeHandler = undefined;
363
+ }
206
364
  const closeCode = typeof code === 'number' ? code : 1000;
207
365
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
208
366
  const shutdownError = new errors_js_1.FameTransportClose(closeReason, closeCode);
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ /**
3
+ * Transport frame layer for multiplexing logical links on physical channels.
4
+ *
5
+ * This lightweight framing layer wraps raw FAME payloads to enable multiple
6
+ * logical connections over a single physical channel (BroadcastChannel or InPage bus).
7
+ *
8
+ * The transport frame does NOT modify FAME envelopes - it only wraps the raw
9
+ * Uint8Array payload at the connector level.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TRANSPORT_FRAME_VERSION = void 0;
13
+ exports.wrapTransportFrame = wrapTransportFrame;
14
+ exports.serializeTransportFrame = serializeTransportFrame;
15
+ exports.unwrapTransportFrame = unwrapTransportFrame;
16
+ exports.isTransportFrame = isTransportFrame;
17
+ /**
18
+ * Transport frame version for future compatibility
19
+ */
20
+ exports.TRANSPORT_FRAME_VERSION = 1;
21
+ /**
22
+ * Wrap a raw payload in a transport frame
23
+ *
24
+ * @param payload - Raw FAME envelope bytes
25
+ * @param srcNodeId - Local node ID (this connector)
26
+ * @param dstNodeId - Remote node ID (target connector)
27
+ * @returns Transport frame ready for transmission
28
+ */
29
+ function wrapTransportFrame(payload, srcNodeId, dstNodeId) {
30
+ return {
31
+ v: exports.TRANSPORT_FRAME_VERSION,
32
+ src: srcNodeId,
33
+ dst: dstNodeId,
34
+ payload,
35
+ };
36
+ }
37
+ /**
38
+ * Serialize a transport frame for transmission over the bus
39
+ *
40
+ * @param frame - Transport frame to serialize
41
+ * @returns Serialized frame data ready for postMessage/dispatchEvent
42
+ */
43
+ function serializeTransportFrame(frame) {
44
+ // Convert Uint8Array to regular array for JSON serialization
45
+ const serializable = {
46
+ v: frame.v,
47
+ src: frame.src,
48
+ dst: frame.dst,
49
+ payload: Array.from(frame.payload),
50
+ };
51
+ return serializable;
52
+ }
53
+ /**
54
+ * Unwrap a transport frame, validating source and destination
55
+ *
56
+ * @param raw - Raw data from the bus
57
+ * @param localNodeId - This connector's node ID
58
+ * @param remoteNodeId - Expected remote node ID
59
+ * @returns Unwrapped payload if frame is valid and addressed to us, null otherwise
60
+ */
61
+ function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
62
+ // Validate basic structure
63
+ if (!raw || typeof raw !== 'object') {
64
+ return null;
65
+ }
66
+ const frame = raw;
67
+ // Check version
68
+ if (frame.v !== exports.TRANSPORT_FRAME_VERSION) {
69
+ return null;
70
+ }
71
+ // Check src and dst
72
+ if (typeof frame.src !== 'string' || typeof frame.dst !== 'string') {
73
+ return null;
74
+ }
75
+ // Only accept frames addressed to us from the expected remote
76
+ if (frame.dst !== localNodeId || frame.src !== remoteNodeId) {
77
+ return null;
78
+ }
79
+ // Extract payload
80
+ if (!frame.payload || !Array.isArray(frame.payload)) {
81
+ return null;
82
+ }
83
+ // Convert array back to Uint8Array
84
+ return Uint8Array.from(frame.payload);
85
+ }
86
+ /**
87
+ * Check if raw data looks like a transport frame
88
+ *
89
+ * @param raw - Raw data from the bus
90
+ * @returns True if this appears to be a transport frame
91
+ */
92
+ function isTransportFrame(raw) {
93
+ if (!raw || typeof raw !== 'object') {
94
+ return false;
95
+ }
96
+ const frame = raw;
97
+ return (typeof frame.v === 'number' &&
98
+ typeof frame.src === 'string' &&
99
+ typeof frame.dst === 'string' &&
100
+ Array.isArray(frame.payload));
101
+ }
@@ -25,6 +25,14 @@ function isBroadcastChannelConnectionGrant(candidate) {
25
25
  record.inboxCapacity <= 0)) {
26
26
  return false;
27
27
  }
28
+ if (record.localNodeId !== undefined &&
29
+ (typeof record.localNodeId !== 'string' || record.localNodeId.length === 0)) {
30
+ return false;
31
+ }
32
+ if (record.remoteNodeId !== undefined &&
33
+ (typeof record.remoteNodeId !== 'string' || record.remoteNodeId.length === 0)) {
34
+ return false;
35
+ }
28
36
  return true;
29
37
  }
30
38
  function normalizeBroadcastChannelConnectionGrant(candidate) {
@@ -58,6 +66,20 @@ function normalizeBroadcastChannelConnectionGrant(candidate) {
58
66
  }
59
67
  result.inboxCapacity = Math.floor(inboxValue);
60
68
  }
69
+ const localNodeIdValue = candidate.localNodeId ?? candidate['local_node_id'];
70
+ if (localNodeIdValue !== undefined) {
71
+ if (typeof localNodeIdValue !== 'string' || localNodeIdValue.trim().length === 0) {
72
+ throw new TypeError('BroadcastChannelConnectionGrant "localNodeId" must be a non-empty string when provided');
73
+ }
74
+ result.localNodeId = localNodeIdValue.trim();
75
+ }
76
+ const remoteNodeIdValue = candidate.remoteNodeId ?? candidate['remote_node_id'];
77
+ if (remoteNodeIdValue !== undefined) {
78
+ if (typeof remoteNodeIdValue !== 'string' || remoteNodeIdValue.trim().length === 0) {
79
+ throw new TypeError('BroadcastChannelConnectionGrant "remoteNodeId" must be a non-empty string when provided');
80
+ }
81
+ result.remoteNodeId = remoteNodeIdValue.trim();
82
+ }
61
83
  return result;
62
84
  }
63
85
  function broadcastChannelGrantToConnectorConfig(grant) {
@@ -71,5 +93,11 @@ function broadcastChannelGrantToConnectorConfig(grant) {
71
93
  if (normalized.inboxCapacity !== undefined) {
72
94
  config.inboxCapacity = normalized.inboxCapacity;
73
95
  }
96
+ if (normalized.localNodeId) {
97
+ config.localNodeId = normalized.localNodeId;
98
+ }
99
+ if (normalized.remoteNodeId) {
100
+ config.remoteNodeId = normalized.remoteNodeId;
101
+ }
74
102
  return config;
75
103
  }
@@ -25,6 +25,14 @@ function isInPageConnectionGrant(candidate) {
25
25
  record.inboxCapacity <= 0)) {
26
26
  return false;
27
27
  }
28
+ if (record.localNodeId !== undefined &&
29
+ (typeof record.localNodeId !== 'string' || record.localNodeId.length === 0)) {
30
+ return false;
31
+ }
32
+ if (record.remoteNodeId !== undefined &&
33
+ (typeof record.remoteNodeId !== 'string' || record.remoteNodeId.length === 0)) {
34
+ return false;
35
+ }
28
36
  return true;
29
37
  }
30
38
  function normalizeInPageConnectionGrant(candidate) {
@@ -58,6 +66,20 @@ function normalizeInPageConnectionGrant(candidate) {
58
66
  }
59
67
  result.inboxCapacity = Math.floor(inboxValue);
60
68
  }
69
+ const localNodeIdValue = candidate.localNodeId ?? candidate['local_node_id'];
70
+ if (localNodeIdValue !== undefined) {
71
+ if (typeof localNodeIdValue !== 'string' || localNodeIdValue.trim().length === 0) {
72
+ throw new TypeError('InPageConnectionGrant "localNodeId" must be a non-empty string when provided');
73
+ }
74
+ result.localNodeId = localNodeIdValue.trim();
75
+ }
76
+ const remoteNodeIdValue = candidate.remoteNodeId ?? candidate['remote_node_id'];
77
+ if (remoteNodeIdValue !== undefined) {
78
+ if (typeof remoteNodeIdValue !== 'string' || remoteNodeIdValue.trim().length === 0) {
79
+ throw new TypeError('InPageConnectionGrant "remoteNodeId" must be a non-empty string when provided');
80
+ }
81
+ result.remoteNodeId = remoteNodeIdValue.trim();
82
+ }
61
83
  return result;
62
84
  }
63
85
  function inPageGrantToConnectorConfig(grant) {
@@ -71,5 +93,11 @@ function inPageGrantToConnectorConfig(grant) {
71
93
  if (normalized.inboxCapacity !== undefined) {
72
94
  config.inboxCapacity = normalized.inboxCapacity;
73
95
  }
96
+ if (normalized.localNodeId) {
97
+ config.localNodeId = normalized.localNodeId;
98
+ }
99
+ if (normalized.remoteNodeId) {
100
+ config.remoteNodeId = normalized.remoteNodeId;
101
+ }
74
102
  return config;
75
103
  }
@@ -388,7 +388,7 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
388
388
  this.currentStopSubtasks = null;
389
389
  await Promise.allSettled(tasks.map((task) => task.promise));
390
390
  if (this.connector) {
391
- logger.info('upstream_stopping_old_connector', {
391
+ logger.debug('upstream_stopping_old_connector', {
392
392
  connect_epoch: this.connectEpoch,
393
393
  target_system_id: this.targetSystemId,
394
394
  timestamp: new Date().toISOString(),
@@ -399,7 +399,7 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
399
399
  error: err instanceof Error ? err.message : String(err),
400
400
  });
401
401
  });
402
- logger.info('upstream_old_connector_stopped', {
402
+ logger.debug('upstream_old_connector_stopped', {
403
403
  connect_epoch: this.connectEpoch,
404
404
  target_system_id: this.targetSystemId,
405
405
  timestamp: new Date().toISOString(),
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  // This file is auto-generated during build - do not edit manually
3
- // Generated from package.json version: 0.3.5-test.941
3
+ // Generated from package.json version: 0.3.5-test.943
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.VERSION = void 0;
6
6
  /**
7
7
  * The package version, injected at build time.
8
8
  * @internal
9
9
  */
10
- exports.VERSION = '0.3.5-test.941';
10
+ exports.VERSION = '0.3.5-test.943';
@@ -86,6 +86,8 @@ export class BroadcastChannelConnectorFactory extends ConnectorFactory {
86
86
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
87
87
  channelName,
88
88
  inboxCapacity,
89
+ localNodeId: normalized.localNodeId,
90
+ remoteNodeId: normalized.remoteNodeId,
89
91
  };
90
92
  const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
91
93
  if (options.authorization) {
@@ -147,6 +149,16 @@ export class BroadcastChannelConnectorFactory extends ConnectorFactory {
147
149
  if (candidate.authorizationContext !== undefined) {
148
150
  normalized.authorizationContext = candidate.authorizationContext;
149
151
  }
152
+ // Handle localNodeId
153
+ const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
154
+ if (typeof localNodeId === 'string' && localNodeId.trim().length > 0) {
155
+ normalized.localNodeId = localNodeId.trim();
156
+ }
157
+ // Handle remoteNodeId
158
+ const remoteNodeId = candidate.remoteNodeId ?? candidate['remote_node_id'];
159
+ if (typeof remoteNodeId === 'string' && remoteNodeId.trim().length > 0) {
160
+ normalized.remoteNodeId = remoteNodeId.trim();
161
+ }
150
162
  normalized.channelName = normalized.channelName ?? DEFAULT_CHANNEL;
151
163
  normalized.inboxCapacity =
152
164
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;