@naylence/runtime 0.3.5-test.940 → 0.3.5-test.942

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.
@@ -5478,12 +5478,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
5478
5478
  }
5479
5479
 
5480
5480
  // This file is auto-generated during build - do not edit manually
5481
- // Generated from package.json version: 0.3.5-test.940
5481
+ // Generated from package.json version: 0.3.5-test.942
5482
5482
  /**
5483
5483
  * The package version, injected at build time.
5484
5484
  * @internal
5485
5485
  */
5486
- const VERSION = '0.3.5-test.940';
5486
+ const VERSION = '0.3.5-test.942';
5487
5487
 
5488
5488
  /**
5489
5489
  * Fame errors module - Fame protocol specific error classes
@@ -11646,6 +11646,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11646
11646
  if (typeof document !== 'undefined') {
11647
11647
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
11648
11648
  this.visibilityChangeListenerRegistered = true;
11649
+ // Track page lifecycle events to detect browser unload/discard
11650
+ if (typeof window !== 'undefined') {
11651
+ const lifecycleLogger = (event) => {
11652
+ logger$10.info('broadcast_channel_page_lifecycle', {
11653
+ channel: this.channelName,
11654
+ connector_id: this.connectorId,
11655
+ event_type: event.type,
11656
+ visibility_state: document.visibilityState,
11657
+ timestamp: new Date().toISOString(),
11658
+ });
11659
+ };
11660
+ window.addEventListener('beforeunload', lifecycleLogger);
11661
+ window.addEventListener('unload', lifecycleLogger);
11662
+ window.addEventListener('pagehide', lifecycleLogger);
11663
+ window.addEventListener('pageshow', lifecycleLogger);
11664
+ document.addEventListener('freeze', lifecycleLogger);
11665
+ document.addEventListener('resume', lifecycleLogger);
11666
+ }
11649
11667
  // Log initial state with detailed visibility info
11650
11668
  logger$10.debug('broadcast_channel_initial_visibility', {
11651
11669
  channel: this.channelName,
@@ -11654,6 +11672,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11654
11672
  document_hidden: document.hidden,
11655
11673
  visibility_state: document.visibilityState,
11656
11674
  has_focus: document.hasFocus(),
11675
+ timestamp: new Date().toISOString(),
11657
11676
  });
11658
11677
  }
11659
11678
  }
@@ -12366,7 +12385,7 @@ class UpstreamSessionManager extends TaskSpawner {
12366
12385
  this.currentStopSubtasks = null;
12367
12386
  await Promise.allSettled(tasks.map((task) => task.promise));
12368
12387
  if (this.connector) {
12369
- logger$$.info('upstream_stopping_old_connector', {
12388
+ logger$$.debug('upstream_stopping_old_connector', {
12370
12389
  connect_epoch: this.connectEpoch,
12371
12390
  target_system_id: this.targetSystemId,
12372
12391
  timestamp: new Date().toISOString(),
@@ -12377,7 +12396,7 @@ class UpstreamSessionManager extends TaskSpawner {
12377
12396
  error: err instanceof Error ? err.message : String(err),
12378
12397
  });
12379
12398
  });
12380
- logger$$.info('upstream_old_connector_stopped', {
12399
+ logger$$.debug('upstream_old_connector_stopped', {
12381
12400
  connect_epoch: this.connectEpoch,
12382
12401
  target_system_id: this.targetSystemId,
12383
12402
  timestamp: new Date().toISOString(),
@@ -21407,6 +21426,7 @@ class InPageConnector extends BaseAsyncConnector {
21407
21426
  ensureBrowserEnvironment$2();
21408
21427
  super(baseConfig);
21409
21428
  this.listenerRegistered = false;
21429
+ this.visibilityChangeListenerRegistered = false;
21410
21430
  this.channelName =
21411
21431
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
21412
21432
  ? config.channelName.trim()
@@ -21494,6 +21514,92 @@ class InPageConnector extends BaseAsyncConnector {
21494
21514
  };
21495
21515
  getSharedBus$1().addEventListener(this.channelName, this.onMsg);
21496
21516
  this.listenerRegistered = true;
21517
+ // Setup visibility change monitoring
21518
+ this.visibilityChangeHandler = () => {
21519
+ const isHidden = document.hidden;
21520
+ logger$J.debug('inpage_visibility_changed', {
21521
+ channel: this.channelName,
21522
+ connector_id: this.connectorId,
21523
+ visibility: isHidden ? 'hidden' : 'visible',
21524
+ timestamp: new Date().toISOString(),
21525
+ });
21526
+ // Pause/resume connector based on visibility
21527
+ if (isHidden && this.state === core.ConnectorState.STARTED) {
21528
+ this.pause().catch((err) => {
21529
+ logger$J.warning('inpage_pause_failed', {
21530
+ channel: this.channelName,
21531
+ connector_id: this.connectorId,
21532
+ error: err instanceof Error ? err.message : String(err),
21533
+ });
21534
+ });
21535
+ }
21536
+ else if (!isHidden && this.state === core.ConnectorState.PAUSED) {
21537
+ this.resume().catch((err) => {
21538
+ logger$J.warning('inpage_resume_failed', {
21539
+ channel: this.channelName,
21540
+ connector_id: this.connectorId,
21541
+ error: err instanceof Error ? err.message : String(err),
21542
+ });
21543
+ });
21544
+ }
21545
+ };
21546
+ if (typeof document !== 'undefined') {
21547
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
21548
+ this.visibilityChangeListenerRegistered = true;
21549
+ // Track page lifecycle events to detect browser unload/discard
21550
+ if (typeof window !== 'undefined') {
21551
+ const lifecycleLogger = (event) => {
21552
+ logger$J.info('inpage_page_lifecycle', {
21553
+ channel: this.channelName,
21554
+ connector_id: this.connectorId,
21555
+ event_type: event.type,
21556
+ visibility_state: document.visibilityState,
21557
+ timestamp: new Date().toISOString(),
21558
+ });
21559
+ };
21560
+ window.addEventListener('beforeunload', lifecycleLogger);
21561
+ window.addEventListener('unload', lifecycleLogger);
21562
+ window.addEventListener('pagehide', lifecycleLogger);
21563
+ window.addEventListener('pageshow', lifecycleLogger);
21564
+ document.addEventListener('freeze', lifecycleLogger);
21565
+ document.addEventListener('resume', lifecycleLogger);
21566
+ }
21567
+ // Log initial state with detailed visibility info
21568
+ logger$J.debug('inpage_initial_visibility', {
21569
+ channel: this.channelName,
21570
+ connector_id: this.connectorId,
21571
+ visibility: document.hidden ? 'hidden' : 'visible',
21572
+ document_hidden: document.hidden,
21573
+ visibility_state: document.visibilityState,
21574
+ has_focus: document.hasFocus(),
21575
+ timestamp: new Date().toISOString(),
21576
+ });
21577
+ }
21578
+ }
21579
+ /**
21580
+ * Override start() to check initial visibility state
21581
+ */
21582
+ async start(inboundHandler) {
21583
+ await super.start(inboundHandler);
21584
+ // After transitioning to STARTED, check if tab is already hidden
21585
+ if (typeof document !== 'undefined' && document.hidden) {
21586
+ logger$J.debug('inpage_start_in_hidden_tab', {
21587
+ channel: this.channelName,
21588
+ connector_id: this.connectorId,
21589
+ document_hidden: document.hidden,
21590
+ visibility_state: document.visibilityState,
21591
+ has_focus: document.hasFocus(),
21592
+ timestamp: new Date().toISOString(),
21593
+ });
21594
+ // Immediately pause if tab is hidden at start time
21595
+ await this.pause().catch((err) => {
21596
+ logger$J.warning('inpage_initial_pause_failed', {
21597
+ channel: this.channelName,
21598
+ connector_id: this.connectorId,
21599
+ error: err instanceof Error ? err.message : String(err),
21600
+ });
21601
+ });
21602
+ }
21497
21603
  }
21498
21604
  // Allow listeners to feed envelopes directly into the in-page receive queue.
21499
21605
  async pushToReceive(rawOrEnvelope) {
@@ -21543,6 +21649,11 @@ class InPageConnector extends BaseAsyncConnector {
21543
21649
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
21544
21650
  this.listenerRegistered = false;
21545
21651
  }
21652
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
21653
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
21654
+ this.visibilityChangeListenerRegistered = false;
21655
+ this.visibilityChangeHandler = undefined;
21656
+ }
21546
21657
  const closeCode = typeof code === 'number' ? code : 1000;
21547
21658
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
21548
21659
  const shutdownError = new FameTransportClose(closeReason, closeCode);
@@ -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.940
5480
+ // Generated from package.json version: 0.3.5-test.942
5481
5481
  /**
5482
5482
  * The package version, injected at build time.
5483
5483
  * @internal
5484
5484
  */
5485
- const VERSION = '0.3.5-test.940';
5485
+ const VERSION = '0.3.5-test.942';
5486
5486
 
5487
5487
  /**
5488
5488
  * Fame errors module - Fame protocol specific error classes
@@ -11645,6 +11645,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11645
11645
  if (typeof document !== 'undefined') {
11646
11646
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
11647
11647
  this.visibilityChangeListenerRegistered = true;
11648
+ // Track page lifecycle events to detect browser unload/discard
11649
+ if (typeof window !== 'undefined') {
11650
+ const lifecycleLogger = (event) => {
11651
+ logger$10.info('broadcast_channel_page_lifecycle', {
11652
+ channel: this.channelName,
11653
+ connector_id: this.connectorId,
11654
+ event_type: event.type,
11655
+ visibility_state: document.visibilityState,
11656
+ timestamp: new Date().toISOString(),
11657
+ });
11658
+ };
11659
+ window.addEventListener('beforeunload', lifecycleLogger);
11660
+ window.addEventListener('unload', lifecycleLogger);
11661
+ window.addEventListener('pagehide', lifecycleLogger);
11662
+ window.addEventListener('pageshow', lifecycleLogger);
11663
+ document.addEventListener('freeze', lifecycleLogger);
11664
+ document.addEventListener('resume', lifecycleLogger);
11665
+ }
11648
11666
  // Log initial state with detailed visibility info
11649
11667
  logger$10.debug('broadcast_channel_initial_visibility', {
11650
11668
  channel: this.channelName,
@@ -11653,6 +11671,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
11653
11671
  document_hidden: document.hidden,
11654
11672
  visibility_state: document.visibilityState,
11655
11673
  has_focus: document.hasFocus(),
11674
+ timestamp: new Date().toISOString(),
11656
11675
  });
11657
11676
  }
11658
11677
  }
@@ -12365,7 +12384,7 @@ class UpstreamSessionManager extends TaskSpawner {
12365
12384
  this.currentStopSubtasks = null;
12366
12385
  await Promise.allSettled(tasks.map((task) => task.promise));
12367
12386
  if (this.connector) {
12368
- logger$$.info('upstream_stopping_old_connector', {
12387
+ logger$$.debug('upstream_stopping_old_connector', {
12369
12388
  connect_epoch: this.connectEpoch,
12370
12389
  target_system_id: this.targetSystemId,
12371
12390
  timestamp: new Date().toISOString(),
@@ -12376,7 +12395,7 @@ class UpstreamSessionManager extends TaskSpawner {
12376
12395
  error: err instanceof Error ? err.message : String(err),
12377
12396
  });
12378
12397
  });
12379
- logger$$.info('upstream_old_connector_stopped', {
12398
+ logger$$.debug('upstream_old_connector_stopped', {
12380
12399
  connect_epoch: this.connectEpoch,
12381
12400
  target_system_id: this.targetSystemId,
12382
12401
  timestamp: new Date().toISOString(),
@@ -21406,6 +21425,7 @@ class InPageConnector extends BaseAsyncConnector {
21406
21425
  ensureBrowserEnvironment$2();
21407
21426
  super(baseConfig);
21408
21427
  this.listenerRegistered = false;
21428
+ this.visibilityChangeListenerRegistered = false;
21409
21429
  this.channelName =
21410
21430
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
21411
21431
  ? config.channelName.trim()
@@ -21493,6 +21513,92 @@ class InPageConnector extends BaseAsyncConnector {
21493
21513
  };
21494
21514
  getSharedBus$1().addEventListener(this.channelName, this.onMsg);
21495
21515
  this.listenerRegistered = true;
21516
+ // Setup visibility change monitoring
21517
+ this.visibilityChangeHandler = () => {
21518
+ const isHidden = document.hidden;
21519
+ logger$J.debug('inpage_visibility_changed', {
21520
+ channel: this.channelName,
21521
+ connector_id: this.connectorId,
21522
+ visibility: isHidden ? 'hidden' : 'visible',
21523
+ timestamp: new Date().toISOString(),
21524
+ });
21525
+ // Pause/resume connector based on visibility
21526
+ if (isHidden && this.state === ConnectorState.STARTED) {
21527
+ this.pause().catch((err) => {
21528
+ logger$J.warning('inpage_pause_failed', {
21529
+ channel: this.channelName,
21530
+ connector_id: this.connectorId,
21531
+ error: err instanceof Error ? err.message : String(err),
21532
+ });
21533
+ });
21534
+ }
21535
+ else if (!isHidden && this.state === ConnectorState.PAUSED) {
21536
+ this.resume().catch((err) => {
21537
+ logger$J.warning('inpage_resume_failed', {
21538
+ channel: this.channelName,
21539
+ connector_id: this.connectorId,
21540
+ error: err instanceof Error ? err.message : String(err),
21541
+ });
21542
+ });
21543
+ }
21544
+ };
21545
+ if (typeof document !== 'undefined') {
21546
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
21547
+ this.visibilityChangeListenerRegistered = true;
21548
+ // Track page lifecycle events to detect browser unload/discard
21549
+ if (typeof window !== 'undefined') {
21550
+ const lifecycleLogger = (event) => {
21551
+ logger$J.info('inpage_page_lifecycle', {
21552
+ channel: this.channelName,
21553
+ connector_id: this.connectorId,
21554
+ event_type: event.type,
21555
+ visibility_state: document.visibilityState,
21556
+ timestamp: new Date().toISOString(),
21557
+ });
21558
+ };
21559
+ window.addEventListener('beforeunload', lifecycleLogger);
21560
+ window.addEventListener('unload', lifecycleLogger);
21561
+ window.addEventListener('pagehide', lifecycleLogger);
21562
+ window.addEventListener('pageshow', lifecycleLogger);
21563
+ document.addEventListener('freeze', lifecycleLogger);
21564
+ document.addEventListener('resume', lifecycleLogger);
21565
+ }
21566
+ // Log initial state with detailed visibility info
21567
+ logger$J.debug('inpage_initial_visibility', {
21568
+ channel: this.channelName,
21569
+ connector_id: this.connectorId,
21570
+ visibility: document.hidden ? 'hidden' : 'visible',
21571
+ document_hidden: document.hidden,
21572
+ visibility_state: document.visibilityState,
21573
+ has_focus: document.hasFocus(),
21574
+ timestamp: new Date().toISOString(),
21575
+ });
21576
+ }
21577
+ }
21578
+ /**
21579
+ * Override start() to check initial visibility state
21580
+ */
21581
+ async start(inboundHandler) {
21582
+ await super.start(inboundHandler);
21583
+ // After transitioning to STARTED, check if tab is already hidden
21584
+ if (typeof document !== 'undefined' && document.hidden) {
21585
+ logger$J.debug('inpage_start_in_hidden_tab', {
21586
+ channel: this.channelName,
21587
+ connector_id: this.connectorId,
21588
+ document_hidden: document.hidden,
21589
+ visibility_state: document.visibilityState,
21590
+ has_focus: document.hasFocus(),
21591
+ timestamp: new Date().toISOString(),
21592
+ });
21593
+ // Immediately pause if tab is hidden at start time
21594
+ await this.pause().catch((err) => {
21595
+ logger$J.warning('inpage_initial_pause_failed', {
21596
+ channel: this.channelName,
21597
+ connector_id: this.connectorId,
21598
+ error: err instanceof Error ? err.message : String(err),
21599
+ });
21600
+ });
21601
+ }
21496
21602
  }
21497
21603
  // Allow listeners to feed envelopes directly into the in-page receive queue.
21498
21604
  async pushToReceive(rawOrEnvelope) {
@@ -21542,6 +21648,11 @@ class InPageConnector extends BaseAsyncConnector {
21542
21648
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
21543
21649
  this.listenerRegistered = false;
21544
21650
  }
21651
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
21652
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
21653
+ this.visibilityChangeListenerRegistered = false;
21654
+ this.visibilityChangeHandler = undefined;
21655
+ }
21545
21656
  const closeCode = typeof code === 'number' ? code : 1000;
21546
21657
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
21547
21658
  const shutdownError = new FameTransportClose(closeReason, closeCode);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { BaseAsyncConnector, type BaseAsyncConnectorConfig } from './base-async-connector.js';
6
6
  import type { ConnectorConfig } from './connector-config.js';
7
- import type { FameEnvelope, FameChannelMessage } from '@naylence/core';
7
+ import type { FameEnvelope, FameChannelMessage, FameEnvelopeHandler } from '@naylence/core';
8
8
  export declare const INPAGE_CONNECTOR_TYPE: "inpage-connector";
9
9
  export interface InPageConnectorConfig extends ConnectorConfig {
10
10
  type: typeof INPAGE_CONNECTOR_TYPE;
@@ -18,9 +18,15 @@ export declare class InPageConnector extends BaseAsyncConnector {
18
18
  private listenerRegistered;
19
19
  private readonly connectorId;
20
20
  private readonly onMsg;
21
+ private visibilityChangeListenerRegistered;
22
+ private visibilityChangeHandler?;
21
23
  private static generateConnectorId;
22
24
  private static coercePayload;
23
25
  constructor(config: InPageConnectorConfig, baseConfig?: BaseAsyncConnectorConfig);
26
+ /**
27
+ * Override start() to check initial visibility state
28
+ */
29
+ start(inboundHandler: FameEnvelopeHandler): Promise<void>;
24
30
  pushToReceive(rawOrEnvelope: Uint8Array | FameEnvelope | FameChannelMessage): Promise<void>;
25
31
  protected _transportSendBytes(data: Uint8Array): Promise<void>;
26
32
  protected _transportReceive(): Promise<InPageInboxItem>;
@@ -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.940";
5
+ export declare const VERSION = "0.3.5-test.942";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naylence/runtime",
3
- "version": "0.3.5-test.940",
3
+ "version": "0.3.5-test.942",
4
4
  "type": "module",
5
5
  "description": "Naylence Runtime - Complete TypeScript runtime",
6
6
  "author": "Naylence Dev <naylencedev@gmail.com>",