@opencrvs/toolkit 2.0.0-rc.c2f305f → 2.0.0-rc.c30a093
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/dist/application-config/index.js +15 -5
- package/dist/cli.js +166 -5101
- package/dist/commons/api/router.d.ts +8 -0
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/ActionConfig.d.ts +176 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
- package/dist/commons/events/EventConfig.d.ts +2 -0
- package/dist/commons/events/EventIndex.d.ts +11 -0
- package/dist/commons/events/EventMetadata.d.ts +26 -0
- package/dist/commons/events/FieldConfig.d.ts +10 -0
- package/dist/commons/events/locations.d.ts +1 -0
- package/dist/commons/events/state/index.d.ts +8 -0
- package/dist/commons/events/state/utils.d.ts +9 -0
- package/dist/conditionals/index.js +10 -5
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +1 -0
- package/dist/events/index.js +130 -12
- package/dist/migrations/v2.0/index.js +88 -5139
- 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 +106 -8
- package/dist/scopes/index.d.ts +89 -1
- package/dist/scopes/index.js +10 -5
- package/dist/templates/charts-values/opencrvs-services/values.yaml +1 -0
- package/opencrvs-toolkit-2.0.0-rc.c30a093.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.c2f305f.tgz +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-explicit-correction-flags.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/add-explicit-correction-flags.ts"],"names":[],"mappings":"AAyPA,iBAAe,IAAI,kBA+ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: Add explicit `APPROVE_CORRECTION` / `REJECT_CORRECTION` action
|
|
28
|
+
* configs when `REQUEST_CORRECTION` has `flags` and/or `conditionals`.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* ts-node -r tsconfig-paths/register src/migrations/v2.1/add-explicit-correction-flags.ts
|
|
32
|
+
*
|
|
33
|
+
* Why:
|
|
34
|
+
* `getActionConfig()` used to alias `APPROVE_CORRECTION` and
|
|
35
|
+
* `REJECT_CORRECTION` to whatever was configured on `REQUEST_CORRECTION`
|
|
36
|
+
* (label, flags, conditionals). As of v2.1, each resolves to its own
|
|
37
|
+
* independent config, so `flags`/`conditionals` configured only on
|
|
38
|
+
* `REQUEST_CORRECTION` would silently stop applying when an
|
|
39
|
+
* `APPROVE_CORRECTION`/`REJECT_CORRECTION` action is accepted. See
|
|
40
|
+
* CHANGELOG.md ("APPROVE_CORRECTION / REJECT_CORRECTION no longer inherit
|
|
41
|
+
* REQUEST_CORRECTION's config").
|
|
42
|
+
*
|
|
43
|
+
* What it does:
|
|
44
|
+
* - Scans all TypeScript files under `src/`
|
|
45
|
+
* - Finds every `defineConfig({ ... })` call expression
|
|
46
|
+
* - Inside the `actions` array, locates the `REQUEST_CORRECTION` action
|
|
47
|
+
* - If it has a non-empty `flags` and/or `conditionals` array, inserts
|
|
48
|
+
* sibling `APPROVE_CORRECTION` and `REJECT_CORRECTION` action objects
|
|
49
|
+
* (carrying over the same `flags`/`conditionals`) immediately after it,
|
|
50
|
+
* unless an action of that type already exists in the array
|
|
51
|
+
* - Saves the modified files in-place
|
|
52
|
+
*/
|
|
53
|
+
const ts_morph_1 = require("ts-morph");
|
|
54
|
+
const path_1 = __importDefault(require("path"));
|
|
55
|
+
const DEFINE_CONFIG_NAME = 'defineConfig';
|
|
56
|
+
const ACTIONS_PROPERTY_NAME = 'actions';
|
|
57
|
+
const TYPE_PROPERTY_NAME = 'type';
|
|
58
|
+
const FLAGS_PROPERTY_NAME = 'flags';
|
|
59
|
+
const CONDITIONALS_PROPERTY_NAME = 'conditionals';
|
|
60
|
+
const ACTION_TYPE_ENUM_NAME = 'ActionType';
|
|
61
|
+
const REQUEST_CORRECTION_TYPE = 'REQUEST_CORRECTION';
|
|
62
|
+
const CORRECTION_ACTIONS_TO_ADD = [
|
|
63
|
+
{
|
|
64
|
+
actionType: 'APPROVE_CORRECTION',
|
|
65
|
+
labelId: 'v2.events.correction.approve.label',
|
|
66
|
+
defaultMessage: 'Approve correction',
|
|
67
|
+
description: 'Label for the approve correction action'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
actionType: 'REJECT_CORRECTION',
|
|
71
|
+
labelId: 'v2.events.correction.reject.label',
|
|
72
|
+
defaultMessage: 'Reject correction',
|
|
73
|
+
description: 'Label for the reject correction action'
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Returns true if the object's `type` property matches the given type name.
|
|
78
|
+
* Handles both `ActionType.X` and the string literal `'X'` forms.
|
|
79
|
+
*/
|
|
80
|
+
function isActionOfType(obj, typeName) {
|
|
81
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
82
|
+
if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
|
|
83
|
+
return false;
|
|
84
|
+
const typeInit = typeProperty.getInitializer();
|
|
85
|
+
if (!typeInit)
|
|
86
|
+
return false;
|
|
87
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
|
|
88
|
+
return (typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME &&
|
|
89
|
+
typeInit.getName() === typeName);
|
|
90
|
+
}
|
|
91
|
+
if (ts_morph_1.Node.isStringLiteral(typeInit)) {
|
|
92
|
+
return typeInit.getLiteralValue() === typeName;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns whether `type` is written as `ActionType.X` (enum access) or as a
|
|
98
|
+
* bare string literal, so newly inserted actions can mirror the same style.
|
|
99
|
+
*/
|
|
100
|
+
function getTypeInitializerStyle(obj) {
|
|
101
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
102
|
+
if (typeProperty && ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
|
|
103
|
+
const typeInit = typeProperty.getInitializer();
|
|
104
|
+
if (typeInit && ts_morph_1.Node.isPropertyAccessExpression(typeInit))
|
|
105
|
+
return 'enum';
|
|
106
|
+
}
|
|
107
|
+
return 'string';
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the source text of `obj[propName]` if it's an array literal with
|
|
111
|
+
* at least one element, otherwise undefined.
|
|
112
|
+
*/
|
|
113
|
+
function getNonEmptyArrayPropertyText(obj, propName) {
|
|
114
|
+
const prop = obj.getProperty(propName);
|
|
115
|
+
if (!prop || !ts_morph_1.Node.isPropertyAssignment(prop))
|
|
116
|
+
return undefined;
|
|
117
|
+
const init = prop.getInitializer();
|
|
118
|
+
if (!init || !ts_morph_1.Node.isArrayLiteralExpression(init))
|
|
119
|
+
return undefined;
|
|
120
|
+
if (init.getElements().length === 0)
|
|
121
|
+
return undefined;
|
|
122
|
+
return init.getText();
|
|
123
|
+
}
|
|
124
|
+
function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
|
|
125
|
+
const typeText = typeStyle === 'enum'
|
|
126
|
+
? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}`
|
|
127
|
+
: `'${spec.actionType}'`;
|
|
128
|
+
const lines = [
|
|
129
|
+
`type: ${typeText}`,
|
|
130
|
+
`label: {
|
|
131
|
+
id: '${spec.labelId}',
|
|
132
|
+
defaultMessage: '${spec.defaultMessage}',
|
|
133
|
+
description: '${spec.description}'
|
|
134
|
+
}`
|
|
135
|
+
];
|
|
136
|
+
if (flagsText) {
|
|
137
|
+
lines.push(`${FLAGS_PROPERTY_NAME}: ${flagsText}`);
|
|
138
|
+
}
|
|
139
|
+
if (conditionalsText) {
|
|
140
|
+
lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
|
|
141
|
+
}
|
|
142
|
+
return `{\n ${lines.join(',\n ')}\n}`;
|
|
143
|
+
}
|
|
144
|
+
function processFile(filePath, project) {
|
|
145
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
146
|
+
if (!sourceFile)
|
|
147
|
+
return 0;
|
|
148
|
+
let changes = 0;
|
|
149
|
+
const relPath = path_1.default.relative(process.cwd(), filePath);
|
|
150
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
151
|
+
for (const call of callExpressions) {
|
|
152
|
+
const expression = call.getExpression();
|
|
153
|
+
if (!ts_morph_1.Node.isIdentifier(expression) ||
|
|
154
|
+
expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const args = call.getArguments();
|
|
158
|
+
if (args.length === 0)
|
|
159
|
+
continue;
|
|
160
|
+
const configArg = args[0];
|
|
161
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
|
|
162
|
+
continue;
|
|
163
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
164
|
+
if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
|
|
165
|
+
continue;
|
|
166
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
167
|
+
if (!actionsInitializer ||
|
|
168
|
+
!ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
|
|
169
|
+
continue;
|
|
170
|
+
const elements = actionsInitializer.getElements();
|
|
171
|
+
const requestCorrectionIndex = elements.findIndex((el) => ts_morph_1.Node.isObjectLiteralExpression(el) &&
|
|
172
|
+
isActionOfType(el, REQUEST_CORRECTION_TYPE));
|
|
173
|
+
if (requestCorrectionIndex === -1)
|
|
174
|
+
continue;
|
|
175
|
+
const requestCorrection = elements[requestCorrectionIndex];
|
|
176
|
+
const flagsText = getNonEmptyArrayPropertyText(requestCorrection, FLAGS_PROPERTY_NAME);
|
|
177
|
+
const conditionalsText = getNonEmptyArrayPropertyText(requestCorrection, CONDITIONALS_PROPERTY_NAME);
|
|
178
|
+
// Nothing on REQUEST_CORRECTION that approve/reject would need to inherit.
|
|
179
|
+
if (!flagsText && !conditionalsText)
|
|
180
|
+
continue;
|
|
181
|
+
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
182
|
+
let insertAt = requestCorrectionIndex + 1;
|
|
183
|
+
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
184
|
+
const alreadyPresent = actionsInitializer
|
|
185
|
+
.getElements()
|
|
186
|
+
.some((el) => ts_morph_1.Node.isObjectLiteralExpression(el) &&
|
|
187
|
+
isActionOfType(el, spec.actionType));
|
|
188
|
+
if (alreadyPresent)
|
|
189
|
+
continue;
|
|
190
|
+
const text = buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText);
|
|
191
|
+
actionsInitializer.insertElement(insertAt, text);
|
|
192
|
+
insertAt++;
|
|
193
|
+
changes++;
|
|
194
|
+
console.log(` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return changes;
|
|
198
|
+
}
|
|
199
|
+
function main() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
202
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
|
|
203
|
+
const project = new ts_morph_1.Project({
|
|
204
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
205
|
+
skipAddingFilesFromTsConfig: false
|
|
206
|
+
});
|
|
207
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
208
|
+
const fp = sf.getFilePath();
|
|
209
|
+
return fp.includes('/src/') && !fp.includes('/node_modules/');
|
|
210
|
+
});
|
|
211
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
|
|
212
|
+
let totalChanges = 0;
|
|
213
|
+
const modifiedFiles = [];
|
|
214
|
+
for (const sourceFile of sourceFiles) {
|
|
215
|
+
const filePath = sourceFile.getFilePath();
|
|
216
|
+
const changes = processFile(filePath, project);
|
|
217
|
+
if (changes > 0) {
|
|
218
|
+
totalChanges += changes;
|
|
219
|
+
modifiedFiles.push(filePath);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (modifiedFiles.length === 0) {
|
|
223
|
+
console.log('No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do.');
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
227
|
+
for (const filePath of modifiedFiles) {
|
|
228
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
229
|
+
yield sourceFile.save();
|
|
230
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
231
|
+
}
|
|
232
|
+
console.log(`\nDone. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/index.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAEpD"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/migrations/v2.1/index.ts
|
|
32
|
+
var v2_exports = {};
|
|
33
|
+
__export(v2_exports, {
|
|
34
|
+
runUpgrade: () => runUpgrade
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(v2_exports);
|
|
37
|
+
|
|
38
|
+
// src/migrations/v2.1/add-explicit-correction-flags.ts
|
|
39
|
+
var import_ts_morph = require("ts-morph");
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
42
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
43
|
+
var TYPE_PROPERTY_NAME = "type";
|
|
44
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
45
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
46
|
+
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
47
|
+
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
48
|
+
var CORRECTION_ACTIONS_TO_ADD = [
|
|
49
|
+
{
|
|
50
|
+
actionType: "APPROVE_CORRECTION",
|
|
51
|
+
labelId: "v2.events.correction.approve.label",
|
|
52
|
+
defaultMessage: "Approve correction",
|
|
53
|
+
description: "Label for the approve correction action"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
actionType: "REJECT_CORRECTION",
|
|
57
|
+
labelId: "v2.events.correction.reject.label",
|
|
58
|
+
defaultMessage: "Reject correction",
|
|
59
|
+
description: "Label for the reject correction action"
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
function isActionOfType(obj, typeName) {
|
|
63
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
64
|
+
if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) return false;
|
|
65
|
+
const typeInit = typeProperty.getInitializer();
|
|
66
|
+
if (!typeInit) return false;
|
|
67
|
+
if (import_ts_morph.Node.isPropertyAccessExpression(typeInit)) {
|
|
68
|
+
return typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === typeName;
|
|
69
|
+
}
|
|
70
|
+
if (import_ts_morph.Node.isStringLiteral(typeInit)) {
|
|
71
|
+
return typeInit.getLiteralValue() === typeName;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
function getTypeInitializerStyle(obj) {
|
|
76
|
+
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
77
|
+
if (typeProperty && import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
|
|
78
|
+
const typeInit = typeProperty.getInitializer();
|
|
79
|
+
if (typeInit && import_ts_morph.Node.isPropertyAccessExpression(typeInit)) return "enum";
|
|
80
|
+
}
|
|
81
|
+
return "string";
|
|
82
|
+
}
|
|
83
|
+
function getNonEmptyArrayPropertyText(obj, propName) {
|
|
84
|
+
const prop = obj.getProperty(propName);
|
|
85
|
+
if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
|
|
86
|
+
const init = prop.getInitializer();
|
|
87
|
+
if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
|
|
88
|
+
if (init.getElements().length === 0) return void 0;
|
|
89
|
+
return init.getText();
|
|
90
|
+
}
|
|
91
|
+
function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
|
|
92
|
+
const typeText = typeStyle === "enum" ? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}` : `'${spec.actionType}'`;
|
|
93
|
+
const lines = [
|
|
94
|
+
`type: ${typeText}`,
|
|
95
|
+
`label: {
|
|
96
|
+
id: '${spec.labelId}',
|
|
97
|
+
defaultMessage: '${spec.defaultMessage}',
|
|
98
|
+
description: '${spec.description}'
|
|
99
|
+
}`
|
|
100
|
+
];
|
|
101
|
+
if (flagsText) {
|
|
102
|
+
lines.push(`${FLAGS_PROPERTY_NAME}: ${flagsText}`);
|
|
103
|
+
}
|
|
104
|
+
if (conditionalsText) {
|
|
105
|
+
lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
|
|
106
|
+
}
|
|
107
|
+
return `{
|
|
108
|
+
${lines.join(",\n ")}
|
|
109
|
+
}`;
|
|
110
|
+
}
|
|
111
|
+
function processFile(filePath, project) {
|
|
112
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
113
|
+
if (!sourceFile) return 0;
|
|
114
|
+
let changes = 0;
|
|
115
|
+
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
116
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
117
|
+
import_ts_morph.SyntaxKind.CallExpression
|
|
118
|
+
);
|
|
119
|
+
for (const call of callExpressions) {
|
|
120
|
+
const expression = call.getExpression();
|
|
121
|
+
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const args = call.getArguments();
|
|
125
|
+
if (args.length === 0) continue;
|
|
126
|
+
const configArg = args[0];
|
|
127
|
+
if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
|
|
128
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
129
|
+
if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
|
|
130
|
+
continue;
|
|
131
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
132
|
+
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
133
|
+
continue;
|
|
134
|
+
const elements = actionsInitializer.getElements();
|
|
135
|
+
const requestCorrectionIndex = elements.findIndex(
|
|
136
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
137
|
+
);
|
|
138
|
+
if (requestCorrectionIndex === -1) continue;
|
|
139
|
+
const requestCorrection = elements[requestCorrectionIndex];
|
|
140
|
+
const flagsText = getNonEmptyArrayPropertyText(
|
|
141
|
+
requestCorrection,
|
|
142
|
+
FLAGS_PROPERTY_NAME
|
|
143
|
+
);
|
|
144
|
+
const conditionalsText = getNonEmptyArrayPropertyText(
|
|
145
|
+
requestCorrection,
|
|
146
|
+
CONDITIONALS_PROPERTY_NAME
|
|
147
|
+
);
|
|
148
|
+
if (!flagsText && !conditionalsText) continue;
|
|
149
|
+
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
150
|
+
let insertAt = requestCorrectionIndex + 1;
|
|
151
|
+
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
152
|
+
const alreadyPresent = actionsInitializer.getElements().some(
|
|
153
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
|
|
154
|
+
);
|
|
155
|
+
if (alreadyPresent) continue;
|
|
156
|
+
const text = buildCorrectionActionText(
|
|
157
|
+
spec,
|
|
158
|
+
typeStyle,
|
|
159
|
+
flagsText,
|
|
160
|
+
conditionalsText
|
|
161
|
+
);
|
|
162
|
+
actionsInitializer.insertElement(insertAt, text);
|
|
163
|
+
insertAt++;
|
|
164
|
+
changes++;
|
|
165
|
+
console.log(
|
|
166
|
+
` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return changes;
|
|
171
|
+
}
|
|
172
|
+
async function main() {
|
|
173
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
174
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
175
|
+
`);
|
|
176
|
+
const project = new import_ts_morph.Project({
|
|
177
|
+
tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
|
|
178
|
+
skipAddingFilesFromTsConfig: false
|
|
179
|
+
});
|
|
180
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
181
|
+
const fp = sf.getFilePath();
|
|
182
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
183
|
+
});
|
|
184
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
185
|
+
`);
|
|
186
|
+
let totalChanges = 0;
|
|
187
|
+
const modifiedFiles = [];
|
|
188
|
+
for (const sourceFile of sourceFiles) {
|
|
189
|
+
const filePath = sourceFile.getFilePath();
|
|
190
|
+
const changes = processFile(filePath, project);
|
|
191
|
+
if (changes > 0) {
|
|
192
|
+
totalChanges += changes;
|
|
193
|
+
modifiedFiles.push(filePath);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (modifiedFiles.length === 0) {
|
|
197
|
+
console.log(
|
|
198
|
+
"No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do."
|
|
199
|
+
);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
console.log(`
|
|
203
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
204
|
+
for (const filePath of modifiedFiles) {
|
|
205
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
206
|
+
await sourceFile.save();
|
|
207
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
208
|
+
}
|
|
209
|
+
console.log(
|
|
210
|
+
`
|
|
211
|
+
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/migrations/v2.1/index.ts
|
|
216
|
+
async function runUpgrade(dockerSwarm) {
|
|
217
|
+
await main();
|
|
218
|
+
}
|
|
@@ -118,11 +118,13 @@ var scopeOptionsPlaceEvent = z2.object({
|
|
|
118
118
|
event: scopeByEvent,
|
|
119
119
|
placeOfEvent: JurisdictionFilter.optional()
|
|
120
120
|
}).describe("Options applicable to all record scopes.");
|
|
121
|
-
var
|
|
121
|
+
var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
|
|
122
|
+
notifiedIn: JurisdictionFilter.optional(),
|
|
123
|
+
notifiedBy: UserFilter.optional(),
|
|
122
124
|
declaredIn: JurisdictionFilter.optional(),
|
|
123
125
|
declaredBy: UserFilter.optional()
|
|
124
126
|
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
125
|
-
var AllRecordScopeOptions =
|
|
127
|
+
var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
|
|
126
128
|
registeredIn: JurisdictionFilter.optional(),
|
|
127
129
|
registeredBy: UserFilter.optional()
|
|
128
130
|
}).describe(
|
|
@@ -160,6 +162,8 @@ var ResolvedScopeOptionsPlaceEvent = z2.object({
|
|
|
160
162
|
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
161
163
|
);
|
|
162
164
|
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
165
|
+
notifiedIn: UUID.nullish(),
|
|
166
|
+
notifiedBy: z2.string().optional(),
|
|
163
167
|
declaredIn: UUID.nullish(),
|
|
164
168
|
declaredBy: z2.string().optional()
|
|
165
169
|
}).describe(
|
|
@@ -205,7 +209,7 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
|
|
|
205
209
|
}),
|
|
206
210
|
z2.object({
|
|
207
211
|
type: ScopesWithDeclaredOptions,
|
|
208
|
-
options:
|
|
212
|
+
options: scopeOptionsDeclaredOrNotified.optional()
|
|
209
213
|
}),
|
|
210
214
|
z2.object({
|
|
211
215
|
type: ScopesWithFullOptions,
|
|
@@ -294,8 +298,9 @@ var EncodedScope = z2.string().brand("EncodedScope");
|
|
|
294
298
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
295
299
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
296
300
|
accessLevel: JurisdictionFilter.enum.all,
|
|
297
|
-
|
|
298
|
-
declaredIn: JurisdictionFilter.enum.all
|
|
301
|
+
notifiedIn: JurisdictionFilter.enum.all,
|
|
302
|
+
declaredIn: JurisdictionFilter.enum.all,
|
|
303
|
+
registeredIn: JurisdictionFilter.enum.all
|
|
299
304
|
};
|
|
300
305
|
|
|
301
306
|
// ../commons/src/authentication.ts
|
|
@@ -1357,6 +1362,7 @@ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
|
|
|
1357
1362
|
)
|
|
1358
1363
|
});
|
|
1359
1364
|
var LegalStatuses = z16.object({
|
|
1365
|
+
[EventStatus.enum.NOTIFIED]: ActionCreationMetadata.nullish(),
|
|
1360
1366
|
[EventStatus.enum.DECLARED]: ActionCreationMetadata.nullish(),
|
|
1361
1367
|
[EventStatus.enum.REGISTERED]: RegistrationCreationMetadata.nullish()
|
|
1362
1368
|
});
|
|
@@ -1416,6 +1422,8 @@ var EventMetadataKeys = z16.enum(EventMetadataKeysArray);
|
|
|
1416
1422
|
var EventMetadataDateFieldIdInput = z16.enum([
|
|
1417
1423
|
"createdAt",
|
|
1418
1424
|
"updatedAt",
|
|
1425
|
+
"legalStatuses.NOTIFIED.createdAt",
|
|
1426
|
+
"legalStatuses.NOTIFIED.acceptedAt",
|
|
1419
1427
|
"legalStatuses.DECLARED.createdAt",
|
|
1420
1428
|
"legalStatuses.DECLARED.acceptedAt",
|
|
1421
1429
|
"legalStatuses.REGISTERED.createdAt",
|
|
@@ -1424,6 +1432,8 @@ var EventMetadataDateFieldIdInput = z16.enum([
|
|
|
1424
1432
|
var EventMetadataDateFieldId = z16.enum([
|
|
1425
1433
|
"event.createdAt",
|
|
1426
1434
|
"event.updatedAt",
|
|
1435
|
+
"event.legalStatuses.NOTIFIED.createdAt",
|
|
1436
|
+
"event.legalStatuses.NOTIFIED.acceptedAt",
|
|
1427
1437
|
"event.legalStatuses.DECLARED.createdAt",
|
|
1428
1438
|
"event.legalStatuses.DECLARED.acceptedAt",
|
|
1429
1439
|
"event.legalStatuses.REGISTERED.createdAt",
|
|
@@ -2685,6 +2695,52 @@ var NotifyConfig = ActionConfigBase.extend(
|
|
|
2685
2695
|
type: z24.literal(ActionType.NOTIFY)
|
|
2686
2696
|
}).shape
|
|
2687
2697
|
);
|
|
2698
|
+
var DuplicateDetectedConfig = ActionConfigBase.extend(
|
|
2699
|
+
z24.object({
|
|
2700
|
+
type: z24.literal(ActionType.DUPLICATE_DETECTED),
|
|
2701
|
+
label: z24.never().optional().describe(
|
|
2702
|
+
"DUPLICATE_DETECTED is system-generated and never shown as a button, so it has no label."
|
|
2703
|
+
),
|
|
2704
|
+
supportingCopy: z24.never().optional(),
|
|
2705
|
+
icon: z24.never().optional().describe(
|
|
2706
|
+
"DUPLICATE_DETECTED is system-generated and never shown as a button, so it has no icon."
|
|
2707
|
+
),
|
|
2708
|
+
conditionals: z24.never().optional().describe(
|
|
2709
|
+
"DUPLICATE_DETECTED is system-generated and never shown as a button, so it cannot be disabled or hidden with conditionals."
|
|
2710
|
+
)
|
|
2711
|
+
}).shape
|
|
2712
|
+
);
|
|
2713
|
+
var MarkAsDuplicateConfig = ActionConfigBase.extend(
|
|
2714
|
+
z24.object({
|
|
2715
|
+
type: z24.literal(ActionType.MARK_AS_DUPLICATE)
|
|
2716
|
+
}).shape
|
|
2717
|
+
);
|
|
2718
|
+
var MarkAsNotDuplicateConfig = ActionConfigBase.extend(
|
|
2719
|
+
z24.object({
|
|
2720
|
+
type: z24.literal(ActionType.MARK_AS_NOT_DUPLICATE)
|
|
2721
|
+
}).shape
|
|
2722
|
+
);
|
|
2723
|
+
var AssignConfig = ActionConfigBase.extend(
|
|
2724
|
+
z24.object({
|
|
2725
|
+
type: z24.literal(ActionType.ASSIGN),
|
|
2726
|
+
flags: z24.never().optional().describe(
|
|
2727
|
+
"ASSIGN is a meta action excluded from flag resolution, so flags configured here would never apply."
|
|
2728
|
+
)
|
|
2729
|
+
}).shape
|
|
2730
|
+
);
|
|
2731
|
+
var UnassignConfig = ActionConfigBase.extend(
|
|
2732
|
+
z24.object({
|
|
2733
|
+
type: z24.literal(ActionType.UNASSIGN),
|
|
2734
|
+
flags: z24.never().optional().describe(
|
|
2735
|
+
"UNASSIGN is a meta action excluded from flag resolution, so flags configured here would never apply."
|
|
2736
|
+
)
|
|
2737
|
+
}).shape
|
|
2738
|
+
);
|
|
2739
|
+
var DeleteConfig = ActionConfigBase.extend(
|
|
2740
|
+
z24.object({
|
|
2741
|
+
type: z24.literal(ActionType.DELETE)
|
|
2742
|
+
}).shape
|
|
2743
|
+
);
|
|
2688
2744
|
var DeclareConfig = DeclarationActionBase.extend(
|
|
2689
2745
|
z24.object({
|
|
2690
2746
|
type: z24.literal(ActionType.DECLARE),
|
|
@@ -2747,7 +2803,17 @@ var RequestCorrectionConfig = ActionConfigBase.extend(
|
|
|
2747
2803
|
correctionForm: ActionFormConfig
|
|
2748
2804
|
}).shape
|
|
2749
2805
|
);
|
|
2750
|
-
var
|
|
2806
|
+
var ApproveCorrectionConfig = ActionConfigBase.extend(
|
|
2807
|
+
z24.object({
|
|
2808
|
+
type: z24.literal(ActionType.APPROVE_CORRECTION)
|
|
2809
|
+
}).shape
|
|
2810
|
+
);
|
|
2811
|
+
var RejectCorrectionConfig = ActionConfigBase.extend(
|
|
2812
|
+
z24.object({
|
|
2813
|
+
type: z24.literal(ActionType.REJECT_CORRECTION)
|
|
2814
|
+
}).shape
|
|
2815
|
+
);
|
|
2816
|
+
var CustomActionConfig = ActionConfigBase.extend(
|
|
2751
2817
|
z24.object({
|
|
2752
2818
|
type: z24.literal(ActionType.CUSTOM),
|
|
2753
2819
|
customActionType: z24.string().describe("Type identifier of the custom action."),
|
|
@@ -2758,7 +2824,7 @@ var CustomActionConfig = ActionConfigBase.merge(
|
|
|
2758
2824
|
auditHistoryLabel: TranslationConfig.describe(
|
|
2759
2825
|
'The label to show in audit history for this action. For example "Approved".'
|
|
2760
2826
|
)
|
|
2761
|
-
})
|
|
2827
|
+
}).shape
|
|
2762
2828
|
);
|
|
2763
2829
|
var ActionConfig = z24.discriminatedUnion("type", [
|
|
2764
2830
|
/*
|
|
@@ -2769,6 +2835,18 @@ var ActionConfig = z24.discriminatedUnion("type", [
|
|
|
2769
2835
|
id: "ReadActionConfig",
|
|
2770
2836
|
description: "Configuration for the read action \u2014 defines the record-tab content displayed on the event overview page."
|
|
2771
2837
|
}),
|
|
2838
|
+
AssignConfig.meta({
|
|
2839
|
+
id: "AssignActionConfig",
|
|
2840
|
+
description: "Configuration for assigning a record to the current user."
|
|
2841
|
+
}),
|
|
2842
|
+
UnassignConfig.meta({
|
|
2843
|
+
id: "UnassignActionConfig",
|
|
2844
|
+
description: "Configuration for unassigning a record from its current assignee."
|
|
2845
|
+
}),
|
|
2846
|
+
DeleteConfig.meta({
|
|
2847
|
+
id: "DeleteActionConfig",
|
|
2848
|
+
description: "Configuration for deleting a draft record."
|
|
2849
|
+
}),
|
|
2772
2850
|
NotifyConfig.meta({
|
|
2773
2851
|
id: "NotifyActionConfig",
|
|
2774
2852
|
description: "Configuration for the notify action. When present, NOTIFY uses this config independently from DECLARE. When absent, NOTIFY falls back to the DeclareActionConfig."
|
|
@@ -2777,6 +2855,18 @@ var ActionConfig = z24.discriminatedUnion("type", [
|
|
|
2777
2855
|
id: "DeclareActionConfig",
|
|
2778
2856
|
description: "Configuration for the declare action. Includes review-page fields. NOTIFY falls back to this config when no dedicated NotifyActionConfig is provided."
|
|
2779
2857
|
}),
|
|
2858
|
+
DuplicateDetectedConfig.meta({
|
|
2859
|
+
id: "DuplicateDetectedActionConfig",
|
|
2860
|
+
description: "Configuration for the system-generated duplicate-detection action. Never shown as a button, so it only supports flags \u2014 not label, icon, or conditionals."
|
|
2861
|
+
}),
|
|
2862
|
+
MarkAsDuplicateConfig.meta({
|
|
2863
|
+
id: "MarkAsDuplicateActionConfig",
|
|
2864
|
+
description: "Configuration for marking a record as a duplicate."
|
|
2865
|
+
}),
|
|
2866
|
+
MarkAsNotDuplicateConfig.meta({
|
|
2867
|
+
id: "MarkAsNotDuplicateActionConfig",
|
|
2868
|
+
description: "Configuration for marking a record as not a duplicate, after it was previously flagged as one."
|
|
2869
|
+
}),
|
|
2780
2870
|
RejectConfig.meta({
|
|
2781
2871
|
id: "RejectActionConfig",
|
|
2782
2872
|
description: "Configuration for rejecting a record before registration."
|
|
@@ -2793,6 +2883,14 @@ var ActionConfig = z24.discriminatedUnion("type", [
|
|
|
2793
2883
|
id: "RequestCorrectionActionConfig",
|
|
2794
2884
|
description: "Configuration for requesting a correction on a registered record."
|
|
2795
2885
|
}),
|
|
2886
|
+
ApproveCorrectionConfig.meta({
|
|
2887
|
+
id: "ApproveCorrectionActionConfig",
|
|
2888
|
+
description: "Configuration for approving a requested correction."
|
|
2889
|
+
}),
|
|
2890
|
+
RejectCorrectionConfig.meta({
|
|
2891
|
+
id: "RejectCorrectionActionConfig",
|
|
2892
|
+
description: "Configuration for rejecting a requested correction."
|
|
2893
|
+
}),
|
|
2796
2894
|
EditActionConfig.meta({
|
|
2797
2895
|
id: "EditActionConfig",
|
|
2798
2896
|
description: "Configuration for editing a record before registration."
|
|
@@ -3920,7 +4018,7 @@ function validateActionFlags(event2, ctx) {
|
|
|
3920
4018
|
const isInherentFlag = (value) => Object.values(InherentFlags).includes(value);
|
|
3921
4019
|
const configuredFlagIds = event2.flags.map((flag) => flag.id);
|
|
3922
4020
|
const actionFlagIds = event2.actions.flatMap(
|
|
3923
|
-
(action) => action.flags.map((flag) => flag.id)
|
|
4021
|
+
(action) => (action.flags ?? []).map((flag) => flag.id)
|
|
3924
4022
|
);
|
|
3925
4023
|
for (const actionFlagId of actionFlagIds) {
|
|
3926
4024
|
const isConfigured = configuredFlagIds.includes(actionFlagId);
|