@opencrvs/toolkit 2.0.0-rc.c2c75ca → 2.0.0-rc.c3d327f

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 (47) 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 +54 -36
  4. package/dist/cli.js +442 -169
  5. package/dist/commons/api/router.d.ts +3015 -298
  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 +38 -1
  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 +37 -7
  21. package/dist/events/index.js +159 -62
  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 +60 -35
  24. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  25. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  26. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
  27. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
  28. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
  30. package/dist/migrations/v2.0/index.d.ts +5 -3
  31. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  32. package/dist/migrations/v2.0/index.js +442 -169
  33. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  34. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
  35. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
  36. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
  37. package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
  38. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/migrate-scopes.js +54 -30
  40. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
  42. package/dist/notification/index.js +53 -32
  43. package/dist/scopes/index.d.ts +87 -10
  44. package/dist/scopes/index.js +43 -8
  45. package/opencrvs-toolkit-2.0.0-rc.c3d327f.tgz +0 -0
  46. package/package.json +1 -1
  47. package/opencrvs-toolkit-2.0.0-rc.c2c75ca.tgz +0 -0
@@ -1,7 +1,8 @@
1
+ import { UUID } from '../uuid';
1
2
  import * as z from 'zod/v4';
2
3
  import { EventIndex } from './EventIndex';
3
4
  import { ActionCreationMetadata, RegistrationCreationMetadata } from './EventMetadata';
4
- import { RecordScopeV2 } from '../scopes';
5
+ import { RecordScopeV2, UserScopeV2 } from '../scopes';
5
6
  import { SystemContext, UserContext } from '../users/User';
6
7
  /** @deprecated Moving on, location types are arbitrary and defined by the country config. */
7
8
  export declare const LocationTypeV1: z.ZodEnum<{
@@ -51,11 +52,47 @@ export type EventIndexWithAdministrativeHierarchy = Omit<ToArrayFields<EventInde
51
52
  *
52
53
  */
53
54
  export declare function canAccessEventWithScope(event: Partial<EventIndexWithAdministrativeHierarchy>, scope: RecordScopeV2, user: UserContext | SystemContext, customActionType?: string): boolean;
55
+ export type UserWithResolvedHierarchy = {
56
+ role: string;
57
+ administrativeHierarchy: UUID[];
58
+ primaryOfficeId: UUID;
59
+ };
60
+ export declare function canAccessUserWithScope({ userToAccess, scope, user }: {
61
+ userToAccess: UserWithResolvedHierarchy;
62
+ scope: UserScopeV2;
63
+ user: UserContext | SystemContext;
64
+ }): boolean;
65
+ export declare function canAccessOtherUserWithScopes({ scopes, userToAccess, user }: {
66
+ scopes: UserScopeV2[];
67
+ userToAccess: UserWithResolvedHierarchy;
68
+ user: UserContext | SystemContext;
69
+ }): boolean;
54
70
  /**
55
71
  * Given indexed event and list of resolved scopes, determine if any of the scopes allow access to the event.
56
72
  *
57
73
  * One of the scopes must allow access for the event to be accessible.
58
74
  */
59
75
  export declare function userCanAccessEventWithScopes(event: Partial<EventIndexWithAdministrativeHierarchy>, scopes: RecordScopeV2[], user: UserContext | SystemContext, customActionType?: string): boolean;
76
+ export declare function getAdministrativeAreaHierarchy(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, AdministrativeArea>): {
77
+ id: string & z.core.$brand<"UUID">;
78
+ name: string;
79
+ parentId: (string & z.core.$brand<"UUID">) | null;
80
+ validUntil: string | null;
81
+ externalId?: string | null | undefined;
82
+ }[];
83
+ /**
84
+ * Resolves a location or administrative area UUID into a root-first hierarchy of UUIDs.
85
+ *
86
+ * If the ID refers to a `Location` (e.g. CRVS office), the hierarchy includes
87
+ * the administrative area ancestors followed by the location itself.
88
+ * If the ID refers to an `AdministrativeArea`, returns the area's ancestor chain (root-first).
89
+ *
90
+ * Uses `getAdministrativeAreaHierarchy` which returns leaf-first order,
91
+ * so the result is reversed to match the root-first convention used by the server.
92
+ */
93
+ export declare function getLocationHierarchy(selectedId: UUID, context: {
94
+ administrativeAreas: Map<UUID, AdministrativeArea>;
95
+ locations: Map<UUID, Location>;
96
+ }): UUID[];
60
97
  export {};
61
98
  //# sourceMappingURL=locations.d.ts.map
@@ -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
  *
@@ -182,6 +182,10 @@ var scopeByEvent = z6.preprocess(
182
182
  (val) => val === void 0 ? void 0 : [val].flat(),
183
183
  z6.array(z6.string()).optional()
184
184
  ).describe("Event type, e.g. birth, death");
185
+ var userRole = z6.preprocess(
186
+ (val) => val === void 0 ? void 0 : [val].flat(),
187
+ z6.array(z6.string()).optional()
188
+ ).describe("User role, e.g. admin, field agent");
185
189
  var scopeOptionsPlaceEvent = z6.object({
186
190
  event: scopeByEvent,
187
191
  placeOfEvent: JurisdictionFilter.optional()
@@ -205,6 +209,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
205
209
  var AccessLevelOptions = z6.object({
206
210
  accessLevel: JurisdictionFilter.optional()
207
211
  });
212
+ var AllUserScopeOptions = AccessLevelOptions.extend({
213
+ role: userRole.optional()
214
+ });
208
215
  var WorkqueueOrDashboardOptions = z6.object({
209
216
  ids: z6.preprocess(
210
217
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -214,6 +221,7 @@ var WorkqueueOrDashboardOptions = z6.object({
214
221
  var AllScopeOptions = z6.object({
215
222
  ...AllRecordScopeOptions.shape,
216
223
  ...AccessLevelOptions.shape,
224
+ ...AllUserScopeOptions.shape,
217
225
  ...WorkqueueOrDashboardOptions.shape
218
226
  });
219
227
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -286,6 +294,30 @@ var RecordScopeV2 = z6.discriminatedUnion("type", [
286
294
  ]).describe(
287
295
  "Scopes used to check user's permission to perform actions on a record."
288
296
  );
297
+ var SystemScopeType = z6.enum([
298
+ "organisation.read-locations",
299
+ "user.read",
300
+ "user.create",
301
+ "user.edit",
302
+ "user.search"
303
+ ]);
304
+ var UserScopeType = SystemScopeType.extract([
305
+ "user.read",
306
+ "user.create",
307
+ "user.edit",
308
+ "user.search"
309
+ ]);
310
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
311
+ var UserScopeV2 = z6.discriminatedUnion("type", [
312
+ z6.object({
313
+ type: ScopesWithRoleOption,
314
+ options: AllUserScopeOptions.optional()
315
+ }),
316
+ z6.object({
317
+ type: UserScopeType.extract(["user.read", "user.search"]),
318
+ options: AccessLevelOptions.optional()
319
+ })
320
+ ]);
289
321
  var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
290
322
  z6.object({
291
323
  type: ScopesWithPlaceEventOptions,
@@ -306,16 +338,14 @@ var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
306
338
  }).optional()
307
339
  })
308
340
  ]).describe("Resolved scope with location/user IDs instead of filters.");
309
- var SystemScopeType = z6.enum([
310
- "organisation.read-locations",
311
- "user.read",
312
- "user.create",
313
- "user.edit"
314
- ]);
315
341
  var Scope2 = z6.discriminatedUnion("type", [
316
342
  z6.object({ type: PlainScopeType }),
317
343
  ...RecordScopeV2.options,
318
- z6.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
344
+ ...UserScopeV2.options,
345
+ z6.object({
346
+ type: z6.literal("organisation.read-locations"),
347
+ options: AccessLevelOptions.optional()
348
+ }),
319
349
  z6.object({
320
350
  type: z6.literal("workqueue"),
321
351
  options: WorkqueueOrDashboardOptions
@@ -243,6 +243,8 @@ __export(events_exports, {
243
243
  areConditionsMet: () => areConditionsMet,
244
244
  buildFormState: () => buildFormState,
245
245
  canAccessEventWithScope: () => canAccessEventWithScope,
246
+ canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
247
+ canAccessUserWithScope: () => canAccessUserWithScope,
246
248
  compositeFieldTypes: () => compositeFieldTypes,
247
249
  createEmptyDraft: () => createEmptyDraft,
248
250
  createFieldConditionals: () => createFieldConditionals,
@@ -300,12 +302,13 @@ __export(events_exports, {
300
302
  getActionConfig: () => getActionConfig,
301
303
  getActionReview: () => getActionReview,
302
304
  getActionReviewFields: () => getActionReviewFields,
305
+ getAdministrativeAreaHierarchy: () => getAdministrativeAreaHierarchy,
303
306
  getAllUniqueFields: () => getAllUniqueFields,
304
307
  getAnnotationFromDrafts: () => getAnnotationFromDrafts,
305
308
  getAssignedUserFromActions: () => getAssignedUserFromActions,
306
- getAssignedUserSignatureFromActions: () => getAssignedUserSignatureFromActions,
307
309
  getAssignmentStatus: () => getAssignmentStatus,
308
310
  getAvailableActionsForEvent: () => getAvailableActionsForEvent,
311
+ getAvailableRolesForUserUpdatePayload: () => getAvailableRolesForUserUpdatePayload,
309
312
  getCompleteActionAnnotation: () => getCompleteActionAnnotation,
310
313
  getCompleteActionDeclaration: () => getCompleteActionDeclaration,
311
314
  getCurrentEventState: () => getCurrentEventState,
@@ -316,6 +319,7 @@ __export(events_exports, {
316
319
  getDeclarationPages: () => getDeclarationPages,
317
320
  getEventConfigById: () => getEventConfigById,
318
321
  getFilePathsFromEvent: () => getFilePathsFromEvent,
322
+ getLocationHierarchy: () => getLocationHierarchy,
319
323
  getMixedPath: () => getMixedPath,
320
324
  getPendingAction: () => getPendingAction,
321
325
  getPrintCertificatePages: () => getPrintCertificatePages,
@@ -489,6 +493,10 @@ var scopeByEvent = z2.preprocess(
489
493
  (val) => val === void 0 ? void 0 : [val].flat(),
490
494
  z2.array(z2.string()).optional()
491
495
  ).describe("Event type, e.g. birth, death");
496
+ var userRole = z2.preprocess(
497
+ (val) => val === void 0 ? void 0 : [val].flat(),
498
+ z2.array(z2.string()).optional()
499
+ ).describe("User role, e.g. admin, field agent");
492
500
  var scopeOptionsPlaceEvent = z2.object({
493
501
  event: scopeByEvent,
494
502
  placeOfEvent: JurisdictionFilter.optional()
@@ -512,6 +520,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
512
520
  var AccessLevelOptions = z2.object({
513
521
  accessLevel: JurisdictionFilter.optional()
514
522
  });
523
+ var AllUserScopeOptions = AccessLevelOptions.extend({
524
+ role: userRole.optional()
525
+ });
515
526
  var WorkqueueOrDashboardOptions = z2.object({
516
527
  ids: z2.preprocess(
517
528
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -521,6 +532,7 @@ var WorkqueueOrDashboardOptions = z2.object({
521
532
  var AllScopeOptions = z2.object({
522
533
  ...AllRecordScopeOptions.shape,
523
534
  ...AccessLevelOptions.shape,
535
+ ...AllUserScopeOptions.shape,
524
536
  ...WorkqueueOrDashboardOptions.shape
525
537
  });
526
538
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -593,6 +605,33 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
593
605
  ]).describe(
594
606
  "Scopes used to check user's permission to perform actions on a record."
595
607
  );
608
+ var SystemScopeType = z2.enum([
609
+ "organisation.read-locations",
610
+ "user.read",
611
+ "user.create",
612
+ "user.edit",
613
+ "user.search"
614
+ ]);
615
+ var UserScopeType = SystemScopeType.extract([
616
+ "user.read",
617
+ "user.create",
618
+ "user.edit",
619
+ "user.search"
620
+ ]);
621
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
622
+ var UserScopeV2 = z2.discriminatedUnion("type", [
623
+ z2.object({
624
+ type: ScopesWithRoleOption,
625
+ options: AllUserScopeOptions.optional()
626
+ }),
627
+ z2.object({
628
+ type: UserScopeType.extract(["user.read", "user.search"]),
629
+ options: AccessLevelOptions.optional()
630
+ })
631
+ ]);
632
+ function scopeUsesRoleOptions(scope) {
633
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
634
+ }
596
635
  function scopeUsesDeclaredOptions(scope) {
597
636
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
598
637
  }
@@ -625,16 +664,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
625
664
  }).optional()
626
665
  })
627
666
  ]).describe("Resolved scope with location/user IDs instead of filters.");
628
- var SystemScopeType = z2.enum([
629
- "organisation.read-locations",
630
- "user.read",
631
- "user.create",
632
- "user.edit"
633
- ]);
634
667
  var Scope = z2.discriminatedUnion("type", [
635
668
  z2.object({ type: PlainScopeType }),
636
669
  ...RecordScopeV2.options,
637
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
670
+ ...UserScopeV2.options,
671
+ z2.object({
672
+ type: z2.literal("organisation.read-locations"),
673
+ options: AccessLevelOptions.optional()
674
+ }),
638
675
  z2.object({
639
676
  type: z2.literal("workqueue"),
640
677
  options: WorkqueueOrDashboardOptions
@@ -1376,28 +1413,20 @@ function schemaPriority(schema) {
1376
1413
  return idx === -1 ? 9999 : idx;
1377
1414
  }
1378
1415
  function safeUnion(schemas) {
1416
+ const sortedSchemas = [...schemas].sort(
1417
+ (a, b) => schemaPriority(a) - schemaPriority(b)
1418
+ );
1379
1419
  return z12.any().superRefine((val, ctx) => {
1380
- const successful = schemas.filter((s) => s.safeParse(val).success);
1381
- if (successful.length === 1) {
1382
- return;
1383
- }
1384
- if (successful.length === 0) {
1385
- ctx.addIssue({
1386
- code: "invalid_type",
1387
- expected: "custom",
1388
- message: "Value does not match any schema"
1389
- });
1390
- return;
1391
- }
1392
- successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
1393
- const best = successful[0];
1394
- if (!best.safeParse(val).success) {
1395
- ctx.addIssue({
1396
- expected: "custom",
1397
- code: "invalid_type",
1398
- message: "Value did not match the best schema"
1399
- });
1420
+ for (const schema of sortedSchemas) {
1421
+ if (schema.safeParse(val).success) {
1422
+ return;
1423
+ }
1400
1424
  }
1425
+ ctx.addIssue({
1426
+ code: "invalid_type",
1427
+ expected: "custom",
1428
+ message: "Value does not match any schema"
1429
+ });
1401
1430
  }).meta({
1402
1431
  description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
1403
1432
  });
@@ -1735,8 +1764,7 @@ var ActionCreationMetadata = z16.object({
1735
1764
  ),
1736
1765
  createdByUserType: z16.enum(["user", "system"]).nullish().describe("Whether the user is a normal user or a system."),
1737
1766
  acceptedAt: z16.iso.datetime().describe("Timestamp when the action request was accepted."),
1738
- createdByRole: z16.string().optional().describe("Role of the user at the time of action request creation."),
1739
- 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.")
1740
1768
  });
1741
1769
  var RegistrationCreationMetadata = ActionCreationMetadata.extend({
1742
1770
  registrationNumber: z16.string().describe(
@@ -1764,9 +1792,6 @@ var EventMetadata = z16.object({
1764
1792
  createdAtLocation: UUID.nullish().describe(
1765
1793
  "Location of the user who created the event."
1766
1794
  ),
1767
- createdBySignature: DocumentPath.nullish().describe(
1768
- "Signature of the user who created the event."
1769
- ),
1770
1795
  updatedAtLocation: UUID.nullish().describe(
1771
1796
  "Location of the user who last changed the status."
1772
1797
  ),
@@ -3766,6 +3791,9 @@ function precompileActionSchemas(eventConfigurations) {
3766
3791
  function isAgeValue(value) {
3767
3792
  return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
3768
3793
  }
3794
+ function mergeWithBaseFormState(values, context) {
3795
+ return { ...context.baseFormState, ...values };
3796
+ }
3769
3797
  function validate(schema, data) {
3770
3798
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3771
3799
  if ("$form" in data) {
@@ -3804,7 +3832,7 @@ function isOnline() {
3804
3832
  }
3805
3833
  function isConditionMet(conditional, values, context, eventIndex) {
3806
3834
  return validate(conditional, {
3807
- $form: values,
3835
+ $form: mergeWithBaseFormState(values, context),
3808
3836
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3809
3837
  $online: isOnline(),
3810
3838
  $user: context.user,
@@ -3833,7 +3861,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3833
3861
  return true;
3834
3862
  }
3835
3863
  const validConditionals = getConditionalActionsForField(field3, {
3836
- $form: form,
3864
+ $form: mergeWithBaseFormState(form, context),
3837
3865
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3838
3866
  $online: isOnline(),
3839
3867
  $user: context.user,
@@ -4025,7 +4053,7 @@ function runFieldValidations({
4025
4053
  return [];
4026
4054
  }
4027
4055
  const conditionalParameters = {
4028
- $form: form,
4056
+ $form: mergeWithBaseFormState(form, context),
4029
4057
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4030
4058
  /**
4031
4059
  * In real use cases, there can be hundreds of thousands of locations.
@@ -4269,17 +4297,16 @@ function isPageVisible(page, formValues, context) {
4269
4297
  }
4270
4298
  return isConditionMet(page.conditional, formValues, context);
4271
4299
  }
4272
- function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false, declarationContext) {
4300
+ function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false) {
4273
4301
  const base = (0, import_lodash.cloneDeep)(formValues);
4274
4302
  function fn(prevVisibilityContext) {
4275
- const visibilityForm = declarationContext ? { ...declarationContext, ...prevVisibilityContext } : prevVisibilityContext;
4276
4303
  const cleaned = (0, import_lodash.omitBy)(base, (value, fieldId) => {
4277
4304
  const fieldConfig = fields.filter((f) => f.id === fieldId);
4278
4305
  if (!fieldConfig.length) {
4279
4306
  return false;
4280
4307
  }
4281
4308
  const isHidden = fieldConfig.every(
4282
- (f) => !isFieldVisible(f, visibilityForm, validatorContext)
4309
+ (f) => !isFieldVisible(f, prevVisibilityContext, validatorContext)
4283
4310
  );
4284
4311
  if (!isHidden) {
4285
4312
  return false;
@@ -4297,7 +4324,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
4297
4324
  const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4298
4325
  const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4299
4326
  const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
4300
- return hiddenFields.some((f) => f.id === fieldId);
4327
+ return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
4301
4328
  });
4302
4329
  return omitHiddenFields(
4303
4330
  visibleFields,
@@ -4344,13 +4371,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
4344
4371
  }
4345
4372
  function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
4346
4373
  const annotationFields = getActionAnnotationFields(actionConfig);
4347
- return omitHiddenFields(
4348
- annotationFields,
4349
- annotation,
4350
- context,
4351
- false,
4352
- declaration
4353
- );
4374
+ return omitHiddenFields(annotationFields, annotation, {
4375
+ ...context,
4376
+ baseFormState: declaration
4377
+ });
4354
4378
  }
4355
4379
  function deepMerge(currentDocument, actionDocument) {
4356
4380
  const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
@@ -5862,6 +5886,9 @@ var BaseActionInput = z38.object({
5862
5886
  originalActionId: UUID.optional(),
5863
5887
  // should not be part of base action.
5864
5888
  keepAssignment: z38.boolean().optional(),
5889
+ keepAssignmentIfAccepted: z38.boolean().optional(),
5890
+ keepAssignmentIfRejected: z38.boolean().optional(),
5891
+ waitFor: z38.boolean().optional(),
5865
5892
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5866
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.
5867
5894
  createdAtLocation: UUID.nullish().describe(
@@ -6115,7 +6142,6 @@ function getDeclarationActionCreationMetadata(actionType, actions) {
6115
6142
  createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
6116
6143
  acceptedAt: acceptAction.createdAt,
6117
6144
  createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
6118
- createdBySignature: requestAction?.createdBySignature ?? acceptAction.createdBySignature,
6119
6145
  registrationNumber
6120
6146
  };
6121
6147
  }
@@ -6329,17 +6355,6 @@ function getAssignedUserFromActions(actions) {
6329
6355
  return user2;
6330
6356
  }, null);
6331
6357
  }
6332
- function getAssignedUserSignatureFromActions(actions) {
6333
- return actions.reduce((signature, action) => {
6334
- if (action.type === ActionType.ASSIGN) {
6335
- return action.createdBySignature || null;
6336
- }
6337
- if (action.type === ActionType.UNASSIGN) {
6338
- return null;
6339
- }
6340
- return signature;
6341
- }, null);
6342
- }
6343
6358
  function deepDropNulls(obj) {
6344
6359
  if (Array.isArray(obj)) {
6345
6360
  return obj.map(deepDropNulls);
@@ -6435,10 +6450,8 @@ function getCurrentEventState(event2, config) {
6435
6450
  createdBy: creationAction.createdBy,
6436
6451
  createdByUserType: creationAction.createdByUserType,
6437
6452
  createdAtLocation: creationAction.createdAtLocation,
6438
- createdBySignature: creationAction.createdBySignature,
6439
6453
  updatedAt: acceptedActionMetadata.createdAt,
6440
6454
  assignedTo: getAssignedUserFromActions(acceptedActions),
6441
- assignedToSignature: getAssignedUserSignatureFromActions(acceptedActions),
6442
6455
  updatedBy: requestActionMetadata.createdBy,
6443
6456
  updatedAtLocation: requestActionMetadata.createdAtLocation,
6444
6457
  declaration,
@@ -9697,7 +9710,6 @@ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
9697
9710
  createdBy: overrides.createdBy ?? generateUuid(rng),
9698
9711
  createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
9699
9712
  updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
9700
- createdBySignature: overrides.createdBySignature ?? generateRandomSignature(rng),
9701
9713
  updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
9702
9714
  assignedTo: overrides.assignedTo ?? null,
9703
9715
  updatedBy: overrides.updatedBy ?? generateUuid(rng),
@@ -9930,11 +9942,77 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9930
9942
  }
9931
9943
  return true;
9932
9944
  }
9945
+ function canAccessUserWithScope({
9946
+ userToAccess,
9947
+ scope,
9948
+ user: user2
9949
+ }) {
9950
+ const opts = scope.options;
9951
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
9952
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
9953
+ return false;
9954
+ }
9955
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
9956
+ (id) => user2.administrativeAreaId === id
9957
+ ) || user2.administrativeAreaId === null;
9958
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
9959
+ return false;
9960
+ }
9961
+ if (scopeUsesRoleOptions(scope)) {
9962
+ const { options } = scope;
9963
+ if (options?.role && !options.role.includes(userToAccess.role)) {
9964
+ return false;
9965
+ }
9966
+ }
9967
+ return true;
9968
+ }
9969
+ function canAccessOtherUserWithScopes({
9970
+ scopes,
9971
+ userToAccess,
9972
+ user: user2
9973
+ }) {
9974
+ return scopes.some(
9975
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
9976
+ );
9977
+ }
9933
9978
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
9934
9979
  return scopes.some(
9935
9980
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
9936
9981
  );
9937
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
+ }
9938
10016
 
9939
10017
  // ../commons/src/events/scopes.ts
9940
10018
  var ACTION_SCOPE_MAP = {
@@ -10009,6 +10087,25 @@ function isActionInScope({
10009
10087
  );
10010
10088
  return canAccess;
10011
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
+ }
10012
10109
 
10013
10110
  // ../commons/src/events/serializers/user/deserializer.ts
10014
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":"AA2aA,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"}