@opencrvs/toolkit 2.0.0-rc.fef9d21 → 2.0.0-rc.ff04b30

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 (52) 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 +68 -39
  4. package/dist/cli.js +539 -175
  5. package/dist/commons/api/router.d.ts +3334 -271
  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/WorkqueueConfig.d.ts +146 -146
  15. package/dist/commons/events/locations.d.ts +38 -1
  16. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  17. package/dist/commons/events/scopes.d.ts +24 -1
  18. package/dist/commons/events/state/index.d.ts +0 -4
  19. package/dist/commons/events/state/utils.d.ts +0 -2
  20. package/dist/commons/events/utils.d.ts +1 -1
  21. package/dist/conditionals/index.js +40 -8
  22. package/dist/events/index.js +184 -83
  23. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  24. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +60 -35
  25. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  26. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
  28. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
  29. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
  30. package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
  31. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
  32. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
  33. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
  34. package/dist/migrations/v2.0/index.d.ts +5 -3
  35. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  36. package/dist/migrations/v2.0/index.js +537 -173
  37. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  38. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
  39. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
  40. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
  42. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/migrate-scopes.js +54 -30
  44. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
  46. package/dist/notification/index.js +78 -53
  47. package/dist/scopes/index.d.ts +87 -10
  48. package/dist/scopes/index.js +46 -9
  49. package/opencrvs-toolkit-2.0.0-rc.ff04b30.tgz +0 -0
  50. package/package.json +1 -1
  51. package/tsconfig.tsbuildinfo +1 -1
  52. package/opencrvs-toolkit-2.0.0-rc.fef9d21.tgz +0 -0
@@ -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
@@ -667,7 +704,9 @@ var decodeScope = (query) => {
667
704
  };
668
705
  var DEFAULT_SCOPE_OPTIONS = {
669
706
  placeOfEvent: JurisdictionFilter.enum.all,
670
- accessLevel: JurisdictionFilter.enum.all
707
+ accessLevel: JurisdictionFilter.enum.all,
708
+ registeredIn: JurisdictionFilter.enum.all,
709
+ declaredIn: JurisdictionFilter.enum.all
671
710
  };
672
711
  function getAcceptedScopesByType({
673
712
  acceptedScopes,
@@ -1040,7 +1079,10 @@ var ActionConditional = z7.discriminatedUnion("type", [
1040
1079
  ShowConditional,
1041
1080
  // Action can be shown to the user in the list but as disabled
1042
1081
  EnableConditional
1043
- ]);
1082
+ ]).meta({
1083
+ description: "Action conditional configuration",
1084
+ id: "ActionConditional"
1085
+ });
1044
1086
  var DisplayOnReviewConditional = z7.object({
1045
1087
  type: z7.literal(ConditionalType.DISPLAY_ON_REVIEW),
1046
1088
  conditional: Conditional
@@ -1376,28 +1418,20 @@ function schemaPriority(schema) {
1376
1418
  return idx === -1 ? 9999 : idx;
1377
1419
  }
1378
1420
  function safeUnion(schemas) {
1421
+ const sortedSchemas = [...schemas].sort(
1422
+ (a, b) => schemaPriority(a) - schemaPriority(b)
1423
+ );
1379
1424
  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
- });
1425
+ for (const schema of sortedSchemas) {
1426
+ if (schema.safeParse(val).success) {
1427
+ return;
1428
+ }
1400
1429
  }
1430
+ ctx.addIssue({
1431
+ code: "invalid_type",
1432
+ expected: "custom",
1433
+ message: "Value does not match any schema"
1434
+ });
1401
1435
  }).meta({
1402
1436
  description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
1403
1437
  });
@@ -1707,6 +1741,9 @@ var FlagConfig = z15.object({
1707
1741
  "Indicates if this flag expects an action to be performed to be cleared."
1708
1742
  ),
1709
1743
  label: TranslationConfig.describe("Human readable label of the flag.")
1744
+ }).meta({
1745
+ description: "Flag configuration",
1746
+ id: "FlagConfig"
1710
1747
  });
1711
1748
  var ActionFlagConfig = z15.object({
1712
1749
  id: Flag,
@@ -1714,6 +1751,9 @@ var ActionFlagConfig = z15.object({
1714
1751
  conditional: Conditional.optional().describe(
1715
1752
  "When conditional is met, the operation is performed on the flag. If not provided, the operation is performed unconditionally."
1716
1753
  )
1754
+ }).meta({
1755
+ description: "Action flag configuration",
1756
+ id: "ActionFlagConfig"
1717
1757
  });
1718
1758
 
1719
1759
  // ../commons/src/events/EventMetadata.ts
@@ -1735,8 +1775,7 @@ var ActionCreationMetadata = z16.object({
1735
1775
  ),
1736
1776
  createdByUserType: z16.enum(["user", "system"]).nullish().describe("Whether the user is a normal user or a system."),
1737
1777
  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.")
1778
+ createdByRole: z16.string().optional().describe("Role of the user at the time of action request creation.")
1740
1779
  });
1741
1780
  var RegistrationCreationMetadata = ActionCreationMetadata.extend({
1742
1781
  registrationNumber: z16.string().describe(
@@ -1764,9 +1803,6 @@ var EventMetadata = z16.object({
1764
1803
  createdAtLocation: UUID.nullish().describe(
1765
1804
  "Location of the user who created the event."
1766
1805
  ),
1767
- createdBySignature: DocumentPath.nullish().describe(
1768
- "Signature of the user who created the event."
1769
- ),
1770
1806
  updatedAtLocation: UUID.nullish().describe(
1771
1807
  "Location of the user who last changed the status."
1772
1808
  ),
@@ -2141,7 +2177,7 @@ var FieldId = import_v43.default.string().superRefine((val, ctx) => {
2141
2177
  }
2142
2178
  }).describe("Unique identifier for the field");
2143
2179
  var FieldReference = import_v43.default.object({
2144
- $$field: FieldId,
2180
+ $$field: FieldId.describe("Id of the field to reference"),
2145
2181
  $$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
2146
2182
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
2147
2183
  )
@@ -2854,10 +2890,10 @@ var VerificationPageConfig = FormPageConfig.extend({
2854
2890
  type: z21.literal(PageTypes.enum.VERIFICATION),
2855
2891
  actions: VerificationActionConfig
2856
2892
  });
2857
- var PageConfig = z21.discriminatedUnion("type", [
2858
- FormPageConfig,
2859
- VerificationPageConfig
2860
- ]);
2893
+ var PageConfig = z21.discriminatedUnion("type", [FormPageConfig, VerificationPageConfig]).meta({
2894
+ description: "Page configuration",
2895
+ id: "PageConfig"
2896
+ });
2861
2897
 
2862
2898
  // ../commons/src/events/FormConfig.ts
2863
2899
  var DeclarationFormConfig = z22.object({
@@ -3766,6 +3802,9 @@ function precompileActionSchemas(eventConfigurations) {
3766
3802
  function isAgeValue(value) {
3767
3803
  return typeof value === "object" && value !== null && "age" in value && typeof value.age === "number";
3768
3804
  }
3805
+ function mergeWithBaseFormState(values, context) {
3806
+ return { ...context.baseFormState, ...values };
3807
+ }
3769
3808
  function validate(schema, data) {
3770
3809
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3771
3810
  if ("$form" in data) {
@@ -3804,7 +3843,7 @@ function isOnline() {
3804
3843
  }
3805
3844
  function isConditionMet(conditional, values, context, eventIndex) {
3806
3845
  return validate(conditional, {
3807
- $form: values,
3846
+ $form: mergeWithBaseFormState(values, context),
3808
3847
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3809
3848
  $online: isOnline(),
3810
3849
  $user: context.user,
@@ -3833,7 +3872,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3833
3872
  return true;
3834
3873
  }
3835
3874
  const validConditionals = getConditionalActionsForField(field3, {
3836
- $form: form,
3875
+ $form: mergeWithBaseFormState(form, context),
3837
3876
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3838
3877
  $online: isOnline(),
3839
3878
  $user: context.user,
@@ -4025,7 +4064,7 @@ function runFieldValidations({
4025
4064
  return [];
4026
4065
  }
4027
4066
  const conditionalParameters = {
4028
- $form: form,
4067
+ $form: mergeWithBaseFormState(form, context),
4029
4068
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4030
4069
  /**
4031
4070
  * In real use cases, there can be hundreds of thousands of locations.
@@ -4269,17 +4308,16 @@ function isPageVisible(page, formValues, context) {
4269
4308
  }
4270
4309
  return isConditionMet(page.conditional, formValues, context);
4271
4310
  }
4272
- function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false, declarationContext) {
4311
+ function omitHiddenFields(fields, formValues, validatorContext, includeHiddenFieldsWithNullValues = false) {
4273
4312
  const base = (0, import_lodash.cloneDeep)(formValues);
4274
4313
  function fn(prevVisibilityContext) {
4275
- const visibilityForm = declarationContext ? { ...declarationContext, ...prevVisibilityContext } : prevVisibilityContext;
4276
4314
  const cleaned = (0, import_lodash.omitBy)(base, (value, fieldId) => {
4277
4315
  const fieldConfig = fields.filter((f) => f.id === fieldId);
4278
4316
  if (!fieldConfig.length) {
4279
4317
  return false;
4280
4318
  }
4281
4319
  const isHidden = fieldConfig.every(
4282
- (f) => !isFieldVisible(f, visibilityForm, validatorContext)
4320
+ (f) => !isFieldVisible(f, prevVisibilityContext, validatorContext)
4283
4321
  );
4284
4322
  if (!isHidden) {
4285
4323
  return false;
@@ -4297,7 +4335,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
4297
4335
  const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4298
4336
  const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
4299
4337
  const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
4300
- return hiddenFields.some((f) => f.id === fieldId);
4338
+ return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
4301
4339
  });
4302
4340
  return omitHiddenFields(
4303
4341
  visibleFields,
@@ -4344,13 +4382,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
4344
4382
  }
4345
4383
  function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
4346
4384
  const annotationFields = getActionAnnotationFields(actionConfig);
4347
- return omitHiddenFields(
4348
- annotationFields,
4349
- annotation,
4350
- context,
4351
- false,
4352
- declaration
4353
- );
4385
+ return omitHiddenFields(annotationFields, annotation, {
4386
+ ...context,
4387
+ baseFormState: declaration
4388
+ });
4354
4389
  }
4355
4390
  function deepMerge(currentDocument, actionDocument) {
4356
4391
  const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
@@ -5339,7 +5374,7 @@ var _EventConfigBase = z33.object({
5339
5374
  ),
5340
5375
  label: TranslationConfig.describe("Human-readable label for the event type."),
5341
5376
  actions: z33.array(ActionConfig).describe(
5342
- "Configuration of system-defined actions associated with the event."
5377
+ "Configuration of core and custom actions associated with the event."
5343
5378
  ),
5344
5379
  actionOrder: z33.array(z33.string()).optional().describe(
5345
5380
  "Order of actions in the action menu. Use either the action type for core actions or the customActionType for custom actions."
@@ -5351,7 +5386,7 @@ var _EventConfigBase = z33.object({
5351
5386
  "Configuration of fields available in the advanced search feature."
5352
5387
  ),
5353
5388
  flags: z33.array(FlagConfig).optional().default([]).describe(
5354
- "Configuration of flags associated with the actions of this event type."
5389
+ "Configuration of custom flags associated with the actions of this event type."
5355
5390
  ),
5356
5391
  analytics: z33.boolean().optional().default(true).describe(
5357
5392
  "Indicates whether the records of this event type are included in analytics"
@@ -5790,18 +5825,11 @@ var WorkqueueConfigWithoutQuery = WorkqueueConfig.omit({
5790
5825
  query: true,
5791
5826
  columns: true
5792
5827
  });
5793
- var WorkqueueConfigInput = z37.object({
5794
- slug: z37.string().describe("Determines the url of the workqueue."),
5795
- name: TranslationConfig.describe(
5796
- "Title of the workflow (both in navigation and on the page)"
5797
- ),
5798
- query: CountryConfigQueryInputType,
5799
- action: z37.object({ type: WorkqueueActionType }).optional().describe(
5800
- "Workqueue call-to-action button configuration. This determines the quick action button shown on each event card and the action taken when the button is clicked."
5801
- ),
5802
- columns: z37.array(WorkqueueColumn).default(mandatoryColumns),
5803
- icon: AvailableIcons,
5804
- emptyMessage: TranslationConfig.optional()
5828
+ var WorkqueueConfigInput = WorkqueueConfig.extend({
5829
+ query: CountryConfigQueryInputType
5830
+ }).meta({
5831
+ description: "Workqueue configuration",
5832
+ id: "WorkqueueConfig"
5805
5833
  });
5806
5834
  function defineWorkqueue(workqueueInput) {
5807
5835
  const queryInput = workqueueInput.query;
@@ -5862,6 +5890,9 @@ var BaseActionInput = z38.object({
5862
5890
  originalActionId: UUID.optional(),
5863
5891
  // should not be part of base action.
5864
5892
  keepAssignment: z38.boolean().optional(),
5893
+ keepAssignmentIfAccepted: z38.boolean().optional(),
5894
+ keepAssignmentIfRejected: z38.boolean().optional(),
5895
+ waitFor: z38.boolean().optional(),
5865
5896
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5866
5897
  // @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
5898
  createdAtLocation: UUID.nullish().describe(
@@ -6115,7 +6146,6 @@ function getDeclarationActionCreationMetadata(actionType, actions) {
6115
6146
  createdAtLocation: requestAction?.createdAtLocation ?? acceptAction.createdAtLocation,
6116
6147
  acceptedAt: acceptAction.createdAt,
6117
6148
  createdByRole: requestAction?.createdByRole ?? acceptAction.createdByRole,
6118
- createdBySignature: requestAction?.createdBySignature ?? acceptAction.createdBySignature,
6119
6149
  registrationNumber
6120
6150
  };
6121
6151
  }
@@ -6329,17 +6359,6 @@ function getAssignedUserFromActions(actions) {
6329
6359
  return user2;
6330
6360
  }, null);
6331
6361
  }
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
6362
  function deepDropNulls(obj) {
6344
6363
  if (Array.isArray(obj)) {
6345
6364
  return obj.map(deepDropNulls);
@@ -6435,10 +6454,8 @@ function getCurrentEventState(event2, config) {
6435
6454
  createdBy: creationAction.createdBy,
6436
6455
  createdByUserType: creationAction.createdByUserType,
6437
6456
  createdAtLocation: creationAction.createdAtLocation,
6438
- createdBySignature: creationAction.createdBySignature,
6439
6457
  updatedAt: acceptedActionMetadata.createdAt,
6440
6458
  assignedTo: getAssignedUserFromActions(acceptedActions),
6441
- assignedToSignature: getAssignedUserSignatureFromActions(acceptedActions),
6442
6459
  updatedBy: requestActionMetadata.createdBy,
6443
6460
  updatedAtLocation: requestActionMetadata.createdAtLocation,
6444
6461
  declaration,
@@ -9697,7 +9714,6 @@ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
9697
9714
  createdBy: overrides.createdBy ?? generateUuid(rng),
9698
9715
  createdAtLocation: overrides.createdAtLocation ?? generateUuid(rng),
9699
9716
  updatedAtLocation: overrides.updatedAtLocation ?? generateUuid(rng),
9700
- createdBySignature: overrides.createdBySignature ?? generateRandomSignature(rng),
9701
9717
  updatedAt: overrides.updatedAt ?? (0, import_date_fns4.addDays)(new Date(createdAt), 1).toISOString(),
9702
9718
  assignedTo: overrides.assignedTo ?? null,
9703
9719
  updatedBy: overrides.updatedBy ?? generateUuid(rng),
@@ -9930,11 +9946,77 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9930
9946
  }
9931
9947
  return true;
9932
9948
  }
9949
+ function canAccessUserWithScope({
9950
+ userToAccess,
9951
+ scope,
9952
+ user: user2
9953
+ }) {
9954
+ const opts = scope.options;
9955
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
9956
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
9957
+ return false;
9958
+ }
9959
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
9960
+ (id) => user2.administrativeAreaId === id
9961
+ ) || user2.administrativeAreaId === null;
9962
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
9963
+ return false;
9964
+ }
9965
+ if (scopeUsesRoleOptions(scope)) {
9966
+ const { options } = scope;
9967
+ if (options?.role && !options.role.includes(userToAccess.role)) {
9968
+ return false;
9969
+ }
9970
+ }
9971
+ return true;
9972
+ }
9973
+ function canAccessOtherUserWithScopes({
9974
+ scopes,
9975
+ userToAccess,
9976
+ user: user2
9977
+ }) {
9978
+ return scopes.some(
9979
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
9980
+ );
9981
+ }
9933
9982
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
9934
9983
  return scopes.some(
9935
9984
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
9936
9985
  );
9937
9986
  }
9987
+ function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
9988
+ const collectedLocations = [];
9989
+ const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
9990
+ let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
9991
+ while (current) {
9992
+ collectedLocations.push(current);
9993
+ if (!current.parentId) {
9994
+ break;
9995
+ }
9996
+ const parentId = current.parentId;
9997
+ current = administrativeAreas.get(parentId);
9998
+ }
9999
+ return collectedLocations;
10000
+ }
10001
+ function getLocationHierarchy(selectedId, context) {
10002
+ const { administrativeAreas, locations } = context;
10003
+ const loc = locations.get(selectedId);
10004
+ if (loc) {
10005
+ if (loc.administrativeAreaId) {
10006
+ const hierarchy2 = getAdministrativeAreaHierarchy(
10007
+ loc.administrativeAreaId,
10008
+ administrativeAreas
10009
+ );
10010
+ return [...hierarchy2.reverse().map((area) => area.id), loc.id];
10011
+ }
10012
+ return [loc.id];
10013
+ }
10014
+ const hierarchy = getAdministrativeAreaHierarchy(
10015
+ selectedId,
10016
+ administrativeAreas
10017
+ );
10018
+ return hierarchy.reverse().map((area) => area.id);
10019
+ }
9938
10020
 
9939
10021
  // ../commons/src/events/scopes.ts
9940
10022
  var ACTION_SCOPE_MAP = {
@@ -10009,6 +10091,25 @@ function isActionInScope({
10009
10091
  );
10010
10092
  return canAccess;
10011
10093
  }
10094
+ function getAvailableRolesForUserUpdatePayload({
10095
+ allRoles,
10096
+ userLocation,
10097
+ acceptedScopes,
10098
+ userRequesting
10099
+ }) {
10100
+ const availableRoles = allRoles.filter((role) => {
10101
+ const canAccess = canAccessOtherUserWithScopes({
10102
+ userToAccess: {
10103
+ ...userLocation,
10104
+ role
10105
+ },
10106
+ user: userRequesting,
10107
+ scopes: acceptedScopes
10108
+ });
10109
+ return canAccess;
10110
+ });
10111
+ return availableRoles;
10112
+ }
10012
10113
 
10013
10114
  // ../commons/src/events/serializers/user/deserializer.ts
10014
10115
  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"}