@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.
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.3.5-test.965
16
+ // Generated from package.json version: 0.3.5-test.967
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.3.5-test.965';
21
+ const VERSION = '0.3.5-test.967';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9885,11 +9885,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9885
9885
  ensureBroadcastEnvironment();
9886
9886
  super(baseConfig);
9887
9887
  this.listenerRegistered = false;
9888
- this.seenAckKeys = new Map();
9889
- this.seenAckOrder = [];
9890
- this.ackDedupTtlMs = 30000;
9891
- this.ackDedupMaxEntries = 4096;
9892
- this.textDecoder = new TextDecoder();
9893
9888
  this.visibilityChangeListenerRegistered = false;
9894
9889
  this.channelName =
9895
9890
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
@@ -9981,9 +9976,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9981
9976
  connector_id: this.connectorId,
9982
9977
  payload_length: payload.byteLength,
9983
9978
  });
9984
- if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
9985
- return;
9986
- }
9987
9979
  try {
9988
9980
  if (typeof this.inbox.tryEnqueue === 'function') {
9989
9981
  const accepted = this.inbox.tryEnqueue(payload);
@@ -10087,9 +10079,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10087
10079
  }
10088
10080
  async pushToReceive(rawOrEnvelope) {
10089
10081
  const item = this._normalizeInboxItem(rawOrEnvelope);
10090
- if (this._shouldSkipDuplicateAckFromInboxItem(item)) {
10091
- return;
10092
- }
10093
10082
  try {
10094
10083
  if (typeof this.inbox.tryEnqueue === 'function') {
10095
10084
  const accepted = this.inbox.tryEnqueue(item);
@@ -10189,8 +10178,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10189
10178
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
10190
10179
  const shutdownError = new FameTransportClose(closeReason, closeCode);
10191
10180
  this.inbox.drain(shutdownError);
10192
- this.seenAckKeys.clear();
10193
- this.seenAckOrder.length = 0;
10194
10181
  }
10195
10182
  _normalizeInboxItem(rawOrEnvelope) {
10196
10183
  if (rawOrEnvelope instanceof Uint8Array) {
@@ -10267,125 +10254,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10267
10254
  ...extra,
10268
10255
  });
10269
10256
  }
10270
- _shouldSkipDuplicateAck(senderId, payload) {
10271
- const dedupKey = this._extractAckDedupKey(payload);
10272
- if (!dedupKey) {
10273
- return false;
10274
- }
10275
- const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
10276
- ? senderId
10277
- : undefined;
10278
- if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
10279
- logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10280
- channel: this.channelName,
10281
- connector_id: this.connectorId,
10282
- sender_id: normalizedSenderId,
10283
- dedup_key: dedupKey,
10284
- source: 'listener',
10285
- });
10286
- return false;
10287
- }
10288
- logger$_.debug('broadcast_channel_duplicate_ack_check', {
10289
- channel: this.channelName,
10290
- connector_id: this.connectorId,
10291
- sender_id: normalizedSenderId ?? null,
10292
- dedup_key: dedupKey,
10293
- source: 'listener',
10294
- cache_entries: this.seenAckKeys.size,
10295
- });
10296
- return this._checkDuplicateAck(dedupKey, normalizedSenderId);
10297
- }
10298
- _shouldSkipDuplicateAckFromInboxItem(item) {
10299
- if (item instanceof Uint8Array) {
10300
- return this._shouldSkipDuplicateAck(undefined, item);
10301
- }
10302
- const envelope = this._extractEnvelopeFromInboxItem(item);
10303
- if (!envelope) {
10304
- return false;
10305
- }
10306
- const frame = envelope.frame;
10307
- if (!frame || frame.type !== 'DeliveryAck') {
10308
- return false;
10309
- }
10310
- const refId = typeof frame.refId === 'string' && frame.refId.length > 0
10311
- ? frame.refId
10312
- : null;
10313
- const dedupKey = refId ?? envelope.id ?? null;
10314
- if (!dedupKey) {
10315
- return false;
10316
- }
10317
- const senderId = this._extractSenderIdFromInboxItem(item);
10318
- if (senderId && senderId !== this.localNodeId) {
10319
- logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10320
- channel: this.channelName,
10321
- connector_id: this.connectorId,
10322
- sender_id: senderId,
10323
- dedup_key: dedupKey,
10324
- source: 'inbox_item',
10325
- });
10326
- return false;
10327
- }
10328
- logger$_.debug('broadcast_channel_duplicate_ack_check', {
10329
- channel: this.channelName,
10330
- connector_id: this.connectorId,
10331
- sender_id: senderId ?? null,
10332
- dedup_key: dedupKey,
10333
- source: 'inbox_item',
10334
- cache_entries: this.seenAckKeys.size,
10335
- });
10336
- return this._checkDuplicateAck(dedupKey, senderId);
10337
- }
10338
- _checkDuplicateAck(dedupKey, senderId) {
10339
- const now = Date.now();
10340
- const lastSeen = this.seenAckKeys.get(dedupKey);
10341
- if (lastSeen && now - lastSeen < this.ackDedupTtlMs) {
10342
- logger$_.debug('broadcast_channel_duplicate_ack_suppressed', {
10343
- channel: this.channelName,
10344
- connector_id: this.connectorId,
10345
- sender_id: senderId ?? null,
10346
- dedup_key: dedupKey,
10347
- age_ms: now - lastSeen,
10348
- ttl_ms: this.ackDedupTtlMs,
10349
- cache_entries: this.seenAckKeys.size,
10350
- });
10351
- return true;
10352
- }
10353
- this.seenAckKeys.set(dedupKey, now);
10354
- this.seenAckOrder.push(dedupKey);
10355
- logger$_.debug('broadcast_channel_duplicate_ack_recorded', {
10356
- channel: this.channelName,
10357
- connector_id: this.connectorId,
10358
- sender_id: senderId ?? null,
10359
- dedup_key: dedupKey,
10360
- cache_entries: this.seenAckKeys.size,
10361
- });
10362
- this._trimSeenAcks(now);
10363
- return false;
10364
- }
10365
- _extractEnvelopeFromInboxItem(item) {
10366
- if (!item || typeof item !== 'object') {
10367
- return null;
10368
- }
10369
- if ('envelope' in item) {
10370
- return item.envelope;
10371
- }
10372
- if ('frame' in item) {
10373
- return item;
10374
- }
10375
- return null;
10376
- }
10377
- _extractSenderIdFromInboxItem(item) {
10378
- if (!item || typeof item !== 'object') {
10379
- return undefined;
10380
- }
10381
- if ('context' in item) {
10382
- const context = item.context;
10383
- if (context && typeof context.fromSystemId === 'string') {
10384
- return context.fromSystemId;
10385
- }
10386
- }
10387
- return undefined;
10388
- }
10389
10257
  /**
10390
10258
  * Override start() to check initial visibility state
10391
10259
  */
@@ -10439,47 +10307,6 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10439
10307
  target_mode: 'wildcard',
10440
10308
  });
10441
10309
  }
10442
- _trimSeenAcks(now) {
10443
- while (this.seenAckOrder.length > 0) {
10444
- const candidate = this.seenAckOrder[0];
10445
- const timestamp = this.seenAckKeys.get(candidate);
10446
- if (timestamp === undefined) {
10447
- this.seenAckOrder.shift();
10448
- continue;
10449
- }
10450
- if (this.seenAckKeys.size > this.ackDedupMaxEntries ||
10451
- now - timestamp > this.ackDedupTtlMs) {
10452
- this.seenAckKeys.delete(candidate);
10453
- this.seenAckOrder.shift();
10454
- continue;
10455
- }
10456
- break;
10457
- }
10458
- }
10459
- _extractAckDedupKey(payload) {
10460
- try {
10461
- const decoded = this.textDecoder.decode(payload);
10462
- const parsed = JSON.parse(decoded);
10463
- const envelopeId = typeof parsed?.id === 'string' ? parsed.id : null;
10464
- const frameType = parsed?.frame?.type;
10465
- if (typeof frameType !== 'string' || frameType !== 'DeliveryAck') {
10466
- return null;
10467
- }
10468
- const refId = parsed.frame?.refId;
10469
- if (typeof refId === 'string' && refId.length > 0) {
10470
- return refId;
10471
- }
10472
- return envelopeId;
10473
- }
10474
- catch (error) {
10475
- logger$_.debug('broadcast_channel_ack_dedup_parse_failed', {
10476
- channel: this.channelName,
10477
- connector_id: this.connectorId,
10478
- error: error instanceof Error ? error.message : String(error),
10479
- });
10480
- return null;
10481
- }
10482
- }
10483
10310
  };
10484
10311
 
10485
10312
  const ERROR_MESSAGE = 'BroadcastChannelConnector is browser-only and requires BroadcastChannel support';
@@ -20606,6 +20433,26 @@ class InPageConnector extends BaseAsyncConnector {
20606
20433
  }
20607
20434
  return null;
20608
20435
  }
20436
+ static normalizeNodeId(value) {
20437
+ if (typeof value !== 'string') {
20438
+ return null;
20439
+ }
20440
+ const trimmed = value.trim();
20441
+ return trimmed.length > 0 ? trimmed : null;
20442
+ }
20443
+ static normalizeTargetNodeId(value) {
20444
+ if (typeof value !== 'string') {
20445
+ return undefined;
20446
+ }
20447
+ const trimmed = value.trim();
20448
+ if (trimmed.length === 0) {
20449
+ return undefined;
20450
+ }
20451
+ if (trimmed === '*') {
20452
+ return '*';
20453
+ }
20454
+ return trimmed;
20455
+ }
20609
20456
  constructor(config, baseConfig = {}) {
20610
20457
  ensureBrowserEnvironment$2();
20611
20458
  super(baseConfig);
@@ -20621,41 +20468,68 @@ class InPageConnector extends BaseAsyncConnector {
20621
20468
  ? Math.floor(config.inboxCapacity)
20622
20469
  : DEFAULT_INBOX_CAPACITY$6;
20623
20470
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
20471
+ this.inboxCapacity = preferredCapacity;
20624
20472
  this.connectorId = InPageConnector.generateConnectorId();
20473
+ const normalizedLocalNodeId = InPageConnector.normalizeNodeId(config.localNodeId);
20474
+ if (!normalizedLocalNodeId) {
20475
+ throw new Error('InPageConnector requires a non-empty localNodeId');
20476
+ }
20477
+ this.localNodeId = normalizedLocalNodeId;
20478
+ this.targetNodeId = InPageConnector.normalizeTargetNodeId(config.initialTargetNodeId);
20625
20479
  logger$G.debug('inpage_connector_initialized', {
20626
20480
  channel: this.channelName,
20627
20481
  connector_id: this.connectorId,
20482
+ local_node_id: this.localNodeId,
20483
+ target_node_id: this.targetNodeId ?? null,
20484
+ inbox_capacity: preferredCapacity,
20628
20485
  });
20629
20486
  this.onMsg = (event) => {
20487
+ if (!this.listenerRegistered) {
20488
+ logger$G.warning('inpage_message_after_unregister', {
20489
+ channel: this.channelName,
20490
+ connector_id: this.connectorId,
20491
+ timestamp: new Date().toISOString(),
20492
+ });
20493
+ return;
20494
+ }
20630
20495
  const messageEvent = event;
20631
20496
  const message = messageEvent.data;
20632
20497
  logger$G.debug('inpage_raw_event', {
20633
20498
  channel: this.channelName,
20634
20499
  connector_id: this.connectorId,
20635
- message_type: message && typeof message === 'object' ? message.constructor?.name ?? typeof message : typeof message,
20636
- has_sender_id: Boolean(message?.senderId),
20637
- payload_type: message && typeof message === 'object'
20638
- ? message?.payload instanceof Uint8Array
20639
- ? 'Uint8Array'
20640
- : message?.payload instanceof ArrayBuffer
20641
- ? 'ArrayBuffer'
20642
- : typeof message?.payload
20500
+ message_type: message && typeof message === 'object'
20501
+ ? message.constructor?.name ?? typeof message
20643
20502
  : typeof message,
20644
- payload_constructor: message && typeof message === 'object'
20645
- ? message?.payload?.constructor?.name
20646
- : undefined,
20647
- payload_keys: message && typeof message === 'object' && message?.payload && typeof message?.payload === 'object'
20648
- ? Object.keys(message.payload).slice(0, 5)
20649
- : undefined,
20503
+ has_sender_id: Boolean(message?.senderId),
20504
+ has_sender_node_id: Boolean(message?.senderNodeId),
20650
20505
  });
20651
20506
  if (!message || typeof message !== 'object') {
20652
20507
  return;
20653
20508
  }
20654
20509
  const busMessage = message;
20655
- if (typeof busMessage.senderId !== 'string' || busMessage.senderId.length === 0) {
20510
+ const senderId = typeof busMessage.senderId === 'string' && busMessage.senderId.length > 0
20511
+ ? busMessage.senderId
20512
+ : null;
20513
+ const senderNodeId = InPageConnector.normalizeNodeId(busMessage.senderNodeId);
20514
+ if (!senderId || !senderNodeId) {
20515
+ logger$G.debug('inpage_message_rejected', {
20516
+ channel: this.channelName,
20517
+ connector_id: this.connectorId,
20518
+ reason: 'missing_sender_metadata',
20519
+ });
20656
20520
  return;
20657
20521
  }
20658
- if (busMessage.senderId === this.connectorId) {
20522
+ if (senderId === this.connectorId || senderNodeId === this.localNodeId) {
20523
+ logger$G.debug('inpage_message_rejected', {
20524
+ channel: this.channelName,
20525
+ connector_id: this.connectorId,
20526
+ reason: 'self_echo',
20527
+ sender_node_id: senderNodeId,
20528
+ });
20529
+ return;
20530
+ }
20531
+ const incomingTargetNodeId = InPageConnector.normalizeTargetNodeId(busMessage.targetNodeId);
20532
+ if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
20659
20533
  return;
20660
20534
  }
20661
20535
  const payload = InPageConnector.coercePayload(busMessage.payload);
@@ -20669,7 +20543,9 @@ class InPageConnector extends BaseAsyncConnector {
20669
20543
  }
20670
20544
  logger$G.debug('inpage_message_received', {
20671
20545
  channel: this.channelName,
20672
- sender_id: busMessage.senderId,
20546
+ sender_id: senderId,
20547
+ sender_node_id: senderNodeId,
20548
+ target_node_id: incomingTargetNodeId ?? null,
20673
20549
  connector_id: this.connectorId,
20674
20550
  payload_length: payload.byteLength,
20675
20551
  });
@@ -20677,15 +20553,27 @@ class InPageConnector extends BaseAsyncConnector {
20677
20553
  if (typeof this.inbox.tryEnqueue === 'function') {
20678
20554
  const accepted = this.inbox.tryEnqueue(payload);
20679
20555
  if (accepted) {
20556
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
20557
+ source: 'listener',
20558
+ enqueue_strategy: 'try',
20559
+ payload_length: payload.byteLength,
20560
+ });
20680
20561
  return;
20681
20562
  }
20682
20563
  }
20683
20564
  this.inbox.enqueue(payload);
20565
+ this.logInboxSnapshot('inpage_inbox_enqueued', {
20566
+ source: 'listener',
20567
+ enqueue_strategy: 'enqueue',
20568
+ payload_length: payload.byteLength,
20569
+ });
20684
20570
  }
20685
20571
  catch (error) {
20686
20572
  if (error instanceof QueueFullError) {
20687
20573
  logger$G.warning('inpage_receive_queue_full', {
20688
20574
  channel: this.channelName,
20575
+ inbox_capacity: this.inboxCapacity,
20576
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20689
20577
  });
20690
20578
  }
20691
20579
  else {
@@ -20792,15 +20680,25 @@ class InPageConnector extends BaseAsyncConnector {
20792
20680
  if (typeof this.inbox.tryEnqueue === 'function') {
20793
20681
  const accepted = this.inbox.tryEnqueue(item);
20794
20682
  if (accepted) {
20683
+ this.logInboxSnapshot('inpage_push_enqueued', {
20684
+ enqueue_strategy: 'try',
20685
+ item_type: this._describeInboxItem(item),
20686
+ });
20795
20687
  return;
20796
20688
  }
20797
20689
  }
20798
20690
  this.inbox.enqueue(item);
20691
+ this.logInboxSnapshot('inpage_push_enqueued', {
20692
+ enqueue_strategy: 'enqueue',
20693
+ item_type: this._describeInboxItem(item),
20694
+ });
20799
20695
  }
20800
20696
  catch (error) {
20801
20697
  if (error instanceof QueueFullError) {
20802
20698
  logger$G.warning('inpage_push_queue_full', {
20803
20699
  channel: this.channelName,
20700
+ inbox_capacity: this.inboxCapacity,
20701
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20804
20702
  });
20805
20703
  throw error;
20806
20704
  }
@@ -20813,25 +20711,52 @@ class InPageConnector extends BaseAsyncConnector {
20813
20711
  }
20814
20712
  async _transportSendBytes(data) {
20815
20713
  ensureBrowserEnvironment$2();
20714
+ const targetNodeId = this.targetNodeId ?? '*';
20816
20715
  logger$G.debug('inpage_message_sending', {
20817
20716
  channel: this.channelName,
20818
20717
  sender_id: this.connectorId,
20718
+ sender_node_id: this.localNodeId,
20719
+ target_node_id: targetNodeId,
20819
20720
  });
20820
20721
  const event = new MessageEvent(this.channelName, {
20821
20722
  data: {
20822
20723
  senderId: this.connectorId,
20724
+ senderNodeId: this.localNodeId,
20725
+ targetNodeId,
20823
20726
  payload: data,
20824
20727
  },
20825
20728
  });
20826
20729
  getSharedBus$1().dispatchEvent(event);
20827
20730
  }
20828
20731
  async _transportReceive() {
20829
- return await this.inbox.dequeue();
20732
+ const item = await this.inbox.dequeue();
20733
+ this.logInboxSnapshot('inpage_inbox_dequeued', {
20734
+ item_type: this._describeInboxItem(item),
20735
+ });
20736
+ return item;
20830
20737
  }
20831
20738
  async _transportClose(code, reason) {
20739
+ logger$G.debug('inpage_transport_closing', {
20740
+ channel: this.channelName,
20741
+ connector_id: this.connectorId,
20742
+ code,
20743
+ reason,
20744
+ listener_registered: this.listenerRegistered,
20745
+ timestamp: new Date().toISOString(),
20746
+ });
20832
20747
  if (this.listenerRegistered) {
20748
+ logger$G.debug('inpage_removing_listener', {
20749
+ channel: this.channelName,
20750
+ connector_id: this.connectorId,
20751
+ timestamp: new Date().toISOString(),
20752
+ });
20833
20753
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
20834
20754
  this.listenerRegistered = false;
20755
+ logger$G.debug('inpage_listener_removed', {
20756
+ channel: this.channelName,
20757
+ connector_id: this.connectorId,
20758
+ timestamp: new Date().toISOString(),
20759
+ });
20835
20760
  }
20836
20761
  if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
20837
20762
  document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
@@ -20849,6 +20774,103 @@ class InPageConnector extends BaseAsyncConnector {
20849
20774
  }
20850
20775
  return rawOrEnvelope;
20851
20776
  }
20777
+ _isWildcardTarget() {
20778
+ return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
20779
+ }
20780
+ _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
20781
+ if (this._isWildcardTarget()) {
20782
+ if (targetNodeId &&
20783
+ targetNodeId !== '*' &&
20784
+ targetNodeId !== this.localNodeId) {
20785
+ logger$G.debug('inpage_message_rejected', {
20786
+ channel: this.channelName,
20787
+ connector_id: this.connectorId,
20788
+ reason: 'wildcard_target_mismatch',
20789
+ sender_node_id: senderNodeId,
20790
+ target_node_id: targetNodeId,
20791
+ local_node_id: this.localNodeId,
20792
+ });
20793
+ return false;
20794
+ }
20795
+ return true;
20796
+ }
20797
+ const expectedSender = this.targetNodeId;
20798
+ if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
20799
+ logger$G.debug('inpage_message_rejected', {
20800
+ channel: this.channelName,
20801
+ connector_id: this.connectorId,
20802
+ reason: 'unexpected_sender',
20803
+ expected_sender_node_id: expectedSender,
20804
+ sender_node_id: senderNodeId,
20805
+ local_node_id: this.localNodeId,
20806
+ });
20807
+ return false;
20808
+ }
20809
+ if (targetNodeId &&
20810
+ targetNodeId !== '*' &&
20811
+ targetNodeId !== this.localNodeId) {
20812
+ logger$G.debug('inpage_message_rejected', {
20813
+ channel: this.channelName,
20814
+ connector_id: this.connectorId,
20815
+ reason: 'unexpected_target',
20816
+ sender_node_id: senderNodeId,
20817
+ target_node_id: targetNodeId,
20818
+ local_node_id: this.localNodeId,
20819
+ });
20820
+ return false;
20821
+ }
20822
+ return true;
20823
+ }
20824
+ _describeInboxItem(item) {
20825
+ if (item instanceof Uint8Array) {
20826
+ return 'bytes';
20827
+ }
20828
+ if (item.envelope) {
20829
+ return 'channel_message';
20830
+ }
20831
+ if (item.frame) {
20832
+ return 'envelope';
20833
+ }
20834
+ return 'unknown';
20835
+ }
20836
+ logInboxSnapshot(event, extra = {}) {
20837
+ logger$G.debug(event, {
20838
+ channel: this.channelName,
20839
+ connector_id: this.connectorId,
20840
+ connector_state: this.state,
20841
+ inbox_capacity: this.inboxCapacity,
20842
+ inbox_remaining_capacity: this.inbox.remainingCapacity,
20843
+ ...extra,
20844
+ });
20845
+ }
20846
+ setTargetNodeId(nodeId) {
20847
+ const normalized = InPageConnector.normalizeNodeId(nodeId);
20848
+ if (!normalized) {
20849
+ throw new Error('InPageConnector target node id must be a non-empty string');
20850
+ }
20851
+ if (normalized === '*') {
20852
+ this.setWildcardTarget();
20853
+ return;
20854
+ }
20855
+ this.targetNodeId = normalized;
20856
+ logger$G.debug('inpage_target_updated', {
20857
+ channel: this.channelName,
20858
+ connector_id: this.connectorId,
20859
+ local_node_id: this.localNodeId,
20860
+ target_node_id: this.targetNodeId,
20861
+ target_mode: 'direct',
20862
+ });
20863
+ }
20864
+ setWildcardTarget() {
20865
+ this.targetNodeId = '*';
20866
+ logger$G.debug('inpage_target_updated', {
20867
+ channel: this.channelName,
20868
+ connector_id: this.connectorId,
20869
+ local_node_id: this.localNodeId,
20870
+ target_node_id: this.targetNodeId,
20871
+ target_mode: 'wildcard',
20872
+ });
20873
+ }
20852
20874
  }
20853
20875
 
20854
20876
  const RPC_REGISTRY = Symbol('naylence.rpc.registry');
@@ -29503,8 +29525,16 @@ class InPageConnectorFactory extends ConnectorFactory {
29503
29525
  }
29504
29526
  const normalized = this._normalizeConfig(config);
29505
29527
  const options = (factoryArgs[0] ?? {});
29528
+ const normalizedLocalNodeFromConfig = this._normalizeNodeId(normalized.localNodeId);
29529
+ const localNodeId = this._normalizeNodeId(options.localNodeId) ?? normalizedLocalNodeFromConfig;
29530
+ if (!localNodeId) {
29531
+ throw new Error('InPageConnectorFactory requires a localNodeId from config or create() options');
29532
+ }
29506
29533
  const channelName = normalized.channelName ?? DEFAULT_CHANNEL$3;
29507
29534
  const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
29535
+ const targetFromOptions = this._normalizeTargetNodeId(options.initialTargetNodeId);
29536
+ const targetFromConfig = this._normalizeTargetNodeId(normalized.initialTargetNodeId);
29537
+ const resolvedTarget = targetFromOptions ?? targetFromConfig ?? '*';
29508
29538
  const baseConfig = {
29509
29539
  drainTimeout: normalized.drainTimeout,
29510
29540
  flowControl: normalized.flowControl,
@@ -29519,6 +29549,8 @@ class InPageConnectorFactory extends ConnectorFactory {
29519
29549
  type: INPAGE_CONNECTOR_TYPE,
29520
29550
  channelName,
29521
29551
  inboxCapacity,
29552
+ localNodeId,
29553
+ initialTargetNodeId: resolvedTarget,
29522
29554
  };
29523
29555
  const connector = new InPageConnector(connectorConfig, baseConfig);
29524
29556
  if (options.authorization) {
@@ -29554,6 +29586,16 @@ class InPageConnectorFactory extends ConnectorFactory {
29554
29586
  capacity > 0) {
29555
29587
  normalized.inboxCapacity = Math.floor(capacity);
29556
29588
  }
29589
+ const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
29590
+ const normalizedLocalNodeId = this._normalizeNodeId(localNodeId);
29591
+ if (normalizedLocalNodeId) {
29592
+ normalized.localNodeId = normalizedLocalNodeId;
29593
+ }
29594
+ const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
29595
+ const normalizedTarget = this._normalizeTargetNodeId(initialTargetNodeId);
29596
+ if (normalizedTarget) {
29597
+ normalized.initialTargetNodeId = normalizedTarget;
29598
+ }
29557
29599
  if (typeof candidate.flowControl === 'boolean') {
29558
29600
  normalized.flowControl = candidate.flowControl;
29559
29601
  }
@@ -29592,6 +29634,22 @@ class InPageConnectorFactory extends ConnectorFactory {
29592
29634
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
29593
29635
  return normalized;
29594
29636
  }
29637
+ _normalizeNodeId(value) {
29638
+ if (typeof value !== 'string') {
29639
+ return null;
29640
+ }
29641
+ const trimmed = value.trim();
29642
+ return trimmed.length > 0 ? trimmed : null;
29643
+ }
29644
+ _normalizeTargetNodeId(value) {
29645
+ if (value === undefined || value === null) {
29646
+ return undefined;
29647
+ }
29648
+ if (value === '*') {
29649
+ return '*';
29650
+ }
29651
+ return this._normalizeNodeId(value) ?? undefined;
29652
+ }
29595
29653
  }
29596
29654
 
29597
29655
  var inpageConnectorFactory = /*#__PURE__*/Object.freeze({
@@ -37629,7 +37687,7 @@ class InPageListener extends TransportListener {
37629
37687
  node: routingNode,
37630
37688
  });
37631
37689
  const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
37632
- connectorConfig = this._grantToConnectorConfig(selection.grant);
37690
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, this._grantToConnectorConfig(selection.grant));
37633
37691
  }
37634
37692
  catch (error) {
37635
37693
  logger$7.debug('inpage_listener_grant_selection_failed', {
@@ -37637,13 +37695,13 @@ class InPageListener extends TransportListener {
37637
37695
  system_id: systemId,
37638
37696
  error: error instanceof Error ? error.message : String(error),
37639
37697
  });
37640
- connectorConfig =
37641
- this._extractInPageConnectorConfig(frame) ??
37642
- {
37643
- type: INPAGE_CONNECTOR_TYPE,
37644
- channelName: this._channelName,
37645
- inboxCapacity: this._inboxCapacity,
37646
- };
37698
+ const fallbackConfig = this._extractInPageConnectorConfig(frame) ??
37699
+ {
37700
+ type: INPAGE_CONNECTOR_TYPE,
37701
+ channelName: this._channelName,
37702
+ inboxCapacity: this._inboxCapacity,
37703
+ };
37704
+ connectorConfig = this._buildConnectorConfigForSystem(systemId, fallbackConfig);
37647
37705
  }
37648
37706
  try {
37649
37707
  const connector = await routingNode.createOriginConnector({
@@ -37762,6 +37820,65 @@ class InPageListener extends TransportListener {
37762
37820
  typeof frame === 'object' &&
37763
37821
  frame.type === 'NodeAttach');
37764
37822
  }
37823
+ _buildConnectorConfigForSystem(systemId, baseConfig) {
37824
+ const localNodeId = this._requireLocalNodeId();
37825
+ const targetSystemId = this._normalizeNodeId(systemId);
37826
+ if (!targetSystemId) {
37827
+ throw new Error('InPageListener requires a valid system id for connector creation');
37828
+ }
37829
+ const candidate = baseConfig ?? null;
37830
+ const channelCandidate = candidate && 'channelName' in candidate
37831
+ ? candidate.channelName
37832
+ : undefined;
37833
+ const inboxCandidate = candidate && 'inboxCapacity' in candidate
37834
+ ? candidate.inboxCapacity
37835
+ : undefined;
37836
+ const targetCandidate = candidate && 'initialTargetNodeId' in candidate
37837
+ ? candidate.initialTargetNodeId
37838
+ : undefined;
37839
+ const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
37840
+ ? channelCandidate.trim()
37841
+ : this._channelName;
37842
+ const inboxCapacity = typeof inboxCandidate === 'number' &&
37843
+ Number.isFinite(inboxCandidate) &&
37844
+ inboxCandidate > 0
37845
+ ? Math.floor(inboxCandidate)
37846
+ : this._inboxCapacity;
37847
+ const normalizedTarget = this._normalizeTargetNodeId(targetCandidate);
37848
+ return {
37849
+ type: INPAGE_CONNECTOR_TYPE,
37850
+ channelName,
37851
+ inboxCapacity,
37852
+ localNodeId,
37853
+ initialTargetNodeId: normalizedTarget ?? targetSystemId,
37854
+ };
37855
+ }
37856
+ _requireLocalNodeId() {
37857
+ if (!this._routingNode) {
37858
+ throw new Error('InPageListener requires routing node context');
37859
+ }
37860
+ const normalized = this._normalizeNodeId(this._routingNode.id);
37861
+ if (!normalized) {
37862
+ throw new Error('InPageListener requires routing node with a stable identifier');
37863
+ }
37864
+ return normalized;
37865
+ }
37866
+ _normalizeNodeId(value) {
37867
+ if (typeof value !== 'string') {
37868
+ return null;
37869
+ }
37870
+ const trimmed = value.trim();
37871
+ return trimmed.length > 0 ? trimmed : null;
37872
+ }
37873
+ _normalizeTargetNodeId(value) {
37874
+ if (value === undefined || value === null) {
37875
+ return undefined;
37876
+ }
37877
+ if (value === '*') {
37878
+ return '*';
37879
+ }
37880
+ return this._normalizeNodeId(value) ?? undefined;
37881
+ }
37765
37882
  }
37766
37883
  function getInPageListenerInstance() {
37767
37884
  return _lastInPageListenerInstance;