@digitraffic/common 2022.11.22-1 → 2022.11.23-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/integration.d.ts +21 -0
- package/dist/aws/infra/api/integration.js +8 -4
- package/dist/aws/infra/api/integration.js.map +1 -0
- package/dist/aws/infra/api/response.d.ts +29 -0
- package/dist/aws/infra/api/response.js +36 -11
- package/dist/aws/infra/api/response.js.map +1 -0
- package/dist/aws/infra/api/responses.d.ts +47 -0
- package/dist/aws/infra/api/responses.js +8 -0
- package/dist/aws/infra/api/responses.js.map +1 -0
- package/dist/aws/infra/api/static-integration.d.ts +15 -0
- package/dist/aws/infra/api/static-integration.js.map +1 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
- package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-role.js.map +1 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/canary.js.map +1 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
- package/dist/aws/infra/canaries/database-canary.js.map +1 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
- package/dist/aws/infra/canaries/database-checker.js.map +1 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-canary.js.map +1 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
- package/dist/aws/infra/canaries/url-checker.js.map +1 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/documentation.js.map +1 -0
- package/dist/aws/infra/import-util.d.ts +21 -0
- package/dist/aws/infra/import-util.js.map +1 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/scheduler.js.map +1 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/security-rule.js.map +1 -0
- package/dist/aws/infra/sqs-integration.d.ts +7 -0
- package/dist/aws/infra/sqs-integration.js.map +1 -0
- package/dist/aws/infra/sqs-queue.d.ts +16 -0
- package/dist/aws/infra/sqs-queue.js.map +1 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +64 -0
- package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
- package/dist/aws/infra/stack/monitoredfunction.js +31 -31
- package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
- package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
- package/dist/aws/infra/stack/rest_apis.js.map +1 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
- package/dist/aws/infra/stack/stack.d.ts +45 -0
- package/dist/aws/infra/stack/stack.js.map +1 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stack/subscription.js.map +1 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +11 -0
- package/dist/aws/infra/stacks/db-dns-stack.js.map +1 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +19 -0
- package/dist/aws/infra/stacks/db-proxy-stack.js.map +1 -0
- package/dist/aws/infra/stacks/db-stack.d.ts +31 -0
- package/dist/aws/infra/stacks/db-stack.js.map +1 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.js.map +1 -0
- package/dist/aws/infra/stacks/network-stack.d.ts +12 -0
- package/dist/aws/infra/stacks/network-stack.js.map +1 -0
- package/dist/aws/infra/usage-plans.d.ts +16 -0
- package/dist/aws/infra/usage-plans.js.map +1 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/apikey.js.map +1 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
- package/dist/aws/runtime/environment.d.ts +1 -0
- package/dist/aws/runtime/environment.js.map +1 -0
- package/dist/aws/runtime/messaging.d.ts +10 -0
- package/dist/aws/runtime/messaging.js.map +1 -0
- package/dist/aws/runtime/s3.d.ts +2 -0
- package/dist/aws/runtime/s3.js.map +1 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +54 -0
- package/dist/aws/runtime/secrets/dbsecret.js +4 -4
- package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +26 -0
- package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/runtime/secrets/secret.js.map +1 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/errors.js.map +1 -0
- package/dist/aws/types/lambda-response.d.ts +13 -0
- package/dist/aws/types/lambda-response.js.map +1 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/mediatypes.js.map +1 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/model-with-reference.js.map +1 -0
- package/dist/aws/types/proxytypes.d.ts +26 -0
- package/dist/aws/types/proxytypes.js.map +1 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/aws/types/tags.js.map +1 -0
- package/dist/database/cached.d.ts +7 -0
- package/dist/database/cached.js.map +1 -0
- package/dist/database/database.d.ts +19 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/last-updated.d.ts +16 -0
- package/dist/database/last-updated.js.map +1 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js.map +1 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/id_utils.js.map +1 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/marine/rtz.js.map +1 -0
- package/dist/test/asserter.d.ts +11 -0
- package/dist/test/asserter.js.map +1 -0
- package/dist/test/db-testutils.d.ts +3 -0
- package/dist/test/db-testutils.js.map +1 -0
- package/dist/test/httpserver.d.ts +19 -0
- package/dist/test/httpserver.js.map +1 -0
- package/dist/test/secret.d.ts +3 -0
- package/dist/test/secret.js.map +1 -0
- package/dist/test/secrets-manager.d.ts +9 -0
- package/dist/test/secrets-manager.js.map +1 -0
- package/dist/test/testutils.d.ts +12 -0
- package/dist/test/testutils.js.map +1 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js.map +1 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/input-error.js.map +1 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/language.js.map +1 -0
- package/dist/types/traffictype.d.ts +8 -0
- package/dist/types/traffictype.js.map +1 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/types/validator.js.map +1 -0
- package/dist/utils/api-model.d.ts +87 -0
- package/dist/utils/api-model.js.map +1 -0
- package/dist/utils/base64.d.ts +12 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/date-utils.d.ts +17 -0
- package/dist/utils/date-utils.js.map +1 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geojson-types.js.map +1 -0
- package/dist/utils/geometry.d.ts +36 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/retry.d.ts +13 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/slack.js.map +1 -0
- package/dist/utils/utils.d.ts +46 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +19 -29
- package/src/aws/infra/api/integration.ts +30 -14
- package/src/aws/infra/api/response.ts +83 -20
- package/src/aws/infra/api/responses.ts +8 -0
- package/src/aws/runtime/secrets/dbsecret.ts +23 -54
- package/src/aws/runtime/secrets/secret-holder.ts +6 -3
- package/src/database/database.ts +1 -1
@@ -52,6 +52,9 @@ export const RESPONSE_404_NOT_FOUND = {
|
|
52
52
|
responseTemplates: NotFoundResponseTemplate,
|
53
53
|
};
|
54
54
|
|
55
|
+
/**
|
56
|
+
* @Deprecated Use DigitrafficMethodResponse
|
57
|
+
*/
|
55
58
|
export function methodResponse(
|
56
59
|
status: string,
|
57
60
|
contentType: MediaType,
|
@@ -65,6 +68,9 @@ export function methodResponse(
|
|
65
68
|
};
|
66
69
|
}
|
67
70
|
|
71
|
+
/**
|
72
|
+
* @Deprecated Use DigitrafficMethodResponse
|
73
|
+
*/
|
68
74
|
export function corsMethod(response: MethodResponse): MethodResponse {
|
69
75
|
return {
|
70
76
|
...response,
|
@@ -89,6 +95,8 @@ interface IntegrationOptions {
|
|
89
95
|
* Creates a default Lambda integration for a REST API resource _root_
|
90
96
|
* @param lambdaFunction The Lambda function
|
91
97
|
* @param options Options
|
98
|
+
*
|
99
|
+
* @deprecated Use DigitrafficIntegration
|
92
100
|
*/
|
93
101
|
export function defaultIntegration(
|
94
102
|
lambdaFunction: AWSFunction,
|
@@ -1,24 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import {withSecret, withSecretAndPrefix} from "./secret";
|
2
2
|
|
3
3
|
export type DbSecret = {
|
4
|
-
readonly username: string
|
5
|
-
readonly password: string
|
6
|
-
readonly host: string
|
7
|
-
readonly ro_host: string
|
4
|
+
readonly username: string
|
5
|
+
readonly password: string
|
6
|
+
readonly host: string
|
7
|
+
readonly ro_host: string
|
8
8
|
};
|
9
9
|
|
10
10
|
export enum RdsProxySecretKey {
|
11
|
-
username = "username",
|
12
|
-
password = "password",
|
13
|
-
proxy_host = "proxy_host",
|
14
|
-
proxy_ro_host = "proxy_ro_host",
|
11
|
+
username = "username", password = "password", proxy_host = "proxy_host", proxy_ro_host = "proxy_ro_host"
|
15
12
|
}
|
16
13
|
|
17
14
|
export enum RdsSecretKey {
|
18
|
-
username = "username",
|
19
|
-
password = "password",
|
20
|
-
host = "host",
|
21
|
-
ro_host = "ro_host",
|
15
|
+
username = "username", password = "password", host = "host", ro_host = "ro_host"
|
22
16
|
}
|
23
17
|
|
24
18
|
export type RdsProxySecret = Record<RdsProxySecretKey, string>;
|
@@ -43,7 +37,7 @@ function setDbSecret(secret: DbSecret) {
|
|
43
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
44
38
|
let cachedSecret: any;
|
45
39
|
|
46
|
-
const missingSecretErrorText =
|
40
|
+
const missingSecretErrorText = 'Missing or empty secretId';
|
47
41
|
|
48
42
|
/**
|
49
43
|
* You can give the following options for retrieving a secret:
|
@@ -54,22 +48,13 @@ const missingSecretErrorText = "Missing or empty secretId";
|
|
54
48
|
|
55
49
|
*/
|
56
50
|
export type SecretOptions = {
|
57
|
-
readonly expectedKeys?: string[]
|
58
|
-
readonly prefix?: string
|
59
|
-
}
|
51
|
+
readonly expectedKeys?: string[],
|
52
|
+
readonly prefix?: string
|
53
|
+
}
|
60
54
|
|
61
|
-
export type SecretToPromiseFunction<Secret, Response = void> = (
|
62
|
-
|
63
|
-
|
64
|
-
export type SecretFunction<Secret, Response = void> = (
|
65
|
-
secretId: string,
|
66
|
-
fn: SecretToPromiseFunction<Secret, Response>,
|
67
|
-
options?: SecretOptions
|
68
|
-
) => Promise<Response | void>;
|
69
|
-
export type EmptySecretFunction<Response = void> = SecretFunction<
|
70
|
-
DbSecret,
|
71
|
-
Response
|
72
|
-
>;
|
55
|
+
export type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
|
56
|
+
export type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
|
57
|
+
export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
|
73
58
|
|
74
59
|
/**
|
75
60
|
* Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
|
@@ -81,11 +66,7 @@ export type EmptySecretFunction<Response = void> = SecretFunction<
|
|
81
66
|
* @param {function} fn
|
82
67
|
* @param {SecretOptions} options
|
83
68
|
*/
|
84
|
-
export async function withDbSecret<Secret, Response>(
|
85
|
-
secretId: string,
|
86
|
-
fn: SecretToPromiseFunction<Secret, Response>,
|
87
|
-
options?: SecretOptions
|
88
|
-
): Promise<Response | void> {
|
69
|
+
export async function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void> {
|
89
70
|
if (!secretId) {
|
90
71
|
console.error(missingSecretErrorText);
|
91
72
|
return Promise.reject(missingSecretErrorText);
|
@@ -100,13 +81,9 @@ export async function withDbSecret<Secret, Response>(
|
|
100
81
|
});
|
101
82
|
|
102
83
|
// then actual secret
|
103
|
-
await withSecretAndPrefix(
|
104
|
-
|
105
|
-
|
106
|
-
(fetchedSecret: Secret) => {
|
107
|
-
cachedSecret = fetchedSecret;
|
108
|
-
}
|
109
|
-
);
|
84
|
+
await withSecretAndPrefix(secretId, options.prefix, (fetchedSecret: Secret) => {
|
85
|
+
cachedSecret = fetchedSecret;
|
86
|
+
});
|
110
87
|
} else {
|
111
88
|
await withSecret(secretId, (fetchedSecret: DbSecret) => {
|
112
89
|
setDbSecret(fetchedSecret);
|
@@ -120,10 +97,7 @@ export async function withDbSecret<Secret, Response>(
|
|
120
97
|
}
|
121
98
|
return fn(cachedSecret);
|
122
99
|
} catch (error) {
|
123
|
-
console.error(
|
124
|
-
"method=withDbSecret Caught an error, refreshing secret",
|
125
|
-
error
|
126
|
-
);
|
100
|
+
console.error('method=withDbSecret Caught an error, refreshing secret', error);
|
127
101
|
// try to refetch secret in case it has changed
|
128
102
|
await withSecret(secretId, (fetchedSecret: DbSecret) => {
|
129
103
|
setDbSecret(fetchedSecret);
|
@@ -133,15 +107,10 @@ export async function withDbSecret<Secret, Response>(
|
|
133
107
|
}
|
134
108
|
}
|
135
109
|
|
136
|
-
export function checkExpectedSecretKeys<Secret
|
137
|
-
keys
|
138
|
-
secret: Secret
|
139
|
-
) {
|
140
|
-
const missingKeys = keys.filter((key) => !(key in secret));
|
110
|
+
export function checkExpectedSecretKeys<Secret>(keys: string[], secret: Secret) {
|
111
|
+
const missingKeys = keys.filter(key => !(key in secret));
|
141
112
|
if (missingKeys.length) {
|
142
|
-
console.error(
|
143
|
-
|
144
|
-
);
|
145
|
-
throw new Error("Expected keys were not found");
|
113
|
+
console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
|
114
|
+
throw new Error('Expected keys were not found');
|
146
115
|
}
|
147
116
|
}
|
@@ -23,7 +23,7 @@ const DEFAULT_CONFIGURATION = {
|
|
23
23
|
*
|
24
24
|
* Supports setting the database environment paramaters from the secret too.
|
25
25
|
*/
|
26
|
-
export class SecretHolder<Secret
|
26
|
+
export class SecretHolder<Secret> {
|
27
27
|
private readonly secretId: string;
|
28
28
|
private readonly prefix: string;
|
29
29
|
private readonly expectedKeys: string[];
|
@@ -51,7 +51,7 @@ export class SecretHolder<Secret extends GenericSecret> {
|
|
51
51
|
this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
|
52
52
|
}
|
53
53
|
|
54
|
-
public static create<S
|
54
|
+
public static create<S>(
|
55
55
|
prefix = DEFAULT_PREFIX,
|
56
56
|
expectedKeys: string[] = []
|
57
57
|
) {
|
@@ -67,7 +67,10 @@ export class SecretHolder<Secret extends GenericSecret> {
|
|
67
67
|
const parsedSecret =
|
68
68
|
this.prefix === DEFAULT_PREFIX
|
69
69
|
? secret
|
70
|
-
: this.parseSecret(
|
70
|
+
: this.parseSecret(
|
71
|
+
secret as unknown as GenericSecret,
|
72
|
+
`${this.prefix}.`
|
73
|
+
);
|
71
74
|
|
72
75
|
if (this.expectedKeys.length > 0) {
|
73
76
|
checkExpectedSecretKeys(this.expectedKeys, parsedSecret);
|
package/src/database/database.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { IDatabase, ITask } from "pg-promise";
|
2
2
|
import { DatabaseEnvironmentKeys } from "../aws/runtime/secrets/dbsecret";
|
3
|
-
import { getEnvVariable
|
3
|
+
import { getEnvVariable } from "../utils/utils";
|
4
4
|
import { envValue } from "../aws/runtime/environment";
|
5
5
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|