@patch-adams/core 1.5.17 → 1.5.19

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
@@ -2282,17 +2282,27 @@ function generateLrsBridgeCode(options) {
2282
2282
  function updateCourseInfoFromApi(docData) {
2283
2283
  if (!docData || !LRS.courseInfo) return;
2284
2284
 
2285
- // Document GUID
2286
- if (docData.guid && !LRS.courseInfo.guid) {
2285
+ // Document GUID \u2014 Bravais API GUID ALWAYS overrides baked-in GUID.
2286
+ // The baked-in GUID is a random UUID from wrap time. The Bravais GUID is the
2287
+ // canonical document identifier that Analytics uses to link statements to documents.
2288
+ // Without this override, our statements have a different object.id than cloudplayer
2289
+ // statements, so Analytics treats them as unrelated to the document.
2290
+ if (docData.guid) {
2291
+ var oldGuid = LRS.courseInfo.guid;
2287
2292
  LRS.courseInfo.guid = docData.guid;
2288
2293
  LRS.courseInfo.id = 'http://xyleme.com/bravais/document/' + docData.guid;
2289
- log('Updated course guid from API:', docData.guid);
2294
+ // Always-visible log (not behind DEBUG) so we can confirm override in production
2295
+ console.info('[PA-LRS] Document GUID set from API:', docData.guid,
2296
+ oldGuid && oldGuid !== docData.guid ? '(was: ' + oldGuid + ')' : '');
2290
2297
  }
2291
2298
 
2292
- // Version GUID from latestVersion
2293
- if (docData.latestVersion && docData.latestVersion.guid && !LRS.courseInfo.versionGuid) {
2299
+ // Version GUID \u2014 same principle: Bravais version GUID must override baked-in
2300
+ if (docData.latestVersion && docData.latestVersion.guid) {
2301
+ if (LRS.courseInfo.versionGuid && LRS.courseInfo.versionGuid !== docData.latestVersion.guid) {
2302
+ log('Overriding baked-in version GUID:', LRS.courseInfo.versionGuid, '->', docData.latestVersion.guid);
2303
+ }
2294
2304
  LRS.courseInfo.versionGuid = docData.latestVersion.guid;
2295
- log('Updated version guid from API:', docData.latestVersion.guid);
2305
+ log('Version GUID from API:', docData.latestVersion.guid);
2296
2306
  }
2297
2307
 
2298
2308
  // Other metadata
@@ -2592,21 +2602,20 @@ function generateLrsBridgeCode(options) {
2592
2602
  info.sharedLinkName = launchInfo.sharedLinkName || info.sharedLinkName;
2593
2603
  }
2594
2604
 
2595
- // 3b. Try to extract GUIDs from Xyleme Cloud Player's internal data
2596
- // This is more reliable than API calls which may fail with 401
2597
- if (!info.guid || !info.versionGuid) {
2598
- var cloudPlayerData = extractFromXylemeCloudPlayer();
2599
- if (cloudPlayerData) {
2600
- info.guid = cloudPlayerData.guid || info.guid;
2601
- info.versionGuid = cloudPlayerData.versionGuid || info.versionGuid;
2602
- info.documentId = cloudPlayerData.documentId || info.documentId;
2603
- info.title = cloudPlayerData.title || info.title;
2604
- log('Updated course info from Cloud Player:', {
2605
- guid: info.guid,
2606
- versionGuid: info.versionGuid,
2607
- documentId: info.documentId
2608
- });
2609
- }
2605
+ // 3b. Always try to extract GUIDs from Xyleme Cloud Player's internal data.
2606
+ // Cloud Player data is authoritative \u2014 it has the canonical Bravais GUID.
2607
+ // This overrides any baked-in GUID which is just a random UUID from wrap time.
2608
+ var cloudPlayerData = extractFromXylemeCloudPlayer();
2609
+ if (cloudPlayerData) {
2610
+ if (cloudPlayerData.guid) info.guid = cloudPlayerData.guid;
2611
+ if (cloudPlayerData.versionGuid) info.versionGuid = cloudPlayerData.versionGuid;
2612
+ info.documentId = cloudPlayerData.documentId || info.documentId;
2613
+ info.title = cloudPlayerData.title || info.title;
2614
+ log('Updated course info from Cloud Player:', {
2615
+ guid: info.guid,
2616
+ versionGuid: info.versionGuid,
2617
+ documentId: info.documentId
2618
+ });
2610
2619
  }
2611
2620
 
2612
2621
  // 4. Try getCourseTitle() from preloadIntegrity.js
@@ -5228,12 +5237,18 @@ function generateLrsBridgeCode(options) {
5228
5237
 
5229
5238
  // Always-visible bridge summary (not gated by DEBUG)
5230
5239
  // This ensures diagnostics are available even in production builds
5240
+ // Shows current GUID (may be from Cloud Player, baked-in, or pending API override)
5241
+ var currentGuid = LRS.courseInfo ? LRS.courseInfo.guid : DOCUMENT_GUID;
5242
+ var currentVerGuid = LRS.courseInfo ? LRS.courseInfo.versionGuid : VERSION_GUID;
5243
+ var sharedToken = LRS.courseInfo ? LRS.courseInfo.sharedLinkToken : null;
5231
5244
  if (window.console && window.console.info) {
5232
5245
  console.info('[PA-LRS] Bridge v' + LRS.version + ': mode=' + LRS.mode +
5233
5246
  ', endpoint=' + (LRS_ENDPOINT ? LRS_ENDPOINT.substring(0, 30) + '...' : 'NONE') +
5234
5247
  ', proxy=' + (LRS_PROXY_ENDPOINT ? 'yes' : 'no') +
5235
- ', docGuid=' + (DOCUMENT_GUID || 'NONE') +
5236
- ', verGuid=' + (VERSION_GUID || 'NONE') +
5248
+ ', docGuid=' + (currentGuid || 'NONE') +
5249
+ (currentGuid !== DOCUMENT_GUID ? ' (overridden from baked: ' + DOCUMENT_GUID + ')' : '') +
5250
+ ', verGuid=' + (currentVerGuid || 'NONE') +
5251
+ ', sharedToken=' + (sharedToken || 'NONE') +
5237
5252
  ', actor=' + (LRS.actor ? (LRS.actor.name || 'anonymous') : 'none') +
5238
5253
  ', hasRefreshActor=' + (typeof LRS.refreshActor === 'function'));
5239
5254
  }
@@ -5304,35 +5319,30 @@ function generateLrsBridgeCode(options) {
5304
5319
  });
5305
5320
  }
5306
5321
 
5307
- if (!LRS.courseInfo.guid) {
5308
- // When we have a shared link token, use /api/shared/{token}/documents directly
5309
- // This endpoint does NOT require authentication and returns both document GUID and version GUID
5310
- if (sharedLinkToken) {
5311
- log('Have shared link token, fetching document data via shared API...');
5312
- // fetchDocumentMetadata will use /api/shared/{token}/documents when sharedLinkToken is present
5313
- fetchDocumentMetadata(null, function(docData) {
5314
- if (docData) {
5315
- updateCourseInfoFromApi(docData);
5316
- // Also update document name if available
5317
- if (docData.name) {
5318
- LRS.courseInfo.sharedLinkName = docData.name;
5319
- }
5320
- } else {
5321
- warn('Could not fetch document data from shared API - statements may fail aggregation');
5322
+ // ALWAYS fetch document metadata from the Bravais API.
5323
+ // Even if we have a baked-in GUID, we must override it with the canonical
5324
+ // Bravais GUID so our statements link to the same document as cloudplayer.
5325
+ // The baked-in GUID is a random UUID from wrap time; the Bravais GUID is
5326
+ // assigned at upload and is what Analytics uses for aggregation.
5327
+ if (sharedLinkToken) {
5328
+ log('Have shared link token, fetching document data via shared API...');
5329
+ fetchDocumentMetadata(null, function(docData) {
5330
+ if (docData) {
5331
+ updateCourseInfoFromApi(docData);
5332
+ if (docData.name) {
5333
+ LRS.courseInfo.sharedLinkName = docData.name;
5322
5334
  }
5323
- maybeEnrichAndReady();
5324
- });
5325
- } else if (documentId) {
5326
- // No shared link token, try with extracted document ID (requires auth)
5327
- log('No shared link token, fetching document data with ID:', documentId);
5328
- fetchDocDataAndReady(documentId);
5329
- } else {
5330
- // No identifiers available
5331
- warn('No shared link token or document ID - statements may fail aggregation');
5335
+ } else {
5336
+ warn('Could not fetch document data from shared API - statements may use baked-in GUID');
5337
+ }
5332
5338
  maybeEnrichAndReady();
5333
- }
5339
+ });
5340
+ } else if (documentId) {
5341
+ log('Fetching document data with ID:', documentId);
5342
+ fetchDocDataAndReady(documentId);
5334
5343
  } else {
5335
- // Already have GUID \u2014 still try to enrich packageName if missing
5344
+ // No identifiers available
5345
+ warn('No shared link token or document ID - statements will use baked-in GUID');
5336
5346
  maybeEnrichAndReady();
5337
5347
  }
5338
5348