@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 CHANGED
@@ -622,13 +622,13 @@ html.${htmlClass}.${loadingClass} body {
622
622
  var link = loadCSSSync(REMOTE_URL);
623
623
 
624
624
  link.onerror = function() {
625
- console.warn('[Patch-Adams] CSS before failed to load from remote, using local fallback');
625
+ console.warn('[PA-Patcher] CSS before failed to load from remote, using local fallback');
626
626
  document.head.removeChild(link);
627
627
  loadCSSSync(LOCAL_PATH);
628
628
  };
629
629
 
630
630
  link.onload = function() {
631
- console.log('[Patch-Adams] CSS before loaded from remote:', REMOTE_URL);
631
+ console.log('[PA-Patcher] CSS before loaded from remote:', REMOTE_URL);
632
632
  };
633
633
  })();
634
634
  </script>`;
@@ -682,7 +682,7 @@ function generateCssAfterLoader(options) {
682
682
  if (loaded) return;
683
683
  loaded = true;
684
684
  clearTimeout(timeoutId);
685
- console.log('[Patch-Adams] CSS after loaded from remote:', REMOTE_URL);
685
+ console.log('[PA-Patcher] CSS after loaded from remote:', REMOTE_URL);
686
686
  },
687
687
  function() {
688
688
  if (loaded) return;
@@ -696,7 +696,7 @@ function generateCssAfterLoader(options) {
696
696
  timeoutId = setTimeout(function() {
697
697
  if (loaded) return;
698
698
  loaded = true;
699
- console.warn('[Patch-Adams] CSS after timed out, using local fallback');
699
+ console.warn('[PA-Patcher] CSS after timed out, using local fallback');
700
700
  if (remoteLink.parentNode) {
701
701
  document.head.removeChild(remoteLink);
702
702
  }
@@ -708,10 +708,10 @@ function generateCssAfterLoader(options) {
708
708
  loadCSS(
709
709
  LOCAL_PATH,
710
710
  function() {
711
- console.log('[Patch-Adams] CSS after loaded from local fallback:', LOCAL_PATH);
711
+ console.log('[PA-Patcher] CSS after loaded from local fallback:', LOCAL_PATH);
712
712
  },
713
713
  function() {
714
- console.error('[Patch-Adams] CSS after failed to load from both remote and local');
714
+ console.error('[PA-Patcher] CSS after failed to load from both remote and local');
715
715
  }
716
716
  );
717
717
  }
@@ -1676,7 +1676,9 @@ function generateLrsBridgeCode(options) {
1676
1676
  ((employee.fname || employee.firstName || '') + ' ' + (employee.lname || employee.lastName || '')).trim(),
1677
1677
  firstName: employee.fname || employee.firstName || employee.first_name,
1678
1678
  lastName: employee.lname || employee.lastName || employee.last_name,
1679
- employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId
1679
+ employeeId: employee.emp_id || employee.employeeId || employee.employee_id || employeeId,
1680
+ bravaisUserId: employee.bravaisUserId || null,
1681
+ tenantUrl: employee.tenantUrl || null
1680
1682
  };
1681
1683
  log('Parsed employee data:', employeeLookupData);
1682
1684
  // Persist to localStorage for cross-session caching
@@ -1750,6 +1752,16 @@ function generateLrsBridgeCode(options) {
1750
1752
  if (employeeData.name && (!actor.name || actor.name === 'Unknown Learner')) {
1751
1753
  actor.name = employeeData.name;
1752
1754
  }
1755
+
1756
+ // Update account with Bravais user ID and tenant URL if available
1757
+ if (employeeData.bravaisUserId) {
1758
+ var originalAccountName = actor.account ? actor.account.name : null;
1759
+ actor.account = {
1760
+ name: employeeData.bravaisUserId,
1761
+ homePage: employeeData.tenantUrl || (actor.account && actor.account.homePage) || window.location.origin
1762
+ };
1763
+ log('Updated actor account: bravaisUserId=' + employeeData.bravaisUserId + ', homePage=' + actor.account.homePage + ' (was: ' + originalAccountName + ')');
1764
+ }
1753
1765
  }
1754
1766
  callback(actor);
1755
1767
  });
@@ -2414,7 +2426,7 @@ function generateLrsBridgeCode(options) {
2414
2426
  tenantHomepage: null // https://{tenant}.bravais.com format
2415
2427
  };
2416
2428
 
2417
- // 0. Use baked-in GUIDs from Patch-Adams config (highest priority - set at wrap time)
2429
+ // 0. Use baked-in GUIDs from PA-Patcher config (highest priority - set at wrap time)
2418
2430
  if (DOCUMENT_GUID) {
2419
2431
  info.guid = DOCUMENT_GUID;
2420
2432
  info.id = 'http://xyleme.com/bravais/document/' + DOCUMENT_GUID;
@@ -2923,6 +2935,11 @@ function generateLrsBridgeCode(options) {
2923
2935
  // Publish index (default to 1)
2924
2936
  ctx.extensions['publishIndex'] = (LRS.courseInfo && LRS.courseInfo.publishIndex) ? LRS.courseInfo.publishIndex : 1;
2925
2937
 
2938
+ // Employee ID from employee lookup (if available)
2939
+ if (employeeLookupData && employeeLookupData.employeeId) {
2940
+ ctx.extensions['employeeId'] = employeeLookupData.employeeId;
2941
+ }
2942
+
2926
2943
  // Xyleme schema version and PII flag
2927
2944
  ctx.extensions['http://xyleme.com/bravais/extensions/statement-schema'] = 'xyleme_10';
2928
2945
  ctx.extensions['http://xyleme.com/bravais/extensions/protect_pii'] = false;
@@ -4405,6 +4422,19 @@ function generateLrsBridgeCode(options) {
4405
4422
  // Setup connection
4406
4423
  var bridgeReady = setupBridge();
4407
4424
 
4425
+ // Track async readiness: both actor and doc metadata must resolve before sending statements
4426
+ var actorReady = false;
4427
+ var docReady = false;
4428
+ var launchEventsSent = false;
4429
+
4430
+ function tryLaunchEvents() {
4431
+ if (launchEventsSent) return;
4432
+ if (!actorReady || !docReady) return;
4433
+ launchEventsSent = true;
4434
+ log('Both actor and doc metadata ready, sending launch events');
4435
+ setTimeout(sendLaunchEvents, 50);
4436
+ }
4437
+
4408
4438
  if (bridgeReady) {
4409
4439
  LRS.initialized = true;
4410
4440
 
@@ -4415,14 +4445,23 @@ function generateLrsBridgeCode(options) {
4415
4445
  log('Actor:', LRS.actor);
4416
4446
  log('Course:', LRS.courseInfo);
4417
4447
 
4418
- // Then try async actor extraction from Bravais session
4419
- // This will update the actor with real user info if available
4448
+ // Then try async actor extraction (employee lookup, Bravais session)
4449
+ // Launch events will NOT be sent until this completes
4420
4450
  extractActorAsync(function(actor) {
4421
4451
  log('Actor updated after async fetch:', actor);
4452
+ actorReady = true;
4453
+ // Log final actor state for diagnostics
4454
+ if (window.console && window.console.info) {
4455
+ console.info('[PA-LRS] Actor resolved: name=' + (actor ? actor.name : 'none') +
4456
+ ', mbox=' + (actor ? actor.mbox : 'none') +
4457
+ ', account=' + (actor && actor.account ? actor.account.name : 'none'));
4458
+ }
4459
+ tryLaunchEvents();
4422
4460
  });
4423
4461
  } else {
4424
4462
  warn('Bridge setup failed - operating in offline mode');
4425
4463
  LRS.mode = 'offline';
4464
+ actorReady = true; // No actor to wait for in offline mode
4426
4465
  }
4427
4466
 
4428
4467
  // Always-visible bridge summary (not gated by DEBUG)
@@ -4467,13 +4506,17 @@ function generateLrsBridgeCode(options) {
4467
4506
  }
4468
4507
  }
4469
4508
 
4470
- function fetchDocDataAndSend(docId) {
4509
+ function onDocReady() {
4510
+ docReady = true;
4511
+ tryLaunchEvents();
4512
+ }
4513
+
4514
+ function fetchDocDataAndReady(docId) {
4471
4515
  fetchDocumentMetadata(docId, function(docData) {
4472
4516
  if (docData) {
4473
4517
  updateCourseInfoFromApi(docData);
4474
4518
  }
4475
- // Send launch events after API fetch (success or failure)
4476
- setTimeout(sendLaunchEvents, 100);
4519
+ onDocReady();
4477
4520
  });
4478
4521
  }
4479
4522
 
@@ -4493,20 +4536,20 @@ function generateLrsBridgeCode(options) {
4493
4536
  } else {
4494
4537
  warn('Could not fetch document data from shared API - statements may fail aggregation');
4495
4538
  }
4496
- setTimeout(sendLaunchEvents, 100);
4539
+ onDocReady();
4497
4540
  });
4498
4541
  } else if (documentId) {
4499
4542
  // No shared link token, try with extracted document ID (requires auth)
4500
4543
  log('No shared link token, fetching document data with ID:', documentId);
4501
- fetchDocDataAndSend(documentId);
4544
+ fetchDocDataAndReady(documentId);
4502
4545
  } else {
4503
4546
  // No identifiers available
4504
4547
  warn('No shared link token or document ID - statements may fail aggregation');
4505
- setTimeout(sendLaunchEvents, 500);
4548
+ onDocReady();
4506
4549
  }
4507
4550
  } else {
4508
- // Already have GUID - send after short delay
4509
- setTimeout(sendLaunchEvents, 500);
4551
+ // Already have GUID
4552
+ onDocReady();
4510
4553
  }
4511
4554
 
4512
4555
  // Setup beforeunload to send terminated
@@ -4591,7 +4634,7 @@ ${courseLines.join("\n")}
4591
4634
  },` : "";
4592
4635
  return `<!-- === PATCH-ADAMS: JS BEFORE (blocking) === -->
4593
4636
  <script data-pa="js-before-loader">
4594
- // Initialize Patch-Adams global namespace IMMEDIATELY (before IIFE)
4637
+ // Initialize PA-Patcher global namespace IMMEDIATELY (before IIFE)
4595
4638
  window.pa_patcher = window.pa_patcher || {
4596
4639
  version: '1.0.25',
4597
4640
  htmlClass: '${htmlClass}',
@@ -4636,7 +4679,7 @@ window.pa_patcher = window.pa_patcher || {
4636
4679
  if (isExtensionError(event.reason)) {
4637
4680
  event.preventDefault();
4638
4681
  event.stopImmediatePropagation();
4639
- console.debug('[Patch-Adams] Suppressed browser extension error:', event.reason);
4682
+ console.debug('[PA-Patcher] Suppressed browser extension error:', event.reason);
4640
4683
  return false;
4641
4684
  }
4642
4685
  }, true);
@@ -4646,7 +4689,7 @@ window.pa_patcher = window.pa_patcher || {
4646
4689
  if (isExtensionError(event.error || event.message)) {
4647
4690
  event.preventDefault();
4648
4691
  event.stopImmediatePropagation();
4649
- console.debug('[Patch-Adams] Suppressed browser extension error:', event.message);
4692
+ console.debug('[PA-Patcher] Suppressed browser extension error:', event.message);
4650
4693
  return false;
4651
4694
  }
4652
4695
  }, true);
@@ -4671,17 +4714,17 @@ window.pa_patcher = window.pa_patcher || {
4671
4714
  var script = loadJSSync(REMOTE_URL);
4672
4715
 
4673
4716
  script.onerror = function() {
4674
- console.warn('[Patch-Adams] JS before failed to load from remote, using local fallback');
4717
+ console.warn('[PA-Patcher] JS before failed to load from remote, using local fallback');
4675
4718
  document.head.removeChild(script);
4676
4719
  var fallback = loadJSSync(LOCAL_PATH);
4677
4720
  fallback.onload = function() {
4678
4721
  if (window.pa_patcher && window.pa_patcher.loaded) {
4679
4722
  window.pa_patcher.loaded.jsBefore = true;
4680
4723
  }
4681
- console.log('[Patch-Adams] JS before loaded from local fallback:', LOCAL_PATH);
4724
+ console.log('[PA-Patcher] JS before loaded from local fallback:', LOCAL_PATH);
4682
4725
  };
4683
4726
  fallback.onerror = function() {
4684
- console.error('[Patch-Adams] JS before failed to load from both remote and local');
4727
+ console.error('[PA-Patcher] JS before failed to load from both remote and local');
4685
4728
  };
4686
4729
  };
4687
4730
 
@@ -4689,7 +4732,7 @@ window.pa_patcher = window.pa_patcher || {
4689
4732
  if (window.pa_patcher && window.pa_patcher.loaded) {
4690
4733
  window.pa_patcher.loaded.jsBefore = true;
4691
4734
  }
4692
- console.log('[Patch-Adams] JS before loaded from remote:', REMOTE_URL);
4735
+ console.log('[PA-Patcher] JS before loaded from remote:', REMOTE_URL);
4693
4736
  };
4694
4737
  })();
4695
4738
  ${lrsBridgeCode}
@@ -4760,14 +4803,14 @@ function generateJsAfterLoader(options) {
4760
4803
  if (window.pa_patcher && window.pa_patcher.loaded) {
4761
4804
  window.pa_patcher.loaded.jsAfter = true;
4762
4805
  }
4763
- console.log('[Patch-Adams] Loading complete, content revealed');
4806
+ console.log('[PA-Patcher] Loading complete, content revealed');
4764
4807
 
4765
4808
  // Add visual badge to indicate patching is active
4766
4809
  var badge = document.createElement('div');
4767
4810
  badge.setAttribute('data-pa', 'badge');
4768
4811
  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;';
4769
4812
  badge.textContent = 'PA';
4770
- badge.title = 'Patch-Adams Active';
4813
+ badge.title = 'PA-Patcher Active';
4771
4814
  badge.onclick = function() { badge.style.display = 'none'; };
4772
4815
  document.body.appendChild(badge);
4773
4816
  }
@@ -4783,7 +4826,7 @@ function generateJsAfterLoader(options) {
4783
4826
  if (loaded) return;
4784
4827
  loaded = true;
4785
4828
  clearTimeout(timeoutId);
4786
- console.log('[Patch-Adams] JS after loaded from remote:', REMOTE_URL);
4829
+ console.log('[PA-Patcher] JS after loaded from remote:', REMOTE_URL);
4787
4830
  // Give the script a moment to execute, then remove loading class
4788
4831
  setTimeout(removeLoadingClass, 50);
4789
4832
  },
@@ -4799,7 +4842,7 @@ function generateJsAfterLoader(options) {
4799
4842
  timeoutId = setTimeout(function() {
4800
4843
  if (loaded) return;
4801
4844
  loaded = true;
4802
- console.warn('[Patch-Adams] JS after timed out, using local fallback');
4845
+ console.warn('[PA-Patcher] JS after timed out, using local fallback');
4803
4846
  if (remoteScript.parentNode) {
4804
4847
  document.body.removeChild(remoteScript);
4805
4848
  }
@@ -4811,11 +4854,11 @@ function generateJsAfterLoader(options) {
4811
4854
  loadJS(
4812
4855
  LOCAL_PATH,
4813
4856
  function() {
4814
- console.log('[Patch-Adams] JS after loaded from local fallback:', LOCAL_PATH);
4857
+ console.log('[PA-Patcher] JS after loaded from local fallback:', LOCAL_PATH);
4815
4858
  setTimeout(removeLoadingClass, 50);
4816
4859
  },
4817
4860
  function() {
4818
- console.error('[Patch-Adams] JS after failed to load from both remote and local');
4861
+ console.error('[PA-Patcher] JS after failed to load from both remote and local');
4819
4862
  // Still remove loading class so content is visible even if JS fails
4820
4863
  removeLoadingClass();
4821
4864
  }
@@ -5275,7 +5318,7 @@ var ManifestUpdater = class {
5275
5318
  const resourceClosePattern = /(\s*)<\/resource>/i;
5276
5319
  const match = xmlContent.match(resourceClosePattern);
5277
5320
  if (!match) {
5278
- console.warn("[Patch-Adams] Could not find </resource> tag in imsmanifest.xml");
5321
+ console.warn("[PA-Patcher] Could not find </resource> tag in imsmanifest.xml");
5279
5322
  return [];
5280
5323
  }
5281
5324
  const updatedXml = xmlContent.replace(
@@ -5287,7 +5330,7 @@ $1</resource>`
5287
5330
  zip.updateFile("imsmanifest.xml", Buffer.from(updatedXml, "utf-8"));
5288
5331
  return ["imsmanifest.xml"];
5289
5332
  } catch (error) {
5290
- console.error("[Patch-Adams] Failed to update imsmanifest.xml:", error);
5333
+ console.error("[PA-Patcher] Failed to update imsmanifest.xml:", error);
5291
5334
  return [];
5292
5335
  }
5293
5336
  }
@@ -5609,7 +5652,7 @@ ${js.after}
5609
5652
  var pluginRegistry = new PluginRegistry();
5610
5653
 
5611
5654
  // src/patcher/index.ts
5612
- var DEFAULT_CSS_BEFORE = `/* Patch-Adams: CSS Before (blocking)
5655
+ var DEFAULT_CSS_BEFORE = `/* PA-Patcher: CSS Before (blocking)
5613
5656
  * This file loads at the start of <head> and blocks rendering.
5614
5657
  * Use it to hide content and prevent flash of unstyled content.
5615
5658
  *
@@ -5619,7 +5662,7 @@ var DEFAULT_CSS_BEFORE = `/* Patch-Adams: CSS Before (blocking)
5619
5662
  * }
5620
5663
  */
5621
5664
  `;
5622
- var DEFAULT_CSS_AFTER = `/* Patch-Adams: CSS After (async)
5665
+ var DEFAULT_CSS_AFTER = `/* PA-Patcher: CSS After (async)
5623
5666
  * This file loads at the end of <head> with remote fallback.
5624
5667
  * Use it for style overrides that take precedence over Rise styles.
5625
5668
  *
@@ -5629,7 +5672,7 @@ var DEFAULT_CSS_AFTER = `/* Patch-Adams: CSS After (async)
5629
5672
  * }
5630
5673
  */
5631
5674
  `;
5632
- var DEFAULT_JS_BEFORE = `// Patch-Adams: JS Before (blocking)
5675
+ var DEFAULT_JS_BEFORE = `// PA-Patcher: JS Before (blocking)
5633
5676
  // This file loads at the start of <head> and blocks rendering.
5634
5677
  // Use it for setup, API interception, and preparing globals.
5635
5678
  //
@@ -5639,9 +5682,9 @@ var DEFAULT_JS_BEFORE = `// Patch-Adams: JS Before (blocking)
5639
5682
  // analytics: true
5640
5683
  // };
5641
5684
 
5642
- console.log('[Patch-Adams] JS Before loaded');
5685
+ console.log('[PA-Patcher] JS Before loaded');
5643
5686
  `;
5644
- var DEFAULT_JS_AFTER = `// Patch-Adams: JS After (async)
5687
+ var DEFAULT_JS_AFTER = `// PA-Patcher: JS After (async)
5645
5688
  // This file loads at the end of <body> with remote fallback.
5646
5689
  // Use it for DOM manipulation after Rise has initialized.
5647
5690
  //
@@ -5653,7 +5696,7 @@ var DEFAULT_JS_AFTER = `// Patch-Adams: JS After (async)
5653
5696
  // // Your modifications here
5654
5697
  // });
5655
5698
 
5656
- console.log('[Patch-Adams] JS After loaded');
5699
+ console.log('[PA-Patcher] JS After loaded');
5657
5700
  `;
5658
5701
  var Patcher = class {
5659
5702
  config;