@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/index.js CHANGED
@@ -1404,6 +1404,10 @@ function generateLrsBridgeCode(options) {
1404
1404
  log('Looking up email for employee ID:', employeeId);
1405
1405
 
1406
1406
  fetchEmployeeEmail(employeeId, function(employeeData) {
1407
+ console.info('[PA-LRS] Employee lookup result for ' + employeeId + ': ' +
1408
+ (employeeData ? 'name=' + employeeData.name + ', email=' + employeeData.email +
1409
+ ', bravaisUserId=' + employeeData.bravaisUserId + ', tenantUrl=' + employeeData.tenantUrl
1410
+ : 'NO DATA'));
1407
1411
  if (employeeData && employeeData.email) {
1408
1412
  actor.mbox = 'mailto:' + employeeData.email;
1409
1413
  log('Enhanced actor with email:', employeeData.email);
@@ -4109,14 +4113,83 @@ function generateLrsBridgeCode(options) {
4109
4113
  // Launch events will NOT be sent until this completes
4110
4114
  extractActorAsync(function(actor) {
4111
4115
  log('Actor updated after async fetch:', actor);
4112
- actorReady = true;
4113
- // Log final actor state for diagnostics
4114
- if (window.console && window.console.info) {
4115
- console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4116
- ', mbox=' + (actor ? actor.mbox : 'none') +
4117
- ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4116
+
4117
+ // Check if actor is still "Unknown Learner" - SCORM API might not be available yet
4118
+ // The SCORM API is often injected by scorm-calls.js AFTER <head> init completes
4119
+ var isUnknown = !actor || actor.name === 'Unknown Learner' ||
4120
+ !actor.account || actor.account.name === 'unknown';
4121
+
4122
+ if (isUnknown) {
4123
+ log('Actor is Unknown Learner - SCORM API likely not available yet, polling for it...');
4124
+ var scormPollCount = 0;
4125
+ var scormMaxPolls = 20; // wait up to 20 seconds
4126
+
4127
+ var scormPollTimer = setInterval(function() {
4128
+ scormPollCount++;
4129
+
4130
+ // Search parent frames for SCORM API (not just current window)
4131
+ var api2004 = findAPIInFrameHierarchy('API_1484_11', 10);
4132
+ var api12 = !api2004 ? findAPIInFrameHierarchy('API', 10) : null;
4133
+ var foundApi = api2004 || api12;
4134
+
4135
+ if (foundApi) {
4136
+ clearInterval(scormPollTimer);
4137
+ var foundType = api2004 ? '2004' : '1.2';
4138
+ log('SCORM API found on poll ' + scormPollCount + ' at level ' + foundApi.level);
4139
+
4140
+ // Update LRS SCORM API reference
4141
+ if (!LRS.scormApi) {
4142
+ LRS.scormApi = foundApi.api;
4143
+ LRS.scormApiFound = true;
4144
+ LRS.scormApiType = foundType;
4145
+ }
4146
+
4147
+ // Read learner_id right now for diagnostics
4148
+ var scormLearnerId = 'n/a', scormLearnerName = 'n/a';
4149
+ try {
4150
+ if (foundType === '2004') {
4151
+ scormLearnerId = foundApi.api.GetValue('cmi.learner_id');
4152
+ scormLearnerName = foundApi.api.GetValue('cmi.learner_name');
4153
+ } else {
4154
+ scormLearnerId = foundApi.api.LMSGetValue('cmi.core.student_id');
4155
+ scormLearnerName = foundApi.api.LMSGetValue('cmi.core.student_name');
4156
+ }
4157
+ } catch(e) { scormLearnerId = 'error'; scormLearnerName = 'error'; }
4158
+ console.info('[PA-LRS] SCORM API found (poll ' + scormPollCount + ', type=' + foundType +
4159
+ ', level=' + foundApi.level + '): learner_id=' + scormLearnerId + ', learner_name=' + scormLearnerName);
4160
+
4161
+ // refreshActor re-reads learner_id from SCORM and runs employee lookup
4162
+ LRS.refreshActor(function(refreshedActor) {
4163
+ if (window.console && window.console.info) {
4164
+ console.info('[PA-LRS] Actor resolved (after SCORM wait, poll ' + scormPollCount + '): name=' +
4165
+ (refreshedActor ? refreshedActor.name : 'none') +
4166
+ ', mbox=' + (refreshedActor ? refreshedActor.mbox : 'none') +
4167
+ ', account=' + (refreshedActor && refreshedActor.account ? refreshedActor.account.name : 'none'));
4168
+ }
4169
+ actorReady = true;
4170
+ tryLaunchEvents();
4171
+ });
4172
+ } else if (scormPollCount >= scormMaxPolls) {
4173
+ clearInterval(scormPollTimer);
4174
+ log('SCORM API not found after ' + scormMaxPolls + 's, proceeding with Unknown Learner');
4175
+ if (window.console && window.console.info) {
4176
+ console.info('[PA-LRS] Actor resolved (timeout): name=' + (actor ? actor.name : 'none') +
4177
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4178
+ }
4179
+ actorReady = true;
4180
+ tryLaunchEvents();
4181
+ }
4182
+ }, 1000);
4183
+ } else {
4184
+ // Actor is valid - proceed immediately
4185
+ if (window.console && window.console.info) {
4186
+ console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4187
+ ', mbox=' + (actor ? actor.mbox : 'none') +
4188
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4189
+ }
4190
+ actorReady = true;
4191
+ tryLaunchEvents();
4118
4192
  }
4119
- tryLaunchEvents();
4120
4193
  });
4121
4194
  } else {
4122
4195
  warn('Bridge setup failed - operating in offline mode');
@@ -4239,32 +4312,6 @@ function generateLrsBridgeCode(options) {
4239
4312
  }, 1000);
4240
4313
  }
4241
4314
 
4242
- // If actor is still Unknown Learner, poll for SCORM API availability
4243
- // The SCORM API may not be available during <head> init but appears later
4244
- // (e.g., scorm-calls.js finds and initializes it after DOM ready)
4245
- if (!LRS.actor || LRS.actor.name === 'Unknown Learner' || !LRS.actor.account || LRS.actor.account.name === 'unknown') {
4246
- var actorRetryCount = 0;
4247
- var actorMaxRetries = 15;
4248
- var actorRetryInterval = setInterval(function() {
4249
- actorRetryCount++;
4250
- // Check if SCORM API has become available (injected by scorm-calls.js or LMS)
4251
- var hasScormApi = LRS.scormApi ||
4252
- (typeof window.API !== 'undefined' && window.API) ||
4253
- (typeof window.API_1484_11 !== 'undefined' && window.API_1484_11);
4254
-
4255
- if (hasScormApi) {
4256
- log('SCORM API now available (attempt ' + actorRetryCount + '), refreshing actor...');
4257
- clearInterval(actorRetryInterval);
4258
- LRS.refreshActor(function(actor) {
4259
- log('Actor refreshed after SCORM API detected:', actor ? actor.name : 'none');
4260
- });
4261
- } else if (actorRetryCount >= actorMaxRetries) {
4262
- log('SCORM API not found after ' + actorMaxRetries + ' attempts, actor stays as-is');
4263
- clearInterval(actorRetryInterval);
4264
- }
4265
- }, 1000);
4266
- }
4267
-
4268
4315
  log('LRS bridge setup complete');
4269
4316
  }
4270
4317