@digitraffic/common 2022.12.2-1 → 2022.12.22-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/dist/aws/infra/api/handler-factory.d.ts +9 -7
- package/dist/aws/infra/api/handler-factory.js +19 -16
- package/dist/aws/infra/api/integration.d.ts +2 -2
- package/dist/aws/infra/api/responses.js +4 -4
- package/dist/aws/infra/canaries/canary-parameters.d.ts +2 -2
- package/dist/aws/infra/canaries/canary-role.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-role.js +3 -5
- package/dist/aws/infra/documentation.d.ts +1 -1
- package/dist/aws/infra/documentation.js +3 -3
- package/dist/aws/infra/stack/monitoredfunction.d.ts +4 -4
- package/dist/aws/infra/stack/monitoredfunction.js +2 -2
- package/dist/aws/infra/stack/stack-checking-aspect.js +6 -8
- package/dist/aws/infra/stacks/db-stack.js +2 -1
- package/dist/aws/runtime/dt-logger.d.ts +28 -0
- package/dist/aws/runtime/dt-logger.js +41 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +4 -4
- package/dist/aws/runtime/secrets/dbsecret.js +1 -1
- package/dist/aws/types/proxytypes.d.ts +4 -4
- package/dist/database/last-updated.js +9 -7
- package/dist/marine/rtz.d.ts +20 -20
- package/dist/test/asserter.d.ts +6 -4
- package/dist/test/asserter.js +1 -1
- package/dist/test/httpserver.d.ts +1 -3
- package/dist/test/httpserver.js +10 -4
- package/dist/types/either.d.ts +4 -4
- package/package.json +1 -1
- package/src/aws/infra/api/handler-factory.ts +36 -26
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/responses.ts +6 -4
- package/src/aws/infra/canaries/canary-parameters.ts +3 -3
- package/src/aws/infra/canaries/canary-role.ts +20 -10
- package/src/aws/infra/documentation.ts +42 -24
- package/src/aws/infra/stack/monitoredfunction.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +15 -15
- package/src/aws/infra/stacks/db-stack.ts +2 -1
- package/src/aws/runtime/dt-logger.ts +61 -0
- package/src/aws/runtime/secrets/dbsecret.ts +5 -5
- package/src/aws/types/proxytypes.ts +14 -14
- package/src/database/last-updated.ts +75 -31
- package/src/marine/rtz.ts +29 -29
- package/src/test/asserter.ts +21 -11
- package/src/test/httpserver.ts +17 -8
- package/src/types/either.ts +8 -2
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { DtLogger } from "../../runtime/dt-logger";
|
2
|
+
import { LambdaResponse } from "../../types/lambda-response";
|
3
|
+
export type LoggingHandler = (method: () => Promise<LambdaResponse>, logger: DtLogger) => Promise<LambdaResponse>;
|
4
|
+
export type ErrorHandler = (error: unknown, logger: DtLogger) => LambdaResponse;
|
3
5
|
/**
|
4
6
|
* Factory class for creating lambda-handler functions. You can set functionality to handle logging and error-handling,
|
5
7
|
* with the defaults:
|
@@ -9,12 +11,12 @@ export type ErrorHandler<RESPONSE> = (error: unknown) => RESPONSE;
|
|
9
11
|
* You should instantiate HandlerFactory in your project with desired error handling and use the factory instance for
|
10
12
|
* creating handler-functions for your lambdas.
|
11
13
|
*/
|
12
|
-
export declare class HandlerFactory
|
14
|
+
export declare class HandlerFactory {
|
13
15
|
private loggingHandler;
|
14
16
|
private errorHandler;
|
15
17
|
constructor();
|
16
|
-
withLoggingHandler(loggingHandler: LoggingHandler
|
17
|
-
withErrorHandler(errorHandler: ErrorHandler
|
18
|
-
createEventHandler(
|
18
|
+
withLoggingHandler(loggingHandler: LoggingHandler): this;
|
19
|
+
withErrorHandler(errorHandler: ErrorHandler): this;
|
20
|
+
createEventHandler(handler: (event: unknown) => Promise<LambdaResponse>, logger: DtLogger): (event: unknown) => Promise<LambdaResponse>;
|
19
21
|
}
|
20
|
-
export declare function
|
22
|
+
export declare function createJsonLoggingHandler(): LoggingHandler;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.createJsonLoggingHandler = exports.HandlerFactory = void 0;
|
4
4
|
/**
|
5
5
|
* Factory class for creating lambda-handler functions. You can set functionality to handle logging and error-handling,
|
6
6
|
* with the defaults:
|
@@ -12,7 +12,15 @@ exports.createNoLoggingHandler = exports.HandlerFactory = void 0;
|
|
12
12
|
*/
|
13
13
|
class HandlerFactory {
|
14
14
|
constructor() {
|
15
|
-
this.loggingHandler =
|
15
|
+
this.loggingHandler = async (method) => {
|
16
|
+
const start = Date.now();
|
17
|
+
try {
|
18
|
+
return await method();
|
19
|
+
}
|
20
|
+
finally {
|
21
|
+
console.info("method=%s.handler tookMs=%d", process.env.AWS_LAMBDA_FUNCTION_NAME, Date.now() - start);
|
22
|
+
}
|
23
|
+
};
|
16
24
|
this.errorHandler = (error) => {
|
17
25
|
throw error;
|
18
26
|
};
|
@@ -25,35 +33,30 @@ class HandlerFactory {
|
|
25
33
|
this.errorHandler = errorHandler;
|
26
34
|
return this;
|
27
35
|
}
|
28
|
-
createEventHandler(
|
36
|
+
createEventHandler(handler, logger) {
|
29
37
|
return async (event) => {
|
30
|
-
return await this.loggingHandler(
|
38
|
+
return await this.loggingHandler(async () => {
|
31
39
|
try {
|
32
40
|
return await handler(event);
|
33
41
|
}
|
34
42
|
catch (error) {
|
35
|
-
return this.errorHandler(error);
|
43
|
+
return this.errorHandler(error, logger);
|
36
44
|
}
|
37
|
-
});
|
45
|
+
}, logger);
|
38
46
|
};
|
39
47
|
}
|
40
48
|
}
|
41
49
|
exports.HandlerFactory = HandlerFactory;
|
42
|
-
function
|
43
|
-
return (
|
44
|
-
return method();
|
45
|
-
};
|
46
|
-
}
|
47
|
-
exports.createNoLoggingHandler = createNoLoggingHandler;
|
48
|
-
function createDefaultLoggingHandler() {
|
49
|
-
return (methodName, method) => {
|
50
|
+
function createJsonLoggingHandler() {
|
51
|
+
return async (method, logger) => {
|
50
52
|
const start = Date.now();
|
51
53
|
try {
|
52
|
-
return method();
|
54
|
+
return await method();
|
53
55
|
}
|
54
56
|
finally {
|
55
|
-
|
57
|
+
logger.info({ tookMs: Date.now() - start });
|
56
58
|
}
|
57
59
|
};
|
58
60
|
}
|
61
|
+
exports.createJsonLoggingHandler = createJsonLoggingHandler;
|
59
62
|
//# sourceMappingURL=handler-factory.js.map
|
@@ -11,8 +11,8 @@ export declare class DigitrafficIntegration {
|
|
11
11
|
readonly mediaType: MediaType;
|
12
12
|
readonly parameters: ApiParameter[];
|
13
13
|
constructor(lambda: IFunction, mediaType?: MediaType);
|
14
|
-
addPathParameter(...names: string[]):
|
15
|
-
addQueryParameter(...names: string[]):
|
14
|
+
addPathParameter(...names: string[]): this;
|
15
|
+
addQueryParameter(...names: string[]): this;
|
16
16
|
build(): LambdaIntegration;
|
17
17
|
createRequestParameters(): Record<string, string>;
|
18
18
|
createRequestTemplates(): Record<string, string>;
|
@@ -37,7 +37,7 @@ function methodResponse(status, contentType, model, parameters) {
|
|
37
37
|
return {
|
38
38
|
statusCode: status,
|
39
39
|
responseModels: (0, response_1.createResponses)(contentType, model),
|
40
|
-
responseParameters: parameters
|
40
|
+
responseParameters: parameters ?? {},
|
41
41
|
};
|
42
42
|
}
|
43
43
|
exports.methodResponse = methodResponse;
|
@@ -65,14 +65,14 @@ exports.corsMethod = corsMethod;
|
|
65
65
|
function defaultIntegration(lambdaFunction, options) {
|
66
66
|
return new aws_apigateway_1.LambdaIntegration(lambdaFunction, {
|
67
67
|
proxy: false,
|
68
|
-
integrationResponses: options?.responses
|
68
|
+
integrationResponses: options?.responses ?? [
|
69
69
|
getResponse(exports.RESPONSE_200_OK, options),
|
70
70
|
getResponse(exports.RESPONSE_400_BAD_REQUEST, options),
|
71
71
|
getResponse(exports.RESPONSE_404_NOT_FOUND, options),
|
72
72
|
getResponse(exports.RESPONSE_500_SERVER_ERROR, options),
|
73
73
|
],
|
74
|
-
requestParameters: options?.requestParameters
|
75
|
-
requestTemplates: options?.requestTemplates
|
74
|
+
requestParameters: options?.requestParameters ?? {},
|
75
|
+
requestTemplates: options?.requestTemplates ?? {},
|
76
76
|
passthroughBehavior: options?.passthroughBehavior ?? aws_apigateway_1.PassthroughBehavior.WHEN_NO_MATCH,
|
77
77
|
});
|
78
78
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
|
2
2
|
/** Optional env parameters for canary */
|
3
3
|
type CanaryEnv = Record<string, string>;
|
4
|
-
export
|
4
|
+
export interface CanaryParameters {
|
5
5
|
readonly name: string;
|
6
6
|
readonly schedule?: Schedule;
|
7
7
|
readonly secret?: string;
|
@@ -14,5 +14,5 @@ export type CanaryParameters = {
|
|
14
14
|
readonly topicArn?: string;
|
15
15
|
};
|
16
16
|
readonly canaryEnv?: CanaryEnv;
|
17
|
-
}
|
17
|
+
}
|
18
18
|
export {};
|
@@ -2,5 +2,5 @@ import { Role } from "aws-cdk-lib/aws-iam";
|
|
2
2
|
import { Construct } from "constructs";
|
3
3
|
export declare class DigitrafficCanaryRole extends Role {
|
4
4
|
constructor(stack: Construct, canaryName: string);
|
5
|
-
withDatabaseAccess():
|
5
|
+
withDatabaseAccess(): this;
|
6
6
|
}
|
@@ -13,19 +13,17 @@ const BASE_POLICY_STATEMENT_PROPS = {
|
|
13
13
|
resources: ["*"],
|
14
14
|
};
|
15
15
|
const CLOUDWATCH_STATEMENT_PROPS = {
|
16
|
-
actions: [
|
17
|
-
"cloudwatch:PutMetricData",
|
18
|
-
],
|
16
|
+
actions: ["cloudwatch:PutMetricData"],
|
19
17
|
resources: ["*"],
|
20
18
|
conditions: {
|
21
|
-
|
19
|
+
StringEquals: {
|
22
20
|
"cloudwatch:namespace": "CloudWatchSynthetics",
|
23
21
|
},
|
24
22
|
},
|
25
23
|
};
|
26
24
|
class DigitrafficCanaryRole extends aws_iam_1.Role {
|
27
25
|
constructor(stack, canaryName) {
|
28
|
-
super(stack,
|
26
|
+
super(stack, "canary-role-" + canaryName, {
|
29
27
|
assumedBy: new aws_iam_1.ServicePrincipal("lambda.amazonaws.com"),
|
30
28
|
managedPolicies: [
|
31
29
|
aws_iam_1.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchSyntheticsFullAccess"),
|
@@ -49,7 +49,7 @@ export declare class DocumentationPart {
|
|
49
49
|
readonly type: string;
|
50
50
|
readonly documentationProperties: DocumentationProperties;
|
51
51
|
private constructor();
|
52
|
-
deprecated(note: string):
|
52
|
+
deprecated(note: string): this;
|
53
53
|
static queryParameter(parameterName: string, description: string): DocumentationPart;
|
54
54
|
static pathParameter(parameterName: string, description: string): DocumentationPart;
|
55
55
|
static method(tags: string[], name: string, summary: string): DocumentationPart;
|
@@ -17,7 +17,7 @@ function addQueryParameterDescription(name, description, resource, stack) {
|
|
17
17
|
new aws_apigateway_1.CfnDocumentationPart(stack, `${name}Documentation`, {
|
18
18
|
restApiId: resource.api.restApiId,
|
19
19
|
location: {
|
20
|
-
type:
|
20
|
+
type: "QUERY_PARAMETER",
|
21
21
|
name,
|
22
22
|
path: resource.path,
|
23
23
|
},
|
@@ -36,7 +36,7 @@ function addDocumentation(methodDescription, documentationProperties, resource,
|
|
36
36
|
new aws_apigateway_1.CfnDocumentationPart(stack, `${methodDescription}Documentation`, {
|
37
37
|
restApiId: resource.api.restApiId,
|
38
38
|
location: {
|
39
|
-
type:
|
39
|
+
type: "METHOD",
|
40
40
|
path: resource.path,
|
41
41
|
},
|
42
42
|
properties: JSON.stringify(documentationProperties),
|
@@ -78,7 +78,7 @@ class DocumentationPart {
|
|
78
78
|
deprecated(note) {
|
79
79
|
// deprecated is not supported ATM: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
|
80
80
|
this.documentationProperties.deprecated = true;
|
81
|
-
this.documentationProperties.summary +=
|
81
|
+
this.documentationProperties.summary += ". " + note;
|
82
82
|
return this;
|
83
83
|
}
|
84
84
|
static queryParameter(parameterName, description) {
|
@@ -8,7 +8,7 @@ import { TrafficType } from "../../../types/traffictype";
|
|
8
8
|
/**
|
9
9
|
* Allows customization of CloudWatch Alarm properties
|
10
10
|
*/
|
11
|
-
export
|
11
|
+
export interface MonitoredFunctionAlarmProps {
|
12
12
|
/**
|
13
13
|
* Setting this to false will not create a CloudWatch alarm
|
14
14
|
*/
|
@@ -17,13 +17,13 @@ export type MonitoredFunctionAlarmProps = {
|
|
17
17
|
readonly evaluationPeriods?: number;
|
18
18
|
readonly datapointsToAlarm?: number;
|
19
19
|
readonly comparisonOperator?: ComparisonOperator;
|
20
|
-
}
|
21
|
-
export
|
20
|
+
}
|
21
|
+
export interface MonitoredFunctionProps {
|
22
22
|
readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
|
23
23
|
readonly durationWarningProps?: MonitoredFunctionAlarmProps;
|
24
24
|
readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
|
25
25
|
readonly throttleAlarmProps?: MonitoredFunctionAlarmProps;
|
26
|
-
}
|
26
|
+
}
|
27
27
|
/**
|
28
28
|
* Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
|
29
29
|
*/
|
@@ -37,7 +37,7 @@ class MonitoredFunction extends aws_lambda_1.Function {
|
|
37
37
|
* @param functionParameters Lambda function parameters
|
38
38
|
*/
|
39
39
|
static createV2(stack, name, environment, functionParameters) {
|
40
|
-
const functionName = functionParameters?.functionName
|
40
|
+
const functionName = functionParameters?.functionName ??
|
41
41
|
`${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
|
42
42
|
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
|
43
43
|
return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
|
@@ -127,7 +127,7 @@ class MonitoredDBFunction {
|
|
127
127
|
* @param functionParameters Lambda function parameters
|
128
128
|
*/
|
129
129
|
static create(stack, name, environment, functionParameters) {
|
130
|
-
const functionName = functionParameters?.functionName
|
130
|
+
const functionName = functionParameters?.functionName ??
|
131
131
|
`${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
|
132
132
|
const env = environment ? environment : stack.createLambdaEnvironment();
|
133
133
|
const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, env, functionName, name, functionParameters);
|
@@ -110,13 +110,11 @@ class StackCheckingAspect {
|
|
110
110
|
checkBucket(node) {
|
111
111
|
if (node instanceof aws_s3_1.CfnBucket) {
|
112
112
|
const c = node.publicAccessBlockConfiguration;
|
113
|
-
if (c
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
this.addAnnotation(node, ResourceType.bucketPublicity, "Check bucket publicity");
|
119
|
-
}
|
113
|
+
if (!c.blockPublicAcls ||
|
114
|
+
!c.blockPublicPolicy ||
|
115
|
+
!c.ignorePublicAcls ||
|
116
|
+
!c.restrictPublicBuckets) {
|
117
|
+
this.addAnnotation(node, ResourceType.bucketPublicity, "Check bucket publicity");
|
120
118
|
}
|
121
119
|
}
|
122
120
|
}
|
@@ -141,7 +139,7 @@ class StackCheckingAspect {
|
|
141
139
|
}
|
142
140
|
else if (node instanceof aws_apigateway_1.CfnMethod) {
|
143
141
|
const integration = node.integration;
|
144
|
-
if (integration
|
142
|
+
if (integration?.requestParameters) {
|
145
143
|
Object.keys(integration.requestParameters).forEach((key) => {
|
146
144
|
const split = key.split(".");
|
147
145
|
const type = split[2];
|
@@ -38,7 +38,8 @@ class DbStack extends aws_cdk_lib_1.Stack {
|
|
38
38
|
}),
|
39
39
|
parameters: {
|
40
40
|
"pg_stat_statements.track": "ALL",
|
41
|
-
random_page_cost: "1",
|
41
|
+
"random_page_cost": "1",
|
42
|
+
"work_mem": "512MB"
|
42
43
|
},
|
43
44
|
})
|
44
45
|
: aws_rds_1.ParameterGroup.fromParameterGroupName(this, "ParameterGroup", `default.aurora-postgresql${configuration.dbVersion.auroraPostgresMajorVersion}`);
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { Writable } from "stream";
|
3
|
+
type LOG_LEVEL = "DEBUG" | "INFO" | "ERROR";
|
4
|
+
export interface LoggerConfiguration {
|
5
|
+
lambdaName?: string;
|
6
|
+
fileName?: string;
|
7
|
+
runTime?: string;
|
8
|
+
writeStream?: Writable;
|
9
|
+
}
|
10
|
+
export type LoggableType = string | number | Record<string, unknown>;
|
11
|
+
/**
|
12
|
+
* Helper class for json-logging. Logged line will include
|
13
|
+
* * log-level (see LOG_LEVEL)
|
14
|
+
* * lambdaName (taken from process environment)
|
15
|
+
* * runtime (taken from process environment)
|
16
|
+
* * the actual message (as json or as string)
|
17
|
+
*/
|
18
|
+
export declare class DtLogger {
|
19
|
+
readonly lambdaName?: string;
|
20
|
+
readonly fileName?: string;
|
21
|
+
readonly runtime?: string;
|
22
|
+
readonly writeStream: Writable;
|
23
|
+
constructor(config?: LoggerConfiguration);
|
24
|
+
info(message: LoggableType): void;
|
25
|
+
error(message: LoggableType): void;
|
26
|
+
log(level: LOG_LEVEL, message: LoggableType): void;
|
27
|
+
}
|
28
|
+
export {};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.DtLogger = void 0;
|
4
|
+
/**
|
5
|
+
* Helper class for json-logging. Logged line will include
|
6
|
+
* * log-level (see LOG_LEVEL)
|
7
|
+
* * lambdaName (taken from process environment)
|
8
|
+
* * runtime (taken from process environment)
|
9
|
+
* * the actual message (as json or as string)
|
10
|
+
*/
|
11
|
+
class DtLogger {
|
12
|
+
constructor(config) {
|
13
|
+
this.lambdaName =
|
14
|
+
config?.lambdaName ?? process.env.AWS_LAMBDA_FUNCTION_NAME;
|
15
|
+
this.fileName = config?.fileName;
|
16
|
+
this.runtime = config?.runTime ?? process.env.AWS_EXECUTION_ENV;
|
17
|
+
this.writeStream = config?.writeStream ?? process.stdout;
|
18
|
+
}
|
19
|
+
info(message) {
|
20
|
+
this.log("INFO", message);
|
21
|
+
}
|
22
|
+
error(message) {
|
23
|
+
this.log("ERROR", message);
|
24
|
+
}
|
25
|
+
log(level, message) {
|
26
|
+
// put string/number messages into message object
|
27
|
+
const actualMessage = typeof message == "object" ? message : { message: message };
|
28
|
+
const logMessage = {
|
29
|
+
...actualMessage,
|
30
|
+
...{
|
31
|
+
level,
|
32
|
+
fileName: this.fileName,
|
33
|
+
lambdaName: this.lambdaName,
|
34
|
+
runtime: this.runtime,
|
35
|
+
},
|
36
|
+
};
|
37
|
+
this.writeStream.write(JSON.stringify(logMessage) + "\n");
|
38
|
+
}
|
39
|
+
}
|
40
|
+
exports.DtLogger = DtLogger;
|
41
|
+
//# sourceMappingURL=dt-logger.js.map
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { GenericSecret } from "./secret";
|
2
|
-
export
|
2
|
+
export interface DbSecret {
|
3
3
|
readonly username: string;
|
4
4
|
readonly password: string;
|
5
5
|
readonly host: string;
|
6
6
|
readonly ro_host: string;
|
7
|
-
}
|
7
|
+
}
|
8
8
|
export declare enum RdsProxySecretKey {
|
9
9
|
username = "username",
|
10
10
|
password = "password",
|
@@ -34,10 +34,10 @@ export declare enum DatabaseEnvironmentKeys {
|
|
34
34
|
* The secret that is passed to the given function will not include the prefix in it's keys.
|
35
35
|
|
36
36
|
*/
|
37
|
-
export
|
37
|
+
export interface SecretOptions {
|
38
38
|
readonly expectedKeys?: string[];
|
39
39
|
readonly prefix?: string;
|
40
|
-
}
|
40
|
+
}
|
41
41
|
export type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
|
42
42
|
export type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
|
43
43
|
export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
|
@@ -88,7 +88,7 @@ exports.withDbSecret = withDbSecret;
|
|
88
88
|
function checkExpectedSecretKeys(keys, secret) {
|
89
89
|
const missingKeys = keys.filter((key) => !(key in secret));
|
90
90
|
if (missingKeys.length) {
|
91
|
-
console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
|
91
|
+
console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys.toString()}`);
|
92
92
|
throw new Error("Expected keys were not found");
|
93
93
|
}
|
94
94
|
}
|
@@ -3,18 +3,18 @@
|
|
3
3
|
*
|
4
4
|
* Not fully described, extend if necessary.
|
5
5
|
*/
|
6
|
-
export
|
6
|
+
export interface ProxyLambdaResponse {
|
7
7
|
readonly statusCode: number;
|
8
8
|
readonly body: string;
|
9
9
|
readonly headers?: Record<string, string>;
|
10
10
|
readonly multiValueHeaders?: Record<string, string[]>;
|
11
|
-
}
|
11
|
+
}
|
12
12
|
/**
|
13
13
|
* https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
|
14
14
|
*
|
15
15
|
* Not fully described, extend if necessary.
|
16
16
|
*/
|
17
|
-
export
|
17
|
+
export interface ProxyLambdaRequest {
|
18
18
|
readonly resource: string;
|
19
19
|
readonly path: string;
|
20
20
|
readonly httpMethod: string;
|
@@ -23,4 +23,4 @@ export type ProxyLambdaRequest = {
|
|
23
23
|
readonly queryStringParameters: Record<string, string>;
|
24
24
|
readonly multiValueQueryStringParameters: Record<string, string[]>;
|
25
25
|
readonly body?: string;
|
26
|
-
}
|
26
|
+
}
|
@@ -11,17 +11,19 @@ var DataType;
|
|
11
11
|
DataType["PERMIT_DATA"] = "PERMIT_DATA";
|
12
12
|
DataType["PERMIT_DATA_CHECK"] = "PERMIT_DATA_CHECK";
|
13
13
|
})(DataType = exports.DataType || (exports.DataType = {}));
|
14
|
-
const UNSET_SUBTYPE =
|
14
|
+
const UNSET_SUBTYPE = "-";
|
15
15
|
function getLastUpdated(db, datatype) {
|
16
16
|
return db.oneOrNone("select updated from data_updated where data_type=$(datatype) and subtype=$(subtype)", {
|
17
|
-
datatype: datatype,
|
18
|
-
|
17
|
+
datatype: datatype,
|
18
|
+
subtype: UNSET_SUBTYPE,
|
19
|
+
}, (x) => x?.updated ?? null);
|
19
20
|
}
|
20
21
|
exports.getLastUpdated = getLastUpdated;
|
21
22
|
function getLastUpdatedWithSubtype(db, datatype, subtype) {
|
22
23
|
return db.oneOrNone("SELECT updated FROM data_updated WHERE data_type=$(datatype) AND subtype=$(subtype)", {
|
23
|
-
datatype: datatype,
|
24
|
-
|
24
|
+
datatype: datatype,
|
25
|
+
subtype: subtype,
|
26
|
+
}, (x) => x?.updated ?? null);
|
25
27
|
}
|
26
28
|
exports.getLastUpdatedWithSubtype = getLastUpdatedWithSubtype;
|
27
29
|
function updateLastUpdated(db, datatype, updated) {
|
@@ -41,10 +43,10 @@ exports.updateLastUpdatedWithSubtype = updateLastUpdatedWithSubtype;
|
|
41
43
|
function getUpdatedTimestamp(db, datatype) {
|
42
44
|
return db.oneOrNone("select updated_time as updated from updated_timestamp where updated_name=$(datatype)", {
|
43
45
|
datatype: datatype,
|
44
|
-
}, (x) => x?.updated
|
46
|
+
}, (x) => x?.updated ?? null);
|
45
47
|
}
|
46
48
|
exports.getUpdatedTimestamp = getUpdatedTimestamp;
|
47
|
-
function updateUpdatedTimestamp(db, datatype, date, by =
|
49
|
+
function updateUpdatedTimestamp(db, datatype, date, by = "") {
|
48
50
|
return db.none(`insert into updated_timestamp(updated_name, updated_time, updated_by)
|
49
51
|
values($(datatype), $(date), $(by))
|
50
52
|
on conflict (updated_name)
|
package/dist/marine/rtz.d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
export
|
1
|
+
export interface RtzPositionCoordinate {
|
2
2
|
readonly $: {
|
3
3
|
readonly lat: number;
|
4
4
|
readonly lon: number;
|
5
5
|
};
|
6
|
-
}
|
7
|
-
export
|
6
|
+
}
|
7
|
+
export interface RtzWaypointPosition {
|
8
8
|
readonly position: RtzPositionCoordinate[];
|
9
|
-
}
|
10
|
-
export
|
9
|
+
}
|
10
|
+
export interface RtzWaypoint {
|
11
11
|
readonly waypoint: RtzWaypointPosition[];
|
12
|
-
}
|
13
|
-
export
|
12
|
+
}
|
13
|
+
export interface RtzScheduleElement {
|
14
14
|
readonly $: {
|
15
15
|
/**
|
16
16
|
* Date
|
@@ -21,28 +21,28 @@ export type RtzScheduleElement = {
|
|
21
21
|
*/
|
22
22
|
readonly eta?: string;
|
23
23
|
};
|
24
|
-
}
|
25
|
-
export
|
24
|
+
}
|
25
|
+
export interface RtzSchedule {
|
26
26
|
readonly scheduleElement: RtzScheduleElement[];
|
27
|
-
}
|
28
|
-
export
|
27
|
+
}
|
28
|
+
export interface RtzScheduleWrapper {
|
29
29
|
readonly manual?: RtzSchedule[];
|
30
30
|
readonly calculated?: RtzSchedule[];
|
31
|
-
}
|
32
|
-
export
|
31
|
+
}
|
32
|
+
export interface RtzSchedules {
|
33
33
|
readonly schedule: RtzScheduleWrapper[];
|
34
|
-
}
|
35
|
-
export
|
34
|
+
}
|
35
|
+
export interface RtzRouteInfo {
|
36
36
|
readonly $: {
|
37
37
|
readonly vesselMMSI: string;
|
38
38
|
readonly vesselIMO: string;
|
39
39
|
};
|
40
|
-
}
|
41
|
-
export
|
40
|
+
}
|
41
|
+
export interface RtzRoute {
|
42
42
|
readonly routeInfo: RtzRouteInfo[];
|
43
43
|
readonly waypoints: RtzWaypoint[];
|
44
44
|
readonly schedules: RtzSchedules[];
|
45
|
-
}
|
46
|
-
export
|
45
|
+
}
|
46
|
+
export interface RtzVoyagePlan {
|
47
47
|
readonly route: RtzRoute;
|
48
|
-
}
|
48
|
+
}
|
package/dist/test/asserter.d.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
/**
|
2
2
|
* A simple asserter-class for writing canaries without dependency to testing-libraries.
|
3
3
|
*/
|
4
|
+
type AssertedValue = string | number;
|
4
5
|
export declare abstract class Asserter {
|
5
|
-
static assertEquals
|
6
|
-
static assertTrue
|
7
|
-
static assertLength<T>(data: T[], expected: number): void;
|
8
|
-
static assertLengthGreaterThan<T>(data: T[], expected: number): void;
|
6
|
+
static assertEquals(value: AssertedValue, expected: AssertedValue): void;
|
7
|
+
static assertTrue(value: boolean): void;
|
8
|
+
static assertLength<T>(data: T[] | undefined, expected: number): void;
|
9
|
+
static assertLengthGreaterThan<T>(data: T[] | undefined, expected: number): void;
|
9
10
|
static assertGreaterThan(value: number, expected: number): void;
|
10
11
|
static assertToBeCloseTo(value: number, expected: number, delta: number): void;
|
11
12
|
}
|
13
|
+
export {};
|
package/dist/test/asserter.js
CHANGED
@@ -14,6 +14,4 @@ export declare class TestHttpServer {
|
|
14
14
|
close(): void;
|
15
15
|
private debuglog;
|
16
16
|
}
|
17
|
-
export
|
18
|
-
[key: string]: (url?: string, data?: string) => string;
|
19
|
-
}
|
17
|
+
export type ListenProperties = Record<string, (url?: string, data?: string) => string>;
|
package/dist/test/httpserver.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.TestHttpServer = exports.ERRORCODE_NOT_FOUND = exports.ERROR_NO_MATCH = void 0;
|
4
4
|
const http_1 = require("http");
|
5
|
+
const url_1 = require("url");
|
5
6
|
exports.ERROR_NO_MATCH = "NO MATCH";
|
6
7
|
exports.ERRORCODE_NOT_FOUND = 404;
|
7
8
|
/**
|
@@ -25,9 +26,14 @@ class TestHttpServer {
|
|
25
26
|
this.server = (0, http_1.createServer)((req, res) => {
|
26
27
|
this.debuglog("Mapped urls: ");
|
27
28
|
Object.keys(props).forEach((k) => this.debuglog(k));
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
if (!req.url) {
|
30
|
+
throw new Error("Missing request url!");
|
31
|
+
}
|
32
|
+
this.debuglog(`Received request to url ${req.url} ..`);
|
33
|
+
const path = (0, url_1.parse)(req.url).pathname;
|
34
|
+
if (!path) {
|
35
|
+
throw new Error("Missing path from request!");
|
36
|
+
}
|
31
37
|
let dataStr = "";
|
32
38
|
req.on("data", (chunk) => {
|
33
39
|
if (chunk) {
|
@@ -46,7 +52,7 @@ class TestHttpServer {
|
|
46
52
|
});
|
47
53
|
}
|
48
54
|
else {
|
49
|
-
this.debuglog(
|
55
|
+
this.debuglog(`..no match for ${path}`);
|
50
56
|
req.on("end", () => {
|
51
57
|
// assume sent data is in JSON format
|
52
58
|
this.messageStack[this.messageStack.length] =
|
package/dist/types/either.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export
|
1
|
+
export interface EitherOk<T> {
|
2
2
|
result: "ok";
|
3
3
|
value: T;
|
4
|
-
}
|
5
|
-
export
|
4
|
+
}
|
5
|
+
export interface EitherError {
|
6
6
|
result: "error";
|
7
7
|
message: string;
|
8
|
-
}
|
8
|
+
}
|
9
9
|
export type Either<T> = EitherOk<T> | EitherError;
|