@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.cjs CHANGED
@@ -625,12 +625,30 @@ function generateLrsBridgeCode(options) {
625
625
  });
626
626
  }
627
627
 
628
- // Decode HTML entities (e.g., " " & ') to clean text
628
+ // Clean HTML entities from text \u2014 handles both proper (") and broken (quot;) forms
629
+ // Rise strips the & from entities in SCORM interaction IDs, so we need both
629
630
  function decodeEntities(str) {
630
631
  if (!str || typeof str !== 'string') return str;
631
- var txt = document.createElement('textarea');
632
- txt.innerHTML = str;
633
- return txt.value;
632
+ // 1. Replace known broken entities (without &) that Rise leaves behind
633
+ str = str
634
+ .replace(/quot;/g, '"')
635
+ .replace(/apos;/g, "'")
636
+ .replace(/amp;/g, '&')
637
+ .replace(/lt;/g, '<')
638
+ .replace(/gt;/g, '>')
639
+ .replace(/nbsp;/g, ' ');
640
+ // 2. Replace numeric entities like &#34; &#39; &#x22; etc.
641
+ str = str.replace(/&#(x?[0-9a-fA-F]+);/g, function(match, code) {
642
+ var num = code.charAt(0) === 'x' ? parseInt(code.substring(1), 16) : parseInt(code, 10);
643
+ return isNaN(num) ? match : String.fromCharCode(num);
644
+ });
645
+ // 3. Catch any remaining standard &entities; via textarea decode
646
+ try {
647
+ var txt = document.createElement('textarea');
648
+ txt.innerHTML = str;
649
+ str = txt.value;
650
+ } catch (e) {}
651
+ return str;
634
652
  }
635
653
 
636
654
  LRS.sessionId = generateUUID();
@@ -2693,15 +2711,37 @@ function generateLrsBridgeCode(options) {
2693
2711
  * Build activity object for questions in Xyleme format
2694
2712
  * Name format: "Assessment Name - Q#: Question text..."
2695
2713
  */
2714
+ /**
2715
+ * Simple string hash for generating short, stable IDs from long strings.
2716
+ * Returns a hex string (8 chars). Not cryptographic \u2014 just for uniqueness.
2717
+ */
2718
+ function hashString(str) {
2719
+ var hash = 0;
2720
+ for (var i = 0; i < str.length; i++) {
2721
+ var ch = str.charCodeAt(i);
2722
+ hash = ((hash << 5) - hash) + ch;
2723
+ hash = hash & hash; // Convert to 32-bit integer
2724
+ }
2725
+ return Math.abs(hash).toString(16).padStart(8, '0');
2726
+ }
2727
+
2696
2728
  function buildQuestionActivityObject(questionInfo) {
2697
- var questionGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2729
+ var rawGuid = questionInfo.questionGuid || questionInfo.id || generateUUID();
2730
+
2731
+ // Ensure the object ID stays under 255 chars total to avoid Bravais aggregation failures.
2732
+ // Rise SCORM interaction IDs can be very long (full slugified question text).
2733
+ // Use a truncated prefix + hash to keep it short but unique and stable.
2734
+ var questionGuid = rawGuid;
2735
+ if (rawGuid.length > 80) {
2736
+ questionGuid = rawGuid.substring(0, 60) + '_' + hashString(rawGuid);
2737
+ }
2698
2738
 
2699
2739
  // Build human-readable display name
2700
2740
  var displayName = (questionInfo.assessmentName || 'Knowledge Check');
2701
2741
  if (questionInfo.questionNumber) {
2702
2742
  displayName += ' - Q' + questionInfo.questionNumber;
2703
2743
  }
2704
- var questionText = questionInfo.text || questionInfo.questionText || '';
2744
+ var questionText = decodeEntities(questionInfo.text || questionInfo.questionText || '');
2705
2745
  if (questionText.length > 50) {
2706
2746
  displayName += ': ' + questionText.substring(0, 47) + '...';
2707
2747
  } else if (questionText.length > 0) {
@@ -4078,10 +4118,12 @@ function generateLrsBridgeCode(options) {
4078
4118
  var interactionId = interaction.id || ('interaction-' + idx);
4079
4119
 
4080
4120
  // Try to make a readable question text from the interaction ID
4081
- var questionText = interactionId
4082
- .replace(/_\\d+$/, '') // remove trailing _0
4083
- .replace(/_/g, ' ') // underscores to spaces
4084
- .substring(0, 200);
4121
+ var questionText = decodeEntities(
4122
+ interactionId
4123
+ .replace(/_\\d+$/, '') // remove trailing _0
4124
+ .replace(/_/g, ' ') // underscores to spaces
4125
+ .substring(0, 200)
4126
+ );
4085
4127
 
4086
4128
  // Get lesson context
4087
4129
  var lessonInfo = getCachedLessonInfo();