@digitraffic/common 2026.1.9-3 → 2026.1.13-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.
|
@@ -11,6 +11,7 @@ export declare class LambdaProxyResponseBuilder {
|
|
|
11
11
|
etag?: string;
|
|
12
12
|
fileName?: string;
|
|
13
13
|
timestamp?: Date;
|
|
14
|
+
location?: string;
|
|
14
15
|
compressBody: boolean;
|
|
15
16
|
status: number;
|
|
16
17
|
contentType: string;
|
|
@@ -25,6 +26,7 @@ export declare class LambdaProxyResponseBuilder {
|
|
|
25
26
|
withCompression(enabled?: boolean): LambdaProxyResponseBuilder;
|
|
26
27
|
withContentType(contentType: MediaType): LambdaProxyResponseBuilder;
|
|
27
28
|
withDebug(enabled?: boolean): LambdaProxyResponseBuilder;
|
|
29
|
+
withLocation(location: string): LambdaProxyResponseBuilder;
|
|
28
30
|
static internalError(error?: object | string): APIGatewayProxyResult;
|
|
29
31
|
static notImplemented(error?: object | string): APIGatewayProxyResult;
|
|
30
32
|
static badRequest(error?: object | string): APIGatewayProxyResult;
|
|
@@ -15,13 +15,14 @@ export class LambdaProxyResponseBuilder {
|
|
|
15
15
|
etag;
|
|
16
16
|
fileName;
|
|
17
17
|
timestamp;
|
|
18
|
+
location;
|
|
18
19
|
compressBody = false;
|
|
19
20
|
status = 200;
|
|
20
21
|
contentType = MediaType.APPLICATION_JSON;
|
|
21
22
|
debug = false;
|
|
22
23
|
sizeUncompressedBase64Bytes;
|
|
23
24
|
sizeCompressedBase64Bytes;
|
|
24
|
-
static create(body, isBase64Encoded = false) {
|
|
25
|
+
static create(body = "", isBase64Encoded = false) {
|
|
25
26
|
const builder = new LambdaProxyResponseBuilder();
|
|
26
27
|
if (body !== undefined) {
|
|
27
28
|
builder.withBody(body, isBase64Encoded);
|
|
@@ -76,6 +77,10 @@ export class LambdaProxyResponseBuilder {
|
|
|
76
77
|
this.debug = enabled;
|
|
77
78
|
return this;
|
|
78
79
|
}
|
|
80
|
+
withLocation(location) {
|
|
81
|
+
this.location = location;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
79
84
|
static internalError(error = "Internal Error") {
|
|
80
85
|
return LambdaProxyResponseBuilder.create().withError(error, 500).build();
|
|
81
86
|
}
|
|
@@ -99,11 +104,12 @@ export class LambdaProxyResponseBuilder {
|
|
|
99
104
|
: MediaType.APPLICATION_JSON);
|
|
100
105
|
}
|
|
101
106
|
build() {
|
|
102
|
-
|
|
107
|
+
const bodyNotRequired = [204, 301, 302, 303, 307, 308].includes(this.status);
|
|
108
|
+
if (!this.body && !bodyNotRequired) {
|
|
103
109
|
throw new Error("Body is required for LambdaResponseBuilder");
|
|
104
110
|
}
|
|
105
111
|
// This needs to be called before building the response as this might modify compressBody value
|
|
106
|
-
const maybeEncodedBody = this.encodeBody();
|
|
112
|
+
const maybeEncodedBody = this.body ? this.encodeBody() : "";
|
|
107
113
|
const response = {
|
|
108
114
|
statusCode: this.status,
|
|
109
115
|
headers: {
|
|
@@ -112,6 +118,7 @@ export class LambdaProxyResponseBuilder {
|
|
|
112
118
|
...(this.fileName
|
|
113
119
|
? { "Content-Disposition": `attachment; filename="${this.fileName}"` }
|
|
114
120
|
: {}),
|
|
121
|
+
...(this.location ? { Location: this.location } : {}),
|
|
115
122
|
...(this.timestamp
|
|
116
123
|
? { "Last-Modified": this.timestamp.toUTCString() }
|
|
117
124
|
: {}),
|
package/dist/utils/zod-utils.js
CHANGED
|
@@ -6,9 +6,7 @@ import { z } from "zod";
|
|
|
6
6
|
* Usage:
|
|
7
7
|
* const mySchema = z
|
|
8
8
|
* .object({
|
|
9
|
-
* myParameter:
|
|
10
|
-
* .zStringToDate("Invalid value of myParameter")
|
|
11
|
-
* .optional()
|
|
9
|
+
* myParameter: zStringToDate("Invalid value of myParameter").optional()
|
|
12
10
|
* });
|
|
13
11
|
*
|
|
14
12
|
*/
|
|
@@ -16,7 +14,7 @@ export function zStringToNumber(message) {
|
|
|
16
14
|
return z
|
|
17
15
|
.string()
|
|
18
16
|
.transform(Number)
|
|
19
|
-
.refine((
|
|
17
|
+
.refine((number) => !Number.isNaN(number), {
|
|
20
18
|
message: message ? message : "Not a number",
|
|
21
19
|
});
|
|
22
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.1.13-1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"repository": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"./dist/utils/retry": "./dist/utils/retry.js",
|
|
48
48
|
"./dist/utils/geometry": "./dist/utils/geometry.js",
|
|
49
49
|
"./dist/utils/lambda-proxy-event": "./dist/utils/lambda-proxy-event.js",
|
|
50
|
+
"./dist/utils/zod-utils": "./dist/utils/zod-utils.js",
|
|
50
51
|
"./dist/aws/infra/sqs-integration": "./dist/aws/infra/sqs-integration.js",
|
|
51
52
|
"./dist/aws/infra/stacks/network-stack": "./dist/aws/infra/stacks/network-stack.js",
|
|
52
53
|
"./dist/aws/infra/stacks/db-stack": "./dist/aws/infra/stacks/db-stack.js",
|
|
@@ -129,7 +130,7 @@
|
|
|
129
130
|
"@types/lodash-es": "4.17.12",
|
|
130
131
|
"@types/madge": "5.0.3",
|
|
131
132
|
"@types/node": "22.19.3",
|
|
132
|
-
"aws-cdk-lib": "2.234.
|
|
133
|
+
"aws-cdk-lib": "2.234.1",
|
|
133
134
|
"change-case": "5.4.4",
|
|
134
135
|
"constructs": "10.4.4",
|
|
135
136
|
"date-fns": "4.1.0",
|