@naylence/runtime 0.3.5-test.950 → 0.3.5-test.952

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.3.5-test.950
16
+ // Generated from package.json version: 0.3.5-test.952
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.3.5-test.950';
21
+ const VERSION = '0.3.5-test.952';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9779,14 +9779,12 @@ function serializeTransportFrame(frame) {
9779
9779
  return serializable;
9780
9780
  }
9781
9781
  /**
9782
- * Unwrap a transport frame, validating source and destination
9782
+ * Unwrap a transport frame (pure deserializer - no filtering)
9783
9783
  *
9784
9784
  * @param raw - Raw data from the bus
9785
- * @param localNodeId - This connector's node ID
9786
- * @param remoteNodeId - Expected remote node ID
9787
- * @returns Unwrapped payload if frame is valid and addressed to us, null otherwise
9785
+ * @returns Unwrapped frame with payload as Uint8Array, or null if invalid structure
9788
9786
  */
9789
- function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
9787
+ function unwrapTransportFrame(raw) {
9790
9788
  // Validate basic structure
9791
9789
  if (!raw || typeof raw !== 'object') {
9792
9790
  return null;
@@ -9800,16 +9798,17 @@ function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
9800
9798
  if (typeof frame.src !== 'string' || typeof frame.dst !== 'string') {
9801
9799
  return null;
9802
9800
  }
9803
- // Only accept frames addressed to us from the expected remote
9804
- if (frame.dst !== localNodeId || frame.src !== remoteNodeId) {
9805
- return null;
9806
- }
9807
9801
  // Extract payload
9808
9802
  if (!frame.payload || !Array.isArray(frame.payload)) {
9809
9803
  return null;
9810
9804
  }
9811
- // Convert array back to Uint8Array
9812
- return Uint8Array.from(frame.payload);
9805
+ // Convert array back to Uint8Array and return full frame
9806
+ return {
9807
+ v: frame.v,
9808
+ src: frame.src,
9809
+ dst: frame.dst,
9810
+ payload: Uint8Array.from(frame.payload),
9811
+ };
9813
9812
  }
9814
9813
 
9815
9814
  const logger$_ = getLogger('naylence.fame.connector.broadcast_channel_connector');
@@ -9924,43 +9923,64 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9924
9923
  return;
9925
9924
  }
9926
9925
  // Try to unwrap as transport frame
9927
- const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
9928
- if (unwrapped) {
9929
- // Successfully unwrapped transport frame
9930
- logger$_.debug('broadcast_channel_transport_frame_received', {
9931
- channel: this.channelName,
9932
- sender_id: busMessage.senderId,
9933
- connector_id: this.connectorId,
9934
- local_node_id: this.localNodeId,
9935
- remote_node_id: this.remoteNodeId,
9936
- payload_length: unwrapped.byteLength,
9937
- });
9938
- if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
9939
- return;
9940
- }
9941
- try {
9942
- if (typeof this.inbox.tryEnqueue === 'function') {
9943
- const accepted = this.inbox.tryEnqueue(unwrapped);
9944
- if (accepted) {
9945
- return;
9946
- }
9926
+ const frame = unwrapTransportFrame(busMessage.payload);
9927
+ if (frame) {
9928
+ // Apply connector's filtering policy: strict dst check, src accepts wildcard
9929
+ const srcMatches = this.remoteNodeId === '*' || frame.src === this.remoteNodeId;
9930
+ const dstMatches = frame.dst === this.localNodeId;
9931
+ if (dstMatches && srcMatches) {
9932
+ // Successfully received and filtered transport frame
9933
+ logger$_.debug('broadcast_channel_transport_frame_received', {
9934
+ channel: this.channelName,
9935
+ sender_id: busMessage.senderId,
9936
+ connector_id: this.connectorId,
9937
+ local_node_id: this.localNodeId,
9938
+ remote_node_id: this.remoteNodeId,
9939
+ frame_src: frame.src,
9940
+ frame_dst: frame.dst,
9941
+ payload_length: frame.payload.byteLength,
9942
+ });
9943
+ const unwrapped = frame.payload;
9944
+ if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
9945
+ return;
9947
9946
  }
9948
- this.inbox.enqueue(unwrapped);
9949
- }
9950
- catch (error) {
9951
- if (error instanceof QueueFullError) {
9952
- logger$_.warning('broadcast_channel_receive_queue_full', {
9953
- channel: this.channelName,
9954
- });
9947
+ try {
9948
+ if (typeof this.inbox.tryEnqueue === 'function') {
9949
+ const accepted = this.inbox.tryEnqueue(unwrapped);
9950
+ if (accepted) {
9951
+ return;
9952
+ }
9953
+ }
9954
+ this.inbox.enqueue(unwrapped);
9955
9955
  }
9956
- else {
9957
- logger$_.error('broadcast_channel_receive_error', {
9958
- channel: this.channelName,
9959
- error: error instanceof Error ? error.message : String(error),
9960
- });
9956
+ catch (error) {
9957
+ if (error instanceof QueueFullError) {
9958
+ logger$_.warning('broadcast_channel_receive_queue_full', {
9959
+ channel: this.channelName,
9960
+ });
9961
+ }
9962
+ else {
9963
+ logger$_.error('broadcast_channel_receive_error', {
9964
+ channel: this.channelName,
9965
+ error: error instanceof Error ? error.message : String(error),
9966
+ });
9967
+ }
9961
9968
  }
9969
+ return;
9970
+ }
9971
+ else {
9972
+ // Frame filtered out by addressing rules
9973
+ logger$_.debug('broadcast_channel_transport_frame_filtered', {
9974
+ channel: this.channelName,
9975
+ connector_id: this.connectorId,
9976
+ local_node_id: this.localNodeId,
9977
+ remote_node_id: this.remoteNodeId,
9978
+ frame_src: frame.src,
9979
+ frame_dst: frame.dst,
9980
+ reason: !dstMatches ? 'wrong_destination' : 'wrong_source',
9981
+ });
9982
+ return;
9962
9983
  }
9963
- return;
9964
9984
  }
9965
9985
  // Fall back to legacy format (no transport frame)
9966
9986
  const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
@@ -20487,40 +20507,61 @@ class InPageConnector extends BaseAsyncConnector {
20487
20507
  return;
20488
20508
  }
20489
20509
  // Try to unwrap as transport frame
20490
- const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
20491
- if (unwrapped) {
20492
- // Successfully unwrapped transport frame
20493
- logger$G.debug('inpage_transport_frame_received', {
20494
- channel: this.channelName,
20495
- sender_id: busMessage.senderId,
20496
- connector_id: this.connectorId,
20497
- local_node_id: this.localNodeId,
20498
- remote_node_id: this.remoteNodeId,
20499
- payload_length: unwrapped.byteLength,
20500
- });
20501
- try {
20502
- if (typeof this.inbox.tryEnqueue === 'function') {
20503
- const accepted = this.inbox.tryEnqueue(unwrapped);
20504
- if (accepted) {
20505
- return;
20510
+ const frame = unwrapTransportFrame(busMessage.payload);
20511
+ if (frame) {
20512
+ // Apply connector's filtering policy: strict dst check, src accepts wildcard
20513
+ const srcMatches = this.remoteNodeId === '*' || frame.src === this.remoteNodeId;
20514
+ const dstMatches = frame.dst === this.localNodeId;
20515
+ if (dstMatches && srcMatches) {
20516
+ // Successfully received and filtered transport frame
20517
+ logger$G.debug('inpage_transport_frame_received', {
20518
+ channel: this.channelName,
20519
+ sender_id: busMessage.senderId,
20520
+ connector_id: this.connectorId,
20521
+ local_node_id: this.localNodeId,
20522
+ remote_node_id: this.remoteNodeId,
20523
+ frame_src: frame.src,
20524
+ frame_dst: frame.dst,
20525
+ payload_length: frame.payload.byteLength,
20526
+ });
20527
+ const unwrapped = frame.payload;
20528
+ try {
20529
+ if (typeof this.inbox.tryEnqueue === 'function') {
20530
+ const accepted = this.inbox.tryEnqueue(unwrapped);
20531
+ if (accepted) {
20532
+ return;
20533
+ }
20506
20534
  }
20535
+ this.inbox.enqueue(unwrapped);
20507
20536
  }
20508
- this.inbox.enqueue(unwrapped);
20509
- }
20510
- catch (error) {
20511
- if (error instanceof QueueFullError) {
20512
- logger$G.warning('inpage_receive_queue_full', {
20513
- channel: this.channelName,
20514
- });
20515
- }
20516
- else {
20517
- logger$G.error('inpage_receive_error', {
20518
- channel: this.channelName,
20519
- error: error instanceof Error ? error.message : String(error),
20520
- });
20537
+ catch (error) {
20538
+ if (error instanceof QueueFullError) {
20539
+ logger$G.warning('inpage_receive_queue_full', {
20540
+ channel: this.channelName,
20541
+ });
20542
+ }
20543
+ else {
20544
+ logger$G.error('inpage_receive_error', {
20545
+ channel: this.channelName,
20546
+ error: error instanceof Error ? error.message : String(error),
20547
+ });
20548
+ }
20521
20549
  }
20550
+ return;
20551
+ }
20552
+ else {
20553
+ // Frame filtered out by addressing rules
20554
+ logger$G.debug('inpage_transport_frame_filtered', {
20555
+ channel: this.channelName,
20556
+ connector_id: this.connectorId,
20557
+ local_node_id: this.localNodeId,
20558
+ remote_node_id: this.remoteNodeId,
20559
+ frame_src: frame.src,
20560
+ frame_dst: frame.dst,
20561
+ reason: !dstMatches ? 'wrong_destination' : 'wrong_source',
20562
+ });
20563
+ return;
20522
20564
  }
20523
- return;
20524
20565
  }
20525
20566
  // Fall back to legacy format (no transport frame)
20526
20567
  const payload = InPageConnector.coercePayload(busMessage.payload);
@@ -36320,41 +36361,44 @@ class BroadcastChannelListener extends TransportListener {
36320
36361
  if (typeof senderId !== 'string' || senderId.length === 0) {
36321
36362
  return null;
36322
36363
  }
36323
- const payload = coercePayload$1(record.payload);
36324
- if (!payload) {
36325
- logger$a.debug('broadcast_channel_listener_ignored_event_without_payload', {
36326
- sender_id: senderId,
36327
- });
36328
- return null;
36329
- }
36330
- // Try to unwrap as transport frame first
36331
- // Use wildcard for remoteNodeId since we don't know the sender's node ID yet
36332
- let unwrapped = null;
36333
- if (this._routingNode) {
36334
- try {
36335
- // First try to deserialize as transport frame
36336
- const parsed = JSON.parse(new TextDecoder().decode(payload));
36337
- if (parsed && typeof parsed === 'object' && 'v' in parsed && 'src' in parsed && 'dst' in parsed) {
36338
- const frame = parsed;
36339
- // Check if this frame is addressed to us (localNodeId)
36340
- if (frame.dst === this._routingNode.id) {
36341
- unwrapped = unwrapTransportFrame(payload, this._routingNode.id, '*');
36342
- if (unwrapped) {
36343
- logger$a.debug('broadcast_channel_listener_unwrapped_transport_frame', {
36344
- sender_id: senderId,
36345
- src: frame.src,
36346
- dst: frame.dst,
36347
- });
36348
- }
36349
- }
36364
+ // Check if payload is a transport frame object first
36365
+ let envelopePayload = null;
36366
+ if (this._routingNode && record.payload && typeof record.payload === 'object') {
36367
+ // Try to unwrap as transport frame
36368
+ const frame = unwrapTransportFrame(record.payload);
36369
+ if (frame) {
36370
+ // Apply listener's filtering policy: accept frames addressed to us OR with wildcard destination
36371
+ // Wildcard is needed because downstream nodes don't know the sentinel's ID during initial attach
36372
+ const isAddressedToUs = frame.dst === this._routingNode.id || frame.dst === '*';
36373
+ if (isAddressedToUs) {
36374
+ envelopePayload = frame.payload;
36375
+ logger$a.debug('broadcast_channel_listener_unwrapped_transport_frame', {
36376
+ sender_id: senderId,
36377
+ src: frame.src,
36378
+ dst: frame.dst,
36379
+ });
36380
+ }
36381
+ else {
36382
+ // Frame addressed to a different node, ignore it
36383
+ logger$a.debug('broadcast_channel_listener_ignored_frame_wrong_destination', {
36384
+ sender_id: senderId,
36385
+ dst: frame.dst,
36386
+ expected: this._routingNode.id,
36387
+ });
36388
+ return null;
36350
36389
  }
36351
36390
  }
36352
- catch {
36353
- // Not a transport frame, continue with legacy format
36391
+ }
36392
+ // If not a transport frame, try to coerce as legacy format
36393
+ if (!envelopePayload) {
36394
+ envelopePayload = coercePayload$1(record.payload);
36395
+ if (!envelopePayload) {
36396
+ logger$a.debug('broadcast_channel_listener_ignored_event_without_payload', {
36397
+ sender_id: senderId,
36398
+ });
36399
+ return null;
36354
36400
  }
36355
36401
  }
36356
- // Use unwrapped payload if available, otherwise use raw payload
36357
- const envelopePayload = unwrapped ?? payload;
36358
36402
  let envelope;
36359
36403
  try {
36360
36404
  const decoded = new TextDecoder().decode(envelopePayload);
@@ -36364,7 +36408,7 @@ class BroadcastChannelListener extends TransportListener {
36364
36408
  catch (error) {
36365
36409
  const decoded = (() => {
36366
36410
  try {
36367
- return new TextDecoder().decode(payload);
36411
+ return new TextDecoder().decode(envelopePayload);
36368
36412
  }
36369
36413
  catch {
36370
36414
  return null;