@digitraffic/common 2023.1.18-2 → 2023.1.23-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws/infra/api/integration.d.ts +2 -1
- package/dist/aws/infra/api/integration.js +3 -2
- package/dist/aws/infra/api/response.d.ts +2 -1
- package/dist/aws/infra/api/response.js +13 -7
- package/dist/aws/infra/canaries/canary-alarm.js +11 -13
- package/dist/aws/infra/canaries/canary.js +2 -4
- package/dist/aws/infra/canaries/database-checker.js +4 -1
- package/dist/aws/infra/canaries/url-canary.js +1 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.js +24 -5
- package/dist/aws/infra/sqs-integration.d.ts +1 -3
- package/dist/aws/infra/sqs-integration.js +28 -32
- package/dist/aws/infra/sqs-queue.d.ts +0 -2
- package/dist/aws/infra/sqs-queue.js +31 -24
- package/dist/aws/infra/stack/lambda-configs.d.ts +2 -31
- package/dist/aws/infra/stack/lambda-configs.js +5 -38
- package/dist/aws/infra/stack/monitoredfunction.js +3 -1
- package/dist/aws/infra/stacks/db-stack.js +1 -1
- package/dist/aws/infra/stacks/network-stack.d.ts +2 -1
- package/dist/aws/infra/stacks/network-stack.js +4 -2
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +2 -2
- package/dist/aws/runtime/digitraffic-integration-response.js +6 -4
- package/dist/aws/runtime/secrets/dbsecret.d.ts +0 -39
- package/dist/aws/runtime/secrets/dbsecret.js +1 -71
- package/dist/aws/runtime/secrets/proxy-holder.js +5 -4
- package/dist/aws/runtime/secrets/rds-holder.js +5 -4
- package/dist/aws/runtime/secrets/secret-holder.d.ts +0 -4
- package/dist/aws/runtime/secrets/secret-holder.js +6 -12
- package/dist/aws/runtime/secrets/secret.d.ts +0 -6
- package/dist/aws/runtime/secrets/secret.js +8 -17
- package/dist/database/database.d.ts +7 -0
- package/dist/database/database.js +19 -8
- package/dist/test/db-testutils.js +4 -5
- package/package.json +1 -1
- package/src/aws/infra/api/integration.ts +8 -3
- package/src/aws/infra/api/response.ts +16 -16
- package/src/aws/infra/canaries/canary-alarm.ts +26 -24
- package/src/aws/infra/canaries/canary.ts +2 -4
- package/src/aws/infra/canaries/database-checker.ts +4 -1
- package/src/aws/infra/canaries/url-canary.ts +2 -1
- package/src/aws/infra/canaries/url-checker.ts +28 -11
- package/src/aws/infra/sqs-integration.ts +51 -47
- package/src/aws/infra/sqs-queue.ts +85 -53
- package/src/aws/infra/stack/lambda-configs.ts +6 -69
- package/src/aws/infra/stack/monitoredfunction.ts +2 -1
- package/src/aws/infra/stacks/db-stack.ts +1 -1
- package/src/aws/infra/stacks/network-stack.ts +7 -3
- package/src/aws/runtime/digitraffic-integration-response.ts +16 -9
- package/src/aws/runtime/secrets/dbsecret.ts +1 -117
- package/src/aws/runtime/secrets/proxy-holder.ts +2 -5
- package/src/aws/runtime/secrets/rds-holder.ts +2 -1
- package/src/aws/runtime/secrets/secret-holder.ts +8 -20
- package/src/aws/runtime/secrets/secret.ts +17 -22
- package/src/database/database.ts +14 -3
- package/src/test/db-testutils.ts +5 -2
- package/dist/test/secret.d.ts +0 -3
- package/dist/test/secret.js +0 -25
- package/src/test/secret.ts +0 -23
@@ -1,5 +1,4 @@
|
|
1
|
-
import {SecretsManager} from
|
2
|
-
import {SecretToPromiseFunction} from "./dbsecret";
|
1
|
+
import { SecretsManager } from "aws-sdk";
|
3
2
|
|
4
3
|
const smClient = new SecretsManager({
|
5
4
|
region: process.env.AWS_REGION,
|
@@ -7,29 +6,29 @@ const smClient = new SecretsManager({
|
|
7
6
|
|
8
7
|
export type GenericSecret = Record<string, string>;
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
SecretId: secretId,
|
20
|
-
}).promise();
|
9
|
+
export async function getSecret<Secret>(
|
10
|
+
secretId: string,
|
11
|
+
prefix = ""
|
12
|
+
): Promise<Secret> {
|
13
|
+
const secretObj = await smClient
|
14
|
+
.getSecretValue({
|
15
|
+
SecretId: secretId,
|
16
|
+
})
|
17
|
+
.promise();
|
21
18
|
|
22
19
|
if (!secretObj.SecretString) {
|
23
|
-
throw new Error(
|
20
|
+
throw new Error("No secret found!");
|
24
21
|
}
|
25
22
|
|
26
|
-
const secret = JSON.parse(
|
23
|
+
const secret: GenericSecret | Secret = JSON.parse(
|
24
|
+
secretObj.SecretString
|
25
|
+
) as unknown as GenericSecret | Secret;
|
27
26
|
|
28
|
-
if (prefix
|
29
|
-
return secret;
|
27
|
+
if (!prefix) {
|
28
|
+
return secret as Secret;
|
30
29
|
}
|
31
30
|
|
32
|
-
return parseSecret(secret, `${prefix}.`);
|
31
|
+
return parseSecret(secret as GenericSecret, `${prefix}.`);
|
33
32
|
}
|
34
33
|
|
35
34
|
function parseSecret<Secret>(secret: GenericSecret, prefix: string): Secret {
|
@@ -44,7 +43,3 @@ function parseSecret<Secret>(secret: GenericSecret, prefix: string): Secret {
|
|
44
43
|
|
45
44
|
return parsed as unknown as Secret;
|
46
45
|
}
|
47
|
-
|
48
|
-
export async function withSecretAndPrefix<Secret, Response>(secretId: string, prefix: string, fn: SecretToPromiseFunction<Secret, Response>): Promise<Response | void> {
|
49
|
-
return fn(await getSecret(secretId, prefix));
|
50
|
-
}
|
package/src/database/database.ts
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
import { IDatabase, ITask } from "pg-promise";
|
2
|
-
import { DatabaseEnvironmentKeys } from "../aws/runtime/secrets/dbsecret";
|
3
2
|
import { getEnvVariable } from "../utils/utils";
|
4
3
|
import { envValue } from "../aws/runtime/environment";
|
5
4
|
|
6
|
-
|
5
|
+
export enum DatabaseEnvironmentKeys {
|
6
|
+
DB_USER = "DB_USER",
|
7
|
+
DB_PASS = "DB_PASS",
|
8
|
+
DB_URI = "DB_URI",
|
9
|
+
DB_RO_URI = "DB_RO_URI",
|
10
|
+
DB_APPLICATION = "DB_APPLICATION",
|
11
|
+
}
|
12
|
+
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
7
14
|
const pgp = require("pg-promise")();
|
8
15
|
|
9
16
|
// convert numeric types to number instead of string
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
10
18
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.INT8, (value: string) => {
|
11
19
|
return parseInt(value);
|
12
20
|
});
|
13
21
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
14
23
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.FLOAT8, (value: string) => {
|
15
24
|
return parseFloat(value);
|
16
25
|
});
|
17
26
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
18
28
|
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.NUMERIC, (value: string) => {
|
19
29
|
return parseFloat(value);
|
20
30
|
});
|
@@ -44,6 +54,7 @@ export function initDbConnection(
|
|
44
54
|
): DTDatabase {
|
45
55
|
const finalUrl = `postgresql://${username}:${password}@${url}?application_name=${applicationName}`;
|
46
56
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
47
58
|
return pgp(finalUrl, options);
|
48
59
|
}
|
49
60
|
|
@@ -90,6 +101,6 @@ async function doInDatabase<T>(
|
|
90
101
|
console.error("Error in db:", e);
|
91
102
|
throw e;
|
92
103
|
} finally {
|
93
|
-
db.$pool.end();
|
104
|
+
await db.$pool.end();
|
94
105
|
}
|
95
106
|
}
|
package/src/test/db-testutils.ts
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import {
|
2
|
+
DatabaseEnvironmentKeys,
|
3
|
+
DTDatabase,
|
4
|
+
initDbConnection,
|
5
|
+
} from "../database/database";
|
3
6
|
import { Countable } from "../database/models";
|
4
7
|
|
5
8
|
export async function assertCount(db: DTDatabase, sql: string, count: number) {
|
package/dist/test/secret.d.ts
DELETED
@@ -1,3 +0,0 @@
|
|
1
|
-
import { EmptySecretFunction, SecretFunction } from "../aws/runtime/secrets/dbsecret";
|
2
|
-
export declare function createSecretFunction<Secret, Response>(secret: Secret): SecretFunction<Secret, Response>;
|
3
|
-
export declare function createEmptySecretFunction<Response>(): EmptySecretFunction<Response>;
|
package/dist/test/secret.js
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createEmptySecretFunction = exports.createSecretFunction = void 0;
|
4
|
-
const EMPTY_DB_SECRET = {
|
5
|
-
username: '',
|
6
|
-
password: '',
|
7
|
-
host: '',
|
8
|
-
// eslint-disable-next-line camelcase
|
9
|
-
ro_host: '',
|
10
|
-
};
|
11
|
-
function createSecretFunction(secret) {
|
12
|
-
// eslint-disable-next-line require-await
|
13
|
-
return async (secretId, fn) => {
|
14
|
-
return fn(secret);
|
15
|
-
};
|
16
|
-
}
|
17
|
-
exports.createSecretFunction = createSecretFunction;
|
18
|
-
function createEmptySecretFunction() {
|
19
|
-
// eslint-disable-next-line require-await
|
20
|
-
return async (secretId, fn) => {
|
21
|
-
return fn(EMPTY_DB_SECRET);
|
22
|
-
};
|
23
|
-
}
|
24
|
-
exports.createEmptySecretFunction = createEmptySecretFunction;
|
25
|
-
//# sourceMappingURL=secret.js.map
|
package/src/test/secret.ts
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
import {DbSecret, EmptySecretFunction, SecretFunction, SecretToPromiseFunction} from "../aws/runtime/secrets/dbsecret";
|
2
|
-
|
3
|
-
const EMPTY_DB_SECRET: DbSecret = {
|
4
|
-
username: '',
|
5
|
-
password: '',
|
6
|
-
host: '',
|
7
|
-
// eslint-disable-next-line camelcase
|
8
|
-
ro_host: '',
|
9
|
-
};
|
10
|
-
|
11
|
-
export function createSecretFunction<Secret, Response>(secret: Secret): SecretFunction<Secret, Response> {
|
12
|
-
// eslint-disable-next-line require-await
|
13
|
-
return async (secretId: string, fn: SecretToPromiseFunction<Secret, Response>) => {
|
14
|
-
return fn(secret);
|
15
|
-
};
|
16
|
-
}
|
17
|
-
|
18
|
-
export function createEmptySecretFunction<Response>(): EmptySecretFunction<Response> {
|
19
|
-
// eslint-disable-next-line require-await
|
20
|
-
return async (secretId: string, fn: SecretToPromiseFunction<DbSecret, Response>) => {
|
21
|
-
return fn(EMPTY_DB_SECRET);
|
22
|
-
};
|
23
|
-
}
|