@digitraffic/common 2022.10.28-2 → 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/stack/lambda-configs.js +8 -8
- package/jest.config.js +15 -0
- package/package.json +4 -4
- package/src/aws/infra/stack/lambda-configs.ts +12 -12
- package/src/aws/infra/stack/monitoredfunction.ts +3 -3
- 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/dist/aws/infra/api/integration.d.ts +0 -21
- package/dist/aws/infra/api/integration.js.map +0 -1
- package/dist/aws/infra/api/response.d.ts +0 -22
- package/dist/aws/infra/api/response.js.map +0 -1
- package/dist/aws/infra/api/responses.d.ts +0 -39
- package/dist/aws/infra/api/responses.js.map +0 -1
- package/dist/aws/infra/api/static-integration.d.ts +0 -15
- package/dist/aws/infra/api/static-integration.js.map +0 -1
- package/dist/aws/infra/canaries/canary-alarm.d.ts +0 -6
- package/dist/aws/infra/canaries/canary-alarm.js.map +0 -1
- package/dist/aws/infra/canaries/canary-keys.d.ts +0 -3
- package/dist/aws/infra/canaries/canary-keys.js.map +0 -1
- package/dist/aws/infra/canaries/canary-parameters.d.ts +0 -18
- package/dist/aws/infra/canaries/canary-parameters.js.map +0 -1
- package/dist/aws/infra/canaries/canary-role.d.ts +0 -6
- package/dist/aws/infra/canaries/canary-role.js.map +0 -1
- package/dist/aws/infra/canaries/canary.d.ts +0 -8
- package/dist/aws/infra/canaries/canary.js.map +0 -1
- package/dist/aws/infra/canaries/database-canary.d.ts +0 -18
- package/dist/aws/infra/canaries/database-canary.js.map +0 -1
- package/dist/aws/infra/canaries/database-checker.d.ts +0 -21
- package/dist/aws/infra/canaries/database-checker.js.map +0 -1
- package/dist/aws/infra/canaries/url-canary.d.ts +0 -16
- package/dist/aws/infra/canaries/url-canary.js.map +0 -1
- package/dist/aws/infra/canaries/url-checker.d.ts +0 -46
- package/dist/aws/infra/canaries/url-checker.js.map +0 -1
- package/dist/aws/infra/documentation.d.ts +0 -56
- package/dist/aws/infra/documentation.js.map +0 -1
- package/dist/aws/infra/scheduler.d.ts +0 -12
- package/dist/aws/infra/scheduler.js.map +0 -1
- package/dist/aws/infra/security-rule.d.ts +0 -12
- package/dist/aws/infra/security-rule.js.map +0 -1
- package/dist/aws/infra/sqs-integration.d.ts +0 -7
- package/dist/aws/infra/sqs-integration.js.map +0 -1
- package/dist/aws/infra/sqs-queue.d.ts +0 -16
- package/dist/aws/infra/sqs-queue.js.map +0 -1
- package/dist/aws/infra/stack/lambda-configs.d.ts +0 -72
- package/dist/aws/infra/stack/lambda-configs.js.map +0 -1
- package/dist/aws/infra/stack/monitoredfunction.d.ts +0 -84
- package/dist/aws/infra/stack/monitoredfunction.js.map +0 -1
- package/dist/aws/infra/stack/rest_apis.d.ts +0 -41
- package/dist/aws/infra/stack/rest_apis.js.map +0 -1
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +0 -21
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +0 -1
- package/dist/aws/infra/stack/stack.d.ts +0 -45
- package/dist/aws/infra/stack/stack.js.map +0 -1
- package/dist/aws/infra/stack/subscription.d.ts +0 -17
- package/dist/aws/infra/stack/subscription.js.map +0 -1
- package/dist/aws/infra/usage-plans.d.ts +0 -15
- package/dist/aws/infra/usage-plans.js.map +0 -1
- package/dist/aws/runtime/apikey.d.ts +0 -2
- package/dist/aws/runtime/apikey.js.map +0 -1
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +0 -8
- package/dist/aws/runtime/digitraffic-integration-response.js.map +0 -1
- package/dist/aws/runtime/environment.d.ts +0 -1
- package/dist/aws/runtime/environment.js.map +0 -1
- package/dist/aws/runtime/messaging.d.ts +0 -10
- package/dist/aws/runtime/messaging.js.map +0 -1
- package/dist/aws/runtime/s3.d.ts +0 -2
- package/dist/aws/runtime/s3.js.map +0 -1
- package/dist/aws/runtime/secrets/dbsecret.d.ts +0 -54
- package/dist/aws/runtime/secrets/dbsecret.js.map +0 -1
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +0 -9
- package/dist/aws/runtime/secrets/proxy-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/rds-holder.d.ts +0 -9
- package/dist/aws/runtime/secrets/rds-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/secret-holder.d.ts +0 -26
- package/dist/aws/runtime/secrets/secret-holder.js.map +0 -1
- package/dist/aws/runtime/secrets/secret.d.ts +0 -8
- package/dist/aws/runtime/secrets/secret.js.map +0 -1
- package/dist/aws/types/errors.d.ts +0 -8
- package/dist/aws/types/errors.js.map +0 -1
- package/dist/aws/types/lambda-response.d.ts +0 -13
- package/dist/aws/types/lambda-response.js.map +0 -1
- package/dist/aws/types/mediatypes.d.ts +0 -10
- package/dist/aws/types/mediatypes.js.map +0 -1
- package/dist/aws/types/model-with-reference.d.ts +0 -7
- package/dist/aws/types/model-with-reference.js.map +0 -1
- package/dist/aws/types/proxytypes.d.ts +0 -26
- package/dist/aws/types/proxytypes.js.map +0 -1
- package/dist/aws/types/tags.d.ts +0 -2
- package/dist/aws/types/tags.js.map +0 -1
- package/dist/database/cached.d.ts +0 -7
- package/dist/database/cached.js.map +0 -1
- package/dist/database/database.d.ts +0 -19
- package/dist/database/database.js.map +0 -1
- package/dist/database/last-updated.d.ts +0 -16
- package/dist/database/last-updated.js.map +0 -1
- package/dist/database/models.d.ts +0 -6
- package/dist/database/models.js.map +0 -1
- package/dist/marine/id_utils.d.ts +0 -3
- package/dist/marine/id_utils.js.map +0 -1
- package/dist/marine/rtz.d.ts +0 -48
- package/dist/marine/rtz.js.map +0 -1
- package/dist/test/asserter.d.ts +0 -11
- package/dist/test/asserter.js.map +0 -1
- package/dist/test/db-testutils.d.ts +0 -2
- package/dist/test/db-testutils.js.map +0 -1
- package/dist/test/httpserver.d.ts +0 -19
- package/dist/test/httpserver.js.map +0 -1
- package/dist/test/secret.d.ts +0 -3
- package/dist/test/secret.js.map +0 -1
- package/dist/test/secrets-manager.d.ts +0 -9
- package/dist/test/secrets-manager.js.map +0 -1
- package/dist/test/testutils.d.ts +0 -12
- package/dist/test/testutils.js.map +0 -1
- package/dist/types/either.d.ts +0 -9
- package/dist/types/either.js.map +0 -1
- package/dist/types/input-error.d.ts +0 -2
- package/dist/types/input-error.js.map +0 -1
- package/dist/types/language.d.ts +0 -5
- package/dist/types/language.js.map +0 -1
- package/dist/types/traffictype.d.ts +0 -8
- package/dist/types/traffictype.js.map +0 -1
- package/dist/types/validator.d.ts +0 -4
- package/dist/types/validator.js.map +0 -1
- package/dist/utils/api-model.d.ts +0 -87
- package/dist/utils/api-model.js.map +0 -1
- package/dist/utils/base64.d.ts +0 -12
- package/dist/utils/base64.js.map +0 -1
- package/dist/utils/date-utils.d.ts +0 -17
- package/dist/utils/date-utils.js.map +0 -1
- package/dist/utils/geojson-types.d.ts +0 -14
- package/dist/utils/geojson-types.js.map +0 -1
- package/dist/utils/geometry.d.ts +0 -36
- package/dist/utils/geometry.js.map +0 -1
- package/dist/utils/retry.d.ts +0 -13
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/slack.d.ts +0 -5
- package/dist/utils/slack.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -46
- package/dist/utils/utils.js.map +0 -1
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
@@ -22,22 +22,22 @@ function databaseFunctionProps(stack, environment, lambdaName, simpleLambdaName,
|
|
22
22
|
exports.databaseFunctionProps = databaseFunctionProps;
|
23
23
|
function lambdaFunctionProps(stack, environment, lambdaName, simpleLambdaName, config) {
|
24
24
|
return {
|
25
|
-
runtime: config?.runtime
|
26
|
-
architecture: config?.architecture
|
27
|
-
memorySize: config?.memorySize
|
25
|
+
runtime: config?.runtime ?? aws_lambda_1.Runtime.NODEJS_14_X,
|
26
|
+
architecture: config?.architecture ?? aws_lambda_1.Architecture.ARM_64,
|
27
|
+
memorySize: config?.memorySize ?? 128,
|
28
28
|
functionName: lambdaName,
|
29
29
|
role: config?.role,
|
30
|
-
timeout: aws_cdk_lib_1.Duration.seconds(config?.timeout
|
30
|
+
timeout: aws_cdk_lib_1.Duration.seconds(config?.timeout ?? 60),
|
31
31
|
logRetention: aws_logs_1.RetentionDays.ONE_YEAR,
|
32
|
-
reservedConcurrentExecutions: config?.reservedConcurrentExecutions
|
33
|
-
code: getAssetCode(simpleLambdaName, config),
|
32
|
+
reservedConcurrentExecutions: config?.reservedConcurrentExecutions ?? 2,
|
33
|
+
code: getAssetCode(simpleLambdaName, config?.singleLambda ?? false),
|
34
34
|
handler: `${simpleLambdaName}.handler`,
|
35
35
|
environment,
|
36
36
|
};
|
37
37
|
}
|
38
38
|
exports.lambdaFunctionProps = lambdaFunctionProps;
|
39
|
-
function getAssetCode(simpleLambdaName,
|
40
|
-
const lambdaPath =
|
39
|
+
function getAssetCode(simpleLambdaName, isSingleLambda) {
|
40
|
+
const lambdaPath = isSingleLambda
|
41
41
|
? `dist/lambda/`
|
42
42
|
: `dist/lambda/${simpleLambdaName}`;
|
43
43
|
return new aws_lambda_1.AssetCode(lambdaPath);
|
package/jest.config.js
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2022.10.
|
3
|
+
"version": "2022.10.31-1",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -26,10 +26,10 @@
|
|
26
26
|
"src/**/*.ts"
|
27
27
|
],
|
28
28
|
"dependencies": {
|
29
|
-
"@aws-cdk/aws-synthetics-alpha": "2.
|
29
|
+
"@aws-cdk/aws-synthetics-alpha": "2.47.0-alpha.0",
|
30
30
|
"@types/geojson": "^7946.0.10",
|
31
|
-
"aws-cdk-lib": "2.
|
32
|
-
"aws-sdk": "2.
|
31
|
+
"aws-cdk-lib": "2.47.0",
|
32
|
+
"aws-sdk": "2.1241.0",
|
33
33
|
"axios": "^0.21.1",
|
34
34
|
"change-case": "4.1.2",
|
35
35
|
"constructs": "10.1.131",
|
@@ -44,7 +44,7 @@ export function databaseFunctionProps(
|
|
44
44
|
environment: LambdaEnvironment,
|
45
45
|
lambdaName: string,
|
46
46
|
simpleLambdaName: string,
|
47
|
-
config?: FunctionParameters
|
47
|
+
config?: Partial<FunctionParameters>
|
48
48
|
): FunctionProps {
|
49
49
|
const vpcSubnets = stack.vpc
|
50
50
|
? {
|
@@ -73,18 +73,18 @@ export function lambdaFunctionProps(
|
|
73
73
|
environment: LambdaEnvironment,
|
74
74
|
lambdaName: string,
|
75
75
|
simpleLambdaName: string,
|
76
|
-
config?: FunctionParameters
|
76
|
+
config?: Partial<FunctionParameters>
|
77
77
|
): FunctionProps {
|
78
78
|
return {
|
79
|
-
runtime: config?.runtime
|
80
|
-
architecture: config?.architecture
|
81
|
-
memorySize: config?.memorySize
|
79
|
+
runtime: config?.runtime ?? Runtime.NODEJS_14_X,
|
80
|
+
architecture: config?.architecture ?? Architecture.ARM_64,
|
81
|
+
memorySize: config?.memorySize ?? 128,
|
82
82
|
functionName: lambdaName,
|
83
83
|
role: config?.role,
|
84
|
-
timeout: Duration.seconds(config?.timeout
|
84
|
+
timeout: Duration.seconds(config?.timeout ?? 60),
|
85
85
|
logRetention: RetentionDays.ONE_YEAR,
|
86
|
-
reservedConcurrentExecutions: config?.reservedConcurrentExecutions
|
87
|
-
code: getAssetCode(simpleLambdaName, config),
|
86
|
+
reservedConcurrentExecutions: config?.reservedConcurrentExecutions ?? 2,
|
87
|
+
code: getAssetCode(simpleLambdaName, config?.singleLambda ?? false),
|
88
88
|
handler: `${simpleLambdaName}.handler`,
|
89
89
|
environment,
|
90
90
|
};
|
@@ -92,9 +92,9 @@ export function lambdaFunctionProps(
|
|
92
92
|
|
93
93
|
function getAssetCode(
|
94
94
|
simpleLambdaName: string,
|
95
|
-
|
95
|
+
isSingleLambda: boolean
|
96
96
|
): AssetCode {
|
97
|
-
const lambdaPath =
|
97
|
+
const lambdaPath = isSingleLambda
|
98
98
|
? `dist/lambda/`
|
99
99
|
: `dist/lambda/${simpleLambdaName}`;
|
100
100
|
|
@@ -190,7 +190,7 @@ export interface FunctionParameters {
|
|
190
190
|
singleLambda?: boolean;
|
191
191
|
}
|
192
192
|
|
193
|
-
export type MonitoredFunctionParameters = {
|
193
|
+
export type MonitoredFunctionParameters = FunctionParameters & {
|
194
194
|
readonly memorySize?: number;
|
195
195
|
readonly timeout?: number;
|
196
196
|
readonly functionName?: string;
|
@@ -204,4 +204,4 @@ export type MonitoredFunctionParameters = {
|
|
204
204
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
205
205
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|
206
206
|
readonly throttleAlarmProps?: MonitoredFunctionAlarmProps;
|
207
|
-
}
|
207
|
+
};
|
@@ -75,7 +75,7 @@ export class MonitoredFunction extends Function {
|
|
75
75
|
stack: DigitrafficStack,
|
76
76
|
id: string,
|
77
77
|
functionProps: FunctionProps,
|
78
|
-
props?: MonitoredFunctionProps
|
78
|
+
props?: Partial<MonitoredFunctionProps>
|
79
79
|
): MonitoredFunction {
|
80
80
|
if (
|
81
81
|
props === MonitoredFunction.DISABLE_ALARMS &&
|
@@ -112,7 +112,7 @@ export class MonitoredFunction extends Function {
|
|
112
112
|
stack: DigitrafficStack,
|
113
113
|
name: string,
|
114
114
|
environment: LambdaEnvironment,
|
115
|
-
functionParameters?: MonitoredFunctionParameters
|
115
|
+
functionParameters?: Partial<MonitoredFunctionParameters>
|
116
116
|
): MonitoredFunction {
|
117
117
|
const functionName =
|
118
118
|
functionParameters?.functionName ||
|
@@ -310,7 +310,7 @@ export class MonitoredDBFunction {
|
|
310
310
|
stack: DigitrafficStack,
|
311
311
|
name: string,
|
312
312
|
environment?: LambdaEnvironment,
|
313
|
-
functionParameters?: MonitoredFunctionParameters
|
313
|
+
functionParameters?: Partial<MonitoredFunctionParameters>
|
314
314
|
): MonitoredFunction {
|
315
315
|
const functionName =
|
316
316
|
functionParameters?.functionName ||
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import * as IdUtils from '../../src/marine/id_utils';
|
2
|
+
import {getRandomNumber} from "../../src/test/testutils";
|
3
|
+
|
4
|
+
describe('IdUtils tests', () => {
|
5
|
+
|
6
|
+
test('isValidLOCODE - success', () => {
|
7
|
+
expect(IdUtils.isValidLOCODE('FILOL')).toBe(true);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('isValidLOCODE - fail with non-finnish prefix', () => {
|
11
|
+
expect(IdUtils.isValidLOCODE('SEABS')).toBe(false);
|
12
|
+
});
|
13
|
+
|
14
|
+
test('isValidLOCODE - fail with numbers', () => {
|
15
|
+
expect(IdUtils.isValidLOCODE('FIAA1')).toBe(false);
|
16
|
+
});
|
17
|
+
|
18
|
+
test('isValidIMO - successful checksum - ship TRANSMAR', () => {
|
19
|
+
expect(IdUtils.isValidIMO(9167332)).toBe(true);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('isValidIMO - successful checksum - ship ANNIKA B', () => {
|
23
|
+
expect(IdUtils.isValidIMO(9213715)).toBe(true);
|
24
|
+
});
|
25
|
+
|
26
|
+
test('isValidIMO - successful checksum - ship X PRESS ELBE', () => {
|
27
|
+
expect(IdUtils.isValidIMO(9483669)).toBe(true);
|
28
|
+
});
|
29
|
+
|
30
|
+
test('isValidIMO - successful checksum - ship SILVERFORS', () => {
|
31
|
+
expect(IdUtils.isValidIMO(8322765)).toBe(true);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('isValidIMO - invalid checksum', () => {
|
35
|
+
expect(IdUtils.isValidIMO(8322766)).toBe(false);
|
36
|
+
});
|
37
|
+
|
38
|
+
test('isValidIMO - fail with number smaller than 1000000', () => {
|
39
|
+
expect(IdUtils.isValidIMO(getRandomNumber(0, 1000000 - 1))).toBe(false);
|
40
|
+
});
|
41
|
+
|
42
|
+
test('isValidIMO - fail with number larger than 9999999', () => {
|
43
|
+
expect(IdUtils.isValidIMO(getRandomNumber(9999999 + 1, 99999999))).toBe(false);
|
44
|
+
});
|
45
|
+
|
46
|
+
test('isValidMMSI - success', () => {
|
47
|
+
expect(IdUtils.isValidMMSI(230927000)).toBe(true);
|
48
|
+
});
|
49
|
+
|
50
|
+
test('isValidMMSI - fail with number smaller than 100000000', () => {
|
51
|
+
expect(IdUtils.isValidMMSI(getRandomNumber(0, 100000000 - 1))).toBe(false);
|
52
|
+
});
|
53
|
+
|
54
|
+
test('isValidMMSI - fail with number larger than 999999999', () => {
|
55
|
+
expect(IdUtils.isValidMMSI(getRandomNumber(999999999 + 1, 9999999999))).toBe(false);
|
56
|
+
});
|
57
|
+
});
|
@@ -0,0 +1,143 @@
|
|
1
|
+
import {getRandomInteger} from "../../src/test/testutils";
|
2
|
+
import {retry, RetryLogError} from "../../src/utils/retry";
|
3
|
+
|
4
|
+
describe('Promise utils tests', () => {
|
5
|
+
|
6
|
+
test('retry - no retries', async () => {
|
7
|
+
const fn = jest.fn().mockResolvedValue(1);
|
8
|
+
|
9
|
+
const ret = await retry(fn, 0, RetryLogError.NO_LOGGING);
|
10
|
+
|
11
|
+
expect(ret).toBe(1);
|
12
|
+
expect(fn.mock.calls.length).toBe(1);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('retry - error with n+1 retries', async () => {
|
16
|
+
const fn = jest.fn().mockRejectedValue('error');
|
17
|
+
const retries = getRandomInteger(1, 10);
|
18
|
+
|
19
|
+
try {
|
20
|
+
await retry(fn, retries, RetryLogError.NO_LOGGING);
|
21
|
+
} catch {
|
22
|
+
// ignore
|
23
|
+
} finally {
|
24
|
+
expect(fn.mock.calls.length).toBe(retries + 1);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
test('retry - no error with n+1 retries', async () => {
|
29
|
+
const fn = jest.fn().mockResolvedValue(1);
|
30
|
+
const retries = getRandomInteger(1, 10);
|
31
|
+
|
32
|
+
const ret = await retry(fn, retries, RetryLogError.NO_LOGGING);
|
33
|
+
|
34
|
+
expect(ret).toBe(1);
|
35
|
+
expect(fn.mock.calls.length).toBe(1);
|
36
|
+
});
|
37
|
+
|
38
|
+
test('retry - errors with no error logging', async () => {
|
39
|
+
const fn = jest.fn().mockRejectedValue('error');
|
40
|
+
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
41
|
+
|
42
|
+
try {
|
43
|
+
await retry(fn, getRandomInteger(0, 10), RetryLogError.NO_LOGGING);
|
44
|
+
} catch {
|
45
|
+
// ignore
|
46
|
+
} finally {
|
47
|
+
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
|
48
|
+
consoleErrorSpy.mockRestore();
|
49
|
+
}
|
50
|
+
});
|
51
|
+
|
52
|
+
test('retry - no retries with error logging', async () => {
|
53
|
+
const fn = jest.fn().mockRejectedValue('error');
|
54
|
+
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
55
|
+
|
56
|
+
try {
|
57
|
+
await retry(fn, 0, RetryLogError.LOG_ALL_AS_ERRORS);
|
58
|
+
} catch {
|
59
|
+
// ignore
|
60
|
+
} finally {
|
61
|
+
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
62
|
+
consoleErrorSpy.mockRestore();
|
63
|
+
}
|
64
|
+
});
|
65
|
+
|
66
|
+
test('retry - retries with error logging', async () => {
|
67
|
+
const fn = jest.fn().mockRejectedValue('error');
|
68
|
+
const retries = getRandomInteger(1, 10);
|
69
|
+
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
70
|
+
|
71
|
+
try {
|
72
|
+
await retry(fn, retries, RetryLogError.LOG_ALL_AS_ERRORS);
|
73
|
+
} catch {
|
74
|
+
// ignore
|
75
|
+
} finally {
|
76
|
+
expect(consoleErrorSpy).toHaveBeenCalledTimes(retries + 1);
|
77
|
+
consoleErrorSpy.mockRestore();
|
78
|
+
}
|
79
|
+
});
|
80
|
+
|
81
|
+
test('retry - exceeded retry count throws error', async () => {
|
82
|
+
const fn = jest.fn().mockRejectedValue('error');
|
83
|
+
|
84
|
+
await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
|
85
|
+
});
|
86
|
+
|
87
|
+
test('retry - defaults', async () => {
|
88
|
+
const fn = jest.fn().mockRejectedValue('error');
|
89
|
+
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
90
|
+
|
91
|
+
try {
|
92
|
+
await retry(fn);
|
93
|
+
} catch {
|
94
|
+
// ignore
|
95
|
+
} finally {
|
96
|
+
expect(fn.mock.calls.length).toBe(3 + 1);
|
97
|
+
expect(consoleErrorSpy).toHaveBeenCalledTimes(1); // last retry
|
98
|
+
}
|
99
|
+
});
|
100
|
+
|
101
|
+
test('retry - NaN throws error', async () => {
|
102
|
+
const fn = jest.fn();
|
103
|
+
|
104
|
+
await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
105
|
+
});
|
106
|
+
|
107
|
+
test('retry - Infinity throws error', async () => {
|
108
|
+
const fn = jest.fn();
|
109
|
+
|
110
|
+
await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
111
|
+
});
|
112
|
+
|
113
|
+
test('retry - exceeded maximum retry count throws error', async () => {
|
114
|
+
const fn = jest.fn();
|
115
|
+
|
116
|
+
await expect(() => retry(fn, getRandomInteger(101, 1000000), RetryLogError.NO_LOGGING)).rejects.toThrow();
|
117
|
+
});
|
118
|
+
|
119
|
+
test('retry - use without mocks without retry', async () => {
|
120
|
+
const val = 1;
|
121
|
+
const fn = () => Promise.resolve(val);
|
122
|
+
|
123
|
+
const ret = await retry(fn);
|
124
|
+
|
125
|
+
expect(ret).toBe(val);
|
126
|
+
});
|
127
|
+
|
128
|
+
test('retry - use without mocks with retry', async () => {
|
129
|
+
let i = 0;
|
130
|
+
const val = 1;
|
131
|
+
const fn = () => {
|
132
|
+
if (i < 3) {
|
133
|
+
i++;
|
134
|
+
throw new Error('not yet');
|
135
|
+
}
|
136
|
+
return Promise.resolve(val);
|
137
|
+
};
|
138
|
+
|
139
|
+
const ret = await retry(fn);
|
140
|
+
|
141
|
+
expect(ret).toBe(val);
|
142
|
+
});
|
143
|
+
});
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import {mockSecret, stubSecretsManager} from "../../src/test/secrets-manager";
|
2
|
+
|
3
|
+
import * as sinon from 'sinon';
|
4
|
+
|
5
|
+
const SECRET_ID = "test_secret";
|
6
|
+
const SECRET_WITH_PREFIX = {
|
7
|
+
"prefix.value" : "value",
|
8
|
+
"prefix.name" : "name",
|
9
|
+
"wrong.value" : "value",
|
10
|
+
};
|
11
|
+
const SECRET_EMPTY = {};
|
12
|
+
|
13
|
+
stubSecretsManager();
|
14
|
+
|
15
|
+
import {GenericSecret, withSecret, withSecretAndPrefix} from "../../src/aws/runtime/secrets/secret";
|
16
|
+
|
17
|
+
describe('secret - test', () => {
|
18
|
+
afterEach(() => {
|
19
|
+
sinon.restore();
|
20
|
+
});
|
21
|
+
|
22
|
+
test('getSecret - no secret', async () => {
|
23
|
+
mockSecret(null);
|
24
|
+
|
25
|
+
await expect(async () => {
|
26
|
+
await withSecret(SECRET_ID, () => {
|
27
|
+
// do nothing
|
28
|
+
});
|
29
|
+
}).rejects.toThrowError("No secret found!");
|
30
|
+
});
|
31
|
+
|
32
|
+
test('getSecret - empty secret', async () => {
|
33
|
+
mockSecret(SECRET_EMPTY);
|
34
|
+
|
35
|
+
await withSecret(SECRET_ID, (secret: GenericSecret) => {
|
36
|
+
expect(secret).toEqual(SECRET_EMPTY);
|
37
|
+
});
|
38
|
+
});
|
39
|
+
|
40
|
+
test('getSecret - no prefix', async () => {
|
41
|
+
mockSecret(SECRET_WITH_PREFIX);
|
42
|
+
|
43
|
+
await withSecret(SECRET_ID, (secret: GenericSecret) => {
|
44
|
+
expect(secret).toEqual(SECRET_WITH_PREFIX);
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
48
|
+
test('getSecret - with prefix', async () => {
|
49
|
+
mockSecret(SECRET_WITH_PREFIX);
|
50
|
+
|
51
|
+
await withSecretAndPrefix(SECRET_ID, 'prefix', (secret: GenericSecret) => {
|
52
|
+
expect(secret).toEqual({
|
53
|
+
value: "value",
|
54
|
+
name: "name",
|
55
|
+
});
|
56
|
+
});
|
57
|
+
|
58
|
+
});
|
59
|
+
});
|