@opencrvs/toolkit 2.1.0-rc.05a1257 → 2.1.0-rc.05b7761

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 (66) hide show
  1. package/README.md +2 -12
  2. package/build.sh +10 -3
  3. package/create-countryconfig/index.js +338 -4
  4. package/dist/application-config/index.js +17 -18
  5. package/dist/authentication/index.d.ts +67 -0
  6. package/dist/authentication/index.d.ts.map +1 -0
  7. package/dist/authentication/index.js +751 -0
  8. package/dist/cli.js +1090 -187
  9. package/dist/commons/api/router.d.ts +6 -42
  10. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  11. package/dist/commons/conditionals/validate.d.ts +1 -1
  12. package/dist/commons/events/ActionConfig.d.ts +4 -0
  13. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -12
  14. package/dist/commons/events/FieldConfig.d.ts +16 -15
  15. package/dist/commons/events/FormConfig.d.ts +6 -0
  16. package/dist/commons/events/PageConfig.d.ts +4 -0
  17. package/dist/commons/events/locations.d.ts +4 -0
  18. package/dist/commons/events/test.utils.d.ts +18 -1
  19. package/dist/commons/events/utils.d.ts +15 -0
  20. package/dist/commons/notification/dispatch.d.ts +1 -6
  21. package/dist/conditionals/index.js +7 -6
  22. package/dist/csv.d.ts.map +1 -1
  23. package/dist/csv.js +7 -2
  24. package/dist/environment/logger.d.ts +3 -0
  25. package/dist/environment/logger.d.ts.map +1 -1
  26. package/dist/environment/manage-users.js +1 -1
  27. package/dist/environment/setup-environment.js +44 -26
  28. package/dist/environment/templates.d.ts +0 -1
  29. package/dist/environment/templates.d.ts.map +1 -1
  30. package/dist/environment/templates.js +3 -8
  31. package/dist/environment/update-workflows.d.ts.map +1 -1
  32. package/dist/environment/update-workflows.js +4 -0
  33. package/dist/environment/utils.d.ts +0 -12
  34. package/dist/environment/utils.d.ts.map +1 -1
  35. package/dist/environment/utils.js +1 -28
  36. package/dist/events/index.js +1901 -1792
  37. package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
  38. package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
  39. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
  40. package/dist/migrations/v2.1/add-translations.js +42 -11
  41. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  42. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  43. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  44. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  45. package/dist/migrations/v2.1/index.js +601 -19
  46. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +3 -0
  47. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  48. package/dist/migrations/v2.1/rename-trigger-paths.js +216 -0
  49. package/dist/notification/index.js +167 -155
  50. package/dist/scopes/index.d.ts +109 -5
  51. package/dist/scopes/index.js +7 -6
  52. package/dist/telemetry/index.d.ts +45 -0
  53. package/dist/telemetry/index.d.ts.map +1 -0
  54. package/dist/telemetry/index.js +43 -0
  55. package/dist/templates/charts-values/dependencies/values.yaml +2 -0
  56. package/dist/translations/check.d.ts +2 -4
  57. package/dist/translations/check.d.ts.map +1 -1
  58. package/dist/translations/check.js +14 -8
  59. package/dist/verify/endpoints.d.ts +2 -0
  60. package/dist/verify/endpoints.d.ts.map +1 -0
  61. package/dist/verify/endpoints.js +345 -0
  62. package/opencrvs-toolkit-2.1.0-rc.05b7761.tgz +0 -0
  63. package/package.json +5 -2
  64. package/tsconfig.build.tsbuildinfo +1 -1
  65. package/tsconfig.json +3 -0
  66. package/opencrvs-toolkit-2.1.0-rc.05a1257.tgz +0 -0
@@ -162,6 +162,7 @@ __export(events_exports, {
162
162
  HttpFieldValue: () => HttpFieldValue,
163
163
  IdReaderFieldValue: () => IdReaderFieldValue,
164
164
  ImageMimeType: () => ImageMimeType,
165
+ InactiveOfficeError: () => InactiveOfficeError,
165
166
  InfoBox: () => InfoBox,
166
167
  InherentFlags: () => InherentFlags,
167
168
  LanguageConfig: () => LanguageConfig,
@@ -292,6 +293,7 @@ __export(events_exports, {
292
293
  defineWorkqueues: () => defineWorkqueues,
293
294
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
294
295
  deserializeQuery: () => deserializeQuery,
296
+ dropSecuredDeclarationFields: () => dropSecuredDeclarationFields,
295
297
  errorMessages: () => errorMessages,
296
298
  evaluate: () => evaluate,
297
299
  event: () => event,
@@ -321,6 +323,7 @@ __export(events_exports, {
321
323
  generateRandomName: () => generateRandomName,
322
324
  generateRandomSignature: () => generateRandomSignature,
323
325
  generateRegistrationNumber: () => generateRegistrationNumber,
326
+ generateTestValidatorContext: () => generateTestValidatorContext,
324
327
  generateTrackingId: () => generateTrackingId,
325
328
  generateTransactionId: () => generateTransactionId,
326
329
  generateTranslationConfig: () => generateTranslationConfig2,
@@ -353,6 +356,7 @@ __export(events_exports, {
353
356
  getEventFlags: () => getEventFlags,
354
357
  getEventValidatorContext: () => getEventValidatorContext,
355
358
  getFilePathsFromEvent: () => getFilePathsFromEvent,
359
+ getLeafAdministrativeAreaIds: () => getLeafAdministrativeAreaIds,
356
360
  getLocationHierarchy: () => getLocationHierarchy,
357
361
  getMixedPath: () => getMixedPath,
358
362
  getPendingAction: () => getPendingAction,
@@ -800,10 +804,7 @@ var PlainScopeType = z7.enum([
800
804
  // Performance dashboard
801
805
  "performance.read",
802
806
  "performance.read-dashboards",
803
- "performance.vital-statistics-export",
804
- // Scopes used exclusively by countryconfig integration token
805
- "record.confirm-registration",
806
- "record.reject-registration"
807
+ "performance.vital-statistics-export"
807
808
  ]);
808
809
  var scopeByEvent = z7.preprocess(
809
810
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -821,7 +822,9 @@ var userRole = z7.preprocess(
821
822
  ).describe("User role, e.g. admin, field agent");
822
823
  var scopeOptionsPlaceEvent = z7.object({
823
824
  event: scopeByEvent,
824
- placeOfEvent: JurisdictionFilter.optional()
825
+ placeOfEvent: JurisdictionFilter.optional(),
826
+ createdBy: UserFilter.optional(),
827
+ createdIn: JurisdictionFilter.optional()
825
828
  }).describe("Options applicable to all record scopes.");
826
829
  var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
827
830
  notifiedIn: JurisdictionFilter.optional(),
@@ -864,7 +867,9 @@ var AllScopeOptions = z7.object({
864
867
  var ScopeOptionKey = AllScopeOptions.keyof();
865
868
  var ResolvedScopeOptionsPlaceEvent = z7.object({
866
869
  event: scopeByEvent,
867
- placeOfEvent: UUID.nullish()
870
+ placeOfEvent: UUID.nullish(),
871
+ createdBy: z7.string().optional(),
872
+ createdIn: UUID.nullish()
868
873
  }).describe(
869
874
  "Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
870
875
  );
@@ -1018,11 +1023,25 @@ var ScopeType = z7.enum([
1018
1023
  "workqueue",
1019
1024
  "dashboard.view"
1020
1025
  ]);
1026
+ var flattenScope = (scope) => ({
1027
+ type: scope.type,
1028
+ ..."options" in scope ? scope.options : {}
1029
+ });
1021
1030
  var unflattenScope = (input) => {
1022
1031
  const { type, ...options } = input;
1023
1032
  return { type, options };
1024
1033
  };
1025
1034
  var EncodedScope = z7.string().brand("EncodedScope");
1035
+ var encodeScope = (scope) => {
1036
+ const flattened = flattenScope(scope);
1037
+ return qs.stringify(flattened, {
1038
+ arrayFormat: "comma",
1039
+ commaRoundTrip: true,
1040
+ allowDots: true,
1041
+ addQueryPrefix: false,
1042
+ encode: false
1043
+ });
1044
+ };
1026
1045
  var decodedScopeCache = /* @__PURE__ */ new Map();
1027
1046
  var decodeScope = (encodedScope) => {
1028
1047
  if (decodedScopeCache.has(encodedScope)) {
@@ -2825,9 +2844,6 @@ var AdministrativeAreaField = BaseField.extend({
2825
2844
  partOf: FieldReference.optional().describe("Parent location"),
2826
2845
  type: AdministrativeAreas,
2827
2846
  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
2847
  activeOnly: import_v43.default.boolean().optional().describe(
2832
2848
  "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
2849
  ),
@@ -2845,9 +2861,6 @@ var LocationInput = BaseField.extend({
2845
2861
  configuration: import_v43.default.object({
2846
2862
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2847
2863
  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
2864
  activeOnly: import_v43.default.boolean().optional().describe(
2852
2865
  "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
2866
  ),
@@ -2881,7 +2894,6 @@ var Facility = BaseField.extend({
2881
2894
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2882
2895
  configuration: import_v43.default.object({
2883
2896
  allowedLocations: AllowedLocations,
2884
- listHistoricalNames: import_v43.default.boolean().optional(),
2885
2897
  activeOnly: import_v43.default.boolean().optional(),
2886
2898
  anchorToDateOfEvent: import_v43.default.boolean().optional()
2887
2899
  }).optional()
@@ -2891,7 +2903,6 @@ var Office = BaseField.extend({
2891
2903
  defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2892
2904
  configuration: import_v43.default.object({
2893
2905
  allowedLocations: AllowedLocations,
2894
- listHistoricalNames: import_v43.default.boolean().optional(),
2895
2906
  activeOnly: import_v43.default.boolean().optional(),
2896
2907
  anchorToDateOfEvent: import_v43.default.boolean().optional()
2897
2908
  }).optional()
@@ -2928,9 +2939,6 @@ var Address = BaseField.extend({
2928
2939
  })
2929
2940
  ).optional(),
2930
2941
  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
2942
  activeOnly: import_v43.default.boolean().optional().describe(
2935
2943
  "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
2944
  ),
@@ -2991,10 +2999,19 @@ var ButtonField = BaseField.extend({
2991
2999
  description: "A generic button that can be used to trigger an action",
2992
3000
  id: "ButtonField"
2993
3001
  });
3002
+ var FieldGroupConfiguration = import_v43.default.object({
3003
+ separator: import_v43.default.string().optional().describe(
3004
+ 'Joins the subfield values when the group is rendered as output, e.g. ", ". Defaults to one subfield per line.'
3005
+ ),
3006
+ hideEmptyFields: import_v43.default.boolean().default(false).optional().describe(
3007
+ "Leaves subfields without a value out of the output. Pair it with a separator so the separator does not double up around the gaps."
3008
+ )
3009
+ });
2994
3010
  var FieldGroup = BaseField.extend({
2995
3011
  type: import_v43.default.literal(FieldType.FIELD_GROUP),
2996
3012
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
2997
- fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig))
3013
+ fields: import_v43.default.lazy(() => import_v43.default.array(FieldConfig)),
3014
+ configuration: FieldGroupConfiguration.optional()
2998
3015
  }).meta({
2999
3016
  description: "A group of fields that are displayed together",
3000
3017
  id: "FieldGroup"
@@ -3248,6 +3265,9 @@ var PageConfigBase = z22.object({
3248
3265
  requireCompletionToContinue: z22.boolean().default(false).describe(
3249
3266
  "If true, all required fields must be filled before continuing to the next page"
3250
3267
  ),
3268
+ showClearButton: z22.boolean().optional().describe(
3269
+ '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'
3270
+ ),
3251
3271
  fields: z22.array(FieldConfig).describe("Fields to be rendered on the page"),
3252
3272
  conditional: Conditional.optional().describe(
3253
3273
  "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
@@ -5831,7 +5851,7 @@ function areConditionsMet(conditions, values, context, event2) {
5831
5851
  (condition) => validate(condition.conditional, clientFunctionContext)
5832
5852
  );
5833
5853
  }
5834
- function isFieldSecured(field3, event2, context = {}) {
5854
+ function isFieldSecured(field3, event2, context) {
5835
5855
  if (typeof field3.secured !== "object" || field3.secured === null) {
5836
5856
  return Boolean(field3.secured);
5837
5857
  }
@@ -6596,6 +6616,23 @@ function aggregateActionAnnotations(event2) {
6596
6616
  return deepMerge(ann, sortedAction.annotation);
6597
6617
  }, {});
6598
6618
  }
6619
+ function dropSecuredDeclarationFields(eventConfig, eventIndex, validatorContext) {
6620
+ const declarationFields = getDeclarationFields(eventConfig);
6621
+ const securedFieldIds = new Set(
6622
+ declarationFields.filter(
6623
+ (declarationField) => isFieldSecured(declarationField, eventIndex, validatorContext)
6624
+ ).map((declarationField) => declarationField.id)
6625
+ );
6626
+ const declaration = Object.fromEntries(
6627
+ Object.entries(eventIndex.declaration).filter(
6628
+ ([fieldId]) => !securedFieldIds.has(fieldId)
6629
+ )
6630
+ );
6631
+ return {
6632
+ ...eventIndex,
6633
+ declaration
6634
+ };
6635
+ }
6599
6636
 
6600
6637
  // ../commons/src/events/eventConfigValidation.ts
6601
6638
  function validateAdvancedSearchConfig(event2, ctx) {
@@ -8183,6 +8220,7 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
8183
8220
  defaultMessage: "Who is applying for the membership?",
8184
8221
  description: "This is the title of the section"
8185
8222
  },
8223
+ showClearButton: true,
8186
8224
  fields: [
8187
8225
  {
8188
8226
  id: "applicant.name",
@@ -9853,1828 +9891,1899 @@ var digitalIdentityEvent = defineConfig({
9853
9891
  });
9854
9892
 
9855
9893
  // ../commons/src/events/test.utils.ts
9894
+ var z44 = __toESM(require("zod/v4"));
9895
+
9896
+ // ../commons/src/events/locations.ts
9856
9897
  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"
9898
+ var LocationTypeV1 = z43.enum([
9899
+ "ADMIN_STRUCTURE",
9900
+ "CRVS_OFFICE",
9901
+ "HEALTH_FACILITY"
9868
9902
  ]);
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
- ];
9903
+ var LocationStatus = z43.enum(["active", "inactive"]);
9904
+ var InactiveOfficeError = class extends Error {
9905
+ constructor(message = "Assigned office is inactive") {
9906
+ super(message);
9907
+ this.name = "InactiveOfficeError";
9908
+ }
9909
+ };
9910
+ var LocationVersion = z43.object({
9911
+ versionId: UUID,
9912
+ effectiveFrom: z43.iso.date(),
9913
+ name: z43.string(),
9914
+ externalId: z43.string().nullish(),
9915
+ status: LocationStatus
9916
+ });
9917
+ var AdministrativeArea = z43.object({
9918
+ id: UUID,
9919
+ name: z43.string(),
9920
+ externalId: z43.string().nullish(),
9921
+ parentId: UUID.nullable(),
9922
+ status: LocationStatus,
9923
+ versions: z43.array(LocationVersion)
9924
+ });
9925
+ var Location = z43.object({
9926
+ id: UUID,
9927
+ name: z43.string(),
9928
+ externalId: z43.string().nullish(),
9929
+ administrativeAreaId: UUID.nullable(),
9930
+ locationType: z43.string().nullable(),
9931
+ status: LocationStatus,
9932
+ versions: z43.array(LocationVersion)
9933
+ });
9934
+ var ClientAdministrativeArea = AdministrativeArea.omit({
9935
+ name: true,
9936
+ status: true,
9937
+ externalId: true
9938
+ });
9939
+ var ClientLocation = Location.omit({
9940
+ name: true,
9941
+ status: true,
9942
+ externalId: true
9943
+ });
9944
+ function toClientLocation(location) {
9903
9945
  return {
9904
- firstname: pickRandom(rng, firstnames),
9905
- surname: pickRandom(rng, surnames)
9946
+ id: location.id,
9947
+ administrativeAreaId: location.administrativeAreaId,
9948
+ locationType: location.locationType,
9949
+ versions: location.versions
9906
9950
  };
9907
9951
  }
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
- });
9952
+ function toClientAdministrativeArea(area) {
9953
+ return {
9954
+ id: area.id,
9955
+ parentId: area.parentId,
9956
+ versions: area.versions
9957
+ };
9914
9958
  }
9915
- function generateTrackingId(rng) {
9916
- const uuid2 = generateUuid(rng).replace(/-/g, "");
9917
- const trackingId = uuid2.slice(0, 6).toUpperCase();
9918
- return trackingId;
9959
+ function validateAscendingDates(versions, ctx) {
9960
+ const ascending = versions.every(
9961
+ (version, index) => index === 0 || versions[index - 1].effectiveFrom < version.effectiveFrom
9962
+ );
9963
+ if (!ascending) {
9964
+ ctx.addIssue("versions must be strictly ascending by effectiveFrom");
9965
+ }
9919
9966
  }
9920
- function generateRegistrationNumber(rng) {
9921
- const uuid2 = generateUuid(rng).replace(/-/g, "");
9922
- const registrationNumber = uuid2.slice(0, 12).toUpperCase();
9923
- return registrationNumber;
9967
+ function validateUniqueIds(versions, ctx) {
9968
+ const versionIds = new Set(versions.map((version) => version.versionId));
9969
+ if (versionIds.size !== versions.length) {
9970
+ ctx.addIssue("versions must not repeat a versionId");
9971
+ }
9924
9972
  }
9925
- function generateRandomSignature(rng) {
9926
- return `${generateUuid(rng)}.png`;
9973
+ var SeededLocationVersions = z43.array(LocationVersion).min(1).superRefine((versions, ctx) => {
9974
+ validateAscendingDates(versions, ctx);
9975
+ validateUniqueIds(versions, ctx);
9976
+ });
9977
+ var SetLocationPayload = z43.object({
9978
+ id: UUID,
9979
+ name: z43.string(),
9980
+ externalId: z43.string().nullish(),
9981
+ administrativeAreaId: UUID.nullable(),
9982
+ locationType: z43.string().nullable(),
9983
+ versions: SeededLocationVersions.optional()
9984
+ });
9985
+ var SetAdministrativeAreaPayload = z43.object({
9986
+ id: UUID,
9987
+ name: z43.string(),
9988
+ externalId: z43.string().nullish(),
9989
+ parentId: UUID.nullable(),
9990
+ versions: SeededLocationVersions.optional()
9991
+ });
9992
+ function resolveVersion(versions, anchor) {
9993
+ let resolved = versions[0];
9994
+ for (const version of versions) {
9995
+ if (version.effectiveFrom <= anchor) {
9996
+ resolved = version;
9997
+ }
9998
+ }
9999
+ return resolved;
9927
10000
  }
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
- };
10001
+ function isSelectableAtAnchor(versions, anchor) {
10002
+ return versions.some((version) => version.effectiveFrom <= anchor) && resolveVersion(versions, anchor).status === "active";
9937
10003
  }
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
- )
10004
+ function hasActiveExternalIdOnOrAfter(versions, externalId, anchor) {
10005
+ const inEffectAtAnchor = resolveVersion(versions, anchor);
10006
+ const laterVersions = versions.filter((v) => v.effectiveFrom > anchor);
10007
+ return [inEffectAtAnchor, ...laterVersions].some(
10008
+ (v) => v.externalId === externalId && v.status === "active"
9943
10009
  );
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;
10010
+ }
10011
+ function matchesJurisdictionFilter(locationIds, filter, user2) {
10012
+ if (!locationIds) {
10013
+ return false;
10014
+ }
10015
+ if (filter === JurisdictionFilter.enum.location) {
10016
+ return locationIds.some((id) => id === user2.primaryOfficeId);
10017
+ }
10018
+ if (filter === JurisdictionFilter.enum.administrativeArea) {
10019
+ return !user2.administrativeAreaId || locationIds.some((id) => id === user2.administrativeAreaId);
10020
+ }
10021
+ return true;
10022
+ }
10023
+ function matchesFlagsFilter(eventFlags, flags) {
10024
+ const currentFlags = eventFlags ?? [];
10025
+ if (flags.anyOf && !flags.anyOf.some((flag2) => currentFlags.includes(flag2))) {
10026
+ return false;
10027
+ }
10028
+ if (flags.noneOf && flags.noneOf.some((flag2) => currentFlags.includes(flag2))) {
10029
+ return false;
10030
+ }
10031
+ if (flags.allOf && !flags.allOf.every((flag2) => currentFlags.includes(flag2))) {
10032
+ return false;
10033
+ }
10034
+ return true;
10035
+ }
10036
+ function canAccessEventWithScope(event2, scope, user2, customActionType) {
10037
+ const opts = scope.options;
10038
+ if (opts?.event) {
10039
+ if (!event2.type || !opts.event.includes(event2.type)) {
10040
+ return false;
9958
10041
  }
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
10042
  }
10057
- }
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
- {}
10070
- );
10071
- }
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 {};
10043
+ if (opts?.placeOfEvent === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10044
+ event2.placeOfEvent,
10045
+ JurisdictionFilter.enum.location,
10046
+ user2
10047
+ )) {
10048
+ return false;
10076
10049
  }
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
- );
10050
+ if (opts?.placeOfEvent === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10051
+ event2.placeOfEvent,
10052
+ JurisdictionFilter.enum.administrativeArea,
10053
+ user2
10054
+ )) {
10055
+ return false;
10095
10056
  }
10096
- console.warn(`${action} is not a declaration action. Setting data as {}.`);
10097
- return {};
10057
+ if (opts?.createdBy === UserFilter.enum.user && event2.createdBy !== user2.id) {
10058
+ return false;
10059
+ }
10060
+ if (opts?.createdIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10061
+ event2.createdAtLocation,
10062
+ JurisdictionFilter.enum.location,
10063
+ user2
10064
+ )) {
10065
+ return false;
10066
+ }
10067
+ if (opts?.createdIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10068
+ event2.createdAtLocation,
10069
+ JurisdictionFilter.enum.administrativeArea,
10070
+ user2
10071
+ )) {
10072
+ return false;
10073
+ }
10074
+ if (scopeUsesDeclaredOptions(scope)) {
10075
+ const { options } = scope;
10076
+ if (options?.status && (!event2.status || !options.status.includes(event2.status))) {
10077
+ return false;
10078
+ }
10079
+ if (options?.notifiedBy === UserFilter.enum.user) {
10080
+ if (event2.legalStatuses?.NOTIFIED?.createdBy !== user2.id) {
10081
+ return false;
10082
+ }
10083
+ }
10084
+ if (options?.notifiedIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10085
+ event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10086
+ JurisdictionFilter.enum.location,
10087
+ user2
10088
+ )) {
10089
+ return false;
10090
+ }
10091
+ if (options?.notifiedIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10092
+ event2.legalStatuses?.NOTIFIED?.createdAtLocation,
10093
+ JurisdictionFilter.enum.administrativeArea,
10094
+ user2
10095
+ )) {
10096
+ return false;
10097
+ }
10098
+ if (options?.declaredBy === UserFilter.enum.user) {
10099
+ if (event2.legalStatuses?.DECLARED?.createdBy !== user2.id) {
10100
+ return false;
10101
+ }
10102
+ }
10103
+ if (options?.declaredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10104
+ event2.legalStatuses?.DECLARED?.createdAtLocation,
10105
+ JurisdictionFilter.enum.location,
10106
+ user2
10107
+ )) {
10108
+ return false;
10109
+ }
10110
+ if (options?.declaredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10111
+ event2.legalStatuses?.DECLARED?.createdAtLocation,
10112
+ JurisdictionFilter.enum.administrativeArea,
10113
+ user2
10114
+ )) {
10115
+ return false;
10116
+ }
10117
+ }
10118
+ if (scopeUsesFullOptions(scope) || scopeUsesPrintCertifiedCopiesOptions(scope) || isCustomActionScope(scope)) {
10119
+ const { options } = scope;
10120
+ if (options?.registeredBy === UserFilter.enum.user) {
10121
+ if (event2.legalStatuses?.REGISTERED?.createdBy !== user2.id) {
10122
+ return false;
10123
+ }
10124
+ }
10125
+ if (options?.registeredIn === JurisdictionFilter.enum.location && !matchesJurisdictionFilter(
10126
+ event2.legalStatuses?.REGISTERED?.createdAtLocation,
10127
+ JurisdictionFilter.enum.location,
10128
+ user2
10129
+ )) {
10130
+ return false;
10131
+ }
10132
+ if (options?.registeredIn === JurisdictionFilter.enum.administrativeArea && !matchesJurisdictionFilter(
10133
+ event2.legalStatuses?.REGISTERED?.createdAtLocation,
10134
+ JurisdictionFilter.enum.administrativeArea,
10135
+ user2
10136
+ )) {
10137
+ return false;
10138
+ }
10139
+ if (options?.flags && !matchesFlagsFilter(event2.flags, options.flags)) {
10140
+ return false;
10141
+ }
10142
+ }
10143
+ if (isCustomActionScope(scope)) {
10144
+ const { options } = scope;
10145
+ if (!customActionType || !options?.customActionTypes || !options?.customActionTypes.includes(customActionType)) {
10146
+ return false;
10147
+ }
10148
+ }
10149
+ return true;
10098
10150
  }
10099
- function generateActionDuplicateDeclarationInput(...args) {
10100
- const [configuration, action, rng, overrides] = args;
10101
- return generateActionDeclarationInput(configuration, action, rng, {
10102
- ...overrides,
10103
- "applicant.dobUnknown": false
10104
- });
10151
+ function canAccessUserWithScope({
10152
+ userToAccess,
10153
+ scope,
10154
+ user: user2
10155
+ }) {
10156
+ const opts = scope.options;
10157
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
10158
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
10159
+ return false;
10160
+ }
10161
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
10162
+ (id) => user2.administrativeAreaId === id
10163
+ ) || !user2.administrativeAreaId;
10164
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
10165
+ return false;
10166
+ }
10167
+ if (scopeUsesRoleOptions(scope)) {
10168
+ const { options } = scope;
10169
+ if (options?.role && !options.role.includes(userToAccess.role)) {
10170
+ return false;
10171
+ }
10172
+ }
10173
+ return true;
10105
10174
  }
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
- {}
10175
+ function canAccessOtherUserWithScopes({
10176
+ scopes,
10177
+ userToAccess,
10178
+ user: user2
10179
+ }) {
10180
+ return scopes.some(
10181
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
10116
10182
  );
10117
- const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
10118
- (acc, pageId) => ({
10119
- ...acc,
10120
- [pageId]: true
10121
- }),
10122
- {}
10183
+ }
10184
+ function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10185
+ return scopes.some(
10186
+ (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
10123
10187
  );
10124
- const fieldBasedPayload = omitHiddenFields(
10125
- annotationFields,
10126
- annotation,
10127
- {}
10128
- // Intentionally empty. Allow generating fields with custom conditionals.
10188
+ }
10189
+ function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
10190
+ const collectedLocations = [];
10191
+ const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
10192
+ let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
10193
+ while (current) {
10194
+ collectedLocations.push(current);
10195
+ if (!current.parentId) {
10196
+ break;
10197
+ }
10198
+ const parentId = current.parentId;
10199
+ current = administrativeAreas.get(parentId);
10200
+ }
10201
+ return collectedLocations;
10202
+ }
10203
+ function getLocationHierarchy(selectedId, context) {
10204
+ const { administrativeAreas, locations } = context;
10205
+ const loc = locations.get(selectedId);
10206
+ if (loc) {
10207
+ if (loc.administrativeAreaId) {
10208
+ const hierarchy2 = getAdministrativeAreaHierarchy(
10209
+ loc.administrativeAreaId,
10210
+ administrativeAreas
10211
+ );
10212
+ return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10213
+ }
10214
+ return [loc.id];
10215
+ }
10216
+ const hierarchy = getAdministrativeAreaHierarchy(
10217
+ selectedId,
10218
+ administrativeAreas
10129
10219
  );
10220
+ return hierarchy.reverse().map((area) => area.id);
10221
+ }
10222
+ function resolvePath(locationId, anchor, context) {
10223
+ return getLocationHierarchy(locationId, context).flatMap((id) => {
10224
+ const node = context.locations.get(id) ?? context.administrativeAreas.get(id);
10225
+ if (!node) {
10226
+ return [];
10227
+ }
10228
+ const { name, status: status2 } = resolveVersion(node.versions, anchor);
10229
+ return [{ id, name, status: status2 }];
10230
+ });
10231
+ }
10232
+
10233
+ // ../commons/src/events/mocks.test.utils.ts
10234
+ function withVersionFields(entity) {
10130
10235
  return {
10131
- ...fieldBasedPayload,
10132
- ...visiblePageVerificationMap
10236
+ ...entity,
10237
+ status: "active",
10238
+ versions: [
10239
+ {
10240
+ versionId: entity.id,
10241
+ effectiveFrom: "0001-01-01",
10242
+ name: entity.name,
10243
+ externalId: entity.externalId ?? null,
10244
+ status: "active"
10245
+ }
10246
+ ]
10133
10247
  };
10134
10248
  }
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
- })
10381
- }
10382
- }
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
- };
10444
- }
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
- };
10456
- }
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
- };
10475
- }
10476
- case ActionType.DELETE:
10477
- default:
10478
- throw new Error(`Unsupported action type: ${action}`);
10479
- }
10480
- }
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];
10490
- }
10491
- function generateEventDocument({
10492
- configuration,
10493
- actions,
10494
- rng = () => 0.1,
10495
- defaults = {}
10496
- }) {
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
- };
10532
- }
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
10543
- });
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
- }
10559
- function generateRandomApplicant(rng) {
10560
- const { firstname, surname } = generateRandomName(rng);
10561
- const randomDob = getRandomDate(rng, "1990-01-01", "2010-12-31");
10562
- 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;
10579
- };
10580
- }
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.eyJzY29wZSI6WyJyZWNvcmQuZGVjbGFyYXRpb24tc3VibWl0LWZvci1yZXZpZXciLCJzZWFyY2guYmlydGgiLCJzZWFyY2guZGVhdGgiLCJzZWFyY2gubWFycmlhZ2UiLCJ3b3JrcXVldWVbaWQ9YWxsLWV2ZW50c3xhc3NpZ25lZC10by15b3V8cmVjZW50fHJlcXVpcmVzLXVwZGF0ZXN8c2VudC1mb3ItcmV2aWV3XSIsInR5cGU9cmVjb3JkLnNlYXJjaCZldmVudD1iaXJ0aCxkZWF0aCx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwLGNoaWxkLW9uYm9hcmRpbmcsRk9PVEJBTExfQ0xVQl9NRU1CRVJTSElQI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GlZWckoxy23i9Cp0oyjF-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([
10619
- {
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;
10712
- }
10713
- if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
10714
- return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
10715
- }
10716
- return false;
10717
- }
10718
-
10719
- // ../commons/src/events/scopes.ts
10720
- var import_lodash6 = require("lodash");
10721
-
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"
10728
- ]);
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;
10855
- }
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;
10953
- }
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;
10977
- }
10978
- function canAccessOtherUserWithScopes({
10979
- scopes,
10980
- userToAccess,
10981
- user: user2
10982
- }) {
10983
- return scopes.some(
10984
- (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
10985
- );
10986
- }
10987
- function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10988
- return scopes.some(
10989
- (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
10990
- );
10991
- }
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;
11005
- }
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
11014
- );
11015
- return [...hierarchy2.reverse().map((area) => area.id), loc.id];
11016
- }
11017
- return [loc.id];
10249
+ var MOCK_ADMINISTRATIVE_AREAS_BASE = [
10250
+ {
10251
+ id: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10252
+ name: "Central",
10253
+ parentId: null,
10254
+ externalId: "ydyJb1RAy4U1"
10255
+ },
10256
+ {
10257
+ id: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10258
+ name: "Sulaka",
10259
+ parentId: null,
10260
+ externalId: "pQ8nGxWmZ2Q3"
10261
+ },
10262
+ {
10263
+ id: "7ef2b9c7-5e6d-49f6-ae05-656207d0fc64",
10264
+ name: "Pualula",
10265
+ parentId: null,
10266
+ externalId: "Aq91DweLmT8k"
10267
+ },
10268
+ {
10269
+ id: "6d1a59df-988c-4021-a846-ccbc021931a7",
10270
+ name: "Chuminga",
10271
+ parentId: null,
10272
+ externalId: "Rw0fYNh2Xk9a"
10273
+ },
10274
+ {
10275
+ id: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10276
+ name: "Ibombo",
10277
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10278
+ externalId: "k7DsP4vbN1Qe"
10279
+ },
10280
+ {
10281
+ id: "27160bbd-32d1-4625-812f-860226bfb92a",
10282
+ name: "Isango",
10283
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10284
+ externalId: "Gm3Z9eQpHw4L"
10285
+ },
10286
+ {
10287
+ id: "967032fd-3f81-478a-826c-30cb8fe121bd",
10288
+ name: "Isamba",
10289
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10290
+ externalId: "sT0xVu1KqJ7r"
10291
+ },
10292
+ {
10293
+ id: "89a33893-b17d-481d-a26d-6461e7ac1651",
10294
+ name: "Itambo",
10295
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10296
+ externalId: "Nq6Bv2HpL9Te"
10297
+ },
10298
+ {
10299
+ id: "d42ab2fe-e7ed-470e-8b31-4fb27f9b8250",
10300
+ name: "Ezhi",
10301
+ parentId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10302
+ externalId: "xK8cQ0ZRy5Wd"
10303
+ },
10304
+ {
10305
+ id: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
10306
+ name: "Ilanga",
10307
+ parentId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10308
+ externalId: "Cq4Jm1XvN8Ls"
10309
+ },
10310
+ // Villages under Ibombo (62a0ccb4-880d-4f30-8882-f256007dfff9)
10311
+ {
10312
+ id: "1d4e5f6a-7b8c-4912-8efa-345678901234",
10313
+ name: "Klow",
10314
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10315
+ externalId: "IkYcYBUcyY2"
10316
+ },
10317
+ {
10318
+ id: "2e5f6a7b-8c9d-4a23-8fab-456789012345",
10319
+ name: "Mbondo",
10320
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10321
+ externalId: "Qhvv5hvo3mY"
10322
+ },
10323
+ {
10324
+ id: "3f6a7b8c-9d0e-4b34-8abc-567890123456",
10325
+ name: "Ndara",
10326
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10327
+ externalId: "crXh068O9TR"
10328
+ },
10329
+ {
10330
+ id: "4a7b8c9d-0e1f-4c45-abcd-678901234567",
10331
+ name: "Olani",
10332
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10333
+ externalId: "r00It8Tvvp7"
10334
+ },
10335
+ {
10336
+ id: "5b8c9d0e-1f2a-4d56-bcde-789012345678",
10337
+ name: "Pemba",
10338
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10339
+ externalId: "ZnUWsbONIaH"
10340
+ },
10341
+ {
10342
+ id: "6c9d0e1f-2a3b-4e67-8def-890123456789",
10343
+ name: "Quanza",
10344
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10345
+ externalId: "fDZycvQTa7l"
10346
+ },
10347
+ {
10348
+ id: "7d0e1f2a-3b4c-4f78-8efa-901234567890",
10349
+ name: "Rivka",
10350
+ parentId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10351
+ externalId: "KqswxCGTELa"
10352
+ },
10353
+ // Villages under Isamba (967032fd-3f81-478a-826c-30cb8fe121bd)
10354
+ {
10355
+ id: "8e1f2a3b-4c5d-4089-8fab-012345678901",
10356
+ name: "Mbula",
10357
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10358
+ externalId: "osEbKjRc9Kg"
10359
+ },
10360
+ {
10361
+ id: "9f2a3b4c-5d6e-4190-8abf-123456789012",
10362
+ name: "Ndoki",
10363
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10364
+ externalId: "aq4daBUAGr3"
10365
+ },
10366
+ {
10367
+ id: "0a3b4c5d-6e7f-4201-abcd-234567890123",
10368
+ name: "Tsanga",
10369
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10370
+ externalId: "cqis6Y8trbJ"
10371
+ },
10372
+ {
10373
+ id: "1b4c5d6e-7f8a-4312-bcde-345678901234",
10374
+ name: "Waziri",
10375
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10376
+ externalId: "LMijHPyyx6d"
10377
+ },
10378
+ {
10379
+ id: "2c5d6e7f-8a9b-4423-8def-456789012345",
10380
+ name: "Zimbi",
10381
+ parentId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10382
+ externalId: "pcQYbPuKGZ7"
10383
+ },
10384
+ // Villages under Itambo (89a33893-b17d-481d-a26d-6461e7ac1651)
10385
+ {
10386
+ id: "3d6e7f8a-9b0c-4534-8efa-567890123456",
10387
+ name: "Felani",
10388
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10389
+ externalId: "gSqpoCGdMXp"
10390
+ },
10391
+ {
10392
+ id: "4e7f8a9b-0c1d-4645-8fab-678901234567",
10393
+ name: "Goroma",
10394
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10395
+ externalId: "KvAAIaNqVrp"
10396
+ },
10397
+ {
10398
+ id: "5f8a9b0c-1d2e-4756-8abc-789012345678",
10399
+ name: "Halifu",
10400
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10401
+ externalId: "qe4UnEVt1hv"
10402
+ },
10403
+ {
10404
+ id: "6a9b0c1d-2e3f-4867-abcd-890123456789",
10405
+ name: "Jabari",
10406
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10407
+ externalId: "yHH9Nz4rLOt"
10408
+ },
10409
+ {
10410
+ id: "7b0c1d2e-3f4a-4978-bcde-901234567890",
10411
+ name: "Kifani",
10412
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10413
+ externalId: "eSWmXIGeu1I"
10414
+ },
10415
+ {
10416
+ id: "8c1d2e3f-4a5b-4089-8def-012345678901",
10417
+ name: "Lumela",
10418
+ parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
10419
+ externalId: "bh0b3aI1uP3"
11018
10420
  }
11019
- const hierarchy = getAdministrativeAreaHierarchy(
11020
- selectedId,
11021
- administrativeAreas
11022
- );
11023
- return hierarchy.reverse().map((area) => area.id);
11024
- }
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 [];
11030
- }
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;
10421
+ ];
10422
+ var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS = MOCK_ADMINISTRATIVE_AREAS_BASE.map(withVersionFields);
10423
+ var MOCK_LOCATIONS_BASE = [
10424
+ {
10425
+ id: "6f6186ce-cd5f-4a5f-810a-2d99e7c4ba12",
10426
+ name: "Central Provincial Office",
10427
+ locationType: "CRVS_OFFICE",
10428
+ administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
10429
+ externalId: "Xr3Df8WpK6Ys"
10430
+ },
10431
+ {
10432
+ id: "b1c2d3e4-f5a6-7890-bcde-f12345678901",
10433
+ name: "Central Health Post",
10434
+ locationType: "HEALTH_FACILITY",
10435
+ administrativeAreaId: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c"
10436
+ },
10437
+ {
10438
+ id: "028d2c85-ca31-426d-b5d1-2cef545a4902",
10439
+ name: "Ibombo District Office",
10440
+ locationType: "CRVS_OFFICE",
10441
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10442
+ externalId: "Sm4Nw7GrD2Vy"
10443
+ },
10444
+ {
10445
+ id: "62a0ccb4-4f30-4f30-8882-f256007dff9f",
10446
+ name: "Isamba District Office",
10447
+ locationType: "CRVS_OFFICE",
10448
+ administrativeAreaId: "967032fd-3f81-478a-826c-30cb8fe121bd",
10449
+ externalId: "Vg1Bq5XeH9Lt"
10450
+ },
10451
+ {
10452
+ id: "954c93e1-13f7-4435-bb82-35e0e215e07d",
10453
+ name: "Isango District Office",
10454
+ locationType: "CRVS_OFFICE",
10455
+ administrativeAreaId: "27160bbd-32d1-4625-812f-860226bfb92a",
10456
+ externalId: "Je7Lm2XqN9Vz"
10457
+ },
10458
+ {
10459
+ id: "2884f5b9-17b4-49ce-bf4d-f538228935df",
10460
+ name: "Sulaka Provincial Office",
10461
+ locationType: "CRVS_OFFICE",
10462
+ administrativeAreaId: "c599b691-fd2d-45e1-abf4-d185de727fb5",
10463
+ externalId: "Ht2Wp9KcX5Qv"
10464
+ },
10465
+ {
10466
+ id: "030358c6-54af-44be-821b-8e4af963a49c",
10467
+ name: "Ilanga District Office",
10468
+ locationType: "CRVS_OFFICE",
10469
+ administrativeAreaId: "8fbd09d2-212b-47f4-beb3-5e1694931d9f",
10470
+ externalId: "Yp6Ds1WqN3Xz"
10471
+ },
10472
+ {
10473
+ id: "423d000f-101b-47c0-8b86-21a908067cee",
10474
+ name: "Chamakubi Health Post",
10475
+ locationType: "HEALTH_FACILITY",
10476
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10477
+ externalId: "M1nFr8LbC2Qy"
10478
+ },
10479
+ {
10480
+ id: "4d3279be-d026-420c-88f7-f0a4ae986973",
10481
+ name: "Ibombo Rural Health Centre",
10482
+ locationType: "HEALTH_FACILITY",
10483
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10484
+ externalId: "bT7pV6YrW0Xc"
10485
+ },
10486
+ {
10487
+ id: "190902f4-1d77-476a-8947-41145af1db7d",
10488
+ name: "Chikobo Rural Health Centre",
10489
+ locationType: "HEALTH_FACILITY",
10490
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10491
+ externalId: "zE4qPn2SgJ5d"
10492
+ },
10493
+ {
10494
+ id: "f5ecbd9b-a01e-4a65-910e-70e86ab41b71",
10495
+ name: "Chilochabalenje Health Post",
10496
+ locationType: "HEALTH_FACILITY",
10497
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10498
+ externalId: "H8vDs1MqR4Uf"
10499
+ },
10500
+ {
10501
+ id: "dbfc178f-7295-4b90-b28d-111c95b03127",
10502
+ name: "Chipeso Rural Health Centre",
10503
+ locationType: "HEALTH_FACILITY",
10504
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10505
+ externalId: "Qw3uZ9KfX6Lm"
10506
+ },
10507
+ {
10508
+ id: "09862bfe-c7ac-46cd-987b-668681533c80",
10509
+ name: "Chisamba Rural Health Centre",
10510
+ locationType: "HEALTH_FACILITY",
10511
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10512
+ externalId: "Yr0pCg8LdM2s"
10513
+ },
10514
+ {
10515
+ id: "834ce389-e95b-4fb0-96a0-33e9ab323059",
10516
+ name: "Chitanda Rural Health Centre",
10517
+ locationType: "HEALTH_FACILITY",
10518
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10519
+ externalId: "tS9gJ4PwB1Qx"
10520
+ },
10521
+ {
10522
+ id: "0431c433-6062-4a4c-aee9-25271aec61ee",
10523
+ name: "Golden Valley Rural Health Centre",
10524
+ locationType: "HEALTH_FACILITY",
10525
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10526
+ externalId: "Ld7Qm3XsA8Vr"
10527
+ },
10528
+ {
10529
+ id: "bc84d0b6-7ba7-480d-a339-5d9920d90eb2",
10530
+ name: "Ipongo Rural Health Centre",
10531
+ locationType: "HEALTH_FACILITY",
10532
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10533
+ externalId: "kF2sW9DmH0Bt"
10534
+ },
10535
+ {
10536
+ id: "4cf1f53b-b730-41d2-8649-dff7eeed970d",
10537
+ name: "Itumbwe Health Post",
10538
+ locationType: "HEALTH_FACILITY",
10539
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10540
+ externalId: "Ue5Xb3VaC7Pq"
10541
+ },
10542
+ {
10543
+ id: "4b3676cb-9355-4942-9eb9-2ce46acaf0e0",
10544
+ name: "Kabangalala Rural Health Centre",
10545
+ locationType: "HEALTH_FACILITY",
10546
+ administrativeAreaId: "62a0ccb4-880d-4f30-8882-f256007dfff9",
10547
+ externalId: "Pz8Kc1TqH6Jn"
10548
+ },
10549
+ // Village offices
10550
+ {
10551
+ id: "1f4a5b6c-7d8e-4312-8abc-345678901234",
10552
+ name: "Klow Village Office",
10553
+ locationType: "CRVS_OFFICE",
10554
+ administrativeAreaId: "1d4e5f6a-7b8c-4912-8efa-345678901234",
10555
+ externalId: "PmAyxAJkxiJ"
11074
10556
  }
11075
- return eventState.assignedTo == userId ? AssignmentStatus.ASSIGNED_TO_SELF : AssignmentStatus.ASSIGNED_TO_OTHERS;
10557
+ ];
10558
+ var V2_DEFAULT_MOCK_LOCATIONS = MOCK_LOCATIONS_BASE.map(withVersionFields);
10559
+ var V2_DEFAULT_MOCK_LOCATIONS_MAP = new Map(
10560
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, l])
10561
+ );
10562
+ var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP = new Map(
10563
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [a.id, a])
10564
+ );
10565
+ var V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP = new Map(
10566
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, toClientLocation(l)])
10567
+ );
10568
+ var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
10569
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [
10570
+ a.id,
10571
+ toClientAdministrativeArea(a)
10572
+ ])
10573
+ );
10574
+
10575
+ // ../commons/src/events/test.utils.ts
10576
+ var TEST_SYSTEM_IANA_TIMEZONE = "Asia/Dhaka";
10577
+ var TestUserRole = z44.enum([
10578
+ "FIELD_AGENT",
10579
+ "LOCAL_REGISTRAR",
10580
+ "LOCAL_SYSTEM_ADMIN",
10581
+ "NATIONAL_REGISTRAR",
10582
+ "REGISTRATION_AGENT",
10583
+ "NATIONAL_SYSTEM_ADMIN",
10584
+ "SOCIAL_WORKER",
10585
+ "COMMUNITY_LEADER",
10586
+ "PROVINCIAL_REGISTRAR"
10587
+ ]);
10588
+ function pickRandom(rng, items) {
10589
+ return items[Math.floor(rng() * items.length)];
11076
10590
  }
11077
- function isActionInScope({
11078
- scopes,
11079
- action,
11080
- event: event2,
11081
- currentUser
11082
- }) {
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
11106
- }
11107
- );
11108
- return canAccess;
10591
+ function generateRandomName(rng) {
10592
+ const firstnames = [
10593
+ "Danny",
10594
+ "John",
10595
+ "Jane",
10596
+ "Emily",
10597
+ "Michael",
10598
+ "Sarah",
10599
+ "Chris",
10600
+ "Jessica",
10601
+ "Sara",
10602
+ "Sarachella",
10603
+ "Sarandera",
10604
+ "Zara"
10605
+ ];
10606
+ const surnames = [
10607
+ "Doe",
10608
+ "Smith",
10609
+ "Johnson",
10610
+ "Brown",
10611
+ "Williams",
10612
+ "Jones",
10613
+ "Garcia",
10614
+ "Miller",
10615
+ "Saranen",
10616
+ "Sarajanen",
10617
+ "Sarthua",
10618
+ "Tsarakovski",
10619
+ "Salamander",
10620
+ "Zarathustra"
10621
+ ];
10622
+ return {
10623
+ firstname: pickRandom(rng, firstnames),
10624
+ surname: pickRandom(rng, surnames)
10625
+ };
11109
10626
  }
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;
10627
+ function generateUuid(rng = () => 0.1) {
10628
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
10629
+ const r = Math.floor(rng() * 16);
10630
+ const v = c === "x" ? r : r & 3 | 8;
10631
+ return v.toString(16);
11126
10632
  });
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
10633
  }
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;
10634
+ function generateTrackingId(rng) {
10635
+ const uuid2 = generateUuid(rng).replace(/-/g, "");
10636
+ const trackingId = uuid2.slice(0, 6).toUpperCase();
10637
+ return trackingId;
11157
10638
  }
11158
- function deserializeExpression(expression, user2) {
11159
- if (expression.type === "exact") {
11160
- const term = userDeserializer(expression.term, user2);
11161
- if (!term) {
11162
- return void 0;
11163
- }
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;
11173
- }
11174
- return {
11175
- ...expression,
11176
- location
11177
- };
11178
- }
11179
- return void 0;
10639
+ function generateRegistrationNumber(rng) {
10640
+ const uuid2 = generateUuid(rng).replace(/-/g, "");
10641
+ const registrationNumber = uuid2.slice(0, 12).toUpperCase();
10642
+ return registrationNumber;
11180
10643
  }
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;
11196
- 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
11215
- };
10644
+ function generateRandomSignature(rng) {
10645
+ return `${generateUuid(rng)}.png`;
11216
10646
  }
11217
- function deserializeQuery(query, user2) {
10647
+ function locationVersion(overrides = {}, rng) {
11218
10648
  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
- )
10649
+ versionId: generateUuid(rng),
10650
+ effectiveFrom: "0001-01-01",
10651
+ name: "Location name",
10652
+ externalId: null,
10653
+ status: "active",
10654
+ ...overrides
11225
10655
  };
11226
10656
  }
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);
11286
- }
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;
10657
+ function mapFieldTypeToMockValue(field3, i, rng, administrativeHierarchy) {
10658
+ const leafLevelAdministrativeAreas = administrativeHierarchy?.administrativeAreas.filter(
10659
+ (aa) => administrativeHierarchy?.administrativeAreas.every(
10660
+ (other) => other.parentId !== aa.id
10661
+ )
10662
+ );
10663
+ switch (field3.type) {
10664
+ case FieldType.FIELD_GROUP: {
10665
+ const nestedValue = field3.fields.reduce(
10666
+ (acc, subfield, index) => ({
10667
+ ...acc,
10668
+ [subfield.id]: mapFieldTypeToMockValue(
10669
+ subfield,
10670
+ i * 1e3 + index,
10671
+ rng
10672
+ )
10673
+ }),
10674
+ {}
10675
+ );
10676
+ return nestedValue;
10677
+ }
10678
+ case FieldType.DIVIDER:
10679
+ case FieldType.TEXT:
10680
+ case FieldType.TEXTAREA:
10681
+ case FieldType.BULLET_LIST:
10682
+ case FieldType.PAGE_HEADER:
10683
+ case FieldType.LOCATION:
10684
+ case FieldType.SELECT:
10685
+ case FieldType.SELECT_DATE_RANGE:
10686
+ case FieldType.COUNTRY:
10687
+ case FieldType.RADIO_GROUP:
10688
+ case FieldType.PARAGRAPH:
10689
+ case FieldType.HEADING:
10690
+ case FieldType.IMAGE_VIEW:
10691
+ case FieldType.ADMINISTRATIVE_AREA:
10692
+ case FieldType.PHONE:
10693
+ case FieldType.QUERY_PARAM_READER:
10694
+ case FieldType.ID:
10695
+ case FieldType.LINK_BUTTON:
10696
+ case FieldType.LOADER:
10697
+ case FieldType.ALPHA_HIDDEN:
10698
+ return `${field3.id}-${field3.type}-${i}`;
10699
+ case FieldType.VERIFICATION_STATUS:
10700
+ return "verified";
10701
+ case FieldType.FACILITY:
10702
+ case FieldType.OFFICE:
10703
+ return administrativeHierarchy?.locations ? pickRandom(rng, administrativeHierarchy.locations)?.id : "a45b982a-5c7b-4bd9-8fd8-a42d0994054c";
10704
+ case FieldType.NAME:
10705
+ return generateRandomName(rng);
10706
+ case FieldType.NUMBER:
10707
+ return 19;
10708
+ case FieldType.NUMBER_WITH_UNIT:
10709
+ return {
10710
+ numericValue: 42,
10711
+ unit: "Hours"
10712
+ };
10713
+ case FieldType.BUTTON:
10714
+ return 1;
10715
+ case FieldType.EMAIL:
10716
+ return "test@opencrvs.org";
10717
+ case FieldType.ADDRESS:
10718
+ return {
10719
+ country: "FAR",
10720
+ addressType: AddressType.DOMESTIC,
10721
+ administrativeArea: leafLevelAdministrativeAreas ? pickRandom(rng, leafLevelAdministrativeAreas)?.id : "27160bbd-32d1-4625-812f-860226bfb92a",
10722
+ streetLevelDetails: {
10723
+ town: "Example Town",
10724
+ residentialArea: "Example Residential Area",
10725
+ street: "Example Street",
10726
+ number: "55",
10727
+ zipCode: "123456",
10728
+ state: "Example State",
10729
+ district2: "Example District 2"
10730
+ }
10731
+ };
10732
+ case FieldType.DATE:
10733
+ return "2021-01-01";
10734
+ case FieldType.AGE:
10735
+ return {
10736
+ age: 19,
10737
+ asOfDateRef: "applicant.dob"
10738
+ };
10739
+ case FieldType.TIME:
10740
+ return "09:33";
10741
+ case FieldType.ALPHA_PRINT_BUTTON:
10742
+ return void 0;
10743
+ case FieldType.DATE_RANGE:
10744
+ return {
10745
+ start: PlainDate.parse("2021-01-01"),
10746
+ end: PlainDate.parse("2021-01-31")
10747
+ };
10748
+ case FieldType.CHECKBOX:
10749
+ return true;
10750
+ case FieldType.SIGNATURE:
10751
+ case FieldType.FILE:
10752
+ return {
10753
+ path: "4f095fc4-4312-4de2-aa38-86dcc0f71044.png",
10754
+ originalFilename: "abcd.png",
10755
+ type: "image/png"
10756
+ };
10757
+ case FieldType.SEARCH:
10758
+ case FieldType.AUTOCOMPLETE:
10759
+ case FieldType.HTTP:
10760
+ return {
10761
+ error: null,
10762
+ data: { nid: "1234567890" },
10763
+ loading: false
10764
+ };
10765
+ case FieldType.FILE_WITH_OPTIONS:
10766
+ case FieldType.DATA:
10767
+ case FieldType._EXPERIMENTAL_CUSTOM:
10768
+ return void 0;
10769
+ case FieldType.QR_READER:
10770
+ return /* @__PURE__ */ Object.create(null);
10771
+ case FieldType.ID_READER:
10772
+ return /* @__PURE__ */ Object.create(null);
10773
+ case FieldType.USER_ROLE:
10774
+ return TestUserRole.enum.FIELD_AGENT;
11300
10775
  }
11301
- return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
11302
10776
  }
11303
- function getAvailableActionsForEvent(event2) {
11304
- return filterActionsByFlags(
11305
- getAvailableActionsWithoutFlagFilters(event2.status, event2.flags),
11306
- event2.flags
10777
+ function fieldConfigsToActionPayload(fields, rng, administrativeHierarchy) {
10778
+ return fields.reduce(
10779
+ (acc, field3, i) => ({
10780
+ ...acc,
10781
+ [field3.id]: mapFieldTypeToMockValue(
10782
+ field3,
10783
+ i,
10784
+ rng,
10785
+ administrativeHierarchy
10786
+ )
10787
+ }),
10788
+ {}
11307
10789
  );
11308
10790
  }
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;
10791
+ function generateActionDeclarationInput(configuration, action, rng, overrides, administrativeHierarchy) {
10792
+ const parsed = DeclarationUpdateActions.safeParse(action);
10793
+ if ((0, import_lodash5.isEmpty)(overrides) && typeof overrides === "object") {
10794
+ return {};
10795
+ }
10796
+ if (parsed.success) {
10797
+ const fields = getDeclarationFields(configuration);
10798
+ const declarationConfig = getDeclaration(configuration);
10799
+ const declaration = fieldConfigsToActionPayload(
10800
+ fields,
10801
+ rng,
10802
+ administrativeHierarchy
10803
+ );
10804
+ return omitHiddenPaginatedFields(
10805
+ declarationConfig,
10806
+ {
10807
+ ...declaration,
10808
+ ...overrides
10809
+ },
10810
+ {},
10811
+ // Intentionally empty. Allow generating fields with custom conditionals.
10812
+ true
10813
+ );
10814
+ }
10815
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
10816
+ return {};
10817
+ }
10818
+ function generateActionDuplicateDeclarationInput(...args) {
10819
+ const [configuration, action, rng, overrides] = args;
10820
+ return generateActionDeclarationInput(configuration, action, rng, {
10821
+ ...overrides,
10822
+ "applicant.dobUnknown": false
11333
10823
  });
11334
- return (0, import_lodash7.uniq)(filepaths);
11335
10824
  }
11336
-
11337
- // ../commons/src/events/mocks.test.utils.ts
11338
- function withVersionFields(entity) {
10825
+ function generateActionAnnotationInput(configuration, action, rng) {
10826
+ const actionConfig = configuration.actions.find(
10827
+ (ac) => ac.type === action
10828
+ );
10829
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
10830
+ const annotation = fieldConfigsToActionPayload(annotationFields, rng);
10831
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
10832
+ findRecordActionPages(configuration, action),
10833
+ annotation,
10834
+ {}
10835
+ );
10836
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
10837
+ (acc, pageId) => ({
10838
+ ...acc,
10839
+ [pageId]: true
10840
+ }),
10841
+ {}
10842
+ );
10843
+ const fieldBasedPayload = omitHiddenFields(
10844
+ annotationFields,
10845
+ annotation,
10846
+ {}
10847
+ // Intentionally empty. Allow generating fields with custom conditionals.
10848
+ );
11339
10849
  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"
10850
+ ...fieldBasedPayload,
10851
+ ...visiblePageVerificationMap
10852
+ };
10853
+ }
10854
+ function eventPayloadGenerator(rng, configuration = tennisClubMembershipEvent) {
10855
+ return {
10856
+ create: (input = {}) => ({
10857
+ transactionId: input.transactionId ?? getUUID(),
10858
+ type: input.type ?? configuration.id
10859
+ }),
10860
+ patch: (id, input = {}) => ({
10861
+ transactionId: input.transactionId ?? getUUID(),
10862
+ type: input.type ?? configuration.id,
10863
+ id
10864
+ }),
10865
+ draft: ({
10866
+ eventId,
10867
+ actionType,
10868
+ annotation,
10869
+ omitFields = []
10870
+ }, input = {}) => {
10871
+ const base = {
10872
+ id: getUUID(),
10873
+ eventId,
10874
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10875
+ transactionId: getUUID(),
10876
+ action: {
10877
+ transactionId: getUUID(),
10878
+ type: actionType,
10879
+ status: ActionStatus.Accepted,
10880
+ declaration: {
10881
+ "applicant.name": {
10882
+ firstname: "Max",
10883
+ surname: "McLaren"
10884
+ },
10885
+ "applicant.dob": "2020-01-02",
10886
+ "applicant.image": {
10887
+ path: "e56d1dd3-2cd4-452a-b54e-bf3e2d830605.png",
10888
+ originalFilename: "Screenshot.png",
10889
+ type: "image/png"
10890
+ }
10891
+ },
10892
+ annotation: {
10893
+ "correction.requester.relationship": "ANOTHER_AGENT",
10894
+ "correction.request.reason": "Child's name was incorrect",
10895
+ "identity-check": true,
10896
+ ...annotation
10897
+ },
10898
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
10899
+ createdBy: "@todo",
10900
+ createdByUserType: TokenUserType.enum.user,
10901
+ createdByRole: "@todo"
10902
+ }
10903
+ };
10904
+ base.action.declaration = (0, import_lodash5.omit)(base.action.declaration, omitFields);
10905
+ return (0, import_lodash5.merge)(base, input);
10906
+ },
10907
+ actions: {
10908
+ declare: (eventId, input = {}) => ({
10909
+ type: ActionType.DECLARE,
10910
+ transactionId: input.transactionId ?? getUUID(),
10911
+ declaration: input.declaration ?? generateActionDeclarationInput(
10912
+ configuration,
10913
+ ActionType.DECLARE,
10914
+ rng
10915
+ ),
10916
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.DECLARE, rng),
10917
+ eventId,
10918
+ ...input
10919
+ }),
10920
+ /**
10921
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
10922
+ */
10923
+ notify: (eventId, input = {}) => {
10924
+ let declaration = input.declaration;
10925
+ if (!declaration) {
10926
+ const partialDeclaration = (0, import_lodash5.omitBy)(
10927
+ generateActionDeclarationInput(
10928
+ configuration,
10929
+ ActionType.NOTIFY,
10930
+ rng
10931
+ ),
10932
+ import_lodash5.isString
10933
+ );
10934
+ declaration = partialDeclaration;
10935
+ }
10936
+ return {
10937
+ type: ActionType.NOTIFY,
10938
+ transactionId: input.transactionId ?? getUUID(),
10939
+ declaration,
10940
+ eventId,
10941
+ keepAssignment: input.keepAssignment
10942
+ };
10943
+ },
10944
+ edit: (eventId, input = {}) => ({
10945
+ type: ActionType.EDIT,
10946
+ transactionId: input.transactionId ?? getUUID(),
10947
+ declaration: input.declaration ?? generateActionDeclarationInput(configuration, ActionType.EDIT, rng),
10948
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.EDIT, rng),
10949
+ eventId,
10950
+ ...input
10951
+ }),
10952
+ assign: (eventId, input = {}) => ({
10953
+ type: ActionType.ASSIGN,
10954
+ transactionId: input.transactionId ?? getUUID(),
10955
+ declaration: {},
10956
+ assignedTo: input.assignedTo ?? getUUID(),
10957
+ eventId
10958
+ }),
10959
+ unassign: (eventId, input = {}) => ({
10960
+ type: ActionType.UNASSIGN,
10961
+ transactionId: input.transactionId ?? getUUID(),
10962
+ declaration: {},
10963
+ assignedTo: null,
10964
+ eventId
10965
+ }),
10966
+ archive: (eventId, input = {}) => ({
10967
+ type: ActionType.ARCHIVE,
10968
+ transactionId: input.transactionId ?? getUUID(),
10969
+ declaration: {},
10970
+ annotation: {},
10971
+ eventId,
10972
+ ...input
10973
+ }),
10974
+ unarchive: (eventId, input = {}) => ({
10975
+ type: ActionType.UNARCHIVE,
10976
+ transactionId: input.transactionId ?? getUUID(),
10977
+ declaration: {},
10978
+ annotation: {},
10979
+ eventId,
10980
+ ...input
10981
+ }),
10982
+ reject: (eventId, input = {}) => ({
10983
+ type: ActionType.REJECT,
10984
+ transactionId: input.transactionId ?? getUUID(),
10985
+ declaration: {},
10986
+ annotation: input.annotation ?? generateActionAnnotationInput(configuration, ActionType.REJECT, rng),
10987
+ eventId,
10988
+ content: { reason: `${ActionType.REJECT}` },
10989
+ ...input
10990
+ }),
10991
+ register: (eventId, input = {}) => ({
10992
+ type: ActionType.REGISTER,
10993
+ transactionId: input.transactionId ?? getUUID(),
10994
+ declaration: input.declaration ?? generateActionDeclarationInput(
10995
+ configuration,
10996
+ ActionType.REGISTER,
10997
+ rng
10998
+ ),
10999
+ annotation: input.annotation ?? generateActionAnnotationInput(
11000
+ configuration,
11001
+ ActionType.REGISTER,
11002
+ rng
11003
+ ),
11004
+ eventId,
11005
+ ...input
11006
+ }),
11007
+ printCertificate: (eventId, input = {}) => ({
11008
+ type: ActionType.PRINT_CERTIFICATE,
11009
+ transactionId: input.transactionId ?? getUUID(),
11010
+ declaration: {},
11011
+ annotation: input.annotation ?? generateActionAnnotationInput(
11012
+ configuration,
11013
+ ActionType.PRINT_CERTIFICATE,
11014
+ rng
11015
+ ),
11016
+ eventId,
11017
+ ...input
11018
+ }),
11019
+ correction: {
11020
+ request: (eventId, input = {}) => ({
11021
+ type: ActionType.REQUEST_CORRECTION,
11022
+ transactionId: input.transactionId ?? getUUID(),
11023
+ declaration: input.declaration ?? (0, import_lodash5.omit)(
11024
+ generateActionDeclarationInput(
11025
+ configuration,
11026
+ ActionType.REQUEST_CORRECTION,
11027
+ rng
11028
+ ),
11029
+ ["applicant.email", "applicant.image"]
11030
+ ),
11031
+ annotation: input.annotation ?? generateActionAnnotationInput(
11032
+ configuration,
11033
+ ActionType.REQUEST_CORRECTION,
11034
+ rng
11035
+ ),
11036
+ eventId,
11037
+ keepAssignment: input.keepAssignment
11038
+ }),
11039
+ approve: (eventId, requestId, input = {}) => ({
11040
+ type: ActionType.APPROVE_CORRECTION,
11041
+ transactionId: input.transactionId ?? getUUID(),
11042
+ declaration: {},
11043
+ annotation: input.annotation ?? generateActionAnnotationInput(
11044
+ configuration,
11045
+ ActionType.APPROVE_CORRECTION,
11046
+ rng
11047
+ ),
11048
+ eventId,
11049
+ requestId,
11050
+ keepAssignment: input.keepAssignment
11051
+ }),
11052
+ reject: (eventId, requestId, input) => ({
11053
+ type: ActionType.REJECT_CORRECTION,
11054
+ transactionId: input.transactionId ?? getUUID(),
11055
+ declaration: {},
11056
+ annotation: input.annotation ?? generateActionAnnotationInput(
11057
+ configuration,
11058
+ ActionType.REJECT_CORRECTION,
11059
+ rng
11060
+ ),
11061
+ eventId,
11062
+ requestId,
11063
+ keepAssignment: input.keepAssignment,
11064
+ content: input.content ?? { reason: "" }
11065
+ })
11066
+ },
11067
+ duplicate: {
11068
+ markAsDuplicate: (eventId, input = {}) => ({
11069
+ type: ActionType.MARK_AS_DUPLICATE,
11070
+ transactionId: input.transactionId ?? getUUID(),
11071
+ declaration: input.declaration ?? generateActionDeclarationInput(
11072
+ tennisClubMembershipEvent,
11073
+ ActionType.REGISTER,
11074
+ rng
11075
+ ),
11076
+ annotation: input.annotation ?? generateActionAnnotationInput(
11077
+ tennisClubMembershipEvent,
11078
+ ActionType.REGISTER,
11079
+ rng
11080
+ ),
11081
+ eventId,
11082
+ keepAssignment: input.keepAssignment
11083
+ }),
11084
+ markNotDuplicate: (eventId, input = {}) => ({
11085
+ type: ActionType.MARK_AS_NOT_DUPLICATE,
11086
+ transactionId: input.transactionId ?? getUUID(),
11087
+ declaration: input.declaration ?? generateActionDeclarationInput(
11088
+ tennisClubMembershipEvent,
11089
+ ActionType.REGISTER,
11090
+ rng
11091
+ ),
11092
+ annotation: input.annotation ?? generateActionAnnotationInput(
11093
+ tennisClubMembershipEvent,
11094
+ ActionType.REGISTER,
11095
+ rng
11096
+ ),
11097
+ eventId,
11098
+ keepAssignment: input.keepAssignment
11099
+ })
11349
11100
  }
11350
- ]
11101
+ }
11351
11102
  };
11352
11103
  }
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
- },
11519
- {
11520
- id: "8c1d2e3f-4a5b-4089-8def-012345678901",
11521
- name: "Lumela",
11522
- parentId: "89a33893-b17d-481d-a26d-6461e7ac1651",
11523
- externalId: "bh0b3aI1uP3"
11104
+ function generateActionDocument({
11105
+ configuration,
11106
+ action,
11107
+ rng = () => 0.1,
11108
+ defaults,
11109
+ declarationOverrides
11110
+ }) {
11111
+ const actionBase = {
11112
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11113
+ // @TODO: This should be fixed in the future.
11114
+ createdAt: new Date(Date.now() - 500).toISOString(),
11115
+ createdBy: generateUuid(rng),
11116
+ createdByUserType: TokenUserType.enum.user,
11117
+ createdByRole: TestUserRole.enum.FIELD_AGENT,
11118
+ id: getUUID(),
11119
+ createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
11120
+ declaration: generateActionDeclarationInput(
11121
+ configuration,
11122
+ action,
11123
+ rng,
11124
+ declarationOverrides
11125
+ ),
11126
+ annotation: {},
11127
+ status: ActionStatus.Accepted,
11128
+ transactionId: getUUID(),
11129
+ ...defaults
11130
+ };
11131
+ switch (action) {
11132
+ case ActionType.READ:
11133
+ case ActionType.MARK_AS_NOT_DUPLICATE:
11134
+ case ActionType.DECLARE:
11135
+ case ActionType.UNASSIGN:
11136
+ case ActionType.CREATE:
11137
+ case ActionType.NOTIFY:
11138
+ case ActionType.REGISTER:
11139
+ case ActionType.REQUEST_CORRECTION:
11140
+ case ActionType.UNARCHIVE:
11141
+ return { ...actionBase, type: action };
11142
+ case ActionType.EDIT:
11143
+ return {
11144
+ ...actionBase,
11145
+ type: action,
11146
+ content: { comment: "Test comment" }
11147
+ };
11148
+ case ActionType.CUSTOM:
11149
+ return {
11150
+ ...actionBase,
11151
+ type: action,
11152
+ customActionType: "CUSTOM_ACTION_TYPE"
11153
+ };
11154
+ case ActionType.MARK_AS_DUPLICATE:
11155
+ return { ...actionBase, type: action, content: void 0 };
11156
+ case ActionType.ASSIGN: {
11157
+ const assignActionDefaults = defaults;
11158
+ return {
11159
+ ...actionBase,
11160
+ assignedTo: assignActionDefaults?.assignedTo ?? getUUID(),
11161
+ type: action
11162
+ };
11163
+ }
11164
+ case ActionType.ARCHIVE:
11165
+ return { ...actionBase, type: action, content: { reason: "Archive" } };
11166
+ case ActionType.REJECT:
11167
+ return { ...actionBase, type: action, content: { reason: "Reject" } };
11168
+ case ActionType.PRINT_CERTIFICATE: {
11169
+ const printActionDefaults = defaults;
11170
+ return {
11171
+ ...actionBase,
11172
+ type: action,
11173
+ content: printActionDefaults?.content
11174
+ };
11175
+ }
11176
+ case ActionType.APPROVE_CORRECTION:
11177
+ return { ...actionBase, requestId: getUUID(), type: action };
11178
+ case ActionType.REJECT_CORRECTION:
11179
+ return {
11180
+ ...actionBase,
11181
+ requestId: getUUID(),
11182
+ type: action,
11183
+ content: { reason: "Correction rejection" }
11184
+ };
11185
+ case ActionType.DUPLICATE_DETECTED: {
11186
+ const duplicateActionDefaults = defaults;
11187
+ return {
11188
+ ...actionBase,
11189
+ type: action,
11190
+ content: {
11191
+ duplicates: duplicateActionDefaults?.content?.duplicates ?? []
11192
+ }
11193
+ };
11194
+ }
11195
+ case ActionType.DELETE:
11196
+ default:
11197
+ throw new Error(`Unsupported action type: ${action}`);
11524
11198
  }
11525
- ];
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
11199
+ }
11200
+ function generateRandomDatetime(rng, start, end) {
11201
+ const range = end.getTime() - start.getTime();
11202
+ const offset = Math.floor(rng() * range);
11203
+ const randomDate = new Date(start.getTime() + offset);
11204
+ return randomDate.toISOString();
11205
+ }
11206
+ function getRandomDate(rng, start, end) {
11207
+ const datetime = generateRandomDatetime(rng, new Date(start), new Date(end));
11208
+ return datetime.split("T")[0];
11209
+ }
11210
+ function generateEventDocument({
11211
+ configuration,
11212
+ actions,
11213
+ rng = () => 0.1,
11214
+ defaults = {}
11215
+ }) {
11216
+ return {
11217
+ trackingId: generateTrackingId(rng),
11218
+ type: configuration.id,
11219
+ actions: actions.map(
11220
+ (action, i) => generateActionDocument({
11221
+ configuration,
11222
+ action: action.type,
11223
+ defaults: {
11224
+ createdBy: action.user?.id,
11225
+ createdAtLocation: action.user?.primaryOfficeId,
11226
+ assignedTo: action.user?.assignedTo,
11227
+ createdByRole: action.user?.role,
11228
+ createdAt: (0, import_date_fns4.addDays)(
11229
+ new Date(
11230
+ generateRandomDatetime(
11231
+ rng,
11232
+ new Date(2025, 0, 1),
11233
+ new Date(2025, 11, 31)
11234
+ )
11235
+ ),
11236
+ i
11237
+ ).toISOString()
11238
+ },
11239
+ declarationOverrides: action.declarationOverrides
11240
+ })
11241
+ ),
11242
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11243
+ // @TODO: This should be fixed in the future.
11244
+ createdAt: new Date(Date.now() - 1e3).toISOString(),
11245
+ id: getUUID(),
11246
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
11247
+ // @TODO: This should be fixed in the future.
11248
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
11249
+ ...defaults
11250
+ };
11251
+ }
11252
+ function generateEventDraftDocument({
11253
+ eventId,
11254
+ actionType,
11255
+ rng = () => 0.1,
11256
+ declaration = {}
11257
+ }) {
11258
+ const action = generateActionDocument({
11259
+ configuration: tennisClubMembershipEvent,
11260
+ action: actionType,
11261
+ rng
11262
+ });
11263
+ return {
11264
+ id: getUUID(),
11265
+ transactionId: getUUID(),
11266
+ action: {
11267
+ ...action,
11268
+ declaration: {
11269
+ ...action.declaration,
11270
+ ...declaration
11271
+ },
11272
+ annotation: action.annotation
11273
+ },
11274
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
11275
+ eventId
11276
+ };
11277
+ }
11278
+ function generateRandomApplicant(rng) {
11279
+ const { firstname, surname } = generateRandomName(rng);
11280
+ const randomDob = getRandomDate(rng, "1990-01-01", "2010-12-31");
11281
+ return {
11282
+ "recommender.none": true,
11283
+ "applicant.name": {
11284
+ firstname,
11285
+ surname
11286
+ },
11287
+ "applicant.dob": randomDob
11288
+ };
11289
+ }
11290
+ function createPrng(seed) {
11291
+ const MODULUS = 2 ** 32;
11292
+ const MULTIPLIER = 1664525;
11293
+ const INCREMENT = 1013904223;
11294
+ let state = seed >>> 0;
11295
+ return () => {
11296
+ state = (MULTIPLIER * state + INCREMENT) % MODULUS;
11297
+ return state / MODULUS;
11298
+ };
11299
+ }
11300
+ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
11301
+ const rng = createPrng(seed);
11302
+ const createdAt = generateRandomDatetime(
11303
+ rng,
11304
+ /* @__PURE__ */ new Date("2024-01-01"),
11305
+ /* @__PURE__ */ new Date("2024-12-31")
11306
+ );
11307
+ return {
11308
+ id: overrides.id ?? generateUuid(rng),
11309
+ type: overrides.type ?? TENNIS_CLUB_MEMBERSHIP,
11310
+ status: overrides.status ?? pickRandom(rng, EventStatus.options),
11311
+ createdAt: overrides.createdAt ?? createdAt,
11312
+ createdByUserType: overrides.createdByUserType ?? "user",
11313
+ createdBy: overrides.createdBy ?? generateUuid(rng),
11314
+ createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
11315
+ updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
11316
+ updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
11317
+ assignedTo: overrides.assignedTo ?? null,
11318
+ updatedBy: overrides.updatedBy ?? generateUuid(rng),
11319
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
11320
+ flags: overrides.flags ?? [],
11321
+ potentialDuplicates: [],
11322
+ legalStatuses: overrides.legalStatuses ?? {},
11323
+ declaration: overrides.declaration ?? generateRandomApplicant(rng),
11324
+ trackingId: overrides.trackingId ?? generateTrackingId(rng)
11325
+ };
11326
+ };
11327
+ var generateTranslationConfig2 = (message) => ({
11328
+ defaultMessage: message,
11329
+ description: "Description for ${message}",
11330
+ id: message.trim().replace(/\s+/g, "_").toLowerCase()
11331
+ });
11332
+ var BearerTokenByUserType = {
11333
+ fieldAgent: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJyZWNvcmQuZGVjbGFyYXRpb24tc3VibWl0LWZvci1yZXZpZXciLCJzZWFyY2guYmlydGgiLCJzZWFyY2guZGVhdGgiLCJzZWFyY2gubWFycmlhZ2UiLCJ3b3JrcXVldWVbaWQ9YWxsLWV2ZW50c3xhc3NpZ25lZC10by15b3V8cmVjZW50fHJlcXVpcmVzLXVwZGF0ZXN8c2VudC1mb3ItcmV2aWV3XSIsInR5cGU9cmVjb3JkLnNlYXJjaCZldmVudD1iaXJ0aCxkZWF0aCx0ZW5uaXMtY2x1Yi1tZW1iZXJzaGlwLGNoaWxkLW9uYm9hcmRpbmcsRk9PVEJBTExfQ0xVQl9NRU1CRVJTSElQIiwidHlwZT1yZWNvcmQuY3JlYXRlJmV2ZW50PWJpcnRoLGRlYXRoLHRlbm5pcy1jbHViLW1lbWJlcnNoaXAsY2hpbGQtb25ib2FyZGluZyIsInR5cGU9cmVjb3JkLnJlYWQmZXZlbnQ9YmlydGgsZGVhdGgsdGVubmlzLWNsdWItbWVtYmVyc2hpcCxjaGlsZC1vbmJvYXJkaW5nIiwicmVjb3JkLmRlY2xhcmVbZXZlbnQ9YmlydGh8ZG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NIQ_4AjKQse6PM_t_7qUbOAzdkfySDsSNFLwjsy0cX8xovPJFr2E1S20-NmA6moiMghi34proGzDBs8750Wk724hSTwuFrvj3cT1nekCgkVa41b7b5E88ys5d6A48fkracYUrn0DwPs3Fbm8d6Z2kMnNAELQ_xPbBAkN8-ySwxS1dhTKtAG3gXbbIOG2jpnVQaugZaaCSZTCFA26Tw5x9wYOtR_GCeGI1lU2zd8_zjxlJA8g5zs186sPkkyWRy_J_xP2KIKfK4vBQ4FpcCDeoUh6B5sT4Bq_38PwzsC2gshzl4Np9oh9bVWbZC5Z7SLqE4TJzXDOWaoKRt6wFEfZhJjG7MYnAD2PD0YzTWyPKFn4sqZI7-zNajHfUDC-yXyIiiohQNkI"
11336
+ };
11337
+ var generateWorkqueues = (slug = "all-events") => defineWorkqueues([
11654
11338
  {
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"
11339
+ slug,
11340
+ name: {
11341
+ id: "workqueues.inProgress.title",
11342
+ defaultMessage: slug.charAt(0).toUpperCase() + slug.slice(1).split("-").join(" "),
11343
+ description: "Title of in progress workqueue"
11344
+ },
11345
+ query: {
11346
+ type: "and",
11347
+ clauses: [{ eventType: tennisClubMembershipEvent.id }]
11348
+ },
11349
+ action: { type: ActionType.READ },
11350
+ icon: "Draft"
11351
+ }
11352
+ ]);
11353
+ var generateEventConfig = ({
11354
+ id,
11355
+ fields,
11356
+ placeOfEventId,
11357
+ dateOfEventId
11358
+ }) => {
11359
+ return defineConfig({
11360
+ id,
11361
+ label: generateTranslationConfig2(id),
11362
+ title: generateTranslationConfig2(`${id} Event`),
11363
+ summary: {
11364
+ fields: []
11365
+ },
11366
+ placeOfEvent: placeOfEventId ? { $$field: placeOfEventId } : void 0,
11367
+ dateOfEvent: dateOfEventId ? { $$field: dateOfEventId } : void 0,
11368
+ declaration: {
11369
+ label: generateTranslationConfig2(`${id} Declaration`),
11370
+ pages: [
11371
+ {
11372
+ id: "page1",
11373
+ title: generateTranslationConfig2("Page 1"),
11374
+ fields
11375
+ }
11376
+ ]
11377
+ },
11378
+ actions: [
11379
+ {
11380
+ type: ActionType.READ,
11381
+ label: generateTranslationConfig2("Read"),
11382
+ review: {
11383
+ title: generateTranslationConfig2("Review Read Action"),
11384
+ fields: []
11385
+ }
11386
+ },
11387
+ {
11388
+ type: ActionType.DECLARE,
11389
+ label: generateTranslationConfig2("Declare"),
11390
+ review: {
11391
+ title: generateTranslationConfig2("Review Declare Action"),
11392
+ fields: []
11393
+ }
11394
+ }
11395
+ ]
11396
+ });
11397
+ };
11398
+ function getLeafAdministrativeAreaIds(administrativeAreas) {
11399
+ const nonLeafAdministrativeAreaIds = /* @__PURE__ */ new Set();
11400
+ for (const [, location] of administrativeAreas) {
11401
+ if (location.parentId) {
11402
+ nonLeafAdministrativeAreaIds.add(location.parentId);
11403
+ }
11404
+ }
11405
+ const result = [];
11406
+ for (const [id] of administrativeAreas) {
11407
+ if (!nonLeafAdministrativeAreaIds.has(id)) {
11408
+ result.push({ id });
11409
+ }
11410
+ }
11411
+ return result;
11412
+ }
11413
+ function generateUserTokenPayload({
11414
+ role,
11415
+ scope
11416
+ }) {
11417
+ return {
11418
+ // @TODO: Validate which fields are necessary https://github.com/opencrvs/opencrvs-core/issues/13530
11419
+ sub: generateUuid(),
11420
+ algorithm: "RS256",
11421
+ exp: "1787221786",
11422
+ role: role ?? TestUserRole.enum.FIELD_AGENT,
11423
+ scope: scope ?? [
11424
+ encodeScope({
11425
+ type: "record.read"
11426
+ })
11427
+ ],
11428
+ userType: TokenUserType.enum.user
11429
+ };
11430
+ }
11431
+ function generateTestValidatorContext(userRole2, eventWithConfig) {
11432
+ const user2 = generateUserTokenPayload({ role: userRole2 });
11433
+ const leafAdminStructureLocationIds = getLeafAdministrativeAreaIds(
11434
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP
11435
+ );
11436
+ if (!eventWithConfig) {
11437
+ return { user: user2, leafAdminStructureLocationIds };
11438
+ }
11439
+ const { event: event2, eventConfig } = eventWithConfig;
11440
+ return {
11441
+ user: user2,
11442
+ leafAdminStructureLocationIds,
11443
+ event: getEventValidatorContext(event2, eventConfig)
11444
+ };
11445
+ }
11446
+
11447
+ // ../commons/src/events/TemplateConfig.ts
11448
+ var window2 = () => ({
11449
+ location: {
11450
+ get: (key) => {
11451
+ return `$window.location.${key}`;
11452
+ }
11453
+ }
11454
+ });
11455
+ function isTemplateVariable(value) {
11456
+ return typeof value === "string" && value.startsWith("$");
11457
+ }
11458
+ function isFieldValue(value) {
11459
+ return FieldValue.safeParse(value).success;
11460
+ }
11461
+ function isFieldValueWithoutTemplates(value) {
11462
+ if (isTemplateVariable(value)) {
11463
+ return false;
11464
+ }
11465
+ if (typeof value === "object" && value !== null && Object.values(value).some((val) => isTemplateVariable(val))) {
11466
+ return false;
11467
+ }
11468
+ return true;
11469
+ }
11470
+ function isFieldConfigDefaultValue(value) {
11471
+ if (!value) {
11472
+ return false;
11473
+ }
11474
+ if (isFieldValue(value)) {
11475
+ return true;
11476
+ }
11477
+ if (isTemplateVariable(value)) {
11478
+ return true;
11479
+ }
11480
+ if (typeof value === "object" && Object.values(value).every((v) => typeof v === "object" && v !== null)) {
11481
+ return Object.values(value).every((v) => isFieldConfigDefaultValue(v));
11482
+ }
11483
+ return false;
11484
+ }
11485
+
11486
+ // ../commons/src/events/scopes.ts
11487
+ var import_lodash6 = require("lodash");
11488
+ var ACTION_SCOPE_MAP = {
11489
+ [ActionType.READ]: ["record.read"],
11490
+ [ActionType.CREATE]: ["record.create"],
11491
+ [ActionType.NOTIFY]: ["record.notify"],
11492
+ [ActionType.DECLARE]: ["record.declare", "record.register"],
11493
+ [ActionType.EDIT]: ["record.edit"],
11494
+ [ActionType.DELETE]: ["record.declare", "record.notify"],
11495
+ [ActionType.REGISTER]: ["record.register"],
11496
+ [ActionType.PRINT_CERTIFICATE]: ["record.print-certified-copies"],
11497
+ [ActionType.REQUEST_CORRECTION]: [
11498
+ "record.request-correction",
11499
+ "record.correct"
11500
+ ],
11501
+ [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: ["record.correct"],
11502
+ [ActionType.REJECT_CORRECTION]: ["record.correct"],
11503
+ [ActionType.APPROVE_CORRECTION]: ["record.correct"],
11504
+ [ActionType.MARK_AS_DUPLICATE]: ["record.review-duplicates"],
11505
+ [ActionType.MARK_AS_NOT_DUPLICATE]: ["record.review-duplicates"],
11506
+ [ActionType.ARCHIVE]: ["record.archive"],
11507
+ [ActionType.UNARCHIVE]: ["record.unarchive"],
11508
+ [ActionType.REJECT]: ["record.reject"],
11509
+ [ActionType.ASSIGN]: null,
11510
+ [ActionType.UNASSIGN]: null,
11511
+ [ActionType.DUPLICATE_DETECTED]: [],
11512
+ [ActionType.CUSTOM]: []
11513
+ };
11514
+ function hasAnyOfScopes(a, b) {
11515
+ return (0, import_lodash6.intersection)(a, b).length > 0;
11516
+ }
11517
+ var AssignmentStatus = {
11518
+ ASSIGNED_TO_SELF: "ASSIGNED_TO_SELF",
11519
+ ASSIGNED_TO_OTHERS: "ASSIGNED_TO_OTHERS",
11520
+ UNASSIGNED: "UNASSIGNED"
11521
+ };
11522
+ function getAssignmentStatus(eventState, userId) {
11523
+ if (!eventState.assignedTo) {
11524
+ return AssignmentStatus.UNASSIGNED;
11525
+ }
11526
+ return eventState.assignedTo == userId ? AssignmentStatus.ASSIGNED_TO_SELF : AssignmentStatus.ASSIGNED_TO_OTHERS;
11527
+ }
11528
+ function isActionInScope({
11529
+ scopes,
11530
+ action,
11531
+ event: event2,
11532
+ currentUser
11533
+ }) {
11534
+ const assignmentStatus = getAssignmentStatus(event2, currentUser.id);
11535
+ const isUnassigningOthers = action === ActionType.UNASSIGN && assignmentStatus === AssignmentStatus.ASSIGNED_TO_OTHERS;
11536
+ const acceptedScopes = isUnassigningOthers ? ["record.unassign-others"] : ACTION_SCOPE_MAP[action];
11537
+ if (acceptedScopes === null) {
11538
+ return true;
11539
+ }
11540
+ if (!acceptedScopes.length) {
11541
+ return false;
11542
+ }
11543
+ const matchingScopes = getAcceptedScopesByType({
11544
+ acceptedScopes,
11545
+ scopes
11546
+ });
11547
+ const canAccess = userCanAccessEventWithScopes(
11548
+ event2,
11549
+ matchingScopes,
11550
+ {
11551
+ id: currentUser.id,
11552
+ primaryOfficeId: currentUser.primaryOfficeId,
11553
+ administrativeAreaId: currentUser.administrativeAreaId ?? null,
11554
+ role: currentUser.role,
11555
+ signature: currentUser.signature,
11556
+ type: currentUser.type
11557
+ }
11558
+ );
11559
+ return canAccess;
11560
+ }
11561
+ function getAvailableRolesForUserUpdatePayload({
11562
+ allRoles,
11563
+ userLocation,
11564
+ acceptedScopes,
11565
+ userRequesting
11566
+ }) {
11567
+ const availableRoles = allRoles.filter((role) => {
11568
+ const canAccess = canAccessOtherUserWithScopes({
11569
+ userToAccess: {
11570
+ ...userLocation,
11571
+ role
11572
+ },
11573
+ user: userRequesting,
11574
+ scopes: acceptedScopes
11575
+ });
11576
+ return canAccess;
11577
+ });
11578
+ return availableRoles;
11579
+ }
11580
+
11581
+ // ../commons/src/events/serializers/user/deserializer.ts
11582
+ function userDeserializer(serializedUserField, user2) {
11583
+ if (typeof serializedUserField === "string") {
11584
+ return serializedUserField;
11585
+ }
11586
+ if (typeof serializedUserField !== "object") {
11587
+ return void 0;
11588
+ }
11589
+ if (serializedUserField.$userField === "name" || serializedUserField.$userField === "fullHonorificName" || serializedUserField.$userField === "device" || serializedUserField.$userField === "firstname" || serializedUserField.$userField === "middlename" || serializedUserField.$userField === "surname") {
11590
+ throw new Error(
11591
+ `Deserializer for ${serializedUserField.$userField} is not implemented yet`
11592
+ );
11593
+ }
11594
+ const value = user2[serializedUserField.$userField];
11595
+ return typeof value === "string" ? value : void 0;
11596
+ }
11597
+ function isDefined(value) {
11598
+ return value !== void 0;
11599
+ }
11600
+ function serializeLocationField(expression, user2) {
11601
+ if (expression.type === "exact") {
11602
+ return userDeserializer(expression.term, user2);
11603
+ }
11604
+ if (expression.type === "within") {
11605
+ return userDeserializer(expression.location, user2);
11606
+ }
11607
+ return void 0;
11608
+ }
11609
+ function deserializeExpression(expression, user2) {
11610
+ if (expression.type === "exact") {
11611
+ const term = userDeserializer(expression.term, user2);
11612
+ if (!term) {
11613
+ return void 0;
11614
+ }
11615
+ return {
11616
+ ...expression,
11617
+ term
11618
+ };
11619
+ }
11620
+ if (expression.type === "within") {
11621
+ const location = userDeserializer(expression.location, user2);
11622
+ if (!location) {
11623
+ return void 0;
11624
+ }
11625
+ return {
11626
+ ...expression,
11627
+ location
11628
+ };
11660
11629
  }
11630
+ return void 0;
11631
+ }
11632
+ function deserializeQueryExpression(expression, user2) {
11633
+ const assignedTo = expression.assignedTo ? userDeserializer(expression.assignedTo.term, user2) : void 0;
11634
+ const createdBy = expression.createdBy ? userDeserializer(expression.createdBy.term, user2) : void 0;
11635
+ const updatedBy = expression.updatedBy ? userDeserializer(expression.updatedBy.term, user2) : void 0;
11636
+ const createdAtLocation = expression.createdAtLocation ? serializeLocationField(expression.createdAtLocation, user2) : void 0;
11637
+ const updatedAtLocation = expression.updatedAtLocation ? serializeLocationField(expression.updatedAtLocation, user2) : void 0;
11638
+ const updatedByUserRole = expression.updatedByUserRole ? userDeserializer(expression.updatedByUserRole.term, user2) : void 0;
11639
+ const declaredLocation = expression["legalStatuses.DECLARED.createdAtLocation"] ? userDeserializer(
11640
+ expression["legalStatuses.DECLARED.createdAtLocation"].location,
11641
+ user2
11642
+ ) : void 0;
11643
+ const registeredLocation = expression["legalStatuses.REGISTERED.createdAtLocation"] ? userDeserializer(
11644
+ expression["legalStatuses.REGISTERED.createdAtLocation"].location,
11645
+ user2
11646
+ ) : void 0;
11647
+ return {
11648
+ ...expression,
11649
+ assignedTo: expression.assignedTo && isDefined(assignedTo) ? { ...expression.assignedTo, term: assignedTo } : void 0,
11650
+ createdBy: expression.createdBy && isDefined(createdBy) ? { ...expression.createdBy, term: createdBy } : void 0,
11651
+ updatedBy: expression.updatedBy && isDefined(updatedBy) ? { ...expression.updatedBy, term: updatedBy } : void 0,
11652
+ updatedByUserRole: expression.updatedByUserRole && isDefined(updatedByUserRole) ? {
11653
+ ...expression.updatedByUserRole,
11654
+ term: updatedByUserRole
11655
+ } : void 0,
11656
+ createdAtLocation: expression.createdAtLocation && isDefined(createdAtLocation) ? deserializeExpression(expression.createdAtLocation, user2) : void 0,
11657
+ updatedAtLocation: expression.updatedAtLocation && isDefined(updatedAtLocation) ? deserializeExpression(expression.updatedAtLocation, user2) : void 0,
11658
+ ["legalStatuses.DECLARED.createdAtLocation"]: expression["legalStatuses.DECLARED.createdAtLocation"] && isDefined(declaredLocation) ? {
11659
+ ...expression["legalStatuses.DECLARED.createdAtLocation"],
11660
+ location: declaredLocation
11661
+ } : void 0,
11662
+ ["legalStatuses.REGISTERED.createdAtLocation"]: expression["legalStatuses.REGISTERED.createdAtLocation"] && isDefined(registeredLocation) ? {
11663
+ ...expression["legalStatuses.REGISTERED.createdAtLocation"],
11664
+ location: registeredLocation
11665
+ } : void 0
11666
+ };
11667
+ }
11668
+ function deserializeQuery(query, user2) {
11669
+ return {
11670
+ ...query,
11671
+ clauses: query.clauses.map(
11672
+ (clause) => deserializeQueryExpression(clause, user2)
11673
+ // SAFETY: This cast should be safe because `query.clauses` has already been validated as non-empty by the Zod schema.
11674
+ // Without the cast, TypeScript cannot infer the tuple type required by the target interface.
11675
+ )
11676
+ };
11677
+ }
11678
+
11679
+ // ../commons/src/events/state/availableActions.ts
11680
+ var AVAILABLE_ACTIONS_BY_EVENT_STATUS = {
11681
+ [EventStatus.enum.CREATED]: [
11682
+ ActionType.READ,
11683
+ ActionType.DECLARE,
11684
+ ActionType.NOTIFY,
11685
+ ActionType.DELETE
11686
+ ],
11687
+ [EventStatus.enum.NOTIFIED]: [
11688
+ ActionType.READ,
11689
+ ActionType.EDIT,
11690
+ ActionType.MARK_AS_DUPLICATE,
11691
+ ActionType.ARCHIVE,
11692
+ ActionType.REJECT,
11693
+ ActionType.CUSTOM
11694
+ ],
11695
+ [EventStatus.enum.DECLARED]: [
11696
+ ActionType.READ,
11697
+ ActionType.REGISTER,
11698
+ ActionType.MARK_AS_DUPLICATE,
11699
+ ActionType.ARCHIVE,
11700
+ ActionType.REJECT,
11701
+ ActionType.CUSTOM,
11702
+ ActionType.EDIT
11703
+ ],
11704
+ [EventStatus.enum.REGISTERED]: [
11705
+ ActionType.READ,
11706
+ ActionType.PRINT_CERTIFICATE,
11707
+ ActionType.REQUEST_CORRECTION,
11708
+ ActionType.APPROVE_CORRECTION,
11709
+ ActionType.REJECT_CORRECTION,
11710
+ ActionType.CUSTOM,
11711
+ ClientSpecificAction.REVIEW_CORRECTION_REQUEST
11712
+ ],
11713
+ [EventStatus.enum.ARCHIVED]: [
11714
+ ActionType.READ,
11715
+ ActionType.CUSTOM,
11716
+ ActionType.UNARCHIVE
11717
+ ]
11718
+ };
11719
+ var ACTION_FILTERS = {
11720
+ [ActionType.PRINT_CERTIFICATE]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11721
+ [ActionType.REQUEST_CORRECTION]: (flags) => !flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11722
+ [ClientSpecificAction.REVIEW_CORRECTION_REQUEST]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11723
+ [ActionType.APPROVE_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11724
+ [ActionType.REJECT_CORRECTION]: (flags) => flags.includes(InherentFlags.CORRECTION_REQUESTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11725
+ [ActionType.MARK_AS_DUPLICATE]: (flags) => flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11726
+ [ActionType.EDIT]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11727
+ [ActionType.REGISTER]: (flags) => !flags.includes(InherentFlags.POTENTIAL_DUPLICATE) && !flags.some((flag2) => flag2.endsWith(":requested")),
11728
+ [ActionType.REJECT]: (flags) => !flags.includes(InherentFlags.REJECTED) && !flags.some((flag2) => flag2.endsWith(":requested")),
11729
+ [ActionType.ARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11730
+ [ActionType.UNARCHIVE]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11731
+ [ActionType.ASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11732
+ [ActionType.UNASSIGN]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested")),
11733
+ [ActionType.CUSTOM]: (flags) => !flags.some((flag2) => flag2.endsWith(":requested"))
11734
+ };
11735
+ function filterActionsByFlags(actions, flags) {
11736
+ return actions.filter((action) => ACTION_FILTERS[action]?.(flags) ?? true);
11737
+ }
11738
+ var REJECTED_ACTIONS = [
11739
+ ActionType.READ,
11740
+ ActionType.NOTIFY,
11741
+ ActionType.CUSTOM,
11742
+ ActionType.EDIT,
11743
+ ActionType.ARCHIVE
11661
11744
  ];
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
- );
11745
+ function getAvailableActionsWithoutFlagFilters(status2, flags) {
11746
+ if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
11747
+ return [ActionType.NOTIFY, ActionType.DECLARE, ActionType.REGISTER];
11748
+ }
11749
+ if (flags.includes(InherentFlags.REJECTED) && status2 !== EventStatus.enum.ARCHIVED) {
11750
+ return REJECTED_ACTIONS;
11751
+ }
11752
+ return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
11753
+ }
11754
+ function getAvailableActionsForEvent(event2) {
11755
+ return filterActionsByFlags(
11756
+ getAvailableActionsWithoutFlagFilters(event2.status, event2.flags),
11757
+ event2.flags
11758
+ );
11759
+ }
11760
+
11761
+ // ../commons/src/events/FileUtils.ts
11762
+ var import_lodash7 = require("lodash");
11763
+ function getFilePathsFromEvent(event2) {
11764
+ const filepaths = event2.actions.filter(
11765
+ (action) => action.status !== ActionStatus.Rejected
11766
+ ).flatMap((action) => {
11767
+ const declarationValues = Object.values(action.declaration);
11768
+ const annotationValues = Object.values(action.annotation ?? {});
11769
+ const actionFilePaths = [
11770
+ ...declarationValues,
11771
+ ...annotationValues
11772
+ ].flatMap((value) => {
11773
+ const fileParsed = FileFieldValue.safeParse(value);
11774
+ if (fileParsed.success) {
11775
+ return [fileParsed.data.path];
11776
+ }
11777
+ const fileOptionParsed = FileFieldWithOptionValue.safeParse(value);
11778
+ if (fileOptionParsed.success) {
11779
+ return fileOptionParsed.data.map((val) => val.path);
11780
+ }
11781
+ return [];
11782
+ });
11783
+ return actionFilePaths;
11784
+ });
11785
+ return (0, import_lodash7.uniq)(filepaths);
11786
+ }
11678
11787
 
11679
11788
  // ../commons/src/events/locationPayloads.ts
11680
11789
  var z45 = __toESM(require("zod/v4"));