@opencrvs/toolkit 2.1.0-rc.5617d8e → 2.1.0-rc.562608b

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 (129) hide show
  1. package/README.md +3 -12
  2. package/build.sh +12 -4
  3. package/create-countryconfig/index.js +441 -59
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +4 -1
  6. package/dist/application-config/index.js +362 -284
  7. package/dist/authentication/index.d.ts +66 -0
  8. package/dist/authentication/index.d.ts.map +1 -0
  9. package/dist/authentication/index.js +765 -0
  10. package/dist/cli.js +3347 -1229
  11. package/dist/commons/api/router.d.ts +761 -151
  12. package/dist/commons/application-config/index.d.ts +0 -2
  13. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  14. package/dist/commons/conditionals/validate.d.ts +34 -8
  15. package/dist/commons/events/ActionConfig.d.ts +5 -14
  16. package/dist/commons/events/ActionDocument.d.ts +35 -15
  17. package/dist/commons/events/ActionInput.d.ts +4 -4
  18. package/dist/commons/events/ActionStatus.d.ts +14 -0
  19. package/dist/commons/events/AdvancedSearchConfig.d.ts +48 -12
  20. package/dist/commons/events/AuditLog.d.ts +148 -0
  21. package/dist/commons/events/Draft.d.ts +1 -21
  22. package/dist/commons/events/EventConfig.d.ts +3 -0
  23. package/dist/commons/events/EventDocument.d.ts +472 -4
  24. package/dist/commons/events/EventIndex.d.ts +3 -26
  25. package/dist/commons/events/EventMetadata.d.ts +1 -11
  26. package/dist/commons/events/EventStatus.d.ts +19 -0
  27. package/dist/commons/events/FieldConfig.d.ts +109 -63
  28. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  29. package/dist/commons/events/FieldValue.d.ts +3 -2
  30. package/dist/commons/events/Flag.d.ts +42 -0
  31. package/dist/commons/events/FormConfig.d.ts +6 -0
  32. package/dist/commons/events/PageConfig.d.ts +4 -0
  33. package/dist/commons/events/PlainDate.d.ts +8 -0
  34. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  35. package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
  36. package/dist/commons/events/event.d.ts +12 -0
  37. package/dist/commons/events/index.d.ts +1 -0
  38. package/dist/commons/events/locationPayloads.d.ts +95 -0
  39. package/dist/commons/events/locations.d.ts +169 -29
  40. package/dist/commons/events/mocks.test.utils.d.ts +30 -2
  41. package/dist/commons/events/scopes.d.ts +21 -1
  42. package/dist/commons/events/test.utils.d.ts +78 -20
  43. package/dist/commons/events/utils.d.ts +34 -4
  44. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  45. package/dist/commons/notification/dispatch.d.ts +10 -0
  46. package/dist/commons/notification/index.d.ts +1 -0
  47. package/dist/conditionals/index.js +349 -65
  48. package/dist/csv.d.ts +25 -0
  49. package/dist/csv.d.ts.map +1 -0
  50. package/dist/csv.js +120 -0
  51. package/dist/environment/index.d.ts +1 -0
  52. package/dist/environment/index.d.ts.map +1 -1
  53. package/dist/environment/index.js +12 -1
  54. package/dist/environment/logger.d.ts +15 -3
  55. package/dist/environment/logger.d.ts.map +1 -1
  56. package/dist/environment/manage-users.js +1 -1
  57. package/dist/environment/paths.d.ts +7 -0
  58. package/dist/environment/paths.d.ts.map +1 -0
  59. package/dist/environment/paths.js +72 -0
  60. package/dist/environment/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +20 -14
  62. package/dist/environment/setup-environment.d.ts +1 -1
  63. package/dist/environment/setup-environment.d.ts.map +1 -1
  64. package/dist/environment/setup-environment.js +587 -562
  65. package/dist/environment/templates.d.ts +0 -1
  66. package/dist/environment/templates.d.ts.map +1 -1
  67. package/dist/environment/templates.js +5 -9
  68. package/dist/environment/update-workflows.d.ts.map +1 -1
  69. package/dist/environment/update-workflows.js +21 -5
  70. package/dist/environment/upgrade.d.ts +2 -0
  71. package/dist/environment/upgrade.d.ts.map +1 -0
  72. package/dist/environment/upgrade.js +82 -0
  73. package/dist/environment/users.js +11 -13
  74. package/dist/environment/utils.d.ts +0 -12
  75. package/dist/environment/utils.d.ts.map +1 -1
  76. package/dist/environment/utils.js +1 -28
  77. package/dist/events/index.js +7182 -6611
  78. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  79. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  80. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  81. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  82. package/dist/migrations/v2.0/convert-config-files-to-ts.js +3 -10
  83. package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
  84. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  85. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  86. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  87. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  88. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  89. package/dist/migrations/v2.1/add-translations.js +149 -0
  90. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  91. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  92. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  93. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  94. package/dist/migrations/v2.1/index.js +1556 -0
  95. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  96. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  97. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  98. package/dist/migrations/v2.1/remove-sentry.d.ts +3 -0
  99. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  100. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  101. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +3 -0
  102. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  103. package/dist/migrations/v2.1/rename-trigger-paths.js +216 -0
  104. package/dist/notification/index.js +1862 -1448
  105. package/dist/scopes/index.d.ts +614 -36
  106. package/dist/scopes/index.js +351 -65
  107. package/dist/telemetry/index.d.ts +45 -0
  108. package/dist/telemetry/index.d.ts.map +1 -0
  109. package/dist/telemetry/index.js +43 -0
  110. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  111. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  112. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  113. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  114. package/dist/templates/inventory/inventory.template.yml +1 -3
  115. package/dist/translations/template.d.ts +11 -0
  116. package/dist/translations/template.d.ts.map +1 -0
  117. package/dist/translations/template.js +100 -0
  118. package/dist/verify/endpoints.d.ts +2 -0
  119. package/dist/verify/endpoints.d.ts.map +1 -0
  120. package/dist/verify/endpoints.js +510 -0
  121. package/opencrvs-toolkit-2.1.0-rc.562608b.tgz +0 -0
  122. package/package.json +13 -6
  123. package/tsconfig.build.json +11 -0
  124. package/tsconfig.build.tsbuildinfo +1 -0
  125. package/tsconfig.json +3 -0
  126. package/dist/templates/inventory/production.example.yml +0 -77
  127. package/dist/templates/inventory/qa.example.yml +0 -48
  128. package/opencrvs-toolkit-2.1.0-rc.5617d8e.tgz +0 -0
  129. package/tsconfig.tsbuildinfo +0 -1
@@ -1,5 +1,5 @@
1
- export declare const UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
2
- export declare const UPSTREAM_BRANCH = "release/2.0.0";
1
+ export declare const UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-farajaland.git";
2
+ export declare const UPSTREAM_BRANCH = "release/v2.0.0";
3
3
  /**
4
4
  * Runs a git command in the country config working directory.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,2DACiC,CAAA;AAE1D,eAAO,MAAM,eAAe,kBAAkB,CAAA;AAc9C;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAO9C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAID,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"checkout-upstream-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/checkout-upstream-files.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,wDAC8B,CAAA;AAEvD,eAAO,MAAM,eAAe,mBAAmB,CAAA;AAc/C;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,MAAc,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAO9C;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAID,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAuDnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -58,8 +58,8 @@ exports.main = main;
58
58
  * - Requires the country config working directory to be a git repo.
59
59
  */
60
60
  const child_process_1 = require("child_process");
61
- exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
62
- exports.UPSTREAM_BRANCH = 'release/2.0.0';
61
+ exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-farajaland.git';
62
+ exports.UPSTREAM_BRANCH = 'release/v2.0.0';
63
63
  // Remote name used only for the duration of this codemod. Prefixed to avoid
64
64
  // clashing with remotes the user may have (origin, upstream, etc.).
65
65
  const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
@@ -1 +1 @@
1
- {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAuuBA,wBAAsB,IAAI,kBAyPzB"}
1
+ {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAiuBA,wBAAsB,IAAI,kBAyPzB"}
@@ -101,7 +101,6 @@ const path_1 = __importDefault(require("path"));
101
101
  const CLIENT_VALID_KEYS = new Set([
102
102
  'COUNTRY',
103
103
  'LANGUAGES',
104
- 'SENTRY',
105
104
  'REGISTER_BACKGROUND',
106
105
  'DASHBOARDS',
107
106
  'FEATURES'
@@ -112,8 +111,7 @@ const LOGIN_VALID_KEYS = new Set([
112
111
  'USER_NOTIFICATION_DELIVERY_METHOD',
113
112
  'INFORMANT_NOTIFICATION_DELIVERY_METHOD',
114
113
  'PHONE_NUMBER_PATTERN',
115
- 'LOGIN_BACKGROUND',
116
- 'SENTRY'
114
+ 'LOGIN_BACKGROUND'
117
115
  ]);
118
116
  // Keys defined in ApplicationConfig from packages/commons/src/application-config.ts
119
117
  const APPLICATION_CONFIG_VALID_KEYS = new Set([
@@ -316,14 +314,13 @@ function transformDashboardsValue(init, isProd) {
316
314
  *
317
315
  * Prod files (isProd = true):
318
316
  * - Import `env` from './environment'
319
- * - Define `scheme = 'https'`, `hostname = env.DOMAIN`, `sentry = env.SENTRY_DSN`
320
- * - Use `sentry` for the SENTRY property
317
+ * - Define `scheme = 'https'`, `hostname = env.DOMAIN`
321
318
  * - Rewrite DASHBOARDS[].url origins to use scheme/hostname template expressions
322
319
  *
323
320
  * Dev files (isProd = false):
324
321
  * - No env import
325
322
  * - Define `scheme = 'http'`, `hostname = 'localhost'`
326
- * - Keep SENTRY and DASHBOARDS URLs as-is from the original JS file
323
+ * - Keep DASHBOARDS URLs as-is from the original JS file
327
324
  */
328
325
  function generateTsContent(configObj, exportName, group, isProd) {
329
326
  var _a;
@@ -347,9 +344,6 @@ function generateTsContent(configObj, exportName, group, isProd) {
347
344
  if (name === 'LANGUAGES') {
348
345
  propertyLines.push(` LANGUAGES: ${convertLanguages(init)}`);
349
346
  }
350
- else if (name === 'SENTRY' && isProd) {
351
- propertyLines.push(` SENTRY: sentry`);
352
- }
353
347
  else if (name === 'DASHBOARDS') {
354
348
  propertyLines.push(` DASHBOARDS: ${transformDashboardsValue(init, isProd)}`);
355
349
  }
@@ -383,7 +377,6 @@ function generateTsContent(configObj, exportName, group, isProd) {
383
377
  if (isProd) {
384
378
  headerLines.push(`const scheme = 'https'`);
385
379
  headerLines.push(`const hostname = env.DOMAIN`);
386
- headerLines.push(`const sentry = env.SENTRY_DSN`);
387
380
  }
388
381
  else {
389
382
  headerLines.push(`const scheme = 'http'`);
@@ -56,7 +56,7 @@ exports.main = main;
56
56
  * so `git merge-base HEAD upstream/develop` typically returns nothing.
57
57
  * - With no merge-base, a 3-way merge degenerates to a 2-way diff against
58
58
  * an empty file — every line that differs becomes a conflict.
59
- * - `release-v1.9` is the latest 1.9.x release line on upstream and is a
59
+ * - `release/1.9.15` is the latest 1.9.x release on upstream and is a
60
60
  * near-perfect representation of "what `infrastructure/` looked like
61
61
  * before v2.0", regardless of whether the fork's git history reaches it.
62
62
  * - For files the country config never modified relative to that baseline,
@@ -81,7 +81,7 @@ exports.main = main;
81
81
  * sides changed a binary file, the result will be invalid and a warning
82
82
  * is printed.
83
83
  * - Forks that are on a much older 1.9.x and never merged later 1.9 patches
84
- * may see a few extra conflicts on files where 1.9.x → release-v1.9
84
+ * may see a few extra conflicts on files where 1.9.x → release/1.9.15
85
85
  * patches and v1.9 → v2.0 changes textually overlap.
86
86
  */
87
87
  const child_process_1 = require("child_process");
@@ -97,7 +97,7 @@ const INFRASTRUCTURE_DIR = 'infrastructure';
97
97
  // Synthetic merge-base: the tip of upstream's latest 1.9.x release line.
98
98
  // We use this branch's content as the "common ancestor" for every file,
99
99
  // since most country forks don't share git history with upstream.
100
- const BASE_BRANCH = 'release-v1.9';
100
+ const BASE_BRANCH = 'release/1.9.15';
101
101
  /**
102
102
  * Reads `git show <ref>:<path>` as a Uint8Array (binary-safe).
103
103
  * Returns `null` if the path doesn't exist at that ref.
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=add-recovery-link-notifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-recovery-link-notifications.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/add-recovery-link-notifications.ts"],"names":[],"mappings":"AAopBA,iBAAe,IAAI,kBA0ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,511 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ /**
27
+ * Codemod: Register the two v2.1 account-recovery notifications,
28
+ * `password-reset-link` and `username-reminder-link`.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.1/add-recovery-link-notifications.ts
32
+ *
33
+ * Why:
34
+ * v2.1 replaces the 6-digit code exchanged over `/api/auth/verifyUser` with
35
+ * an emailed single-use recovery link, so that endpoint no longer reveals
36
+ * whether an account exists. Core now dispatches two new `TriggerEvent`s to
37
+ * the country config. Because they are members of `TriggerEvent`, every
38
+ * `Record<TriggerEvent, ...>` / `[T in TriggerEvent]` map in a v2.0 country
39
+ * config stops compiling until it handles them, and until the routes exist
40
+ * the recovery email is never sent (core logs the 404 and moves on).
41
+ *
42
+ * What it does, skipping anything already present:
43
+ * - `src/api/notification/email-templates/index.ts`: adds the two variable
44
+ * schemas to `TriggerVariable` and the two entries to `templates`
45
+ * - `src/api/notification/sms-service.ts`: adds the two SMS template names
46
+ * to `otherTemplates` and the two mappings to `TriggerToSMSTemplate`
47
+ * - `src/api/notification/handler.ts`: adds the two cases to the
48
+ * `convertPayloadToVariable` switch, building the recovery URL from the
49
+ * token in the payload
50
+ * - `src/config/routes/userNotificationRoutes.ts`: adds the two
51
+ * `POST /trigger/user/*` routes core posts to
52
+ * - `src/api/notification/email-templates/other/*.html`: writes the two
53
+ * email bodies
54
+ * - `src/translations/notification.csv`: adds the two SMS messages
55
+ * - `src/translations/login.csv`: adds the login messages for the screens
56
+ * that wait on the emailed link
57
+ *
58
+ * Caveats:
59
+ * - Country configs that renamed or restructured these files keep their own
60
+ * structure; each step warns and is skipped rather than guessing. The
61
+ * warning lists what still has to be wired by hand.
62
+ */
63
+ const ts_morph_1 = require("ts-morph");
64
+ const fs_1 = require("fs");
65
+ const path_1 = __importDefault(require("path"));
66
+ const csv_1 = require("../../csv");
67
+ const EMAIL_TEMPLATES_FILE = 'src/api/notification/email-templates/index.ts';
68
+ const SMS_SERVICE_FILE = 'src/api/notification/sms-service.ts';
69
+ const HANDLER_FILE = 'src/api/notification/handler.ts';
70
+ const ROUTES_FILE = 'src/config/routes/userNotificationRoutes.ts';
71
+ const EMAIL_TEMPLATE_DIR = 'src/api/notification/email-templates/other';
72
+ const NOTIFICATION_CSV = 'src/translations/notification.csv';
73
+ const LOGIN_CSV = 'src/translations/login.csv';
74
+ const TRIGGER_VARIABLE_OBJECT = 'TriggerVariable';
75
+ const TEMPLATES_OBJECT = 'templates';
76
+ const OTHER_TEMPLATES_OBJECT = 'otherTemplates';
77
+ const TRIGGER_TO_SMS_TEMPLATE_OBJECT = 'TriggerToSMSTemplate';
78
+ const CONVERT_PAYLOAD_FUNCTION = 'convertPayloadToVariable';
79
+ const ROUTES_FUNCTION = 'getUserNotificationRoutes';
80
+ const RECOVERY_EVENTS = [
81
+ {
82
+ id: 'password-reset-link',
83
+ constant: 'PASSWORD_RESET_LINK',
84
+ smsTemplate: 'resetPasswordLinkNotification',
85
+ emailSubject: 'Reset your password',
86
+ routeDescription: 'Handles notification for password reset recovery link',
87
+ heading: 'Reset your password',
88
+ reason: 'Someone asked to reset the password for your {{applicationName}}\n account.',
89
+ linkLabel: 'Reset your password'
90
+ },
91
+ {
92
+ id: 'username-reminder-link',
93
+ constant: 'USERNAME_REMINDER_LINK',
94
+ smsTemplate: 'retrieveUsernameLinkNotification',
95
+ emailSubject: 'Retrieve your username',
96
+ routeDescription: 'Handles notification for username reminder recovery link',
97
+ heading: 'Retrieve your username',
98
+ reason: 'Someone asked for a reminder of the username for your\n {{applicationName}} account.',
99
+ linkLabel: 'Retrieve your username'
100
+ }
101
+ ];
102
+ const NOTIFICATION_CSV_ROWS = [
103
+ `resetPasswordLinkNotification,The SMS message that is sent to a user containing a self-service password reset link,{{applicationName}}: reset your password using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : réinitialisez votre mot de passe à l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`,
104
+ `retrieveUsernameLinkNotification,The SMS message that is sent to a user containing a self-service username retrieval link,{{applicationName}}: retrieve your username using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : récupérez votre nom d'utilisateur à l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`
105
+ ];
106
+ const LOGIN_CSV_ROWS = [
107
+ `buttons.backToLogin,"Label used to leave a screen that is waiting on an emailed link, where logging in is not yet possible",Back to login,Retour à la connexion`,
108
+ `resetCredentials.recoveryInstructionsSent.body,"Body message for the recovery instructions sent page. Must not assert delivery, since the account may not exist.","If we found an account, you'll receive instructions for {forgottenItem, select, username {retrieving your username} other {resetting your password}}. The link expires in 1 hour.","Si nous trouvons un compte correspondant, vous recevrez les instructions pour {forgottenItem, select, username {récupérer votre nom d'utilisateur} other {réinitialiser votre mot de passe}}. Le lien expire dans 1 heure."`,
109
+ `resetCredentials.recoveryInstructionsSent.title.email,Title for the recovery instructions sent page when notifications are delivered by email,Check your email,Vérifiez votre e-mail`,
110
+ `resetCredentials.recoveryInstructionsSent.title.phone,Title for the recovery instructions sent page when notifications are delivered by SMS,Check your phone,Vérifiez votre téléphone`,
111
+ `resetCredentials.recoveryLinkLanding.expired.body,"Body shown when a recovery link is invalid, expired, or already used. Must not reveal whether the underlying account exists.",This link is no longer valid. Request a new one to continue.,Ce lien n'est plus valide. Veuillez en demander un nouveau pour continuer.`,
112
+ `resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
113
+ `resetCredentials.recoveryLinkLanding.expired.title,"Title shown when a recovery link is invalid, expired, or already used",This link has expired,Ce lien a expiré`
114
+ ];
115
+ const skipped = [];
116
+ function warnSkipped(message) {
117
+ skipped.push(message);
118
+ console.warn(` ⚠️ ${message}`);
119
+ }
120
+ // ─── ts-morph helpers ────────────────────────────────────────────────────────
121
+ /**
122
+ * Returns the object literal a `const x = { ... }` declares, unwrapping any
123
+ * `as const` / `satisfies Record<...>` the map is annotated with.
124
+ */
125
+ function findObjectLiteral(declaration) {
126
+ let expression = declaration === null || declaration === void 0 ? void 0 : declaration.getInitializer();
127
+ while (expression &&
128
+ (ts_morph_1.Node.isAsExpression(expression) || ts_morph_1.Node.isSatisfiesExpression(expression))) {
129
+ expression = expression.getExpression();
130
+ }
131
+ return expression && ts_morph_1.Node.isObjectLiteralExpression(expression)
132
+ ? expression
133
+ : undefined;
134
+ }
135
+ /**
136
+ * Property keys for these maps are written in three interchangeable styles:
137
+ * `[TriggerEvent.PASSWORD_RESET_LINK]`, `['password-reset-link']` and
138
+ * `password-reset-link`. All three mean the same key, so all three count as
139
+ * already present.
140
+ */
141
+ function hasKeyFor(obj, key, constant) {
142
+ const accepted = new Set([
143
+ `[TriggerEvent.${constant}]`,
144
+ `['${key}']`,
145
+ `["${key}"]`,
146
+ `'${key}'`,
147
+ `"${key}"`,
148
+ key
149
+ ]);
150
+ return obj
151
+ .getProperties()
152
+ .some((property) => ts_morph_1.Node.isPropertyAssignment(property) &&
153
+ accepted.has(property.getName().trim()));
154
+ }
155
+ /**
156
+ * Mirrors the key style the object already uses, so the inserted entry does
157
+ * not look foreign next to its neighbours.
158
+ */
159
+ function renderKey(obj, key, constant) {
160
+ const names = obj
161
+ .getProperties()
162
+ .filter(ts_morph_1.Node.isPropertyAssignment)
163
+ .map((property) => property.getName().trim());
164
+ if (names.some((name) => name.startsWith('[TriggerEvent.'))) {
165
+ return `[TriggerEvent.${constant}]`;
166
+ }
167
+ if (names.some((name) => name.startsWith('['))) {
168
+ return `['${key}']`;
169
+ }
170
+ return `'${key}'`;
171
+ }
172
+ /**
173
+ * Appends `key: <value>` after the last entry of the object literal declared
174
+ * as `objectName`, given the value as lines indented relative to the key.
175
+ *
176
+ * Text insertion rather than `addPropertyAssignment`: ts-morph re-indents the
177
+ * code it writes one level deeper than a property of an already-nested map,
178
+ * which turns a two-line addition into a whole-file reformat once prettier
179
+ * runs over it. Returns false when the object cannot be found or is empty.
180
+ *
181
+ * Insertion invalidates every node previously read from this file, so callers
182
+ * must re-resolve what they need afterwards.
183
+ */
184
+ function appendEntry(sourceFile, objectName, key, valueLines) {
185
+ var _a;
186
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
187
+ const properties = (_a = obj === null || obj === void 0 ? void 0 : obj.getProperties()) !== null && _a !== void 0 ? _a : [];
188
+ const lastProperty = properties[properties.length - 1];
189
+ if (!lastProperty)
190
+ return false;
191
+ const indent = lastProperty.getIndentationText();
192
+ const entry = valueLines
193
+ .map((line, index) => `${indent}${index === 0 ? `${key}: ${line}` : line}`)
194
+ .join('\n');
195
+ sourceFile.insertText(lastProperty.getEnd(), `,\n${entry}`);
196
+ return true;
197
+ }
198
+ /**
199
+ * Returns whether the named object literal already holds a key for `event`,
200
+ * under any of the styles `hasKeyFor` accepts.
201
+ */
202
+ function objectHasKeyFor(sourceFile, objectName, key, constant) {
203
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
204
+ return obj ? hasKeyFor(obj, key, constant) : false;
205
+ }
206
+ /**
207
+ * Resolves the key style of the named object literal. Falls back to the
208
+ * quoted-string form when the object is gone.
209
+ */
210
+ function renderKeyFor(sourceFile, objectName, key, constant) {
211
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
212
+ return obj ? renderKey(obj, key, constant) : `'${key}'`;
213
+ }
214
+ // ─── Steps ───────────────────────────────────────────────────────────────────
215
+ function updateEmailTemplates(project, cwd) {
216
+ const sourceFile = project.getSourceFile(path_1.default.join(cwd, EMAIL_TEMPLATES_FILE));
217
+ if (!sourceFile) {
218
+ warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
219
+ return;
220
+ }
221
+ const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find((objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName)));
222
+ if (missingObject) {
223
+ warnSkipped(`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`);
224
+ return;
225
+ }
226
+ for (const event of RECOVERY_EVENTS) {
227
+ if (!objectHasKeyFor(sourceFile, TRIGGER_VARIABLE_OBJECT, event.id, event.constant) &&
228
+ appendEntry(sourceFile, TRIGGER_VARIABLE_OBJECT, renderKeyFor(sourceFile, TRIGGER_VARIABLE_OBJECT, event.id, event.constant), [
229
+ 'z.object({',
230
+ ' firstname: z.string(),',
231
+ ' applicationName: z.string(),',
232
+ ' countryLogo: z.string(),',
233
+ ' recoveryURL: z.string()',
234
+ '})'
235
+ ])) {
236
+ console.log(` ✓ ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
237
+ }
238
+ if (!objectHasKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant) &&
239
+ appendEntry(sourceFile, TEMPLATES_OBJECT, renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant), [
240
+ '{',
241
+ ` type: '${event.id}',`,
242
+ ` subject: '${event.emailSubject}',`,
243
+ ` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
244
+ ` '${event.id}'`,
245
+ ' )',
246
+ '}'
247
+ ])) {
248
+ console.log(` ✓ ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
249
+ }
250
+ }
251
+ }
252
+ function updateSmsService(project, cwd) {
253
+ const sourceFile = project.getSourceFile(path_1.default.join(cwd, SMS_SERVICE_FILE));
254
+ if (!sourceFile) {
255
+ warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
256
+ return;
257
+ }
258
+ const missingObject = [
259
+ OTHER_TEMPLATES_OBJECT,
260
+ TRIGGER_TO_SMS_TEMPLATE_OBJECT
261
+ ].find((objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName)));
262
+ if (missingObject) {
263
+ warnSkipped(`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`);
264
+ return;
265
+ }
266
+ for (const event of RECOVERY_EVENTS) {
267
+ if (!objectHasKeyFor(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, event.smsTemplate) &&
268
+ appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
269
+ `'${event.smsTemplate}'`
270
+ ])) {
271
+ console.log(` ✓ ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
272
+ }
273
+ if (!objectHasKeyFor(sourceFile, TRIGGER_TO_SMS_TEMPLATE_OBJECT, event.id, event.constant) &&
274
+ appendEntry(sourceFile, TRIGGER_TO_SMS_TEMPLATE_OBJECT, renderKeyFor(sourceFile, TRIGGER_TO_SMS_TEMPLATE_OBJECT, event.id, event.constant), [`'${event.smsTemplate}'`])) {
275
+ console.log(` ✓ ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`);
276
+ }
277
+ }
278
+ }
279
+ function updateHandler(project, cwd) {
280
+ var _a;
281
+ const sourceFile = project.getSourceFile(path_1.default.join(cwd, HANDLER_FILE));
282
+ if (!sourceFile) {
283
+ warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
284
+ return;
285
+ }
286
+ const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
287
+ const caseBlock = (_a = convertPayload === null || convertPayload === void 0 ? void 0 : convertPayload.getFirstDescendantByKind(ts_morph_1.SyntaxKind.SwitchStatement)) === null || _a === void 0 ? void 0 : _a.getCaseBlock();
288
+ if (!caseBlock) {
289
+ warnSkipped(`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`);
290
+ return;
291
+ }
292
+ const missing = RECOVERY_EVENTS.filter((event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) &&
293
+ !caseBlock.getText().includes(`'${event.id}'`));
294
+ if (missing.length === 0)
295
+ return;
296
+ /*
297
+ * `CaseBlock` has no clause-insertion API, so this inserts text instead:
298
+ * ahead of `default:` when there is one — an unreached case would silently
299
+ * become an "Unknown event" throw — otherwise after the last clause.
300
+ * Inserted text is not re-indented, so it carries its neighbours' indent.
301
+ */
302
+ const existingClauses = caseBlock.getClauses();
303
+ if (existingClauses.length === 0) {
304
+ warnSkipped(`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`);
305
+ return;
306
+ }
307
+ const defaultClause = existingClauses.find(ts_morph_1.Node.isDefaultClause);
308
+ const anchor = defaultClause !== null && defaultClause !== void 0 ? defaultClause : existingClauses[existingClauses.length - 1];
309
+ const indent = anchor.getIndentationText();
310
+ /*
311
+ * Both events carry the same payload and render the same variables, so they
312
+ * share one body — matching how the switch already groups 2fa with the
313
+ * change-phone-number / change-email-address cases.
314
+ */
315
+ const lines = [
316
+ ...missing.map((event) => `case TriggerEvent.${event.constant}:`),
317
+ ` return {`,
318
+ ` firstname,`,
319
+ ` applicationName: applicationConfig.APPLICATION_NAME,`,
320
+ ` countryLogo: COUNTRY_LOGO_URL,`,
321
+ ` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
322
+ ` }`
323
+ ];
324
+ if (defaultClause) {
325
+ // Insertion starts at `default`, i.e. past its indent, so the first line
326
+ // brings none of its own and the last hands the indent back.
327
+ caseBlock.insertText(anchor.getStart(), `${lines.map((line, index) => (index === 0 ? line : `${indent}${line}`)).join('\n')}\n${indent}`);
328
+ }
329
+ else {
330
+ caseBlock.insertText(anchor.getEnd(), `\n${lines.map((line) => `${indent}${line}`).join('\n')}`);
331
+ }
332
+ for (const event of missing) {
333
+ console.log(` ✓ ${HANDLER_FILE}: ${event.id} case`);
334
+ }
335
+ }
336
+ function updateRoutes(project, cwd) {
337
+ var _a;
338
+ var _b;
339
+ const sourceFile = project.getSourceFile(path_1.default.join(cwd, ROUTES_FILE));
340
+ if (!sourceFile) {
341
+ warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
342
+ return;
343
+ }
344
+ const routesFunction = (_b = sourceFile.getFunction(ROUTES_FUNCTION)) !== null && _b !== void 0 ? _b : sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
345
+ const routesArray = (_a = routesFunction === null || routesFunction === void 0 ? void 0 : routesFunction.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ReturnStatement)) === null || _a === void 0 ? void 0 : _a.getExpressionIfKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
346
+ if (!routesArray) {
347
+ warnSkipped(`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`);
348
+ return;
349
+ }
350
+ for (const event of RECOVERY_EVENTS) {
351
+ if (routesArray.getText().includes(`/trigger/user/${event.id}`))
352
+ continue;
353
+ routesArray.addElement(`{
354
+ method: 'POST',
355
+ path: '/trigger/user/${event.id}',
356
+ handler: makeNotificationHandler('${event.id}'),
357
+ options: {
358
+ auth: false,
359
+ tags: ['api'],
360
+ description: '${event.routeDescription}'
361
+ }
362
+ }`);
363
+ console.log(` ✓ ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
364
+ }
365
+ }
366
+ function renderEmailTemplate(event) {
367
+ return `<!--
368
+ This Source Code Form is subject to the terms of the Mozilla Public
369
+ License, v. 2.0. If a copy of the MPL was not distributed with this
370
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
371
+
372
+ OpenCRVS is also distributed under the terms of the Civil Registration
373
+ & Healthcare Disclaimer located at http://opencrvs.org/license.
374
+
375
+ Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
376
+ -->
377
+ <!doctype html>
378
+ <html>
379
+ <head>
380
+ <link
381
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
382
+ rel="stylesheet"
383
+ />
384
+ <style type="text/css">
385
+ body {
386
+ font-family: 'Noto Sans', sans-serif;
387
+ color: #222;
388
+ padding: 16px 24px;
389
+ }
390
+
391
+ h1 {
392
+ font-size: 21px;
393
+ margin-top: 32px;
394
+ margin-bottom: 36px;
395
+ font-weight: 700;
396
+ }
397
+
398
+ p {
399
+ font-weight: 400;
400
+ font-size: 16px;
401
+ line-height: 1.8;
402
+ margin-bottom: 24px;
403
+ }
404
+
405
+ i {
406
+ color: #666;
407
+ font-weight: 400;
408
+ font-size: 16px;
409
+ }
410
+ </style>
411
+ </head>
412
+
413
+ <body>
414
+ <img
415
+ src="{{countryLogo}}"
416
+ alt="country_logo"
417
+ style="max-height: 88px; max-width: 100%"
418
+ />
419
+ <h1>${event.heading}</h1>
420
+ <p>Hello {{firstname}},</p>
421
+ <p>
422
+ ${event.reason}
423
+ </p>
424
+
425
+ <div style="margin-top: 32px; margin-bottom: 32px">
426
+ <a href="{{{recoveryURL}}}">${event.linkLabel}</a>
427
+ </div>
428
+ <br />
429
+ <p>
430
+ This link expires in 1 hour and can only be used once. If you did not
431
+ request this, you can ignore this email.
432
+ </p>
433
+ <br />
434
+ <p>
435
+ Best regards, <br />
436
+ {{applicationName}} Team
437
+ </p>
438
+ </body>
439
+ </html>
440
+ `;
441
+ }
442
+ function writeEmailTemplates(cwd) {
443
+ const templateDir = path_1.default.join(cwd, EMAIL_TEMPLATE_DIR);
444
+ if (!(0, fs_1.existsSync)(templateDir)) {
445
+ warnSkipped(`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`);
446
+ return;
447
+ }
448
+ for (const event of RECOVERY_EVENTS) {
449
+ const templatePath = path_1.default.join(templateDir, `${event.id}.html`);
450
+ if ((0, fs_1.existsSync)(templatePath))
451
+ continue;
452
+ /*
453
+ * The recovery URL uses a triple stash on purpose: Handlebars' default
454
+ * escaping turns the `=` of `?token=` into `&#x3D;`, which breaks the
455
+ * query string the login page parses the token out of.
456
+ */
457
+ (0, fs_1.writeFileSync)(templatePath, renderEmailTemplate(event));
458
+ console.log(` ✓ ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
459
+ }
460
+ }
461
+ /**
462
+ * Appends the rows the CSV is missing, keeping the file's own ordering.
463
+ */
464
+ function addCsvRows(cwd, relativePath, rows) {
465
+ const csvPath = path_1.default.join(cwd, relativePath);
466
+ const file = (0, csv_1.readCsvFile)(csvPath);
467
+ if (!file) {
468
+ warnSkipped(`${relativePath} not found; translations not added`);
469
+ return;
470
+ }
471
+ const added = (0, csv_1.addRows)(file, rows);
472
+ if (added.length === 0)
473
+ return;
474
+ for (const id of added) {
475
+ console.log(` ✓ ${relativePath}: ${id}`);
476
+ }
477
+ (0, csv_1.writeCsvFile)(csvPath, file);
478
+ }
479
+ // ─── Entry point ─────────────────────────────────────────────────────────────
480
+ function main() {
481
+ return __awaiter(this, void 0, void 0, function* () {
482
+ const cwd = process.cwd();
483
+ const tsConfigFilePath = path_1.default.join(cwd, 'tsconfig.json');
484
+ console.log('Registering the password-reset-link and username-reminder-link notifications...\n');
485
+ if (!(0, fs_1.existsSync)(tsConfigFilePath)) {
486
+ warnSkipped(`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`);
487
+ return;
488
+ }
489
+ const project = new ts_morph_1.Project({
490
+ tsConfigFilePath,
491
+ skipAddingFilesFromTsConfig: false,
492
+ // ts-morph indents inserted code with four spaces by default, which every
493
+ // country config's prettier run would immediately undo.
494
+ manipulationSettings: { indentationText: ts_morph_1.IndentationText.TwoSpaces }
495
+ });
496
+ updateEmailTemplates(project, cwd);
497
+ updateSmsService(project, cwd);
498
+ updateHandler(project, cwd);
499
+ updateRoutes(project, cwd);
500
+ yield project.save();
501
+ writeEmailTemplates(cwd);
502
+ addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
503
+ addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
504
+ if (skipped.length > 0) {
505
+ console.warn(`\n⚠️ ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`);
506
+ for (const message of skipped) {
507
+ console.warn(` - ${message}`);
508
+ }
509
+ }
510
+ });
511
+ }
@@ -0,0 +1,9 @@
1
+ import { CsvFile } from '../../csv';
2
+ /**
3
+ * The rows of the template that the local file has no id for, expressed in the
4
+ * local file's columns.
5
+ */
6
+ export declare function rowsToAdd(local: CsvFile, template: CsvFile): string[];
7
+ declare function main(): Promise<void>;
8
+ export { main };
9
+ //# sourceMappingURL=add-translations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-translations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/add-translations.ts"],"names":[],"mappings":"AAiCA,OAAO,EACL,OAAO,EAMR,MAAM,WAAW,CAAA;AAelB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAgBrE;AAoED,iBAAe,IAAI,kBA2BlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}