@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.
Files changed (238) hide show
  1. package/README.md +18 -1
  2. package/dist/__test__/asserter.d.ts +13 -0
  3. package/dist/__test__/asserter.js +39 -0
  4. package/dist/__test__/db-testutils.d.ts +3 -0
  5. package/dist/__test__/db-testutils.js +38 -0
  6. package/dist/__test__/dependencies.test.d.ts +1 -0
  7. package/dist/__test__/dependencies.test.js +21 -0
  8. package/dist/__test__/imports.test.d.ts +1 -0
  9. package/dist/__test__/imports.test.js +318 -0
  10. package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
  11. package/dist/__test__/infra/acl-builder.test.js +72 -0
  12. package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
  13. package/dist/__test__/infra/api/handler-factory.test.js +42 -0
  14. package/dist/__test__/infra/api/integration.test.d.ts +1 -0
  15. package/dist/__test__/infra/api/integration.test.js +162 -0
  16. package/dist/__test__/infra/api/response.test.d.ts +1 -0
  17. package/dist/__test__/infra/api/response.test.js +77 -0
  18. package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
  19. package/dist/__test__/infra/api/static-integration.test.js +35 -0
  20. package/dist/__test__/infra/documentation.test.d.ts +1 -0
  21. package/dist/__test__/infra/documentation.test.js +38 -0
  22. package/dist/__test__/infra/scheduler.test.d.ts +1 -0
  23. package/dist/__test__/infra/scheduler.test.js +23 -0
  24. package/dist/__test__/infra/security-rule.test.d.ts +1 -0
  25. package/dist/__test__/infra/security-rule.test.js +21 -0
  26. package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
  27. package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
  28. package/dist/__test__/marine/id_utils.test.d.ts +1 -0
  29. package/dist/__test__/marine/id_utils.test.js +45 -0
  30. package/dist/__test__/mock-ky.d.ts +2 -0
  31. package/dist/__test__/mock-ky.js +15 -0
  32. package/dist/__test__/promise/promise.test.d.ts +1 -0
  33. package/dist/__test__/promise/promise.test.js +126 -0
  34. package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
  35. package/dist/__test__/runtime/dt-logger.test.js +193 -0
  36. package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
  37. package/dist/__test__/secrets/secret-holder.test.js +96 -0
  38. package/dist/__test__/secrets/secret.test.d.ts +1 -0
  39. package/dist/__test__/secrets/secret.test.js +57 -0
  40. package/dist/__test__/stack/dt-function.test.d.ts +1 -0
  41. package/dist/__test__/stack/dt-function.test.js +340 -0
  42. package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
  43. package/dist/__test__/stack/rest-apis.test.js +45 -0
  44. package/dist/__test__/test/mock-ky.test.d.ts +1 -0
  45. package/dist/__test__/test/mock-ky.test.js +46 -0
  46. package/dist/__test__/testutils.d.ts +12 -0
  47. package/dist/__test__/testutils.js +32 -0
  48. package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
  49. package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
  50. package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
  51. package/dist/__test__/types/lambda-response-builder.test.js +81 -0
  52. package/dist/__test__/types/lambda-response.test.d.ts +9 -0
  53. package/dist/__test__/types/lambda-response.test.js +73 -0
  54. package/dist/__test__/utils/base64.test.d.ts +1 -0
  55. package/dist/__test__/utils/base64.test.js +38 -0
  56. package/dist/__test__/utils/date-utils.test.d.ts +1 -0
  57. package/dist/__test__/utils/date-utils.test.js +32 -0
  58. package/dist/__test__/utils/geometry.test.d.ts +1 -0
  59. package/dist/__test__/utils/geometry.test.js +25 -0
  60. package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
  61. package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
  62. package/dist/__test__/utils/logging.test.d.ts +1 -0
  63. package/dist/__test__/utils/logging.test.js +75 -0
  64. package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
  65. package/dist/__test__/utils/stop-watch.test.js +118 -0
  66. package/dist/__test__/utils/utils.test.d.ts +1 -0
  67. package/dist/__test__/utils/utils.test.js +48 -0
  68. package/dist/aws/infra/acl-builder.d.ts +53 -0
  69. package/dist/aws/infra/acl-builder.js +407 -0
  70. package/dist/aws/infra/api/handler-factory.d.ts +22 -0
  71. package/dist/aws/infra/api/handler-factory.js +68 -0
  72. package/dist/aws/infra/api/integration.d.ts +49 -0
  73. package/dist/aws/infra/api/integration.js +162 -0
  74. package/dist/aws/infra/api/response.d.ts +62 -0
  75. package/dist/aws/infra/api/response.js +132 -0
  76. package/dist/aws/infra/api/responses.d.ts +60 -0
  77. package/dist/aws/infra/api/responses.js +90 -0
  78. package/dist/aws/infra/api/static-integration.d.ts +16 -0
  79. package/dist/aws/infra/api/static-integration.js +76 -0
  80. package/dist/aws/infra/bucket-policy.d.ts +38 -0
  81. package/dist/aws/infra/bucket-policy.js +30 -0
  82. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  83. package/dist/aws/infra/canaries/canary-alarm.js +20 -0
  84. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  85. package/dist/aws/infra/canaries/canary-keys.js +4 -0
  86. package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
  87. package/dist/aws/infra/canaries/canary-parameters.js +2 -0
  88. package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
  89. package/dist/aws/infra/canaries/canary-role.js +51 -0
  90. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  91. package/dist/aws/infra/canaries/canary.js +26 -0
  92. package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
  93. package/dist/aws/infra/canaries/database-canary.js +65 -0
  94. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  95. package/dist/aws/infra/canaries/database-checker.js +119 -0
  96. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  97. package/dist/aws/infra/canaries/url-canary.js +55 -0
  98. package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
  99. package/dist/aws/infra/canaries/url-checker.js +256 -0
  100. package/dist/aws/infra/documentation.d.ts +56 -0
  101. package/dist/aws/infra/documentation.js +90 -0
  102. package/dist/aws/infra/import-util.d.ts +17 -0
  103. package/dist/aws/infra/import-util.js +41 -0
  104. package/dist/aws/infra/scheduler.d.ts +12 -0
  105. package/dist/aws/infra/scheduler.js +27 -0
  106. package/dist/aws/infra/security-rule.d.ts +12 -0
  107. package/dist/aws/infra/security-rule.js +35 -0
  108. package/dist/aws/infra/sqs-integration.d.ts +4 -0
  109. package/dist/aws/infra/sqs-integration.js +85 -0
  110. package/dist/aws/infra/sqs-queue.d.ts +19 -0
  111. package/dist/aws/infra/sqs-queue.js +145 -0
  112. package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
  113. package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
  114. package/dist/aws/infra/stack/dt-function.d.ts +124 -0
  115. package/dist/aws/infra/stack/dt-function.js +315 -0
  116. package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
  117. package/dist/aws/infra/stack/lambda-configs.js +71 -0
  118. package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
  119. package/dist/aws/infra/stack/lambda-log-group.js +24 -0
  120. package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
  121. package/dist/aws/infra/stack/monitoredfunction.js +147 -0
  122. package/dist/aws/infra/stack/parameters.d.ts +40 -0
  123. package/dist/aws/infra/stack/parameters.js +50 -0
  124. package/dist/aws/infra/stack/rest-api.d.ts +74 -0
  125. package/dist/aws/infra/stack/rest-api.js +235 -0
  126. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
  127. package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
  128. package/dist/aws/infra/stack/stack.d.ts +56 -0
  129. package/dist/aws/infra/stack/stack.js +71 -0
  130. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  131. package/dist/aws/infra/stack/subscription.js +37 -0
  132. package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
  133. package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
  134. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
  135. package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
  136. package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
  137. package/dist/aws/infra/stacks/db-stack.js +189 -0
  138. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  139. package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
  140. package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
  141. package/dist/aws/infra/stacks/network-stack.js +45 -0
  142. package/dist/aws/infra/usage-plans.d.ts +16 -0
  143. package/dist/aws/infra/usage-plans.js +38 -0
  144. package/dist/aws/runtime/apikey.d.ts +2 -0
  145. package/dist/aws/runtime/apikey.js +13 -0
  146. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  147. package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
  148. package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
  149. package/dist/aws/runtime/dt-logger-default.js +6 -0
  150. package/dist/aws/runtime/dt-logger.d.ts +117 -0
  151. package/dist/aws/runtime/dt-logger.js +159 -0
  152. package/dist/aws/runtime/environment.d.ts +5 -0
  153. package/dist/aws/runtime/environment.js +7 -0
  154. package/dist/aws/runtime/s3.d.ts +3 -0
  155. package/dist/aws/runtime/s3.js +21 -0
  156. package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
  157. package/dist/aws/runtime/secrets/dbsecret.js +26 -0
  158. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  159. package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
  160. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  161. package/dist/aws/runtime/secrets/rds-holder.js +25 -0
  162. package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
  163. package/dist/aws/runtime/secrets/secret-holder.js +81 -0
  164. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  165. package/dist/aws/runtime/secrets/secret.js +61 -0
  166. package/dist/aws/types/errors.d.ts +8 -0
  167. package/dist/aws/types/errors.js +13 -0
  168. package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
  169. package/dist/aws/types/lambda-proxy-types.js +210 -0
  170. package/dist/aws/types/lambda-response.d.ts +89 -0
  171. package/dist/aws/types/lambda-response.js +204 -0
  172. package/dist/aws/types/mediatypes.d.ts +11 -0
  173. package/dist/aws/types/mediatypes.js +14 -0
  174. package/dist/aws/types/model-with-reference.d.ts +7 -0
  175. package/dist/aws/types/model-with-reference.js +2 -0
  176. package/dist/aws/types/tags.d.ts +2 -0
  177. package/dist/aws/types/tags.js +4 -0
  178. package/dist/database/database.d.ts +27 -0
  179. package/dist/database/database.js +95 -0
  180. package/dist/database/last-updated.d.ts +15 -0
  181. package/dist/database/last-updated.js +46 -0
  182. package/dist/database/models.d.ts +6 -0
  183. package/dist/database/models.js +2 -0
  184. package/dist/index.d.ts +2 -0
  185. package/dist/index.js +2 -0
  186. package/dist/marine/id_utils.d.ts +3 -0
  187. package/dist/marine/id_utils.js +36 -0
  188. package/dist/marine/rtz.d.ts +48 -0
  189. package/dist/marine/rtz.js +2 -0
  190. package/dist/types/async-timeout-error.d.ts +3 -0
  191. package/dist/types/async-timeout-error.js +6 -0
  192. package/dist/types/either.d.ts +9 -0
  193. package/dist/types/either.js +2 -0
  194. package/dist/types/geojson.d.ts +47 -0
  195. package/dist/types/geojson.js +51 -0
  196. package/dist/types/http-error.d.ts +4 -0
  197. package/dist/types/http-error.js +8 -0
  198. package/dist/types/input-error.d.ts +2 -0
  199. package/dist/types/input-error.js +3 -0
  200. package/dist/types/language.d.ts +5 -0
  201. package/dist/types/language.js +7 -0
  202. package/dist/types/nullable.d.ts +24 -0
  203. package/dist/types/nullable.js +2 -0
  204. package/dist/types/openapi-schema.d.ts +932 -0
  205. package/dist/types/openapi-schema.js +151 -0
  206. package/dist/types/traffictype.d.ts +11 -0
  207. package/dist/types/traffictype.js +13 -0
  208. package/dist/types/urn.d.ts +1 -0
  209. package/dist/types/urn.js +2 -0
  210. package/dist/types/util-types.d.ts +11 -0
  211. package/dist/types/util-types.js +2 -0
  212. package/dist/types/validator.d.ts +4 -0
  213. package/dist/types/validator.js +9 -0
  214. package/dist/utils/api-model.d.ts +51 -0
  215. package/dist/utils/api-model.js +118 -0
  216. package/dist/utils/base64.d.ts +34 -0
  217. package/dist/utils/base64.js +53 -0
  218. package/dist/utils/date-utils.d.ts +27 -0
  219. package/dist/utils/date-utils.js +45 -0
  220. package/dist/utils/geojson-types.d.ts +14 -0
  221. package/dist/utils/geojson-types.js +15 -0
  222. package/dist/utils/geometry.d.ts +44 -0
  223. package/dist/utils/geometry.js +154 -0
  224. package/dist/utils/lambda-proxy-event.d.ts +9 -0
  225. package/dist/utils/lambda-proxy-event.js +31 -0
  226. package/dist/utils/logging.d.ts +40 -0
  227. package/dist/utils/logging.js +88 -0
  228. package/dist/utils/retry.d.ts +33 -0
  229. package/dist/utils/retry.js +135 -0
  230. package/dist/utils/slack.d.ts +5 -0
  231. package/dist/utils/slack.js +24 -0
  232. package/dist/utils/stop-watch.d.ts +46 -0
  233. package/dist/utils/stop-watch.js +114 -0
  234. package/dist/utils/utils.d.ts +95 -0
  235. package/dist/utils/utils.js +178 -0
  236. package/dist/utils/zod-utils.d.ts +27 -0
  237. package/dist/utils/zod-utils.js +57 -0
  238. package/package.json +30 -28
@@ -0,0 +1,162 @@
1
+ import { App, Stack } from "aws-cdk-lib";
2
+ import { Code, Function as LambdaFunction, Runtime, } from "aws-cdk-lib/aws-lambda";
3
+ import velocity from "velocityjs";
4
+ import { describe, expect, test } from "vitest";
5
+ import { DigitrafficIntegration } from "../../../aws/infra/api/integration.js";
6
+ import { MediaType } from "../../../aws/types/mediatypes.js";
7
+ import { decodeBase64ToAscii } from "../../../utils/base64.js";
8
+ describe("integration tests", () => {
9
+ function createTemplate(i) {
10
+ const template = i
11
+ .createRequestTemplates()[MediaType.APPLICATION_JSON].trim();
12
+ // assert template parses
13
+ const response = createResponseFromTemplate(template);
14
+ // assert response parses
15
+ console.info(`response ${response}`);
16
+ return JSON.parse(response);
17
+ }
18
+ function createResponseFromTemplate(template) {
19
+ console.info(`compile ${template}`);
20
+ const compile = new velocity.Compile(velocity.parse(template));
21
+ return compile.render({
22
+ method: {
23
+ request: {
24
+ multivaluequerystring: {
25
+ m1: ["multi1", "multi2"],
26
+ },
27
+ },
28
+ },
29
+ input: {
30
+ body: '{ body: "\'moi" }',
31
+ params: () => ({
32
+ header: {
33
+ h1: "header1",
34
+ },
35
+ querystring: {
36
+ q1: "querystring1",
37
+ q2: "querystring2",
38
+ },
39
+ path: {
40
+ p1: "path1",
41
+ },
42
+ }),
43
+ },
44
+ util: {
45
+ base64Encode: (data) => Buffer.from(data).toString("base64"),
46
+ base64Decode: decodeBase64ToAscii,
47
+ escapeJavaScript: (data) => encodeURIComponent(data),
48
+ parseJson: (data) => JSON.stringify(data),
49
+ },
50
+ context: {
51
+ c1: "context1",
52
+ authorizer: {
53
+ c2: "context2",
54
+ },
55
+ },
56
+ });
57
+ }
58
+ function createIntegration() {
59
+ const app = new App();
60
+ const stack = new Stack(app);
61
+ const f = new LambdaFunction(stack, "id", {
62
+ runtime: Runtime.NODEJS_24_X,
63
+ code: Code.fromInline("placeholder"),
64
+ handler: "handler",
65
+ });
66
+ return new DigitrafficIntegration(f);
67
+ }
68
+ test("no parameters", () => {
69
+ const i = createIntegration();
70
+ const t = createTemplate(i);
71
+ expect(t).toEqual({});
72
+ });
73
+ test("query parameter", () => {
74
+ const i = createIntegration().addQueryParameter("q1");
75
+ const t = createTemplate(i);
76
+ expect(t).toEqual({
77
+ q1: "querystring1",
78
+ });
79
+ });
80
+ test("two query parameters", () => {
81
+ const i = createIntegration()
82
+ .addQueryParameter("q1")
83
+ .addQueryParameter("q2");
84
+ const t = createTemplate(i);
85
+ expect(t).toEqual({
86
+ q1: "querystring1",
87
+ q2: "querystring2",
88
+ });
89
+ });
90
+ test("multivaluequery parameter", () => {
91
+ const i = createIntegration().addMultiValueQueryParameter("m1");
92
+ const t = createTemplate(i);
93
+ expect(t).toEqual({
94
+ m1: ["multi1", "multi2"],
95
+ });
96
+ });
97
+ test("all parameters", () => {
98
+ const i = createIntegration().passAllQueryParameters();
99
+ const t = createTemplate(i);
100
+ expect(t).toEqual({
101
+ q1: "querystring1",
102
+ q2: "querystring2",
103
+ });
104
+ });
105
+ test("path parameter", () => {
106
+ const i = createIntegration().addPathParameter("p1");
107
+ const t = createTemplate(i);
108
+ expect(t).toEqual({
109
+ p1: "path1",
110
+ });
111
+ });
112
+ test("context parameter", () => {
113
+ const i = createIntegration().addContextParameter("c1");
114
+ const t = createTemplate(i);
115
+ expect(t).toEqual({
116
+ c1: "context1",
117
+ });
118
+ });
119
+ test("context parameter authorizer", () => {
120
+ const i = createIntegration().addContextParameter("authorizer.c2");
121
+ const t = createTemplate(i);
122
+ expect(t).toEqual({
123
+ "authorizer.c2": "context2",
124
+ });
125
+ });
126
+ test("all parameters and header", () => {
127
+ const i = createIntegration()
128
+ .passAllQueryParameters()
129
+ .addHeaderParameter("h1");
130
+ const t = createTemplate(i);
131
+ expect(t).toEqual({
132
+ h1: "header1",
133
+ q1: "querystring1",
134
+ q2: "querystring2",
135
+ });
136
+ });
137
+ test("all parameters & parameter - fail", () => {
138
+ expect(() => {
139
+ createIntegration().passAllQueryParameters().addQueryParameter("q1");
140
+ }).toThrow();
141
+ });
142
+ test("path parameters & pass all ", () => {
143
+ const i = createIntegration()
144
+ .addPathParameter("p1")
145
+ .passAllQueryParameters();
146
+ const t = createTemplate(i);
147
+ expect(t).toEqual({
148
+ p1: "path1",
149
+ q1: "querystring1",
150
+ q2: "querystring2",
151
+ });
152
+ });
153
+ test("path body", () => {
154
+ const i = createIntegration().passBody();
155
+ const t = createTemplate(i);
156
+ // body base64-encoded
157
+ expect(t).toEqual({
158
+ payload: "eyBib2R5OiAiJ21vaSIgfQ==",
159
+ });
160
+ });
161
+ });
162
+ //# sourceMappingURL=integration.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import etag from "etag";
2
+ import velocity from "velocityjs";
3
+ import { describe, expect, test } from "vitest";
4
+ import { RESPONSE_DEFAULT_LAMBDA } from "../../../aws/infra/api/response.js";
5
+ const TEST_BODY = "Hello world!";
6
+ describe("response tests", () => {
7
+ function generateEtagValueFromString(body) {
8
+ return generateEtagValueFromBase64String(Buffer.from(body).toString("base64"));
9
+ }
10
+ function generateEtagValueFromBase64String(bodyBase64) {
11
+ return etag(bodyBase64);
12
+ }
13
+ function generateResponse(status, fileName, timestamp) {
14
+ const compile = new velocity.Compile(velocity.parse(RESPONSE_DEFAULT_LAMBDA));
15
+ const output = compile.render({
16
+ input: {
17
+ path: () => ({
18
+ body: Buffer.from(TEST_BODY).toString("base64"),
19
+ status,
20
+ fileName,
21
+ timestamp: timestamp?.toUTCString(),
22
+ etag: generateEtagValueFromString(TEST_BODY),
23
+ }),
24
+ },
25
+ util: {
26
+ base64Decode: (data) => Buffer.from(data, "base64").toString(),
27
+ },
28
+ context: {
29
+ responseOverride: {
30
+ status: undefined,
31
+ header: {
32
+ "Content-Type": undefined,
33
+ "Access-Control-Allow-Origin": undefined,
34
+ ETag: undefined,
35
+ "Last-Modified": undefined,
36
+ "Content-Disposition": undefined,
37
+ },
38
+ },
39
+ },
40
+ });
41
+ // @ts-expect-error: context is not in the type definition
42
+ return [output, compile.context.context];
43
+ }
44
+ function assertOutputAndContext(output, context, status, contentType, fileName, timestamp) {
45
+ expect(output).toEqual(TEST_BODY);
46
+ expect(context).toMatchObject({
47
+ responseOverride: {
48
+ status,
49
+ header: {
50
+ "Content-Type": contentType,
51
+ "Access-Control-Allow-Origin": "*",
52
+ "Content-Disposition": fileName,
53
+ "Last-Modified": timestamp?.toUTCString(),
54
+ ETag: generateEtagValueFromString(TEST_BODY),
55
+ },
56
+ },
57
+ });
58
+ }
59
+ test("test 200", () => {
60
+ const [output, context] = generateResponse(200);
61
+ assertOutputAndContext(output, context);
62
+ });
63
+ test("test 200 - filename", () => {
64
+ const [output, context] = generateResponse(200, "test.txt");
65
+ assertOutputAndContext(output, context, undefined, undefined, 'attachment; filename="test.txt"');
66
+ });
67
+ test("test 200 - filename and timestamp", () => {
68
+ const now = new Date();
69
+ const [output, context] = generateResponse(200, "test.txt", now);
70
+ assertOutputAndContext(output, context, undefined, undefined, 'attachment; filename="test.txt"', now);
71
+ });
72
+ test("test 204", () => {
73
+ const [output, context] = generateResponse(204);
74
+ assertOutputAndContext(output, context, 204, "text/plain");
75
+ });
76
+ });
77
+ //# sourceMappingURL=response.test.js.map
@@ -0,0 +1,35 @@
1
+ import { Model } from "aws-cdk-lib/aws-apigateway";
2
+ import { describe, expect, test } from "vitest";
3
+ import { DigitrafficStaticIntegration } from "../../../aws/infra/api/static-integration.js";
4
+ import { MediaType } from "../../../aws/types/mediatypes.js";
5
+ describe("response tests", () => {
6
+ test("createIntegrationResponse works", () => {
7
+ const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse("FakeResource", MediaType.APPLICATION_JSON, { "test-header": "test-value" });
8
+ expect(integrationResponse).toEqual({
9
+ responseParameters: {
10
+ "method.response.header.test-header": "'test-value'",
11
+ },
12
+ responseTemplates: {
13
+ "application/json": "FakeResource",
14
+ },
15
+ statusCode: "200",
16
+ });
17
+ });
18
+ test("createMethodResponse works", () => {
19
+ const methodResponse = DigitrafficStaticIntegration.createMethodResponse({
20
+ "test-header": "test-value",
21
+ }, MediaType.TEXT_PLAIN, Model.EMPTY_MODEL);
22
+ expect(methodResponse).toEqual({
23
+ responseModels: {
24
+ "text/plain": {
25
+ modelId: "Empty",
26
+ },
27
+ },
28
+ responseParameters: {
29
+ "method.response.header.test-header": true,
30
+ },
31
+ statusCode: "200",
32
+ });
33
+ });
34
+ });
35
+ //# sourceMappingURL=static-integration.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { DocumentationPart } from "../../aws/infra/documentation.js";
3
+ const METHOD_NAME = "test";
4
+ const SUMMARY = "summary";
5
+ const PARAMETER_NAME = "parameter";
6
+ const DESCRIPTION = "description";
7
+ const DEPRECATION_NOTE = "note";
8
+ describe("DocumentationPart tests", () => {
9
+ test("method", () => {
10
+ const part = DocumentationPart.method([], METHOD_NAME, SUMMARY);
11
+ expect(part.type).toEqual("METHOD");
12
+ expect(part.parameterName).toEqual(METHOD_NAME);
13
+ expect(part.documentationProperties.summary).toEqual(SUMMARY);
14
+ expect(part.documentationProperties.deprecated).toBeFalsy();
15
+ });
16
+ test("method - deprecated", () => {
17
+ const part = DocumentationPart.method([], METHOD_NAME, SUMMARY).deprecated(DEPRECATION_NOTE);
18
+ expect(part.type).toEqual("METHOD");
19
+ expect(part.parameterName).toEqual(METHOD_NAME);
20
+ expect(part.documentationProperties.summary).toEqual(`${SUMMARY}. ${DEPRECATION_NOTE}`);
21
+ expect(part.documentationProperties.deprecated).toBeTruthy();
22
+ });
23
+ test("queryparameter", () => {
24
+ const part = DocumentationPart.queryParameter(PARAMETER_NAME, DESCRIPTION);
25
+ expect(part.type).toEqual("QUERY_PARAMETER");
26
+ expect(part.parameterName).toEqual(PARAMETER_NAME);
27
+ expect(part.documentationProperties.description).toEqual(DESCRIPTION);
28
+ expect(part.documentationProperties.deprecated).toBeFalsy();
29
+ });
30
+ test("pathparameter", () => {
31
+ const part = DocumentationPart.pathParameter(PARAMETER_NAME, DESCRIPTION);
32
+ expect(part.type).toEqual("PATH_PARAMETER");
33
+ expect(part.parameterName).toEqual(PARAMETER_NAME);
34
+ expect(part.documentationProperties.description).toEqual(DESCRIPTION);
35
+ expect(part.documentationProperties.deprecated).toBeFalsy();
36
+ });
37
+ });
38
+ //# sourceMappingURL=documentation.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { App, Stack } from "aws-cdk-lib";
2
+ import { Template } from "aws-cdk-lib/assertions";
3
+ import { describe, test } from "vitest";
4
+ import { Scheduler } from "../../aws/infra/scheduler.js";
5
+ describe("scheduler tests", () => {
6
+ function expectRate(createScheduler, expectedRate) {
7
+ const app = new App();
8
+ const stack = new Stack(app);
9
+ createScheduler(stack);
10
+ const template = Template.fromStack(stack);
11
+ template.hasResource("AWS::Events::Rule", {
12
+ Properties: {
13
+ ScheduleExpression: expectedRate,
14
+ State: "ENABLED",
15
+ },
16
+ });
17
+ }
18
+ test("everyMinute", () => expectRate((stack) => Scheduler.everyMinute(stack, "test"), "rate(1 minute)"));
19
+ test("everyMinutes", () => expectRate((stack) => Scheduler.everyMinutes(stack, "test", 12), "rate(12 minutes)"));
20
+ test("everyHour", () => expectRate((stack) => Scheduler.everyHour(stack, "test"), "rate(1 hour)"));
21
+ test("everyDay", () => expectRate((stack) => Scheduler.everyDay(stack, "test"), "rate(1 day)"));
22
+ });
23
+ //# sourceMappingURL=scheduler.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { App, Stack } from "aws-cdk-lib";
2
+ import { Template } from "aws-cdk-lib/assertions";
3
+ import { Topic } from "aws-cdk-lib/aws-sns";
4
+ import { describe, test } from "vitest";
5
+ import { DigitrafficSecurityRule } from "../../aws/infra/security-rule.js";
6
+ describe("security-rule tests", () => {
7
+ test("create", () => {
8
+ const app = new App();
9
+ const stack = new Stack(app);
10
+ const topic = new Topic(stack, "test");
11
+ new DigitrafficSecurityRule(stack, topic);
12
+ const template = Template.fromStack(stack);
13
+ template.hasResource("AWS::Events::Rule", {
14
+ Properties: {
15
+ EventPattern: {},
16
+ State: "ENABLED",
17
+ },
18
+ });
19
+ });
20
+ });
21
+ //# sourceMappingURL=security-rule.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { App } from "aws-cdk-lib";
2
+ import { describe, expect, test } from "vitest";
3
+ import { DigitrafficRestApi } from "../../../aws/infra/stack/rest-api.js";
4
+ import { DigitrafficStack } from "../../../aws/infra/stack/stack.js";
5
+ describe("DigitrafficRestApi tests", () => {
6
+ function createRestApi() {
7
+ const app = new App();
8
+ const stack = new DigitrafficStack(app, "name", {
9
+ shortName: "TEST",
10
+ });
11
+ return new DigitrafficRestApi(stack, "id", "name");
12
+ }
13
+ test("exportEndpoint - no apikeys", () => {
14
+ expect(() => {
15
+ const restApi = createRestApi();
16
+ restApi.exportEndpoint();
17
+ }).toThrow("No apikeys to export");
18
+ });
19
+ test("exportEndpoint - multiple keys", () => {
20
+ expect(() => {
21
+ const restApi = createRestApi();
22
+ restApi.apiKeyIds.push("key1");
23
+ restApi.apiKeyIds.push("key2");
24
+ restApi.exportEndpoint();
25
+ }).toThrow("Multiple apikeys, configure which to export");
26
+ });
27
+ test("exportEndpoint - multiple keys, set key", () => {
28
+ const restApi = createRestApi();
29
+ restApi.apiKeyIds.push("key1");
30
+ restApi.apiKeyIds.push("key2");
31
+ const [sp1, sp2] = restApi.exportEndpoint({
32
+ apiKeyId: "key3",
33
+ });
34
+ expect(sp1.node.id).toEqual("export.endpoint.TEST");
35
+ expect(sp2.node.id).toEqual("export.apiKeyId.TEST");
36
+ });
37
+ test("exportEndpoint - override name", () => {
38
+ const restApi = createRestApi();
39
+ restApi.apiKeyIds.push("key1");
40
+ const [sp1, sp2] = restApi.exportEndpoint({
41
+ exportName: "exp1",
42
+ });
43
+ expect(sp1.node.id).toEqual("export.endpoint.exp1");
44
+ expect(sp2.node.id).toEqual("export.apiKeyId.exp1");
45
+ });
46
+ });
47
+ //# sourceMappingURL=rest-apis.test.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { getRandomNumber } from "../../__test__/testutils.js";
3
+ import * as IdUtils from "../../marine/id_utils.js";
4
+ describe("IdUtils tests", () => {
5
+ test("isValidLOCODE - success", () => {
6
+ expect(IdUtils.isValidLOCODE("FILOL")).toBe(true);
7
+ });
8
+ test("isValidLOCODE - fail with non-finnish prefix", () => {
9
+ expect(IdUtils.isValidLOCODE("SEABS")).toBe(false);
10
+ });
11
+ test("isValidLOCODE - fail with numbers", () => {
12
+ expect(IdUtils.isValidLOCODE("FIAA1")).toBe(false);
13
+ });
14
+ test("isValidIMO - successful checksum - ship TRANSMAR", () => {
15
+ expect(IdUtils.isValidIMO(9167332)).toBe(true);
16
+ });
17
+ test("isValidIMO - successful checksum - ship ANNIKA B", () => {
18
+ expect(IdUtils.isValidIMO(9213715)).toBe(true);
19
+ });
20
+ test("isValidIMO - successful checksum - ship X PRESS ELBE", () => {
21
+ expect(IdUtils.isValidIMO(9483669)).toBe(true);
22
+ });
23
+ test("isValidIMO - successful checksum - ship SILVERFORS", () => {
24
+ expect(IdUtils.isValidIMO(8322765)).toBe(true);
25
+ });
26
+ test("isValidIMO - invalid checksum", () => {
27
+ expect(IdUtils.isValidIMO(8322766)).toBe(false);
28
+ });
29
+ test("isValidIMO - fail with number smaller than 1000000", () => {
30
+ expect(IdUtils.isValidIMO(getRandomNumber(0, 1000000 - 1))).toBe(false);
31
+ });
32
+ test("isValidIMO - fail with number larger than 9999999", () => {
33
+ expect(IdUtils.isValidIMO(getRandomNumber(9999999 + 1, 99999999))).toBe(false);
34
+ });
35
+ test("isValidMMSI - success", () => {
36
+ expect(IdUtils.isValidMMSI(230927000)).toBe(true);
37
+ });
38
+ test("isValidMMSI - fail with number smaller than 100000000", () => {
39
+ expect(IdUtils.isValidMMSI(getRandomNumber(0, 100000000 - 1))).toBe(false);
40
+ });
41
+ test("isValidMMSI - fail with number larger than 999999999", () => {
42
+ expect(IdUtils.isValidMMSI(getRandomNumber(999999999 + 1, 9999999999))).toBe(false);
43
+ });
44
+ });
45
+ //# sourceMappingURL=id_utils.test.js.map
@@ -0,0 +1,2 @@
1
+ import type { ResponsePromise } from "ky";
2
+ export declare function mockKyResponse(status: number, body: string): ResponsePromise;
@@ -0,0 +1,15 @@
1
+ export function mockKyResponse(status, body) {
2
+ const response = new Response(body, {
3
+ status: status,
4
+ });
5
+ const promise = Promise.resolve(response);
6
+ // The ky ResponsePromise is just Promise<Response> with some convenience methods.
7
+ return Object.assign(promise, {
8
+ arrayBuffer: () => response.arrayBuffer(),
9
+ blob: () => response.blob(),
10
+ formData: () => response.formData(),
11
+ json: () => response.json(),
12
+ text: () => response.text(),
13
+ });
14
+ }
15
+ //# sourceMappingURL=mock-ky.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ import { describe, expect, test, vi } from "vitest";
2
+ import { getRandomInteger } from "../../__test__/testutils.js";
3
+ import { logger } from "../../aws/runtime/dt-logger-default.js";
4
+ import { RetryLogError, retry } from "../../utils/retry.js";
5
+ vi.useFakeTimers();
6
+ describe("Promise utils tests", () => {
7
+ test("retry - no retries", async () => {
8
+ const fn = vi.fn(() => Promise.resolve(1));
9
+ const ret = await retry(fn, 0, RetryLogError.NO_LOGGING);
10
+ expect(ret).toBe(1);
11
+ expect(fn.mock.calls.length).toBe(1);
12
+ });
13
+ test("retry - error with n+1 retries", async () => {
14
+ const fn = vi.fn(() => Promise.reject("error"));
15
+ const retries = getRandomInteger(1, 10);
16
+ try {
17
+ await retry(fn, retries, RetryLogError.NO_LOGGING);
18
+ }
19
+ catch {
20
+ // ignore
21
+ }
22
+ finally {
23
+ expect(fn.mock.calls.length).toBe(retries + 1);
24
+ }
25
+ });
26
+ test("retry - no error with n+1 retries", async () => {
27
+ const fn = vi.fn(() => Promise.resolve(1));
28
+ const retries = getRandomInteger(1, 10);
29
+ const ret = await retry(fn, retries, RetryLogError.NO_LOGGING);
30
+ expect(ret).toBe(1);
31
+ expect(fn.mock.calls.length).toBe(1);
32
+ });
33
+ test("retry - errors with no error logging", async () => {
34
+ const fn = vi.fn(() => Promise.reject("error"));
35
+ const consoleErrorSpy = vi.spyOn(logger, "error");
36
+ try {
37
+ await retry(fn, getRandomInteger(0, 10), RetryLogError.NO_LOGGING);
38
+ }
39
+ catch {
40
+ // ignore
41
+ }
42
+ finally {
43
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
44
+ consoleErrorSpy.mockRestore();
45
+ }
46
+ });
47
+ test("retry - no retries with error logging", async () => {
48
+ const fn = vi.fn(() => Promise.reject("error"));
49
+ const consoleErrorSpy = vi.spyOn(logger, "error");
50
+ try {
51
+ await retry(fn, 0, RetryLogError.LOG_ALL_AS_ERRORS);
52
+ }
53
+ catch {
54
+ // ignore
55
+ }
56
+ finally {
57
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
58
+ consoleErrorSpy.mockRestore();
59
+ }
60
+ });
61
+ test("retry - retries with error logging", async () => {
62
+ const fn = vi.fn(() => Promise.reject("error"));
63
+ const retries = getRandomInteger(1, 10);
64
+ const consoleErrorSpy = vi.spyOn(logger, "error");
65
+ try {
66
+ await retry(fn, retries, RetryLogError.LOG_ALL_AS_ERRORS);
67
+ }
68
+ catch {
69
+ // ignore
70
+ }
71
+ finally {
72
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(retries + 1);
73
+ consoleErrorSpy.mockRestore();
74
+ }
75
+ });
76
+ test("retry - exceeded retry count throws error", async () => {
77
+ const fn = vi.fn(() => Promise.reject("error"));
78
+ await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
79
+ });
80
+ test("retry - defaults", async () => {
81
+ const fn = vi.fn(() => Promise.reject("error"));
82
+ const consoleErrorSpy = vi.spyOn(logger, "error");
83
+ try {
84
+ await retry(fn);
85
+ }
86
+ catch {
87
+ // ignore
88
+ }
89
+ finally {
90
+ expect(fn.mock.calls.length).toBe(3 + 1);
91
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1); // last retry
92
+ }
93
+ });
94
+ test("retry - NaN throws error", async () => {
95
+ const fn = vi.fn(() => Promise.resolve(NaN));
96
+ await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
97
+ });
98
+ test("retry - Infinity throws error", async () => {
99
+ const fn = vi.fn(() => Promise.resolve(NaN));
100
+ await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
101
+ });
102
+ test("retry - exceeded maximum retry count throws error", async () => {
103
+ const fn = vi.fn(() => Promise.resolve(NaN));
104
+ await expect(() => retry(fn, getRandomInteger(101, 1000000), RetryLogError.NO_LOGGING)).rejects.toThrow();
105
+ });
106
+ test("retry - use without mocks without retry", async () => {
107
+ const val = 1;
108
+ const fn = () => Promise.resolve(val);
109
+ const ret = await retry(fn);
110
+ expect(ret).toBe(val);
111
+ });
112
+ test("retry - use without mocks with retry", async () => {
113
+ let i = 0;
114
+ const val = 1;
115
+ const fn = () => {
116
+ if (i < 3) {
117
+ i++;
118
+ throw new Error("not yet");
119
+ }
120
+ return Promise.resolve(val);
121
+ };
122
+ const ret = await retry(fn);
123
+ expect(ret).toBe(val);
124
+ });
125
+ });
126
+ //# sourceMappingURL=promise.test.js.map
@@ -0,0 +1 @@
1
+ export {};