@opencrvs/toolkit 2.0.0-rc.e0b2a80 → 2.0.0-rc.e0eac6c
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/build.sh +2 -2
- package/create-countryconfig/index.js +50 -20
- package/create-countryconfig/package.json +12 -2
- package/dist/application-config/index.js +273 -120
- package/dist/cli.js +105 -4771
- package/dist/commons/api/router.d.ts +3359 -217
- package/dist/commons/application-config/index.d.ts +1 -0
- package/dist/commons/conditionals/conditionals.d.ts +354 -4
- package/dist/commons/conditionals/validate.d.ts +52 -2
- package/dist/commons/events/ActionConfig.d.ts +204 -2
- package/dist/commons/events/ActionDocument.d.ts +6 -0
- package/dist/commons/events/ActionInput.d.ts +114 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
- package/dist/commons/events/Draft.d.ts +4 -2
- package/dist/commons/events/EventDocument.d.ts +3 -0
- package/dist/commons/events/EventIndex.d.ts +14 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -7
- package/dist/commons/events/FieldConfig.d.ts +378 -50
- package/dist/commons/events/FieldType.d.ts +1 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
- package/dist/commons/events/FieldValue.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +189 -150
- package/dist/commons/events/field.d.ts +53 -1
- package/dist/commons/events/index.d.ts +2 -0
- package/dist/commons/events/state/flags.d.ts +16 -0
- package/dist/commons/events/state/index.d.ts +0 -4
- package/dist/commons/events/state/utils.d.ts +12 -289
- package/dist/commons/events/utils.d.ts +13 -2
- package/dist/conditionals/index.js +55 -2
- package/dist/events/index.js +1169 -292
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
- package/dist/migrations/v2.0/index.d.ts +5 -3
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +88 -4869
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +54 -30
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +3 -0
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +234 -0
- package/dist/migrations/v2.1/index.d.ts +6 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -0
- package/dist/migrations/v2.1/index.js +218 -0
- package/dist/notification/index.js +992 -159
- package/dist/scopes/index.d.ts +4 -6
- package/dist/scopes/index.js +12 -4
- package/opencrvs-toolkit-2.0.0-rc.e0eac6c.tgz +0 -0
- package/package.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.e0b2a80.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -23,50 +23,84 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// src/migrations/v2.
|
|
26
|
+
// src/migrations/v2.1/add-explicit-correction-flags.ts
|
|
27
27
|
var import_ts_morph = require("ts-morph");
|
|
28
28
|
var import_path = __toESM(require("path"));
|
|
29
29
|
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
30
30
|
var ACTIONS_PROPERTY_NAME = "actions";
|
|
31
31
|
var TYPE_PROPERTY_NAME = "type";
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
33
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
34
|
+
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
35
|
+
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
36
|
+
var CORRECTION_ACTIONS_TO_ADD = [
|
|
37
|
+
{
|
|
38
|
+
actionType: "APPROVE_CORRECTION",
|
|
39
|
+
labelId: "v2.events.correction.approve.label",
|
|
40
|
+
defaultMessage: "Approve correction",
|
|
41
|
+
description: "Label for the approve correction action"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
actionType: "REJECT_CORRECTION",
|
|
45
|
+
labelId: "v2.events.correction.reject.label",
|
|
46
|
+
defaultMessage: "Reject correction",
|
|
47
|
+
description: "Label for the reject correction action"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
function isActionOfType(obj, typeName) {
|
|
51
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
52
|
+
if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) return false;
|
|
53
|
+
const typeInit = typeProperty.getInitializer();
|
|
54
|
+
if (!typeInit) return false;
|
|
55
|
+
if (import_ts_morph.Node.isPropertyAccessExpression(typeInit)) {
|
|
56
|
+
return typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === typeName;
|
|
44
57
|
}
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
58
|
+
if (import_ts_morph.Node.isStringLiteral(typeInit)) {
|
|
59
|
+
return typeInit.getLiteralValue() === typeName;
|
|
47
60
|
}
|
|
48
61
|
return false;
|
|
49
62
|
}
|
|
50
|
-
function
|
|
63
|
+
function getTypeInitializerStyle(obj) {
|
|
51
64
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
52
|
-
if (
|
|
53
|
-
|
|
65
|
+
if (typeProperty && import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
|
|
66
|
+
const typeInit = typeProperty.getInitializer();
|
|
67
|
+
if (typeInit && import_ts_morph.Node.isPropertyAccessExpression(typeInit)) return "enum";
|
|
54
68
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
return "string";
|
|
70
|
+
}
|
|
71
|
+
function getNonEmptyArrayPropertyText(obj, propName) {
|
|
72
|
+
const prop = obj.getProperty(propName);
|
|
73
|
+
if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
|
|
74
|
+
const init = prop.getInitializer();
|
|
75
|
+
if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
|
|
76
|
+
if (init.getElements().length === 0) return void 0;
|
|
77
|
+
return init.getText();
|
|
78
|
+
}
|
|
79
|
+
function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
|
|
80
|
+
const typeText = typeStyle === "enum" ? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}` : `'${spec.actionType}'`;
|
|
81
|
+
const lines = [
|
|
82
|
+
`type: ${typeText}`,
|
|
83
|
+
`label: {
|
|
84
|
+
id: '${spec.labelId}',
|
|
85
|
+
defaultMessage: '${spec.defaultMessage}',
|
|
86
|
+
description: '${spec.description}'
|
|
87
|
+
}`
|
|
88
|
+
];
|
|
89
|
+
if (flagsText) {
|
|
90
|
+
lines.push(`${FLAGS_PROPERTY_NAME}: ${flagsText}`);
|
|
58
91
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return false;
|
|
92
|
+
if (conditionalsText) {
|
|
93
|
+
lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
|
|
62
94
|
}
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
return `{
|
|
96
|
+
${lines.join(",\n ")}
|
|
97
|
+
}`;
|
|
65
98
|
}
|
|
66
99
|
function processFile(filePath, project) {
|
|
67
100
|
const sourceFile = project.getSourceFile(filePath);
|
|
68
101
|
if (!sourceFile) return 0;
|
|
69
|
-
let
|
|
102
|
+
let changes = 0;
|
|
103
|
+
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
70
104
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
71
105
|
import_ts_morph.SyntaxKind.CallExpression
|
|
72
106
|
);
|
|
@@ -85,18 +119,43 @@ function processFile(filePath, project) {
|
|
|
85
119
|
const actionsInitializer = actionsProperty.getInitializer();
|
|
86
120
|
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
87
121
|
continue;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
122
|
+
const elements = actionsInitializer.getElements();
|
|
123
|
+
const requestCorrectionIndex = elements.findIndex(
|
|
124
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
125
|
+
);
|
|
126
|
+
if (requestCorrectionIndex === -1) continue;
|
|
127
|
+
const requestCorrection = elements[requestCorrectionIndex];
|
|
128
|
+
const flagsText = getNonEmptyArrayPropertyText(
|
|
129
|
+
requestCorrection,
|
|
130
|
+
FLAGS_PROPERTY_NAME
|
|
131
|
+
);
|
|
132
|
+
const conditionalsText = getNonEmptyArrayPropertyText(
|
|
133
|
+
requestCorrection,
|
|
134
|
+
CONDITIONALS_PROPERTY_NAME
|
|
135
|
+
);
|
|
136
|
+
if (!flagsText && !conditionalsText) continue;
|
|
137
|
+
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
138
|
+
let insertAt = requestCorrectionIndex + 1;
|
|
139
|
+
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
140
|
+
const alreadyPresent = actionsInitializer.getElements().some(
|
|
141
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
|
|
142
|
+
);
|
|
143
|
+
if (alreadyPresent) continue;
|
|
144
|
+
const text = buildCorrectionActionText(
|
|
145
|
+
spec,
|
|
146
|
+
typeStyle,
|
|
147
|
+
flagsText,
|
|
148
|
+
conditionalsText
|
|
149
|
+
);
|
|
150
|
+
actionsInitializer.insertElement(insertAt, text);
|
|
151
|
+
insertAt++;
|
|
152
|
+
changes++;
|
|
153
|
+
console.log(
|
|
154
|
+
` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
|
|
155
|
+
);
|
|
97
156
|
}
|
|
98
157
|
}
|
|
99
|
-
return
|
|
158
|
+
return changes;
|
|
100
159
|
}
|
|
101
160
|
async function main() {
|
|
102
161
|
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
@@ -104,9 +163,7 @@ async function main() {
|
|
|
104
163
|
`);
|
|
105
164
|
const project = new import_ts_morph.Project({
|
|
106
165
|
tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
|
|
107
|
-
// Do not emit — we only manipulate source files
|
|
108
166
|
skipAddingFilesFromTsConfig: false
|
|
109
|
-
// addFilesFromTsConfig: true
|
|
110
167
|
});
|
|
111
168
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
112
169
|
const fp = sf.getFilePath();
|
|
@@ -114,19 +171,19 @@ async function main() {
|
|
|
114
171
|
});
|
|
115
172
|
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
116
173
|
`);
|
|
117
|
-
let
|
|
174
|
+
let totalChanges = 0;
|
|
118
175
|
const modifiedFiles = [];
|
|
119
176
|
for (const sourceFile of sourceFiles) {
|
|
120
177
|
const filePath = sourceFile.getFilePath();
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
178
|
+
const changes = processFile(filePath, project);
|
|
179
|
+
if (changes > 0) {
|
|
180
|
+
totalChanges += changes;
|
|
124
181
|
modifiedFiles.push(filePath);
|
|
125
182
|
}
|
|
126
183
|
}
|
|
127
184
|
if (modifiedFiles.length === 0) {
|
|
128
185
|
console.log(
|
|
129
|
-
"No
|
|
186
|
+
"No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do."
|
|
130
187
|
);
|
|
131
188
|
return;
|
|
132
189
|
}
|
|
@@ -139,4736 +196,13 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
139
196
|
}
|
|
140
197
|
console.log(
|
|
141
198
|
`
|
|
142
|
-
Done.
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/migrations/v2.0/make-built-in-validate-actions-custom.ts
|
|
147
|
-
var import_ts_morph2 = require("ts-morph");
|
|
148
|
-
var import_path2 = __toESM(require("path"));
|
|
149
|
-
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
150
|
-
var REQUIRED_SYMBOLS = [
|
|
151
|
-
"ConditionalType",
|
|
152
|
-
"and",
|
|
153
|
-
"status",
|
|
154
|
-
"not",
|
|
155
|
-
"flag",
|
|
156
|
-
"InherentFlags"
|
|
157
|
-
];
|
|
158
|
-
function ensureImports(sourceFile) {
|
|
159
|
-
const existingImport = sourceFile.getImportDeclaration(
|
|
160
|
-
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE
|
|
161
|
-
);
|
|
162
|
-
if (existingImport) {
|
|
163
|
-
const existingNames = new Set(
|
|
164
|
-
existingImport.getNamedImports().map((ni) => ni.getName())
|
|
165
|
-
);
|
|
166
|
-
for (const name of REQUIRED_SYMBOLS) {
|
|
167
|
-
if (!existingNames.has(name)) {
|
|
168
|
-
existingImport.addNamedImport(name);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
sourceFile.addImportDeclaration({
|
|
173
|
-
moduleSpecifier: TOOLKIT_EVENTS_MODULE,
|
|
174
|
-
namedImports: REQUIRED_SYMBOLS
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
|
-
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
|
-
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
-
var ID_PROPERTY_NAME = "id";
|
|
182
|
-
var FLAGS_PROPERTY_NAME = "flags";
|
|
183
|
-
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
184
|
-
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
185
|
-
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
186
|
-
var REVIEW_PROPERTY_NAME2 = "review";
|
|
187
|
-
var FIELDS_PROPERTY_NAME = "fields";
|
|
188
|
-
var FORM_PROPERTY_NAME = "form";
|
|
189
|
-
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
190
|
-
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
191
|
-
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
-
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
193
|
-
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
194
|
-
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
-
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
196
|
-
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
-
var VALIDATED_FLAG_VALUE = "validated";
|
|
198
|
-
function isValidateType(typeInitializer) {
|
|
199
|
-
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
200
|
-
const propAccess = typeInitializer.asKindOrThrow(
|
|
201
|
-
import_ts_morph2.SyntaxKind.PropertyAccessExpression
|
|
202
|
-
);
|
|
203
|
-
const obj = propAccess.getExpression();
|
|
204
|
-
const member = propAccess.getName();
|
|
205
|
-
return import_ts_morph2.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME && member === VALIDATE_MEMBER_NAME;
|
|
206
|
-
}
|
|
207
|
-
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.StringLiteral) {
|
|
208
|
-
return typeInitializer.asKindOrThrow(import_ts_morph2.SyntaxKind.StringLiteral).getLiteralValue() === VALIDATE_STRING_LITERAL;
|
|
209
|
-
}
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
function resolveEventType(configArg) {
|
|
213
|
-
const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME2);
|
|
214
|
-
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return null;
|
|
215
|
-
const initializer = typeProperty.getInitializer();
|
|
216
|
-
if (!initializer) return null;
|
|
217
|
-
if (import_ts_morph2.Node.isStringLiteral(initializer)) {
|
|
218
|
-
return initializer.getLiteralValue().toLowerCase();
|
|
219
|
-
}
|
|
220
|
-
if (initializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression && import_ts_morph2.Node.isPropertyAccessExpression(initializer)) {
|
|
221
|
-
return initializer.getName().toLowerCase();
|
|
222
|
-
}
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
function transformValidateActionToCustom(obj, eventType) {
|
|
226
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME2);
|
|
227
|
-
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
231
|
-
if (!typeInitializer || !isValidateType(typeInitializer)) {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
235
|
-
typeInitializer.replaceWithText(
|
|
236
|
-
`${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`
|
|
237
|
-
);
|
|
238
|
-
} else {
|
|
239
|
-
typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
|
|
240
|
-
}
|
|
241
|
-
if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
|
|
242
|
-
obj.addPropertyAssignment({
|
|
243
|
-
name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
|
|
244
|
-
initializer: `'${VALIDATE_DECLARATION_VALUE}'`
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
|
|
248
|
-
const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
|
|
249
|
-
obj.addPropertyAssignment({
|
|
250
|
-
name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
|
|
251
|
-
initializer: `{
|
|
252
|
-
defaultMessage: 'Validated',
|
|
253
|
-
description: 'The label to show in audit history for the validate action',
|
|
254
|
-
id: '${messageId}'
|
|
255
|
-
}`
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
if (!obj.getProperty("supportingCopy")) {
|
|
259
|
-
const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
|
|
260
|
-
obj.addPropertyAssignment({
|
|
261
|
-
name: "supportingCopy",
|
|
262
|
-
initializer: `{
|
|
263
|
-
defaultMessage:
|
|
264
|
-
'Approving this declaration confirms it as legally accepted and eligible for registration.',
|
|
265
|
-
description:
|
|
266
|
-
'This is the supporting copy for the Validate declaration -action',
|
|
267
|
-
id: '${supportingCopyId}'
|
|
268
|
-
}`
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
if (!obj.getProperty("conditionals")) {
|
|
272
|
-
obj.addPropertyAssignment({
|
|
273
|
-
name: "conditionals",
|
|
274
|
-
initializer: `[
|
|
275
|
-
{
|
|
276
|
-
type: ConditionalType.SHOW,
|
|
277
|
-
conditional: and(status('DECLARED'), not(flag('validated')))
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
type: ConditionalType.ENABLE,
|
|
281
|
-
conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
|
|
282
|
-
}
|
|
283
|
-
]`
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
if (!obj.getProperty("flags")) {
|
|
287
|
-
obj.addPropertyAssignment({
|
|
288
|
-
name: "flags",
|
|
289
|
-
initializer: `[{ id: 'validated', operation: 'add' }]`
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
|
|
293
|
-
if (deduplicationProperty) {
|
|
294
|
-
deduplicationProperty.remove();
|
|
295
|
-
}
|
|
296
|
-
const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME2);
|
|
297
|
-
if (reviewProperty && import_ts_morph2.Node.isPropertyAssignment(reviewProperty)) {
|
|
298
|
-
const reviewInitializer = reviewProperty.getInitializer();
|
|
299
|
-
if (reviewInitializer) {
|
|
300
|
-
if (import_ts_morph2.Node.isObjectLiteralExpression(reviewInitializer)) {
|
|
301
|
-
const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
|
|
302
|
-
if (fieldsProperty && import_ts_morph2.Node.isPropertyAssignment(fieldsProperty)) {
|
|
303
|
-
const fieldsInitializer = fieldsProperty.getInitializer();
|
|
304
|
-
if (fieldsInitializer) {
|
|
305
|
-
reviewProperty.set({
|
|
306
|
-
name: FORM_PROPERTY_NAME,
|
|
307
|
-
initializer: fieldsInitializer.getText()
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
reviewProperty.set({
|
|
313
|
-
name: FORM_PROPERTY_NAME,
|
|
314
|
-
initializer: `${reviewInitializer.getText()}.fields`
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
function isRegisterAction(action) {
|
|
322
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
323
|
-
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
324
|
-
const typeInit = typeProperty.getInitializer();
|
|
325
|
-
if (!typeInit) return false;
|
|
326
|
-
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
327
|
-
const enumExpr = typeInit.getExpression();
|
|
328
|
-
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
329
|
-
}
|
|
330
|
-
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
331
|
-
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
332
|
-
}
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
function arrayHasElementWithId(array3, id) {
|
|
336
|
-
for (const el of array3.getElements()) {
|
|
337
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
338
|
-
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
339
|
-
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
340
|
-
const idInit = idProp.getInitializer();
|
|
341
|
-
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return false;
|
|
346
|
-
}
|
|
347
|
-
function ensureRegisterRemovesValidatedFlag(action) {
|
|
348
|
-
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
349
|
-
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
350
|
-
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
351
|
-
const flagsInit = flagsProp.getInitializer();
|
|
352
|
-
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
353
|
-
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
354
|
-
flagsInit.addElement(entry);
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
action.addPropertyAssignment({
|
|
360
|
-
name: FLAGS_PROPERTY_NAME,
|
|
361
|
-
initializer: `[${entry}]`
|
|
362
|
-
});
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
function processFile2(filePath, project) {
|
|
366
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
367
|
-
if (!sourceFile) return 0;
|
|
368
|
-
let transformedCount = 0;
|
|
369
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
370
|
-
import_ts_morph2.SyntaxKind.CallExpression
|
|
371
|
-
);
|
|
372
|
-
for (const call of callExpressions) {
|
|
373
|
-
const expression = call.getExpression();
|
|
374
|
-
if (!import_ts_morph2.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME2) {
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
const args2 = call.getArguments();
|
|
378
|
-
if (args2.length === 0) continue;
|
|
379
|
-
const configArg = args2[0];
|
|
380
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(configArg)) continue;
|
|
381
|
-
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME2);
|
|
382
|
-
if (!actionsProperty || !import_ts_morph2.Node.isPropertyAssignment(actionsProperty))
|
|
383
|
-
continue;
|
|
384
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
385
|
-
if (!actionsInitializer || !import_ts_morph2.Node.isArrayLiteralExpression(actionsInitializer))
|
|
386
|
-
continue;
|
|
387
|
-
const eventType = resolveEventType(configArg);
|
|
388
|
-
if (!eventType) {
|
|
389
|
-
console.warn(
|
|
390
|
-
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
let fileNeedsImports = false;
|
|
394
|
-
let configHadValidateAction = false;
|
|
395
|
-
for (const element of actionsInitializer.getElements()) {
|
|
396
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
397
|
-
const wasTransformed = transformValidateActionToCustom(
|
|
398
|
-
element,
|
|
399
|
-
eventType ?? "unknown"
|
|
400
|
-
);
|
|
401
|
-
if (wasTransformed) {
|
|
402
|
-
transformedCount++;
|
|
403
|
-
fileNeedsImports = true;
|
|
404
|
-
configHadValidateAction = true;
|
|
405
|
-
console.log(
|
|
406
|
-
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (configHadValidateAction && !configArg.getProperty("flags")) {
|
|
411
|
-
const resolvedEventType = eventType ?? "unknown";
|
|
412
|
-
configArg.addPropertyAssignment({
|
|
413
|
-
name: "flags",
|
|
414
|
-
initializer: `[
|
|
415
|
-
{
|
|
416
|
-
id: 'validated',
|
|
417
|
-
label: {
|
|
418
|
-
id: 'event.${resolvedEventType}.flag.validated',
|
|
419
|
-
defaultMessage: 'Validated',
|
|
420
|
-
description: 'Flag label for validated'
|
|
421
|
-
},
|
|
422
|
-
requiresAction: true
|
|
423
|
-
}
|
|
424
|
-
]`
|
|
425
|
-
});
|
|
426
|
-
console.log(
|
|
427
|
-
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
if (configHadValidateAction) {
|
|
431
|
-
for (const element of actionsInitializer.getElements()) {
|
|
432
|
-
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
433
|
-
if (!isRegisterAction(element)) continue;
|
|
434
|
-
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
435
|
-
transformedCount++;
|
|
436
|
-
console.log(
|
|
437
|
-
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
if (fileNeedsImports) {
|
|
443
|
-
ensureImports(sourceFile);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return transformedCount;
|
|
447
|
-
}
|
|
448
|
-
async function main2() {
|
|
449
|
-
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
450
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
451
|
-
`);
|
|
452
|
-
const project = new import_ts_morph2.Project({
|
|
453
|
-
tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
|
|
454
|
-
// Do not emit — we only manipulate source files
|
|
455
|
-
skipAddingFilesFromTsConfig: false
|
|
456
|
-
});
|
|
457
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
458
|
-
const fp = sf.getFilePath();
|
|
459
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
460
|
-
});
|
|
461
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
462
|
-
`);
|
|
463
|
-
let totalTransformed = 0;
|
|
464
|
-
const modifiedFiles = [];
|
|
465
|
-
for (const sourceFile of sourceFiles) {
|
|
466
|
-
const filePath = sourceFile.getFilePath();
|
|
467
|
-
const transformed = processFile2(filePath, project);
|
|
468
|
-
if (transformed > 0) {
|
|
469
|
-
totalTransformed += transformed;
|
|
470
|
-
modifiedFiles.push(filePath);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if (modifiedFiles.length === 0) {
|
|
474
|
-
console.log(
|
|
475
|
-
"No VALIDATE actions found inside defineConfig calls. Nothing to do."
|
|
476
|
-
);
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
console.log(`
|
|
480
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
481
|
-
for (const filePath of modifiedFiles) {
|
|
482
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
483
|
-
await sourceFile.save();
|
|
484
|
-
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
485
|
-
}
|
|
486
|
-
console.log(
|
|
487
|
-
`
|
|
488
|
-
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
489
|
-
);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// src/migrations/v2.0/remove-delete-actions.ts
|
|
493
|
-
var import_ts_morph3 = require("ts-morph");
|
|
494
|
-
var import_path3 = __toESM(require("path"));
|
|
495
|
-
var DEFINE_CONFIG_NAME3 = "defineConfig";
|
|
496
|
-
var ACTIONS_PROPERTY_NAME3 = "actions";
|
|
497
|
-
var TYPE_PROPERTY_NAME3 = "type";
|
|
498
|
-
var ACTION_TYPE_ENUM_NAME2 = "ActionType";
|
|
499
|
-
var DELETE_MEMBER_NAME = "DELETE";
|
|
500
|
-
var DELETE_STRING_LITERAL = "DELETE";
|
|
501
|
-
function isDeleteType(typeInitializer) {
|
|
502
|
-
if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.PropertyAccessExpression) {
|
|
503
|
-
const propAccess = typeInitializer.asKindOrThrow(
|
|
504
|
-
import_ts_morph3.SyntaxKind.PropertyAccessExpression
|
|
505
|
-
);
|
|
506
|
-
const obj = propAccess.getExpression();
|
|
507
|
-
const member = propAccess.getName();
|
|
508
|
-
return import_ts_morph3.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME2 && member === DELETE_MEMBER_NAME;
|
|
509
|
-
}
|
|
510
|
-
if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.StringLiteral) {
|
|
511
|
-
return typeInitializer.asKindOrThrow(import_ts_morph3.SyntaxKind.StringLiteral).getLiteralValue() === DELETE_STRING_LITERAL;
|
|
512
|
-
}
|
|
513
|
-
return false;
|
|
514
|
-
}
|
|
515
|
-
function isDeleteAction(obj) {
|
|
516
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME3);
|
|
517
|
-
if (!typeProperty || !import_ts_morph3.Node.isPropertyAssignment(typeProperty)) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
521
|
-
return !!typeInitializer && isDeleteType(typeInitializer);
|
|
522
|
-
}
|
|
523
|
-
function processFile3(filePath, project) {
|
|
524
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
525
|
-
if (!sourceFile) return 0;
|
|
526
|
-
let removedCount = 0;
|
|
527
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
528
|
-
import_ts_morph3.SyntaxKind.CallExpression
|
|
529
|
-
);
|
|
530
|
-
for (const call of callExpressions) {
|
|
531
|
-
const expression = call.getExpression();
|
|
532
|
-
if (!import_ts_morph3.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME3) {
|
|
533
|
-
continue;
|
|
534
|
-
}
|
|
535
|
-
const args2 = call.getArguments();
|
|
536
|
-
if (args2.length === 0) continue;
|
|
537
|
-
const configArg = args2[0];
|
|
538
|
-
if (!import_ts_morph3.Node.isObjectLiteralExpression(configArg)) continue;
|
|
539
|
-
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME3);
|
|
540
|
-
if (!actionsProperty || !import_ts_morph3.Node.isPropertyAssignment(actionsProperty))
|
|
541
|
-
continue;
|
|
542
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
543
|
-
if (!actionsInitializer || !import_ts_morph3.Node.isArrayLiteralExpression(actionsInitializer))
|
|
544
|
-
continue;
|
|
545
|
-
const indicesToRemove = [];
|
|
546
|
-
actionsInitializer.getElements().forEach((element, index) => {
|
|
547
|
-
if (import_ts_morph3.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
|
|
548
|
-
indicesToRemove.push(index);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
for (const index of indicesToRemove.reverse()) {
|
|
552
|
-
actionsInitializer.removeElement(index);
|
|
553
|
-
removedCount++;
|
|
554
|
-
console.log(
|
|
555
|
-
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
return removedCount;
|
|
560
|
-
}
|
|
561
|
-
async function main3() {
|
|
562
|
-
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
563
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
564
|
-
`);
|
|
565
|
-
const project = new import_ts_morph3.Project({
|
|
566
|
-
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
567
|
-
// Do not emit — we only manipulate source files
|
|
568
|
-
skipAddingFilesFromTsConfig: false
|
|
569
|
-
});
|
|
570
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
571
|
-
const fp = sf.getFilePath();
|
|
572
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
573
|
-
});
|
|
574
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
575
|
-
`);
|
|
576
|
-
let totalRemoved = 0;
|
|
577
|
-
const modifiedFiles = [];
|
|
578
|
-
for (const sourceFile of sourceFiles) {
|
|
579
|
-
const filePath = sourceFile.getFilePath();
|
|
580
|
-
const removed = processFile3(filePath, project);
|
|
581
|
-
if (removed > 0) {
|
|
582
|
-
totalRemoved += removed;
|
|
583
|
-
modifiedFiles.push(filePath);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (modifiedFiles.length === 0) {
|
|
587
|
-
console.log(
|
|
588
|
-
"No DELETE actions found inside defineConfig calls. Nothing to do."
|
|
589
|
-
);
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
console.log(`
|
|
593
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
594
|
-
for (const filePath of modifiedFiles) {
|
|
595
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
596
|
-
await sourceFile.save();
|
|
597
|
-
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
598
|
-
}
|
|
599
|
-
console.log(
|
|
600
|
-
`
|
|
601
|
-
Done. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/migrations/v2.0/convert-paragraph-to-heading.ts
|
|
606
|
-
var import_ts_morph4 = require("ts-morph");
|
|
607
|
-
var import_path4 = __toESM(require("path"));
|
|
608
|
-
var FIELD_TYPE_ENUM_NAME = "FieldType";
|
|
609
|
-
var PARAGRAPH_MEMBER_NAME = "PARAGRAPH";
|
|
610
|
-
var HEADING_MEMBER_NAME = "HEADING";
|
|
611
|
-
var TYPE_PROPERTY_NAME4 = "type";
|
|
612
|
-
var CONFIGURATION_PROPERTY_NAME = "configuration";
|
|
613
|
-
var STYLES_PROPERTY_NAME = "styles";
|
|
614
|
-
var FONT_VARIANT_PROPERTY_NAME = "fontVariant";
|
|
615
|
-
var HEADING_FONT_VARIANTS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4"]);
|
|
616
|
-
function isParagraphType(typeInitializer) {
|
|
617
|
-
if (!import_ts_morph4.Node.isPropertyAccessExpression(typeInitializer)) return false;
|
|
618
|
-
const obj = typeInitializer.getExpression();
|
|
619
|
-
const member = typeInitializer.getName();
|
|
620
|
-
return import_ts_morph4.Node.isIdentifier(obj) && obj.getText() === FIELD_TYPE_ENUM_NAME && member === PARAGRAPH_MEMBER_NAME;
|
|
621
|
-
}
|
|
622
|
-
function getFontVariantProperty(obj) {
|
|
623
|
-
const configProperty = obj.getProperty(CONFIGURATION_PROPERTY_NAME);
|
|
624
|
-
if (!configProperty || !import_ts_morph4.Node.isPropertyAssignment(configProperty)) return null;
|
|
625
|
-
const configInitializer = configProperty.getInitializer();
|
|
626
|
-
if (!configInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(configInitializer))
|
|
627
|
-
return null;
|
|
628
|
-
const stylesProperty = configInitializer.getProperty(STYLES_PROPERTY_NAME);
|
|
629
|
-
if (!stylesProperty || !import_ts_morph4.Node.isPropertyAssignment(stylesProperty)) return null;
|
|
630
|
-
const stylesInitializer = stylesProperty.getInitializer();
|
|
631
|
-
if (!stylesInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(stylesInitializer))
|
|
632
|
-
return null;
|
|
633
|
-
const fontVariantProperty = stylesInitializer.getProperty(
|
|
634
|
-
FONT_VARIANT_PROPERTY_NAME
|
|
635
|
-
);
|
|
636
|
-
if (!fontVariantProperty || !import_ts_morph4.Node.isPropertyAssignment(fontVariantProperty))
|
|
637
|
-
return null;
|
|
638
|
-
return fontVariantProperty;
|
|
639
|
-
}
|
|
640
|
-
function transformParagraphField(obj) {
|
|
641
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME4);
|
|
642
|
-
if (!typeProperty || !import_ts_morph4.Node.isPropertyAssignment(typeProperty)) return null;
|
|
643
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
644
|
-
if (!typeInitializer || !isParagraphType(typeInitializer)) return null;
|
|
645
|
-
const fontVariantProperty = getFontVariantProperty(obj);
|
|
646
|
-
if (fontVariantProperty) {
|
|
647
|
-
const fontVariantInitializer = fontVariantProperty.getInitializer();
|
|
648
|
-
if (fontVariantInitializer && import_ts_morph4.Node.isStringLiteral(fontVariantInitializer) && HEADING_FONT_VARIANTS.has(fontVariantInitializer.getLiteralValue())) {
|
|
649
|
-
typeInitializer.replaceWithText(
|
|
650
|
-
`${FIELD_TYPE_ENUM_NAME}.${HEADING_MEMBER_NAME}`
|
|
651
|
-
);
|
|
652
|
-
return "converted-to-heading";
|
|
653
|
-
}
|
|
654
|
-
fontVariantProperty.remove();
|
|
655
|
-
return "removed-font-variant";
|
|
656
|
-
}
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
function processFile4(filePath, project) {
|
|
660
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
661
|
-
if (!sourceFile) return 0;
|
|
662
|
-
let changedCount = 0;
|
|
663
|
-
const objectLiterals = sourceFile.getDescendantsOfKind(
|
|
664
|
-
import_ts_morph4.SyntaxKind.ObjectLiteralExpression
|
|
199
|
+
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
665
200
|
);
|
|
666
|
-
for (const obj of objectLiterals) {
|
|
667
|
-
const result = transformParagraphField(obj);
|
|
668
|
-
if (result === "converted-to-heading") {
|
|
669
|
-
changedCount++;
|
|
670
|
-
console.log(
|
|
671
|
-
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
672
|
-
);
|
|
673
|
-
} else if (result === "removed-font-variant") {
|
|
674
|
-
changedCount++;
|
|
675
|
-
console.log(
|
|
676
|
-
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return changedCount;
|
|
681
|
-
}
|
|
682
|
-
async function main4() {
|
|
683
|
-
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
684
|
-
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
685
|
-
`);
|
|
686
|
-
const project = new import_ts_morph4.Project({
|
|
687
|
-
tsConfigFilePath: import_path4.default.resolve(srcDir, "../tsconfig.json"),
|
|
688
|
-
skipAddingFilesFromTsConfig: false
|
|
689
|
-
});
|
|
690
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
691
|
-
const fp = sf.getFilePath();
|
|
692
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
693
|
-
});
|
|
694
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
695
|
-
`);
|
|
696
|
-
let totalChanged = 0;
|
|
697
|
-
const modifiedFiles = [];
|
|
698
|
-
for (const sourceFile of sourceFiles) {
|
|
699
|
-
const filePath = sourceFile.getFilePath();
|
|
700
|
-
const changed = processFile4(filePath, project);
|
|
701
|
-
if (changed > 0) {
|
|
702
|
-
totalChanged += changed;
|
|
703
|
-
modifiedFiles.push(filePath);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
if (modifiedFiles.length === 0) {
|
|
707
|
-
console.log(
|
|
708
|
-
"No FieldType.PARAGRAPH fields with fontVariant found. Nothing to do."
|
|
709
|
-
);
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
console.log(`
|
|
713
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
714
|
-
for (const filePath of modifiedFiles) {
|
|
715
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
716
|
-
await sourceFile.save();
|
|
717
|
-
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
718
|
-
}
|
|
719
|
-
console.log(`
|
|
720
|
-
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
721
201
|
}
|
|
722
202
|
|
|
723
|
-
// src/migrations/v2.
|
|
724
|
-
var import_ts_morph5 = require("ts-morph");
|
|
725
|
-
var import_path5 = __toESM(require("path"));
|
|
726
|
-
var DEFINE_WORKQUEUES_NAME = "defineWorkqueues";
|
|
727
|
-
var QUERY_PROPERTY_NAME = "query";
|
|
728
|
-
var TYPE_PROPERTY_NAME5 = "type";
|
|
729
|
-
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
730
|
-
var STATUS_PROPERTY_NAME = "status";
|
|
731
|
-
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
732
|
-
var TERMS_PROPERTY_NAME = "terms";
|
|
733
|
-
var TERM_PROPERTY_NAME = "term";
|
|
734
|
-
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
735
|
-
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
736
|
-
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
737
|
-
function addValidatedFlag(clause) {
|
|
738
|
-
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
739
|
-
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
740
|
-
const flagsInit = flagsProperty.getInitializer();
|
|
741
|
-
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
742
|
-
const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
|
|
743
|
-
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
744
|
-
const anyOfInit = anyOfProperty.getInitializer();
|
|
745
|
-
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
746
|
-
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
747
|
-
}
|
|
748
|
-
} else {
|
|
749
|
-
flagsInit.addPropertyAssignment({
|
|
750
|
-
name: ANY_OF_PROPERTY_NAME,
|
|
751
|
-
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
} else {
|
|
756
|
-
clause.addPropertyAssignment({
|
|
757
|
-
name: FLAGS_PROPERTY_NAME2,
|
|
758
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
function migrateClause(clause) {
|
|
763
|
-
const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
|
|
764
|
-
if (!statusProperty || !import_ts_morph5.Node.isPropertyAssignment(statusProperty)) {
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
const statusInit = statusProperty.getInitializer();
|
|
768
|
-
if (!statusInit || !import_ts_morph5.Node.isObjectLiteralExpression(statusInit)) {
|
|
769
|
-
return false;
|
|
770
|
-
}
|
|
771
|
-
const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME5);
|
|
772
|
-
if (!statusTypeProperty || !import_ts_morph5.Node.isPropertyAssignment(statusTypeProperty)) {
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
const statusTypeInit = statusTypeProperty.getInitializer();
|
|
776
|
-
if (!statusTypeInit || !import_ts_morph5.Node.isStringLiteral(statusTypeInit)) {
|
|
777
|
-
return false;
|
|
778
|
-
}
|
|
779
|
-
const statusType = statusTypeInit.getLiteralValue();
|
|
780
|
-
if (statusType === "anyOf") {
|
|
781
|
-
const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
|
|
782
|
-
if (!termsProperty || !import_ts_morph5.Node.isPropertyAssignment(termsProperty)) {
|
|
783
|
-
return false;
|
|
784
|
-
}
|
|
785
|
-
const termsInit = termsProperty.getInitializer();
|
|
786
|
-
if (!termsInit || !import_ts_morph5.Node.isArrayLiteralExpression(termsInit)) {
|
|
787
|
-
return false;
|
|
788
|
-
}
|
|
789
|
-
const elements = termsInit.getElements();
|
|
790
|
-
const validatedIndex = elements.findIndex(
|
|
791
|
-
(el) => import_ts_morph5.Node.isStringLiteral(el) && el.getLiteralValue() === VALIDATED_STATUS_VALUE
|
|
792
|
-
);
|
|
793
|
-
if (validatedIndex === -1) return false;
|
|
794
|
-
termsInit.removeElement(validatedIndex);
|
|
795
|
-
if (termsInit.getElements().length === 0) {
|
|
796
|
-
statusProperty.remove();
|
|
797
|
-
}
|
|
798
|
-
addValidatedFlag(clause);
|
|
799
|
-
return true;
|
|
800
|
-
}
|
|
801
|
-
if (statusType === "exact") {
|
|
802
|
-
const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
|
|
803
|
-
if (!termProperty || !import_ts_morph5.Node.isPropertyAssignment(termProperty)) {
|
|
804
|
-
return false;
|
|
805
|
-
}
|
|
806
|
-
const termInit = termProperty.getInitializer();
|
|
807
|
-
if (!termInit || !import_ts_morph5.Node.isStringLiteral(termInit)) {
|
|
808
|
-
return false;
|
|
809
|
-
}
|
|
810
|
-
if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE) return false;
|
|
811
|
-
statusProperty.remove();
|
|
812
|
-
addValidatedFlag(clause);
|
|
813
|
-
return true;
|
|
814
|
-
}
|
|
815
|
-
return false;
|
|
816
|
-
}
|
|
817
|
-
function walkQuery(queryObj) {
|
|
818
|
-
const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME5);
|
|
819
|
-
if (typeProperty && import_ts_morph5.Node.isPropertyAssignment(typeProperty)) {
|
|
820
|
-
const typeInit = typeProperty.getInitializer();
|
|
821
|
-
if (typeInit && import_ts_morph5.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
|
|
822
|
-
const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
|
|
823
|
-
if (!clausesProperty || !import_ts_morph5.Node.isPropertyAssignment(clausesProperty)) {
|
|
824
|
-
return 0;
|
|
825
|
-
}
|
|
826
|
-
const clausesInit = clausesProperty.getInitializer();
|
|
827
|
-
if (!clausesInit || !import_ts_morph5.Node.isArrayLiteralExpression(clausesInit)) {
|
|
828
|
-
return 0;
|
|
829
|
-
}
|
|
830
|
-
let changed = 0;
|
|
831
|
-
for (const clause of clausesInit.getElements()) {
|
|
832
|
-
if (import_ts_morph5.Node.isObjectLiteralExpression(clause)) {
|
|
833
|
-
changed += walkQuery(clause);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
return changed;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
return migrateClause(queryObj) ? 1 : 0;
|
|
840
|
-
}
|
|
841
|
-
function processFile5(filePath, project) {
|
|
842
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
843
|
-
if (!sourceFile) return 0;
|
|
844
|
-
let migratedCount = 0;
|
|
845
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
846
|
-
import_ts_morph5.SyntaxKind.CallExpression
|
|
847
|
-
);
|
|
848
|
-
for (const call of callExpressions) {
|
|
849
|
-
const expression = call.getExpression();
|
|
850
|
-
if (!import_ts_morph5.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME) {
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
const args2 = call.getArguments();
|
|
854
|
-
if (args2.length === 0) continue;
|
|
855
|
-
const workqueuesArg = args2[0];
|
|
856
|
-
if (!import_ts_morph5.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
857
|
-
for (const workqueueElement of workqueuesArg.getElements()) {
|
|
858
|
-
if (!import_ts_morph5.Node.isObjectLiteralExpression(workqueueElement)) continue;
|
|
859
|
-
const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
|
|
860
|
-
if (!queryProperty || !import_ts_morph5.Node.isPropertyAssignment(queryProperty)) continue;
|
|
861
|
-
const queryInit = queryProperty.getInitializer();
|
|
862
|
-
if (!queryInit || !import_ts_morph5.Node.isObjectLiteralExpression(queryInit)) continue;
|
|
863
|
-
const changed = walkQuery(queryInit);
|
|
864
|
-
if (changed > 0) {
|
|
865
|
-
migratedCount += changed;
|
|
866
|
-
console.log(
|
|
867
|
-
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return migratedCount;
|
|
873
|
-
}
|
|
874
|
-
async function main5() {
|
|
875
|
-
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
876
|
-
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
877
|
-
`);
|
|
878
|
-
const project = new import_ts_morph5.Project({
|
|
879
|
-
tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
|
|
880
|
-
skipAddingFilesFromTsConfig: false
|
|
881
|
-
});
|
|
882
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
883
|
-
const fp = sf.getFilePath();
|
|
884
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
885
|
-
});
|
|
886
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
887
|
-
`);
|
|
888
|
-
let totalMigrated = 0;
|
|
889
|
-
const modifiedFiles = [];
|
|
890
|
-
for (const sourceFile of sourceFiles) {
|
|
891
|
-
const filePath = sourceFile.getFilePath();
|
|
892
|
-
const migrated = processFile5(filePath, project);
|
|
893
|
-
if (migrated > 0) {
|
|
894
|
-
totalMigrated += migrated;
|
|
895
|
-
modifiedFiles.push(filePath);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
if (modifiedFiles.length === 0) {
|
|
899
|
-
console.log(
|
|
900
|
-
"No VALIDATED status references found in defineWorkqueues calls. Nothing to do."
|
|
901
|
-
);
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
console.log(`
|
|
905
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
906
|
-
for (const filePath of modifiedFiles) {
|
|
907
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
908
|
-
await sourceFile.save();
|
|
909
|
-
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
910
|
-
}
|
|
911
|
-
console.log(
|
|
912
|
-
`
|
|
913
|
-
Done. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`
|
|
914
|
-
);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
// src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
|
|
918
|
-
var import_ts_morph6 = require("ts-morph");
|
|
919
|
-
var import_path6 = __toESM(require("path"));
|
|
920
|
-
var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
921
|
-
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
922
|
-
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
923
|
-
var ACTION_PROPERTY_NAME = "action";
|
|
924
|
-
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
925
|
-
var QUERY_PROPERTY_NAME2 = "query";
|
|
926
|
-
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
-
var ID_PROPERTY_NAME2 = "id";
|
|
928
|
-
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
929
|
-
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
930
|
-
var FLAG_ID = "pending-first-certificate-issuance";
|
|
931
|
-
var REGISTER_TYPE = "REGISTER";
|
|
932
|
-
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
933
|
-
function flagDefinitionInitializer(eventType) {
|
|
934
|
-
return `{
|
|
935
|
-
id: '${FLAG_ID}',
|
|
936
|
-
label: {
|
|
937
|
-
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
938
|
-
defaultMessage: 'Pending first certificate issuance',
|
|
939
|
-
description: 'Flag label for first certificate issuance'
|
|
940
|
-
},
|
|
941
|
-
requiresAction: true
|
|
942
|
-
}`;
|
|
943
|
-
}
|
|
944
|
-
function isActionOfType(obj, typeName) {
|
|
945
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
946
|
-
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
947
|
-
const typeInit = typeProperty.getInitializer();
|
|
948
|
-
if (!typeInit) return false;
|
|
949
|
-
if (import_ts_morph6.Node.isPropertyAccessExpression(typeInit)) {
|
|
950
|
-
return typeInit.getName() === typeName;
|
|
951
|
-
}
|
|
952
|
-
if (import_ts_morph6.Node.isStringLiteral(typeInit)) {
|
|
953
|
-
return typeInit.getLiteralValue() === typeName;
|
|
954
|
-
}
|
|
955
|
-
return false;
|
|
956
|
-
}
|
|
957
|
-
function getEventType(configArg) {
|
|
958
|
-
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
959
|
-
const prop = configArg.getProperty(propName);
|
|
960
|
-
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
961
|
-
const initializer = prop.getInitializer();
|
|
962
|
-
if (!initializer) continue;
|
|
963
|
-
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
964
|
-
return initializer.getLiteralValue().toLowerCase();
|
|
965
|
-
}
|
|
966
|
-
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
967
|
-
return initializer.getName().toLowerCase();
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
return null;
|
|
971
|
-
}
|
|
972
|
-
function hasElementWithId(array3, id) {
|
|
973
|
-
for (const el of array3.getElements()) {
|
|
974
|
-
if (!import_ts_morph6.Node.isObjectLiteralExpression(el)) continue;
|
|
975
|
-
const idProp = el.getProperty("id");
|
|
976
|
-
if (!idProp || !import_ts_morph6.Node.isPropertyAssignment(idProp)) continue;
|
|
977
|
-
const idInit = idProp.getInitializer();
|
|
978
|
-
if (idInit && import_ts_morph6.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
979
|
-
return true;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
return false;
|
|
983
|
-
}
|
|
984
|
-
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
985
|
-
const initializer = flagDefinitionInitializer(eventType);
|
|
986
|
-
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
987
|
-
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
988
|
-
const flagsInit = flagsProp.getInitializer();
|
|
989
|
-
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
990
|
-
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
991
|
-
flagsInit.addElement(initializer);
|
|
992
|
-
return true;
|
|
993
|
-
}
|
|
994
|
-
return false;
|
|
995
|
-
}
|
|
996
|
-
configArg.addPropertyAssignment({
|
|
997
|
-
name: FLAGS_PROPERTY_NAME3,
|
|
998
|
-
initializer: `[
|
|
999
|
-
${initializer}
|
|
1000
|
-
]`
|
|
1001
|
-
});
|
|
1002
|
-
return true;
|
|
1003
|
-
}
|
|
1004
|
-
function ensureActionOperationFlag(action, operation) {
|
|
1005
|
-
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1006
|
-
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
1007
|
-
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1008
|
-
const flagsInit = flagsProp.getInitializer();
|
|
1009
|
-
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
1010
|
-
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
1011
|
-
flagsInit.addElement(entry);
|
|
1012
|
-
return true;
|
|
1013
|
-
}
|
|
1014
|
-
return false;
|
|
1015
|
-
}
|
|
1016
|
-
action.addPropertyAssignment({
|
|
1017
|
-
name: FLAGS_PROPERTY_NAME3,
|
|
1018
|
-
initializer: `[${entry}]`
|
|
1019
|
-
});
|
|
1020
|
-
return true;
|
|
1021
|
-
}
|
|
1022
|
-
function processConfig(configArg, eventType, relPath) {
|
|
1023
|
-
let changes = 0;
|
|
1024
|
-
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
1025
|
-
changes++;
|
|
1026
|
-
console.log(
|
|
1027
|
-
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
1031
|
-
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
1032
|
-
const actionsInit = actionsProp.getInitializer();
|
|
1033
|
-
if (!actionsInit || !import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
|
|
1034
|
-
return changes;
|
|
1035
|
-
}
|
|
1036
|
-
for (const element of actionsInit.getElements()) {
|
|
1037
|
-
if (!import_ts_morph6.Node.isObjectLiteralExpression(element)) continue;
|
|
1038
|
-
if (isActionOfType(element, REGISTER_TYPE)) {
|
|
1039
|
-
if (ensureActionOperationFlag(element, "add")) {
|
|
1040
|
-
changes++;
|
|
1041
|
-
console.log(
|
|
1042
|
-
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
|
|
1047
|
-
if (ensureActionOperationFlag(element, "remove")) {
|
|
1048
|
-
changes++;
|
|
1049
|
-
console.log(
|
|
1050
|
-
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
return changes;
|
|
1056
|
-
}
|
|
1057
|
-
function hasPrintCertificateAction(workqueue) {
|
|
1058
|
-
const actionsProp = workqueue.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
1059
|
-
if (actionsProp && import_ts_morph6.Node.isPropertyAssignment(actionsProp)) {
|
|
1060
|
-
const actionsInit = actionsProp.getInitializer();
|
|
1061
|
-
if (actionsInit && import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
|
|
1062
|
-
for (const el of actionsInit.getElements()) {
|
|
1063
|
-
if (import_ts_morph6.Node.isObjectLiteralExpression(el) && isActionOfType(el, PRINT_CERTIFICATE_TYPE)) {
|
|
1064
|
-
return true;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
const actionProp = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
1070
|
-
if (actionProp && import_ts_morph6.Node.isPropertyAssignment(actionProp)) {
|
|
1071
|
-
const actionInit = actionProp.getInitializer();
|
|
1072
|
-
if (actionInit && import_ts_morph6.Node.isObjectLiteralExpression(actionInit) && isActionOfType(actionInit, PRINT_CERTIFICATE_TYPE)) {
|
|
1073
|
-
return true;
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return false;
|
|
1077
|
-
}
|
|
1078
|
-
function addFlagToQueryClause(clause) {
|
|
1079
|
-
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1080
|
-
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1081
|
-
const flagsInit = flagsProp.getInitializer();
|
|
1082
|
-
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
1083
|
-
const anyOfProp = flagsInit.getProperty(ANY_OF_PROPERTY_NAME2);
|
|
1084
|
-
if (anyOfProp && import_ts_morph6.Node.isPropertyAssignment(anyOfProp)) {
|
|
1085
|
-
const anyOfInit = anyOfProp.getInitializer();
|
|
1086
|
-
if (anyOfInit && import_ts_morph6.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
1087
|
-
const alreadyPresent = anyOfInit.getElements().some(
|
|
1088
|
-
(el) => import_ts_morph6.Node.isStringLiteral(el) && el.getLiteralValue() === FLAG_ID
|
|
1089
|
-
);
|
|
1090
|
-
if (alreadyPresent) return false;
|
|
1091
|
-
anyOfInit.addElement(`'${FLAG_ID}'`);
|
|
1092
|
-
return true;
|
|
1093
|
-
}
|
|
1094
|
-
} else {
|
|
1095
|
-
flagsInit.addPropertyAssignment({
|
|
1096
|
-
name: ANY_OF_PROPERTY_NAME2,
|
|
1097
|
-
initializer: `['${FLAG_ID}']`
|
|
1098
|
-
});
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
} else {
|
|
1103
|
-
clause.addPropertyAssignment({
|
|
1104
|
-
name: FLAGS_PROPERTY_NAME3,
|
|
1105
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1106
|
-
});
|
|
1107
|
-
return true;
|
|
1108
|
-
}
|
|
1109
|
-
return false;
|
|
1110
|
-
}
|
|
1111
|
-
function walkQueryForFlagAddition(queryObj) {
|
|
1112
|
-
const typeProp = queryObj.getProperty(TYPE_PROPERTY_NAME6);
|
|
1113
|
-
if (typeProp && import_ts_morph6.Node.isPropertyAssignment(typeProp)) {
|
|
1114
|
-
const typeInit = typeProp.getInitializer();
|
|
1115
|
-
if (typeInit && import_ts_morph6.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
|
|
1116
|
-
const clausesProp = queryObj.getProperty(CLAUSES_PROPERTY_NAME2);
|
|
1117
|
-
if (!clausesProp || !import_ts_morph6.Node.isPropertyAssignment(clausesProp)) return 0;
|
|
1118
|
-
const clausesInit = clausesProp.getInitializer();
|
|
1119
|
-
if (!clausesInit || !import_ts_morph6.Node.isArrayLiteralExpression(clausesInit)) return 0;
|
|
1120
|
-
let changed = 0;
|
|
1121
|
-
for (const clause of clausesInit.getElements()) {
|
|
1122
|
-
if (import_ts_morph6.Node.isObjectLiteralExpression(clause)) {
|
|
1123
|
-
changed += walkQueryForFlagAddition(clause);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
return changed;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
return addFlagToQueryClause(queryObj) ? 1 : 0;
|
|
1130
|
-
}
|
|
1131
|
-
function processFile6(filePath, project) {
|
|
1132
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
1133
|
-
if (!sourceFile) return 0;
|
|
1134
|
-
let totalChanges = 0;
|
|
1135
|
-
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1136
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1137
|
-
import_ts_morph6.SyntaxKind.CallExpression
|
|
1138
|
-
);
|
|
1139
|
-
for (const call of callExpressions) {
|
|
1140
|
-
const expression = call.getExpression();
|
|
1141
|
-
if (!import_ts_morph6.Node.isIdentifier(expression)) continue;
|
|
1142
|
-
const calleeName = expression.getText();
|
|
1143
|
-
if (calleeName === DEFINE_CONFIG_NAME4) {
|
|
1144
|
-
const args2 = call.getArguments();
|
|
1145
|
-
if (args2.length === 0) continue;
|
|
1146
|
-
const configArg = args2[0];
|
|
1147
|
-
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1148
|
-
const eventType = getEventType(configArg);
|
|
1149
|
-
if (!eventType) continue;
|
|
1150
|
-
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1151
|
-
}
|
|
1152
|
-
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1153
|
-
const args2 = call.getArguments();
|
|
1154
|
-
if (args2.length === 0) continue;
|
|
1155
|
-
const workqueuesArg = args2[0];
|
|
1156
|
-
if (!import_ts_morph6.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
1157
|
-
for (const workqueueEl of workqueuesArg.getElements()) {
|
|
1158
|
-
if (!import_ts_morph6.Node.isObjectLiteralExpression(workqueueEl)) continue;
|
|
1159
|
-
if (!hasPrintCertificateAction(workqueueEl)) continue;
|
|
1160
|
-
const queryProp = workqueueEl.getProperty(QUERY_PROPERTY_NAME2);
|
|
1161
|
-
if (!queryProp || !import_ts_morph6.Node.isPropertyAssignment(queryProp)) continue;
|
|
1162
|
-
const queryInit = queryProp.getInitializer();
|
|
1163
|
-
if (!queryInit || !import_ts_morph6.Node.isObjectLiteralExpression(queryInit)) continue;
|
|
1164
|
-
const changed = walkQueryForFlagAddition(queryInit);
|
|
1165
|
-
if (changed > 0) {
|
|
1166
|
-
totalChanges += changed;
|
|
1167
|
-
console.log(
|
|
1168
|
-
` [${relPath}] Added '${FLAG_ID}' to flags.anyOf in ${changed} PRINT_CERTIFICATE workqueue clause(s)`
|
|
1169
|
-
);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
return totalChanges;
|
|
1175
|
-
}
|
|
1176
|
-
async function main6() {
|
|
1177
|
-
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1178
|
-
console.log(
|
|
1179
|
-
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1180
|
-
`
|
|
1181
|
-
);
|
|
1182
|
-
const project = new import_ts_morph6.Project({
|
|
1183
|
-
tsConfigFilePath: import_path6.default.resolve(srcDir, "../tsconfig.json"),
|
|
1184
|
-
skipAddingFilesFromTsConfig: false
|
|
1185
|
-
});
|
|
1186
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1187
|
-
const fp = sf.getFilePath();
|
|
1188
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1189
|
-
});
|
|
1190
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1191
|
-
`);
|
|
1192
|
-
let totalChanges = 0;
|
|
1193
|
-
const modifiedFiles = [];
|
|
1194
|
-
for (const sourceFile of sourceFiles) {
|
|
1195
|
-
const filePath = sourceFile.getFilePath();
|
|
1196
|
-
const changes = processFile6(filePath, project);
|
|
1197
|
-
if (changes > 0) {
|
|
1198
|
-
totalChanges += changes;
|
|
1199
|
-
modifiedFiles.push(filePath);
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
if (modifiedFiles.length === 0) {
|
|
1203
|
-
console.log(
|
|
1204
|
-
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1205
|
-
);
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
console.log(`
|
|
1209
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1210
|
-
for (const filePath of modifiedFiles) {
|
|
1211
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1212
|
-
await sourceFile.save();
|
|
1213
|
-
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1214
|
-
}
|
|
1215
|
-
console.log(
|
|
1216
|
-
`
|
|
1217
|
-
Done. Applied ${totalChanges} change(s) across ${modifiedFiles.length} file(s).`
|
|
1218
|
-
);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
// src/migrations/v2.0/remove-pending-certification-flag.ts
|
|
1222
|
-
var import_ts_morph7 = require("ts-morph");
|
|
1223
|
-
var import_path7 = __toESM(require("path"));
|
|
1224
|
-
var INHERENT_FLAGS_ENUM_NAME = "InherentFlags";
|
|
1225
|
-
var PENDING_CERTIFICATION_MEMBER = "PENDING_CERTIFICATION";
|
|
1226
|
-
function isPendingCertificationFlag(node) {
|
|
1227
|
-
if (!import_ts_morph7.Node.isPropertyAccessExpression(node)) return false;
|
|
1228
|
-
const obj = node.getExpression();
|
|
1229
|
-
const member = node.getName();
|
|
1230
|
-
return import_ts_morph7.Node.isIdentifier(obj) && obj.getText() === INHERENT_FLAGS_ENUM_NAME && member === PENDING_CERTIFICATION_MEMBER;
|
|
1231
|
-
}
|
|
1232
|
-
function processFile7(filePath, project) {
|
|
1233
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
1234
|
-
if (!sourceFile) return 0;
|
|
1235
|
-
let removedCount = 0;
|
|
1236
|
-
const arrayLiterals = sourceFile.getDescendantsOfKind(
|
|
1237
|
-
import_ts_morph7.SyntaxKind.ArrayLiteralExpression
|
|
1238
|
-
);
|
|
1239
|
-
for (const array3 of arrayLiterals) {
|
|
1240
|
-
const indicesToRemove = [];
|
|
1241
|
-
array3.getElements().forEach((element, index) => {
|
|
1242
|
-
if (isPendingCertificationFlag(element)) {
|
|
1243
|
-
indicesToRemove.push(index);
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
for (const index of indicesToRemove.reverse()) {
|
|
1247
|
-
array3.removeElement(index);
|
|
1248
|
-
removedCount++;
|
|
1249
|
-
console.log(
|
|
1250
|
-
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
return removedCount;
|
|
1255
|
-
}
|
|
1256
|
-
async function main7() {
|
|
1257
|
-
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1258
|
-
console.log(
|
|
1259
|
-
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1260
|
-
`
|
|
1261
|
-
);
|
|
1262
|
-
const project = new import_ts_morph7.Project({
|
|
1263
|
-
tsConfigFilePath: import_path7.default.resolve(srcDir, "../tsconfig.json"),
|
|
1264
|
-
skipAddingFilesFromTsConfig: false
|
|
1265
|
-
});
|
|
1266
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1267
|
-
const fp = sf.getFilePath();
|
|
1268
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1269
|
-
});
|
|
1270
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1271
|
-
`);
|
|
1272
|
-
let totalRemoved = 0;
|
|
1273
|
-
const modifiedFiles = [];
|
|
1274
|
-
for (const sourceFile of sourceFiles) {
|
|
1275
|
-
const filePath = sourceFile.getFilePath();
|
|
1276
|
-
const removed = processFile7(filePath, project);
|
|
1277
|
-
if (removed > 0) {
|
|
1278
|
-
totalRemoved += removed;
|
|
1279
|
-
modifiedFiles.push(filePath);
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
if (modifiedFiles.length === 0) {
|
|
1283
|
-
console.log(
|
|
1284
|
-
"No InherentFlags.PENDING_CERTIFICATION elements found in any array. Nothing to do."
|
|
1285
|
-
);
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
console.log(`
|
|
1289
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1290
|
-
for (const filePath of modifiedFiles) {
|
|
1291
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1292
|
-
await sourceFile.save();
|
|
1293
|
-
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1294
|
-
}
|
|
1295
|
-
console.log(
|
|
1296
|
-
`
|
|
1297
|
-
Done. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`
|
|
1298
|
-
);
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
// src/migrations/v2.0/rename-location-parent-id.ts
|
|
1302
|
-
var import_ts_morph8 = require("ts-morph");
|
|
1303
|
-
var import_path8 = __toESM(require("path"));
|
|
1304
|
-
var OLD_PROPERTY_NAME = "parentId";
|
|
1305
|
-
var NEW_PROPERTY_NAME = "administrativeAreaId";
|
|
1306
|
-
var LOCATION_TYPE_NAME = "Location";
|
|
1307
|
-
var LOCATION_STRUCTURAL_PROPS = [
|
|
1308
|
-
"id",
|
|
1309
|
-
"name",
|
|
1310
|
-
"externalId",
|
|
1311
|
-
"locationType"
|
|
1312
|
-
];
|
|
1313
|
-
var LOCATION_AREA_ID_PROPS = ["administrativeAreaId", "parentId"];
|
|
1314
|
-
function isSingleLocationType(t) {
|
|
1315
|
-
if (t.getAliasSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
|
|
1316
|
-
if (t.getSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
|
|
1317
|
-
if (t.isObject()) {
|
|
1318
|
-
const propNames = new Set(t.getProperties().map((p) => p.getName()));
|
|
1319
|
-
const hasCorePropNames = LOCATION_STRUCTURAL_PROPS.every(
|
|
1320
|
-
(p) => propNames.has(p)
|
|
1321
|
-
);
|
|
1322
|
-
const hasAreaIdProp = LOCATION_AREA_ID_PROPS.some((p) => propNames.has(p));
|
|
1323
|
-
if (hasCorePropNames && hasAreaIdProp) return true;
|
|
1324
|
-
}
|
|
1325
|
-
return false;
|
|
1326
|
-
}
|
|
1327
|
-
function isLocationType(node) {
|
|
1328
|
-
let type;
|
|
1329
|
-
try {
|
|
1330
|
-
type = node.getType();
|
|
1331
|
-
} catch {
|
|
1332
|
-
return false;
|
|
1333
|
-
}
|
|
1334
|
-
if (isSingleLocationType(type)) return true;
|
|
1335
|
-
for (const constituent of type.getUnionTypes()) {
|
|
1336
|
-
if (isSingleLocationType(constituent)) return true;
|
|
1337
|
-
}
|
|
1338
|
-
return false;
|
|
1339
|
-
}
|
|
1340
|
-
function processFile8(filePath, project) {
|
|
1341
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
1342
|
-
if (!sourceFile) return 0;
|
|
1343
|
-
let renamedCount = 0;
|
|
1344
|
-
const candidates = sourceFile.getDescendantsOfKind(import_ts_morph8.SyntaxKind.PropertyAccessExpression).filter((propAccess) => propAccess.getName() === OLD_PROPERTY_NAME);
|
|
1345
|
-
for (const propAccess of candidates) {
|
|
1346
|
-
const obj = propAccess.getExpression();
|
|
1347
|
-
if (!isLocationType(obj)) continue;
|
|
1348
|
-
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1349
|
-
renamedCount++;
|
|
1350
|
-
console.log(
|
|
1351
|
-
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1352
|
-
);
|
|
1353
|
-
}
|
|
1354
|
-
return renamedCount;
|
|
1355
|
-
}
|
|
1356
|
-
async function main8() {
|
|
1357
|
-
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1358
|
-
console.log(
|
|
1359
|
-
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1360
|
-
`
|
|
1361
|
-
);
|
|
1362
|
-
const project = new import_ts_morph8.Project({
|
|
1363
|
-
tsConfigFilePath: import_path8.default.resolve(srcDir, "../tsconfig.json"),
|
|
1364
|
-
skipAddingFilesFromTsConfig: false
|
|
1365
|
-
});
|
|
1366
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1367
|
-
const fp = sf.getFilePath();
|
|
1368
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1369
|
-
});
|
|
1370
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1371
|
-
`);
|
|
1372
|
-
let totalRenamed = 0;
|
|
1373
|
-
const modifiedFiles = [];
|
|
1374
|
-
for (const sourceFile of sourceFiles) {
|
|
1375
|
-
const filePath = sourceFile.getFilePath();
|
|
1376
|
-
const renamed = processFile8(filePath, project);
|
|
1377
|
-
if (renamed > 0) {
|
|
1378
|
-
totalRenamed += renamed;
|
|
1379
|
-
modifiedFiles.push(filePath);
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
if (modifiedFiles.length === 0) {
|
|
1383
|
-
console.log(
|
|
1384
|
-
`No Location.${OLD_PROPERTY_NAME} references found. Nothing to do.`
|
|
1385
|
-
);
|
|
1386
|
-
return;
|
|
1387
|
-
}
|
|
1388
|
-
console.log(`
|
|
1389
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1390
|
-
for (const filePath of modifiedFiles) {
|
|
1391
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1392
|
-
await sourceFile.save();
|
|
1393
|
-
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1394
|
-
}
|
|
1395
|
-
console.log(
|
|
1396
|
-
`
|
|
1397
|
-
Done. Renamed ${totalRenamed} Location.${OLD_PROPERTY_NAME} reference(s) to Location.${NEW_PROPERTY_NAME}.`
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
// src/migrations/v2.0/rename-api-paths.ts
|
|
1402
|
-
var import_ts_morph9 = require("ts-morph");
|
|
1403
|
-
var import_path9 = __toESM(require("path"));
|
|
1404
|
-
var PATH_RENAMES = {
|
|
1405
|
-
"/events": "/config/events",
|
|
1406
|
-
"/application-config": "/config/application",
|
|
1407
|
-
"/workqueue": "/config/workqueues",
|
|
1408
|
-
"/locations": "/config/locations",
|
|
1409
|
-
"/users": "/config/users",
|
|
1410
|
-
"/roles": "/config/roles"
|
|
1411
|
-
};
|
|
1412
|
-
var METHOD_PROPERTY_NAME = "method";
|
|
1413
|
-
var PATH_PROPERTY_NAME = "path";
|
|
1414
|
-
var HTTP_VERBS = /* @__PURE__ */ new Set([
|
|
1415
|
-
"GET",
|
|
1416
|
-
"POST",
|
|
1417
|
-
"PUT",
|
|
1418
|
-
"PATCH",
|
|
1419
|
-
"DELETE",
|
|
1420
|
-
"OPTIONS",
|
|
1421
|
-
"HEAD",
|
|
1422
|
-
"*"
|
|
1423
|
-
]);
|
|
1424
|
-
function isRouteConfig(obj) {
|
|
1425
|
-
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
1426
|
-
if (!methodProp || !import_ts_morph9.Node.isPropertyAssignment(methodProp)) return false;
|
|
1427
|
-
const methodInit = methodProp.getInitializer();
|
|
1428
|
-
if (!methodInit) return false;
|
|
1429
|
-
if (import_ts_morph9.Node.isStringLiteral(methodInit)) {
|
|
1430
|
-
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
1431
|
-
return false;
|
|
1432
|
-
} else if (import_ts_morph9.Node.isArrayLiteralExpression(methodInit)) {
|
|
1433
|
-
const allVerbs = methodInit.getElements().every(
|
|
1434
|
-
(el) => import_ts_morph9.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
|
|
1435
|
-
);
|
|
1436
|
-
if (!allVerbs) return false;
|
|
1437
|
-
} else {
|
|
1438
|
-
return false;
|
|
1439
|
-
}
|
|
1440
|
-
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
1441
|
-
if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return false;
|
|
1442
|
-
const pathInit = pathProp.getInitializer();
|
|
1443
|
-
return !!pathInit && import_ts_morph9.Node.isStringLiteral(pathInit);
|
|
1444
|
-
}
|
|
1445
|
-
function renameRoutePath(obj) {
|
|
1446
|
-
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
1447
|
-
if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return null;
|
|
1448
|
-
const pathInit = pathProp.getInitializer();
|
|
1449
|
-
if (!pathInit || !import_ts_morph9.Node.isStringLiteral(pathInit)) return null;
|
|
1450
|
-
const oldPath = pathInit.getLiteralValue();
|
|
1451
|
-
const newPath = PATH_RENAMES[oldPath];
|
|
1452
|
-
if (!newPath) return null;
|
|
1453
|
-
pathInit.replaceWithText(`'${newPath}'`);
|
|
1454
|
-
return newPath;
|
|
1455
|
-
}
|
|
1456
|
-
function processFile9(filePath, project) {
|
|
1457
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
1458
|
-
if (!sourceFile) return 0;
|
|
1459
|
-
let renamedCount = 0;
|
|
1460
|
-
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1461
|
-
const candidates = sourceFile.getDescendantsOfKind(
|
|
1462
|
-
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1463
|
-
);
|
|
1464
|
-
for (const obj of candidates) {
|
|
1465
|
-
if (!isRouteConfig(obj)) continue;
|
|
1466
|
-
const newPath = renameRoutePath(obj);
|
|
1467
|
-
if (newPath) {
|
|
1468
|
-
renamedCount++;
|
|
1469
|
-
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
return renamedCount;
|
|
1473
|
-
}
|
|
1474
|
-
async function main9() {
|
|
1475
|
-
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1476
|
-
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1477
|
-
`);
|
|
1478
|
-
console.log("Active path renames:");
|
|
1479
|
-
for (const [from, to] of Object.entries(PATH_RENAMES)) {
|
|
1480
|
-
console.log(` '${from}' \u2192 '${to}'`);
|
|
1481
|
-
}
|
|
1482
|
-
console.log();
|
|
1483
|
-
const project = new import_ts_morph9.Project({
|
|
1484
|
-
tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
|
|
1485
|
-
skipAddingFilesFromTsConfig: false
|
|
1486
|
-
});
|
|
1487
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
1488
|
-
const fp = sf.getFilePath();
|
|
1489
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
1490
|
-
});
|
|
1491
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
1492
|
-
`);
|
|
1493
|
-
let totalRenamed = 0;
|
|
1494
|
-
const modifiedFiles = [];
|
|
1495
|
-
for (const sourceFile of sourceFiles) {
|
|
1496
|
-
const filePath = sourceFile.getFilePath();
|
|
1497
|
-
const renamed = processFile9(filePath, project);
|
|
1498
|
-
if (renamed > 0) {
|
|
1499
|
-
totalRenamed += renamed;
|
|
1500
|
-
modifiedFiles.push(filePath);
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
if (modifiedFiles.length === 0) {
|
|
1504
|
-
console.log("No matching route paths found. Nothing to do.");
|
|
1505
|
-
return;
|
|
1506
|
-
}
|
|
1507
|
-
console.log(`
|
|
1508
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
1509
|
-
for (const filePath of modifiedFiles) {
|
|
1510
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1511
|
-
await sourceFile.save();
|
|
1512
|
-
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1513
|
-
}
|
|
1514
|
-
console.log(`
|
|
1515
|
-
Done. Renamed ${totalRenamed} route path(s).`);
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
// src/migrations/v2.0/convert-config-files-to-ts.ts
|
|
1519
|
-
var fs = __toESM(require("fs"));
|
|
1520
|
-
var import_ts_morph10 = require("ts-morph");
|
|
1521
|
-
var import_path10 = __toESM(require("path"));
|
|
1522
|
-
var CLIENT_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1523
|
-
"COUNTRY",
|
|
1524
|
-
"LANGUAGES",
|
|
1525
|
-
"SENTRY",
|
|
1526
|
-
"REGISTER_BACKGROUND",
|
|
1527
|
-
"DASHBOARDS",
|
|
1528
|
-
"FEATURES"
|
|
1529
|
-
]);
|
|
1530
|
-
var LOGIN_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1531
|
-
"COUNTRY",
|
|
1532
|
-
"LANGUAGES",
|
|
1533
|
-
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1534
|
-
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1535
|
-
"PHONE_NUMBER_PATTERN",
|
|
1536
|
-
"LOGIN_BACKGROUND",
|
|
1537
|
-
"SENTRY"
|
|
1538
|
-
]);
|
|
1539
|
-
var APPLICATION_CONFIG_VALID_KEYS = /* @__PURE__ */ new Set([
|
|
1540
|
-
"APPLICATION_NAME",
|
|
1541
|
-
"COUNTRY_LOGO",
|
|
1542
|
-
"SYSTEM_IANA_TIMEZONE",
|
|
1543
|
-
"CURRENCY",
|
|
1544
|
-
"ADMIN_STRUCTURE",
|
|
1545
|
-
"PHONE_NUMBER_PATTERN",
|
|
1546
|
-
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1547
|
-
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1548
|
-
"SEARCH_DEFAULT_CRITERIA"
|
|
1549
|
-
]);
|
|
1550
|
-
var CONFIG_GROUPS = [
|
|
1551
|
-
{
|
|
1552
|
-
baseName: "client-config",
|
|
1553
|
-
prodName: "client-config.prod",
|
|
1554
|
-
defineFn: "defineClientConfig",
|
|
1555
|
-
importFrom: "@opencrvs/toolkit/application-config",
|
|
1556
|
-
validKeys: CLIENT_VALID_KEYS,
|
|
1557
|
-
requiredPlaceholders: {
|
|
1558
|
-
// BackgroundConfig requires backgroundColor or backgroundImage
|
|
1559
|
-
REGISTER_BACKGROUND: "{ backgroundColor: '#F4F4F7' }"
|
|
1560
|
-
},
|
|
1561
|
-
exportNames: {
|
|
1562
|
-
"client-config": "clientConfig",
|
|
1563
|
-
"client-config.prod": "clientConfigProd"
|
|
1564
|
-
},
|
|
1565
|
-
routePath: "/client-config.js"
|
|
1566
|
-
},
|
|
1567
|
-
{
|
|
1568
|
-
baseName: "login-config",
|
|
1569
|
-
prodName: "login-config.prod",
|
|
1570
|
-
defineFn: "defineLoginConfig",
|
|
1571
|
-
importFrom: "@opencrvs/toolkit/application-config",
|
|
1572
|
-
validKeys: LOGIN_VALID_KEYS,
|
|
1573
|
-
requiredPlaceholders: {},
|
|
1574
|
-
// These keys are always sourced from applicationConfig rather than
|
|
1575
|
-
// copied from the old JS file or filled with a placeholder value.
|
|
1576
|
-
// LOGIN_BACKGROUND lives in applicationConfig and is not part of the
|
|
1577
|
-
// ApplicationConfig schema, so Phase 3 will inline its value and remove
|
|
1578
|
-
// it from applicationConfig automatically.
|
|
1579
|
-
applicationConfigKeys: [
|
|
1580
|
-
"LOGIN_BACKGROUND",
|
|
1581
|
-
"USER_NOTIFICATION_DELIVERY_METHOD",
|
|
1582
|
-
"INFORMANT_NOTIFICATION_DELIVERY_METHOD",
|
|
1583
|
-
"PHONE_NUMBER_PATTERN"
|
|
1584
|
-
],
|
|
1585
|
-
applicationConfigImportPath: "./api/application/application-config",
|
|
1586
|
-
exportNames: {
|
|
1587
|
-
"login-config": "loginConfig",
|
|
1588
|
-
"login-config.prod": "loginConfigProd"
|
|
1589
|
-
},
|
|
1590
|
-
routePath: "/login-config.js"
|
|
1591
|
-
}
|
|
1592
|
-
];
|
|
1593
|
-
var HTTP_VERBS2 = /* @__PURE__ */ new Set([
|
|
1594
|
-
"GET",
|
|
1595
|
-
"POST",
|
|
1596
|
-
"PUT",
|
|
1597
|
-
"PATCH",
|
|
1598
|
-
"DELETE",
|
|
1599
|
-
"OPTIONS",
|
|
1600
|
-
"HEAD",
|
|
1601
|
-
"*"
|
|
1602
|
-
]);
|
|
1603
|
-
function extractWindowConfig(jsFilePath) {
|
|
1604
|
-
const jsProject = new import_ts_morph10.Project({
|
|
1605
|
-
compilerOptions: { allowJs: true, checkJs: false }
|
|
1606
|
-
// addFilesFromTsConfig: false
|
|
1607
|
-
});
|
|
1608
|
-
let sourceFile;
|
|
1609
|
-
try {
|
|
1610
|
-
sourceFile = jsProject.addSourceFileAtPath(jsFilePath);
|
|
1611
|
-
} catch {
|
|
1612
|
-
console.warn(` Could not parse ${jsFilePath}`);
|
|
1613
|
-
return null;
|
|
1614
|
-
}
|
|
1615
|
-
for (const binary of sourceFile.getDescendantsOfKind(
|
|
1616
|
-
import_ts_morph10.SyntaxKind.BinaryExpression
|
|
1617
|
-
)) {
|
|
1618
|
-
if (binary.getOperatorToken().getKind() !== import_ts_morph10.SyntaxKind.EqualsToken) continue;
|
|
1619
|
-
const left = binary.getLeft();
|
|
1620
|
-
if (!import_ts_morph10.Node.isPropertyAccessExpression(left)) continue;
|
|
1621
|
-
if (left.getExpression().getText() !== "window") continue;
|
|
1622
|
-
if (left.getName() !== "config") continue;
|
|
1623
|
-
const right = binary.getRight();
|
|
1624
|
-
if (import_ts_morph10.Node.isObjectLiteralExpression(right)) return right;
|
|
1625
|
-
}
|
|
1626
|
-
return null;
|
|
1627
|
-
}
|
|
1628
|
-
function convertLanguages(init) {
|
|
1629
|
-
if (import_ts_morph10.Node.isStringLiteral(init)) {
|
|
1630
|
-
const langs = init.getLiteralValue().split(",").map((l) => `'${l.trim()}'`).join(", ");
|
|
1631
|
-
return `[${langs}]`;
|
|
1632
|
-
}
|
|
1633
|
-
return init.getText();
|
|
1634
|
-
}
|
|
1635
|
-
function extractStaticUrlString(init) {
|
|
1636
|
-
if (import_ts_morph10.Node.isStringLiteral(init)) {
|
|
1637
|
-
return init.getLiteralValue();
|
|
1638
|
-
}
|
|
1639
|
-
if (init.getKind() === import_ts_morph10.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
1640
|
-
const raw = init.getText();
|
|
1641
|
-
return raw.slice(1, -1);
|
|
1642
|
-
}
|
|
1643
|
-
return null;
|
|
1644
|
-
}
|
|
1645
|
-
function transformDashboardUrl(init, isProd) {
|
|
1646
|
-
if (!isProd) return init.getText();
|
|
1647
|
-
const urlString = extractStaticUrlString(init);
|
|
1648
|
-
if (!urlString) return init.getText();
|
|
1649
|
-
try {
|
|
1650
|
-
const parsed = new URL(urlString);
|
|
1651
|
-
const rest = parsed.pathname + parsed.search + parsed.hash;
|
|
1652
|
-
return `\`\${scheme}//metabase.\${hostname}${rest}\``;
|
|
1653
|
-
} catch {
|
|
1654
|
-
return init.getText();
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
function transformDashboardsValue(init, isProd) {
|
|
1658
|
-
if (!isProd || !import_ts_morph10.Node.isArrayLiteralExpression(init)) {
|
|
1659
|
-
return init.getText();
|
|
1660
|
-
}
|
|
1661
|
-
const elementParts = [];
|
|
1662
|
-
for (const el of init.getElements()) {
|
|
1663
|
-
if (!import_ts_morph10.Node.isObjectLiteralExpression(el)) {
|
|
1664
|
-
elementParts.push(el.getText());
|
|
1665
|
-
continue;
|
|
1666
|
-
}
|
|
1667
|
-
const propParts = [];
|
|
1668
|
-
for (const prop of el.getProperties()) {
|
|
1669
|
-
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) {
|
|
1670
|
-
propParts.push(prop.getText());
|
|
1671
|
-
continue;
|
|
1672
|
-
}
|
|
1673
|
-
const propName = prop.getName();
|
|
1674
|
-
const propInit = prop.getInitializer();
|
|
1675
|
-
if (!propInit) {
|
|
1676
|
-
propParts.push(prop.getText());
|
|
1677
|
-
continue;
|
|
1678
|
-
}
|
|
1679
|
-
if (propName === "url") {
|
|
1680
|
-
propParts.push(`url: ${transformDashboardUrl(propInit, isProd)}`);
|
|
1681
|
-
} else {
|
|
1682
|
-
propParts.push(`${propName}: ${propInit.getText()}`);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
elementParts.push(
|
|
1686
|
-
` {
|
|
1687
|
-
${propParts.map((p) => ` ${p}`).join(",\n")}
|
|
1688
|
-
}`
|
|
1689
|
-
);
|
|
1690
|
-
}
|
|
1691
|
-
return `[
|
|
1692
|
-
${elementParts.join(",\n")}
|
|
1693
|
-
]`;
|
|
1694
|
-
}
|
|
1695
|
-
function generateTsContent(configObj, exportName, group, isProd) {
|
|
1696
|
-
const propertyLines = [];
|
|
1697
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
1698
|
-
const appConfigKeySet = new Set(group.applicationConfigKeys ?? []);
|
|
1699
|
-
for (const prop of configObj.getProperties()) {
|
|
1700
|
-
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) continue;
|
|
1701
|
-
const name = prop.getName();
|
|
1702
|
-
if (!group.validKeys.has(name)) continue;
|
|
1703
|
-
if (appConfigKeySet.has(name)) continue;
|
|
1704
|
-
seenKeys.add(name);
|
|
1705
|
-
const init = prop.getInitializer();
|
|
1706
|
-
if (!init) continue;
|
|
1707
|
-
if (name === "LANGUAGES") {
|
|
1708
|
-
propertyLines.push(` LANGUAGES: ${convertLanguages(init)}`);
|
|
1709
|
-
} else if (name === "SENTRY" && isProd) {
|
|
1710
|
-
propertyLines.push(` SENTRY: sentry`);
|
|
1711
|
-
} else if (name === "DASHBOARDS") {
|
|
1712
|
-
propertyLines.push(
|
|
1713
|
-
` DASHBOARDS: ${transformDashboardsValue(init, isProd)}`
|
|
1714
|
-
);
|
|
1715
|
-
} else {
|
|
1716
|
-
propertyLines.push(` ${name}: ${init.getText()}`);
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
for (const [key, placeholder] of Object.entries(group.requiredPlaceholders)) {
|
|
1720
|
-
if (!seenKeys.has(key)) {
|
|
1721
|
-
propertyLines.push(
|
|
1722
|
-
` // TODO: configure ${key} \u2014 replace this placeholder`,
|
|
1723
|
-
` ${key}: ${placeholder}`
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
for (const key of appConfigKeySet) {
|
|
1728
|
-
propertyLines.push(` ${key}: applicationConfig.${key}`);
|
|
1729
|
-
}
|
|
1730
|
-
const body = propertyLines.join(",\n");
|
|
1731
|
-
const headerLines = [];
|
|
1732
|
-
headerLines.push(`import * as fs from 'fs'`);
|
|
1733
|
-
headerLines.push(`import { join } from 'path'`);
|
|
1734
|
-
if (isProd) {
|
|
1735
|
-
headerLines.push(`import { env } from './environment'`);
|
|
1736
|
-
}
|
|
1737
|
-
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1738
|
-
if (group.applicationConfigImportPath) {
|
|
1739
|
-
headerLines.push(
|
|
1740
|
-
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1741
|
-
);
|
|
1742
|
-
}
|
|
1743
|
-
headerLines.push("");
|
|
1744
|
-
if (isProd) {
|
|
1745
|
-
headerLines.push(`const scheme = 'https'`);
|
|
1746
|
-
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1747
|
-
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1748
|
-
} else {
|
|
1749
|
-
headerLines.push(`const scheme = 'http'`);
|
|
1750
|
-
headerLines.push(`const hostname = 'localhost'`);
|
|
1751
|
-
}
|
|
1752
|
-
return [
|
|
1753
|
-
...headerLines,
|
|
1754
|
-
"",
|
|
1755
|
-
`export const ${exportName} = ${group.defineFn}({`,
|
|
1756
|
-
body,
|
|
1757
|
-
"})",
|
|
1758
|
-
""
|
|
1759
|
-
].join("\n");
|
|
1760
|
-
}
|
|
1761
|
-
function convertFile(name, group, srcDir) {
|
|
1762
|
-
const jsFilePath = import_path10.default.join(srcDir, `${name}.js`);
|
|
1763
|
-
const tsFilePath = import_path10.default.join(srcDir, `${name}.ts`);
|
|
1764
|
-
if (!fs.existsSync(jsFilePath)) {
|
|
1765
|
-
console.log(` Skipping ${name}.js \u2014 file not found`);
|
|
1766
|
-
return false;
|
|
1767
|
-
}
|
|
1768
|
-
if (fs.existsSync(tsFilePath)) {
|
|
1769
|
-
console.log(` Skipping ${name}.js \u2014 ${name}.ts already exists`);
|
|
1770
|
-
return false;
|
|
1771
|
-
}
|
|
1772
|
-
const configObj = extractWindowConfig(jsFilePath);
|
|
1773
|
-
if (!configObj) {
|
|
1774
|
-
console.warn(
|
|
1775
|
-
` [${name}.js] Could not locate window.config assignment \u2014 skipping`
|
|
1776
|
-
);
|
|
1777
|
-
return false;
|
|
1778
|
-
}
|
|
1779
|
-
const isProd = name.endsWith(".prod");
|
|
1780
|
-
const exportName = group.exportNames[name];
|
|
1781
|
-
const content = generateTsContent(configObj, exportName, group, isProd);
|
|
1782
|
-
fs.writeFileSync(tsFilePath, content, "utf8");
|
|
1783
|
-
fs.unlinkSync(jsFilePath);
|
|
1784
|
-
console.log(` Converted ${name}.js \u2192 ${name}.ts (export: ${exportName})`);
|
|
1785
|
-
return true;
|
|
1786
|
-
}
|
|
1787
|
-
function isRouteConfig2(obj) {
|
|
1788
|
-
const methodProp = obj.getProperty("method");
|
|
1789
|
-
if (!methodProp || !import_ts_morph10.Node.isPropertyAssignment(methodProp)) return false;
|
|
1790
|
-
const methodInit = methodProp.getInitializer();
|
|
1791
|
-
if (!methodInit) return false;
|
|
1792
|
-
if (import_ts_morph10.Node.isStringLiteral(methodInit)) {
|
|
1793
|
-
if (!HTTP_VERBS2.has(methodInit.getLiteralValue().toUpperCase()))
|
|
1794
|
-
return false;
|
|
1795
|
-
} else if (import_ts_morph10.Node.isArrayLiteralExpression(methodInit)) {
|
|
1796
|
-
const allVerbs = methodInit.getElements().every(
|
|
1797
|
-
(el) => import_ts_morph10.Node.isStringLiteral(el) && HTTP_VERBS2.has(el.getLiteralValue().toUpperCase())
|
|
1798
|
-
);
|
|
1799
|
-
if (!allVerbs) return false;
|
|
1800
|
-
} else {
|
|
1801
|
-
return false;
|
|
1802
|
-
}
|
|
1803
|
-
const pathProp = obj.getProperty("path");
|
|
1804
|
-
if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return false;
|
|
1805
|
-
const pathInit = pathProp.getInitializer();
|
|
1806
|
-
return !!pathInit && import_ts_morph10.Node.isStringLiteral(pathInit);
|
|
1807
|
-
}
|
|
1808
|
-
function getRoutePath(obj) {
|
|
1809
|
-
const pathProp = obj.getProperty("path");
|
|
1810
|
-
if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return null;
|
|
1811
|
-
const pathInit = pathProp.getInitializer();
|
|
1812
|
-
if (!pathInit || !import_ts_morph10.Node.isStringLiteral(pathInit)) return null;
|
|
1813
|
-
return pathInit.getLiteralValue();
|
|
1814
|
-
}
|
|
1815
|
-
function findHandlerProperty(routeObj) {
|
|
1816
|
-
const directHandler = routeObj.getProperty("handler");
|
|
1817
|
-
if (directHandler && import_ts_morph10.Node.isPropertyAssignment(directHandler)) {
|
|
1818
|
-
return directHandler;
|
|
1819
|
-
}
|
|
1820
|
-
const optionsProp = routeObj.getProperty("options");
|
|
1821
|
-
if (optionsProp && import_ts_morph10.Node.isPropertyAssignment(optionsProp)) {
|
|
1822
|
-
const optionsInit = optionsProp.getInitializer();
|
|
1823
|
-
if (optionsInit && import_ts_morph10.Node.isObjectLiteralExpression(optionsInit)) {
|
|
1824
|
-
const nestedHandler = optionsInit.getProperty("handler");
|
|
1825
|
-
if (nestedHandler && import_ts_morph10.Node.isPropertyAssignment(nestedHandler)) {
|
|
1826
|
-
return nestedHandler;
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
return null;
|
|
1831
|
-
}
|
|
1832
|
-
function ensureConfigImports(sourceFile, group, srcDir) {
|
|
1833
|
-
const routeFileDir = import_path10.default.dirname(sourceFile.getFilePath());
|
|
1834
|
-
for (const name of [group.baseName, group.prodName]) {
|
|
1835
|
-
const exportName = group.exportNames[name];
|
|
1836
|
-
const absoluteConfigPath = import_path10.default.join(srcDir, name);
|
|
1837
|
-
const rel = import_path10.default.relative(routeFileDir, absoluteConfigPath).replace(/\\/g, "/");
|
|
1838
|
-
const moduleSpecifier = rel.startsWith(".") ? rel : `./${rel}`;
|
|
1839
|
-
const alreadyImported = sourceFile.getImportDeclarations().some(
|
|
1840
|
-
(d) => d.getModuleSpecifierValue() === moduleSpecifier || d.getNamedImports().some((ni) => ni.getName() === exportName)
|
|
1841
|
-
);
|
|
1842
|
-
if (!alreadyImported) {
|
|
1843
|
-
sourceFile.addImportDeclaration({
|
|
1844
|
-
moduleSpecifier,
|
|
1845
|
-
namedImports: [exportName]
|
|
1846
|
-
});
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
1851
|
-
const baseExport = group.exportNames[group.baseName];
|
|
1852
|
-
const prodExport = group.exportNames[group.prodName];
|
|
1853
|
-
const newHandlerText = `async (request, h) => {
|
|
1854
|
-
const config =
|
|
1855
|
-
process.env.NODE_ENV === 'production' ? ${prodExport} : ${baseExport}
|
|
1856
|
-
return h
|
|
1857
|
-
.response(\`window.config = \${JSON.stringify(config)}\`)
|
|
1858
|
-
.type('application/javascript')
|
|
1859
|
-
}`;
|
|
1860
|
-
let replacedCount = 0;
|
|
1861
|
-
for (const sourceFile of sourceFiles) {
|
|
1862
|
-
const filePath = sourceFile.getFilePath();
|
|
1863
|
-
const candidates = sourceFile.getDescendantsOfKind(
|
|
1864
|
-
import_ts_morph10.SyntaxKind.ObjectLiteralExpression
|
|
1865
|
-
);
|
|
1866
|
-
for (const obj of candidates) {
|
|
1867
|
-
if (!isRouteConfig2(obj)) continue;
|
|
1868
|
-
if (getRoutePath(obj) !== group.routePath) continue;
|
|
1869
|
-
const handlerProp = findHandlerProperty(obj);
|
|
1870
|
-
if (!handlerProp) {
|
|
1871
|
-
console.warn(
|
|
1872
|
-
` [${relCwd(filePath)}] Found route '${group.routePath}' but could not locate handler property \u2014 skipping`
|
|
1873
|
-
);
|
|
1874
|
-
continue;
|
|
1875
|
-
}
|
|
1876
|
-
handlerProp.setInitializer(newHandlerText);
|
|
1877
|
-
ensureConfigImports(sourceFile, group, srcDir);
|
|
1878
|
-
replacedCount++;
|
|
1879
|
-
console.log(
|
|
1880
|
-
` [${relCwd(filePath)}] Replaced handler for route '${group.routePath}'`
|
|
1881
|
-
);
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
return replacedCount;
|
|
1885
|
-
}
|
|
1886
|
-
function resolveConfigChain(configObj, path23) {
|
|
1887
|
-
let current = configObj;
|
|
1888
|
-
for (const key of path23) {
|
|
1889
|
-
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1890
|
-
const prop = current.getProperty(key);
|
|
1891
|
-
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
1892
|
-
const initNode = prop.getInitializer();
|
|
1893
|
-
if (!initNode) return null;
|
|
1894
|
-
current = initNode;
|
|
1895
|
-
}
|
|
1896
|
-
return current.getText();
|
|
1897
|
-
}
|
|
1898
|
-
function rewriteDirnameRefs(text, relDir) {
|
|
1899
|
-
if (!relDir || relDir === ".") return text;
|
|
1900
|
-
const relForward = relDir.replace(/\\/g, "/");
|
|
1901
|
-
return text.replace(
|
|
1902
|
-
/\b((?:path\.)?(?:join|resolve))\s*\(\s*__dirname\s*,/g,
|
|
1903
|
-
`$1(__dirname, '${relForward}',`
|
|
1904
|
-
);
|
|
1905
|
-
}
|
|
1906
|
-
function ensureFsImport(sf) {
|
|
1907
|
-
const hasFs = sf.getImportDeclarations().some(
|
|
1908
|
-
(d) => d.getModuleSpecifierValue() === "fs" && (d.getNamespaceImport() || d.getDefaultImport())
|
|
1909
|
-
);
|
|
1910
|
-
if (hasFs) return;
|
|
1911
|
-
sf.addImportDeclaration({
|
|
1912
|
-
moduleSpecifier: "fs",
|
|
1913
|
-
namespaceImport: "fs"
|
|
1914
|
-
});
|
|
1915
|
-
}
|
|
1916
|
-
function ensureJoinImport(sf) {
|
|
1917
|
-
const pathImports = sf.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === "path");
|
|
1918
|
-
if (pathImports.some(
|
|
1919
|
-
(d) => d.getNamedImports().some((ni) => ni.getName() === "join")
|
|
1920
|
-
)) {
|
|
1921
|
-
return;
|
|
1922
|
-
}
|
|
1923
|
-
if (pathImports.length > 0) {
|
|
1924
|
-
pathImports[0].addNamedImport("join");
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
sf.addImportDeclaration({
|
|
1928
|
-
moduleSpecifier: "path",
|
|
1929
|
-
namedImports: ["join"]
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
async function main10() {
|
|
1933
|
-
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1934
|
-
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1935
|
-
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1936
|
-
let convertedCount = 0;
|
|
1937
|
-
for (const group of CONFIG_GROUPS) {
|
|
1938
|
-
for (const name of [group.baseName, group.prodName]) {
|
|
1939
|
-
if (convertFile(name, group, srcDir)) {
|
|
1940
|
-
convertedCount++;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
if (convertedCount === 0) {
|
|
1945
|
-
console.log(" No JS config files needed conversion.\n");
|
|
1946
|
-
} else {
|
|
1947
|
-
console.log(`
|
|
1948
|
-
Converted ${convertedCount} file(s).
|
|
1949
|
-
`);
|
|
1950
|
-
}
|
|
1951
|
-
console.log(
|
|
1952
|
-
"Phase 3: Wrapping applicationConfig with defineApplicationConfig...\n"
|
|
1953
|
-
);
|
|
1954
|
-
const appConfigRelPath = "api/application/application-config.ts";
|
|
1955
|
-
const appConfigAbsPath = import_path10.default.join(srcDir, appConfigRelPath);
|
|
1956
|
-
if (!fs.existsSync(appConfigAbsPath)) {
|
|
1957
|
-
console.log(` Skipping Phase 3 \u2014 ${appConfigRelPath} not found in src/
|
|
1958
|
-
`);
|
|
1959
|
-
} else {
|
|
1960
|
-
const appConfigProject = new import_ts_morph10.Project({
|
|
1961
|
-
tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
|
|
1962
|
-
skipAddingFilesFromTsConfig: false
|
|
1963
|
-
});
|
|
1964
|
-
const appConfigFile = appConfigProject.getSourceFile(appConfigAbsPath) ?? appConfigProject.addSourceFileAtPath(appConfigAbsPath);
|
|
1965
|
-
let wrapped = false;
|
|
1966
|
-
for (const varDecl of appConfigFile.getVariableDeclarations()) {
|
|
1967
|
-
if (varDecl.getName() !== "applicationConfig") continue;
|
|
1968
|
-
const init = varDecl.getInitializer();
|
|
1969
|
-
if (!init || !import_ts_morph10.Node.isObjectLiteralExpression(init)) continue;
|
|
1970
|
-
const propsToRemove = init.getProperties().filter((prop) => {
|
|
1971
|
-
if (!import_ts_morph10.Node.isPropertyAssignment(prop)) return false;
|
|
1972
|
-
const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
|
|
1973
|
-
return !APPLICATION_CONFIG_VALID_KEYS.has(name);
|
|
1974
|
-
});
|
|
1975
|
-
if (propsToRemove.length > 0) {
|
|
1976
|
-
const filesToSaveAfterInlining = /* @__PURE__ */ new Set();
|
|
1977
|
-
const appConfigDir = import_path10.default.dirname(appConfigAbsPath);
|
|
1978
|
-
for (const removedProp of propsToRemove) {
|
|
1979
|
-
const key = removedProp.getName();
|
|
1980
|
-
for (const sf of appConfigProject.getSourceFiles()) {
|
|
1981
|
-
if (sf.getFilePath() === appConfigAbsPath) continue;
|
|
1982
|
-
if (!sf.getFilePath().includes("/src/")) continue;
|
|
1983
|
-
if (sf.getFilePath().includes("/node_modules/")) continue;
|
|
1984
|
-
const targetDir = import_path10.default.dirname(sf.getFilePath());
|
|
1985
|
-
const relDirFromTarget = import_path10.default.relative(targetDir, appConfigDir);
|
|
1986
|
-
let madeReplacement = true;
|
|
1987
|
-
while (madeReplacement) {
|
|
1988
|
-
madeReplacement = false;
|
|
1989
|
-
for (const identNode of sf.getDescendantsOfKind(
|
|
1990
|
-
import_ts_morph10.SyntaxKind.Identifier
|
|
1991
|
-
)) {
|
|
1992
|
-
if (identNode.getText() !== "applicationConfig") continue;
|
|
1993
|
-
let node = identNode;
|
|
1994
|
-
const accessPath = [];
|
|
1995
|
-
while (true) {
|
|
1996
|
-
const parent = node.getParent();
|
|
1997
|
-
if (!import_ts_morph10.Node.isPropertyAccessExpression(parent)) break;
|
|
1998
|
-
if (parent.getExpression() !== node) break;
|
|
1999
|
-
accessPath.push(parent.getName());
|
|
2000
|
-
node = parent;
|
|
2001
|
-
}
|
|
2002
|
-
if (accessPath.length === 0 || accessPath[0] !== key) continue;
|
|
2003
|
-
const resolvedValue = resolveConfigChain(init, accessPath);
|
|
2004
|
-
if (resolvedValue === null) {
|
|
2005
|
-
console.log(
|
|
2006
|
-
` Cannot resolve applicationConfig.${accessPath.join(".")} \u2014 skipping inline replacement`
|
|
2007
|
-
);
|
|
2008
|
-
continue;
|
|
2009
|
-
}
|
|
2010
|
-
const adjustedValue = rewriteDirnameRefs(
|
|
2011
|
-
resolvedValue,
|
|
2012
|
-
relDirFromTarget
|
|
2013
|
-
);
|
|
2014
|
-
node.replaceWithText(adjustedValue);
|
|
2015
|
-
if (/\bfs\s*\./.test(adjustedValue)) {
|
|
2016
|
-
ensureFsImport(sf);
|
|
2017
|
-
}
|
|
2018
|
-
if (/\bjoin\s*\(/.test(adjustedValue)) {
|
|
2019
|
-
ensureJoinImport(sf);
|
|
2020
|
-
}
|
|
2021
|
-
console.log(
|
|
2022
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
2023
|
-
);
|
|
2024
|
-
filesToSaveAfterInlining.add(sf);
|
|
2025
|
-
madeReplacement = true;
|
|
2026
|
-
break;
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
2032
|
-
await sf.save();
|
|
2033
|
-
console.log(
|
|
2034
|
-
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
2035
|
-
);
|
|
2036
|
-
}
|
|
2037
|
-
for (const prop of [...propsToRemove].reverse()) {
|
|
2038
|
-
const propName = prop.getName();
|
|
2039
|
-
console.log(
|
|
2040
|
-
` Removing unknown key '${propName}' from applicationConfig (not in ApplicationConfig schema)`
|
|
2041
|
-
);
|
|
2042
|
-
prop.remove();
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
varDecl.setInitializer(`defineApplicationConfig(${init.getText()})`);
|
|
2046
|
-
const TOOLKIT_MODULE = "@opencrvs/toolkit/application-config";
|
|
2047
|
-
const existing = appConfigFile.getImportDeclaration(
|
|
2048
|
-
(d) => d.getModuleSpecifierValue() === TOOLKIT_MODULE
|
|
2049
|
-
);
|
|
2050
|
-
if (existing) {
|
|
2051
|
-
const names = new Set(
|
|
2052
|
-
existing.getNamedImports().map((ni) => ni.getName())
|
|
2053
|
-
);
|
|
2054
|
-
if (!names.has("defineApplicationConfig")) {
|
|
2055
|
-
existing.addNamedImport("defineApplicationConfig");
|
|
2056
|
-
}
|
|
2057
|
-
} else {
|
|
2058
|
-
appConfigFile.addImportDeclaration({
|
|
2059
|
-
moduleSpecifier: TOOLKIT_MODULE,
|
|
2060
|
-
namedImports: ["defineApplicationConfig"]
|
|
2061
|
-
});
|
|
2062
|
-
}
|
|
2063
|
-
wrapped = true;
|
|
2064
|
-
console.log(
|
|
2065
|
-
` Wrapped applicationConfig with defineApplicationConfig in ${appConfigRelPath}`
|
|
2066
|
-
);
|
|
2067
|
-
break;
|
|
2068
|
-
}
|
|
2069
|
-
if (!wrapped) {
|
|
2070
|
-
console.log(
|
|
2071
|
-
` Skipping Phase 3 \u2014 applicationConfig plain object not found (already wrapped?)
|
|
2072
|
-
`
|
|
2073
|
-
);
|
|
2074
|
-
} else {
|
|
2075
|
-
await appConfigFile.save();
|
|
2076
|
-
console.log(` Saved: ${appConfigRelPath}
|
|
2077
|
-
`);
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
console.log("Phase 2: Updating Hapi route handlers...\n");
|
|
2081
|
-
const project = new import_ts_morph10.Project({
|
|
2082
|
-
tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
|
|
2083
|
-
skipAddingFilesFromTsConfig: false
|
|
2084
|
-
});
|
|
2085
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
2086
|
-
const fp = sf.getFilePath();
|
|
2087
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
2088
|
-
});
|
|
2089
|
-
console.log(` Analysing ${sourceFiles.length} source file(s).
|
|
2090
|
-
`);
|
|
2091
|
-
let totalReplaced = 0;
|
|
2092
|
-
for (const group of CONFIG_GROUPS) {
|
|
2093
|
-
totalReplaced += updateRouteHandlers(sourceFiles, group, srcDir, relCwd);
|
|
2094
|
-
}
|
|
2095
|
-
if (totalReplaced === 0) {
|
|
2096
|
-
console.log(" No route handlers matched \u2014 nothing to update in Phase 2.\n");
|
|
2097
|
-
}
|
|
2098
|
-
const modified = sourceFiles.filter((sf) => sf.wasForgotten() === false);
|
|
2099
|
-
const toSave = modified.filter(
|
|
2100
|
-
(sf) => sf.getDescendantsOfKind(import_ts_morph10.SyntaxKind.ObjectLiteralExpression).length > 0
|
|
2101
|
-
);
|
|
2102
|
-
let savedCount = 0;
|
|
2103
|
-
for (const sf of project.getSourceFiles()) {
|
|
2104
|
-
if (sf.isSaved()) continue;
|
|
2105
|
-
await sf.save();
|
|
2106
|
-
console.log(` Saved: ${relCwd(sf.getFilePath())}`);
|
|
2107
|
-
savedCount++;
|
|
2108
|
-
}
|
|
2109
|
-
if (savedCount === 0 && totalReplaced === 0) {
|
|
2110
|
-
console.log("Nothing was changed.");
|
|
2111
|
-
return;
|
|
2112
|
-
}
|
|
2113
|
-
console.log(
|
|
2114
|
-
`
|
|
2115
|
-
Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} route handler(s).`
|
|
2116
|
-
);
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
// src/migrations/v2.0/migrate-scopes.ts
|
|
2120
|
-
var import_ts_morph11 = require("ts-morph");
|
|
2121
|
-
var import_path11 = __toESM(require("path"));
|
|
2122
|
-
|
|
2123
|
-
// ../commons/src/scopes.ts
|
|
2124
|
-
var z3 = __toESM(require("zod/v4"));
|
|
2125
|
-
var qs = __toESM(require("qs"));
|
|
2126
|
-
|
|
2127
|
-
// ../commons/src/uuid.ts
|
|
2128
|
-
var import_uuid = require("uuid");
|
|
2129
|
-
var z = __toESM(require("zod/v4"));
|
|
2130
|
-
var UUID = z.uuid().brand("UUID");
|
|
2131
|
-
|
|
2132
|
-
// ../commons/src/authentication.ts
|
|
2133
|
-
var import_jwt_decode = __toESM(require("jwt-decode"));
|
|
2134
|
-
var z2 = __toESM(require("zod/v4"));
|
|
2135
|
-
var TokenUserType = z2.enum(["user", "system"]);
|
|
2136
|
-
var TokenWithBearer = z2.string().regex(/^Bearer\s/);
|
|
2137
|
-
|
|
2138
|
-
// ../commons/src/scopes.ts
|
|
2139
|
-
var JurisdictionFilter = z3.enum(["administrativeArea", "location", "all"]).describe(
|
|
2140
|
-
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
2141
|
-
);
|
|
2142
|
-
var UserFilter = z3.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
2143
|
-
var RecordScopeTypeV2 = z3.enum([
|
|
2144
|
-
"record.search",
|
|
2145
|
-
"record.create",
|
|
2146
|
-
"record.read",
|
|
2147
|
-
"record.declare",
|
|
2148
|
-
"record.notify",
|
|
2149
|
-
"record.edit",
|
|
2150
|
-
"record.reject",
|
|
2151
|
-
"record.archive",
|
|
2152
|
-
"record.review-duplicates",
|
|
2153
|
-
"record.register",
|
|
2154
|
-
"record.print-certified-copies",
|
|
2155
|
-
"record.request-correction",
|
|
2156
|
-
"record.correct",
|
|
2157
|
-
"record.unassign-others",
|
|
2158
|
-
"record.custom-action"
|
|
2159
|
-
]);
|
|
2160
|
-
var PlainScopeType = z3.enum([
|
|
2161
|
-
// Misc. system scopes
|
|
2162
|
-
"bypassratelimit",
|
|
2163
|
-
"record.reindex",
|
|
2164
|
-
"user.data-seeding",
|
|
2165
|
-
"integration.create",
|
|
2166
|
-
"record.import",
|
|
2167
|
-
"config.update-all",
|
|
2168
|
-
"attachment.upload",
|
|
2169
|
-
"profile.electronic-signature",
|
|
2170
|
-
"user.read-only-my-audit",
|
|
2171
|
-
// Performance dashboard
|
|
2172
|
-
"performance.read",
|
|
2173
|
-
"performance.read-dashboards",
|
|
2174
|
-
"performance.vital-statistics-export",
|
|
2175
|
-
// Scopes used exclusively by countryconfig integration token
|
|
2176
|
-
"record.confirm-registration",
|
|
2177
|
-
"record.reject-registration"
|
|
2178
|
-
]);
|
|
2179
|
-
var scopeByEvent = z3.preprocess(
|
|
2180
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2181
|
-
z3.array(z3.string()).optional()
|
|
2182
|
-
).describe("Event type, e.g. birth, death");
|
|
2183
|
-
var userRole = z3.preprocess(
|
|
2184
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2185
|
-
z3.array(z3.string()).optional()
|
|
2186
|
-
).describe("User role, e.g. admin, field agent");
|
|
2187
|
-
var scopeOptionsPlaceEvent = z3.object({
|
|
2188
|
-
event: scopeByEvent,
|
|
2189
|
-
placeOfEvent: JurisdictionFilter.optional()
|
|
2190
|
-
}).describe("Options applicable to all record scopes.");
|
|
2191
|
-
var scopeOptionsDeclared = scopeOptionsPlaceEvent.extend({
|
|
2192
|
-
declaredIn: JurisdictionFilter.optional(),
|
|
2193
|
-
declaredBy: UserFilter.optional()
|
|
2194
|
-
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
2195
|
-
var AllRecordScopeOptions = scopeOptionsDeclared.extend({
|
|
2196
|
-
registeredIn: JurisdictionFilter.optional(),
|
|
2197
|
-
registeredBy: UserFilter.optional()
|
|
2198
|
-
}).describe(
|
|
2199
|
-
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
2200
|
-
);
|
|
2201
|
-
var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
2202
|
-
customActionTypes: z3.preprocess(
|
|
2203
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2204
|
-
z3.array(z3.string()).optional()
|
|
2205
|
-
).describe("Allowed custom action types")
|
|
2206
|
-
});
|
|
2207
|
-
var AccessLevelOptions = z3.object({
|
|
2208
|
-
accessLevel: JurisdictionFilter.optional()
|
|
2209
|
-
});
|
|
2210
|
-
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2211
|
-
role: userRole.optional()
|
|
2212
|
-
});
|
|
2213
|
-
var WorkqueueOrDashboardOptions = z3.object({
|
|
2214
|
-
ids: z3.preprocess(
|
|
2215
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2216
|
-
z3.array(z3.string())
|
|
2217
|
-
).describe("Must contain a list of workqueue or dashboard ids.")
|
|
2218
|
-
});
|
|
2219
|
-
var AllScopeOptions = z3.object({
|
|
2220
|
-
...AllRecordScopeOptions.shape,
|
|
2221
|
-
...AccessLevelOptions.shape,
|
|
2222
|
-
...AllUserScopeOptions.shape,
|
|
2223
|
-
...WorkqueueOrDashboardOptions.shape
|
|
2224
|
-
});
|
|
2225
|
-
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
2226
|
-
var ResolvedScopeOptionsPlaceEvent = z3.object({
|
|
2227
|
-
event: scopeByEvent,
|
|
2228
|
-
placeOfEvent: UUID.nullish()
|
|
2229
|
-
}).describe(
|
|
2230
|
-
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
2231
|
-
);
|
|
2232
|
-
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
2233
|
-
declaredIn: UUID.nullish(),
|
|
2234
|
-
declaredBy: z3.string().optional()
|
|
2235
|
-
}).describe(
|
|
2236
|
-
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
2237
|
-
);
|
|
2238
|
-
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
2239
|
-
registeredIn: UUID.nullish(),
|
|
2240
|
-
registeredBy: z3.string().optional()
|
|
2241
|
-
}).describe(
|
|
2242
|
-
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
2243
|
-
);
|
|
2244
|
-
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
2245
|
-
"record.create",
|
|
2246
|
-
"record.declare",
|
|
2247
|
-
"record.notify"
|
|
2248
|
-
]);
|
|
2249
|
-
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
2250
|
-
"record.edit",
|
|
2251
|
-
"record.reject",
|
|
2252
|
-
"record.archive",
|
|
2253
|
-
"record.review-duplicates",
|
|
2254
|
-
"record.register"
|
|
2255
|
-
]);
|
|
2256
|
-
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
2257
|
-
"record.search",
|
|
2258
|
-
"record.read",
|
|
2259
|
-
"record.request-correction",
|
|
2260
|
-
"record.correct",
|
|
2261
|
-
"record.unassign-others"
|
|
2262
|
-
]);
|
|
2263
|
-
var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
|
|
2264
|
-
templates: z3.preprocess(
|
|
2265
|
-
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2266
|
-
z3.array(z3.string()).optional()
|
|
2267
|
-
).describe(
|
|
2268
|
-
"Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
|
|
2269
|
-
)
|
|
2270
|
-
});
|
|
2271
|
-
var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2272
|
-
z3.object({
|
|
2273
|
-
type: ScopesWithPlaceEventOptions,
|
|
2274
|
-
options: scopeOptionsPlaceEvent.optional()
|
|
2275
|
-
}),
|
|
2276
|
-
z3.object({
|
|
2277
|
-
type: ScopesWithDeclaredOptions,
|
|
2278
|
-
options: scopeOptionsDeclared.optional()
|
|
2279
|
-
}),
|
|
2280
|
-
z3.object({
|
|
2281
|
-
type: ScopesWithFullOptions,
|
|
2282
|
-
options: AllRecordScopeOptions.optional()
|
|
2283
|
-
}),
|
|
2284
|
-
z3.object({
|
|
2285
|
-
type: z3.literal("record.custom-action"),
|
|
2286
|
-
options: CustomActionScopeOptions.optional()
|
|
2287
|
-
}),
|
|
2288
|
-
z3.object({
|
|
2289
|
-
type: z3.literal("record.print-certified-copies"),
|
|
2290
|
-
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
2291
|
-
})
|
|
2292
|
-
]).describe(
|
|
2293
|
-
"Scopes used to check user's permission to perform actions on a record."
|
|
2294
|
-
);
|
|
2295
|
-
var SystemScopeType = z3.enum([
|
|
2296
|
-
"organisation.read-locations",
|
|
2297
|
-
"user.read",
|
|
2298
|
-
"user.create",
|
|
2299
|
-
"user.edit",
|
|
2300
|
-
"user.search"
|
|
2301
|
-
]);
|
|
2302
|
-
var UserScopeType = SystemScopeType.extract([
|
|
2303
|
-
"user.read",
|
|
2304
|
-
"user.create",
|
|
2305
|
-
"user.edit",
|
|
2306
|
-
"user.search"
|
|
2307
|
-
]);
|
|
2308
|
-
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2309
|
-
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2310
|
-
z3.object({
|
|
2311
|
-
type: ScopesWithRoleOption,
|
|
2312
|
-
options: AllUserScopeOptions.optional()
|
|
2313
|
-
}),
|
|
2314
|
-
z3.object({
|
|
2315
|
-
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2316
|
-
options: AccessLevelOptions.optional()
|
|
2317
|
-
})
|
|
2318
|
-
]);
|
|
2319
|
-
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2320
|
-
z3.object({
|
|
2321
|
-
type: ScopesWithPlaceEventOptions,
|
|
2322
|
-
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
2323
|
-
}),
|
|
2324
|
-
z3.object({
|
|
2325
|
-
type: ScopesWithDeclaredOptions,
|
|
2326
|
-
options: ResolvedScopeOptionsDeclared.optional()
|
|
2327
|
-
}),
|
|
2328
|
-
z3.object({
|
|
2329
|
-
type: ScopesWithFullOptions,
|
|
2330
|
-
options: ResolvedScopeOptionsFull.optional()
|
|
2331
|
-
}),
|
|
2332
|
-
z3.object({
|
|
2333
|
-
type: z3.literal("record.print-certified-copies"),
|
|
2334
|
-
options: ResolvedScopeOptionsFull.extend({
|
|
2335
|
-
templates: z3.array(z3.string()).optional()
|
|
2336
|
-
}).optional()
|
|
2337
|
-
})
|
|
2338
|
-
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2339
|
-
var Scope2 = z3.discriminatedUnion("type", [
|
|
2340
|
-
z3.object({ type: PlainScopeType }),
|
|
2341
|
-
...RecordScopeV2.options,
|
|
2342
|
-
...UserScopeV2.options,
|
|
2343
|
-
z3.object({
|
|
2344
|
-
type: z3.literal("organisation.read-locations"),
|
|
2345
|
-
options: AccessLevelOptions.optional()
|
|
2346
|
-
}),
|
|
2347
|
-
z3.object({
|
|
2348
|
-
type: z3.literal("workqueue"),
|
|
2349
|
-
options: WorkqueueOrDashboardOptions
|
|
2350
|
-
}),
|
|
2351
|
-
z3.object({
|
|
2352
|
-
type: z3.literal("dashboard.view"),
|
|
2353
|
-
options: WorkqueueOrDashboardOptions
|
|
2354
|
-
})
|
|
2355
|
-
]);
|
|
2356
|
-
var ScopeType2 = z3.enum([
|
|
2357
|
-
...SystemScopeType.options,
|
|
2358
|
-
...RecordScopeTypeV2.options,
|
|
2359
|
-
...PlainScopeType.options,
|
|
2360
|
-
"workqueue",
|
|
2361
|
-
"dashboard.view"
|
|
2362
|
-
]);
|
|
2363
|
-
var flattenScope = (scope) => ({
|
|
2364
|
-
type: scope.type,
|
|
2365
|
-
..."options" in scope ? scope.options : {}
|
|
2366
|
-
});
|
|
2367
|
-
var unflattenScope = (input) => {
|
|
2368
|
-
const { type, ...options } = input;
|
|
2369
|
-
return { type, options };
|
|
2370
|
-
};
|
|
2371
|
-
var EncodedScope2 = z3.string().brand("EncodedScope");
|
|
2372
|
-
var encodeScope = (scope) => {
|
|
2373
|
-
const flattened = flattenScope(scope);
|
|
2374
|
-
return qs.stringify(flattened, {
|
|
2375
|
-
arrayFormat: "comma",
|
|
2376
|
-
allowDots: true,
|
|
2377
|
-
addQueryPrefix: false,
|
|
2378
|
-
encode: false
|
|
2379
|
-
});
|
|
2380
|
-
};
|
|
2381
|
-
var decodeScope = (query) => {
|
|
2382
|
-
const scope = qs.parse(query, {
|
|
2383
|
-
ignoreQueryPrefix: true,
|
|
2384
|
-
comma: true,
|
|
2385
|
-
allowDots: true
|
|
2386
|
-
});
|
|
2387
|
-
const unflattenedScope = unflattenScope(scope);
|
|
2388
|
-
return Scope2.safeParse(unflattenedScope)?.data;
|
|
2389
|
-
};
|
|
2390
|
-
var DEFAULT_SCOPE_OPTIONS = {
|
|
2391
|
-
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2392
|
-
accessLevel: JurisdictionFilter.enum.all
|
|
2393
|
-
};
|
|
2394
|
-
|
|
2395
|
-
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2396
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2397
|
-
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2398
|
-
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2399
|
-
var SearchScope = z4.object({
|
|
2400
|
-
type: z4.literal("search"),
|
|
2401
|
-
options: z4.object({
|
|
2402
|
-
event: z4.array(z4.string()).length(1),
|
|
2403
|
-
access: z4.array(z4.enum(["my-jurisdiction", "all"])).length(1)
|
|
2404
|
-
})
|
|
2405
|
-
});
|
|
2406
|
-
var CreateUserScope = z4.object({
|
|
2407
|
-
type: z4.literal("user.create"),
|
|
2408
|
-
options: z4.object({
|
|
2409
|
-
role: z4.array(z4.string())
|
|
2410
|
-
})
|
|
2411
|
-
});
|
|
2412
|
-
var EditUserScope = z4.object({
|
|
2413
|
-
type: z4.literal("user.edit"),
|
|
2414
|
-
options: z4.object({
|
|
2415
|
-
role: z4.array(z4.string())
|
|
2416
|
-
})
|
|
2417
|
-
});
|
|
2418
|
-
var WorkqueueScope = z4.object({
|
|
2419
|
-
type: z4.literal("workqueue"),
|
|
2420
|
-
options: z4.object({
|
|
2421
|
-
id: z4.array(z4.string())
|
|
2422
|
-
})
|
|
2423
|
-
});
|
|
2424
|
-
var PrintCertifiedCopiesScope = z4.object({
|
|
2425
|
-
type: z4.literal("record.registered.print-certified-copies"),
|
|
2426
|
-
options: z4.object({
|
|
2427
|
-
event: z4.array(z4.string()).describe("Event type, e.g. birth, death"),
|
|
2428
|
-
templates: z4.array(z4.string()).optional().describe(
|
|
2429
|
-
"Template IDs for certified copies. If not provided, all templates will be used."
|
|
2430
|
-
)
|
|
2431
|
-
})
|
|
2432
|
-
});
|
|
2433
|
-
var LegacyRecordScope = z4.object({
|
|
2434
|
-
type: z4.enum([
|
|
2435
|
-
"record.create",
|
|
2436
|
-
"record.read",
|
|
2437
|
-
"record.declare",
|
|
2438
|
-
"record.notify",
|
|
2439
|
-
"record.declared.edit",
|
|
2440
|
-
"record.declared.validate",
|
|
2441
|
-
"record.declared.reject",
|
|
2442
|
-
"record.declared.archive",
|
|
2443
|
-
"record.declared.review-duplicates",
|
|
2444
|
-
"record.register",
|
|
2445
|
-
"record.registered.request-correction",
|
|
2446
|
-
"record.registered.correct",
|
|
2447
|
-
"record.unassign-others"
|
|
2448
|
-
]),
|
|
2449
|
-
options: z4.object({
|
|
2450
|
-
event: z4.array(z4.string()).describe("Event type, e.g. birth, death")
|
|
2451
|
-
})
|
|
2452
|
-
}).describe(
|
|
2453
|
-
"Scopes used to check user's permission to perform actions on a record."
|
|
2454
|
-
);
|
|
2455
|
-
var ConfigurableRawScopes = z4.discriminatedUnion("type", [
|
|
2456
|
-
SearchScope,
|
|
2457
|
-
LegacyRecordScope,
|
|
2458
|
-
PrintCertifiedCopiesScope,
|
|
2459
|
-
CreateUserScope,
|
|
2460
|
-
EditUserScope,
|
|
2461
|
-
WorkqueueScope
|
|
2462
|
-
]);
|
|
2463
|
-
function getScopeOptions(rawOptions) {
|
|
2464
|
-
return rawOptions.split(",").reduce((acc, option) => {
|
|
2465
|
-
const [key, value] = option.split("=");
|
|
2466
|
-
acc[key] = value.split("|");
|
|
2467
|
-
return acc;
|
|
2468
|
-
}, {});
|
|
2469
|
-
}
|
|
2470
|
-
function parseConfigurableScope(scope) {
|
|
2471
|
-
const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
|
|
2472
|
-
if (!maybeConfigurableScope.success) {
|
|
2473
|
-
return;
|
|
2474
|
-
}
|
|
2475
|
-
const rawScope = maybeConfigurableScope.data;
|
|
2476
|
-
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
|
2477
|
-
const options = getScopeOptions(rawOptions);
|
|
2478
|
-
const parsedScope = {
|
|
2479
|
-
type,
|
|
2480
|
-
options
|
|
2481
|
-
};
|
|
2482
|
-
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
|
2483
|
-
return result.success ? result.data : void 0;
|
|
2484
|
-
}
|
|
2485
|
-
var SCOPES = {
|
|
2486
|
-
BYPASSRATELIMIT: "bypassratelimit",
|
|
2487
|
-
RECORD_REINDEX: "record.reindex",
|
|
2488
|
-
RECORD_IMPORT: "record.import",
|
|
2489
|
-
ATTACHMENT_UPLOAD: "attachment.upload",
|
|
2490
|
-
USER_DATA_SEEDING: "user.data-seeding",
|
|
2491
|
-
INTEGRATION_CREATE: "integration.create",
|
|
2492
|
-
PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
|
|
2493
|
-
PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
|
|
2494
|
-
PERFORMANCE_READ: "performance.read",
|
|
2495
|
-
PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
|
|
2496
|
-
CONFIG_UPDATE_ALL: "config.update-all",
|
|
2497
|
-
ORGANISATION_READ_LOCATIONS: "organisation.read-locations",
|
|
2498
|
-
ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
|
|
2499
|
-
ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
|
|
2500
|
-
USER_CREATE: "user.create:all",
|
|
2501
|
-
USER_READ: "user.read:all",
|
|
2502
|
-
USER_UPDATE: "user.update:all",
|
|
2503
|
-
USER_READ_MY_OFFICE: "user.read:my-office",
|
|
2504
|
-
USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
|
|
2505
|
-
USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
|
|
2506
|
-
USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
|
|
2507
|
-
USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction"
|
|
2508
|
-
};
|
|
2509
|
-
var literalScopeToV2ScopeMap = {
|
|
2510
|
-
[SCOPES.BYPASSRATELIMIT]: { type: "bypassratelimit" },
|
|
2511
|
-
[SCOPES.RECORD_REINDEX]: { type: "record.reindex" },
|
|
2512
|
-
[SCOPES.RECORD_IMPORT]: { type: "record.import" },
|
|
2513
|
-
[SCOPES.ATTACHMENT_UPLOAD]: { type: "attachment.upload" },
|
|
2514
|
-
[SCOPES.USER_DATA_SEEDING]: { type: "user.data-seeding" },
|
|
2515
|
-
[SCOPES.INTEGRATION_CREATE]: { type: "integration.create" },
|
|
2516
|
-
[SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS]: {
|
|
2517
|
-
type: "performance.vital-statistics-export"
|
|
2518
|
-
},
|
|
2519
|
-
[SCOPES.PROFILE_ELECTRONIC_SIGNATURE]: {
|
|
2520
|
-
type: "profile.electronic-signature"
|
|
2521
|
-
},
|
|
2522
|
-
[SCOPES.PERFORMANCE_READ]: { type: "performance.read" },
|
|
2523
|
-
[SCOPES.PERFORMANCE_READ_DASHBOARDS]: { type: "performance.read-dashboards" },
|
|
2524
|
-
[SCOPES.CONFIG_UPDATE_ALL]: { type: "config.update-all" },
|
|
2525
|
-
[SCOPES.ORGANISATION_READ_LOCATIONS]: {
|
|
2526
|
-
type: "organisation.read-locations"
|
|
2527
|
-
},
|
|
2528
|
-
[SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE]: {
|
|
2529
|
-
type: "organisation.read-locations",
|
|
2530
|
-
options: { accessLevel: "location" }
|
|
2531
|
-
},
|
|
2532
|
-
[SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION]: {
|
|
2533
|
-
type: "organisation.read-locations",
|
|
2534
|
-
options: { accessLevel: "administrativeArea" }
|
|
2535
|
-
},
|
|
2536
|
-
[SCOPES.USER_CREATE]: { type: "user.create" },
|
|
2537
|
-
[SCOPES.USER_CREATE_MY_JURISDICTION]: {
|
|
2538
|
-
type: "user.create",
|
|
2539
|
-
options: { accessLevel: "administrativeArea" }
|
|
2540
|
-
},
|
|
2541
|
-
[SCOPES.USER_READ]: { type: "user.read" },
|
|
2542
|
-
[SCOPES.USER_READ_MY_OFFICE]: {
|
|
2543
|
-
type: "user.read",
|
|
2544
|
-
options: { accessLevel: "location" }
|
|
2545
|
-
},
|
|
2546
|
-
[SCOPES.USER_READ_MY_JURISDICTION]: {
|
|
2547
|
-
type: "user.read",
|
|
2548
|
-
options: { accessLevel: "administrativeArea" }
|
|
2549
|
-
},
|
|
2550
|
-
[SCOPES.USER_READ_ONLY_MY_AUDIT]: { type: "user.read-only-my-audit" },
|
|
2551
|
-
[SCOPES.USER_UPDATE]: { type: "user.edit" },
|
|
2552
|
-
[SCOPES.USER_UPDATE_MY_JURISDICTION]: {
|
|
2553
|
-
type: "user.edit",
|
|
2554
|
-
options: { accessLevel: "administrativeArea" }
|
|
2555
|
-
}
|
|
2556
|
-
};
|
|
2557
|
-
function parseLiteralScope(scope) {
|
|
2558
|
-
if (scope in literalScopeToV2ScopeMap) {
|
|
2559
|
-
return literalScopeToV2ScopeMap[scope];
|
|
2560
|
-
}
|
|
2561
|
-
return void 0;
|
|
2562
|
-
}
|
|
2563
|
-
var v1ToV2ConfigScopeTypeMap = {
|
|
2564
|
-
search: "record.search",
|
|
2565
|
-
workqueue: "workqueue",
|
|
2566
|
-
"user.create": "user.create",
|
|
2567
|
-
"user.edit": "user.edit",
|
|
2568
|
-
"record.create": "record.create",
|
|
2569
|
-
"record.read": "record.read",
|
|
2570
|
-
"record.declare": "record.declare",
|
|
2571
|
-
"record.notify": "record.notify",
|
|
2572
|
-
"record.register": "record.register",
|
|
2573
|
-
"record.unassign-others": "record.unassign-others",
|
|
2574
|
-
"record.declared.reject": "record.reject",
|
|
2575
|
-
"record.declared.archive": "record.archive",
|
|
2576
|
-
"record.declared.review-duplicates": "record.review-duplicates",
|
|
2577
|
-
"record.registered.print-certified-copies": "record.print-certified-copies",
|
|
2578
|
-
"record.registered.request-correction": "record.request-correction",
|
|
2579
|
-
"record.registered.correct": "record.correct",
|
|
2580
|
-
"record.declared.edit": "record.edit",
|
|
2581
|
-
"record.declared.validate": "record.custom-action"
|
|
2582
|
-
};
|
|
2583
|
-
var legacyScopeToV2Scope = (v1Scope) => {
|
|
2584
|
-
const configurableV1Scope = parseConfigurableScope(v1Scope);
|
|
2585
|
-
const literalV1Scope = parseLiteralScope(v1Scope);
|
|
2586
|
-
if (!configurableV1Scope && !literalV1Scope) {
|
|
2587
|
-
throw new Error(`Invalid V1 scope: ${v1Scope}`);
|
|
2588
|
-
}
|
|
2589
|
-
if (literalV1Scope) {
|
|
2590
|
-
return encodeScope(literalV1Scope);
|
|
2591
|
-
}
|
|
2592
|
-
if (configurableV1Scope) {
|
|
2593
|
-
const type = v1ToV2ConfigScopeTypeMap[configurableV1Scope.type];
|
|
2594
|
-
if (type === void 0) {
|
|
2595
|
-
throw new Error(`Unsupported V1 scope type: ${configurableV1Scope.type}`);
|
|
2596
|
-
}
|
|
2597
|
-
if (configurableV1Scope.type === "workqueue") {
|
|
2598
|
-
return encodeScope({
|
|
2599
|
-
type: "workqueue",
|
|
2600
|
-
options: {
|
|
2601
|
-
ids: configurableV1Scope.options.id || []
|
|
2602
|
-
}
|
|
2603
|
-
});
|
|
2604
|
-
}
|
|
2605
|
-
if (configurableV1Scope.type === "search") {
|
|
2606
|
-
return encodeScope({
|
|
2607
|
-
type,
|
|
2608
|
-
options: {
|
|
2609
|
-
event: configurableV1Scope.options.event || [],
|
|
2610
|
-
placeOfEvent: configurableV1Scope.options.access[0] === "my-jurisdiction" ? "administrativeArea" : "all"
|
|
2611
|
-
}
|
|
2612
|
-
});
|
|
2613
|
-
}
|
|
2614
|
-
if (configurableV1Scope.type === "record.declared.validate") {
|
|
2615
|
-
return encodeScope({
|
|
2616
|
-
type: "record.custom-action",
|
|
2617
|
-
options: {
|
|
2618
|
-
event: configurableV1Scope.options.event,
|
|
2619
|
-
customActionTypes: ["VALIDATE_DECLARATION"]
|
|
2620
|
-
}
|
|
2621
|
-
});
|
|
2622
|
-
}
|
|
2623
|
-
return encodeScope({
|
|
2624
|
-
type,
|
|
2625
|
-
options: configurableV1Scope.options
|
|
2626
|
-
});
|
|
2627
|
-
}
|
|
2628
|
-
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2629
|
-
};
|
|
2630
|
-
|
|
2631
|
-
// src/migrations/v2.0/migrate-scopes.ts
|
|
2632
|
-
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
2633
|
-
var SCOPES_PROPERTY_NAME = "scopes";
|
|
2634
|
-
var TOOLKIT_SCOPES_MODULE = "@opencrvs/toolkit/scopes";
|
|
2635
|
-
var DEFINE_SCOPES_IMPORT_NAME = "defineScopes";
|
|
2636
|
-
var DEFINE_ROLES_IMPORT_NAME = "defineRoles";
|
|
2637
|
-
function resolveScopeKeyFromElementAccess(element) {
|
|
2638
|
-
if (import_ts_morph11.Node.isPropertyAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
|
|
2639
|
-
return element.getName();
|
|
2640
|
-
}
|
|
2641
|
-
if (import_ts_morph11.Node.isElementAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
|
|
2642
|
-
const argumentExpression = element.getArgumentExpression();
|
|
2643
|
-
if (argumentExpression && (import_ts_morph11.Node.isStringLiteral(argumentExpression) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
|
|
2644
|
-
return argumentExpression.getLiteralValue();
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
return null;
|
|
2648
|
-
}
|
|
2649
|
-
function resolveLegacyScopeFromElement(element) {
|
|
2650
|
-
if (import_ts_morph11.Node.isStringLiteral(element) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(element)) {
|
|
2651
|
-
return element.getLiteralValue();
|
|
2652
|
-
}
|
|
2653
|
-
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2654
|
-
if (scopeKey) {
|
|
2655
|
-
const scopeValue = SCOPES[scopeKey];
|
|
2656
|
-
return typeof scopeValue === "string" ? scopeValue : null;
|
|
2657
|
-
}
|
|
2658
|
-
const expressionType = element.getType();
|
|
2659
|
-
if (expressionType.isStringLiteral()) {
|
|
2660
|
-
const literalValue = expressionType.getLiteralValue();
|
|
2661
|
-
return typeof literalValue === "string" ? literalValue : null;
|
|
2662
|
-
}
|
|
2663
|
-
return null;
|
|
2664
|
-
}
|
|
2665
|
-
function migrateScopesArrays(rolesFilePath, project) {
|
|
2666
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2667
|
-
if (!sourceFile) return { migratedCount: 0, removedCount: 0 };
|
|
2668
|
-
let migratedCount = 0;
|
|
2669
|
-
let removedCount = 0;
|
|
2670
|
-
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2671
|
-
for (const scopesProp of scopesProperties) {
|
|
2672
|
-
const initializer = scopesProp.getInitializer();
|
|
2673
|
-
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2674
|
-
const elements = initializer.getElements();
|
|
2675
|
-
for (let index = elements.length - 1; index >= 0; index--) {
|
|
2676
|
-
const element = elements[index];
|
|
2677
|
-
if (!import_ts_morph11.Node.isExpression(element)) continue;
|
|
2678
|
-
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2679
|
-
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2680
|
-
console.warn(
|
|
2681
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2682
|
-
);
|
|
2683
|
-
initializer.removeElement(index);
|
|
2684
|
-
removedCount++;
|
|
2685
|
-
continue;
|
|
2686
|
-
}
|
|
2687
|
-
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2688
|
-
if (!legacyScope) {
|
|
2689
|
-
console.warn(
|
|
2690
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2691
|
-
);
|
|
2692
|
-
continue;
|
|
2693
|
-
}
|
|
2694
|
-
try {
|
|
2695
|
-
const migratedScope = legacyScopeToV2Scope(legacyScope);
|
|
2696
|
-
const scope = decodeScope(migratedScope);
|
|
2697
|
-
if (!scope) {
|
|
2698
|
-
console.warn(
|
|
2699
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2700
|
-
);
|
|
2701
|
-
continue;
|
|
2702
|
-
}
|
|
2703
|
-
element.replaceWithText(JSON.stringify(scope));
|
|
2704
|
-
migratedCount++;
|
|
2705
|
-
} catch (error) {
|
|
2706
|
-
console.warn(
|
|
2707
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2708
|
-
);
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
if (removedCount > 0) {
|
|
2713
|
-
console.log(
|
|
2714
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2715
|
-
);
|
|
2716
|
-
}
|
|
2717
|
-
return { migratedCount, removedCount };
|
|
2718
|
-
}
|
|
2719
|
-
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2720
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2721
|
-
if (!sourceFile) return false;
|
|
2722
|
-
const existingImport = sourceFile.getImportDeclaration(
|
|
2723
|
-
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE
|
|
2724
|
-
);
|
|
2725
|
-
let changed = false;
|
|
2726
|
-
if (existingImport) {
|
|
2727
|
-
const hasDefineScopesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
|
|
2728
|
-
const hasDefineRolesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
|
|
2729
|
-
if (!hasDefineScopesImport) {
|
|
2730
|
-
existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
|
|
2731
|
-
changed = true;
|
|
2732
|
-
}
|
|
2733
|
-
if (!hasDefineRolesImport) {
|
|
2734
|
-
existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
|
|
2735
|
-
changed = true;
|
|
2736
|
-
}
|
|
2737
|
-
const encodeScopeImport = existingImport.getNamedImports().find((ni) => ni.getName() === "encodeScope");
|
|
2738
|
-
if (encodeScopeImport) {
|
|
2739
|
-
encodeScopeImport.remove();
|
|
2740
|
-
changed = true;
|
|
2741
|
-
}
|
|
2742
|
-
return changed;
|
|
2743
|
-
}
|
|
2744
|
-
sourceFile.addImportDeclaration({
|
|
2745
|
-
moduleSpecifier: TOOLKIT_SCOPES_MODULE,
|
|
2746
|
-
namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
|
|
2747
|
-
});
|
|
2748
|
-
return true;
|
|
2749
|
-
}
|
|
2750
|
-
function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
|
|
2751
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2752
|
-
if (!sourceFile) return 0;
|
|
2753
|
-
let wrappedCount = 0;
|
|
2754
|
-
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2755
|
-
for (const scopesProp of scopesProperties) {
|
|
2756
|
-
const initializer = scopesProp.getInitializer();
|
|
2757
|
-
if (!initializer) continue;
|
|
2758
|
-
if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
|
|
2759
|
-
continue;
|
|
2760
|
-
}
|
|
2761
|
-
if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2762
|
-
scopesProp.setInitializer(
|
|
2763
|
-
`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`
|
|
2764
|
-
);
|
|
2765
|
-
wrappedCount++;
|
|
2766
|
-
}
|
|
2767
|
-
return wrappedCount;
|
|
2768
|
-
}
|
|
2769
|
-
function wrapRolesWithDefineRoles(rolesFilePath, project) {
|
|
2770
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2771
|
-
if (!sourceFile) return false;
|
|
2772
|
-
const rolesDeclaration = sourceFile.getVariableDeclaration("roles");
|
|
2773
|
-
if (!rolesDeclaration) return false;
|
|
2774
|
-
const initializer = rolesDeclaration.getInitializer();
|
|
2775
|
-
if (!initializer) return false;
|
|
2776
|
-
if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
|
|
2777
|
-
return false;
|
|
2778
|
-
}
|
|
2779
|
-
if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) return false;
|
|
2780
|
-
const typeNode = rolesDeclaration.getTypeNode();
|
|
2781
|
-
if (typeNode?.getText().includes("Role")) {
|
|
2782
|
-
rolesDeclaration.removeType();
|
|
2783
|
-
}
|
|
2784
|
-
rolesDeclaration.setInitializer(
|
|
2785
|
-
`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`
|
|
2786
|
-
);
|
|
2787
|
-
return true;
|
|
2788
|
-
}
|
|
2789
|
-
function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
|
|
2790
|
-
const importDeclaration = sourceFile.getImportDeclaration(
|
|
2791
|
-
(decl) => decl.getModuleSpecifierValue() === moduleSpecifier
|
|
2792
|
-
);
|
|
2793
|
-
if (!importDeclaration) return false;
|
|
2794
|
-
const namedImport = importDeclaration.getNamedImports().find((ni) => ni.getName() === importName);
|
|
2795
|
-
if (!namedImport) return false;
|
|
2796
|
-
const references = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.Identifier).filter(
|
|
2797
|
-
(identifier) => identifier.getText() === importName && !import_ts_morph11.Node.isImportSpecifier(identifier.getParent())
|
|
2798
|
-
);
|
|
2799
|
-
if (references.length > 0) {
|
|
2800
|
-
return false;
|
|
2801
|
-
}
|
|
2802
|
-
namedImport.remove();
|
|
2803
|
-
if (importDeclaration.getNamedImports().length === 0 && !importDeclaration.getDefaultImport() && !importDeclaration.getNamespaceImport()) {
|
|
2804
|
-
importDeclaration.remove();
|
|
2805
|
-
}
|
|
2806
|
-
return true;
|
|
2807
|
-
}
|
|
2808
|
-
function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
2809
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2810
|
-
if (!sourceFile) return false;
|
|
2811
|
-
let removed = false;
|
|
2812
|
-
const roleTypeAlias = sourceFile.getTypeAlias("Role");
|
|
2813
|
-
if (roleTypeAlias) {
|
|
2814
|
-
roleTypeAlias.remove();
|
|
2815
|
-
removed = true;
|
|
2816
|
-
}
|
|
2817
|
-
const roleInterface = sourceFile.getInterface("Role");
|
|
2818
|
-
if (roleInterface) {
|
|
2819
|
-
roleInterface.remove();
|
|
2820
|
-
removed = true;
|
|
2821
|
-
}
|
|
2822
|
-
const removedScopeImport = pruneNamedImportIfUnused(
|
|
2823
|
-
sourceFile,
|
|
2824
|
-
TOOLKIT_SCOPES_MODULE,
|
|
2825
|
-
"Scope"
|
|
2826
|
-
);
|
|
2827
|
-
const removedMessageDescriptorImport = pruneNamedImportIfUnused(
|
|
2828
|
-
sourceFile,
|
|
2829
|
-
"react-intl",
|
|
2830
|
-
"MessageDescriptor"
|
|
2831
|
-
);
|
|
2832
|
-
removed = removed || removedScopeImport || removedMessageDescriptorImport;
|
|
2833
|
-
return removed;
|
|
2834
|
-
}
|
|
2835
|
-
async function main11() {
|
|
2836
|
-
const cwd = process.cwd();
|
|
2837
|
-
const srcDir = import_path11.default.join(cwd, "src");
|
|
2838
|
-
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2839
|
-
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2840
|
-
const project = new import_ts_morph11.Project({
|
|
2841
|
-
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
2842
|
-
skipAddingFilesFromTsConfig: false
|
|
2843
|
-
});
|
|
2844
|
-
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2845
|
-
if (!sourceFile) {
|
|
2846
|
-
console.log(
|
|
2847
|
-
`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`
|
|
2848
|
-
);
|
|
2849
|
-
return;
|
|
2850
|
-
}
|
|
2851
|
-
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2852
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2853
|
-
rolesFilePath,
|
|
2854
|
-
project
|
|
2855
|
-
);
|
|
2856
|
-
const wrappedScopesCount = wrapScopesArraysWithDefineScopes(
|
|
2857
|
-
rolesFilePath,
|
|
2858
|
-
project
|
|
2859
|
-
);
|
|
2860
|
-
const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
|
|
2861
|
-
const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(
|
|
2862
|
-
rolesFilePath,
|
|
2863
|
-
project
|
|
2864
|
-
);
|
|
2865
|
-
if (migratedCount === 0 && removedCount === 0 && wrappedScopesCount === 0 && !wrappedRoles && !removedRoleType && !importChanged) {
|
|
2866
|
-
console.log("No migratable literal scopes found. Nothing to do.");
|
|
2867
|
-
return;
|
|
2868
|
-
}
|
|
2869
|
-
await sourceFile.save();
|
|
2870
|
-
console.log(
|
|
2871
|
-
`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." : "."}`
|
|
2872
|
-
);
|
|
2873
|
-
}
|
|
2874
|
-
|
|
2875
|
-
// src/migrations/v2.0/remove-deprecated-imports.ts
|
|
2876
|
-
var import_ts_morph12 = require("ts-morph");
|
|
2877
|
-
var import_path12 = __toESM(require("path"));
|
|
2878
|
-
var DEPRECATED_IMPORT = "SCOPES";
|
|
2879
|
-
var TARGET_MODULES = /* @__PURE__ */ new Set([
|
|
2880
|
-
"@opencrvs/toolkit/scopes",
|
|
2881
|
-
"@opencrvs/toolkit"
|
|
2882
|
-
]);
|
|
2883
|
-
function processFile10(filePath, project) {
|
|
2884
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
2885
|
-
if (!sourceFile) return 0;
|
|
2886
|
-
let removedCount = 0;
|
|
2887
|
-
const importDecls = sourceFile.getImportDeclarations().filter((decl) => TARGET_MODULES.has(decl.getModuleSpecifierValue()));
|
|
2888
|
-
for (const decl of importDecls) {
|
|
2889
|
-
const matchingNamedImports = decl.getNamedImports().filter((ni) => ni.getName() === DEPRECATED_IMPORT);
|
|
2890
|
-
if (matchingNamedImports.length === 0) continue;
|
|
2891
|
-
for (const namedImport of matchingNamedImports) {
|
|
2892
|
-
namedImport.remove();
|
|
2893
|
-
removedCount++;
|
|
2894
|
-
}
|
|
2895
|
-
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
2896
|
-
const hasDefaultImport = !!decl.getDefaultImport();
|
|
2897
|
-
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
2898
|
-
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
2899
|
-
decl.remove();
|
|
2900
|
-
}
|
|
2901
|
-
console.log(
|
|
2902
|
-
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2903
|
-
);
|
|
2904
|
-
}
|
|
2905
|
-
return removedCount;
|
|
2906
|
-
}
|
|
2907
|
-
async function main12() {
|
|
2908
|
-
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2909
|
-
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2910
|
-
`);
|
|
2911
|
-
const project = new import_ts_morph12.Project({
|
|
2912
|
-
tsConfigFilePath: import_path12.default.resolve(srcDir, "../tsconfig.json"),
|
|
2913
|
-
skipAddingFilesFromTsConfig: false
|
|
2914
|
-
});
|
|
2915
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
2916
|
-
const fp = sf.getFilePath();
|
|
2917
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
2918
|
-
});
|
|
2919
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
2920
|
-
`);
|
|
2921
|
-
let totalRemoved = 0;
|
|
2922
|
-
const modifiedFiles = [];
|
|
2923
|
-
for (const sourceFile of sourceFiles) {
|
|
2924
|
-
const filePath = sourceFile.getFilePath();
|
|
2925
|
-
const removed = processFile10(filePath, project);
|
|
2926
|
-
if (removed > 0) {
|
|
2927
|
-
totalRemoved += removed;
|
|
2928
|
-
modifiedFiles.push(filePath);
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
if (modifiedFiles.length === 0) {
|
|
2932
|
-
console.log("No deprecated imports found. Nothing to do.");
|
|
2933
|
-
return;
|
|
2934
|
-
}
|
|
2935
|
-
console.log(`
|
|
2936
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2937
|
-
for (const filePath of modifiedFiles) {
|
|
2938
|
-
await project.getSourceFileOrThrow(filePath).save();
|
|
2939
|
-
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2940
|
-
}
|
|
2941
|
-
console.log(`
|
|
2942
|
-
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2943
|
-
}
|
|
2944
|
-
|
|
2945
|
-
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2946
|
-
var import_path13 = __toESM(require("path"));
|
|
2947
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2948
|
-
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2949
|
-
"APPLICATION_CONFIG_URL",
|
|
2950
|
-
"FHIR_URL",
|
|
2951
|
-
"CONFIRM_REGISTRATION_URL"
|
|
2952
|
-
]);
|
|
2953
|
-
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2954
|
-
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2955
|
-
function cleanEnvironmentFile(project, filePath) {
|
|
2956
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
2957
|
-
if (!sourceFile) return [];
|
|
2958
|
-
const removed = [];
|
|
2959
|
-
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2960
|
-
const expr = call.getExpression();
|
|
2961
|
-
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2962
|
-
});
|
|
2963
|
-
if (!cleanEnvCall) return removed;
|
|
2964
|
-
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2965
|
-
if (!schemaArg) return removed;
|
|
2966
|
-
for (const name of UNUSED_ENV_VARS) {
|
|
2967
|
-
const prop = schemaArg.getProperty(name);
|
|
2968
|
-
if (!prop) continue;
|
|
2969
|
-
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2970
|
-
prop.remove();
|
|
2971
|
-
removed.push(name);
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
return removed;
|
|
2975
|
-
}
|
|
2976
|
-
function extractEnvAccess(initText) {
|
|
2977
|
-
if (!initText) return null;
|
|
2978
|
-
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2979
|
-
return match ? match[1] : null;
|
|
2980
|
-
}
|
|
2981
|
-
function cleanConstantsFile(project, filePath) {
|
|
2982
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
2983
|
-
if (!sourceFile) return [];
|
|
2984
|
-
const removed = [];
|
|
2985
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2986
|
-
const declarations = [...stmt.getDeclarations()];
|
|
2987
|
-
const declarationsToRemove = declarations.filter((decl) => {
|
|
2988
|
-
const name = decl.getName();
|
|
2989
|
-
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2990
|
-
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2991
|
-
});
|
|
2992
|
-
if (declarationsToRemove.length === 0) continue;
|
|
2993
|
-
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2994
|
-
removed.push(...namesToRemove);
|
|
2995
|
-
if (declarationsToRemove.length === declarations.length) {
|
|
2996
|
-
stmt.remove();
|
|
2997
|
-
} else {
|
|
2998
|
-
for (const decl of declarationsToRemove) {
|
|
2999
|
-
decl.remove();
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
return removed;
|
|
3004
|
-
}
|
|
3005
|
-
async function main13() {
|
|
3006
|
-
const project = new import_ts_morph13.Project({
|
|
3007
|
-
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3008
|
-
skipAddingFilesFromTsConfig: false
|
|
3009
|
-
});
|
|
3010
|
-
console.log(
|
|
3011
|
-
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
3012
|
-
`
|
|
3013
|
-
);
|
|
3014
|
-
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
3015
|
-
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
3016
|
-
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
3017
|
-
if (envRemoved.length > 0) {
|
|
3018
|
-
await project.getSourceFileOrThrow(envFilePath).save();
|
|
3019
|
-
console.log(
|
|
3020
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
3021
|
-
);
|
|
3022
|
-
} else if (project.getSourceFile(envFilePath)) {
|
|
3023
|
-
console.log(
|
|
3024
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
3025
|
-
);
|
|
3026
|
-
} else {
|
|
3027
|
-
console.log(
|
|
3028
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
3029
|
-
);
|
|
3030
|
-
}
|
|
3031
|
-
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
3032
|
-
if (constsRemoved.length > 0) {
|
|
3033
|
-
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
3034
|
-
console.log(
|
|
3035
|
-
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
3036
|
-
);
|
|
3037
|
-
} else if (project.getSourceFile(constsFilePath)) {
|
|
3038
|
-
console.log(
|
|
3039
|
-
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
3040
|
-
);
|
|
3041
|
-
} else {
|
|
3042
|
-
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
3043
|
-
}
|
|
3044
|
-
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
3045
|
-
console.log("\nNothing to do.");
|
|
3046
|
-
return;
|
|
3047
|
-
}
|
|
3048
|
-
console.log(
|
|
3049
|
-
`
|
|
3050
|
-
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
3051
|
-
);
|
|
3052
|
-
}
|
|
3053
|
-
|
|
3054
|
-
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
3055
|
-
var import_path14 = __toESM(require("path"));
|
|
3056
|
-
var import_ts_morph14 = require("ts-morph");
|
|
3057
|
-
var FHIR_IMPORT = "FHIR_URL";
|
|
3058
|
-
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
3059
|
-
"getFromFhir",
|
|
3060
|
-
"updateResourceFromHearth",
|
|
3061
|
-
"updateResourceInHearth"
|
|
3062
|
-
]);
|
|
3063
|
-
function removeHelpers(sourceFilePath, project) {
|
|
3064
|
-
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
3065
|
-
if (!sourceFile) {
|
|
3066
|
-
return {
|
|
3067
|
-
removedHelpers: [],
|
|
3068
|
-
removedImportCount: 0,
|
|
3069
|
-
remainingFhirReferences: 0
|
|
3070
|
-
};
|
|
3071
|
-
}
|
|
3072
|
-
const removedHelpers = [];
|
|
3073
|
-
let removedImportCount = 0;
|
|
3074
|
-
for (const fn of sourceFile.getFunctions()) {
|
|
3075
|
-
const name = fn.getName();
|
|
3076
|
-
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3077
|
-
removedHelpers.push(name);
|
|
3078
|
-
fn.remove();
|
|
3079
|
-
}
|
|
3080
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3081
|
-
const declarations = [...stmt.getDeclarations()];
|
|
3082
|
-
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3083
|
-
if (toRemove.length === 0) continue;
|
|
3084
|
-
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3085
|
-
if (toRemove.length === declarations.length) {
|
|
3086
|
-
stmt.remove();
|
|
3087
|
-
} else {
|
|
3088
|
-
for (const decl of toRemove) decl.remove();
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3092
|
-
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3093
|
-
if (matches.length === 0) continue;
|
|
3094
|
-
for (const named of matches) {
|
|
3095
|
-
named.remove();
|
|
3096
|
-
removedImportCount++;
|
|
3097
|
-
}
|
|
3098
|
-
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3099
|
-
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3100
|
-
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3101
|
-
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3102
|
-
decl.remove();
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
const remainingFhirReferences = sourceFile.getDescendantsOfKind(import_ts_morph14.SyntaxKind.Identifier).filter((id) => id.getText() === FHIR_IMPORT).filter((id) => !id.getFirstAncestorByKind(import_ts_morph14.SyntaxKind.ImportDeclaration)).length;
|
|
3106
|
-
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3107
|
-
}
|
|
3108
|
-
async function main14() {
|
|
3109
|
-
const project = new import_ts_morph14.Project({
|
|
3110
|
-
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3111
|
-
skipAddingFilesFromTsConfig: false
|
|
3112
|
-
});
|
|
3113
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3114
|
-
const fp = sf.getFilePath();
|
|
3115
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3116
|
-
});
|
|
3117
|
-
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3118
|
-
`);
|
|
3119
|
-
let totalRemovedImports = 0;
|
|
3120
|
-
let totalRemovedHelpers = 0;
|
|
3121
|
-
const modifiedFiles = [];
|
|
3122
|
-
const warnings = [];
|
|
3123
|
-
for (const sourceFile of sourceFiles) {
|
|
3124
|
-
const filePath = sourceFile.getFilePath();
|
|
3125
|
-
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3126
|
-
const result = removeHelpers(filePath, project);
|
|
3127
|
-
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3128
|
-
if (changed) {
|
|
3129
|
-
modifiedFiles.push(filePath);
|
|
3130
|
-
totalRemovedImports += result.removedImportCount;
|
|
3131
|
-
totalRemovedHelpers += result.removedHelpers.length;
|
|
3132
|
-
if (result.removedHelpers.length > 0) {
|
|
3133
|
-
console.log(
|
|
3134
|
-
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3135
|
-
);
|
|
3136
|
-
}
|
|
3137
|
-
if (result.removedImportCount > 0) {
|
|
3138
|
-
console.log(
|
|
3139
|
-
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3140
|
-
);
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
if (result.remainingFhirReferences > 0) {
|
|
3144
|
-
warnings.push(
|
|
3145
|
-
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3146
|
-
);
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3150
|
-
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3151
|
-
return;
|
|
3152
|
-
}
|
|
3153
|
-
if (modifiedFiles.length > 0) {
|
|
3154
|
-
console.log(`
|
|
3155
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3156
|
-
for (const filePath of modifiedFiles) {
|
|
3157
|
-
await project.getSourceFileOrThrow(filePath).save();
|
|
3158
|
-
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3159
|
-
}
|
|
3160
|
-
}
|
|
3161
|
-
if (warnings.length > 0) {
|
|
3162
|
-
console.warn(
|
|
3163
|
-
`
|
|
3164
|
-
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3165
|
-
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3166
|
-
);
|
|
3167
|
-
}
|
|
3168
|
-
console.log(
|
|
3169
|
-
`
|
|
3170
|
-
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3171
|
-
);
|
|
3172
|
-
}
|
|
3173
|
-
|
|
3174
|
-
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3175
|
-
var import_path15 = __toESM(require("path"));
|
|
3176
|
-
var import_ts_morph15 = require("ts-morph");
|
|
3177
|
-
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3178
|
-
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3179
|
-
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3180
|
-
var FUNCTION_LIKE_KINDS = [
|
|
3181
|
-
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3182
|
-
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3183
|
-
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3184
|
-
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3185
|
-
];
|
|
3186
|
-
function describeFunction(node) {
|
|
3187
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3188
|
-
return node.getName() ?? "<anonymous>";
|
|
3189
|
-
}
|
|
3190
|
-
const parent = node.getParent();
|
|
3191
|
-
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3192
|
-
return parent.getName();
|
|
3193
|
-
}
|
|
3194
|
-
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3195
|
-
return parent.getName();
|
|
3196
|
-
}
|
|
3197
|
-
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3198
|
-
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3199
|
-
}
|
|
3200
|
-
return "<anonymous>";
|
|
3201
|
-
}
|
|
3202
|
-
function hasBlockBody(node) {
|
|
3203
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3204
|
-
return node.getBody() !== void 0;
|
|
3205
|
-
}
|
|
3206
|
-
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3207
|
-
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3208
|
-
}
|
|
3209
|
-
return false;
|
|
3210
|
-
}
|
|
3211
|
-
function isConfigFetcher(node) {
|
|
3212
|
-
let referencesTarget = false;
|
|
3213
|
-
let callsFetch = false;
|
|
3214
|
-
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3215
|
-
const text = id.getText();
|
|
3216
|
-
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3217
|
-
if (!callsFetch && text === "fetch") {
|
|
3218
|
-
const parent = id.getParent();
|
|
3219
|
-
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3220
|
-
callsFetch = true;
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
if (referencesTarget && callsFetch) return true;
|
|
3224
|
-
}
|
|
3225
|
-
return false;
|
|
3226
|
-
}
|
|
3227
|
-
function processFile11(sourceFile) {
|
|
3228
|
-
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3229
|
-
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3230
|
-
);
|
|
3231
|
-
if (importsWithTarget.length === 0) {
|
|
3232
|
-
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3233
|
-
}
|
|
3234
|
-
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3235
|
-
const parent = id.getParent();
|
|
3236
|
-
const kind = parent.getKind();
|
|
3237
|
-
return kind === import_ts_morph15.SyntaxKind.VariableDeclaration || kind === import_ts_morph15.SyntaxKind.FunctionDeclaration || kind === import_ts_morph15.SyntaxKind.ClassDeclaration || kind === import_ts_morph15.SyntaxKind.Parameter;
|
|
3238
|
-
});
|
|
3239
|
-
if (collidingLocals.length > 0) {
|
|
3240
|
-
return {
|
|
3241
|
-
changed: false,
|
|
3242
|
-
rewrittenFunctions: [],
|
|
3243
|
-
renamedReferences: 0,
|
|
3244
|
-
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3245
|
-
};
|
|
3246
|
-
}
|
|
3247
|
-
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3248
|
-
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3249
|
-
);
|
|
3250
|
-
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3251
|
-
const rewrittenFunctions = [];
|
|
3252
|
-
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3253
|
-
for (const fn of candidateFunctions) {
|
|
3254
|
-
if (!hasBlockBody(fn)) continue;
|
|
3255
|
-
if (!isConfigFetcher(fn)) continue;
|
|
3256
|
-
let inRewrittenAncestor = false;
|
|
3257
|
-
let cursor = fn.getParent();
|
|
3258
|
-
while (cursor) {
|
|
3259
|
-
if (rewrittenSet.has(cursor)) {
|
|
3260
|
-
inRewrittenAncestor = true;
|
|
3261
|
-
break;
|
|
3262
|
-
}
|
|
3263
|
-
cursor = cursor.getParent();
|
|
3264
|
-
}
|
|
3265
|
-
if (inRewrittenAncestor) continue;
|
|
3266
|
-
const start = fn.getStart();
|
|
3267
|
-
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3268
|
-
const name = describeFunction(fn);
|
|
3269
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(fn) || import_ts_morph15.Node.isFunctionExpression(fn) || import_ts_morph15.Node.isMethodDeclaration(fn) || import_ts_morph15.Node.isArrowFunction(fn)) {
|
|
3270
|
-
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3271
|
-
}
|
|
3272
|
-
rewrittenFunctions.push({ name, line });
|
|
3273
|
-
rewrittenSet.add(fn);
|
|
3274
|
-
}
|
|
3275
|
-
for (const decl of importsWithTarget) {
|
|
3276
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3277
|
-
targetNamed?.remove();
|
|
3278
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3279
|
-
if (isNowEmpty) decl.remove();
|
|
3280
|
-
}
|
|
3281
|
-
const existing = sourceFile.getImportDeclaration(
|
|
3282
|
-
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3283
|
-
);
|
|
3284
|
-
if (existing) {
|
|
3285
|
-
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3286
|
-
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3287
|
-
} else {
|
|
3288
|
-
sourceFile.addImportDeclaration({
|
|
3289
|
-
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3290
|
-
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3291
|
-
});
|
|
3292
|
-
}
|
|
3293
|
-
const renameTargets = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === TARGET_IDENTIFIER).filter((id) => !id.getFirstAncestorByKind(import_ts_morph15.SyntaxKind.ImportDeclaration)).filter((id) => {
|
|
3294
|
-
const parent = id.getParent();
|
|
3295
|
-
const parentKind = parent.getKind();
|
|
3296
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3297
|
-
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3298
|
-
if (pae.getNameNode() === id) return false;
|
|
3299
|
-
}
|
|
3300
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3301
|
-
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3302
|
-
if (pa.getNameNode() === id) return false;
|
|
3303
|
-
}
|
|
3304
|
-
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3305
|
-
return false;
|
|
3306
|
-
}
|
|
3307
|
-
return true;
|
|
3308
|
-
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3309
|
-
for (const id of renameTargets) {
|
|
3310
|
-
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3311
|
-
}
|
|
3312
|
-
return {
|
|
3313
|
-
changed: true,
|
|
3314
|
-
rewrittenFunctions,
|
|
3315
|
-
renamedReferences: renameTargets.length
|
|
3316
|
-
};
|
|
3317
|
-
}
|
|
3318
|
-
async function main15() {
|
|
3319
|
-
const project = new import_ts_morph15.Project({
|
|
3320
|
-
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3321
|
-
skipAddingFilesFromTsConfig: false
|
|
3322
|
-
});
|
|
3323
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3324
|
-
const fp = sf.getFilePath();
|
|
3325
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3326
|
-
});
|
|
3327
|
-
console.log(
|
|
3328
|
-
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3329
|
-
`
|
|
3330
|
-
);
|
|
3331
|
-
let changedFiles = 0;
|
|
3332
|
-
let totalRewrittenFunctions = 0;
|
|
3333
|
-
let totalRenamedReferences = 0;
|
|
3334
|
-
const skipped = [];
|
|
3335
|
-
for (const sourceFile of sourceFiles) {
|
|
3336
|
-
const filePath = sourceFile.getFilePath();
|
|
3337
|
-
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3338
|
-
const result = processFile11(sourceFile);
|
|
3339
|
-
if (result.skippedReason) {
|
|
3340
|
-
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3341
|
-
continue;
|
|
3342
|
-
}
|
|
3343
|
-
if (!result.changed) continue;
|
|
3344
|
-
await sourceFile.save();
|
|
3345
|
-
changedFiles++;
|
|
3346
|
-
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3347
|
-
totalRenamedReferences += result.renamedReferences;
|
|
3348
|
-
for (const fn of result.rewrittenFunctions) {
|
|
3349
|
-
console.log(
|
|
3350
|
-
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3351
|
-
);
|
|
3352
|
-
}
|
|
3353
|
-
if (result.renamedReferences > 0) {
|
|
3354
|
-
console.log(
|
|
3355
|
-
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3356
|
-
);
|
|
3357
|
-
}
|
|
3358
|
-
}
|
|
3359
|
-
if (skipped.length > 0) {
|
|
3360
|
-
console.warn(
|
|
3361
|
-
`
|
|
3362
|
-
${skipped.length} file(s) skipped:
|
|
3363
|
-
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3364
|
-
);
|
|
3365
|
-
}
|
|
3366
|
-
if (changedFiles === 0) {
|
|
3367
|
-
console.log(`
|
|
3368
|
-
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3369
|
-
return;
|
|
3370
|
-
}
|
|
3371
|
-
console.log(
|
|
3372
|
-
`
|
|
3373
|
-
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3374
|
-
);
|
|
3375
|
-
if (totalRewrittenFunctions > 0) {
|
|
3376
|
-
console.log(
|
|
3377
|
-
`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}'.`
|
|
3378
|
-
);
|
|
3379
|
-
}
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
|
-
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3383
|
-
var import_path16 = __toESM(require("path"));
|
|
3384
|
-
var import_ts_morph16 = require("ts-morph");
|
|
3385
|
-
var ROUTE_PATH = "/statistics";
|
|
3386
|
-
var HANDLER_NAME = "statisticsHandler";
|
|
3387
|
-
function isStatisticsRouteObject(obj) {
|
|
3388
|
-
const pathProp = obj.getProperty("path");
|
|
3389
|
-
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3390
|
-
const init = pathProp.getInitializer();
|
|
3391
|
-
if (!init) return false;
|
|
3392
|
-
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3393
|
-
return init.getLiteralValue() === ROUTE_PATH;
|
|
3394
|
-
}
|
|
3395
|
-
return false;
|
|
3396
|
-
}
|
|
3397
|
-
function removeStatisticsRoutes(sourceFile) {
|
|
3398
|
-
let removed = 0;
|
|
3399
|
-
const callExpressions = [
|
|
3400
|
-
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3401
|
-
];
|
|
3402
|
-
for (const call of callExpressions) {
|
|
3403
|
-
if (call.wasForgotten()) continue;
|
|
3404
|
-
const expr = call.getExpression();
|
|
3405
|
-
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3406
|
-
if (expr.getName() !== "route") continue;
|
|
3407
|
-
const args2 = call.getArguments();
|
|
3408
|
-
if (args2.length === 0) continue;
|
|
3409
|
-
const firstArg = args2[0];
|
|
3410
|
-
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3411
|
-
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3412
|
-
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3413
|
-
if (stmt) {
|
|
3414
|
-
stmt.remove();
|
|
3415
|
-
removed++;
|
|
3416
|
-
} else {
|
|
3417
|
-
call.replaceWithText("");
|
|
3418
|
-
removed++;
|
|
3419
|
-
}
|
|
3420
|
-
continue;
|
|
3421
|
-
}
|
|
3422
|
-
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3423
|
-
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3424
|
-
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3425
|
-
).map(({ idx }) => idx);
|
|
3426
|
-
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3427
|
-
firstArg.removeElement(idx);
|
|
3428
|
-
removed++;
|
|
3429
|
-
});
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
return removed;
|
|
3433
|
-
}
|
|
3434
|
-
function removeStatisticsHandlerImports(sourceFile) {
|
|
3435
|
-
let changed = false;
|
|
3436
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3437
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3438
|
-
if (!targetNamed) continue;
|
|
3439
|
-
targetNamed.remove();
|
|
3440
|
-
changed = true;
|
|
3441
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3442
|
-
if (isNowEmpty) decl.remove();
|
|
3443
|
-
}
|
|
3444
|
-
return changed;
|
|
3445
|
-
}
|
|
3446
|
-
function processFile12(sourceFile) {
|
|
3447
|
-
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3448
|
-
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3449
|
-
return { routesRemoved, importsCleaned };
|
|
3450
|
-
}
|
|
3451
|
-
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3452
|
-
const result = [];
|
|
3453
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3454
|
-
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3455
|
-
if (!moduleSf) continue;
|
|
3456
|
-
const fp = moduleSf.getFilePath();
|
|
3457
|
-
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3458
|
-
result.push(fp);
|
|
3459
|
-
}
|
|
3460
|
-
return result;
|
|
3461
|
-
}
|
|
3462
|
-
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3463
|
-
const initialCandidates = collectLocalImportsInSubtree(
|
|
3464
|
-
startingFile,
|
|
3465
|
-
subtreeRoot
|
|
3466
|
-
);
|
|
3467
|
-
const startingPath = startingFile.getFilePath();
|
|
3468
|
-
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3469
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3470
|
-
const worklist = [...initialCandidates];
|
|
3471
|
-
const orphans = [];
|
|
3472
|
-
while (worklist.length > 0) {
|
|
3473
|
-
const candidate = worklist.shift();
|
|
3474
|
-
if (seen.has(candidate)) continue;
|
|
3475
|
-
seen.add(candidate);
|
|
3476
|
-
if (deleted.has(candidate)) continue;
|
|
3477
|
-
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3478
|
-
const candidateSf = project.getSourceFile(candidate);
|
|
3479
|
-
if (!candidateSf) continue;
|
|
3480
|
-
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3481
|
-
const sfPath = sf.getFilePath();
|
|
3482
|
-
if (deleted.has(sfPath)) return false;
|
|
3483
|
-
if (sfPath === candidate) return false;
|
|
3484
|
-
return sf.getImportDeclarations().some(
|
|
3485
|
-
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3486
|
-
);
|
|
3487
|
-
});
|
|
3488
|
-
if (stillImported) continue;
|
|
3489
|
-
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3490
|
-
worklist.push(...next);
|
|
3491
|
-
candidateSf.delete();
|
|
3492
|
-
deleted.add(candidate);
|
|
3493
|
-
orphans.push(candidate);
|
|
3494
|
-
}
|
|
3495
|
-
return orphans;
|
|
3496
|
-
}
|
|
3497
|
-
function processHandlerFile(project) {
|
|
3498
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3499
|
-
const fp = sf.getFilePath();
|
|
3500
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3501
|
-
});
|
|
3502
|
-
for (const sf of sourceFiles) {
|
|
3503
|
-
const fn = sf.getFunction(HANDLER_NAME);
|
|
3504
|
-
if (!fn) continue;
|
|
3505
|
-
const filePath = sf.getFilePath();
|
|
3506
|
-
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3507
|
-
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3508
|
-
if (otherExports.length === 0) {
|
|
3509
|
-
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3510
|
-
const orphansDeleted = deleteOrphanedDescendants(
|
|
3511
|
-
project,
|
|
3512
|
-
sf,
|
|
3513
|
-
subtreeRoot
|
|
3514
|
-
);
|
|
3515
|
-
sf.delete();
|
|
3516
|
-
return { filePath, action: "deleted", orphansDeleted };
|
|
3517
|
-
}
|
|
3518
|
-
fn.remove();
|
|
3519
|
-
return {
|
|
3520
|
-
filePath,
|
|
3521
|
-
action: "function-removed",
|
|
3522
|
-
remainingExports: otherExports,
|
|
3523
|
-
orphansDeleted: []
|
|
3524
|
-
};
|
|
3525
|
-
}
|
|
3526
|
-
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3527
|
-
}
|
|
3528
|
-
async function main16() {
|
|
3529
|
-
const project = new import_ts_morph16.Project({
|
|
3530
|
-
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3531
|
-
skipAddingFilesFromTsConfig: false
|
|
3532
|
-
});
|
|
3533
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3534
|
-
const fp = sf.getFilePath();
|
|
3535
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3536
|
-
});
|
|
3537
|
-
console.log(
|
|
3538
|
-
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3539
|
-
`
|
|
3540
|
-
);
|
|
3541
|
-
let totalRoutesRemoved = 0;
|
|
3542
|
-
let totalFilesWithImportsCleaned = 0;
|
|
3543
|
-
let totalFilesWithRoutesRemoved = 0;
|
|
3544
|
-
for (const sourceFile of sourceFiles) {
|
|
3545
|
-
const filePath = sourceFile.getFilePath();
|
|
3546
|
-
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3547
|
-
const result = processFile12(sourceFile);
|
|
3548
|
-
if (result.routesRemoved > 0) {
|
|
3549
|
-
console.log(
|
|
3550
|
-
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3551
|
-
);
|
|
3552
|
-
totalRoutesRemoved += result.routesRemoved;
|
|
3553
|
-
totalFilesWithRoutesRemoved++;
|
|
3554
|
-
}
|
|
3555
|
-
if (result.importsCleaned) {
|
|
3556
|
-
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3557
|
-
totalFilesWithImportsCleaned++;
|
|
3558
|
-
}
|
|
3559
|
-
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3560
|
-
await sourceFile.save();
|
|
3561
|
-
}
|
|
3562
|
-
}
|
|
3563
|
-
const handlerResult = processHandlerFile(project);
|
|
3564
|
-
switch (handlerResult.action) {
|
|
3565
|
-
case "deleted": {
|
|
3566
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3567
|
-
console.log(
|
|
3568
|
-
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3569
|
-
);
|
|
3570
|
-
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3571
|
-
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3572
|
-
console.log(
|
|
3573
|
-
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3574
|
-
);
|
|
3575
|
-
}
|
|
3576
|
-
await project.save();
|
|
3577
|
-
break;
|
|
3578
|
-
}
|
|
3579
|
-
case "function-removed": {
|
|
3580
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3581
|
-
console.warn(
|
|
3582
|
-
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3583
|
-
);
|
|
3584
|
-
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3585
|
-
if (sf) await sf.save();
|
|
3586
|
-
break;
|
|
3587
|
-
}
|
|
3588
|
-
case "not-found":
|
|
3589
|
-
break;
|
|
3590
|
-
}
|
|
3591
|
-
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3592
|
-
console.log(`
|
|
3593
|
-
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3594
|
-
return;
|
|
3595
|
-
}
|
|
3596
|
-
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3597
|
-
console.log(
|
|
3598
|
-
`
|
|
3599
|
-
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3600
|
-
);
|
|
3601
|
-
}
|
|
3602
|
-
|
|
3603
|
-
// src/migrations/v2.0/update-package-json.ts
|
|
3604
|
-
var import_fs = require("fs");
|
|
3605
|
-
var import_path17 = __toESM(require("path"));
|
|
3606
|
-
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3607
|
-
var TARGET_VERSION = "2.0.0";
|
|
3608
|
-
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3609
|
-
async function main17() {
|
|
3610
|
-
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3611
|
-
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3612
|
-
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3613
|
-
return;
|
|
3614
|
-
}
|
|
3615
|
-
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3616
|
-
let parsed;
|
|
3617
|
-
try {
|
|
3618
|
-
parsed = JSON.parse(raw);
|
|
3619
|
-
} catch (error) {
|
|
3620
|
-
console.warn(
|
|
3621
|
-
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3622
|
-
);
|
|
3623
|
-
return;
|
|
3624
|
-
}
|
|
3625
|
-
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3626
|
-
const previousVersion = parsed.version;
|
|
3627
|
-
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3628
|
-
parsed.version = TARGET_VERSION;
|
|
3629
|
-
if (versionChanged) {
|
|
3630
|
-
console.log(
|
|
3631
|
-
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3632
|
-
);
|
|
3633
|
-
} else {
|
|
3634
|
-
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3635
|
-
}
|
|
3636
|
-
let zodBucket = "dependencies";
|
|
3637
|
-
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3638
|
-
zodBucket = "devDependencies";
|
|
3639
|
-
}
|
|
3640
|
-
if (!parsed[zodBucket]) {
|
|
3641
|
-
parsed[zodBucket] = {};
|
|
3642
|
-
}
|
|
3643
|
-
const bucket = parsed[zodBucket];
|
|
3644
|
-
const previousZod = bucket.zod;
|
|
3645
|
-
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3646
|
-
bucket.zod = TARGET_ZOD_RANGE;
|
|
3647
|
-
if (zodChanged) {
|
|
3648
|
-
console.log(
|
|
3649
|
-
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3650
|
-
);
|
|
3651
|
-
} else {
|
|
3652
|
-
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3653
|
-
}
|
|
3654
|
-
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3655
|
-
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3656
|
-
if (next === raw) {
|
|
3657
|
-
console.log("\n No changes to write.");
|
|
3658
|
-
return;
|
|
3659
|
-
}
|
|
3660
|
-
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3661
|
-
console.log(`
|
|
3662
|
-
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3663
|
-
console.log(
|
|
3664
|
-
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3665
|
-
);
|
|
3666
|
-
}
|
|
3667
|
-
|
|
3668
|
-
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3669
|
-
var import_ts_morph17 = require("ts-morph");
|
|
3670
|
-
var import_path18 = __toESM(require("path"));
|
|
3671
|
-
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
3672
|
-
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
3673
|
-
var ACTION_PROPERTY_NAME2 = "action";
|
|
3674
|
-
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3675
|
-
var TYPE_PROPERTY_NAME7 = "type";
|
|
3676
|
-
var SLUG_PROPERTY_NAME = "slug";
|
|
3677
|
-
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3678
|
-
"READ",
|
|
3679
|
-
"DELETE",
|
|
3680
|
-
"DECLARE",
|
|
3681
|
-
"REGISTER",
|
|
3682
|
-
"EDIT",
|
|
3683
|
-
"REJECT",
|
|
3684
|
-
"MARK_AS_DUPLICATE",
|
|
3685
|
-
"ARCHIVE",
|
|
3686
|
-
"PRINT_CERTIFICATE",
|
|
3687
|
-
"REQUEST_CORRECTION"
|
|
3688
|
-
]);
|
|
3689
|
-
function getWorkqueueLabel(workqueue) {
|
|
3690
|
-
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3691
|
-
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3692
|
-
return "(unknown slug)";
|
|
3693
|
-
}
|
|
3694
|
-
const slugInitializer = slugProperty.getInitializer();
|
|
3695
|
-
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3696
|
-
return "(unknown slug)";
|
|
3697
|
-
}
|
|
3698
|
-
return slugInitializer.getLiteralValue();
|
|
3699
|
-
}
|
|
3700
|
-
function getActionTypeName(action) {
|
|
3701
|
-
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3702
|
-
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3703
|
-
return null;
|
|
3704
|
-
}
|
|
3705
|
-
const typeInitializer = typeProperty.getInitializer();
|
|
3706
|
-
if (!typeInitializer) {
|
|
3707
|
-
return null;
|
|
3708
|
-
}
|
|
3709
|
-
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3710
|
-
return typeInitializer.getLiteralValue();
|
|
3711
|
-
}
|
|
3712
|
-
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3713
|
-
return typeInitializer.getName();
|
|
3714
|
-
}
|
|
3715
|
-
return null;
|
|
3716
|
-
}
|
|
3717
|
-
function isUnsupportedActionType(action) {
|
|
3718
|
-
const typeName = getActionTypeName(action);
|
|
3719
|
-
if (!typeName) {
|
|
3720
|
-
return false;
|
|
3721
|
-
}
|
|
3722
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3723
|
-
}
|
|
3724
|
-
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3725
|
-
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3726
|
-
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3727
|
-
return 0;
|
|
3728
|
-
}
|
|
3729
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
3730
|
-
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3731
|
-
return 0;
|
|
3732
|
-
}
|
|
3733
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3734
|
-
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3735
|
-
if (existingActionProperty) {
|
|
3736
|
-
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3737
|
-
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3738
|
-
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3739
|
-
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
3740
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3741
|
-
);
|
|
3742
|
-
if (conditionalsProperty2) {
|
|
3743
|
-
conditionalsProperty2.remove();
|
|
3744
|
-
console.log(
|
|
3745
|
-
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3746
|
-
);
|
|
3747
|
-
}
|
|
3748
|
-
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
3749
|
-
existingActionProperty.remove();
|
|
3750
|
-
console.log(
|
|
3751
|
-
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
3752
|
-
);
|
|
3753
|
-
}
|
|
3754
|
-
}
|
|
3755
|
-
}
|
|
3756
|
-
actionsProperty.remove();
|
|
3757
|
-
console.log(
|
|
3758
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3759
|
-
);
|
|
3760
|
-
return 1;
|
|
3761
|
-
}
|
|
3762
|
-
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3763
|
-
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3764
|
-
);
|
|
3765
|
-
if (actionCandidates.length === 0) {
|
|
3766
|
-
actionsProperty.remove();
|
|
3767
|
-
console.log(
|
|
3768
|
-
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3769
|
-
);
|
|
3770
|
-
return 1;
|
|
3771
|
-
}
|
|
3772
|
-
if (actionCandidates.length > 1) {
|
|
3773
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3774
|
-
console.warn(
|
|
3775
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3776
|
-
);
|
|
3777
|
-
}
|
|
3778
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3779
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3780
|
-
);
|
|
3781
|
-
if (conditionalsProperty) {
|
|
3782
|
-
conditionalsProperty.remove();
|
|
3783
|
-
console.log(
|
|
3784
|
-
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3785
|
-
);
|
|
3786
|
-
}
|
|
3787
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3788
|
-
actionsProperty.remove();
|
|
3789
|
-
console.log(
|
|
3790
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3791
|
-
);
|
|
3792
|
-
return 1;
|
|
3793
|
-
}
|
|
3794
|
-
const firstActionText = actionCandidates[0].getText();
|
|
3795
|
-
workqueue.addPropertyAssignment({
|
|
3796
|
-
name: ACTION_PROPERTY_NAME2,
|
|
3797
|
-
initializer: firstActionText
|
|
3798
|
-
});
|
|
3799
|
-
actionsProperty.remove();
|
|
3800
|
-
console.log(
|
|
3801
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3802
|
-
);
|
|
3803
|
-
return 1;
|
|
3804
|
-
}
|
|
3805
|
-
function processFile13(filePath, project) {
|
|
3806
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
3807
|
-
if (!sourceFile) return 0;
|
|
3808
|
-
let migratedWorkqueues = 0;
|
|
3809
|
-
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3810
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3811
|
-
import_ts_morph17.SyntaxKind.CallExpression
|
|
3812
|
-
);
|
|
3813
|
-
for (const call of callExpressions) {
|
|
3814
|
-
const expression = call.getExpression();
|
|
3815
|
-
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3816
|
-
continue;
|
|
3817
|
-
}
|
|
3818
|
-
const args2 = call.getArguments();
|
|
3819
|
-
if (args2.length === 0) continue;
|
|
3820
|
-
const workqueuesArg = args2[0];
|
|
3821
|
-
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3822
|
-
for (const element of workqueuesArg.getElements()) {
|
|
3823
|
-
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3824
|
-
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3825
|
-
}
|
|
3826
|
-
}
|
|
3827
|
-
return migratedWorkqueues;
|
|
3828
|
-
}
|
|
3829
|
-
async function main18() {
|
|
3830
|
-
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3831
|
-
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3832
|
-
`);
|
|
3833
|
-
const project = new import_ts_morph17.Project({
|
|
3834
|
-
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3835
|
-
skipAddingFilesFromTsConfig: false
|
|
3836
|
-
});
|
|
3837
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3838
|
-
const fp = sf.getFilePath();
|
|
3839
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3840
|
-
});
|
|
3841
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3842
|
-
`);
|
|
3843
|
-
let totalMigrated = 0;
|
|
3844
|
-
const modifiedFiles = [];
|
|
3845
|
-
for (const sourceFile of sourceFiles) {
|
|
3846
|
-
const filePath = sourceFile.getFilePath();
|
|
3847
|
-
const migrated = processFile13(filePath, project);
|
|
3848
|
-
if (migrated > 0) {
|
|
3849
|
-
totalMigrated += migrated;
|
|
3850
|
-
modifiedFiles.push(filePath);
|
|
3851
|
-
}
|
|
3852
|
-
}
|
|
3853
|
-
if (modifiedFiles.length === 0) {
|
|
3854
|
-
console.log(
|
|
3855
|
-
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3856
|
-
);
|
|
3857
|
-
return;
|
|
3858
|
-
}
|
|
3859
|
-
console.log(`
|
|
3860
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3861
|
-
for (const filePath of modifiedFiles) {
|
|
3862
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3863
|
-
await sourceFile.save();
|
|
3864
|
-
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3865
|
-
}
|
|
3866
|
-
console.log(
|
|
3867
|
-
`
|
|
3868
|
-
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3869
|
-
);
|
|
3870
|
-
}
|
|
3871
|
-
|
|
3872
|
-
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3873
|
-
var import_path19 = __toESM(require("path"));
|
|
3874
|
-
var import_ts_morph18 = require("ts-morph");
|
|
3875
|
-
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3876
|
-
async function main19() {
|
|
3877
|
-
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3878
|
-
const project = new import_ts_morph18.Project({
|
|
3879
|
-
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3880
|
-
skipAddingFilesFromTsConfig: false
|
|
3881
|
-
});
|
|
3882
|
-
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
3883
|
-
if (!sourceFile) {
|
|
3884
|
-
console.log(
|
|
3885
|
-
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3886
|
-
);
|
|
3887
|
-
return;
|
|
3888
|
-
}
|
|
3889
|
-
let changed = false;
|
|
3890
|
-
const constantsImport = sourceFile.getImportDeclaration(
|
|
3891
|
-
(decl) => decl.getModuleSpecifierValue() === "@countryconfig/constants"
|
|
3892
|
-
);
|
|
3893
|
-
if (constantsImport) {
|
|
3894
|
-
constantsImport.remove();
|
|
3895
|
-
changed = true;
|
|
3896
|
-
}
|
|
3897
|
-
const rolesHandler = sourceFile.getFunction("rolesHandler");
|
|
3898
|
-
if (!rolesHandler) {
|
|
3899
|
-
console.log(
|
|
3900
|
-
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3901
|
-
);
|
|
3902
|
-
return;
|
|
3903
|
-
}
|
|
3904
|
-
const secondParam = rolesHandler.getParameters()[1];
|
|
3905
|
-
const secondParamName = secondParam?.getName();
|
|
3906
|
-
const responseToolkitIdentifier = secondParamName || "h";
|
|
3907
|
-
const currentBodyText = rolesHandler.getBodyText();
|
|
3908
|
-
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3909
|
-
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3910
|
-
if (normalizedCurrent !== normalizedDesired) {
|
|
3911
|
-
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3912
|
-
changed = true;
|
|
3913
|
-
}
|
|
3914
|
-
if (!changed) {
|
|
3915
|
-
console.log(
|
|
3916
|
-
`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`
|
|
3917
|
-
);
|
|
3918
|
-
return;
|
|
3919
|
-
}
|
|
3920
|
-
await sourceFile.save();
|
|
3921
|
-
console.log(
|
|
3922
|
-
`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`
|
|
3923
|
-
);
|
|
3924
|
-
}
|
|
3925
|
-
|
|
3926
|
-
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3927
|
-
var fs2 = __toESM(require("fs"));
|
|
3928
|
-
var import_path20 = __toESM(require("path"));
|
|
3929
|
-
var PATHS_TO_REMOVE = [
|
|
3930
|
-
{
|
|
3931
|
-
relativePath: "src/migrations/hearth",
|
|
3932
|
-
label: "Hearth migrations directory"
|
|
3933
|
-
},
|
|
3934
|
-
{
|
|
3935
|
-
relativePath: "src/migrations/user-mgnt",
|
|
3936
|
-
label: "user-mgnt migrations directory"
|
|
3937
|
-
},
|
|
3938
|
-
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3939
|
-
];
|
|
3940
|
-
async function main20() {
|
|
3941
|
-
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3942
|
-
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3943
|
-
if (fs2.existsSync(absolutePath)) {
|
|
3944
|
-
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3945
|
-
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3946
|
-
} else {
|
|
3947
|
-
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3948
|
-
}
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
|
|
3952
|
-
// src/migrations/v2.0/create-events-index.ts
|
|
3953
|
-
var import_ts_morph19 = require("ts-morph");
|
|
3954
|
-
var import_fs2 = __toESM(require("fs"));
|
|
3955
|
-
var import_path21 = __toESM(require("path"));
|
|
3956
|
-
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3957
|
-
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3958
|
-
"getCustomEventsHandler",
|
|
3959
|
-
"getEventsHandler"
|
|
3960
|
-
]);
|
|
3961
|
-
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3962
|
-
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3963
|
-
var RESPONSE_METHOD_NAME = "response";
|
|
3964
|
-
var LICENSE_HEADER = `/*
|
|
3965
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3966
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3967
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3968
|
-
*
|
|
3969
|
-
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3970
|
-
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3971
|
-
*
|
|
3972
|
-
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3973
|
-
*/
|
|
3974
|
-
`;
|
|
3975
|
-
function findEventConfigExports(project, srcDir) {
|
|
3976
|
-
const found = [];
|
|
3977
|
-
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3978
|
-
for (const sourceFile of project.getSourceFiles()) {
|
|
3979
|
-
const filePath = sourceFile.getFilePath();
|
|
3980
|
-
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3981
|
-
continue;
|
|
3982
|
-
}
|
|
3983
|
-
if (filePath === eventsIndexAbs) continue;
|
|
3984
|
-
for (const statement of sourceFile.getVariableStatements()) {
|
|
3985
|
-
if (!statement.hasExportKeyword()) continue;
|
|
3986
|
-
for (const decl of statement.getDeclarations()) {
|
|
3987
|
-
const initializer = decl.getInitializer();
|
|
3988
|
-
if (!initializer) continue;
|
|
3989
|
-
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3990
|
-
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3991
|
-
const callee = unwrapped.getExpression();
|
|
3992
|
-
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3993
|
-
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3994
|
-
found.push({ name: decl.getName(), filePath });
|
|
3995
|
-
}
|
|
3996
|
-
}
|
|
3997
|
-
}
|
|
3998
|
-
return found;
|
|
3999
|
-
}
|
|
4000
|
-
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
4001
|
-
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
4002
|
-
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
4003
|
-
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
4004
|
-
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
4005
|
-
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
4006
|
-
return rel;
|
|
4007
|
-
}
|
|
4008
|
-
function buildEventsIndexSource(exports, srcDir) {
|
|
4009
|
-
const imports = exports.map(
|
|
4010
|
-
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
4011
|
-
e.filePath,
|
|
4012
|
-
srcDir
|
|
4013
|
-
)}'`
|
|
4014
|
-
).join("\n");
|
|
4015
|
-
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
4016
|
-
return `${LICENSE_HEADER}${imports}
|
|
4017
|
-
|
|
4018
|
-
${array3}
|
|
4019
|
-
`;
|
|
4020
|
-
}
|
|
4021
|
-
function findHandlerSourceFile(project, srcDir) {
|
|
4022
|
-
for (const sf of project.getSourceFiles()) {
|
|
4023
|
-
const fp = sf.getFilePath();
|
|
4024
|
-
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
4025
|
-
for (const fn of sf.getFunctions()) {
|
|
4026
|
-
const name = fn.getName();
|
|
4027
|
-
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
4028
|
-
}
|
|
4029
|
-
for (const statement of sf.getVariableStatements()) {
|
|
4030
|
-
for (const decl of statement.getDeclarations()) {
|
|
4031
|
-
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
4032
|
-
}
|
|
4033
|
-
}
|
|
4034
|
-
}
|
|
4035
|
-
return void 0;
|
|
4036
|
-
}
|
|
4037
|
-
function modifyHandler(sourceFile, exportNames) {
|
|
4038
|
-
const changes = [];
|
|
4039
|
-
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
4040
|
-
const namedImports = importDecl.getNamedImports();
|
|
4041
|
-
if (namedImports.length === 0) continue;
|
|
4042
|
-
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
4043
|
-
if (matched.length === 0) continue;
|
|
4044
|
-
const removedNames = matched.map((ni) => ni.getName());
|
|
4045
|
-
for (const ni of matched) ni.remove();
|
|
4046
|
-
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
4047
|
-
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
4048
|
-
if (!stillUsed) importDecl.remove();
|
|
4049
|
-
}
|
|
4050
|
-
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
4051
|
-
if (!statement.hasExportKeyword()) continue;
|
|
4052
|
-
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
4053
|
-
if (hasEventConfigs) {
|
|
4054
|
-
statement.remove();
|
|
4055
|
-
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
4056
|
-
}
|
|
4057
|
-
}
|
|
4058
|
-
const existing = sourceFile.getImportDeclaration(
|
|
4059
|
-
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
4060
|
-
);
|
|
4061
|
-
if (existing) {
|
|
4062
|
-
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
4063
|
-
if (!already) {
|
|
4064
|
-
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
4065
|
-
changes.push(
|
|
4066
|
-
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
4067
|
-
);
|
|
4068
|
-
}
|
|
4069
|
-
} else {
|
|
4070
|
-
sourceFile.addImportDeclaration({
|
|
4071
|
-
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
4072
|
-
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
4073
|
-
});
|
|
4074
|
-
changes.push(
|
|
4075
|
-
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
4076
|
-
);
|
|
4077
|
-
}
|
|
4078
|
-
for (const call of sourceFile.getDescendantsOfKind(
|
|
4079
|
-
import_ts_morph19.SyntaxKind.CallExpression
|
|
4080
|
-
)) {
|
|
4081
|
-
const callee = call.getExpression();
|
|
4082
|
-
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
4083
|
-
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
4084
|
-
const args2 = call.getArguments();
|
|
4085
|
-
if (args2.length !== 1) continue;
|
|
4086
|
-
const [arg] = args2;
|
|
4087
|
-
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
4088
|
-
if (arg.getElements().length === 0) continue;
|
|
4089
|
-
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
4090
|
-
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
4091
|
-
changes.push(
|
|
4092
|
-
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
4093
|
-
);
|
|
4094
|
-
}
|
|
4095
|
-
return changes;
|
|
4096
|
-
}
|
|
4097
|
-
async function main21() {
|
|
4098
|
-
const cwd = process.cwd();
|
|
4099
|
-
const srcDir = import_path21.default.join(cwd, "src");
|
|
4100
|
-
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
4101
|
-
`);
|
|
4102
|
-
const project = new import_ts_morph19.Project({
|
|
4103
|
-
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
4104
|
-
skipAddingFilesFromTsConfig: false
|
|
4105
|
-
});
|
|
4106
|
-
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
4107
|
-
if (eventConfigExports.length === 0) {
|
|
4108
|
-
console.log(
|
|
4109
|
-
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
4110
|
-
);
|
|
4111
|
-
return;
|
|
4112
|
-
}
|
|
4113
|
-
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
4114
|
-
for (const e of eventConfigExports) {
|
|
4115
|
-
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
4116
|
-
}
|
|
4117
|
-
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4118
|
-
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4119
|
-
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
4120
|
-
console.log(`
|
|
4121
|
-
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
4122
|
-
} else {
|
|
4123
|
-
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
4124
|
-
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
4125
|
-
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
4126
|
-
overwrite: false
|
|
4127
|
-
});
|
|
4128
|
-
await eventsIndexFile.save();
|
|
4129
|
-
console.log(
|
|
4130
|
-
`
|
|
4131
|
-
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
4132
|
-
);
|
|
4133
|
-
}
|
|
4134
|
-
const handler = findHandlerSourceFile(project, srcDir);
|
|
4135
|
-
if (!handler) {
|
|
4136
|
-
console.log(
|
|
4137
|
-
`
|
|
4138
|
-
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
4139
|
-
HANDLER_FUNCTION_NAMES
|
|
4140
|
-
).join(", ")}). Skipping handler rewrite.`
|
|
4141
|
-
);
|
|
4142
|
-
return;
|
|
4143
|
-
}
|
|
4144
|
-
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
4145
|
-
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
4146
|
-
const changes = modifyHandler(handler, exportNameSet);
|
|
4147
|
-
if (changes.length === 0) {
|
|
4148
|
-
console.log(`
|
|
4149
|
-
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
4150
|
-
return;
|
|
4151
|
-
}
|
|
4152
|
-
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
4153
|
-
await handler.save();
|
|
4154
|
-
console.log(`
|
|
4155
|
-
Saved ${handlerRelPath}.`);
|
|
4156
|
-
}
|
|
4157
|
-
|
|
4158
|
-
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4159
|
-
var import_child_process = require("child_process");
|
|
4160
|
-
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4161
|
-
var UPSTREAM_BRANCH = "develop";
|
|
4162
|
-
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4163
|
-
var FILES_TO_CHECKOUT = [
|
|
4164
|
-
"src/analytics/analytics.ts",
|
|
4165
|
-
"Dockerfile",
|
|
4166
|
-
"Dockerfile.assets"
|
|
4167
|
-
];
|
|
4168
|
-
function runGit(args2, { silent = false } = {}) {
|
|
4169
|
-
return (0, import_child_process.execFileSync)("git", args2, {
|
|
4170
|
-
cwd: process.cwd(),
|
|
4171
|
-
encoding: "utf8",
|
|
4172
|
-
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
4173
|
-
});
|
|
4174
|
-
}
|
|
4175
|
-
function tryGit(args2) {
|
|
4176
|
-
try {
|
|
4177
|
-
runGit(args2, { silent: true });
|
|
4178
|
-
return true;
|
|
4179
|
-
} catch {
|
|
4180
|
-
return false;
|
|
4181
|
-
}
|
|
4182
|
-
}
|
|
4183
|
-
function assertIsGitRepo() {
|
|
4184
|
-
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4185
|
-
throw new Error(
|
|
4186
|
-
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4187
|
-
);
|
|
4188
|
-
}
|
|
4189
|
-
}
|
|
4190
|
-
async function main22() {
|
|
4191
|
-
console.log(
|
|
4192
|
-
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
4193
|
-
`
|
|
4194
|
-
);
|
|
4195
|
-
assertIsGitRepo();
|
|
4196
|
-
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
4197
|
-
try {
|
|
4198
|
-
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
4199
|
-
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
4200
|
-
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
4201
|
-
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
4202
|
-
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
4203
|
-
const missing = [];
|
|
4204
|
-
let checkedOut = 0;
|
|
4205
|
-
for (const file of FILES_TO_CHECKOUT) {
|
|
4206
|
-
if (tryGit(["checkout", ref, "--", file])) {
|
|
4207
|
-
console.log(` Checked out ${file} from ${ref}`);
|
|
4208
|
-
checkedOut++;
|
|
4209
|
-
} else {
|
|
4210
|
-
console.warn(
|
|
4211
|
-
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
4212
|
-
);
|
|
4213
|
-
missing.push(file);
|
|
4214
|
-
}
|
|
4215
|
-
}
|
|
4216
|
-
console.log(
|
|
4217
|
-
`
|
|
4218
|
-
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
4219
|
-
);
|
|
4220
|
-
if (missing.length > 0) {
|
|
4221
|
-
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
4222
|
-
}
|
|
4223
|
-
if (checkedOut > 0) {
|
|
4224
|
-
console.log(
|
|
4225
|
-
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
4226
|
-
(f) => `'${f}'`
|
|
4227
|
-
).join(" ")}
|
|
4228
|
-
`
|
|
4229
|
-
);
|
|
4230
|
-
}
|
|
4231
|
-
} finally {
|
|
4232
|
-
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
4233
|
-
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
4234
|
-
}
|
|
4235
|
-
}
|
|
4236
|
-
}
|
|
4237
|
-
|
|
4238
|
-
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4239
|
-
var import_fs3 = require("fs");
|
|
4240
|
-
var import_path22 = __toESM(require("path"));
|
|
4241
|
-
var import_ts_morph20 = require("ts-morph");
|
|
4242
|
-
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4243
|
-
skipAddingFilesFromTsConfig: true,
|
|
4244
|
-
manipulationSettings: {
|
|
4245
|
-
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4246
|
-
}
|
|
4247
|
-
};
|
|
4248
|
-
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4249
|
-
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4250
|
-
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4251
|
-
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4252
|
-
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4253
|
-
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4254
|
-
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4255
|
-
<html>
|
|
4256
|
-
<head>
|
|
4257
|
-
<link
|
|
4258
|
-
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4259
|
-
rel="stylesheet"
|
|
4260
|
-
/>
|
|
4261
|
-
<style type="text/css">
|
|
4262
|
-
body {
|
|
4263
|
-
font-family: 'Noto Sans', sans-serif;
|
|
4264
|
-
color: #222;
|
|
4265
|
-
padding: 16px 24px;
|
|
4266
|
-
}
|
|
4267
|
-
|
|
4268
|
-
h1 {
|
|
4269
|
-
font-size: 21px;
|
|
4270
|
-
margin-top: 32px;
|
|
4271
|
-
margin-bottom: 36px;
|
|
4272
|
-
font-weight: 700;
|
|
4273
|
-
}
|
|
4274
|
-
|
|
4275
|
-
p {
|
|
4276
|
-
font-weight: 400;
|
|
4277
|
-
font-size: 16px;
|
|
4278
|
-
line-height: 1.8;
|
|
4279
|
-
margin-bottom: 24px;
|
|
4280
|
-
}
|
|
4281
|
-
|
|
4282
|
-
i {
|
|
4283
|
-
color: #666;
|
|
4284
|
-
font-weight: 400;
|
|
4285
|
-
font-size: 16px;
|
|
4286
|
-
}
|
|
4287
|
-
</style>
|
|
4288
|
-
</head>
|
|
4289
|
-
|
|
4290
|
-
<body>
|
|
4291
|
-
<img
|
|
4292
|
-
src="{{countryLogo}}"
|
|
4293
|
-
alt="country_logo"
|
|
4294
|
-
style="max-height: 88px; max-width: 100%"
|
|
4295
|
-
/>
|
|
4296
|
-
<h1>Your {{applicationName}} account invitation</h1>
|
|
4297
|
-
<p>Hello {{firstname}},</p>
|
|
4298
|
-
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4299
|
-
<p>
|
|
4300
|
-
Username: <strong>{{username}}</strong><br />
|
|
4301
|
-
Password: <strong>{{temporaryPassword}}</strong>
|
|
4302
|
-
</p>
|
|
4303
|
-
<p>
|
|
4304
|
-
Please click the link below to complete your account setup and start using
|
|
4305
|
-
{{applicationName}}.
|
|
4306
|
-
</p>
|
|
4307
|
-
|
|
4308
|
-
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4309
|
-
<a href="{{loginURL}}">Complete setup</a>
|
|
4310
|
-
</div>
|
|
4311
|
-
<br />
|
|
4312
|
-
<p>
|
|
4313
|
-
Best regards, <br />
|
|
4314
|
-
{{applicationName}} Team
|
|
4315
|
-
</p>
|
|
4316
|
-
</body>
|
|
4317
|
-
</html>
|
|
4318
|
-
`;
|
|
4319
|
-
var CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a \xE9t\xE9 renvoy\xE9e. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
|
|
4320
|
-
function getObjectLiteralFromConst(declaration) {
|
|
4321
|
-
if (!declaration) {
|
|
4322
|
-
return;
|
|
4323
|
-
}
|
|
4324
|
-
const initializer = declaration.getInitializer();
|
|
4325
|
-
if (!initializer) {
|
|
4326
|
-
return;
|
|
4327
|
-
}
|
|
4328
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4329
|
-
return initializer;
|
|
4330
|
-
}
|
|
4331
|
-
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4332
|
-
const expression = initializer.getExpression();
|
|
4333
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4334
|
-
return expression;
|
|
4335
|
-
}
|
|
4336
|
-
}
|
|
4337
|
-
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4338
|
-
const expression = initializer.getExpression();
|
|
4339
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4340
|
-
return expression;
|
|
4341
|
-
}
|
|
4342
|
-
}
|
|
4343
|
-
}
|
|
4344
|
-
function patchEmailTemplatesIndex() {
|
|
4345
|
-
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4346
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4347
|
-
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4348
|
-
return false;
|
|
4349
|
-
}
|
|
4350
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4351
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4352
|
-
let changed = false;
|
|
4353
|
-
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4354
|
-
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4355
|
-
);
|
|
4356
|
-
if (triggerVariableObject) {
|
|
4357
|
-
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4358
|
-
if (!hasResendInviteVariable) {
|
|
4359
|
-
const properties = triggerVariableObject.getProperties();
|
|
4360
|
-
const lastProperty = properties[properties.length - 1];
|
|
4361
|
-
if (lastProperty) {
|
|
4362
|
-
sourceFile.insertText(
|
|
4363
|
-
lastProperty.getEnd(),
|
|
4364
|
-
`,
|
|
4365
|
-
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4366
|
-
firstname: z.string(),
|
|
4367
|
-
username: z.string(),
|
|
4368
|
-
temporaryPassword: z.string(),
|
|
4369
|
-
completeSetupUrl: z.string(),
|
|
4370
|
-
loginURL: z.string()
|
|
4371
|
-
})`
|
|
4372
|
-
);
|
|
4373
|
-
changed = true;
|
|
4374
|
-
}
|
|
4375
|
-
}
|
|
4376
|
-
}
|
|
4377
|
-
const templatesObject = getObjectLiteralFromConst(
|
|
4378
|
-
sourceFile.getVariableDeclaration("templates")
|
|
4379
|
-
);
|
|
4380
|
-
if (templatesObject) {
|
|
4381
|
-
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4382
|
-
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4383
|
-
);
|
|
4384
|
-
if (!hasResendInviteTemplate) {
|
|
4385
|
-
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4386
|
-
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4387
|
-
if (anchor) {
|
|
4388
|
-
sourceFile.insertText(
|
|
4389
|
-
anchor.getEnd(),
|
|
4390
|
-
`,
|
|
4391
|
-
[TriggerEvent.RESEND_INVITE]: {
|
|
4392
|
-
type: 'resend-invite',
|
|
4393
|
-
subject: 'Your OpenCRVS account invitation',
|
|
4394
|
-
template:
|
|
4395
|
-
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4396
|
-
}`
|
|
4397
|
-
);
|
|
4398
|
-
changed = true;
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
if (changed) {
|
|
4403
|
-
sourceFile.saveSync();
|
|
4404
|
-
}
|
|
4405
|
-
return changed;
|
|
4406
|
-
}
|
|
4407
|
-
function patchNotificationHandler() {
|
|
4408
|
-
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4409
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4410
|
-
return false;
|
|
4411
|
-
}
|
|
4412
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4413
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4414
|
-
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4415
|
-
if (!convertFn) {
|
|
4416
|
-
return false;
|
|
4417
|
-
}
|
|
4418
|
-
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4419
|
-
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4420
|
-
);
|
|
4421
|
-
if (!switchStmt) {
|
|
4422
|
-
return false;
|
|
4423
|
-
}
|
|
4424
|
-
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4425
|
-
const hasResendInvite = clauses.some(
|
|
4426
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4427
|
-
);
|
|
4428
|
-
if (hasResendInvite) {
|
|
4429
|
-
return false;
|
|
4430
|
-
}
|
|
4431
|
-
const userCreatedClauseIndex = clauses.findIndex(
|
|
4432
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4433
|
-
);
|
|
4434
|
-
if (userCreatedClauseIndex < 0) {
|
|
4435
|
-
return false;
|
|
4436
|
-
}
|
|
4437
|
-
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4438
|
-
sourceFile.insertText(
|
|
4439
|
-
userCreatedClause.getEnd(),
|
|
4440
|
-
`
|
|
4441
|
-
|
|
4442
|
-
case TriggerEvent.RESEND_INVITE:
|
|
4443
|
-
return {
|
|
4444
|
-
firstname,
|
|
4445
|
-
username: payload.username,
|
|
4446
|
-
temporaryPassword: payload.temporaryPassword,
|
|
4447
|
-
completeSetupUrl: LOGIN_URL,
|
|
4448
|
-
loginURL: LOGIN_URL
|
|
4449
|
-
}`
|
|
4450
|
-
);
|
|
4451
|
-
sourceFile.saveSync();
|
|
4452
|
-
return true;
|
|
4453
|
-
}
|
|
4454
|
-
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4455
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4456
|
-
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4457
|
-
const fn = sourceFile.getFunction(fnName);
|
|
4458
|
-
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4459
|
-
const expr = returnStmt?.getExpression();
|
|
4460
|
-
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4461
|
-
return { sourceFile, arrayLiteral: void 0 };
|
|
4462
|
-
}
|
|
4463
|
-
return { sourceFile, arrayLiteral: expr };
|
|
4464
|
-
}
|
|
4465
|
-
function patchUserNotificationRoutes() {
|
|
4466
|
-
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4467
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4468
|
-
return false;
|
|
4469
|
-
}
|
|
4470
|
-
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4471
|
-
full,
|
|
4472
|
-
"getUserNotificationRoutes"
|
|
4473
|
-
);
|
|
4474
|
-
if (!arrayLiteral) {
|
|
4475
|
-
return false;
|
|
4476
|
-
}
|
|
4477
|
-
const elements = arrayLiteral.getElements();
|
|
4478
|
-
const routeExists = elements.some(
|
|
4479
|
-
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4480
|
-
);
|
|
4481
|
-
if (routeExists) {
|
|
4482
|
-
return false;
|
|
4483
|
-
}
|
|
4484
|
-
const anchor = elements.find(
|
|
4485
|
-
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4486
|
-
) ?? elements[elements.length - 1];
|
|
4487
|
-
if (!anchor) {
|
|
4488
|
-
return false;
|
|
4489
|
-
}
|
|
4490
|
-
sourceFile.insertText(
|
|
4491
|
-
anchor.getEnd(),
|
|
4492
|
-
`,
|
|
4493
|
-
{
|
|
4494
|
-
method: 'POST',
|
|
4495
|
-
path: '/triggers/user/resend-invite',
|
|
4496
|
-
handler: makeNotificationHandler('resend-invite'),
|
|
4497
|
-
options: {
|
|
4498
|
-
auth: false,
|
|
4499
|
-
tags: ['api'],
|
|
4500
|
-
description: 'Handles notification for resent user invite'
|
|
4501
|
-
}
|
|
4502
|
-
}`
|
|
4503
|
-
);
|
|
4504
|
-
sourceFile.saveSync();
|
|
4505
|
-
return true;
|
|
4506
|
-
}
|
|
4507
|
-
function patchSmsService() {
|
|
4508
|
-
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4509
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4510
|
-
return false;
|
|
4511
|
-
}
|
|
4512
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4513
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4514
|
-
let changed = false;
|
|
4515
|
-
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4516
|
-
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4517
|
-
);
|
|
4518
|
-
if (otherTemplatesObject) {
|
|
4519
|
-
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4520
|
-
if (!hasResendTemplate) {
|
|
4521
|
-
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4522
|
-
otherTemplatesObject.insertPropertyAssignment(
|
|
4523
|
-
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4524
|
-
{
|
|
4525
|
-
name: "resendInviteNotification",
|
|
4526
|
-
initializer: `'resendInviteNotification'`
|
|
4527
|
-
}
|
|
4528
|
-
);
|
|
4529
|
-
changed = true;
|
|
4530
|
-
}
|
|
4531
|
-
}
|
|
4532
|
-
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4533
|
-
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4534
|
-
);
|
|
4535
|
-
if (triggerToSmsTemplateObject) {
|
|
4536
|
-
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4537
|
-
if (!hasResendInviteMap) {
|
|
4538
|
-
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4539
|
-
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4540
|
-
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4541
|
-
{
|
|
4542
|
-
name: `['resend-invite']`,
|
|
4543
|
-
initializer: `'resendInviteNotification'`
|
|
4544
|
-
}
|
|
4545
|
-
);
|
|
4546
|
-
changed = true;
|
|
4547
|
-
}
|
|
4548
|
-
}
|
|
4549
|
-
if (changed) {
|
|
4550
|
-
sourceFile.saveSync();
|
|
4551
|
-
}
|
|
4552
|
-
return changed;
|
|
4553
|
-
}
|
|
4554
|
-
async function main23() {
|
|
4555
|
-
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4556
|
-
const touched = [];
|
|
4557
|
-
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4558
|
-
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4559
|
-
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4560
|
-
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4561
|
-
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4562
|
-
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4563
|
-
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4564
|
-
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4565
|
-
if (!t.endsWith("\n")) t += "\n";
|
|
4566
|
-
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4567
|
-
touched.push(NOTIFICATION_CSV);
|
|
4568
|
-
}
|
|
4569
|
-
}
|
|
4570
|
-
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4571
|
-
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4572
|
-
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4573
|
-
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4574
|
-
touched.push(RESEND_INVITE_HTML);
|
|
4575
|
-
}
|
|
4576
|
-
if (touched.length === 0) {
|
|
4577
|
-
console.log(" Nothing to update (already present or anchors not found).");
|
|
4578
|
-
return;
|
|
4579
|
-
}
|
|
4580
|
-
console.log(` Updated:
|
|
4581
|
-
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4582
|
-
}
|
|
4583
|
-
|
|
4584
|
-
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4585
|
-
var import_ts_morph21 = require("ts-morph");
|
|
4586
|
-
var import_fs4 = __toESM(require("fs"));
|
|
4587
|
-
var import_path23 = __toESM(require("path"));
|
|
4588
|
-
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4589
|
-
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4590
|
-
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
4591
|
-
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
4592
|
-
function removeTargetedNamedImports(sourceFile) {
|
|
4593
|
-
const log = [];
|
|
4594
|
-
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
4595
|
-
const namedImports = importDecl.getNamedImports();
|
|
4596
|
-
if (namedImports.length === 0) continue;
|
|
4597
|
-
const matched = namedImports.filter(
|
|
4598
|
-
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
4599
|
-
);
|
|
4600
|
-
if (matched.length === 0) continue;
|
|
4601
|
-
const removedNames = matched.map((ni) => ni.getName());
|
|
4602
|
-
for (const ni of matched) ni.remove();
|
|
4603
|
-
log.push(
|
|
4604
|
-
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
4605
|
-
);
|
|
4606
|
-
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
4607
|
-
if (!stillUsed) importDecl.remove();
|
|
4608
|
-
}
|
|
4609
|
-
return log;
|
|
4610
|
-
}
|
|
4611
|
-
function findPrecalculateFunction(sourceFile) {
|
|
4612
|
-
for (const fn of sourceFile.getFunctions()) {
|
|
4613
|
-
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
4614
|
-
}
|
|
4615
|
-
for (const statement of sourceFile.getVariableStatements()) {
|
|
4616
|
-
for (const decl of statement.getDeclarations()) {
|
|
4617
|
-
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
4618
|
-
}
|
|
4619
|
-
}
|
|
4620
|
-
return void 0;
|
|
4621
|
-
}
|
|
4622
|
-
function getFunctionBodyBlock(fn) {
|
|
4623
|
-
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4624
|
-
const initializer = fn.getInitializer();
|
|
4625
|
-
if (!initializer) return void 0;
|
|
4626
|
-
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
4627
|
-
return void 0;
|
|
4628
|
-
}
|
|
4629
|
-
return initializer.getBody();
|
|
4630
|
-
}
|
|
4631
|
-
function simplifyPrecalculateFunction(sourceFile) {
|
|
4632
|
-
const log = [];
|
|
4633
|
-
const fn = findPrecalculateFunction(sourceFile);
|
|
4634
|
-
if (!fn) return log;
|
|
4635
|
-
const body = getFunctionBodyBlock(fn);
|
|
4636
|
-
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
4637
|
-
for (const statement of [...body.getStatements()]) {
|
|
4638
|
-
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4639
|
-
if (references) {
|
|
4640
|
-
statement.remove();
|
|
4641
|
-
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
4642
|
-
}
|
|
4643
|
-
}
|
|
4644
|
-
const remaining = body.getStatements();
|
|
4645
|
-
const last = remaining[remaining.length - 1];
|
|
4646
|
-
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4647
|
-
if (!alreadyCorrect) {
|
|
4648
|
-
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4649
|
-
log.push(
|
|
4650
|
-
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
4651
|
-
);
|
|
4652
|
-
}
|
|
4653
|
-
return log;
|
|
4654
|
-
}
|
|
4655
|
-
async function main24() {
|
|
4656
|
-
const cwd = process.cwd();
|
|
4657
|
-
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4658
|
-
if (!import_fs4.default.existsSync(absPath)) {
|
|
4659
|
-
console.log(
|
|
4660
|
-
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
4661
|
-
);
|
|
4662
|
-
return;
|
|
4663
|
-
}
|
|
4664
|
-
const project = new import_ts_morph21.Project({
|
|
4665
|
-
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
4666
|
-
skipAddingFilesFromTsConfig: false
|
|
4667
|
-
});
|
|
4668
|
-
const sourceFile = project.getSourceFile(absPath);
|
|
4669
|
-
if (!sourceFile) {
|
|
4670
|
-
console.log(
|
|
4671
|
-
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
4672
|
-
);
|
|
4673
|
-
return;
|
|
4674
|
-
}
|
|
4675
|
-
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
4676
|
-
`);
|
|
4677
|
-
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
4678
|
-
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
4679
|
-
const allLogs = [...importLogs, ...fnLogs];
|
|
4680
|
-
if (allLogs.length === 0) {
|
|
4681
|
-
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
4682
|
-
return;
|
|
4683
|
-
}
|
|
4684
|
-
for (const log of allLogs) {
|
|
4685
|
-
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
4686
|
-
}
|
|
4687
|
-
await sourceFile.save();
|
|
4688
|
-
console.log(`
|
|
4689
|
-
Saved ${ANALYTICS_FILE_REL}.`);
|
|
4690
|
-
}
|
|
4691
|
-
|
|
4692
|
-
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4693
|
-
var import_child_process2 = require("child_process");
|
|
4694
|
-
var import_fs5 = require("fs");
|
|
4695
|
-
var import_os = require("os");
|
|
4696
|
-
var import_path24 = require("path");
|
|
4697
|
-
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4698
|
-
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4699
|
-
var BASE_BRANCH = "release-v1.9";
|
|
4700
|
-
function gitShowBytes(ref, path23) {
|
|
4701
|
-
try {
|
|
4702
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4703
|
-
cwd: process.cwd(),
|
|
4704
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4705
|
-
});
|
|
4706
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4707
|
-
} catch {
|
|
4708
|
-
return null;
|
|
4709
|
-
}
|
|
4710
|
-
}
|
|
4711
|
-
async function main25() {
|
|
4712
|
-
console.log(
|
|
4713
|
-
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4714
|
-
`
|
|
4715
|
-
);
|
|
4716
|
-
assertIsGitRepo();
|
|
4717
|
-
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4718
|
-
try {
|
|
4719
|
-
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4720
|
-
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4721
|
-
console.log(
|
|
4722
|
-
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4723
|
-
);
|
|
4724
|
-
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4725
|
-
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4726
|
-
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4727
|
-
const upstreamFiles = runGit(
|
|
4728
|
-
[
|
|
4729
|
-
"ls-tree",
|
|
4730
|
-
"-r",
|
|
4731
|
-
"--name-only",
|
|
4732
|
-
"-z",
|
|
4733
|
-
ref,
|
|
4734
|
-
"--",
|
|
4735
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4736
|
-
],
|
|
4737
|
-
{ silent: true }
|
|
4738
|
-
).split("\0").filter(Boolean);
|
|
4739
|
-
if (upstreamFiles.length === 0) {
|
|
4740
|
-
console.log(
|
|
4741
|
-
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4742
|
-
);
|
|
4743
|
-
return;
|
|
4744
|
-
}
|
|
4745
|
-
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4746
|
-
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4747
|
-
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4748
|
-
let added = 0;
|
|
4749
|
-
let merged = 0;
|
|
4750
|
-
const conflictedFiles = [];
|
|
4751
|
-
for (const file of upstreamFiles) {
|
|
4752
|
-
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4753
|
-
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4754
|
-
if (tryGit(["checkout", ref, "--", file])) {
|
|
4755
|
-
console.log(` + ${file} (new from upstream)`);
|
|
4756
|
-
added++;
|
|
4757
|
-
} else {
|
|
4758
|
-
console.warn(` [warn] failed to add new file ${file}`);
|
|
4759
|
-
}
|
|
4760
|
-
continue;
|
|
4761
|
-
}
|
|
4762
|
-
const theirContents = gitShowBytes(ref, file);
|
|
4763
|
-
if (theirContents === null) {
|
|
4764
|
-
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4765
|
-
continue;
|
|
4766
|
-
}
|
|
4767
|
-
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4768
|
-
const baseContents = gitShowBytes(baseRef, file);
|
|
4769
|
-
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4770
|
-
try {
|
|
4771
|
-
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4772
|
-
cwd: process.cwd(),
|
|
4773
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4774
|
-
});
|
|
4775
|
-
runGit(["add", "--", file], { silent: true });
|
|
4776
|
-
merged++;
|
|
4777
|
-
} catch (err) {
|
|
4778
|
-
const status = err.status;
|
|
4779
|
-
if (typeof status === "number" && status > 0) {
|
|
4780
|
-
conflictedFiles.push(file);
|
|
4781
|
-
console.warn(
|
|
4782
|
-
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4783
|
-
);
|
|
4784
|
-
} else {
|
|
4785
|
-
conflictedFiles.push(file);
|
|
4786
|
-
console.warn(
|
|
4787
|
-
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4788
|
-
);
|
|
4789
|
-
}
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
4792
|
-
console.log(
|
|
4793
|
-
`
|
|
4794
|
-
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4795
|
-
);
|
|
4796
|
-
if (conflictedFiles.length > 0) {
|
|
4797
|
-
console.warn(
|
|
4798
|
-
`
|
|
4799
|
-
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4800
|
-
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4801
|
-
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4802
|
-
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4803
|
-
);
|
|
4804
|
-
}
|
|
4805
|
-
} finally {
|
|
4806
|
-
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4807
|
-
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4808
|
-
}
|
|
4809
|
-
}
|
|
4810
|
-
}
|
|
4811
|
-
|
|
4812
|
-
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4813
|
-
var import_fs6 = require("fs");
|
|
4814
|
-
var import_path25 = require("path");
|
|
4815
|
-
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4816
|
-
async function main26() {
|
|
4817
|
-
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4818
|
-
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4819
|
-
console.log(
|
|
4820
|
-
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
4821
|
-
);
|
|
4822
|
-
return;
|
|
4823
|
-
}
|
|
4824
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4825
|
-
`);
|
|
4826
|
-
assertIsGitRepo();
|
|
4827
|
-
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4828
|
-
silent: true
|
|
4829
|
-
});
|
|
4830
|
-
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4831
|
-
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4832
|
-
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4833
|
-
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4834
|
-
}
|
|
4835
|
-
console.log(
|
|
4836
|
-
`
|
|
4837
|
-
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4838
|
-
);
|
|
4839
|
-
}
|
|
4840
|
-
|
|
4841
|
-
// src/migrations/v2.0/index.ts
|
|
203
|
+
// src/migrations/v2.1/index.ts
|
|
4842
204
|
async function runUpgrade(dockerSwarm) {
|
|
4843
|
-
await main18();
|
|
4844
205
|
await main();
|
|
4845
|
-
await main2();
|
|
4846
|
-
await main3();
|
|
4847
|
-
await main4();
|
|
4848
|
-
await main5();
|
|
4849
|
-
await main6();
|
|
4850
|
-
await main7();
|
|
4851
|
-
await main8();
|
|
4852
|
-
await main9();
|
|
4853
|
-
await main10();
|
|
4854
|
-
await main11();
|
|
4855
|
-
await main12();
|
|
4856
|
-
await main13();
|
|
4857
|
-
await main14();
|
|
4858
|
-
await main15();
|
|
4859
|
-
await main16();
|
|
4860
|
-
await main19();
|
|
4861
|
-
await main20();
|
|
4862
|
-
await main21();
|
|
4863
|
-
await main22();
|
|
4864
|
-
await main23();
|
|
4865
|
-
await main24();
|
|
4866
|
-
await main17();
|
|
4867
|
-
if (dockerSwarm) {
|
|
4868
|
-
await main25();
|
|
4869
|
-
} else {
|
|
4870
|
-
await main26();
|
|
4871
|
-
}
|
|
4872
206
|
}
|
|
4873
207
|
|
|
4874
208
|
// src/cli.ts
|
|
@@ -4896,7 +230,7 @@ Options:
|
|
|
4896
230
|
'infrastructure/' directory is deleted (default).
|
|
4897
231
|
-h, --help Show this message.
|
|
4898
232
|
`.trim();
|
|
4899
|
-
function
|
|
233
|
+
function main2() {
|
|
4900
234
|
const command = args[0];
|
|
4901
235
|
if (!command || command === "--help" || command === "-h") {
|
|
4902
236
|
console.log(USAGE);
|
|
@@ -4971,4 +305,4 @@ function handleCheckTranslations() {
|
|
|
4971
305
|
console.warn("This command is not implemented yet!");
|
|
4972
306
|
process.exit(1);
|
|
4973
307
|
}
|
|
4974
|
-
|
|
308
|
+
main2();
|