@patch-adams/core 1.4.7 → 1.4.8

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.js CHANGED
@@ -2011,15 +2011,11 @@ function generateLrsBridgeCode(options) {
2011
2011
  }
2012
2012
 
2013
2013
  /**
2014
- * Fetch document metadata from Bravais API to get GUIDs
2015
- * Endpoint: /api/v3/documents/{documentId}
2014
+ * Fetch document metadata from Bravais shared API to get GUIDs
2015
+ * PRIMARY endpoint: /api/shared/{token}/documents (does NOT require auth)
2016
+ * FALLBACK endpoint: /api/v3/documents/{documentId} (requires auth)
2016
2017
  */
2017
- function fetchDocumentMetadata(documentId, callback) {
2018
- if (!documentId) {
2019
- callback(null);
2020
- return;
2021
- }
2022
-
2018
+ function fetchDocumentMetadata(documentIdOrToken, callback) {
2023
2019
  if (documentApiFetched) {
2024
2020
  callback(documentApiData);
2025
2021
  return;
@@ -2033,8 +2029,24 @@ function generateLrsBridgeCode(options) {
2033
2029
  return;
2034
2030
  }
2035
2031
 
2036
- var apiUrl = coreUrl + '/api/v3/documents/' + documentId;
2037
- log('Fetching document metadata from:', apiUrl);
2032
+ // Determine which endpoint to use
2033
+ // If we have a shared link token, use /api/shared/{token}/documents (no auth required)
2034
+ // This is the same endpoint Xyleme Cloud Player uses
2035
+ var sharedToken = LRS.courseInfo ? LRS.courseInfo.sharedLinkToken : null;
2036
+ var apiUrl;
2037
+
2038
+ if (sharedToken) {
2039
+ apiUrl = coreUrl + '/api/shared/' + sharedToken + '/documents';
2040
+ log('Fetching document via shared API (no auth required):', apiUrl);
2041
+ } else if (documentIdOrToken) {
2042
+ apiUrl = coreUrl + '/api/v3/documents/' + documentIdOrToken;
2043
+ log('Fetching document via v3 API (requires auth):', apiUrl);
2044
+ } else {
2045
+ log('No shared token or document ID available for metadata fetch');
2046
+ documentApiFetched = true;
2047
+ callback(null);
2048
+ return;
2049
+ }
2038
2050
 
2039
2051
  var xhr = new XMLHttpRequest();
2040
2052
  xhr.open('GET', apiUrl, true);
@@ -3969,32 +3981,25 @@ function generateLrsBridgeCode(options) {
3969
3981
  }
3970
3982
 
3971
3983
  if (!LRS.courseInfo.guid) {
3972
- // First, try to get real document ID from shared link token
3973
- // The URL path contains a thin pack file ID, not the real document ID
3984
+ // When we have a shared link token, use /api/shared/{token}/documents directly
3985
+ // This endpoint does NOT require authentication and returns both document GUID and version GUID
3974
3986
  if (sharedLinkToken) {
3975
- log('Fetching shared link data to get real document ID...');
3976
- fetchSharedLinkData(sharedLinkToken, function(linkData) {
3977
- if (linkData && linkData.documentId) {
3978
- // Got the real document ID from shared link
3979
- log('Got real document ID from shared link:', linkData.documentId);
3980
- LRS.courseInfo.documentId = linkData.documentId;
3981
- // Update shared link name if available
3982
- if (linkData.documentName) {
3983
- LRS.courseInfo.sharedLinkName = linkData.documentName;
3987
+ log('Have shared link token, fetching document data via shared API...');
3988
+ // fetchDocumentMetadata will use /api/shared/{token}/documents when sharedLinkToken is present
3989
+ fetchDocumentMetadata(null, function(docData) {
3990
+ if (docData) {
3991
+ updateCourseInfoFromApi(docData);
3992
+ // Also update document name if available
3993
+ if (docData.name) {
3994
+ LRS.courseInfo.sharedLinkName = docData.name;
3984
3995
  }
3985
- fetchDocDataAndSend(linkData.documentId);
3986
- } else if (documentId) {
3987
- // Fallback to extracted document ID (may be thin pack ID)
3988
- warn('Could not get document ID from shared link, using extracted ID:', documentId);
3989
- fetchDocDataAndSend(documentId);
3990
3996
  } else {
3991
- // No document ID available
3992
- warn('No document ID available - statements may fail aggregation');
3993
- setTimeout(sendLaunchEvents, 100);
3997
+ warn('Could not fetch document data from shared API - statements may fail aggregation');
3994
3998
  }
3999
+ setTimeout(sendLaunchEvents, 100);
3995
4000
  });
3996
4001
  } else if (documentId) {
3997
- // No shared link token, try with extracted document ID
4002
+ // No shared link token, try with extracted document ID (requires auth)
3998
4003
  log('No shared link token, fetching document data with ID:', documentId);
3999
4004
  fetchDocDataAndSend(documentId);
4000
4005
  } else {