@digitraffic/common 2026.1.13-1 → 2026.1.13-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,8 @@
1
1
  import type { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
2
2
  import { MediaType } from "./mediatypes.js";
3
3
  export declare const MAX_LAMBDA_PAYLOAD_BYTES: number;
4
+ export declare const REDIRECTION_HTTP_STATUS_CODES: readonly [301, 302, 303, 307, 308];
5
+ export type RedirectionStatusCode = (typeof REDIRECTION_HTTP_STATUS_CODES)[number];
4
6
  /**
5
7
  * Used to build APIGatewayProxyResult response for Lambda proxy integration.
6
8
  * Default status is 200, compressed = false and contentType is application/json.
@@ -32,6 +34,7 @@ export declare class LambdaProxyResponseBuilder {
32
34
  static badRequest(error?: object | string): APIGatewayProxyResult;
33
35
  static notFound(error?: object | string): APIGatewayProxyResult;
34
36
  static unauthorized(error?: object | string): APIGatewayProxyResult;
37
+ static redirect(path: string, status?: RedirectionStatusCode): APIGatewayProxyResult;
35
38
  private withError;
36
39
  build(): APIGatewayProxyResult;
37
40
  /**
@@ -5,6 +5,7 @@ import { StopWatch } from "../../utils/stop-watch.js";
5
5
  import { logger } from "../runtime/dt-logger-default.js";
6
6
  import { MediaType } from "./mediatypes.js";
7
7
  export const MAX_LAMBDA_PAYLOAD_BYTES = 6 * 1024 * 1024; // 6 MiB
8
+ export const REDIRECTION_HTTP_STATUS_CODES = [301, 302, 303, 307, 308];
8
9
  /**
9
10
  * Used to build APIGatewayProxyResult response for Lambda proxy integration.
10
11
  * Default status is 200, compressed = false and contentType is application/json.
@@ -96,6 +97,12 @@ export class LambdaProxyResponseBuilder {
96
97
  static unauthorized(error = "Unauthorized") {
97
98
  return LambdaProxyResponseBuilder.create().withError(error, 401).build();
98
99
  }
100
+ static redirect(path, status = 302) {
101
+ return LambdaProxyResponseBuilder.create()
102
+ .withLocation(path)
103
+ .withStatus(status)
104
+ .build();
105
+ }
99
106
  withError(error, status) {
100
107
  return this.withStatus(status)
101
108
  .withBody(error)
@@ -104,7 +111,7 @@ export class LambdaProxyResponseBuilder {
104
111
  : MediaType.APPLICATION_JSON);
105
112
  }
106
113
  build() {
107
- const bodyNotRequired = [204, 301, 302, 303, 307, 308].includes(this.status);
114
+ const bodyNotRequired = [204, ...REDIRECTION_HTTP_STATUS_CODES].includes(this.status);
108
115
  if (!this.body && !bodyNotRequired) {
109
116
  throw new Error("Body is required for LambdaResponseBuilder");
110
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2026.1.13-1",
3
+ "version": "2026.1.13-2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "repository": {