@opencrvs/toolkit 2.2.0-rc.ac299dc → 2.2.0-rc.e6591c5

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 (249) hide show
  1. package/build.sh +17 -14
  2. package/dist/application-config/index.js +21 -11
  3. package/dist/authentication/index.d.ts +2 -1
  4. package/dist/authentication/index.js +20 -13
  5. package/dist/cli.js +2631 -377
  6. package/dist/commons/api/router.d.ts +263 -250
  7. package/dist/commons/application-config/index.d.ts +3 -3
  8. package/dist/commons/conditionals/conditionals.d.ts +4 -4
  9. package/dist/commons/conditionals/index.d.ts +1 -0
  10. package/dist/commons/conditionals/validate.d.ts +6 -1
  11. package/dist/commons/events/ActionConfig.d.ts +16 -23
  12. package/dist/commons/events/ActionDocument.d.ts +1 -0
  13. package/dist/commons/events/ActionInput.d.ts +4 -4
  14. package/dist/commons/events/ActionStatus.d.ts +2 -2
  15. package/dist/commons/events/ActionType.d.ts +2 -0
  16. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -6
  17. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  18. package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
  19. package/dist/commons/events/Draft.d.ts +34 -1
  20. package/dist/commons/events/EventConfig.d.ts +448 -1
  21. package/dist/commons/events/EventDocument.d.ts +2 -0
  22. package/dist/commons/events/EventIndex.d.ts +3 -6
  23. package/dist/commons/events/EventInput.d.ts +1 -0
  24. package/dist/commons/events/EventMetadata.d.ts +1 -1
  25. package/dist/commons/events/FieldConfig.d.ts +1 -1
  26. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  27. package/dist/commons/events/Flag.d.ts +1 -7
  28. package/dist/commons/events/PlainDate.d.ts +6 -0
  29. package/dist/commons/events/WorkqueueConfig.d.ts +12 -27
  30. package/dist/commons/events/defineConfig.d.ts +7 -2
  31. package/dist/commons/events/event.d.ts +4 -1
  32. package/dist/commons/events/eventConfigValidation.d.ts +9 -0
  33. package/dist/commons/events/field.d.ts +5 -5
  34. package/dist/commons/events/index.d.ts +3 -0
  35. package/dist/commons/events/locations.d.ts +1 -1
  36. package/dist/commons/events/scopes.d.ts +2 -1
  37. package/dist/commons/events/state/flags.d.ts +1 -1
  38. package/dist/commons/events/state/index.d.ts +1 -0
  39. package/dist/commons/events/test.utils.d.ts +62 -7
  40. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  41. package/dist/commons/events/utils.d.ts +59 -7
  42. package/dist/commons/users/Role.d.ts +23 -0
  43. package/dist/commons/users/User.d.ts +263 -0
  44. package/dist/commons/users/authentication.d.ts +67 -0
  45. package/dist/commons/users/index.d.ts +5 -0
  46. package/dist/commons/users/roleValidations.d.ts +15 -0
  47. package/dist/commons/users/scopes.d.ts +1402 -0
  48. package/dist/commons/users/userReferences.d.ts +176 -0
  49. package/dist/conditionals/index.js +5 -6
  50. package/dist/configurator/index.d.ts +24 -0
  51. package/dist/configurator/index.d.ts.map +1 -0
  52. package/dist/configurator/index.js +161 -0
  53. package/dist/configurator/layout.d.ts +29 -0
  54. package/dist/configurator/layout.d.ts.map +1 -0
  55. package/dist/configurator/layout.js +78 -0
  56. package/dist/configurator/paths.d.ts +13 -0
  57. package/dist/configurator/paths.d.ts.map +1 -0
  58. package/dist/configurator/paths.js +48 -0
  59. package/dist/configurator/server/environments.d.ts +20 -0
  60. package/dist/configurator/server/environments.d.ts.map +1 -0
  61. package/dist/configurator/server/environments.js +143 -0
  62. package/dist/configurator/server/files.d.ts +11 -0
  63. package/dist/configurator/server/files.d.ts.map +1 -0
  64. package/dist/configurator/server/files.js +67 -0
  65. package/dist/configurator/server/github.d.ts +56 -0
  66. package/dist/configurator/server/github.d.ts.map +1 -0
  67. package/dist/configurator/server/github.js +239 -0
  68. package/dist/configurator/server/plugin.d.ts +39 -0
  69. package/dist/configurator/server/plugin.d.ts.map +1 -0
  70. package/dist/configurator/server/plugin.js +298 -0
  71. package/dist/configurator/server/seal.d.ts +2 -0
  72. package/dist/configurator/server/seal.d.ts.map +1 -0
  73. package/dist/configurator/server/seal.js +36 -0
  74. package/dist/configurator/server/sshKeys.d.ts +5 -0
  75. package/dist/configurator/server/sshKeys.d.ts.map +1 -0
  76. package/dist/configurator/server/sshKeys.js +28 -0
  77. package/dist/configurator/server/start.d.ts +12 -0
  78. package/dist/configurator/server/start.d.ts.map +1 -0
  79. package/dist/configurator/server/start.js +91 -0
  80. package/dist/configurator/testing.d.ts +11 -0
  81. package/dist/configurator/testing.d.ts.map +1 -0
  82. package/dist/configurator/testing.js +74 -0
  83. package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
  84. package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
  85. package/dist/configurator/ui/bindings/bindings.js +5 -0
  86. package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
  87. package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
  88. package/dist/configurator/ui/bindings/parsers.js +85 -0
  89. package/dist/configurator/ui/form/users.d.ts +11 -0
  90. package/dist/configurator/ui/form/users.d.ts.map +1 -0
  91. package/dist/configurator/ui/form/users.js +33 -0
  92. package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
  93. package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
  94. package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
  95. package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
  96. package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
  97. package/dist/configurator/ui/plan/templateValues.js +70 -0
  98. package/dist/configurator/workflows.d.ts +54 -0
  99. package/dist/configurator/workflows.d.ts.map +1 -0
  100. package/dist/configurator/workflows.js +161 -0
  101. package/dist/configurator-assets/forms/bindings.yml +265 -0
  102. package/dist/configurator-assets/templates/README.md +18 -0
  103. package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
  104. package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +96 -0
  105. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  106. package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
  107. package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
  108. package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
  109. package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
  110. package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
  111. package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
  112. package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
  113. package/dist/configurator-assets/ui/assets/index-DU1Y6E0b.js +169 -0
  114. package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
  115. package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
  116. package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
  117. package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
  118. package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
  119. package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
  120. package/dist/configurator-assets/ui/index.html +25 -0
  121. package/dist/environment/custom-types.d.ts +1 -0
  122. package/dist/environment/custom-types.d.ts.map +1 -1
  123. package/dist/environment/derived-variables.d.ts +18 -4
  124. package/dist/environment/derived-variables.d.ts.map +1 -1
  125. package/dist/environment/derived-variables.js +20 -4
  126. package/dist/environment/questions.d.ts +42 -9
  127. package/dist/environment/questions.d.ts.map +1 -1
  128. package/dist/environment/questions.js +71 -48
  129. package/dist/environment/registry.d.ts +15 -0
  130. package/dist/environment/registry.d.ts.map +1 -0
  131. package/dist/environment/registry.js +112 -0
  132. package/dist/environment/setup-environment.d.ts.map +1 -1
  133. package/dist/environment/setup-environment.js +145 -25
  134. package/dist/environment/templates.d.ts.map +1 -1
  135. package/dist/events/index.js +826 -210
  136. package/dist/migrations/add-notify-config.d.ts +40 -0
  137. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  138. package/dist/migrations/add-notify-config.js +249 -0
  139. package/dist/migrations/index.d.ts +9 -0
  140. package/dist/migrations/index.d.ts.map +1 -0
  141. package/dist/migrations/index.js +1306 -0
  142. package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
  143. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
  144. package/dist/migrations/move-declaration-to-declare-action.js +260 -0
  145. package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
  146. package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
  147. package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
  148. package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
  149. package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
  150. package/dist/migrations/persistent/check-upgrade-path.js +105 -0
  151. package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
  152. package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
  153. package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
  154. package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
  155. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
  156. package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +4 -62
  157. package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
  158. package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
  159. package/dist/migrations/replace-incomplete-flag.js +126 -0
  160. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  161. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  162. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  163. package/dist/migrations/utils.d.ts +61 -0
  164. package/dist/migrations/utils.d.ts.map +1 -0
  165. package/dist/migrations/utils.js +218 -0
  166. package/dist/notification/index.js +722 -82
  167. package/dist/roles/index.d.ts +2 -0
  168. package/dist/roles/index.d.ts.map +1 -0
  169. package/dist/roles/index.js +730 -0
  170. package/dist/scopes/index.d.ts +54 -94
  171. package/dist/scopes/index.js +15 -12
  172. package/dist/templates/charts-values/dependencies/values.yaml +5 -2
  173. package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -7
  174. package/dist/templates/charts-values/traefik/values.yaml +2 -0
  175. package/dist/verify/endpoints.d.ts +11 -0
  176. package/dist/verify/endpoints.d.ts.map +1 -1
  177. package/dist/verify/endpoints.js +21 -27
  178. package/opencrvs-toolkit-2.2.0-rc.e6591c5.tgz +0 -0
  179. package/package.json +17 -4
  180. package/tsconfig.build.json +11 -1
  181. package/tsconfig.build.tsbuildinfo +1 -1
  182. package/tsconfig.json +15 -6
  183. package/dist/migrations/add-translations.d.ts.map +0 -1
  184. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
  185. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
  186. package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
  187. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
  188. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
  189. package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
  190. package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
  191. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
  192. package/dist/migrations/v2.1/enable-telemetry.js +0 -455
  193. package/dist/migrations/v2.1/index.d.ts +0 -6
  194. package/dist/migrations/v2.1/index.d.ts.map +0 -1
  195. package/dist/migrations/v2.1/index.js +0 -50
  196. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
  197. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
  198. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
  199. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
  200. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
  201. package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
  202. package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
  203. package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
  204. package/dist/migrations/v2.1/remove-sentry.js +0 -354
  205. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
  206. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
  207. package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
  208. package/dist/migrations/v2.1/template-files.d.ts +0 -8
  209. package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
  210. package/dist/migrations/v2.1/template-files.js +0 -49
  211. package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
  212. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
  213. package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
  214. package/dist/migrations/v2.2/index.d.ts +0 -6
  215. package/dist/migrations/v2.2/index.d.ts.map +0 -1
  216. package/dist/migrations/v2.2/index.js +0 -456
  217. package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
  218. package/dist/templates/countryconfig-template/.tiltignore +0 -1
  219. package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
  220. package/dist/templates/countryconfig-template/Tiltfile +0 -112
  221. package/dist/templates/countryconfig-template/assets/README.md +0 -1
  222. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
  223. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
  224. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
  225. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
  226. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
  227. package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
  228. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
  229. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
  230. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
  231. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
  232. package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
  233. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
  234. package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
  235. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
  236. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
  237. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
  238. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
  239. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
  240. package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
  241. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
  242. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
  243. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
  244. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
  245. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
  246. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
  247. package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
  248. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
  249. package/opencrvs-toolkit-2.2.0-rc.ac299dc.tgz +0 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORMATTERS = exports.PARSERS = void 0;
4
+ exports.formatWith = formatWith;
5
+ exports.parseWith = parseWith;
6
+ /*
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
10
+ *
11
+ * OpenCRVS is also distributed under the terms of the Civil Registration
12
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
13
+ *
14
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
15
+ */
16
+ const users_ts_1 = require("../form/users.js");
17
+ const text = (raw) => (typeof raw === 'string' || typeof raw === 'number' || typeof raw === 'boolean' ? String(raw).trim() : '');
18
+ exports.PARSERS = {
19
+ string: (raw) => text(raw) || undefined,
20
+ boolean: (raw) => {
21
+ const value = text(raw).toLowerCase();
22
+ return value === 'true' ? true : value === 'false' ? false : undefined;
23
+ },
24
+ // GitHub variable "10.0.0.1, 10.0.0.2" -> table rows. An empty string means "no workers".
25
+ 'csv-to-ip-rows': (raw) => {
26
+ if (typeof raw !== 'string')
27
+ return undefined;
28
+ return raw
29
+ .split(',')
30
+ .map((ip) => ip.trim())
31
+ .filter(Boolean)
32
+ .map((ip) => ({ ip }));
33
+ },
34
+ // Host addresses read from the inventory -> table rows.
35
+ 'ip-rows': (raw) => {
36
+ if (!Array.isArray(raw))
37
+ return undefined;
38
+ const rows = raw.map((ip) => text(ip)).filter(Boolean).map((ip) => ({ ip }));
39
+ return rows.length ? rows : undefined;
40
+ },
41
+ // `all.vars.users` -> USERS table rows. Older inventories used `sudoer` instead of `role`.
42
+ users: (raw) => {
43
+ if (!Array.isArray(raw))
44
+ return undefined;
45
+ return raw.map((entry) => {
46
+ const user = (entry !== null && entry !== void 0 ? entry : {});
47
+ const keys = Array.isArray(user.ssh_keys) ? user.ssh_keys.map((key) => text(key)).filter(Boolean) : [];
48
+ return {
49
+ name: text(user.name),
50
+ role: user.role === 'admin' || user.role === 'operator' ? user.role : user.sudoer ? 'admin' : 'operator',
51
+ state: user.state === 'absent' ? 'absent' : 'present',
52
+ ssh_keys: keys.join('\n')
53
+ };
54
+ });
55
+ }
56
+ };
57
+ // The other direction: a form value as it is written. Used for file templates, where a list
58
+ // stays a list, and for GitHub, where `String(...)` of the result is stored.
59
+ exports.FORMATTERS = {
60
+ string: (value) => (typeof value === 'string' ? value.trim() : String(value)),
61
+ boolean: (value) => value === true || value === 'true',
62
+ // table rows -> "10.0.0.1,10.0.0.2" (a GitHub variable)
63
+ 'csv-to-ip-rows': (value) => ipsOf(value).join(','),
64
+ // table rows -> ["10.0.0.1", "10.0.0.2"] (a template list)
65
+ 'ip-rows': (value) => ipsOf(value),
66
+ // table rows -> the users the inventory template expects
67
+ users: (value) => (0, users_ts_1.rowsToUsers)(value)
68
+ };
69
+ function ipsOf(rows) {
70
+ if (!Array.isArray(rows))
71
+ return [];
72
+ return rows.map((row) => text(row === null || row === void 0 ? void 0 : row.ip)).filter(Boolean);
73
+ }
74
+ function formatWith(name, value) {
75
+ const formatter = exports.FORMATTERS[name !== null && name !== void 0 ? name : 'string'];
76
+ if (!formatter)
77
+ throw new Error(`Unknown parser "${name}"`);
78
+ return formatter(value);
79
+ }
80
+ function parseWith(name, raw) {
81
+ const parser = exports.PARSERS[name !== null && name !== void 0 ? name : 'string'];
82
+ if (!parser)
83
+ throw new Error(`Unknown parser "${name}"`);
84
+ return parser(raw);
85
+ }
@@ -0,0 +1,11 @@
1
+ export interface User {
2
+ name: string;
3
+ ssh_keys: string[];
4
+ state: 'present' | 'absent';
5
+ role: 'admin' | 'operator';
6
+ }
7
+ export declare function parseKeys(text: unknown): string[];
8
+ export declare const areValidKeys: (text: unknown) => boolean;
9
+ export declare function rowsToUsers(rows: unknown): User[];
10
+ export declare const countUsersWithoutKeys: (rows: unknown) => number;
11
+ //# sourceMappingURL=users.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../../../src/configurator/ui/form/users.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC3B,IAAI,EAAE,OAAO,GAAG,UAAU,CAAA;CAC3B;AAWD,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAMjD;AAOD,eAAO,MAAM,YAAY,SAAU,OAAO,YAAyD,CAAA;AAEnG,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,CAUjD;AAED,eAAO,MAAM,qBAAqB,SAAU,OAAO,WACoB,CAAA"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countUsersWithoutKeys = exports.areValidKeys = void 0;
4
+ exports.parseKeys = parseKeys;
5
+ exports.rowsToUsers = rowsToUsers;
6
+ // Same rule as the CLI: blank lines and lines starting with # are ignored.
7
+ function parseKeys(text) {
8
+ if (typeof text !== 'string')
9
+ return [];
10
+ return text
11
+ .split('\n')
12
+ .map((line) => line.trim())
13
+ .filter((line) => line && !line.startsWith('#'));
14
+ }
15
+ // Stricter than the CLI, which accepts anything: every key line must look like an
16
+ // OpenSSH public key, which also rejects a pasted private key.
17
+ const PUBLIC_KEY = /^(ssh-(rsa|ed25519|dss)|ecdsa-sha2-nistp(256|384|521)|sk-(ssh-ed25519|ecdsa-sha2-nistp256)@openssh\.com)\s+[A-Za-z0-9+/]+={0,3}(\s+.*)?$/;
18
+ const areValidKeys = (text) => parseKeys(text).every((key) => PUBLIC_KEY.test(key));
19
+ exports.areValidKeys = areValidKeys;
20
+ function rowsToUsers(rows) {
21
+ if (!Array.isArray(rows))
22
+ return [];
23
+ return rows
24
+ .filter((row) => { var _a; return (_a = row === null || row === void 0 ? void 0 : row.name) === null || _a === void 0 ? void 0 : _a.trim(); })
25
+ .map((row) => { var _a, _b; return ({
26
+ name: row.name.trim(),
27
+ ssh_keys: parseKeys(row.ssh_keys),
28
+ state: (_a = row.state) !== null && _a !== void 0 ? _a : 'present',
29
+ role: (_b = row.role) !== null && _b !== void 0 ? _b : 'operator'
30
+ }); });
31
+ }
32
+ const countUsersWithoutKeys = (rows) => rowsToUsers(rows).filter((user) => user.ssh_keys.length === 0).length;
33
+ exports.countUsersWithoutKeys = countUsersWithoutKeys;
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_HOSTS: Record<string, (environment: string) => string>;
2
+ //# sourceMappingURL=dependencyHosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencyHosts.d.ts","sourceRoot":"","sources":["../../../../src/configurator/ui/plan/dependencyHosts.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAMzE,CAAA"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_HOSTS = void 0;
4
+ /*
5
+ * This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
+ *
9
+ * OpenCRVS is also distributed under the terms of the Civil Registration
10
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
11
+ *
12
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
13
+ */
14
+ // Where each built-in component runs, inside the cluster: the address the chart templates used before the
15
+ // hosts became questions, by the question that asks for it. S3 is RustFS, because the installer has no
16
+ // question for MinIO. The OpenTelemetry Collector's is an endpoint, with its protocol, not just a host.
17
+ //
18
+ // This is the one place the addresses are written. Everything else reads it:
19
+ //
20
+ // - The form pre-fills each question with it (`defaultAddress(...)` in forms/wizard.yml, see src/form/functions.ts).
21
+ // - The host questions are only on screen while "Use built-in component" is unchecked. A hidden question
22
+ // is not part of the answers, so for a built-in component nothing arrives to fill `host:` in the
23
+ // services chart and the dependencies chart. Rendering gives every template variable that such a question
24
+ // feeds this address when it has no answer (see `builtInValues` in templateValues.ts); without it `host:`
25
+ // would be empty. A new entry here needs only its binding in forms/bindings.yml.
26
+ // - Reading an environment back from the services file, an address equal to its default means "built in",
27
+ // and any other host is one the user entered (see inferToggles in src/form/infer.ts). A "Use built-in
28
+ // component" flag stored in the dependencies chart takes precedence, so this is only a fallback.
29
+ // - The sample environments render with the same addresses as the form (scripts/fixtures.ts).
30
+ exports.DEFAULT_HOSTS = {
31
+ ELASTICSEARCH_HOST: (environment) => `elasticsearch.opencrvs-deps-${environment}.svc.cluster.local`,
32
+ S3_HOST: (environment) => `rustfs-0.rustfs.opencrvs-deps-${environment}.svc.cluster.local`,
33
+ POSTGRES_HOST: (environment) => `postgres-0.postgres.opencrvs-deps-${environment}.svc.cluster.local`,
34
+ REDIS_HOST: (environment) => `redis-0.redis.opencrvs-deps-${environment}.svc.cluster.local`,
35
+ OTEL_COLLECTOR_ENDPOINT: (environment) => `http://opentelemetry-collector.opencrvs-deps-${environment}.svc.cluster.local:4317`
36
+ };
@@ -0,0 +1,11 @@
1
+ import type { Bindings } from '../bindings/bindings.ts';
2
+ interface Context {
3
+ environment: string;
4
+ answers: Record<string, unknown>;
5
+ fromQuestions: Record<string, unknown>;
6
+ }
7
+ export declare const DERIVED: Record<string, (context: Context) => unknown>;
8
+ export declare function builtInValues(template: string, environment: string, bindings: Bindings): Record<string, string>;
9
+ export declare function templateValues(template: string, environment: string, answers: Record<string, unknown>, bindings: Bindings): Record<string, unknown>;
10
+ export {};
11
+ //# sourceMappingURL=templateValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateValues.d.ts","sourceRoot":"","sources":["../../../../src/configurator/ui/plan/templateValues.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAIvD,UAAU,OAAO;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACvC;AAGD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAYjE,CAAA;AAmBD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO/G;AAKD,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DERIVED = void 0;
4
+ exports.builtInValues = builtInValues;
5
+ exports.templateValues = templateValues;
6
+ const parsers_ts_1 = require("../bindings/parsers.js");
7
+ const dependencyHosts_ts_1 = require("./dependencyHosts.js");
8
+ // Values worked out from other values, the way `yarn environment:init` does.
9
+ exports.DERIVED = {
10
+ env: ({ environment }) => environment,
11
+ // A cluster is a single node unless it has workers or a backup server (the CLI passes a string).
12
+ single_node: ({ fromQuestions }) => { var _a; return ((_a = fromQuestions.kube_worker_nodes) === null || _a === void 0 ? void 0 : _a.length) || fromQuestions.backup_host ? 'false' : 'true'; },
13
+ backup_enabled: ({ answers }) => answers.BACKUP_OR_RESTORE === 'backup',
14
+ restore_enabled: ({ answers }) => answers.BACKUP_OR_RESTORE === 'restore',
15
+ opencrvs_environment: ({ environment }) => environment,
16
+ // On unless the question says otherwise (the template reads it only to switch tracing on).
17
+ monitoring_enabled: ({ answers }) => answers.MONITORING_ENABLED !== false,
18
+ lets_encrypt: ({ answers }) => answers.TRAEFIK_MODE === 'lets_encrypt',
19
+ static_ssl: ({ answers }) => answers.TRAEFIK_MODE === 'static_ssl'
20
+ };
21
+ // The template variable a file target feeds. `users.name` with collect: container belongs to `users`.
22
+ const variableOf = (target) => (target.collect === 'container' ? target.var.split('.')[0] : target.var);
23
+ // Every file target of a template, with the question that feeds it.
24
+ function* fileTargets(template, bindings) {
25
+ for (const [question, binding] of Object.entries(bindings.bindings)) {
26
+ for (const target of binding.targets) {
27
+ if (target.source === 'file' && target.template === template)
28
+ yield { question, target, variable: variableOf(target) };
29
+ }
30
+ }
31
+ }
32
+ // The address of a built-in component, for each variable of the template that a question with one feeds
33
+ // (see DEFAULT_HOSTS). A component that is built in has no host question on screen, and a hidden question is not
34
+ // part of the answers, so the component runs at its address in the cluster. One address can feed several
35
+ // variables: the collector endpoint is in the services chart and in Traefik's tracing block.
36
+ // Nothing here is listed by hand: the questions come from DEFAULT_HOSTS and the variables from bindings.yml.
37
+ function builtInValues(template, environment, bindings) {
38
+ const values = {};
39
+ for (const { question, variable } of fileTargets(template, bindings)) {
40
+ const address = dependencyHosts_ts_1.DEFAULT_HOSTS[question];
41
+ if (address)
42
+ values[variable] = address(environment);
43
+ }
44
+ return values;
45
+ }
46
+ // The data a template is rendered with: defaults, then question values (reverse of how they are
47
+ // read back), then the built-in addresses of what has no answer, then derived values.
48
+ // `answers` must only hold what is on screen (see src/form/active.ts).
49
+ function templateValues(template, environment, answers, bindings) {
50
+ var _a;
51
+ var _b, _c;
52
+ const fromQuestions = {};
53
+ for (const { question, target, variable } of fileTargets(template, bindings)) {
54
+ if (answers[question] !== undefined)
55
+ fromQuestions[variable] = (0, parsers_ts_1.formatWith)(target.parse, answers[question]);
56
+ }
57
+ const config = (_a = bindings.templates) === null || _a === void 0 ? void 0 : _a[template];
58
+ const values = Object.assign(Object.assign({}, ((_b = config === null || config === void 0 ? void 0 : config.defaults) !== null && _b !== void 0 ? _b : {})), fromQuestions);
59
+ for (const [variable, address] of Object.entries(builtInValues(template, environment, bindings))) {
60
+ if (!values[variable])
61
+ values[variable] = address;
62
+ }
63
+ for (const name of (_c = config === null || config === void 0 ? void 0 : config.derived) !== null && _c !== void 0 ? _c : []) {
64
+ const derive = exports.DERIVED[name];
65
+ if (!derive)
66
+ throw new Error(`${template}: no derived value named "${name}"`);
67
+ values[name] = derive({ environment, answers, fromQuestions });
68
+ }
69
+ return values;
70
+ }
@@ -0,0 +1,54 @@
1
+ /** Workflows that act on a server: they list the environments that have an inventory. */
2
+ export declare const INFRASTRUCTURE_WORKFLOWS: readonly ['provision.yml', 'reset-2fa.yml'];
3
+ /** Workflows that act on the cluster: they list the environments that have Helm values. */
4
+ export declare const APPLICATION_WORKFLOWS: readonly ['deploy-dependencies.yml', 'deploy-opencrvs.yml', 'clear-all-data.yml', 'seed-data.yml', 'reindex.yml', 'github-to-k8s-sync-env.yml'];
5
+ /** A workflow file does not have the `environment` choice input this tool maintains. */
6
+ export declare class WorkflowFormatError extends Error {
7
+ }
8
+ export interface Environments {
9
+ /** Environments with an `inventory.yml`. */
10
+ infrastructure: string[];
11
+ /** Environments with an `opencrvs-services` folder. */
12
+ application: string[];
13
+ }
14
+ export declare function listEnvironments(root: string): Environments;
15
+ export interface OptionsUpdate {
16
+ content: string;
17
+ warnings: string[];
18
+ }
19
+ /**
20
+ * Sets the options of the `environment` input of a workflow file to
21
+ * `environments`, and leaves every other byte of the file alone.
22
+ *
23
+ * Only the `environment` list is touched, wherever it is in the file: workflows
24
+ * such as `provision.yml` have other `options` lists (the tags) as well.
25
+ *
26
+ * Environments already in the list keep their order and new ones are appended
27
+ * in the order given, so a list that holds exactly these environments, in any
28
+ * order, is not rewritten at all. When it is, comments inside the list are lost.
29
+ */
30
+ export declare function updateEnvironmentOptions(content: string, environments: readonly string[]): OptionsUpdate;
31
+ type WorkflowStatus = 'updated' | 'unchanged'
32
+ /** The repository does not have this workflow. */
33
+ | 'not-found'
34
+ /** There is no environment to list, so the workflow is left as it is. */
35
+ | 'no-environments';
36
+ export interface WorkflowChange {
37
+ /** Relative to the repository root. */
38
+ file: string;
39
+ environments: string[];
40
+ status: WorkflowStatus;
41
+ before: string;
42
+ after: string;
43
+ warnings: string[];
44
+ }
45
+ /**
46
+ * Works out what every workflow needs, writing nothing. It throws on the first
47
+ * workflow that does not have the expected `environment` input, so that nothing
48
+ * is written when one of them cannot be updated.
49
+ */
50
+ export declare function planWorkflowUpdates(root: string): WorkflowChange[];
51
+ /** Writes the workflows of a plan that are `updated`. Returns their paths. */
52
+ export declare function applyWorkflowUpdates(root: string, changes: readonly WorkflowChange[]): string[];
53
+ export {};
54
+ //# sourceMappingURL=workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/configurator/workflows.ts"],"names":[],"mappings":"AAqBA,yFAAyF;AACzF,eAAO,MAAM,wBAAwB,YACnC,eAAe,EACf,eAAe,CACP,CAAA;AAEV,2FAA2F;AAC3F,eAAO,MAAM,qBAAqB,YAChC,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,4BAA4B,CACpB,CAAA;AASV,wFAAwF;AACxF,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,uDAAuD;IACvD,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAgB3D;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,aAAa,CAwEf;AAED,KAAK,cAAc,GACf,SAAS,GACT,WAAW;AACb,kDAAkD;GAChD,WAAW;AACb,yEAAyE;GACvE,iBAAiB,CAAA;AAErB,MAAM,WAAW,cAAc;IAC7B,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,MAAM,EAAE,cAAc,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAwCD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAWlE;AAED,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,MAAM,EAAE,CAMV"}
@@ -0,0 +1,161 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.WorkflowFormatError = exports.APPLICATION_WORKFLOWS = exports.INFRASTRUCTURE_WORKFLOWS = void 0;
14
+ exports.listEnvironments = listEnvironments;
15
+ exports.updateEnvironmentOptions = updateEnvironmentOptions;
16
+ exports.planWorkflowUpdates = planWorkflowUpdates;
17
+ exports.applyWorkflowUpdates = applyWorkflowUpdates;
18
+ const node_fs_1 = require("node:fs");
19
+ const node_path_1 = require("node:path");
20
+ const yaml_1 = require("yaml");
21
+ const paths_1 = require("./paths");
22
+ /** Workflows that act on a server: they list the environments that have an inventory. */
23
+ exports.INFRASTRUCTURE_WORKFLOWS = [
24
+ 'provision.yml',
25
+ 'reset-2fa.yml'
26
+ ];
27
+ /** Workflows that act on the cluster: they list the environments that have Helm values. */
28
+ exports.APPLICATION_WORKFLOWS = [
29
+ 'deploy-dependencies.yml',
30
+ 'deploy-opencrvs.yml',
31
+ 'clear-all-data.yml',
32
+ 'seed-data.yml',
33
+ 'reindex.yml',
34
+ 'github-to-k8s-sync-env.yml'
35
+ ];
36
+ const ENVIRONMENT_INPUT = [
37
+ 'on',
38
+ 'workflow_dispatch',
39
+ 'inputs',
40
+ 'environment'
41
+ ];
42
+ /** A workflow file does not have the `environment` choice input this tool maintains. */
43
+ class WorkflowFormatError extends Error {
44
+ }
45
+ exports.WorkflowFormatError = WorkflowFormatError;
46
+ function listEnvironments(root) {
47
+ const directory = (0, node_path_1.join)(root, paths_1.ENVIRONMENTS_DIR);
48
+ const names = (0, paths_1.isDirectory)(directory)
49
+ ? (0, node_fs_1.readdirSync)(directory)
50
+ .filter((name) => (0, paths_1.isDirectory)((0, node_path_1.join)(directory, name)))
51
+ .sort()
52
+ : [];
53
+ return {
54
+ infrastructure: names.filter((name) => (0, node_fs_1.existsSync)((0, node_path_1.join)(directory, name, paths_1.INVENTORY_FILE_NAME))),
55
+ application: names.filter((name) => (0, paths_1.isDirectory)((0, node_path_1.join)(directory, name, 'opencrvs-services')))
56
+ };
57
+ }
58
+ /**
59
+ * Sets the options of the `environment` input of a workflow file to
60
+ * `environments`, and leaves every other byte of the file alone.
61
+ *
62
+ * Only the `environment` list is touched, wherever it is in the file: workflows
63
+ * such as `provision.yml` have other `options` lists (the tags) as well.
64
+ *
65
+ * Environments already in the list keep their order and new ones are appended
66
+ * in the order given, so a list that holds exactly these environments, in any
67
+ * order, is not rewritten at all. When it is, comments inside the list are lost.
68
+ */
69
+ function updateEnvironmentOptions(content, environments) {
70
+ const document = (0, yaml_1.parseDocument)(content);
71
+ if (document.errors.length > 0) {
72
+ throw new WorkflowFormatError(`Invalid YAML: ${document.errors[0].message}`);
73
+ }
74
+ const options = document.getIn([...ENVIRONMENT_INPUT, 'options'], true);
75
+ if (!(0, yaml_1.isSeq)(options)) {
76
+ throw new WorkflowFormatError('Expected a list at on.workflow_dispatch.inputs.environment.options');
77
+ }
78
+ if (options.flow || !options.range) {
79
+ throw new WorkflowFormatError('on.workflow_dispatch.inputs.environment.options has to be a block list, one "- name" per line');
80
+ }
81
+ const warnings = [];
82
+ const fallback = document.getIn([...ENVIRONMENT_INPUT, 'default']);
83
+ if (typeof fallback === 'string' && !environments.includes(fallback)) {
84
+ warnings.push(`the default environment "${fallback}" is not one of the options`);
85
+ }
86
+ // Environments that are still there keep their place, new ones follow. A list somebody ordered by
87
+ // hand (the default first, say) is therefore not reshuffled, and an added environment is one line.
88
+ const current = options.items.map((item) => String((0, yaml_1.isScalar)(item) ? item.value : item));
89
+ const target = [
90
+ ...current.filter((name, i) => environments.includes(name) && current.indexOf(name) === i),
91
+ ...environments.filter((name) => !current.includes(name))
92
+ ];
93
+ if (target.length === current.length &&
94
+ target.every((name, i) => name === current[i])) {
95
+ return { content, warnings };
96
+ }
97
+ // The list runs from its first "-" to the end of its last line, line break included.
98
+ const [start, end] = options.range;
99
+ const indentation = content.slice(content.lastIndexOf('\n', start - 1) + 1, start);
100
+ if (indentation.trim() !== '') {
101
+ throw new WorkflowFormatError('on.workflow_dispatch.inputs.environment.options is not on its own lines');
102
+ }
103
+ const eol = content.includes('\r\n') ? '\r\n' : '\n';
104
+ const endsWithLineBreak = content.slice(start, end).endsWith('\n');
105
+ const items = target
106
+ .map((name) => `- ${(0, yaml_1.stringify)(name, { lineWidth: 0 }).trimEnd()}`)
107
+ .join(eol + indentation);
108
+ return {
109
+ content: content.slice(0, start) +
110
+ items +
111
+ (endsWithLineBreak ? eol : '') +
112
+ content.slice(end),
113
+ warnings
114
+ };
115
+ }
116
+ function planWorkflow(root, workflow, environments) {
117
+ const file = (0, node_path_1.join)(paths_1.WORKFLOWS_DIR, workflow);
118
+ const path = (0, node_path_1.join)(root, file);
119
+ const change = {
120
+ file,
121
+ environments,
122
+ before: '',
123
+ after: '',
124
+ warnings: []
125
+ };
126
+ if (!(0, node_fs_1.existsSync)(path))
127
+ return Object.assign(Object.assign({}, change), { status: 'not-found' });
128
+ const before = (0, node_fs_1.readFileSync)(path, 'utf8');
129
+ if (environments.length === 0)
130
+ return Object.assign(Object.assign({}, change), { status: 'no-environments', before, after: before });
131
+ try {
132
+ const { content, warnings } = updateEnvironmentOptions(before, environments);
133
+ return Object.assign(Object.assign({}, change), { status: content === before ? 'unchanged' : 'updated', before, after: content, warnings });
134
+ }
135
+ catch (error) {
136
+ if (error instanceof WorkflowFormatError) {
137
+ throw new WorkflowFormatError(`${file}: ${error.message}`);
138
+ }
139
+ throw error;
140
+ }
141
+ }
142
+ /**
143
+ * Works out what every workflow needs, writing nothing. It throws on the first
144
+ * workflow that does not have the expected `environment` input, so that nothing
145
+ * is written when one of them cannot be updated.
146
+ */
147
+ function planWorkflowUpdates(root) {
148
+ const { infrastructure, application } = listEnvironments(root);
149
+ return [
150
+ ...exports.INFRASTRUCTURE_WORKFLOWS.map((workflow) => planWorkflow(root, workflow, infrastructure)),
151
+ ...exports.APPLICATION_WORKFLOWS.map((workflow) => planWorkflow(root, workflow, application))
152
+ ];
153
+ }
154
+ /** Writes the workflows of a plan that are `updated`. Returns their paths. */
155
+ function applyWorkflowUpdates(root, changes) {
156
+ const updated = changes.filter((change) => change.status === 'updated');
157
+ for (const change of updated) {
158
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, change.file), change.after, 'utf8');
159
+ }
160
+ return updated.map((change) => change.file);
161
+ }