@naylence/runtime 0.3.5-test.965 → 0.3.5-test.967

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.
@@ -98,12 +98,12 @@ installProcessEnvShim();
98
98
  // --- END ENV SHIM ---
99
99
 
100
100
  // This file is auto-generated during build - do not edit manually
101
- // Generated from package.json version: 0.3.5-test.965
101
+ // Generated from package.json version: 0.3.5-test.967
102
102
  /**
103
103
  * The package version, injected at build time.
104
104
  * @internal
105
105
  */
106
- const VERSION = '0.3.5-test.965';
106
+ const VERSION = '0.3.5-test.967';
107
107
 
108
108
  /**
109
109
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9970,11 +9970,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9970
9970
  ensureBroadcastEnvironment();
9971
9971
  super(baseConfig);
9972
9972
  this.listenerRegistered = false;
9973
- this.seenAckKeys = new Map();
9974
- this.seenAckOrder = [];
9975
- this.ackDedupTtlMs = 30000;
9976
- this.ackDedupMaxEntries = 4096;
9977
- this.textDecoder = new TextDecoder();
9978
9973
  this.visibilityChangeListenerRegistered = false;
9979
9974
  this.channelName =
9980
9975
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
@@ -10066,9 +10061,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10066
10061
  connector_id: this.connectorId,
10067
10062
  payload_length: payload.byteLength,
10068
10063
  });
10069
- if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
10070
- return;
10071
- }
10072
10064
  try {
10073
10065
  if (typeof this.inbox.tryEnqueue === 'function') {
10074
10066
  const accepted = this.inbox.tryEnqueue(payload);
@@ -10172,9 +10164,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10172
10164
  }
10173
10165
  async pushToReceive(rawOrEnvelope) {
10174
10166
  const item = this._normalizeInboxItem(rawOrEnvelope);
10175
- if (this._shouldSkipDuplicateAckFromInboxItem(item)) {
10176
- return;
10177
- }
10178
10167
  try {
10179
10168
  if (typeof this.inbox.tryEnqueue === 'function') {
10180
10169
  const accepted = this.inbox.tryEnqueue(item);
@@ -10274,8 +10263,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10274
10263
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
10275
10264
  const shutdownError = new FameTransportClose(closeReason, closeCode);
10276
10265
  this.inbox.drain(shutdownError);
10277
- this.seenAckKeys.clear();
10278
- this.seenAckOrder.length = 0;
10279
10266
  }
10280
10267
  _normalizeInboxItem(rawOrEnvelope) {
10281
10268
  if (rawOrEnvelope instanceof Uint8Array) {
@@ -10352,125 +10339,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10352
10339
  ...extra,
10353
10340
  });
10354
10341
  }
10355
- _shouldSkipDuplicateAck(senderId, payload) {
10356
- const dedupKey = this._extractAckDedupKey(payload);
10357
- if (!dedupKey) {
10358
- return false;
10359
- }
10360
- const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
10361
- ? senderId
10362
- : undefined;
10363
- if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
10364
- logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10365
- channel: this.channelName,
10366
- connector_id: this.connectorId,
10367
- sender_id: normalizedSenderId,
10368
- dedup_key: dedupKey,
10369
- source: 'listener',
10370
- });
10371
- return false;
10372
- }
10373
- logger$_.debug('broadcast_channel_duplicate_ack_check', {
10374
- channel: this.channelName,
10375
- connector_id: this.connectorId,
10376
- sender_id: normalizedSenderId ?? null,
10377
- dedup_key: dedupKey,
10378
- source: 'listener',
10379
- cache_entries: this.seenAckKeys.size,
10380
- });
10381
- return this._checkDuplicateAck(dedupKey, normalizedSenderId);
10382
- }
10383
- _shouldSkipDuplicateAckFromInboxItem(item) {
10384
- if (item instanceof Uint8Array) {
10385
- return this._shouldSkipDuplicateAck(undefined, item);
10386
- }
10387
- const envelope = this._extractEnvelopeFromInboxItem(item);
10388
- if (!envelope) {
10389
- return false;
10390
- }
10391
- const frame = envelope.frame;
10392
- if (!frame || frame.type !== 'DeliveryAck') {
10393
- return false;
10394
- }
10395
- const refId = typeof frame.refId === 'string' && frame.refId.length > 0
10396
- ? frame.refId
10397
- : null;
10398
- const dedupKey = refId ?? envelope.id ?? null;
10399
- if (!dedupKey) {
10400
- return false;
10401
- }
10402
- const senderId = this._extractSenderIdFromInboxItem(item);
10403
- if (senderId && senderId !== this.localNodeId) {
10404
- logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10405
- channel: this.channelName,
10406
- connector_id: this.connectorId,
10407
- sender_id: senderId,
10408
- dedup_key: dedupKey,
10409
- source: 'inbox_item',
10410
- });
10411
- return false;
10412
- }
10413
- logger$_.debug('broadcast_channel_duplicate_ack_check', {
10414
- channel: this.channelName,
10415
- connector_id: this.connectorId,
10416
- sender_id: senderId ?? null,
10417
- dedup_key: dedupKey,
10418
- source: 'inbox_item',
10419
- cache_entries: this.seenAckKeys.size,
10420
- });
10421
- return this._checkDuplicateAck(dedupKey, senderId);
10422
- }
10423
- _checkDuplicateAck(dedupKey, senderId) {
10424
- const now = Date.now();
10425
- const lastSeen = this.seenAckKeys.get(dedupKey);
10426
- if (lastSeen && now - lastSeen < this.ackDedupTtlMs) {
10427
- logger$_.debug('broadcast_channel_duplicate_ack_suppressed', {
10428
- channel: this.channelName,
10429
- connector_id: this.connectorId,
10430
- sender_id: senderId ?? null,
10431
- dedup_key: dedupKey,
10432
- age_ms: now - lastSeen,
10433
- ttl_ms: this.ackDedupTtlMs,
10434
- cache_entries: this.seenAckKeys.size,
10435
- });
10436
- return true;
10437
- }
10438
- this.seenAckKeys.set(dedupKey, now);
10439
- this.seenAckOrder.push(dedupKey);
10440
- logger$_.debug('broadcast_channel_duplicate_ack_recorded', {
10441
- channel: this.channelName,
10442
- connector_id: this.connectorId,
10443
- sender_id: senderId ?? null,
10444
- dedup_key: dedupKey,
10445
- cache_entries: this.seenAckKeys.size,
10446
- });
10447
- this._trimSeenAcks(now);
10448
- return false;
10449
- }
10450
- _extractEnvelopeFromInboxItem(item) {
10451
- if (!item || typeof item !== 'object') {
10452
- return null;
10453
- }
10454
- if ('envelope' in item) {
10455
- return item.envelope;
10456
- }
10457
- if ('frame' in item) {
10458
- return item;
10459
- }
10460
- return null;
10461
- }
10462
- _extractSenderIdFromInboxItem(item) {
10463
- if (!item || typeof item !== 'object') {
10464
- return undefined;
10465
- }
10466
- if ('context' in item) {
10467
- const context = item.context;
10468
- if (context && typeof context.fromSystemId === 'string') {
10469
- return context.fromSystemId;
10470
- }
10471
- }
10472
- return undefined;
10473
- }
10474
10342
  /**
10475
10343
  * Override start() to check initial visibility state
10476
10344
  */
@@ -10524,47 +10392,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10524
10392
  target_mode: 'wildcard',
10525
10393
  });
10526
10394
  }
10527
- _trimSeenAcks(now) {
10528
- while (this.seenAckOrder.length > 0) {
10529
- const candidate = this.seenAckOrder[0];
10530
- const timestamp = this.seenAckKeys.get(candidate);
10531
- if (timestamp === undefined) {
10532
- this.seenAckOrder.shift();
10533
- continue;
10534
- }
10535
- if (this.seenAckKeys.size > this.ackDedupMaxEntries ||
10536
- now - timestamp > this.ackDedupTtlMs) {
10537
- this.seenAckKeys.delete(candidate);
10538
- this.seenAckOrder.shift();
10539
- continue;
10540
- }
10541
- break;
10542
- }
10543
- }
10544
- _extractAckDedupKey(payload) {
10545
- try {
10546
- const decoded = this.textDecoder.decode(payload);
10547
- const parsed = JSON.parse(decoded);
10548
- const envelopeId = typeof parsed?.id === 'string' ? parsed.id : null;
10549
- const frameType = parsed?.frame?.type;
10550
- if (typeof frameType !== 'string' || frameType !== 'DeliveryAck') {
10551
- return null;
10552
- }
10553
- const refId = parsed.frame?.refId;
10554
- if (typeof refId === 'string' && refId.length > 0) {
10555
- return refId;
10556
- }
10557
- return envelopeId;
10558
- }
10559
- catch (error) {
10560
- logger$_.debug('broadcast_channel_ack_dedup_parse_failed', {
10561
- channel: this.channelName,
10562
- connector_id: this.connectorId,
10563
- error: error instanceof Error ? error.message : String(error),
10564
- });
10565
- return null;
10566
- }
10567
- }
10568
10395
  };
10569
10396
 
10570
10397
  const ERROR_MESSAGE = 'BroadcastChannelConnector is browser-only and requires BroadcastChannel support';
@@ -20691,6 +20518,26 @@ class InPageConnector extends BaseAsyncConnector {
20691
20518
  }
20692
20519
  return null;
20693
20520
  }
20521
+ static normalizeNodeId(value) {
20522
+ if (typeof value !== 'string') {
20523
+ return null;
20524
+ }
20525
+ const trimmed = value.trim();
20526
+ return trimmed.length > 0 ? trimmed : null;
20527
+ }
20528
+ static normalizeTargetNodeId(value) {
20529
+ if (typeof value !== 'string') {
20530
+ return undefined;
20531
+ }
20532
+ const trimmed = value.trim();
20533
+ if (trimmed.length === 0) {
20534
+ return undefined;
20535
+ }
20536
+ if (trimmed === '*') {
20537
+ return '*';
20538
+ }
20539
+ return trimmed;
20540
+ }
20694
20541
  constructor(config, baseConfig = {}) {
20695
20542
  ensureBrowserEnvironment$2();
20696
20543
  super(baseConfig);
@@ -20706,41 +20553,68 @@ class InPageConnector extends BaseAsyncConnector {
20706
20553
  ? Math.floor(config.inboxCapacity)
20707
20554
  : DEFAULT_INBOX_CAPACITY$6;
20708
20555
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
20556
+ this.inboxCapacity = preferredCapacity;
20709
20557
  this.connectorId = InPageConnector.generateConnectorId();
20558
+ const normalizedLocalNodeId = InPageConnector.normalizeNodeId(config.localNodeId);
20559
+ if (!normalizedLocalNodeId) {
20560
+ throw new Error('InPageConnector requires a non-empty localNodeId');
20561
+ }
20562
+ this.localNodeId = normalizedLocalNodeId;
20563
+ this.targetNodeId = InPageConnector.normalizeTargetNodeId(config.initialTargetNodeId);
20710
20564
  logger$G.debug('inpage_connector_initialized', {
20711
20565
  channel: this.channelName,
20712
20566
  connector_id: this.connectorId,
20567
+ local_node_id: this.localNodeId,
20568
+ target_node_id: this.targetNodeId ?? null,
20569
+ inbox_capacity: preferredCapacity,
20713
20570
  });
20714
20571
  this.onMsg = (event) => {
20572
+ if (!this.listenerRegistered) {
20573
+ logger$G.warning('inpage_message_after_unregister', {
20574
+ channel: this.channelName,
20575
+ connector_id: this.connectorId,
20576
+ timestamp: new Date().toISOString(),
20577
+ });
20578
+ return;
20579
+ }
20715
20580
  const messageEvent = event;
20716
20581
  const message = messageEvent.data;
20717
20582
  logger$G.debug('inpage_raw_event', {
20718
20583
  channel: this.channelName,
20719
20584
  connector_id: this.connectorId,
20720
- message_type: message && typeof message === 'object' ? message.constructor?.name ?? typeof message : typeof message,
20721
- has_sender_id: Boolean(message?.senderId),
20722
- payload_type: message && typeof message === 'object'
20723
- ? message?.payload instanceof Uint8Array
20724
- ? 'Uint8Array'
20725
- : message?.payload instanceof ArrayBuffer
20726
- ? 'ArrayBuffer'
20727
- : typeof message?.payload
20585
+ message_type: message && typeof message === 'object'
20586
+ ? message.constructor?.name ?? typeof message
20728
20587
  : typeof message,
20729
- payload_constructor: message && typeof message === 'object'
20730
- ? message?.payload?.constructor?.name
20731
- : undefined,
20732
- payload_keys: message && typeof message === 'object' && message?.payload && typeof message?.payload === 'object'
20733
- ? Object.keys(message.payload).slice(0, 5)
20734
- : undefined,
20588
+ has_sender_id: Boolean(message?.senderId),
20589
+ has_sender_node_id: Boolean(message?.senderNodeId),
20735
20590
  });
20736
20591
  if (!message || typeof message !== 'object') {
20737
20592
  return;
20738
20593
  }
20739
20594
  const busMessage = message;
20740
- if (typeof busMessage.senderId !== 'string' || busMessage.senderId.length === 0) {
20595
+ const senderId = typeof busMessage.senderId === 'string' && busMessage.senderId.length > 0
20596
+ ? busMessage.senderId
20597
+ : null;
20598
+ const senderNodeId = InPageConnector.normalizeNodeId(busMessage.senderNodeId);
20599
+ if (!senderId || !senderNodeId) {
20600
+ logger$G.debug('inpage_message_rejected', {
20601
+ channel: this.channelName,
20602
+ connector_id: this.connectorId,
20603
+ reason: 'missing_sender_metadata',
20604
+ });
20741
20605
  return;
20742
20606
  }
20743
- if (busMessage.senderId === this.connectorId) {
20607
+ if (senderId === this.connectorId || senderNodeId === this.localNodeId) {
20608
+ logger$G.debug('inpage_message_rejected', {
20609
+ channel: this.channelName,
20610
+ connector_id: this.connectorId,
20611
+ reason: 'self_echo',
20612
+ sender_node_id: senderNodeId,
20613
+ });
20614
+ return;
20615
+ }
20616
+ const incomingTargetNodeId = InPageConnector.normalizeTargetNodeId(busMessage.targetNodeId);
20617
+ if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
20744
20618
  return;
20745
20619
  }
20746
20620
  const payload = InPageConnector.coercePayload(busMessage.payload);
@@ -20754,7 +20628,9 @@ class InPageConnector extends BaseAsyncConnector {
20754
20628
  }
20755
20629
  logger$G.debug('inpage_message_received', {
20756
20630
  channel: this.channelName,
20757
- sender_id: busMessage.senderId,
20631
+ sender_id: senderId,
20632
+ sender_node_id: senderNodeId,
20633
+ target_node_id: incomingTargetNodeId ?? null,
20758
20634
  connector_id: this.connectorId,
20759
20635
  payload_length: payload.byteLength,
20760
20636
  });
@@ -20762,15 +20638,27 @@ class InPageConnector extends BaseAsyncConnector {
20762
20638
  if (typeof this.inbox.tryEnqueue === 'function') {
20763
20639
  const accepted = this.inbox.tryEnqueue(payload);
20764
20640
  if (accepted) {
20641
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
20642
+ source: 'listener',
20643
+ enqueue_strategy: 'try',
20644
+ payload_length: payload.byteLength,
20645
+ });
20765
20646
  return;
20766
20647
  }
20767
20648
  }
20768
20649
  this.inbox.enqueue(payload);
20650
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
20651
+ source: 'listener',
20652
+ enqueue_strategy: 'enqueue',
20653
+ payload_length: payload.byteLength,
20654
+ });
20769
20655
  }
20770
20656
  catch (error) {
20771
20657
  if (error instanceof QueueFullError) {
20772
20658
  logger$G.warning('inpage_receive_queue_full', {
20773
20659
  channel: this.channelName,
20660
+ inbox_capacity: this.inboxCapacity,
20661
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20774
20662
  });
20775
20663
  }
20776
20664
  else {
@@ -20877,15 +20765,25 @@ class InPageConnector extends BaseAsyncConnector {
20877
20765
  if (typeof this.inbox.tryEnqueue === 'function') {
20878
20766
  const accepted = this.inbox.tryEnqueue(item);
20879
20767
  if (accepted) {
20768
+ this.logInboxSnapshot('inpage_push_enqueued', {
20769
+ enqueue_strategy: 'try',
20770
+ item_type: this._describeInboxItem(item),
20771
+ });
20880
20772
  return;
20881
20773
  }
20882
20774
  }
20883
20775
  this.inbox.enqueue(item);
20776
+ this.logInboxSnapshot('inpage_push_enqueued', {
20777
+ enqueue_strategy: 'enqueue',
20778
+ item_type: this._describeInboxItem(item),
20779
+ });
20884
20780
  }
20885
20781
  catch (error) {
20886
20782
  if (error instanceof QueueFullError) {
20887
20783
  logger$G.warning('inpage_push_queue_full', {
20888
20784
  channel: this.channelName,
20785
+ inbox_capacity: this.inboxCapacity,
20786
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20889
20787
  });
20890
20788
  throw error;
20891
20789
  }
@@ -20898,25 +20796,52 @@ class InPageConnector extends BaseAsyncConnector {
20898
20796
  }
20899
20797
  async _transportSendBytes(data) {
20900
20798
  ensureBrowserEnvironment$2();
20799
+ const targetNodeId = this.targetNodeId ?? '*';
20901
20800
  logger$G.debug('inpage_message_sending', {
20902
20801
  channel: this.channelName,
20903
20802
  sender_id: this.connectorId,
20803
+ sender_node_id: this.localNodeId,
20804
+ target_node_id: targetNodeId,
20904
20805
  });
20905
20806
  const event = new MessageEvent(this.channelName, {
20906
20807
  data: {
20907
20808
  senderId: this.connectorId,
20809
+ senderNodeId: this.localNodeId,
20810
+ targetNodeId,
20908
20811
  payload: data,
20909
20812
  },
20910
20813
  });
20911
20814
  getSharedBus$1().dispatchEvent(event);
20912
20815
  }
20913
20816
  async _transportReceive() {
20914
- return await this.inbox.dequeue();
20817
+ const item = await this.inbox.dequeue();
20818
+ this.logInboxSnapshot('inpage_inbox_dequeued', {
20819
+ item_type: this._describeInboxItem(item),
20820
+ });
20821
+ return item;
20915
20822
  }
20916
20823
  async _transportClose(code, reason) {
20824
+ logger$G.debug('inpage_transport_closing', {
20825
+ channel: this.channelName,
20826
+ connector_id: this.connectorId,
20827
+ code,
20828
+ reason,
20829
+ listener_registered: this.listenerRegistered,
20830
+ timestamp: new Date().toISOString(),
20831
+ });
20917
20832
  if (this.listenerRegistered) {
20833
+ logger$G.debug('inpage_removing_listener', {
20834
+ channel: this.channelName,
20835
+ connector_id: this.connectorId,
20836
+ timestamp: new Date().toISOString(),
20837
+ });
20918
20838
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
20919
20839
  this.listenerRegistered = false;
20840
+ logger$G.debug('inpage_listener_removed', {
20841
+ channel: this.channelName,
20842
+ connector_id: this.connectorId,
20843
+ timestamp: new Date().toISOString(),
20844
+ });
20920
20845
  }
20921
20846
  if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
20922
20847
  document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
@@ -20934,6 +20859,103 @@ class InPageConnector extends BaseAsyncConnector {
20934
20859
  }
20935
20860
  return rawOrEnvelope;
20936
20861
  }
20862
+ _isWildcardTarget() {
20863
+ return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
20864
+ }
20865
+ _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
20866
+ if (this._isWildcardTarget()) {
20867
+ if (targetNodeId &&
20868
+ targetNodeId !== '*' &&
20869
+ targetNodeId !== this.localNodeId) {
20870
+ logger$G.debug('inpage_message_rejected', {
20871
+ channel: this.channelName,
20872
+ connector_id: this.connectorId,
20873
+ reason: 'wildcard_target_mismatch',
20874
+ sender_node_id: senderNodeId,
20875
+ target_node_id: targetNodeId,
20876
+ local_node_id: this.localNodeId,
20877
+ });
20878
+ return false;
20879
+ }
20880
+ return true;
20881
+ }
20882
+ const expectedSender = this.targetNodeId;
20883
+ if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
20884
+ logger$G.debug('inpage_message_rejected', {
20885
+ channel: this.channelName,
20886
+ connector_id: this.connectorId,
20887
+ reason: 'unexpected_sender',
20888
+ expected_sender_node_id: expectedSender,
20889
+ sender_node_id: senderNodeId,
20890
+ local_node_id: this.localNodeId,
20891
+ });
20892
+ return false;
20893
+ }
20894
+ if (targetNodeId &&
20895
+ targetNodeId !== '*' &&
20896
+ targetNodeId !== this.localNodeId) {
20897
+ logger$G.debug('inpage_message_rejected', {
20898
+ channel: this.channelName,
20899
+ connector_id: this.connectorId,
20900
+ reason: 'unexpected_target',
20901
+ sender_node_id: senderNodeId,
20902
+ target_node_id: targetNodeId,
20903
+ local_node_id: this.localNodeId,
20904
+ });
20905
+ return false;
20906
+ }
20907
+ return true;
20908
+ }
20909
+ _describeInboxItem(item) {
20910
+ if (item instanceof Uint8Array) {
20911
+ return 'bytes';
20912
+ }
20913
+ if (item.envelope) {
20914
+ return 'channel_message';
20915
+ }
20916
+ if (item.frame) {
20917
+ return 'envelope';
20918
+ }
20919
+ return 'unknown';
20920
+ }
20921
+ logInboxSnapshot(event, extra = {}) {
20922
+ logger$G.debug(event, {
20923
+ channel: this.channelName,
20924
+ connector_id: this.connectorId,
20925
+ connector_state: this.state,
20926
+ inbox_capacity: this.inboxCapacity,
20927
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20928
+ ...extra,
20929
+ });
20930
+ }
20931
+ setTargetNodeId(nodeId) {
20932
+ const normalized = InPageConnector.normalizeNodeId(nodeId);
20933
+ if (!normalized) {
20934
+ throw new Error('InPageConnector target node id must be a non-empty string');
20935
+ }
20936
+ if (normalized === '*') {
20937
+ this.setWildcardTarget();
20938
+ return;
20939
+ }
20940
+ this.targetNodeId = normalized;
20941
+ logger$G.debug('inpage_target_updated', {
20942
+ channel: this.channelName,
20943
+ connector_id: this.connectorId,
20944
+ local_node_id: this.localNodeId,
20945
+ target_node_id: this.targetNodeId,
20946
+ target_mode: 'direct',
20947
+ });
20948
+ }
20949
+ setWildcardTarget() {
20950
+ this.targetNodeId = '*';
20951
+ logger$G.debug('inpage_target_updated', {
20952
+ channel: this.channelName,
20953
+ connector_id: this.connectorId,
20954
+ local_node_id: this.localNodeId,
20955
+ target_node_id: this.targetNodeId,
20956
+ target_mode: 'wildcard',
20957
+ });
20958
+ }
20937
20959
  }
20938
20960
 
20939
20961
  const RPC_REGISTRY = Symbol('naylence.rpc.registry');
@@ -28921,8 +28943,16 @@ class InPageConnectorFactory extends ConnectorFactory {
28921
28943
  }
28922
28944
  const normalized = this._normalizeConfig(config);
28923
28945
  const options = (factoryArgs[0] ?? {});
28946
+ const normalizedLocalNodeFromConfig = this._normalizeNodeId(normalized.localNodeId);
28947
+ const localNodeId = this._normalizeNodeId(options.localNodeId) ?? normalizedLocalNodeFromConfig;
28948
+ if (!localNodeId) {
28949
+ throw new Error('InPageConnectorFactory requires a localNodeId from config or create() options');
28950
+ }
28924
28951
  const channelName = normalized.channelName ?? DEFAULT_CHANNEL$5;
28925
28952
  const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$5;
28953
+ const targetFromOptions = this._normalizeTargetNodeId(options.initialTargetNodeId);
28954
+ const targetFromConfig = this._normalizeTargetNodeId(normalized.initialTargetNodeId);
28955
+ const resolvedTarget = targetFromOptions ?? targetFromConfig ?? '*';
28926
28956
  const baseConfig = {
28927
28957
  drainTimeout: normalized.drainTimeout,
28928
28958
  flowControl: normalized.flowControl,
@@ -28937,6 +28967,8 @@ class InPageConnectorFactory extends ConnectorFactory {
28937
28967
  type: INPAGE_CONNECTOR_TYPE,
28938
28968
  channelName,
28939
28969
  inboxCapacity,
28970
+ localNodeId,
28971
+ initialTargetNodeId: resolvedTarget,
28940
28972
  };
28941
28973
  const connector = new InPageConnector(connectorConfig, baseConfig);
28942
28974
  if (options.authorization) {
@@ -28972,6 +29004,16 @@ class InPageConnectorFactory extends ConnectorFactory {
28972
29004
  capacity > 0) {
28973
29005
  normalized.inboxCapacity = Math.floor(capacity);
28974
29006
  }
29007
+ const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
29008
+ const normalizedLocalNodeId = this._normalizeNodeId(localNodeId);
29009
+ if (normalizedLocalNodeId) {
29010
+ normalized.localNodeId = normalizedLocalNodeId;
29011
+ }
29012
+ const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
29013
+ const normalizedTarget = this._normalizeTargetNodeId(initialTargetNodeId);
29014
+ if (normalizedTarget) {
29015
+ normalized.initialTargetNodeId = normalizedTarget;
29016
+ }
28975
29017
  if (typeof candidate.flowControl === 'boolean') {
28976
29018
  normalized.flowControl = candidate.flowControl;
28977
29019
  }
@@ -29010,6 +29052,22 @@ class InPageConnectorFactory extends ConnectorFactory {
29010
29052
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$5;
29011
29053
  return normalized;
29012
29054
  }
29055
+ _normalizeNodeId(value) {
29056
+ if (typeof value !== 'string') {
29057
+ return null;
29058
+ }
29059
+ const trimmed = value.trim();
29060
+ return trimmed.length > 0 ? trimmed : null;
29061
+ }
29062
+ _normalizeTargetNodeId(value) {
29063
+ if (value === undefined || value === null) {
29064
+ return undefined;
29065
+ }
29066
+ if (value === '*') {
29067
+ return '*';
29068
+ }
29069
+ return this._normalizeNodeId(value) ?? undefined;
29070
+ }
29013
29071
  }
29014
29072
 
29015
29073
  var inpageConnectorFactory = /*#__PURE__*/Object.freeze({
@@ -29788,7 +29846,7 @@ class InPageListener extends TransportListener {
29788
29846
  node: routingNode,
29789
29847
  });
29790
29848
  const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
29791
- connectorConfig = this._grantToConnectorConfig(selection.grant);
29849
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, this._grantToConnectorConfig(selection.grant));
29792
29850
  }
29793
29851
  catch (error) {
29794
29852
  logger$p.debug('inpage_listener_grant_selection_failed', {
@@ -29796,13 +29854,13 @@ class InPageListener extends TransportListener {
29796
29854
  system_id: systemId,
29797
29855
  error: error instanceof Error ? error.message : String(error),
29798
29856
  });
29799
- connectorConfig =
29800
- this._extractInPageConnectorConfig(frame) ??
29801
- {
29802
- type: INPAGE_CONNECTOR_TYPE,
29803
- channelName: this._channelName,
29804
- inboxCapacity: this._inboxCapacity,
29805
- };
29857
+ const fallbackConfig = this._extractInPageConnectorConfig(frame) ??
29858
+ {
29859
+ type: INPAGE_CONNECTOR_TYPE,
29860
+ channelName: this._channelName,
29861
+ inboxCapacity: this._inboxCapacity,
29862
+ };
29863
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, fallbackConfig);
29806
29864
  }
29807
29865
  try {
29808
29866
  const connector = await routingNode.createOriginConnector({
@@ -29921,6 +29979,65 @@ class InPageListener extends TransportListener {
29921
29979
  typeof frame === 'object' &&
29922
29980
  frame.type === 'NodeAttach');
29923
29981
  }
29982
+ _buildConnectorConfigForSystem(systemId, baseConfig) {
29983
+ const localNodeId = this._requireLocalNodeId();
29984
+ const targetSystemId = this._normalizeNodeId(systemId);
29985
+ if (!targetSystemId) {
29986
+ throw new Error('InPageListener requires a valid system id for connector creation');
29987
+ }
29988
+ const candidate = baseConfig ?? null;
29989
+ const channelCandidate = candidate && 'channelName' in candidate
29990
+ ? candidate.channelName
29991
+ : undefined;
29992
+ const inboxCandidate = candidate && 'inboxCapacity' in candidate
29993
+ ? candidate.inboxCapacity
29994
+ : undefined;
29995
+ const targetCandidate = candidate && 'initialTargetNodeId' in candidate
29996
+ ? candidate.initialTargetNodeId
29997
+ : undefined;
29998
+ const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
29999
+ ? channelCandidate.trim()
30000
+ : this._channelName;
30001
+ const inboxCapacity = typeof inboxCandidate === 'number' &&
30002
+ Number.isFinite(inboxCandidate) &&
30003
+ inboxCandidate > 0
30004
+ ? Math.floor(inboxCandidate)
30005
+ : this._inboxCapacity;
30006
+ const normalizedTarget = this._normalizeTargetNodeId(targetCandidate);
30007
+ return {
30008
+ type: INPAGE_CONNECTOR_TYPE,
30009
+ channelName,
30010
+ inboxCapacity,
30011
+ localNodeId,
30012
+ initialTargetNodeId: normalizedTarget ?? targetSystemId,
30013
+ };
30014
+ }
30015
+ _requireLocalNodeId() {
30016
+ if (!this._routingNode) {
30017
+ throw new Error('InPageListener requires routing node context');
30018
+ }
30019
+ const normalized = this._normalizeNodeId(this._routingNode.id);
30020
+ if (!normalized) {
30021
+ throw new Error('InPageListener requires routing node with a stable identifier');
30022
+ }
30023
+ return normalized;
30024
+ }
30025
+ _normalizeNodeId(value) {
30026
+ if (typeof value !== 'string') {
30027
+ return null;
30028
+ }
30029
+ const trimmed = value.trim();
30030
+ return trimmed.length > 0 ? trimmed : null;
30031
+ }
30032
+ _normalizeTargetNodeId(value) {
30033
+ if (value === undefined || value === null) {
30034
+ return undefined;
30035
+ }
30036
+ if (value === '*') {
30037
+ return '*';
30038
+ }
30039
+ return this._normalizeNodeId(value) ?? undefined;
30040
+ }
29924
30041
  }
29925
30042
  function getInPageListenerInstance() {
29926
30043
  return _lastInPageListenerInstance;