@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.
@@ -5477,12 +5477,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5477
5477
  }
5478
5478
 
5479
5479
  // This file is auto-generated during build - do not edit manually
5480
- // Generated from package.json version: 0.3.5-test.950
5480
+ // Generated from package.json version: 0.3.5-test.952
5481
5481
  /**
5482
5482
  * The package version, injected at build time.
5483
5483
  * @internal
5484
5484
  */
5485
- const VERSION = '0.3.5-test.950';
5485
+ const VERSION = '0.3.5-test.952';
5486
5486
 
5487
5487
  /**
5488
5488
  * Fame errors module - Fame protocol specific error classes
@@ -11516,14 +11516,12 @@ function serializeTransportFrame(frame) {
11516
11516
  return serializable;
11517
11517
  }
11518
11518
  /**
11519
- * Unwrap a transport frame, validating source and destination
11519
+ * Unwrap a transport frame (pure deserializer - no filtering)
11520
11520
  *
11521
11521
  * @param raw - Raw data from the bus
11522
- * @param localNodeId - This connector's node ID
11523
- * @param remoteNodeId - Expected remote node ID
11524
- * @returns Unwrapped payload if frame is valid and addressed to us, null otherwise
11522
+ * @returns Unwrapped frame with payload as Uint8Array, or null if invalid structure
11525
11523
  */
11526
- function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
11524
+ function unwrapTransportFrame(raw) {
11527
11525
  // Validate basic structure
11528
11526
  if (!raw || typeof raw !== 'object') {
11529
11527
  return null;
@@ -11537,16 +11535,17 @@ function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
11537
11535
  if (typeof frame.src !== 'string' || typeof frame.dst !== 'string') {
11538
11536
  return null;
11539
11537
  }
11540
- // Only accept frames addressed to us from the expected remote
11541
- if (frame.dst !== localNodeId || frame.src !== remoteNodeId) {
11542
- return null;
11543
- }
11544
11538
  // Extract payload
11545
11539
  if (!frame.payload || !Array.isArray(frame.payload)) {
11546
11540
  return null;
11547
11541
  }
11548
- // Convert array back to Uint8Array
11549
- return Uint8Array.from(frame.payload);
11542
+ // Convert array back to Uint8Array and return full frame
11543
+ return {
11544
+ v: frame.v,
11545
+ src: frame.src,
11546
+ dst: frame.dst,
11547
+ payload: Uint8Array.from(frame.payload),
11548
+ };
11550
11549
  }
11551
11550
  /**
11552
11551
  * Check if raw data looks like a transport frame
@@ -11677,43 +11676,64 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11677
11676
  return;
11678
11677
  }
11679
11678
  // Try to unwrap as transport frame
11680
- const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
11681
- if (unwrapped) {
11682
- // Successfully unwrapped transport frame
11683
- logger$10.debug('broadcast_channel_transport_frame_received', {
11684
- channel: this.channelName,
11685
- sender_id: busMessage.senderId,
11686
- connector_id: this.connectorId,
11687
- local_node_id: this.localNodeId,
11688
- remote_node_id: this.remoteNodeId,
11689
- payload_length: unwrapped.byteLength,
11690
- });
11691
- if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
11692
- return;
11693
- }
11694
- try {
11695
- if (typeof this.inbox.tryEnqueue === 'function') {
11696
- const accepted = this.inbox.tryEnqueue(unwrapped);
11697
- if (accepted) {
11698
- return;
11699
- }
11679
+ const frame = unwrapTransportFrame(busMessage.payload);
11680
+ if (frame) {
11681
+ // Apply connector's filtering policy: strict dst check, src accepts wildcard
11682
+ const srcMatches = this.remoteNodeId === '*' || frame.src === this.remoteNodeId;
11683
+ const dstMatches = frame.dst === this.localNodeId;
11684
+ if (dstMatches && srcMatches) {
11685
+ // Successfully received and filtered transport frame
11686
+ logger$10.debug('broadcast_channel_transport_frame_received', {
11687
+ channel: this.channelName,
11688
+ sender_id: busMessage.senderId,
11689
+ connector_id: this.connectorId,
11690
+ local_node_id: this.localNodeId,
11691
+ remote_node_id: this.remoteNodeId,
11692
+ frame_src: frame.src,
11693
+ frame_dst: frame.dst,
11694
+ payload_length: frame.payload.byteLength,
11695
+ });
11696
+ const unwrapped = frame.payload;
11697
+ if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
11698
+ return;
11700
11699
  }
11701
- this.inbox.enqueue(unwrapped);
11702
- }
11703
- catch (error) {
11704
- if (error instanceof QueueFullError) {
11705
- logger$10.warning('broadcast_channel_receive_queue_full', {
11706
- channel: this.channelName,
11707
- });
11700
+ try {
11701
+ if (typeof this.inbox.tryEnqueue === 'function') {
11702
+ const accepted = this.inbox.tryEnqueue(unwrapped);
11703
+ if (accepted) {
11704
+ return;
11705
+ }
11706
+ }
11707
+ this.inbox.enqueue(unwrapped);
11708
11708
  }
11709
- else {
11710
- logger$10.error('broadcast_channel_receive_error', {
11711
- channel: this.channelName,
11712
- error: error instanceof Error ? error.message : String(error),
11713
- });
11709
+ catch (error) {
11710
+ if (error instanceof QueueFullError) {
11711
+ logger$10.warning('broadcast_channel_receive_queue_full', {
11712
+ channel: this.channelName,
11713
+ });
11714
+ }
11715
+ else {
11716
+ logger$10.error('broadcast_channel_receive_error', {
11717
+ channel: this.channelName,
11718
+ error: error instanceof Error ? error.message : String(error),
11719
+ });
11720
+ }
11714
11721
  }
11722
+ return;
11723
+ }
11724
+ else {
11725
+ // Frame filtered out by addressing rules
11726
+ logger$10.debug('broadcast_channel_transport_frame_filtered', {
11727
+ channel: this.channelName,
11728
+ connector_id: this.connectorId,
11729
+ local_node_id: this.localNodeId,
11730
+ remote_node_id: this.remoteNodeId,
11731
+ frame_src: frame.src,
11732
+ frame_dst: frame.dst,
11733
+ reason: !dstMatches ? 'wrong_destination' : 'wrong_source',
11734
+ });
11735
+ return;
11715
11736
  }
11716
- return;
11717
11737
  }
11718
11738
  // Fall back to legacy format (no transport frame)
11719
11739
  const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
@@ -21681,40 +21701,61 @@ class InPageConnector extends BaseAsyncConnector {
21681
21701
  return;
21682
21702
  }
21683
21703
  // Try to unwrap as transport frame
21684
- const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
21685
- if (unwrapped) {
21686
- // Successfully unwrapped transport frame
21687
- logger$J.debug('inpage_transport_frame_received', {
21688
- channel: this.channelName,
21689
- sender_id: busMessage.senderId,
21690
- connector_id: this.connectorId,
21691
- local_node_id: this.localNodeId,
21692
- remote_node_id: this.remoteNodeId,
21693
- payload_length: unwrapped.byteLength,
21694
- });
21695
- try {
21696
- if (typeof this.inbox.tryEnqueue === 'function') {
21697
- const accepted = this.inbox.tryEnqueue(unwrapped);
21698
- if (accepted) {
21699
- return;
21704
+ const frame = unwrapTransportFrame(busMessage.payload);
21705
+ if (frame) {
21706
+ // Apply connector's filtering policy: strict dst check, src accepts wildcard
21707
+ const srcMatches = this.remoteNodeId === '*' || frame.src === this.remoteNodeId;
21708
+ const dstMatches = frame.dst === this.localNodeId;
21709
+ if (dstMatches && srcMatches) {
21710
+ // Successfully received and filtered transport frame
21711
+ logger$J.debug('inpage_transport_frame_received', {
21712
+ channel: this.channelName,
21713
+ sender_id: busMessage.senderId,
21714
+ connector_id: this.connectorId,
21715
+ local_node_id: this.localNodeId,
21716
+ remote_node_id: this.remoteNodeId,
21717
+ frame_src: frame.src,
21718
+ frame_dst: frame.dst,
21719
+ payload_length: frame.payload.byteLength,
21720
+ });
21721
+ const unwrapped = frame.payload;
21722
+ try {
21723
+ if (typeof this.inbox.tryEnqueue === 'function') {
21724
+ const accepted = this.inbox.tryEnqueue(unwrapped);
21725
+ if (accepted) {
21726
+ return;
21727
+ }
21700
21728
  }
21729
+ this.inbox.enqueue(unwrapped);
21701
21730
  }
21702
- this.inbox.enqueue(unwrapped);
21703
- }
21704
- catch (error) {
21705
- if (error instanceof QueueFullError) {
21706
- logger$J.warning('inpage_receive_queue_full', {
21707
- channel: this.channelName,
21708
- });
21709
- }
21710
- else {
21711
- logger$J.error('inpage_receive_error', {
21712
- channel: this.channelName,
21713
- error: error instanceof Error ? error.message : String(error),
21714
- });
21731
+ catch (error) {
21732
+ if (error instanceof QueueFullError) {
21733
+ logger$J.warning('inpage_receive_queue_full', {
21734
+ channel: this.channelName,
21735
+ });
21736
+ }
21737
+ else {
21738
+ logger$J.error('inpage_receive_error', {
21739
+ channel: this.channelName,
21740
+ error: error instanceof Error ? error.message : String(error),
21741
+ });
21742
+ }
21715
21743
  }
21744
+ return;
21745
+ }
21746
+ else {
21747
+ // Frame filtered out by addressing rules
21748
+ logger$J.debug('inpage_transport_frame_filtered', {
21749
+ channel: this.channelName,
21750
+ connector_id: this.connectorId,
21751
+ local_node_id: this.localNodeId,
21752
+ remote_node_id: this.remoteNodeId,
21753
+ frame_src: frame.src,
21754
+ frame_dst: frame.dst,
21755
+ reason: !dstMatches ? 'wrong_destination' : 'wrong_source',
21756
+ });
21757
+ return;
21716
21758
  }
21717
- return;
21718
21759
  }
21719
21760
  // Fall back to legacy format (no transport frame)
21720
21761
  const payload = InPageConnector.coercePayload(busMessage.payload);
@@ -32896,41 +32937,44 @@ class BroadcastChannelListener extends TransportListener {
32896
32937
  if (typeof senderId !== 'string' || senderId.length === 0) {
32897
32938
  return null;
32898
32939
  }
32899
- const payload = coercePayload(record.payload);
32900
- if (!payload) {
32901
- logger$n.debug('broadcast_channel_listener_ignored_event_without_payload', {
32902
- sender_id: senderId,
32903
- });
32904
- return null;
32905
- }
32906
- // Try to unwrap as transport frame first
32907
- // Use wildcard for remoteNodeId since we don't know the sender's node ID yet
32908
- let unwrapped = null;
32909
- if (this._routingNode) {
32910
- try {
32911
- // First try to deserialize as transport frame
32912
- const parsed = JSON.parse(new TextDecoder().decode(payload));
32913
- if (parsed && typeof parsed === 'object' && 'v' in parsed && 'src' in parsed && 'dst' in parsed) {
32914
- const frame = parsed;
32915
- // Check if this frame is addressed to us (localNodeId)
32916
- if (frame.dst === this._routingNode.id) {
32917
- unwrapped = unwrapTransportFrame(payload, this._routingNode.id, '*');
32918
- if (unwrapped) {
32919
- logger$n.debug('broadcast_channel_listener_unwrapped_transport_frame', {
32920
- sender_id: senderId,
32921
- src: frame.src,
32922
- dst: frame.dst,
32923
- });
32924
- }
32925
- }
32940
+ // Check if payload is a transport frame object first
32941
+ let envelopePayload = null;
32942
+ if (this._routingNode && record.payload && typeof record.payload === 'object') {
32943
+ // Try to unwrap as transport frame
32944
+ const frame = unwrapTransportFrame(record.payload);
32945
+ if (frame) {
32946
+ // Apply listener's filtering policy: accept frames addressed to us OR with wildcard destination
32947
+ // Wildcard is needed because downstream nodes don't know the sentinel's ID during initial attach
32948
+ const isAddressedToUs = frame.dst === this._routingNode.id || frame.dst === '*';
32949
+ if (isAddressedToUs) {
32950
+ envelopePayload = frame.payload;
32951
+ logger$n.debug('broadcast_channel_listener_unwrapped_transport_frame', {
32952
+ sender_id: senderId,
32953
+ src: frame.src,
32954
+ dst: frame.dst,
32955
+ });
32956
+ }
32957
+ else {
32958
+ // Frame addressed to a different node, ignore it
32959
+ logger$n.debug('broadcast_channel_listener_ignored_frame_wrong_destination', {
32960
+ sender_id: senderId,
32961
+ dst: frame.dst,
32962
+ expected: this._routingNode.id,
32963
+ });
32964
+ return null;
32926
32965
  }
32927
32966
  }
32928
- catch {
32929
- // Not a transport frame, continue with legacy format
32967
+ }
32968
+ // If not a transport frame, try to coerce as legacy format
32969
+ if (!envelopePayload) {
32970
+ envelopePayload = coercePayload(record.payload);
32971
+ if (!envelopePayload) {
32972
+ logger$n.debug('broadcast_channel_listener_ignored_event_without_payload', {
32973
+ sender_id: senderId,
32974
+ });
32975
+ return null;
32930
32976
  }
32931
32977
  }
32932
- // Use unwrapped payload if available, otherwise use raw payload
32933
- const envelopePayload = unwrapped ?? payload;
32934
32978
  let envelope;
32935
32979
  try {
32936
32980
  const decoded = new TextDecoder().decode(envelopePayload);
@@ -32940,7 +32984,7 @@ class BroadcastChannelListener extends TransportListener {
32940
32984
  catch (error) {
32941
32985
  const decoded = (() => {
32942
32986
  try {
32943
- return new TextDecoder().decode(payload);
32987
+ return new TextDecoder().decode(envelopePayload);
32944
32988
  }
32945
32989
  catch {
32946
32990
  return null;
@@ -41,14 +41,12 @@ export declare function wrapTransportFrame(payload: Uint8Array, srcNodeId: strin
41
41
  */
42
42
  export declare function serializeTransportFrame(frame: TransportFrame): unknown;
43
43
  /**
44
- * Unwrap a transport frame, validating source and destination
44
+ * Unwrap a transport frame (pure deserializer - no filtering)
45
45
  *
46
46
  * @param raw - Raw data from the bus
47
- * @param localNodeId - This connector's node ID
48
- * @param remoteNodeId - Expected remote node ID
49
- * @returns Unwrapped payload if frame is valid and addressed to us, null otherwise
47
+ * @returns Unwrapped frame with payload as Uint8Array, or null if invalid structure
50
48
  */
51
- export declare function unwrapTransportFrame(raw: unknown, localNodeId: string, remoteNodeId: string): Uint8Array | null;
49
+ export declare function unwrapTransportFrame(raw: unknown): TransportFrame | null;
52
50
  /**
53
51
  * Check if raw data looks like a transport frame
54
52
  *
@@ -2,4 +2,4 @@
2
2
  * The package version, injected at build time.
3
3
  * @internal
4
4
  */
5
- export declare const VERSION = "0.3.5-test.950";
5
+ export declare const VERSION = "0.3.5-test.952";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.3.5-test.950",
3
+ "version": "0.3.5-test.952",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",