@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
package/README.md CHANGED
@@ -29,6 +29,8 @@ Use `pnpm` to build the code i.e.
29
29
  pnpm build
30
30
  pnpm test
31
31
  pnpm test --test-path-pattern 'dt-logger.test'
32
+ pnpm test:watch
33
+ pnpm test:watch --test-path-pattern 'dt-logger.test'
32
34
 
33
35
  Format code
34
36
 
@@ -2,12 +2,12 @@
2
2
  * A simple asserter-class for writing canaries without dependency to testing-libraries.
3
3
  */
4
4
  type AssertedValue = string | number;
5
- export declare abstract class Asserter {
6
- static assertEquals(value: AssertedValue, expected: AssertedValue): void;
7
- static assertTrue(value: boolean): void;
8
- static assertLength<T>(data: T[] | undefined, expected: number): void;
9
- static assertLengthGreaterThan<T>(data: T[] | undefined, expected: number): void;
10
- static assertGreaterThan(value: number, expected: number): void;
11
- static assertToBeCloseTo(value: number, expected: number, delta: number): void;
12
- }
5
+ export declare const Asserter: {
6
+ assertEquals(value: AssertedValue, expected: AssertedValue): void;
7
+ assertTrue(value: boolean): void;
8
+ assertLength<T>(data: T[] | undefined, expected: number): void;
9
+ assertLengthGreaterThan<T>(data: T[] | undefined, expected: number): void;
10
+ assertGreaterThan(value: number, expected: number): void;
11
+ assertToBeCloseTo(value: number, expected: number, delta: number): void;
12
+ };
13
13
  export {};
@@ -1,41 +1,41 @@
1
1
  /**
2
2
  * A simple asserter-class for writing canaries without dependency to testing-libraries.
3
3
  */
4
- export class Asserter {
5
- static assertEquals(value, expected) {
4
+ export const Asserter = {
5
+ assertEquals(value, expected) {
6
6
  if (value !== expected) {
7
7
  throw new Error(`Given value ${value} was not expected ${expected}`);
8
8
  }
9
- }
10
- static assertTrue(value) {
9
+ },
10
+ assertTrue(value) {
11
11
  if (!value) {
12
12
  throw new Error(`Given value was not true`);
13
13
  }
14
- }
15
- static assertLength(data, expected) {
14
+ },
15
+ assertLength(data, expected) {
16
16
  if (!data) {
17
17
  throw new Error("Given array was not defined");
18
18
  }
19
19
  if (data.length !== expected) {
20
20
  throw new Error(`Given array length ${data.length} was not expected ${expected}`);
21
21
  }
22
- }
23
- static assertLengthGreaterThan(data, expected) {
22
+ },
23
+ assertLengthGreaterThan(data, expected) {
24
24
  if (!data) {
25
25
  throw new Error("Given array was not defined");
26
26
  }
27
27
  if (data.length <= expected) {
28
28
  throw new Error(`Given array length ${data.length} was not greater than ${expected}`);
29
29
  }
30
- }
31
- static assertGreaterThan(value, expected) {
30
+ },
31
+ assertGreaterThan(value, expected) {
32
32
  if (value <= expected) {
33
33
  throw new Error(`Value ${value} was expected to be greater than ${expected}`);
34
34
  }
35
- }
36
- static assertToBeCloseTo(value, expected, delta) {
35
+ },
36
+ assertToBeCloseTo(value, expected, delta) {
37
37
  expect(expected - value).toBeGreaterThanOrEqual(-1 * delta);
38
38
  expect(expected - value).toBeLessThanOrEqual(delta);
39
- }
40
- }
39
+ },
40
+ };
41
41
  //# sourceMappingURL=asserter.js.map
@@ -1,3 +1,3 @@
1
- import { type DTDatabase } from "../database/database.js";
1
+ import type { DTDatabase } from "../database/database.js";
2
2
  export declare function assertCount(db: DTDatabase, sql: string, count: number): Promise<void>;
3
3
  export declare function dbTestBase(fn: (db: DTDatabase) => void, truncateFn: (db: DTDatabase) => Promise<void>, dbUser: string, dbPass: string, dbUri: string, convertNullsToUndefined?: boolean): () => void;
@@ -20,7 +20,7 @@ export function dbTestBase(fn, truncateFn, dbUser, dbPass, dbUri, convertNullsTo
20
20
  await truncateFn(db);
21
21
  }
22
22
  catch (e) {
23
- console.info("cought in commonDbTest:" + JSON.stringify(e));
23
+ console.info(`cought in commonDbTest:${JSON.stringify(e)}`);
24
24
  throw e;
25
25
  }
26
26
  });
@@ -39,10 +39,6 @@ test("nullable import ok?", () => {
39
39
  const nullable = import("../types/nullable.js");
40
40
  return expect(nullable).resolves.toBeDefined();
41
41
  });
42
- test("awsEnv import ok?", () => {
43
- const awsEnv = import("../types/aws-env.js");
44
- return expect(awsEnv).resolves.toBeDefined();
45
- });
46
42
  test("asyncTimeoutError import ok?", () => {
47
43
  const asyncTimeoutError = import("../types/async-timeout-error.js");
48
44
  return expect(asyncTimeoutError).resolves.toBeDefined();
@@ -107,6 +103,10 @@ test("slack import ok?", () => {
107
103
  const slack = import("../utils/slack.js");
108
104
  return expect(slack).resolves.toBeDefined();
109
105
  });
106
+ test("stopWatch import ok?", () => {
107
+ const stopWatch = import("../utils/stop-watch.js");
108
+ return expect(stopWatch).resolves.toBeDefined();
109
+ });
110
110
  test("utils import ok?", () => {
111
111
  const utils = import("../utils/utils.js");
112
112
  return expect(utils).resolves.toBeDefined();
@@ -1,6 +1,6 @@
1
- import { AclBuilder } from "../../aws/infra/acl-builder.js";
2
- import { App, Stack } from "aws-cdk-lib";
3
1
  import { expect } from "@jest/globals";
2
+ import { App, Stack } from "aws-cdk-lib";
3
+ import { AclBuilder } from "../../aws/infra/acl-builder.js";
4
4
  describe("acl-builder tests", () => {
5
5
  function createBuilder() {
6
6
  const app = new App();
@@ -15,19 +15,20 @@ describe("acl-builder tests", () => {
15
15
  expect(acl.rules).toHaveLength(4);
16
16
  });
17
17
  test("two aws rules", () => {
18
- const acl = createBuilder().withAWSManagedRules([
19
- "CommonRuleSet",
20
- "AmazonIpReputationList",
21
- ]).build();
18
+ const acl = createBuilder()
19
+ .withAWSManagedRules(["CommonRuleSet", "AmazonIpReputationList"])
20
+ .build();
22
21
  expect(acl.rules).toHaveLength(2);
23
22
  });
24
23
  test("ip blacklist", () => {
25
- const acl = createBuilder().withIpBlacklistRule(["1.2.3.4", "1.2.6.6"])
24
+ const acl = createBuilder()
25
+ .withIpBlacklistRule(["1.2.3.4", "1.2.6.6"])
26
26
  .build();
27
27
  expect(acl.rules).toHaveLength(1);
28
28
  });
29
29
  test("ip whitelist", () => {
30
- const acl = createBuilder().withIpWhitelistRule(["1.2.3.4", "1.2.6.6"])
30
+ const acl = createBuilder()
31
+ .withIpWhitelistRule(["1.2.3.4", "1.2.6.6"])
31
32
  .build();
32
33
  expect(acl.rules).toHaveLength(1);
33
34
  });
@@ -42,19 +43,19 @@ describe("acl-builder tests", () => {
42
43
  const acl = aclBuilder.build();
43
44
  // Check that the rule exists and a custom response is defined
44
45
  expect(acl.rules).toHaveLength(1);
45
- expect(Object.keys(acl.customResponseBodies))
46
- .toHaveLength(1);
46
+ expect(Object.keys(acl.customResponseBodies)).toHaveLength(1);
47
47
  // Check that the rule does throttle
48
48
  const throttleRule = acl.rules[0];
49
49
  expect(throttleRule.statement
50
50
  .rateBasedStatement).toBeDefined();
51
- expect(throttleRule.action.block)
52
- .toBeDefined();
51
+ expect(throttleRule.action.block).toBeDefined();
53
52
  }
54
53
  });
55
54
  test("Cannot define two rules with the same name", () => {
56
- expect(() => createBuilder().withThrottleAnonymousUserIp(10)
57
- .withThrottleAnonymousUserIp(200).build()).toThrow();
55
+ expect(() => createBuilder()
56
+ .withThrottleAnonymousUserIp(10)
57
+ .withThrottleAnonymousUserIp(200)
58
+ .build()).toThrow();
58
59
  });
59
60
  test("throtle rule without limit does nothing", () => {
60
61
  for (const aclBuilder of [
@@ -1,6 +1,6 @@
1
+ import { jest } from "@jest/globals";
1
2
  import { HandlerFactory } from "../../../aws/infra/api/handler-factory.js";
2
3
  import { DtLogger } from "../../../aws/runtime/dt-logger.js";
3
- import { jest } from "@jest/globals";
4
4
  const logger = new DtLogger();
5
5
  describe("handler-factory tests", () => {
6
6
  test("test defaults", async () => {
@@ -1,21 +1,21 @@
1
- import { DigitrafficIntegration } from "../../../aws/infra/api/integration.js";
2
- import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";
3
1
  import { App, Stack } from "aws-cdk-lib";
4
- import { MediaType } from "../../../aws/types/mediatypes.js";
2
+ import { Code, Function as LambdaFunction, Runtime, } from "aws-cdk-lib/aws-lambda";
5
3
  import velocity from "velocityjs";
4
+ import { DigitrafficIntegration } from "../../../aws/infra/api/integration.js";
5
+ import { MediaType } from "../../../aws/types/mediatypes.js";
6
6
  import { decodeBase64ToAscii } from "../../../utils/base64.js";
7
7
  describe("integration tests", () => {
8
8
  function createTemplate(i) {
9
- const template = i.createRequestTemplates()[MediaType.APPLICATION_JSON]
10
- .trim();
9
+ const template = i
10
+ .createRequestTemplates()[MediaType.APPLICATION_JSON].trim();
11
11
  // assert template parses
12
12
  const response = createResponseFromTemplate(template);
13
13
  // assert response parses
14
- console.info("response " + response);
14
+ console.info(`response ${response}`);
15
15
  return JSON.parse(response);
16
16
  }
17
17
  function createResponseFromTemplate(template) {
18
- console.info("compile " + template);
18
+ console.info(`compile ${template}`);
19
19
  const compile = new velocity.Compile(velocity.parse(template));
20
20
  return compile.render({
21
21
  method: {
@@ -57,7 +57,7 @@ describe("integration tests", () => {
57
57
  function createIntegration() {
58
58
  const app = new App();
59
59
  const stack = new Stack(app);
60
- const f = new Function(stack, "id", {
60
+ const f = new LambdaFunction(stack, "id", {
61
61
  runtime: Runtime.NODEJS_22_X,
62
62
  code: Code.fromInline("placeholder"),
63
63
  handler: "handler",
@@ -70,8 +70,7 @@ describe("integration tests", () => {
70
70
  expect(t).toEqual({});
71
71
  });
72
72
  test("query parameter", () => {
73
- const i = createIntegration()
74
- .addQueryParameter("q1");
73
+ const i = createIntegration().addQueryParameter("q1");
75
74
  const t = createTemplate(i);
76
75
  expect(t).toEqual({
77
76
  q1: "querystring1",
@@ -88,16 +87,14 @@ describe("integration tests", () => {
88
87
  });
89
88
  });
90
89
  test("multivaluequery parameter", () => {
91
- const i = createIntegration()
92
- .addMultiValueQueryParameter("m1");
90
+ const i = createIntegration().addMultiValueQueryParameter("m1");
93
91
  const t = createTemplate(i);
94
92
  expect(t).toEqual({
95
93
  m1: ["multi1", "multi2"],
96
94
  });
97
95
  });
98
96
  test("all parameters", () => {
99
- const i = createIntegration()
100
- .passAllQueryParameters();
97
+ const i = createIntegration().passAllQueryParameters();
101
98
  const t = createTemplate(i);
102
99
  expect(t).toEqual({
103
100
  q1: "querystring1",
@@ -105,24 +102,21 @@ describe("integration tests", () => {
105
102
  });
106
103
  });
107
104
  test("path parameter", () => {
108
- const i = createIntegration()
109
- .addPathParameter("p1");
105
+ const i = createIntegration().addPathParameter("p1");
110
106
  const t = createTemplate(i);
111
107
  expect(t).toEqual({
112
108
  p1: "path1",
113
109
  });
114
110
  });
115
111
  test("context parameter", () => {
116
- const i = createIntegration()
117
- .addContextParameter("c1");
112
+ const i = createIntegration().addContextParameter("c1");
118
113
  const t = createTemplate(i);
119
114
  expect(t).toEqual({
120
115
  c1: "context1",
121
116
  });
122
117
  });
123
118
  test("context parameter authorizer", () => {
124
- const i = createIntegration()
125
- .addContextParameter("authorizer.c2");
119
+ const i = createIntegration().addContextParameter("authorizer.c2");
126
120
  const t = createTemplate(i);
127
121
  expect(t).toEqual({
128
122
  "authorizer.c2": "context2",
@@ -141,9 +135,7 @@ describe("integration tests", () => {
141
135
  });
142
136
  test("all parameters & parameter - fail", () => {
143
137
  expect(() => {
144
- createIntegration()
145
- .passAllQueryParameters()
146
- .addQueryParameter("q1");
138
+ createIntegration().passAllQueryParameters().addQueryParameter("q1");
147
139
  }).toThrow();
148
140
  });
149
141
  test("path parameters & pass all ", () => {
@@ -158,8 +150,7 @@ describe("integration tests", () => {
158
150
  });
159
151
  });
160
152
  test("path body", () => {
161
- const i = createIntegration()
162
- .passBody();
153
+ const i = createIntegration().passBody();
163
154
  const t = createTemplate(i);
164
155
  // body base64-encoded
165
156
  expect(t).toEqual({
@@ -1,6 +1,6 @@
1
- import { RESPONSE_DEFAULT_LAMBDA } from "../../../aws/infra/api/response.js";
2
1
  import etag from "etag";
3
2
  import velocity from "velocityjs";
3
+ import { RESPONSE_DEFAULT_LAMBDA } from "../../../aws/infra/api/response.js";
4
4
  const TEST_BODY = "Hello world!";
5
5
  describe("response tests", () => {
6
6
  function generateEtagValueFromString(body) {
@@ -38,7 +38,6 @@ describe("response tests", () => {
38
38
  },
39
39
  });
40
40
  // @ts-expect-error: context is not in the type definition
41
- // eslint-disable-next-line
42
41
  return [output, compile.context.context];
43
42
  }
44
43
  function assertOutputAndContext(output, context, status, contentType, fileName, timestamp) {
@@ -3,8 +3,7 @@ import { DigitrafficStaticIntegration } from "../../../aws/infra/api/static-inte
3
3
  import { MediaType } from "../../../aws/types/mediatypes.js";
4
4
  describe("response tests", () => {
5
5
  it("createIntegrationResponse works", () => {
6
- const integrationResponse = DigitrafficStaticIntegration
7
- .createIntegrationResponse("FakeResource", MediaType.APPLICATION_JSON, { "test-header": "test-value" });
6
+ const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse("FakeResource", MediaType.APPLICATION_JSON, { "test-header": "test-value" });
8
7
  expect(integrationResponse).toEqual({
9
8
  responseParameters: {
10
9
  "method.response.header.test-header": "'test-value'",
@@ -1,6 +1,6 @@
1
1
  import { App, Stack } from "aws-cdk-lib";
2
- import { Scheduler } from "../../aws/infra/scheduler.js";
3
2
  import { Template } from "aws-cdk-lib/assertions";
3
+ import { Scheduler } from "../../aws/infra/scheduler.js";
4
4
  describe("scheduler tests", () => {
5
5
  function expectRate(createScheduler, expectedRate) {
6
6
  const app = new App();
@@ -1,7 +1,7 @@
1
1
  import { App, Stack } from "aws-cdk-lib";
2
2
  import { Template } from "aws-cdk-lib/assertions";
3
- import { DigitrafficSecurityRule } from "../../aws/infra/security-rule.js";
4
3
  import { Topic } from "aws-cdk-lib/aws-sns";
4
+ import { DigitrafficSecurityRule } from "../../aws/infra/security-rule.js";
5
5
  describe("security-rule tests", () => {
6
6
  test("create", () => {
7
7
  const app = new App();
@@ -5,7 +5,7 @@ describe("DigitrafficRestApi tests", () => {
5
5
  function createRestApi() {
6
6
  const app = new App();
7
7
  const stack = new DigitrafficStack(app, "name", {
8
- shortName: "TEST"
8
+ shortName: "TEST",
9
9
  });
10
10
  return new DigitrafficRestApi(stack, "id", "name");
11
11
  }
@@ -28,7 +28,7 @@ describe("DigitrafficRestApi tests", () => {
28
28
  restApi.apiKeyIds.push("key1");
29
29
  restApi.apiKeyIds.push("key2");
30
30
  const [sp1, sp2] = restApi.exportEndpoint({
31
- apiKeyId: "key3"
31
+ apiKeyId: "key3",
32
32
  });
33
33
  expect(sp1.node.id).toEqual("export.endpoint.TEST");
34
34
  expect(sp2.node.id).toEqual("export.apiKeyId.TEST");
@@ -37,7 +37,7 @@ describe("DigitrafficRestApi tests", () => {
37
37
  const restApi = createRestApi();
38
38
  restApi.apiKeyIds.push("key1");
39
39
  const [sp1, sp2] = restApi.exportEndpoint({
40
- exportName: "exp1"
40
+ exportName: "exp1",
41
41
  });
42
42
  expect(sp1.node.id).toEqual("export.endpoint.exp1");
43
43
  expect(sp2.node.id).toEqual("export.apiKeyId.exp1");
@@ -1,5 +1,5 @@
1
- import * as IdUtils from "../../marine/id_utils.js";
2
1
  import { getRandomNumber } from "../../__test__/testutils.js";
2
+ import * as IdUtils from "../../marine/id_utils.js";
3
3
  describe("IdUtils tests", () => {
4
4
  test("isValidLOCODE - success", () => {
5
5
  expect(IdUtils.isValidLOCODE("FILOL")).toBe(true);
@@ -38,8 +38,7 @@ describe("IdUtils tests", () => {
38
38
  expect(IdUtils.isValidMMSI(getRandomNumber(0, 100000000 - 1))).toBe(false);
39
39
  });
40
40
  test("isValidMMSI - fail with number larger than 999999999", () => {
41
- expect(IdUtils.isValidMMSI(getRandomNumber(999999999 + 1, 9999999999)))
42
- .toBe(false);
41
+ expect(IdUtils.isValidMMSI(getRandomNumber(999999999 + 1, 9999999999))).toBe(false);
43
42
  });
44
43
  });
45
44
  //# sourceMappingURL=id_utils.test.js.map
@@ -7,7 +7,6 @@ export function mockKyResponse(status, body) {
7
7
  return Object.assign(promise, {
8
8
  arrayBuffer: () => response.arrayBuffer(),
9
9
  blob: () => response.blob(),
10
- // eslint-disable-next-line deprecation/deprecation
11
10
  formData: () => response.formData(),
12
11
  json: () => response.json(),
13
12
  text: () => response.text(),
@@ -1,7 +1,7 @@
1
+ import { jest } from "@jest/globals";
1
2
  import { getRandomInteger } from "../../__test__/testutils.js";
2
- import { retry, RetryLogError } from "../../utils/retry.js";
3
3
  import { logger } from "../../aws/runtime/dt-logger-default.js";
4
- import { jest } from "@jest/globals";
4
+ import { RetryLogError, retry } from "../../utils/retry.js";
5
5
  jest.useFakeTimers();
6
6
  describe("Promise utils tests", () => {
7
7
  test("retry - no retries", async () => {
@@ -75,8 +75,7 @@ describe("Promise utils tests", () => {
75
75
  });
76
76
  test("retry - exceeded retry count throws error", async () => {
77
77
  const fn = jest.fn(() => Promise.reject("error"));
78
- await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects
79
- .toThrow();
78
+ await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
80
79
  });
81
80
  test("retry - defaults", async () => {
82
81
  const fn = jest.fn(() => Promise.reject("error"));
@@ -94,13 +93,11 @@ describe("Promise utils tests", () => {
94
93
  });
95
94
  test("retry - NaN throws error", async () => {
96
95
  const fn = jest.fn(() => Promise.resolve(NaN));
97
- await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects
98
- .toThrow();
96
+ await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
99
97
  });
100
98
  test("retry - Infinity throws error", async () => {
101
99
  const fn = jest.fn(() => Promise.resolve(NaN));
102
- await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects
103
- .toThrow();
100
+ await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
104
101
  });
105
102
  test("retry - exceeded maximum retry count throws error", async () => {
106
103
  const fn = jest.fn(() => Promise.resolve(NaN));
@@ -1,5 +1,5 @@
1
- import { Writable } from "stream";
2
- import { DtLogger, } from "../../aws/runtime/dt-logger.js";
1
+ import { Writable } from "node:stream";
2
+ import { DtLogger } from "../../aws/runtime/dt-logger.js";
3
3
  const LOG_LINE = {
4
4
  method: "dt-logger.test",
5
5
  message: "FOO",
@@ -40,17 +40,14 @@ describe("dt-logger", () => {
40
40
  const loggedLine = JSON.parse(logged[0]);
41
41
  console.info(loggedLine);
42
42
  if (typeof expected === "object" && "stack" in expected && expected.stack) {
43
- // eslint-disable-next-line dot-notation
44
- const stack = loggedLine["stack"];
43
+ const stack = loggedLine.stack;
45
44
  expect(stack).toBeDefined();
46
- // @ts-ignore // stack should be multiline string
45
+ // stack should be multiline string
47
46
  const stackLines = stack.split("\n");
48
47
  expect(stackLines.length).toBeGreaterThanOrEqual(2);
49
48
  expect(stackLines[0]).toEqual(expected.stack);
50
- // @ts-ignore
51
- expect(stackLines[1].trim().startsWith("at ")).toBe(true);
52
- // eslint-disable-next-line dot-notation
53
- delete loggedLine["stack"];
49
+ expect(stackLines[1]?.trim()?.startsWith("at ")).toBe(true);
50
+ delete loggedLine.stack;
54
51
  delete expected.stack;
55
52
  }
56
53
  expect(loggedLine).toMatchObject(expected);
@@ -65,7 +62,7 @@ describe("dt-logger", () => {
65
62
  customEqualsText: "foo=bar",
66
63
  }, {
67
64
  method: EXPECTED_LOG_LINE.method,
68
- message: `${EXPECTED_LOG_LINE.message} date=${date.toISOString()} number=123 text=abc equalsText=\"foo=bar\"`,
65
+ message: `${EXPECTED_LOG_LINE.message} date=${date.toISOString()} number=123 text=abc equalsText="foo=bar"`,
69
66
  date: date.toISOString(),
70
67
  number: 123,
71
68
  text: "abc",
@@ -172,11 +169,11 @@ describe("dt-logger", () => {
172
169
  test("error - Error with stack", () => {
173
170
  let error;
174
171
  try {
175
- // @ts-ignore
172
+ // @ts-expect-error
176
173
  console.log(`Result: ${undefined.length}`);
177
174
  }
178
175
  catch (e) {
179
- // @ts-ignore
176
+ // @ts-expect-error
180
177
  console.debug(`Failed message: ${e.message}`);
181
178
  console.debug(`Failed stack: ${e.stack}`);
182
179
  error = e;
@@ -1,5 +1,6 @@
1
- import { SecretsManager, } from "@aws-sdk/client-secrets-manager";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
2
  import { jest } from "@jest/globals";
3
+ import { setEnvVariable, setEnvVariableAwsRegion } from "../../utils/utils.js";
3
4
  const SECRET_WITH_PREFIX = {
4
5
  "prefix.value": "value",
5
6
  "prefix.name": "name",
@@ -8,12 +9,11 @@ const SECRET_WITH_PREFIX = {
8
9
  };
9
10
  const emptySecret = { $metadata: {} };
10
11
  const getSecretValueMock = jest.fn();
11
- jest.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(
12
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
13
- getSecretValueMock);
12
+ jest
13
+ .spyOn(SecretsManager.prototype, "getSecretValue")
14
+ .mockImplementation(getSecretValueMock);
14
15
  const { SecretHolder } = await import("../../aws/runtime/secrets/secret-holder.js");
15
16
  const { DatabaseEnvironmentKeys } = await import("../../database/database.js");
16
- // eslint-disable-next-line @rushstack/no-new-null
17
17
  function mockSecret(secret) {
18
18
  if (!secret) {
19
19
  getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
@@ -27,10 +27,8 @@ function mockSecret(secret) {
27
27
  }
28
28
  describe("SecretHolder - tests", () => {
29
29
  beforeEach(() => {
30
- // eslint-disable-next-line dot-notation
31
- process.env["SECRET_ID"] = "test-id";
32
- // eslint-disable-next-line dot-notation
33
- process.env["AWS_REGION"] = "eu-west-1";
30
+ setEnvVariable("SECRET_ID", "test-id");
31
+ setEnvVariableAwsRegion("eu-west-1");
34
32
  });
35
33
  afterEach(() => {
36
34
  delete process.env[DatabaseEnvironmentKeys.DB_USER];
@@ -1,5 +1,6 @@
1
- import { SecretsManager, } from "@aws-sdk/client-secrets-manager";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
2
  import { jest } from "@jest/globals";
3
+ import { setEnvVariableAwsRegion } from "../../utils/utils.js";
3
4
  const SECRET_ID = "test_secret";
4
5
  const SECRET_WITH_PREFIX = {
5
6
  "prefix.value": "value",
@@ -8,10 +9,9 @@ const SECRET_WITH_PREFIX = {
8
9
  };
9
10
  const emptySecret = { $metadata: {} };
10
11
  const getSecretValueMock = jest.fn();
11
- jest.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(
12
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
13
- getSecretValueMock);
14
- // eslint-disable-next-line @rushstack/no-new-null
12
+ jest
13
+ .spyOn(SecretsManager.prototype, "getSecretValue")
14
+ .mockImplementation(getSecretValueMock);
15
15
  function mockSecret(secret) {
16
16
  if (!secret) {
17
17
  getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
@@ -23,8 +23,7 @@ function mockSecret(secret) {
23
23
  }));
24
24
  }
25
25
  }
26
- // eslint-disable-next-line dot-notation
27
- process.env["AWS_REGION"] = "eu-west-1";
26
+ setEnvVariableAwsRegion("eu-west-1");
28
27
  const secret = await import("../../aws/runtime/secrets/secret.js");
29
28
  const { getSecret } = secret;
30
29
  describe("secret - test", () => {
@@ -1,8 +1,8 @@
1
1
  import { App } from "aws-cdk-lib";
2
+ import { Match, Template } from "aws-cdk-lib/assertions";
2
3
  import { DigitrafficRestApi } from "../../aws/infra/stack/rest-api.js";
3
4
  import { DigitrafficStack } from "../../aws/infra/stack/stack.js";
4
5
  import { TrafficType } from "../../types/traffictype.js";
5
- import { Match, Template } from "aws-cdk-lib/assertions";
6
6
  describe("Rest api test", () => {
7
7
  test("OPTIONS method is added to API-gateway", () => {
8
8
  const app = new App();