@nocobase/plugin-flow-engine 2.2.0-alpha.1 → 2.2.0-alpha.2

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.
Files changed (65) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +9 -9
  3. package/dist/locale/en-US.json +1 -0
  4. package/dist/locale/index.d.ts +2 -0
  5. package/dist/locale/zh-CN.json +1 -0
  6. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  7. package/dist/node_modules/acorn/package.json +1 -1
  8. package/dist/node_modules/acorn-jsx/package.json +1 -1
  9. package/dist/node_modules/acorn-walk/package.json +1 -1
  10. package/dist/node_modules/ses/package.json +1 -1
  11. package/dist/node_modules/zod/package.json +1 -1
  12. package/dist/server/flow-surfaces/{runjs-authoring/blocked-global-stop/index.d.ts → approval/authoring-validation.d.ts} +1 -2
  13. package/dist/server/flow-surfaces/approval/authoring-validation.js +1151 -0
  14. package/dist/server/flow-surfaces/approval/blueprint-service.js +2 -0
  15. package/dist/server/flow-surfaces/authoring-validation.js +452 -39
  16. package/dist/server/flow-surfaces/blueprint/export-document.d.ts +50 -0
  17. package/dist/server/flow-surfaces/blueprint/export-document.js +2505 -0
  18. package/dist/server/flow-surfaces/builder.js +16 -1
  19. package/dist/server/flow-surfaces/catalog.js +3 -1
  20. package/dist/server/flow-surfaces/configure-options.js +4 -3
  21. package/dist/server/flow-surfaces/constants.d.ts +9 -2
  22. package/dist/server/flow-surfaces/constants.js +1 -0
  23. package/dist/server/flow-surfaces/contract-guard.js +24 -2
  24. package/dist/server/flow-surfaces/default-action-popup.d.ts +2 -0
  25. package/dist/server/flow-surfaces/default-action-popup.js +27 -13
  26. package/dist/server/flow-surfaces/filter-group.d.ts +19 -2
  27. package/dist/server/flow-surfaces/filter-group.js +232 -3
  28. package/dist/server/flow-surfaces/planning/compiler.d.ts +1 -0
  29. package/dist/server/flow-surfaces/planning/compiler.js +205 -82
  30. package/dist/server/flow-surfaces/planning/key-registry.d.ts +1 -1
  31. package/dist/server/flow-surfaces/planning/runtime.js +1 -0
  32. package/dist/server/flow-surfaces/planning/step-link.d.ts +1 -1
  33. package/dist/server/flow-surfaces/planning/step-link.js +22 -3
  34. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +0 -9
  35. package/dist/server/flow-surfaces/reaction/field-value.d.ts +9 -0
  36. package/dist/server/flow-surfaces/reaction/field-value.js +51 -2
  37. package/dist/server/flow-surfaces/reaction/linkage.d.ts +6 -1
  38. package/dist/server/flow-surfaces/reaction/linkage.js +18 -3
  39. package/dist/server/flow-surfaces/reaction/meta.js +19 -1
  40. package/dist/server/flow-surfaces/reaction/types.d.ts +19 -0
  41. package/dist/server/flow-surfaces/relation-backing-foreign-key.d.ts +10 -0
  42. package/dist/server/flow-surfaces/relation-backing-foreign-key.js +79 -0
  43. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +1 -0
  44. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +20 -0
  45. package/dist/server/flow-surfaces/runjs-authoring/rules.js +0 -2
  46. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +0 -1
  47. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +11 -19
  48. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +0 -12
  49. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +12 -2
  50. package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +0 -14
  51. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +10 -8
  52. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +0 -14
  53. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +18 -73
  54. package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
  55. package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +9 -53
  56. package/dist/server/flow-surfaces/service.d.ts +42 -0
  57. package/dist/server/flow-surfaces/service.js +727 -93
  58. package/dist/server/variables/registry.js +3 -0
  59. package/dist/swagger/flow-surfaces.d.ts +180 -0
  60. package/dist/swagger/flow-surfaces.examples.d.ts +8 -0
  61. package/dist/swagger/flow-surfaces.examples.js +8 -0
  62. package/dist/swagger/flow-surfaces.js +160 -4
  63. package/dist/swagger/index.d.ts +180 -0
  64. package/package.json +2 -2
  65. package/dist/server/flow-surfaces/runjs-authoring/blocked-global-stop/index.js +0 -40
@@ -51,6 +51,7 @@ var import_association_title_field = require("./association-title-field");
51
51
  var import_chart_config = require("./chart-config");
52
52
  var import_public_data_surface_default_filter = require("./public-data-surface-default-filter");
53
53
  var import_default_action_popup = require("./default-action-popup");
54
+ var import_relation_backing_foreign_key = require("./relation-backing-foreign-key");
54
55
  var import_default_block_actions = require("./default-block-actions");
55
56
  var import_hidden_popup_contract = require("./hidden-popup-contract");
56
57
  var import_node_use_sets = require("./node-use-sets");
@@ -60,6 +61,7 @@ var import_association_interfaces = require("./association-interfaces");
60
61
  var import_defaults = require("./blueprint/defaults");
61
62
  var import_runjs_authoring = require("./runjs-authoring");
62
63
  var import_configure_options = require("./configure-options");
64
+ var import_context = require("./context");
63
65
  var import_filter_group = require("./filter-group");
64
66
  const MAIN_BLOCK_UNSUPPORTED_SECTIONS = {
65
67
  calendar: ["fields", "fieldGroups", "recordActions", "fieldsLayout"],
@@ -472,7 +474,10 @@ async function collectFlowSurfaceAuthoringErrors(actionName, values, context = {
472
474
  blocks.forEach(({ block }) => collectLocalKeys(block, localKeys));
473
475
  }
474
476
  blocks.forEach(({ block, path }) => collectBlockErrors(block, path, errors, localKeys, validationContext));
475
- collectReactionErrors(values == null ? void 0 : values.reaction, "$.reaction", localKeys, errors);
477
+ collectReactionErrors(values == null ? void 0 : values.reaction, "$.reaction", localKeys, errors, {
478
+ values,
479
+ context: validationContext
480
+ });
476
481
  if (!validationContext.skipGeneratedPopupDefaultFieldGroups) {
477
482
  collectGeneratedPopupDefaultFieldGroupErrors(actionName, values, validationContext, errors);
478
483
  }
@@ -1177,47 +1182,69 @@ function collectBuilderChartAssetQueryErrors(query, path, context, errors) {
1177
1182
  errors,
1178
1183
  withChartRepairHint()
1179
1184
  );
1180
- collectChartQueryFilterOperatorErrors(query, `${path}.query`, errors);
1185
+ collectChartQueryFilterOperatorErrors(query, `${path}.query`, errors, context);
1181
1186
  collectBuilderChartAssetFieldErrors(query, path, context, errors);
1182
1187
  }
1183
- function collectChartQueryFilterOperatorErrors(query, path, errors) {
1188
+ const AUTHORABLE_REACTION_SCALAR_CONTEXT_PATHS = /* @__PURE__ */ new Set(["role", "locale", "token", "deviceType"]);
1189
+ const AUTHORABLE_REACTION_CONTEXT_ROOTS = /* @__PURE__ */ new Set([
1190
+ "user",
1191
+ "collection",
1192
+ "formValues",
1193
+ "record",
1194
+ "item",
1195
+ "popup",
1196
+ "urlSearchParams"
1197
+ ]);
1198
+ function collectChartQueryFilterOperatorErrors(query, path, errors, context) {
1184
1199
  if (!_.isPlainObject(query) || !hasOwn(query, "filter")) {
1185
1200
  return;
1186
1201
  }
1187
- collectChartFilterOperatorErrors(query.filter, `${path}.filter`, errors);
1202
+ collectChartFilterOperatorErrors(
1203
+ query.filter,
1204
+ `${path}.filter`,
1205
+ errors,
1206
+ createChartQueryDateConditionFieldResolver(query, context)
1207
+ );
1188
1208
  }
1189
- function collectChartFilterOperatorErrors(filter, path, errors) {
1209
+ function collectChartFilterOperatorErrors(filter, path, errors, resolveField) {
1190
1210
  if (_.isUndefined(filter) || _.isNull(filter) || !_.isPlainObject(filter)) {
1191
1211
  return;
1192
1212
  }
1193
1213
  if (Array.isArray(filter.items)) {
1194
- collectChartFilterGroupOperatorErrors(filter.items, `${path}.items`, errors);
1214
+ collectChartFilterGroupOperatorErrors(filter.items, `${path}.items`, errors, resolveField);
1195
1215
  return;
1196
1216
  }
1197
- collectBackendQueryFilterOperatorErrors(filter, path, errors);
1217
+ collectBackendQueryFilterOperatorErrors(filter, path, errors, resolveField);
1198
1218
  }
1199
- function collectChartFilterGroupOperatorErrors(items, path, errors) {
1219
+ function collectChartFilterGroupOperatorErrors(items, path, errors, resolveField) {
1200
1220
  items.forEach((item, index) => {
1201
1221
  const itemPath = `${path}[${index}]`;
1202
1222
  if (!_.isPlainObject(item)) {
1203
1223
  return;
1204
1224
  }
1205
1225
  if (Array.isArray(item.items)) {
1206
- collectChartFilterGroupOperatorErrors(item.items, `${itemPath}.items`, errors);
1226
+ collectChartFilterGroupOperatorErrors(item.items, `${itemPath}.items`, errors, resolveField);
1207
1227
  return;
1208
1228
  }
1209
1229
  if (hasOwn(item, "operator")) {
1210
1230
  collectChartFilterOperatorError(item.operator, `${itemPath}.operator`, errors);
1211
- collectChartFilterDateValueError(item.operator, item.value, `${itemPath}.value`, errors);
1231
+ const fieldPath = String(item.path || item.field || "").trim();
1232
+ collectChartFilterDateValueError(
1233
+ item.operator,
1234
+ item.value,
1235
+ `${itemPath}.value`,
1236
+ errors,
1237
+ fieldPath ? (resolveField == null ? void 0 : resolveField(fieldPath)) || { fieldPath } : void 0
1238
+ );
1212
1239
  }
1213
1240
  });
1214
1241
  }
1215
- function collectBackendQueryFilterOperatorErrors(filter, path, errors) {
1242
+ function collectBackendQueryFilterOperatorErrors(filter, path, errors, resolveField) {
1216
1243
  Object.entries(filter).forEach(([field, condition]) => {
1217
1244
  const fieldPath = `${path}.${field}`;
1218
1245
  if ((field === "$and" || field === "$or") && Array.isArray(condition)) {
1219
1246
  condition.forEach(
1220
- (operand, index) => collectChartFilterOperatorErrors(operand, `${fieldPath}[${index}]`, errors)
1247
+ (operand, index) => collectChartFilterOperatorErrors(operand, `${fieldPath}[${index}]`, errors, resolveField)
1221
1248
  );
1222
1249
  return;
1223
1250
  }
@@ -1226,11 +1253,17 @@ function collectBackendQueryFilterOperatorErrors(filter, path, errors) {
1226
1253
  }
1227
1254
  Object.keys(condition).forEach((operator) => {
1228
1255
  if (operator === "$and" || operator === "$or") {
1229
- collectChartFilterOperatorErrors({ [operator]: condition[operator] }, fieldPath, errors);
1256
+ collectChartFilterOperatorErrors({ [operator]: condition[operator] }, fieldPath, errors, resolveField);
1230
1257
  return;
1231
1258
  }
1232
1259
  collectChartFilterOperatorError(operator, `${fieldPath}.${operator}`, errors);
1233
- collectChartFilterDateValueError(operator, condition[operator], `${fieldPath}.${operator}`, errors);
1260
+ collectChartFilterDateValueError(
1261
+ operator,
1262
+ condition[operator],
1263
+ `${fieldPath}.${operator}`,
1264
+ errors,
1265
+ (resolveField == null ? void 0 : resolveField(field)) || { fieldPath: field }
1266
+ );
1234
1267
  });
1235
1268
  });
1236
1269
  }
@@ -1245,9 +1278,18 @@ function collectChartFilterOperatorError(operator, path, errors) {
1245
1278
  throw error;
1246
1279
  }
1247
1280
  }
1248
- function collectChartFilterDateValueError(operator, value, path, errors) {
1281
+ function collectChartFilterDateValueError(operator, value, path, errors, fieldContext) {
1282
+ const fieldMeta = getDateConditionFieldContextMeta(fieldContext);
1283
+ const normalizedOperator = typeof operator === "string" ? operator.trim() : "";
1284
+ if (!import_filter_group.FLOW_SURFACE_DATE_FILTER_OPERATORS.has(normalizedOperator) && !(0, import_filter_group.isFlowSurfaceDateLikeFieldMeta)(fieldMeta)) {
1285
+ return;
1286
+ }
1249
1287
  try {
1250
- (0, import_filter_group.normalizeFlowSurfaceStrictFilterDateValue)(operator, value, path);
1288
+ (0, import_filter_group.normalizeFlowSurfaceDateConditionValue)(operator, value, path, {
1289
+ fieldPath: fieldContext == null ? void 0 : fieldContext.fieldPath,
1290
+ fieldType: fieldMeta.type,
1291
+ fieldInterface: fieldMeta.interface
1292
+ });
1251
1293
  } catch (error) {
1252
1294
  if (error instanceof import_errors.FlowSurfaceBadRequestError) {
1253
1295
  pushChartBadRequestAuthoringError(errors, error, path);
@@ -1256,6 +1298,38 @@ function collectChartFilterDateValueError(operator, value, path, errors) {
1256
1298
  throw error;
1257
1299
  }
1258
1300
  }
1301
+ function createChartQueryDateConditionFieldResolver(query, context) {
1302
+ const resource = _.isPlainObject(query == null ? void 0 : query.resource) ? query.resource : null;
1303
+ const collectionName = String((resource == null ? void 0 : resource.collectionName) || "").trim();
1304
+ if (!collectionName || typeof (context == null ? void 0 : context.getCollection) !== "function") {
1305
+ return null;
1306
+ }
1307
+ const dataSourceKey = String((resource == null ? void 0 : resource.dataSourceKey) || "main").trim() || "main";
1308
+ const collection = context.getCollection(dataSourceKey, collectionName);
1309
+ if (!collection) {
1310
+ return null;
1311
+ }
1312
+ return (fieldPath) => {
1313
+ const normalizedFieldPath = (0, import_service_helpers.normalizeFieldPath)(fieldPath);
1314
+ const resolved = resolveDefaultFilterFieldPath(collection, normalizedFieldPath, dataSourceKey, context);
1315
+ return {
1316
+ fieldPath,
1317
+ field: resolved.field
1318
+ };
1319
+ };
1320
+ }
1321
+ function getDateConditionFieldMeta(field) {
1322
+ return {
1323
+ type: (0, import_service_helpers.getFieldType)(field),
1324
+ interface: (0, import_service_helpers.getFieldInterface)(field)
1325
+ };
1326
+ }
1327
+ function getDateConditionFieldContextMeta(fieldContext) {
1328
+ return {
1329
+ ...getDateConditionFieldMeta(fieldContext == null ? void 0 : fieldContext.field),
1330
+ ...(fieldContext == null ? void 0 : fieldContext.fieldMeta) || {}
1331
+ };
1332
+ }
1259
1333
  function normalizeChartAssetFieldPath(input) {
1260
1334
  if (Array.isArray(input)) {
1261
1335
  return input.map((item) => String(item || "").trim()).filter(Boolean).join(".");
@@ -3616,6 +3690,9 @@ function getGeneratedPopupBusinessFieldCandidates(collection) {
3616
3690
  if (!fieldName || !(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupBusinessField)(field)) {
3617
3691
  return [];
3618
3692
  }
3693
+ if ((0, import_relation_backing_foreign_key.isRelationBackingForeignKeyField)(collection, field)) {
3694
+ return [];
3695
+ }
3619
3696
  return [
3620
3697
  {
3621
3698
  field,
@@ -3730,11 +3807,15 @@ function getGeneratedPopupDefaultFormFieldPaths(candidates, fieldGroups) {
3730
3807
  }
3731
3808
  function getGeneratedPopupRuntimeFieldCandidates(input) {
3732
3809
  const candidateContext = DEFAULT_ACTION_POPUP_FIELD_CONTEXT_BY_TYPE[input.actionType];
3810
+ const explicitDefaultFieldPaths = (0, import_default_action_popup.collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths)(input.fieldGroups);
3733
3811
  return (0, import_service_helpers.getCollectionFields)(input.collection).flatMap((field) => {
3734
3812
  const fieldName = (0, import_service_helpers.getFieldName)(field);
3735
3813
  if (!fieldName || !(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupBusinessField)(field)) {
3736
3814
  return [];
3737
3815
  }
3816
+ if ((0, import_relation_backing_foreign_key.isRelationBackingForeignKeyField)(input.collection, field) && !explicitDefaultFieldPaths.has(fieldName)) {
3817
+ return [];
3818
+ }
3738
3819
  const fieldInterface = (0, import_service_helpers.getFieldInterface)(field);
3739
3820
  const registeredBinding = (0, import_field_binding_registry.resolveRegisteredFieldBinding)({
3740
3821
  containerUse: candidateContext.ownerUse,
@@ -3958,9 +4039,16 @@ function collectBlockErrors(block, path, errors, localKeys, context) {
3958
4039
  collectChartDisplayTitleErrors(block, blockType, path, errors);
3959
4040
  collectTreeTableExplicitFieldsErrors(block, blockType, path, errors, context);
3960
4041
  collectTreeConnectFieldsErrors((_a = block.settings) == null ? void 0 : _a.connectFields, `${path}.settings.connectFields`, errors);
3961
- collectTableSettingsErrors(block, blockType, path, errors, {
3962
- deferPublicDataScopeErrors: context.authoringActionName === "addBlocks"
3963
- });
4042
+ collectTableSettingsErrors(
4043
+ block,
4044
+ blockType,
4045
+ path,
4046
+ errors,
4047
+ {
4048
+ deferPublicDataScopeErrors: context.authoringActionName === "addBlocks"
4049
+ },
4050
+ context
4051
+ );
3964
4052
  collectGridCardSettingsErrors(block, blockType, path, errors);
3965
4053
  const descendantContext = getBlockDescendantValidationContext(block, context);
3966
4054
  collectActionListErrors(block.actions, `${path}.actions`, errors, block, descendantContext, "actions");
@@ -4268,8 +4356,8 @@ async function collectConfigureErrors(values, errors, context) {
4268
4356
  collectCommentsBlockErrors(changesBlock, hostBlockType, "$.changes", errors, context);
4269
4357
  collectRecordHistoryBlockErrors(changesBlock, hostBlockType, "$.changes", errors, context);
4270
4358
  collectChartDisplayTitleErrors(changes, hostBlockType, "$.changes", errors);
4271
- collectChartConfigureFilterOperatorErrors(changes, hostBlockType, "$.changes", errors);
4272
- collectTableSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true });
4359
+ collectChartConfigureFilterOperatorErrors(changes, hostBlockType, "$.changes", errors, context);
4360
+ collectTableSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true }, context);
4273
4361
  collectGridCardSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true });
4274
4362
  collectAssignValuesErrors(changes.assignValues, "$.changes.assignValues", errors, changesBlock, context);
4275
4363
  collectTriggerWorkflowsErrors(changes.triggerWorkflows, "$.changes.triggerWorkflows", errors);
@@ -4357,10 +4445,20 @@ function collectUnsupportedDefaultFilterOperatorError(operator, path, errors) {
4357
4445
  }
4358
4446
  });
4359
4447
  }
4360
- function collectDefaultFilterDateValueError(operator, value, path, errors) {
4448
+ function collectDefaultFilterDateValueError(operator, value, path, errors, fieldContext, options = {}) {
4361
4449
  var _a, _b, _c;
4450
+ const fieldMeta = getDateConditionFieldContextMeta(fieldContext);
4451
+ const normalizedOperator = typeof operator === "string" ? operator.trim() : "";
4452
+ if (!import_filter_group.FLOW_SURFACE_DATE_FILTER_OPERATORS.has(normalizedOperator) && !(0, import_filter_group.isFlowSurfaceDateLikeFieldMeta)(fieldMeta)) {
4453
+ return;
4454
+ }
4362
4455
  try {
4363
- (0, import_filter_group.normalizeFlowSurfaceStrictFilterDateValue)(operator, value, path);
4456
+ (0, import_filter_group.normalizeFlowSurfaceDateConditionValue)(operator, value, path, {
4457
+ fieldPath: fieldContext == null ? void 0 : fieldContext.fieldPath,
4458
+ fieldType: fieldMeta.type,
4459
+ fieldInterface: fieldMeta.interface,
4460
+ allowContextPathValue: options.allowContextPathValue
4461
+ });
4364
4462
  } catch (error) {
4365
4463
  if (!(error instanceof import_errors.FlowSurfaceBadRequestError)) {
4366
4464
  throw error;
@@ -5423,13 +5521,13 @@ function collectChartDisplayTitleErrors(block, blockType, blockPath, errors) {
5423
5521
  message: "Chart block settings do not support displayTitle in the current flowSurfaces runtime; keep settings.title and omit displayTitle."
5424
5522
  });
5425
5523
  }
5426
- function collectChartConfigureFilterOperatorErrors(changes, hostBlockType, path, errors) {
5524
+ function collectChartConfigureFilterOperatorErrors(changes, hostBlockType, path, errors, context) {
5427
5525
  if (hostBlockType !== "chart" || !_.isPlainObject(changes)) {
5428
5526
  return;
5429
5527
  }
5430
- collectChartQueryFilterOperatorErrors(changes.query, `${path}.query`, errors);
5528
+ collectChartQueryFilterOperatorErrors(changes.query, `${path}.query`, errors, context);
5431
5529
  if (_.isPlainObject(changes.configure)) {
5432
- collectChartQueryFilterOperatorErrors(changes.configure.query, `${path}.configure.query`, errors);
5530
+ collectChartQueryFilterOperatorErrors(changes.configure.query, `${path}.configure.query`, errors, context);
5433
5531
  }
5434
5532
  }
5435
5533
  function visitFilterItems(value, path, errors, block, context = {}) {
@@ -5446,7 +5544,13 @@ function visitFilterItems(value, path, errors, block, context = {}) {
5446
5544
  }
5447
5545
  if (typeof value.operator === "string") {
5448
5546
  collectUnsupportedDefaultFilterOperatorError(value.operator, `${path}.operator`, errors);
5449
- collectDefaultFilterDateValueError(value.operator, value.value, `${path}.value`, errors);
5547
+ collectDefaultFilterDateValueError(
5548
+ value.operator,
5549
+ value.value,
5550
+ `${path}.value`,
5551
+ errors,
5552
+ fieldRef ? resolveDefaultFilterDateConditionField(fieldRef.value, block, context) : void 0
5553
+ );
5450
5554
  }
5451
5555
  const filterItems = value.items;
5452
5556
  if (Array.isArray(filterItems)) {
@@ -5472,11 +5576,33 @@ function visitFilterItems(value, path, errors, block, context = {}) {
5472
5576
  if (_.isPlainObject(child)) {
5473
5577
  Object.entries(child).forEach(([operator, operatorValue]) => {
5474
5578
  collectUnsupportedDefaultFilterOperatorError(operator, `${path}.${key}.${operator}`, errors);
5475
- collectDefaultFilterDateValueError(operator, operatorValue, `${path}.${key}.${operator}`, errors);
5579
+ collectDefaultFilterDateValueError(
5580
+ operator,
5581
+ operatorValue,
5582
+ `${path}.${key}.${operator}`,
5583
+ errors,
5584
+ resolveDefaultFilterDateConditionField(key, block, context)
5585
+ );
5476
5586
  });
5477
5587
  }
5478
5588
  });
5479
5589
  }
5590
+ function resolveDefaultFilterDateConditionField(rawFieldPath, block, context) {
5591
+ const fieldPath = String(rawFieldPath || "").trim();
5592
+ if (!fieldPath || fieldPath.startsWith("$") || fieldPath.startsWith("{{")) {
5593
+ return null;
5594
+ }
5595
+ const collection = getBlockCollection(block, context);
5596
+ if (!collection) {
5597
+ return null;
5598
+ }
5599
+ const dataSourceKey = getBlockDataSourceKey(block, context);
5600
+ const resolved = resolveDefaultFilterFieldPath(collection, (0, import_service_helpers.normalizeFieldPath)(fieldPath), dataSourceKey, context);
5601
+ return {
5602
+ fieldPath,
5603
+ field: resolved.field
5604
+ };
5605
+ }
5480
5606
  function collectTreeConnectFieldsErrors(value, path, errors) {
5481
5607
  if (_.isUndefined(value)) {
5482
5608
  return [];
@@ -5825,7 +5951,7 @@ function getCollectionFilterTargetKey(collection) {
5825
5951
  function normalizeDataSourceKey(value) {
5826
5952
  return String(value || "main").trim() || "main";
5827
5953
  }
5828
- function collectTableSettingsErrors(block, blockType, blockPath, errors, options = {}) {
5954
+ function collectTableSettingsErrors(block, blockType, blockPath, errors, options = {}, context = {}) {
5829
5955
  if (blockType !== "table" || !_.isPlainObject(block)) {
5830
5956
  return;
5831
5957
  }
@@ -5836,6 +5962,9 @@ function collectTableSettingsErrors(block, blockType, blockPath, errors, options
5836
5962
  });
5837
5963
  const hasSettings = _.isPlainObject(block == null ? void 0 : block.settings);
5838
5964
  if (!hasSettings) {
5965
+ if (options.directSettings === true && !shouldDeferPublicDataScopeErrorsToBatchItem(blockPath, errors, options)) {
5966
+ collectPublicDataScopeErrors(block.dataScope, `${blockPath}.dataScope`, errors, block, context);
5967
+ }
5839
5968
  return;
5840
5969
  }
5841
5970
  const settings = block.settings;
@@ -5850,7 +5979,7 @@ function collectTableSettingsErrors(block, blockType, blockPath, errors, options
5850
5979
  pushTableSettingsUnsupportedError(errors, `${settingsPath}.${key}`, key);
5851
5980
  });
5852
5981
  if (!shouldDeferPublicDataScopeErrorsToBatchItem(blockPath, errors, options)) {
5853
- collectPublicDataScopeErrors(settings.dataScope, `${settingsPath}.dataScope`, errors);
5982
+ collectPublicDataScopeErrors(settings.dataScope, `${settingsPath}.dataScope`, errors, block, context);
5854
5983
  }
5855
5984
  }
5856
5985
  function pushTableSettingsUnsupportedError(errors, path, key) {
@@ -5865,7 +5994,7 @@ function pushTableSettingsUnsupportedError(errors, path, key) {
5865
5994
  }
5866
5995
  });
5867
5996
  }
5868
- function collectPublicDataScopeErrors(value, path, errors) {
5997
+ function collectPublicDataScopeErrors(value, path, errors, block, context) {
5869
5998
  if (_.isUndefined(value)) {
5870
5999
  return;
5871
6000
  }
@@ -5885,6 +6014,62 @@ function collectPublicDataScopeErrors(value, path, errors) {
5885
6014
  repairHint: 'Use settings.dataScope with logic/items, for example {"logic":"$and","items":[{"path":"status","operator":"$eq","value":"Active"}]}; do not use a field-name map.'
5886
6015
  }
5887
6016
  });
6017
+ return;
6018
+ }
6019
+ collectPublicDataScopeFieldPathErrors(validationValue, path, errors, block, context);
6020
+ collectFilterGroupDateConditionErrors(validationValue, path, errors, block, context);
6021
+ }
6022
+ function collectPublicDataScopeFieldPathErrors(value, path, errors, block, context) {
6023
+ if (!_.isPlainObject(value)) {
6024
+ return;
6025
+ }
6026
+ if (hasOwn(value, "operator")) {
6027
+ collectPublicDataScopeFieldPathError(value.path, `${path}.path`, block, context, errors);
6028
+ }
6029
+ if (Array.isArray(value.items)) {
6030
+ value.items.forEach(
6031
+ (item, index) => collectPublicDataScopeFieldPathErrors(item, `${path}.items[${index}]`, errors, block, context)
6032
+ );
6033
+ }
6034
+ }
6035
+ function collectPublicDataScopeFieldPathError(rawFieldPath, path, block, context, errors) {
6036
+ const fieldPath = String(rawFieldPath || "").trim();
6037
+ if (!fieldPath || fieldPath.startsWith("$") || fieldPath.startsWith("{{")) {
6038
+ return;
6039
+ }
6040
+ const collection = getBlockCollection(block, context);
6041
+ if (!collection) {
6042
+ return;
6043
+ }
6044
+ const resolved = resolveDefaultFilterFieldPath(
6045
+ collection,
6046
+ (0, import_service_helpers.normalizeFieldPath)(fieldPath),
6047
+ getBlockDataSourceKey(block, context),
6048
+ context
6049
+ );
6050
+ if (!resolved.field) {
6051
+ pushAuthoringError(errors, {
6052
+ path,
6053
+ ruleId: "field-path-unknown",
6054
+ message: `flowSurfaces authoring ${path} references unknown field '${fieldPath}'`,
6055
+ details: {
6056
+ fieldPath,
6057
+ collection: (0, import_service_helpers.getCollectionName)(resolved.collection || collection),
6058
+ availableFields: (0, import_service_helpers.getCollectionFields)(resolved.collection || collection).map((field) => String((0, import_service_helpers.getFieldName)(field) || "").trim()).filter(Boolean)
6059
+ }
6060
+ });
6061
+ return;
6062
+ }
6063
+ if ((0, import_service_helpers.isAssociationField)(resolved.field)) {
6064
+ pushAuthoringError(errors, {
6065
+ path,
6066
+ ruleId: "defaultFilter-relation-field-unsupported",
6067
+ message: `flowSurfaces authoring ${path} cannot use relation field '${fieldPath}' itself; use a scalar subfield instead`,
6068
+ details: {
6069
+ fieldPath,
6070
+ fieldName: (0, import_service_helpers.getFieldName)(resolved.field)
6071
+ }
6072
+ });
5888
6073
  }
5889
6074
  }
5890
6075
  function shouldDeferPublicDataScopeErrorsToBatchItem(blockPath, errors, options) {
@@ -5906,6 +6091,28 @@ function normalizePublicDataScopeValueForValidation(value) {
5906
6091
  }
5907
6092
  return value;
5908
6093
  }
6094
+ function collectFilterGroupDateConditionErrors(value, path, errors, block, context) {
6095
+ if (!_.isPlainObject(value)) {
6096
+ return;
6097
+ }
6098
+ if (Array.isArray(value.items)) {
6099
+ value.items.forEach(
6100
+ (item, index) => collectFilterGroupDateConditionErrors(item, `${path}.items[${index}]`, errors, block, context)
6101
+ );
6102
+ return;
6103
+ }
6104
+ if (!hasOwn(value, "operator")) {
6105
+ return;
6106
+ }
6107
+ const fieldPath = String(value.path || value.field || "").trim();
6108
+ collectDefaultFilterDateValueError(
6109
+ value.operator,
6110
+ value.value,
6111
+ `${path}.value`,
6112
+ errors,
6113
+ fieldPath ? resolveDefaultFilterDateConditionField(fieldPath, block, context) : void 0
6114
+ );
6115
+ }
5909
6116
  function collectGridCardSettingsErrors(block, blockType, blockPath, errors, options = {}) {
5910
6117
  const hasSettings = _.isPlainObject(block == null ? void 0 : block.settings);
5911
6118
  if (!hasSettings && options.directSettings !== true) {
@@ -6033,11 +6240,12 @@ function buildAuthoringAIEmployeeActionIdentity(settings) {
6033
6240
  return stableSerializeAuthoringValue(normalizeAuthoringAIEmployeePublicSettingsForIdentity(settings));
6034
6241
  }
6035
6242
  function normalizeAuthoringAIEmployeePublicSettingsForIdentity(settings) {
6243
+ const workContext = Object.prototype.hasOwnProperty.call(settings, "workContext") ? normalizeAuthoringAIEmployeeWorkContextForIdentity(settings.workContext) : [{ type: "flow-model", target: "self" }];
6036
6244
  return {
6037
6245
  username: String(settings.username || "").trim(),
6038
6246
  auto: typeof settings.auto === "boolean" ? settings.auto : false,
6039
- workContext: Object.prototype.hasOwnProperty.call(settings, "workContext") ? normalizeAuthoringAIEmployeeWorkContextForIdentity(settings.workContext) : [{ type: "flow-model", target: "self" }],
6040
- tasks: normalizeAuthoringAIEmployeeTasksForIdentity(settings.tasks),
6247
+ workContext,
6248
+ tasks: normalizeAuthoringAIEmployeeTasksForIdentity(settings.tasks, workContext),
6041
6249
  style: {
6042
6250
  ...AUTHORING_AI_EMPLOYEE_DEFAULT_STYLE,
6043
6251
  ..._.isPlainObject(settings.style) ? _.pick(settings.style, AUTHORING_AI_EMPLOYEE_STYLE_PUBLIC_KEYS) : {}
@@ -6056,7 +6264,14 @@ function normalizeAuthoringAIEmployeeWorkContextForIdentity(value) {
6056
6264
  return output;
6057
6265
  });
6058
6266
  }
6059
- function normalizeAuthoringAIEmployeeTasksForIdentity(value) {
6267
+ function normalizeAuthoringAIEmployeeTaskWorkContextForIdentity(value, defaultWorkContext) {
6268
+ const normalized = normalizeAuthoringAIEmployeeWorkContextForIdentity(value);
6269
+ if (Array.isArray(defaultWorkContext) && !normalized.length) {
6270
+ return _.cloneDeep(defaultWorkContext);
6271
+ }
6272
+ return normalized;
6273
+ }
6274
+ function normalizeAuthoringAIEmployeeTasksForIdentity(value, defaultWorkContext) {
6060
6275
  return _.castArray(value || []).map((task) => {
6061
6276
  if (!_.isPlainObject(task)) {
6062
6277
  return task;
@@ -6064,10 +6279,11 @@ function normalizeAuthoringAIEmployeeTasksForIdentity(value) {
6064
6279
  const output = _.pick(task, AUTHORING_AI_EMPLOYEE_TASK_PUBLIC_SETTING_KEYS);
6065
6280
  if (_.isPlainObject(output.message)) {
6066
6281
  output.message = _.pick(output.message, AUTHORING_AI_EMPLOYEE_TASK_MESSAGE_PUBLIC_KEYS);
6067
- if (_.isPlainObject(output.message.workContext)) {
6068
- output.message.workContext = normalizeAuthoringAIEmployeeWorkContextForIdentity(output.message.workContext);
6069
- } else if (Array.isArray(output.message.workContext)) {
6070
- output.message.workContext = normalizeAuthoringAIEmployeeWorkContextForIdentity(output.message.workContext);
6282
+ if (Object.prototype.hasOwnProperty.call(output.message, "workContext")) {
6283
+ output.message.workContext = normalizeAuthoringAIEmployeeTaskWorkContextForIdentity(
6284
+ output.message.workContext,
6285
+ defaultWorkContext
6286
+ );
6071
6287
  }
6072
6288
  }
6073
6289
  if (Object.prototype.hasOwnProperty.call(task, "prompt") && !Object.prototype.hasOwnProperty.call(output.message || {}, "user")) {
@@ -6076,6 +6292,13 @@ function normalizeAuthoringAIEmployeeTasksForIdentity(value) {
6076
6292
  user: task.prompt
6077
6293
  };
6078
6294
  }
6295
+ if (!_.isPlainObject(output.message) && Array.isArray(defaultWorkContext)) {
6296
+ output.message = {
6297
+ workContext: _.cloneDeep(defaultWorkContext)
6298
+ };
6299
+ } else if (_.isPlainObject(output.message) && !Object.prototype.hasOwnProperty.call(output.message, "workContext")) {
6300
+ output.message.workContext = _.cloneDeep(defaultWorkContext || []);
6301
+ }
6079
6302
  if (_.isPlainObject(output.model)) {
6080
6303
  output.model = _.pick(output.model, AUTHORING_AI_EMPLOYEE_TASK_MODEL_PUBLIC_KEYS);
6081
6304
  }
@@ -6516,7 +6739,7 @@ function collectNestedBlockErrors(blocks, path, errors, localKeys, context) {
6516
6739
  }
6517
6740
  blocks.forEach((block, index) => collectBlockErrors(block, `${path}[${index}]`, errors, localKeys, context));
6518
6741
  }
6519
- function collectReactionErrors(reaction, path, localKeys, errors) {
6742
+ function collectReactionErrors(reaction, path, localKeys, errors, options = {}) {
6520
6743
  const items = Array.isArray(reaction == null ? void 0 : reaction.items) ? reaction.items : [];
6521
6744
  items.forEach((item, index) => {
6522
6745
  const rawTarget = (item == null ? void 0 : item.target) ?? (item == null ? void 0 : item.targetKey) ?? (item == null ? void 0 : item.targetBlock);
@@ -6534,8 +6757,198 @@ function collectReactionErrors(reaction, path, localKeys, errors) {
6534
6757
  message: `flowSurfaces authoring ${path}.items[${index}].target references unknown local target '${target}'`
6535
6758
  });
6536
6759
  }
6760
+ collectReactionItemDateConditionErrors(item, `${path}.items[${index}]`, target, errors, options);
6537
6761
  });
6538
6762
  }
6763
+ function collectReactionItemDateConditionErrors(item, path, target, errors, options) {
6764
+ if (!_.isPlainObject(item) || !_.isPlainObject(options.values) || !options.context) {
6765
+ return;
6766
+ }
6767
+ const targetMatch = findApplyBlueprintReactionTargetBlock(options.values, target, options.context);
6768
+ if (!targetMatch) {
6769
+ return;
6770
+ }
6771
+ const type = String(item.type || "").trim();
6772
+ const conditionFieldMetaByPath = buildApplyBlueprintReactionConditionFieldMetaByPath(
6773
+ targetMatch.block,
6774
+ targetMatch.context
6775
+ );
6776
+ _.castArray(item.rules || []).forEach((rule, ruleIndex) => {
6777
+ collectReactionFilterDateConditionErrors(
6778
+ (rule == null ? void 0 : rule.when) ?? (rule == null ? void 0 : rule.condition),
6779
+ `${path}.rules[${ruleIndex}].when`,
6780
+ errors,
6781
+ targetMatch.block,
6782
+ targetMatch.context,
6783
+ conditionFieldMetaByPath
6784
+ );
6785
+ if (type !== "setFieldLinkageRules") {
6786
+ return;
6787
+ }
6788
+ _.castArray((rule == null ? void 0 : rule.then) || (rule == null ? void 0 : rule.actions) || []).forEach((action, actionIndex) => {
6789
+ _.castArray((action == null ? void 0 : action.items) || []).forEach((assignItem, itemIndex) => {
6790
+ collectReactionFilterDateConditionErrors(
6791
+ (assignItem == null ? void 0 : assignItem.when) ?? (assignItem == null ? void 0 : assignItem.condition),
6792
+ `${path}.rules[${ruleIndex}].then[${actionIndex}].items[${itemIndex}].when`,
6793
+ errors,
6794
+ targetMatch.block,
6795
+ targetMatch.context,
6796
+ conditionFieldMetaByPath
6797
+ );
6798
+ });
6799
+ });
6800
+ });
6801
+ }
6802
+ function collectReactionFilterDateConditionErrors(filter, path, errors, block, context, fieldMetaByPath = {}) {
6803
+ if (!_.isPlainObject(filter)) {
6804
+ return;
6805
+ }
6806
+ if (Array.isArray(filter.items)) {
6807
+ filter.items.forEach(
6808
+ (item, index) => collectReactionFilterDateConditionErrors(
6809
+ item,
6810
+ `${path}.items[${index}]`,
6811
+ errors,
6812
+ block,
6813
+ context,
6814
+ fieldMetaByPath
6815
+ )
6816
+ );
6817
+ return;
6818
+ }
6819
+ if (!hasOwn(filter, "operator")) {
6820
+ return;
6821
+ }
6822
+ const conditionPath = normalizeReactionConditionPath(filter.path);
6823
+ const fieldContext = resolveReactionConditionFieldContext(conditionPath, block, context, fieldMetaByPath);
6824
+ collectDefaultFilterDateValueError(filter.operator, filter.value, `${path}.value`, errors, fieldContext, {
6825
+ allowContextPathValue: true
6826
+ });
6827
+ }
6828
+ function normalizeReactionConditionPath(rawPath) {
6829
+ const value = String(rawPath || "").trim();
6830
+ const templateMatch = /^\{\{\s*ctx(?:\.([^}]+?))?\s*\}\}$/.exec(value);
6831
+ const path = templateMatch ? String(templateMatch[1] || "").trim() : value.replace(/^ctx\./, "");
6832
+ return path.split(".").map((segment) => segment.trim()).filter(Boolean).join(".");
6833
+ }
6834
+ function buildApplyBlueprintReactionConditionFieldMetaByPath(block, context) {
6835
+ var _a, _b;
6836
+ const collection = getBlockCollection(block, context);
6837
+ const dataSourceKey = getBlockDataSourceKey(block, context);
6838
+ const userCollection = ((_a = context.getCollection) == null ? void 0 : _a.call(context, "main", "users")) || ((_b = context.getCollection) == null ? void 0 : _b.call(context, dataSourceKey, "users")) || null;
6839
+ const response = (0, import_context.buildFlowSurfaceContextResponse)({
6840
+ semantic: {
6841
+ collection,
6842
+ userCollection,
6843
+ recordCollection: collection,
6844
+ formValuesCollection: collection,
6845
+ itemCollections: collection ? [collection] : [],
6846
+ itemRootCollection: collection || void 0,
6847
+ popupLevels: context.isPopupSurface || context.popupHasCurrentRecord ? [
6848
+ {
6849
+ recordCollection: collection,
6850
+ sourceRecordCollection: collection
6851
+ }
6852
+ ] : []
6853
+ },
6854
+ maxDepth: 4
6855
+ });
6856
+ const fieldMetaByPath = collectAuthorableReactionContextFieldMetaByPath(response);
6857
+ addCollectionFieldMetaAliases(fieldMetaByPath, collection, ["collection", "record", "formValues"]);
6858
+ addCollectionFieldMetaAliases(fieldMetaByPath, collection, ["item"], {
6859
+ preserveExisting: true,
6860
+ reservedKeys: /* @__PURE__ */ new Set(["index", "length", "value", "parentItem"])
6861
+ });
6862
+ if (userCollection) {
6863
+ addCollectionFieldMetaAliases(fieldMetaByPath, userCollection, ["user"]);
6864
+ }
6865
+ return fieldMetaByPath;
6866
+ }
6867
+ function collectAuthorableReactionContextFieldMetaByPath(context) {
6868
+ const fieldMetaByPath = {};
6869
+ const visit = (prefix, info) => {
6870
+ if (!prefix || !info) {
6871
+ return;
6872
+ }
6873
+ if (isAuthorableReactionContextPath(prefix)) {
6874
+ fieldMetaByPath[prefix] = {
6875
+ ...info.type ? { type: info.type } : {},
6876
+ ...info.interface ? { interface: info.interface } : {}
6877
+ };
6878
+ }
6879
+ if (info.dynamicProperties) {
6880
+ visit(`${prefix}.*`, info.dynamicProperties);
6881
+ }
6882
+ Object.entries(info.properties || {}).forEach(([key, child]) => visit(`${prefix}.${key}`, child));
6883
+ };
6884
+ Object.entries((context == null ? void 0 : context.vars) || {}).forEach(([key, info]) => visit(key, info));
6885
+ return fieldMetaByPath;
6886
+ }
6887
+ function isAuthorableReactionContextPath(path) {
6888
+ const segments = String(path || "").split(".").filter(Boolean);
6889
+ const root = segments[0];
6890
+ if (!root) {
6891
+ return false;
6892
+ }
6893
+ if (AUTHORABLE_REACTION_SCALAR_CONTEXT_PATHS.has(root)) {
6894
+ return segments.length === 1;
6895
+ }
6896
+ return AUTHORABLE_REACTION_CONTEXT_ROOTS.has(root);
6897
+ }
6898
+ function addCollectionFieldMetaAliases(fieldMetaByPath, collection, roots, options = {}) {
6899
+ var _a;
6900
+ for (const field of (0, import_service_helpers.getCollectionFields)(collection)) {
6901
+ const fieldName = (0, import_service_helpers.getFieldName)(field);
6902
+ if (!fieldName) {
6903
+ continue;
6904
+ }
6905
+ const fieldMeta = {
6906
+ ...(0, import_service_helpers.getFieldType)(field) ? { type: (0, import_service_helpers.getFieldType)(field) } : {},
6907
+ ...(0, import_service_helpers.getFieldInterface)(field) ? { interface: (0, import_service_helpers.getFieldInterface)(field) } : {}
6908
+ };
6909
+ for (const root of roots) {
6910
+ if ((_a = options.reservedKeys) == null ? void 0 : _a.has(fieldName)) {
6911
+ continue;
6912
+ }
6913
+ const aliasPath = `${root}.${fieldName}`;
6914
+ if (options.preserveExisting && fieldMetaByPath[aliasPath]) {
6915
+ continue;
6916
+ }
6917
+ fieldMetaByPath[aliasPath] = {
6918
+ ...fieldMetaByPath[aliasPath],
6919
+ ...fieldMeta
6920
+ };
6921
+ }
6922
+ }
6923
+ }
6924
+ function resolveReactionConditionFieldContext(path, block, context, fieldMetaByPath) {
6925
+ const normalized = String(path || "").trim();
6926
+ const contextMeta = resolveReactionConditionFieldMeta(normalized, fieldMetaByPath);
6927
+ if (contextMeta) {
6928
+ return {
6929
+ fieldPath: normalized,
6930
+ fieldMeta: contextMeta
6931
+ };
6932
+ }
6933
+ const fieldPath = resolveReactionConditionFieldPath(normalized);
6934
+ return fieldPath ? resolveDefaultFilterDateConditionField(fieldPath, block, context) || void 0 : void 0;
6935
+ }
6936
+ function resolveReactionConditionFieldMeta(path, fieldMetaByPath) {
6937
+ if (fieldMetaByPath[path]) {
6938
+ return fieldMetaByPath[path];
6939
+ }
6940
+ const wildcardPath = Object.keys(fieldMetaByPath).filter((candidate) => candidate.endsWith(".*")).sort((a, b) => b.length - a.length).find((candidate) => {
6941
+ const prefix = candidate.slice(0, -2);
6942
+ return path.startsWith(`${prefix}.`) && path.length > prefix.length + 1;
6943
+ });
6944
+ return wildcardPath ? fieldMetaByPath[wildcardPath] : void 0;
6945
+ }
6946
+ function resolveReactionConditionFieldPath(path) {
6947
+ const normalized = String(path || "").trim();
6948
+ const prefixes = ["formValues.", "record.", "item.value.", "item.", "popup.record.", "collection.", "user."];
6949
+ const prefix = prefixes.find((candidate) => normalized.startsWith(candidate));
6950
+ return prefix ? normalized.slice(prefix.length) : "";
6951
+ }
6539
6952
  function collectFieldListErrors(fields, path, errors, localKeys, context, block) {
6540
6953
  if (!Array.isArray(fields)) {
6541
6954
  return;