@opencrvs/toolkit 2.0.0-rc.153df7b → 2.0.0-rc.1d9a00b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`
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 FLAGS_PROPERTY_NAME = "flags";
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 VALIDATED_FLAG_VALUE = "validated";
736
+ var VALIDATED_FLAG_VALUE2 = "validated";
676
737
  function addValidatedFlag(clause) {
677
- const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
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(`'${VALIDATED_FLAG_VALUE}'`);
746
+ anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
686
747
  }
687
748
  } else {
688
749
  flagsInit.addPropertyAssignment({
689
750
  name: ANY_OF_PROPERTY_NAME,
690
- initializer: `['${VALIDATED_FLAG_VALUE}']`
751
+ initializer: `['${VALIDATED_FLAG_VALUE2}']`
691
752
  });
692
753
  }
693
754
  }
694
755
  } else {
695
756
  clause.addPropertyAssignment({
696
- name: FLAGS_PROPERTY_NAME,
697
- initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
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 FLAGS_PROPERTY_NAME2 = "flags";
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
- var FLAG_DEFINITION_INITIALIZER = `{
933
+ function flagDefinitionInitializer(eventType) {
934
+ return `{
872
935
  id: '${FLAG_ID}',
873
936
  label: {
874
- id: 'event.birth.flag.${FLAG_ID}',
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 isBirthConfig(configArg) {
894
- const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME6);
895
- if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
896
- const initializer = typeProperty.getInitializer();
897
- if (!initializer) return false;
898
- if (import_ts_morph6.Node.isStringLiteral(initializer)) {
899
- return initializer.getLiteralValue().toLowerCase() === "birth";
900
- }
901
- if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
902
- return initializer.getName().toLowerCase() === "birth";
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 false;
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 flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
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(FLAG_DEFINITION_INITIALIZER);
991
+ flagsInit.addElement(initializer);
925
992
  return true;
926
993
  }
927
994
  return false;
928
995
  }
929
996
  configArg.addPropertyAssignment({
930
- name: FLAGS_PROPERTY_NAME2,
997
+ name: FLAGS_PROPERTY_NAME3,
931
998
  initializer: `[
932
- ${FLAG_DEFINITION_INITIALIZER}
999
+ ${initializer}
933
1000
  ]`
934
1001
  });
935
1002
  return true;
936
1003
  }
937
1004
  function ensureActionOperationFlag(action, operation) {
938
- const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME2);
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: FLAGS_PROPERTY_NAME2,
1017
+ name: FLAGS_PROPERTY_NAME3,
951
1018
  initializer: `[${entry}]`
952
1019
  });
953
1020
  return true;
954
1021
  }
955
- function processBirthConfig(configArg, relPath) {
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(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
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(FLAGS_PROPERTY_NAME2);
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: FLAGS_PROPERTY_NAME2,
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
- if (!isBirthConfig(configArg)) continue;
1080
- totalChanges += processBirthConfig(configArg, relPath);
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 birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
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 birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
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, path22) {
1886
+ function resolveConfigChain(configObj, path23) {
1817
1887
  let current = configObj;
1818
- for (const key of path22) {
1888
+ for (const key of path23) {
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;
@@ -2110,6 +2180,10 @@ var scopeByEvent = z3.preprocess(
2110
2180
  (val) => val === void 0 ? void 0 : [val].flat(),
2111
2181
  z3.array(z3.string()).optional()
2112
2182
  ).describe("Event type, e.g. birth, death");
2183
+ var userRole = z3.preprocess(
2184
+ (val) => val === void 0 ? void 0 : [val].flat(),
2185
+ z3.array(z3.string()).optional()
2186
+ ).describe("User role, e.g. admin, field agent");
2113
2187
  var scopeOptionsPlaceEvent = z3.object({
2114
2188
  event: scopeByEvent,
2115
2189
  placeOfEvent: JurisdictionFilter.optional()
@@ -2133,6 +2207,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2133
2207
  var AccessLevelOptions = z3.object({
2134
2208
  accessLevel: JurisdictionFilter.optional()
2135
2209
  });
2210
+ var AllUserScopeOptions = AccessLevelOptions.extend({
2211
+ role: userRole.optional()
2212
+ });
2136
2213
  var WorkqueueOrDashboardOptions = z3.object({
2137
2214
  ids: z3.preprocess(
2138
2215
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2142,6 +2219,7 @@ var WorkqueueOrDashboardOptions = z3.object({
2142
2219
  var AllScopeOptions = z3.object({
2143
2220
  ...AllRecordScopeOptions.shape,
2144
2221
  ...AccessLevelOptions.shape,
2222
+ ...AllUserScopeOptions.shape,
2145
2223
  ...WorkqueueOrDashboardOptions.shape
2146
2224
  });
2147
2225
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2214,6 +2292,28 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2214
2292
  ]).describe(
2215
2293
  "Scopes used to check user's permission to perform actions on a record."
2216
2294
  );
2295
+ var SystemScopeType = z3.enum([
2296
+ "organisation.read-locations",
2297
+ "user.read",
2298
+ "user.create",
2299
+ "user.edit"
2300
+ ]);
2301
+ var UserScopeType = SystemScopeType.extract([
2302
+ "user.read",
2303
+ "user.create",
2304
+ "user.edit"
2305
+ ]);
2306
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2307
+ var UserScopeV2 = z3.discriminatedUnion("type", [
2308
+ z3.object({
2309
+ type: ScopesWithRoleOption,
2310
+ options: AllUserScopeOptions.optional()
2311
+ }),
2312
+ z3.object({
2313
+ type: UserScopeType.extract(["user.read"]),
2314
+ options: AccessLevelOptions.optional()
2315
+ })
2316
+ ]);
2217
2317
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2218
2318
  z3.object({
2219
2319
  type: ScopesWithPlaceEventOptions,
@@ -2234,16 +2334,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2234
2334
  }).optional()
2235
2335
  })
2236
2336
  ]).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
2337
  var Scope2 = z3.discriminatedUnion("type", [
2244
2338
  z3.object({ type: PlainScopeType }),
2245
2339
  ...RecordScopeV2.options,
2246
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2340
+ ...UserScopeV2.options,
2341
+ z3.object({
2342
+ type: z3.literal("organisation.read-locations"),
2343
+ options: AccessLevelOptions.optional()
2344
+ }),
2247
2345
  z3.object({
2248
2346
  type: z3.literal("workqueue"),
2249
2347
  options: WorkqueueOrDashboardOptions
@@ -4135,10 +4233,356 @@ async function main22() {
4135
4233
  }
4136
4234
  }
4137
4235
 
4138
- // src/migrations/v2.0/simplify-analytics-precalculations.ts
4139
- var import_ts_morph20 = require("ts-morph");
4140
- var import_fs3 = __toESM(require("fs"));
4236
+ // src/migrations/v2.0/add-resend-invite-notification.ts
4237
+ var import_fs3 = require("fs");
4141
4238
  var import_path22 = __toESM(require("path"));
4239
+ var import_ts_morph20 = require("ts-morph");
4240
+ var TS_MORPH_PROJECT_OPTIONS = {
4241
+ skipAddingFilesFromTsConfig: true,
4242
+ manipulationSettings: {
4243
+ indentationText: import_ts_morph20.IndentationText.TwoSpaces
4244
+ }
4245
+ };
4246
+ var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
4247
+ var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
4248
+ var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
4249
+ var SMS_SERVICE = "src/api/notification/sms-service.ts";
4250
+ var NOTIFICATION_CSV = "src/translations/notification.csv";
4251
+ var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
4252
+ var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
4253
+ <html>
4254
+ <head>
4255
+ <link
4256
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
4257
+ rel="stylesheet"
4258
+ />
4259
+ <style type="text/css">
4260
+ body {
4261
+ font-family: 'Noto Sans', sans-serif;
4262
+ color: #222;
4263
+ padding: 16px 24px;
4264
+ }
4265
+
4266
+ h1 {
4267
+ font-size: 21px;
4268
+ margin-top: 32px;
4269
+ margin-bottom: 36px;
4270
+ font-weight: 700;
4271
+ }
4272
+
4273
+ p {
4274
+ font-weight: 400;
4275
+ font-size: 16px;
4276
+ line-height: 1.8;
4277
+ margin-bottom: 24px;
4278
+ }
4279
+
4280
+ i {
4281
+ color: #666;
4282
+ font-weight: 400;
4283
+ font-size: 16px;
4284
+ }
4285
+ </style>
4286
+ </head>
4287
+
4288
+ <body>
4289
+ <img
4290
+ src="{{countryLogo}}"
4291
+ alt="country_logo"
4292
+ style="max-height: 88px; max-width: 100%"
4293
+ />
4294
+ <h1>Your {{applicationName}} account invitation</h1>
4295
+ <p>Hello {{firstname}},</p>
4296
+ <p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
4297
+ <p>
4298
+ Username: <strong>{{username}}</strong><br />
4299
+ Password: <strong>{{temporaryPassword}}</strong>
4300
+ </p>
4301
+ <p>
4302
+ Please click the link below to complete your account setup and start using
4303
+ {{applicationName}}.
4304
+ </p>
4305
+
4306
+ <div style="margin-top: 32px; margin-bottom: 32px">
4307
+ <a href="{{loginURL}}">Complete setup</a>
4308
+ </div>
4309
+ <br />
4310
+ <p>
4311
+ Best regards, <br />
4312
+ {{applicationName}} Team
4313
+ </p>
4314
+ </body>
4315
+ </html>
4316
+ `;
4317
+ 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";
4318
+ function getObjectLiteralFromConst(declaration) {
4319
+ if (!declaration) {
4320
+ return;
4321
+ }
4322
+ const initializer = declaration.getInitializer();
4323
+ if (!initializer) {
4324
+ return;
4325
+ }
4326
+ if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
4327
+ return initializer;
4328
+ }
4329
+ if (import_ts_morph20.Node.isAsExpression(initializer)) {
4330
+ const expression = initializer.getExpression();
4331
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4332
+ return expression;
4333
+ }
4334
+ }
4335
+ if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
4336
+ const expression = initializer.getExpression();
4337
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4338
+ return expression;
4339
+ }
4340
+ }
4341
+ }
4342
+ function patchEmailTemplatesIndex() {
4343
+ const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
4344
+ if (!(0, import_fs3.existsSync)(full)) {
4345
+ console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
4346
+ return false;
4347
+ }
4348
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4349
+ const sourceFile = project.addSourceFileAtPath(full);
4350
+ let changed = false;
4351
+ const triggerVariableObject = getObjectLiteralFromConst(
4352
+ sourceFile.getVariableDeclaration("TriggerVariable")
4353
+ );
4354
+ if (triggerVariableObject) {
4355
+ const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
4356
+ if (!hasResendInviteVariable) {
4357
+ const properties = triggerVariableObject.getProperties();
4358
+ const lastProperty = properties[properties.length - 1];
4359
+ if (lastProperty) {
4360
+ sourceFile.insertText(
4361
+ lastProperty.getEnd(),
4362
+ `,
4363
+ [TriggerEvent.RESEND_INVITE]: z.object({
4364
+ firstname: z.string(),
4365
+ username: z.string(),
4366
+ temporaryPassword: z.string(),
4367
+ completeSetupUrl: z.string(),
4368
+ loginURL: z.string()
4369
+ })`
4370
+ );
4371
+ changed = true;
4372
+ }
4373
+ }
4374
+ }
4375
+ const templatesObject = getObjectLiteralFromConst(
4376
+ sourceFile.getVariableDeclaration("templates")
4377
+ );
4378
+ if (templatesObject) {
4379
+ const hasResendInviteTemplate = templatesObject.getProperties().some(
4380
+ (prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
4381
+ );
4382
+ if (!hasResendInviteTemplate) {
4383
+ const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
4384
+ const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
4385
+ if (anchor) {
4386
+ sourceFile.insertText(
4387
+ anchor.getEnd(),
4388
+ `,
4389
+ [TriggerEvent.RESEND_INVITE]: {
4390
+ type: 'resend-invite',
4391
+ subject: 'Your OpenCRVS account invitation',
4392
+ template:
4393
+ readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
4394
+ }`
4395
+ );
4396
+ changed = true;
4397
+ }
4398
+ }
4399
+ }
4400
+ if (changed) {
4401
+ sourceFile.saveSync();
4402
+ }
4403
+ return changed;
4404
+ }
4405
+ function patchNotificationHandler() {
4406
+ const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
4407
+ if (!(0, import_fs3.existsSync)(full)) {
4408
+ return false;
4409
+ }
4410
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4411
+ const sourceFile = project.addSourceFileAtPath(full);
4412
+ const convertFn = sourceFile.getFunction("convertPayloadToVariable");
4413
+ if (!convertFn) {
4414
+ return false;
4415
+ }
4416
+ const switchStmt = convertFn.getFirstDescendantByKind(
4417
+ import_ts_morph20.SyntaxKind.SwitchStatement
4418
+ );
4419
+ if (!switchStmt) {
4420
+ return false;
4421
+ }
4422
+ const clauses = switchStmt.getCaseBlock().getClauses();
4423
+ const hasResendInvite = clauses.some(
4424
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
4425
+ );
4426
+ if (hasResendInvite) {
4427
+ return false;
4428
+ }
4429
+ const userCreatedClauseIndex = clauses.findIndex(
4430
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
4431
+ );
4432
+ if (userCreatedClauseIndex < 0) {
4433
+ return false;
4434
+ }
4435
+ const userCreatedClause = clauses[userCreatedClauseIndex];
4436
+ sourceFile.insertText(
4437
+ userCreatedClause.getEnd(),
4438
+ `
4439
+
4440
+ case TriggerEvent.RESEND_INVITE:
4441
+ return {
4442
+ firstname,
4443
+ username: payload.username,
4444
+ temporaryPassword: payload.temporaryPassword,
4445
+ completeSetupUrl: LOGIN_URL,
4446
+ loginURL: LOGIN_URL
4447
+ }`
4448
+ );
4449
+ sourceFile.saveSync();
4450
+ return true;
4451
+ }
4452
+ function getReturnedArrayLiteral(functionFilePath, fnName) {
4453
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4454
+ const sourceFile = project.addSourceFileAtPath(functionFilePath);
4455
+ const fn = sourceFile.getFunction(fnName);
4456
+ const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
4457
+ const expr = returnStmt?.getExpression();
4458
+ if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
4459
+ return { sourceFile, arrayLiteral: void 0 };
4460
+ }
4461
+ return { sourceFile, arrayLiteral: expr };
4462
+ }
4463
+ function patchUserNotificationRoutes() {
4464
+ const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
4465
+ if (!(0, import_fs3.existsSync)(full)) {
4466
+ return false;
4467
+ }
4468
+ const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
4469
+ full,
4470
+ "getUserNotificationRoutes"
4471
+ );
4472
+ if (!arrayLiteral) {
4473
+ return false;
4474
+ }
4475
+ const elements = arrayLiteral.getElements();
4476
+ const routeExists = elements.some(
4477
+ (element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
4478
+ );
4479
+ if (routeExists) {
4480
+ return false;
4481
+ }
4482
+ const anchor = elements.find(
4483
+ (element) => element.getText().includes(`path: '/triggers/user/user-created'`)
4484
+ ) ?? elements[elements.length - 1];
4485
+ if (!anchor) {
4486
+ return false;
4487
+ }
4488
+ sourceFile.insertText(
4489
+ anchor.getEnd(),
4490
+ `,
4491
+ {
4492
+ method: 'POST',
4493
+ path: '/triggers/user/resend-invite',
4494
+ handler: makeNotificationHandler('resend-invite'),
4495
+ options: {
4496
+ auth: false,
4497
+ tags: ['api'],
4498
+ description: 'Handles notification for resent user invite'
4499
+ }
4500
+ }`
4501
+ );
4502
+ sourceFile.saveSync();
4503
+ return true;
4504
+ }
4505
+ function patchSmsService() {
4506
+ const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
4507
+ if (!(0, import_fs3.existsSync)(full)) {
4508
+ return false;
4509
+ }
4510
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4511
+ const sourceFile = project.addSourceFileAtPath(full);
4512
+ let changed = false;
4513
+ const otherTemplatesObject = getObjectLiteralFromConst(
4514
+ sourceFile.getVariableDeclaration("otherTemplates")
4515
+ );
4516
+ if (otherTemplatesObject) {
4517
+ const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
4518
+ if (!hasResendTemplate) {
4519
+ const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
4520
+ otherTemplatesObject.insertPropertyAssignment(
4521
+ userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
4522
+ {
4523
+ name: "resendInviteNotification",
4524
+ initializer: `'resendInviteNotification'`
4525
+ }
4526
+ );
4527
+ changed = true;
4528
+ }
4529
+ }
4530
+ const triggerToSmsTemplateObject = getObjectLiteralFromConst(
4531
+ sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
4532
+ );
4533
+ if (triggerToSmsTemplateObject) {
4534
+ const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
4535
+ if (!hasResendInviteMap) {
4536
+ const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
4537
+ triggerToSmsTemplateObject.insertPropertyAssignment(
4538
+ userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
4539
+ {
4540
+ name: `['resend-invite']`,
4541
+ initializer: `'resendInviteNotification'`
4542
+ }
4543
+ );
4544
+ changed = true;
4545
+ }
4546
+ }
4547
+ if (changed) {
4548
+ sourceFile.saveSync();
4549
+ }
4550
+ return changed;
4551
+ }
4552
+ async function main23() {
4553
+ console.log("Adding RESEND_INVITE notification wiring\u2026");
4554
+ const touched = [];
4555
+ if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
4556
+ if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
4557
+ if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
4558
+ if (patchSmsService()) touched.push(SMS_SERVICE);
4559
+ const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
4560
+ if ((0, import_fs3.existsSync)(csvPath)) {
4561
+ let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
4562
+ if (!/^resendInviteNotification,/m.test(t)) {
4563
+ if (!t.endsWith("\n")) t += "\n";
4564
+ (0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
4565
+ touched.push(NOTIFICATION_CSV);
4566
+ }
4567
+ }
4568
+ const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
4569
+ (0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
4570
+ if (!(0, import_fs3.existsSync)(htmlPath)) {
4571
+ (0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
4572
+ touched.push(RESEND_INVITE_HTML);
4573
+ }
4574
+ if (touched.length === 0) {
4575
+ console.log(" Nothing to update (already present or anchors not found).");
4576
+ return;
4577
+ }
4578
+ console.log(` Updated:
4579
+ ${touched.map((f) => ` - ${f}`).join("\n")}`);
4580
+ }
4581
+
4582
+ // src/migrations/v2.0/simplify-analytics-precalculations.ts
4583
+ var import_ts_morph21 = require("ts-morph");
4584
+ var import_fs4 = __toESM(require("fs"));
4585
+ var import_path23 = __toESM(require("path"));
4142
4586
  var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
4143
4587
  var FUNCTION_NAME = "precalculateAdditionalAnalytics";
4144
4588
  var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
@@ -4174,10 +4618,10 @@ function findPrecalculateFunction(sourceFile) {
4174
4618
  return void 0;
4175
4619
  }
4176
4620
  function getFunctionBodyBlock(fn) {
4177
- if (import_ts_morph20.Node.isFunctionDeclaration(fn)) return fn.getBody();
4621
+ if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
4178
4622
  const initializer = fn.getInitializer();
4179
4623
  if (!initializer) return void 0;
4180
- if (!import_ts_morph20.Node.isArrowFunction(initializer) && !import_ts_morph20.Node.isFunctionExpression(initializer)) {
4624
+ if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
4181
4625
  return void 0;
4182
4626
  }
4183
4627
  return initializer.getBody();
@@ -4187,9 +4631,9 @@ function simplifyPrecalculateFunction(sourceFile) {
4187
4631
  const fn = findPrecalculateFunction(sourceFile);
4188
4632
  if (!fn) return log;
4189
4633
  const body = getFunctionBodyBlock(fn);
4190
- if (!body || !import_ts_morph20.Node.isBlock(body)) return log;
4634
+ if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
4191
4635
  for (const statement of [...body.getStatements()]) {
4192
- const references = statement.getDescendantsOfKind(import_ts_morph20.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
4636
+ const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
4193
4637
  if (references) {
4194
4638
  statement.remove();
4195
4639
  log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
@@ -4197,7 +4641,7 @@ function simplifyPrecalculateFunction(sourceFile) {
4197
4641
  }
4198
4642
  const remaining = body.getStatements();
4199
4643
  const last = remaining[remaining.length - 1];
4200
- const alreadyCorrect = last && import_ts_morph20.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
4644
+ const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
4201
4645
  if (!alreadyCorrect) {
4202
4646
  body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
4203
4647
  log.push(
@@ -4206,17 +4650,17 @@ function simplifyPrecalculateFunction(sourceFile) {
4206
4650
  }
4207
4651
  return log;
4208
4652
  }
4209
- async function main23() {
4653
+ async function main24() {
4210
4654
  const cwd = process.cwd();
4211
- const absPath = import_path22.default.join(cwd, ANALYTICS_FILE_REL);
4212
- if (!import_fs3.default.existsSync(absPath)) {
4655
+ const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
4656
+ if (!import_fs4.default.existsSync(absPath)) {
4213
4657
  console.log(
4214
4658
  `[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
4215
4659
  );
4216
4660
  return;
4217
4661
  }
4218
- const project = new import_ts_morph20.Project({
4219
- tsConfigFilePath: import_path22.default.resolve(cwd, "tsconfig.json"),
4662
+ const project = new import_ts_morph21.Project({
4663
+ tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
4220
4664
  skipAddingFilesFromTsConfig: false
4221
4665
  });
4222
4666
  const sourceFile = project.getSourceFile(absPath);
@@ -4245,15 +4689,15 @@ Saved ${ANALYTICS_FILE_REL}.`);
4245
4689
 
4246
4690
  // src/migrations/v2.0/merge-infrastructure-directory.ts
4247
4691
  var import_child_process2 = require("child_process");
4248
- var import_fs4 = require("fs");
4692
+ var import_fs5 = require("fs");
4249
4693
  var import_os = require("os");
4250
- var import_path23 = require("path");
4694
+ var import_path24 = require("path");
4251
4695
  var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
4252
4696
  var INFRASTRUCTURE_DIR = "infrastructure";
4253
4697
  var BASE_BRANCH = "release-v1.9";
4254
- function gitShowBytes(ref, path22) {
4698
+ function gitShowBytes(ref, path23) {
4255
4699
  try {
4256
- const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path22}`], {
4700
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
4257
4701
  cwd: process.cwd(),
4258
4702
  stdio: ["ignore", "pipe", "pipe"]
4259
4703
  });
@@ -4262,7 +4706,7 @@ function gitShowBytes(ref, path22) {
4262
4706
  return null;
4263
4707
  }
4264
4708
  }
4265
- async function main24() {
4709
+ async function main25() {
4266
4710
  console.log(
4267
4711
  `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4268
4712
  `
@@ -4296,15 +4740,15 @@ async function main24() {
4296
4740
  );
4297
4741
  return;
4298
4742
  }
4299
- const tmpDir = (0, import_fs4.mkdtempSync)((0, import_path23.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
4300
- const baseTmp = (0, import_path23.join)(tmpDir, "base");
4301
- const theirsTmp = (0, import_path23.join)(tmpDir, "theirs");
4743
+ const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
4744
+ const baseTmp = (0, import_path24.join)(tmpDir, "base");
4745
+ const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
4302
4746
  let added = 0;
4303
4747
  let merged = 0;
4304
4748
  const conflictedFiles = [];
4305
4749
  for (const file of upstreamFiles) {
4306
- const fullPath = (0, import_path23.join)(process.cwd(), file);
4307
- if (!(0, import_fs4.existsSync)(fullPath)) {
4750
+ const fullPath = (0, import_path24.join)(process.cwd(), file);
4751
+ if (!(0, import_fs5.existsSync)(fullPath)) {
4308
4752
  if (tryGit(["checkout", ref, "--", file])) {
4309
4753
  console.log(` + ${file} (new from upstream)`);
4310
4754
  added++;
@@ -4318,9 +4762,9 @@ async function main24() {
4318
4762
  console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
4319
4763
  continue;
4320
4764
  }
4321
- (0, import_fs4.writeFileSync)(theirsTmp, theirContents);
4765
+ (0, import_fs5.writeFileSync)(theirsTmp, theirContents);
4322
4766
  const baseContents = gitShowBytes(baseRef, file);
4323
- (0, import_fs4.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
4767
+ (0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
4324
4768
  try {
4325
4769
  (0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
4326
4770
  cwd: process.cwd(),
@@ -4364,12 +4808,12 @@ async function main24() {
4364
4808
  }
4365
4809
 
4366
4810
  // src/migrations/v2.0/delete-infrastructure-directory.ts
4367
- var import_fs5 = require("fs");
4368
- var import_path24 = require("path");
4811
+ var import_fs6 = require("fs");
4812
+ var import_path25 = require("path");
4369
4813
  var INFRASTRUCTURE_DIR2 = "infrastructure";
4370
- async function main25() {
4371
- const fullPath = (0, import_path24.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4372
- if (!(0, import_fs5.existsSync)(fullPath)) {
4814
+ async function main26() {
4815
+ const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4816
+ if (!(0, import_fs6.existsSync)(fullPath)) {
4373
4817
  console.log(
4374
4818
  `'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
4375
4819
  );
@@ -4382,8 +4826,8 @@ async function main25() {
4382
4826
  silent: true
4383
4827
  });
4384
4828
  console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4385
- if ((0, import_fs5.existsSync)(fullPath)) {
4386
- (0, import_fs5.rmSync)(fullPath, { recursive: true, force: true });
4829
+ if ((0, import_fs6.existsSync)(fullPath)) {
4830
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4387
4831
  console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4388
4832
  }
4389
4833
  console.log(
@@ -4416,11 +4860,12 @@ async function runUpgrade(dockerSwarm) {
4416
4860
  await main21();
4417
4861
  await main22();
4418
4862
  await main23();
4863
+ await main24();
4419
4864
  await main17();
4420
4865
  if (dockerSwarm) {
4421
- await main24();
4422
- } else {
4423
4866
  await main25();
4867
+ } else {
4868
+ await main26();
4424
4869
  }
4425
4870
  }
4426
4871
 
@@ -4449,7 +4894,7 @@ Options:
4449
4894
  'infrastructure/' directory is deleted (default).
4450
4895
  -h, --help Show this message.
4451
4896
  `.trim();
4452
- function main26() {
4897
+ function main27() {
4453
4898
  const command = args[0];
4454
4899
  if (!command || command === "--help" || command === "-h") {
4455
4900
  console.log(USAGE);
@@ -4524,4 +4969,4 @@ function handleCheckTranslations() {
4524
4969
  console.warn("This command is not implemented yet!");
4525
4970
  process.exit(1);
4526
4971
  }
4527
- main26();
4972
+ main27();