@opencrvs/toolkit 2.1.2 → 2.2.0-rc.19ec10b

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 (177) hide show
  1. package/build.sh +9 -14
  2. package/create-countryconfig/package.json +1 -1
  3. package/dist/application-config/index.js +57 -14
  4. package/dist/authentication/index.d.ts +2 -1
  5. package/dist/authentication/index.js +34 -14
  6. package/dist/cli.js +1491 -2020
  7. package/dist/commons/api/router.d.ts +1564 -248
  8. package/dist/commons/application-config/index.d.ts +3 -3
  9. package/dist/commons/conditionals/conditionals.d.ts +58 -7
  10. package/dist/commons/conditionals/index.d.ts +1 -0
  11. package/dist/commons/conditionals/validate.d.ts +6 -1
  12. package/dist/commons/events/ActionConfig.d.ts +146 -20
  13. package/dist/commons/events/ActionDocument.d.ts +89 -0
  14. package/dist/commons/events/ActionInput.d.ts +56 -4
  15. package/dist/commons/events/ActionStatus.d.ts +2 -2
  16. package/dist/commons/events/ActionType.d.ts +13 -1
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -0
  18. package/dist/commons/events/AuditLog.d.ts +4 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  20. package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
  21. package/dist/commons/events/Draft.d.ts +36 -1
  22. package/dist/commons/events/EventConfig.d.ts +473 -6
  23. package/dist/commons/events/EventDocument.d.ts +90 -0
  24. package/dist/commons/events/EventIndex.d.ts +44 -6
  25. package/dist/commons/events/EventInput.d.ts +1 -0
  26. package/dist/commons/events/EventMetadata.d.ts +24 -1
  27. package/dist/commons/events/EventStatus.d.ts +1 -0
  28. package/dist/commons/events/FieldConfig.d.ts +11 -1
  29. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  30. package/dist/commons/events/Flag.d.ts +1 -7
  31. package/dist/commons/events/PlainDate.d.ts +6 -0
  32. package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
  33. package/dist/commons/events/defineConfig.d.ts +7 -2
  34. package/dist/commons/events/event.d.ts +20 -1
  35. package/dist/commons/events/eventConfigValidation.d.ts +26 -1
  36. package/dist/commons/events/field.d.ts +37 -0
  37. package/dist/commons/events/index.d.ts +3 -0
  38. package/dist/commons/events/locations.d.ts +1 -1
  39. package/dist/commons/events/scopes.d.ts +4 -1
  40. package/dist/commons/events/state/flags.d.ts +1 -1
  41. package/dist/commons/events/state/index.d.ts +11 -2
  42. package/dist/commons/events/state/utils.d.ts +11 -1
  43. package/dist/commons/events/test.utils.d.ts +89 -7
  44. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  45. package/dist/commons/events/utils.d.ts +90 -10
  46. package/dist/commons/users/Role.d.ts +23 -0
  47. package/dist/commons/users/User.d.ts +263 -0
  48. package/dist/commons/users/authentication.d.ts +67 -0
  49. package/dist/commons/users/index.d.ts +5 -0
  50. package/dist/commons/users/roleValidations.d.ts +15 -0
  51. package/dist/commons/users/scopes.d.ts +1402 -0
  52. package/dist/commons/users/userReferences.d.ts +176 -0
  53. package/dist/conditionals/index.js +29 -9
  54. package/dist/environment/custom-types.d.ts +1 -0
  55. package/dist/environment/custom-types.d.ts.map +1 -1
  56. package/dist/environment/derived-variables.d.ts +24 -4
  57. package/dist/environment/derived-variables.d.ts.map +1 -1
  58. package/dist/environment/derived-variables.js +27 -4
  59. package/dist/environment/questions.d.ts +42 -9
  60. package/dist/environment/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +71 -48
  62. package/dist/environment/registry.d.ts +15 -0
  63. package/dist/environment/registry.d.ts.map +1 -0
  64. package/dist/environment/registry.js +112 -0
  65. package/dist/environment/setup-environment.d.ts.map +1 -1
  66. package/dist/environment/setup-environment.js +165 -35
  67. package/dist/environment/templates.d.ts.map +1 -1
  68. package/dist/events/index.js +2050 -1156
  69. package/dist/migrations/add-notify-config.d.ts +40 -0
  70. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  71. package/dist/migrations/add-notify-config.js +249 -0
  72. package/dist/migrations/index.d.ts +9 -0
  73. package/dist/migrations/index.d.ts.map +1 -0
  74. package/dist/migrations/index.js +1306 -0
  75. package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
  76. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
  77. package/dist/migrations/move-declaration-to-declare-action.js +260 -0
  78. package/dist/migrations/{v2.1 → persistent}/add-translations.d.ts +7 -1
  79. package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
  80. package/dist/migrations/{v2.1 → persistent}/add-translations.js +14 -12
  81. package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
  82. package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
  83. package/dist/migrations/persistent/check-upgrade-path.js +105 -0
  84. package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
  85. package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
  86. package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
  87. package/dist/migrations/read-declaration-through-helper.d.ts +39 -0
  88. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
  89. package/dist/migrations/read-declaration-through-helper.js +199 -0
  90. package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
  91. package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
  92. package/dist/migrations/replace-incomplete-flag.js +126 -0
  93. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  94. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  95. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  96. package/dist/migrations/utils.d.ts +61 -0
  97. package/dist/migrations/utils.d.ts.map +1 -0
  98. package/dist/migrations/utils.js +218 -0
  99. package/dist/notification/index.js +1081 -209
  100. package/dist/roles/index.d.ts +2 -0
  101. package/dist/roles/index.d.ts.map +1 -0
  102. package/dist/roles/index.js +730 -0
  103. package/dist/scopes/index.d.ts +83 -100
  104. package/dist/scopes/index.js +29 -13
  105. package/dist/templates/charts-values/dependencies/values.yaml +6 -3
  106. package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -10
  107. package/dist/templates/charts-values/traefik/values.yaml +4 -3
  108. package/dist/verify/endpoints.d.ts +11 -0
  109. package/dist/verify/endpoints.d.ts.map +1 -1
  110. package/dist/verify/endpoints.js +21 -27
  111. package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
  112. package/package.json +5 -3
  113. package/tsconfig.build.tsbuildinfo +1 -1
  114. package/tsconfig.json +3 -5
  115. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
  116. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
  117. package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
  118. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
  119. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
  120. package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
  121. package/dist/migrations/v2.1/add-translations.d.ts.map +0 -1
  122. package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
  123. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
  124. package/dist/migrations/v2.1/enable-telemetry.js +0 -455
  125. package/dist/migrations/v2.1/index.d.ts +0 -6
  126. package/dist/migrations/v2.1/index.d.ts.map +0 -1
  127. package/dist/migrations/v2.1/index.js +0 -2170
  128. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -14
  129. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
  130. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
  131. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
  132. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
  133. package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
  134. package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
  135. package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
  136. package/dist/migrations/v2.1/remove-sentry.js +0 -354
  137. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
  138. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
  139. package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
  140. package/dist/migrations/v2.1/template-files.d.ts +0 -8
  141. package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
  142. package/dist/migrations/v2.1/template-files.js +0 -49
  143. package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -8
  144. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
  145. package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
  146. package/dist/templates/countryconfig-template/.tiltignore +0 -1
  147. package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
  148. package/dist/templates/countryconfig-template/Tiltfile +0 -112
  149. package/dist/templates/countryconfig-template/assets/README.md +0 -1
  150. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
  151. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
  152. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
  153. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
  154. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
  155. package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
  156. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
  157. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
  158. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
  159. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
  160. package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
  161. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
  162. package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
  163. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
  164. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
  165. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
  166. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
  167. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
  168. package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
  169. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
  170. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
  171. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
  172. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
  173. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
  174. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
  175. package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
  176. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
  177. package/opencrvs-toolkit-2.1.2.tgz +0 -0
@@ -38,16 +38,19 @@ __export(notification_exports, {
38
38
  triggerUserEventNotification: () => triggerUserEventNotification
39
39
  });
40
40
  module.exports = __toCommonJS(notification_exports);
41
- var z47 = __toESM(require("zod/v4"));
41
+ var z48 = __toESM(require("zod/v4"));
42
+
43
+ // ../commons/src/events/index.ts
44
+ var import_compile = require("zod/compile");
42
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
 
@@ -83,6 +86,8 @@ var ActionType = {
83
86
  REQUEST_CORRECTION: "REQUEST_CORRECTION",
84
87
  REJECT_CORRECTION: "REJECT_CORRECTION",
85
88
  APPROVE_CORRECTION: "APPROVE_CORRECTION",
89
+ REVOKE_REGISTRATION: "REVOKE_REGISTRATION",
90
+ REINSTATE_REGISTRATION: "REINSTATE_REGISTRATION",
86
91
  // General actions
87
92
  READ: "READ",
88
93
  ASSIGN: "ASSIGN",
@@ -102,6 +107,8 @@ var ConfirmableActions = [
102
107
  ActionType.REQUEST_CORRECTION,
103
108
  ActionType.APPROVE_CORRECTION,
104
109
  ActionType.REJECT_CORRECTION,
110
+ ActionType.REVOKE_REGISTRATION,
111
+ ActionType.REINSTATE_REGISTRATION,
105
112
  ActionType.CUSTOM
106
113
  ];
107
114
  var ActionTypes = z2.enum([
@@ -121,13 +128,17 @@ var ActionTypes = z2.enum([
121
128
  "REQUEST_CORRECTION",
122
129
  "REJECT_CORRECTION",
123
130
  "APPROVE_CORRECTION",
131
+ "REVOKE_REGISTRATION",
132
+ "REINSTATE_REGISTRATION",
124
133
  "READ",
125
134
  "ASSIGN",
126
135
  "UNASSIGN",
127
136
  "CUSTOM"
128
137
  ]);
129
138
  var ClientSpecificAction = {
130
- 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"
131
142
  };
132
143
  var declarationActionValues = [
133
144
  ActionTypes.enum.DECLARE,
@@ -162,7 +173,9 @@ var WorkqueueActionType = ActionTypes.extract([
162
173
  ActionType.ARCHIVE,
163
174
  ActionType.UNARCHIVE,
164
175
  ActionType.PRINT_CERTIFICATE,
165
- ActionType.REQUEST_CORRECTION
176
+ ActionType.REQUEST_CORRECTION,
177
+ ActionType.REVOKE_REGISTRATION,
178
+ ActionType.REINSTATE_REGISTRATION
166
179
  ]);
167
180
  var META_ACTIONS = [
168
181
  ActionType.ASSIGN,
@@ -178,7 +191,7 @@ var ActionStatus = {
178
191
  };
179
192
 
180
193
  // ../commons/src/events/Flag.ts
181
- var z5 = __toESM(require("zod/v4"));
194
+ var z5 = __toESM(require("zod"));
182
195
 
183
196
  // ../commons/src/events/TranslationConfig.ts
184
197
  var z3 = __toESM(require("zod/v4"));
@@ -247,7 +260,6 @@ var FieldConditional = z4.discriminatedUnion("type", [
247
260
 
248
261
  // ../commons/src/events/Flag.ts
249
262
  var InherentFlags = {
250
- INCOMPLETE: "incomplete",
251
263
  REJECTED: "rejected",
252
264
  CORRECTION_REQUESTED: "correction-requested",
253
265
  POTENTIAL_DUPLICATE: "potential-duplicate",
@@ -275,7 +287,7 @@ var CustomFlag = z5.string().refine((val) => !Object.values(InherentFlags).inclu
275
287
  message: `Custom flag cannot be one of the inherent flags: ${Object.values(
276
288
  InherentFlags
277
289
  ).join(", ")}`
278
- }).refine((val) => !ActionFlag.safeParse(val).success, {
290
+ }).refine((val) => !ActionFlag.validate(val), {
279
291
  message: "Custom flag cannot match the ActionFlag pattern (ActionType:ActionStatus)."
280
292
  }).describe("Custom flag identifier defined by the country config.");
281
293
  var Flag = ActionFlag.or(z5.enum(InherentFlags)).or(CustomFlag);
@@ -314,10 +326,11 @@ var EventStatus = z6.enum([
314
326
  "NOTIFIED",
315
327
  "DECLARED",
316
328
  "REGISTERED",
329
+ "REVOKED",
317
330
  "ARCHIVED"
318
331
  ]);
319
332
 
320
- // ../commons/src/scopes.ts
333
+ // ../commons/src/users/scopes.ts
321
334
  var JurisdictionFilter = z7.enum(["administrativeArea", "location", "all"]).describe(
322
335
  "Filters based on user jurisdiction relative to their office location in hierarchy."
323
336
  );
@@ -337,6 +350,8 @@ var RecordScopeTypeV2 = z7.enum([
337
350
  "record.print-certified-copies",
338
351
  "record.request-correction",
339
352
  "record.correct",
353
+ "record.revoke-registration",
354
+ "record.reinstate-registration",
340
355
  "record.unassign-others",
341
356
  "record.custom-action",
342
357
  "record.action.accept",
@@ -463,6 +478,8 @@ var ScopesWithFullOptions = RecordScopeTypeV2.extract([
463
478
  "record.read",
464
479
  "record.request-correction",
465
480
  "record.correct",
481
+ "record.revoke-registration",
482
+ "record.reinstate-registration",
466
483
  "record.unassign-others",
467
484
  "record.review-duplicates"
468
485
  ]);
@@ -586,7 +603,7 @@ var DEFAULT_SCOPE_OPTIONS = {
586
603
  registeredIn: JurisdictionFilter.enum.all
587
604
  };
588
605
 
589
- // ../commons/src/authentication.ts
606
+ // ../commons/src/users/authentication.ts
590
607
  var TokenUserType = z8.enum(["user", "system"]);
591
608
  var TokenWithBearer = z8.string().regex(/^Bearer\s/);
592
609
 
@@ -648,6 +665,8 @@ var EventActionEntrySchema = AuditLogEntryBase.extend({
648
665
  "event.actions.correction.request.request",
649
666
  "event.actions.correction.approve.request",
650
667
  "event.actions.correction.reject.request",
668
+ "event.actions.revoke_registration.request",
669
+ "event.actions.reinstate_registration.request",
651
670
  "event.actions.mark_as_duplicate.request",
652
671
  "event.actions.mark_as_not_duplicate.request"
653
672
  ]),
@@ -982,7 +1001,7 @@ var z14 = __toESM(require("zod/v4"));
982
1001
  // ../commons/src/documents.ts
983
1002
  var z11 = __toESM(require("zod/v4"));
984
1003
  var FullDocumentUrl = z11.string().brand("FullDocumentUrl").describe(
985
- "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"
986
1005
  );
987
1006
  var FullDocumentPath = z11.string().overwrite((val) => val.startsWith("/") ? val : `/${val}`).meta({ effectType: "input", type: "string" }).describe(
988
1007
  "A full absolute path with bucket name, starting from the root of the S3 server, /bucket-name/document-id.jpg"
@@ -992,7 +1011,7 @@ var DocumentPath = z11.string().brand("DocumentPath").describe(
992
1011
  );
993
1012
 
994
1013
  // ../commons/src/events/CompositeFieldValue.ts
995
- var z12 = __toESM(require("zod/v4"));
1014
+ var z12 = __toESM(require("zod"));
996
1015
  var AddressType = {
997
1016
  DOMESTIC: "DOMESTIC",
998
1017
  INTERNATIONAL: "INTERNATIONAL"
@@ -1089,6 +1108,26 @@ var CustomFieldValue = z12.unknown().brand("CustomFieldValue");
1089
1108
  // ../commons/src/events/PlainDate.ts
1090
1109
  var import_zod = require("zod");
1091
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
+ }
1092
1131
 
1093
1132
  // ../commons/src/events/FieldValue.ts
1094
1133
  var TextValue = z14.string();
@@ -1197,7 +1236,7 @@ function safeUnion(schemas) {
1197
1236
  );
1198
1237
  return z14.any().superRefine((val, ctx) => {
1199
1238
  for (const schema of sortedSchemas) {
1200
- if (schema.safeParse(val).success) {
1239
+ if (schema.validate(val)) {
1201
1240
  return;
1202
1241
  }
1203
1242
  }
@@ -1391,6 +1430,16 @@ var UnarchiveAction = ActionBase.extend(
1391
1430
  type: z16.literal(ActionType.UNARCHIVE)
1392
1431
  }).shape
1393
1432
  );
1433
+ var RevokeRegistrationAction = ActionBase.extend(
1434
+ z16.object({
1435
+ type: z16.literal(ActionType.REVOKE_REGISTRATION)
1436
+ }).shape
1437
+ );
1438
+ var ReinstateRegistrationAction = ActionBase.extend(
1439
+ z16.object({
1440
+ type: z16.literal(ActionType.REINSTATE_REGISTRATION)
1441
+ }).shape
1442
+ );
1394
1443
  var CreatedAction = ActionBase.extend(
1395
1444
  z16.object({
1396
1445
  type: z16.literal(ActionType.CREATE)
@@ -1459,6 +1508,8 @@ var ActionDocument = z16.discriminatedUnion("type", [
1459
1508
  MarkAsDuplicateAction.meta({ id: "MarkAsDuplicateAction" }),
1460
1509
  ArchiveAction.meta({ id: "ArchiveAction" }),
1461
1510
  UnarchiveAction.meta({ id: "UnarchiveAction" }),
1511
+ RevokeRegistrationAction.meta({ id: "RevokeRegistrationAction" }),
1512
+ ReinstateRegistrationAction.meta({ id: "ReinstateRegistrationAction" }),
1462
1513
  NotifiedAction.meta({ id: "NotifiedAction" }),
1463
1514
  RegisterAction.meta({ id: "RegisterAction" }),
1464
1515
  DeclareAction.meta({ id: "DeclareAction" }),
@@ -1507,11 +1558,15 @@ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
1507
1558
  var LegalStatuses = z17.object({
1508
1559
  [EventStatus.enum.NOTIFIED]: ActionCreationMetadata.nullish(),
1509
1560
  [EventStatus.enum.DECLARED]: ActionCreationMetadata.nullish(),
1510
- [EventStatus.enum.REGISTERED]: RegistrationCreationMetadata.nullish()
1561
+ [EventStatus.enum.REGISTERED]: RegistrationCreationMetadata.nullish(),
1562
+ [EventStatus.enum.REVOKED]: ActionCreationMetadata.nullish()
1511
1563
  });
1512
1564
  var EventMetadata = z17.object({
1513
1565
  id: UUID,
1514
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
+ ),
1515
1570
  status: EventStatus,
1516
1571
  legalStatuses: LegalStatuses.describe(
1517
1572
  "Metadata related to the legal registration of the event, such as who registered it and when."
@@ -1627,6 +1682,12 @@ var AnyOfStatus = import_v4.z.object({
1627
1682
  }).meta({
1628
1683
  id: "AnyOfStatus"
1629
1684
  });
1685
+ var NoneOfStatus = import_v4.z.object({
1686
+ type: import_v4.z.literal("noneOf"),
1687
+ terms: import_v4.z.array(EventStatus)
1688
+ }).meta({
1689
+ id: "NoneOfStatus"
1690
+ });
1630
1691
  var Range = import_v4.z.object({
1631
1692
  type: import_v4.z.literal("range"),
1632
1693
  gte: import_v4.z.string(),
@@ -1667,7 +1728,7 @@ var QueryInput = import_v4.z.lazy(
1667
1728
  var QueryExpression = import_v4.z.object({
1668
1729
  id: import_v4.z.optional(import_v4.z.string()),
1669
1730
  eventType: import_v4.z.string(),
1670
- status: import_v4.z.optional(import_v4.z.union([AnyOfStatus, ExactStatus])),
1731
+ status: import_v4.z.optional(import_v4.z.union([AnyOfStatus, NoneOfStatus, ExactStatus])),
1671
1732
  createdAt: import_v4.z.optional(DateCondition),
1672
1733
  updatedAt: import_v4.z.optional(DateCondition),
1673
1734
  "legalStatuses.DECLARED.createdAtLocation": import_v4.z.optional(Within).nullable(),
@@ -1676,6 +1737,7 @@ var QueryExpression = import_v4.z.object({
1676
1737
  "legalStatuses.REGISTERED.createdAtLocation": import_v4.z.optional(Within).nullable(),
1677
1738
  "legalStatuses.REGISTERED.createdByRole": import_v4.z.optional(AnyOf),
1678
1739
  "legalStatuses.REGISTERED.registrationNumber": import_v4.z.optional(Exact),
1740
+ "legalStatuses.REVOKED.createdAtLocation": import_v4.z.optional(Within).nullable(),
1679
1741
  createdAtLocation: import_v4.z.optional(import_v4.z.union([Within, Exact])),
1680
1742
  updatedAtLocation: import_v4.z.optional(import_v4.z.union([Within, Exact])),
1681
1743
  assignedTo: import_v4.z.optional(Exact),
@@ -2873,6 +2935,12 @@ var ReadActionConfig = ActionConfigBase.extend(
2873
2935
  var NotifyConfig = ActionConfigBase.extend(
2874
2936
  z25.object({
2875
2937
  type: z25.literal(ActionType.NOTIFY),
2938
+ notificationForm: DeclarationFormConfig.describe(
2939
+ "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."
2940
+ ),
2941
+ review: DeclarationReviewConfig.describe(
2942
+ "Review page configuration for the notify action. Values of its fields are stored as the NOTIFY action annotation."
2943
+ ),
2876
2944
  form: actionConfirmationForm
2877
2945
  }).shape
2878
2946
  );
@@ -2925,6 +2993,9 @@ var DeleteConfig = ActionConfigBase.extend(
2925
2993
  var DeclareConfig = DeclarationActionBase.extend(
2926
2994
  z25.object({
2927
2995
  type: z25.literal(ActionType.DECLARE),
2996
+ declaration: DeclarationFormConfig.describe(
2997
+ "Configuration of the form used to gather event data."
2998
+ ),
2928
2999
  review: DeclarationReviewConfig.describe(
2929
3000
  "Configuration of the review page fields."
2930
3001
  ),
@@ -2953,6 +3024,18 @@ var UnarchiveConfig = ActionConfigBase.extend(
2953
3024
  type: z25.literal(ActionType.UNARCHIVE)
2954
3025
  }).shape
2955
3026
  );
3027
+ var RevokeRegistrationConfig = ActionConfigBase.extend(
3028
+ z25.object({
3029
+ type: z25.literal(ActionType.REVOKE_REGISTRATION),
3030
+ form: actionConfirmationForm
3031
+ }).shape
3032
+ );
3033
+ var ReinstateRegistrationConfig = ActionConfigBase.extend(
3034
+ z25.object({
3035
+ type: z25.literal(ActionType.REINSTATE_REGISTRATION),
3036
+ form: actionConfirmationForm
3037
+ }).shape
3038
+ );
2956
3039
  var EditActionConfig = ActionConfigBase.extend(
2957
3040
  z25.object({
2958
3041
  type: z25.literal(ActionType.EDIT),
@@ -3039,11 +3122,11 @@ var ActionConfig = z25.discriminatedUnion("type", [
3039
3122
  }),
3040
3123
  NotifyConfig.meta({
3041
3124
  id: "NotifyActionConfig",
3042
- description: "Configuration for the notify action. When present, NOTIFY uses this config independently from DECLARE. When absent, NOTIFY falls back to 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."
3043
3126
  }),
3044
3127
  DeclareConfig.meta({
3045
3128
  id: "DeclareActionConfig",
3046
- description: "Configuration for the declare action. Includes review-page fields. NOTIFY falls back to this config when no dedicated NotifyActionConfig is provided."
3129
+ description: "Configuration for the declare action. Includes the declaration form and review-page fields."
3047
3130
  }),
3048
3131
  DuplicateDetectedConfig.meta({
3049
3132
  id: "DuplicateDetectedActionConfig",
@@ -3093,6 +3176,14 @@ var ActionConfig = z25.discriminatedUnion("type", [
3093
3176
  id: "UnarchiveActionConfig",
3094
3177
  description: "Configuration for unarchiving a record."
3095
3178
  }),
3179
+ RevokeRegistrationConfig.meta({
3180
+ id: "RevokeRegistrationActionConfig",
3181
+ description: "Configuration for revoking a registered record."
3182
+ }),
3183
+ ReinstateRegistrationConfig.meta({
3184
+ id: "ReinstateRegistrationActionConfig",
3185
+ description: "Configuration for reinstating a revoked record back to registered."
3186
+ }),
3096
3187
  CustomActionConfig.meta({
3097
3188
  id: "CustomActionConfig",
3098
3189
  description: "Configuration for a country-defined custom action. An event may include any number of these."
@@ -3299,7 +3390,7 @@ var ReferenceField = BaseField2.extend({
3299
3390
  var Field = BaseField2.extend({
3300
3391
  id: z29.string().describe("Identifier of the summary field."),
3301
3392
  value: TranslationConfig.describe(
3302
- '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.'
3303
3394
  ),
3304
3395
  label: TranslationConfig
3305
3396
  }).describe("Custom field defined for the summary view.");
@@ -3394,7 +3485,10 @@ var SearchQueryParams = z30.object({
3394
3485
  }).catchall(FieldValue);
3395
3486
  var FieldConfigSchema = BaseField3.extend({
3396
3487
  fieldId: z30.string(),
3397
- 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
+ )
3398
3492
  });
3399
3493
  var EventFieldIdInput = z30.enum([
3400
3494
  "trackingId",
@@ -3443,32 +3537,20 @@ var AdvancedSearchConfig = z30.object({
3443
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()`)."
3444
3538
  });
3445
3539
 
3446
- // ../commons/src/events/utils.ts
3447
- var import_lodash4 = require("lodash");
3448
-
3449
- // ../commons/src/conditionals/validate.ts
3450
- var import__ = __toESM(require("ajv/dist/2019"));
3451
- var import_ajv_formats = __toESM(require("ajv-formats"));
3452
- var z34 = __toESM(require("zod/v4"));
3453
- var import_date_fns2 = require("date-fns");
3454
-
3455
- // ../commons/src/events/FieldTypeMapping.ts
3456
- var z32 = __toESM(require("zod/v4"));
3457
-
3458
- // ../commons/src/events/DynamicFieldValue.ts
3459
- var z31 = __toESM(require("zod/v4"));
3460
-
3461
- // ../commons/src/events/state/index.ts
3462
- var import_lodash3 = require("lodash");
3463
-
3464
3540
  // ../commons/src/utils.ts
3465
- var z33 = __toESM(require("zod/v4"));
3541
+ var z31 = __toESM(require("zod/v4"));
3466
3542
  var _ = __toESM(require("lodash"));
3467
- var FullNameV1 = z33.array(
3468
- z33.object({
3469
- use: z33.string(),
3470
- family: z33.string(),
3471
- 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())
3472
3554
  })
3473
3555
  );
3474
3556
  function omitKeyDeep(obj, keyToRemove) {
@@ -3487,65 +3569,14 @@ function omitKeyDeep(obj, keyToRemove) {
3487
3569
  return newObj;
3488
3570
  }
3489
3571
 
3490
- // ../commons/src/events/state/utils.ts
3491
- var import_lodash = require("lodash");
3492
- var updateActions = new Set(
3493
- ActionTypes.extract([
3494
- ActionType.CREATE,
3495
- ActionType.NOTIFY,
3496
- ActionType.EDIT,
3497
- ActionType.DECLARE,
3498
- ActionType.REGISTER,
3499
- ActionType.REJECT,
3500
- ActionType.ARCHIVE,
3501
- ActionType.UNARCHIVE,
3502
- ActionType.PRINT_CERTIFICATE,
3503
- ActionType.REQUEST_CORRECTION,
3504
- ActionType.APPROVE_CORRECTION,
3505
- ActionType.REJECT_CORRECTION,
3506
- ActionType.CUSTOM
3507
- ]).options
3508
- );
3572
+ // ../commons/src/events/utils.ts
3573
+ var import_lodash4 = require("lodash");
3509
3574
 
3510
- // ../commons/src/events/state/flags.ts
3511
- var import_lodash2 = require("lodash");
3512
- var import_date_fns = require("date-fns");
3513
- var INHERENT_FLAG_RULES = [
3514
- {
3515
- flag: InherentFlags.CORRECTION_REQUESTED,
3516
- setOn: [ActionType.REQUEST_CORRECTION],
3517
- resetOn: [ActionType.APPROVE_CORRECTION, ActionType.REJECT_CORRECTION]
3518
- },
3519
- {
3520
- // INCOMPLETE mirrors the NOTIFIED status: set by NOTIFY, cleared by any
3521
- // other status-changing action (see getStatusFromActions). ARCHIVE/UNARCHIVE
3522
- // are deliberately excluded so the flag freezes across an archive/unarchive
3523
- // round trip and comes back exactly as it was.
3524
- flag: InherentFlags.INCOMPLETE,
3525
- setOn: [ActionType.NOTIFY],
3526
- resetOn: [ActionType.CREATE, ActionType.DECLARE, ActionType.REGISTER]
3527
- },
3528
- {
3529
- flag: InherentFlags.REJECTED,
3530
- setOn: [ActionType.REJECT],
3531
- resetOn: [
3532
- ActionType.NOTIFY,
3533
- ActionType.DECLARE,
3534
- ActionType.EDIT,
3535
- ActionType.REGISTER
3536
- ]
3537
- },
3538
- {
3539
- flag: InherentFlags.POTENTIAL_DUPLICATE,
3540
- setOn: [ActionType.DUPLICATE_DETECTED],
3541
- resetOn: [ActionType.MARK_AS_DUPLICATE, ActionType.MARK_AS_NOT_DUPLICATE]
3542
- },
3543
- {
3544
- flag: InherentFlags.EDIT_IN_PROGRESS,
3545
- setOn: [ActionType.EDIT],
3546
- resetOnAnyOtherAction: true
3547
- }
3548
- ];
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");
3549
3580
 
3550
3581
  // ../commons/src/conditionals/conditionals.ts
3551
3582
  var objectHash = __toESM(require("object-hash"));
@@ -3669,6 +3700,9 @@ var user = Object.assign(userSerializer, {
3669
3700
  function isFieldReference(value) {
3670
3701
  return typeof value === "object" && value !== null && "$$field" in value;
3671
3702
  }
3703
+ function isActionDateReference(value) {
3704
+ return typeof value === "object" && value !== null && "$action" in value;
3705
+ }
3672
3706
  function getDateRangeToFieldReference(field3, comparedField, clause) {
3673
3707
  return {
3674
3708
  type: "object",
@@ -3856,7 +3890,9 @@ function createFieldConditionals(fieldId) {
3856
3890
  },
3857
3891
  fromNow: () => {
3858
3892
  return defineFormConditional(getDayRange(this, days, "after"));
3859
- }
3893
+ },
3894
+ beforeAction: (action) => defineFormConditional(getDayRange(this, -days, "after", action)),
3895
+ afterAction: (action) => defineFormConditional(getDayRange(this, days, "after", action))
3860
3896
  }),
3861
3897
  date: (date) => {
3862
3898
  if (isFieldReference(date)) {
@@ -3897,7 +3933,9 @@ function createFieldConditionals(fieldId) {
3897
3933
  },
3898
3934
  fromNow: () => {
3899
3935
  return defineFormConditional(getDayRange(this, -days, "before"));
3900
- }
3936
+ },
3937
+ beforeAction: (action) => defineFormConditional(getDayRange(this, -days, "before", action)),
3938
+ afterAction: (action) => defineFormConditional(getDayRange(this, days, "before", action))
3901
3939
  }),
3902
3940
  date: (date) => {
3903
3941
  if (isFieldReference(date)) {
@@ -4181,6 +4219,206 @@ function createFieldConditionals(fieldId) {
4181
4219
  };
4182
4220
  }
4183
4221
 
4222
+ // ../commons/src/events/FieldTypeMapping.ts
4223
+ var z33 = __toESM(require("zod/v4"));
4224
+
4225
+ // ../commons/src/events/DynamicFieldValue.ts
4226
+ var z32 = __toESM(require("zod/v4"));
4227
+ function getDynamicNameValue(field3) {
4228
+ const nameConfiguration = field3.configuration?.name;
4229
+ const firstnameRequired = nameConfiguration?.firstname?.required ?? field3.required;
4230
+ const surnameRequired = nameConfiguration?.surname?.required ?? field3.required;
4231
+ return z32.object({
4232
+ firstname: firstnameRequired ? NonEmptyTextValue : TextValue,
4233
+ surname: surnameRequired ? NonEmptyTextValue : TextValue,
4234
+ middlename: nameConfiguration?.middlename?.required ? NonEmptyTextValue : TextValue.optional()
4235
+ });
4236
+ }
4237
+ function getDynamicAddressFieldValue(field3) {
4238
+ const schema = field3.required ? AddressFieldValue : AddressFieldUpdateValue;
4239
+ const configIds = field3.configuration?.streetAddressForm?.map((a) => a.id) ?? [];
4240
+ return schema.refine((arg) => {
4241
+ if (!arg) {
4242
+ return true;
4243
+ }
4244
+ const submittedKeys = Object.keys(arg.streetLevelDetails ?? {});
4245
+ const invalidKeys = submittedKeys.filter((k) => !configIds.includes(k));
4246
+ if (invalidKeys.length) {
4247
+ console.log(
4248
+ "Invalid streetLevelDetails: unknown keys",
4249
+ JSON.stringify(invalidKeys, null, 2)
4250
+ );
4251
+ return false;
4252
+ }
4253
+ return true;
4254
+ });
4255
+ }
4256
+
4257
+ // ../commons/src/events/FieldTypeMapping.ts
4258
+ function mapFieldTypeToZod(field3, actionType) {
4259
+ let schema;
4260
+ switch (field3.type) {
4261
+ case FieldType.FIELD_GROUP: {
4262
+ schema = z33.object(
4263
+ field3.fields.reduce((acc, subfield) => {
4264
+ acc[subfield.id] = mapFieldTypeToZod(subfield, actionType);
4265
+ return acc;
4266
+ }, {})
4267
+ );
4268
+ break;
4269
+ }
4270
+ case FieldType.DATE:
4271
+ schema = PlainDate;
4272
+ break;
4273
+ case FieldType.AGE:
4274
+ schema = AgeValue;
4275
+ break;
4276
+ case FieldType.TIME:
4277
+ schema = TimeValue;
4278
+ break;
4279
+ case FieldType.EMAIL:
4280
+ schema = EmailValue;
4281
+ break;
4282
+ case FieldType.DATE_RANGE:
4283
+ schema = DateRangeFieldValue;
4284
+ break;
4285
+ case FieldType.SELECT_DATE_RANGE:
4286
+ schema = SelectDateRangeValue;
4287
+ break;
4288
+ case FieldType.TEXT:
4289
+ case FieldType.TEXTAREA:
4290
+ case FieldType.DIVIDER:
4291
+ case FieldType.BULLET_LIST:
4292
+ case FieldType.PAGE_HEADER:
4293
+ case FieldType.LOCATION:
4294
+ case FieldType.SELECT:
4295
+ case FieldType.COUNTRY:
4296
+ case FieldType.RADIO_GROUP:
4297
+ case FieldType.PARAGRAPH:
4298
+ case FieldType.HEADING:
4299
+ case FieldType.IMAGE_VIEW:
4300
+ case FieldType.ADMINISTRATIVE_AREA:
4301
+ case FieldType.FACILITY:
4302
+ case FieldType.OFFICE:
4303
+ case FieldType.PHONE:
4304
+ case FieldType.LINK_BUTTON:
4305
+ case FieldType.VERIFICATION_STATUS:
4306
+ case FieldType.ID:
4307
+ case FieldType.LOADER:
4308
+ case FieldType.ALPHA_HIDDEN:
4309
+ case FieldType.USER_ROLE:
4310
+ schema = field3.required ? NonEmptyTextValue : TextValue;
4311
+ break;
4312
+ case FieldType.NUMBER:
4313
+ schema = NumberFieldValue;
4314
+ break;
4315
+ case FieldType.NUMBER_WITH_UNIT:
4316
+ schema = field3.required ? NumberWithUnitFieldValue : NumberWithUnitFieldUpdateValue;
4317
+ break;
4318
+ case FieldType.CHECKBOX:
4319
+ schema = CheckboxFieldValue;
4320
+ break;
4321
+ case FieldType.SIGNATURE:
4322
+ case FieldType.FILE:
4323
+ schema = FileFieldValue;
4324
+ break;
4325
+ case FieldType.FILE_WITH_OPTIONS:
4326
+ schema = field3.required ? FileFieldWithOptionValue.min(1) : FileFieldWithOptionValue;
4327
+ break;
4328
+ case FieldType.ADDRESS:
4329
+ schema = getDynamicAddressFieldValue(field3);
4330
+ break;
4331
+ case FieldType.DATA:
4332
+ schema = DataFieldValue;
4333
+ break;
4334
+ case FieldType.NAME:
4335
+ schema = actionType === ActionType.NOTIFY ? NameFieldUpdateValue : getDynamicNameValue(field3);
4336
+ break;
4337
+ case FieldType.BUTTON:
4338
+ schema = ButtonFieldValue;
4339
+ break;
4340
+ case FieldType.ALPHA_PRINT_BUTTON:
4341
+ schema = TextValue;
4342
+ break;
4343
+ case FieldType.AUTOCOMPLETE:
4344
+ schema = AutocompleteValue;
4345
+ break;
4346
+ case FieldType.HTTP:
4347
+ case FieldType.SEARCH:
4348
+ schema = HttpFieldUpdateValue;
4349
+ break;
4350
+ case FieldType.QUERY_PARAM_READER:
4351
+ schema = QueryParamReaderFieldUpdateValue;
4352
+ break;
4353
+ case FieldType.QR_READER:
4354
+ schema = QrReaderFieldValue;
4355
+ break;
4356
+ case FieldType.ID_READER:
4357
+ schema = IdReaderFieldValue;
4358
+ break;
4359
+ case FieldType._EXPERIMENTAL_CUSTOM:
4360
+ schema = CustomFieldValue;
4361
+ break;
4362
+ }
4363
+ return field3.required ? schema : schema.nullish();
4364
+ }
4365
+
4366
+ // ../commons/src/events/state/index.ts
4367
+ var import_lodash3 = require("lodash");
4368
+
4369
+ // ../commons/src/events/state/utils.ts
4370
+ var import_lodash = require("lodash");
4371
+ var updateActions = new Set(
4372
+ ActionTypes.extract([
4373
+ ActionType.CREATE,
4374
+ ActionType.NOTIFY,
4375
+ ActionType.EDIT,
4376
+ ActionType.DECLARE,
4377
+ ActionType.REGISTER,
4378
+ ActionType.REJECT,
4379
+ ActionType.ARCHIVE,
4380
+ ActionType.UNARCHIVE,
4381
+ ActionType.PRINT_CERTIFICATE,
4382
+ ActionType.REQUEST_CORRECTION,
4383
+ ActionType.APPROVE_CORRECTION,
4384
+ ActionType.REJECT_CORRECTION,
4385
+ ActionType.REVOKE_REGISTRATION,
4386
+ ActionType.REINSTATE_REGISTRATION,
4387
+ ActionType.CUSTOM
4388
+ ]).options
4389
+ );
4390
+
4391
+ // ../commons/src/events/state/flags.ts
4392
+ var import_lodash2 = require("lodash");
4393
+ var import_date_fns = require("date-fns");
4394
+ var INHERENT_FLAG_RULES = [
4395
+ {
4396
+ flag: InherentFlags.CORRECTION_REQUESTED,
4397
+ setOn: [ActionType.REQUEST_CORRECTION],
4398
+ resetOn: [ActionType.APPROVE_CORRECTION, ActionType.REJECT_CORRECTION]
4399
+ },
4400
+ {
4401
+ flag: InherentFlags.REJECTED,
4402
+ setOn: [ActionType.REJECT],
4403
+ resetOn: [
4404
+ ActionType.NOTIFY,
4405
+ ActionType.DECLARE,
4406
+ ActionType.EDIT,
4407
+ ActionType.REGISTER
4408
+ ]
4409
+ },
4410
+ {
4411
+ flag: InherentFlags.POTENTIAL_DUPLICATE,
4412
+ setOn: [ActionType.DUPLICATE_DETECTED],
4413
+ resetOn: [ActionType.MARK_AS_DUPLICATE, ActionType.MARK_AS_NOT_DUPLICATE]
4414
+ },
4415
+ {
4416
+ flag: InherentFlags.EDIT_IN_PROGRESS,
4417
+ setOn: [ActionType.EDIT],
4418
+ resetOnAnyOtherAction: true
4419
+ }
4420
+ ];
4421
+
4184
4422
  // ../commons/src/conditionals/validate.ts
4185
4423
  var ajv = new import__.default({
4186
4424
  $data: true,
@@ -4214,6 +4452,15 @@ function resolveDataPath(rootData, dataPath, instancePath) {
4214
4452
  }
4215
4453
  return current;
4216
4454
  }
4455
+ function resolveActionDate(event2, { match, occurrence }) {
4456
+ const dates = (event2?.actions ?? []).filter(({ status: status2 }) => status2 === ActionStatus.Accepted).filter(
4457
+ (action) => match.some(
4458
+ ({ type, customActionType }) => action.type === type && (!customActionType || "customActionType" in action && action.customActionType === customActionType)
4459
+ )
4460
+ ).map(({ createdAt }) => createdAt).sort();
4461
+ const date = occurrence === "first" ? dates[0] : dates[dates.length - 1];
4462
+ return date && (0, import_date_fns2.formatISO)((0, import_date_fns2.parseISO)(date), { representation: "date" });
4463
+ }
4217
4464
  function todayISO() {
4218
4465
  return (0, import_date_fns2.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
4219
4466
  }
@@ -4235,7 +4482,9 @@ function buildClientFunctionContext(input) {
4235
4482
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
4236
4483
  $online: isOnline(),
4237
4484
  $user: input.validatorContext?.user,
4238
- $event: input.validatorContext?.event?.document,
4485
+ $event: input.validatorContext?.event?.document ? getEventWithCompleteAcceptedActions(
4486
+ input.validatorContext.event.document
4487
+ ) : void 0,
4239
4488
  $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
4240
4489
  user: input.systemVariables?.user,
4241
4490
  $window: input.systemVariables?.$window,
@@ -4265,6 +4514,10 @@ ajv.addKeyword({
4265
4514
  return false;
4266
4515
  }
4267
4516
  let referenceDate = schema.referenceDate;
4517
+ if (isActionDateReference(referenceDate)) {
4518
+ const rootData = dataContext.rootData;
4519
+ referenceDate = resolveActionDate(rootData.$event, referenceDate.$action);
4520
+ }
4268
4521
  if (referenceDate && typeof referenceDate === "object" && "$data" in referenceDate) {
4269
4522
  referenceDate = resolveDataPath(
4270
4523
  dataContext.rootData,
@@ -4322,8 +4575,28 @@ function isOnline() {
4322
4575
 
4323
4576
  // ../commons/src/events/utils.ts
4324
4577
  var import_date_fns3 = require("date-fns");
4578
+ function getDeclaration(configuration) {
4579
+ const declareAction = configuration.actions.find(
4580
+ (action) => action.type === ActionType.DECLARE
4581
+ );
4582
+ if (!declareAction) {
4583
+ throw new Error(
4584
+ `Event '${configuration.id}' has no ${ActionType.DECLARE} action to read the declaration from`
4585
+ );
4586
+ }
4587
+ return declareAction.declaration;
4588
+ }
4589
+ function getDeclarationPages(configuration) {
4590
+ return getDeclaration(configuration).pages;
4591
+ }
4325
4592
  function getDeclarationFields(configuration) {
4326
- return configuration.declaration.pages.flatMap(({ fields }) => fields);
4593
+ return getDeclarationPages(configuration).flatMap(({ fields }) => fields);
4594
+ }
4595
+ function findNotificationForm(configuration) {
4596
+ const notifyAction = configuration.actions.find(
4597
+ (action) => action.type === ActionType.NOTIFY
4598
+ );
4599
+ return notifyAction?.type === ActionType.NOTIFY ? notifyAction.notificationForm : void 0;
4327
4600
  }
4328
4601
  var getActionAnnotationFields = (actionConfig) => {
4329
4602
  if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
@@ -4339,12 +4612,108 @@ var getActionAnnotationFields = (actionConfig) => {
4339
4612
  function getAllAnnotationFields(config) {
4340
4613
  return (0, import_lodash4.flattenDeep)(config.actions.map(getActionAnnotationFields));
4341
4614
  }
4615
+ function deepMerge(currentDocument, actionDocument) {
4616
+ return (0, import_lodash4.mergeWith)(
4617
+ (0, import_lodash4.cloneDeep)(currentDocument),
4618
+ actionDocument,
4619
+ (previousValue, incomingValue) => {
4620
+ if (incomingValue === void 0) {
4621
+ return previousValue;
4622
+ }
4623
+ if ((0, import_lodash4.isArray)(incomingValue)) {
4624
+ return incomingValue;
4625
+ }
4626
+ if ((0, import_lodash4.isObject)(previousValue) && (0, import_lodash4.isObject)(incomingValue)) {
4627
+ return void 0;
4628
+ }
4629
+ return incomingValue;
4630
+ }
4631
+ );
4632
+ }
4342
4633
  var findAllFields = (config) => {
4343
4634
  return (0, import_lodash4.flattenDeep)([
4344
4635
  ...getDeclarationFields(config),
4636
+ ...findNotificationForm(config)?.pages.flatMap(({ fields }) => fields) ?? [],
4345
4637
  ...getAllAnnotationFields(config)
4346
4638
  ]);
4347
4639
  };
4640
+ function isAcceptedAction(a) {
4641
+ return a.status === ActionStatus.Accepted;
4642
+ }
4643
+ function getCompleteActionAnnotation(event2, action) {
4644
+ if (action.originalActionId) {
4645
+ const originalAction = event2.actions.find(
4646
+ ({ id }) => id === action.originalActionId
4647
+ );
4648
+ if (originalAction?.status === ActionStatus.Requested) {
4649
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4650
+ }
4651
+ }
4652
+ return action.annotation ?? {};
4653
+ }
4654
+ function getCompleteActionContent(event2, action) {
4655
+ const currentContent = "content" in action ? action.content : void 0;
4656
+ if (!action.originalActionId) {
4657
+ return currentContent;
4658
+ }
4659
+ const originalAction = event2.actions.find(
4660
+ ({ id }) => id === action.originalActionId
4661
+ );
4662
+ if (originalAction && "content" in originalAction && originalAction.content) {
4663
+ return {
4664
+ ...originalAction.content,
4665
+ ...currentContent ?? {}
4666
+ };
4667
+ }
4668
+ return currentContent;
4669
+ }
4670
+ function getCompleteActionDeclaration(declaration, event2, action) {
4671
+ if (action.originalActionId) {
4672
+ const originalAction = event2.actions.find(
4673
+ ({ id }) => id === action.originalActionId
4674
+ );
4675
+ if (originalAction?.status === ActionStatus.Requested) {
4676
+ return deepMerge(
4677
+ deepMerge(declaration, originalAction.declaration),
4678
+ action.declaration
4679
+ );
4680
+ }
4681
+ }
4682
+ return deepMerge(declaration, action.declaration);
4683
+ }
4684
+ function completeAcceptedAction(event2, action) {
4685
+ return {
4686
+ ...action,
4687
+ declaration: getCompleteActionDeclaration({}, event2, action),
4688
+ annotation: getCompleteActionAnnotation(event2, action)
4689
+ };
4690
+ }
4691
+ function getEventWithCompleteAcceptedActions(event2) {
4692
+ return {
4693
+ ...event2,
4694
+ actions: event2.actions.map((action) => {
4695
+ if (!isAcceptedAction(action) || !action.originalActionId) {
4696
+ return action;
4697
+ }
4698
+ const requestedAction = event2.actions.find(
4699
+ ({ id }) => id === action.originalActionId
4700
+ );
4701
+ if (requestedAction?.status !== ActionStatus.Requested) {
4702
+ return action;
4703
+ }
4704
+ const content = getCompleteActionContent(event2, action);
4705
+ return {
4706
+ ...completeAcceptedAction(event2, action),
4707
+ // Who requested the action, as getActionUpdateMetadata resolves it.
4708
+ createdBy: requestedAction.createdBy,
4709
+ createdByRole: requestedAction.createdByRole,
4710
+ createdByUserType: requestedAction.createdByUserType,
4711
+ createdAtLocation: requestedAction.createdAtLocation,
4712
+ ...content ? { content } : {}
4713
+ };
4714
+ })
4715
+ };
4716
+ }
4348
4717
  var EXCLUDED_ACTIONS = [
4349
4718
  ActionType.REQUEST_CORRECTION,
4350
4719
  ActionType.PRINT_CERTIFICATE,
@@ -4352,6 +4721,20 @@ var EXCLUDED_ACTIONS = [
4352
4721
  ];
4353
4722
 
4354
4723
  // ../commons/src/events/eventConfigValidation.ts
4724
+ var SEARCH_DEFAULT_VALUE_FIELD_TYPES = [
4725
+ FieldType.TEXT,
4726
+ FieldType.TEXTAREA,
4727
+ FieldType.EMAIL,
4728
+ FieldType.PHONE,
4729
+ FieldType.ID,
4730
+ FieldType.SELECT,
4731
+ FieldType.RADIO_GROUP,
4732
+ FieldType.COUNTRY,
4733
+ FieldType.LOCATION,
4734
+ FieldType.ADMINISTRATIVE_AREA,
4735
+ FieldType.NUMBER,
4736
+ FieldType.DATE
4737
+ ];
4355
4738
  function validateAdvancedSearchConfig(event2, ctx) {
4356
4739
  const allFields = findAllFields(event2);
4357
4740
  const fieldIds = allFields.map((field3) => field3.id);
@@ -4383,6 +4766,56 @@ function validateAdvancedSearchConfig(event2, ctx) {
4383
4766
  path: ["advancedSearch"]
4384
4767
  });
4385
4768
  }
4769
+ event2.advancedSearch.forEach((section, sectionIndex) => {
4770
+ section.fields.forEach((searchField, fieldIndex) => {
4771
+ if (searchField.fieldType !== "field" || searchField.defaultValue === void 0) {
4772
+ return;
4773
+ }
4774
+ const path = [
4775
+ "advancedSearch",
4776
+ sectionIndex,
4777
+ "fields",
4778
+ fieldIndex,
4779
+ "defaultValue"
4780
+ ];
4781
+ if (searchField.config.searchFields && searchField.config.searchFields.length > 0) {
4782
+ ctx.addIssue({
4783
+ code: "custom",
4784
+ message: `Advanced search field ${searchField.fieldId} searches across several form fields, so it does not support a defaultValue.`,
4785
+ path
4786
+ });
4787
+ return;
4788
+ }
4789
+ if (typeof searchField.defaultValue === "boolean") {
4790
+ return;
4791
+ }
4792
+ const formField = allFields.find(({ id }) => id === searchField.fieldId);
4793
+ if (!formField) {
4794
+ return;
4795
+ }
4796
+ if (!SEARCH_DEFAULT_VALUE_FIELD_TYPES.some(
4797
+ (type) => type === formField.type
4798
+ )) {
4799
+ ctx.addIssue({
4800
+ code: "custom",
4801
+ 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(", ")}.`,
4802
+ path
4803
+ });
4804
+ } else if (formField.type === FieldType.DATE && searchField.config.type === "range") {
4805
+ ctx.addIssue({
4806
+ code: "custom",
4807
+ message: `Advanced search field ${searchField.fieldId} is searched as a date range, so its defaultValue can only be true or false.`,
4808
+ path
4809
+ });
4810
+ } else if (!mapFieldTypeToZod(formField).safeParse(searchField.defaultValue).success) {
4811
+ ctx.addIssue({
4812
+ code: "custom",
4813
+ message: `Advanced search field ${searchField.fieldId} has defaultValue "${searchField.defaultValue}", which is not a valid ${formField.type} value.`,
4814
+ path
4815
+ });
4816
+ }
4817
+ });
4818
+ });
4386
4819
  }
4387
4820
  function validateDateOfEvent(event2, ctx) {
4388
4821
  if (event2.dateOfEvent && isFieldReference(event2.dateOfEvent)) {
@@ -4469,15 +4902,102 @@ function validateActionOrder(event2, ctx) {
4469
4902
  }
4470
4903
  }
4471
4904
  }
4905
+ function validateExactlyOneDeclareAction(event2, ctx) {
4906
+ const declareActionCount = event2.actions.filter(
4907
+ (action) => action.type === ActionType.DECLARE
4908
+ ).length;
4909
+ if (declareActionCount !== 1) {
4910
+ ctx.addIssue({
4911
+ code: "custom",
4912
+ message: `Event must have exactly one ${ActionType.DECLARE} action. Found ${declareActionCount} for event ${event2.id}`,
4913
+ path: ["actions"]
4914
+ });
4915
+ return false;
4916
+ }
4917
+ return true;
4918
+ }
4919
+ function validateDeclarationGivenExactlyOnce(config, ctx) {
4920
+ const declareActionIndex = config.actions.findIndex(
4921
+ (action) => action.type === ActionType.DECLARE
4922
+ );
4923
+ const declareAction = config.actions[declareActionIndex];
4924
+ const onDeclareAction = declareAction.type === ActionType.DECLARE && !!declareAction.declaration;
4925
+ const onTopLevel = !!config.declaration;
4926
+ const declareActionPath = `actions[${declareActionIndex}].declaration`;
4927
+ if (onTopLevel && onDeclareAction) {
4928
+ ctx.addIssue({
4929
+ code: "custom",
4930
+ message: `Event '${config.id}' defines \`declaration\` both at the top level and on the ${ActionType.DECLARE} action (\`${declareActionPath}\`). Define it in only one of these places.`,
4931
+ path: ["declaration"]
4932
+ });
4933
+ }
4934
+ if (!onTopLevel && !onDeclareAction) {
4935
+ ctx.addIssue({
4936
+ code: "custom",
4937
+ message: `Event '${config.id}' does not define \`declaration\`. Define it either at the top level or on the ${ActionType.DECLARE} action (\`${declareActionPath}\`).`,
4938
+ path: ["declaration"]
4939
+ });
4940
+ }
4941
+ }
4942
+ function validateNotificationForm(event2, ctx) {
4943
+ const declarationFields = getDeclarationPages(event2).flatMap(
4944
+ (page) => page.fields.map((field3) => ({ field: field3, pageId: page.id }))
4945
+ );
4946
+ event2.actions.forEach((action, actionIndex) => {
4947
+ if (action.type !== ActionType.NOTIFY) {
4948
+ return;
4949
+ }
4950
+ action.notificationForm.pages.forEach((page, pageIndex) => {
4951
+ page.fields.forEach((field3, fieldIndex) => {
4952
+ const path = [
4953
+ "actions",
4954
+ actionIndex,
4955
+ "notificationForm",
4956
+ "pages",
4957
+ pageIndex,
4958
+ "fields",
4959
+ fieldIndex
4960
+ ];
4961
+ const matchingFields = declarationFields.filter(
4962
+ (declarationField) => declarationField.field.id === field3.id
4963
+ );
4964
+ if (matchingFields.length === 0) {
4965
+ ctx.addIssue({
4966
+ code: "custom",
4967
+ message: `Notification form field '${field3.id}' does not exist in the declaration form of event '${event2.id}'. Notification form fields must also be defined in the ${ActionType.DECLARE} action's declaration.`,
4968
+ path
4969
+ });
4970
+ return;
4971
+ }
4972
+ if (!matchingFields.some(
4973
+ (declarationField) => declarationField.field.type === field3.type
4974
+ )) {
4975
+ const [declarationField] = matchingFields;
4976
+ ctx.addIssue({
4977
+ code: "custom",
4978
+ 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}.`,
4979
+ path
4980
+ });
4981
+ }
4982
+ });
4983
+ });
4984
+ });
4985
+ }
4472
4986
 
4473
4987
  // ../commons/src/events/EventConfig.ts
4474
4988
  var EventFieldReference = z35.object({ $$event: EventMetadataDateFieldIdInput }).describe(
4475
4989
  "Reference to a field defined in the event metadata, using the field id."
4476
4990
  );
4477
- var _EventConfigBase = z35.object({
4991
+ var eventLevelFields = {
4478
4992
  id: z35.string().describe(
4479
4993
  'Machine-readable identifier of the event (e.g. "birth", "death").'
4480
4994
  ),
4995
+ label: TranslationConfig.describe("Human-readable label for the event type."),
4996
+ advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4997
+ "Configuration of fields available in the advanced search feature."
4998
+ )
4999
+ };
5000
+ var versionFields = {
4481
5001
  dateOfEvent: FieldReference.or(EventFieldReference).optional().describe(
4482
5002
  "Reference to the field capturing the date of the event (e.g. date of birth). Defaults to the event creation date if unspecified."
4483
5003
  ),
@@ -4493,19 +5013,12 @@ var _EventConfigBase = z35.object({
4493
5013
  summary: SummaryConfig.describe(
4494
5014
  "Summary information displayed in the event overview."
4495
5015
  ),
4496
- label: TranslationConfig.describe("Human-readable label for the event type."),
4497
5016
  actions: z35.array(ActionConfig).describe(
4498
5017
  "Configuration of core and custom actions associated with the event."
4499
5018
  ),
4500
5019
  actionOrder: z35.array(z35.string()).optional().describe(
4501
5020
  "Order of actions in the action menu. Use either the action type for core actions or the customActionType for custom actions."
4502
5021
  ),
4503
- declaration: DeclarationFormConfig.describe(
4504
- "Configuration of the form used to gather event data."
4505
- ),
4506
- advancedSearch: z35.array(AdvancedSearchConfig).optional().default([]).describe(
4507
- "Configuration of fields available in the advanced search feature."
4508
- ),
4509
5022
  flags: z35.array(FlagConfig).optional().default([]).describe(
4510
5023
  "Configuration of custom flags associated with the actions of this event type."
4511
5024
  ),
@@ -4515,17 +5028,155 @@ var _EventConfigBase = z35.object({
4515
5028
  icon: z35.partialRecord(AvailableIcons, Conditional).optional().describe(
4516
5029
  '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.'
4517
5030
  )
4518
- });
4519
- var EventConfig = _EventConfigBase.superRefine((event2, ctx) => {
5031
+ };
5032
+ var _EventConfigBase = z35.object({ ...eventLevelFields, ...versionFields });
5033
+ function validateEventConfig(event2, ctx) {
5034
+ if (!validateExactlyOneDeclareAction(event2, ctx)) {
5035
+ return;
5036
+ }
5037
+ validateNotificationForm(event2, ctx);
4520
5038
  validateAdvancedSearchConfig(event2, ctx);
4521
5039
  validateDateOfEvent(event2, ctx);
4522
5040
  validatePlaceOfEvent(event2, ctx);
4523
5041
  validateActionFlags(event2, ctx);
4524
5042
  validateActionOrder(event2, ctx);
4525
- }).meta({
5043
+ }
5044
+ var EventConfig2 = _EventConfigBase.superRefine(validateEventConfig).meta({
4526
5045
  id: "EventConfig",
4527
5046
  description: "Configuration defining an event type registered in OpenCRVS (for example birth or death)."
4528
5047
  });
5048
+ var INITIAL_EVENT_CONFIG_VERSION_ID = "initial";
5049
+ var DEFAULT_EFFECTIVE_FROM = "0001-01-01";
5050
+ var _EventConfigVersion = z35.object({
5051
+ id: z35.string().describe(
5052
+ 'Identifier of the version, unique within the event (e.g. "birth-v2").'
5053
+ ),
5054
+ label: TranslationConfig.describe(
5055
+ 'Name of the version, which the UI shows wherever it names the version. For example, "{event.configVersionLabel}" in the event summary.'
5056
+ ),
5057
+ effectiveFrom: z35.iso.date().default(DEFAULT_EFFECTIVE_FROM).describe(
5058
+ `Date (YYYY-MM-DD) from which this version is effective. A version without one is effective from the beginning of time ('${DEFAULT_EFFECTIVE_FROM}').`
5059
+ ),
5060
+ ...versionFields
5061
+ });
5062
+ var resolvedConfigs = /* @__PURE__ */ new WeakMap();
5063
+ function toEventConfig(config, version) {
5064
+ let resolvedVersions = resolvedConfigs.get(config);
5065
+ if (!resolvedVersions) {
5066
+ resolvedVersions = /* @__PURE__ */ new WeakMap();
5067
+ resolvedConfigs.set(config, resolvedVersions);
5068
+ }
5069
+ const cached = resolvedVersions.get(version);
5070
+ if (cached) {
5071
+ return cached;
5072
+ }
5073
+ const {
5074
+ id: _id,
5075
+ label: _label,
5076
+ effectiveFrom: _effectiveFrom,
5077
+ ...fields
5078
+ } = version;
5079
+ const resolved = {
5080
+ ...fields,
5081
+ id: config.id,
5082
+ label: config.label,
5083
+ advancedSearch: config.advancedSearch
5084
+ };
5085
+ resolvedVersions.set(version, resolved);
5086
+ return resolved;
5087
+ }
5088
+ function byEffectiveFrom(a, b) {
5089
+ return a.effectiveFrom.localeCompare(b.effectiveFrom);
5090
+ }
5091
+ function getVersionsInEffectOn(config, date) {
5092
+ return config.versions.filter(({ effectiveFrom }) => effectiveFrom <= date).sort(byEffectiveFrom);
5093
+ }
5094
+ function findVersionInEffectOn(config, date) {
5095
+ return getVersionsInEffectOn(config, date).at(-1);
5096
+ }
5097
+ function resolveEventConfigOnDate(config, date) {
5098
+ return toEventConfig(
5099
+ config,
5100
+ getOrThrow(
5101
+ findVersionInEffectOn(config, date),
5102
+ `Event '${config.id}' has no version in effect on ${date}`
5103
+ )
5104
+ );
5105
+ }
5106
+ function resolveEventConfigInTimeZone(config, timeZone, now2 = /* @__PURE__ */ new Date()) {
5107
+ return resolveEventConfigOnDate(config, toPlainDateInTimeZone(now2, timeZone));
5108
+ }
5109
+ function resolveEventConfig(config) {
5110
+ return resolveEventConfigInTimeZone(config, "UTC");
5111
+ }
5112
+ function validateVersionList(config, ctx) {
5113
+ const ids = /* @__PURE__ */ new Set();
5114
+ const versionIdByEffectiveFrom = /* @__PURE__ */ new Map();
5115
+ config.versions.forEach((version, index) => {
5116
+ if (ids.has(version.id)) {
5117
+ ctx.addIssue({
5118
+ code: "custom",
5119
+ message: `Event '${config.id}' has more than one version with id '${version.id}'. Each version must have a different id.`,
5120
+ path: ["versions", index, "id"]
5121
+ });
5122
+ }
5123
+ ids.add(version.id);
5124
+ const sameEffectiveFromId = versionIdByEffectiveFrom.get(
5125
+ version.effectiveFrom
5126
+ );
5127
+ if (sameEffectiveFromId !== void 0) {
5128
+ const versionIds = `'${sameEffectiveFromId}', '${version.id}'`;
5129
+ ctx.addIssue({
5130
+ code: "custom",
5131
+ 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.`,
5132
+ path: ["versions", index, "effectiveFrom"]
5133
+ });
5134
+ } else {
5135
+ versionIdByEffectiveFrom.set(version.effectiveFrom, version.id);
5136
+ }
5137
+ });
5138
+ }
5139
+ function validateEachVersion(ctx, events, validate2) {
5140
+ const reported = /* @__PURE__ */ new Set();
5141
+ events.forEach((event2, index) => {
5142
+ const addIssue = (issue) => {
5143
+ if (typeof issue === "string") {
5144
+ ctx.addIssue({
5145
+ code: "custom",
5146
+ message: issue,
5147
+ path: ["versions", index]
5148
+ });
5149
+ return;
5150
+ }
5151
+ const [field3] = issue.path ?? [];
5152
+ const isEventLevel = typeof field3 === "string" && field3 in eventLevelFields;
5153
+ const path = isEventLevel ? issue.path ?? [] : ["versions", index, ...issue.path ?? []];
5154
+ const key = JSON.stringify([path, issue.message]);
5155
+ if (reported.has(key)) {
5156
+ return;
5157
+ }
5158
+ reported.add(key);
5159
+ ctx.addIssue({ ...issue, path });
5160
+ };
5161
+ validate2(event2, { value: event2, addIssue });
5162
+ });
5163
+ }
5164
+ var VersionedEventConfig2 = z35.object({
5165
+ ...eventLevelFields,
5166
+ versions: z35.array(_EventConfigVersion).min(1).describe(
5167
+ `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}'.`
5168
+ )
5169
+ }).superRefine((config, ctx) => {
5170
+ validateVersionList(config, ctx);
5171
+ validateEachVersion(
5172
+ ctx,
5173
+ config.versions.map((version) => toEventConfig(config, version)),
5174
+ validateEventConfig
5175
+ );
5176
+ }).meta({
5177
+ id: "VersionedEventConfig",
5178
+ description: "Configuration of an event type registered in OpenCRVS (for example birth or death), with every version of it."
5179
+ });
4529
5180
 
4530
5181
  // ../commons/src/events/EventConfigInput.ts
4531
5182
  var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
@@ -4597,7 +5248,7 @@ function createSearchConfig(baseField) {
4597
5248
 
4598
5249
  // ../commons/src/event-config/event-configuration.ts
4599
5250
  function isNonSearchableEventMetadataTimeFieldId(fieldId) {
4600
- return !EventFieldIdInput.safeParse(fieldId).success;
5251
+ return !EventFieldIdInput.validate(fieldId);
4601
5252
  }
4602
5253
  function createEventFieldConfig(fieldId) {
4603
5254
  const baseField = {
@@ -4622,9 +5273,20 @@ function createEventFieldConfig(fieldId) {
4622
5273
  function eventFn(fieldId) {
4623
5274
  return createEventFieldConfig(fieldId);
4624
5275
  }
5276
+ function actionDateReference(match, occurrence) {
5277
+ return {
5278
+ $action: {
5279
+ match: match.map((m) => typeof m === "string" ? { type: m } : m),
5280
+ occurrence
5281
+ }
5282
+ };
5283
+ }
4625
5284
  var event = Object.assign(eventFn, {
4626
5285
  /**
4627
- * Checks if the event contains a specific action type.
5286
+ * Checks if the event contains a specific accepted action type.
5287
+ * Only Accepted actions are matched: a confirmable action is stored as a
5288
+ * Requested and an Accepted action, and a pending or rejected request must
5289
+ * not count as the action having happened.
4628
5290
  * Can be used directly as a conditional or chained with additional methods.
4629
5291
  * @param action - The action type to check for.
4630
5292
  */
@@ -4642,9 +5304,12 @@ var event = Object.assign(eventFn, {
4642
5304
  properties: {
4643
5305
  type: {
4644
5306
  const: action
5307
+ },
5308
+ status: {
5309
+ const: ActionStatus.Accepted
4645
5310
  }
4646
5311
  },
4647
- required: ["type"]
5312
+ required: ["type", "status"]
4648
5313
  }
4649
5314
  }
4650
5315
  },
@@ -4655,9 +5320,10 @@ var event = Object.assign(eventFn, {
4655
5320
  });
4656
5321
  const buildActionConstraints = (additionalFields) => {
4657
5322
  const actionProperties = {
4658
- type: { const: action }
5323
+ type: { const: action },
5324
+ status: { const: ActionStatus.Accepted }
4659
5325
  };
4660
- const requiredFields = ["type"];
5326
+ const requiredFields = ["type", "status"];
4661
5327
  if (additionalFields) {
4662
5328
  Object.entries(additionalFields).forEach(([key, value]) => {
4663
5329
  actionProperties[key] = { const: value };
@@ -4731,6 +5397,16 @@ var event = Object.assign(eventFn, {
4731
5397
  $event: field3
4732
5398
  };
4733
5399
  },
5400
+ /**
5401
+ * References the date of the first action matching any of the given types,
5402
+ * e.g. `field('child.dob').isAfter().days(30).beforeAction(event.firstAction(ActionType.DECLARE))`.
5403
+ * Until a matching action exists, the comparison uses $now.
5404
+ */
5405
+ firstAction: (first, ...rest) => actionDateReference([first, ...rest], "first"),
5406
+ /**
5407
+ * Like {@link event.firstAction}, but references the most recent matching action.
5408
+ */
5409
+ lastAction: (first, ...rest) => actionDateReference([first, ...rest], "last"),
4734
5410
  /**
4735
5411
  * Checks if the event currently has the given status.
4736
5412
  * @param eventStatus - The status to check for.
@@ -4779,7 +5455,7 @@ var SerializableWithin = z37.object({
4779
5455
  });
4780
5456
  var SerializedQueryExpression = z37.object({
4781
5457
  eventType: z37.string(),
4782
- status: z37.optional(z37.union([AnyOfStatus, ExactStatus])),
5458
+ status: z37.optional(z37.union([AnyOfStatus, NoneOfStatus, ExactStatus])),
4783
5459
  createdAt: z37.optional(DateCondition),
4784
5460
  updatedAt: z37.optional(DateCondition),
4785
5461
  "legalStatuses.DECLARED.createdAtLocation": z37.optional(SerializableWithin),
@@ -4788,6 +5464,7 @@ var SerializedQueryExpression = z37.object({
4788
5464
  "legalStatuses.REGISTERED.createdAtLocation": z37.optional(SerializableWithin),
4789
5465
  "legalStatuses.REGISTERED.createdByRole": z37.optional(AnyOf),
4790
5466
  "legalStatuses.REGISTERED.registrationNumber": z37.optional(Exact),
5467
+ "legalStatuses.REVOKED.createdAtLocation": z37.optional(SerializableWithin),
4791
5468
  createdAtLocation: z37.optional(
4792
5469
  z37.union([SerializableWithin, SerializableExact])
4793
5470
  ),
@@ -4927,6 +5604,12 @@ var RegisterActionInput = BaseActionInput.extend(
4927
5604
  var NotifyActionInput = BaseActionInput.extend(
4928
5605
  z39.object({
4929
5606
  type: z39.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
5607
+ declaration: BaseActionInput.shape.declaration.describe(
5608
+ "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."
5609
+ ),
5610
+ annotation: BaseActionInput.shape.annotation.describe(
5611
+ "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."
5612
+ ),
4930
5613
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
4931
5614
  createdAtLocation: UUID.nullish().describe(
4932
5615
  "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."
@@ -4999,6 +5682,16 @@ var UnarchiveActionInput = BaseActionInput.extend(
4999
5682
  type: z39.literal(ActionType.UNARCHIVE).default(ActionType.UNARCHIVE)
5000
5683
  }).shape
5001
5684
  );
5685
+ var RevokeRegistrationActionInput = BaseActionInput.extend(
5686
+ z39.object({
5687
+ type: z39.literal(ActionType.REVOKE_REGISTRATION).default(ActionType.REVOKE_REGISTRATION)
5688
+ }).shape
5689
+ );
5690
+ var ReinstateRegistrationActionInput = BaseActionInput.extend(
5691
+ z39.object({
5692
+ type: z39.literal(ActionType.REINSTATE_REGISTRATION).default(ActionType.REINSTATE_REGISTRATION)
5693
+ }).shape
5694
+ );
5002
5695
  var AssignActionInput = BaseActionInput.extend(
5003
5696
  z39.object({
5004
5697
  type: z39.literal(ActionType.ASSIGN),
@@ -5061,6 +5754,12 @@ var ActionInput = z39.discriminatedUnion("type", [
5061
5754
  }),
5062
5755
  ArchiveActionInput.meta({ id: "ArchiveActionInput" }),
5063
5756
  UnarchiveActionInput.meta({ id: "UnarchiveActionInput" }),
5757
+ RevokeRegistrationActionInput.meta({
5758
+ id: "RevokeRegistrationActionInput"
5759
+ }),
5760
+ ReinstateRegistrationActionInput.meta({
5761
+ id: "ReinstateRegistrationActionInput"
5762
+ }),
5064
5763
  AssignActionInput.meta({ id: "AssignActionInput" }),
5065
5764
  UnassignActionInput.meta({ id: "UnassignActionInput" }),
5066
5765
  PrintCertificateActionInput.meta({ id: "PrintCertificateActionInput" }),
@@ -5094,17 +5793,19 @@ var DraftInput = BaseActionInput.omit({ waitFor: true }).extend({
5094
5793
  /*
5095
5794
  * A draft can name a file that no action references. Such a file stays until
5096
5795
  * the record is deleted or the record's next action sweeps its prefix.
5097
- * DECLARE is available only where one of those is still coming: a created
5098
- * record, which can still be deleted, and a record part way through an edit,
5099
- * which is about to be declared or registered.
5796
+ * Drafts are therefore saved only on a created record, which can still be deleted.
5797
+ * The server refuses them on any other record.
5100
5798
  */
5101
- type: z40.literal(ActionTypes.enum.DECLARE),
5799
+ type: z40.enum([ActionTypes.enum.DECLARE, ActionTypes.enum.NOTIFY]),
5102
5800
  status: z40.enum([
5103
5801
  ActionStatus.Requested,
5104
5802
  ActionStatus.Accepted,
5105
5803
  ActionStatus.Rejected
5106
5804
  ])
5107
5805
  });
5806
+ var RemoteDraft = Draft.extend({
5807
+ action: Draft.shape.action.extend({ type: DraftInput.shape.type })
5808
+ });
5108
5809
 
5109
5810
  // ../commons/src/events/EventInput.ts
5110
5811
  var z41 = __toESM(require("zod/v4"));
@@ -5114,6 +5815,9 @@ var EventInput = z41.object({
5114
5815
  type: z41.string(),
5115
5816
  createdAtLocation: UUID.nullish().describe(
5116
5817
  "Location where the event occurred. Required for system users."
5818
+ ),
5819
+ configVersionId: z41.string().optional().describe(
5820
+ "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."
5117
5821
  )
5118
5822
  }).meta({ default: { transactionId: (0, import_uuid11.v4)(), type: "birth" } });
5119
5823
 
@@ -5129,6 +5833,9 @@ var EventDocument = z42.object({
5129
5833
  actions: z42.array(Action).describe("Ordered list of actions associated with the event."),
5130
5834
  trackingId: z42.string().describe(
5131
5835
  "System-generated tracking identifier used to look up the event."
5836
+ ),
5837
+ configVersionId: z42.string().describe(
5838
+ "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'."
5132
5839
  )
5133
5840
  }).meta({ id: "EventDocument" });
5134
5841
  var EventDocumentOnlyLastAction = EventDocument.extend({
@@ -5136,10 +5843,114 @@ var EventDocumentOnlyLastAction = EventDocument.extend({
5136
5843
  }).brand("EventDocumentOnlyLastAction");
5137
5844
 
5138
5845
  // ../commons/src/events/defineConfig.ts
5139
- var defineConfig = (config) => {
5140
- const input = EventConfig.parse(config);
5141
- return input;
5142
- };
5846
+ var z43 = __toESM(require("zod/v4"));
5847
+ function moveDeclarationToDeclareAction({
5848
+ declaration,
5849
+ ...config
5850
+ }) {
5851
+ if (declaration) {
5852
+ console.warn(
5853
+ `Event '${config.id}' defines \`declaration\` at the top level, which is deprecated and will be removed in a future release. Define it on the ${ActionType.DECLARE} action instead.`
5854
+ );
5855
+ }
5856
+ return {
5857
+ ...config,
5858
+ actions: config.actions.map((action) => {
5859
+ if (action.type !== ActionType.DECLARE) {
5860
+ return action;
5861
+ }
5862
+ const declarationOfAction = action.declaration ?? declaration;
5863
+ if (!declarationOfAction) {
5864
+ throw new Error(`Event '${config.id}' does not define \`declaration\`.`);
5865
+ }
5866
+ return { ...action, declaration: declarationOfAction };
5867
+ })
5868
+ };
5869
+ }
5870
+ var VERSIONED_EVENT_FIELDS = [
5871
+ "id",
5872
+ "label",
5873
+ "advancedSearch",
5874
+ "versions"
5875
+ ];
5876
+ function validateNoVersionFieldsAtTopLevel(config, ctx) {
5877
+ Object.keys(config).filter((key) => !VERSIONED_EVENT_FIELDS.includes(key)).forEach((key) => {
5878
+ ctx.addIssue({
5879
+ code: "custom",
5880
+ message: `Event '${config.id}' defines \`versions\`, so \`${key}\` must be defined on each version, not at the top level.`,
5881
+ path: [key]
5882
+ });
5883
+ });
5884
+ }
5885
+ function toVersionedInput(config) {
5886
+ if ("versions" in config) {
5887
+ return config;
5888
+ }
5889
+ const { id, label, advancedSearch, ...version } = moveDeclarationToDeclareAction(config);
5890
+ return {
5891
+ id,
5892
+ label,
5893
+ advancedSearch,
5894
+ versions: [{ ...version, id: INITIAL_EVENT_CONFIG_VERSION_ID, label }]
5895
+ };
5896
+ }
5897
+ var WESTERNMOST_TIME_ZONE = "Etc/GMT+12";
5898
+ function validateVersionInEffectToday(config, ctx) {
5899
+ const today = toPlainDateInTimeZone(/* @__PURE__ */ new Date(), WESTERNMOST_TIME_ZONE);
5900
+ const isAnyVersionInEffect = config.versions.some(
5901
+ ({ effectiveFrom }) => effectiveFrom <= today
5902
+ );
5903
+ if (!isAnyVersionInEffect) {
5904
+ ctx.addIssue({
5905
+ code: "custom",
5906
+ 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.`,
5907
+ path: ["versions"]
5908
+ });
5909
+ }
5910
+ }
5911
+ var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5912
+ if ("versions" in config) {
5913
+ validateNoVersionFieldsAtTopLevel(config, ctx);
5914
+ return;
5915
+ }
5916
+ const eventCtx = { ...ctx, value: config };
5917
+ if (validateExactlyOneDeclareAction(config, eventCtx)) {
5918
+ validateDeclarationGivenExactlyOnce(config, eventCtx);
5919
+ }
5920
+ }).transform(toVersionedInput).pipe(VersionedEventConfig2).superRefine(validateVersionInEffectToday);
5921
+ var defineConfig = (config) => EventConfigDefinition.parse(config);
5922
+
5923
+ // ../commons/src/events/toNotificationForm.ts
5924
+ function toOptionalField(field3) {
5925
+ const { validation: _validation, ...rest } = field3;
5926
+ if (rest.type === FieldType.FIELD_GROUP && "fields" in rest) {
5927
+ return {
5928
+ ...rest,
5929
+ required: false,
5930
+ fields: rest.fields.map(toOptionalField)
5931
+ };
5932
+ }
5933
+ return { ...rest, required: false };
5934
+ }
5935
+ function toNotificationForm(declaration) {
5936
+ return {
5937
+ ...declaration,
5938
+ pages: declaration.pages.map((page) => ({
5939
+ ...page,
5940
+ fields: page.fields.map(
5941
+ toOptionalField
5942
+ )
5943
+ }))
5944
+ };
5945
+ }
5946
+ function toNotificationReview(review) {
5947
+ return {
5948
+ ...review,
5949
+ fields: review.fields.map(
5950
+ toOptionalField
5951
+ )
5952
+ };
5953
+ }
5143
5954
 
5144
5955
  // ../commons/src/events/test.utils.ts
5145
5956
  var import_lodash5 = require("lodash");
@@ -6389,7 +7200,7 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
6389
7200
  });
6390
7201
 
6391
7202
  // ../commons/src/fixtures/tennis-club-membership-event.ts
6392
- var tennisClubMembershipEvent = defineConfig({
7203
+ var versionedTennisClubMembershipEvent = defineConfig({
6393
7204
  id: TENNIS_CLUB_MEMBERSHIP,
6394
7205
  declaration: TENNIS_CLUB_DECLARATION_FORM,
6395
7206
  label: {
@@ -6448,6 +7259,8 @@ var tennisClubMembershipEvent = defineConfig({
6448
7259
  description: "This is shown as the action name anywhere the user can trigger the action from",
6449
7260
  id: "event.tennis-club-membership.action.notify.label"
6450
7261
  },
7262
+ notificationForm: toNotificationForm(TENNIS_CLUB_DECLARATION_FORM),
7263
+ review: toNotificationReview(TENNIS_CLUB_DECLARATION_REVIEW),
6451
7264
  flags: [
6452
7265
  {
6453
7266
  id: "health-worker-notified",
@@ -6744,9 +7557,12 @@ var tennisClubMembershipEvent = defineConfig({
6744
7557
  }
6745
7558
  ]
6746
7559
  });
7560
+ var tennisClubMembershipEvent = resolveEventConfig(
7561
+ versionedTennisClubMembershipEvent
7562
+ );
6747
7563
 
6748
7564
  // ../commons/src/fixtures/football-club-membership-event.ts
6749
- var footballClubMembershipEvent = defineConfig({
7565
+ var versionedFootballClubMembershipEvent = defineConfig({
6750
7566
  id: "FOOTBALL_CLUB_MEMBERSHIP",
6751
7567
  label: {
6752
7568
  defaultMessage: "Football club membership application",
@@ -7069,6 +7885,9 @@ var footballClubMembershipEvent = defineConfig({
7069
7885
  ],
7070
7886
  declaration: TENNIS_CLUB_DECLARATION_FORM
7071
7887
  });
7888
+ var footballClubMembershipEvent = resolveEventConfig(
7889
+ versionedFootballClubMembershipEvent
7890
+ );
7072
7891
 
7073
7892
  // ../commons/src/fixtures/library-membership-event.ts
7074
7893
  var libraryMembershipForm = defineDeclarationForm({
@@ -7112,7 +7931,7 @@ var libraryMembershipForm = defineDeclarationForm({
7112
7931
  }
7113
7932
  ]
7114
7933
  });
7115
- var libraryMembershipEvent = defineConfig({
7934
+ var versionedLibraryMembershipEvent = defineConfig({
7116
7935
  id: "library-membership",
7117
7936
  label: {
7118
7937
  defaultMessage: "Library membership application",
@@ -7125,9 +7944,29 @@ var libraryMembershipEvent = defineConfig({
7125
7944
  id: "event.library-membership.title"
7126
7945
  },
7127
7946
  summary: { fields: [] },
7128
- actions: [],
7947
+ actions: [
7948
+ {
7949
+ type: ActionType.DECLARE,
7950
+ label: {
7951
+ defaultMessage: "Declare",
7952
+ description: "This is shown as the action name anywhere the user can trigger the action from",
7953
+ id: "event.library-membership.action.declare.label"
7954
+ },
7955
+ review: {
7956
+ title: {
7957
+ defaultMessage: "Library membership application",
7958
+ description: "Title of the review page",
7959
+ id: "event.library-membership.action.declare.form.review.title"
7960
+ },
7961
+ fields: []
7962
+ }
7963
+ }
7964
+ ],
7129
7965
  declaration: libraryMembershipForm
7130
7966
  });
7967
+ var libraryMembershipEvent = resolveEventConfig(
7968
+ versionedLibraryMembershipEvent
7969
+ );
7131
7970
 
7132
7971
  // ../commons/src/fixtures/child-onboarding-event.ts
7133
7972
  function generateTranslationConfig(message) {
@@ -7341,7 +8180,7 @@ var CHILD_ONBOARDING_DECLARATION_FORM = defineDeclarationForm({
7341
8180
  label: generateTranslationConfig("Birth decalration form"),
7342
8181
  pages: [child, mother]
7343
8182
  });
7344
- var ChildOnboardingEvent = defineConfig({
8183
+ var versionedChildOnboardingEvent = defineConfig({
7345
8184
  id: CHILD_ONBOARDING_EVENT,
7346
8185
  title: generateTranslationConfig(
7347
8186
  "{child.name.firstname} {child.name.surname}"
@@ -7369,6 +8208,9 @@ var ChildOnboardingEvent = defineConfig({
7369
8208
  ],
7370
8209
  advancedSearch: []
7371
8210
  });
8211
+ var ChildOnboardingEvent = resolveEventConfig(
8212
+ versionedChildOnboardingEvent
8213
+ );
7372
8214
 
7373
8215
  // ../commons/src/fixtures/digital-identity-issuance-event.ts
7374
8216
  var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
@@ -7557,7 +8399,7 @@ var digitalIdentityForm = defineDeclarationForm({
7557
8399
  }
7558
8400
  ]
7559
8401
  });
7560
- var digitalIdentityEvent = defineConfig({
8402
+ var versionedDigitalIdentityEvent = defineConfig({
7561
8403
  id: "digital-identity",
7562
8404
  label: {
7563
8405
  defaultMessage: "Digital identity issuance",
@@ -7571,6 +8413,22 @@ var digitalIdentityEvent = defineConfig({
7571
8413
  },
7572
8414
  summary: { fields: [] },
7573
8415
  actions: [
8416
+ {
8417
+ type: ActionType.DECLARE,
8418
+ label: {
8419
+ defaultMessage: "Declare",
8420
+ description: "This is shown as the action name anywhere the user can trigger the action from",
8421
+ id: "event.digital-identity.action.declare.label"
8422
+ },
8423
+ review: {
8424
+ title: {
8425
+ defaultMessage: "Digital identity issuance",
8426
+ description: "Title of the review page",
8427
+ id: "event.digital-identity.action.declare.form.review.title"
8428
+ },
8429
+ fields: []
8430
+ }
8431
+ },
7574
8432
  {
7575
8433
  type: ActionType.PRINT_CERTIFICATE,
7576
8434
  label: {
@@ -7583,41 +8441,44 @@ var digitalIdentityEvent = defineConfig({
7583
8441
  ],
7584
8442
  declaration: digitalIdentityForm
7585
8443
  });
8444
+ var digitalIdentityEvent = resolveEventConfig(
8445
+ versionedDigitalIdentityEvent
8446
+ );
7586
8447
 
7587
8448
  // ../commons/src/events/test.utils.ts
7588
- var z44 = __toESM(require("zod/v4"));
8449
+ var z45 = __toESM(require("zod/v4"));
7589
8450
 
7590
8451
  // ../commons/src/events/locations.ts
7591
- var z43 = __toESM(require("zod/v4"));
7592
- var LocationTypeV1 = z43.enum([
8452
+ var z44 = __toESM(require("zod/v4"));
8453
+ var LocationTypeV1 = z44.enum([
7593
8454
  "ADMIN_STRUCTURE",
7594
8455
  "CRVS_OFFICE",
7595
8456
  "HEALTH_FACILITY"
7596
8457
  ]);
7597
- var LocationStatus = z43.enum(["active", "inactive"]);
7598
- var LocationVersion = z43.object({
8458
+ var LocationStatus = z44.enum(["active", "inactive"]);
8459
+ var LocationVersion = z44.object({
7599
8460
  versionId: UUID,
7600
- effectiveFrom: z43.iso.date(),
7601
- name: z43.string(),
7602
- externalId: z43.string().nullish(),
8461
+ effectiveFrom: z44.iso.date(),
8462
+ name: z44.string(),
8463
+ externalId: z44.string().nullish(),
7603
8464
  status: LocationStatus
7604
8465
  });
7605
- var AdministrativeArea = z43.object({
8466
+ var AdministrativeArea = z44.object({
7606
8467
  id: UUID,
7607
- name: z43.string(),
7608
- externalId: z43.string().nullish(),
8468
+ name: z44.string(),
8469
+ externalId: z44.string().nullish(),
7609
8470
  parentId: UUID.nullable(),
7610
8471
  status: LocationStatus,
7611
- versions: z43.array(LocationVersion)
8472
+ versions: z44.array(LocationVersion)
7612
8473
  });
7613
- var Location = z43.object({
8474
+ var Location = z44.object({
7614
8475
  id: UUID,
7615
- name: z43.string(),
7616
- externalId: z43.string().nullish(),
8476
+ name: z44.string(),
8477
+ externalId: z44.string().nullish(),
7617
8478
  administrativeAreaId: UUID.nullable(),
7618
- locationType: z43.string().nullable(),
8479
+ locationType: z44.string().nullable(),
7619
8480
  status: LocationStatus,
7620
- versions: z43.array(LocationVersion)
8481
+ versions: z44.array(LocationVersion)
7621
8482
  });
7622
8483
  var ClientAdministrativeArea = AdministrativeArea.omit({
7623
8484
  name: true,
@@ -7658,22 +8519,22 @@ function validateUniqueIds(versions, ctx) {
7658
8519
  ctx.addIssue("versions must not repeat a versionId");
7659
8520
  }
7660
8521
  }
7661
- var SeededLocationVersions = z43.array(LocationVersion).min(1).superRefine((versions, ctx) => {
8522
+ var SeededLocationVersions = z44.array(LocationVersion).min(1).superRefine((versions, ctx) => {
7662
8523
  validateAscendingDates(versions, ctx);
7663
8524
  validateUniqueIds(versions, ctx);
7664
8525
  });
7665
- var SetLocationPayload = z43.object({
8526
+ var SetLocationPayload = z44.object({
7666
8527
  id: UUID,
7667
- name: z43.string(),
7668
- externalId: z43.string().nullish(),
8528
+ name: z44.string(),
8529
+ externalId: z44.string().nullish(),
7669
8530
  administrativeAreaId: UUID.nullable(),
7670
- locationType: z43.string().nullable(),
8531
+ locationType: z44.string().nullable(),
7671
8532
  versions: SeededLocationVersions.optional()
7672
8533
  });
7673
- var SetAdministrativeAreaPayload = z43.object({
8534
+ var SetAdministrativeAreaPayload = z44.object({
7674
8535
  id: UUID,
7675
- name: z43.string(),
7676
- externalId: z43.string().nullish(),
8536
+ name: z44.string(),
8537
+ externalId: z44.string().nullish(),
7677
8538
  parentId: UUID.nullable(),
7678
8539
  versions: SeededLocationVersions.optional()
7679
8540
  });
@@ -8021,7 +8882,7 @@ var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
8021
8882
  );
8022
8883
 
8023
8884
  // ../commons/src/events/test.utils.ts
8024
- var TestUserRole = z44.enum([
8885
+ var TestUserRole = z45.enum([
8025
8886
  "FIELD_AGENT",
8026
8887
  "LOCAL_REGISTRAR",
8027
8888
  "LOCAL_SYSTEM_ADMIN",
@@ -8049,8 +8910,12 @@ var ACTION_SCOPE_MAP = {
8049
8910
  "record.correct"
8050
8911
  ],
8051
8912
  [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
8913
+ // Not granted by a scope: the client checks the draft's own action instead
8914
+ [ClientSpecificAction.CONTINUE_DRAFT]: [],
8052
8915
  [ActionType.REJECT_CORRECTION]: ["record.correct"],
8053
8916
  [ActionType.APPROVE_CORRECTION]: ["record.correct"],
8917
+ [ActionType.REVOKE_REGISTRATION]: ["record.revoke-registration"],
8918
+ [ActionType.REINSTATE_REGISTRATION]: ["record.reinstate-registration"],
8054
8919
  [ActionType.MARK_AS_DUPLICATE]: ["record.review-duplicates"],
8055
8920
  [ActionType.MARK_AS_NOT_DUPLICATE]: ["record.review-duplicates"],
8056
8921
  [ActionType.ARCHIVE]: ["record.archive"],
@@ -8097,7 +8962,12 @@ var AVAILABLE_ACTIONS_BY_EVENT_STATUS = {
8097
8962
  ActionType.APPROVE_CORRECTION,
8098
8963
  ActionType.REJECT_CORRECTION,
8099
8964
  ActionType.CUSTOM,
8100
- ClientSpecificAction.REVIEW_CORRECTION_REQUEST
8965
+ ClientSpecificAction.REVIEW_CORRECTION_REQUEST,
8966
+ ActionType.REVOKE_REGISTRATION
8967
+ ],
8968
+ [EventStatus.enum.REVOKED]: [
8969
+ ActionType.READ,
8970
+ ActionType.REINSTATE_REGISTRATION
8101
8971
  ],
8102
8972
  [EventStatus.enum.ARCHIVED]: [
8103
8973
  ActionType.READ,
@@ -8111,6 +8981,8 @@ var ACTION_FILTERS = {
8111
8981
  [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
8112
8982
  [ActionType.APPROVE_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
8113
8983
  [ActionType.REJECT_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
8984
+ [ActionType.REVOKE_REGISTRATION]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
8985
+ [ActionType.REINSTATE_REGISTRATION]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
8114
8986
  [ActionType.MARK_AS_DUPLICATE]: (flags) => flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
8115
8987
  [ActionType.EDIT]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
8116
8988
  [ActionType.REGISTER]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
@@ -8133,55 +9005,55 @@ var REJECTED_ACTIONS = [
8133
9005
  var import_lodash7 = require("lodash");
8134
9006
 
8135
9007
  // ../commons/src/events/locationPayloads.ts
8136
- var z45 = __toESM(require("zod/v4"));
8137
- var CreateLocationPayload = z45.object({
9008
+ var z46 = __toESM(require("zod/v4"));
9009
+ var CreateLocationPayload = z46.object({
8138
9010
  id: UUID.optional(),
8139
9011
  versionId: UUID.optional(),
8140
- name: z45.string(),
8141
- externalId: z45.string().nullish(),
9012
+ name: z46.string(),
9013
+ externalId: z46.string().nullish(),
8142
9014
  administrativeAreaId: UUID.nullable(),
8143
- locationType: z45.string().nullable(),
8144
- effectiveFrom: z45.iso.date().optional(),
9015
+ locationType: z46.string().nullable(),
9016
+ effectiveFrom: z46.iso.date().optional(),
8145
9017
  status: LocationStatus.default("active")
8146
9018
  });
8147
- var UpdateLocationPayload = z45.strictObject({
9019
+ var UpdateLocationPayload = z46.strictObject({
8148
9020
  id: UUID,
8149
9021
  versionId: UUID.optional(),
8150
- name: z45.string(),
8151
- externalId: z45.string().nullish(),
9022
+ name: z46.string(),
9023
+ externalId: z46.string().nullish(),
8152
9024
  status: LocationStatus,
8153
- effectiveFrom: z45.iso.date().optional(),
9025
+ effectiveFrom: z46.iso.date().optional(),
8154
9026
  lastVersionId: UUID
8155
9027
  });
8156
- var WithdrawLocationVersionPayload = z45.object({
9028
+ var WithdrawLocationVersionPayload = z46.object({
8157
9029
  id: UUID,
8158
9030
  versionId: UUID
8159
9031
  });
8160
- var CreateAdministrativeAreaPayload = z45.object({
9032
+ var CreateAdministrativeAreaPayload = z46.object({
8161
9033
  id: UUID.optional(),
8162
9034
  versionId: UUID.optional(),
8163
- name: z45.string(),
8164
- externalId: z45.string().nullish(),
9035
+ name: z46.string(),
9036
+ externalId: z46.string().nullish(),
8165
9037
  parentId: UUID.nullable(),
8166
- effectiveFrom: z45.iso.date().optional(),
9038
+ effectiveFrom: z46.iso.date().optional(),
8167
9039
  status: LocationStatus.default("active")
8168
9040
  });
8169
- var UpdateAdministrativeAreaPayload = z45.strictObject({
9041
+ var UpdateAdministrativeAreaPayload = z46.strictObject({
8170
9042
  id: UUID,
8171
9043
  versionId: UUID.optional(),
8172
- name: z45.string(),
8173
- externalId: z45.string().nullish(),
9044
+ name: z46.string(),
9045
+ externalId: z46.string().nullish(),
8174
9046
  status: LocationStatus,
8175
- effectiveFrom: z45.iso.date().optional(),
9047
+ effectiveFrom: z46.iso.date().optional(),
8176
9048
  lastVersionId: UUID
8177
9049
  });
8178
- var WithdrawAdministrativeAreaVersionPayload = z45.object({
9050
+ var WithdrawAdministrativeAreaVersionPayload = z46.object({
8179
9051
  id: UUID,
8180
9052
  versionId: UUID
8181
9053
  });
8182
9054
 
8183
9055
  // ../commons/src/notification/UserNotifications.ts
8184
- var z46 = __toESM(require("zod/v4"));
9056
+ var z47 = __toESM(require("zod/v4"));
8185
9057
  var TriggerEvent = {
8186
9058
  USER_CREATED: "user-created",
8187
9059
  USER_UPDATED: "user-updated",
@@ -8196,60 +9068,60 @@ var TriggerEvent = {
8196
9068
  CHANGE_PHONE_NUMBER: "change-phone-number",
8197
9069
  CHANGE_EMAIL_ADDRESS: "change-email-address"
8198
9070
  };
8199
- var Recipient = z46.object({
9071
+ var Recipient = z47.object({
8200
9072
  name: NameFieldValue.optional(),
8201
- mobile: z46.string().optional(),
8202
- email: z46.string().optional(),
8203
- bcc: z46.array(z46.string()).optional()
9073
+ mobile: z47.string().optional(),
9074
+ email: z47.string().optional(),
9075
+ bcc: z47.array(z47.string()).optional()
8204
9076
  });
8205
- var BasePayload = z46.object({
9077
+ var BasePayload = z47.object({
8206
9078
  recipient: Recipient
8207
9079
  });
8208
9080
  var TriggerPayload = {
8209
9081
  [TriggerEvent.USER_CREATED]: BasePayload.extend({
8210
- username: z46.string(),
8211
- temporaryPassword: z46.string()
9082
+ username: z47.string(),
9083
+ temporaryPassword: z47.string()
8212
9084
  }),
8213
9085
  [TriggerEvent.USER_UPDATED]: BasePayload.extend({
8214
- oldUsername: z46.string(),
8215
- newUsername: z46.string()
9086
+ oldUsername: z47.string(),
9087
+ newUsername: z47.string()
8216
9088
  }),
8217
9089
  [TriggerEvent.USERNAME_REMINDER]: BasePayload.extend({
8218
- username: z46.string()
9090
+ username: z47.string()
8219
9091
  }),
8220
9092
  [TriggerEvent.RESET_PASSWORD]: BasePayload.extend({
8221
- code: z46.string()
9093
+ code: z47.string()
8222
9094
  }),
8223
9095
  [TriggerEvent.RESET_PASSWORD_BY_ADMIN]: BasePayload.extend({
8224
- temporaryPassword: z46.string(),
8225
- admin: z46.object({
8226
- id: z46.string(),
9096
+ temporaryPassword: z47.string(),
9097
+ admin: z47.object({
9098
+ id: z47.string(),
8227
9099
  name: NameFieldValue,
8228
- role: z46.string()
9100
+ role: z47.string()
8229
9101
  })
8230
9102
  }),
8231
9103
  [TriggerEvent.PASSWORD_RESET_LINK]: BasePayload.extend({
8232
- token: z46.string()
9104
+ token: z47.string()
8233
9105
  }),
8234
9106
  [TriggerEvent.USERNAME_REMINDER_LINK]: BasePayload.extend({
8235
- token: z46.string()
9107
+ token: z47.string()
8236
9108
  }),
8237
9109
  [TriggerEvent.RESEND_INVITE]: BasePayload.extend({
8238
- username: z46.string(),
8239
- temporaryPassword: z46.string()
9110
+ username: z47.string(),
9111
+ temporaryPassword: z47.string()
8240
9112
  }),
8241
9113
  [TriggerEvent.TWO_FA]: BasePayload.extend({
8242
- code: z46.string()
9114
+ code: z47.string()
8243
9115
  }),
8244
9116
  [TriggerEvent.ALL_USER_NOTIFICATION]: BasePayload.extend({
8245
- subject: z46.string(),
8246
- body: z46.string()
9117
+ subject: z47.string(),
9118
+ body: z47.string()
8247
9119
  }),
8248
9120
  [TriggerEvent.CHANGE_PHONE_NUMBER]: BasePayload.extend({
8249
- code: z46.string()
9121
+ code: z47.string()
8250
9122
  }),
8251
9123
  [TriggerEvent.CHANGE_EMAIL_ADDRESS]: BasePayload.extend({
8252
- code: z46.string()
9124
+ code: z47.string()
8253
9125
  })
8254
9126
  };
8255
9127
  function parseUserEventTrigger(event2, body) {
@@ -8352,7 +9224,7 @@ async function triggerUserEventNotification({
8352
9224
  }
8353
9225
 
8354
9226
  // src/notification/index.ts
8355
- z47.globalRegistry.clear();
9227
+ z48.globalRegistry.clear();
8356
9228
  // Annotate the CommonJS export names for ESM import in node:
8357
9229
  0 && (module.exports = {
8358
9230
  BasePayload,