@digitraffic/common 2024.11.29-1 → 2024.12.10-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.
@@ -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;
@@ -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] != '_')
@@ -8,6 +8,10 @@ import type { DigitrafficStack } from "./stack/stack.js";
8
8
  */
9
9
  export declare class DigitrafficSqsQueue extends Queue {
10
10
  static create(stack: DigitrafficStack, name: string, props: QueueProps): DigitrafficSqsQueue;
11
+ /**
12
+ * Create a fifo with given name. No DLQ created!
13
+ */
14
+ static createFifo(stack: DigitrafficStack, name: string, props: QueueProps): DigitrafficSqsQueue;
11
15
  }
12
16
  export declare class DigitrafficDLQueue {
13
17
  static create(stack: DigitrafficStack, name: string): DigitrafficSqsQueue;
@@ -34,18 +34,28 @@ export class DigitrafficSqsQueue extends Queue {
34
34
  const queueName = `${stack.configuration.shortName}-${name}-Queue`;
35
35
  const queueProps = {
36
36
  ...props,
37
- ...{
38
- encryption: QueueEncryption.KMS_MANAGED,
39
- queueName,
40
- deadLetterQueue: props.deadLetterQueue ?? {
41
- maxReceiveCount: 2,
42
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
43
- queue: DigitrafficDLQueue.create(stack, name),
44
- },
37
+ encryption: QueueEncryption.KMS_MANAGED,
38
+ queueName,
39
+ deadLetterQueue: props.deadLetterQueue ?? {
40
+ maxReceiveCount: 2,
41
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
42
+ queue: DigitrafficDLQueue.create(stack, name),
45
43
  },
46
44
  };
47
45
  return new DigitrafficSqsQueue(stack, queueName, queueProps);
48
46
  }
47
+ /**
48
+ * Create a fifo with given name. No DLQ created!
49
+ */
50
+ static createFifo(stack, name, props) {
51
+ const queueName = `${stack.configuration.shortName}-${name}-Queue.fifo`;
52
+ const queueProps = {
53
+ ...props,
54
+ encryption: QueueEncryption.KMS_MANAGED,
55
+ queueName
56
+ };
57
+ return new DigitrafficSqsQueue(stack, queueName, queueProps);
58
+ }
49
59
  }
50
60
  export class DigitrafficDLQueue {
51
61
  static create(stack, name) {
@@ -21,19 +21,23 @@ export declare class LambdaResponse {
21
21
  /**
22
22
  * Create LambdaResponse for HTTP 400
23
23
  */
24
- static badRequest(body: string): LambdaResponse;
24
+ static badRequest(error: string): LambdaResponse;
25
25
  /**
26
26
  * Create LambdaResponse for HTTP 404
27
27
  */
28
- static notFound(): LambdaResponse;
28
+ static notFound(error?: string): LambdaResponse;
29
29
  /**
30
30
  * Create LambdaResponse for HTTP 500
31
31
  */
32
- static internalError(): LambdaResponse;
32
+ static internalError(error?: string): LambdaResponse;
33
+ /**
34
+ * Create LambdaResponse for HTTP 401
35
+ */
36
+ static unauthorized(error?: string): LambdaResponse;
33
37
  /**
34
38
  * Create LambdaResponse for HTTP 501
35
39
  */
36
- static notImplemented(): LambdaResponse;
40
+ static notImplemented(error?: string): LambdaResponse;
37
41
  private static createForString;
38
42
  private static createForBase64;
39
43
  }
@@ -36,26 +36,32 @@ export class LambdaResponse {
36
36
  /**
37
37
  * Create LambdaResponse for HTTP 400
38
38
  */
39
- static badRequest(body) {
40
- return this.createForString(400, body);
39
+ static badRequest(error) {
40
+ return this.createForString(400, error);
41
41
  }
42
42
  /**
43
43
  * Create LambdaResponse for HTTP 404
44
44
  */
45
- static notFound() {
46
- return this.createForString(404, "Not found");
45
+ static notFound(error = "Not found") {
46
+ return this.createForString(404, error);
47
47
  }
48
48
  /**
49
49
  * Create LambdaResponse for HTTP 500
50
50
  */
51
- static internalError() {
52
- return this.createForString(500, "Internal error");
51
+ static internalError(error = "Internal error") {
52
+ return this.createForString(500, error);
53
+ }
54
+ /**
55
+ * Create LambdaResponse for HTTP 401
56
+ */
57
+ static unauthorized(error = "Unauthorized") {
58
+ return this.createForString(401, error);
53
59
  }
54
60
  /**
55
61
  * Create LambdaResponse for HTTP 501
56
62
  */
57
- static notImplemented() {
58
- return this.createForString(501, "Not implemented");
63
+ static notImplemented(error = "Not implemented") {
64
+ return this.createForString(501, error);
59
65
  }
60
66
  static createForString(status, body, fileName) {
61
67
  return this.createForBase64(status, toBase64(body), fileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.11.29-1",
3
+ "version": "2024.12.10-2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {