@patch-adams/core 1.5.7 → 1.5.9

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.js CHANGED
@@ -616,12 +616,30 @@ function generateLrsBridgeCode(options) {
616
616
  });
617
617
  }
618
618
 
619
- // Decode HTML entities (e.g., " " & ') to clean text
619
+ // Clean HTML entities from text \u2014 handles both proper (") and broken (quot;) forms
620
+ // Rise strips the & from entities in SCORM interaction IDs, so we need both
620
621
  function decodeEntities(str) {
621
622
  if (!str || typeof str !== 'string') return str;
622
- var txt = document.createElement('textarea');
623
- txt.innerHTML = str;
624
- return txt.value;
623
+ // 1. Replace known broken entities (without &) that Rise leaves behind
624
+ str = str
625
+ .replace(/quot;/g, '"')
626
+ .replace(/apos;/g, "'")
627
+ .replace(/amp;/g, '&')
628
+ .replace(/lt;/g, '<')
629
+ .replace(/gt;/g, '>')
630
+ .replace(/nbsp;/g, ' ');
631
+ // 2. Replace numeric entities like &#34; &#39; &#x22; etc.
632
+ str = str.replace(/&#(x?[0-9a-fA-F]+);/g, function(match, code) {
633
+ var num = code.charAt(0) === 'x' ? parseInt(code.substring(1), 16) : parseInt(code, 10);
634
+ return isNaN(num) ? match : String.fromCharCode(num);
635
+ });
636
+ // 3. Catch any remaining standard &entities; via textarea decode
637
+ try {
638
+ var txt = document.createElement('textarea');
639
+ txt.innerHTML = str;
640
+ str = txt.value;
641
+ } catch (e) {}
642
+ return str;
625
643
  }
626
644
 
627
645
  LRS.sessionId = generateUUID();
@@ -2684,15 +2702,37 @@ function generateLrsBridgeCode(options) {
2684
2702
  * Build activity object for questions in Xyleme format
2685
2703
  * Name format: "Assessment Name - Q#: Question text..."
2686
2704
  */
2705
+ /**
2706
+ * Simple string hash for generating short, stable IDs from long strings.
2707
+ * Returns a hex string (8 chars). Not cryptographic \u2014 just for uniqueness.
2708
+ */
2709
+ function hashString(str) {
2710
+ var hash = 0;
2711
+ for (var i = 0; i < str.length; i++) {
2712
+ var ch = str.charCodeAt(i);
2713
+ hash = ((hash << 5) - hash) + ch;
2714
+ hash = hash & hash; // Convert to 32-bit integer
2715
+ }
2716
+ return Math.abs(hash).toString(16).padStart(8, '0');
2717
+ }
2718
+
2687
2719
  function buildQuestionActivityObject(questionInfo) {
2688
- var questionGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2720
+ var rawGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2721
+
2722
+ // Ensure the object ID stays under 255 chars total to avoid Bravais aggregation failures.
2723
+ // Rise SCORM interaction IDs can be very long (full slugified question text).
2724
+ // Use a truncated prefix + hash to keep it short but unique and stable.
2725
+ var questionGuid = rawGuid;
2726
+ if (rawGuid.length > 80) {
2727
+ questionGuid = rawGuid.substring(0, 60) + '_' + hashString(rawGuid);
2728
+ }
2689
2729
 
2690
2730
  // Build human-readable display name
2691
2731
  var displayName = (questionInfo.assessmentName || 'Knowledge Check');
2692
2732
  if (questionInfo.questionNumber) {
2693
2733
  displayName += ' - Q' + questionInfo.questionNumber;
2694
2734
  }
2695
- var questionText = questionInfo.text || questionInfo.questionText || '';
2735
+ var questionText = decodeEntities(questionInfo.text || questionInfo.questionText || '');
2696
2736
  if (questionText.length > 50) {
2697
2737
  displayName += ': ' + questionText.substring(0, 47) + '...';
2698
2738
  } else if (questionText.length > 0) {
@@ -4069,10 +4109,12 @@ function generateLrsBridgeCode(options) {
4069
4109
  var interactionId = interaction.id || ('interaction-' + idx);
4070
4110
 
4071
4111
  // Try to make a readable question text from the interaction ID
4072
- var questionText = interactionId
4073
- .replace(/_\\d+$/, '') // remove trailing _0
4074
- .replace(/_/g, ' ') // underscores to spaces
4075
- .substring(0, 200);
4112
+ var questionText = decodeEntities(
4113
+ interactionId
4114
+ .replace(/_\\d+$/, '') // remove trailing _0
4115
+ .replace(/_/g, ' ') // underscores to spaces
4116
+ .substring(0, 200)
4117
+ );
4076
4118
 
4077
4119
  // Get lesson context
4078
4120
  var lessonInfo = getCachedLessonInfo();