@patch-adams/core 1.4.26 → 1.4.28

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.js CHANGED
@@ -4413,6 +4413,19 @@ function generateLrsBridgeCode(options) {
4413
4413
  // Setup connection
4414
4414
  var bridgeReady = setupBridge();
4415
4415
 
4416
+ // Track async readiness: both actor and doc metadata must resolve before sending statements
4417
+ var actorReady = false;
4418
+ var docReady = false;
4419
+ var launchEventsSent = false;
4420
+
4421
+ function tryLaunchEvents() {
4422
+ if (launchEventsSent) return;
4423
+ if (!actorReady || !docReady) return;
4424
+ launchEventsSent = true;
4425
+ log('Both actor and doc metadata ready, sending launch events');
4426
+ setTimeout(sendLaunchEvents, 50);
4427
+ }
4428
+
4416
4429
  if (bridgeReady) {
4417
4430
  LRS.initialized = true;
4418
4431
 
@@ -4423,14 +4436,23 @@ function generateLrsBridgeCode(options) {
4423
4436
  log('Actor:', LRS.actor);
4424
4437
  log('Course:', LRS.courseInfo);
4425
4438
 
4426
- // Then try async actor extraction from Bravais session
4427
- // This will update the actor with real user info if available
4439
+ // Then try async actor extraction (employee lookup, Bravais session)
4440
+ // Launch events will NOT be sent until this completes
4428
4441
  extractActorAsync(function(actor) {
4429
4442
  log('Actor updated after async fetch:', actor);
4443
+ actorReady = true;
4444
+ // Log final actor state for diagnostics
4445
+ if (window.console && window.console.info) {
4446
+ console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4447
+ ', mbox=' + (actor ? actor.mbox : 'none') +
4448
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4449
+ }
4450
+ tryLaunchEvents();
4430
4451
  });
4431
4452
  } else {
4432
4453
  warn('Bridge setup failed - operating in offline mode');
4433
4454
  LRS.mode = 'offline';
4455
+ actorReady = true; // No actor to wait for in offline mode
4434
4456
  }
4435
4457
 
4436
4458
  // Always-visible bridge summary (not gated by DEBUG)
@@ -4475,13 +4497,17 @@ function generateLrsBridgeCode(options) {
4475
4497
  }
4476
4498
  }
4477
4499
 
4478
- function fetchDocDataAndSend(docId) {
4500
+ function onDocReady() {
4501
+ docReady = true;
4502
+ tryLaunchEvents();
4503
+ }
4504
+
4505
+ function fetchDocDataAndReady(docId) {
4479
4506
  fetchDocumentMetadata(docId, function(docData) {
4480
4507
  if (docData) {
4481
4508
  updateCourseInfoFromApi(docData);
4482
4509
  }
4483
- // Send launch events after API fetch (success or failure)
4484
- setTimeout(sendLaunchEvents, 100);
4510
+ onDocReady();
4485
4511
  });
4486
4512
  }
4487
4513
 
@@ -4501,20 +4527,20 @@ function generateLrsBridgeCode(options) {
4501
4527
  } else {
4502
4528
  warn('Could not fetch document data from shared API - statements may fail aggregation');
4503
4529
  }
4504
- setTimeout(sendLaunchEvents, 100);
4530
+ onDocReady();
4505
4531
  });
4506
4532
  } else if (documentId) {
4507
4533
  // No shared link token, try with extracted document ID (requires auth)
4508
4534
  log('No shared link token, fetching document data with ID:', documentId);
4509
- fetchDocDataAndSend(documentId);
4535
+ fetchDocDataAndReady(documentId);
4510
4536
  } else {
4511
4537
  // No identifiers available
4512
4538
  warn('No shared link token or document ID - statements may fail aggregation');
4513
- setTimeout(sendLaunchEvents, 500);
4539
+ onDocReady();
4514
4540
  }
4515
4541
  } else {
4516
- // Already have GUID - send after short delay
4517
- setTimeout(sendLaunchEvents, 500);
4542
+ // Already have GUID
4543
+ onDocReady();
4518
4544
  }
4519
4545
 
4520
4546
  // Setup beforeunload to send terminated
@@ -4544,6 +4570,32 @@ function generateLrsBridgeCode(options) {
4544
4570
  }, 1000);
4545
4571
  }
4546
4572
 
4573
+ // If actor is still Unknown Learner, poll for SCORM API availability
4574
+ // The SCORM API may not be available during <head> init but appears later
4575
+ // (e.g., scorm-calls.js finds and initializes it after DOM ready)
4576
+ if (!LRS.actor || LRS.actor.name === 'Unknown Learner' || !LRS.actor.account || LRS.actor.account.name === 'unknown') {
4577
+ var actorRetryCount = 0;
4578
+ var actorMaxRetries = 15;
4579
+ var actorRetryInterval = setInterval(function() {
4580
+ actorRetryCount++;
4581
+ // Check if SCORM API has become available (injected by scorm-calls.js or LMS)
4582
+ var hasScormApi = LRS.scormApi ||
4583
+ (typeof window.API !== 'undefined' && window.API) ||
4584
+ (typeof window.API_1484_11 !== 'undefined' && window.API_1484_11);
4585
+
4586
+ if (hasScormApi) {
4587
+ log('SCORM API now available (attempt ' + actorRetryCount + '), refreshing actor...');
4588
+ clearInterval(actorRetryInterval);
4589
+ LRS.refreshActor(function(actor) {
4590
+ log('Actor refreshed after SCORM API detected:', actor ? actor.name : 'none');
4591
+ });
4592
+ } else if (actorRetryCount >= actorMaxRetries) {
4593
+ log('SCORM API not found after ' + actorMaxRetries + ' attempts, actor stays as-is');
4594
+ clearInterval(actorRetryInterval);
4595
+ }
4596
+ }, 1000);
4597
+ }
4598
+
4547
4599
  log('LRS bridge setup complete');
4548
4600
  }
4549
4601