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