@digitraffic/common 2024.1.24-3 → 2024.3.11-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 (212) 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 +86 -0
  15. package/dist/__test__/secrets/secret.test.d.mts +1 -0
  16. package/dist/__test__/secrets/secret.test.mjs +38 -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__/test/mock-ky.test.d.mts +1 -0
  20. package/dist/__test__/test/mock-ky.test.mjs +46 -0
  21. package/dist/__test__/types/lambda-response.test.d.mts +1 -0
  22. package/dist/__test__/types/lambda-response.test.mjs +58 -0
  23. package/dist/__test__/utils/date-utils.test.d.mts +1 -0
  24. package/dist/__test__/utils/date-utils.test.mjs +27 -0
  25. package/dist/__test__/utils/geometry.test.d.mts +1 -0
  26. package/dist/__test__/utils/geometry.test.mjs +24 -0
  27. package/dist/__test__/utils/logging.test.d.mts +1 -0
  28. package/dist/__test__/utils/logging.test.mjs +78 -0
  29. package/dist/__test__/utils/utils.test.d.mts +1 -0
  30. package/dist/__test__/utils/utils.test.mjs +43 -0
  31. package/dist/aws/infra/api/handler-factory.mjs +4 -0
  32. package/dist/aws/infra/api/integration.d.mts +2 -2
  33. package/dist/aws/infra/api/integration.mjs +4 -1
  34. package/dist/aws/infra/api/response.d.mts +1 -1
  35. package/dist/aws/infra/api/responses.d.mts +1 -1
  36. package/dist/aws/infra/api/responses.mjs +2 -0
  37. package/dist/aws/infra/api/static-integration.mjs +1 -1
  38. package/dist/aws/infra/canaries/canary-alarm.d.mts +1 -1
  39. package/dist/aws/infra/canaries/canary-alarm.mjs +2 -0
  40. package/dist/aws/infra/canaries/canary-parameters.mjs +1 -1
  41. package/dist/aws/infra/canaries/canary-role.mjs +1 -0
  42. package/dist/aws/infra/canaries/canary.d.mts +2 -2
  43. package/dist/aws/infra/canaries/canary.mjs +2 -0
  44. package/dist/aws/infra/canaries/database-canary.d.mts +2 -2
  45. package/dist/aws/infra/canaries/database-canary.mjs +2 -0
  46. package/dist/aws/infra/canaries/database-checker.d.mts +1 -1
  47. package/dist/aws/infra/canaries/database-checker.mjs +7 -1
  48. package/dist/aws/infra/canaries/url-canary.d.mts +2 -2
  49. package/dist/aws/infra/canaries/url-canary.mjs +3 -0
  50. package/dist/aws/infra/canaries/url-checker.d.mts +1 -1
  51. package/dist/aws/infra/canaries/url-checker.mjs +4 -1
  52. package/dist/aws/infra/documentation.mjs +5 -1
  53. package/dist/aws/infra/import-util.d.mts +1 -1
  54. package/dist/aws/infra/import-util.mjs +4 -3
  55. package/dist/aws/infra/scheduler.mjs +2 -0
  56. package/dist/aws/infra/security-rule.d.mts +1 -1
  57. package/dist/aws/infra/security-rule.mjs +1 -0
  58. package/dist/aws/infra/sqs-integration.d.mts +1 -1
  59. package/dist/aws/infra/sqs-integration.mjs +3 -1
  60. package/dist/aws/infra/sqs-queue.d.mts +1 -1
  61. package/dist/aws/infra/sqs-queue.mjs +2 -1
  62. package/dist/aws/infra/stack/lambda-configs.d.mts +4 -4
  63. package/dist/aws/infra/stack/lambda-configs.mjs +4 -2
  64. package/dist/aws/infra/stack/monitoredfunction.d.mts +3 -3
  65. package/dist/aws/infra/stack/monitoredfunction.mjs +23 -18
  66. package/dist/aws/infra/stack/parameters.mjs +1 -0
  67. package/dist/aws/infra/stack/rest_apis.d.mts +2 -2
  68. package/dist/aws/infra/stack/rest_apis.mjs +6 -1
  69. package/dist/aws/infra/stack/stack-checking-aspect.d.mts +2 -2
  70. package/dist/aws/infra/stack/stack-checking-aspect.mjs +6 -1
  71. package/dist/aws/infra/stack/stack.d.mts +5 -5
  72. package/dist/aws/infra/stack/stack.mjs +9 -0
  73. package/dist/aws/infra/stack/subscription.mjs +4 -0
  74. package/dist/aws/infra/stacks/db-dns-stack.d.mts +1 -1
  75. package/dist/aws/infra/stacks/db-dns-stack.mjs +1 -0
  76. package/dist/aws/infra/stacks/db-proxy-stack.d.mts +3 -3
  77. package/dist/aws/infra/stacks/db-proxy-stack.mjs +4 -2
  78. package/dist/aws/infra/stacks/db-stack.d.mts +3 -3
  79. package/dist/aws/infra/stacks/db-stack.mjs +11 -7
  80. package/dist/aws/infra/stacks/intra-stack-configuration.d.mts +1 -1
  81. package/dist/aws/infra/stacks/network-stack.d.mts +2 -2
  82. package/dist/aws/infra/stacks/network-stack.mjs +8 -0
  83. package/dist/aws/infra/usage-plans.d.mts +1 -1
  84. package/dist/aws/infra/usage-plans.mjs +1 -0
  85. package/dist/aws/runtime/apikey.d.mts +2 -2
  86. package/dist/aws/runtime/apikey.mjs +2 -2
  87. package/dist/aws/runtime/digitraffic-integration-response.d.mts +1 -1
  88. package/dist/aws/runtime/dt-logger.mjs +6 -2
  89. package/dist/aws/runtime/messaging.d.mts +2 -2
  90. package/dist/aws/runtime/messaging.mjs +5 -4
  91. package/dist/aws/runtime/s3.d.mts +4 -2
  92. package/dist/aws/runtime/s3.mjs +15 -10
  93. package/dist/aws/runtime/secrets/dbsecret.d.mts +1 -1
  94. package/dist/aws/runtime/secrets/proxy-holder.mjs +1 -0
  95. package/dist/aws/runtime/secrets/rds-holder.mjs +1 -0
  96. package/dist/aws/runtime/secrets/secret-holder.d.mts +1 -1
  97. package/dist/aws/runtime/secrets/secret-holder.mjs +6 -1
  98. package/dist/aws/runtime/secrets/secret.mjs +5 -6
  99. package/dist/aws/types/errors.mjs +1 -0
  100. package/dist/aws/types/lambda-response.mjs +5 -0
  101. package/dist/aws/types/model-with-reference.mjs +1 -1
  102. package/dist/database/cached.d.mts +1 -1
  103. package/dist/database/database.mjs +1 -0
  104. package/dist/database/last-updated.d.mts +1 -1
  105. package/dist/test/db-testutils.d.mts +1 -1
  106. package/dist/test/db-testutils.mjs +1 -1
  107. package/dist/test/httpserver.mjs +7 -3
  108. package/dist/test/mock-ky.d.mts +2 -0
  109. package/dist/test/mock-ky.mjs +15 -0
  110. package/dist/test/secrets-manager.d.mts +3 -2
  111. package/dist/test/secrets-manager.mjs +14 -16
  112. package/dist/test/testutils.mjs +1 -1
  113. package/dist/types/http-error.mjs +1 -0
  114. package/dist/types/nullable.d.mts +1 -1
  115. package/dist/utils/api-model.d.mts +2 -2
  116. package/dist/utils/api-model.mjs +1 -1
  117. package/dist/utils/geojson-types.d.mts +1 -1
  118. package/dist/utils/geojson-types.mjs +4 -2
  119. package/dist/utils/geometry.d.mts +1 -1
  120. package/dist/utils/geometry.mjs +3 -0
  121. package/dist/utils/logging.mjs +2 -2
  122. package/dist/utils/retry.d.mts +2 -2
  123. package/dist/utils/retry.mjs +2 -2
  124. package/dist/utils/slack.mjs +4 -3
  125. package/dist/utils/utils.d.mts +2 -2
  126. package/package.json +25 -15
  127. package/src/@types/geojson-validation/index.d.mts +0 -4
  128. package/src/aws/infra/api/handler-factory.mts +0 -86
  129. package/src/aws/infra/api/integration.mts +0 -147
  130. package/src/aws/infra/api/response.mts +0 -165
  131. package/src/aws/infra/api/responses.mts +0 -127
  132. package/src/aws/infra/api/static-integration.mts +0 -108
  133. package/src/aws/infra/canaries/Synthetics.d.mts +0 -21
  134. package/src/aws/infra/canaries/canary-alarm.mts +0 -33
  135. package/src/aws/infra/canaries/canary-keys.mts +0 -3
  136. package/src/aws/infra/canaries/canary-parameters.mts +0 -19
  137. package/src/aws/infra/canaries/canary-role.mts +0 -73
  138. package/src/aws/infra/canaries/canary.mts +0 -44
  139. package/src/aws/infra/canaries/database-canary.mts +0 -98
  140. package/src/aws/infra/canaries/database-checker.mts +0 -163
  141. package/src/aws/infra/canaries/url-canary.mts +0 -98
  142. package/src/aws/infra/canaries/url-checker.mts +0 -388
  143. package/src/aws/infra/documentation.mts +0 -142
  144. package/src/aws/infra/import-util.mts +0 -57
  145. package/src/aws/infra/scheduler.mts +0 -59
  146. package/src/aws/infra/security-rule.mts +0 -38
  147. package/src/aws/infra/sqs-integration.mts +0 -106
  148. package/src/aws/infra/sqs-queue.mts +0 -162
  149. package/src/aws/infra/stack/lambda-configs.mts +0 -135
  150. package/src/aws/infra/stack/monitoredfunction.mts +0 -352
  151. package/src/aws/infra/stack/parameters.mts +0 -74
  152. package/src/aws/infra/stack/rest_apis.mts +0 -322
  153. package/src/aws/infra/stack/stack-checking-aspect.mts +0 -233
  154. package/src/aws/infra/stack/stack.mts +0 -144
  155. package/src/aws/infra/stack/subscription.mts +0 -58
  156. package/src/aws/infra/stacks/db-dns-stack.mts +0 -77
  157. package/src/aws/infra/stacks/db-proxy-stack.mts +0 -134
  158. package/src/aws/infra/stacks/db-stack.mts +0 -292
  159. package/src/aws/infra/stacks/intra-stack-configuration.mts +0 -6
  160. package/src/aws/infra/stacks/network-stack.mts +0 -76
  161. package/src/aws/infra/usage-plans.mts +0 -50
  162. package/src/aws/runtime/apikey.mts +0 -9
  163. package/src/aws/runtime/digitraffic-integration-response.mts +0 -35
  164. package/src/aws/runtime/dt-logger-default.mts +0 -11
  165. package/src/aws/runtime/dt-logger.mts +0 -184
  166. package/src/aws/runtime/environment.mts +0 -22
  167. package/src/aws/runtime/messaging.mts +0 -26
  168. package/src/aws/runtime/s3.mts +0 -44
  169. package/src/aws/runtime/secrets/dbsecret.mts +0 -31
  170. package/src/aws/runtime/secrets/node-ttl.d.mts +0 -12
  171. package/src/aws/runtime/secrets/proxy-holder.mts +0 -34
  172. package/src/aws/runtime/secrets/rds-holder.mts +0 -34
  173. package/src/aws/runtime/secrets/secret-holder.mts +0 -106
  174. package/src/aws/runtime/secrets/secret.mts +0 -58
  175. package/src/aws/types/errors.mts +0 -14
  176. package/src/aws/types/lambda-response.mts +0 -100
  177. package/src/aws/types/mediatypes.mts +0 -12
  178. package/src/aws/types/model-with-reference.mts +0 -8
  179. package/src/aws/types/proxytypes.mts +0 -27
  180. package/src/aws/types/tags.mts +0 -3
  181. package/src/database/cached.mts +0 -64
  182. package/src/database/database.mts +0 -107
  183. package/src/database/last-updated.mts +0 -103
  184. package/src/database/models.mts +0 -7
  185. package/src/index.mts +0 -2
  186. package/src/marine/id_utils.mts +0 -30
  187. package/src/marine/rtz.mts +0 -57
  188. package/src/test/asserter.mts +0 -58
  189. package/src/test/db-testutils.mts +0 -52
  190. package/src/test/httpserver.mts +0 -111
  191. package/src/test/secrets-manager.mts +0 -37
  192. package/src/test/testutils.mts +0 -39
  193. package/src/types/async-timeout-error.mts +0 -5
  194. package/src/types/aws-env.mts +0 -3
  195. package/src/types/either.mts +0 -9
  196. package/src/types/http-error.mts +0 -8
  197. package/src/types/input-error.mts +0 -2
  198. package/src/types/language.mts +0 -3
  199. package/src/types/nullable.mts +0 -21
  200. package/src/types/traffictype.mts +0 -8
  201. package/src/types/urn.mts +0 -1
  202. package/src/types/util-types.mts +0 -10
  203. package/src/types/validator.mts +0 -10
  204. package/src/utils/api-model.mts +0 -133
  205. package/src/utils/base64.mts +0 -16
  206. package/src/utils/date-utils.mts +0 -53
  207. package/src/utils/geojson-types.mts +0 -22
  208. package/src/utils/geometry.mts +0 -171
  209. package/src/utils/logging.mts +0 -75
  210. package/src/utils/retry.mts +0 -200
  211. package/src/utils/slack.mts +0 -26
  212. package/src/utils/utils.mts +0 -184
@@ -1,4 +1,8 @@
1
1
  import { CfnSubscriptionFilter } from "aws-cdk-lib/aws-logs";
2
+ import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
3
+ import { DigitrafficStack } from "./stack.mjs";
4
+ import { Construct } from "constructs";
5
+ import { MonitoredFunction } from "./monitoredfunction.mjs";
2
6
  /**
3
7
  * Creates a subscription filter that subscribes to a Lambda Log Group and delivers the logs to another destination.
4
8
  * https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html
@@ -1,6 +1,6 @@
1
1
  import { Stack } from "aws-cdk-lib";
2
2
  import { type Construct } from "constructs";
3
- import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
3
+ import type { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
4
4
  /**
5
5
  * Creates a dns local zone and creates records for cluster endpoints and proxy endpoints.
6
6
  *
@@ -1,4 +1,5 @@
1
1
  import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
2
+ import {} from "constructs";
2
3
  import { PrivateHostedZone, RecordSet, RecordTarget, RecordType, } from "aws-cdk-lib/aws-route53";
3
4
  import { importVpc } from "../import-util.mjs";
4
5
  import { getParameterValue } from "../stack/parameters.mjs";
@@ -1,7 +1,7 @@
1
1
  import { CfnDBProxyEndpoint, DatabaseProxy } from "aws-cdk-lib/aws-rds";
2
- import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
3
- import { IVpc } from "aws-cdk-lib/aws-ec2";
4
- import { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
2
+ import { type ISecret } from "aws-cdk-lib/aws-secretsmanager";
3
+ import { type IVpc } from "aws-cdk-lib/aws-ec2";
4
+ import type { InfraStackConfiguration } from "./intra-stack-configuration.mjs";
5
5
  import { Stack } from "aws-cdk-lib/core";
6
6
  import { Construct } from "constructs/lib/construct.js";
7
7
  export interface ProxyConfiguration {
@@ -5,10 +5,14 @@ import { DbStack } from "./db-stack.mjs";
5
5
  import { exportValue, importVpc } from "../import-util.mjs";
6
6
  import { createParameter } from "../stack/parameters.mjs";
7
7
  import { Stack, Duration } from "aws-cdk-lib/core";
8
+ import { Construct } from "constructs/lib/construct.js";
8
9
  /**
9
10
  * A stack that creates a Database proxy.
10
11
  */
11
12
  export class DbProxyStack extends Stack {
13
+ isc;
14
+ static PROXY_READER_EXPORT_NAME = "db-reader-endpoint";
15
+ static PROXY_WRITER_EXPORT_NAME = "db-writer-endpoint";
12
16
  constructor(scope, id, isc, configuration) {
13
17
  super(scope, id, {
14
18
  env: isc.env,
@@ -68,6 +72,4 @@ export class DbProxyStack extends Stack {
68
72
  });
69
73
  }
70
74
  }
71
- DbProxyStack.PROXY_READER_EXPORT_NAME = "db-reader-endpoint";
72
- DbProxyStack.PROXY_WRITER_EXPORT_NAME = "db-writer-endpoint";
73
75
  //# sourceMappingURL=db-proxy-stack.mjs.map
@@ -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 { UpdateApiKeyCommandOutput } from "@aws-sdk/client-api-gateway";
2
+ export declare function getApiKeyFromAPIGateway(keyId: string): Promise<UpdateApiKeyCommandOutput>;
@@ -1,9 +1,9 @@
1
- import { APIGateway } from "aws-sdk";
1
+ import { APIGateway } from "@aws-sdk/client-api-gateway";
2
2
  export function getApiKeyFromAPIGateway(keyId) {
3
3
  const agw = new APIGateway();
4
4
  return agw.getApiKey({
5
5
  apiKey: keyId,
6
6
  includeValue: true,
7
- }).promise();
7
+ });
8
8
  }
9
9
  //# sourceMappingURL=apikey.mjs.map
@@ -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 { SNS as SNSType } from "@aws-sdk/client-sns";
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,3 +1,4 @@
1
+ import { SNS as SNSType } from "@aws-sdk/client-sns";
1
2
  /**
2
3
  * Utility function for publishing SNS messages.
3
4
  * Made because using *await* with AWS APIs doesn't require calling promise() but nothing works if it isn't called.
@@ -12,15 +13,15 @@ export async function snsPublish(message, topicArn, sns) {
12
13
  TopicArn: topicArn,
13
14
  };
14
15
  try {
15
- await sns.publish(publishParams).promise();
16
+ await sns.publish(publishParams);
16
17
  }
17
18
  catch (error) {
18
- console.error('method=snsPublish error, retrying', error);
19
+ console.error("method=snsPublish error, retrying", error);
19
20
  try {
20
- await sns.publish(publishParams).promise();
21
+ await sns.publish(publishParams);
21
22
  }
22
23
  catch (e2) {
23
- console.error('method=snsPublish error after retry', e2);
24
+ console.error("method=snsPublish error after retry", e2);
24
25
  }
25
26
  }
26
27
  }
@@ -1,2 +1,4 @@
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
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { ObjectCannedACL } from "@aws-sdk/client-s3";
3
+ import { Readable } from "node:stream";
4
+ export declare function uploadToS3(bucketName: string, body: Readable, objectName: string, cannedAcl?: ObjectCannedACL, contentType?: string): Promise<void>;
@@ -1,26 +1,31 @@
1
- import { S3 } from "aws-sdk";
1
+ import { Upload } from "@aws-sdk/lib-storage";
2
+ import { S3 } from "@aws-sdk/client-s3";
3
+ import { Readable } from "node:stream";
2
4
  export async function uploadToS3(bucketName, body, objectName, cannedAcl, contentType) {
3
5
  const s3 = new S3();
4
6
  try {
5
7
  await doUpload(s3, bucketName, body, objectName, cannedAcl, contentType);
6
8
  }
7
9
  catch (error) {
8
- console.warn('method=uploadToS3 retrying upload to bucket %s', bucketName);
10
+ console.warn("method=uploadToS3 retrying upload to bucket %s", bucketName);
9
11
  try {
10
12
  await doUpload(s3, bucketName, body, objectName, cannedAcl, contentType);
11
13
  }
12
14
  catch (e2) {
13
- console.error('method=uploadToS3 failed retrying upload to bucket %s', bucketName);
15
+ console.error("method=uploadToS3 failed retrying upload to bucket %s", bucketName);
14
16
  }
15
17
  }
16
18
  }
17
19
  function doUpload(s3, bucketName, body, filename, cannedAcl, contentType) {
18
- return s3.upload({
19
- Bucket: bucketName,
20
- Body: body,
21
- Key: filename,
22
- ACL: cannedAcl,
23
- ContentType: contentType,
24
- }).promise();
20
+ return new Upload({
21
+ client: s3,
22
+ params: {
23
+ Bucket: bucketName,
24
+ Body: body,
25
+ Key: filename,
26
+ ACL: cannedAcl,
27
+ ContentType: contentType,
28
+ },
29
+ }).done();
25
30
  }
26
31
  //# sourceMappingURL=s3.mjs.map
@@ -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,6 @@
1
- import { SecretsManager } from "aws-sdk";
2
1
  import { getEnvVariable, getEnvVariableOrElse } from "../../../utils/utils.mjs";
3
2
  import { EnvKeys } from "../environment.mjs";
3
+ const { SecretsManager } = await import("@aws-sdk/client-secrets-manager");
4
4
  // SECRET_OVERRIDE_AWS_REGION might not have been set before import of
5
5
  // secret, so we need to lazy initialize SecretsManager
6
6
  let smClient;
@@ -14,11 +14,9 @@ function getSmClient() {
14
14
  return smClient;
15
15
  }
16
16
  export async function getSecret(secretId, prefix = "") {
17
- const secretObj = await getSmClient()
18
- .getSecretValue({
17
+ const secretObj = await getSmClient().getSecretValue({
19
18
  SecretId: secretId,
20
- })
21
- .promise();
19
+ });
22
20
  if (!secretObj.SecretString) {
23
21
  throw new Error("No secret found!");
24
22
  }
@@ -33,7 +31,8 @@ function parseSecret(secret, prefix) {
33
31
  const skip = prefix.length;
34
32
  for (const key in secret) {
35
33
  if (key.startsWith(prefix)) {
36
- parsed[key.substring(skip)] = secret[key];
34
+ const withoutPrefix = key.substring(skip);
35
+ parsed[withoutPrefix] = secret[key];
37
36
  }
38
37
  }
39
38
  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 {
@@ -0,0 +1,2 @@
1
+ import type { ResponsePromise } from "ky";
2
+ export declare function mockKyResponse(status: number, body: string): ResponsePromise;
@@ -0,0 +1,15 @@
1
+ export function mockKyResponse(status, body) {
2
+ const response = new Response(body, {
3
+ status: status,
4
+ });
5
+ const promise = Promise.resolve(response);
6
+ // The ky ResponsePromise is just Promise<Response> with some convenience methods.
7
+ return Object.assign(promise, {
8
+ arrayBuffer: () => response.arrayBuffer(),
9
+ blob: () => response.blob(),
10
+ formData: () => response.formData(),
11
+ json: () => response.json(),
12
+ text: () => response.text(),
13
+ });
14
+ }
15
+ //# sourceMappingURL=mock-ky.mjs.map
@@ -1,9 +1,10 @@
1
- import * as sinon from "sinon";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
+ import sinon from "sinon";
2
3
  /**
3
4
  * Stub Secrets Manager for tests. You must call this
4
5
  * before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
5
6
  *
6
7
  * To mock the actual secret, call mockSecret()
7
8
  */
8
- export declare function stubSecretsManager(): sinon.SinonStub<any[], any>;
9
+ export declare function stubSecretsManager(): sinon.SinonStubbedInstance<SecretsManager>;
9
10
  export declare function mockSecret<Secret>(secret: Secret): void;
@@ -1,9 +1,12 @@
1
- import AWS from "aws-sdk";
2
- import * as sinon from "sinon";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
+ import sinon from "sinon";
3
3
  import { EnvKeys } from "../aws/runtime/environment.mjs";
4
4
  import { setEnvVariable } from "../utils/utils.mjs";
5
+ import { jest } from '@jest/globals';
5
6
  setEnvVariable(EnvKeys.AWS_REGION, "eu-west-1");
6
- const secretValue = sinon.stub();
7
+ const emptySecret = { $metadata: {} };
8
+ const SecretsManagerStubInstance = sinon.createStubInstance(SecretsManager);
9
+ SecretsManagerStubInstance.getSecretValue.resolves(emptySecret);
7
10
  /**
8
11
  * Stub Secrets Manager for tests. You must call this
9
12
  * before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
@@ -11,24 +14,19 @@ const secretValue = sinon.stub();
11
14
  * To mock the actual secret, call mockSecret()
12
15
  */
13
16
  export function stubSecretsManager() {
14
- const smStub = {
15
- getSecretValue: secretValue,
16
- };
17
- sinon.stub(AWS, "SecretsManager").returns(smStub);
18
- return smStub.getSecretValue;
17
+ jest.unstable_mockModule("@aws-sdk/client-secrets-manager", function () {
18
+ return {
19
+ SecretsManager: sinon.stub().returns(SecretsManagerStubInstance)
20
+ };
21
+ });
22
+ return SecretsManagerStubInstance;
19
23
  }
20
24
  export function mockSecret(secret) {
21
25
  if (!secret) {
22
- secretValue.returns({
23
- promise: sinon.stub().returns({}),
24
- });
26
+ SecretsManagerStubInstance.getSecretValue.resolves({ ...emptySecret });
25
27
  }
26
28
  else {
27
- secretValue.returns({
28
- promise: sinon.stub().returns({
29
- SecretString: JSON.stringify(secret),
30
- }),
31
- });
29
+ SecretsManagerStubInstance.getSecretValue.resolves({ SecretString: JSON.stringify(secret) });
32
30
  }
33
31
  }
34
32
  //# sourceMappingURL=secrets-manager.mjs.map
@@ -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;