@digitraffic/common 2022.11.22-1 → 2022.11.23-1

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 (156) 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 +29 -0
  5. package/dist/aws/infra/api/response.js +36 -11
  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.map +1 -0
  12. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  13. package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
  14. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  15. package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
  16. package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
  17. package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
  18. package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
  19. package/dist/aws/infra/canaries/canary-role.js.map +1 -0
  20. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  21. package/dist/aws/infra/canaries/canary.js.map +1 -0
  22. package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
  23. package/dist/aws/infra/canaries/database-canary.js.map +1 -0
  24. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  25. package/dist/aws/infra/canaries/database-checker.js.map +1 -0
  26. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  27. package/dist/aws/infra/canaries/url-canary.js.map +1 -0
  28. package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
  29. package/dist/aws/infra/canaries/url-checker.js.map +1 -0
  30. package/dist/aws/infra/documentation.d.ts +56 -0
  31. package/dist/aws/infra/documentation.js.map +1 -0
  32. package/dist/aws/infra/import-util.d.ts +21 -0
  33. package/dist/aws/infra/import-util.js.map +1 -0
  34. package/dist/aws/infra/scheduler.d.ts +12 -0
  35. package/dist/aws/infra/scheduler.js.map +1 -0
  36. package/dist/aws/infra/security-rule.d.ts +12 -0
  37. package/dist/aws/infra/security-rule.js.map +1 -0
  38. package/dist/aws/infra/sqs-integration.d.ts +7 -0
  39. package/dist/aws/infra/sqs-integration.js.map +1 -0
  40. package/dist/aws/infra/sqs-queue.d.ts +16 -0
  41. package/dist/aws/infra/sqs-queue.js.map +1 -0
  42. package/dist/aws/infra/stack/lambda-configs.d.ts +64 -0
  43. package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
  44. package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
  45. package/dist/aws/infra/stack/monitoredfunction.js +31 -31
  46. package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
  47. package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
  48. package/dist/aws/infra/stack/rest_apis.js.map +1 -0
  49. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
  50. package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
  51. package/dist/aws/infra/stack/stack.d.ts +45 -0
  52. package/dist/aws/infra/stack/stack.js.map +1 -0
  53. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  54. package/dist/aws/infra/stack/subscription.js.map +1 -0
  55. package/dist/aws/infra/stacks/db-dns-stack.d.ts +11 -0
  56. package/dist/aws/infra/stacks/db-dns-stack.js.map +1 -0
  57. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +19 -0
  58. package/dist/aws/infra/stacks/db-proxy-stack.js.map +1 -0
  59. package/dist/aws/infra/stacks/db-stack.d.ts +31 -0
  60. package/dist/aws/infra/stacks/db-stack.js.map +1 -0
  61. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  62. package/dist/aws/infra/stacks/intra-stack-configuration.js.map +1 -0
  63. package/dist/aws/infra/stacks/network-stack.d.ts +12 -0
  64. package/dist/aws/infra/stacks/network-stack.js.map +1 -0
  65. package/dist/aws/infra/usage-plans.d.ts +16 -0
  66. package/dist/aws/infra/usage-plans.js.map +1 -0
  67. package/dist/aws/runtime/apikey.d.ts +2 -0
  68. package/dist/aws/runtime/apikey.js.map +1 -0
  69. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  70. package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
  71. package/dist/aws/runtime/environment.d.ts +1 -0
  72. package/dist/aws/runtime/environment.js.map +1 -0
  73. package/dist/aws/runtime/messaging.d.ts +10 -0
  74. package/dist/aws/runtime/messaging.js.map +1 -0
  75. package/dist/aws/runtime/s3.d.ts +2 -0
  76. package/dist/aws/runtime/s3.js.map +1 -0
  77. package/dist/aws/runtime/secrets/dbsecret.d.ts +54 -0
  78. package/dist/aws/runtime/secrets/dbsecret.js +4 -4
  79. package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
  80. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  81. package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
  82. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  83. package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
  84. package/dist/aws/runtime/secrets/secret-holder.d.ts +26 -0
  85. package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
  86. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  87. package/dist/aws/runtime/secrets/secret.js.map +1 -0
  88. package/dist/aws/types/errors.d.ts +8 -0
  89. package/dist/aws/types/errors.js.map +1 -0
  90. package/dist/aws/types/lambda-response.d.ts +13 -0
  91. package/dist/aws/types/lambda-response.js.map +1 -0
  92. package/dist/aws/types/mediatypes.d.ts +11 -0
  93. package/dist/aws/types/mediatypes.js.map +1 -0
  94. package/dist/aws/types/model-with-reference.d.ts +7 -0
  95. package/dist/aws/types/model-with-reference.js.map +1 -0
  96. package/dist/aws/types/proxytypes.d.ts +26 -0
  97. package/dist/aws/types/proxytypes.js.map +1 -0
  98. package/dist/aws/types/tags.d.ts +2 -0
  99. package/dist/aws/types/tags.js.map +1 -0
  100. package/dist/database/cached.d.ts +7 -0
  101. package/dist/database/cached.js.map +1 -0
  102. package/dist/database/database.d.ts +19 -0
  103. package/dist/database/database.js.map +1 -0
  104. package/dist/database/last-updated.d.ts +16 -0
  105. package/dist/database/last-updated.js.map +1 -0
  106. package/dist/database/models.d.ts +6 -0
  107. package/dist/database/models.js.map +1 -0
  108. package/dist/marine/id_utils.d.ts +3 -0
  109. package/dist/marine/id_utils.js.map +1 -0
  110. package/dist/marine/rtz.d.ts +48 -0
  111. package/dist/marine/rtz.js.map +1 -0
  112. package/dist/test/asserter.d.ts +11 -0
  113. package/dist/test/asserter.js.map +1 -0
  114. package/dist/test/db-testutils.d.ts +3 -0
  115. package/dist/test/db-testutils.js.map +1 -0
  116. package/dist/test/httpserver.d.ts +19 -0
  117. package/dist/test/httpserver.js.map +1 -0
  118. package/dist/test/secret.d.ts +3 -0
  119. package/dist/test/secret.js.map +1 -0
  120. package/dist/test/secrets-manager.d.ts +9 -0
  121. package/dist/test/secrets-manager.js.map +1 -0
  122. package/dist/test/testutils.d.ts +12 -0
  123. package/dist/test/testutils.js.map +1 -0
  124. package/dist/types/either.d.ts +9 -0
  125. package/dist/types/either.js.map +1 -0
  126. package/dist/types/input-error.d.ts +2 -0
  127. package/dist/types/input-error.js.map +1 -0
  128. package/dist/types/language.d.ts +5 -0
  129. package/dist/types/language.js.map +1 -0
  130. package/dist/types/traffictype.d.ts +8 -0
  131. package/dist/types/traffictype.js.map +1 -0
  132. package/dist/types/validator.d.ts +4 -0
  133. package/dist/types/validator.js.map +1 -0
  134. package/dist/utils/api-model.d.ts +87 -0
  135. package/dist/utils/api-model.js.map +1 -0
  136. package/dist/utils/base64.d.ts +12 -0
  137. package/dist/utils/base64.js.map +1 -0
  138. package/dist/utils/date-utils.d.ts +17 -0
  139. package/dist/utils/date-utils.js.map +1 -0
  140. package/dist/utils/geojson-types.d.ts +14 -0
  141. package/dist/utils/geojson-types.js.map +1 -0
  142. package/dist/utils/geometry.d.ts +36 -0
  143. package/dist/utils/geometry.js.map +1 -0
  144. package/dist/utils/retry.d.ts +13 -0
  145. package/dist/utils/retry.js.map +1 -0
  146. package/dist/utils/slack.d.ts +5 -0
  147. package/dist/utils/slack.js.map +1 -0
  148. package/dist/utils/utils.d.ts +46 -0
  149. package/dist/utils/utils.js.map +1 -0
  150. package/package.json +19 -29
  151. package/src/aws/infra/api/integration.ts +30 -14
  152. package/src/aws/infra/api/response.ts +83 -20
  153. package/src/aws/infra/api/responses.ts +8 -0
  154. package/src/aws/runtime/secrets/dbsecret.ts +23 -54
  155. package/src/aws/runtime/secrets/secret-holder.ts +6 -3
  156. package/src/database/database.ts +1 -1
@@ -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,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