@opencrvs/toolkit 2.2.0-rc.045257f → 2.2.0-rc.25c3c81

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 (156) hide show
  1. package/build.sh +15 -2
  2. package/dist/application-config/index.js +16 -5
  3. package/dist/authentication/index.d.ts +1 -1
  4. package/dist/authentication/index.js +4 -8
  5. package/dist/cli.js +2197 -544
  6. package/dist/commons/api/router.d.ts +17 -4
  7. package/dist/commons/application-config/index.d.ts +1 -1
  8. package/dist/commons/conditionals/conditionals.d.ts +4 -4
  9. package/dist/commons/conditionals/validate.d.ts +1 -1
  10. package/dist/commons/events/ActionStatus.d.ts +2 -2
  11. package/dist/commons/events/ActionType.d.ts +2 -0
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
  13. package/dist/commons/events/Draft.d.ts +34 -1
  14. package/dist/commons/events/EventConfig.d.ts +446 -0
  15. package/dist/commons/events/EventDocument.d.ts +2 -0
  16. package/dist/commons/events/EventIndex.d.ts +1 -0
  17. package/dist/commons/events/EventInput.d.ts +1 -0
  18. package/dist/commons/events/EventMetadata.d.ts +1 -0
  19. package/dist/commons/events/FieldTypeMapping.d.ts +19 -19
  20. package/dist/commons/events/PlainDate.d.ts +5 -0
  21. package/dist/commons/events/defineConfig.d.ts +7 -2
  22. package/dist/commons/events/event.d.ts +4 -1
  23. package/dist/commons/events/field.d.ts +5 -0
  24. package/dist/commons/events/locations.d.ts +1 -1
  25. package/dist/commons/events/scopes.d.ts +2 -1
  26. package/dist/commons/events/state/index.d.ts +1 -0
  27. package/dist/commons/events/test.utils.d.ts +59 -6
  28. package/dist/commons/events/utils.d.ts +28 -2
  29. package/dist/commons/users/Role.d.ts +23 -0
  30. package/dist/commons/users/User.d.ts +263 -0
  31. package/dist/commons/users/authentication.d.ts +67 -0
  32. package/dist/commons/users/index.d.ts +5 -0
  33. package/dist/commons/users/roleValidations.d.ts +15 -0
  34. package/dist/commons/users/scopes.d.ts +1402 -0
  35. package/dist/commons/users/userReferences.d.ts +176 -0
  36. package/dist/conditionals/index.js +3 -3
  37. package/dist/configurator/index.d.ts +24 -0
  38. package/dist/configurator/index.d.ts.map +1 -0
  39. package/dist/configurator/index.js +161 -0
  40. package/dist/configurator/layout.d.ts +28 -0
  41. package/dist/configurator/layout.d.ts.map +1 -0
  42. package/dist/configurator/layout.js +78 -0
  43. package/dist/configurator/paths.d.ts +13 -0
  44. package/dist/configurator/paths.d.ts.map +1 -0
  45. package/dist/configurator/paths.js +48 -0
  46. package/dist/configurator/server/environments.d.ts +20 -0
  47. package/dist/configurator/server/environments.d.ts.map +1 -0
  48. package/dist/configurator/server/environments.js +143 -0
  49. package/dist/configurator/server/files.d.ts +11 -0
  50. package/dist/configurator/server/files.d.ts.map +1 -0
  51. package/dist/configurator/server/files.js +67 -0
  52. package/dist/configurator/server/github.d.ts +56 -0
  53. package/dist/configurator/server/github.d.ts.map +1 -0
  54. package/dist/configurator/server/github.js +239 -0
  55. package/dist/configurator/server/plugin.d.ts +39 -0
  56. package/dist/configurator/server/plugin.d.ts.map +1 -0
  57. package/dist/configurator/server/plugin.js +298 -0
  58. package/dist/configurator/server/seal.d.ts +2 -0
  59. package/dist/configurator/server/seal.d.ts.map +1 -0
  60. package/dist/configurator/server/seal.js +36 -0
  61. package/dist/configurator/server/sshKeys.d.ts +5 -0
  62. package/dist/configurator/server/sshKeys.d.ts.map +1 -0
  63. package/dist/configurator/server/sshKeys.js +28 -0
  64. package/dist/configurator/server/start.d.ts +12 -0
  65. package/dist/configurator/server/start.d.ts.map +1 -0
  66. package/dist/configurator/server/start.js +91 -0
  67. package/dist/configurator/testing.d.ts +11 -0
  68. package/dist/configurator/testing.d.ts.map +1 -0
  69. package/dist/configurator/testing.js +74 -0
  70. package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
  71. package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
  72. package/dist/configurator/ui/bindings/bindings.js +5 -0
  73. package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
  74. package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
  75. package/dist/configurator/ui/bindings/parsers.js +85 -0
  76. package/dist/configurator/ui/form/users.d.ts +11 -0
  77. package/dist/configurator/ui/form/users.d.ts.map +1 -0
  78. package/dist/configurator/ui/form/users.js +33 -0
  79. package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
  80. package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
  81. package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
  82. package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
  83. package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
  84. package/dist/configurator/ui/plan/templateValues.js +70 -0
  85. package/dist/configurator/workflows.d.ts +53 -0
  86. package/dist/configurator/workflows.d.ts.map +1 -0
  87. package/dist/configurator/workflows.js +161 -0
  88. package/dist/configurator-assets/forms/bindings.yml +263 -0
  89. package/dist/configurator-assets/templates/README.md +18 -0
  90. package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
  91. package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +99 -0
  92. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  93. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
  94. package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
  95. package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
  96. package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
  97. package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
  98. package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
  99. package/dist/configurator-assets/ui/assets/index-Bf3eC7uO.js +169 -0
  100. package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
  101. package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
  102. package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
  103. package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
  104. package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
  105. package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
  106. package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
  107. package/dist/configurator-assets/ui/index.html +25 -0
  108. package/dist/environment/custom-types.d.ts +1 -0
  109. package/dist/environment/custom-types.d.ts.map +1 -1
  110. package/dist/environment/derived-variables.d.ts +8 -0
  111. package/dist/environment/derived-variables.d.ts.map +1 -1
  112. package/dist/environment/derived-variables.js +9 -0
  113. package/dist/environment/questions.d.ts +42 -9
  114. package/dist/environment/questions.d.ts.map +1 -1
  115. package/dist/environment/questions.js +70 -47
  116. package/dist/environment/registry.d.ts +15 -0
  117. package/dist/environment/registry.d.ts.map +1 -0
  118. package/dist/environment/registry.js +112 -0
  119. package/dist/environment/setup-environment.d.ts.map +1 -1
  120. package/dist/environment/setup-environment.js +104 -23
  121. package/dist/events/index.js +635 -149
  122. package/dist/migrations/add-notify-config.d.ts +40 -0
  123. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  124. package/dist/migrations/add-notify-config.js +249 -0
  125. package/dist/migrations/index.d.ts.map +1 -1
  126. package/dist/migrations/index.js +602 -143
  127. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  128. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  129. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  130. package/dist/migrations/read-declaration-through-helper.js +3 -61
  131. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  132. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  133. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  134. package/dist/migrations/utils.d.ts +61 -0
  135. package/dist/migrations/utils.d.ts.map +1 -0
  136. package/dist/migrations/utils.js +218 -0
  137. package/dist/notification/index.js +616 -66
  138. package/dist/roles/index.d.ts +2 -0
  139. package/dist/roles/index.d.ts.map +1 -0
  140. package/dist/roles/index.js +730 -0
  141. package/dist/scopes/index.d.ts +0 -10
  142. package/dist/scopes/index.js +3 -7
  143. package/dist/templates/charts-values/dependencies/values.yaml +4 -1
  144. package/dist/templates/charts-values/opencrvs-services/values.yaml +2 -2
  145. package/dist/verify/endpoints.d.ts +11 -0
  146. package/dist/verify/endpoints.d.ts.map +1 -1
  147. package/dist/verify/endpoints.js +21 -27
  148. package/opencrvs-toolkit-2.2.0-rc.25c3c81.tgz +0 -0
  149. package/package.json +16 -3
  150. package/tsconfig.build.json +11 -1
  151. package/tsconfig.build.tsbuildinfo +1 -1
  152. package/tsconfig.json +15 -6
  153. package/dist/environment/dockerhub.d.ts +0 -15
  154. package/dist/environment/dockerhub.d.ts.map +0 -1
  155. package/dist/environment/dockerhub.js +0 -104
  156. package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
@@ -46,11 +46,11 @@ var import_compile = require("zod/compile");
46
46
  // ../commons/src/events/AuditLog.ts
47
47
  var z9 = __toESM(require("zod/v4"));
48
48
 
49
- // ../commons/src/authentication.ts
49
+ // ../commons/src/users/authentication.ts
50
50
  var import_jwt_decode = __toESM(require("jwt-decode"));
51
51
  var z8 = __toESM(require("zod/v4"));
52
52
 
53
- // ../commons/src/scopes.ts
53
+ // ../commons/src/users/scopes.ts
54
54
  var z7 = __toESM(require("zod/v4"));
55
55
  var qs = __toESM(require("qs"));
56
56
 
@@ -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,
@@ -328,7 +330,7 @@ var EventStatus = z6.enum([
328
330
  "ARCHIVED"
329
331
  ]);
330
332
 
331
- // ../commons/src/scopes.ts
333
+ // ../commons/src/users/scopes.ts
332
334
  var JurisdictionFilter = z7.enum(["administrativeArea", "location", "all"]).describe(
333
335
  "Filters based on user jurisdiction relative to their office location in hierarchy."
334
336
  );
@@ -601,7 +603,7 @@ var DEFAULT_SCOPE_OPTIONS = {
601
603
  registeredIn: JurisdictionFilter.enum.all
602
604
  };
603
605
 
604
- // ../commons/src/authentication.ts
606
+ // ../commons/src/users/authentication.ts
605
607
  var TokenUserType = z8.enum(["user", "system"]);
606
608
  var TokenWithBearer = z8.string().regex(/^Bearer\s/);
607
609
 
@@ -1106,6 +1108,26 @@ var CustomFieldValue = z12.unknown().brand("CustomFieldValue");
1106
1108
  // ../commons/src/events/PlainDate.ts
1107
1109
  var import_zod = require("zod");
1108
1110
  var PlainDate = import_zod.z.string().date().brand("PlainDate").describe("Date in the format YYYY-MM-DD");
1111
+ var dateFormats = /* @__PURE__ */ new Map();
1112
+ function getDateFormat(timeZone) {
1113
+ let format2 = dateFormats.get(timeZone);
1114
+ if (!format2) {
1115
+ format2 = new Intl.DateTimeFormat("en-US", {
1116
+ timeZone,
1117
+ year: "numeric",
1118
+ month: "2-digit",
1119
+ day: "2-digit"
1120
+ });
1121
+ dateFormats.set(timeZone, format2);
1122
+ }
1123
+ return format2;
1124
+ }
1125
+ function toPlainDateInTimeZone(date, timeZone) {
1126
+ const parts = Object.fromEntries(
1127
+ getDateFormat(timeZone).formatToParts(date).map(({ type, value }) => [type, value])
1128
+ );
1129
+ return `${parts.year}-${parts.month}-${parts.day}`;
1130
+ }
1109
1131
 
1110
1132
  // ../commons/src/events/FieldValue.ts
1111
1133
  var TextValue = z14.string();
@@ -1542,6 +1564,9 @@ var LegalStatuses = z17.object({
1542
1564
  var EventMetadata = z17.object({
1543
1565
  id: UUID,
1544
1566
  type: z17.string().describe("The type of event, such as birth, death, or marriage."),
1567
+ configVersionId: z17.string().describe(
1568
+ "Id of the event configuration version the record was created under. Records created before versioning have 'initial'."
1569
+ ),
1545
1570
  status: EventStatus,
1546
1571
  legalStatuses: LegalStatuses.describe(
1547
1572
  "Metadata related to the legal registration of the event, such as who registered it and when."
@@ -3097,7 +3122,7 @@ var ActionConfig = z25.discriminatedUnion("type", [
3097
3122
  }),
3098
3123
  NotifyConfig.meta({
3099
3124
  id: "NotifyActionConfig",
3100
- description: "Configuration for the notify action, including the notification form and its review page. When undefined, it is generated using the DeclareActionConfig."
3125
+ description: "Configuration for the notify action: the notification form and its review page. An event without a NOTIFY action cannot be notified."
3101
3126
  }),
3102
3127
  DeclareConfig.meta({
3103
3128
  id: "DeclareActionConfig",
@@ -3365,7 +3390,7 @@ var ReferenceField = BaseField2.extend({
3365
3390
  var Field = BaseField2.extend({
3366
3391
  id: z29.string().describe("Identifier of the summary field."),
3367
3392
  value: TranslationConfig.describe(
3368
- 'Field value template supports variables from configuration (e.g. "{informant.phoneNo} {informant.email}") and EventMetadata (e.g. "{event.legalStatuses.REGISTERED.acceptedAt, date, ::dd MMMM yyyy}").'
3393
+ 'Field value template supports variables from configuration (e.g. "{informant.phoneNo} {informant.email}") and EventMetadata (e.g. "{event.legalStatuses.REGISTERED.acceptedAt, date, ::dd MMMM yyyy}"). "{event.configVersionLabel}" gives the label of the configuration version that the record was created under.'
3369
3394
  ),
3370
3395
  label: TranslationConfig
3371
3396
  }).describe("Custom field defined for the summary view.");
@@ -3460,7 +3485,10 @@ var SearchQueryParams = z30.object({
3460
3485
  }).catchall(FieldValue);
3461
3486
  var FieldConfigSchema = BaseField3.extend({
3462
3487
  fieldId: z30.string(),
3463
- fieldType: z30.literal("field")
3488
+ fieldType: z30.literal("field"),
3489
+ defaultValue: z30.union([z30.boolean(), z30.string(), z30.number()]).optional().describe(
3490
+ `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.`
3491
+ )
3464
3492
  });
3465
3493
  var EventFieldIdInput = z30.enum([
3466
3494
  "trackingId",
@@ -3509,32 +3537,20 @@ var AdvancedSearchConfig = z30.object({
3509
3537
  description: "Configuration of one advanced search tab. Each tab has a title and a list of searchable fields \u2014 either declaration fields (via `field()`) or event metadata (via `event()`)."
3510
3538
  });
3511
3539
 
3512
- // ../commons/src/events/utils.ts
3513
- var import_lodash4 = require("lodash");
3514
-
3515
- // ../commons/src/conditionals/validate.ts
3516
- var import__ = __toESM(require("ajv/dist/2019"));
3517
- var import_ajv_formats = __toESM(require("ajv-formats"));
3518
- var z34 = __toESM(require("zod/v4"));
3519
- var import_date_fns2 = require("date-fns");
3520
-
3521
- // ../commons/src/events/FieldTypeMapping.ts
3522
- var z32 = __toESM(require("zod/v4"));
3523
-
3524
- // ../commons/src/events/DynamicFieldValue.ts
3525
- var z31 = __toESM(require("zod/v4"));
3526
-
3527
- // ../commons/src/events/state/index.ts
3528
- var import_lodash3 = require("lodash");
3529
-
3530
3540
  // ../commons/src/utils.ts
3531
- var z33 = __toESM(require("zod/v4"));
3541
+ var z31 = __toESM(require("zod/v4"));
3532
3542
  var _ = __toESM(require("lodash"));
3533
- var FullNameV1 = z33.array(
3534
- z33.object({
3535
- use: z33.string(),
3536
- family: z33.string(),
3537
- given: z33.array(z33.string())
3543
+ function getOrThrow(x, message) {
3544
+ if (x === void 0 || x === null) {
3545
+ throw new Error(message);
3546
+ }
3547
+ return x;
3548
+ }
3549
+ var FullNameV1 = z31.array(
3550
+ z31.object({
3551
+ use: z31.string(),
3552
+ family: z31.string(),
3553
+ given: z31.array(z31.string())
3538
3554
  })
3539
3555
  );
3540
3556
  function omitKeyDeep(obj, keyToRemove) {
@@ -3553,6 +3569,162 @@ function omitKeyDeep(obj, keyToRemove) {
3553
3569
  return newObj;
3554
3570
  }
3555
3571
 
3572
+ // ../commons/src/events/utils.ts
3573
+ var import_lodash4 = require("lodash");
3574
+
3575
+ // ../commons/src/conditionals/validate.ts
3576
+ var import__ = __toESM(require("ajv/dist/2019"));
3577
+ var import_ajv_formats = __toESM(require("ajv-formats"));
3578
+ var z34 = __toESM(require("zod/v4"));
3579
+ var import_date_fns2 = require("date-fns");
3580
+
3581
+ // ../commons/src/events/FieldTypeMapping.ts
3582
+ var z33 = __toESM(require("zod/v4"));
3583
+
3584
+ // ../commons/src/events/DynamicFieldValue.ts
3585
+ var z32 = __toESM(require("zod/v4"));
3586
+ function getDynamicNameValue(field3) {
3587
+ const nameConfiguration = field3.configuration?.name;
3588
+ const firstnameRequired = nameConfiguration?.firstname?.required ?? field3.required;
3589
+ const surnameRequired = nameConfiguration?.surname?.required ?? field3.required;
3590
+ return z32.object({
3591
+ firstname: firstnameRequired ? NonEmptyTextValue : TextValue,
3592
+ surname: surnameRequired ? NonEmptyTextValue : TextValue,
3593
+ middlename: nameConfiguration?.middlename?.required ? NonEmptyTextValue : TextValue.optional()
3594
+ });
3595
+ }
3596
+ function getDynamicAddressFieldValue(field3) {
3597
+ const schema = field3.required ? AddressFieldValue : AddressFieldUpdateValue;
3598
+ const configIds = field3.configuration?.streetAddressForm?.map((a) => a.id) ?? [];
3599
+ return schema.refine((arg) => {
3600
+ if (!arg) {
3601
+ return true;
3602
+ }
3603
+ const submittedKeys = Object.keys(arg.streetLevelDetails ?? {});
3604
+ const invalidKeys = submittedKeys.filter((k) => !configIds.includes(k));
3605
+ if (invalidKeys.length) {
3606
+ console.log(
3607
+ "Invalid streetLevelDetails: unknown keys",
3608
+ JSON.stringify(invalidKeys, null, 2)
3609
+ );
3610
+ return false;
3611
+ }
3612
+ return true;
3613
+ });
3614
+ }
3615
+
3616
+ // ../commons/src/events/FieldTypeMapping.ts
3617
+ function mapFieldTypeToZod(field3, actionType) {
3618
+ let schema;
3619
+ switch (field3.type) {
3620
+ case FieldType.FIELD_GROUP: {
3621
+ schema = z33.object(
3622
+ field3.fields.reduce((acc, subfield) => {
3623
+ acc[subfield.id] = mapFieldTypeToZod(subfield, actionType);
3624
+ return acc;
3625
+ }, {})
3626
+ );
3627
+ break;
3628
+ }
3629
+ case FieldType.DATE:
3630
+ schema = PlainDate;
3631
+ break;
3632
+ case FieldType.AGE:
3633
+ schema = AgeValue;
3634
+ break;
3635
+ case FieldType.TIME:
3636
+ schema = TimeValue;
3637
+ break;
3638
+ case FieldType.EMAIL:
3639
+ schema = EmailValue;
3640
+ break;
3641
+ case FieldType.DATE_RANGE:
3642
+ schema = DateRangeFieldValue;
3643
+ break;
3644
+ case FieldType.SELECT_DATE_RANGE:
3645
+ schema = SelectDateRangeValue;
3646
+ break;
3647
+ case FieldType.TEXT:
3648
+ case FieldType.TEXTAREA:
3649
+ case FieldType.DIVIDER:
3650
+ case FieldType.BULLET_LIST:
3651
+ case FieldType.PAGE_HEADER:
3652
+ case FieldType.LOCATION:
3653
+ case FieldType.SELECT:
3654
+ case FieldType.COUNTRY:
3655
+ case FieldType.RADIO_GROUP:
3656
+ case FieldType.PARAGRAPH:
3657
+ case FieldType.HEADING:
3658
+ case FieldType.IMAGE_VIEW:
3659
+ case FieldType.ADMINISTRATIVE_AREA:
3660
+ case FieldType.FACILITY:
3661
+ case FieldType.OFFICE:
3662
+ case FieldType.PHONE:
3663
+ case FieldType.LINK_BUTTON:
3664
+ case FieldType.VERIFICATION_STATUS:
3665
+ case FieldType.ID:
3666
+ case FieldType.LOADER:
3667
+ case FieldType.ALPHA_HIDDEN:
3668
+ case FieldType.USER_ROLE:
3669
+ schema = field3.required ? NonEmptyTextValue : TextValue;
3670
+ break;
3671
+ case FieldType.NUMBER:
3672
+ schema = NumberFieldValue;
3673
+ break;
3674
+ case FieldType.NUMBER_WITH_UNIT:
3675
+ schema = field3.required ? NumberWithUnitFieldValue : NumberWithUnitFieldUpdateValue;
3676
+ break;
3677
+ case FieldType.CHECKBOX:
3678
+ schema = CheckboxFieldValue;
3679
+ break;
3680
+ case FieldType.SIGNATURE:
3681
+ case FieldType.FILE:
3682
+ schema = FileFieldValue;
3683
+ break;
3684
+ case FieldType.FILE_WITH_OPTIONS:
3685
+ schema = field3.required ? FileFieldWithOptionValue.min(1) : FileFieldWithOptionValue;
3686
+ break;
3687
+ case FieldType.ADDRESS:
3688
+ schema = getDynamicAddressFieldValue(field3);
3689
+ break;
3690
+ case FieldType.DATA:
3691
+ schema = DataFieldValue;
3692
+ break;
3693
+ case FieldType.NAME:
3694
+ schema = actionType === ActionType.NOTIFY ? NameFieldUpdateValue : getDynamicNameValue(field3);
3695
+ break;
3696
+ case FieldType.BUTTON:
3697
+ schema = ButtonFieldValue;
3698
+ break;
3699
+ case FieldType.ALPHA_PRINT_BUTTON:
3700
+ schema = TextValue;
3701
+ break;
3702
+ case FieldType.AUTOCOMPLETE:
3703
+ schema = AutocompleteValue;
3704
+ break;
3705
+ case FieldType.HTTP:
3706
+ case FieldType.SEARCH:
3707
+ schema = HttpFieldUpdateValue;
3708
+ break;
3709
+ case FieldType.QUERY_PARAM_READER:
3710
+ schema = QueryParamReaderFieldUpdateValue;
3711
+ break;
3712
+ case FieldType.QR_READER:
3713
+ schema = QrReaderFieldValue;
3714
+ break;
3715
+ case FieldType.ID_READER:
3716
+ schema = IdReaderFieldValue;
3717
+ break;
3718
+ case FieldType._EXPERIMENTAL_CUSTOM:
3719
+ schema = CustomFieldValue;
3720
+ break;
3721
+ }
3722
+ return field3.required ? schema : schema.nullish();
3723
+ }
3724
+
3725
+ // ../commons/src/events/state/index.ts
3726
+ var import_lodash3 = require("lodash");
3727
+
3556
3728
  // ../commons/src/events/state/utils.ts
3557
3729
  var import_lodash = require("lodash");
3558
3730
  var updateActions = new Set(
@@ -4294,7 +4466,9 @@ function buildClientFunctionContext(input) {
4294
4466
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
4295
4467
  $online: isOnline(),
4296
4468
  $user: input.validatorContext?.user,
4297
- $event: input.validatorContext?.event?.document,
4469
+ $event: input.validatorContext?.event?.document ? getEventWithCompleteAcceptedActions(
4470
+ input.validatorContext.event.document
4471
+ ) : void 0,
4298
4472
  $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
4299
4473
  user: input.systemVariables?.user,
4300
4474
  $window: input.systemVariables?.$window,
@@ -4398,7 +4572,7 @@ function getDeclarationPages(configuration) {
4398
4572
  function getDeclarationFields(configuration) {
4399
4573
  return getDeclarationPages(configuration).flatMap(({ fields }) => fields);
4400
4574
  }
4401
- function getConfiguredNotificationForm(configuration) {
4575
+ function findNotificationForm(configuration) {
4402
4576
  const notifyAction = configuration.actions.find(
4403
4577
  (action) => action.type === ActionType.NOTIFY
4404
4578
  );
@@ -4418,15 +4592,108 @@ var getActionAnnotationFields = (actionConfig) => {
4418
4592
  function getAllAnnotationFields(config) {
4419
4593
  return (0, import_lodash4.flattenDeep)(config.actions.map(getActionAnnotationFields));
4420
4594
  }
4595
+ function deepMerge(currentDocument, actionDocument) {
4596
+ return (0, import_lodash4.mergeWith)(
4597
+ (0, import_lodash4.cloneDeep)(currentDocument),
4598
+ actionDocument,
4599
+ (previousValue, incomingValue) => {
4600
+ if (incomingValue === void 0) {
4601
+ return previousValue;
4602
+ }
4603
+ if ((0, import_lodash4.isArray)(incomingValue)) {
4604
+ return incomingValue;
4605
+ }
4606
+ if ((0, import_lodash4.isObject)(previousValue) && (0, import_lodash4.isObject)(incomingValue)) {
4607
+ return void 0;
4608
+ }
4609
+ return incomingValue;
4610
+ }
4611
+ );
4612
+ }
4421
4613
  var findAllFields = (config) => {
4422
4614
  return (0, import_lodash4.flattenDeep)([
4423
4615
  ...getDeclarationFields(config),
4424
- ...getConfiguredNotificationForm(config)?.pages.flatMap(
4425
- ({ fields }) => fields
4426
- ) ?? [],
4616
+ ...findNotificationForm(config)?.pages.flatMap(({ fields }) => fields) ?? [],
4427
4617
  ...getAllAnnotationFields(config)
4428
4618
  ]);
4429
4619
  };
4620
+ function isAcceptedAction(a) {
4621
+ return a.status === ActionStatus.Accepted;
4622
+ }
4623
+ function getCompleteActionAnnotation(event2, action) {
4624
+ if (action.originalActionId) {
4625
+ const originalAction = event2.actions.find(
4626
+ ({ id }) => id === action.originalActionId
4627
+ );
4628
+ if (originalAction?.status === ActionStatus.Requested) {
4629
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4630
+ }
4631
+ }
4632
+ return action.annotation ?? {};
4633
+ }
4634
+ function getCompleteActionContent(event2, action) {
4635
+ const currentContent = "content" in action ? action.content : void 0;
4636
+ if (!action.originalActionId) {
4637
+ return currentContent;
4638
+ }
4639
+ const originalAction = event2.actions.find(
4640
+ ({ id }) => id === action.originalActionId
4641
+ );
4642
+ if (originalAction && "content" in originalAction && originalAction.content) {
4643
+ return {
4644
+ ...originalAction.content,
4645
+ ...currentContent ?? {}
4646
+ };
4647
+ }
4648
+ return currentContent;
4649
+ }
4650
+ function getCompleteActionDeclaration(declaration, event2, action) {
4651
+ if (action.originalActionId) {
4652
+ const originalAction = event2.actions.find(
4653
+ ({ id }) => id === action.originalActionId
4654
+ );
4655
+ if (originalAction?.status === ActionStatus.Requested) {
4656
+ return deepMerge(
4657
+ deepMerge(declaration, originalAction.declaration),
4658
+ action.declaration
4659
+ );
4660
+ }
4661
+ }
4662
+ return deepMerge(declaration, action.declaration);
4663
+ }
4664
+ function completeAcceptedAction(event2, action) {
4665
+ return {
4666
+ ...action,
4667
+ declaration: getCompleteActionDeclaration({}, event2, action),
4668
+ annotation: getCompleteActionAnnotation(event2, action)
4669
+ };
4670
+ }
4671
+ function getEventWithCompleteAcceptedActions(event2) {
4672
+ return {
4673
+ ...event2,
4674
+ actions: event2.actions.map((action) => {
4675
+ if (!isAcceptedAction(action) || !action.originalActionId) {
4676
+ return action;
4677
+ }
4678
+ const requestedAction = event2.actions.find(
4679
+ ({ id }) => id === action.originalActionId
4680
+ );
4681
+ if (requestedAction?.status !== ActionStatus.Requested) {
4682
+ return action;
4683
+ }
4684
+ const content = getCompleteActionContent(event2, action);
4685
+ return {
4686
+ ...completeAcceptedAction(event2, action),
4687
+ // Who requested the action, as getActionUpdateMetadata resolves it.
4688
+ createdBy: requestedAction.createdBy,
4689
+ createdByRole: requestedAction.createdByRole,
4690
+ createdByUserType: requestedAction.createdByUserType,
4691
+ createdAtLocation: requestedAction.createdAtLocation,
4692
+ ...content ? { content } : {}
4693
+ };
4694
+ })
4695
+ };
4696
+ }
4430
4697
  var EXCLUDED_ACTIONS = [
4431
4698
  ActionType.REQUEST_CORRECTION,
4432
4699
  ActionType.PRINT_CERTIFICATE,
@@ -4434,6 +4701,20 @@ var EXCLUDED_ACTIONS = [
4434
4701
  ];
4435
4702
 
4436
4703
  // ../commons/src/events/eventConfigValidation.ts
4704
+ var SEARCH_DEFAULT_VALUE_FIELD_TYPES = [
4705
+ FieldType.TEXT,
4706
+ FieldType.TEXTAREA,
4707
+ FieldType.EMAIL,
4708
+ FieldType.PHONE,
4709
+ FieldType.ID,
4710
+ FieldType.SELECT,
4711
+ FieldType.RADIO_GROUP,
4712
+ FieldType.COUNTRY,
4713
+ FieldType.LOCATION,
4714
+ FieldType.ADMINISTRATIVE_AREA,
4715
+ FieldType.NUMBER,
4716
+ FieldType.DATE
4717
+ ];
4437
4718
  function validateAdvancedSearchConfig(event2, ctx) {
4438
4719
  const allFields = findAllFields(event2);
4439
4720
  const fieldIds = allFields.map((field3) => field3.id);
@@ -4465,6 +4746,56 @@ function validateAdvancedSearchConfig(event2, ctx) {
4465
4746
  path: ["advancedSearch"]
4466
4747
  });
4467
4748
  }
4749
+ event2.advancedSearch.forEach((section, sectionIndex) => {
4750
+ section.fields.forEach((searchField, fieldIndex) => {
4751
+ if (searchField.fieldType !== "field" || searchField.defaultValue === void 0) {
4752
+ return;
4753
+ }
4754
+ const path = [
4755
+ "advancedSearch",
4756
+ sectionIndex,
4757
+ "fields",
4758
+ fieldIndex,
4759
+ "defaultValue"
4760
+ ];
4761
+ if (searchField.config.searchFields && searchField.config.searchFields.length > 0) {
4762
+ ctx.addIssue({
4763
+ code: "custom",
4764
+ message: `Advanced search field ${searchField.fieldId} searches across several form fields, so it does not support a defaultValue.`,
4765
+ path
4766
+ });
4767
+ return;
4768
+ }
4769
+ if (typeof searchField.defaultValue === "boolean") {
4770
+ return;
4771
+ }
4772
+ const formField = allFields.find(({ id }) => id === searchField.fieldId);
4773
+ if (!formField) {
4774
+ return;
4775
+ }
4776
+ if (!SEARCH_DEFAULT_VALUE_FIELD_TYPES.some(
4777
+ (type) => type === formField.type
4778
+ )) {
4779
+ ctx.addIssue({
4780
+ code: "custom",
4781
+ 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(", ")}.`,
4782
+ path
4783
+ });
4784
+ } else if (formField.type === FieldType.DATE && searchField.config.type === "range") {
4785
+ ctx.addIssue({
4786
+ code: "custom",
4787
+ message: `Advanced search field ${searchField.fieldId} is searched as a date range, so its defaultValue can only be true or false.`,
4788
+ path
4789
+ });
4790
+ } else if (!mapFieldTypeToZod(formField).safeParse(searchField.defaultValue).success) {
4791
+ ctx.addIssue({
4792
+ code: "custom",
4793
+ message: `Advanced search field ${searchField.fieldId} has defaultValue "${searchField.defaultValue}", which is not a valid ${formField.type} value.`,
4794
+ path
4795
+ });
4796
+ }
4797
+ });
4798
+ });
4468
4799
  }
4469
4800
  function validateDateOfEvent(event2, ctx) {
4470
4801
  if (event2.dateOfEvent && isFieldReference(event2.dateOfEvent)) {
@@ -4637,10 +4968,16 @@ function validateNotificationForm(event2, ctx) {
4637
4968
  var EventFieldReference = z35.object({ $$event: EventMetadataDateFieldIdInput }).describe(
4638
4969
  "Reference to a field defined in the event metadata, using the field id."
4639
4970
  );
4640
- var _EventConfigBase = z35.object({
4971
+ var eventLevelFields = {
4641
4972
  id: z35.string().describe(
4642
4973
  'Machine-readable identifier of the event (e.g. "birth", "death").'
4643
4974
  ),
4975
+ label: TranslationConfig.describe("Human-readable label for the event type."),
4976
+ advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4977
+ "Configuration of fields available in the advanced search feature."
4978
+ )
4979
+ };
4980
+ var versionFields = {
4644
4981
  dateOfEvent: FieldReference.or(EventFieldReference).optional().describe(
4645
4982
  "Reference to the field capturing the date of the event (e.g. date of birth). Defaults to the event creation date if unspecified."
4646
4983
  ),
@@ -4656,18 +4993,12 @@ var _EventConfigBase = z35.object({
4656
4993
  summary: SummaryConfig.describe(
4657
4994
  "Summary information displayed in the event overview."
4658
4995
  ),
4659
- label: TranslationConfig.describe(
4660
- "Human-readable label for the event type."
4661
- ),
4662
4996
  actions: z35.array(ActionConfig).describe(
4663
4997
  "Configuration of core and custom actions associated with the event."
4664
4998
  ),
4665
4999
  actionOrder: z35.array(z35.string()).optional().describe(
4666
5000
  "Order of actions in the action menu. Use either the action type for core actions or the customActionType for custom actions."
4667
5001
  ),
4668
- advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4669
- "Configuration of fields available in the advanced search feature."
4670
- ),
4671
5002
  flags: z35.array(FlagConfig).optional().default([]).describe(
4672
5003
  "Configuration of custom flags associated with the actions of this event type."
4673
5004
  ),
@@ -4677,8 +5008,9 @@ var _EventConfigBase = z35.object({
4677
5008
  icon: z35.partialRecord(AvailableIcons, Conditional).optional().describe(
4678
5009
  '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
5010
  )
4680
- });
4681
- var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
5011
+ };
5012
+ var _EventConfigBase = z35.object({ ...eventLevelFields, ...versionFields });
5013
+ function validateEventConfig(event2, ctx) {
4682
5014
  if (!validateExactlyOneDeclareAction(event2, ctx)) {
4683
5015
  return;
4684
5016
  }
@@ -4688,10 +5020,143 @@ var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
4688
5020
  validatePlaceOfEvent(event2, ctx);
4689
5021
  validateActionFlags(event2, ctx);
4690
5022
  validateActionOrder(event2, ctx);
4691
- }).meta({
5023
+ }
5024
+ var EventConfig2 = _EventConfigBase.superRefine(validateEventConfig).meta({
4692
5025
  id: "EventConfig",
4693
5026
  description: "Configuration defining an event type registered in OpenCRVS (for example birth or death)."
4694
5027
  });
5028
+ var INITIAL_EVENT_CONFIG_VERSION_ID = "initial";
5029
+ var DEFAULT_EFFECTIVE_FROM = "0001-01-01";
5030
+ var _EventConfigVersion = z35.object({
5031
+ id: z35.string().describe(
5032
+ 'Identifier of the version, unique within the event (e.g. "birth-v2").'
5033
+ ),
5034
+ label: TranslationConfig.describe(
5035
+ 'Name of the version, which the UI shows wherever it names the version. For example, "{event.configVersionLabel}" in the event summary.'
5036
+ ),
5037
+ effectiveFrom: z35.iso.date().default(DEFAULT_EFFECTIVE_FROM).describe(
5038
+ `Date (YYYY-MM-DD) from which this version is effective. A version without one is effective from the beginning of time ('${DEFAULT_EFFECTIVE_FROM}').`
5039
+ ),
5040
+ ...versionFields
5041
+ });
5042
+ var resolvedConfigs = /* @__PURE__ */ new WeakMap();
5043
+ function toEventConfig(config, version) {
5044
+ let resolvedVersions = resolvedConfigs.get(config);
5045
+ if (!resolvedVersions) {
5046
+ resolvedVersions = /* @__PURE__ */ new WeakMap();
5047
+ resolvedConfigs.set(config, resolvedVersions);
5048
+ }
5049
+ const cached = resolvedVersions.get(version);
5050
+ if (cached) {
5051
+ return cached;
5052
+ }
5053
+ const {
5054
+ id: _id,
5055
+ label: _label,
5056
+ effectiveFrom: _effectiveFrom,
5057
+ ...fields
5058
+ } = version;
5059
+ const resolved = {
5060
+ ...fields,
5061
+ id: config.id,
5062
+ label: config.label,
5063
+ advancedSearch: config.advancedSearch
5064
+ };
5065
+ resolvedVersions.set(version, resolved);
5066
+ return resolved;
5067
+ }
5068
+ function byEffectiveFrom(a, b) {
5069
+ return a.effectiveFrom.localeCompare(b.effectiveFrom);
5070
+ }
5071
+ function getVersionsInEffectOn(config, date) {
5072
+ return config.versions.filter(({ effectiveFrom }) => effectiveFrom <= date).sort(byEffectiveFrom);
5073
+ }
5074
+ function findVersionInEffectOn(config, date) {
5075
+ return getVersionsInEffectOn(config, date).at(-1);
5076
+ }
5077
+ function resolveEventConfigOnDate(config, date) {
5078
+ return toEventConfig(
5079
+ config,
5080
+ getOrThrow(
5081
+ findVersionInEffectOn(config, date),
5082
+ `Event '${config.id}' has no version in effect on ${date}`
5083
+ )
5084
+ );
5085
+ }
5086
+ function resolveEventConfigInTimeZone(config, timeZone, now2 = /* @__PURE__ */ new Date()) {
5087
+ return resolveEventConfigOnDate(config, toPlainDateInTimeZone(now2, timeZone));
5088
+ }
5089
+ function resolveEventConfig(config) {
5090
+ return resolveEventConfigInTimeZone(config, "UTC");
5091
+ }
5092
+ function validateVersionList(config, ctx) {
5093
+ const ids = /* @__PURE__ */ new Set();
5094
+ const versionIdByEffectiveFrom = /* @__PURE__ */ new Map();
5095
+ config.versions.forEach((version, index) => {
5096
+ if (ids.has(version.id)) {
5097
+ ctx.addIssue({
5098
+ code: "custom",
5099
+ message: `Event '${config.id}' has more than one version with id '${version.id}'. Each version must have a different id.`,
5100
+ path: ["versions", index, "id"]
5101
+ });
5102
+ }
5103
+ ids.add(version.id);
5104
+ const sameEffectiveFromId = versionIdByEffectiveFrom.get(
5105
+ version.effectiveFrom
5106
+ );
5107
+ if (sameEffectiveFromId !== void 0) {
5108
+ const versionIds = `'${sameEffectiveFromId}', '${version.id}'`;
5109
+ ctx.addIssue({
5110
+ code: "custom",
5111
+ 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.`,
5112
+ path: ["versions", index, "effectiveFrom"]
5113
+ });
5114
+ } else {
5115
+ versionIdByEffectiveFrom.set(version.effectiveFrom, version.id);
5116
+ }
5117
+ });
5118
+ }
5119
+ function validateEachVersion(ctx, events, validate2) {
5120
+ const reported = /* @__PURE__ */ new Set();
5121
+ events.forEach((event2, index) => {
5122
+ const addIssue = (issue) => {
5123
+ if (typeof issue === "string") {
5124
+ ctx.addIssue({
5125
+ code: "custom",
5126
+ message: issue,
5127
+ path: ["versions", index]
5128
+ });
5129
+ return;
5130
+ }
5131
+ const [field3] = issue.path ?? [];
5132
+ const isEventLevel = typeof field3 === "string" && field3 in eventLevelFields;
5133
+ const path = isEventLevel ? issue.path ?? [] : ["versions", index, ...issue.path ?? []];
5134
+ const key = JSON.stringify([path, issue.message]);
5135
+ if (reported.has(key)) {
5136
+ return;
5137
+ }
5138
+ reported.add(key);
5139
+ ctx.addIssue({ ...issue, path });
5140
+ };
5141
+ validate2(event2, { value: event2, addIssue });
5142
+ });
5143
+ }
5144
+ var VersionedEventConfig2 = z35.object({
5145
+ ...eventLevelFields,
5146
+ versions: z35.array(_EventConfigVersion).min(1).describe(
5147
+ `Versions of the event configuration, each effective from its \`effectiveFrom\`. An event configured without versions has a single version, with id '${INITIAL_EVENT_CONFIG_VERSION_ID}' and \`effectiveFrom\` '${DEFAULT_EFFECTIVE_FROM}'.`
5148
+ )
5149
+ }).superRefine((config, ctx) => {
5150
+ validateVersionList(config, ctx);
5151
+ validateEachVersion(
5152
+ ctx,
5153
+ config.versions.map((version) => toEventConfig(config, version)),
5154
+ validateEventConfig
5155
+ );
5156
+ }).meta({
5157
+ id: "VersionedEventConfig",
5158
+ description: "Configuration of an event type registered in OpenCRVS (for example birth or death), with every version of it."
5159
+ });
4695
5160
 
4696
5161
  // ../commons/src/events/EventConfigInput.ts
4697
5162
  var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
@@ -4790,7 +5255,10 @@ function eventFn(fieldId) {
4790
5255
  }
4791
5256
  var event = Object.assign(eventFn, {
4792
5257
  /**
4793
- * Checks if the event contains a specific action type.
5258
+ * Checks if the event contains a specific accepted action type.
5259
+ * Only Accepted actions are matched: a confirmable action is stored as a
5260
+ * Requested and an Accepted action, and a pending or rejected request must
5261
+ * not count as the action having happened.
4794
5262
  * Can be used directly as a conditional or chained with additional methods.
4795
5263
  * @param action - The action type to check for.
4796
5264
  */
@@ -4808,9 +5276,12 @@ var event = Object.assign(eventFn, {
4808
5276
  properties: {
4809
5277
  type: {
4810
5278
  const: action
5279
+ },
5280
+ status: {
5281
+ const: ActionStatus.Accepted
4811
5282
  }
4812
5283
  },
4813
- required: ["type"]
5284
+ required: ["type", "status"]
4814
5285
  }
4815
5286
  }
4816
5287
  },
@@ -4821,9 +5292,10 @@ var event = Object.assign(eventFn, {
4821
5292
  });
4822
5293
  const buildActionConstraints = (additionalFields) => {
4823
5294
  const actionProperties = {
4824
- type: { const: action }
5295
+ type: { const: action },
5296
+ status: { const: ActionStatus.Accepted }
4825
5297
  };
4826
- const requiredFields = ["type"];
5298
+ const requiredFields = ["type", "status"];
4827
5299
  if (additionalFields) {
4828
5300
  Object.entries(additionalFields).forEach(([key, value]) => {
4829
5301
  actionProperties[key] = { const: value };
@@ -5283,17 +5755,19 @@ var DraftInput = BaseActionInput.omit({ waitFor: true }).extend({
5283
5755
  /*
5284
5756
  * A draft can name a file that no action references. Such a file stays until
5285
5757
  * 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.
5758
+ * Drafts are therefore saved only on a created record, which can still be deleted.
5759
+ * The server refuses them on any other record.
5289
5760
  */
5290
- type: z40.literal(ActionTypes.enum.DECLARE),
5761
+ type: z40.enum([ActionTypes.enum.DECLARE, ActionTypes.enum.NOTIFY]),
5291
5762
  status: z40.enum([
5292
5763
  ActionStatus.Requested,
5293
5764
  ActionStatus.Accepted,
5294
5765
  ActionStatus.Rejected
5295
5766
  ])
5296
5767
  });
5768
+ var RemoteDraft = Draft.extend({
5769
+ action: Draft.shape.action.extend({ type: DraftInput.shape.type })
5770
+ });
5297
5771
 
5298
5772
  // ../commons/src/events/EventInput.ts
5299
5773
  var z41 = __toESM(require("zod/v4"));
@@ -5303,6 +5777,9 @@ var EventInput = z41.object({
5303
5777
  type: z41.string(),
5304
5778
  createdAtLocation: UUID.nullish().describe(
5305
5779
  "Location where the event occurred. Required for system users."
5780
+ ),
5781
+ configVersionId: z41.string().optional().describe(
5782
+ "Id of the event configuration version the client created the record under, e.g. while offline. Must be configured and not take effect in the future. Defaults to the version in effect when the server receives the record."
5306
5783
  )
5307
5784
  }).meta({ default: { transactionId: (0, import_uuid11.v4)(), type: "birth" } });
5308
5785
 
@@ -5318,6 +5795,9 @@ var EventDocument = z42.object({
5318
5795
  actions: z42.array(Action).describe("Ordered list of actions associated with the event."),
5319
5796
  trackingId: z42.string().describe(
5320
5797
  "System-generated tracking identifier used to look up the event."
5798
+ ),
5799
+ configVersionId: z42.string().describe(
5800
+ "Id of the event configuration version the record was created under. Every action on the record uses that version. Records created before versioning have 'initial'."
5321
5801
  )
5322
5802
  }).meta({ id: "EventDocument" });
5323
5803
  var EventDocumentOnlyLastAction = EventDocument.extend({
@@ -5337,16 +5817,69 @@ function moveDeclarationToDeclareAction({
5337
5817
  }
5338
5818
  return {
5339
5819
  ...config,
5340
- actions: config.actions.map(
5341
- (action) => action.type === ActionType.DECLARE && declaration ? { ...action, declaration } : action
5342
- )
5820
+ actions: config.actions.map((action) => {
5821
+ if (action.type !== ActionType.DECLARE) {
5822
+ return action;
5823
+ }
5824
+ const declarationOfAction = action.declaration ?? declaration;
5825
+ if (!declarationOfAction) {
5826
+ throw new Error(`Event '${config.id}' does not define \`declaration\`.`);
5827
+ }
5828
+ return { ...action, declaration: declarationOfAction };
5829
+ })
5343
5830
  };
5344
5831
  }
5832
+ var VERSIONED_EVENT_FIELDS = [
5833
+ "id",
5834
+ "label",
5835
+ "advancedSearch",
5836
+ "versions"
5837
+ ];
5838
+ function validateNoVersionFieldsAtTopLevel(config, ctx) {
5839
+ Object.keys(config).filter((key) => !VERSIONED_EVENT_FIELDS.includes(key)).forEach((key) => {
5840
+ ctx.addIssue({
5841
+ code: "custom",
5842
+ message: `Event '${config.id}' defines \`versions\`, so \`${key}\` must be defined on each version, not at the top level.`,
5843
+ path: [key]
5844
+ });
5845
+ });
5846
+ }
5847
+ function toVersionedInput(config) {
5848
+ if ("versions" in config) {
5849
+ return config;
5850
+ }
5851
+ const { id, label, advancedSearch, ...version } = moveDeclarationToDeclareAction(config);
5852
+ return {
5853
+ id,
5854
+ label,
5855
+ advancedSearch,
5856
+ versions: [{ ...version, id: INITIAL_EVENT_CONFIG_VERSION_ID, label }]
5857
+ };
5858
+ }
5859
+ var WESTERNMOST_TIME_ZONE = "Etc/GMT+12";
5860
+ function validateVersionInEffectToday(config, ctx) {
5861
+ const today = toPlainDateInTimeZone(/* @__PURE__ */ new Date(), WESTERNMOST_TIME_ZONE);
5862
+ const isAnyVersionInEffect = config.versions.some(
5863
+ ({ effectiveFrom }) => effectiveFrom <= today
5864
+ );
5865
+ if (!isAnyVersionInEffect) {
5866
+ ctx.addIssue({
5867
+ code: "custom",
5868
+ message: `Event '${config.id}' has no version in effect today (${today}, UTC\u221212, the last time zone to begin the day). At least one version must omit \`effectiveFrom\` or take effect on or before that date.`,
5869
+ path: ["versions"]
5870
+ });
5871
+ }
5872
+ }
5345
5873
  var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5346
- if (validateExactlyOneDeclareAction(config, ctx)) {
5347
- validateDeclarationGivenExactlyOnce(config, ctx);
5874
+ if ("versions" in config) {
5875
+ validateNoVersionFieldsAtTopLevel(config, ctx);
5876
+ return;
5348
5877
  }
5349
- }).transform(moveDeclarationToDeclareAction).pipe(EventConfig);
5878
+ const eventCtx = { ...ctx, value: config };
5879
+ if (validateExactlyOneDeclareAction(config, eventCtx)) {
5880
+ validateDeclarationGivenExactlyOnce(config, eventCtx);
5881
+ }
5882
+ }).transform(toVersionedInput).pipe(VersionedEventConfig2).superRefine(validateVersionInEffectToday);
5350
5883
  var defineConfig = (config) => EventConfigDefinition.parse(config);
5351
5884
 
5352
5885
  // ../commons/src/events/toNotificationForm.ts
@@ -6629,7 +7162,7 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
6629
7162
  });
6630
7163
 
6631
7164
  // ../commons/src/fixtures/tennis-club-membership-event.ts
6632
- var tennisClubMembershipEvent = defineConfig({
7165
+ var versionedTennisClubMembershipEvent = defineConfig({
6633
7166
  id: TENNIS_CLUB_MEMBERSHIP,
6634
7167
  declaration: TENNIS_CLUB_DECLARATION_FORM,
6635
7168
  label: {
@@ -6986,9 +7519,12 @@ var tennisClubMembershipEvent = defineConfig({
6986
7519
  }
6987
7520
  ]
6988
7521
  });
7522
+ var tennisClubMembershipEvent = resolveEventConfig(
7523
+ versionedTennisClubMembershipEvent
7524
+ );
6989
7525
 
6990
7526
  // ../commons/src/fixtures/football-club-membership-event.ts
6991
- var footballClubMembershipEvent = defineConfig({
7527
+ var versionedFootballClubMembershipEvent = defineConfig({
6992
7528
  id: "FOOTBALL_CLUB_MEMBERSHIP",
6993
7529
  label: {
6994
7530
  defaultMessage: "Football club membership application",
@@ -7311,6 +7847,9 @@ var footballClubMembershipEvent = defineConfig({
7311
7847
  ],
7312
7848
  declaration: TENNIS_CLUB_DECLARATION_FORM
7313
7849
  });
7850
+ var footballClubMembershipEvent = resolveEventConfig(
7851
+ versionedFootballClubMembershipEvent
7852
+ );
7314
7853
 
7315
7854
  // ../commons/src/fixtures/library-membership-event.ts
7316
7855
  var libraryMembershipForm = defineDeclarationForm({
@@ -7354,7 +7893,7 @@ var libraryMembershipForm = defineDeclarationForm({
7354
7893
  }
7355
7894
  ]
7356
7895
  });
7357
- var libraryMembershipEvent = defineConfig({
7896
+ var versionedLibraryMembershipEvent = defineConfig({
7358
7897
  id: "library-membership",
7359
7898
  label: {
7360
7899
  defaultMessage: "Library membership application",
@@ -7387,6 +7926,9 @@ var libraryMembershipEvent = defineConfig({
7387
7926
  ],
7388
7927
  declaration: libraryMembershipForm
7389
7928
  });
7929
+ var libraryMembershipEvent = resolveEventConfig(
7930
+ versionedLibraryMembershipEvent
7931
+ );
7390
7932
 
7391
7933
  // ../commons/src/fixtures/child-onboarding-event.ts
7392
7934
  function generateTranslationConfig(message) {
@@ -7600,7 +8142,7 @@ var CHILD_ONBOARDING_DECLARATION_FORM = defineDeclarationForm({
7600
8142
  label: generateTranslationConfig("Birth decalration form"),
7601
8143
  pages: [child, mother]
7602
8144
  });
7603
- var ChildOnboardingEvent = defineConfig({
8145
+ var versionedChildOnboardingEvent = defineConfig({
7604
8146
  id: CHILD_ONBOARDING_EVENT,
7605
8147
  title: generateTranslationConfig(
7606
8148
  "{child.name.firstname} {child.name.surname}"
@@ -7628,6 +8170,9 @@ var ChildOnboardingEvent = defineConfig({
7628
8170
  ],
7629
8171
  advancedSearch: []
7630
8172
  });
8173
+ var ChildOnboardingEvent = resolveEventConfig(
8174
+ versionedChildOnboardingEvent
8175
+ );
7631
8176
 
7632
8177
  // ../commons/src/fixtures/digital-identity-issuance-event.ts
7633
8178
  var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
@@ -7816,7 +8361,7 @@ var digitalIdentityForm = defineDeclarationForm({
7816
8361
  }
7817
8362
  ]
7818
8363
  });
7819
- var digitalIdentityEvent = defineConfig({
8364
+ var versionedDigitalIdentityEvent = defineConfig({
7820
8365
  id: "digital-identity",
7821
8366
  label: {
7822
8367
  defaultMessage: "Digital identity issuance",
@@ -7858,6 +8403,9 @@ var digitalIdentityEvent = defineConfig({
7858
8403
  ],
7859
8404
  declaration: digitalIdentityForm
7860
8405
  });
8406
+ var digitalIdentityEvent = resolveEventConfig(
8407
+ versionedDigitalIdentityEvent
8408
+ );
7861
8409
 
7862
8410
  // ../commons/src/events/test.utils.ts
7863
8411
  var z45 = __toESM(require("zod/v4"));
@@ -8324,6 +8872,8 @@ var ACTION_SCOPE_MAP = {
8324
8872
  "record.correct"
8325
8873
  ],
8326
8874
  [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
8875
+ // Not granted by a scope: the client checks the draft's own action instead
8876
+ [ClientSpecificAction.CONTINUE_DRAFT]: [],
8327
8877
  [ActionType.REJECT_CORRECTION]: ["record.correct"],
8328
8878
  [ActionType.APPROVE_CORRECTION]: ["record.correct"],
8329
8879
  [ActionType.REVOKE_REGISTRATION]: ["record.revoke-registration"],