@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.
@@ -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: string[]): this;
16
- addQueryParameter(...names: string[]): this;
17
- addMultiValueQueryParameter(...names: string[]): this;
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: string[]): this;
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: string[]): this;
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 "@aws-cdk/aws-synthetics-alpha";
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
  }
@@ -1,4 +1,4 @@
1
- import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Schedule } from "aws-cdk-lib/aws-synthetics";
2
2
  /** Optional env parameters for canary */
3
3
  type CanaryEnv = Record<string, string>;
4
4
  export interface CanaryParameters {
@@ -1,4 +1,4 @@
1
- import { Canary } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Canary } from "aws-cdk-lib/aws-synthetics";
2
2
  import { Role } from "aws-cdk-lib/aws-iam";
3
3
  import { CanaryParameters } from "./canary-parameters";
4
4
  import { Construct } from "constructs";
@@ -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 aws_synthetics_alpha_1 = require("@aws-cdk/aws-synthetics-alpha");
5
+ const aws_synthetics_1 = require("aws-cdk-lib/aws-synthetics");
6
6
  const canary_alarm_1 = require("./canary-alarm");
7
- class DigitrafficCanary extends aws_synthetics_alpha_1.Canary {
7
+ class DigitrafficCanary extends aws_synthetics_1.Canary {
8
8
  constructor(scope, canaryName, role, params, environmentVariables) {
9
9
  super(scope, canaryName, {
10
- runtime: aws_synthetics_alpha_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
10
+ runtime: aws_synthetics_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_4_0,
11
11
  role,
12
- test: aws_synthetics_alpha_1.Test.custom({
13
- code: new aws_synthetics_alpha_1.AssetCode("dist", {
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 ?? aws_synthetics_alpha_1.Schedule.rate(aws_cdk_lib_1.Duration.minutes(15)),
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
- console.info("canary checking sql " + check.sql);
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
- console.error("No api key defined");
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
- console.info("error " + JSON.stringify(e));
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}-${(0, change_case_1.pascalCase)(name)}`;
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}-${(0, change_case_1.pascalCase)(name)}`;
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 R = require("ramda");
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 R.assoc("modelReference", (0, api_model_1.getModelReference)(model.modelId, this.restApiId), model);
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.NODEJS_14_X.name, aws_lambda_1.Runtime.NODEJS_16_X.name];
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 (0, change_case_1.snakeCase)(name) === name;
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
- console.info("refreshing secret " + this.secretId);
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
- console.error("Error in db:", e);
73
+ (0, logging_1.logException)(dt_logger_default_1.logger, e);
72
74
  throw e;
73
75
  }
74
76
  finally {
@@ -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
- console.error("unsupported locationType=%s", geometry.type);
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;
@@ -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
- console.info('method=notify Notifying Slack');
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
- console.error('method=notify Slack notify failed!');
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.10.11-1",
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
- "@aws-cdk/aws-synthetics-alpha": "^2.85.0-alpha.0",
21
- "@types/geojson": "^7946.0.10",
22
- "aws-cdk-lib": "^2.85.0",
23
- "aws-sdk": "^2.1405.0",
24
- "axios": "^1.2.6",
25
- "change-case": "^4.1.2",
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.0"
32
+ "pg-promise": "^11.5.4"
34
33
  },
35
34
  "devDependencies": {
36
- "@aws-cdk/aws-synthetics-alpha": "2.85.0-alpha.0",
37
- "@types/aws-lambda": "~8.10.119",
38
- "@types/geojson": "^7946.0.10",
39
- "@types/etag": "^1.8.1",
40
- "@types/jest": "^29.5.2",
41
- "@types/lodash": "^4.14.195",
42
- "@types/node": "18.15.13",
43
- "@types/ramda": "~0.29.1",
44
- "@types/sinon": "10.0.15",
45
- "@typescript-eslint/eslint-plugin": "~5.60.1",
46
- "@typescript-eslint/parser": "^5.60.1",
47
- "aws-cdk-lib": "~2.85.0",
48
- "aws-sdk": "~2.1405.0",
49
- "axios": "^1.3.6",
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.43.0",
55
- "eslint-config-prettier": "^8.8.0",
56
- "eslint-plugin-deprecation": "~1.4.1",
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.5.0",
57
+ "jest": "^29.7.0",
61
58
  "jest-junit": "^16.0.0",
62
- "lint-staged": "^13.2.2",
63
- "lodash": "^4.17.21",
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.0",
63
+ "pg-promise": "^11.5.4",
67
64
  "prettier": "^2.8.8",
68
- "ramda": "~0.29.0",
69
- "rimraf": "^5.0.1",
70
- "sinon": "15.2.0",
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: string[]): this {
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: string[]): this {
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: string[]): this {
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: string[]): this {
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: string[]): this {
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 "@aws-cdk/aws-synthetics-alpha";
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
 
@@ -1,4 +1,4 @@
1
- import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
1
+ import { Schedule } from "aws-cdk-lib/aws-synthetics";
2
2
 
3
3
  /** Optional env parameters for canary */
4
4
  type CanaryEnv = Record<string, string>;
@@ -5,7 +5,7 @@ import {
5
5
  Runtime,
6
6
  Schedule,
7
7
  Test,
8
- } from "@aws-cdk/aws-synthetics-alpha";
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
- console.info("canary checking sql " + check.sql);
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
- console.error("No api key defined");
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
- console.info("error " + JSON.stringify(e));
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}-${pascalCase(name)}`;
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}-${pascalCase(name)}`;
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 R = require("ramda");
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 R.assoc(
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.NODEJS_14_X.name, Runtime.NODEJS_16_X.name];
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
- console.info("refreshing secret " + this.secretId);
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);
@@ -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
- console.error("Error in db:", e);
102
+ logException(logger, e);
103
+
101
104
  throw e;
102
105
  } finally {
103
106
  await db.$pool.end();
@@ -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
- console.error("unsupported locationType=%s", geometry.type);
33
+ logger.error({
34
+ method: "Geometry.createGeometry",
35
+ message: "Unsupported locationType " + geometry.type,
36
+ });
37
+
33
38
  return "POLYGON EMPTY";
34
39
  }
35
40
 
@@ -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 :string) {
8
+ constructor(url: string) {
8
9
  this.url = url;
9
10
  }
10
11
 
11
12
  async notify(text: string) {
12
13
  try {
13
- console.info('method=notify Notifying Slack');
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
- console.error('method=notify Slack notify failed!');
23
+ logException(logger, error);
19
24
  }
20
25
  }
21
-
22
26
  }