@digitraffic/common 2026.4.17-1 → 2026.4.17-3
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.
- package/dist/__test__/asserter.js +1 -3
- package/dist/__test__/db-testutils.js +1 -0
- package/dist/__test__/dependencies.test.js +1 -1
- package/dist/__test__/imports.test.js +1 -1
- package/dist/__test__/infra/acl-builder.test.js +1 -1
- package/dist/__test__/infra/api/handler-factory.test.js +6 -6
- package/dist/__test__/infra/api/integration.test.js +1 -0
- package/dist/__test__/infra/api/response.test.js +1 -0
- package/dist/__test__/infra/api/static-integration.test.js +3 -2
- package/dist/__test__/infra/documentation.test.js +1 -0
- package/dist/__test__/infra/scheduler.test.js +1 -0
- package/dist/__test__/infra/security-rule.test.js +1 -0
- package/dist/__test__/infra/stack/rest-apis.test.js +1 -0
- package/dist/__test__/marine/id_utils.test.js +1 -0
- package/dist/__test__/promise/promise.test.js +17 -17
- package/dist/__test__/runtime/dt-logger.test.js +1 -0
- package/dist/__test__/secrets/secret-holder.test.js +3 -5
- package/dist/__test__/secrets/secret.test.js +7 -5
- package/dist/__test__/stack/dt-function.test.js +1 -0
- package/dist/__test__/stack/rest-apis.test.js +1 -0
- package/dist/__test__/test/mock-ky.test.js +13 -35
- package/dist/__test__/types/lambda-proxy-types.test.js +1 -0
- package/dist/__test__/types/lambda-response-builder.test.js +1 -0
- package/dist/__test__/types/lambda-response.test.js +1 -0
- package/dist/__test__/utils/base64.test.js +1 -0
- package/dist/__test__/utils/date-utils.test.js +1 -0
- package/dist/__test__/utils/geometry.test.js +1 -0
- package/dist/__test__/utils/lambda-proxy-event.test.js +1 -0
- package/dist/__test__/utils/logging.test.js +1 -0
- package/dist/__test__/utils/stop-watch.test.js +1 -1
- package/dist/__test__/utils/utils.test.js +1 -0
- package/dist/aws/infra/stack/dt-function.d.ts +6 -0
- package/dist/aws/infra/stack/dt-function.js +9 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +8 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const madge = await import("madge");
|
|
2
|
+
import { expect, test } from "vitest";
|
|
2
3
|
const WHITELISTED_DEPENDENCIES = [
|
|
3
4
|
// aspect is using DigitrafficStack with instanceof, can't remove
|
|
4
5
|
`["aws/infra/stack/stack.mjs","aws/infra/stack/stack-checking-aspect.mjs"]`,
|
|
@@ -17,5 +18,4 @@ test("circular dependencies", async () => {
|
|
|
17
18
|
const errors = circulars.filter(whitelist);
|
|
18
19
|
assertNoErrors(errors);
|
|
19
20
|
});
|
|
20
|
-
export {};
|
|
21
21
|
//# sourceMappingURL=dependencies.test.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { HandlerFactory } from "../../../aws/infra/api/handler-factory.js";
|
|
3
3
|
import { DtLogger } from "../../../aws/runtime/dt-logger.js";
|
|
4
4
|
const logger = new DtLogger();
|
|
5
5
|
describe("handler-factory tests", () => {
|
|
6
6
|
test("test defaults", async () => {
|
|
7
7
|
const factory = new HandlerFactory();
|
|
8
|
-
const method =
|
|
8
|
+
const method = vi.fn((method) => {
|
|
9
9
|
return method;
|
|
10
10
|
});
|
|
11
11
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -13,11 +13,11 @@ describe("handler-factory tests", () => {
|
|
|
13
13
|
expect(method).toHaveBeenCalledTimes(1);
|
|
14
14
|
});
|
|
15
15
|
test("test logging", async () => {
|
|
16
|
-
const loggingHandler =
|
|
16
|
+
const loggingHandler = vi.fn((method) => {
|
|
17
17
|
return method();
|
|
18
18
|
});
|
|
19
19
|
const factory = new HandlerFactory().withLoggingHandler(loggingHandler);
|
|
20
|
-
const method =
|
|
20
|
+
const method = vi.fn((method) => {
|
|
21
21
|
return method;
|
|
22
22
|
});
|
|
23
23
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -26,11 +26,11 @@ describe("handler-factory tests", () => {
|
|
|
26
26
|
expect(loggingHandler).toHaveBeenCalledTimes(1);
|
|
27
27
|
});
|
|
28
28
|
test("test error handling", async () => {
|
|
29
|
-
const eh =
|
|
29
|
+
const eh = vi.fn((method) => {
|
|
30
30
|
return method;
|
|
31
31
|
});
|
|
32
32
|
const factory = new HandlerFactory().withErrorHandler(eh);
|
|
33
|
-
const method =
|
|
33
|
+
const method = vi.fn(() => {
|
|
34
34
|
throw new Error("MAGIC");
|
|
35
35
|
});
|
|
36
36
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Code, Function as LambdaFunction, Runtime, } from "aws-cdk-lib/aws-lambda";
|
|
3
3
|
import velocity from "velocityjs";
|
|
4
|
+
import { describe, expect, test } from "vitest";
|
|
4
5
|
import { DigitrafficIntegration } from "../../../aws/infra/api/integration.js";
|
|
5
6
|
import { MediaType } from "../../../aws/types/mediatypes.js";
|
|
6
7
|
import { decodeBase64ToAscii } from "../../../utils/base64.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Model } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DigitrafficStaticIntegration } from "../../../aws/infra/api/static-integration.js";
|
|
3
4
|
import { MediaType } from "../../../aws/types/mediatypes.js";
|
|
4
5
|
describe("response tests", () => {
|
|
5
|
-
|
|
6
|
+
test("createIntegrationResponse works", () => {
|
|
6
7
|
const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse("FakeResource", MediaType.APPLICATION_JSON, { "test-header": "test-value" });
|
|
7
8
|
expect(integrationResponse).toEqual({
|
|
8
9
|
responseParameters: {
|
|
@@ -14,7 +15,7 @@ describe("response tests", () => {
|
|
|
14
15
|
statusCode: "200",
|
|
15
16
|
});
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
+
test("createMethodResponse works", () => {
|
|
18
19
|
const methodResponse = DigitrafficStaticIntegration.createMethodResponse({
|
|
19
20
|
"test-header": "test-value",
|
|
20
21
|
}, MediaType.TEXT_PLAIN, Model.EMPTY_MODEL);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Template } from "aws-cdk-lib/assertions";
|
|
3
|
+
import { describe, test } from "vitest";
|
|
3
4
|
import { Scheduler } from "../../aws/infra/scheduler.js";
|
|
4
5
|
describe("scheduler tests", () => {
|
|
5
6
|
function expectRate(createScheduler, expectedRate) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Template } from "aws-cdk-lib/assertions";
|
|
3
3
|
import { Topic } from "aws-cdk-lib/aws-sns";
|
|
4
|
+
import { describe, test } from "vitest";
|
|
4
5
|
import { DigitrafficSecurityRule } from "../../aws/infra/security-rule.js";
|
|
5
6
|
describe("security-rule tests", () => {
|
|
6
7
|
test("create", () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { App } from "aws-cdk-lib";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DigitrafficRestApi } from "../../../aws/infra/stack/rest-api.js";
|
|
3
4
|
import { DigitrafficStack } from "../../../aws/infra/stack/stack.js";
|
|
4
5
|
describe("DigitrafficRestApi tests", () => {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { getRandomInteger } from "../../__test__/testutils.js";
|
|
3
3
|
import { logger } from "../../aws/runtime/dt-logger-default.js";
|
|
4
4
|
import { RetryLogError, retry } from "../../utils/retry.js";
|
|
5
|
-
|
|
5
|
+
vi.useFakeTimers();
|
|
6
6
|
describe("Promise utils tests", () => {
|
|
7
7
|
test("retry - no retries", async () => {
|
|
8
|
-
const fn =
|
|
8
|
+
const fn = vi.fn(() => Promise.resolve(1));
|
|
9
9
|
const ret = await retry(fn, 0, RetryLogError.NO_LOGGING);
|
|
10
10
|
expect(ret).toBe(1);
|
|
11
11
|
expect(fn.mock.calls.length).toBe(1);
|
|
12
12
|
});
|
|
13
13
|
test("retry - error with n+1 retries", async () => {
|
|
14
|
-
const fn =
|
|
14
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
15
15
|
const retries = getRandomInteger(1, 10);
|
|
16
16
|
try {
|
|
17
17
|
await retry(fn, retries, RetryLogError.NO_LOGGING);
|
|
@@ -24,15 +24,15 @@ describe("Promise utils tests", () => {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
test("retry - no error with n+1 retries", async () => {
|
|
27
|
-
const fn =
|
|
27
|
+
const fn = vi.fn(() => Promise.resolve(1));
|
|
28
28
|
const retries = getRandomInteger(1, 10);
|
|
29
29
|
const ret = await retry(fn, retries, RetryLogError.NO_LOGGING);
|
|
30
30
|
expect(ret).toBe(1);
|
|
31
31
|
expect(fn.mock.calls.length).toBe(1);
|
|
32
32
|
});
|
|
33
33
|
test("retry - errors with no error logging", async () => {
|
|
34
|
-
const fn =
|
|
35
|
-
const consoleErrorSpy =
|
|
34
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
35
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
36
36
|
try {
|
|
37
37
|
await retry(fn, getRandomInteger(0, 10), RetryLogError.NO_LOGGING);
|
|
38
38
|
}
|
|
@@ -45,8 +45,8 @@ describe("Promise utils tests", () => {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
test("retry - no retries with error logging", async () => {
|
|
48
|
-
const fn =
|
|
49
|
-
const consoleErrorSpy =
|
|
48
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
49
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
50
50
|
try {
|
|
51
51
|
await retry(fn, 0, RetryLogError.LOG_ALL_AS_ERRORS);
|
|
52
52
|
}
|
|
@@ -59,9 +59,9 @@ describe("Promise utils tests", () => {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
test("retry - retries with error logging", async () => {
|
|
62
|
-
const fn =
|
|
62
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
63
63
|
const retries = getRandomInteger(1, 10);
|
|
64
|
-
const consoleErrorSpy =
|
|
64
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
65
65
|
try {
|
|
66
66
|
await retry(fn, retries, RetryLogError.LOG_ALL_AS_ERRORS);
|
|
67
67
|
}
|
|
@@ -74,12 +74,12 @@ describe("Promise utils tests", () => {
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
test("retry - exceeded retry count throws error", async () => {
|
|
77
|
-
const fn =
|
|
77
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
78
78
|
await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
|
|
79
79
|
});
|
|
80
80
|
test("retry - defaults", async () => {
|
|
81
|
-
const fn =
|
|
82
|
-
const consoleErrorSpy =
|
|
81
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
82
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
83
83
|
try {
|
|
84
84
|
await retry(fn);
|
|
85
85
|
}
|
|
@@ -92,15 +92,15 @@ describe("Promise utils tests", () => {
|
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
test("retry - NaN throws error", async () => {
|
|
95
|
-
const fn =
|
|
95
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
96
96
|
await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
97
97
|
});
|
|
98
98
|
test("retry - Infinity throws error", async () => {
|
|
99
|
-
const fn =
|
|
99
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
100
100
|
await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
101
101
|
});
|
|
102
102
|
test("retry - exceeded maximum retry count throws error", async () => {
|
|
103
|
-
const fn =
|
|
103
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
104
104
|
await expect(() => retry(fn, getRandomInteger(101, 1000000), RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
105
105
|
});
|
|
106
106
|
test("retry - use without mocks without retry", async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
|
-
import {
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
3
|
import { setEnvVariable, setEnvVariableAwsRegion } from "../../utils/utils.js";
|
|
4
4
|
const SECRET_WITH_PREFIX = {
|
|
5
5
|
"prefix.value": "value",
|
|
@@ -8,10 +8,8 @@ const SECRET_WITH_PREFIX = {
|
|
|
8
8
|
username: "DB_USER",
|
|
9
9
|
};
|
|
10
10
|
const emptySecret = { $metadata: {} };
|
|
11
|
-
const getSecretValueMock =
|
|
12
|
-
|
|
13
|
-
.spyOn(SecretsManager.prototype, "getSecretValue")
|
|
14
|
-
.mockImplementation(getSecretValueMock);
|
|
11
|
+
const getSecretValueMock = vi.fn();
|
|
12
|
+
vi.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
|
|
15
13
|
const { SecretHolder } = await import("../../aws/runtime/secrets/secret-holder.js");
|
|
16
14
|
const { DatabaseEnvironmentKeys } = await import("../../database/database.js");
|
|
17
15
|
function mockSecret(secret) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { afterEach } from "node:test";
|
|
1
2
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
|
-
import {
|
|
3
|
+
import { describe, expect, test, vi } from "vitest";
|
|
3
4
|
import { setEnvVariableAwsRegion } from "../../utils/utils.js";
|
|
4
5
|
const SECRET_ID = "test_secret";
|
|
5
6
|
const SECRET_WITH_PREFIX = {
|
|
@@ -8,10 +9,8 @@ const SECRET_WITH_PREFIX = {
|
|
|
8
9
|
"wrong.value": "value",
|
|
9
10
|
};
|
|
10
11
|
const emptySecret = { $metadata: {} };
|
|
11
|
-
const getSecretValueMock =
|
|
12
|
-
|
|
13
|
-
.spyOn(SecretsManager.prototype, "getSecretValue")
|
|
14
|
-
.mockImplementation(getSecretValueMock);
|
|
12
|
+
const getSecretValueMock = vi.fn();
|
|
13
|
+
vi.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
|
|
15
14
|
function mockSecret(secret) {
|
|
16
15
|
if (!secret) {
|
|
17
16
|
getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
|
|
@@ -27,6 +26,9 @@ setEnvVariableAwsRegion("eu-west-1");
|
|
|
27
26
|
const secret = await import("../../aws/runtime/secrets/secret.js");
|
|
28
27
|
const { getSecret } = secret;
|
|
29
28
|
describe("secret - test", () => {
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
});
|
|
30
32
|
test("getSecret - no secret", async () => {
|
|
31
33
|
mockSecret(null);
|
|
32
34
|
await expect(async () => {
|
|
@@ -2,6 +2,7 @@ import { App, Duration } from "aws-cdk-lib";
|
|
|
2
2
|
import { Match, Template } from "aws-cdk-lib/assertions";
|
|
3
3
|
import { PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
4
4
|
import { Architecture, Code, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
5
6
|
import { FunctionBuilder } from "../../aws/infra/stack/dt-function.js";
|
|
6
7
|
import { DigitrafficStack } from "../../aws/infra/stack/stack.js";
|
|
7
8
|
import { EnvKeys } from "../../aws/runtime/environment.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App } from "aws-cdk-lib";
|
|
2
2
|
import { Match, Template } from "aws-cdk-lib/assertions";
|
|
3
|
+
import { describe, test } from "vitest";
|
|
3
4
|
import { DigitrafficRestApi } from "../../aws/infra/stack/rest-api.js";
|
|
4
5
|
import { DigitrafficStack } from "../../aws/infra/stack/stack.js";
|
|
5
6
|
import { TrafficType } from "../../types/traffictype.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { mockKyResponse } from "../../__test__/mock-ky.js";
|
|
3
3
|
const ky = (await import("ky")).default;
|
|
4
4
|
describe("mockKyResponse", () => {
|
|
@@ -6,61 +6,39 @@ describe("mockKyResponse", () => {
|
|
|
6
6
|
const testJson = JSON.stringify(testObj);
|
|
7
7
|
const url = "https://example.com";
|
|
8
8
|
afterEach(() => {
|
|
9
|
-
|
|
9
|
+
vi.restoreAllMocks();
|
|
10
10
|
});
|
|
11
11
|
test("works with all methods", async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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));
|
|
12
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
13
|
+
vi.spyOn(ky, "post").mockImplementation(() => mockKyResponse(200, testJson));
|
|
14
|
+
vi.spyOn(ky, "put").mockImplementation(() => mockKyResponse(200, testJson));
|
|
15
|
+
vi.spyOn(ky, "delete").mockImplementation(() => mockKyResponse(200, testJson));
|
|
24
16
|
expect(await ky.get(url).text()).toEqual(testJson);
|
|
25
17
|
expect(await ky.put(url).text()).toEqual(testJson);
|
|
26
18
|
expect(await ky.post(url).text()).toEqual(testJson);
|
|
27
19
|
expect(await ky.delete(url).text()).toEqual(testJson);
|
|
28
20
|
});
|
|
29
21
|
test("returns correct status", async () => {
|
|
30
|
-
|
|
31
|
-
.spyOn(ky, "get")
|
|
32
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
22
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
33
23
|
expect((await ky.get(url)).status).toEqual(200);
|
|
34
|
-
|
|
35
|
-
.spyOn(ky, "get")
|
|
36
|
-
.mockImplementation(() => mockKyResponse(400, testJson));
|
|
24
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(400, testJson));
|
|
37
25
|
expect((await ky.get(url)).status).toEqual(400);
|
|
38
26
|
});
|
|
39
27
|
test("returns correct ok", async () => {
|
|
40
|
-
|
|
41
|
-
.spyOn(ky, "get")
|
|
42
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
28
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
43
29
|
expect((await ky.get(url)).ok).toEqual(true);
|
|
44
|
-
|
|
45
|
-
.spyOn(ky, "get")
|
|
46
|
-
.mockImplementation(() => mockKyResponse(299, testJson));
|
|
30
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(299, testJson));
|
|
47
31
|
expect((await ky.get(url)).ok).toEqual(true);
|
|
48
|
-
|
|
49
|
-
.spyOn(ky, "get")
|
|
50
|
-
.mockImplementation(() => mockKyResponse(300, testJson));
|
|
32
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(300, testJson));
|
|
51
33
|
expect((await ky.get(url)).ok).toEqual(false);
|
|
52
34
|
});
|
|
53
35
|
test("convenience methods work: text", async () => {
|
|
54
|
-
|
|
55
|
-
.spyOn(ky, "get")
|
|
56
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
36
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
57
37
|
expect(await ky.get(url).text()).toEqual(testJson);
|
|
58
38
|
expect(await (await ky.get(url)).text()).toEqual(testJson);
|
|
59
39
|
});
|
|
60
40
|
test("convenience methods work: json", async () => {
|
|
61
|
-
|
|
62
|
-
.spyOn(ky, "get")
|
|
63
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
41
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
64
42
|
expect(await ky.get(url).json()).toEqual(testObj);
|
|
65
43
|
expect(await (await ky.get(url)).json()).toEqual(testObj);
|
|
66
44
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
1
2
|
import { LambdaResponseBuilder } from "../../aws/types/lambda-response.js";
|
|
2
3
|
import { decodeBase64ToUtf8 } from "../../utils/base64.js";
|
|
3
4
|
import { TEST_FILENAME, TEST_JSON, TEST_MESSAGE, TEST_TIMESTAMP, TEST_TIMESTAMP_STR, } from "./lambda-response.test.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
1
2
|
import { compressBuffer, decodeBase64ToAscii, decodeBase64ToUtf8, encodeAsciiToBase64, encodeUtf8ToBase64, } from "../../utils/base64.js";
|
|
2
3
|
describe("Base64UtilTest", () => {
|
|
3
4
|
const EXPECTED_ASCII = "0a9f4967-faaa-445a-ba11-078f7f9556b4";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Writable } from "node:stream";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DtLogger } from "../../aws/runtime/dt-logger.js";
|
|
3
4
|
import { logException, truncateEnd, truncateMiddle, } from "../../utils/logging.js";
|
|
4
5
|
const TEST_METHODNAME = "test.logException";
|
|
@@ -2,6 +2,7 @@ import { Duration } from "aws-cdk-lib";
|
|
|
2
2
|
import type { ISecurityGroup } from "aws-cdk-lib/aws-ec2";
|
|
3
3
|
import type { IRole } from "aws-cdk-lib/aws-iam";
|
|
4
4
|
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
5
|
+
import type { ILayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
5
6
|
import { Architecture, Function as AwsFunction, Code, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
6
7
|
import { DtFunctionAlarms } from "./dt-function-alarms.js";
|
|
7
8
|
import type { LambdaEnvironment } from "./lambda-configs.js";
|
|
@@ -22,6 +23,7 @@ export declare class FunctionBuilder {
|
|
|
22
23
|
private alarms;
|
|
23
24
|
private code;
|
|
24
25
|
private handler;
|
|
26
|
+
private readonly layers;
|
|
25
27
|
private readonly securityGroups;
|
|
26
28
|
private readonly policyStatements;
|
|
27
29
|
private readonly allowedActions;
|
|
@@ -73,6 +75,10 @@ export declare class FunctionBuilder {
|
|
|
73
75
|
* Set runtime for the lambda. Default is Runtime.NODEJS_24_X.
|
|
74
76
|
*/
|
|
75
77
|
withRuntime(runtime: Runtime): this;
|
|
78
|
+
/**
|
|
79
|
+
* Add Lambda layers.
|
|
80
|
+
*/
|
|
81
|
+
withLayers(...layers: ILayerVersion[]): this;
|
|
76
82
|
/**
|
|
77
83
|
* Set architecture for the lambda. Default is Architecture.ARM_64.
|
|
78
84
|
*/
|
|
@@ -25,6 +25,7 @@ export class FunctionBuilder {
|
|
|
25
25
|
// these will be overridden in constructor, but inspection won't see it, so set some default values.
|
|
26
26
|
code = Code.fromInline("placeholder");
|
|
27
27
|
handler = "";
|
|
28
|
+
layers = [];
|
|
28
29
|
securityGroups = [];
|
|
29
30
|
policyStatements = [];
|
|
30
31
|
allowedActions = [];
|
|
@@ -133,6 +134,13 @@ export class FunctionBuilder {
|
|
|
133
134
|
this.runtime = runtime;
|
|
134
135
|
return this;
|
|
135
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Add Lambda layers.
|
|
139
|
+
*/
|
|
140
|
+
withLayers(...layers) {
|
|
141
|
+
this.layers.push(...layers);
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
136
144
|
/**
|
|
137
145
|
* Set architecture for the lambda. Default is Architecture.ARM_64.
|
|
138
146
|
*/
|
|
@@ -230,6 +238,7 @@ export class FunctionBuilder {
|
|
|
230
238
|
securityGroups,
|
|
231
239
|
environment: this.getEnvironment(),
|
|
232
240
|
description: this.description,
|
|
241
|
+
layers: this.layers.length > 0 ? this.layers : undefined,
|
|
233
242
|
});
|
|
234
243
|
if (this._features.secretAccess) {
|
|
235
244
|
this._stack.grantSecret(createdFunction);
|
|
@@ -8,7 +8,12 @@ import { kebabCase } from "change-case";
|
|
|
8
8
|
import { snakeCase } from "es-toolkit";
|
|
9
9
|
import { DigitrafficStack, SOLUTION_KEY } from "./stack.js";
|
|
10
10
|
const MAX_CONCURRENCY_LIMIT = 100;
|
|
11
|
-
const
|
|
11
|
+
const ALLOWED_RUNTIMES = [
|
|
12
|
+
Runtime.NODEJS_24_X.name,
|
|
13
|
+
Runtime.NODEJS_22_X.name,
|
|
14
|
+
Runtime.PYTHON_3_12.name,
|
|
15
|
+
Runtime.PYTHON_3_13.name,
|
|
16
|
+
];
|
|
12
17
|
var ResourceType;
|
|
13
18
|
(function (ResourceType) {
|
|
14
19
|
ResourceType["stackName"] = "STACK_NAME";
|
|
@@ -88,7 +93,8 @@ export class StackCheckingAspect {
|
|
|
88
93
|
if (!node.memorySize) {
|
|
89
94
|
this.addAnnotation(node, ResourceType.functionMemorySize, "Function must have memorySize");
|
|
90
95
|
}
|
|
91
|
-
if (node.runtime !== undefined &&
|
|
96
|
+
if (node.runtime !== undefined &&
|
|
97
|
+
!ALLOWED_RUNTIMES.includes(node.runtime)) {
|
|
92
98
|
this.addAnnotation(node, ResourceType.functionRuntime, `Function has wrong runtime ${node.runtime}!`);
|
|
93
99
|
}
|
|
94
100
|
if (this.stackShortName &&
|