@digitraffic/common 2023.5.22-1 → 2023.5.25-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,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.ETag = $inputRoot.timestamp)\n#set ($context.responseOverride.header.Last-Modified = $inputRoot.timestamp)\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)";
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))
@@ -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.22-1",
3
+ "version": "2023.5.25-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,6 +35,7 @@
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
40
  "@types/lodash": "^4.14.194",
39
41
  "@types/node": "18.15.13",
@@ -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))
@@ -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) {