@opencrvs/toolkit 2.0.0-rc.bee2b7b → 2.0.0-rc.bfc4add

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 (92) hide show
  1. package/create-countryconfig/index.js +73 -0
  2. package/create-countryconfig/package.json +11 -0
  3. package/dist/application-config/index.js +28 -39
  4. package/dist/cli.js +1845 -360
  5. package/dist/commons/api/router.d.ts +3016 -300
  6. package/dist/commons/application-config/index.d.ts +16 -4
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/conditionals/validate.d.ts +1 -0
  9. package/dist/commons/events/ActionInput.d.ts +108 -0
  10. package/dist/commons/events/Draft.d.ts +3 -0
  11. package/dist/commons/events/EventIndex.d.ts +0 -3
  12. package/dist/commons/events/EventMetadata.d.ts +0 -7
  13. package/dist/commons/events/FieldConfig.d.ts +10 -0
  14. package/dist/commons/events/locations.d.ts +21 -0
  15. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  16. package/dist/commons/events/scopes.d.ts +24 -1
  17. package/dist/commons/events/state/index.d.ts +0 -4
  18. package/dist/commons/events/state/utils.d.ts +0 -2
  19. package/dist/commons/events/utils.d.ts +1 -1
  20. package/dist/conditionals/index.js +11 -10
  21. package/dist/events/index.js +95 -65
  22. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  23. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  24. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  25. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  26. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  27. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  28. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
  30. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  32. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  33. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  34. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  35. package/dist/migrations/v2.0/create-events-index.js +1 -2
  36. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
  37. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  38. package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
  39. package/dist/migrations/v2.0/index.d.ts +10 -4
  40. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/index.js +1813 -357
  42. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  44. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
  45. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  46. package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
  47. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  48. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  49. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  50. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  51. package/dist/migrations/v2.0/migrate-scopes.js +55 -32
  52. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  53. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  54. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  55. package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
  56. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  57. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  58. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  59. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  60. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  61. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  62. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  63. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  64. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  65. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  66. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  67. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  68. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  70. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  71. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  72. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  73. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  74. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  75. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  76. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  77. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  78. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  79. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  80. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  81. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  82. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  83. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  84. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  85. package/dist/migrations/v2.0/update-package-json.js +105 -0
  86. package/dist/notification/index.js +27 -35
  87. package/dist/scopes/index.d.ts +8 -1
  88. package/dist/scopes/index.js +11 -10
  89. package/opencrvs-toolkit-2.0.0-rc.bfc4add.tgz +0 -0
  90. package/package.json +1 -1
  91. package/tsconfig.tsbuildinfo +1 -1
  92. package/opencrvs-toolkit-2.0.0-rc.bee2b7b.tgz +0 -0
@@ -0,0 +1,19 @@
1
+ import { AdministrativeArea, Location } from './locations';
2
+ export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS: AdministrativeArea[];
3
+ export declare const V2_DEFAULT_MOCK_LOCATIONS: Location[];
4
+ export declare const V2_DEFAULT_MOCK_LOCATIONS_MAP: Map<string & import("zod").$brand<"UUID">, {
5
+ id: string & import("zod").$brand<"UUID">;
6
+ name: string;
7
+ administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
8
+ validUntil: string | null;
9
+ locationType: string | null;
10
+ externalId?: string | null | undefined;
11
+ }>;
12
+ export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: Map<string & import("zod").$brand<"UUID">, {
13
+ id: string & import("zod").$brand<"UUID">;
14
+ name: string;
15
+ parentId: (string & import("zod").$brand<"UUID">) | null;
16
+ validUntil: string | null;
17
+ externalId?: string | null | undefined;
18
+ }>;
19
+ //# sourceMappingURL=mocks.test.utils.d.ts.map
@@ -1,8 +1,9 @@
1
1
  import { DisplayableAction } from './ActionType';
2
- import { EncodedScope } from '../scopes';
2
+ import { EncodedScope, UserScopeV2 } from '../scopes';
3
3
  import { EventIndexWithAdministrativeHierarchy } from './locations';
4
4
  import { UserContext } from '../users/User';
5
5
  import { EventIndex } from './EventIndex';
6
+ import { UUID } from 'src/uuid';
6
7
  export declare const ACTION_SCOPE_MAP: {
7
8
  READ: "record.read"[];
8
9
  CREATE: "record.create"[];
@@ -53,4 +54,26 @@ export declare function isActionInScope({ scopes, action, event, currentUser }:
53
54
  event: EventIndexWithAdministrativeHierarchy;
54
55
  currentUser: UserContext;
55
56
  }): boolean;
57
+ /**
58
+ *
59
+ *
60
+ * @param allRoles - All possible roles in the system
61
+ * @param userLocation - The location and role information of the user whose role options are being determined
62
+ * @param acceptedScopes - The scopes of the user requesting the role update, used to determine which roles they can assign.
63
+ * @param userRequesting - The user context of the user requesting the role update, used to check location-based access to the target user's location.
64
+ *
65
+ * @returns An array of roles that the requesting user is allowed to assign to the target user based on their scopes and location
66
+ *
67
+ * 1) Used to determine which roles should be available in the dropdown when a user is editing another user's role in the user management interface.
68
+ * 2) Used to check if payload includes valid role.
69
+ */
70
+ export declare function getAvailableRolesForUserUpdatePayload({ allRoles, userLocation, acceptedScopes, userRequesting }: {
71
+ allRoles: string[];
72
+ userRequesting: UserContext;
73
+ acceptedScopes: UserScopeV2[];
74
+ userLocation: {
75
+ administrativeHierarchy: UUID[];
76
+ primaryOfficeId: UUID;
77
+ };
78
+ }): string[];
56
79
  //# sourceMappingURL=scopes.d.ts.map
@@ -9,7 +9,6 @@ import { UUID } from '../../uuid';
9
9
  import { DocumentPath } from '../../documents';
10
10
  export declare function getStatusFromActions(actions: Array<Action>): "CREATED" | "NOTIFIED" | "DECLARED" | "REGISTERED" | "ARCHIVED";
11
11
  export declare function getAssignedUserFromActions(actions: Array<ActionDocument>): string | null;
12
- export declare function getAssignedUserSignatureFromActions(actions: Array<ActionDocument>): string | null;
13
12
  type NonNullableDeep<T> = T extends [unknown, ...unknown[]] ? {
14
13
  [K in keyof T]: NonNullableDeep<NonNullable<T[K]>>;
15
14
  } : T extends UUID ? T : T extends DocumentPath ? T : T extends string ? NonNullable<T> : T extends (infer U)[] ? NonNullableDeep<U>[] : T extends object ? {
@@ -73,7 +72,6 @@ export declare function applyDraftToEventIndex(eventIndex: EventIndex, draft: Dr
73
72
  createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
74
73
  createdByUserType?: "user" | "system" | null | undefined;
75
74
  createdByRole?: string | undefined;
76
- createdBySignature?: string | null | undefined;
77
75
  } | null | undefined;
78
76
  REGISTERED?: {
79
77
  createdAt: string;
@@ -83,7 +81,6 @@ export declare function applyDraftToEventIndex(eventIndex: EventIndex, draft: Dr
83
81
  createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
84
82
  createdByUserType?: "user" | "system" | null | undefined;
85
83
  createdByRole?: string | undefined;
86
- createdBySignature?: string | null | undefined;
87
84
  } | null | undefined;
88
85
  };
89
86
  createdAt: string;
@@ -101,7 +98,6 @@ export declare function applyDraftToEventIndex(eventIndex: EventIndex, draft: Dr
101
98
  createdByUserType?: "user" | "system" | null | undefined;
102
99
  updatedByUserRole?: string | null | undefined;
103
100
  createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
104
- createdBySignature?: (string & import("zod").$brand<"DocumentPath">) | null | undefined;
105
101
  updatedAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
106
102
  assignedTo?: string | null | undefined;
107
103
  updatedBy?: string | null | undefined;
@@ -312,7 +312,6 @@ export declare function getLegalStatuses(actions: Action[]): {
312
312
  createdAtLocation: (string & import("zod").$brand<"UUID">) | null | undefined;
313
313
  acceptedAt: string;
314
314
  createdByRole: string | undefined;
315
- createdBySignature: (string & import("zod").$brand<"DocumentPath">) | null | undefined;
316
315
  registrationNumber: string | null | undefined;
317
316
  } | null;
318
317
  REGISTERED: {
@@ -322,7 +321,6 @@ export declare function getLegalStatuses(actions: Action[]): {
322
321
  createdAtLocation: (string & import("zod").$brand<"UUID">) | null | undefined;
323
322
  acceptedAt: string;
324
323
  createdByRole: string | undefined;
325
- createdBySignature: (string & import("zod").$brand<"DocumentPath">) | null | undefined;
326
324
  registrationNumber: string | null | undefined;
327
325
  } | null;
328
326
  };
@@ -131,7 +131,7 @@ export declare function isPageVisible(page: PageConfig, formValues: ActionUpdate
131
131
  * * @param validatorContext - custom validation context
132
132
  * @returns {Partial<T>} A new object containing only the values for visible fields
133
133
  */
134
- export declare function omitHiddenFields<T extends EventState | ActionUpdate>(fields: FieldConfig[], formValues: T, validatorContext: ValidatorContext, includeHiddenFieldsWithNullValues?: boolean, declarationContext?: EventState): Partial<T>;
134
+ export declare function omitHiddenFields<T extends EventState | ActionUpdate>(fields: FieldConfig[], formValues: T, validatorContext: ValidatorContext, includeHiddenFieldsWithNullValues?: boolean): Partial<T>;
135
135
  export declare function omitHiddenPaginatedFields<T extends EventState | ActionUpdate>(formConfig: FormConfig, values: T, validatorContext: ValidatorContext, includeHiddenFieldsWithNullValues?: boolean): Partial<Partial<T>>;
136
136
  /**
137
137
  *
@@ -209,6 +209,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
209
209
  var AccessLevelOptions = z6.object({
210
210
  accessLevel: JurisdictionFilter.optional()
211
211
  });
212
+ var AllUserScopeOptions = AccessLevelOptions.extend({
213
+ role: userRole.optional()
214
+ });
212
215
  var WorkqueueOrDashboardOptions = z6.object({
213
216
  ids: z6.preprocess(
214
217
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -218,6 +221,7 @@ var WorkqueueOrDashboardOptions = z6.object({
218
221
  var AllScopeOptions = z6.object({
219
222
  ...AllRecordScopeOptions.shape,
220
223
  ...AccessLevelOptions.shape,
224
+ ...AllUserScopeOptions.shape,
221
225
  ...WorkqueueOrDashboardOptions.shape
222
226
  });
223
227
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -294,27 +298,24 @@ var SystemScopeType = z6.enum([
294
298
  "organisation.read-locations",
295
299
  "user.read",
296
300
  "user.create",
297
- "user.edit"
301
+ "user.edit",
302
+ "user.search"
298
303
  ]);
299
304
  var UserScopeType = SystemScopeType.extract([
300
305
  "user.read",
301
306
  "user.create",
302
- "user.edit"
307
+ "user.edit",
308
+ "user.search"
303
309
  ]);
304
310
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
305
311
  var UserScopeV2 = z6.discriminatedUnion("type", [
306
312
  z6.object({
307
313
  type: ScopesWithRoleOption,
308
- options: z6.object({
309
- accessLevel: JurisdictionFilter.optional(),
310
- role: userRole.optional()
311
- }).optional()
314
+ options: AllUserScopeOptions.optional()
312
315
  }),
313
316
  z6.object({
314
- type: UserScopeType.extract(["user.read"]),
315
- options: z6.object({
316
- accessLevel: JurisdictionFilter.optional()
317
- }).optional()
317
+ type: UserScopeType.extract(["user.read", "user.search"]),
318
+ options: AccessLevelOptions.optional()
318
319
  })
319
320
  ]);
320
321
  var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
@@ -302,12 +302,13 @@ __export(events_exports, {
302
302
  getActionConfig: () => getActionConfig,
303
303
  getActionReview: () => getActionReview,
304
304
  getActionReviewFields: () => getActionReviewFields,
305
+ getAdministrativeAreaHierarchy: () => getAdministrativeAreaHierarchy,
305
306
  getAllUniqueFields: () => getAllUniqueFields,
306
307
  getAnnotationFromDrafts: () => getAnnotationFromDrafts,
307
308
  getAssignedUserFromActions: () => getAssignedUserFromActions,
308
- getAssignedUserSignatureFromActions: () => getAssignedUserSignatureFromActions,
309
309
  getAssignmentStatus: () => getAssignmentStatus,
310
310
  getAvailableActionsForEvent: () => getAvailableActionsForEvent,
311
+ getAvailableRolesForUserUpdatePayload: () => getAvailableRolesForUserUpdatePayload,
311
312
  getCompleteActionAnnotation: () => getCompleteActionAnnotation,
312
313
  getCompleteActionDeclaration: () => getCompleteActionDeclaration,
313
314
  getCurrentEventState: () => getCurrentEventState,
@@ -318,6 +319,7 @@ __export(events_exports, {
318
319
  getDeclarationPages: () => getDeclarationPages,
319
320
  getEventConfigById: () => getEventConfigById,
320
321
  getFilePathsFromEvent: () => getFilePathsFromEvent,
322
+ getLocationHierarchy: () => getLocationHierarchy,
321
323
  getMixedPath: () => getMixedPath,
322
324
  getPendingAction: () => getPendingAction,
323
325
  getPrintCertificatePages: () => getPrintCertificatePages,
@@ -518,6 +520,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
518
520
  var AccessLevelOptions = z2.object({
519
521
  accessLevel: JurisdictionFilter.optional()
520
522
  });
523
+ var AllUserScopeOptions = AccessLevelOptions.extend({
524
+ role: userRole.optional()
525
+ });
521
526
  var WorkqueueOrDashboardOptions = z2.object({
522
527
  ids: z2.preprocess(
523
528
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -527,6 +532,7 @@ var WorkqueueOrDashboardOptions = z2.object({
527
532
  var AllScopeOptions = z2.object({
528
533
  ...AllRecordScopeOptions.shape,
529
534
  ...AccessLevelOptions.shape,
535
+ ...AllUserScopeOptions.shape,
530
536
  ...WorkqueueOrDashboardOptions.shape
531
537
  });
532
538
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -603,27 +609,24 @@ var SystemScopeType = z2.enum([
603
609
  "organisation.read-locations",
604
610
  "user.read",
605
611
  "user.create",
606
- "user.edit"
612
+ "user.edit",
613
+ "user.search"
607
614
  ]);
608
615
  var UserScopeType = SystemScopeType.extract([
609
616
  "user.read",
610
617
  "user.create",
611
- "user.edit"
618
+ "user.edit",
619
+ "user.search"
612
620
  ]);
613
621
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
614
622
  var UserScopeV2 = z2.discriminatedUnion("type", [
615
623
  z2.object({
616
624
  type: ScopesWithRoleOption,
617
- options: z2.object({
618
- accessLevel: JurisdictionFilter.optional(),
619
- role: userRole.optional()
620
- }).optional()
625
+ options: AllUserScopeOptions.optional()
621
626
  }),
622
627
  z2.object({
623
- type: UserScopeType.extract(["user.read"]),
624
- options: z2.object({
625
- accessLevel: JurisdictionFilter.optional()
626
- }).optional()
628
+ type: UserScopeType.extract(["user.read", "user.search"]),
629
+ options: AccessLevelOptions.optional()
627
630
  })
628
631
  ]);
629
632
  function scopeUsesRoleOptions(scope) {
@@ -1410,28 +1413,20 @@ function schemaPriority(schema) {
1410
1413
  return idx === -1 ? 9999 : idx;
1411
1414
  }
1412
1415
  function safeUnion(schemas) {
1416
+ const sortedSchemas = [...schemas].sort(
1417
+ (a, b) => schemaPriority(a) - schemaPriority(b)
1418
+ );
1413
1419
  return z12.any().superRefine((val, ctx) => {
1414
- const successful = schemas.filter((s) => s.safeParse(val).success);
1415
- if (successful.length === 1) {
1416
- return;
1417
- }
1418
- if (successful.length === 0) {
1419
- ctx.addIssue({
1420
- code: "invalid_type",
1421
- expected: "custom",
1422
- message: "Value does not match any schema"
1423
- });
1424
- return;
1425
- }
1426
- successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
1427
- const best = successful[0];
1428
- if (!best.safeParse(val).success) {
1429
- ctx.addIssue({
1430
- expected: "custom",
1431
- code: "invalid_type",
1432
- message: "Value did not match the best schema"
1433
- });
1420
+ for (const schema of sortedSchemas) {
1421
+ if (schema.safeParse(val).success) {
1422
+ return;
1423
+ }
1434
1424
  }
1425
+ ctx.addIssue({
1426
+ code: "invalid_type",
1427
+ expected: "custom",
1428
+ message: "Value does not match any schema"
1429
+ });
1435
1430
  }).meta({
1436
1431
  description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
1437
1432
  });
@@ -1769,8 +1764,7 @@ var ActionCreationMetadata = z16.object({
1769
1764
  ),
1770
1765
  createdByUserType: z16.enum(["user", "system"]).nullish().describe("Whether the user is a normal user or a system."),
1771
1766
  acceptedAt: z16.iso.datetime().describe("Timestamp when the action request was accepted."),
1772
- createdByRole: z16.string().optional().describe("Role of the user at the time of action request creation."),
1773
- createdBySignature: z16.string().nullish().describe("Signature of the user who created the action request.")
1767
+ createdByRole: z16.string().optional().describe("Role of the user at the time of action request creation.")
1774
1768
  });
1775
1769
  var RegistrationCreationMetadata = ActionCreationMetadata.extend({
1776
1770
  registrationNumber: z16.string().describe(
@@ -1798,9 +1792,6 @@ var EventMetadata = z16.object({
1798
1792
  createdAtLocation: UUID.nullish().describe(
1799
1793
  "Location of the user who created the event."
1800
1794
  ),
1801
- createdBySignature: DocumentPath.nullish().describe(
1802
- "Signature of the user who created the event."
1803
- ),
1804
1795
  updatedAtLocation: UUID.nullish().describe(
1805
1796
  "Location of the user who last changed the status."
1806
1797
  ),
@@ -3800,6 +3791,9 @@ function precompileActionSchemas(eventConfigurations) {
3800
3791
  function isAgeValue(value) {
3801
3792
  return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
3802
3793
  }
3794
+ function mergeWithBaseFormState(values, context) {
3795
+ return { ...context.baseFormState, ...values };
3796
+ }
3803
3797
  function validate(schema, data) {
3804
3798
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3805
3799
  if ("$form" in data) {
@@ -3838,7 +3832,7 @@ function isOnline() {
3838
3832
  }
3839
3833
  function isConditionMet(conditional, values, context, eventIndex) {
3840
3834
  return validate(conditional, {
3841
- $form: values,
3835
+ $form: mergeWithBaseFormState(values, context),
3842
3836
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3843
3837
  $online: isOnline(),
3844
3838
  $user: context.user,
@@ -3867,7 +3861,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3867
3861
  return true;
3868
3862
  }
3869
3863
  const validConditionals = getConditionalActionsForField(field3, {
3870
- $form: form,
3864
+ $form: mergeWithBaseFormState(form, context),
3871
3865
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3872
3866
  $online: isOnline(),
3873
3867
  $user: context.user,
@@ -4059,7 +4053,7 @@ function runFieldValidations({
4059
4053
  return [];
4060
4054
  }
4061
4055
  const conditionalParameters = {
4062
- $form: form,
4056
+ $form: mergeWithBaseFormState(form, context),
4063
4057
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4064
4058
  /**
4065
4059
  * In real use cases, there can be hundreds of thousands of locations.
@@ -4303,17 +4297,16 @@ function isPageVisible(page, formValues, context) {
4303
4297
  }
4304
4298
  return isConditionMet(page.conditional, formValues, context);
4305
4299
  }
4306
- function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false, declarationContext) {
4300
+ function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false) {
4307
4301
  const base = (0, import_lodash.cloneDeep)(formValues);
4308
4302
  function fn(prevVisibilityContext) {
4309
- const visibilityForm = declarationContext ? { ...declarationContext, ...prevVisibilityContext } : prevVisibilityContext;
4310
4303
  const cleaned = (0, import_lodash.omitBy)(base, (value, fieldId) => {
4311
4304
  const fieldConfig = fields.filter((f) => f.id === fieldId);
4312
4305
  if (!fieldConfig.length) {
4313
4306
  return false;
4314
4307
  }
4315
4308
  const isHidden = fieldConfig.every(
4316
- (f) => !isFieldVisible(f, visibilityForm, validatorContext)
4309
+ (f) => !isFieldVisible(f, prevVisibilityContext, validatorContext)
4317
4310
  );
4318
4311
  if (!isHidden) {
4319
4312
  return false;
@@ -4331,7 +4324,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
4331
4324
  const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4332
4325
  const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4333
4326
  const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
4334
- return hiddenFields.some((f) => f.id === fieldId);
4327
+ return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
4335
4328
  });
4336
4329
  return omitHiddenFields(
4337
4330
  visibleFields,
@@ -4378,13 +4371,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
4378
4371
  }
4379
4372
  function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
4380
4373
  const annotationFields = getActionAnnotationFields(actionConfig);
4381
- return omitHiddenFields(
4382
- annotationFields,
4383
- annotation,
4384
- context,
4385
- false,
4386
- declaration
4387
- );
4374
+ return omitHiddenFields(annotationFields, annotation, {
4375
+ ...context,
4376
+ baseFormState: declaration
4377
+ });
4388
4378
  }
4389
4379
  function deepMerge(currentDocument, actionDocument) {
4390
4380
  const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
@@ -5896,6 +5886,9 @@ var BaseActionInput = z38.object({
5896
5886
  originalActionId: UUID.optional(),
5897
5887
  // should not be part of base action.
5898
5888
  keepAssignment: z38.boolean().optional(),
5889
+ keepAssignmentIfAccepted: z38.boolean().optional(),
5890
+ keepAssignmentIfRejected: z38.boolean().optional(),
5891
+ waitFor: z38.boolean().optional(),
5899
5892
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5900
5893
  // @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
5901
5894
  createdAtLocation: UUID.nullish().describe(
@@ -6149,7 +6142,6 @@ function getDeclarationActionCreationMetadata(actionType, actions) {
6149
6142
  createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
6150
6143
  acceptedAt: acceptAction.createdAt,
6151
6144
  createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
6152
- createdBySignature: requestAction?.createdBySignature ?? acceptAction.createdBySignature,
6153
6145
  registrationNumber
6154
6146
  };
6155
6147
  }
@@ -6363,17 +6355,6 @@ function getAssignedUserFromActions(actions) {
6363
6355
  return user2;
6364
6356
  }, null);
6365
6357
  }
6366
- function getAssignedUserSignatureFromActions(actions) {
6367
- return actions.reduce((signature, action) => {
6368
- if (action.type === ActionType.ASSIGN) {
6369
- return action.createdBySignature || null;
6370
- }
6371
- if (action.type === ActionType.UNASSIGN) {
6372
- return null;
6373
- }
6374
- return signature;
6375
- }, null);
6376
- }
6377
6358
  function deepDropNulls(obj) {
6378
6359
  if (Array.isArray(obj)) {
6379
6360
  return obj.map(deepDropNulls);
@@ -6469,10 +6450,8 @@ function getCurrentEventState(event2, config) {
6469
6450
  createdBy: creationAction.createdBy,
6470
6451
  createdByUserType: creationAction.createdByUserType,
6471
6452
  createdAtLocation: creationAction.createdAtLocation,
6472
- createdBySignature: creationAction.createdBySignature,
6473
6453
  updatedAt: acceptedActionMetadata.createdAt,
6474
6454
  assignedTo: getAssignedUserFromActions(acceptedActions),
6475
- assignedToSignature: getAssignedUserSignatureFromActions(acceptedActions),
6476
6455
  updatedBy: requestActionMetadata.createdBy,
6477
6456
  updatedAtLocation: requestActionMetadata.createdAtLocation,
6478
6457
  declaration,
@@ -9731,7 +9710,6 @@ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
9731
9710
  createdBy: overrides.createdBy ?? generateUuid(rng),
9732
9711
  createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
9733
9712
  updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
9734
- createdBySignature: overrides.createdBySignature ?? generateRandomSignature(rng),
9735
9713
  updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
9736
9714
  assignedTo: overrides.assignedTo ?? null,
9737
9715
  updatedBy: overrides.updatedBy ?? generateUuid(rng),
@@ -10002,6 +9980,39 @@ function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10002
9980
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
10003
9981
  );
10004
9982
  }
9983
+ function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
9984
+ const collectedLocations = [];
9985
+ const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
9986
+ let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
9987
+ while (current) {
9988
+ collectedLocations.push(current);
9989
+ if (!current.parentId) {
9990
+ break;
9991
+ }
9992
+ const parentId = current.parentId;
9993
+ current = administrativeAreas.get(parentId);
9994
+ }
9995
+ return collectedLocations;
9996
+ }
9997
+ function getLocationHierarchy(selectedId, context) {
9998
+ const { administrativeAreas, locations } = context;
9999
+ const loc = locations.get(selectedId);
10000
+ if (loc) {
10001
+ if (loc.administrativeAreaId) {
10002
+ const hierarchy2 = getAdministrativeAreaHierarchy(
10003
+ loc.administrativeAreaId,
10004
+ administrativeAreas
10005
+ );
10006
+ return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10007
+ }
10008
+ return [loc.id];
10009
+ }
10010
+ const hierarchy = getAdministrativeAreaHierarchy(
10011
+ selectedId,
10012
+ administrativeAreas
10013
+ );
10014
+ return hierarchy.reverse().map((area) => area.id);
10015
+ }
10005
10016
 
10006
10017
  // ../commons/src/events/scopes.ts
10007
10018
  var ACTION_SCOPE_MAP = {
@@ -10076,6 +10087,25 @@ function isActionInScope({
10076
10087
  );
10077
10088
  return canAccess;
10078
10089
  }
10090
+ function getAvailableRolesForUserUpdatePayload({
10091
+ allRoles,
10092
+ userLocation,
10093
+ acceptedScopes,
10094
+ userRequesting
10095
+ }) {
10096
+ const availableRoles = allRoles.filter((role) => {
10097
+ const canAccess = canAccessOtherUserWithScopes({
10098
+ userToAccess: {
10099
+ ...userLocation,
10100
+ role
10101
+ },
10102
+ user: userRequesting,
10103
+ scopes: acceptedScopes
10104
+ });
10105
+ return canAccess;
10106
+ });
10107
+ return availableRoles;
10108
+ }
10079
10109
 
10080
10110
  // ../commons/src/events/serializers/user/deserializer.ts
10081
10111
  function userDeserializer(serializedUserField, user2) {
@@ -1 +1 @@
1
- {"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"AA6aA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"add-birth-certificate-issuance-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/add-birth-certificate-issuance-flag.ts"],"names":[],"mappings":"AAycA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}