@digitraffic/common 2024.1.10-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 +30 -35
- 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 +24 -31
- package/dist/aws/infra/stack/stack.d.ts +3 -4
- 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 +14 -18
- 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.js +10 -14
- 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 +107 -18
- 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 +2 -2
- package/src/aws/infra/stack/lambda-configs.ts +2 -2
- 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 +1 -1
- 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/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,5 +1,5 @@
|
|
1
|
-
import { DtLogger } from "../../runtime/dt-logger";
|
2
|
-
import { LambdaResponse } from "../../types/lambda-response";
|
1
|
+
import { DtLogger } from "../../runtime/dt-logger.js";
|
2
|
+
import { LambdaResponse } from "../../types/lambda-response.js";
|
3
3
|
export type LoggingHandler = (method: () => Promise<LambdaResponse>, logger: DtLogger) => Promise<LambdaResponse>;
|
4
4
|
export type ErrorHandler = (error: unknown, logger: DtLogger) => LambdaResponse;
|
5
5
|
/**
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.createJsonLoggingHandler = exports.HandlerFactory = void 0;
|
4
|
-
const utils_1 = require("../../../utils/utils");
|
5
|
-
const functionName = (0, utils_1.getEnvVariableOrElse)("AWS_LAMBDA_FUNCTION_NAME", "test");
|
1
|
+
import { getEnvVariableOrElse } from "../../../utils/utils.js";
|
2
|
+
const functionName = getEnvVariableOrElse("AWS_LAMBDA_FUNCTION_NAME", "test");
|
6
3
|
/**
|
7
4
|
* Factory class for creating lambda-handler functions. You can set functionality to handle logging and error-handling,
|
8
5
|
* with the defaults:
|
@@ -12,7 +9,7 @@ const functionName = (0, utils_1.getEnvVariableOrElse)("AWS_LAMBDA_FUNCTION_NAME
|
|
12
9
|
* You should instantiate HandlerFactory in your project with desired error handling and use the factory instance for
|
13
10
|
* creating handler-functions for your lambdas.
|
14
11
|
*/
|
15
|
-
class HandlerFactory {
|
12
|
+
export class HandlerFactory {
|
16
13
|
constructor() {
|
17
14
|
this.loggingHandler = async (method) => {
|
18
15
|
const start = Date.now();
|
@@ -48,8 +45,7 @@ class HandlerFactory {
|
|
48
45
|
};
|
49
46
|
}
|
50
47
|
}
|
51
|
-
|
52
|
-
function createJsonLoggingHandler() {
|
48
|
+
export function createJsonLoggingHandler() {
|
53
49
|
return async (method, logger) => {
|
54
50
|
const start = Date.now();
|
55
51
|
try {
|
@@ -63,5 +59,4 @@ function createJsonLoggingHandler() {
|
|
63
59
|
}
|
64
60
|
};
|
65
61
|
}
|
66
|
-
exports.createJsonLoggingHandler = createJsonLoggingHandler;
|
67
62
|
//# sourceMappingURL=handler-factory.js.map
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { IFunction } from "aws-cdk-lib/aws-lambda";
|
3
|
-
import { MediaType } from "../../types/mediatypes";
|
3
|
+
import { MediaType } from "../../types/mediatypes.js";
|
4
4
|
type ParameterType = "path" | "querystring" | "multivaluequerystring" | "context" | "header";
|
5
5
|
interface ApiParameter {
|
6
6
|
type: ParameterType;
|
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const digitraffic_integration_response_1 = require("../../runtime/digitraffic-integration-response");
|
7
|
-
class DigitrafficIntegration {
|
8
|
-
constructor(lambda, mediaType = mediatypes_1.MediaType.TEXT_PLAIN, sunset) {
|
1
|
+
import { LambdaIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import { MediaType } from "../../types/mediatypes.js";
|
3
|
+
import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response.js";
|
4
|
+
export class DigitrafficIntegration {
|
5
|
+
constructor(lambda, mediaType = MediaType.TEXT_PLAIN, sunset) {
|
9
6
|
this.parameters = [];
|
10
7
|
this.lambda = lambda;
|
11
8
|
this.mediaType = mediaType;
|
@@ -44,7 +41,7 @@ class DigitrafficIntegration {
|
|
44
41
|
}
|
45
42
|
build() {
|
46
43
|
const integrationResponses = this.createResponses();
|
47
|
-
return new
|
44
|
+
return new LambdaIntegration(this.lambda, {
|
48
45
|
proxy: false,
|
49
46
|
integrationResponses,
|
50
47
|
requestParameters: this.parameters.length == 0
|
@@ -53,7 +50,7 @@ class DigitrafficIntegration {
|
|
53
50
|
requestTemplates: this.parameters.length == 0
|
54
51
|
? undefined
|
55
52
|
: this.createRequestTemplates(),
|
56
|
-
passthroughBehavior:
|
53
|
+
passthroughBehavior: PassthroughBehavior.WHEN_NO_MATCH,
|
57
54
|
});
|
58
55
|
}
|
59
56
|
createRequestParameters() {
|
@@ -81,12 +78,11 @@ class DigitrafficIntegration {
|
|
81
78
|
}
|
82
79
|
});
|
83
80
|
return {
|
84
|
-
[
|
81
|
+
[MediaType.APPLICATION_JSON]: JSON.stringify(requestJson),
|
85
82
|
};
|
86
83
|
}
|
87
84
|
createResponses() {
|
88
|
-
return [
|
85
|
+
return [DigitrafficIntegrationResponse.ok(this.mediaType, this.sunset)];
|
89
86
|
}
|
90
87
|
}
|
91
|
-
exports.DigitrafficIntegration = DigitrafficIntegration;
|
92
88
|
//# sourceMappingURL=integration.js.map
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { MediaType } from "../../types/mediatypes";
|
2
|
-
import { JsonSchema, MethodResponse } from "aws-cdk-lib/aws-apigateway";
|
3
|
-
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
1
|
+
import { MediaType } from "../../types/mediatypes.js";
|
2
|
+
import { JsonSchema, MethodResponse, type IModel } from "aws-cdk-lib/aws-apigateway";
|
4
3
|
/**
|
5
4
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
6
5
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const mediatypes_1 = require("../../types/mediatypes");
|
5
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
|
-
const date_utils_1 = require("../../../utils/date-utils");
|
1
|
+
import { MediaType } from "../../types/mediatypes.js";
|
2
|
+
import { JsonSchemaType, JsonSchemaVersion, Model } from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import { dateFromIsoString } from "../../../utils/date-utils.js";
|
7
4
|
/**
|
8
5
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
9
6
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -15,7 +12,7 @@ const date_utils_1 = require("../../../utils/date-utils");
|
|
15
12
|
* If fileName is set, then Content-Disposition-header will be set to use it
|
16
13
|
* If timestamp is set, then ETag & Last-Modified headers will be set
|
17
14
|
*/
|
18
|
-
|
15
|
+
export const RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))
|
19
16
|
#if ($inputRoot.status != 200)
|
20
17
|
#set ($context.responseOverride.status = $inputRoot.status)
|
21
18
|
#set ($context.responseOverride.header.Content-Type = 'text/plain')
|
@@ -40,33 +37,32 @@ $util.base64Decode($inputRoot.body)`;
|
|
40
37
|
* Sunset: Tue, 20 Dec 2022 00:00:00 GMT
|
41
38
|
* @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
|
42
39
|
*/
|
43
|
-
const getDeprecatedDefaultLambdaResponse = (sunset) => {
|
40
|
+
export const getDeprecatedDefaultLambdaResponse = (sunset) => {
|
44
41
|
const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
|
45
|
-
#set ($context.responseOverride.header.Sunset = '${
|
46
|
-
return
|
42
|
+
#set ($context.responseOverride.header.Sunset = '${dateFromIsoString(sunset).toUTCString()}')`;
|
43
|
+
return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
|
47
44
|
};
|
48
|
-
exports.getDeprecatedDefaultLambdaResponse = getDeprecatedDefaultLambdaResponse;
|
49
45
|
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
50
46
|
/// @deprecated
|
51
47
|
const messageSchema = {
|
52
|
-
schema:
|
53
|
-
type:
|
48
|
+
schema: JsonSchemaVersion.DRAFT4,
|
49
|
+
type: JsonSchemaType.OBJECT,
|
54
50
|
description: "Response with message",
|
55
51
|
properties: {
|
56
52
|
message: {
|
57
|
-
type:
|
53
|
+
type: JsonSchemaType.STRING,
|
58
54
|
description: "Response message",
|
59
55
|
},
|
60
56
|
},
|
61
57
|
};
|
62
58
|
/// @deprecated
|
63
|
-
|
64
|
-
contentType:
|
59
|
+
export const MessageModel = {
|
60
|
+
contentType: MediaType.APPLICATION_JSON,
|
65
61
|
modelName: "MessageResponseModel",
|
66
62
|
schema: messageSchema,
|
67
63
|
};
|
68
64
|
const NotFoundMessage = "Not found";
|
69
|
-
|
65
|
+
export const NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
|
70
66
|
const InternalServerErrorMessage = "Error";
|
71
67
|
const InternalServerErrorResponse = JSON.stringify({
|
72
68
|
message: InternalServerErrorMessage,
|
@@ -74,22 +70,22 @@ const InternalServerErrorResponse = JSON.stringify({
|
|
74
70
|
const BadRequestMessage = "Bad request";
|
75
71
|
const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
|
76
72
|
/// @deprecated
|
77
|
-
|
78
|
-
[
|
73
|
+
export const BadRequestResponseTemplate = {
|
74
|
+
[MediaType.APPLICATION_JSON]: BadRequestResponse,
|
79
75
|
};
|
80
76
|
/// @deprecated
|
81
|
-
|
82
|
-
[
|
77
|
+
export const NotFoundResponseTemplate = {
|
78
|
+
[MediaType.APPLICATION_JSON]: NotFoundResponse,
|
83
79
|
};
|
84
80
|
/// @deprecated
|
85
|
-
|
86
|
-
[
|
81
|
+
export const XmlResponseTemplate = {
|
82
|
+
[MediaType.APPLICATION_XML]: BODY_FROM_INPUT_PATH,
|
87
83
|
};
|
88
84
|
/// @deprecated
|
89
|
-
|
90
|
-
[
|
85
|
+
export const InternalServerErrorResponseTemplate = {
|
86
|
+
[MediaType.APPLICATION_JSON]: InternalServerErrorResponse,
|
91
87
|
};
|
92
|
-
class DigitrafficMethodResponse {
|
88
|
+
export class DigitrafficMethodResponse {
|
93
89
|
static response(statusCode, model, mediaType, disableCors = false, deprecation = false) {
|
94
90
|
return {
|
95
91
|
statusCode,
|
@@ -107,15 +103,14 @@ class DigitrafficMethodResponse {
|
|
107
103
|
},
|
108
104
|
};
|
109
105
|
}
|
110
|
-
static response200(model, mediaType =
|
106
|
+
static response200(model, mediaType = MediaType.APPLICATION_JSON) {
|
111
107
|
return DigitrafficMethodResponse.response("200", model, mediaType, false);
|
112
108
|
}
|
113
|
-
static response500(model =
|
109
|
+
static response500(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
|
114
110
|
return DigitrafficMethodResponse.response("500", model, mediaType, false);
|
115
111
|
}
|
116
|
-
static response400(model =
|
112
|
+
static response400(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
|
117
113
|
return DigitrafficMethodResponse.response("400", model, mediaType, false);
|
118
114
|
}
|
119
115
|
}
|
120
|
-
exports.DigitrafficMethodResponse = DigitrafficMethodResponse;
|
121
116
|
//# sourceMappingURL=response.js.map
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { LambdaIntegration, MethodResponse, IntegrationResponse, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
|
1
|
+
import { LambdaIntegration, MethodResponse, IntegrationResponse, PassthroughBehavior, type IModel } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
|
3
|
-
import {
|
4
|
-
import { MediaType } from "../../types/mediatypes";
|
3
|
+
import { MediaType } from "../../types/mediatypes.js";
|
5
4
|
export declare const RESPONSE_200_OK: IntegrationResponse;
|
6
5
|
export declare const RESPONSE_400_BAD_REQUEST: IntegrationResponse;
|
7
6
|
export declare const RESPONSE_500_SERVER_ERROR: IntegrationResponse;
|
@@ -1,45 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const response_1 = require("./response");
|
5
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
|
-
const errors_1 = require("../../types/errors");
|
1
|
+
import { InternalServerErrorResponseTemplate, XmlResponseTemplate, NotFoundResponseTemplate, BadRequestResponseTemplate, } from "./response.js";
|
2
|
+
import { LambdaIntegration, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import { BAD_REQUEST_MESSAGE, ERROR_MESSAGE, NOT_FOUND_MESSAGE, } from "../../types/errors.js";
|
7
4
|
/// @deprecated
|
8
|
-
|
5
|
+
export const RESPONSE_200_OK = {
|
9
6
|
statusCode: "200",
|
10
7
|
};
|
11
8
|
/// @deprecated
|
12
|
-
|
9
|
+
export const RESPONSE_400_BAD_REQUEST = {
|
13
10
|
statusCode: "400",
|
14
|
-
selectionPattern:
|
15
|
-
responseTemplates:
|
11
|
+
selectionPattern: BAD_REQUEST_MESSAGE,
|
12
|
+
responseTemplates: BadRequestResponseTemplate,
|
16
13
|
};
|
17
14
|
/// @deprecated
|
18
|
-
|
15
|
+
export const RESPONSE_500_SERVER_ERROR = {
|
19
16
|
statusCode: "500",
|
20
|
-
selectionPattern:
|
21
|
-
responseTemplates:
|
17
|
+
selectionPattern: ERROR_MESSAGE,
|
18
|
+
responseTemplates: InternalServerErrorResponseTemplate,
|
22
19
|
};
|
23
20
|
/// @deprecated
|
24
21
|
const RESPONSE_XML = {
|
25
|
-
responseTemplates:
|
22
|
+
responseTemplates: XmlResponseTemplate,
|
26
23
|
};
|
27
24
|
/// @deprecated
|
28
|
-
|
25
|
+
export const RESPONSE_CORS_INTEGRATION = {
|
29
26
|
responseParameters: {
|
30
27
|
"method.response.header.Access-Control-Allow-Origin": "'*'",
|
31
28
|
},
|
32
29
|
};
|
33
30
|
/// @deprecated
|
34
|
-
|
31
|
+
export const RESPONSE_404_NOT_FOUND = {
|
35
32
|
statusCode: "404",
|
36
|
-
selectionPattern:
|
37
|
-
responseTemplates:
|
33
|
+
selectionPattern: NOT_FOUND_MESSAGE,
|
34
|
+
responseTemplates: NotFoundResponseTemplate,
|
38
35
|
};
|
39
36
|
/**
|
40
37
|
* @deprecated Use DigitrafficMethodResponse
|
41
38
|
*/
|
42
|
-
function methodResponse(status, contentType, model, parameters) {
|
39
|
+
export function methodResponse(status, contentType, model, parameters) {
|
43
40
|
return {
|
44
41
|
statusCode: status,
|
45
42
|
responseModels: {
|
@@ -48,7 +45,6 @@ function methodResponse(status, contentType, model, parameters) {
|
|
48
45
|
responseParameters: parameters ?? {},
|
49
46
|
};
|
50
47
|
}
|
51
|
-
exports.methodResponse = methodResponse;
|
52
48
|
/**
|
53
49
|
* Creates a default Lambda integration for a REST API resource _root_
|
54
50
|
* @param lambdaFunction The Lambda function
|
@@ -56,29 +52,27 @@ exports.methodResponse = methodResponse;
|
|
56
52
|
*
|
57
53
|
* @deprecated Use DigitrafficIntegration
|
58
54
|
*/
|
59
|
-
function defaultIntegration(lambdaFunction, options) {
|
60
|
-
return new
|
55
|
+
export function defaultIntegration(lambdaFunction, options) {
|
56
|
+
return new LambdaIntegration(lambdaFunction, {
|
61
57
|
proxy: false,
|
62
58
|
integrationResponses: options?.responses ?? [
|
63
|
-
getResponse(
|
64
|
-
getResponse(
|
65
|
-
getResponse(
|
66
|
-
getResponse(
|
59
|
+
getResponse(RESPONSE_200_OK, options),
|
60
|
+
getResponse(RESPONSE_400_BAD_REQUEST, options),
|
61
|
+
getResponse(RESPONSE_404_NOT_FOUND, options),
|
62
|
+
getResponse(RESPONSE_500_SERVER_ERROR, options),
|
67
63
|
],
|
68
64
|
requestParameters: options?.requestParameters ?? {},
|
69
65
|
requestTemplates: options?.requestTemplates ?? {},
|
70
|
-
passthroughBehavior: options?.passthroughBehavior ??
|
66
|
+
passthroughBehavior: options?.passthroughBehavior ?? PassthroughBehavior.WHEN_NO_MATCH,
|
71
67
|
});
|
72
68
|
}
|
73
|
-
|
74
|
-
function getResponse(response, options) {
|
69
|
+
export function getResponse(response, options) {
|
75
70
|
if (options?.xml) {
|
76
71
|
response = { ...response, ...RESPONSE_XML };
|
77
72
|
}
|
78
73
|
if (!options?.disableCors) {
|
79
|
-
response = { ...response, ...
|
74
|
+
response = { ...response, ...RESPONSE_CORS_INTEGRATION };
|
80
75
|
}
|
81
76
|
return response;
|
82
77
|
}
|
83
|
-
exports.getResponse = getResponse;
|
84
78
|
//# sourceMappingURL=responses.js.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { MockIntegration, Resource } from "aws-cdk-lib/aws-apigateway";
|
2
|
-
import { MediaType } from "../../types/mediatypes";
|
2
|
+
import { MediaType } from "../../types/mediatypes.js";
|
3
3
|
/**
|
4
4
|
* Static integration, that returns the given response with given mediaType from given resource.
|
5
5
|
*
|
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
5
|
-
const mediatypes_1 = require("../../types/mediatypes");
|
6
|
-
const responses_1 = require("./responses");
|
1
|
+
import { MockIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import { MediaType } from "../../types/mediatypes.js";
|
3
|
+
import { RESPONSE_CORS_INTEGRATION } from "./responses.js";
|
7
4
|
const INTEGRATION_RESPONSE_200 = `{
|
8
5
|
"statusCode": 200
|
9
6
|
}`;
|
@@ -17,11 +14,11 @@ const METHOD_RESPONSE_200 = {
|
|
17
14
|
* @param mediaType
|
18
15
|
* @param response
|
19
16
|
*/
|
20
|
-
class DigitrafficStaticIntegration extends
|
17
|
+
export class DigitrafficStaticIntegration extends MockIntegration {
|
21
18
|
constructor(resource, mediaType, response, enableCors = true, apiKeyRequired = true) {
|
22
19
|
const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, enableCors);
|
23
20
|
super({
|
24
|
-
passthroughBehavior:
|
21
|
+
passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
|
25
22
|
requestTemplates: {
|
26
23
|
[mediaType]: INTEGRATION_RESPONSE_200,
|
27
24
|
},
|
@@ -37,7 +34,7 @@ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
|
|
37
34
|
});
|
38
35
|
}
|
39
36
|
static json(resource, response, enableCors = true, apiKeyRequired = true) {
|
40
|
-
return new DigitrafficStaticIntegration(resource,
|
37
|
+
return new DigitrafficStaticIntegration(resource, MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired);
|
41
38
|
}
|
42
39
|
static createIntegrationResponse(response, mediaType, enableCors) {
|
43
40
|
const integrationResponse = {
|
@@ -47,7 +44,7 @@ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
|
|
47
44
|
},
|
48
45
|
};
|
49
46
|
return enableCors
|
50
|
-
? { ...integrationResponse, ...
|
47
|
+
? { ...integrationResponse, ...RESPONSE_CORS_INTEGRATION }
|
51
48
|
: integrationResponse;
|
52
49
|
}
|
53
50
|
static createMethodResponse(enableCors) {
|
@@ -56,7 +53,6 @@ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
|
|
56
53
|
: METHOD_RESPONSE_200;
|
57
54
|
}
|
58
55
|
}
|
59
|
-
exports.DigitrafficStaticIntegration = DigitrafficStaticIntegration;
|
60
56
|
function corsMethod(response) {
|
61
57
|
return {
|
62
58
|
...response,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Construct } from "constructs";
|
2
|
-
import { CanaryParameters } from "./canary-parameters";
|
2
|
+
import { CanaryParameters } from "./canary-parameters.js";
|
3
3
|
import { Canary } from "aws-cdk-lib/aws-synthetics";
|
4
4
|
export declare class CanaryAlarm {
|
5
5
|
constructor(stack: Construct, canary: Canary, params: CanaryParameters);
|
@@ -1,24 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const aws_cloudwatch_actions_1 = require("aws-cdk-lib/aws-cloudwatch-actions");
|
6
|
-
const aws_sns_1 = require("aws-cdk-lib/aws-sns");
|
7
|
-
class CanaryAlarm {
|
1
|
+
import { Alarm, ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
2
|
+
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
3
|
+
import { Topic } from "aws-cdk-lib/aws-sns";
|
4
|
+
export class CanaryAlarm {
|
8
5
|
constructor(stack, canary, params) {
|
9
6
|
const alarmName = params.alarm?.alarmName ?? `${params.name}-alarm`;
|
10
|
-
const alarm = new
|
7
|
+
const alarm = new Alarm(stack, alarmName, {
|
11
8
|
alarmName,
|
12
9
|
alarmDescription: params.alarm?.description ?? "",
|
13
10
|
metric: canary.metricSuccessPercent(),
|
14
11
|
evaluationPeriods: params.alarm?.evalutionPeriods ?? 1,
|
15
12
|
threshold: params.alarm?.threshold ?? 100,
|
16
|
-
comparisonOperator:
|
13
|
+
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
|
17
14
|
});
|
18
15
|
if (params.alarm?.topicArn) {
|
19
|
-
alarm.addAlarmAction(new
|
16
|
+
alarm.addAlarmAction(new SnsAction(Topic.fromTopicArn(stack, `${alarmName}-action`, params.alarm.topicArn)));
|
20
17
|
}
|
21
18
|
}
|
22
19
|
}
|
23
|
-
exports.CanaryAlarm = CanaryAlarm;
|
24
20
|
//# sourceMappingURL=canary-alarm.js.map
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
exports.ENV_API_KEY = "apiKeyId";
|
5
|
-
exports.ENV_HOSTNAME = "hostname";
|
6
|
-
exports.ENV_SECRET = "secret";
|
1
|
+
export const ENV_API_KEY = "apiKeyId";
|
2
|
+
export const ENV_HOSTNAME = "hostname";
|
3
|
+
export const ENV_SECRET = "secret";
|
7
4
|
//# sourceMappingURL=canary-keys.js.map
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DigitrafficCanaryRole = void 0;
|
4
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
1
|
+
import { ManagedPolicy, PolicyStatement, Role, ServicePrincipal, } from "aws-cdk-lib/aws-iam";
|
5
2
|
const BASE_POLICY_STATEMENT_PROPS = {
|
6
3
|
actions: [
|
7
4
|
"logs:CreateLogStream",
|
@@ -21,16 +18,16 @@ const CLOUDWATCH_STATEMENT_PROPS = {
|
|
21
18
|
},
|
22
19
|
},
|
23
20
|
};
|
24
|
-
class DigitrafficCanaryRole extends
|
21
|
+
export class DigitrafficCanaryRole extends Role {
|
25
22
|
constructor(stack, canaryName) {
|
26
23
|
super(stack, "canary-role-" + canaryName, {
|
27
|
-
assumedBy: new
|
24
|
+
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
|
28
25
|
managedPolicies: [
|
29
|
-
|
26
|
+
ManagedPolicy.fromAwsManagedPolicyName("CloudWatchSyntheticsFullAccess"),
|
30
27
|
],
|
31
28
|
});
|
32
|
-
this.addToPolicy(new
|
33
|
-
this.addToPolicy(new
|
29
|
+
this.addToPolicy(new PolicyStatement(BASE_POLICY_STATEMENT_PROPS));
|
30
|
+
this.addToPolicy(new PolicyStatement(CLOUDWATCH_STATEMENT_PROPS));
|
34
31
|
}
|
35
32
|
/**
|
36
33
|
* Provides permissions to access resources within a VPC.
|
@@ -39,7 +36,7 @@ class DigitrafficCanaryRole extends aws_iam_1.Role {
|
|
39
36
|
// Won't work :(
|
40
37
|
// this.addToPolicy(new PolicyStatement(DB_STATEMENT_PROPS));
|
41
38
|
// Works
|
42
|
-
this.addManagedPolicy(
|
39
|
+
this.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaVPCAccessExecutionRole"));
|
43
40
|
return this;
|
44
41
|
}
|
45
42
|
/**
|
@@ -47,9 +44,8 @@ class DigitrafficCanaryRole extends aws_iam_1.Role {
|
|
47
44
|
* A UrlCanary needs these permissions to e.g. access a private API Gateway endpoint in a VPC.
|
48
45
|
*/
|
49
46
|
withVpcAccess() {
|
50
|
-
this.addManagedPolicy(
|
47
|
+
this.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaVPCAccessExecutionRole"));
|
51
48
|
return this;
|
52
49
|
}
|
53
50
|
}
|
54
|
-
exports.DigitrafficCanaryRole = DigitrafficCanaryRole;
|
55
51
|
//# sourceMappingURL=canary-role.js.map
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Canary } from "aws-cdk-lib/aws-synthetics";
|
2
2
|
import { Role } from "aws-cdk-lib/aws-iam";
|
3
|
-
import { CanaryParameters } from "./canary-parameters";
|
3
|
+
import { CanaryParameters } from "./canary-parameters.js";
|
4
4
|
import { Construct } from "constructs";
|
5
|
-
import { LambdaEnvironment } from "../stack/lambda-configs";
|
5
|
+
import { LambdaEnvironment } from "../stack/lambda-configs.js";
|
6
6
|
export declare class DigitrafficCanary extends Canary {
|
7
7
|
constructor(scope: Construct, canaryName: string, role: Role, params: CanaryParameters, environmentVariables: LambdaEnvironment);
|
8
8
|
}
|
@@ -1,16 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const aws_synthetics_1 = require("aws-cdk-lib/aws-synthetics");
|
6
|
-
const canary_alarm_1 = require("./canary-alarm");
|
7
|
-
class DigitrafficCanary extends aws_synthetics_1.Canary {
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
2
|
+
import { AssetCode, Canary, Runtime, Schedule, Test, } from "aws-cdk-lib/aws-synthetics";
|
3
|
+
import { CanaryAlarm } from "./canary-alarm.js";
|
4
|
+
export class DigitrafficCanary extends Canary {
|
8
5
|
constructor(scope, canaryName, role, params, environmentVariables) {
|
9
6
|
super(scope, canaryName, {
|
10
|
-
runtime:
|
7
|
+
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
|
11
8
|
role,
|
12
|
-
test:
|
13
|
-
code: new
|
9
|
+
test: Test.custom({
|
10
|
+
code: new AssetCode("dist", {
|
14
11
|
exclude: ["lambda", "out", "canaries"],
|
15
12
|
}),
|
16
13
|
handler: params.handler,
|
@@ -20,11 +17,10 @@ class DigitrafficCanary extends aws_synthetics_1.Canary {
|
|
20
17
|
...params.canaryEnv,
|
21
18
|
},
|
22
19
|
canaryName,
|
23
|
-
schedule: params.schedule ??
|
20
|
+
schedule: params.schedule ?? Schedule.rate(Duration.minutes(15)),
|
24
21
|
});
|
25
22
|
this.artifactsBucket.grantWrite(role);
|
26
|
-
new
|
23
|
+
new CanaryAlarm(scope, this, params);
|
27
24
|
}
|
28
25
|
}
|
29
|
-
exports.DigitrafficCanary = DigitrafficCanary;
|
30
26
|
//# sourceMappingURL=canary.js.map
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Role } from "aws-cdk-lib/aws-iam";
|
2
2
|
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
3
|
-
import { CanaryParameters } from "./canary-parameters";
|
4
|
-
import { DigitrafficCanary } from "./canary";
|
5
|
-
import { DigitrafficStack } from "../stack/stack";
|
3
|
+
import { CanaryParameters } from "./canary-parameters.js";
|
4
|
+
import { DigitrafficCanary } from "./canary.js";
|
5
|
+
import { DigitrafficStack } from "../stack/stack.js";
|
6
6
|
export declare class DatabaseCanary extends DigitrafficCanary {
|
7
7
|
constructor(stack: DigitrafficStack, role: Role, secret: ISecret, params: CanaryParameters);
|
8
8
|
static create(stack: DigitrafficStack, role: Role, params: CanaryParameters): DatabaseCanary;
|
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
7
|
-
const canary_1 = require("./canary");
|
8
|
-
class DatabaseCanary extends canary_1.DigitrafficCanary {
|
1
|
+
import { CfnCanary } from "aws-cdk-lib/aws-synthetics";
|
2
|
+
import { Schedule } from "aws-cdk-lib/aws-events";
|
3
|
+
import { Duration } from "aws-cdk-lib";
|
4
|
+
import { DigitrafficCanary } from "./canary.js";
|
5
|
+
export class DatabaseCanary extends DigitrafficCanary {
|
9
6
|
constructor(stack, role, secret, params) {
|
10
7
|
const canaryName = `${params.name}-db`;
|
11
8
|
const environmentVariables = stack.createDefaultLambdaEnvironment(`Synthetics-${canaryName}`);
|
@@ -14,7 +11,7 @@ class DatabaseCanary extends canary_1.DigitrafficCanary {
|
|
14
11
|
this.artifactsBucket.grantWrite(this.role);
|
15
12
|
secret.grantRead(this.role);
|
16
13
|
// need to override vpc and security group, can't do this with cdk
|
17
|
-
if (this.node.defaultChild instanceof
|
14
|
+
if (this.node.defaultChild instanceof CfnCanary) {
|
18
15
|
const subnetIds = stack.vpc === undefined
|
19
16
|
? []
|
20
17
|
: stack.vpc.privateSubnets.map((subnet) => subnet.subnetId);
|
@@ -33,7 +30,7 @@ class DatabaseCanary extends canary_1.DigitrafficCanary {
|
|
33
30
|
return new DatabaseCanary(stack, role, secret, {
|
34
31
|
...{
|
35
32
|
secret: stack.configuration.secretId,
|
36
|
-
schedule:
|
33
|
+
schedule: Schedule.rate(Duration.hours(1)),
|
37
34
|
handler: `${params.name}.handler`,
|
38
35
|
},
|
39
36
|
...params,
|
@@ -52,7 +49,7 @@ class DatabaseCanary extends canary_1.DigitrafficCanary {
|
|
52
49
|
return new DatabaseCanary(stack, role, secret, {
|
53
50
|
...{
|
54
51
|
secret: stack.configuration.secretId,
|
55
|
-
schedule:
|
52
|
+
schedule: Schedule.rate(Duration.hours(1)),
|
56
53
|
handler: `${name}-db.handler`,
|
57
54
|
name: canaryName,
|
58
55
|
alarm: {
|
@@ -66,5 +63,4 @@ class DatabaseCanary extends canary_1.DigitrafficCanary {
|
|
66
63
|
});
|
67
64
|
}
|
68
65
|
}
|
69
|
-
exports.DatabaseCanary = DatabaseCanary;
|
70
66
|
//# sourceMappingURL=database-canary.js.map
|