@patch-adams/core 1.4.20 → 1.4.22

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
@@ -393,7 +393,11 @@ var LrsBridgeConfigSchema = zod.z.object({
393
393
  /** LRS proxy endpoint URL - statements are sent here instead of direct LRS, proxy handles auth server-side */
394
394
  lrsProxyEndpoint: zod.z.string().optional(),
395
395
  /** Employee API endpoint URL for user identity lookup (e.g., https://node.example.com/admin_api/users/employees/) */
396
- employeeApiEndpoint: zod.z.string().optional()
396
+ employeeApiEndpoint: zod.z.string().optional(),
397
+ /** Document GUID for xAPI statement aggregation - baked into package at wrap time */
398
+ documentGuid: zod.z.string().optional(),
399
+ /** Version GUID for xAPI statement aggregation - unique per export */
400
+ versionGuid: zod.z.string().optional()
397
401
  });
398
402
  var BlockingAssetConfigSchema = zod.z.object({
399
403
  /** Filename for the asset */
@@ -738,6 +742,8 @@ function generateLrsBridgeCode(options) {
738
742
  const employeeApiEndpoint = options.employeeApiEndpoint || "";
739
743
  const lrsAuth = options.lrsAuth || "";
740
744
  const lrsProxyEndpoint = options.lrsProxyEndpoint || "";
745
+ const documentGuid = options.documentGuid || "";
746
+ const versionGuid = options.versionGuid || "";
741
747
  return `
742
748
  // ==========================================================================
743
749
  // PATCH-ADAMS LRS BRIDGE v2.2.0
@@ -768,6 +774,8 @@ function generateLrsBridgeCode(options) {
768
774
  var EMPLOYEE_API_ENDPOINT = '${employeeApiEndpoint}';
769
775
  var LRS_AUTH = '${lrsAuth}';
770
776
  var LRS_PROXY_ENDPOINT = '${lrsProxyEndpoint}';
777
+ var DOCUMENT_GUID = '${documentGuid}';
778
+ var VERSION_GUID = '${versionGuid}';
771
779
 
772
780
  // Bravais LRS endpoint pattern: https://lrs-{tenant}.bravais.com/XAPI/statements
773
781
  // Example: core-acme.bravais.com -> lrs-acme.bravais.com
@@ -2413,6 +2421,17 @@ function generateLrsBridgeCode(options) {
2413
2421
  tenantHomepage: null // https://{tenant}.bravais.com format
2414
2422
  };
2415
2423
 
2424
+ // 0. Use baked-in GUIDs from Patch-Adams config (highest priority - set at wrap time)
2425
+ if (DOCUMENT_GUID) {
2426
+ info.guid = DOCUMENT_GUID;
2427
+ info.id = 'http://xyleme.com/bravais/document/' + DOCUMENT_GUID;
2428
+ log('Document GUID from baked-in config:', DOCUMENT_GUID);
2429
+ }
2430
+ if (VERSION_GUID) {
2431
+ info.versionGuid = VERSION_GUID;
2432
+ log('Version GUID from baked-in config:', VERSION_GUID);
2433
+ }
2434
+
2416
2435
  // 1. Extract shared link token and document ID from URL
2417
2436
  info.sharedLinkToken = extractSharedLinkToken();
2418
2437
  info.documentId = extractBravaisDocumentId();
@@ -2489,14 +2508,15 @@ function generateLrsBridgeCode(options) {
2489
2508
  info.title = document.title;
2490
2509
  }
2491
2510
 
2492
- // 7. Get from PA metadata if available
2493
- if (window.pa_patcher && window.pa_patcher.courseMetadata) {
2494
- var meta = window.pa_patcher.courseMetadata;
2495
- info.documentId = meta.documentId || meta.courseId || info.documentId;
2496
- info.guid = meta.guid || meta.courseGuid || info.guid;
2497
- info.versionGuid = meta.versionGuid || info.versionGuid;
2498
- info.title = meta.title || meta.courseTitle || info.title;
2499
- info.versionId = meta.versionId || info.versionId;
2511
+ // 7. Get from PA metadata if available (check both .courseMetadata and .course)
2512
+ var paMeta = (window.pa_patcher && window.pa_patcher.courseMetadata) ||
2513
+ (window.pa_patcher && window.pa_patcher.course) || null;
2514
+ if (paMeta) {
2515
+ info.documentId = paMeta.documentId || paMeta.courseId || info.documentId;
2516
+ if (!info.guid) info.guid = paMeta.guid || paMeta.courseGuid || null;
2517
+ if (!info.versionGuid) info.versionGuid = paMeta.versionGuid || null;
2518
+ info.title = (info.title === 'Rise Course') ? (paMeta.title || paMeta.courseTitle || info.title) : info.title;
2519
+ info.versionId = paMeta.versionId || info.versionId;
2500
2520
  }
2501
2521
 
2502
2522
  // 8. Build the course ID in Xyleme IRI format
@@ -3623,6 +3643,34 @@ function generateLrsBridgeCode(options) {
3623
3643
  sendStatement(statement);
3624
3644
  };
3625
3645
 
3646
+ /**
3647
+ * Re-extract actor from SCORM after LMSInitialize has been called.
3648
+ * Call this from the SCORM wrapper after scormInit() succeeds,
3649
+ * because the bridge initializes in <head> before LMSInitialize runs.
3650
+ */
3651
+ LRS.refreshActor = function(callback) {
3652
+ log('refreshActor called - re-extracting from SCORM...');
3653
+ var previousName = LRS.actor ? LRS.actor.name : 'none';
3654
+
3655
+ // Re-run sync extraction (SCORM data should now be available)
3656
+ var newActor = extractActor();
3657
+
3658
+ if (isValidActor(newActor) && newActor.account && newActor.account.name !== 'unknown') {
3659
+ log('refreshActor: got valid actor:', newActor.name, newActor.account ? newActor.account.name : '');
3660
+ // Enhance with email lookup (async)
3661
+ extractActorAsync(function(enhancedActor) {
3662
+ if (window.console && window.console.info) {
3663
+ console.info('[PA-LRS] Actor refreshed: ' + previousName + ' -> ' + enhancedActor.name +
3664
+ (enhancedActor.mbox ? ' (' + enhancedActor.mbox + ')' : ''));
3665
+ }
3666
+ if (callback) callback(enhancedActor);
3667
+ });
3668
+ } else {
3669
+ log('refreshActor: no valid actor found after re-extraction');
3670
+ if (callback) callback(LRS.actor);
3671
+ }
3672
+ };
3673
+
3626
3674
  // Course terminated/exited
3627
3675
  LRS.courseTerminated = function() {
3628
3676
  // Calculate duration
@@ -4628,7 +4676,9 @@ function buildJsBeforeOptions(config, metadata) {
4628
4676
  autoDetectLrs: lrsBridgeConfig.autoDetectLrs,
4629
4677
  lrsAuth: lrsBridgeConfig.lrsAuth,
4630
4678
  lrsProxyEndpoint: lrsBridgeConfig.lrsProxyEndpoint,
4631
- employeeApiEndpoint: lrsBridgeConfig.employeeApiEndpoint
4679
+ employeeApiEndpoint: lrsBridgeConfig.employeeApiEndpoint,
4680
+ documentGuid: lrsBridgeConfig.documentGuid,
4681
+ versionGuid: lrsBridgeConfig.versionGuid
4632
4682
  };
4633
4683
  return {
4634
4684
  remoteUrl: `${config.remoteDomain}/${config.localFolders.js}/${config.jsBefore.filename}`,