@digitraffic/common 2022.11.22-1 → 2022.11.23-test
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/dist/aws/infra/api/integration.d.ts +21 -0
- package/dist/aws/infra/api/response.d.ts +22 -0
- package/dist/aws/infra/api/responses.d.ts +39 -0
- package/dist/aws/infra/api/static-integration.d.ts +15 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/import-util.d.ts +21 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/sqs-integration.d.ts +7 -0
- package/dist/aws/infra/sqs-queue.d.ts +16 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +64 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
- package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
- package/dist/aws/infra/stack/stack.d.ts +45 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +11 -0
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +19 -0
- package/dist/aws/infra/stacks/db-stack.d.ts +31 -0
- package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
- package/dist/aws/infra/stacks/network-stack.d.ts +12 -0
- package/dist/aws/infra/usage-plans.d.ts +16 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/environment.d.ts +1 -0
- package/dist/aws/runtime/messaging.d.ts +10 -0
- package/dist/aws/runtime/s3.d.ts +2 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +55 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +27 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/lambda-response.d.ts +13 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/proxytypes.d.ts +26 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/database/cached.d.ts +7 -0
- package/dist/database/database.d.ts +19 -0
- package/dist/database/last-updated.d.ts +16 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/test/asserter.d.ts +11 -0
- package/dist/test/db-testutils.d.ts +3 -0
- package/dist/test/httpserver.d.ts +19 -0
- package/dist/test/secret.d.ts +3 -0
- package/dist/test/secrets-manager.d.ts +9 -0
- package/dist/test/testutils.d.ts +12 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/traffictype.d.ts +8 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/utils/api-model.d.ts +87 -0
- package/dist/utils/base64.d.ts +12 -0
- package/dist/utils/date-utils.d.ts +17 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geometry.d.ts +36 -0
- package/dist/utils/retry.d.ts +13 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/utils.d.ts +46 -0
- package/package.json +2 -1
@@ -0,0 +1,45 @@
|
|
1
|
+
import { Stack, StackProps } from "aws-cdk-lib";
|
2
|
+
import { IVpc } from "aws-cdk-lib/aws-ec2";
|
3
|
+
import { ISecurityGroup } from "aws-cdk-lib/aws-ec2/lib/security-group";
|
4
|
+
import { ITopic } from "aws-cdk-lib/aws-sns";
|
5
|
+
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
6
|
+
import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
|
7
|
+
import { Construct } from "constructs";
|
8
|
+
import { TrafficType } from "../../../types/traffictype";
|
9
|
+
import { DBLambdaEnvironment } from "./lambda-configs";
|
10
|
+
export declare const SOLUTION_KEY = "Solution";
|
11
|
+
export declare const SSM_KEY_WARNING_TOPIC: string;
|
12
|
+
export declare const SSM_KEY_ALARM_TOPIC: string;
|
13
|
+
export interface StackConfiguration {
|
14
|
+
readonly shortName: string;
|
15
|
+
readonly secretId?: string;
|
16
|
+
readonly alarmTopicArn: string;
|
17
|
+
readonly warningTopicArn: string;
|
18
|
+
readonly logsDestinationArn?: string;
|
19
|
+
readonly vpcId?: string;
|
20
|
+
readonly lambdaDbSgId?: string;
|
21
|
+
readonly privateSubnetIds?: string[];
|
22
|
+
readonly availabilityZones?: string[];
|
23
|
+
readonly trafficType: TrafficType;
|
24
|
+
readonly production: boolean;
|
25
|
+
readonly stackProps: StackProps;
|
26
|
+
readonly stackFeatures?: {
|
27
|
+
readonly enableCanaries?: boolean;
|
28
|
+
readonly enableDocumentation?: boolean;
|
29
|
+
};
|
30
|
+
readonly whitelistedResources?: string[];
|
31
|
+
}
|
32
|
+
export declare class DigitrafficStack extends Stack {
|
33
|
+
readonly vpc?: IVpc;
|
34
|
+
readonly lambdaDbSg?: ISecurityGroup;
|
35
|
+
readonly alarmTopic: ITopic;
|
36
|
+
readonly warningTopic: ITopic;
|
37
|
+
readonly secret?: ISecret;
|
38
|
+
readonly configuration: StackConfiguration;
|
39
|
+
constructor(scope: Construct, id: string, configuration: StackConfiguration);
|
40
|
+
addAspects(): void;
|
41
|
+
createLambdaEnvironment(): DBLambdaEnvironment;
|
42
|
+
createDefaultLambdaEnvironment(dbApplication: string): DBLambdaEnvironment;
|
43
|
+
getSecret(): ISecret;
|
44
|
+
grantSecret(...lambdas: AWSFunction[]): void;
|
45
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { CfnSubscriptionFilter } from "aws-cdk-lib/aws-logs";
|
2
|
+
import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
|
3
|
+
import { DigitrafficStack } from "./stack";
|
4
|
+
import { Construct } from "constructs";
|
5
|
+
import { MonitoredFunction } from "./monitoredfunction";
|
6
|
+
/**
|
7
|
+
* Creates a subscription filter that subscribes to a Lambda Log Group and delivers the logs to another destination.
|
8
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html
|
9
|
+
* @param lambda The Lambda function, needed to create a dependency
|
10
|
+
* @param lambdaName The Lambda name from which the Log Group name is derived
|
11
|
+
* @param logDestinationArn Destination for streamed logs
|
12
|
+
* @param stack CloudFormation stack
|
13
|
+
*/
|
14
|
+
export declare function createSubscription(lambda: AWSFunction, lambdaName: string, logDestinationArn: string | undefined, stack: Construct): CfnSubscriptionFilter | undefined;
|
15
|
+
export declare class DigitrafficLogSubscriptions {
|
16
|
+
constructor(stack: DigitrafficStack, ...lambdas: MonitoredFunction[]);
|
17
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
2
|
+
import { Construct } from "constructs";
|
3
|
+
import { InfraStackConfiguration } from "./intra-stack-configuration";
|
4
|
+
/**
|
5
|
+
* Creates a dns local zone and creates records for cluster endpoints and proxy endpoints.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
export declare class DbDnsStack extends Stack {
|
9
|
+
constructor(scope: Construct, id: string, isc: InfraStackConfiguration);
|
10
|
+
createDnsRecords(isc: InfraStackConfiguration): void;
|
11
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
2
|
+
import { Construct } from "constructs";
|
3
|
+
import { CfnDBProxyEndpoint, DatabaseProxy } from "aws-cdk-lib/aws-rds";
|
4
|
+
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
5
|
+
import { IVpc } from "aws-cdk-lib/aws-ec2";
|
6
|
+
import { InfraStackConfiguration } from "./intra-stack-configuration";
|
7
|
+
import { DbConfiguration } from "./db-stack";
|
8
|
+
/**
|
9
|
+
* A stack that creates a Database proxy.
|
10
|
+
*/
|
11
|
+
export declare class DbProxyStack extends Stack {
|
12
|
+
static PROXY_READER_EXPORT_NAME: string;
|
13
|
+
static PROXY_WRITER_EXPORT_NAME: string;
|
14
|
+
readonly isc: InfraStackConfiguration;
|
15
|
+
constructor(scope: Construct, id: string, isc: InfraStackConfiguration, configuration: DbConfiguration);
|
16
|
+
createProxy(vpc: IVpc, secret: ISecret, configuration: DbConfiguration): DatabaseProxy;
|
17
|
+
createProxyEndpoints(vpc: IVpc, proxy: DatabaseProxy, securityGroupId: string): CfnDBProxyEndpoint;
|
18
|
+
setOutputs(configuration: DbConfiguration, proxy: DatabaseProxy, proxyEndpoint: CfnDBProxyEndpoint): void;
|
19
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
2
|
+
import { Construct } from "constructs";
|
3
|
+
import { AuroraPostgresEngineVersion, DatabaseCluster } from "aws-cdk-lib/aws-rds";
|
4
|
+
import { InstanceType } from "aws-cdk-lib/aws-ec2";
|
5
|
+
import { InfraStackConfiguration } from "./intra-stack-configuration";
|
6
|
+
export interface DbConfiguration {
|
7
|
+
readonly secretArn: string;
|
8
|
+
readonly dbVersion: AuroraPostgresEngineVersion;
|
9
|
+
readonly dbInstanceType: InstanceType;
|
10
|
+
readonly snapshotIdentifier: string;
|
11
|
+
readonly instances: number;
|
12
|
+
readonly customParameterGroup: boolean;
|
13
|
+
readonly securityGroupId: string;
|
14
|
+
readonly dbProxyName?: string;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* How to upgrade major version?
|
18
|
+
* 0. Set correct SG for db-stack and db-proxy-stack(this step will be removed in the future)
|
19
|
+
* 1. Update db-stack WITHOUT parameter group
|
20
|
+
* 2. Upgrade extensions by hand
|
21
|
+
* 3. Upgrade database from the AWS console
|
22
|
+
* 4. Update db-stack with the upgraded version and custom parameter group
|
23
|
+
*/
|
24
|
+
export declare class DbStack extends Stack {
|
25
|
+
static CLUSTER_IDENTIFIER_EXPORT_NAME: string;
|
26
|
+
static CLUSTER_READ_ENDPOINT_EXPORT_NAME: string;
|
27
|
+
static CLUSTER_WRITE_ENDPOINT_EXPORT_NAME: string;
|
28
|
+
static CLUSTER_PORT: number;
|
29
|
+
constructor(scope: Construct, id: string, isc: InfraStackConfiguration, configuration: DbConfiguration);
|
30
|
+
createAuroraCluster(isc: InfraStackConfiguration, configuration: DbConfiguration): DatabaseCluster;
|
31
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Stack } from "aws-cdk-lib";
|
2
|
+
import { Construct } from "constructs";
|
3
|
+
import { Vpc } from "aws-cdk-lib/aws-ec2";
|
4
|
+
import { InfraStackConfiguration } from "./intra-stack-configuration";
|
5
|
+
export interface NetworkConfiguration {
|
6
|
+
readonly vpcName: string;
|
7
|
+
readonly cidr: string;
|
8
|
+
}
|
9
|
+
export declare class NetworkStack extends Stack {
|
10
|
+
constructor(scope: Construct, id: string, isc: InfraStackConfiguration, configuration: NetworkConfiguration);
|
11
|
+
createVpc(configuration: NetworkConfiguration): Vpc;
|
12
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { IApiKey, RestApi } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
/**
|
3
|
+
* Creates an usage plan for a REST API with a single API key
|
4
|
+
* @param api The REST API
|
5
|
+
* @param apiKeyId Id for the API key, this is a surrogate id for CDK, not displayed anywhere
|
6
|
+
* @param apiKeyName Name for the API key, this is displayed in the AWS Console
|
7
|
+
* @deprecated Creates randomized API key names, use createDefaultUsagePlan instead
|
8
|
+
*/
|
9
|
+
export declare function createUsagePlan(api: RestApi, apiKeyId: string, apiKeyName: string): IApiKey;
|
10
|
+
/**
|
11
|
+
* Creates a default usage plan for a REST API with a single API key
|
12
|
+
* @param api The REST API
|
13
|
+
* @param apiName Name of the api. Will generate key: apiName + ' API Key' and plan: apiName + ' API Usage Plan'
|
14
|
+
* @param value Optional value for the API key
|
15
|
+
*/
|
16
|
+
export declare function createDefaultUsagePlan(api: RestApi, apiName: string, value?: string): IApiKey;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { IntegrationResponse } from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import { MediaType } from "../types/mediatypes";
|
3
|
+
export declare abstract class DigitrafficIntegrationResponse {
|
4
|
+
static ok(mediaType: MediaType): IntegrationResponse;
|
5
|
+
static badRequest(mediaType?: MediaType): IntegrationResponse;
|
6
|
+
static notImplemented(mediaType?: MediaType): IntegrationResponse;
|
7
|
+
static create(statusCode: string, mediaType: MediaType): IntegrationResponse;
|
8
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function envValue(key: string, defaultValue?: string): string;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { SNS } from "aws-sdk";
|
2
|
+
/**
|
3
|
+
* Utility function for publishing SNS messages.
|
4
|
+
* Made because using *await* with AWS APIs doesn't require calling promise() but nothing works if it isn't called.
|
5
|
+
* Retries a single time in case of failure.
|
6
|
+
* @param message
|
7
|
+
* @param topicArn
|
8
|
+
* @param sns
|
9
|
+
*/
|
10
|
+
export declare function snsPublish(message: string, topicArn: string, sns: SNS): Promise<void>;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { GenericSecret } from "./secret";
|
2
|
+
export type DbSecret = {
|
3
|
+
readonly username: string;
|
4
|
+
readonly password: string;
|
5
|
+
readonly host: string;
|
6
|
+
readonly ro_host: string;
|
7
|
+
};
|
8
|
+
export declare enum RdsProxySecretKey {
|
9
|
+
username = "username",
|
10
|
+
password = "password",
|
11
|
+
proxy_host = "proxy_host",
|
12
|
+
proxy_ro_host = "proxy_ro_host"
|
13
|
+
}
|
14
|
+
export declare enum RdsSecretKey {
|
15
|
+
username = "username",
|
16
|
+
password = "password",
|
17
|
+
host = "host",
|
18
|
+
ro_host = "ro_host"
|
19
|
+
}
|
20
|
+
export type RdsProxySecret = Record<RdsProxySecretKey, string>;
|
21
|
+
export type RdsSecret = Record<RdsSecretKey, string>;
|
22
|
+
export declare enum DatabaseEnvironmentKeys {
|
23
|
+
DB_USER = "DB_USER",
|
24
|
+
DB_PASS = "DB_PASS",
|
25
|
+
DB_URI = "DB_URI",
|
26
|
+
DB_RO_URI = "DB_RO_URI",
|
27
|
+
DB_APPLICATION = "DB_APPLICATION"
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* You can give the following options for retrieving a secret:
|
31
|
+
*
|
32
|
+
* expectedKeys: the list of keys the secret must include. If not, an error will be thrown.
|
33
|
+
* prefix: a prefix that's included in retrieved secret's keys. Only keys begining with the prefix will be included.
|
34
|
+
* The secret that is passed to the given function will not include the prefix in it's keys.
|
35
|
+
|
36
|
+
*/
|
37
|
+
export type SecretOptions = {
|
38
|
+
readonly expectedKeys?: string[];
|
39
|
+
readonly prefix?: string;
|
40
|
+
};
|
41
|
+
export type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
|
42
|
+
export type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
|
43
|
+
export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
|
44
|
+
/**
|
45
|
+
* Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
|
46
|
+
*
|
47
|
+
* @deprecated use SecretHolder & ProxyHolder
|
48
|
+
* @see SecretOptions
|
49
|
+
*
|
50
|
+
* @param {string} secretId
|
51
|
+
* @param {function} fn
|
52
|
+
* @param {SecretOptions} options
|
53
|
+
*/
|
54
|
+
export declare function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void>;
|
55
|
+
export declare function checkExpectedSecretKeys<Secret extends GenericSecret>(keys: string[], secret: Secret): void;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { GenericSecret } from "./secret";
|
2
|
+
/**
|
3
|
+
* Utility class for getting secrets from Secret Manager.
|
4
|
+
* Supports prefix for secrets, checking of expected keys and ttl-configuration.
|
5
|
+
*
|
6
|
+
* By default, secrets are cached for 5 minutes and then reread from the Secrets Manager(This can be overridden with configuration).
|
7
|
+
*
|
8
|
+
* Supports setting the database environment paramaters from the secret too.
|
9
|
+
*/
|
10
|
+
export declare class SecretHolder<Secret extends GenericSecret> {
|
11
|
+
private readonly secretId;
|
12
|
+
private readonly prefix;
|
13
|
+
private readonly expectedKeys;
|
14
|
+
private readonly secretCache;
|
15
|
+
constructor(secretId: string, prefix?: string, expectedKeys?: string[], configuration?: {
|
16
|
+
ttl: number;
|
17
|
+
});
|
18
|
+
private initSecret;
|
19
|
+
static create<S extends GenericSecret>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
|
20
|
+
get(): Promise<Secret>;
|
21
|
+
private parseSecret;
|
22
|
+
private getSecret;
|
23
|
+
/**
|
24
|
+
* @deprecated Use ProxyHolder
|
25
|
+
*/
|
26
|
+
setDatabaseCredentials(): Promise<void>;
|
27
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { SecretToPromiseFunction } from "./dbsecret";
|
2
|
+
export type GenericSecret = Record<string, string>;
|
3
|
+
/**
|
4
|
+
@deprecated use SecretHolder & ProxyHolder
|
5
|
+
*/
|
6
|
+
export declare function withSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>): Promise<Response | void>;
|
7
|
+
export declare function getSecret<Secret>(secretId: string, prefix?: string): Promise<Secret>;
|
8
|
+
export declare function withSecretAndPrefix<Secret, Response>(secretId: string, prefix: string, fn: SecretToPromiseFunction<Secret, Response>): Promise<Response | void>;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare const NOT_FOUND_MESSAGE = "NOT_FOUND";
|
2
|
+
export declare const ERROR_MESSAGE = "ERROR";
|
3
|
+
export declare const OK_MESSAGE = "OK";
|
4
|
+
export declare const BAD_REQUEST_MESSAGE = "BAD REQUEST";
|
5
|
+
export declare class ValidationError extends Error {
|
6
|
+
statusCode: number;
|
7
|
+
constructor(statusCode: number, body: string);
|
8
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export declare class LambdaResponse<T> {
|
2
|
+
readonly status: number;
|
3
|
+
readonly body: T;
|
4
|
+
readonly fileName?: string;
|
5
|
+
constructor(status: number, body: T, fileName?: string);
|
6
|
+
static ok<T>(body: T, fileName?: string): Promise<LambdaResponse<T>>;
|
7
|
+
static okJson<T>(json: T, fileName?: string): Promise<LambdaResponse<string>>;
|
8
|
+
static badRequest(body: string): Promise<LambdaResponse<string>>;
|
9
|
+
static notFound(): Promise<LambdaResponse<string>>;
|
10
|
+
static internalError(): Promise<LambdaResponse<string>>;
|
11
|
+
static notImplemented(): Promise<LambdaResponse<string>>;
|
12
|
+
static create<T>(status: number, body: T, fileName?: string): Promise<LambdaResponse<T>>;
|
13
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare enum MediaType {
|
2
|
+
APPLICATION_JSON = "application/json",
|
3
|
+
APPLICATION_XML = "application/xml",
|
4
|
+
APPLICATION_GEOJSON = "application/geo+json;charset=UTF-8",
|
5
|
+
IMAGE_SVG = "image/svg+xml",
|
6
|
+
IMAGE_JPEG = "image/jpeg",
|
7
|
+
TEXT_PLAIN = "text/plain",
|
8
|
+
TEXT_HTML = "text/html",
|
9
|
+
TEXT_CSV = "text/csv",
|
10
|
+
APPLICATION_JSON_UTF8 = "application/json;charset=UTF-8"
|
11
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
|
3
|
+
*
|
4
|
+
* Not fully described, extend if necessary.
|
5
|
+
*/
|
6
|
+
export type ProxyLambdaResponse = {
|
7
|
+
readonly statusCode: number;
|
8
|
+
readonly body: string;
|
9
|
+
readonly headers?: Record<string, string>;
|
10
|
+
readonly multiValueHeaders?: Record<string, string[]>;
|
11
|
+
};
|
12
|
+
/**
|
13
|
+
* https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
|
14
|
+
*
|
15
|
+
* Not fully described, extend if necessary.
|
16
|
+
*/
|
17
|
+
export type ProxyLambdaRequest = {
|
18
|
+
readonly resource: string;
|
19
|
+
readonly path: string;
|
20
|
+
readonly httpMethod: string;
|
21
|
+
readonly headers: Record<string, string>;
|
22
|
+
readonly multiValueHeaders: Record<string, string[]>;
|
23
|
+
readonly queryStringParameters: Record<string, string>;
|
24
|
+
readonly multiValueQueryStringParameters: Record<string, string[]>;
|
25
|
+
readonly body?: string;
|
26
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { DTDatabase, DTTransaction } from "./database";
|
2
|
+
export declare enum JSON_CACHE_KEY {
|
3
|
+
NAUTICAL_WARNINGS_ACTIVE = "nautical-warnings-active",
|
4
|
+
NAUTICAL_WARNINGS_ARCHIVED = "nautical-warnings-archived"
|
5
|
+
}
|
6
|
+
export declare function updateCachedJson<T>(db: DTDatabase | DTTransaction, cacheKey: JSON_CACHE_KEY, value: T): Promise<null>;
|
7
|
+
export declare function getJsonFromCache<T>(db: DTDatabase | DTTransaction, cacheKey: JSON_CACHE_KEY): Promise<T | null>;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { IDatabase, ITask } from "pg-promise";
|
2
|
+
export type DTDatabase = IDatabase<unknown>;
|
3
|
+
export type DTTransaction = ITask<unknown>;
|
4
|
+
/**
|
5
|
+
* Creates a non-pooling database connection primarily used by Lambdas.
|
6
|
+
*
|
7
|
+
* Note! Using this method opens a new RDS connection on every invocation. It is advised to
|
8
|
+
* use RDS proxy to pool connections transparently.
|
9
|
+
* https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html
|
10
|
+
* @param username Username
|
11
|
+
* @param password Password
|
12
|
+
* @param applicationName name of application
|
13
|
+
* @param url Connection URL
|
14
|
+
* @param options pg-promise options
|
15
|
+
*/
|
16
|
+
export declare function initDbConnection(username: string, password: string, applicationName: string, url: string, options?: object): DTDatabase;
|
17
|
+
export declare function inTransaction<T>(fn: (db: DTTransaction) => Promise<T>): Promise<T>;
|
18
|
+
export declare function inDatabase<T>(fn: (db: DTDatabase) => Promise<T>): Promise<T>;
|
19
|
+
export declare function inDatabaseReadonly<T>(fn: (db: DTDatabase) => Promise<T>): Promise<T>;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { DTDatabase, DTTransaction } from "./database";
|
2
|
+
export declare enum DataType {
|
3
|
+
VS_DATEX2 = "VS_DATEX2",
|
4
|
+
COUNTING_SITES_DATA = "COUNTING_SITES_DATA",
|
5
|
+
COUNTING_SITES_METADATA = "COUNTING_SITES_METADATA",
|
6
|
+
COUNTING_SITES_METADATA_CHECK = "COUNTING_SITES_METADATA_CHECK",
|
7
|
+
MAINTENANCE_TRACKING_DATA_CHECKED = "MAINTENANCE_TRACKING_DATA_CHECKED",
|
8
|
+
PERMIT_DATA = "PERMIT_DATA",
|
9
|
+
PERMIT_DATA_CHECK = "PERMIT_DATA_CHECK"
|
10
|
+
}
|
11
|
+
export declare function getLastUpdated(db: DTDatabase, datatype: DataType): Promise<Date | null>;
|
12
|
+
export declare function getLastUpdatedWithSubtype(db: DTDatabase, datatype: DataType, subtype: string): Promise<Date | null>;
|
13
|
+
export declare function updateLastUpdated(db: DTDatabase | DTTransaction, datatype: DataType, updated: Date): Promise<null>;
|
14
|
+
export declare function updateLastUpdatedWithSubtype(db: DTDatabase | DTTransaction, datatype: DataType, subtype: string, updated: Date): Promise<null>;
|
15
|
+
export declare function getUpdatedTimestamp(db: DTDatabase, datatype: string): Promise<Date | null>;
|
16
|
+
export declare function updateUpdatedTimestamp(db: DTDatabase | DTTransaction, datatype: string, date: Date, by?: string): Promise<null>;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
export type RtzPositionCoordinate = {
|
2
|
+
readonly $: {
|
3
|
+
readonly lat: number;
|
4
|
+
readonly lon: number;
|
5
|
+
};
|
6
|
+
};
|
7
|
+
export type RtzWaypointPosition = {
|
8
|
+
readonly position: RtzPositionCoordinate[];
|
9
|
+
};
|
10
|
+
export type RtzWaypoint = {
|
11
|
+
readonly waypoint: RtzWaypointPosition[];
|
12
|
+
};
|
13
|
+
export type RtzScheduleElement = {
|
14
|
+
readonly $: {
|
15
|
+
/**
|
16
|
+
* Date
|
17
|
+
*/
|
18
|
+
readonly etd?: string;
|
19
|
+
/**
|
20
|
+
* Date
|
21
|
+
*/
|
22
|
+
readonly eta?: string;
|
23
|
+
};
|
24
|
+
};
|
25
|
+
export type RtzSchedule = {
|
26
|
+
readonly scheduleElement: RtzScheduleElement[];
|
27
|
+
};
|
28
|
+
export type RtzScheduleWrapper = {
|
29
|
+
readonly manual?: RtzSchedule[];
|
30
|
+
readonly calculated?: RtzSchedule[];
|
31
|
+
};
|
32
|
+
export type RtzSchedules = {
|
33
|
+
readonly schedule: RtzScheduleWrapper[];
|
34
|
+
};
|
35
|
+
export type RtzRouteInfo = {
|
36
|
+
readonly $: {
|
37
|
+
readonly vesselMMSI: string;
|
38
|
+
readonly vesselIMO: string;
|
39
|
+
};
|
40
|
+
};
|
41
|
+
export type RtzRoute = {
|
42
|
+
readonly routeInfo: RtzRouteInfo[];
|
43
|
+
readonly waypoints: RtzWaypoint[];
|
44
|
+
readonly schedules: RtzSchedules[];
|
45
|
+
};
|
46
|
+
export type RtzVoyagePlan = {
|
47
|
+
readonly route: RtzRoute;
|
48
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
3
|
+
*/
|
4
|
+
export declare abstract class Asserter {
|
5
|
+
static assertEquals<T>(value: T, expected: T): void;
|
6
|
+
static assertTrue<T>(value: T): void;
|
7
|
+
static assertLength<T>(data: T[], expected: number): void;
|
8
|
+
static assertLengthGreaterThan<T>(data: T[], expected: number): void;
|
9
|
+
static assertGreaterThan(value: number, expected: number): void;
|
10
|
+
static assertToBeCloseTo(value: number, expected: number, delta: number): void;
|
11
|
+
}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { DTDatabase } from "../database/database";
|
2
|
+
export declare function assertCount(db: DTDatabase, sql: string, count: number): Promise<void>;
|
3
|
+
export declare function dbTestBase(fn: (db: DTDatabase) => void, truncateFn: (db: DTDatabase) => Promise<void>, dbUser: string, dbPass: string, dbUri: string): () => void;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export declare const ERROR_NO_MATCH = "NO MATCH";
|
2
|
+
export declare const ERRORCODE_NOT_FOUND = 404;
|
3
|
+
/**
|
4
|
+
* A mock HTTP server created for testing connections from a Lambda to an outside integration
|
5
|
+
*/
|
6
|
+
export declare class TestHttpServer {
|
7
|
+
private server?;
|
8
|
+
private debug;
|
9
|
+
private messageStack;
|
10
|
+
constructor();
|
11
|
+
getCallCount(): number;
|
12
|
+
getRequestBody(callNumber: number): string;
|
13
|
+
listen(port: number, props: ListenProperties, debug?: boolean, statusCode?: number): void;
|
14
|
+
close(): void;
|
15
|
+
private debuglog;
|
16
|
+
}
|
17
|
+
export interface ListenProperties {
|
18
|
+
[key: string]: (url?: string, data?: string) => string;
|
19
|
+
}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { EmptySecretFunction, SecretFunction } from "../aws/runtime/secrets/dbsecret";
|
2
|
+
export declare function createSecretFunction<Secret, Response>(secret: Secret): SecretFunction<Secret, Response>;
|
3
|
+
export declare function createEmptySecretFunction<Response>(): EmptySecretFunction<Response>;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import * as sinon from "sinon";
|
2
|
+
/**
|
3
|
+
* Stub Secrets Manager for tests. You must call this
|
4
|
+
* before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
|
5
|
+
*
|
6
|
+
* To mock the actual secret, call mockSecret()
|
7
|
+
*/
|
8
|
+
export declare function stubSecretsManager(): sinon.SinonStub<any[], any>;
|
9
|
+
export declare function mockSecret<Secret>(secret: Secret): void;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare function randomString(): string;
|
2
|
+
export declare function getRandomNumber(min: number, max: number): number;
|
3
|
+
export declare function getRandomNumberAsString(min: number, max: number): string;
|
4
|
+
export declare function getRandomInteger(min: number, max: number): number;
|
5
|
+
export declare function getRandomIntegerAsString(min: number, max: number): string;
|
6
|
+
export declare function getRandomBigInt(min: number, max: number): bigint;
|
7
|
+
export declare function randomBoolean(): boolean;
|
8
|
+
/**
|
9
|
+
* Returns a new copy of an array, shuffled using Math.random()
|
10
|
+
* @param array Array
|
11
|
+
*/
|
12
|
+
export declare function shuffle<T>(array: T[]): T[];
|