@patch-adams/core 1.4.0 → 1.4.2
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 +156 -24
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +156 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +156 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +156 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1909,24 +1909,12 @@ function generateLrsBridgeCode(options) {
|
|
|
1909
1909
|
// Store for document API data
|
|
1910
1910
|
var documentApiData = null;
|
|
1911
1911
|
var documentApiFetched = false;
|
|
1912
|
+
var sharedLinkApiData = null;
|
|
1912
1913
|
|
|
1913
1914
|
/**
|
|
1914
|
-
*
|
|
1915
|
-
* Endpoint: /api/v3/documents/{documentId}
|
|
1915
|
+
* Detect Bravais core URL from current page context
|
|
1916
1916
|
*/
|
|
1917
|
-
function
|
|
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;
|
|
1917
|
+
function detectCoreUrl() {
|
|
1930
1918
|
var urlsToCheck = [window.location.href, document.referrer];
|
|
1931
1919
|
|
|
1932
1920
|
try {
|
|
@@ -1942,13 +1930,91 @@ function generateLrsBridgeCode(options) {
|
|
|
1942
1930
|
} catch (e) {}
|
|
1943
1931
|
|
|
1944
1932
|
for (var j = 0; j < urlsToCheck.length; j++) {
|
|
1945
|
-
var match = urlsToCheck[j].match(/(https
|
|
1933
|
+
var match = urlsToCheck[j].match(/(https?://core-[a-zA-Z0-9_-]+.bravais.com)/);
|
|
1946
1934
|
if (match) {
|
|
1947
|
-
|
|
1948
|
-
break;
|
|
1935
|
+
return match[1];
|
|
1949
1936
|
}
|
|
1950
1937
|
}
|
|
1938
|
+
return null;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Fetch shared link data from Bravais API to get the real document ID
|
|
1943
|
+
* Endpoint: /api/v3/sharedLinks/token/{token}
|
|
1944
|
+
* Returns: { documentId, documentName, format, ... }
|
|
1945
|
+
*/
|
|
1946
|
+
function fetchSharedLinkData(token, callback) {
|
|
1947
|
+
if (!token) {
|
|
1948
|
+
callback(null);
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
1951
|
|
|
1952
|
+
var coreUrl = detectCoreUrl();
|
|
1953
|
+
if (!coreUrl) {
|
|
1954
|
+
log('No Bravais core URL detected for shared link fetch');
|
|
1955
|
+
callback(null);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
var apiUrl = coreUrl + '/api/v3/sharedLinks/token/' + token;
|
|
1960
|
+
log('Fetching shared link data 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
|
+
log('Shared link API response status:', xhr.status);
|
|
1970
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
1971
|
+
try {
|
|
1972
|
+
sharedLinkApiData = JSON.parse(xhr.responseText);
|
|
1973
|
+
log('Shared link data received:', sharedLinkApiData);
|
|
1974
|
+
if (sharedLinkApiData.documentId) {
|
|
1975
|
+
log('Real document ID from shared link:', sharedLinkApiData.documentId);
|
|
1976
|
+
}
|
|
1977
|
+
callback(sharedLinkApiData);
|
|
1978
|
+
} catch (e) {
|
|
1979
|
+
warn('Error parsing shared link data:', e);
|
|
1980
|
+
callback(null);
|
|
1981
|
+
}
|
|
1982
|
+
} else {
|
|
1983
|
+
warn('Shared link fetch failed. Status:', xhr.status);
|
|
1984
|
+
callback(null);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
|
|
1989
|
+
xhr.onerror = function() {
|
|
1990
|
+
log('Network error fetching shared link data');
|
|
1991
|
+
callback(null);
|
|
1992
|
+
};
|
|
1993
|
+
|
|
1994
|
+
try {
|
|
1995
|
+
xhr.send();
|
|
1996
|
+
} catch (e) {
|
|
1997
|
+
warn('Error sending shared link request:', e);
|
|
1998
|
+
callback(null);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Fetch document metadata from Bravais API to get GUIDs
|
|
2004
|
+
* Endpoint: /api/v3/documents/{documentId}
|
|
2005
|
+
*/
|
|
2006
|
+
function fetchDocumentMetadata(documentId, callback) {
|
|
2007
|
+
if (!documentId) {
|
|
2008
|
+
callback(null);
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
if (documentApiFetched) {
|
|
2013
|
+
callback(documentApiData);
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
var coreUrl = detectCoreUrl();
|
|
1952
2018
|
if (!coreUrl) {
|
|
1953
2019
|
log('No Bravais core URL detected for document metadata fetch');
|
|
1954
2020
|
documentApiFetched = true;
|
|
@@ -1972,13 +2038,24 @@ function generateLrsBridgeCode(options) {
|
|
|
1972
2038
|
try {
|
|
1973
2039
|
documentApiData = JSON.parse(xhr.responseText);
|
|
1974
2040
|
log('Document metadata received:', documentApiData);
|
|
2041
|
+
// Validate that we got the required fields
|
|
2042
|
+
if (documentApiData.guid) {
|
|
2043
|
+
log('Document GUID found:', documentApiData.guid);
|
|
2044
|
+
} else {
|
|
2045
|
+
warn('Document API response missing guid field!', documentApiData);
|
|
2046
|
+
}
|
|
2047
|
+
if (documentApiData.latestVersion && documentApiData.latestVersion.guid) {
|
|
2048
|
+
log('Version GUID found:', documentApiData.latestVersion.guid);
|
|
2049
|
+
} else {
|
|
2050
|
+
warn('Document API response missing latestVersion.guid field!', documentApiData);
|
|
2051
|
+
}
|
|
1975
2052
|
callback(documentApiData);
|
|
1976
2053
|
} catch (e) {
|
|
1977
2054
|
warn('Error parsing document metadata:', e);
|
|
1978
2055
|
callback(null);
|
|
1979
2056
|
}
|
|
1980
2057
|
} else {
|
|
1981
|
-
|
|
2058
|
+
warn('Document metadata fetch failed. Status:', xhr.status, 'Response:', xhr.responseText);
|
|
1982
2059
|
callback(null);
|
|
1983
2060
|
}
|
|
1984
2061
|
}
|
|
@@ -2362,6 +2439,14 @@ function generateLrsBridgeCode(options) {
|
|
|
2362
2439
|
function buildCourseActivityObject() {
|
|
2363
2440
|
if (!LRS.courseInfo) return null;
|
|
2364
2441
|
|
|
2442
|
+
// Warn if we don't have the required GUIDs for Bravais aggregation
|
|
2443
|
+
if (!LRS.courseInfo.guid) {
|
|
2444
|
+
warn('Missing document GUID - statement may fail Bravais aggregation. Using numeric ID:', LRS.courseInfo.documentId);
|
|
2445
|
+
}
|
|
2446
|
+
if (!LRS.courseInfo.versionGuid) {
|
|
2447
|
+
warn('Missing version GUID - statement may fail Bravais aggregation (document_version_id will be null)');
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2365
2450
|
var obj = {
|
|
2366
2451
|
objectType: 'Activity',
|
|
2367
2452
|
id: LRS.courseInfo.id,
|
|
@@ -2374,10 +2459,13 @@ function generateLrsBridgeCode(options) {
|
|
|
2374
2459
|
// Add Xyleme-format extensions
|
|
2375
2460
|
obj.definition.extensions = {};
|
|
2376
2461
|
|
|
2377
|
-
// Version ID in Xyleme IRI format
|
|
2462
|
+
// Version ID in Xyleme IRI format - REQUIRED for Bravais aggregation
|
|
2378
2463
|
if (LRS.courseInfo.versionGuid) {
|
|
2379
2464
|
obj.definition.extensions['versionId'] =
|
|
2380
2465
|
'http://xyleme.com/bravais/document.version/' + LRS.courseInfo.versionGuid;
|
|
2466
|
+
} else {
|
|
2467
|
+
// Log error - this will cause aggregation failure
|
|
2468
|
+
warn('versionId extension not set - this statement will fail Bravais aggregation!');
|
|
2381
2469
|
}
|
|
2382
2470
|
|
|
2383
2471
|
// Format (e.g., "SCORM by Rise")
|
|
@@ -3302,9 +3390,18 @@ function generateLrsBridgeCode(options) {
|
|
|
3302
3390
|
|
|
3303
3391
|
// Fetch document metadata from API to get GUIDs (async)
|
|
3304
3392
|
// Then send course launched event
|
|
3393
|
+
var sharedLinkToken = LRS.courseInfo ? LRS.courseInfo.sharedLinkToken : null;
|
|
3305
3394
|
var documentId = LRS.courseInfo ? LRS.courseInfo.documentId : null;
|
|
3306
3395
|
|
|
3307
3396
|
function sendLaunchEvents() {
|
|
3397
|
+
// Log the course info state before sending statements
|
|
3398
|
+
log('Sending launch events with course info:', {
|
|
3399
|
+
id: LRS.courseInfo ? LRS.courseInfo.id : null,
|
|
3400
|
+
guid: LRS.courseInfo ? LRS.courseInfo.guid : null,
|
|
3401
|
+
versionGuid: LRS.courseInfo ? LRS.courseInfo.versionGuid : null,
|
|
3402
|
+
documentId: LRS.courseInfo ? LRS.courseInfo.documentId : null
|
|
3403
|
+
});
|
|
3404
|
+
|
|
3308
3405
|
if (TRACK_NAVIGATION) {
|
|
3309
3406
|
LRS.courseLaunched();
|
|
3310
3407
|
LRS.contentOpened({
|
|
@@ -3315,17 +3412,52 @@ function generateLrsBridgeCode(options) {
|
|
|
3315
3412
|
}
|
|
3316
3413
|
}
|
|
3317
3414
|
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
fetchDocumentMetadata(documentId, function(docData) {
|
|
3415
|
+
function fetchDocDataAndSend(docId) {
|
|
3416
|
+
fetchDocumentMetadata(docId, function(docData) {
|
|
3321
3417
|
if (docData) {
|
|
3322
3418
|
updateCourseInfoFromApi(docData);
|
|
3323
3419
|
}
|
|
3324
3420
|
// Send launch events after API fetch (success or failure)
|
|
3325
3421
|
setTimeout(sendLaunchEvents, 100);
|
|
3326
3422
|
});
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
if (!LRS.courseInfo.guid) {
|
|
3426
|
+
// First, try to get real document ID from shared link token
|
|
3427
|
+
// The URL path contains a thin pack file ID, not the real document ID
|
|
3428
|
+
if (sharedLinkToken) {
|
|
3429
|
+
log('Fetching shared link data to get real document ID...');
|
|
3430
|
+
fetchSharedLinkData(sharedLinkToken, function(linkData) {
|
|
3431
|
+
if (linkData && linkData.documentId) {
|
|
3432
|
+
// Got the real document ID from shared link
|
|
3433
|
+
log('Got real document ID from shared link:', linkData.documentId);
|
|
3434
|
+
LRS.courseInfo.documentId = linkData.documentId;
|
|
3435
|
+
// Update shared link name if available
|
|
3436
|
+
if (linkData.documentName) {
|
|
3437
|
+
LRS.courseInfo.sharedLinkName = linkData.documentName;
|
|
3438
|
+
}
|
|
3439
|
+
fetchDocDataAndSend(linkData.documentId);
|
|
3440
|
+
} else if (documentId) {
|
|
3441
|
+
// Fallback to extracted document ID (may be thin pack ID)
|
|
3442
|
+
warn('Could not get document ID from shared link, using extracted ID:', documentId);
|
|
3443
|
+
fetchDocDataAndSend(documentId);
|
|
3444
|
+
} else {
|
|
3445
|
+
// No document ID available
|
|
3446
|
+
warn('No document ID available - statements may fail aggregation');
|
|
3447
|
+
setTimeout(sendLaunchEvents, 100);
|
|
3448
|
+
}
|
|
3449
|
+
});
|
|
3450
|
+
} else if (documentId) {
|
|
3451
|
+
// No shared link token, try with extracted document ID
|
|
3452
|
+
log('No shared link token, fetching document data with ID:', documentId);
|
|
3453
|
+
fetchDocDataAndSend(documentId);
|
|
3454
|
+
} else {
|
|
3455
|
+
// No identifiers available
|
|
3456
|
+
warn('No shared link token or document ID - statements may fail aggregation');
|
|
3457
|
+
setTimeout(sendLaunchEvents, 500);
|
|
3458
|
+
}
|
|
3327
3459
|
} else {
|
|
3328
|
-
// Already have GUID
|
|
3460
|
+
// Already have GUID - send after short delay
|
|
3329
3461
|
setTimeout(sendLaunchEvents, 500);
|
|
3330
3462
|
}
|
|
3331
3463
|
|