@opencrvs/toolkit 2.0.0-rc.22faee8 → 2.0.0-rc.23284a8

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 (90) 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 +63 -32
  4. package/dist/cli.js +1860 -346
  5. package/dist/commons/api/router.d.ts +3036 -292
  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/AuditLog.d.ts +2 -0
  11. package/dist/commons/events/Draft.d.ts +3 -0
  12. package/dist/commons/events/FieldConfig.d.ts +10 -0
  13. package/dist/commons/events/locations.d.ts +38 -1
  14. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  15. package/dist/commons/events/scopes.d.ts +24 -1
  16. package/dist/commons/events/utils.d.ts +1 -1
  17. package/dist/commons/notification/UserNotifications.d.ts +15 -0
  18. package/dist/conditionals/index.js +37 -7
  19. package/dist/events/index.js +173 -46
  20. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  21. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  22. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  23. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  24. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  25. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  26. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
  28. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  30. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  32. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  33. package/dist/migrations/v2.0/create-events-index.js +1 -2
  34. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
  35. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  36. package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
  37. package/dist/migrations/v2.0/index.d.ts +10 -4
  38. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/index.js +1828 -343
  40. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  42. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
  43. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  44. package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
  45. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  46. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  47. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  48. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/migrate-scopes.js +55 -32
  50. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  51. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  52. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  53. package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
  54. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  55. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  56. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  57. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  58. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  59. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  60. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  61. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  62. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  63. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  64. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  65. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  66. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  67. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  68. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  69. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  70. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  71. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  72. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  73. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  74. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  75. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  76. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  77. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  78. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  79. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  80. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  81. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  82. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  83. package/dist/migrations/v2.0/update-package-json.js +105 -0
  84. package/dist/notification/index.js +72 -32
  85. package/dist/scopes/index.d.ts +87 -10
  86. package/dist/scopes/index.js +43 -8
  87. package/opencrvs-toolkit-2.0.0-rc.23284a8.tgz +0 -0
  88. package/package.json +1 -1
  89. package/tsconfig.tsbuildinfo +1 -1
  90. package/opencrvs-toolkit-2.0.0-rc.22faee8.tgz +0 -0
@@ -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
@@ -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
  *
@@ -5,6 +5,7 @@ export declare const TriggerEvent: {
5
5
  readonly USERNAME_REMINDER: "username-reminder";
6
6
  readonly RESET_PASSWORD: "reset-password";
7
7
  readonly RESET_PASSWORD_BY_ADMIN: "reset-password-by-admin";
8
+ readonly RESEND_INVITE: "resend-invite";
8
9
  readonly TWO_FA: "2fa";
9
10
  readonly ALL_USER_NOTIFICATION: "all-user-notification";
10
11
  readonly CHANGE_PHONE_NUMBER: "change-phone-number";
@@ -112,6 +113,20 @@ export declare const TriggerPayload: {
112
113
  role: z.ZodString;
113
114
  }, z.core.$strip>;
114
115
  }, z.core.$strip>;
116
+ readonly "resend-invite": z.ZodObject<{
117
+ recipient: z.ZodObject<{
118
+ name: z.ZodOptional<z.ZodObject<{
119
+ firstname: z.ZodString;
120
+ surname: z.ZodString;
121
+ middlename: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strip>>;
123
+ mobile: z.ZodOptional<z.ZodString>;
124
+ email: z.ZodOptional<z.ZodString>;
125
+ bcc: z.ZodOptional<z.ZodArray<z.ZodString>>;
126
+ }, z.core.$strip>;
127
+ username: z.ZodString;
128
+ temporaryPassword: z.ZodString;
129
+ }, z.core.$strip>;
115
130
  readonly "2fa": z.ZodObject<{
116
131
  recipient: z.ZodObject<{
117
132
  name: z.ZodOptional<z.ZodObject<{
@@ -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,14 @@ __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
309
  getAssignedUserSignatureFromActions: () => getAssignedUserSignatureFromActions,
307
310
  getAssignmentStatus: () => getAssignmentStatus,
308
311
  getAvailableActionsForEvent: () => getAvailableActionsForEvent,
312
+ getAvailableRolesForUserUpdatePayload: () => getAvailableRolesForUserUpdatePayload,
309
313
  getCompleteActionAnnotation: () => getCompleteActionAnnotation,
310
314
  getCompleteActionDeclaration: () => getCompleteActionDeclaration,
311
315
  getCurrentEventState: () => getCurrentEventState,
@@ -316,6 +320,7 @@ __export(events_exports, {
316
320
  getDeclarationPages: () => getDeclarationPages,
317
321
  getEventConfigById: () => getEventConfigById,
318
322
  getFilePathsFromEvent: () => getFilePathsFromEvent,
323
+ getLocationHierarchy: () => getLocationHierarchy,
319
324
  getMixedPath: () => getMixedPath,
320
325
  getPendingAction: () => getPendingAction,
321
326
  getPrintCertificatePages: () => getPrintCertificatePages,
@@ -489,6 +494,10 @@ var scopeByEvent = z2.preprocess(
489
494
  (val) => val === void 0 ? void 0 : [val].flat(),
490
495
  z2.array(z2.string()).optional()
491
496
  ).describe("Event type, e.g. birth, death");
497
+ var userRole = z2.preprocess(
498
+ (val) => val === void 0 ? void 0 : [val].flat(),
499
+ z2.array(z2.string()).optional()
500
+ ).describe("User role, e.g. admin, field agent");
492
501
  var scopeOptionsPlaceEvent = z2.object({
493
502
  event: scopeByEvent,
494
503
  placeOfEvent: JurisdictionFilter.optional()
@@ -512,6 +521,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
512
521
  var AccessLevelOptions = z2.object({
513
522
  accessLevel: JurisdictionFilter.optional()
514
523
  });
524
+ var AllUserScopeOptions = AccessLevelOptions.extend({
525
+ role: userRole.optional()
526
+ });
515
527
  var WorkqueueOrDashboardOptions = z2.object({
516
528
  ids: z2.preprocess(
517
529
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -521,6 +533,7 @@ var WorkqueueOrDashboardOptions = z2.object({
521
533
  var AllScopeOptions = z2.object({
522
534
  ...AllRecordScopeOptions.shape,
523
535
  ...AccessLevelOptions.shape,
536
+ ...AllUserScopeOptions.shape,
524
537
  ...WorkqueueOrDashboardOptions.shape
525
538
  });
526
539
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -593,6 +606,33 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
593
606
  ]).describe(
594
607
  "Scopes used to check user's permission to perform actions on a record."
595
608
  );
609
+ var SystemScopeType = z2.enum([
610
+ "organisation.read-locations",
611
+ "user.read",
612
+ "user.create",
613
+ "user.edit",
614
+ "user.search"
615
+ ]);
616
+ var UserScopeType = SystemScopeType.extract([
617
+ "user.read",
618
+ "user.create",
619
+ "user.edit",
620
+ "user.search"
621
+ ]);
622
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
623
+ var UserScopeV2 = z2.discriminatedUnion("type", [
624
+ z2.object({
625
+ type: ScopesWithRoleOption,
626
+ options: AllUserScopeOptions.optional()
627
+ }),
628
+ z2.object({
629
+ type: UserScopeType.extract(["user.read", "user.search"]),
630
+ options: AccessLevelOptions.optional()
631
+ })
632
+ ]);
633
+ function scopeUsesRoleOptions(scope) {
634
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
635
+ }
596
636
  function scopeUsesDeclaredOptions(scope) {
597
637
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
598
638
  }
@@ -625,16 +665,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
625
665
  }).optional()
626
666
  })
627
667
  ]).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
668
  var Scope = z2.discriminatedUnion("type", [
635
669
  z2.object({ type: PlainScopeType }),
636
670
  ...RecordScopeV2.options,
637
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
671
+ ...UserScopeV2.options,
672
+ z2.object({
673
+ type: z2.literal("organisation.read-locations"),
674
+ options: AccessLevelOptions.optional()
675
+ }),
638
676
  z2.object({
639
677
  type: z2.literal("workqueue"),
640
678
  options: WorkqueueOrDashboardOptions
@@ -938,6 +976,7 @@ var UserSubjectOnlyEntrySchema = AuditLogEntryBase.extend({
938
976
  "user.password_changed",
939
977
  "user.password_reset",
940
978
  "user.password_reset_by_admin",
979
+ "user.resend_invite",
941
980
  "user.username_reminder",
942
981
  "user.username_reminder_by_admin"
943
982
  ]),
@@ -1039,7 +1078,10 @@ var ActionConditional = z7.discriminatedUnion("type", [
1039
1078
  ShowConditional,
1040
1079
  // Action can be shown to the user in the list but as disabled
1041
1080
  EnableConditional
1042
- ]);
1081
+ ]).meta({
1082
+ description: "Action conditional configuration",
1083
+ id: "ActionConditional"
1084
+ });
1043
1085
  var DisplayOnReviewConditional = z7.object({
1044
1086
  type: z7.literal(ConditionalType.DISPLAY_ON_REVIEW),
1045
1087
  conditional: Conditional
@@ -1375,28 +1417,20 @@ function schemaPriority(schema) {
1375
1417
  return idx === -1 ? 9999 : idx;
1376
1418
  }
1377
1419
  function safeUnion(schemas) {
1420
+ const sortedSchemas = [...schemas].sort(
1421
+ (a, b) => schemaPriority(a) - schemaPriority(b)
1422
+ );
1378
1423
  return z12.any().superRefine((val, ctx) => {
1379
- const successful = schemas.filter((s) => s.safeParse(val).success);
1380
- if (successful.length === 1) {
1381
- return;
1382
- }
1383
- if (successful.length === 0) {
1384
- ctx.addIssue({
1385
- code: "invalid_type",
1386
- expected: "custom",
1387
- message: "Value does not match any schema"
1388
- });
1389
- return;
1390
- }
1391
- successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
1392
- const best = successful[0];
1393
- if (!best.safeParse(val).success) {
1394
- ctx.addIssue({
1395
- expected: "custom",
1396
- code: "invalid_type",
1397
- message: "Value did not match the best schema"
1398
- });
1424
+ for (const schema of sortedSchemas) {
1425
+ if (schema.safeParse(val).success) {
1426
+ return;
1427
+ }
1399
1428
  }
1429
+ ctx.addIssue({
1430
+ code: "invalid_type",
1431
+ expected: "custom",
1432
+ message: "Value does not match any schema"
1433
+ });
1400
1434
  }).meta({
1401
1435
  description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
1402
1436
  });
@@ -1706,6 +1740,9 @@ var FlagConfig = z15.object({
1706
1740
  "Indicates if this flag expects an action to be performed to be cleared."
1707
1741
  ),
1708
1742
  label: TranslationConfig.describe("Human readable label of the flag.")
1743
+ }).meta({
1744
+ description: "Flag configuration",
1745
+ id: "FlagConfig"
1709
1746
  });
1710
1747
  var ActionFlagConfig = z15.object({
1711
1748
  id: Flag,
@@ -1713,6 +1750,9 @@ var ActionFlagConfig = z15.object({
1713
1750
  conditional: Conditional.optional().describe(
1714
1751
  "When conditional is met, the operation is performed on the flag. If not provided, the operation is performed unconditionally."
1715
1752
  )
1753
+ }).meta({
1754
+ description: "Action flag configuration",
1755
+ id: "ActionFlagConfig"
1716
1756
  });
1717
1757
 
1718
1758
  // ../commons/src/events/EventMetadata.ts
@@ -2853,10 +2893,10 @@ var VerificationPageConfig = FormPageConfig.extend({
2853
2893
  type: z21.literal(PageTypes.enum.VERIFICATION),
2854
2894
  actions: VerificationActionConfig
2855
2895
  });
2856
- var PageConfig = z21.discriminatedUnion("type", [
2857
- FormPageConfig,
2858
- VerificationPageConfig
2859
- ]);
2896
+ var PageConfig = z21.discriminatedUnion("type", [FormPageConfig, VerificationPageConfig]).meta({
2897
+ description: "Page configuration",
2898
+ id: "PageConfig"
2899
+ });
2860
2900
 
2861
2901
  // ../commons/src/events/FormConfig.ts
2862
2902
  var DeclarationFormConfig = z22.object({
@@ -3765,6 +3805,9 @@ function precompileActionSchemas(eventConfigurations) {
3765
3805
  function isAgeValue(value) {
3766
3806
  return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
3767
3807
  }
3808
+ function mergeWithBaseFormState(values, context) {
3809
+ return { ...context.baseFormState, ...values };
3810
+ }
3768
3811
  function validate(schema, data) {
3769
3812
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3770
3813
  if ("$form" in data) {
@@ -3803,7 +3846,7 @@ function isOnline() {
3803
3846
  }
3804
3847
  function isConditionMet(conditional, values, context, eventIndex) {
3805
3848
  return validate(conditional, {
3806
- $form: values,
3849
+ $form: mergeWithBaseFormState(values, context),
3807
3850
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3808
3851
  $online: isOnline(),
3809
3852
  $user: context.user,
@@ -3832,7 +3875,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3832
3875
  return true;
3833
3876
  }
3834
3877
  const validConditionals = getConditionalActionsForField(field3, {
3835
- $form: form,
3878
+ $form: mergeWithBaseFormState(form, context),
3836
3879
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3837
3880
  $online: isOnline(),
3838
3881
  $user: context.user,
@@ -4024,7 +4067,7 @@ function runFieldValidations({
4024
4067
  return [];
4025
4068
  }
4026
4069
  const conditionalParameters = {
4027
- $form: form,
4070
+ $form: mergeWithBaseFormState(form, context),
4028
4071
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4029
4072
  /**
4030
4073
  * In real use cases, there can be hundreds of thousands of locations.
@@ -4268,17 +4311,16 @@ function isPageVisible(page, formValues, context) {
4268
4311
  }
4269
4312
  return isConditionMet(page.conditional, formValues, context);
4270
4313
  }
4271
- function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false, declarationContext) {
4314
+ function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false) {
4272
4315
  const base = (0, import_lodash.cloneDeep)(formValues);
4273
4316
  function fn(prevVisibilityContext) {
4274
- const visibilityForm = declarationContext ? { ...declarationContext, ...prevVisibilityContext } : prevVisibilityContext;
4275
4317
  const cleaned = (0, import_lodash.omitBy)(base, (value, fieldId) => {
4276
4318
  const fieldConfig = fields.filter((f) => f.id === fieldId);
4277
4319
  if (!fieldConfig.length) {
4278
4320
  return false;
4279
4321
  }
4280
4322
  const isHidden = fieldConfig.every(
4281
- (f) => !isFieldVisible(f, visibilityForm, validatorContext)
4323
+ (f) => !isFieldVisible(f, prevVisibilityContext, validatorContext)
4282
4324
  );
4283
4325
  if (!isHidden) {
4284
4326
  return false;
@@ -4296,7 +4338,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
4296
4338
  const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4297
4339
  const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4298
4340
  const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
4299
- return hiddenFields.some((f) => f.id === fieldId);
4341
+ return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
4300
4342
  });
4301
4343
  return omitHiddenFields(
4302
4344
  visibleFields,
@@ -4343,13 +4385,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
4343
4385
  }
4344
4386
  function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
4345
4387
  const annotationFields = getActionAnnotationFields(actionConfig);
4346
- return omitHiddenFields(
4347
- annotationFields,
4348
- annotation,
4349
- context,
4350
- false,
4351
- declaration
4352
- );
4388
+ return omitHiddenFields(annotationFields, annotation, {
4389
+ ...context,
4390
+ baseFormState: declaration
4391
+ });
4353
4392
  }
4354
4393
  function deepMerge(currentDocument, actionDocument) {
4355
4394
  const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
@@ -5861,6 +5900,9 @@ var BaseActionInput = z38.object({
5861
5900
  originalActionId: UUID.optional(),
5862
5901
  // should not be part of base action.
5863
5902
  keepAssignment: z38.boolean().optional(),
5903
+ keepAssignmentIfAccepted: z38.boolean().optional(),
5904
+ keepAssignmentIfRejected: z38.boolean().optional(),
5905
+ waitFor: z38.boolean().optional(),
5864
5906
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5865
5907
  // @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
5866
5908
  createdAtLocation: UUID.nullish().describe(
@@ -9929,11 +9971,77 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9929
9971
  }
9930
9972
  return true;
9931
9973
  }
9974
+ function canAccessUserWithScope({
9975
+ userToAccess,
9976
+ scope,
9977
+ user: user2
9978
+ }) {
9979
+ const opts = scope.options;
9980
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
9981
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
9982
+ return false;
9983
+ }
9984
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
9985
+ (id) => user2.administrativeAreaId === id
9986
+ ) || user2.administrativeAreaId === null;
9987
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
9988
+ return false;
9989
+ }
9990
+ if (scopeUsesRoleOptions(scope)) {
9991
+ const { options } = scope;
9992
+ if (options?.role && !options.role.includes(userToAccess.role)) {
9993
+ return false;
9994
+ }
9995
+ }
9996
+ return true;
9997
+ }
9998
+ function canAccessOtherUserWithScopes({
9999
+ scopes,
10000
+ userToAccess,
10001
+ user: user2
10002
+ }) {
10003
+ return scopes.some(
10004
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
10005
+ );
10006
+ }
9932
10007
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
9933
10008
  return scopes.some(
9934
10009
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
9935
10010
  );
9936
10011
  }
10012
+ function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
10013
+ const collectedLocations = [];
10014
+ const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
10015
+ let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
10016
+ while (current) {
10017
+ collectedLocations.push(current);
10018
+ if (!current.parentId) {
10019
+ break;
10020
+ }
10021
+ const parentId = current.parentId;
10022
+ current = administrativeAreas.get(parentId);
10023
+ }
10024
+ return collectedLocations;
10025
+ }
10026
+ function getLocationHierarchy(selectedId, context) {
10027
+ const { administrativeAreas, locations } = context;
10028
+ const loc = locations.get(selectedId);
10029
+ if (loc) {
10030
+ if (loc.administrativeAreaId) {
10031
+ const hierarchy2 = getAdministrativeAreaHierarchy(
10032
+ loc.administrativeAreaId,
10033
+ administrativeAreas
10034
+ );
10035
+ return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10036
+ }
10037
+ return [loc.id];
10038
+ }
10039
+ const hierarchy = getAdministrativeAreaHierarchy(
10040
+ selectedId,
10041
+ administrativeAreas
10042
+ );
10043
+ return hierarchy.reverse().map((area) => area.id);
10044
+ }
9937
10045
 
9938
10046
  // ../commons/src/events/scopes.ts
9939
10047
  var ACTION_SCOPE_MAP = {
@@ -10008,6 +10116,25 @@ function isActionInScope({
10008
10116
  );
10009
10117
  return canAccess;
10010
10118
  }
10119
+ function getAvailableRolesForUserUpdatePayload({
10120
+ allRoles,
10121
+ userLocation,
10122
+ acceptedScopes,
10123
+ userRequesting
10124
+ }) {
10125
+ const availableRoles = allRoles.filter((role) => {
10126
+ const canAccess = canAccessOtherUserWithScopes({
10127
+ userToAccess: {
10128
+ ...userLocation,
10129
+ role
10130
+ },
10131
+ user: userRequesting,
10132
+ scopes: acceptedScopes
10133
+ });
10134
+ return canAccess;
10135
+ });
10136
+ return availableRoles;
10137
+ }
10011
10138
 
10012
10139
  // ../commons/src/events/serializers/user/deserializer.ts
10013
10140
  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"}