@opencrvs/toolkit 2.2.0-rc.045257f → 2.2.0-rc.1a111f2

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 (54) hide show
  1. package/dist/cli.js +925 -356
  2. package/dist/commons/api/router.d.ts +4 -4
  3. package/dist/commons/events/ActionType.d.ts +2 -0
  4. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
  5. package/dist/commons/events/Draft.d.ts +34 -1
  6. package/dist/commons/events/EventConfig.d.ts +385 -0
  7. package/dist/commons/events/defineConfig.d.ts +7 -2
  8. package/dist/commons/events/event.d.ts +4 -1
  9. package/dist/commons/events/field.d.ts +5 -0
  10. package/dist/commons/events/scopes.d.ts +1 -0
  11. package/dist/commons/events/test.utils.d.ts +57 -5
  12. package/dist/commons/events/utils.d.ts +13 -0
  13. package/dist/environment/custom-types.d.ts +1 -0
  14. package/dist/environment/custom-types.d.ts.map +1 -1
  15. package/dist/environment/derived-variables.d.ts +8 -0
  16. package/dist/environment/derived-variables.d.ts.map +1 -1
  17. package/dist/environment/derived-variables.js +9 -0
  18. package/dist/environment/questions.d.ts +42 -9
  19. package/dist/environment/questions.d.ts.map +1 -1
  20. package/dist/environment/questions.js +70 -47
  21. package/dist/environment/registry.d.ts +15 -0
  22. package/dist/environment/registry.d.ts.map +1 -0
  23. package/dist/environment/registry.js +112 -0
  24. package/dist/environment/setup-environment.d.ts.map +1 -1
  25. package/dist/environment/setup-environment.js +98 -23
  26. package/dist/events/index.js +462 -99
  27. package/dist/migrations/add-notify-config.d.ts +40 -0
  28. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  29. package/dist/migrations/add-notify-config.js +249 -0
  30. package/dist/migrations/index.d.ts.map +1 -1
  31. package/dist/migrations/index.js +602 -143
  32. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  33. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  34. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  35. package/dist/migrations/read-declaration-through-helper.js +3 -61
  36. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  37. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  38. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  39. package/dist/migrations/utils.d.ts +61 -0
  40. package/dist/migrations/utils.d.ts.map +1 -0
  41. package/dist/migrations/utils.js +218 -0
  42. package/dist/notification/index.js +510 -36
  43. package/dist/templates/charts-values/dependencies/values.yaml +2 -1
  44. package/dist/templates/charts-values/opencrvs-services/values.yaml +2 -2
  45. package/dist/verify/endpoints.d.ts +11 -0
  46. package/dist/verify/endpoints.d.ts.map +1 -1
  47. package/dist/verify/endpoints.js +21 -27
  48. package/opencrvs-toolkit-2.2.0-rc.1a111f2.tgz +0 -0
  49. package/package.json +2 -1
  50. package/tsconfig.build.tsbuildinfo +1 -1
  51. package/dist/environment/dockerhub.d.ts +0 -15
  52. package/dist/environment/dockerhub.d.ts.map +0 -1
  53. package/dist/environment/dockerhub.js +0 -104
  54. package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
@@ -136,7 +136,9 @@ var ActionTypes = z2.enum([
136
136
  "CUSTOM"
137
137
  ]);
138
138
  var ClientSpecificAction = {
139
- 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"
140
142
  };
141
143
  var declarationActionValues = [
142
144
  ActionTypes.enum.DECLARE,
@@ -3460,7 +3462,10 @@ var SearchQueryParams = z30.object({
3460
3462
  }).catchall(FieldValue);
3461
3463
  var FieldConfigSchema = BaseField3.extend({
3462
3464
  fieldId: z30.string(),
3463
- 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
+ )
3464
3469
  });
3465
3470
  var EventFieldIdInput = z30.enum([
3466
3471
  "trackingId",
@@ -3523,6 +3528,144 @@ var z32 = __toESM(require("zod/v4"));
3523
3528
 
3524
3529
  // ../commons/src/events/DynamicFieldValue.ts
3525
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
+ }
3526
3669
 
3527
3670
  // ../commons/src/events/state/index.ts
3528
3671
  var import_lodash3 = require("lodash");
@@ -4294,7 +4437,9 @@ function buildClientFunctionContext(input) {
4294
4437
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
4295
4438
  $online: isOnline(),
4296
4439
  $user: input.validatorContext?.user,
4297
- $event: input.validatorContext?.event?.document,
4440
+ $event: input.validatorContext?.event?.document ? getEventWithCompleteAcceptedActions(
4441
+ input.validatorContext.event.document
4442
+ ) : void 0,
4298
4443
  $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
4299
4444
  user: input.systemVariables?.user,
4300
4445
  $window: input.systemVariables?.$window,
@@ -4398,7 +4543,7 @@ function getDeclarationPages(configuration) {
4398
4543
  function getDeclarationFields(configuration) {
4399
4544
  return getDeclarationPages(configuration).flatMap(({ fields }) => fields);
4400
4545
  }
4401
- function getConfiguredNotificationForm(configuration) {
4546
+ function findNotificationForm(configuration) {
4402
4547
  const notifyAction = configuration.actions.find(
4403
4548
  (action) => action.type === ActionType.NOTIFY
4404
4549
  );
@@ -4418,15 +4563,108 @@ var getActionAnnotationFields = (actionConfig) => {
4418
4563
  function getAllAnnotationFields(config) {
4419
4564
  return (0, import_lodash4.flattenDeep)(config.actions.map(getActionAnnotationFields));
4420
4565
  }
4566
+ function deepMerge(currentDocument, actionDocument) {
4567
+ return (0, import_lodash4.mergeWith)(
4568
+ (0, import_lodash4.cloneDeep)(currentDocument),
4569
+ actionDocument,
4570
+ (previousValue, incomingValue) => {
4571
+ if (incomingValue === void 0) {
4572
+ return previousValue;
4573
+ }
4574
+ if ((0, import_lodash4.isArray)(incomingValue)) {
4575
+ return incomingValue;
4576
+ }
4577
+ if ((0, import_lodash4.isObject)(previousValue) && (0, import_lodash4.isObject)(incomingValue)) {
4578
+ return void 0;
4579
+ }
4580
+ return incomingValue;
4581
+ }
4582
+ );
4583
+ }
4421
4584
  var findAllFields = (config) => {
4422
4585
  return (0, import_lodash4.flattenDeep)([
4423
4586
  ...getDeclarationFields(config),
4424
- ...getConfiguredNotificationForm(config)?.pages.flatMap(
4425
- ({ fields }) => fields
4426
- ) ?? [],
4587
+ ...findNotificationForm(config)?.pages.flatMap(({ fields }) => fields) ?? [],
4427
4588
  ...getAllAnnotationFields(config)
4428
4589
  ]);
4429
4590
  };
4591
+ function isAcceptedAction(a) {
4592
+ return a.status === ActionStatus.Accepted;
4593
+ }
4594
+ function getCompleteActionAnnotation(event2, action) {
4595
+ if (action.originalActionId) {
4596
+ const originalAction = event2.actions.find(
4597
+ ({ id }) => id === action.originalActionId
4598
+ );
4599
+ if (originalAction?.status === ActionStatus.Requested) {
4600
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4601
+ }
4602
+ }
4603
+ return action.annotation ?? {};
4604
+ }
4605
+ function getCompleteActionContent(event2, action) {
4606
+ const currentContent = "content" in action ? action.content : void 0;
4607
+ if (!action.originalActionId) {
4608
+ return currentContent;
4609
+ }
4610
+ const originalAction = event2.actions.find(
4611
+ ({ id }) => id === action.originalActionId
4612
+ );
4613
+ if (originalAction && "content" in originalAction && originalAction.content) {
4614
+ return {
4615
+ ...originalAction.content,
4616
+ ...currentContent ?? {}
4617
+ };
4618
+ }
4619
+ return currentContent;
4620
+ }
4621
+ function getCompleteActionDeclaration(declaration, event2, action) {
4622
+ if (action.originalActionId) {
4623
+ const originalAction = event2.actions.find(
4624
+ ({ id }) => id === action.originalActionId
4625
+ );
4626
+ if (originalAction?.status === ActionStatus.Requested) {
4627
+ return deepMerge(
4628
+ deepMerge(declaration, originalAction.declaration),
4629
+ action.declaration
4630
+ );
4631
+ }
4632
+ }
4633
+ return deepMerge(declaration, action.declaration);
4634
+ }
4635
+ function completeAcceptedAction(event2, action) {
4636
+ return {
4637
+ ...action,
4638
+ declaration: getCompleteActionDeclaration({}, event2, action),
4639
+ annotation: getCompleteActionAnnotation(event2, action)
4640
+ };
4641
+ }
4642
+ function getEventWithCompleteAcceptedActions(event2) {
4643
+ return {
4644
+ ...event2,
4645
+ actions: event2.actions.map((action) => {
4646
+ if (!isAcceptedAction(action) || !action.originalActionId) {
4647
+ return action;
4648
+ }
4649
+ const requestedAction = event2.actions.find(
4650
+ ({ id }) => id === action.originalActionId
4651
+ );
4652
+ if (requestedAction?.status !== ActionStatus.Requested) {
4653
+ return action;
4654
+ }
4655
+ const content = getCompleteActionContent(event2, action);
4656
+ return {
4657
+ ...completeAcceptedAction(event2, action),
4658
+ // Who requested the action, as getActionUpdateMetadata resolves it.
4659
+ createdBy: requestedAction.createdBy,
4660
+ createdByRole: requestedAction.createdByRole,
4661
+ createdByUserType: requestedAction.createdByUserType,
4662
+ createdAtLocation: requestedAction.createdAtLocation,
4663
+ ...content ? { content } : {}
4664
+ };
4665
+ })
4666
+ };
4667
+ }
4430
4668
  var EXCLUDED_ACTIONS = [
4431
4669
  ActionType.REQUEST_CORRECTION,
4432
4670
  ActionType.PRINT_CERTIFICATE,
@@ -4434,6 +4672,20 @@ var EXCLUDED_ACTIONS = [
4434
4672
  ];
4435
4673
 
4436
4674
  // ../commons/src/events/eventConfigValidation.ts
4675
+ var SEARCH_DEFAULT_VALUE_FIELD_TYPES = [
4676
+ FieldType.TEXT,
4677
+ FieldType.TEXTAREA,
4678
+ FieldType.EMAIL,
4679
+ FieldType.PHONE,
4680
+ FieldType.ID,
4681
+ FieldType.SELECT,
4682
+ FieldType.RADIO_GROUP,
4683
+ FieldType.COUNTRY,
4684
+ FieldType.LOCATION,
4685
+ FieldType.ADMINISTRATIVE_AREA,
4686
+ FieldType.NUMBER,
4687
+ FieldType.DATE
4688
+ ];
4437
4689
  function validateAdvancedSearchConfig(event2, ctx) {
4438
4690
  const allFields = findAllFields(event2);
4439
4691
  const fieldIds = allFields.map((field3) => field3.id);
@@ -4465,6 +4717,56 @@ function validateAdvancedSearchConfig(event2, ctx) {
4465
4717
  path: ["advancedSearch"]
4466
4718
  });
4467
4719
  }
4720
+ event2.advancedSearch.forEach((section, sectionIndex) => {
4721
+ section.fields.forEach((searchField, fieldIndex) => {
4722
+ if (searchField.fieldType !== "field" || searchField.defaultValue === void 0) {
4723
+ return;
4724
+ }
4725
+ const path = [
4726
+ "advancedSearch",
4727
+ sectionIndex,
4728
+ "fields",
4729
+ fieldIndex,
4730
+ "defaultValue"
4731
+ ];
4732
+ if (searchField.config.searchFields && searchField.config.searchFields.length > 0) {
4733
+ ctx.addIssue({
4734
+ code: "custom",
4735
+ message: `Advanced search field ${searchField.fieldId} searches across several form fields, so it does not support a defaultValue.`,
4736
+ path
4737
+ });
4738
+ return;
4739
+ }
4740
+ if (typeof searchField.defaultValue === "boolean") {
4741
+ return;
4742
+ }
4743
+ const formField = allFields.find(({ id }) => id === searchField.fieldId);
4744
+ if (!formField) {
4745
+ return;
4746
+ }
4747
+ if (!SEARCH_DEFAULT_VALUE_FIELD_TYPES.some(
4748
+ (type) => type === formField.type
4749
+ )) {
4750
+ ctx.addIssue({
4751
+ code: "custom",
4752
+ 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(", ")}.`,
4753
+ path
4754
+ });
4755
+ } else if (formField.type === FieldType.DATE && searchField.config.type === "range") {
4756
+ ctx.addIssue({
4757
+ code: "custom",
4758
+ message: `Advanced search field ${searchField.fieldId} is searched as a date range, so its defaultValue can only be true or false.`,
4759
+ path
4760
+ });
4761
+ } else if (!mapFieldTypeToZod(formField).safeParse(searchField.defaultValue).success) {
4762
+ ctx.addIssue({
4763
+ code: "custom",
4764
+ message: `Advanced search field ${searchField.fieldId} has defaultValue "${searchField.defaultValue}", which is not a valid ${formField.type} value.`,
4765
+ path
4766
+ });
4767
+ }
4768
+ });
4769
+ });
4468
4770
  }
4469
4771
  function validateDateOfEvent(event2, ctx) {
4470
4772
  if (event2.dateOfEvent && isFieldReference(event2.dateOfEvent)) {
@@ -4637,10 +4939,16 @@ function validateNotificationForm(event2, ctx) {
4637
4939
  var EventFieldReference = z35.object({ $$event: EventMetadataDateFieldIdInput }).describe(
4638
4940
  "Reference to a field defined in the event metadata, using the field id."
4639
4941
  );
4640
- var _EventConfigBase = z35.object({
4942
+ var eventLevelFields = {
4641
4943
  id: z35.string().describe(
4642
4944
  'Machine-readable identifier of the event (e.g. "birth", "death").'
4643
4945
  ),
4946
+ label: TranslationConfig.describe("Human-readable label for the event type."),
4947
+ advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4948
+ "Configuration of fields available in the advanced search feature."
4949
+ )
4950
+ };
4951
+ var versionFields = {
4644
4952
  dateOfEvent: FieldReference.or(EventFieldReference).optional().describe(
4645
4953
  "Reference to the field capturing the date of the event (e.g. date of birth). Defaults to the event creation date if unspecified."
4646
4954
  ),
@@ -4656,18 +4964,12 @@ var _EventConfigBase = z35.object({
4656
4964
  summary: SummaryConfig.describe(
4657
4965
  "Summary information displayed in the event overview."
4658
4966
  ),
4659
- label: TranslationConfig.describe(
4660
- "Human-readable label for the event type."
4661
- ),
4662
4967
  actions: z35.array(ActionConfig).describe(
4663
4968
  "Configuration of core and custom actions associated with the event."
4664
4969
  ),
4665
4970
  actionOrder: z35.array(z35.string()).optional().describe(
4666
4971
  "Order of actions in the action menu. Use either the action type for core actions or the customActionType for custom actions."
4667
4972
  ),
4668
- advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4669
- "Configuration of fields available in the advanced search feature."
4670
- ),
4671
4973
  flags: z35.array(FlagConfig).optional().default([]).describe(
4672
4974
  "Configuration of custom flags associated with the actions of this event type."
4673
4975
  ),
@@ -4677,8 +4979,9 @@ var _EventConfigBase = z35.object({
4677
4979
  icon: z35.partialRecord(AvailableIcons, Conditional).optional().describe(
4678
4980
  'Maps an icon name to a conditional. The icon of the first entry (in definition order) whose conditional matches the event is used when rendering it (e.g. in the "iconWithName"/"iconWithNameEvent" workqueue columns). Falls back to the default status-based icon when unset or when no conditional matches.'
4679
4981
  )
4680
- });
4681
- var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
4982
+ };
4983
+ var _EventConfigBase = z35.object({ ...eventLevelFields, ...versionFields });
4984
+ function validateEventConfig(event2, ctx) {
4682
4985
  if (!validateExactlyOneDeclareAction(event2, ctx)) {
4683
4986
  return;
4684
4987
  }
@@ -4688,10 +4991,116 @@ var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
4688
4991
  validatePlaceOfEvent(event2, ctx);
4689
4992
  validateActionFlags(event2, ctx);
4690
4993
  validateActionOrder(event2, ctx);
4691
- }).meta({
4994
+ }
4995
+ var EventConfig = _EventConfigBase.superRefine(validateEventConfig).meta({
4692
4996
  id: "EventConfig",
4693
4997
  description: "Configuration defining an event type registered in OpenCRVS (for example birth or death)."
4694
4998
  });
4999
+ var DEFAULT_EVENT_CONFIG_VERSION_ID = "default";
5000
+ var DEFAULT_EFFECTIVE_FROM = "0001-01-01";
5001
+ var _EventConfigVersion = z35.object({
5002
+ id: z35.string().describe(
5003
+ 'Identifier of the version, unique within the event (e.g. "birth-v2").'
5004
+ ),
5005
+ effectiveFrom: z35.iso.date().default(DEFAULT_EFFECTIVE_FROM).describe(
5006
+ `Date (YYYY-MM-DD) from which this version is effective. A version without one is effective from the beginning of time ('${DEFAULT_EFFECTIVE_FROM}').`
5007
+ ),
5008
+ ...versionFields
5009
+ });
5010
+ var resolvedConfigs = /* @__PURE__ */ new WeakMap();
5011
+ function getEventConfigOfVersion(config, version) {
5012
+ let resolvedVersions = resolvedConfigs.get(config);
5013
+ if (!resolvedVersions) {
5014
+ resolvedVersions = /* @__PURE__ */ new WeakMap();
5015
+ resolvedConfigs.set(config, resolvedVersions);
5016
+ }
5017
+ const cached = resolvedVersions.get(version);
5018
+ if (cached) {
5019
+ return cached;
5020
+ }
5021
+ const { id: _id, effectiveFrom: _effectiveFrom, ...fields } = version;
5022
+ const resolved = {
5023
+ ...fields,
5024
+ id: config.id,
5025
+ label: config.label,
5026
+ advancedSearch: config.advancedSearch
5027
+ };
5028
+ resolvedVersions.set(version, resolved);
5029
+ return resolved;
5030
+ }
5031
+ function resolveEventConfig(config) {
5032
+ return getEventConfigOfVersion(config, config.versions[0]);
5033
+ }
5034
+ function validateVersionList(config, ctx) {
5035
+ const ids = /* @__PURE__ */ new Set();
5036
+ const versionIdByEffectiveFrom = /* @__PURE__ */ new Map();
5037
+ config.versions.forEach((version, index) => {
5038
+ if (ids.has(version.id)) {
5039
+ ctx.addIssue({
5040
+ code: "custom",
5041
+ message: `Event '${config.id}' has more than one version with id '${version.id}'. Each version must have a different id.`,
5042
+ path: ["versions", index, "id"]
5043
+ });
5044
+ }
5045
+ ids.add(version.id);
5046
+ const sameEffectiveFromId = versionIdByEffectiveFrom.get(
5047
+ version.effectiveFrom
5048
+ );
5049
+ if (sameEffectiveFromId !== void 0) {
5050
+ const versionIds = `'${sameEffectiveFromId}', '${version.id}'`;
5051
+ ctx.addIssue({
5052
+ code: "custom",
5053
+ message: version.effectiveFrom !== DEFAULT_EFFECTIVE_FROM ? `Event '${config.id}' has more than one version with \`effectiveFrom\` '${version.effectiveFrom}' (${versionIds}). Each version must have a different \`effectiveFrom\`.` : `Event '${config.id}' has more than one version without \`effectiveFrom\` (${versionIds}). At most one version may omit it.`,
5054
+ path: ["versions", index, "effectiveFrom"]
5055
+ });
5056
+ } else {
5057
+ versionIdByEffectiveFrom.set(version.effectiveFrom, version.id);
5058
+ }
5059
+ });
5060
+ }
5061
+ function validateEachVersion(ctx, events, validate2) {
5062
+ const reported = /* @__PURE__ */ new Set();
5063
+ events.forEach((event2, index) => {
5064
+ const addIssue = (issue) => {
5065
+ if (typeof issue === "string") {
5066
+ ctx.addIssue({
5067
+ code: "custom",
5068
+ message: issue,
5069
+ path: ["versions", index]
5070
+ });
5071
+ return;
5072
+ }
5073
+ const [field3] = issue.path ?? [];
5074
+ const isEventLevel = typeof field3 === "string" && field3 in eventLevelFields;
5075
+ const path = isEventLevel ? issue.path ?? [] : ["versions", index, ...issue.path ?? []];
5076
+ const key = JSON.stringify([path, issue.message]);
5077
+ if (reported.has(key)) {
5078
+ return;
5079
+ }
5080
+ reported.add(key);
5081
+ ctx.addIssue({ ...issue, path });
5082
+ };
5083
+ validate2(event2, { value: event2, addIssue });
5084
+ });
5085
+ }
5086
+ var VersionedEventConfig = z35.object({
5087
+ ...eventLevelFields,
5088
+ versions: z35.array(_EventConfigVersion).min(1).describe(
5089
+ `Versions of the event configuration, each effective from its \`effectiveFrom\`. An event configured without versions has a single version, with id '${DEFAULT_EVENT_CONFIG_VERSION_ID}' and \`effectiveFrom\` '${DEFAULT_EFFECTIVE_FROM}'.`
5090
+ )
5091
+ }).superRefine((config, ctx) => {
5092
+ validateVersionList(config, ctx);
5093
+ validateEachVersion(
5094
+ ctx,
5095
+ config.versions.map(
5096
+ (version) => getEventConfigOfVersion(config, version)
5097
+ ),
5098
+ validateEventConfig
5099
+ );
5100
+ }).meta({
5101
+ id: "VersionedEventConfig",
5102
+ description: "Configuration of an event type registered in OpenCRVS (for example birth or death), with every version of it."
5103
+ });
4695
5104
 
4696
5105
  // ../commons/src/events/EventConfigInput.ts
4697
5106
  var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
@@ -4790,7 +5199,10 @@ function eventFn(fieldId) {
4790
5199
  }
4791
5200
  var event = Object.assign(eventFn, {
4792
5201
  /**
4793
- * Checks if the event contains a specific action type.
5202
+ * Checks if the event contains a specific accepted action type.
5203
+ * Only Accepted actions are matched: a confirmable action is stored as a
5204
+ * Requested and an Accepted action, and a pending or rejected request must
5205
+ * not count as the action having happened.
4794
5206
  * Can be used directly as a conditional or chained with additional methods.
4795
5207
  * @param action - The action type to check for.
4796
5208
  */
@@ -4808,9 +5220,12 @@ var event = Object.assign(eventFn, {
4808
5220
  properties: {
4809
5221
  type: {
4810
5222
  const: action
5223
+ },
5224
+ status: {
5225
+ const: ActionStatus.Accepted
4811
5226
  }
4812
5227
  },
4813
- required: ["type"]
5228
+ required: ["type", "status"]
4814
5229
  }
4815
5230
  }
4816
5231
  },
@@ -4821,9 +5236,10 @@ var event = Object.assign(eventFn, {
4821
5236
  });
4822
5237
  const buildActionConstraints = (additionalFields) => {
4823
5238
  const actionProperties = {
4824
- type: { const: action }
5239
+ type: { const: action },
5240
+ status: { const: ActionStatus.Accepted }
4825
5241
  };
4826
- const requiredFields = ["type"];
5242
+ const requiredFields = ["type", "status"];
4827
5243
  if (additionalFields) {
4828
5244
  Object.entries(additionalFields).forEach(([key, value]) => {
4829
5245
  actionProperties[key] = { const: value };
@@ -5283,17 +5699,19 @@ var DraftInput = BaseActionInput.omit({ waitFor: true }).extend({
5283
5699
  /*
5284
5700
  * A draft can name a file that no action references. Such a file stays until
5285
5701
  * the record is deleted or the record's next action sweeps its prefix.
5286
- * DECLARE is available only where one of those is still coming: a created
5287
- * record, which can still be deleted, and a record part way through an edit,
5288
- * which is about to be declared or registered.
5702
+ * Drafts are therefore saved only on a created record, which can still be deleted.
5703
+ * The server refuses them on any other record.
5289
5704
  */
5290
- type: z40.literal(ActionTypes.enum.DECLARE),
5705
+ type: z40.enum([ActionTypes.enum.DECLARE, ActionTypes.enum.NOTIFY]),
5291
5706
  status: z40.enum([
5292
5707
  ActionStatus.Requested,
5293
5708
  ActionStatus.Accepted,
5294
5709
  ActionStatus.Rejected
5295
5710
  ])
5296
5711
  });
5712
+ var RemoteDraft = Draft.extend({
5713
+ action: Draft.shape.action.extend({ type: DraftInput.shape.type })
5714
+ });
5297
5715
 
5298
5716
  // ../commons/src/events/EventInput.ts
5299
5717
  var z41 = __toESM(require("zod/v4"));
@@ -5337,16 +5755,55 @@ function moveDeclarationToDeclareAction({
5337
5755
  }
5338
5756
  return {
5339
5757
  ...config,
5340
- actions: config.actions.map(
5341
- (action) => action.type === ActionType.DECLARE && declaration ? { ...action, declaration } : action
5342
- )
5758
+ actions: config.actions.map((action) => {
5759
+ if (action.type !== ActionType.DECLARE) {
5760
+ return action;
5761
+ }
5762
+ const declarationOfAction = action.declaration ?? declaration;
5763
+ if (!declarationOfAction) {
5764
+ throw new Error(`Event '${config.id}' does not define \`declaration\`.`);
5765
+ }
5766
+ return { ...action, declaration: declarationOfAction };
5767
+ })
5768
+ };
5769
+ }
5770
+ var VERSIONED_EVENT_FIELDS = [
5771
+ "id",
5772
+ "label",
5773
+ "advancedSearch",
5774
+ "versions"
5775
+ ];
5776
+ function validateNoVersionFieldsAtTopLevel(config, ctx) {
5777
+ Object.keys(config).filter((key) => !VERSIONED_EVENT_FIELDS.includes(key)).forEach((key) => {
5778
+ ctx.addIssue({
5779
+ code: "custom",
5780
+ message: `Event '${config.id}' defines \`versions\`, so \`${key}\` must be defined on each version, not at the top level.`,
5781
+ path: [key]
5782
+ });
5783
+ });
5784
+ }
5785
+ function toVersionedInput(config) {
5786
+ if ("versions" in config) {
5787
+ return config;
5788
+ }
5789
+ const { id, label, advancedSearch, ...version } = moveDeclarationToDeclareAction(config);
5790
+ return {
5791
+ id,
5792
+ label,
5793
+ advancedSearch,
5794
+ versions: [{ ...version, id: DEFAULT_EVENT_CONFIG_VERSION_ID }]
5343
5795
  };
5344
5796
  }
5345
5797
  var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5346
- if (validateExactlyOneDeclareAction(config, ctx)) {
5347
- validateDeclarationGivenExactlyOnce(config, ctx);
5798
+ if ("versions" in config) {
5799
+ validateNoVersionFieldsAtTopLevel(config, ctx);
5800
+ return;
5348
5801
  }
5349
- }).transform(moveDeclarationToDeclareAction).pipe(EventConfig);
5802
+ const eventCtx = { ...ctx, value: config };
5803
+ if (validateExactlyOneDeclareAction(config, eventCtx)) {
5804
+ validateDeclarationGivenExactlyOnce(config, eventCtx);
5805
+ }
5806
+ }).transform(toVersionedInput).pipe(VersionedEventConfig);
5350
5807
  var defineConfig = (config) => EventConfigDefinition.parse(config);
5351
5808
 
5352
5809
  // ../commons/src/events/toNotificationForm.ts
@@ -6629,7 +7086,7 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
6629
7086
  });
6630
7087
 
6631
7088
  // ../commons/src/fixtures/tennis-club-membership-event.ts
6632
- var tennisClubMembershipEvent = defineConfig({
7089
+ var versionedTennisClubMembershipEvent = defineConfig({
6633
7090
  id: TENNIS_CLUB_MEMBERSHIP,
6634
7091
  declaration: TENNIS_CLUB_DECLARATION_FORM,
6635
7092
  label: {
@@ -6986,9 +7443,12 @@ var tennisClubMembershipEvent = defineConfig({
6986
7443
  }
6987
7444
  ]
6988
7445
  });
7446
+ var tennisClubMembershipEvent = resolveEventConfig(
7447
+ versionedTennisClubMembershipEvent
7448
+ );
6989
7449
 
6990
7450
  // ../commons/src/fixtures/football-club-membership-event.ts
6991
- var footballClubMembershipEvent = defineConfig({
7451
+ var versionedFootballClubMembershipEvent = defineConfig({
6992
7452
  id: "FOOTBALL_CLUB_MEMBERSHIP",
6993
7453
  label: {
6994
7454
  defaultMessage: "Football club membership application",
@@ -7311,6 +7771,9 @@ var footballClubMembershipEvent = defineConfig({
7311
7771
  ],
7312
7772
  declaration: TENNIS_CLUB_DECLARATION_FORM
7313
7773
  });
7774
+ var footballClubMembershipEvent = resolveEventConfig(
7775
+ versionedFootballClubMembershipEvent
7776
+ );
7314
7777
 
7315
7778
  // ../commons/src/fixtures/library-membership-event.ts
7316
7779
  var libraryMembershipForm = defineDeclarationForm({
@@ -7354,7 +7817,7 @@ var libraryMembershipForm = defineDeclarationForm({
7354
7817
  }
7355
7818
  ]
7356
7819
  });
7357
- var libraryMembershipEvent = defineConfig({
7820
+ var versionedLibraryMembershipEvent = defineConfig({
7358
7821
  id: "library-membership",
7359
7822
  label: {
7360
7823
  defaultMessage: "Library membership application",
@@ -7387,6 +7850,9 @@ var libraryMembershipEvent = defineConfig({
7387
7850
  ],
7388
7851
  declaration: libraryMembershipForm
7389
7852
  });
7853
+ var libraryMembershipEvent = resolveEventConfig(
7854
+ versionedLibraryMembershipEvent
7855
+ );
7390
7856
 
7391
7857
  // ../commons/src/fixtures/child-onboarding-event.ts
7392
7858
  function generateTranslationConfig(message) {
@@ -7600,7 +8066,7 @@ var CHILD_ONBOARDING_DECLARATION_FORM = defineDeclarationForm({
7600
8066
  label: generateTranslationConfig("Birth decalration form"),
7601
8067
  pages: [child, mother]
7602
8068
  });
7603
- var ChildOnboardingEvent = defineConfig({
8069
+ var versionedChildOnboardingEvent = defineConfig({
7604
8070
  id: CHILD_ONBOARDING_EVENT,
7605
8071
  title: generateTranslationConfig(
7606
8072
  "{child.name.firstname} {child.name.surname}"
@@ -7628,6 +8094,9 @@ var ChildOnboardingEvent = defineConfig({
7628
8094
  ],
7629
8095
  advancedSearch: []
7630
8096
  });
8097
+ var ChildOnboardingEvent = resolveEventConfig(
8098
+ versionedChildOnboardingEvent
8099
+ );
7631
8100
 
7632
8101
  // ../commons/src/fixtures/digital-identity-issuance-event.ts
7633
8102
  var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
@@ -7816,7 +8285,7 @@ var digitalIdentityForm = defineDeclarationForm({
7816
8285
  }
7817
8286
  ]
7818
8287
  });
7819
- var digitalIdentityEvent = defineConfig({
8288
+ var versionedDigitalIdentityEvent = defineConfig({
7820
8289
  id: "digital-identity",
7821
8290
  label: {
7822
8291
  defaultMessage: "Digital identity issuance",
@@ -7858,6 +8327,9 @@ var digitalIdentityEvent = defineConfig({
7858
8327
  ],
7859
8328
  declaration: digitalIdentityForm
7860
8329
  });
8330
+ var digitalIdentityEvent = resolveEventConfig(
8331
+ versionedDigitalIdentityEvent
8332
+ );
7861
8333
 
7862
8334
  // ../commons/src/events/test.utils.ts
7863
8335
  var z45 = __toESM(require("zod/v4"));
@@ -8324,6 +8796,8 @@ var ACTION_SCOPE_MAP = {
8324
8796
  "record.correct"
8325
8797
  ],
8326
8798
  [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
8799
+ // Not granted by a scope: the client checks the draft's own action instead
8800
+ [ClientSpecificAction.CONTINUE_DRAFT]: [],
8327
8801
  [ActionType.REJECT_CORRECTION]: ["record.correct"],
8328
8802
  [ActionType.APPROVE_CORRECTION]: ["record.correct"],
8329
8803
  [ActionType.REVOKE_REGISTRATION]: ["record.revoke-registration"],