@digitraffic/common 2022.10.25-1 → 2022.10.31-1

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 (283) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +4 -0
  3. package/.eslintrc.json +27 -0
  4. package/.github/CODEOWNERS +2 -0
  5. package/.github/workflows/build.yml +36 -0
  6. package/.github/workflows/eslint.yml +38 -0
  7. package/.github/workflows/mirror.yml +15 -0
  8. package/.gitignore +29 -0
  9. package/.husky/pre-commit +4 -0
  10. package/.prettierrc.json +10 -0
  11. package/dist/aws/infra/api/integration.js +52 -0
  12. package/dist/aws/infra/api/response.js +61 -0
  13. package/dist/aws/infra/api/responses.js +82 -0
  14. package/dist/aws/infra/api/static-integration.js +54 -0
  15. package/dist/aws/infra/canaries/canary-alarm.js +26 -0
  16. package/dist/aws/infra/canaries/canary-keys.js +7 -0
  17. package/dist/aws/infra/canaries/canary-parameters.js +3 -0
  18. package/dist/aws/infra/canaries/canary-role.js +46 -0
  19. package/dist/aws/infra/canaries/canary.js +32 -0
  20. package/dist/aws/infra/canaries/database-canary.js +70 -0
  21. package/dist/aws/infra/canaries/database-checker.js +103 -0
  22. package/dist/aws/infra/canaries/url-canary.js +47 -0
  23. package/dist/aws/infra/canaries/url-checker.js +252 -0
  24. package/dist/aws/infra/documentation.js +95 -0
  25. package/dist/aws/infra/scheduler.js +31 -0
  26. package/dist/aws/infra/security-rule.js +39 -0
  27. package/dist/aws/infra/sqs-integration.js +93 -0
  28. package/dist/aws/infra/sqs-queue.js +130 -0
  29. package/dist/aws/infra/stack/lambda-configs.js +105 -0
  30. package/dist/aws/infra/stack/monitoredfunction.js +143 -0
  31. package/dist/aws/infra/stack/rest_apis.js +185 -0
  32. package/dist/aws/infra/stack/stack-checking-aspect.js +174 -0
  33. package/dist/aws/infra/stack/stack.js +67 -0
  34. package/dist/aws/infra/stack/subscription.js +42 -0
  35. package/dist/aws/infra/usage-plans.js +42 -0
  36. package/dist/aws/runtime/apikey.js +13 -0
  37. package/dist/aws/runtime/digitraffic-integration-response.js +26 -0
  38. package/dist/aws/runtime/environment.js +12 -0
  39. package/dist/aws/runtime/messaging.js +31 -0
  40. package/dist/aws/runtime/s3.js +30 -0
  41. package/dist/aws/runtime/secrets/dbsecret.js +96 -0
  42. package/dist/aws/runtime/secrets/proxy-holder.js +27 -0
  43. package/dist/aws/runtime/secrets/rds-holder.js +27 -0
  44. package/dist/aws/runtime/secrets/secret-holder.js +76 -0
  45. package/dist/aws/runtime/secrets/secret.js +43 -0
  46. package/dist/aws/types/errors.js +16 -0
  47. package/dist/aws/types/lambda-response.js +33 -0
  48. package/dist/aws/types/mediatypes.js +16 -0
  49. package/dist/aws/types/model-with-reference.js +3 -0
  50. package/dist/aws/types/proxytypes.js +3 -0
  51. package/dist/aws/types/tags.js +7 -0
  52. package/dist/database/cached.js +32 -0
  53. package/dist/database/database.js +70 -0
  54. package/dist/database/last-updated.js +54 -0
  55. package/dist/database/models.js +3 -0
  56. package/dist/marine/id_utils.js +33 -0
  57. package/dist/marine/rtz.js +3 -0
  58. package/dist/test/asserter.js +45 -0
  59. package/dist/test/db-testutils.js +31 -0
  60. package/dist/test/httpserver.js +74 -0
  61. package/dist/test/secret.js +25 -0
  62. package/dist/test/secrets-manager.js +59 -0
  63. package/dist/test/testutils.js +44 -0
  64. package/dist/types/either.js +3 -0
  65. package/dist/types/input-error.js +7 -0
  66. package/dist/types/language.js +10 -0
  67. package/dist/types/traffictype.js +13 -0
  68. package/dist/types/validator.js +14 -0
  69. package/dist/utils/api-model.js +129 -0
  70. package/dist/utils/base64.js +21 -0
  71. package/dist/utils/date-utils.js +34 -0
  72. package/dist/utils/geojson-types.js +18 -0
  73. package/dist/utils/geometry.js +164 -0
  74. package/dist/utils/retry.js +50 -0
  75. package/dist/utils/slack.js +25 -0
  76. package/dist/utils/utils.js +75 -0
  77. package/jest.config.js +15 -0
  78. package/package.json +15 -13
  79. package/src/@types/geojson-validation/index.d.ts +4 -0
  80. package/src/aws/infra/api/integration.ts +73 -0
  81. package/src/aws/infra/api/response.ts +67 -0
  82. package/src/aws/infra/api/responses.ts +124 -0
  83. package/src/aws/infra/api/static-integration.ts +62 -0
  84. package/src/aws/infra/canaries/canary-alarm.ts +31 -0
  85. package/src/aws/infra/canaries/canary-keys.ts +3 -0
  86. package/{aws/infra/canaries/canary-parameters.d.ts → src/aws/infra/canaries/canary-parameters.ts} +7 -6
  87. package/src/aws/infra/canaries/canary-role.ts +47 -0
  88. package/src/aws/infra/canaries/canary.ts +46 -0
  89. package/src/aws/infra/canaries/database-canary.ts +98 -0
  90. package/src/aws/infra/canaries/database-checker.ts +155 -0
  91. package/src/aws/infra/canaries/url-canary.ts +74 -0
  92. package/src/aws/infra/canaries/url-checker.ts +366 -0
  93. package/src/aws/infra/documentation.ts +124 -0
  94. package/src/aws/infra/scheduler.ts +59 -0
  95. package/src/aws/infra/security-rule.ts +38 -0
  96. package/src/aws/infra/sqs-integration.ts +102 -0
  97. package/src/aws/infra/sqs-queue.ts +148 -0
  98. package/src/aws/infra/stack/lambda-configs.ts +207 -0
  99. package/src/aws/infra/stack/monitoredfunction.ts +342 -0
  100. package/src/aws/infra/stack/rest_apis.ts +223 -0
  101. package/src/aws/infra/stack/stack-checking-aspect.ts +279 -0
  102. package/src/aws/infra/stack/stack.ts +145 -0
  103. package/src/aws/infra/stack/subscription.ts +58 -0
  104. package/src/aws/infra/usage-plans.ts +41 -0
  105. package/src/aws/runtime/apikey.ts +9 -0
  106. package/src/aws/runtime/digitraffic-integration-response.ts +28 -0
  107. package/src/aws/runtime/environment.ts +9 -0
  108. package/src/aws/runtime/messaging.ts +26 -0
  109. package/src/aws/runtime/s3.ts +44 -0
  110. package/src/aws/runtime/secrets/dbsecret.ts +116 -0
  111. package/src/aws/runtime/secrets/proxy-holder.ts +37 -0
  112. package/src/aws/runtime/secrets/rds-holder.ts +33 -0
  113. package/src/aws/runtime/secrets/secret-holder.ts +116 -0
  114. package/src/aws/runtime/secrets/secret.ts +50 -0
  115. package/src/aws/types/errors.ts +14 -0
  116. package/src/aws/types/lambda-response.ts +43 -0
  117. package/{aws/types/mediatypes.d.ts → src/aws/types/mediatypes.ts} +4 -3
  118. package/{aws/types/model-with-reference.d.ts → src/aws/types/model-with-reference.ts} +2 -1
  119. package/src/aws/types/proxytypes.ts +27 -0
  120. package/src/aws/types/tags.ts +3 -0
  121. package/src/database/cached.ts +35 -0
  122. package/src/database/database.ts +96 -0
  123. package/src/database/last-updated.ts +59 -0
  124. package/{database/models.d.ts → src/database/models.ts} +1 -0
  125. package/src/marine/id_utils.ts +30 -0
  126. package/src/marine/rtz.ts +57 -0
  127. package/src/test/asserter.ts +48 -0
  128. package/src/test/db-testutils.ts +44 -0
  129. package/src/test/httpserver.ts +96 -0
  130. package/src/test/secret.ts +23 -0
  131. package/src/test/secrets-manager.ts +34 -0
  132. package/src/test/testutils.ts +39 -0
  133. package/src/types/either.ts +3 -0
  134. package/src/types/input-error.ts +2 -0
  135. package/src/types/language.ts +3 -0
  136. package/src/types/traffictype.ts +8 -0
  137. package/src/types/validator.ts +10 -0
  138. package/src/utils/api-model.ts +133 -0
  139. package/src/utils/base64.ts +16 -0
  140. package/src/utils/date-utils.ts +30 -0
  141. package/src/utils/geojson-types.ts +22 -0
  142. package/src/utils/geometry.ts +164 -0
  143. package/src/utils/retry.ts +49 -0
  144. package/src/utils/slack.ts +22 -0
  145. package/src/utils/utils.ts +105 -0
  146. package/test/marine/id_utils.test.ts +57 -0
  147. package/test/promise/promise.test.ts +143 -0
  148. package/test/secrets/dbsecret.test.ts +59 -0
  149. package/test/secrets/secret-holder.test.ts +143 -0
  150. package/test/secrets/secret.test.ts +49 -0
  151. package/test/test/httpserver.test.ts +128 -0
  152. package/test/utils/date-utils.test.ts +28 -0
  153. package/test/utils/geometry.test.ts +29 -0
  154. package/test/utils/utils.test.ts +64 -0
  155. package/tsconfig.eslint.json +4 -0
  156. package/tsconfig.json +22 -0
  157. package/yarn.lock +4060 -0
  158. package/aws/infra/api/integration.d.ts +0 -21
  159. package/aws/infra/api/integration.js +0 -52
  160. package/aws/infra/api/response.d.ts +0 -22
  161. package/aws/infra/api/response.js +0 -61
  162. package/aws/infra/api/responses.d.ts +0 -39
  163. package/aws/infra/api/responses.js +0 -79
  164. package/aws/infra/api/static-integration.d.ts +0 -15
  165. package/aws/infra/api/static-integration.js +0 -54
  166. package/aws/infra/canaries/canary-alarm.d.ts +0 -6
  167. package/aws/infra/canaries/canary-alarm.js +0 -26
  168. package/aws/infra/canaries/canary-parameters.js +0 -3
  169. package/aws/infra/canaries/canary-role.d.ts +0 -6
  170. package/aws/infra/canaries/canary-role.js +0 -46
  171. package/aws/infra/canaries/canary.d.ts +0 -8
  172. package/aws/infra/canaries/canary.js +0 -32
  173. package/aws/infra/canaries/database-canary.d.ts +0 -18
  174. package/aws/infra/canaries/database-canary.js +0 -55
  175. package/aws/infra/canaries/database-checker.d.ts +0 -21
  176. package/aws/infra/canaries/database-checker.js +0 -109
  177. package/aws/infra/canaries/url-canary.d.ts +0 -19
  178. package/aws/infra/canaries/url-canary.js +0 -46
  179. package/aws/infra/canaries/url-checker.d.ts +0 -46
  180. package/aws/infra/canaries/url-checker.js +0 -238
  181. package/aws/infra/documentation.d.ts +0 -56
  182. package/aws/infra/documentation.js +0 -95
  183. package/aws/infra/scheduler.d.ts +0 -12
  184. package/aws/infra/scheduler.js +0 -31
  185. package/aws/infra/security-rule.d.ts +0 -12
  186. package/aws/infra/security-rule.js +0 -39
  187. package/aws/infra/sqs-integration.d.ts +0 -7
  188. package/aws/infra/sqs-integration.js +0 -93
  189. package/aws/infra/sqs-queue.d.ts +0 -16
  190. package/aws/infra/sqs-queue.js +0 -130
  191. package/aws/infra/stack/lambda-configs.d.ts +0 -72
  192. package/aws/infra/stack/lambda-configs.js +0 -93
  193. package/aws/infra/stack/monitoredfunction.d.ts +0 -84
  194. package/aws/infra/stack/monitoredfunction.js +0 -135
  195. package/aws/infra/stack/rest_apis.d.ts +0 -41
  196. package/aws/infra/stack/rest_apis.js +0 -185
  197. package/aws/infra/stack/stack-checking-aspect.d.ts +0 -21
  198. package/aws/infra/stack/stack-checking-aspect.js +0 -174
  199. package/aws/infra/stack/stack.d.ts +0 -44
  200. package/aws/infra/stack/stack.js +0 -60
  201. package/aws/infra/stack/subscription.d.ts +0 -17
  202. package/aws/infra/stack/subscription.js +0 -41
  203. package/aws/infra/usage-plans.d.ts +0 -15
  204. package/aws/infra/usage-plans.js +0 -42
  205. package/aws/runtime/apikey.d.ts +0 -2
  206. package/aws/runtime/apikey.js +0 -13
  207. package/aws/runtime/digitraffic-integration-response.d.ts +0 -8
  208. package/aws/runtime/digitraffic-integration-response.js +0 -26
  209. package/aws/runtime/environment.d.ts +0 -1
  210. package/aws/runtime/environment.js +0 -12
  211. package/aws/runtime/messaging.d.ts +0 -10
  212. package/aws/runtime/messaging.js +0 -31
  213. package/aws/runtime/s3.d.ts +0 -2
  214. package/aws/runtime/s3.js +0 -30
  215. package/aws/runtime/secrets/dbsecret.d.ts +0 -54
  216. package/aws/runtime/secrets/dbsecret.js +0 -96
  217. package/aws/runtime/secrets/proxy-holder.d.ts +0 -9
  218. package/aws/runtime/secrets/proxy-holder.js +0 -26
  219. package/aws/runtime/secrets/rds-holder.d.ts +0 -9
  220. package/aws/runtime/secrets/rds-holder.js +0 -26
  221. package/aws/runtime/secrets/secret-holder.d.ts +0 -26
  222. package/aws/runtime/secrets/secret-holder.js +0 -73
  223. package/aws/runtime/secrets/secret.d.ts +0 -8
  224. package/aws/runtime/secrets/secret.js +0 -43
  225. package/aws/types/errors.d.ts +0 -4
  226. package/aws/types/errors.js +0 -9
  227. package/aws/types/lambda-response.d.ts +0 -12
  228. package/aws/types/lambda-response.js +0 -28
  229. package/aws/types/mediatypes.js +0 -15
  230. package/aws/types/model-with-reference.js +0 -3
  231. package/aws/types/proxytypes.d.ts +0 -26
  232. package/aws/types/proxytypes.js +0 -3
  233. package/aws/types/tags.d.ts +0 -2
  234. package/aws/types/tags.js +0 -7
  235. package/database/cached.d.ts +0 -7
  236. package/database/cached.js +0 -32
  237. package/database/database.d.ts +0 -19
  238. package/database/database.js +0 -62
  239. package/database/last-updated.d.ts +0 -16
  240. package/database/last-updated.js +0 -54
  241. package/database/models.js +0 -3
  242. package/index.d.ts +0 -1
  243. package/index.js +0 -18
  244. package/marine/id_utils.d.ts +0 -3
  245. package/marine/id_utils.js +0 -33
  246. package/marine/rtz.d.ts +0 -48
  247. package/marine/rtz.js +0 -3
  248. package/test/asserter.d.ts +0 -11
  249. package/test/asserter.js +0 -45
  250. package/test/db-testutils.d.ts +0 -2
  251. package/test/db-testutils.js +0 -31
  252. package/test/httpserver.d.ts +0 -18
  253. package/test/httpserver.js +0 -67
  254. package/test/secret.d.ts +0 -3
  255. package/test/secret.js +0 -25
  256. package/test/secrets-manager.d.ts +0 -9
  257. package/test/secrets-manager.js +0 -59
  258. package/test/testutils.d.ts +0 -12
  259. package/test/testutils.js +0 -44
  260. package/types/input-error.d.ts +0 -2
  261. package/types/input-error.js +0 -7
  262. package/types/language.d.ts +0 -5
  263. package/types/language.js +0 -10
  264. package/types/traffictype.d.ts +0 -8
  265. package/types/traffictype.js +0 -13
  266. package/types/validator.d.ts +0 -4
  267. package/types/validator.js +0 -14
  268. package/utils/api-model.d.ts +0 -87
  269. package/utils/api-model.js +0 -129
  270. package/utils/base64.d.ts +0 -12
  271. package/utils/base64.js +0 -21
  272. package/utils/date-utils.d.ts +0 -17
  273. package/utils/date-utils.js +0 -34
  274. package/utils/geojson-types.d.ts +0 -14
  275. package/utils/geojson-types.js +0 -18
  276. package/utils/geometry.d.ts +0 -36
  277. package/utils/geometry.js +0 -140
  278. package/utils/retry.d.ts +0 -13
  279. package/utils/retry.js +0 -50
  280. package/utils/slack.d.ts +0 -5
  281. package/utils/slack.js +0 -25
  282. package/utils/utils.d.ts +0 -30
  283. package/utils/utils.js +0 -64
package/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ [*]
2
+ charset=utf-8
3
+ end_of_line=lf
4
+ insert_final_newline=true
5
+ indent_style=space
6
+ indent_size=4
7
+
8
+ [{*.json,*.yml,*.yaml}]
9
+ indent_size=2
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ *.js
2
+ cdk.out
3
+ dist
4
+ output
package/.eslintrc.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "env": {
3
+ "browser": false,
4
+ "commonjs": true,
5
+ "es2021": true
6
+ },
7
+ "parser": "@typescript-eslint/parser",
8
+ "parserOptions": {
9
+ "project": ["./tsconfig.eslint.json"]
10
+ },
11
+ "plugins": ["@typescript-eslint"],
12
+ "extends": [
13
+ "eslint:recommended",
14
+ "plugin:@typescript-eslint/eslint-recommended",
15
+ "plugin:@typescript-eslint/recommended",
16
+ // "plugin:@typescript-eslint/recommended-requiring-type-checking",
17
+ // "plugin:@typescript-eslint/strict",
18
+ "prettier"
19
+ ],
20
+ "rules": {
21
+ "@typescript-eslint/no-extraneous-class": "off",
22
+ "@typescript-eslint/no-non-null-assertion": "error",
23
+ "@typescript-eslint/non-nullable-type-assertion-style": "error",
24
+ "@typescript-eslint/no-throw-literal": "error",
25
+ "@typescript-eslint/no-explicit-any": "error"
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ # These owners will be the default owners for everything in the repo.
2
+ * @teijosol @jouniso @teemu-solita @jkhaak-solita @solita-ijunnone @mattihe
@@ -0,0 +1,36 @@
1
+ name: Build
2
+ on: [push]
3
+ jobs:
4
+ build:
5
+ if: github.event.repo.name != 'tmfg/digitraffic-common'
6
+ runs-on: ubuntu-20.04
7
+ steps:
8
+ - name: Checkout
9
+ uses: actions/checkout@v3
10
+ - name: Setup Node.js
11
+ uses: actions/setup-node@v2
12
+ with:
13
+ node-version: '14'
14
+ - name: Compile
15
+ run: |
16
+ yarn
17
+ yarn build
18
+ - name: Run tests
19
+ run: |
20
+ yarn test >> $GITHUB_STEP_SUMMARY
21
+ - name: Test Report
22
+ uses: dorny/test-reporter@v1
23
+ if: success() || failure()
24
+ with:
25
+ name: Jest test report
26
+ reporter: jest-junit
27
+ path: junit.xml
28
+ - name: Notify Slack
29
+ if: failure()
30
+ uses: 8398a7/action-slack@v3
31
+ with:
32
+ status: failure
33
+ text: FAILED digitraffic-common build
34
+ fields: repo, job, took
35
+ env:
36
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
@@ -0,0 +1,38 @@
1
+ name: ESLint
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-22.04
8
+ steps:
9
+ - name: Checkout
10
+ uses: actions/checkout@v3
11
+ with:
12
+ fetch-depth: 0
13
+
14
+ - name: Setup Node.js
15
+ uses: actions/setup-node@v3
16
+ with:
17
+ node-version: "14"
18
+
19
+ - name: Install packages
20
+ run: yarn install --frozen-lock
21
+
22
+ - name: Create ESLint reports for affected projects
23
+ id: report
24
+ run: yarn eslint-report -- -o ${{ github.ref_name }}/report.html
25
+ continue-on-error: true
26
+
27
+ - name: Publish report
28
+ id: publish-reports
29
+ uses: tmfg/digitraffic-actions@gh-pages-publish/v1
30
+ with:
31
+ GH_PAGES_BRANCH: gh-pages
32
+ FILE_PATH: ${{ github.ref_name }}/report.html
33
+ COMMIT_MESSAGE: ESLint report in branch $CURRENT_BRANCH
34
+ LINK_TEXT: ESLint report
35
+
36
+ - name: Fail on ESLint errors
37
+ run: |
38
+ if [[ "${{ steps.report.outcome }}" == "failure" || "${{ steps.report-affected.outcome }}" == "failure" ]]; then exit 1; else exit 0; fi
@@ -0,0 +1,15 @@
1
+ name: 'Mirror repo to public'
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ Mirror-action:
8
+ if: github.repository != 'tmfg/digitraffic-common'
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Mirror
12
+ uses: tmfg/digitraffic-actions@mirror/v1
13
+ with:
14
+ mirror-repo: git@github.com:tmfg/digitraffic-common.git
15
+ ssh-private-key: ${{ secrets.SSH_MIRROR_KEY }}
package/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ *
2
+
3
+ !.husky/
4
+ !.husky/pre-commit
5
+ !/.editorconfig
6
+ !/.eslintignore
7
+ !/.eslintrc.json
8
+ !/.gitignore
9
+ !/.prettierrc.json
10
+ !/jest.config.js
11
+ !/LICENSE
12
+ !/package.json
13
+ !/README.md
14
+ !/tsconfig.json
15
+ !/tsconfig.eslint.json
16
+ !/yarn.lock
17
+
18
+ !src/
19
+ !src/**/
20
+ !src/**/*.ts
21
+
22
+ !test/
23
+ !test/**/
24
+ !test/**/*.ts
25
+
26
+ !.github/
27
+ !.github/**/
28
+ !.github/workflows/**/**.yml
29
+ !.github/CODEOWNERS
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn lint-staged
@@ -0,0 +1,10 @@
1
+ {
2
+ "overrides": [
3
+ {
4
+ "files": ["*.json", "*.yml", "*.yaml"],
5
+ "options": {
6
+ "tabWidth": 2
7
+ }
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitrafficIntegration = void 0;
4
+ const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
5
+ const mediatypes_1 = require("../../types/mediatypes");
6
+ const digitraffic_integration_response_1 = require("../../runtime/digitraffic-integration-response");
7
+ class DigitrafficIntegration {
8
+ constructor(lambda, mediaType = mediatypes_1.MediaType.TEXT_PLAIN) {
9
+ this.parameters = [];
10
+ this.lambda = lambda;
11
+ this.mediaType = mediaType;
12
+ }
13
+ addPathParameter(...names) {
14
+ names.forEach(name => this.parameters.push({ type: 'path', name }));
15
+ return this;
16
+ }
17
+ addQueryParameter(...names) {
18
+ names.forEach(name => this.parameters.push({ type: 'querystring', name }));
19
+ return this;
20
+ }
21
+ build() {
22
+ const integrationResponses = this.createResponses();
23
+ return new aws_apigateway_1.LambdaIntegration(this.lambda, {
24
+ proxy: false,
25
+ integrationResponses,
26
+ requestParameters: this.parameters.length == 0 ? undefined : this.createRequestParameters(),
27
+ requestTemplates: this.parameters.length == 0 ? undefined : this.createRequestTemplates(),
28
+ passthroughBehavior: aws_apigateway_1.PassthroughBehavior.WHEN_NO_MATCH,
29
+ });
30
+ }
31
+ createRequestParameters() {
32
+ const requestParameters = {};
33
+ this.parameters.forEach((parameter) => {
34
+ requestParameters[`integration.request.${parameter.type}.${parameter.name}`] = `method.request.${parameter.type}.${parameter.name}`;
35
+ });
36
+ return requestParameters;
37
+ }
38
+ createRequestTemplates() {
39
+ const requestJson = {};
40
+ this.parameters.forEach((parameter) => {
41
+ requestJson[parameter.name] = `$util.escapeJavaScript($input.params('${parameter.name}'))`;
42
+ });
43
+ return {
44
+ [mediatypes_1.MediaType.APPLICATION_JSON]: JSON.stringify(requestJson),
45
+ };
46
+ }
47
+ createResponses() {
48
+ return [digitraffic_integration_response_1.DigitrafficIntegrationResponse.ok(this.mediaType)];
49
+ }
50
+ }
51
+ exports.DigitrafficIntegration = DigitrafficIntegration;
52
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createResponses = exports.InternalServerErrorResponseTemplate = exports.SvgResponseTemplate = exports.XmlResponseTemplate = exports.NotFoundResponseTemplate = exports.BadRequestResponseTemplate = exports.NotFoundResponse = exports.MessageModel = exports.RESPONSE_DEFAULT_LAMBDA = void 0;
4
+ const apigateway = require("aws-cdk-lib/aws-apigateway");
5
+ const mediatypes_1 = require("../../types/mediatypes");
6
+ /**
7
+ * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
8
+ * It will always return the body and status, but if status in something else than 200 OK the content-type
9
+ * will be overridden to text/plain. (it's assumed, that lambda will return error text).
10
+ *
11
+ * If fileName is set, then Content-Disposition-header will be set to use it
12
+ */
13
+ exports.RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))
14
+ $inputRoot.body
15
+ #if ($inputRoot.status != 200)
16
+ #set ($context.responseOverride.status = $inputRoot.status)
17
+ #set ($context.responseOverride.header.Content-Type = 'text/plain')
18
+ #end
19
+ #set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')
20
+ #if ("$!inputRoot.fileName" != "")
21
+ #set ($disposition = 'attachment; filename="FN"')
22
+ #set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
23
+ #end
24
+ `;
25
+ const BODY_FROM_INPUT_PATH = "$input.path('$').body";
26
+ // DEPRECATED
27
+ const messageSchema = {
28
+ schema: apigateway.JsonSchemaVersion.DRAFT4,
29
+ type: apigateway.JsonSchemaType.OBJECT,
30
+ description: 'Response with message',
31
+ properties: {
32
+ message: {
33
+ type: apigateway.JsonSchemaType.STRING,
34
+ description: 'Response message',
35
+ },
36
+ },
37
+ };
38
+ // DEPRECATED
39
+ exports.MessageModel = {
40
+ contentType: mediatypes_1.MediaType.APPLICATION_JSON,
41
+ modelName: 'MessageResponseModel',
42
+ schema: messageSchema,
43
+ };
44
+ const NotFoundMessage = 'Not found';
45
+ exports.NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
46
+ const InternalServerErrorMessage = 'Error';
47
+ const InternalServerErrorResponse = JSON.stringify({ message: InternalServerErrorMessage });
48
+ const BadRequestMessage = 'Bad request';
49
+ const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
50
+ exports.BadRequestResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, BadRequestResponse);
51
+ exports.NotFoundResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, exports.NotFoundResponse);
52
+ exports.XmlResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_XML, BODY_FROM_INPUT_PATH);
53
+ exports.SvgResponseTemplate = createResponses(mediatypes_1.MediaType.IMAGE_SVG, BODY_FROM_INPUT_PATH);
54
+ exports.InternalServerErrorResponseTemplate = createResponses(mediatypes_1.MediaType.APPLICATION_JSON, InternalServerErrorResponse);
55
+ function createResponses(key, value) {
56
+ const map = {};
57
+ map[key] = value;
58
+ return map;
59
+ }
60
+ exports.createResponses = createResponses;
61
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getResponse = exports.defaultIntegration = exports.corsMethod = exports.methodResponse = exports.RESPONSE_404_NOT_FOUND = exports.RESPONSE_CORS_INTEGRATION = exports.RESPONSE_500_SERVER_ERROR = exports.RESPONSE_400_BAD_REQUEST = exports.RESPONSE_200_OK = void 0;
4
+ const response_1 = require("./response");
5
+ const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
6
+ const errors_1 = require("../../types/errors");
7
+ exports.RESPONSE_200_OK = {
8
+ statusCode: "200",
9
+ };
10
+ exports.RESPONSE_400_BAD_REQUEST = {
11
+ statusCode: "400",
12
+ selectionPattern: errors_1.BAD_REQUEST_MESSAGE,
13
+ responseTemplates: response_1.BadRequestResponseTemplate,
14
+ };
15
+ exports.RESPONSE_500_SERVER_ERROR = {
16
+ statusCode: "500",
17
+ selectionPattern: errors_1.ERROR_MESSAGE,
18
+ responseTemplates: response_1.InternalServerErrorResponseTemplate,
19
+ };
20
+ const RESPONSE_XML = {
21
+ responseTemplates: response_1.XmlResponseTemplate,
22
+ };
23
+ exports.RESPONSE_CORS_INTEGRATION = {
24
+ responseParameters: {
25
+ "method.response.header.Access-Control-Allow-Origin": "'*'",
26
+ },
27
+ };
28
+ exports.RESPONSE_404_NOT_FOUND = {
29
+ statusCode: "404",
30
+ selectionPattern: errors_1.NOT_FOUND_MESSAGE,
31
+ responseTemplates: response_1.NotFoundResponseTemplate,
32
+ };
33
+ function methodResponse(status, contentType, model, parameters) {
34
+ return {
35
+ statusCode: status,
36
+ responseModels: (0, response_1.createResponses)(contentType, model),
37
+ responseParameters: parameters || {},
38
+ };
39
+ }
40
+ exports.methodResponse = methodResponse;
41
+ function corsMethod(response) {
42
+ return {
43
+ ...response,
44
+ ...{
45
+ responseParameters: {
46
+ "method.response.header.Access-Control-Allow-Origin": true,
47
+ },
48
+ },
49
+ };
50
+ }
51
+ exports.corsMethod = corsMethod;
52
+ /**
53
+ * Creates a default Lambda integration for a REST API resource _root_
54
+ * @param lambdaFunction The Lambda function
55
+ * @param options Options
56
+ */
57
+ function defaultIntegration(lambdaFunction, options) {
58
+ return new aws_apigateway_1.LambdaIntegration(lambdaFunction, {
59
+ proxy: false,
60
+ integrationResponses: options?.responses || [
61
+ getResponse(exports.RESPONSE_200_OK, options),
62
+ getResponse(exports.RESPONSE_400_BAD_REQUEST, options),
63
+ getResponse(exports.RESPONSE_404_NOT_FOUND, options),
64
+ getResponse(exports.RESPONSE_500_SERVER_ERROR, options),
65
+ ],
66
+ requestParameters: options?.requestParameters || {},
67
+ requestTemplates: options?.requestTemplates || {},
68
+ passthroughBehavior: options?.passthroughBehavior ?? aws_apigateway_1.PassthroughBehavior.WHEN_NO_MATCH,
69
+ });
70
+ }
71
+ exports.defaultIntegration = defaultIntegration;
72
+ function getResponse(response, options) {
73
+ if (options?.xml) {
74
+ response = { ...response, ...RESPONSE_XML };
75
+ }
76
+ if (!options?.disableCors) {
77
+ response = { ...response, ...exports.RESPONSE_CORS_INTEGRATION };
78
+ }
79
+ return response;
80
+ }
81
+ exports.getResponse = getResponse;
82
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitrafficStaticIntegration = void 0;
4
+ const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
5
+ const mediatypes_1 = require("../../types/mediatypes");
6
+ const responses_1 = require("./responses");
7
+ const INTEGRATION_RESPONSE_200 = `{
8
+ "statusCode": 200
9
+ }`;
10
+ const METHOD_RESPONSE_200 = {
11
+ statusCode: '200',
12
+ };
13
+ /**
14
+ * Static integration, that returns the given response with given mediaType from given resource.
15
+ *
16
+ * @param resource
17
+ * @param mediaType
18
+ * @param response
19
+ */
20
+ class DigitrafficStaticIntegration extends aws_apigateway_1.MockIntegration {
21
+ constructor(resource, mediaType, response, enableCors = true, apiKeyRequired = true) {
22
+ const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, enableCors);
23
+ super({
24
+ passthroughBehavior: aws_apigateway_1.PassthroughBehavior.WHEN_NO_TEMPLATES,
25
+ requestTemplates: {
26
+ [mediaType]: INTEGRATION_RESPONSE_200,
27
+ },
28
+ integrationResponses: [integrationResponse],
29
+ });
30
+ ['GET', 'HEAD'].forEach((httpMethod) => {
31
+ resource.addMethod(httpMethod, this, {
32
+ apiKeyRequired,
33
+ methodResponses: [DigitrafficStaticIntegration.createMethodResponse(enableCors)],
34
+ });
35
+ });
36
+ }
37
+ static json(resource, response, enableCors = true, apiKeyRequired = true) {
38
+ return new DigitrafficStaticIntegration(resource, mediatypes_1.MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired);
39
+ }
40
+ static createIntegrationResponse(response, mediaType, enableCors) {
41
+ const integrationResponse = {
42
+ statusCode: '200',
43
+ responseTemplates: {
44
+ [mediaType]: response,
45
+ },
46
+ };
47
+ return enableCors ? { ...integrationResponse, ...responses_1.RESPONSE_CORS_INTEGRATION } : integrationResponse;
48
+ }
49
+ static createMethodResponse(enableCors) {
50
+ return enableCors ? (0, responses_1.corsMethod)(METHOD_RESPONSE_200) : METHOD_RESPONSE_200;
51
+ }
52
+ }
53
+ exports.DigitrafficStaticIntegration = DigitrafficStaticIntegration;
54
+ //# sourceMappingURL=static-integration.js.map
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CanaryAlarm = void 0;
4
+ const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
5
+ const aws_cloudwatch_actions_1 = require("aws-cdk-lib/aws-cloudwatch-actions");
6
+ const aws_sns_1 = require("aws-cdk-lib/aws-sns");
7
+ class CanaryAlarm {
8
+ constructor(stack, canary, params) {
9
+ if (params.alarm ?? true) {
10
+ const alarmName = params.alarm?.alarmName ?? `${params.name}-alarm`;
11
+ const alarm = new aws_cloudwatch_1.Alarm(stack, alarmName, {
12
+ alarmName,
13
+ alarmDescription: params.alarm?.description ?? '',
14
+ metric: canary.metricSuccessPercent(),
15
+ evaluationPeriods: params.alarm?.evalutionPeriods ?? 1,
16
+ threshold: params.alarm?.threshold ?? 100,
17
+ comparisonOperator: aws_cloudwatch_1.ComparisonOperator.LESS_THAN_THRESHOLD,
18
+ });
19
+ if (params.alarm?.topicArn) {
20
+ alarm.addAlarmAction(new aws_cloudwatch_actions_1.SnsAction(aws_sns_1.Topic.fromTopicArn(stack, `${alarmName}-action`, params.alarm.topicArn)));
21
+ }
22
+ }
23
+ }
24
+ }
25
+ exports.CanaryAlarm = CanaryAlarm;
26
+ //# sourceMappingURL=canary-alarm.js.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENV_SECRET = exports.ENV_HOSTNAME = exports.ENV_API_KEY = void 0;
4
+ exports.ENV_API_KEY = "apiKeyId";
5
+ exports.ENV_HOSTNAME = "hostname";
6
+ exports.ENV_SECRET = "secret";
7
+ //# sourceMappingURL=canary-keys.js.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=canary-parameters.js.map
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitrafficCanaryRole = void 0;
4
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
+ const BASE_POLICY_STATEMENT_PROPS = {
6
+ actions: [
7
+ "logs:CreateLogStream",
8
+ "logs:PutLogEvents",
9
+ "logs:CreateLogGroup",
10
+ "logs:DescribeLogGroups",
11
+ "logs:DescribeLogStreams",
12
+ ],
13
+ resources: ["*"],
14
+ };
15
+ const CLOUDWATCH_STATEMENT_PROPS = {
16
+ actions: [
17
+ "cloudwatch:PutMetricData",
18
+ ],
19
+ resources: ["*"],
20
+ conditions: {
21
+ "StringEquals": {
22
+ "cloudwatch:namespace": "CloudWatchSynthetics",
23
+ },
24
+ },
25
+ };
26
+ class DigitrafficCanaryRole extends aws_iam_1.Role {
27
+ constructor(stack, canaryName) {
28
+ super(stack, 'canary-role-' + canaryName, {
29
+ assumedBy: new aws_iam_1.ServicePrincipal("lambda.amazonaws.com"),
30
+ managedPolicies: [
31
+ aws_iam_1.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchSyntheticsFullAccess"),
32
+ ],
33
+ });
34
+ this.addToPolicy(new aws_iam_1.PolicyStatement(BASE_POLICY_STATEMENT_PROPS));
35
+ this.addToPolicy(new aws_iam_1.PolicyStatement(CLOUDWATCH_STATEMENT_PROPS));
36
+ }
37
+ withDatabaseAccess() {
38
+ // Won't work :(
39
+ // this.addToPolicy(new PolicyStatement(DB_STATEMENT_PROPS));
40
+ // Works
41
+ this.addManagedPolicy(aws_iam_1.ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaVPCAccessExecutionRole"));
42
+ return this;
43
+ }
44
+ }
45
+ exports.DigitrafficCanaryRole = DigitrafficCanaryRole;
46
+ //# sourceMappingURL=canary-role.js.map
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DigitrafficCanary = void 0;
4
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ const aws_synthetics_alpha_1 = require("@aws-cdk/aws-synthetics-alpha");
6
+ const canary_alarm_1 = require("./canary-alarm");
7
+ class DigitrafficCanary extends aws_synthetics_alpha_1.Canary {
8
+ constructor(scope, canaryName, role, params, environmentVariables) {
9
+ super(scope, canaryName, {
10
+ runtime: aws_synthetics_alpha_1.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_6,
11
+ role,
12
+ test: aws_synthetics_alpha_1.Test.custom({
13
+ code: new aws_synthetics_alpha_1.AssetCode("dist", {
14
+ exclude: ["lambda", "out", "canaries"],
15
+ }),
16
+ handler: params.handler,
17
+ }),
18
+ environmentVariables: {
19
+ ...environmentVariables,
20
+ ...params?.canaryEnv,
21
+ },
22
+ canaryName,
23
+ schedule: params.schedule ?? aws_synthetics_alpha_1.Schedule.rate(aws_cdk_lib_1.Duration.minutes(15)),
24
+ });
25
+ this.artifactsBucket.grantWrite(role);
26
+ if (params.alarm ?? true) {
27
+ new canary_alarm_1.CanaryAlarm(scope, this, params);
28
+ }
29
+ }
30
+ }
31
+ exports.DigitrafficCanary = DigitrafficCanary;
32
+ //# sourceMappingURL=canary.js.map
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseCanary = void 0;
4
+ const aws_synthetics_1 = require("aws-cdk-lib/aws-synthetics");
5
+ const aws_events_1 = require("aws-cdk-lib/aws-events");
6
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
7
+ const canary_1 = require("./canary");
8
+ class DatabaseCanary extends canary_1.DigitrafficCanary {
9
+ constructor(stack, role, secret, params) {
10
+ const canaryName = `${params.name}-db`;
11
+ const environmentVariables = stack.createDefaultLambdaEnvironment(`Synthetics-${canaryName}`);
12
+ // the handler code is defined at the actual project using this
13
+ super(stack, canaryName, role, params, environmentVariables);
14
+ this.artifactsBucket.grantWrite(this.role);
15
+ secret.grantRead(this.role);
16
+ // need to override vpc and security group, can't do this with cdk
17
+ if (this.node.defaultChild instanceof aws_synthetics_1.CfnCanary) {
18
+ const subnetIds = stack.vpc === undefined
19
+ ? []
20
+ : stack.vpc.privateSubnets.map((subnet) => subnet.subnetId);
21
+ const securityGroupIds = stack.lambdaDbSg === undefined
22
+ ? []
23
+ : [stack.lambdaDbSg.securityGroupId];
24
+ this.node.defaultChild.vpcConfig = {
25
+ vpcId: stack.vpc?.vpcId,
26
+ securityGroupIds,
27
+ subnetIds,
28
+ };
29
+ }
30
+ }
31
+ static create(stack, role, params) {
32
+ const secret = stack.getSecret();
33
+ return new DatabaseCanary(stack, role, secret, {
34
+ ...{
35
+ secret: stack.configuration.secretId,
36
+ schedule: aws_events_1.Schedule.rate(aws_cdk_lib_1.Duration.hours(1)),
37
+ handler: `${params.name}.handler`,
38
+ },
39
+ ...params,
40
+ });
41
+ }
42
+ /**
43
+ *
44
+ * @param stack
45
+ * @param role
46
+ * @param name name of the typescipt file without -db -suffix. Max len is 10 char if @param canaryName is not given.
47
+ * @param params
48
+ * @param canaryName Optional name for canary if multiple canaries is made from same ${name}-db.ts canary file.
49
+ */
50
+ static createV2(stack, role, name, params = {}, canaryName = name) {
51
+ const secret = stack.getSecret();
52
+ return new DatabaseCanary(stack, role, secret, {
53
+ ...{
54
+ secret: stack.configuration.secretId,
55
+ schedule: aws_events_1.Schedule.rate(aws_cdk_lib_1.Duration.hours(1)),
56
+ handler: `${name}-db.handler`,
57
+ name: canaryName,
58
+ alarm: {
59
+ alarmName: canaryName === name
60
+ ? `${stack.configuration.shortName}-DB-Alarm`
61
+ : `${canaryName}-DB-Alarm`,
62
+ topicArn: stack.configuration.alarmTopicArn,
63
+ },
64
+ },
65
+ ...params,
66
+ });
67
+ }
68
+ }
69
+ exports.DatabaseCanary = DatabaseCanary;
70
+ //# sourceMappingURL=database-canary.js.map