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