@dyrected/core 2.11.0 → 2.13.0

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
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  BUILTIN_JEXL_HELPERS,
3
3
  ConfigValidationError,
4
+ DyrectedAIError,
4
5
  LIFECYCLE_EVENTS_COLLECTION,
5
6
  WORKFLOW_HISTORY_COLLECTION,
6
7
  abs,
@@ -56,6 +57,7 @@ import {
56
57
  generateOpenApi,
57
58
  get,
58
59
  getAdminAuthCollection,
60
+ getAllowedSitesForUser,
59
61
  getPublicAdminAuthConfig,
60
62
  includes,
61
63
  initializeWorkflowDocument,
@@ -64,6 +66,7 @@ import {
64
66
  isEmpty,
65
67
  isFuture,
66
68
  isPast,
69
+ isSiteAuthorized,
67
70
  join,
68
71
  last,
69
72
  length,
@@ -81,6 +84,7 @@ import {
81
84
  registerJexlHelpers,
82
85
  replace,
83
86
  resolveAdminAuthCollection,
87
+ resolveAuthorizedSiteId,
84
88
  round,
85
89
  runCollectionHooks,
86
90
  saveWorkflowDraft,
@@ -101,7 +105,24 @@ import {
101
105
  validatePreviewUrlExpression,
102
106
  wordCount,
103
107
  workflowCapabilities
104
- } from "./chunk-H7DVVW2P.js";
108
+ } from "./chunk-DZMBVIMN.js";
109
+ import {
110
+ NON_NEGOTIABLE_CREDENTIAL_FIELDS,
111
+ PII_REGEX_PATTERNS,
112
+ maskEmail,
113
+ maskPhone,
114
+ maskTextPII,
115
+ sanitizeDocForAI
116
+ } from "./chunk-254THFDS.js";
117
+ import {
118
+ AI_ACTIONS_COLLECTION,
119
+ AI_AUDIT_COLLECTION,
120
+ AI_CHUNKS_COLLECTION,
121
+ AI_MESSAGES_COLLECTION,
122
+ AI_THREADS_COLLECTION,
123
+ isAICollection
124
+ } from "./chunk-4RAQJVJM.js";
125
+ import "./chunk-27YRIGK5.js";
105
126
  import "./chunk-JSBRDJBE.js";
106
127
 
107
128
  // src/types/workflows.ts
@@ -384,8 +405,8 @@ function buildSqlOrderBy(sort, existingColumns, numericFields, dialect) {
384
405
  return `${dialect.quoteIdent(field)} ${direction}`;
385
406
  }
386
407
  const extracted = dialect.jsonExtract(field);
387
- const expr = numericFields.has(field) ? dialect.castNumeric(extracted) : extracted;
388
- return `${expr} ${direction}`;
408
+ const expr2 = numericFields.has(field) ? dialect.castNumeric(extracted) : extracted;
409
+ return `${expr2} ${direction}`;
389
410
  }).join(", ");
390
411
  }
391
412
 
@@ -424,12 +445,12 @@ var MatchBuilder = class {
424
445
  */
425
446
  otherwise(fallback = "null") {
426
447
  if (this.branches.length === 0) return formatJexlValue(fallback);
427
- let expr = formatJexlValue(fallback);
448
+ let expr2 = formatJexlValue(fallback);
428
449
  for (let i = this.branches.length - 1; i >= 0; i--) {
429
450
  const b = this.branches[i];
430
- expr = `${b.condition} ? ${formatJexlValue(b.value)} : ${expr}`;
451
+ expr2 = `${b.condition} ? ${formatJexlValue(b.value)} : ${expr2}`;
431
452
  }
432
- return expr;
453
+ return expr2;
433
454
  }
434
455
  };
435
456
  var FieldConditionBuilder = class {
@@ -487,6 +508,12 @@ var FieldConditionBuilder = class {
487
508
  isEmpty() {
488
509
  return `${this.field} == null || ${this.field} == ''`;
489
510
  }
511
+ /**
512
+ * Alias for `isEmpty()`.
513
+ */
514
+ empty() {
515
+ return this.isEmpty();
516
+ }
490
517
  /**
491
518
  * Numerical greater than (`field > num`).
492
519
  */
@@ -547,20 +574,44 @@ var FieldConditionBuilder = class {
547
574
  hasLengthAtLeast(length2) {
548
575
  return `length(${this.field}) >= ${length2}`;
549
576
  }
577
+ /**
578
+ * Generates a JEXL `slugify(field)` transform expression.
579
+ */
580
+ slugify() {
581
+ return `slugify(${this.field})`;
582
+ }
583
+ /**
584
+ * Generates a JEXL `lower(field)` transform expression.
585
+ */
586
+ lower() {
587
+ return `lower(${this.field})`;
588
+ }
589
+ /**
590
+ * Generates a JEXL `upper(field)` transform expression.
591
+ */
592
+ upper() {
593
+ return `upper(${this.field})`;
594
+ }
595
+ /**
596
+ * Generates a JEXL `trim(field)` transform expression.
597
+ */
598
+ trim() {
599
+ return `trim(${this.field})`;
600
+ }
550
601
  };
551
- function createWhen() {
552
- const whenFn = ((fieldName) => new FieldConditionBuilder(fieldName));
553
- whenFn.user = (userProp) => new FieldConditionBuilder(`user.${userProp}`);
554
- whenFn.sibling = (siblingProp) => new FieldConditionBuilder(`siblingData.${siblingProp}`);
555
- whenFn.concat = (...parts) => {
602
+ function createExpr() {
603
+ const exprFn = ((fieldName) => new FieldConditionBuilder(fieldName));
604
+ exprFn.user = (userProp) => new FieldConditionBuilder(`user.${userProp}`);
605
+ exprFn.sibling = (siblingProp) => new FieldConditionBuilder(`siblingData.${siblingProp}`);
606
+ exprFn.concat = (...parts) => {
556
607
  if (parts.length === 0) return "''";
557
608
  return parts.map((p) => formatJexlValue(p)).join(" + ");
558
609
  };
559
- whenFn.slugify = (field) => `slugify(${field})`;
560
- whenFn.lower = (field) => `lower(${field})`;
561
- whenFn.upper = (field) => `upper(${field})`;
562
- whenFn.trim = (field) => `trim(${field})`;
563
- whenFn.access = {
610
+ exprFn.slugify = (field) => `slugify(${field})`;
611
+ exprFn.lower = (field) => `lower(${field})`;
612
+ exprFn.upper = (field) => `upper(${field})`;
613
+ exprFn.trim = (field) => `trim(${field})`;
614
+ exprFn.access = {
564
615
  isOwner: (ownerField = "author") => {
565
616
  return `${ownerField} == user.id || ${ownerField}.id == user.id`;
566
617
  },
@@ -568,17 +619,18 @@ function createWhen() {
568
619
  return "user.role == 'admin' || (user.roles != null && 'admin' in user.roles)";
569
620
  },
570
621
  hasRole: (...roles) => {
571
- return whenFn.userRole(...roles);
622
+ return exprFn.userRole(...roles);
572
623
  },
573
624
  isPublishedOrAdmin: (statusField = "status") => {
574
625
  return `${statusField} == 'published' || user.role == 'admin' || (user.roles != null && 'admin' in user.roles)`;
575
626
  }
576
627
  };
577
- whenFn.then = (condition, ifTrue, ifFalse = "null") => {
628
+ exprFn.ifElse = (condition, ifTrue, ifFalse = "null") => {
578
629
  return `${condition} ? ${formatJexlValue(ifTrue)} : ${formatJexlValue(ifFalse)}`;
579
630
  };
580
- whenFn.match = () => new MatchBuilder();
581
- whenFn.cases = (...branches) => {
631
+ exprFn.then = exprFn.ifElse;
632
+ exprFn.match = () => new MatchBuilder();
633
+ exprFn.cases = (...branches) => {
582
634
  const builder = new MatchBuilder();
583
635
  let fallback = "null";
584
636
  for (const b of branches) {
@@ -590,114 +642,130 @@ function createWhen() {
590
642
  }
591
643
  return builder.otherwise(fallback);
592
644
  };
593
- whenFn.all = (...conditions) => {
645
+ exprFn.all = (...conditions) => {
594
646
  const valid = conditions.filter(Boolean);
595
647
  if (valid.length === 0) return "true";
596
648
  if (valid.length === 1) return valid[0];
597
649
  return valid.map((c) => c.includes(" ") ? `(${c})` : c).join(" && ");
598
650
  };
599
- whenFn.and = whenFn.all;
600
- whenFn.any = (...conditions) => {
651
+ exprFn.and = exprFn.all;
652
+ exprFn.any = (...conditions) => {
601
653
  const valid = conditions.filter(Boolean);
602
654
  if (valid.length === 0) return "true";
603
655
  if (valid.length === 1) return valid[0];
604
656
  return valid.map((c) => c.includes(" ") ? `(${c})` : c).join(" || ");
605
657
  };
606
- whenFn.or = whenFn.any;
607
- whenFn.not = (condition) => {
658
+ exprFn.or = exprFn.any;
659
+ exprFn.not = (condition) => {
608
660
  if (!condition) return "false";
609
661
  return `!(${condition})`;
610
662
  };
611
- whenFn.variant = (...variants) => {
663
+ exprFn.variant = (...variants) => {
612
664
  const flat = variants.flat();
613
665
  if (flat.length === 0) return "true";
614
666
  if (flat.length === 1) return `variant == '${flat[0]}'`;
615
667
  return `variant in [${flat.map((v) => `'${v}'`).join(", ")}]`;
616
668
  };
617
- whenFn.notVariant = (...variants) => {
669
+ exprFn.notVariant = (...variants) => {
618
670
  const flat = variants.flat();
619
671
  if (flat.length === 0) return "false";
620
672
  if (flat.length === 1) return `variant != '${flat[0]}'`;
621
673
  return `!(variant in [${flat.map((v) => `'${v}'`).join(", ")}])`;
622
674
  };
623
- whenFn.block = (...blocks) => {
675
+ exprFn.block = (...blocks) => {
624
676
  const flat = blocks.flat();
625
677
  if (flat.length === 0) return "true";
626
678
  if (flat.length === 1) return `block == '${flat[0]}'`;
627
679
  return `block in [${flat.map((b) => `'${b}'`).join(", ")}]`;
628
680
  };
629
- whenFn.notBlock = (...blocks) => {
681
+ exprFn.notBlock = (...blocks) => {
630
682
  const flat = blocks.flat();
631
683
  if (flat.length === 0) return "false";
632
684
  if (flat.length === 1) return `block != '${flat[0]}'`;
633
685
  return `!(block in [${flat.map((b) => `'${b}'`).join(", ")}])`;
634
686
  };
635
- whenFn.fieldEquals = (field, value) => {
687
+ exprFn.equals = (field, value) => {
636
688
  return `${field} == ${JSON.stringify(value)}`;
637
689
  };
638
- whenFn.fieldNotEquals = (field, value) => {
690
+ exprFn.fieldEquals = exprFn.equals;
691
+ exprFn.notEquals = (field, value) => {
639
692
  return `${field} != ${JSON.stringify(value)}`;
640
693
  };
641
- whenFn.fieldIn = (field, ...values) => {
694
+ exprFn.fieldNotEquals = exprFn.notEquals;
695
+ exprFn.in = (field, ...values) => {
642
696
  const flat = values.flat();
643
697
  return `${field} in [${flat.map((v) => JSON.stringify(v)).join(", ")}]`;
644
698
  };
645
- whenFn.fieldNotIn = (field, ...values) => {
699
+ exprFn.fieldIn = exprFn.in;
700
+ exprFn.notIn = (field, ...values) => {
646
701
  const flat = values.flat();
647
702
  return `!(${field} in [${flat.map((v) => JSON.stringify(v)).join(", ")}])`;
648
703
  };
649
- whenFn.fieldNotEmpty = (field) => {
704
+ exprFn.fieldNotIn = exprFn.notIn;
705
+ exprFn.notEmpty = (field) => {
650
706
  return `${field} != null && ${field} != ''`;
651
707
  };
652
- whenFn.fieldEmpty = (field) => {
708
+ exprFn.fieldNotEmpty = exprFn.notEmpty;
709
+ exprFn.empty = (field) => {
653
710
  return `${field} == null || ${field} == ''`;
654
711
  };
655
- whenFn.fieldIsTrue = (field) => {
712
+ exprFn.fieldEmpty = exprFn.empty;
713
+ exprFn.isTrue = (field) => {
656
714
  return `${field} == true`;
657
715
  };
658
- whenFn.fieldIsFalse = (field) => {
716
+ exprFn.fieldIsTrue = exprFn.isTrue;
717
+ exprFn.isFalse = (field) => {
659
718
  return `${field} != true`;
660
719
  };
661
- whenFn.fieldGreaterThan = (field, value) => {
720
+ exprFn.fieldIsFalse = exprFn.isFalse;
721
+ exprFn.greaterThan = (field, value) => {
662
722
  return `${field} > ${value}`;
663
723
  };
664
- whenFn.fieldGreaterThanOrEqual = (field, value) => {
724
+ exprFn.fieldGreaterThan = exprFn.greaterThan;
725
+ exprFn.greaterThanOrEqual = (field, value) => {
665
726
  return `${field} >= ${value}`;
666
727
  };
667
- whenFn.fieldLessThan = (field, value) => {
728
+ exprFn.fieldGreaterThanOrEqual = exprFn.greaterThanOrEqual;
729
+ exprFn.lessThan = (field, value) => {
668
730
  return `${field} < ${value}`;
669
731
  };
670
- whenFn.fieldLessThanOrEqual = (field, value) => {
732
+ exprFn.fieldLessThan = exprFn.lessThan;
733
+ exprFn.lessThanOrEqual = (field, value) => {
671
734
  return `${field} <= ${value}`;
672
735
  };
673
- whenFn.fieldBetween = (field, min2, max2) => {
736
+ exprFn.fieldLessThanOrEqual = exprFn.lessThanOrEqual;
737
+ exprFn.between = (field, min2, max2) => {
674
738
  return `${field} >= ${min2} && ${field} <= ${max2}`;
675
739
  };
676
- whenFn.fieldStartsWith = (field, prefix) => {
740
+ exprFn.fieldBetween = exprFn.between;
741
+ exprFn.startsWith = (field, prefix) => {
677
742
  return `startsWith(${field}, ${JSON.stringify(prefix)})`;
678
743
  };
679
- whenFn.fieldEndsWith = (field, suffix) => {
744
+ exprFn.fieldStartsWith = exprFn.startsWith;
745
+ exprFn.endsWith = (field, suffix) => {
680
746
  return `endsWith(${field}, ${JSON.stringify(suffix)})`;
681
747
  };
682
- whenFn.fieldContains = (field, item) => {
748
+ exprFn.fieldEndsWith = exprFn.endsWith;
749
+ exprFn.contains = (field, item) => {
683
750
  return `includes(${field}, ${JSON.stringify(item)})`;
684
751
  };
685
- whenFn.arrayNotEmpty = (field) => {
752
+ exprFn.fieldContains = exprFn.contains;
753
+ exprFn.arrayNotEmpty = (field) => {
686
754
  return `length(${field}) > 0`;
687
755
  };
688
- whenFn.arrayEmpty = (field) => {
756
+ exprFn.arrayEmpty = (field) => {
689
757
  return `length(${field}) == 0`;
690
758
  };
691
- whenFn.arrayCountGreaterThan = (field, count2) => {
759
+ exprFn.arrayCountGreaterThan = (field, count2) => {
692
760
  return `length(${field}) > ${count2}`;
693
761
  };
694
- whenFn.arrayCountAtLeast = (field, count2) => {
762
+ exprFn.arrayCountAtLeast = (field, count2) => {
695
763
  return `length(${field}) >= ${count2}`;
696
764
  };
697
- whenFn.arrayCountLessThan = (field, count2) => {
765
+ exprFn.arrayCountLessThan = (field, count2) => {
698
766
  return `length(${field}) < ${count2}`;
699
767
  };
700
- whenFn.userRole = (...roles) => {
768
+ exprFn.userRole = (...roles) => {
701
769
  const flat = roles.flat();
702
770
  if (flat.length === 1) {
703
771
  return `user.role == '${flat[0]}' || (user.roles != null && '${flat[0]}' in user.roles)`;
@@ -705,31 +773,33 @@ function createWhen() {
705
773
  const roleArray = `[${flat.map((r) => `'${r}'`).join(", ")}]`;
706
774
  return `user.role in ${roleArray} || (user.roles != null && includes(${roleArray}, user.role))`;
707
775
  };
708
- whenFn.userEmailDomain = (domain) => {
776
+ exprFn.userEmailDomain = (domain) => {
709
777
  const clean = domain.startsWith("@") ? domain : `@${domain}`;
710
778
  return `endsWith(user.email, '${clean}')`;
711
779
  };
712
- whenFn.userAttributeEquals = (attr, value) => {
780
+ exprFn.userAttributeEquals = (attr, value) => {
713
781
  return `user.${attr} == ${JSON.stringify(value)}`;
714
782
  };
715
- whenFn.isNewDocument = () => {
783
+ exprFn.isNewDocument = () => {
716
784
  return "id == null";
717
785
  };
718
- whenFn.isExistingDocument = () => {
786
+ exprFn.isExistingDocument = () => {
719
787
  return "id != null";
720
788
  };
721
- whenFn.statusEquals = (status) => {
789
+ exprFn.statusEquals = (status) => {
722
790
  return `status == '${status}'`;
723
791
  };
724
- whenFn.statusIn = (...statuses) => {
792
+ exprFn.statusIn = (...statuses) => {
725
793
  const flat = statuses.flat();
726
794
  return `status in [${flat.map((s) => `'${s}'`).join(", ")}]`;
727
795
  };
728
- return whenFn;
796
+ return exprFn;
729
797
  }
730
- var when = createWhen();
798
+ var expr = createExpr();
799
+ var when = expr;
731
800
 
732
801
  // src/index.ts
802
+ import { z } from "zod";
733
803
  function defineCollection(config) {
734
804
  return config;
735
805
  }
@@ -777,12 +847,20 @@ function defineTab(args) {
777
847
  }));
778
848
  }
779
849
  export {
850
+ AI_ACTIONS_COLLECTION,
851
+ AI_AUDIT_COLLECTION,
852
+ AI_CHUNKS_COLLECTION,
853
+ AI_MESSAGES_COLLECTION,
854
+ AI_THREADS_COLLECTION,
780
855
  BUILTIN_JEXL_HELPERS,
781
856
  ConfigValidationError,
857
+ DyrectedAIError,
782
858
  FieldConditionBuilder,
783
859
  LIFECYCLE_EVENTS_COLLECTION,
784
860
  LIFECYCLE_EVENT_NAMES,
785
861
  MatchBuilder,
862
+ NON_NEGOTIABLE_CREDENTIAL_FIELDS,
863
+ PII_REGEX_PATTERNS,
786
864
  WORKFLOW_HISTORY_COLLECTION,
787
865
  abs,
788
866
  addDays,
@@ -860,6 +938,7 @@ export {
860
938
  evaluateJexlSync,
861
939
  executeFieldAfterRead,
862
940
  executeFieldBeforeChange,
941
+ expr,
863
942
  first,
864
943
  floor,
865
944
  formatConfigDiagnostics,
@@ -869,18 +948,24 @@ export {
869
948
  generateOpenApi,
870
949
  get,
871
950
  getAdminAuthCollection,
951
+ getAllowedSitesForUser,
872
952
  getPublicAdminAuthConfig,
873
953
  includes,
874
954
  initializeWorkflowDocument,
955
+ isAICollection,
875
956
  isConfigValidationError,
876
957
  isDetailItemVisible,
877
958
  isEmpty,
878
959
  isFuture,
879
960
  isPast,
961
+ isSiteAuthorized,
880
962
  join,
881
963
  last,
882
964
  length,
883
965
  lower,
966
+ maskEmail,
967
+ maskPhone,
968
+ maskTextPII,
884
969
  materializeWorkflowDocument,
885
970
  max,
886
971
  min,
@@ -898,8 +983,10 @@ export {
898
983
  registerJexlHelpers,
899
984
  replace,
900
985
  resolveAdminAuthCollection,
986
+ resolveAuthorizedSiteId,
901
987
  round,
902
988
  runCollectionHooks,
989
+ sanitizeDocForAI,
903
990
  saveWorkflowDraft,
904
991
  simplePublishingWorkflow,
905
992
  slugify,
@@ -918,5 +1005,6 @@ export {
918
1005
  validatePreviewUrlExpression,
919
1006
  when,
920
1007
  wordCount,
921
- workflowCapabilities
1008
+ workflowCapabilities,
1009
+ z
922
1010
  };
@@ -0,0 +1,11 @@
1
+ import {
2
+ RAGService
3
+ } from "./chunk-ZYYDTHF3.js";
4
+ import "./chunk-254THFDS.js";
5
+ import "./chunk-4RAQJVJM.js";
6
+ import "./chunk-HRRJ3RYT.js";
7
+ import "./chunk-27YRIGK5.js";
8
+ import "./chunk-JSBRDJBE.js";
9
+ export {
10
+ RAGService
11
+ };