@opencrvs/toolkit 2.2.0-rc.ab91cce → 2.2.0-rc.e6591c5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.sh +17 -14
- package/dist/application-config/index.js +57 -14
- package/dist/authentication/index.d.ts +2 -1
- package/dist/authentication/index.js +34 -14
- package/dist/cli.js +2631 -377
- package/dist/commons/api/router.d.ts +1564 -248
- package/dist/commons/application-config/index.d.ts +3 -3
- package/dist/commons/conditionals/conditionals.d.ts +7 -7
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +6 -1
- package/dist/commons/events/ActionConfig.d.ts +68 -21
- package/dist/commons/events/ActionDocument.d.ts +89 -0
- package/dist/commons/events/ActionInput.d.ts +56 -4
- package/dist/commons/events/ActionStatus.d.ts +2 -2
- package/dist/commons/events/ActionType.d.ts +13 -1
- package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -0
- package/dist/commons/events/AuditLog.d.ts +4 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
- package/dist/commons/events/Draft.d.ts +36 -1
- package/dist/commons/events/EventConfig.d.ts +448 -1
- package/dist/commons/events/EventDocument.d.ts +90 -0
- package/dist/commons/events/EventIndex.d.ts +44 -6
- package/dist/commons/events/EventInput.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +24 -1
- package/dist/commons/events/EventStatus.d.ts +1 -0
- package/dist/commons/events/FieldConfig.d.ts +11 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +4 -1
- package/dist/commons/events/eventConfigValidation.d.ts +9 -0
- package/dist/commons/events/field.d.ts +5 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +1 -1
- package/dist/commons/events/scopes.d.ts +4 -1
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +11 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +85 -8
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +88 -8
- package/dist/commons/users/Role.d.ts +23 -0
- package/dist/commons/users/User.d.ts +263 -0
- package/dist/commons/users/authentication.d.ts +67 -0
- package/dist/commons/users/index.d.ts +5 -0
- package/dist/commons/users/roleValidations.d.ts +15 -0
- package/dist/commons/users/scopes.d.ts +1402 -0
- package/dist/commons/users/userReferences.d.ts +176 -0
- package/dist/conditionals/index.js +19 -7
- package/dist/configurator/index.d.ts +24 -0
- package/dist/configurator/index.d.ts.map +1 -0
- package/dist/configurator/index.js +161 -0
- package/dist/configurator/layout.d.ts +29 -0
- package/dist/configurator/layout.d.ts.map +1 -0
- package/dist/configurator/layout.js +78 -0
- package/dist/configurator/paths.d.ts +13 -0
- package/dist/configurator/paths.d.ts.map +1 -0
- package/dist/configurator/paths.js +48 -0
- package/dist/configurator/server/environments.d.ts +20 -0
- package/dist/configurator/server/environments.d.ts.map +1 -0
- package/dist/configurator/server/environments.js +143 -0
- package/dist/configurator/server/files.d.ts +11 -0
- package/dist/configurator/server/files.d.ts.map +1 -0
- package/dist/configurator/server/files.js +67 -0
- package/dist/configurator/server/github.d.ts +56 -0
- package/dist/configurator/server/github.d.ts.map +1 -0
- package/dist/configurator/server/github.js +239 -0
- package/dist/configurator/server/plugin.d.ts +39 -0
- package/dist/configurator/server/plugin.d.ts.map +1 -0
- package/dist/configurator/server/plugin.js +298 -0
- package/dist/configurator/server/seal.d.ts +2 -0
- package/dist/configurator/server/seal.d.ts.map +1 -0
- package/dist/configurator/server/seal.js +36 -0
- package/dist/configurator/server/sshKeys.d.ts +5 -0
- package/dist/configurator/server/sshKeys.d.ts.map +1 -0
- package/dist/configurator/server/sshKeys.js +28 -0
- package/dist/configurator/server/start.d.ts +12 -0
- package/dist/configurator/server/start.d.ts.map +1 -0
- package/dist/configurator/server/start.js +91 -0
- package/dist/configurator/testing.d.ts +11 -0
- package/dist/configurator/testing.d.ts.map +1 -0
- package/dist/configurator/testing.js +74 -0
- package/dist/configurator/ui/bindings/bindings.d.ts +35 -0
- package/dist/configurator/ui/bindings/bindings.d.ts.map +1 -0
- package/dist/configurator/ui/bindings/bindings.js +5 -0
- package/dist/configurator/ui/bindings/parsers.d.ts +7 -0
- package/dist/configurator/ui/bindings/parsers.d.ts.map +1 -0
- package/dist/configurator/ui/bindings/parsers.js +85 -0
- package/dist/configurator/ui/form/users.d.ts +11 -0
- package/dist/configurator/ui/form/users.d.ts.map +1 -0
- package/dist/configurator/ui/form/users.js +33 -0
- package/dist/configurator/ui/plan/dependencyHosts.d.ts +2 -0
- package/dist/configurator/ui/plan/dependencyHosts.d.ts.map +1 -0
- package/dist/configurator/ui/plan/dependencyHosts.js +36 -0
- package/dist/configurator/ui/plan/templateValues.d.ts +11 -0
- package/dist/configurator/ui/plan/templateValues.d.ts.map +1 -0
- package/dist/configurator/ui/plan/templateValues.js +70 -0
- package/dist/configurator/workflows.d.ts +54 -0
- package/dist/configurator/workflows.d.ts.map +1 -0
- package/dist/configurator/workflows.js +161 -0
- package/dist/configurator-assets/forms/bindings.yml +265 -0
- package/dist/configurator-assets/templates/README.md +18 -0
- package/dist/configurator-assets/templates/charts-values/dependencies/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/dependencies/values.yaml +96 -0
- package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/opencrvs-services/values.yaml +83 -0
- package/dist/configurator-assets/templates/charts-values/opentelemetry/values.yaml +102 -0
- package/dist/configurator-assets/templates/charts-values/traefik/values.override.yaml +4 -0
- package/dist/configurator-assets/templates/charts-values/traefik/values.yaml +130 -0
- package/dist/configurator-assets/templates/inventory/inventory.template.yml +98 -0
- package/dist/configurator-assets/ui/apple-touch-icon.png +0 -0
- package/dist/configurator-assets/ui/assets/index-CaqYFJUk.css +6 -0
- package/dist/configurator-assets/ui/assets/index-DU1Y6E0b.js +169 -0
- package/dist/configurator-assets/ui/assets/opencrvs-logo-sIjz08HT.svg +1 -0
- package/dist/configurator-assets/ui/assets/poppins-400-BwTUGeWf.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-500-CWICHMj6.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-600-DJVo7c07.woff2 +0 -0
- package/dist/configurator-assets/ui/assets/poppins-700-g9MkRaG0.woff2 +0 -0
- package/dist/configurator-assets/ui/favicon-32x32.png +0 -0
- package/dist/configurator-assets/ui/index.html +25 -0
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +18 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +20 -4
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +71 -48
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +145 -25
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +957 -215
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +1306 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
- package/dist/migrations/move-declaration-to-declare-action.js +260 -0
- package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
- package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
- package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
- package/dist/migrations/persistent/check-upgrade-path.js +105 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
- package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +4 -62
- package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
- package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
- package/dist/migrations/replace-incomplete-flag.js +126 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +810 -84
- package/dist/roles/index.d.ts +2 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +730 -0
- package/dist/scopes/index.d.ts +83 -100
- package/dist/scopes/index.js +29 -13
- package/dist/templates/charts-values/dependencies/values.yaml +5 -2
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -7
- package/dist/templates/charts-values/traefik/values.yaml +2 -0
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.e6591c5.tgz +0 -0
- package/package.json +17 -4
- package/tsconfig.build.json +11 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +15 -6
- package/dist/migrations/add-translations.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
- package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.js +0 -455
- package/dist/migrations/v2.1/index.d.ts +0 -6
- package/dist/migrations/v2.1/index.d.ts.map +0 -1
- package/dist/migrations/v2.1/index.js +0 -50
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
- package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-sentry.js +0 -354
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
- package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
- package/dist/migrations/v2.1/template-files.d.ts +0 -8
- package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
- package/dist/migrations/v2.1/template-files.js +0 -49
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/migrations/v2.2/index.d.ts +0 -6
- package/dist/migrations/v2.2/index.d.ts.map +0 -1
- package/dist/migrations/v2.2/index.js +0 -456
- package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
- package/dist/templates/countryconfig-template/.tiltignore +0 -1
- package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
- package/dist/templates/countryconfig-template/Tiltfile +0 -112
- package/dist/templates/countryconfig-template/assets/README.md +0 -1
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
- package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
- package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
- package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
- package/opencrvs-toolkit-2.2.0-rc.ab91cce.tgz +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.GitHubSession = void 0;
|
|
20
|
+
exports.handleApiRequest = handleApiRequest;
|
|
21
|
+
exports.middleware = middleware;
|
|
22
|
+
const node_fs_1 = require("node:fs");
|
|
23
|
+
const node_path_1 = require("node:path");
|
|
24
|
+
const environments_ts_1 = require("./environments.js");
|
|
25
|
+
const files_ts_1 = require("./files.js");
|
|
26
|
+
const github_ts_1 = require("./github.js");
|
|
27
|
+
const sshKeys_ts_1 = require("./sshKeys.js");
|
|
28
|
+
// The GitHub connection of this dev server. The token is kept here, in memory, for as long as the
|
|
29
|
+
// server runs or until disconnect; it is never written anywhere or sent back to the page.
|
|
30
|
+
class GitHubSession {
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.baseUrl = options.baseUrl;
|
|
33
|
+
this.fetchImpl = options.fetch;
|
|
34
|
+
}
|
|
35
|
+
connect(token, owner, repo) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const client = new github_ts_1.GitHubClient({ token, owner, repo, baseUrl: this.baseUrl, fetch: this.fetchImpl });
|
|
38
|
+
const result = yield client.connect();
|
|
39
|
+
this.client = result.ok ? client : undefined;
|
|
40
|
+
return result;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
disconnect() {
|
|
44
|
+
this.client = undefined;
|
|
45
|
+
}
|
|
46
|
+
get current() {
|
|
47
|
+
return this.client;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.GitHubSession = GitHubSession;
|
|
51
|
+
const LOCAL_HOST = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/;
|
|
52
|
+
const NAME = /^[A-Za-z0-9_.-]{1,100}$/;
|
|
53
|
+
// GitHub variable and secret names: letters, digits and underscores, not starting with a digit.
|
|
54
|
+
const VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,99}$/;
|
|
55
|
+
// GitHub's limit for a secret is 48 KB.
|
|
56
|
+
const MAX_VALUE = 49152;
|
|
57
|
+
const fail = (status, error) => ({ status, body: { error } });
|
|
58
|
+
// This server can act with the user's GitHub token, so a page from another site must not be able
|
|
59
|
+
// to use it: the Host must be local (against DNS rebinding) and a browser-supplied Origin must be
|
|
60
|
+
// this same server. Writes also need JSON, which makes browsers send a preflight first.
|
|
61
|
+
function crossSiteProblem(request) {
|
|
62
|
+
var _a;
|
|
63
|
+
const host = (_a = request.host) !== null && _a !== void 0 ? _a : 'localhost';
|
|
64
|
+
if (!LOCAL_HOST.test(host))
|
|
65
|
+
return 'Only local requests are accepted.';
|
|
66
|
+
if (request.origin !== undefined && request.origin !== `http://${host}`)
|
|
67
|
+
return 'Requests from other sites are not accepted.';
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const mapGitHubError = (error) => error instanceof github_ts_1.GitHubError ? fail(error.status === 401 ? 401 : 502, error.message) : fail(502, 'Could not reach GitHub.');
|
|
71
|
+
// One write per request, so the page can show progress and retry a single item. Answers say
|
|
72
|
+
// whether it worked and never repeat the value.
|
|
73
|
+
function githubWrite(path, body, session) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const client = session.current;
|
|
76
|
+
if (!client)
|
|
77
|
+
return fail(409, 'Not connected to GitHub.');
|
|
78
|
+
const input = (body !== null && body !== void 0 ? body : {});
|
|
79
|
+
try {
|
|
80
|
+
if (path === '/api/github/environment') {
|
|
81
|
+
if (typeof input.name !== 'string' || !NAME.test(input.name))
|
|
82
|
+
return fail(400, 'Invalid environment name.');
|
|
83
|
+
yield client.createEnvironment(input.name);
|
|
84
|
+
return { status: 200, body: { ok: true } };
|
|
85
|
+
}
|
|
86
|
+
const { scope, environment, name, value } = input;
|
|
87
|
+
if (scope !== 'environment' && scope !== 'repository')
|
|
88
|
+
return fail(400, 'Scope must be environment or repository.');
|
|
89
|
+
if (scope === 'environment' && (typeof environment !== 'string' || !NAME.test(environment)))
|
|
90
|
+
return fail(400, 'Invalid environment name.');
|
|
91
|
+
if (typeof name !== 'string' || !VARIABLE_NAME.test(name))
|
|
92
|
+
return fail(400, 'Invalid variable or secret name.');
|
|
93
|
+
if (typeof value !== 'string' || value === '' || value.length > MAX_VALUE)
|
|
94
|
+
return fail(400, 'The value must be 1 to 49152 characters.');
|
|
95
|
+
const target = Object.assign({ scope, name, value }, (scope === 'environment' ? { environment: environment } : {}));
|
|
96
|
+
if (path === '/api/github/variable')
|
|
97
|
+
yield client.putVariable(target, typeof input.exists === 'boolean' ? input.exists : undefined);
|
|
98
|
+
else
|
|
99
|
+
yield client.putSecret(target);
|
|
100
|
+
return { status: 200, body: { ok: true } };
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return mapGitHubError(error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function githubRoute(path, method, body, options) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const session = options.github;
|
|
110
|
+
if (path === '/api/github/status' && method === 'GET') {
|
|
111
|
+
const client = session.current;
|
|
112
|
+
return { status: 200, body: client ? { connected: true, owner: client.owner, repo: client.repo } : { connected: false } };
|
|
113
|
+
}
|
|
114
|
+
if (path === '/api/github/connect' && method === 'POST') {
|
|
115
|
+
const { token, owner, repo } = (body !== null && body !== void 0 ? body : {});
|
|
116
|
+
if (typeof token !== 'string' || !token.trim() || token.length > 500)
|
|
117
|
+
return fail(400, 'Enter a token.');
|
|
118
|
+
if (typeof owner !== 'string' || !NAME.test(owner) || typeof repo !== 'string' || !NAME.test(repo)) {
|
|
119
|
+
return fail(400, 'Enter the repository owner and name.');
|
|
120
|
+
}
|
|
121
|
+
// The answer never includes the token.
|
|
122
|
+
return { status: 200, body: yield session.connect(token.trim(), owner, repo) };
|
|
123
|
+
}
|
|
124
|
+
if (path === '/api/github/disconnect' && method === 'POST') {
|
|
125
|
+
session.disconnect();
|
|
126
|
+
return { status: 200, body: { ok: true } };
|
|
127
|
+
}
|
|
128
|
+
const writeRoutes = ['/api/github/environment', '/api/github/variable', '/api/github/secret'];
|
|
129
|
+
if (method === 'POST' && writeRoutes.includes(path))
|
|
130
|
+
return githubWrite(path, body, session);
|
|
131
|
+
const reads = ['/api/github/environments', '/api/github/repository'];
|
|
132
|
+
const environment = path.match(/^\/api\/github\/environments\/([^/]+)$/);
|
|
133
|
+
if (method === 'GET' && (reads.includes(path) || environment)) {
|
|
134
|
+
const client = session.current;
|
|
135
|
+
if (!client)
|
|
136
|
+
return fail(409, 'Not connected to GitHub.');
|
|
137
|
+
try {
|
|
138
|
+
if (path === '/api/github/environments')
|
|
139
|
+
return { status: 200, body: { names: yield client.listEnvironments() } };
|
|
140
|
+
if (path === '/api/github/repository')
|
|
141
|
+
return { status: 200, body: yield client.readRepository() };
|
|
142
|
+
return { status: 200, body: yield client.readEnvironment(decodeURIComponent(environment[1])) };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return mapGitHubError(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Rendering shows what would be written; writing renders again on the server, so the page can
|
|
152
|
+
// never choose what ends up in a file or where. Only answers on screen are sent, never secrets.
|
|
153
|
+
function filesRoute(name, action, method, body, options) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
var _a;
|
|
156
|
+
const wanted = action === 'render' ? 'POST' : 'PUT';
|
|
157
|
+
if (method !== wanted)
|
|
158
|
+
return null;
|
|
159
|
+
if (!options.files)
|
|
160
|
+
return fail(501, 'File rendering is not configured.');
|
|
161
|
+
if (!environments_ts_1.SAFE_NAME.test(name))
|
|
162
|
+
return fail(400, 'Invalid environment name.');
|
|
163
|
+
const values = body === null || body === void 0 ? void 0 : body.values;
|
|
164
|
+
if (!values || typeof values !== 'object' || Array.isArray(values))
|
|
165
|
+
return fail(400, 'Send the answers as { values }.');
|
|
166
|
+
let rendered;
|
|
167
|
+
try {
|
|
168
|
+
const { bindings, templatesDir } = options.files;
|
|
169
|
+
rendered = (0, files_ts_1.renderEnvironmentFiles)({
|
|
170
|
+
environment: name,
|
|
171
|
+
values: values,
|
|
172
|
+
bindings,
|
|
173
|
+
readTemplate: (template) => (0, node_fs_1.readFileSync)((0, node_path_1.join)(templatesDir, template), 'utf8')
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (_b) {
|
|
177
|
+
return fail(500, 'Could not render the files.');
|
|
178
|
+
}
|
|
179
|
+
const flat = options.files.bindings.flat;
|
|
180
|
+
if (action === 'render') {
|
|
181
|
+
const existing = (_a = (yield (0, environments_ts_1.readEnvironmentFiles)(options.environmentsDir, name, flat))) !== null && _a !== void 0 ? _a : {};
|
|
182
|
+
const { layout, targets } = yield (0, environments_ts_1.fileTargets)(options.environmentsDir, name, flat);
|
|
183
|
+
return {
|
|
184
|
+
status: 200,
|
|
185
|
+
body: {
|
|
186
|
+
layout,
|
|
187
|
+
// `target` is where the file would be written, or null when the layout has no place for it.
|
|
188
|
+
files: Object.entries(rendered).map(([path, text]) => { var _a, _b; return ({
|
|
189
|
+
path,
|
|
190
|
+
text,
|
|
191
|
+
existing: targets[path] === null ? null : ((_a = existing[path]) !== null && _a !== void 0 ? _a : null),
|
|
192
|
+
target: (_b = targets[path]) !== null && _b !== void 0 ? _b : null
|
|
193
|
+
}); })
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
return { status: 200, body: { written: yield (0, files_ts_1.writeEnvironmentFiles)(options.environmentsDir, name, rendered, flat) } };
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
return fail(409, error instanceof Error ? error.message : 'Could not write the files.');
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// The whole API as a function of the request, so it can be tested without a server.
|
|
206
|
+
function handleApiRequest(path_1, options_1) {
|
|
207
|
+
return __awaiter(this, arguments, void 0, function* (path, options, request = {}) {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
const method = (_a = request.method) !== null && _a !== void 0 ? _a : 'GET';
|
|
210
|
+
const problem = crossSiteProblem(request);
|
|
211
|
+
if (problem)
|
|
212
|
+
return fail(403, problem);
|
|
213
|
+
if (path.startsWith('/api/github/'))
|
|
214
|
+
return githubRoute(path, method, request.body, options);
|
|
215
|
+
// A new SSH key pair for the backup server. A POST, so it is never cached and a page from another site
|
|
216
|
+
// cannot trigger it; it is handed to the page once and stored nowhere here.
|
|
217
|
+
if (path === '/api/ssh-keypair' && method === 'POST')
|
|
218
|
+
return { status: 200, body: (0, sshKeys_ts_1.generateSSHKeyPair)() };
|
|
219
|
+
const fileRoute = path.match(/^\/api\/environments\/([^/]+)\/(render|files)$/);
|
|
220
|
+
if (fileRoute)
|
|
221
|
+
return filesRoute(decodeURIComponent(fileRoute[1]), fileRoute[2], method, request.body, options);
|
|
222
|
+
if (method !== 'GET')
|
|
223
|
+
return null;
|
|
224
|
+
if (path === '/api/context') {
|
|
225
|
+
const remote = yield ((_b = options.gitRemote) !== null && _b !== void 0 ? _b : (() => (0, environments_ts_1.readGitRemote)(options.projectDir)))();
|
|
226
|
+
return { status: 200, body: { repository: remote ? (0, environments_ts_1.parseGitRemote)(remote) : null } };
|
|
227
|
+
}
|
|
228
|
+
if (path === '/api/environments') {
|
|
229
|
+
return { status: 200, body: yield (0, environments_ts_1.listEnvironmentNames)(options.environmentsDir) };
|
|
230
|
+
}
|
|
231
|
+
const match = path.match(/^\/api\/environments\/([^/]+)$/);
|
|
232
|
+
if (match) {
|
|
233
|
+
const files = yield (0, environments_ts_1.readEnvironmentFiles)(options.environmentsDir, decodeURIComponent(match[1]));
|
|
234
|
+
return files ? { status: 200, body: { files } } : fail(404, 'Unknown environment');
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function readJson(request) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
var _a, request_1, request_1_1;
|
|
242
|
+
var _b, e_1, _c, _d;
|
|
243
|
+
const chunks = [];
|
|
244
|
+
let size = 0;
|
|
245
|
+
try {
|
|
246
|
+
for (_a = true, request_1 = __asyncValues(request); request_1_1 = yield request_1.next(), _b = request_1_1.done, !_b; _a = true) {
|
|
247
|
+
_d = request_1_1.value;
|
|
248
|
+
_a = false;
|
|
249
|
+
const chunk = _d;
|
|
250
|
+
size += chunk.length;
|
|
251
|
+
if (size > 300000)
|
|
252
|
+
throw new Error('too large');
|
|
253
|
+
chunks.push(chunk);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
257
|
+
finally {
|
|
258
|
+
try {
|
|
259
|
+
if (!_a && !_b && (_c = request_1.return)) yield _c.call(request_1);
|
|
260
|
+
}
|
|
261
|
+
finally { if (e_1) throw e_1.error; }
|
|
262
|
+
}
|
|
263
|
+
return chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : undefined;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function middleware(options) {
|
|
267
|
+
return (request, response, next) => __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
var _a, _b, _c, _d;
|
|
269
|
+
// Everything under /api/ is ours; the rest belongs to the page.
|
|
270
|
+
const path = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost').pathname;
|
|
271
|
+
if (!path.startsWith('/api/'))
|
|
272
|
+
return next();
|
|
273
|
+
let result;
|
|
274
|
+
try {
|
|
275
|
+
const method = (_b = request.method) !== null && _b !== void 0 ? _b : 'GET';
|
|
276
|
+
const json = ((_c = request.headers['content-type']) !== null && _c !== void 0 ? _c : '').startsWith('application/json');
|
|
277
|
+
const hasBody = method === 'POST' || method === 'PUT';
|
|
278
|
+
if (hasBody && !json) {
|
|
279
|
+
result = fail(415, 'Send JSON.');
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
result = (_d = (yield handleApiRequest(path, options, {
|
|
283
|
+
method,
|
|
284
|
+
body: hasBody ? yield readJson(request) : undefined,
|
|
285
|
+
host: request.headers.host,
|
|
286
|
+
origin: request.headers.origin
|
|
287
|
+
}))) !== null && _d !== void 0 ? _d : fail(404, 'Unknown API path');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
catch (_e) {
|
|
291
|
+
result = fail(400, 'Bad request.');
|
|
292
|
+
}
|
|
293
|
+
response.statusCode = result.status;
|
|
294
|
+
response.setHeader('Content-Type', 'application/json');
|
|
295
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
296
|
+
response.end(JSON.stringify(result.body));
|
|
297
|
+
});
|
|
298
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seal.d.ts","sourceRoot":"","sources":["../../../src/configurator/server/seal.ts"],"names":[],"mappings":"AAcA,wBAAsB,UAAU,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKxF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.sealSecret = sealSecret;
|
|
16
|
+
/*
|
|
17
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
18
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
19
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
20
|
+
*
|
|
21
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
22
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
23
|
+
*
|
|
24
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
25
|
+
*/
|
|
26
|
+
const libsodium_wrappers_1 = __importDefault(require("libsodium-wrappers"));
|
|
27
|
+
// GitHub only accepts secrets encrypted with the public key of the repository or environment:
|
|
28
|
+
// a libsodium "sealed box" (X25519), base64 in and out.
|
|
29
|
+
function sealSecret(publicKeyBase64, value) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield libsodium_wrappers_1.default.ready;
|
|
32
|
+
const key = libsodium_wrappers_1.default.from_base64(publicKeyBase64, libsodium_wrappers_1.default.base64_variants.ORIGINAL);
|
|
33
|
+
const sealed = libsodium_wrappers_1.default.crypto_box_seal(libsodium_wrappers_1.default.from_string(value), key);
|
|
34
|
+
return libsodium_wrappers_1.default.to_base64(sealed, libsodium_wrappers_1.default.base64_variants.ORIGINAL);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sshKeys.d.ts","sourceRoot":"","sources":["../../../src/configurator/server/sshKeys.ts"],"names":[],"mappings":"AAiBA,wBAAgB,kBAAkB,IAAI;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAMA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateSSHKeyPair = generateSSHKeyPair;
|
|
7
|
+
/*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
11
|
+
*
|
|
12
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
13
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
14
|
+
*
|
|
15
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
16
|
+
*/
|
|
17
|
+
// ssh2 is a CommonJS package, so Node's own ESM loader (which runs the dev server's config) has no named exports for it.
|
|
18
|
+
const ssh2_1 = __importDefault(require("ssh2"));
|
|
19
|
+
const { utils } = ssh2_1.default;
|
|
20
|
+
// The same key pair the CLI makes for the backup server (opencrvs-core/packages/toolkit/src/environment/ssh-keygen.ts):
|
|
21
|
+
// Ed25519, the private key in OpenSSH format.
|
|
22
|
+
function generateSSHKeyPair() {
|
|
23
|
+
const keys = utils.generateKeyPairSync('ed25519');
|
|
24
|
+
return {
|
|
25
|
+
publicKey: keys.public.toString(),
|
|
26
|
+
privateKey: keys.private.toString()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Server } from 'node:http';
|
|
2
|
+
export interface ServerOptions {
|
|
3
|
+
/** The infrastructure repository: its environments/ folder holds the environments and its git remote names the GitHub repository. */
|
|
4
|
+
projectDir: string;
|
|
5
|
+
/** Where the built page (ui/), forms/bindings.yml and templates/ are. */
|
|
6
|
+
assetsDir: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
host?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Starts listening and resolves with the server once it does. */
|
|
11
|
+
export declare function startServer(options: ServerOptions): Promise<Server>;
|
|
12
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/configurator/server/start.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAA;AAW1E,MAAM,WAAW,aAAa;IAC5B,qIAAqI;IACrI,UAAU,EAAE,MAAM,CAAA;IAClB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AA4BD,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCnE"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.startServer = startServer;
|
|
13
|
+
/*
|
|
14
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
15
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
16
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
17
|
+
*
|
|
18
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
19
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
20
|
+
*
|
|
21
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
22
|
+
*/
|
|
23
|
+
const node_http_1 = require("node:http");
|
|
24
|
+
const node_fs_1 = require("node:fs");
|
|
25
|
+
const promises_1 = require("node:fs/promises");
|
|
26
|
+
const node_path_1 = require("node:path");
|
|
27
|
+
const yaml_1 = require("yaml");
|
|
28
|
+
const plugin_ts_1 = require("./plugin.js");
|
|
29
|
+
const TYPES = {
|
|
30
|
+
'.html': 'text/html; charset=utf-8',
|
|
31
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
32
|
+
'.css': 'text/css; charset=utf-8',
|
|
33
|
+
'.svg': 'image/svg+xml',
|
|
34
|
+
'.png': 'image/png',
|
|
35
|
+
'.woff2': 'font/woff2',
|
|
36
|
+
'.json': 'application/json'
|
|
37
|
+
};
|
|
38
|
+
function serveStatic(staticDir, urlPath, response) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
41
|
+
const relative = (0, node_path_1.normalize)(decodeURIComponent(urlPath)).replace(/^([/\\])+/, '');
|
|
42
|
+
let file = (0, node_path_1.join)(staticDir, relative);
|
|
43
|
+
if (!file.startsWith(staticDir))
|
|
44
|
+
file = (0, node_path_1.join)(staticDir, 'index.html');
|
|
45
|
+
let body;
|
|
46
|
+
try {
|
|
47
|
+
body = yield (0, promises_1.readFile)(file);
|
|
48
|
+
}
|
|
49
|
+
catch (_b) {
|
|
50
|
+
// Not a file: the single page answers every other path.
|
|
51
|
+
file = (0, node_path_1.join)(staticDir, 'index.html');
|
|
52
|
+
body = yield (0, promises_1.readFile)(file);
|
|
53
|
+
}
|
|
54
|
+
response.setHeader('Content-Type', (_a = TYPES[(0, node_path_1.extname)(file)]) !== null && _a !== void 0 ? _a : 'application/octet-stream');
|
|
55
|
+
response.end(body);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** Starts listening and resolves with the server once it does. */
|
|
59
|
+
function startServer(options) {
|
|
60
|
+
var _a;
|
|
61
|
+
const projectDir = (0, node_path_1.resolve)(options.projectDir);
|
|
62
|
+
const assetsDir = (0, node_path_1.resolve)(options.assetsDir);
|
|
63
|
+
const staticDir = (0, node_path_1.join)(assetsDir, 'ui');
|
|
64
|
+
const api = (0, plugin_ts_1.middleware)({
|
|
65
|
+
environmentsDir: (_a = process.env.ENVIRONMENTS_DIR) !== null && _a !== void 0 ? _a : (0, node_path_1.join)(projectDir, 'environments'),
|
|
66
|
+
projectDir,
|
|
67
|
+
github: new plugin_ts_1.GitHubSession({ baseUrl: process.env.GITHUB_API_URL }),
|
|
68
|
+
files: {
|
|
69
|
+
bindings: (0, yaml_1.parse)((0, node_fs_1.readFileSync)((0, node_path_1.join)(assetsDir, 'forms', 'bindings.yml'), 'utf8')),
|
|
70
|
+
templatesDir: (0, node_path_1.join)(assetsDir, 'templates')
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const server = (0, node_http_1.createServer)((request, response) => {
|
|
74
|
+
api(request, response, () => {
|
|
75
|
+
var _a;
|
|
76
|
+
const path = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost').pathname;
|
|
77
|
+
serveStatic(staticDir, path, response).catch(() => {
|
|
78
|
+
response.statusCode = 500;
|
|
79
|
+
response.end('The page is not built. Build the toolkit first.');
|
|
80
|
+
});
|
|
81
|
+
}).catch(() => {
|
|
82
|
+
response.statusCode = 500;
|
|
83
|
+
response.end();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
return new Promise((resolveListening, reject) => {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
server.once('error', reject);
|
|
89
|
+
server.listen((_a = options.port) !== null && _a !== void 0 ? _a : 4173, (_b = options.host) !== null && _b !== void 0 ? _b : '127.0.0.1', () => resolveListening(server));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A throwaway directory holding `files` (path relative to it -> content). */
|
|
2
|
+
export declare function createRepository(files?: Record<string, string>): string;
|
|
3
|
+
export declare function removeRepositories(): void;
|
|
4
|
+
export declare const read: (root: string, path: string) => string;
|
|
5
|
+
/** The shape of the `environment` input in the infrastructure repository's workflows. */
|
|
6
|
+
export declare const environmentInput: (options: string[], fallback?: string) => string;
|
|
7
|
+
/** Another choice input with its own `options`, as `provision.yml` has. */
|
|
8
|
+
export declare const tagsInput: string;
|
|
9
|
+
/** A workflow with the given inputs and, like the real ones, an unrelated `options:` further down. */
|
|
10
|
+
export declare const workflow: (...inputs: string[]) => string;
|
|
11
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/configurator/testing.ts"],"names":[],"mappings":"AAwBA,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAQ3E;AAED,wBAAgB,kBAAkB,SAIjC;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,QAAQ,MAAM,WACP,CAAA;AAExC,yFAAyF;AACzF,eAAO,MAAM,gBAAgB,YAAa,MAAM,EAAE,8BASpC,CAAA;AAEd,2EAA2E;AAC3E,eAAO,MAAM,SAAS,QAMV,CAAA;AAEZ,sGAAsG;AACtG,eAAO,MAAM,QAAQ,cAAe,MAAM,EAAE,WAgB9B,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.workflow = exports.tagsInput = exports.environmentInput = exports.read = void 0;
|
|
14
|
+
exports.createRepository = createRepository;
|
|
15
|
+
exports.removeRepositories = removeRepositories;
|
|
16
|
+
// Helpers for the tests. Nothing in the CLI imports this file.
|
|
17
|
+
const node_fs_1 = require("node:fs");
|
|
18
|
+
const node_os_1 = require("node:os");
|
|
19
|
+
const node_path_1 = require("node:path");
|
|
20
|
+
const created = [];
|
|
21
|
+
/** A throwaway directory holding `files` (path relative to it -> content). */
|
|
22
|
+
function createRepository(files = {}) {
|
|
23
|
+
const root = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'configurator-'));
|
|
24
|
+
created.push(root);
|
|
25
|
+
for (const [path, content] of Object.entries(files)) {
|
|
26
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)((0, node_path_1.join)(root, path)), { recursive: true });
|
|
27
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, path), content);
|
|
28
|
+
}
|
|
29
|
+
return root;
|
|
30
|
+
}
|
|
31
|
+
function removeRepositories() {
|
|
32
|
+
for (const directory of created.splice(0)) {
|
|
33
|
+
(0, node_fs_1.rmSync)(directory, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const read = (root, path) => (0, node_fs_1.readFileSync)((0, node_path_1.join)(root, path), 'utf8');
|
|
37
|
+
exports.read = read;
|
|
38
|
+
/** The shape of the `environment` input in the infrastructure repository's workflows. */
|
|
39
|
+
const environmentInput = (options, fallback = options[0]) => [
|
|
40
|
+
' environment:',
|
|
41
|
+
' description: Environment',
|
|
42
|
+
' required: true',
|
|
43
|
+
` default: ${fallback}`,
|
|
44
|
+
' type: choice',
|
|
45
|
+
' options:',
|
|
46
|
+
...options.map((option) => ` - ${option}`)
|
|
47
|
+
].join('\n');
|
|
48
|
+
exports.environmentInput = environmentInput;
|
|
49
|
+
/** Another choice input with its own `options`, as `provision.yml` has. */
|
|
50
|
+
exports.tagsInput = [
|
|
51
|
+
' tags:',
|
|
52
|
+
' type: choice',
|
|
53
|
+
' options:',
|
|
54
|
+
' - all',
|
|
55
|
+
' - users'
|
|
56
|
+
].join('\n');
|
|
57
|
+
/** A workflow with the given inputs and, like the real ones, an unrelated `options:` further down. */
|
|
58
|
+
const workflow = (...inputs) => [
|
|
59
|
+
'name: Test',
|
|
60
|
+
'on:',
|
|
61
|
+
' workflow_dispatch:',
|
|
62
|
+
' inputs:',
|
|
63
|
+
...inputs,
|
|
64
|
+
'jobs:',
|
|
65
|
+
' run:',
|
|
66
|
+
' runs-on: ubuntu-latest',
|
|
67
|
+
' steps:',
|
|
68
|
+
' - uses: ./.github/actions/ansible',
|
|
69
|
+
' with:',
|
|
70
|
+
' options: |-',
|
|
71
|
+
' --verbose',
|
|
72
|
+
''
|
|
73
|
+
].join('\n');
|
|
74
|
+
exports.workflow = workflow;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type SourceName = 'github' | 'file';
|
|
2
|
+
interface GitHubTarget {
|
|
3
|
+
source: 'github';
|
|
4
|
+
kind: 'variable' | 'secret';
|
|
5
|
+
scope: 'environment' | 'repository';
|
|
6
|
+
name?: string;
|
|
7
|
+
legacy?: string[];
|
|
8
|
+
parse?: string;
|
|
9
|
+
}
|
|
10
|
+
interface FileTarget {
|
|
11
|
+
source: 'file';
|
|
12
|
+
template: string;
|
|
13
|
+
var: string;
|
|
14
|
+
collect?: 'container';
|
|
15
|
+
parse?: string;
|
|
16
|
+
}
|
|
17
|
+
type Target = GitHubTarget | FileTarget;
|
|
18
|
+
interface Binding {
|
|
19
|
+
precedence?: SourceName[];
|
|
20
|
+
targets: Target[];
|
|
21
|
+
}
|
|
22
|
+
export interface Bindings {
|
|
23
|
+
precedence: SourceName[];
|
|
24
|
+
files: Record<string, string>;
|
|
25
|
+
flat?: string;
|
|
26
|
+
templates?: Record<string, {
|
|
27
|
+
defaults?: Record<string, unknown>;
|
|
28
|
+
derived?: string[];
|
|
29
|
+
}>;
|
|
30
|
+
ignore: Record<string, string>;
|
|
31
|
+
bindings: Record<string, Binding>;
|
|
32
|
+
}
|
|
33
|
+
export declare const githubName: (question: string, target: GitHubTarget) => string;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../../../src/configurator/ui/bindings/bindings.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE1C,UAAU,YAAY;IACpB,MAAM,EAAE,QAAQ,CAAA;IAChB,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC3B,KAAK,EAAE,aAAa,GAAG,YAAY,CAAA;IAEnC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAA;IAEd,QAAQ,EAAE,MAAM,CAAA;IAEhB,GAAG,EAAE,MAAM,CAAA;IAEX,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,KAAK,MAAM,GAAG,YAAY,GAAG,UAAU,CAAA;AAEvC,UAAU,OAAO;IACf,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,UAAU,EAAE,CAAA;IAExB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAG7B,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;IAEtF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,eAAO,MAAM,UAAU,aAAc,MAAM,UAAU,YAAY,WAA4B,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Parser = (raw: unknown) => unknown;
|
|
2
|
+
export declare const PARSERS: Record<string, Parser>;
|
|
3
|
+
export declare const FORMATTERS: Record<string, (value: unknown) => unknown>;
|
|
4
|
+
export declare function formatWith(name: string | undefined, value: unknown): unknown;
|
|
5
|
+
export declare function parseWith(name: string | undefined, raw: unknown): unknown;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../../../../src/configurator/ui/bindings/parsers.ts"],"names":[],"mappings":"AAeA,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;AAIvC,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuC1C,CAAA;AAID,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CASlE,CAAA;AAOD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAI5E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzE"}
|