@opencrvs/toolkit 2.1.0-rc.75e32d8 → 2.1.0-rc.7737766
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/README.md +1 -0
- package/build.sh +9 -1
- package/create-countryconfig/index.js +412 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +349 -277
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +754 -0
- package/dist/cli.js +1782 -113
- package/dist/commons/api/router.d.ts +3976 -3374
- package/dist/commons/application-config/index.d.ts +6 -6
- package/dist/commons/conditionals/conditionals.d.ts +32 -323
- package/dist/commons/conditionals/validate.d.ts +16 -5
- package/dist/commons/events/ActionConfig.d.ts +109 -105
- package/dist/commons/events/ActionDocument.d.ts +121 -127
- package/dist/commons/events/ActionInput.d.ts +4 -10
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/ActionType.d.ts +62 -62
- package/dist/commons/events/AdvancedSearchConfig.d.ts +543 -507
- package/dist/commons/events/AuditLog.d.ts +189 -42
- package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
- package/dist/commons/events/Conditional.d.ts +3 -3
- package/dist/commons/events/CountryConfigQueryInput.d.ts +590 -590
- package/dist/commons/events/Draft.d.ts +37 -37
- package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
- package/dist/commons/events/EventConfig.d.ts +8 -5
- package/dist/commons/events/EventDocument.d.ts +518 -50
- package/dist/commons/events/EventIndex.d.ts +49 -72
- package/dist/commons/events/EventMetadata.d.ts +39 -49
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +434 -389
- package/dist/commons/events/FieldType.d.ts +51 -51
- package/dist/commons/events/FieldTypeMapping.d.ts +86 -86
- package/dist/commons/events/FieldValue.d.ts +14 -14
- package/dist/commons/events/Flag.d.ts +57 -15
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/TemplateConfig.d.ts +1 -1
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
- package/dist/commons/events/WorkqueueConfig.d.ts +817 -814
- package/dist/commons/events/deduplication.d.ts +1 -1
- package/dist/commons/events/event.d.ts +14 -2
- package/dist/commons/events/field.d.ts +69 -198
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +247 -14
- package/dist/commons/events/mocks.test.utils.d.ts +48 -4
- package/dist/commons/events/scopes.d.ts +4 -4
- package/dist/commons/events/state/index.d.ts +17 -17
- package/dist/commons/events/state/utils.d.ts +7 -7
- package/dist/commons/events/test.utils.d.ts +64 -46
- package/dist/commons/events/utils.d.ts +129 -114
- package/dist/commons/notification/UserNotifications.d.ts +38 -23
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +334 -60
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/derived-variables.d.ts +119 -119
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +10 -0
- package/dist/environment/logger.d.ts +6 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +17 -7
- package/dist/environment/paths.d.ts +7 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +72 -0
- package/dist/environment/questions.d.ts +75 -74
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.js +36 -21
- package/dist/environment/swarm-to-k8s.js +17 -7
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +2 -1
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +34 -12
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +82 -0
- package/dist/environment/users.js +28 -20
- package/dist/environment/utils.d.ts +1 -1
- package/dist/environment/utils.js +17 -7
- package/dist/events/deduplication.d.ts +1 -1
- package/dist/events/index.js +7641 -7128
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +17 -7
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
- package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.js +17 -7
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +213 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +438 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1058 -0
- package/dist/notification/index.js +1870 -1464
- package/dist/scopes/index.d.ts +560 -157
- package/dist/scopes/index.js +335 -60
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +39 -0
- package/dist/templates/charts-values/dependencies/values.yaml +2 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/check.d.ts +21 -0
- package/dist/translations/check.d.ts.map +1 -0
- package/dist/translations/check.js +132 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +345 -0
- package/opencrvs-toolkit-2.1.0-rc.7737766.tgz +0 -0
- package/package.json +12 -7
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.75e32d8.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
mode: deployment
|
|
2
|
+
|
|
3
|
+
image:
|
|
4
|
+
repository: otel/opentelemetry-collector-k8s
|
|
5
|
+
|
|
6
|
+
resources:
|
|
7
|
+
requests:
|
|
8
|
+
cpu: 100m
|
|
9
|
+
memory: 128Mi
|
|
10
|
+
limits:
|
|
11
|
+
cpu: 500m
|
|
12
|
+
memory: 512Mi
|
|
13
|
+
|
|
14
|
+
ports:
|
|
15
|
+
jaeger-compact:
|
|
16
|
+
enabled: false
|
|
17
|
+
jaeger-thrift:
|
|
18
|
+
enabled: false
|
|
19
|
+
jaeger-grpc:
|
|
20
|
+
enabled: false
|
|
21
|
+
zipkin:
|
|
22
|
+
enabled: false
|
|
23
|
+
|
|
24
|
+
config:
|
|
25
|
+
receivers:
|
|
26
|
+
otlp:
|
|
27
|
+
protocols:
|
|
28
|
+
grpc:
|
|
29
|
+
endpoint: ${env:MY_POD_IP}:4317
|
|
30
|
+
http:
|
|
31
|
+
endpoint: ${env:MY_POD_IP}:4318
|
|
32
|
+
prometheus: null
|
|
33
|
+
jaeger: null
|
|
34
|
+
zipkin: null
|
|
35
|
+
|
|
36
|
+
exporters:
|
|
37
|
+
otlp/elastic:
|
|
38
|
+
endpoint: apm-server.opencrvs-deps-{{env}}.svc.cluster.local:8200
|
|
39
|
+
tls:
|
|
40
|
+
insecure: true
|
|
41
|
+
processors:
|
|
42
|
+
batch:
|
|
43
|
+
timeout: 15s
|
|
44
|
+
send_batch_size: 1024
|
|
45
|
+
|
|
46
|
+
memory_limiter:
|
|
47
|
+
check_interval: 5s
|
|
48
|
+
limit_percentage: 80
|
|
49
|
+
spike_limit_percentage: 25
|
|
50
|
+
|
|
51
|
+
transform/traces:
|
|
52
|
+
error_mode: ignore
|
|
53
|
+
trace_statements:
|
|
54
|
+
# Start with the raw path.
|
|
55
|
+
- set(span.attributes["http.route"], span.attributes["url.path"]) where resource.attributes["service.name"] == "traefik" and span.attributes["url.path"] != nil
|
|
56
|
+
|
|
57
|
+
# Match getTracePath(): collapse repeated slashes.
|
|
58
|
+
- replace_pattern(span.attributes["http.route"], "/+", "/") where resource.attributes["service.name"] == "traefik" and span.attributes["http.route"] != nil
|
|
59
|
+
|
|
60
|
+
# Match getTracePath(): replace dynamic-looking segments with "#".
|
|
61
|
+
- replace_pattern(span.attributes["http.route"], "/([^/]*\\.[^/]*|[0-9]+|[0-9a-fA-F]{24}|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})(/|$)", "/#$$2") where resource.attributes["service.name"] == "traefik" and span.attributes["http.route"] != nil
|
|
62
|
+
|
|
63
|
+
# Concatenate Request method and normalized URL to conform same format as NodeJs.
|
|
64
|
+
- set(span.name, Concat([span.attributes["http.request.method"], span.attributes["http.route"]], " ")) where resource.attributes["service.name"] == "traefik" and span.attributes["http.request.method"] != nil and span.attributes["http.route"] != nil
|
|
65
|
+
|
|
66
|
+
# SDK language to avoid errors in Kibana on APM -> Service Inventory -> Traefik -> Metrics.
|
|
67
|
+
- delete_key(resource.attributes, "telemetry.sdk.language") where resource.attributes["service.name"] == "traefik"
|
|
68
|
+
|
|
69
|
+
# Nginx OTEL module uses older HTTP semantic convention names, so build the span name from http.method and http.route.
|
|
70
|
+
- set(span.name, Concat([span.attributes["http.method"], span.attributes["http.route"]], " ")) where (resource.attributes["service.name"] == "opencrvs_client" or resource.attributes["service.name"] == "opencrvs_login") and span.attributes["http.method"] != nil and span.attributes["http.route"] != nil
|
|
71
|
+
|
|
72
|
+
service:
|
|
73
|
+
telemetry:
|
|
74
|
+
metrics:
|
|
75
|
+
level: none
|
|
76
|
+
readers: null
|
|
77
|
+
pipelines:
|
|
78
|
+
logs: null
|
|
79
|
+
metrics:
|
|
80
|
+
receivers:
|
|
81
|
+
- otlp
|
|
82
|
+
processors:
|
|
83
|
+
- memory_limiter
|
|
84
|
+
- batch
|
|
85
|
+
exporters:
|
|
86
|
+
- otlp/elastic
|
|
87
|
+
traces:
|
|
88
|
+
receivers:
|
|
89
|
+
- otlp
|
|
90
|
+
processors:
|
|
91
|
+
- memory_limiter
|
|
92
|
+
- transform/traces
|
|
93
|
+
- batch
|
|
94
|
+
exporters:
|
|
95
|
+
- otlp/elastic
|
|
@@ -9,16 +9,28 @@
|
|
|
9
9
|
|
|
10
10
|
# Overwriting https://github.com/traefik/traefik-helm-chart/blob/master/traefik/values.yaml
|
|
11
11
|
namespaceOverride: "traefik"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
access
|
|
19
|
-
|
|
12
|
+
log:
|
|
13
|
+
# "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "PANIC"
|
|
14
|
+
level: "INFO"
|
|
15
|
+
# format: "common" # For local environment
|
|
16
|
+
format: "json" # For server environment
|
|
17
|
+
accessLog:
|
|
18
|
+
# -- To enable access logs
|
|
19
|
+
enabled: true
|
|
20
|
+
format: "json"
|
|
21
|
+
|
|
22
|
+
tracing:
|
|
23
|
+
serviceName: traefik
|
|
24
|
+
resourceAttributes:
|
|
25
|
+
deployment.environment.name: "{{env}}"
|
|
26
|
+
service.namespace: traefik
|
|
27
|
+
otlp:
|
|
20
28
|
enabled: true
|
|
21
|
-
|
|
29
|
+
grpc:
|
|
30
|
+
enabled: true
|
|
31
|
+
endpoint: "opentelemetry-collector.opencrvs-deps-{{env}}.svc.cluster.local:4317"
|
|
32
|
+
insecure: true
|
|
33
|
+
|
|
22
34
|
|
|
23
35
|
ingressRoute:
|
|
24
36
|
dashboard:
|
|
@@ -98,6 +110,8 @@ tlsStore:
|
|
|
98
110
|
|
|
99
111
|
deployment:
|
|
100
112
|
hostNetwork: true
|
|
113
|
+
podLabels:
|
|
114
|
+
service_name: traefik
|
|
101
115
|
{{#if static_ssl}}
|
|
102
116
|
kind: DaemonSet
|
|
103
117
|
{{/if}}
|
|
@@ -13,10 +13,8 @@ all:
|
|
|
13
13
|
# - If you are behind VPN, use private IP address
|
|
14
14
|
# - If your server is exposed (not recommeded), use public IP address
|
|
15
15
|
# - If you would like to run kubectl commands from the remote server, leave this field empty
|
|
16
|
-
#
|
|
17
|
-
|
|
16
|
+
# kube_api_host: ''
|
|
18
17
|
# IMPORTANT: If master VM has multiple ethernet interfaces, put private IP address at kube_api_host
|
|
19
|
-
# kube_api_host: 10.10.10.10
|
|
20
18
|
kube_api_host: {{kube_api_host}}
|
|
21
19
|
|
|
22
20
|
# Default ansible provision user, keep as is
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Message = {
|
|
2
|
+
id: string;
|
|
3
|
+
defaultMessage: string;
|
|
4
|
+
description: string;
|
|
5
|
+
};
|
|
6
|
+
export type CheckResult = {
|
|
7
|
+
missing: Message[];
|
|
8
|
+
/** Rows in countryconfig.csv that nothing in the source declares. */
|
|
9
|
+
outdated: string[];
|
|
10
|
+
/** Files declaring a message whose id is assembled at runtime. */
|
|
11
|
+
dynamicIds: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare function check(cwd: string): CheckResult;
|
|
14
|
+
/**
|
|
15
|
+
* Adds a row per missing message, filling in only English — the rest is copy
|
|
16
|
+
* somebody has to write. Returns the ids added.
|
|
17
|
+
*
|
|
18
|
+
* Creates countryconfig.csv if it doesn't exist yet.
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeMissing(cwd: string, missing: Message[]): string[];
|
|
21
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/translations/check.ts"],"names":[],"mappings":"AAwCA,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,EAAE,CAAA;IAClB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,kEAAkE;IAClE,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAgED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAyB9C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAwB3D"}
|
|
@@ -0,0 +1,132 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.check = check;
|
|
17
|
+
exports.writeMissing = writeMissing;
|
|
18
|
+
/**
|
|
19
|
+
* Checks that every message a country config declares has a row in
|
|
20
|
+
* `countryconfig.csv`.
|
|
21
|
+
*
|
|
22
|
+
* The mirror of the check core runs over its own packages: core validates
|
|
23
|
+
* `client.csv` and `login.csv` against the client and login sources, and this
|
|
24
|
+
* validates `countryconfig.csv` against the country config's own source.
|
|
25
|
+
* Without it, a form or event label added to a country config renders as a raw
|
|
26
|
+
* id.
|
|
27
|
+
*
|
|
28
|
+
* `client.csv` and `login.csv` are read but never written: core owns them, and
|
|
29
|
+
* `opencrvs upgrade` keeps them in sync.
|
|
30
|
+
*/
|
|
31
|
+
const ts_morph_1 = require("ts-morph");
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
const csv_1 = require("../csv");
|
|
34
|
+
const TRANSLATIONS = 'src/translations';
|
|
35
|
+
const OWN_FILE = `${TRANSLATIONS}/countryconfig.csv`;
|
|
36
|
+
const CORE_FILES = [`${TRANSLATIONS}/client.csv`, `${TRANSLATIONS}/login.csv`];
|
|
37
|
+
/**
|
|
38
|
+
* The value of a property when the source says what it is outright. A template
|
|
39
|
+
* literal with something interpolated into it does not count.
|
|
40
|
+
*/
|
|
41
|
+
function staticStringOf(node, name) {
|
|
42
|
+
const property = node.getProperty(name);
|
|
43
|
+
if (!property || !ts_morph_1.Node.isPropertyAssignment(property)) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const initializer = property.getInitializer();
|
|
47
|
+
return initializer &&
|
|
48
|
+
(ts_morph_1.Node.isStringLiteral(initializer) ||
|
|
49
|
+
ts_morph_1.Node.isNoSubstitutionTemplateLiteral(initializer))
|
|
50
|
+
? initializer.getLiteralValue()
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
function messagesDeclaredIn(cwd) {
|
|
54
|
+
const project = new ts_morph_1.Project({ skipAddingFilesFromTsConfig: true });
|
|
55
|
+
project.addSourceFilesAtPaths([
|
|
56
|
+
path_1.default.join(cwd, 'src/**/*.ts'),
|
|
57
|
+
path_1.default.join(cwd, 'src/**/*.tsx'),
|
|
58
|
+
`!${path_1.default.join(cwd, 'src/**/*.test.ts')}`,
|
|
59
|
+
`!${path_1.default.join(cwd, 'src/**/*.test.tsx')}`,
|
|
60
|
+
`!${path_1.default.join(cwd, 'src/**/*.stories.ts')}`,
|
|
61
|
+
`!${path_1.default.join(cwd, 'src/**/*.stories.tsx')}`
|
|
62
|
+
]);
|
|
63
|
+
const messages = [];
|
|
64
|
+
const dynamicIds = [];
|
|
65
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
66
|
+
sourceFile.forEachDescendant((node) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(node)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!(node.getProperty('id') && node.getProperty('defaultMessage'))) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const id = staticStringOf(node, 'id');
|
|
75
|
+
if (id === undefined) {
|
|
76
|
+
dynamicIds.push(path_1.default.relative(cwd, sourceFile.getFilePath()));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
messages.push({
|
|
80
|
+
id,
|
|
81
|
+
defaultMessage: (_a = staticStringOf(node, 'defaultMessage')) !== null && _a !== void 0 ? _a : '',
|
|
82
|
+
description: (_b = staticStringOf(node, 'description')) !== null && _b !== void 0 ? _b : ''
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return { messages, dynamicIds: [...new Set(dynamicIds)] };
|
|
87
|
+
}
|
|
88
|
+
function check(cwd) {
|
|
89
|
+
var _a;
|
|
90
|
+
const { messages, dynamicIds } = messagesDeclaredIn(cwd);
|
|
91
|
+
const own = (0, csv_1.readCsvFile)(path_1.default.join(cwd, OWN_FILE));
|
|
92
|
+
const covered = new Set([own, ...CORE_FILES.map((file) => (0, csv_1.readCsvFile)(path_1.default.join(cwd, file)))]
|
|
93
|
+
.flatMap((csv) => { var _a; return (_a = csv === null || csv === void 0 ? void 0 : csv.body) !== null && _a !== void 0 ? _a : []; })
|
|
94
|
+
.map(csv_1.idOf));
|
|
95
|
+
// The same message is often declared in more than one place.
|
|
96
|
+
const missing = [
|
|
97
|
+
...new Map(messages
|
|
98
|
+
.filter(({ id }) => !covered.has(id))
|
|
99
|
+
.map((message) => [message.id, message])).values()
|
|
100
|
+
].sort((a, b) => (a.id < b.id ? -1 : 1));
|
|
101
|
+
const declared = new Set(messages.map(({ id }) => id));
|
|
102
|
+
const outdated = ((_a = own === null || own === void 0 ? void 0 : own.body) !== null && _a !== void 0 ? _a : [])
|
|
103
|
+
.map(csv_1.idOf)
|
|
104
|
+
.filter((id) => !declared.has(id));
|
|
105
|
+
return { missing, outdated, dynamicIds };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a row per missing message, filling in only English — the rest is copy
|
|
109
|
+
* somebody has to write. Returns the ids added.
|
|
110
|
+
*
|
|
111
|
+
* Creates countryconfig.csv if it doesn't exist yet.
|
|
112
|
+
*/
|
|
113
|
+
function writeMissing(cwd, missing) {
|
|
114
|
+
var _a;
|
|
115
|
+
const file = (_a = (0, csv_1.readCsvFile)(path_1.default.join(cwd, OWN_FILE))) !== null && _a !== void 0 ? _a : {
|
|
116
|
+
header: 'id,description,en',
|
|
117
|
+
body: [],
|
|
118
|
+
newline: '\n',
|
|
119
|
+
trailingNewline: true
|
|
120
|
+
};
|
|
121
|
+
const columns = file.header.split(',');
|
|
122
|
+
const rows = missing.map((message) => (0, csv_1.toCsvLine)(columns.map((column) => {
|
|
123
|
+
if (column === 'id')
|
|
124
|
+
return message.id;
|
|
125
|
+
if (column === 'description')
|
|
126
|
+
return message.description;
|
|
127
|
+
return column === 'en' ? message.defaultMessage : '';
|
|
128
|
+
})));
|
|
129
|
+
const added = (0, csv_1.addRows)(file, rows);
|
|
130
|
+
(0, csv_1.writeCsvFile)(path_1.default.join(cwd, OWN_FILE), file);
|
|
131
|
+
return added;
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/verify/endpoints.ts"],"names":[],"mappings":"AA2QA,wBAAsB,kBAAkB,CACtC,MAAM,GAAE,MAA2B,GAClC,OAAO,CAAC,IAAI,CAAC,CAkIf"}
|
|
@@ -0,0 +1,345 @@
|
|
|
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.runVerifyEndpoints = runVerifyEndpoints;
|
|
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
|
+
/* eslint-disable no-console */
|
|
24
|
+
const colors_1 = require("kleur/colors");
|
|
25
|
+
const REQUEST_TIMEOUT_MS = 15000;
|
|
26
|
+
/**
|
|
27
|
+
* The country config service listens on port 3040 locally. This command is
|
|
28
|
+
* meant to be run against that instance right after `opencrvs upgrade`, to
|
|
29
|
+
* confirm the upgraded config still exposes the expected endpoints and keeps
|
|
30
|
+
* the secured ones locked down.
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_TARGET_URL = 'http://localhost:3040';
|
|
33
|
+
/**
|
|
34
|
+
* Publicly-served endpoints every country config must expose. The client and
|
|
35
|
+
* login apps, and core services, fetch these before or without user
|
|
36
|
+
* authentication, so they must respond with a 2xx status.
|
|
37
|
+
*
|
|
38
|
+
* `/fonts/{filename}` is handled separately: it is public but parameterised
|
|
39
|
+
* with a country-specific filename we cannot know, so we probe a made-up name.
|
|
40
|
+
*/
|
|
41
|
+
const REQUIRED_PUBLIC_ENDPOINTS = [
|
|
42
|
+
{ method: 'GET', path: '/client-config.js' },
|
|
43
|
+
{ method: 'GET', path: '/login-config.js' },
|
|
44
|
+
{ method: 'GET', path: '/handlebars.js' },
|
|
45
|
+
{ method: 'GET', path: '/content/client' },
|
|
46
|
+
{ method: 'GET', path: '/content/login' },
|
|
47
|
+
{ method: 'GET', path: '/content/map.geojson' },
|
|
48
|
+
{ method: 'GET', path: '/content/country-logo' },
|
|
49
|
+
{ method: 'GET', path: '/config/application' },
|
|
50
|
+
{ method: 'GET', path: '/config/workqueues' },
|
|
51
|
+
{ method: 'GET', path: '/config/locations' },
|
|
52
|
+
{ method: 'GET', path: '/config/roles' },
|
|
53
|
+
{ method: 'GET', path: '/config/events' }
|
|
54
|
+
];
|
|
55
|
+
/** Made-up path segment used to probe parameterised routes we can't enumerate. */
|
|
56
|
+
const PROBE_SEGMENT = 'verify-endpoints-probe';
|
|
57
|
+
/**
|
|
58
|
+
* User-notification trigger events. Core forwards an authenticated token to
|
|
59
|
+
* each of these, so a country config must never process them unauthenticated.
|
|
60
|
+
*
|
|
61
|
+
* Kept in sync with `TriggerEvent` in `../commons/notification` by the
|
|
62
|
+
* compile-time guard below.
|
|
63
|
+
*/
|
|
64
|
+
const SECURED_TRIGGER_USER_EVENTS = [
|
|
65
|
+
'user-created',
|
|
66
|
+
'user-updated',
|
|
67
|
+
'username-reminder',
|
|
68
|
+
'reset-password',
|
|
69
|
+
'reset-password-by-admin',
|
|
70
|
+
'password-reset-link',
|
|
71
|
+
'username-reminder-link',
|
|
72
|
+
'resend-invite',
|
|
73
|
+
'2fa',
|
|
74
|
+
'all-user-notification',
|
|
75
|
+
'change-phone-number',
|
|
76
|
+
'change-email-address'
|
|
77
|
+
];
|
|
78
|
+
/**
|
|
79
|
+
* Endpoints that must require authentication. Each must either be absent (404)
|
|
80
|
+
* or reject an unauthenticated request (401/403) — never process it. Paths
|
|
81
|
+
* with `{param}` segments use a throwaway concrete value; authentication is
|
|
82
|
+
* enforced before the handler ever inspects the parameters (so `/certificates`
|
|
83
|
+
* ids and the like do not need to be real).
|
|
84
|
+
*/
|
|
85
|
+
const SECURED_ENDPOINTS = [
|
|
86
|
+
...SECURED_TRIGGER_USER_EVENTS.map((event) => ({
|
|
87
|
+
method: 'POST',
|
|
88
|
+
path: `/triggers/user/${event}`
|
|
89
|
+
})),
|
|
90
|
+
{ method: 'POST', path: '/trigger/telemetry' },
|
|
91
|
+
{ method: 'GET', path: '/triggers/system/ready' },
|
|
92
|
+
{
|
|
93
|
+
method: 'GET',
|
|
94
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
95
|
+
label: '/certificates/{id}'
|
|
96
|
+
},
|
|
97
|
+
{ method: 'GET', path: '/certificates' },
|
|
98
|
+
{ method: 'GET', path: '/config/users' }
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* Used only when `/config/events` cannot be fetched, so the event action
|
|
102
|
+
* triggers are still checked against their route patterns.
|
|
103
|
+
*/
|
|
104
|
+
const FALLBACK_EVENT_TRIGGERS = [
|
|
105
|
+
{
|
|
106
|
+
method: 'POST',
|
|
107
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
108
|
+
label: '/trigger/events/{event}/actions/{action}'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
method: 'POST',
|
|
112
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
113
|
+
label: '/trigger/events/birth/actions/{action}'
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
method: 'POST',
|
|
117
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
118
|
+
label: '/trigger/events/death/actions/{action}'
|
|
119
|
+
}
|
|
120
|
+
];
|
|
121
|
+
const isSuccess = (status) => status !== 'error' && status >= 200 && status < 300;
|
|
122
|
+
const requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
123
|
+
/**
|
|
124
|
+
* Issues a single request and returns its HTTP status, or `'error'` when the
|
|
125
|
+
* request could not be completed (DNS failure, connection refused, timeout).
|
|
126
|
+
*/
|
|
127
|
+
function requestStatus(url, method) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const controller = new AbortController();
|
|
130
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
131
|
+
try {
|
|
132
|
+
const response = yield fetch(url, {
|
|
133
|
+
method,
|
|
134
|
+
signal: controller.signal,
|
|
135
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
136
|
+
// rejects with 401/403 before ever reading the body.
|
|
137
|
+
headers: method === 'POST' ? { 'Content-Type': 'application/json' } : undefined,
|
|
138
|
+
body: method === 'POST' ? '{}' : undefined
|
|
139
|
+
});
|
|
140
|
+
return response.status;
|
|
141
|
+
}
|
|
142
|
+
catch (_a) {
|
|
143
|
+
return 'error';
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function toEventTriggerConfig(value) {
|
|
151
|
+
if (typeof value !== 'object' || value === null) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const record = value;
|
|
155
|
+
if (typeof record.id !== 'string') {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const actions = Array.isArray(record.actions)
|
|
159
|
+
? Array.from(new Set(record.actions
|
|
160
|
+
.map((action) => {
|
|
161
|
+
if (typeof action !== 'object' || action === null) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const type = action.type;
|
|
165
|
+
return typeof type === 'string' ? type : null;
|
|
166
|
+
})
|
|
167
|
+
.filter((type) => type !== null)))
|
|
168
|
+
: [];
|
|
169
|
+
return { id: record.id, actions };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Fetches the event configuration so the event action triggers can be checked
|
|
173
|
+
* against the real event ids and action types. Returns `null` if the endpoint
|
|
174
|
+
* is unreachable or does not return the expected shape.
|
|
175
|
+
*/
|
|
176
|
+
function fetchEventConfigs(baseUrl) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
180
|
+
try {
|
|
181
|
+
const response = yield fetch(`${baseUrl}/config/events`, {
|
|
182
|
+
signal: controller.signal
|
|
183
|
+
});
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const body = yield response.json();
|
|
188
|
+
if (!Array.isArray(body)) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
return body
|
|
192
|
+
.map(toEventTriggerConfig)
|
|
193
|
+
.filter((config) => config !== null);
|
|
194
|
+
}
|
|
195
|
+
catch (_a) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
finally {
|
|
199
|
+
clearTimeout(timer);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Normalises the CLI argument into a base URL. Accepts either a bare domain
|
|
205
|
+
* (`example.org`, assumed https) or a full URL, and strips any trailing slash.
|
|
206
|
+
*/
|
|
207
|
+
function resolveBaseUrl(input) {
|
|
208
|
+
const withProtocol = /^https?:\/\//i.test(input) ? input : `https://${input}`;
|
|
209
|
+
return withProtocol.replace(/\/+$/, '');
|
|
210
|
+
}
|
|
211
|
+
function describeStatus(status) {
|
|
212
|
+
return status === 'error' ? 'no response' : `HTTP ${status}`;
|
|
213
|
+
}
|
|
214
|
+
function endpointLabel(check) {
|
|
215
|
+
var _a;
|
|
216
|
+
const shown = (_a = check.label) !== null && _a !== void 0 ? _a : check.path;
|
|
217
|
+
const suffix = check.label ? (0, colors_1.dim)(` → ${check.path}`) : '';
|
|
218
|
+
return `${check.method} ${shown}${suffix}`;
|
|
219
|
+
}
|
|
220
|
+
function line(ok, label, detail) {
|
|
221
|
+
const mark = ok ? (0, colors_1.green)('✓') : (0, colors_1.red)('✗');
|
|
222
|
+
return ` ${mark} ${label} ${(0, colors_1.dim)(`(${detail})`)}`;
|
|
223
|
+
}
|
|
224
|
+
function securedDetail(status) {
|
|
225
|
+
if (status === 401 || status === 403) {
|
|
226
|
+
return `${describeStatus(status)} — auth required`;
|
|
227
|
+
}
|
|
228
|
+
if (status === 404) {
|
|
229
|
+
return `${describeStatus(status)} — not implemented`;
|
|
230
|
+
}
|
|
231
|
+
if (status === 'error') {
|
|
232
|
+
return `${describeStatus(status)} — request failed`;
|
|
233
|
+
}
|
|
234
|
+
return `${describeStatus(status)} — INSECURE: processed without a token`;
|
|
235
|
+
}
|
|
236
|
+
function runVerifyEndpoints() {
|
|
237
|
+
return __awaiter(this, arguments, void 0, function* (target = DEFAULT_TARGET_URL) {
|
|
238
|
+
const baseUrl = resolveBaseUrl(target);
|
|
239
|
+
console.log((0, colors_1.bold)(`Verifying country config endpoints at ${baseUrl}\n`));
|
|
240
|
+
let failures = 0;
|
|
241
|
+
console.log((0, colors_1.bold)('Required public endpoints (must respond 2xx):'));
|
|
242
|
+
for (const check of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
243
|
+
const status = yield requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
244
|
+
const ok = isSuccess(status);
|
|
245
|
+
if (!ok) {
|
|
246
|
+
failures++;
|
|
247
|
+
}
|
|
248
|
+
const detail = status === 404
|
|
249
|
+
? `${describeStatus(status)} — missing`
|
|
250
|
+
: ok
|
|
251
|
+
? describeStatus(status)
|
|
252
|
+
: `${describeStatus(status)} — unexpected`;
|
|
253
|
+
console.log(line(ok, endpointLabel(check), detail));
|
|
254
|
+
}
|
|
255
|
+
// `/fonts/{filename}` is public but the filename is country-specific and
|
|
256
|
+
// cannot be automated, so we probe a made-up name. A registered public route
|
|
257
|
+
// returns 404 (file not found) or 200 (if the name happens to exist); either
|
|
258
|
+
// is acceptable. 401/403 would mean the route was wrongly put behind auth.
|
|
259
|
+
{
|
|
260
|
+
const path = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
261
|
+
const status = yield requestStatus(`${baseUrl}${path}`, 'GET');
|
|
262
|
+
const ok = status === 200 || status === 404;
|
|
263
|
+
if (!ok) {
|
|
264
|
+
failures++;
|
|
265
|
+
}
|
|
266
|
+
let detail;
|
|
267
|
+
if (status === 404) {
|
|
268
|
+
detail = `${describeStatus(status)} — reachable (made-up filename)`;
|
|
269
|
+
}
|
|
270
|
+
else if (status === 200) {
|
|
271
|
+
detail = describeStatus(status);
|
|
272
|
+
}
|
|
273
|
+
else if (status === 401 || status === 403) {
|
|
274
|
+
detail = `${describeStatus(status)} — must be public`;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
detail = `${describeStatus(status)} — unexpected`;
|
|
278
|
+
}
|
|
279
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, colors_1.dim)(` → ${path}`)}`, detail));
|
|
280
|
+
}
|
|
281
|
+
console.log();
|
|
282
|
+
console.log((0, colors_1.bold)('Secured endpoints (must be absent or require auth):'));
|
|
283
|
+
for (const check of SECURED_ENDPOINTS) {
|
|
284
|
+
const status = yield requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
285
|
+
const ok = requiresAuthOrAbsent(status);
|
|
286
|
+
if (!ok) {
|
|
287
|
+
failures++;
|
|
288
|
+
}
|
|
289
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
290
|
+
}
|
|
291
|
+
console.log();
|
|
292
|
+
console.log((0, colors_1.bold)('Event action triggers (must be absent or require auth):'));
|
|
293
|
+
const events = yield fetchEventConfigs(baseUrl);
|
|
294
|
+
if (!events) {
|
|
295
|
+
console.log(' ' +
|
|
296
|
+
(0, colors_1.yellow)('Could not read /config/events; falling back to route-pattern checks.'));
|
|
297
|
+
for (const check of FALLBACK_EVENT_TRIGGERS) {
|
|
298
|
+
const status = yield requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
299
|
+
const ok = requiresAuthOrAbsent(status);
|
|
300
|
+
if (!ok) {
|
|
301
|
+
failures++;
|
|
302
|
+
}
|
|
303
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else if (events.length === 0) {
|
|
307
|
+
console.log(' ' + (0, colors_1.yellow)('No events configured.'));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
for (const event of events) {
|
|
311
|
+
// Fall back to a made-up action when an event declares none, so the
|
|
312
|
+
// route is still exercised.
|
|
313
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
314
|
+
const failed = [];
|
|
315
|
+
for (const action of actions) {
|
|
316
|
+
const status = yield requestStatus(`${baseUrl}/trigger/events/${event.id}/actions/${action}`, 'POST');
|
|
317
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
318
|
+
failed.push({ action, status });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
322
|
+
if (failed.length === 0) {
|
|
323
|
+
console.log(line(true, pattern, `${actions.length} action(s) — all require auth`));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
for (const failure of failed) {
|
|
327
|
+
failures++;
|
|
328
|
+
console.log(line(false, `POST /trigger/events/${event.id}/actions/${failure.action}`, securedDetail(failure.status)));
|
|
329
|
+
}
|
|
330
|
+
const okCount = actions.length - failed.length;
|
|
331
|
+
if (okCount > 0) {
|
|
332
|
+
console.log(line(true, pattern, `${okCount} other action(s) require auth`));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
console.log();
|
|
338
|
+
if (failures > 0) {
|
|
339
|
+
console.log((0, colors_1.red)((0, colors_1.bold)(`✗ ${failures} check(s) failed.`)) +
|
|
340
|
+
(0, colors_1.yellow)(' See the lines marked ✗ above.'));
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
343
|
+
console.log((0, colors_1.green)((0, colors_1.bold)('✓ All endpoint checks passed.')));
|
|
344
|
+
});
|
|
345
|
+
}
|
|
Binary file
|