@digitraffic/common 2023.10.11-1 → 2023.11.21-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aws/infra/api/integration.d.ts +6 -6
- package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-parameters.d.ts +1 -1
- package/dist/aws/infra/canaries/canary.d.ts +1 -1
- package/dist/aws/infra/canaries/canary.js +6 -6
- package/dist/aws/infra/canaries/database-checker.js +5 -1
- package/dist/aws/infra/canaries/url-checker.js +7 -2
- package/dist/aws/infra/stack/monitoredfunction.js +14 -3
- package/dist/aws/infra/stack/rest_apis.js +5 -2
- package/dist/aws/infra/stack/stack-checking-aspect.js +7 -3
- package/dist/aws/runtime/secrets/secret-holder.js +5 -1
- package/dist/database/database.js +3 -1
- package/dist/utils/geometry.js +5 -1
- package/dist/utils/slack.js +7 -2
- package/package.json +32 -36
- package/src/aws/infra/api/integration.ts +6 -6
- package/src/aws/infra/canaries/canary-alarm.ts +1 -1
- package/src/aws/infra/canaries/canary-parameters.ts +1 -1
- package/src/aws/infra/canaries/canary.ts +1 -1
- package/src/aws/infra/canaries/database-checker.ts +5 -1
- package/src/aws/infra/canaries/url-checker.ts +7 -2
- package/src/aws/infra/stack/monitoredfunction.ts +12 -3
- package/src/aws/infra/stack/rest_apis.ts +4 -4
- package/src/aws/infra/stack/stack-checking-aspect.ts +4 -3
- package/src/aws/runtime/secrets/secret-holder.ts +5 -1
- package/src/database/database.ts +4 -1
- package/src/utils/geometry.ts +6 -1
- package/src/utils/slack.ts +9 -5
@@ -6,28 +6,28 @@ interface ApiParameter {
|
|
6
6
|
type: ParameterType;
|
7
7
|
name: string;
|
8
8
|
}
|
9
|
-
export declare class DigitrafficIntegration {
|
9
|
+
export declare class DigitrafficIntegration<T extends string> {
|
10
10
|
readonly lambda: IFunction;
|
11
11
|
readonly mediaType: MediaType;
|
12
12
|
readonly parameters: ApiParameter[];
|
13
13
|
readonly sunset?: string;
|
14
14
|
constructor(lambda: IFunction, mediaType?: MediaType, sunset?: string);
|
15
|
-
addPathParameter(...names:
|
16
|
-
addQueryParameter(...names:
|
17
|
-
addMultiValueQueryParameter(...names:
|
15
|
+
addPathParameter(...names: T[]): this;
|
16
|
+
addQueryParameter(...names: T[]): this;
|
17
|
+
addMultiValueQueryParameter(...names: T[]): this;
|
18
18
|
/**
|
19
19
|
* Note that context parameter values needs to be in json format as they will be parsed in template as json.
|
20
20
|
* See createRequestTemplates below.
|
21
21
|
* @param names for the parameters
|
22
22
|
* @returns
|
23
23
|
*/
|
24
|
-
addContextParameter(...names:
|
24
|
+
addContextParameter(...names: T[]): this;
|
25
25
|
/**
|
26
26
|
* Do not use Authorization header as that will be consumed by ApiGW.
|
27
27
|
* If Authorization header is needed, use lambda authorizers.
|
28
28
|
* @param names for the headers
|
29
29
|
*/
|
30
|
-
addHeaderParameter(...names:
|
30
|
+
addHeaderParameter(...names: T[]): this;
|
31
31
|
build(): LambdaIntegration;
|
32
32
|
createRequestParameters(): Record<string, string>;
|
33
33
|
createRequestTemplates(): Record<string, string>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Construct } from "constructs";
|
2
2
|
import { CanaryParameters } from "./canary-parameters";
|
3
|
-
import { Canary } from "
|
3
|
+
import { Canary } from "aws-cdk-lib/aws-synthetics";
|
4
4
|
export declare class CanaryAlarm {
|
5
5
|
constructor(stack: Construct, canary: Canary, params: CanaryParameters);
|
6
6
|
}
|
@@ -2,15 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DigitrafficCanary = void 0;
|
4
4
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
5
|
-
const
|
5
|
+
const aws_synthetics_1 = require("aws-cdk-lib/aws-synthetics");
|
6
6
|
const canary_alarm_1 = require("./canary-alarm");
|
7
|
-
class DigitrafficCanary extends
|
7
|
+
class DigitrafficCanary extends aws_synthetics_1.Canary {
|
8
8
|
constructor(scope, canaryName, role, params, environmentVariables) {
|
9
9
|
super(scope, canaryName, {
|
10
|
-
runtime:
|
10
|
+
runtime: aws_synthetics_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
|
11
11
|
role,
|
12
|
-
test:
|
13
|
-
code: new
|
12
|
+
test: aws_synthetics_1.Test.custom({
|
13
|
+
code: new aws_synthetics_1.AssetCode("dist", {
|
14
14
|
exclude: ["lambda", "out", "canaries"],
|
15
15
|
}),
|
16
16
|
handler: params.handler,
|
@@ -20,7 +20,7 @@ class DigitrafficCanary extends aws_synthetics_alpha_1.Canary {
|
|
20
20
|
...params.canaryEnv,
|
21
21
|
},
|
22
22
|
canaryName,
|
23
|
-
schedule: params.schedule ??
|
23
|
+
schedule: params.schedule ?? aws_synthetics_1.Schedule.rate(aws_cdk_lib_1.Duration.minutes(15)),
|
24
24
|
});
|
25
25
|
this.artifactsBucket.grantWrite(role);
|
26
26
|
new canary_alarm_1.CanaryAlarm(scope, this, params);
|
@@ -5,6 +5,7 @@ const database_1 = require("../../../database/database");
|
|
5
5
|
const proxy_holder_1 = require("../../runtime/secrets/proxy-holder");
|
6
6
|
const rds_holder_1 = require("../../runtime/secrets/rds-holder");
|
7
7
|
const utils_1 = require("../../../utils/utils");
|
8
|
+
const dt_logger_default_1 = require("../../runtime/dt-logger-default");
|
8
9
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
9
10
|
const synthetics = require("Synthetics");
|
10
11
|
class DatabaseCheck {
|
@@ -97,7 +98,10 @@ class DatabaseCountChecker {
|
|
97
98
|
await this.credentialsFunction();
|
98
99
|
await (0, database_1.inDatabaseReadonly)(async (db) => {
|
99
100
|
for (const check of this.checks) {
|
100
|
-
|
101
|
+
dt_logger_default_1.logger.info({
|
102
|
+
method: "DatabaseCountChecker.expect",
|
103
|
+
message: "Running sql: " + check.sql,
|
104
|
+
});
|
101
105
|
const value = await db.one(check.sql);
|
102
106
|
const checkFunction = () => {
|
103
107
|
check.check(value);
|
@@ -10,6 +10,8 @@ const apikey_1 = require("../../runtime/apikey");
|
|
10
10
|
const geometry_1 = require("../../../utils/geometry");
|
11
11
|
const utils_1 = require("../../../utils/utils");
|
12
12
|
const canary_keys_1 = require("./canary-keys");
|
13
|
+
const dt_logger_default_1 = require("../../runtime/dt-logger-default");
|
14
|
+
const logging_1 = require("../../../utils/logging");
|
13
15
|
exports.API_KEY_HEADER = "x-api-key";
|
14
16
|
const baseHeaders = {
|
15
17
|
"Digitraffic-User": "internal-digitraffic-canary",
|
@@ -88,7 +90,10 @@ class UrlChecker {
|
|
88
90
|
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
89
91
|
!this.requestOptions.headers ||
|
90
92
|
!this.requestOptions.headers[exports.API_KEY_HEADER]) {
|
91
|
-
|
93
|
+
dt_logger_default_1.logger.error({
|
94
|
+
method: "UrlChecker.expect403WithoutApiKey",
|
95
|
+
message: "No Api-key defined",
|
96
|
+
});
|
92
97
|
}
|
93
98
|
const requestOptions = {
|
94
99
|
...this.requestOptions,
|
@@ -112,7 +117,7 @@ async function getResponseBody(response) {
|
|
112
117
|
return zlib.gunzipSync(body).toString();
|
113
118
|
}
|
114
119
|
catch (e) {
|
115
|
-
|
120
|
+
(0, logging_1.logException)(dt_logger_default_1.logger, e);
|
116
121
|
}
|
117
122
|
}
|
118
123
|
return body.toString();
|
@@ -1,12 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.MonitoredDBFunction = exports.MonitoredFunction = void 0;
|
4
7
|
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
5
8
|
const aws_cloudwatch_actions_1 = require("aws-cdk-lib/aws-cloudwatch-actions");
|
6
9
|
const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
|
7
10
|
const lambda_configs_1 = require("../stack/lambda-configs");
|
8
|
-
const change_case_1 = require("change-case");
|
9
11
|
const subscription_1 = require("../stack/subscription");
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
10
13
|
/**
|
11
14
|
* Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
|
12
15
|
*/
|
@@ -40,7 +43,11 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
40
43
|
*/
|
41
44
|
static createV2(stack, name, environment, functionParameters) {
|
42
45
|
const functionName = functionParameters?.functionName ??
|
43
|
-
`${stack.configuration.shortName}-${
|
46
|
+
`${stack.configuration.shortName}-${lodash_1.default.chain(name)
|
47
|
+
.camelCase()
|
48
|
+
.startCase()
|
49
|
+
.replace(/\s/g, "")
|
50
|
+
.value()}`;
|
44
51
|
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
|
45
52
|
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
46
53
|
}
|
@@ -130,7 +137,11 @@ class MonitoredDBFunction {
|
|
130
137
|
*/
|
131
138
|
static create(stack, name, environment, functionParameters) {
|
132
139
|
const functionName = functionParameters?.functionName ??
|
133
|
-
`${stack.configuration.shortName}-${
|
140
|
+
`${stack.configuration.shortName}-${lodash_1.default.chain(name)
|
141
|
+
.camelCase()
|
142
|
+
.startCase()
|
143
|
+
.replace(/\s/g, "")
|
144
|
+
.value()}`;
|
134
145
|
const env = environment ? environment : stack.createLambdaEnvironment();
|
135
146
|
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, env, functionName, name, functionParameters);
|
136
147
|
const mf = MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
@@ -1,4 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.createIpRestrictionPolicyDocument = exports.createDefaultPolicyDocument = exports.createRestApi = exports.setReturnCodeForMissingAuthenticationToken = exports.add401Support = exports.add404Support = exports.DigitrafficRestApi = void 0;
|
4
7
|
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
@@ -6,7 +9,7 @@ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
|
6
9
|
const api_model_1 = require("../../../utils/api-model");
|
7
10
|
const mediatypes_1 = require("../../types/mediatypes");
|
8
11
|
const usage_plans_1 = require("../usage-plans");
|
9
|
-
const
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
10
13
|
class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
11
14
|
constructor(stack, apiId, apiName, allowFromIpAddresses, config) {
|
12
15
|
const policyDocument = allowFromIpAddresses == null
|
@@ -58,7 +61,7 @@ class DigitrafficRestApi extends aws_apigateway_1.RestApi {
|
|
58
61
|
}));
|
59
62
|
}
|
60
63
|
getModelWithReference(model) {
|
61
|
-
return
|
64
|
+
return lodash_1.default.set(model, "modelReference", (0, api_model_1.getModelReference)(model.modelId, this.restApiId));
|
62
65
|
}
|
63
66
|
addDocumentationPart(resource, parameterName, resourceName, type, properties) {
|
64
67
|
const location = {
|
@@ -1,4 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.StackCheckingAspect = void 0;
|
4
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
@@ -6,11 +9,12 @@ const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
6
9
|
const aws_s3_1 = require("aws-cdk-lib/aws-s3");
|
7
10
|
const stack_1 = require("./stack");
|
8
11
|
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
9
|
-
const change_case_1 = require("change-case");
|
10
12
|
const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
|
11
13
|
const aws_logs_1 = require("aws-cdk-lib/aws-logs");
|
14
|
+
const change_case_1 = require("change-case");
|
15
|
+
const lodash_1 = __importDefault(require("lodash"));
|
12
16
|
const MAX_CONCURRENCY_LIMIT = 100;
|
13
|
-
const NODE_RUNTIMES = [aws_lambda_1.Runtime.
|
17
|
+
const NODE_RUNTIMES = [aws_lambda_1.Runtime.NODEJS_16_X.name, aws_lambda_1.Runtime.NODEJS_18_X.name];
|
14
18
|
var ResourceType;
|
15
19
|
(function (ResourceType) {
|
16
20
|
ResourceType["stackName"] = "STACK_NAME";
|
@@ -130,7 +134,7 @@ class StackCheckingAspect {
|
|
130
134
|
return (0, change_case_1.paramCase)(path) === path;
|
131
135
|
}
|
132
136
|
static isValidQueryString(name) {
|
133
|
-
return
|
137
|
+
return lodash_1.default.snakeCase(name) === name;
|
134
138
|
}
|
135
139
|
checkResourceCasing(node) {
|
136
140
|
if (node instanceof aws_apigateway_1.CfnResource) {
|
@@ -4,6 +4,7 @@ exports.SecretHolder = void 0;
|
|
4
4
|
const secret_1 = require("./secret");
|
5
5
|
const dbsecret_1 = require("./dbsecret");
|
6
6
|
const utils_1 = require("../../../utils/utils");
|
7
|
+
const dt_logger_default_1 = require("../dt-logger-default");
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
8
9
|
const NodeTtl = require("node-ttl");
|
9
10
|
const DEFAULT_PREFIX = "";
|
@@ -33,7 +34,10 @@ class SecretHolder {
|
|
33
34
|
}
|
34
35
|
async initSecret() {
|
35
36
|
const secretValue = await (0, secret_1.getSecret)(this.secretId);
|
36
|
-
|
37
|
+
dt_logger_default_1.logger.info({
|
38
|
+
method: "SecretHolder.initSecret",
|
39
|
+
message: "Refreshing secret " + this.secretId,
|
40
|
+
});
|
37
41
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
38
42
|
this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
|
39
43
|
}
|
@@ -2,6 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.inDatabaseReadonly = exports.inDatabase = exports.inTransaction = exports.initDbConnection = exports.DatabaseEnvironmentKeys = void 0;
|
4
4
|
const utils_1 = require("../utils/utils");
|
5
|
+
const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
|
6
|
+
const logging_1 = require("../utils/logging");
|
5
7
|
var DatabaseEnvironmentKeys;
|
6
8
|
(function (DatabaseEnvironmentKeys) {
|
7
9
|
DatabaseEnvironmentKeys["DB_USER"] = "DB_USER";
|
@@ -68,7 +70,7 @@ async function doInDatabase(readonly, fn) {
|
|
68
70
|
return await fn(db);
|
69
71
|
}
|
70
72
|
catch (e) {
|
71
|
-
|
73
|
+
(0, logging_1.logException)(dt_logger_default_1.logger, e);
|
72
74
|
throw e;
|
73
75
|
}
|
74
76
|
finally {
|
package/dist/utils/geometry.js
CHANGED
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
26
|
exports.positionToList = exports.createGmlLineString = exports.distanceBetweenPositionsInM = exports.areDistinctPositions = exports.distanceBetweenPositionsInKm = exports.isFeatureCollection = exports.isValidGeoJson = exports.createFeatureCollection = exports.createGeometry = exports.SRID_WGS84 = void 0;
|
27
27
|
const geoJsonValidator = __importStar(require("geojson-validation"));
|
28
|
+
const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
|
28
29
|
exports.SRID_WGS84 = 4326;
|
29
30
|
/**
|
30
31
|
* Creates WKT geometry from GeoJSON geometry
|
@@ -47,7 +48,10 @@ function createGeometry(geometry) {
|
|
47
48
|
const coordinates = multiPolygon(geometry.coordinates);
|
48
49
|
return `MULTIPOLYGON(${coordinates})`;
|
49
50
|
}
|
50
|
-
|
51
|
+
dt_logger_default_1.logger.error({
|
52
|
+
method: "Geometry.createGeometry",
|
53
|
+
message: "Unsupported locationType " + geometry.type,
|
54
|
+
});
|
51
55
|
return "POLYGON EMPTY";
|
52
56
|
}
|
53
57
|
exports.createGeometry = createGeometry;
|
package/dist/utils/slack.js
CHANGED
@@ -5,19 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.SlackApi = void 0;
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
8
|
+
const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
|
9
|
+
const logging_1 = require("./logging");
|
8
10
|
class SlackApi {
|
9
11
|
constructor(url) {
|
10
12
|
this.url = url;
|
11
13
|
}
|
12
14
|
async notify(text) {
|
13
15
|
try {
|
14
|
-
|
16
|
+
dt_logger_default_1.logger.info({
|
17
|
+
method: "SlackApi.notify",
|
18
|
+
message: "Sending slack notification",
|
19
|
+
});
|
15
20
|
await axios_1.default.post(this.url, {
|
16
21
|
text,
|
17
22
|
});
|
18
23
|
}
|
19
24
|
catch (error) {
|
20
|
-
|
25
|
+
(0, logging_1.logException)(dt_logger_default_1.logger, error);
|
21
26
|
}
|
22
27
|
}
|
23
28
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2023.
|
3
|
+
"version": "2023.11.21-1",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -17,58 +17,54 @@
|
|
17
17
|
"src/**/*.ts"
|
18
18
|
],
|
19
19
|
"peerDependencies": {
|
20
|
-
"@
|
21
|
-
"
|
22
|
-
"aws-
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"constructs": "^10.2.17",
|
20
|
+
"@types/geojson": "^7946.0.12",
|
21
|
+
"aws-cdk-lib": "^2.103.0",
|
22
|
+
"aws-sdk": "^2.1481.0",
|
23
|
+
"axios": "^1.5.1",
|
24
|
+
"change-case": "4.1.2",
|
25
|
+
"constructs": "^10.3.0",
|
27
26
|
"date-fns-tz": "~2.0.0",
|
28
27
|
"date-fns": "~2.30.0",
|
29
28
|
"etag": "^1.8.1",
|
30
29
|
"geojson-validation": "^1.0.2",
|
31
30
|
"node-ttl": "^0.2.0",
|
32
31
|
"pg-native": "^3.0.1",
|
33
|
-
"pg-promise": "^11.5.
|
32
|
+
"pg-promise": "^11.5.4"
|
34
33
|
},
|
35
34
|
"devDependencies": {
|
36
|
-
"@
|
37
|
-
"@types/
|
38
|
-
"@types/
|
39
|
-
"@types/
|
40
|
-
"@types/
|
41
|
-
"@types/
|
42
|
-
"@types/
|
43
|
-
"@
|
44
|
-
"@
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"change-case": "^4.1.2",
|
51
|
-
"constructs": "10.2.61",
|
35
|
+
"@types/aws-lambda": "8.10.125",
|
36
|
+
"@types/geojson": "7946.0.12",
|
37
|
+
"@types/etag": "1.8.2",
|
38
|
+
"@types/jest": "29.5.6",
|
39
|
+
"@types/lodash": "4.14.200",
|
40
|
+
"@types/node": "20.8.9",
|
41
|
+
"@types/sinon": "10.0.20",
|
42
|
+
"@typescript-eslint/eslint-plugin": "~6.9.0",
|
43
|
+
"@typescript-eslint/parser": "^6.9.0",
|
44
|
+
"aws-cdk-lib": "~2.103.1",
|
45
|
+
"aws-sdk": "~2.1482.0",
|
46
|
+
"axios": "^1.6.0",
|
47
|
+
"change-case": "4.1.2",
|
48
|
+
"constructs": "10.3.0",
|
52
49
|
"date-fns-tz": "~2.0.0",
|
53
50
|
"date-fns": "~2.30.0",
|
54
|
-
"eslint": "~8.
|
55
|
-
"eslint-config-prettier": "^
|
56
|
-
"eslint-plugin-deprecation": "~
|
51
|
+
"eslint": "~8.52.0",
|
52
|
+
"eslint-config-prettier": "^9.0.0",
|
53
|
+
"eslint-plugin-deprecation": "~2.0.0",
|
57
54
|
"etag": "^1.8.1",
|
58
55
|
"geojson-validation": "^1.0.2",
|
59
56
|
"husky": "^8.0.3",
|
60
|
-
"jest": "^29.
|
57
|
+
"jest": "^29.7.0",
|
61
58
|
"jest-junit": "^16.0.0",
|
62
|
-
"lint-staged": "^
|
63
|
-
"lodash": "
|
59
|
+
"lint-staged": "^15.0.2",
|
60
|
+
"lodash": "~4.17.21",
|
64
61
|
"node-ttl": "^0.2.0",
|
65
62
|
"pg-native": "^3.0.1",
|
66
|
-
"pg-promise": "^11.5.
|
63
|
+
"pg-promise": "^11.5.4",
|
67
64
|
"prettier": "^2.8.8",
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"ts-jest": "^29.1.0",
|
65
|
+
"rimraf": "^5.0.5",
|
66
|
+
"sinon": "17.0.0",
|
67
|
+
"ts-jest": "^29.1.1",
|
72
68
|
"typescript": "~4.9.5",
|
73
69
|
"velocityjs": "2.0.6"
|
74
70
|
},
|
@@ -19,7 +19,7 @@ interface ApiParameter {
|
|
19
19
|
name: string;
|
20
20
|
}
|
21
21
|
|
22
|
-
export class DigitrafficIntegration {
|
22
|
+
export class DigitrafficIntegration<T extends string> {
|
23
23
|
readonly lambda: IFunction;
|
24
24
|
readonly mediaType: MediaType;
|
25
25
|
readonly parameters: ApiParameter[] = [];
|
@@ -35,20 +35,20 @@ export class DigitrafficIntegration {
|
|
35
35
|
this.sunset = sunset;
|
36
36
|
}
|
37
37
|
|
38
|
-
addPathParameter(...names:
|
38
|
+
addPathParameter(...names: T[]): this {
|
39
39
|
names.forEach((name) => this.parameters.push({ type: "path", name }));
|
40
40
|
|
41
41
|
return this;
|
42
42
|
}
|
43
43
|
|
44
|
-
addQueryParameter(...names:
|
44
|
+
addQueryParameter(...names: T[]): this {
|
45
45
|
names.forEach((name) =>
|
46
46
|
this.parameters.push({ type: "querystring", name })
|
47
47
|
);
|
48
48
|
return this;
|
49
49
|
}
|
50
50
|
|
51
|
-
addMultiValueQueryParameter(...names:
|
51
|
+
addMultiValueQueryParameter(...names: T[]): this {
|
52
52
|
names.forEach((name) =>
|
53
53
|
this.parameters.push({ type: "multivaluequerystring", name })
|
54
54
|
);
|
@@ -61,7 +61,7 @@ export class DigitrafficIntegration {
|
|
61
61
|
* @param names for the parameters
|
62
62
|
* @returns
|
63
63
|
*/
|
64
|
-
addContextParameter(...names:
|
64
|
+
addContextParameter(...names: T[]): this {
|
65
65
|
names.forEach((name) =>
|
66
66
|
this.parameters.push({ type: "context", name })
|
67
67
|
);
|
@@ -74,7 +74,7 @@ export class DigitrafficIntegration {
|
|
74
74
|
* If Authorization header is needed, use lambda authorizers.
|
75
75
|
* @param names for the headers
|
76
76
|
*/
|
77
|
-
addHeaderParameter(...names:
|
77
|
+
addHeaderParameter(...names: T[]): this {
|
78
78
|
names.forEach((name) => this.parameters.push({ type: "header", name }));
|
79
79
|
|
80
80
|
return this;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Construct } from "constructs";
|
2
2
|
import { CanaryParameters } from "./canary-parameters";
|
3
3
|
import { Alarm, ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
4
|
-
import { Canary } from "
|
4
|
+
import { Canary } from "aws-cdk-lib/aws-synthetics";
|
5
5
|
import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
|
6
6
|
import { Topic } from "aws-cdk-lib/aws-sns";
|
7
7
|
|
@@ -5,7 +5,7 @@ import {
|
|
5
5
|
Runtime,
|
6
6
|
Schedule,
|
7
7
|
Test,
|
8
|
-
} from "
|
8
|
+
} from "aws-cdk-lib/aws-synthetics";
|
9
9
|
import { Role } from "aws-cdk-lib/aws-iam";
|
10
10
|
import { CanaryAlarm } from "./canary-alarm";
|
11
11
|
import { CanaryParameters } from "./canary-parameters";
|
@@ -3,6 +3,7 @@ import { ProxyHolder } from "../../runtime/secrets/proxy-holder";
|
|
3
3
|
import { RdsHolder } from "../../runtime/secrets/rds-holder";
|
4
4
|
import { getEnvVariable } from "../../../utils/utils";
|
5
5
|
import { Countable } from "../../../database/models";
|
6
|
+
import { logger } from "../../runtime/dt-logger-default";
|
6
7
|
|
7
8
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
8
9
|
const synthetics = require("Synthetics");
|
@@ -141,7 +142,10 @@ export class DatabaseCountChecker {
|
|
141
142
|
await this.credentialsFunction();
|
142
143
|
await inDatabaseReadonly(async (db: DTDatabase) => {
|
143
144
|
for (const check of this.checks) {
|
144
|
-
|
145
|
+
logger.info({
|
146
|
+
method: "DatabaseCountChecker.expect",
|
147
|
+
message: "Running sql: " + check.sql,
|
148
|
+
});
|
145
149
|
|
146
150
|
const value = await db.one<Countable>(check.sql);
|
147
151
|
const checkFunction = () => {
|
@@ -10,6 +10,8 @@ import { FeatureCollection } from "geojson";
|
|
10
10
|
import { isValidGeoJson } from "../../../utils/geometry";
|
11
11
|
import { getEnvVariable } from "../../../utils/utils";
|
12
12
|
import { ENV_API_KEY, ENV_HOSTNAME } from "./canary-keys";
|
13
|
+
import { logger } from "../../runtime/dt-logger-default";
|
14
|
+
import { logException } from "../../../utils/logging";
|
13
15
|
|
14
16
|
export const API_KEY_HEADER = "x-api-key";
|
15
17
|
|
@@ -142,7 +144,10 @@ export class UrlChecker {
|
|
142
144
|
!this.requestOptions.headers ||
|
143
145
|
!this.requestOptions.headers[API_KEY_HEADER]
|
144
146
|
) {
|
145
|
-
|
147
|
+
logger.error({
|
148
|
+
method: "UrlChecker.expect403WithoutApiKey",
|
149
|
+
message: "No Api-key defined",
|
150
|
+
});
|
146
151
|
}
|
147
152
|
|
148
153
|
const requestOptions = {
|
@@ -176,7 +181,7 @@ async function getResponseBody(response: IncomingMessage): Promise<string> {
|
|
176
181
|
try {
|
177
182
|
return zlib.gunzipSync(body).toString();
|
178
183
|
} catch (e) {
|
179
|
-
|
184
|
+
logException(logger, e);
|
180
185
|
}
|
181
186
|
}
|
182
187
|
|
@@ -9,10 +9,11 @@ import {
|
|
9
9
|
LambdaEnvironment,
|
10
10
|
MonitoredFunctionParameters,
|
11
11
|
} from "../stack/lambda-configs";
|
12
|
-
import { pascalCase } from "change-case";
|
13
12
|
import { DigitrafficLogSubscriptions } from "../stack/subscription";
|
14
13
|
import { TrafficType } from "../../../types/traffictype";
|
15
14
|
|
15
|
+
import _ from "lodash";
|
16
|
+
|
16
17
|
/**
|
17
18
|
* Allows customization of CloudWatch Alarm properties
|
18
19
|
*/
|
@@ -117,7 +118,11 @@ export class MonitoredFunction extends Function {
|
|
117
118
|
): MonitoredFunction {
|
118
119
|
const functionName =
|
119
120
|
functionParameters?.functionName ??
|
120
|
-
`${stack.configuration.shortName}-${
|
121
|
+
`${stack.configuration.shortName}-${_.chain(name)
|
122
|
+
.camelCase()
|
123
|
+
.startCase()
|
124
|
+
.replace(/\s/g, "")
|
125
|
+
.value()}`;
|
121
126
|
const functionProps = databaseFunctionProps(
|
122
127
|
stack,
|
123
128
|
environment,
|
@@ -315,7 +320,11 @@ export class MonitoredDBFunction {
|
|
315
320
|
): MonitoredFunction {
|
316
321
|
const functionName =
|
317
322
|
functionParameters?.functionName ??
|
318
|
-
`${stack.configuration.shortName}-${
|
323
|
+
`${stack.configuration.shortName}-${_.chain(name)
|
324
|
+
.camelCase()
|
325
|
+
.startCase()
|
326
|
+
.replace(/\s/g, "")
|
327
|
+
.value()}`;
|
319
328
|
const env = environment ? environment : stack.createLambdaEnvironment();
|
320
329
|
const functionProps = databaseFunctionProps(
|
321
330
|
stack,
|
@@ -26,7 +26,7 @@ import { DocumentationPart, DocumentationProperties } from "../documentation";
|
|
26
26
|
import { createDefaultUsagePlan, createUsagePlan } from "../usage-plans";
|
27
27
|
import { DigitrafficStack } from "./stack";
|
28
28
|
|
29
|
-
import
|
29
|
+
import _ from "lodash";
|
30
30
|
|
31
31
|
export class DigitrafficRestApi extends RestApi {
|
32
32
|
readonly apiKeyIds: string[];
|
@@ -109,10 +109,10 @@ export class DigitrafficRestApi extends RestApi {
|
|
109
109
|
}
|
110
110
|
|
111
111
|
private getModelWithReference(model: Model): ModelWithReference {
|
112
|
-
return
|
112
|
+
return _.set(
|
113
|
+
model,
|
113
114
|
"modelReference",
|
114
|
-
getModelReference(model.modelId, this.restApiId)
|
115
|
-
model
|
115
|
+
getModelReference(model.modelId, this.restApiId)
|
116
116
|
) as ModelWithReference;
|
117
117
|
}
|
118
118
|
|
@@ -4,13 +4,14 @@ import { CfnBucket } from "aws-cdk-lib/aws-s3";
|
|
4
4
|
import { DigitrafficStack, SOLUTION_KEY } from "./stack";
|
5
5
|
import { IConstruct } from "constructs";
|
6
6
|
import { CfnMethod, CfnResource } from "aws-cdk-lib/aws-apigateway";
|
7
|
-
import { paramCase, snakeCase } from "change-case";
|
8
7
|
import { CfnQueue } from "aws-cdk-lib/aws-sqs";
|
9
8
|
import { LogRetention } from "aws-cdk-lib/aws-logs";
|
9
|
+
import { paramCase } from "change-case";
|
10
|
+
import _ from "lodash";
|
10
11
|
import IntegrationProperty = CfnMethod.IntegrationProperty;
|
11
12
|
|
12
13
|
const MAX_CONCURRENCY_LIMIT = 100;
|
13
|
-
const NODE_RUNTIMES = [Runtime.
|
14
|
+
const NODE_RUNTIMES = [Runtime.NODEJS_16_X.name, Runtime.NODEJS_18_X.name];
|
14
15
|
|
15
16
|
enum ResourceType {
|
16
17
|
stackName = "STACK_NAME",
|
@@ -214,7 +215,7 @@ export class StackCheckingAspect implements IAspect {
|
|
214
215
|
}
|
215
216
|
|
216
217
|
private static isValidQueryString(name: string) {
|
217
|
-
return snakeCase(name) === name;
|
218
|
+
return _.snakeCase(name) === name;
|
218
219
|
}
|
219
220
|
|
220
221
|
private checkResourceCasing(node: IConstruct) {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { GenericSecret, getSecret } from "./secret";
|
2
2
|
import { checkExpectedSecretKeys } from "./dbsecret";
|
3
3
|
import { getEnvVariable } from "../../../utils/utils";
|
4
|
+
import { logger } from "../dt-logger-default";
|
4
5
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
6
7
|
const NodeTtl = require("node-ttl");
|
@@ -47,7 +48,10 @@ export class SecretHolder<Secret extends GenericSecret> {
|
|
47
48
|
private async initSecret() {
|
48
49
|
const secretValue = await getSecret<Secret>(this.secretId);
|
49
50
|
|
50
|
-
|
51
|
+
logger.info({
|
52
|
+
method: "SecretHolder.initSecret",
|
53
|
+
message: "Refreshing secret " + this.secretId,
|
54
|
+
});
|
51
55
|
|
52
56
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
53
57
|
this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
|
package/src/database/database.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { IDatabase, ITask } from "pg-promise";
|
2
2
|
import { getEnvVariable, getEnvVariableOrElse } from "../utils/utils";
|
3
|
+
import { logger } from "../aws/runtime/dt-logger-default";
|
4
|
+
import { logException } from "../utils/logging";
|
3
5
|
|
4
6
|
export enum DatabaseEnvironmentKeys {
|
5
7
|
DB_USER = "DB_USER",
|
@@ -97,7 +99,8 @@ async function doInDatabase<T>(
|
|
97
99
|
await db.none("DISCARD ALL");
|
98
100
|
return await fn(db);
|
99
101
|
} catch (e) {
|
100
|
-
|
102
|
+
logException(logger, e);
|
103
|
+
|
101
104
|
throw e;
|
102
105
|
} finally {
|
103
106
|
await db.$pool.end();
|
package/src/utils/geometry.ts
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
import { Feature, FeatureCollection, Geometry, Position } from "geojson";
|
5
5
|
import * as geoJsonValidator from "geojson-validation";
|
6
|
+
import { logger } from "../aws/runtime/dt-logger-default";
|
6
7
|
|
7
8
|
export const SRID_WGS84 = 4326;
|
8
9
|
|
@@ -29,7 +30,11 @@ export function createGeometry(geometry: Geometry): string {
|
|
29
30
|
return `MULTIPOLYGON(${coordinates})`;
|
30
31
|
}
|
31
32
|
|
32
|
-
|
33
|
+
logger.error({
|
34
|
+
method: "Geometry.createGeometry",
|
35
|
+
message: "Unsupported locationType " + geometry.type,
|
36
|
+
});
|
37
|
+
|
33
38
|
return "POLYGON EMPTY";
|
34
39
|
}
|
35
40
|
|
package/src/utils/slack.ts
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
import axios from "axios";
|
2
|
+
import { logger } from "../aws/runtime/dt-logger-default";
|
3
|
+
import { logException } from "./logging";
|
2
4
|
|
3
5
|
export class SlackApi {
|
4
|
-
|
5
6
|
private readonly url: string;
|
6
7
|
|
7
|
-
constructor(url
|
8
|
+
constructor(url: string) {
|
8
9
|
this.url = url;
|
9
10
|
}
|
10
11
|
|
11
12
|
async notify(text: string) {
|
12
13
|
try {
|
13
|
-
|
14
|
+
logger.info({
|
15
|
+
method: "SlackApi.notify",
|
16
|
+
message: "Sending slack notification",
|
17
|
+
});
|
18
|
+
|
14
19
|
await axios.post(this.url, {
|
15
20
|
text,
|
16
21
|
});
|
17
22
|
} catch (error) {
|
18
|
-
|
23
|
+
logException(logger, error);
|
19
24
|
}
|
20
25
|
}
|
21
|
-
|
22
26
|
}
|