@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,188 @@
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: Rename Hapi route `path` values inside route configuration objects.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/rename-api-paths.ts
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds every object literal that looks like a Hapi route config, i.e. one that
35
+ * has both a `method` property whose value is a recognised HTTP verb (or an array
36
+ * of them) and a `path` property whose value is a string literal
37
+ * - Applies every rename listed in PATH_RENAMES to the `path` value
38
+ * - Saves the modified files in-place
39
+ *
40
+ * Adding new renames:
41
+ * Add an entry to the PATH_RENAMES map below. Keys are the old path strings,
42
+ * values are the new path strings. Exact string matching is used — no wildcards.
43
+ */
44
+ const ts_morph_1 = require("ts-morph");
45
+ const path_1 = __importDefault(require("path"));
46
+ const _1 = require(".");
47
+ // ─── Path rename table ────────────────────────────────────────────────────────
48
+ // Add new renames here as further API paths are changed between versions.
49
+ const PATH_RENAMES = {
50
+ '/events': '/config/events',
51
+ '/application-config': '/config/application',
52
+ '/workqueue': '/config/workqueues',
53
+ '/locations': '/config/locations',
54
+ '/users': '/config/users',
55
+ '/roles': '/config/roles'
56
+ };
57
+ // ─── Constants ────────────────────────────────────────────────────────────────
58
+ const METHOD_PROPERTY_NAME = 'method';
59
+ const PATH_PROPERTY_NAME = 'path';
60
+ const HTTP_VERBS = new Set([
61
+ 'GET',
62
+ 'POST',
63
+ 'PUT',
64
+ 'PATCH',
65
+ 'DELETE',
66
+ 'OPTIONS',
67
+ 'HEAD',
68
+ '*'
69
+ ]);
70
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
71
+ /**
72
+ * Returns true when the given object literal looks like a Hapi route config.
73
+ *
74
+ * A route config must have:
75
+ * - a `method` property whose value is either a recognised HTTP verb string
76
+ * literal, or an array literal whose elements are all recognised verb strings
77
+ * - a `path` property whose value is a string literal
78
+ */
79
+ function isRouteConfig(obj) {
80
+ // ── method check ────────────────────────────────────────────────────────────
81
+ const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
82
+ if (!methodProp || !ts_morph_1.Node.isPropertyAssignment(methodProp))
83
+ return false;
84
+ const methodInit = methodProp.getInitializer();
85
+ if (!methodInit)
86
+ return false;
87
+ if (ts_morph_1.Node.isStringLiteral(methodInit)) {
88
+ if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
89
+ return false;
90
+ }
91
+ else if (ts_morph_1.Node.isArrayLiteralExpression(methodInit)) {
92
+ const allVerbs = methodInit
93
+ .getElements()
94
+ .every((el) => ts_morph_1.Node.isStringLiteral(el) &&
95
+ HTTP_VERBS.has(el.getLiteralValue().toUpperCase()));
96
+ if (!allVerbs)
97
+ return false;
98
+ }
99
+ else {
100
+ return false;
101
+ }
102
+ // ── path check ──────────────────────────────────────────────────────────────
103
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
104
+ if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
105
+ return false;
106
+ const pathInit = pathProp.getInitializer();
107
+ return !!pathInit && ts_morph_1.Node.isStringLiteral(pathInit);
108
+ }
109
+ /**
110
+ * Applies PATH_RENAMES to the `path` property of a confirmed route config object.
111
+ * Returns the new path string if a rename was applied, or null if no change was made.
112
+ */
113
+ function renameRoutePath(obj) {
114
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
115
+ if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
116
+ return null;
117
+ const pathInit = pathProp.getInitializer();
118
+ if (!pathInit || !ts_morph_1.Node.isStringLiteral(pathInit))
119
+ return null;
120
+ const oldPath = pathInit.getLiteralValue();
121
+ const newPath = PATH_RENAMES[oldPath];
122
+ if (!newPath)
123
+ return null;
124
+ pathInit.replaceWithText(`'${newPath}'`);
125
+ return newPath;
126
+ }
127
+ // ─── File processor ──────────────────────────────────────────────────────────
128
+ function processFile(filePath, project) {
129
+ const sourceFile = project.getSourceFile(filePath);
130
+ if (!sourceFile)
131
+ return 0;
132
+ let renamedCount = 0;
133
+ const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
134
+ // Collect candidates first to avoid iterating a mutating tree
135
+ const candidates = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
136
+ for (const obj of candidates) {
137
+ if (!isRouteConfig(obj))
138
+ continue;
139
+ const newPath = renameRoutePath(obj);
140
+ if (newPath) {
141
+ renamedCount++;
142
+ console.log(` [${relPath}] Renamed route path → '${newPath}'`);
143
+ }
144
+ }
145
+ return renamedCount;
146
+ }
147
+ // ─── Entry point ─────────────────────────────────────────────────────────────
148
+ function main() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
151
+ console.log(`Scanning for Hapi route configs in: ${srcDir}\n`);
152
+ console.log('Active path renames:');
153
+ for (const [from, to] of Object.entries(PATH_RENAMES)) {
154
+ console.log(` '${from}' → '${to}'`);
155
+ }
156
+ console.log();
157
+ const project = new ts_morph_1.Project({
158
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
159
+ skipAddingFilesFromTsConfig: false
160
+ });
161
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
162
+ const fp = sf.getFilePath();
163
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
164
+ });
165
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
166
+ let totalRenamed = 0;
167
+ const modifiedFiles = [];
168
+ for (const sourceFile of sourceFiles) {
169
+ const filePath = sourceFile.getFilePath();
170
+ const renamed = processFile(filePath, project);
171
+ if (renamed > 0) {
172
+ totalRenamed += renamed;
173
+ modifiedFiles.push(filePath);
174
+ }
175
+ }
176
+ if (modifiedFiles.length === 0) {
177
+ console.log('No matching route paths found. Nothing to do.');
178
+ return;
179
+ }
180
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
181
+ for (const filePath of modifiedFiles) {
182
+ const sourceFile = project.getSourceFileOrThrow(filePath);
183
+ yield sourceFile.save();
184
+ console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
185
+ }
186
+ console.log(`\nDone. Renamed ${totalRenamed} route path(s).`);
187
+ });
188
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=rename-location-parent-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-location-parent-id.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/rename-location-parent-id.ts"],"names":[],"mappings":"AAqJA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,181 @@
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: Rename `parentId` to `administrativeAreaId` on `Location` typed expressions.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/rename-location-parent-id.ts
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds every property access expression whose property name is `parentId`
35
+ * - Uses the TypeScript type checker to resolve the type of the object being accessed
36
+ * - Only renames to `administrativeAreaId` when the type (or any union constituent) is
37
+ * the OpenCRVS `Location` type, identified via three strategies in order:
38
+ * 1. Alias symbol name equals 'Location' (works when TypeScript preserves alias info)
39
+ * 2. Direct symbol name equals 'Location'
40
+ * 3. Structural fallback: the type is an object with the property set that uniquely
41
+ * identifies the OpenCRVS Location shape (id, name, externalId, locationType, and
42
+ * either administrativeAreaId or parentId)
43
+ * - Skips `parentId` accesses on any other type (e.g. plain objects, other interfaces)
44
+ * - Saves the modified files in-place
45
+ */
46
+ const ts_morph_1 = require("ts-morph");
47
+ const path_1 = __importDefault(require("path"));
48
+ const _1 = require(".");
49
+ const OLD_PROPERTY_NAME = 'parentId';
50
+ const NEW_PROPERTY_NAME = 'administrativeAreaId';
51
+ const LOCATION_TYPE_NAME = 'Location';
52
+ // Properties that together uniquely identify the OpenCRVS Location type.
53
+ // Used as a structural fallback when TypeScript loses the alias name through
54
+ // re-export chains (e.g. z.infer<…> re-exported via @opencrvs/toolkit/events).
55
+ const LOCATION_STRUCTURAL_PROPS = [
56
+ 'id',
57
+ 'name',
58
+ 'externalId',
59
+ 'locationType'
60
+ ];
61
+ // At least one of these must also be present (old name or new name)
62
+ const LOCATION_AREA_ID_PROPS = ['administrativeAreaId', 'parentId'];
63
+ // ─── Type helpers ─────────────────────────────────────────────────────────────
64
+ /**
65
+ * Returns true if a single (non-union) type resolves to the OpenCRVS Location type.
66
+ *
67
+ * Three strategies are tried in order so that the check remains robust across
68
+ * different TypeScript/ts-morph resolution paths:
69
+ *
70
+ * 1. Alias symbol name — works when TypeScript preserves the `type Location =
71
+ * z.infer<typeof Location>` alias through the re-export chain.
72
+ * 2. Direct symbol name — works when the type is represented by a named interface
73
+ * or class rather than an alias.
74
+ * 3. Structural match — fallback for when both symbol lookups fail (e.g. the
75
+ * alias is lost because the type was re-exported through a barrel or because
76
+ * z.infer<…> fully unwraps the alias). Checks for the combination of
77
+ * properties that uniquely identify the OpenCRVS Location shape.
78
+ */
79
+ function isSingleLocationType(t) {
80
+ var _a, _b;
81
+ // Strategy 1: alias symbol (zod-inferred type aliases surface here)
82
+ if (((_a = t.getAliasSymbol()) === null || _a === void 0 ? void 0 : _a.getName()) === LOCATION_TYPE_NAME)
83
+ return true;
84
+ // Strategy 2: direct symbol (plain interface / class)
85
+ if (((_b = t.getSymbol()) === null || _b === void 0 ? void 0 : _b.getName()) === LOCATION_TYPE_NAME)
86
+ return true;
87
+ // Strategy 3: structural fallback
88
+ if (t.isObject()) {
89
+ const propNames = new Set(t.getProperties().map((p) => p.getName()));
90
+ const hasCorePropNames = LOCATION_STRUCTURAL_PROPS.every((p) => propNames.has(p));
91
+ const hasAreaIdProp = LOCATION_AREA_ID_PROPS.some((p) => propNames.has(p));
92
+ if (hasCorePropNames && hasAreaIdProp)
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+ /**
98
+ * Returns true when the type of `node` is (or has a union constituent that is)
99
+ * the OpenCRVS Location type.
100
+ * Handles:
101
+ * - `Location`
102
+ * - `Location | undefined` (optional / nullable)
103
+ * - `Location | null | undefined`
104
+ */
105
+ function isLocationType(node) {
106
+ let type;
107
+ try {
108
+ type = node.getType();
109
+ }
110
+ catch (_a) {
111
+ // getType() can throw on malformed/unresolvable nodes — skip them
112
+ return false;
113
+ }
114
+ if (isSingleLocationType(type))
115
+ return true;
116
+ // Walk union constituents (Location | undefined, Location | null, …)
117
+ for (const constituent of type.getUnionTypes()) {
118
+ if (isSingleLocationType(constituent))
119
+ return true;
120
+ }
121
+ return false;
122
+ }
123
+ // ─── File processor ──────────────────────────────────────────────────────────
124
+ function processFile(filePath, project) {
125
+ const sourceFile = project.getSourceFile(filePath);
126
+ if (!sourceFile)
127
+ return 0;
128
+ let renamedCount = 0;
129
+ // Collect all matching nodes first to avoid mutating the tree while iterating
130
+ const candidates = sourceFile
131
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAccessExpression)
132
+ .filter((propAccess) => propAccess.getName() === OLD_PROPERTY_NAME);
133
+ for (const propAccess of candidates) {
134
+ const obj = propAccess.getExpression();
135
+ if (!isLocationType(obj))
136
+ continue;
137
+ // Rename only the identifier node (the part after the dot) to preserve
138
+ // surrounding whitespace and optional-chain tokens (?.)
139
+ propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
140
+ renamedCount++;
141
+ console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} → Location.${NEW_PROPERTY_NAME}`);
142
+ }
143
+ return renamedCount;
144
+ }
145
+ // ─── Entry point ─────────────────────────────────────────────────────────────
146
+ function main() {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
149
+ console.log(`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}\n`);
150
+ const project = new ts_morph_1.Project({
151
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
152
+ skipAddingFilesFromTsConfig: false
153
+ });
154
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
155
+ const fp = sf.getFilePath();
156
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
157
+ });
158
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
159
+ let totalRenamed = 0;
160
+ const modifiedFiles = [];
161
+ for (const sourceFile of sourceFiles) {
162
+ const filePath = sourceFile.getFilePath();
163
+ const renamed = processFile(filePath, project);
164
+ if (renamed > 0) {
165
+ totalRenamed += renamed;
166
+ modifiedFiles.push(filePath);
167
+ }
168
+ }
169
+ if (modifiedFiles.length === 0) {
170
+ console.log(`No Location.${OLD_PROPERTY_NAME} references found. Nothing to do.`);
171
+ return;
172
+ }
173
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
174
+ for (const filePath of modifiedFiles) {
175
+ const sourceFile = project.getSourceFileOrThrow(filePath);
176
+ yield sourceFile.save();
177
+ console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
178
+ }
179
+ console.log(`\nDone. Renamed ${totalRenamed} Location.${OLD_PROPERTY_NAME} reference(s) to Location.${NEW_PROPERTY_NAME}.`);
180
+ });
181
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=simplify-analytics-precalculations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplify-analytics-precalculations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/simplify-analytics-precalculations.ts"],"names":[],"mappings":"AAuLA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAyCnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,196 @@
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: Clean up `src/analytics/analytics.ts` by removing the Farajaland
28
+ * sample precalculation wiring.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/simplify-analytics-precalculations.ts
32
+ *
33
+ * Runs LAST, after `checkout-upstream-files` has replaced
34
+ * `src/analytics/analytics.ts` with the upstream v2.0 version. That upstream
35
+ * version hardcodes a Farajaland-specific birth-event precalculation (it
36
+ * imports `Event` and `precalculateBirthEvent`), which countries implementing
37
+ * their own flows don't want. This codemod strips that out so each country
38
+ * starts from a clean placeholder.
39
+ *
40
+ * What it does (only to `src/analytics/analytics.ts`, if present):
41
+ * 1. Removes the named imports `Event` and `precalculateBirthEvent`.
42
+ * If an import declaration becomes empty it is removed entirely.
43
+ * 2. Rewrites the body of `precalculateAdditionalAnalytics` so it contains
44
+ * nothing but `return declaration` — i.e. every statement that
45
+ * references `Event` or `precalculateBirthEvent` is dropped, and a
46
+ * `return declaration` is ensured at the end.
47
+ *
48
+ * The codemod is safe to re-run: if the imports are already gone and the
49
+ * function body is already `return declaration`, it is a no-op.
50
+ */
51
+ const ts_morph_1 = require("ts-morph");
52
+ const fs_1 = __importDefault(require("fs"));
53
+ const path_1 = __importDefault(require("path"));
54
+ const _1 = require(".");
55
+ const ANALYTICS_FILE_REL = 'src/analytics/analytics.ts';
56
+ const FUNCTION_NAME = 'precalculateAdditionalAnalytics';
57
+ const IMPORT_NAMES_TO_REMOVE = new Set(['Event', 'precalculateBirthEvent']);
58
+ const RETURN_EXPRESSION_TEXT = 'declaration';
59
+ // ─── Import cleanup ──────────────────────────────────────────────────────────
60
+ /**
61
+ * Removes every named import in `sourceFile` whose local binding name is in
62
+ * `IMPORT_NAMES_TO_REMOVE`. If a given import declaration is left with no
63
+ * named imports, default import or namespace import, the declaration itself
64
+ * is removed.
65
+ */
66
+ function removeTargetedNamedImports(sourceFile) {
67
+ const log = [];
68
+ for (const importDecl of [...sourceFile.getImportDeclarations()]) {
69
+ const namedImports = importDecl.getNamedImports();
70
+ if (namedImports.length === 0)
71
+ continue;
72
+ const matched = namedImports.filter((ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName()));
73
+ if (matched.length === 0)
74
+ continue;
75
+ const removedNames = matched.map((ni) => ni.getName());
76
+ for (const ni of matched)
77
+ ni.remove();
78
+ log.push(`removed import(s) ${removedNames.join(', ')} from '${importDecl.getModuleSpecifierValue()}'`);
79
+ const stillUsed = importDecl.getNamedImports().length > 0 ||
80
+ importDecl.getDefaultImport() ||
81
+ importDecl.getNamespaceImport();
82
+ if (!stillUsed)
83
+ importDecl.remove();
84
+ }
85
+ return log;
86
+ }
87
+ // ─── Function-body cleanup ───────────────────────────────────────────────────
88
+ /**
89
+ * Returns the `precalculateAdditionalAnalytics` declaration in `sourceFile`,
90
+ * whether it was written as `function precalculateAdditionalAnalytics(...)` or
91
+ * as `const precalculateAdditionalAnalytics = (...) => { ... }`.
92
+ */
93
+ function findPrecalculateFunction(sourceFile) {
94
+ for (const fn of sourceFile.getFunctions()) {
95
+ if (fn.getName() === FUNCTION_NAME)
96
+ return fn;
97
+ }
98
+ for (const statement of sourceFile.getVariableStatements()) {
99
+ for (const decl of statement.getDeclarations()) {
100
+ if (decl.getName() === FUNCTION_NAME)
101
+ return decl;
102
+ }
103
+ }
104
+ return undefined;
105
+ }
106
+ /**
107
+ * Returns the block body of a function declaration or variable-declared arrow
108
+ * / function expression, or undefined if the function has an expression body
109
+ * or doesn't exist.
110
+ */
111
+ function getFunctionBodyBlock(fn) {
112
+ if (ts_morph_1.Node.isFunctionDeclaration(fn))
113
+ return fn.getBody();
114
+ const initializer = fn.getInitializer();
115
+ if (!initializer)
116
+ return undefined;
117
+ if (!ts_morph_1.Node.isArrowFunction(initializer) &&
118
+ !ts_morph_1.Node.isFunctionExpression(initializer)) {
119
+ return undefined;
120
+ }
121
+ return initializer.getBody();
122
+ }
123
+ /**
124
+ * Rewrites the body of `precalculateAdditionalAnalytics` so that the only
125
+ * statement is `return declaration`. Any statement whose subtree references
126
+ * the removed imports (`Event`, `precalculateBirthEvent`) is dropped; a
127
+ * trailing `return declaration` is ensured.
128
+ */
129
+ function simplifyPrecalculateFunction(sourceFile) {
130
+ var _a;
131
+ const log = [];
132
+ const fn = findPrecalculateFunction(sourceFile);
133
+ if (!fn)
134
+ return log;
135
+ const body = getFunctionBodyBlock(fn);
136
+ if (!body || !ts_morph_1.Node.isBlock(body))
137
+ return log;
138
+ // Drop every statement (not just `if`s) whose AST references an identifier
139
+ // in IMPORT_NAMES_TO_REMOVE. This handles both the upstream shape
140
+ // if (eventConfig.id === Event.Birth) return precalculateBirthEvent(...)
141
+ // and any equivalent variant a country might have typed.
142
+ for (const statement of [...body.getStatements()]) {
143
+ const references = statement
144
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
145
+ .some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
146
+ if (references) {
147
+ statement.remove();
148
+ log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
149
+ }
150
+ }
151
+ // Ensure the function ends with `return declaration`. If nothing changed
152
+ // and the body already ends correctly, this is a no-op.
153
+ const remaining = body.getStatements();
154
+ const last = remaining[remaining.length - 1];
155
+ const alreadyCorrect = last &&
156
+ ts_morph_1.Node.isReturnStatement(last) &&
157
+ ((_a = last.getExpression()) === null || _a === void 0 ? void 0 : _a.getText()) === RETURN_EXPRESSION_TEXT;
158
+ if (!alreadyCorrect) {
159
+ body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
160
+ log.push(`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`);
161
+ }
162
+ return log;
163
+ }
164
+ // ─── Entry point ─────────────────────────────────────────────────────────────
165
+ function main() {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const cwd = (0, _1.getCwd)();
168
+ const absPath = path_1.default.join(cwd, ANALYTICS_FILE_REL);
169
+ if (!fs_1.default.existsSync(absPath)) {
170
+ console.log(`[${ANALYTICS_FILE_REL}] does not exist — nothing to clean up.`);
171
+ return;
172
+ }
173
+ const project = new ts_morph_1.Project({
174
+ tsConfigFilePath: path_1.default.resolve(cwd, 'tsconfig.json'),
175
+ skipAddingFilesFromTsConfig: false
176
+ });
177
+ const sourceFile = project.getSourceFile(absPath);
178
+ if (!sourceFile) {
179
+ console.log(`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`);
180
+ return;
181
+ }
182
+ console.log(`Cleaning up ${ANALYTICS_FILE_REL}...\n`);
183
+ const importLogs = removeTargetedNamedImports(sourceFile);
184
+ const fnLogs = simplifyPrecalculateFunction(sourceFile);
185
+ const allLogs = [...importLogs, ...fnLogs];
186
+ if (allLogs.length === 0) {
187
+ console.log(`[${ANALYTICS_FILE_REL}] already clean — nothing to do.`);
188
+ return;
189
+ }
190
+ for (const log of allLogs) {
191
+ console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
192
+ }
193
+ yield sourceFile.save();
194
+ console.log(`\nSaved ${ANALYTICS_FILE_REL}.`);
195
+ });
196
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notification/index.ts"],"names":[],"mappings":"AAUA,cAAc,gCAAgC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notification/index.ts"],"names":[],"mappings":"AAaA,cAAc,gCAAgC,CAAA"}