@opencrvs/toolkit 2.0.0-rc.153df7b → 2.0.0-rc.18d8164
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 +73 -0
- package/create-countryconfig/package.json +11 -0
- package/dist/application-config/index.js +41 -11
- package/dist/cli.js +532 -85
- package/dist/commons/api/router.d.ts +55 -54
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/events/FieldConfig.d.ts +10 -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/conditionals/index.js +37 -7
- package/dist/events/index.js +130 -7
- 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/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +530 -83
- 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/notification/index.js +37 -7
- package/dist/scopes/index.d.ts +87 -10
- package/dist/scopes/index.js +43 -8
- package/opencrvs-toolkit-2.0.0-rc.18d8164.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.153df7b.tgz +0 -0
|
@@ -190,6 +190,8 @@ function ensureImports(sourceFile) {
|
|
|
190
190
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
191
191
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
192
192
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
193
|
+
var ID_PROPERTY_NAME = "id";
|
|
194
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
193
195
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
194
196
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
195
197
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -199,9 +201,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
199
201
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
200
202
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
201
203
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
204
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
202
205
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
203
206
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
207
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
204
208
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
209
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
205
210
|
function isValidateType(typeInitializer) {
|
|
206
211
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
207
212
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -325,6 +330,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
325
330
|
}
|
|
326
331
|
return true;
|
|
327
332
|
}
|
|
333
|
+
function isRegisterAction(action) {
|
|
334
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
335
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
336
|
+
const typeInit = typeProperty.getInitializer();
|
|
337
|
+
if (!typeInit) return false;
|
|
338
|
+
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
339
|
+
const enumExpr = typeInit.getExpression();
|
|
340
|
+
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
341
|
+
}
|
|
342
|
+
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
343
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function arrayHasElementWithId(array3, id) {
|
|
348
|
+
for (const el of array3.getElements()) {
|
|
349
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
350
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
351
|
+
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
352
|
+
const idInit = idProp.getInitializer();
|
|
353
|
+
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
360
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
361
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
362
|
+
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
363
|
+
const flagsInit = flagsProp.getInitializer();
|
|
364
|
+
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
365
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
366
|
+
flagsInit.addElement(entry);
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
action.addPropertyAssignment({
|
|
372
|
+
name: FLAGS_PROPERTY_NAME,
|
|
373
|
+
initializer: `[${entry}]`
|
|
374
|
+
});
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
328
377
|
function processFile2(filePath, project) {
|
|
329
378
|
const sourceFile = project.getSourceFile(filePath);
|
|
330
379
|
if (!sourceFile) return 0;
|
|
@@ -390,6 +439,18 @@ function processFile2(filePath, project) {
|
|
|
390
439
|
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
391
440
|
);
|
|
392
441
|
}
|
|
442
|
+
if (configHadValidateAction) {
|
|
443
|
+
for (const element of actionsInitializer.getElements()) {
|
|
444
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
445
|
+
if (!isRegisterAction(element)) continue;
|
|
446
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
447
|
+
transformedCount++;
|
|
448
|
+
console.log(
|
|
449
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
393
454
|
if (fileNeedsImports) {
|
|
394
455
|
ensureImports(sourceFile);
|
|
395
456
|
}
|
|
@@ -436,7 +497,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
436
497
|
}
|
|
437
498
|
console.log(
|
|
438
499
|
`
|
|
439
|
-
Done.
|
|
500
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
440
501
|
);
|
|
441
502
|
}
|
|
442
503
|
|
|
@@ -679,14 +740,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
679
740
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
680
741
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
681
742
|
var STATUS_PROPERTY_NAME = "status";
|
|
682
|
-
var
|
|
743
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
683
744
|
var TERMS_PROPERTY_NAME = "terms";
|
|
684
745
|
var TERM_PROPERTY_NAME = "term";
|
|
685
746
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
686
747
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
687
|
-
var
|
|
748
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
688
749
|
function addValidatedFlag(clause) {
|
|
689
|
-
const flagsProperty = clause.getProperty(
|
|
750
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
690
751
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
691
752
|
const flagsInit = flagsProperty.getInitializer();
|
|
692
753
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -694,19 +755,19 @@ function addValidatedFlag(clause) {
|
|
|
694
755
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
695
756
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
696
757
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
697
|
-
anyOfInit.addElement(`'${
|
|
758
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
698
759
|
}
|
|
699
760
|
} else {
|
|
700
761
|
flagsInit.addPropertyAssignment({
|
|
701
762
|
name: ANY_OF_PROPERTY_NAME,
|
|
702
|
-
initializer: `['${
|
|
763
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
703
764
|
});
|
|
704
765
|
}
|
|
705
766
|
}
|
|
706
767
|
} else {
|
|
707
768
|
clause.addPropertyAssignment({
|
|
708
|
-
name:
|
|
709
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
769
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
770
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
710
771
|
});
|
|
711
772
|
}
|
|
712
773
|
}
|
|
@@ -872,23 +933,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
872
933
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
873
934
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
874
935
|
var ACTION_PROPERTY_NAME = "action";
|
|
875
|
-
var
|
|
936
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
876
937
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
877
938
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
939
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
878
940
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
879
941
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
880
942
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
881
943
|
var REGISTER_TYPE = "REGISTER";
|
|
882
944
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
883
|
-
|
|
945
|
+
function flagDefinitionInitializer(eventType) {
|
|
946
|
+
return `{
|
|
884
947
|
id: '${FLAG_ID}',
|
|
885
948
|
label: {
|
|
886
|
-
id: 'event.
|
|
949
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
887
950
|
defaultMessage: 'Pending first certificate issuance',
|
|
888
951
|
description: 'Flag label for first certificate issuance'
|
|
889
952
|
},
|
|
890
953
|
requiresAction: true
|
|
891
954
|
}`;
|
|
955
|
+
}
|
|
892
956
|
function isActionOfType(obj, typeName) {
|
|
893
957
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
894
958
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -902,18 +966,20 @@ function isActionOfType(obj, typeName) {
|
|
|
902
966
|
}
|
|
903
967
|
return false;
|
|
904
968
|
}
|
|
905
|
-
function
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
969
|
+
function getEventType(configArg) {
|
|
970
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
971
|
+
const prop = configArg.getProperty(propName);
|
|
972
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
973
|
+
const initializer = prop.getInitializer();
|
|
974
|
+
if (!initializer) continue;
|
|
975
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
976
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
977
|
+
}
|
|
978
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
979
|
+
return initializer.getName().toLowerCase();
|
|
980
|
+
}
|
|
915
981
|
}
|
|
916
|
-
return
|
|
982
|
+
return null;
|
|
917
983
|
}
|
|
918
984
|
function hasElementWithId(array3, id) {
|
|
919
985
|
for (const el of array3.getElements()) {
|
|
@@ -927,27 +993,28 @@ function hasElementWithId(array3, id) {
|
|
|
927
993
|
}
|
|
928
994
|
return false;
|
|
929
995
|
}
|
|
930
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
931
|
-
const
|
|
996
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
997
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
998
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
932
999
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
933
1000
|
const flagsInit = flagsProp.getInitializer();
|
|
934
1001
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
935
1002
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
936
|
-
flagsInit.addElement(
|
|
1003
|
+
flagsInit.addElement(initializer);
|
|
937
1004
|
return true;
|
|
938
1005
|
}
|
|
939
1006
|
return false;
|
|
940
1007
|
}
|
|
941
1008
|
configArg.addPropertyAssignment({
|
|
942
|
-
name:
|
|
1009
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
943
1010
|
initializer: `[
|
|
944
|
-
${
|
|
1011
|
+
${initializer}
|
|
945
1012
|
]`
|
|
946
1013
|
});
|
|
947
1014
|
return true;
|
|
948
1015
|
}
|
|
949
1016
|
function ensureActionOperationFlag(action, operation) {
|
|
950
|
-
const flagsProp = action.getProperty(
|
|
1017
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
951
1018
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
952
1019
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
953
1020
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -959,16 +1026,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
959
1026
|
return false;
|
|
960
1027
|
}
|
|
961
1028
|
action.addPropertyAssignment({
|
|
962
|
-
name:
|
|
1029
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
963
1030
|
initializer: `[${entry}]`
|
|
964
1031
|
});
|
|
965
1032
|
return true;
|
|
966
1033
|
}
|
|
967
|
-
function
|
|
1034
|
+
function processConfig(configArg, eventType, relPath) {
|
|
968
1035
|
let changes = 0;
|
|
969
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1036
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
970
1037
|
changes++;
|
|
971
|
-
console.log(
|
|
1038
|
+
console.log(
|
|
1039
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1040
|
+
);
|
|
972
1041
|
}
|
|
973
1042
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
974
1043
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -982,7 +1051,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
982
1051
|
if (ensureActionOperationFlag(element, "add")) {
|
|
983
1052
|
changes++;
|
|
984
1053
|
console.log(
|
|
985
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1054
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
986
1055
|
);
|
|
987
1056
|
}
|
|
988
1057
|
}
|
|
@@ -990,7 +1059,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
990
1059
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
991
1060
|
changes++;
|
|
992
1061
|
console.log(
|
|
993
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1062
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
994
1063
|
);
|
|
995
1064
|
}
|
|
996
1065
|
}
|
|
@@ -1019,7 +1088,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1019
1088
|
return false;
|
|
1020
1089
|
}
|
|
1021
1090
|
function addFlagToQueryClause(clause) {
|
|
1022
|
-
const flagsProp = clause.getProperty(
|
|
1091
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1023
1092
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1024
1093
|
const flagsInit = flagsProp.getInitializer();
|
|
1025
1094
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1044,7 +1113,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1044
1113
|
}
|
|
1045
1114
|
} else {
|
|
1046
1115
|
clause.addPropertyAssignment({
|
|
1047
|
-
name:
|
|
1116
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1048
1117
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1049
1118
|
});
|
|
1050
1119
|
return true;
|
|
@@ -1088,8 +1157,9 @@ function processFile6(filePath, project) {
|
|
|
1088
1157
|
if (args.length === 0) continue;
|
|
1089
1158
|
const configArg = args[0];
|
|
1090
1159
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1091
|
-
|
|
1092
|
-
|
|
1160
|
+
const eventType = getEventType(configArg);
|
|
1161
|
+
if (!eventType) continue;
|
|
1162
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1093
1163
|
}
|
|
1094
1164
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1095
1165
|
const args = call.getArguments();
|
|
@@ -1118,7 +1188,7 @@ function processFile6(filePath, project) {
|
|
|
1118
1188
|
async function main6() {
|
|
1119
1189
|
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1120
1190
|
console.log(
|
|
1121
|
-
`Scanning for
|
|
1191
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1122
1192
|
`
|
|
1123
1193
|
);
|
|
1124
1194
|
const project = new import_ts_morph6.Project({
|
|
@@ -1143,7 +1213,7 @@ async function main6() {
|
|
|
1143
1213
|
}
|
|
1144
1214
|
if (modifiedFiles.length === 0) {
|
|
1145
1215
|
console.log(
|
|
1146
|
-
"No
|
|
1216
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1147
1217
|
);
|
|
1148
1218
|
return;
|
|
1149
1219
|
}
|
|
@@ -1825,9 +1895,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1825
1895
|
}
|
|
1826
1896
|
return replacedCount;
|
|
1827
1897
|
}
|
|
1828
|
-
function resolveConfigChain(configObj,
|
|
1898
|
+
function resolveConfigChain(configObj, path23) {
|
|
1829
1899
|
let current = configObj;
|
|
1830
|
-
for (const key of
|
|
1900
|
+
for (const key of path23) {
|
|
1831
1901
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1832
1902
|
const prop = current.getProperty(key);
|
|
1833
1903
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -2122,6 +2192,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
2122
2192
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2123
2193
|
z3.array(z3.string()).optional()
|
|
2124
2194
|
).describe("Event type, e.g. birth, death");
|
|
2195
|
+
var userRole = z3.preprocess(
|
|
2196
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2197
|
+
z3.array(z3.string()).optional()
|
|
2198
|
+
).describe("User role, e.g. admin, field agent");
|
|
2125
2199
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2126
2200
|
event: scopeByEvent,
|
|
2127
2201
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2145,6 +2219,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2145
2219
|
var AccessLevelOptions = z3.object({
|
|
2146
2220
|
accessLevel: JurisdictionFilter.optional()
|
|
2147
2221
|
});
|
|
2222
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2223
|
+
role: userRole.optional()
|
|
2224
|
+
});
|
|
2148
2225
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2149
2226
|
ids: z3.preprocess(
|
|
2150
2227
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2154,6 +2231,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2154
2231
|
var AllScopeOptions = z3.object({
|
|
2155
2232
|
...AllRecordScopeOptions.shape,
|
|
2156
2233
|
...AccessLevelOptions.shape,
|
|
2234
|
+
...AllUserScopeOptions.shape,
|
|
2157
2235
|
...WorkqueueOrDashboardOptions.shape
|
|
2158
2236
|
});
|
|
2159
2237
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2226,6 +2304,30 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2226
2304
|
]).describe(
|
|
2227
2305
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2228
2306
|
);
|
|
2307
|
+
var SystemScopeType = z3.enum([
|
|
2308
|
+
"organisation.read-locations",
|
|
2309
|
+
"user.read",
|
|
2310
|
+
"user.create",
|
|
2311
|
+
"user.edit",
|
|
2312
|
+
"user.search"
|
|
2313
|
+
]);
|
|
2314
|
+
var UserScopeType = SystemScopeType.extract([
|
|
2315
|
+
"user.read",
|
|
2316
|
+
"user.create",
|
|
2317
|
+
"user.edit",
|
|
2318
|
+
"user.search"
|
|
2319
|
+
]);
|
|
2320
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2321
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2322
|
+
z3.object({
|
|
2323
|
+
type: ScopesWithRoleOption,
|
|
2324
|
+
options: AllUserScopeOptions.optional()
|
|
2325
|
+
}),
|
|
2326
|
+
z3.object({
|
|
2327
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2328
|
+
options: AccessLevelOptions.optional()
|
|
2329
|
+
})
|
|
2330
|
+
]);
|
|
2229
2331
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2230
2332
|
z3.object({
|
|
2231
2333
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2246,16 +2348,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2246
2348
|
}).optional()
|
|
2247
2349
|
})
|
|
2248
2350
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2249
|
-
var SystemScopeType = z3.enum([
|
|
2250
|
-
"organisation.read-locations",
|
|
2251
|
-
"user.read",
|
|
2252
|
-
"user.create",
|
|
2253
|
-
"user.edit"
|
|
2254
|
-
]);
|
|
2255
2351
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2256
2352
|
z3.object({ type: PlainScopeType }),
|
|
2257
2353
|
...RecordScopeV2.options,
|
|
2258
|
-
|
|
2354
|
+
...UserScopeV2.options,
|
|
2355
|
+
z3.object({
|
|
2356
|
+
type: z3.literal("organisation.read-locations"),
|
|
2357
|
+
options: AccessLevelOptions.optional()
|
|
2358
|
+
}),
|
|
2259
2359
|
z3.object({
|
|
2260
2360
|
type: z3.literal("workqueue"),
|
|
2261
2361
|
options: WorkqueueOrDashboardOptions
|
|
@@ -4147,10 +4247,356 @@ async function main22() {
|
|
|
4147
4247
|
}
|
|
4148
4248
|
}
|
|
4149
4249
|
|
|
4150
|
-
// src/migrations/v2.0/
|
|
4151
|
-
var
|
|
4152
|
-
var import_fs3 = __toESM(require("fs"));
|
|
4250
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4251
|
+
var import_fs3 = require("fs");
|
|
4153
4252
|
var import_path22 = __toESM(require("path"));
|
|
4253
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4254
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4255
|
+
skipAddingFilesFromTsConfig: true,
|
|
4256
|
+
manipulationSettings: {
|
|
4257
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4258
|
+
}
|
|
4259
|
+
};
|
|
4260
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4261
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4262
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4263
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4264
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4265
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4266
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4267
|
+
<html>
|
|
4268
|
+
<head>
|
|
4269
|
+
<link
|
|
4270
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4271
|
+
rel="stylesheet"
|
|
4272
|
+
/>
|
|
4273
|
+
<style type="text/css">
|
|
4274
|
+
body {
|
|
4275
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4276
|
+
color: #222;
|
|
4277
|
+
padding: 16px 24px;
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
h1 {
|
|
4281
|
+
font-size: 21px;
|
|
4282
|
+
margin-top: 32px;
|
|
4283
|
+
margin-bottom: 36px;
|
|
4284
|
+
font-weight: 700;
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4287
|
+
p {
|
|
4288
|
+
font-weight: 400;
|
|
4289
|
+
font-size: 16px;
|
|
4290
|
+
line-height: 1.8;
|
|
4291
|
+
margin-bottom: 24px;
|
|
4292
|
+
}
|
|
4293
|
+
|
|
4294
|
+
i {
|
|
4295
|
+
color: #666;
|
|
4296
|
+
font-weight: 400;
|
|
4297
|
+
font-size: 16px;
|
|
4298
|
+
}
|
|
4299
|
+
</style>
|
|
4300
|
+
</head>
|
|
4301
|
+
|
|
4302
|
+
<body>
|
|
4303
|
+
<img
|
|
4304
|
+
src="{{countryLogo}}"
|
|
4305
|
+
alt="country_logo"
|
|
4306
|
+
style="max-height: 88px; max-width: 100%"
|
|
4307
|
+
/>
|
|
4308
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4309
|
+
<p>Hello {{firstname}},</p>
|
|
4310
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4311
|
+
<p>
|
|
4312
|
+
Username: <strong>{{username}}</strong><br />
|
|
4313
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4314
|
+
</p>
|
|
4315
|
+
<p>
|
|
4316
|
+
Please click the link below to complete your account setup and start using
|
|
4317
|
+
{{applicationName}}.
|
|
4318
|
+
</p>
|
|
4319
|
+
|
|
4320
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4321
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4322
|
+
</div>
|
|
4323
|
+
<br />
|
|
4324
|
+
<p>
|
|
4325
|
+
Best regards, <br />
|
|
4326
|
+
{{applicationName}} Team
|
|
4327
|
+
</p>
|
|
4328
|
+
</body>
|
|
4329
|
+
</html>
|
|
4330
|
+
`;
|
|
4331
|
+
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";
|
|
4332
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4333
|
+
if (!declaration) {
|
|
4334
|
+
return;
|
|
4335
|
+
}
|
|
4336
|
+
const initializer = declaration.getInitializer();
|
|
4337
|
+
if (!initializer) {
|
|
4338
|
+
return;
|
|
4339
|
+
}
|
|
4340
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4341
|
+
return initializer;
|
|
4342
|
+
}
|
|
4343
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4344
|
+
const expression = initializer.getExpression();
|
|
4345
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4346
|
+
return expression;
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4350
|
+
const expression = initializer.getExpression();
|
|
4351
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4352
|
+
return expression;
|
|
4353
|
+
}
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
function patchEmailTemplatesIndex() {
|
|
4357
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4358
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4359
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4360
|
+
return false;
|
|
4361
|
+
}
|
|
4362
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4363
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4364
|
+
let changed = false;
|
|
4365
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4366
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4367
|
+
);
|
|
4368
|
+
if (triggerVariableObject) {
|
|
4369
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4370
|
+
if (!hasResendInviteVariable) {
|
|
4371
|
+
const properties = triggerVariableObject.getProperties();
|
|
4372
|
+
const lastProperty = properties[properties.length - 1];
|
|
4373
|
+
if (lastProperty) {
|
|
4374
|
+
sourceFile.insertText(
|
|
4375
|
+
lastProperty.getEnd(),
|
|
4376
|
+
`,
|
|
4377
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4378
|
+
firstname: z.string(),
|
|
4379
|
+
username: z.string(),
|
|
4380
|
+
temporaryPassword: z.string(),
|
|
4381
|
+
completeSetupUrl: z.string(),
|
|
4382
|
+
loginURL: z.string()
|
|
4383
|
+
})`
|
|
4384
|
+
);
|
|
4385
|
+
changed = true;
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4390
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4391
|
+
);
|
|
4392
|
+
if (templatesObject) {
|
|
4393
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4394
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4395
|
+
);
|
|
4396
|
+
if (!hasResendInviteTemplate) {
|
|
4397
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4398
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4399
|
+
if (anchor) {
|
|
4400
|
+
sourceFile.insertText(
|
|
4401
|
+
anchor.getEnd(),
|
|
4402
|
+
`,
|
|
4403
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4404
|
+
type: 'resend-invite',
|
|
4405
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4406
|
+
template:
|
|
4407
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4408
|
+
}`
|
|
4409
|
+
);
|
|
4410
|
+
changed = true;
|
|
4411
|
+
}
|
|
4412
|
+
}
|
|
4413
|
+
}
|
|
4414
|
+
if (changed) {
|
|
4415
|
+
sourceFile.saveSync();
|
|
4416
|
+
}
|
|
4417
|
+
return changed;
|
|
4418
|
+
}
|
|
4419
|
+
function patchNotificationHandler() {
|
|
4420
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4421
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4422
|
+
return false;
|
|
4423
|
+
}
|
|
4424
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4425
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4426
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4427
|
+
if (!convertFn) {
|
|
4428
|
+
return false;
|
|
4429
|
+
}
|
|
4430
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4431
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4432
|
+
);
|
|
4433
|
+
if (!switchStmt) {
|
|
4434
|
+
return false;
|
|
4435
|
+
}
|
|
4436
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4437
|
+
const hasResendInvite = clauses.some(
|
|
4438
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4439
|
+
);
|
|
4440
|
+
if (hasResendInvite) {
|
|
4441
|
+
return false;
|
|
4442
|
+
}
|
|
4443
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4444
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4445
|
+
);
|
|
4446
|
+
if (userCreatedClauseIndex < 0) {
|
|
4447
|
+
return false;
|
|
4448
|
+
}
|
|
4449
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4450
|
+
sourceFile.insertText(
|
|
4451
|
+
userCreatedClause.getEnd(),
|
|
4452
|
+
`
|
|
4453
|
+
|
|
4454
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4455
|
+
return {
|
|
4456
|
+
firstname,
|
|
4457
|
+
username: payload.username,
|
|
4458
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4459
|
+
completeSetupUrl: LOGIN_URL,
|
|
4460
|
+
loginURL: LOGIN_URL
|
|
4461
|
+
}`
|
|
4462
|
+
);
|
|
4463
|
+
sourceFile.saveSync();
|
|
4464
|
+
return true;
|
|
4465
|
+
}
|
|
4466
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4467
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4468
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4469
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4470
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4471
|
+
const expr = returnStmt?.getExpression();
|
|
4472
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4473
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4474
|
+
}
|
|
4475
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4476
|
+
}
|
|
4477
|
+
function patchUserNotificationRoutes() {
|
|
4478
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4479
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4480
|
+
return false;
|
|
4481
|
+
}
|
|
4482
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4483
|
+
full,
|
|
4484
|
+
"getUserNotificationRoutes"
|
|
4485
|
+
);
|
|
4486
|
+
if (!arrayLiteral) {
|
|
4487
|
+
return false;
|
|
4488
|
+
}
|
|
4489
|
+
const elements = arrayLiteral.getElements();
|
|
4490
|
+
const routeExists = elements.some(
|
|
4491
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4492
|
+
);
|
|
4493
|
+
if (routeExists) {
|
|
4494
|
+
return false;
|
|
4495
|
+
}
|
|
4496
|
+
const anchor = elements.find(
|
|
4497
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4498
|
+
) ?? elements[elements.length - 1];
|
|
4499
|
+
if (!anchor) {
|
|
4500
|
+
return false;
|
|
4501
|
+
}
|
|
4502
|
+
sourceFile.insertText(
|
|
4503
|
+
anchor.getEnd(),
|
|
4504
|
+
`,
|
|
4505
|
+
{
|
|
4506
|
+
method: 'POST',
|
|
4507
|
+
path: '/triggers/user/resend-invite',
|
|
4508
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4509
|
+
options: {
|
|
4510
|
+
auth: false,
|
|
4511
|
+
tags: ['api'],
|
|
4512
|
+
description: 'Handles notification for resent user invite'
|
|
4513
|
+
}
|
|
4514
|
+
}`
|
|
4515
|
+
);
|
|
4516
|
+
sourceFile.saveSync();
|
|
4517
|
+
return true;
|
|
4518
|
+
}
|
|
4519
|
+
function patchSmsService() {
|
|
4520
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4521
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4522
|
+
return false;
|
|
4523
|
+
}
|
|
4524
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4525
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4526
|
+
let changed = false;
|
|
4527
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4528
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4529
|
+
);
|
|
4530
|
+
if (otherTemplatesObject) {
|
|
4531
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4532
|
+
if (!hasResendTemplate) {
|
|
4533
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4534
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4535
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4536
|
+
{
|
|
4537
|
+
name: "resendInviteNotification",
|
|
4538
|
+
initializer: `'resendInviteNotification'`
|
|
4539
|
+
}
|
|
4540
|
+
);
|
|
4541
|
+
changed = true;
|
|
4542
|
+
}
|
|
4543
|
+
}
|
|
4544
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4545
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4546
|
+
);
|
|
4547
|
+
if (triggerToSmsTemplateObject) {
|
|
4548
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4549
|
+
if (!hasResendInviteMap) {
|
|
4550
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4551
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4552
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4553
|
+
{
|
|
4554
|
+
name: `['resend-invite']`,
|
|
4555
|
+
initializer: `'resendInviteNotification'`
|
|
4556
|
+
}
|
|
4557
|
+
);
|
|
4558
|
+
changed = true;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
if (changed) {
|
|
4562
|
+
sourceFile.saveSync();
|
|
4563
|
+
}
|
|
4564
|
+
return changed;
|
|
4565
|
+
}
|
|
4566
|
+
async function main23() {
|
|
4567
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4568
|
+
const touched = [];
|
|
4569
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4570
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4571
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4572
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4573
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4574
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4575
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4576
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4577
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4578
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4579
|
+
touched.push(NOTIFICATION_CSV);
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4583
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4584
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4585
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4586
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4587
|
+
}
|
|
4588
|
+
if (touched.length === 0) {
|
|
4589
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4590
|
+
return;
|
|
4591
|
+
}
|
|
4592
|
+
console.log(` Updated:
|
|
4593
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4594
|
+
}
|
|
4595
|
+
|
|
4596
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4597
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4598
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4599
|
+
var import_path23 = __toESM(require("path"));
|
|
4154
4600
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4155
4601
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4156
4602
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -4186,10 +4632,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
4186
4632
|
return void 0;
|
|
4187
4633
|
}
|
|
4188
4634
|
function getFunctionBodyBlock(fn) {
|
|
4189
|
-
if (
|
|
4635
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4190
4636
|
const initializer = fn.getInitializer();
|
|
4191
4637
|
if (!initializer) return void 0;
|
|
4192
|
-
if (!
|
|
4638
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
4193
4639
|
return void 0;
|
|
4194
4640
|
}
|
|
4195
4641
|
return initializer.getBody();
|
|
@@ -4199,9 +4645,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4199
4645
|
const fn = findPrecalculateFunction(sourceFile);
|
|
4200
4646
|
if (!fn) return log;
|
|
4201
4647
|
const body = getFunctionBodyBlock(fn);
|
|
4202
|
-
if (!body || !
|
|
4648
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
4203
4649
|
for (const statement of [...body.getStatements()]) {
|
|
4204
|
-
const references = statement.getDescendantsOfKind(
|
|
4650
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4205
4651
|
if (references) {
|
|
4206
4652
|
statement.remove();
|
|
4207
4653
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -4209,7 +4655,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4209
4655
|
}
|
|
4210
4656
|
const remaining = body.getStatements();
|
|
4211
4657
|
const last = remaining[remaining.length - 1];
|
|
4212
|
-
const alreadyCorrect = last &&
|
|
4658
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4213
4659
|
if (!alreadyCorrect) {
|
|
4214
4660
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4215
4661
|
log.push(
|
|
@@ -4218,17 +4664,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4218
4664
|
}
|
|
4219
4665
|
return log;
|
|
4220
4666
|
}
|
|
4221
|
-
async function
|
|
4667
|
+
async function main24() {
|
|
4222
4668
|
const cwd = process.cwd();
|
|
4223
|
-
const absPath =
|
|
4224
|
-
if (!
|
|
4669
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4670
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
4225
4671
|
console.log(
|
|
4226
4672
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
4227
4673
|
);
|
|
4228
4674
|
return;
|
|
4229
4675
|
}
|
|
4230
|
-
const project = new
|
|
4231
|
-
tsConfigFilePath:
|
|
4676
|
+
const project = new import_ts_morph21.Project({
|
|
4677
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
4232
4678
|
skipAddingFilesFromTsConfig: false
|
|
4233
4679
|
});
|
|
4234
4680
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -4257,15 +4703,15 @@ Saved ${ANALYTICS_FILE_REL}.`);
|
|
|
4257
4703
|
|
|
4258
4704
|
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4259
4705
|
var import_child_process2 = require("child_process");
|
|
4260
|
-
var
|
|
4706
|
+
var import_fs5 = require("fs");
|
|
4261
4707
|
var import_os = require("os");
|
|
4262
|
-
var
|
|
4708
|
+
var import_path24 = require("path");
|
|
4263
4709
|
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4264
4710
|
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4265
4711
|
var BASE_BRANCH = "release-v1.9";
|
|
4266
|
-
function gitShowBytes(ref,
|
|
4712
|
+
function gitShowBytes(ref, path23) {
|
|
4267
4713
|
try {
|
|
4268
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${
|
|
4714
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4269
4715
|
cwd: process.cwd(),
|
|
4270
4716
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4271
4717
|
});
|
|
@@ -4274,7 +4720,7 @@ function gitShowBytes(ref, path22) {
|
|
|
4274
4720
|
return null;
|
|
4275
4721
|
}
|
|
4276
4722
|
}
|
|
4277
|
-
async function
|
|
4723
|
+
async function main25() {
|
|
4278
4724
|
console.log(
|
|
4279
4725
|
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4280
4726
|
`
|
|
@@ -4308,15 +4754,15 @@ async function main24() {
|
|
|
4308
4754
|
);
|
|
4309
4755
|
return;
|
|
4310
4756
|
}
|
|
4311
|
-
const tmpDir = (0,
|
|
4312
|
-
const baseTmp = (0,
|
|
4313
|
-
const theirsTmp = (0,
|
|
4757
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4758
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4759
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4314
4760
|
let added = 0;
|
|
4315
4761
|
let merged = 0;
|
|
4316
4762
|
const conflictedFiles = [];
|
|
4317
4763
|
for (const file of upstreamFiles) {
|
|
4318
|
-
const fullPath = (0,
|
|
4319
|
-
if (!(0,
|
|
4764
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4765
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4320
4766
|
if (tryGit(["checkout", ref, "--", file])) {
|
|
4321
4767
|
console.log(` + ${file} (new from upstream)`);
|
|
4322
4768
|
added++;
|
|
@@ -4330,9 +4776,9 @@ async function main24() {
|
|
|
4330
4776
|
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4331
4777
|
continue;
|
|
4332
4778
|
}
|
|
4333
|
-
(0,
|
|
4779
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4334
4780
|
const baseContents = gitShowBytes(baseRef, file);
|
|
4335
|
-
(0,
|
|
4781
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4336
4782
|
try {
|
|
4337
4783
|
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4338
4784
|
cwd: process.cwd(),
|
|
@@ -4376,12 +4822,12 @@ async function main24() {
|
|
|
4376
4822
|
}
|
|
4377
4823
|
|
|
4378
4824
|
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4379
|
-
var
|
|
4380
|
-
var
|
|
4825
|
+
var import_fs6 = require("fs");
|
|
4826
|
+
var import_path25 = require("path");
|
|
4381
4827
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4382
|
-
async function
|
|
4383
|
-
const fullPath = (0,
|
|
4384
|
-
if (!(0,
|
|
4828
|
+
async function main26() {
|
|
4829
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4830
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4385
4831
|
console.log(
|
|
4386
4832
|
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
4387
4833
|
);
|
|
@@ -4394,8 +4840,8 @@ async function main25() {
|
|
|
4394
4840
|
silent: true
|
|
4395
4841
|
});
|
|
4396
4842
|
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4397
|
-
if ((0,
|
|
4398
|
-
(0,
|
|
4843
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4844
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4399
4845
|
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4400
4846
|
}
|
|
4401
4847
|
console.log(
|
|
@@ -4428,10 +4874,11 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4428
4874
|
await main21();
|
|
4429
4875
|
await main22();
|
|
4430
4876
|
await main23();
|
|
4877
|
+
await main24();
|
|
4431
4878
|
await main17();
|
|
4432
4879
|
if (dockerSwarm) {
|
|
4433
|
-
await main24();
|
|
4434
|
-
} else {
|
|
4435
4880
|
await main25();
|
|
4881
|
+
} else {
|
|
4882
|
+
await main26();
|
|
4436
4883
|
}
|
|
4437
4884
|
}
|