@digitraffic/common 2023.5.22-1 → 2023.5.31-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/aws/infra/api/response.d.ts +1 -1
- package/dist/aws/infra/api/response.js +3 -1
- package/dist/aws/infra/stacks/db-stack.d.ts +5 -0
- package/dist/aws/infra/stacks/db-stack.js +8 -1
- package/dist/aws/types/lambda-response.d.ts +1 -0
- package/dist/aws/types/lambda-response.js +5 -0
- package/package.json +9 -8
- package/src/aws/infra/api/response.ts +3 -1
- package/src/aws/infra/stacks/db-stack.ts +15 -1
- package/src/aws/types/lambda-response.ts +4 -0
- package/src/utils/date-utils.ts +1 -1
@@ -12,7 +12,7 @@ import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
|
12
12
|
* If fileName is set, then Content-Disposition-header will be set to use it
|
13
13
|
* If timestamp is set, then ETag & Last-Modified headers will be set
|
14
14
|
*/
|
15
|
-
export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$'))\n#if ($inputRoot.status != 200)\n#set ($context.responseOverride.status = $inputRoot.status)\n#set ($context.responseOverride.header.Content-Type = 'text/plain')\n#end\n#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')\n#if (\"$!inputRoot.timestamp\" != \"\")\n#set ($context.responseOverride.header.
|
15
|
+
export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$'))\n#if ($inputRoot.status != 200)\n#set ($context.responseOverride.status = $inputRoot.status)\n#set ($context.responseOverride.header.Content-Type = 'text/plain')\n#end\n#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')\n#if (\"$!inputRoot.timestamp\" != \"\")\n#set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)\n#end\n#if (\"$!inputRoot.etag\" != \"\")\n#set ($context.responseOverride.header.ETag = $inputRoot.etag)\n#end\n#if (\"$!inputRoot.fileName\" != \"\")\n#set ($disposition = 'attachment; filename=\"FN\"')\n#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))\n#end\n$util.base64Decode($inputRoot.body)";
|
16
16
|
/**
|
17
17
|
* Use this for deprecated integrations.
|
18
18
|
* Will add HTTP headers Deprecation and Sunset to response.
|
@@ -22,9 +22,11 @@ exports.RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))
|
|
22
22
|
#end
|
23
23
|
#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')
|
24
24
|
#if ("$!inputRoot.timestamp" != "")
|
25
|
-
#set ($context.responseOverride.header.ETag = $inputRoot.timestamp)
|
26
25
|
#set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)
|
27
26
|
#end
|
27
|
+
#if ("$!inputRoot.etag" != "")
|
28
|
+
#set ($context.responseOverride.header.ETag = $inputRoot.etag)
|
29
|
+
#end
|
28
30
|
#if ("$!inputRoot.fileName" != "")
|
29
31
|
#set ($disposition = 'attachment; filename="FN"')
|
30
32
|
#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
|
@@ -5,6 +5,9 @@ import { AuroraPostgresEngineVersion, DatabaseCluster, DatabaseClusterProps, IPa
|
|
5
5
|
import { Construct } from "constructs";
|
6
6
|
import { InfraStackConfiguration } from "./intra-stack-configuration";
|
7
7
|
export interface DbConfiguration {
|
8
|
+
/** superuser username and password are fetched from this secret, using keys
|
9
|
+
* db.superuser and db.superuser.password
|
10
|
+
*/
|
8
11
|
readonly secretArn: string;
|
9
12
|
readonly dbVersion: AuroraPostgresEngineVersion;
|
10
13
|
readonly dbInstanceType: InstanceType;
|
@@ -12,6 +15,8 @@ export interface DbConfiguration {
|
|
12
15
|
readonly instances: number;
|
13
16
|
readonly customParameterGroup: boolean;
|
14
17
|
readonly securityGroupId: string;
|
18
|
+
/** If this is not specified, import default vpc */
|
19
|
+
readonly vpcId?: string;
|
15
20
|
readonly proxy: {
|
16
21
|
readonly name?: string;
|
17
22
|
readonly securityGroupId: string;
|
@@ -75,13 +75,20 @@ class DbStack extends aws_cdk_lib_1.Stack {
|
|
75
75
|
},
|
76
76
|
credentials: aws_rds_1.Credentials.fromPassword(secret.secretValueFromJson("db.superuser").unsafeUnwrap(), secret.secretValueFromJson("db.superuser.password")),
|
77
77
|
parameterGroup,
|
78
|
+
storageEncrypted: true,
|
79
|
+
monitoringInterval: aws_cdk_lib_1.Duration.seconds(30),
|
78
80
|
};
|
79
81
|
}
|
80
82
|
createAuroraCluster(isc, configuration) {
|
81
83
|
const instanceName = isc.environmentName + "-db";
|
82
84
|
const securityGroup = aws_ec2_1.SecurityGroup.fromSecurityGroupId(this, "securitygroup", configuration.securityGroupId);
|
83
85
|
const parameterGroup = this.createParamaterGroup(configuration);
|
84
|
-
const
|
86
|
+
const vpc = configuration.vpcId
|
87
|
+
? aws_ec2_1.Vpc.fromLookup(this, "vpc", {
|
88
|
+
vpcId: configuration.vpcId,
|
89
|
+
})
|
90
|
+
: (0, import_util_1.importVpc)(this, isc.environmentName);
|
91
|
+
const parameters = this.createClusterParameters(configuration, instanceName, vpc, securityGroup, parameterGroup);
|
85
92
|
// create cluster from the snapshot or from the scratch
|
86
93
|
const cluster = configuration.snapshotIdentifier
|
87
94
|
? new aws_rds_1.DatabaseClusterFromSnapshot(this, instanceName, {
|
@@ -3,6 +3,7 @@ export declare class LambdaResponse {
|
|
3
3
|
readonly body: string;
|
4
4
|
readonly fileName?: string;
|
5
5
|
readonly timestamp?: string;
|
6
|
+
readonly etag: string;
|
6
7
|
constructor(status: number, body: string, fileName?: string, timestamp?: Date);
|
7
8
|
withTimestamp(timestamp: Date): LambdaResponse;
|
8
9
|
/**
|
@@ -1,12 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.LambdaResponse = void 0;
|
7
|
+
const etag_1 = __importDefault(require("etag"));
|
4
8
|
class LambdaResponse {
|
5
9
|
constructor(status, body, fileName, timestamp) {
|
6
10
|
this.status = status;
|
7
11
|
this.body = body;
|
8
12
|
this.fileName = fileName;
|
9
13
|
this.timestamp = timestamp?.toUTCString();
|
14
|
+
this.etag = (0, etag_1.default)(body); // create strong etag by default
|
10
15
|
}
|
11
16
|
withTimestamp(timestamp) {
|
12
17
|
return new LambdaResponse(this.status, this.body, this.fileName, timestamp);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2023.5.
|
3
|
+
"version": "2023.5.31-1",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -24,6 +24,7 @@
|
|
24
24
|
"axios": "^1.2.6",
|
25
25
|
"change-case": "^4.1.2",
|
26
26
|
"constructs": "^10.2.17",
|
27
|
+
"etag": "^1.8.1",
|
27
28
|
"geojson-validation": "^1.0.2",
|
28
29
|
"moment": "^2.29.4",
|
29
30
|
"node-ttl": "^0.2.0",
|
@@ -34,11 +35,12 @@
|
|
34
35
|
"@aws-cdk/aws-synthetics-alpha": "2.78.0-alpha.0",
|
35
36
|
"@types/aws-lambda": "~8.10.115",
|
36
37
|
"@types/geojson": "^7946.0.10",
|
38
|
+
"@types/etag": "^1.8.1",
|
37
39
|
"@types/jest": "^29.5.1",
|
38
|
-
"@types/lodash": "^4.14.
|
40
|
+
"@types/lodash": "^4.14.195",
|
39
41
|
"@types/node": "18.15.13",
|
40
42
|
"@types/ramda": "~0.29.1",
|
41
|
-
"@types/sinon": "10.0.
|
43
|
+
"@types/sinon": "10.0.15",
|
42
44
|
"@typescript-eslint/eslint-plugin": "~5.59.5",
|
43
45
|
"@typescript-eslint/parser": "^5.59.5",
|
44
46
|
"aws-cdk-lib": "~2.78.0",
|
@@ -49,19 +51,21 @@
|
|
49
51
|
"eslint": "~8.40.0",
|
50
52
|
"eslint-config-prettier": "^8.8.0",
|
51
53
|
"eslint-plugin-deprecation": "~1.4.1",
|
54
|
+
"etag": "^1.8.1",
|
52
55
|
"geojson-validation": "^1.0.2",
|
53
56
|
"husky": "^8.0.3",
|
54
57
|
"jest": "^29.5.0",
|
55
58
|
"jest-junit": "^16.0.0",
|
56
59
|
"lint-staged": "^13.2.2",
|
60
|
+
"lodash": "^4.17.21",
|
57
61
|
"moment": "^2.29.4",
|
58
62
|
"node-ttl": "^0.2.0",
|
59
63
|
"pg-native": "^3.0.1",
|
60
64
|
"pg-promise": "^11.4.3",
|
61
65
|
"prettier": "^2.8.8",
|
62
66
|
"ramda": "~0.29.0",
|
63
|
-
"rimraf": "^5.0.
|
64
|
-
"sinon": "15.0
|
67
|
+
"rimraf": "^5.0.1",
|
68
|
+
"sinon": "15.1.0",
|
65
69
|
"ts-jest": "^29.1.0",
|
66
70
|
"typescript": "~4.9.5",
|
67
71
|
"velocityjs": "2.0.6"
|
@@ -73,9 +77,6 @@
|
|
73
77
|
"lint-staged": {
|
74
78
|
"*.{js,ts,css,md,yml,yaml,json}": "prettier --write"
|
75
79
|
},
|
76
|
-
"dependencies": {
|
77
|
-
"lodash": "^4.17.21"
|
78
|
-
},
|
79
80
|
"scripts": {
|
80
81
|
"build": "tsc",
|
81
82
|
"lint": "eslint --cache .",
|
@@ -27,9 +27,11 @@ export const RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))
|
|
27
27
|
#end
|
28
28
|
#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')
|
29
29
|
#if ("$!inputRoot.timestamp" != "")
|
30
|
-
#set ($context.responseOverride.header.ETag = $inputRoot.timestamp)
|
31
30
|
#set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)
|
32
31
|
#end
|
32
|
+
#if ("$!inputRoot.etag" != "")
|
33
|
+
#set ($context.responseOverride.header.ETag = $inputRoot.etag)
|
34
|
+
#end
|
33
35
|
#if ("$!inputRoot.fileName" != "")
|
34
36
|
#set ($disposition = 'attachment; filename="FN"')
|
35
37
|
#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
|
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
IVpc,
|
5
5
|
SecurityGroup,
|
6
6
|
SubnetType,
|
7
|
+
Vpc,
|
7
8
|
} from "aws-cdk-lib/aws-ec2";
|
8
9
|
import { ISecurityGroup } from "aws-cdk-lib/aws-ec2/lib/security-group";
|
9
10
|
import {
|
@@ -24,6 +25,9 @@ import { InfraStackConfiguration } from "./intra-stack-configuration";
|
|
24
25
|
import { exportValue, importVpc } from "../import-util";
|
25
26
|
|
26
27
|
export interface DbConfiguration {
|
28
|
+
/** superuser username and password are fetched from this secret, using keys
|
29
|
+
* db.superuser and db.superuser.password
|
30
|
+
*/
|
27
31
|
readonly secretArn: string;
|
28
32
|
|
29
33
|
readonly dbVersion: AuroraPostgresEngineVersion;
|
@@ -32,6 +36,8 @@ export interface DbConfiguration {
|
|
32
36
|
readonly instances: number;
|
33
37
|
readonly customParameterGroup: boolean;
|
34
38
|
readonly securityGroupId: string;
|
39
|
+
/** If this is not specified, import default vpc */
|
40
|
+
readonly vpcId?: string;
|
35
41
|
|
36
42
|
readonly proxy: {
|
37
43
|
readonly name?: string;
|
@@ -163,6 +169,8 @@ export class DbStack extends Stack {
|
|
163
169
|
secret.secretValueFromJson("db.superuser.password")
|
164
170
|
),
|
165
171
|
parameterGroup,
|
172
|
+
storageEncrypted: true,
|
173
|
+
monitoringInterval: Duration.seconds(30),
|
166
174
|
};
|
167
175
|
}
|
168
176
|
|
@@ -177,10 +185,16 @@ export class DbStack extends Stack {
|
|
177
185
|
configuration.securityGroupId
|
178
186
|
);
|
179
187
|
const parameterGroup = this.createParamaterGroup(configuration);
|
188
|
+
const vpc = configuration.vpcId
|
189
|
+
? Vpc.fromLookup(this, "vpc", {
|
190
|
+
vpcId: configuration.vpcId,
|
191
|
+
})
|
192
|
+
: importVpc(this, isc.environmentName);
|
193
|
+
|
180
194
|
const parameters = this.createClusterParameters(
|
181
195
|
configuration,
|
182
196
|
instanceName,
|
183
|
-
|
197
|
+
vpc,
|
184
198
|
securityGroup,
|
185
199
|
parameterGroup
|
186
200
|
);
|
@@ -1,8 +1,11 @@
|
|
1
|
+
import etag from "etag";
|
2
|
+
|
1
3
|
export class LambdaResponse {
|
2
4
|
readonly status: number;
|
3
5
|
readonly body: string;
|
4
6
|
readonly fileName?: string;
|
5
7
|
readonly timestamp?: string;
|
8
|
+
readonly etag: string;
|
6
9
|
|
7
10
|
constructor(
|
8
11
|
status: number,
|
@@ -14,6 +17,7 @@ export class LambdaResponse {
|
|
14
17
|
this.body = body;
|
15
18
|
this.fileName = fileName;
|
16
19
|
this.timestamp = timestamp?.toUTCString();
|
20
|
+
this.etag = etag(body); // create strong etag by default
|
17
21
|
}
|
18
22
|
|
19
23
|
withTimestamp(timestamp: Date) {
|