@digitraffic/common 2023.1.23-2 → 2023.1.26-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.
@@ -12,6 +12,14 @@ 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
+ */
15
23
  export declare const getDeprecatedDefaultLambdaResponse: (sunset: string) => string;
16
24
  export declare const MessageModel: {
17
25
  contentType: MediaType;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
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,9 +26,17 @@ $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
+ */
28
37
  const getDeprecatedDefaultLambdaResponse = (sunset) => {
29
38
  const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
30
- #set ($context.responseOverride.header.Sunset = '${sunset}')`;
39
+ #set ($context.responseOverride.header.Sunset = '${(0, date_utils_1.dateFromIsoString)(sunset).toUTCString()}')`;
31
40
  return exports.RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
32
41
  };
33
42
  exports.getDeprecatedDefaultLambdaResponse = getDeprecatedDefaultLambdaResponse;
@@ -81,9 +90,13 @@ class DigitrafficMethodResponse {
81
90
  [mediaType]: model,
82
91
  },
83
92
  responseParameters: {
84
- "method.response.header.Access-Control-Allow-Origin": !disableCors,
85
- "method.response.header.Deprecation": deprecation,
86
- "method.response.header.Sunset": deprecation,
93
+ ...(!disableCors && {
94
+ "method.response.header.Access-Control-Allow-Origin": true,
95
+ }),
96
+ ...(deprecation && {
97
+ "method.response.header.Deprecation": true,
98
+ "method.response.header.Sunset": true,
99
+ }),
87
100
  },
88
101
  };
89
102
  }
@@ -34,7 +34,7 @@ export declare class ContentChecker {
34
34
  static checkResponse(fn: (body: string, res: IncomingMessage) => void): CheckerFunction;
35
35
  }
36
36
  export declare class ContentTypeChecker {
37
- static checkContentType(contentType: MediaType): (res: IncomingMessage) => void;
37
+ static checkContentType(contentType: MediaType): CheckerFunction;
38
38
  }
39
39
  export declare class GeoJsonChecker {
40
40
  static validFeatureCollection(fn?: (json: FeatureCollection) => void): CheckerFunction;
@@ -233,6 +233,7 @@ class ContentTypeChecker {
233
233
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
234
234
  `Wrong content-type ${res.headers["content-type"]}`);
235
235
  }
236
+ return Promise.resolve();
236
237
  };
237
238
  }
238
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.01.23-2",
3
+ "version": "2023.01.26-1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,6 +1,7 @@
1
1
  import {MediaType} from "../../types/mediatypes";
2
2
  import {JsonSchema, JsonSchemaType, JsonSchemaVersion, MethodResponse, Model,} from "aws-cdk-lib/aws-apigateway";
3
3
  import {IModel} from "aws-cdk-lib/aws-apigateway/lib/model";
4
+ import {dateFromIsoString} from "../../../utils/date-utils";
4
5
 
5
6
  /**
6
7
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
@@ -25,9 +26,18 @@ $util.base64Decode($inputRoot.body)
25
26
  #end
26
27
  `;
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
+
28
38
  export const getDeprecatedDefaultLambdaResponse = (sunset: string) => {
29
39
  const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
30
- #set ($context.responseOverride.header.Sunset = '${sunset}')`;
40
+ #set ($context.responseOverride.header.Sunset = '${dateFromIsoString(sunset).toUTCString()}')`;
31
41
  return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
32
42
  };
33
43
 
@@ -109,9 +119,13 @@ export class DigitrafficMethodResponse {
109
119
  [mediaType]: model,
110
120
  },
111
121
  responseParameters: {
112
- "method.response.header.Access-Control-Allow-Origin": !disableCors,
113
- "method.response.header.Deprecation": deprecation,
114
- "method.response.header.Sunset": deprecation,
122
+ ...(!disableCors && {
123
+ "method.response.header.Access-Control-Allow-Origin": true,
124
+ }),
125
+ ...(deprecation && {
126
+ "method.response.header.Deprecation": true,
127
+ "method.response.header.Sunset": true,
128
+ }),
115
129
  },
116
130
  };
117
131
  }
@@ -318,7 +318,7 @@ export class ContentChecker {
318
318
  }
319
319
 
320
320
  export class ContentTypeChecker {
321
- static checkContentType(contentType: MediaType) {
321
+ static checkContentType(contentType: MediaType): CheckerFunction {
322
322
  return (res: IncomingMessage) => {
323
323
  if (!res.statusCode) {
324
324
  throw new Error("statusCode missing");
@@ -339,6 +339,8 @@ export class ContentTypeChecker {
339
339
  `Wrong content-type ${res.headers["content-type"]!}`
340
340
  );
341
341
  }
342
+
343
+ return Promise.resolve();
342
344
  };
343
345
  }
344
346
  }