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