@opencrvs/toolkit 2.1.2 → 2.2.0-rc.19ec10b

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 (177) hide show
  1. package/build.sh +9 -14
  2. package/create-countryconfig/package.json +1 -1
  3. package/dist/application-config/index.js +57 -14
  4. package/dist/authentication/index.d.ts +2 -1
  5. package/dist/authentication/index.js +34 -14
  6. package/dist/cli.js +1491 -2020
  7. package/dist/commons/api/router.d.ts +1564 -248
  8. package/dist/commons/application-config/index.d.ts +3 -3
  9. package/dist/commons/conditionals/conditionals.d.ts +58 -7
  10. package/dist/commons/conditionals/index.d.ts +1 -0
  11. package/dist/commons/conditionals/validate.d.ts +6 -1
  12. package/dist/commons/events/ActionConfig.d.ts +146 -20
  13. package/dist/commons/events/ActionDocument.d.ts +89 -0
  14. package/dist/commons/events/ActionInput.d.ts +56 -4
  15. package/dist/commons/events/ActionStatus.d.ts +2 -2
  16. package/dist/commons/events/ActionType.d.ts +13 -1
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -0
  18. package/dist/commons/events/AuditLog.d.ts +4 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  20. package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
  21. package/dist/commons/events/Draft.d.ts +36 -1
  22. package/dist/commons/events/EventConfig.d.ts +473 -6
  23. package/dist/commons/events/EventDocument.d.ts +90 -0
  24. package/dist/commons/events/EventIndex.d.ts +44 -6
  25. package/dist/commons/events/EventInput.d.ts +1 -0
  26. package/dist/commons/events/EventMetadata.d.ts +24 -1
  27. package/dist/commons/events/EventStatus.d.ts +1 -0
  28. package/dist/commons/events/FieldConfig.d.ts +11 -1
  29. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  30. package/dist/commons/events/Flag.d.ts +1 -7
  31. package/dist/commons/events/PlainDate.d.ts +6 -0
  32. package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
  33. package/dist/commons/events/defineConfig.d.ts +7 -2
  34. package/dist/commons/events/event.d.ts +20 -1
  35. package/dist/commons/events/eventConfigValidation.d.ts +26 -1
  36. package/dist/commons/events/field.d.ts +37 -0
  37. package/dist/commons/events/index.d.ts +3 -0
  38. package/dist/commons/events/locations.d.ts +1 -1
  39. package/dist/commons/events/scopes.d.ts +4 -1
  40. package/dist/commons/events/state/flags.d.ts +1 -1
  41. package/dist/commons/events/state/index.d.ts +11 -2
  42. package/dist/commons/events/state/utils.d.ts +11 -1
  43. package/dist/commons/events/test.utils.d.ts +89 -7
  44. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  45. package/dist/commons/events/utils.d.ts +90 -10
  46. package/dist/commons/users/Role.d.ts +23 -0
  47. package/dist/commons/users/User.d.ts +263 -0
  48. package/dist/commons/users/authentication.d.ts +67 -0
  49. package/dist/commons/users/index.d.ts +5 -0
  50. package/dist/commons/users/roleValidations.d.ts +15 -0
  51. package/dist/commons/users/scopes.d.ts +1402 -0
  52. package/dist/commons/users/userReferences.d.ts +176 -0
  53. package/dist/conditionals/index.js +29 -9
  54. package/dist/environment/custom-types.d.ts +1 -0
  55. package/dist/environment/custom-types.d.ts.map +1 -1
  56. package/dist/environment/derived-variables.d.ts +24 -4
  57. package/dist/environment/derived-variables.d.ts.map +1 -1
  58. package/dist/environment/derived-variables.js +27 -4
  59. package/dist/environment/questions.d.ts +42 -9
  60. package/dist/environment/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +71 -48
  62. package/dist/environment/registry.d.ts +15 -0
  63. package/dist/environment/registry.d.ts.map +1 -0
  64. package/dist/environment/registry.js +112 -0
  65. package/dist/environment/setup-environment.d.ts.map +1 -1
  66. package/dist/environment/setup-environment.js +165 -35
  67. package/dist/environment/templates.d.ts.map +1 -1
  68. package/dist/events/index.js +2050 -1156
  69. package/dist/migrations/add-notify-config.d.ts +40 -0
  70. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  71. package/dist/migrations/add-notify-config.js +249 -0
  72. package/dist/migrations/index.d.ts +9 -0
  73. package/dist/migrations/index.d.ts.map +1 -0
  74. package/dist/migrations/index.js +1306 -0
  75. package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
  76. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
  77. package/dist/migrations/move-declaration-to-declare-action.js +260 -0
  78. package/dist/migrations/{v2.1 → persistent}/add-translations.d.ts +7 -1
  79. package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
  80. package/dist/migrations/{v2.1 → persistent}/add-translations.js +14 -12
  81. package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
  82. package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
  83. package/dist/migrations/persistent/check-upgrade-path.js +105 -0
  84. package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
  85. package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
  86. package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
  87. package/dist/migrations/read-declaration-through-helper.d.ts +39 -0
  88. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
  89. package/dist/migrations/read-declaration-through-helper.js +199 -0
  90. package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
  91. package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
  92. package/dist/migrations/replace-incomplete-flag.js +126 -0
  93. package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
  94. package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
  95. package/dist/migrations/resolve-versioned-event-config.js +353 -0
  96. package/dist/migrations/utils.d.ts +61 -0
  97. package/dist/migrations/utils.d.ts.map +1 -0
  98. package/dist/migrations/utils.js +218 -0
  99. package/dist/notification/index.js +1081 -209
  100. package/dist/roles/index.d.ts +2 -0
  101. package/dist/roles/index.d.ts.map +1 -0
  102. package/dist/roles/index.js +730 -0
  103. package/dist/scopes/index.d.ts +83 -100
  104. package/dist/scopes/index.js +29 -13
  105. package/dist/templates/charts-values/dependencies/values.yaml +6 -3
  106. package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -10
  107. package/dist/templates/charts-values/traefik/values.yaml +4 -3
  108. package/dist/verify/endpoints.d.ts +11 -0
  109. package/dist/verify/endpoints.d.ts.map +1 -1
  110. package/dist/verify/endpoints.js +21 -27
  111. package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
  112. package/package.json +5 -3
  113. package/tsconfig.build.tsbuildinfo +1 -1
  114. package/tsconfig.json +3 -5
  115. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
  116. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
  117. package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
  118. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
  119. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
  120. package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
  121. package/dist/migrations/v2.1/add-translations.d.ts.map +0 -1
  122. package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
  123. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
  124. package/dist/migrations/v2.1/enable-telemetry.js +0 -455
  125. package/dist/migrations/v2.1/index.d.ts +0 -6
  126. package/dist/migrations/v2.1/index.d.ts.map +0 -1
  127. package/dist/migrations/v2.1/index.js +0 -2170
  128. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -14
  129. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
  130. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
  131. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
  132. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
  133. package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
  134. package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
  135. package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
  136. package/dist/migrations/v2.1/remove-sentry.js +0 -354
  137. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
  138. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
  139. package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
  140. package/dist/migrations/v2.1/template-files.d.ts +0 -8
  141. package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
  142. package/dist/migrations/v2.1/template-files.js +0 -49
  143. package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -8
  144. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
  145. package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
  146. package/dist/templates/countryconfig-template/.tiltignore +0 -1
  147. package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
  148. package/dist/templates/countryconfig-template/Tiltfile +0 -112
  149. package/dist/templates/countryconfig-template/assets/README.md +0 -1
  150. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
  151. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
  152. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
  153. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
  154. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
  155. package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
  156. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
  157. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
  158. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
  159. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
  160. package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
  161. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
  162. package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
  163. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
  164. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
  165. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
  166. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
  167. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
  168. package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
  169. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
  170. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
  171. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
  172. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
  173. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
  174. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
  175. package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
  176. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
  177. package/opencrvs-toolkit-2.1.2.tgz +0 -0
@@ -1,14 +0,0 @@
1
- type Outcome = 'copied' | 'kept' | 'merged' | 'conflict' | 'dropped' | 'exists' | 'exists-differs' | 'not-moved';
2
- export interface AssetsMigrationResult {
3
- /** Paths relative to `assets/`, by what happened to them. */
4
- outcomes: Record<string, Outcome>;
5
- /** Paths relative to `infrastructure/` that can be removed. */
6
- migrated: string[];
7
- }
8
- export type ReadBase = (file: string) => Uint8Array | undefined;
9
- export declare function migrateInfrastructureToAssets(cwd: string, templateDir: string, readBase: ReadBase): AssetsMigrationResult;
10
- /** Removes migrated files and any directories they leave empty. */
11
- export declare function removeMigrated(cwd: string, migrated: string[]): void;
12
- declare function main(dockerSwarm?: boolean): Promise<void>;
13
- export { main };
14
- //# sourceMappingURL=migrate-infrastructure-to-assets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate-infrastructure-to-assets.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/migrate-infrastructure-to-assets.ts"],"names":[],"mappings":"AAiHA,KAAK,OAAO,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,UAAU,GACV,SAAS,GACT,QAAQ,GACR,gBAAgB,GAChB,WAAW,CAAA;AAEf,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAA;AAyF/D,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,qBAAqB,CAmGvB;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAwB7D;AAeD,iBAAe,IAAI,CAAC,WAAW,UAAQ,iBAiFtC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,348 +0,0 @@
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.migrateInfrastructureToAssets = migrateInfrastructureToAssets;
26
- exports.removeMigrated = removeMigrated;
27
- exports.main = main;
28
- /**
29
- * Codemod: move `infrastructure/` into the v2.1 `assets/` directory, merging
30
- * the country's changes with the template's.
31
- *
32
- * The assets image (Dockerfile.assets) is now built from `assets/` with a
33
- * single `COPY assets /assets`, and the charts copy `/assets/metabase`,
34
- * `/assets/postgres` and `/assets/elasticsearch` out of it.
35
- *
36
- * What it does, for every file under `infrastructure/{metabase,postgres,
37
- * deployment,elasticsearch}/` and the template's `assets/`, going to the same
38
- * path under `assets/`:
39
- * - template only → copied from the template
40
- * - unchanged since v2.0 → the template's version (or dropped,
41
- * when the template no longer has it)
42
- * - changed by the country only → the country's version
43
- * - changed on both sides → 3-way merged (`git merge-file`), with
44
- * conflict markers left for review
45
- * - country only → moved across as is
46
- * The v2.0 version of each file, used as the merge base, is read from
47
- * opencrvs-farajaland's release/v2.0.0 on GitHub.
48
- *
49
- * `assets/elasticsearch/reindex.sh`, which the reindex job runs, is built from
50
- * `infrastructure/deployment/reindex.sh` so a customised reindex script
51
- * carries over.
52
- *
53
- * `postgres/on-deploy.sh` is never moved: the data-migration-analytics job
54
- * runs every `*.sh` in `/assets/postgres`, and the chart ships its own
55
- * on-deploy script. The v2.0 Dockerfile.assets deleted it from the image for
56
- * the same reason.
57
- *
58
- * Then `Dockerfile.assets` is replaced with the template's, the migrated files
59
- * are removed from `infrastructure/` (kept with `--docker-swarm`), and the
60
- * result is staged. Files with conflicts are left unstaged. Anything else in
61
- * `infrastructure/`, such as Docker Swarm configuration, is left in place.
62
- *
63
- * Caveats:
64
- * - Existing files under `assets/` are never overwritten, so running it
65
- * again, or after migrating by hand, leaves them alone. The
66
- * `infrastructure/` original is then only removed when identical.
67
- * - Binary files changed by the country keep the country's version.
68
- * - Requires network access to raw.githubusercontent.com. Without it
69
- * nothing is changed and the step is reported as skipped.
70
- */
71
- const child_process_1 = require("child_process");
72
- const fs_1 = require("fs");
73
- const os_1 = require("os");
74
- const path_1 = __importDefault(require("path"));
75
- const template_files_1 = require("./template-files");
76
- const INFRASTRUCTURE_DIR = 'infrastructure';
77
- const ASSETS_DIR = 'assets';
78
- const BASE_URL = 'https://raw.githubusercontent.com/opencrvs/opencrvs-farajaland/release/v2.0.0/infrastructure';
79
- /** Assets built from a differently named v2.0 file, when not present themselves. */
80
- const SOURCE_OF = {
81
- 'elasticsearch/reindex.sh': 'deployment/reindex.sh'
82
- };
83
- /**
84
- * What the assets image needs. The rest of `infrastructure/` (Docker Swarm
85
- * compose files, server setup and so on) is left where it is.
86
- */
87
- const MIGRATED_DIRS = ['metabase', 'postgres', 'deployment', 'elasticsearch'];
88
- /** Never moved into `assets/`. */
89
- const NOT_MOVED = ['postgres/on-deploy.sh'];
90
- const isMigrated = (file) => MIGRATED_DIRS.some((dir) => file.startsWith(`${dir}/`));
91
- /** Runs git silently in the working directory, returning true on success. */
92
- function tryGit(args) {
93
- try {
94
- (0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
95
- return true;
96
- }
97
- catch (_a) {
98
- return false;
99
- }
100
- }
101
- function assertIsGitRepo() {
102
- if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
103
- throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
104
- }
105
- }
106
- /*
107
- * Plain Uint8Array rather than Buffer: the repository's Node typings reject a
108
- * Buffer where fs expects an ArrayBufferView.
109
- */
110
- const toBytes = (buffer) => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
111
- const sameBytes = (a, b) => a.length === b.length && a.every((byte, index) => byte === b[index]);
112
- const isBinary = (contents) => contents.includes(0);
113
- function readIfExists(file) {
114
- return (0, fs_1.existsSync)(file) ? toBytes((0, fs_1.readFileSync)(file)) : undefined;
115
- }
116
- /** 3-way merge of text contents. `conflicts` is 0 for a clean merge. */
117
- function mergeFile(file, ours, base, theirs) {
118
- const dir = (0, fs_1.mkdtempSync)(path_1.default.join((0, os_1.tmpdir)(), 'opencrvs-merge-assets-'));
119
- try {
120
- const [oursPath, basePath, theirsPath] = ['ours', 'base', 'theirs'].map((name) => path_1.default.join(dir, name));
121
- (0, fs_1.writeFileSync)(oursPath, ours);
122
- (0, fs_1.writeFileSync)(basePath, base);
123
- (0, fs_1.writeFileSync)(theirsPath, theirs);
124
- // Without -p git writes the result into `oursPath`, so large files
125
- // (e.g. the Metabase init dump) don't overflow the stdout buffer
126
- const args = [
127
- 'merge-file',
128
- '-q',
129
- '-L',
130
- `infrastructure/${file}`,
131
- '-L',
132
- 'v2.0',
133
- '-L',
134
- `v2.1 template`,
135
- oursPath,
136
- basePath,
137
- theirsPath
138
- ];
139
- let conflicts = 0;
140
- try {
141
- (0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
142
- }
143
- catch (error) {
144
- const { status } = error;
145
- // git merge-file exits with the number of conflicts, or 255 on error
146
- if (!status || status >= 255)
147
- throw error;
148
- conflicts = status;
149
- }
150
- return { contents: toBytes((0, fs_1.readFileSync)(oursPath)), conflicts };
151
- }
152
- finally {
153
- (0, fs_1.rmSync)(dir, { recursive: true, force: true });
154
- }
155
- }
156
- /** Every v2.0 file the migration needs as a merge base, fetched up front. */
157
- function fetchBases(files) {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- const bases = new Map();
160
- for (const file of files) {
161
- const url = `${BASE_URL}/${file}`;
162
- const response = yield fetch(url);
163
- if (response.ok) {
164
- bases.set(file, new Uint8Array(yield response.arrayBuffer()));
165
- }
166
- else if (response.status !== 404) {
167
- // 404 means the file is the country's own; anything else would merge
168
- // against a missing base, so give up before touching anything
169
- throw new Error(`GitHub answered ${response.status} ${response.statusText} for ${url}`);
170
- }
171
- }
172
- return bases;
173
- });
174
- }
175
- function migrateInfrastructureToAssets(cwd, templateDir, readBase) {
176
- const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
177
- const templateAssets = path_1.default.join(templateDir, ASSETS_DIR);
178
- const relativeTo = (dir) => (file) => file.slice(dir.length + 1);
179
- const localFiles = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
180
- .map(relativeTo(INFRASTRUCTURE_DIR))
181
- .filter(isMigrated);
182
- const templateFiles = (0, template_files_1.listFiles)(templateDir, ASSETS_DIR).map(relativeTo(ASSETS_DIR));
183
- const outcomes = {};
184
- const migrated = new Set();
185
- for (const file of [...new Set([...templateFiles, ...localFiles])].sort()) {
186
- const sourceFile = !localFiles.includes(file) && localFiles.includes(SOURCE_OF[file])
187
- ? SOURCE_OF[file]
188
- : file;
189
- const ours = readIfExists(path_1.default.join(infrastructure, sourceFile));
190
- const theirsPath = path_1.default.join(templateAssets, file);
191
- const theirs = readIfExists(theirsPath);
192
- const base = ours && readBase(sourceFile);
193
- const target = path_1.default.join(cwd, ASSETS_DIR, file);
194
- if (NOT_MOVED.includes(file)) {
195
- if (ours && base && sameBytes(ours, base)) {
196
- migrated.add(file);
197
- outcomes[file] = 'dropped';
198
- }
199
- else if (ours) {
200
- outcomes[file] = 'not-moved';
201
- }
202
- continue;
203
- }
204
- const ownsSource = ours !== undefined && sourceFile === file;
205
- if ((0, fs_1.existsSync)(target)) {
206
- // Migrated before (a re-run, or by hand): only remove the original
207
- // when nothing in it would be lost
208
- if (ownsSource) {
209
- const same = sameBytes(toBytes((0, fs_1.readFileSync)(target)), ours);
210
- if (same) {
211
- migrated.add(file);
212
- }
213
- outcomes[file] = same ? 'exists' : 'exists-differs';
214
- }
215
- continue;
216
- }
217
- if (ownsSource) {
218
- migrated.add(file);
219
- }
220
- let contents;
221
- let outcome;
222
- if (!ours) {
223
- contents = theirs;
224
- outcome = 'copied';
225
- }
226
- else if (!theirs) {
227
- const unchanged = base && sameBytes(ours, base);
228
- contents = unchanged ? undefined : ours;
229
- outcome = unchanged ? 'dropped' : 'kept';
230
- }
231
- else if (sameBytes(ours, theirs) || (base && sameBytes(ours, base))) {
232
- contents = theirs;
233
- outcome = 'copied';
234
- }
235
- else if (!base || sameBytes(base, theirs) || isBinary(ours)) {
236
- contents = ours;
237
- outcome = 'kept';
238
- }
239
- else {
240
- const result = mergeFile(sourceFile, ours, base, theirs);
241
- contents = result.contents;
242
- outcome = result.conflicts > 0 ? 'conflict' : 'merged';
243
- }
244
- outcomes[file] = outcome;
245
- if (contents === undefined) {
246
- continue;
247
- }
248
- (0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
249
- (0, fs_1.writeFileSync)(target, contents);
250
- const modeSource = ours && outcome === 'kept'
251
- ? path_1.default.join(infrastructure, sourceFile)
252
- : theirsPath;
253
- if ((0, fs_1.existsSync)(modeSource)) {
254
- (0, fs_1.chmodSync)(target, (0, fs_1.statSync)(modeSource).mode & 0o777);
255
- }
256
- }
257
- return { outcomes, migrated: [...migrated].sort() };
258
- }
259
- /** Removes migrated files and any directories they leave empty. */
260
- function removeMigrated(cwd, migrated) {
261
- const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
262
- for (const file of migrated) {
263
- (0, fs_1.rmSync)(path_1.default.join(infrastructure, file), { force: true });
264
- }
265
- const pruneEmpty = (dir) => {
266
- if (!(0, fs_1.existsSync)(dir)) {
267
- return true;
268
- }
269
- const empty = (0, fs_1.readdirSync)(dir, { withFileTypes: true })
270
- .map((entry) => entry.isDirectory() ? pruneEmpty(path_1.default.join(dir, entry.name)) : false)
271
- .every(Boolean);
272
- if (empty) {
273
- (0, fs_1.rmdirSync)(dir);
274
- }
275
- return empty;
276
- };
277
- pruneEmpty(infrastructure);
278
- }
279
- const DESCRIPTIONS = {
280
- copied: 'from the template',
281
- kept: "country's version",
282
- merged: 'merged',
283
- conflict: 'CONFLICT, resolve the markers by hand',
284
- dropped: 'dropped, no longer used',
285
- exists: 'already migrated',
286
- 'exists-differs': 'already exists with different contents; infrastructure/ copy kept for review',
287
- 'not-moved': 'changed locally but not moved: the chart runs its own on-deploy script, port your changes there'
288
- };
289
- function main() {
290
- return __awaiter(this, arguments, void 0, function* (dockerSwarm = false) {
291
- const cwd = process.cwd();
292
- console.log('Moving infrastructure/ into assets/...\n');
293
- const templateDir = (0, template_files_1.findTemplateDir)();
294
- if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR))) {
295
- assertIsGitRepo();
296
- const needed = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
297
- .map((file) => file.slice(INFRASTRUCTURE_DIR.length + 1))
298
- .filter(isMigrated);
299
- let bases;
300
- try {
301
- bases = yield fetchBases(needed);
302
- }
303
- catch (error) {
304
- console.warn(` ⚠️ Could not read the v2.0 files to merge against (${error.message}); infrastructure/ was not migrated. Re-run 'opencrvs upgrade' with network access.`);
305
- return;
306
- }
307
- const { outcomes, migrated } = migrateInfrastructureToAssets(cwd, templateDir, (file) => bases.get(file));
308
- for (const [file, outcome] of Object.entries(outcomes)) {
309
- const needsReview = ['conflict', 'not-moved', 'exists-differs'].includes(outcome);
310
- const shown = outcome === 'not-moved' ? INFRASTRUCTURE_DIR : ASSETS_DIR;
311
- const line = ` ${needsReview ? '⚠️ ' : '✓'} ${shown}/${file}: ${DESCRIPTIONS[outcome]}`;
312
- if (needsReview) {
313
- console.warn(line);
314
- }
315
- else {
316
- console.log(line);
317
- }
318
- }
319
- if (dockerSwarm) {
320
- console.log('\n infrastructure/ kept in place (--docker-swarm); assets/ now holds a copy.');
321
- }
322
- else {
323
- removeMigrated(cwd, migrated);
324
- }
325
- tryGit(['add', '-A', '--', ASSETS_DIR, INFRASTRUCTURE_DIR]);
326
- const conflicts = Object.keys(outcomes).filter((file) => outcomes[file] === 'conflict');
327
- for (const file of conflicts) {
328
- tryGit(['restore', '--staged', '--', `${ASSETS_DIR}/${file}`]);
329
- }
330
- if (conflicts.length > 0) {
331
- console.warn(`\n ⚠️ ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(', ')}`);
332
- }
333
- if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR)) && !dockerSwarm) {
334
- console.warn(' ⚠️ infrastructure/ still has files the Kubernetes deployment does not use. Review and delete them if they are no longer needed.');
335
- }
336
- }
337
- else {
338
- console.log(' infrastructure/ not found, nothing to move.');
339
- }
340
- const dockerfile = toBytes((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'Dockerfile.assets')));
341
- const current = readIfExists(path_1.default.join(cwd, 'Dockerfile.assets'));
342
- if (!current || !sameBytes(current, dockerfile)) {
343
- (0, fs_1.writeFileSync)(path_1.default.join(cwd, 'Dockerfile.assets'), dockerfile);
344
- tryGit(['add', '--', 'Dockerfile.assets']);
345
- console.log(' ✓ Dockerfile.assets replaced with the template version');
346
- }
347
- });
348
- }
@@ -1,2 +0,0 @@
1
- export declare function main(): Promise<void>;
2
- //# sourceMappingURL=remove-metabase-package-installs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remove-metabase-package-installs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/remove-metabase-package-installs.ts"],"names":[],"mappings":"AA+KA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAY1C"}
@@ -1,161 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.main = main;
23
- /**
24
- * Codemod: Stop the Metabase startup scripts installing packages over the
25
- * internet.
26
- *
27
- * `run.sh` used to `apk add gettext util-linux` on every start. Since chart
28
- * v2.1.0 the dashboards Deployment renders NetworkPolicies and the chart
29
- * default `network_policy.egress_mode: private` allows RFC1918 only, so the
30
- * fetch to dl-cdn.alpinelinux.org is dropped, apk reports "Permission denied"
31
- * and Metabase never starts. Both tools have in-image equivalents:
32
- *
33
- * - uuidgen (util-linux) -> /proc/sys/kernel/random/uuid, keeping uuidgen
34
- * as the fallback for local macOS runs
35
- * - envsubst (gettext) -> bash's own heredoc expansion
36
- *
37
- * This is the country-config side of core's #13778, which fixed the same
38
- * scripts in `countryconfig-template` and `testland` — i.e. only for newly
39
- * scaffolded country configs.
40
- *
41
- * What it does:
42
- * Rewrites `run.sh` and `update-database.sh` under `infrastructure/metabase/`
43
- * (and `assets/metabase/`, in case the directory has already been renamed)
44
- * to match the fixed upstream versions.
45
- *
46
- * Caveats:
47
- * - Anchored on the exact upstream v2.0 wording. A script that was edited
48
- * locally is left alone with a warning rather than half-patched, and the
49
- * dev applies core's #13778 by hand.
50
- * - No-op when the files are absent (Swarm configs that dropped
51
- * `infrastructure/`, or configs scaffolded from the fixed template).
52
- */
53
- const fs_1 = require("fs");
54
- const path_1 = require("path");
55
- const METABASE_DIRS = ['infrastructure/metabase', 'assets/metabase'];
56
- // ─── run.sh ──────────────────────────────────────────────────────────────────
57
- const APK_BLOCK = [
58
- 'apk update',
59
- 'apk upgrade',
60
- 'apk add --no-cache gettext',
61
- 'apk add --no-cache util-linux',
62
- '',
63
- ''
64
- ].join('\n');
65
- const SALT_LINE = 'export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(uuidgen)\n';
66
- const FIXED_SALT_LINE = 'export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=' +
67
- '$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)\n\n';
68
- const FIXED_SALT_MARKER = '/proc/sys/kernel/random/uuid';
69
- // ─── update-database.sh ──────────────────────────────────────────────────────
70
- const ENVSUBST_GUARD = [
71
- 'if ! which envsubst >/dev/null; then',
72
- ' echo "envsubst could not be found. Please install envsubst before continuing."',
73
- ' echo "MacOS: brew install gettext && brew link --force gettext"',
74
- ' exit 1',
75
- 'fi',
76
- ''
77
- ].join('\n');
78
- const ENVSUBST_CALL = 'envsubst < $environment_configuration_sql_file > ' +
79
- '$environment_configuration_sql_file.tmp\n';
80
- const FIXED_EXPANSION = [
81
- '',
82
- "# Expand $VAR / ${VAR} using bash's own heredoc expansion instead of envsubst,",
83
- '# because envsubst is not installed in the Metabase image',
84
- 'eval "cat <<OPENCRVS_ENV_EOF',
85
- '$(cat "$environment_configuration_sql_file")',
86
- 'OPENCRVS_ENV_EOF" > "$environment_configuration_sql_file.tmp"',
87
- ''
88
- ].join('\n');
89
- const FIXED_EXPANSION_MARKER = 'OPENCRVS_ENV_EOF';
90
- /**
91
- * Rewrites `run.sh` to read the salt from the kernel instead of installing
92
- * util-linux for uuidgen.
93
- *
94
- * Returns the source unchanged when it is already fixed, and `undefined` when
95
- * it does not match the upstream v2.0 wording — the caller warns and skips.
96
- */
97
- function patchRunScript(source) {
98
- if (source.includes(FIXED_SALT_MARKER) && !source.includes(APK_BLOCK)) {
99
- return source;
100
- }
101
- if (!source.includes(APK_BLOCK) || !source.includes(SALT_LINE)) {
102
- return undefined;
103
- }
104
- return source.replace(APK_BLOCK, '').replace(SALT_LINE, FIXED_SALT_LINE);
105
- }
106
- /**
107
- * Rewrites `update-database.sh` to expand the environment configuration with
108
- * bash instead of installing gettext for envsubst.
109
- *
110
- * Returns the source unchanged when it is already fixed, and `undefined` when
111
- * it does not match the upstream v2.0 wording — the caller warns and skips.
112
- */
113
- function patchUpdateDatabaseScript(source) {
114
- if (source.includes(FIXED_EXPANSION_MARKER) &&
115
- !source.includes(ENVSUBST_CALL)) {
116
- return source;
117
- }
118
- if (!source.includes(ENVSUBST_GUARD) || !source.includes(ENVSUBST_CALL)) {
119
- return undefined;
120
- }
121
- return source
122
- .replace(ENVSUBST_GUARD, '')
123
- .replace(ENVSUBST_CALL, FIXED_EXPANSION);
124
- }
125
- /**
126
- * Applies `patch` to `relativePath`, writing it back only when the contents
127
- * actually change. Warns and leaves the file alone when it has been edited
128
- * locally, because a half-patched script still fails to start — silently.
129
- */
130
- function patchFile(relativePath, patch, removed) {
131
- const filePath = (0, path_1.join)(process.cwd(), relativePath);
132
- if (!(0, fs_1.existsSync)(filePath)) {
133
- return;
134
- }
135
- const source = (0, fs_1.readFileSync)(filePath, 'utf8');
136
- const patched = patch(source);
137
- if (patched === undefined) {
138
- // eslint-disable-next-line no-console
139
- console.warn(` ⚠️ ${relativePath} does not match the upstream v2.0 version, so it ` +
140
- `was left alone. Apply ` +
141
- `https://github.com/opencrvs/opencrvs-core/pull/13778 by hand, or ` +
142
- `Metabase will fail to start behind the chart's private egress policy.`);
143
- return;
144
- }
145
- if (patched === source) {
146
- return;
147
- }
148
- (0, fs_1.writeFileSync)(filePath, patched);
149
- // eslint-disable-next-line no-console
150
- console.log(` ✓ ${relativePath}: ${removed}`);
151
- }
152
- function main() {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- // eslint-disable-next-line no-console
155
- console.log('\nRemoving the Metabase package installs...\n');
156
- for (const dir of METABASE_DIRS) {
157
- patchFile((0, path_1.join)(dir, 'run.sh'), patchRunScript, 'apk add gettext util-linux');
158
- patchFile((0, path_1.join)(dir, 'update-database.sh'), patchUpdateDatabaseScript, 'envsubst');
159
- }
160
- });
161
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=remove-sentry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"remove-sentry.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/remove-sentry.ts"],"names":[],"mappings":"AAwaA,iBAAe,IAAI,kBAiClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}