@opencrvs/toolkit 2.0.1 → 2.1.0-beta.2

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 (167) hide show
  1. package/README.md +18 -12
  2. package/build.sh +14 -5
  3. package/create-countryconfig/index.js +313 -129
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +5 -2
  6. package/dist/application-config/index.js +367 -278
  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 +754 -0
  10. package/dist/cli.js +4320 -4790
  11. package/dist/commons/api/router.d.ts +4120 -2982
  12. package/dist/commons/application-config/index.d.ts +6 -6
  13. package/dist/commons/conditionals/conditionals.d.ts +32 -323
  14. package/dist/commons/conditionals/validate.d.ts +16 -5
  15. package/dist/commons/events/ActionConfig.d.ts +302 -67
  16. package/dist/commons/events/ActionDocument.d.ts +159 -121
  17. package/dist/commons/events/ActionInput.d.ts +30 -10
  18. package/dist/commons/events/ActionStatus.d.ts +14 -0
  19. package/dist/commons/events/ActionType.d.ts +63 -58
  20. package/dist/commons/events/AdvancedSearchConfig.d.ts +537 -495
  21. package/dist/commons/events/AuditLog.d.ts +189 -40
  22. package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
  23. package/dist/commons/events/Conditional.d.ts +3 -3
  24. package/dist/commons/events/CountryConfigQueryInput.d.ts +603 -561
  25. package/dist/commons/events/Draft.d.ts +38 -36
  26. package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
  27. package/dist/commons/events/EventConfig.d.ts +8 -3
  28. package/dist/commons/events/EventDocument.d.ts +537 -47
  29. package/dist/commons/events/EventIndex.d.ts +61 -59
  30. package/dist/commons/events/EventMetadata.d.ts +59 -43
  31. package/dist/commons/events/EventStatus.d.ts +19 -0
  32. package/dist/commons/events/FieldConfig.d.ts +431 -380
  33. package/dist/commons/events/FieldType.d.ts +51 -51
  34. package/dist/commons/events/FieldTypeMapping.d.ts +86 -86
  35. package/dist/commons/events/FieldValue.d.ts +14 -14
  36. package/dist/commons/events/Flag.d.ts +57 -15
  37. package/dist/commons/events/PlainDate.d.ts +8 -0
  38. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  39. package/dist/commons/events/TemplateConfig.d.ts +1 -1
  40. package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
  41. package/dist/commons/events/WorkqueueConfig.d.ts +835 -790
  42. package/dist/commons/events/deduplication.d.ts +1 -1
  43. package/dist/commons/events/event.d.ts +14 -2
  44. package/dist/commons/events/field.d.ts +69 -198
  45. package/dist/commons/events/index.d.ts +1 -0
  46. package/dist/commons/events/locationPayloads.d.ts +95 -0
  47. package/dist/commons/events/locations.d.ts +248 -14
  48. package/dist/commons/events/mocks.test.utils.d.ts +48 -4
  49. package/dist/commons/events/scopes.d.ts +5 -4
  50. package/dist/commons/events/state/index.d.ts +23 -15
  51. package/dist/commons/events/state/utils.d.ts +15 -6
  52. package/dist/commons/events/test.utils.d.ts +68 -42
  53. package/dist/commons/events/utils.d.ts +143 -110
  54. package/dist/commons/notification/UserNotifications.d.ts +38 -18
  55. package/dist/commons/notification/dispatch.d.ts +10 -0
  56. package/dist/commons/notification/index.d.ts +1 -0
  57. package/dist/conditionals/index.js +340 -63
  58. package/dist/csv.d.ts +25 -0
  59. package/dist/csv.d.ts.map +1 -0
  60. package/dist/csv.js +120 -0
  61. package/dist/environment/custom-types.d.ts +33 -0
  62. package/dist/environment/custom-types.d.ts.map +1 -0
  63. package/dist/environment/custom-types.js +12 -0
  64. package/dist/environment/derived-variables.d.ts +122 -0
  65. package/dist/environment/derived-variables.d.ts.map +1 -0
  66. package/dist/environment/derived-variables.js +155 -0
  67. package/dist/environment/editor-questions.d.ts +4 -0
  68. package/dist/environment/editor-questions.d.ts.map +1 -0
  69. package/dist/environment/editor-questions.js +67 -0
  70. package/dist/environment/git.d.ts +5 -0
  71. package/dist/environment/git.d.ts.map +1 -0
  72. package/dist/environment/git.js +38 -0
  73. package/dist/environment/github.d.ts +26 -0
  74. package/dist/environment/github.d.ts.map +1 -0
  75. package/dist/environment/github.js +247 -0
  76. package/dist/environment/index.d.ts +6 -0
  77. package/dist/environment/index.d.ts.map +1 -0
  78. package/dist/environment/index.js +81 -0
  79. package/dist/environment/logger.d.ts +18 -0
  80. package/dist/environment/logger.d.ts.map +1 -0
  81. package/dist/environment/logger.js +25 -0
  82. package/dist/environment/manage-users.d.ts +11 -0
  83. package/dist/environment/manage-users.d.ts.map +1 -0
  84. package/dist/environment/manage-users.js +507 -0
  85. package/dist/environment/paths.d.ts +7 -0
  86. package/dist/environment/paths.d.ts.map +1 -0
  87. package/dist/environment/paths.js +72 -0
  88. package/dist/environment/questions-helper.d.ts +15 -0
  89. package/dist/environment/questions-helper.d.ts.map +1 -0
  90. package/dist/environment/questions-helper.js +70 -0
  91. package/dist/environment/questions.d.ts +200 -0
  92. package/dist/environment/questions.d.ts.map +1 -0
  93. package/dist/environment/questions.js +418 -0
  94. package/dist/environment/setup-environment.d.ts +2 -0
  95. package/dist/environment/setup-environment.d.ts.map +1 -0
  96. package/dist/environment/setup-environment.js +793 -0
  97. package/dist/environment/ssh-keygen.d.ts +5 -0
  98. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  99. package/dist/environment/ssh-keygen.js +21 -0
  100. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  101. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  102. package/dist/environment/swarm-to-k8s.js +183 -0
  103. package/dist/environment/templates.d.ts +26 -0
  104. package/dist/environment/templates.d.ts.map +1 -0
  105. package/dist/environment/templates.js +159 -0
  106. package/dist/environment/update-workflows.d.ts +2 -0
  107. package/dist/environment/update-workflows.d.ts.map +1 -0
  108. package/dist/environment/update-workflows.js +195 -0
  109. package/dist/environment/upgrade.d.ts +2 -0
  110. package/dist/environment/upgrade.d.ts.map +1 -0
  111. package/dist/environment/upgrade.js +82 -0
  112. package/dist/environment/users.d.ts +2 -0
  113. package/dist/environment/users.d.ts.map +1 -0
  114. package/dist/environment/users.js +120 -0
  115. package/dist/environment/utils.d.ts +6 -0
  116. package/dist/environment/utils.d.ts.map +1 -0
  117. package/dist/environment/utils.js +83 -0
  118. package/dist/events/deduplication.d.ts +1 -1
  119. package/dist/events/index.js +8107 -7388
  120. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  121. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  122. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  123. package/dist/migrations/v2.0/convert-config-files-to-ts.js +17 -7
  124. package/dist/migrations/v2.0/index.js +88 -5143
  125. package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
  126. package/dist/migrations/v2.0/remove-hearth-migrations.js +17 -7
  127. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +3 -0
  128. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +1 -0
  129. package/dist/migrations/v2.1/add-explicit-correction-flags.js +234 -0
  130. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  131. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  132. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  133. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  134. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  135. package/dist/migrations/v2.1/add-translations.js +213 -0
  136. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  137. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  138. package/dist/migrations/v2.1/enable-telemetry.js +438 -0
  139. package/dist/migrations/v2.1/index.d.ts +6 -0
  140. package/dist/migrations/v2.1/index.d.ts.map +1 -0
  141. package/dist/migrations/v2.1/index.js +1276 -0
  142. package/dist/notification/index.js +2011 -1446
  143. package/dist/scopes/index.d.ts +550 -161
  144. package/dist/scopes/index.js +341 -63
  145. package/dist/telemetry/index.d.ts +45 -0
  146. package/dist/telemetry/index.d.ts.map +1 -0
  147. package/dist/telemetry/index.js +39 -0
  148. package/dist/templates/charts-values/dependencies/values.override.yaml +4 -0
  149. package/dist/templates/charts-values/dependencies/values.yaml +82 -0
  150. package/dist/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  151. package/dist/templates/charts-values/opencrvs-services/values.yaml +78 -0
  152. package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
  153. package/dist/templates/charts-values/traefik/values.override.yaml +4 -0
  154. package/dist/templates/charts-values/traefik/values.yaml +129 -0
  155. package/dist/templates/inventory/inventory.template.yml +98 -0
  156. package/dist/translations/check.d.ts +21 -0
  157. package/dist/translations/check.d.ts.map +1 -0
  158. package/dist/translations/check.js +132 -0
  159. package/dist/verify/endpoints.d.ts.map +1 -1
  160. package/dist/verify/endpoints.js +26 -26
  161. package/opencrvs-toolkit-2.1.0-beta.2.tgz +0 -0
  162. package/package.json +25 -6
  163. package/tsconfig.build.json +11 -0
  164. package/tsconfig.build.tsbuildinfo +1 -0
  165. package/tsconfig.json +3 -0
  166. package/opencrvs-toolkit-2.0.1.tgz +0 -0
  167. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,507 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
46
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
+ return new (P || (P = Promise))(function (resolve, reject) {
48
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
+ };
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.manageUsers = manageUsers;
56
+ const os = __importStar(require("os"));
57
+ /* eslint-disable no-console */
58
+ const fs = __importStar(require("fs"));
59
+ const path = __importStar(require("path"));
60
+ function inquirerPrompt(name, options) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const inquirer = yield import('@inquirer/prompts');
63
+ return inquirer[name](options);
64
+ });
65
+ }
66
+ const input = (options) => inquirerPrompt('input', options);
67
+ const select = (options) => inquirerPrompt('select', options);
68
+ const confirm = (options) => inquirerPrompt('confirm', options);
69
+ const editor = (options) => inquirerPrompt('editor', options);
70
+ const checkbox = (options) => inquirerPrompt('checkbox', options);
71
+ const logger_1 = require("./logger");
72
+ const utils_1 = require("./utils");
73
+ const templates_1 = require("./templates");
74
+ /**
75
+ * Updates users in Ansible inventory file
76
+ *
77
+ * @param {string} filePath - Path to the inventory file
78
+ * @param {User[]} users - Users array
79
+ */
80
+ function updateInventoryFile(filePath, users) {
81
+ var _a, _b;
82
+ const data = (0, utils_1.readYamlFile)(filePath);
83
+ if (!((_b = (_a = data === null || data === void 0 ? void 0 : data.all) === null || _a === void 0 ? void 0 : _a.vars) === null || _b === void 0 ? void 0 : _b.users)) {
84
+ throw Error(`'users' section not found within inventory file: ${filePath}`);
85
+ }
86
+ data.all.vars.users = users;
87
+ (0, utils_1.writeYamlFile)(filePath, data);
88
+ }
89
+ /**
90
+ * Parses the Ansible inventory file and extracts existing users
91
+ *
92
+ * @param {string} filePath - Path to the inventory file
93
+ * @returns {User[]} Array of existing users
94
+ */
95
+ function parseInventoryFile(filePath) {
96
+ try {
97
+ const data = (0, utils_1.readYamlFile)(filePath);
98
+ return (0, templates_1.extractAndModifyUsers)(data);
99
+ }
100
+ catch (_a) {
101
+ return [];
102
+ }
103
+ }
104
+ /**
105
+ * Gets the current system username
106
+ *
107
+ * @returns {string} Current OS username
108
+ */
109
+ function getCurrentUsername() {
110
+ return os.userInfo().username;
111
+ }
112
+ /**
113
+ * Reads SSH public keys from the current user's .ssh directory
114
+ *
115
+ * @returns {string[]} Array of SSH public keys found
116
+ */
117
+ function getCurrentUserSSHKeys() {
118
+ const homeDir = os.homedir();
119
+ const sshDir = path.join(homeDir, '.ssh');
120
+ const keys = [];
121
+ // Common public key filenames
122
+ const keyFiles = [
123
+ 'id_rsa.pub',
124
+ 'id_ecdsa.pub',
125
+ 'id_ed25519.pub',
126
+ 'id_dsa.pub'
127
+ ];
128
+ for (const keyFile of keyFiles) {
129
+ const keyPath = path.join(sshDir, keyFile);
130
+ try {
131
+ if (fs.existsSync(keyPath)) {
132
+ const keyContent = fs.readFileSync(keyPath, 'utf8').trim();
133
+ if (keyContent) {
134
+ keys.push(keyContent);
135
+ }
136
+ }
137
+ }
138
+ catch (error) {
139
+ // Silently skip if can't read the file
140
+ continue;
141
+ }
142
+ }
143
+ return keys;
144
+ }
145
+ function selectRole() {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return yield select({
148
+ message: 'Select user role:',
149
+ choices: [
150
+ { name: 'Admin (full access to OS and Kubernetes)', value: 'admin' },
151
+ { name: 'Operator (read-only OS, full Kubernetes)', value: 'operator' }
152
+ ]
153
+ });
154
+ });
155
+ }
156
+ function selectState() {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ return yield select({
159
+ message: 'Select user state:',
160
+ choices: [
161
+ { name: 'Present (user is allowed to login)', value: 'present' },
162
+ { name: 'Absent (user account is disabled)', value: 'absent' }
163
+ ]
164
+ });
165
+ });
166
+ }
167
+ /**
168
+ * Asks if user wants to add current system user as the first user
169
+ *
170
+ * @returns {Promise<User | null>} User object if accepted, null if declined
171
+ */
172
+ function askToAddCurrentUser(existingUsers) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const currentUsername = getCurrentUsername();
175
+ const currentKeys = getCurrentUserSSHKeys();
176
+ // Check if user already exists
177
+ if (existingUsers.find((u) => u.name === currentUsername)) {
178
+ (0, logger_1.info)(`ℹ️ User "${currentUsername}" already exists in inventory.`);
179
+ return null;
180
+ }
181
+ if (currentKeys.length === 0) {
182
+ // No SSH keys found for current user
183
+ return null;
184
+ }
185
+ const addCurrentUser = yield confirm({
186
+ message: `Add current user "${currentUsername}" with ${currentKeys.length} SSH key(s)?`,
187
+ default: true
188
+ });
189
+ if (!addCurrentUser) {
190
+ return null;
191
+ }
192
+ // Ask for role
193
+ const role = yield selectRole();
194
+ return {
195
+ name: currentUsername,
196
+ ssh_keys: currentKeys,
197
+ state: 'present',
198
+ role: role
199
+ };
200
+ });
201
+ }
202
+ /**
203
+ * Add a new user
204
+ */
205
+ function addNewUser(existingUsers) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ const name = yield input({
208
+ message: 'Enter username:',
209
+ validate: (value) => {
210
+ if (!value.trim()) {
211
+ return 'Username required';
212
+ }
213
+ if (existingUsers.find((u) => u.name === value.trim())) {
214
+ return `User "${value}" already exists`;
215
+ }
216
+ if (!/^[a-z_][a-z0-9_-]*[$]?$/.test(value.trim())) {
217
+ return 'Invalid username format (use lowercase, numbers, underscore, hyphen)';
218
+ }
219
+ return true;
220
+ }
221
+ });
222
+ const keysInput = yield editor({
223
+ message: 'Paste SSH public key(s) (one per line):',
224
+ default: ''
225
+ });
226
+ const ssh_keys = keysInput
227
+ .split('\n')
228
+ .map((key) => key.trim())
229
+ .filter((key) => key && !key.startsWith('#'));
230
+ if (ssh_keys.length === 0) {
231
+ (0, logger_1.warn)('⚠️ Warning: No SSH keys provided. User will not be able to login remotely.');
232
+ }
233
+ const role = yield selectRole();
234
+ // New users always active
235
+ const state = 'present';
236
+ return {
237
+ name: name.trim(),
238
+ ssh_keys,
239
+ state,
240
+ role
241
+ };
242
+ });
243
+ }
244
+ /**
245
+ * Display user summary
246
+ */
247
+ function displayUserSummary(users) {
248
+ if (users.length === 0) {
249
+ console.log('\n📋 No users configured.\n');
250
+ return;
251
+ }
252
+ console.log('\n' + '='.repeat(70));
253
+ console.log(`📋 User Configuration Summary - Total users: ${users.length}`);
254
+ console.log('='.repeat(70));
255
+ users.forEach((user, index) => {
256
+ const stateIcon = user.state === 'present' ? '✅' : '❌';
257
+ const roleIcon = user.role === 'admin' ? '👑' : '👤';
258
+ console.log(`${index + 1}. ${stateIcon} ${roleIcon} ${user.name.padEnd(20)} ` +
259
+ `Role: ${user.role.padEnd(10)} State: ${user.state.padEnd(10)} ` +
260
+ `SSH Keys: ${user.ssh_keys.length}`);
261
+ });
262
+ console.log('='.repeat(70) + '\n');
263
+ }
264
+ /**
265
+ * Edit an existing user with screen clearing for better UX
266
+ */
267
+ function editUser(user) {
268
+ return __awaiter(this, void 0, void 0, function* () {
269
+ const updatedUser = Object.assign({}, user);
270
+ let continueEditing = true;
271
+ // Function to clear screen and move cursor to top
272
+ const clearScreen = () => {
273
+ process.stdout.write('\x1Bc'); // Clear entire screen
274
+ // Alternative: process.stdout.write('\x1B[2J\x1B[0f'); // Clear screen + move cursor to top
275
+ };
276
+ // Function to display current user state
277
+ const displayUserState = () => {
278
+ clearScreen();
279
+ console.log('─'.repeat(70));
280
+ console.log(`📝 Editing user: ${updatedUser.name}`);
281
+ console.log('─'.repeat(70));
282
+ console.log(`Current Role: ${updatedUser.role === 'admin' ? '👑 admin' : '👤 operator'}`);
283
+ console.log(`Current State: ${updatedUser.state === 'present' ? '✅ present' : '❌ absent'}`);
284
+ console.log(`Current SSH Keys: ${updatedUser.ssh_keys.length} key(s)`);
285
+ if (updatedUser.ssh_keys.length > 0) {
286
+ updatedUser.ssh_keys.forEach((key, idx) => {
287
+ const keyPreview = key.length > 50 ? key.substring(0, 47) + '...' : key;
288
+ console.log(` ${idx + 1}. ${keyPreview}`);
289
+ });
290
+ }
291
+ console.log('─'.repeat(70));
292
+ console.log(''); // Empty line for spacing
293
+ };
294
+ while (continueEditing) {
295
+ displayUserState();
296
+ const action = yield select({
297
+ message: 'What would you like to modify?',
298
+ choices: [
299
+ {
300
+ name: `Change role (current: ${updatedUser.role})`,
301
+ value: 'role'
302
+ },
303
+ {
304
+ name: `Change state (current: ${updatedUser.state})`,
305
+ value: 'state'
306
+ },
307
+ {
308
+ name: `Update SSH keys (current: ${updatedUser.ssh_keys.length} key(s))`,
309
+ value: 'keys'
310
+ },
311
+ {
312
+ name: '💾 Save changes and return',
313
+ value: 'save'
314
+ },
315
+ {
316
+ name: '🚫 Cancel and discard changes',
317
+ value: 'cancel'
318
+ }
319
+ ]
320
+ });
321
+ switch (action) {
322
+ case 'role':
323
+ const newRole = yield selectRole();
324
+ if (newRole !== updatedUser.role) {
325
+ updatedUser.role = newRole;
326
+ }
327
+ break;
328
+ case 'state':
329
+ const newState = yield selectState();
330
+ if (newState !== updatedUser.state) {
331
+ updatedUser.state = newState;
332
+ }
333
+ break;
334
+ case 'keys':
335
+ const keysInput = yield editor({
336
+ message: 'Update SSH public key(s) (one per line):',
337
+ default: updatedUser.ssh_keys.join('\n')
338
+ });
339
+ const newKeys = keysInput
340
+ .split('\n')
341
+ .map((key) => key.trim())
342
+ .filter((key) => key && !key.startsWith('#'));
343
+ if (newKeys.length === 0) {
344
+ clearScreen();
345
+ displayUserState();
346
+ const confirmRemoveKeys = yield confirm({
347
+ message: '⚠️ Warning: All SSH keys will be removed. Continue with no SSH keys?',
348
+ default: false
349
+ });
350
+ if (confirmRemoveKeys) {
351
+ updatedUser.ssh_keys = [];
352
+ }
353
+ }
354
+ else {
355
+ updatedUser.ssh_keys = newKeys;
356
+ }
357
+ break;
358
+ case 'save':
359
+ const hasChanges = updatedUser.role !== user.role ||
360
+ updatedUser.state !== user.state ||
361
+ JSON.stringify(updatedUser.ssh_keys) !== JSON.stringify(user.ssh_keys);
362
+ clearScreen();
363
+ if (hasChanges) {
364
+ console.log('\n✅ Changes saved for user:', updatedUser.name, '\n');
365
+ }
366
+ else {
367
+ console.log('\nℹ️ No changes made\n');
368
+ }
369
+ continueEditing = false;
370
+ break;
371
+ case 'cancel':
372
+ clearScreen();
373
+ const confirmCancel = yield confirm({
374
+ message: 'Discard all changes?',
375
+ default: false
376
+ });
377
+ if (confirmCancel) {
378
+ console.log('\n🚫 Changes discarded\n');
379
+ return user; // Return original user
380
+ }
381
+ break;
382
+ }
383
+ }
384
+ return updatedUser;
385
+ });
386
+ }
387
+ /**
388
+ * Main function to manage users
389
+ */
390
+ function manageUsers(inventoryPath) {
391
+ return __awaiter(this, void 0, void 0, function* () {
392
+ let users = fs.existsSync(inventoryPath)
393
+ ? parseInventoryFile(inventoryPath)
394
+ : [];
395
+ if (users.length > 0) {
396
+ displayUserSummary(users);
397
+ }
398
+ let continueManaging = true;
399
+ while (continueManaging) {
400
+ const action = yield select({
401
+ message: 'What would you like to do?',
402
+ choices: [
403
+ { name: '➕ Add new user', value: 'add' },
404
+ { name: '✏️ Edit existing user', value: 'edit' },
405
+ { name: '🗑️ Remove user', value: 'remove' },
406
+ { name: '👤 Add current system user', value: 'add-current' },
407
+ { name: '📋 View all users', value: 'view' },
408
+ { name: '💾 Save and exit', value: 'save' },
409
+ { name: '🚪 Exit without saving', value: 'exit' }
410
+ ]
411
+ });
412
+ switch (action) {
413
+ case 'add':
414
+ const newUser = yield addNewUser(users);
415
+ if (newUser) {
416
+ users.push(newUser);
417
+ console.log(`✅ User "${newUser.name}" added.\n`);
418
+ }
419
+ break;
420
+ case 'add-current':
421
+ const currentUser = yield askToAddCurrentUser(users);
422
+ if (currentUser) {
423
+ users.push(currentUser);
424
+ console.log(`✅ Current user "${currentUser.name}" added.\n`);
425
+ }
426
+ break;
427
+ case 'edit':
428
+ if (users.length === 0) {
429
+ console.log('⚠️ No users to edit.\n');
430
+ break;
431
+ }
432
+ const userToEdit = yield select({
433
+ message: 'Select user to edit:',
434
+ choices: users.map((u) => ({
435
+ name: `${u.name} (${u.role}, ${u.state})`,
436
+ value: u.name
437
+ }))
438
+ });
439
+ const userIndex = users.findIndex((u) => u.name === userToEdit);
440
+ if (userIndex !== -1) {
441
+ users[userIndex] = yield editUser(users[userIndex]);
442
+ console.log(`✅ User "${userToEdit}" updated.\n`);
443
+ }
444
+ break;
445
+ case 'remove':
446
+ if (users.length === 0) {
447
+ console.log('⚠️ No users to remove.\n');
448
+ break;
449
+ }
450
+ const usersToRemove = yield checkbox({
451
+ message: 'Select user(s) to remove:',
452
+ choices: users.map((u) => ({
453
+ name: `${u.name} (${u.role}, ${u.state})`,
454
+ value: u.name
455
+ }))
456
+ });
457
+ if (usersToRemove.length > 0) {
458
+ const confirmRemove = yield confirm({
459
+ message: `Remove ${usersToRemove.length} user(s)?`,
460
+ default: false
461
+ });
462
+ if (confirmRemove) {
463
+ users = users.filter((u) => !usersToRemove.includes(u.name));
464
+ console.log(`✅ Removed ${usersToRemove.length} user(s).\n`);
465
+ }
466
+ }
467
+ break;
468
+ case 'view':
469
+ displayUserSummary(users);
470
+ break;
471
+ case 'save':
472
+ if (users.length === 0) {
473
+ (0, logger_1.info)('\n📋 No users configured.\n');
474
+ continueManaging = false;
475
+ break;
476
+ }
477
+ displayUserSummary(users);
478
+ const confirmSave = yield confirm({
479
+ message: 'Save changes end exit?',
480
+ default: true
481
+ });
482
+ if (confirmSave && fs.existsSync(inventoryPath)) {
483
+ updateInventoryFile(inventoryPath, users);
484
+ console.log(`\n✅ Changes saved to ${inventoryPath}\n`);
485
+ }
486
+ continueManaging = false;
487
+ break;
488
+ case 'exit':
489
+ if (users.length === 0) {
490
+ (0, logger_1.info)('\n📋 No users configured.\n');
491
+ continueManaging = false;
492
+ break;
493
+ }
494
+ const confirmExit = yield confirm({
495
+ message: 'Exit without saving changes?',
496
+ default: false
497
+ });
498
+ if (confirmExit) {
499
+ console.log('👋 Exited without saving.\n');
500
+ continueManaging = false;
501
+ }
502
+ break;
503
+ }
504
+ }
505
+ return users;
506
+ });
507
+ }
@@ -0,0 +1,7 @@
1
+ export declare const OLD_INVENTORY_DIR: string;
2
+ export declare const INVENTORY_FILE_NAME = "inventory.yml";
3
+ export declare function getEnvironmentInventoryPath(environment: string): string;
4
+ export declare function findOldInventoryFiles(): string[];
5
+ export declare function getEnvironmentNameFromOldInventoryPath(filePath: string): string;
6
+ export declare function assertNoOldInventoryLayout(): void;
7
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/environment/paths.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,iBAAiB,QAI7B,CAAA;AAED,eAAO,MAAM,mBAAmB,kBAAkB,CAAA;AAElD,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,UAE9D;AAED,wBAAgB,qBAAqB,aAEpC;AAED,wBAAgB,sCAAsC,CAAC,QAAQ,EAAE,MAAM,UAEtE;AAED,wBAAgB,0BAA0B,SAWzC"}
@@ -0,0 +1,72 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.INVENTORY_FILE_NAME = exports.OLD_INVENTORY_DIR = void 0;
47
+ exports.getEnvironmentInventoryPath = getEnvironmentInventoryPath;
48
+ exports.findOldInventoryFiles = findOldInventoryFiles;
49
+ exports.getEnvironmentNameFromOldInventoryPath = getEnvironmentNameFromOldInventoryPath;
50
+ exports.assertNoOldInventoryLayout = assertNoOldInventoryLayout;
51
+ const path_1 = require("path");
52
+ const glob = __importStar(require("glob"));
53
+ exports.OLD_INVENTORY_DIR = (0, path_1.join)('infrastructure', 'server-setup', 'inventory');
54
+ exports.INVENTORY_FILE_NAME = 'inventory.yml';
55
+ function getEnvironmentInventoryPath(environment) {
56
+ return (0, path_1.join)('environments', environment, exports.INVENTORY_FILE_NAME);
57
+ }
58
+ function findOldInventoryFiles() {
59
+ return glob.sync((0, path_1.join)(exports.OLD_INVENTORY_DIR, '*.yml')).sort();
60
+ }
61
+ function getEnvironmentNameFromOldInventoryPath(filePath) {
62
+ return (0, path_1.basename)(filePath, '.yml');
63
+ }
64
+ function assertNoOldInventoryLayout() {
65
+ if (findOldInventoryFiles().length === 0) {
66
+ return;
67
+ }
68
+ throw new Error([
69
+ `Old inventory layout detected at ${exports.OLD_INVENTORY_DIR}.`,
70
+ 'Please run `yarn environment:upgrade` before running `yarn environment:init`.'
71
+ ].join(' '));
72
+ }
@@ -0,0 +1,15 @@
1
+ import { Choice } from 'prompts';
2
+ export declare function getIndexFromChoices(choices: Choice[], value: string): number;
3
+ type SelectWithCustomOptions = {
4
+ message: string;
5
+ choices: readonly {
6
+ name: string;
7
+ value: string;
8
+ }[];
9
+ customLabel?: string;
10
+ customInputMessage?: string;
11
+ initial?: string;
12
+ };
13
+ export declare function selectWithCustom(config: SelectWithCustomOptions): Promise<string>;
14
+ export {};
15
+ //# sourceMappingURL=questions-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions-helper.d.ts","sourceRoot":"","sources":["../../src/environment/questions-helper.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAYhC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,UASnE;AAED,KAAK,uBAAuB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACnD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAkCjB"}
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getIndexFromChoices = getIndexFromChoices;
23
+ exports.selectWithCustom = selectWithCustom;
24
+ function input(options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const inquirer = yield import('@inquirer/prompts');
27
+ return inquirer.input(options);
28
+ });
29
+ }
30
+ function select(options) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const inquirer = yield import('@inquirer/prompts');
33
+ return inquirer.select(options);
34
+ });
35
+ }
36
+ function getIndexFromChoices(choices, value) {
37
+ let idx = 0;
38
+ for (const choice of choices) {
39
+ if (choice.value === value) {
40
+ return idx;
41
+ }
42
+ idx++;
43
+ }
44
+ return 0;
45
+ }
46
+ function selectWithCustom(config) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const { message, choices, initial = undefined, customLabel = 'Other...', customInputMessage = 'Enter custom value:' } = config;
49
+ const CUSTOM = '__custom__';
50
+ const selected = yield select({
51
+ message,
52
+ choices: [
53
+ ...choices,
54
+ {
55
+ value: CUSTOM,
56
+ name: customLabel
57
+ }
58
+ ],
59
+ default: initial
60
+ });
61
+ if (selected === CUSTOM) {
62
+ const customValue = yield input({
63
+ message: customInputMessage,
64
+ validate: (value) => value.trim().length > 0 ? true : 'Value cannot be empty'
65
+ });
66
+ return customValue;
67
+ }
68
+ return selected;
69
+ });
70
+ }