@digitraffic/common 2024.1.24-3 → 2024.1.30-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.
Files changed (206) hide show
  1. package/dist/__test__/api/handler-factory.test.d.mts +1 -0
  2. package/dist/__test__/api/handler-factory.test.mjs +43 -0
  3. package/dist/__test__/api/response.test.d.mts +1 -0
  4. package/dist/__test__/api/response.test.mjs +86 -0
  5. package/dist/__test__/imports.test.d.mts +1 -0
  6. package/dist/__test__/imports.test.mjs +332 -0
  7. package/dist/__test__/marine/id_utils.test.d.mts +1 -0
  8. package/dist/__test__/marine/id_utils.test.mjs +44 -0
  9. package/dist/__test__/promise/promise.test.d.mts +1 -0
  10. package/dist/__test__/promise/promise.test.mjs +130 -0
  11. package/dist/__test__/runtime/dt-logger.test.d.mts +1 -0
  12. package/dist/__test__/runtime/dt-logger.test.mjs +108 -0
  13. package/dist/__test__/secrets/secret-holder.test.d.mts +1 -0
  14. package/dist/__test__/secrets/secret-holder.test.mjs +89 -0
  15. package/dist/__test__/secrets/secret.test.d.mts +1 -0
  16. package/dist/__test__/secrets/secret.test.mjs +42 -0
  17. package/dist/__test__/test/httpserver.test.d.mts +1 -0
  18. package/dist/__test__/test/httpserver.test.mjs +154 -0
  19. package/dist/__test__/types/lambda-response.test.d.mts +1 -0
  20. package/dist/__test__/types/lambda-response.test.mjs +58 -0
  21. package/dist/__test__/utils/date-utils.test.d.mts +1 -0
  22. package/dist/__test__/utils/date-utils.test.mjs +27 -0
  23. package/dist/__test__/utils/geometry.test.d.mts +1 -0
  24. package/dist/__test__/utils/geometry.test.mjs +24 -0
  25. package/dist/__test__/utils/logging.test.d.mts +1 -0
  26. package/dist/__test__/utils/logging.test.mjs +78 -0
  27. package/dist/__test__/utils/utils.test.d.mts +1 -0
  28. package/dist/__test__/utils/utils.test.mjs +43 -0
  29. package/dist/aws/infra/api/handler-factory.mjs +4 -0
  30. package/dist/aws/infra/api/integration.d.mts +2 -2
  31. package/dist/aws/infra/api/integration.mjs +4 -1
  32. package/dist/aws/infra/api/response.d.mts +1 -1
  33. package/dist/aws/infra/api/responses.d.mts +1 -1
  34. package/dist/aws/infra/api/responses.mjs +2 -0
  35. package/dist/aws/infra/api/static-integration.mjs +1 -1
  36. package/dist/aws/infra/canaries/canary-alarm.d.mts +1 -1
  37. package/dist/aws/infra/canaries/canary-alarm.mjs +2 -0
  38. package/dist/aws/infra/canaries/canary-parameters.mjs +1 -1
  39. package/dist/aws/infra/canaries/canary-role.mjs +1 -0
  40. package/dist/aws/infra/canaries/canary.d.mts +2 -2
  41. package/dist/aws/infra/canaries/canary.mjs +2 -0
  42. package/dist/aws/infra/canaries/database-canary.d.mts +2 -2
  43. package/dist/aws/infra/canaries/database-canary.mjs +2 -0
  44. package/dist/aws/infra/canaries/database-checker.d.mts +1 -1
  45. package/dist/aws/infra/canaries/database-checker.mjs +7 -1
  46. package/dist/aws/infra/canaries/url-canary.d.mts +2 -2
  47. package/dist/aws/infra/canaries/url-canary.mjs +3 -0
  48. package/dist/aws/infra/canaries/url-checker.d.mts +1 -1
  49. package/dist/aws/infra/canaries/url-checker.mjs +4 -1
  50. package/dist/aws/infra/documentation.mjs +5 -1
  51. package/dist/aws/infra/import-util.d.mts +1 -1
  52. package/dist/aws/infra/import-util.mjs +4 -3
  53. package/dist/aws/infra/scheduler.mjs +2 -0
  54. package/dist/aws/infra/security-rule.d.mts +1 -1
  55. package/dist/aws/infra/security-rule.mjs +1 -0
  56. package/dist/aws/infra/sqs-integration.d.mts +1 -1
  57. package/dist/aws/infra/sqs-integration.mjs +3 -1
  58. package/dist/aws/infra/sqs-queue.d.mts +1 -1
  59. package/dist/aws/infra/sqs-queue.mjs +2 -1
  60. package/dist/aws/infra/stack/lambda-configs.d.mts +4 -4
  61. package/dist/aws/infra/stack/lambda-configs.mjs +4 -2
  62. package/dist/aws/infra/stack/monitoredfunction.d.mts +3 -3
  63. package/dist/aws/infra/stack/monitoredfunction.mjs +20 -16
  64. package/dist/aws/infra/stack/parameters.mjs +1 -0
  65. package/dist/aws/infra/stack/rest_apis.d.mts +2 -2
  66. package/dist/aws/infra/stack/rest_apis.mjs +6 -1
  67. package/dist/aws/infra/stack/stack-checking-aspect.d.mts +2 -2
  68. package/dist/aws/infra/stack/stack-checking-aspect.mjs +6 -1
  69. package/dist/aws/infra/stack/stack.d.mts +5 -5
  70. package/dist/aws/infra/stack/stack.mjs +9 -0
  71. package/dist/aws/infra/stack/subscription.mjs +4 -0
  72. package/dist/aws/infra/stacks/db-dns-stack.d.mts +1 -1
  73. package/dist/aws/infra/stacks/db-dns-stack.mjs +1 -0
  74. package/dist/aws/infra/stacks/db-proxy-stack.d.mts +3 -3
  75. package/dist/aws/infra/stacks/db-proxy-stack.mjs +4 -2
  76. package/dist/aws/infra/stacks/db-stack.d.mts +3 -3
  77. package/dist/aws/infra/stacks/db-stack.mjs +11 -7
  78. package/dist/aws/infra/stacks/intra-stack-configuration.d.mts +1 -1
  79. package/dist/aws/infra/stacks/network-stack.d.mts +2 -2
  80. package/dist/aws/infra/stacks/network-stack.mjs +8 -0
  81. package/dist/aws/infra/usage-plans.d.mts +1 -1
  82. package/dist/aws/infra/usage-plans.mjs +1 -0
  83. package/dist/aws/runtime/apikey.d.mts +2 -2
  84. package/dist/aws/runtime/apikey.mjs +2 -1
  85. package/dist/aws/runtime/digitraffic-integration-response.d.mts +1 -1
  86. package/dist/aws/runtime/dt-logger.mjs +6 -2
  87. package/dist/aws/runtime/messaging.d.mts +2 -2
  88. package/dist/aws/runtime/s3.d.mts +2 -2
  89. package/dist/aws/runtime/s3.mjs +2 -1
  90. package/dist/aws/runtime/secrets/dbsecret.d.mts +1 -1
  91. package/dist/aws/runtime/secrets/proxy-holder.mjs +1 -0
  92. package/dist/aws/runtime/secrets/rds-holder.mjs +1 -0
  93. package/dist/aws/runtime/secrets/secret-holder.d.mts +1 -1
  94. package/dist/aws/runtime/secrets/secret-holder.mjs +6 -1
  95. package/dist/aws/runtime/secrets/secret.mjs +4 -2
  96. package/dist/aws/types/errors.mjs +1 -0
  97. package/dist/aws/types/lambda-response.mjs +5 -0
  98. package/dist/aws/types/model-with-reference.mjs +1 -1
  99. package/dist/database/cached.d.mts +1 -1
  100. package/dist/database/database.mjs +1 -0
  101. package/dist/database/last-updated.d.mts +1 -1
  102. package/dist/test/db-testutils.d.mts +1 -1
  103. package/dist/test/db-testutils.mjs +1 -1
  104. package/dist/test/httpserver.mjs +7 -3
  105. package/dist/test/secrets-manager.d.mts +1 -1
  106. package/dist/test/secrets-manager.mjs +1 -1
  107. package/dist/test/testutils.mjs +1 -1
  108. package/dist/types/http-error.mjs +1 -0
  109. package/dist/types/nullable.d.mts +1 -1
  110. package/dist/utils/api-model.d.mts +2 -2
  111. package/dist/utils/api-model.mjs +1 -1
  112. package/dist/utils/geojson-types.d.mts +1 -1
  113. package/dist/utils/geojson-types.mjs +4 -2
  114. package/dist/utils/geometry.d.mts +1 -1
  115. package/dist/utils/geometry.mjs +3 -0
  116. package/dist/utils/retry.d.mts +2 -2
  117. package/dist/utils/retry.mjs +2 -2
  118. package/dist/utils/slack.mjs +1 -0
  119. package/dist/utils/utils.d.mts +2 -2
  120. package/package.json +11 -6
  121. package/src/@types/geojson-validation/index.d.mts +0 -4
  122. package/src/aws/infra/api/handler-factory.mts +0 -86
  123. package/src/aws/infra/api/integration.mts +0 -147
  124. package/src/aws/infra/api/response.mts +0 -165
  125. package/src/aws/infra/api/responses.mts +0 -127
  126. package/src/aws/infra/api/static-integration.mts +0 -108
  127. package/src/aws/infra/canaries/Synthetics.d.mts +0 -21
  128. package/src/aws/infra/canaries/canary-alarm.mts +0 -33
  129. package/src/aws/infra/canaries/canary-keys.mts +0 -3
  130. package/src/aws/infra/canaries/canary-parameters.mts +0 -19
  131. package/src/aws/infra/canaries/canary-role.mts +0 -73
  132. package/src/aws/infra/canaries/canary.mts +0 -44
  133. package/src/aws/infra/canaries/database-canary.mts +0 -98
  134. package/src/aws/infra/canaries/database-checker.mts +0 -163
  135. package/src/aws/infra/canaries/url-canary.mts +0 -98
  136. package/src/aws/infra/canaries/url-checker.mts +0 -388
  137. package/src/aws/infra/documentation.mts +0 -142
  138. package/src/aws/infra/import-util.mts +0 -57
  139. package/src/aws/infra/scheduler.mts +0 -59
  140. package/src/aws/infra/security-rule.mts +0 -38
  141. package/src/aws/infra/sqs-integration.mts +0 -106
  142. package/src/aws/infra/sqs-queue.mts +0 -162
  143. package/src/aws/infra/stack/lambda-configs.mts +0 -135
  144. package/src/aws/infra/stack/monitoredfunction.mts +0 -352
  145. package/src/aws/infra/stack/parameters.mts +0 -74
  146. package/src/aws/infra/stack/rest_apis.mts +0 -322
  147. package/src/aws/infra/stack/stack-checking-aspect.mts +0 -233
  148. package/src/aws/infra/stack/stack.mts +0 -144
  149. package/src/aws/infra/stack/subscription.mts +0 -58
  150. package/src/aws/infra/stacks/db-dns-stack.mts +0 -77
  151. package/src/aws/infra/stacks/db-proxy-stack.mts +0 -134
  152. package/src/aws/infra/stacks/db-stack.mts +0 -292
  153. package/src/aws/infra/stacks/intra-stack-configuration.mts +0 -6
  154. package/src/aws/infra/stacks/network-stack.mts +0 -76
  155. package/src/aws/infra/usage-plans.mts +0 -50
  156. package/src/aws/runtime/apikey.mts +0 -9
  157. package/src/aws/runtime/digitraffic-integration-response.mts +0 -35
  158. package/src/aws/runtime/dt-logger-default.mts +0 -11
  159. package/src/aws/runtime/dt-logger.mts +0 -184
  160. package/src/aws/runtime/environment.mts +0 -22
  161. package/src/aws/runtime/messaging.mts +0 -26
  162. package/src/aws/runtime/s3.mts +0 -44
  163. package/src/aws/runtime/secrets/dbsecret.mts +0 -31
  164. package/src/aws/runtime/secrets/node-ttl.d.mts +0 -12
  165. package/src/aws/runtime/secrets/proxy-holder.mts +0 -34
  166. package/src/aws/runtime/secrets/rds-holder.mts +0 -34
  167. package/src/aws/runtime/secrets/secret-holder.mts +0 -106
  168. package/src/aws/runtime/secrets/secret.mts +0 -58
  169. package/src/aws/types/errors.mts +0 -14
  170. package/src/aws/types/lambda-response.mts +0 -100
  171. package/src/aws/types/mediatypes.mts +0 -12
  172. package/src/aws/types/model-with-reference.mts +0 -8
  173. package/src/aws/types/proxytypes.mts +0 -27
  174. package/src/aws/types/tags.mts +0 -3
  175. package/src/database/cached.mts +0 -64
  176. package/src/database/database.mts +0 -107
  177. package/src/database/last-updated.mts +0 -103
  178. package/src/database/models.mts +0 -7
  179. package/src/index.mts +0 -2
  180. package/src/marine/id_utils.mts +0 -30
  181. package/src/marine/rtz.mts +0 -57
  182. package/src/test/asserter.mts +0 -58
  183. package/src/test/db-testutils.mts +0 -52
  184. package/src/test/httpserver.mts +0 -111
  185. package/src/test/secrets-manager.mts +0 -37
  186. package/src/test/testutils.mts +0 -39
  187. package/src/types/async-timeout-error.mts +0 -5
  188. package/src/types/aws-env.mts +0 -3
  189. package/src/types/either.mts +0 -9
  190. package/src/types/http-error.mts +0 -8
  191. package/src/types/input-error.mts +0 -2
  192. package/src/types/language.mts +0 -3
  193. package/src/types/nullable.mts +0 -21
  194. package/src/types/traffictype.mts +0 -8
  195. package/src/types/urn.mts +0 -1
  196. package/src/types/util-types.mts +0 -10
  197. package/src/types/validator.mts +0 -10
  198. package/src/utils/api-model.mts +0 -133
  199. package/src/utils/base64.mts +0 -16
  200. package/src/utils/date-utils.mts +0 -53
  201. package/src/utils/geojson-types.mts +0 -22
  202. package/src/utils/geometry.mts +0 -171
  203. package/src/utils/logging.mts +0 -75
  204. package/src/utils/retry.mts +0 -200
  205. package/src/utils/slack.mts +0 -26
  206. package/src/utils/utils.mts +0 -184
@@ -1,7 +1,7 @@
1
- import { InstanceType, IVpc, type ISecurityGroup } from "aws-cdk-lib/aws-ec2";
2
- import { AuroraPostgresEngineVersion, DatabaseCluster, DatabaseClusterProps, IParameterGroup } from "aws-cdk-lib/aws-rds";
1
+ import { InstanceType, type IVpc, type ISecurityGroup } from "aws-cdk-lib/aws-ec2";
2
+ import { AuroraPostgresEngineVersion, DatabaseCluster, type DatabaseClusterProps, type IParameterGroup } from "aws-cdk-lib/aws-rds";
3
3
  import { Construct } from "constructs/lib/construct.js";
4
- import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
4
+ import type { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
5
5
  import { Stack } from "aws-cdk-lib/core";
6
6
  export interface DbConfiguration {
7
7
  readonly cluster?: ClusterConfiguration;
@@ -1,5 +1,6 @@
1
- import { SecurityGroup, SubnetType, } from "aws-cdk-lib/aws-ec2";
2
- import { CfnDBInstance, Credentials, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot, InstanceUpdateBehaviour, ParameterGroup, } from "aws-cdk-lib/aws-rds";
1
+ import { InstanceType, SecurityGroup, SubnetType, } from "aws-cdk-lib/aws-ec2";
2
+ import { AuroraPostgresEngineVersion, CfnDBInstance, Credentials, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot, InstanceUpdateBehaviour, ParameterGroup, } from "aws-cdk-lib/aws-rds";
3
+ import { Construct } from "constructs/lib/construct.js";
3
4
  import { Secret } from "aws-cdk-lib/aws-secretsmanager";
4
5
  import { exportValue, importVpc } from "../import-util.mjs";
5
6
  import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib/core";
@@ -14,11 +15,15 @@ import { createParameter } from "../stack/parameters.mjs";
14
15
  * stack, but cluster is not part of the stack after that.
15
16
  */
16
17
  export class DbStack extends Stack {
18
+ static CLUSTER_PORT = 5432;
19
+ static CLUSTER_IDENTIFIER_EXPORT_NAME = "db-cluster";
20
+ static CLUSTER_READ_ENDPOINT_EXPORT_NAME = "db-cluster-reader-endpoint";
21
+ static CLUSTER_WRITE_ENDPOINT_EXPORT_NAME = "db-cluster-writer-endpoint";
22
+ clusterIdentifier = "";
17
23
  constructor(scope, id, isc, configuration) {
18
24
  super(scope, id, {
19
25
  env: isc.env,
20
26
  });
21
- this.clusterIdentifier = "";
22
27
  const parameterGroups = this.createParameterGroups(configuration.customParameterGroups, configuration.workmem ?? 524288);
23
28
  if ((configuration.cluster && configuration.clusterImport) ||
24
29
  (!configuration.cluster && !configuration.clusterImport)) {
@@ -100,6 +105,9 @@ export class DbStack extends Stack {
100
105
  const vpc = configuration.vpc
101
106
  ? configuration.vpc
102
107
  : importVpc(this, isc.environmentName);
108
+ if (parameterGroups[0] === undefined) {
109
+ throw Error('ParameterGroups should not be empty');
110
+ }
103
111
  const parameters = this.createClusterParameters(configuration.secretArn, clusterConfiguration, instanceName, vpc, securityGroup, parameterGroups[0]);
104
112
  // create cluster from the snapshot or from the scratch
105
113
  const cluster = clusterConfiguration.snapshotIdentifier
@@ -119,8 +127,4 @@ export class DbStack extends Stack {
119
127
  return cluster;
120
128
  }
121
129
  }
122
- DbStack.CLUSTER_PORT = 5432;
123
- DbStack.CLUSTER_IDENTIFIER_EXPORT_NAME = "db-cluster";
124
- DbStack.CLUSTER_READ_ENDPOINT_EXPORT_NAME = "db-cluster-reader-endpoint";
125
- DbStack.CLUSTER_WRITE_ENDPOINT_EXPORT_NAME = "db-cluster-writer-endpoint";
126
130
  //# sourceMappingURL=db-stack.mjs.map
@@ -1,4 +1,4 @@
1
- import { Environment } from "aws-cdk-lib/core";
1
+ import type { Environment } from "aws-cdk-lib/core";
2
2
  export interface InfraStackConfiguration {
3
3
  readonly env: Environment;
4
4
  readonly environmentName: string;
@@ -1,5 +1,5 @@
1
- import { IVpc, Vpc } from "aws-cdk-lib/aws-ec2";
2
- import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
1
+ import { type IVpc, Vpc } from "aws-cdk-lib/aws-ec2";
2
+ import type { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
3
3
  import { Stack } from "aws-cdk-lib/core";
4
4
  import { Construct } from "constructs/lib/construct.js";
5
5
  export interface NetworkConfiguration {
@@ -1,12 +1,20 @@
1
1
  import { IpAddresses, SubnetType, Vpc } from "aws-cdk-lib/aws-ec2";
2
2
  import { exportValue } from "../import-util.mjs";
3
3
  import { Stack } from "aws-cdk-lib/core";
4
+ import { Construct } from "constructs/lib/construct.js";
4
5
  export class NetworkStack extends Stack {
6
+ vpc;
5
7
  constructor(scope, id, isc, configuration) {
6
8
  super(scope, id, {
7
9
  env: isc.env,
8
10
  });
9
11
  this.vpc = this.createVpc(configuration);
12
+ if (this.vpc.publicSubnets[0] === undefined ||
13
+ this.vpc.publicSubnets[1] === undefined ||
14
+ this.vpc.privateSubnets[0] === undefined ||
15
+ this.vpc.privateSubnets[1] === undefined) {
16
+ throw Error('Subnets are not set correctly');
17
+ }
10
18
  exportValue(this, isc.environmentName, "VPCID", this.vpc.vpcId);
11
19
  exportValue(this, isc.environmentName, "digitrafficpublicASubnet", this.vpc.publicSubnets[0].subnetId);
12
20
  exportValue(this, isc.environmentName, "digitrafficpublicBSubnet", this.vpc.publicSubnets[1].subnetId);
@@ -1,4 +1,4 @@
1
- import { IApiKey, RestApi } from "aws-cdk-lib/aws-apigateway";
1
+ import { type IApiKey, RestApi } from "aws-cdk-lib/aws-apigateway";
2
2
  /**
3
3
  * Creates an usage plan for a REST API with a single API key
4
4
  * @param api The REST API
@@ -1,3 +1,4 @@
1
+ import { RestApi } from "aws-cdk-lib/aws-apigateway";
1
2
  /**
2
3
  * Creates an usage plan for a REST API with a single API key
3
4
  * @param api The REST API
@@ -1,2 +1,2 @@
1
- import { APIGateway } from "aws-sdk";
2
- export declare function getApiKeyFromAPIGateway(keyId: string): Promise<APIGateway.Types.ApiKey>;
1
+ import type { APIGateway as APIGatewayType } from "aws-sdk";
2
+ export declare function getApiKeyFromAPIGateway(keyId: string): Promise<APIGatewayType.Types.ApiKey>;
@@ -1,4 +1,5 @@
1
- import { APIGateway } from "aws-sdk";
1
+ import awsSdk from "aws-sdk";
2
+ const { APIGateway } = awsSdk;
2
3
  export function getApiKeyFromAPIGateway(keyId) {
3
4
  const agw = new APIGateway();
4
5
  return agw.getApiKey({
@@ -1,4 +1,4 @@
1
- import { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
1
+ import type { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
2
2
  import { MediaType } from "../types/mediatypes.mjs";
3
3
  export declare abstract class DigitrafficIntegrationResponse {
4
4
  static ok(mediaType: MediaType, sunset?: string): IntegrationResponse;
@@ -1,3 +1,4 @@
1
+ import { Writable } from "stream";
1
2
  import _ from "lodash";
2
3
  /**
3
4
  * Helper class for json-logging.
@@ -9,6 +10,9 @@ import _ from "lodash";
9
10
  * * the actual message (as json or as string)
10
11
  */
11
12
  export class DtLogger {
13
+ lambdaName;
14
+ runtime;
15
+ writeStream;
12
16
  /**
13
17
  * Create a new Logger instance.
14
18
  * @constructor
@@ -16,8 +20,8 @@ export class DtLogger {
16
20
  */
17
21
  constructor(config) {
18
22
  this.lambdaName =
19
- config?.lambdaName ?? process.env.AWS_LAMBDA_FUNCTION_NAME;
20
- this.runtime = config?.runTime ?? process.env.AWS_EXECUTION_ENV;
23
+ config?.lambdaName ?? process.env['AWS_LAMBDA_FUNCTION_NAME'];
24
+ this.runtime = config?.runTime ?? process.env['AWS_EXECUTION_ENV'];
21
25
  this.writeStream = config?.writeStream ?? process.stdout;
22
26
  }
23
27
  /**
@@ -1,4 +1,4 @@
1
- import { SNS } from "aws-sdk";
1
+ import type { SNS as SNSType } from "aws-sdk";
2
2
  /**
3
3
  * Utility function for publishing SNS messages.
4
4
  * Made because using *await* with AWS APIs doesn't require calling promise() but nothing works if it isn't called.
@@ -7,4 +7,4 @@ import { SNS } from "aws-sdk";
7
7
  * @param topicArn
8
8
  * @param sns
9
9
  */
10
- export declare function snsPublish(message: string, topicArn: string, sns: SNS): Promise<void>;
10
+ export declare function snsPublish(message: string, topicArn: string, sns: SNSType): Promise<void>;
@@ -1,2 +1,2 @@
1
- import { S3 } from "aws-sdk";
2
- export declare function uploadToS3<Body extends S3.Body | undefined>(bucketName: string, body: Body, objectName: string, cannedAcl?: string, contentType?: string): Promise<void>;
1
+ import type { S3 as S3Type } from "aws-sdk";
2
+ export declare function uploadToS3<Body extends S3Type.Body | undefined>(bucketName: string, body: Body, objectName: string, cannedAcl?: string, contentType?: string): Promise<void>;
@@ -1,4 +1,5 @@
1
- import { S3 } from "aws-sdk";
1
+ import awsSdk from "aws-sdk";
2
+ const { S3 } = awsSdk;
2
3
  export async function uploadToS3(bucketName, body, objectName, cannedAcl, contentType) {
3
4
  const s3 = new S3();
4
5
  try {
@@ -1,4 +1,4 @@
1
- import { GenericSecret } from "./secret.mjs";
1
+ import type { GenericSecret } from "./secret.mjs";
2
2
  export declare enum RdsProxySecretKey {
3
3
  username = "username",
4
4
  password = "password",
@@ -7,6 +7,7 @@ const RDS_PROXY_SECRET_KEYS = Object.values(RdsProxySecretKey);
7
7
  * Holds credentials for RDS Proxy access.
8
8
  */
9
9
  export class ProxyHolder {
10
+ secretHolder;
10
11
  constructor(secretId) {
11
12
  this.secretHolder = new SecretHolder(secretId, "", RDS_PROXY_SECRET_KEYS);
12
13
  }
@@ -7,6 +7,7 @@ const RDS_SECRET_KEYS = Object.values(RdsSecretKey);
7
7
  * Holds credentials for RDS access.
8
8
  */
9
9
  export class RdsHolder {
10
+ secretHolder;
10
11
  constructor(secretId) {
11
12
  this.secretHolder = new SecretHolder(secretId, "", RDS_SECRET_KEYS);
12
13
  }
@@ -1,4 +1,4 @@
1
- import { GenericSecret } from "./secret.mjs";
1
+ import { type GenericSecret } from "./secret.mjs";
2
2
  /**
3
3
  * Utility class for getting secrets from Secret Manager.
4
4
  * Supports prefix for secrets, checking of expected keys and ttl-configuration.
@@ -21,6 +21,10 @@ const DEFAULT_CONFIGURATION = {
21
21
  *
22
22
  */
23
23
  export class SecretHolder {
24
+ secretId;
25
+ prefix;
26
+ expectedKeys;
27
+ secretCache;
24
28
  constructor(secretId, prefix = "", expectedKeys = [], configuration = DEFAULT_CONFIGURATION) {
25
29
  this.secretId = secretId;
26
30
  this.prefix = prefix;
@@ -55,7 +59,8 @@ export class SecretHolder {
55
59
  const skip = prefix.length;
56
60
  for (const key in secret) {
57
61
  if (key.startsWith(prefix)) {
58
- parsed[key.substring(skip)] = secret[key];
62
+ const withoutPrefix = key.substring(skip);
63
+ parsed[withoutPrefix] = secret[key];
59
64
  }
60
65
  }
61
66
  return parsed;
@@ -1,6 +1,7 @@
1
- import { SecretsManager } from "aws-sdk";
1
+ import awsSdk from "aws-sdk";
2
2
  import { getEnvVariable, getEnvVariableOrElse } from "../../../utils/utils.mjs";
3
3
  import { EnvKeys } from "../environment.mjs";
4
+ const { SecretsManager } = awsSdk;
4
5
  // SECRET_OVERRIDE_AWS_REGION might not have been set before import of
5
6
  // secret, so we need to lazy initialize SecretsManager
6
7
  let smClient;
@@ -33,7 +34,8 @@ function parseSecret(secret, prefix) {
33
34
  const skip = prefix.length;
34
35
  for (const key in secret) {
35
36
  if (key.startsWith(prefix)) {
36
- parsed[key.substring(skip)] = secret[key];
37
+ const withoutPrefix = key.substring(skip);
38
+ parsed[withoutPrefix] = secret[key];
37
39
  }
38
40
  }
39
41
  return parsed;
@@ -4,6 +4,7 @@ export const ERROR_MESSAGE = "ERROR";
4
4
  export const OK_MESSAGE = "OK";
5
5
  export const BAD_REQUEST_MESSAGE = "BAD REQUEST";
6
6
  export class ValidationError extends Error {
7
+ statusCode;
7
8
  constructor(statusCode, body) {
8
9
  super(body);
9
10
  this.statusCode = statusCode;
@@ -1,5 +1,10 @@
1
1
  import etag from "etag";
2
2
  export class LambdaResponse {
3
+ status;
4
+ body;
5
+ fileName;
6
+ timestamp;
7
+ etag;
3
8
  constructor(status, body, fileName, timestamp) {
4
9
  this.status = status;
5
10
  this.body = body;
@@ -1,2 +1,2 @@
1
- export {};
1
+ import { Model } from "aws-cdk-lib/aws-apigateway";
2
2
  //# sourceMappingURL=model-with-reference.mjs.map
@@ -1,4 +1,4 @@
1
- import { DTDatabase, DTTransaction } from "./database.mjs";
1
+ import type { DTDatabase, DTTransaction } from "./database.mjs";
2
2
  export interface CachedValue<T> {
3
3
  content: T;
4
4
  last_updated: Date;
@@ -1,3 +1,4 @@
1
+ import {} from "pg-promise";
1
2
  import { getEnvVariable, getEnvVariableOrElse } from "../utils/utils.mjs";
2
3
  import { logger } from "../aws/runtime/dt-logger-default.mjs";
3
4
  import { logException } from "../utils/logging.mjs";
@@ -1,4 +1,4 @@
1
- import { DTDatabase, DTTransaction } from "./database.mjs";
1
+ import type { DTDatabase, DTTransaction } from "./database.mjs";
2
2
  export declare enum DataType {
3
3
  VS_DATEX2 = "VS_DATEX2",
4
4
  COUNTING_SITES_DATA = "COUNTING_SITES_DATA",
@@ -1,3 +1,3 @@
1
- import { DTDatabase } from "../database/database.mjs";
1
+ import { type DTDatabase } from "../database/database.mjs";
2
2
  export declare function assertCount(db: DTDatabase, sql: string, count: number): Promise<void>;
3
3
  export declare function dbTestBase(fn: (db: DTDatabase) => void, truncateFn: (db: DTDatabase) => Promise<void>, dbUser: string, dbPass: string, dbUri: string): () => void;
@@ -3,7 +3,7 @@ export async function assertCount(db, sql, count) {
3
3
  await db.one(sql).then((x) => expect(x.count).toEqual(count));
4
4
  }
5
5
  export function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri) {
6
- const theDbUri = process.env.DB_URI ?? dbUri;
6
+ const theDbUri = process.env['DB_URI'] ?? dbUri;
7
7
  console.log(`Test database URI: ${theDbUri}`);
8
8
  return () => {
9
9
  const db = initDbConnection(dbUser, dbPass, "test", theDbUri, {
@@ -1,4 +1,4 @@
1
- import { createServer } from "http";
1
+ import { Server, createServer } from "http";
2
2
  import { parse } from "url";
3
3
  export const ERROR_NO_MATCH = "NO MATCH";
4
4
  export const ERRORCODE_NOT_FOUND = 404;
@@ -6,6 +6,9 @@ export const ERRORCODE_NOT_FOUND = 404;
6
6
  * A mock HTTP server created for testing connections from a Lambda to an outside integration
7
7
  */
8
8
  export class TestHttpServer {
9
+ server;
10
+ debug;
11
+ messageStack;
9
12
  constructor() {
10
13
  this.debug = false;
11
14
  this.messageStack = [];
@@ -14,7 +17,7 @@ export class TestHttpServer {
14
17
  return this.messageStack.length;
15
18
  }
16
19
  getRequestBody(callNumber) {
17
- return this.messageStack[callNumber];
20
+ return this.messageStack[callNumber] ?? '';
18
21
  }
19
22
  listen(port, props, debug = false, statusCode = 200) {
20
23
  this.debug = debug;
@@ -45,7 +48,8 @@ export class TestHttpServer {
45
48
  req.on("end", () => {
46
49
  // assume sent data is in JSON format
47
50
  this.messageStack[this.messageStack.length] = dataStr;
48
- res.end(props[path](req.url, dataStr));
51
+ const invokable = props[path];
52
+ res.end(invokable(req.url, dataStr));
49
53
  });
50
54
  }
51
55
  else {
@@ -1,4 +1,4 @@
1
- import * as sinon from "sinon";
1
+ import sinon from "sinon";
2
2
  /**
3
3
  * Stub Secrets Manager for tests. You must call this
4
4
  * before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
@@ -1,5 +1,5 @@
1
1
  import AWS from "aws-sdk";
2
- import * as sinon from "sinon";
2
+ import sinon from "sinon";
3
3
  import { EnvKeys } from "../aws/runtime/environment.mjs";
4
4
  import { setEnvVariable } from "../utils/utils.mjs";
5
5
  setEnvVariable(EnvKeys.AWS_REGION, "eu-west-1");
@@ -27,7 +27,7 @@ export function shuffle(array) {
27
27
  // pretty fast way to copy an array, not necessarily the fastest
28
28
  const newArray = array.slice(0);
29
29
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
- newArray.sort((x) => 0.5 - Math.random());
30
+ newArray.sort((_) => 0.5 - Math.random());
31
31
  return newArray;
32
32
  }
33
33
  //# sourceMappingURL=testutils.mjs.map
@@ -1,4 +1,5 @@
1
1
  export class HttpError extends Error {
2
+ statusCode;
2
3
  constructor(statusCode, message) {
3
4
  super(message);
4
5
  this.statusCode = statusCode;
@@ -1,4 +1,4 @@
1
- import { ValueOf } from "./util-types.mjs";
1
+ import type { ValueOf } from "./util-types.mjs";
2
2
  /**
3
3
  * Adds `null` as an accepted type to all properties in given type.
4
4
  */
@@ -1,5 +1,5 @@
1
- import { RestApi, Model, JsonSchema, RequestValidator, JsonSchemaType, JsonSchemaVersion } from 'aws-cdk-lib/aws-apigateway';
2
- import { ModelWithReference } from "../aws/types/model-with-reference.mjs";
1
+ import { RestApi, Model, type JsonSchema, RequestValidator, JsonSchemaType, JsonSchemaVersion } from 'aws-cdk-lib/aws-apigateway';
2
+ import type { ModelWithReference } from "../aws/types/model-with-reference.mjs";
3
3
  /**
4
4
  * Get a reference to an OpenAPI model object in a REST API.
5
5
  * Can be used to supply a reference to properties of a GeoJSON feature.
@@ -1,4 +1,4 @@
1
- import { JsonSchemaType, JsonSchemaVersion, } from 'aws-cdk-lib/aws-apigateway';
1
+ import { RestApi, Model, RequestValidator, JsonSchemaType, JsonSchemaVersion, } from 'aws-cdk-lib/aws-apigateway';
2
2
  /**
3
3
  * Get a reference to an OpenAPI model object in a REST API.
4
4
  * Can be used to supply a reference to properties of a GeoJSON feature.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * GeoJSON types
3
3
  */
4
- import { LineString, Point, Position } from "geojson";
4
+ import type { LineString, Point, Position } from "geojson";
5
5
  export declare class GeoJsonPoint implements Point {
6
6
  readonly type = "Point";
7
7
  readonly coordinates: Position;
@@ -1,12 +1,14 @@
1
1
  export class GeoJsonPoint {
2
+ type = "Point";
3
+ coordinates;
2
4
  constructor(coordinates) {
3
- this.type = "Point";
4
5
  this.coordinates = coordinates;
5
6
  }
6
7
  }
7
8
  export class GeoJsonLineString {
9
+ type = "LineString";
10
+ coordinates;
8
11
  constructor(coordinates) {
9
- this.type = "LineString";
10
12
  this.coordinates = coordinates;
11
13
  }
12
14
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * GeoJSON functions and tools
3
3
  */
4
- import { Feature, FeatureCollection, Geometry, Position } from "geojson";
4
+ import type { Feature, FeatureCollection, Geometry, Position } from "geojson";
5
5
  export declare const SRID_WGS84 = 4326;
6
6
  /**
7
7
  * Creates WKT geometry from GeoJSON geometry
@@ -87,6 +87,9 @@ function distanceBetweenWGS84PointsInKm(fromXLon, fromYLat, toXLon, toYLat) {
87
87
  * @param pos2
88
88
  */
89
89
  export function distanceBetweenPositionsInKm(pos1, pos2) {
90
+ if (pos1.length !== 2 && pos2.length !== 2) {
91
+ throw Error(`Positions ${pos1.toString()} and ${pos2.toString()} both must be arrays of length two`);
92
+ }
90
93
  return distanceBetweenWGS84PointsInKm(pos1[0], pos1[1], pos2[0], pos2[1]);
91
94
  }
92
95
  export function areDistinctPositions(previous, next) {
@@ -9,7 +9,7 @@ export type RetryPredicate = (error: unknown) => boolean;
9
9
  * Utility timeout functions for "retry" function.
10
10
  */
11
11
  export declare const timeoutFunctions: {
12
- noTimeout: (retryCount: number) => number;
12
+ noTimeout: (_: number) => number;
13
13
  exponentialTimeout: (retryCount: number) => number;
14
14
  };
15
15
  /**
@@ -17,7 +17,7 @@ export declare const timeoutFunctions: {
17
17
  */
18
18
  export declare const retryPredicates: {
19
19
  retryBasedOnStatusCode: (error: unknown) => boolean;
20
- alwaysRetry: (error: unknown) => boolean;
20
+ alwaysRetry: (_: unknown) => boolean;
21
21
  };
22
22
  export declare let retryCount: number;
23
23
  /**
@@ -13,7 +13,7 @@ export var RetryLogError;
13
13
  export const timeoutFunctions = (function () {
14
14
  return {
15
15
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- noTimeout: (retryCount) => {
16
+ noTimeout: (_) => {
17
17
  return 0;
18
18
  },
19
19
  exponentialTimeout: (retryCount) => {
@@ -39,7 +39,7 @@ export const retryPredicates = (function () {
39
39
  return false;
40
40
  },
41
41
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- alwaysRetry: (error) => {
42
+ alwaysRetry: (_) => {
43
43
  return true;
44
44
  },
45
45
  };
@@ -2,6 +2,7 @@ import axios from "axios";
2
2
  import { logger } from "../aws/runtime/dt-logger-default.mjs";
3
3
  import { logException } from "./logging.mjs";
4
4
  export class SlackApi {
5
+ url;
5
6
  constructor(url) {
6
7
  this.url = url;
7
8
  }
@@ -1,5 +1,5 @@
1
- import { AwsEnv } from "../types/aws-env.mjs";
2
- import { Either } from "../types/either.mjs";
1
+ import type { AwsEnv } from "../types/aws-env.mjs";
2
+ import type { Either } from "../types/either.mjs";
3
3
  /**
4
4
  * Check if arrays have only elements that also exists also in other array.
5
5
  * Individual element count doesn't matter.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.1.24-3",
3
+ "version": "2024.1.30-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -14,8 +14,7 @@
14
14
  "private": false,
15
15
  "files": [
16
16
  "dist/**/*.mjs",
17
- "dist/**/*.d.mts",
18
- "src/**/*.mts"
17
+ "dist/**/*.d.mts"
19
18
  ],
20
19
  "exports": {
21
20
  ".": "./dist/index.mjs",
@@ -121,6 +120,11 @@
121
120
  },
122
121
  "devDependencies": {
123
122
  "@jest/globals": "^29.7.0",
123
+ "@rushstack/eslint-config": "^3.6.2",
124
+ "@rushstack/heft": "^0.64.3",
125
+ "@rushstack/heft-jest-plugin": "^0.11.3",
126
+ "@rushstack/heft-lint-plugin": "^0.3.3",
127
+ "@rushstack/heft-typescript-plugin": "^0.3.3",
124
128
  "@types/aws-lambda": "8.10.131",
125
129
  "@types/etag": "1.8.3",
126
130
  "@types/geojson": "7946.0.13",
@@ -130,10 +134,10 @@
130
134
  "@types/node": "20.10.7",
131
135
  "@types/sinon": "17.0.2",
132
136
  "@typescript-eslint/eslint-plugin": "~6.18.1",
133
- "@typescript-eslint/parser": "^6.19.1",
137
+ "@typescript-eslint/parser": "^6.20.0",
134
138
  "aws-cdk-lib": "~2.118.0",
135
139
  "aws-sdk": "~2.1531.0",
136
- "axios": "^1.6.5",
140
+ "axios": "^1.6.7",
137
141
  "change-case": "5.3.0",
138
142
  "constructs": "10.3.0",
139
143
  "date-fns": "~2.30.0",
@@ -166,7 +170,8 @@
166
170
  "eslint-report": "eslint . --format html",
167
171
  "ci:eslint-report": "eslint . --format html -o report.html || true",
168
172
  "clean": "rimraf dist output",
169
- "test": "node --experimental-vm-modules --max-old-space-size=1536 --expose-gc ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand",
173
+ "test": "NODE_OPTIONS='--experimental-vm-modules' heft test --clean --max-workers=1",
174
+ "test:jest": "node --trace-warnings --experimental-vm-modules --max-old-space-size=1536 --expose-gc ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand --verbose",
170
175
  "test:inspect": "node --inspect-brk --expose-gc ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand",
171
176
  "test:watch": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --watch"
172
177
  }
@@ -1,4 +0,0 @@
1
- declare module "geojson-validation" {
2
- export function valid(json): boolean;
3
- export function isFeatureCollection(json): boolean;
4
- }