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