@opencrvs/toolkit 2.2.0-rc.3af310b → 2.2.0-rc.5bf5dfc

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 (82) hide show
  1. package/build.sh +7 -2
  2. package/dist/application-config/index.js +9 -9
  3. package/dist/authentication/index.d.ts +2 -1
  4. package/dist/authentication/index.js +20 -12
  5. package/dist/cli.js +633 -333
  6. package/dist/commons/api/router.d.ts +249 -249
  7. package/dist/commons/application-config/index.d.ts +2 -2
  8. package/dist/commons/conditionals/conditionals.d.ts +4 -4
  9. package/dist/commons/conditionals/index.d.ts +1 -0
  10. package/dist/commons/conditionals/validate.d.ts +6 -1
  11. package/dist/commons/events/ActionConfig.d.ts +2 -2
  12. package/dist/commons/events/ActionDocument.d.ts +1 -0
  13. package/dist/commons/events/ActionInput.d.ts +4 -4
  14. package/dist/commons/events/ActionStatus.d.ts +2 -2
  15. package/dist/commons/events/ActionType.d.ts +2 -0
  16. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
  17. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  18. package/dist/commons/events/Draft.d.ts +34 -1
  19. package/dist/commons/events/EventConfig.d.ts +1 -10
  20. package/dist/commons/events/EventIndex.d.ts +2 -2
  21. package/dist/commons/events/FieldConfig.d.ts +1 -1
  22. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  23. package/dist/commons/events/Flag.d.ts +1 -1
  24. package/dist/commons/events/PlainDate.d.ts +1 -0
  25. package/dist/commons/events/eventConfigValidation.d.ts +1 -1
  26. package/dist/commons/events/field.d.ts +5 -0
  27. package/dist/commons/events/index.d.ts +3 -0
  28. package/dist/commons/events/locations.d.ts +1 -1
  29. package/dist/commons/events/scopes.d.ts +2 -1
  30. package/dist/commons/events/test.utils.d.ts +5 -6
  31. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  32. package/dist/commons/events/utils.d.ts +26 -5
  33. package/dist/commons/users/Role.d.ts +23 -0
  34. package/dist/commons/users/User.d.ts +263 -0
  35. package/dist/commons/users/authentication.d.ts +67 -0
  36. package/dist/commons/users/index.d.ts +5 -0
  37. package/dist/commons/users/roleValidations.d.ts +15 -0
  38. package/dist/commons/users/scopes.d.ts +1402 -0
  39. package/dist/commons/users/userReferences.d.ts +176 -0
  40. package/dist/conditionals/index.js +5 -5
  41. package/dist/environment/custom-types.d.ts +1 -0
  42. package/dist/environment/custom-types.d.ts.map +1 -1
  43. package/dist/environment/derived-variables.d.ts +6 -4
  44. package/dist/environment/derived-variables.d.ts.map +1 -1
  45. package/dist/environment/derived-variables.js +6 -4
  46. package/dist/environment/questions.d.ts +42 -9
  47. package/dist/environment/questions.d.ts.map +1 -1
  48. package/dist/environment/questions.js +70 -47
  49. package/dist/environment/registry.d.ts +15 -0
  50. package/dist/environment/registry.d.ts.map +1 -0
  51. package/dist/environment/registry.js +112 -0
  52. package/dist/environment/setup-environment.d.ts.map +1 -1
  53. package/dist/environment/setup-environment.js +85 -29
  54. package/dist/events/index.js +214 -152
  55. package/dist/migrations/add-notify-config.d.ts +40 -0
  56. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  57. package/dist/migrations/add-notify-config.js +249 -0
  58. package/dist/migrations/index.d.ts.map +1 -1
  59. package/dist/migrations/index.js +345 -143
  60. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  61. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  62. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  63. package/dist/migrations/read-declaration-through-helper.js +3 -61
  64. package/dist/migrations/utils.d.ts +61 -0
  65. package/dist/migrations/utils.d.ts.map +1 -0
  66. package/dist/migrations/utils.js +218 -0
  67. package/dist/notification/index.js +282 -90
  68. package/dist/roles/index.d.ts +2 -0
  69. package/dist/roles/index.d.ts.map +1 -0
  70. package/dist/roles/index.js +719 -0
  71. package/dist/scopes/index.d.ts +54 -61
  72. package/dist/scopes/index.js +15 -11
  73. package/dist/templates/charts-values/opencrvs-services/values.yaml +3 -4
  74. package/opencrvs-toolkit-2.2.0-rc.5bf5dfc.tgz +0 -0
  75. package/package.json +5 -3
  76. package/tsconfig.build.tsbuildinfo +1 -1
  77. package/tsconfig.json +3 -5
  78. package/dist/commons/events/notificationFormFallback.d.ts +0 -10
  79. package/dist/environment/dockerhub.d.ts +0 -15
  80. package/dist/environment/dockerhub.d.ts.map +0 -1
  81. package/dist/environment/dockerhub.js +0 -104
  82. package/opencrvs-toolkit-2.2.0-rc.3af310b.tgz +0 -0
@@ -40,14 +40,17 @@ __export(notification_exports, {
40
40
  module.exports = __toCommonJS(notification_exports);
41
41
  var z48 = __toESM(require("zod/v4"));
42
42
 
43
+ // ../commons/src/events/index.ts
44
+ var import_compile = require("zod/compile");
45
+
43
46
  // ../commons/src/events/AuditLog.ts
44
47
  var z9 = __toESM(require("zod/v4"));
45
48
 
46
- // ../commons/src/authentication.ts
49
+ // ../commons/src/users/authentication.ts
47
50
  var import_jwt_decode = __toESM(require("jwt-decode"));
48
51
  var z8 = __toESM(require("zod/v4"));
49
52
 
50
- // ../commons/src/scopes.ts
53
+ // ../commons/src/users/scopes.ts
51
54
  var z7 = __toESM(require("zod/v4"));
52
55
  var qs = __toESM(require("qs"));
53
56
 
@@ -133,7 +136,9 @@ var ActionTypes = z2.enum([
133
136
  "CUSTOM"
134
137
  ]);
135
138
  var ClientSpecificAction = {
136
- REVIEW_CORRECTION_REQUEST: "REVIEW_CORRECTION_REQUEST"
139
+ REVIEW_CORRECTION_REQUEST: "REVIEW_CORRECTION_REQUEST",
140
+ /** Opens the user's declare or notify draft of the event in its own flow */
141
+ CONTINUE_DRAFT: "CONTINUE_DRAFT"
137
142
  };
138
143
  var declarationActionValues = [
139
144
  ActionTypes.enum.DECLARE,
@@ -186,7 +191,7 @@ var ActionStatus = {
186
191
  };
187
192
 
188
193
  // ../commons/src/events/Flag.ts
189
- var z5 = __toESM(require("zod/v4"));
194
+ var z5 = __toESM(require("zod"));
190
195
 
191
196
  // ../commons/src/events/TranslationConfig.ts
192
197
  var z3 = __toESM(require("zod/v4"));
@@ -282,7 +287,7 @@ var CustomFlag = z5.string().refine((val) => !Object.values(InherentFlags).inclu
282
287
  message: `Custom flag cannot be one of the inherent flags: ${Object.values(
283
288
  InherentFlags
284
289
  ).join(", ")}`
285
- }).refine((val) => !ActionFlag.safeParse(val).success, {
290
+ }).refine((val) => !ActionFlag.validate(val), {
286
291
  message: "Custom flag cannot match the ActionFlag pattern (ActionType:ActionStatus)."
287
292
  }).describe("Custom flag identifier defined by the country config.");
288
293
  var Flag = ActionFlag.or(z5.enum(InherentFlags)).or(CustomFlag);
@@ -325,7 +330,7 @@ var EventStatus = z6.enum([
325
330
  "ARCHIVED"
326
331
  ]);
327
332
 
328
- // ../commons/src/scopes.ts
333
+ // ../commons/src/users/scopes.ts
329
334
  var JurisdictionFilter = z7.enum(["administrativeArea", "location", "all"]).describe(
330
335
  "Filters based on user jurisdiction relative to their office location in hierarchy."
331
336
  );
@@ -598,7 +603,7 @@ var DEFAULT_SCOPE_OPTIONS = {
598
603
  registeredIn: JurisdictionFilter.enum.all
599
604
  };
600
605
 
601
- // ../commons/src/authentication.ts
606
+ // ../commons/src/users/authentication.ts
602
607
  var TokenUserType = z8.enum(["user", "system"]);
603
608
  var TokenWithBearer = z8.string().regex(/^Bearer\s/);
604
609
 
@@ -996,7 +1001,7 @@ var z14 = __toESM(require("zod/v4"));
996
1001
  // ../commons/src/documents.ts
997
1002
  var z11 = __toESM(require("zod/v4"));
998
1003
  var FullDocumentUrl = z11.string().brand("FullDocumentUrl").describe(
999
- "A full url with protocol, host, bucket name, starting from the root of the S3 server, https://minio.opencrvs.com/bucket-name/document-id.jpg"
1004
+ "A full url with protocol, host, bucket name, starting from the root of the S3 server, https://s3.opencrvs.com/bucket-name/document-id.jpg"
1000
1005
  );
1001
1006
  var FullDocumentPath = z11.string().overwrite((val) => val.startsWith("/") ? val : `/${val}`).meta({ effectType: "input", type: "string" }).describe(
1002
1007
  "A full absolute path with bucket name, starting from the root of the S3 server, /bucket-name/document-id.jpg"
@@ -1006,7 +1011,7 @@ var DocumentPath = z11.string().brand("DocumentPath").describe(
1006
1011
  );
1007
1012
 
1008
1013
  // ../commons/src/events/CompositeFieldValue.ts
1009
- var z12 = __toESM(require("zod/v4"));
1014
+ var z12 = __toESM(require("zod"));
1010
1015
  var AddressType = {
1011
1016
  DOMESTIC: "DOMESTIC",
1012
1017
  INTERNATIONAL: "INTERNATIONAL"
@@ -1211,7 +1216,7 @@ function safeUnion(schemas) {
1211
1216
  );
1212
1217
  return z14.any().superRefine((val, ctx) => {
1213
1218
  for (const schema of sortedSchemas) {
1214
- if (schema.safeParse(val).success) {
1219
+ if (schema.validate(val)) {
1215
1220
  return;
1216
1221
  }
1217
1222
  }
@@ -2907,11 +2912,11 @@ var ReadActionConfig = ActionConfigBase.extend(
2907
2912
  var NotifyConfig = ActionConfigBase.extend(
2908
2913
  z25.object({
2909
2914
  type: z25.literal(ActionType.NOTIFY),
2910
- notificationForm: DeclarationFormConfig.optional().describe(
2911
- "Notification form configuration. Its fields must be a subset of the declaration form fields, with matching types. The values submitted on the notification form pre-fill the declaration. If not defined, the declare action's declaration is used (with all fields optional)."
2915
+ notificationForm: DeclarationFormConfig.describe(
2916
+ "Notification form configuration. Its fields must be a subset of the declaration form fields, with matching types. The values submitted on the notification form pre-fill the declaration."
2912
2917
  ),
2913
2918
  review: DeclarationReviewConfig.describe(
2914
- "Review page configuration for the notify action. Values of its fields are stored as the NOTIFY action annotation. If not defined, defineConfig generates it from the declare action's review (with all fields optional)."
2919
+ "Review page configuration for the notify action. Values of its fields are stored as the NOTIFY action annotation."
2915
2920
  ),
2916
2921
  form: actionConfirmationForm
2917
2922
  }).shape
@@ -3457,7 +3462,10 @@ var SearchQueryParams = z30.object({
3457
3462
  }).catchall(FieldValue);
3458
3463
  var FieldConfigSchema = BaseField3.extend({
3459
3464
  fieldId: z30.string(),
3460
- fieldType: z30.literal("field")
3465
+ fieldType: z30.literal("field"),
3466
+ defaultValue: z30.union([z30.boolean(), z30.string(), z30.number()]).optional().describe(
3467
+ `Value the field opens with in advanced search. Omitted or true uses the declaration form's defaultValue, false opens the field empty, and any other value opens it with that value. Only text, number and date fields take a value; every other field type, and date fields searched as a range, only accept true or false.`
3468
+ )
3461
3469
  });
3462
3470
  var EventFieldIdInput = z30.enum([
3463
3471
  "trackingId",
@@ -3520,6 +3528,144 @@ var z32 = __toESM(require("zod/v4"));
3520
3528
 
3521
3529
  // ../commons/src/events/DynamicFieldValue.ts
3522
3530
  var z31 = __toESM(require("zod/v4"));
3531
+ function getDynamicNameValue(field3) {
3532
+ const nameConfiguration = field3.configuration?.name;
3533
+ const firstnameRequired = nameConfiguration?.firstname?.required ?? field3.required;
3534
+ const surnameRequired = nameConfiguration?.surname?.required ?? field3.required;
3535
+ return z31.object({
3536
+ firstname: firstnameRequired ? NonEmptyTextValue : TextValue,
3537
+ surname: surnameRequired ? NonEmptyTextValue : TextValue,
3538
+ middlename: nameConfiguration?.middlename?.required ? NonEmptyTextValue : TextValue.optional()
3539
+ });
3540
+ }
3541
+ function getDynamicAddressFieldValue(field3) {
3542
+ const schema = field3.required ? AddressFieldValue : AddressFieldUpdateValue;
3543
+ const configIds = field3.configuration?.streetAddressForm?.map((a) => a.id) ?? [];
3544
+ return schema.refine((arg) => {
3545
+ if (!arg) {
3546
+ return true;
3547
+ }
3548
+ const submittedKeys = Object.keys(arg.streetLevelDetails ?? {});
3549
+ const invalidKeys = submittedKeys.filter((k) => !configIds.includes(k));
3550
+ if (invalidKeys.length) {
3551
+ console.log(
3552
+ "Invalid streetLevelDetails: unknown keys",
3553
+ JSON.stringify(invalidKeys, null, 2)
3554
+ );
3555
+ return false;
3556
+ }
3557
+ return true;
3558
+ });
3559
+ }
3560
+
3561
+ // ../commons/src/events/FieldTypeMapping.ts
3562
+ function mapFieldTypeToZod(field3, actionType) {
3563
+ let schema;
3564
+ switch (field3.type) {
3565
+ case FieldType.FIELD_GROUP: {
3566
+ schema = z32.object(
3567
+ field3.fields.reduce((acc, subfield) => {
3568
+ acc[subfield.id] = mapFieldTypeToZod(subfield, actionType);
3569
+ return acc;
3570
+ }, {})
3571
+ );
3572
+ break;
3573
+ }
3574
+ case FieldType.DATE:
3575
+ schema = PlainDate;
3576
+ break;
3577
+ case FieldType.AGE:
3578
+ schema = AgeValue;
3579
+ break;
3580
+ case FieldType.TIME:
3581
+ schema = TimeValue;
3582
+ break;
3583
+ case FieldType.EMAIL:
3584
+ schema = EmailValue;
3585
+ break;
3586
+ case FieldType.DATE_RANGE:
3587
+ schema = DateRangeFieldValue;
3588
+ break;
3589
+ case FieldType.SELECT_DATE_RANGE:
3590
+ schema = SelectDateRangeValue;
3591
+ break;
3592
+ case FieldType.TEXT:
3593
+ case FieldType.TEXTAREA:
3594
+ case FieldType.DIVIDER:
3595
+ case FieldType.BULLET_LIST:
3596
+ case FieldType.PAGE_HEADER:
3597
+ case FieldType.LOCATION:
3598
+ case FieldType.SELECT:
3599
+ case FieldType.COUNTRY:
3600
+ case FieldType.RADIO_GROUP:
3601
+ case FieldType.PARAGRAPH:
3602
+ case FieldType.HEADING:
3603
+ case FieldType.IMAGE_VIEW:
3604
+ case FieldType.ADMINISTRATIVE_AREA:
3605
+ case FieldType.FACILITY:
3606
+ case FieldType.OFFICE:
3607
+ case FieldType.PHONE:
3608
+ case FieldType.LINK_BUTTON:
3609
+ case FieldType.VERIFICATION_STATUS:
3610
+ case FieldType.ID:
3611
+ case FieldType.LOADER:
3612
+ case FieldType.ALPHA_HIDDEN:
3613
+ case FieldType.USER_ROLE:
3614
+ schema = field3.required ? NonEmptyTextValue : TextValue;
3615
+ break;
3616
+ case FieldType.NUMBER:
3617
+ schema = NumberFieldValue;
3618
+ break;
3619
+ case FieldType.NUMBER_WITH_UNIT:
3620
+ schema = field3.required ? NumberWithUnitFieldValue : NumberWithUnitFieldUpdateValue;
3621
+ break;
3622
+ case FieldType.CHECKBOX:
3623
+ schema = CheckboxFieldValue;
3624
+ break;
3625
+ case FieldType.SIGNATURE:
3626
+ case FieldType.FILE:
3627
+ schema = FileFieldValue;
3628
+ break;
3629
+ case FieldType.FILE_WITH_OPTIONS:
3630
+ schema = field3.required ? FileFieldWithOptionValue.min(1) : FileFieldWithOptionValue;
3631
+ break;
3632
+ case FieldType.ADDRESS:
3633
+ schema = getDynamicAddressFieldValue(field3);
3634
+ break;
3635
+ case FieldType.DATA:
3636
+ schema = DataFieldValue;
3637
+ break;
3638
+ case FieldType.NAME:
3639
+ schema = actionType === ActionType.NOTIFY ? NameFieldUpdateValue : getDynamicNameValue(field3);
3640
+ break;
3641
+ case FieldType.BUTTON:
3642
+ schema = ButtonFieldValue;
3643
+ break;
3644
+ case FieldType.ALPHA_PRINT_BUTTON:
3645
+ schema = TextValue;
3646
+ break;
3647
+ case FieldType.AUTOCOMPLETE:
3648
+ schema = AutocompleteValue;
3649
+ break;
3650
+ case FieldType.HTTP:
3651
+ case FieldType.SEARCH:
3652
+ schema = HttpFieldUpdateValue;
3653
+ break;
3654
+ case FieldType.QUERY_PARAM_READER:
3655
+ schema = QueryParamReaderFieldUpdateValue;
3656
+ break;
3657
+ case FieldType.QR_READER:
3658
+ schema = QrReaderFieldValue;
3659
+ break;
3660
+ case FieldType.ID_READER:
3661
+ schema = IdReaderFieldValue;
3662
+ break;
3663
+ case FieldType._EXPERIMENTAL_CUSTOM:
3664
+ schema = CustomFieldValue;
3665
+ break;
3666
+ }
3667
+ return field3.required ? schema : schema.nullish();
3668
+ }
3523
3669
 
3524
3670
  // ../commons/src/events/state/index.ts
3525
3671
  var import_lodash3 = require("lodash");
@@ -4376,25 +4522,6 @@ function isOnline() {
4376
4522
  return true;
4377
4523
  }
4378
4524
 
4379
- // ../commons/src/events/notificationFormFallback.ts
4380
- function toOptionalField(field3) {
4381
- const { validation: _validation, ...rest } = field3;
4382
- if (rest.type === FieldType.FIELD_GROUP && "fields" in rest) {
4383
- return {
4384
- ...rest,
4385
- required: false,
4386
- fields: rest.fields.map(toOptionalField)
4387
- };
4388
- }
4389
- return { ...rest, required: false };
4390
- }
4391
- function generateNotifyReview(declareReview) {
4392
- return {
4393
- ...declareReview,
4394
- fields: declareReview.fields.map(toOptionalField)
4395
- };
4396
- }
4397
-
4398
4525
  // ../commons/src/events/utils.ts
4399
4526
  var import_date_fns3 = require("date-fns");
4400
4527
  function getDeclaration(configuration) {
@@ -4414,7 +4541,7 @@ function getDeclarationPages(configuration) {
4414
4541
  function getDeclarationFields(configuration) {
4415
4542
  return getDeclarationPages(configuration).flatMap(({ fields }) => fields);
4416
4543
  }
4417
- function getConfiguredNotificationForm(configuration) {
4544
+ function findNotificationForm(configuration) {
4418
4545
  const notifyAction = configuration.actions.find(
4419
4546
  (action) => action.type === ActionType.NOTIFY
4420
4547
  );
@@ -4437,10 +4564,7 @@ function getAllAnnotationFields(config) {
4437
4564
  var findAllFields = (config) => {
4438
4565
  return (0, import_lodash4.flattenDeep)([
4439
4566
  ...getDeclarationFields(config),
4440
- // Only a configured notification form: a derived one repeats the declaration fields.
4441
- ...getConfiguredNotificationForm(config)?.pages.flatMap(
4442
- ({ fields }) => fields
4443
- ) ?? [],
4567
+ ...findNotificationForm(config)?.pages.flatMap(({ fields }) => fields) ?? [],
4444
4568
  ...getAllAnnotationFields(config)
4445
4569
  ]);
4446
4570
  };
@@ -4451,6 +4575,20 @@ var EXCLUDED_ACTIONS = [
4451
4575
  ];
4452
4576
 
4453
4577
  // ../commons/src/events/eventConfigValidation.ts
4578
+ var SEARCH_DEFAULT_VALUE_FIELD_TYPES = [
4579
+ FieldType.TEXT,
4580
+ FieldType.TEXTAREA,
4581
+ FieldType.EMAIL,
4582
+ FieldType.PHONE,
4583
+ FieldType.ID,
4584
+ FieldType.SELECT,
4585
+ FieldType.RADIO_GROUP,
4586
+ FieldType.COUNTRY,
4587
+ FieldType.LOCATION,
4588
+ FieldType.ADMINISTRATIVE_AREA,
4589
+ FieldType.NUMBER,
4590
+ FieldType.DATE
4591
+ ];
4454
4592
  function validateAdvancedSearchConfig(event2, ctx) {
4455
4593
  const allFields = findAllFields(event2);
4456
4594
  const fieldIds = allFields.map((field3) => field3.id);
@@ -4482,6 +4620,56 @@ function validateAdvancedSearchConfig(event2, ctx) {
4482
4620
  path: ["advancedSearch"]
4483
4621
  });
4484
4622
  }
4623
+ event2.advancedSearch.forEach((section, sectionIndex) => {
4624
+ section.fields.forEach((searchField, fieldIndex) => {
4625
+ if (searchField.fieldType !== "field" || searchField.defaultValue === void 0) {
4626
+ return;
4627
+ }
4628
+ const path = [
4629
+ "advancedSearch",
4630
+ sectionIndex,
4631
+ "fields",
4632
+ fieldIndex,
4633
+ "defaultValue"
4634
+ ];
4635
+ if (searchField.config.searchFields && searchField.config.searchFields.length > 0) {
4636
+ ctx.addIssue({
4637
+ code: "custom",
4638
+ message: `Advanced search field ${searchField.fieldId} searches across several form fields, so it does not support a defaultValue.`,
4639
+ path
4640
+ });
4641
+ return;
4642
+ }
4643
+ if (typeof searchField.defaultValue === "boolean") {
4644
+ return;
4645
+ }
4646
+ const formField = allFields.find(({ id }) => id === searchField.fieldId);
4647
+ if (!formField) {
4648
+ return;
4649
+ }
4650
+ if (!SEARCH_DEFAULT_VALUE_FIELD_TYPES.some(
4651
+ (type) => type === formField.type
4652
+ )) {
4653
+ ctx.addIssue({
4654
+ code: "custom",
4655
+ message: `Advanced search field ${searchField.fieldId} is a ${formField.type} field, which does not support a defaultValue value, only true or false. Field types that support a defaultValue value: ${SEARCH_DEFAULT_VALUE_FIELD_TYPES.join(", ")}.`,
4656
+ path
4657
+ });
4658
+ } else if (formField.type === FieldType.DATE && searchField.config.type === "range") {
4659
+ ctx.addIssue({
4660
+ code: "custom",
4661
+ message: `Advanced search field ${searchField.fieldId} is searched as a date range, so its defaultValue can only be true or false.`,
4662
+ path
4663
+ });
4664
+ } else if (!mapFieldTypeToZod(formField).safeParse(searchField.defaultValue).success) {
4665
+ ctx.addIssue({
4666
+ code: "custom",
4667
+ message: `Advanced search field ${searchField.fieldId} has defaultValue "${searchField.defaultValue}", which is not a valid ${formField.type} value.`,
4668
+ path
4669
+ });
4670
+ }
4671
+ });
4672
+ });
4485
4673
  }
4486
4674
  function validateDateOfEvent(event2, ctx) {
4487
4675
  if (event2.dateOfEvent && isFieldReference(event2.dateOfEvent)) {
@@ -4606,9 +4794,11 @@ function validateDeclarationGivenExactlyOnce(config, ctx) {
4606
4794
  }
4607
4795
  }
4608
4796
  function validateNotificationForm(event2, ctx) {
4609
- const declarationFields = getDeclarationFields(event2);
4797
+ const declarationFields = getDeclarationPages(event2).flatMap(
4798
+ (page) => page.fields.map((field3) => ({ field: field3, pageId: page.id }))
4799
+ );
4610
4800
  event2.actions.forEach((action, actionIndex) => {
4611
- if (action.type !== ActionType.NOTIFY || !action.notificationForm) {
4801
+ if (action.type !== ActionType.NOTIFY) {
4612
4802
  return;
4613
4803
  }
4614
4804
  action.notificationForm.pages.forEach((page, pageIndex) => {
@@ -4623,7 +4813,7 @@ function validateNotificationForm(event2, ctx) {
4623
4813
  fieldIndex
4624
4814
  ];
4625
4815
  const matchingFields = declarationFields.filter(
4626
- ({ id }) => id === field3.id
4816
+ (declarationField) => declarationField.field.id === field3.id
4627
4817
  );
4628
4818
  if (matchingFields.length === 0) {
4629
4819
  ctx.addIssue({
@@ -4633,10 +4823,13 @@ function validateNotificationForm(event2, ctx) {
4633
4823
  });
4634
4824
  return;
4635
4825
  }
4636
- if (!matchingFields.some(({ type }) => type === field3.type)) {
4826
+ if (!matchingFields.some(
4827
+ (declarationField) => declarationField.field.type === field3.type
4828
+ )) {
4829
+ const [declarationField] = matchingFields;
4637
4830
  ctx.addIssue({
4638
4831
  code: "custom",
4639
- message: `Notification form field '${field3.id}' is of type ${field3.type}, but the declaration form field with the same id in event '${event2.id}' is of type ${matchingFields[0].type}.`,
4832
+ message: `Notification form field '${field3.id}' on page '${page.id}' is of type ${field3.type}, but the declaration form field with the same id in event '${event2.id}' (${ActionType.DECLARE} declaration, page '${declarationField.pageId}') is of type ${declarationField.field.type}.`,
4640
4833
  path
4641
4834
  });
4642
4835
  }
@@ -4775,7 +4968,7 @@ function createSearchConfig(baseField) {
4775
4968
 
4776
4969
  // ../commons/src/event-config/event-configuration.ts
4777
4970
  function isNonSearchableEventMetadataTimeFieldId(fieldId) {
4778
- return !EventFieldIdInput.safeParse(fieldId).success;
4971
+ return !EventFieldIdInput.validate(fieldId);
4779
4972
  }
4780
4973
  function createEventFieldConfig(fieldId) {
4781
4974
  const baseField = {
@@ -5106,6 +5299,12 @@ var RegisterActionInput = BaseActionInput.extend(
5106
5299
  var NotifyActionInput = BaseActionInput.extend(
5107
5300
  z39.object({
5108
5301
  type: z39.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
5302
+ declaration: BaseActionInput.shape.declaration.describe(
5303
+ "Values for fields of the notification form, keyed by field id. Fields outside the notification form are rejected. Only these values become part of the record declaration, so any id that needs to be searchable must be a declaration field."
5304
+ ),
5305
+ annotation: BaseActionInput.shape.annotation.describe(
5306
+ "Values for notify-only fields (NOTIFY review and form fields), keyed by field id. These are stored on the NOTIFY action, not in the record declaration."
5307
+ ),
5109
5308
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5110
5309
  createdAtLocation: UUID.nullish().describe(
5111
5310
  "A valid office location ID. This is required for system users performing actions. The provided location must be a leaf-location, i.e. it must not have any children locations."
@@ -5289,17 +5488,19 @@ var DraftInput = BaseActionInput.omit({ waitFor: true }).extend({
5289
5488
  /*
5290
5489
  * A draft can name a file that no action references. Such a file stays until
5291
5490
  * the record is deleted or the record's next action sweeps its prefix.
5292
- * DECLARE is available only where one of those is still coming: a created
5293
- * record, which can still be deleted, and a record part way through an edit,
5294
- * which is about to be declared or registered.
5491
+ * Drafts are therefore saved only on a created record, which can still be deleted.
5492
+ * The server refuses them on any other record.
5295
5493
  */
5296
- type: z40.literal(ActionTypes.enum.DECLARE),
5494
+ type: z40.enum([ActionTypes.enum.DECLARE, ActionTypes.enum.NOTIFY]),
5297
5495
  status: z40.enum([
5298
5496
  ActionStatus.Requested,
5299
5497
  ActionStatus.Accepted,
5300
5498
  ActionStatus.Rejected
5301
5499
  ])
5302
5500
  });
5501
+ var RemoteDraft = Draft.extend({
5502
+ action: Draft.shape.action.extend({ type: DraftInput.shape.type })
5503
+ });
5303
5504
 
5304
5505
  // ../commons/src/events/EventInput.ts
5305
5506
  var z41 = __toESM(require("zod/v4"));
@@ -5348,57 +5549,44 @@ function moveDeclarationToDeclareAction({
5348
5549
  )
5349
5550
  };
5350
5551
  }
5351
- function generateNotificationFormFallback(config) {
5352
- const declareAction = config.actions.find(
5353
- (action) => action.type === ActionType.DECLARE
5354
- );
5355
- const notifyAction = config.actions.find(
5356
- (action) => action.type === ActionType.NOTIFY
5357
- );
5358
- if (!notifyAction?.notificationForm) {
5359
- console.warn(
5360
- `Event '${config.id}' has no ${ActionType.NOTIFY} form. Using the ${ActionType.DECLARE} form with all fields optional. Configure \`actions[${ActionType.NOTIFY}].notificationForm\`. This fallback will be removed in a future release.`
5361
- );
5362
- }
5363
- if (notifyAction?.review) {
5364
- return config;
5365
- }
5366
- if (!declareAction?.declaration) {
5367
- throw new Error(
5368
- `Event '${config.id}' has no ${ActionType.DECLARE} form. Configure \`actions[${ActionType.DECLARE}].declaration\`.`
5369
- );
5552
+ var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5553
+ if (validateExactlyOneDeclareAction(config, ctx)) {
5554
+ validateDeclarationGivenExactlyOnce(config, ctx);
5370
5555
  }
5371
- const review = generateNotifyReview(declareAction.review);
5372
- if (notifyAction) {
5556
+ }).transform(moveDeclarationToDeclareAction).pipe(EventConfig);
5557
+ var defineConfig = (config) => EventConfigDefinition.parse(config);
5558
+
5559
+ // ../commons/src/events/toNotificationForm.ts
5560
+ function toOptionalField(field3) {
5561
+ const { validation: _validation, ...rest } = field3;
5562
+ if (rest.type === FieldType.FIELD_GROUP && "fields" in rest) {
5373
5563
  return {
5374
- ...config,
5375
- actions: config.actions.map(
5376
- (action) => action === notifyAction ? { ...notifyAction, review } : action
5377
- )
5564
+ ...rest,
5565
+ required: false,
5566
+ fields: rest.fields.map(toOptionalField)
5378
5567
  };
5379
5568
  }
5380
- const notifyFromDeclare = {
5381
- type: ActionType.NOTIFY,
5382
- label: declareAction.label,
5383
- icon: declareAction.icon,
5384
- conditionals: declareAction.conditionals,
5385
- flags: declareAction.flags,
5386
- supportingCopy: declareAction.dialogCopy?.notify,
5387
- review
5569
+ return { ...rest, required: false };
5570
+ }
5571
+ function toNotificationForm(declaration) {
5572
+ return {
5573
+ ...declaration,
5574
+ pages: declaration.pages.map((page) => ({
5575
+ ...page,
5576
+ fields: page.fields.map(
5577
+ toOptionalField
5578
+ )
5579
+ }))
5388
5580
  };
5581
+ }
5582
+ function toNotificationReview(review) {
5389
5583
  return {
5390
- ...config,
5391
- actions: config.actions.flatMap(
5392
- (action) => action === declareAction ? [notifyFromDeclare, action] : [action]
5584
+ ...review,
5585
+ fields: review.fields.map(
5586
+ toOptionalField
5393
5587
  )
5394
5588
  };
5395
5589
  }
5396
- var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5397
- if (validateExactlyOneDeclareAction(config, ctx)) {
5398
- validateDeclarationGivenExactlyOnce(config, ctx);
5399
- }
5400
- }).transform(moveDeclarationToDeclareAction).transform(generateNotificationFormFallback).pipe(EventConfig);
5401
- var defineConfig = (config) => EventConfigDefinition.parse(config);
5402
5590
 
5403
5591
  // ../commons/src/events/test.utils.ts
5404
5592
  var import_lodash5 = require("lodash");
@@ -6707,6 +6895,8 @@ var tennisClubMembershipEvent = defineConfig({
6707
6895
  description: "This is shown as the action name anywhere the user can trigger the action from",
6708
6896
  id: "event.tennis-club-membership.action.notify.label"
6709
6897
  },
6898
+ notificationForm: toNotificationForm(TENNIS_CLUB_DECLARATION_FORM),
6899
+ review: toNotificationReview(TENNIS_CLUB_DECLARATION_REVIEW),
6710
6900
  flags: [
6711
6901
  {
6712
6902
  id: "health-worker-notified",
@@ -8341,6 +8531,8 @@ var ACTION_SCOPE_MAP = {
8341
8531
  "record.correct"
8342
8532
  ],
8343
8533
  [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
8534
+ // Not granted by a scope: the client checks the draft's own action instead
8535
+ [ClientSpecificAction.CONTINUE_DRAFT]: [],
8344
8536
  [ActionType.REJECT_CORRECTION]: ["record.correct"],
8345
8537
  [ActionType.APPROVE_CORRECTION]: ["record.correct"],
8346
8538
  [ActionType.REVOKE_REGISTRATION]: ["record.revoke-registration"],
@@ -0,0 +1,2 @@
1
+ export * from '../commons/users/Role';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/roles/index.ts"],"names":[],"mappings":"AAaA,cAAc,8BAA8B,CAAA"}