@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.
Files changed (73) hide show
  1. package/dist/aws/infra/api/integration.d.ts +21 -0
  2. package/dist/aws/infra/api/response.d.ts +22 -0
  3. package/dist/aws/infra/api/responses.d.ts +39 -0
  4. package/dist/aws/infra/api/static-integration.d.ts +15 -0
  5. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  6. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  7. package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
  8. package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
  9. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  10. package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
  11. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  12. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  13. package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
  14. package/dist/aws/infra/documentation.d.ts +56 -0
  15. package/dist/aws/infra/import-util.d.ts +21 -0
  16. package/dist/aws/infra/scheduler.d.ts +12 -0
  17. package/dist/aws/infra/security-rule.d.ts +12 -0
  18. package/dist/aws/infra/sqs-integration.d.ts +7 -0
  19. package/dist/aws/infra/sqs-queue.d.ts +16 -0
  20. package/dist/aws/infra/stack/lambda-configs.d.ts +64 -0
  21. package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
  22. package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
  23. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
  24. package/dist/aws/infra/stack/stack.d.ts +45 -0
  25. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  26. package/dist/aws/infra/stacks/db-dns-stack.d.ts +11 -0
  27. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +19 -0
  28. package/dist/aws/infra/stacks/db-stack.d.ts +31 -0
  29. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  30. package/dist/aws/infra/stacks/network-stack.d.ts +12 -0
  31. package/dist/aws/infra/usage-plans.d.ts +16 -0
  32. package/dist/aws/runtime/apikey.d.ts +2 -0
  33. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  34. package/dist/aws/runtime/environment.d.ts +1 -0
  35. package/dist/aws/runtime/messaging.d.ts +10 -0
  36. package/dist/aws/runtime/s3.d.ts +2 -0
  37. package/dist/aws/runtime/secrets/dbsecret.d.ts +55 -0
  38. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  39. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  40. package/dist/aws/runtime/secrets/secret-holder.d.ts +27 -0
  41. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  42. package/dist/aws/types/errors.d.ts +8 -0
  43. package/dist/aws/types/lambda-response.d.ts +13 -0
  44. package/dist/aws/types/mediatypes.d.ts +11 -0
  45. package/dist/aws/types/model-with-reference.d.ts +7 -0
  46. package/dist/aws/types/proxytypes.d.ts +26 -0
  47. package/dist/aws/types/tags.d.ts +2 -0
  48. package/dist/database/cached.d.ts +7 -0
  49. package/dist/database/database.d.ts +19 -0
  50. package/dist/database/last-updated.d.ts +16 -0
  51. package/dist/database/models.d.ts +6 -0
  52. package/dist/marine/id_utils.d.ts +3 -0
  53. package/dist/marine/rtz.d.ts +48 -0
  54. package/dist/test/asserter.d.ts +11 -0
  55. package/dist/test/db-testutils.d.ts +3 -0
  56. package/dist/test/httpserver.d.ts +19 -0
  57. package/dist/test/secret.d.ts +3 -0
  58. package/dist/test/secrets-manager.d.ts +9 -0
  59. package/dist/test/testutils.d.ts +12 -0
  60. package/dist/types/either.d.ts +9 -0
  61. package/dist/types/input-error.d.ts +2 -0
  62. package/dist/types/language.d.ts +5 -0
  63. package/dist/types/traffictype.d.ts +8 -0
  64. package/dist/types/validator.d.ts +4 -0
  65. package/dist/utils/api-model.d.ts +87 -0
  66. package/dist/utils/base64.d.ts +12 -0
  67. package/dist/utils/date-utils.d.ts +17 -0
  68. package/dist/utils/geojson-types.d.ts +14 -0
  69. package/dist/utils/geometry.d.ts +36 -0
  70. package/dist/utils/retry.d.ts +13 -0
  71. package/dist/utils/slack.d.ts +5 -0
  72. package/dist/utils/utils.d.ts +46 -0
  73. package/package.json +2 -1
@@ -0,0 +1,21 @@
1
+ import { IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
2
+ import { IFunction } from "aws-cdk-lib/aws-lambda";
3
+ import { MediaType } from "../../types/mediatypes";
4
+ type ParameterType = 'path' | 'querystring';
5
+ interface ApiParameter {
6
+ type: ParameterType;
7
+ name: string;
8
+ }
9
+ export declare class DigitrafficIntegration {
10
+ readonly lambda: IFunction;
11
+ readonly mediaType: MediaType;
12
+ readonly parameters: ApiParameter[];
13
+ constructor(lambda: IFunction, mediaType?: MediaType);
14
+ addPathParameter(...names: string[]): DigitrafficIntegration;
15
+ addQueryParameter(...names: string[]): DigitrafficIntegration;
16
+ build(): LambdaIntegration;
17
+ createRequestParameters(): Record<string, string>;
18
+ createRequestTemplates(): Record<string, string>;
19
+ createResponses(): IntegrationResponse[];
20
+ }
21
+ export {};
@@ -0,0 +1,22 @@
1
+ import apigateway = require('aws-cdk-lib/aws-apigateway');
2
+ import { MediaType } from "../../types/mediatypes";
3
+ /**
4
+ * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
5
+ * It will always return the body and status, but if status in something else than 200 OK the content-type
6
+ * will be overridden to text/plain. (it's assumed, that lambda will return error text).
7
+ *
8
+ * If fileName is set, then Content-Disposition-header will be set to use it
9
+ */
10
+ export declare const RESPONSE_DEFAULT_LAMBDA = "#set($inputRoot = $input.path('$'))\n$inputRoot.body\n#if ($inputRoot.status != 200)\n#set ($context.responseOverride.status = $inputRoot.status)\n#set ($context.responseOverride.header.Content-Type = 'text/plain')\n#end\n#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')\n#if (\"$!inputRoot.fileName\" != \"\")\n#set ($disposition = 'attachment; filename=\"FN\"')\n#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))\n#end\n";
11
+ export declare const MessageModel: {
12
+ contentType: MediaType;
13
+ modelName: string;
14
+ schema: apigateway.JsonSchema;
15
+ };
16
+ export declare const NotFoundResponse: string;
17
+ export declare const BadRequestResponseTemplate: Record<string, string>;
18
+ export declare const NotFoundResponseTemplate: Record<string, string>;
19
+ export declare const XmlResponseTemplate: Record<string, string>;
20
+ export declare const SvgResponseTemplate: Record<string, string>;
21
+ export declare const InternalServerErrorResponseTemplate: Record<string, string>;
22
+ export declare function createResponses<T>(key: MediaType, value: T): Record<string, T>;
@@ -0,0 +1,39 @@
1
+ import { LambdaIntegration, MethodResponse, IntegrationResponse, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
2
+ import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
3
+ import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
4
+ import { MediaType } from "../../types/mediatypes";
5
+ export declare const RESPONSE_200_OK: IntegrationResponse;
6
+ export declare const RESPONSE_400_BAD_REQUEST: IntegrationResponse;
7
+ export declare const RESPONSE_500_SERVER_ERROR: IntegrationResponse;
8
+ export declare const RESPONSE_CORS_INTEGRATION: {
9
+ responseParameters: {
10
+ "method.response.header.Access-Control-Allow-Origin": string;
11
+ };
12
+ };
13
+ export declare const RESPONSE_404_NOT_FOUND: {
14
+ statusCode: string;
15
+ selectionPattern: string;
16
+ responseTemplates: Record<string, string>;
17
+ };
18
+ export declare function methodResponse(status: string, contentType: MediaType, model: IModel, parameters?: Record<string, boolean>): MethodResponse;
19
+ export declare function corsMethod(response: MethodResponse): MethodResponse;
20
+ interface IntegrationOptions {
21
+ requestParameters?: {
22
+ [dest: string]: string;
23
+ };
24
+ requestTemplates?: {
25
+ [contentType: string]: string;
26
+ };
27
+ responses?: IntegrationResponse[];
28
+ disableCors?: boolean;
29
+ xml?: boolean;
30
+ passthroughBehavior?: PassthroughBehavior;
31
+ }
32
+ /**
33
+ * Creates a default Lambda integration for a REST API resource _root_
34
+ * @param lambdaFunction The Lambda function
35
+ * @param options Options
36
+ */
37
+ export declare function defaultIntegration(lambdaFunction: AWSFunction, options?: IntegrationOptions): LambdaIntegration;
38
+ export declare function getResponse(response: IntegrationResponse, options?: IntegrationOptions): IntegrationResponse;
39
+ export {};
@@ -0,0 +1,15 @@
1
+ import { MockIntegration, Resource } from "aws-cdk-lib/aws-apigateway";
2
+ import { MediaType } from "../../types/mediatypes";
3
+ /**
4
+ * Static integration, that returns the given response with given mediaType from given resource.
5
+ *
6
+ * @param resource
7
+ * @param mediaType
8
+ * @param response
9
+ */
10
+ export declare class DigitrafficStaticIntegration extends MockIntegration {
11
+ constructor(resource: Resource, mediaType: MediaType, response: string, enableCors?: boolean, apiKeyRequired?: boolean);
12
+ static json<K>(resource: Resource, response: K, enableCors?: boolean, apiKeyRequired?: boolean): DigitrafficStaticIntegration;
13
+ private static createIntegrationResponse;
14
+ private static createMethodResponse;
15
+ }
@@ -0,0 +1,6 @@
1
+ import { Construct } from "constructs";
2
+ import { CanaryParameters } from "./canary-parameters";
3
+ import { Canary } from "@aws-cdk/aws-synthetics-alpha";
4
+ export declare class CanaryAlarm {
5
+ constructor(stack: Construct, canary: Canary, params: CanaryParameters);
6
+ }
@@ -0,0 +1,3 @@
1
+ export declare const ENV_API_KEY = "apiKeyId";
2
+ export declare const ENV_HOSTNAME = "hostname";
3
+ export declare const ENV_SECRET = "secret";
@@ -0,0 +1,18 @@
1
+ import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
2
+ /** Optional env parameters for canary */
3
+ type CanaryEnv = Record<string, string>;
4
+ export type CanaryParameters = {
5
+ readonly name: string;
6
+ readonly schedule?: Schedule;
7
+ readonly secret?: string;
8
+ readonly handler: string;
9
+ readonly alarm?: {
10
+ readonly alarmName?: string;
11
+ readonly description?: string;
12
+ readonly evalutionPeriods?: number;
13
+ readonly threshold?: number;
14
+ readonly topicArn?: string;
15
+ };
16
+ readonly canaryEnv?: CanaryEnv;
17
+ };
18
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Role } from "aws-cdk-lib/aws-iam";
2
+ import { Construct } from "constructs";
3
+ export declare class DigitrafficCanaryRole extends Role {
4
+ constructor(stack: Construct, canaryName: string);
5
+ withDatabaseAccess(): DigitrafficCanaryRole;
6
+ }
@@ -0,0 +1,8 @@
1
+ import { Canary } from "@aws-cdk/aws-synthetics-alpha";
2
+ import { Role } from "aws-cdk-lib/aws-iam";
3
+ import { CanaryParameters } from "./canary-parameters";
4
+ import { Construct } from "constructs";
5
+ import { LambdaEnvironment } from "../stack/lambda-configs";
6
+ export declare class DigitrafficCanary extends Canary {
7
+ constructor(scope: Construct, canaryName: string, role: Role, params: CanaryParameters, environmentVariables: LambdaEnvironment);
8
+ }
@@ -0,0 +1,18 @@
1
+ import { Role } from "aws-cdk-lib/aws-iam";
2
+ import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
3
+ import { CanaryParameters } from "./canary-parameters";
4
+ import { DigitrafficCanary } from "./canary";
5
+ import { DigitrafficStack } from "../stack/stack";
6
+ export declare class DatabaseCanary extends DigitrafficCanary {
7
+ constructor(stack: DigitrafficStack, role: Role, secret: ISecret, params: CanaryParameters);
8
+ static create(stack: DigitrafficStack, role: Role, params: CanaryParameters): DatabaseCanary;
9
+ /**
10
+ *
11
+ * @param stack
12
+ * @param role
13
+ * @param name name of the typescipt file without -db -suffix. Max len is 10 char if @param canaryName is not given.
14
+ * @param params
15
+ * @param canaryName Optional name for canary if multiple canaries is made from same ${name}-db.ts canary file.
16
+ */
17
+ static createV2(stack: DigitrafficStack, role: Role, name: string, params?: Partial<CanaryParameters>, canaryName?: string): DatabaseCanary;
18
+ }
@@ -0,0 +1,33 @@
1
+ import { Countable } from "../../../database/models";
2
+ declare abstract class DatabaseCheck<T> {
3
+ readonly name: string;
4
+ readonly sql: string;
5
+ failed: boolean;
6
+ protected constructor(name: string, sql: string);
7
+ abstract check(value: T): void;
8
+ }
9
+ /**
10
+ * Checker for sql that checks the count. Meaning that the
11
+ * sql must be structured as "select count(*) from <table> where <something>".
12
+ */
13
+ export declare class DatabaseCountChecker {
14
+ readonly credentialsFunction: () => Promise<void>;
15
+ readonly checks: DatabaseCheck<Countable>[];
16
+ private constructor();
17
+ static createForProxy(): DatabaseCountChecker;
18
+ static createForRds(): DatabaseCountChecker;
19
+ /**
20
+ * Expect that the count is 1
21
+ */
22
+ expectOne(name: string, sql: string): this;
23
+ /**
24
+ * Expect that the count is 0
25
+ */
26
+ expectZero(name: string, sql: string): this;
27
+ /**
28
+ * Expect that the count is 1 or more
29
+ */
30
+ expectOneOrMore(name: string, sql: string): this;
31
+ expect(): Promise<string>;
32
+ }
33
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Construct } from "constructs";
2
+ import { CanaryParameters } from "./canary-parameters";
3
+ import { Role } from "aws-cdk-lib/aws-iam";
4
+ import { DigitrafficCanary } from "./canary";
5
+ import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
6
+ import { DigitrafficStack } from "../stack/stack";
7
+ import { DigitrafficRestApi } from "../stack/rest_apis";
8
+ export interface UrlCanaryParameters extends CanaryParameters {
9
+ readonly hostname: string;
10
+ readonly apiKeyId?: string;
11
+ }
12
+ export declare class UrlCanary extends DigitrafficCanary {
13
+ constructor(stack: Construct, role: Role, params: UrlCanaryParameters, secret?: ISecret);
14
+ static create(stack: DigitrafficStack, role: Role, publicApi: DigitrafficRestApi, params: Partial<UrlCanaryParameters>): UrlCanary;
15
+ static getApiKey(publicApi: DigitrafficRestApi): string | undefined;
16
+ }
@@ -0,0 +1,46 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from "http";
3
+ import { MediaType } from "../../types/mediatypes";
4
+ import { FeatureCollection } from "geojson";
5
+ export declare const API_KEY_HEADER = "x-api-key";
6
+ type CheckerFunction = (Res: IncomingMessage) => void;
7
+ type JsonCheckerFunction<T> = (json: T, body: string, message: IncomingMessage) => void;
8
+ export declare class UrlChecker {
9
+ private readonly requestOptions;
10
+ constructor(hostname: string, apiKey?: string);
11
+ static create(hostname: string, apiKeyId: string): Promise<UrlChecker>;
12
+ static createV2(): Promise<UrlChecker>;
13
+ expectStatus<T>(statusCode: number, url: string, callback: JsonCheckerFunction<T>): Promise<void>;
14
+ expect200<T>(url: string, ...callbacks: JsonCheckerFunction<T>[]): Promise<void>;
15
+ expect404(url: string): Promise<void>;
16
+ expect400(url: string): Promise<void>;
17
+ expect403WithoutApiKey(url: string, mediaType?: MediaType): Promise<void>;
18
+ done(): string;
19
+ }
20
+ export declare class ResponseChecker {
21
+ private readonly contentType;
22
+ private checkCors;
23
+ constructor(contentType: string);
24
+ static forJson(): ResponseChecker;
25
+ static forCSV(): ResponseChecker;
26
+ static forGeojson(): ResponseChecker;
27
+ static forJpeg(): ResponseChecker;
28
+ check(): CheckerFunction;
29
+ checkJson<T>(fn: (json: T, body: string, res: IncomingMessage) => void): CheckerFunction;
30
+ responseChecker(fn: (body: string, res: IncomingMessage) => void): CheckerFunction;
31
+ }
32
+ export declare class ContentChecker {
33
+ static checkJson<T>(fn: (json: T, body: string, res: IncomingMessage) => void): CheckerFunction;
34
+ static checkResponse(fn: (body: string, res: IncomingMessage) => void): CheckerFunction;
35
+ }
36
+ export declare class ContentTypeChecker {
37
+ static checkContentType(contentType: MediaType): (res: IncomingMessage) => void;
38
+ }
39
+ export declare class GeoJsonChecker {
40
+ static validFeatureCollection(fn?: (json: FeatureCollection) => void): CheckerFunction;
41
+ }
42
+ export declare class HeaderChecker {
43
+ static checkHeaderExists(headerName: string): CheckerFunction;
44
+ static checkHeaderMissing(headerName: string): CheckerFunction;
45
+ }
46
+ export {};
@@ -0,0 +1,56 @@
1
+ import { Construct } from "constructs";
2
+ import { Resource } from "aws-cdk-lib/aws-apigateway";
3
+ /**
4
+ * Add description to a query parameter
5
+ * @param name query parameter name
6
+ * @param description query parameter description
7
+ * @param resource REST API resource
8
+ * @param stack CloudFormation stack
9
+ *
10
+ * @deprecated Use DigitrafficRestApi.documentResource
11
+ */
12
+ export declare function addQueryParameterDescription(name: string, description: string, resource: Resource, stack: Construct): void;
13
+ /**
14
+ * Add a documentation part to a method
15
+ * @param methodDescription
16
+ * @param documentationProperties
17
+ * @param resource REST API resource
18
+ * @param stack CloudFormation stack
19
+ */
20
+ export declare function addDocumentation(methodDescription: string, documentationProperties: object, resource: Resource, stack: Construct): void;
21
+ /**
22
+ * Adds OpenAPI tags to an API method
23
+ * @param methodDescription Description of API method
24
+ * @param tags OpenAPI tags
25
+ * @param resource REST API resource
26
+ * @param stack CloudFormation stack
27
+ */
28
+ export declare function addTags(methodDescription: string, tags: string[], resource: Resource, stack: Construct): void;
29
+ /**
30
+ * Adds OpenAPI tags and a method summary to an API method
31
+ *
32
+ * @deprecated Use DigitrafficRestApi.documentResource
33
+ *
34
+ * @param methodDescription Description of API method
35
+ * @param tags OpenAPI tags
36
+ * @param summary OpenAPI summary
37
+ * @param resource REST API resource
38
+ * @param stack CloudFormation stack
39
+ */
40
+ export declare function addTagsAndSummary(methodDescription: string, tags: string[], summary: string, resource: Resource, stack: Construct): void;
41
+ export interface DocumentationProperties {
42
+ description?: string;
43
+ tags?: string[];
44
+ summary?: string;
45
+ deprecated?: boolean;
46
+ }
47
+ export declare class DocumentationPart {
48
+ readonly parameterName: string;
49
+ readonly type: string;
50
+ readonly documentationProperties: DocumentationProperties;
51
+ private constructor();
52
+ deprecated(note: string): DocumentationPart;
53
+ static queryParameter(parameterName: string, description: string): DocumentationPart;
54
+ static pathParameter(parameterName: string, description: string): DocumentationPart;
55
+ static method(tags: string[], name: string, summary: string): DocumentationPart;
56
+ }
@@ -0,0 +1,21 @@
1
+ import { IVpc } from "aws-cdk-lib/aws-ec2";
2
+ import { Stack } from "aws-cdk-lib";
3
+ import { Construct } from "constructs";
4
+ export declare class OldStackImports {
5
+ static AURORAINSTANCE_SG_IMPORT_NAME: string;
6
+ static RDSPROXY_SG_IMPORT_NAME: string;
7
+ }
8
+ /**
9
+ * Import VPC from other stack outputs
10
+ */
11
+ export declare function importVpc(scope: Construct, environmentName: string): IVpc;
12
+ /**
13
+ * Import value from other stack output. Stack outputs are named with
14
+ * digitraffic-${environmentName}-${name} pattern and this function takes care of it
15
+ */
16
+ export declare function importValue(environmentName: string, name: string): string;
17
+ /**
18
+ * Export value as stack output. Use same naming pattern as importValue.
19
+ */
20
+ export declare function exportValue(stack: Stack, environmentName: string, name: string, value: string): void;
21
+ export declare function outputName(environmentName: string, name: string): string;
@@ -0,0 +1,12 @@
1
+ import { Rule, Schedule } from "aws-cdk-lib/aws-events";
2
+ import { Duration } from "aws-cdk-lib";
3
+ import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
4
+ import { Construct } from "constructs";
5
+ export declare class Scheduler extends Rule {
6
+ constructor(stack: Construct, ruleName: string, schedule: Schedule, lambda?: AWSFunction);
7
+ static everyMinute(stack: Construct, ruleName: string, lambda?: AWSFunction): Scheduler;
8
+ static everyMinutes(stack: Construct, ruleName: string, minutes: number, lambda?: AWSFunction): Scheduler;
9
+ static everyHour(stack: Construct, ruleName: string, lambda?: AWSFunction): Scheduler;
10
+ static everyDay(stack: Construct, ruleName: string, lambda?: AWSFunction): Scheduler;
11
+ static every(stack: Construct, ruleName: string, duration: Duration, lambda?: AWSFunction): Scheduler;
12
+ }
@@ -0,0 +1,12 @@
1
+ import { Construct } from "constructs";
2
+ import { Rule } from "aws-cdk-lib/aws-events";
3
+ import { ITopic } from "aws-cdk-lib/aws-sns";
4
+ /**
5
+ * Automatic rule for Security Hub. Send notification to given topic if the following conditions apply:
6
+ * * There is a finding with a status of NEW
7
+ * * It has severity of HIGH or CRITICAL
8
+ * * It is in a FAILED state
9
+ */
10
+ export declare class DigitrafficSecurityRule extends Rule {
11
+ constructor(scope: Construct, topic: ITopic);
12
+ }
@@ -0,0 +1,7 @@
1
+ import { RequestValidator, Resource } from "aws-cdk-lib/aws-apigateway";
2
+ import { Queue } from "aws-cdk-lib/aws-sqs";
3
+ import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
4
+ import { Construct } from "constructs";
5
+ export declare function attachQueueToApiGatewayResource(stack: Construct, queue: Queue, resource: Resource, requestValidator: RequestValidator, resourceName: string, apiKeyRequired: boolean, requestModels?: {
6
+ [param: string]: IModel;
7
+ }): void;
@@ -0,0 +1,16 @@
1
+ import { Queue, QueueProps } from "aws-cdk-lib/aws-sqs";
2
+ import { Construct } from "constructs";
3
+ import { DigitrafficStack } from "./stack/stack";
4
+ /**
5
+ * Construct for creating SQS-queues.
6
+ *
7
+ * If you don't config your own deadLetterQueue, this will create a dlq for you, also a lambda function, a s3 bucket
8
+ * and an alarm for the queue. Anything that goes to the dlq will be written into the bucket and the alarm is activated.
9
+ */
10
+ export declare class DigitrafficSqsQueue extends Queue {
11
+ constructor(scope: Construct, name: string, props: QueueProps);
12
+ static create(stack: DigitrafficStack, name: string, props: QueueProps): DigitrafficSqsQueue;
13
+ }
14
+ export declare class DigitrafficDLQueue {
15
+ static create(stack: DigitrafficStack, name: string): DigitrafficSqsQueue;
16
+ }
@@ -0,0 +1,64 @@
1
+ import { Architecture, Code, FunctionProps, Runtime } from "aws-cdk-lib/aws-lambda";
2
+ import { ISecurityGroup, IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
3
+ import { Role } from "aws-cdk-lib/aws-iam";
4
+ import { DigitrafficStack } from "./stack";
5
+ import { MonitoredFunctionAlarmProps } from "./monitoredfunction";
6
+ export type LambdaEnvironment = Record<string, string>;
7
+ export type DBLambdaEnvironment = LambdaEnvironment & {
8
+ SECRET_ID?: string;
9
+ DB_APPLICATION: string;
10
+ };
11
+ export interface LambdaConfiguration {
12
+ vpcId: string;
13
+ allowFromIpAddresses?: string[];
14
+ privateSubnetIds: string[];
15
+ availabilityZones: string[];
16
+ lambdaDbSgId: string;
17
+ dbProps?: DbProps;
18
+ defaultLambdaDurationSeconds?: number;
19
+ logsDestinationArn: string;
20
+ memorySize?: number;
21
+ runtime?: Runtime;
22
+ }
23
+ declare interface DbProps {
24
+ username: string;
25
+ password: string;
26
+ uri?: string;
27
+ ro_uri?: string;
28
+ }
29
+ export declare function databaseFunctionProps(stack: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, config?: Partial<FunctionParameters>): FunctionProps;
30
+ export declare function lambdaFunctionProps(stack: DigitrafficStack, environment: LambdaEnvironment, lambdaName: string, simpleLambdaName: string, config?: Partial<FunctionParameters>): FunctionProps;
31
+ /**
32
+ * Creates a base configuration for a Lambda that uses an RDS database
33
+ * @param vpc "Private" Lambdas are associated with a VPC
34
+ * @param lambdaDbSg Security Group shared by Lambda and RDS
35
+ * @param props Database connection properties for the Lambda
36
+ * @param config Lambda configuration
37
+ */
38
+ export declare function dbLambdaConfiguration(vpc: IVpc, lambdaDbSg: ISecurityGroup, props: LambdaConfiguration, config: FunctionParameters): FunctionProps;
39
+ export declare function defaultLambdaConfiguration(config: FunctionParameters): FunctionProps;
40
+ export interface FunctionParameters {
41
+ memorySize?: number;
42
+ timeout?: number;
43
+ functionName?: string;
44
+ code: Code;
45
+ handler: string;
46
+ readOnly?: boolean;
47
+ environment?: {
48
+ [key: string]: string;
49
+ };
50
+ reservedConcurrentExecutions?: number;
51
+ role?: Role;
52
+ vpc?: IVpc;
53
+ vpcSubnets?: SubnetSelection;
54
+ runtime?: Runtime;
55
+ architecture?: Architecture;
56
+ singleLambda?: boolean;
57
+ }
58
+ export type MonitoredFunctionParameters = FunctionParameters & {
59
+ readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
60
+ readonly durationWarningProps?: MonitoredFunctionAlarmProps;
61
+ readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
62
+ readonly throttleAlarmProps?: MonitoredFunctionAlarmProps;
63
+ };
64
+ export {};
@@ -0,0 +1,84 @@
1
+ import { Function, FunctionProps } from "aws-cdk-lib/aws-lambda";
2
+ import { Stack } from "aws-cdk-lib";
3
+ import { ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
4
+ import { DigitrafficStack } from "../stack/stack";
5
+ import { ITopic } from "aws-cdk-lib/aws-sns";
6
+ import { LambdaEnvironment, MonitoredFunctionParameters } from "../stack/lambda-configs";
7
+ import { TrafficType } from "../../../types/traffictype";
8
+ /**
9
+ * Allows customization of CloudWatch Alarm properties
10
+ */
11
+ export type MonitoredFunctionAlarmProps = {
12
+ /**
13
+ * Setting this to false will not create a CloudWatch alarm
14
+ */
15
+ readonly create: boolean;
16
+ readonly threshold?: number;
17
+ readonly evaluationPeriods?: number;
18
+ readonly datapointsToAlarm?: number;
19
+ readonly comparisonOperator?: ComparisonOperator;
20
+ };
21
+ export type MonitoredFunctionProps = {
22
+ readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
23
+ readonly durationWarningProps?: MonitoredFunctionAlarmProps;
24
+ readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
25
+ readonly throttleAlarmProps?: MonitoredFunctionAlarmProps;
26
+ };
27
+ /**
28
+ * Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
29
+ */
30
+ export declare class MonitoredFunction extends Function {
31
+ readonly givenName: string;
32
+ /** disable all alarms */
33
+ static readonly DISABLE_ALARMS: MonitoredFunctionProps;
34
+ /**
35
+ * Create new MonitoredFunction. Use topics from given DigitrafficStack.
36
+ *
37
+ * @param stack DigitrafficStack
38
+ * @param id Lambda construct Id
39
+ * @param functionProps Lambda function properties
40
+ * @param props Monitored function properties
41
+ */
42
+ static create(stack: DigitrafficStack, id: string, functionProps: FunctionProps, props?: Partial<MonitoredFunctionProps>): MonitoredFunction;
43
+ /**
44
+ * Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
45
+ *
46
+ * For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
47
+ *
48
+ * @param stack DigitrafficStack
49
+ * @param name param-case name
50
+ * @param environment Lambda environment
51
+ * @param functionParameters Lambda function parameters
52
+ */
53
+ static createV2(stack: DigitrafficStack, name: string, environment: LambdaEnvironment, functionParameters?: Partial<MonitoredFunctionParameters>): MonitoredFunction;
54
+ /**
55
+ * @param scope Stack
56
+ * @param id Lambda construct Id
57
+ * @param functionProps Lambda function properties
58
+ * @param alarmSnsTopic SNS topic for alarms
59
+ * @param warningSnsTopic SNS topic for warnings
60
+ * @param production Is the stack a production stack, used for determining the alarm topic
61
+ * @param trafficType Traffic type, used for alarm names. Set to null if Lambda is not related to any traffic type.
62
+ * @param props Monitored function properties
63
+ */
64
+ constructor(scope: Stack, id: string, functionProps: FunctionProps, alarmSnsTopic: ITopic, warningSnsTopic: ITopic, production: boolean, trafficType: TrafficType | null, props?: MonitoredFunctionProps);
65
+ private createAlarm;
66
+ private getAlarmActionForEnv;
67
+ }
68
+ export declare class MonitoredDBFunction {
69
+ /**
70
+ * Create new MonitoredDBFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
71
+ * Grant secret and create log subscription.
72
+ *
73
+ * For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
74
+ *
75
+ * If you don't need to pass any extra arguments to lambda-environment, you can leave environment out and this function will create the
76
+ * default Lambda Environment with SECRET_ID and DB_APPLICATION.
77
+ *
78
+ * @param stack DigitrafficStack
79
+ * @param name param-case name
80
+ * @param environment Lambda environment
81
+ * @param functionParameters Lambda function parameters
82
+ */
83
+ static create(stack: DigitrafficStack, name: string, environment?: LambdaEnvironment, functionParameters?: Partial<MonitoredFunctionParameters>): MonitoredFunction;
84
+ }
@@ -0,0 +1,41 @@
1
+ import { RestApi, RestApiProps, JsonSchema, Resource } from "aws-cdk-lib/aws-apigateway";
2
+ import { PolicyDocument } from "aws-cdk-lib/aws-iam";
3
+ import { Construct } from "constructs";
4
+ import { DigitrafficStack } from "./stack";
5
+ import { ModelWithReference } from "../../types/model-with-reference";
6
+ import { DocumentationPart } from "../documentation";
7
+ export declare class DigitrafficRestApi extends RestApi {
8
+ readonly apiKeyIds: string[];
9
+ readonly enableDocumentation: boolean;
10
+ constructor(stack: DigitrafficStack, apiId: string, apiName: string, allowFromIpAddresses?: string[] | undefined, config?: Partial<RestApiProps>);
11
+ hostname(): string;
12
+ createUsagePlan(apiKeyId: string, apiKeyName: string): string;
13
+ createUsagePlanV2(apiName: string, apiKey?: string): string;
14
+ addJsonModel(modelName: string, schema: JsonSchema): ModelWithReference;
15
+ addCSVModel(modelName: string): ModelWithReference;
16
+ private getModelWithReference;
17
+ private addDocumentationPart;
18
+ documentResource(resource: Resource, ...documentationPart: DocumentationPart[]): void;
19
+ }
20
+ /**
21
+ * Due to AWS API design API Gateway will always return 403 'Missing Authentication Token' for requests
22
+ * with a non-existent endpoint. This function translates this response to a 404.
23
+ * Requests with an invalid or missing API key are not affected (still return 403 'Forbidden').
24
+ * @param restApi RestApi
25
+ * @param stack Construct
26
+ */
27
+ export declare function add404Support(restApi: RestApi, stack: Construct): void;
28
+ export declare function add401Support(restApi: RestApi, stack: Construct): void;
29
+ /**
30
+ * Due to AWS API design API Gateway will always return 403 'Missing Authentication Token' for requests
31
+ * with a non-existent endpoint. This function converts this response to a custom one.
32
+ * Requests with an invalid or missing API key are not affected (still return 403 'Forbidden').
33
+ * @param returnCode
34
+ * @param message
35
+ * @param restApi RestApi
36
+ * @param stack Construct
37
+ */
38
+ export declare function setReturnCodeForMissingAuthenticationToken(returnCode: number, message: string, restApi: RestApi, stack: Construct): void;
39
+ export declare function createRestApi(stack: Construct, apiId: string, apiName: string, allowFromIpAddresses?: string[] | undefined): RestApi;
40
+ export declare function createDefaultPolicyDocument(): PolicyDocument;
41
+ export declare function createIpRestrictionPolicyDocument(allowFromIpAddresses: string[]): PolicyDocument;
@@ -0,0 +1,21 @@
1
+ import { IAspect } from "aws-cdk-lib";
2
+ import { DigitrafficStack } from "./stack";
3
+ import { IConstruct } from "constructs";
4
+ export declare class StackCheckingAspect implements IAspect {
5
+ private readonly stackShortName?;
6
+ private readonly whitelistedResources?;
7
+ constructor(stackShortName?: string, whitelistedResources?: string[]);
8
+ static create(stack: DigitrafficStack): StackCheckingAspect;
9
+ visit(node: IConstruct): void;
10
+ private isWhitelisted;
11
+ private addAnnotation;
12
+ private checkStack;
13
+ private checkFunction;
14
+ private checkTags;
15
+ private checkBucket;
16
+ private static isValidPath;
17
+ private static isValidQueryString;
18
+ private checkResourceCasing;
19
+ private checkQueueEncryption;
20
+ private checkLogGroupRetention;
21
+ }