@digitraffic/common 2025.10.29-2 → 2025.10.30-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.
Files changed (112) hide show
  1. package/README.md +2 -0
  2. package/dist/__test__/asserter.d.ts +8 -8
  3. package/dist/__test__/asserter.js +14 -14
  4. package/dist/__test__/db-testutils.d.ts +1 -1
  5. package/dist/__test__/db-testutils.js +1 -1
  6. package/dist/__test__/imports.test.js +4 -4
  7. package/dist/__test__/infra/acl-builder.test.js +15 -14
  8. package/dist/__test__/infra/api/handler-factory.test.js +1 -1
  9. package/dist/__test__/infra/api/integration.test.js +16 -25
  10. package/dist/__test__/infra/api/response.test.js +1 -2
  11. package/dist/__test__/infra/api/static-integration.test.js +1 -2
  12. package/dist/__test__/infra/scheduler.test.js +1 -1
  13. package/dist/__test__/infra/security-rule.test.js +1 -1
  14. package/dist/__test__/infra/stack/rest-apis.test.js +3 -3
  15. package/dist/__test__/marine/id_utils.test.js +2 -3
  16. package/dist/__test__/mock-ky.js +0 -1
  17. package/dist/__test__/promise/promise.test.js +5 -8
  18. package/dist/__test__/runtime/dt-logger.test.js +9 -12
  19. package/dist/__test__/secrets/secret-holder.test.js +7 -9
  20. package/dist/__test__/secrets/secret.test.js +6 -7
  21. package/dist/__test__/stack/rest-apis.test.js +1 -1
  22. package/dist/__test__/test/mock-ky.test.js +34 -12
  23. package/dist/__test__/types/lambda-response.test.js +1 -2
  24. package/dist/__test__/utils/date-utils.test.js +1 -1
  25. package/dist/__test__/utils/geometry.test.js +1 -1
  26. package/dist/__test__/utils/logging.test.js +1 -1
  27. package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
  28. package/dist/__test__/utils/stop-watch.test.js +118 -0
  29. package/dist/__test__/utils/utils.test.js +2 -5
  30. package/dist/aws/infra/acl-builder.js +3 -3
  31. package/dist/aws/infra/api/integration.d.ts +2 -1
  32. package/dist/aws/infra/api/integration.js +17 -6
  33. package/dist/aws/infra/api/response.d.ts +22 -7
  34. package/dist/aws/infra/api/response.js +29 -17
  35. package/dist/aws/infra/api/responses.d.ts +17 -1
  36. package/dist/aws/infra/api/responses.js +20 -9
  37. package/dist/aws/infra/api/static-integration.d.ts +2 -1
  38. package/dist/aws/infra/api/static-integration.js +5 -3
  39. package/dist/aws/infra/bucket-policy.js +3 -3
  40. package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
  41. package/dist/aws/infra/canaries/canary-role.js +1 -1
  42. package/dist/aws/infra/canaries/canary.d.ts +2 -2
  43. package/dist/aws/infra/canaries/canary.js +0 -1
  44. package/dist/aws/infra/canaries/database-canary.d.ts +2 -2
  45. package/dist/aws/infra/canaries/database-canary.js +2 -2
  46. package/dist/aws/infra/canaries/database-checker.js +6 -12
  47. package/dist/aws/infra/canaries/url-canary.js +2 -5
  48. package/dist/aws/infra/canaries/url-checker.d.ts +16 -16
  49. package/dist/aws/infra/canaries/url-checker.js +35 -44
  50. package/dist/aws/infra/documentation.d.ts +1 -1
  51. package/dist/aws/infra/documentation.js +2 -4
  52. package/dist/aws/infra/import-util.d.ts +2 -6
  53. package/dist/aws/infra/import-util.js +1 -6
  54. package/dist/aws/infra/scheduler.d.ts +1 -1
  55. package/dist/aws/infra/scheduler.js +1 -1
  56. package/dist/aws/infra/security-rule.d.ts +1 -1
  57. package/dist/aws/infra/sqs-integration.d.ts +1 -1
  58. package/dist/aws/infra/sqs-queue.d.ts +5 -4
  59. package/dist/aws/infra/sqs-queue.js +15 -15
  60. package/dist/aws/infra/stack/lambda-configs.d.ts +4 -3
  61. package/dist/aws/infra/stack/lambda-configs.js +1 -1
  62. package/dist/aws/infra/stack/lambda-log-group.d.ts +1 -1
  63. package/dist/aws/infra/stack/lambda-log-group.js +1 -2
  64. package/dist/aws/infra/stack/monitoredfunction.d.ts +8 -7
  65. package/dist/aws/infra/stack/monitoredfunction.js +12 -17
  66. package/dist/aws/infra/stack/parameters.d.ts +1 -1
  67. package/dist/aws/infra/stack/parameters.js +0 -1
  68. package/dist/aws/infra/stack/rest-api.d.ts +3 -2
  69. package/dist/aws/infra/stack/rest-api.js +5 -9
  70. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
  71. package/dist/aws/infra/stack/stack-checking-aspect.js +6 -8
  72. package/dist/aws/infra/stack/stack.d.ts +5 -4
  73. package/dist/aws/infra/stack/stack.js +6 -5
  74. package/dist/aws/infra/stack/subscription.d.ts +2 -2
  75. package/dist/aws/infra/stacks/db-dns-stack.d.ts +1 -1
  76. package/dist/aws/infra/stacks/db-dns-stack.js +1 -2
  77. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +3 -3
  78. package/dist/aws/infra/stacks/db-proxy-stack.js +3 -3
  79. package/dist/aws/infra/stacks/db-stack.d.ts +3 -2
  80. package/dist/aws/infra/stacks/db-stack.js +13 -11
  81. package/dist/aws/infra/stacks/network-stack.d.ts +3 -2
  82. package/dist/aws/infra/stacks/network-stack.js +1 -1
  83. package/dist/aws/infra/usage-plans.js +2 -2
  84. package/dist/aws/runtime/apikey.d.ts +1 -1
  85. package/dist/aws/runtime/apikey.js +1 -1
  86. package/dist/aws/runtime/digitraffic-integration-response.js +5 -4
  87. package/dist/aws/runtime/dt-logger.d.ts +1 -1
  88. package/dist/aws/runtime/dt-logger.js +17 -11
  89. package/dist/aws/runtime/s3.d.ts +2 -3
  90. package/dist/aws/runtime/s3.js +1 -2
  91. package/dist/aws/runtime/secrets/proxy-holder.js +3 -3
  92. package/dist/aws/runtime/secrets/rds-holder.js +3 -3
  93. package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
  94. package/dist/aws/runtime/secrets/secret-holder.js +3 -3
  95. package/dist/aws/types/lambda-response.js +10 -10
  96. package/dist/database/cached.js +3 -1
  97. package/dist/database/database.js +2 -6
  98. package/dist/marine/id_utils.js +6 -2
  99. package/dist/types/openapi-schema.js +10 -5
  100. package/dist/utils/api-model.d.ts +2 -2
  101. package/dist/utils/api-model.js +2 -2
  102. package/dist/utils/date-utils.js +1 -1
  103. package/dist/utils/geometry.js +9 -6
  104. package/dist/utils/logging.js +1 -3
  105. package/dist/utils/retry.js +12 -14
  106. package/dist/utils/stop-watch.d.ts +47 -0
  107. package/dist/utils/stop-watch.js +114 -0
  108. package/dist/utils/utils.d.ts +1 -9
  109. package/dist/utils/utils.js +7 -22
  110. package/package.json +3 -3
  111. package/dist/types/aws-env.d.ts +0 -3
  112. package/dist/types/aws-env.js +0 -2
@@ -1,5 +1,5 @@
1
- import { mockKyResponse } from "../../__test__/mock-ky.js";
2
1
  import { describe, jest, test } from "@jest/globals";
2
+ import { mockKyResponse } from "../../__test__/mock-ky.js";
3
3
  const ky = (await import("ky")).default;
4
4
  describe("mockKyResponse", () => {
5
5
  const testObj = { test: "data" };
@@ -9,36 +9,58 @@ describe("mockKyResponse", () => {
9
9
  jest.restoreAllMocks();
10
10
  });
11
11
  test("works with all methods", async () => {
12
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
13
- jest.spyOn(ky, "post").mockImplementation(() => mockKyResponse(200, testJson));
14
- jest.spyOn(ky, "put").mockImplementation(() => mockKyResponse(200, testJson));
15
- jest.spyOn(ky, "delete").mockImplementation(() => mockKyResponse(200, testJson));
12
+ jest
13
+ .spyOn(ky, "get")
14
+ .mockImplementation(() => mockKyResponse(200, testJson));
15
+ jest
16
+ .spyOn(ky, "post")
17
+ .mockImplementation(() => mockKyResponse(200, testJson));
18
+ jest
19
+ .spyOn(ky, "put")
20
+ .mockImplementation(() => mockKyResponse(200, testJson));
21
+ jest
22
+ .spyOn(ky, "delete")
23
+ .mockImplementation(() => mockKyResponse(200, testJson));
16
24
  expect(await ky.get(url).text()).toEqual(testJson);
17
25
  expect(await ky.put(url).text()).toEqual(testJson);
18
26
  expect(await ky.post(url).text()).toEqual(testJson);
19
27
  expect(await ky.delete(url).text()).toEqual(testJson);
20
28
  });
21
29
  test("returns correct status", async () => {
22
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
30
+ jest
31
+ .spyOn(ky, "get")
32
+ .mockImplementation(() => mockKyResponse(200, testJson));
23
33
  expect((await ky.get(url)).status).toEqual(200);
24
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(400, testJson));
34
+ jest
35
+ .spyOn(ky, "get")
36
+ .mockImplementation(() => mockKyResponse(400, testJson));
25
37
  expect((await ky.get(url)).status).toEqual(400);
26
38
  });
27
39
  test("returns correct ok", async () => {
28
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
40
+ jest
41
+ .spyOn(ky, "get")
42
+ .mockImplementation(() => mockKyResponse(200, testJson));
29
43
  expect((await ky.get(url)).ok).toEqual(true);
30
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(299, testJson));
44
+ jest
45
+ .spyOn(ky, "get")
46
+ .mockImplementation(() => mockKyResponse(299, testJson));
31
47
  expect((await ky.get(url)).ok).toEqual(true);
32
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(300, testJson));
48
+ jest
49
+ .spyOn(ky, "get")
50
+ .mockImplementation(() => mockKyResponse(300, testJson));
33
51
  expect((await ky.get(url)).ok).toEqual(false);
34
52
  });
35
53
  test("convenience methods work: text", async () => {
36
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
54
+ jest
55
+ .spyOn(ky, "get")
56
+ .mockImplementation(() => mockKyResponse(200, testJson));
37
57
  expect(await ky.get(url).text()).toEqual(testJson);
38
58
  expect(await (await ky.get(url)).text()).toEqual(testJson);
39
59
  });
40
60
  test("convenience methods work: json", async () => {
41
- jest.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
61
+ jest
62
+ .spyOn(ky, "get")
63
+ .mockImplementation(() => mockKyResponse(200, testJson));
42
64
  expect(await ky.get(url).json()).toEqual(testObj);
43
65
  expect(await (await ky.get(url)).json()).toEqual(testObj);
44
66
  });
@@ -31,8 +31,7 @@ describe("lambda-response", () => {
31
31
  assertJson(response, TEST_JSON, 200, TEST_FILENAME);
32
32
  });
33
33
  test("okJson - with fileName and timestamp", () => {
34
- const response = LambdaResponse.okJson(TEST_JSON, TEST_FILENAME)
35
- .withTimestamp(TEST_TIMESTAMP);
34
+ const response = LambdaResponse.okJson(TEST_JSON, TEST_FILENAME).withTimestamp(TEST_TIMESTAMP);
36
35
  assertJson(response, TEST_JSON, 200, TEST_FILENAME, TEST_TIMESTAMP);
37
36
  });
38
37
  test("okBinary - with fileName and timestamp", () => {
@@ -7,7 +7,7 @@ describe("CommonDateUtilsTest", () => {
7
7
  expect(parsed.toISOString()).toEqual(ISO);
8
8
  });
9
9
  test("dateFromIsoString fails", () => {
10
- expect(() => CommonDateUtils.dateFromIsoString(ISO + "foobar")).toThrow();
10
+ expect(() => CommonDateUtils.dateFromIsoString(`${ISO}foobar`)).toThrow();
11
11
  });
12
12
  test("countDiffMs", () => {
13
13
  const start = new Date();
@@ -1,5 +1,5 @@
1
- import { Asserter } from "../asserter.js";
2
1
  import * as Geometry from "../../utils/geometry.js";
2
+ import { Asserter } from "../asserter.js";
3
3
  const TAMPERE_WGS84_X = 23.761290078;
4
4
  const TAMPERE_WGS84_Y = 61.49774257;
5
5
  const KUOPIO_WGS84_X = 27.688935;
@@ -1,4 +1,4 @@
1
- import { Writable } from "stream";
1
+ import { Writable } from "node:stream";
2
2
  import { DtLogger } from "../../aws/runtime/dt-logger.js";
3
3
  import { logException } from "../../utils/logging.js";
4
4
  const TEST_METHODNAME = "test.logException";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ import { expect } from "@jest/globals";
2
+ import { StopWatch } from "../../utils/stop-watch.js";
3
+ describe("stop-watch.test.ts", () => {
4
+ test("StopWatch start-stop", async () => {
5
+ const sw = new StopWatch().start();
6
+ await sleepMs(100);
7
+ sw.stop();
8
+ expect(sw.getDuration()).toBeGreaterThanOrEqual(95);
9
+ expect(sw.getDuration()).toBeLessThan(150);
10
+ sw.logTasks("StopWatchTest.stopWatch");
11
+ });
12
+ test("StopWatch with tasks start-stop", async () => {
13
+ const sw = StopWatch.createStarted();
14
+ sw.start("task1");
15
+ await sleepMs(50);
16
+ sw.stop("task1").start("task2");
17
+ await sleepMs(100);
18
+ sw.stop("task2").stop();
19
+ // total duration should be ~150ms
20
+ expect(sw.getDuration()).toBeGreaterThanOrEqual(145);
21
+ expect(sw.getDuration()).toBeLessThan(160);
22
+ // individual tasks
23
+ expect(sw.getDuration("task1")).toBeGreaterThanOrEqual(45);
24
+ expect(sw.getDuration("task1")).toBeLessThan(60);
25
+ expect(sw.getDuration("task2")).toBeGreaterThanOrEqual(95);
26
+ expect(sw.getDuration("task2")).toBeLessThan(110);
27
+ sw.logTasks("StopWatchTest.tasks");
28
+ });
29
+ test("StopWatch task with periods", async () => {
30
+ const sw = StopWatch.createStarted();
31
+ // period 1
32
+ sw.start("task1");
33
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
34
+ expect(sw.getTask("task1")?.periods.length).toEqual(1);
35
+ await sleepMs(50);
36
+ // period 2
37
+ sw.start("task1");
38
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
39
+ expect(sw.getTask("task1")?.periods.length).toEqual(2);
40
+ await sleepMs(100);
41
+ sw.stop("task1");
42
+ expect(sw.getTask("task1")?.isRunning).toEqual(false);
43
+ expect(sw.getTask("task1")?.periods.length).toEqual(2);
44
+ expect(sw.getTask("task1")?.periods[0]?.duration).toBeGreaterThanOrEqual(45);
45
+ expect(sw.getTask("task1")?.periods[0]?.duration).toBeLessThan(60);
46
+ expect(sw.getTask("task1")?.periods[1]?.duration).toBeGreaterThanOrEqual(95);
47
+ expect(sw.getTask("task1")?.periods[1]?.duration).toBeLessThan(110);
48
+ expect(sw.getTask("task1")?.totalDuration).toBeGreaterThanOrEqual(145);
49
+ expect(sw.getTask("task1")?.totalDuration).toBeLessThan(160);
50
+ expect(sw.getDuration("task1")).toEqual(sw.getTask("task1")?.totalDuration);
51
+ sw.logTasks("StopWatchTest.periods");
52
+ });
53
+ test("StopWatch task with periods", async () => {
54
+ const sw = StopWatch.createStarted();
55
+ // period 1
56
+ sw.start("task1");
57
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
58
+ expect(sw.getTask("task1")?.periods.length).toEqual(1);
59
+ await sleepMs(50);
60
+ // period 2
61
+ sw.start("task1");
62
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
63
+ expect(sw.getTask("task1")?.periods.length).toEqual(2);
64
+ await sleepMs(100);
65
+ sw.stop("task1");
66
+ expect(sw.getTask("task1")?.isRunning).toEqual(false);
67
+ expect(sw.getTask("task1")?.periods.length).toEqual(2);
68
+ expect(sw.getTask("task1")?.periods[0]?.duration).toBeGreaterThanOrEqual(45);
69
+ expect(sw.getTask("task1")?.periods[0]?.duration).toBeLessThan(60);
70
+ expect(sw.getTask("task1")?.periods[1]?.duration).toBeGreaterThanOrEqual(95);
71
+ expect(sw.getTask("task1")?.periods[1]?.duration).toBeLessThan(110);
72
+ expect(sw.getTask("task1")?.totalDuration).toBeGreaterThanOrEqual(145);
73
+ expect(sw.getTask("task1")?.totalDuration).toBeLessThan(160);
74
+ expect(sw.getDuration("task1")).toEqual(sw.getTask("task1")?.totalDuration);
75
+ sw.logTasks("StopWatchTest.periods");
76
+ });
77
+ test("StopWatch task not stopped", async () => {
78
+ const sw = StopWatch.createStarted();
79
+ await sleepMs(50);
80
+ // period 1
81
+ sw.start("task1");
82
+ await sleepMs(50);
83
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
84
+ expect(sw.getDuration()).toBeGreaterThanOrEqual(95);
85
+ expect(sw.getDuration()).toBeLessThan(110);
86
+ expect(sw.getDuration("task1")).toBeGreaterThanOrEqual(45);
87
+ expect(sw.getDuration("task1")).toBeLessThan(55);
88
+ sw.logTasks("StopWatchTest.notStopped");
89
+ });
90
+ test("StopWatch reset", async () => {
91
+ const sw = StopWatch.createStarted();
92
+ await sleepMs(50);
93
+ // period 1
94
+ sw.start("task1");
95
+ sw.start("task2");
96
+ await sleepMs(50);
97
+ // reset tassk2 should not affect task1
98
+ sw.reset("task2");
99
+ expect(sw.getTask("task2")).toBeUndefined();
100
+ expect(sw.getTask("task1")?.isRunning).toEqual(true);
101
+ expect(sw.getDuration()).toBeGreaterThanOrEqual(95);
102
+ expect(sw.getDuration()).toBeLessThan(110);
103
+ expect(sw.getDuration("task1")).toBeGreaterThanOrEqual(45);
104
+ expect(sw.getDuration("task1")).toBeLessThan(55);
105
+ // Reset only task1
106
+ sw.reset("task1");
107
+ expect(sw.getTask("task1")).toBeUndefined();
108
+ expect(sw.getDuration()).toBeGreaterThanOrEqual(95);
109
+ expect(sw.getDuration()).toBeLessThan(110);
110
+ // Reset also default task
111
+ sw.reset();
112
+ expect(sw.getDuration()).toEqual(0);
113
+ });
114
+ });
115
+ function sleepMs(ms) {
116
+ return new Promise((resolve) => setTimeout(resolve, ms));
117
+ }
118
+ //# sourceMappingURL=stop-watch.test.js.map
@@ -11,8 +11,7 @@ describe("ArrayUtils", () => {
11
11
  expect(ArrayUtils.bothArraysHasSameValues(["a"], undefined)).toEqual(false);
12
12
  expect(ArrayUtils.bothArraysHasSameValues(["a"], null)).toEqual(false);
13
13
  expect(ArrayUtils.bothArraysHasSameValues(["a", "b"], ["a", "a"])).toEqual(false);
14
- expect(ArrayUtils.bothArraysHasSameValues(["a", "a", "a"], ["a", "b", "c"]))
15
- .toEqual(false);
14
+ expect(ArrayUtils.bothArraysHasSameValues(["a", "a", "a"], ["a", "b", "c"])).toEqual(false);
16
15
  const o1 = { a: 1, b: 2 };
17
16
  const o2 = { a: 1, b: 2 };
18
17
  // Objects are references to same
@@ -41,9 +40,7 @@ describe("ArrayUtils", () => {
41
40
  });
42
41
  test("isDefined", () => {
43
42
  expect([1, 2, undefined, null, 3].filter(ArrayUtils.isDefined)).toEqual([
44
- 1,
45
- 2,
46
- 3,
43
+ 1, 2, 3,
47
44
  ]);
48
45
  });
49
46
  });
@@ -1,6 +1,6 @@
1
1
  import { CfnIPSet, CfnWebACL } from "aws-cdk-lib/aws-wafv2";
2
- import { logger } from "../runtime/dt-logger-default.js";
3
2
  import { concat, range, zipWith } from "lodash-es";
3
+ import { logger } from "../runtime/dt-logger-default.js";
4
4
  /**
5
5
  * Builder class for building CfnWebACL.
6
6
  *
@@ -327,7 +327,7 @@ function createThrottleStatement(limit, isHeaderRequired, isBasedOnIpAndUriPath,
327
327
  aggregateKeyType: "CUSTOM_KEYS",
328
328
  customKeys: CUSTOM_KEYS_IP_AND_URI_PATH,
329
329
  limit: limit,
330
- scopeDownStatement
330
+ scopeDownStatement,
331
331
  },
332
332
  };
333
333
  }
@@ -335,7 +335,7 @@ function createThrottleStatement(limit, isHeaderRequired, isBasedOnIpAndUriPath,
335
335
  rateBasedStatement: {
336
336
  aggregateKeyType: "IP",
337
337
  limit: limit,
338
- scopeDownStatement
338
+ scopeDownStatement,
339
339
  },
340
340
  };
341
341
  }
@@ -1,4 +1,5 @@
1
- import { type IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
1
+ import type { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
2
+ import { LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
2
3
  import type { IFunction } from "aws-cdk-lib/aws-lambda";
3
4
  import { MediaType } from "../../types/mediatypes.js";
4
5
  type ParameterType = "path" | "querystring" | "multivaluequerystring" | "context" | "header";
@@ -1,6 +1,6 @@
1
1
  import { LambdaIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
2
- import { MediaType } from "../../types/mediatypes.js";
3
2
  import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response.js";
3
+ import { MediaType } from "../../types/mediatypes.js";
4
4
  const VELOCITY_ALL_PARAMS = `#foreach($paramName in $params.keySet())
5
5
  #if( ! $paramMap.containsKey("_$paramName"))
6
6
  #set($tmp = $paramMap.put($paramName, $params[$paramName]))
@@ -48,18 +48,24 @@ export class DigitrafficIntegration {
48
48
  return this;
49
49
  }
50
50
  addPathParameter(...names) {
51
- names.forEach((name) => this.addParameter("path", name));
51
+ names.forEach((name) => {
52
+ this.addParameter("path", name);
53
+ });
52
54
  return this;
53
55
  }
54
56
  addQueryParameter(...names) {
55
57
  if (this._passAllQueryParameters) {
56
58
  throw new Error("Can't add query parameters with pass all");
57
59
  }
58
- names.forEach((name) => this.addParameter("querystring", name));
60
+ names.forEach((name) => {
61
+ this.addParameter("querystring", name);
62
+ });
59
63
  return this;
60
64
  }
61
65
  addMultiValueQueryParameter(...names) {
62
- names.forEach((name) => this.addParameter("multivaluequerystring", name));
66
+ names.forEach((name) => {
67
+ this.addParameter("multivaluequerystring", name);
68
+ });
63
69
  return this;
64
70
  }
65
71
  /**
@@ -69,7 +75,9 @@ export class DigitrafficIntegration {
69
75
  * @returns
70
76
  */
71
77
  addContextParameter(...names) {
72
- names.forEach((name) => this.addParameter("context", name));
78
+ names.forEach((name) => {
79
+ this.addParameter("context", name);
80
+ });
73
81
  return this;
74
82
  }
75
83
  /**
@@ -78,7 +86,9 @@ export class DigitrafficIntegration {
78
86
  * @param names for the headers
79
87
  */
80
88
  addHeaderParameter(...names) {
81
- names.forEach((name) => this.addParameter("header", name));
89
+ names.forEach((name) => {
90
+ this.addParameter("header", name);
91
+ });
82
92
  return this;
83
93
  }
84
94
  build() {
@@ -93,6 +103,7 @@ export class DigitrafficIntegration {
93
103
  passthroughBehavior: PassthroughBehavior.WHEN_NO_MATCH,
94
104
  });
95
105
  }
106
+ // noinspection JSUnusedGlobalSymbols
96
107
  createRequestParameters() {
97
108
  const requestParameters = {};
98
109
  // filter out context parameters
@@ -1,5 +1,5 @@
1
+ import type { IModel, JsonSchema, MethodResponse } from "aws-cdk-lib/aws-apigateway";
1
2
  import { MediaType } from "../../types/mediatypes.js";
2
- import { type IModel, type JsonSchema, type MethodResponse } from "aws-cdk-lib/aws-apigateway";
3
3
  /**
4
4
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
5
5
  * It will always return the body and status, but if status in something else than 200 OK the content-type
@@ -21,27 +21,42 @@ export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$
21
21
  * @param sunset Sunset date as string in ISO 8601 date-time format (YYYY-MM-DD)
22
22
  */
23
23
  export declare const getDeprecatedDefaultLambdaResponse: (sunset?: string) => string;
24
+ /**
25
+ * @deprecated
26
+ */
24
27
  export declare const MessageModel: {
25
28
  contentType: MediaType;
26
29
  modelName: string;
27
30
  schema: JsonSchema;
28
31
  };
29
32
  export declare const NotFoundResponse: string;
33
+ /**
34
+ * @deprecated
35
+ */
30
36
  export declare const BadRequestResponseTemplate: {
31
37
  "application/json": string;
32
38
  };
39
+ /**
40
+ * @deprecated
41
+ */
33
42
  export declare const NotFoundResponseTemplate: {
34
43
  "application/json": string;
35
44
  };
45
+ /**
46
+ * @deprecated
47
+ */
36
48
  export declare const XmlResponseTemplate: {
37
49
  "application/xml": string;
38
50
  };
51
+ /**
52
+ * @deprecated
53
+ */
39
54
  export declare const InternalServerErrorResponseTemplate: {
40
55
  "application/json": string;
41
56
  };
42
- export declare class DigitrafficMethodResponse {
43
- static response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean, deprecation?: boolean, sunset?: boolean): MethodResponse;
44
- static response200(model: IModel, mediaType?: MediaType, deprecation?: boolean, sunset?: boolean): MethodResponse;
45
- static response500(model?: IModel, mediaType?: MediaType): MethodResponse;
46
- static response400(model?: IModel, mediaType?: MediaType): MethodResponse;
47
- }
57
+ export declare const DigitrafficMethodResponse: {
58
+ response(statusCode: string, model: IModel, mediaType: MediaType, disableCors?: boolean, deprecation?: boolean, sunset?: boolean): MethodResponse;
59
+ response200(model: IModel, mediaType?: MediaType, deprecation?: boolean, sunset?: boolean): MethodResponse;
60
+ response500(model?: IModel, mediaType?: MediaType): MethodResponse;
61
+ response400(model?: IModel, mediaType?: MediaType): MethodResponse;
62
+ };
@@ -1,6 +1,6 @@
1
- import { MediaType } from "../../types/mediatypes.js";
2
1
  import { JsonSchemaType, JsonSchemaVersion, Model, } from "aws-cdk-lib/aws-apigateway";
3
2
  import { dateFromIsoString } from "../../../utils/date-utils.js";
3
+ import { MediaType } from "../../types/mediatypes.js";
4
4
  /**
5
5
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
6
6
  * It will always return the body and status, but if status in something else than 200 OK the content-type
@@ -45,7 +45,9 @@ export const getDeprecatedDefaultLambdaResponse = (sunset) => {
45
45
  return RESPONSE_DEFAULT_LAMBDA.concat(setDeprecationHeaders);
46
46
  };
47
47
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
48
- /// @deprecated
48
+ /**
49
+ * @deprecated
50
+ */
49
51
  const messageSchema = {
50
52
  schema: JsonSchemaVersion.DRAFT4,
51
53
  type: JsonSchemaType.OBJECT,
@@ -57,7 +59,9 @@ const messageSchema = {
57
59
  },
58
60
  },
59
61
  };
60
- /// @deprecated
62
+ /**
63
+ * @deprecated
64
+ */
61
65
  export const MessageModel = {
62
66
  contentType: MediaType.APPLICATION_JSON,
63
67
  modelName: "MessageResponseModel",
@@ -71,24 +75,32 @@ const InternalServerErrorResponse = JSON.stringify({
71
75
  });
72
76
  const BadRequestMessage = "Bad request";
73
77
  const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
74
- /// @deprecated
78
+ /**
79
+ * @deprecated
80
+ */
75
81
  export const BadRequestResponseTemplate = {
76
82
  [MediaType.APPLICATION_JSON]: BadRequestResponse,
77
83
  };
78
- /// @deprecated
84
+ /**
85
+ * @deprecated
86
+ */
79
87
  export const NotFoundResponseTemplate = {
80
88
  [MediaType.APPLICATION_JSON]: NotFoundResponse,
81
89
  };
82
- /// @deprecated
90
+ /**
91
+ * @deprecated
92
+ */
83
93
  export const XmlResponseTemplate = {
84
94
  [MediaType.APPLICATION_XML]: BODY_FROM_INPUT_PATH,
85
95
  };
86
- /// @deprecated
96
+ /**
97
+ * @deprecated
98
+ */
87
99
  export const InternalServerErrorResponseTemplate = {
88
100
  [MediaType.APPLICATION_JSON]: InternalServerErrorResponse,
89
101
  };
90
- export class DigitrafficMethodResponse {
91
- static response(statusCode, model, mediaType, disableCors = false, deprecation = false, sunset = false) {
102
+ export const DigitrafficMethodResponse = {
103
+ response(statusCode, model, mediaType, disableCors = false, deprecation = false, sunset = false) {
92
104
  return {
93
105
  statusCode,
94
106
  responseModels: {
@@ -106,15 +118,15 @@ export class DigitrafficMethodResponse {
106
118
  }),
107
119
  },
108
120
  };
109
- }
110
- static response200(model, mediaType = MediaType.APPLICATION_JSON, deprecation = false, sunset = false) {
121
+ },
122
+ response200(model, mediaType = MediaType.APPLICATION_JSON, deprecation = false, sunset = false) {
111
123
  return DigitrafficMethodResponse.response("200", model, mediaType, false, deprecation, sunset);
112
- }
113
- static response500(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
124
+ },
125
+ response500(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
114
126
  return DigitrafficMethodResponse.response("500", model, mediaType, false);
115
- }
116
- static response400(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
127
+ },
128
+ response400(model = Model.EMPTY_MODEL, mediaType = MediaType.APPLICATION_JSON) {
117
129
  return DigitrafficMethodResponse.response("400", model, mediaType, false);
118
- }
119
- }
130
+ },
131
+ };
120
132
  //# sourceMappingURL=response.js.map
@@ -1,14 +1,30 @@
1
- import { type IModel, type IntegrationResponse, LambdaIntegration, type MethodResponse, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
1
+ import type { IModel, IntegrationResponse, MethodResponse } from "aws-cdk-lib/aws-apigateway";
2
+ import { LambdaIntegration, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
2
3
  import type { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
3
4
  import type { MediaType } from "../../types/mediatypes.js";
5
+ /**
6
+ * @deprecated
7
+ */
4
8
  export declare const RESPONSE_200_OK: IntegrationResponse;
9
+ /**
10
+ * @deprecated
11
+ */
5
12
  export declare const RESPONSE_400_BAD_REQUEST: IntegrationResponse;
13
+ /**
14
+ * @deprecated
15
+ */
6
16
  export declare const RESPONSE_500_SERVER_ERROR: IntegrationResponse;
17
+ /**
18
+ * @deprecated
19
+ */
7
20
  export declare const RESPONSE_CORS_INTEGRATION: {
8
21
  responseParameters: {
9
22
  "method.response.header.Access-Control-Allow-Origin": string;
10
23
  };
11
24
  };
25
+ /**
26
+ * @deprecated
27
+ */
12
28
  export declare const RESPONSE_404_NOT_FOUND: {
13
29
  statusCode: string;
14
30
  selectionPattern: string;
@@ -1,33 +1,45 @@
1
- import { BadRequestResponseTemplate, InternalServerErrorResponseTemplate, NotFoundResponseTemplate, XmlResponseTemplate, } from "./response.js";
2
1
  import { LambdaIntegration, PassthroughBehavior, } from "aws-cdk-lib/aws-apigateway";
3
2
  import { BAD_REQUEST_MESSAGE, ERROR_MESSAGE, NOT_FOUND_MESSAGE, } from "../../types/errors.js";
4
- /// @deprecated
3
+ import { BadRequestResponseTemplate, InternalServerErrorResponseTemplate, NotFoundResponseTemplate, XmlResponseTemplate, } from "./response.js";
4
+ /**
5
+ * @deprecated
6
+ */
5
7
  export const RESPONSE_200_OK = {
6
8
  statusCode: "200",
7
9
  };
8
- /// @deprecated
10
+ /**
11
+ * @deprecated
12
+ */
9
13
  export const RESPONSE_400_BAD_REQUEST = {
10
14
  statusCode: "400",
11
15
  selectionPattern: BAD_REQUEST_MESSAGE,
12
16
  responseTemplates: BadRequestResponseTemplate,
13
17
  };
14
- /// @deprecated
18
+ /**
19
+ * @deprecated
20
+ */
15
21
  export const RESPONSE_500_SERVER_ERROR = {
16
22
  statusCode: "500",
17
23
  selectionPattern: ERROR_MESSAGE,
18
24
  responseTemplates: InternalServerErrorResponseTemplate,
19
25
  };
20
- /// @deprecated
26
+ /**
27
+ * @deprecated
28
+ */
21
29
  const RESPONSE_XML = {
22
30
  responseTemplates: XmlResponseTemplate,
23
31
  };
24
- /// @deprecated
32
+ /**
33
+ * @deprecated
34
+ */
25
35
  export const RESPONSE_CORS_INTEGRATION = {
26
36
  responseParameters: {
27
37
  "method.response.header.Access-Control-Allow-Origin": "'*'",
28
38
  },
29
39
  };
30
- /// @deprecated
40
+ /**
41
+ * @deprecated
42
+ */
31
43
  export const RESPONSE_404_NOT_FOUND = {
32
44
  statusCode: "404",
33
45
  selectionPattern: NOT_FOUND_MESSAGE,
@@ -63,8 +75,7 @@ export function defaultIntegration(lambdaFunction, options) {
63
75
  ],
64
76
  requestParameters: options?.requestParameters ?? {},
65
77
  requestTemplates: options?.requestTemplates ?? {},
66
- passthroughBehavior: options?.passthroughBehavior ??
67
- PassthroughBehavior.WHEN_NO_MATCH,
78
+ passthroughBehavior: options?.passthroughBehavior ?? PassthroughBehavior.WHEN_NO_MATCH,
68
79
  });
69
80
  }
70
81
  export function getResponse(response, options) {
@@ -1,4 +1,5 @@
1
- import { type IModel, type IntegrationResponse, type MethodResponse, MockIntegration, type Resource } from "aws-cdk-lib/aws-apigateway";
1
+ import type { IModel, IntegrationResponse, MethodResponse, Resource } from "aws-cdk-lib/aws-apigateway";
2
+ import { MockIntegration } from "aws-cdk-lib/aws-apigateway";
2
3
  import { MediaType } from "../../types/mediatypes.js";
3
4
  /**
4
5
  * Static integration, that returns the given response with given mediaType from given resource.
@@ -15,8 +15,7 @@ export class DigitrafficStaticIntegration extends MockIntegration {
15
15
  if (enableCors) {
16
16
  headers = { ...headers, "Access-Control-Allow-Origin": "*" };
17
17
  }
18
- const integrationResponse = DigitrafficStaticIntegration
19
- .createIntegrationResponse(response, mediaType, headers);
18
+ const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, headers);
20
19
  super({
21
20
  passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
22
21
  requestTemplates: {
@@ -37,7 +36,10 @@ export class DigitrafficStaticIntegration extends MockIntegration {
37
36
  return new DigitrafficStaticIntegration(resource, MediaType.APPLICATION_JSON, JSON.stringify(response), model, enableCors, apiKeyRequired, headers);
38
37
  }
39
38
  static createIntegrationResponse(response, mediaType, headers = {}) {
40
- const params = mapRecord(headers, (entry) => ["method.response.header." + entry[0], `'${entry[1]}'`]);
39
+ const params = mapRecord(headers, (entry) => [
40
+ `method.response.header.${entry[0]}`,
41
+ `'${entry[1]}'`,
42
+ ]);
41
43
  return {
42
44
  statusCode: "200",
43
45
  responseTemplates: {
@@ -6,10 +6,10 @@ export function grantOACRights(config) {
6
6
  config.bucket.addToResourcePolicy(new PolicyStatement({
7
7
  effect: config.effect ?? Effect.ALLOW,
8
8
  principals: [new ServicePrincipal("cloudfront.amazonaws.com")],
9
- resources: config.resources ?? [config.bucket.bucketArn + "/*"],
9
+ resources: config.resources ?? [`${config.bucket.bucketArn}/*`],
10
10
  actions: config.actions ?? ["s3:GetObject"],
11
11
  conditions: {
12
- "StringEquals": {
12
+ StringEquals: {
13
13
  "AWS:SourceArn": config.distributionArn,
14
14
  },
15
15
  },
@@ -23,7 +23,7 @@ export function grantOAIRights(config) {
23
23
  config.bucket.addToResourcePolicy(new PolicyStatement({
24
24
  effect: config.effect ?? Effect.ALLOW,
25
25
  principals: [new CanonicalUserPrincipal(config.canonicalUserId)],
26
- resources: config.resources ?? [config.bucket.bucketArn + "/*"],
26
+ resources: config.resources ?? [`${config.bucket.bucketArn}/*`],
27
27
  actions: config.actions ?? ["s3:GetObject"],
28
28
  }));
29
29
  }
@@ -1,6 +1,6 @@
1
+ import type { Canary } from "aws-cdk-lib/aws-synthetics";
1
2
  import type { Construct } from "constructs";
2
3
  import type { CanaryParameters } from "./canary-parameters.js";
3
- import type { Canary } from "aws-cdk-lib/aws-synthetics";
4
4
  export declare class CanaryAlarm {
5
5
  constructor(stack: Construct, canary: Canary, params: CanaryParameters);
6
6
  }