@opencrvs/toolkit 2.1.0-rc.0cb2d8f → 2.1.0-rc.12673aa

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.
Files changed (109) hide show
  1. package/README.md +3 -12
  2. package/build.sh +9 -1
  3. package/create-countryconfig/index.js +412 -59
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +4 -1
  6. package/dist/application-config/index.js +342 -276
  7. package/dist/authentication/index.d.ts +67 -0
  8. package/dist/authentication/index.d.ts.map +1 -0
  9. package/dist/authentication/index.js +750 -0
  10. package/dist/cli.js +1918 -282
  11. package/dist/commons/api/router.d.ts +724 -126
  12. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  13. package/dist/commons/conditionals/validate.d.ts +16 -5
  14. package/dist/commons/events/ActionDocument.d.ts +11 -17
  15. package/dist/commons/events/ActionInput.d.ts +4 -10
  16. package/dist/commons/events/ActionStatus.d.ts +14 -0
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -0
  18. package/dist/commons/events/AuditLog.d.ts +147 -0
  19. package/dist/commons/events/EventConfig.d.ts +3 -0
  20. package/dist/commons/events/EventDocument.d.ts +472 -4
  21. package/dist/commons/events/EventIndex.d.ts +3 -26
  22. package/dist/commons/events/EventMetadata.d.ts +1 -11
  23. package/dist/commons/events/EventStatus.d.ts +19 -0
  24. package/dist/commons/events/FieldConfig.d.ts +89 -53
  25. package/dist/commons/events/FieldTypeMapping.d.ts +27 -27
  26. package/dist/commons/events/FieldValue.d.ts +2 -2
  27. package/dist/commons/events/Flag.d.ts +42 -0
  28. package/dist/commons/events/PlainDate.d.ts +8 -0
  29. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  30. package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
  31. package/dist/commons/events/event.d.ts +12 -0
  32. package/dist/commons/events/index.d.ts +1 -0
  33. package/dist/commons/events/locationPayloads.d.ts +95 -0
  34. package/dist/commons/events/locations.d.ts +246 -13
  35. package/dist/commons/events/mocks.test.utils.d.ts +46 -2
  36. package/dist/commons/events/test.utils.d.ts +29 -11
  37. package/dist/commons/events/utils.d.ts +15 -4
  38. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  39. package/dist/commons/notification/dispatch.d.ts +10 -0
  40. package/dist/commons/notification/index.d.ts +1 -0
  41. package/dist/conditionals/index.js +328 -58
  42. package/dist/csv.d.ts +25 -0
  43. package/dist/csv.d.ts.map +1 -0
  44. package/dist/csv.js +120 -0
  45. package/dist/environment/index.d.ts +1 -0
  46. package/dist/environment/index.d.ts.map +1 -1
  47. package/dist/environment/index.js +10 -0
  48. package/dist/environment/logger.d.ts +15 -3
  49. package/dist/environment/logger.d.ts.map +1 -1
  50. package/dist/environment/manage-users.js +1 -1
  51. package/dist/environment/paths.d.ts +7 -0
  52. package/dist/environment/paths.d.ts.map +1 -0
  53. package/dist/environment/paths.js +72 -0
  54. package/dist/environment/questions.d.ts.map +1 -1
  55. package/dist/environment/questions.js +20 -14
  56. package/dist/environment/setup-environment.js +43 -28
  57. package/dist/environment/templates.d.ts +0 -1
  58. package/dist/environment/templates.d.ts.map +1 -1
  59. package/dist/environment/templates.js +5 -9
  60. package/dist/environment/update-workflows.d.ts.map +1 -1
  61. package/dist/environment/update-workflows.js +21 -5
  62. package/dist/environment/upgrade.d.ts +2 -0
  63. package/dist/environment/upgrade.d.ts.map +1 -0
  64. package/dist/environment/upgrade.js +82 -0
  65. package/dist/environment/users.js +11 -13
  66. package/dist/environment/utils.d.ts +0 -12
  67. package/dist/environment/utils.d.ts.map +1 -1
  68. package/dist/environment/utils.js +1 -28
  69. package/dist/events/index.js +7692 -7206
  70. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  71. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  72. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  73. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  74. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  75. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  76. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  77. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  78. package/dist/migrations/v2.1/add-translations.js +213 -0
  79. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  80. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  81. package/dist/migrations/v2.1/enable-telemetry.js +438 -0
  82. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  83. package/dist/migrations/v2.1/index.js +1058 -0
  84. package/dist/notification/index.js +1859 -1463
  85. package/dist/scopes/index.d.ts +327 -32
  86. package/dist/scopes/index.js +329 -58
  87. package/dist/telemetry/index.d.ts +45 -0
  88. package/dist/telemetry/index.d.ts.map +1 -0
  89. package/dist/telemetry/index.js +39 -0
  90. package/dist/templates/charts-values/dependencies/values.yaml +2 -0
  91. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
  92. package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
  93. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  94. package/dist/templates/inventory/inventory.template.yml +1 -3
  95. package/dist/translations/check.d.ts +21 -0
  96. package/dist/translations/check.d.ts.map +1 -0
  97. package/dist/translations/check.js +132 -0
  98. package/dist/verify/endpoints.d.ts +2 -0
  99. package/dist/verify/endpoints.d.ts.map +1 -0
  100. package/dist/verify/endpoints.js +345 -0
  101. package/opencrvs-toolkit-2.1.0-rc.12673aa.tgz +0 -0
  102. package/package.json +13 -7
  103. package/tsconfig.build.json +11 -0
  104. package/tsconfig.build.tsbuildinfo +1 -0
  105. package/tsconfig.json +3 -0
  106. package/dist/templates/inventory/production.example.yml +0 -77
  107. package/dist/templates/inventory/qa.example.yml +0 -48
  108. package/opencrvs-toolkit-2.1.0-rc.0cb2d8f.tgz +0 -0
  109. package/tsconfig.tsbuildinfo +0 -1
@@ -60,12 +60,21 @@ const path_1 = require("path");
60
60
  const glob = __importStar(require("glob"));
61
61
  const yaml = __importStar(require("js-yaml"));
62
62
  const logger_1 = require("./logger");
63
+ const paths_1 = require("./paths");
64
+ function isDirectory(path) {
65
+ try {
66
+ return (0, fs_1.statSync)(path).isDirectory();
67
+ }
68
+ catch (_a) {
69
+ return false;
70
+ }
71
+ }
63
72
  function extractInfrastructureNames() {
64
73
  return __awaiter(this, void 0, void 0, function* () {
65
- const files = glob.sync('infrastructure/server-setup/inventory/*.yml');
66
- const infraEnvironments = files.map((file) => (0, path_1.basename)(file, '.yml'));
74
+ const files = glob.sync((0, path_1.join)('environments', '*', paths_1.INVENTORY_FILE_NAME));
75
+ const infraEnvironments = files.map((file) => (0, path_1.basename)((0, path_1.dirname)(file)));
67
76
  if (infraEnvironments.length === 0) {
68
- console.log('⚠️ Warning: No environment directories found in infrastructure/server-setup/inventory/');
77
+ console.log(`⚠️ Warning: No environment inventory files found at environments/*/${paths_1.INVENTORY_FILE_NAME}`);
69
78
  return [];
70
79
  }
71
80
  (0, logger_1.log)('🔍 Found infrastructure configurations:', infraEnvironments.join(', '));
@@ -77,8 +86,11 @@ function extractEnvironmentNames() {
77
86
  const entries = yield (0, promises_1.readdir)('environments');
78
87
  // Filter only directories
79
88
  const environments = entries.filter((entry) => {
80
- const fullPath = (0, path_1.join)('environments', entry);
81
- return (0, fs_1.statSync)(fullPath).isDirectory();
89
+ const environmentPath = (0, path_1.join)('environments', entry);
90
+ const opencrvsServicesPath = (0, path_1.join)(environmentPath, 'opencrvs-services');
91
+ return (isDirectory(environmentPath) &&
92
+ (0, fs_1.existsSync)(opencrvsServicesPath) &&
93
+ isDirectory(opencrvsServicesPath));
82
94
  });
83
95
  if (environments.length === 0) {
84
96
  console.log('⚠️ Warning: No environment directories found in environments/');
@@ -109,6 +121,10 @@ function updateWorkflows(envList, config) {
109
121
  var _a, _b, _c, _d;
110
122
  const { workflows } = config;
111
123
  for (const workflowPath of workflows) {
124
+ if (!(0, fs_1.existsSync)(workflowPath)) {
125
+ (0, logger_1.log)(` ↷ Skipped ${workflowPath} (not found in this repository)`);
126
+ continue;
127
+ }
112
128
  try {
113
129
  const fileContents = (0, fs_1.readFileSync)(workflowPath, 'utf8');
114
130
  // Verify the file is valid YAML and has the expected structure
@@ -0,0 +1,2 @@
1
+ export declare function upgradeEnvironmentLayout(): Promise<void>;
2
+ //# sourceMappingURL=upgrade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/environment/upgrade.ts"],"names":[],"mappings":"AAkFA,wBAAsB,wBAAwB,kBAY7C"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.upgradeEnvironmentLayout = upgradeEnvironmentLayout;
26
+ const fs_1 = require("fs");
27
+ const path_1 = require("path");
28
+ const kleur_1 = __importDefault(require("kleur"));
29
+ const logger_1 = require("./logger");
30
+ const paths_1 = require("./paths");
31
+ const update_workflows_1 = require("./update-workflows");
32
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
33
+ if (!(0, fs_1.existsSync)(sourcePath)) {
34
+ return false;
35
+ }
36
+ if ((0, fs_1.existsSync)(destinationPath)) {
37
+ (0, logger_1.warn)(`⚠️ Skipped ${sourcePath}; destination already exists at ${destinationPath}`);
38
+ return false;
39
+ }
40
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(destinationPath), { recursive: true });
41
+ (0, fs_1.renameSync)(sourcePath, destinationPath);
42
+ (0, logger_1.log)(` ✓ Moved ${sourcePath} -> ${destinationPath}`);
43
+ return true;
44
+ }
45
+ function migrateInventoryFiles() {
46
+ const oldInventoryFiles = (0, paths_1.findOldInventoryFiles)();
47
+ if (oldInventoryFiles.length === 0) {
48
+ (0, logger_1.log)(`ℹ️ No old inventory files found at ${paths_1.OLD_INVENTORY_DIR}`);
49
+ return false;
50
+ }
51
+ (0, logger_1.log)(kleur_1.default.bold('\nMigrating Ansible inventory files'));
52
+ let didMoveInventory = false;
53
+ for (const oldInventoryFile of oldInventoryFiles) {
54
+ const environment = (0, paths_1.getEnvironmentNameFromOldInventoryPath)(oldInventoryFile);
55
+ didMoveInventory =
56
+ moveFileIfDestinationMissing(oldInventoryFile, (0, paths_1.getEnvironmentInventoryPath)(environment)) || didMoveInventory;
57
+ }
58
+ try {
59
+ if ((0, fs_1.existsSync)(paths_1.OLD_INVENTORY_DIR) &&
60
+ (0, fs_1.readdirSync)(paths_1.OLD_INVENTORY_DIR).length === 0) {
61
+ (0, fs_1.rmdirSync)(paths_1.OLD_INVENTORY_DIR);
62
+ (0, logger_1.log)(` ✓ Removed empty ${paths_1.OLD_INVENTORY_DIR}`);
63
+ }
64
+ }
65
+ catch (_a) {
66
+ (0, logger_1.warn)(`⚠️ Could not remove ${paths_1.OLD_INVENTORY_DIR}; please review it manually`);
67
+ }
68
+ return didMoveInventory;
69
+ }
70
+ function upgradeEnvironmentLayout() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const didMoveInventory = migrateInventoryFiles();
73
+ yield (0, update_workflows_1.updateWorkflowEnvironments)();
74
+ if (didMoveInventory) {
75
+ (0, logger_1.success)('\n✅ Environment layout upgrade completed successfully.');
76
+ }
77
+ else {
78
+ (0, logger_1.success)('\n✅ Environment layout already uses the current structure.');
79
+ }
80
+ (0, logger_1.log)('\nCommit changes into git after upgrade');
81
+ });
82
+ }
@@ -62,6 +62,7 @@ const path = __importStar(require("path"));
62
62
  const kleur_1 = __importDefault(require("kleur"));
63
63
  const manage_users_1 = require("./manage-users");
64
64
  const logger_1 = require("./logger");
65
+ const paths_1 = require("./paths");
65
66
  function select(options) {
66
67
  return __awaiter(this, void 0, void 0, function* () {
67
68
  const inquirer = yield import('@inquirer/prompts');
@@ -76,32 +77,29 @@ function select(options) {
76
77
  * * @returns {string} Inventory file
77
78
  */
78
79
  function selectInventoryFile() {
79
- return __awaiter(this, arguments, void 0, function* (dirPath = './infrastructure/server-setup/inventory/') {
80
+ return __awaiter(this, arguments, void 0, function* (dirPath = './environments') {
80
81
  // Check if directory exists
81
82
  if (!fs.existsSync(dirPath)) {
82
83
  (0, logger_1.warn)(`⚠️ No environment configuration directory found at ${dirPath}`);
83
84
  (0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
84
85
  return null;
85
86
  }
86
- // Read and filter files
87
- const files = fs
87
+ const environments = fs
88
88
  .readdirSync(dirPath)
89
- .filter((file) => {
90
- const filePath = path.join(dirPath, file);
91
- const isFile = fs.statSync(filePath).isFile();
92
- const ext = path.extname(file).slice(1).toLowerCase();
93
- return isFile && (ext === 'yml' || ext === 'yaml');
89
+ .filter((entry) => {
90
+ const filePath = path.join(dirPath, entry);
91
+ return (fs.statSync(filePath).isDirectory() &&
92
+ fs.existsSync((0, paths_1.getEnvironmentInventoryPath)(entry)));
94
93
  })
95
94
  .sort();
96
- if (files.length === 0) {
95
+ if (environments.length === 0) {
97
96
  (0, logger_1.warn)(`⚠️ No environment configuration files found at ${dirPath}`);
98
97
  (0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
99
98
  return null;
100
99
  }
101
- // Create choices - remove extension from display
102
- const choices = files.map((file) => ({
103
- name: path.basename(file, path.extname(file)),
104
- value: path.join(dirPath, file)
100
+ const choices = environments.map((environment) => ({
101
+ name: environment,
102
+ value: (0, paths_1.getEnvironmentInventoryPath)(environment)
105
103
  }));
106
104
  const selectedFile = yield select({
107
105
  message: 'Select environment (inventory file) to load users:',
@@ -1,18 +1,6 @@
1
1
  import { Secret, Variable } from './github';
2
- import { Answers } from './custom-types';
3
2
  export declare function generateLongPassword(): string;
4
3
  export declare function findExistingValue<T extends string>(name: string, type: T, scope: 'ENVIRONMENT' | 'REPOSITORY', existingValues: Array<Secret | Variable>): (T extends 'SECRET' ? Secret : T extends 'VARIABLE' ? Variable : never) | undefined;
5
- /**
6
- * Merges and stores secrets in `.env.{environment}` file.
7
- * Updates existing variables, preserves unchanged ones, adds new ones.
8
- *
9
- * @param environment - Environment name (e.g., 'production')
10
- * @param answers - Variables to update: `[{ name: 'KEY', value: 'val' }]`
11
- *
12
- * @example
13
- * storeSecrets('prod', [{ name: 'API_KEY', value: 'abc123' }]);
14
- */
15
- export declare function storeSecrets(environment: string, answers: Answers): void;
16
4
  export declare function readYamlFile(filePath: any): any;
17
5
  export declare function writeYamlFile(filePath: string, data: any): void;
18
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/environment/utils.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,wBAAgB,oBAAoB,WAMnC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,aAAa,GAAG,YAAY,EACnC,cAAc,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAMpC,CAAC,CAAC,SAAS,QAAQ,GAAG,MAAM,GAAG,CAAC,SAAS,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC,GACvE,SAAS,CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,QAoBjE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CAG/C;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAcxD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/environment/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE3C,wBAAgB,oBAAoB,WAMnC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,aAAa,GAAG,YAAY,EACnC,cAAc,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAMpC,CAAC,CAAC,SAAS,QAAQ,GAAG,MAAM,GAAG,CAAC,SAAS,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC,GACvE,SAAS,CACd;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,CAG/C;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAcxD"}
@@ -48,12 +48,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.generateLongPassword = generateLongPassword;
50
50
  exports.findExistingValue = findExistingValue;
51
- exports.storeSecrets = storeSecrets;
52
51
  exports.readYamlFile = readYamlFile;
53
52
  exports.writeYamlFile = writeYamlFile;
54
- const fs_1 = __importStar(require("fs"));
53
+ const fs_1 = __importDefault(require("fs"));
55
54
  const yaml = __importStar(require("js-yaml"));
56
- const dotenv_1 = __importDefault(require("dotenv"));
57
55
  function generateLongPassword() {
58
56
  const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
59
57
  let result = '';
@@ -64,31 +62,6 @@ function generateLongPassword() {
64
62
  function findExistingValue(name, type, scope, existingValues) {
65
63
  return existingValues.find((value) => value.name === name && value.type === type && value.scope === scope);
66
64
  }
67
- /**
68
- * Merges and stores secrets in `.env.{environment}` file.
69
- * Updates existing variables, preserves unchanged ones, adds new ones.
70
- *
71
- * @param environment - Environment name (e.g., 'production')
72
- * @param answers - Variables to update: `[{ name: 'KEY', value: 'val' }]`
73
- *
74
- * @example
75
- * storeSecrets('prod', [{ name: 'API_KEY', value: 'abc123' }]);
76
- */
77
- function storeSecrets(environment, answers) {
78
- let envConfig = {};
79
- try {
80
- envConfig = dotenv_1.default.parse((0, fs_1.readFileSync)(`${process.cwd()}/.env.${environment}`));
81
- }
82
- catch (error) {
83
- envConfig = {};
84
- }
85
- const linesFromAnswers = answers.map((update) => `${update.name}="${update.value}"`);
86
- const linesFromEnvConfig = Object.entries(envConfig)
87
- .filter(([name]) => !answers.find((update) => update.name === name))
88
- .map(([name, value]) => `${name}="${value}"`);
89
- const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
90
- (0, fs_1.writeFileSync)(`.env.${environment}`, allLines.join('\n'));
91
- }
92
65
  function readYamlFile(filePath) {
93
66
  const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
94
67
  return yaml.load(fileContent);