@digitraffic/common 2022.11.22-1 → 2022.11.23-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.
Files changed (158) hide show
  1. package/dist/aws/infra/api/integration.d.ts +21 -0
  2. package/dist/aws/infra/api/integration.js +8 -4
  3. package/dist/aws/infra/api/integration.js.map +1 -0
  4. package/dist/aws/infra/api/response.d.ts +28 -0
  5. package/dist/aws/infra/api/response.js +49 -18
  6. package/dist/aws/infra/api/response.js.map +1 -0
  7. package/dist/aws/infra/api/responses.d.ts +47 -0
  8. package/dist/aws/infra/api/responses.js +8 -0
  9. package/dist/aws/infra/api/responses.js.map +1 -0
  10. package/dist/aws/infra/api/static-integration.d.ts +15 -0
  11. package/dist/aws/infra/api/static-integration.js +12 -6
  12. package/dist/aws/infra/api/static-integration.js.map +1 -0
  13. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  14. package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
  15. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  16. package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
  17. package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
  18. package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
  19. package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
  20. package/dist/aws/infra/canaries/canary-role.js.map +1 -0
  21. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  22. package/dist/aws/infra/canaries/canary.js.map +1 -0
  23. package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
  24. package/dist/aws/infra/canaries/database-canary.js.map +1 -0
  25. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  26. package/dist/aws/infra/canaries/database-checker.js.map +1 -0
  27. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  28. package/dist/aws/infra/canaries/url-canary.js.map +1 -0
  29. package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
  30. package/dist/aws/infra/canaries/url-checker.js.map +1 -0
  31. package/dist/aws/infra/documentation.d.ts +56 -0
  32. package/dist/aws/infra/documentation.js.map +1 -0
  33. package/dist/aws/infra/import-util.d.ts +21 -0
  34. package/dist/aws/infra/import-util.js.map +1 -0
  35. package/dist/aws/infra/scheduler.d.ts +12 -0
  36. package/dist/aws/infra/scheduler.js.map +1 -0
  37. package/dist/aws/infra/security-rule.d.ts +12 -0
  38. package/dist/aws/infra/security-rule.js.map +1 -0
  39. package/dist/aws/infra/sqs-integration.d.ts +7 -0
  40. package/dist/aws/infra/sqs-integration.js.map +1 -0
  41. package/dist/aws/infra/sqs-queue.d.ts +16 -0
  42. package/dist/aws/infra/sqs-queue.js.map +1 -0
  43. package/dist/aws/infra/stack/lambda-configs.d.ts +64 -0
  44. package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
  45. package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
  46. package/dist/aws/infra/stack/monitoredfunction.js +31 -31
  47. package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
  48. package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
  49. package/dist/aws/infra/stack/rest_apis.js.map +1 -0
  50. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
  51. package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
  52. package/dist/aws/infra/stack/stack.d.ts +45 -0
  53. package/dist/aws/infra/stack/stack.js.map +1 -0
  54. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  55. package/dist/aws/infra/stack/subscription.js.map +1 -0
  56. package/dist/aws/infra/stacks/db-dns-stack.d.ts +11 -0
  57. package/dist/aws/infra/stacks/db-dns-stack.js.map +1 -0
  58. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +19 -0
  59. package/dist/aws/infra/stacks/db-proxy-stack.js.map +1 -0
  60. package/dist/aws/infra/stacks/db-stack.d.ts +31 -0
  61. package/dist/aws/infra/stacks/db-stack.js.map +1 -0
  62. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  63. package/dist/aws/infra/stacks/intra-stack-configuration.js.map +1 -0
  64. package/dist/aws/infra/stacks/network-stack.d.ts +12 -0
  65. package/dist/aws/infra/stacks/network-stack.js.map +1 -0
  66. package/dist/aws/infra/usage-plans.d.ts +16 -0
  67. package/dist/aws/infra/usage-plans.js.map +1 -0
  68. package/dist/aws/runtime/apikey.d.ts +2 -0
  69. package/dist/aws/runtime/apikey.js.map +1 -0
  70. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  71. package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
  72. package/dist/aws/runtime/environment.d.ts +1 -0
  73. package/dist/aws/runtime/environment.js.map +1 -0
  74. package/dist/aws/runtime/messaging.d.ts +10 -0
  75. package/dist/aws/runtime/messaging.js.map +1 -0
  76. package/dist/aws/runtime/s3.d.ts +2 -0
  77. package/dist/aws/runtime/s3.js.map +1 -0
  78. package/dist/aws/runtime/secrets/dbsecret.d.ts +54 -0
  79. package/dist/aws/runtime/secrets/dbsecret.js +4 -4
  80. package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
  81. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  82. package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
  83. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  84. package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
  85. package/dist/aws/runtime/secrets/secret-holder.d.ts +26 -0
  86. package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
  87. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  88. package/dist/aws/runtime/secrets/secret.js.map +1 -0
  89. package/dist/aws/types/errors.d.ts +8 -0
  90. package/dist/aws/types/errors.js.map +1 -0
  91. package/dist/aws/types/lambda-response.d.ts +13 -0
  92. package/dist/aws/types/lambda-response.js.map +1 -0
  93. package/dist/aws/types/mediatypes.d.ts +11 -0
  94. package/dist/aws/types/mediatypes.js.map +1 -0
  95. package/dist/aws/types/model-with-reference.d.ts +7 -0
  96. package/dist/aws/types/model-with-reference.js.map +1 -0
  97. package/dist/aws/types/proxytypes.d.ts +26 -0
  98. package/dist/aws/types/proxytypes.js.map +1 -0
  99. package/dist/aws/types/tags.d.ts +2 -0
  100. package/dist/aws/types/tags.js.map +1 -0
  101. package/dist/database/cached.d.ts +7 -0
  102. package/dist/database/cached.js.map +1 -0
  103. package/dist/database/database.d.ts +19 -0
  104. package/dist/database/database.js.map +1 -0
  105. package/dist/database/last-updated.d.ts +16 -0
  106. package/dist/database/last-updated.js.map +1 -0
  107. package/dist/database/models.d.ts +6 -0
  108. package/dist/database/models.js.map +1 -0
  109. package/dist/marine/id_utils.d.ts +3 -0
  110. package/dist/marine/id_utils.js.map +1 -0
  111. package/dist/marine/rtz.d.ts +48 -0
  112. package/dist/marine/rtz.js.map +1 -0
  113. package/dist/test/asserter.d.ts +11 -0
  114. package/dist/test/asserter.js.map +1 -0
  115. package/dist/test/db-testutils.d.ts +3 -0
  116. package/dist/test/db-testutils.js.map +1 -0
  117. package/dist/test/httpserver.d.ts +19 -0
  118. package/dist/test/httpserver.js.map +1 -0
  119. package/dist/test/secret.d.ts +3 -0
  120. package/dist/test/secret.js.map +1 -0
  121. package/dist/test/secrets-manager.d.ts +9 -0
  122. package/dist/test/secrets-manager.js.map +1 -0
  123. package/dist/test/testutils.d.ts +12 -0
  124. package/dist/test/testutils.js.map +1 -0
  125. package/dist/types/either.d.ts +9 -0
  126. package/dist/types/either.js.map +1 -0
  127. package/dist/types/input-error.d.ts +2 -0
  128. package/dist/types/input-error.js.map +1 -0
  129. package/dist/types/language.d.ts +5 -0
  130. package/dist/types/language.js.map +1 -0
  131. package/dist/types/traffictype.d.ts +8 -0
  132. package/dist/types/traffictype.js.map +1 -0
  133. package/dist/types/validator.d.ts +4 -0
  134. package/dist/types/validator.js.map +1 -0
  135. package/dist/utils/api-model.d.ts +87 -0
  136. package/dist/utils/api-model.js.map +1 -0
  137. package/dist/utils/base64.d.ts +12 -0
  138. package/dist/utils/base64.js.map +1 -0
  139. package/dist/utils/date-utils.d.ts +17 -0
  140. package/dist/utils/date-utils.js.map +1 -0
  141. package/dist/utils/geojson-types.d.ts +14 -0
  142. package/dist/utils/geojson-types.js.map +1 -0
  143. package/dist/utils/geometry.d.ts +36 -0
  144. package/dist/utils/geometry.js.map +1 -0
  145. package/dist/utils/retry.d.ts +13 -0
  146. package/dist/utils/retry.js.map +1 -0
  147. package/dist/utils/slack.d.ts +5 -0
  148. package/dist/utils/slack.js.map +1 -0
  149. package/dist/utils/utils.d.ts +46 -0
  150. package/dist/utils/utils.js.map +1 -0
  151. package/package.json +19 -29
  152. package/src/aws/infra/api/integration.ts +30 -14
  153. package/src/aws/infra/api/response.ts +107 -26
  154. package/src/aws/infra/api/responses.ts +8 -0
  155. package/src/aws/infra/api/static-integration.ts +48 -14
  156. package/src/aws/runtime/secrets/dbsecret.ts +23 -54
  157. package/src/aws/runtime/secrets/secret-holder.ts +6 -3
  158. package/src/database/database.ts +1 -1
@@ -1,5 +1,12 @@
1
- import apigateway = require('aws-cdk-lib/aws-apigateway');
2
- import {MediaType} from "../../types/mediatypes";
1
+ import { MediaType } from "../../types/mediatypes";
2
+ import {
3
+ JsonSchemaType,
4
+ JsonSchemaVersion,
5
+ JsonSchema,
6
+ MethodResponse,
7
+ Model,
8
+ } from "aws-cdk-lib/aws-apigateway";
9
+ import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
3
10
 
4
11
  /**
5
12
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
@@ -23,45 +30,119 @@ $inputRoot.body
23
30
 
24
31
  const BODY_FROM_INPUT_PATH = "$input.path('$').body";
25
32
 
26
- // DEPRECATED
27
- const messageSchema: apigateway.JsonSchema = {
28
- schema: apigateway.JsonSchemaVersion.DRAFT4,
29
- type: apigateway.JsonSchemaType.OBJECT,
30
- description: 'Response with message',
33
+ /// @deprecated
34
+ const messageSchema: JsonSchema = {
35
+ schema: JsonSchemaVersion.DRAFT4,
36
+ type: JsonSchemaType.OBJECT,
37
+ description: "Response with message",
31
38
  properties: {
32
39
  message: {
33
- type: apigateway.JsonSchemaType.STRING,
34
- description: 'Response message',
40
+ type: JsonSchemaType.STRING,
41
+ description: "Response message",
35
42
  },
36
43
  },
37
44
  };
38
45
 
39
- // DEPRECATED
46
+ /// @deprecated
40
47
  export const MessageModel = {
41
48
  contentType: MediaType.APPLICATION_JSON,
42
- modelName: 'MessageResponseModel',
49
+ modelName: "MessageResponseModel",
43
50
  schema: messageSchema,
44
51
  };
45
52
 
46
- const NotFoundMessage = 'Not found';
47
- export const NotFoundResponse = JSON.stringify({message: NotFoundMessage});
53
+ const NotFoundMessage = "Not found";
54
+ export const NotFoundResponse = JSON.stringify({ message: NotFoundMessage });
48
55
 
49
- const InternalServerErrorMessage = 'Error';
50
- const InternalServerErrorResponse = JSON.stringify({message: InternalServerErrorMessage});
56
+ const InternalServerErrorMessage = "Error";
57
+ const InternalServerErrorResponse = JSON.stringify({
58
+ message: InternalServerErrorMessage,
59
+ });
51
60
 
52
- const BadRequestMessage = 'Bad request';
53
- const BadRequestResponse = JSON.stringify({message: BadRequestMessage});
61
+ const BadRequestMessage = "Bad request";
62
+ const BadRequestResponse = JSON.stringify({ message: BadRequestMessage });
54
63
 
55
- export const BadRequestResponseTemplate = createResponses(MediaType.APPLICATION_JSON, BadRequestResponse);
56
- export const NotFoundResponseTemplate = createResponses(MediaType.APPLICATION_JSON, NotFoundResponse);
57
- export const XmlResponseTemplate = createResponses(MediaType.APPLICATION_XML, BODY_FROM_INPUT_PATH);
58
- export const SvgResponseTemplate = createResponses(MediaType.IMAGE_SVG, BODY_FROM_INPUT_PATH);
59
- export const InternalServerErrorResponseTemplate = createResponses(MediaType.APPLICATION_JSON, InternalServerErrorResponse);
64
+ /// @deprecated
65
+ export const BadRequestResponseTemplate = createResponses(
66
+ MediaType.APPLICATION_JSON,
67
+ BadRequestResponse
68
+ );
69
+ /// @deprecated
70
+ export const NotFoundResponseTemplate = createResponses(
71
+ MediaType.APPLICATION_JSON,
72
+ NotFoundResponse
73
+ );
74
+ /// @deprecated
75
+ export const XmlResponseTemplate = createResponses(
76
+ MediaType.APPLICATION_XML,
77
+ BODY_FROM_INPUT_PATH
78
+ );
79
+ /// @deprecated
80
+ export const InternalServerErrorResponseTemplate = createResponses(
81
+ MediaType.APPLICATION_JSON,
82
+ InternalServerErrorResponse
83
+ );
60
84
 
61
- export function createResponses<T>(key: MediaType, value: T): Record<string, T> {
62
- const map: Record<string, T> = {};
85
+ /// @deprecated
86
+ export function createResponses<T>(
87
+ key: MediaType,
88
+ value: T
89
+ ): Record<string, T> {
90
+ return {
91
+ [key]: value,
92
+ };
93
+ }
94
+
95
+ export class DigitrafficMethodResponse {
96
+ static response(
97
+ statusCode: string,
98
+ model: IModel,
99
+ mediaType: MediaType,
100
+ disableCors = false
101
+ ): MethodResponse {
102
+ return {
103
+ statusCode,
104
+ responseModels: {
105
+ [mediaType]: model,
106
+ },
107
+ responseParameters: disableCors
108
+ ? {}
109
+ : {
110
+ "method.response.header.Access-Control-Allow-Origin":
111
+ true,
112
+ },
113
+ };
114
+ }
115
+
116
+ static response200(model: IModel, mediaType = MediaType.APPLICATION_JSON) {
117
+ return DigitrafficMethodResponse.response(
118
+ "200",
119
+ model,
120
+ mediaType,
121
+ false
122
+ );
123
+ }
63
124
 
64
- map[key] = value;
125
+ static response500(
126
+ model = Model.EMPTY_MODEL,
127
+ mediaType = MediaType.APPLICATION_JSON
128
+ ) {
129
+ return DigitrafficMethodResponse.response(
130
+ "500",
131
+ model,
132
+ mediaType,
133
+ false
134
+ );
135
+ }
65
136
 
66
- return map;
137
+ static response400(
138
+ model = Model.EMPTY_MODEL,
139
+ mediaType = MediaType.APPLICATION_JSON
140
+ ) {
141
+ return DigitrafficMethodResponse.response(
142
+ "400",
143
+ model,
144
+ mediaType,
145
+ false
146
+ );
147
+ }
67
148
  }
@@ -52,6 +52,9 @@ export const RESPONSE_404_NOT_FOUND = {
52
52
  responseTemplates: NotFoundResponseTemplate,
53
53
  };
54
54
 
55
+ /**
56
+ * @deprecated Use DigitrafficMethodResponse
57
+ */
55
58
  export function methodResponse(
56
59
  status: string,
57
60
  contentType: MediaType,
@@ -65,6 +68,9 @@ export function methodResponse(
65
68
  };
66
69
  }
67
70
 
71
+ /**
72
+ * @deprecated Use DigitrafficMethodResponse
73
+ */
68
74
  export function corsMethod(response: MethodResponse): MethodResponse {
69
75
  return {
70
76
  ...response,
@@ -89,6 +95,8 @@ interface IntegrationOptions {
89
95
  * Creates a default Lambda integration for a REST API resource _root_
90
96
  * @param lambdaFunction The Lambda function
91
97
  * @param options Options
98
+ *
99
+ * @deprecated Use DigitrafficIntegration
92
100
  */
93
101
  export function defaultIntegration(
94
102
  lambdaFunction: AWSFunction,
@@ -1,13 +1,17 @@
1
- import {MockIntegration, PassthroughBehavior, Resource} from "aws-cdk-lib/aws-apigateway";
2
- import {MediaType} from "../../types/mediatypes";
3
- import {corsMethod, RESPONSE_CORS_INTEGRATION} from "./responses";
1
+ import {
2
+ MockIntegration,
3
+ PassthroughBehavior,
4
+ Resource,
5
+ } from "aws-cdk-lib/aws-apigateway";
6
+ import { MediaType } from "../../types/mediatypes";
7
+ import { corsMethod, RESPONSE_CORS_INTEGRATION } from "./responses";
4
8
 
5
9
  const INTEGRATION_RESPONSE_200 = `{
6
10
  "statusCode": 200
7
11
  }`;
8
12
 
9
13
  const METHOD_RESPONSE_200 = {
10
- statusCode: '200',
14
+ statusCode: "200",
11
15
  };
12
16
 
13
17
  /**
@@ -19,9 +23,18 @@ const METHOD_RESPONSE_200 = {
19
23
  */
20
24
  export class DigitrafficStaticIntegration extends MockIntegration {
21
25
  constructor(
22
- resource: Resource, mediaType: MediaType, response: string, enableCors = true, apiKeyRequired = true,
26
+ resource: Resource,
27
+ mediaType: MediaType,
28
+ response: string,
29
+ enableCors = true,
30
+ apiKeyRequired = true
23
31
  ) {
24
- const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, enableCors);
32
+ const integrationResponse =
33
+ DigitrafficStaticIntegration.createIntegrationResponse(
34
+ response,
35
+ mediaType,
36
+ enableCors
37
+ );
25
38
 
26
39
  super({
27
40
  passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
@@ -31,32 +44,53 @@ export class DigitrafficStaticIntegration extends MockIntegration {
31
44
  integrationResponses: [integrationResponse],
32
45
  });
33
46
 
34
- ['GET', 'HEAD'].forEach((httpMethod) => {
47
+ ["GET", "HEAD"].forEach((httpMethod) => {
35
48
  resource.addMethod(httpMethod, this, {
36
49
  apiKeyRequired,
37
- methodResponses: [DigitrafficStaticIntegration.createMethodResponse(enableCors)],
50
+ methodResponses: [
51
+ DigitrafficStaticIntegration.createMethodResponse(
52
+ enableCors
53
+ ),
54
+ ],
38
55
  });
39
56
  });
40
57
  }
41
58
 
42
- static json<K>(resource: Resource, response: K, enableCors = true, apiKeyRequired = true) {
59
+ static json<K>(
60
+ resource: Resource,
61
+ response: K,
62
+ enableCors = true,
63
+ apiKeyRequired = true
64
+ ) {
43
65
  return new DigitrafficStaticIntegration(
44
- resource, MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired,
66
+ resource,
67
+ MediaType.APPLICATION_JSON,
68
+ JSON.stringify(response),
69
+ enableCors,
70
+ apiKeyRequired
45
71
  );
46
72
  }
47
73
 
48
- private static createIntegrationResponse(response: string, mediaType: MediaType, enableCors: boolean) {
74
+ private static createIntegrationResponse(
75
+ response: string,
76
+ mediaType: MediaType,
77
+ enableCors: boolean
78
+ ) {
49
79
  const integrationResponse = {
50
- statusCode: '200',
80
+ statusCode: "200",
51
81
  responseTemplates: {
52
82
  [mediaType]: response,
53
83
  },
54
84
  };
55
85
 
56
- return enableCors ? {...integrationResponse, ...RESPONSE_CORS_INTEGRATION} : integrationResponse;
86
+ return enableCors
87
+ ? { ...integrationResponse, ...RESPONSE_CORS_INTEGRATION }
88
+ : integrationResponse;
57
89
  }
58
90
 
59
91
  private static createMethodResponse(enableCors: boolean) {
60
- return enableCors ? corsMethod(METHOD_RESPONSE_200) : METHOD_RESPONSE_200;
92
+ return enableCors
93
+ ? corsMethod(METHOD_RESPONSE_200)
94
+ : METHOD_RESPONSE_200;
61
95
  }
62
96
  }
@@ -1,24 +1,18 @@
1
- import { GenericSecret, withSecret, withSecretAndPrefix } from "./secret";
1
+ import {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",
12
- password = "password",
13
- proxy_host = "proxy_host",
14
- proxy_ro_host = "proxy_ro_host",
11
+ username = "username", password = "password", proxy_host = "proxy_host", proxy_ro_host = "proxy_ro_host"
15
12
  }
16
13
 
17
14
  export enum RdsSecretKey {
18
- username = "username",
19
- password = "password",
20
- host = "host",
21
- ro_host = "ro_host",
15
+ username = "username", password = "password", host = "host", ro_host = "ro_host"
22
16
  }
23
17
 
24
18
  export type RdsProxySecret = Record<RdsProxySecretKey, string>;
@@ -43,7 +37,7 @@ function setDbSecret(secret: DbSecret) {
43
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
38
  let cachedSecret: any;
45
39
 
46
- const missingSecretErrorText = "Missing or empty secretId";
40
+ const missingSecretErrorText = 'Missing or empty secretId';
47
41
 
48
42
  /**
49
43
  * You can give the following options for retrieving a secret:
@@ -54,22 +48,13 @@ const missingSecretErrorText = "Missing or empty secretId";
54
48
 
55
49
  */
56
50
  export type SecretOptions = {
57
- readonly expectedKeys?: string[];
58
- readonly prefix?: string;
59
- };
51
+ readonly expectedKeys?: string[],
52
+ readonly prefix?: string
53
+ }
60
54
 
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
- >;
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>;
73
58
 
74
59
  /**
75
60
  * Run the given function with secret retrieved from Secrets Manager. Also injects database-credentials into environment.
@@ -81,11 +66,7 @@ export type EmptySecretFunction<Response = void> = SecretFunction<
81
66
  * @param {function} fn
82
67
  * @param {SecretOptions} options
83
68
  */
84
- export async function withDbSecret<Secret, Response>(
85
- secretId: string,
86
- fn: SecretToPromiseFunction<Secret, Response>,
87
- options?: SecretOptions
88
- ): Promise<Response | void> {
69
+ export async function withDbSecret<Secret, Response>(secretId: string, fn: SecretToPromiseFunction<Secret, Response>, options?: SecretOptions): Promise<Response | void> {
89
70
  if (!secretId) {
90
71
  console.error(missingSecretErrorText);
91
72
  return Promise.reject(missingSecretErrorText);
@@ -100,13 +81,9 @@ export async function withDbSecret<Secret, Response>(
100
81
  });
101
82
 
102
83
  // then actual secret
103
- await withSecretAndPrefix(
104
- secretId,
105
- options.prefix,
106
- (fetchedSecret: Secret) => {
107
- cachedSecret = fetchedSecret;
108
- }
109
- );
84
+ await withSecretAndPrefix(secretId, options.prefix, (fetchedSecret: Secret) => {
85
+ cachedSecret = fetchedSecret;
86
+ });
110
87
  } else {
111
88
  await withSecret(secretId, (fetchedSecret: DbSecret) => {
112
89
  setDbSecret(fetchedSecret);
@@ -120,10 +97,7 @@ export async function withDbSecret<Secret, Response>(
120
97
  }
121
98
  return fn(cachedSecret);
122
99
  } catch (error) {
123
- console.error(
124
- "method=withDbSecret Caught an error, refreshing secret",
125
- error
126
- );
100
+ console.error('method=withDbSecret Caught an error, refreshing secret', error);
127
101
  // try to refetch secret in case it has changed
128
102
  await withSecret(secretId, (fetchedSecret: DbSecret) => {
129
103
  setDbSecret(fetchedSecret);
@@ -133,15 +107,10 @@ export async function withDbSecret<Secret, Response>(
133
107
  }
134
108
  }
135
109
 
136
- export function checkExpectedSecretKeys<Secret extends GenericSecret>(
137
- keys: string[],
138
- secret: Secret
139
- ) {
140
- const missingKeys = keys.filter((key) => !(key in secret));
110
+ export function checkExpectedSecretKeys<Secret>(keys: string[], secret: Secret) {
111
+ const missingKeys = keys.filter(key => !(key in secret));
141
112
  if (missingKeys.length) {
142
- console.error(
143
- `method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`
144
- );
145
- throw new Error("Expected keys were not found");
113
+ console.error(`method=checkExpectedSecretKeys secret didn't contain the key(s) ${missingKeys}`);
114
+ throw new Error('Expected keys were not found');
146
115
  }
147
116
  }
@@ -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 extends GenericSecret> {
26
+ export class SecretHolder<Secret> {
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 extends GenericSecret> {
51
51
  this.secretCache.push(DEFAULT_SECRET_KEY, secretValue);
52
52
  }
53
53
 
54
- public static create<S extends GenericSecret>(
54
+ public static create<S>(
55
55
  prefix = DEFAULT_PREFIX,
56
56
  expectedKeys: string[] = []
57
57
  ) {
@@ -67,7 +67,10 @@ export class SecretHolder<Secret extends GenericSecret> {
67
67
  const parsedSecret =
68
68
  this.prefix === DEFAULT_PREFIX
69
69
  ? secret
70
- : this.parseSecret(secret, `${this.prefix}.`);
70
+ : this.parseSecret(
71
+ secret as unknown as GenericSecret,
72
+ `${this.prefix}.`
73
+ );
71
74
 
72
75
  if (this.expectedKeys.length > 0) {
73
76
  checkExpectedSecretKeys(this.expectedKeys, parsedSecret);
@@ -1,6 +1,6 @@
1
1
  import { IDatabase, ITask } from "pg-promise";
2
2
  import { DatabaseEnvironmentKeys } from "../aws/runtime/secrets/dbsecret";
3
- import { getEnvVariable, getEnvVariableSafe } from "../utils/utils";
3
+ import { getEnvVariable } from "../utils/utils";
4
4
  import { envValue } from "../aws/runtime/environment";
5
5
 
6
6
  // eslint-disable-next-line @typescript-eslint/no-var-requires