@digitraffic/common 2026.3.17-1 → 2026.3.26-1-beta
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/README.md +18 -1
- package/dist/__test__/asserter.d.ts +13 -0
- package/dist/__test__/asserter.js +39 -0
- package/dist/__test__/db-testutils.d.ts +3 -0
- package/dist/__test__/db-testutils.js +38 -0
- package/dist/__test__/dependencies.test.d.ts +1 -0
- package/dist/__test__/dependencies.test.js +21 -0
- package/dist/__test__/imports.test.d.ts +1 -0
- package/dist/__test__/imports.test.js +318 -0
- package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
- package/dist/__test__/infra/acl-builder.test.js +72 -0
- package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
- package/dist/__test__/infra/api/handler-factory.test.js +42 -0
- package/dist/__test__/infra/api/integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/integration.test.js +162 -0
- package/dist/__test__/infra/api/response.test.d.ts +1 -0
- package/dist/__test__/infra/api/response.test.js +77 -0
- package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
- package/dist/__test__/infra/api/static-integration.test.js +35 -0
- package/dist/__test__/infra/documentation.test.d.ts +1 -0
- package/dist/__test__/infra/documentation.test.js +38 -0
- package/dist/__test__/infra/scheduler.test.d.ts +1 -0
- package/dist/__test__/infra/scheduler.test.js +23 -0
- package/dist/__test__/infra/security-rule.test.d.ts +1 -0
- package/dist/__test__/infra/security-rule.test.js +21 -0
- package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
- package/dist/__test__/marine/id_utils.test.d.ts +1 -0
- package/dist/__test__/marine/id_utils.test.js +45 -0
- package/dist/__test__/mock-ky.d.ts +2 -0
- package/dist/__test__/mock-ky.js +15 -0
- package/dist/__test__/promise/promise.test.d.ts +1 -0
- package/dist/__test__/promise/promise.test.js +126 -0
- package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
- package/dist/__test__/runtime/dt-logger.test.js +193 -0
- package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
- package/dist/__test__/secrets/secret-holder.test.js +96 -0
- package/dist/__test__/secrets/secret.test.d.ts +1 -0
- package/dist/__test__/secrets/secret.test.js +57 -0
- package/dist/__test__/stack/dt-function.test.d.ts +1 -0
- package/dist/__test__/stack/dt-function.test.js +340 -0
- package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
- package/dist/__test__/stack/rest-apis.test.js +45 -0
- package/dist/__test__/test/mock-ky.test.d.ts +1 -0
- package/dist/__test__/test/mock-ky.test.js +46 -0
- package/dist/__test__/testutils.d.ts +12 -0
- package/dist/__test__/testutils.js +32 -0
- package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
- package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
- package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
- package/dist/__test__/types/lambda-response-builder.test.js +81 -0
- package/dist/__test__/types/lambda-response.test.d.ts +9 -0
- package/dist/__test__/types/lambda-response.test.js +73 -0
- package/dist/__test__/utils/base64.test.d.ts +1 -0
- package/dist/__test__/utils/base64.test.js +38 -0
- package/dist/__test__/utils/date-utils.test.d.ts +1 -0
- package/dist/__test__/utils/date-utils.test.js +32 -0
- package/dist/__test__/utils/geometry.test.d.ts +1 -0
- package/dist/__test__/utils/geometry.test.js +25 -0
- package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
- package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
- package/dist/__test__/utils/logging.test.d.ts +1 -0
- package/dist/__test__/utils/logging.test.js +75 -0
- package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
- package/dist/__test__/utils/stop-watch.test.js +118 -0
- package/dist/__test__/utils/utils.test.d.ts +1 -0
- package/dist/__test__/utils/utils.test.js +48 -0
- package/dist/aws/infra/acl-builder.d.ts +53 -0
- package/dist/aws/infra/acl-builder.js +407 -0
- package/dist/aws/infra/api/handler-factory.d.ts +22 -0
- package/dist/aws/infra/api/handler-factory.js +68 -0
- package/dist/aws/infra/api/integration.d.ts +49 -0
- package/dist/aws/infra/api/integration.js +162 -0
- package/dist/aws/infra/api/response.d.ts +62 -0
- package/dist/aws/infra/api/response.js +132 -0
- package/dist/aws/infra/api/responses.d.ts +60 -0
- package/dist/aws/infra/api/responses.js +90 -0
- package/dist/aws/infra/api/static-integration.d.ts +16 -0
- package/dist/aws/infra/api/static-integration.js +76 -0
- package/dist/aws/infra/bucket-policy.d.ts +38 -0
- package/dist/aws/infra/bucket-policy.js +30 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-alarm.js +20 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js +4 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
- package/dist/aws/infra/canaries/canary-parameters.js +2 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
- package/dist/aws/infra/canaries/canary-role.js +51 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/canary.js +26 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
- package/dist/aws/infra/canaries/database-canary.js +65 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
- package/dist/aws/infra/canaries/database-checker.js +119 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-canary.js +55 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
- package/dist/aws/infra/canaries/url-checker.js +256 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/documentation.js +90 -0
- package/dist/aws/infra/import-util.d.ts +17 -0
- package/dist/aws/infra/import-util.js +41 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/scheduler.js +27 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/security-rule.js +35 -0
- package/dist/aws/infra/sqs-integration.d.ts +4 -0
- package/dist/aws/infra/sqs-integration.js +85 -0
- package/dist/aws/infra/sqs-queue.d.ts +19 -0
- package/dist/aws/infra/sqs-queue.js +145 -0
- package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
- package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
- package/dist/aws/infra/stack/dt-function.d.ts +124 -0
- package/dist/aws/infra/stack/dt-function.js +315 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
- package/dist/aws/infra/stack/lambda-configs.js +71 -0
- package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
- package/dist/aws/infra/stack/lambda-log-group.js +24 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
- package/dist/aws/infra/stack/monitoredfunction.js +147 -0
- package/dist/aws/infra/stack/parameters.d.ts +40 -0
- package/dist/aws/infra/stack/parameters.js +50 -0
- package/dist/aws/infra/stack/rest-api.d.ts +74 -0
- package/dist/aws/infra/stack/rest-api.js +235 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
- package/dist/aws/infra/stack/stack.d.ts +56 -0
- package/dist/aws/infra/stack/stack.js +71 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stack/subscription.js +37 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
- package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
- package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
- package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
- package/dist/aws/infra/stacks/db-stack.js +189 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
- package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
- package/dist/aws/infra/stacks/network-stack.js +45 -0
- package/dist/aws/infra/usage-plans.d.ts +16 -0
- package/dist/aws/infra/usage-plans.js +38 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
- package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
- package/dist/aws/runtime/dt-logger-default.js +6 -0
- package/dist/aws/runtime/dt-logger.d.ts +117 -0
- package/dist/aws/runtime/dt-logger.js +159 -0
- package/dist/aws/runtime/environment.d.ts +5 -0
- package/dist/aws/runtime/environment.js +7 -0
- package/dist/aws/runtime/s3.d.ts +3 -0
- package/dist/aws/runtime/s3.js +21 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
- package/dist/aws/runtime/secrets/dbsecret.js +26 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.js +25 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
- package/dist/aws/runtime/secrets/secret-holder.js +81 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/runtime/secrets/secret.js +61 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/errors.js +13 -0
- package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
- package/dist/aws/types/lambda-proxy-types.js +210 -0
- package/dist/aws/types/lambda-response.d.ts +89 -0
- package/dist/aws/types/lambda-response.js +204 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/mediatypes.js +14 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/model-with-reference.js +2 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/aws/types/tags.js +4 -0
- package/dist/database/database.d.ts +27 -0
- package/dist/database/database.js +95 -0
- package/dist/database/last-updated.d.ts +15 -0
- package/dist/database/last-updated.js +46 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/id_utils.js +36 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/marine/rtz.js +2 -0
- package/dist/types/async-timeout-error.d.ts +3 -0
- package/dist/types/async-timeout-error.js +6 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js +2 -0
- package/dist/types/geojson.d.ts +47 -0
- package/dist/types/geojson.js +51 -0
- package/dist/types/http-error.d.ts +4 -0
- package/dist/types/http-error.js +8 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/input-error.js +3 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/language.js +7 -0
- package/dist/types/nullable.d.ts +24 -0
- package/dist/types/nullable.js +2 -0
- package/dist/types/openapi-schema.d.ts +932 -0
- package/dist/types/openapi-schema.js +151 -0
- package/dist/types/traffictype.d.ts +11 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/urn.d.ts +1 -0
- package/dist/types/urn.js +2 -0
- package/dist/types/util-types.d.ts +11 -0
- package/dist/types/util-types.js +2 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/types/validator.js +9 -0
- package/dist/utils/api-model.d.ts +51 -0
- package/dist/utils/api-model.js +118 -0
- package/dist/utils/base64.d.ts +34 -0
- package/dist/utils/base64.js +53 -0
- package/dist/utils/date-utils.d.ts +27 -0
- package/dist/utils/date-utils.js +45 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geojson-types.js +15 -0
- package/dist/utils/geometry.d.ts +44 -0
- package/dist/utils/geometry.js +154 -0
- package/dist/utils/lambda-proxy-event.d.ts +9 -0
- package/dist/utils/lambda-proxy-event.js +31 -0
- package/dist/utils/logging.d.ts +40 -0
- package/dist/utils/logging.js +88 -0
- package/dist/utils/retry.d.ts +33 -0
- package/dist/utils/retry.js +135 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/slack.js +24 -0
- package/dist/utils/stop-watch.d.ts +46 -0
- package/dist/utils/stop-watch.js +114 -0
- package/dist/utils/utils.d.ts +95 -0
- package/dist/utils/utils.js +178 -0
- package/dist/utils/zod-utils.d.ts +27 -0
- package/dist/utils/zod-utils.js +57 -0
- package/package.json +30 -28
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Writable } from "node:stream";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { DtLogger } from "../../aws/runtime/dt-logger.js";
|
|
4
|
+
import { logException, truncateEnd, truncateMiddle, } from "../../utils/logging.js";
|
|
5
|
+
const TEST_METHODNAME = "test.logException";
|
|
6
|
+
describe("logging-test", () => {
|
|
7
|
+
function assertLogError(error, expected, includeStack = false) {
|
|
8
|
+
assertWrite((logger) => {
|
|
9
|
+
logException(logger, error, includeStack);
|
|
10
|
+
}, expected);
|
|
11
|
+
}
|
|
12
|
+
function assertWrite(writeFunction, expected) {
|
|
13
|
+
const logged = [];
|
|
14
|
+
const writeStream = new Writable({
|
|
15
|
+
write: (chunk) => {
|
|
16
|
+
logged.push(chunk.toString());
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const logger = new DtLogger({
|
|
20
|
+
...{ writeStream: writeStream },
|
|
21
|
+
});
|
|
22
|
+
writeFunction(logger);
|
|
23
|
+
expect(logged.length).toBe(1);
|
|
24
|
+
const loggedLine = JSON.parse(logged[0]);
|
|
25
|
+
console.info(loggedLine);
|
|
26
|
+
if (expected.stack) {
|
|
27
|
+
const stack = loggedLine.stack;
|
|
28
|
+
delete loggedLine.stack;
|
|
29
|
+
delete expected.stack;
|
|
30
|
+
expect(stack).toBeDefined();
|
|
31
|
+
}
|
|
32
|
+
expect(loggedLine).toMatchObject(expected);
|
|
33
|
+
}
|
|
34
|
+
test("log error - string", () => {
|
|
35
|
+
const STRING_ERROR = "string error";
|
|
36
|
+
assertLogError(STRING_ERROR, {
|
|
37
|
+
type: "Error",
|
|
38
|
+
method: TEST_METHODNAME,
|
|
39
|
+
message: `${TEST_METHODNAME} error=${STRING_ERROR} type=Error`,
|
|
40
|
+
level: "ERROR",
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
test("log error - error", () => {
|
|
44
|
+
const ERROR = new Error("Errormessage");
|
|
45
|
+
assertLogError(ERROR, {
|
|
46
|
+
type: "Error",
|
|
47
|
+
method: TEST_METHODNAME,
|
|
48
|
+
message: `${TEST_METHODNAME} error=${ERROR.message} type=Error`,
|
|
49
|
+
level: "ERROR",
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
test("log error - error with stack", () => {
|
|
53
|
+
const ERROR = new Error("Errormessage");
|
|
54
|
+
assertLogError(ERROR, {
|
|
55
|
+
type: "Error",
|
|
56
|
+
method: TEST_METHODNAME,
|
|
57
|
+
message: `${TEST_METHODNAME} error=${ERROR.message} type=Error`,
|
|
58
|
+
level: "ERROR",
|
|
59
|
+
stack: true,
|
|
60
|
+
}, true);
|
|
61
|
+
});
|
|
62
|
+
test("truncateEnd - not truncated as would be longer", () => {
|
|
63
|
+
expect(truncateEnd("This is a test string", 10)).toBe("This is a test string");
|
|
64
|
+
});
|
|
65
|
+
test("truncateEnd", () => {
|
|
66
|
+
expect(truncateEnd("This is a test string that is long enough", 10)).toBe("This is a [TRUNCATED 31 CHARS]");
|
|
67
|
+
});
|
|
68
|
+
test("truncateMiddle - not truncated as would be longer", () => {
|
|
69
|
+
expect(truncateMiddle("This is a test string", 10)).toBe("This is a test string");
|
|
70
|
+
});
|
|
71
|
+
test("truncateMiddle", () => {
|
|
72
|
+
expect(truncateMiddle("This is a test string that is long enough", 20)).toBe("This is a [TRUNCATED 21 CHARS] ong enough");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=logging.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import * as ArrayUtils from "../../utils/utils.js";
|
|
3
|
+
describe("ArrayUtils", () => {
|
|
4
|
+
test("bothArraysHasSameValues", () => {
|
|
5
|
+
expect(ArrayUtils.bothArraysHasSameValues([], [])).toEqual(true);
|
|
6
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a"], ["a"])).toEqual(true);
|
|
7
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a"], ["a", "a"])).toEqual(true);
|
|
8
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a", "a"], ["a", "a"])).toEqual(true);
|
|
9
|
+
expect(ArrayUtils.bothArraysHasSameValues(null, null)).toEqual(true);
|
|
10
|
+
expect(ArrayUtils.bothArraysHasSameValues(undefined, undefined)).toEqual(true);
|
|
11
|
+
expect(ArrayUtils.bothArraysHasSameValues(null, undefined)).toEqual(true);
|
|
12
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a"], undefined)).toEqual(false);
|
|
13
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a"], null)).toEqual(false);
|
|
14
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a", "b"], ["a", "a"])).toEqual(false);
|
|
15
|
+
expect(ArrayUtils.bothArraysHasSameValues(["a", "a", "a"], ["a", "b", "c"])).toEqual(false);
|
|
16
|
+
const o1 = { a: 1, b: 2 };
|
|
17
|
+
const o2 = { a: 1, b: 2 };
|
|
18
|
+
// Objects are references to same
|
|
19
|
+
expect(ArrayUtils.bothArraysHasSameValues([o1], [o1])).toEqual(true);
|
|
20
|
+
// Object's are not the same but the contents are the same
|
|
21
|
+
expect(ArrayUtils.bothArraysHasSameValues([o1], [o2])).toEqual(false);
|
|
22
|
+
});
|
|
23
|
+
test("getFirst - empty throws", () => {
|
|
24
|
+
expect(() => {
|
|
25
|
+
ArrayUtils.getFirst([]);
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
test("getFirst - two objects", () => {
|
|
29
|
+
expect(ArrayUtils.getFirst([1, 2])).toEqual(1);
|
|
30
|
+
});
|
|
31
|
+
test("getFirst - two objects with sort function", () => {
|
|
32
|
+
expect(ArrayUtils.getFirst([1, 2], (a) => -a)).toEqual(2);
|
|
33
|
+
});
|
|
34
|
+
test("getLast - empty throws", () => {
|
|
35
|
+
expect(() => {
|
|
36
|
+
ArrayUtils.getLast([]);
|
|
37
|
+
}).toThrow();
|
|
38
|
+
});
|
|
39
|
+
test("getLast - two objects", () => {
|
|
40
|
+
expect(ArrayUtils.getLast([1, 2])).toEqual(2);
|
|
41
|
+
});
|
|
42
|
+
test("isDefined", () => {
|
|
43
|
+
expect([1, 2, undefined, null, 3].filter(ArrayUtils.isDefined)).toEqual([
|
|
44
|
+
1, 2, 3,
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CfnWebACL } from "aws-cdk-lib/aws-wafv2";
|
|
2
|
+
import type { Construct } from "constructs";
|
|
3
|
+
export type AWSManagedWafRule = "CommonRuleSet" | "AmazonIpReputationList" | "KnownBadInputsRuleSet" | "SQLiRuleSet";
|
|
4
|
+
export type ExcludedAWSRules = {
|
|
5
|
+
[key in AWSManagedWafRule]?: string[];
|
|
6
|
+
};
|
|
7
|
+
export type CfnWebAclRuleProperty = {
|
|
8
|
+
[P in keyof CfnWebACL.RuleProperty as Exclude<P, "priority">]: CfnWebACL.RuleProperty[P];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builder class for building CfnWebACL.
|
|
12
|
+
*
|
|
13
|
+
* Currently supports:
|
|
14
|
+
* * Some AWS managed WAF rules
|
|
15
|
+
* * IP blacklisting/whitelisting
|
|
16
|
+
*/
|
|
17
|
+
export declare class AclBuilder {
|
|
18
|
+
readonly _construct: Construct;
|
|
19
|
+
readonly _countRules: CfnWebAclRuleProperty[];
|
|
20
|
+
readonly _blockRules: CfnWebAclRuleProperty[];
|
|
21
|
+
readonly _name: string;
|
|
22
|
+
_scope: string;
|
|
23
|
+
_customResponseBodies: Record<string, CfnWebACL.CustomResponseBodyProperty>;
|
|
24
|
+
constructor(construct: Construct, name?: string);
|
|
25
|
+
isRuleDefined(rules: AWSManagedWafRule[] | "all", rule: AWSManagedWafRule): boolean;
|
|
26
|
+
withAWSManagedRules(rules?: AWSManagedWafRule[] | "all", excludedRules?: ExcludedAWSRules): this;
|
|
27
|
+
/**
|
|
28
|
+
* Block access from given addresses
|
|
29
|
+
*/
|
|
30
|
+
withIpBlacklistRule(addresses: string[]): this;
|
|
31
|
+
/**
|
|
32
|
+
* Allow access only from the given addresses
|
|
33
|
+
*/
|
|
34
|
+
withIpWhitelistRule(addresses: string[]): this;
|
|
35
|
+
withThrottleRule(name: string, limit: number, isHeaderRequired: boolean, isBasedOnIpAndUriPath: boolean, customResponseBodyKey?: string, path?: RegExp): this;
|
|
36
|
+
withCustomResponseBody(key: string, customResponseBody: CfnWebACL.CustomResponseBodyProperty): this;
|
|
37
|
+
withThrottleDigitrafficUserIp(limit: number | undefined): this;
|
|
38
|
+
withThrottleDigitrafficUserIpAndUriPath(limit: number | undefined): this;
|
|
39
|
+
withThrottleAnonymousUserIp(limit: number | undefined): AclBuilder;
|
|
40
|
+
withThrottleAnonymousUserIpByUriPath(limit: number | undefined, path: RegExp | undefined): AclBuilder;
|
|
41
|
+
withThrottleAnonymousUserIpAndUriPath(limit: number | undefined): this;
|
|
42
|
+
withCountDigitrafficUserIp(limit: number | undefined): this;
|
|
43
|
+
withCountDigitrafficUserIpAndUriPath(limit: number | undefined): this;
|
|
44
|
+
withCountAnonymousUserIp(limit: number | undefined): this;
|
|
45
|
+
withCountAnonymousUserIpAndUriPath(limit: number | undefined): this;
|
|
46
|
+
/**
|
|
47
|
+
* Block requests with a query string larger than the specified size.
|
|
48
|
+
*/
|
|
49
|
+
withQueryStringSizeRestriction(limit: number): this;
|
|
50
|
+
_isCustomResponseBodyKeySet(key: string): boolean;
|
|
51
|
+
_addThrottleResponseBody(customResponseBodyKey: string, limit: number): void;
|
|
52
|
+
build(): CfnWebACL;
|
|
53
|
+
}
|