@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.
- package/.editorconfig +9 -0
- package/.eslintignore +4 -0
- package/.eslintrc.json +27 -0
- package/.github/CODEOWNERS +2 -0
- package/.github/workflows/build.yml +36 -0
- package/.github/workflows/eslint.yml +38 -0
- package/.github/workflows/mirror.yml +15 -0
- package/.gitignore +29 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.json +10 -0
- package/dist/aws/infra/api/integration.js +52 -0
- package/dist/aws/infra/api/response.js +61 -0
- package/dist/aws/infra/api/responses.js +82 -0
- package/dist/aws/infra/api/static-integration.js +54 -0
- package/dist/aws/infra/canaries/canary-alarm.js +26 -0
- package/dist/aws/infra/canaries/canary-keys.js +7 -0
- package/dist/aws/infra/canaries/canary-parameters.js +3 -0
- package/dist/aws/infra/canaries/canary-role.js +46 -0
- package/dist/aws/infra/canaries/canary.js +32 -0
- package/dist/aws/infra/canaries/database-canary.js +70 -0
- package/dist/aws/infra/canaries/database-checker.js +103 -0
- package/dist/aws/infra/canaries/url-canary.js +47 -0
- package/dist/aws/infra/canaries/url-checker.js +252 -0
- package/dist/aws/infra/documentation.js +95 -0
- package/dist/aws/infra/scheduler.js +31 -0
- package/dist/aws/infra/security-rule.js +39 -0
- package/dist/aws/infra/sqs-integration.js +93 -0
- package/dist/aws/infra/sqs-queue.js +130 -0
- package/dist/aws/infra/stack/lambda-configs.js +105 -0
- package/dist/aws/infra/stack/monitoredfunction.js +143 -0
- package/dist/aws/infra/stack/rest_apis.js +185 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +174 -0
- package/dist/aws/infra/stack/stack.js +67 -0
- package/dist/aws/infra/stack/subscription.js +42 -0
- package/dist/aws/infra/usage-plans.js +42 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +26 -0
- package/dist/aws/runtime/environment.js +12 -0
- package/dist/aws/runtime/messaging.js +31 -0
- package/dist/aws/runtime/s3.js +30 -0
- package/dist/aws/runtime/secrets/dbsecret.js +96 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +27 -0
- package/dist/aws/runtime/secrets/rds-holder.js +27 -0
- package/dist/aws/runtime/secrets/secret-holder.js +76 -0
- package/dist/aws/runtime/secrets/secret.js +43 -0
- package/dist/aws/types/errors.js +16 -0
- package/dist/aws/types/lambda-response.js +33 -0
- package/dist/aws/types/mediatypes.js +16 -0
- package/dist/aws/types/model-with-reference.js +3 -0
- package/dist/aws/types/proxytypes.js +3 -0
- package/dist/aws/types/tags.js +7 -0
- package/dist/database/cached.js +32 -0
- package/dist/database/database.js +70 -0
- package/dist/database/last-updated.js +54 -0
- package/dist/database/models.js +3 -0
- package/dist/marine/id_utils.js +33 -0
- package/dist/marine/rtz.js +3 -0
- package/dist/test/asserter.js +45 -0
- package/dist/test/db-testutils.js +31 -0
- package/dist/test/httpserver.js +74 -0
- package/dist/test/secret.js +25 -0
- package/dist/test/secrets-manager.js +59 -0
- package/dist/test/testutils.js +44 -0
- package/dist/types/either.js +3 -0
- package/dist/types/input-error.js +7 -0
- package/dist/types/language.js +10 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/validator.js +14 -0
- package/dist/utils/api-model.js +129 -0
- package/dist/utils/base64.js +21 -0
- package/dist/utils/date-utils.js +34 -0
- package/dist/utils/geojson-types.js +18 -0
- package/dist/utils/geometry.js +164 -0
- package/dist/utils/retry.js +50 -0
- package/dist/utils/slack.js +25 -0
- package/dist/utils/utils.js +75 -0
- package/jest.config.js +15 -0
- package/package.json +15 -13
- package/src/@types/geojson-validation/index.d.ts +4 -0
- package/src/aws/infra/api/integration.ts +73 -0
- package/src/aws/infra/api/response.ts +67 -0
- package/src/aws/infra/api/responses.ts +124 -0
- package/src/aws/infra/api/static-integration.ts +62 -0
- package/src/aws/infra/canaries/canary-alarm.ts +31 -0
- package/src/aws/infra/canaries/canary-keys.ts +3 -0
- package/{aws/infra/canaries/canary-parameters.d.ts → src/aws/infra/canaries/canary-parameters.ts} +7 -6
- package/src/aws/infra/canaries/canary-role.ts +47 -0
- package/src/aws/infra/canaries/canary.ts +46 -0
- package/src/aws/infra/canaries/database-canary.ts +98 -0
- package/src/aws/infra/canaries/database-checker.ts +155 -0
- package/src/aws/infra/canaries/url-canary.ts +74 -0
- package/src/aws/infra/canaries/url-checker.ts +366 -0
- package/src/aws/infra/documentation.ts +124 -0
- package/src/aws/infra/scheduler.ts +59 -0
- package/src/aws/infra/security-rule.ts +38 -0
- package/src/aws/infra/sqs-integration.ts +102 -0
- package/src/aws/infra/sqs-queue.ts +148 -0
- package/src/aws/infra/stack/lambda-configs.ts +207 -0
- package/src/aws/infra/stack/monitoredfunction.ts +342 -0
- package/src/aws/infra/stack/rest_apis.ts +223 -0
- package/src/aws/infra/stack/stack-checking-aspect.ts +279 -0
- package/src/aws/infra/stack/stack.ts +145 -0
- package/src/aws/infra/stack/subscription.ts +58 -0
- package/src/aws/infra/usage-plans.ts +41 -0
- package/src/aws/runtime/apikey.ts +9 -0
- package/src/aws/runtime/digitraffic-integration-response.ts +28 -0
- package/src/aws/runtime/environment.ts +9 -0
- package/src/aws/runtime/messaging.ts +26 -0
- package/src/aws/runtime/s3.ts +44 -0
- package/src/aws/runtime/secrets/dbsecret.ts +116 -0
- package/src/aws/runtime/secrets/proxy-holder.ts +37 -0
- package/src/aws/runtime/secrets/rds-holder.ts +33 -0
- package/src/aws/runtime/secrets/secret-holder.ts +116 -0
- package/src/aws/runtime/secrets/secret.ts +50 -0
- package/src/aws/types/errors.ts +14 -0
- package/src/aws/types/lambda-response.ts +43 -0
- package/{aws/types/mediatypes.d.ts → src/aws/types/mediatypes.ts} +4 -3
- package/{aws/types/model-with-reference.d.ts → src/aws/types/model-with-reference.ts} +2 -1
- package/src/aws/types/proxytypes.ts +27 -0
- package/src/aws/types/tags.ts +3 -0
- package/src/database/cached.ts +35 -0
- package/src/database/database.ts +96 -0
- package/src/database/last-updated.ts +59 -0
- package/{database/models.d.ts → src/database/models.ts} +1 -0
- package/src/marine/id_utils.ts +30 -0
- package/src/marine/rtz.ts +57 -0
- package/src/test/asserter.ts +48 -0
- package/src/test/db-testutils.ts +44 -0
- package/src/test/httpserver.ts +96 -0
- package/src/test/secret.ts +23 -0
- package/src/test/secrets-manager.ts +34 -0
- package/src/test/testutils.ts +39 -0
- package/src/types/either.ts +3 -0
- package/src/types/input-error.ts +2 -0
- package/src/types/language.ts +3 -0
- package/src/types/traffictype.ts +8 -0
- package/src/types/validator.ts +10 -0
- package/src/utils/api-model.ts +133 -0
- package/src/utils/base64.ts +16 -0
- package/src/utils/date-utils.ts +30 -0
- package/src/utils/geojson-types.ts +22 -0
- package/src/utils/geometry.ts +164 -0
- package/src/utils/retry.ts +49 -0
- package/src/utils/slack.ts +22 -0
- package/src/utils/utils.ts +105 -0
- package/test/marine/id_utils.test.ts +57 -0
- package/test/promise/promise.test.ts +143 -0
- package/test/secrets/dbsecret.test.ts +59 -0
- package/test/secrets/secret-holder.test.ts +143 -0
- package/test/secrets/secret.test.ts +49 -0
- package/test/test/httpserver.test.ts +128 -0
- package/test/utils/date-utils.test.ts +28 -0
- package/test/utils/geometry.test.ts +29 -0
- package/test/utils/utils.test.ts +64 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +22 -0
- package/yarn.lock +4060 -0
- package/aws/infra/api/integration.d.ts +0 -21
- package/aws/infra/api/integration.js +0 -52
- package/aws/infra/api/response.d.ts +0 -22
- package/aws/infra/api/response.js +0 -61
- package/aws/infra/api/responses.d.ts +0 -39
- package/aws/infra/api/responses.js +0 -79
- package/aws/infra/api/static-integration.d.ts +0 -15
- package/aws/infra/api/static-integration.js +0 -54
- package/aws/infra/canaries/canary-alarm.d.ts +0 -6
- package/aws/infra/canaries/canary-alarm.js +0 -26
- package/aws/infra/canaries/canary-parameters.js +0 -3
- package/aws/infra/canaries/canary-role.d.ts +0 -6
- package/aws/infra/canaries/canary-role.js +0 -46
- package/aws/infra/canaries/canary.d.ts +0 -8
- package/aws/infra/canaries/canary.js +0 -32
- package/aws/infra/canaries/database-canary.d.ts +0 -18
- package/aws/infra/canaries/database-canary.js +0 -55
- package/aws/infra/canaries/database-checker.d.ts +0 -21
- package/aws/infra/canaries/database-checker.js +0 -109
- package/aws/infra/canaries/url-canary.d.ts +0 -19
- package/aws/infra/canaries/url-canary.js +0 -46
- package/aws/infra/canaries/url-checker.d.ts +0 -46
- package/aws/infra/canaries/url-checker.js +0 -238
- package/aws/infra/documentation.d.ts +0 -56
- package/aws/infra/documentation.js +0 -95
- package/aws/infra/scheduler.d.ts +0 -12
- package/aws/infra/scheduler.js +0 -31
- package/aws/infra/security-rule.d.ts +0 -12
- package/aws/infra/security-rule.js +0 -39
- package/aws/infra/sqs-integration.d.ts +0 -7
- package/aws/infra/sqs-integration.js +0 -93
- package/aws/infra/sqs-queue.d.ts +0 -16
- package/aws/infra/sqs-queue.js +0 -130
- package/aws/infra/stack/lambda-configs.d.ts +0 -72
- package/aws/infra/stack/lambda-configs.js +0 -93
- package/aws/infra/stack/monitoredfunction.d.ts +0 -84
- package/aws/infra/stack/monitoredfunction.js +0 -135
- package/aws/infra/stack/rest_apis.d.ts +0 -41
- package/aws/infra/stack/rest_apis.js +0 -185
- package/aws/infra/stack/stack-checking-aspect.d.ts +0 -21
- package/aws/infra/stack/stack-checking-aspect.js +0 -174
- package/aws/infra/stack/stack.d.ts +0 -44
- package/aws/infra/stack/stack.js +0 -60
- package/aws/infra/stack/subscription.d.ts +0 -17
- package/aws/infra/stack/subscription.js +0 -41
- package/aws/infra/usage-plans.d.ts +0 -15
- package/aws/infra/usage-plans.js +0 -42
- package/aws/runtime/apikey.d.ts +0 -2
- package/aws/runtime/apikey.js +0 -13
- package/aws/runtime/digitraffic-integration-response.d.ts +0 -8
- package/aws/runtime/digitraffic-integration-response.js +0 -26
- package/aws/runtime/environment.d.ts +0 -1
- package/aws/runtime/environment.js +0 -12
- package/aws/runtime/messaging.d.ts +0 -10
- package/aws/runtime/messaging.js +0 -31
- package/aws/runtime/s3.d.ts +0 -2
- package/aws/runtime/s3.js +0 -30
- package/aws/runtime/secrets/dbsecret.d.ts +0 -54
- package/aws/runtime/secrets/dbsecret.js +0 -96
- package/aws/runtime/secrets/proxy-holder.d.ts +0 -9
- package/aws/runtime/secrets/proxy-holder.js +0 -26
- package/aws/runtime/secrets/rds-holder.d.ts +0 -9
- package/aws/runtime/secrets/rds-holder.js +0 -26
- package/aws/runtime/secrets/secret-holder.d.ts +0 -26
- package/aws/runtime/secrets/secret-holder.js +0 -73
- package/aws/runtime/secrets/secret.d.ts +0 -8
- package/aws/runtime/secrets/secret.js +0 -43
- package/aws/types/errors.d.ts +0 -4
- package/aws/types/errors.js +0 -9
- package/aws/types/lambda-response.d.ts +0 -12
- package/aws/types/lambda-response.js +0 -28
- package/aws/types/mediatypes.js +0 -15
- package/aws/types/model-with-reference.js +0 -3
- package/aws/types/proxytypes.d.ts +0 -26
- package/aws/types/proxytypes.js +0 -3
- package/aws/types/tags.d.ts +0 -2
- package/aws/types/tags.js +0 -7
- package/database/cached.d.ts +0 -7
- package/database/cached.js +0 -32
- package/database/database.d.ts +0 -19
- package/database/database.js +0 -62
- package/database/last-updated.d.ts +0 -16
- package/database/last-updated.js +0 -54
- package/database/models.js +0 -3
- package/index.d.ts +0 -1
- package/index.js +0 -18
- package/marine/id_utils.d.ts +0 -3
- package/marine/id_utils.js +0 -33
- package/marine/rtz.d.ts +0 -48
- package/marine/rtz.js +0 -3
- package/test/asserter.d.ts +0 -11
- package/test/asserter.js +0 -45
- package/test/db-testutils.d.ts +0 -2
- package/test/db-testutils.js +0 -31
- package/test/httpserver.d.ts +0 -18
- package/test/httpserver.js +0 -67
- package/test/secret.d.ts +0 -3
- package/test/secret.js +0 -25
- package/test/secrets-manager.d.ts +0 -9
- package/test/secrets-manager.js +0 -59
- package/test/testutils.d.ts +0 -12
- package/test/testutils.js +0 -44
- package/types/input-error.d.ts +0 -2
- package/types/input-error.js +0 -7
- package/types/language.d.ts +0 -5
- package/types/language.js +0 -10
- package/types/traffictype.d.ts +0 -8
- package/types/traffictype.js +0 -13
- package/types/validator.d.ts +0 -4
- package/types/validator.js +0 -14
- package/utils/api-model.d.ts +0 -87
- package/utils/api-model.js +0 -129
- package/utils/base64.d.ts +0 -12
- package/utils/base64.js +0 -21
- package/utils/date-utils.d.ts +0 -17
- package/utils/date-utils.js +0 -34
- package/utils/geojson-types.d.ts +0 -14
- package/utils/geojson-types.js +0 -18
- package/utils/geometry.d.ts +0 -36
- package/utils/geometry.js +0 -140
- package/utils/retry.d.ts +0 -13
- package/utils/retry.js +0 -50
- package/utils/slack.d.ts +0 -5
- package/utils/slack.js +0 -25
- package/utils/utils.d.ts +0 -30
- package/utils/utils.js +0 -64
package/.editorconfig
ADDED
package/.eslintignore
ADDED
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,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
|
package/.prettierrc.json
ADDED
@@ -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,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
|