@patch-adams/core 1.4.28 → 1.4.31
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 +123 -33
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +123 -33
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +123 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +123 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,126 @@ 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
|
-
|
|
4113
|
-
//
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
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 = 30; // wait up to 30 seconds
|
|
4126
|
+
var scormResolved = false;
|
|
4127
|
+
|
|
4128
|
+
// Helper: search all possible locations for SCORM API
|
|
4129
|
+
function findScormApiAnywhere() {
|
|
4130
|
+
// 1. Search parent frame hierarchy (standard approach)
|
|
4131
|
+
var api2004 = findAPIInFrameHierarchy('API_1484_11', 10);
|
|
4132
|
+
if (api2004) return { api: api2004.api, type: '2004', source: 'parent-chain level ' + api2004.level };
|
|
4133
|
+
var api12 = findAPIInFrameHierarchy('API', 10);
|
|
4134
|
+
if (api12) return { api: api12.api, type: '1.2', source: 'parent-chain level ' + api12.level };
|
|
4135
|
+
|
|
4136
|
+
// 2. Check window.opener and its parent hierarchy (LMS opens content in popup)
|
|
4137
|
+
try {
|
|
4138
|
+
if (window.opener && window.opener !== window) {
|
|
4139
|
+
// Direct check on opener
|
|
4140
|
+
if (window.opener.API_1484_11) return { api: window.opener.API_1484_11, type: '2004', source: 'window.opener' };
|
|
4141
|
+
if (window.opener.API) return { api: window.opener.API, type: '1.2', source: 'window.opener' };
|
|
4142
|
+
// Check opener's parent chain
|
|
4143
|
+
var openerWin = window.opener;
|
|
4144
|
+
var openerLevel = 0;
|
|
4145
|
+
while (openerLevel < 10) {
|
|
4146
|
+
try {
|
|
4147
|
+
if (openerWin.API_1484_11) return { api: openerWin.API_1484_11, type: '2004', source: 'opener-chain level ' + openerLevel };
|
|
4148
|
+
if (openerWin.API) return { api: openerWin.API, type: '1.2', source: 'opener-chain level ' + openerLevel };
|
|
4149
|
+
if (openerWin.parent && openerWin.parent !== openerWin) { openerWin = openerWin.parent; openerLevel++; }
|
|
4150
|
+
else break;
|
|
4151
|
+
} catch(e) { break; }
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
} catch(e) { /* cross-origin opener */ }
|
|
4155
|
+
|
|
4156
|
+
// 3. Check for global LMS functions (Bravais/Xyleme mock API)
|
|
4157
|
+
try {
|
|
4158
|
+
if (typeof window.LMSInitialize === 'function') {
|
|
4159
|
+
return { api: { LMSInitialize: window.LMSInitialize, LMSGetValue: window.LMSGetValue, LMSSetValue: window.LMSSetValue, LMSCommit: window.LMSCommit, LMSFinish: window.LMSFinish, LMSGetLastError: window.LMSGetLastError, LMSGetErrorString: window.LMSGetErrorString }, type: '1.2', source: 'global-functions' };
|
|
4160
|
+
}
|
|
4161
|
+
} catch(e) {}
|
|
4162
|
+
try {
|
|
4163
|
+
if (window.parent && window.parent !== window && typeof window.parent.LMSInitialize === 'function') {
|
|
4164
|
+
return { api: { LMSInitialize: window.parent.LMSInitialize, LMSGetValue: window.parent.LMSGetValue, LMSSetValue: window.parent.LMSSetValue, LMSCommit: window.parent.LMSCommit, LMSFinish: window.parent.LMSFinish, LMSGetLastError: window.parent.LMSGetLastError, LMSGetErrorString: window.parent.LMSGetErrorString }, type: '1.2', source: 'parent-global-functions' };
|
|
4165
|
+
}
|
|
4166
|
+
} catch(e) {}
|
|
4167
|
+
|
|
4168
|
+
return null;
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
function onScormApiFound(result, pollNum) {
|
|
4172
|
+
if (scormResolved) return;
|
|
4173
|
+
scormResolved = true;
|
|
4174
|
+
|
|
4175
|
+
LRS.scormApi = result.api;
|
|
4176
|
+
LRS.scormApiFound = true;
|
|
4177
|
+
LRS.scormApiType = result.type;
|
|
4178
|
+
|
|
4179
|
+
// Read learner_id for diagnostics
|
|
4180
|
+
var scormLearnerId = 'n/a', scormLearnerName = 'n/a';
|
|
4181
|
+
try {
|
|
4182
|
+
if (result.type === '2004') {
|
|
4183
|
+
scormLearnerId = result.api.GetValue('cmi.learner_id');
|
|
4184
|
+
scormLearnerName = result.api.GetValue('cmi.learner_name');
|
|
4185
|
+
} else {
|
|
4186
|
+
scormLearnerId = result.api.LMSGetValue('cmi.core.student_id');
|
|
4187
|
+
scormLearnerName = result.api.LMSGetValue('cmi.core.student_name');
|
|
4188
|
+
}
|
|
4189
|
+
} catch(e) { scormLearnerId = 'error'; scormLearnerName = 'error'; }
|
|
4190
|
+
console.info('[PA-LRS] SCORM API found (poll ' + pollNum + ', source=' + result.source +
|
|
4191
|
+
', type=' + result.type + '): learner_id=' + scormLearnerId + ', learner_name=' + scormLearnerName);
|
|
4192
|
+
|
|
4193
|
+
// refreshActor re-reads learner_id from SCORM and runs employee lookup
|
|
4194
|
+
LRS.refreshActor(function(refreshedActor) {
|
|
4195
|
+
if (window.console && window.console.info) {
|
|
4196
|
+
console.info('[PA-LRS] Actor resolved (after SCORM wait, poll ' + pollNum + '): name=' +
|
|
4197
|
+
(refreshedActor ? refreshedActor.name : 'none') +
|
|
4198
|
+
', mbox=' + (refreshedActor ? refreshedActor.mbox : 'none') +
|
|
4199
|
+
', account=' + (refreshedActor && refreshedActor.account ? refreshedActor.account.name : 'none'));
|
|
4200
|
+
}
|
|
4201
|
+
actorReady = true;
|
|
4202
|
+
tryLaunchEvents();
|
|
4203
|
+
});
|
|
4204
|
+
}
|
|
4205
|
+
|
|
4206
|
+
var scormPollTimer = setInterval(function() {
|
|
4207
|
+
if (scormResolved) { clearInterval(scormPollTimer); return; }
|
|
4208
|
+
scormPollCount++;
|
|
4209
|
+
|
|
4210
|
+
var result = findScormApiAnywhere();
|
|
4211
|
+
|
|
4212
|
+
if (result) {
|
|
4213
|
+
clearInterval(scormPollTimer);
|
|
4214
|
+
onScormApiFound(result, scormPollCount);
|
|
4215
|
+
} else if (scormPollCount >= scormMaxPolls) {
|
|
4216
|
+
clearInterval(scormPollTimer);
|
|
4217
|
+
log('SCORM API not found after ' + scormMaxPolls + 's, proceeding with Unknown Learner');
|
|
4218
|
+
if (window.console && window.console.info) {
|
|
4219
|
+
console.info('[PA-LRS] Actor resolved (timeout ' + scormMaxPolls + 's): name=' + (actor ? actor.name : 'none') +
|
|
4220
|
+
', account=' + (actor && actor.account ? actor.account.name : 'none'));
|
|
4221
|
+
}
|
|
4222
|
+
actorReady = true;
|
|
4223
|
+
tryLaunchEvents();
|
|
4224
|
+
}
|
|
4225
|
+
}, 1000);
|
|
4226
|
+
} else {
|
|
4227
|
+
// Actor is valid - proceed immediately
|
|
4228
|
+
if (window.console && window.console.info) {
|
|
4229
|
+
console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
|
|
4230
|
+
', mbox=' + (actor ? actor.mbox : 'none') +
|
|
4231
|
+
', account=' + (actor && actor.account ? actor.account.name : 'none'));
|
|
4232
|
+
}
|
|
4233
|
+
actorReady = true;
|
|
4234
|
+
tryLaunchEvents();
|
|
4118
4235
|
}
|
|
4119
|
-
tryLaunchEvents();
|
|
4120
4236
|
});
|
|
4121
4237
|
} else {
|
|
4122
4238
|
warn('Bridge setup failed - operating in offline mode');
|
|
@@ -4239,32 +4355,6 @@ function generateLrsBridgeCode(options) {
|
|
|
4239
4355
|
}, 1000);
|
|
4240
4356
|
}
|
|
4241
4357
|
|
|
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
4358
|
log('LRS bridge setup complete');
|
|
4269
4359
|
}
|
|
4270
4360
|
|