@digitraffic/common 2022.11.23-1 → 2022.11.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.
@@ -1,6 +1,5 @@
1
- import apigateway = require("aws-cdk-lib/aws-apigateway");
2
1
  import { MediaType } from "../../types/mediatypes";
3
- import { MethodResponse } from "aws-cdk-lib/aws-apigateway";
2
+ import { JsonSchema, MethodResponse } from "aws-cdk-lib/aws-apigateway";
4
3
  import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
5
4
  /**
6
5
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
@@ -13,17 +12,17 @@ export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$
13
12
  export declare const MessageModel: {
14
13
  contentType: MediaType;
15
14
  modelName: string;
16
- schema: apigateway.JsonSchema;
15
+ schema: JsonSchema;
17
16
  };
18
17
  export declare const NotFoundResponse: string;
19
18
  export declare const BadRequestResponseTemplate: Record<string, string>;
20
19
  export declare const NotFoundResponseTemplate: Record<string, string>;
21
20
  export declare const XmlResponseTemplate: Record<string, string>;
22
- export declare const SvgResponseTemplate: Record<string, string>;
23
21
  export declare const InternalServerErrorResponseTemplate: Record<string, string>;
24
22
  export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
25
23
  export declare class DigitrafficMethodResponse {
26
24
  static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean): MethodResponse;
27
- static response200(model: IModel, mediaType?: MediaType): apigateway.MethodResponse;
28
- static response500(model?: apigateway.IModel, mediaType?: MediaType): apigateway.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;
29
28
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DigitrafficMethodResponse = exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.SvgResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
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");
6
5
  const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
7
6
  /**
@@ -24,19 +23,19 @@ $inputRoot.body
24
23
  #end
25
24
  `;
26
25
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
27
- // DEPRECATED
26
+ /// @deprecated
28
27
  const messageSchema = {
29
- schema: apigateway.JsonSchemaVersion.DRAFT4,
30
- type: apigateway.JsonSchemaType.OBJECT,
28
+ schema: aws_apigateway_1.JsonSchemaVersion.DRAFT4,
29
+ type: aws_apigateway_1.JsonSchemaType.OBJECT,
31
30
  description: "Response with message",
32
31
  properties: {
33
32
  message: {
34
- type: apigateway.JsonSchemaType.STRING,
33
+ type: aws_apigateway_1.JsonSchemaType.STRING,
35
34
  description: "Response message",
36
35
  },
37
36
  },
38
37
  };
39
- // DEPRECATED
38
+ /// @deprecated
40
39
  exports.MessageModel = {
41
40
  contentType: mediatypes_1.MediaType.APPLICATION_JSON,
42
41
  modelName: "MessageResponseModel",
@@ -50,11 +49,15 @@ const InternalServerErrorResponse = JSON.stringify({
50
49
  });
51
50
  const BadRequestMessage = "Bad request";
52
51
  const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
52
+ /// @deprecated
53
53
  exports.BadRequestResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, BadRequestResponse);
54
+ /// @deprecated
54
55
  exports.NotFoundResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, exports.NotFoundResponse);
56
+ /// @deprecated
55
57
  exports.XmlResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_XML, BODY_FROM_INPUT_PATH);
56
- exports.SvgResponseTemplate = createResponses(mediatypes_1.MediaType.IMAGE_SVG, BODY_FROM_INPUT_PATH);
58
+ /// @deprecated
57
59
  exports.InternalServerErrorResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, InternalServerErrorResponse);
60
+ /// @deprecated
58
61
  function createResponses(key, value) {
59
62
  return {
60
63
  [key]: value,
@@ -81,6 +84,9 @@ class DigitrafficMethodResponse {
81
84
  static response500(model = aws_apigateway_1.Model.EMPTY_MODEL, mediaType = mediatypes_1.MediaType.APPLICATION_JSON) {
82
85
  return DigitrafficMethodResponse.response("500", model, mediaType, false);
83
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
+ }
84
90
  }
85
91
  exports.DigitrafficMethodResponse = DigitrafficMethodResponse;
86
92
  //# sourceMappingURL=response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/aws/infra/api/response.ts"],"names":[],"mappings":";;;AAAA,yDAA0D;AAC1D,uDAAmD;AACnD,+DAAmE;AAGnE;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG;;;;;;;;;;;CAWtC,CAAC;AAEF,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAErD,aAAa;AACb,MAAM,aAAa,GAA0B;IACzC,MAAM,EAAE,UAAU,CAAC,iBAAiB,CAAC,MAAM;IAC3C,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,MAAM;IACtC,WAAW,EAAE,uBAAuB;IACpC,UAAU,EAAE;QACR,OAAO,EAAE;YACL,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,MA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pB,WAAW,GAAG,KAAK;QAEnB,OAAO;YACH,UAAU;YACV,cAAc,EAAE;gBACZ,CAAC,SAAS,CAAC,EAAE,KAAK;aACrB;YACD,kBAAkB,EAAE,WAAW;gBAC3B,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC;oBACI,oDAAoD,EAChD,IAAI;iBACX;SACV,CAAC;IACN,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,KAAa,EAAE,SAAS,GAAG,sBAAS,CAAC,gBAAgB;QACpE,OAAO,yBAAyB,CAAC,QAAQ,CACrC,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,CACR,CAAC;IACN,CAAC;IAED,MAAM,CAAC,WAAW,CACd,KAAK,GAAG,sBAAK,CAAC,WAAW,EACzB,SAAS,GAAG,sBAAS,CAAC,gBAAgB;QAEtC,OAAO,yBAAyB,CAAC,QAAQ,CACrC,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,CACR,CAAC;IACN,CAAC;CACJ;AAzCD,8DAyCC"}
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/aws/infra/api/response.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,+DAMoC;AAGpC;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG;;;;;;;;;;;CAWtC,CAAC;AAEF,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAErD,eAAe;AACf,MAAM,aAAa,GAAe;IAC9B,MAAM,EAAE,kCAAiB,CAAC,MAAM;IAChC,IAAI,EAAE,+BAAc,CAAC,MAAM;IAC3B,WAAW,EAAE,uBAAuB;IACpC,UAAU,EAAE;QACR,OAAO,EAAE;YACL,IAAI,EAAE,+BAAc,CAAC,MAAM;YAC3B,WAAW,EAAE,kBAAkB;SAClC;KACJ;CACJ,CAAC;AAEF,eAAe;AACF,QAAA,YAAY,GAAG;IACxB,WAAW,EAAE,sBAAS,CAAC,gBAAgB;IACvC,SAAS,EAAE,sBAAsB;IACjC,MAAM,EAAE,aAAa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;SACV,CAAC;IACN,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,KAAa,EAAE,SAAS,GAAG,sBAAS,CAAC,gBAAgB;QACpE,OAAO,yBAAyB,CAAC,QAAQ,CACrC,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,CACR,CAAC;IACN,CAAC;IAED,MAAM,CAAC,WAAW,CACd,KAAK,GAAG,sBAAK,CAAC,WAAW,EACzB,SAAS,GAAG,sBAAS,CAAC,gBAAgB;QAEtC,OAAO,yBAAyB,CAAC,QAAQ,CACrC,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,CACR,CAAC;IACN,CAAC;IAED,MAAM,CAAC,WAAW,CACd,KAAK,GAAG,sBAAK,CAAC,WAAW,EACzB,SAAS,GAAG,sBAAS,CAAC,gBAAgB;QAEtC,OAAO,yBAAyB,CAAC,QAAQ,CACrC,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,CACR,CAAC;IACN,CAAC;CACJ;AArDD,8DAqDC"}
@@ -16,11 +16,11 @@ export declare const RESPONSE_404_NOT_FOUND: {
16
16
  responseTemplates: Record<string, string>;
17
17
  };
18
18
  /**
19
- * @Deprecated Use DigitrafficMethodResponse
19
+ * @deprecated Use DigitrafficMethodResponse
20
20
  */
21
21
  export declare function methodResponse(status: string, contentType: MediaType, model: IModel, parameters?: Record<string, boolean>): MethodResponse;
22
22
  /**
23
- * @Deprecated Use DigitrafficMethodResponse
23
+ * @deprecated Use DigitrafficMethodResponse
24
24
  */
25
25
  export declare function corsMethod(response: MethodResponse): MethodResponse;
26
26
  interface IntegrationOptions {
@@ -31,7 +31,7 @@ exports.RESPONSE_404_NOT_FOUND = {
31
31
  responseTemplates: response_1.NotFoundResponseTemplate,
32
32
  };
33
33
  /**
34
- * @Deprecated Use DigitrafficMethodResponse
34
+ * @deprecated Use DigitrafficMethodResponse
35
35
  */
36
36
  function methodResponse(status, contentType, model, parameters) {
37
37
  return {
@@ -42,7 +42,7 @@ function methodResponse(status, contentType, model, parameters) {
42
42
  }
43
43
  exports.methodResponse = methodResponse;
44
44
  /**
45
- * @Deprecated Use DigitrafficMethodResponse
45
+ * @deprecated Use DigitrafficMethodResponse
46
46
  */
47
47
  function corsMethod(response) {
48
48
  return {
@@ -8,7 +8,7 @@ const INTEGRATION_RESPONSE_200 = `{
8
8
  "statusCode": 200
9
9
  }`;
10
10
  const METHOD_RESPONSE_200 = {
11
- statusCode: '200',
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
- ['GET', 'HEAD'].forEach((httpMethod) => {
30
+ ["GET", "HEAD"].forEach((httpMethod) => {
31
31
  resource.addMethod(httpMethod, this, {
32
32
  apiKeyRequired,
33
- methodResponses: [DigitrafficStaticIntegration.createMethodResponse(enableCors)],
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: '200',
44
+ statusCode: "200",
43
45
  responseTemplates: {
44
46
  [mediaType]: response,
45
47
  },
46
48
  };
47
- return enableCors ? { ...integrationResponse, ...responses_1.RESPONSE_CORS_INTEGRATION } : integrationResponse;
49
+ return enableCors
50
+ ? { ...integrationResponse, ...responses_1.RESPONSE_CORS_INTEGRATION }
51
+ : integrationResponse;
48
52
  }
49
53
  static createMethodResponse(enableCors) {
50
- return enableCors ? (0, responses_1.corsMethod)(METHOD_RESPONSE_200) : METHOD_RESPONSE_200;
54
+ return enableCors
55
+ ? (0, responses_1.corsMethod)(METHOD_RESPONSE_200)
56
+ : METHOD_RESPONSE_200;
51
57
  }
52
58
  }
53
59
  exports.DigitrafficStaticIntegration = DigitrafficStaticIntegration;
@@ -1 +1 @@
1
- {"version":3,"file":"static-integration.js","sourceRoot":"","sources":["../../../../src/aws/infra/api/static-integration.ts"],"names":[],"mappings":";;;AAAA,+DAA0F;AAC1F,uDAAiD;AACjD,2CAAkE;AAElE,MAAM,wBAAwB,GAAG;;EAE/B,CAAC;AAEH,MAAM,mBAAmB,GAAG;IACxB,UAAU,EAAE,KAAK;CACpB,CAAC;AAEF;;;;;;GAMG;AACH,MAAa,4BAA6B,SAAQ,gCAAe;IAC7D,YACI,QAAkB,EAAE,SAAoB,EAAE,QAAgB,EAAE,UAAU,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI;QAEpG,MAAM,mBAAmB,GAAG,4BAA4B,CAAC,yBAAyB,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QAEpH,KAAK,CAAC;YACF,mBAAmB,EAAE,oCAAmB,CAAC,iBAAiB;YAC1D,gBAAgB,EAAE;gBACd,CAAC,SAAS,CAAC,EAAE,wBAAwB;aACxC;YACD,oBAAoB,EAAE,CAAC,mBAAmB,CAAC;SAC9C,CAAC,CAAC;QAEH,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACnC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE;gBACjC,cAAc;gBACd,eAAe,EAAE,CAAC,4BAA4B,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;aACnF,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,IAAI,CAAI,QAAkB,EAAE,QAAW,EAAE,UAAU,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI;QACpF,OAAO,IAAI,4BAA4B,CACnC,QAAQ,EAAE,sBAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,cAAc,CAC7F,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,yBAAyB,CAAC,QAAgB,EAAE,SAAoB,EAAE,UAAmB;QAChG,MAAM,mBAAmB,GAAG;YACxB,UAAU,EAAE,KAAK;YACjB,iBAAiB,EAAE;gBACf,CAAC,SAAS,CAAC,EAAE,QAAQ;aACxB;SACJ,CAAC;QAEF,OAAO,UAAU,CAAC,CAAC,CAAC,EAAC,GAAG,mBAAmB,EAAE,GAAG,qCAAyB,EAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC;IACrG,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,UAAmB;QACnD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAA,sBAAU,EAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC;IAC9E,CAAC;CACJ;AA1CD,oEA0CC"}
1
+ {"version":3,"file":"static-integration.js","sourceRoot":"","sources":["../../../../src/aws/infra/api/static-integration.ts"],"names":[],"mappings":";;;AAAA,+DAIoC;AACpC,uDAAmD;AACnD,2CAAoE;AAEpE,MAAM,wBAAwB,GAAG;;EAE/B,CAAC;AAEH,MAAM,mBAAmB,GAAG;IACxB,UAAU,EAAE,KAAK;CACpB,CAAC;AAEF;;;;;;GAMG;AACH,MAAa,4BAA6B,SAAQ,gCAAe;IAC7D,YACI,QAAkB,EAClB,SAAoB,EACpB,QAAgB,EAChB,UAAU,GAAG,IAAI,EACjB,cAAc,GAAG,IAAI;QAErB,MAAM,mBAAmB,GACrB,4BAA4B,CAAC,yBAAyB,CAClD,QAAQ,EACR,SAAS,EACT,UAAU,CACb,CAAC;QAEN,KAAK,CAAC;YACF,mBAAmB,EAAE,oCAAmB,CAAC,iBAAiB;YAC1D,gBAAgB,EAAE;gBACd,CAAC,SAAS,CAAC,EAAE,wBAAwB;aACxC;YACD,oBAAoB,EAAE,CAAC,mBAAmB,CAAC;SAC9C,CAAC,CAAC;QAEH,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YACnC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE;gBACjC,cAAc;gBACd,eAAe,EAAE;oBACb,4BAA4B,CAAC,oBAAoB,CAC7C,UAAU,CACb;iBACJ;aACJ,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,IAAI,CACP,QAAkB,EAClB,QAAW,EACX,UAAU,GAAG,IAAI,EACjB,cAAc,GAAG,IAAI;QAErB,OAAO,IAAI,4BAA4B,CACnC,QAAQ,EACR,sBAAS,CAAC,gBAAgB,EAC1B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EACxB,UAAU,EACV,cAAc,CACjB,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,yBAAyB,CACpC,QAAgB,EAChB,SAAoB,EACpB,UAAmB;QAEnB,MAAM,mBAAmB,GAAG;YACxB,UAAU,EAAE,KAAK;YACjB,iBAAiB,EAAE;gBACf,CAAC,SAAS,CAAC,EAAE,QAAQ;aACxB;SACJ,CAAC;QAEF,OAAO,UAAU;YACb,CAAC,CAAC,EAAE,GAAG,mBAAmB,EAAE,GAAG,qCAAyB,EAAE;YAC1D,CAAC,CAAC,mBAAmB,CAAC;IAC9B,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,UAAmB;QACnD,OAAO,UAAU;YACb,CAAC,CAAC,IAAA,sBAAU,EAAC,mBAAmB,CAAC;YACjC,CAAC,CAAC,mBAAmB,CAAC;IAC9B,CAAC;CACJ;AAxED,oEAwEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2022.11.23-1",
3
+ "version": "2022.11.23-2",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,6 +1,11 @@
1
- import apigateway = require("aws-cdk-lib/aws-apigateway");
2
1
  import { MediaType } from "../../types/mediatypes";
3
- import { MethodResponse, Model } from "aws-cdk-lib/aws-apigateway";
2
+ import {
3
+ JsonSchemaType,
4
+ JsonSchemaVersion,
5
+ JsonSchema,
6
+ MethodResponse,
7
+ Model,
8
+ } from "aws-cdk-lib/aws-apigateway";
4
9
  import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
5
10
 
6
11
  /**
@@ -25,20 +30,20 @@ $inputRoot.body
25
30
 
26
31
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
27
32
 
28
- // DEPRECATED
29
- const messageSchema: apigateway.JsonSchema = {
30
- schema: apigateway.JsonSchemaVersion.DRAFT4,
31
- type: apigateway.JsonSchemaType.OBJECT,
33
+ /// @deprecated
34
+ const messageSchema: JsonSchema = {
35
+ schema: JsonSchemaVersion.DRAFT4,
36
+ type: JsonSchemaType.OBJECT,
32
37
  description: "Response with message",
33
38
  properties: {
34
39
  message: {
35
- type: apigateway.JsonSchemaType.STRING,
40
+ type: JsonSchemaType.STRING,
36
41
  description: "Response message",
37
42
  },
38
43
  },
39
44
  };
40
45
 
41
- // DEPRECATED
46
+ /// @deprecated
42
47
  export const MessageModel = {
43
48
  contentType: MediaType.APPLICATION_JSON,
44
49
  modelName: "MessageResponseModel",
@@ -56,27 +61,28 @@ const InternalServerErrorResponse = JSON.stringify({
56
61
  const BadRequestMessage = "Bad request";
57
62
  const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
58
63
 
64
+ /// @deprecated
59
65
  export const BadRequestResponseTemplate = createResponses(
60
66
  MediaType.APPLICATION_JSON,
61
67
  BadRequestResponse
62
68
  );
69
+ /// @deprecated
63
70
  export const NotFoundResponseTemplate = createResponses(
64
71
  MediaType.APPLICATION_JSON,
65
72
  NotFoundResponse
66
73
  );
74
+ /// @deprecated
67
75
  export const XmlResponseTemplate = createResponses(
68
76
  MediaType.APPLICATION_XML,
69
77
  BODY_FROM_INPUT_PATH
70
78
  );
71
- export const SvgResponseTemplate = createResponses(
72
- MediaType.IMAGE_SVG,
73
- BODY_FROM_INPUT_PATH
74
- );
79
+ /// @deprecated
75
80
  export const InternalServerErrorResponseTemplate = createResponses(
76
81
  MediaType.APPLICATION_JSON,
77
82
  InternalServerErrorResponse
78
83
  );
79
84
 
85
+ /// @deprecated
80
86
  export function createResponses<T>(
81
87
  key: MediaType,
82
88
  value: T
@@ -127,4 +133,16 @@ export class DigitrafficMethodResponse {
127
133
  false
128
134
  );
129
135
  }
136
+
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
+ }
130
148
  }
@@ -53,7 +53,7 @@ export const RESPONSE_404_NOT_FOUND = {
53
53
  };
54
54
 
55
55
  /**
56
- * @Deprecated Use DigitrafficMethodResponse
56
+ * @deprecated Use DigitrafficMethodResponse
57
57
  */
58
58
  export function methodResponse(
59
59
  status: string,
@@ -69,7 +69,7 @@ export function methodResponse(
69
69
  }
70
70
 
71
71
  /**
72
- * @Deprecated Use DigitrafficMethodResponse
72
+ * @deprecated Use DigitrafficMethodResponse
73
73
  */
74
74
  export function corsMethod(response: MethodResponse): MethodResponse {
75
75
  return {
@@ -1,13 +1,17 @@
1
- import {MockIntegration, PassthroughBehavior, Resource} from "aws-cdk-lib/aws-apigateway";
2
- import {MediaType} from "../../types/mediatypes";
3
- import {corsMethod, RESPONSE_CORS_INTEGRATION} from "./responses";
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: '200',
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, mediaType: MediaType, response: string, enableCors = true, apiKeyRequired = true,
26
+ resource: Resource,
27
+ mediaType: MediaType,
28
+ response: string,
29
+ enableCors = true,
30
+ apiKeyRequired = true
23
31
  ) {
24
- const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, enableCors);
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
- ['GET', 'HEAD'].forEach((httpMethod) => {
47
+ ["GET", "HEAD"].forEach((httpMethod) => {
35
48
  resource.addMethod(httpMethod, this, {
36
49
  apiKeyRequired,
37
- methodResponses: [DigitrafficStaticIntegration.createMethodResponse(enableCors)],
50
+ methodResponses: [
51
+ DigitrafficStaticIntegration.createMethodResponse(
52
+ enableCors
53
+ ),
54
+ ],
38
55
  });
39
56
  });
40
57
  }
41
58
 
42
- static json<K>(resource: Resource, response: K, enableCors = true, apiKeyRequired = true) {
59
+ static json<K>(
60
+ resource: Resource,
61
+ response: K,
62
+ enableCors = true,
63
+ apiKeyRequired = true
64
+ ) {
43
65
  return new DigitrafficStaticIntegration(
44
- resource, MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired,
66
+ resource,
67
+ MediaType.APPLICATION_JSON,
68
+ JSON.stringify(response),
69
+ enableCors,
70
+ apiKeyRequired
45
71
  );
46
72
  }
47
73
 
48
- private static createIntegrationResponse(response: string, mediaType: MediaType, enableCors: boolean) {
74
+ private static createIntegrationResponse(
75
+ response: string,
76
+ mediaType: MediaType,
77
+ enableCors: boolean
78
+ ) {
49
79
  const integrationResponse = {
50
- statusCode: '200',
80
+ statusCode: "200",
51
81
  responseTemplates: {
52
82
  [mediaType]: response,
53
83
  },
54
84
  };
55
85
 
56
- return enableCors ? {...integrationResponse, ...RESPONSE_CORS_INTEGRATION} : integrationResponse;
86
+ return enableCors
87
+ ? { ...integrationResponse, ...RESPONSE_CORS_INTEGRATION }
88
+ : integrationResponse;
57
89
  }
58
90
 
59
91
  private static createMethodResponse(enableCors: boolean) {
60
- return enableCors ? corsMethod(METHOD_RESPONSE_200) : METHOD_RESPONSE_200;
92
+ return enableCors
93
+ ? corsMethod(METHOD_RESPONSE_200)
94
+ : METHOD_RESPONSE_200;
61
95
  }
62
96
  }