@naylence/runtime 0.3.5-test.960 → 0.3.5-test.962

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.
@@ -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.960
17
+ // Generated from package.json version: 0.3.5-test.962
18
18
  /**
19
19
  * The package version, injected at build time.
20
20
  * @internal
21
21
  */
22
- const VERSION = '0.3.5-test.960';
22
+ const VERSION = '0.3.5-test.962';
23
23
 
24
24
  /**
25
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9862,6 +9862,26 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9862
9862
  }
9863
9863
  return null;
9864
9864
  }
9865
+ static normalizeNodeId(value) {
9866
+ if (typeof value !== 'string') {
9867
+ return null;
9868
+ }
9869
+ const trimmed = value.trim();
9870
+ return trimmed.length > 0 ? trimmed : null;
9871
+ }
9872
+ static normalizeTargetNodeId(value) {
9873
+ if (typeof value !== 'string') {
9874
+ return undefined;
9875
+ }
9876
+ const trimmed = value.trim();
9877
+ if (trimmed.length === 0) {
9878
+ return undefined;
9879
+ }
9880
+ if (trimmed === '*') {
9881
+ return '*';
9882
+ }
9883
+ return trimmed;
9884
+ }
9865
9885
  constructor(config, baseConfig = {}) {
9866
9886
  ensureBroadcastEnvironment();
9867
9887
  super(baseConfig);
@@ -9884,10 +9904,18 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9884
9904
  this.inbox = new BoundedAsyncQueue(preferredCapacity);
9885
9905
  this.inboxCapacity = preferredCapacity;
9886
9906
  this.connectorId = BroadcastChannelConnector.generateConnectorId();
9907
+ const normalizedLocalNodeId = BroadcastChannelConnector.normalizeNodeId(config.localNodeId);
9908
+ if (!normalizedLocalNodeId) {
9909
+ throw new Error('BroadcastChannelConnector requires a non-empty localNodeId');
9910
+ }
9911
+ this.localNodeId = normalizedLocalNodeId;
9912
+ this.targetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(config.initialTargetNodeId);
9887
9913
  this.channel = new BroadcastChannel(this.channelName);
9888
9914
  logger$_.debug('broadcast_channel_connector_created', {
9889
9915
  channel: this.channelName,
9890
9916
  connector_id: this.connectorId,
9917
+ local_node_id: this.localNodeId,
9918
+ target_node_id: this.targetNodeId ?? null,
9891
9919
  inbox_capacity: preferredCapacity,
9892
9920
  timestamp: new Date().toISOString(),
9893
9921
  });
@@ -9909,15 +9937,32 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9909
9937
  ? message.constructor?.name ?? typeof message
9910
9938
  : typeof message,
9911
9939
  has_sender_id: Boolean(message?.senderId),
9940
+ has_sender_node_id: Boolean(message?.senderNodeId),
9912
9941
  });
9913
9942
  if (!message || typeof message !== 'object') {
9914
9943
  return;
9915
9944
  }
9916
9945
  const busMessage = message;
9917
- if (typeof busMessage.senderId !== 'string' || busMessage.senderId.length === 0) {
9946
+ const senderNodeId = BroadcastChannelConnector.normalizeNodeId(busMessage.senderNodeId);
9947
+ if (!senderNodeId) {
9948
+ logger$_.debug('broadcast_channel_message_rejected', {
9949
+ channel: this.channelName,
9950
+ connector_id: this.connectorId,
9951
+ reason: 'missing_sender_node_id',
9952
+ });
9918
9953
  return;
9919
9954
  }
9920
- if (busMessage.senderId === this.connectorId) {
9955
+ if (senderNodeId === this.localNodeId) {
9956
+ logger$_.debug('broadcast_channel_message_rejected', {
9957
+ channel: this.channelName,
9958
+ connector_id: this.connectorId,
9959
+ reason: 'self_echo',
9960
+ sender_node_id: senderNodeId,
9961
+ });
9962
+ return;
9963
+ }
9964
+ const incomingTargetNodeId = BroadcastChannelConnector.normalizeTargetNodeId(busMessage.targetNodeId);
9965
+ if (!this._shouldAcceptMessageFromBus(senderNodeId, incomingTargetNodeId)) {
9921
9966
  return;
9922
9967
  }
9923
9968
  const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
@@ -9931,11 +9976,13 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9931
9976
  }
9932
9977
  logger$_.debug('broadcast_channel_message_received', {
9933
9978
  channel: this.channelName,
9934
- sender_id: busMessage.senderId,
9979
+ sender_id: message?.senderId,
9980
+ sender_node_id: senderNodeId,
9981
+ target_node_id: incomingTargetNodeId ?? null,
9935
9982
  connector_id: this.connectorId,
9936
9983
  payload_length: payload.byteLength,
9937
9984
  });
9938
- if (this._shouldSkipDuplicateAck(busMessage.senderId, payload)) {
9985
+ if (this._shouldSkipDuplicateAck(senderNodeId, payload)) {
9939
9986
  return;
9940
9987
  }
9941
9988
  try {
@@ -10079,12 +10126,17 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10079
10126
  }
10080
10127
  async _transportSendBytes(data) {
10081
10128
  ensureBroadcastEnvironment();
10129
+ const targetNodeId = this.targetNodeId ?? '*';
10082
10130
  logger$_.debug('broadcast_channel_message_sending', {
10083
10131
  channel: this.channelName,
10084
10132
  sender_id: this.connectorId,
10133
+ sender_node_id: this.localNodeId,
10134
+ target_node_id: targetNodeId,
10085
10135
  });
10086
10136
  this.channel.postMessage({
10087
10137
  senderId: this.connectorId,
10138
+ senderNodeId: this.localNodeId,
10139
+ targetNodeId,
10088
10140
  payload: data,
10089
10141
  });
10090
10142
  }
@@ -10147,6 +10199,51 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10147
10199
  }
10148
10200
  return rawOrEnvelope;
10149
10201
  }
10202
+ _isWildcardTarget() {
10203
+ return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
10204
+ }
10205
+ _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
10206
+ if (this._isWildcardTarget()) {
10207
+ if (targetNodeId && targetNodeId !== '*') {
10208
+ logger$_.debug('broadcast_channel_message_rejected', {
10209
+ channel: this.channelName,
10210
+ connector_id: this.connectorId,
10211
+ reason: 'wildcard_target_mismatch',
10212
+ sender_node_id: senderNodeId,
10213
+ target_node_id: targetNodeId,
10214
+ local_node_id: this.localNodeId,
10215
+ });
10216
+ return false;
10217
+ }
10218
+ return true;
10219
+ }
10220
+ const expectedSender = this.targetNodeId;
10221
+ if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
10222
+ logger$_.debug('broadcast_channel_message_rejected', {
10223
+ channel: this.channelName,
10224
+ connector_id: this.connectorId,
10225
+ reason: 'unexpected_sender',
10226
+ expected_sender_node_id: expectedSender,
10227
+ sender_node_id: senderNodeId,
10228
+ local_node_id: this.localNodeId,
10229
+ });
10230
+ return false;
10231
+ }
10232
+ if (targetNodeId &&
10233
+ targetNodeId !== '*' &&
10234
+ targetNodeId !== this.localNodeId) {
10235
+ logger$_.debug('broadcast_channel_message_rejected', {
10236
+ channel: this.channelName,
10237
+ connector_id: this.connectorId,
10238
+ reason: 'unexpected_target',
10239
+ sender_node_id: senderNodeId,
10240
+ target_node_id: targetNodeId,
10241
+ local_node_id: this.localNodeId,
10242
+ });
10243
+ return false;
10244
+ }
10245
+ return true;
10246
+ }
10150
10247
  _describeInboxItem(item) {
10151
10248
  if (item instanceof Uint8Array) {
10152
10249
  return 'bytes';
@@ -10177,6 +10274,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10177
10274
  const normalizedSenderId = typeof senderId === 'string' && senderId.length > 0
10178
10275
  ? senderId
10179
10276
  : undefined;
10277
+ if (normalizedSenderId && normalizedSenderId !== this.localNodeId) {
10278
+ logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10279
+ channel: this.channelName,
10280
+ connector_id: this.connectorId,
10281
+ sender_id: normalizedSenderId,
10282
+ dedup_key: dedupKey,
10283
+ source: 'listener',
10284
+ });
10285
+ return false;
10286
+ }
10180
10287
  logger$_.debug('broadcast_channel_duplicate_ack_check', {
10181
10288
  channel: this.channelName,
10182
10289
  connector_id: this.connectorId,
@@ -10207,6 +10314,16 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10207
10314
  return false;
10208
10315
  }
10209
10316
  const senderId = this._extractSenderIdFromInboxItem(item);
10317
+ if (senderId && senderId !== this.localNodeId) {
10318
+ logger$_.debug('broadcast_channel_duplicate_ack_bypass_non_self', {
10319
+ channel: this.channelName,
10320
+ connector_id: this.connectorId,
10321
+ sender_id: senderId,
10322
+ dedup_key: dedupKey,
10323
+ source: 'inbox_item',
10324
+ });
10325
+ return false;
10326
+ }
10210
10327
  logger$_.debug('broadcast_channel_duplicate_ack_check', {
10211
10328
  channel: this.channelName,
10212
10329
  connector_id: this.connectorId,
@@ -10293,6 +10410,34 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
10293
10410
  });
10294
10411
  }
10295
10412
  }
10413
+ setTargetNodeId(nodeId) {
10414
+ const normalized = BroadcastChannelConnector.normalizeNodeId(nodeId);
10415
+ if (!normalized) {
10416
+ throw new Error('BroadcastChannelConnector target node id must be a non-empty string');
10417
+ }
10418
+ if (normalized === '*') {
10419
+ this.setWildcardTarget();
10420
+ return;
10421
+ }
10422
+ this.targetNodeId = normalized;
10423
+ logger$_.debug('broadcast_channel_target_updated', {
10424
+ channel: this.channelName,
10425
+ connector_id: this.connectorId,
10426
+ local_node_id: this.localNodeId,
10427
+ target_node_id: this.targetNodeId,
10428
+ target_mode: 'direct',
10429
+ });
10430
+ }
10431
+ setWildcardTarget() {
10432
+ this.targetNodeId = '*';
10433
+ logger$_.debug('broadcast_channel_target_updated', {
10434
+ channel: this.channelName,
10435
+ connector_id: this.connectorId,
10436
+ local_node_id: this.localNodeId,
10437
+ target_node_id: this.targetNodeId,
10438
+ target_mode: 'wildcard',
10439
+ });
10440
+ }
10296
10441
  _trimSeenAcks(now) {
10297
10442
  while (this.seenAckOrder.length > 0) {
10298
10443
  const candidate = this.seenAckOrder[0];
@@ -28667,8 +28812,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
28667
28812
  }
28668
28813
  const normalized = this._normalizeConfig(config);
28669
28814
  const options = (factoryArgs[0] ?? {});
28815
+ const localNodeId = this._normalizeNodeId(options.localNodeId);
28816
+ if (!localNodeId) {
28817
+ throw new Error('BroadcastChannelConnectorFactory requires a localNodeId in create() options');
28818
+ }
28670
28819
  const channelName = normalized.channelName ?? DEFAULT_CHANNEL$5;
28671
28820
  const inboxCapacity = normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$5;
28821
+ const resolvedTarget = this._normalizeTargetNodeId(options.initialTargetNodeId ?? normalized.initialTargetNodeId);
28672
28822
  const baseConfig = {
28673
28823
  drainTimeout: normalized.drainTimeout,
28674
28824
  flowControl: normalized.flowControl,
@@ -28683,6 +28833,8 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
28683
28833
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
28684
28834
  channelName,
28685
28835
  inboxCapacity,
28836
+ localNodeId,
28837
+ initialTargetNodeId: resolvedTarget,
28686
28838
  };
28687
28839
  const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
28688
28840
  if (options.authorization) {
@@ -28706,6 +28858,13 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
28706
28858
  normalized.channelName = channel.trim();
28707
28859
  }
28708
28860
  const capacity = candidate.inboxCapacity ?? candidate['inbox_capacity'];
28861
+ const initialTargetNodeId = candidate.initialTargetNodeId ?? candidate['initial_target_node_id'];
28862
+ if (typeof initialTargetNodeId === 'string' && initialTargetNodeId.trim().length > 0) {
28863
+ normalized.initialTargetNodeId = initialTargetNodeId.trim();
28864
+ }
28865
+ else if (initialTargetNodeId === '*') {
28866
+ normalized.initialTargetNodeId = '*';
28867
+ }
28709
28868
  if (typeof capacity === 'number' &&
28710
28869
  Number.isFinite(capacity) &&
28711
28870
  capacity > 0) {
@@ -28749,6 +28908,19 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
28749
28908
  normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$5;
28750
28909
  return normalized;
28751
28910
  }
28911
+ _normalizeNodeId(value) {
28912
+ if (typeof value !== 'string') {
28913
+ return null;
28914
+ }
28915
+ const trimmed = value.trim();
28916
+ return trimmed.length > 0 ? trimmed : null;
28917
+ }
28918
+ _normalizeTargetNodeId(value) {
28919
+ if (value === '*') {
28920
+ return '*';
28921
+ }
28922
+ return this._normalizeNodeId(value) ?? '*';
28923
+ }
28752
28924
  }
28753
28925
 
28754
28926
  var broadcastChannelConnectorFactory = /*#__PURE__*/Object.freeze({
@@ -36326,7 +36498,7 @@ class BroadcastChannelListener extends TransportListener {
36326
36498
  node: routingNode,
36327
36499
  });
36328
36500
  const selection = defaultGrantSelectionPolicy.selectCallbackGrant(selectionContext);
36329
- connectorConfig = this._grantToConnectorConfig(selection.grant);
36501
+ connectorConfig = this._grantToConnectorConfig(selection.grant, systemId);
36330
36502
  }
36331
36503
  catch (error) {
36332
36504
  logger$a.debug('broadcast_channel_listener_grant_selection_failed', {
@@ -36335,13 +36507,20 @@ class BroadcastChannelListener extends TransportListener {
36335
36507
  error: error instanceof Error ? error.message : String(error),
36336
36508
  });
36337
36509
  connectorConfig =
36338
- this._extractBroadcastConnectorConfig(frame) ??
36339
- {
36510
+ this._extractBroadcastConnectorConfig(frame, systemId) ??
36511
+ this._buildConnectorConfigForSystem(systemId, {
36340
36512
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
36341
36513
  channelName: this._channelName,
36342
36514
  inboxCapacity: this._inboxCapacity,
36343
36515
  passive: true,
36344
- };
36516
+ });
36517
+ }
36518
+ if (!connectorConfig) {
36519
+ logger$a.error('broadcast_channel_listener_missing_connector_config', {
36520
+ sender_id: params.senderId,
36521
+ system_id: systemId,
36522
+ });
36523
+ return null;
36345
36524
  }
36346
36525
  try {
36347
36526
  const connector = await routingNode.createOriginConnector({
@@ -36367,7 +36546,7 @@ class BroadcastChannelListener extends TransportListener {
36367
36546
  return null;
36368
36547
  }
36369
36548
  }
36370
- _extractBroadcastConnectorConfig(frame) {
36549
+ _extractBroadcastConnectorConfig(frame, systemId) {
36371
36550
  const rawGrants = frame.callbackGrants;
36372
36551
  if (!Array.isArray(rawGrants)) {
36373
36552
  return null;
@@ -36378,7 +36557,10 @@ class BroadcastChannelListener extends TransportListener {
36378
36557
  (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE ||
36379
36558
  grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE)) {
36380
36559
  try {
36381
- return this._grantToConnectorConfig(grant);
36560
+ if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE) {
36561
+ return this._buildConnectorConfigForSystem(systemId, grant);
36562
+ }
36563
+ return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
36382
36564
  }
36383
36565
  catch (error) {
36384
36566
  logger$a.debug('broadcast_channel_listener_grant_normalization_failed', {
@@ -36389,31 +36571,87 @@ class BroadcastChannelListener extends TransportListener {
36389
36571
  }
36390
36572
  return null;
36391
36573
  }
36392
- _grantToConnectorConfig(grant) {
36393
- if (grant.type !== BROADCAST_CHANNEL_CONNECTOR_TYPE) {
36394
- if (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE) {
36395
- return broadcastChannelGrantToConnectorConfig(grant);
36574
+ _grantToConnectorConfig(grant, systemId) {
36575
+ if (grant.type === BROADCAST_CHANNEL_CONNECTOR_TYPE) {
36576
+ return this._buildConnectorConfigForSystem(systemId, grant);
36577
+ }
36578
+ if (grant.type === BROADCAST_CHANNEL_CONNECTION_GRANT_TYPE) {
36579
+ return this._buildConnectorConfigForSystem(systemId, broadcastChannelGrantToConnectorConfig(grant));
36580
+ }
36581
+ if ('toConnectorConfig' in grant &&
36582
+ typeof grant.toConnectorConfig ===
36583
+ 'function') {
36584
+ const normalized = grant.toConnectorConfig();
36585
+ if (normalized.type !== BROADCAST_CHANNEL_CONNECTOR_TYPE) {
36586
+ throw new Error(`Unsupported grant connector type: ${normalized.type}`);
36396
36587
  }
36397
- throw new Error(`Unsupported grant type: ${grant.type}`);
36588
+ return this._buildConnectorConfigForSystem(systemId, normalized);
36398
36589
  }
36399
- const candidate = grant;
36400
- const config = {
36590
+ throw new Error(`Unsupported grant type: ${grant.type}`);
36591
+ }
36592
+ _buildConnectorConfigForSystem(systemId, baseConfig) {
36593
+ const localNodeId = this._requireLocalNodeId();
36594
+ const targetSystemId = this._normalizeNodeId(systemId);
36595
+ if (!targetSystemId) {
36596
+ throw new Error('BroadcastChannelListener requires a valid system id');
36597
+ }
36598
+ const candidate = baseConfig ?? null;
36599
+ const channelCandidate = candidate && 'channelName' in candidate
36600
+ ? candidate.channelName
36601
+ : undefined;
36602
+ const inboxCandidate = candidate && 'inboxCapacity' in candidate
36603
+ ? candidate.inboxCapacity
36604
+ : undefined;
36605
+ const initialWindowCandidate = candidate && 'initialWindow' in candidate
36606
+ ? candidate.initialWindow
36607
+ : undefined;
36608
+ const passiveCandidate = candidate && 'passive' in candidate
36609
+ ? candidate.passive
36610
+ : undefined;
36611
+ const targetCandidate = candidate && 'initialTargetNodeId' in candidate
36612
+ ? candidate.initialTargetNodeId
36613
+ : undefined;
36614
+ const channelName = typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
36615
+ ? channelCandidate.trim()
36616
+ : this._channelName;
36617
+ const inboxCapacity = typeof inboxCandidate === 'number' &&
36618
+ Number.isFinite(inboxCandidate) &&
36619
+ inboxCandidate > 0
36620
+ ? Math.floor(inboxCandidate)
36621
+ : this._inboxCapacity;
36622
+ const initialWindow = typeof initialWindowCandidate === 'number' &&
36623
+ Number.isFinite(initialWindowCandidate) &&
36624
+ initialWindowCandidate > 0
36625
+ ? Math.floor(initialWindowCandidate)
36626
+ : undefined;
36627
+ const initialTargetNodeId = this._normalizeNodeId(targetCandidate) ?? targetSystemId;
36628
+ return {
36401
36629
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
36402
- channelName: this._channelName,
36403
- inboxCapacity: this._inboxCapacity,
36404
- passive: true,
36630
+ channelName,
36631
+ inboxCapacity,
36632
+ passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
36633
+ initialWindow,
36634
+ localNodeId,
36635
+ initialTargetNodeId,
36405
36636
  };
36406
- const channelCandidate = candidate.channelName ?? candidate['channel_name'];
36407
- if (typeof channelCandidate === 'string' && channelCandidate.trim().length > 0) {
36408
- config.channelName = channelCandidate.trim();
36637
+ }
36638
+ _requireLocalNodeId() {
36639
+ if (!this._routingNode) {
36640
+ throw new Error('BroadcastChannelListener requires routing node context');
36409
36641
  }
36410
- const inboxCandidate = candidate.inboxCapacity ?? candidate['inbox_capacity'];
36411
- if (typeof inboxCandidate === 'number' &&
36412
- Number.isFinite(inboxCandidate) &&
36413
- inboxCandidate > 0) {
36414
- config.inboxCapacity = Math.floor(inboxCandidate);
36642
+ const normalized = this._normalizeNodeId(this._routingNode.sid) ??
36643
+ this._normalizeNodeId(this._routingNode.id);
36644
+ if (!normalized) {
36645
+ throw new Error('BroadcastChannelListener requires routing node with a stable identifier');
36415
36646
  }
36416
- return config;
36647
+ return normalized;
36648
+ }
36649
+ _normalizeNodeId(value) {
36650
+ if (typeof value !== 'string') {
36651
+ return null;
36652
+ }
36653
+ const trimmed = value.trim();
36654
+ return trimmed.length > 0 ? trimmed : null;
36417
36655
  }
36418
36656
  _monitorConnectorLifecycle(senderId, systemId, connector) {
36419
36657
  const maybeClosable = connector;