@opencrvs/toolkit 2.0.0-rc.ede78c9 → 2.0.0-rc.ee0e51b

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 (124) hide show
  1. package/README.md +14 -0
  2. package/build.sh +1 -0
  3. package/create-countryconfig/index.js +103 -0
  4. package/create-countryconfig/package.json +21 -0
  5. package/dist/application-config/index.js +276 -122
  6. package/dist/cli.js +3654 -208
  7. package/dist/commons/api/router.d.ts +3377 -237
  8. package/dist/commons/application-config/index.d.ts +1 -0
  9. package/dist/commons/conditionals/conditionals.d.ts +357 -7
  10. package/dist/commons/conditionals/validate.d.ts +52 -2
  11. package/dist/commons/events/ActionConfig.d.ts +28 -2
  12. package/dist/commons/events/ActionDocument.d.ts +6 -0
  13. package/dist/commons/events/ActionInput.d.ts +114 -0
  14. package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
  15. package/dist/commons/events/Draft.d.ts +4 -2
  16. package/dist/commons/events/EventDocument.d.ts +3 -0
  17. package/dist/commons/events/EventIndex.d.ts +0 -3
  18. package/dist/commons/events/EventMetadata.d.ts +0 -7
  19. package/dist/commons/events/FieldConfig.d.ts +383 -50
  20. package/dist/commons/events/FieldType.d.ts +1 -0
  21. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  22. package/dist/commons/events/FieldValue.d.ts +6 -0
  23. package/dist/commons/events/WorkqueueConfig.d.ts +150 -150
  24. package/dist/commons/events/field.d.ts +53 -1
  25. package/dist/commons/events/index.d.ts +2 -0
  26. package/dist/commons/events/locations.d.ts +21 -0
  27. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  28. package/dist/commons/events/scopes.d.ts +24 -1
  29. package/dist/commons/events/state/flags.d.ts +16 -0
  30. package/dist/commons/events/state/index.d.ts +0 -4
  31. package/dist/commons/events/state/utils.d.ts +12 -289
  32. package/dist/commons/events/utils.d.ts +13 -2
  33. package/dist/conditionals/index.js +60 -5
  34. package/dist/environment/custom-types.d.ts +33 -0
  35. package/dist/environment/custom-types.d.ts.map +1 -0
  36. package/dist/environment/custom-types.js +12 -0
  37. package/dist/environment/derived-variables.d.ts +134 -0
  38. package/dist/environment/derived-variables.d.ts.map +1 -0
  39. package/dist/environment/derived-variables.js +169 -0
  40. package/dist/environment/editor-questions.d.ts +4 -0
  41. package/dist/environment/editor-questions.d.ts.map +1 -0
  42. package/dist/environment/editor-questions.js +65 -0
  43. package/dist/environment/git.d.ts +5 -0
  44. package/dist/environment/git.d.ts.map +1 -0
  45. package/dist/environment/git.js +38 -0
  46. package/dist/environment/github.d.ts +26 -0
  47. package/dist/environment/github.d.ts.map +1 -0
  48. package/dist/environment/github.js +244 -0
  49. package/dist/environment/index.d.ts +5 -0
  50. package/dist/environment/index.d.ts.map +1 -0
  51. package/dist/environment/index.js +70 -0
  52. package/dist/environment/logger.d.ts +15 -0
  53. package/dist/environment/logger.d.ts.map +1 -0
  54. package/dist/environment/logger.js +25 -0
  55. package/dist/environment/manage-users.d.ts +11 -0
  56. package/dist/environment/manage-users.d.ts.map +1 -0
  57. package/dist/environment/manage-users.js +494 -0
  58. package/dist/environment/questions-helper.d.ts +15 -0
  59. package/dist/environment/questions-helper.d.ts.map +1 -0
  60. package/dist/environment/questions-helper.js +70 -0
  61. package/dist/environment/questions.d.ts +199 -0
  62. package/dist/environment/questions.d.ts.map +1 -0
  63. package/dist/environment/questions.js +412 -0
  64. package/dist/environment/setup-environment.d.ts +2 -0
  65. package/dist/environment/setup-environment.d.ts.map +1 -0
  66. package/dist/environment/setup-environment.js +773 -0
  67. package/dist/environment/ssh-keygen.d.ts +5 -0
  68. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  69. package/dist/environment/ssh-keygen.js +18 -0
  70. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  71. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  72. package/dist/environment/swarm-to-k8s.js +172 -0
  73. package/dist/environment/templates/charts-values/dependencies/values.override.yaml +4 -0
  74. package/dist/environment/templates/charts-values/dependencies/values.yaml +82 -0
  75. package/dist/environment/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  76. package/dist/environment/templates/charts-values/opencrvs-services/values.yaml +79 -0
  77. package/dist/environment/templates/charts-values/traefik/values.override.yaml +4 -0
  78. package/dist/environment/templates/charts-values/traefik/values.yaml +116 -0
  79. package/dist/environment/templates/inventory/inventory.template.yml +100 -0
  80. package/dist/environment/templates/inventory/production.example.yml +77 -0
  81. package/dist/environment/templates/inventory/qa.example.yml +48 -0
  82. package/dist/environment/templates.d.ts +27 -0
  83. package/dist/environment/templates.d.ts.map +1 -0
  84. package/dist/environment/templates.js +159 -0
  85. package/dist/environment/update-workflows.d.ts +2 -0
  86. package/dist/environment/update-workflows.d.ts.map +1 -0
  87. package/dist/environment/update-workflows.js +168 -0
  88. package/dist/environment/users.d.ts +2 -0
  89. package/dist/environment/users.d.ts.map +1 -0
  90. package/dist/environment/users.js +102 -0
  91. package/dist/environment/utils.d.ts +18 -0
  92. package/dist/environment/utils.d.ts.map +1 -0
  93. package/dist/environment/utils.js +100 -0
  94. package/dist/events/index.js +1135 -287
  95. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  96. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +60 -35
  97. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  98. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  99. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
  100. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
  101. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
  102. package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
  103. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
  104. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
  106. package/dist/migrations/v2.0/index.d.ts +5 -3
  107. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  108. package/dist/migrations/v2.0/index.js +514 -172
  109. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  110. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
  111. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
  112. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
  113. package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
  114. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  115. package/dist/migrations/v2.0/migrate-scopes.js +54 -30
  116. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  117. package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
  118. package/dist/notification/index.js +904 -158
  119. package/dist/scopes/index.d.ts +10 -7
  120. package/dist/scopes/index.js +17 -7
  121. package/opencrvs-toolkit-2.0.0-rc.ee0e51b.tgz +0 -0
  122. package/package.json +20 -2
  123. package/tsconfig.tsbuildinfo +1 -1
  124. package/opencrvs-toolkit-2.0.0-rc.ede78c9.tgz +0 -0
@@ -0,0 +1,48 @@
1
+ all:
2
+ vars:
3
+ # Domain/IP address for remote access to your cluster API
4
+ # Domain/IP address will be added as main endpoint to your ~/.kube/config
5
+ # - If you are behind VPN, use private IP address
6
+ # - If your server is exposed (not recommeded), use public IP address
7
+ # - If you would like to run kubectl commands from the remote server, leave this field empty
8
+
9
+ # IMPORTANT: If master VM has multiple ethernet interfaces, put private IP address at kube_api_address
10
+ # kube_api_host: 10.10.10.10
11
+ kube_api_host: []
12
+
13
+ # Default ansible provision user, keep as is
14
+ ansible_user: provision
15
+
16
+ # single_node:
17
+ # For development/qa/testing/staging keep true
18
+ # For production keep false
19
+ # Defaults production configuration:
20
+ # - master node
21
+ # - 2 worker nodes
22
+ single_node: true
23
+
24
+ # users: Add as many users as you wish
25
+ # Configuration example
26
+ # - name: <login>
27
+ # ssh_keys:
28
+ # - <public ssh key 1>
29
+ # - <public ssh key 2>
30
+ # state: present
31
+ # role: admin
32
+ # Allowed roles:
33
+ # - operator: grant read only access to OS and full access to kubernetes cluster
34
+ # - admin: grant full access to OS and kubernetes cluster
35
+ # Allowed states:
36
+ # - present: user is allowed to login
37
+ # - absent: user account is disabled
38
+ users: []
39
+
40
+ children:
41
+ master:
42
+ hosts:
43
+ # Replace master with value returned by command: hostname
44
+ master:
45
+ # Keep values (ansible_host, ansible_connection) as is
46
+ # Ansible is executed on master node
47
+ ansible_host: localhost
48
+ ansible_connection: local
@@ -0,0 +1,27 @@
1
+ export declare function getUsers(data: any): any;
2
+ export declare function extractAndModifyUsers(data: any): any;
3
+ export declare function dockerManagerFirst(data: any): string;
4
+ export declare function extractBackupNode(data: any): string;
5
+ export declare function extractWorkerNodes(data: any): string[];
6
+ /**
7
+ * Copy charts-values directory into environments/<env>
8
+ * @param env Environment name
9
+ * Usage: copyChartsValues('dev')
10
+ */
11
+ /**
12
+ * Recursively copy a directory and replace placeholders in text files.
13
+ */
14
+ export declare function copyChartsValues(env: string, values: Record<string, string | boolean>): void;
15
+ /**
16
+ * Generate Ansible inventory file from template
17
+ * @param env Environment name
18
+ * @param number_of_servers Number of servers (1 for single-node, >1 for multi-node)
19
+ * @param values Key-value pairs to replace in the template
20
+ * Usage: generateInventory('dev', 1, {
21
+ * HOST: process.env.APP_HOST || "localhost",
22
+ * USER: process.env.SSH_USER || "ubuntu",
23
+ * PORT: process.env.SSH_PORT || "22"
24
+ * });
25
+ */
26
+ export declare function generateInventory(env: string, values: Record<string, any>): void;
27
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AAsBA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAKvC;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAwCrF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAczE"}
@@ -0,0 +1,159 @@
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 __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.getUsers = getUsers;
28
+ exports.extractAndModifyUsers = extractAndModifyUsers;
29
+ exports.dockerManagerFirst = dockerManagerFirst;
30
+ exports.extractBackupNode = extractBackupNode;
31
+ exports.extractWorkerNodes = extractWorkerNodes;
32
+ exports.copyChartsValues = copyChartsValues;
33
+ exports.generateInventory = generateInventory;
34
+ const fs_1 = __importDefault(require("fs"));
35
+ const path_1 = __importDefault(require("path"));
36
+ const logger_1 = require("./logger");
37
+ const handlebars_1 = __importDefault(require("handlebars"));
38
+ // Register a helper to increment numbers
39
+ handlebars_1.default.registerHelper('data_label_idx', function (value) {
40
+ return parseInt(value) + 2;
41
+ });
42
+ function getUsers(data) {
43
+ var _a, _b;
44
+ 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)) {
45
+ return { users: [] };
46
+ }
47
+ return data.all.vars.users;
48
+ }
49
+ // START: TEMPORAL SECTION FOR TRANSITION FROM DOCKER SWARM TO K8s
50
+ // Extract users from the old inventory
51
+ // Docker swarm format to new
52
+ function extractAndModifyUsers(data) {
53
+ var _a, _b;
54
+ 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)) {
55
+ return { users: [] };
56
+ }
57
+ const users = data.all.vars.users.map((user) => {
58
+ const { sudoer } = user, rest = __rest(user, ["sudoer"]);
59
+ return Object.assign(Object.assign({}, rest), { role: sudoer ? "admin" : "operator" });
60
+ });
61
+ return users;
62
+ }
63
+ function dockerManagerFirst(data) {
64
+ var _a;
65
+ if (!((_a = data === null || data === void 0 ? void 0 : data['docker-manager-first']) === null || _a === void 0 ? void 0 : _a.hosts)) {
66
+ throw new Error('Invalid YAML structure: missing docker-manager-first.hosts');
67
+ }
68
+ const hosts = data['docker-manager-first'].hosts;
69
+ const dockerManagerFirst = Object.values(hosts)
70
+ .filter((host) => host.ansible_host)
71
+ .map((host) => host.ansible_host);
72
+ return dockerManagerFirst.length === 1 ? dockerManagerFirst[0] : '';
73
+ }
74
+ function extractBackupNode(data) {
75
+ var _a;
76
+ if (!((_a = data === null || data === void 0 ? void 0 : data['backups']) === null || _a === void 0 ? void 0 : _a.hosts)) {
77
+ return '';
78
+ }
79
+ const hosts = data['backups'].hosts;
80
+ const backupHostEntry = Object.values(hosts)
81
+ .filter((host) => host.ansible_host)
82
+ .map((host) => host.ansible_host);
83
+ return backupHostEntry.length === 1 ? backupHostEntry[0] : '';
84
+ }
85
+ function extractWorkerNodes(data) {
86
+ var _a;
87
+ if (!((_a = data === null || data === void 0 ? void 0 : data['docker-workers']) === null || _a === void 0 ? void 0 : _a.hosts)) {
88
+ return [];
89
+ }
90
+ const hosts = data['docker-workers'].hosts;
91
+ const worker_hosts = Object.values(hosts)
92
+ .filter((host) => host.ansible_host)
93
+ .map((host) => host.ansible_host);
94
+ return worker_hosts;
95
+ }
96
+ // END: TEMPORAL SECTION FOR TRANSITION FROM DOCKER SWARM TO K8s
97
+ /**
98
+ * Copy charts-values directory into environments/<env>
99
+ * @param env Environment name
100
+ * Usage: copyChartsValues('dev')
101
+ */
102
+ /**
103
+ * Recursively copy a directory and replace placeholders in text files.
104
+ */
105
+ function copyChartsValues(env, values) {
106
+ const srcDir = path_1.default.resolve(__dirname, "templates", "charts-values");
107
+ const destDir = path_1.default.resolve(process.cwd(), "environments", env);
108
+ fs_1.default.mkdirSync(destDir, { recursive: true });
109
+ values['lets_encrypt'] = values['traefik_mode'] === "lets_encrypt";
110
+ values['static_ssl'] = values['traefik_mode'] === "static_ssl";
111
+ function copyRecursive(src, dest) {
112
+ const stat = fs_1.default.statSync(src);
113
+ if (stat.isDirectory()) {
114
+ fs_1.default.mkdirSync(dest, { recursive: true });
115
+ for (const item of fs_1.default.readdirSync(src)) {
116
+ copyRecursive(path_1.default.join(src, item), path_1.default.join(dest, item));
117
+ }
118
+ }
119
+ else {
120
+ const content = fs_1.default.readFileSync(src, "utf8");
121
+ const template = handlebars_1.default.compile(content);
122
+ const updated = template(values);
123
+ const isOverridesFile = dest.endsWith("override.yaml");
124
+ // Skip overwrite for existing overrides.yaml
125
+ if (isOverridesFile && fs_1.default.existsSync(dest)) {
126
+ (0, logger_1.log)(` ↷ Skipped existing overrides file: ${dest}`);
127
+ return;
128
+ }
129
+ fs_1.default.writeFileSync(dest, updated, "utf8");
130
+ (0, logger_1.log)(` ✓ Created: ${dest}`);
131
+ }
132
+ }
133
+ (0, logger_1.log)(`\n📋 Copying charts-values templates to ${destDir}:`);
134
+ copyRecursive(srcDir, destDir);
135
+ (0, logger_1.success)(`✅ Completed copying charts-values.\n`);
136
+ }
137
+ /**
138
+ * Generate Ansible inventory file from template
139
+ * @param env Environment name
140
+ * @param number_of_servers Number of servers (1 for single-node, >1 for multi-node)
141
+ * @param values Key-value pairs to replace in the template
142
+ * Usage: generateInventory('dev', 1, {
143
+ * HOST: process.env.APP_HOST || "localhost",
144
+ * USER: process.env.SSH_USER || "ubuntu",
145
+ * PORT: process.env.SSH_PORT || "22"
146
+ * });
147
+ */
148
+ function generateInventory(env, values) {
149
+ // Template and output paths
150
+ const templatePath = path_1.default.join(__dirname, "templates", "inventory", "inventory.template.yml");
151
+ const outputPath = path_1.default.join(process.cwd(), "infrastructure", "server-setup", "inventory", `${env}.yml`);
152
+ const templateFile = fs_1.default.readFileSync(templatePath, "utf-8");
153
+ const template = handlebars_1.default.compile(templateFile);
154
+ values['single_node'] = (values['kube_worker_nodes'].length > 0 || values['backup_host']) ? "false" : "true";
155
+ const updated = template(values);
156
+ fs_1.default.mkdirSync(path_1.default.dirname(outputPath), { recursive: true });
157
+ fs_1.default.writeFileSync(outputPath, updated);
158
+ (0, logger_1.log)(`\n✅ Generated inventory file at ${outputPath}\n`);
159
+ }
@@ -0,0 +1,2 @@
1
+ export declare function updateWorkflowEnvironments(): Promise<void>;
2
+ //# sourceMappingURL=update-workflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AAuGA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhE"}
@@ -0,0 +1,168 @@
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 (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.updateWorkflowEnvironments = updateWorkflowEnvironments;
46
+ const promises_1 = require("fs/promises");
47
+ const fs_1 = require("fs");
48
+ const path_1 = require("path");
49
+ const glob = __importStar(require("glob"));
50
+ const yaml = __importStar(require("js-yaml"));
51
+ const logger_1 = require("./logger");
52
+ function extractInfrastructureNames() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const files = glob.sync('infrastructure/server-setup/inventory/*.yml');
55
+ const infraEnvironments = files.map(file => (0, path_1.basename)(file, '.yml'));
56
+ if (infraEnvironments.length === 0) {
57
+ console.log('⚠️ Warning: No environment directories found in infrastructure/server-setup/inventory/');
58
+ return [];
59
+ }
60
+ (0, logger_1.log)('🔍 Found infrastructure configurations:', infraEnvironments.join(', '));
61
+ return infraEnvironments;
62
+ });
63
+ }
64
+ function extractEnvironmentNames() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const entries = yield (0, promises_1.readdir)('environments');
67
+ // Filter only directories
68
+ const environments = entries.filter(entry => {
69
+ const fullPath = (0, path_1.join)('environments', entry);
70
+ return (0, fs_1.statSync)(fullPath).isDirectory();
71
+ });
72
+ if (environments.length === 0) {
73
+ console.log('⚠️ Warning: No environment directories found in environments/');
74
+ return [];
75
+ }
76
+ (0, logger_1.log)('🔍 Found OpenCRVS configurations:', environments.join(', '));
77
+ return environments;
78
+ });
79
+ }
80
+ function updateOptionsInYaml(content, envList) {
81
+ // Find the options array pattern
82
+ // Matches: options: followed by array items (- item)
83
+ const optionsRegex = /([ ]*options:[ ]*\n)((?:[ ]*-[^\n]*\n)+)/;
84
+ const match = content.match(optionsRegex);
85
+ if (!match) {
86
+ throw new Error('Could not find options array in workflow file');
87
+ }
88
+ // Get the indentation from the first array item
89
+ const firstItemMatch = match[2].match(/^([ ]*)-/);
90
+ const itemIndent = firstItemMatch ? firstItemMatch[1] : ' ';
91
+ // Create new options array
92
+ const newOptions = match[1] + envList.map(env => `${itemIndent}- ${env}`).join('\n') + '\n';
93
+ // Replace the old options array with the new one
94
+ return content.replace(optionsRegex, newOptions);
95
+ }
96
+ function updateWorkflows(envList, config) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ var _a, _b, _c, _d;
99
+ const { workflows } = config;
100
+ for (const workflowPath of workflows) {
101
+ try {
102
+ const fileContents = (0, fs_1.readFileSync)(workflowPath, 'utf8');
103
+ // Verify the file is valid YAML and has the expected structure
104
+ const workflowData = yaml.load(fileContents);
105
+ if (!((_d = (_c = (_b = (_a = workflowData === null || workflowData === void 0 ? void 0 : workflowData.on) === null || _a === void 0 ? void 0 : _a.workflow_dispatch) === null || _b === void 0 ? void 0 : _b.inputs) === null || _c === void 0 ? void 0 : _c.environment) === null || _d === void 0 ? void 0 : _d.options)) {
106
+ throw new Error('Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options');
107
+ }
108
+ // Update only the options array while preserving everything else
109
+ const updatedContent = updateOptionsInYaml(fileContents, envList);
110
+ (0, fs_1.writeFileSync)(workflowPath, updatedContent, 'utf8');
111
+ (0, logger_1.log)(` ✓ Successfully updated ${workflowPath}`);
112
+ }
113
+ catch (error) {
114
+ console.error(`\n⚠️ Error updating ${workflowPath} with environments: [${envList.join(', ')}]`);
115
+ console.error(`✗ Failed to update ${workflowPath}:`, error);
116
+ throw error;
117
+ }
118
+ }
119
+ });
120
+ }
121
+ function updateWorkflowEnvironments() {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ try {
124
+ let didUpdateWorkflows = false;
125
+ // Extract infrastructure names
126
+ const infraEnvironments = yield extractInfrastructureNames();
127
+ if (infraEnvironments.length > 0) {
128
+ console.log('🔄 Updating infrastructure workflows:');
129
+ yield updateWorkflows(infraEnvironments, {
130
+ workflows: [
131
+ '.github/workflows/provision.yml',
132
+ '.github/workflows/reset-2fa.yml',
133
+ ],
134
+ path: 'on.workflow_dispatch.inputs.environment.options'
135
+ });
136
+ didUpdateWorkflows = true;
137
+ }
138
+ // Extract environment names (only directories)
139
+ const environments = yield extractEnvironmentNames();
140
+ if (environments.length > 0) {
141
+ const workflows = [
142
+ '.github/workflows/deploy-dependencies.yml',
143
+ '.github/workflows/deploy-opencrvs.yml',
144
+ '.github/workflows/clear-all-data.yml',
145
+ '.github/workflows/seed-data.yml',
146
+ '.github/workflows/reindex.yml',
147
+ '.github/workflows/github-to-k8s-sync-env.yml'
148
+ ];
149
+ (0, logger_1.log)("📋 Updating OpenCRVS application workflows:");
150
+ yield updateWorkflows(environments, {
151
+ workflows,
152
+ path: 'on.workflow_dispatch.inputs.environment.options'
153
+ });
154
+ didUpdateWorkflows = true;
155
+ }
156
+ if (didUpdateWorkflows) {
157
+ (0, logger_1.success)('✅ Workflow updates completed successfully!');
158
+ }
159
+ else {
160
+ (0, logger_1.log)('ℹ️ No workflows were updated.');
161
+ }
162
+ }
163
+ catch (error) {
164
+ console.error('\n❌ Error updating workflows:', error);
165
+ process.exit(1);
166
+ }
167
+ });
168
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=users.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/environment/users.ts"],"names":[],"mappings":""}
@@ -0,0 +1,102 @@
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 (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ const fs = __importStar(require("fs"));
49
+ const path = __importStar(require("path"));
50
+ const kleur_1 = __importDefault(require("kleur"));
51
+ const manage_users_1 = require("./manage-users");
52
+ function select(options) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const inquirer = yield import('@inquirer/prompts');
55
+ return inquirer.select(options);
56
+ });
57
+ }
58
+ /**
59
+ * Allow user to select inventory file (environment from a list)
60
+ *
61
+ * @param {string} dirPath - Path to the inventory file
62
+ *
63
+ * * @returns {string} Inventory file
64
+ */
65
+ function selectInventoryFile() {
66
+ return __awaiter(this, arguments, void 0, function* (dirPath = './infrastructure/server-setup/inventory/') {
67
+ // Check if directory exists
68
+ if (!fs.existsSync(dirPath)) {
69
+ throw Error(`Directory ${dirPath} doesn't exist`);
70
+ }
71
+ // Read and filter files
72
+ const files = fs.readdirSync(dirPath)
73
+ .filter(file => {
74
+ const filePath = path.join(dirPath, file);
75
+ const isFile = fs.statSync(filePath).isFile();
76
+ const ext = path.extname(file).slice(1).toLowerCase();
77
+ return isFile && (ext === 'yml' || ext === 'yaml');
78
+ })
79
+ .sort();
80
+ if (files.length === 0) {
81
+ throw Error(`No environment configuration files found at ${dirPath}`);
82
+ }
83
+ // Create choices - remove extension from display
84
+ const choices = files.map(file => ({
85
+ name: path.basename(file, path.extname(file)),
86
+ value: path.join(dirPath, file)
87
+ }));
88
+ const selectedFile = yield select({
89
+ message: 'Select environment (inventory file) to load users:',
90
+ choices: choices
91
+ });
92
+ return selectedFile;
93
+ });
94
+ }
95
+ function manageUsersStandalone() {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ console.log('\n', kleur_1.default.bold().underline("Manage users"), '\n');
98
+ const inventory_file = yield selectInventoryFile();
99
+ (0, manage_users_1.manageUsers)(inventory_file);
100
+ });
101
+ }
102
+ manageUsersStandalone();
@@ -0,0 +1,18 @@
1
+ import { Secret, Variable } from './github';
2
+ import { Answers } from './custom-types';
3
+ export declare function generateLongPassword(): string;
4
+ 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
+ export declare function readYamlFile(filePath: any): any;
17
+ export declare function writeYamlFile(filePath: string, data: any): void;
18
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/environment/utils.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,MAAM,EACN,QAAQ,EACT,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,OAAO,EACR,MAAM,gBAAgB,CAAA;AAGvB,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"}
@@ -0,0 +1,100 @@
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 (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.generateLongPassword = generateLongPassword;
40
+ exports.findExistingValue = findExistingValue;
41
+ exports.storeSecrets = storeSecrets;
42
+ exports.readYamlFile = readYamlFile;
43
+ exports.writeYamlFile = writeYamlFile;
44
+ const fs_1 = __importStar(require("fs"));
45
+ const yaml = __importStar(require("js-yaml"));
46
+ const dotenv_1 = __importDefault(require("dotenv"));
47
+ function generateLongPassword() {
48
+ const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
49
+ let result = '';
50
+ for (let i = 16; i > 0; --i)
51
+ result += chars[Math.floor(Math.random() * chars.length)];
52
+ return result;
53
+ }
54
+ function findExistingValue(name, type, scope, existingValues) {
55
+ return existingValues.find((value) => value.name === name && value.type === type && value.scope === scope);
56
+ }
57
+ /**
58
+ * Merges and stores secrets in `.env.{environment}` file.
59
+ * Updates existing variables, preserves unchanged ones, adds new ones.
60
+ *
61
+ * @param environment - Environment name (e.g., 'production')
62
+ * @param answers - Variables to update: `[{ name: 'KEY', value: 'val' }]`
63
+ *
64
+ * @example
65
+ * storeSecrets('prod', [{ name: 'API_KEY', value: 'abc123' }]);
66
+ */
67
+ function storeSecrets(environment, answers) {
68
+ let envConfig = {};
69
+ try {
70
+ envConfig = dotenv_1.default.parse((0, fs_1.readFileSync)(`${process.cwd()}/.env.${environment}`));
71
+ }
72
+ catch (error) {
73
+ envConfig = {};
74
+ }
75
+ const linesFromAnswers = answers.map((update) => `${update.name}="${update.value}"`);
76
+ const linesFromEnvConfig = Object.entries(envConfig)
77
+ .filter(([name]) => !answers.find((update) => update.name === name))
78
+ .map(([name, value]) => `${name}="${value}"`);
79
+ const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
80
+ (0, fs_1.writeFileSync)(`.env.${environment}`, allLines.join('\n'));
81
+ }
82
+ function readYamlFile(filePath) {
83
+ const fileContent = fs_1.default.readFileSync(filePath, "utf8");
84
+ return yaml.load(fileContent);
85
+ }
86
+ function writeYamlFile(filePath, data) {
87
+ try {
88
+ const yamlContent = yaml.dump(data, {
89
+ indent: 2,
90
+ lineWidth: -1,
91
+ flowLevel: -1, // Prevent flow style for arrays/objects
92
+ noRefs: true,
93
+ sortKeys: false
94
+ });
95
+ fs_1.default.writeFileSync(filePath, yamlContent, 'utf8');
96
+ }
97
+ catch (error) {
98
+ throw new Error(`Failed to write inventory file: ${error}`);
99
+ }
100
+ }