@patch-adams/core 1.5.6 → 1.5.8

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/index.cjs CHANGED
@@ -625,6 +625,14 @@ function generateLrsBridgeCode(options) {
625
625
  });
626
626
  }
627
627
 
628
+ // Decode HTML entities (e.g., " " & ') to clean text
629
+ function decodeEntities(str) {
630
+ if (!str || typeof str !== 'string') return str;
631
+ var txt = document.createElement('textarea');
632
+ txt.innerHTML = str;
633
+ return txt.value;
634
+ }
635
+
628
636
  LRS.sessionId = generateUUID();
629
637
  LRS.courseAttemptId = generateUUID(); // Unique per session for Xyleme correlation
630
638
  LRS.launchTime = new Date().toISOString();
@@ -2216,6 +2224,10 @@ function generateLrsBridgeCode(options) {
2216
2224
  info.id = window.location.href.split('#')[0].split('?')[0];
2217
2225
  }
2218
2226
 
2227
+ // Decode any HTML entities in title/description
2228
+ if (info.title) info.title = decodeEntities(info.title);
2229
+ if (info.description) info.description = decodeEntities(info.description);
2230
+
2219
2231
  // Build shared link name if not provided
2220
2232
  if (!info.sharedLinkName && info.title && info.sharedLinkToken) {
2221
2233
  info.sharedLinkName = info.title + ' - LMS Thin Pack';
@@ -2395,7 +2407,7 @@ function generateLrsBridgeCode(options) {
2395
2407
  id: window.location.href.split('#')[0].split('?')[0],
2396
2408
  definition: {
2397
2409
  type: 'http://xyleme.com/bravais/activities/document',
2398
- name: { 'en-US': document.title || 'Rise Course' }
2410
+ name: { 'en-US': decodeEntities(document.title) || 'Rise Course' }
2399
2411
  }
2400
2412
  };
2401
2413
  }
@@ -2426,10 +2438,11 @@ function generateLrsBridgeCode(options) {
2426
2438
  courseObj.definition.extensions = courseObj.definition.extensions || {};
2427
2439
 
2428
2440
  if (activityDetails) {
2429
- // Merge activity details into extensions
2441
+ // Merge activity details into extensions, decoding any HTML entities in string values
2430
2442
  for (var key in activityDetails) {
2431
2443
  if (activityDetails.hasOwnProperty(key)) {
2432
- courseObj.definition.extensions[key] = activityDetails[key];
2444
+ var val = activityDetails[key];
2445
+ courseObj.definition.extensions[key] = typeof val === 'string' ? decodeEntities(val) : val;
2433
2446
  }
2434
2447
  }
2435
2448
  }
@@ -2508,7 +2521,7 @@ function generateLrsBridgeCode(options) {
2508
2521
  id: LRS.courseInfo.id,
2509
2522
  definition: {
2510
2523
  type: 'http://xyleme.com/bravais/activities/document',
2511
- name: { 'en-US': LRS.courseInfo.title }
2524
+ name: { 'en-US': decodeEntities(LRS.courseInfo.title) }
2512
2525
  }
2513
2526
  };
2514
2527
 
@@ -2558,7 +2571,7 @@ function generateLrsBridgeCode(options) {
2558
2571
  objectType: 'Activity',
2559
2572
  definition: {
2560
2573
  type: 'http://xyleme.com/bravais/activities/document',
2561
- name: { 'en-US': LRS.courseInfo.title || 'Rise Course' }
2574
+ name: { 'en-US': decodeEntities(LRS.courseInfo.title) || 'Rise Course' }
2562
2575
  }
2563
2576
  };
2564
2577
 
@@ -2680,15 +2693,37 @@ function generateLrsBridgeCode(options) {
2680
2693
  * Build activity object for questions in Xyleme format
2681
2694
  * Name format: "Assessment Name - Q#: Question text..."
2682
2695
  */
2696
+ /**
2697
+ * Simple string hash for generating short, stable IDs from long strings.
2698
+ * Returns a hex string (8 chars). Not cryptographic \u2014 just for uniqueness.
2699
+ */
2700
+ function hashString(str) {
2701
+ var hash = 0;
2702
+ for (var i = 0; i < str.length; i++) {
2703
+ var ch = str.charCodeAt(i);
2704
+ hash = ((hash << 5) - hash) + ch;
2705
+ hash = hash & hash; // Convert to 32-bit integer
2706
+ }
2707
+ return Math.abs(hash).toString(16).padStart(8, '0');
2708
+ }
2709
+
2683
2710
  function buildQuestionActivityObject(questionInfo) {
2684
- var questionGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2711
+ var rawGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2712
+
2713
+ // Ensure the object ID stays under 255 chars total to avoid Bravais aggregation failures.
2714
+ // Rise SCORM interaction IDs can be very long (full slugified question text).
2715
+ // Use a truncated prefix + hash to keep it short but unique and stable.
2716
+ var questionGuid = rawGuid;
2717
+ if (rawGuid.length > 80) {
2718
+ questionGuid = rawGuid.substring(0, 60) + '_' + hashString(rawGuid);
2719
+ }
2685
2720
 
2686
2721
  // Build human-readable display name
2687
2722
  var displayName = (questionInfo.assessmentName || 'Knowledge Check');
2688
2723
  if (questionInfo.questionNumber) {
2689
2724
  displayName += ' - Q' + questionInfo.questionNumber;
2690
2725
  }
2691
- var questionText = questionInfo.text || questionInfo.questionText || '';
2726
+ var questionText = decodeEntities(questionInfo.text || questionInfo.questionText || '');
2692
2727
  if (questionText.length > 50) {
2693
2728
  displayName += ': ' + questionText.substring(0, 47) + '...';
2694
2729
  } else if (questionText.length > 0) {
@@ -4065,10 +4100,12 @@ function generateLrsBridgeCode(options) {
4065
4100
  var interactionId = interaction.id || ('interaction-' + idx);
4066
4101
 
4067
4102
  // Try to make a readable question text from the interaction ID
4068
- var questionText = interactionId
4069
- .replace(/_\\d+$/, '') // remove trailing _0
4070
- .replace(/_/g, ' ') // underscores to spaces
4071
- .substring(0, 200);
4103
+ var questionText = decodeEntities(
4104
+ interactionId
4105
+ .replace(/_\\d+$/, '') // remove trailing _0
4106
+ .replace(/_/g, ' ') // underscores to spaces
4107
+ .substring(0, 200)
4108
+ );
4072
4109
 
4073
4110
  // Get lesson context
4074
4111
  var lessonInfo = getCachedLessonInfo();