@naylence/runtime 0.3.5-test.966 → 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.
- package/dist/browser/index.cjs +318 -28
- package/dist/browser/index.mjs +318 -28
- package/dist/cjs/naylence/fame/connector/inpage-connector-factory.js +36 -0
- package/dist/cjs/naylence/fame/connector/inpage-connector.js +213 -18
- package/dist/cjs/naylence/fame/connector/inpage-listener.js +67 -8
- package/dist/cjs/version.js +2 -2
- package/dist/esm/naylence/fame/connector/inpage-connector-factory.js +36 -0
- package/dist/esm/naylence/fame/connector/inpage-connector.js +213 -18
- package/dist/esm/naylence/fame/connector/inpage-listener.js +67 -8
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +318 -28
- package/dist/node/index.mjs +318 -28
- package/dist/node/node.cjs +318 -28
- package/dist/node/node.mjs +318 -28
- package/dist/types/naylence/fame/connector/inpage-connector-factory.d.ts +6 -0
- package/dist/types/naylence/fame/connector/inpage-connector.d.ts +13 -0
- package/dist/types/naylence/fame/connector/inpage-listener.d.ts +4 -0
- package/dist/types/naylence/fame/grants/inpage-connection-grant.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
@@ -20433,6 +20433,26 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20433
20433
|
}
|
|
20434
20434
|
return null;
|
|
20435
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
|
+
}
|
|
20436
20456
|
constructor(config, baseConfig = {}) {
|
|
20437
20457
|
ensureBrowserEnvironment$2();
|
|
20438
20458
|
super(baseConfig);
|
|
@@ -20448,41 +20468,68 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20448
20468
|
? Math.floor(config.inboxCapacity)
|
|
20449
20469
|
: DEFAULT_INBOX_CAPACITY$6;
|
|
20450
20470
|
this.inbox = new BoundedAsyncQueue(preferredCapacity);
|
|
20471
|
+
this.inboxCapacity = preferredCapacity;
|
|
20451
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);
|
|
20452
20479
|
logger$G.debug('inpage_connector_initialized', {
|
|
20453
20480
|
channel: this.channelName,
|
|
20454
20481
|
connector_id: this.connectorId,
|
|
20482
|
+
local_node_id: this.localNodeId,
|
|
20483
|
+
target_node_id: this.targetNodeId ?? null,
|
|
20484
|
+
inbox_capacity: preferredCapacity,
|
|
20455
20485
|
});
|
|
20456
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
|
+
}
|
|
20457
20495
|
const messageEvent = event;
|
|
20458
20496
|
const message = messageEvent.data;
|
|
20459
20497
|
logger$G.debug('inpage_raw_event', {
|
|
20460
20498
|
channel: this.channelName,
|
|
20461
20499
|
connector_id: this.connectorId,
|
|
20462
|
-
message_type: message && typeof message === 'object'
|
|
20463
|
-
|
|
20464
|
-
payload_type: message && typeof message === 'object'
|
|
20465
|
-
? message?.payload instanceof Uint8Array
|
|
20466
|
-
? 'Uint8Array'
|
|
20467
|
-
: message?.payload instanceof ArrayBuffer
|
|
20468
|
-
? 'ArrayBuffer'
|
|
20469
|
-
: typeof message?.payload
|
|
20500
|
+
message_type: message && typeof message === 'object'
|
|
20501
|
+
? message.constructor?.name ?? typeof message
|
|
20470
20502
|
: typeof message,
|
|
20471
|
-
|
|
20472
|
-
|
|
20473
|
-
: undefined,
|
|
20474
|
-
payload_keys: message && typeof message === 'object' && message?.payload && typeof message?.payload === 'object'
|
|
20475
|
-
? Object.keys(message.payload).slice(0, 5)
|
|
20476
|
-
: undefined,
|
|
20503
|
+
has_sender_id: Boolean(message?.senderId),
|
|
20504
|
+
has_sender_node_id: Boolean(message?.senderNodeId),
|
|
20477
20505
|
});
|
|
20478
20506
|
if (!message || typeof message !== 'object') {
|
|
20479
20507
|
return;
|
|
20480
20508
|
}
|
|
20481
20509
|
const busMessage = message;
|
|
20482
|
-
|
|
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
|
+
});
|
|
20483
20520
|
return;
|
|
20484
20521
|
}
|
|
20485
|
-
if (
|
|
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)) {
|
|
20486
20533
|
return;
|
|
20487
20534
|
}
|
|
20488
20535
|
const payload = InPageConnector.coercePayload(busMessage.payload);
|
|
@@ -20496,7 +20543,9 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20496
20543
|
}
|
|
20497
20544
|
logger$G.debug('inpage_message_received', {
|
|
20498
20545
|
channel: this.channelName,
|
|
20499
|
-
sender_id:
|
|
20546
|
+
sender_id: senderId,
|
|
20547
|
+
sender_node_id: senderNodeId,
|
|
20548
|
+
target_node_id: incomingTargetNodeId ?? null,
|
|
20500
20549
|
connector_id: this.connectorId,
|
|
20501
20550
|
payload_length: payload.byteLength,
|
|
20502
20551
|
});
|
|
@@ -20504,15 +20553,27 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20504
20553
|
if (typeof this.inbox.tryEnqueue === 'function') {
|
|
20505
20554
|
const accepted = this.inbox.tryEnqueue(payload);
|
|
20506
20555
|
if (accepted) {
|
|
20556
|
+
this.logInboxSnapshot('inpage_inbox_enqueued', {
|
|
20557
|
+
source: 'listener',
|
|
20558
|
+
enqueue_strategy: 'try',
|
|
20559
|
+
payload_length: payload.byteLength,
|
|
20560
|
+
});
|
|
20507
20561
|
return;
|
|
20508
20562
|
}
|
|
20509
20563
|
}
|
|
20510
20564
|
this.inbox.enqueue(payload);
|
|
20565
|
+
this.logInboxSnapshot('inpage_inbox_enqueued', {
|
|
20566
|
+
source: 'listener',
|
|
20567
|
+
enqueue_strategy: 'enqueue',
|
|
20568
|
+
payload_length: payload.byteLength,
|
|
20569
|
+
});
|
|
20511
20570
|
}
|
|
20512
20571
|
catch (error) {
|
|
20513
20572
|
if (error instanceof QueueFullError) {
|
|
20514
20573
|
logger$G.warning('inpage_receive_queue_full', {
|
|
20515
20574
|
channel: this.channelName,
|
|
20575
|
+
inbox_capacity: this.inboxCapacity,
|
|
20576
|
+
inbox_remaining_capacity: this.inbox.remainingCapacity,
|
|
20516
20577
|
});
|
|
20517
20578
|
}
|
|
20518
20579
|
else {
|
|
@@ -20619,15 +20680,25 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20619
20680
|
if (typeof this.inbox.tryEnqueue === 'function') {
|
|
20620
20681
|
const accepted = this.inbox.tryEnqueue(item);
|
|
20621
20682
|
if (accepted) {
|
|
20683
|
+
this.logInboxSnapshot('inpage_push_enqueued', {
|
|
20684
|
+
enqueue_strategy: 'try',
|
|
20685
|
+
item_type: this._describeInboxItem(item),
|
|
20686
|
+
});
|
|
20622
20687
|
return;
|
|
20623
20688
|
}
|
|
20624
20689
|
}
|
|
20625
20690
|
this.inbox.enqueue(item);
|
|
20691
|
+
this.logInboxSnapshot('inpage_push_enqueued', {
|
|
20692
|
+
enqueue_strategy: 'enqueue',
|
|
20693
|
+
item_type: this._describeInboxItem(item),
|
|
20694
|
+
});
|
|
20626
20695
|
}
|
|
20627
20696
|
catch (error) {
|
|
20628
20697
|
if (error instanceof QueueFullError) {
|
|
20629
20698
|
logger$G.warning('inpage_push_queue_full', {
|
|
20630
20699
|
channel: this.channelName,
|
|
20700
|
+
inbox_capacity: this.inboxCapacity,
|
|
20701
|
+
inbox_remaining_capacity: this.inbox.remainingCapacity,
|
|
20631
20702
|
});
|
|
20632
20703
|
throw error;
|
|
20633
20704
|
}
|
|
@@ -20640,25 +20711,52 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20640
20711
|
}
|
|
20641
20712
|
async _transportSendBytes(data) {
|
|
20642
20713
|
ensureBrowserEnvironment$2();
|
|
20714
|
+
const targetNodeId = this.targetNodeId ?? '*';
|
|
20643
20715
|
logger$G.debug('inpage_message_sending', {
|
|
20644
20716
|
channel: this.channelName,
|
|
20645
20717
|
sender_id: this.connectorId,
|
|
20718
|
+
sender_node_id: this.localNodeId,
|
|
20719
|
+
target_node_id: targetNodeId,
|
|
20646
20720
|
});
|
|
20647
20721
|
const event = new MessageEvent(this.channelName, {
|
|
20648
20722
|
data: {
|
|
20649
20723
|
senderId: this.connectorId,
|
|
20724
|
+
senderNodeId: this.localNodeId,
|
|
20725
|
+
targetNodeId,
|
|
20650
20726
|
payload: data,
|
|
20651
20727
|
},
|
|
20652
20728
|
});
|
|
20653
20729
|
getSharedBus$1().dispatchEvent(event);
|
|
20654
20730
|
}
|
|
20655
20731
|
async _transportReceive() {
|
|
20656
|
-
|
|
20732
|
+
const item = await this.inbox.dequeue();
|
|
20733
|
+
this.logInboxSnapshot('inpage_inbox_dequeued', {
|
|
20734
|
+
item_type: this._describeInboxItem(item),
|
|
20735
|
+
});
|
|
20736
|
+
return item;
|
|
20657
20737
|
}
|
|
20658
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
|
+
});
|
|
20659
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
|
+
});
|
|
20660
20753
|
getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
|
|
20661
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
|
+
});
|
|
20662
20760
|
}
|
|
20663
20761
|
if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
|
|
20664
20762
|
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
@@ -20676,6 +20774,103 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20676
20774
|
}
|
|
20677
20775
|
return rawOrEnvelope;
|
|
20678
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
|
+
}
|
|
20679
20874
|
}
|
|
20680
20875
|
|
|
20681
20876
|
const RPC_REGISTRY = Symbol('naylence.rpc.registry');
|
|
@@ -29330,8 +29525,16 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
29330
29525
|
}
|
|
29331
29526
|
const normalized = this._normalizeConfig(config);
|
|
29332
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
|
+
}
|
|
29333
29533
|
const channelName = normalized.channelName ?? DEFAULT_CHANNEL$3;
|
|
29334
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 ?? '*';
|
|
29335
29538
|
const baseConfig = {
|
|
29336
29539
|
drainTimeout: normalized.drainTimeout,
|
|
29337
29540
|
flowControl: normalized.flowControl,
|
|
@@ -29346,6 +29549,8 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
29346
29549
|
type: INPAGE_CONNECTOR_TYPE,
|
|
29347
29550
|
channelName,
|
|
29348
29551
|
inboxCapacity,
|
|
29552
|
+
localNodeId,
|
|
29553
|
+
initialTargetNodeId: resolvedTarget,
|
|
29349
29554
|
};
|
|
29350
29555
|
const connector = new InPageConnector(connectorConfig, baseConfig);
|
|
29351
29556
|
if (options.authorization) {
|
|
@@ -29381,6 +29586,16 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
29381
29586
|
capacity > 0) {
|
|
29382
29587
|
normalized.inboxCapacity = Math.floor(capacity);
|
|
29383
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
|
+
}
|
|
29384
29599
|
if (typeof candidate.flowControl === 'boolean') {
|
|
29385
29600
|
normalized.flowControl = candidate.flowControl;
|
|
29386
29601
|
}
|
|
@@ -29419,6 +29634,22 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
29419
29634
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
|
|
29420
29635
|
return normalized;
|
|
29421
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
|
+
}
|
|
29422
29653
|
}
|
|
29423
29654
|
|
|
29424
29655
|
var inpageConnectorFactory = /*#__PURE__*/Object.freeze({
|
|
@@ -37456,7 +37687,7 @@ class InPageListener extends TransportListener {
|
|
|
37456
37687
|
node: routingNode,
|
|
37457
37688
|
});
|
|
37458
37689
|
const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
|
|
37459
|
-
connectorConfig = this._grantToConnectorConfig(selection.grant);
|
|
37690
|
+
connectorConfig = this._buildConnectorConfigForSystem(systemId, this._grantToConnectorConfig(selection.grant));
|
|
37460
37691
|
}
|
|
37461
37692
|
catch (error) {
|
|
37462
37693
|
logger$7.debug('inpage_listener_grant_selection_failed', {
|
|
@@ -37464,13 +37695,13 @@ class InPageListener extends TransportListener {
|
|
|
37464
37695
|
system_id: systemId,
|
|
37465
37696
|
error: error instanceof Error ? error.message : String(error),
|
|
37466
37697
|
});
|
|
37467
|
-
|
|
37468
|
-
|
|
37469
|
-
|
|
37470
|
-
|
|
37471
|
-
|
|
37472
|
-
|
|
37473
|
-
|
|
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);
|
|
37474
37705
|
}
|
|
37475
37706
|
try {
|
|
37476
37707
|
const connector = await routingNode.createOriginConnector({
|
|
@@ -37589,6 +37820,65 @@ class InPageListener extends TransportListener {
|
|
|
37589
37820
|
typeof frame === 'object' &&
|
|
37590
37821
|
frame.type === 'NodeAttach');
|
|
37591
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
|
+
}
|
|
37592
37882
|
}
|
|
37593
37883
|
function getInPageListenerInstance() {
|
|
37594
37884
|
return _lastInPageListenerInstance;
|