@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/index.js CHANGED
@@ -1676,15 +1676,11 @@ function generateLrsBridgeCode(options) {
1676
1676
  }
1677
1677
 
1678
1678
  /**
1679
- * Fetch document metadata from Bravais API to get GUIDs
1680
- * Endpoint: /api/v3/documents/{documentId}
1679
+ * Fetch document metadata from Bravais shared API to get GUIDs
1680
+ * PRIMARY endpoint: /api/shared/{token}/documents (does NOT require auth)
1681
+ * FALLBACK endpoint: /api/v3/documents/{documentId} (requires auth)
1681
1682
  */
1682
- function fetchDocumentMetadata(documentId, callback) {
1683
- if (!documentId) {
1684
- callback(null);
1685
- return;
1686
- }
1687
-
1683
+ function fetchDocumentMetadata(documentIdOrToken, callback) {
1688
1684
  if (documentApiFetched) {
1689
1685
  callback(documentApiData);
1690
1686
  return;
@@ -1698,8 +1694,24 @@ function generateLrsBridgeCode(options) {
1698
1694
  return;
1699
1695
  }
1700
1696
 
1701
- var apiUrl = coreUrl + '/api/v3/documents/' + documentId;
1702
- log('Fetching document metadata from:', apiUrl);
1697
+ // Determine which endpoint to use
1698
+ // If we have a shared link token, use /api/shared/{token}/documents (no auth required)
1699
+ // This is the same endpoint Xyleme Cloud Player uses
1700
+ var sharedToken = LRS.courseInfo ? LRS.courseInfo.sharedLinkToken : null;
1701
+ var apiUrl;
1702
+
1703
+ if (sharedToken) {
1704
+ apiUrl = coreUrl + '/api/shared/' + sharedToken + '/documents';
1705
+ log('Fetching document via shared API (no auth required):', apiUrl);
1706
+ } else if (documentIdOrToken) {
1707
+ apiUrl = coreUrl + '/api/v3/documents/' + documentIdOrToken;
1708
+ log('Fetching document via v3 API (requires auth):', apiUrl);
1709
+ } else {
1710
+ log('No shared token or document ID available for metadata fetch');
1711
+ documentApiFetched = true;
1712
+ callback(null);
1713
+ return;
1714
+ }
1703
1715
 
1704
1716
  var xhr = new XMLHttpRequest();
1705
1717
  xhr.open('GET', apiUrl, true);
@@ -3634,32 +3646,25 @@ function generateLrsBridgeCode(options) {
3634
3646
  }
3635
3647
 
3636
3648
  if (!LRS.courseInfo.guid) {
3637
- // First, try to get real document ID from shared link token
3638
- // The URL path contains a thin pack file ID, not the real document ID
3649
+ // When we have a shared link token, use /api/shared/{token}/documents directly
3650
+ // This endpoint does NOT require authentication and returns both document GUID and version GUID
3639
3651
  if (sharedLinkToken) {
3640
- log('Fetching shared link data to get real document ID...');
3641
- fetchSharedLinkData(sharedLinkToken, function(linkData) {
3642
- if (linkData && linkData.documentId) {
3643
- // Got the real document ID from shared link
3644
- log('Got real document ID from shared link:', linkData.documentId);
3645
- LRS.courseInfo.documentId = linkData.documentId;
3646
- // Update shared link name if available
3647
- if (linkData.documentName) {
3648
- LRS.courseInfo.sharedLinkName = linkData.documentName;
3652
+ log('Have shared link token, fetching document data via shared API...');
3653
+ // fetchDocumentMetadata will use /api/shared/{token}/documents when sharedLinkToken is present
3654
+ fetchDocumentMetadata(null, function(docData) {
3655
+ if (docData) {
3656
+ updateCourseInfoFromApi(docData);
3657
+ // Also update document name if available
3658
+ if (docData.name) {
3659
+ LRS.courseInfo.sharedLinkName = docData.name;
3649
3660
  }
3650
- fetchDocDataAndSend(linkData.documentId);
3651
- } else if (documentId) {
3652
- // Fallback to extracted document ID (may be thin pack ID)
3653
- warn('Could not get document ID from shared link, using extracted ID:', documentId);
3654
- fetchDocDataAndSend(documentId);
3655
3661
  } else {
3656
- // No document ID available
3657
- warn('No document ID available - statements may fail aggregation');
3658
- setTimeout(sendLaunchEvents, 100);
3662
+ warn('Could not fetch document data from shared API - statements may fail aggregation');
3659
3663
  }
3664
+ setTimeout(sendLaunchEvents, 100);
3660
3665
  });
3661
3666
  } else if (documentId) {
3662
- // No shared link token, try with extracted document ID
3667
+ // No shared link token, try with extracted document ID (requires auth)
3663
3668
  log('No shared link token, fetching document data with ID:', documentId);
3664
3669
  fetchDocDataAndSend(documentId);
3665
3670
  } else {