@digitraffic/common 2022.11.23-2 → 2022.11.23-4

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.
@@ -1,7 +1,7 @@
1
1
  import { IntegrationResponse, LambdaIntegration } from "aws-cdk-lib/aws-apigateway";
2
2
  import { IFunction } from "aws-cdk-lib/aws-lambda";
3
3
  import { MediaType } from "../../types/mediatypes";
4
- declare type ParameterType = "path" | "querystring";
4
+ type ParameterType = "path" | "querystring";
5
5
  interface ApiParameter {
6
6
  type: ParameterType;
7
7
  name: string;
@@ -1,7 +1,7 @@
1
1
  import { Schedule } from "@aws-cdk/aws-synthetics-alpha";
2
2
  /** Optional env parameters for canary */
3
- declare type CanaryEnv = Record<string, string>;
4
- export declare type CanaryParameters = {
3
+ type CanaryEnv = Record<string, string>;
4
+ export type CanaryParameters = {
5
5
  readonly name: string;
6
6
  readonly schedule?: Schedule;
7
7
  readonly secret?: string;
@@ -3,8 +3,8 @@ import { IncomingMessage } from "http";
3
3
  import { MediaType } from "../../types/mediatypes";
4
4
  import { FeatureCollection } from "geojson";
5
5
  export declare const API_KEY_HEADER = "x-api-key";
6
- declare type CheckerFunction = (Res: IncomingMessage) => void;
7
- declare type JsonCheckerFunction<T> = (json: T, body: string, message: IncomingMessage) => void;
6
+ type CheckerFunction = (Res: IncomingMessage) => void;
7
+ type JsonCheckerFunction<T> = (json: T, body: string, message: IncomingMessage) => void;
8
8
  export declare class UrlChecker {
9
9
  private readonly requestOptions;
10
10
  constructor(hostname: string, apiKey?: string);
@@ -3,8 +3,8 @@ import { ISecurityGroup, IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
3
3
  import { Role } from "aws-cdk-lib/aws-iam";
4
4
  import { DigitrafficStack } from "./stack";
5
5
  import { MonitoredFunctionAlarmProps } from "./monitoredfunction";
6
- export declare type LambdaEnvironment = Record<string, string>;
7
- export declare type DBLambdaEnvironment = LambdaEnvironment & {
6
+ export type LambdaEnvironment = Record<string, string>;
7
+ export type DBLambdaEnvironment = LambdaEnvironment & {
8
8
  SECRET_ID?: string;
9
9
  DB_APPLICATION: string;
10
10
  };
@@ -55,7 +55,7 @@ export interface FunctionParameters {
55
55
  architecture?: Architecture;
56
56
  singleLambda?: boolean;
57
57
  }
58
- export declare type MonitoredFunctionParameters = FunctionParameters & {
58
+ export type MonitoredFunctionParameters = FunctionParameters & {
59
59
  readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
60
60
  readonly durationWarningProps?: MonitoredFunctionAlarmProps;
61
61
  readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
@@ -8,7 +8,7 @@ import { TrafficType } from "../../../types/traffictype";
8
8
  /**
9
9
  * Allows customization of CloudWatch Alarm properties
10
10
  */
11
- export declare type MonitoredFunctionAlarmProps = {
11
+ export type MonitoredFunctionAlarmProps = {
12
12
  /**
13
13
  * Setting this to false will not create a CloudWatch alarm
14
14
  */
@@ -18,7 +18,7 @@ export declare type MonitoredFunctionAlarmProps = {
18
18
  readonly datapointsToAlarm?: number;
19
19
  readonly comparisonOperator?: ComparisonOperator;
20
20
  };
21
- export declare type MonitoredFunctionProps = {
21
+ export type MonitoredFunctionProps = {
22
22
  readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
23
23
  readonly durationWarningProps?: MonitoredFunctionAlarmProps;
24
24
  readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
@@ -11,6 +11,37 @@ const subscription_1 = require("../stack/subscription");
11
11
  * Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
12
12
  */
13
13
  class MonitoredFunction extends aws_lambda_1.Function {
14
+ /**
15
+ * Create new MonitoredFunction. Use topics from given DigitrafficStack.
16
+ *
17
+ * @param stack DigitrafficStack
18
+ * @param id Lambda construct Id
19
+ * @param functionProps Lambda function properties
20
+ * @param props Monitored function properties
21
+ */
22
+ static create(stack, id, functionProps, props) {
23
+ if (props === MonitoredFunction.DISABLE_ALARMS &&
24
+ stack.configuration.production) {
25
+ throw new Error(`Function ${functionProps.functionName} has DISABLE_ALARMS. Remove before installing to production or define your own properties!`);
26
+ }
27
+ return new MonitoredFunction(stack, id, functionProps, stack.alarmTopic, stack.warningTopic, stack.configuration.production, stack.configuration.trafficType, props);
28
+ }
29
+ /**
30
+ * Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
31
+ *
32
+ * 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.
33
+ *
34
+ * @param stack DigitrafficStack
35
+ * @param name param-case name
36
+ * @param environment Lambda environment
37
+ * @param functionParameters Lambda function parameters
38
+ */
39
+ static createV2(stack, name, environment, functionParameters) {
40
+ const functionName = functionParameters?.functionName ||
41
+ `${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
42
+ const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
43
+ return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
44
+ }
14
45
  /**
15
46
  * @param scope Stack
16
47
  * @param id Lambda construct Id
@@ -48,37 +79,6 @@ class MonitoredFunction extends aws_lambda_1.Function {
48
79
  this.createAlarm(scope, this.metricThrottles(), "Throttles", "Throttles alarm", "Has throttled", trafficType, this.getAlarmActionForEnv(alarmSnsAction, warningSnsAction, production), 0, 1, 1, aws_cloudwatch_1.ComparisonOperator.GREATER_THAN_THRESHOLD, props?.throttleAlarmProps);
49
80
  }
50
81
  }
51
- /**
52
- * Create new MonitoredFunction. Use topics from given DigitrafficStack.
53
- *
54
- * @param stack DigitrafficStack
55
- * @param id Lambda construct Id
56
- * @param functionProps Lambda function properties
57
- * @param props Monitored function properties
58
- */
59
- static create(stack, id, functionProps, props) {
60
- if (props === MonitoredFunction.DISABLE_ALARMS &&
61
- stack.configuration.production) {
62
- throw new Error(`Function ${functionProps.functionName} has DISABLE_ALARMS. Remove before installing to production or define your own properties!`);
63
- }
64
- return new MonitoredFunction(stack, id, functionProps, stack.alarmTopic, stack.warningTopic, stack.configuration.production, stack.configuration.trafficType, props);
65
- }
66
- /**
67
- * Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
68
- *
69
- * 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.
70
- *
71
- * @param stack DigitrafficStack
72
- * @param name param-case name
73
- * @param environment Lambda environment
74
- * @param functionParameters Lambda function parameters
75
- */
76
- static createV2(stack, name, environment, functionParameters) {
77
- const functionName = functionParameters?.functionName ||
78
- `${stack.configuration.shortName}-${(0, change_case_1.pascalCase)(name)}`;
79
- const functionProps = (0, lambda_configs_1.databaseFunctionProps)(stack, environment, functionName, name, functionParameters);
80
- return MonitoredFunction.create(stack, functionName, functionProps, functionParameters);
81
- }
82
82
  createAlarm(stack, metric, alarmId, alarmName, alarmDescription, trafficType, alarmSnsAction, threshold, evaluationPeriods, datapointsToAlarm, comparisonOperator, alarmProps) {
83
83
  metric
84
84
  .createAlarm(stack, `${this.node.id}-${alarmId}`, {
@@ -1 +1 @@
1
- {"version":3,"file":"monitoredfunction.js","sourceRoot":"","sources":["../../../../src/aws/infra/stack/monitoredfunction.ts"],"names":[],"mappings":";;;AAAA,uDAAiE;AAEjE,+EAA+D;AAC/D,+DAAwE;AAGxE,4DAIiC;AACjC,6CAAyC;AACzC,wDAAoE;AA+BpE;;GAEG;AACH,MAAa,iBAAkB,SAAQ,qBAAQ;IAyF3C;;;;;;;;;OASG;IACH,YACI,KAAY,EACZ,EAAU,EACV,aAA4B,EAC5B,aAAqB,EACrB,eAAuB,EACvB,UAAmB,EACnB,WAA+B,EAC/B,KAA8B;QAE9B,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;QAEhC,IAAI,aAAa,CAAC,YAAY,KAAK,SAAS,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SACjD;QACD,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC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;;AApPL,8CAqPC;AAlPG,yBAAyB;AACF,gCAAc,GAA2B;IAC5D,kBAAkB,EAAE;QAChB,MAAM,EAAE,KAAK;KAChB;IACD,oBAAoB,EAAE;QAClB,MAAM,EAAE,KAAK;KAChB;IACD,eAAe,EAAE;QACb,MAAM,EAAE,KAAK;KAChB;IACD,kBAAkB,EAAE;QAChB,MAAM,EAAE,KAAK;KAChB;CACJ,CAAC;AAsON,MAAa,mBAAmB;IAC5B;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,MAAM,CACT,KAAuB,EACvB,IAAY,EACZ,WAA+B,EAC/B,kBAAyD;QAEzD,MAAM,YAAY,GACd,kBAAkB,EAAE,YAAY;YAChC,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,IAAI,IAAA,wBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;QAC3D,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC;QACxE,MAAM,aAAa,GAAG,IAAA,sCAAqB,EACvC,KAAK,EACL,GAAG,EACH,YAAY,EACZ,IAAI,EACJ,kBAAkB,CACrB,CAAC;QAEF,MAAM,EAAE,GAAG,iBAAiB,CAAC,MAAM,CAC/B,KAAK,EACL,YAAY,EACZ,aAAa,EACb,kBAAkB,CACrB,CAAC;QAEF,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAEtB,IAAI,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;YACxC,IAAI,0CAA2B,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SAC9C;QAED,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAhDD,kDAgDC"}
1
+ {"version":3,"file":"monitoredfunction.js","sourceRoot":"","sources":["../../../../src/aws/infra/stack/monitoredfunction.ts"],"names":[],"mappings":";;;AAAA,uDAAiE;AAEjE,+EAA+D;AAC/D,+DAAwE;AAGxE,4DAIiC;AACjC,6CAAyC;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b,kBAAkB,CACrB,CAAC;QAEF,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAEtB,IAAI,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;YACxC,IAAI,0CAA2B,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SAC9C;QAED,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAhDD,kDAgDC"}
@@ -1,4 +1,5 @@
1
- export declare type DbSecret = {
1
+ import { GenericSecret } from "./secret";
2
+ export type DbSecret = {
2
3
  readonly username: string;
3
4
  readonly password: string;
4
5
  readonly host: string;
@@ -16,8 +17,8 @@ export declare enum RdsSecretKey {
16
17
  host = "host",
17
18
  ro_host = "ro_host"
18
19
  }
19
- export declare type RdsProxySecret = Record<RdsProxySecretKey, string>;
20
- export declare type RdsSecret = Record<RdsSecretKey, string>;
20
+ export type RdsProxySecret = Record<RdsProxySecretKey, string>;
21
+ export type RdsSecret = Record<RdsSecretKey, string>;
21
22
  export declare enum DatabaseEnvironmentKeys {
22
23
  DB_USER = "DB_USER",
23
24
  DB_PASS = "DB_PASS",
@@ -33,13 +34,13 @@ export declare enum DatabaseEnvironmentKeys {
33
34
  * The secret that is passed to the given function will not include the prefix in it's keys.
34
35
 
35
36
  */
36
- export declare type SecretOptions = {
37
+ export type SecretOptions = {
37
38
  readonly expectedKeys?: string[];
38
39
  readonly prefix?: string;
39
40
  };
40
- export declare type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
41
- export declare type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
42
- export declare type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
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>;
43
44
  /**
44
45
  * Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
45
46
  *
@@ -51,4 +52,4 @@ export declare type EmptySecretFunction<Response = void> = SecretFunction<DbSecr
51
52
  * @param {SecretOptions} options
52
53
  */
53
54
  export declare function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void>;
54
- export declare function checkExpectedSecretKeys<Secret>(keys: string[], secret: Secret): void;
55
+ export declare function checkExpectedSecretKeys<Secret extends GenericSecret>(keys: string[], secret: Secret): void;
@@ -33,7 +33,7 @@ function setDbSecret(secret) {
33
33
  // cached at Lambda container level
34
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
35
  let cachedSecret;
36
- const missingSecretErrorText = 'Missing or empty secretId';
36
+ const missingSecretErrorText = "Missing or empty secretId";
37
37
  /**
38
38
  * Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
39
39
  *
@@ -75,7 +75,7 @@ async function withDbSecret(secretId, fn, options) {
75
75
  return fn(cachedSecret);
76
76
  }
77
77
  catch (error) {
78
- console.error('method=withDbSecret Caught an error, refreshing secret', error);
78
+ console.error("method=withDbSecret Caught an error, refreshing secret", error);
79
79
  // try to refetch secret in case it has changed
80
80
  await (0, secret_1.withSecret)(secretId, (fetchedSecret) => {
81
81
  setDbSecret(fetchedSecret);
@@ -86,10 +86,10 @@ async function withDbSecret(secretId, fn, options) {
86
86
  }
87
87
  exports.withDbSecret = withDbSecret;
88
88
  function checkExpectedSecretKeys(keys, secret) {
89
- const missingKeys = keys.filter(key => !(key in secret));
89
+ const missingKeys = keys.filter((key) => !(key in secret));
90
90
  if (missingKeys.length) {
91
91
  console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
92
- throw new Error('Expected keys were not found');
92
+ throw new Error("Expected keys were not found");
93
93
  }
94
94
  }
95
95
  exports.checkExpectedSecretKeys = checkExpect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CAAC,CAAC;SAC/D;QACD,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;KAC3B;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CACT,wDAAwD,EACxD,KAAK,CACR,CAAC;QACF,+CAA+C;QAC/C,MAAM,IAAA,mBAAU,EAAC,QAAQ,EAAE,CAAC,aAAuB,EAAE,EAAE;YACnD,WAAW,CAAC,aAAa,CAAC,CAAC;YAC3B,YAAY,GAAG,aAAa,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC;KAC3B;AACL,CAAC;AAlDD,oCAkDC;AAED,SAAgB,uBAAuB,CACnC,IAAc,EACd,MAAc;IAEd,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC;IAC3D,IAAI,WAAW,CAAC,MAAM,EAAE;QACpB,OAAO,CAAC,KAAK,CACT,mEAAmE,WAAW,EAAE,CACnF,CAAC;QACF,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACnD;AACL,CAAC;AAXD,0DAWC"}
@@ -1,3 +1,4 @@
1
+ import { GenericSecret } from "./secret";
1
2
  /**
2
3
  * Utility class for getting secrets from Secret Manager.
3
4
  * Supports prefix for secrets, checking of expected keys and ttl-configuration.
@@ -6,7 +7,7 @@
6
7
  *
7
8
  * Supports setting the database environment paramaters from the secret too.
8
9
  */
9
- export declare class SecretHolder<Secret> {
10
+ export declare class SecretHolder<Secret extends GenericSecret> {
10
11
  private readonly secretId;
11
12
  private readonly prefix;
12
13
  private readonly expectedKeys;
@@ -15,7 +16,7 @@ export declare class SecretHolder<Secret> {
15
16
  ttl: number;
16
17
  });
17
18
  private initSecret;
18
- static create<S>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
19
+ static create<S extends GenericSecret>(prefix?: string, expectedKeys?: string[]): SecretHolder<S>;
19
20
  get(): Promise<Secret>;
20
21
  private parseSecret;
21
22
  private getSecret;
@@ -1 +1 @@
1
- {"version":3,"file":"secret-holder.js","sourceRoot":"","sources":["../../../../src/aws/runtime/secrets/secret-holder.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AACpD,yCAIoB;AACpB,gDAAsD;AAEtD,8DAA8D;AAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEpC,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AACpC,MAAM,qBAAqB,GAAG;IAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,+BAA+B;CAC/C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAa,YAAY;IAOrB,YACI,QAAgB,EAChB,MAAM,GAAG,EAAE,EACX,eAAyB,EAAE,EAC3B,aAAa,GAAG,qBAAqB;QAErC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,IAAI,CAAC,WAAW,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,UAAU;QACpB,MAAM,WAAW,GAAG,MAAM,IAAA,kBAAS,EAAS,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE3D,OAAO,CAAC,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAEM,MAAM,CAAC,MAAM,CAChB,MAAM,GAAG,cAAc,EACvB,eAAyB,EAAE;QAE3B,OAAO,IAAI,YAAY,CACnB,IAAA,sBAAc,EAAC,WAAW,CAAC,EAC3B,MAAM,EACN,YAAY,CACf,CAAC;IACN,CAAC;IAEM,K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,OAAO,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,sBAAsB;QAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAY,CAAC;QAEhD,OAAO,CAAC,GAAG,CAAC,kCAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,kCAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,kCAAuB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;QAC1D,OAAO,CAAC,GAAG,CAAC,kCAAuB,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;IACpE,CAAC;CACJ;AAvFD,oCAuFC"}
@@ -1,5 +1,5 @@
1
1
  import { SecretToPromiseFunction } from "./dbsecret";
2
- export declare type GenericSecret = Record<string, string>;
2
+ export type GenericSecret = Record<string, string>;
3
3
  /**
4
4
  @deprecated use SecretHolder & ProxyHolder
5
5
  */
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Not fully described, extend if necessary.
5
5
  */
6
- export declare type ProxyLambdaResponse = {
6
+ export type ProxyLambdaResponse = {
7
7
  readonly statusCode: number;
8
8
  readonly body: string;
9
9
  readonly headers?: Record<string, string>;
@@ -14,7 +14,7 @@ export declare type ProxyLambdaResponse = {
14
14
  *
15
15
  * Not fully described, extend if necessary.
16
16
  */
17
- export declare type ProxyLambdaRequest = {
17
+ export type ProxyLambdaRequest = {
18
18
  readonly resource: string;
19
19
  readonly path: string;
20
20
  readonly httpMethod: string;
@@ -1,6 +1,6 @@
1
1
  import { IDatabase, ITask } from "pg-promise";
2
- export declare type DTDatabase = IDatabase<unknown>;
3
- export declare type DTTransaction = ITask<unknown>;
2
+ export type DTDatabase = IDatabase<unknown>;
3
+ export type DTTransaction = ITask<unknown>;
4
4
  /**
5
5
  * Creates a non-pooling database connection primarily used by Lambdas.
6
6
  *
@@ -1,16 +1,16 @@
1
- export declare type RtzPositionCoordinate = {
1
+ export type RtzPositionCoordinate = {
2
2
  readonly $: {
3
3
  readonly lat: number;
4
4
  readonly lon: number;
5
5
  };
6
6
  };
7
- export declare type RtzWaypointPosition = {
7
+ export type RtzWaypointPosition = {
8
8
  readonly position: RtzPositionCoordinate[];
9
9
  };
10
- export declare type RtzWaypoint = {
10
+ export type RtzWaypoint = {
11
11
  readonly waypoint: RtzWaypointPosition[];
12
12
  };
13
- export declare type RtzScheduleElement = {
13
+ export type RtzScheduleElement = {
14
14
  readonly $: {
15
15
  /**
16
16
  * Date
@@ -22,27 +22,27 @@ export declare type RtzScheduleElement = {
22
22
  readonly eta?: string;
23
23
  };
24
24
  };
25
- export declare type RtzSchedule = {
25
+ export type RtzSchedule = {
26
26
  readonly scheduleElement: RtzScheduleElement[];
27
27
  };
28
- export declare type RtzScheduleWrapper = {
28
+ export type RtzScheduleWrapper = {
29
29
  readonly manual?: RtzSchedule[];
30
30
  readonly calculated?: RtzSchedule[];
31
31
  };
32
- export declare type RtzSchedules = {
32
+ export type RtzSchedules = {
33
33
  readonly schedule: RtzScheduleWrapper[];
34
34
  };
35
- export declare type RtzRouteInfo = {
35
+ export type RtzRouteInfo = {
36
36
  readonly $: {
37
37
  readonly vesselMMSI: string;
38
38
  readonly vesselIMO: string;
39
39
  };
40
40
  };
41
- export declare type RtzRoute = {
41
+ export type RtzRoute = {
42
42
  readonly routeInfo: RtzRouteInfo[];
43
43
  readonly waypoints: RtzWaypoint[];
44
44
  readonly schedules: RtzSchedules[];
45
45
  };
46
- export declare type RtzVoyagePlan = {
46
+ export type RtzVoyagePlan = {
47
47
  readonly route: RtzRoute;
48
48
  };
@@ -1,9 +1,9 @@
1
- export declare type EitherOk<T> = {
1
+ export type EitherOk<T> = {
2
2
  result: "ok";
3
3
  value: T;
4
4
  };
5
- export declare type EitherError = {
5
+ export type EitherError = {
6
6
  result: "error";
7
7
  message: string;
8
8
  };
9
- export declare type Either<T> = EitherOk<T> | EitherError;
9
+ export type Either<T> = EitherOk<T> | EitherError;
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2022.11.23-2",
3
+ "version": "2022.11.23-4",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/tmfg/digitraffic-common.git"
8
8
  },
9
9
  "engines": {
10
- "node": ">=14 <17",
11
- "yarn": ">1.2 <2"
10
+ "node": ">=14 <17"
12
11
  },
13
12
  "scripts": {
14
13
  "build": "tsc",
@@ -17,49 +16,63 @@
17
16
  "clean": "rimraf dist output",
18
17
  "test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest",
19
18
  "prepare": "husky install",
20
- "prepublishOnly": "yarn clean && yarn build && yarn test"
19
+ "prepublishOnly": "pnpm clean && pnpm build && pnpm test"
21
20
  },
22
21
  "license": "EUPL-1.2",
23
22
  "private": false,
24
23
  "files": [
25
24
  "dist/**/*.js",
25
+ "dist/**/*.d.ts",
26
26
  "src/**/*.ts"
27
27
  ],
28
- "dependencies": {
29
- "@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
28
+ "peerDependencies": {
29
+ "@aws-cdk/aws-synthetics-alpha": "^2.50.0-alpha.0",
30
30
  "@types/geojson": "^7946.0.10",
31
- "aws-cdk-lib": "2.51.1",
32
- "aws-sdk": "2.1241.0",
31
+ "aws-cdk-lib": "^2.51.1",
32
+ "aws-sdk": "^2.1241.0",
33
33
  "axios": "^0.21.1",
34
- "change-case": "4.1.2",
35
- "constructs": "10.1.131",
34
+ "change-case": "^4.1.2",
35
+ "constructs": "^10.1.131",
36
36
  "geojson-validation": "^1.0.2",
37
37
  "moment": "^2.29.4",
38
38
  "node-ttl": "^0.2.0",
39
39
  "pg-native": "^3.0.1",
40
- "pg-promise": "^10.12.0"
40
+ "pg-promise": "^10.12.0",
41
+ "spex": "^3.0.0"
41
42
  },
42
43
  "devDependencies": {
44
+ "@aws-cdk/aws-synthetics-alpha": "2.50.0-alpha.0",
43
45
  "@types/aws-lambda": "^8.10.106",
46
+ "@types/geojson": "^7946.0.10",
44
47
  "@types/jest": "^29.0.3",
45
48
  "@types/node": "^18.7.23",
46
49
  "@types/ramda": "^0.28.15",
47
50
  "@types/sinon": "^10.0.13",
48
51
  "@typescript-eslint/eslint-plugin": "^5.39.0",
49
52
  "@typescript-eslint/parser": "^5.39.0",
53
+ "aws-cdk-lib": "^2.50.0",
54
+ "aws-sdk": "^2.1241.0",
55
+ "axios": "^0.21.1",
56
+ "change-case": "^4.1.2",
57
+ "constructs": "^10.1.131",
50
58
  "eslint": "^8.24.0",
51
59
  "eslint-config-prettier": "^8.5.0",
52
60
  "eslint-plugin-deprecation": "1.3.3",
61
+ "geojson-validation": "^1.0.2",
53
62
  "husky": ">=6",
54
63
  "jest": "^29.1.1",
55
64
  "jest-junit": "^14.0.1",
56
65
  "lint-staged": ">=10",
66
+ "moment": "^2.29.4",
67
+ "node-ttl": "^0.2.0",
68
+ "pg-native": "^3.0.1",
69
+ "pg-promise": "^10.12.0",
57
70
  "prettier": "^2.7.1",
58
71
  "ramda": "^0.28.0",
59
72
  "rimraf": "^3.0.2",
60
73
  "sinon": "^14.0.0",
61
74
  "ts-jest": "^29.0.3",
62
- "typescript": "^4.8.4"
75
+ "typescript": "^4.7.4"
63
76
  },
64
77
  "externals": [
65
78
  "aws-sdk",
@@ -1,18 +1,24 @@
1
- import {withSecret, withSecretAndPrefix} from "./secret";
1
+ import { GenericSecret, withSecret, withSecretAndPrefix } from "./secret";
2
2
 
3
3
  export type DbSecret = {
4
- readonly username: string
5
- readonly password: string
6
- readonly host: string
7
- readonly ro_host: string
4
+ readonly username: string;
5
+ readonly password: string;
6
+ readonly host: string;
7
+ readonly ro_host: string;
8
8
  };
9
9
 
10
10
  export enum RdsProxySecretKey {
11
- username = "username", password = "password", proxy_host = "proxy_host", proxy_ro_host = "proxy_ro_host"
11
+ username = "username",
12
+ password = "password",
13
+ proxy_host = "proxy_host",
14
+ proxy_ro_host = "proxy_ro_host",
12
15
  }
13
16
 
14
17
  export enum RdsSecretKey {
15
- username = "username", password = "password", host = "host", ro_host = "ro_host"
18
+ username = "username",
19
+ password = "password",
20
+ host = "host",
21
+ ro_host = "ro_host",
16
22
  }
17
23
 
18
24
  export type RdsProxySecret = Record<RdsProxySecretKey, string>;
@@ -37,7 +43,7 @@ function setDbSecret(secret: DbSecret) {
37
43
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
44
  let cachedSecret: any;
39
45
 
40
- const missingSecretErrorText = 'Missing or empty secretId';
46
+ const missingSecretErrorText = "Missing or empty secretId";
41
47
 
42
48
  /**
43
49
  * You can give the following options for retrieving a secret:
@@ -48,13 +54,22 @@ const missingSecretErrorText = 'Missing or empty secretId';
48
54
 
49
55
  */
50
56
  export type SecretOptions = {
51
- readonly expectedKeys?: string[],
52
- readonly prefix?: string
53
- }
57
+ readonly expectedKeys?: string[];
58
+ readonly prefix?: string;
59
+ };
54
60
 
55
- export type SecretToPromiseFunction<Secret, Response = void> = (secret: Secret) => Promise<Response> | void;
56
- export type SecretFunction<Secret, Response = void> = (secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions) => Promise<Response | void>;
57
- export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Response>;
61
+ export type SecretToPromiseFunction<Secret, Response = void> = (
62
+ secret: Secret
63
+ ) => Promise<Response> | void;
64
+ export type SecretFunction<Secret, Response = void> = (
65
+ secretId: string,
66
+ fn: SecretToPromiseFunction<Secret, Response>,
67
+ options?: SecretOptions
68
+ ) => Promise<Response | void>;
69
+ export type EmptySecretFunction<Response = void> = SecretFunction<
70
+ DbSecret,
71
+ Response
72
+ >;
58
73
 
59
74
  /**
60
75
  * Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
@@ -66,7 +81,11 @@ export type EmptySecretFunction<Response = void> = SecretFunction<DbSecret, Resp
66
81
  * @param {function} fn
67
82
  * @param {SecretOptions} options
68
83
  */
69
- export async function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void> {
84
+ export async function withDbSecret<Secret, Response>(
85
+ secretId: string,
86
+ fn: SecretToPromiseFunction<Secret, Response>,
87
+ options?: SecretOptions
88
+ ): Promise<Response | void> {
70
89
  if (!secretId) {
71
90
  console.error(missingSecretErrorText);
72
91
  return Promise.reject(missingSecretErrorText);
@@ -81,9 +100,13 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
81
100
  });
82
101
 
83
102
  // then actual secret
84
- await withSecretAndPrefix(secretId, options.prefix, (fetchedSecret: Secret) => {
85
- cachedSecret = fetchedSecret;
86
- });
103
+ await withSecretAndPrefix(
104
+ secretId,
105
+ options.prefix,
106
+ (fetchedSecret: Secret) => {
107
+ cachedSecret = fetchedSecret;
108
+ }
109
+ );
87
110
  } else {
88
111
  await withSecret(secretId, (fetchedSecret: DbSecret) => {
89
112
  setDbSecret(fetchedSecret);
@@ -97,7 +120,10 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
97
120
  }
98
121
  return fn(cachedSecret);
99
122
  } catch (error) {
100
- console.error('method=withDbSecret Caught an error, refreshing secret', error);
123
+ console.error(
124
+ "method=withDbSecret Caught an error, refreshing secret",
125
+ error
126
+ );
101
127
  // try to refetch secret in case it has changed
102
128
  await withSecret(secretId, (fetchedSecret: DbSecret) => {
103
129
  setDbSecret(fetchedSecret);
@@ -107,10 +133,15 @@ export async function withDbSecret<Secret, Response>(secretId: string, fn: Secre
107
133
  }
108
134
  }
109
135
 
110
- export function checkExpectedSecretKeys<Secret>(keys: string[], secret: Secret) {
111
- const missingKeys = keys.filter(key => !(key in secret));
136
+ export function checkExpectedSecretKeys<Secret extends GenericSecret>(
137
+ keys: string[],
138
+ secret: Secret
139
+ ) {
140
+ const missingKeys = keys.filter((key) => !(key in secret));
112
141
  if (missingKeys.length) {
113
- console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
114
- throw new Error('Expected keys were not found');
142
+ console.error(
143
+ `method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`
144
+ );
145
+ throw new Error("Expected keys were not found");
115
146
  }
116
147
  }
@@ -23,7 +23,7 @@ const DEFAULT_CONFIGURATION = {
23
23
  *
24
24
  * Supports setting the database environment paramaters from the secret too.
25
25
  */
26
- export class SecretHolder<Secret> {
26
+ export class SecretHolder<Secret extends GenericSecret> {
27
27
  private readonly secretId: string;
28
28
  private readonly prefix: string;
29
29
  private readonly expectedKeys: string[];
@@ -51,7 +51,7 @@ export class SecretHolder<Secret> {
51
51
  this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
52
52
  }
53
53
 
54
- public static create<S>(
54
+ public static create<S extends GenericSecret>(
55
55
  prefix = DEFAULT_PREFIX,
56
56
  expectedKeys: string[] = []
57
57
  ) {
@@ -67,10 +67,7 @@ export class SecretHolder<Secret> {
67
67
  const parsedSecret =
68
68
  this.prefix === DEFAULT_PREFIX
69
69
  ? secret
70
- : this.parseSecret(
71
- secret as unknown as GenericSecret,
72
- `${this.prefix}.`
73
- );
70
+ : this.parseSecret(secret, `${this.prefix}.`);
74
71
 
75
72
  if (this.expectedKeys.length > 0) {
76
73
  checkExpectedSecretKeys(this.expectedKeys, parsedSecret);