@opencrvs/toolkit 2.0.0-rc.e94ba6c → 2.0.0-rc.e9eb54d
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/README.md +15 -0
- package/build.sh +5 -4
- package/create-countryconfig/index.js +50 -20
- package/create-countryconfig/package.json +12 -2
- package/dist/application-config/index.js +286 -123
- package/dist/cli.js +3219 -4778
- package/dist/commons/api/router.d.ts +3367 -217
- package/dist/commons/application-config/index.d.ts +1 -0
- package/dist/commons/conditionals/conditionals.d.ts +357 -7
- 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 +354 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
- package/dist/commons/events/Draft.d.ts +4 -2
- package/dist/commons/events/EventConfig.d.ts +2 -0
- package/dist/commons/events/EventDocument.d.ts +3 -0
- package/dist/commons/events/EventIndex.d.ts +25 -3
- package/dist/commons/events/EventMetadata.d.ts +26 -7
- package/dist/commons/events/FieldConfig.d.ts +388 -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/locations.d.ts +1 -0
- package/dist/commons/events/state/flags.d.ts +16 -0
- package/dist/commons/events/state/index.d.ts +8 -4
- package/dist/commons/events/state/utils.d.ts +21 -289
- package/dist/commons/events/utils.d.ts +13 -2
- package/dist/conditionals/index.js +63 -5
- package/dist/environment/custom-types.d.ts +33 -0
- package/dist/environment/custom-types.d.ts.map +1 -0
- package/dist/environment/custom-types.js +12 -0
- package/dist/environment/derived-variables.d.ts +134 -0
- package/dist/environment/derived-variables.d.ts.map +1 -0
- package/dist/environment/derived-variables.js +169 -0
- package/dist/environment/editor-questions.d.ts +4 -0
- package/dist/environment/editor-questions.d.ts.map +1 -0
- package/dist/environment/editor-questions.js +67 -0
- package/dist/environment/git.d.ts +5 -0
- package/dist/environment/git.d.ts.map +1 -0
- package/dist/environment/git.js +38 -0
- package/dist/environment/github.d.ts +26 -0
- package/dist/environment/github.d.ts.map +1 -0
- package/dist/environment/github.js +247 -0
- package/dist/environment/index.d.ts +5 -0
- package/dist/environment/index.d.ts.map +1 -0
- package/dist/environment/index.js +71 -0
- package/dist/environment/logger.d.ts +15 -0
- package/dist/environment/logger.d.ts.map +1 -0
- package/dist/environment/logger.js +25 -0
- package/dist/environment/manage-users.d.ts +11 -0
- package/dist/environment/manage-users.d.ts.map +1 -0
- package/dist/environment/manage-users.js +497 -0
- package/dist/environment/questions-helper.d.ts +15 -0
- package/dist/environment/questions-helper.d.ts.map +1 -0
- package/dist/environment/questions-helper.js +70 -0
- package/dist/environment/questions.d.ts +199 -0
- package/dist/environment/questions.d.ts.map +1 -0
- package/dist/environment/questions.js +412 -0
- package/dist/environment/setup-environment.d.ts +2 -0
- package/dist/environment/setup-environment.d.ts.map +1 -0
- package/dist/environment/setup-environment.js +794 -0
- package/dist/environment/ssh-keygen.d.ts +5 -0
- package/dist/environment/ssh-keygen.d.ts.map +1 -0
- package/dist/environment/ssh-keygen.js +21 -0
- package/dist/environment/swarm-to-k8s.d.ts +2 -0
- package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
- package/dist/environment/swarm-to-k8s.js +173 -0
- package/dist/environment/templates.d.ts +27 -0
- package/dist/environment/templates.d.ts.map +1 -0
- package/dist/environment/templates.js +163 -0
- package/dist/environment/update-workflows.d.ts +2 -0
- package/dist/environment/update-workflows.d.ts.map +1 -0
- package/dist/environment/update-workflows.js +169 -0
- package/dist/environment/users.d.ts +2 -0
- package/dist/environment/users.d.ts.map +1 -0
- package/dist/environment/users.js +112 -0
- package/dist/environment/utils.d.ts +18 -0
- package/dist/environment/utils.d.ts.map +1 -0
- package/dist/environment/utils.js +100 -0
- package/dist/events/index.js +1205 -295
- 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 -1
- 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.map +1 -1
- package/dist/migrations/v2.0/index.js +88 -4963
- 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.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 +1005 -162
- package/dist/scopes/index.d.ts +93 -7
- package/dist/scopes/index.js +20 -7
- package/dist/templates/charts-values/dependencies/values.override.yaml +4 -0
- package/dist/templates/charts-values/dependencies/values.yaml +83 -0
- package/dist/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +81 -0
- package/dist/templates/charts-values/traefik/values.override.yaml +4 -0
- package/dist/templates/charts-values/traefik/values.yaml +115 -0
- package/dist/templates/inventory/inventory.template.yml +100 -0
- package/dist/templates/inventory/production.example.yml +77 -0
- package/dist/templates/inventory/qa.example.yml +48 -0
- package/opencrvs-toolkit-2.0.0-rc.e9eb54d.tgz +0 -0
- package/package.json +20 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.e94ba6c.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAoXA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.main = main;
|
|
26
26
|
const ts_morph_1 = require("ts-morph");
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const scopes_1 = require("../commons/scopes");
|
|
29
28
|
const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
|
|
30
29
|
const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
|
|
31
30
|
const SCOPES_PROPERTY_NAME = 'scopes';
|
|
@@ -65,60 +64,85 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
65
64
|
}
|
|
66
65
|
return null;
|
|
67
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Walks each `scopes: [...]` array in the roles file, classifies elements,
|
|
69
|
+
* and rewrites the whole array using `migrateLegacyScopesArrayToV2Scopes`
|
|
70
|
+
* (which preserves v1.9 AND semantics by merging pairs of legacy scopes
|
|
71
|
+
* that targeted the same v2 type). See issue #12489.
|
|
72
|
+
*
|
|
73
|
+
* Elements are partitioned into three kinds:
|
|
74
|
+
* - drop: `SCOPES.X` references where X is not in the SCOPES map (warned
|
|
75
|
+
* and removed, matching pre-refactor behavior).
|
|
76
|
+
* - raw: non-literal expressions we cannot statically resolve (e.g.
|
|
77
|
+
* `...sharedScopes` spreads). Preserved verbatim in output so authoring
|
|
78
|
+
* intent isn't lost.
|
|
79
|
+
* - legacy: literal strings or resolvable `SCOPES.X` references.
|
|
80
|
+
* Collected and passed as a batch to the merge function.
|
|
81
|
+
*
|
|
82
|
+
* The output array text is `[...rawTexts, ...mergedScopesAsJson]`. Order of
|
|
83
|
+
* legacy entries relative to raw expressions is not preserved — scopes in a
|
|
84
|
+
* v2 array compose with OR, so position is semantically irrelevant.
|
|
85
|
+
*/
|
|
68
86
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
69
87
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
70
|
-
if (!sourceFile)
|
|
71
|
-
return { migratedCount: 0, removedCount: 0 };
|
|
88
|
+
if (!sourceFile) {
|
|
89
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
90
|
+
}
|
|
72
91
|
let migratedCount = 0;
|
|
73
92
|
let removedCount = 0;
|
|
93
|
+
let mergedCount = 0;
|
|
74
94
|
const scopesProperties = sourceFile
|
|
75
95
|
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
76
96
|
.filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
97
|
+
const relPath = path_1.default.relative(process.cwd(), rolesFilePath);
|
|
77
98
|
for (const scopesProp of scopesProperties) {
|
|
78
99
|
const initializer = scopesProp.getInitializer();
|
|
79
100
|
if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
|
|
80
101
|
continue;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
continue;
|
|
102
|
+
const rawTexts = [];
|
|
103
|
+
const legacyStrings = [];
|
|
104
|
+
let anyChange = false;
|
|
105
|
+
for (const element of initializer.getElements()) {
|
|
86
106
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
87
107
|
if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
|
|
88
108
|
// eslint-disable-next-line no-console
|
|
89
|
-
console.warn(` [${
|
|
90
|
-
initializer.removeElement(index);
|
|
109
|
+
console.warn(` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`);
|
|
91
110
|
removedCount++;
|
|
111
|
+
anyChange = true;
|
|
92
112
|
continue;
|
|
93
113
|
}
|
|
94
114
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
95
115
|
if (!legacyScope) {
|
|
96
116
|
// eslint-disable-next-line no-console
|
|
97
|
-
console.warn(` [${
|
|
117
|
+
console.warn(` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`);
|
|
118
|
+
rawTexts.push(element.getText());
|
|
98
119
|
continue;
|
|
99
120
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
|
|
114
|
-
}
|
|
121
|
+
legacyStrings.push(legacyScope);
|
|
122
|
+
anyChange = true;
|
|
123
|
+
}
|
|
124
|
+
if (!anyChange)
|
|
125
|
+
continue;
|
|
126
|
+
let mergedScopes;
|
|
127
|
+
try {
|
|
128
|
+
mergedScopes = (0, scopes_deprecated_do_not_use_1.migrateLegacyScopesArrayToV2Scopes)(legacyStrings);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw new Error(`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
115
132
|
}
|
|
133
|
+
migratedCount += legacyStrings.length;
|
|
134
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
135
|
+
const outputElements = [
|
|
136
|
+
...rawTexts,
|
|
137
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
138
|
+
];
|
|
139
|
+
scopesProp.setInitializer(`[${outputElements.join(', ')}]`);
|
|
116
140
|
}
|
|
117
141
|
if (removedCount > 0) {
|
|
118
142
|
// eslint-disable-next-line no-console
|
|
119
|
-
console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
143
|
+
console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`);
|
|
120
144
|
}
|
|
121
|
-
return { migratedCount, removedCount };
|
|
145
|
+
return { migratedCount, removedCount, mergedCount };
|
|
122
146
|
}
|
|
123
147
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
124
148
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -262,7 +286,7 @@ function main() {
|
|
|
262
286
|
return;
|
|
263
287
|
}
|
|
264
288
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
265
|
-
const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
|
|
289
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(rolesFilePath, project);
|
|
266
290
|
const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
|
|
267
291
|
const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
|
|
268
292
|
const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
|
|
@@ -276,6 +300,6 @@ function main() {
|
|
|
276
300
|
return;
|
|
277
301
|
}
|
|
278
302
|
yield sourceFile.save();
|
|
279
|
-
console.log(`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
|
|
303
|
+
console.log(`Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
|
|
280
304
|
});
|
|
281
305
|
}
|
|
@@ -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
|
+
}
|