@digitraffic/common 2022.11.23-1 → 2022.11.23-test
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/integration.js +4 -8
- package/dist/aws/infra/api/response.d.ts +1 -8
- package/dist/aws/infra/api/response.js +11 -36
- package/dist/aws/infra/api/responses.d.ts +0 -8
- package/dist/aws/infra/api/responses.js +0 -8
- 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 +30 -19
- package/src/aws/infra/api/integration.ts +14 -30
- package/src/aws/infra/api/response.ts +20 -83
- package/src/aws/infra/api/responses.ts +0 -8
- package/src/aws/runtime/secrets/dbsecret.ts +54 -23
- package/src/aws/runtime/secrets/secret-holder.ts +3 -6
- package/src/database/database.ts +1 -1
- 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;
|
@@ -11,11 +11,11 @@ class DigitrafficIntegration {
|
|
11
11
|
this.mediaType = mediaType;
|
12
12
|
}
|
13
13
|
addPathParameter(...names) {
|
14
|
-
names.forEach(
|
14
|
+
names.forEach(name => this.parameters.push({ type: 'path', name }));
|
15
15
|
return this;
|
16
16
|
}
|
17
17
|
addQueryParameter(...names) {
|
18
|
-
names.forEach(
|
18
|
+
names.forEach(name => this.parameters.push({ type: 'querystring', name }));
|
19
19
|
return this;
|
20
20
|
}
|
21
21
|
build() {
|
@@ -23,12 +23,8 @@ class DigitrafficIntegration {
|
|
23
23
|
return new aws_apigateway_1.LambdaIntegration(this.lambda, {
|
24
24
|
proxy: false,
|
25
25
|
integrationResponses,
|
26
|
-
requestParameters: this.parameters.length == 0
|
27
|
-
|
28
|
-
: this.createRequestParameters(),
|
29
|
-
requestTemplates: this.parameters.length == 0
|
30
|
-
? undefined
|
31
|
-
: this.createRequestTemplates(),
|
26
|
+
requestParameters: this.parameters.length == 0 ? undefined : this.createRequestParameters(),
|
27
|
+
requestTemplates: this.parameters.length == 0 ? undefined : this.createRequestTemplates(),
|
32
28
|
passthroughBehavior: aws_apigateway_1.PassthroughBehavior.WHEN_NO_MATCH,
|
33
29
|
});
|
34
30
|
}
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import apigateway = require(
|
1
|
+
import apigateway = require('aws-cdk-lib/aws-apigateway');
|
2
2
|
import { MediaType } from "../../types/mediatypes";
|
3
|
-
import { MethodResponse } from "aws-cdk-lib/aws-apigateway";
|
4
|
-
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
5
3
|
/**
|
6
4
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
7
5
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -22,8 +20,3 @@ export declare const XmlResponseTemplate: Record<string, string>;
|
|
22
20
|
export declare const SvgResponseTemplate: Record<string, string>;
|
23
21
|
export declare const InternalServerErrorResponseTemplate: Record<string, string>;
|
24
22
|
export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
|
25
|
-
export declare class DigitrafficMethodResponse {
|
26
|
-
static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
|
27
|
-
static response200(model: IModel, mediaType?: MediaType): apigateway.MethodResponse;
|
28
|
-
static response500(model?: apigateway.IModel, mediaType?: MediaType): apigateway.MethodResponse;
|
29
|
-
}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.SvgResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
|
4
4
|
const apigateway = require("aws-cdk-lib/aws-apigateway");
|
5
5
|
const mediatypes_1 = require("../../types/mediatypes");
|
6
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
7
6
|
/**
|
8
7
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
9
8
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -28,27 +27,25 @@ const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
|
28
27
|
const messageSchema = {
|
29
28
|
schema: apigateway.JsonSchemaVersion.DRAFT4,
|
30
29
|
type: apigateway.JsonSchemaType.OBJECT,
|
31
|
-
description:
|
30
|
+
description: 'Response with message',
|
32
31
|
properties: {
|
33
32
|
message: {
|
34
33
|
type: apigateway.JsonSchemaType.STRING,
|
35
|
-
description:
|
34
|
+
description: 'Response message',
|
36
35
|
},
|
37
36
|
},
|
38
37
|
};
|
39
38
|
// DEPRECATED
|
40
39
|
exports.MessageModel = {
|
41
40
|
contentType: mediatypes_1.MediaType.APPLICATION_JSON,
|
42
|
-
modelName:
|
41
|
+
modelName: 'MessageResponseModel',
|
43
42
|
schema: messageSchema,
|
44
43
|
};
|
45
|
-
const NotFoundMessage =
|
44
|
+
const NotFoundMessage = 'Not found';
|
46
45
|
exports.NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
|
47
|
-
const InternalServerErrorMessage =
|
48
|
-
const InternalServerErrorResponse = JSON.stringify({
|
49
|
-
|
50
|
-
});
|
51
|
-
const BadRequestMessage = "Bad request";
|
46
|
+
const InternalServerErrorMessage = 'Error';
|
47
|
+
const InternalServerErrorResponse = JSON.stringify({ message: InternalServerErrorMessage });
|
48
|
+
const BadRequestMessage = 'Bad request';
|
52
49
|
const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
|
53
50
|
exports.BadRequestResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, BadRequestResponse);
|
54
51
|
exports.NotFoundResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, exports.NotFoundResponse);
|
@@ -56,31 +53,9 @@ exports.XmlResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION
|
|
56
53
|
exports.SvgResponseTemplate = createResponses(mediatypes_1.MediaType.IMAGE_SVG, BODY_FROM_INPUT_PATH);
|
57
54
|
exports.InternalServerErrorResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, InternalServerErrorResponse);
|
58
55
|
function createResponses(key, value) {
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
const map = {};
|
57
|
+
map[key] = value;
|
58
|
+
return map;
|
62
59
|
}
|
63
60
|
exports.createResponses = createResponses;
|
64
|
-
class DigitrafficMethodResponse {
|
65
|
-
static response(statusCode, model, mediaType, disableCors = false) {
|
66
|
-
return {
|
67
|
-
statusCode,
|
68
|
-
responseModels: {
|
69
|
-
[mediaType]: model,
|
70
|
-
},
|
71
|
-
responseParameters: disableCors
|
72
|
-
? {}
|
73
|
-
: {
|
74
|
-
"method.response.header.Access-Control-Allow-Origin": true,
|
75
|
-
},
|
76
|
-
};
|
77
|
-
}
|
78
|
-
static response200(model, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
79
|
-
return DigitrafficMethodResponse.response("200", model, mediaType, false);
|
80
|
-
}
|
81
|
-
static response500(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
82
|
-
return DigitrafficMethodResponse.response("500", model, mediaType, false);
|
83
|
-
}
|
84
|
-
}
|
85
|
-
exports.DigitrafficMethodResponse = DigitrafficMethodResponse;
|
86
61
|
//# sourceMappingURL=response.js.map
|
@@ -15,13 +15,7 @@ export declare const RESPONSE_404_NOT_FOUND: {
|
|
15
15
|
selectionPattern: string;
|
16
16
|
responseTemplates: Record<string, string>;
|
17
17
|
};
|
18
|
-
/**
|
19
|
-
* @Deprecated Use DigitrafficMethodResponse
|
20
|
-
*/
|
21
18
|
export declare function methodResponse(status: string, contentType: MediaType, model: IModel, parameters?: Record<string, boolean>): MethodResponse;
|
22
|
-
/**
|
23
|
-
* @Deprecated Use DigitrafficMethodResponse
|
24
|
-
*/
|
25
19
|
export declare function corsMethod(response: MethodResponse): MethodResponse;
|
26
20
|
interface IntegrationOptions {
|
27
21
|
requestParameters?: {
|
@@ -39,8 +33,6 @@ interface IntegrationOptions {
|
|
39
33
|
* Creates a default Lambda integration for a REST API resource _root_
|
40
34
|
* @param lambdaFunction The Lambda function
|
41
35
|
* @param options Options
|
42
|
-
*
|
43
|
-
* @deprecated Use DigitrafficIntegration
|
44
36
|
*/
|
45
37
|
export declare function defaultIntegration(lambdaFunction: AWSFunction, options?: IntegrationOptions): LambdaIntegration;
|
46
38
|
export declare function getResponse(response: IntegrationResponse, options?: IntegrationOptions): IntegrationResponse;
|
@@ -30,9 +30,6 @@ exports.RESPONSE_404_NOT_FOUND = {
|
|
30
30
|
selectionPattern: errors_1.NOT_FOUND_MESSAGE,
|
31
31
|
responseTemplates: response_1.NotFoundResponseTemplate,
|
32
32
|
};
|
33
|
-
/**
|
34
|
-
* @Deprecated Use DigitrafficMethodResponse
|
35
|
-
*/
|
36
33
|
function methodResponse(status, contentType, model, parameters) {
|
37
34
|
return {
|
38
35
|
statusCode: status,
|
@@ -41,9 +38,6 @@ function methodResponse(status, contentType, model, parameters) {
|
|
41
38
|
};
|
42
39
|
}
|
43
40
|
exports.methodResponse = methodResponse;
|
44
|
-
/**
|
45
|
-
* @Deprecated Use DigitrafficMethodResponse
|
46
|
-
*/
|
47
41
|
function corsMethod(response) {
|
48
42
|
return {
|
49
43
|
...response,
|
@@ -59,8 +53,6 @@ exports.corsMethod = corsMethod;
|
|
59
53
|
* Creates a default Lambda integration for a REST API resource _root_
|
60
54
|
* @param lambdaFunction The Lambda function
|
61
55
|
* @param options Options
|
62
|
-
*
|
63
|
-
* @deprecated Use DigitrafficIntegration
|
64
56
|
*/
|
65
57
|
function defaultIntegration(lambdaFunction, options) {
|
66
58
|
return new aws_apigateway_1.LambdaIntegration(lambdaFunction, {
|
@@ -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-test",
|
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
|
-
"
|
20
|
+
"peerDependencies": {
|
21
|
+
"pg-promise": "^10.12.0",
|
22
|
+
"spex": "^3.0.0",
|
23
|
+
"constructs": "^10.1.131",
|
29
24
|
"@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
|
30
25
|
"@types/geojson": "^7946.0.10",
|
31
|
-
"aws-cdk-lib": "2.
|
26
|
+
"aws-cdk-lib": "2.50.0",
|
32
27
|
"aws-sdk": "2.1241.0",
|
33
28
|
"axios": "^0.21.1",
|
34
29
|
"change-case": "4.1.2",
|
35
|
-
"constructs": "10.1.131",
|
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",
|
@@ -49,7 +54,6 @@
|
|
49
54
|
"@typescript-eslint/parser": "^5.39.0",
|
50
55
|
"eslint": "^8.24.0",
|
51
56
|
"eslint-config-prettier": "^8.5.0",
|
52
|
-
"eslint-plugin-deprecation": "1.3.3",
|
53
57
|
"husky": ">=6",
|
54
58
|
"jest": "^29.1.1",
|
55
59
|
"jest-junit": "^14.0.1",
|
@@ -58,8 +62,8 @@
|
|
58
62
|
"ramda": "^0.28.0",
|
59
63
|
"rimraf": "^3.0.2",
|
60
64
|
"sinon": "^14.0.0",
|
61
|
-
"ts-jest": "^29.0.
|
62
|
-
"typescript": "^4.
|
65
|
+
"ts-jest": "^29.0.2",
|
66
|
+
"typescript": "^4.7.4"
|
63
67
|
},
|
64
68
|
"externals": [
|
65
69
|
"aws-sdk",
|
@@ -67,5 +71,12 @@
|
|
67
71
|
],
|
68
72
|
"lint-staged": {
|
69
73
|
"*.{js,ts,css,md,yml,yaml,json}": "prettier --write"
|
74
|
+
},
|
75
|
+
"scripts": {
|
76
|
+
"build": "tsc",
|
77
|
+
"lint": "eslint --cache .",
|
78
|
+
"eslint-report": "eslint . --format html",
|
79
|
+
"clean": "rimraf dist output",
|
80
|
+
"test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest"
|
70
81
|
}
|
71
|
-
}
|
82
|
+
}
|