@patch-adams/core 1.4.6 → 1.4.7

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
@@ -1651,7 +1651,12 @@ function generateLrsBridgeCode(options) {
1651
1651
  callback(null);
1652
1652
  }
1653
1653
  } else {
1654
- warn('Shared link fetch failed. Status:', xhr.status);
1654
+ // 401/403 is expected - API requires auth that may not be available from iframe
1655
+ if (xhr.status === 401 || xhr.status === 403) {
1656
+ log('Shared link API requires auth (expected), will use fallback');
1657
+ } else {
1658
+ log('Shared link fetch failed. Status:', xhr.status);
1659
+ }
1655
1660
  callback(null);
1656
1661
  }
1657
1662
  }
@@ -1726,7 +1731,12 @@ function generateLrsBridgeCode(options) {
1726
1731
  callback(null);
1727
1732
  }
1728
1733
  } else {
1729
- warn('Document metadata fetch failed. Status:', xhr.status, 'Response:', xhr.responseText);
1734
+ // 401/403 is expected - API requires auth that may not be available from iframe
1735
+ if (xhr.status === 401 || xhr.status === 403) {
1736
+ log('Document API requires auth (expected), will use fallback');
1737
+ } else {
1738
+ log('Document metadata fetch failed. Status:', xhr.status);
1739
+ }
1730
1740
  callback(null);
1731
1741
  }
1732
1742
  }
@@ -1889,6 +1899,95 @@ function generateLrsBridgeCode(options) {
1889
1899
  return null;
1890
1900
  }
1891
1901
 
1902
+ /**
1903
+ * Try to extract document data from Xyleme Cloud Player's internal state
1904
+ * The Cloud Player stores this after fetching /api/shared/{token}/documents
1905
+ */
1906
+ function extractFromXylemeCloudPlayer() {
1907
+ try {
1908
+ var win = window;
1909
+ for (var level = 0; level < 10; level++) {
1910
+ try {
1911
+ // Check for Xyleme Cloud Player's document data in various locations
1912
+ // The player stores data in multiple places depending on version
1913
+
1914
+ // Check for CdsDataService data
1915
+ if (win._cdsDataService && win._cdsDataService.documentData) {
1916
+ var docData = win._cdsDataService.documentData;
1917
+ log('Found document data in _cdsDataService at level', level);
1918
+ return extractGuidsFromDocumentData(docData);
1919
+ }
1920
+
1921
+ // Check for window.documentData
1922
+ if (win.documentData && win.documentData.guid) {
1923
+ log('Found document data in window.documentData at level', level);
1924
+ return extractGuidsFromDocumentData(win.documentData);
1925
+ }
1926
+
1927
+ // Check for PlayerIntegration's internal data
1928
+ if (win.playerIntegration && win.playerIntegration._documentData) {
1929
+ log('Found document data in playerIntegration at level', level);
1930
+ return extractGuidsFromDocumentData(win.playerIntegration._documentData);
1931
+ }
1932
+
1933
+ // Check for __xyleme_data
1934
+ if (win.__xyleme_data && win.__xyleme_data.document) {
1935
+ log('Found document data in __xyleme_data at level', level);
1936
+ return extractGuidsFromDocumentData(win.__xyleme_data.document);
1937
+ }
1938
+
1939
+ // Check for documentVersionData which has the versionGuid
1940
+ if (win.documentVersionData) {
1941
+ log('Found documentVersionData at level', level);
1942
+ return {
1943
+ versionGuid: win.documentVersionData.guid || win.documentVersionData.versionGuid,
1944
+ documentId: win.documentVersionData.documentId
1945
+ };
1946
+ }
1947
+
1948
+ } catch (e) {}
1949
+
1950
+ if (win.parent && win.parent !== win) {
1951
+ win = win.parent;
1952
+ } else {
1953
+ break;
1954
+ }
1955
+ }
1956
+ } catch (e) {}
1957
+ return null;
1958
+ }
1959
+
1960
+ function extractGuidsFromDocumentData(data) {
1961
+ if (!data) return null;
1962
+
1963
+ var result = {};
1964
+
1965
+ // Document GUID
1966
+ if (data.guid) result.guid = data.guid;
1967
+ if (data.documentGuid) result.guid = data.documentGuid;
1968
+
1969
+ // Version GUID - usually in latestVersion or currentVersion
1970
+ if (data.latestVersion && data.latestVersion.guid) {
1971
+ result.versionGuid = data.latestVersion.guid;
1972
+ }
1973
+ if (data.currentVersion && data.currentVersion.guid) {
1974
+ result.versionGuid = data.currentVersion.guid;
1975
+ }
1976
+ if (data.versionGuid) result.versionGuid = data.versionGuid;
1977
+
1978
+ // Numeric IDs
1979
+ if (data.id) result.documentId = data.id;
1980
+ if (data.documentId) result.documentId = data.documentId;
1981
+ if (data.cdsId) result.documentId = data.cdsId;
1982
+
1983
+ // Title
1984
+ if (data.name) result.title = data.name;
1985
+ if (data.title) result.title = data.title;
1986
+
1987
+ log('Extracted GUIDs from Cloud Player:', result);
1988
+ return Object.keys(result).length > 0 ? result : null;
1989
+ }
1990
+
1892
1991
  function extractCourseInfo() {
1893
1992
  var info = {
1894
1993
  // Xyleme IRI format: http://xyleme.com/bravais/document/{guid}
@@ -1944,6 +2043,23 @@ function generateLrsBridgeCode(options) {
1944
2043
  info.sharedLinkName = launchInfo.sharedLinkName || info.sharedLinkName;
1945
2044
  }
1946
2045
 
2046
+ // 3b. Try to extract GUIDs from Xyleme Cloud Player's internal data
2047
+ // This is more reliable than API calls which may fail with 401
2048
+ if (!info.guid || !info.versionGuid) {
2049
+ var cloudPlayerData = extractFromXylemeCloudPlayer();
2050
+ if (cloudPlayerData) {
2051
+ info.guid = cloudPlayerData.guid || info.guid;
2052
+ info.versionGuid = cloudPlayerData.versionGuid || info.versionGuid;
2053
+ info.documentId = cloudPlayerData.documentId || info.documentId;
2054
+ info.title = cloudPlayerData.title || info.title;
2055
+ log('Updated course info from Cloud Player:', {
2056
+ guid: info.guid,
2057
+ versionGuid: info.versionGuid,
2058
+ documentId: info.documentId
2059
+ });
2060
+ }
2061
+ }
2062
+
1947
2063
  // 4. Try getCourseTitle() from preloadIntegrity.js
1948
2064
  var preloadTitle = extractCourseTitleFromPreload();
1949
2065
  if (preloadTitle) {
@@ -3449,7 +3565,7 @@ function generateLrsBridgeCode(options) {
3449
3565
  // ========================================================================
3450
3566
 
3451
3567
  function init() {
3452
- log('Initializing LRS bridge v2.5.1...');
3568
+ log('Initializing LRS bridge v2.6.0...');
3453
3569
 
3454
3570
  // Extract course info early
3455
3571
  extractCourseInfo();