@opencrvs/toolkit 2.0.0-rc.a456517 → 2.0.0-rc.a7c070e

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 (86) hide show
  1. package/create-countryconfig/index.js +73 -0
  2. package/create-countryconfig/package.json +11 -0
  3. package/dist/application-config/index.js +53 -31
  4. package/dist/cli.js +1661 -320
  5. package/dist/commons/api/router.d.ts +62 -54
  6. package/dist/commons/application-config/index.d.ts +16 -4
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/events/ActionInput.d.ts +36 -0
  9. package/dist/commons/events/Draft.d.ts +1 -0
  10. package/dist/commons/events/FieldConfig.d.ts +10 -0
  11. package/dist/commons/events/locations.d.ts +38 -1
  12. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  13. package/dist/commons/events/scopes.d.ts +24 -1
  14. package/dist/conditionals/index.js +37 -7
  15. package/dist/events/index.js +143 -27
  16. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  17. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  18. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  19. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  20. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  21. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  22. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  23. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
  24. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  25. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  26. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  28. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/create-events-index.js +1 -2
  30. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  31. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  32. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  33. package/dist/migrations/v2.0/index.d.ts +8 -4
  34. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  35. package/dist/migrations/v2.0/index.js +1629 -317
  36. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  37. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  38. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  39. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  40. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  41. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  42. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  43. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  44. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  46. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  48. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  50. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  51. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  52. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  53. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  54. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  55. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  56. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  57. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  58. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  59. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  60. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  61. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  62. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  63. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  64. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  65. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  66. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  67. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  68. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  69. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  70. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  71. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  72. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  73. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  74. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  75. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  76. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  77. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  78. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  79. package/dist/migrations/v2.0/update-package-json.js +105 -0
  80. package/dist/notification/index.js +50 -27
  81. package/dist/scopes/index.d.ts +87 -10
  82. package/dist/scopes/index.js +43 -8
  83. package/opencrvs-toolkit-2.0.0-rc.a7c070e.tgz +0 -0
  84. package/package.json +1 -1
  85. package/tsconfig.tsbuildinfo +1 -1
  86. package/opencrvs-toolkit-2.0.0-rc.a456517.tgz +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AA6WA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AAodA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -41,11 +41,14 @@ exports.main = main;
41
41
  * - Removes the `deduplication` property from those objects
42
42
  * - Replaces `review: { fields: <value> }` with `form: <value>`, or
43
43
  * `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
44
+ * - Adds the top-level `validated` flag definition and `{ id: 'validated',
45
+ * operation: 'add' }` to the (now custom) validate action
46
+ * - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
47
+ * in the same config, closing the flag's lifecycle when registration happens
44
48
  * - Saves the modified files in-place
45
49
  */
46
50
  const ts_morph_1 = require("ts-morph");
47
51
  const path_1 = __importDefault(require("path"));
48
- const _1 = require(".");
49
52
  const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
50
53
  const REQUIRED_SYMBOLS = [
51
54
  'ConditionalType',
@@ -75,6 +78,8 @@ function ensureImports(sourceFile) {
75
78
  const DEFINE_CONFIG_NAME = 'defineConfig';
76
79
  const ACTIONS_PROPERTY_NAME = 'actions';
77
80
  const TYPE_PROPERTY_NAME = 'type';
81
+ const ID_PROPERTY_NAME = 'id';
82
+ const FLAGS_PROPERTY_NAME = 'flags';
78
83
  const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
79
84
  const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
80
85
  const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
@@ -84,9 +89,12 @@ const FORM_PROPERTY_NAME = 'form';
84
89
  const ACTION_TYPE_ENUM_NAME = 'ActionType';
85
90
  const VALIDATE_MEMBER_NAME = 'VALIDATE';
86
91
  const CUSTOM_MEMBER_NAME = 'CUSTOM';
92
+ const REGISTER_MEMBER_NAME = 'REGISTER';
87
93
  const VALIDATE_STRING_LITERAL = 'VALIDATE';
88
94
  const CUSTOM_STRING_LITERAL = 'CUSTOM';
95
+ const REGISTER_STRING_LITERAL = 'REGISTER';
89
96
  const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
97
+ const VALIDATED_FLAG_VALUE = 'validated';
90
98
  function isValidateType(typeInitializer) {
91
99
  // Matches: ActionType.VALIDATE
92
100
  if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
@@ -231,6 +239,72 @@ function transformValidateActionToCustom(obj, eventType) {
231
239
  }
232
240
  return true;
233
241
  }
242
+ function isRegisterAction(action) {
243
+ const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
244
+ if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
245
+ return false;
246
+ const typeInit = typeProperty.getInitializer();
247
+ if (!typeInit)
248
+ return false;
249
+ // Matches: ActionType.REGISTER
250
+ if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
251
+ const enumExpr = typeInit.getExpression();
252
+ return (ts_morph_1.Node.isIdentifier(enumExpr) &&
253
+ enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
254
+ typeInit.getName() === REGISTER_MEMBER_NAME);
255
+ }
256
+ // Matches: "REGISTER"
257
+ if (ts_morph_1.Node.isStringLiteral(typeInit)) {
258
+ return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
259
+ }
260
+ return false;
261
+ }
262
+ /**
263
+ * Returns true if an array literal contains an object literal with `id: <id>`.
264
+ */
265
+ function arrayHasElementWithId(array, id) {
266
+ for (const el of array.getElements()) {
267
+ if (!ts_morph_1.Node.isObjectLiteralExpression(el))
268
+ continue;
269
+ const idProp = el.getProperty(ID_PROPERTY_NAME);
270
+ if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
271
+ continue;
272
+ const idInit = idProp.getInitializer();
273
+ if (idInit &&
274
+ ts_morph_1.Node.isStringLiteral(idInit) &&
275
+ idInit.getLiteralValue() === id) {
276
+ return true;
277
+ }
278
+ }
279
+ return false;
280
+ }
281
+ /**
282
+ * Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
283
+ * `flags` array. Skips if any `validated` flag entry is already present —
284
+ * this keeps the codemod idempotent and avoids stomping on an intentional
285
+ * `add` op a maintainer may have authored manually.
286
+ *
287
+ * Returns true if a change was made.
288
+ */
289
+ function ensureRegisterRemovesValidatedFlag(action) {
290
+ const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
291
+ const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
292
+ if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
293
+ const flagsInit = flagsProp.getInitializer();
294
+ if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
295
+ if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
296
+ return false;
297
+ flagsInit.addElement(entry);
298
+ return true;
299
+ }
300
+ return false;
301
+ }
302
+ action.addPropertyAssignment({
303
+ name: FLAGS_PROPERTY_NAME,
304
+ initializer: `[${entry}]`
305
+ });
306
+ return true;
307
+ }
234
308
  function processFile(filePath, project) {
235
309
  const sourceFile = project.getSourceFile(filePath);
236
310
  if (!sourceFile)
@@ -263,7 +337,7 @@ function processFile(filePath, project) {
263
337
  // Resolve the root event type for use in the auditHistoryLabel id
264
338
  const eventType = resolveEventType(configArg);
265
339
  if (!eventType) {
266
- console.warn(` [${path_1.default.relative((0, _1.getCwd)(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
340
+ console.warn(` [${path_1.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
267
341
  }
268
342
  // Iterate over every element in the `actions` array
269
343
  let fileNeedsImports = false;
@@ -276,7 +350,7 @@ function processFile(filePath, project) {
276
350
  transformedCount++;
277
351
  fileNeedsImports = true;
278
352
  configHadValidateAction = true;
279
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
353
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
280
354
  }
281
355
  }
282
356
  // Add top-level flags array to the config object if a VALIDATE action was found
@@ -296,7 +370,21 @@ function processFile(filePath, project) {
296
370
  }
297
371
  ]`
298
372
  });
299
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Added top-level 'flags' array to defineConfig`);
373
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
374
+ }
375
+ // Close the `validated` flag's lifecycle: when the validate action adds the
376
+ // flag, the matching REGISTER action(s) must remove it on registration.
377
+ if (configHadValidateAction) {
378
+ for (const element of actionsInitializer.getElements()) {
379
+ if (!ts_morph_1.Node.isObjectLiteralExpression(element))
380
+ continue;
381
+ if (!isRegisterAction(element))
382
+ continue;
383
+ if (ensureRegisterRemovesValidatedFlag(element)) {
384
+ transformedCount++;
385
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
386
+ }
387
+ }
300
388
  }
301
389
  if (fileNeedsImports) {
302
390
  ensureImports(sourceFile);
@@ -306,7 +394,7 @@ function processFile(filePath, project) {
306
394
  }
307
395
  function main() {
308
396
  return __awaiter(this, void 0, void 0, function* () {
309
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
397
+ const srcDir = path_1.default.join(process.cwd(), 'src');
310
398
  console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
311
399
  const project = new ts_morph_1.Project({
312
400
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -337,8 +425,8 @@ function main() {
337
425
  for (const filePath of modifiedFiles) {
338
426
  const sourceFile = project.getSourceFileOrThrow(filePath);
339
427
  yield sourceFile.save();
340
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
428
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
341
429
  }
342
- console.log(`\nDone. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`);
430
+ console.log(`\nDone. Applied ${totalTransformed} change(s): VALIDATE → CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`);
343
431
  });
344
432
  }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=merge-infrastructure-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAkInC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,221 @@
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: Merge upstream changes into the local `infrastructure/` directory
25
+ * from opencrvs/opencrvs-countryconfig.
26
+ *
27
+ * Usage:
28
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/merge-infrastructure-directory.ts
29
+ *
30
+ * What it does:
31
+ * 1. Registers a temporary git remote that points at the canonical
32
+ * opencrvs-countryconfig repository and fetches both:
33
+ * - the upstream "theirs" branch (v2.0) → `UPSTREAM_BRANCH`
34
+ * - the synthetic merge-base branch (latest 1.9 release line)
35
+ * → `BASE_BRANCH`
36
+ * 2. For every file under `infrastructure/` on upstream "theirs", performs
37
+ * a file-scoped 3-way merge:
38
+ * - new file on upstream → checked out and staged
39
+ * - existing file → 3-way merged in place via `git merge-file`,
40
+ * using the BASE_BRANCH version of the file
41
+ * as the ancestor (or an empty file if the
42
+ * base doesn't have it)
43
+ * Files local to the country config that don't exist on upstream are
44
+ * left untouched.
45
+ * 3. Cleanly merged files are staged. Files with conflicts are left in the
46
+ * working tree with standard <<<<<<< / ======= / >>>>>>> markers and
47
+ * MUST be resolved manually by the developer.
48
+ * 4. Removes the temporary remote in all cases (success, failure, or
49
+ * unexpected error) via a `finally` block.
50
+ *
51
+ * Why a content-based synthetic merge-base instead of `git merge-base`:
52
+ * - Country config repos rarely share git history with
53
+ * opencrvs-countryconfig (squashed forks, template-cloned repos, etc.),
54
+ * so `git merge-base HEAD upstream/develop` typically returns nothing.
55
+ * - With no merge-base, a 3-way merge degenerates to a 2-way diff against
56
+ * an empty file — every line that differs becomes a conflict.
57
+ * - `release-v1.9` is the latest 1.9.x release line on upstream and is a
58
+ * near-perfect representation of "what `infrastructure/` looked like
59
+ * before v2.0", regardless of whether the fork's git history reaches it.
60
+ * - For files the country config never modified relative to that baseline,
61
+ * `git merge-file` resolves cleanly to upstream's v2.0 version. Conflicts
62
+ * are produced only where local edits genuinely overlap with v1.9 → v2.0
63
+ * upstream edits — which is what the developer needs to review anyway.
64
+ *
65
+ * Why per-file merge instead of a real `git merge`:
66
+ * - Limits the blast radius to `infrastructure/` only — no other paths
67
+ * are touched.
68
+ * - Doesn't put the repository into an in-progress merge state
69
+ * (no MERGE_HEAD), so subsequent codemods/commands behave normally.
70
+ * - Works regardless of whether the local repo shares history with
71
+ * opencrvs-countryconfig.
72
+ *
73
+ * Caveats:
74
+ * - Local edits to merged files may be overwritten where they overlap
75
+ * with upstream changes. Run on a clean working tree.
76
+ * - Requires git to be installed and network access to github.com.
77
+ * - Requires the country config working directory to be a git repo.
78
+ * - Binary files in `infrastructure/` are not merged textually; if both
79
+ * sides changed a binary file, the result will be invalid and a warning
80
+ * is printed.
81
+ * - Forks that are on a much older 1.9.x and never merged later 1.9 patches
82
+ * may see a few extra conflicts on files where 1.9.x → release-v1.9
83
+ * patches and v1.9 → v2.0 changes textually overlap.
84
+ */
85
+ const child_process_1 = require("child_process");
86
+ const fs_1 = require("fs");
87
+ const os_1 = require("os");
88
+ const path_1 = require("path");
89
+ const checkout_upstream_files_1 = require("./checkout-upstream-files");
90
+ // Distinct from the remote used by `checkout-upstream-files` so that a stale
91
+ // remote left behind by an aborted run of one codemod doesn't trip up the
92
+ // other.
93
+ const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod-merge-infra';
94
+ const INFRASTRUCTURE_DIR = 'infrastructure';
95
+ // Synthetic merge-base: the tip of upstream's latest 1.9.x release line.
96
+ // We use this branch's content as the "common ancestor" for every file,
97
+ // since most country forks don't share git history with upstream.
98
+ const BASE_BRANCH = 'release-v1.9';
99
+ /**
100
+ * Reads `git show <ref>:<path>` as a Uint8Array (binary-safe).
101
+ * Returns `null` if the path doesn't exist at that ref.
102
+ */
103
+ function gitShowBytes(ref, path) {
104
+ try {
105
+ const buf = (0, child_process_1.execFileSync)('git', ['show', `${ref}:${path}`], {
106
+ cwd: process.cwd(),
107
+ stdio: ['ignore', 'pipe', 'pipe']
108
+ });
109
+ // Return a plain Uint8Array view to satisfy strict typings of `fs`
110
+ // (which want `ArrayBufferView`, not Node's `Buffer` subtype).
111
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
112
+ }
113
+ catch (_a) {
114
+ return null;
115
+ }
116
+ }
117
+ // ─── Entry point ─────────────────────────────────────────────────────────────
118
+ function main() {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ console.log(`Merging '${INFRASTRUCTURE_DIR}/' from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
121
+ (0, checkout_upstream_files_1.assertIsGitRepo)();
122
+ // Best-effort cleanup of a stale temp remote from a previous aborted run.
123
+ (0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE]);
124
+ try {
125
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${checkout_upstream_files_1.UPSTREAM_URL}`);
126
+ (0, checkout_upstream_files_1.runGit)(['remote', 'add', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_URL], { silent: true });
127
+ // Fetch both branches at depth=1 — we only need their tip contents,
128
+ // not their history (the merge is content-based, not history-based).
129
+ console.log(` Fetching ${TEMP_REMOTE}/{${checkout_upstream_files_1.UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`);
130
+ (0, checkout_upstream_files_1.runGit)(['fetch', '--depth=1', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_BRANCH, BASE_BRANCH]);
131
+ const ref = `${TEMP_REMOTE}/${checkout_upstream_files_1.UPSTREAM_BRANCH}`;
132
+ const baseRef = `${TEMP_REMOTE}/${BASE_BRANCH}`;
133
+ // -z gives NUL-separated paths so filenames with spaces or newlines
134
+ // survive the round-trip.
135
+ const upstreamFiles = (0, checkout_upstream_files_1.runGit)([
136
+ 'ls-tree',
137
+ '-r',
138
+ '--name-only',
139
+ '-z',
140
+ ref,
141
+ '--',
142
+ `${INFRASTRUCTURE_DIR}/`
143
+ ], { silent: true })
144
+ .split('\0')
145
+ .filter(Boolean);
146
+ if (upstreamFiles.length === 0) {
147
+ console.log(` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`);
148
+ return;
149
+ }
150
+ const tmpDir = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'opencrvs-merge-infra-'));
151
+ const baseTmp = (0, path_1.join)(tmpDir, 'base');
152
+ const theirsTmp = (0, path_1.join)(tmpDir, 'theirs');
153
+ let added = 0;
154
+ let merged = 0;
155
+ const conflictedFiles = [];
156
+ for (const file of upstreamFiles) {
157
+ const fullPath = (0, path_1.join)(process.cwd(), file);
158
+ if (!(0, fs_1.existsSync)(fullPath)) {
159
+ // New upstream file — `git checkout` handles binary correctly and
160
+ // stages the result, matching the UX of `checkout-upstream-files`.
161
+ if ((0, checkout_upstream_files_1.tryGit)(['checkout', ref, '--', file])) {
162
+ console.log(` + ${file} (new from upstream)`);
163
+ added++;
164
+ }
165
+ else {
166
+ console.warn(` [warn] failed to add new file ${file}`);
167
+ }
168
+ continue;
169
+ }
170
+ const theirContents = gitShowBytes(ref, file);
171
+ if (theirContents === null) {
172
+ // Shouldn't happen — `ls-tree` just told us the file is there.
173
+ console.warn(` [warn] could not read ${file} from ${ref} — skipping.`);
174
+ continue;
175
+ }
176
+ (0, fs_1.writeFileSync)(theirsTmp, theirContents);
177
+ // Pull the base version from upstream's latest 1.9 release line. If
178
+ // the file didn't exist there yet (added in v2.0), fall back to an
179
+ // empty base — `git merge-file` will then treat any local content as
180
+ // a local addition.
181
+ const baseContents = gitShowBytes(baseRef, file);
182
+ (0, fs_1.writeFileSync)(baseTmp, baseContents !== null && baseContents !== void 0 ? baseContents : new Uint8Array(0));
183
+ // `git merge-file` does an in-place 3-way merge. Exit codes:
184
+ // 0 → clean merge
185
+ // 1..N → that many conflicts; markers written into the file
186
+ // <0/127 → error (e.g. binary file rejected)
187
+ try {
188
+ (0, child_process_1.execFileSync)('git', ['merge-file', fullPath, baseTmp, theirsTmp], {
189
+ cwd: process.cwd(),
190
+ stdio: ['ignore', 'pipe', 'pipe']
191
+ });
192
+ (0, checkout_upstream_files_1.runGit)(['add', '--', file], { silent: true });
193
+ merged++;
194
+ }
195
+ catch (err) {
196
+ const status = err.status;
197
+ if (typeof status === 'number' && status > 0) {
198
+ conflictedFiles.push(file);
199
+ console.warn(` ! ${file} (${status} conflict${status > 1 ? 's' : ''})`);
200
+ }
201
+ else {
202
+ conflictedFiles.push(file);
203
+ console.warn(` [warn] merge failed for ${file} (likely binary or unreadable) — left untouched.`);
204
+ }
205
+ }
206
+ }
207
+ console.log(`\n Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`);
208
+ if (conflictedFiles.length > 0) {
209
+ console.warn(`\n NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.\n` +
210
+ ` Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:\n` +
211
+ conflictedFiles.map((f) => ` - ${f}`).join('\n') +
212
+ `\n After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`);
213
+ }
214
+ }
215
+ finally {
216
+ if ((0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE])) {
217
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
218
+ }
219
+ }
220
+ });
221
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-application-config-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-application-config-url.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-application-config-url.ts"],"names":[],"mappings":"AAwUA,iBAAe,IAAI,kBAqElB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}