@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.e0918cb

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 (130) hide show
  1. package/build.sh +13 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/application-config/index.d.ts +2 -0
  4. package/dist/application-config/index.d.ts.map +1 -0
  5. package/dist/application-config/index.js +2128 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +3633 -0
  9. package/dist/commons/api/router.d.ts +3438 -2300
  10. package/dist/commons/application-config/index.d.ts +84 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -3
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +888 -1941
  15. package/dist/commons/events/ActionInput.d.ts +277 -1073
  16. package/dist/commons/events/ActionType.d.ts +91 -11
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
  18. package/dist/commons/events/AuditLog.d.ts +405 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
  20. package/dist/commons/events/Conditional.d.ts +26 -38
  21. package/dist/commons/events/Constants.d.ts +1 -1
  22. package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
  23. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  24. package/dist/commons/events/Draft.d.ts +72 -107
  25. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  26. package/dist/commons/events/EventConfig.d.ts +37 -2420
  27. package/dist/commons/events/EventConfigInput.d.ts +0 -3
  28. package/dist/commons/events/EventDocument.d.ts +354 -1366
  29. package/dist/commons/events/EventIndex.d.ts +212 -1010
  30. package/dist/commons/events/EventInput.d.ts +3 -8
  31. package/dist/commons/events/EventMetadata.d.ts +130 -357
  32. package/dist/commons/events/FieldConfig.d.ts +2892 -12892
  33. package/dist/commons/events/FieldType.d.ts +26 -4
  34. package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
  35. package/dist/commons/events/FieldValue.d.ts +149 -527
  36. package/dist/commons/events/FileUtils.d.ts +2 -2
  37. package/dist/commons/events/Flag.d.ts +67 -0
  38. package/dist/commons/events/FormConfig.d.ts +54 -721
  39. package/dist/commons/events/PageConfig.d.ts +58 -320
  40. package/dist/commons/events/PlainDate.d.ts +1 -1
  41. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  42. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  43. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  44. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  45. package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
  46. package/dist/commons/events/deduplication.d.ts +3 -3
  47. package/dist/commons/events/defineConfig.d.ts +2 -247
  48. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  49. package/dist/commons/events/index.d.ts +3 -0
  50. package/dist/commons/events/locations.d.ts +57 -20
  51. package/dist/commons/events/scopes.d.ts +36 -35
  52. package/dist/commons/events/state/availableActions.d.ts +7 -2
  53. package/dist/commons/events/state/flags.d.ts +21 -3
  54. package/dist/commons/events/state/index.d.ts +30 -27
  55. package/dist/commons/events/state/utils.d.ts +190 -172
  56. package/dist/commons/events/test.utils.d.ts +52 -11
  57. package/dist/commons/events/transactions.d.ts +1 -1
  58. package/dist/commons/events/utils.d.ts +373 -273
  59. package/dist/commons/notification/UserNotifications.d.ts +61 -637
  60. package/dist/conditionals/index.d.ts.map +1 -1
  61. package/dist/conditionals/index.js +302 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2860 -2115
  64. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  65. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +405 -0
  67. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
  68. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
  70. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  71. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/convert-config-files-to-ts.js +829 -0
  73. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  74. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
  76. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  77. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/create-events-index.js +326 -0
  79. package/dist/migrations/v2.0/index.d.ts +7 -0
  80. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/index.js +3572 -0
  82. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  83. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
  85. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  86. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/migrate-scopes.js +282 -0
  88. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  89. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
  91. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  92. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
  94. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  95. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
  97. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  98. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
  100. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  101. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
  103. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  104. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
  106. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
  109. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
  112. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  113. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/rename-api-paths.js +188 -0
  115. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  116. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
  118. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  119. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
  121. package/dist/notification/index.d.ts.map +1 -1
  122. package/dist/notification/index.js +2076 -1767
  123. package/dist/scopes/index.d.ts +640 -353
  124. package/dist/scopes/index.d.ts.map +1 -1
  125. package/dist/scopes/index.js +340 -300
  126. package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
  127. package/package.json +18 -8
  128. package/tsconfig.json +12 -2
  129. package/tsconfig.tsbuildinfo +1 -1
  130. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=convert-paragraph-to-heading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-paragraph-to-heading.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-paragraph-to-heading.ts"],"names":[],"mappings":"AAwJA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,159 @@
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.main = main;
26
+ /**
27
+ * Codemod: Convert `FieldType.PARAGRAPH` fields with a heading `fontVariant` to `FieldType.HEADING`,
28
+ * and remove the `fontVariant` property from plain paragraphs.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/convert-paragraph-to-heading.ts
32
+ *
33
+ * What it does:
34
+ * - Scans all TypeScript files under `src/`
35
+ * - Finds every object literal whose `type` property is `FieldType.PARAGRAPH`
36
+ * - Navigates `configuration.styles.fontVariant` on that object
37
+ * - If `fontVariant` is one of 'h1' | 'h2' | 'h3' | 'h4':
38
+ * changes `type` to `FieldType.HEADING`
39
+ * - If `fontVariant` is absent, not a string literal, or any other value:
40
+ * leaves `type` as `FieldType.PARAGRAPH` and removes the `fontVariant` property
41
+ * - Saves the modified files in-place
42
+ */
43
+ const ts_morph_1 = require("ts-morph");
44
+ const path_1 = __importDefault(require("path"));
45
+ const _1 = require(".");
46
+ const FIELD_TYPE_ENUM_NAME = 'FieldType';
47
+ const PARAGRAPH_MEMBER_NAME = 'PARAGRAPH';
48
+ const HEADING_MEMBER_NAME = 'HEADING';
49
+ const TYPE_PROPERTY_NAME = 'type';
50
+ const CONFIGURATION_PROPERTY_NAME = 'configuration';
51
+ const STYLES_PROPERTY_NAME = 'styles';
52
+ const FONT_VARIANT_PROPERTY_NAME = 'fontVariant';
53
+ const HEADING_FONT_VARIANTS = new Set(['h1', 'h2', 'h3', 'h4']);
54
+ function isParagraphType(typeInitializer) {
55
+ if (!ts_morph_1.Node.isPropertyAccessExpression(typeInitializer))
56
+ return false;
57
+ const obj = typeInitializer.getExpression();
58
+ const member = typeInitializer.getName();
59
+ return (ts_morph_1.Node.isIdentifier(obj) &&
60
+ obj.getText() === FIELD_TYPE_ENUM_NAME &&
61
+ member === PARAGRAPH_MEMBER_NAME);
62
+ }
63
+ function getFontVariantProperty(obj) {
64
+ const configProperty = obj.getProperty(CONFIGURATION_PROPERTY_NAME);
65
+ if (!configProperty || !ts_morph_1.Node.isPropertyAssignment(configProperty))
66
+ return null;
67
+ const configInitializer = configProperty.getInitializer();
68
+ if (!configInitializer || !ts_morph_1.Node.isObjectLiteralExpression(configInitializer))
69
+ return null;
70
+ const stylesProperty = configInitializer.getProperty(STYLES_PROPERTY_NAME);
71
+ if (!stylesProperty || !ts_morph_1.Node.isPropertyAssignment(stylesProperty))
72
+ return null;
73
+ const stylesInitializer = stylesProperty.getInitializer();
74
+ if (!stylesInitializer || !ts_morph_1.Node.isObjectLiteralExpression(stylesInitializer))
75
+ return null;
76
+ const fontVariantProperty = stylesInitializer.getProperty(FONT_VARIANT_PROPERTY_NAME);
77
+ if (!fontVariantProperty || !ts_morph_1.Node.isPropertyAssignment(fontVariantProperty))
78
+ return null;
79
+ return fontVariantProperty;
80
+ }
81
+ function transformParagraphField(obj) {
82
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
83
+ if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
84
+ return null;
85
+ const typeInitializer = typeProperty.getInitializer();
86
+ if (!typeInitializer || !isParagraphType(typeInitializer))
87
+ return null;
88
+ const fontVariantProperty = getFontVariantProperty(obj);
89
+ if (fontVariantProperty) {
90
+ const fontVariantInitializer = fontVariantProperty.getInitializer();
91
+ if (fontVariantInitializer &&
92
+ ts_morph_1.Node.isStringLiteral(fontVariantInitializer) &&
93
+ HEADING_FONT_VARIANTS.has(fontVariantInitializer.getLiteralValue())) {
94
+ // fontVariant is h1–h4: promote to HEADING
95
+ typeInitializer.replaceWithText(`${FIELD_TYPE_ENUM_NAME}.${HEADING_MEMBER_NAME}`);
96
+ return 'converted-to-heading';
97
+ }
98
+ // fontVariant is present but not a heading variant: remove it
99
+ fontVariantProperty.remove();
100
+ return 'removed-font-variant';
101
+ }
102
+ // No fontVariant at all: nothing to do
103
+ return null;
104
+ }
105
+ function processFile(filePath, project) {
106
+ const sourceFile = project.getSourceFile(filePath);
107
+ if (!sourceFile)
108
+ return 0;
109
+ let changedCount = 0;
110
+ const objectLiterals = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
111
+ for (const obj of objectLiterals) {
112
+ const result = transformParagraphField(obj);
113
+ if (result === 'converted-to-heading') {
114
+ changedCount++;
115
+ console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`);
116
+ }
117
+ else if (result === 'removed-font-variant') {
118
+ changedCount++;
119
+ console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`);
120
+ }
121
+ }
122
+ return changedCount;
123
+ }
124
+ function main() {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
127
+ console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}\n`);
128
+ const project = new ts_morph_1.Project({
129
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
130
+ skipAddingFilesFromTsConfig: false
131
+ });
132
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
133
+ const fp = sf.getFilePath();
134
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
135
+ });
136
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
137
+ let totalChanged = 0;
138
+ const modifiedFiles = [];
139
+ for (const sourceFile of sourceFiles) {
140
+ const filePath = sourceFile.getFilePath();
141
+ const changed = processFile(filePath, project);
142
+ if (changed > 0) {
143
+ totalChanged += changed;
144
+ modifiedFiles.push(filePath);
145
+ }
146
+ }
147
+ if (modifiedFiles.length === 0) {
148
+ console.log('No FieldType.PARAGRAPH fields with fontVariant found. Nothing to do.');
149
+ return;
150
+ }
151
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
152
+ for (const filePath of modifiedFiles) {
153
+ const sourceFile = project.getSourceFileOrThrow(filePath);
154
+ yield sourceFile.save();
155
+ console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
156
+ }
157
+ console.log(`\nDone. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
158
+ });
159
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=create-events-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAqTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,326 @@
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.main = main;
26
+ /**
27
+ * Codemod: Create `src/events/index.ts` that collects every `defineConfig`
28
+ * event export, and rewire the event-config handler to import from it.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/create-events-index.ts
32
+ *
33
+ * Context:
34
+ * No codemod currently *moves* event-config source files into `src/events/`.
35
+ * Event configs therefore still live wherever the country defined them
36
+ * (typically `src/form/...`). This codemod works regardless of their
37
+ * location by discovering every `export const X = defineConfig(...)`
38
+ * declaration in `src/`.
39
+ *
40
+ * What it does:
41
+ * 1. Scans `src/` for every top-level `export const X = defineConfig(...)`
42
+ * declaration and records `{ name, filePath }` pairs.
43
+ * 2. Creates `src/events/index.ts` (if it does not already exist) that
44
+ * imports each event config from its actual file location using a
45
+ * relative path from `src/events/`, and exports:
46
+ * export const eventConfigs = [<name1>, <name2>, ...]
47
+ * 3. Locates the event-config Hapi handler file (a file whose top level
48
+ * declares a function named `getCustomEventsHandler` or
49
+ * `getEventsHandler`) and:
50
+ * - Removes direct named imports of the event configs it no longer
51
+ * needs, cleaning up the import declaration if it becomes empty.
52
+ * - Removes any previously-inlined `export const eventConfigs = [...]`
53
+ * at the top level (in case an earlier codemod version hoisted one).
54
+ * - Adds `import { eventConfigs } from '@countryconfig/events'`
55
+ * (merging into an existing import of the same module if present).
56
+ * - Rewrites `h.response([<identifiers>]).code(...)` inside the
57
+ * handler to `h.response(eventConfigs).code(...)`.
58
+ * 4. Saves the modified files.
59
+ *
60
+ * The codemod is safe to re-run: if `src/events/index.ts` already exists it
61
+ * is left untouched, and handler modifications are idempotent.
62
+ */
63
+ const ts_morph_1 = require("ts-morph");
64
+ const fs_1 = __importDefault(require("fs"));
65
+ const path_1 = __importDefault(require("path"));
66
+ const _1 = require(".");
67
+ const DEFINE_CONFIG_NAME = 'defineConfig';
68
+ const HANDLER_FUNCTION_NAMES = new Set([
69
+ 'getCustomEventsHandler',
70
+ 'getEventsHandler'
71
+ ]);
72
+ const EVENT_CONFIGS_IDENTIFIER = 'eventConfigs';
73
+ const EVENTS_INDEX_IMPORT_PATH = '@countryconfig/events';
74
+ const RESPONSE_METHOD_NAME = 'response';
75
+ const LICENSE_HEADER = `/*
76
+ * This Source Code Form is subject to the terms of the Mozilla Public
77
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
78
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
79
+ *
80
+ * OpenCRVS is also distributed under the terms of the Civil Registration
81
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
82
+ *
83
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
84
+ */
85
+ `;
86
+ // ─── Discovery ───────────────────────────────────────────────────────────────
87
+ /**
88
+ * Returns every top-level `export const X = defineConfig(...)` declaration in
89
+ * files under `srcDir`. A declaration may wrap the call in a type assertion
90
+ * (`... as EventConfig`) — this is unwrapped before matching.
91
+ *
92
+ * An existing `src/events/index.ts` is excluded so re-runs don't pick up its
93
+ * re-exports as source definitions.
94
+ */
95
+ function findEventConfigExports(project, srcDir) {
96
+ const found = [];
97
+ const eventsIndexAbs = path_1.default.join(srcDir, 'events', 'index.ts');
98
+ for (const sourceFile of project.getSourceFiles()) {
99
+ const filePath = sourceFile.getFilePath();
100
+ if (!filePath.startsWith(srcDir) || filePath.includes('/node_modules/')) {
101
+ continue;
102
+ }
103
+ if (filePath === eventsIndexAbs)
104
+ continue;
105
+ for (const statement of sourceFile.getVariableStatements()) {
106
+ if (!statement.hasExportKeyword())
107
+ continue;
108
+ for (const decl of statement.getDeclarations()) {
109
+ const initializer = decl.getInitializer();
110
+ if (!initializer)
111
+ continue;
112
+ const unwrapped = ts_morph_1.Node.isAsExpression(initializer)
113
+ ? initializer.getExpression()
114
+ : initializer;
115
+ if (!ts_morph_1.Node.isCallExpression(unwrapped))
116
+ continue;
117
+ const callee = unwrapped.getExpression();
118
+ if (!ts_morph_1.Node.isIdentifier(callee))
119
+ continue;
120
+ if (callee.getText() !== DEFINE_CONFIG_NAME)
121
+ continue;
122
+ found.push({ name: decl.getName(), filePath });
123
+ }
124
+ }
125
+ }
126
+ return found;
127
+ }
128
+ // ─── Path helpers ────────────────────────────────────────────────────────────
129
+ /**
130
+ * Builds the POSIX module-specifier string used by `src/events/index.ts` to
131
+ * import from `eventConfigFilePath`.
132
+ *
133
+ * - Strips the trailing `.ts` extension.
134
+ * - Collapses `/index` so `src/form/v2/birth/index.ts` → `../form/v2/birth`.
135
+ * - Ensures the result starts with `./` or `../` (relative paths are required
136
+ * for sibling files that would otherwise be parsed as bare module names).
137
+ */
138
+ function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
139
+ const eventsIndexDir = path_1.default.join(srcDir, 'events');
140
+ let rel = path_1.default
141
+ .relative(eventsIndexDir, eventConfigFilePath)
142
+ .split(path_1.default.sep)
143
+ .join('/');
144
+ if (rel.endsWith('.ts'))
145
+ rel = rel.slice(0, -'.ts'.length);
146
+ if (rel.endsWith('/index'))
147
+ rel = rel.slice(0, -'/index'.length);
148
+ if (!rel.startsWith('.'))
149
+ rel = './' + rel;
150
+ return rel;
151
+ }
152
+ // ─── events/index.ts generation ──────────────────────────────────────────────
153
+ function buildEventsIndexSource(exports, srcDir) {
154
+ const imports = exports
155
+ .map((e) => `import { ${e.name} } from '${buildIndexImportSpecifier(e.filePath, srcDir)}'`)
156
+ .join('\n');
157
+ const array = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports
158
+ .map((e) => e.name)
159
+ .join(', ')}]`;
160
+ return `${LICENSE_HEADER}${imports}\n\n${array}\n`;
161
+ }
162
+ // ─── Handler discovery & rewrite ─────────────────────────────────────────────
163
+ /**
164
+ * Returns the first source file under `srcDir` whose top-level declarations
165
+ * include a function (either `function foo()` or `const foo = () => {}`) whose
166
+ * name is in `HANDLER_FUNCTION_NAMES`.
167
+ */
168
+ function findHandlerSourceFile(project, srcDir) {
169
+ for (const sf of project.getSourceFiles()) {
170
+ const fp = sf.getFilePath();
171
+ if (!fp.startsWith(srcDir) || fp.includes('/node_modules/'))
172
+ continue;
173
+ for (const fn of sf.getFunctions()) {
174
+ const name = fn.getName();
175
+ if (name && HANDLER_FUNCTION_NAMES.has(name))
176
+ return sf;
177
+ }
178
+ for (const statement of sf.getVariableStatements()) {
179
+ for (const decl of statement.getDeclarations()) {
180
+ if (HANDLER_FUNCTION_NAMES.has(decl.getName()))
181
+ return sf;
182
+ }
183
+ }
184
+ }
185
+ return undefined;
186
+ }
187
+ /**
188
+ * Mutates the handler source file:
189
+ * 1. Removes named imports matching `exportNames` from existing imports
190
+ * and drops any import declaration that's left empty.
191
+ * 2. Removes a stale top-level `export const eventConfigs = ...` if present.
192
+ * 3. Ensures `import { eventConfigs } from '@countryconfig/events'` exists
193
+ * (merging into an existing import of the same module when possible).
194
+ * 4. Replaces every `h.response([<identifiers>])` argument with
195
+ * `eventConfigs`.
196
+ *
197
+ * Returns a log of the changes that were actually applied.
198
+ */
199
+ function modifyHandler(sourceFile, exportNames) {
200
+ const changes = [];
201
+ // 1. Drop direct imports of event configs. Iterate over a snapshot because
202
+ // `importDecl.remove()` may mutate the declaration list.
203
+ for (const importDecl of [...sourceFile.getImportDeclarations()]) {
204
+ const namedImports = importDecl.getNamedImports();
205
+ if (namedImports.length === 0)
206
+ continue;
207
+ const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
208
+ if (matched.length === 0)
209
+ continue;
210
+ const removedNames = matched.map((ni) => ni.getName());
211
+ for (const ni of matched)
212
+ ni.remove();
213
+ changes.push(`removed direct imports: ${removedNames.join(', ')}`);
214
+ const stillUsed = importDecl.getNamedImports().length > 0 ||
215
+ importDecl.getDefaultImport() ||
216
+ importDecl.getNamespaceImport();
217
+ if (!stillUsed)
218
+ importDecl.remove();
219
+ }
220
+ // 2. Remove an inline top-level `export const eventConfigs = ...` if present.
221
+ // This cleans up after any earlier in-place hoisting done by a previous
222
+ // version of this migration.
223
+ for (const statement of [...sourceFile.getVariableStatements()]) {
224
+ if (!statement.hasExportKeyword())
225
+ continue;
226
+ const hasEventConfigs = statement
227
+ .getDeclarations()
228
+ .some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
229
+ if (hasEventConfigs) {
230
+ statement.remove();
231
+ changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
232
+ }
233
+ }
234
+ // 3. Ensure `import { eventConfigs } from '@countryconfig/events'`.
235
+ const existing = sourceFile.getImportDeclaration((imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH);
236
+ if (existing) {
237
+ const already = existing
238
+ .getNamedImports()
239
+ .some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
240
+ if (!already) {
241
+ existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
242
+ changes.push(`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`);
243
+ }
244
+ }
245
+ else {
246
+ sourceFile.addImportDeclaration({
247
+ moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
248
+ namedImports: [EVENT_CONFIGS_IDENTIFIER]
249
+ });
250
+ changes.push(`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`);
251
+ }
252
+ // 4. Replace inline `h.response([<identifiers>])` with `h.response(eventConfigs)`.
253
+ for (const call of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)) {
254
+ const callee = call.getExpression();
255
+ if (!ts_morph_1.Node.isPropertyAccessExpression(callee))
256
+ continue;
257
+ if (callee.getName() !== RESPONSE_METHOD_NAME)
258
+ continue;
259
+ const args = call.getArguments();
260
+ if (args.length !== 1)
261
+ continue;
262
+ const [arg] = args;
263
+ if (!ts_morph_1.Node.isArrayLiteralExpression(arg))
264
+ continue;
265
+ if (arg.getElements().length === 0)
266
+ continue;
267
+ if (!arg.getElements().every((el) => ts_morph_1.Node.isIdentifier(el)))
268
+ continue;
269
+ arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
270
+ changes.push(`rewrote h.response([...]) → h.response(${EVENT_CONFIGS_IDENTIFIER})`);
271
+ }
272
+ return changes;
273
+ }
274
+ // ─── Entry point ─────────────────────────────────────────────────────────────
275
+ function main() {
276
+ return __awaiter(this, void 0, void 0, function* () {
277
+ const cwd = (0, _1.getCwd)();
278
+ const srcDir = path_1.default.join(cwd, 'src');
279
+ console.log(`Scanning for defineConfig event exports in: ${srcDir}\n`);
280
+ const project = new ts_morph_1.Project({
281
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
282
+ skipAddingFilesFromTsConfig: false
283
+ });
284
+ const eventConfigExports = findEventConfigExports(project, srcDir);
285
+ if (eventConfigExports.length === 0) {
286
+ console.log('No top-level `export const X = defineConfig(...)` declarations found. Nothing to do.');
287
+ return;
288
+ }
289
+ console.log(`Found ${eventConfigExports.length} event config export(s):`);
290
+ for (const e of eventConfigExports) {
291
+ console.log(` ${e.name} ← ${path_1.default.relative(cwd, e.filePath)}`);
292
+ }
293
+ // ── Create (or skip) src/events/index.ts ───────────────────────────────────
294
+ const eventsIndexAbs = path_1.default.join(srcDir, 'events', 'index.ts');
295
+ const eventsIndexRel = path_1.default.relative(cwd, eventsIndexAbs);
296
+ if (fs_1.default.existsSync(eventsIndexAbs)) {
297
+ console.log(`\n[${eventsIndexRel}] already exists — leaving untouched.`);
298
+ }
299
+ else {
300
+ fs_1.default.mkdirSync(path_1.default.dirname(eventsIndexAbs), { recursive: true });
301
+ const source = buildEventsIndexSource(eventConfigExports, srcDir);
302
+ const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
303
+ overwrite: false
304
+ });
305
+ yield eventsIndexFile.save();
306
+ console.log(`\n[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`);
307
+ }
308
+ // ── Rewire handler file ────────────────────────────────────────────────────
309
+ const handler = findHandlerSourceFile(project, srcDir);
310
+ if (!handler) {
311
+ console.log(`\nNo event-config handler file found (looked for exported function(s): ${Array.from(HANDLER_FUNCTION_NAMES).join(', ')}). Skipping handler rewrite.`);
312
+ return;
313
+ }
314
+ const handlerRelPath = path_1.default.relative(cwd, handler.getFilePath());
315
+ const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
316
+ const changes = modifyHandler(handler, exportNameSet);
317
+ if (changes.length === 0) {
318
+ console.log(`\n[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} — no changes.`);
319
+ return;
320
+ }
321
+ for (const c of changes)
322
+ console.log(` [${handlerRelPath}] ${c}`);
323
+ yield handler.save();
324
+ console.log(`\nSaved ${handlerRelPath}.`);
325
+ });
326
+ }
@@ -0,0 +1,7 @@
1
+ export declare function getCwd(): string;
2
+ /**
3
+ * Run the upgrade process for a given country config directory.
4
+ * @param ccwd - The country config working directory.
5
+ */
6
+ export declare function runUpgrade(ccwd: string | undefined): Promise<void>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA+BA,wBAAgB,MAAM,WAMrB;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,iBA8BxD"}