@sendbird/actionbook-core 0.10.1 → 0.10.3

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.d.ts CHANGED
@@ -222,6 +222,15 @@ declare function collectAllVariables(structures: JinjaIfStructure[]): Variable[]
222
222
  * @returns true/false if evaluation succeeded, null if parsing/evaluation failed
223
223
  */
224
224
  declare function evaluateCondition(condition: string, variables: Map<string, VariableValue>): boolean | null;
225
+ interface ConditionValidationResult {
226
+ readonly valid: boolean;
227
+ readonly error?: string;
228
+ }
229
+ /**
230
+ * Validate a Jinja conditional expression without evaluating it.
231
+ * Returns a structured result with an error message on failure.
232
+ */
233
+ declare function validateCondition(condition: string): ConditionValidationResult;
225
234
 
226
235
  type HighlightCategory = 'variable' | 'operator' | 'value' | 'punctuation';
227
236
  interface ConditionToken {
@@ -424,4 +433,4 @@ declare function actionbookToAST(manual: {
424
433
  logic: LogicV2;
425
434
  }): DocumentNode;
426
435
 
427
- export { ActionbookConversionError, type ActionbookJSON, AstNode, BlockNode, BlockquoteNode, BoldMark, type BranchDecision, BulletListNode, CodeMark, type ConditionToken, type DecisionTree, type DeleteOp, DeserializationError, DocumentNode, type DocumentTreeNode, type DocumentTreeNodeType, type EnumeratePathsIterOptions, type GotoEdge, type GotoEntryResolution, HardBreakNode, HeadingNode, type HighlightCategory, HorizontalRuleNode, InlineNode, type InsertOp, ItalicMark, type JinjaBlock, JinjaIfBlockNode, JinjaIfBranch, JinjaIfInlineNode, type JinjaIfStructure, type JinjaVisualBranch, type JinjaVisualStructure, JumpPointNode, LinkMark, type LintAsyncOptions, LintContext, LintResult, LintRule, LintSection, ListItemNode, LlmCompletionEndpoint, LlmLintRule, Mark, NodePath, NoteBlockNode, type Operation, OperationError, OrderedListNode, ParagraphNode, type ParseMarkdownOptions, type ReplaceOp, ResourceTagNode, ResourceTagType, StrikethroughMark, TableCellNode, TableNode, TableRowNode, TextNode, type Transaction, type TreeNode, type TreeNodeClassification, type TreeNodeLine, type TreeNodeType, type TreePath, type TreeSection, UnderlineMark, type ValidationError, type Variable, type VariableValue, type VisitOptions, actionbookToAST, analyzeJinjaBlocks, applyOperation, applyTransaction, blockquote, bold, buildDocumentTree, bulletList, chunkByHeading, code, collectAllVariables, comparePaths, defaultLlmRules, defaultRules, deserializeFromJSON, doc, enumeratePaths, enumeratePathsBySection, enumeratePathsIter, evaluateCondition, evaluateJinjaNodes, extractResourceTags, extractVariables, findAll, findDuplicateJumpPoints, fromMdast, generateDecisionTree, hardBreak, heading, horizontalRule, invertOperation, isBlock, isDocument, isInline, isTextNode, italic, jinjaBranch, jinjaIfBlock, jinjaIfInline, jumpPoint, link, lint, lintAsync, listItem, map, nodeAtPath, noteBlock, orderedList, paragraph, parentPath, parseFragment, parseMarkdown, pathFromString, pathToString, resolveGotoEntryPath, resourceTag, scanJinjaBlocks, serializeFragment, serializeToJSON, serializeToMarkdown, strikethrough, structureJinjaBlocks, table, tableCell, tableRow, text, textContent, toMdast, todoItem, tokenizeCondition, underline, validate, visit };
436
+ export { ActionbookConversionError, type ActionbookJSON, AstNode, BlockNode, BlockquoteNode, BoldMark, type BranchDecision, BulletListNode, CodeMark, type ConditionToken, type ConditionValidationResult, type DecisionTree, type DeleteOp, DeserializationError, DocumentNode, type DocumentTreeNode, type DocumentTreeNodeType, type EnumeratePathsIterOptions, type GotoEdge, type GotoEntryResolution, HardBreakNode, HeadingNode, type HighlightCategory, HorizontalRuleNode, InlineNode, type InsertOp, ItalicMark, type JinjaBlock, JinjaIfBlockNode, JinjaIfBranch, JinjaIfInlineNode, type JinjaIfStructure, type JinjaVisualBranch, type JinjaVisualStructure, JumpPointNode, LinkMark, type LintAsyncOptions, LintContext, LintResult, LintRule, LintSection, ListItemNode, LlmCompletionEndpoint, LlmLintRule, Mark, NodePath, NoteBlockNode, type Operation, OperationError, OrderedListNode, ParagraphNode, type ParseMarkdownOptions, type ReplaceOp, ResourceTagNode, ResourceTagType, StrikethroughMark, TableCellNode, TableNode, TableRowNode, TextNode, type Transaction, type TreeNode, type TreeNodeClassification, type TreeNodeLine, type TreeNodeType, type TreePath, type TreeSection, UnderlineMark, type ValidationError, type Variable, type VariableValue, type VisitOptions, actionbookToAST, analyzeJinjaBlocks, applyOperation, applyTransaction, blockquote, bold, buildDocumentTree, bulletList, chunkByHeading, code, collectAllVariables, comparePaths, defaultLlmRules, defaultRules, deserializeFromJSON, doc, enumeratePaths, enumeratePathsBySection, enumeratePathsIter, evaluateCondition, evaluateJinjaNodes, extractResourceTags, extractVariables, findAll, findDuplicateJumpPoints, fromMdast, generateDecisionTree, hardBreak, heading, horizontalRule, invertOperation, isBlock, isDocument, isInline, isTextNode, italic, jinjaBranch, jinjaIfBlock, jinjaIfInline, jumpPoint, link, lint, lintAsync, listItem, map, nodeAtPath, noteBlock, orderedList, paragraph, parentPath, parseFragment, parseMarkdown, pathFromString, pathToString, resolveGotoEntryPath, resourceTag, scanJinjaBlocks, serializeFragment, serializeToJSON, serializeToMarkdown, strikethrough, structureJinjaBlocks, table, tableCell, tableRow, text, textContent, toMdast, todoItem, tokenizeCondition, underline, validate, validateCondition, visit };
package/dist/index.js CHANGED
@@ -3627,7 +3627,7 @@ function tokenize(input) {
3627
3627
  i++;
3628
3628
  }
3629
3629
  }
3630
- if (i >= input.length) return [];
3630
+ if (i >= input.length) return { tokens: [], error: "Unterminated string literal" };
3631
3631
  i++;
3632
3632
  tokens.push({ type: "STRING", value: str });
3633
3633
  continue;
@@ -3710,10 +3710,10 @@ function tokenize(input) {
3710
3710
  i++;
3711
3711
  continue;
3712
3712
  }
3713
- return [];
3713
+ return { tokens: [], error: `Unexpected character: ${input[i]}` };
3714
3714
  }
3715
3715
  tokens.push({ type: "EOF", value: "" });
3716
- return tokens;
3716
+ return { tokens };
3717
3717
  }
3718
3718
  var Parser = class {
3719
3719
  pos = 0;
@@ -3892,8 +3892,8 @@ function toNumber(v) {
3892
3892
  }
3893
3893
  function evaluateCondition(condition, variables) {
3894
3894
  try {
3895
- const tokens = tokenize(condition.trim());
3896
- if (tokens.length === 0) return null;
3895
+ const { tokens, error } = tokenize(condition.trim());
3896
+ if (error || tokens.length === 0) return null;
3897
3897
  const parser = new Parser(tokens, variables);
3898
3898
  const result = parser.evaluate();
3899
3899
  return isTruthy(result);
@@ -3901,6 +3901,21 @@ function evaluateCondition(condition, variables) {
3901
3901
  return null;
3902
3902
  }
3903
3903
  }
3904
+ function validateCondition(condition) {
3905
+ const trimmed = condition.trim();
3906
+ if (trimmed === "") return { valid: true };
3907
+ const { tokens, error: tokenError } = tokenize(trimmed);
3908
+ if (tokenError) return { valid: false, error: tokenError };
3909
+ if (tokens.length === 0) return { valid: false, error: "Empty expression" };
3910
+ try {
3911
+ const parser = new Parser(tokens, /* @__PURE__ */ new Map());
3912
+ parser.evaluate();
3913
+ return { valid: true };
3914
+ } catch (e) {
3915
+ const msg = e instanceof Error ? e.message : "Invalid expression";
3916
+ return { valid: false, error: msg };
3917
+ }
3918
+ }
3904
3919
 
3905
3920
  // src/jinja/conditionHighlighter.ts
3906
3921
  var KEYWORDS3 = {
@@ -5795,6 +5810,7 @@ export {
5795
5810
  tokenizeCondition,
5796
5811
  underline,
5797
5812
  validate,
5813
+ validateCondition,
5798
5814
  visit
5799
5815
  };
5800
5816
  //# sourceMappingURL=index.js.map