@digitraffic/common 2023.12.15-1 → 2024.1.19-1
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/dist/aws/infra/api/handler-factory.d.ts +2 -2
- package/dist/aws/infra/api/handler-factory.js +4 -9
- package/dist/aws/infra/api/integration.d.ts +1 -1
- package/dist/aws/infra/api/integration.js +9 -13
- package/dist/aws/infra/api/response.d.ts +2 -3
- package/dist/aws/infra/api/response.js +25 -30
- package/dist/aws/infra/api/responses.d.ts +2 -3
- package/dist/aws/infra/api/responses.js +25 -31
- package/dist/aws/infra/api/static-integration.d.ts +1 -1
- package/dist/aws/infra/api/static-integration.js +7 -11
- package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.js +7 -11
- package/dist/aws/infra/canaries/canary-keys.js +3 -6
- package/dist/aws/infra/canaries/canary-parameters.js +1 -2
- package/dist/aws/infra/canaries/canary-role.js +8 -12
- package/dist/aws/infra/canaries/canary.d.ts +2 -2
- package/dist/aws/infra/canaries/canary.js +9 -13
- package/dist/aws/infra/canaries/database-canary.d.ts +3 -3
- package/dist/aws/infra/canaries/database-canary.js +8 -12
- package/dist/aws/infra/canaries/database-checker.d.ts +1 -1
- package/dist/aws/infra/canaries/database-checker.js +10 -14
- package/dist/aws/infra/canaries/url-canary.d.ts +4 -4
- package/dist/aws/infra/canaries/url-canary.js +8 -12
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.js +33 -40
- package/dist/aws/infra/documentation.js +8 -16
- package/dist/aws/infra/import-util.js +10 -18
- package/dist/aws/infra/scheduler.js +10 -14
- package/dist/aws/infra/security-rule.js +4 -8
- package/dist/aws/infra/sqs-integration.d.ts +1 -2
- package/dist/aws/infra/sqs-integration.js +11 -15
- package/dist/aws/infra/sqs-queue.d.ts +1 -1
- package/dist/aws/infra/sqs-queue.js +51 -50
- package/dist/aws/infra/stack/lambda-configs.d.ts +2 -2
- package/dist/aws/infra/stack/lambda-configs.js +14 -20
- package/dist/aws/infra/stack/monitoredfunction.d.ts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.js +19 -27
- package/dist/aws/infra/stack/parameters.d.ts +1 -1
- package/dist/aws/infra/stack/parameters.js +5 -10
- package/dist/aws/infra/stack/rest_apis.d.ts +3 -3
- package/dist/aws/infra/stack/rest_apis.js +41 -54
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
- package/dist/aws/infra/stack/stack-checking-aspect.js +28 -39
- package/dist/aws/infra/stack/stack.d.ts +5 -6
- package/dist/aws/infra/stack/stack.js +16 -20
- package/dist/aws/infra/stack/subscription.d.ts +2 -2
- package/dist/aws/infra/stack/subscription.js +5 -10
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-dns-stack.js +25 -29
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-proxy-stack.js +23 -27
- package/dist/aws/infra/stacks/db-stack.d.ts +3 -4
- package/dist/aws/infra/stacks/db-stack.js +30 -34
- package/dist/aws/infra/stacks/intra-stack-configuration.js +1 -2
- package/dist/aws/infra/stacks/network-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/network-stack.js +15 -19
- package/dist/aws/infra/usage-plans.js +2 -7
- package/dist/aws/runtime/apikey.js +3 -7
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +1 -1
- package/dist/aws/runtime/digitraffic-integration-response.js +7 -11
- package/dist/aws/runtime/dt-logger-default.d.ts +2 -2
- package/dist/aws/runtime/dt-logger-default.js +2 -5
- package/dist/aws/runtime/dt-logger.d.ts +1 -1
- package/dist/aws/runtime/dt-logger.js +3 -10
- package/dist/aws/runtime/environment.js +3 -7
- package/dist/aws/runtime/messaging.js +1 -5
- package/dist/aws/runtime/s3.js +3 -7
- package/dist/aws/runtime/secrets/dbsecret.d.ts +1 -1
- package/dist/aws/runtime/secrets/dbsecret.js +5 -9
- package/dist/aws/runtime/secrets/proxy-holder.js +12 -16
- package/dist/aws/runtime/secrets/rds-holder.js +12 -16
- package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.js +9 -13
- package/dist/aws/runtime/secrets/secret.js +7 -11
- package/dist/aws/types/errors.js +5 -9
- package/dist/aws/types/lambda-response.js +3 -10
- package/dist/aws/types/mediatypes.js +2 -5
- package/dist/aws/types/model-with-reference.js +1 -2
- package/dist/aws/types/proxytypes.js +1 -2
- package/dist/aws/types/tags.js +2 -5
- package/dist/database/cached.d.ts +1 -1
- package/dist/database/cached.js +8 -14
- package/dist/database/database.js +14 -21
- package/dist/database/last-updated.d.ts +1 -1
- package/dist/database/last-updated.js +8 -17
- package/dist/database/models.js +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.js +3 -9
- package/dist/marine/rtz.js +1 -2
- package/dist/test/asserter.js +1 -5
- package/dist/test/db-testutils.d.ts +1 -1
- package/dist/test/db-testutils.js +8 -13
- package/dist/test/httpserver.d.ts +1 -1
- package/dist/test/httpserver.js +19 -18
- package/dist/test/secrets-manager.js +9 -35
- package/dist/test/testutils.js +8 -19
- package/dist/types/async-timeout-error.js +1 -5
- package/dist/types/aws-env.js +1 -2
- package/dist/types/either.js +1 -2
- package/dist/types/http-error.js +1 -5
- package/dist/types/input-error.js +1 -5
- package/dist/types/language.js +2 -5
- package/dist/types/nullable.d.ts +1 -1
- package/dist/types/nullable.js +1 -2
- package/dist/types/traffictype.js +2 -5
- package/dist/types/urn.js +1 -2
- package/dist/types/util-types.js +1 -2
- package/dist/types/validator.js +4 -9
- package/dist/utils/api-model.d.ts +1 -1
- package/dist/utils/api-model.js +17 -27
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/base64.js +2 -7
- package/dist/utils/date-utils.js +9 -16
- package/dist/utils/geojson-types.js +2 -7
- package/dist/utils/geometry.js +15 -48
- package/dist/utils/logging.d.ts +1 -1
- package/dist/utils/logging.js +8 -13
- package/dist/utils/retry.js +21 -26
- package/dist/utils/slack.js +7 -14
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +14 -29
- package/package.json +127 -41
- package/src/aws/infra/api/handler-factory.ts +3 -3
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/response.ts +3 -3
- package/src/aws/infra/api/responses.ts +4 -4
- package/src/aws/infra/api/static-integration.ts +2 -2
- package/src/aws/infra/canaries/canary-alarm.ts +1 -1
- package/src/aws/infra/canaries/canary.ts +3 -3
- package/src/aws/infra/canaries/database-canary.ts +3 -3
- package/src/aws/infra/canaries/database-checker.ts +6 -6
- package/src/aws/infra/canaries/url-canary.ts +6 -6
- package/src/aws/infra/canaries/url-checker.ts +8 -8
- package/src/aws/infra/sqs-integration.ts +1 -1
- package/src/aws/infra/sqs-queue.ts +29 -44
- package/src/aws/infra/stack/lambda-configs.ts +9 -9
- package/src/aws/infra/stack/monitoredfunction.ts +4 -4
- package/src/aws/infra/stack/parameters.ts +1 -1
- package/src/aws/infra/stack/rest_apis.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +20 -72
- package/src/aws/infra/stack/stack.ts +4 -5
- package/src/aws/infra/stack/subscription.ts +2 -2
- package/src/aws/infra/stacks/db-dns-stack.ts +4 -4
- package/src/aws/infra/stacks/db-proxy-stack.ts +5 -5
- package/src/aws/infra/stacks/db-stack.ts +5 -5
- package/src/aws/infra/stacks/network-stack.ts +3 -3
- package/src/aws/runtime/digitraffic-integration-response.ts +2 -2
- package/src/aws/runtime/dt-logger-default.ts +2 -2
- package/src/aws/runtime/secrets/dbsecret.ts +1 -1
- package/src/aws/runtime/secrets/proxy-holder.ts +4 -4
- package/src/aws/runtime/secrets/rds-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret.ts +2 -2
- package/src/database/cached.ts +1 -1
- package/src/database/database.ts +3 -3
- package/src/database/last-updated.ts +1 -1
- package/src/index.ts +2 -0
- package/src/test/db-testutils.ts +2 -2
- package/src/test/httpserver.ts +13 -7
- package/src/test/secrets-manager.ts +2 -2
- package/src/types/nullable.ts +1 -1
- package/src/utils/api-model.ts +1 -1
- package/src/utils/geometry.ts +5 -3
- package/src/utils/logging.ts +2 -2
- package/src/utils/retry.ts +3 -3
- package/src/utils/slack.ts +2 -2
- package/src/utils/utils.ts +3 -3
@@ -1,28 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const
|
6
|
-
const utils_1 = require("../../../utils/utils");
|
7
|
-
const database_1 = require("../../../database/database");
|
8
|
-
const RDS_PROXY_SECRET_KEYS = Object.values(dbsecret_1.RdsProxySecretKey);
|
1
|
+
import { SecretHolder } from "./secret-holder.js";
|
2
|
+
import { RdsProxySecretKey } from "./dbsecret.js";
|
3
|
+
import { getEnvVariable } from "../../../utils/utils.js";
|
4
|
+
import { DatabaseEnvironmentKeys } from "../../../database/database.js";
|
5
|
+
const RDS_PROXY_SECRET_KEYS = Object.values(RdsProxySecretKey);
|
9
6
|
/**
|
10
7
|
* Holds credentials for RDS Proxy access.
|
11
8
|
*/
|
12
|
-
class ProxyHolder {
|
9
|
+
export class ProxyHolder {
|
13
10
|
constructor(secretId) {
|
14
|
-
this.secretHolder = new
|
11
|
+
this.secretHolder = new SecretHolder(secretId, "", RDS_PROXY_SECRET_KEYS);
|
15
12
|
}
|
16
13
|
static create() {
|
17
|
-
return new ProxyHolder(
|
14
|
+
return new ProxyHolder(getEnvVariable("SECRET_ID"));
|
18
15
|
}
|
19
16
|
async setCredentials() {
|
20
17
|
const secret = await this.secretHolder.get();
|
21
|
-
process.env[
|
22
|
-
process.env[
|
23
|
-
process.env[
|
24
|
-
process.env[
|
18
|
+
process.env[DatabaseEnvironmentKeys.DB_USER] = secret.username;
|
19
|
+
process.env[DatabaseEnvironmentKeys.DB_PASS] = secret.password;
|
20
|
+
process.env[DatabaseEnvironmentKeys.DB_URI] = secret.proxy_host;
|
21
|
+
process.env[DatabaseEnvironmentKeys.DB_RO_URI] = secret.proxy_ro_host;
|
25
22
|
}
|
26
23
|
}
|
27
|
-
exports.ProxyHolder = ProxyHolder;
|
28
24
|
//# sourceMappingURL=proxy-holder.js.map
|
@@ -1,28 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const
|
6
|
-
const utils_1 = require("../../../utils/utils");
|
7
|
-
const database_1 = require("../../../database/database");
|
8
|
-
const RDS_SECRET_KEYS = Object.values(dbsecret_1.RdsSecretKey);
|
1
|
+
import { SecretHolder } from "./secret-holder.js";
|
2
|
+
import { RdsSecretKey } from "./dbsecret.js";
|
3
|
+
import { getEnvVariable } from "../../../utils/utils.js";
|
4
|
+
import { DatabaseEnvironmentKeys } from "../../../database/database.js";
|
5
|
+
const RDS_SECRET_KEYS = Object.values(RdsSecretKey);
|
9
6
|
/**
|
10
7
|
* Holds credentials for RDS access.
|
11
8
|
*/
|
12
|
-
class RdsHolder {
|
9
|
+
export class RdsHolder {
|
13
10
|
constructor(secretId) {
|
14
|
-
this.secretHolder = new
|
11
|
+
this.secretHolder = new SecretHolder(secretId, "", RDS_SECRET_KEYS);
|
15
12
|
}
|
16
13
|
static create() {
|
17
|
-
return new RdsHolder(
|
14
|
+
return new RdsHolder(getEnvVariable("SECRET_ID"));
|
18
15
|
}
|
19
16
|
async setCredentials() {
|
20
17
|
const secret = await this.secretHolder.get();
|
21
|
-
process.env[
|
22
|
-
process.env[
|
23
|
-
process.env[
|
24
|
-
process.env[
|
18
|
+
process.env[DatabaseEnvironmentKeys.DB_USER] = secret.username;
|
19
|
+
process.env[DatabaseEnvironmentKeys.DB_PASS] = secret.password;
|
20
|
+
process.env[DatabaseEnvironmentKeys.DB_URI] = secret.host;
|
21
|
+
process.env[DatabaseEnvironmentKeys.DB_RO_URI] = secret.ro_host;
|
25
22
|
}
|
26
23
|
}
|
27
|
-
exports.RdsHolder = RdsHolder;
|
28
24
|
//# sourceMappingURL=rds-holder.js.map
|
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const dbsecret_1 = require("./dbsecret");
|
6
|
-
const utils_1 = require("../../../utils/utils");
|
7
|
-
const dt_logger_default_1 = require("../dt-logger-default");
|
1
|
+
import { getSecret } from "./secret.js";
|
2
|
+
import { checkExpectedSecretKeys } from "./dbsecret.js";
|
3
|
+
import { getEnvVariable } from "../../../utils/utils.js";
|
4
|
+
import { logger } from "../dt-logger-default.js";
|
8
5
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
9
6
|
const NodeTtl = require("node-ttl");
|
10
7
|
const DEFAULT_PREFIX = "";
|
@@ -24,7 +21,7 @@ const DEFAULT_CONFIGURATION = {
|
|
24
21
|
* setting the region with utils setSecretOverideAwsRegionEnv method.
|
25
22
|
*
|
26
23
|
*/
|
27
|
-
class SecretHolder {
|
24
|
+
export class SecretHolder {
|
28
25
|
constructor(secretId, prefix = "", expectedKeys = [], configuration = DEFAULT_CONFIGURATION) {
|
29
26
|
this.secretId = secretId;
|
30
27
|
this.prefix = prefix;
|
@@ -33,8 +30,8 @@ class SecretHolder {
|
|
33
30
|
this.secretCache = new NodeTtl(configuration);
|
34
31
|
}
|
35
32
|
async initSecret() {
|
36
|
-
const secretValue = await
|
37
|
-
|
33
|
+
const secretValue = await getSecret(this.secretId);
|
34
|
+
logger.info({
|
38
35
|
method: "SecretHolder.initSecret",
|
39
36
|
message: "Refreshing secret " + this.secretId,
|
40
37
|
});
|
@@ -42,7 +39,7 @@ class SecretHolder {
|
|
42
39
|
this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
|
43
40
|
}
|
44
41
|
static create(prefix = DEFAULT_PREFIX, expectedKeys = []) {
|
45
|
-
return new SecretHolder(
|
42
|
+
return new SecretHolder(getEnvVariable("SECRET_ID"), prefix, expectedKeys);
|
46
43
|
}
|
47
44
|
async get() {
|
48
45
|
const secret = await this.getSecret();
|
@@ -50,7 +47,7 @@ class SecretHolder {
|
|
50
47
|
? secret
|
51
48
|
: this.parseSecret(secret, `${this.prefix}.`);
|
52
49
|
if (this.expectedKeys.length > 0) {
|
53
|
-
|
50
|
+
checkExpectedSecretKeys(this.expectedKeys, parsedSecret);
|
54
51
|
}
|
55
52
|
return parsedSecret;
|
56
53
|
}
|
@@ -74,5 +71,4 @@ class SecretHolder {
|
|
74
71
|
return secret ?? this.secretCache.get(DEFAULT_SECRET_KEY);
|
75
72
|
}
|
76
73
|
}
|
77
|
-
exports.SecretHolder = SecretHolder;
|
78
74
|
//# sourceMappingURL=secret-holder.js.map
|
@@ -1,22 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const aws_sdk_1 = require("aws-sdk");
|
5
|
-
const utils_1 = require("../../../utils/utils");
|
6
|
-
const environment_1 = require("../environment");
|
1
|
+
import { SecretsManager } from "aws-sdk";
|
2
|
+
import { getEnvVariable, getEnvVariableOrElse } from "../../../utils/utils.js";
|
3
|
+
import { EnvKeys } from "../environment.js";
|
7
4
|
// SECRET_OVERRIDE_AWS_REGION might not have been set before import of
|
8
5
|
// secret, so we need to lazy initialize SecretsManager
|
9
6
|
let smClient;
|
10
7
|
function getSmClient() {
|
11
8
|
if (!smClient) {
|
12
|
-
smClient = new
|
13
|
-
region:
|
14
|
-
|
9
|
+
smClient = new SecretsManager({
|
10
|
+
region: getEnvVariableOrElse(EnvKeys.SECRET_OVERRIDE_AWS_REGION, // this is override secret region
|
11
|
+
getEnvVariable(EnvKeys.AWS_REGION)),
|
15
12
|
});
|
16
13
|
}
|
17
14
|
return smClient;
|
18
15
|
}
|
19
|
-
async function getSecret(secretId, prefix = "") {
|
16
|
+
export async function getSecret(secretId, prefix = "") {
|
20
17
|
const secretObj = await getSmClient()
|
21
18
|
.getSecretValue({
|
22
19
|
SecretId: secretId,
|
@@ -31,7 +28,6 @@ async function getSecret(secretId, prefix = "") {
|
|
31
28
|
}
|
32
29
|
return parseSecret(secret, `${prefix}.`);
|
33
30
|
}
|
34
|
-
exports.getSecret = getSecret;
|
35
31
|
function parseSecret(secret, prefix) {
|
36
32
|
const parsed = {};
|
37
33
|
const skip = prefix.length;
|
package/dist/aws/types/errors.js
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ValidationError = exports.BAD_REQUEST_MESSAGE = exports.OK_MESSAGE = exports.ERROR_MESSAGE = exports.NOT_FOUND_MESSAGE = void 0;
|
4
1
|
// DEPRECATED, remove these!
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
class ValidationError extends Error {
|
2
|
+
export const NOT_FOUND_MESSAGE = "NOT_FOUND";
|
3
|
+
export const ERROR_MESSAGE = "ERROR";
|
4
|
+
export const OK_MESSAGE = "OK";
|
5
|
+
export const BAD_REQUEST_MESSAGE = "BAD REQUEST";
|
6
|
+
export class ValidationError extends Error {
|
10
7
|
constructor(statusCode, body) {
|
11
8
|
super(body);
|
12
9
|
this.statusCode = statusCode;
|
13
10
|
}
|
14
11
|
}
|
15
|
-
exports.ValidationError = ValidationError;
|
16
12
|
//# sourceMappingURL=errors.js.map
|
@@ -1,17 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.LambdaResponse = void 0;
|
7
|
-
const etag_1 = __importDefault(require("etag"));
|
8
|
-
class LambdaResponse {
|
1
|
+
import etag from "etag";
|
2
|
+
export class LambdaResponse {
|
9
3
|
constructor(status, body, fileName, timestamp) {
|
10
4
|
this.status = status;
|
11
5
|
this.body = body;
|
12
6
|
this.fileName = fileName;
|
13
7
|
this.timestamp = timestamp?.toUTCString();
|
14
|
-
this.etag = (
|
8
|
+
this.etag = etag(body); // create strong etag by default
|
15
9
|
}
|
16
10
|
withTimestamp(timestamp) {
|
17
11
|
return new LambdaResponse(this.status, this.body, this.fileName, timestamp);
|
@@ -65,7 +59,6 @@ class LambdaResponse {
|
|
65
59
|
return new LambdaResponse(status, base64Body, fileName);
|
66
60
|
}
|
67
61
|
}
|
68
|
-
exports.LambdaResponse = LambdaResponse;
|
69
62
|
function toBase64(body) {
|
70
63
|
return Buffer.from(body).toString("base64");
|
71
64
|
}
|
@@ -1,8 +1,5 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.MediaType = void 0;
|
4
1
|
// charset=UTF-8 is deprecated but mobile applications sometimes needs it
|
5
|
-
var MediaType;
|
2
|
+
export var MediaType;
|
6
3
|
(function (MediaType) {
|
7
4
|
MediaType["APPLICATION_JSON"] = "application/json";
|
8
5
|
MediaType["APPLICATION_XML"] = "application/xml";
|
@@ -13,5 +10,5 @@ var MediaType;
|
|
13
10
|
MediaType["TEXT_HTML"] = "text/html";
|
14
11
|
MediaType["TEXT_CSV"] = "text/csv";
|
15
12
|
MediaType["APPLICATION_JSON_UTF8"] = "application/json;charset=UTF-8";
|
16
|
-
})(MediaType
|
13
|
+
})(MediaType || (MediaType = {}));
|
17
14
|
//# sourceMappingURL=mediatypes.js.map
|
package/dist/aws/types/tags.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DATA_V1_TAGS = exports.BETA_TAGS = void 0;
|
4
1
|
// DEPRECATED! This must be replaced with new application specific tags
|
5
|
-
|
6
|
-
|
2
|
+
export const BETA_TAGS = ['Beta'];
|
3
|
+
export const DATA_V1_TAGS = ['Data v1'];
|
7
4
|
//# sourceMappingURL=tags.js.map
|
package/dist/database/cached.js
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.getFromCache = exports.getJsonFromCache = exports.updateCachedJson = exports.JSON_CACHE_KEY = void 0;
|
4
|
-
const pg_promise_1 = require("pg-promise");
|
5
|
-
const PS_UPDATE_CACHE_VALUE = new pg_promise_1.PreparedStatement({
|
1
|
+
import { PreparedStatement } from "pg-promise";
|
2
|
+
const PS_UPDATE_CACHE_VALUE = new PreparedStatement({
|
6
3
|
name: "update-cache-value",
|
7
4
|
text: `insert into cached_json(cache_id, content, last_updated)
|
8
5
|
values ($1, $2, $3)
|
9
6
|
on conflict(cache_id) do
|
10
7
|
update set content = $2, last_updated = $3`,
|
11
8
|
});
|
12
|
-
const PS_GET_CACHE_VALUE = new
|
9
|
+
const PS_GET_CACHE_VALUE = new PreparedStatement({
|
13
10
|
name: "get-cache-value",
|
14
11
|
text: "select content, last_updated, modified from cached_json where cache_id = $1",
|
15
12
|
});
|
16
|
-
var JSON_CACHE_KEY;
|
13
|
+
export var JSON_CACHE_KEY;
|
17
14
|
(function (JSON_CACHE_KEY) {
|
18
15
|
JSON_CACHE_KEY["NAUTICAL_WARNINGS_ACTIVE"] = "nautical-warnings-active";
|
19
16
|
JSON_CACHE_KEY["NAUTICAL_WARNINGS_ARCHIVED"] = "nautical-warnings-archived";
|
20
|
-
})(JSON_CACHE_KEY
|
17
|
+
})(JSON_CACHE_KEY || (JSON_CACHE_KEY = {}));
|
21
18
|
/**
|
22
19
|
*
|
23
20
|
* @param db
|
@@ -25,22 +22,19 @@ var JSON_CACHE_KEY;
|
|
25
22
|
* @param value
|
26
23
|
* @param lastUpdated time when data was created or updated
|
27
24
|
*/
|
28
|
-
async function updateCachedJson(db, cacheKey, value, lastUpdated) {
|
25
|
+
export async function updateCachedJson(db, cacheKey, value, lastUpdated) {
|
29
26
|
await db.none(PS_UPDATE_CACHE_VALUE, [cacheKey, value, lastUpdated]);
|
30
27
|
}
|
31
|
-
|
32
|
-
function getJsonFromCache(db, cacheKey) {
|
28
|
+
export function getJsonFromCache(db, cacheKey) {
|
33
29
|
return db
|
34
30
|
.oneOrNone(PS_GET_CACHE_VALUE, [cacheKey])
|
35
31
|
.then((value) => value?.content ?? undefined);
|
36
32
|
}
|
37
|
-
|
38
|
-
async function getFromCache(db, cacheKey) {
|
33
|
+
export async function getFromCache(db, cacheKey) {
|
39
34
|
return db
|
40
35
|
.oneOrNone(PS_GET_CACHE_VALUE, [cacheKey])
|
41
36
|
.then((result) => {
|
42
37
|
return result ?? undefined;
|
43
38
|
});
|
44
39
|
}
|
45
|
-
exports.getFromCache = getFromCache;
|
46
40
|
//# sourceMappingURL=cached.js.map
|
@@ -1,17 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
|
6
|
-
const logging_1 = require("../utils/logging");
|
7
|
-
var DatabaseEnvironmentKeys;
|
1
|
+
import { getEnvVariable, getEnvVariableOrElse } from "../utils/utils.js";
|
2
|
+
import { logger } from "../aws/runtime/dt-logger-default.js";
|
3
|
+
import { logException } from "../utils/logging.js";
|
4
|
+
export var DatabaseEnvironmentKeys;
|
8
5
|
(function (DatabaseEnvironmentKeys) {
|
9
6
|
DatabaseEnvironmentKeys["DB_USER"] = "DB_USER";
|
10
7
|
DatabaseEnvironmentKeys["DB_PASS"] = "DB_PASS";
|
11
8
|
DatabaseEnvironmentKeys["DB_URI"] = "DB_URI";
|
12
9
|
DatabaseEnvironmentKeys["DB_RO_URI"] = "DB_RO_URI";
|
13
10
|
DatabaseEnvironmentKeys["DB_APPLICATION"] = "DB_APPLICATION";
|
14
|
-
})(DatabaseEnvironmentKeys
|
11
|
+
})(DatabaseEnvironmentKeys || (DatabaseEnvironmentKeys = {}));
|
15
12
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
16
13
|
const pgp = require("pg-promise")();
|
17
14
|
// convert numeric types to number instead of string
|
@@ -39,30 +36,26 @@ pgp.pg.types.setTypeParser(pgp.pg.types.builtins.NUMERIC, (value) => {
|
|
39
36
|
* @param url Connection URL
|
40
37
|
* @param options pg-promise options
|
41
38
|
*/
|
42
|
-
function initDbConnection(username, password, applicationName, url, options) {
|
39
|
+
export function initDbConnection(username, password, applicationName, url, options) {
|
43
40
|
const finalUrl = `postgresql://${username}:${password}@${url}?application_name=${applicationName}`;
|
44
41
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
45
42
|
return pgp(finalUrl, options);
|
46
43
|
}
|
47
|
-
|
48
|
-
function inTransaction(fn) {
|
44
|
+
export function inTransaction(fn) {
|
49
45
|
return inDatabase((db) => db.tx((t) => fn(t)));
|
50
46
|
}
|
51
|
-
|
52
|
-
function inDatabase(fn) {
|
47
|
+
export function inDatabase(fn) {
|
53
48
|
return doInDatabase(false, fn);
|
54
49
|
}
|
55
|
-
|
56
|
-
function inDatabaseReadonly(fn) {
|
50
|
+
export function inDatabaseReadonly(fn) {
|
57
51
|
return doInDatabase(true, fn);
|
58
52
|
}
|
59
|
-
exports.inDatabaseReadonly = inDatabaseReadonly;
|
60
53
|
async function doInDatabase(readonly, fn) {
|
61
|
-
const db_application =
|
54
|
+
const db_application = getEnvVariableOrElse(DatabaseEnvironmentKeys.DB_APPLICATION, "unknown-cdk-application");
|
62
55
|
const db_uri = readonly
|
63
|
-
?
|
64
|
-
:
|
65
|
-
const db = initDbConnection(
|
56
|
+
? getEnvVariable(DatabaseEnvironmentKeys.DB_RO_URI)
|
57
|
+
: getEnvVariable(DatabaseEnvironmentKeys.DB_URI);
|
58
|
+
const db = initDbConnection(getEnvVariable(DatabaseEnvironmentKeys.DB_USER), getEnvVariable(DatabaseEnvironmentKeys.DB_PASS), db_application, db_uri);
|
66
59
|
try {
|
67
60
|
// deallocate all prepared statements to allow for connection pooling
|
68
61
|
// DISCARD instead of DEALLOCATE as it didn't always clean all prepared statements
|
@@ -70,7 +63,7 @@ async function doInDatabase(readonly, fn) {
|
|
70
63
|
return await fn(db);
|
71
64
|
}
|
72
65
|
catch (e) {
|
73
|
-
|
66
|
+
logException(logger, e);
|
74
67
|
throw e;
|
75
68
|
}
|
76
69
|
finally {
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.updateUpdatedTimestamp = exports.getUpdatedTimestamp = exports.updateLastUpdatedWithSubtype = exports.updateLastUpdated = exports.getLastUpdatedWithSubtype = exports.getLastUpdated = exports.DataType = void 0;
|
4
|
-
var DataType;
|
1
|
+
export var DataType;
|
5
2
|
(function (DataType) {
|
6
3
|
DataType["VS_DATEX2"] = "VS_DATEX2";
|
7
4
|
DataType["COUNTING_SITES_DATA"] = "COUNTING_SITES_DATA";
|
@@ -10,47 +7,41 @@ var DataType;
|
|
10
7
|
DataType["MAINTENANCE_TRACKING_DATA_CHECKED"] = "MAINTENANCE_TRACKING_DATA_CHECKED";
|
11
8
|
DataType["PERMIT_DATA"] = "PERMIT_DATA";
|
12
9
|
DataType["PERMIT_DATA_CHECK"] = "PERMIT_DATA_CHECK";
|
13
|
-
})(DataType
|
10
|
+
})(DataType || (DataType = {}));
|
14
11
|
const UNSET_SUBTYPE = "-";
|
15
|
-
function getLastUpdated(db, datatype) {
|
12
|
+
export function getLastUpdated(db, datatype) {
|
16
13
|
return db.oneOrNone("select updated from data_updated where data_type=$(datatype) and subtype=$(subtype)", {
|
17
14
|
datatype: datatype,
|
18
15
|
subtype: UNSET_SUBTYPE,
|
19
16
|
}, (x) => x?.updated ?? null);
|
20
17
|
}
|
21
|
-
|
22
|
-
function getLastUpdatedWithSubtype(db, datatype, subtype) {
|
18
|
+
export function getLastUpdatedWithSubtype(db, datatype, subtype) {
|
23
19
|
return db.oneOrNone("SELECT updated FROM data_updated WHERE data_type=$(datatype) AND subtype=$(subtype)", {
|
24
20
|
datatype: datatype,
|
25
21
|
subtype: subtype,
|
26
22
|
}, (x) => x?.updated ?? null);
|
27
23
|
}
|
28
|
-
|
29
|
-
function updateLastUpdated(db, datatype, updated) {
|
24
|
+
export function updateLastUpdated(db, datatype, updated) {
|
30
25
|
return db.none(`insert into data_updated(id, data_type, updated)
|
31
26
|
values(nextval('seq_data_updated'), $(datatype), $(updated))
|
32
27
|
on conflict (data_type, subtype)
|
33
28
|
do update set updated = $(updated)`, { updated, datatype });
|
34
29
|
}
|
35
|
-
|
36
|
-
function updateLastUpdatedWithSubtype(db, datatype, subtype, updated) {
|
30
|
+
export function updateLastUpdatedWithSubtype(db, datatype, subtype, updated) {
|
37
31
|
return db.none(`insert into data_updated(id, data_type, subtype, updated)
|
38
32
|
values(nextval('seq_data_updated'), $(datatype), $(subtype), $(updated))
|
39
33
|
on conflict (data_type, subtype)
|
40
34
|
do update set updated = $(updated)`, { updated, subtype, datatype });
|
41
35
|
}
|
42
|
-
|
43
|
-
function getUpdatedTimestamp(db, datatype) {
|
36
|
+
export function getUpdatedTimestamp(db, datatype) {
|
44
37
|
return db.oneOrNone("select updated_time as updated from updated_timestamp where updated_name=$(datatype)", {
|
45
38
|
datatype: datatype,
|
46
39
|
}, (x) => x?.updated ?? null);
|
47
40
|
}
|
48
|
-
|
49
|
-
function updateUpdatedTimestamp(db, datatype, date, by = "") {
|
41
|
+
export function updateUpdatedTimestamp(db, datatype, date, by = "") {
|
50
42
|
return db.none(`insert into updated_timestamp(updated_name, updated_time, updated_by)
|
51
43
|
values($(datatype), $(date), $(by))
|
52
44
|
on conflict (updated_name)
|
53
45
|
do update set updated_time = $(date), updated_by = $(by)`, { date, datatype, by });
|
54
46
|
}
|
55
|
-
exports.updateUpdatedTimestamp = updateUpdatedTimestamp;
|
56
47
|
//# sourceMappingURL=last-updated.js.map
|
package/dist/database/models.js
CHANGED
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { DigitrafficStack } from "./aws/infra/stack/stack.js";
|
package/dist/index.js
ADDED
package/dist/marine/id_utils.js
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isValidLOCODE = exports.isValidMMSI = exports.isValidIMO = void 0;
|
4
|
-
function isValidIMO(imo) {
|
1
|
+
export function isValidIMO(imo) {
|
5
2
|
return imo >= 1000000 && imo <= 9999999 && imoChecksumIsValid(imo);
|
6
3
|
}
|
7
|
-
exports.isValidIMO = isValidIMO;
|
8
4
|
function imoChecksumIsValid(imo) {
|
9
5
|
const imoStr = imo.toString();
|
10
6
|
const imoDigit1 = Number(imoStr[0]);
|
@@ -21,13 +17,11 @@ function imoChecksumIsValid(imo) {
|
|
21
17
|
}
|
22
18
|
return checkResult;
|
23
19
|
}
|
24
|
-
function isValidMMSI(mmsi) {
|
20
|
+
export function isValidMMSI(mmsi) {
|
25
21
|
return mmsi >= 100000000 && mmsi <= 999999999;
|
26
22
|
}
|
27
|
-
exports.isValidMMSI = isValidMMSI;
|
28
23
|
const LocodePattern = /^FI[A-Z]{3}$/i;
|
29
|
-
function isValidLOCODE(locode) {
|
24
|
+
export function isValidLOCODE(locode) {
|
30
25
|
return LocodePattern.test(locode);
|
31
26
|
}
|
32
|
-
exports.isValidLOCODE = isValidLOCODE;
|
33
27
|
//# sourceMappingURL=id_utils.js.map
|
package/dist/marine/rtz.js
CHANGED
package/dist/test/asserter.js
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
"use strict";
|
2
1
|
/**
|
3
2
|
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
4
3
|
*/
|
5
|
-
|
6
|
-
exports.Asserter = void 0;
|
7
|
-
class Asserter {
|
4
|
+
export class Asserter {
|
8
5
|
static assertEquals(value, expected) {
|
9
6
|
if (value != expected) {
|
10
7
|
throw new Error(`Given value ${value} was not expected ${expected}`);
|
@@ -41,5 +38,4 @@ class Asserter {
|
|
41
38
|
expect(expected - value).toBeLessThanOrEqual(delta);
|
42
39
|
}
|
43
40
|
}
|
44
|
-
exports.Asserter = Asserter;
|
45
41
|
//# sourceMappingURL=asserter.js.map
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { DTDatabase } from "../database/database";
|
1
|
+
import { DTDatabase } from "../database/database.js";
|
2
2
|
export declare function assertCount(db: DTDatabase, sql: string, count: number): Promise<void>;
|
3
3
|
export declare function dbTestBase(fn: (db: DTDatabase) => void, truncateFn: (db: DTDatabase) => Promise<void>, dbUser: string, dbPass: string, dbUri: string): () => void;
|
@@ -1,23 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.dbTestBase = exports.assertCount = void 0;
|
4
|
-
const database_1 = require("../database/database");
|
5
|
-
async function assertCount(db, sql, count) {
|
1
|
+
import { DatabaseEnvironmentKeys, initDbConnection, } from "../database/database.js";
|
2
|
+
export async function assertCount(db, sql, count) {
|
6
3
|
await db.one(sql).then((x) => expect(x.count).toEqual(count));
|
7
4
|
}
|
8
|
-
|
9
|
-
function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri) {
|
5
|
+
export function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri) {
|
10
6
|
const theDbUri = process.env.DB_URI ?? dbUri;
|
11
7
|
console.log(`Test database URI: ${theDbUri}`);
|
12
8
|
return () => {
|
13
|
-
const db =
|
9
|
+
const db = initDbConnection(dbUser, dbPass, "test", theDbUri, {
|
14
10
|
noWarnings: true, // ignore duplicate connection warning for tests
|
15
11
|
});
|
16
12
|
beforeAll(async () => {
|
17
|
-
process.env[
|
18
|
-
process.env[
|
19
|
-
process.env[
|
20
|
-
process.env[
|
13
|
+
process.env[DatabaseEnvironmentKeys.DB_USER] = dbUser;
|
14
|
+
process.env[DatabaseEnvironmentKeys.DB_PASS] = dbPass;
|
15
|
+
process.env[DatabaseEnvironmentKeys.DB_URI] = theDbUri;
|
16
|
+
process.env[DatabaseEnvironmentKeys.DB_RO_URI] = theDbUri;
|
21
17
|
await truncateFn(db);
|
22
18
|
});
|
23
19
|
afterAll(async () => {
|
@@ -30,5 +26,4 @@ function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri) {
|
|
30
26
|
fn(db);
|
31
27
|
};
|
32
28
|
}
|
33
|
-
exports.dbTestBase = dbTestBase;
|
34
29
|
//# sourceMappingURL=db-testutils.js.map
|
@@ -11,7 +11,7 @@ export declare class TestHttpServer {
|
|
11
11
|
getCallCount(): number;
|
12
12
|
getRequestBody(callNumber: number): string;
|
13
13
|
listen(port: number, props: ListenProperties, debug?: boolean, statusCode?: number): void;
|
14
|
-
close():
|
14
|
+
close(): Promise<boolean>;
|
15
15
|
private debuglog;
|
16
16
|
}
|
17
17
|
export type ListenProperties = Record<string, (url?: string, data?: string) => string>;
|