@patch-adams/core 1.3.4 → 1.3.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/cli.cjs +147 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +147 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +147 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +147 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1562,6 +1562,132 @@ function generateLrsBridgeCode(options) {
|
|
|
1562
1562
|
return null;
|
|
1563
1563
|
}
|
|
1564
1564
|
|
|
1565
|
+
// Store for document API data
|
|
1566
|
+
var documentApiData = null;
|
|
1567
|
+
var documentApiFetched = false;
|
|
1568
|
+
|
|
1569
|
+
/**
|
|
1570
|
+
* Fetch document metadata from Bravais API to get GUIDs
|
|
1571
|
+
* Endpoint: /api/v3/documents/{documentId}
|
|
1572
|
+
*/
|
|
1573
|
+
function fetchDocumentMetadata(documentId, callback) {
|
|
1574
|
+
if (!documentId) {
|
|
1575
|
+
callback(null);
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
if (documentApiFetched) {
|
|
1580
|
+
callback(documentApiData);
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// Detect Bravais core URL
|
|
1585
|
+
var coreUrl = null;
|
|
1586
|
+
var urlsToCheck = [window.location.href, document.referrer];
|
|
1587
|
+
|
|
1588
|
+
try {
|
|
1589
|
+
var win = window;
|
|
1590
|
+
for (var i = 0; i < 10; i++) {
|
|
1591
|
+
if (win.parent && win.parent !== win) {
|
|
1592
|
+
win = win.parent;
|
|
1593
|
+
try {
|
|
1594
|
+
urlsToCheck.push(win.location.href);
|
|
1595
|
+
} catch (e) { break; }
|
|
1596
|
+
} else { break; }
|
|
1597
|
+
}
|
|
1598
|
+
} catch (e) {}
|
|
1599
|
+
|
|
1600
|
+
for (var j = 0; j < urlsToCheck.length; j++) {
|
|
1601
|
+
var match = urlsToCheck[j].match(/(https?:\\/\\/core-[a-zA-Z0-9_-]+\\.bravais\\.com)/);
|
|
1602
|
+
if (match) {
|
|
1603
|
+
coreUrl = match[1];
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
if (!coreUrl) {
|
|
1609
|
+
log('No Bravais core URL detected for document metadata fetch');
|
|
1610
|
+
documentApiFetched = true;
|
|
1611
|
+
callback(null);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
var apiUrl = coreUrl + '/api/v3/documents/' + documentId;
|
|
1616
|
+
log('Fetching document metadata from:', apiUrl);
|
|
1617
|
+
|
|
1618
|
+
var xhr = new XMLHttpRequest();
|
|
1619
|
+
xhr.open('GET', apiUrl, true);
|
|
1620
|
+
xhr.withCredentials = true;
|
|
1621
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
|
1622
|
+
|
|
1623
|
+
xhr.onreadystatechange = function() {
|
|
1624
|
+
if (xhr.readyState === 4) {
|
|
1625
|
+
documentApiFetched = true;
|
|
1626
|
+
log('Document API response status:', xhr.status);
|
|
1627
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
1628
|
+
try {
|
|
1629
|
+
documentApiData = JSON.parse(xhr.responseText);
|
|
1630
|
+
log('Document metadata received:', documentApiData);
|
|
1631
|
+
callback(documentApiData);
|
|
1632
|
+
} catch (e) {
|
|
1633
|
+
warn('Error parsing document metadata:', e);
|
|
1634
|
+
callback(null);
|
|
1635
|
+
}
|
|
1636
|
+
} else {
|
|
1637
|
+
log('Document metadata fetch failed. Status:', xhr.status);
|
|
1638
|
+
callback(null);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
xhr.onerror = function() {
|
|
1644
|
+
documentApiFetched = true;
|
|
1645
|
+
log('Network error fetching document metadata');
|
|
1646
|
+
callback(null);
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
try {
|
|
1650
|
+
xhr.send();
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
documentApiFetched = true;
|
|
1653
|
+
warn('Error sending document request:', e);
|
|
1654
|
+
callback(null);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Update course info with data from document API
|
|
1660
|
+
*/
|
|
1661
|
+
function updateCourseInfoFromApi(docData) {
|
|
1662
|
+
if (!docData || !LRS.courseInfo) return;
|
|
1663
|
+
|
|
1664
|
+
// Document GUID
|
|
1665
|
+
if (docData.guid && !LRS.courseInfo.guid) {
|
|
1666
|
+
LRS.courseInfo.guid = docData.guid;
|
|
1667
|
+
LRS.courseInfo.id = 'http://xyleme.com/bravais/document/' + docData.guid;
|
|
1668
|
+
log('Updated course guid from API:', docData.guid);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// Version GUID from latestVersion
|
|
1672
|
+
if (docData.latestVersion && docData.latestVersion.guid && !LRS.courseInfo.versionGuid) {
|
|
1673
|
+
LRS.courseInfo.versionGuid = docData.latestVersion.guid;
|
|
1674
|
+
log('Updated version guid from API:', docData.latestVersion.guid);
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// Other metadata
|
|
1678
|
+
if (docData.name && LRS.courseInfo.title === 'Rise Course') {
|
|
1679
|
+
LRS.courseInfo.title = docData.name;
|
|
1680
|
+
}
|
|
1681
|
+
if (docData.format) {
|
|
1682
|
+
LRS.courseInfo.format = docData.format;
|
|
1683
|
+
}
|
|
1684
|
+
if (docData.resourceType) {
|
|
1685
|
+
LRS.courseInfo.resourceType = docData.resourceType;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
log('Course info updated from API:', LRS.courseInfo);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1565
1691
|
/**
|
|
1566
1692
|
* Extract Bravais document ID from URL
|
|
1567
1693
|
* Pattern: /api/shared/.../files/{documentId}/scormcontent/
|
|
@@ -2796,7 +2922,7 @@ function generateLrsBridgeCode(options) {
|
|
|
2796
2922
|
// ========================================================================
|
|
2797
2923
|
|
|
2798
2924
|
function init() {
|
|
2799
|
-
log('Initializing LRS bridge v2.
|
|
2925
|
+
log('Initializing LRS bridge v2.2.0...');
|
|
2800
2926
|
|
|
2801
2927
|
// Extract course info early
|
|
2802
2928
|
extractCourseInfo();
|
|
@@ -2830,8 +2956,11 @@ function generateLrsBridgeCode(options) {
|
|
|
2830
2956
|
setupQuizInterceptors();
|
|
2831
2957
|
setupInteractionInterceptors();
|
|
2832
2958
|
|
|
2833
|
-
//
|
|
2834
|
-
|
|
2959
|
+
// Fetch document metadata from API to get GUIDs (async)
|
|
2960
|
+
// Then send course launched event
|
|
2961
|
+
var documentId = LRS.courseInfo ? LRS.courseInfo.documentId : null;
|
|
2962
|
+
|
|
2963
|
+
function sendLaunchEvents() {
|
|
2835
2964
|
if (TRACK_NAVIGATION) {
|
|
2836
2965
|
LRS.courseLaunched();
|
|
2837
2966
|
LRS.contentOpened({
|
|
@@ -2840,7 +2969,21 @@ function generateLrsBridgeCode(options) {
|
|
|
2840
2969
|
action: 'launched'
|
|
2841
2970
|
});
|
|
2842
2971
|
}
|
|
2843
|
-
}
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
if (documentId && !LRS.courseInfo.guid) {
|
|
2975
|
+
// Try to fetch GUIDs from API before sending statements
|
|
2976
|
+
fetchDocumentMetadata(documentId, function(docData) {
|
|
2977
|
+
if (docData) {
|
|
2978
|
+
updateCourseInfoFromApi(docData);
|
|
2979
|
+
}
|
|
2980
|
+
// Send launch events after API fetch (success or failure)
|
|
2981
|
+
setTimeout(sendLaunchEvents, 100);
|
|
2982
|
+
});
|
|
2983
|
+
} else {
|
|
2984
|
+
// Already have GUID or no document ID - send after short delay
|
|
2985
|
+
setTimeout(sendLaunchEvents, 500);
|
|
2986
|
+
}
|
|
2844
2987
|
|
|
2845
2988
|
// Setup beforeunload to send terminated
|
|
2846
2989
|
window.addEventListener('beforeunload', function() {
|