@digitraffic/common 2023.1.23-1 → 2023.1.23-2

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.
@@ -10,7 +10,8 @@ export declare class DigitrafficIntegration {
10
10
  readonly lambda: IFunction;
11
11
  readonly mediaType: MediaType;
12
12
  readonly parameters: ApiParameter[];
13
- constructor(lambda: IFunction, mediaType?: MediaType);
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,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
  */
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
+ export declare const getDeprecatedDefaultLambdaResponse: (sunset: string) => string;
15
16
  export declare const MessageModel: {
16
17
  contentType: MediaType;
17
18
  modelName: string;
@@ -24,7 +25,7 @@ export declare const XmlResponseTemplate: Record<string, string>;
24
25
  export declare const InternalServerErrorResponseTemplate: Record<string, string>;
25
26
  export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
26
27
  export declare class DigitrafficMethodResponse {
27
- static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
28
+ static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean, deprecation?: boolean): MethodResponse;
28
29
  static response200(model: IModel, mediaType?: MediaType): MethodResponse;
29
30
  static response500(model?: IModel, mediaType?: MediaType): MethodResponse;
30
31
  static response400(model?: IModel, mediaType?: MediaType): MethodResponse;
@@ -1,6 +1,6 @@
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
6
  /**
@@ -25,6 +25,12 @@ $util.base64Decode($inputRoot.body)
25
25
  #set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
26
26
  #end
27
27
  `;
28
+ const getDeprecatedDefaultLambdaResponse = (sunset) => {
29
+ const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
30
+ #set ($context.responseOverride.header.Sunset = '${sunset}')`;
31
+ return exports.RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
32
+ };
33
+ exports.getDeprecatedDefaultLambdaResponse = getDeprecatedDefaultLambdaResponse;
28
34
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
29
35
  /// @deprecated
30
36
  const messageSchema = {
@@ -68,17 +74,17 @@ function createResponses(key, value) {
68
74
  }
69
75
  exports.createResponses = createResponses;
70
76
  class DigitrafficMethodResponse {
71
- static response(statusCode, model, mediaType, disableCors = false) {
77
+ static response(statusCode, model, mediaType, disableCors = false, deprecation = false) {
72
78
  return {
73
79
  statusCode,
74
80
  responseModels: {
75
81
  [mediaType]: model,
76
82
  },
77
- responseParameters: disableCors
78
- ? {}
79
- : {
80
- "method.response.header.Access-Control-Allow-Origin": true,
81
- },
83
+ responseParameters: {
84
+ "method.response.header.Access-Control-Allow-Origin": !disableCors,
85
+ "method.response.header.Deprecation": deprecation,
86
+ "method.response.header.Sunset": deprecation,
87
+ },
82
88
  };
83
89
  }
84
90
  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]: response_1.RESPONSE_DEFAULT_LAMBDA,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.01.23-1",
3
+ "version": "2023.01.23-2",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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(lambda: IFunction, mediaType = MediaType.TEXT_PLAIN) {
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,6 @@
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";
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";
10
4
 
11
5
  /**
12
6
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
@@ -31,6 +25,12 @@ $util.base64Decode($inputRoot.body)
31
25
  #end
32
26
  `;
33
27
 
28
+ export const getDeprecatedDefaultLambdaResponse = (sunset: string) => {
29
+ const setDeprecationHeaders = `#set ($context.responseOverride.header.Deprecation = 'true')
30
+ #set ($context.responseOverride.header.Sunset = '${sunset}')`;
31
+ return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
32
+ };
33
+
34
34
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
35
35
 
36
36
  /// @deprecated
@@ -100,19 +100,19 @@ export class DigitrafficMethodResponse {
100
100
  statusCode: string,
101
101
  model: IModel,
102
102
  mediaType: MediaType,
103
- disableCors = false
103
+ disableCors = false,
104
+ deprecation = false
104
105
  ): MethodResponse {
105
106
  return {
106
107
  statusCode,
107
108
  responseModels: {
108
109
  [mediaType]: model,
109
110
  },
110
- responseParameters: disableCors
111
- ? {}
112
- : {
113
- "method.response.header.Access-Control-Allow-Origin":
114
- true,
115
- },
111
+ responseParameters: {
112
+ "method.response.header.Access-Control-Allow-Origin": !disableCors,
113
+ "method.response.header.Deprecation": deprecation,
114
+ "method.response.header.Sunset": deprecation,
115
+ },
116
116
  };
117
117
  }
118
118
 
@@ -1,11 +1,13 @@
1
- import {IntegrationResponse} from "aws-cdk-lib/aws-apigateway";
2
- import {MediaType} from "../types/mediatypes";
3
- import {RESPONSE_DEFAULT_LAMBDA} from "../infra/api/response";
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
- static ok(mediaType: MediaType): IntegrationResponse {
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(statusCode: string, mediaType: MediaType): IntegrationResponse {
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]: RESPONSE_DEFAULT_LAMBDA,
29
+ [mediaType]: sunset
30
+ ? getDeprecatedDefaultLambdaResponse(sunset)
31
+ : RESPONSE_DEFAULT_LAMBDA,
24
32
  },
25
33
  };
26
34
  }
27
35
  }
28
-