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