@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.
Files changed (159) 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/stack/lambda-configs.js +8 -8
  12. package/jest.config.js +15 -0
  13. package/package.json +4 -4
  14. package/src/aws/infra/stack/lambda-configs.ts +12 -12
  15. package/src/aws/infra/stack/monitoredfunction.ts +3 -3
  16. package/test/marine/id_utils.test.ts +57 -0
  17. package/test/promise/promise.test.ts +143 -0
  18. package/test/secrets/dbsecret.test.ts +59 -0
  19. package/test/secrets/secret-holder.test.ts +143 -0
  20. package/test/secrets/secret.test.ts +49 -0
  21. package/test/test/httpserver.test.ts +128 -0
  22. package/test/utils/date-utils.test.ts +28 -0
  23. package/test/utils/geometry.test.ts +29 -0
  24. package/test/utils/utils.test.ts +64 -0
  25. package/tsconfig.eslint.json +4 -0
  26. package/tsconfig.json +22 -0
  27. package/yarn.lock +4060 -0
  28. package/dist/aws/infra/api/integration.d.ts +0 -21
  29. package/dist/aws/infra/api/integration.js.map +0 -1
  30. package/dist/aws/infra/api/response.d.ts +0 -22
  31. package/dist/aws/infra/api/response.js.map +0 -1
  32. package/dist/aws/infra/api/responses.d.ts +0 -39
  33. package/dist/aws/infra/api/responses.js.map +0 -1
  34. package/dist/aws/infra/api/static-integration.d.ts +0 -15
  35. package/dist/aws/infra/api/static-integration.js.map +0 -1
  36. package/dist/aws/infra/canaries/canary-alarm.d.ts +0 -6
  37. package/dist/aws/infra/canaries/canary-alarm.js.map +0 -1
  38. package/dist/aws/infra/canaries/canary-keys.d.ts +0 -3
  39. package/dist/aws/infra/canaries/canary-keys.js.map +0 -1
  40. package/dist/aws/infra/canaries/canary-parameters.d.ts +0 -18
  41. package/dist/aws/infra/canaries/canary-parameters.js.map +0 -1
  42. package/dist/aws/infra/canaries/canary-role.d.ts +0 -6
  43. package/dist/aws/infra/canaries/canary-role.js.map +0 -1
  44. package/dist/aws/infra/canaries/canary.d.ts +0 -8
  45. package/dist/aws/infra/canaries/canary.js.map +0 -1
  46. package/dist/aws/infra/canaries/database-canary.d.ts +0 -18
  47. package/dist/aws/infra/canaries/database-canary.js.map +0 -1
  48. package/dist/aws/infra/canaries/database-checker.d.ts +0 -21
  49. package/dist/aws/infra/canaries/database-checker.js.map +0 -1
  50. package/dist/aws/infra/canaries/url-canary.d.ts +0 -16
  51. package/dist/aws/infra/canaries/url-canary.js.map +0 -1
  52. package/dist/aws/infra/canaries/url-checker.d.ts +0 -46
  53. package/dist/aws/infra/canaries/url-checker.js.map +0 -1
  54. package/dist/aws/infra/documentation.d.ts +0 -56
  55. package/dist/aws/infra/documentation.js.map +0 -1
  56. package/dist/aws/infra/scheduler.d.ts +0 -12
  57. package/dist/aws/infra/scheduler.js.map +0 -1
  58. package/dist/aws/infra/security-rule.d.ts +0 -12
  59. package/dist/aws/infra/security-rule.js.map +0 -1
  60. package/dist/aws/infra/sqs-integration.d.ts +0 -7
  61. package/dist/aws/infra/sqs-integration.js.map +0 -1
  62. package/dist/aws/infra/sqs-queue.d.ts +0 -16
  63. package/dist/aws/infra/sqs-queue.js.map +0 -1
  64. package/dist/aws/infra/stack/lambda-configs.d.ts +0 -72
  65. package/dist/aws/infra/stack/lambda-configs.js.map +0 -1
  66. package/dist/aws/infra/stack/monitoredfunction.d.ts +0 -84
  67. package/dist/aws/infra/stack/monitoredfunction.js.map +0 -1
  68. package/dist/aws/infra/stack/rest_apis.d.ts +0 -41
  69. package/dist/aws/infra/stack/rest_apis.js.map +0 -1
  70. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +0 -21
  71. package/dist/aws/infra/stack/stack-checking-aspect.js.map +0 -1
  72. package/dist/aws/infra/stack/stack.d.ts +0 -45
  73. package/dist/aws/infra/stack/stack.js.map +0 -1
  74. package/dist/aws/infra/stack/subscription.d.ts +0 -17
  75. package/dist/aws/infra/stack/subscription.js.map +0 -1
  76. package/dist/aws/infra/usage-plans.d.ts +0 -15
  77. package/dist/aws/infra/usage-plans.js.map +0 -1
  78. package/dist/aws/runtime/apikey.d.ts +0 -2
  79. package/dist/aws/runtime/apikey.js.map +0 -1
  80. package/dist/aws/runtime/digitraffic-integration-response.d.ts +0 -8
  81. package/dist/aws/runtime/digitraffic-integration-response.js.map +0 -1
  82. package/dist/aws/runtime/environment.d.ts +0 -1
  83. package/dist/aws/runtime/environment.js.map +0 -1
  84. package/dist/aws/runtime/messaging.d.ts +0 -10
  85. package/dist/aws/runtime/messaging.js.map +0 -1
  86. package/dist/aws/runtime/s3.d.ts +0 -2
  87. package/dist/aws/runtime/s3.js.map +0 -1
  88. package/dist/aws/runtime/secrets/dbsecret.d.ts +0 -54
  89. package/dist/aws/runtime/secrets/dbsecret.js.map +0 -1
  90. package/dist/aws/runtime/secrets/proxy-holder.d.ts +0 -9
  91. package/dist/aws/runtime/secrets/proxy-holder.js.map +0 -1
  92. package/dist/aws/runtime/secrets/rds-holder.d.ts +0 -9
  93. package/dist/aws/runtime/secrets/rds-holder.js.map +0 -1
  94. package/dist/aws/runtime/secrets/secret-holder.d.ts +0 -26
  95. package/dist/aws/runtime/secrets/secret-holder.js.map +0 -1
  96. package/dist/aws/runtime/secrets/secret.d.ts +0 -8
  97. package/dist/aws/runtime/secrets/secret.js.map +0 -1
  98. package/dist/aws/types/errors.d.ts +0 -8
  99. package/dist/aws/types/errors.js.map +0 -1
  100. package/dist/aws/types/lambda-response.d.ts +0 -13
  101. package/dist/aws/types/lambda-response.js.map +0 -1
  102. package/dist/aws/types/mediatypes.d.ts +0 -10
  103. package/dist/aws/types/mediatypes.js.map +0 -1
  104. package/dist/aws/types/model-with-reference.d.ts +0 -7
  105. package/dist/aws/types/model-with-reference.js.map +0 -1
  106. package/dist/aws/types/proxytypes.d.ts +0 -26
  107. package/dist/aws/types/proxytypes.js.map +0 -1
  108. package/dist/aws/types/tags.d.ts +0 -2
  109. package/dist/aws/types/tags.js.map +0 -1
  110. package/dist/database/cached.d.ts +0 -7
  111. package/dist/database/cached.js.map +0 -1
  112. package/dist/database/database.d.ts +0 -19
  113. package/dist/database/database.js.map +0 -1
  114. package/dist/database/last-updated.d.ts +0 -16
  115. package/dist/database/last-updated.js.map +0 -1
  116. package/dist/database/models.d.ts +0 -6
  117. package/dist/database/models.js.map +0 -1
  118. package/dist/marine/id_utils.d.ts +0 -3
  119. package/dist/marine/id_utils.js.map +0 -1
  120. package/dist/marine/rtz.d.ts +0 -48
  121. package/dist/marine/rtz.js.map +0 -1
  122. package/dist/test/asserter.d.ts +0 -11
  123. package/dist/test/asserter.js.map +0 -1
  124. package/dist/test/db-testutils.d.ts +0 -2
  125. package/dist/test/db-testutils.js.map +0 -1
  126. package/dist/test/httpserver.d.ts +0 -19
  127. package/dist/test/httpserver.js.map +0 -1
  128. package/dist/test/secret.d.ts +0 -3
  129. package/dist/test/secret.js.map +0 -1
  130. package/dist/test/secrets-manager.d.ts +0 -9
  131. package/dist/test/secrets-manager.js.map +0 -1
  132. package/dist/test/testutils.d.ts +0 -12
  133. package/dist/test/testutils.js.map +0 -1
  134. package/dist/types/either.d.ts +0 -9
  135. package/dist/types/either.js.map +0 -1
  136. package/dist/types/input-error.d.ts +0 -2
  137. package/dist/types/input-error.js.map +0 -1
  138. package/dist/types/language.d.ts +0 -5
  139. package/dist/types/language.js.map +0 -1
  140. package/dist/types/traffictype.d.ts +0 -8
  141. package/dist/types/traffictype.js.map +0 -1
  142. package/dist/types/validator.d.ts +0 -4
  143. package/dist/types/validator.js.map +0 -1
  144. package/dist/utils/api-model.d.ts +0 -87
  145. package/dist/utils/api-model.js.map +0 -1
  146. package/dist/utils/base64.d.ts +0 -12
  147. package/dist/utils/base64.js.map +0 -1
  148. package/dist/utils/date-utils.d.ts +0 -17
  149. package/dist/utils/date-utils.js.map +0 -1
  150. package/dist/utils/geojson-types.d.ts +0 -14
  151. package/dist/utils/geojson-types.js.map +0 -1
  152. package/dist/utils/geometry.d.ts +0 -36
  153. package/dist/utils/geometry.js.map +0 -1
  154. package/dist/utils/retry.d.ts +0 -13
  155. package/dist/utils/retry.js.map +0 -1
  156. package/dist/utils/slack.d.ts +0 -5
  157. package/dist/utils/slack.js.map +0 -1
  158. package/dist/utils/utils.d.ts +0 -46
  159. package/dist/utils/utils.js.map +0 -1
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
+ }
@@ -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 || aws_lambda_1.Runtime.NODEJS_14_X,
26
- architecture: config?.architecture || aws_lambda_1.Architecture.ARM_64,
27
- memorySize: config?.memorySize || 128,
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 || 60),
30
+ timeout: aws_cdk_lib_1.Duration.seconds(config?.timeout ?? 60),
31
31
  logRetention: aws_logs_1.RetentionDays.ONE_YEAR,
32
- reservedConcurrentExecutions: config?.reservedConcurrentExecutions || 2,
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, config) {
40
- const lambdaPath = config?.singleLambda
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
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ roots: [
3
+ '<rootDir>/test',
4
+ ],
5
+ testMatch: [
6
+ '**/*.test.ts',
7
+ ],
8
+ testResultsProcessor: 'jest-junit',
9
+ preset: 'ts-jest',
10
+ coverageThreshold: {
11
+ global: {
12
+ lines: 70,
13
+ },
14
+ },
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2022.10.28-2",
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.46.0-alpha.0",
29
+ "@aws-cdk/aws-synthetics-alpha": "2.47.0-alpha.0",
30
30
  "@types/geojson": "^7946.0.10",
31
- "aws-cdk-lib": "2.46.0",
32
- "aws-sdk": "2.1232.0",
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 || Runtime.NODEJS_14_X,
80
- architecture: config?.architecture || Architecture.ARM_64,
81
- memorySize: config?.memorySize || 128,
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 || 60),
84
+ timeout: Duration.seconds(config?.timeout ?? 60),
85
85
  logRetention: RetentionDays.ONE_YEAR,
86
- reservedConcurrentExecutions: config?.reservedConcurrentExecutions || 2,
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
- config?: FunctionParameters
95
+ isSingleLambda: boolean
96
96
  ): AssetCode {
97
- const lambdaPath = config?.singleLambda
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
- } & FunctionParameters;
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
+ });