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

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 (157) hide show
  1. package/build.sh +13 -0
  2. package/create-countryconfig/index.js +73 -0
  3. package/create-countryconfig/package.json +11 -0
  4. package/dist/api/index.d.ts.map +1 -1
  5. package/dist/application-config/index.d.ts +2 -0
  6. package/dist/application-config/index.d.ts.map +1 -0
  7. package/dist/application-config/index.js +2158 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +4974 -0
  11. package/dist/commons/api/router.d.ts +3497 -2348
  12. package/dist/commons/application-config/index.d.ts +96 -0
  13. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  14. package/dist/commons/conditionals/validate.d.ts +13 -3
  15. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  16. package/dist/commons/events/ActionDocument.d.ts +888 -1941
  17. package/dist/commons/events/ActionInput.d.ts +277 -1073
  18. package/dist/commons/events/ActionType.d.ts +91 -11
  19. package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
  20. package/dist/commons/events/AuditLog.d.ts +407 -0
  21. package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
  22. package/dist/commons/events/Conditional.d.ts +26 -38
  23. package/dist/commons/events/Constants.d.ts +1 -1
  24. package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
  25. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  26. package/dist/commons/events/Draft.d.ts +72 -107
  27. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  28. package/dist/commons/events/EventConfig.d.ts +37 -2420
  29. package/dist/commons/events/EventConfigInput.d.ts +0 -3
  30. package/dist/commons/events/EventDocument.d.ts +354 -1366
  31. package/dist/commons/events/EventIndex.d.ts +212 -1010
  32. package/dist/commons/events/EventInput.d.ts +3 -8
  33. package/dist/commons/events/EventMetadata.d.ts +130 -357
  34. package/dist/commons/events/FieldConfig.d.ts +2902 -12892
  35. package/dist/commons/events/FieldType.d.ts +26 -4
  36. package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
  37. package/dist/commons/events/FieldValue.d.ts +149 -527
  38. package/dist/commons/events/FileUtils.d.ts +2 -2
  39. package/dist/commons/events/Flag.d.ts +67 -0
  40. package/dist/commons/events/FormConfig.d.ts +54 -721
  41. package/dist/commons/events/PageConfig.d.ts +58 -320
  42. package/dist/commons/events/PlainDate.d.ts +1 -1
  43. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  44. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  45. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  46. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  47. package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
  48. package/dist/commons/events/deduplication.d.ts +3 -3
  49. package/dist/commons/events/defineConfig.d.ts +2 -247
  50. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  51. package/dist/commons/events/index.d.ts +3 -0
  52. package/dist/commons/events/locations.d.ts +93 -19
  53. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  54. package/dist/commons/events/scopes.d.ts +56 -32
  55. package/dist/commons/events/state/availableActions.d.ts +7 -2
  56. package/dist/commons/events/state/flags.d.ts +21 -3
  57. package/dist/commons/events/state/index.d.ts +30 -27
  58. package/dist/commons/events/state/utils.d.ts +190 -172
  59. package/dist/commons/events/test.utils.d.ts +52 -11
  60. package/dist/commons/events/transactions.d.ts +1 -1
  61. package/dist/commons/events/utils.d.ts +373 -273
  62. package/dist/commons/notification/UserNotifications.d.ts +76 -637
  63. package/dist/conditionals/index.d.ts.map +1 -1
  64. package/dist/conditionals/index.js +332 -14
  65. package/dist/events/deduplication.d.ts +3 -3
  66. package/dist/events/index.js +2996 -2127
  67. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  68. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +429 -0
  70. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  71. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  73. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  74. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  76. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  77. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
  79. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  80. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
  82. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  83. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/create-events-index.js +325 -0
  85. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  86. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  88. package/dist/migrations/v2.0/index.d.ts +11 -0
  89. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/index.js +4884 -0
  91. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  92. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +432 -0
  94. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  95. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  97. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  98. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  100. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  101. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  103. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  104. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
  106. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  107. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/migrate-workqueue-configs.js +236 -0
  109. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
  112. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  113. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
  115. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  116. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
  118. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  119. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  121. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  122. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  123. package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
  124. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  125. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  126. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  127. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  128. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  129. package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
  130. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  131. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  132. package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
  133. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  134. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  135. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  136. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  137. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  138. package/dist/migrations/v2.0/rename-api-paths.js +187 -0
  139. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  140. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  141. package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
  142. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  143. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  144. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  145. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  146. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  147. package/dist/migrations/v2.0/update-package-json.js +105 -0
  148. package/dist/notification/index.d.ts.map +1 -1
  149. package/dist/notification/index.js +2112 -1767
  150. package/dist/scopes/index.d.ts +716 -352
  151. package/dist/scopes/index.d.ts.map +1 -1
  152. package/dist/scopes/index.js +374 -299
  153. package/opencrvs-toolkit-2.0.0-beta.tgz +0 -0
  154. package/package.json +18 -8
  155. package/tsconfig.json +12 -2
  156. package/tsconfig.tsbuildinfo +1 -1
  157. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -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"}
@@ -0,0 +1,342 @@
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: Replace usages of the legacy `APPLICATION_CONFIG_URL` env-derived
28
+ * constant with direct usage of the v2.0 `applicationConfig` object.
29
+ *
30
+ * Background:
31
+ * In v1.9 country configs read application configuration over HTTP from
32
+ * the config service via `APPLICATION_CONFIG_URL`. In v2.0 the config is
33
+ * defined statically in `src/api/application/application-config.ts` (as
34
+ * `applicationConfig`) and consumed by import.
35
+ *
36
+ * What it does (per source file under `src/`):
37
+ * 1. If the file imports `APPLICATION_CONFIG_URL` (from any module), the
38
+ * named import is removed; if that leaves the import declaration empty,
39
+ * the whole declaration is removed.
40
+ * 2. An import of `applicationConfig` from
41
+ * `@countryconfig/api/application/application-config` is added
42
+ * (idempotent — re-uses an existing import declaration if one exists).
43
+ * 3. Block-bodied functions whose body references *both*
44
+ * `APPLICATION_CONFIG_URL` *and* a `fetch(...)` call are recognised
45
+ * as "config-fetcher" functions. Their entire body is replaced with
46
+ * `return applicationConfig` — eliminating the URL construction,
47
+ * `fetch`, JSON parsing, and unwrapping of `.config`. Callers
48
+ * (`await getApplicationConfig()` etc.) keep working because async
49
+ * functions still wrap the return value in a `Promise`.
50
+ * 4. Any remaining bare identifier references to `APPLICATION_CONFIG_URL`
51
+ * are renamed to `applicationConfig`. Property names (e.g.
52
+ * `obj.APPLICATION_CONFIG_URL` or `{ APPLICATION_CONFIG_URL: x }`)
53
+ * are left alone.
54
+ *
55
+ * Caveats:
56
+ * - Wholesale body replacement of config-fetcher functions destroys any
57
+ * custom logic the country had inlined there (error handling, derived
58
+ * fields, etc.). Each rewrite is logged so the developer can review
59
+ * the diff and re-apply customisations on top of `applicationConfig`.
60
+ * - The shape of v2.0 `applicationConfig` is not identical to the v1.9
61
+ * `IApplicationConfigResponse.config` — callers that destructured
62
+ * v1.9-only fields will produce TypeScript errors and need manual
63
+ * review.
64
+ * - Files that have a local declaration named `applicationConfig` are
65
+ * skipped to avoid a name collision; a warning is logged so the
66
+ * developer can resolve it manually.
67
+ * - Files that reference `APPLICATION_CONFIG_URL` *without* importing it
68
+ * (e.g. as a local variable) are skipped — we only rewrite imported
69
+ * usages.
70
+ * - Concise-body arrow functions (`() => fetch(...)`) are not
71
+ * body-rewritten — only their identifier is renamed in step 4. If a
72
+ * country happens to inline the fetch in concise form, the result
73
+ * will need manual cleanup.
74
+ */
75
+ const path_1 = __importDefault(require("path"));
76
+ const ts_morph_1 = require("ts-morph");
77
+ const TARGET_IDENTIFIER = 'APPLICATION_CONFIG_URL';
78
+ const REPLACEMENT_IDENTIFIER = 'applicationConfig';
79
+ const REPLACEMENT_MODULE = '@countryconfig/api/application/application-config';
80
+ /**
81
+ * Function-like syntax kinds whose `body` we know how to replace via
82
+ * `setBodyText` (i.e. block-bodied callables).
83
+ */
84
+ const FUNCTION_LIKE_KINDS = [
85
+ ts_morph_1.SyntaxKind.FunctionDeclaration,
86
+ ts_morph_1.SyntaxKind.FunctionExpression,
87
+ ts_morph_1.SyntaxKind.ArrowFunction,
88
+ ts_morph_1.SyntaxKind.MethodDeclaration
89
+ ];
90
+ /**
91
+ * Returns the name of the function-like node for logging purposes.
92
+ * Falls back to `<anonymous>` when nothing useful can be derived.
93
+ */
94
+ function describeFunction(node) {
95
+ var _a, _b, _c;
96
+ if (ts_morph_1.Node.isFunctionDeclaration(node) || ts_morph_1.Node.isMethodDeclaration(node)) {
97
+ return (_a = node.getName()) !== null && _a !== void 0 ? _a : '<anonymous>';
98
+ }
99
+ // FunctionExpression / ArrowFunction: try to pick up the assignment target.
100
+ const parent = node.getParent();
101
+ if (parent && ts_morph_1.Node.isVariableDeclaration(parent)) {
102
+ return parent.getName();
103
+ }
104
+ if (parent && ts_morph_1.Node.isPropertyAssignment(parent)) {
105
+ return parent.getName();
106
+ }
107
+ if (ts_morph_1.Node.isFunctionExpression(node) &&
108
+ node.getNameNode() !== undefined) {
109
+ return (_c = (_b = node.getNameNode()) === null || _b === void 0 ? void 0 : _b.getText()) !== null && _c !== void 0 ? _c : '<anonymous>';
110
+ }
111
+ return '<anonymous>';
112
+ }
113
+ /**
114
+ * True when the node has a block body that we can safely replace via
115
+ * `setBodyText` (excludes concise-body arrow functions like `() => 1`).
116
+ */
117
+ function hasBlockBody(node) {
118
+ if (ts_morph_1.Node.isFunctionDeclaration(node) ||
119
+ ts_morph_1.Node.isFunctionExpression(node) ||
120
+ ts_morph_1.Node.isMethodDeclaration(node)) {
121
+ return node.getBody() !== undefined;
122
+ }
123
+ if (ts_morph_1.Node.isArrowFunction(node)) {
124
+ return node.getBody().getKind() === ts_morph_1.SyntaxKind.Block;
125
+ }
126
+ return false;
127
+ }
128
+ /**
129
+ * True when the node's body references `APPLICATION_CONFIG_URL` AND
130
+ * contains at least one `fetch(...)` call — the "config-fetcher" signature.
131
+ */
132
+ function isConfigFetcher(node) {
133
+ let referencesTarget = false;
134
+ let callsFetch = false;
135
+ for (const id of node.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)) {
136
+ const text = id.getText();
137
+ if (!referencesTarget && text === TARGET_IDENTIFIER)
138
+ referencesTarget = true;
139
+ if (!callsFetch && text === 'fetch') {
140
+ // Only count `fetch(` calls, not bare references like
141
+ // `const f = fetch` (rare, but pedantic).
142
+ const parent = id.getParent();
143
+ if (ts_morph_1.Node.isCallExpression(parent) &&
144
+ parent.getExpression() === id) {
145
+ callsFetch = true;
146
+ }
147
+ }
148
+ if (referencesTarget && callsFetch)
149
+ return true;
150
+ }
151
+ return false;
152
+ }
153
+ function processFile(sourceFile) {
154
+ const importsWithTarget = sourceFile
155
+ .getImportDeclarations()
156
+ .filter((decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER));
157
+ if (importsWithTarget.length === 0) {
158
+ return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
159
+ }
160
+ // Bail out if a same-named local would collide with the new identifier.
161
+ // Imported `applicationConfig` doesn't count as a local declaration.
162
+ const collidingLocals = sourceFile
163
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
164
+ .filter((id) => id.getText() === REPLACEMENT_IDENTIFIER)
165
+ .filter((id) => {
166
+ const parent = id.getParent();
167
+ const kind = parent.getKind();
168
+ return (kind === ts_morph_1.SyntaxKind.VariableDeclaration ||
169
+ kind === ts_morph_1.SyntaxKind.FunctionDeclaration ||
170
+ kind === ts_morph_1.SyntaxKind.ClassDeclaration ||
171
+ kind === ts_morph_1.SyntaxKind.Parameter);
172
+ });
173
+ if (collidingLocals.length > 0) {
174
+ return {
175
+ changed: false,
176
+ rewrittenFunctions: [],
177
+ renamedReferences: 0,
178
+ skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
179
+ };
180
+ }
181
+ // ─── 1. Rewrite "config-fetcher" function bodies ───────────────────────
182
+ // We only replace block-bodied functions that reference both
183
+ // APPLICATION_CONFIG_URL and `fetch(...)`. The bodies are replaced with
184
+ // `return applicationConfig`, which works for both sync and async
185
+ // functions (the latter automatically wraps the value in a Promise).
186
+ const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap((kind) => sourceFile.getDescendantsOfKind(kind));
187
+ // Outermost-first: when functions are nested, rewriting the outer one
188
+ // also discards the inner one, so we shouldn't try to rewrite the inner
189
+ // afterwards. Sorting by start position handles this; we additionally
190
+ // filter out any candidate whose ancestor we already rewrote.
191
+ candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
192
+ const rewrittenFunctions = [];
193
+ const rewrittenSet = new Set();
194
+ for (const fn of candidateFunctions) {
195
+ if (!hasBlockBody(fn))
196
+ continue;
197
+ if (!isConfigFetcher(fn))
198
+ continue;
199
+ // Skip if any ancestor was already rewritten (its descendants are now
200
+ // detached from the source file).
201
+ let inRewrittenAncestor = false;
202
+ let cursor = fn.getParent();
203
+ while (cursor) {
204
+ if (rewrittenSet.has(cursor)) {
205
+ inRewrittenAncestor = true;
206
+ break;
207
+ }
208
+ cursor = cursor.getParent();
209
+ }
210
+ if (inRewrittenAncestor)
211
+ continue;
212
+ const start = fn.getStart();
213
+ const line = sourceFile.getLineAndColumnAtPos(start).line;
214
+ const name = describeFunction(fn);
215
+ if (ts_morph_1.Node.isFunctionDeclaration(fn) ||
216
+ ts_morph_1.Node.isFunctionExpression(fn) ||
217
+ ts_morph_1.Node.isMethodDeclaration(fn) ||
218
+ ts_morph_1.Node.isArrowFunction(fn)) {
219
+ fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
220
+ }
221
+ rewrittenFunctions.push({ name, line });
222
+ rewrittenSet.add(fn);
223
+ }
224
+ // ─── 2. Remove the `APPLICATION_CONFIG_URL` import ─────────────────────
225
+ for (const decl of importsWithTarget) {
226
+ const targetNamed = decl
227
+ .getNamedImports()
228
+ .find((ni) => ni.getName() === TARGET_IDENTIFIER);
229
+ targetNamed === null || targetNamed === void 0 ? void 0 : targetNamed.remove();
230
+ const isNowEmpty = decl.getNamedImports().length === 0 &&
231
+ !decl.getDefaultImport() &&
232
+ !decl.getNamespaceImport();
233
+ if (isNowEmpty)
234
+ decl.remove();
235
+ }
236
+ // ─── 3. Add the new `applicationConfig` import ─────────────────────────
237
+ const existing = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE);
238
+ if (existing) {
239
+ const alreadyImported = existing
240
+ .getNamedImports()
241
+ .some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
242
+ if (!alreadyImported)
243
+ existing.addNamedImport(REPLACEMENT_IDENTIFIER);
244
+ }
245
+ else {
246
+ sourceFile.addImportDeclaration({
247
+ moduleSpecifier: REPLACEMENT_MODULE,
248
+ namedImports: [REPLACEMENT_IDENTIFIER]
249
+ });
250
+ }
251
+ // ─── 4. Rename remaining identifier references ─────────────────────────
252
+ // Anything still named APPLICATION_CONFIG_URL after the function-body
253
+ // rewrites and import cleanup is a stray reference; rename it. Iterate
254
+ // from highest position to lowest so `replaceWithText` doesn't shift
255
+ // offsets for nodes we haven't visited yet.
256
+ const renameTargets = sourceFile
257
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
258
+ .filter((id) => id.getText() === TARGET_IDENTIFIER)
259
+ .filter((id) => !id.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ImportDeclaration))
260
+ .filter((id) => {
261
+ const parent = id.getParent();
262
+ const parentKind = parent.getKind();
263
+ if (parentKind === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
264
+ const pae = parent.asKind(ts_morph_1.SyntaxKind.PropertyAccessExpression);
265
+ // Right-hand side of `x.APPLICATION_CONFIG_URL` — leave alone.
266
+ if (pae.getNameNode() === id)
267
+ return false;
268
+ }
269
+ if (parentKind === ts_morph_1.SyntaxKind.PropertyAssignment) {
270
+ const pa = parent.asKind(ts_morph_1.SyntaxKind.PropertyAssignment);
271
+ // `{ APPLICATION_CONFIG_URL: ... }` — leave the key alone.
272
+ if (pa.getNameNode() === id)
273
+ return false;
274
+ }
275
+ if (parentKind === ts_morph_1.SyntaxKind.ShorthandPropertyAssignment) {
276
+ // `{ APPLICATION_CONFIG_URL }` shorthand — both binding name AND
277
+ // referenced symbol. Leave alone here; if the user wants to rename
278
+ // the referenced value they should expand it manually first.
279
+ return false;
280
+ }
281
+ return true;
282
+ })
283
+ .sort((a, b) => b.getPos() - a.getPos());
284
+ for (const id of renameTargets) {
285
+ id.replaceWithText(REPLACEMENT_IDENTIFIER);
286
+ }
287
+ return {
288
+ changed: true,
289
+ rewrittenFunctions,
290
+ renamedReferences: renameTargets.length
291
+ };
292
+ }
293
+ function main() {
294
+ return __awaiter(this, void 0, void 0, function* () {
295
+ const project = new ts_morph_1.Project({
296
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
297
+ skipAddingFilesFromTsConfig: false
298
+ });
299
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
300
+ const fp = sf.getFilePath();
301
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
302
+ });
303
+ console.log(`Migrating '${TARGET_IDENTIFIER}' → '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...\n`);
304
+ let changedFiles = 0;
305
+ let totalRewrittenFunctions = 0;
306
+ let totalRenamedReferences = 0;
307
+ const skipped = [];
308
+ for (const sourceFile of sourceFiles) {
309
+ const filePath = sourceFile.getFilePath();
310
+ const rel = path_1.default.relative(process.cwd(), filePath);
311
+ const result = processFile(sourceFile);
312
+ if (result.skippedReason) {
313
+ skipped.push(`${rel} (${result.skippedReason})`);
314
+ continue;
315
+ }
316
+ if (!result.changed)
317
+ continue;
318
+ yield sourceFile.save();
319
+ changedFiles++;
320
+ totalRewrittenFunctions += result.rewrittenFunctions.length;
321
+ totalRenamedReferences += result.renamedReferences;
322
+ for (const fn of result.rewrittenFunctions) {
323
+ console.log(` [${rel}:${fn.line}] Rewrote '${fn.name}' body → 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`);
324
+ }
325
+ if (result.renamedReferences > 0) {
326
+ console.log(` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} → ${REPLACEMENT_IDENTIFIER}`);
327
+ }
328
+ }
329
+ if (skipped.length > 0) {
330
+ console.warn(`\n ${skipped.length} file(s) skipped:\n` +
331
+ skipped.map((s) => ` - ${s}`).join('\n'));
332
+ }
333
+ if (changedFiles === 0) {
334
+ console.log(`\nNo files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
335
+ return;
336
+ }
337
+ console.log(`\nDone. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`);
338
+ if (totalRewrittenFunctions > 0) {
339
+ console.log(`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`);
340
+ }
341
+ });
342
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAyVA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,281 @@
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
+ const ts_morph_1 = require("ts-morph");
27
+ const path_1 = __importDefault(require("path"));
28
+ const scopes_1 = require("../commons/scopes");
29
+ const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
30
+ const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
31
+ const SCOPES_PROPERTY_NAME = 'scopes';
32
+ const TOOLKIT_SCOPES_MODULE = '@opencrvs/toolkit/scopes';
33
+ const DEFINE_SCOPES_IMPORT_NAME = 'defineScopes';
34
+ const DEFINE_ROLES_IMPORT_NAME = 'defineRoles';
35
+ function resolveScopeKeyFromElementAccess(element) {
36
+ if (ts_morph_1.Node.isPropertyAccessExpression(element) &&
37
+ element.getExpression().getText() === 'SCOPES') {
38
+ return element.getName();
39
+ }
40
+ if (ts_morph_1.Node.isElementAccessExpression(element) &&
41
+ element.getExpression().getText() === 'SCOPES') {
42
+ const argumentExpression = element.getArgumentExpression();
43
+ if (argumentExpression &&
44
+ (ts_morph_1.Node.isStringLiteral(argumentExpression) ||
45
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
46
+ return argumentExpression.getLiteralValue();
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ function resolveLegacyScopeFromElement(element) {
52
+ if (ts_morph_1.Node.isStringLiteral(element) ||
53
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(element)) {
54
+ return element.getLiteralValue();
55
+ }
56
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
57
+ if (scopeKey) {
58
+ const scopeValue = scopes_deprecated_do_not_use_1.SCOPES[scopeKey];
59
+ return typeof scopeValue === 'string' ? scopeValue : null;
60
+ }
61
+ const expressionType = element.getType();
62
+ if (expressionType.isStringLiteral()) {
63
+ const literalValue = expressionType.getLiteralValue();
64
+ return typeof literalValue === 'string' ? literalValue : null;
65
+ }
66
+ return null;
67
+ }
68
+ function migrateScopesArrays(rolesFilePath, project) {
69
+ const sourceFile = project.getSourceFile(rolesFilePath);
70
+ if (!sourceFile)
71
+ return { migratedCount: 0, removedCount: 0 };
72
+ let migratedCount = 0;
73
+ let removedCount = 0;
74
+ const scopesProperties = sourceFile
75
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
76
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
77
+ for (const scopesProp of scopesProperties) {
78
+ const initializer = scopesProp.getInitializer();
79
+ if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
80
+ continue;
81
+ const elements = initializer.getElements();
82
+ for (let index = elements.length - 1; index >= 0; index--) {
83
+ const element = elements[index];
84
+ if (!ts_morph_1.Node.isExpression(element))
85
+ continue;
86
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
87
+ if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
88
+ // eslint-disable-next-line no-console
89
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`);
90
+ initializer.removeElement(index);
91
+ removedCount++;
92
+ continue;
93
+ }
94
+ const legacyScope = resolveLegacyScopeFromElement(element);
95
+ if (!legacyScope) {
96
+ // eslint-disable-next-line no-console
97
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`);
98
+ continue;
99
+ }
100
+ try {
101
+ const migratedScope = (0, scopes_deprecated_do_not_use_1.legacyScopeToV2Scope)(legacyScope);
102
+ const scope = (0, scopes_1.decodeScope)(migratedScope);
103
+ if (!scope) {
104
+ // eslint-disable-next-line no-console
105
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`);
106
+ continue;
107
+ }
108
+ element.replaceWithText(JSON.stringify(scope));
109
+ migratedCount++;
110
+ }
111
+ catch (error) {
112
+ // eslint-disable-next-line no-console
113
+ console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
114
+ }
115
+ }
116
+ }
117
+ if (removedCount > 0) {
118
+ // eslint-disable-next-line no-console
119
+ console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${path_1.default.relative(process.cwd(), rolesFilePath)}'.`);
120
+ }
121
+ return { migratedCount, removedCount };
122
+ }
123
+ function ensureScopesHelpersImport(rolesFilePath, project) {
124
+ const sourceFile = project.getSourceFile(rolesFilePath);
125
+ if (!sourceFile)
126
+ return false;
127
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE);
128
+ let changed = false;
129
+ if (existingImport) {
130
+ const hasDefineScopesImport = existingImport
131
+ .getNamedImports()
132
+ .some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
133
+ const hasDefineRolesImport = existingImport
134
+ .getNamedImports()
135
+ .some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
136
+ if (!hasDefineScopesImport) {
137
+ existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
138
+ changed = true;
139
+ }
140
+ if (!hasDefineRolesImport) {
141
+ existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
142
+ changed = true;
143
+ }
144
+ const encodeScopeImport = existingImport
145
+ .getNamedImports()
146
+ .find((ni) => ni.getName() === 'encodeScope');
147
+ if (encodeScopeImport) {
148
+ encodeScopeImport.remove();
149
+ changed = true;
150
+ }
151
+ return changed;
152
+ }
153
+ sourceFile.addImportDeclaration({
154
+ moduleSpecifier: TOOLKIT_SCOPES_MODULE,
155
+ namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
156
+ });
157
+ return true;
158
+ }
159
+ function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
160
+ const sourceFile = project.getSourceFile(rolesFilePath);
161
+ if (!sourceFile)
162
+ return 0;
163
+ let wrappedCount = 0;
164
+ const scopesProperties = sourceFile
165
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
166
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
167
+ for (const scopesProp of scopesProperties) {
168
+ const initializer = scopesProp.getInitializer();
169
+ if (!initializer)
170
+ continue;
171
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
172
+ initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
173
+ continue;
174
+ }
175
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
176
+ continue;
177
+ scopesProp.setInitializer(`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`);
178
+ wrappedCount++;
179
+ }
180
+ return wrappedCount;
181
+ }
182
+ function wrapRolesWithDefineRoles(rolesFilePath, project) {
183
+ const sourceFile = project.getSourceFile(rolesFilePath);
184
+ if (!sourceFile)
185
+ return false;
186
+ const rolesDeclaration = sourceFile.getVariableDeclaration('roles');
187
+ if (!rolesDeclaration)
188
+ return false;
189
+ const initializer = rolesDeclaration.getInitializer();
190
+ if (!initializer)
191
+ return false;
192
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
193
+ initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
194
+ return false;
195
+ }
196
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
197
+ return false;
198
+ const typeNode = rolesDeclaration.getTypeNode();
199
+ if (typeNode === null || typeNode === void 0 ? void 0 : typeNode.getText().includes('Role')) {
200
+ rolesDeclaration.removeType();
201
+ }
202
+ rolesDeclaration.setInitializer(`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`);
203
+ return true;
204
+ }
205
+ function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
206
+ const importDeclaration = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === moduleSpecifier);
207
+ if (!importDeclaration)
208
+ return false;
209
+ const namedImport = importDeclaration
210
+ .getNamedImports()
211
+ .find((ni) => ni.getName() === importName);
212
+ if (!namedImport)
213
+ return false;
214
+ const references = sourceFile
215
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
216
+ .filter((identifier) => identifier.getText() === importName &&
217
+ !ts_morph_1.Node.isImportSpecifier(identifier.getParent()));
218
+ if (references.length > 0) {
219
+ return false;
220
+ }
221
+ namedImport.remove();
222
+ if (importDeclaration.getNamedImports().length === 0 &&
223
+ !importDeclaration.getDefaultImport() &&
224
+ !importDeclaration.getNamespaceImport()) {
225
+ importDeclaration.remove();
226
+ }
227
+ return true;
228
+ }
229
+ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
230
+ const sourceFile = project.getSourceFile(rolesFilePath);
231
+ if (!sourceFile)
232
+ return false;
233
+ let removed = false;
234
+ const roleTypeAlias = sourceFile.getTypeAlias('Role');
235
+ if (roleTypeAlias) {
236
+ roleTypeAlias.remove();
237
+ removed = true;
238
+ }
239
+ const roleInterface = sourceFile.getInterface('Role');
240
+ if (roleInterface) {
241
+ roleInterface.remove();
242
+ removed = true;
243
+ }
244
+ const removedScopeImport = pruneNamedImportIfUnused(sourceFile, TOOLKIT_SCOPES_MODULE, 'Scope');
245
+ const removedMessageDescriptorImport = pruneNamedImportIfUnused(sourceFile, 'react-intl', 'MessageDescriptor');
246
+ removed = removed || removedScopeImport || removedMessageDescriptorImport;
247
+ return removed;
248
+ }
249
+ function main() {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ const cwd = process.cwd();
252
+ const srcDir = path_1.default.join(cwd, 'src');
253
+ const rolesFilePath = path_1.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
254
+ console.log(`Scanning roles scopes in: ${rolesFilePath}`);
255
+ const project = new ts_morph_1.Project({
256
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
257
+ skipAddingFilesFromTsConfig: false
258
+ });
259
+ const sourceFile = project.getSourceFile(rolesFilePath);
260
+ if (!sourceFile) {
261
+ console.log(`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`);
262
+ return;
263
+ }
264
+ const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
265
+ const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
266
+ const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
267
+ const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
268
+ const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
269
+ if (migratedCount === 0 &&
270
+ removedCount === 0 &&
271
+ wrappedScopesCount === 0 &&
272
+ !wrappedRoles &&
273
+ !removedRoleType &&
274
+ !importChanged) {
275
+ console.log('No migratable literal scopes found. Nothing to do.');
276
+ return;
277
+ }
278
+ yield sourceFile.save();
279
+ console.log(`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
280
+ });
281
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-validated-workqueue-status-to-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-validated-workqueue-status-to-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts"],"names":[],"mappings":"AAyQA,iBAAe,IAAI,kBA+ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}