@opencrvs/toolkit 2.2.0-rc.30529dd → 2.2.0-rc.3de6f63

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 (48) hide show
  1. package/dist/application-config/index.js +1 -1
  2. package/dist/authentication/index.js +10 -2
  3. package/dist/cli.js +586 -303
  4. package/dist/commons/events/ActionConfig.d.ts +2 -2
  5. package/dist/commons/events/EventConfig.d.ts +1 -10
  6. package/dist/commons/events/eventConfigValidation.d.ts +1 -1
  7. package/dist/commons/events/index.d.ts +1 -0
  8. package/dist/commons/events/test.utils.d.ts +2 -3
  9. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  10. package/dist/commons/events/utils.d.ts +77 -56
  11. package/dist/environment/custom-types.d.ts +1 -0
  12. package/dist/environment/custom-types.d.ts.map +1 -1
  13. package/dist/environment/derived-variables.d.ts +6 -4
  14. package/dist/environment/derived-variables.d.ts.map +1 -1
  15. package/dist/environment/derived-variables.js +6 -4
  16. package/dist/environment/questions.d.ts +14 -2
  17. package/dist/environment/questions.d.ts.map +1 -1
  18. package/dist/environment/questions.js +39 -18
  19. package/dist/environment/registry.d.ts +15 -0
  20. package/dist/environment/registry.d.ts.map +1 -0
  21. package/dist/environment/registry.js +112 -0
  22. package/dist/environment/setup-environment.d.ts.map +1 -1
  23. package/dist/environment/setup-environment.js +76 -28
  24. package/dist/events/index.js +60 -97
  25. package/dist/migrations/add-notify-config.d.ts +40 -0
  26. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  27. package/dist/migrations/add-notify-config.js +249 -0
  28. package/dist/migrations/index.d.ts.map +1 -1
  29. package/dist/migrations/index.js +345 -143
  30. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  31. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  32. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  33. package/dist/migrations/read-declaration-through-helper.js +3 -61
  34. package/dist/migrations/utils.d.ts +61 -0
  35. package/dist/migrations/utils.d.ts.map +1 -0
  36. package/dist/migrations/utils.js +218 -0
  37. package/dist/notification/index.js +47 -75
  38. package/dist/scopes/index.d.ts +5 -2
  39. package/dist/scopes/index.js +10 -2
  40. package/dist/templates/charts-values/opencrvs-services/values.yaml +3 -4
  41. package/opencrvs-toolkit-2.2.0-rc.3de6f63.tgz +0 -0
  42. package/package.json +2 -1
  43. package/tsconfig.build.tsbuildinfo +1 -1
  44. package/dist/commons/events/notificationFormFallback.d.ts +0 -10
  45. package/dist/environment/dockerhub.d.ts +0 -15
  46. package/dist/environment/dockerhub.d.ts.map +0 -1
  47. package/dist/environment/dockerhub.js +0 -104
  48. package/opencrvs-toolkit-2.2.0-rc.30529dd.tgz +0 -0
@@ -999,7 +999,7 @@ var z14 = __toESM(require("zod/v4"));
999
999
  // ../commons/src/documents.ts
1000
1000
  var z11 = __toESM(require("zod/v4"));
1001
1001
  var FullDocumentUrl = z11.string().brand("FullDocumentUrl").describe(
1002
- "A full url with protocol, host, bucket name, starting from the root of the S3 server, https://minio.opencrvs.com/bucket-name/document-id.jpg"
1002
+ "A full url with protocol, host, bucket name, starting from the root of the S3 server, https://s3.opencrvs.com/bucket-name/document-id.jpg"
1003
1003
  );
1004
1004
  var FullDocumentPath = z11.string().overwrite((val) => val.startsWith("/") ? val : `/${val}`).meta({ effectType: "input", type: "string" }).describe(
1005
1005
  "A full absolute path with bucket name, starting from the root of the S3 server, /bucket-name/document-id.jpg"
@@ -2910,11 +2910,11 @@ var ReadActionConfig = ActionConfigBase.extend(
2910
2910
  var NotifyConfig = ActionConfigBase.extend(
2911
2911
  z25.object({
2912
2912
  type: z25.literal(ActionType.NOTIFY),
2913
- notificationForm: DeclarationFormConfig.optional().describe(
2914
- "Notification form configuration. Its fields must be a subset of the declaration form fields, with matching types. The values submitted on the notification form pre-fill the declaration. If not defined, the declare action's declaration is used (with all fields optional)."
2913
+ notificationForm: DeclarationFormConfig.describe(
2914
+ "Notification form configuration. Its fields must be a subset of the declaration form fields, with matching types. The values submitted on the notification form pre-fill the declaration."
2915
2915
  ),
2916
2916
  review: DeclarationReviewConfig.describe(
2917
- "Review page configuration for the notify action. Values of its fields are stored as the NOTIFY action annotation. If not defined, defineConfig generates it from the declare action's review (with all fields optional)."
2917
+ "Review page configuration for the notify action. Values of its fields are stored as the NOTIFY action annotation."
2918
2918
  ),
2919
2919
  form: actionConfirmationForm
2920
2920
  }).shape
@@ -4520,25 +4520,6 @@ function isOnline() {
4520
4520
  return true;
4521
4521
  }
4522
4522
 
4523
- // ../commons/src/events/notificationFormFallback.ts
4524
- function toOptionalField(field3) {
4525
- const { validation: _validation, ...rest } = field3;
4526
- if (rest.type === FieldType.FIELD_GROUP && "fields" in rest) {
4527
- return {
4528
- ...rest,
4529
- required: false,
4530
- fields: rest.fields.map(toOptionalField)
4531
- };
4532
- }
4533
- return { ...rest, required: false };
4534
- }
4535
- function generateNotifyReview(declareReview) {
4536
- return {
4537
- ...declareReview,
4538
- fields: declareReview.fields.map(toOptionalField)
4539
- };
4540
- }
4541
-
4542
4523
  // ../commons/src/events/utils.ts
4543
4524
  var import_date_fns3 = require("date-fns");
4544
4525
  function getDeclaration(configuration) {
@@ -4558,7 +4539,7 @@ function getDeclarationPages(configuration) {
4558
4539
  function getDeclarationFields(configuration) {
4559
4540
  return getDeclarationPages(configuration).flatMap(({ fields }) => fields);
4560
4541
  }
4561
- function getConfiguredNotificationForm(configuration) {
4542
+ function findNotificationForm(configuration) {
4562
4543
  const notifyAction = configuration.actions.find(
4563
4544
  (action) => action.type === ActionType.NOTIFY
4564
4545
  );
@@ -4581,10 +4562,7 @@ function getAllAnnotationFields(config) {
4581
4562
  var findAllFields = (config) => {
4582
4563
  return (0, import_lodash4.flattenDeep)([
4583
4564
  ...getDeclarationFields(config),
4584
- // Only a configured notification form: a derived one repeats the declaration fields.
4585
- ...getConfiguredNotificationForm(config)?.pages.flatMap(
4586
- ({ fields }) => fields
4587
- ) ?? [],
4565
+ ...findNotificationForm(config)?.pages.flatMap(({ fields }) => fields) ?? [],
4588
4566
  ...getAllAnnotationFields(config)
4589
4567
  ]);
4590
4568
  };
@@ -4814,9 +4792,11 @@ function validateDeclarationGivenExactlyOnce(config, ctx) {
4814
4792
  }
4815
4793
  }
4816
4794
  function validateNotificationForm(event2, ctx) {
4817
- const declarationFields = getDeclarationFields(event2);
4795
+ const declarationFields = getDeclarationPages(event2).flatMap(
4796
+ (page) => page.fields.map((field3) => ({ field: field3, pageId: page.id }))
4797
+ );
4818
4798
  event2.actions.forEach((action, actionIndex) => {
4819
- if (action.type !== ActionType.NOTIFY || !action.notificationForm) {
4799
+ if (action.type !== ActionType.NOTIFY) {
4820
4800
  return;
4821
4801
  }
4822
4802
  action.notificationForm.pages.forEach((page, pageIndex) => {
@@ -4831,7 +4811,7 @@ function validateNotificationForm(event2, ctx) {
4831
4811
  fieldIndex
4832
4812
  ];
4833
4813
  const matchingFields = declarationFields.filter(
4834
- ({ id }) => id === field3.id
4814
+ (declarationField) => declarationField.field.id === field3.id
4835
4815
  );
4836
4816
  if (matchingFields.length === 0) {
4837
4817
  ctx.addIssue({
@@ -4841,10 +4821,13 @@ function validateNotificationForm(event2, ctx) {
4841
4821
  });
4842
4822
  return;
4843
4823
  }
4844
- if (!matchingFields.some(({ type }) => type === field3.type)) {
4824
+ if (!matchingFields.some(
4825
+ (declarationField) => declarationField.field.type === field3.type
4826
+ )) {
4827
+ const [declarationField] = matchingFields;
4845
4828
  ctx.addIssue({
4846
4829
  code: "custom",
4847
- message: `Notification form field '${field3.id}' is of type ${field3.type}, but the declaration form field with the same id in event '${event2.id}' is of type ${matchingFields[0].type}.`,
4830
+ message: `Notification form field '${field3.id}' on page '${page.id}' is of type ${field3.type}, but the declaration form field with the same id in event '${event2.id}' (${ActionType.DECLARE} declaration, page '${declarationField.pageId}') is of type ${declarationField.field.type}.`,
4848
4831
  path
4849
4832
  });
4850
4833
  }
@@ -5562,57 +5545,44 @@ function moveDeclarationToDeclareAction({
5562
5545
  )
5563
5546
  };
5564
5547
  }
5565
- function generateNotificationFormFallback(config) {
5566
- const declareAction = config.actions.find(
5567
- (action) => action.type === ActionType.DECLARE
5568
- );
5569
- const notifyAction = config.actions.find(
5570
- (action) => action.type === ActionType.NOTIFY
5571
- );
5572
- if (!notifyAction?.notificationForm) {
5573
- console.warn(
5574
- `Event '${config.id}' has no ${ActionType.NOTIFY} form. Using the ${ActionType.DECLARE} form with all fields optional. Configure \`actions[${ActionType.NOTIFY}].notificationForm\`. This fallback will be removed in a future release.`
5575
- );
5576
- }
5577
- if (notifyAction?.review) {
5578
- return config;
5579
- }
5580
- if (!declareAction?.declaration) {
5581
- throw new Error(
5582
- `Event '${config.id}' has no ${ActionType.DECLARE} form. Configure \`actions[${ActionType.DECLARE}].declaration\`.`
5583
- );
5548
+ var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5549
+ if (validateExactlyOneDeclareAction(config, ctx)) {
5550
+ validateDeclarationGivenExactlyOnce(config, ctx);
5584
5551
  }
5585
- const review = generateNotifyReview(declareAction.review);
5586
- if (notifyAction) {
5552
+ }).transform(moveDeclarationToDeclareAction).pipe(EventConfig);
5553
+ var defineConfig = (config) => EventConfigDefinition.parse(config);
5554
+
5555
+ // ../commons/src/events/toNotificationForm.ts
5556
+ function toOptionalField(field3) {
5557
+ const { validation: _validation, ...rest } = field3;
5558
+ if (rest.type === FieldType.FIELD_GROUP && "fields" in rest) {
5587
5559
  return {
5588
- ...config,
5589
- actions: config.actions.map(
5590
- (action) => action === notifyAction ? { ...notifyAction, review } : action
5591
- )
5560
+ ...rest,
5561
+ required: false,
5562
+ fields: rest.fields.map(toOptionalField)
5592
5563
  };
5593
5564
  }
5594
- const notifyFromDeclare = {
5595
- type: ActionType.NOTIFY,
5596
- label: declareAction.label,
5597
- icon: declareAction.icon,
5598
- conditionals: declareAction.conditionals,
5599
- flags: declareAction.flags,
5600
- supportingCopy: declareAction.dialogCopy?.notify,
5601
- review
5565
+ return { ...rest, required: false };
5566
+ }
5567
+ function toNotificationForm(declaration) {
5568
+ return {
5569
+ ...declaration,
5570
+ pages: declaration.pages.map((page) => ({
5571
+ ...page,
5572
+ fields: page.fields.map(
5573
+ toOptionalField
5574
+ )
5575
+ }))
5602
5576
  };
5577
+ }
5578
+ function toNotificationReview(review) {
5603
5579
  return {
5604
- ...config,
5605
- actions: config.actions.flatMap(
5606
- (action) => action === declareAction ? [notifyFromDeclare, action] : [action]
5580
+ ...review,
5581
+ fields: review.fields.map(
5582
+ toOptionalField
5607
5583
  )
5608
5584
  };
5609
5585
  }
5610
- var EventConfigDefinition = z43.custom().superRefine((config, ctx) => {
5611
- if (validateExactlyOneDeclareAction(config, ctx)) {
5612
- validateDeclarationGivenExactlyOnce(config, ctx);
5613
- }
5614
- }).transform(moveDeclarationToDeclareAction).transform(generateNotificationFormFallback).pipe(EventConfig);
5615
- var defineConfig = (config) => EventConfigDefinition.parse(config);
5616
5586
 
5617
5587
  // ../commons/src/events/test.utils.ts
5618
5588
  var import_lodash5 = require("lodash");
@@ -6921,6 +6891,8 @@ var tennisClubMembershipEvent = defineConfig({
6921
6891
  description: "This is shown as the action name anywhere the user can trigger the action from",
6922
6892
  id: "event.tennis-club-membership.action.notify.label"
6923
6893
  },
6894
+ notificationForm: toNotificationForm(TENNIS_CLUB_DECLARATION_FORM),
6895
+ review: toNotificationReview(TENNIS_CLUB_DECLARATION_REVIEW),
6924
6896
  flags: [
6925
6897
  {
6926
6898
  id: "health-worker-notified",
@@ -1382,13 +1382,16 @@ export declare function hasScope(token: string, scope: ScopeType): boolean;
1382
1382
  */
1383
1383
  export declare function hasScope(scopes: EncodedScope[], scope: ScopeType): boolean;
1384
1384
  /**
1385
- * Checks if the given event type is allowed by the accepted scopes. If no specific event types are defined, it returns true.
1385
+ * Checks if the user has the scope to perform an action on an event of a certain type.
1386
1386
  *
1387
1387
  * @param {Scope[]} userScopes - The scopes of the user.
1388
1388
  * @param {string} eventType - The event type to check for permission.
1389
- * @returns {boolean} Returns true if the event type is allowed by the scope.
1389
+ * @param {ScopeType[]} acceptedScopes - The scopes to check for permission.
1390
+ * @returns {boolean} Returns true if the user has the scope to perform an action on an event of a certain type.
1390
1391
  */
1392
+ export declare function hasScopeForEventType(userScopes: EncodedScope[], eventType: string, acceptedScope: ScopeType): boolean;
1391
1393
  export declare function canUserCreateEvent(userScopes: EncodedScope[], eventType: string): boolean;
1394
+ export declare function canUserNotifyEvent(userScopes: EncodedScope[], eventType: string): boolean;
1392
1395
  /**
1393
1396
  * Helper for defining scopes for user roles. Should be used in country config.
1394
1397
  *
@@ -45,6 +45,7 @@ __export(scopes_exports, {
45
45
  UserFilter: () => UserFilter,
46
46
  UserScopeV2: () => UserScopeV2,
47
47
  canUserCreateEvent: () => canUserCreateEvent,
48
+ canUserNotifyEvent: () => canUserNotifyEvent,
48
49
  decodeScope: () => decodeScope,
49
50
  defineRoles: () => defineRoles,
50
51
  defineScopes: () => defineScopes,
@@ -53,6 +54,7 @@ __export(scopes_exports, {
53
54
  getScopeOptionValue: () => getScopeOptionValue,
54
55
  hasAnyScope: () => hasAnyScope,
55
56
  hasScope: () => hasScope,
57
+ hasScopeForEventType: () => hasScopeForEventType,
56
58
  isCustomActionScope: () => isCustomActionScope,
57
59
  scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
58
60
  scopeUsesFullOptions: () => scopeUsesFullOptions,
@@ -714,9 +716,9 @@ function hasScope(tokenOrScopes, scope) {
714
716
  }
715
717
  return hasAnyScope(tokenOrScopes, [scope]);
716
718
  }
717
- function canUserCreateEvent(userScopes, eventType) {
719
+ function hasScopeForEventType(userScopes, eventType, acceptedScope) {
718
720
  const scopes = getAcceptedScopesByType({
719
- acceptedScopes: ["record.create"],
721
+ acceptedScopes: [acceptedScope],
720
722
  scopes: userScopes
721
723
  });
722
724
  return scopes.some((scope) => {
@@ -726,6 +728,12 @@ function canUserCreateEvent(userScopes, eventType) {
726
728
  return scope.options?.event?.includes(eventType);
727
729
  });
728
730
  }
731
+ function canUserCreateEvent(userScopes, eventType) {
732
+ return hasScopeForEventType(userScopes, eventType, "record.create");
733
+ }
734
+ function canUserNotifyEvent(userScopes, eventType) {
735
+ return hasScopeForEventType(userScopes, eventType, "record.notify");
736
+ }
729
737
  function defineScopes(scopes) {
730
738
  return scopes.map((scope) => Scope2.parse(scope)).map(encodeScope);
731
739
  }
@@ -27,7 +27,7 @@ hpa:
27
27
  enabled: false
28
28
 
29
29
  env:
30
- MINIO_BUCKET: ocrvs
30
+ S3_BUCKET: ocrvs
31
31
  OPENCRVS_ENVIRONMENT: {{opencrvs_environment}}
32
32
 
33
33
  otel:
@@ -39,8 +39,7 @@ elasticsearch:
39
39
  auth_mode: auto
40
40
  host: elasticsearch.opencrvs-deps-{{env}}.svc.cluster.local
41
41
 
42
- minio:
43
- auth_mode: use_secret
42
+ s3:
44
43
  host: minio-0.minio.opencrvs-deps-{{env}}.svc.cluster.local
45
44
 
46
45
  redis:
@@ -54,7 +53,7 @@ postgres:
54
53
  platform:
55
54
  imagePullSecrets:
56
55
  # Default value for credentials created while yarn environment:init
57
- - name: dockerhub-credentials
56
+ - name: registry-credentials
58
57
 
59
58
  auth:
60
59
  env:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.2.0-rc.30529dd",
3
+ "version": "2.2.0-rc.3de6f63",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {
@@ -22,6 +22,7 @@
22
22
  "build": "./build.sh",
23
23
  "build:all": "pnpm -w exec lerna run build --include-dependencies --scope @opencrvs/toolkit",
24
24
  "test": "vitest run",
25
+ "test:watch": "vitest",
25
26
  "test:compilation": "tsc --noEmit"
26
27
  },
27
28
  "repository": {