@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.cjs CHANGED
@@ -1659,7 +1659,12 @@ function generateLrsBridgeCode(options) {
1659
1659
  callback(null);
1660
1660
  }
1661
1661
  } else {
1662
- warn('Shared link fetch failed. Status:', xhr.status);
1662
+ // 401/403 is expected - API requires auth that may not be available from iframe
1663
+ if (xhr.status === 401 || xhr.status === 403) {
1664
+ log('Shared link API requires auth (expected), will use fallback');
1665
+ } else {
1666
+ log('Shared link fetch failed. Status:', xhr.status);
1667
+ }
1663
1668
  callback(null);
1664
1669
  }
1665
1670
  }
@@ -1734,7 +1739,12 @@ function generateLrsBridgeCode(options) {
1734
1739
  callback(null);
1735
1740
  }
1736
1741
  } else {
1737
- warn('Document metadata fetch failed. Status:', xhr.status, 'Response:', xhr.responseText);
1742
+ // 401/403 is expected - API requires auth that may not be available from iframe
1743
+ if (xhr.status === 401 || xhr.status === 403) {
1744
+ log('Document API requires auth (expected), will use fallback');
1745
+ } else {
1746
+ log('Document metadata fetch failed. Status:', xhr.status);
1747
+ }
1738
1748
  callback(null);
1739
1749
  }
1740
1750
  }
@@ -1897,6 +1907,95 @@ function generateLrsBridgeCode(options) {
1897
1907
  return null;
1898
1908
  }
1899
1909
 
1910
+ /**
1911
+ * Try to extract document data from Xyleme Cloud Player's internal state
1912
+ * The Cloud Player stores this after fetching /api/shared/{token}/documents
1913
+ */
1914
+ function extractFromXylemeCloudPlayer() {
1915
+ try {
1916
+ var win = window;
1917
+ for (var level = 0; level < 10; level++) {
1918
+ try {
1919
+ // Check for Xyleme Cloud Player's document data in various locations
1920
+ // The player stores data in multiple places depending on version
1921
+
1922
+ // Check for CdsDataService data
1923
+ if (win._cdsDataService && win._cdsDataService.documentData) {
1924
+ var docData = win._cdsDataService.documentData;
1925
+ log('Found document data in _cdsDataService at level', level);
1926
+ return extractGuidsFromDocumentData(docData);
1927
+ }
1928
+
1929
+ // Check for window.documentData
1930
+ if (win.documentData && win.documentData.guid) {
1931
+ log('Found document data in window.documentData at level', level);
1932
+ return extractGuidsFromDocumentData(win.documentData);
1933
+ }
1934
+
1935
+ // Check for PlayerIntegration's internal data
1936
+ if (win.playerIntegration && win.playerIntegration._documentData) {
1937
+ log('Found document data in playerIntegration at level', level);
1938
+ return extractGuidsFromDocumentData(win.playerIntegration._documentData);
1939
+ }
1940
+
1941
+ // Check for __xyleme_data
1942
+ if (win.__xyleme_data && win.__xyleme_data.document) {
1943
+ log('Found document data in __xyleme_data at level', level);
1944
+ return extractGuidsFromDocumentData(win.__xyleme_data.document);
1945
+ }
1946
+
1947
+ // Check for documentVersionData which has the versionGuid
1948
+ if (win.documentVersionData) {
1949
+ log('Found documentVersionData at level', level);
1950
+ return {
1951
+ versionGuid: win.documentVersionData.guid || win.documentVersionData.versionGuid,
1952
+ documentId: win.documentVersionData.documentId
1953
+ };
1954
+ }
1955
+
1956
+ } catch (e) {}
1957
+
1958
+ if (win.parent && win.parent !== win) {
1959
+ win = win.parent;
1960
+ } else {
1961
+ break;
1962
+ }
1963
+ }
1964
+ } catch (e) {}
1965
+ return null;
1966
+ }
1967
+
1968
+ function extractGuidsFromDocumentData(data) {
1969
+ if (!data) return null;
1970
+
1971
+ var result = {};
1972
+
1973
+ // Document GUID
1974
+ if (data.guid) result.guid = data.guid;
1975
+ if (data.documentGuid) result.guid = data.documentGuid;
1976
+
1977
+ // Version GUID - usually in latestVersion or currentVersion
1978
+ if (data.latestVersion && data.latestVersion.guid) {
1979
+ result.versionGuid = data.latestVersion.guid;
1980
+ }
1981
+ if (data.currentVersion && data.currentVersion.guid) {
1982
+ result.versionGuid = data.currentVersion.guid;
1983
+ }
1984
+ if (data.versionGuid) result.versionGuid = data.versionGuid;
1985
+
1986
+ // Numeric IDs
1987
+ if (data.id) result.documentId = data.id;
1988
+ if (data.documentId) result.documentId = data.documentId;
1989
+ if (data.cdsId) result.documentId = data.cdsId;
1990
+
1991
+ // Title
1992
+ if (data.name) result.title = data.name;
1993
+ if (data.title) result.title = data.title;
1994
+
1995
+ log('Extracted GUIDs from Cloud Player:', result);
1996
+ return Object.keys(result).length > 0 ? result : null;
1997
+ }
1998
+
1900
1999
  function extractCourseInfo() {
1901
2000
  var info = {
1902
2001
  // Xyleme IRI format: http://xyleme.com/bravais/document/{guid}
@@ -1952,6 +2051,23 @@ function generateLrsBridgeCode(options) {
1952
2051
  info.sharedLinkName = launchInfo.sharedLinkName || info.sharedLinkName;
1953
2052
  }
1954
2053
 
2054
+ // 3b. Try to extract GUIDs from Xyleme Cloud Player's internal data
2055
+ // This is more reliable than API calls which may fail with 401
2056
+ if (!info.guid || !info.versionGuid) {
2057
+ var cloudPlayerData = extractFromXylemeCloudPlayer();
2058
+ if (cloudPlayerData) {
2059
+ info.guid = cloudPlayerData.guid || info.guid;
2060
+ info.versionGuid = cloudPlayerData.versionGuid || info.versionGuid;
2061
+ info.documentId = cloudPlayerData.documentId || info.documentId;
2062
+ info.title = cloudPlayerData.title || info.title;
2063
+ log('Updated course info from Cloud Player:', {
2064
+ guid: info.guid,
2065
+ versionGuid: info.versionGuid,
2066
+ documentId: info.documentId
2067
+ });
2068
+ }
2069
+ }
2070
+
1955
2071
  // 4. Try getCourseTitle() from preloadIntegrity.js
1956
2072
  var preloadTitle = extractCourseTitleFromPreload();
1957
2073
  if (preloadTitle) {
@@ -3457,7 +3573,7 @@ function generateLrsBridgeCode(options) {
3457
3573
  // ========================================================================
3458
3574
 
3459
3575
  function init() {
3460
- log('Initializing LRS bridge v2.5.1...');
3576
+ log('Initializing LRS bridge v2.6.0...');
3461
3577
 
3462
3578
  // Extract course info early
3463
3579
  extractCourseInfo();