@opencrvs/toolkit 2.0.0-rc.153df7b → 2.0.0-rc.15555da
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/create-countryconfig/index.js +103 -0
- package/create-countryconfig/package.json +21 -0
- package/dist/application-config/index.js +312 -130
- package/dist/cli.js +922 -205
- package/dist/commons/api/router.d.ts +3407 -271
- package/dist/commons/application-config/index.d.ts +17 -4
- package/dist/commons/conditionals/conditionals.d.ts +360 -10
- package/dist/commons/conditionals/validate.d.ts +52 -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/Draft.d.ts +4 -2
- package/dist/commons/events/EventDocument.d.ts +3 -0
- package/dist/commons/events/EventIndex.d.ts +0 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -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 +150 -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 +38 -1
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- 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 +92 -9
- package/dist/events/index.js +1104 -271
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +60 -35
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- 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 +920 -203
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
- 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/notification/index.js +857 -161
- package/dist/scopes/index.d.ts +91 -16
- package/dist/scopes/index.js +55 -12
- package/opencrvs-toolkit-2.0.0-rc.15555da.tgz +0 -0
- package/package.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.153df7b.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -178,6 +178,8 @@ function ensureImports(sourceFile) {
|
|
|
178
178
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
179
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
180
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
+
var ID_PROPERTY_NAME = "id";
|
|
182
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
181
183
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
182
184
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
183
185
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -187,9 +189,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
187
189
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
188
190
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
189
191
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
190
193
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
191
194
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
192
196
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
193
198
|
function isValidateType(typeInitializer) {
|
|
194
199
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
195
200
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -313,6 +318,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
313
318
|
}
|
|
314
319
|
return true;
|
|
315
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
|
+
}
|
|
316
365
|
function processFile2(filePath, project) {
|
|
317
366
|
const sourceFile = project.getSourceFile(filePath);
|
|
318
367
|
if (!sourceFile) return 0;
|
|
@@ -378,6 +427,18 @@ function processFile2(filePath, project) {
|
|
|
378
427
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
428
|
);
|
|
380
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
|
+
}
|
|
381
442
|
if (fileNeedsImports) {
|
|
382
443
|
ensureImports(sourceFile);
|
|
383
444
|
}
|
|
@@ -424,7 +485,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
424
485
|
}
|
|
425
486
|
console.log(
|
|
426
487
|
`
|
|
427
|
-
Done.
|
|
488
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
428
489
|
);
|
|
429
490
|
}
|
|
430
491
|
|
|
@@ -667,14 +728,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
667
728
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
668
729
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
669
730
|
var STATUS_PROPERTY_NAME = "status";
|
|
670
|
-
var
|
|
731
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
671
732
|
var TERMS_PROPERTY_NAME = "terms";
|
|
672
733
|
var TERM_PROPERTY_NAME = "term";
|
|
673
734
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
674
735
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
675
|
-
var
|
|
736
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
676
737
|
function addValidatedFlag(clause) {
|
|
677
|
-
const flagsProperty = clause.getProperty(
|
|
738
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
678
739
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
679
740
|
const flagsInit = flagsProperty.getInitializer();
|
|
680
741
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -682,19 +743,19 @@ function addValidatedFlag(clause) {
|
|
|
682
743
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
683
744
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
684
745
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
685
|
-
anyOfInit.addElement(`'${
|
|
746
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
686
747
|
}
|
|
687
748
|
} else {
|
|
688
749
|
flagsInit.addPropertyAssignment({
|
|
689
750
|
name: ANY_OF_PROPERTY_NAME,
|
|
690
|
-
initializer: `['${
|
|
751
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
691
752
|
});
|
|
692
753
|
}
|
|
693
754
|
}
|
|
694
755
|
} else {
|
|
695
756
|
clause.addPropertyAssignment({
|
|
696
|
-
name:
|
|
697
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
757
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
758
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
698
759
|
});
|
|
699
760
|
}
|
|
700
761
|
}
|
|
@@ -860,23 +921,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
860
921
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
861
922
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
862
923
|
var ACTION_PROPERTY_NAME = "action";
|
|
863
|
-
var
|
|
924
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
864
925
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
926
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
866
928
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
929
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
930
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
931
|
var REGISTER_TYPE = "REGISTER";
|
|
870
932
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
-
|
|
933
|
+
function flagDefinitionInitializer(eventType) {
|
|
934
|
+
return `{
|
|
872
935
|
id: '${FLAG_ID}',
|
|
873
936
|
label: {
|
|
874
|
-
id: 'event.
|
|
937
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
875
938
|
defaultMessage: 'Pending first certificate issuance',
|
|
876
939
|
description: 'Flag label for first certificate issuance'
|
|
877
940
|
},
|
|
878
941
|
requiresAction: true
|
|
879
942
|
}`;
|
|
943
|
+
}
|
|
880
944
|
function isActionOfType(obj, typeName) {
|
|
881
945
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
946
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -890,18 +954,20 @@ function isActionOfType(obj, typeName) {
|
|
|
890
954
|
}
|
|
891
955
|
return false;
|
|
892
956
|
}
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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
|
+
}
|
|
903
969
|
}
|
|
904
|
-
return
|
|
970
|
+
return null;
|
|
905
971
|
}
|
|
906
972
|
function hasElementWithId(array3, id) {
|
|
907
973
|
for (const el of array3.getElements()) {
|
|
@@ -915,27 +981,28 @@ function hasElementWithId(array3, id) {
|
|
|
915
981
|
}
|
|
916
982
|
return false;
|
|
917
983
|
}
|
|
918
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
-
const
|
|
984
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
985
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
986
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
920
987
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
988
|
const flagsInit = flagsProp.getInitializer();
|
|
922
989
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
990
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
-
flagsInit.addElement(
|
|
991
|
+
flagsInit.addElement(initializer);
|
|
925
992
|
return true;
|
|
926
993
|
}
|
|
927
994
|
return false;
|
|
928
995
|
}
|
|
929
996
|
configArg.addPropertyAssignment({
|
|
930
|
-
name:
|
|
997
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
931
998
|
initializer: `[
|
|
932
|
-
${
|
|
999
|
+
${initializer}
|
|
933
1000
|
]`
|
|
934
1001
|
});
|
|
935
1002
|
return true;
|
|
936
1003
|
}
|
|
937
1004
|
function ensureActionOperationFlag(action, operation) {
|
|
938
|
-
const flagsProp = action.getProperty(
|
|
1005
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
939
1006
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
940
1007
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
941
1008
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -947,16 +1014,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
947
1014
|
return false;
|
|
948
1015
|
}
|
|
949
1016
|
action.addPropertyAssignment({
|
|
950
|
-
name:
|
|
1017
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
951
1018
|
initializer: `[${entry}]`
|
|
952
1019
|
});
|
|
953
1020
|
return true;
|
|
954
1021
|
}
|
|
955
|
-
function
|
|
1022
|
+
function processConfig(configArg, eventType, relPath) {
|
|
956
1023
|
let changes = 0;
|
|
957
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1024
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
958
1025
|
changes++;
|
|
959
|
-
console.log(
|
|
1026
|
+
console.log(
|
|
1027
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
+
);
|
|
960
1029
|
}
|
|
961
1030
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
1031
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -970,7 +1039,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
970
1039
|
if (ensureActionOperationFlag(element, "add")) {
|
|
971
1040
|
changes++;
|
|
972
1041
|
console.log(
|
|
973
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1042
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
1043
|
);
|
|
975
1044
|
}
|
|
976
1045
|
}
|
|
@@ -978,7 +1047,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
978
1047
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
1048
|
changes++;
|
|
980
1049
|
console.log(
|
|
981
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1050
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
1051
|
);
|
|
983
1052
|
}
|
|
984
1053
|
}
|
|
@@ -1007,7 +1076,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1007
1076
|
return false;
|
|
1008
1077
|
}
|
|
1009
1078
|
function addFlagToQueryClause(clause) {
|
|
1010
|
-
const flagsProp = clause.getProperty(
|
|
1079
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1011
1080
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1012
1081
|
const flagsInit = flagsProp.getInitializer();
|
|
1013
1082
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1032,7 +1101,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1032
1101
|
}
|
|
1033
1102
|
} else {
|
|
1034
1103
|
clause.addPropertyAssignment({
|
|
1035
|
-
name:
|
|
1104
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1036
1105
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1037
1106
|
});
|
|
1038
1107
|
return true;
|
|
@@ -1076,8 +1145,9 @@ function processFile6(filePath, project) {
|
|
|
1076
1145
|
if (args2.length === 0) continue;
|
|
1077
1146
|
const configArg = args2[0];
|
|
1078
1147
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
-
|
|
1080
|
-
|
|
1148
|
+
const eventType = getEventType(configArg);
|
|
1149
|
+
if (!eventType) continue;
|
|
1150
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1081
1151
|
}
|
|
1082
1152
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
1153
|
const args2 = call.getArguments();
|
|
@@ -1106,7 +1176,7 @@ function processFile6(filePath, project) {
|
|
|
1106
1176
|
async function main6() {
|
|
1107
1177
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1178
|
console.log(
|
|
1109
|
-
`Scanning for
|
|
1179
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1180
|
`
|
|
1111
1181
|
);
|
|
1112
1182
|
const project = new import_ts_morph6.Project({
|
|
@@ -1131,7 +1201,7 @@ async function main6() {
|
|
|
1131
1201
|
}
|
|
1132
1202
|
if (modifiedFiles.length === 0) {
|
|
1133
1203
|
console.log(
|
|
1134
|
-
"No
|
|
1204
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
1205
|
);
|
|
1136
1206
|
return;
|
|
1137
1207
|
}
|
|
@@ -1813,9 +1883,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1813
1883
|
}
|
|
1814
1884
|
return replacedCount;
|
|
1815
1885
|
}
|
|
1816
|
-
function resolveConfigChain(configObj,
|
|
1886
|
+
function resolveConfigChain(configObj, path24) {
|
|
1817
1887
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1888
|
+
for (const key of path24) {
|
|
1819
1889
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1820
1890
|
const prop = current.getProperty(key);
|
|
1821
1891
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -2050,6 +2120,10 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
|
|
|
2050
2120
|
var import_ts_morph11 = require("ts-morph");
|
|
2051
2121
|
var import_path11 = __toESM(require("path"));
|
|
2052
2122
|
|
|
2123
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2124
|
+
var z4 = __toESM(require("zod/v4"));
|
|
2125
|
+
var import_lodash = require("lodash");
|
|
2126
|
+
|
|
2053
2127
|
// ../commons/src/scopes.ts
|
|
2054
2128
|
var z3 = __toESM(require("zod/v4"));
|
|
2055
2129
|
var qs = __toESM(require("qs"));
|
|
@@ -2110,6 +2184,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
2110
2184
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2111
2185
|
z3.array(z3.string()).optional()
|
|
2112
2186
|
).describe("Event type, e.g. birth, death");
|
|
2187
|
+
var userRole = z3.preprocess(
|
|
2188
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2189
|
+
z3.array(z3.string()).optional()
|
|
2190
|
+
).describe("User role, e.g. admin, field agent");
|
|
2113
2191
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2114
2192
|
event: scopeByEvent,
|
|
2115
2193
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2133,6 +2211,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2133
2211
|
var AccessLevelOptions = z3.object({
|
|
2134
2212
|
accessLevel: JurisdictionFilter.optional()
|
|
2135
2213
|
});
|
|
2214
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2215
|
+
role: userRole.optional()
|
|
2216
|
+
});
|
|
2136
2217
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2137
2218
|
ids: z3.preprocess(
|
|
2138
2219
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2142,6 +2223,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2142
2223
|
var AllScopeOptions = z3.object({
|
|
2143
2224
|
...AllRecordScopeOptions.shape,
|
|
2144
2225
|
...AccessLevelOptions.shape,
|
|
2226
|
+
...AllUserScopeOptions.shape,
|
|
2145
2227
|
...WorkqueueOrDashboardOptions.shape
|
|
2146
2228
|
});
|
|
2147
2229
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2214,6 +2296,30 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2214
2296
|
]).describe(
|
|
2215
2297
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2216
2298
|
);
|
|
2299
|
+
var SystemScopeType = z3.enum([
|
|
2300
|
+
"organisation.read-locations",
|
|
2301
|
+
"user.read",
|
|
2302
|
+
"user.create",
|
|
2303
|
+
"user.edit",
|
|
2304
|
+
"user.search"
|
|
2305
|
+
]);
|
|
2306
|
+
var UserScopeType = SystemScopeType.extract([
|
|
2307
|
+
"user.read",
|
|
2308
|
+
"user.create",
|
|
2309
|
+
"user.edit",
|
|
2310
|
+
"user.search"
|
|
2311
|
+
]);
|
|
2312
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2313
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2314
|
+
z3.object({
|
|
2315
|
+
type: ScopesWithRoleOption,
|
|
2316
|
+
options: AllUserScopeOptions.optional()
|
|
2317
|
+
}),
|
|
2318
|
+
z3.object({
|
|
2319
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2320
|
+
options: AccessLevelOptions.optional()
|
|
2321
|
+
})
|
|
2322
|
+
]);
|
|
2217
2323
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2218
2324
|
z3.object({
|
|
2219
2325
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2234,16 +2340,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2234
2340
|
}).optional()
|
|
2235
2341
|
})
|
|
2236
2342
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2237
|
-
var SystemScopeType = z3.enum([
|
|
2238
|
-
"organisation.read-locations",
|
|
2239
|
-
"user.read",
|
|
2240
|
-
"user.create",
|
|
2241
|
-
"user.edit"
|
|
2242
|
-
]);
|
|
2243
2343
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2244
2344
|
z3.object({ type: PlainScopeType }),
|
|
2245
2345
|
...RecordScopeV2.options,
|
|
2246
|
-
|
|
2346
|
+
...UserScopeV2.options,
|
|
2347
|
+
z3.object({
|
|
2348
|
+
type: z3.literal("organisation.read-locations"),
|
|
2349
|
+
options: AccessLevelOptions.optional()
|
|
2350
|
+
}),
|
|
2247
2351
|
z3.object({
|
|
2248
2352
|
type: z3.literal("workqueue"),
|
|
2249
2353
|
options: WorkqueueOrDashboardOptions
|
|
@@ -2278,22 +2382,29 @@ var encodeScope = (scope) => {
|
|
|
2278
2382
|
encode: false
|
|
2279
2383
|
});
|
|
2280
2384
|
};
|
|
2281
|
-
var
|
|
2282
|
-
|
|
2385
|
+
var decodedScopeCache = /* @__PURE__ */ new Map();
|
|
2386
|
+
var decodeScope = (encodedScope) => {
|
|
2387
|
+
if (decodedScopeCache.has(encodedScope)) {
|
|
2388
|
+
return decodedScopeCache.get(encodedScope);
|
|
2389
|
+
}
|
|
2390
|
+
const scope = qs.parse(encodedScope, {
|
|
2283
2391
|
ignoreQueryPrefix: true,
|
|
2284
2392
|
comma: true,
|
|
2285
2393
|
allowDots: true
|
|
2286
2394
|
});
|
|
2287
2395
|
const unflattenedScope = unflattenScope(scope);
|
|
2288
|
-
|
|
2396
|
+
const result = Scope2.safeParse(unflattenedScope)?.data;
|
|
2397
|
+
decodedScopeCache.set(encodedScope, result);
|
|
2398
|
+
return result;
|
|
2289
2399
|
};
|
|
2290
2400
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
2291
2401
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2292
|
-
accessLevel: JurisdictionFilter.enum.all
|
|
2402
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
2403
|
+
registeredIn: JurisdictionFilter.enum.all,
|
|
2404
|
+
declaredIn: JurisdictionFilter.enum.all
|
|
2293
2405
|
};
|
|
2294
2406
|
|
|
2295
2407
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2296
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2297
2408
|
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2298
2409
|
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2299
2410
|
var SearchScope = z4.object({
|
|
@@ -2527,6 +2638,74 @@ var legacyScopeToV2Scope = (v1Scope) => {
|
|
|
2527
2638
|
}
|
|
2528
2639
|
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2529
2640
|
};
|
|
2641
|
+
var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
|
|
2642
|
+
function isMergeableUserScopeType(type) {
|
|
2643
|
+
return MERGEABLE_USER_SCOPE_TYPES.includes(type);
|
|
2644
|
+
}
|
|
2645
|
+
function decodeLegacyScope(legacy) {
|
|
2646
|
+
const encoded = legacyScopeToV2Scope(legacy);
|
|
2647
|
+
const scope = decodeScope(encoded);
|
|
2648
|
+
if (!scope) {
|
|
2649
|
+
throw new Error(
|
|
2650
|
+
`Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
return { legacy, scope };
|
|
2654
|
+
}
|
|
2655
|
+
function groupByType(entries) {
|
|
2656
|
+
return entries.reduce(
|
|
2657
|
+
(groups, entry) => ({
|
|
2658
|
+
...groups,
|
|
2659
|
+
[entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
|
|
2660
|
+
}),
|
|
2661
|
+
{}
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2664
|
+
function deduplicateEntries(entries) {
|
|
2665
|
+
return entries.filter(
|
|
2666
|
+
(entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
|
|
2667
|
+
);
|
|
2668
|
+
}
|
|
2669
|
+
function mergeEntries(type, entries) {
|
|
2670
|
+
const optionsList = entries.map(
|
|
2671
|
+
(e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
|
|
2672
|
+
);
|
|
2673
|
+
const allKeys = optionsList.flatMap(
|
|
2674
|
+
(opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
|
|
2675
|
+
);
|
|
2676
|
+
const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
|
|
2677
|
+
if (conflictKey) {
|
|
2678
|
+
const conflicting = entries.filter(
|
|
2679
|
+
(e) => conflictKey in ("options" in e.scope && e.scope.options || {})
|
|
2680
|
+
).map((e) => JSON.stringify(e.legacy));
|
|
2681
|
+
throw new Error(
|
|
2682
|
+
`Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
const mergedOptions = Object.assign({}, ...optionsList);
|
|
2686
|
+
const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
|
|
2687
|
+
const parsed = Scope2.safeParse(merged);
|
|
2688
|
+
if (!parsed.success) {
|
|
2689
|
+
throw new Error(
|
|
2690
|
+
`Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
return parsed.data;
|
|
2694
|
+
}
|
|
2695
|
+
function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
|
|
2696
|
+
const groups = groupByType(legacyScopes.map(decodeLegacyScope));
|
|
2697
|
+
return Object.entries(groups).flatMap(([type, entries]) => {
|
|
2698
|
+
const deduped = deduplicateEntries(entries);
|
|
2699
|
+
if (deduped.length <= 1) return deduped.map((e) => e.scope);
|
|
2700
|
+
if (!isMergeableUserScopeType(type)) {
|
|
2701
|
+
console.warn(
|
|
2702
|
+
`Multiple non-mergeable '${type}' scopes detected after dedup \u2014 kept all as-is. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}]. Review whether the duplication is intentional.`
|
|
2703
|
+
);
|
|
2704
|
+
return deduped.map((e) => e.scope);
|
|
2705
|
+
}
|
|
2706
|
+
return [mergeEntries(type, deduped)];
|
|
2707
|
+
});
|
|
2708
|
+
}
|
|
2530
2709
|
|
|
2531
2710
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2532
2711
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
@@ -2564,57 +2743,65 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2564
2743
|
}
|
|
2565
2744
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
2566
2745
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2567
|
-
if (!sourceFile)
|
|
2746
|
+
if (!sourceFile) {
|
|
2747
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
2748
|
+
}
|
|
2568
2749
|
let migratedCount = 0;
|
|
2569
2750
|
let removedCount = 0;
|
|
2751
|
+
let mergedCount = 0;
|
|
2570
2752
|
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2753
|
+
const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
|
|
2571
2754
|
for (const scopesProp of scopesProperties) {
|
|
2572
2755
|
const initializer = scopesProp.getInitializer();
|
|
2573
2756
|
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2574
|
-
const
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2757
|
+
const rawTexts = [];
|
|
2758
|
+
const legacyStrings = [];
|
|
2759
|
+
let anyChange = false;
|
|
2760
|
+
for (const element of initializer.getElements()) {
|
|
2578
2761
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2579
2762
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2580
2763
|
console.warn(
|
|
2581
|
-
` [${
|
|
2764
|
+
` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2582
2765
|
);
|
|
2583
|
-
initializer.removeElement(index);
|
|
2584
2766
|
removedCount++;
|
|
2767
|
+
anyChange = true;
|
|
2585
2768
|
continue;
|
|
2586
2769
|
}
|
|
2587
2770
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2588
2771
|
if (!legacyScope) {
|
|
2589
2772
|
console.warn(
|
|
2590
|
-
` [${
|
|
2773
|
+
` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
|
|
2591
2774
|
);
|
|
2775
|
+
rawTexts.push(element.getText());
|
|
2592
2776
|
continue;
|
|
2593
2777
|
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
console.warn(
|
|
2607
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2608
|
-
);
|
|
2609
|
-
}
|
|
2778
|
+
legacyStrings.push(legacyScope);
|
|
2779
|
+
anyChange = true;
|
|
2780
|
+
}
|
|
2781
|
+
if (!anyChange) continue;
|
|
2782
|
+
let mergedScopes;
|
|
2783
|
+
try {
|
|
2784
|
+
mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
|
|
2785
|
+
} catch (error) {
|
|
2786
|
+
throw new Error(
|
|
2787
|
+
`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
|
|
2788
|
+
{ cause: error }
|
|
2789
|
+
);
|
|
2610
2790
|
}
|
|
2791
|
+
migratedCount += legacyStrings.length;
|
|
2792
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
2793
|
+
const outputElements = [
|
|
2794
|
+
...rawTexts,
|
|
2795
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
2796
|
+
];
|
|
2797
|
+
scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
|
|
2611
2798
|
}
|
|
2612
2799
|
if (removedCount > 0) {
|
|
2613
2800
|
console.log(
|
|
2614
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
2801
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
|
|
2615
2802
|
);
|
|
2616
2803
|
}
|
|
2617
|
-
return { migratedCount, removedCount };
|
|
2804
|
+
return { migratedCount, removedCount, mergedCount };
|
|
2618
2805
|
}
|
|
2619
2806
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2620
2807
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -2749,7 +2936,7 @@ async function main11() {
|
|
|
2749
2936
|
return;
|
|
2750
2937
|
}
|
|
2751
2938
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2752
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2939
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
|
|
2753
2940
|
rolesFilePath,
|
|
2754
2941
|
project
|
|
2755
2942
|
);
|
|
@@ -2768,7 +2955,7 @@ async function main11() {
|
|
|
2768
2955
|
}
|
|
2769
2956
|
await sourceFile.save();
|
|
2770
2957
|
console.log(
|
|
2771
|
-
`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." : "."}`
|
|
2958
|
+
`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." : "."}`
|
|
2772
2959
|
);
|
|
2773
2960
|
}
|
|
2774
2961
|
|
|
@@ -3574,6 +3761,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3574
3761
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3575
3762
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3576
3763
|
var SLUG_PROPERTY_NAME = "slug";
|
|
3764
|
+
var READ_ACTION_TYPE = "READ";
|
|
3765
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3766
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3767
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3577
3768
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3578
3769
|
"READ",
|
|
3579
3770
|
"DELETE",
|
|
@@ -3621,91 +3812,137 @@ function isUnsupportedActionType(action) {
|
|
|
3621
3812
|
}
|
|
3622
3813
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3623
3814
|
}
|
|
3624
|
-
function
|
|
3625
|
-
const
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3815
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3816
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3817
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3818
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3819
|
+
const initializer = actionProperty.getInitializer();
|
|
3820
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3821
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3822
|
+
return { changed: false, usedReadFallback: false };
|
|
3823
|
+
}
|
|
3824
|
+
actionProperty.set({
|
|
3825
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3826
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3827
|
+
});
|
|
3828
|
+
console.log(
|
|
3829
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3830
|
+
);
|
|
3831
|
+
return { changed: true, usedReadFallback: true };
|
|
3832
|
+
}
|
|
3632
3833
|
}
|
|
3834
|
+
workqueue.addPropertyAssignment({
|
|
3835
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3836
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3837
|
+
});
|
|
3838
|
+
console.log(
|
|
3839
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3840
|
+
);
|
|
3841
|
+
return { changed: true, usedReadFallback: true };
|
|
3842
|
+
}
|
|
3843
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3633
3844
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3634
|
-
const
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3845
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3846
|
+
let actionsArrayMigrated = false;
|
|
3847
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3848
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3849
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3850
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3851
|
+
if (existingActionProperty) {
|
|
3852
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3853
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3854
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3855
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3856
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3857
|
+
);
|
|
3858
|
+
if (conditionalsProperty) {
|
|
3859
|
+
conditionalsProperty.remove();
|
|
3860
|
+
console.log(
|
|
3861
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3862
|
+
);
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
actionsProperty.remove();
|
|
3867
|
+
console.log(
|
|
3868
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3641
3869
|
);
|
|
3642
|
-
|
|
3643
|
-
|
|
3870
|
+
actionsArrayMigrated = true;
|
|
3871
|
+
} else {
|
|
3872
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3873
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3874
|
+
);
|
|
3875
|
+
if (actionCandidates.length === 0) {
|
|
3876
|
+
actionsProperty.remove();
|
|
3644
3877
|
console.log(
|
|
3645
|
-
` [${relPath}] Removed
|
|
3878
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3646
3879
|
);
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3880
|
+
actionsArrayMigrated = true;
|
|
3881
|
+
} else {
|
|
3882
|
+
if (actionCandidates.length > 1) {
|
|
3883
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3884
|
+
console.warn(
|
|
3885
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3889
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3652
3890
|
);
|
|
3891
|
+
if (conditionalsProperty) {
|
|
3892
|
+
conditionalsProperty.remove();
|
|
3893
|
+
console.log(
|
|
3894
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3895
|
+
);
|
|
3896
|
+
}
|
|
3897
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3898
|
+
actionsProperty.remove();
|
|
3899
|
+
console.log(
|
|
3900
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3901
|
+
);
|
|
3902
|
+
actionsArrayMigrated = true;
|
|
3903
|
+
} else {
|
|
3904
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3905
|
+
workqueue.addPropertyAssignment({
|
|
3906
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3907
|
+
initializer: firstActionText
|
|
3908
|
+
});
|
|
3909
|
+
actionsProperty.remove();
|
|
3910
|
+
console.log(
|
|
3911
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3912
|
+
);
|
|
3913
|
+
actionsArrayMigrated = true;
|
|
3914
|
+
}
|
|
3653
3915
|
}
|
|
3654
3916
|
}
|
|
3655
3917
|
}
|
|
3656
|
-
actionsProperty.remove();
|
|
3657
|
-
console.log(
|
|
3658
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3659
|
-
);
|
|
3660
|
-
return 1;
|
|
3661
3918
|
}
|
|
3662
|
-
const
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
}
|
|
3672
|
-
if (actionCandidates.length > 1) {
|
|
3673
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3674
|
-
console.warn(
|
|
3675
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3676
|
-
);
|
|
3677
|
-
}
|
|
3678
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3679
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3919
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3920
|
+
return {
|
|
3921
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3922
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3923
|
+
};
|
|
3924
|
+
}
|
|
3925
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3926
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3927
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3680
3928
|
);
|
|
3681
|
-
if (
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3688
|
-
actionsProperty.remove();
|
|
3689
|
-
console.log(
|
|
3690
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3691
|
-
);
|
|
3692
|
-
return 1;
|
|
3929
|
+
if (existingImport) {
|
|
3930
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3931
|
+
if (!alreadyImported) {
|
|
3932
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3933
|
+
}
|
|
3934
|
+
return;
|
|
3693
3935
|
}
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
initializer: firstActionText
|
|
3936
|
+
sourceFile.addImportDeclaration({
|
|
3937
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3938
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3698
3939
|
});
|
|
3699
|
-
actionsProperty.remove();
|
|
3700
|
-
console.log(
|
|
3701
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3702
|
-
);
|
|
3703
|
-
return 1;
|
|
3704
3940
|
}
|
|
3705
3941
|
function processFile13(filePath, project) {
|
|
3706
3942
|
const sourceFile = project.getSourceFile(filePath);
|
|
3707
3943
|
if (!sourceFile) return 0;
|
|
3708
3944
|
let migratedWorkqueues = 0;
|
|
3945
|
+
let needsActionTypeImport = false;
|
|
3709
3946
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3710
3947
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3711
3948
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3721,9 +3958,14 @@ function processFile13(filePath, project) {
|
|
|
3721
3958
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3722
3959
|
for (const element of workqueuesArg.getElements()) {
|
|
3723
3960
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3724
|
-
|
|
3961
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3962
|
+
if (result.changed) migratedWorkqueues++;
|
|
3963
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3725
3964
|
}
|
|
3726
3965
|
}
|
|
3966
|
+
if (needsActionTypeImport) {
|
|
3967
|
+
ensureActionTypeImport(sourceFile);
|
|
3968
|
+
}
|
|
3727
3969
|
return migratedWorkqueues;
|
|
3728
3970
|
}
|
|
3729
3971
|
async function main18() {
|
|
@@ -4058,7 +4300,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4058
4300
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4059
4301
|
var import_child_process = require("child_process");
|
|
4060
4302
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4061
|
-
var UPSTREAM_BRANCH = "
|
|
4303
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4062
4304
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4063
4305
|
var FILES_TO_CHECKOUT = [
|
|
4064
4306
|
"src/analytics/analytics.ts",
|
|
@@ -4135,10 +4377,356 @@ async function main22() {
|
|
|
4135
4377
|
}
|
|
4136
4378
|
}
|
|
4137
4379
|
|
|
4138
|
-
// src/migrations/v2.0/
|
|
4139
|
-
var
|
|
4140
|
-
var import_fs3 = __toESM(require("fs"));
|
|
4380
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4381
|
+
var import_fs3 = require("fs");
|
|
4141
4382
|
var import_path22 = __toESM(require("path"));
|
|
4383
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4384
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4385
|
+
skipAddingFilesFromTsConfig: true,
|
|
4386
|
+
manipulationSettings: {
|
|
4387
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4388
|
+
}
|
|
4389
|
+
};
|
|
4390
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4391
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4392
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4393
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4394
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4395
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4396
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4397
|
+
<html>
|
|
4398
|
+
<head>
|
|
4399
|
+
<link
|
|
4400
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4401
|
+
rel="stylesheet"
|
|
4402
|
+
/>
|
|
4403
|
+
<style type="text/css">
|
|
4404
|
+
body {
|
|
4405
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4406
|
+
color: #222;
|
|
4407
|
+
padding: 16px 24px;
|
|
4408
|
+
}
|
|
4409
|
+
|
|
4410
|
+
h1 {
|
|
4411
|
+
font-size: 21px;
|
|
4412
|
+
margin-top: 32px;
|
|
4413
|
+
margin-bottom: 36px;
|
|
4414
|
+
font-weight: 700;
|
|
4415
|
+
}
|
|
4416
|
+
|
|
4417
|
+
p {
|
|
4418
|
+
font-weight: 400;
|
|
4419
|
+
font-size: 16px;
|
|
4420
|
+
line-height: 1.8;
|
|
4421
|
+
margin-bottom: 24px;
|
|
4422
|
+
}
|
|
4423
|
+
|
|
4424
|
+
i {
|
|
4425
|
+
color: #666;
|
|
4426
|
+
font-weight: 400;
|
|
4427
|
+
font-size: 16px;
|
|
4428
|
+
}
|
|
4429
|
+
</style>
|
|
4430
|
+
</head>
|
|
4431
|
+
|
|
4432
|
+
<body>
|
|
4433
|
+
<img
|
|
4434
|
+
src="{{countryLogo}}"
|
|
4435
|
+
alt="country_logo"
|
|
4436
|
+
style="max-height: 88px; max-width: 100%"
|
|
4437
|
+
/>
|
|
4438
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4439
|
+
<p>Hello {{firstname}},</p>
|
|
4440
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4441
|
+
<p>
|
|
4442
|
+
Username: <strong>{{username}}</strong><br />
|
|
4443
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4444
|
+
</p>
|
|
4445
|
+
<p>
|
|
4446
|
+
Please click the link below to complete your account setup and start using
|
|
4447
|
+
{{applicationName}}.
|
|
4448
|
+
</p>
|
|
4449
|
+
|
|
4450
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4451
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4452
|
+
</div>
|
|
4453
|
+
<br />
|
|
4454
|
+
<p>
|
|
4455
|
+
Best regards, <br />
|
|
4456
|
+
{{applicationName}} Team
|
|
4457
|
+
</p>
|
|
4458
|
+
</body>
|
|
4459
|
+
</html>
|
|
4460
|
+
`;
|
|
4461
|
+
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";
|
|
4462
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4463
|
+
if (!declaration) {
|
|
4464
|
+
return;
|
|
4465
|
+
}
|
|
4466
|
+
const initializer = declaration.getInitializer();
|
|
4467
|
+
if (!initializer) {
|
|
4468
|
+
return;
|
|
4469
|
+
}
|
|
4470
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4471
|
+
return initializer;
|
|
4472
|
+
}
|
|
4473
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4474
|
+
const expression = initializer.getExpression();
|
|
4475
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4476
|
+
return expression;
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4479
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4480
|
+
const expression = initializer.getExpression();
|
|
4481
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4482
|
+
return expression;
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
function patchEmailTemplatesIndex() {
|
|
4487
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4488
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4489
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4490
|
+
return false;
|
|
4491
|
+
}
|
|
4492
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4493
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4494
|
+
let changed = false;
|
|
4495
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4496
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4497
|
+
);
|
|
4498
|
+
if (triggerVariableObject) {
|
|
4499
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4500
|
+
if (!hasResendInviteVariable) {
|
|
4501
|
+
const properties = triggerVariableObject.getProperties();
|
|
4502
|
+
const lastProperty = properties[properties.length - 1];
|
|
4503
|
+
if (lastProperty) {
|
|
4504
|
+
sourceFile.insertText(
|
|
4505
|
+
lastProperty.getEnd(),
|
|
4506
|
+
`,
|
|
4507
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4508
|
+
firstname: z.string(),
|
|
4509
|
+
username: z.string(),
|
|
4510
|
+
temporaryPassword: z.string(),
|
|
4511
|
+
completeSetupUrl: z.string(),
|
|
4512
|
+
loginURL: z.string()
|
|
4513
|
+
})`
|
|
4514
|
+
);
|
|
4515
|
+
changed = true;
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4520
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4521
|
+
);
|
|
4522
|
+
if (templatesObject) {
|
|
4523
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4524
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4525
|
+
);
|
|
4526
|
+
if (!hasResendInviteTemplate) {
|
|
4527
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4528
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4529
|
+
if (anchor) {
|
|
4530
|
+
sourceFile.insertText(
|
|
4531
|
+
anchor.getEnd(),
|
|
4532
|
+
`,
|
|
4533
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4534
|
+
type: 'resend-invite',
|
|
4535
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4536
|
+
template:
|
|
4537
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4538
|
+
}`
|
|
4539
|
+
);
|
|
4540
|
+
changed = true;
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
}
|
|
4544
|
+
if (changed) {
|
|
4545
|
+
sourceFile.saveSync();
|
|
4546
|
+
}
|
|
4547
|
+
return changed;
|
|
4548
|
+
}
|
|
4549
|
+
function patchNotificationHandler() {
|
|
4550
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4551
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4552
|
+
return false;
|
|
4553
|
+
}
|
|
4554
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4555
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4556
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4557
|
+
if (!convertFn) {
|
|
4558
|
+
return false;
|
|
4559
|
+
}
|
|
4560
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4561
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4562
|
+
);
|
|
4563
|
+
if (!switchStmt) {
|
|
4564
|
+
return false;
|
|
4565
|
+
}
|
|
4566
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4567
|
+
const hasResendInvite = clauses.some(
|
|
4568
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4569
|
+
);
|
|
4570
|
+
if (hasResendInvite) {
|
|
4571
|
+
return false;
|
|
4572
|
+
}
|
|
4573
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4574
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4575
|
+
);
|
|
4576
|
+
if (userCreatedClauseIndex < 0) {
|
|
4577
|
+
return false;
|
|
4578
|
+
}
|
|
4579
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4580
|
+
sourceFile.insertText(
|
|
4581
|
+
userCreatedClause.getEnd(),
|
|
4582
|
+
`
|
|
4583
|
+
|
|
4584
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4585
|
+
return {
|
|
4586
|
+
firstname,
|
|
4587
|
+
username: payload.username,
|
|
4588
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4589
|
+
completeSetupUrl: LOGIN_URL,
|
|
4590
|
+
loginURL: LOGIN_URL
|
|
4591
|
+
}`
|
|
4592
|
+
);
|
|
4593
|
+
sourceFile.saveSync();
|
|
4594
|
+
return true;
|
|
4595
|
+
}
|
|
4596
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4597
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4598
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4599
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4600
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4601
|
+
const expr = returnStmt?.getExpression();
|
|
4602
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4603
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4604
|
+
}
|
|
4605
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4606
|
+
}
|
|
4607
|
+
function patchUserNotificationRoutes() {
|
|
4608
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4609
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4610
|
+
return false;
|
|
4611
|
+
}
|
|
4612
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4613
|
+
full,
|
|
4614
|
+
"getUserNotificationRoutes"
|
|
4615
|
+
);
|
|
4616
|
+
if (!arrayLiteral) {
|
|
4617
|
+
return false;
|
|
4618
|
+
}
|
|
4619
|
+
const elements = arrayLiteral.getElements();
|
|
4620
|
+
const routeExists = elements.some(
|
|
4621
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4622
|
+
);
|
|
4623
|
+
if (routeExists) {
|
|
4624
|
+
return false;
|
|
4625
|
+
}
|
|
4626
|
+
const anchor = elements.find(
|
|
4627
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4628
|
+
) ?? elements[elements.length - 1];
|
|
4629
|
+
if (!anchor) {
|
|
4630
|
+
return false;
|
|
4631
|
+
}
|
|
4632
|
+
sourceFile.insertText(
|
|
4633
|
+
anchor.getEnd(),
|
|
4634
|
+
`,
|
|
4635
|
+
{
|
|
4636
|
+
method: 'POST',
|
|
4637
|
+
path: '/triggers/user/resend-invite',
|
|
4638
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4639
|
+
options: {
|
|
4640
|
+
auth: false,
|
|
4641
|
+
tags: ['api'],
|
|
4642
|
+
description: 'Handles notification for resent user invite'
|
|
4643
|
+
}
|
|
4644
|
+
}`
|
|
4645
|
+
);
|
|
4646
|
+
sourceFile.saveSync();
|
|
4647
|
+
return true;
|
|
4648
|
+
}
|
|
4649
|
+
function patchSmsService() {
|
|
4650
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4651
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4652
|
+
return false;
|
|
4653
|
+
}
|
|
4654
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4655
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4656
|
+
let changed = false;
|
|
4657
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4658
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4659
|
+
);
|
|
4660
|
+
if (otherTemplatesObject) {
|
|
4661
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4662
|
+
if (!hasResendTemplate) {
|
|
4663
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4664
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4665
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4666
|
+
{
|
|
4667
|
+
name: "resendInviteNotification",
|
|
4668
|
+
initializer: `'resendInviteNotification'`
|
|
4669
|
+
}
|
|
4670
|
+
);
|
|
4671
|
+
changed = true;
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4675
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4676
|
+
);
|
|
4677
|
+
if (triggerToSmsTemplateObject) {
|
|
4678
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4679
|
+
if (!hasResendInviteMap) {
|
|
4680
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4681
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4682
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4683
|
+
{
|
|
4684
|
+
name: `['resend-invite']`,
|
|
4685
|
+
initializer: `'resendInviteNotification'`
|
|
4686
|
+
}
|
|
4687
|
+
);
|
|
4688
|
+
changed = true;
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
if (changed) {
|
|
4692
|
+
sourceFile.saveSync();
|
|
4693
|
+
}
|
|
4694
|
+
return changed;
|
|
4695
|
+
}
|
|
4696
|
+
async function main23() {
|
|
4697
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4698
|
+
const touched = [];
|
|
4699
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4700
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4701
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4702
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4703
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4704
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4705
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4706
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4707
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4708
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4709
|
+
touched.push(NOTIFICATION_CSV);
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4713
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4714
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4715
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4716
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4717
|
+
}
|
|
4718
|
+
if (touched.length === 0) {
|
|
4719
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4720
|
+
return;
|
|
4721
|
+
}
|
|
4722
|
+
console.log(` Updated:
|
|
4723
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4724
|
+
}
|
|
4725
|
+
|
|
4726
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4727
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4728
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4729
|
+
var import_path23 = __toESM(require("path"));
|
|
4142
4730
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4143
4731
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4144
4732
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -4174,10 +4762,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
4174
4762
|
return void 0;
|
|
4175
4763
|
}
|
|
4176
4764
|
function getFunctionBodyBlock(fn) {
|
|
4177
|
-
if (
|
|
4765
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4178
4766
|
const initializer = fn.getInitializer();
|
|
4179
4767
|
if (!initializer) return void 0;
|
|
4180
|
-
if (!
|
|
4768
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
4181
4769
|
return void 0;
|
|
4182
4770
|
}
|
|
4183
4771
|
return initializer.getBody();
|
|
@@ -4187,9 +4775,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4187
4775
|
const fn = findPrecalculateFunction(sourceFile);
|
|
4188
4776
|
if (!fn) return log;
|
|
4189
4777
|
const body = getFunctionBodyBlock(fn);
|
|
4190
|
-
if (!body || !
|
|
4778
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
4191
4779
|
for (const statement of [...body.getStatements()]) {
|
|
4192
|
-
const references = statement.getDescendantsOfKind(
|
|
4780
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4193
4781
|
if (references) {
|
|
4194
4782
|
statement.remove();
|
|
4195
4783
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -4197,7 +4785,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4197
4785
|
}
|
|
4198
4786
|
const remaining = body.getStatements();
|
|
4199
4787
|
const last = remaining[remaining.length - 1];
|
|
4200
|
-
const alreadyCorrect = last &&
|
|
4788
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4201
4789
|
if (!alreadyCorrect) {
|
|
4202
4790
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4203
4791
|
log.push(
|
|
@@ -4206,17 +4794,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4206
4794
|
}
|
|
4207
4795
|
return log;
|
|
4208
4796
|
}
|
|
4209
|
-
async function
|
|
4797
|
+
async function main24() {
|
|
4210
4798
|
const cwd = process.cwd();
|
|
4211
|
-
const absPath =
|
|
4212
|
-
if (!
|
|
4799
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4800
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
4213
4801
|
console.log(
|
|
4214
4802
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
4215
4803
|
);
|
|
4216
4804
|
return;
|
|
4217
4805
|
}
|
|
4218
|
-
const project = new
|
|
4219
|
-
tsConfigFilePath:
|
|
4806
|
+
const project = new import_ts_morph21.Project({
|
|
4807
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
4220
4808
|
skipAddingFilesFromTsConfig: false
|
|
4221
4809
|
});
|
|
4222
4810
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -4245,15 +4833,15 @@ Saved ${ANALYTICS_FILE_REL}.`);
|
|
|
4245
4833
|
|
|
4246
4834
|
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4247
4835
|
var import_child_process2 = require("child_process");
|
|
4248
|
-
var
|
|
4836
|
+
var import_fs5 = require("fs");
|
|
4249
4837
|
var import_os = require("os");
|
|
4250
|
-
var
|
|
4838
|
+
var import_path24 = require("path");
|
|
4251
4839
|
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4252
4840
|
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4253
4841
|
var BASE_BRANCH = "release-v1.9";
|
|
4254
|
-
function gitShowBytes(ref,
|
|
4842
|
+
function gitShowBytes(ref, path24) {
|
|
4255
4843
|
try {
|
|
4256
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${
|
|
4844
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path24}`], {
|
|
4257
4845
|
cwd: process.cwd(),
|
|
4258
4846
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4259
4847
|
});
|
|
@@ -4262,9 +4850,13 @@ function gitShowBytes(ref, path22) {
|
|
|
4262
4850
|
return null;
|
|
4263
4851
|
}
|
|
4264
4852
|
}
|
|
4265
|
-
async function
|
|
4853
|
+
async function main25({
|
|
4854
|
+
subdirs = []
|
|
4855
|
+
} = {}) {
|
|
4856
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4857
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4266
4858
|
console.log(
|
|
4267
|
-
`Merging
|
|
4859
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4268
4860
|
`
|
|
4269
4861
|
);
|
|
4270
4862
|
assertIsGitRepo();
|
|
@@ -4279,32 +4871,24 @@ async function main24() {
|
|
|
4279
4871
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4280
4872
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4281
4873
|
const upstreamFiles = runGit(
|
|
4282
|
-
[
|
|
4283
|
-
"ls-tree",
|
|
4284
|
-
"-r",
|
|
4285
|
-
"--name-only",
|
|
4286
|
-
"-z",
|
|
4287
|
-
ref,
|
|
4288
|
-
"--",
|
|
4289
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4290
|
-
],
|
|
4874
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4291
4875
|
{ silent: true }
|
|
4292
4876
|
).split("\0").filter(Boolean);
|
|
4293
4877
|
if (upstreamFiles.length === 0) {
|
|
4294
4878
|
console.log(
|
|
4295
|
-
` No files found under
|
|
4879
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4296
4880
|
);
|
|
4297
4881
|
return;
|
|
4298
4882
|
}
|
|
4299
|
-
const tmpDir = (0,
|
|
4300
|
-
const baseTmp = (0,
|
|
4301
|
-
const theirsTmp = (0,
|
|
4883
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4884
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4885
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4302
4886
|
let added = 0;
|
|
4303
4887
|
let merged = 0;
|
|
4304
4888
|
const conflictedFiles = [];
|
|
4305
4889
|
for (const file of upstreamFiles) {
|
|
4306
|
-
const fullPath = (0,
|
|
4307
|
-
if (!(0,
|
|
4890
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4891
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4308
4892
|
if (tryGit(["checkout", ref, "--", file])) {
|
|
4309
4893
|
console.log(` + ${file} (new from upstream)`);
|
|
4310
4894
|
added++;
|
|
@@ -4318,9 +4902,9 @@ async function main24() {
|
|
|
4318
4902
|
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4319
4903
|
continue;
|
|
4320
4904
|
}
|
|
4321
|
-
(0,
|
|
4905
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4322
4906
|
const baseContents = gitShowBytes(baseRef, file);
|
|
4323
|
-
(0,
|
|
4907
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4324
4908
|
try {
|
|
4325
4909
|
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4326
4910
|
cwd: process.cwd(),
|
|
@@ -4364,35 +4948,165 @@ async function main24() {
|
|
|
4364
4948
|
}
|
|
4365
4949
|
|
|
4366
4950
|
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4367
|
-
var
|
|
4368
|
-
var
|
|
4951
|
+
var import_fs6 = require("fs");
|
|
4952
|
+
var import_path25 = require("path");
|
|
4369
4953
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4370
|
-
async function
|
|
4371
|
-
|
|
4372
|
-
|
|
4954
|
+
async function main26({
|
|
4955
|
+
keep = []
|
|
4956
|
+
} = {}) {
|
|
4957
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4958
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4373
4959
|
console.log(
|
|
4374
4960
|
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
4375
4961
|
);
|
|
4376
4962
|
return;
|
|
4377
4963
|
}
|
|
4378
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4379
|
-
`);
|
|
4380
4964
|
assertIsGitRepo();
|
|
4381
|
-
|
|
4382
|
-
|
|
4965
|
+
if (keep.length === 0) {
|
|
4966
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4967
|
+
`);
|
|
4968
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4969
|
+
silent: true
|
|
4970
|
+
});
|
|
4971
|
+
console.log(
|
|
4972
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4973
|
+
);
|
|
4974
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4975
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4976
|
+
console.log(
|
|
4977
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4978
|
+
);
|
|
4979
|
+
}
|
|
4980
|
+
console.log(
|
|
4981
|
+
`
|
|
4982
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4983
|
+
);
|
|
4984
|
+
return;
|
|
4985
|
+
}
|
|
4986
|
+
const keepSet = new Set(keep);
|
|
4987
|
+
console.log(
|
|
4988
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4989
|
+
`
|
|
4990
|
+
);
|
|
4991
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4992
|
+
let deleted = 0;
|
|
4993
|
+
for (const entry of topLevelEntries) {
|
|
4994
|
+
if (keepSet.has(entry.name)) {
|
|
4995
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4996
|
+
continue;
|
|
4997
|
+
}
|
|
4998
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4999
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
5000
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
5001
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
5002
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
5003
|
+
}
|
|
5004
|
+
console.log(` Deleted '${relPath}'.`);
|
|
5005
|
+
deleted++;
|
|
5006
|
+
}
|
|
5007
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
5008
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
5009
|
+
if (missingKeeps.length > 0) {
|
|
5010
|
+
console.warn(
|
|
5011
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
5012
|
+
);
|
|
5013
|
+
}
|
|
5014
|
+
console.log(
|
|
5015
|
+
`
|
|
5016
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
5017
|
+
);
|
|
5018
|
+
}
|
|
5019
|
+
|
|
5020
|
+
// src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
|
|
5021
|
+
var import_ts_morph22 = require("ts-morph");
|
|
5022
|
+
var import_path26 = __toESM(require("path"));
|
|
5023
|
+
var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
|
|
5024
|
+
var ACTION_PARAMETER_NAME = "action";
|
|
5025
|
+
var OLD_TYPE = "ActionInput";
|
|
5026
|
+
var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
5027
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
5028
|
+
const functionDeclaration = parameter.getFirstAncestorByKind(
|
|
5029
|
+
import_ts_morph22.SyntaxKind.FunctionDeclaration
|
|
5030
|
+
);
|
|
5031
|
+
if (functionDeclaration?.getName() === TARGET_FUNCTION_NAME) {
|
|
5032
|
+
return true;
|
|
5033
|
+
}
|
|
5034
|
+
const arrowFunction = parameter.getFirstAncestorByKind(
|
|
5035
|
+
import_ts_morph22.SyntaxKind.ArrowFunction
|
|
5036
|
+
);
|
|
5037
|
+
const variableDeclaration = arrowFunction?.getFirstAncestorByKind(
|
|
5038
|
+
import_ts_morph22.SyntaxKind.VariableDeclaration
|
|
5039
|
+
);
|
|
5040
|
+
return variableDeclaration?.getName() === TARGET_FUNCTION_NAME;
|
|
5041
|
+
}
|
|
5042
|
+
function processFile14(filePath, project) {
|
|
5043
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
5044
|
+
if (!sourceFile) return 0;
|
|
5045
|
+
let updatedCount = 0;
|
|
5046
|
+
for (const parameter of sourceFile.getDescendantsOfKind(
|
|
5047
|
+
import_ts_morph22.SyntaxKind.Parameter
|
|
5048
|
+
)) {
|
|
5049
|
+
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
5050
|
+
continue;
|
|
5051
|
+
}
|
|
5052
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
5053
|
+
continue;
|
|
5054
|
+
}
|
|
5055
|
+
const typeNode = parameter.getTypeNode();
|
|
5056
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
5057
|
+
continue;
|
|
5058
|
+
}
|
|
5059
|
+
parameter.setType(NEW_TYPE);
|
|
5060
|
+
updatedCount++;
|
|
5061
|
+
console.log(
|
|
5062
|
+
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
|
|
5063
|
+
);
|
|
5064
|
+
}
|
|
5065
|
+
return updatedCount;
|
|
5066
|
+
}
|
|
5067
|
+
async function main27() {
|
|
5068
|
+
const srcDir = import_path26.default.join(process.cwd(), "src");
|
|
5069
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
|
|
5070
|
+
`);
|
|
5071
|
+
const project = new import_ts_morph22.Project({
|
|
5072
|
+
tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
|
|
5073
|
+
skipAddingFilesFromTsConfig: false
|
|
4383
5074
|
});
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
5075
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
5076
|
+
const filePath = sf.getFilePath();
|
|
5077
|
+
return filePath.includes("/src/") && !filePath.includes("/node_modules/");
|
|
5078
|
+
});
|
|
5079
|
+
let totalUpdated = 0;
|
|
5080
|
+
const modifiedFiles = [];
|
|
5081
|
+
for (const sourceFile of sourceFiles) {
|
|
5082
|
+
const filePath = sourceFile.getFilePath();
|
|
5083
|
+
const updated = processFile14(filePath, project);
|
|
5084
|
+
if (updated > 0) {
|
|
5085
|
+
totalUpdated += updated;
|
|
5086
|
+
modifiedFiles.push(filePath);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
if (modifiedFiles.length === 0) {
|
|
5090
|
+
console.log(
|
|
5091
|
+
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
|
|
5092
|
+
);
|
|
5093
|
+
return;
|
|
5094
|
+
}
|
|
5095
|
+
console.log(`
|
|
5096
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5097
|
+
for (const filePath of modifiedFiles) {
|
|
5098
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
5099
|
+
await sourceFile.save();
|
|
5100
|
+
console.log(` Saved: ${import_path26.default.relative(process.cwd(), filePath)}`);
|
|
4388
5101
|
}
|
|
4389
5102
|
console.log(
|
|
4390
5103
|
`
|
|
4391
|
-
|
|
5104
|
+
Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
|
|
4392
5105
|
);
|
|
4393
5106
|
}
|
|
4394
5107
|
|
|
4395
5108
|
// src/migrations/v2.0/index.ts
|
|
5109
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4396
5110
|
async function runUpgrade(dockerSwarm) {
|
|
4397
5111
|
await main18();
|
|
4398
5112
|
await main();
|
|
@@ -4416,11 +5130,14 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4416
5130
|
await main21();
|
|
4417
5131
|
await main22();
|
|
4418
5132
|
await main23();
|
|
5133
|
+
await main24();
|
|
5134
|
+
await main27();
|
|
4419
5135
|
await main17();
|
|
4420
5136
|
if (dockerSwarm) {
|
|
4421
|
-
await main24();
|
|
4422
|
-
} else {
|
|
4423
5137
|
await main25();
|
|
5138
|
+
} else {
|
|
5139
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
5140
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4424
5141
|
}
|
|
4425
5142
|
}
|
|
4426
5143
|
|
|
@@ -4449,7 +5166,7 @@ Options:
|
|
|
4449
5166
|
'infrastructure/' directory is deleted (default).
|
|
4450
5167
|
-h, --help Show this message.
|
|
4451
5168
|
`.trim();
|
|
4452
|
-
function
|
|
5169
|
+
function main28() {
|
|
4453
5170
|
const command = args[0];
|
|
4454
5171
|
if (!command || command === "--help" || command === "-h") {
|
|
4455
5172
|
console.log(USAGE);
|
|
@@ -4524,4 +5241,4 @@ function handleCheckTranslations() {
|
|
|
4524
5241
|
console.warn("This command is not implemented yet!");
|
|
4525
5242
|
process.exit(1);
|
|
4526
5243
|
}
|
|
4527
|
-
|
|
5244
|
+
main28();
|