@opencrvs/toolkit 2.1.0-rc.1f688f9 → 2.1.0-rc.268cfbe

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 (209) hide show
  1. package/README.md +2 -12
  2. package/build.sh +20 -5
  3. package/create-countryconfig/index.js +164 -4
  4. package/dist/application-config/index.js +36 -25
  5. package/dist/authentication/index.d.ts +66 -0
  6. package/dist/authentication/index.d.ts.map +1 -0
  7. package/dist/authentication/index.js +765 -0
  8. package/dist/cli.js +2829 -1294
  9. package/dist/commons/api/router.d.ts +252 -290
  10. package/dist/commons/application-config/index.d.ts +0 -2
  11. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  12. package/dist/commons/conditionals/validate.d.ts +19 -4
  13. package/dist/commons/events/ActionConfig.d.ts +5 -14
  14. package/dist/commons/events/ActionDocument.d.ts +30 -4
  15. package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
  16. package/dist/commons/events/AuditLog.d.ts +1 -0
  17. package/dist/commons/events/Draft.d.ts +1 -21
  18. package/dist/commons/events/EventDocument.d.ts +4 -4
  19. package/dist/commons/events/FieldConfig.d.ts +26 -15
  20. package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
  21. package/dist/commons/events/FieldValue.d.ts +1 -0
  22. package/dist/commons/events/FormConfig.d.ts +6 -0
  23. package/dist/commons/events/PageConfig.d.ts +4 -0
  24. package/dist/commons/events/locations.d.ts +4 -0
  25. package/dist/commons/events/scopes.d.ts +21 -1
  26. package/dist/commons/events/test.utils.d.ts +71 -22
  27. package/dist/commons/events/utils.d.ts +37 -2
  28. package/dist/commons/notification/dispatch.d.ts +1 -6
  29. package/dist/conditionals/index.js +21 -7
  30. package/dist/csv.d.ts +25 -0
  31. package/dist/csv.d.ts.map +1 -0
  32. package/dist/csv.js +120 -0
  33. package/dist/environment/index.d.ts.map +1 -1
  34. package/dist/environment/index.js +2 -1
  35. package/dist/environment/logger.d.ts +3 -0
  36. package/dist/environment/logger.d.ts.map +1 -1
  37. package/dist/environment/manage-users.js +1 -1
  38. package/dist/environment/setup-environment.d.ts +1 -1
  39. package/dist/environment/setup-environment.d.ts.map +1 -1
  40. package/dist/environment/setup-environment.js +593 -562
  41. package/dist/environment/swarm-to-k8s.js +3 -4
  42. package/dist/environment/templates.d.ts +0 -1
  43. package/dist/environment/templates.d.ts.map +1 -1
  44. package/dist/environment/templates.js +3 -8
  45. package/dist/environment/update-workflows.d.ts.map +1 -1
  46. package/dist/environment/update-workflows.js +4 -0
  47. package/dist/environment/utils.d.ts +0 -12
  48. package/dist/environment/utils.d.ts.map +1 -1
  49. package/dist/environment/utils.js +1 -28
  50. package/dist/events/index.js +2115 -1884
  51. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -1
  52. package/dist/migrations/v2.1/add-recovery-link-notifications.js +13 -32
  53. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  54. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  55. package/dist/migrations/v2.1/add-translations.js +149 -0
  56. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
  57. package/dist/migrations/v2.1/enable-telemetry.js +32 -15
  58. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  59. package/dist/migrations/v2.1/index.js +1160 -70
  60. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  61. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  62. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +345 -0
  63. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  64. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  65. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  66. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  67. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  68. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  69. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  70. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  71. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  72. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  73. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  74. package/dist/migrations/v2.1/template-files.js +49 -0
  75. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  76. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  77. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  78. package/dist/notification/index.js +249 -207
  79. package/dist/scopes/index.d.ts +288 -5
  80. package/dist/scopes/index.js +22 -7
  81. package/dist/telemetry/index.js +5 -1
  82. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  83. package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
  84. package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
  85. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  86. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  87. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  88. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  89. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  90. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  91. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  92. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  93. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  94. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  95. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  96. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  97. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  98. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  99. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  100. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  101. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  102. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  103. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  104. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  105. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  106. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  107. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  108. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  109. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  110. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  111. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  112. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  113. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  114. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  115. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  116. package/dist/translations/template.d.ts +11 -0
  117. package/dist/translations/template.d.ts.map +1 -0
  118. package/dist/translations/template.js +100 -0
  119. package/dist/verify/endpoints.d.ts +2 -0
  120. package/dist/verify/endpoints.d.ts.map +1 -0
  121. package/dist/verify/endpoints.js +510 -0
  122. package/opencrvs-toolkit-2.1.0-rc.268cfbe.tgz +0 -0
  123. package/package.json +9 -4
  124. package/tsconfig.build.json +11 -0
  125. package/tsconfig.build.tsbuildinfo +1 -0
  126. package/tsconfig.json +3 -0
  127. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  128. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  129. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  130. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  131. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  132. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  133. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  134. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  135. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  136. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  137. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  138. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  139. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  140. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  141. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  142. package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
  143. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  144. package/dist/migrations/v2.0/create-events-index.js +0 -325
  145. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  146. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  147. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  148. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  149. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  150. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  151. package/dist/migrations/v2.0/index.d.ts +0 -13
  152. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  153. package/dist/migrations/v2.0/index.js +0 -103
  154. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  155. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  156. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  157. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  158. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  159. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  160. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  161. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  162. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  163. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  164. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  165. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  166. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  167. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  168. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  169. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  170. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  171. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  172. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  173. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  174. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  175. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  176. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  177. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  178. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  179. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  180. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  181. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  182. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  183. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  184. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  185. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  186. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  187. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  188. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  189. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  190. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  191. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  192. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  193. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  194. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  195. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  196. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  197. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  198. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  199. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  200. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  201. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  202. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  203. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  204. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  205. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  206. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  207. package/dist/migrations/v2.0/update-package-json.js +0 -105
  208. package/opencrvs-toolkit-2.1.0-rc.1f688f9.tgz +0 -0
  209. package/tsconfig.tsbuildinfo +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"add-recovery-link-notifications.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/add-recovery-link-notifications.ts"],"names":[],"mappings":"AA4qBA,iBAAe,IAAI,kBA0ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
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"}
@@ -48,7 +48,7 @@ exports.main = main;
48
48
  * `convertPayloadToVariable` switch, building the recovery URL from the
49
49
  * token in the payload
50
50
  * - `src/config/routes/userNotificationRoutes.ts`: adds the two
51
- * `POST /triggers/user/*` routes core posts to
51
+ * `POST /trigger/user/*` routes core posts to
52
52
  * - `src/api/notification/email-templates/other/*.html`: writes the two
53
53
  * email bodies
54
54
  * - `src/translations/notification.csv`: adds the two SMS messages
@@ -63,6 +63,7 @@ exports.main = main;
63
63
  const ts_morph_1 = require("ts-morph");
64
64
  const fs_1 = require("fs");
65
65
  const path_1 = __importDefault(require("path"));
66
+ const csv_1 = require("../../csv");
66
67
  const EMAIL_TEMPLATES_FILE = 'src/api/notification/email-templates/index.ts';
67
68
  const SMS_SERVICE_FILE = 'src/api/notification/sms-service.ts';
68
69
  const HANDLER_FILE = 'src/api/notification/handler.ts';
@@ -347,11 +348,11 @@ function updateRoutes(project, cwd) {
347
348
  return;
348
349
  }
349
350
  for (const event of RECOVERY_EVENTS) {
350
- if (routesArray.getText().includes(`/triggers/user/${event.id}`))
351
+ if (routesArray.getText().includes(`/trigger/user/${event.id}`))
351
352
  continue;
352
353
  routesArray.addElement(`{
353
354
  method: 'POST',
354
- path: '/triggers/user/${event.id}',
355
+ path: '/trigger/user/${event.id}',
355
356
  handler: makeNotificationHandler('${event.id}'),
356
357
  options: {
357
358
  auth: false,
@@ -359,7 +360,7 @@ function updateRoutes(project, cwd) {
359
360
  description: '${event.routeDescription}'
360
361
  }
361
362
  }`);
362
- console.log(` ✓ ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
363
+ console.log(` ✓ ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
363
364
  }
364
365
  }
365
366
  function renderEmailTemplate(event) {
@@ -458,42 +459,22 @@ function writeEmailTemplates(cwd) {
458
459
  }
459
460
  }
460
461
  /**
461
- * Appends the rows the CSV is missing, keeping the file's own ordering: rows
462
- * go in sorted position when the file is already sorted by id, otherwise at
463
- * the end.
462
+ * Appends the rows the CSV is missing, keeping the file's own ordering.
464
463
  */
465
464
  function addCsvRows(cwd, relativePath, rows) {
466
465
  const csvPath = path_1.default.join(cwd, relativePath);
467
- if (!(0, fs_1.existsSync)(csvPath)) {
466
+ const file = (0, csv_1.readCsvFile)(csvPath);
467
+ if (!file) {
468
468
  warnSkipped(`${relativePath} not found; translations not added`);
469
469
  return;
470
470
  }
471
- const original = (0, fs_1.readFileSync)(csvPath, 'utf8');
472
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
473
- const hadTrailingNewline = /\r?\n$/.test(original);
474
- const lines = original.replace(/\r?\n$/, '').split(/\r?\n/);
475
- const idOf = (line) => line.slice(0, line.indexOf(','));
476
- const header = lines[0];
477
- const body = lines.slice(1);
478
- const isSorted = body.every((line, index) => index === 0 || idOf(body[index - 1]) <= idOf(line));
479
- let added = 0;
480
- for (const row of rows) {
481
- const id = idOf(row);
482
- if (body.some((line) => idOf(line) === id))
483
- continue;
484
- const insertAt = isSorted ? body.findIndex((line) => idOf(line) > id) : -1;
485
- if (insertAt === -1) {
486
- body.push(row);
487
- }
488
- else {
489
- body.splice(insertAt, 0, row);
490
- }
491
- added++;
471
+ const added = (0, csv_1.addRows)(file, rows);
472
+ if (added.length === 0)
473
+ return;
474
+ for (const id of added) {
492
475
  console.log(` ✓ ${relativePath}: ${id}`);
493
476
  }
494
- if (added === 0)
495
- return;
496
- (0, fs_1.writeFileSync)(csvPath, [header, ...body].join(newline) + (hadTrailingNewline ? newline : ''));
477
+ (0, csv_1.writeCsvFile)(csvPath, file);
497
478
  }
498
479
  // ─── Entry point ─────────────────────────────────────────────────────────────
499
480
  function main() {
@@ -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"}
@@ -0,0 +1,149 @@
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.rowsToAdd = rowsToAdd;
26
+ exports.main = main;
27
+ /**
28
+ * Codemod: copy the translation keys core gained this version into this country
29
+ * config.
30
+ *
31
+ * Unlike every other codemod, this one carries no list of what it changes, and
32
+ * should not need editing again. Its input is `client.csv` and `login.csv` from
33
+ * the country config template of the version being upgraded to, fetched from
34
+ * GitHub; whatever rows those files have gained, this adds. A pull request that
35
+ * introduces a translation key therefore only has to add it to the template —
36
+ * `packages/countryconfig-template/src/translations/` — which the
37
+ * check-missing-translation workflow makes it do anyway.
38
+ *
39
+ * `countryconfig.csv` is deliberately left alone. It holds the copy the country
40
+ * config declares itself, which is nobody's business but the country's.
41
+ *
42
+ * Rows are rebuilt against the local file's own columns rather than copied
43
+ * across, so a country config with languages the template does not have keeps
44
+ * its shape: the template's value is used for a language they share, and an
45
+ * empty cell for one it has nothing for.
46
+ */
47
+ const path_1 = __importDefault(require("path"));
48
+ const csv_1 = require("../../csv");
49
+ const template_1 = require("../../translations/template");
50
+ const APPLICATIONS = ['client', 'login'];
51
+ /** The version this folder upgrades a country config to. */
52
+ const TARGET_VERSION = '2.1';
53
+ const skipped = [];
54
+ function warnSkipped(message) {
55
+ skipped.push(message);
56
+ console.warn(` ⚠️ ${message}`);
57
+ }
58
+ /**
59
+ * The rows of the template that the local file has no id for, expressed in the
60
+ * local file's columns.
61
+ */
62
+ function rowsToAdd(local, template) {
63
+ const localColumns = (0, csv_1.parseCsvLine)(local.header);
64
+ const templateColumns = (0, csv_1.parseCsvLine)(template.header);
65
+ return template.body
66
+ .filter((line) => line !== '')
67
+ .map((line) => {
68
+ const values = (0, csv_1.parseCsvLine)(line);
69
+ return (0, csv_1.toCsvLine)(localColumns.map((column) => {
70
+ var _a;
71
+ const index = templateColumns.indexOf(column);
72
+ return index === -1 ? '' : ((_a = values[index]) !== null && _a !== void 0 ? _a : '');
73
+ }));
74
+ });
75
+ }
76
+ function updateApplication(cwd, refs, application) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const relativePath = `src/translations/${application}.csv`;
79
+ const local = (0, csv_1.readCsvFile)(path_1.default.join(cwd, relativePath));
80
+ if (!local) {
81
+ warnSkipped(`${relativePath} not found; translations not added`);
82
+ return;
83
+ }
84
+ const fetched = yield (0, template_1.fetchTemplate)(refs, application);
85
+ if (!fetched) {
86
+ warnSkipped(`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`);
87
+ return;
88
+ }
89
+ const template = readTemplate(fetched.contents);
90
+ const added = (0, csv_1.addRows)(local, rowsToAdd(local, template));
91
+ if (added.length === 0) {
92
+ return;
93
+ }
94
+ try {
95
+ (0, csv_1.writeCsvFile)(path_1.default.join(cwd, relativePath), local);
96
+ }
97
+ catch (error) {
98
+ warnSkipped(`Could not write ${relativePath} (${error.message}); translations not added`);
99
+ return;
100
+ }
101
+ for (const id of added) {
102
+ console.log(` ✓ ${relativePath}: ${id}`);
103
+ }
104
+ });
105
+ }
106
+ function readTemplate(contents) {
107
+ const lines = contents.replace(/\r?\n$/, '').split(/\r?\n/);
108
+ return {
109
+ header: lines[0],
110
+ body: lines.slice(1),
111
+ newline: '\n',
112
+ trailingNewline: true
113
+ };
114
+ }
115
+ /** Refs to read the template from. Undefined when GitHub cannot be asked. */
116
+ function listRefs() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ try {
119
+ return yield (0, template_1.candidateRefs)(TARGET_VERSION);
120
+ }
121
+ catch (error) {
122
+ warnSkipped(`Could not list the ${TARGET_VERSION} refs on GitHub (${error.message}); translations not added`);
123
+ return undefined;
124
+ }
125
+ });
126
+ }
127
+ function main() {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const cwd = process.cwd();
130
+ console.log('Adding the translation keys core gained this version...\n');
131
+ const refs = yield listRefs();
132
+ if (refs) {
133
+ for (const application of APPLICATIONS) {
134
+ try {
135
+ yield updateApplication(cwd, refs, application);
136
+ }
137
+ catch (error) {
138
+ warnSkipped(`Could not read ${application}.csv from the country config template on GitHub (${error.message}); ${application}.csv not updated`);
139
+ }
140
+ }
141
+ }
142
+ if (skipped.length > 0) {
143
+ console.warn(`\n⚠️ ${skipped.length} step(s) were skipped. Add the missing translations by hand before upgrading:`);
144
+ for (const message of skipped) {
145
+ console.warn(` - ${message}`);
146
+ }
147
+ }
148
+ });
149
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"enable-telemetry.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/enable-telemetry.ts"],"names":[],"mappings":"AAwhBA,iBAAe,IAAI,kBAiClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"enable-telemetry.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/enable-telemetry.ts"],"names":[],"mappings":"AAijBA,iBAAe,IAAI,kBAiClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -105,10 +105,10 @@ export const TELEMETRY_DISABLED_NOTICE =
105
105
  * telemetry is enabled or of the country code / domain / environment reported.
106
106
  */
107
107
  export async function telemetryHandler(request: Request, h: ResponseToolkit) {
108
- // Only accept OpenCRVS *system* tokens (the events service's anonymous
108
+ // Only accept OpenCRVS *system* tokens (the events service's service
109
109
  // token has userType 'system'). A logged-in user's token is a 'user' token,
110
110
  // so a user cannot submit telemetry with their own credentials — and the
111
- // anonymous-token endpoint is not reachable through the public gateway.
111
+ // service-token endpoint is not reachable through the public gateway.
112
112
  const credentials = request.auth.credentials as
113
113
  | { userType?: string }
114
114
  | undefined
@@ -328,6 +328,31 @@ function addEnvironmentVariables(project, cwd, config) {
328
328
  upsertEnvVar(sourceFile, 'ORGANISATION', 'str', config.enabled ? JSON.stringify(config.organisation) : `''`, 'Organisation running this instance, reported with telemetry. Empty by default.', config.enabled);
329
329
  upsertEnvVar(sourceFile, 'ENVIRONMENT_NAME', 'str', `'development'`, 'Environment name (e.g. "production", "staging") reported as the telemetry environment.', false);
330
330
  }
331
+ /**
332
+ * Add the handler import, or top up the named imports of one that is already
333
+ * there.
334
+ */
335
+ function ensureHandlerNamedImports(sourceFile, names) {
336
+ const importDeclaration = sourceFile
337
+ .getImportDeclarations()
338
+ .find((declaration) => declaration.getModuleSpecifierValue() === HANDLER_MODULE);
339
+ if (!importDeclaration) {
340
+ sourceFile.addImportDeclaration({
341
+ moduleSpecifier: HANDLER_MODULE,
342
+ namedImports: names
343
+ });
344
+ console.log(` ✓ ${INDEX_FILE}: import ${HANDLER_MODULE}`);
345
+ return;
346
+ }
347
+ const existing = new Set(importDeclaration.getNamedImports().map((named) => named.getName()));
348
+ const missing = names.filter((name) => !existing.has(name));
349
+ for (const name of missing) {
350
+ importDeclaration.addNamedImport(name);
351
+ }
352
+ if (missing.length > 0) {
353
+ console.log(` ✓ ${INDEX_FILE}: import ${missing.join(', ')} from ${HANDLER_MODULE}`);
354
+ }
355
+ }
331
356
  function wireIndex(project, cwd) {
332
357
  const sourceFile = project.addSourceFileAtPathIfExists(path_1.default.join(cwd, INDEX_FILE));
333
358
  if (!sourceFile) {
@@ -335,19 +360,11 @@ function wireIndex(project, cwd) {
335
360
  return;
336
361
  }
337
362
  // 1. import
338
- if (!sourceFile
339
- .getImportDeclarations()
340
- .some((d) => d.getModuleSpecifierValue() === HANDLER_MODULE)) {
341
- sourceFile.addImportDeclaration({
342
- moduleSpecifier: HANDLER_MODULE,
343
- namedImports: [
344
- 'telemetryHandler',
345
- 'telemetrySchema',
346
- 'TELEMETRY_DISABLED_NOTICE'
347
- ]
348
- });
349
- console.log(` ✓ ${INDEX_FILE}: import ${HANDLER_MODULE}`);
350
- }
363
+ ensureHandlerNamedImports(sourceFile, [
364
+ 'telemetryHandler',
365
+ 'telemetrySchema',
366
+ 'TELEMETRY_DISABLED_NOTICE'
367
+ ]);
351
368
  // 2. route, inserted after the last server.route(...) call
352
369
  if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
353
370
  const lastRouteStatement = sourceFile
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/index.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAIpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/index.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAWpD"}