@opencrvs/toolkit 2.1.0-rc.12673aa → 2.1.0-rc.14fb6a5

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 (188) hide show
  1. package/build.sh +14 -4
  2. package/create-countryconfig/index.js +59 -30
  3. package/dist/application-config/index.js +26 -13
  4. package/dist/authentication/index.d.ts +8 -9
  5. package/dist/authentication/index.js +23 -8
  6. package/dist/cli.js +2268 -1385
  7. package/dist/commons/api/router.d.ts +252 -290
  8. package/dist/commons/application-config/index.d.ts +0 -2
  9. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  10. package/dist/commons/conditionals/validate.d.ts +18 -3
  11. package/dist/commons/events/ActionConfig.d.ts +5 -14
  12. package/dist/commons/events/ActionDocument.d.ts +30 -4
  13. package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
  14. package/dist/commons/events/AuditLog.d.ts +1 -0
  15. package/dist/commons/events/Draft.d.ts +1 -21
  16. package/dist/commons/events/EventDocument.d.ts +4 -4
  17. package/dist/commons/events/FieldConfig.d.ts +20 -10
  18. package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
  19. package/dist/commons/events/FieldValue.d.ts +1 -0
  20. package/dist/commons/events/FormConfig.d.ts +6 -0
  21. package/dist/commons/events/PageConfig.d.ts +4 -0
  22. package/dist/commons/events/scopes.d.ts +21 -1
  23. package/dist/commons/events/test.utils.d.ts +53 -21
  24. package/dist/commons/events/utils.d.ts +26 -2
  25. package/dist/conditionals/index.js +21 -7
  26. package/dist/environment/index.d.ts.map +1 -1
  27. package/dist/environment/index.js +2 -1
  28. package/dist/environment/setup-environment.d.ts +1 -1
  29. package/dist/environment/setup-environment.d.ts.map +1 -1
  30. package/dist/environment/setup-environment.js +586 -569
  31. package/dist/environment/swarm-to-k8s.js +3 -4
  32. package/dist/events/index.js +282 -138
  33. package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
  34. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
  35. package/dist/migrations/v2.1/add-translations.js +4 -68
  36. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
  37. package/dist/migrations/v2.1/enable-telemetry.js +30 -13
  38. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  39. package/dist/migrations/v2.1/index.js +927 -33
  40. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  41. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  42. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  43. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  44. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  45. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  46. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  47. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  48. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  49. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  50. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  51. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  52. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  53. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  54. package/dist/migrations/v2.1/template-files.js +49 -0
  55. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  56. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  57. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  58. package/dist/notification/index.js +105 -61
  59. package/dist/scopes/index.d.ts +288 -5
  60. package/dist/scopes/index.js +22 -7
  61. package/dist/telemetry/index.js +4 -0
  62. package/dist/templates/charts-values/dependencies/values.yaml +6 -0
  63. package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
  64. package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
  65. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  66. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  67. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  68. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  69. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  70. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  71. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  72. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  73. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  74. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  75. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  76. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  77. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  78. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  79. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  80. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  81. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  82. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  83. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  84. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  85. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  86. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  87. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  88. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  89. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  90. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  91. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  92. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  93. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  94. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  95. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  96. package/dist/translations/template.d.ts +11 -0
  97. package/dist/translations/template.d.ts.map +1 -0
  98. package/dist/translations/template.js +100 -0
  99. package/dist/verify/endpoints.d.ts.map +1 -1
  100. package/dist/verify/endpoints.js +179 -14
  101. package/opencrvs-toolkit-2.1.0-rc.14fb6a5.tgz +0 -0
  102. package/package.json +2 -1
  103. package/tsconfig.build.tsbuildinfo +1 -1
  104. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  105. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  106. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  107. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  108. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  109. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  110. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  111. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  112. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  113. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  114. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  115. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  116. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  117. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  118. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  119. package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
  120. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  121. package/dist/migrations/v2.0/create-events-index.js +0 -325
  122. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  123. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  124. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  125. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  126. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  127. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  128. package/dist/migrations/v2.0/index.d.ts +0 -13
  129. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  130. package/dist/migrations/v2.0/index.js +0 -103
  131. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  132. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  133. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  134. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  135. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  136. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  137. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  138. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  139. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  140. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  141. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  142. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  143. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  144. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  145. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  146. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  147. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  148. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  149. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  150. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  151. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  152. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  153. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  154. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  155. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  156. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  157. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  158. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  159. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  160. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  161. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  162. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  163. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  164. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  165. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  166. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  167. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  168. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  169. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  170. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  171. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  172. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  173. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  174. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  175. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  176. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  177. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  178. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  179. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  180. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  181. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  182. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  183. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  184. package/dist/migrations/v2.0/update-package-json.js +0 -105
  185. package/dist/translations/check.d.ts +0 -21
  186. package/dist/translations/check.d.ts.map +0 -1
  187. package/dist/translations/check.js +0 -132
  188. package/opencrvs-toolkit-2.1.0-rc.12673aa.tgz +0 -0
@@ -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
@@ -348,11 +348,11 @@ function updateRoutes(project, cwd) {
348
348
  return;
349
349
  }
350
350
  for (const event of RECOVERY_EVENTS) {
351
- if (routesArray.getText().includes(`/triggers/user/${event.id}`))
351
+ if (routesArray.getText().includes(`/trigger/user/${event.id}`))
352
352
  continue;
353
353
  routesArray.addElement(`{
354
354
  method: 'POST',
355
- path: '/triggers/user/${event.id}',
355
+ path: '/trigger/user/${event.id}',
356
356
  handler: makeNotificationHandler('${event.id}'),
357
357
  options: {
358
358
  auth: false,
@@ -360,7 +360,7 @@ function updateRoutes(project, cwd) {
360
360
  description: '${event.routeDescription}'
361
361
  }
362
362
  }`);
363
- console.log(` ✓ ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
363
+ console.log(` ✓ ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
364
364
  }
365
365
  }
366
366
  function renderEmailTemplate(event) {
@@ -1 +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;AA2FlB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAgBrE;AAiED,iBAAe,IAAI,kBA2BlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
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"}
@@ -46,8 +46,7 @@ exports.main = main;
46
46
  */
47
47
  const path_1 = __importDefault(require("path"));
48
48
  const csv_1 = require("../../csv");
49
- const REPOSITORY = 'opencrvs/opencrvs-core';
50
- const TEMPLATE_TRANSLATIONS = 'packages/countryconfig-template/src/translations';
49
+ const template_1 = require("../../translations/template");
51
50
  const APPLICATIONS = ['client', 'login'];
52
51
  /** The version this folder upgrades a country config to. */
53
52
  const TARGET_VERSION = '2.1';
@@ -56,70 +55,6 @@ function warnSkipped(message) {
56
55
  skipped.push(message);
57
56
  console.warn(` ⚠️ ${message}`);
58
57
  }
59
- /**
60
- * The refs matching a prefix, newest patch first.
61
- *
62
- * Every patch gets its own release branch — `release/2.1.0`, `release/2.1.1` —
63
- * and a translation key added in a patch only exists on that patch's branch, so
64
- * the newest one is the one worth reading.
65
- */
66
- function matchingRefs(namespace, prefix) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
69
- const response = yield fetch(url, {
70
- headers: { accept: 'application/vnd.github+json' }
71
- });
72
- /*
73
- * An empty list and a failed request are not the same thing: GitHub answers
74
- * 200 with `[]` for a prefix nothing matches, so anything else is the request
75
- * failing rather than the version having no release branch. Swallowing it
76
- * would leave `develop` as the only candidate left, and an unauthenticated
77
- * api.github.com allows 60 requests an hour per IP — a country upgrading from
78
- * a shared network or a CI runner would quietly get unreleased copy.
79
- */
80
- if (!response.ok) {
81
- throw new Error(`GitHub answered ${response.status} ${response.statusText} for ${url}`);
82
- }
83
- const refs = (yield response.json());
84
- const patchOf = (ref) => Number(ref.split('.').pop()) || 0;
85
- return refs
86
- .map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, ''))
87
- .sort((a, b) => patchOf(b) - patchOf(a));
88
- });
89
- }
90
- /**
91
- * Where to read the template from, most specific first: the newest release
92
- * branch of the target version, then its newest tag, then `develop` for anyone
93
- * running the codemod before the version has been cut.
94
- */
95
- function candidateRefs() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return [
98
- ...(yield matchingRefs('heads', `release/${TARGET_VERSION}.`)),
99
- ...(yield matchingRefs('tags', `v${TARGET_VERSION}.`)),
100
- 'develop'
101
- ];
102
- });
103
- }
104
- function fetchTemplate(refs, application) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- for (const ref of refs) {
107
- const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
108
- const response = yield fetch(url);
109
- if (response.ok) {
110
- return { ref, contents: yield response.text() };
111
- }
112
- // 404 means this ref does not carry the file and the next one is worth a
113
- // try. Anything else is the request failing, and moving on would read the
114
- // template from a ref older than the one that was asked for.
115
- if (response.status !== 404) {
116
- throw new Error(`GitHub answered ${response.status} ${response.statusText} for ${url}`);
117
- }
118
- }
119
- warnSkipped(`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`);
120
- return undefined;
121
- });
122
- }
123
58
  /**
124
59
  * The rows of the template that the local file has no id for, expressed in the
125
60
  * local file's columns.
@@ -146,8 +81,9 @@ function updateApplication(cwd, refs, application) {
146
81
  warnSkipped(`${relativePath} not found; translations not added`);
147
82
  return;
148
83
  }
149
- const fetched = yield fetchTemplate(refs, application);
84
+ const fetched = yield (0, template_1.fetchTemplate)(refs, application);
150
85
  if (!fetched) {
86
+ warnSkipped(`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`);
151
87
  return;
152
88
  }
153
89
  const template = readTemplate(fetched.contents);
@@ -180,7 +116,7 @@ function readTemplate(contents) {
180
116
  function listRefs() {
181
117
  return __awaiter(this, void 0, void 0, function* () {
182
118
  try {
183
- return yield candidateRefs();
119
+ return yield (0, template_1.candidateRefs)(TARGET_VERSION);
184
120
  }
185
121
  catch (error) {
186
122
  warnSkipped(`Could not list the ${TARGET_VERSION} refs on GitHub (${error.message}); translations not added`);
@@ -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"}
@@ -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":"AAeA;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAKpD"}
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,iBAYpD"}