@patch-adams/core 1.5.16 → 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 +109 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +109 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +109 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +109 -10
- 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
|
|
|
@@ -2580,15 +2656,20 @@ function generateLrsBridgeCode(options) {
|
|
|
2580
2656
|
if (!info.packageName) {
|
|
2581
2657
|
var bravaisDocName = null;
|
|
2582
2658
|
|
|
2583
|
-
// Strategy 1: Walk parent frames for PARAMS.documentName
|
|
2659
|
+
// Strategy 1: Walk parent frames for PARAMS.documentName and PARAMS.did
|
|
2584
2660
|
try {
|
|
2585
2661
|
var win = window;
|
|
2586
2662
|
for (var i = 0; i < 10; i++) {
|
|
2587
2663
|
try {
|
|
2588
|
-
if (win.PARAMS
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
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
|
+
}
|
|
2592
2673
|
}
|
|
2593
2674
|
} catch (e) {}
|
|
2594
2675
|
if (win === win.parent) break;
|
|
@@ -5196,12 +5277,30 @@ function generateLrsBridgeCode(options) {
|
|
|
5196
5277
|
tryLaunchEvents();
|
|
5197
5278
|
}
|
|
5198
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
|
+
|
|
5199
5298
|
function fetchDocDataAndReady(docId) {
|
|
5200
5299
|
fetchDocumentMetadata(docId, function(docData) {
|
|
5201
5300
|
if (docData) {
|
|
5202
5301
|
updateCourseInfoFromApi(docData);
|
|
5203
5302
|
}
|
|
5204
|
-
|
|
5303
|
+
maybeEnrichAndReady();
|
|
5205
5304
|
});
|
|
5206
5305
|
}
|
|
5207
5306
|
|
|
@@ -5221,7 +5320,7 @@ function generateLrsBridgeCode(options) {
|
|
|
5221
5320
|
} else {
|
|
5222
5321
|
warn('Could not fetch document data from shared API - statements may fail aggregation');
|
|
5223
5322
|
}
|
|
5224
|
-
|
|
5323
|
+
maybeEnrichAndReady();
|
|
5225
5324
|
});
|
|
5226
5325
|
} else if (documentId) {
|
|
5227
5326
|
// No shared link token, try with extracted document ID (requires auth)
|
|
@@ -5230,11 +5329,11 @@ function generateLrsBridgeCode(options) {
|
|
|
5230
5329
|
} else {
|
|
5231
5330
|
// No identifiers available
|
|
5232
5331
|
warn('No shared link token or document ID - statements may fail aggregation');
|
|
5233
|
-
|
|
5332
|
+
maybeEnrichAndReady();
|
|
5234
5333
|
}
|
|
5235
5334
|
} else {
|
|
5236
|
-
// Already have GUID
|
|
5237
|
-
|
|
5335
|
+
// Already have GUID \u2014 still try to enrich packageName if missing
|
|
5336
|
+
maybeEnrichAndReady();
|
|
5238
5337
|
}
|
|
5239
5338
|
|
|
5240
5339
|
// Setup beforeunload to send terminated
|