@patch-adams/core 1.4.19 → 1.4.21

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
@@ -382,7 +382,9 @@ var LrsBridgeConfigSchema = z.object({
382
382
  /** Basic auth credentials for LRS (Base64 encoded "username:password") - used when no cookie session exists */
383
383
  lrsAuth: z.string().optional(),
384
384
  /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
385
- lrsProxyEndpoint: z.string().optional()
385
+ lrsProxyEndpoint: z.string().optional(),
386
+ /** Employee API endpoint URL for user identity lookup (e.g., https://node.example.com/admin_api/users/employees/) */
387
+ employeeApiEndpoint: z.string().optional()
386
388
  });
387
389
  var BlockingAssetConfigSchema = z.object({
388
390
  /** Filename for the asset */
@@ -1603,12 +1605,32 @@ function generateLrsBridgeCode(options) {
1603
1605
  return;
1604
1606
  }
1605
1607
 
1606
- // Cache check
1608
+ // In-memory cache check
1607
1609
  if (employeeLookupFetched && employeeLookupData) {
1608
1610
  callback(employeeLookupData);
1609
1611
  return;
1610
1612
  }
1611
1613
 
1614
+ // localStorage cache check (persists across page loads / sessions)
1615
+ var cacheKey = 'pa_employee_' + employeeId;
1616
+ try {
1617
+ var cached = localStorage.getItem(cacheKey);
1618
+ if (cached) {
1619
+ var parsed = JSON.parse(cached);
1620
+ // TTL: 7 days = 604800000 ms
1621
+ if (parsed.timestamp && (Date.now() - parsed.timestamp) < 604800000) {
1622
+ log('Employee data from localStorage cache');
1623
+ employeeLookupData = parsed;
1624
+ employeeLookupFetched = true;
1625
+ callback(parsed);
1626
+ return;
1627
+ }
1628
+ localStorage.removeItem(cacheKey);
1629
+ }
1630
+ } catch (e) {
1631
+ // localStorage unavailable (private browsing, iframe restrictions)
1632
+ }
1633
+
1612
1634
  // Build URL: endpoint should end with ? or include query param structure
1613
1635
  var apiUrl = EMPLOYEE_API_ENDPOINT + (EMPLOYEE_API_ENDPOINT.indexOf('?') >= 0 ? '&' : '?') + 'q=' + encodeURIComponent(employeeId);
1614
1636
  log('Fetching employee data from:', apiUrl);
@@ -1640,6 +1662,14 @@ function generateLrsBridgeCode(options) {
1640
1662
  employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId
1641
1663
  };
1642
1664
  log('Parsed employee data:', employeeLookupData);
1665
+ // Persist to localStorage for cross-session caching
1666
+ try {
1667
+ var cacheData = {};
1668
+ for (var k in employeeLookupData) { if (employeeLookupData.hasOwnProperty(k)) cacheData[k] = employeeLookupData[k]; }
1669
+ cacheData.timestamp = Date.now();
1670
+ localStorage.setItem(cacheKey, JSON.stringify(cacheData));
1671
+ log('Employee data cached in localStorage');
1672
+ } catch (e) { /* localStorage unavailable */ }
1643
1673
  callback(employeeLookupData);
1644
1674
  } else {
1645
1675
  callback(null);
@@ -3584,6 +3614,34 @@ function generateLrsBridgeCode(options) {
3584
3614
  sendStatement(statement);
3585
3615
  };
3586
3616
 
3617
+ /**
3618
+ * Re-extract actor from SCORM after LMSInitialize has been called.
3619
+ * Call this from the SCORM wrapper after scormInit() succeeds,
3620
+ * because the bridge initializes in <head> before LMSInitialize runs.
3621
+ */
3622
+ LRS.refreshActor = function(callback) {
3623
+ log('refreshActor called - re-extracting from SCORM...');
3624
+ var previousName = LRS.actor ? LRS.actor.name : 'none';
3625
+
3626
+ // Re-run sync extraction (SCORM data should now be available)
3627
+ var newActor = extractActor();
3628
+
3629
+ if (isValidActor(newActor) && newActor.account && newActor.account.name !== 'unknown') {
3630
+ log('refreshActor: got valid actor:', newActor.name, newActor.account ? newActor.account.name : '');
3631
+ // Enhance with email lookup (async)
3632
+ extractActorAsync(function(enhancedActor) {
3633
+ if (window.console && window.console.info) {
3634
+ console.info('[PA-LRS] Actor refreshed: ' + previousName + ' -> ' + enhancedActor.name +
3635
+ (enhancedActor.mbox ? ' (' + enhancedActor.mbox + ')' : ''));
3636
+ }
3637
+ if (callback) callback(enhancedActor);
3638
+ });
3639
+ } else {
3640
+ log('refreshActor: no valid actor found after re-extraction');
3641
+ if (callback) callback(LRS.actor);
3642
+ }
3643
+ };
3644
+
3587
3645
  // Course terminated/exited
3588
3646
  LRS.courseTerminated = function() {
3589
3647
  // Calculate duration
@@ -4588,7 +4646,8 @@ function buildJsBeforeOptions(config, metadata) {
4588
4646
  courseHomepage: lrsBridgeConfig.courseHomepage,
4589
4647
  autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4590
4648
  lrsAuth: lrsBridgeConfig.lrsAuth,
4591
- lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4649
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint,
4650
+ employeeApiEndpoint: lrsBridgeConfig.employeeApiEndpoint
4592
4651
  };
4593
4652
  return {
4594
4653
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,