@digitraffic/common 2023.1.23-1 → 2023.1.23-3
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 +2 -1
- package/dist/aws/infra/api/integration.js +3 -2
- package/dist/aws/infra/api/response.d.ts +10 -1
- package/dist/aws/infra/api/response.js +22 -7
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +2 -2
- package/dist/aws/runtime/digitraffic-integration-response.js +6 -4
- package/package.json +1 -1
- package/src/aws/infra/api/integration.ts +8 -3
- package/src/aws/infra/api/response.ts +26 -16
- package/src/aws/runtime/digitraffic-integration-response.ts +16 -9
@@ -10,7 +10,8 @@ export declare class DigitrafficIntegration {
|
|
10
10
|
readonly lambda: IFunction;
|
11
11
|
readonly mediaType: MediaType;
|
12
12
|
readonly parameters: ApiParameter[];
|
13
|
-
|
13
|
+
readonly sunset?: string;
|
14
|
+
constructor(lambda: IFunction, mediaType?: MediaType, sunset?: string);
|
14
15
|
addPathParameter(...names: string[]): this;
|
15
16
|
addQueryParameter(...names: string[]): this;
|
16
17
|
build(): LambdaIntegration;
|
@@ -5,10 +5,11 @@ const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
|
5
5
|
const mediatypes_1 = require("../../types/mediatypes");
|
6
6
|
const digitraffic_integration_response_1 = require("../../runtime/digitraffic-integration-response");
|
7
7
|
class DigitrafficIntegration {
|
8
|
-
constructor(lambda, mediaType = mediatypes_1.MediaType.TEXT_PLAIN) {
|
8
|
+
constructor(lambda, mediaType = mediatypes_1.MediaType.TEXT_PLAIN, sunset) {
|
9
9
|
this.parameters = [];
|
10
10
|
this.lambda = lambda;
|
11
11
|
this.mediaType = mediaType;
|
12
|
+
this.sunset = sunset;
|
12
13
|
}
|
13
14
|
addPathParameter(...names) {
|
14
15
|
names.forEach((name) => this.parameters.push({ type: "path", name }));
|
@@ -49,7 +50,7 @@ class DigitrafficIntegration {
|
|
49
50
|
};
|
50
51
|
}
|
51
52
|
createResponses() {
|
52
|
-
return [digitraffic_integration_response_1.DigitrafficIntegrationResponse.ok(this.mediaType)];
|
53
|
+
return [digitraffic_integration_response_1.DigitrafficIntegrationResponse.ok(this.mediaType, this.sunset)];
|
53
54
|
}
|
54
55
|
}
|
55
56
|
exports.DigitrafficIntegration = DigitrafficIntegration;
|
@@ -12,6 +12,15 @@ 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
|
*/
|
14
14
|
export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$'))\n$util.base64Decode($inputRoot.body)\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.fileName\" != \"\")\n#set ($disposition = 'attachment; filename=\"FN\"')\n#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))\n#end\n";
|
15
|
+
/**
|
16
|
+
* Use this for deprecated integrations.
|
17
|
+
* Will add HTTP headers Deprecation and Sunset to response.
|
18
|
+
* Example:
|
19
|
+
* Deprecation: true
|
20
|
+
* Sunset: Tue, 20 Dec 2022 00:00:00 GMT
|
21
|
+
* @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
|
22
|
+
*/
|
23
|
+
export declare const getDeprecatedDefaultLambdaResponse: (sunset: string) => string;
|
15
24
|
export declare const MessageModel: {
|
16
25
|
contentType: MediaType;
|
17
26
|
modelName: string;
|
@@ -24,7 +33,7 @@ export declare const XmlResponseTemplate: Record<string, string>;
|
|
24
33
|
export declare const InternalServerErrorResponseTemplate: Record<string, string>;
|
25
34
|
export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
|
26
35
|
export declare class DigitrafficMethodResponse {
|
27
|
-
static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
|
36
|
+
static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean, deprecation?: boolean): MethodResponse;
|
28
37
|
static response200(model: IModel, mediaType?: MediaType): MethodResponse;
|
29
38
|
static response500(model?: IModel, mediaType?: MediaType): MethodResponse;
|
30
39
|
static response400(model?: IModel, mediaType?: MediaType): MethodResponse;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DigitrafficMethodResponse = exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
|
3
|
+
exports.DigitrafficMethodResponse = exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.getDeprecatedDefaultLambdaResponse = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
|
4
4
|
const mediatypes_1 = require("../../types/mediatypes");
|
5
5
|
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
|
+
const date_utils_1 = require("../../../utils/date-utils");
|
6
7
|
/**
|
7
8
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
8
9
|
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
@@ -25,6 +26,20 @@ $util.base64Decode($inputRoot.body)
|
|
25
26
|
#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
|
26
27
|
#end
|
27
28
|
`;
|
29
|
+
/**
|
30
|
+
* Use this for deprecated integrations.
|
31
|
+
* Will add HTTP headers Deprecation and Sunset to response.
|
32
|
+
* Example:
|
33
|
+
* Deprecation: true
|
34
|
+
* Sunset: Tue, 20 Dec 2022 00:00:00 GMT
|
35
|
+
* @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
|
36
|
+
*/
|
37
|
+
const getDeprecatedDefaultLambdaResponse = (sunset) => {
|
38
|
+
const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
|
39
|
+
#set ($context.responseOverride.header.Sunset = '${(0, date_utils_1.dateFromIsoString)(sunset).toUTCString()}')`;
|
40
|
+
return exports.RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
|
41
|
+
};
|
42
|
+
exports.getDeprecatedDefaultLambdaResponse = getDeprecatedDefaultLambdaResponse;
|
28
43
|
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
29
44
|
/// @deprecated
|
30
45
|
const messageSchema = {
|
@@ -68,17 +83,17 @@ function createResponses(key, value) {
|
|
68
83
|
}
|
69
84
|
exports.createResponses = createResponses;
|
70
85
|
class DigitrafficMethodResponse {
|
71
|
-
static response(statusCode, model, mediaType, disableCors = false) {
|
86
|
+
static response(statusCode, model, mediaType, disableCors = false, deprecation = false) {
|
72
87
|
return {
|
73
88
|
statusCode,
|
74
89
|
responseModels: {
|
75
90
|
[mediaType]: model,
|
76
91
|
},
|
77
|
-
responseParameters:
|
78
|
-
|
79
|
-
:
|
80
|
-
|
81
|
-
|
92
|
+
responseParameters: {
|
93
|
+
"method.response.header.Access-Control-Allow-Origin": !disableCors,
|
94
|
+
"method.response.header.Deprecation": deprecation,
|
95
|
+
"method.response.header.Sunset": deprecation,
|
96
|
+
},
|
82
97
|
};
|
83
98
|
}
|
84
99
|
static response200(model, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { MediaType } from "../types/mediatypes";
|
3
3
|
export declare abstract class DigitrafficIntegrationResponse {
|
4
|
-
static ok(mediaType: MediaType): IntegrationResponse;
|
4
|
+
static ok(mediaType: MediaType, sunset?: string): IntegrationResponse;
|
5
5
|
static badRequest(mediaType?: MediaType): IntegrationResponse;
|
6
6
|
static notImplemented(mediaType?: MediaType): IntegrationResponse;
|
7
|
-
static create(statusCode: string, mediaType: MediaType): IntegrationResponse;
|
7
|
+
static create(statusCode: string, mediaType: MediaType, sunset?: string): IntegrationResponse;
|
8
8
|
}
|
@@ -4,8 +4,8 @@ exports.DigitrafficIntegrationResponse = void 0;
|
|
4
4
|
const mediatypes_1 = require("../types/mediatypes");
|
5
5
|
const response_1 = require("../infra/api/response");
|
6
6
|
class DigitrafficIntegrationResponse {
|
7
|
-
static ok(mediaType) {
|
8
|
-
return this.create("200", mediaType);
|
7
|
+
static ok(mediaType, sunset) {
|
8
|
+
return this.create("200", mediaType, sunset);
|
9
9
|
}
|
10
10
|
static badRequest(mediaType) {
|
11
11
|
return this.create("400", mediaType ?? mediatypes_1.MediaType.TEXT_PLAIN);
|
@@ -13,11 +13,13 @@ class DigitrafficIntegrationResponse {
|
|
13
13
|
static notImplemented(mediaType) {
|
14
14
|
return this.create("501", mediaType ?? mediatypes_1.MediaType.TEXT_PLAIN);
|
15
15
|
}
|
16
|
-
static create(statusCode, mediaType) {
|
16
|
+
static create(statusCode, mediaType, sunset) {
|
17
17
|
return {
|
18
18
|
statusCode,
|
19
19
|
responseTemplates: {
|
20
|
-
[mediaType]:
|
20
|
+
[mediaType]: sunset
|
21
|
+
? (0, response_1.getDeprecatedDefaultLambdaResponse)(sunset)
|
22
|
+
: response_1.RESPONSE_DEFAULT_LAMBDA,
|
21
23
|
},
|
22
24
|
};
|
23
25
|
}
|
package/package.json
CHANGED
@@ -17,12 +17,17 @@ interface ApiParameter {
|
|
17
17
|
export class DigitrafficIntegration {
|
18
18
|
readonly lambda: IFunction;
|
19
19
|
readonly mediaType: MediaType;
|
20
|
-
|
21
20
|
readonly parameters: ApiParameter[] = [];
|
21
|
+
readonly sunset?: string;
|
22
22
|
|
23
|
-
constructor(
|
23
|
+
constructor(
|
24
|
+
lambda: IFunction,
|
25
|
+
mediaType = MediaType.TEXT_PLAIN,
|
26
|
+
sunset?: string
|
27
|
+
) {
|
24
28
|
this.lambda = lambda;
|
25
29
|
this.mediaType = mediaType;
|
30
|
+
this.sunset = sunset;
|
26
31
|
}
|
27
32
|
|
28
33
|
addPathParameter(...names: string[]): this {
|
@@ -84,6 +89,6 @@ export class DigitrafficIntegration {
|
|
84
89
|
}
|
85
90
|
|
86
91
|
createResponses(): IntegrationResponse[] {
|
87
|
-
return [DigitrafficIntegrationResponse.ok(this.mediaType)];
|
92
|
+
return [DigitrafficIntegrationResponse.ok(this.mediaType, this.sunset)];
|
88
93
|
}
|
89
94
|
}
|
@@ -1,12 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
JsonSchema,
|
6
|
-
MethodResponse,
|
7
|
-
Model,
|
8
|
-
} from "aws-cdk-lib/aws-apigateway";
|
9
|
-
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
1
|
+
import {MediaType} from "../../types/mediatypes";
|
2
|
+
import {JsonSchema, JsonSchemaType, JsonSchemaVersion, MethodResponse, Model,} from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import {IModel} from "aws-cdk-lib/aws-apigateway/lib/model";
|
4
|
+
import {dateFromIsoString} from "../../../utils/date-utils";
|
10
5
|
|
11
6
|
/**
|
12
7
|
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
@@ -31,6 +26,21 @@ $util.base64Decode($inputRoot.body)
|
|
31
26
|
#end
|
32
27
|
`;
|
33
28
|
|
29
|
+
/**
|
30
|
+
* Use this for deprecated integrations.
|
31
|
+
* Will add HTTP headers Deprecation and Sunset to response.
|
32
|
+
* Example:
|
33
|
+
* Deprecation: true
|
34
|
+
* Sunset: Tue, 20 Dec 2022 00:00:00 GMT
|
35
|
+
* @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
|
36
|
+
*/
|
37
|
+
|
38
|
+
export const getDeprecatedDefaultLambdaResponse = (sunset: string) => {
|
39
|
+
const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
|
40
|
+
#set ($context.responseOverride.header.Sunset = '${dateFromIsoString(sunset).toUTCString()}')`;
|
41
|
+
return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
|
42
|
+
};
|
43
|
+
|
34
44
|
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
35
45
|
|
36
46
|
/// @deprecated
|
@@ -100,19 +110,19 @@ export class DigitrafficMethodResponse {
|
|
100
110
|
statusCode: string,
|
101
111
|
model: IModel,
|
102
112
|
mediaType: MediaType,
|
103
|
-
disableCors = false
|
113
|
+
disableCors = false,
|
114
|
+
deprecation = false
|
104
115
|
): MethodResponse {
|
105
116
|
return {
|
106
117
|
statusCode,
|
107
118
|
responseModels: {
|
108
119
|
[mediaType]: model,
|
109
120
|
},
|
110
|
-
responseParameters:
|
111
|
-
|
112
|
-
:
|
113
|
-
|
114
|
-
|
115
|
-
},
|
121
|
+
responseParameters: {
|
122
|
+
"method.response.header.Access-Control-Allow-Origin": !disableCors,
|
123
|
+
"method.response.header.Deprecation": deprecation,
|
124
|
+
"method.response.header.Sunset": deprecation,
|
125
|
+
},
|
116
126
|
};
|
117
127
|
}
|
118
128
|
|
@@ -1,11 +1,13 @@
|
|
1
|
-
import {IntegrationResponse} from "aws-cdk-lib/aws-apigateway";
|
2
|
-
import {MediaType} from "../types/mediatypes";
|
3
|
-
import {
|
1
|
+
import { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import { MediaType } from "../types/mediatypes";
|
3
|
+
import {
|
4
|
+
getDeprecatedDefaultLambdaResponse,
|
5
|
+
RESPONSE_DEFAULT_LAMBDA,
|
6
|
+
} from "../infra/api/response";
|
4
7
|
|
5
8
|
export abstract class DigitrafficIntegrationResponse {
|
6
|
-
|
7
|
-
|
8
|
-
return this.create("200", mediaType);
|
9
|
+
static ok(mediaType: MediaType, sunset?: string): IntegrationResponse {
|
10
|
+
return this.create("200", mediaType, sunset);
|
9
11
|
}
|
10
12
|
|
11
13
|
static badRequest(mediaType?: MediaType): IntegrationResponse {
|
@@ -16,13 +18,18 @@ export abstract class DigitrafficIntegrationResponse {
|
|
16
18
|
return this.create("501", mediaType ?? MediaType.TEXT_PLAIN);
|
17
19
|
}
|
18
20
|
|
19
|
-
static create(
|
21
|
+
static create(
|
22
|
+
statusCode: string,
|
23
|
+
mediaType: MediaType,
|
24
|
+
sunset?: string
|
25
|
+
): IntegrationResponse {
|
20
26
|
return {
|
21
27
|
statusCode,
|
22
28
|
responseTemplates: {
|
23
|
-
[mediaType]:
|
29
|
+
[mediaType]: sunset
|
30
|
+
? getDeprecatedDefaultLambdaResponse(sunset)
|
31
|
+
: RESPONSE_DEFAULT_LAMBDA,
|
24
32
|
},
|
25
33
|
};
|
26
34
|
}
|
27
35
|
}
|
28
|
-
|