@digitraffic/common 2022.11.23-test → 2022.11.24-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/integration.d.ts +1 -1
- package/dist/aws/infra/api/integration.js +8 -4
- package/dist/aws/infra/api/response.d.ts +9 -3
- package/dist/aws/infra/api/response.js +49 -18
- package/dist/aws/infra/api/responses.d.ts +8 -0
- package/dist/aws/infra/api/responses.js +8 -0
- package/dist/aws/infra/api/static-integration.js +12 -6
- package/package.json +14 -14
- package/src/aws/infra/api/integration.ts +30 -14
- package/src/aws/infra/api/response.ts +107 -26
- package/src/aws/infra/api/responses.ts +8 -0
- package/src/aws/infra/api/static-integration.ts +48 -14
- package/src/database/database.ts +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
import { IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { IFunction } from "aws-cdk-lib/aws-lambda";
|
3
3
|
import { MediaType } from "../../types/mediatypes";
|
4
|
-
type ParameterType =
|
4
|
+
type ParameterType = "path" | "querystring";
|
5
5
|
interface ApiParameter {
|
6
6
|
type: ParameterType;
|
7
7
|
name: string;
|
@@ -11,11 +11,11 @@ class DigitrafficIntegration {
|
|
11
11
|
this.mediaType = mediaType;
|
12
12
|
}
|
13
13
|
addPathParameter(...names) {
|
14
|
-
names.forEach(name => this.parameters.push({ type:
|
14
|
+
names.forEach((name) => this.parameters.push({ type: "path", name }));
|
15
15
|
return this;
|
16
16
|
}
|
17
17
|
addQueryParameter(...names) {
|
18
|
-
names.forEach(name => this.parameters.push({ type:
|
18
|
+
names.forEach((name) => this.parameters.push({ type: "querystring", name }));
|
19
19
|
return this;
|
20
20
|
}
|
21
21
|
build() {
|
@@ -23,8 +23,12 @@ class DigitrafficIntegration {
|
|
23
23
|
return new aws_apigateway_1.LambdaIntegration(this.lambda, {
|
24
24
|
proxy: false,
|
25
25
|
integrationResponses,
|
26
|
-
requestParameters: this.parameters.length == 0
|
27
|
-
|
26
|
+
requestParameters: this.parameters.length == 0
|
27
|
+
? undefined
|
28
|
+
: this.createRequestParameters(),
|
29
|
+
requestTemplates: this.parameters.length == 0
|
30
|
+
? undefined
|
31
|
+
: this.createRequestTemplates(),
|
28
32
|
passthroughBehavior: aws_apigateway_1.PassthroughBehavior.WHEN_NO_MATCH,
|
29
33
|
});
|
30
34
|
}
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import apigateway = require('aws-cdk-lib/aws-apigateway');
|
2
1
|
import { MediaType } from "../../types/mediatypes";
|
2
|
+
import { JsonSchema, MethodResponse } from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
3
4
|
/**
|
4
5
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
5
6
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -11,12 +12,17 @@ export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$
|
|
11
12
|
export declare const MessageModel: {
|
12
13
|
contentType: MediaType;
|
13
14
|
modelName: string;
|
14
|
-
schema:
|
15
|
+
schema: JsonSchema;
|
15
16
|
};
|
16
17
|
export declare const NotFoundResponse: string;
|
17
18
|
export declare const BadRequestResponseTemplate: Record<string, string>;
|
18
19
|
export declare const NotFoundResponseTemplate: Record<string, string>;
|
19
20
|
export declare const XmlResponseTemplate: Record<string, string>;
|
20
|
-
export declare const SvgResponseTemplate: Record<string, string>;
|
21
21
|
export declare const InternalServerErrorResponseTemplate: Record<string, string>;
|
22
22
|
export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
|
23
|
+
export declare class DigitrafficMethodResponse {
|
24
|
+
static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
|
25
|
+
static response200(model: IModel, mediaType?: MediaType): MethodResponse;
|
26
|
+
static response500(model?: IModel, mediaType?: MediaType): MethodResponse;
|
27
|
+
static response400(model?: IModel, mediaType?: MediaType): MethodResponse;
|
28
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
const apigateway = require("aws-cdk-lib/aws-apigateway");
|
3
|
+
exports.DigitrafficMethodResponse = exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
|
5
4
|
const mediatypes_1 = require("../../types/mediatypes");
|
5
|
+
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
6
|
/**
|
7
7
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
8
8
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -23,39 +23,70 @@ $inputRoot.body
|
|
23
23
|
#end
|
24
24
|
`;
|
25
25
|
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
26
|
-
|
26
|
+
/// @deprecated
|
27
27
|
const messageSchema = {
|
28
|
-
schema:
|
29
|
-
type:
|
30
|
-
description:
|
28
|
+
schema: aws_apigateway_1.JsonSchemaVersion.DRAFT4,
|
29
|
+
type: aws_apigateway_1.JsonSchemaType.OBJECT,
|
30
|
+
description: "Response with message",
|
31
31
|
properties: {
|
32
32
|
message: {
|
33
|
-
type:
|
34
|
-
description:
|
33
|
+
type: aws_apigateway_1.JsonSchemaType.STRING,
|
34
|
+
description: "Response message",
|
35
35
|
},
|
36
36
|
},
|
37
37
|
};
|
38
|
-
|
38
|
+
/// @deprecated
|
39
39
|
exports.MessageModel = {
|
40
40
|
contentType: mediatypes_1.MediaType.APPLICATION_JSON,
|
41
|
-
modelName:
|
41
|
+
modelName: "MessageResponseModel",
|
42
42
|
schema: messageSchema,
|
43
43
|
};
|
44
|
-
const NotFoundMessage =
|
44
|
+
const NotFoundMessage = "Not found";
|
45
45
|
exports.NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
|
46
|
-
const InternalServerErrorMessage =
|
47
|
-
const InternalServerErrorResponse = JSON.stringify({
|
48
|
-
|
46
|
+
const InternalServerErrorMessage = "Error";
|
47
|
+
const InternalServerErrorResponse = JSON.stringify({
|
48
|
+
message: InternalServerErrorMessage,
|
49
|
+
});
|
50
|
+
const BadRequestMessage = "Bad request";
|
49
51
|
const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
|
52
|
+
/// @deprecated
|
50
53
|
exports.BadRequestResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, BadRequestResponse);
|
54
|
+
/// @deprecated
|
51
55
|
exports.NotFoundResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, exports.NotFoundResponse);
|
56
|
+
/// @deprecated
|
52
57
|
exports.XmlResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_XML, BODY_FROM_INPUT_PATH);
|
53
|
-
|
58
|
+
/// @deprecated
|
54
59
|
exports.InternalServerErrorResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, InternalServerErrorResponse);
|
60
|
+
/// @deprecated
|
55
61
|
function createResponses(key, value) {
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
return {
|
63
|
+
[key]: value,
|
64
|
+
};
|
59
65
|
}
|
60
66
|
exports.createResponses = createResponses;
|
67
|
+
class DigitrafficMethodResponse {
|
68
|
+
static response(statusCode, model, mediaType, disableCors = false) {
|
69
|
+
return {
|
70
|
+
statusCode,
|
71
|
+
responseModels: {
|
72
|
+
[mediaType]: model,
|
73
|
+
},
|
74
|
+
responseParameters: disableCors
|
75
|
+
? {}
|
76
|
+
: {
|
77
|
+
"method.response.header.Access-Control-Allow-Origin": true,
|
78
|
+
},
|
79
|
+
};
|
80
|
+
}
|
81
|
+
static response200(model, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
82
|
+
return DigitrafficMethodResponse.response("200", model, mediaType, false);
|
83
|
+
}
|
84
|
+
static response500(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
85
|
+
return DigitrafficMethodResponse.response("500", model, mediaType, false);
|
86
|
+
}
|
87
|
+
static response400(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
88
|
+
return DigitrafficMethodResponse.response("400", model, mediaType, false);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
exports.DigitrafficMethodResponse = DigitrafficMethodResponse;
|
61
92
|
//# sourceMappingURL=response.js.map
|
@@ -15,7 +15,13 @@ export declare const RESPONSE_404_NOT_FOUND: {
|
|
15
15
|
selectionPattern: string;
|
16
16
|
responseTemplates: Record<string, string>;
|
17
17
|
};
|
18
|
+
/**
|
19
|
+
* @deprecated Use DigitrafficMethodResponse
|
20
|
+
*/
|
18
21
|
export declare function methodResponse(status: string, contentType: MediaType, model: IModel, parameters?: Record<string, boolean>): MethodResponse;
|
22
|
+
/**
|
23
|
+
* @deprecated Use DigitrafficMethodResponse
|
24
|
+
*/
|
19
25
|
export declare function corsMethod(response: MethodResponse): MethodResponse;
|
20
26
|
interface IntegrationOptions {
|
21
27
|
requestParameters?: {
|
@@ -33,6 +39,8 @@ interface IntegrationOptions {
|
|
33
39
|
* Creates a default Lambda integration for a REST API resource _root_
|
34
40
|
* @param lambdaFunction The Lambda function
|
35
41
|
* @param options Options
|
42
|
+
*
|
43
|
+
* @deprecated Use DigitrafficIntegration
|
36
44
|
*/
|
37
45
|
export declare function defaultIntegration(lambdaFunction: AWSFunction, options?: IntegrationOptions): LambdaIntegration;
|
38
46
|
export declare function getResponse(response: IntegrationResponse, options?: IntegrationOptions): IntegrationResponse;
|
@@ -30,6 +30,9 @@ exports.RESPONSE_404_NOT_FOUND = {
|
|
30
30
|
selectionPattern: errors_1.NOT_FOUND_MESSAGE,
|
31
31
|
responseTemplates: response_1.NotFoundResponseTemplate,
|
32
32
|
};
|
33
|
+
/**
|
34
|
+
* @deprecated Use DigitrafficMethodResponse
|
35
|
+
*/
|
33
36
|
function methodResponse(status, contentType, model, parameters) {
|
34
37
|
return {
|
35
38
|
statusCode: status,
|
@@ -38,6 +41,9 @@ function methodResponse(status, contentType, model, parameters) {
|
|
38
41
|
};
|
39
42
|
}
|
40
43
|
exports.methodResponse = methodResponse;
|
44
|
+
/**
|
45
|
+
* @deprecated Use DigitrafficMethodResponse
|
46
|
+
*/
|
41
47
|
function corsMethod(response) {
|
42
48
|
return {
|
43
49
|
...response,
|
@@ -53,6 +59,8 @@ exports.corsMethod = corsMethod;
|
|
53
59
|
* Creates a default Lambda integration for a REST API resource _root_
|
54
60
|
* @param lambdaFunction The Lambda function
|
55
61
|
* @param options Options
|
62
|
+
*
|
63
|
+
* @deprecated Use DigitrafficIntegration
|
56
64
|
*/
|
57
65
|
function defaultIntegration(lambdaFunction, options) {
|
58
66
|
return new aws_apigateway_1.LambdaIntegration(lambdaFunction, {
|
@@ -8,7 +8,7 @@ const INTEGRATION_RESPONSE_200 = `{
|
|
8
8
|
"statusCode": 200
|
9
9
|
}`;
|
10
10
|
const METHOD_RESPONSE_200 = {
|
11
|
-
statusCode:
|
11
|
+
statusCode: "200",
|
12
12
|
};
|
13
13
|
/**
|
14
14
|
* Static integration, that returns the given response with given mediaType from given resource.
|
@@ -27,10 +27,12 @@ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
|
|
27
27
|
},
|
28
28
|
integrationResponses: [integrationResponse],
|
29
29
|
});
|
30
|
-
[
|
30
|
+
["GET", "HEAD"].forEach((httpMethod) => {
|
31
31
|
resource.addMethod(httpMethod, this, {
|
32
32
|
apiKeyRequired,
|
33
|
-
methodResponses: [
|
33
|
+
methodResponses: [
|
34
|
+
DigitrafficStaticIntegration.createMethodResponse(enableCors),
|
35
|
+
],
|
34
36
|
});
|
35
37
|
});
|
36
38
|
}
|
@@ -39,15 +41,19 @@ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
|
|
39
41
|
}
|
40
42
|
static createIntegrationResponse(response, mediaType, enableCors) {
|
41
43
|
const integrationResponse = {
|
42
|
-
statusCode:
|
44
|
+
statusCode: "200",
|
43
45
|
responseTemplates: {
|
44
46
|
[mediaType]: response,
|
45
47
|
},
|
46
48
|
};
|
47
|
-
return enableCors
|
49
|
+
return enableCors
|
50
|
+
? { ...integrationResponse, ...responses_1.RESPONSE_CORS_INTEGRATION }
|
51
|
+
: integrationResponse;
|
48
52
|
}
|
49
53
|
static createMethodResponse(enableCors) {
|
50
|
-
return enableCors
|
54
|
+
return enableCors
|
55
|
+
? (0, responses_1.corsMethod)(METHOD_RESPONSE_200)
|
56
|
+
: METHOD_RESPONSE_200;
|
51
57
|
}
|
52
58
|
}
|
53
59
|
exports.DigitrafficStaticIntegration = DigitrafficStaticIntegration;
|
package/package.json
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2022.11.
|
3
|
+
"version": "2022.11.24-1",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "https://github.com/tmfg/digitraffic-common.git"
|
8
8
|
},
|
9
9
|
"engines": {
|
10
|
-
"node": ">=14 <17"
|
11
|
-
"yarn": ">1.2 <2"
|
10
|
+
"node": ">=14 <17"
|
12
11
|
},
|
13
12
|
"license": "EUPL-1.2",
|
14
13
|
"private": false,
|
@@ -21,12 +20,12 @@
|
|
21
20
|
"pg-promise": "^10.12.0",
|
22
21
|
"spex": "^3.0.0",
|
23
22
|
"constructs": "^10.1.131",
|
24
|
-
"@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
|
23
|
+
"@aws-cdk/aws-synthetics-alpha": "^2.50.0-alpha.0",
|
25
24
|
"@types/geojson": "^7946.0.10",
|
26
|
-
"aws-cdk-lib": "2.
|
27
|
-
"aws-sdk": "2.1241.0",
|
28
|
-
"axios": "^
|
29
|
-
"change-case": "4.1.2",
|
25
|
+
"aws-cdk-lib": "^2.51.1",
|
26
|
+
"aws-sdk": "^2.1241.0",
|
27
|
+
"axios": "^1.2.0",
|
28
|
+
"change-case": "^4.1.2",
|
30
29
|
"geojson-validation": "^1.0.2",
|
31
30
|
"moment": "^2.29.4",
|
32
31
|
"node-ttl": "^0.2.0",
|
@@ -35,11 +34,11 @@
|
|
35
34
|
"devDependencies": {
|
36
35
|
"@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
|
37
36
|
"@types/geojson": "^7946.0.10",
|
38
|
-
"aws-cdk-lib": "2.50.0",
|
39
|
-
"aws-sdk": "2.1241.0",
|
37
|
+
"aws-cdk-lib": "^2.50.0",
|
38
|
+
"aws-sdk": "^2.1241.0",
|
40
39
|
"axios": "^0.21.1",
|
41
|
-
"change-case": "4.1.2",
|
42
|
-
"constructs": "10.1.131",
|
40
|
+
"change-case": "^4.1.2",
|
41
|
+
"constructs": "^10.1.131",
|
43
42
|
"geojson-validation": "^1.0.2",
|
44
43
|
"moment": "^2.29.4",
|
45
44
|
"node-ttl": "^0.2.0",
|
@@ -54,6 +53,7 @@
|
|
54
53
|
"@typescript-eslint/parser": "^5.39.0",
|
55
54
|
"eslint": "^8.24.0",
|
56
55
|
"eslint-config-prettier": "^8.5.0",
|
56
|
+
"eslint-plugin-deprecation": "1.3.3",
|
57
57
|
"husky": ">=6",
|
58
58
|
"jest": "^29.1.1",
|
59
59
|
"jest-junit": "^14.0.1",
|
@@ -62,8 +62,8 @@
|
|
62
62
|
"ramda": "^0.28.0",
|
63
63
|
"rimraf": "^3.0.2",
|
64
64
|
"sinon": "^14.0.0",
|
65
|
-
"
|
66
|
-
"
|
65
|
+
"typescript": "^4.7.4",
|
66
|
+
"ts-jest": "^29.0.3"
|
67
67
|
},
|
68
68
|
"externals": [
|
69
69
|
"aws-sdk",
|
@@ -1,13 +1,17 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import {
|
2
|
+
IntegrationResponse,
|
3
|
+
LambdaIntegration,
|
4
|
+
PassthroughBehavior,
|
5
|
+
} from "aws-cdk-lib/aws-apigateway";
|
6
|
+
import { IFunction } from "aws-cdk-lib/aws-lambda";
|
7
|
+
import { MediaType } from "../../types/mediatypes";
|
8
|
+
import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response";
|
5
9
|
|
6
|
-
type ParameterType =
|
10
|
+
type ParameterType = "path" | "querystring";
|
7
11
|
|
8
12
|
interface ApiParameter {
|
9
|
-
type: ParameterType
|
10
|
-
name: string
|
13
|
+
type: ParameterType;
|
14
|
+
name: string;
|
11
15
|
}
|
12
16
|
|
13
17
|
export class DigitrafficIntegration {
|
@@ -22,13 +26,15 @@ export class DigitrafficIntegration {
|
|
22
26
|
}
|
23
27
|
|
24
28
|
addPathParameter(...names: string[]): DigitrafficIntegration {
|
25
|
-
names.forEach(name => this.parameters.push({type:
|
29
|
+
names.forEach((name) => this.parameters.push({ type: "path", name }));
|
26
30
|
|
27
31
|
return this;
|
28
32
|
}
|
29
33
|
|
30
34
|
addQueryParameter(...names: string[]): DigitrafficIntegration {
|
31
|
-
names.forEach(name =>
|
35
|
+
names.forEach((name) =>
|
36
|
+
this.parameters.push({ type: "querystring", name })
|
37
|
+
);
|
32
38
|
|
33
39
|
return this;
|
34
40
|
}
|
@@ -39,8 +45,14 @@ export class DigitrafficIntegration {
|
|
39
45
|
return new LambdaIntegration(this.lambda, {
|
40
46
|
proxy: false,
|
41
47
|
integrationResponses,
|
42
|
-
requestParameters:
|
43
|
-
|
48
|
+
requestParameters:
|
49
|
+
this.parameters.length == 0
|
50
|
+
? undefined
|
51
|
+
: this.createRequestParameters(),
|
52
|
+
requestTemplates:
|
53
|
+
this.parameters.length == 0
|
54
|
+
? undefined
|
55
|
+
: this.createRequestTemplates(),
|
44
56
|
passthroughBehavior: PassthroughBehavior.WHEN_NO_MATCH,
|
45
57
|
});
|
46
58
|
}
|
@@ -49,7 +61,9 @@ export class DigitrafficIntegration {
|
|
49
61
|
const requestParameters: Record<string, string> = {};
|
50
62
|
|
51
63
|
this.parameters.forEach((parameter: ApiParameter) => {
|
52
|
-
requestParameters[
|
64
|
+
requestParameters[
|
65
|
+
`integration.request.${parameter.type}.${parameter.name}`
|
66
|
+
] = `method.request.${parameter.type}.${parameter.name}`;
|
53
67
|
});
|
54
68
|
|
55
69
|
return requestParameters;
|
@@ -59,7 +73,9 @@ export class DigitrafficIntegration {
|
|
59
73
|
const requestJson: Record<string, string> = {};
|
60
74
|
|
61
75
|
this.parameters.forEach((parameter: ApiParameter) => {
|
62
|
-
requestJson[
|
76
|
+
requestJson[
|
77
|
+
parameter.name
|
78
|
+
] = `$util.escapeJavaScript($input.params('${parameter.name}'))`;
|
63
79
|
});
|
64
80
|
|
65
81
|
return {
|
@@ -70,4 +86,4 @@ export class DigitrafficIntegration {
|
|
70
86
|
createResponses(): IntegrationResponse[] {
|
71
87
|
return [DigitrafficIntegrationResponse.ok(this.mediaType)];
|
72
88
|
}
|
73
|
-
}
|
89
|
+
}
|
@@ -1,5 +1,12 @@
|
|
1
|
-
import
|
2
|
-
import {
|
1
|
+
import { MediaType } from "../../types/mediatypes";
|
2
|
+
import {
|
3
|
+
JsonSchemaType,
|
4
|
+
JsonSchemaVersion,
|
5
|
+
JsonSchema,
|
6
|
+
MethodResponse,
|
7
|
+
Model,
|
8
|
+
} from "aws-cdk-lib/aws-apigateway";
|
9
|
+
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
3
10
|
|
4
11
|
/**
|
5
12
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
@@ -23,45 +30,119 @@ $inputRoot.body
|
|
23
30
|
|
24
31
|
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
25
32
|
|
26
|
-
|
27
|
-
const messageSchema:
|
28
|
-
schema:
|
29
|
-
type:
|
30
|
-
description:
|
33
|
+
/// @deprecated
|
34
|
+
const messageSchema: JsonSchema = {
|
35
|
+
schema: JsonSchemaVersion.DRAFT4,
|
36
|
+
type: JsonSchemaType.OBJECT,
|
37
|
+
description: "Response with message",
|
31
38
|
properties: {
|
32
39
|
message: {
|
33
|
-
type:
|
34
|
-
description:
|
40
|
+
type: JsonSchemaType.STRING,
|
41
|
+
description: "Response message",
|
35
42
|
},
|
36
43
|
},
|
37
44
|
};
|
38
45
|
|
39
|
-
|
46
|
+
/// @deprecated
|
40
47
|
export const MessageModel = {
|
41
48
|
contentType: MediaType.APPLICATION_JSON,
|
42
|
-
modelName:
|
49
|
+
modelName: "MessageResponseModel",
|
43
50
|
schema: messageSchema,
|
44
51
|
};
|
45
52
|
|
46
|
-
const NotFoundMessage =
|
47
|
-
export const NotFoundResponse = JSON.stringify({message: NotFoundMessage});
|
53
|
+
const NotFoundMessage = "Not found";
|
54
|
+
export const NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
|
48
55
|
|
49
|
-
const InternalServerErrorMessage =
|
50
|
-
const InternalServerErrorResponse = JSON.stringify({
|
56
|
+
const InternalServerErrorMessage = "Error";
|
57
|
+
const InternalServerErrorResponse = JSON.stringify({
|
58
|
+
message: InternalServerErrorMessage,
|
59
|
+
});
|
51
60
|
|
52
|
-
const BadRequestMessage =
|
53
|
-
const BadRequestResponse = JSON.stringify({message: BadRequestMessage});
|
61
|
+
const BadRequestMessage = "Bad request";
|
62
|
+
const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
|
54
63
|
|
55
|
-
|
56
|
-
export const
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
/// @deprecated
|
65
|
+
export const BadRequestResponseTemplate = createResponses(
|
66
|
+
MediaType.APPLICATION_JSON,
|
67
|
+
BadRequestResponse
|
68
|
+
);
|
69
|
+
/// @deprecated
|
70
|
+
export const NotFoundResponseTemplate = createResponses(
|
71
|
+
MediaType.APPLICATION_JSON,
|
72
|
+
NotFoundResponse
|
73
|
+
);
|
74
|
+
/// @deprecated
|
75
|
+
export const XmlResponseTemplate = createResponses(
|
76
|
+
MediaType.APPLICATION_XML,
|
77
|
+
BODY_FROM_INPUT_PATH
|
78
|
+
);
|
79
|
+
/// @deprecated
|
80
|
+
export const InternalServerErrorResponseTemplate = createResponses(
|
81
|
+
MediaType.APPLICATION_JSON,
|
82
|
+
InternalServerErrorResponse
|
83
|
+
);
|
60
84
|
|
61
|
-
|
62
|
-
|
85
|
+
/// @deprecated
|
86
|
+
export function createResponses<T>(
|
87
|
+
key: MediaType,
|
88
|
+
value: T
|
89
|
+
): Record<string, T> {
|
90
|
+
return {
|
91
|
+
[key]: value,
|
92
|
+
};
|
93
|
+
}
|
94
|
+
|
95
|
+
export class DigitrafficMethodResponse {
|
96
|
+
static response(
|
97
|
+
statusCode: string,
|
98
|
+
model: IModel,
|
99
|
+
mediaType: MediaType,
|
100
|
+
disableCors = false
|
101
|
+
): MethodResponse {
|
102
|
+
return {
|
103
|
+
statusCode,
|
104
|
+
responseModels: {
|
105
|
+
[mediaType]: model,
|
106
|
+
},
|
107
|
+
responseParameters: disableCors
|
108
|
+
? {}
|
109
|
+
: {
|
110
|
+
"method.response.header.Access-Control-Allow-Origin":
|
111
|
+
true,
|
112
|
+
},
|
113
|
+
};
|
114
|
+
}
|
115
|
+
|
116
|
+
static response200(model: IModel, mediaType = MediaType.APPLICATION_JSON) {
|
117
|
+
return DigitrafficMethodResponse.response(
|
118
|
+
"200",
|
119
|
+
model,
|
120
|
+
mediaType,
|
121
|
+
false
|
122
|
+
);
|
123
|
+
}
|
63
124
|
|
64
|
-
|
125
|
+
static response500(
|
126
|
+
model = Model.EMPTY_MODEL,
|
127
|
+
mediaType = MediaType.APPLICATION_JSON
|
128
|
+
) {
|
129
|
+
return DigitrafficMethodResponse.response(
|
130
|
+
"500",
|
131
|
+
model,
|
132
|
+
mediaType,
|
133
|
+
false
|
134
|
+
);
|
135
|
+
}
|
65
136
|
|
66
|
-
|
137
|
+
static response400(
|
138
|
+
model = Model.EMPTY_MODEL,
|
139
|
+
mediaType = MediaType.APPLICATION_JSON
|
140
|
+
) {
|
141
|
+
return DigitrafficMethodResponse.response(
|
142
|
+
"400",
|
143
|
+
model,
|
144
|
+
mediaType,
|
145
|
+
false
|
146
|
+
);
|
147
|
+
}
|
67
148
|
}
|
@@ -52,6 +52,9 @@ export const RESPONSE_404_NOT_FOUND = {
|
|
52
52
|
responseTemplates: NotFoundResponseTemplate,
|
53
53
|
};
|
54
54
|
|
55
|
+
/**
|
56
|
+
* @deprecated Use DigitrafficMethodResponse
|
57
|
+
*/
|
55
58
|
export function methodResponse(
|
56
59
|
status: string,
|
57
60
|
contentType: MediaType,
|
@@ -65,6 +68,9 @@ export function methodResponse(
|
|
65
68
|
};
|
66
69
|
}
|
67
70
|
|
71
|
+
/**
|
72
|
+
* @deprecated Use DigitrafficMethodResponse
|
73
|
+
*/
|
68
74
|
export function corsMethod(response: MethodResponse): MethodResponse {
|
69
75
|
return {
|
70
76
|
...response,
|
@@ -89,6 +95,8 @@ interface IntegrationOptions {
|
|
89
95
|
* Creates a default Lambda integration for a REST API resource _root_
|
90
96
|
* @param lambdaFunction The Lambda function
|
91
97
|
* @param options Options
|
98
|
+
*
|
99
|
+
* @deprecated Use DigitrafficIntegration
|
92
100
|
*/
|
93
101
|
export function defaultIntegration(
|
94
102
|
lambdaFunction: AWSFunction,
|
@@ -1,13 +1,17 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
1
|
+
import {
|
2
|
+
MockIntegration,
|
3
|
+
PassthroughBehavior,
|
4
|
+
Resource,
|
5
|
+
} from "aws-cdk-lib/aws-apigateway";
|
6
|
+
import { MediaType } from "../../types/mediatypes";
|
7
|
+
import { corsMethod, RESPONSE_CORS_INTEGRATION } from "./responses";
|
4
8
|
|
5
9
|
const INTEGRATION_RESPONSE_200 = `{
|
6
10
|
"statusCode": 200
|
7
11
|
}`;
|
8
12
|
|
9
13
|
const METHOD_RESPONSE_200 = {
|
10
|
-
statusCode:
|
14
|
+
statusCode: "200",
|
11
15
|
};
|
12
16
|
|
13
17
|
/**
|
@@ -19,9 +23,18 @@ const METHOD_RESPONSE_200 = {
|
|
19
23
|
*/
|
20
24
|
export class DigitrafficStaticIntegration extends MockIntegration {
|
21
25
|
constructor(
|
22
|
-
resource: Resource,
|
26
|
+
resource: Resource,
|
27
|
+
mediaType: MediaType,
|
28
|
+
response: string,
|
29
|
+
enableCors = true,
|
30
|
+
apiKeyRequired = true
|
23
31
|
) {
|
24
|
-
const integrationResponse =
|
32
|
+
const integrationResponse =
|
33
|
+
DigitrafficStaticIntegration.createIntegrationResponse(
|
34
|
+
response,
|
35
|
+
mediaType,
|
36
|
+
enableCors
|
37
|
+
);
|
25
38
|
|
26
39
|
super({
|
27
40
|
passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
|
@@ -31,32 +44,53 @@ export class DigitrafficStaticIntegration extends MockIntegration {
|
|
31
44
|
integrationResponses: [integrationResponse],
|
32
45
|
});
|
33
46
|
|
34
|
-
[
|
47
|
+
["GET", "HEAD"].forEach((httpMethod) => {
|
35
48
|
resource.addMethod(httpMethod, this, {
|
36
49
|
apiKeyRequired,
|
37
|
-
methodResponses: [
|
50
|
+
methodResponses: [
|
51
|
+
DigitrafficStaticIntegration.createMethodResponse(
|
52
|
+
enableCors
|
53
|
+
),
|
54
|
+
],
|
38
55
|
});
|
39
56
|
});
|
40
57
|
}
|
41
58
|
|
42
|
-
static json<K>(
|
59
|
+
static json<K>(
|
60
|
+
resource: Resource,
|
61
|
+
response: K,
|
62
|
+
enableCors = true,
|
63
|
+
apiKeyRequired = true
|
64
|
+
) {
|
43
65
|
return new DigitrafficStaticIntegration(
|
44
|
-
resource,
|
66
|
+
resource,
|
67
|
+
MediaType.APPLICATION_JSON,
|
68
|
+
JSON.stringify(response),
|
69
|
+
enableCors,
|
70
|
+
apiKeyRequired
|
45
71
|
);
|
46
72
|
}
|
47
73
|
|
48
|
-
private static createIntegrationResponse(
|
74
|
+
private static createIntegrationResponse(
|
75
|
+
response: string,
|
76
|
+
mediaType: MediaType,
|
77
|
+
enableCors: boolean
|
78
|
+
) {
|
49
79
|
const integrationResponse = {
|
50
|
-
statusCode:
|
80
|
+
statusCode: "200",
|
51
81
|
responseTemplates: {
|
52
82
|
[mediaType]: response,
|
53
83
|
},
|
54
84
|
};
|
55
85
|
|
56
|
-
return enableCors
|
86
|
+
return enableCors
|
87
|
+
? { ...integrationResponse, ...RESPONSE_CORS_INTEGRATION }
|
88
|
+
: integrationResponse;
|
57
89
|
}
|
58
90
|
|
59
91
|
private static createMethodResponse(enableCors: boolean) {
|
60
|
-
return enableCors
|
92
|
+
return enableCors
|
93
|
+
? corsMethod(METHOD_RESPONSE_200)
|
94
|
+
: METHOD_RESPONSE_200;
|
61
95
|
}
|
62
96
|
}
|
package/src/database/database.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { IDatabase, ITask } from "pg-promise";
|
2
2
|
import { DatabaseEnvironmentKeys } from "../aws/runtime/secrets/dbsecret";
|
3
|
-
import { getEnvVariable
|
3
|
+
import { getEnvVariable } from "../utils/utils";
|
4
4
|
import { envValue } from "../aws/runtime/environment";
|
5
5
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|