@opencrvs/toolkit 1.9.12-rc.87b5aae → 1.9.12-rc.888e9f5
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.
- package/dist/application-config/index.js +1 -1
- package/dist/cli.js +1246 -35
- package/dist/commons/api/router.d.ts +193 -181
- package/dist/commons/events/EventConfig.d.ts +3 -1
- package/dist/commons/events/FieldConfig.d.ts +2 -2
- package/dist/commons/events/scopes.d.ts +1 -1
- package/dist/events/index.js +17 -4
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +97 -21
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +326 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +1244 -33
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +6 -5
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
- package/dist/notification/index.js +5 -2
- package/opencrvs-toolkit-1.9.12-rc.888e9f5.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.87b5aae.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AA2VA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -25,7 +25,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.main = main;
|
|
26
26
|
const ts_morph_1 = require("ts-morph");
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const
|
|
28
|
+
const scopes_1 = require("../commons/scopes");
|
|
29
|
+
const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
|
|
29
30
|
const _1 = require(".");
|
|
30
31
|
const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
|
|
31
32
|
const SCOPES_PROPERTY_NAME = 'scopes';
|
|
@@ -55,7 +56,7 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
55
56
|
}
|
|
56
57
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
57
58
|
if (scopeKey) {
|
|
58
|
-
const scopeValue =
|
|
59
|
+
const scopeValue = scopes_deprecated_do_not_use_1.SCOPES[scopeKey];
|
|
59
60
|
return typeof scopeValue === 'string' ? scopeValue : null;
|
|
60
61
|
}
|
|
61
62
|
const expressionType = element.getType();
|
|
@@ -84,7 +85,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
84
85
|
if (!ts_morph_1.Node.isExpression(element))
|
|
85
86
|
continue;
|
|
86
87
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
87
|
-
if (scopeKey && !(scopeKey in
|
|
88
|
+
if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
|
|
88
89
|
// eslint-disable-next-line no-console
|
|
89
90
|
console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`);
|
|
90
91
|
initializer.removeElement(index);
|
|
@@ -98,8 +99,8 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
98
99
|
continue;
|
|
99
100
|
}
|
|
100
101
|
try {
|
|
101
|
-
const migratedScope = (0,
|
|
102
|
-
const scope = (0,
|
|
102
|
+
const migratedScope = (0, scopes_deprecated_do_not_use_1.legacyScopeToV2Scope)(legacyScope);
|
|
103
|
+
const scope = (0, scopes_1.decodeScope)(migratedScope);
|
|
103
104
|
if (!scope) {
|
|
104
105
|
// eslint-disable-next-line no-console
|
|
105
106
|
console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-workqueue-configs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-workqueue-configs.ts"],"names":[],"mappings":"AAiPA,iBAAe,IAAI,kBAqDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,237 @@
|
|
|
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: migrate deprecated workqueue `actions` array to singular `action`.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans TypeScript files under `src/`
|
|
34
|
+
* - Finds `defineWorkqueues([...])` calls
|
|
35
|
+
* - For each workqueue object:
|
|
36
|
+
* - `actions: []` -> removes `actions`
|
|
37
|
+
* - `actions: [{ ... }]` -> replaces with `action: { ... }` if type is supported
|
|
38
|
+
* - `actions: [{ type: 'DEFAULT' }]` -> removes `actions` and does not create `action`
|
|
39
|
+
* - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
|
|
40
|
+
* - If `action` already exists, removes deprecated `actions` and keeps `action`
|
|
41
|
+
* - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
|
|
42
|
+
* - Saves modified files in-place
|
|
43
|
+
*/
|
|
44
|
+
const ts_morph_1 = require("ts-morph");
|
|
45
|
+
const path_1 = __importDefault(require("path"));
|
|
46
|
+
const _1 = require(".");
|
|
47
|
+
const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
|
|
48
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
49
|
+
const ACTION_PROPERTY_NAME = 'action';
|
|
50
|
+
const CONDITIONALS_PROPERTY_NAME = 'conditionals';
|
|
51
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
52
|
+
const SLUG_PROPERTY_NAME = 'slug';
|
|
53
|
+
const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
|
|
54
|
+
'READ',
|
|
55
|
+
'DELETE',
|
|
56
|
+
'DECLARE',
|
|
57
|
+
'REGISTER',
|
|
58
|
+
'EDIT',
|
|
59
|
+
'REJECT',
|
|
60
|
+
'MARK_AS_DUPLICATE',
|
|
61
|
+
'ARCHIVE',
|
|
62
|
+
'PRINT_CERTIFICATE',
|
|
63
|
+
'REQUEST_CORRECTION'
|
|
64
|
+
]);
|
|
65
|
+
function getWorkqueueLabel(workqueue) {
|
|
66
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
67
|
+
if (!slugProperty || !ts_morph_1.Node.isPropertyAssignment(slugProperty)) {
|
|
68
|
+
return '(unknown slug)';
|
|
69
|
+
}
|
|
70
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
71
|
+
if (!slugInitializer || !ts_morph_1.Node.isStringLiteral(slugInitializer)) {
|
|
72
|
+
return '(unknown slug)';
|
|
73
|
+
}
|
|
74
|
+
return slugInitializer.getLiteralValue();
|
|
75
|
+
}
|
|
76
|
+
function getActionTypeName(action) {
|
|
77
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
|
|
78
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
82
|
+
if (!typeInitializer) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (ts_morph_1.Node.isStringLiteral(typeInitializer)) {
|
|
86
|
+
return typeInitializer.getLiteralValue();
|
|
87
|
+
}
|
|
88
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
89
|
+
return typeInitializer.getName();
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function isUnsupportedActionType(action) {
|
|
94
|
+
const typeName = getActionTypeName(action);
|
|
95
|
+
if (!typeName) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
99
|
+
}
|
|
100
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
101
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
|
|
102
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
106
|
+
if (!actionsInitializer || !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
110
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
111
|
+
if (existingActionProperty) {
|
|
112
|
+
if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
|
|
113
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
114
|
+
if (existingActionInitializer && ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
115
|
+
const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
116
|
+
if (conditionalsProperty) {
|
|
117
|
+
conditionalsProperty.remove();
|
|
118
|
+
// eslint-disable-next-line no-console
|
|
119
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
|
|
120
|
+
}
|
|
121
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
122
|
+
existingActionProperty.remove();
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
124
|
+
console.log(` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
actionsProperty.remove();
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
const actionCandidates = actionsInitializer
|
|
134
|
+
.getElements()
|
|
135
|
+
.filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
|
|
136
|
+
if (actionCandidates.length === 0) {
|
|
137
|
+
actionsProperty.remove();
|
|
138
|
+
// eslint-disable-next-line no-console
|
|
139
|
+
console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
if (actionCandidates.length > 1) {
|
|
143
|
+
const droppedCount = actionCandidates.length - 1;
|
|
144
|
+
// eslint-disable-next-line no-console
|
|
145
|
+
console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
|
|
146
|
+
}
|
|
147
|
+
const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
148
|
+
if (conditionalsProperty) {
|
|
149
|
+
conditionalsProperty.remove();
|
|
150
|
+
// eslint-disable-next-line no-console
|
|
151
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
|
|
152
|
+
}
|
|
153
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
154
|
+
actionsProperty.remove();
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
const firstActionText = actionCandidates[0].getText();
|
|
160
|
+
workqueue.addPropertyAssignment({
|
|
161
|
+
name: ACTION_PROPERTY_NAME,
|
|
162
|
+
initializer: firstActionText
|
|
163
|
+
});
|
|
164
|
+
actionsProperty.remove();
|
|
165
|
+
// eslint-disable-next-line no-console
|
|
166
|
+
console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
function processFile(filePath, project) {
|
|
170
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
171
|
+
if (!sourceFile)
|
|
172
|
+
return 0;
|
|
173
|
+
let migratedWorkqueues = 0;
|
|
174
|
+
const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
|
|
175
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
176
|
+
for (const call of callExpressions) {
|
|
177
|
+
const expression = call.getExpression();
|
|
178
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
179
|
+
expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const args = call.getArguments();
|
|
183
|
+
if (args.length === 0)
|
|
184
|
+
continue;
|
|
185
|
+
const workqueuesArg = args[0];
|
|
186
|
+
if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
|
|
187
|
+
continue;
|
|
188
|
+
for (const element of workqueuesArg.getElements()) {
|
|
189
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
190
|
+
continue;
|
|
191
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return migratedWorkqueues;
|
|
195
|
+
}
|
|
196
|
+
function main() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
|
|
199
|
+
// eslint-disable-next-line no-console
|
|
200
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
|
|
201
|
+
const project = new ts_morph_1.Project({
|
|
202
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
203
|
+
skipAddingFilesFromTsConfig: false
|
|
204
|
+
});
|
|
205
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
206
|
+
const fp = sf.getFilePath();
|
|
207
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
208
|
+
});
|
|
209
|
+
// eslint-disable-next-line no-console
|
|
210
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
211
|
+
let totalMigrated = 0;
|
|
212
|
+
const modifiedFiles = [];
|
|
213
|
+
for (const sourceFile of sourceFiles) {
|
|
214
|
+
const filePath = sourceFile.getFilePath();
|
|
215
|
+
const migrated = processFile(filePath, project);
|
|
216
|
+
if (migrated > 0) {
|
|
217
|
+
totalMigrated += migrated;
|
|
218
|
+
modifiedFiles.push(filePath);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (modifiedFiles.length === 0) {
|
|
222
|
+
// eslint-disable-next-line no-console
|
|
223
|
+
console.log("No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do.");
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line no-console
|
|
227
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
228
|
+
for (const filePath of modifiedFiles) {
|
|
229
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
230
|
+
yield sourceFile.save();
|
|
231
|
+
// eslint-disable-next-line no-console
|
|
232
|
+
console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
|
|
233
|
+
}
|
|
234
|
+
// eslint-disable-next-line no-console
|
|
235
|
+
console.log(`\nDone. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-demo-scope.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-demo-scope.ts"],"names":[],"mappings":"AAiBA,iBAAe,IAAI,kBA8DlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
27
|
+
const ts_morph_1 = require("ts-morph");
|
|
28
|
+
const _1 = require(".");
|
|
29
|
+
const ROLES_HANDLER_RELATIVE_PATH = 'src/data-seeding/roles/handler.ts';
|
|
30
|
+
function main() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
33
|
+
const rolesHandlerPath = path_1.default.join((0, _1.getCwd)(), ROLES_HANDLER_RELATIVE_PATH);
|
|
34
|
+
const project = new ts_morph_1.Project({
|
|
35
|
+
tsConfigFilePath: path_1.default.resolve((0, _1.getCwd)(), 'tsconfig.json'),
|
|
36
|
+
skipAddingFilesFromTsConfig: false
|
|
37
|
+
});
|
|
38
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
39
|
+
if (!sourceFile) {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.log(`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let changed = false;
|
|
45
|
+
const constantsImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === '@countryconfig/constants');
|
|
46
|
+
if (constantsImport) {
|
|
47
|
+
constantsImport.remove();
|
|
48
|
+
changed = true;
|
|
49
|
+
}
|
|
50
|
+
const rolesHandler = sourceFile.getFunction('rolesHandler');
|
|
51
|
+
if (!rolesHandler) {
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.log(`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const secondParam = rolesHandler.getParameters()[1];
|
|
57
|
+
const secondParamName = secondParam === null || secondParam === void 0 ? void 0 : secondParam.getName();
|
|
58
|
+
const responseToolkitIdentifier = secondParamName || 'h';
|
|
59
|
+
const currentBodyText = rolesHandler.getBodyText();
|
|
60
|
+
const normalizedCurrent = (_a = currentBodyText === null || currentBodyText === void 0 ? void 0 : currentBodyText.replace(/\s+/g, ' ').trim()) !== null && _a !== void 0 ? _a : '';
|
|
61
|
+
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
62
|
+
if (normalizedCurrent !== normalizedDesired) {
|
|
63
|
+
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
64
|
+
changed = true;
|
|
65
|
+
}
|
|
66
|
+
if (!changed) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.log(`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
yield sourceFile.save();
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.log(`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AA2BA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.main = main;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const _1 = require(".");
|
|
52
|
+
const PATHS_TO_REMOVE = [
|
|
53
|
+
{
|
|
54
|
+
relativePath: 'src/migrations/hearth',
|
|
55
|
+
label: 'Hearth migrations directory'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
relativePath: 'src/migrations/user-mgnt',
|
|
59
|
+
label: 'user-mgnt migrations directory'
|
|
60
|
+
},
|
|
61
|
+
{ relativePath: 'src/utils/hearth-helpers.ts', label: 'Hearth helpers file' }
|
|
62
|
+
];
|
|
63
|
+
function main() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
66
|
+
const absolutePath = path_1.default.join((0, _1.getCwd)(), relativePath);
|
|
67
|
+
if (fs.existsSync(absolutePath)) {
|
|
68
|
+
fs.rmSync(absolutePath, { recursive: true, force: true });
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -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
|
+
}
|