@digitraffic/common 2023.10.18-1 → 2023.12.15-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.
@@ -30,9 +30,7 @@ class UrlChecker {
30
30
  protocol: "https:",
31
31
  headers,
32
32
  };
33
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
34
33
  synthetics.getConfiguration().disableRequestMetrics();
35
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
36
34
  synthetics
37
35
  .getConfiguration()
38
36
  .withIncludeRequestBody(false)
@@ -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,9 +9,10 @@ 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
17
  const NODE_RUNTIMES = [aws_lambda_1.Runtime.NODEJS_16_X.name, aws_lambda_1.Runtime.NODEJS_18_X.name];
14
18
  var ResourceType;
@@ -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) {
@@ -1 +1,11 @@
1
1
  export type ValueOf<Obj> = Obj[keyof Obj];
2
+ /**
3
+ * Type-level conversion from readonly object to mutable object. Use with caution!
4
+ *
5
+ * Only converts in the type-level. Caution must be used, as the typescript cannot enforce readonly-ness at
6
+ * runtime. This is only useful for type-checking and especially in cases where 3rd party code requires
7
+ * mutable even though it is not needed.
8
+ */
9
+ export type Writable<T> = {
10
+ -readonly [P in keyof T]: T[P];
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.10.18-1",
3
+ "version": "2023.12.15-1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,11 +17,11 @@
17
17
  "src/**/*.ts"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@types/geojson": "^7946.0.11",
21
- "aws-cdk-lib": "^2.101.1",
22
- "aws-sdk": "^2.1474.0",
23
- "axios": "^1.5.1",
24
- "change-case": "^4.1.2",
20
+ "@types/geojson": "^7946.0.12",
21
+ "aws-cdk-lib": "^2.103.0",
22
+ "aws-sdk": "^2.1481.0",
23
+ "axios": "^1.6.2",
24
+ "change-case": "4.1.2",
25
25
  "constructs": "^10.3.0",
26
26
  "date-fns-tz": "~2.0.0",
27
27
  "date-fns": "~2.30.0",
@@ -29,44 +29,42 @@
29
29
  "geojson-validation": "^1.0.2",
30
30
  "node-ttl": "^0.2.0",
31
31
  "pg-native": "^3.0.1",
32
- "pg-promise": "^11.5.0"
32
+ "pg-promise": "^11.5.4"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/aws-lambda": "~8.10.119",
36
- "@types/geojson": "^7946.0.11",
37
- "@types/etag": "^1.8.1",
38
- "@types/jest": "^29.5.5",
39
- "@types/lodash": "^4.14.199",
40
- "@types/node": "20.8.4",
41
- "@types/ramda": "~0.29.1",
42
- "@types/sinon": "10.0.15",
43
- "@typescript-eslint/eslint-plugin": "~6.7.5",
44
- "@typescript-eslint/parser": "^6.0.0",
45
- "aws-cdk-lib": "~2.101.1",
46
- "aws-sdk": "~2.1474.0",
47
- "axios": "^1.5.1",
48
- "change-case": "^4.1.2",
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",
49
48
  "constructs": "10.3.0",
50
49
  "date-fns-tz": "~2.0.0",
51
50
  "date-fns": "~2.30.0",
52
- "eslint": "~8.51.0",
53
- "eslint-config-prettier": "^8.8.0",
51
+ "eslint": "~8.52.0",
52
+ "eslint-config-prettier": "^9.0.0",
54
53
  "eslint-plugin-deprecation": "~2.0.0",
55
54
  "etag": "^1.8.1",
56
55
  "geojson-validation": "^1.0.2",
57
56
  "husky": "^8.0.3",
58
- "jest": "^29.5.0",
57
+ "jest": "^29.7.0",
59
58
  "jest-junit": "^16.0.0",
60
- "lint-staged": "^13.2.2",
61
- "lodash": "^4.17.21",
59
+ "lint-staged": "^15.0.2",
60
+ "lodash": "~4.17.21",
62
61
  "node-ttl": "^0.2.0",
63
62
  "pg-native": "^3.0.1",
64
- "pg-promise": "^11.5.0",
63
+ "pg-promise": "^11.5.4",
65
64
  "prettier": "^2.8.8",
66
- "ramda": "~0.29.0",
67
- "rimraf": "^5.0.1",
68
- "sinon": "15.2.0",
69
- "ts-jest": "^29.1.0",
65
+ "rimraf": "^5.0.5",
66
+ "sinon": "17.0.0",
67
+ "ts-jest": "^29.1.1",
70
68
  "typescript": "~4.9.5",
71
69
  "velocityjs": "2.0.6"
72
70
  },
@@ -2,7 +2,7 @@ import { IncomingMessage, RequestOptions } from "http";
2
2
  import { Asserter } from "../../../test/asserter";
3
3
 
4
4
  // 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
5
- const synthetics = require("Synthetics");
5
+ const synthetics: Synthetics = require("Synthetics");
6
6
  import zlib = require("zlib");
7
7
  import { MediaType } from "../../types/mediatypes";
8
8
  import { getApiKeyFromAPIGateway } from "../../runtime/apikey";
@@ -28,6 +28,26 @@ type JsonCheckerFunction<T> = (
28
28
  message: IncomingMessage
29
29
  ) => Promise<void>;
30
30
 
31
+ /** Temporary type fix for SyntheticsConfiguration */
32
+ interface SyntheticsConfiguration {
33
+ withIncludeRequestBody: (value: boolean) => SyntheticsConfiguration;
34
+ withIncludeRequestHeaders: (value: boolean) => SyntheticsConfiguration;
35
+ withIncludeResponseBody: (value: boolean) => SyntheticsConfiguration;
36
+ withIncludeResponseHeaders: (value: boolean) => SyntheticsConfiguration;
37
+ withFailedCanaryMetric: (value: boolean) => SyntheticsConfiguration;
38
+ disableRequestMetrics: () => SyntheticsConfiguration;
39
+ }
40
+
41
+ /** Temporary type fix for Synthetics */
42
+ interface Synthetics {
43
+ executeHttpStep<T>(
44
+ name: string,
45
+ requestOptions: RequestOptions,
46
+ callback: JsonCheckerFunction<T>
47
+ ): Promise<void>;
48
+ getConfiguration(): SyntheticsConfiguration;
49
+ }
50
+
31
51
  export class UrlChecker {
32
52
  private readonly requestOptions: RequestOptions;
33
53
 
@@ -45,10 +65,8 @@ export class UrlChecker {
45
65
  headers,
46
66
  };
47
67
 
48
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
49
68
  synthetics.getConfiguration().disableRequestMetrics();
50
69
 
51
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
52
70
  synthetics
53
71
  .getConfiguration()
54
72
  .withIncludeRequestBody(false)
@@ -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,9 +4,10 @@ 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;
@@ -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 +1,10 @@
1
1
  export type ValueOf<Obj> = Obj[keyof Obj];
2
+
3
+ /**
4
+ * Type-level conversion from readonly object to mutable object. Use with caution!
5
+ *
6
+ * Only converts in the type-level. Caution must be used, as the typescript cannot enforce readonly-ness at
7
+ * runtime. This is only useful for type-checking and especially in cases where 3rd party code requires
8
+ * mutable even though it is not needed.
9
+ */
10
+ export type Writable<T> = { -readonly [P in keyof T]: T[P] };