@opencrvs/toolkit 2.0.0-rc.a657c77 → 2.0.0-rc.a7c070e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application-config/index.js +12 -20
- package/dist/cli.js +93 -187
- package/dist/commons/api/router.d.ts +7 -0
- package/dist/commons/events/ActionInput.d.ts +36 -0
- package/dist/commons/events/Draft.d.ts +1 -0
- package/dist/events/index.js +13 -20
- 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 +2 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +1 -9
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +20 -66
- package/dist/migrations/v2.0/index.d.ts +3 -5
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +93 -187
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +1 -11
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +16 -17
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +59 -140
- package/dist/notification/index.js +13 -20
- package/opencrvs-toolkit-2.0.0-rc.a7c070e.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.a657c77.tgz +0 -0
|
@@ -39,10 +39,6 @@ exports.main = main;
|
|
|
39
39
|
* - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
|
|
40
40
|
* - If `action` already exists, removes deprecated `actions` and keeps `action`
|
|
41
41
|
* - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
|
|
42
|
-
* - Ensures every workqueue ends up with a valid `action`. When none is
|
|
43
|
-
* present (or the existing one is unsupported), falls back to
|
|
44
|
-
* `action: { type: ActionType.READ }` and ensures `ActionType` is imported
|
|
45
|
-
* from `@opencrvs/toolkit/events` in the file.
|
|
46
42
|
* - Saves modified files in-place
|
|
47
43
|
*/
|
|
48
44
|
const ts_morph_1 = require("ts-morph");
|
|
@@ -53,10 +49,6 @@ const ACTION_PROPERTY_NAME = 'action';
|
|
|
53
49
|
const CONDITIONALS_PROPERTY_NAME = 'conditionals';
|
|
54
50
|
const TYPE_PROPERTY_NAME = 'type';
|
|
55
51
|
const SLUG_PROPERTY_NAME = 'slug';
|
|
56
|
-
const READ_ACTION_TYPE = 'READ';
|
|
57
|
-
const ACTION_TYPE_IMPORT_NAME = 'ActionType';
|
|
58
|
-
const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
|
|
59
|
-
const READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
60
52
|
const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
|
|
61
53
|
'READ',
|
|
62
54
|
'DELETE',
|
|
@@ -104,146 +96,80 @@ function isUnsupportedActionType(action) {
|
|
|
104
96
|
}
|
|
105
97
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
106
98
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Ensures the workqueue has a valid singular `action` property. When the
|
|
109
|
-
* existing `action` is missing or has an unsupported type, replaces it with
|
|
110
|
-
* `action: { type: ActionType.READ }`.
|
|
111
|
-
*
|
|
112
|
-
* Returns whether anything was changed and whether the READ fallback was
|
|
113
|
-
* applied (so the caller can ensure `ActionType` is imported in the file).
|
|
114
|
-
*/
|
|
115
|
-
function ensureValidAction(workqueue, relPath) {
|
|
116
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
117
|
-
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
118
|
-
if (actionProperty && ts_morph_1.Node.isPropertyAssignment(actionProperty)) {
|
|
119
|
-
const initializer = actionProperty.getInitializer();
|
|
120
|
-
if (initializer && ts_morph_1.Node.isObjectLiteralExpression(initializer)) {
|
|
121
|
-
if (!isUnsupportedActionType(initializer)) {
|
|
122
|
-
return { changed: false, usedReadFallback: false };
|
|
123
|
-
}
|
|
124
|
-
actionProperty.set({
|
|
125
|
-
name: ACTION_PROPERTY_NAME,
|
|
126
|
-
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
127
|
-
});
|
|
128
|
-
// eslint-disable-next-line no-console
|
|
129
|
-
console.log(` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`);
|
|
130
|
-
return { changed: true, usedReadFallback: true };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
workqueue.addPropertyAssignment({
|
|
134
|
-
name: ACTION_PROPERTY_NAME,
|
|
135
|
-
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
136
|
-
});
|
|
137
|
-
// eslint-disable-next-line no-console
|
|
138
|
-
console.log(` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`);
|
|
139
|
-
return { changed: true, usedReadFallback: true };
|
|
140
|
-
}
|
|
141
99
|
function migrateWorkqueueActions(workqueue, relPath) {
|
|
142
|
-
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
143
100
|
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
actionsProperty.remove();
|
|
164
|
-
// eslint-disable-next-line no-console
|
|
165
|
-
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
|
|
166
|
-
actionsArrayMigrated = true;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const actionCandidates = actionsInitializer
|
|
170
|
-
.getElements()
|
|
171
|
-
.filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
|
|
172
|
-
if (actionCandidates.length === 0) {
|
|
173
|
-
actionsProperty.remove();
|
|
101
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
105
|
+
if (!actionsInitializer || !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
109
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
|
|
110
|
+
if (existingActionProperty) {
|
|
111
|
+
if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
|
|
112
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
113
|
+
if (existingActionInitializer && ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
114
|
+
const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
115
|
+
if (conditionalsProperty) {
|
|
116
|
+
conditionalsProperty.remove();
|
|
174
117
|
// eslint-disable-next-line no-console
|
|
175
|
-
console.log(` [${relPath}] Removed
|
|
176
|
-
actionsArrayMigrated = true;
|
|
118
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
|
|
177
119
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
|
|
183
|
-
}
|
|
184
|
-
const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
185
|
-
if (conditionalsProperty) {
|
|
186
|
-
conditionalsProperty.remove();
|
|
187
|
-
// eslint-disable-next-line no-console
|
|
188
|
-
console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
|
|
189
|
-
}
|
|
190
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
191
|
-
actionsProperty.remove();
|
|
192
|
-
// eslint-disable-next-line no-console
|
|
193
|
-
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
|
|
194
|
-
actionsArrayMigrated = true;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
const firstActionText = actionCandidates[0].getText();
|
|
198
|
-
workqueue.addPropertyAssignment({
|
|
199
|
-
name: ACTION_PROPERTY_NAME,
|
|
200
|
-
initializer: firstActionText
|
|
201
|
-
});
|
|
202
|
-
actionsProperty.remove();
|
|
203
|
-
// eslint-disable-next-line no-console
|
|
204
|
-
console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
|
|
205
|
-
actionsArrayMigrated = true;
|
|
206
|
-
}
|
|
120
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
121
|
+
existingActionProperty.remove();
|
|
122
|
+
// eslint-disable-next-line no-console
|
|
123
|
+
console.log(` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`);
|
|
207
124
|
}
|
|
208
125
|
}
|
|
209
126
|
}
|
|
127
|
+
actionsProperty.remove();
|
|
128
|
+
// eslint-disable-next-line no-console
|
|
129
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
|
|
130
|
+
return 1;
|
|
210
131
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Ensures `import { ActionType } from '@opencrvs/toolkit/events'` exists in
|
|
222
|
-
* the source file, merging into any existing import declaration from the
|
|
223
|
-
* same module specifier.
|
|
224
|
-
*/
|
|
225
|
-
function ensureActionTypeImport(sourceFile) {
|
|
226
|
-
const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
|
|
227
|
-
if (existingImport) {
|
|
228
|
-
const alreadyImported = existingImport
|
|
229
|
-
.getNamedImports()
|
|
230
|
-
.some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
231
|
-
if (!alreadyImported) {
|
|
232
|
-
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
132
|
+
const actionCandidates = actionsInitializer
|
|
133
|
+
.getElements()
|
|
134
|
+
.filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
|
|
135
|
+
if (actionCandidates.length === 0) {
|
|
136
|
+
actionsProperty.remove();
|
|
137
|
+
// eslint-disable-next-line no-console
|
|
138
|
+
console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
|
|
139
|
+
return 1;
|
|
235
140
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
141
|
+
if (actionCandidates.length > 1) {
|
|
142
|
+
const droppedCount = actionCandidates.length - 1;
|
|
143
|
+
// eslint-disable-next-line no-console
|
|
144
|
+
console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
|
|
145
|
+
}
|
|
146
|
+
const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
|
|
147
|
+
if (conditionalsProperty) {
|
|
148
|
+
conditionalsProperty.remove();
|
|
149
|
+
// eslint-disable-next-line no-console
|
|
150
|
+
console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
|
|
151
|
+
}
|
|
152
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
153
|
+
actionsProperty.remove();
|
|
154
|
+
// eslint-disable-next-line no-console
|
|
155
|
+
console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
const firstActionText = actionCandidates[0].getText();
|
|
159
|
+
workqueue.addPropertyAssignment({
|
|
160
|
+
name: ACTION_PROPERTY_NAME,
|
|
161
|
+
initializer: firstActionText
|
|
239
162
|
});
|
|
163
|
+
actionsProperty.remove();
|
|
164
|
+
// eslint-disable-next-line no-console
|
|
165
|
+
console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
|
|
166
|
+
return 1;
|
|
240
167
|
}
|
|
241
168
|
function processFile(filePath, project) {
|
|
242
169
|
const sourceFile = project.getSourceFile(filePath);
|
|
243
170
|
if (!sourceFile)
|
|
244
171
|
return 0;
|
|
245
172
|
let migratedWorkqueues = 0;
|
|
246
|
-
let needsActionTypeImport = false;
|
|
247
173
|
const relPath = path_1.default.relative(process.cwd(), filePath);
|
|
248
174
|
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
249
175
|
for (const call of callExpressions) {
|
|
@@ -261,16 +187,9 @@ function processFile(filePath, project) {
|
|
|
261
187
|
for (const element of workqueuesArg.getElements()) {
|
|
262
188
|
if (!ts_morph_1.Node.isObjectLiteralExpression(element))
|
|
263
189
|
continue;
|
|
264
|
-
|
|
265
|
-
if (result.changed)
|
|
266
|
-
migratedWorkqueues++;
|
|
267
|
-
if (result.usedReadFallback)
|
|
268
|
-
needsActionTypeImport = true;
|
|
190
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
269
191
|
}
|
|
270
192
|
}
|
|
271
|
-
if (needsActionTypeImport) {
|
|
272
|
-
ensureActionTypeImport(sourceFile);
|
|
273
|
-
}
|
|
274
193
|
return migratedWorkqueues;
|
|
275
194
|
}
|
|
276
195
|
function main() {
|
|
@@ -980,28 +980,20 @@ function schemaPriority(schema) {
|
|
|
980
980
|
return idx === -1 ? 9999 : idx;
|
|
981
981
|
}
|
|
982
982
|
function safeUnion(schemas) {
|
|
983
|
+
const sortedSchemas = [...schemas].sort(
|
|
984
|
+
(a, b) => schemaPriority(a) - schemaPriority(b)
|
|
985
|
+
);
|
|
983
986
|
return z12.any().superRefine((val, ctx) => {
|
|
984
|
-
const
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
if (successful.length === 0) {
|
|
989
|
-
ctx.addIssue({
|
|
990
|
-
code: "invalid_type",
|
|
991
|
-
expected: "custom",
|
|
992
|
-
message: "Value does not match any schema"
|
|
993
|
-
});
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
|
-
successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
|
|
997
|
-
const best = successful[0];
|
|
998
|
-
if (!best.safeParse(val).success) {
|
|
999
|
-
ctx.addIssue({
|
|
1000
|
-
expected: "custom",
|
|
1001
|
-
code: "invalid_type",
|
|
1002
|
-
message: "Value did not match the best schema"
|
|
1003
|
-
});
|
|
987
|
+
for (const schema of sortedSchemas) {
|
|
988
|
+
if (schema.safeParse(val).success) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
1004
991
|
}
|
|
992
|
+
ctx.addIssue({
|
|
993
|
+
code: "invalid_type",
|
|
994
|
+
expected: "custom",
|
|
995
|
+
message: "Value does not match any schema"
|
|
996
|
+
});
|
|
1005
997
|
}).meta({
|
|
1006
998
|
description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
|
|
1007
999
|
});
|
|
@@ -4180,6 +4172,7 @@ var BaseActionInput = z38.object({
|
|
|
4180
4172
|
originalActionId: UUID.optional(),
|
|
4181
4173
|
// should not be part of base action.
|
|
4182
4174
|
keepAssignment: z38.boolean().optional(),
|
|
4175
|
+
waitFor: z38.boolean().optional(),
|
|
4183
4176
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
4184
4177
|
// @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
|
|
4185
4178
|
createdAtLocation: UUID.nullish().describe(
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|