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