@patch-adams/core 1.4.26 → 1.4.27

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/cli.cjs CHANGED
@@ -4422,6 +4422,19 @@ function generateLrsBridgeCode(options) {
4422
4422
  // Setup connection
4423
4423
  var bridgeReady = setupBridge();
4424
4424
 
4425
+ // Track async readiness: both actor and doc metadata must resolve before sending statements
4426
+ var actorReady = false;
4427
+ var docReady = false;
4428
+ var launchEventsSent = false;
4429
+
4430
+ function tryLaunchEvents() {
4431
+ if (launchEventsSent) return;
4432
+ if (!actorReady || !docReady) return;
4433
+ launchEventsSent = true;
4434
+ log('Both actor and doc metadata ready, sending launch events');
4435
+ setTimeout(sendLaunchEvents, 50);
4436
+ }
4437
+
4425
4438
  if (bridgeReady) {
4426
4439
  LRS.initialized = true;
4427
4440
 
@@ -4432,14 +4445,23 @@ function generateLrsBridgeCode(options) {
4432
4445
  log('Actor:', LRS.actor);
4433
4446
  log('Course:', LRS.courseInfo);
4434
4447
 
4435
- // Then try async actor extraction from Bravais session
4436
- // This will update the actor with real user info if available
4448
+ // Then try async actor extraction (employee lookup, Bravais session)
4449
+ // Launch events will NOT be sent until this completes
4437
4450
  extractActorAsync(function(actor) {
4438
4451
  log('Actor updated after async fetch:', actor);
4452
+ actorReady = true;
4453
+ // Log final actor state for diagnostics
4454
+ if (window.console && window.console.info) {
4455
+ console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4456
+ ', mbox=' + (actor ? actor.mbox : 'none') +
4457
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4458
+ }
4459
+ tryLaunchEvents();
4439
4460
  });
4440
4461
  } else {
4441
4462
  warn('Bridge setup failed - operating in offline mode');
4442
4463
  LRS.mode = 'offline';
4464
+ actorReady = true; // No actor to wait for in offline mode
4443
4465
  }
4444
4466
 
4445
4467
  // Always-visible bridge summary (not gated by DEBUG)
@@ -4484,13 +4506,17 @@ function generateLrsBridgeCode(options) {
4484
4506
  }
4485
4507
  }
4486
4508
 
4487
- function fetchDocDataAndSend(docId) {
4509
+ function onDocReady() {
4510
+ docReady = true;
4511
+ tryLaunchEvents();
4512
+ }
4513
+
4514
+ function fetchDocDataAndReady(docId) {
4488
4515
  fetchDocumentMetadata(docId, function(docData) {
4489
4516
  if (docData) {
4490
4517
  updateCourseInfoFromApi(docData);
4491
4518
  }
4492
- // Send launch events after API fetch (success or failure)
4493
- setTimeout(sendLaunchEvents, 100);
4519
+ onDocReady();
4494
4520
  });
4495
4521
  }
4496
4522
 
@@ -4510,20 +4536,20 @@ function generateLrsBridgeCode(options) {
4510
4536
  } else {
4511
4537
  warn('Could not fetch document data from shared API - statements may fail aggregation');
4512
4538
  }
4513
- setTimeout(sendLaunchEvents, 100);
4539
+ onDocReady();
4514
4540
  });
4515
4541
  } else if (documentId) {
4516
4542
  // No shared link token, try with extracted document ID (requires auth)
4517
4543
  log('No shared link token, fetching document data with ID:', documentId);
4518
- fetchDocDataAndSend(documentId);
4544
+ fetchDocDataAndReady(documentId);
4519
4545
  } else {
4520
4546
  // No identifiers available
4521
4547
  warn('No shared link token or document ID - statements may fail aggregation');
4522
- setTimeout(sendLaunchEvents, 500);
4548
+ onDocReady();
4523
4549
  }
4524
4550
  } else {
4525
- // Already have GUID - send after short delay
4526
- setTimeout(sendLaunchEvents, 500);
4551
+ // Already have GUID
4552
+ onDocReady();
4527
4553
  }
4528
4554
 
4529
4555
  // Setup beforeunload to send terminated