@patch-adams/core 1.4.19 → 1.4.20

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
@@ -43,7 +43,9 @@ var LrsBridgeConfigSchema = zod.z.object({
43
43
  /** Basic auth credentials for LRS (Base64 encoded "username:password") - used when no cookie session exists */
44
44
  lrsAuth: zod.z.string().optional(),
45
45
  /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
46
- lrsProxyEndpoint: zod.z.string().optional()
46
+ lrsProxyEndpoint: zod.z.string().optional(),
47
+ /** Employee API endpoint URL for user identity lookup (e.g., https://node.example.com/admin_api/users/employees/) */
48
+ employeeApiEndpoint: zod.z.string().optional()
47
49
  });
48
50
  var BlockingAssetConfigSchema = zod.z.object({
49
51
  /** Filename for the asset */
@@ -1278,12 +1280,32 @@ function generateLrsBridgeCode(options) {
1278
1280
  return;
1279
1281
  }
1280
1282
 
1281
- // Cache check
1283
+ // In-memory cache check
1282
1284
  if (employeeLookupFetched && employeeLookupData) {
1283
1285
  callback(employeeLookupData);
1284
1286
  return;
1285
1287
  }
1286
1288
 
1289
+ // localStorage cache check (persists across page loads / sessions)
1290
+ var cacheKey = 'pa_employee_' + employeeId;
1291
+ try {
1292
+ var cached = localStorage.getItem(cacheKey);
1293
+ if (cached) {
1294
+ var parsed = JSON.parse(cached);
1295
+ // TTL: 7 days = 604800000 ms
1296
+ if (parsed.timestamp && (Date.now() - parsed.timestamp) < 604800000) {
1297
+ log('Employee data from localStorage cache');
1298
+ employeeLookupData = parsed;
1299
+ employeeLookupFetched = true;
1300
+ callback(parsed);
1301
+ return;
1302
+ }
1303
+ localStorage.removeItem(cacheKey);
1304
+ }
1305
+ } catch (e) {
1306
+ // localStorage unavailable (private browsing, iframe restrictions)
1307
+ }
1308
+
1287
1309
  // Build URL: endpoint should end with ? or include query param structure
1288
1310
  var apiUrl = EMPLOYEE_API_ENDPOINT + (EMPLOYEE_API_ENDPOINT.indexOf('?') >= 0 ? '&' : '?') + 'q=' + encodeURIComponent(employeeId);
1289
1311
  log('Fetching employee data from:', apiUrl);
@@ -1315,6 +1337,14 @@ function generateLrsBridgeCode(options) {
1315
1337
  employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId
1316
1338
  };
1317
1339
  log('Parsed employee data:', employeeLookupData);
1340
+ // Persist to localStorage for cross-session caching
1341
+ try {
1342
+ var cacheData = {};
1343
+ for (var k in employeeLookupData) { if (employeeLookupData.hasOwnProperty(k)) cacheData[k] = employeeLookupData[k]; }
1344
+ cacheData.timestamp = Date.now();
1345
+ localStorage.setItem(cacheKey, JSON.stringify(cacheData));
1346
+ log('Employee data cached in localStorage');
1347
+ } catch (e) { /* localStorage unavailable */ }
1318
1348
  callback(employeeLookupData);
1319
1349
  } else {
1320
1350
  callback(null);
@@ -4263,7 +4293,8 @@ function buildJsBeforeOptions(config, metadata) {
4263
4293
  courseHomepage: lrsBridgeConfig.courseHomepage,
4264
4294
  autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4265
4295
  lrsAuth: lrsBridgeConfig.lrsAuth,
4266
- lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4296
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint,
4297
+ employeeApiEndpoint: lrsBridgeConfig.employeeApiEndpoint
4267
4298
  };
4268
4299
  return {
4269
4300
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,