@digitraffic/common 2024.9.24-3 → 2024.10.4-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.
@@ -24,16 +24,17 @@ describe("integration tests", () => {
24
24
  }
25
25
  },
26
26
  input: {
27
- path: () => ({}),
28
27
  params: () => ({
29
- p1: "path1",
30
- q1: "query1",
31
- q2: "query2",
32
- h1: "header1",
28
+ header: {
29
+ h1: "header1",
30
+ },
33
31
  querystring: {
34
- qs1: "querystring1",
35
- qs2: "querystring2"
36
- }
32
+ q1: "querystring1",
33
+ q2: "querystring2"
34
+ },
35
+ path: {
36
+ p1: "path1"
37
+ },
37
38
  })
38
39
  },
39
40
  util: {
@@ -66,7 +67,17 @@ describe("integration tests", () => {
66
67
  .addQueryParameter("q1");
67
68
  const t = createTemplate(i);
68
69
  expect(t).toEqual({
69
- q1: "query1"
70
+ q1: "querystring1"
71
+ });
72
+ });
73
+ test("two query parameters", () => {
74
+ const i = createIntegration()
75
+ .addQueryParameter("q1")
76
+ .addQueryParameter("q2");
77
+ const t = createTemplate(i);
78
+ expect(t).toEqual({
79
+ q1: "querystring1",
80
+ q2: "querystring2"
70
81
  });
71
82
  });
72
83
  test("multivaluequery parameter", () => {
@@ -82,8 +93,8 @@ describe("integration tests", () => {
82
93
  .passAllQueryParameters();
83
94
  const t = createTemplate(i);
84
95
  expect(t).toEqual({
85
- qs1: "querystring1",
86
- qs2: "querystring2"
96
+ q1: "querystring1",
97
+ q2: "querystring2"
87
98
  });
88
99
  });
89
100
  test("path parameter", () => {
@@ -108,9 +119,9 @@ describe("integration tests", () => {
108
119
  .addHeaderParameter("h1");
109
120
  const t = createTemplate(i);
110
121
  expect(t).toEqual({
111
- "h1": "header1",
112
- qs1: "querystring1",
113
- qs2: "querystring2"
122
+ h1: "header1",
123
+ q1: "querystring1",
124
+ q2: "querystring2"
114
125
  });
115
126
  });
116
127
  test("all parameters & parameter - fail", () => {
@@ -127,8 +138,8 @@ describe("integration tests", () => {
127
138
  const t = createTemplate(i);
128
139
  expect(t).toEqual({
129
140
  p1: "path1",
130
- qs1: "querystring1",
131
- qs2: "querystring2"
141
+ q1: "querystring1",
142
+ q2: "querystring2"
132
143
  });
133
144
  });
134
145
  });
@@ -1,3 +1,4 @@
1
+ import { Model } from "aws-cdk-lib/aws-apigateway";
1
2
  import { DigitrafficStaticIntegration } from "../../../aws/infra/api/static-integration.js";
2
3
  import { MediaType } from "../../../aws/types/mediatypes.js";
3
4
  describe("response tests", () => {
@@ -15,9 +16,14 @@ describe("response tests", () => {
15
16
  });
16
17
  it("createMethodResponse works", () => {
17
18
  const methodResponse = DigitrafficStaticIntegration.createMethodResponse({
18
- "test-header": "test-value",
19
- });
19
+ "test-header": "test-value"
20
+ }, MediaType.TEXT_PLAIN, Model.EMPTY_MODEL);
20
21
  expect(methodResponse).toEqual({
22
+ responseModels: {
23
+ "text/plain": {
24
+ modelId: "Empty"
25
+ }
26
+ },
21
27
  responseParameters: {
22
28
  "method.response.header.test-header": true,
23
29
  },
@@ -88,8 +88,14 @@ export class DigitrafficIntegration {
88
88
  // make multivaluequerystring values to array
89
89
  parameterAssignments.push(`#set($tmp = $paramMap.put('_${parameter.name}', $util.parseJson($method.request.multivaluequerystring['${parameter.name}'])))`);
90
90
  }
91
+ else if (parameter.type === "path") {
92
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($input.params().path['${parameter.name}'])))`);
93
+ }
94
+ else if (parameter.type === "header") {
95
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($input.params().header['${parameter.name}'])))`);
96
+ }
91
97
  else {
92
- parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($input.params()['${parameter.name}'])))`);
98
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($params['${parameter.name}'])))`);
93
99
  }
94
100
  });
95
101
  // parameters starting with _ will be handled as json, and will not be in quotes
@@ -1,4 +1,4 @@
1
- import { type IntegrationResponse, type MethodResponse, MockIntegration, type Resource } from "aws-cdk-lib/aws-apigateway";
1
+ import { type IModel, type IntegrationResponse, type MethodResponse, MockIntegration, type Resource } from "aws-cdk-lib/aws-apigateway";
2
2
  import { MediaType } from "../../types/mediatypes.js";
3
3
  /**
4
4
  * Static integration, that returns the given response with given mediaType from given resource.
@@ -8,8 +8,8 @@ import { MediaType } from "../../types/mediatypes.js";
8
8
  * @param response
9
9
  */
10
10
  export declare class DigitrafficStaticIntegration extends MockIntegration {
11
- constructor(resource: Resource, mediaType: MediaType, response: string, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>);
12
- static json<K>(resource: Resource, response: K, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>): DigitrafficStaticIntegration;
11
+ constructor(resource: Resource, mediaType: MediaType, response: string, model: IModel, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>);
12
+ static json<K>(resource: Resource, response: K, model: IModel, enableCors?: boolean, apiKeyRequired?: boolean, headers?: Record<string, string>): DigitrafficStaticIntegration;
13
13
  static createIntegrationResponse(response: string, mediaType: MediaType, headers?: Record<string, string>): IntegrationResponse;
14
- static createMethodResponse(headers: Record<string, string>): MethodResponse;
14
+ static createMethodResponse(headers: Record<string, string>, mediaType: MediaType, model: IModel): MethodResponse;
15
15
  }
@@ -1,4 +1,4 @@
1
- import { MockIntegration, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
1
+ import { MockIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
2
2
  import { MediaType } from "../../types/mediatypes.js";
3
3
  const INTEGRATION_RESPONSE_200 = `{
4
4
  "statusCode": 200
@@ -11,7 +11,7 @@ const INTEGRATION_RESPONSE_200 = `{
11
11
  * @param response
12
12
  */
13
13
  export class DigitrafficStaticIntegration extends MockIntegration {
14
- constructor(resource, mediaType, response, enableCors = true, apiKeyRequired = true, headers = {}) {
14
+ constructor(resource, mediaType, response, model, enableCors = true, apiKeyRequired = true, headers = {}) {
15
15
  if (enableCors) {
16
16
  headers = { ...headers, "Access-Control-Allow-Origin": "*" };
17
17
  }
@@ -26,12 +26,12 @@ export class DigitrafficStaticIntegration extends MockIntegration {
26
26
  ["GET", "HEAD"].forEach((httpMethod) => {
27
27
  resource.addMethod(httpMethod, this, {
28
28
  apiKeyRequired,
29
- methodResponses: [DigitrafficStaticIntegration.createMethodResponse(headers)],
29
+ methodResponses: [DigitrafficStaticIntegration.createMethodResponse(headers, mediaType, model)],
30
30
  });
31
31
  });
32
32
  }
33
- static json(resource, response, enableCors = true, apiKeyRequired = true, headers = {}) {
34
- return new DigitrafficStaticIntegration(resource, MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired, headers);
33
+ static json(resource, response, model, enableCors = true, apiKeyRequired = true, headers = {}) {
34
+ return new DigitrafficStaticIntegration(resource, MediaType.APPLICATION_JSON, JSON.stringify(response), model, enableCors, apiKeyRequired, headers);
35
35
  }
36
36
  static createIntegrationResponse(response, mediaType, headers = {}) {
37
37
  const params = mapRecord(headers, (entry) => ["method.response.header." + entry[0], `'${entry[1]}'`]);
@@ -43,12 +43,15 @@ export class DigitrafficStaticIntegration extends MockIntegration {
43
43
  responseParameters: params,
44
44
  };
45
45
  }
46
- static createMethodResponse(headers) {
46
+ static createMethodResponse(headers, mediaType, model) {
47
47
  const allowedHeaders = Object.keys(headers);
48
48
  const entries = Object.fromEntries(allowedHeaders.map((key) => [key, true]));
49
49
  return {
50
50
  statusCode: "200",
51
51
  responseParameters: prefixKeys("method.response.header.", entries),
52
+ responseModels: {
53
+ [mediaType]: model
54
+ }
52
55
  };
53
56
  }
54
57
  }
@@ -1,5 +1,3 @@
1
- //import { APIGatewayClient, GetApiKeyCommand } from "@aws-sdk/client-api-gateway";
2
- //import type { GetApiKeyCommandOutput } from "@aws-sdk/client-api-gateway";
3
1
  import { APIGateway } from "aws-sdk";
4
2
  export async function getApiKeyFromAPIGateway(keyId) {
5
3
  const ag = new APIGateway();
@@ -7,15 +5,6 @@ export async function getApiKeyFromAPIGateway(keyId) {
7
5
  .getApiKey({
8
6
  apiKey: keyId,
9
7
  includeValue: true,
10
- })
11
- .promise();
12
- /*
13
- const client = new APIGatewayClient();
14
- const command = new GetApiKeyCommand({
15
- apiKey: keyId,
16
- includeValue: true,
17
- });
18
-
19
- return client.send(command);*/
8
+ }).promise();
20
9
  }
21
10
  //# sourceMappingURL=apikey.js.map
@@ -3,7 +3,3 @@ export declare enum EnvKeys {
3
3
  SECRET_ID = "SECRET_ID",
4
4
  SECRET_OVERRIDE_AWS_REGION = "SECRET_OVERRIDE_AWS_REGION"
5
5
  }
6
- /**
7
- * @deprecated Use digitraffic/common/utils/utils#getEnvVariable
8
- */
9
- export declare function envValue(key: string, defaultValue?: string): string;
@@ -4,17 +4,4 @@ export var EnvKeys;
4
4
  EnvKeys["SECRET_ID"] = "SECRET_ID";
5
5
  EnvKeys["SECRET_OVERRIDE_AWS_REGION"] = "SECRET_OVERRIDE_AWS_REGION";
6
6
  })(EnvKeys || (EnvKeys = {}));
7
- /**
8
- * @deprecated Use digitraffic/common/utils/utils#getEnvVariable
9
- */
10
- export function envValue(key, defaultValue) {
11
- const value = process.env[key];
12
- if (value === null || value === undefined) {
13
- if (defaultValue) {
14
- return defaultValue;
15
- }
16
- throw new Error(`Missing environment value ${key}`);
17
- }
18
- return value;
19
- }
20
7
  //# sourceMappingURL=environment.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.9.24-3",
3
+ "version": "2024.10.4-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -104,69 +104,69 @@
104
104
  "./dist/aws/runtime/digitraffic-integration-response": "./dist/aws/runtime/digitraffic-integration-response.js"
105
105
  },
106
106
  "peerDependencies": {
107
- "@aws-sdk/client-api-gateway": "^3.624.0",
108
- "@aws-sdk/client-s3": "^3.627.0",
109
- "@aws-sdk/client-secrets-manager": "^3.624.0",
110
- "@aws-sdk/client-sns": "^3.624.0",
111
- "@aws-sdk/lib-storage": "^3.627.0",
112
- "aws-cdk-lib": "^2.151.0",
113
- "aws-sdk": "^2.1670.0",
107
+ "@aws-sdk/client-api-gateway": "^3.664.0",
108
+ "@aws-sdk/client-s3": "^3.664.0",
109
+ "@aws-sdk/client-secrets-manager": "^3.664.0",
110
+ "@aws-sdk/client-sns": "^3.664.0",
111
+ "@aws-sdk/lib-storage": "^3.664.0",
112
+ "aws-cdk-lib": "^2.161.0",
113
+ "aws-sdk": "^2.1691.0",
114
114
  "change-case": "^5.4.4",
115
115
  "constructs": "~10.3.0",
116
- "date-fns": "~3.6.0",
117
- "date-fns-tz": "~3.1.3",
116
+ "date-fns": "3.6.0",
117
+ "date-fns-tz": "3.2.0",
118
118
  "etag": "^1.8.1",
119
119
  "geojson-validation": "^1.0.2",
120
- "ky": "^1.5.0",
120
+ "ky": "^1.7.2",
121
121
  "lodash-es": "~4.17.21",
122
122
  "node-ttl": "^0.2.0",
123
- "pg-native": "^3.1.0",
123
+ "pg-native": "^3.2.0",
124
124
  "pg-promise": "^11.9.1",
125
125
  "zod": "~3.23.8"
126
126
  },
127
127
  "devDependencies": {
128
- "@aws-sdk/client-api-gateway": "^3.637.0",
129
- "@aws-sdk/client-s3": "^3.637.0",
130
- "@aws-sdk/client-secrets-manager": "^3.637.0",
131
- "@aws-sdk/client-sns": "^3.637.0",
132
- "@aws-sdk/lib-storage": "^3.637.0",
128
+ "@aws-sdk/client-api-gateway": "^3.664.0",
129
+ "@aws-sdk/client-s3": "^3.664.0",
130
+ "@aws-sdk/client-secrets-manager": "^3.664.0",
131
+ "@aws-sdk/client-sns": "^3.664.0",
132
+ "@aws-sdk/lib-storage": "^3.664.0",
133
133
  "@digitraffic/eslint-config": "^2.1.0",
134
134
  "@jest/globals": "^29.7.0",
135
135
  "@rushstack/eslint-config": "^3.7.1",
136
- "@rushstack/heft": "^0.67.0",
137
- "@rushstack/heft-jest-plugin": "^0.12.9",
138
- "@rushstack/heft-lint-plugin": "^0.4.1",
139
- "@rushstack/heft-typescript-plugin": "^0.5.25",
140
- "@smithy/types": "^3.3.0",
141
- "@types/aws-lambda": "8.10.143",
136
+ "@rushstack/heft": "^0.67.2",
137
+ "@rushstack/heft-jest-plugin": "^0.12.14",
138
+ "@rushstack/heft-lint-plugin": "^0.4.6",
139
+ "@rushstack/heft-typescript-plugin": "^0.5.30",
140
+ "@smithy/types": "^3.5.0",
141
+ "@types/aws-lambda": "8.10.145",
142
142
  "@types/etag": "^1.8.3",
143
143
  "@types/geojson": "7946.0.14",
144
144
  "@types/geojson-validation": "^1.0.3",
145
- "@types/jest": "29.5.12",
145
+ "@types/jest": "29.5.13",
146
146
  "@types/lodash-es": "4.17.7",
147
147
  "@types/madge": "5.0.3",
148
148
  "@types/node": "20.14.9",
149
149
  "@typescript-eslint/eslint-plugin": "~7.14.1",
150
150
  "@typescript-eslint/parser": "^7.18.0",
151
- "aws-cdk-lib": "^2.155.0",
152
- "aws-sdk": "^2.1686.0",
151
+ "aws-cdk-lib": "^2.161.0",
152
+ "aws-sdk": "^2.1691.0",
153
153
  "change-case": "^5.4.4",
154
154
  "constructs": "~10.3.0",
155
- "date-fns": "~3.6.0",
156
- "date-fns-tz": "~3.1.3",
157
- "eslint": "^8.57.0",
155
+ "date-fns": "3.6.0",
156
+ "date-fns-tz": "3.2.0",
157
+ "eslint": "^8.57.1",
158
158
  "eslint-config-prettier": "^9.1.0",
159
159
  "eslint-plugin-deprecation": "~3.0.0",
160
160
  "etag": "^1.8.1",
161
161
  "geojson-validation": "^1.0.2",
162
162
  "jest": "^29.7.0",
163
163
  "jest-junit": "^16.0.0",
164
- "ky": "^1.7.1",
164
+ "ky": "^1.7.2",
165
165
  "lodash": "^4.17.21",
166
166
  "lodash-es": "~4.17.21",
167
167
  "madge": "^8.0.0",
168
168
  "node-ttl": "^0.2.0",
169
- "pg-native": "^3.1.0",
169
+ "pg-native": "^3.2.0",
170
170
  "pg-promise": "^11.9.1",
171
171
  "prettier": "^3.3.3",
172
172
  "rimraf": "^6.0.1",