@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/index.js CHANGED
@@ -1941,17 +1941,27 @@ function generateLrsBridgeCode(options) {
1941
1941
  function updateCourseInfoFromApi(docData) {
1942
1942
  if (!docData || !LRS.courseInfo) return;
1943
1943
 
1944
- // Document GUID
1945
- if (docData.guid && !LRS.courseInfo.guid) {
1944
+ // Document GUID \u2014 Bravais API GUID ALWAYS overrides baked-in GUID.
1945
+ // The baked-in GUID is a random UUID from wrap time. The Bravais GUID is the
1946
+ // canonical document identifier that Analytics uses to link statements to documents.
1947
+ // Without this override, our statements have a different object.id than cloudplayer
1948
+ // statements, so Analytics treats them as unrelated to the document.
1949
+ if (docData.guid) {
1950
+ var oldGuid = LRS.courseInfo.guid;
1946
1951
  LRS.courseInfo.guid = docData.guid;
1947
1952
  LRS.courseInfo.id = 'http://xyleme.com/bravais/document/' + docData.guid;
1948
- log('Updated course guid from API:', docData.guid);
1953
+ // Always-visible log (not behind DEBUG) so we can confirm override in production
1954
+ console.info('[PA-LRS] Document GUID set from API:', docData.guid,
1955
+ oldGuid && oldGuid !== docData.guid ? '(was: ' + oldGuid + ')' : '');
1949
1956
  }
1950
1957
 
1951
- // Version GUID from latestVersion
1952
- if (docData.latestVersion && docData.latestVersion.guid && !LRS.courseInfo.versionGuid) {
1958
+ // Version GUID \u2014 same principle: Bravais version GUID must override baked-in
1959
+ if (docData.latestVersion && docData.latestVersion.guid) {
1960
+ if (LRS.courseInfo.versionGuid && LRS.courseInfo.versionGuid !== docData.latestVersion.guid) {
1961
+ log('Overriding baked-in version GUID:', LRS.courseInfo.versionGuid, '->', docData.latestVersion.guid);
1962
+ }
1953
1963
  LRS.courseInfo.versionGuid = docData.latestVersion.guid;
1954
- log('Updated version guid from API:', docData.latestVersion.guid);
1964
+ log('Version GUID from API:', docData.latestVersion.guid);
1955
1965
  }
1956
1966
 
1957
1967
  // Other metadata
@@ -2251,21 +2261,20 @@ function generateLrsBridgeCode(options) {
2251
2261
  info.sharedLinkName = launchInfo.sharedLinkName || info.sharedLinkName;
2252
2262
  }
2253
2263
 
2254
- // 3b. Try to extract GUIDs from Xyleme Cloud Player's internal data
2255
- // This is more reliable than API calls which may fail with 401
2256
- if (!info.guid || !info.versionGuid) {
2257
- var cloudPlayerData = extractFromXylemeCloudPlayer();
2258
- if (cloudPlayerData) {
2259
- info.guid = cloudPlayerData.guid || info.guid;
2260
- info.versionGuid = cloudPlayerData.versionGuid || info.versionGuid;
2261
- info.documentId = cloudPlayerData.documentId || info.documentId;
2262
- info.title = cloudPlayerData.title || info.title;
2263
- log('Updated course info from Cloud Player:', {
2264
- guid: info.guid,
2265
- versionGuid: info.versionGuid,
2266
- documentId: info.documentId
2267
- });
2268
- }
2264
+ // 3b. Always try to extract GUIDs from Xyleme Cloud Player's internal data.
2265
+ // Cloud Player data is authoritative \u2014 it has the canonical Bravais GUID.
2266
+ // This overrides any baked-in GUID which is just a random UUID from wrap time.
2267
+ var cloudPlayerData = extractFromXylemeCloudPlayer();
2268
+ if (cloudPlayerData) {
2269
+ if (cloudPlayerData.guid) info.guid = cloudPlayerData.guid;
2270
+ if (cloudPlayerData.versionGuid) info.versionGuid = cloudPlayerData.versionGuid;
2271
+ info.documentId = cloudPlayerData.documentId || info.documentId;
2272
+ info.title = cloudPlayerData.title || info.title;
2273
+ log('Updated course info from Cloud Player:', {
2274
+ guid: info.guid,
2275
+ versionGuid: info.versionGuid,
2276
+ documentId: info.documentId
2277
+ });
2269
2278
  }
2270
2279
 
2271
2280
  // 4. Try getCourseTitle() from preloadIntegrity.js
@@ -4887,12 +4896,18 @@ function generateLrsBridgeCode(options) {
4887
4896
 
4888
4897
  // Always-visible bridge summary (not gated by DEBUG)
4889
4898
  // This ensures diagnostics are available even in production builds
4899
+ // Shows current GUID (may be from Cloud Player, baked-in, or pending API override)
4900
+ var currentGuid = LRS.courseInfo ? LRS.courseInfo.guid : DOCUMENT_GUID;
4901
+ var currentVerGuid = LRS.courseInfo ? LRS.courseInfo.versionGuid : VERSION_GUID;
4902
+ var sharedToken = LRS.courseInfo ? LRS.courseInfo.sharedLinkToken : null;
4890
4903
  if (window.console && window.console.info) {
4891
4904
  console.info('[PA-LRS] Bridge v' + LRS.version + ': mode=' + LRS.mode +
4892
4905
  ', endpoint=' + (LRS_ENDPOINT ? LRS_ENDPOINT.substring(0, 30) + '...' : 'NONE') +
4893
4906
  ', proxy=' + (LRS_PROXY_ENDPOINT ? 'yes' : 'no') +
4894
- ', docGuid=' + (DOCUMENT_GUID || 'NONE') +
4895
- ', verGuid=' + (VERSION_GUID || 'NONE') +
4907
+ ', docGuid=' + (currentGuid || 'NONE') +
4908
+ (currentGuid !== DOCUMENT_GUID ? ' (overridden from baked: ' + DOCUMENT_GUID + ')' : '') +
4909
+ ', verGuid=' + (currentVerGuid || 'NONE') +
4910
+ ', sharedToken=' + (sharedToken || 'NONE') +
4896
4911
  ', actor=' + (LRS.actor ? (LRS.actor.name || 'anonymous') : 'none') +
4897
4912
  ', hasRefreshActor=' + (typeof LRS.refreshActor === 'function'));
4898
4913
  }
@@ -4963,35 +4978,30 @@ function generateLrsBridgeCode(options) {
4963
4978
  });
4964
4979
  }
4965
4980
 
4966
- if (!LRS.courseInfo.guid) {
4967
- // When we have a shared link token, use /api/shared/{token}/documents directly
4968
- // This endpoint does NOT require authentication and returns both document GUID and version GUID
4969
- if (sharedLinkToken) {
4970
- log('Have shared link token, fetching document data via shared API...');
4971
- // fetchDocumentMetadata will use /api/shared/{token}/documents when sharedLinkToken is present
4972
- fetchDocumentMetadata(null, function(docData) {
4973
- if (docData) {
4974
- updateCourseInfoFromApi(docData);
4975
- // Also update document name if available
4976
- if (docData.name) {
4977
- LRS.courseInfo.sharedLinkName = docData.name;
4978
- }
4979
- } else {
4980
- warn('Could not fetch document data from shared API - statements may fail aggregation');
4981
+ // ALWAYS fetch document metadata from the Bravais API.
4982
+ // Even if we have a baked-in GUID, we must override it with the canonical
4983
+ // Bravais GUID so our statements link to the same document as cloudplayer.
4984
+ // The baked-in GUID is a random UUID from wrap time; the Bravais GUID is
4985
+ // assigned at upload and is what Analytics uses for aggregation.
4986
+ if (sharedLinkToken) {
4987
+ log('Have shared link token, fetching document data via shared API...');
4988
+ fetchDocumentMetadata(null, function(docData) {
4989
+ if (docData) {
4990
+ updateCourseInfoFromApi(docData);
4991
+ if (docData.name) {
4992
+ LRS.courseInfo.sharedLinkName = docData.name;
4981
4993
  }
4982
- maybeEnrichAndReady();
4983
- });
4984
- } else if (documentId) {
4985
- // No shared link token, try with extracted document ID (requires auth)
4986
- log('No shared link token, fetching document data with ID:', documentId);
4987
- fetchDocDataAndReady(documentId);
4988
- } else {
4989
- // No identifiers available
4990
- warn('No shared link token or document ID - statements may fail aggregation');
4994
+ } else {
4995
+ warn('Could not fetch document data from shared API - statements may use baked-in GUID');
4996
+ }
4991
4997
  maybeEnrichAndReady();
4992
- }
4998
+ });
4999
+ } else if (documentId) {
5000
+ log('Fetching document data with ID:', documentId);
5001
+ fetchDocDataAndReady(documentId);
4993
5002
  } else {
4994
- // Already have GUID \u2014 still try to enrich packageName if missing
5003
+ // No identifiers available
5004
+ warn('No shared link token or document ID - statements will use baked-in GUID');
4995
5005
  maybeEnrichAndReady();
4996
5006
  }
4997
5007