@patch-adams/core 1.4.28 → 1.4.30

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
@@ -1735,6 +1735,10 @@ function generateLrsBridgeCode(options) {
1735
1735
  log('Looking up email for employee ID:', employeeId);
1736
1736
 
1737
1737
  fetchEmployeeEmail(employeeId, function(employeeData) {
1738
+ console.info('[PA-LRS] Employee lookup result for ' + employeeId + ': ' +
1739
+ (employeeData ? 'name=' + employeeData.name + ', email=' + employeeData.email +
1740
+ ', bravaisUserId=' + employeeData.bravaisUserId + ', tenantUrl=' + employeeData.tenantUrl
1741
+ : 'NO DATA'));
1738
1742
  if (employeeData && employeeData.email) {
1739
1743
  actor.mbox = 'mailto:' + employeeData.email;
1740
1744
  log('Enhanced actor with email:', employeeData.email);
@@ -4440,14 +4444,83 @@ function generateLrsBridgeCode(options) {
4440
4444
  // Launch events will NOT be sent until this completes
4441
4445
  extractActorAsync(function(actor) {
4442
4446
  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'));
4447
+
4448
+ // Check if actor is still "Unknown Learner" - SCORM API might not be available yet
4449
+ // The SCORM API is often injected by scorm-calls.js AFTER <head> init completes
4450
+ var isUnknown = !actor || actor.name === 'Unknown Learner' ||
4451
+ !actor.account || actor.account.name === 'unknown';
4452
+
4453
+ if (isUnknown) {
4454
+ log('Actor is Unknown Learner - SCORM API likely not available yet, polling for it...');
4455
+ var scormPollCount = 0;
4456
+ var scormMaxPolls = 20; // wait up to 20 seconds
4457
+
4458
+ var scormPollTimer = setInterval(function() {
4459
+ scormPollCount++;
4460
+
4461
+ // Search parent frames for SCORM API (not just current window)
4462
+ var api2004 = findAPIInFrameHierarchy('API_1484_11', 10);
4463
+ var api12 = !api2004 ? findAPIInFrameHierarchy('API', 10) : null;
4464
+ var foundApi = api2004 || api12;
4465
+
4466
+ if (foundApi) {
4467
+ clearInterval(scormPollTimer);
4468
+ var foundType = api2004 ? '2004' : '1.2';
4469
+ log('SCORM API found on poll ' + scormPollCount + ' at level ' + foundApi.level);
4470
+
4471
+ // Update LRS SCORM API reference
4472
+ if (!LRS.scormApi) {
4473
+ LRS.scormApi = foundApi.api;
4474
+ LRS.scormApiFound = true;
4475
+ LRS.scormApiType = foundType;
4476
+ }
4477
+
4478
+ // Read learner_id right now for diagnostics
4479
+ var scormLearnerId = 'n/a', scormLearnerName = 'n/a';
4480
+ try {
4481
+ if (foundType === '2004') {
4482
+ scormLearnerId = foundApi.api.GetValue('cmi.learner_id');
4483
+ scormLearnerName = foundApi.api.GetValue('cmi.learner_name');
4484
+ } else {
4485
+ scormLearnerId = foundApi.api.LMSGetValue('cmi.core.student_id');
4486
+ scormLearnerName = foundApi.api.LMSGetValue('cmi.core.student_name');
4487
+ }
4488
+ } catch(e) { scormLearnerId = 'error'; scormLearnerName = 'error'; }
4489
+ console.info('[PA-LRS] SCORM API found (poll ' + scormPollCount + ', type=' + foundType +
4490
+ ', level=' + foundApi.level + '): learner_id=' + scormLearnerId + ', learner_name=' + scormLearnerName);
4491
+
4492
+ // refreshActor re-reads learner_id from SCORM and runs employee lookup
4493
+ LRS.refreshActor(function(refreshedActor) {
4494
+ if (window.console && window.console.info) {
4495
+ console.info('[PA-LRS] Actor resolved (after SCORM wait, poll ' + scormPollCount + '): name=' +
4496
+ (refreshedActor ? refreshedActor.name : 'none') +
4497
+ ', mbox=' + (refreshedActor ? refreshedActor.mbox : 'none') +
4498
+ ', account=' + (refreshedActor && refreshedActor.account ? refreshedActor.account.name : 'none'));
4499
+ }
4500
+ actorReady = true;
4501
+ tryLaunchEvents();
4502
+ });
4503
+ } else if (scormPollCount >= scormMaxPolls) {
4504
+ clearInterval(scormPollTimer);
4505
+ log('SCORM API not found after ' + scormMaxPolls + 's, proceeding with Unknown Learner');
4506
+ if (window.console && window.console.info) {
4507
+ console.info('[PA-LRS] Actor resolved (timeout): name=' + (actor ? actor.name : 'none') +
4508
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4509
+ }
4510
+ actorReady = true;
4511
+ tryLaunchEvents();
4512
+ }
4513
+ }, 1000);
4514
+ } else {
4515
+ // Actor is valid - proceed immediately
4516
+ if (window.console && window.console.info) {
4517
+ console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4518
+ ', mbox=' + (actor ? actor.mbox : 'none') +
4519
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4520
+ }
4521
+ actorReady = true;
4522
+ tryLaunchEvents();
4449
4523
  }
4450
- tryLaunchEvents();
4451
4524
  });
4452
4525
  } else {
4453
4526
  warn('Bridge setup failed - operating in offline mode');
@@ -4570,32 +4643,6 @@ function generateLrsBridgeCode(options) {
4570
4643
  }, 1000);
4571
4644
  }
4572
4645
 
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
-
4599
4646
  log('LRS bridge setup complete');
4600
4647
  }
4601
4648