@patch-adams/core 1.4.7 → 1.4.9

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);
@@ -2643,6 +2655,22 @@ function generateLrsBridgeCode(options) {
2643
2655
  // This allows filtering by type (video, assessment, interaction) in Analytics
2644
2656
  if (activityType) {
2645
2657
  courseObj.definition.type = activityType;
2658
+
2659
+ // Also update resourceType extension to human-readable form for Bravais Type column
2660
+ courseObj.definition.extensions = courseObj.definition.extensions || {};
2661
+ var resourceTypeMap = {
2662
+ 'https://w3id.org/xapi/video/activity-type/video': 'Video',
2663
+ 'https://w3id.org/xapi/audio/activity-type/audio': 'Audio',
2664
+ 'http://adlnet.gov/expapi/activities/media': 'Media',
2665
+ 'http://adlnet.gov/expapi/activities/assessment': 'Assessment',
2666
+ 'http://adlnet.gov/expapi/activities/question': 'Question',
2667
+ 'http://adlnet.gov/expapi/activities/interaction': 'Interaction',
2668
+ 'http://adlnet.gov/expapi/activities/lesson': 'Lesson',
2669
+ 'http://adlnet.gov/expapi/activities/module': 'Module',
2670
+ 'http://adlnet.gov/expapi/activities/course': 'Course',
2671
+ 'http://xyleme.com/bravais/activities/document': 'Course'
2672
+ };
2673
+ courseObj.definition.extensions['resourceType'] = resourceTypeMap[activityType] || 'Course';
2646
2674
  }
2647
2675
 
2648
2676
  // Add activity-specific details to extensions
@@ -3978,32 +4006,25 @@ function generateLrsBridgeCode(options) {
3978
4006
  }
3979
4007
 
3980
4008
  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
4009
+ // When we have a shared link token, use /api/shared/{token}/documents directly
4010
+ // This endpoint does NOT require authentication and returns both document GUID and version GUID
3983
4011
  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;
4012
+ log('Have shared link token, fetching document data via shared API...');
4013
+ // fetchDocumentMetadata will use /api/shared/{token}/documents when sharedLinkToken is present
4014
+ fetchDocumentMetadata(null, function(docData) {
4015
+ if (docData) {
4016
+ updateCourseInfoFromApi(docData);
4017
+ // Also update document name if available
4018
+ if (docData.name) {
4019
+ LRS.courseInfo.sharedLinkName = docData.name;
3993
4020
  }
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
4021
  } else {
4000
- // No document ID available
4001
- warn('No document ID available - statements may fail aggregation');
4002
- setTimeout(sendLaunchEvents, 100);
4022
+ warn('Could not fetch document data from shared API - statements may fail aggregation');
4003
4023
  }
4024
+ setTimeout(sendLaunchEvents, 100);
4004
4025
  });
4005
4026
  } else if (documentId) {
4006
- // No shared link token, try with extracted document ID
4027
+ // No shared link token, try with extracted document ID (requires auth)
4007
4028
  log('No shared link token, fetching document data with ID:', documentId);
4008
4029
  fetchDocDataAndSend(documentId);
4009
4030
  } else {