@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.
@@ -5562,12 +5562,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5562
5562
  }
5563
5563
 
5564
5564
  // This file is auto-generated during build - do not edit manually
5565
- // Generated from package.json version: 0.3.5-test.965
5565
+ // Generated from package.json version: 0.3.5-test.967
5566
5566
  /**
5567
5567
  * The package version, injected at build time.
5568
5568
  * @internal
5569
5569
  */
5570
- const VERSION = '0.3.5-test.965';
5570
+ const VERSION = '0.3.5-test.967';
5571
5571
 
5572
5572
  /**
5573
5573
  * Fame errors module - Fame protocol specific error classes
@@ -11622,11 +11622,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11622
11622
  ensureBroadcastEnvironment();
11623
11623
  super(baseConfig);
11624
11624
  this.listenerRegistered = false;
11625
- this.seenAckKeys = new Map();
11626
- this.seenAckOrder = [];
11627
- this.ackDedupTtlMs = 30000;
11628
- this.ackDedupMaxEntries = 4096;
11629
- this.textDecoder = new TextDecoder();
11630
11625
  this.visibilityChangeListenerRegistered = false;
11631
11626
  this.channelName =
11632
11627
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
@@ -11718,9 +11713,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11718
11713
  connector_id: this.connectorId,
11719
11714
  payload_length: payload.byteLength,
11720
11715
  });
11721
- if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
11722
- return;
11723
- }
11724
11716
  try {
11725
11717
  if (typeof this.inbox.tryEnqueue === 'function') {
11726
11718
  const accepted = this.inbox.tryEnqueue(payload);
@@ -11824,9 +11816,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11824
11816
  }
11825
11817
  async pushToReceive(rawOrEnvelope) {
11826
11818
  const item = this._normalizeInboxItem(rawOrEnvelope);
11827
- if (this._shouldSkipDuplicateAckFromInboxItem(item)) {
11828
- return;
11829
- }
11830
11819
  try {
11831
11820
  if (typeof this.inbox.tryEnqueue === 'function') {
11832
11821
  const accepted = this.inbox.tryEnqueue(item);
@@ -11926,8 +11915,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11926
11915
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
11927
11916
  const shutdownError = new FameTransportClose(closeReason, closeCode);
11928
11917
  this.inbox.drain(shutdownError);
11929
- this.seenAckKeys.clear();
11930
- this.seenAckOrder.length = 0;
11931
11918
  }
11932
11919
  _normalizeInboxItem(rawOrEnvelope) {
11933
11920
  if (rawOrEnvelope instanceof Uint8Array) {
@@ -12004,125 +11991,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
12004
11991
  ...extra,
12005
11992
  });
12006
11993
  }
12007
- _shouldSkipDuplicateAck(senderId, payload) {
12008
- const dedupKey = this._extractAckDedupKey(payload);
12009
- if (!dedupKey) {
12010
- return false;
12011
- }
12012
- const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
12013
- ? senderId
12014
- : undefined;
12015
- if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
12016
- logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
12017
- channel: this.channelName,
12018
- connector_id: this.connectorId,
12019
- sender_id: normalizedSenderId,
12020
- dedup_key: dedupKey,
12021
- source: 'listener',
12022
- });
12023
- return false;
12024
- }
12025
- logger$10.debug('broadcast_channel_duplicate_ack_check', {
12026
- channel: this.channelName,
12027
- connector_id: this.connectorId,
12028
- sender_id: normalizedSenderId ?? null,
12029
- dedup_key: dedupKey,
12030
- source: 'listener',
12031
- cache_entries: this.seenAckKeys.size,
12032
- });
12033
- return this._checkDuplicateAck(dedupKey, normalizedSenderId);
12034
- }
12035
- _shouldSkipDuplicateAckFromInboxItem(item) {
12036
- if (item instanceof Uint8Array) {
12037
- return this._shouldSkipDuplicateAck(undefined, item);
12038
- }
12039
- const envelope = this._extractEnvelopeFromInboxItem(item);
12040
- if (!envelope) {
12041
- return false;
12042
- }
12043
- const frame = envelope.frame;
12044
- if (!frame || frame.type !== 'DeliveryAck') {
12045
- return false;
12046
- }
12047
- const refId = typeof frame.refId === 'string' && frame.refId.length > 0
12048
- ? frame.refId
12049
- : null;
12050
- const dedupKey = refId ?? envelope.id ?? null;
12051
- if (!dedupKey) {
12052
- return false;
12053
- }
12054
- const senderId = this._extractSenderIdFromInboxItem(item);
12055
- if (senderId && senderId !== this.localNodeId) {
12056
- logger$10.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
12057
- channel: this.channelName,
12058
- connector_id: this.connectorId,
12059
- sender_id: senderId,
12060
- dedup_key: dedupKey,
12061
- source: 'inbox_item',
12062
- });
12063
- return false;
12064
- }
12065
- logger$10.debug('broadcast_channel_duplicate_ack_check', {
12066
- channel: this.channelName,
12067
- connector_id: this.connectorId,
12068
- sender_id: senderId ?? null,
12069
- dedup_key: dedupKey,
12070
- source: 'inbox_item',
12071
- cache_entries: this.seenAckKeys.size,
12072
- });
12073
- return this._checkDuplicateAck(dedupKey, senderId);
12074
- }
12075
- _checkDuplicateAck(dedupKey, senderId) {
12076
- const now = Date.now();
12077
- const lastSeen = this.seenAckKeys.get(dedupKey);
12078
- if (lastSeen && now - lastSeen < this.ackDedupTtlMs) {
12079
- logger$10.debug('broadcast_channel_duplicate_ack_suppressed', {
12080
- channel: this.channelName,
12081
- connector_id: this.connectorId,
12082
- sender_id: senderId ?? null,
12083
- dedup_key: dedupKey,
12084
- age_ms: now - lastSeen,
12085
- ttl_ms: this.ackDedupTtlMs,
12086
- cache_entries: this.seenAckKeys.size,
12087
- });
12088
- return true;
12089
- }
12090
- this.seenAckKeys.set(dedupKey, now);
12091
- this.seenAckOrder.push(dedupKey);
12092
- logger$10.debug('broadcast_channel_duplicate_ack_recorded', {
12093
- channel: this.channelName,
12094
- connector_id: this.connectorId,
12095
- sender_id: senderId ?? null,
12096
- dedup_key: dedupKey,
12097
- cache_entries: this.seenAckKeys.size,
12098
- });
12099
- this._trimSeenAcks(now);
12100
- return false;
12101
- }
12102
- _extractEnvelopeFromInboxItem(item) {
12103
- if (!item || typeof item !== 'object') {
12104
- return null;
12105
- }
12106
- if ('envelope' in item) {
12107
- return item.envelope;
12108
- }
12109
- if ('frame' in item) {
12110
- return item;
12111
- }
12112
- return null;
12113
- }
12114
- _extractSenderIdFromInboxItem(item) {
12115
- if (!item || typeof item !== 'object') {
12116
- return undefined;
12117
- }
12118
- if ('context' in item) {
12119
- const context = item.context;
12120
- if (context && typeof context.fromSystemId === 'string') {
12121
- return context.fromSystemId;
12122
- }
12123
- }
12124
- return undefined;
12125
- }
12126
11994
  /**
12127
11995
  * Override start() to check initial visibility state
12128
11996
  */
@@ -12176,47 +12044,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
12176
12044
  target_mode: 'wildcard',
12177
12045
  });
12178
12046
  }
12179
- _trimSeenAcks(now) {
12180
- while (this.seenAckOrder.length > 0) {
12181
- const candidate = this.seenAckOrder[0];
12182
- const timestamp = this.seenAckKeys.get(candidate);
12183
- if (timestamp === undefined) {
12184
- this.seenAckOrder.shift();
12185
- continue;
12186
- }
12187
- if (this.seenAckKeys.size > this.ackDedupMaxEntries ||
12188
- now - timestamp > this.ackDedupTtlMs) {
12189
- this.seenAckKeys.delete(candidate);
12190
- this.seenAckOrder.shift();
12191
- continue;
12192
- }
12193
- break;
12194
- }
12195
- }
12196
- _extractAckDedupKey(payload) {
12197
- try {
12198
- const decoded = this.textDecoder.decode(payload);
12199
- const parsed = JSON.parse(decoded);
12200
- const envelopeId = typeof parsed?.id === 'string' ? parsed.id : null;
12201
- const frameType = parsed?.frame?.type;
12202
- if (typeof frameType !== 'string' || frameType !== 'DeliveryAck') {
12203
- return null;
12204
- }
12205
- const refId = parsed.frame?.refId;
12206
- if (typeof refId === 'string' && refId.length > 0) {
12207
- return refId;
12208
- }
12209
- return envelopeId;
12210
- }
12211
- catch (error) {
12212
- logger$10.debug('broadcast_channel_ack_dedup_parse_failed', {
12213
- channel: this.channelName,
12214
- connector_id: this.connectorId,
12215
- error: error instanceof Error ? error.message : String(error),
12216
- });
12217
- return null;
12218
- }
12219
- }
12220
12047
  };
12221
12048
 
12222
12049
  const BROADCAST_CHANNEL_CONNECTOR_TYPE = 'broadcast-channel-connector';
@@ -21784,6 +21611,26 @@ class InPageConnector extends BaseAsyncConnector {
21784
21611
  }
21785
21612
  return null;
21786
21613
  }
21614
+ static normalizeNodeId(value) {
21615
+ if (typeof value !== 'string') {
21616
+ return null;
21617
+ }
21618
+ const trimmed = value.trim();
21619
+ return trimmed.length > 0 ? trimmed : null;
21620
+ }
21621
+ static normalizeTargetNodeId(value) {
21622
+ if (typeof value !== 'string') {
21623
+ return undefined;
21624
+ }
21625
+ const trimmed = value.trim();
21626
+ if (trimmed.length === 0) {
21627
+ return undefined;
21628
+ }
21629
+ if (trimmed === '*') {
21630
+ return '*';
21631
+ }
21632
+ return trimmed;
21633
+ }
21787
21634
  constructor(config, baseConfig = {}) {
21788
21635
  ensureBrowserEnvironment$2();
21789
21636
  super(baseConfig);
@@ -21799,41 +21646,68 @@ class InPageConnector extends BaseAsyncConnector {
21799
21646
  ? Math.floor(config.inboxCapacity)
21800
21647
  : DEFAULT_INBOX_CAPACITY$6;
21801
21648
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
21649
+ this.inboxCapacity = preferredCapacity;
21802
21650
  this.connectorId = InPageConnector.generateConnectorId();
21651
+ const normalizedLocalNodeId = InPageConnector.normalizeNodeId(config.localNodeId);
21652
+ if (!normalizedLocalNodeId) {
21653
+ throw new Error('InPageConnector requires a non-empty localNodeId');
21654
+ }
21655
+ this.localNodeId = normalizedLocalNodeId;
21656
+ this.targetNodeId = InPageConnector.normalizeTargetNodeId(config.initialTargetNodeId);
21803
21657
  logger$J.debug('inpage_connector_initialized', {
21804
21658
  channel: this.channelName,
21805
21659
  connector_id: this.connectorId,
21660
+ local_node_id: this.localNodeId,
21661
+ target_node_id: this.targetNodeId ?? null,
21662
+ inbox_capacity: preferredCapacity,
21806
21663
  });
21807
21664
  this.onMsg = (event) => {
21665
+ if (!this.listenerRegistered) {
21666
+ logger$J.warning('inpage_message_after_unregister', {
21667
+ channel: this.channelName,
21668
+ connector_id: this.connectorId,
21669
+ timestamp: new Date().toISOString(),
21670
+ });
21671
+ return;
21672
+ }
21808
21673
  const messageEvent = event;
21809
21674
  const message = messageEvent.data;
21810
21675
  logger$J.debug('inpage_raw_event', {
21811
21676
  channel: this.channelName,
21812
21677
  connector_id: this.connectorId,
21813
- message_type: message && typeof message === 'object' ? message.constructor?.name ?? typeof message : typeof message,
21814
- has_sender_id: Boolean(message?.senderId),
21815
- payload_type: message && typeof message === 'object'
21816
- ? message?.payload instanceof Uint8Array
21817
- ? 'Uint8Array'
21818
- : message?.payload instanceof ArrayBuffer
21819
- ? 'ArrayBuffer'
21820
- : typeof message?.payload
21678
+ message_type: message && typeof message === 'object'
21679
+ ? message.constructor?.name ?? typeof message
21821
21680
  : typeof message,
21822
- payload_constructor: message && typeof message === 'object'
21823
- ? message?.payload?.constructor?.name
21824
- : undefined,
21825
- payload_keys: message && typeof message === 'object' && message?.payload && typeof message?.payload === 'object'
21826
- ? Object.keys(message.payload).slice(0, 5)
21827
- : undefined,
21681
+ has_sender_id: Boolean(message?.senderId),
21682
+ has_sender_node_id: Boolean(message?.senderNodeId),
21828
21683
  });
21829
21684
  if (!message || typeof message !== 'object') {
21830
21685
  return;
21831
21686
  }
21832
21687
  const busMessage = message;
21833
- if (typeof busMessage.senderId !== 'string' || busMessage.senderId.length === 0) {
21688
+ const senderId = typeof busMessage.senderId === 'string' && busMessage.senderId.length > 0
21689
+ ? busMessage.senderId
21690
+ : null;
21691
+ const senderNodeId = InPageConnector.normalizeNodeId(busMessage.senderNodeId);
21692
+ if (!senderId || !senderNodeId) {
21693
+ logger$J.debug('inpage_message_rejected', {
21694
+ channel: this.channelName,
21695
+ connector_id: this.connectorId,
21696
+ reason: 'missing_sender_metadata',
21697
+ });
21834
21698
  return;
21835
21699
  }
21836
- if (busMessage.senderId === this.connectorId) {
21700
+ if (senderId === this.connectorId || senderNodeId === this.localNodeId) {
21701
+ logger$J.debug('inpage_message_rejected', {
21702
+ channel: this.channelName,
21703
+ connector_id: this.connectorId,
21704
+ reason: 'self_echo',
21705
+ sender_node_id: senderNodeId,
21706
+ });
21707
+ return;
21708
+ }
21709
+ const incomingTargetNodeId = InPageConnector.normalizeTargetNodeId(busMessage.targetNodeId);
21710
+ if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
21837
21711
  return;
21838
21712
  }
21839
21713
  const payload = InPageConnector.coercePayload(busMessage.payload);
@@ -21847,7 +21721,9 @@ class InPageConnector extends BaseAsyncConnector {
21847
21721
  }
21848
21722
  logger$J.debug('inpage_message_received', {
21849
21723
  channel: this.channelName,
21850
- sender_id: busMessage.senderId,
21724
+ sender_id: senderId,
21725
+ sender_node_id: senderNodeId,
21726
+ target_node_id: incomingTargetNodeId ?? null,
21851
21727
  connector_id: this.connectorId,
21852
21728
  payload_length: payload.byteLength,
21853
21729
  });
@@ -21855,15 +21731,27 @@ class InPageConnector extends BaseAsyncConnector {
21855
21731
  if (typeof this.inbox.tryEnqueue === 'function') {
21856
21732
  const accepted = this.inbox.tryEnqueue(payload);
21857
21733
  if (accepted) {
21734
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
21735
+ source: 'listener',
21736
+ enqueue_strategy: 'try',
21737
+ payload_length: payload.byteLength,
21738
+ });
21858
21739
  return;
21859
21740
  }
21860
21741
  }
21861
21742
  this.inbox.enqueue(payload);
21743
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
21744
+ source: 'listener',
21745
+ enqueue_strategy: 'enqueue',
21746
+ payload_length: payload.byteLength,
21747
+ });
21862
21748
  }
21863
21749
  catch (error) {
21864
21750
  if (error instanceof QueueFullError) {
21865
21751
  logger$J.warning('inpage_receive_queue_full', {
21866
21752
  channel: this.channelName,
21753
+ inbox_capacity: this.inboxCapacity,
21754
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
21867
21755
  });
21868
21756
  }
21869
21757
  else {
@@ -21970,15 +21858,25 @@ class InPageConnector extends BaseAsyncConnector {
21970
21858
  if (typeof this.inbox.tryEnqueue === 'function') {
21971
21859
  const accepted = this.inbox.tryEnqueue(item);
21972
21860
  if (accepted) {
21861
+ this.logInboxSnapshot('inpage_push_enqueued', {
21862
+ enqueue_strategy: 'try',
21863
+ item_type: this._describeInboxItem(item),
21864
+ });
21973
21865
  return;
21974
21866
  }
21975
21867
  }
21976
21868
  this.inbox.enqueue(item);
21869
+ this.logInboxSnapshot('inpage_push_enqueued', {
21870
+ enqueue_strategy: 'enqueue',
21871
+ item_type: this._describeInboxItem(item),
21872
+ });
21977
21873
  }
21978
21874
  catch (error) {
21979
21875
  if (error instanceof QueueFullError) {
21980
21876
  logger$J.warning('inpage_push_queue_full', {
21981
21877
  channel: this.channelName,
21878
+ inbox_capacity: this.inboxCapacity,
21879
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
21982
21880
  });
21983
21881
  throw error;
21984
21882
  }
@@ -21991,25 +21889,52 @@ class InPageConnector extends BaseAsyncConnector {
21991
21889
  }
21992
21890
  async _transportSendBytes(data) {
21993
21891
  ensureBrowserEnvironment$2();
21892
+ const targetNodeId = this.targetNodeId ?? '*';
21994
21893
  logger$J.debug('inpage_message_sending', {
21995
21894
  channel: this.channelName,
21996
21895
  sender_id: this.connectorId,
21896
+ sender_node_id: this.localNodeId,
21897
+ target_node_id: targetNodeId,
21997
21898
  });
21998
21899
  const event = new MessageEvent(this.channelName, {
21999
21900
  data: {
22000
21901
  senderId: this.connectorId,
21902
+ senderNodeId: this.localNodeId,
21903
+ targetNodeId,
22001
21904
  payload: data,
22002
21905
  },
22003
21906
  });
22004
21907
  getSharedBus$1().dispatchEvent(event);
22005
21908
  }
22006
21909
  async _transportReceive() {
22007
- return await this.inbox.dequeue();
21910
+ const item = await this.inbox.dequeue();
21911
+ this.logInboxSnapshot('inpage_inbox_dequeued', {
21912
+ item_type: this._describeInboxItem(item),
21913
+ });
21914
+ return item;
22008
21915
  }
22009
21916
  async _transportClose(code, reason) {
21917
+ logger$J.debug('inpage_transport_closing', {
21918
+ channel: this.channelName,
21919
+ connector_id: this.connectorId,
21920
+ code,
21921
+ reason,
21922
+ listener_registered: this.listenerRegistered,
21923
+ timestamp: new Date().toISOString(),
21924
+ });
22010
21925
  if (this.listenerRegistered) {
21926
+ logger$J.debug('inpage_removing_listener', {
21927
+ channel: this.channelName,
21928
+ connector_id: this.connectorId,
21929
+ timestamp: new Date().toISOString(),
21930
+ });
22011
21931
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
22012
21932
  this.listenerRegistered = false;
21933
+ logger$J.debug('inpage_listener_removed', {
21934
+ channel: this.channelName,
21935
+ connector_id: this.connectorId,
21936
+ timestamp: new Date().toISOString(),
21937
+ });
22013
21938
  }
22014
21939
  if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
22015
21940
  document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
@@ -22027,6 +21952,103 @@ class InPageConnector extends BaseAsyncConnector {
22027
21952
  }
22028
21953
  return rawOrEnvelope;
22029
21954
  }
21955
+ _isWildcardTarget() {
21956
+ return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
21957
+ }
21958
+ _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
21959
+ if (this._isWildcardTarget()) {
21960
+ if (targetNodeId &&
21961
+ targetNodeId !== '*' &&
21962
+ targetNodeId !== this.localNodeId) {
21963
+ logger$J.debug('inpage_message_rejected', {
21964
+ channel: this.channelName,
21965
+ connector_id: this.connectorId,
21966
+ reason: 'wildcard_target_mismatch',
21967
+ sender_node_id: senderNodeId,
21968
+ target_node_id: targetNodeId,
21969
+ local_node_id: this.localNodeId,
21970
+ });
21971
+ return false;
21972
+ }
21973
+ return true;
21974
+ }
21975
+ const expectedSender = this.targetNodeId;
21976
+ if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
21977
+ logger$J.debug('inpage_message_rejected', {
21978
+ channel: this.channelName,
21979
+ connector_id: this.connectorId,
21980
+ reason: 'unexpected_sender',
21981
+ expected_sender_node_id: expectedSender,
21982
+ sender_node_id: senderNodeId,
21983
+ local_node_id: this.localNodeId,
21984
+ });
21985
+ return false;
21986
+ }
21987
+ if (targetNodeId &&
21988
+ targetNodeId !== '*' &&
21989
+ targetNodeId !== this.localNodeId) {
21990
+ logger$J.debug('inpage_message_rejected', {
21991
+ channel: this.channelName,
21992
+ connector_id: this.connectorId,
21993
+ reason: 'unexpected_target',
21994
+ sender_node_id: senderNodeId,
21995
+ target_node_id: targetNodeId,
21996
+ local_node_id: this.localNodeId,
21997
+ });
21998
+ return false;
21999
+ }
22000
+ return true;
22001
+ }
22002
+ _describeInboxItem(item) {
22003
+ if (item instanceof Uint8Array) {
22004
+ return 'bytes';
22005
+ }
22006
+ if (item.envelope) {
22007
+ return 'channel_message';
22008
+ }
22009
+ if (item.frame) {
22010
+ return 'envelope';
22011
+ }
22012
+ return 'unknown';
22013
+ }
22014
+ logInboxSnapshot(event, extra = {}) {
22015
+ logger$J.debug(event, {
22016
+ channel: this.channelName,
22017
+ connector_id: this.connectorId,
22018
+ connector_state: this.state,
22019
+ inbox_capacity: this.inboxCapacity,
22020
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
22021
+ ...extra,
22022
+ });
22023
+ }
22024
+ setTargetNodeId(nodeId) {
22025
+ const normalized = InPageConnector.normalizeNodeId(nodeId);
22026
+ if (!normalized) {
22027
+ throw new Error('InPageConnector target node id must be a non-empty string');
22028
+ }
22029
+ if (normalized === '*') {
22030
+ this.setWildcardTarget();
22031
+ return;
22032
+ }
22033
+ this.targetNodeId = normalized;
22034
+ logger$J.debug('inpage_target_updated', {
22035
+ channel: this.channelName,
22036
+ connector_id: this.connectorId,
22037
+ local_node_id: this.localNodeId,
22038
+ target_node_id: this.targetNodeId,
22039
+ target_mode: 'direct',
22040
+ });
22041
+ }
22042
+ setWildcardTarget() {
22043
+ this.targetNodeId = '*';
22044
+ logger$J.debug('inpage_target_updated', {
22045
+ channel: this.channelName,
22046
+ connector_id: this.connectorId,
22047
+ local_node_id: this.localNodeId,
22048
+ target_node_id: this.targetNodeId,
22049
+ target_mode: 'wildcard',
22050
+ });
22051
+ }
22030
22052
  }
22031
22053
 
22032
22054
  const RPC_REGISTRY = Symbol('naylence.rpc.registry');
@@ -30607,8 +30629,16 @@ class InPageConnectorFactory extends ConnectorFactory {
30607
30629
  }
30608
30630
  const normalized = this._normalizeConfig(config);
30609
30631
  const options = (factoryArgs[0] ?? {});
30632
+ const normalizedLocalNodeFromConfig = this._normalizeNodeId(normalized.localNodeId);
30633
+ const localNodeId = this._normalizeNodeId(options.localNodeId) ?? normalizedLocalNodeFromConfig;
30634
+ if (!localNodeId) {
30635
+ throw new Error('InPageConnectorFactory requires a localNodeId from config or create() options');
30636
+ }
30610
30637
  const channelName = normalized.channelName ?? DEFAULT_CHANNEL$3;
30611
30638
  const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
30639
+ const targetFromOptions = this._normalizeTargetNodeId(options.initialTargetNodeId);
30640
+ const targetFromConfig = this._normalizeTargetNodeId(normalized.initialTargetNodeId);
30641
+ const resolvedTarget = targetFromOptions ?? targetFromConfig ?? '*';
30612
30642
  const baseConfig = {
30613
30643
  drainTimeout: normalized.drainTimeout,
30614
30644
  flowControl: normalized.flowControl,
@@ -30623,6 +30653,8 @@ class InPageConnectorFactory extends ConnectorFactory {
30623
30653
  type: INPAGE_CONNECTOR_TYPE,
30624
30654
  channelName,
30625
30655
  inboxCapacity,
30656
+ localNodeId,
30657
+ initialTargetNodeId: resolvedTarget,
30626
30658
  };
30627
30659
  const connector = new InPageConnector(connectorConfig, baseConfig);
30628
30660
  if (options.authorization) {
@@ -30658,6 +30690,16 @@ class InPageConnectorFactory extends ConnectorFactory {
30658
30690
  capacity > 0) {
30659
30691
  normalized.inboxCapacity = Math.floor(capacity);
30660
30692
  }
30693
+ const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
30694
+ const normalizedLocalNodeId = this._normalizeNodeId(localNodeId);
30695
+ if (normalizedLocalNodeId) {
30696
+ normalized.localNodeId = normalizedLocalNodeId;
30697
+ }
30698
+ const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
30699
+ const normalizedTarget = this._normalizeTargetNodeId(initialTargetNodeId);
30700
+ if (normalizedTarget) {
30701
+ normalized.initialTargetNodeId = normalizedTarget;
30702
+ }
30661
30703
  if (typeof candidate.flowControl === 'boolean') {
30662
30704
  normalized.flowControl = candidate.flowControl;
30663
30705
  }
@@ -30696,6 +30738,22 @@ class InPageConnectorFactory extends ConnectorFactory {
30696
30738
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
30697
30739
  return normalized;
30698
30740
  }
30741
+ _normalizeNodeId(value) {
30742
+ if (typeof value !== 'string') {
30743
+ return null;
30744
+ }
30745
+ const trimmed = value.trim();
30746
+ return trimmed.length > 0 ? trimmed : null;
30747
+ }
30748
+ _normalizeTargetNodeId(value) {
30749
+ if (value === undefined || value === null) {
30750
+ return undefined;
30751
+ }
30752
+ if (value === '*') {
30753
+ return '*';
30754
+ }
30755
+ return this._normalizeNodeId(value) ?? undefined;
30756
+ }
30699
30757
  }
30700
30758
 
30701
30759
  var inpageConnectorFactory = /*#__PURE__*/Object.freeze({
@@ -32590,7 +32648,7 @@ class InPageListener extends TransportListener {
32590
32648
  node: routingNode,
32591
32649
  });
32592
32650
  const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
32593
- connectorConfig = this._grantToConnectorConfig(selection.grant);
32651
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, this._grantToConnectorConfig(selection.grant));
32594
32652
  }
32595
32653
  catch (error) {
32596
32654
  logger$o.debug('inpage_listener_grant_selection_failed', {
@@ -32598,13 +32656,13 @@ class InPageListener extends TransportListener {
32598
32656
  system_id: systemId,
32599
32657
  error: error instanceof Error ? error.message : String(error),
32600
32658
  });
32601
- connectorConfig =
32602
- this._extractInPageConnectorConfig(frame) ??
32603
- {
32604
- type: INPAGE_CONNECTOR_TYPE,
32605
- channelName: this._channelName,
32606
- inboxCapacity: this._inboxCapacity,
32607
- };
32659
+ const fallbackConfig = this._extractInPageConnectorConfig(frame) ??
32660
+ {
32661
+ type: INPAGE_CONNECTOR_TYPE,
32662
+ channelName: this._channelName,
32663
+ inboxCapacity: this._inboxCapacity,
32664
+ };
32665
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, fallbackConfig);
32608
32666
  }
32609
32667
  try {
32610
32668
  const connector = await routingNode.createOriginConnector({
@@ -32723,6 +32781,65 @@ class InPageListener extends TransportListener {
32723
32781
  typeof frame === 'object' &&
32724
32782
  frame.type === 'NodeAttach');
32725
32783
  }
32784
+ _buildConnectorConfigForSystem(systemId, baseConfig) {
32785
+ const localNodeId = this._requireLocalNodeId();
32786
+ const targetSystemId = this._normalizeNodeId(systemId);
32787
+ if (!targetSystemId) {
32788
+ throw new Error('InPageListener requires a valid system id for connector creation');
32789
+ }
32790
+ const candidate = baseConfig ?? null;
32791
+ const channelCandidate = candidate && 'channelName' in candidate
32792
+ ? candidate.channelName
32793
+ : undefined;
32794
+ const inboxCandidate = candidate && 'inboxCapacity' in candidate
32795
+ ? candidate.inboxCapacity
32796
+ : undefined;
32797
+ const targetCandidate = candidate && 'initialTargetNodeId' in candidate
32798
+ ? candidate.initialTargetNodeId
32799
+ : undefined;
32800
+ const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
32801
+ ? channelCandidate.trim()
32802
+ : this._channelName;
32803
+ const inboxCapacity = typeof inboxCandidate === 'number' &&
32804
+ Number.isFinite(inboxCandidate) &&
32805
+ inboxCandidate > 0
32806
+ ? Math.floor(inboxCandidate)
32807
+ : this._inboxCapacity;
32808
+ const normalizedTarget = this._normalizeTargetNodeId(targetCandidate);
32809
+ return {
32810
+ type: INPAGE_CONNECTOR_TYPE,
32811
+ channelName,
32812
+ inboxCapacity,
32813
+ localNodeId,
32814
+ initialTargetNodeId: normalizedTarget ?? targetSystemId,
32815
+ };
32816
+ }
32817
+ _requireLocalNodeId() {
32818
+ if (!this._routingNode) {
32819
+ throw new Error('InPageListener requires routing node context');
32820
+ }
32821
+ const normalized = this._normalizeNodeId(this._routingNode.id);
32822
+ if (!normalized) {
32823
+ throw new Error('InPageListener requires routing node with a stable identifier');
32824
+ }
32825
+ return normalized;
32826
+ }
32827
+ _normalizeNodeId(value) {
32828
+ if (typeof value !== 'string') {
32829
+ return null;
32830
+ }
32831
+ const trimmed = value.trim();
32832
+ return trimmed.length > 0 ? trimmed : null;
32833
+ }
32834
+ _normalizeTargetNodeId(value) {
32835
+ if (value === undefined || value === null) {
32836
+ return undefined;
32837
+ }
32838
+ if (value === '*') {
32839
+ return '*';
32840
+ }
32841
+ return this._normalizeNodeId(value) ?? undefined;
32842
+ }
32726
32843
  }
32727
32844
  function getInPageListenerInstance() {
32728
32845
  return _lastInPageListenerInstance;