@claritylabs/cl-sdk 3.0.7 → 3.0.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.js CHANGED
@@ -9439,6 +9439,18 @@ function endorsementTitle(value) {
9439
9439
  function sourceNodeText(node) {
9440
9440
  return cleanText([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "), "");
9441
9441
  }
9442
+ function looksLikeEndorsementStart(node) {
9443
+ const title = cleanText(node.title, "");
9444
+ const body = cleanText([node.textExcerpt, node.description].filter(Boolean).join(" "), "");
9445
+ const start = body.slice(0, 260);
9446
+ if (/\bthis endorsement changes the policy\b/i.test(start) && endorsementReference(start)) return true;
9447
+ if (/^(?:[A-Z]{2,}-)?END\s+0*[0-9]{1,4}\b/i.test(start)) return true;
9448
+ if (/^endorsement\s+(?:no\.?|number|#)\s*[A-Z0-9][A-Z0-9.-]*\b/i.test(start)) return true;
9449
+ return /^endorsement\s+(?:no\.?|number|#)\s*[A-Z0-9][A-Z0-9.-]*\b/i.test(title) && /\bthis endorsement changes the policy\b/i.test(body);
9450
+ }
9451
+ function endorsementStartTitle(node) {
9452
+ return looksLikeEndorsementStart(node) ? endorsementTitle(sourceNodeText(node)) : void 0;
9453
+ }
9442
9454
  function semanticGroupNodeId(documentId, kind, title, childNodeIds) {
9443
9455
  return [
9444
9456
  documentId.replace(/[^a-zA-Z0-9_.:-]/g, "_"),
@@ -9504,8 +9516,7 @@ function groupAdjacentChildren(params) {
9504
9516
  function applySemanticPageGrouping(sourceTree) {
9505
9517
  const relabeled = sourceTree.map((node) => {
9506
9518
  if (node.kind === "document" || node.kind === "page_group") return node;
9507
- const text = sourceNodeText(node);
9508
- const endorsement = endorsementTitle(text);
9519
+ const endorsement = endorsementStartTitle(node);
9509
9520
  if (endorsement && node.kind === "page") {
9510
9521
  return {
9511
9522
  ...node,
@@ -9541,7 +9552,7 @@ function applySemanticPageGrouping(sourceTree) {
9541
9552
  const declarationIds = [];
9542
9553
  for (let index = declarationsStartIndex; index < children.length; index += 1) {
9543
9554
  const child = children[index];
9544
- if (index > declarationsStartIndex && (looksLikePolicyFormStart(child) || endorsementTitle(sourceNodeText(child)))) break;
9555
+ if (index > declarationsStartIndex && (looksLikePolicyFormStart(child) || looksLikeEndorsementStart(child))) break;
9545
9556
  if (!looksLikeDeclarationsContinuation(child)) break;
9546
9557
  declarationIds.push(child.id);
9547
9558
  }
@@ -9560,7 +9571,7 @@ function applySemanticPageGrouping(sourceTree) {
9560
9571
  const policyIds = [];
9561
9572
  for (let index = policyStartIndex; index < children.length; index += 1) {
9562
9573
  const child = children[index];
9563
- if (index > policyStartIndex && endorsementTitle(sourceNodeText(child))) break;
9574
+ if (index > policyStartIndex && looksLikeEndorsementStart(child)) break;
9564
9575
  if (!looksLikePolicyFormContinuation(child)) break;
9565
9576
  policyIds.push(child.id);
9566
9577
  }
@@ -9599,8 +9610,19 @@ function endorsementGroupNodeId(documentId, parentId) {
9599
9610
  }
9600
9611
  function applyEndorsementGrouping(sourceTree) {
9601
9612
  const relabeledTree = sourceTree.map((node) => {
9602
- if (node.kind === "document" || isEndorsementGroup(node) || node.kind === "endorsement") return node;
9603
- const title = endorsementTitle([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "));
9613
+ if (node.kind === "document" || isEndorsementGroup(node)) return node;
9614
+ const title = endorsementStartTitle(node);
9615
+ if (!title && node.kind === "endorsement") {
9616
+ return {
9617
+ ...node,
9618
+ kind: "page",
9619
+ title: node.pageStart ? `Page ${node.pageStart}` : cleanText(node.title, "Page"),
9620
+ metadata: {
9621
+ ...node.metadata,
9622
+ organizerRepair: "demote_incidental_endorsement_reference"
9623
+ }
9624
+ };
9625
+ }
9604
9626
  if (!title) return node;
9605
9627
  return {
9606
9628
  ...node,
@@ -9640,7 +9662,7 @@ function applyEndorsementGrouping(sourceTree) {
9640
9662
  });
9641
9663
  nextTree = nextTree.map((node) => {
9642
9664
  if (!endorsementGroupIds.has(node.parentId ?? "")) return node;
9643
- const title = endorsementTitle([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "));
9665
+ const title = endorsementStartTitle(node);
9644
9666
  if (!title) return node;
9645
9667
  return {
9646
9668
  ...node,