@opencrvs/toolkit 2.1.0-rc.1f688f9 → 2.1.0-rc.268cfbe

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 (209) hide show
  1. package/README.md +2 -12
  2. package/build.sh +20 -5
  3. package/create-countryconfig/index.js +164 -4
  4. package/dist/application-config/index.js +36 -25
  5. package/dist/authentication/index.d.ts +66 -0
  6. package/dist/authentication/index.d.ts.map +1 -0
  7. package/dist/authentication/index.js +765 -0
  8. package/dist/cli.js +2829 -1294
  9. package/dist/commons/api/router.d.ts +252 -290
  10. package/dist/commons/application-config/index.d.ts +0 -2
  11. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  12. package/dist/commons/conditionals/validate.d.ts +19 -4
  13. package/dist/commons/events/ActionConfig.d.ts +5 -14
  14. package/dist/commons/events/ActionDocument.d.ts +30 -4
  15. package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
  16. package/dist/commons/events/AuditLog.d.ts +1 -0
  17. package/dist/commons/events/Draft.d.ts +1 -21
  18. package/dist/commons/events/EventDocument.d.ts +4 -4
  19. package/dist/commons/events/FieldConfig.d.ts +26 -15
  20. package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
  21. package/dist/commons/events/FieldValue.d.ts +1 -0
  22. package/dist/commons/events/FormConfig.d.ts +6 -0
  23. package/dist/commons/events/PageConfig.d.ts +4 -0
  24. package/dist/commons/events/locations.d.ts +4 -0
  25. package/dist/commons/events/scopes.d.ts +21 -1
  26. package/dist/commons/events/test.utils.d.ts +71 -22
  27. package/dist/commons/events/utils.d.ts +37 -2
  28. package/dist/commons/notification/dispatch.d.ts +1 -6
  29. package/dist/conditionals/index.js +21 -7
  30. package/dist/csv.d.ts +25 -0
  31. package/dist/csv.d.ts.map +1 -0
  32. package/dist/csv.js +120 -0
  33. package/dist/environment/index.d.ts.map +1 -1
  34. package/dist/environment/index.js +2 -1
  35. package/dist/environment/logger.d.ts +3 -0
  36. package/dist/environment/logger.d.ts.map +1 -1
  37. package/dist/environment/manage-users.js +1 -1
  38. package/dist/environment/setup-environment.d.ts +1 -1
  39. package/dist/environment/setup-environment.d.ts.map +1 -1
  40. package/dist/environment/setup-environment.js +593 -562
  41. package/dist/environment/swarm-to-k8s.js +3 -4
  42. package/dist/environment/templates.d.ts +0 -1
  43. package/dist/environment/templates.d.ts.map +1 -1
  44. package/dist/environment/templates.js +3 -8
  45. package/dist/environment/update-workflows.d.ts.map +1 -1
  46. package/dist/environment/update-workflows.js +4 -0
  47. package/dist/environment/utils.d.ts +0 -12
  48. package/dist/environment/utils.d.ts.map +1 -1
  49. package/dist/environment/utils.js +1 -28
  50. package/dist/events/index.js +2115 -1884
  51. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -1
  52. package/dist/migrations/v2.1/add-recovery-link-notifications.js +13 -32
  53. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  54. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  55. package/dist/migrations/v2.1/add-translations.js +149 -0
  56. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
  57. package/dist/migrations/v2.1/enable-telemetry.js +32 -15
  58. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  59. package/dist/migrations/v2.1/index.js +1160 -70
  60. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  61. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  62. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +345 -0
  63. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  64. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  65. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  66. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  67. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  68. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  69. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  70. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  71. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  72. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  73. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  74. package/dist/migrations/v2.1/template-files.js +49 -0
  75. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  76. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  77. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  78. package/dist/notification/index.js +249 -207
  79. package/dist/scopes/index.d.ts +288 -5
  80. package/dist/scopes/index.js +22 -7
  81. package/dist/telemetry/index.js +5 -1
  82. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  83. package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
  84. package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
  85. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  86. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  87. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  88. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  89. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  90. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  91. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  92. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  93. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  94. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  95. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  96. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  97. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  98. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  99. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  100. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  101. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  102. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  103. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  104. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  105. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  106. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  107. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  108. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  109. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  110. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  111. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  112. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  113. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  114. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  115. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  116. package/dist/translations/template.d.ts +11 -0
  117. package/dist/translations/template.d.ts.map +1 -0
  118. package/dist/translations/template.js +100 -0
  119. package/dist/verify/endpoints.d.ts +2 -0
  120. package/dist/verify/endpoints.d.ts.map +1 -0
  121. package/dist/verify/endpoints.js +510 -0
  122. package/opencrvs-toolkit-2.1.0-rc.268cfbe.tgz +0 -0
  123. package/package.json +9 -4
  124. package/tsconfig.build.json +11 -0
  125. package/tsconfig.build.tsbuildinfo +1 -0
  126. package/tsconfig.json +3 -0
  127. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  128. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  129. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  130. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  131. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  132. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  133. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  134. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  135. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  136. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  137. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  138. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  139. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  140. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  141. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  142. package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
  143. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  144. package/dist/migrations/v2.0/create-events-index.js +0 -325
  145. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  146. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  147. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  148. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  149. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  150. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  151. package/dist/migrations/v2.0/index.d.ts +0 -13
  152. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  153. package/dist/migrations/v2.0/index.js +0 -103
  154. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  155. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  156. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  157. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  158. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  159. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  160. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  161. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  162. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  163. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  164. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  165. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  166. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  167. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  168. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  169. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  170. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  171. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  172. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  173. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  174. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  175. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  176. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  177. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  178. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  179. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  180. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  181. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  182. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  183. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  184. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  185. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  186. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  187. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  188. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  189. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  190. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  191. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  192. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  193. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  194. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  195. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  196. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  197. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  198. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  199. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  200. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  201. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  202. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  203. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  204. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  205. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  206. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  207. package/dist/migrations/v2.0/update-package-json.js +0 -105
  208. package/opencrvs-toolkit-2.1.0-rc.1f688f9.tgz +0 -0
  209. package/tsconfig.tsbuildinfo +0 -1
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var events_exports = {};
32
32
  __export(events_exports, {
33
33
  ACTION_SCOPE_MAP: () => ACTION_SCOPE_MAP,
34
+ AGE_MAX_VALUE: () => AGE_MAX_VALUE,
34
35
  Action: () => Action,
35
36
  ActionBase: () => ActionBase,
36
37
  ActionConditional: () => ActionConditional,
@@ -67,7 +68,6 @@ __export(events_exports, {
67
68
  AutocompleteUpdateValue: () => AutocompleteUpdateValue,
68
69
  AutocompleteValue: () => AutocompleteValue,
69
70
  BaseActionInput: () => BaseActionInput,
70
- BearerTokenByUserType: () => BearerTokenByUserType,
71
71
  ButtonFieldValue: () => ButtonFieldValue,
72
72
  CHILD_ONBOARDING_EVENT: () => CHILD_ONBOARDING_EVENT,
73
73
  CertificateConfig: () => CertificateConfig,
@@ -89,6 +89,7 @@ __export(events_exports, {
89
89
  CustomFlag: () => CustomFlag,
90
90
  DEFAULT_DATE_OF_EVENT_PROPERTY: () => DEFAULT_DATE_OF_EVENT_PROPERTY,
91
91
  DEFAULT_PLACE_OF_EVENT_PROPERTY: () => DEFAULT_PLACE_OF_EVENT_PROPERTY,
92
+ DOCUMENT_DELETE_SCOPES: () => DOCUMENT_DELETE_SCOPES,
92
93
  DataEntry: () => DataEntry,
93
94
  DataFieldValue: () => DataFieldValue,
94
95
  DateCondition: () => DateCondition,
@@ -162,6 +163,7 @@ __export(events_exports, {
162
163
  HttpFieldValue: () => HttpFieldValue,
163
164
  IdReaderFieldValue: () => IdReaderFieldValue,
164
165
  ImageMimeType: () => ImageMimeType,
166
+ InactiveOfficeError: () => InactiveOfficeError,
165
167
  InfoBox: () => InfoBox,
166
168
  InherentFlags: () => InherentFlags,
167
169
  LanguageConfig: () => LanguageConfig,
@@ -194,6 +196,7 @@ __export(events_exports, {
194
196
  QueryParamReaderFieldUpdateValue: () => QueryParamReaderFieldUpdateValue,
195
197
  QueryParamReaderFieldValue: () => QueryParamReaderFieldValue,
196
198
  QueryType: () => QueryType,
199
+ RECORD_WRITE_SCOPES: () => RECORD_WRITE_SCOPES,
197
200
  Range: () => Range,
198
201
  ReadActionInput: () => ReadActionInput,
199
202
  ReasonContent: () => ReasonContent,
@@ -202,6 +205,7 @@ __export(events_exports, {
202
205
  RegistrationCreationMetadata: () => RegistrationCreationMetadata,
203
206
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
204
207
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
208
+ RejectedCorrectionAction: () => RejectedCorrectionAction,
205
209
  RequestCorrectionActionInput: () => RequestCorrectionActionInput,
206
210
  SearchQuery: () => SearchQuery,
207
211
  SearchQueryParams: () => SearchQueryParams,
@@ -292,6 +296,7 @@ __export(events_exports, {
292
296
  defineWorkqueues: () => defineWorkqueues,
293
297
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
294
298
  deserializeQuery: () => deserializeQuery,
299
+ dropSecuredDeclarationFields: () => dropSecuredDeclarationFields,
295
300
  errorMessages: () => errorMessages,
296
301
  evaluate: () => evaluate,
297
302
  event: () => event,
@@ -321,6 +326,7 @@ __export(events_exports, {
321
326
  generateRandomName: () => generateRandomName,
322
327
  generateRandomSignature: () => generateRandomSignature,
323
328
  generateRegistrationNumber: () => generateRegistrationNumber,
329
+ generateTestValidatorContext: () => generateTestValidatorContext,
324
330
  generateTrackingId: () => generateTrackingId,
325
331
  generateTransactionId: () => generateTransactionId,
326
332
  generateTranslationConfig: () => generateTranslationConfig2,
@@ -346,13 +352,16 @@ __export(events_exports, {
346
352
  getCurrentEventState: () => getCurrentEventState,
347
353
  getCustomActionFields: () => getCustomActionFields,
348
354
  getDeclaration: () => getDeclaration,
355
+ getDeclarationAfterEachAction: () => getDeclarationAfterEachAction,
349
356
  getDeclarationFieldById: () => getDeclarationFieldById,
350
357
  getDeclarationFields: () => getDeclarationFields,
351
358
  getDeclarationPages: () => getDeclarationPages,
359
+ getDeclarationWithPendingAction: () => getDeclarationWithPendingAction,
352
360
  getEventConfigById: () => getEventConfigById,
353
361
  getEventFlags: () => getEventFlags,
354
362
  getEventValidatorContext: () => getEventValidatorContext,
355
363
  getFilePathsFromEvent: () => getFilePathsFromEvent,
364
+ getLeafAdministrativeAreaIds: () => getLeafAdministrativeAreaIds,
356
365
  getLocationHierarchy: () => getLocationHierarchy,
357
366
  getMixedPath: () => getMixedPath,
358
367
  getPendingAction: () => getPendingAction,
@@ -778,7 +787,9 @@ var RecordScopeTypeV2 = z7.enum([
778
787
  "record.request-correction",
779
788
  "record.correct",
780
789
  "record.unassign-others",
781
- "record.custom-action"
790
+ "record.custom-action",
791
+ "record.action.accept",
792
+ "record.action.reject"
782
793
  ]);
783
794
  var PlainScopeType = z7.enum([
784
795
  // Misc. system scopes
@@ -800,10 +811,7 @@ var PlainScopeType = z7.enum([
800
811
  // Performance dashboard
801
812
  "performance.read",
802
813
  "performance.read-dashboards",
803
- "performance.vital-statistics-export",
804
- // Scopes used exclusively by countryconfig integration token
805
- "record.confirm-registration",
806
- "record.reject-registration"
814
+ "performance.vital-statistics-export"
807
815
  ]);
808
816
  var scopeByEvent = z7.preprocess(
809
817
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -821,7 +829,9 @@ var userRole = z7.preprocess(
821
829
  ).describe("User role, e.g. admin, field agent");
822
830
  var scopeOptionsPlaceEvent = z7.object({
823
831
  event: scopeByEvent,
824
- placeOfEvent: JurisdictionFilter.optional()
832
+ placeOfEvent: JurisdictionFilter.optional(),
833
+ createdBy: UserFilter.optional(),
834
+ createdIn: JurisdictionFilter.optional()
825
835
  }).describe("Options applicable to all record scopes.");
826
836
  var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
827
837
  notifiedIn: JurisdictionFilter.optional(),
@@ -864,7 +874,9 @@ var AllScopeOptions = z7.object({
864
874
  var ScopeOptionKey = AllScopeOptions.keyof();
865
875
  var ResolvedScopeOptionsPlaceEvent = z7.object({
866
876
  event: scopeByEvent,
867
- placeOfEvent: UUID.nullish()
877
+ placeOfEvent: UUID.nullish(),
878
+ createdBy: z7.string().optional(),
879
+ createdIn: UUID.nullish()
868
880
  }).describe(
869
881
  "Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
870
882
  );
@@ -911,6 +923,13 @@ var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
911
923
  "Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
912
924
  )
913
925
  });
926
+ var ActionConfirmationScopeType = RecordScopeTypeV2.extract([
927
+ "record.action.accept",
928
+ "record.action.reject"
929
+ ]);
930
+ var ActionConfirmationScopeOptions = AllRecordScopeOptions.describe(
931
+ "Options for confirming (accepting or rejecting) an action."
932
+ );
914
933
  var RecordScopeV2 = z7.discriminatedUnion("type", [
915
934
  z7.object({
916
935
  type: ScopesWithPlaceEventOptions,
@@ -931,6 +950,10 @@ var RecordScopeV2 = z7.discriminatedUnion("type", [
931
950
  z7.object({
932
951
  type: z7.literal("record.print-certified-copies"),
933
952
  options: ScopeOptionsPrintCertifiedCopies.optional()
953
+ }),
954
+ z7.object({
955
+ type: ActionConfirmationScopeType,
956
+ options: ActionConfirmationScopeOptions.optional()
934
957
  })
935
958
  ]).describe(
936
959
  "Scopes used to check user's permission to perform actions on a record."
@@ -1018,11 +1041,25 @@ var ScopeType = z7.enum([
1018
1041
  "workqueue",
1019
1042
  "dashboard.view"
1020
1043
  ]);
1044
+ var flattenScope = (scope) => ({
1045
+ type: scope.type,
1046
+ ..."options" in scope ? scope.options : {}
1047
+ });
1021
1048
  var unflattenScope = (input) => {
1022
1049
  const { type, ...options } = input;
1023
1050
  return { type, options };
1024
1051
  };
1025
1052
  var EncodedScope = z7.string().brand("EncodedScope");
1053
+ var encodeScope = (scope) => {
1054
+ const flattened = flattenScope(scope);
1055
+ return qs.stringify(flattened, {
1056
+ arrayFormat: "comma",
1057
+ commaRoundTrip: true,
1058
+ allowDots: true,
1059
+ addQueryPrefix: false,
1060
+ encode: false
1061
+ });
1062
+ };
1026
1063
  var decodedScopeCache = /* @__PURE__ */ new Map();
1027
1064
  var decodeScope = (encodedScope) => {
1028
1065
  if (decodedScopeCache.has(encodedScope)) {
@@ -1251,6 +1288,7 @@ var AttachmentUploadEntrySchema = AuditLogEntryBase.extend({
1251
1288
  operation: z9.literal("attachments.upload"),
1252
1289
  requestData: z9.object({
1253
1290
  transactionId: z9.string(),
1291
+ eventId: z9.string().optional(),
1254
1292
  path: z9.string().nullable()
1255
1293
  }),
1256
1294
  responseSummary: z9.object({ fileUrl: z9.string() })
@@ -1576,8 +1614,9 @@ var TextValue = z14.string();
1576
1614
  var HiddenFieldValue = z14.string();
1577
1615
  var NonEmptyTextValue = z14.string().trim().min(1);
1578
1616
  var DateValue = z14.iso.date().describe("Date in the format YYYY-MM-DD");
1617
+ var AGE_MAX_VALUE = 999;
1579
1618
  var AgeValue = z14.object({
1580
- age: z14.number(),
1619
+ age: z14.number().int().min(0).max(AGE_MAX_VALUE),
1581
1620
  asOfDateRef: z14.string()
1582
1621
  });
1583
1622
  var AgeUpdateValue = AgeValue.optional().nullable();
@@ -1907,7 +1946,7 @@ var RequestedCorrectionAction = ActionBase.extend(
1907
1946
  var ApprovedCorrectionAction = ActionBase.extend(
1908
1947
  z16.object({
1909
1948
  type: z16.literal(ActionType.APPROVE_CORRECTION),
1910
- requestId: z16.string(),
1949
+ requestId: UUID,
1911
1950
  // TODO move into 'content' property
1912
1951
  content: z16.object({ immediateCorrection: z16.boolean().optional() }).optional()
1913
1952
  }).shape
@@ -1915,7 +1954,7 @@ var ApprovedCorrectionAction = ActionBase.extend(
1915
1954
  var RejectedCorrectionAction = ActionBase.extend(
1916
1955
  z16.object({
1917
1956
  type: z16.literal(ActionType.REJECT_CORRECTION),
1918
- requestId: z16.string(),
1957
+ requestId: UUID,
1919
1958
  // TODO move into 'content' property
1920
1959
  content: ReasonContent
1921
1960
  }).shape
@@ -2825,9 +2864,6 @@ var AdministrativeAreaField = BaseField.extend({
2825
2864
  partOf: FieldReference.optional().describe("Parent location"),
2826
2865
  type: AdministrativeAreas,
2827
2866
  allowedLocations: AllowedLocations,
2828
- listHistoricalNames: import_v43.default.boolean().optional().describe(
2829
- "List every historical name a location has had as a separate, selectable option."
2830
- ),
2831
2867
  activeOnly: import_v43.default.boolean().optional().describe(
2832
2868
  "Offer only locations that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded."
2833
2869
  ),
@@ -2845,9 +2881,6 @@ var LocationInput = BaseField.extend({
2845
2881
  configuration: import_v43.default.object({
2846
2882
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2847
2883
  allowedLocations: AllowedLocations,
2848
- listHistoricalNames: import_v43.default.boolean().optional().describe(
2849
- "List every historical name a location has had as a separate, selectable option."
2850
- ),
2851
2884
  activeOnly: import_v43.default.boolean().optional().describe(
2852
2885
  "Offer only locations that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded."
2853
2886
  ),
@@ -2881,7 +2914,6 @@ var Facility = BaseField.extend({
2881
2914
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2882
2915
  configuration: import_v43.default.object({
2883
2916
  allowedLocations: AllowedLocations,
2884
- listHistoricalNames: import_v43.default.boolean().optional(),
2885
2917
  activeOnly: import_v43.default.boolean().optional(),
2886
2918
  anchorToDateOfEvent: import_v43.default.boolean().optional()
2887
2919
  }).optional()
@@ -2891,7 +2923,6 @@ var Office = BaseField.extend({
2891
2923
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2892
2924
  configuration: import_v43.default.object({
2893
2925
  allowedLocations: AllowedLocations,
2894
- listHistoricalNames: import_v43.default.boolean().optional(),
2895
2926
  activeOnly: import_v43.default.boolean().optional(),
2896
2927
  anchorToDateOfEvent: import_v43.default.boolean().optional()
2897
2928
  }).optional()
@@ -2928,9 +2959,6 @@ var Address = BaseField.extend({
2928
2959
  })
2929
2960
  ).optional(),
2930
2961
  allowedLocations: AllowedLocations,
2931
- listHistoricalNames: import_v43.default.boolean().optional().describe(
2932
- "List every historical name a location has had as a separate, selectable option. Propagated to the embedded admin-area selectors."
2933
- ),
2934
2962
  activeOnly: import_v43.default.boolean().optional().describe(
2935
2963
  "Offer only admin areas that are active at the resolved anchor date (today, or the date of event when anchorToDateOfEvent is set); inactive or not-yet-effective versions are excluded. Propagated to the embedded admin-area selectors."
2936
2964
  ),
@@ -2991,10 +3019,19 @@ var ButtonField = BaseField.extend({
2991
3019
  description: "A generic button that can be used to trigger an action",
2992
3020
  id: "ButtonField"
2993
3021
  });
3022
+ var FieldGroupConfiguration = import_v43.default.object({
3023
+ separator: import_v43.default.string().optional().describe(
3024
+ 'Joins the subfield values when the group is rendered as output, e.g. ", ". Defaults to one subfield per line.'
3025
+ ),
3026
+ hideEmptyFields: import_v43.default.boolean().default(false).optional().describe(
3027
+ "Leaves subfields without a value out of the output. Pair it with a separator so the separator does not double up around the gaps."
3028
+ )
3029
+ });
2994
3030
  var FieldGroup = BaseField.extend({
2995
3031
  type: import_v43.default.literal(FieldType.FIELD_GROUP),
2996
3032
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
2997
- fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig))
3033
+ fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig)),
3034
+ configuration: FieldGroupConfiguration.optional()
2998
3035
  }).meta({
2999
3036
  description: "A group of fields that are displayed together",
3000
3037
  id: "FieldGroup"
@@ -3248,6 +3285,9 @@ var PageConfigBase = z22.object({
3248
3285
  requireCompletionToContinue: z22.boolean().default(false).describe(
3249
3286
  "If true, all required fields must be filled before continuing to the next page"
3250
3287
  ),
3288
+ showClearButton: z22.boolean().optional().describe(
3289
+ 'If true, a "Clear" button is shown at the top of the page allowing the user to reset all fields on the page to their default state'
3290
+ ),
3251
3291
  fields: z22.array(FieldConfig).describe("Fields to be rendered on the page"),
3252
3292
  conditional: Conditional.optional().describe(
3253
3293
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
@@ -3428,7 +3468,10 @@ var ReadActionConfig = ActionConfigBase.extend(
3428
3468
  review: DeclarationReviewConfig.describe(
3429
3469
  "Configuration of the review page for read-only view."
3430
3470
  ),
3431
- conditionals: z25.never().optional().describe("Read-action can not be disabled or hidden with conditionals.")
3471
+ conditionals: z25.never().optional().describe("Read-action can not be disabled or hidden with conditionals."),
3472
+ flags: z25.never().optional().describe(
3473
+ "READ is a meta action excluded from flag resolution, so flags configured here would never apply."
3474
+ )
3432
3475
  }).shape
3433
3476
  );
3434
3477
  var NotifyConfig = ActionConfigBase.extend(
@@ -3860,7 +3903,7 @@ var ReferenceField = BaseField2.extend({
3860
3903
  var Field = BaseField2.extend({
3861
3904
  id: z29.string().describe("Identifier of the summary field."),
3862
3905
  value: TranslationConfig.describe(
3863
- 'Field value template supporting variables from configuration and EventMetadata (e.g. "{informant.phoneNo} {informant.email}").'
3906
+ '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}").'
3864
3907
  ),
3865
3908
  label: TranslationConfig
3866
3909
  }).describe("Custom field defined for the summary view.");
@@ -4451,21 +4494,23 @@ function getDeclarationActionCreationMetadata(actionType, actions) {
4451
4494
  registrationNumber
4452
4495
  };
4453
4496
  }
4454
- var updateActions = ActionTypes.extract([
4455
- ActionType.CREATE,
4456
- ActionType.NOTIFY,
4457
- ActionType.EDIT,
4458
- ActionType.DECLARE,
4459
- ActionType.REGISTER,
4460
- ActionType.REJECT,
4461
- ActionType.ARCHIVE,
4462
- ActionType.UNARCHIVE,
4463
- ActionType.PRINT_CERTIFICATE,
4464
- ActionType.REQUEST_CORRECTION,
4465
- ActionType.APPROVE_CORRECTION,
4466
- ActionType.REJECT_CORRECTION,
4467
- ActionType.CUSTOM
4468
- ]);
4497
+ var updateActions = new Set(
4498
+ ActionTypes.extract([
4499
+ ActionType.CREATE,
4500
+ ActionType.NOTIFY,
4501
+ ActionType.EDIT,
4502
+ ActionType.DECLARE,
4503
+ ActionType.REGISTER,
4504
+ ActionType.REJECT,
4505
+ ActionType.ARCHIVE,
4506
+ ActionType.UNARCHIVE,
4507
+ ActionType.PRINT_CERTIFICATE,
4508
+ ActionType.REQUEST_CORRECTION,
4509
+ ActionType.APPROVE_CORRECTION,
4510
+ ActionType.REJECT_CORRECTION,
4511
+ ActionType.CUSTOM
4512
+ ]).options
4513
+ );
4469
4514
  function getActionUpdateMetadata(actions) {
4470
4515
  const createAction = getOrThrow(
4471
4516
  actions.find((action) => action.type === ActionType.CREATE),
@@ -4478,7 +4523,7 @@ function getActionUpdateMetadata(actions) {
4478
4523
  "createdAtLocation",
4479
4524
  "createdByRole"
4480
4525
  ];
4481
- return actions.filter(({ type }) => updateActions.safeParse(type).success).reduce(
4526
+ return actions.filter(({ type }) => updateActions.has(type)).reduce(
4482
4527
  (_2, action) => {
4483
4528
  if (action.originalActionId) {
4484
4529
  const originalAction = actions.find(({ id }) => id === action.originalActionId) ?? action;
@@ -4631,7 +4676,12 @@ function resolveInherentFlag(rule, acceptedActions, event2, eventConfiguration)
4631
4676
  }
4632
4677
  function resolveEventCustomFlags(event2, eventConfiguration) {
4633
4678
  const actions = getAcceptedActions(event2).filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
4679
+ const declarations = getDeclarationAfterEachAction({ ...event2, actions });
4680
+ let annotation = {};
4634
4681
  return actions.reduce((acc, action, idx) => {
4682
+ if (action.annotation) {
4683
+ annotation = deepMerge(annotation, action.annotation);
4684
+ }
4635
4685
  let actionConfig;
4636
4686
  if (isActionConfigType(action.type)) {
4637
4687
  actionConfig = getActionConfig({
@@ -4643,13 +4693,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
4643
4693
  if (!actionConfig) {
4644
4694
  return acc;
4645
4695
  }
4646
- const eventUpToThisAction = {
4647
- ...event2,
4648
- actions: actions.slice(0, idx + 1)
4649
- };
4650
- const declaration = aggregateActionDeclarations(eventUpToThisAction);
4651
- const annotation = aggregateActionAnnotations(eventUpToThisAction);
4652
- const form = { ...declaration, ...annotation };
4696
+ const form = { ...declarations[idx], ...annotation };
4653
4697
  const flagsWithMetConditions = (actionConfig.flags ?? []).filter(
4654
4698
  ({ conditional }) => (
4655
4699
  // If conditional is not provided, the flag is resolved
@@ -5831,7 +5875,7 @@ function areConditionsMet(conditions, values, context, event2) {
5831
5875
  (condition) => validate(condition.conditional, clientFunctionContext)
5832
5876
  );
5833
5877
  }
5834
- function isFieldSecured(field3, event2, context = {}) {
5878
+ function isFieldSecured(field3, event2, context) {
5835
5879
  if (typeof field3.secured !== "object" || field3.secured === null) {
5836
5880
  return Boolean(field3.secured);
5837
5881
  }
@@ -6088,47 +6132,69 @@ function runFieldValidations({
6088
6132
  });
6089
6133
  return [...fieldValidationResult, ...customValidationResults];
6090
6134
  }
6091
- function getValidatorsForField(fieldId, validations) {
6092
- return validations.map(({ validator, message }) => {
6093
- const jsonSchema = validator;
6094
- if (!jsonSchema.properties) {
6095
- return null;
6096
- }
6097
- const $form = jsonSchema.properties.$form;
6098
- if ($form.properties?.[fieldId]?.type === "object") {
6135
+ function extractFieldSchema(fieldId, jsonSchema) {
6136
+ if (!jsonSchema.properties) {
6137
+ if (Array.isArray(jsonSchema.allOf)) {
6138
+ const members = jsonSchema.allOf.map((member) => extractFieldSchema(fieldId, member)).filter((member) => member !== null).map(({ $id, ...member }) => member);
6139
+ if (members.length === 0) {
6140
+ return null;
6141
+ }
6099
6142
  return {
6100
- message,
6101
- validator: {
6102
- ...jsonSchema,
6103
- properties: {
6104
- $form: {
6105
- type: "object",
6106
- properties: $form.properties?.[fieldId]?.properties || {},
6107
- required: $form.properties?.[fieldId]?.required || []
6108
- }
6109
- }
6110
- }
6143
+ ...jsonSchema,
6144
+ /*
6145
+ * `validate()` looks schemas up from Ajv's cache by `$id`, so a
6146
+ * narrowed schema must not reuse the id its un-narrowed parent was
6147
+ * compiled under.
6148
+ */
6149
+ ...typeof jsonSchema.$id === "string" ? { $id: `${jsonSchema.$id}.${fieldId}` } : {},
6150
+ allOf: members
6111
6151
  };
6112
6152
  }
6113
- if (!$form.properties?.[fieldId]) {
6114
- return null;
6115
- }
6153
+ return null;
6154
+ }
6155
+ const $form = jsonSchema.properties.$form;
6156
+ if (!$form?.properties) {
6157
+ return null;
6158
+ }
6159
+ if ($form.properties?.[fieldId]?.type === "object") {
6116
6160
  return {
6117
- message,
6118
- validator: {
6119
- ...jsonSchema,
6120
- $id: jsonSchema.$id + "." + fieldId,
6121
- properties: {
6122
- $form: {
6123
- type: "object",
6124
- properties: {
6125
- [fieldId]: $form.properties?.[fieldId]
6126
- },
6127
- required: $form.required?.includes(fieldId) ? [fieldId] : []
6128
- }
6161
+ ...jsonSchema,
6162
+ // See the `$id` note in the `allOf` branch above: Ajv caches by `$id`,
6163
+ // so a narrowed schema must not reuse its parent's id.
6164
+ ...typeof jsonSchema.$id === "string" ? { $id: `${jsonSchema.$id}.${fieldId}` } : {},
6165
+ properties: {
6166
+ $form: {
6167
+ type: "object",
6168
+ properties: $form.properties?.[fieldId]?.properties || {},
6169
+ required: $form.properties?.[fieldId]?.required || []
6129
6170
  }
6130
6171
  }
6131
6172
  };
6173
+ }
6174
+ if (!$form.properties?.[fieldId]) {
6175
+ return null;
6176
+ }
6177
+ return {
6178
+ ...jsonSchema,
6179
+ $id: jsonSchema.$id + "." + fieldId,
6180
+ properties: {
6181
+ $form: {
6182
+ type: "object",
6183
+ properties: {
6184
+ [fieldId]: $form.properties?.[fieldId]
6185
+ },
6186
+ required: $form.required?.includes(fieldId) ? [fieldId] : []
6187
+ }
6188
+ }
6189
+ };
6190
+ }
6191
+ function getValidatorsForField(fieldId, validations) {
6192
+ return validations.map(({ validator, message }) => {
6193
+ const narrowed = extractFieldSchema(fieldId, validator);
6194
+ if (narrowed === null) {
6195
+ return null;
6196
+ }
6197
+ return { message, validator: narrowed };
6132
6198
  }).filter((x) => x !== null);
6133
6199
  }
6134
6200
  function areCertificateConditionsMet(conditions, values) {
@@ -6339,9 +6405,8 @@ function omitHiddenAnnotationFields(actionConfig, declaration, annotation, conte
6339
6405
  });
6340
6406
  }
6341
6407
  function deepMerge(currentDocument, actionDocument) {
6342
- const currentDocumentClone = (0, import_lodash4.cloneDeep)(currentDocument);
6343
6408
  return (0, import_lodash4.mergeWith)(
6344
- (0, import_lodash4.cloneDeep)(currentDocumentClone),
6409
+ (0, import_lodash4.cloneDeep)(currentDocument),
6345
6410
  actionDocument,
6346
6411
  (previousValue, incomingValue) => {
6347
6412
  if (incomingValue === void 0) {
@@ -6505,7 +6570,7 @@ function getPendingAction(actions) {
6505
6570
  );
6506
6571
  if (pendingActions.length !== 1) {
6507
6572
  throw new Error(
6508
- `Expected exactly one pending action, but found ${pendingActions.map(({ id }) => id).join(", ")}`
6573
+ `Expected exactly one pending action, but found ${pendingActions.length ? pendingActions.map(({ id }) => id).join(", ") : "none"}`
6509
6574
  );
6510
6575
  }
6511
6576
  return pendingActions[0];
@@ -6563,30 +6628,70 @@ var EXCLUDED_ACTIONS = [
6563
6628
  ActionType.PRINT_CERTIFICATE,
6564
6629
  ActionType.REJECT_CORRECTION
6565
6630
  ];
6631
+ function applyActionDeclaration(declaration, event2, action, acceptedActions) {
6632
+ if (action.type === ActionType.APPROVE_CORRECTION) {
6633
+ const requestAction = acceptedActions.find(
6634
+ ({ id }) => id === action.requestId
6635
+ );
6636
+ if (!requestAction) {
6637
+ return declaration;
6638
+ }
6639
+ const declarationWithApprovedCorrection = getCompleteActionDeclaration(
6640
+ declaration,
6641
+ event2,
6642
+ requestAction
6643
+ );
6644
+ return getCompleteActionDeclaration(
6645
+ declarationWithApprovedCorrection,
6646
+ event2,
6647
+ action
6648
+ );
6649
+ }
6650
+ return getCompleteActionDeclaration(declaration, event2, action);
6651
+ }
6566
6652
  function aggregateActionDeclarations(event2) {
6567
6653
  const allAcceptedActions = getAcceptedActions(event2);
6568
6654
  const aggregatedActions = allAcceptedActions.filter((a) => !EXCLUDED_ACTIONS.some((type) => type === a.type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6569
- return aggregatedActions.reduce((declaration, action) => {
6570
- if (action.type === ActionType.APPROVE_CORRECTION) {
6571
- const requestAction = allAcceptedActions.find(
6572
- ({ id }) => id === action.requestId
6573
- );
6574
- if (!requestAction) {
6575
- return declaration;
6576
- }
6577
- const declarationWithApprovedCorrection = getCompleteActionDeclaration(
6655
+ return aggregatedActions.reduce(
6656
+ (declaration, action) => applyActionDeclaration(declaration, event2, action, allAcceptedActions),
6657
+ {}
6658
+ );
6659
+ }
6660
+ function getDeclarationAfterEachAction(event2) {
6661
+ const acceptedActions = [];
6662
+ let declaration = {};
6663
+ return event2.actions.map((action, index) => {
6664
+ if (!isAcceptedAction(action)) {
6665
+ return declaration;
6666
+ }
6667
+ const eventUntilAction = {
6668
+ ...event2,
6669
+ actions: event2.actions.slice(0, index + 1)
6670
+ };
6671
+ const acceptedAction = {
6672
+ ...action,
6673
+ declaration: getCompleteActionDeclaration({}, eventUntilAction, action)
6674
+ };
6675
+ acceptedActions.push(acceptedAction);
6676
+ if (!EXCLUDED_ACTIONS.some((type) => type === action.type)) {
6677
+ declaration = applyActionDeclaration(
6578
6678
  declaration,
6579
- event2,
6580
- requestAction
6581
- );
6582
- return getCompleteActionDeclaration(
6583
- declarationWithApprovedCorrection,
6584
- event2,
6585
- action
6679
+ eventUntilAction,
6680
+ acceptedAction,
6681
+ acceptedActions
6586
6682
  );
6587
6683
  }
6588
- return getCompleteActionDeclaration(declaration, event2, action);
6589
- }, {});
6684
+ return declaration;
6685
+ });
6686
+ }
6687
+ function getDeclarationWithPendingAction(event2) {
6688
+ const pendingAction = getPendingAction(event2.actions);
6689
+ return applyActionDeclaration(
6690
+ aggregateActionDeclarations(event2),
6691
+ event2,
6692
+ pendingAction,
6693
+ getAcceptedActions(event2)
6694
+ );
6590
6695
  }
6591
6696
  function aggregateActionAnnotations(event2) {
6592
6697
  return event2.actions.reduce((ann, sortedAction) => {
@@ -6596,6 +6701,23 @@ function aggregateActionAnnotations(event2) {
6596
6701
  return deepMerge(ann, sortedAction.annotation);
6597
6702
  }, {});
6598
6703
  }
6704
+ function dropSecuredDeclarationFields(eventConfig, eventIndex, validatorContext) {
6705
+ const declarationFields = getDeclarationFields(eventConfig);
6706
+ const securedFieldIds = new Set(
6707
+ declarationFields.filter(
6708
+ (declarationField) => isFieldSecured(declarationField, eventIndex, validatorContext)
6709
+ ).map((declarationField) => declarationField.id)
6710
+ );
6711
+ const declaration = Object.fromEntries(
6712
+ Object.entries(eventIndex.declaration).filter(
6713
+ ([fieldId]) => !securedFieldIds.has(fieldId)
6714
+ )
6715
+ );
6716
+ return {
6717
+ ...eventIndex,
6718
+ declaration
6719
+ };
6720
+ }
6599
6721
 
6600
6722
  // ../commons/src/events/eventConfigValidation.ts
6601
6723
  function validateAdvancedSearchConfig(event2, ctx) {
@@ -7359,7 +7481,14 @@ var Draft = z40.object({
7359
7481
  "A temporary storage for an action. Stored with details of the event, creator and creation time."
7360
7482
  );
7361
7483
  var DraftInput = BaseActionInput.omit({ waitFor: true }).extend({
7362
- type: ActionTypes.exclude([ActionTypes.enum.DELETE]),
7484
+ /*
7485
+ * A draft can name a file that no action references. Such a file stays until
7486
+ * the record is deleted or the record's next action sweeps its prefix.
7487
+ * DECLARE is available only where one of those is still coming: a created
7488
+ * record, which can still be deleted, and a record part way through an edit,
7489
+ * which is about to be declared or registered.
7490
+ */
7491
+ type: z40.literal(ActionTypes.enum.DECLARE),
7363
7492
  status: z40.enum([
7364
7493
  ActionStatus.Requested,
7365
7494
  ActionStatus.Accepted,
@@ -7397,38 +7526,8 @@ var EventDocumentOnlyLastAction = EventDocument.extend({
7397
7526
  }).brand("EventDocumentOnlyLastAction");
7398
7527
 
7399
7528
  // ../commons/src/events/defineConfig.ts
7400
- var IGNORED_EVENT_TYPES = [
7401
- "FOOTBALL_CLUB_MEMBERSHIP",
7402
- "tennis-club-membership",
7403
- "library-membership",
7404
- "child-onboarding",
7405
- "digital-identity",
7406
- "event-with-optional-address"
7407
- ];
7408
- function warnOnConfigurationIssues2(config) {
7409
- const eventId = config.id;
7410
- if (IGNORED_EVENT_TYPES.includes(eventId)) {
7411
- return;
7412
- }
7413
- const validateDeclarationAction = config.actions.find(
7414
- (action) => action.type === ActionType.CUSTOM && action.customActionType === "VALIDATE_DECLARATION"
7415
- );
7416
- if (!validateDeclarationAction) {
7417
- console.warn(
7418
- `
7419
- ************** WARNING **************
7420
- A custom action with customActionType 'VALIDATE_DECLARATION' is not defined for event '${eventId}'!
7421
- For v2.0, we expect this to be defined for all events.
7422
-
7423
- The deprecated v1.9 'ActionType.VALIDATE' actions are migrated to customActionType 'VALIDATE_DECLARATION' in v2.0.
7424
- ************** WARNING **************
7425
- `
7426
- );
7427
- }
7428
- }
7429
7529
  var defineConfig = (config) => {
7430
7530
  const input = EventConfig.parse(config);
7431
- warnOnConfigurationIssues2(input);
7432
7531
  return input;
7433
7532
  };
7434
7533
 
@@ -8127,6 +8226,21 @@ var TENNIS_CLUB_DECLARATION_REVIEW = {
8127
8226
  description: "Title of the review page"
8128
8227
  },
8129
8228
  fields: [
8229
+ {
8230
+ id: "annotation.hidden",
8231
+ type: FieldType.TEXT,
8232
+ label: {
8233
+ id: "annotation.hidden.label",
8234
+ defaultMessage: "Show not be visible",
8235
+ description: "Catch for rendering"
8236
+ },
8237
+ conditionals: [
8238
+ {
8239
+ type: ConditionalType.SHOW,
8240
+ conditional: never2()
8241
+ }
8242
+ ]
8243
+ },
8130
8244
  {
8131
8245
  id: "review.comment",
8132
8246
  type: FieldType.TEXTAREA,
@@ -8183,7 +8297,23 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
8183
8297
  defaultMessage: "Who is applying for the membership?",
8184
8298
  description: "This is the title of the section"
8185
8299
  },
8300
+ showClearButton: true,
8186
8301
  fields: [
8302
+ {
8303
+ id: "declaration.hidden",
8304
+ type: FieldType.TEXT,
8305
+ label: {
8306
+ id: "declaration.hidden.label",
8307
+ defaultMessage: "Show not be visible",
8308
+ description: "Catch for rendering"
8309
+ },
8310
+ conditionals: [
8311
+ {
8312
+ type: ConditionalType.SHOW,
8313
+ conditional: never2()
8314
+ }
8315
+ ]
8316
+ },
8187
8317
  {
8188
8318
  id: "applicant.name",
8189
8319
  type: FieldType.NAME,
@@ -9853,1828 +9983,1929 @@ var digitalIdentityEvent = defineConfig({
9853
9983
  });
9854
9984
 
9855
9985
  // ../commons/src/events/test.utils.ts
9986
+ var z44 = __toESM(require("zod/v4"));
9987
+
9988
+ // ../commons/src/events/locations.ts
9856
9989
  var z43 = __toESM(require("zod/v4"));
9857
- var TEST_SYSTEM_IANA_TIMEZONE = "Asia/Dhaka";
9858
- var TestUserRole = z43.enum([
9859
- "FIELD_AGENT",
9860
- "LOCAL_REGISTRAR",
9861
- "LOCAL_SYSTEM_ADMIN",
9862
- "NATIONAL_REGISTRAR",
9863
- "REGISTRATION_AGENT",
9864
- "NATIONAL_SYSTEM_ADMIN",
9865
- "SOCIAL_WORKER",
9866
- "COMMUNITY_LEADER",
9867
- "PROVINCIAL_REGISTRAR"
9990
+ var LocationTypeV1 = z43.enum([
9991
+ "ADMIN_STRUCTURE",
9992
+ "CRVS_OFFICE",
9993
+ "HEALTH_FACILITY"
9868
9994
  ]);
9869
- function pickRandom(rng, items) {
9870
- return items[Math.floor(rng() * items.length)];
9871
- }
9872
- function generateRandomName(rng) {
9873
- const firstnames = [
9874
- "Danny",
9875
- "John",
9876
- "Jane",
9877
- "Emily",
9878
- "Michael",
9879
- "Sarah",
9880
- "Chris",
9881
- "Jessica",
9882
- "Sara",
9883
- "Sarachella",
9884
- "Sarandera",
9885
- "Zara"
9886
- ];
9887
- const surnames = [
9888
- "Doe",
9889
- "Smith",
9890
- "Johnson",
9891
- "Brown",
9892
- "Williams",
9893
- "Jones",
9894
- "Garcia",
9895
- "Miller",
9896
- "Saranen",
9897
- "Sarajanen",
9898
- "Sarthua",
9899
- "Tsarakovski",
9900
- "Salamander",
9901
- "Zarathustra"
9902
- ];
9995
+ var LocationStatus = z43.enum(["active", "inactive"]);
9996
+ var InactiveOfficeError = class extends Error {
9997
+ constructor(message = "Assigned office is inactive") {
9998
+ super(message);
9999
+ this.name = "InactiveOfficeError";
10000
+ }
10001
+ };
10002
+ var LocationVersion = z43.object({
10003
+ versionId: UUID,
10004
+ effectiveFrom: z43.iso.date(),
10005
+ name: z43.string(),
10006
+ externalId: z43.string().nullish(),
10007
+ status: LocationStatus
10008
+ });
10009
+ var AdministrativeArea = z43.object({
10010
+ id: UUID,
10011
+ name: z43.string(),
10012
+ externalId: z43.string().nullish(),
10013
+ parentId: UUID.nullable(),
10014
+ status: LocationStatus,
10015
+ versions: z43.array(LocationVersion)
10016
+ });
10017
+ var Location = z43.object({
10018
+ id: UUID,
10019
+ name: z43.string(),
10020
+ externalId: z43.string().nullish(),
10021
+ administrativeAreaId: UUID.nullable(),
10022
+ locationType: z43.string().nullable(),
10023
+ status: LocationStatus,
10024
+ versions: z43.array(LocationVersion)
10025
+ });
10026
+ var ClientAdministrativeArea = AdministrativeArea.omit({
10027
+ name: true,
10028
+ status: true,
10029
+ externalId: true
10030
+ });
10031
+ var ClientLocation = Location.omit({
10032
+ name: true,
10033
+ status: true,
10034
+ externalId: true
10035
+ });
10036
+ function toClientLocation(location) {
9903
10037
  return {
9904
- firstname: pickRandom(rng, firstnames),
9905
- surname: pickRandom(rng, surnames)
10038
+ id: location.id,
10039
+ administrativeAreaId: location.administrativeAreaId,
10040
+ locationType: location.locationType,
10041
+ versions: location.versions
9906
10042
  };
9907
10043
  }
9908
- function generateUuid(rng = () => 0.1) {
9909
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
9910
- const r = Math.floor(rng() * 16);
9911
- const v = c === "x" ? r : r & 3 | 8;
9912
- return v.toString(16);
9913
- });
10044
+ function toClientAdministrativeArea(area) {
10045
+ return {
10046
+ id: area.id,
10047
+ parentId: area.parentId,
10048
+ versions: area.versions
10049
+ };
9914
10050
  }
9915
- function generateTrackingId(rng) {
9916
- const uuid2 = generateUuid(rng).replace(/-/g, "");
9917
- const trackingId = uuid2.slice(0, 6).toUpperCase();
9918
- return trackingId;
10051
+ function validateAscendingDates(versions, ctx) {
10052
+ const ascending = versions.every(
10053
+ (version, index) => index === 0 || versions[index - 1].effectiveFrom < version.effectiveFrom
10054
+ );
10055
+ if (!ascending) {
10056
+ ctx.addIssue("versions must be strictly ascending by effectiveFrom");
10057
+ }
9919
10058
  }
9920
- function generateRegistrationNumber(rng) {
9921
- const uuid2 = generateUuid(rng).replace(/-/g, "");
9922
- const registrationNumber = uuid2.slice(0, 12).toUpperCase();
9923
- return registrationNumber;
9924
- }
9925
- function generateRandomSignature(rng) {
9926
- return `${generateUuid(rng)}.png`;
9927
- }
9928
- function locationVersion(overrides = {}, rng) {
9929
- return {
9930
- versionId: generateUuid(rng),
9931
- effectiveFrom: "0001-01-01",
9932
- name: "Location name",
9933
- externalId: null,
9934
- status: "active",
9935
- ...overrides
9936
- };
10059
+ function validateUniqueIds(versions, ctx) {
10060
+ const versionIds = new Set(versions.map((version) => version.versionId));
10061
+ if (versionIds.size !== versions.length) {
10062
+ ctx.addIssue("versions must not repeat a versionId");
10063
+ }
9937
10064
  }
9938
- function mapFieldTypeToMockValue(field3, i, rng, administrativeHierarchy) {
9939
- const leafLevelAdministrativeAreas = administrativeHierarchy?.administrativeAreas.filter(
9940
- (aa) => administrativeHierarchy?.administrativeAreas.every(
9941
- (other) => other.parentId !== aa.id
9942
- )
9943
- );
9944
- switch (field3.type) {
9945
- case FieldType.FIELD_GROUP: {
9946
- const nestedValue = field3.fields.reduce(
9947
- (acc, subfield, index) => ({
9948
- ...acc,
9949
- [subfield.id]: mapFieldTypeToMockValue(
9950
- subfield,
9951
- i * 1e3 + index,
9952
- rng
9953
- )
9954
- }),
9955
- {}
9956
- );
9957
- return nestedValue;
10065
+ var SeededLocationVersions = z43.array(LocationVersion).min(1).superRefine((versions, ctx) => {
10066
+ validateAscendingDates(versions, ctx);
10067
+ validateUniqueIds(versions, ctx);
10068
+ });
10069
+ var SetLocationPayload = z43.object({
10070
+ id: UUID,
10071
+ name: z43.string(),
10072
+ externalId: z43.string().nullish(),
10073
+ administrativeAreaId: UUID.nullable(),
10074
+ locationType: z43.string().nullable(),
10075
+ versions: SeededLocationVersions.optional()
10076
+ });
10077
+ var SetAdministrativeAreaPayload = z43.object({
10078
+ id: UUID,
10079
+ name: z43.string(),
10080
+ externalId: z43.string().nullish(),
10081
+ parentId: UUID.nullable(),
10082
+ versions: SeededLocationVersions.optional()
10083
+ });
10084
+ function resolveVersion(versions, anchor) {
10085
+ let resolved = versions[0];
10086
+ for (const version of versions) {
10087
+ if (version.effectiveFrom <= anchor) {
10088
+ resolved = version;
9958
10089
  }
9959
- case FieldType.DIVIDER:
9960
- case FieldType.TEXT:
9961
- case FieldType.TEXTAREA:
9962
- case FieldType.BULLET_LIST:
9963
- case FieldType.PAGE_HEADER:
9964
- case FieldType.LOCATION:
9965
- case FieldType.SELECT:
9966
- case FieldType.SELECT_DATE_RANGE:
9967
- case FieldType.COUNTRY:
9968
- case FieldType.RADIO_GROUP:
9969
- case FieldType.PARAGRAPH:
9970
- case FieldType.HEADING:
9971
- case FieldType.IMAGE_VIEW:
9972
- case FieldType.ADMINISTRATIVE_AREA:
9973
- case FieldType.PHONE:
9974
- case FieldType.QUERY_PARAM_READER:
9975
- case FieldType.ID:
9976
- case FieldType.LINK_BUTTON:
9977
- case FieldType.LOADER:
9978
- case FieldType.ALPHA_HIDDEN:
9979
- return `${field3.id}-${field3.type}-${i}`;
9980
- case FieldType.VERIFICATION_STATUS:
9981
- return "verified";
9982
- case FieldType.FACILITY:
9983
- case FieldType.OFFICE:
9984
- return administrativeHierarchy?.locations ? pickRandom(rng, administrativeHierarchy.locations)?.id : "a45b982a-5c7b-4bd9-8fd8-a42d0994054c";
9985
- case FieldType.NAME:
9986
- return generateRandomName(rng);
9987
- case FieldType.NUMBER:
9988
- return 19;
9989
- case FieldType.NUMBER_WITH_UNIT:
9990
- return {
9991
- numericValue: 42,
9992
- unit: "Hours"
9993
- };
9994
- case FieldType.BUTTON:
9995
- return 1;
9996
- case FieldType.EMAIL:
9997
- return "test@opencrvs.org";
9998
- case FieldType.ADDRESS:
9999
- return {
10000
- country: "FAR",
10001
- addressType: AddressType.DOMESTIC,
10002
- administrativeArea: leafLevelAdministrativeAreas ? pickRandom(rng, leafLevelAdministrativeAreas)?.id : "27160bbd-32d1-4625-812f-860226bfb92a",
10003
- streetLevelDetails: {
10004
- town: "Example Town",
10005
- residentialArea: "Example Residential Area",
10006
- street: "Example Street",
10007
- number: "55",
10008
- zipCode: "123456",
10009
- state: "Example State",
10010
- district2: "Example District 2"
10011
- }
10012
- };
10013
- case FieldType.DATE:
10014
- return "2021-01-01";
10015
- case FieldType.AGE:
10016
- return {
10017
- age: 19,
10018
- asOfDateRef: "applicant.dob"
10019
- };
10020
- case FieldType.TIME:
10021
- return "09:33";
10022
- case FieldType.ALPHA_PRINT_BUTTON:
10023
- return void 0;
10024
- case FieldType.DATE_RANGE:
10025
- return {
10026
- start: PlainDate.parse("2021-01-01"),
10027
- end: PlainDate.parse("2021-01-31")
10028
- };
10029
- case FieldType.CHECKBOX:
10030
- return true;
10031
- case FieldType.SIGNATURE:
10032
- case FieldType.FILE:
10033
- return {
10034
- path: "4f095fc4-4312-4de2-aa38-86dcc0f71044.png",
10035
- originalFilename: "abcd.png",
10036
- type: "image/png"
10037
- };
10038
- case FieldType.SEARCH:
10039
- case FieldType.AUTOCOMPLETE:
10040
- case FieldType.HTTP:
10041
- return {
10042
- error: null,
10043
- data: { nid: "1234567890" },
10044
- loading: false
10045
- };
10046
- case FieldType.FILE_WITH_OPTIONS:
10047
- case FieldType.DATA:
10048
- case FieldType._EXPERIMENTAL_CUSTOM:
10049
- return void 0;
10050
- case FieldType.QR_READER:
10051
- return /* @__PURE__ */ Object.create(null);
10052
- case FieldType.ID_READER:
10053
- return /* @__PURE__ */ Object.create(null);
10054
- case FieldType.USER_ROLE:
10055
- return TestUserRole.enum.FIELD_AGENT;
10056
10090
  }
10091
+ return resolved;
10057
10092
  }
10058
- function fieldConfigsToActionPayload(fields, rng, administrativeHierarchy) {
10059
- return fields.reduce(
10060
- (acc, field3, i) => ({
10061
- ...acc,
10062
- [field3.id]: mapFieldTypeToMockValue(
10063
- field3,
10064
- i,
10065
- rng,
10066
- administrativeHierarchy
10067
- )
10068
- }),
10069
- {}
10093
+ function isSelectableAtAnchor(versions, anchor) {
10094
+ return versions.some((version) => version.effectiveFrom <= anchor) && resolveVersion(versions, anchor).status === "active";
10095
+ }
10096
+ function hasActiveExternalIdOnOrAfter(versions, externalId, anchor) {
10097
+ const inEffectAtAnchor = resolveVersion(versions, anchor);
10098
+ const laterVersions = versions.filter((v) => v.effectiveFrom > anchor);
10099
+ return [inEffectAtAnchor, ...laterVersions].some(
10100
+ (v) => v.externalId === externalId && v.status === "active"
10070
10101
  );
10071
10102
  }
10072
- function generateActionDeclarationInput(configuration, action, rng, overrides, administrativeHierarchy) {
10073
- const parsed = DeclarationUpdateActions.safeParse(action);
10074
- if ((0, import_lodash5.isEmpty)(overrides) && typeof overrides === "object") {
10075
- return {};
10103
+ function matchesJurisdictionFilter(locationIds, filter, user2) {
10104
+ if (!locationIds) {
10105
+ return false;
10076
10106
  }
10077
- if (parsed.success) {
10078
- const fields = getDeclarationFields(configuration);
10079
- const declarationConfig = getDeclaration(configuration);
10080
- const declaration = fieldConfigsToActionPayload(
10081
- fields,
10082
- rng,
10083
- administrativeHierarchy
10084
- );
10085
- return omitHiddenPaginatedFields(
10086
- declarationConfig,
10087
- {
10088
- ...declaration,
10089
- ...overrides
10090
- },
10091
- {},
10092
- // Intentionally empty. Allow generating fields with custom conditionals.
10093
- true
10094
- );
10107
+ if (filter === JurisdictionFilter.enum.location) {
10108
+ return locationIds.some((id) => id === user2.primaryOfficeId);
10095
10109
  }
10096
- console.warn(`${action} is not a declaration action. Setting data as {}.`);
10097
- return {};
10098
- }
10099
- function generateActionDuplicateDeclarationInput(...args) {
10100
- const [configuration, action, rng, overrides] = args;
10101
- return generateActionDeclarationInput(configuration, action, rng, {
10102
- ...overrides,
10103
- "applicant.dobUnknown": false
10104
- });
10110
+ if (filter === JurisdictionFilter.enum.administrativeArea) {
10111
+ return !user2.administrativeAreaId || locationIds.some((id) => id === user2.administrativeAreaId);
10112
+ }
10113
+ return true;
10105
10114
  }
10106
- function generateActionAnnotationInput(configuration, action, rng) {
10107
- const actionConfig = configuration.actions.find(
10108
- (ac) => ac.type === action
10109
- );
10110
- const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
10111
- const annotation = fieldConfigsToActionPayload(annotationFields, rng);
10112
- const visibleVerificationPageIds = getVisibleVerificationPageIds(
10113
- findRecordActionPages(configuration, action),
10114
- annotation,
10115
- {}
10116
- );
10117
- const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
10118
- (acc, pageId) => ({
10119
- ...acc,
10120
- [pageId]: true
10121
- }),
10122
- {}
10123
- );
10124
- const fieldBasedPayload = omitHiddenFields(
10125
- annotationFields,
10126
- annotation,
10127
- {}
10128
- // Intentionally empty. Allow generating fields with custom conditionals.
10129
- );
10130
- return {
10131
- ...fieldBasedPayload,
10132
- ...visiblePageVerificationMap
10133
- };
10115
+ function matchesFlagsFilter(eventFlags, flags) {
10116
+ const currentFlags = eventFlags ?? [];
10117
+ if (flags.anyOf && !flags.anyOf.some((flag2) => currentFlags.includes(flag2))) {
10118
+ return false;
10119
+ }
10120
+ if (flags.noneOf && flags.noneOf.some((flag2) => currentFlags.includes(flag2))) {
10121
+ return false;
10122
+ }
10123
+ if (flags.allOf && !flags.allOf.every((flag2) => currentFlags.includes(flag2))) {
10124
+ return false;
10125
+ }
10126
+ return true;
10134
10127
  }
10135
- function eventPayloadGenerator(rng, configuration = tennisClubMembershipEvent) {
10136
- return {
10137
- create: (input = {}) => ({
10138
- transactionId: input.transactionId ?? getUUID(),
10139
- type: input.type ?? configuration.id
10140
- }),
10141
- patch: (id, input = {}) => ({
10142
- transactionId: input.transactionId ?? getUUID(),
10143
- type: input.type ?? configuration.id,
10144
- id
10145
- }),
10146
- draft: ({
10147
- eventId,
10148
- actionType,
10149
- annotation,
10150
- omitFields = []
10151
- }, input = {}) => {
10152
- const base = {
10153
- id: getUUID(),
10154
- eventId,
10155
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10156
- transactionId: getUUID(),
10157
- action: {
10158
- transactionId: getUUID(),
10159
- type: actionType,
10160
- status: ActionStatus.Accepted,
10161
- declaration: {
10162
- "applicant.name": {
10163
- firstname: "Max",
10164
- surname: "McLaren"
10165
- },
10166
- "applicant.dob": "2020-01-02",
10167
- "applicant.image": {
10168
- path: "e56d1dd3-2cd4-452a-b54e-bf3e2d830605.png",
10169
- originalFilename: "Screenshot.png",
10170
- type: "image/png"
10171
- }
10172
- },
10173
- annotation: {
10174
- "correction.requester.relationship": "ANOTHER_AGENT",
10175
- "correction.request.reason": "Child's name was incorrect",
10176
- "identity-check": true,
10177
- ...annotation
10178
- },
10179
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10180
- createdBy: "@todo",
10181
- createdByUserType: TokenUserType.enum.user,
10182
- createdByRole: "@todo"
10183
- }
10184
- };
10185
- base.action.declaration = (0, import_lodash5.omit)(base.action.declaration, omitFields);
10186
- return (0, import_lodash5.merge)(base, input);
10187
- },
10188
- actions: {
10189
- declare: (eventId, input = {}) => ({
10190
- type: ActionType.DECLARE,
10191
- transactionId: input.transactionId ?? getUUID(),
10192
- declaration: input.declaration ?? generateActionDeclarationInput(
10193
- configuration,
10194
- ActionType.DECLARE,
10195
- rng
10196
- ),
10197
- annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.DECLARE, rng),
10198
- eventId,
10199
- ...input
10200
- }),
10201
- /**
10202
- * Notify allows sending incomplete data. Think it as 'partial declare' for now.
10203
- */
10204
- notify: (eventId, input = {}) => {
10205
- let declaration = input.declaration;
10206
- if (!declaration) {
10207
- const partialDeclaration = (0, import_lodash5.omitBy)(
10208
- generateActionDeclarationInput(
10209
- configuration,
10210
- ActionType.NOTIFY,
10211
- rng
10212
- ),
10213
- import_lodash5.isString
10214
- );
10215
- declaration = partialDeclaration;
10216
- }
10217
- return {
10218
- type: ActionType.NOTIFY,
10219
- transactionId: input.transactionId ?? getUUID(),
10220
- declaration,
10221
- eventId,
10222
- keepAssignment: input.keepAssignment
10223
- };
10224
- },
10225
- edit: (eventId, input = {}) => ({
10226
- type: ActionType.EDIT,
10227
- transactionId: input.transactionId ?? getUUID(),
10228
- declaration: input.declaration ?? generateActionDeclarationInput(configuration, ActionType.EDIT, rng),
10229
- annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.EDIT, rng),
10230
- eventId,
10231
- ...input
10232
- }),
10233
- assign: (eventId, input = {}) => ({
10234
- type: ActionType.ASSIGN,
10235
- transactionId: input.transactionId ?? getUUID(),
10236
- declaration: {},
10237
- assignedTo: input.assignedTo ?? getUUID(),
10238
- eventId
10239
- }),
10240
- unassign: (eventId, input = {}) => ({
10241
- type: ActionType.UNASSIGN,
10242
- transactionId: input.transactionId ?? getUUID(),
10243
- declaration: {},
10244
- assignedTo: null,
10245
- eventId
10246
- }),
10247
- archive: (eventId, input = {}) => ({
10248
- type: ActionType.ARCHIVE,
10249
- transactionId: input.transactionId ?? getUUID(),
10250
- declaration: {},
10251
- annotation: {},
10252
- eventId,
10253
- ...input
10254
- }),
10255
- unarchive: (eventId, input = {}) => ({
10256
- type: ActionType.UNARCHIVE,
10257
- transactionId: input.transactionId ?? getUUID(),
10258
- declaration: {},
10259
- annotation: {},
10260
- eventId,
10261
- ...input
10262
- }),
10263
- reject: (eventId, input = {}) => ({
10264
- type: ActionType.REJECT,
10265
- transactionId: input.transactionId ?? getUUID(),
10266
- declaration: {},
10267
- annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.REJECT, rng),
10268
- eventId,
10269
- content: { reason: `${ActionType.REJECT}` },
10270
- ...input
10271
- }),
10272
- register: (eventId, input = {}) => ({
10273
- type: ActionType.REGISTER,
10274
- transactionId: input.transactionId ?? getUUID(),
10275
- declaration: input.declaration ?? generateActionDeclarationInput(
10276
- configuration,
10277
- ActionType.REGISTER,
10278
- rng
10279
- ),
10280
- annotation: input.annotation ?? generateActionAnnotationInput(
10281
- configuration,
10282
- ActionType.REGISTER,
10283
- rng
10284
- ),
10285
- eventId,
10286
- ...input
10287
- }),
10288
- printCertificate: (eventId, input = {}) => ({
10289
- type: ActionType.PRINT_CERTIFICATE,
10290
- transactionId: input.transactionId ?? getUUID(),
10291
- declaration: {},
10292
- annotation: input.annotation ?? generateActionAnnotationInput(
10293
- configuration,
10294
- ActionType.PRINT_CERTIFICATE,
10295
- rng
10296
- ),
10297
- eventId,
10298
- ...input
10299
- }),
10300
- correction: {
10301
- request: (eventId, input = {}) => ({
10302
- type: ActionType.REQUEST_CORRECTION,
10303
- transactionId: input.transactionId ?? getUUID(),
10304
- declaration: input.declaration ?? (0, import_lodash5.omit)(
10305
- generateActionDeclarationInput(
10306
- configuration,
10307
- ActionType.REQUEST_CORRECTION,
10308
- rng
10309
- ),
10310
- ["applicant.email", "applicant.image"]
10311
- ),
10312
- annotation: input.annotation ?? generateActionAnnotationInput(
10313
- configuration,
10314
- ActionType.REQUEST_CORRECTION,
10315
- rng
10316
- ),
10317
- eventId,
10318
- keepAssignment: input.keepAssignment
10319
- }),
10320
- approve: (eventId, requestId, input = {}) => ({
10321
- type: ActionType.APPROVE_CORRECTION,
10322
- transactionId: input.transactionId ?? getUUID(),
10323
- declaration: {},
10324
- annotation: input.annotation ?? generateActionAnnotationInput(
10325
- configuration,
10326
- ActionType.APPROVE_CORRECTION,
10327
- rng
10328
- ),
10329
- eventId,
10330
- requestId,
10331
- keepAssignment: input.keepAssignment
10332
- }),
10333
- reject: (eventId, requestId, input) => ({
10334
- type: ActionType.REJECT_CORRECTION,
10335
- transactionId: input.transactionId ?? getUUID(),
10336
- declaration: {},
10337
- annotation: input.annotation ?? generateActionAnnotationInput(
10338
- configuration,
10339
- ActionType.REJECT_CORRECTION,
10340
- rng
10341
- ),
10342
- eventId,
10343
- requestId,
10344
- keepAssignment: input.keepAssignment,
10345
- content: input.content ?? { reason: "" }
10346
- })
10347
- },
10348
- duplicate: {
10349
- markAsDuplicate: (eventId, input = {}) => ({
10350
- type: ActionType.MARK_AS_DUPLICATE,
10351
- transactionId: input.transactionId ?? getUUID(),
10352
- declaration: input.declaration ?? generateActionDeclarationInput(
10353
- tennisClubMembershipEvent,
10354
- ActionType.REGISTER,
10355
- rng
10356
- ),
10357
- annotation: input.annotation ?? generateActionAnnotationInput(
10358
- tennisClubMembershipEvent,
10359
- ActionType.REGISTER,
10360
- rng
10361
- ),
10362
- eventId,
10363
- keepAssignment: input.keepAssignment
10364
- }),
10365
- markNotDuplicate: (eventId, input = {}) => ({
10366
- type: ActionType.MARK_AS_NOT_DUPLICATE,
10367
- transactionId: input.transactionId ?? getUUID(),
10368
- declaration: input.declaration ?? generateActionDeclarationInput(
10369
- tennisClubMembershipEvent,
10370
- ActionType.REGISTER,
10371
- rng
10372
- ),
10373
- annotation: input.annotation ?? generateActionAnnotationInput(
10374
- tennisClubMembershipEvent,
10375
- ActionType.REGISTER,
10376
- rng
10377
- ),
10378
- eventId,
10379
- keepAssignment: input.keepAssignment
10380
- })
10128
+ function canAccessEventWithScope(event2, scope, user2, customActionType) {
10129
+ const opts = scope.options;
10130
+ if (opts?.event) {
10131
+ if (!event2.type || !opts.event.includes(event2.type)) {
10132
+ return false;
10133
+ }
10134
+ }
10135
+ if (opts?.placeOfEvent === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10136
+ event2.placeOfEvent,
10137
+ JurisdictionFilter.enum.location,
10138
+ user2
10139
+ )) {
10140
+ return false;
10141
+ }
10142
+ if (opts?.placeOfEvent === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10143
+ event2.placeOfEvent,
10144
+ JurisdictionFilter.enum.administrativeArea,
10145
+ user2
10146
+ )) {
10147
+ return false;
10148
+ }
10149
+ if (opts?.createdBy === UserFilter.enum.user && event2.createdBy !== user2.id) {
10150
+ return false;
10151
+ }
10152
+ if (opts?.createdIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10153
+ event2.createdAtLocation,
10154
+ JurisdictionFilter.enum.location,
10155
+ user2
10156
+ )) {
10157
+ return false;
10158
+ }
10159
+ if (opts?.createdIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10160
+ event2.createdAtLocation,
10161
+ JurisdictionFilter.enum.administrativeArea,
10162
+ user2
10163
+ )) {
10164
+ return false;
10165
+ }
10166
+ if (scopeUsesDeclaredOptions(scope)) {
10167
+ const { options } = scope;
10168
+ if (options?.status && (!event2.status || !options.status.includes(event2.status))) {
10169
+ return false;
10170
+ }
10171
+ if (options?.notifiedBy === UserFilter.enum.user) {
10172
+ if (event2.legalStatuses?.NOTIFIED?.createdBy !== user2.id) {
10173
+ return false;
10174
+ }
10175
+ }
10176
+ if (options?.notifiedIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10177
+ event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10178
+ JurisdictionFilter.enum.location,
10179
+ user2
10180
+ )) {
10181
+ return false;
10182
+ }
10183
+ if (options?.notifiedIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10184
+ event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10185
+ JurisdictionFilter.enum.administrativeArea,
10186
+ user2
10187
+ )) {
10188
+ return false;
10189
+ }
10190
+ if (options?.declaredBy === UserFilter.enum.user) {
10191
+ if (event2.legalStatuses?.DECLARED?.createdBy !== user2.id) {
10192
+ return false;
10381
10193
  }
10382
10194
  }
10383
- };
10384
- }
10385
- function generateActionDocument({
10386
- configuration,
10387
- action,
10388
- rng = () => 0.1,
10389
- defaults,
10390
- declarationOverrides
10391
- }) {
10392
- const actionBase = {
10393
- // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
10394
- // @TODO: This should be fixed in the future.
10395
- createdAt: new Date(Date.now() - 500).toISOString(),
10396
- createdBy: generateUuid(rng),
10397
- createdByUserType: TokenUserType.enum.user,
10398
- createdByRole: TestUserRole.enum.FIELD_AGENT,
10399
- id: getUUID(),
10400
- createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10401
- declaration: generateActionDeclarationInput(
10402
- configuration,
10403
- action,
10404
- rng,
10405
- declarationOverrides
10406
- ),
10407
- annotation: {},
10408
- status: ActionStatus.Accepted,
10409
- transactionId: getUUID(),
10410
- ...defaults
10411
- };
10412
- switch (action) {
10413
- case ActionType.READ:
10414
- case ActionType.MARK_AS_NOT_DUPLICATE:
10415
- case ActionType.DECLARE:
10416
- case ActionType.UNASSIGN:
10417
- case ActionType.CREATE:
10418
- case ActionType.NOTIFY:
10419
- case ActionType.REGISTER:
10420
- case ActionType.REQUEST_CORRECTION:
10421
- case ActionType.UNARCHIVE:
10422
- return { ...actionBase, type: action };
10423
- case ActionType.EDIT:
10424
- return {
10425
- ...actionBase,
10426
- type: action,
10427
- content: { comment: "Test comment" }
10428
- };
10429
- case ActionType.CUSTOM:
10430
- return {
10431
- ...actionBase,
10432
- type: action,
10433
- customActionType: "CUSTOM_ACTION_TYPE"
10434
- };
10435
- case ActionType.MARK_AS_DUPLICATE:
10436
- return { ...actionBase, type: action, content: void 0 };
10437
- case ActionType.ASSIGN: {
10438
- const assignActionDefaults = defaults;
10439
- return {
10440
- ...actionBase,
10441
- assignedTo: assignActionDefaults?.assignedTo ?? getUUID(),
10442
- type: action
10443
- };
10195
+ if (options?.declaredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10196
+ event2.legalStatuses?.DECLARED?.createdAtLocation,
10197
+ JurisdictionFilter.enum.location,
10198
+ user2
10199
+ )) {
10200
+ return false;
10444
10201
  }
10445
- case ActionType.ARCHIVE:
10446
- return { ...actionBase, type: action, content: { reason: "Archive" } };
10447
- case ActionType.REJECT:
10448
- return { ...actionBase, type: action, content: { reason: "Reject" } };
10449
- case ActionType.PRINT_CERTIFICATE: {
10450
- const printActionDefaults = defaults;
10451
- return {
10452
- ...actionBase,
10453
- type: action,
10454
- content: printActionDefaults?.content
10455
- };
10202
+ if (options?.declaredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10203
+ event2.legalStatuses?.DECLARED?.createdAtLocation,
10204
+ JurisdictionFilter.enum.administrativeArea,
10205
+ user2
10206
+ )) {
10207
+ return false;
10456
10208
  }
10457
- case ActionType.APPROVE_CORRECTION:
10458
- return { ...actionBase, requestId: getUUID(), type: action };
10459
- case ActionType.REJECT_CORRECTION:
10460
- return {
10461
- ...actionBase,
10462
- requestId: getUUID(),
10463
- type: action,
10464
- content: { reason: "Correction rejection" }
10465
- };
10466
- case ActionType.DUPLICATE_DETECTED: {
10467
- const duplicateActionDefaults = defaults;
10468
- return {
10469
- ...actionBase,
10470
- type: action,
10471
- content: {
10472
- duplicates: duplicateActionDefaults?.content?.duplicates ?? []
10473
- }
10474
- };
10209
+ }
10210
+ if (scopeUsesFullOptions(scope) || scopeUsesPrintCertifiedCopiesOptions(scope) || isCustomActionScope(scope)) {
10211
+ const { options } = scope;
10212
+ if (options?.registeredBy === UserFilter.enum.user) {
10213
+ if (event2.legalStatuses?.REGISTERED?.createdBy !== user2.id) {
10214
+ return false;
10215
+ }
10216
+ }
10217
+ if (options?.registeredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10218
+ event2.legalStatuses?.REGISTERED?.createdAtLocation,
10219
+ JurisdictionFilter.enum.location,
10220
+ user2
10221
+ )) {
10222
+ return false;
10223
+ }
10224
+ if (options?.registeredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10225
+ event2.legalStatuses?.REGISTERED?.createdAtLocation,
10226
+ JurisdictionFilter.enum.administrativeArea,
10227
+ user2
10228
+ )) {
10229
+ return false;
10230
+ }
10231
+ if (options?.flags && !matchesFlagsFilter(event2.flags, options.flags)) {
10232
+ return false;
10475
10233
  }
10476
- case ActionType.DELETE:
10477
- default:
10478
- throw new Error(`Unsupported action type: ${action}`);
10479
10234
  }
10235
+ if (isCustomActionScope(scope)) {
10236
+ const { options } = scope;
10237
+ if (!customActionType || !options?.customActionTypes || !options?.customActionTypes.includes(customActionType)) {
10238
+ return false;
10239
+ }
10240
+ }
10241
+ return true;
10480
10242
  }
10481
- function generateRandomDatetime(rng, start, end) {
10482
- const range = end.getTime() - start.getTime();
10483
- const offset = Math.floor(rng() * range);
10484
- const randomDate = new Date(start.getTime() + offset);
10485
- return randomDate.toISOString();
10486
- }
10487
- function getRandomDate(rng, start, end) {
10488
- const datetime = generateRandomDatetime(rng, new Date(start), new Date(end));
10489
- return datetime.split("T")[0];
10243
+ function canAccessUserWithScope({
10244
+ userToAccess,
10245
+ scope,
10246
+ user: user2
10247
+ }) {
10248
+ const opts = scope.options;
10249
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
10250
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
10251
+ return false;
10252
+ }
10253
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
10254
+ (id) => user2.administrativeAreaId === id
10255
+ ) || !user2.administrativeAreaId;
10256
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
10257
+ return false;
10258
+ }
10259
+ if (scopeUsesRoleOptions(scope)) {
10260
+ const { options } = scope;
10261
+ if (options?.role && !options.role.includes(userToAccess.role)) {
10262
+ return false;
10263
+ }
10264
+ }
10265
+ return true;
10490
10266
  }
10491
- function generateEventDocument({
10492
- configuration,
10493
- actions,
10494
- rng = () => 0.1,
10495
- defaults = {}
10267
+ function canAccessOtherUserWithScopes({
10268
+ scopes,
10269
+ userToAccess,
10270
+ user: user2
10496
10271
  }) {
10497
- return {
10498
- trackingId: generateTrackingId(rng),
10499
- type: configuration.id,
10500
- actions: actions.map(
10501
- (action, i) => generateActionDocument({
10502
- configuration,
10503
- action: action.type,
10504
- defaults: {
10505
- createdBy: action.user?.id,
10506
- createdAtLocation: action.user?.primaryOfficeId,
10507
- assignedTo: action.user?.assignedTo,
10508
- createdByRole: action.user?.role,
10509
- createdAt: (0, import_date_fns4.addDays)(
10510
- new Date(
10511
- generateRandomDatetime(
10512
- rng,
10513
- new Date(2025, 0, 1),
10514
- new Date(2025, 11, 31)
10515
- )
10516
- ),
10517
- i
10518
- ).toISOString()
10519
- },
10520
- declarationOverrides: action.declarationOverrides
10521
- })
10522
- ),
10523
- // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
10524
- // @TODO: This should be fixed in the future.
10525
- createdAt: new Date(Date.now() - 1e3).toISOString(),
10526
- id: getUUID(),
10527
- // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
10528
- // @TODO: This should be fixed in the future.
10529
- updatedAt: new Date(Date.now() - 1e3).toISOString(),
10530
- ...defaults
10531
- };
10272
+ return scopes.some(
10273
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
10274
+ );
10275
+ }
10276
+ function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10277
+ return scopes.some(
10278
+ (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
10279
+ );
10280
+ }
10281
+ function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
10282
+ const collectedLocations = [];
10283
+ const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
10284
+ let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
10285
+ while (current) {
10286
+ collectedLocations.push(current);
10287
+ if (!current.parentId) {
10288
+ break;
10289
+ }
10290
+ const parentId = current.parentId;
10291
+ current = administrativeAreas.get(parentId);
10292
+ }
10293
+ return collectedLocations;
10294
+ }
10295
+ function getLocationHierarchy(selectedId, context) {
10296
+ const { administrativeAreas, locations } = context;
10297
+ const loc = locations.get(selectedId);
10298
+ if (loc) {
10299
+ if (loc.administrativeAreaId) {
10300
+ const hierarchy2 = getAdministrativeAreaHierarchy(
10301
+ loc.administrativeAreaId,
10302
+ administrativeAreas
10303
+ );
10304
+ return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10305
+ }
10306
+ return [loc.id];
10307
+ }
10308
+ const hierarchy = getAdministrativeAreaHierarchy(
10309
+ selectedId,
10310
+ administrativeAreas
10311
+ );
10312
+ return hierarchy.reverse().map((area) => area.id);
10532
10313
  }
10533
- function generateEventDraftDocument({
10534
- eventId,
10535
- actionType,
10536
- rng = () => 0.1,
10537
- declaration = {}
10538
- }) {
10539
- const action = generateActionDocument({
10540
- configuration: tennisClubMembershipEvent,
10541
- action: actionType,
10542
- rng
10314
+ function resolvePath(locationId, anchor, context) {
10315
+ return getLocationHierarchy(locationId, context).flatMap((id) => {
10316
+ const node = context.locations.get(id) ?? context.administrativeAreas.get(id);
10317
+ if (!node) {
10318
+ return [];
10319
+ }
10320
+ const { name, status: status2 } = resolveVersion(node.versions, anchor);
10321
+ return [{ id, name, status: status2 }];
10543
10322
  });
10544
- return {
10545
- id: getUUID(),
10546
- transactionId: getUUID(),
10547
- action: {
10548
- ...action,
10549
- declaration: {
10550
- ...action.declaration,
10551
- ...declaration
10552
- },
10553
- annotation: action.annotation
10554
- },
10555
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10556
- eventId
10557
- };
10558
10323
  }
10559
- function generateRandomApplicant(rng) {
10560
- const { firstname, surname } = generateRandomName(rng);
10561
- const randomDob = getRandomDate(rng, "1990-01-01", "2010-12-31");
10324
+
10325
+ // ../commons/src/events/mocks.test.utils.ts
10326
+ function withVersionFields(entity) {
10562
10327
  return {
10563
- "recommender.none": true,
10564
- "applicant.name": {
10565
- firstname,
10566
- surname
10567
- },
10568
- "applicant.dob": randomDob
10569
- };
10570
- }
10571
- function createPrng(seed) {
10572
- const MODULUS = 2 ** 32;
10573
- const MULTIPLIER = 1664525;
10574
- const INCREMENT = 1013904223;
10575
- let state = seed >>> 0;
10576
- return () => {
10577
- state = (MULTIPLIER * state + INCREMENT) % MODULUS;
10578
- return state / MODULUS;
10328
+ ...entity,
10329
+ status: "active",
10330
+ versions: [
10331
+ {
10332
+ versionId: entity.id,
10333
+ effectiveFrom: "0001-01-01",
10334
+ name: entity.name,
10335
+ externalId: entity.externalId ?? null,
10336
+ status: "active"
10337
+ }
10338
+ ]
10579
10339
  };
10580
10340
  }
10581
- var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
10582
- const rng = createPrng(seed);
10583
- const createdAt = generateRandomDatetime(
10584
- rng,
10585
- /* @__PURE__ */ new Date("2024-01-01"),
10586
- /* @__PURE__ */ new Date("2024-12-31")
10587
- );
10588
- return {
10589
- id: overrides.id ?? generateUuid(rng),
10590
- type: overrides.type ?? TENNIS_CLUB_MEMBERSHIP,
10591
- status: overrides.status ?? pickRandom(rng, EventStatus.options),
10592
- createdAt: overrides.createdAt ?? createdAt,
10593
- createdByUserType: overrides.createdByUserType ?? "user",
10594
- createdBy: overrides.createdBy ?? generateUuid(rng),
10595
- createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
10596
- updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
10597
- updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
10598
- assignedTo: overrides.assignedTo ?? null,
10599
- updatedBy: overrides.updatedBy ?? generateUuid(rng),
10600
- updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
10601
- flags: overrides.flags ?? [],
10602
- potentialDuplicates: [],
10603
- legalStatuses: overrides.legalStatuses ?? {},
10604
- declaration: overrides.declaration ?? generateRandomApplicant(rng),
10605
- trackingId: overrides.trackingId ?? generateTrackingId(rng)
10606
- };
10607
- };
10608
- var generateTranslationConfig2 = (message) => ({
10609
- defaultMessage: message,
10610
- description: "Description for ${message}",
10611
- id: message.trim().replace(/\s+/g, "_").toLowerCase()
10612
- });
10613
- var BearerTokenByUserType = {
10614
- fieldAgent: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJyZWNvcmQuZGVjbGFyYXRpb24tc3VibWl0LWZvci1yZXZpZXciLCJzZWFyY2guYmlydGgiLCJzZWFyY2guZGVhdGgiLCJzZWFyY2gubWFycmlhZ2UiLCJ3b3JrcXVldWVbaWQ9YWxsLWV2ZW50c3xhc3NpZ25lZC10by15b3V8cmVjZW50fHJlcXVpcmVzLXVwZGF0ZXN8c2VudC1mb3ItcmV2aWV3XSIsInR5cGU9cmVjb3JkLnNlYXJjaCZldmVudD1iaXJ0aCxkZWF0aCx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwLGNoaWxkLW9uYm9hcmRpbmcsRk9PVEJBTExfQ0xVQl9NRU1CRVJTSElQIiwidHlwZT1yZWNvcmQuY3JlYXRlJmV2ZW50PWJpcnRoLGRlYXRoLHRlbm5pcy1jbHViLW1lbWJlcnNoaXAsY2hpbGQtb25ib2FyZGluZyIsInR5cGU9cmVjb3JkLnJlYWQmZXZlbnQ9YmlydGgsZGVhdGgsdGVubmlzLWNsdWItbWVtYmVyc2hpcCxjaGlsZC1vbmJvYXJkaW5nIiwicmVjb3JkLmRlY2xhcmVbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5ub3RpZnlbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5kZWNsYXJlZC5lZGl0W2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iXSwidXNlclR5cGUiOiJ1c2VyIiwicm9sZSI6IkZJRUxEX0FHRU5UIiwiaWF0IjoxNDg3MDc2NzA4LCJhdWQiOiJvcGVuY3J2czpnYXRld2F5LXVzZXIiLCJpc3MiOiJvcGVuY3J2czphdXRoLXNlcnZpY2UiLCJzdWIiOiI2N2VmN2Y4M2Q2YTljYjkyZTllZGFhOTkifQ.E8WIcdgqh_VCYgeOCXBupL9nZgiKtplHQfmwsxoONYfhGEQHilffsFV5nX610McorETRQRQ7ZNY-6v9YaAJVFfHiHTBB4US6D3qS6yI7HicUR2Evh9N10rNm81kXquum58kEqOIfrMkr-CGqIrVS15Qz0LAPGyCq_5t1arEXOL_Lonc54GFV-Q2fhR5hh9oZ3Aconen0V4tbX9MX7iCJ3qjDraeGVrhnjG5yLtl2e7TjpU2kN8nltxokyvUiiRh71Vl786yF9ULb_UWjJXoQPO0SnVyfZti936piAuLhEXhlK-qsUBB8kmz7qScgrt8dZQMoVBuwxSfStMLGkCHu-OwzeryACRd8Iei0SR9mq4rqpX1NAQBwMGUYJqYoWYGjDjUMa11pTDiWsSw0H5R4i7LnGQP7H5wbM57t09vxX8XL9msBrCD7-vtTvjafvYSpekVwI8hZP-w8Bzb0QuL9y_bf6Hae0AJDyZ1y1NXAvUbyRvgSs5wbGldu6CB9k9ZPN7KS4aPaYlWzNhF0_D-U4zU1fRTFOxd_x5DyciYTRPMpL69WieNtlRYwk4QgN-AGXxuYlJ2mK716rw9QXSGDepEYvKU2rBVkZEgBPbIO_J6Hrg30mEnQqhrsrHVwhZ3FDdONJOcqy3ELkdWjUjMnXOORcgQTYnaTjOTKvpJlbts",
10615
- registrationAgent: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJyZWNvcmQuZGVjbGFyYXRpb24tZWRpdCIsInJlY29yZC5kZWNsYXJhdGlvbi1yZWluc3RhdGUiLCJwZXJmb3JtYW5jZS5yZWFkIiwicGVyZm9ybWFuY2UucmVhZC1kYXNoYm9hcmRzIiwib3JnYW5pc2F0aW9uLnJlYWQtbG9jYXRpb25zOm15LW9mZmljZSIsInVzZXIucmVhZDpvbmx5LW15LWF1ZGl0Iiwic2VhcmNoLmJpcnRoIiwic2VhcmNoLmRlYXRoIiwic2VhcmNoLm1hcnJpYWdlIiwid29ya3F1ZXVlW2lkPWFsbC1ldmVudHN8YXNzaWduZWQtdG8teW91fHJlY2VudHxyZXF1aXJlcy1jb21wbGV0aW9ufHJlcXVpcmVzLXVwZGF0ZXN8aW4tcmV2aWV3fHNlbnQtZm9yLWFwcHJvdmFsfGluLWV4dGVybmFsLXZhbGlkYXRpb258cmVhZHktdG8tcHJpbnR8cmVhZHktdG8taXNzdWVdIiwidHlwZT1yZWNvcmQuc2VhcmNoJmV2ZW50PWJpcnRoLGRlYXRoLHRlbm5pcy1jbHViLW1lbWJlcnNoaXAsY2hpbGQtb25ib2FyZGluZyxGT09UQkFMTF9DTFVCX01FTUJFUlNISVAiLCJ0eXBlPXJlY29yZC5jcmVhdGUmZXZlbnQ9YmlydGgsZGVhdGgsdGVubmlzLWNsdWItbWVtYmVyc2hpcCxjaGlsZC1vbmJvYXJkaW5nIiwidHlwZT1yZWNvcmQucmVhZCZldmVudD1iaXJ0aCxkZWF0aCx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwLGNoaWxkLW9uYm9hcmRpbmciLCJyZWNvcmQuZGVjbGFyZVtldmVudD1iaXJ0aHxkZWF0aHx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwfGNoaWxkLW9uYm9hcmRpbmddIiwicmVjb3JkLmRlY2xhcmVkLnJlamVjdFtldmVudD1iaXJ0aHxkZWF0aHx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwfGNoaWxkLW9uYm9hcmRpbmddIiwicmVjb3JkLmRlY2xhcmVkLmVkaXRbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5kZWNsYXJlZC5hcmNoaXZlW2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQucmVnaXN0ZXJlZC5wcmludC1jZXJ0aWZpZWQtY29waWVzW2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQucmVnaXN0ZXJlZC5yZXF1ZXN0LWNvcnJlY3Rpb25bZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSJdLCJ1c2VyVHlwZSI6InVzZXIiLCJyb2xlIjoiUkVHSVNUUkFUSU9OX0FHRU5UIiwiaWF0IjoxNDg3MDc2NzA4LCJhdWQiOiJvcGVuY3J2czpnYXRld2F5LXVzZXIiLCJpc3MiOiJvcGVuY3J2czphdXRoLXNlcnZpY2UiLCJzdWIiOiI2N2VmN2Y4M2Q2YTljYjkyZTllZGFhYTEifQ.SQ6gC8Fpmm9LBgUc0Ae-ABiEx8MeBHAXBZhIImbL_i6u81zD25-5Tbfxj_75ZzzeZYCDj8npO-a6BwQqzejgACrK_U3CPhMTrO9z4lTSHJRjIQBWnuhwEhJyPH4zxHflT5xOIsGfhYK-Ois41E9qdeRj8XhDVdbSFt3NZbog9odcXOlUml0OgX34Y_2bHYnHiUEowoUAQMTJGT2DVrQo2Z5uf1XPr3rD67WafZucttlDwW_Xo75QtT9Bvvt-ORL0xGtn0XOftHXLbD0IzdCckFZDXo0FK6FNixxj0DazM1Mi69A-BjdmB1WGTrtrnhYMlJpWn9-aJl51CIpRS0vhL2qsSq3rKjtY6K3M1sbyOGZ5HVS8xPxo2ZVfbWmBX1jiJGN9heoXnoPq3yuAa_fS2_kwAfEeFwv7OiYGc_HiSDJnY2fALVtE9Szx_LJjDmjYDpTAdg0YFMOafrl6Cl9zMBMSi8P8Lv7ZNIKOq0x8sak4-fsgpfdYlMJGRP4Am97lhQG3Tod2ca43iS0YmudszhVlbP3Sv-dx4OSbQ1EqWvaajKZQ9cvqAESH_UIbH_2cYnsnUkQoJJa-j4EBLpibDsWt36dlmgPxBoKpO3ib5FFNEXNY6ac-obfkZmWw33ihCY8sFMkfaddvg_01O_fFHPFVzJ3GnUmHTO8t2mFVi3Q",
10616
- localRegistrar: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJyZWNvcmQuZGVjbGFyYXRpb24tZWRpdCIsInJlY29yZC5yZXZpZXctZHVwbGljYXRlcyIsInJlY29yZC5kZWNsYXJhdGlvbi1yZWluc3RhdGUiLCJyZWNvcmQuY29uZmlybS1yZWdpc3RyYXRpb24iLCJyZWNvcmQucmVqZWN0LXJlZ2lzdHJhdGlvbiIsInBlcmZvcm1hbmNlLnJlYWQiLCJwZXJmb3JtYW5jZS5yZWFkLWRhc2hib2FyZHMiLCJwcm9maWxlLmVsZWN0cm9uaWMtc2lnbmF0dXJlIiwib3JnYW5pc2F0aW9uLnJlYWQtbG9jYXRpb25zOm15LW9mZmljZSIsInNlYXJjaC5iaXJ0aCIsInNlYXJjaC5kZWF0aCIsInNlYXJjaC5tYXJyaWFnZSIsIndvcmtxdWV1ZVtpZD1hbGwtZXZlbnRzfGFzc2lnbmVkLXRvLXlvdXxyZWNlbnR8cmVxdWlyZXMtY29tcGxldGlvbnxyZXF1aXJlcy11cGRhdGVzfGluLXJldmlldy1hbGx8aW4tZXh0ZXJuYWwtdmFsaWRhdGlvbnxyZWFkeS10by1wcmludHxyZWFkeS10by1pc3N1ZV0iLCJ0eXBlPXJlY29yZC5zZWFyY2gmZXZlbnQ9YmlydGgsZGVhdGgsdGVubmlzLWNsdWItbWVtYmVyc2hpcCxjaGlsZC1vbmJvYXJkaW5nLEZPT1RCQUxMX0NMVUJfTUVNQkVSU0hJUCIsInVzZXIucmVhZDpvbmx5LW15LWF1ZGl0IiwidHlwZT1yZWNvcmQuY3JlYXRlJmV2ZW50PWJpcnRoLGRlYXRoLHRlbm5pcy1jbHViLW1lbWJlcnNoaXAsY2hpbGQtb25ib2FyZGluZyIsInR5cGU9cmVjb3JkLnJlYWQmZXZlbnQ9YmlydGgsZGVhdGgsdGVubmlzLWNsdWItbWVtYmVyc2hpcCxjaGlsZC1vbmJvYXJkaW5nIiwicmVjb3JkLmRlY2xhcmVbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5kZWNsYXJlZC5yZWplY3RbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5kZWNsYXJlZC5hcmNoaXZlW2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQucmVnaXN0ZXJbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5kZWNsYXJlZC5lZGl0W2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQucmVnaXN0ZXJlZC5wcmludC1jZXJ0aWZpZWQtY29waWVzW2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQucmVnaXN0ZXJlZC5jb3JyZWN0W2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQudW5hc3NpZ24tb3RoZXJzW2V2ZW50PWJpcnRofGRlYXRofHRlbm5pcy1jbHViLW1lbWJlcnNoaXB8Y2hpbGQtb25ib2FyZGluZ10iLCJyZWNvcmQuZGVjbGFyZWQucmV2aWV3LWR1cGxpY2F0ZXNbZXZlbnQ9YmlydGh8ZGVhdGh8dGVubmlzLWNsdWItbWVtYmVyc2hpcHxjaGlsZC1vbmJvYXJkaW5nXSIsInJlY29yZC5jdXN0b20tYWN0aW9uW2V2ZW50PXRlbm5pcy1jbHViLW1lbWJlcnNoaXAsY3VzdG9tQWN0aW9uVHlwZT1BcHByb3ZlXSJdLCJ1c2VyVHlwZSI6InVzZXIiLCJyb2xlIjoiTE9DQUxfUkVHSVNUUkFSIiwiaWF0IjoxNDg3MDc2NzA4LCJhdWQiOiJvcGVuY3J2czpnYXRld2F5LXVzZXIiLCJpc3MiOiJvcGVuY3J2czphdXRoLXNlcnZpY2UiLCJzdWIiOiI2ODIxYzE3NWRjZTRkNzg4NmQ0ZTgyMTAifQ.HqPFpOLxTlhr9QARUgWuWpiSxbNVxOiW7tGzz_EoGlZWckoxy23i9Cp0oyjF-GCJbGTT2zfdWROAzvcuD43l1wFiYRMy8rOP3o0PH_k5eAijuMfI1Y9oXuMsZZaMBaDqrx4hHAF5uyitJ8qeAKXGF8ifryKFRdC2iSPrlBhjvKJwT-aaj4MThT_rNFrsVHlW1n-hJ78nyhUKTbgb4qmY92rxVxfJzW1vDy2bhxiJCIoPtluCvUjq6fGJOcaw9f4VuLqnt7b4fke7LN-av-eExPAXijDHyYr5L2vNIQ_4AjKQse6PM_t_7qUbOAzdkfySDsSNFLwjsy0cX8xovPJFr2E1S20-NmA6moiMghi34proGzDBs8750Wk724hSTwuFrvj3cT1nekCgkVa41b7b5E88ys5d6A48fkracYUrn0DwPs3Fbm8d6Z2kMnNAELQ_xPbBAkN8-ySwxS1dhTKtAG3gXbbIOG2jpnVQaugZaaCSZTCFA26Tw5x9wYOtR_GCeGI1lU2zd8_zjxlJA8g5zs186sPkkyWRy_J_xP2KIKfK4vBQ4FpcCDeoUh6B5sT4Bq_38PwzsC2gshzl4Np9oh9bVWbZC5Z7SLqE4TJzXDOWaoKRt6wFEfZhJjG7MYnAD2PD0YzTWyPKFn4sqZI7-zNajHfUDC-yXyIiiohQNkI"
10617
- };
10618
- var generateWorkqueues = (slug = "all-events") => defineWorkqueues([
10341
+ var MOCK_ADMINISTRATIVE_AREAS_BASE = [
10342
+ {
10343
+ id: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10344
+ name: "Central",
10345
+ parentId: null,
10346
+ externalId: "ydyJb1RAy4U1"
10347
+ },
10348
+ {
10349
+ id: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10350
+ name: "Sulaka",
10351
+ parentId: null,
10352
+ externalId: "pQ8nGxWmZ2Q3"
10353
+ },
10354
+ {
10355
+ id: "7ef2b9c7-5e6d-49f6-ae05-656207d0fc64",
10356
+ name: "Pualula",
10357
+ parentId: null,
10358
+ externalId: "Aq91DweLmT8k"
10359
+ },
10360
+ {
10361
+ id: "6d1a59df-988c-4021-a846-ccbc021931a7",
10362
+ name: "Chuminga",
10363
+ parentId: null,
10364
+ externalId: "Rw0fYNh2Xk9a"
10365
+ },
10366
+ {
10367
+ id: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10368
+ name: "Ibombo",
10369
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10370
+ externalId: "k7DsP4vbN1Qe"
10371
+ },
10372
+ {
10373
+ id: "27160bbd-32d1-4625-812f-860226bfb92a",
10374
+ name: "Isango",
10375
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10376
+ externalId: "Gm3Z9eQpHw4L"
10377
+ },
10378
+ {
10379
+ id: "967032fd-3f81-478a-826c-30cb8fe121bd",
10380
+ name: "Isamba",
10381
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10382
+ externalId: "sT0xVu1KqJ7r"
10383
+ },
10384
+ {
10385
+ id: "89a33893-b17d-481d-a26d-6461e7ac1651",
10386
+ name: "Itambo",
10387
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10388
+ externalId: "Nq6Bv2HpL9Te"
10389
+ },
10390
+ {
10391
+ id: "d42ab2fe-e7ed-470e-8b31-4fb27f9b8250",
10392
+ name: "Ezhi",
10393
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10394
+ externalId: "xK8cQ0ZRy5Wd"
10395
+ },
10396
+ {
10397
+ id: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
10398
+ name: "Ilanga",
10399
+ parentId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10400
+ externalId: "Cq4Jm1XvN8Ls"
10401
+ },
10402
+ // Villages under Ibombo (62a0ccb4-880d-4f30-8882-f256007dfff9)
10403
+ {
10404
+ id: "1d4e5f6a-7b8c-4912-8efa-345678901234",
10405
+ name: "Klow",
10406
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10407
+ externalId: "IkYcYBUcyY2"
10408
+ },
10409
+ {
10410
+ id: "2e5f6a7b-8c9d-4a23-8fab-456789012345",
10411
+ name: "Mbondo",
10412
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10413
+ externalId: "Qhvv5hvo3mY"
10414
+ },
10415
+ {
10416
+ id: "3f6a7b8c-9d0e-4b34-8abc-567890123456",
10417
+ name: "Ndara",
10418
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10419
+ externalId: "crXh068O9TR"
10420
+ },
10421
+ {
10422
+ id: "4a7b8c9d-0e1f-4c45-abcd-678901234567",
10423
+ name: "Olani",
10424
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10425
+ externalId: "r00It8Tvvp7"
10426
+ },
10427
+ {
10428
+ id: "5b8c9d0e-1f2a-4d56-bcde-789012345678",
10429
+ name: "Pemba",
10430
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10431
+ externalId: "ZnUWsbONIaH"
10432
+ },
10433
+ {
10434
+ id: "6c9d0e1f-2a3b-4e67-8def-890123456789",
10435
+ name: "Quanza",
10436
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10437
+ externalId: "fDZycvQTa7l"
10438
+ },
10439
+ {
10440
+ id: "7d0e1f2a-3b4c-4f78-8efa-901234567890",
10441
+ name: "Rivka",
10442
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10443
+ externalId: "KqswxCGTELa"
10444
+ },
10445
+ // Villages under Isamba (967032fd-3f81-478a-826c-30cb8fe121bd)
10446
+ {
10447
+ id: "8e1f2a3b-4c5d-4089-8fab-012345678901",
10448
+ name: "Mbula",
10449
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10450
+ externalId: "osEbKjRc9Kg"
10451
+ },
10452
+ {
10453
+ id: "9f2a3b4c-5d6e-4190-8abf-123456789012",
10454
+ name: "Ndoki",
10455
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10456
+ externalId: "aq4daBUAGr3"
10457
+ },
10458
+ {
10459
+ id: "0a3b4c5d-6e7f-4201-abcd-234567890123",
10460
+ name: "Tsanga",
10461
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10462
+ externalId: "cqis6Y8trbJ"
10463
+ },
10464
+ {
10465
+ id: "1b4c5d6e-7f8a-4312-bcde-345678901234",
10466
+ name: "Waziri",
10467
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10468
+ externalId: "LMijHPyyx6d"
10469
+ },
10470
+ {
10471
+ id: "2c5d6e7f-8a9b-4423-8def-456789012345",
10472
+ name: "Zimbi",
10473
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10474
+ externalId: "pcQYbPuKGZ7"
10475
+ },
10476
+ // Villages under Itambo (89a33893-b17d-481d-a26d-6461e7ac1651)
10477
+ {
10478
+ id: "3d6e7f8a-9b0c-4534-8efa-567890123456",
10479
+ name: "Felani",
10480
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10481
+ externalId: "gSqpoCGdMXp"
10482
+ },
10483
+ {
10484
+ id: "4e7f8a9b-0c1d-4645-8fab-678901234567",
10485
+ name: "Goroma",
10486
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10487
+ externalId: "KvAAIaNqVrp"
10488
+ },
10489
+ {
10490
+ id: "5f8a9b0c-1d2e-4756-8abc-789012345678",
10491
+ name: "Halifu",
10492
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10493
+ externalId: "qe4UnEVt1hv"
10494
+ },
10495
+ {
10496
+ id: "6a9b0c1d-2e3f-4867-abcd-890123456789",
10497
+ name: "Jabari",
10498
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10499
+ externalId: "yHH9Nz4rLOt"
10500
+ },
10619
10501
  {
10620
- slug,
10621
- name: {
10622
- id: "workqueues.inProgress.title",
10623
- defaultMessage: slug.charAt(0).toUpperCase() + slug.slice(1).split("-").join(" "),
10624
- description: "Title of in progress workqueue"
10625
- },
10626
- query: {
10627
- type: "and",
10628
- clauses: [{ eventType: tennisClubMembershipEvent.id }]
10629
- },
10630
- action: { type: ActionType.READ },
10631
- icon: "Draft"
10632
- }
10633
- ]);
10634
- var generateEventConfig = ({
10635
- id,
10636
- fields,
10637
- placeOfEventId,
10638
- dateOfEventId
10639
- }) => {
10640
- return defineConfig({
10641
- id,
10642
- label: generateTranslationConfig2(id),
10643
- title: generateTranslationConfig2(`${id} Event`),
10644
- summary: {
10645
- fields: []
10646
- },
10647
- placeOfEvent: placeOfEventId ? { $$field: placeOfEventId } : void 0,
10648
- dateOfEvent: dateOfEventId ? { $$field: dateOfEventId } : void 0,
10649
- declaration: {
10650
- label: generateTranslationConfig2(`${id} Declaration`),
10651
- pages: [
10652
- {
10653
- id: "page1",
10654
- title: generateTranslationConfig2("Page 1"),
10655
- fields
10656
- }
10657
- ]
10658
- },
10659
- actions: [
10660
- {
10661
- type: ActionType.READ,
10662
- label: generateTranslationConfig2("Read"),
10663
- review: {
10664
- title: generateTranslationConfig2("Review Read Action"),
10665
- fields: []
10666
- }
10667
- },
10668
- {
10669
- type: ActionType.DECLARE,
10670
- label: generateTranslationConfig2("Declare"),
10671
- review: {
10672
- title: generateTranslationConfig2("Review Declare Action"),
10673
- fields: []
10674
- }
10675
- }
10676
- ]
10677
- });
10678
- };
10679
-
10680
- // ../commons/src/events/TemplateConfig.ts
10681
- var window2 = () => ({
10682
- location: {
10683
- get: (key) => {
10684
- return `$window.location.${key}`;
10685
- }
10686
- }
10687
- });
10688
- function isTemplateVariable(value) {
10689
- return typeof value === "string" && value.startsWith("$");
10690
- }
10691
- function isFieldValue(value) {
10692
- return FieldValue.safeParse(value).success;
10693
- }
10694
- function isFieldValueWithoutTemplates(value) {
10695
- if (isTemplateVariable(value)) {
10696
- return false;
10697
- }
10698
- if (typeof value === "object" && value !== null && Object.values(value).some((val) => isTemplateVariable(val))) {
10699
- return false;
10700
- }
10701
- return true;
10702
- }
10703
- function isFieldConfigDefaultValue(value) {
10704
- if (!value) {
10705
- return false;
10706
- }
10707
- if (isFieldValue(value)) {
10708
- return true;
10709
- }
10710
- if (isTemplateVariable(value)) {
10711
- return true;
10502
+ id: "7b0c1d2e-3f4a-4978-bcde-901234567890",
10503
+ name: "Kifani",
10504
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10505
+ externalId: "eSWmXIGeu1I"
10506
+ },
10507
+ {
10508
+ id: "8c1d2e3f-4a5b-4089-8def-012345678901",
10509
+ name: "Lumela",
10510
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10511
+ externalId: "bh0b3aI1uP3"
10712
10512
  }
10713
- if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
10714
- return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
10513
+ ];
10514
+ var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS = MOCK_ADMINISTRATIVE_AREAS_BASE.map(withVersionFields);
10515
+ var MOCK_LOCATIONS_BASE = [
10516
+ {
10517
+ id: "6f6186ce-cd5f-4a5f-810a-2d99e7c4ba12",
10518
+ name: "Central Provincial Office",
10519
+ locationType: "CRVS_OFFICE",
10520
+ administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10521
+ externalId: "Xr3Df8WpK6Ys"
10522
+ },
10523
+ {
10524
+ id: "b1c2d3e4-f5a6-7890-bcde-f12345678901",
10525
+ name: "Central Health Post",
10526
+ locationType: "HEALTH_FACILITY",
10527
+ administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c"
10528
+ },
10529
+ {
10530
+ id: "028d2c85-ca31-426d-b5d1-2cef545a4902",
10531
+ name: "Ibombo District Office",
10532
+ locationType: "CRVS_OFFICE",
10533
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10534
+ externalId: "Sm4Nw7GrD2Vy"
10535
+ },
10536
+ {
10537
+ id: "62a0ccb4-4f30-4f30-8882-f256007dff9f",
10538
+ name: "Isamba District Office",
10539
+ locationType: "CRVS_OFFICE",
10540
+ administrativeAreaId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10541
+ externalId: "Vg1Bq5XeH9Lt"
10542
+ },
10543
+ {
10544
+ id: "954c93e1-13f7-4435-bb82-35e0e215e07d",
10545
+ name: "Isango District Office",
10546
+ locationType: "CRVS_OFFICE",
10547
+ administrativeAreaId: "27160bbd-32d1-4625-812f-860226bfb92a",
10548
+ externalId: "Je7Lm2XqN9Vz"
10549
+ },
10550
+ {
10551
+ id: "2884f5b9-17b4-49ce-bf4d-f538228935df",
10552
+ name: "Sulaka Provincial Office",
10553
+ locationType: "CRVS_OFFICE",
10554
+ administrativeAreaId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10555
+ externalId: "Ht2Wp9KcX5Qv"
10556
+ },
10557
+ {
10558
+ id: "030358c6-54af-44be-821b-8e4af963a49c",
10559
+ name: "Ilanga District Office",
10560
+ locationType: "CRVS_OFFICE",
10561
+ administrativeAreaId: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
10562
+ externalId: "Yp6Ds1WqN3Xz"
10563
+ },
10564
+ {
10565
+ id: "423d000f-101b-47c0-8b86-21a908067cee",
10566
+ name: "Chamakubi Health Post",
10567
+ locationType: "HEALTH_FACILITY",
10568
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10569
+ externalId: "M1nFr8LbC2Qy"
10570
+ },
10571
+ {
10572
+ id: "4d3279be-d026-420c-88f7-f0a4ae986973",
10573
+ name: "Ibombo Rural Health Centre",
10574
+ locationType: "HEALTH_FACILITY",
10575
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10576
+ externalId: "bT7pV6YrW0Xc"
10577
+ },
10578
+ {
10579
+ id: "190902f4-1d77-476a-8947-41145af1db7d",
10580
+ name: "Chikobo Rural Health Centre",
10581
+ locationType: "HEALTH_FACILITY",
10582
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10583
+ externalId: "zE4qPn2SgJ5d"
10584
+ },
10585
+ {
10586
+ id: "f5ecbd9b-a01e-4a65-910e-70e86ab41b71",
10587
+ name: "Chilochabalenje Health Post",
10588
+ locationType: "HEALTH_FACILITY",
10589
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10590
+ externalId: "H8vDs1MqR4Uf"
10591
+ },
10592
+ {
10593
+ id: "dbfc178f-7295-4b90-b28d-111c95b03127",
10594
+ name: "Chipeso Rural Health Centre",
10595
+ locationType: "HEALTH_FACILITY",
10596
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10597
+ externalId: "Qw3uZ9KfX6Lm"
10598
+ },
10599
+ {
10600
+ id: "09862bfe-c7ac-46cd-987b-668681533c80",
10601
+ name: "Chisamba Rural Health Centre",
10602
+ locationType: "HEALTH_FACILITY",
10603
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10604
+ externalId: "Yr0pCg8LdM2s"
10605
+ },
10606
+ {
10607
+ id: "834ce389-e95b-4fb0-96a0-33e9ab323059",
10608
+ name: "Chitanda Rural Health Centre",
10609
+ locationType: "HEALTH_FACILITY",
10610
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10611
+ externalId: "tS9gJ4PwB1Qx"
10612
+ },
10613
+ {
10614
+ id: "0431c433-6062-4a4c-aee9-25271aec61ee",
10615
+ name: "Golden Valley Rural Health Centre",
10616
+ locationType: "HEALTH_FACILITY",
10617
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10618
+ externalId: "Ld7Qm3XsA8Vr"
10619
+ },
10620
+ {
10621
+ id: "bc84d0b6-7ba7-480d-a339-5d9920d90eb2",
10622
+ name: "Ipongo Rural Health Centre",
10623
+ locationType: "HEALTH_FACILITY",
10624
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10625
+ externalId: "kF2sW9DmH0Bt"
10626
+ },
10627
+ {
10628
+ id: "4cf1f53b-b730-41d2-8649-dff7eeed970d",
10629
+ name: "Itumbwe Health Post",
10630
+ locationType: "HEALTH_FACILITY",
10631
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10632
+ externalId: "Ue5Xb3VaC7Pq"
10633
+ },
10634
+ {
10635
+ id: "4b3676cb-9355-4942-9eb9-2ce46acaf0e0",
10636
+ name: "Kabangalala Rural Health Centre",
10637
+ locationType: "HEALTH_FACILITY",
10638
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10639
+ externalId: "Pz8Kc1TqH6Jn"
10640
+ },
10641
+ // Village offices
10642
+ {
10643
+ id: "1f4a5b6c-7d8e-4312-8abc-345678901234",
10644
+ name: "Klow Village Office",
10645
+ locationType: "CRVS_OFFICE",
10646
+ administrativeAreaId: "1d4e5f6a-7b8c-4912-8efa-345678901234",
10647
+ externalId: "PmAyxAJkxiJ"
10715
10648
  }
10716
- return false;
10717
- }
10718
-
10719
- // ../commons/src/events/scopes.ts
10720
- var import_lodash6 = require("lodash");
10649
+ ];
10650
+ var V2_DEFAULT_MOCK_LOCATIONS = MOCK_LOCATIONS_BASE.map(withVersionFields);
10651
+ var V2_DEFAULT_MOCK_LOCATIONS_MAP = new Map(
10652
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, l])
10653
+ );
10654
+ var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP = new Map(
10655
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [a.id, a])
10656
+ );
10657
+ var V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP = new Map(
10658
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, toClientLocation(l)])
10659
+ );
10660
+ var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
10661
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [
10662
+ a.id,
10663
+ toClientAdministrativeArea(a)
10664
+ ])
10665
+ );
10721
10666
 
10722
- // ../commons/src/events/locations.ts
10723
- var z44 = __toESM(require("zod/v4"));
10724
- var LocationTypeV1 = z44.enum([
10725
- "ADMIN_STRUCTURE",
10726
- "CRVS_OFFICE",
10727
- "HEALTH_FACILITY"
10667
+ // ../commons/src/events/test.utils.ts
10668
+ var TEST_SYSTEM_IANA_TIMEZONE = "Asia/Dhaka";
10669
+ var TestUserRole = z44.enum([
10670
+ "FIELD_AGENT",
10671
+ "LOCAL_REGISTRAR",
10672
+ "LOCAL_SYSTEM_ADMIN",
10673
+ "NATIONAL_REGISTRAR",
10674
+ "REGISTRATION_AGENT",
10675
+ "NATIONAL_SYSTEM_ADMIN",
10676
+ "SOCIAL_WORKER",
10677
+ "COMMUNITY_LEADER",
10678
+ "PROVINCIAL_REGISTRAR"
10728
10679
  ]);
10729
- var LocationStatus = z44.enum(["active", "inactive"]);
10730
- var LocationVersion = z44.object({
10731
- versionId: UUID,
10732
- effectiveFrom: z44.iso.date(),
10733
- name: z44.string(),
10734
- externalId: z44.string().nullish(),
10735
- status: LocationStatus
10736
- });
10737
- var AdministrativeArea = z44.object({
10738
- id: UUID,
10739
- name: z44.string(),
10740
- externalId: z44.string().nullish(),
10741
- parentId: UUID.nullable(),
10742
- status: LocationStatus,
10743
- versions: z44.array(LocationVersion)
10744
- });
10745
- var Location = z44.object({
10746
- id: UUID,
10747
- name: z44.string(),
10748
- externalId: z44.string().nullish(),
10749
- administrativeAreaId: UUID.nullable(),
10750
- locationType: z44.string().nullable(),
10751
- status: LocationStatus,
10752
- versions: z44.array(LocationVersion)
10753
- });
10754
- var ClientAdministrativeArea = AdministrativeArea.omit({
10755
- name: true,
10756
- status: true,
10757
- externalId: true
10758
- });
10759
- var ClientLocation = Location.omit({
10760
- name: true,
10761
- status: true,
10762
- externalId: true
10763
- });
10764
- function toClientLocation(location) {
10765
- return {
10766
- id: location.id,
10767
- administrativeAreaId: location.administrativeAreaId,
10768
- locationType: location.locationType,
10769
- versions: location.versions
10770
- };
10771
- }
10772
- function toClientAdministrativeArea(area) {
10773
- return {
10774
- id: area.id,
10775
- parentId: area.parentId,
10776
- versions: area.versions
10777
- };
10778
- }
10779
- function validateAscendingDates(versions, ctx) {
10780
- const ascending = versions.every(
10781
- (version, index) => index === 0 || versions[index - 1].effectiveFrom < version.effectiveFrom
10782
- );
10783
- if (!ascending) {
10784
- ctx.addIssue("versions must be strictly ascending by effectiveFrom");
10785
- }
10786
- }
10787
- function validateUniqueIds(versions, ctx) {
10788
- const versionIds = new Set(versions.map((version) => version.versionId));
10789
- if (versionIds.size !== versions.length) {
10790
- ctx.addIssue("versions must not repeat a versionId");
10791
- }
10792
- }
10793
- var SeededLocationVersions = z44.array(LocationVersion).min(1).superRefine((versions, ctx) => {
10794
- validateAscendingDates(versions, ctx);
10795
- validateUniqueIds(versions, ctx);
10796
- });
10797
- var SetLocationPayload = z44.object({
10798
- id: UUID,
10799
- name: z44.string(),
10800
- externalId: z44.string().nullish(),
10801
- administrativeAreaId: UUID.nullable(),
10802
- locationType: z44.string().nullable(),
10803
- versions: SeededLocationVersions.optional()
10804
- });
10805
- var SetAdministrativeAreaPayload = z44.object({
10806
- id: UUID,
10807
- name: z44.string(),
10808
- externalId: z44.string().nullish(),
10809
- parentId: UUID.nullable(),
10810
- versions: SeededLocationVersions.optional()
10811
- });
10812
- function resolveVersion(versions, anchor) {
10813
- let resolved = versions[0];
10814
- for (const version of versions) {
10815
- if (version.effectiveFrom <= anchor) {
10816
- resolved = version;
10817
- }
10818
- }
10819
- return resolved;
10820
- }
10821
- function isSelectableAtAnchor(versions, anchor) {
10822
- return versions.some((version) => version.effectiveFrom <= anchor) && resolveVersion(versions, anchor).status === "active";
10823
- }
10824
- function hasActiveExternalIdOnOrAfter(versions, externalId, anchor) {
10825
- const inEffectAtAnchor = resolveVersion(versions, anchor);
10826
- const laterVersions = versions.filter((v) => v.effectiveFrom > anchor);
10827
- return [inEffectAtAnchor, ...laterVersions].some(
10828
- (v) => v.externalId === externalId && v.status === "active"
10829
- );
10830
- }
10831
- function matchesJurisdictionFilter(locationIds, filter, user2) {
10832
- if (!locationIds) {
10833
- return false;
10834
- }
10835
- if (filter === JurisdictionFilter.enum.location) {
10836
- return locationIds.some((id) => id === user2.primaryOfficeId);
10837
- }
10838
- if (filter === JurisdictionFilter.enum.administrativeArea) {
10839
- return !user2.administrativeAreaId || locationIds.some((id) => id === user2.administrativeAreaId);
10840
- }
10841
- return true;
10842
- }
10843
- function matchesFlagsFilter(eventFlags, flags) {
10844
- const currentFlags = eventFlags ?? [];
10845
- if (flags.anyOf && !flags.anyOf.some((flag2) => currentFlags.includes(flag2))) {
10846
- return false;
10847
- }
10848
- if (flags.noneOf && flags.noneOf.some((flag2) => currentFlags.includes(flag2))) {
10849
- return false;
10850
- }
10851
- if (flags.allOf && !flags.allOf.every((flag2) => currentFlags.includes(flag2))) {
10852
- return false;
10853
- }
10854
- return true;
10680
+ function pickRandom(rng, items) {
10681
+ return items[Math.floor(rng() * items.length)];
10855
10682
  }
10856
- function canAccessEventWithScope(event2, scope, user2, customActionType) {
10857
- const opts = scope.options;
10858
- if (opts?.event) {
10859
- if (!event2.type || !opts.event.includes(event2.type)) {
10860
- return false;
10861
- }
10862
- }
10863
- if (opts?.placeOfEvent === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10864
- event2.placeOfEvent,
10865
- JurisdictionFilter.enum.location,
10866
- user2
10867
- )) {
10868
- return false;
10869
- }
10870
- if (opts?.placeOfEvent === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10871
- event2.placeOfEvent,
10872
- JurisdictionFilter.enum.administrativeArea,
10873
- user2
10874
- )) {
10875
- return false;
10876
- }
10877
- if (scopeUsesDeclaredOptions(scope)) {
10878
- const { options } = scope;
10879
- if (options?.status && (!event2.status || !options.status.includes(event2.status))) {
10880
- return false;
10881
- }
10882
- if (options?.notifiedBy === UserFilter.enum.user) {
10883
- if (event2.legalStatuses?.NOTIFIED?.createdBy !== user2.id) {
10884
- return false;
10885
- }
10886
- }
10887
- if (options?.notifiedIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10888
- event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10889
- JurisdictionFilter.enum.location,
10890
- user2
10891
- )) {
10892
- return false;
10893
- }
10894
- if (options?.notifiedIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10895
- event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10896
- JurisdictionFilter.enum.administrativeArea,
10897
- user2
10898
- )) {
10899
- return false;
10900
- }
10901
- if (options?.declaredBy === UserFilter.enum.user) {
10902
- if (event2.legalStatuses?.DECLARED?.createdBy !== user2.id) {
10903
- return false;
10904
- }
10905
- }
10906
- if (options?.declaredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10907
- event2.legalStatuses?.DECLARED?.createdAtLocation,
10908
- JurisdictionFilter.enum.location,
10909
- user2
10910
- )) {
10911
- return false;
10912
- }
10913
- if (options?.declaredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10914
- event2.legalStatuses?.DECLARED?.createdAtLocation,
10915
- JurisdictionFilter.enum.administrativeArea,
10916
- user2
10917
- )) {
10918
- return false;
10919
- }
10920
- }
10921
- if (scopeUsesFullOptions(scope) || scopeUsesPrintCertifiedCopiesOptions(scope) || isCustomActionScope(scope)) {
10922
- const { options } = scope;
10923
- if (options?.registeredBy === UserFilter.enum.user) {
10924
- if (event2.legalStatuses?.REGISTERED?.createdBy !== user2.id) {
10925
- return false;
10926
- }
10927
- }
10928
- if (options?.registeredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10929
- event2.legalStatuses?.REGISTERED?.createdAtLocation,
10930
- JurisdictionFilter.enum.location,
10931
- user2
10932
- )) {
10933
- return false;
10934
- }
10935
- if (options?.registeredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10936
- event2.legalStatuses?.REGISTERED?.createdAtLocation,
10937
- JurisdictionFilter.enum.administrativeArea,
10938
- user2
10939
- )) {
10940
- return false;
10941
- }
10942
- if (options?.flags && !matchesFlagsFilter(event2.flags, options.flags)) {
10943
- return false;
10944
- }
10945
- }
10946
- if (isCustomActionScope(scope)) {
10947
- const { options } = scope;
10948
- if (!customActionType || !options?.customActionTypes || !options?.customActionTypes.includes(customActionType)) {
10949
- return false;
10950
- }
10951
- }
10952
- return true;
10683
+ function generateRandomName(rng) {
10684
+ const firstnames = [
10685
+ "Danny",
10686
+ "John",
10687
+ "Jane",
10688
+ "Emily",
10689
+ "Michael",
10690
+ "Sarah",
10691
+ "Chris",
10692
+ "Jessica",
10693
+ "Sara",
10694
+ "Sarachella",
10695
+ "Sarandera",
10696
+ "Zara"
10697
+ ];
10698
+ const surnames = [
10699
+ "Doe",
10700
+ "Smith",
10701
+ "Johnson",
10702
+ "Brown",
10703
+ "Williams",
10704
+ "Jones",
10705
+ "Garcia",
10706
+ "Miller",
10707
+ "Saranen",
10708
+ "Sarajanen",
10709
+ "Sarthua",
10710
+ "Tsarakovski",
10711
+ "Salamander",
10712
+ "Zarathustra"
10713
+ ];
10714
+ return {
10715
+ firstname: pickRandom(rng, firstnames),
10716
+ surname: pickRandom(rng, surnames)
10717
+ };
10953
10718
  }
10954
- function canAccessUserWithScope({
10955
- userToAccess,
10956
- scope,
10957
- user: user2
10958
- }) {
10959
- const opts = scope.options;
10960
- const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
10961
- if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
10962
- return false;
10963
- }
10964
- const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
10965
- (id) => user2.administrativeAreaId === id
10966
- ) || !user2.administrativeAreaId;
10967
- if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
10968
- return false;
10969
- }
10970
- if (scopeUsesRoleOptions(scope)) {
10971
- const { options } = scope;
10972
- if (options?.role && !options.role.includes(userToAccess.role)) {
10973
- return false;
10974
- }
10975
- }
10976
- return true;
10719
+ function generateUuid(rng = () => 0.1) {
10720
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
10721
+ const r = Math.floor(rng() * 16);
10722
+ const v = c === "x" ? r : r & 3 | 8;
10723
+ return v.toString(16);
10724
+ });
10977
10725
  }
10978
- function canAccessOtherUserWithScopes({
10979
- scopes,
10980
- userToAccess,
10981
- user: user2
10982
- }) {
10983
- return scopes.some(
10984
- (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
10985
- );
10726
+ function generateTrackingId(rng) {
10727
+ const uuid2 = generateUuid(rng).replace(/-/g, "");
10728
+ const trackingId = uuid2.slice(0, 6).toUpperCase();
10729
+ return trackingId;
10986
10730
  }
10987
- function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10988
- return scopes.some(
10989
- (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
10990
- );
10731
+ function generateRegistrationNumber(rng) {
10732
+ const uuid2 = generateUuid(rng).replace(/-/g, "");
10733
+ const registrationNumber = uuid2.slice(0, 12).toUpperCase();
10734
+ return registrationNumber;
10991
10735
  }
10992
- function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
10993
- const collectedLocations = [];
10994
- const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
10995
- let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
10996
- while (current) {
10997
- collectedLocations.push(current);
10998
- if (!current.parentId) {
10999
- break;
11000
- }
11001
- const parentId = current.parentId;
11002
- current = administrativeAreas.get(parentId);
11003
- }
11004
- return collectedLocations;
10736
+ function generateRandomSignature(rng) {
10737
+ return `${generateUuid(rng)}.png`;
11005
10738
  }
11006
- function getLocationHierarchy(selectedId, context) {
11007
- const { administrativeAreas, locations } = context;
11008
- const loc = locations.get(selectedId);
11009
- if (loc) {
11010
- if (loc.administrativeAreaId) {
11011
- const hierarchy2 = getAdministrativeAreaHierarchy(
11012
- loc.administrativeAreaId,
11013
- administrativeAreas
10739
+ function locationVersion(overrides = {}, rng) {
10740
+ return {
10741
+ versionId: generateUuid(rng),
10742
+ effectiveFrom: "0001-01-01",
10743
+ name: "Location name",
10744
+ externalId: null,
10745
+ status: "active",
10746
+ ...overrides
10747
+ };
10748
+ }
10749
+ function mapFieldTypeToMockValue(field3, i, rng, administrativeHierarchy) {
10750
+ const leafLevelAdministrativeAreas = administrativeHierarchy?.administrativeAreas.filter(
10751
+ (aa) => administrativeHierarchy?.administrativeAreas.every(
10752
+ (other) => other.parentId !== aa.id
10753
+ )
10754
+ );
10755
+ switch (field3.type) {
10756
+ case FieldType.FIELD_GROUP: {
10757
+ const nestedValue = field3.fields.reduce(
10758
+ (acc, subfield, index) => ({
10759
+ ...acc,
10760
+ [subfield.id]: mapFieldTypeToMockValue(
10761
+ subfield,
10762
+ i * 1e3 + index,
10763
+ rng
10764
+ )
10765
+ }),
10766
+ {}
11014
10767
  );
11015
- return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10768
+ return nestedValue;
11016
10769
  }
11017
- return [loc.id];
10770
+ case FieldType.DIVIDER:
10771
+ case FieldType.TEXT:
10772
+ case FieldType.TEXTAREA:
10773
+ case FieldType.BULLET_LIST:
10774
+ case FieldType.PAGE_HEADER:
10775
+ case FieldType.LOCATION:
10776
+ case FieldType.SELECT:
10777
+ case FieldType.SELECT_DATE_RANGE:
10778
+ case FieldType.COUNTRY:
10779
+ case FieldType.RADIO_GROUP:
10780
+ case FieldType.PARAGRAPH:
10781
+ case FieldType.HEADING:
10782
+ case FieldType.IMAGE_VIEW:
10783
+ case FieldType.ADMINISTRATIVE_AREA:
10784
+ case FieldType.PHONE:
10785
+ case FieldType.QUERY_PARAM_READER:
10786
+ case FieldType.ID:
10787
+ case FieldType.LINK_BUTTON:
10788
+ case FieldType.LOADER:
10789
+ case FieldType.ALPHA_HIDDEN:
10790
+ return `${field3.id}-${field3.type}-${i}`;
10791
+ case FieldType.VERIFICATION_STATUS:
10792
+ return "verified";
10793
+ case FieldType.FACILITY:
10794
+ case FieldType.OFFICE:
10795
+ return administrativeHierarchy?.locations ? pickRandom(rng, administrativeHierarchy.locations)?.id : "a45b982a-5c7b-4bd9-8fd8-a42d0994054c";
10796
+ case FieldType.NAME:
10797
+ return generateRandomName(rng);
10798
+ case FieldType.NUMBER:
10799
+ return 19;
10800
+ case FieldType.NUMBER_WITH_UNIT:
10801
+ return {
10802
+ numericValue: 42,
10803
+ unit: "Hours"
10804
+ };
10805
+ case FieldType.BUTTON:
10806
+ return 1;
10807
+ case FieldType.EMAIL:
10808
+ return "test@opencrvs.org";
10809
+ case FieldType.ADDRESS:
10810
+ return {
10811
+ country: "FAR",
10812
+ addressType: AddressType.DOMESTIC,
10813
+ administrativeArea: leafLevelAdministrativeAreas ? pickRandom(rng, leafLevelAdministrativeAreas)?.id : "27160bbd-32d1-4625-812f-860226bfb92a",
10814
+ streetLevelDetails: {
10815
+ town: "Example Town",
10816
+ residentialArea: "Example Residential Area",
10817
+ street: "Example Street",
10818
+ number: "55",
10819
+ zipCode: "123456",
10820
+ state: "Example State",
10821
+ district2: "Example District 2"
10822
+ }
10823
+ };
10824
+ case FieldType.DATE:
10825
+ return "2021-01-01";
10826
+ case FieldType.AGE:
10827
+ return {
10828
+ age: 19,
10829
+ asOfDateRef: "applicant.dob"
10830
+ };
10831
+ case FieldType.TIME:
10832
+ return "09:33";
10833
+ case FieldType.ALPHA_PRINT_BUTTON:
10834
+ return void 0;
10835
+ case FieldType.DATE_RANGE:
10836
+ return {
10837
+ start: PlainDate.parse("2021-01-01"),
10838
+ end: PlainDate.parse("2021-01-31")
10839
+ };
10840
+ case FieldType.CHECKBOX:
10841
+ return true;
10842
+ case FieldType.SIGNATURE:
10843
+ case FieldType.FILE:
10844
+ return {
10845
+ path: "4f095fc4-4312-4de2-aa38-86dcc0f71044.png",
10846
+ originalFilename: "abcd.png",
10847
+ type: "image/png"
10848
+ };
10849
+ case FieldType.SEARCH:
10850
+ case FieldType.AUTOCOMPLETE:
10851
+ case FieldType.HTTP:
10852
+ return {
10853
+ error: null,
10854
+ data: { nid: "1234567890" },
10855
+ loading: false
10856
+ };
10857
+ case FieldType.FILE_WITH_OPTIONS:
10858
+ case FieldType.DATA:
10859
+ case FieldType._EXPERIMENTAL_CUSTOM:
10860
+ return void 0;
10861
+ case FieldType.QR_READER:
10862
+ return /* @__PURE__ */ Object.create(null);
10863
+ case FieldType.ID_READER:
10864
+ return /* @__PURE__ */ Object.create(null);
10865
+ case FieldType.USER_ROLE:
10866
+ return TestUserRole.enum.FIELD_AGENT;
11018
10867
  }
11019
- const hierarchy = getAdministrativeAreaHierarchy(
11020
- selectedId,
11021
- administrativeAreas
10868
+ }
10869
+ function fieldConfigsToActionPayload(fields, rng, administrativeHierarchy) {
10870
+ return fields.reduce(
10871
+ (acc, field3, i) => ({
10872
+ ...acc,
10873
+ [field3.id]: mapFieldTypeToMockValue(
10874
+ field3,
10875
+ i,
10876
+ rng,
10877
+ administrativeHierarchy
10878
+ )
10879
+ }),
10880
+ {}
10881
+ );
10882
+ }
10883
+ function generateActionDeclarationInput(configuration, action, rng, overrides, administrativeHierarchy) {
10884
+ const parsed = DeclarationUpdateActions.safeParse(action);
10885
+ if ((0, import_lodash5.isEmpty)(overrides) && typeof overrides === "object") {
10886
+ return {};
10887
+ }
10888
+ if (parsed.success) {
10889
+ const fields = getDeclarationFields(configuration);
10890
+ const declarationConfig = getDeclaration(configuration);
10891
+ const declaration = fieldConfigsToActionPayload(
10892
+ fields,
10893
+ rng,
10894
+ administrativeHierarchy
10895
+ );
10896
+ return omitHiddenPaginatedFields(
10897
+ declarationConfig,
10898
+ {
10899
+ ...declaration,
10900
+ ...overrides
10901
+ },
10902
+ {},
10903
+ // Intentionally empty. Allow generating fields with custom conditionals.
10904
+ true
10905
+ );
10906
+ }
10907
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
10908
+ return {};
10909
+ }
10910
+ function generateActionDuplicateDeclarationInput(...args) {
10911
+ const [configuration, action, rng, overrides] = args;
10912
+ return generateActionDeclarationInput(configuration, action, rng, {
10913
+ ...overrides,
10914
+ "applicant.dobUnknown": false
10915
+ });
10916
+ }
10917
+ function generateActionAnnotationInput(configuration, action, rng) {
10918
+ const actionConfig = configuration.actions.find(
10919
+ (ac) => ac.type === action
11022
10920
  );
11023
- return hierarchy.reverse().map((area) => area.id);
10921
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
10922
+ const annotation = fieldConfigsToActionPayload(annotationFields, rng);
10923
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
10924
+ findRecordActionPages(configuration, action),
10925
+ annotation,
10926
+ {}
10927
+ );
10928
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
10929
+ (acc, pageId) => ({
10930
+ ...acc,
10931
+ [pageId]: true
10932
+ }),
10933
+ {}
10934
+ );
10935
+ const fieldBasedPayload = omitHiddenFields(
10936
+ annotationFields,
10937
+ annotation,
10938
+ {}
10939
+ // Intentionally empty. Allow generating fields with custom conditionals.
10940
+ );
10941
+ return {
10942
+ ...fieldBasedPayload,
10943
+ ...visiblePageVerificationMap
10944
+ };
11024
10945
  }
11025
- function resolvePath(locationId, anchor, context) {
11026
- return getLocationHierarchy(locationId, context).flatMap((id) => {
11027
- const node = context.locations.get(id) ?? context.administrativeAreas.get(id);
11028
- if (!node) {
11029
- return [];
10946
+ function eventPayloadGenerator(rng, configuration = tennisClubMembershipEvent) {
10947
+ return {
10948
+ create: (input = {}) => ({
10949
+ transactionId: input.transactionId ?? getUUID(),
10950
+ type: input.type ?? configuration.id
10951
+ }),
10952
+ patch: (id, input = {}) => ({
10953
+ transactionId: input.transactionId ?? getUUID(),
10954
+ type: input.type ?? configuration.id,
10955
+ id
10956
+ }),
10957
+ draft: ({
10958
+ eventId,
10959
+ actionType,
10960
+ annotation,
10961
+ omitFields = []
10962
+ }, input = {}) => {
10963
+ const base = {
10964
+ id: getUUID(),
10965
+ eventId,
10966
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10967
+ transactionId: getUUID(),
10968
+ action: {
10969
+ transactionId: getUUID(),
10970
+ type: actionType,
10971
+ status: ActionStatus.Accepted,
10972
+ declaration: {
10973
+ "applicant.name": {
10974
+ firstname: "Max",
10975
+ surname: "McLaren"
10976
+ },
10977
+ "applicant.dob": "2020-01-02",
10978
+ "applicant.image": {
10979
+ path: "e56d1dd3-2cd4-452a-b54e-bf3e2d830605.png",
10980
+ originalFilename: "Screenshot.png",
10981
+ type: "image/png"
10982
+ }
10983
+ },
10984
+ annotation: {
10985
+ "correction.requester.relationship": "ANOTHER_AGENT",
10986
+ "correction.request.reason": "Child's name was incorrect",
10987
+ "identity-check": true,
10988
+ ...annotation
10989
+ },
10990
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10991
+ createdBy: "@todo",
10992
+ createdByUserType: TokenUserType.enum.user,
10993
+ createdByRole: "@todo"
10994
+ }
10995
+ };
10996
+ base.action.declaration = (0, import_lodash5.omit)(base.action.declaration, omitFields);
10997
+ return (0, import_lodash5.merge)(base, input);
10998
+ },
10999
+ actions: {
11000
+ declare: (eventId, input = {}) => ({
11001
+ type: ActionType.DECLARE,
11002
+ transactionId: input.transactionId ?? getUUID(),
11003
+ declaration: input.declaration ?? generateActionDeclarationInput(
11004
+ configuration,
11005
+ ActionType.DECLARE,
11006
+ rng
11007
+ ),
11008
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.DECLARE, rng),
11009
+ eventId,
11010
+ ...input
11011
+ }),
11012
+ /**
11013
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
11014
+ */
11015
+ notify: (eventId, input = {}) => {
11016
+ let declaration = input.declaration;
11017
+ if (!declaration) {
11018
+ const partialDeclaration = (0, import_lodash5.omitBy)(
11019
+ generateActionDeclarationInput(
11020
+ configuration,
11021
+ ActionType.NOTIFY,
11022
+ rng
11023
+ ),
11024
+ import_lodash5.isString
11025
+ );
11026
+ declaration = partialDeclaration;
11027
+ }
11028
+ return {
11029
+ type: ActionType.NOTIFY,
11030
+ transactionId: input.transactionId ?? getUUID(),
11031
+ declaration,
11032
+ eventId,
11033
+ keepAssignment: input.keepAssignment,
11034
+ keepAssignmentIfAccepted: input.keepAssignmentIfAccepted,
11035
+ keepAssignmentIfRejected: input.keepAssignmentIfRejected,
11036
+ waitFor: input.waitFor
11037
+ };
11038
+ },
11039
+ edit: (eventId, input = {}) => ({
11040
+ type: ActionType.EDIT,
11041
+ transactionId: input.transactionId ?? getUUID(),
11042
+ declaration: input.declaration ?? generateActionDeclarationInput(configuration, ActionType.EDIT, rng),
11043
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.EDIT, rng),
11044
+ eventId,
11045
+ ...input
11046
+ }),
11047
+ assign: (eventId, input = {}) => ({
11048
+ type: ActionType.ASSIGN,
11049
+ transactionId: input.transactionId ?? getUUID(),
11050
+ declaration: {},
11051
+ assignedTo: input.assignedTo ?? getUUID(),
11052
+ eventId,
11053
+ waitFor: input.waitFor
11054
+ }),
11055
+ unassign: (eventId, input = {}) => ({
11056
+ type: ActionType.UNASSIGN,
11057
+ transactionId: input.transactionId ?? getUUID(),
11058
+ declaration: {},
11059
+ assignedTo: null,
11060
+ eventId,
11061
+ waitFor: input.waitFor
11062
+ }),
11063
+ archive: (eventId, input = {}) => ({
11064
+ type: ActionType.ARCHIVE,
11065
+ transactionId: input.transactionId ?? getUUID(),
11066
+ declaration: {},
11067
+ annotation: {},
11068
+ eventId,
11069
+ ...input
11070
+ }),
11071
+ unarchive: (eventId, input = {}) => ({
11072
+ type: ActionType.UNARCHIVE,
11073
+ transactionId: input.transactionId ?? getUUID(),
11074
+ declaration: {},
11075
+ annotation: {},
11076
+ eventId,
11077
+ ...input
11078
+ }),
11079
+ reject: (eventId, input = {}) => ({
11080
+ type: ActionType.REJECT,
11081
+ transactionId: input.transactionId ?? getUUID(),
11082
+ declaration: {},
11083
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.REJECT, rng),
11084
+ eventId,
11085
+ content: { reason: `${ActionType.REJECT}` },
11086
+ ...input
11087
+ }),
11088
+ register: (eventId, input = {}) => ({
11089
+ type: ActionType.REGISTER,
11090
+ transactionId: input.transactionId ?? getUUID(),
11091
+ declaration: input.declaration ?? generateActionDeclarationInput(
11092
+ configuration,
11093
+ ActionType.REGISTER,
11094
+ rng
11095
+ ),
11096
+ annotation: input.annotation ?? generateActionAnnotationInput(
11097
+ configuration,
11098
+ ActionType.REGISTER,
11099
+ rng
11100
+ ),
11101
+ eventId,
11102
+ ...input
11103
+ }),
11104
+ printCertificate: (eventId, input = {}) => ({
11105
+ type: ActionType.PRINT_CERTIFICATE,
11106
+ transactionId: input.transactionId ?? getUUID(),
11107
+ declaration: {},
11108
+ annotation: input.annotation ?? generateActionAnnotationInput(
11109
+ configuration,
11110
+ ActionType.PRINT_CERTIFICATE,
11111
+ rng
11112
+ ),
11113
+ eventId,
11114
+ ...input
11115
+ }),
11116
+ correction: {
11117
+ request: (eventId, input = {}) => ({
11118
+ type: ActionType.REQUEST_CORRECTION,
11119
+ transactionId: input.transactionId ?? getUUID(),
11120
+ declaration: input.declaration ?? (0, import_lodash5.omit)(
11121
+ generateActionDeclarationInput(
11122
+ configuration,
11123
+ ActionType.REQUEST_CORRECTION,
11124
+ rng
11125
+ ),
11126
+ ["applicant.email", "applicant.image"]
11127
+ ),
11128
+ annotation: input.annotation ?? generateActionAnnotationInput(
11129
+ configuration,
11130
+ ActionType.REQUEST_CORRECTION,
11131
+ rng
11132
+ ),
11133
+ eventId,
11134
+ keepAssignment: input.keepAssignment,
11135
+ keepAssignmentIfAccepted: input.keepAssignmentIfAccepted,
11136
+ keepAssignmentIfRejected: input.keepAssignmentIfRejected,
11137
+ waitFor: input.waitFor
11138
+ }),
11139
+ approve: (eventId, requestId, input = {}) => ({
11140
+ type: ActionType.APPROVE_CORRECTION,
11141
+ transactionId: input.transactionId ?? getUUID(),
11142
+ declaration: {},
11143
+ annotation: input.annotation ?? generateActionAnnotationInput(
11144
+ configuration,
11145
+ ActionType.APPROVE_CORRECTION,
11146
+ rng
11147
+ ),
11148
+ eventId,
11149
+ requestId,
11150
+ keepAssignment: input.keepAssignment,
11151
+ keepAssignmentIfAccepted: input.keepAssignmentIfAccepted,
11152
+ keepAssignmentIfRejected: input.keepAssignmentIfRejected,
11153
+ waitFor: input.waitFor
11154
+ }),
11155
+ reject: (eventId, requestId, input) => ({
11156
+ type: ActionType.REJECT_CORRECTION,
11157
+ transactionId: input.transactionId ?? getUUID(),
11158
+ declaration: {},
11159
+ annotation: input.annotation ?? generateActionAnnotationInput(
11160
+ configuration,
11161
+ ActionType.REJECT_CORRECTION,
11162
+ rng
11163
+ ),
11164
+ eventId,
11165
+ requestId,
11166
+ content: input.content ?? { reason: "too late" },
11167
+ keepAssignment: input.keepAssignment,
11168
+ keepAssignmentIfAccepted: input.keepAssignmentIfAccepted,
11169
+ keepAssignmentIfRejected: input.keepAssignmentIfRejected,
11170
+ waitFor: input.waitFor
11171
+ })
11172
+ },
11173
+ duplicate: {
11174
+ markAsDuplicate: (eventId, input = {}) => ({
11175
+ type: ActionType.MARK_AS_DUPLICATE,
11176
+ transactionId: input.transactionId ?? getUUID(),
11177
+ declaration: input.declaration ?? generateActionDeclarationInput(
11178
+ tennisClubMembershipEvent,
11179
+ ActionType.REGISTER,
11180
+ rng
11181
+ ),
11182
+ annotation: input.annotation ?? generateActionAnnotationInput(
11183
+ tennisClubMembershipEvent,
11184
+ ActionType.REGISTER,
11185
+ rng
11186
+ ),
11187
+ eventId,
11188
+ keepAssignment: input.keepAssignment
11189
+ }),
11190
+ markNotDuplicate: (eventId, input = {}) => ({
11191
+ type: ActionType.MARK_AS_NOT_DUPLICATE,
11192
+ transactionId: input.transactionId ?? getUUID(),
11193
+ declaration: input.declaration ?? generateActionDeclarationInput(
11194
+ tennisClubMembershipEvent,
11195
+ ActionType.REGISTER,
11196
+ rng
11197
+ ),
11198
+ annotation: input.annotation ?? generateActionAnnotationInput(
11199
+ tennisClubMembershipEvent,
11200
+ ActionType.REGISTER,
11201
+ rng
11202
+ ),
11203
+ eventId,
11204
+ keepAssignment: input.keepAssignment
11205
+ })
11206
+ }
11030
11207
  }
11031
- const { name, status: status2 } = resolveVersion(node.versions, anchor);
11032
- return [{ id, name, status: status2 }];
11033
- });
11034
- }
11035
-
11036
- // ../commons/src/events/scopes.ts
11037
- var ACTION_SCOPE_MAP = {
11038
- [ActionType.READ]: ["record.read"],
11039
- [ActionType.CREATE]: ["record.create"],
11040
- [ActionType.NOTIFY]: ["record.notify"],
11041
- [ActionType.DECLARE]: ["record.declare", "record.register"],
11042
- [ActionType.EDIT]: ["record.edit"],
11043
- [ActionType.DELETE]: ["record.declare", "record.notify"],
11044
- [ActionType.REGISTER]: ["record.register"],
11045
- [ActionType.PRINT_CERTIFICATE]: ["record.print-certified-copies"],
11046
- [ActionType.REQUEST_CORRECTION]: [
11047
- "record.request-correction",
11048
- "record.correct"
11049
- ],
11050
- [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
11051
- [ActionType.REJECT_CORRECTION]: ["record.correct"],
11052
- [ActionType.APPROVE_CORRECTION]: ["record.correct"],
11053
- [ActionType.MARK_AS_DUPLICATE]: ["record.review-duplicates"],
11054
- [ActionType.MARK_AS_NOT_DUPLICATE]: ["record.review-duplicates"],
11055
- [ActionType.ARCHIVE]: ["record.archive"],
11056
- [ActionType.UNARCHIVE]: ["record.unarchive"],
11057
- [ActionType.REJECT]: ["record.reject"],
11058
- [ActionType.ASSIGN]: null,
11059
- [ActionType.UNASSIGN]: null,
11060
- [ActionType.DUPLICATE_DETECTED]: [],
11061
- [ActionType.CUSTOM]: []
11062
- };
11063
- function hasAnyOfScopes(a, b) {
11064
- return (0, import_lodash6.intersection)(a, b).length > 0;
11065
- }
11066
- var AssignmentStatus = {
11067
- ASSIGNED_TO_SELF: "ASSIGNED_TO_SELF",
11068
- ASSIGNED_TO_OTHERS: "ASSIGNED_TO_OTHERS",
11069
- UNASSIGNED: "UNASSIGNED"
11070
- };
11071
- function getAssignmentStatus(eventState, userId) {
11072
- if (!eventState.assignedTo) {
11073
- return AssignmentStatus.UNASSIGNED;
11074
- }
11075
- return eventState.assignedTo == userId ? AssignmentStatus.ASSIGNED_TO_SELF : AssignmentStatus.ASSIGNED_TO_OTHERS;
11208
+ };
11076
11209
  }
11077
- function isActionInScope({
11078
- scopes,
11210
+ function generateActionDocument({
11211
+ configuration,
11079
11212
  action,
11080
- event: event2,
11081
- currentUser
11213
+ rng = () => 0.1,
11214
+ defaults,
11215
+ declarationOverrides
11082
11216
  }) {
11083
- const assignmentStatus = getAssignmentStatus(event2, currentUser.id);
11084
- const isUnassigningOthers = action === ActionType.UNASSIGN && assignmentStatus === AssignmentStatus.ASSIGNED_TO_OTHERS;
11085
- const acceptedScopes = isUnassigningOthers ? ["record.unassign-others"] : ACTION_SCOPE_MAP[action];
11086
- if (acceptedScopes === null) {
11087
- return true;
11088
- }
11089
- if (!acceptedScopes.length) {
11090
- return false;
11091
- }
11092
- const matchingScopes = getAcceptedScopesByType({
11093
- acceptedScopes,
11094
- scopes
11095
- });
11096
- const canAccess = userCanAccessEventWithScopes(
11097
- event2,
11098
- matchingScopes,
11099
- {
11100
- id: currentUser.id,
11101
- primaryOfficeId: currentUser.primaryOfficeId,
11102
- administrativeAreaId: currentUser.administrativeAreaId ?? null,
11103
- role: currentUser.role,
11104
- signature: currentUser.signature,
11105
- type: currentUser.type
11217
+ const actionBase = {
11218
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11219
+ // @TODO: This should be fixed in the future.
11220
+ createdAt: new Date(Date.now() - 500).toISOString(),
11221
+ createdBy: generateUuid(rng),
11222
+ createdByUserType: TokenUserType.enum.user,
11223
+ createdByRole: TestUserRole.enum.FIELD_AGENT,
11224
+ id: getUUID(),
11225
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11226
+ declaration: generateActionDeclarationInput(
11227
+ configuration,
11228
+ action,
11229
+ rng,
11230
+ declarationOverrides
11231
+ ),
11232
+ annotation: {},
11233
+ status: ActionStatus.Accepted,
11234
+ transactionId: getUUID(),
11235
+ ...defaults
11236
+ };
11237
+ switch (action) {
11238
+ case ActionType.READ:
11239
+ case ActionType.MARK_AS_NOT_DUPLICATE:
11240
+ case ActionType.DECLARE:
11241
+ case ActionType.UNASSIGN:
11242
+ case ActionType.CREATE:
11243
+ case ActionType.NOTIFY:
11244
+ case ActionType.REGISTER:
11245
+ case ActionType.REQUEST_CORRECTION:
11246
+ case ActionType.UNARCHIVE:
11247
+ return { ...actionBase, type: action };
11248
+ case ActionType.EDIT:
11249
+ return {
11250
+ ...actionBase,
11251
+ type: action,
11252
+ content: { comment: "Test comment" }
11253
+ };
11254
+ case ActionType.CUSTOM:
11255
+ return {
11256
+ ...actionBase,
11257
+ type: action,
11258
+ customActionType: "CUSTOM_ACTION_TYPE"
11259
+ };
11260
+ case ActionType.MARK_AS_DUPLICATE:
11261
+ return { ...actionBase, type: action, content: void 0 };
11262
+ case ActionType.ASSIGN: {
11263
+ const assignActionDefaults = defaults;
11264
+ return {
11265
+ ...actionBase,
11266
+ assignedTo: assignActionDefaults?.assignedTo ?? getUUID(),
11267
+ type: action
11268
+ };
11106
11269
  }
11107
- );
11108
- return canAccess;
11109
- }
11110
- function getAvailableRolesForUserUpdatePayload({
11111
- allRoles,
11112
- userLocation,
11113
- acceptedScopes,
11114
- userRequesting
11115
- }) {
11116
- const availableRoles = allRoles.filter((role) => {
11117
- const canAccess = canAccessOtherUserWithScopes({
11118
- userToAccess: {
11119
- ...userLocation,
11120
- role
11121
- },
11122
- user: userRequesting,
11123
- scopes: acceptedScopes
11124
- });
11125
- return canAccess;
11126
- });
11127
- return availableRoles;
11128
- }
11129
-
11130
- // ../commons/src/events/serializers/user/deserializer.ts
11131
- function userDeserializer(serializedUserField, user2) {
11132
- if (typeof serializedUserField === "string") {
11133
- return serializedUserField;
11134
- }
11135
- if (typeof serializedUserField !== "object") {
11136
- return void 0;
11137
- }
11138
- if (serializedUserField.$userField === "name" || serializedUserField.$userField === "fullHonorificName" || serializedUserField.$userField === "device" || serializedUserField.$userField === "firstname" || serializedUserField.$userField === "middlename" || serializedUserField.$userField === "surname") {
11139
- throw new Error(
11140
- `Deserializer for ${serializedUserField.$userField} is not implemented yet`
11141
- );
11142
- }
11143
- const value = user2[serializedUserField.$userField];
11144
- return typeof value === "string" ? value : void 0;
11145
- }
11146
- function isDefined(value) {
11147
- return value !== void 0;
11148
- }
11149
- function serializeLocationField(expression, user2) {
11150
- if (expression.type === "exact") {
11151
- return userDeserializer(expression.term, user2);
11152
- }
11153
- if (expression.type === "within") {
11154
- return userDeserializer(expression.location, user2);
11155
- }
11156
- return void 0;
11157
- }
11158
- function deserializeExpression(expression, user2) {
11159
- if (expression.type === "exact") {
11160
- const term = userDeserializer(expression.term, user2);
11161
- if (!term) {
11162
- return void 0;
11270
+ case ActionType.ARCHIVE:
11271
+ return { ...actionBase, type: action, content: { reason: "Archive" } };
11272
+ case ActionType.REJECT:
11273
+ return { ...actionBase, type: action, content: { reason: "Reject" } };
11274
+ case ActionType.PRINT_CERTIFICATE: {
11275
+ const printActionDefaults = defaults;
11276
+ return {
11277
+ ...actionBase,
11278
+ type: action,
11279
+ content: printActionDefaults?.content
11280
+ };
11163
11281
  }
11164
- return {
11165
- ...expression,
11166
- term
11167
- };
11168
- }
11169
- if (expression.type === "within") {
11170
- const location = userDeserializer(expression.location, user2);
11171
- if (!location) {
11172
- return void 0;
11282
+ case ActionType.APPROVE_CORRECTION:
11283
+ return { ...actionBase, requestId: getUUID(), type: action };
11284
+ case ActionType.REJECT_CORRECTION:
11285
+ return {
11286
+ ...actionBase,
11287
+ requestId: getUUID(),
11288
+ type: action,
11289
+ content: { reason: "Correction rejection" }
11290
+ };
11291
+ case ActionType.DUPLICATE_DETECTED: {
11292
+ const duplicateActionDefaults = defaults;
11293
+ return {
11294
+ ...actionBase,
11295
+ type: action,
11296
+ content: {
11297
+ duplicates: duplicateActionDefaults?.content?.duplicates ?? []
11298
+ }
11299
+ };
11173
11300
  }
11174
- return {
11175
- ...expression,
11176
- location
11177
- };
11301
+ case ActionType.DELETE:
11302
+ default:
11303
+ throw new Error(`Unsupported action type: ${action}`);
11178
11304
  }
11179
- return void 0;
11180
11305
  }
11181
- function deserializeQueryExpression(expression, user2) {
11182
- const assignedTo = expression.assignedTo ? userDeserializer(expression.assignedTo.term, user2) : void 0;
11183
- const createdBy = expression.createdBy ? userDeserializer(expression.createdBy.term, user2) : void 0;
11184
- const updatedBy = expression.updatedBy ? userDeserializer(expression.updatedBy.term, user2) : void 0;
11185
- const createdAtLocation = expression.createdAtLocation ? serializeLocationField(expression.createdAtLocation, user2) : void 0;
11186
- const updatedAtLocation = expression.updatedAtLocation ? serializeLocationField(expression.updatedAtLocation, user2) : void 0;
11187
- const updatedByUserRole = expression.updatedByUserRole ? userDeserializer(expression.updatedByUserRole.term, user2) : void 0;
11188
- const declaredLocation = expression["legalStatuses.DECLARED.createdAtLocation"] ? userDeserializer(
11189
- expression["legalStatuses.DECLARED.createdAtLocation"].location,
11190
- user2
11191
- ) : void 0;
11192
- const registeredLocation = expression["legalStatuses.REGISTERED.createdAtLocation"] ? userDeserializer(
11193
- expression["legalStatuses.REGISTERED.createdAtLocation"].location,
11194
- user2
11195
- ) : void 0;
11306
+ function generateRandomDatetime(rng, start, end) {
11307
+ const range = end.getTime() - start.getTime();
11308
+ const offset = Math.floor(rng() * range);
11309
+ const randomDate = new Date(start.getTime() + offset);
11310
+ return randomDate.toISOString();
11311
+ }
11312
+ function getRandomDate(rng, start, end) {
11313
+ const datetime = generateRandomDatetime(rng, new Date(start), new Date(end));
11314
+ return datetime.split("T")[0];
11315
+ }
11316
+ function generateEventDocument({
11317
+ configuration,
11318
+ actions,
11319
+ rng = () => 0.1,
11320
+ defaults = {}
11321
+ }) {
11196
11322
  return {
11197
- ...expression,
11198
- assignedTo: expression.assignedTo && isDefined(assignedTo) ? { ...expression.assignedTo, term: assignedTo } : void 0,
11199
- createdBy: expression.createdBy && isDefined(createdBy) ? { ...expression.createdBy, term: createdBy } : void 0,
11200
- updatedBy: expression.updatedBy && isDefined(updatedBy) ? { ...expression.updatedBy, term: updatedBy } : void 0,
11201
- updatedByUserRole: expression.updatedByUserRole && isDefined(updatedByUserRole) ? {
11202
- ...expression.updatedByUserRole,
11203
- term: updatedByUserRole
11204
- } : void 0,
11205
- createdAtLocation: expression.createdAtLocation && isDefined(createdAtLocation) ? deserializeExpression(expression.createdAtLocation, user2) : void 0,
11206
- updatedAtLocation: expression.updatedAtLocation && isDefined(updatedAtLocation) ? deserializeExpression(expression.updatedAtLocation, user2) : void 0,
11207
- ["legalStatuses.DECLARED.createdAtLocation"]: expression["legalStatuses.DECLARED.createdAtLocation"] && isDefined(declaredLocation) ? {
11208
- ...expression["legalStatuses.DECLARED.createdAtLocation"],
11209
- location: declaredLocation
11210
- } : void 0,
11211
- ["legalStatuses.REGISTERED.createdAtLocation"]: expression["legalStatuses.REGISTERED.createdAtLocation"] && isDefined(registeredLocation) ? {
11212
- ...expression["legalStatuses.REGISTERED.createdAtLocation"],
11213
- location: registeredLocation
11214
- } : void 0
11323
+ trackingId: generateTrackingId(rng),
11324
+ type: configuration.id,
11325
+ actions: actions.map(
11326
+ (action, i) => generateActionDocument({
11327
+ configuration,
11328
+ action: action.type,
11329
+ defaults: {
11330
+ createdBy: action.user?.id,
11331
+ createdAtLocation: action.user?.primaryOfficeId,
11332
+ assignedTo: action.user?.assignedTo,
11333
+ createdByRole: action.user?.role,
11334
+ createdAt: (0, import_date_fns4.addDays)(
11335
+ new Date(
11336
+ generateRandomDatetime(
11337
+ rng,
11338
+ new Date(2025, 0, 1),
11339
+ new Date(2025, 11, 31)
11340
+ )
11341
+ ),
11342
+ i
11343
+ ).toISOString()
11344
+ },
11345
+ declarationOverrides: action.declarationOverrides
11346
+ })
11347
+ ),
11348
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11349
+ // @TODO: This should be fixed in the future.
11350
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
11351
+ id: getUUID(),
11352
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11353
+ // @TODO: This should be fixed in the future.
11354
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
11355
+ ...defaults
11215
11356
  };
11216
11357
  }
11217
- function deserializeQuery(query, user2) {
11358
+ function generateEventDraftDocument({
11359
+ eventId,
11360
+ actionType,
11361
+ rng = () => 0.1,
11362
+ declaration = {}
11363
+ }) {
11364
+ const action = generateActionDocument({
11365
+ configuration: tennisClubMembershipEvent,
11366
+ action: actionType,
11367
+ rng
11368
+ });
11218
11369
  return {
11219
- ...query,
11220
- clauses: query.clauses.map(
11221
- (clause) => deserializeQueryExpression(clause, user2)
11222
- // SAFETY: This cast should be safe because `query.clauses` has already been validated as non-empty by the Zod schema.
11223
- // Without the cast, TypeScript cannot infer the tuple type required by the target interface.
11224
- )
11370
+ id: getUUID(),
11371
+ transactionId: getUUID(),
11372
+ action: {
11373
+ ...action,
11374
+ declaration: {
11375
+ ...action.declaration,
11376
+ ...declaration
11377
+ },
11378
+ annotation: action.annotation
11379
+ },
11380
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
11381
+ eventId
11225
11382
  };
11226
11383
  }
11227
-
11228
- // ../commons/src/events/state/availableActions.ts
11229
- var AVAILABLE_ACTIONS_BY_EVENT_STATUS = {
11230
- [EventStatus.enum.CREATED]: [
11231
- ActionType.READ,
11232
- ActionType.DECLARE,
11233
- ActionType.NOTIFY,
11234
- ActionType.DELETE
11235
- ],
11236
- [EventStatus.enum.NOTIFIED]: [
11237
- ActionType.READ,
11238
- ActionType.EDIT,
11239
- ActionType.MARK_AS_DUPLICATE,
11240
- ActionType.ARCHIVE,
11241
- ActionType.REJECT,
11242
- ActionType.CUSTOM
11243
- ],
11244
- [EventStatus.enum.DECLARED]: [
11245
- ActionType.READ,
11246
- ActionType.REGISTER,
11247
- ActionType.MARK_AS_DUPLICATE,
11248
- ActionType.ARCHIVE,
11249
- ActionType.REJECT,
11250
- ActionType.CUSTOM,
11251
- ActionType.EDIT
11252
- ],
11253
- [EventStatus.enum.REGISTERED]: [
11254
- ActionType.READ,
11255
- ActionType.PRINT_CERTIFICATE,
11256
- ActionType.REQUEST_CORRECTION,
11257
- ActionType.APPROVE_CORRECTION,
11258
- ActionType.REJECT_CORRECTION,
11259
- ActionType.CUSTOM,
11260
- ClientSpecificAction.REVIEW_CORRECTION_REQUEST
11261
- ],
11262
- [EventStatus.enum.ARCHIVED]: [
11263
- ActionType.READ,
11264
- ActionType.CUSTOM,
11265
- ActionType.UNARCHIVE
11266
- ]
11267
- };
11268
- var ACTION_FILTERS = {
11269
- [ActionType.PRINT_CERTIFICATE]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11270
- [ActionType.REQUEST_CORRECTION]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11271
- [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11272
- [ActionType.APPROVE_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11273
- [ActionType.REJECT_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11274
- [ActionType.MARK_AS_DUPLICATE]: (flags) => flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11275
- [ActionType.EDIT]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11276
- [ActionType.REGISTER]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11277
- [ActionType.REJECT]: (flags) => !flags.includes(InherentFlags.REJECTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11278
- [ActionType.ARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11279
- [ActionType.UNARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11280
- [ActionType.ASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11281
- [ActionType.UNASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11282
- [ActionType.CUSTOM]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested"))
11283
- };
11284
- function filterActionsByFlags(actions, flags) {
11285
- return actions.filter((action) => ACTION_FILTERS[action]?.(flags) ?? true);
11384
+ function generateRandomApplicant(rng) {
11385
+ const { firstname, surname } = generateRandomName(rng);
11386
+ const randomDob = getRandomDate(rng, "1990-01-01", "2010-12-31");
11387
+ return {
11388
+ "recommender.none": true,
11389
+ "applicant.name": {
11390
+ firstname,
11391
+ surname
11392
+ },
11393
+ "applicant.dob": randomDob
11394
+ };
11286
11395
  }
11287
- var REJECTED_ACTIONS = [
11288
- ActionType.READ,
11289
- ActionType.NOTIFY,
11290
- ActionType.CUSTOM,
11291
- ActionType.EDIT,
11292
- ActionType.ARCHIVE
11293
- ];
11294
- function getAvailableActionsWithoutFlagFilters(status2, flags) {
11295
- if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
11296
- return [ActionType.NOTIFY, ActionType.DECLARE, ActionType.REGISTER];
11297
- }
11298
- if (flags.includes(InherentFlags.REJECTED) && status2 !== EventStatus.enum.ARCHIVED) {
11299
- return REJECTED_ACTIONS;
11300
- }
11301
- return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
11396
+ function createPrng(seed) {
11397
+ const MODULUS = 2 ** 32;
11398
+ const MULTIPLIER = 1664525;
11399
+ const INCREMENT = 1013904223;
11400
+ let state = seed >>> 0;
11401
+ return () => {
11402
+ state = (MULTIPLIER * state + INCREMENT) % MODULUS;
11403
+ return state / MODULUS;
11404
+ };
11302
11405
  }
11303
- function getAvailableActionsForEvent(event2) {
11304
- return filterActionsByFlags(
11305
- getAvailableActionsWithoutFlagFilters(event2.status, event2.flags),
11306
- event2.flags
11406
+ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
11407
+ const rng = createPrng(seed);
11408
+ const createdAt = generateRandomDatetime(
11409
+ rng,
11410
+ /* @__PURE__ */ new Date("2024-01-01"),
11411
+ /* @__PURE__ */ new Date("2024-12-31")
11307
11412
  );
11308
- }
11309
-
11310
- // ../commons/src/events/FileUtils.ts
11311
- var import_lodash7 = require("lodash");
11312
- function getFilePathsFromEvent(event2) {
11313
- const filepaths = event2.actions.filter(
11314
- (action) => action.status !== ActionStatus.Rejected
11315
- ).flatMap((action) => {
11316
- const declarationValues = Object.values(action.declaration);
11317
- const annotationValues = Object.values(action.annotation ?? {});
11318
- const actionFilePaths = [
11319
- ...declarationValues,
11320
- ...annotationValues
11321
- ].flatMap((value) => {
11322
- const fileParsed = FileFieldValue.safeParse(value);
11323
- if (fileParsed.success) {
11324
- return [fileParsed.data.path];
11325
- }
11326
- const fileOptionParsed = FileFieldWithOptionValue.safeParse(value);
11327
- if (fileOptionParsed.success) {
11328
- return fileOptionParsed.data.map((val) => val.path);
11329
- }
11330
- return [];
11331
- });
11332
- return actionFilePaths;
11333
- });
11334
- return (0, import_lodash7.uniq)(filepaths);
11335
- }
11336
-
11337
- // ../commons/src/events/mocks.test.utils.ts
11338
- function withVersionFields(entity) {
11339
11413
  return {
11340
- ...entity,
11341
- status: "active",
11342
- versions: [
11343
- {
11344
- versionId: entity.id,
11345
- effectiveFrom: "0001-01-01",
11346
- name: entity.name,
11347
- externalId: entity.externalId ?? null,
11348
- status: "active"
11349
- }
11350
- ]
11414
+ id: overrides.id ?? generateUuid(rng),
11415
+ type: overrides.type ?? TENNIS_CLUB_MEMBERSHIP,
11416
+ status: overrides.status ?? pickRandom(rng, EventStatus.options),
11417
+ createdAt: overrides.createdAt ?? createdAt,
11418
+ createdByUserType: overrides.createdByUserType ?? "user",
11419
+ createdBy: overrides.createdBy ?? generateUuid(rng),
11420
+ createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
11421
+ updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
11422
+ updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
11423
+ assignedTo: overrides.assignedTo ?? null,
11424
+ updatedBy: overrides.updatedBy ?? generateUuid(rng),
11425
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
11426
+ flags: overrides.flags ?? [],
11427
+ potentialDuplicates: [],
11428
+ legalStatuses: overrides.legalStatuses ?? {},
11429
+ declaration: overrides.declaration ?? generateRandomApplicant(rng),
11430
+ trackingId: overrides.trackingId ?? generateTrackingId(rng)
11351
11431
  };
11352
- }
11353
- var MOCK_ADMINISTRATIVE_AREAS_BASE = [
11354
- {
11355
- id: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11356
- name: "Central",
11357
- parentId: null,
11358
- externalId: "ydyJb1RAy4U1"
11359
- },
11360
- {
11361
- id: "c599b691-fd2d-45e1-abf4-d185de727fb5",
11362
- name: "Sulaka",
11363
- parentId: null,
11364
- externalId: "pQ8nGxWmZ2Q3"
11365
- },
11366
- {
11367
- id: "7ef2b9c7-5e6d-49f6-ae05-656207d0fc64",
11368
- name: "Pualula",
11369
- parentId: null,
11370
- externalId: "Aq91DweLmT8k"
11371
- },
11372
- {
11373
- id: "6d1a59df-988c-4021-a846-ccbc021931a7",
11374
- name: "Chuminga",
11375
- parentId: null,
11376
- externalId: "Rw0fYNh2Xk9a"
11377
- },
11378
- {
11379
- id: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11380
- name: "Ibombo",
11381
- parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11382
- externalId: "k7DsP4vbN1Qe"
11383
- },
11384
- {
11385
- id: "27160bbd-32d1-4625-812f-860226bfb92a",
11386
- name: "Isango",
11387
- parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11388
- externalId: "Gm3Z9eQpHw4L"
11389
- },
11390
- {
11391
- id: "967032fd-3f81-478a-826c-30cb8fe121bd",
11392
- name: "Isamba",
11393
- parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11394
- externalId: "sT0xVu1KqJ7r"
11395
- },
11396
- {
11397
- id: "89a33893-b17d-481d-a26d-6461e7ac1651",
11398
- name: "Itambo",
11399
- parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11400
- externalId: "Nq6Bv2HpL9Te"
11401
- },
11402
- {
11403
- id: "d42ab2fe-e7ed-470e-8b31-4fb27f9b8250",
11404
- name: "Ezhi",
11405
- parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11406
- externalId: "xK8cQ0ZRy5Wd"
11407
- },
11408
- {
11409
- id: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
11410
- name: "Ilanga",
11411
- parentId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
11412
- externalId: "Cq4Jm1XvN8Ls"
11413
- },
11414
- // Villages under Ibombo (62a0ccb4-880d-4f30-8882-f256007dfff9)
11415
- {
11416
- id: "1d4e5f6a-7b8c-4912-8efa-345678901234",
11417
- name: "Klow",
11418
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11419
- externalId: "IkYcYBUcyY2"
11420
- },
11421
- {
11422
- id: "2e5f6a7b-8c9d-4a23-8fab-456789012345",
11423
- name: "Mbondo",
11424
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11425
- externalId: "Qhvv5hvo3mY"
11426
- },
11427
- {
11428
- id: "3f6a7b8c-9d0e-4b34-8abc-567890123456",
11429
- name: "Ndara",
11430
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11431
- externalId: "crXh068O9TR"
11432
- },
11433
- {
11434
- id: "4a7b8c9d-0e1f-4c45-abcd-678901234567",
11435
- name: "Olani",
11436
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11437
- externalId: "r00It8Tvvp7"
11438
- },
11439
- {
11440
- id: "5b8c9d0e-1f2a-4d56-bcde-789012345678",
11441
- name: "Pemba",
11442
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11443
- externalId: "ZnUWsbONIaH"
11444
- },
11445
- {
11446
- id: "6c9d0e1f-2a3b-4e67-8def-890123456789",
11447
- name: "Quanza",
11448
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11449
- externalId: "fDZycvQTa7l"
11450
- },
11451
- {
11452
- id: "7d0e1f2a-3b4c-4f78-8efa-901234567890",
11453
- name: "Rivka",
11454
- parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11455
- externalId: "KqswxCGTELa"
11456
- },
11457
- // Villages under Isamba (967032fd-3f81-478a-826c-30cb8fe121bd)
11458
- {
11459
- id: "8e1f2a3b-4c5d-4089-8fab-012345678901",
11460
- name: "Mbula",
11461
- parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11462
- externalId: "osEbKjRc9Kg"
11463
- },
11464
- {
11465
- id: "9f2a3b4c-5d6e-4190-8abf-123456789012",
11466
- name: "Ndoki",
11467
- parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11468
- externalId: "aq4daBUAGr3"
11469
- },
11470
- {
11471
- id: "0a3b4c5d-6e7f-4201-abcd-234567890123",
11472
- name: "Tsanga",
11473
- parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11474
- externalId: "cqis6Y8trbJ"
11475
- },
11476
- {
11477
- id: "1b4c5d6e-7f8a-4312-bcde-345678901234",
11478
- name: "Waziri",
11479
- parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11480
- externalId: "LMijHPyyx6d"
11481
- },
11482
- {
11483
- id: "2c5d6e7f-8a9b-4423-8def-456789012345",
11484
- name: "Zimbi",
11485
- parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11486
- externalId: "pcQYbPuKGZ7"
11487
- },
11488
- // Villages under Itambo (89a33893-b17d-481d-a26d-6461e7ac1651)
11489
- {
11490
- id: "3d6e7f8a-9b0c-4534-8efa-567890123456",
11491
- name: "Felani",
11492
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11493
- externalId: "gSqpoCGdMXp"
11494
- },
11495
- {
11496
- id: "4e7f8a9b-0c1d-4645-8fab-678901234567",
11497
- name: "Goroma",
11498
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11499
- externalId: "KvAAIaNqVrp"
11500
- },
11501
- {
11502
- id: "5f8a9b0c-1d2e-4756-8abc-789012345678",
11503
- name: "Halifu",
11504
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11505
- externalId: "qe4UnEVt1hv"
11506
- },
11507
- {
11508
- id: "6a9b0c1d-2e3f-4867-abcd-890123456789",
11509
- name: "Jabari",
11510
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11511
- externalId: "yHH9Nz4rLOt"
11512
- },
11513
- {
11514
- id: "7b0c1d2e-3f4a-4978-bcde-901234567890",
11515
- name: "Kifani",
11516
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11517
- externalId: "eSWmXIGeu1I"
11518
- },
11432
+ };
11433
+ var generateTranslationConfig2 = (message) => ({
11434
+ defaultMessage: message,
11435
+ description: "Description for ${message}",
11436
+ id: message.trim().replace(/\s+/g, "_").toLowerCase()
11437
+ });
11438
+ var generateWorkqueues = (slug = "all-events") => defineWorkqueues([
11519
11439
  {
11520
- id: "8c1d2e3f-4a5b-4089-8def-012345678901",
11521
- name: "Lumela",
11522
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11523
- externalId: "bh0b3aI1uP3"
11440
+ slug,
11441
+ name: {
11442
+ id: "workqueues.inProgress.title",
11443
+ defaultMessage: slug.charAt(0).toUpperCase() + slug.slice(1).split("-").join(" "),
11444
+ description: "Title of in progress workqueue"
11445
+ },
11446
+ query: {
11447
+ type: "and",
11448
+ clauses: [{ eventType: tennisClubMembershipEvent.id }]
11449
+ },
11450
+ action: { type: ActionType.READ },
11451
+ icon: "Draft"
11452
+ }
11453
+ ]);
11454
+ var generateEventConfig = ({
11455
+ id,
11456
+ fields,
11457
+ placeOfEventId,
11458
+ dateOfEventId,
11459
+ actions = []
11460
+ }) => {
11461
+ return defineConfig({
11462
+ id,
11463
+ label: generateTranslationConfig2(id),
11464
+ title: generateTranslationConfig2(`${id} Event`),
11465
+ summary: {
11466
+ fields: []
11467
+ },
11468
+ placeOfEvent: placeOfEventId ? { $$field: placeOfEventId } : void 0,
11469
+ dateOfEvent: dateOfEventId ? { $$field: dateOfEventId } : void 0,
11470
+ declaration: {
11471
+ label: generateTranslationConfig2(`${id} Declaration`),
11472
+ pages: [
11473
+ {
11474
+ id: "page1",
11475
+ title: generateTranslationConfig2("Page 1"),
11476
+ fields
11477
+ }
11478
+ ]
11479
+ },
11480
+ actions: [
11481
+ {
11482
+ type: ActionType.READ,
11483
+ label: generateTranslationConfig2("Read"),
11484
+ review: {
11485
+ title: generateTranslationConfig2("Review Read Action"),
11486
+ fields: []
11487
+ }
11488
+ },
11489
+ {
11490
+ type: ActionType.DECLARE,
11491
+ label: generateTranslationConfig2("Declare"),
11492
+ review: {
11493
+ title: generateTranslationConfig2("Review Declare Action"),
11494
+ fields: []
11495
+ }
11496
+ },
11497
+ ...actions
11498
+ ]
11499
+ });
11500
+ };
11501
+ function getLeafAdministrativeAreaIds(administrativeAreas) {
11502
+ const nonLeafAdministrativeAreaIds = /* @__PURE__ */ new Set();
11503
+ for (const [, location] of administrativeAreas) {
11504
+ if (location.parentId) {
11505
+ nonLeafAdministrativeAreaIds.add(location.parentId);
11506
+ }
11507
+ }
11508
+ const result = [];
11509
+ for (const [id] of administrativeAreas) {
11510
+ if (!nonLeafAdministrativeAreaIds.has(id)) {
11511
+ result.push({ id });
11512
+ }
11524
11513
  }
11514
+ return result;
11515
+ }
11516
+ function generateUserTokenPayload({
11517
+ role,
11518
+ scope
11519
+ }) {
11520
+ return {
11521
+ // @TODO: Validate which fields are necessary https://github.com/opencrvs/opencrvs-core/issues/13530
11522
+ sub: generateUuid(),
11523
+ algorithm: "RS256",
11524
+ exp: "1787221786",
11525
+ role: role ?? TestUserRole.enum.FIELD_AGENT,
11526
+ scope: scope ?? [
11527
+ encodeScope({
11528
+ type: "record.read"
11529
+ })
11530
+ ],
11531
+ userType: TokenUserType.enum.user
11532
+ };
11533
+ }
11534
+ function generateTestValidatorContext(userRole2, eventWithConfig) {
11535
+ const user2 = generateUserTokenPayload({ role: userRole2 });
11536
+ const leafAdminStructureLocationIds = getLeafAdministrativeAreaIds(
11537
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP
11538
+ );
11539
+ if (!eventWithConfig) {
11540
+ return { user: user2, leafAdminStructureLocationIds };
11541
+ }
11542
+ const { event: event2, eventConfig } = eventWithConfig;
11543
+ return {
11544
+ user: user2,
11545
+ leafAdminStructureLocationIds,
11546
+ event: getEventValidatorContext(event2, eventConfig)
11547
+ };
11548
+ }
11549
+
11550
+ // ../commons/src/events/TemplateConfig.ts
11551
+ var window2 = () => ({
11552
+ location: {
11553
+ get: (key) => {
11554
+ return `$window.location.${key}`;
11555
+ }
11556
+ }
11557
+ });
11558
+ function isTemplateVariable(value) {
11559
+ return typeof value === "string" && value.startsWith("$");
11560
+ }
11561
+ function isFieldValue(value) {
11562
+ return FieldValue.safeParse(value).success;
11563
+ }
11564
+ function isFieldValueWithoutTemplates(value) {
11565
+ if (isTemplateVariable(value)) {
11566
+ return false;
11567
+ }
11568
+ if (typeof value === "object" && value !== null && Object.values(value).some((val) => isTemplateVariable(val))) {
11569
+ return false;
11570
+ }
11571
+ return true;
11572
+ }
11573
+ function isFieldConfigDefaultValue(value) {
11574
+ if (!value) {
11575
+ return false;
11576
+ }
11577
+ if (isFieldValue(value)) {
11578
+ return true;
11579
+ }
11580
+ if (isTemplateVariable(value)) {
11581
+ return true;
11582
+ }
11583
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
11584
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
11585
+ }
11586
+ return false;
11587
+ }
11588
+
11589
+ // ../commons/src/events/scopes.ts
11590
+ var import_lodash6 = require("lodash");
11591
+ var ACTION_SCOPE_MAP = {
11592
+ [ActionType.READ]: ["record.read"],
11593
+ [ActionType.CREATE]: ["record.create"],
11594
+ [ActionType.NOTIFY]: ["record.notify"],
11595
+ [ActionType.DECLARE]: ["record.declare", "record.register"],
11596
+ [ActionType.EDIT]: ["record.edit"],
11597
+ [ActionType.DELETE]: ["record.declare", "record.notify"],
11598
+ [ActionType.REGISTER]: ["record.register"],
11599
+ [ActionType.PRINT_CERTIFICATE]: ["record.print-certified-copies"],
11600
+ [ActionType.REQUEST_CORRECTION]: [
11601
+ "record.request-correction",
11602
+ "record.correct"
11603
+ ],
11604
+ [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
11605
+ [ActionType.REJECT_CORRECTION]: ["record.correct"],
11606
+ [ActionType.APPROVE_CORRECTION]: ["record.correct"],
11607
+ [ActionType.MARK_AS_DUPLICATE]: ["record.review-duplicates"],
11608
+ [ActionType.MARK_AS_NOT_DUPLICATE]: ["record.review-duplicates"],
11609
+ [ActionType.ARCHIVE]: ["record.archive"],
11610
+ [ActionType.UNARCHIVE]: ["record.unarchive"],
11611
+ [ActionType.REJECT]: ["record.reject"],
11612
+ [ActionType.ASSIGN]: null,
11613
+ [ActionType.UNASSIGN]: null,
11614
+ [ActionType.DUPLICATE_DETECTED]: [],
11615
+ [ActionType.CUSTOM]: []
11616
+ };
11617
+ var RECORD_WRITE_SCOPES = (0, import_lodash6.uniq)(
11618
+ Object.entries(ACTION_SCOPE_MAP).filter(([action]) => action !== ActionType.READ).flatMap(([, scopes]) => scopes ?? [])
11619
+ );
11620
+ var DOCUMENT_DELETE_SCOPES = [
11621
+ "record.create",
11622
+ "record.notify",
11623
+ "record.declare",
11624
+ "record.register",
11625
+ "record.edit",
11626
+ "record.print-certified-copies",
11627
+ "record.request-correction",
11628
+ "record.correct",
11629
+ "record.review-duplicates",
11630
+ "record.archive",
11631
+ "record.unarchive",
11632
+ "record.reject",
11633
+ "user.edit"
11525
11634
  ];
11526
- var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS = MOCK_ADMINISTRATIVE_AREAS_BASE.map(withVersionFields);
11527
- var MOCK_LOCATIONS_BASE = [
11528
- {
11529
- id: "6f6186ce-cd5f-4a5f-810a-2d99e7c4ba12",
11530
- name: "Central Provincial Office",
11531
- locationType: "CRVS_OFFICE",
11532
- administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11533
- externalId: "Xr3Df8WpK6Ys"
11534
- },
11535
- {
11536
- id: "b1c2d3e4-f5a6-7890-bcde-f12345678901",
11537
- name: "Central Health Post",
11538
- locationType: "HEALTH_FACILITY",
11539
- administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c"
11540
- },
11541
- {
11542
- id: "028d2c85-ca31-426d-b5d1-2cef545a4902",
11543
- name: "Ibombo District Office",
11544
- locationType: "CRVS_OFFICE",
11545
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11546
- externalId: "Sm4Nw7GrD2Vy"
11547
- },
11548
- {
11549
- id: "62a0ccb4-4f30-4f30-8882-f256007dff9f",
11550
- name: "Isamba District Office",
11551
- locationType: "CRVS_OFFICE",
11552
- administrativeAreaId: "967032fd-3f81-478a-826c-30cb8fe121bd",
11553
- externalId: "Vg1Bq5XeH9Lt"
11554
- },
11555
- {
11556
- id: "954c93e1-13f7-4435-bb82-35e0e215e07d",
11557
- name: "Isango District Office",
11558
- locationType: "CRVS_OFFICE",
11559
- administrativeAreaId: "27160bbd-32d1-4625-812f-860226bfb92a",
11560
- externalId: "Je7Lm2XqN9Vz"
11561
- },
11562
- {
11563
- id: "2884f5b9-17b4-49ce-bf4d-f538228935df",
11564
- name: "Sulaka Provincial Office",
11565
- locationType: "CRVS_OFFICE",
11566
- administrativeAreaId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
11567
- externalId: "Ht2Wp9KcX5Qv"
11568
- },
11569
- {
11570
- id: "030358c6-54af-44be-821b-8e4af963a49c",
11571
- name: "Ilanga District Office",
11572
- locationType: "CRVS_OFFICE",
11573
- administrativeAreaId: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
11574
- externalId: "Yp6Ds1WqN3Xz"
11575
- },
11576
- {
11577
- id: "423d000f-101b-47c0-8b86-21a908067cee",
11578
- name: "Chamakubi Health Post",
11579
- locationType: "HEALTH_FACILITY",
11580
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11581
- externalId: "M1nFr8LbC2Qy"
11582
- },
11583
- {
11584
- id: "4d3279be-d026-420c-88f7-f0a4ae986973",
11585
- name: "Ibombo Rural Health Centre",
11586
- locationType: "HEALTH_FACILITY",
11587
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11588
- externalId: "bT7pV6YrW0Xc"
11589
- },
11590
- {
11591
- id: "190902f4-1d77-476a-8947-41145af1db7d",
11592
- name: "Chikobo Rural Health Centre",
11593
- locationType: "HEALTH_FACILITY",
11594
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11595
- externalId: "zE4qPn2SgJ5d"
11596
- },
11597
- {
11598
- id: "f5ecbd9b-a01e-4a65-910e-70e86ab41b71",
11599
- name: "Chilochabalenje Health Post",
11600
- locationType: "HEALTH_FACILITY",
11601
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11602
- externalId: "H8vDs1MqR4Uf"
11603
- },
11604
- {
11605
- id: "dbfc178f-7295-4b90-b28d-111c95b03127",
11606
- name: "Chipeso Rural Health Centre",
11607
- locationType: "HEALTH_FACILITY",
11608
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11609
- externalId: "Qw3uZ9KfX6Lm"
11610
- },
11611
- {
11612
- id: "09862bfe-c7ac-46cd-987b-668681533c80",
11613
- name: "Chisamba Rural Health Centre",
11614
- locationType: "HEALTH_FACILITY",
11615
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11616
- externalId: "Yr0pCg8LdM2s"
11617
- },
11618
- {
11619
- id: "834ce389-e95b-4fb0-96a0-33e9ab323059",
11620
- name: "Chitanda Rural Health Centre",
11621
- locationType: "HEALTH_FACILITY",
11622
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11623
- externalId: "tS9gJ4PwB1Qx"
11624
- },
11625
- {
11626
- id: "0431c433-6062-4a4c-aee9-25271aec61ee",
11627
- name: "Golden Valley Rural Health Centre",
11628
- locationType: "HEALTH_FACILITY",
11629
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11630
- externalId: "Ld7Qm3XsA8Vr"
11631
- },
11632
- {
11633
- id: "bc84d0b6-7ba7-480d-a339-5d9920d90eb2",
11634
- name: "Ipongo Rural Health Centre",
11635
- locationType: "HEALTH_FACILITY",
11636
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11637
- externalId: "kF2sW9DmH0Bt"
11638
- },
11639
- {
11640
- id: "4cf1f53b-b730-41d2-8649-dff7eeed970d",
11641
- name: "Itumbwe Health Post",
11642
- locationType: "HEALTH_FACILITY",
11643
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11644
- externalId: "Ue5Xb3VaC7Pq"
11645
- },
11646
- {
11647
- id: "4b3676cb-9355-4942-9eb9-2ce46acaf0e0",
11648
- name: "Kabangalala Rural Health Centre",
11649
- locationType: "HEALTH_FACILITY",
11650
- administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
11651
- externalId: "Pz8Kc1TqH6Jn"
11652
- },
11653
- // Village offices
11654
- {
11655
- id: "1f4a5b6c-7d8e-4312-8abc-345678901234",
11656
- name: "Klow Village Office",
11657
- locationType: "CRVS_OFFICE",
11658
- administrativeAreaId: "1d4e5f6a-7b8c-4912-8efa-345678901234",
11659
- externalId: "PmAyxAJkxiJ"
11635
+ function hasAnyOfScopes(a, b) {
11636
+ return (0, import_lodash6.intersection)(a, b).length > 0;
11637
+ }
11638
+ var AssignmentStatus = {
11639
+ ASSIGNED_TO_SELF: "ASSIGNED_TO_SELF",
11640
+ ASSIGNED_TO_OTHERS: "ASSIGNED_TO_OTHERS",
11641
+ UNASSIGNED: "UNASSIGNED"
11642
+ };
11643
+ function getAssignmentStatus(eventState, userId) {
11644
+ if (!eventState.assignedTo) {
11645
+ return AssignmentStatus.UNASSIGNED;
11646
+ }
11647
+ return eventState.assignedTo == userId ? AssignmentStatus.ASSIGNED_TO_SELF : AssignmentStatus.ASSIGNED_TO_OTHERS;
11648
+ }
11649
+ function isActionInScope({
11650
+ scopes,
11651
+ action,
11652
+ event: event2,
11653
+ currentUser
11654
+ }) {
11655
+ const assignmentStatus = getAssignmentStatus(event2, currentUser.id);
11656
+ const isUnassigningOthers = action === ActionType.UNASSIGN && assignmentStatus === AssignmentStatus.ASSIGNED_TO_OTHERS;
11657
+ const acceptedScopes = isUnassigningOthers ? ["record.unassign-others"] : ACTION_SCOPE_MAP[action];
11658
+ if (acceptedScopes === null) {
11659
+ return true;
11660
+ }
11661
+ if (!acceptedScopes.length) {
11662
+ return false;
11663
+ }
11664
+ const matchingScopes = getAcceptedScopesByType({
11665
+ acceptedScopes,
11666
+ scopes
11667
+ });
11668
+ const canAccess = userCanAccessEventWithScopes(
11669
+ event2,
11670
+ matchingScopes,
11671
+ {
11672
+ id: currentUser.id,
11673
+ primaryOfficeId: currentUser.primaryOfficeId,
11674
+ administrativeAreaId: currentUser.administrativeAreaId ?? null,
11675
+ role: currentUser.role,
11676
+ signature: currentUser.signature,
11677
+ type: currentUser.type
11678
+ }
11679
+ );
11680
+ return canAccess;
11681
+ }
11682
+ function getAvailableRolesForUserUpdatePayload({
11683
+ allRoles,
11684
+ userLocation,
11685
+ acceptedScopes,
11686
+ userRequesting
11687
+ }) {
11688
+ const availableRoles = allRoles.filter((role) => {
11689
+ const canAccess = canAccessOtherUserWithScopes({
11690
+ userToAccess: {
11691
+ ...userLocation,
11692
+ role
11693
+ },
11694
+ user: userRequesting,
11695
+ scopes: acceptedScopes
11696
+ });
11697
+ return canAccess;
11698
+ });
11699
+ return availableRoles;
11700
+ }
11701
+
11702
+ // ../commons/src/events/serializers/user/deserializer.ts
11703
+ function userDeserializer(serializedUserField, user2) {
11704
+ if (typeof serializedUserField === "string") {
11705
+ return serializedUserField;
11706
+ }
11707
+ if (typeof serializedUserField !== "object") {
11708
+ return void 0;
11709
+ }
11710
+ if (serializedUserField.$userField === "name" || serializedUserField.$userField === "fullHonorificName" || serializedUserField.$userField === "device" || serializedUserField.$userField === "firstname" || serializedUserField.$userField === "middlename" || serializedUserField.$userField === "surname") {
11711
+ throw new Error(
11712
+ `Deserializer for ${serializedUserField.$userField} is not implemented yet`
11713
+ );
11714
+ }
11715
+ const value = user2[serializedUserField.$userField];
11716
+ return typeof value === "string" ? value : void 0;
11717
+ }
11718
+ function isDefined(value) {
11719
+ return value !== void 0;
11720
+ }
11721
+ function serializeLocationField(expression, user2) {
11722
+ if (expression.type === "exact") {
11723
+ return userDeserializer(expression.term, user2);
11724
+ }
11725
+ if (expression.type === "within") {
11726
+ return userDeserializer(expression.location, user2);
11727
+ }
11728
+ return void 0;
11729
+ }
11730
+ function deserializeExpression(expression, user2) {
11731
+ if (expression.type === "exact") {
11732
+ const term = userDeserializer(expression.term, user2);
11733
+ if (!term) {
11734
+ return void 0;
11735
+ }
11736
+ return {
11737
+ ...expression,
11738
+ term
11739
+ };
11740
+ }
11741
+ if (expression.type === "within") {
11742
+ const location = userDeserializer(expression.location, user2);
11743
+ if (!location) {
11744
+ return void 0;
11745
+ }
11746
+ return {
11747
+ ...expression,
11748
+ location
11749
+ };
11660
11750
  }
11751
+ return void 0;
11752
+ }
11753
+ function deserializeQueryExpression(expression, user2) {
11754
+ const assignedTo = expression.assignedTo ? userDeserializer(expression.assignedTo.term, user2) : void 0;
11755
+ const createdBy = expression.createdBy ? userDeserializer(expression.createdBy.term, user2) : void 0;
11756
+ const updatedBy = expression.updatedBy ? userDeserializer(expression.updatedBy.term, user2) : void 0;
11757
+ const createdAtLocation = expression.createdAtLocation ? serializeLocationField(expression.createdAtLocation, user2) : void 0;
11758
+ const updatedAtLocation = expression.updatedAtLocation ? serializeLocationField(expression.updatedAtLocation, user2) : void 0;
11759
+ const updatedByUserRole = expression.updatedByUserRole ? userDeserializer(expression.updatedByUserRole.term, user2) : void 0;
11760
+ const declaredLocation = expression["legalStatuses.DECLARED.createdAtLocation"] ? userDeserializer(
11761
+ expression["legalStatuses.DECLARED.createdAtLocation"].location,
11762
+ user2
11763
+ ) : void 0;
11764
+ const registeredLocation = expression["legalStatuses.REGISTERED.createdAtLocation"] ? userDeserializer(
11765
+ expression["legalStatuses.REGISTERED.createdAtLocation"].location,
11766
+ user2
11767
+ ) : void 0;
11768
+ return {
11769
+ ...expression,
11770
+ assignedTo: expression.assignedTo && isDefined(assignedTo) ? { ...expression.assignedTo, term: assignedTo } : void 0,
11771
+ createdBy: expression.createdBy && isDefined(createdBy) ? { ...expression.createdBy, term: createdBy } : void 0,
11772
+ updatedBy: expression.updatedBy && isDefined(updatedBy) ? { ...expression.updatedBy, term: updatedBy } : void 0,
11773
+ updatedByUserRole: expression.updatedByUserRole && isDefined(updatedByUserRole) ? {
11774
+ ...expression.updatedByUserRole,
11775
+ term: updatedByUserRole
11776
+ } : void 0,
11777
+ createdAtLocation: expression.createdAtLocation && isDefined(createdAtLocation) ? deserializeExpression(expression.createdAtLocation, user2) : void 0,
11778
+ updatedAtLocation: expression.updatedAtLocation && isDefined(updatedAtLocation) ? deserializeExpression(expression.updatedAtLocation, user2) : void 0,
11779
+ ["legalStatuses.DECLARED.createdAtLocation"]: expression["legalStatuses.DECLARED.createdAtLocation"] && isDefined(declaredLocation) ? {
11780
+ ...expression["legalStatuses.DECLARED.createdAtLocation"],
11781
+ location: declaredLocation
11782
+ } : void 0,
11783
+ ["legalStatuses.REGISTERED.createdAtLocation"]: expression["legalStatuses.REGISTERED.createdAtLocation"] && isDefined(registeredLocation) ? {
11784
+ ...expression["legalStatuses.REGISTERED.createdAtLocation"],
11785
+ location: registeredLocation
11786
+ } : void 0
11787
+ };
11788
+ }
11789
+ function deserializeQuery(query, user2) {
11790
+ return {
11791
+ ...query,
11792
+ clauses: query.clauses.map(
11793
+ (clause) => deserializeQueryExpression(clause, user2)
11794
+ // SAFETY: This cast should be safe because `query.clauses` has already been validated as non-empty by the Zod schema.
11795
+ // Without the cast, TypeScript cannot infer the tuple type required by the target interface.
11796
+ )
11797
+ };
11798
+ }
11799
+
11800
+ // ../commons/src/events/state/availableActions.ts
11801
+ var AVAILABLE_ACTIONS_BY_EVENT_STATUS = {
11802
+ [EventStatus.enum.CREATED]: [
11803
+ ActionType.READ,
11804
+ ActionType.DECLARE,
11805
+ ActionType.NOTIFY,
11806
+ ActionType.DELETE
11807
+ ],
11808
+ [EventStatus.enum.NOTIFIED]: [
11809
+ ActionType.READ,
11810
+ ActionType.EDIT,
11811
+ ActionType.MARK_AS_DUPLICATE,
11812
+ ActionType.ARCHIVE,
11813
+ ActionType.REJECT,
11814
+ ActionType.CUSTOM
11815
+ ],
11816
+ [EventStatus.enum.DECLARED]: [
11817
+ ActionType.READ,
11818
+ ActionType.REGISTER,
11819
+ ActionType.MARK_AS_DUPLICATE,
11820
+ ActionType.ARCHIVE,
11821
+ ActionType.REJECT,
11822
+ ActionType.CUSTOM,
11823
+ ActionType.EDIT
11824
+ ],
11825
+ [EventStatus.enum.REGISTERED]: [
11826
+ ActionType.READ,
11827
+ ActionType.PRINT_CERTIFICATE,
11828
+ ActionType.REQUEST_CORRECTION,
11829
+ ActionType.APPROVE_CORRECTION,
11830
+ ActionType.REJECT_CORRECTION,
11831
+ ActionType.CUSTOM,
11832
+ ClientSpecificAction.REVIEW_CORRECTION_REQUEST
11833
+ ],
11834
+ [EventStatus.enum.ARCHIVED]: [
11835
+ ActionType.READ,
11836
+ ActionType.CUSTOM,
11837
+ ActionType.UNARCHIVE
11838
+ ]
11839
+ };
11840
+ var ACTION_FILTERS = {
11841
+ [ActionType.PRINT_CERTIFICATE]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11842
+ [ActionType.REQUEST_CORRECTION]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11843
+ [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11844
+ [ActionType.APPROVE_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11845
+ [ActionType.REJECT_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11846
+ [ActionType.MARK_AS_DUPLICATE]: (flags) => flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11847
+ [ActionType.EDIT]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11848
+ [ActionType.REGISTER]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11849
+ [ActionType.REJECT]: (flags) => !flags.includes(InherentFlags.REJECTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11850
+ [ActionType.ARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11851
+ [ActionType.UNARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11852
+ [ActionType.ASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11853
+ [ActionType.UNASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11854
+ [ActionType.CUSTOM]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested"))
11855
+ };
11856
+ function filterActionsByFlags(actions, flags) {
11857
+ return actions.filter((action) => ACTION_FILTERS[action]?.(flags) ?? true);
11858
+ }
11859
+ var REJECTED_ACTIONS = [
11860
+ ActionType.READ,
11861
+ ActionType.NOTIFY,
11862
+ ActionType.CUSTOM,
11863
+ ActionType.EDIT,
11864
+ ActionType.ARCHIVE
11661
11865
  ];
11662
- var V2_DEFAULT_MOCK_LOCATIONS = MOCK_LOCATIONS_BASE.map(withVersionFields);
11663
- var V2_DEFAULT_MOCK_LOCATIONS_MAP = new Map(
11664
- V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, l])
11665
- );
11666
- var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP = new Map(
11667
- V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [a.id, a])
11668
- );
11669
- var V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP = new Map(
11670
- V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, toClientLocation(l)])
11671
- );
11672
- var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
11673
- V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [
11674
- a.id,
11675
- toClientAdministrativeArea(a)
11676
- ])
11677
- );
11866
+ function getAvailableActionsWithoutFlagFilters(status2, flags) {
11867
+ if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
11868
+ return [ActionType.NOTIFY, ActionType.DECLARE, ActionType.REGISTER];
11869
+ }
11870
+ if (flags.includes(InherentFlags.REJECTED) && status2 !== EventStatus.enum.ARCHIVED) {
11871
+ return REJECTED_ACTIONS;
11872
+ }
11873
+ return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
11874
+ }
11875
+ function getAvailableActionsForEvent(event2) {
11876
+ return filterActionsByFlags(
11877
+ getAvailableActionsWithoutFlagFilters(event2.status, event2.flags),
11878
+ event2.flags
11879
+ );
11880
+ }
11881
+
11882
+ // ../commons/src/events/FileUtils.ts
11883
+ var import_lodash7 = require("lodash");
11884
+ function carriesFieldValues(action) {
11885
+ return "declaration" in action;
11886
+ }
11887
+ function getFilePathsFromEvent(event2) {
11888
+ const filepaths = event2.actions.filter(carriesFieldValues).flatMap((action) => {
11889
+ const declarationValues = Object.values(action.declaration);
11890
+ const annotationValues = Object.values(action.annotation ?? {});
11891
+ const actionFilePaths = [
11892
+ ...declarationValues,
11893
+ ...annotationValues
11894
+ ].flatMap((value) => {
11895
+ const fileParsed = FileFieldValue.safeParse(value);
11896
+ if (fileParsed.success) {
11897
+ return [fileParsed.data.path];
11898
+ }
11899
+ const fileOptionParsed = FileFieldWithOptionValue.safeParse(value);
11900
+ if (fileOptionParsed.success) {
11901
+ return fileOptionParsed.data.map((val) => val.path);
11902
+ }
11903
+ return [];
11904
+ });
11905
+ return actionFilePaths;
11906
+ });
11907
+ return (0, import_lodash7.uniq)(filepaths);
11908
+ }
11678
11909
 
11679
11910
  // ../commons/src/events/locationPayloads.ts
11680
11911
  var z45 = __toESM(require("zod/v4"));