@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.d.ts CHANGED
@@ -1,8 +1,14 @@
1
- import { F as Field, B as Block, D as DyrectedConfig, C as CollectionConfig, A as AdminAuthConfig, P as PublicAdminAuthConfig, G as GlobalConfig, a as DeclarativeHookExpression, W as WorkflowConfig, b as AuthenticatedUser, c as WorkflowTransition, L as LifecycleEventName, d as LifecycleEvent, e as BaseDocument, H as HookRequestContext, f as DetailComputedOptions, g as ComputedHandler, h as DetailComputed, i as DetailCustomOptions, j as DetailCustom, k as DetailDividerOptions, l as DetailDivider, m as DisplayFieldOptions, n as DetailField, o as DetailItem, p as DetailGridOptions, q as DetailGrid, r as DetailRepeatOptions, s as DetailRepeat, t as DetailSectionOptions, u as DetailSection, v as DetailTabOptions, w as DetailTab, x as DetailTabsOptions, y as DetailTabs, z as DetailTextOptions, E as DetailText, I as DetailSchema, J as ArrayField, K as BlocksField, M as BooleanField, N as AuthConfig, O as AccessPolicyResolver, Q as DateField, R as DateTimeField, S as EmailField, T as IconField, U as ImageField, V as JoinField, X as JsonField, Y as MultiSelectField, Z as NumberField, _ as ObjectField, $ as RadioField, a0 as RelationshipField, a1 as RichTextField, a2 as RowField, a3 as SelectField, a4 as TextField, a5 as TextareaField, a6 as TimeField, a7 as UrlField } from './app-config-6U_Kum-Z.js';
2
- export { a8 as AccessConfig, a9 as AccessFunction, aa as AccessFunctionArgs, ab as AccessResult, ac as AccessRule, ad as ActionConfig, ae as ActionContext, af as ActionType, ag as AdminAuthAccessResolution, ah as AdminAuthClaimMapping, ai as AdminAuthMember, aj as AdminAuthProvider, ak as AdminAuthProviderMembersConfig, al as AdminAuthProvisioningMode, am as AdminAuthResolveAccessArgs, an as AdminAuthResolvedIdentity, ao as AdminConfig, ap as AdminDashboardComponentSlots, aq as AdminIconName, ar as AggregateArgs, as as AggregateCastType, at as AggregateInput, au as AggregateOperation, av as AggregateResult, aw as BaseAdminAuthProvider, ax as BaseFieldAdmin, ay as BlockVariant, az as BooleanFieldAdmin, aA as BooleanFormat, aB as CharacterLimitFieldAdmin, aC as CharacterLimitFieldConfig, aD as CollectionAfterChangeHook, aE as CollectionAfterDeleteHook, aF as CollectionAfterReadHook, aG as CollectionAfterReadHookEntry, aH as CollectionAfterTransitionHook, aI as CollectionBeforeChangeHook, aJ as CollectionBeforeChangeHookEntry, aK as CollectionBeforeDeleteHook, aL as CollectionBeforeReadHook, aM as CollectionBeforeReadHookEntry, aN as CollectionBeforeTransitionHook, aO as CollectionListComponentSlots, aP as CollectionViewComponentSlots, aQ as CountOperation, aR as CustomAdminAuthProvider, aS as DatabaseAdapter, aT as DateFieldAdmin, aU as DateFormat, aV as DefineActionOptions, aW as DefineViewOptions, aX as DetailSpan, aY as DisplayTone, aZ as DisplayVariant, a_ as DistinctCountOperation, a$ as DistinctValuesOperation, b0 as DynamicOptionItem, b1 as DynamicOptionsConfig, b2 as DynamicOptionsResolver, b3 as DynamicOptionsResolverArgs, b4 as DyrectedLoggerConfig, b5 as DyrectedObservabilityConfig, b6 as EmailFieldAdmin, b7 as FieldAdminHooks, b8 as FieldAdminOnChangeHook, b9 as FieldAdminOnChangeHookArgs, ba as FieldAdminOptionsHook, bb as FieldAdminOptionsHookArgs, bc as FieldAdminOptionsHookResult, bd as FieldAfterReadHook, be as FieldAfterReadHookArgs, bf as FieldBase, bg as FieldBeforeChangeHook, bh as FieldBeforeChangeHookArgs, bi as FieldHook, bj as FieldHooks, bk as FieldType, bl as FileData, bm as GlobalAfterChangeHook, bn as GlobalAfterReadHook, bo as GlobalAfterReadHookEntry, bp as GlobalBeforeChangeHook, bq as GlobalBeforeChangeHookEntry, br as GlobalBeforeReadHook, bs as GlobalBeforeReadHookEntry, bt as HeadingLevel, bu as HookFunction, bv as IconFieldAdmin, bw as ImageService, bx as InferAggregateResult, by as JoinFieldAdmin, bz as JsonFieldAdmin, bA as JsonFormat, bB as LIFECYCLE_EVENT_NAMES, bC as LifecycleEventHandler, bD as LinkFormat, bE as MetricColor, bF as MultiSelectFieldAdmin, bG as NamedAccessPolicy, bH as NumberFieldAdmin, bI as NumberFormat, bJ as NumberLimitFieldAdmin, bK as NumberLimitFieldConfig, bL as NumericOperation, bM as OIDCAdminAuthProvider, bN as OptionFormat, bO as PaginatedResult, bP as PublicAdminAuthProvider, bQ as RadioFieldAdmin, bR as RateLimitConfig, bS as ReadonlyDatabaseAdapter, bT as RichTextFeature, bU as RichTextFieldConfig, bV as SelectFieldAdmin, bW as SqlWhereResult, bX as StorageAdapter, bY as TextFieldAdmin, bZ as TextFormat, b_ as TextareaFieldAdmin, b$ as TrustProxyConfig, c0 as TypedField, c1 as UploadConfig, c2 as UrlFieldAdmin, c3 as UrlLinkValue, c4 as ViewActionFeatures, c5 as ViewComponentSlots, c6 as ViewConfig, c7 as ViewLayout, c8 as ViewMetric, c9 as ViewSubMetric, ca as WhereClause, cb as WhereOperator, cc as WhereOperatorName, cd as WordLimitFieldAdmin, ce as WordLimitFieldConfig, cf as WorkflowMetadata, cg as WorkflowRole, ch as WorkflowState, ci as WorkflowTransitionContext, cj as defineAction, ck as defineView, cl as parseMongoWhere, cm as parseSqlWhere } from './app-config-6U_Kum-Z.js';
1
+ import { F as Field, B as Block, D as DyrectedConfig, C as CollectionConfig, A as AdminAuthConfig, P as PublicAdminAuthConfig, G as GlobalConfig, a as DeclarativeHookExpression, W as WorkflowConfig, b as AuthenticatedUser, c as WorkflowTransition, L as LifecycleEventName, d as LifecycleEvent, e as BaseDocument, H as HookRequestContext, f as DetailComputedOptions, g as ComputedHandler, h as DetailComputed, i as DetailCustomOptions, j as DetailCustom, k as DetailDividerOptions, l as DetailDivider, m as DisplayFieldOptions, n as DetailField, o as DetailItem, p as DetailGridOptions, q as DetailGrid, r as DetailRepeatOptions, s as DetailRepeat, t as DetailSectionOptions, u as DetailSection, v as DetailTabOptions, w as DetailTab, x as DetailTabsOptions, y as DetailTabs, z as DetailTextOptions, E as DetailText, I as DetailSchema, J as DyrectedContext, K as AIConfig, M as AIPIIConfig, N as ArrayField, O as BlocksField, Q as BooleanField, R as AuthConfig, S as AccessPolicyResolver, T as DateField, U as DateTimeField, V as EmailField, X as IconField, Y as ImageField, Z as JoinField, _ as JsonField, $ as MultiSelectField, a0 as NumberField, a1 as ObjectField, a2 as RadioField, a3 as RelationshipField, a4 as RichTextField, a5 as RowField, a6 as SelectField, a7 as TextField, a8 as TextareaField, a9 as TimeField, aa as UrlField } from './app-D_ODsBWA.js';
2
+ export { ab as AIAction, ac as AIActionStatus, ad as AIActionType, ae as AIAuditActionType, af as AIAuditRecord, ag as AIChunk, ah as AIMessage, ai as AIPIIPattern, aj as AIRateLimitResult, ak as AIRateLimitStore, al as AIThread, am as AIToolContext, an as AIToolDefinition, ao as AI_ACTIONS_COLLECTION, ap as AI_AUDIT_COLLECTION, aq as AI_CHUNKS_COLLECTION, ar as AI_MESSAGES_COLLECTION, as as AI_THREADS_COLLECTION, at as AccessConfig, au as AccessFunction, av as AccessFunctionArgs, aw as AccessResult, ax as AccessRule, ay as ActionConfig, az as ActionContext, aA as ActionType, aB as AdminAuthAccessResolution, aC as AdminAuthClaimMapping, aD as AdminAuthMember, aE as AdminAuthProvider, aF as AdminAuthProviderMembersConfig, aG as AdminAuthProvisioningMode, aH as AdminAuthResolveAccessArgs, aI as AdminAuthResolvedIdentity, aJ as AdminConfig, aK as AdminDashboardComponentSlots, aL as AdminIconName, aM as AggregateArgs, aN as AggregateCastType, aO as AggregateCollectionResult, aP as AggregateInput, aQ as AggregateOperation, aR as AggregateResult, aS as BaseAdminAuthProvider, aT as BaseFieldAdmin, aU as BlockVariant, aV as BooleanFieldAdmin, aW as BooleanFormat, aX as CharacterLimitFieldAdmin, aY as CharacterLimitFieldConfig, aZ as CollectionAfterChangeHook, a_ as CollectionAfterDeleteHook, a$ as CollectionAfterReadHook, b0 as CollectionAfterReadHookEntry, b1 as CollectionAfterTransitionHook, b2 as CollectionBeforeChangeHook, b3 as CollectionBeforeChangeHookEntry, b4 as CollectionBeforeDeleteHook, b5 as CollectionBeforeReadHook, b6 as CollectionBeforeReadHookEntry, b7 as CollectionBeforeTransitionHook, b8 as CollectionListComponentSlots, b9 as CollectionRAGConfig, ba as CollectionSchemaResult, bb as CollectionSummaryResult, bc as CollectionViewComponentSlots, bd as CountOperation, be as CustomAdminAuthProvider, bf as DatabaseAdapter, bg as DateFieldAdmin, bh as DateFormat, bi as DefineActionOptions, bj as DefineViewOptions, bk as DetailSpan, bl as DisplayTone, bm as DisplayVariant, bn as DistinctCountOperation, bo as DistinctValuesOperation, bp as DynamicOptionItem, bq as DynamicOptionsConfig, br as DynamicOptionsResolver, bs as DynamicOptionsResolverArgs, bt as DyrectedAIContext, bu as DyrectedLoggerConfig, bv as DyrectedObservabilityConfig, bw as EmailFieldAdmin, bx as FieldAdminHooks, by as FieldAdminOnChangeHook, bz as FieldAdminOnChangeHookArgs, bA as FieldAdminOptionsHook, bB as FieldAdminOptionsHookArgs, bC as FieldAdminOptionsHookResult, bD as FieldAfterReadHook, bE as FieldAfterReadHookArgs, bF as FieldBase, bG as FieldBeforeChangeHook, bH as FieldBeforeChangeHookArgs, bI as FieldHook, bJ as FieldHooks, bK as FieldType, bL as FileData, bM as GetDocumentResult, bN as GlobalAfterChangeHook, bO as GlobalAfterReadHook, bP as GlobalAfterReadHookEntry, bQ as GlobalBeforeChangeHook, bR as GlobalBeforeChangeHookEntry, bS as GlobalBeforeReadHook, bT as GlobalBeforeReadHookEntry, bU as GlobalRAGConfig, bV as GlobalSchemaResult, bW as GlobalSummaryResult, bX as HeadingLevel, bY as HookFunction, bZ as IconFieldAdmin, b_ as ImageService, b$ as ImageTransformOptions, c0 as InferAggregateResult, c1 as JoinFieldAdmin, c2 as JsonFieldAdmin, c3 as JsonFormat, c4 as LIFECYCLE_EVENT_NAMES, c5 as LifecycleEventHandler, c6 as LinkFormat, c7 as MetricColor, c8 as MultiSelectFieldAdmin, c9 as NamedAccessPolicy, ca as NumberFieldAdmin, cb as NumberFormat, cc as NumberLimitFieldAdmin, cd as NumberLimitFieldConfig, ce as NumericOperation, cf as OIDCAdminAuthProvider, cg as OptionFormat, ch as PaginatedResult, ci as PublicAdminAuthProvider, cj as QueryCollectionResult, ck as RAGSearchResult, cl as RadioFieldAdmin, cm as RateLimitConfig, cn as ReadonlyDatabaseAdapter, co as RichTextFeature, cp as RichTextFieldConfig, cq as SelectFieldAdmin, cr as SqlWhereResult, cs as StorageAdapter, ct as TextFieldAdmin, cu as TextFormat, cv as TextareaFieldAdmin, cw as TrustProxyConfig, cx as TypedField, cy as UploadConfig, cz as UrlFieldAdmin, cA as UrlLinkValue, cB as ViewActionFeatures, cC as ViewComponentSlots, cD as ViewConfig, cE as ViewLayout, cF as ViewMetric, cG as ViewSubMetric, cH as WhereClause, cI as WhereOperator, cJ as WhereOperatorName, cK as WordLimitFieldAdmin, cL as WordLimitFieldConfig, cM as WorkflowMetadata, cN as WorkflowRole, cO as WorkflowState, cP as WorkflowTransitionContext, cQ as defineAction, cR as defineView, cS as isAICollection, cT as parseMongoWhere, cU as parseSqlWhere } from './app-D_ODsBWA.js';
3
3
  import jexl from 'jexl';
4
- import 'lucide-react';
4
+ import { Context } from 'hono';
5
+ export { z } from 'zod';
6
+ import 'hono/types';
5
7
  import 'pino';
8
+ import 'lucide-react';
9
+ import 'jose';
10
+ import '@opentelemetry/api';
11
+ import '@opentelemetry/exporter-prometheus';
6
12
 
7
13
  type Prettify<T> = {
8
14
  [K in keyof T]: T[K];
@@ -75,6 +81,21 @@ type UploadDocFields = {
75
81
  }>;
76
82
  };
77
83
 
84
+ type AIErrorCode = 'AI_UNCONFIGURED' | 'AI_RATE_LIMITED' | 'AI_QUOTA_EXHAUSTED' | 'AI_TIMEOUT' | 'AI_TOOL_VALIDATION_ERROR' | 'AI_PERMISSION_DENIED' | 'AI_TENANT_VIOLATION' | 'AI_ACTION_EXPIRED' | 'AI_ACTION_ALREADY_EXECUTED' | 'AI_INTERNAL_ERROR';
85
+ declare class DyrectedAIError extends Error {
86
+ readonly code: AIErrorCode;
87
+ readonly status: number;
88
+ readonly details?: Record<string, unknown>;
89
+ constructor(code: AIErrorCode, message: string, status?: number, details?: Record<string, unknown>);
90
+ toJSON(): {
91
+ error: boolean;
92
+ code: AIErrorCode;
93
+ message: string;
94
+ status: number;
95
+ details: Record<string, unknown> | undefined;
96
+ };
97
+ }
98
+
78
99
  /**
79
100
  * Normalizes the Dyrected configuration by injecting system fields
80
101
  * (createdAt, updatedAt, createdBy, updatedBy) into every collection and
@@ -751,6 +772,10 @@ declare class FieldConditionBuilder {
751
772
  * Checks that the field is null, undefined, or an empty string.
752
773
  */
753
774
  isEmpty(): string;
775
+ /**
776
+ * Alias for `isEmpty()`.
777
+ */
778
+ empty(): string;
754
779
  /**
755
780
  * Numerical greater than (`field > num`).
756
781
  */
@@ -791,6 +816,22 @@ declare class FieldConditionBuilder {
791
816
  * Checks if array/string length is at least a threshold.
792
817
  */
793
818
  hasLengthAtLeast(length: number): string;
819
+ /**
820
+ * Generates a JEXL `slugify(field)` transform expression.
821
+ */
822
+ slugify(): string;
823
+ /**
824
+ * Generates a JEXL `lower(field)` transform expression.
825
+ */
826
+ lower(): string;
827
+ /**
828
+ * Generates a JEXL `upper(field)` transform expression.
829
+ */
830
+ upper(): string;
831
+ /**
832
+ * Generates a JEXL `trim(field)` transform expression.
833
+ */
834
+ trim(): string;
794
835
  }
795
836
  /**
796
837
  * Pre-built access control condition helpers.
@@ -830,22 +871,26 @@ interface AccessConditions {
830
871
  * Condition builder utilities for serializable JEXL expressions in `admin.condition`,
831
872
  * access control rules, computed fields, and dynamic `admin.previewUrl`.
832
873
  */
833
- interface WhenFunction {
874
+ /**
875
+ * Expression builder utilities for serializable JEXL expressions in `admin.condition`,
876
+ * access control rules, computed fields, transforms, and dynamic `admin.previewUrl`.
877
+ */
878
+ interface ExprFunction {
834
879
  /**
835
- * Starts a fluent condition builder for a specific field name.
880
+ * Starts a fluent condition/expression builder for a specific field name.
836
881
  *
837
882
  * @example
838
- * admin: { condition: when('price').greaterThan(100) }
839
- * admin: { condition: when('status').in('published', 'archived') }
840
- * admin: { previewUrl: when.then(when('slug').equals('home'), '/', "'/' + slug") }
883
+ * admin: { condition: expr('price').greaterThan(100) }
884
+ * admin: { condition: expr('status').in('published', 'archived') }
885
+ * admin: { previewUrl: expr.ifElse(expr('slug').equals('home'), '/', expr.concat('/', 'slug')) }
841
886
  */
842
887
  (fieldName: string): FieldConditionBuilder;
843
888
  /**
844
- * Starts a fluent condition builder on the `user` context (e.g. `when.user('email').endsWith('@company.com')`).
889
+ * Starts a fluent condition builder on the `user` context (e.g. `expr.user('email').endsWith('@company.com')`).
845
890
  */
846
891
  user: (userProp: string) => FieldConditionBuilder;
847
892
  /**
848
- * Starts a fluent condition builder on `siblingData` (e.g. `when.sibling('_variant').equals('split')`).
893
+ * Starts a fluent condition builder on `siblingData` (e.g. `expr.sibling('_variant').equals('split')`).
849
894
  */
850
895
  sibling: (siblingProp: string) => FieldConditionBuilder;
851
896
  /**
@@ -857,10 +902,10 @@ interface WhenFunction {
857
902
  * Automatically quotes literal segments (like paths) and preserves field identifiers.
858
903
  *
859
904
  * @example
860
- * when.concat('/country-portals/', 'slug')
905
+ * expr.concat('/country-portals/', 'slug')
861
906
  * // => "'/country-portals/' + slug"
862
907
  *
863
- * when.concat('/blog/', 'category', '/', 'slug')
908
+ * expr.concat('/blog/', 'category', '/', 'slug')
864
909
  * // => "'/blog/' + category + '/' + slug"
865
910
  */
866
911
  concat: (...parts: string[]) => string;
@@ -885,7 +930,11 @@ interface WhenFunction {
885
930
  * Can be nested to create ternary chains.
886
931
  *
887
932
  * @example
888
- * admin: { previewUrl: when.then(when.fieldEquals('slug', 'home'), '/', "'/' + slug") }
933
+ * admin: { previewUrl: expr.ifElse(expr.equals('slug', 'home'), '/', expr.concat('/', 'slug')) }
934
+ */
935
+ ifElse: (condition: string, ifTrue: string | number | boolean | null, ifFalse?: string | number | boolean | null) => string;
936
+ /**
937
+ * Alias for `ifElse`.
889
938
  */
890
939
  then: (condition: string, ifTrue: string | number | boolean | null, ifFalse?: string | number | boolean | null) => string;
891
940
  /**
@@ -893,10 +942,10 @@ interface WhenFunction {
893
942
  *
894
943
  * @example
895
944
  * admin: {
896
- * previewUrl: when.match()
897
- * .case(when('slug').equals('home'), '/')
898
- * .case(when.fieldNotEmpty('path'), 'path')
899
- * .case(when('category').equals('news'), "'/news/' + slug")
945
+ * previewUrl: expr.match()
946
+ * .case(expr('slug').equals('home'), '/')
947
+ * .case(expr.notEmpty('path'), 'path')
948
+ * .case(expr('category').equals('news'), "'/news/' + slug")
900
949
  * .otherwise("'/' + slug")
901
950
  * }
902
951
  */
@@ -906,9 +955,9 @@ interface WhenFunction {
906
955
  *
907
956
  * @example
908
957
  * admin: {
909
- * previewUrl: when.cases(
910
- * [when.fieldEquals('slug', 'home'), '/'],
911
- * [when.fieldNotEmpty('path'), 'path'],
958
+ * previewUrl: expr.cases(
959
+ * [expr.equals('slug', 'home'), '/'],
960
+ * [expr.notEmpty('path'), 'path'],
912
961
  * "'/' + slug"
913
962
  * )
914
963
  * }
@@ -919,7 +968,7 @@ interface WhenFunction {
919
968
  */
920
969
  all: (...conditions: (string | undefined | null | false)[]) => string;
921
970
  /**
922
- * Alias for `when.all(...)`.
971
+ * Alias for `expr.all(...)`.
923
972
  */
924
973
  and: (...conditions: (string | undefined | null | false)[]) => string;
925
974
  /**
@@ -927,7 +976,7 @@ interface WhenFunction {
927
976
  */
928
977
  any: (...conditions: (string | undefined | null | false)[]) => string;
929
978
  /**
930
- * Alias for `when.any(...)`.
979
+ * Alias for `expr.any(...)`.
931
980
  */
932
981
  or: (...conditions: (string | undefined | null | false)[]) => string;
933
982
  /**
@@ -938,8 +987,8 @@ interface WhenFunction {
938
987
  * Generates a condition matching one or multiple variant names.
939
988
  *
940
989
  * @example
941
- * admin: { condition: when.variant('split') }
942
- * admin: { condition: when.variant('imageLeft', 'imageRight') }
990
+ * admin: { condition: expr.variant('split') }
991
+ * admin: { condition: expr.variant('imageLeft', 'imageRight') }
943
992
  */
944
993
  variant: (...variants: (string | string[])[]) => string;
945
994
  /**
@@ -950,7 +999,7 @@ interface WhenFunction {
950
999
  * Generates a condition matching one or multiple block slugs.
951
1000
  *
952
1001
  * @example
953
- * admin: { condition: when.block('hero', 'cta') }
1002
+ * admin: { condition: expr.block('hero', 'cta') }
954
1003
  */
955
1004
  block: (...blocks: (string | string[])[]) => string;
956
1005
  /**
@@ -961,71 +1010,90 @@ interface WhenFunction {
961
1010
  * Generates a condition checking equality against a field value.
962
1011
  *
963
1012
  * @example
964
- * admin: { condition: when.fieldEquals('status', 'published') }
1013
+ * admin: { condition: expr.equals('status', 'published') }
965
1014
  */
966
- fieldEquals: (field: string, value: string | number | boolean | null) => string;
1015
+ equals: (field: string, value: string | number | boolean | null) => string;
967
1016
  /**
968
1017
  * Generates a condition checking inequality against a field value.
969
1018
  */
970
- fieldNotEquals: (field: string, value: string | number | boolean | null) => string;
1019
+ notEquals: (field: string, value: string | number | boolean | null) => string;
971
1020
  /**
972
1021
  * Generates a condition checking if a field is in a list of allowed values.
973
1022
  */
974
- fieldIn: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
1023
+ in: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
975
1024
  /**
976
1025
  * Generates a condition checking if a field is NOT in a list of values.
977
1026
  */
978
- fieldNotIn: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
1027
+ notIn: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
979
1028
  /**
980
1029
  * Generates a condition checking that a field is not null and not empty.
981
1030
  *
982
1031
  * @example
983
- * admin: { condition: when.fieldNotEmpty('couponCode') }
1032
+ * admin: { condition: expr.notEmpty('couponCode') }
984
1033
  */
985
- fieldNotEmpty: (field: string) => string;
1034
+ notEmpty: (field: string) => string;
986
1035
  /**
987
1036
  * Generates a condition checking that a field is null, undefined, or empty.
1037
+ *
1038
+ * @example
1039
+ * admin: { condition: expr.empty('couponCode') }
988
1040
  */
989
- fieldEmpty: (field: string) => string;
1041
+ empty: (field: string) => string;
990
1042
  /**
991
1043
  * Generates a condition checking that a boolean field is true.
992
1044
  */
993
- fieldIsTrue: (field: string) => string;
1045
+ isTrue: (field: string) => string;
994
1046
  /**
995
1047
  * Generates a condition checking that a boolean field is false / falsy.
996
1048
  */
997
- fieldIsFalse: (field: string) => string;
1049
+ isFalse: (field: string) => string;
998
1050
  /**
999
1051
  * Generates a numerical greater-than condition (`field > value`).
1000
1052
  */
1001
- fieldGreaterThan: (field: string, value: number | string) => string;
1053
+ greaterThan: (field: string, value: number | string) => string;
1002
1054
  /**
1003
1055
  * Generates a numerical greater-than-or-equal condition (`field >= value`).
1004
1056
  */
1005
- fieldGreaterThanOrEqual: (field: string, value: number | string) => string;
1057
+ greaterThanOrEqual: (field: string, value: number | string) => string;
1006
1058
  /**
1007
1059
  * Generates a numerical less-than condition (`field < value`).
1008
1060
  */
1009
- fieldLessThan: (field: string, value: number | string) => string;
1061
+ lessThan: (field: string, value: number | string) => string;
1010
1062
  /**
1011
1063
  * Generates a numerical less-than-or-equal condition (`field <= value`).
1012
1064
  */
1013
- fieldLessThanOrEqual: (field: string, value: number | string) => string;
1065
+ lessThanOrEqual: (field: string, value: number | string) => string;
1014
1066
  /**
1015
1067
  * Generates a range condition (`field >= min && field <= max`).
1016
1068
  */
1017
- fieldBetween: (field: string, min: number, max: number) => string;
1069
+ between: (field: string, min: number, max: number) => string;
1018
1070
  /**
1019
1071
  * Generates a string prefix condition using JEXL `startsWith(...)`.
1020
1072
  */
1021
- fieldStartsWith: (field: string, prefix: string) => string;
1073
+ startsWith: (field: string, prefix: string) => string;
1022
1074
  /**
1023
1075
  * Generates a string suffix condition using JEXL `endsWith(...)`.
1024
1076
  */
1025
- fieldEndsWith: (field: string, suffix: string) => string;
1077
+ endsWith: (field: string, suffix: string) => string;
1026
1078
  /**
1027
1079
  * Generates a string/array inclusion condition using JEXL `includes(...)`.
1028
1080
  */
1081
+ contains: (field: string, item: string | number) => string;
1082
+ fieldEquals: (field: string, value: string | number | boolean | null) => string;
1083
+ fieldNotEquals: (field: string, value: string | number | boolean | null) => string;
1084
+ fieldIn: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
1085
+ fieldNotIn: (field: string, ...values: (string | number | boolean | (string | number | boolean)[])[]) => string;
1086
+ fieldNotEmpty: (field: string) => string;
1087
+ fieldEmpty: (field: string) => string;
1088
+ fieldIsTrue: (field: string) => string;
1089
+ fieldIsFalse: (field: string) => string;
1090
+ fieldGreaterThan: (field: string, value: number | string) => string;
1091
+ fieldGreaterThanOrEqual: (field: string, value: number | string) => string;
1092
+ fieldLessThan: (field: string, value: number | string) => string;
1093
+ fieldLessThanOrEqual: (field: string, value: number | string) => string;
1094
+ fieldBetween: (field: string, min: number, max: number) => string;
1095
+ fieldStartsWith: (field: string, prefix: string) => string;
1096
+ fieldEndsWith: (field: string, suffix: string) => string;
1029
1097
  fieldContains: (field: string, item: string | number) => string;
1030
1098
  /**
1031
1099
  * Generates a condition checking that an array is non-empty (`length(field) > 0`).
@@ -1052,14 +1120,14 @@ interface WhenFunction {
1052
1120
  * Checks both `user.role` (string) and `user.roles` (array).
1053
1121
  *
1054
1122
  * @example
1055
- * admin: { condition: when.userRole('admin', 'developer') }
1123
+ * admin: { condition: expr.userRole('admin', 'developer') }
1056
1124
  */
1057
1125
  userRole: (...roles: (string | string[])[]) => string;
1058
1126
  /**
1059
1127
  * Generates a condition checking the editor's email domain.
1060
1128
  *
1061
1129
  * @example
1062
- * admin: { condition: when.userEmailDomain('agrictrail.com') }
1130
+ * admin: { condition: expr.userEmailDomain('agrictrail.com') }
1063
1131
  */
1064
1132
  userEmailDomain: (domain: string) => string;
1065
1133
  /**
@@ -1083,7 +1151,73 @@ interface WhenFunction {
1083
1151
  */
1084
1152
  statusIn: (...statuses: (string | string[])[]) => string;
1085
1153
  }
1086
- declare const when: WhenFunction;
1154
+ /**
1155
+ * Backwards compatibility type alias for `ExprFunction`.
1156
+ */
1157
+ type WhenFunction = ExprFunction;
1158
+ /**
1159
+ * Primary declarative expression builder for Dyrected schemas.
1160
+ */
1161
+ declare const expr: ExprFunction;
1162
+ /**
1163
+ * Backwards compatibility alias for `expr`.
1164
+ */
1165
+ declare const when: ExprFunction;
1166
+
1167
+ /**
1168
+ * Extracts the list of allowed site IDs for a given authenticated user or token payload.
1169
+ * Checks common tenant membership properties: `allowedSites`, `siteIds`, `siteAccess`, and singular `siteId`.
1170
+ */
1171
+ declare function getAllowedSitesForUser(user?: Record<string, unknown> | null, payload?: Record<string, unknown> | null): string[] | undefined;
1172
+ /**
1173
+ * Checks whether an authenticated user is permitted to access a given site ID.
1174
+ * If the user has no tenant restrictions configured, access is unrestricted (returns true).
1175
+ */
1176
+ declare function isSiteAuthorized(user: Record<string, unknown> | null | undefined, payload: Record<string, unknown> | null | undefined, requestedSiteId: string | undefined): boolean;
1177
+ /**
1178
+ * Resolves the authorized site ID for the current request.
1179
+ * Prioritizes `c.get("siteId")` (set upstream) and `X-Site-Id` header.
1180
+ * Enforces that restricted users cannot spoof or access unauthorized site IDs.
1181
+ *
1182
+ * @throws HTTPException(403) if the user is not authorized for the requested site.
1183
+ */
1184
+ declare function resolveAuthorizedSiteId(c: Context<DyrectedContext>): string;
1185
+
1186
+ declare const NON_NEGOTIABLE_CREDENTIAL_FIELDS: Set<string>;
1187
+ /**
1188
+ * Masks an email address to protect privacy (e.g. "john.doe@example.com" -> "j***@example.com").
1189
+ */
1190
+ declare function maskEmail(email: string, strategy?: "mask" | "token"): string;
1191
+ /**
1192
+ * Masks a phone number (e.g. "+1 555-234-5678" -> "+1 ***-***-5678").
1193
+ */
1194
+ declare function maskPhone(phone: string, strategy?: "mask" | "token"): string;
1195
+ /**
1196
+ * High-performance regex patterns for common PII.
1197
+ */
1198
+ declare const PII_REGEX_PATTERNS: Record<string, RegExp>;
1199
+ /**
1200
+ * Scrubs unstructured free text using configured regex patterns and custom scrubbers.
1201
+ */
1202
+ declare function maskTextPII(text: string, piiConfig?: AIPIIConfig): string;
1203
+ interface SanitizeDocForAIOptions {
1204
+ doc: Record<string, unknown>;
1205
+ collectionConfig?: CollectionConfig;
1206
+ globalAIConfig?: AIConfig;
1207
+ }
1208
+ /**
1209
+ * Deterministically sanitizes a CMS document before sending it to an AI assistant or RAG pipeline:
1210
+ * 1. Non-negotiably strips passwords, secrets, hashes, and session tokens.
1211
+ * 2. Strips collection-level `excludeFields`.
1212
+ * 3. Applies field-level definitions:
1213
+ * - Automatically masks `email` and `phone` by default (opt-out privacy) unless `ai: { allowRaw: true }`.
1214
+ * - Strips fields configured with `ai: { exclude: true }`.
1215
+ * - Masks fields configured with `ai: { redact: true }`.
1216
+ * 4. Applies collection-level `redactFields`.
1217
+ * 5. Calls custom programmatic `collectionConfig.ai.sanitizeDoc` hook if provided.
1218
+ * 6. Scrubs unstructured text across string fields if `config.ai.pii.enabled === true`.
1219
+ */
1220
+ declare function sanitizeDocForAI(options: SanitizeDocForAIOptions): Record<string, unknown>;
1087
1221
 
1088
1222
  type TopLevelFieldName<TFields extends readonly Field[]> = Extract<TFields[number], {
1089
1223
  name: string;
@@ -1504,4 +1638,4 @@ declare function defineTab<const T extends readonly Field[]>(args: {
1504
1638
  fields: T;
1505
1639
  }): T;
1506
1640
 
1507
- export { type AccessConditions, AccessPolicyResolver, AdminAuthConfig, ArrayField, AuthConfig, type AuthDocFields, AuthenticatedUser, BUILTIN_JEXL_HELPERS, BaseDocument, Block, BlocksField, BooleanField, CollectionConfig, ComputedHandler, type ConfigDiagnostic, ConfigValidationError, DateField, DateTimeField, type DeclarativeAccessSurface, type DeclarativeAccessValidationIssue, type DeclarativeAdminSurface, type DeclarativeAdminValidationIssue, DeclarativeHookExpression, type DeclarativeHookSurface, type DeclarativeHookValidationIssue, type DeclarativePreviewSurface, type DeclarativePreviewValidationIssue, DetailComputed, DetailComputedOptions, DetailCustom, DetailCustomOptions, DetailDivider, DetailDividerOptions, DetailField, DetailGrid, DetailGridOptions, DetailItem, DetailRepeat, DetailRepeatOptions, DetailSchema, DetailSection, DetailSectionOptions, DetailTab, DetailTabOptions, DetailTabs, DetailTabsOptions, DetailText, DetailTextOptions, DisplayFieldOptions, DyrectedConfig, EmailField, Field, FieldConditionBuilder, GlobalConfig, HookRequestContext, IconField, ImageField, type InferDocShape, JoinField, JsonField, LIFECYCLE_EVENTS_COLLECTION, LifecycleEvent, LifecycleEventName, MatchBuilder, MultiSelectField, NumberField, ObjectField, type Prettify, PublicAdminAuthConfig, type PublishingWorkflowOptions, RadioField, RelationshipField, RichTextField, RowField, SelectField, type SortClause, type SortDirection, type SqlSortDialect, type SystemDocFields, TextField, TextareaField, TimeField, type UploadDocFields, UrlField, WORKFLOW_HISTORY_COLLECTION, type WhenFunction, WorkflowConfig, WorkflowTransition, abs, addDays, assertValidAdminConditionsInConfig, assertValidDeclarativeAccessInConfig, assertValidDeclarativeHookExpression, assertValidDeclarativeHookResult, assertValidDeclarativeHooksInConfig, assertValidPreviewUrlsInConfig, availableWorkflowTransitions, buildSqlOrderBy, canViewWorkflowDraft, capitalize, ceil, clamp, coalesce, collectAdminConditionValidationIssues, collectConfigDiagnostics, collectDeclarativeAccessValidationIssues, collectDeclarativeHookValidationIssues, collectPreviewUrlValidationIssues, compact, count, createLifecycleEvent, createWorkflowDocument, defaultValue, defineArrayField, defineBlock, defineBlocksField, defineBooleanField, defineCollection, defineConfig, defineDateField, defineDateTimeField, defineEmailField, defineField, defineGlobal, defineIconField, defineImageField, defineJoinField, defineJsonField, defineMultiSelectField, defineNumberField, defineObjectField, definePublishingWorkflow, defineRadioField, defineRelationshipField, defineRichTextField, defineRowField, defineSelectField, defineTab, defineTextField, defineTextareaField, defineTimeField, defineUrlField, diffDays, dispatchLifecycleEvent, dispatchPendingLifecycleEvents, displayComputed, displayCustom, displayCustomComponent, displayDivider, displayField, displayGrid, displayRepeat, displaySection, displayTab, displayTabs, displayText, endsWith, evaluateDetailComputed, evaluateJexl, evaluateJexlSync, executeFieldAfterRead, executeFieldBeforeChange, first, floor, formatConfigDiagnostics, formatDate, formatJexlValue, generateDefaultDetailSchema, generateOpenApi, get, getAdminAuthCollection, getPublicAdminAuthConfig, includes, initializeWorkflowDocument, isConfigValidationError, isDetailItemVisible, isEmpty, isFuture, isPast, join, last, length, lower, materializeWorkflowDocument, max, min, normalizeConfig, normalizeDetailItem, now, numericFieldNames, parseSort, pow, publishedStateName, publishingWorkflow, readingTime, registerJexlHelpers, replace, resolveAdminAuthCollection, round, runCollectionHooks, saveWorkflowDraft, simplePublishingWorkflow, slugify, sqrt, startsWith, sum, today, transitionWorkflow, trim, truncate, unique, upper, validateAdminConditionExpression, validateDeclarativeAccessExpression, validateDeclarativeHookExpression, validatePreviewUrlExpression, when, wordCount, workflowCapabilities };
1641
+ export { AIConfig, type AIErrorCode, AIPIIConfig, type AccessConditions, AccessPolicyResolver, AdminAuthConfig, ArrayField, AuthConfig, type AuthDocFields, AuthenticatedUser, BUILTIN_JEXL_HELPERS, BaseDocument, Block, BlocksField, BooleanField, CollectionConfig, ComputedHandler, type ConfigDiagnostic, ConfigValidationError, DateField, DateTimeField, type DeclarativeAccessSurface, type DeclarativeAccessValidationIssue, type DeclarativeAdminSurface, type DeclarativeAdminValidationIssue, DeclarativeHookExpression, type DeclarativeHookSurface, type DeclarativeHookValidationIssue, type DeclarativePreviewSurface, type DeclarativePreviewValidationIssue, DetailComputed, DetailComputedOptions, DetailCustom, DetailCustomOptions, DetailDivider, DetailDividerOptions, DetailField, DetailGrid, DetailGridOptions, DetailItem, DetailRepeat, DetailRepeatOptions, DetailSchema, DetailSection, DetailSectionOptions, DetailTab, DetailTabOptions, DetailTabs, DetailTabsOptions, DetailText, DetailTextOptions, DisplayFieldOptions, DyrectedAIError, DyrectedConfig, EmailField, type ExprFunction, Field, FieldConditionBuilder, GlobalConfig, HookRequestContext, IconField, ImageField, type InferDocShape, JoinField, JsonField, LIFECYCLE_EVENTS_COLLECTION, LifecycleEvent, LifecycleEventName, MatchBuilder, MultiSelectField, NON_NEGOTIABLE_CREDENTIAL_FIELDS, NumberField, ObjectField, PII_REGEX_PATTERNS, type Prettify, PublicAdminAuthConfig, type PublishingWorkflowOptions, RadioField, RelationshipField, RichTextField, RowField, type SanitizeDocForAIOptions, SelectField, type SortClause, type SortDirection, type SqlSortDialect, type SystemDocFields, TextField, TextareaField, TimeField, type UploadDocFields, UrlField, WORKFLOW_HISTORY_COLLECTION, type WhenFunction, WorkflowConfig, WorkflowTransition, abs, addDays, assertValidAdminConditionsInConfig, assertValidDeclarativeAccessInConfig, assertValidDeclarativeHookExpression, assertValidDeclarativeHookResult, assertValidDeclarativeHooksInConfig, assertValidPreviewUrlsInConfig, availableWorkflowTransitions, buildSqlOrderBy, canViewWorkflowDraft, capitalize, ceil, clamp, coalesce, collectAdminConditionValidationIssues, collectConfigDiagnostics, collectDeclarativeAccessValidationIssues, collectDeclarativeHookValidationIssues, collectPreviewUrlValidationIssues, compact, count, createLifecycleEvent, createWorkflowDocument, defaultValue, defineArrayField, defineBlock, defineBlocksField, defineBooleanField, defineCollection, defineConfig, defineDateField, defineDateTimeField, defineEmailField, defineField, defineGlobal, defineIconField, defineImageField, defineJoinField, defineJsonField, defineMultiSelectField, defineNumberField, defineObjectField, definePublishingWorkflow, defineRadioField, defineRelationshipField, defineRichTextField, defineRowField, defineSelectField, defineTab, defineTextField, defineTextareaField, defineTimeField, defineUrlField, diffDays, dispatchLifecycleEvent, dispatchPendingLifecycleEvents, displayComputed, displayCustom, displayCustomComponent, displayDivider, displayField, displayGrid, displayRepeat, displaySection, displayTab, displayTabs, displayText, endsWith, evaluateDetailComputed, evaluateJexl, evaluateJexlSync, executeFieldAfterRead, executeFieldBeforeChange, expr, first, floor, formatConfigDiagnostics, formatDate, formatJexlValue, generateDefaultDetailSchema, generateOpenApi, get, getAdminAuthCollection, getAllowedSitesForUser, getPublicAdminAuthConfig, includes, initializeWorkflowDocument, isConfigValidationError, isDetailItemVisible, isEmpty, isFuture, isPast, isSiteAuthorized, join, last, length, lower, maskEmail, maskPhone, maskTextPII, materializeWorkflowDocument, max, min, normalizeConfig, normalizeDetailItem, now, numericFieldNames, parseSort, pow, publishedStateName, publishingWorkflow, readingTime, registerJexlHelpers, replace, resolveAdminAuthCollection, resolveAuthorizedSiteId, round, runCollectionHooks, sanitizeDocForAI, saveWorkflowDraft, simplePublishingWorkflow, slugify, sqrt, startsWith, sum, today, transitionWorkflow, trim, truncate, unique, upper, validateAdminConditionExpression, validateDeclarativeAccessExpression, validateDeclarativeHookExpression, validatePreviewUrlExpression, when, wordCount, workflowCapabilities };