@patch-adams/core 1.5.15 → 1.5.17
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 +154 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +154 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +154 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +154 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -2213,6 +2213,69 @@ function generateLrsBridgeCode(options) {
|
|
|
2213
2213
|
}
|
|
2214
2214
|
}
|
|
2215
2215
|
|
|
2216
|
+
/**
|
|
2217
|
+
* Fetch document name from our authenticated server (cdsImporter proxy).
|
|
2218
|
+
* Derives server base URL from LRS_PROXY_ENDPOINT.
|
|
2219
|
+
* Falls back gracefully if CORS blocks or server is unavailable.
|
|
2220
|
+
* This is the final fallback when Bravais API and PARAMS are not available.
|
|
2221
|
+
*/
|
|
2222
|
+
function fetchDocumentNameFromServer(documentId, callback) {
|
|
2223
|
+
if (!LRS_PROXY_ENDPOINT || !documentId) {
|
|
2224
|
+
callback(null);
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
// Derive server base from LRS proxy endpoint
|
|
2229
|
+
// e.g., https://api.example.com/create/statement \u2192 https://api.example.com/create/
|
|
2230
|
+
var serverBase = LRS_PROXY_ENDPOINT.replace(/\\/statement\\/?$/, '/');
|
|
2231
|
+
if (!serverBase || serverBase === LRS_PROXY_ENDPOINT) {
|
|
2232
|
+
log('Could not derive server base URL from LRS_PROXY_ENDPOINT');
|
|
2233
|
+
callback(null);
|
|
2234
|
+
return;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
var apiUrl = serverBase + 'cdsImporter/api/documents/' + documentId;
|
|
2238
|
+
log('Fetching document name from server:', apiUrl);
|
|
2239
|
+
|
|
2240
|
+
var xhr = new XMLHttpRequest();
|
|
2241
|
+
xhr.open('GET', apiUrl, true);
|
|
2242
|
+
xhr.withCredentials = true;
|
|
2243
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
|
2244
|
+
xhr.timeout = 5000;
|
|
2245
|
+
|
|
2246
|
+
xhr.onreadystatechange = function() {
|
|
2247
|
+
if (xhr.readyState === 4) {
|
|
2248
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
2249
|
+
try {
|
|
2250
|
+
var data = JSON.parse(xhr.responseText);
|
|
2251
|
+
if (data.name) {
|
|
2252
|
+
log('Document name from server:', data.name);
|
|
2253
|
+
callback(data.name);
|
|
2254
|
+
} else {
|
|
2255
|
+
callback(null);
|
|
2256
|
+
}
|
|
2257
|
+
} catch (e) {
|
|
2258
|
+
callback(null);
|
|
2259
|
+
}
|
|
2260
|
+
} else {
|
|
2261
|
+
log('Server document lookup returned:', xhr.status);
|
|
2262
|
+
callback(null);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
|
|
2267
|
+
xhr.onerror = function() {
|
|
2268
|
+
log('Server document lookup network error (CORS or connectivity)');
|
|
2269
|
+
callback(null);
|
|
2270
|
+
};
|
|
2271
|
+
xhr.ontimeout = function() {
|
|
2272
|
+
log('Server document lookup timed out');
|
|
2273
|
+
callback(null);
|
|
2274
|
+
};
|
|
2275
|
+
|
|
2276
|
+
try { xhr.send(); } catch (e) { callback(null); }
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2216
2279
|
/**
|
|
2217
2280
|
* Update course info with data from document API
|
|
2218
2281
|
*/
|
|
@@ -2243,6 +2306,19 @@ function generateLrsBridgeCode(options) {
|
|
|
2243
2306
|
LRS.courseInfo.resourceType = docData.resourceType;
|
|
2244
2307
|
}
|
|
2245
2308
|
|
|
2309
|
+
// Update packageName from API document name (matches Bravais Analytics object name)
|
|
2310
|
+
// Only set if not already baked in at wrap time
|
|
2311
|
+
if (docData.name && !LRS.courseInfo.packageName) {
|
|
2312
|
+
LRS.courseInfo.packageName = docData.name;
|
|
2313
|
+
log('Updated packageName from API:', docData.name);
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// Update documentId from API if we didn't have it
|
|
2317
|
+
if (docData.id && !LRS.courseInfo.documentId) {
|
|
2318
|
+
LRS.courseInfo.documentId = String(docData.id);
|
|
2319
|
+
log('Updated documentId from API:', docData.id);
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2246
2322
|
log('Course info updated from API:', LRS.courseInfo);
|
|
2247
2323
|
}
|
|
2248
2324
|
|
|
@@ -2574,7 +2650,61 @@ function generateLrsBridgeCode(options) {
|
|
|
2574
2650
|
info.versionId = paMeta.versionId || info.versionId;
|
|
2575
2651
|
}
|
|
2576
2652
|
|
|
2577
|
-
// 8.
|
|
2653
|
+
// 8. Extract Bravais document name from launch environment (runtime)
|
|
2654
|
+
// This is the name shown in Bravais Analytics and used for search.
|
|
2655
|
+
// Overrides packageName so the statement object name matches the Bravais document.
|
|
2656
|
+
if (!info.packageName) {
|
|
2657
|
+
var bravaisDocName = null;
|
|
2658
|
+
|
|
2659
|
+
// Strategy 1: Walk parent frames for PARAMS.documentName and PARAMS.did
|
|
2660
|
+
try {
|
|
2661
|
+
var win = window;
|
|
2662
|
+
for (var i = 0; i < 10; i++) {
|
|
2663
|
+
try {
|
|
2664
|
+
if (win.PARAMS) {
|
|
2665
|
+
if (win.PARAMS.documentName && !bravaisDocName) {
|
|
2666
|
+
bravaisDocName = win.PARAMS.documentName;
|
|
2667
|
+
log('Bravais document name from PARAMS:', bravaisDocName);
|
|
2668
|
+
}
|
|
2669
|
+
if (win.PARAMS.did && !info.documentId) {
|
|
2670
|
+
info.documentId = String(win.PARAMS.did);
|
|
2671
|
+
log('Bravais document ID from PARAMS.did:', info.documentId);
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
} catch (e) {}
|
|
2675
|
+
if (win === win.parent) break;
|
|
2676
|
+
win = win.parent;
|
|
2677
|
+
}
|
|
2678
|
+
} catch (e) {}
|
|
2679
|
+
|
|
2680
|
+
// Strategy 2: Walk parent frames checking window.name
|
|
2681
|
+
// Bravais sets the iframe name attribute to the document name
|
|
2682
|
+
if (!bravaisDocName) {
|
|
2683
|
+
try {
|
|
2684
|
+
var win = window;
|
|
2685
|
+
for (var i = 0; i < 10; i++) {
|
|
2686
|
+
try {
|
|
2687
|
+
var frameName = win.name;
|
|
2688
|
+
// Document names have hyphens and are long; skip generic frame names
|
|
2689
|
+
if (frameName && frameName.length > 20 && frameName.indexOf('-') > -1 &&
|
|
2690
|
+
frameName.indexOf('scorm') === -1 && frameName.indexOf('API') === -1) {
|
|
2691
|
+
bravaisDocName = frameName;
|
|
2692
|
+
log('Bravais document name from frame name:', bravaisDocName);
|
|
2693
|
+
break;
|
|
2694
|
+
}
|
|
2695
|
+
} catch (e) {}
|
|
2696
|
+
if (win === win.parent) break;
|
|
2697
|
+
win = win.parent;
|
|
2698
|
+
}
|
|
2699
|
+
} catch (e) {}
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
if (bravaisDocName) {
|
|
2703
|
+
info.packageName = bravaisDocName;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
// 9. Build the course ID in Xyleme IRI format
|
|
2578
2708
|
// Native format: http://xyleme.com/bravais/document/{guid}
|
|
2579
2709
|
if (info.guid) {
|
|
2580
2710
|
info.id = 'http://xyleme.com/bravais/document/' + info.guid;
|
|
@@ -5147,12 +5277,30 @@ function generateLrsBridgeCode(options) {
|
|
|
5147
5277
|
tryLaunchEvents();
|
|
5148
5278
|
}
|
|
5149
5279
|
|
|
5280
|
+
// After Bravais API metadata resolves, try our authenticated server as a
|
|
5281
|
+
// final fallback to get the document name for packageName.
|
|
5282
|
+
// This handles cases where PARAMS is cross-origin blocked and no baked name exists.
|
|
5283
|
+
function maybeEnrichAndReady() {
|
|
5284
|
+
if (LRS.courseInfo.packageName || !LRS.courseInfo.documentId || !LRS_PROXY_ENDPOINT) {
|
|
5285
|
+
onDocReady();
|
|
5286
|
+
return;
|
|
5287
|
+
}
|
|
5288
|
+
log('No packageName yet, trying server-side document lookup for ID:', LRS.courseInfo.documentId);
|
|
5289
|
+
fetchDocumentNameFromServer(LRS.courseInfo.documentId, function(name) {
|
|
5290
|
+
if (name) {
|
|
5291
|
+
LRS.courseInfo.packageName = name;
|
|
5292
|
+
log('Set packageName from server lookup:', name);
|
|
5293
|
+
}
|
|
5294
|
+
onDocReady();
|
|
5295
|
+
});
|
|
5296
|
+
}
|
|
5297
|
+
|
|
5150
5298
|
function fetchDocDataAndReady(docId) {
|
|
5151
5299
|
fetchDocumentMetadata(docId, function(docData) {
|
|
5152
5300
|
if (docData) {
|
|
5153
5301
|
updateCourseInfoFromApi(docData);
|
|
5154
5302
|
}
|
|
5155
|
-
|
|
5303
|
+
maybeEnrichAndReady();
|
|
5156
5304
|
});
|
|
5157
5305
|
}
|
|
5158
5306
|
|
|
@@ -5172,7 +5320,7 @@ function generateLrsBridgeCode(options) {
|
|
|
5172
5320
|
} else {
|
|
5173
5321
|
warn('Could not fetch document data from shared API - statements may fail aggregation');
|
|
5174
5322
|
}
|
|
5175
|
-
|
|
5323
|
+
maybeEnrichAndReady();
|
|
5176
5324
|
});
|
|
5177
5325
|
} else if (documentId) {
|
|
5178
5326
|
// No shared link token, try with extracted document ID (requires auth)
|
|
@@ -5181,11 +5329,11 @@ function generateLrsBridgeCode(options) {
|
|
|
5181
5329
|
} else {
|
|
5182
5330
|
// No identifiers available
|
|
5183
5331
|
warn('No shared link token or document ID - statements may fail aggregation');
|
|
5184
|
-
|
|
5332
|
+
maybeEnrichAndReady();
|
|
5185
5333
|
}
|
|
5186
5334
|
} else {
|
|
5187
|
-
// Already have GUID
|
|
5188
|
-
|
|
5335
|
+
// Already have GUID \u2014 still try to enrich packageName if missing
|
|
5336
|
+
maybeEnrichAndReady();
|
|
5189
5337
|
}
|
|
5190
5338
|
|
|
5191
5339
|
// Setup beforeunload to send terminated
|