@digitraffic/common 2024.11.13-1 → 2024.12.10-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.
package/README.md CHANGED
@@ -72,3 +72,4 @@ const lambda = MonitoredDBFunction.create(stack, 'get-metadata');
72
72
  ```
73
73
 
74
74
  See the documentation for more information.
75
+
@@ -43,7 +43,10 @@ describe("integration tests", () => {
43
43
  parseJson: (data) => JSON.stringify(data)
44
44
  },
45
45
  context: {
46
- c1: "context1"
46
+ c1: "context1",
47
+ authorizer: {
48
+ c2: "context2"
49
+ }
47
50
  }
48
51
  });
49
52
  }
@@ -113,6 +116,14 @@ describe("integration tests", () => {
113
116
  c1: "context1"
114
117
  });
115
118
  });
119
+ test("context parameter authorizer", () => {
120
+ const i = createIntegration()
121
+ .addContextParameter("authorizer.c2");
122
+ const t = createTemplate(i);
123
+ expect(t).toEqual({
124
+ "authorizer.c2": "context2"
125
+ });
126
+ });
116
127
  test("all parameters and header", () => {
117
128
  const i = createIntegration()
118
129
  .passAllQueryParameters()
@@ -12,8 +12,14 @@ export declare class DigitrafficIntegration<T extends string> {
12
12
  readonly parameters: ApiParameter[];
13
13
  readonly sunset?: string;
14
14
  _passAllQueryParameters: boolean;
15
+ _passBody: boolean;
15
16
  constructor(lambda: IFunction, mediaType?: MediaType, sunset?: string);
16
17
  passAllQueryParameters(): this;
18
+ /**
19
+ * Body is passed as an escaped string, so broken input won't break anything. You should
20
+ * parse and validate the input in the lambda.
21
+ */
22
+ passBody(): this;
17
23
  addPathParameter(...names: T[]): this;
18
24
  addQueryParameter(...names: T[]): this;
19
25
  addMultiValueQueryParameter(...names: T[]): this;
@@ -4,17 +4,20 @@ import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integr
4
4
  const VELOCITY_ALL_PARAMS = `#foreach($paramName in $params.keySet())
5
5
  #set($tmp = $paramMap.put($paramName, $params[$paramName]))
6
6
  #end`;
7
+ const VELOCITY_PASS_BODY = `#set($tmp = $paramMap.put('body', $util.escapeJavaScript($input.json('$'))))`;
7
8
  export class DigitrafficIntegration {
8
9
  lambda;
9
10
  mediaType;
10
11
  parameters = [];
11
12
  sunset;
12
13
  _passAllQueryParameters;
14
+ _passBody;
13
15
  constructor(lambda, mediaType = MediaType.TEXT_PLAIN, sunset) {
14
16
  this.lambda = lambda;
15
17
  this.mediaType = mediaType;
16
18
  this.sunset = sunset;
17
19
  this._passAllQueryParameters = false;
20
+ this._passBody = false;
18
21
  }
19
22
  passAllQueryParameters() {
20
23
  if (this.parameters.some((p) => p.type === "querystring"))
@@ -22,6 +25,14 @@ export class DigitrafficIntegration {
22
25
  this._passAllQueryParameters = true;
23
26
  return this;
24
27
  }
28
+ /**
29
+ * Body is passed as an escaped string, so broken input won't break anything. You should
30
+ * parse and validate the input in the lambda.
31
+ */
32
+ passBody() {
33
+ this._passBody = true;
34
+ return this;
35
+ }
25
36
  addPathParameter(...names) {
26
37
  names.forEach((name) => this.parameters.push({ type: "path", name }));
27
38
  return this;
@@ -81,7 +92,7 @@ export class DigitrafficIntegration {
81
92
  const parameterAssignments = [];
82
93
  this.parameters.forEach((parameter) => {
83
94
  if (parameter.type === "context") {
84
- parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($context['${parameter.name}'])))`);
95
+ parameterAssignments.push(`#set($tmp = $paramMap.put('${parameter.name}', $util.escapeJavaScript($context.${parameter.name})))`);
85
96
  }
86
97
  else if (parameter.type === "multivaluequerystring") {
87
98
  // make multivaluequerystring values to array
@@ -105,6 +116,7 @@ export class DigitrafficIntegration {
105
116
  #set($params = $input.params().get("querystring"))
106
117
  ${parameterAssignments.join("\n")}
107
118
  ${this._passAllQueryParameters ? VELOCITY_ALL_PARAMS : ""}
119
+ ${this._passBody ? VELOCITY_PASS_BODY : ""}
108
120
  {
109
121
  #foreach($paramName in $paramMap.keySet())
110
122
  #if( $paramName[0] != '_')
@@ -125,10 +125,6 @@ async function retryRecursive(asyncFn, retries, retryCountInj, logError, timeout
125
125
  */
126
126
  export async function retry(asyncFn, retries = 3, logError = RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS, timeoutBetweenRetries = timeoutFunctions.noTimeout, retryPredicate = retryPredicates.alwaysRetry) {
127
127
  retryCount = 0;
128
- logger.debug({
129
- message: `Retrying with ${retries} retries`,
130
- method: "retry.retry",
131
- });
132
128
  return retryRecursive(asyncFn, retries, 0, logError, timeoutBetweenRetries, retryPredicate);
133
129
  }
134
130
  function wrapArgsToFn(fn, ...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.11.13-1",
3
+ "version": "2024.12.10-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -104,36 +104,37 @@
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.667.0",
108
- "@aws-sdk/client-s3": "^3.667.0",
109
- "@aws-sdk/client-secrets-manager": "^3.667.0",
110
- "@aws-sdk/client-sns": "^3.667.0",
111
- "@aws-sdk/lib-storage": "^3.667.0",
107
+ "@aws-sdk/client-api-gateway": "^3.687.0",
108
+ "@aws-sdk/client-s3": "^3.687.0",
109
+ "@aws-sdk/client-secrets-manager": "^3.687.0",
110
+ "@aws-sdk/client-sns": "^3.687.0",
111
+ "@aws-sdk/lib-storage": "^3.687.0",
112
+ "@date-fns/tz": "1.2.0",
112
113
  "@smithy/fetch-http-handler": "3.2.9",
113
- "aws-cdk-lib": "^2.161.1",
114
+ "aws-cdk-lib": "^2.166.0",
114
115
  "change-case": "^5.4.4",
115
- "constructs": "~10.3.0",
116
+ "constructs": "~10.4.2",
116
117
  "date-fns": "~4.1.0",
117
- "@date-fns/tz": "1.1.2",
118
118
  "etag": "^1.8.1",
119
119
  "geojson-validation": "^1.0.2",
120
120
  "ky": "^1.7.2",
121
- "lodash-es": "~4.17.21",
121
+ "lodash-es": "^4.17.21",
122
122
  "node-ttl": "^0.2.0",
123
123
  "pg-native": "^3.2.0",
124
- "pg-promise": "^11.9.1",
125
- "zod": "~3.23.8"
124
+ "pg-promise": "^11.10.1",
125
+ "zod": "^3.23.8"
126
126
  },
127
127
  "devDependencies": {
128
- "@aws-sdk/client-api-gateway": "^3.669.0",
129
- "@aws-sdk/client-s3": "^3.669.0",
130
- "@aws-sdk/client-secrets-manager": "^3.669.0",
131
- "@aws-sdk/client-sns": "^3.669.0",
132
- "@aws-sdk/lib-storage": "^3.669.0",
128
+ "@aws-sdk/client-api-gateway": "^3.687.0",
129
+ "@aws-sdk/client-s3": "^3.687.0",
130
+ "@aws-sdk/client-secrets-manager": "^3.687.0",
131
+ "@aws-sdk/client-sns": "^3.687.0",
132
+ "@aws-sdk/lib-storage": "^3.687.0",
133
+ "@date-fns/tz": "1.2.0",
133
134
  "@digitraffic/eslint-config": "^3.0.1",
134
135
  "@jest/globals": "^29.7.0",
135
136
  "@rushstack/eslint-config": "^3.7.1",
136
- "@rushstack/heft": "^0.68.2",
137
+ "@rushstack/heft": "^0.68.6",
137
138
  "@rushstack/heft-jest-plugin": "^0.12.18",
138
139
  "@rushstack/heft-lint-plugin": "^0.5.0",
139
140
  "@rushstack/heft-typescript-plugin": "^0.5.35",
@@ -143,18 +144,17 @@
143
144
  "@types/etag": "^1.8.3",
144
145
  "@types/geojson": "7946.0.14",
145
146
  "@types/geojson-validation": "^1.0.3",
146
- "@types/jest": "29.5.13",
147
+ "@types/jest": "29.5.14",
147
148
  "@types/lodash-es": "4.17.12",
148
149
  "@types/madge": "5.0.3",
149
- "@types/node": "20.14.9",
150
+ "@types/node": "20.17.6",
150
151
  "@typescript-eslint/eslint-plugin": "~7.14.1",
151
152
  "@typescript-eslint/parser": "^7.18.0",
152
- "aws-cdk-lib": "^2.162.0",
153
- "aws-sdk": "^2.1691.0",
153
+ "aws-cdk-lib": "^2.166.0",
154
+ "aws-sdk": "^2.1692.0",
154
155
  "change-case": "^5.4.4",
155
- "constructs": "~10.3.1",
156
+ "constructs": "~10.4.2",
156
157
  "date-fns": "~4.1.0",
157
- "@date-fns/tz": "1.1.2",
158
158
  "eslint": "^8.57.1",
159
159
  "eslint-config-prettier": "^9.1.0",
160
160
  "eslint-plugin-deprecation": "~3.0.0",
@@ -168,7 +168,7 @@
168
168
  "madge": "^8.0.0",
169
169
  "node-ttl": "^0.2.0",
170
170
  "pg-native": "^3.2.0",
171
- "pg-promise": "^11.9.1",
171
+ "pg-promise": "^11.10.1",
172
172
  "prettier": "^3.3.3",
173
173
  "rimraf": "^6.0.1",
174
174
  "ts-jest": "^29.2.5",