@opencrvs/toolkit 2.0.0-rc.bba732d → 2.0.0-rc.bcb5fb2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.sh CHANGED
@@ -66,4 +66,7 @@ fi
66
66
  npx esbuild src/cli.ts --bundle --format=cjs --outdir=./dist --allow-overwrite --packages=external --banner:js="#!/usr/bin/env node"
67
67
  chmod +x ./dist/cli.js
68
68
 
69
+ # Generate core-en.json from client + login source and place it in dist
70
+ (cd ../.. && yarn generate:core-translations)
71
+
69
72
  echo "Build completed successfully."
package/dist/cli.js CHANGED
@@ -3674,6 +3674,10 @@ var ACTION_PROPERTY_NAME2 = "action";
3674
3674
  var CONDITIONALS_PROPERTY_NAME = "conditionals";
3675
3675
  var TYPE_PROPERTY_NAME7 = "type";
3676
3676
  var SLUG_PROPERTY_NAME = "slug";
3677
+ var READ_ACTION_TYPE = "READ";
3678
+ var ACTION_TYPE_IMPORT_NAME = "ActionType";
3679
+ var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
3680
+ var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
3677
3681
  var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
3678
3682
  "READ",
3679
3683
  "DELETE",
@@ -3721,91 +3725,137 @@ function isUnsupportedActionType(action) {
3721
3725
  }
3722
3726
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
3723
3727
  }
3724
- function migrateWorkqueueActions(workqueue, relPath) {
3725
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3726
- if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3727
- return 0;
3728
- }
3729
- const actionsInitializer = actionsProperty.getInitializer();
3730
- if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3731
- return 0;
3728
+ function ensureValidAction(workqueue, relPath) {
3729
+ const workqueueLabel = getWorkqueueLabel(workqueue);
3730
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3731
+ if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
3732
+ const initializer = actionProperty.getInitializer();
3733
+ if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
3734
+ if (!isUnsupportedActionType(initializer)) {
3735
+ return { changed: false, usedReadFallback: false };
3736
+ }
3737
+ actionProperty.set({
3738
+ name: ACTION_PROPERTY_NAME2,
3739
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3740
+ });
3741
+ console.log(
3742
+ ` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
3743
+ );
3744
+ return { changed: true, usedReadFallback: true };
3745
+ }
3732
3746
  }
3747
+ workqueue.addPropertyAssignment({
3748
+ name: ACTION_PROPERTY_NAME2,
3749
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
3750
+ });
3751
+ console.log(
3752
+ ` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
3753
+ );
3754
+ return { changed: true, usedReadFallback: true };
3755
+ }
3756
+ function migrateWorkqueueActions(workqueue, relPath) {
3733
3757
  const workqueueLabel = getWorkqueueLabel(workqueue);
3734
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3735
- if (existingActionProperty) {
3736
- if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3737
- const existingActionInitializer = existingActionProperty.getInitializer();
3738
- if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3739
- const conditionalsProperty2 = existingActionInitializer.getProperty(
3740
- CONDITIONALS_PROPERTY_NAME
3758
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
3759
+ let actionsArrayMigrated = false;
3760
+ if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
3761
+ const actionsInitializer = actionsProperty.getInitializer();
3762
+ if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
3763
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
3764
+ if (existingActionProperty) {
3765
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
3766
+ const existingActionInitializer = existingActionProperty.getInitializer();
3767
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
3768
+ const conditionalsProperty = existingActionInitializer.getProperty(
3769
+ CONDITIONALS_PROPERTY_NAME
3770
+ );
3771
+ if (conditionalsProperty) {
3772
+ conditionalsProperty.remove();
3773
+ console.log(
3774
+ ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3775
+ );
3776
+ }
3777
+ }
3778
+ }
3779
+ actionsProperty.remove();
3780
+ console.log(
3781
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3782
+ );
3783
+ actionsArrayMigrated = true;
3784
+ } else {
3785
+ const actionCandidates = actionsInitializer.getElements().filter(
3786
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3741
3787
  );
3742
- if (conditionalsProperty2) {
3743
- conditionalsProperty2.remove();
3788
+ if (actionCandidates.length === 0) {
3789
+ actionsProperty.remove();
3744
3790
  console.log(
3745
- ` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
3791
+ ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3746
3792
  );
3747
- }
3748
- if (isUnsupportedActionType(existingActionInitializer)) {
3749
- existingActionProperty.remove();
3750
- console.log(
3751
- ` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
3793
+ actionsArrayMigrated = true;
3794
+ } else {
3795
+ if (actionCandidates.length > 1) {
3796
+ const droppedCount = actionCandidates.length - 1;
3797
+ console.warn(
3798
+ ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3799
+ );
3800
+ }
3801
+ const conditionalsProperty = actionCandidates[0].getProperty(
3802
+ CONDITIONALS_PROPERTY_NAME
3752
3803
  );
3804
+ if (conditionalsProperty) {
3805
+ conditionalsProperty.remove();
3806
+ console.log(
3807
+ ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3808
+ );
3809
+ }
3810
+ if (isUnsupportedActionType(actionCandidates[0])) {
3811
+ actionsProperty.remove();
3812
+ console.log(
3813
+ ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3814
+ );
3815
+ actionsArrayMigrated = true;
3816
+ } else {
3817
+ const firstActionText = actionCandidates[0].getText();
3818
+ workqueue.addPropertyAssignment({
3819
+ name: ACTION_PROPERTY_NAME2,
3820
+ initializer: firstActionText
3821
+ });
3822
+ actionsProperty.remove();
3823
+ console.log(
3824
+ ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3825
+ );
3826
+ actionsArrayMigrated = true;
3827
+ }
3753
3828
  }
3754
3829
  }
3755
3830
  }
3756
- actionsProperty.remove();
3757
- console.log(
3758
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
3759
- );
3760
- return 1;
3761
- }
3762
- const actionCandidates = actionsInitializer.getElements().filter(
3763
- (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
3764
- );
3765
- if (actionCandidates.length === 0) {
3766
- actionsProperty.remove();
3767
- console.log(
3768
- ` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
3769
- );
3770
- return 1;
3771
3831
  }
3772
- if (actionCandidates.length > 1) {
3773
- const droppedCount = actionCandidates.length - 1;
3774
- console.warn(
3775
- ` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
3776
- );
3777
- }
3778
- const conditionalsProperty = actionCandidates[0].getProperty(
3779
- CONDITIONALS_PROPERTY_NAME
3832
+ const fallback = ensureValidAction(workqueue, relPath);
3833
+ return {
3834
+ changed: actionsArrayMigrated || fallback.changed,
3835
+ usedReadFallback: fallback.usedReadFallback
3836
+ };
3837
+ }
3838
+ function ensureActionTypeImport(sourceFile) {
3839
+ const existingImport = sourceFile.getImportDeclaration(
3840
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
3780
3841
  );
3781
- if (conditionalsProperty) {
3782
- conditionalsProperty.remove();
3783
- console.log(
3784
- ` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
3785
- );
3786
- }
3787
- if (isUnsupportedActionType(actionCandidates[0])) {
3788
- actionsProperty.remove();
3789
- console.log(
3790
- ` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
3791
- );
3792
- return 1;
3842
+ if (existingImport) {
3843
+ const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
3844
+ if (!alreadyImported) {
3845
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
3846
+ }
3847
+ return;
3793
3848
  }
3794
- const firstActionText = actionCandidates[0].getText();
3795
- workqueue.addPropertyAssignment({
3796
- name: ACTION_PROPERTY_NAME2,
3797
- initializer: firstActionText
3849
+ sourceFile.addImportDeclaration({
3850
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
3851
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
3798
3852
  });
3799
- actionsProperty.remove();
3800
- console.log(
3801
- ` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
3802
- );
3803
- return 1;
3804
3853
  }
3805
3854
  function processFile13(filePath, project) {
3806
3855
  const sourceFile = project.getSourceFile(filePath);
3807
3856
  if (!sourceFile) return 0;
3808
3857
  let migratedWorkqueues = 0;
3858
+ let needsActionTypeImport = false;
3809
3859
  const relPath = import_path18.default.relative(process.cwd(), filePath);
3810
3860
  const callExpressions = sourceFile.getDescendantsOfKind(
3811
3861
  import_ts_morph17.SyntaxKind.CallExpression
@@ -3821,9 +3871,14 @@ function processFile13(filePath, project) {
3821
3871
  if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3822
3872
  for (const element of workqueuesArg.getElements()) {
3823
3873
  if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3824
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3874
+ const result = migrateWorkqueueActions(element, relPath);
3875
+ if (result.changed) migratedWorkqueues++;
3876
+ if (result.usedReadFallback) needsActionTypeImport = true;
3825
3877
  }
3826
3878
  }
3879
+ if (needsActionTypeImport) {
3880
+ ensureActionTypeImport(sourceFile);
3881
+ }
3827
3882
  return migratedWorkqueues;
3828
3883
  }
3829
3884
  async function main18() {
@@ -4158,7 +4213,7 @@ Saved ${handlerRelPath}.`);
4158
4213
  // src/migrations/v2.0/checkout-upstream-files.ts
4159
4214
  var import_child_process = require("child_process");
4160
4215
  var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
4161
- var UPSTREAM_BRANCH = "develop";
4216
+ var UPSTREAM_BRANCH = "release-v2.0.0";
4162
4217
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
4163
4218
  var FILES_TO_CHECKOUT = [
4164
4219
  "src/analytics/analytics.ts",
@@ -4708,9 +4763,13 @@ function gitShowBytes(ref, path23) {
4708
4763
  return null;
4709
4764
  }
4710
4765
  }
4711
- async function main25() {
4766
+ async function main25({
4767
+ subdirs = []
4768
+ } = {}) {
4769
+ const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
4770
+ const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
4712
4771
  console.log(
4713
- `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4772
+ `Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4714
4773
  `
4715
4774
  );
4716
4775
  assertIsGitRepo();
@@ -4725,20 +4784,12 @@ async function main25() {
4725
4784
  const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4726
4785
  const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4727
4786
  const upstreamFiles = runGit(
4728
- [
4729
- "ls-tree",
4730
- "-r",
4731
- "--name-only",
4732
- "-z",
4733
- ref,
4734
- "--",
4735
- `${INFRASTRUCTURE_DIR}/`
4736
- ],
4787
+ ["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
4737
4788
  { silent: true }
4738
4789
  ).split("\0").filter(Boolean);
4739
4790
  if (upstreamFiles.length === 0) {
4740
4791
  console.log(
4741
- ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4792
+ ` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
4742
4793
  );
4743
4794
  return;
4744
4795
  }
@@ -4813,7 +4864,9 @@ async function main25() {
4813
4864
  var import_fs6 = require("fs");
4814
4865
  var import_path25 = require("path");
4815
4866
  var INFRASTRUCTURE_DIR2 = "infrastructure";
4816
- async function main26() {
4867
+ async function main26({
4868
+ keep = []
4869
+ } = {}) {
4817
4870
  const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4818
4871
  if (!(0, import_fs6.existsSync)(fullPath)) {
4819
4872
  console.log(
@@ -4821,24 +4874,64 @@ async function main26() {
4821
4874
  );
4822
4875
  return;
4823
4876
  }
4824
- console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4825
- `);
4826
4877
  assertIsGitRepo();
4827
- runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4828
- silent: true
4829
- });
4830
- console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4831
- if ((0, import_fs6.existsSync)(fullPath)) {
4832
- (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4833
- console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4878
+ if (keep.length === 0) {
4879
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4880
+ `);
4881
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4882
+ silent: true
4883
+ });
4884
+ console.log(
4885
+ ` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
4886
+ );
4887
+ if ((0, import_fs6.existsSync)(fullPath)) {
4888
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4889
+ console.log(
4890
+ ` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
4891
+ );
4892
+ }
4893
+ console.log(
4894
+ `
4895
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4896
+ );
4897
+ return;
4898
+ }
4899
+ const keepSet = new Set(keep);
4900
+ console.log(
4901
+ `Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
4902
+ `
4903
+ );
4904
+ const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
4905
+ let deleted = 0;
4906
+ for (const entry of topLevelEntries) {
4907
+ if (keepSet.has(entry.name)) {
4908
+ console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
4909
+ continue;
4910
+ }
4911
+ const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
4912
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
4913
+ const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
4914
+ if ((0, import_fs6.existsSync)(fullEntryPath)) {
4915
+ (0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
4916
+ }
4917
+ console.log(` Deleted '${relPath}'.`);
4918
+ deleted++;
4919
+ }
4920
+ const presentNames = new Set(topLevelEntries.map((e) => e.name));
4921
+ const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
4922
+ if (missingKeeps.length > 0) {
4923
+ console.warn(
4924
+ ` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
4925
+ );
4834
4926
  }
4835
4927
  console.log(
4836
4928
  `
4837
- Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4929
+ Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4838
4930
  );
4839
4931
  }
4840
4932
 
4841
4933
  // src/migrations/v2.0/index.ts
4934
+ var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
4842
4935
  async function runUpgrade(dockerSwarm) {
4843
4936
  await main18();
4844
4937
  await main();
@@ -4867,7 +4960,8 @@ async function runUpgrade(dockerSwarm) {
4867
4960
  if (dockerSwarm) {
4868
4961
  await main25();
4869
4962
  } else {
4870
- await main26();
4963
+ await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
4964
+ await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
4871
4965
  }
4872
4966
  }
4873
4967