@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/cli.cjs
CHANGED
|
@@ -1906,6 +1906,132 @@ function generateLrsBridgeCode(options) {
|
|
|
1906
1906
|
return null;
|
|
1907
1907
|
}
|
|
1908
1908
|
|
|
1909
|
+
// Store for document API data
|
|
1910
|
+
var documentApiData = null;
|
|
1911
|
+
var documentApiFetched = false;
|
|
1912
|
+
|
|
1913
|
+
/**
|
|
1914
|
+
* Fetch document metadata from Bravais API to get GUIDs
|
|
1915
|
+
* Endpoint: /api/v3/documents/{documentId}
|
|
1916
|
+
*/
|
|
1917
|
+
function fetchDocumentMetadata(documentId, callback) {
|
|
1918
|
+
if (!documentId) {
|
|
1919
|
+
callback(null);
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
if (documentApiFetched) {
|
|
1924
|
+
callback(documentApiData);
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
// Detect Bravais core URL
|
|
1929
|
+
var coreUrl = null;
|
|
1930
|
+
var urlsToCheck = [window.location.href, document.referrer];
|
|
1931
|
+
|
|
1932
|
+
try {
|
|
1933
|
+
var win = window;
|
|
1934
|
+
for (var i = 0; i < 10; i++) {
|
|
1935
|
+
if (win.parent && win.parent !== win) {
|
|
1936
|
+
win = win.parent;
|
|
1937
|
+
try {
|
|
1938
|
+
urlsToCheck.push(win.location.href);
|
|
1939
|
+
} catch (e) { break; }
|
|
1940
|
+
} else { break; }
|
|
1941
|
+
}
|
|
1942
|
+
} catch (e) {}
|
|
1943
|
+
|
|
1944
|
+
for (var j = 0; j < urlsToCheck.length; j++) {
|
|
1945
|
+
var match = urlsToCheck[j].match(/(https?:\\/\\/core-[a-zA-Z0-9_-]+\\.bravais\\.com)/);
|
|
1946
|
+
if (match) {
|
|
1947
|
+
coreUrl = match[1];
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
if (!coreUrl) {
|
|
1953
|
+
log('No Bravais core URL detected for document metadata fetch');
|
|
1954
|
+
documentApiFetched = true;
|
|
1955
|
+
callback(null);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
var apiUrl = coreUrl + '/api/v3/documents/' + documentId;
|
|
1960
|
+
log('Fetching document metadata from:', apiUrl);
|
|
1961
|
+
|
|
1962
|
+
var xhr = new XMLHttpRequest();
|
|
1963
|
+
xhr.open('GET', apiUrl, true);
|
|
1964
|
+
xhr.withCredentials = true;
|
|
1965
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
|
1966
|
+
|
|
1967
|
+
xhr.onreadystatechange = function() {
|
|
1968
|
+
if (xhr.readyState === 4) {
|
|
1969
|
+
documentApiFetched = true;
|
|
1970
|
+
log('Document API response status:', xhr.status);
|
|
1971
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
1972
|
+
try {
|
|
1973
|
+
documentApiData = JSON.parse(xhr.responseText);
|
|
1974
|
+
log('Document metadata received:', documentApiData);
|
|
1975
|
+
callback(documentApiData);
|
|
1976
|
+
} catch (e) {
|
|
1977
|
+
warn('Error parsing document metadata:', e);
|
|
1978
|
+
callback(null);
|
|
1979
|
+
}
|
|
1980
|
+
} else {
|
|
1981
|
+
log('Document metadata fetch failed. Status:', xhr.status);
|
|
1982
|
+
callback(null);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
};
|
|
1986
|
+
|
|
1987
|
+
xhr.onerror = function() {
|
|
1988
|
+
documentApiFetched = true;
|
|
1989
|
+
log('Network error fetching document metadata');
|
|
1990
|
+
callback(null);
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
try {
|
|
1994
|
+
xhr.send();
|
|
1995
|
+
} catch (e) {
|
|
1996
|
+
documentApiFetched = true;
|
|
1997
|
+
warn('Error sending document request:', e);
|
|
1998
|
+
callback(null);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Update course info with data from document API
|
|
2004
|
+
*/
|
|
2005
|
+
function updateCourseInfoFromApi(docData) {
|
|
2006
|
+
if (!docData || !LRS.courseInfo) return;
|
|
2007
|
+
|
|
2008
|
+
// Document GUID
|
|
2009
|
+
if (docData.guid && !LRS.courseInfo.guid) {
|
|
2010
|
+
LRS.courseInfo.guid = docData.guid;
|
|
2011
|
+
LRS.courseInfo.id = 'http://xyleme.com/bravais/document/' + docData.guid;
|
|
2012
|
+
log('Updated course guid from API:', docData.guid);
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
// Version GUID from latestVersion
|
|
2016
|
+
if (docData.latestVersion && docData.latestVersion.guid && !LRS.courseInfo.versionGuid) {
|
|
2017
|
+
LRS.courseInfo.versionGuid = docData.latestVersion.guid;
|
|
2018
|
+
log('Updated version guid from API:', docData.latestVersion.guid);
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
// Other metadata
|
|
2022
|
+
if (docData.name && LRS.courseInfo.title === 'Rise Course') {
|
|
2023
|
+
LRS.courseInfo.title = docData.name;
|
|
2024
|
+
}
|
|
2025
|
+
if (docData.format) {
|
|
2026
|
+
LRS.courseInfo.format = docData.format;
|
|
2027
|
+
}
|
|
2028
|
+
if (docData.resourceType) {
|
|
2029
|
+
LRS.courseInfo.resourceType = docData.resourceType;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
log('Course info updated from API:', LRS.courseInfo);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
1909
2035
|
/**
|
|
1910
2036
|
* Extract Bravais document ID from URL
|
|
1911
2037
|
* Pattern: /api/shared/.../files/{documentId}/scormcontent/
|
|
@@ -3140,7 +3266,7 @@ function generateLrsBridgeCode(options) {
|
|
|
3140
3266
|
// ========================================================================
|
|
3141
3267
|
|
|
3142
3268
|
function init() {
|
|
3143
|
-
log('Initializing LRS bridge v2.
|
|
3269
|
+
log('Initializing LRS bridge v2.2.0...');
|
|
3144
3270
|
|
|
3145
3271
|
// Extract course info early
|
|
3146
3272
|
extractCourseInfo();
|
|
@@ -3174,8 +3300,11 @@ function generateLrsBridgeCode(options) {
|
|
|
3174
3300
|
setupQuizInterceptors();
|
|
3175
3301
|
setupInteractionInterceptors();
|
|
3176
3302
|
|
|
3177
|
-
//
|
|
3178
|
-
|
|
3303
|
+
// Fetch document metadata from API to get GUIDs (async)
|
|
3304
|
+
// Then send course launched event
|
|
3305
|
+
var documentId = LRS.courseInfo ? LRS.courseInfo.documentId : null;
|
|
3306
|
+
|
|
3307
|
+
function sendLaunchEvents() {
|
|
3179
3308
|
if (TRACK_NAVIGATION) {
|
|
3180
3309
|
LRS.courseLaunched();
|
|
3181
3310
|
LRS.contentOpened({
|
|
@@ -3184,7 +3313,21 @@ function generateLrsBridgeCode(options) {
|
|
|
3184
3313
|
action: 'launched'
|
|
3185
3314
|
});
|
|
3186
3315
|
}
|
|
3187
|
-
}
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
if (documentId && !LRS.courseInfo.guid) {
|
|
3319
|
+
// Try to fetch GUIDs from API before sending statements
|
|
3320
|
+
fetchDocumentMetadata(documentId, function(docData) {
|
|
3321
|
+
if (docData) {
|
|
3322
|
+
updateCourseInfoFromApi(docData);
|
|
3323
|
+
}
|
|
3324
|
+
// Send launch events after API fetch (success or failure)
|
|
3325
|
+
setTimeout(sendLaunchEvents, 100);
|
|
3326
|
+
});
|
|
3327
|
+
} else {
|
|
3328
|
+
// Already have GUID or no document ID - send after short delay
|
|
3329
|
+
setTimeout(sendLaunchEvents, 500);
|
|
3330
|
+
}
|
|
3188
3331
|
|
|
3189
3332
|
// Setup beforeunload to send terminated
|
|
3190
3333
|
window.addEventListener('beforeunload', function() {
|