@patch-adams/core 1.4.25 → 1.4.27
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 +82 -39
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +82 -39
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +82 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +82 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -272,13 +272,13 @@ html.${htmlClass}.${loadingClass} body {
|
|
|
272
272
|
var link = loadCSSSync(REMOTE_URL);
|
|
273
273
|
|
|
274
274
|
link.onerror = function() {
|
|
275
|
-
console.warn('[
|
|
275
|
+
console.warn('[PA-Patcher] CSS before failed to load from remote, using local fallback');
|
|
276
276
|
document.head.removeChild(link);
|
|
277
277
|
loadCSSSync(LOCAL_PATH);
|
|
278
278
|
};
|
|
279
279
|
|
|
280
280
|
link.onload = function() {
|
|
281
|
-
console.log('[
|
|
281
|
+
console.log('[PA-Patcher] CSS before loaded from remote:', REMOTE_URL);
|
|
282
282
|
};
|
|
283
283
|
})();
|
|
284
284
|
</script>`;
|
|
@@ -332,7 +332,7 @@ function generateCssAfterLoader(options) {
|
|
|
332
332
|
if (loaded) return;
|
|
333
333
|
loaded = true;
|
|
334
334
|
clearTimeout(timeoutId);
|
|
335
|
-
console.log('[
|
|
335
|
+
console.log('[PA-Patcher] CSS after loaded from remote:', REMOTE_URL);
|
|
336
336
|
},
|
|
337
337
|
function() {
|
|
338
338
|
if (loaded) return;
|
|
@@ -346,7 +346,7 @@ function generateCssAfterLoader(options) {
|
|
|
346
346
|
timeoutId = setTimeout(function() {
|
|
347
347
|
if (loaded) return;
|
|
348
348
|
loaded = true;
|
|
349
|
-
console.warn('[
|
|
349
|
+
console.warn('[PA-Patcher] CSS after timed out, using local fallback');
|
|
350
350
|
if (remoteLink.parentNode) {
|
|
351
351
|
document.head.removeChild(remoteLink);
|
|
352
352
|
}
|
|
@@ -358,10 +358,10 @@ function generateCssAfterLoader(options) {
|
|
|
358
358
|
loadCSS(
|
|
359
359
|
LOCAL_PATH,
|
|
360
360
|
function() {
|
|
361
|
-
console.log('[
|
|
361
|
+
console.log('[PA-Patcher] CSS after loaded from local fallback:', LOCAL_PATH);
|
|
362
362
|
},
|
|
363
363
|
function() {
|
|
364
|
-
console.error('[
|
|
364
|
+
console.error('[PA-Patcher] CSS after failed to load from both remote and local');
|
|
365
365
|
}
|
|
366
366
|
);
|
|
367
367
|
}
|
|
@@ -1344,7 +1344,9 @@ function generateLrsBridgeCode(options) {
|
|
|
1344
1344
|
((employee.fname || employee.firstName || '') + ' ' + (employee.lname || employee.lastName || '')).trim(),
|
|
1345
1345
|
firstName: employee.fname || employee.firstName || employee.first_name,
|
|
1346
1346
|
lastName: employee.lname || employee.lastName || employee.last_name,
|
|
1347
|
-
employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId
|
|
1347
|
+
employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId,
|
|
1348
|
+
bravaisUserId: employee.bravaisUserId || null,
|
|
1349
|
+
tenantUrl: employee.tenantUrl || null
|
|
1348
1350
|
};
|
|
1349
1351
|
log('Parsed employee data:', employeeLookupData);
|
|
1350
1352
|
// Persist to localStorage for cross-session caching
|
|
@@ -1418,6 +1420,16 @@ function generateLrsBridgeCode(options) {
|
|
|
1418
1420
|
if (employeeData.name && (!actor.name || actor.name === 'Unknown Learner')) {
|
|
1419
1421
|
actor.name = employeeData.name;
|
|
1420
1422
|
}
|
|
1423
|
+
|
|
1424
|
+
// Update account with Bravais user ID and tenant URL if available
|
|
1425
|
+
if (employeeData.bravaisUserId) {
|
|
1426
|
+
var originalAccountName = actor.account ? actor.account.name : null;
|
|
1427
|
+
actor.account = {
|
|
1428
|
+
name: employeeData.bravaisUserId,
|
|
1429
|
+
homePage: employeeData.tenantUrl || (actor.account && actor.account.homePage) || window.location.origin
|
|
1430
|
+
};
|
|
1431
|
+
log('Updated actor account: bravaisUserId=' + employeeData.bravaisUserId + ', homePage=' + actor.account.homePage + ' (was: ' + originalAccountName + ')');
|
|
1432
|
+
}
|
|
1421
1433
|
}
|
|
1422
1434
|
callback(actor);
|
|
1423
1435
|
});
|
|
@@ -2082,7 +2094,7 @@ function generateLrsBridgeCode(options) {
|
|
|
2082
2094
|
tenantHomepage: null // https://{tenant}.bravais.com format
|
|
2083
2095
|
};
|
|
2084
2096
|
|
|
2085
|
-
// 0. Use baked-in GUIDs from
|
|
2097
|
+
// 0. Use baked-in GUIDs from PA-Patcher config (highest priority - set at wrap time)
|
|
2086
2098
|
if (DOCUMENT_GUID) {
|
|
2087
2099
|
info.guid = DOCUMENT_GUID;
|
|
2088
2100
|
info.id = 'http://xyleme.com/bravais/document/' + DOCUMENT_GUID;
|
|
@@ -2591,6 +2603,11 @@ function generateLrsBridgeCode(options) {
|
|
|
2591
2603
|
// Publish index (default to 1)
|
|
2592
2604
|
ctx.extensions['publishIndex'] = (LRS.courseInfo && LRS.courseInfo.publishIndex) ? LRS.courseInfo.publishIndex : 1;
|
|
2593
2605
|
|
|
2606
|
+
// Employee ID from employee lookup (if available)
|
|
2607
|
+
if (employeeLookupData && employeeLookupData.employeeId) {
|
|
2608
|
+
ctx.extensions['employeeId'] = employeeLookupData.employeeId;
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2594
2611
|
// Xyleme schema version and PII flag
|
|
2595
2612
|
ctx.extensions['http://xyleme.com/bravais/extensions/statement-schema'] = 'xyleme_10';
|
|
2596
2613
|
ctx.extensions['http://xyleme.com/bravais/extensions/protect_pii'] = false;
|
|
@@ -4073,6 +4090,19 @@ function generateLrsBridgeCode(options) {
|
|
|
4073
4090
|
// Setup connection
|
|
4074
4091
|
var bridgeReady = setupBridge();
|
|
4075
4092
|
|
|
4093
|
+
// Track async readiness: both actor and doc metadata must resolve before sending statements
|
|
4094
|
+
var actorReady = false;
|
|
4095
|
+
var docReady = false;
|
|
4096
|
+
var launchEventsSent = false;
|
|
4097
|
+
|
|
4098
|
+
function tryLaunchEvents() {
|
|
4099
|
+
if (launchEventsSent) return;
|
|
4100
|
+
if (!actorReady || !docReady) return;
|
|
4101
|
+
launchEventsSent = true;
|
|
4102
|
+
log('Both actor and doc metadata ready, sending launch events');
|
|
4103
|
+
setTimeout(sendLaunchEvents, 50);
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4076
4106
|
if (bridgeReady) {
|
|
4077
4107
|
LRS.initialized = true;
|
|
4078
4108
|
|
|
@@ -4083,14 +4113,23 @@ function generateLrsBridgeCode(options) {
|
|
|
4083
4113
|
log('Actor:', LRS.actor);
|
|
4084
4114
|
log('Course:', LRS.courseInfo);
|
|
4085
4115
|
|
|
4086
|
-
// Then try async actor extraction
|
|
4087
|
-
//
|
|
4116
|
+
// Then try async actor extraction (employee lookup, Bravais session)
|
|
4117
|
+
// Launch events will NOT be sent until this completes
|
|
4088
4118
|
extractActorAsync(function(actor) {
|
|
4089
4119
|
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'));
|
|
4126
|
+
}
|
|
4127
|
+
tryLaunchEvents();
|
|
4090
4128
|
});
|
|
4091
4129
|
} else {
|
|
4092
4130
|
warn('Bridge setup failed - operating in offline mode');
|
|
4093
4131
|
LRS.mode = 'offline';
|
|
4132
|
+
actorReady = true; // No actor to wait for in offline mode
|
|
4094
4133
|
}
|
|
4095
4134
|
|
|
4096
4135
|
// Always-visible bridge summary (not gated by DEBUG)
|
|
@@ -4135,13 +4174,17 @@ function generateLrsBridgeCode(options) {
|
|
|
4135
4174
|
}
|
|
4136
4175
|
}
|
|
4137
4176
|
|
|
4138
|
-
function
|
|
4177
|
+
function onDocReady() {
|
|
4178
|
+
docReady = true;
|
|
4179
|
+
tryLaunchEvents();
|
|
4180
|
+
}
|
|
4181
|
+
|
|
4182
|
+
function fetchDocDataAndReady(docId) {
|
|
4139
4183
|
fetchDocumentMetadata(docId, function(docData) {
|
|
4140
4184
|
if (docData) {
|
|
4141
4185
|
updateCourseInfoFromApi(docData);
|
|
4142
4186
|
}
|
|
4143
|
-
|
|
4144
|
-
setTimeout(sendLaunchEvents, 100);
|
|
4187
|
+
onDocReady();
|
|
4145
4188
|
});
|
|
4146
4189
|
}
|
|
4147
4190
|
|
|
@@ -4161,20 +4204,20 @@ function generateLrsBridgeCode(options) {
|
|
|
4161
4204
|
} else {
|
|
4162
4205
|
warn('Could not fetch document data from shared API - statements may fail aggregation');
|
|
4163
4206
|
}
|
|
4164
|
-
|
|
4207
|
+
onDocReady();
|
|
4165
4208
|
});
|
|
4166
4209
|
} else if (documentId) {
|
|
4167
4210
|
// No shared link token, try with extracted document ID (requires auth)
|
|
4168
4211
|
log('No shared link token, fetching document data with ID:', documentId);
|
|
4169
|
-
|
|
4212
|
+
fetchDocDataAndReady(documentId);
|
|
4170
4213
|
} else {
|
|
4171
4214
|
// No identifiers available
|
|
4172
4215
|
warn('No shared link token or document ID - statements may fail aggregation');
|
|
4173
|
-
|
|
4216
|
+
onDocReady();
|
|
4174
4217
|
}
|
|
4175
4218
|
} else {
|
|
4176
|
-
// Already have GUID
|
|
4177
|
-
|
|
4219
|
+
// Already have GUID
|
|
4220
|
+
onDocReady();
|
|
4178
4221
|
}
|
|
4179
4222
|
|
|
4180
4223
|
// Setup beforeunload to send terminated
|
|
@@ -4259,7 +4302,7 @@ ${courseLines.join("\n")}
|
|
|
4259
4302
|
},` : "";
|
|
4260
4303
|
return `<!-- === PATCH-ADAMS: JS BEFORE (blocking) === -->
|
|
4261
4304
|
<script data-pa="js-before-loader">
|
|
4262
|
-
// Initialize
|
|
4305
|
+
// Initialize PA-Patcher global namespace IMMEDIATELY (before IIFE)
|
|
4263
4306
|
window.pa_patcher = window.pa_patcher || {
|
|
4264
4307
|
version: '1.0.25',
|
|
4265
4308
|
htmlClass: '${htmlClass}',
|
|
@@ -4304,7 +4347,7 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
4304
4347
|
if (isExtensionError(event.reason)) {
|
|
4305
4348
|
event.preventDefault();
|
|
4306
4349
|
event.stopImmediatePropagation();
|
|
4307
|
-
console.debug('[
|
|
4350
|
+
console.debug('[PA-Patcher] Suppressed browser extension error:', event.reason);
|
|
4308
4351
|
return false;
|
|
4309
4352
|
}
|
|
4310
4353
|
}, true);
|
|
@@ -4314,7 +4357,7 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
4314
4357
|
if (isExtensionError(event.error || event.message)) {
|
|
4315
4358
|
event.preventDefault();
|
|
4316
4359
|
event.stopImmediatePropagation();
|
|
4317
|
-
console.debug('[
|
|
4360
|
+
console.debug('[PA-Patcher] Suppressed browser extension error:', event.message);
|
|
4318
4361
|
return false;
|
|
4319
4362
|
}
|
|
4320
4363
|
}, true);
|
|
@@ -4339,17 +4382,17 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
4339
4382
|
var script = loadJSSync(REMOTE_URL);
|
|
4340
4383
|
|
|
4341
4384
|
script.onerror = function() {
|
|
4342
|
-
console.warn('[
|
|
4385
|
+
console.warn('[PA-Patcher] JS before failed to load from remote, using local fallback');
|
|
4343
4386
|
document.head.removeChild(script);
|
|
4344
4387
|
var fallback = loadJSSync(LOCAL_PATH);
|
|
4345
4388
|
fallback.onload = function() {
|
|
4346
4389
|
if (window.pa_patcher && window.pa_patcher.loaded) {
|
|
4347
4390
|
window.pa_patcher.loaded.jsBefore = true;
|
|
4348
4391
|
}
|
|
4349
|
-
console.log('[
|
|
4392
|
+
console.log('[PA-Patcher] JS before loaded from local fallback:', LOCAL_PATH);
|
|
4350
4393
|
};
|
|
4351
4394
|
fallback.onerror = function() {
|
|
4352
|
-
console.error('[
|
|
4395
|
+
console.error('[PA-Patcher] JS before failed to load from both remote and local');
|
|
4353
4396
|
};
|
|
4354
4397
|
};
|
|
4355
4398
|
|
|
@@ -4357,7 +4400,7 @@ window.pa_patcher = window.pa_patcher || {
|
|
|
4357
4400
|
if (window.pa_patcher && window.pa_patcher.loaded) {
|
|
4358
4401
|
window.pa_patcher.loaded.jsBefore = true;
|
|
4359
4402
|
}
|
|
4360
|
-
console.log('[
|
|
4403
|
+
console.log('[PA-Patcher] JS before loaded from remote:', REMOTE_URL);
|
|
4361
4404
|
};
|
|
4362
4405
|
})();
|
|
4363
4406
|
${lrsBridgeCode}
|
|
@@ -4428,14 +4471,14 @@ function generateJsAfterLoader(options) {
|
|
|
4428
4471
|
if (window.pa_patcher && window.pa_patcher.loaded) {
|
|
4429
4472
|
window.pa_patcher.loaded.jsAfter = true;
|
|
4430
4473
|
}
|
|
4431
|
-
console.log('[
|
|
4474
|
+
console.log('[PA-Patcher] Loading complete, content revealed');
|
|
4432
4475
|
|
|
4433
4476
|
// Add visual badge to indicate patching is active
|
|
4434
4477
|
var badge = document.createElement('div');
|
|
4435
4478
|
badge.setAttribute('data-pa', 'badge');
|
|
4436
4479
|
badge.style.cssText = 'position:fixed;bottom:10px;right:10px;background:#4CAF50;color:white;padding:4px 8px;border-radius:4px;font-size:11px;font-family:sans-serif;z-index:999999;opacity:0.8;cursor:pointer;';
|
|
4437
4480
|
badge.textContent = 'PA';
|
|
4438
|
-
badge.title = '
|
|
4481
|
+
badge.title = 'PA-Patcher Active';
|
|
4439
4482
|
badge.onclick = function() { badge.style.display = 'none'; };
|
|
4440
4483
|
document.body.appendChild(badge);
|
|
4441
4484
|
}
|
|
@@ -4451,7 +4494,7 @@ function generateJsAfterLoader(options) {
|
|
|
4451
4494
|
if (loaded) return;
|
|
4452
4495
|
loaded = true;
|
|
4453
4496
|
clearTimeout(timeoutId);
|
|
4454
|
-
console.log('[
|
|
4497
|
+
console.log('[PA-Patcher] JS after loaded from remote:', REMOTE_URL);
|
|
4455
4498
|
// Give the script a moment to execute, then remove loading class
|
|
4456
4499
|
setTimeout(removeLoadingClass, 50);
|
|
4457
4500
|
},
|
|
@@ -4467,7 +4510,7 @@ function generateJsAfterLoader(options) {
|
|
|
4467
4510
|
timeoutId = setTimeout(function() {
|
|
4468
4511
|
if (loaded) return;
|
|
4469
4512
|
loaded = true;
|
|
4470
|
-
console.warn('[
|
|
4513
|
+
console.warn('[PA-Patcher] JS after timed out, using local fallback');
|
|
4471
4514
|
if (remoteScript.parentNode) {
|
|
4472
4515
|
document.body.removeChild(remoteScript);
|
|
4473
4516
|
}
|
|
@@ -4479,11 +4522,11 @@ function generateJsAfterLoader(options) {
|
|
|
4479
4522
|
loadJS(
|
|
4480
4523
|
LOCAL_PATH,
|
|
4481
4524
|
function() {
|
|
4482
|
-
console.log('[
|
|
4525
|
+
console.log('[PA-Patcher] JS after loaded from local fallback:', LOCAL_PATH);
|
|
4483
4526
|
setTimeout(removeLoadingClass, 50);
|
|
4484
4527
|
},
|
|
4485
4528
|
function() {
|
|
4486
|
-
console.error('[
|
|
4529
|
+
console.error('[PA-Patcher] JS after failed to load from both remote and local');
|
|
4487
4530
|
// Still remove loading class so content is visible even if JS fails
|
|
4488
4531
|
removeLoadingClass();
|
|
4489
4532
|
}
|
|
@@ -4943,7 +4986,7 @@ var ManifestUpdater = class {
|
|
|
4943
4986
|
const resourceClosePattern = /(\s*)<\/resource>/i;
|
|
4944
4987
|
const match = xmlContent.match(resourceClosePattern);
|
|
4945
4988
|
if (!match) {
|
|
4946
|
-
console.warn("[
|
|
4989
|
+
console.warn("[PA-Patcher] Could not find </resource> tag in imsmanifest.xml");
|
|
4947
4990
|
return [];
|
|
4948
4991
|
}
|
|
4949
4992
|
const updatedXml = xmlContent.replace(
|
|
@@ -4955,7 +4998,7 @@ $1</resource>`
|
|
|
4955
4998
|
zip.updateFile("imsmanifest.xml", Buffer.from(updatedXml, "utf-8"));
|
|
4956
4999
|
return ["imsmanifest.xml"];
|
|
4957
5000
|
} catch (error) {
|
|
4958
|
-
console.error("[
|
|
5001
|
+
console.error("[PA-Patcher] Failed to update imsmanifest.xml:", error);
|
|
4959
5002
|
return [];
|
|
4960
5003
|
}
|
|
4961
5004
|
}
|
|
@@ -5587,7 +5630,7 @@ ${js.after}
|
|
|
5587
5630
|
var pluginRegistry = new PluginRegistry();
|
|
5588
5631
|
|
|
5589
5632
|
// src/patcher/index.ts
|
|
5590
|
-
var DEFAULT_CSS_BEFORE = `/*
|
|
5633
|
+
var DEFAULT_CSS_BEFORE = `/* PA-Patcher: CSS Before (blocking)
|
|
5591
5634
|
* This file loads at the start of <head> and blocks rendering.
|
|
5592
5635
|
* Use it to hide content and prevent flash of unstyled content.
|
|
5593
5636
|
*
|
|
@@ -5597,7 +5640,7 @@ var DEFAULT_CSS_BEFORE = `/* Patch-Adams: CSS Before (blocking)
|
|
|
5597
5640
|
* }
|
|
5598
5641
|
*/
|
|
5599
5642
|
`;
|
|
5600
|
-
var DEFAULT_CSS_AFTER = `/*
|
|
5643
|
+
var DEFAULT_CSS_AFTER = `/* PA-Patcher: CSS After (async)
|
|
5601
5644
|
* This file loads at the end of <head> with remote fallback.
|
|
5602
5645
|
* Use it for style overrides that take precedence over Rise styles.
|
|
5603
5646
|
*
|
|
@@ -5607,7 +5650,7 @@ var DEFAULT_CSS_AFTER = `/* Patch-Adams: CSS After (async)
|
|
|
5607
5650
|
* }
|
|
5608
5651
|
*/
|
|
5609
5652
|
`;
|
|
5610
|
-
var DEFAULT_JS_BEFORE = `//
|
|
5653
|
+
var DEFAULT_JS_BEFORE = `// PA-Patcher: JS Before (blocking)
|
|
5611
5654
|
// This file loads at the start of <head> and blocks rendering.
|
|
5612
5655
|
// Use it for setup, API interception, and preparing globals.
|
|
5613
5656
|
//
|
|
@@ -5617,9 +5660,9 @@ var DEFAULT_JS_BEFORE = `// Patch-Adams: JS Before (blocking)
|
|
|
5617
5660
|
// analytics: true
|
|
5618
5661
|
// };
|
|
5619
5662
|
|
|
5620
|
-
console.log('[
|
|
5663
|
+
console.log('[PA-Patcher] JS Before loaded');
|
|
5621
5664
|
`;
|
|
5622
|
-
var DEFAULT_JS_AFTER = `//
|
|
5665
|
+
var DEFAULT_JS_AFTER = `// PA-Patcher: JS After (async)
|
|
5623
5666
|
// This file loads at the end of <body> with remote fallback.
|
|
5624
5667
|
// Use it for DOM manipulation after Rise has initialized.
|
|
5625
5668
|
//
|
|
@@ -5631,7 +5674,7 @@ var DEFAULT_JS_AFTER = `// Patch-Adams: JS After (async)
|
|
|
5631
5674
|
// // Your modifications here
|
|
5632
5675
|
// });
|
|
5633
5676
|
|
|
5634
|
-
console.log('[
|
|
5677
|
+
console.log('[PA-Patcher] JS After loaded');
|
|
5635
5678
|
`;
|
|
5636
5679
|
var Patcher = class {
|
|
5637
5680
|
config;
|