@digitraffic/common 2022.11.23-2 → 2022.11.23-3
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 +1 -1
- package/dist/aws/infra/api/response.d.ts +0 -1
- package/dist/aws/infra/api/response.js +0 -3
- package/dist/aws/infra/canaries/canary-parameters.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/stack/lambda-configs.d.ts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.d.ts +2 -2
- package/dist/aws/infra/stack/monitoredfunction.js +31 -31
- package/dist/aws/runtime/secrets/dbsecret.d.ts +9 -8
- package/dist/aws/runtime/secrets/dbsecret.js +4 -4
- package/dist/aws/runtime/secrets/secret-holder.d.ts +3 -2
- package/dist/aws/runtime/secrets/secret.d.ts +1 -1
- package/dist/aws/types/proxytypes.d.ts +2 -2
- package/dist/database/database.d.ts +2 -2
- package/dist/marine/rtz.d.ts +10 -10
- package/dist/types/either.d.ts +3 -3
- package/package.json +33 -21
- package/src/aws/infra/api/response.ts +0 -12
- package/src/aws/runtime/secrets/dbsecret.ts +54 -23
- package/src/aws/runtime/secrets/secret-holder.ts +3 -6
- package/dist/aws/infra/api/integration.js.map +0 -1
- package/dist/aws/infra/api/response.js.map +0 -1
- package/dist/aws/infra/api/responses.js.map +0 -1
- package/dist/aws/infra/api/static-integration.js.map +0 -1
- package/dist/aws/infra/canaries/canary-alarm.js.map +0 -1
- package/dist/aws/infra/canaries/canary-keys.js.map +0 -1
- package/dist/aws/infra/canaries/canary-parameters.js.map +0 -1
- package/dist/aws/infra/canaries/canary-role.js.map +0 -1
- package/dist/aws/infra/canaries/canary.js.map +0 -1
- package/dist/aws/infra/canaries/database-canary.js.map +0 -1
- package/dist/aws/infra/canaries/database-checker.js.map +0 -1
- package/dist/aws/infra/canaries/url-canary.js.map +0 -1
- package/dist/aws/infra/canaries/url-checker.js.map +0 -1
- package/dist/aws/infra/documentation.js.map +0 -1
- package/dist/aws/infra/import-util.js.map +0 -1
- package/dist/aws/infra/scheduler.js.map +0 -1
- package/dist/aws/infra/security-rule.js.map +0 -1
- package/dist/aws/infra/sqs-integration.js.map +0 -1
- package/dist/aws/infra/sqs-queue.js.map +0 -1
- package/dist/aws/infra/stack/lambda-configs.js.map +0 -1
- package/dist/aws/infra/stack/monitoredfunction.js.map +0 -1
- package/dist/aws/infra/stack/rest_apis.js.map +0 -1
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +0 -1
- package/dist/aws/infra/stack/stack.js.map +0 -1
- package/dist/aws/infra/stack/subscription.js.map +0 -1
- package/dist/aws/infra/stacks/db-dns-stack.js.map +0 -1
- package/dist/aws/infra/stacks/db-proxy-stack.js.map +0 -1
- package/dist/aws/infra/stacks/db-stack.js.map +0 -1
- package/dist/aws/infra/stacks/intra-stack-configuration.js.map +0 -1
- package/dist/aws/infra/stacks/network-stack.js.map +0 -1
- package/dist/aws/infra/usage-plans.js.map +0 -1
- package/dist/aws/runtime/apikey.js.map +0 -1
- package/dist/aws/runtime/digitraffic-integration-response.js.map +0 -1
- package/dist/aws/runtime/environment.js.map +0 -1
- package/dist/aws/runtime/messaging.js.map +0 -1
- package/dist/aws/runtime/s3.js.map +0 -1
- package/dist/aws/runtime/secrets/dbsecret.js.map +0 -1
- package/dist/aws/runtime/secrets/proxy-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/rds-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/secret-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/secret.js.map +0 -1
- package/dist/aws/types/errors.js.map +0 -1
- package/dist/aws/types/lambda-response.js.map +0 -1
- package/dist/aws/types/mediatypes.js.map +0 -1
- package/dist/aws/types/model-with-reference.js.map +0 -1
- package/dist/aws/types/proxytypes.js.map +0 -1
- package/dist/aws/types/tags.js.map +0 -1
- package/dist/database/cached.js.map +0 -1
- package/dist/database/database.js.map +0 -1
- package/dist/database/last-updated.js.map +0 -1
- package/dist/database/models.js.map +0 -1
- package/dist/marine/id_utils.js.map +0 -1
- package/dist/marine/rtz.js.map +0 -1
- package/dist/test/asserter.js.map +0 -1
- package/dist/test/db-testutils.js.map +0 -1
- package/dist/test/httpserver.js.map +0 -1
- package/dist/test/secret.js.map +0 -1
- package/dist/test/secrets-manager.js.map +0 -1
- package/dist/test/testutils.js.map +0 -1
- package/dist/types/either.js.map +0 -1
- package/dist/types/input-error.js.map +0 -1
- package/dist/types/language.js.map +0 -1
- package/dist/types/traffictype.js.map +0 -1
- package/dist/types/validator.js.map +0 -1
- package/dist/utils/api-model.js.map +0 -1
- package/dist/utils/base64.js.map +0 -1
- package/dist/utils/date-utils.js.map +0 -1
- package/dist/utils/geojson-types.js.map +0 -1
- package/dist/utils/geometry.js.map +0 -1
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/slack.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
import { IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { IFunction } from "aws-cdk-lib/aws-lambda";
|
3
3
|
import { MediaType } from "../../types/mediatypes";
|
4
|
-
|
4
|
+
type ParameterType = "path" | "querystring";
|
5
5
|
interface ApiParameter {
|
6
6
|
type: ParameterType;
|
7
7
|
name: string;
|
@@ -24,5 +24,4 @@ export declare class DigitrafficMethodResponse {
|
|
24
24
|
static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
|
25
25
|
static response200(model: IModel, mediaType?: MediaType): MethodResponse;
|
26
26
|
static response500(model?: IModel, mediaType?: MediaType): MethodResponse;
|
27
|
-
static response400(model?: IModel, mediaType?: MediaType): MethodResponse;
|
28
27
|
}
|
@@ -84,9 +84,6 @@ class DigitrafficMethodResponse {
|
|
84
84
|
static response500(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
85
85
|
return DigitrafficMethodResponse.response("500", model, mediaType, false);
|
86
86
|
}
|
87
|
-
static response400(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
88
|
-
return DigitrafficMethodResponse.response("400", model, mediaType, false);
|
89
|
-
}
|
90
87
|
}
|
91
88
|
exports.DigitrafficMethodResponse = DigitrafficMethodResponse;
|
92
89
|
//# sourceMappingURL=response.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
|
2
2
|
/** Optional env parameters for canary */
|
3
|
-
|
4
|
-
export
|
3
|
+
type CanaryEnv = Record<string, string>;
|
4
|
+
export type CanaryParameters = {
|
5
5
|
readonly name: string;
|
6
6
|
readonly schedule?: Schedule;
|
7
7
|
readonly secret?: string;
|
@@ -3,8 +3,8 @@ import { IncomingMessage } from "http";
|
|
3
3
|
import { MediaType } from "../../types/mediatypes";
|
4
4
|
import { FeatureCollection } from "geojson";
|
5
5
|
export declare const API_KEY_HEADER = "x-api-key";
|
6
|
-
|
7
|
-
|
6
|
+
type CheckerFunction = (Res: IncomingMessage) => void;
|
7
|
+
type JsonCheckerFunction<T> = (json: T, body: string, message: IncomingMessage) => void;
|
8
8
|
export declare class UrlChecker {
|
9
9
|
private readonly requestOptions;
|
10
10
|
constructor(hostname: string, apiKey?: string);
|
@@ -3,8 +3,8 @@ import { ISecurityGroup, IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
|
|
3
3
|
import { Role } from "aws-cdk-lib/aws-iam";
|
4
4
|
import { DigitrafficStack } from "./stack";
|
5
5
|
import { MonitoredFunctionAlarmProps } from "./monitoredfunction";
|
6
|
-
export
|
7
|
-
export
|
6
|
+
export type LambdaEnvironment = Record<string, string>;
|
7
|
+
export type DBLambdaEnvironment = LambdaEnvironment & {
|
8
8
|
SECRET_ID?: string;
|
9
9
|
DB_APPLICATION: string;
|
10
10
|
};
|
@@ -55,7 +55,7 @@ export interface FunctionParameters {
|
|
55
55
|
architecture?: Architecture;
|
56
56
|
singleLambda?: boolean;
|
57
57
|
}
|
58
|
-
export
|
58
|
+
export type MonitoredFunctionParameters = FunctionParameters & {
|
59
59
|
readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
|
60
60
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
61
61
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|
@@ -8,7 +8,7 @@ import { TrafficType } from "../../../types/traffictype";
|
|
8
8
|
/**
|
9
9
|
* Allows customization of CloudWatch Alarm properties
|
10
10
|
*/
|
11
|
-
export
|
11
|
+
export type MonitoredFunctionAlarmProps = {
|
12
12
|
/**
|
13
13
|
* Setting this to false will not create a CloudWatch alarm
|
14
14
|
*/
|
@@ -18,7 +18,7 @@ export declare type MonitoredFunctionAlarmProps = {
|
|
18
18
|
readonly datapointsToAlarm?: number;
|
19
19
|
readonly comparisonOperator?: ComparisonOperator;
|
20
20
|
};
|
21
|
-
export
|
21
|
+
export type MonitoredFunctionProps = {
|
22
22
|
readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
|
23
23
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
24
24
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|
@@ -11,6 +11,37 @@ const subscription_1 = require("../stack/subscription");
|
|
11
11
|
* Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
|
12
12
|
*/
|
13
13
|
class MonitoredFunction extends aws_lambda_1.Function {
|
14
|
+
/**
|
15
|
+
* Create new MonitoredFunction. Use topics from given DigitrafficStack.
|
16
|
+
*
|
17
|
+
* @param stack DigitrafficStack
|
18
|
+
* @param id Lambda construct Id
|
19
|
+
* @param functionProps Lambda function properties
|
20
|
+
* @param props Monitored function properties
|
21
|
+
*/
|
22
|
+
static create(stack, id, functionProps, props) {
|
23
|
+
if (props === MonitoredFunction.DISABLE_ALARMS &&
|
24
|
+
stack.configuration.production) {
|
25
|
+
throw new Error(`Function ${functionProps.functionName} has DISABLE_ALARMS. Remove before installing to production or define your own properties!`);
|
26
|
+
}
|
27
|
+
return new MonitoredFunction(stack, id, functionProps, stack.alarmTopic, stack.warningTopic, stack.configuration.production, stack.configuration.trafficType, props);
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
|
31
|
+
*
|
32
|
+
* For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
|
33
|
+
*
|
34
|
+
* @param stack DigitrafficStack
|
35
|
+
* @param name param-case name
|
36
|
+
* @param environment Lambda environment
|
37
|
+
* @param functionParameters Lambda function parameters
|
38
|
+
*/
|
39
|
+
static createV2(stack, name, environment, functionParameters) {
|
40
|
+
const functionName = functionParameters?.functionName ||
|
41
|
+
`${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
|
42
|
+
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
|
43
|
+
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
44
|
+
}
|
14
45
|
/**
|
15
46
|
* @param scope Stack
|
16
47
|
* @param id Lambda construct Id
|
@@ -48,37 +79,6 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
48
79
|
this.createAlarm(scope, this.metricThrottles(), "Throttles", "Throttles alarm", "Has throttled", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 0, 1, 1, aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD, props?.throttleAlarmProps);
|
49
80
|
}
|
50
81
|
}
|
51
|
-
/**
|
52
|
-
* Create new MonitoredFunction. Use topics from given DigitrafficStack.
|
53
|
-
*
|
54
|
-
* @param stack DigitrafficStack
|
55
|
-
* @param id Lambda construct Id
|
56
|
-
* @param functionProps Lambda function properties
|
57
|
-
* @param props Monitored function properties
|
58
|
-
*/
|
59
|
-
static create(stack, id, functionProps, props) {
|
60
|
-
if (props === MonitoredFunction.DISABLE_ALARMS &&
|
61
|
-
stack.configuration.production) {
|
62
|
-
throw new Error(`Function ${functionProps.functionName} has DISABLE_ALARMS. Remove before installing to production or define your own properties!`);
|
63
|
-
}
|
64
|
-
return new MonitoredFunction(stack, id, functionProps, stack.alarmTopic, stack.warningTopic, stack.configuration.production, stack.configuration.trafficType, props);
|
65
|
-
}
|
66
|
-
/**
|
67
|
-
* Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
|
68
|
-
*
|
69
|
-
* For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
|
70
|
-
*
|
71
|
-
* @param stack DigitrafficStack
|
72
|
-
* @param name param-case name
|
73
|
-
* @param environment Lambda environment
|
74
|
-
* @param functionParameters Lambda function parameters
|
75
|
-
*/
|
76
|
-
static createV2(stack, name, environment, functionParameters) {
|
77
|
-
const functionName = functionParameters?.functionName ||
|
78
|
-
`${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
|
79
|
-
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
|
80
|
-
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
81
|
-
}
|
82
82
|
createAlarm(stack, metric, alarmId, alarmName, alarmDescription, trafficType, alarmSnsAction, threshold, evaluationPeriods, datapointsToAlarm, comparisonOperator, alarmProps) {
|
83
83
|
metric
|
84
84
|
.createAlarm(stack, `${this.node.id}-${alarmId}`, {
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
import { GenericSecret } from "./secret";
|
2
|
+
export type DbSecret = {
|
2
3
|
readonly username: string;
|
3
4
|
readonly password: string;
|
4
5
|
readonly host: string;
|
@@ -16,8 +17,8 @@ export declare enum RdsSecretKey {
|
|
16
17
|
host = "host",
|
17
18
|
ro_host = "ro_host"
|
18
19
|
}
|
19
|
-
export
|
20
|
-
export
|
20
|
+
export type RdsProxySecret = Record<RdsProxySecretKey, string>;
|
21
|
+
export type RdsSecret = Record<RdsSecretKey, string>;
|
21
22
|
export declare enum DatabaseEnvironmentKeys {
|
22
23
|
DB_USER = "DB_USER",
|
23
24
|
DB_PASS = "DB_PASS",
|
@@ -33,13 +34,13 @@ export declare enum DatabaseEnvironmentKeys {
|
|
33
34
|
* The secret that is passed to the given function will not include the prefix in it's keys.
|
34
35
|
|
35
36
|
*/
|
36
|
-
export
|
37
|
+
export type SecretOptions = {
|
37
38
|
readonly expectedKeys?: string[];
|
38
39
|
readonly prefix?: string;
|
39
40
|
};
|
40
|
-
export
|
41
|
-
export
|
42
|
-
export
|
41
|
+
export type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
|
42
|
+
export type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
|
43
|
+
export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
|
43
44
|
/**
|
44
45
|
* Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
|
45
46
|
*
|
@@ -51,4 +52,4 @@ export declare type EmptySecretFunction<Response = void> = SecretFunction<DbSecr
|
|
51
52
|
* @param {SecretOptions} options
|
52
53
|
*/
|
53
54
|
export declare function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void>;
|
54
|
-
export declare function checkExpectedSecretKeys<Secret>(keys: string[], secret: Secret): void;
|
55
|
+
export declare function checkExpectedSecretKeys<Secret extends GenericSecret>(keys: string[], secret: Secret): void;
|
@@ -33,7 +33,7 @@ function setDbSecret(secret) {
|
|
33
33
|
// cached at Lambda container level
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
35
35
|
let cachedSecret;
|
36
|
-
const missingSecretErrorText =
|
36
|
+
const missingSecretErrorText = "Missing or empty secretId";
|
37
37
|
/**
|
38
38
|
* Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
|
39
39
|
*
|
@@ -75,7 +75,7 @@ async function withDbSecret(secretId, fn, options) {
|
|
75
75
|
return fn(cachedSecret);
|
76
76
|
}
|
77
77
|
catch (error) {
|
78
|
-
console.error(
|
78
|
+
console.error("method=withDbSecret Caught an error, refreshing secret", error);
|
79
79
|
// try to refetch secret in case it has changed
|
80
80
|
await (0, secret_1.withSecret)(secretId, (fetchedSecret) => {
|
81
81
|
setDbSecret(fetchedSecret);
|
@@ -86,10 +86,10 @@ async function withDbSecret(secretId, fn, options) {
|
|
86
86
|
}
|
87
87
|
exports.withDbSecret = withDbSecret;
|
88
88
|
function checkExpectedSecretKeys(keys, secret) {
|
89
|
-
const missingKeys = keys.filter(key => !(key in secret));
|
89
|
+
const missingKeys = keys.filter((key) => !(key in secret));
|
90
90
|
if (missingKeys.length) {
|
91
91
|
console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
|
92
|
-
throw new Error(
|
92
|
+
throw new Error("Expected keys were not found");
|
93
93
|
}
|
94
94
|
}
|
95
95
|
exports.checkExpectedSecretKeys = checkExpectedSecretKeys;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { GenericSecret } from "./secret";
|
1
2
|
/**
|
2
3
|
* Utility class for getting secrets from Secret Manager.
|
3
4
|
* Supports prefix for secrets, checking of expected keys and ttl-configuration.
|
@@ -6,7 +7,7 @@
|
|
6
7
|
*
|
7
8
|
* Supports setting the database environment paramaters from the secret too.
|
8
9
|
*/
|
9
|
-
export declare class SecretHolder<Secret> {
|
10
|
+
export declare class SecretHolder<Secret extends GenericSecret> {
|
10
11
|
private readonly secretId;
|
11
12
|
private readonly prefix;
|
12
13
|
private readonly expectedKeys;
|
@@ -15,7 +16,7 @@ export declare class SecretHolder<Secret> {
|
|
15
16
|
ttl: number;
|
16
17
|
});
|
17
18
|
private initSecret;
|
18
|
-
static create<S>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
|
19
|
+
static create<S extends GenericSecret>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
|
19
20
|
get(): Promise<Secret>;
|
20
21
|
private parseSecret;
|
21
22
|
private getSecret;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* Not fully described, extend if necessary.
|
5
5
|
*/
|
6
|
-
export
|
6
|
+
export type ProxyLambdaResponse = {
|
7
7
|
readonly statusCode: number;
|
8
8
|
readonly body: string;
|
9
9
|
readonly headers?: Record<string, string>;
|
@@ -14,7 +14,7 @@ export declare type ProxyLambdaResponse = {
|
|
14
14
|
*
|
15
15
|
* Not fully described, extend if necessary.
|
16
16
|
*/
|
17
|
-
export
|
17
|
+
export type ProxyLambdaRequest = {
|
18
18
|
readonly resource: string;
|
19
19
|
readonly path: string;
|
20
20
|
readonly httpMethod: string;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { IDatabase, ITask } from "pg-promise";
|
2
|
-
export
|
3
|
-
export
|
2
|
+
export type DTDatabase = IDatabase<unknown>;
|
3
|
+
export type DTTransaction = ITask<unknown>;
|
4
4
|
/**
|
5
5
|
* Creates a non-pooling database connection primarily used by Lambdas.
|
6
6
|
*
|
package/dist/marine/rtz.d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
export
|
1
|
+
export type RtzPositionCoordinate = {
|
2
2
|
readonly $: {
|
3
3
|
readonly lat: number;
|
4
4
|
readonly lon: number;
|
5
5
|
};
|
6
6
|
};
|
7
|
-
export
|
7
|
+
export type RtzWaypointPosition = {
|
8
8
|
readonly position: RtzPositionCoordinate[];
|
9
9
|
};
|
10
|
-
export
|
10
|
+
export type RtzWaypoint = {
|
11
11
|
readonly waypoint: RtzWaypointPosition[];
|
12
12
|
};
|
13
|
-
export
|
13
|
+
export type RtzScheduleElement = {
|
14
14
|
readonly $: {
|
15
15
|
/**
|
16
16
|
* Date
|
@@ -22,27 +22,27 @@ export declare type RtzScheduleElement = {
|
|
22
22
|
readonly eta?: string;
|
23
23
|
};
|
24
24
|
};
|
25
|
-
export
|
25
|
+
export type RtzSchedule = {
|
26
26
|
readonly scheduleElement: RtzScheduleElement[];
|
27
27
|
};
|
28
|
-
export
|
28
|
+
export type RtzScheduleWrapper = {
|
29
29
|
readonly manual?: RtzSchedule[];
|
30
30
|
readonly calculated?: RtzSchedule[];
|
31
31
|
};
|
32
|
-
export
|
32
|
+
export type RtzSchedules = {
|
33
33
|
readonly schedule: RtzScheduleWrapper[];
|
34
34
|
};
|
35
|
-
export
|
35
|
+
export type RtzRouteInfo = {
|
36
36
|
readonly $: {
|
37
37
|
readonly vesselMMSI: string;
|
38
38
|
readonly vesselIMO: string;
|
39
39
|
};
|
40
40
|
};
|
41
|
-
export
|
41
|
+
export type RtzRoute = {
|
42
42
|
readonly routeInfo: RtzRouteInfo[];
|
43
43
|
readonly waypoints: RtzWaypoint[];
|
44
44
|
readonly schedules: RtzSchedules[];
|
45
45
|
};
|
46
|
-
export
|
46
|
+
export type RtzVoyagePlan = {
|
47
47
|
readonly route: RtzRoute;
|
48
48
|
};
|
package/dist/types/either.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export
|
1
|
+
export type EitherOk<T> = {
|
2
2
|
result: "ok";
|
3
3
|
value: T;
|
4
4
|
};
|
5
|
-
export
|
5
|
+
export type EitherError = {
|
6
6
|
result: "error";
|
7
7
|
message: string;
|
8
8
|
};
|
9
|
-
export
|
9
|
+
export type Either<T> = EitherOk<T> | EitherError;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2022.11.23-
|
3
|
+
"version": "2022.11.23-3",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -10,36 +10,41 @@
|
|
10
10
|
"node": ">=14 <17",
|
11
11
|
"yarn": ">1.2 <2"
|
12
12
|
},
|
13
|
-
"scripts": {
|
14
|
-
"build": "tsc",
|
15
|
-
"lint": "eslint --cache .",
|
16
|
-
"eslint-report": "eslint . --format html",
|
17
|
-
"clean": "rimraf dist output",
|
18
|
-
"test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest",
|
19
|
-
"prepare": "husky install",
|
20
|
-
"prepublishOnly": "yarn clean && yarn build && yarn test"
|
21
|
-
},
|
22
13
|
"license": "EUPL-1.2",
|
23
14
|
"private": false,
|
24
15
|
"files": [
|
25
16
|
"dist/**/*.js",
|
17
|
+
"dist/**/*.d.ts",
|
26
18
|
"src/**/*.ts"
|
27
19
|
],
|
28
|
-
"
|
29
|
-
"
|
20
|
+
"peerDependencies": {
|
21
|
+
"pg-promise": "^10.12.0",
|
22
|
+
"spex": "^3.0.0",
|
23
|
+
"constructs": "^10.1.131",
|
24
|
+
"@aws-cdk/aws-synthetics-alpha": "^2.50.0-alpha.0",
|
30
25
|
"@types/geojson": "^7946.0.10",
|
31
|
-
"aws-cdk-lib": "2.51.1",
|
32
|
-
"aws-sdk": "2.1241.0",
|
26
|
+
"aws-cdk-lib": "^2.51.1",
|
27
|
+
"aws-sdk": "^2.1241.0",
|
33
28
|
"axios": "^0.21.1",
|
34
|
-
"change-case": "4.1.2",
|
35
|
-
"constructs": "10.1.131",
|
29
|
+
"change-case": "^4.1.2",
|
36
30
|
"geojson-validation": "^1.0.2",
|
37
31
|
"moment": "^2.29.4",
|
38
32
|
"node-ttl": "^0.2.0",
|
39
|
-
"pg-native": "^3.0.1"
|
40
|
-
"pg-promise": "^10.12.0"
|
33
|
+
"pg-native": "^3.0.1"
|
41
34
|
},
|
42
35
|
"devDependencies": {
|
36
|
+
"@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
|
37
|
+
"@types/geojson": "^7946.0.10",
|
38
|
+
"aws-cdk-lib": "^2.50.0",
|
39
|
+
"aws-sdk": "^2.1241.0",
|
40
|
+
"axios": "^0.21.1",
|
41
|
+
"change-case": "^4.1.2",
|
42
|
+
"constructs": "^10.1.131",
|
43
|
+
"geojson-validation": "^1.0.2",
|
44
|
+
"moment": "^2.29.4",
|
45
|
+
"node-ttl": "^0.2.0",
|
46
|
+
"pg-native": "^3.0.1",
|
47
|
+
"pg-promise": "^10.12.0",
|
43
48
|
"@types/aws-lambda": "^8.10.106",
|
44
49
|
"@types/jest": "^29.0.3",
|
45
50
|
"@types/node": "^18.7.23",
|
@@ -58,8 +63,8 @@
|
|
58
63
|
"ramda": "^0.28.0",
|
59
64
|
"rimraf": "^3.0.2",
|
60
65
|
"sinon": "^14.0.0",
|
61
|
-
"
|
62
|
-
"
|
66
|
+
"typescript": "^4.7.4",
|
67
|
+
"ts-jest": "^29.0.3"
|
63
68
|
},
|
64
69
|
"externals": [
|
65
70
|
"aws-sdk",
|
@@ -67,5 +72,12 @@
|
|
67
72
|
],
|
68
73
|
"lint-staged": {
|
69
74
|
"*.{js,ts,css,md,yml,yaml,json}": "prettier --write"
|
75
|
+
},
|
76
|
+
"scripts": {
|
77
|
+
"build": "tsc",
|
78
|
+
"lint": "eslint --cache .",
|
79
|
+
"eslint-report": "eslint . --format html",
|
80
|
+
"clean": "rimraf dist output",
|
81
|
+
"test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest"
|
70
82
|
}
|
71
|
-
}
|
83
|
+
}
|
@@ -133,16 +133,4 @@ export class DigitrafficMethodResponse {
|
|
133
133
|
false
|
134
134
|
);
|
135
135
|
}
|
136
|
-
|
137
|
-
static response400(
|
138
|
-
model = Model.EMPTY_MODEL,
|
139
|
-
mediaType = MediaType.APPLICATION_JSON
|
140
|
-
) {
|
141
|
-
return DigitrafficMethodResponse.response(
|
142
|
-
"400",
|
143
|
-
model,
|
144
|
-
mediaType,
|
145
|
-
false
|
146
|
-
);
|
147
|
-
}
|
148
136
|
}
|
@@ -1,18 +1,24 @@
|
|
1
|
-
import {withSecret, withSecretAndPrefix} from "./secret";
|
1
|
+
import { GenericSecret, 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",
|
11
|
+
username = "username",
|
12
|
+
password = "password",
|
13
|
+
proxy_host = "proxy_host",
|
14
|
+
proxy_ro_host = "proxy_ro_host",
|
12
15
|
}
|
13
16
|
|
14
17
|
export enum RdsSecretKey {
|
15
|
-
username = "username",
|
18
|
+
username = "username",
|
19
|
+
password = "password",
|
20
|
+
host = "host",
|
21
|
+
ro_host = "ro_host",
|
16
22
|
}
|
17
23
|
|
18
24
|
export type RdsProxySecret = Record<RdsProxySecretKey, string>;
|
@@ -37,7 +43,7 @@ function setDbSecret(secret: DbSecret) {
|
|
37
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
38
44
|
let cachedSecret: any;
|
39
45
|
|
40
|
-
const missingSecretErrorText =
|
46
|
+
const missingSecretErrorText = "Missing or empty secretId";
|
41
47
|
|
42
48
|
/**
|
43
49
|
* You can give the following options for retrieving a secret:
|
@@ -48,13 +54,22 @@ const missingSecretErrorText = 'Missing or empty secretId';
|
|
48
54
|
|
49
55
|
*/
|
50
56
|
export type SecretOptions = {
|
51
|
-
readonly expectedKeys?: string[]
|
52
|
-
readonly prefix?: string
|
53
|
-
}
|
57
|
+
readonly expectedKeys?: string[];
|
58
|
+
readonly prefix?: string;
|
59
|
+
};
|
54
60
|
|
55
|
-
export type SecretToPromiseFunction<Secret, Response = void> = (
|
56
|
-
|
57
|
-
|
61
|
+
export type SecretToPromiseFunction<Secret, Response = void> = (
|
62
|
+
secret: Secret
|
63
|
+
) => Promise<Response> | void;
|
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
|
+
>;
|
58
73
|
|
59
74
|
/**
|
60
75
|
* Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
|
@@ -66,7 +81,11 @@ export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Resp
|
|
66
81
|
* @param {function} fn
|
67
82
|
* @param {SecretOptions} options
|
68
83
|
*/
|
69
|
-
export async function withDbSecret<Secret, Response>(
|
84
|
+
export async function withDbSecret<Secret, Response>(
|
85
|
+
secretId: string,
|
86
|
+
fn: SecretToPromiseFunction<Secret, Response>,
|
87
|
+
options?: SecretOptions
|
88
|
+
): Promise<Response | void> {
|
70
89
|
if (!secretId) {
|
71
90
|
console.error(missingSecretErrorText);
|
72
91
|
return Promise.reject(missingSecretErrorText);
|
@@ -81,9 +100,13 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
|
|
81
100
|
});
|
82
101
|
|
83
102
|
// then actual secret
|
84
|
-
await withSecretAndPrefix(
|
85
|
-
|
86
|
-
|
103
|
+
await withSecretAndPrefix(
|
104
|
+
secretId,
|
105
|
+
options.prefix,
|
106
|
+
(fetchedSecret: Secret) => {
|
107
|
+
cachedSecret = fetchedSecret;
|
108
|
+
}
|
109
|
+
);
|
87
110
|
} else {
|
88
111
|
await withSecret(secretId, (fetchedSecret: DbSecret) => {
|
89
112
|
setDbSecret(fetchedSecret);
|
@@ -97,7 +120,10 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
|
|
97
120
|
}
|
98
121
|
return fn(cachedSecret);
|
99
122
|
} catch (error) {
|
100
|
-
console.error(
|
123
|
+
console.error(
|
124
|
+
"method=withDbSecret Caught an error, refreshing secret",
|
125
|
+
error
|
126
|
+
);
|
101
127
|
// try to refetch secret in case it has changed
|
102
128
|
await withSecret(secretId, (fetchedSecret: DbSecret) => {
|
103
129
|
setDbSecret(fetchedSecret);
|
@@ -107,10 +133,15 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
|
|
107
133
|
}
|
108
134
|
}
|
109
135
|
|
110
|
-
export function checkExpectedSecretKeys<Secret>(
|
111
|
-
|
136
|
+
export function checkExpectedSecretKeys<Secret extends GenericSecret>(
|
137
|
+
keys: string[],
|
138
|
+
secret: Secret
|
139
|
+
) {
|
140
|
+
const missingKeys = keys.filter((key) => !(key in secret));
|
112
141
|
if (missingKeys.length) {
|
113
|
-
console.error(
|
114
|
-
|
142
|
+
console.error(
|
143
|
+
`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`
|
144
|
+
);
|
145
|
+
throw new Error("Expected keys were not found");
|
115
146
|
}
|
116
147
|
}
|
@@ -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 extends GenericSecret> {
|
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> {
|
|
51
51
|
this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
|
52
52
|
}
|
53
53
|
|
54
|
-
public static create<S>(
|
54
|
+
public static create<S extends GenericSecret>(
|
55
55
|
prefix = DEFAULT_PREFIX,
|
56
56
|
expectedKeys: string[] = []
|
57
57
|
) {
|
@@ -67,10 +67,7 @@ export class SecretHolder<Secret> {
|
|
67
67
|
const parsedSecret =
|
68
68
|
this.prefix === DEFAULT_PREFIX
|
69
69
|
? secret
|
70
|
-
: this.parseSecret(
|
71
|
-
secret as unknown as GenericSecret,
|
72
|
-
`${this.prefix}.`
|
73
|
-
);
|
70
|
+
: this.parseSecret(secret, `${this.prefix}.`);
|
74
71
|
|
75
72
|
if (this.expectedKeys.length > 0) {
|
76
73
|
checkExpectedSecretKeys(this.expectedKeys, parsedSecret);
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../../../../src/aws/infra/api/integration.ts"],"names":[],"mappings":";;;AAAA,+DAIoC;AAEpC,uDAAmD;AACnD,qGAAgG;AAShG,MAAa,sBAAsB;IAM/B,YAAY,MAAiB,EAAE,SAAS,GAAG,sBAAS,CAAC,UAAU;QAFtD,eAAU,GAAmB,EAAE,CAAC;QAGrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,gBAAgB,CAAC,GAAG,KAAe;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAEtE,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,iBAAiB,CAAC,GAAG,KAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACnB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CACtD,CAAC;QAEF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,MAAM,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAEpD,OAAO,IAAI,kCAAiB,CAAC,IAAI,CAAC,MAAM,EAAE;YACtC,KAAK,EAAE,KAAK;YACZ,oBAAoB;YACpB,iBAAiB,EACb,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC;gBACvB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC,uBAAuB,EAAE;YACxC,gBAAgB,EACZ,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC;gBACvB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC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