@digitraffic/common 2022.10.25-1 → 2022.10.28-2
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/{aws → dist/aws}/infra/api/integration.d.ts +0 -0
- package/dist/aws/infra/api/integration.js +52 -0
- package/dist/aws/infra/api/integration.js.map +1 -0
- package/{aws → dist/aws}/infra/api/response.d.ts +0 -0
- package/dist/aws/infra/api/response.js +61 -0
- package/dist/aws/infra/api/response.js.map +1 -0
- package/{aws → dist/aws}/infra/api/responses.d.ts +3 -3
- package/dist/aws/infra/api/responses.js +82 -0
- package/dist/aws/infra/api/responses.js.map +1 -0
- package/{aws → dist/aws}/infra/api/static-integration.d.ts +0 -0
- package/dist/aws/infra/api/static-integration.js +54 -0
- package/dist/aws/infra/api/static-integration.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-alarm.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-alarm.js +26 -0
- package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js +7 -0
- package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-parameters.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-parameters.js +3 -0
- package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-role.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-role.js +46 -0
- package/dist/aws/infra/canaries/canary-role.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary.d.ts +0 -0
- package/dist/aws/infra/canaries/canary.js +32 -0
- package/dist/aws/infra/canaries/canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/database-canary.d.ts +0 -0
- package/dist/aws/infra/canaries/database-canary.js +70 -0
- package/dist/aws/infra/canaries/database-canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/database-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/database-checker.js +103 -0
- package/dist/aws/infra/canaries/database-checker.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/url-canary.d.ts +0 -3
- package/dist/aws/infra/canaries/url-canary.js +47 -0
- package/dist/aws/infra/canaries/url-canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/url-checker.d.ts +0 -0
- package/dist/aws/infra/canaries/url-checker.js +252 -0
- package/dist/aws/infra/canaries/url-checker.js.map +1 -0
- package/{aws → dist/aws}/infra/documentation.d.ts +0 -0
- package/dist/aws/infra/documentation.js +95 -0
- package/dist/aws/infra/documentation.js.map +1 -0
- package/{aws → dist/aws}/infra/scheduler.d.ts +7 -7
- package/dist/aws/infra/scheduler.js +31 -0
- package/dist/aws/infra/scheduler.js.map +1 -0
- package/{aws → dist/aws}/infra/security-rule.d.ts +0 -0
- package/dist/aws/infra/security-rule.js +39 -0
- package/dist/aws/infra/security-rule.js.map +1 -0
- package/{aws → dist/aws}/infra/sqs-integration.d.ts +0 -0
- package/dist/aws/infra/sqs-integration.js +93 -0
- package/dist/aws/infra/sqs-integration.js.map +1 -0
- package/{aws → dist/aws}/infra/sqs-queue.d.ts +0 -0
- package/dist/aws/infra/sqs-queue.js +130 -0
- package/dist/aws/infra/sqs-queue.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/lambda-configs.d.ts +5 -5
- package/dist/aws/infra/stack/lambda-configs.js +105 -0
- package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/monitoredfunction.d.ts +1 -1
- package/dist/aws/infra/stack/monitoredfunction.js +143 -0
- package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/rest_apis.d.ts +0 -0
- package/dist/aws/infra/stack/rest_apis.js +185 -0
- package/dist/aws/infra/stack/rest_apis.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/stack-checking-aspect.d.ts +0 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +174 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/stack.d.ts +5 -4
- package/dist/aws/infra/stack/stack.js +67 -0
- package/dist/aws/infra/stack/stack.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/subscription.d.ts +3 -3
- package/dist/aws/infra/stack/subscription.js +42 -0
- package/dist/aws/infra/stack/subscription.js.map +1 -0
- package/{aws → dist/aws}/infra/usage-plans.d.ts +0 -0
- package/dist/aws/infra/usage-plans.js +42 -0
- package/dist/aws/infra/usage-plans.js.map +1 -0
- package/{aws → dist/aws}/runtime/apikey.d.ts +0 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/apikey.js.map +1 -0
- package/{aws → dist/aws}/runtime/digitraffic-integration-response.d.ts +0 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +26 -0
- package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
- package/{aws → dist/aws}/runtime/environment.d.ts +0 -0
- package/dist/aws/runtime/environment.js +12 -0
- package/dist/aws/runtime/environment.js.map +1 -0
- package/{aws → dist/aws}/runtime/messaging.d.ts +0 -0
- package/dist/aws/runtime/messaging.js +31 -0
- package/dist/aws/runtime/messaging.js.map +1 -0
- package/{aws → dist/aws}/runtime/s3.d.ts +0 -0
- package/dist/aws/runtime/s3.js +30 -0
- package/dist/aws/runtime/s3.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/dbsecret.d.ts +0 -0
- package/dist/aws/runtime/secrets/dbsecret.js +96 -0
- package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/proxy-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +27 -0
- package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/rds-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/rds-holder.js +27 -0
- package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/secret-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/secret-holder.js +76 -0
- package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/secret.d.ts +0 -0
- package/dist/aws/runtime/secrets/secret.js +43 -0
- package/dist/aws/runtime/secrets/secret.js.map +1 -0
- package/{aws → dist/aws}/types/errors.d.ts +4 -0
- package/dist/aws/types/errors.js +16 -0
- package/dist/aws/types/errors.js.map +1 -0
- package/{aws → dist/aws}/types/lambda-response.d.ts +4 -3
- package/dist/aws/types/lambda-response.js +33 -0
- package/dist/aws/types/lambda-response.js.map +1 -0
- package/{aws → dist/aws}/types/mediatypes.d.ts +1 -1
- package/dist/aws/types/mediatypes.js +16 -0
- package/dist/aws/types/mediatypes.js.map +1 -0
- package/{aws → dist/aws}/types/model-with-reference.d.ts +0 -0
- package/dist/aws/types/model-with-reference.js +3 -0
- package/dist/aws/types/model-with-reference.js.map +1 -0
- package/{aws → dist/aws}/types/proxytypes.d.ts +0 -0
- package/dist/aws/types/proxytypes.js +3 -0
- package/dist/aws/types/proxytypes.js.map +1 -0
- package/{aws → dist/aws}/types/tags.d.ts +0 -0
- package/dist/aws/types/tags.js +7 -0
- package/dist/aws/types/tags.js.map +1 -0
- package/{database → dist/database}/cached.d.ts +0 -0
- package/dist/database/cached.js +32 -0
- package/dist/database/cached.js.map +1 -0
- package/{database → dist/database}/database.d.ts +0 -0
- package/dist/database/database.js +70 -0
- package/dist/database/database.js.map +1 -0
- package/{database → dist/database}/last-updated.d.ts +0 -0
- package/dist/database/last-updated.js +54 -0
- package/dist/database/last-updated.js.map +1 -0
- package/{database → dist/database}/models.d.ts +0 -0
- package/dist/database/models.js +3 -0
- package/dist/database/models.js.map +1 -0
- package/{marine → dist/marine}/id_utils.d.ts +0 -0
- package/dist/marine/id_utils.js +33 -0
- package/dist/marine/id_utils.js.map +1 -0
- package/{marine → dist/marine}/rtz.d.ts +0 -0
- package/dist/marine/rtz.js +3 -0
- package/dist/marine/rtz.js.map +1 -0
- package/{test → dist/test}/asserter.d.ts +0 -0
- package/dist/test/asserter.js +45 -0
- package/dist/test/asserter.js.map +1 -0
- package/{test → dist/test}/db-testutils.d.ts +0 -0
- package/dist/test/db-testutils.js +31 -0
- package/dist/test/db-testutils.js.map +1 -0
- package/{test → dist/test}/httpserver.d.ts +2 -1
- package/dist/test/httpserver.js +74 -0
- package/dist/test/httpserver.js.map +1 -0
- package/{test → dist/test}/secret.d.ts +0 -0
- package/dist/test/secret.js +25 -0
- package/dist/test/secret.js.map +1 -0
- package/{test → dist/test}/secrets-manager.d.ts +0 -0
- package/dist/test/secrets-manager.js +59 -0
- package/dist/test/secrets-manager.js.map +1 -0
- package/{test → dist/test}/testutils.d.ts +0 -0
- package/dist/test/testutils.js +44 -0
- package/dist/test/testutils.js.map +1 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js +3 -0
- package/dist/types/either.js.map +1 -0
- package/{types → dist/types}/input-error.d.ts +0 -0
- package/dist/types/input-error.js +7 -0
- package/dist/types/input-error.js.map +1 -0
- package/{types → dist/types}/language.d.ts +0 -0
- package/dist/types/language.js +10 -0
- package/dist/types/language.js.map +1 -0
- package/{types → dist/types}/traffictype.d.ts +0 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/traffictype.js.map +1 -0
- package/{types → dist/types}/validator.d.ts +0 -0
- package/dist/types/validator.js +14 -0
- package/dist/types/validator.js.map +1 -0
- package/{utils → dist/utils}/api-model.d.ts +0 -0
- package/dist/utils/api-model.js +129 -0
- package/dist/utils/api-model.js.map +1 -0
- package/{utils → dist/utils}/base64.d.ts +0 -0
- package/dist/utils/base64.js +21 -0
- package/dist/utils/base64.js.map +1 -0
- package/{utils → dist/utils}/date-utils.d.ts +0 -0
- package/dist/utils/date-utils.js +34 -0
- package/dist/utils/date-utils.js.map +1 -0
- package/{utils → dist/utils}/geojson-types.d.ts +0 -0
- package/dist/utils/geojson-types.js +18 -0
- package/dist/utils/geojson-types.js.map +1 -0
- package/{utils → dist/utils}/geometry.d.ts +0 -0
- package/dist/utils/geometry.js +164 -0
- package/dist/utils/geometry.js.map +1 -0
- package/{utils → dist/utils}/retry.d.ts +0 -0
- package/dist/utils/retry.js +50 -0
- package/dist/utils/retry.js.map +1 -0
- package/{utils → dist/utils}/slack.d.ts +0 -0
- package/dist/utils/slack.js +25 -0
- package/dist/utils/slack.js.map +1 -0
- package/{utils → dist/utils}/utils.d.ts +16 -0
- package/dist/utils/utils.js +75 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +12 -10
- 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/src/aws/infra/canaries/canary-parameters.ts +19 -0
- 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/src/aws/types/mediatypes.ts +11 -0
- package/src/aws/types/model-with-reference.ts +8 -0
- 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/src/database/models.ts +7 -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/aws/infra/api/integration.js +0 -52
- package/aws/infra/api/response.js +0 -61
- package/aws/infra/api/responses.js +0 -79
- package/aws/infra/api/static-integration.js +0 -54
- package/aws/infra/canaries/canary-alarm.js +0 -26
- package/aws/infra/canaries/canary-parameters.js +0 -3
- package/aws/infra/canaries/canary-role.js +0 -46
- package/aws/infra/canaries/canary.js +0 -32
- package/aws/infra/canaries/database-canary.js +0 -55
- package/aws/infra/canaries/database-checker.js +0 -109
- package/aws/infra/canaries/url-canary.js +0 -46
- package/aws/infra/canaries/url-checker.js +0 -238
- package/aws/infra/documentation.js +0 -95
- package/aws/infra/scheduler.js +0 -31
- package/aws/infra/security-rule.js +0 -39
- package/aws/infra/sqs-integration.js +0 -93
- package/aws/infra/sqs-queue.js +0 -130
- package/aws/infra/stack/lambda-configs.js +0 -93
- package/aws/infra/stack/monitoredfunction.js +0 -135
- package/aws/infra/stack/rest_apis.js +0 -185
- package/aws/infra/stack/stack-checking-aspect.js +0 -174
- package/aws/infra/stack/stack.js +0 -60
- package/aws/infra/stack/subscription.js +0 -41
- package/aws/infra/usage-plans.js +0 -42
- package/aws/runtime/apikey.js +0 -13
- package/aws/runtime/digitraffic-integration-response.js +0 -26
- package/aws/runtime/environment.js +0 -12
- package/aws/runtime/messaging.js +0 -31
- package/aws/runtime/s3.js +0 -30
- package/aws/runtime/secrets/dbsecret.js +0 -96
- package/aws/runtime/secrets/proxy-holder.js +0 -26
- package/aws/runtime/secrets/rds-holder.js +0 -26
- package/aws/runtime/secrets/secret-holder.js +0 -73
- package/aws/runtime/secrets/secret.js +0 -43
- package/aws/types/errors.js +0 -9
- 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.js +0 -3
- package/aws/types/tags.js +0 -7
- package/database/cached.js +0 -32
- package/database/database.js +0 -62
- 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.js +0 -33
- package/marine/rtz.js +0 -3
- package/test/asserter.js +0 -45
- package/test/db-testutils.js +0 -31
- package/test/httpserver.js +0 -67
- package/test/secret.js +0 -25
- package/test/secrets-manager.js +0 -59
- package/test/testutils.js +0 -44
- package/types/input-error.js +0 -7
- package/types/language.js +0 -10
- package/types/traffictype.js +0 -13
- package/types/validator.js +0 -14
- package/utils/api-model.js +0 -129
- package/utils/base64.js +0 -21
- package/utils/date-utils.js +0 -34
- package/utils/geojson-types.js +0 -18
- package/utils/geometry.js +0 -140
- package/utils/retry.js +0 -50
- package/utils/slack.js +0 -25
- package/utils/utils.js +0 -64
@@ -0,0 +1,30 @@
|
|
1
|
+
export function isValidIMO(imo: number): boolean {
|
2
|
+
return imo >= 1000000 && imo <= 9999999 && imoChecksumIsValid(imo);
|
3
|
+
}
|
4
|
+
|
5
|
+
function imoChecksumIsValid(imo: number): boolean {
|
6
|
+
const imoStr = imo.toString();
|
7
|
+
const imoDigit1 = Number(imoStr[0]);
|
8
|
+
const imoDigit2 = Number(imoStr[1]);
|
9
|
+
const imoDigit3 = Number(imoStr[2]);
|
10
|
+
const imoDigit4 = Number(imoStr[3]);
|
11
|
+
const imoDigit5 = Number(imoStr[4]);
|
12
|
+
const imoDigit6 = Number(imoStr[5]);
|
13
|
+
const checkDigit = Number(imoStr[6]);
|
14
|
+
const checkCalculation = Number(((imoDigit1 * 7) + (imoDigit2 * 6) + (imoDigit3 * 5) + (imoDigit4 * 4) + (imoDigit5 * 3) + (imoDigit6 * 2)));
|
15
|
+
const checkResult = checkCalculation % 10 === checkDigit;
|
16
|
+
if (!checkResult) {
|
17
|
+
console.warn('method=imoChecksumIsValid IMO checksum failed %d', imo);
|
18
|
+
}
|
19
|
+
return checkResult;
|
20
|
+
}
|
21
|
+
|
22
|
+
export function isValidMMSI(mmsi: number): boolean {
|
23
|
+
return mmsi >= 100000000 && mmsi <= 999999999;
|
24
|
+
}
|
25
|
+
|
26
|
+
const LocodePattern = /^FI[A-Z]{3}$/i;
|
27
|
+
|
28
|
+
export function isValidLOCODE(locode: string): boolean {
|
29
|
+
return LocodePattern.test(locode);
|
30
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
export type RtzPositionCoordinate = {
|
2
|
+
readonly $: {
|
3
|
+
readonly lat: number
|
4
|
+
readonly lon: number
|
5
|
+
}
|
6
|
+
}
|
7
|
+
|
8
|
+
export type RtzWaypointPosition = {
|
9
|
+
readonly position: RtzPositionCoordinate[]
|
10
|
+
}
|
11
|
+
|
12
|
+
export type RtzWaypoint = {
|
13
|
+
readonly waypoint: RtzWaypointPosition[]
|
14
|
+
}
|
15
|
+
|
16
|
+
export type RtzScheduleElement = {
|
17
|
+
readonly $: {
|
18
|
+
/**
|
19
|
+
* Date
|
20
|
+
*/
|
21
|
+
readonly etd?: string
|
22
|
+
/**
|
23
|
+
* Date
|
24
|
+
*/
|
25
|
+
readonly eta?: string
|
26
|
+
},
|
27
|
+
}
|
28
|
+
|
29
|
+
export type RtzSchedule = {
|
30
|
+
readonly scheduleElement: RtzScheduleElement[]
|
31
|
+
}
|
32
|
+
|
33
|
+
export type RtzScheduleWrapper = {
|
34
|
+
readonly manual?: RtzSchedule[]
|
35
|
+
readonly calculated?: RtzSchedule[]
|
36
|
+
}
|
37
|
+
|
38
|
+
export type RtzSchedules = {
|
39
|
+
readonly schedule: RtzScheduleWrapper[]
|
40
|
+
}
|
41
|
+
|
42
|
+
export type RtzRouteInfo = {
|
43
|
+
readonly $: {
|
44
|
+
readonly vesselMMSI: string
|
45
|
+
readonly vesselIMO: string
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
export type RtzRoute = {
|
50
|
+
readonly routeInfo: RtzRouteInfo[]
|
51
|
+
readonly waypoints: RtzWaypoint[]
|
52
|
+
readonly schedules: RtzSchedules[]
|
53
|
+
}
|
54
|
+
|
55
|
+
export type RtzVoyagePlan = {
|
56
|
+
readonly route: RtzRoute
|
57
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/**
|
2
|
+
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
3
|
+
*/
|
4
|
+
|
5
|
+
export abstract class Asserter {
|
6
|
+
static assertEquals<T>(value: T, expected: T) {
|
7
|
+
if (value != expected) {
|
8
|
+
throw new Error(`Given value ${value} was not expected ${expected}`);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
static assertTrue<T>(value: T) {
|
13
|
+
if (!value) {
|
14
|
+
throw new Error(`Given value ${value} was not true`);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
static assertLength<T>(data: T[], expected: number) {
|
19
|
+
if (!data) {
|
20
|
+
throw new Error("Given array was not defined");
|
21
|
+
}
|
22
|
+
|
23
|
+
if (data.length != expected) {
|
24
|
+
throw new Error(`Given array length ${data.length} was not expected ${expected}`);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
static assertLengthGreaterThan<T>(data: T[], expected: number) {
|
29
|
+
if (!data) {
|
30
|
+
throw new Error("Given array was not defined");
|
31
|
+
}
|
32
|
+
|
33
|
+
if (data.length <= expected) {
|
34
|
+
throw new Error(`Given array length ${data.length} was not greater than ${expected}`);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
static assertGreaterThan(value: number, expected: number) {
|
39
|
+
if (value <= expected) {
|
40
|
+
throw new Error(`Value ${value} was expected to be greater than ${expected}`);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
static assertToBeCloseTo(value: number, expected: number, delta: number) {
|
45
|
+
expect(expected-value).toBeGreaterThanOrEqual(-1 * delta);
|
46
|
+
expect(expected-value).toBeLessThanOrEqual(delta);
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { DTDatabase, initDbConnection } from "../database/database";
|
2
|
+
import { DatabaseEnvironmentKeys } from "../aws/runtime/secrets/dbsecret";
|
3
|
+
|
4
|
+
export function dbTestBase(
|
5
|
+
fn: (db: DTDatabase) => void,
|
6
|
+
truncateFn: (db: DTDatabase) => Promise<void>,
|
7
|
+
dbUser: string,
|
8
|
+
dbPass: string,
|
9
|
+
dbUri: string
|
10
|
+
): () => void {
|
11
|
+
const theDbUri = process.env.DB_URI ?? dbUri;
|
12
|
+
console.log(`Test database URI: ${theDbUri}`);
|
13
|
+
|
14
|
+
return () => {
|
15
|
+
const db: DTDatabase = initDbConnection(
|
16
|
+
dbUser,
|
17
|
+
dbPass,
|
18
|
+
"test",
|
19
|
+
theDbUri,
|
20
|
+
{
|
21
|
+
noWarnings: true, // ignore duplicate connection warning for tests
|
22
|
+
}
|
23
|
+
);
|
24
|
+
|
25
|
+
beforeAll(async () => {
|
26
|
+
process.env[DatabaseEnvironmentKeys.DB_USER] = dbUser;
|
27
|
+
process.env[DatabaseEnvironmentKeys.DB_PASS] = dbPass;
|
28
|
+
process.env[DatabaseEnvironmentKeys.DB_URI] = theDbUri;
|
29
|
+
process.env[DatabaseEnvironmentKeys.DB_RO_URI] = theDbUri;
|
30
|
+
await truncateFn(db);
|
31
|
+
});
|
32
|
+
|
33
|
+
afterAll(async () => {
|
34
|
+
await truncateFn(db);
|
35
|
+
await db.$pool.end();
|
36
|
+
});
|
37
|
+
|
38
|
+
beforeEach(async () => {
|
39
|
+
await truncateFn(db);
|
40
|
+
});
|
41
|
+
|
42
|
+
fn(db);
|
43
|
+
};
|
44
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import { Server, createServer } from "http";
|
2
|
+
|
3
|
+
export const ERROR_NO_MATCH = "NO MATCH";
|
4
|
+
export const ERRORCODE_NOT_FOUND = 404;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* A mock HTTP server created for testing connections from a Lambda to an outside integration
|
8
|
+
*/
|
9
|
+
export class TestHttpServer {
|
10
|
+
private server?: Server;
|
11
|
+
private debug: boolean;
|
12
|
+
|
13
|
+
private messageStack: string[];
|
14
|
+
|
15
|
+
constructor() {
|
16
|
+
this.debug = false;
|
17
|
+
this.messageStack = [];
|
18
|
+
}
|
19
|
+
|
20
|
+
getCallCount(): number {
|
21
|
+
return this.messageStack.length;
|
22
|
+
}
|
23
|
+
|
24
|
+
getRequestBody(callNumber: number): string {
|
25
|
+
return this.messageStack[callNumber];
|
26
|
+
}
|
27
|
+
|
28
|
+
listen(
|
29
|
+
port: number,
|
30
|
+
props: ListenProperties,
|
31
|
+
debug = false,
|
32
|
+
statusCode = 200
|
33
|
+
) {
|
34
|
+
this.debug = debug;
|
35
|
+
this.messageStack = [];
|
36
|
+
this.debuglog(`Starting test server on port ${port}`);
|
37
|
+
this.server = createServer((req, res) => {
|
38
|
+
this.debuglog("Mapped urls: ");
|
39
|
+
|
40
|
+
Object.keys(props).forEach((k) => this.debuglog(k));
|
41
|
+
this.debuglog("Received request to url " + req.url + "..");
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
43
|
+
const path = require("url").parse(req.url).pathname;
|
44
|
+
|
45
|
+
let dataStr = "";
|
46
|
+
req.on("data", (chunk) => {
|
47
|
+
if (chunk) {
|
48
|
+
dataStr += chunk;
|
49
|
+
}
|
50
|
+
});
|
51
|
+
|
52
|
+
if (path in props) {
|
53
|
+
this.debuglog("..url matched");
|
54
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
55
|
+
res.setHeader(
|
56
|
+
"Access-Control-Allow-Headers",
|
57
|
+
"Authorization,X-User-Id,X-Auth-Token"
|
58
|
+
);
|
59
|
+
res.writeHead(statusCode);
|
60
|
+
|
61
|
+
req.on("end", () => {
|
62
|
+
// assume sent data is in JSON format
|
63
|
+
this.messageStack[this.messageStack.length] = dataStr;
|
64
|
+
res.end(props[path](req.url, dataStr));
|
65
|
+
});
|
66
|
+
} else {
|
67
|
+
this.debuglog("..no match for %" + path);
|
68
|
+
req.on("end", () => {
|
69
|
+
// assume sent data is in JSON format
|
70
|
+
this.messageStack[this.messageStack.length] =
|
71
|
+
ERROR_NO_MATCH;
|
72
|
+
res.writeHead(ERRORCODE_NOT_FOUND);
|
73
|
+
res.end(ERROR_NO_MATCH);
|
74
|
+
});
|
75
|
+
}
|
76
|
+
});
|
77
|
+
this.server.listen(port);
|
78
|
+
}
|
79
|
+
|
80
|
+
close() {
|
81
|
+
this.debuglog("Closing test server");
|
82
|
+
if (this.server !== undefined) {
|
83
|
+
this.server.close();
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
private debuglog(str: string) {
|
88
|
+
if (this.debug) {
|
89
|
+
console.debug(str);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
export interface ListenProperties {
|
95
|
+
[key: string]: (url?: string, data?: string) => string;
|
96
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import {DbSecret, EmptySecretFunction, SecretFunction, SecretToPromiseFunction} from "../aws/runtime/secrets/dbsecret";
|
2
|
+
|
3
|
+
const EMPTY_DB_SECRET: DbSecret = {
|
4
|
+
username: '',
|
5
|
+
password: '',
|
6
|
+
host: '',
|
7
|
+
// eslint-disable-next-line camelcase
|
8
|
+
ro_host: '',
|
9
|
+
};
|
10
|
+
|
11
|
+
export function createSecretFunction<Secret, Response>(secret: Secret): SecretFunction<Secret, Response> {
|
12
|
+
// eslint-disable-next-line require-await
|
13
|
+
return async (secretId: string, fn: SecretToPromiseFunction<Secret, Response>) => {
|
14
|
+
return fn(secret);
|
15
|
+
};
|
16
|
+
}
|
17
|
+
|
18
|
+
export function createEmptySecretFunction<Response>(): EmptySecretFunction<Response> {
|
19
|
+
// eslint-disable-next-line require-await
|
20
|
+
return async (secretId: string, fn: SecretToPromiseFunction<DbSecret, Response>) => {
|
21
|
+
return fn(EMPTY_DB_SECRET);
|
22
|
+
};
|
23
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import AWS = require('aws-sdk');
|
2
|
+
import * as sinon from "sinon";
|
3
|
+
|
4
|
+
const secretValue = sinon.stub();
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Stub Secrets Manager for tests. You must call this
|
8
|
+
* before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
|
9
|
+
*
|
10
|
+
* To mock the actual secret, call mockSecret()
|
11
|
+
*/
|
12
|
+
export function stubSecretsManager() {
|
13
|
+
const smStub = {
|
14
|
+
getSecretValue: secretValue,
|
15
|
+
};
|
16
|
+
|
17
|
+
sinon.stub(AWS, 'SecretsManager').returns(smStub);
|
18
|
+
|
19
|
+
return smStub.getSecretValue;
|
20
|
+
}
|
21
|
+
|
22
|
+
export function mockSecret<Secret>(secret: Secret) {
|
23
|
+
if (!secret) {
|
24
|
+
secretValue.returns({
|
25
|
+
promise: sinon.stub().returns({}),
|
26
|
+
});
|
27
|
+
} else {
|
28
|
+
secretValue.returns({
|
29
|
+
promise: sinon.stub().returns({
|
30
|
+
SecretString: JSON.stringify(secret),
|
31
|
+
}),
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
export function randomString() : string {
|
2
|
+
return Math.random().toString(36).substring(2);
|
3
|
+
}
|
4
|
+
|
5
|
+
export function getRandomNumber(min: number , max: number) : number {
|
6
|
+
return Math.random() * (max - min) + min;
|
7
|
+
}
|
8
|
+
|
9
|
+
export function getRandomNumberAsString(min: number , max: number) : string {
|
10
|
+
return getRandomNumber(min, max).toString();
|
11
|
+
}
|
12
|
+
|
13
|
+
export function getRandomInteger(min: number , max: number) : number {
|
14
|
+
return Math.round(getRandomNumber(min, max));
|
15
|
+
}
|
16
|
+
|
17
|
+
export function getRandomIntegerAsString(min: number , max: number) : string {
|
18
|
+
return Math.round(getRandomInteger(min, max)).toString();
|
19
|
+
}
|
20
|
+
|
21
|
+
export function getRandomBigInt(min: number , max: number) : bigint {
|
22
|
+
return BigInt(getRandomInteger(min, max));
|
23
|
+
}
|
24
|
+
|
25
|
+
export function randomBoolean(): boolean {
|
26
|
+
return Math.random() < 0.5;
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Returns a new copy of an array, shuffled using Math.random()
|
31
|
+
* @param array Array
|
32
|
+
*/
|
33
|
+
export function shuffle<T>(array: T[]): T[] {
|
34
|
+
// pretty fast way to copy an array, not necessarily the fastest
|
35
|
+
const newArray = array.slice(0);
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
37
|
+
newArray.sort((x) => 0.5 - Math.random());
|
38
|
+
return newArray;
|
39
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export const MIN_YEAR = 1900;
|
2
|
+
export const MAX_YEAR = 2100;
|
3
|
+
|
4
|
+
export function validateYear(year: number, minYear = MIN_YEAR, maxYear = MAX_YEAR) {
|
5
|
+
return year >= minYear && year <= maxYear;
|
6
|
+
}
|
7
|
+
|
8
|
+
export function validateMonth(month: number) {
|
9
|
+
return month > 0 && month < 13;
|
10
|
+
}
|
@@ -0,0 +1,133 @@
|
|
1
|
+
import {
|
2
|
+
RestApi,
|
3
|
+
Model,
|
4
|
+
JsonSchema,
|
5
|
+
RequestValidator,
|
6
|
+
JsonSchemaType,
|
7
|
+
JsonSchemaVersion,
|
8
|
+
} from 'aws-cdk-lib/aws-apigateway';
|
9
|
+
import {ModelWithReference} from "../aws/types/model-with-reference";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Get a reference to an OpenAPI model object in a REST API.
|
13
|
+
* Can be used to supply a reference to properties of a GeoJSON feature.
|
14
|
+
* @param modelId Id of the referenced object
|
15
|
+
* @param restApiId Id of the REST API
|
16
|
+
*/
|
17
|
+
export function getModelReference(modelId: string, restApiId: string) {
|
18
|
+
return `https://apigateway.amazonaws.com/restapis/${restApiId}/models/${modelId}`;
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Adds a request validator to a REST API to enforce request parameters/body requirements.
|
23
|
+
* https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html
|
24
|
+
* @param api REST API
|
25
|
+
*/
|
26
|
+
export function addDefaultValidator(api: RestApi): RequestValidator {
|
27
|
+
return api.addRequestValidator('DefaultValidator', {
|
28
|
+
validateRequestParameters: true,
|
29
|
+
validateRequestBody: true,
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
|
35
|
+
* This method adds a schema for _a single object._
|
36
|
+
* @param name Name of the model
|
37
|
+
* @param api REST API
|
38
|
+
* @param schema JSON Schema
|
39
|
+
* @return ModelWithReference A model object with a reference to an API Gateway model object.
|
40
|
+
*/
|
41
|
+
export function addServiceModel(modelName: string, api: RestApi, schema: JsonSchema): ModelWithReference {
|
42
|
+
const mwr = api.addModel(modelName, {
|
43
|
+
contentType: 'application/json',
|
44
|
+
modelName,
|
45
|
+
schema,
|
46
|
+
}) as ModelWithReference;
|
47
|
+
mwr.modelReference = getModelReference(mwr.modelId, api.restApiId);
|
48
|
+
return mwr;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Add an empty JSON schema model to an API Gateway API.
|
53
|
+
* Usable for example if the incoming data is in XML format but some template transformation is necessary.
|
54
|
+
* @param modelName
|
55
|
+
* @param api
|
56
|
+
* @param contentType
|
57
|
+
*/
|
58
|
+
export function addSimpleServiceModel(modelName: string, api: RestApi, contentType = 'application/xml'): Model {
|
59
|
+
return api.addModel(modelName, {
|
60
|
+
contentType,
|
61
|
+
modelName,
|
62
|
+
schema: {},
|
63
|
+
});
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
|
68
|
+
* This method adds a schema for _an array._
|
69
|
+
* @param model
|
70
|
+
* @param api
|
71
|
+
*/
|
72
|
+
export function createArraySchema(model: Model, api: RestApi): JsonSchema {
|
73
|
+
return {
|
74
|
+
type: JsonSchemaType.ARRAY,
|
75
|
+
items: {
|
76
|
+
ref: getModelReference(model.modelId, api.restApiId),
|
77
|
+
},
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Creates a JSON Schema for a GeoJSON Feature. Can be used to generate OpenAPI descriptions.
|
83
|
+
* @param modelReference Reference to a model object
|
84
|
+
*/
|
85
|
+
export function featureSchema(modelReference: string) {
|
86
|
+
return {
|
87
|
+
schema: JsonSchemaVersion.DRAFT4,
|
88
|
+
type: JsonSchemaType.OBJECT,
|
89
|
+
description: 'GeoJson Feature',
|
90
|
+
required: ['type', 'properties', 'geometry'],
|
91
|
+
properties: {
|
92
|
+
type: {
|
93
|
+
type: JsonSchemaType.STRING,
|
94
|
+
description: 'Feature',
|
95
|
+
enum: ['Feature'],
|
96
|
+
},
|
97
|
+
properties: {
|
98
|
+
ref: modelReference,
|
99
|
+
},
|
100
|
+
geometry: {
|
101
|
+
type: JsonSchemaType.OBJECT,
|
102
|
+
description: 'GeoJSON geometry',
|
103
|
+
},
|
104
|
+
},
|
105
|
+
};
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
*
|
110
|
+
* Creates a JSON Schema for a GeoJSON Feature Collection. Can be used to generate OpenAPI descriptions.
|
111
|
+
* @param modelReference Reference to a model object, in this case Features.
|
112
|
+
*/
|
113
|
+
export function geojsonSchema(modelReference: string) {
|
114
|
+
return {
|
115
|
+
schema: JsonSchemaVersion.DRAFT4,
|
116
|
+
type: JsonSchemaType.OBJECT,
|
117
|
+
description: 'GeoJson FeatureCollection',
|
118
|
+
required: ['type', 'features'],
|
119
|
+
properties: {
|
120
|
+
type: {
|
121
|
+
type: JsonSchemaType.STRING,
|
122
|
+
description: 'FeatureCollection',
|
123
|
+
enum: ['FeatureCollection'],
|
124
|
+
},
|
125
|
+
features: {
|
126
|
+
type: JsonSchemaType.ARRAY,
|
127
|
+
items: {
|
128
|
+
ref: modelReference,
|
129
|
+
},
|
130
|
+
},
|
131
|
+
},
|
132
|
+
};
|
133
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* Decode given string from base64 to ascii
|
3
|
+
* @param str string
|
4
|
+
*/
|
5
|
+
export function decodeBase64ToAscii(str: string) {
|
6
|
+
return decodeBase64(str, 'ascii');
|
7
|
+
}
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Decode given string from base64 to given encoding
|
11
|
+
* @param str
|
12
|
+
* @param encoding
|
13
|
+
*/
|
14
|
+
export function decodeBase64(str: string, encoding: BufferEncoding) {
|
15
|
+
return Buffer.from(str, 'base64').toString(encoding);
|
16
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Counts difference in milliseconds between dates.
|
4
|
+
* @param start
|
5
|
+
* @param end
|
6
|
+
*/
|
7
|
+
export function countDiffMs(start: Date, end: Date): number {
|
8
|
+
return end.getTime() - start.getTime();
|
9
|
+
}
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Counts difference in seconds between dates.
|
13
|
+
* @param start
|
14
|
+
* @param end
|
15
|
+
*/
|
16
|
+
export function countDiffInSeconds(start: Date, end: Date): number {
|
17
|
+
return countDiffMs(start, end)/1000;
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Converts ISO 8601 date-time -string to Date object
|
22
|
+
* @param isoString to convert
|
23
|
+
*/
|
24
|
+
export function dateFromIsoString(isoString: string): Date {
|
25
|
+
const parsed = new Date(isoString);
|
26
|
+
if (!(parsed instanceof Date) || isNaN(parsed.getTime())) {
|
27
|
+
throw new Error(`Invalid ISO-DATE -string: ${isoString}`);
|
28
|
+
}
|
29
|
+
return parsed;
|
30
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* GeoJSON types
|
3
|
+
*/
|
4
|
+
import {LineString, Point, Position} from "geojson";
|
5
|
+
|
6
|
+
export class GeoJsonPoint implements Point {
|
7
|
+
readonly type = "Point";
|
8
|
+
readonly coordinates: Position;
|
9
|
+
|
10
|
+
constructor(coordinates: Position) {
|
11
|
+
this.coordinates = coordinates;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
export class GeoJsonLineString implements LineString {
|
16
|
+
readonly type = "LineString";
|
17
|
+
readonly coordinates: Position[];
|
18
|
+
|
19
|
+
constructor(coordinates: Position[]) {
|
20
|
+
this.coordinates = coordinates;
|
21
|
+
}
|
22
|
+
}
|