@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.
- package/dist/__test__/api/handler-factory.test.d.mts +1 -0
- package/dist/__test__/api/handler-factory.test.mjs +43 -0
- package/dist/__test__/api/response.test.d.mts +1 -0
- package/dist/__test__/api/response.test.mjs +86 -0
- package/dist/__test__/imports.test.d.mts +1 -0
- package/dist/__test__/imports.test.mjs +332 -0
- package/dist/__test__/marine/id_utils.test.d.mts +1 -0
- package/dist/__test__/marine/id_utils.test.mjs +44 -0
- package/dist/__test__/promise/promise.test.d.mts +1 -0
- package/dist/__test__/promise/promise.test.mjs +130 -0
- package/dist/__test__/runtime/dt-logger.test.d.mts +1 -0
- package/dist/__test__/runtime/dt-logger.test.mjs +108 -0
- package/dist/__test__/secrets/secret-holder.test.d.mts +1 -0
- package/dist/__test__/secrets/secret-holder.test.mjs +86 -0
- package/dist/__test__/secrets/secret.test.d.mts +1 -0
- package/dist/__test__/secrets/secret.test.mjs +38 -0
- package/dist/__test__/test/httpserver.test.d.mts +1 -0
- package/dist/__test__/test/httpserver.test.mjs +154 -0
- package/dist/__test__/test/mock-ky.test.d.mts +1 -0
- package/dist/__test__/test/mock-ky.test.mjs +46 -0
- package/dist/__test__/types/lambda-response.test.d.mts +1 -0
- package/dist/__test__/types/lambda-response.test.mjs +58 -0
- package/dist/__test__/utils/date-utils.test.d.mts +1 -0
- package/dist/__test__/utils/date-utils.test.mjs +27 -0
- package/dist/__test__/utils/geometry.test.d.mts +1 -0
- package/dist/__test__/utils/geometry.test.mjs +24 -0
- package/dist/__test__/utils/logging.test.d.mts +1 -0
- package/dist/__test__/utils/logging.test.mjs +78 -0
- package/dist/__test__/utils/utils.test.d.mts +1 -0
- package/dist/__test__/utils/utils.test.mjs +43 -0
- package/dist/aws/infra/api/handler-factory.mjs +4 -0
- package/dist/aws/infra/api/integration.d.mts +2 -2
- package/dist/aws/infra/api/integration.mjs +4 -1
- package/dist/aws/infra/api/response.d.mts +1 -1
- package/dist/aws/infra/api/responses.d.mts +1 -1
- package/dist/aws/infra/api/responses.mjs +2 -0
- package/dist/aws/infra/api/static-integration.mjs +1 -1
- package/dist/aws/infra/canaries/canary-alarm.d.mts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.mjs +2 -0
- package/dist/aws/infra/canaries/canary-parameters.mjs +1 -1
- package/dist/aws/infra/canaries/canary-role.mjs +1 -0
- package/dist/aws/infra/canaries/canary.d.mts +2 -2
- package/dist/aws/infra/canaries/canary.mjs +2 -0
- package/dist/aws/infra/canaries/database-canary.d.mts +2 -2
- package/dist/aws/infra/canaries/database-canary.mjs +2 -0
- package/dist/aws/infra/canaries/database-checker.d.mts +1 -1
- package/dist/aws/infra/canaries/database-checker.mjs +7 -1
- package/dist/aws/infra/canaries/url-canary.d.mts +2 -2
- package/dist/aws/infra/canaries/url-canary.mjs +3 -0
- package/dist/aws/infra/canaries/url-checker.d.mts +1 -1
- package/dist/aws/infra/canaries/url-checker.mjs +4 -1
- package/dist/aws/infra/documentation.mjs +5 -1
- package/dist/aws/infra/import-util.d.mts +1 -1
- package/dist/aws/infra/import-util.mjs +4 -3
- package/dist/aws/infra/scheduler.mjs +2 -0
- package/dist/aws/infra/security-rule.d.mts +1 -1
- package/dist/aws/infra/security-rule.mjs +1 -0
- package/dist/aws/infra/sqs-integration.d.mts +1 -1
- package/dist/aws/infra/sqs-integration.mjs +3 -1
- package/dist/aws/infra/sqs-queue.d.mts +1 -1
- package/dist/aws/infra/sqs-queue.mjs +2 -1
- package/dist/aws/infra/stack/lambda-configs.d.mts +4 -4
- package/dist/aws/infra/stack/lambda-configs.mjs +4 -2
- package/dist/aws/infra/stack/monitoredfunction.d.mts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.mjs +23 -18
- package/dist/aws/infra/stack/parameters.mjs +1 -0
- package/dist/aws/infra/stack/rest_apis.d.mts +2 -2
- package/dist/aws/infra/stack/rest_apis.mjs +6 -1
- package/dist/aws/infra/stack/stack-checking-aspect.d.mts +2 -2
- package/dist/aws/infra/stack/stack-checking-aspect.mjs +6 -1
- package/dist/aws/infra/stack/stack.d.mts +5 -5
- package/dist/aws/infra/stack/stack.mjs +9 -0
- package/dist/aws/infra/stack/subscription.mjs +4 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.mts +1 -1
- package/dist/aws/infra/stacks/db-dns-stack.mjs +1 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.mts +3 -3
- package/dist/aws/infra/stacks/db-proxy-stack.mjs +4 -2
- package/dist/aws/infra/stacks/db-stack.d.mts +3 -3
- package/dist/aws/infra/stacks/db-stack.mjs +11 -7
- package/dist/aws/infra/stacks/intra-stack-configuration.d.mts +1 -1
- package/dist/aws/infra/stacks/network-stack.d.mts +2 -2
- package/dist/aws/infra/stacks/network-stack.mjs +8 -0
- package/dist/aws/infra/usage-plans.d.mts +1 -1
- package/dist/aws/infra/usage-plans.mjs +1 -0
- package/dist/aws/runtime/apikey.d.mts +2 -2
- package/dist/aws/runtime/apikey.mjs +2 -2
- package/dist/aws/runtime/digitraffic-integration-response.d.mts +1 -1
- package/dist/aws/runtime/dt-logger.mjs +6 -2
- package/dist/aws/runtime/messaging.d.mts +2 -2
- package/dist/aws/runtime/messaging.mjs +5 -4
- package/dist/aws/runtime/s3.d.mts +4 -2
- package/dist/aws/runtime/s3.mjs +15 -10
- package/dist/aws/runtime/secrets/dbsecret.d.mts +1 -1
- package/dist/aws/runtime/secrets/proxy-holder.mjs +1 -0
- package/dist/aws/runtime/secrets/rds-holder.mjs +1 -0
- package/dist/aws/runtime/secrets/secret-holder.d.mts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.mjs +6 -1
- package/dist/aws/runtime/secrets/secret.mjs +5 -6
- package/dist/aws/types/errors.mjs +1 -0
- package/dist/aws/types/lambda-response.mjs +5 -0
- package/dist/aws/types/model-with-reference.mjs +1 -1
- package/dist/database/cached.d.mts +1 -1
- package/dist/database/database.mjs +1 -0
- package/dist/database/last-updated.d.mts +1 -1
- package/dist/test/db-testutils.d.mts +1 -1
- package/dist/test/db-testutils.mjs +1 -1
- package/dist/test/httpserver.mjs +7 -3
- package/dist/test/mock-ky.d.mts +2 -0
- package/dist/test/mock-ky.mjs +15 -0
- package/dist/test/secrets-manager.d.mts +3 -2
- package/dist/test/secrets-manager.mjs +14 -16
- package/dist/test/testutils.mjs +1 -1
- package/dist/types/http-error.mjs +1 -0
- package/dist/types/nullable.d.mts +1 -1
- package/dist/utils/api-model.d.mts +2 -2
- package/dist/utils/api-model.mjs +1 -1
- package/dist/utils/geojson-types.d.mts +1 -1
- package/dist/utils/geojson-types.mjs +4 -2
- package/dist/utils/geometry.d.mts +1 -1
- package/dist/utils/geometry.mjs +3 -0
- package/dist/utils/logging.mjs +2 -2
- package/dist/utils/retry.d.mts +2 -2
- package/dist/utils/retry.mjs +2 -2
- package/dist/utils/slack.mjs +4 -3
- package/dist/utils/utils.d.mts +2 -2
- package/package.json +25 -15
- package/src/@types/geojson-validation/index.d.mts +0 -4
- package/src/aws/infra/api/handler-factory.mts +0 -86
- package/src/aws/infra/api/integration.mts +0 -147
- package/src/aws/infra/api/response.mts +0 -165
- package/src/aws/infra/api/responses.mts +0 -127
- package/src/aws/infra/api/static-integration.mts +0 -108
- package/src/aws/infra/canaries/Synthetics.d.mts +0 -21
- package/src/aws/infra/canaries/canary-alarm.mts +0 -33
- package/src/aws/infra/canaries/canary-keys.mts +0 -3
- package/src/aws/infra/canaries/canary-parameters.mts +0 -19
- package/src/aws/infra/canaries/canary-role.mts +0 -73
- package/src/aws/infra/canaries/canary.mts +0 -44
- package/src/aws/infra/canaries/database-canary.mts +0 -98
- package/src/aws/infra/canaries/database-checker.mts +0 -163
- package/src/aws/infra/canaries/url-canary.mts +0 -98
- package/src/aws/infra/canaries/url-checker.mts +0 -388
- package/src/aws/infra/documentation.mts +0 -142
- package/src/aws/infra/import-util.mts +0 -57
- package/src/aws/infra/scheduler.mts +0 -59
- package/src/aws/infra/security-rule.mts +0 -38
- package/src/aws/infra/sqs-integration.mts +0 -106
- package/src/aws/infra/sqs-queue.mts +0 -162
- package/src/aws/infra/stack/lambda-configs.mts +0 -135
- package/src/aws/infra/stack/monitoredfunction.mts +0 -352
- package/src/aws/infra/stack/parameters.mts +0 -74
- package/src/aws/infra/stack/rest_apis.mts +0 -322
- package/src/aws/infra/stack/stack-checking-aspect.mts +0 -233
- package/src/aws/infra/stack/stack.mts +0 -144
- package/src/aws/infra/stack/subscription.mts +0 -58
- package/src/aws/infra/stacks/db-dns-stack.mts +0 -77
- package/src/aws/infra/stacks/db-proxy-stack.mts +0 -134
- package/src/aws/infra/stacks/db-stack.mts +0 -292
- package/src/aws/infra/stacks/intra-stack-configuration.mts +0 -6
- package/src/aws/infra/stacks/network-stack.mts +0 -76
- package/src/aws/infra/usage-plans.mts +0 -50
- package/src/aws/runtime/apikey.mts +0 -9
- package/src/aws/runtime/digitraffic-integration-response.mts +0 -35
- package/src/aws/runtime/dt-logger-default.mts +0 -11
- package/src/aws/runtime/dt-logger.mts +0 -184
- package/src/aws/runtime/environment.mts +0 -22
- package/src/aws/runtime/messaging.mts +0 -26
- package/src/aws/runtime/s3.mts +0 -44
- package/src/aws/runtime/secrets/dbsecret.mts +0 -31
- package/src/aws/runtime/secrets/node-ttl.d.mts +0 -12
- package/src/aws/runtime/secrets/proxy-holder.mts +0 -34
- package/src/aws/runtime/secrets/rds-holder.mts +0 -34
- package/src/aws/runtime/secrets/secret-holder.mts +0 -106
- package/src/aws/runtime/secrets/secret.mts +0 -58
- package/src/aws/types/errors.mts +0 -14
- package/src/aws/types/lambda-response.mts +0 -100
- package/src/aws/types/mediatypes.mts +0 -12
- package/src/aws/types/model-with-reference.mts +0 -8
- package/src/aws/types/proxytypes.mts +0 -27
- package/src/aws/types/tags.mts +0 -3
- package/src/database/cached.mts +0 -64
- package/src/database/database.mts +0 -107
- package/src/database/last-updated.mts +0 -103
- package/src/database/models.mts +0 -7
- package/src/index.mts +0 -2
- package/src/marine/id_utils.mts +0 -30
- package/src/marine/rtz.mts +0 -57
- package/src/test/asserter.mts +0 -58
- package/src/test/db-testutils.mts +0 -52
- package/src/test/httpserver.mts +0 -111
- package/src/test/secrets-manager.mts +0 -37
- package/src/test/testutils.mts +0 -39
- package/src/types/async-timeout-error.mts +0 -5
- package/src/types/aws-env.mts +0 -3
- package/src/types/either.mts +0 -9
- package/src/types/http-error.mts +0 -8
- package/src/types/input-error.mts +0 -2
- package/src/types/language.mts +0 -3
- package/src/types/nullable.mts +0 -21
- package/src/types/traffictype.mts +0 -8
- package/src/types/urn.mts +0 -1
- package/src/types/util-types.mts +0 -10
- package/src/types/validator.mts +0 -10
- package/src/utils/api-model.mts +0 -133
- package/src/utils/base64.mts +0 -16
- package/src/utils/date-utils.mts +0 -53
- package/src/utils/geojson-types.mts +0 -22
- package/src/utils/geometry.mts +0 -171
- package/src/utils/logging.mts +0 -75
- package/src/utils/retry.mts +0 -200
- package/src/utils/slack.mts +0 -26
- 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,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,2 +1,2 @@
|
|
1
|
-
import {
|
2
|
-
export declare function getApiKeyFromAPIGateway(keyId: string): Promise<
|
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
|
-
})
|
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
|
20
|
-
this.runtime = config?.runTime ?? process.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:
|
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)
|
16
|
+
await sns.publish(publishParams);
|
16
17
|
}
|
17
18
|
catch (error) {
|
18
|
-
console.error(
|
19
|
+
console.error("method=snsPublish error, retrying", error);
|
19
20
|
try {
|
20
|
-
await sns.publish(publishParams)
|
21
|
+
await sns.publish(publishParams);
|
21
22
|
}
|
22
23
|
catch (e2) {
|
23
|
-
console.error(
|
24
|
+
console.error("method=snsPublish error after retry", e2);
|
24
25
|
}
|
25
26
|
}
|
26
27
|
}
|
@@ -1,2 +1,4 @@
|
|
1
|
-
|
2
|
-
|
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>;
|
package/dist/aws/runtime/s3.mjs
CHANGED
@@ -1,26 +1,31 @@
|
|
1
|
-
import {
|
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(
|
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(
|
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
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
@@ -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
|
}
|
@@ -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
|
-
|
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
|
-
|
34
|
+
const withoutPrefix = key.substring(skip);
|
35
|
+
parsed[withoutPrefix] = secret[key];
|
37
36
|
}
|
38
37
|
}
|
39
38
|
return parsed;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
import { Model } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
//# sourceMappingURL=model-with-reference.mjs.map
|
@@ -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
|
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, {
|
package/dist/test/httpserver.mjs
CHANGED
@@ -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
|
-
|
51
|
+
const invokable = props[path];
|
52
|
+
res.end(invokable(req.url, dataStr));
|
49
53
|
});
|
50
54
|
}
|
51
55
|
else {
|
@@ -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
|
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.
|
9
|
+
export declare function stubSecretsManager(): sinon.SinonStubbedInstance<SecretsManager>;
|
9
10
|
export declare function mockSecret<Secret>(secret: Secret): void;
|
@@ -1,9 +1,12 @@
|
|
1
|
-
import
|
2
|
-
import
|
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
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
promise: sinon.stub().returns({}),
|
24
|
-
});
|
26
|
+
SecretsManagerStubInstance.getSecretValue.resolves({ ...emptySecret });
|
25
27
|
}
|
26
28
|
else {
|
27
|
-
|
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
|
package/dist/test/testutils.mjs
CHANGED
@@ -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((
|
30
|
+
newArray.sort((_) => 0.5 - Math.random());
|
31
31
|
return newArray;
|
32
32
|
}
|
33
33
|
//# sourceMappingURL=testutils.mjs.map
|
@@ -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.
|
package/dist/utils/api-model.mjs
CHANGED
@@ -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.
|