@patch-adams/core 1.4.18 → 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 */
@@ -414,6 +416,12 @@ function generateLrsBridgeCode(options) {
414
416
  'use strict';
415
417
 
416
418
  var DEBUG = ${options.debug};
419
+ // Allow URL-based debug toggle: ?pa_debug=1 or #pa_debug
420
+ try {
421
+ if (window.location.search.indexOf('pa_debug') > -1 || window.location.hash.indexOf('pa_debug') > -1) {
422
+ DEBUG = true;
423
+ }
424
+ } catch (e) {}
417
425
  var TRACK_MEDIA = ${options.trackMedia};
418
426
  var TRACK_NAVIGATION = ${options.trackNavigation};
419
427
  var TRACK_QUIZZES = ${options.trackQuizzes};
@@ -1272,12 +1280,32 @@ function generateLrsBridgeCode(options) {
1272
1280
  return;
1273
1281
  }
1274
1282
 
1275
- // Cache check
1283
+ // In-memory cache check
1276
1284
  if (employeeLookupFetched && employeeLookupData) {
1277
1285
  callback(employeeLookupData);
1278
1286
  return;
1279
1287
  }
1280
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
+
1281
1309
  // Build URL: endpoint should end with ? or include query param structure
1282
1310
  var apiUrl = EMPLOYEE_API_ENDPOINT + (EMPLOYEE_API_ENDPOINT.indexOf('?') >= 0 ? '&' : '?') + 'q=' + encodeURIComponent(employeeId);
1283
1311
  log('Fetching employee data from:', apiUrl);
@@ -1309,6 +1337,14 @@ function generateLrsBridgeCode(options) {
1309
1337
  employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId
1310
1338
  };
1311
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 */ }
1312
1348
  callback(employeeLookupData);
1313
1349
  } else {
1314
1350
  callback(null);
@@ -2785,6 +2821,17 @@ function generateLrsBridgeCode(options) {
2785
2821
  function sendStatement(statement) {
2786
2822
  log('Sending statement:', statement.verb.display['en-US'] || statement.verb.id, statement);
2787
2823
 
2824
+ // Log first statement visibly (not gated by DEBUG) for production diagnostics
2825
+ if (LRS.stats.statementsSent === 0 && LRS.stats.statementsFailed === 0 && LRS.stats.statementsQueued === 0) {
2826
+ if (window.console && window.console.info) {
2827
+ var verb = statement.verb.display ? (statement.verb.display['en-US'] || statement.verb.id) : statement.verb.id;
2828
+ console.info('[PA-LRS] First statement: verb=' + verb +
2829
+ ', endpoint=' + (LRS_ENDPOINT || 'NONE') +
2830
+ ', proxy=' + (LRS_PROXY_ENDPOINT ? 'yes' : 'no') +
2831
+ ', mode=' + LRS.mode);
2832
+ }
2833
+ }
2834
+
2788
2835
  // Store in event log
2789
2836
  LRS.eventLog.push({
2790
2837
  statement: statement,
@@ -3964,6 +4011,15 @@ function generateLrsBridgeCode(options) {
3964
4011
  LRS.mode = 'offline';
3965
4012
  }
3966
4013
 
4014
+ // Always-visible bridge summary (not gated by DEBUG)
4015
+ // This ensures diagnostics are available even in production builds
4016
+ if (window.console && window.console.info) {
4017
+ console.info('[PA-LRS] Bridge: mode=' + LRS.mode +
4018
+ ', endpoint=' + (LRS_ENDPOINT ? LRS_ENDPOINT.substring(0, 30) + '...' : 'NONE') +
4019
+ ', proxy=' + (LRS_PROXY_ENDPOINT ? 'yes' : 'no') +
4020
+ ', actor=' + (LRS.actor ? (LRS.actor.name || 'anonymous') : 'none'));
4021
+ }
4022
+
3967
4023
  // Set up event interceptors
3968
4024
  setupMediaInterceptors();
3969
4025
  setupNavigationInterceptors();
@@ -4237,7 +4293,8 @@ function buildJsBeforeOptions(config, metadata) {
4237
4293
  courseHomepage: lrsBridgeConfig.courseHomepage,
4238
4294
  autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4239
4295
  lrsAuth: lrsBridgeConfig.lrsAuth,
4240
- lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint
4296
+ lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint,
4297
+ employeeApiEndpoint: lrsBridgeConfig.employeeApiEndpoint
4241
4298
  };
4242
4299
  return {
4243
4300
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,