@digitraffic/common 2024.1.10-1 → 2024.1.19-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 (166) hide show
  1. package/dist/aws/infra/api/handler-factory.d.ts +2 -2
  2. package/dist/aws/infra/api/handler-factory.js +4 -9
  3. package/dist/aws/infra/api/integration.d.ts +1 -1
  4. package/dist/aws/infra/api/integration.js +9 -13
  5. package/dist/aws/infra/api/response.d.ts +2 -3
  6. package/dist/aws/infra/api/response.js +25 -30
  7. package/dist/aws/infra/api/responses.d.ts +2 -3
  8. package/dist/aws/infra/api/responses.js +25 -31
  9. package/dist/aws/infra/api/static-integration.d.ts +1 -1
  10. package/dist/aws/infra/api/static-integration.js +7 -11
  11. package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
  12. package/dist/aws/infra/canaries/canary-alarm.js +7 -11
  13. package/dist/aws/infra/canaries/canary-keys.js +3 -6
  14. package/dist/aws/infra/canaries/canary-parameters.js +1 -2
  15. package/dist/aws/infra/canaries/canary-role.js +8 -12
  16. package/dist/aws/infra/canaries/canary.d.ts +2 -2
  17. package/dist/aws/infra/canaries/canary.js +9 -13
  18. package/dist/aws/infra/canaries/database-canary.d.ts +3 -3
  19. package/dist/aws/infra/canaries/database-canary.js +8 -12
  20. package/dist/aws/infra/canaries/database-checker.d.ts +1 -1
  21. package/dist/aws/infra/canaries/database-checker.js +10 -14
  22. package/dist/aws/infra/canaries/url-canary.d.ts +4 -4
  23. package/dist/aws/infra/canaries/url-canary.js +8 -12
  24. package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
  25. package/dist/aws/infra/canaries/url-checker.js +33 -40
  26. package/dist/aws/infra/documentation.js +8 -16
  27. package/dist/aws/infra/import-util.js +10 -18
  28. package/dist/aws/infra/scheduler.js +10 -14
  29. package/dist/aws/infra/security-rule.js +4 -8
  30. package/dist/aws/infra/sqs-integration.d.ts +1 -2
  31. package/dist/aws/infra/sqs-integration.js +11 -15
  32. package/dist/aws/infra/sqs-queue.d.ts +1 -1
  33. package/dist/aws/infra/sqs-queue.js +30 -35
  34. package/dist/aws/infra/stack/lambda-configs.d.ts +2 -2
  35. package/dist/aws/infra/stack/lambda-configs.js +14 -20
  36. package/dist/aws/infra/stack/monitoredfunction.d.ts +3 -3
  37. package/dist/aws/infra/stack/monitoredfunction.js +19 -27
  38. package/dist/aws/infra/stack/parameters.d.ts +1 -1
  39. package/dist/aws/infra/stack/parameters.js +5 -10
  40. package/dist/aws/infra/stack/rest_apis.d.ts +3 -3
  41. package/dist/aws/infra/stack/rest_apis.js +41 -54
  42. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
  43. package/dist/aws/infra/stack/stack-checking-aspect.js +24 -31
  44. package/dist/aws/infra/stack/stack.d.ts +3 -4
  45. package/dist/aws/infra/stack/stack.js +16 -20
  46. package/dist/aws/infra/stack/subscription.d.ts +2 -2
  47. package/dist/aws/infra/stack/subscription.js +5 -10
  48. package/dist/aws/infra/stacks/db-dns-stack.d.ts +2 -2
  49. package/dist/aws/infra/stacks/db-dns-stack.js +25 -29
  50. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +2 -2
  51. package/dist/aws/infra/stacks/db-proxy-stack.js +23 -27
  52. package/dist/aws/infra/stacks/db-stack.d.ts +3 -4
  53. package/dist/aws/infra/stacks/db-stack.js +30 -34
  54. package/dist/aws/infra/stacks/intra-stack-configuration.js +1 -2
  55. package/dist/aws/infra/stacks/network-stack.d.ts +2 -2
  56. package/dist/aws/infra/stacks/network-stack.js +14 -18
  57. package/dist/aws/infra/usage-plans.js +2 -7
  58. package/dist/aws/runtime/apikey.js +3 -7
  59. package/dist/aws/runtime/digitraffic-integration-response.d.ts +1 -1
  60. package/dist/aws/runtime/digitraffic-integration-response.js +7 -11
  61. package/dist/aws/runtime/dt-logger-default.d.ts +2 -2
  62. package/dist/aws/runtime/dt-logger-default.js +2 -5
  63. package/dist/aws/runtime/dt-logger.d.ts +1 -1
  64. package/dist/aws/runtime/dt-logger.js +3 -10
  65. package/dist/aws/runtime/environment.js +3 -7
  66. package/dist/aws/runtime/messaging.js +1 -5
  67. package/dist/aws/runtime/s3.js +3 -7
  68. package/dist/aws/runtime/secrets/dbsecret.d.ts +1 -1
  69. package/dist/aws/runtime/secrets/dbsecret.js +5 -9
  70. package/dist/aws/runtime/secrets/proxy-holder.js +12 -16
  71. package/dist/aws/runtime/secrets/rds-holder.js +12 -16
  72. package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
  73. package/dist/aws/runtime/secrets/secret-holder.js +9 -13
  74. package/dist/aws/runtime/secrets/secret.js +7 -11
  75. package/dist/aws/types/errors.js +5 -9
  76. package/dist/aws/types/lambda-response.js +3 -10
  77. package/dist/aws/types/mediatypes.js +2 -5
  78. package/dist/aws/types/model-with-reference.js +1 -2
  79. package/dist/aws/types/proxytypes.js +1 -2
  80. package/dist/aws/types/tags.js +2 -5
  81. package/dist/database/cached.d.ts +1 -1
  82. package/dist/database/cached.js +8 -14
  83. package/dist/database/database.js +14 -21
  84. package/dist/database/last-updated.d.ts +1 -1
  85. package/dist/database/last-updated.js +8 -17
  86. package/dist/database/models.js +1 -2
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.js +2 -0
  89. package/dist/marine/id_utils.js +3 -9
  90. package/dist/marine/rtz.js +1 -2
  91. package/dist/test/asserter.js +1 -5
  92. package/dist/test/db-testutils.d.ts +1 -1
  93. package/dist/test/db-testutils.js +8 -13
  94. package/dist/test/httpserver.js +10 -14
  95. package/dist/test/secrets-manager.js +9 -35
  96. package/dist/test/testutils.js +8 -19
  97. package/dist/types/async-timeout-error.js +1 -5
  98. package/dist/types/aws-env.js +1 -2
  99. package/dist/types/either.js +1 -2
  100. package/dist/types/http-error.js +1 -5
  101. package/dist/types/input-error.js +1 -5
  102. package/dist/types/language.js +2 -5
  103. package/dist/types/nullable.d.ts +1 -1
  104. package/dist/types/nullable.js +1 -2
  105. package/dist/types/traffictype.js +2 -5
  106. package/dist/types/urn.js +1 -2
  107. package/dist/types/util-types.js +1 -2
  108. package/dist/types/validator.js +4 -9
  109. package/dist/utils/api-model.d.ts +1 -1
  110. package/dist/utils/api-model.js +17 -27
  111. package/dist/utils/base64.d.ts +1 -1
  112. package/dist/utils/base64.js +2 -7
  113. package/dist/utils/date-utils.js +9 -16
  114. package/dist/utils/geojson-types.js +2 -7
  115. package/dist/utils/geometry.js +15 -48
  116. package/dist/utils/logging.d.ts +1 -1
  117. package/dist/utils/logging.js +8 -13
  118. package/dist/utils/retry.js +21 -26
  119. package/dist/utils/slack.js +7 -14
  120. package/dist/utils/utils.d.ts +2 -2
  121. package/dist/utils/utils.js +14 -29
  122. package/package.json +107 -18
  123. package/src/aws/infra/api/handler-factory.ts +3 -3
  124. package/src/aws/infra/api/integration.ts +2 -2
  125. package/src/aws/infra/api/response.ts +3 -3
  126. package/src/aws/infra/api/responses.ts +4 -4
  127. package/src/aws/infra/api/static-integration.ts +2 -2
  128. package/src/aws/infra/canaries/canary-alarm.ts +1 -1
  129. package/src/aws/infra/canaries/canary.ts +3 -3
  130. package/src/aws/infra/canaries/database-canary.ts +3 -3
  131. package/src/aws/infra/canaries/database-checker.ts +6 -6
  132. package/src/aws/infra/canaries/url-canary.ts +6 -6
  133. package/src/aws/infra/canaries/url-checker.ts +8 -8
  134. package/src/aws/infra/sqs-integration.ts +1 -1
  135. package/src/aws/infra/sqs-queue.ts +2 -2
  136. package/src/aws/infra/stack/lambda-configs.ts +2 -2
  137. package/src/aws/infra/stack/monitoredfunction.ts +4 -4
  138. package/src/aws/infra/stack/parameters.ts +1 -1
  139. package/src/aws/infra/stack/rest_apis.ts +6 -6
  140. package/src/aws/infra/stack/stack-checking-aspect.ts +1 -1
  141. package/src/aws/infra/stack/stack.ts +4 -5
  142. package/src/aws/infra/stack/subscription.ts +2 -2
  143. package/src/aws/infra/stacks/db-dns-stack.ts +4 -4
  144. package/src/aws/infra/stacks/db-proxy-stack.ts +5 -5
  145. package/src/aws/infra/stacks/db-stack.ts +5 -5
  146. package/src/aws/infra/stacks/network-stack.ts +3 -3
  147. package/src/aws/runtime/digitraffic-integration-response.ts +2 -2
  148. package/src/aws/runtime/dt-logger-default.ts +2 -2
  149. package/src/aws/runtime/secrets/dbsecret.ts +1 -1
  150. package/src/aws/runtime/secrets/proxy-holder.ts +4 -4
  151. package/src/aws/runtime/secrets/rds-holder.ts +4 -4
  152. package/src/aws/runtime/secrets/secret-holder.ts +4 -4
  153. package/src/aws/runtime/secrets/secret.ts +2 -2
  154. package/src/database/cached.ts +1 -1
  155. package/src/database/database.ts +3 -3
  156. package/src/database/last-updated.ts +1 -1
  157. package/src/index.ts +2 -0
  158. package/src/test/db-testutils.ts +2 -2
  159. package/src/test/secrets-manager.ts +2 -2
  160. package/src/types/nullable.ts +1 -1
  161. package/src/utils/api-model.ts +1 -1
  162. package/src/utils/geometry.ts +5 -3
  163. package/src/utils/logging.ts +2 -2
  164. package/src/utils/retry.ts +3 -3
  165. package/src/utils/slack.ts +2 -2
  166. package/src/utils/utils.ts +3 -3
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retryRequest = exports.retry = exports.retryCount = exports.retryPredicates = exports.timeoutFunctions = exports.RetryLogError = void 0;
4
- const http_error_1 = require("../types/http-error");
5
- const async_timeout_error_1 = require("../types/async-timeout-error");
6
- const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
7
- var RetryLogError;
1
+ import { HttpError } from "../types/http-error.js";
2
+ import { AsyncTimeoutError } from "../types/async-timeout-error.js";
3
+ import { logger } from "../aws/runtime/dt-logger-default.js";
4
+ export var RetryLogError;
8
5
  (function (RetryLogError) {
9
6
  RetryLogError[RetryLogError["LOG_ALL_AS_ERRORS"] = 0] = "LOG_ALL_AS_ERRORS";
10
7
  RetryLogError[RetryLogError["LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS"] = 1] = "LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS";
11
8
  RetryLogError[RetryLogError["NO_LOGGING"] = 2] = "NO_LOGGING";
12
- })(RetryLogError || (exports.RetryLogError = RetryLogError = {}));
9
+ })(RetryLogError || (RetryLogError = {}));
13
10
  /**
14
11
  * Utility timeout functions for "retry" function.
15
12
  */
16
- exports.timeoutFunctions = (function () {
13
+ export const timeoutFunctions = (function () {
17
14
  return {
18
15
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
16
  noTimeout: (retryCount) => {
@@ -27,7 +24,7 @@ exports.timeoutFunctions = (function () {
27
24
  /**
28
25
  * Utility retry predicates for "retry" function.
29
26
  */
30
- exports.retryPredicates = (function () {
27
+ export const retryPredicates = (function () {
31
28
  const retryStatusCodes = new Set([
32
29
  // service might return 403 for no apparent reason
33
30
  403,
@@ -36,7 +33,7 @@ exports.retryPredicates = (function () {
36
33
  ]);
37
34
  return {
38
35
  retryBasedOnStatusCode: (error) => {
39
- if (error instanceof http_error_1.HttpError) {
36
+ if (error instanceof HttpError) {
40
37
  return retryStatusCodes.has(error.statusCode);
41
38
  }
42
39
  return false;
@@ -54,7 +51,7 @@ function readPossibleErrorMessage(error) {
54
51
  return "Something else than an Error object was thrown";
55
52
  }
56
53
  // Tämä muuttuja on testejä varten määritelty täällä.
57
- exports.retryCount = 0;
54
+ export let retryCount = 0;
58
55
  async function retryRecursive(asyncFn, retries, retryCountInj, logError, timeoutBetweenRetries, retryPredicate) {
59
56
  const asyncFnTimeout = 30 * 60 * 1000; // 30 minutes
60
57
  if (!isFinite(retries)) {
@@ -68,46 +65,46 @@ async function retryRecursive(asyncFn, retries, retryCountInj, logError, timeout
68
65
  // then the rest of async/await pairs will be called even though AysncTimeoutError is allready thrown.
69
66
  const result = await Promise.race([
70
67
  asyncFn(),
71
- new Promise((_, reject) => setTimeout(() => reject(new async_timeout_error_1.AsyncTimeoutError()), asyncFnTimeout)),
68
+ new Promise((_, reject) => setTimeout(() => reject(new AsyncTimeoutError()), asyncFnTimeout)),
72
69
  ]);
73
70
  return result;
74
71
  }
75
72
  catch (error) {
76
73
  const remainingRetries = retries - 1;
77
74
  if (logError === RetryLogError.LOG_ALL_AS_ERRORS) {
78
- dt_logger_default_1.logger.error({
75
+ logger.error({
79
76
  message: readPossibleErrorMessage(error),
80
77
  method: "retry.retryRecursive",
81
78
  });
82
79
  }
83
80
  else if (logError === RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS) {
84
81
  if (remainingRetries < 0) {
85
- dt_logger_default_1.logger.error({
82
+ logger.error({
86
83
  message: readPossibleErrorMessage(error),
87
84
  method: "retry.retryRecursive",
88
85
  });
89
86
  }
90
87
  else {
91
- dt_logger_default_1.logger.warn({
88
+ logger.warn({
92
89
  message: readPossibleErrorMessage(error),
93
90
  method: "retry.retryRecursive",
94
91
  });
95
92
  }
96
93
  }
97
94
  if (remainingRetries < 0) {
98
- dt_logger_default_1.logger.warn({
95
+ logger.warn({
99
96
  message: "No retries left",
100
97
  method: "retry.retryRecursive",
101
98
  });
102
99
  throw new Error("No retries left");
103
100
  }
104
- dt_logger_default_1.logger.warn({
101
+ logger.warn({
105
102
  message: `Retrying with remaining retries ${remainingRetries}`,
106
103
  method: "retry.retryRecursive",
107
104
  });
108
105
  if (retryPredicate(error)) {
109
106
  retryCountInj++;
110
- exports.retryCount = retryCountInj;
107
+ retryCount = retryCountInj;
111
108
  const milliseconds = timeoutBetweenRetries(retryCountInj);
112
109
  if (milliseconds > 0) {
113
110
  await new Promise((resolve) => setTimeout(resolve, milliseconds));
@@ -128,21 +125,19 @@ async function retryRecursive(asyncFn, retries, retryCountInj, logError, timeout
128
125
  * @param retryPredicate A function that returns true if the error should be retried. Default is a function that always returns true. The function is called with the error object.
129
126
  * @return Promise return value
130
127
  */
131
- async function retry(asyncFn, retries = 3, logError = RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS, timeoutBetweenRetries = exports.timeoutFunctions.noTimeout, retryPredicate = exports.retryPredicates.alwaysRetry) {
132
- exports.retryCount = 0;
133
- dt_logger_default_1.logger.debug({
128
+ export async function retry(asyncFn, retries = 3, logError = RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS, timeoutBetweenRetries = timeoutFunctions.noTimeout, retryPredicate = retryPredicates.alwaysRetry) {
129
+ retryCount = 0;
130
+ logger.debug({
134
131
  message: `Retrying with ${retries} retries`,
135
132
  method: "retry.retry",
136
133
  });
137
134
  return retryRecursive(asyncFn, retries, 0, logError, timeoutBetweenRetries, retryPredicate);
138
135
  }
139
- exports.retry = retry;
140
136
  function wrapArgsToFn(fn, ...args) {
141
137
  return async () => await fn(...args);
142
138
  }
143
- async function retryRequest(request, ...args) {
139
+ export async function retryRequest(request, ...args) {
144
140
  const asyncFn = wrapArgsToFn(request, ...args);
145
- return retry(asyncFn, 5, RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS, exports.timeoutFunctions.exponentialTimeout, exports.retryPredicates.retryBasedOnStatusCode);
141
+ return retry(asyncFn, 5, RetryLogError.LOG_LAST_RETRY_AS_ERROR_OTHERS_AS_WARNS, timeoutFunctions.exponentialTimeout, retryPredicates.retryBasedOnStatusCode);
146
142
  }
147
- exports.retryRequest = retryRequest;
148
143
  //# sourceMappingURL=retry.js.map
@@ -1,30 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SlackApi = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const dt_logger_default_1 = require("../aws/runtime/dt-logger-default");
9
- const logging_1 = require("./logging");
10
- class SlackApi {
1
+ import axios from "axios";
2
+ import { logger } from "../aws/runtime/dt-logger-default.js";
3
+ import { logException } from "./logging.js";
4
+ export class SlackApi {
11
5
  constructor(url) {
12
6
  this.url = url;
13
7
  }
14
8
  async notify(text) {
15
9
  try {
16
- dt_logger_default_1.logger.info({
10
+ logger.info({
17
11
  method: "SlackApi.notify",
18
12
  message: "Sending slack notification",
19
13
  });
20
- await axios_1.default.post(this.url, {
14
+ await axios.post(this.url, {
21
15
  text,
22
16
  });
23
17
  }
24
18
  catch (error) {
25
- (0, logging_1.logException)(dt_logger_default_1.logger, error);
19
+ logException(logger, error);
26
20
  }
27
21
  }
28
22
  }
29
- exports.SlackApi = SlackApi;
30
23
  //# sourceMappingURL=slack.js.map
@@ -1,5 +1,5 @@
1
- import { AwsEnv } from "../types/aws-env";
2
- import { Either } from "../types/either";
1
+ import { AwsEnv } from "../types/aws-env.js";
2
+ import { Either } from "../types/either.js";
3
3
  /**
4
4
  * Check if arrays have only elements that also exists also in other array.
5
5
  * Individual element count doesn't matter.
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getErrorMessage = exports.hasOwnPropertySafe = exports.setSecretOverideAwsRegionEnv = exports.getEnvVariableOrElse = exports.getEnvVariableOr = exports.setEnvVariable = exports.getEnvVariableSafe = exports.getEnvVariable = exports.getAwsEnv = exports.getFirst = exports.getLast = exports.bothArraysHasSameValues = void 0;
4
- const environment_1 = require("../aws/runtime/environment");
1
+ import { EnvKeys } from "../aws/runtime/environment.js";
5
2
  /**
6
3
  * Check if arrays have only elements that also exists also in other array.
7
4
  * Individual element count doesn't matter.
@@ -23,7 +20,7 @@ const environment_1 = require("../aws/runtime/environment");
23
20
  * @param a first array to compare
24
21
  * @param b second array to compare
25
22
  */
26
- function bothArraysHasSameValues(a, b) {
23
+ export function bothArraysHasSameValues(a, b) {
27
24
  if ((a && !b) || (!a && b)) {
28
25
  return false;
29
26
  }
@@ -37,21 +34,18 @@ function bothArraysHasSameValues(a, b) {
37
34
  }
38
35
  return Array.from(aSet).every((value) => bSet.has(value));
39
36
  }
40
- exports.bothArraysHasSameValues = bothArraysHasSameValues;
41
37
  /**
42
38
  * Returns the last item on the array. If the array is empty, throws an error!
43
39
  */
44
- function getLast(array, sortFunction) {
40
+ export function getLast(array, sortFunction) {
45
41
  return getFirstOrLast(false, array, sortFunction);
46
42
  }
47
- exports.getLast = getLast;
48
43
  /**
49
44
  * Returns the first item on the array. If the array is empty, throws an error!
50
45
  */
51
- function getFirst(array, sortFunction) {
46
+ export function getFirst(array, sortFunction) {
52
47
  return getFirstOrLast(true, array, sortFunction);
53
48
  }
54
- exports.getFirst = getFirst;
55
49
  function getFirstOrLast(getFirst, array, sortFunction) {
56
50
  if (array.length == 0) {
57
51
  throw new Error(`can't get ${getFirst ? "first" : "last"} from empty array!`);
@@ -69,26 +63,24 @@ function getFirstOrLast(getFirst, array, sortFunction) {
69
63
  * @return string
70
64
  * @See https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
71
65
  */
72
- function getAwsEnv() {
66
+ export function getAwsEnv() {
73
67
  return {
74
68
  region: getEnvVariable("AWS_REGION"),
75
69
  };
76
70
  }
77
- exports.getAwsEnv = getAwsEnv;
78
71
  /**
79
72
  * Gets environment variable. Throws error if variable is not found.
80
73
  *
81
74
  * @param key Environment key
82
75
  * @return string
83
76
  */
84
- function getEnvVariable(key) {
77
+ export function getEnvVariable(key) {
85
78
  const either = getEnvVariableSafe(key);
86
79
  if (either.result === "error") {
87
80
  throw new Error(either.message);
88
81
  }
89
82
  return either.value;
90
83
  }
91
- exports.getEnvVariable = getEnvVariable;
92
84
  /**
93
85
  * Gets environment variable. Safe version returns object with either ok or error status.
94
86
  * Easier to use for recovery than catching an error.
@@ -96,7 +88,7 @@ exports.getEnvVariable = getEnvVariable;
96
88
  * @param key Environment key
97
89
  * @return Either<string>
98
90
  */
99
- function getEnvVariableSafe(key) {
91
+ export function getEnvVariableSafe(key) {
100
92
  const value = process.env[key];
101
93
  if (value === undefined) {
102
94
  return {
@@ -106,31 +98,28 @@ function getEnvVariableSafe(key) {
106
98
  }
107
99
  return { result: "ok", value };
108
100
  }
109
- exports.getEnvVariableSafe = getEnvVariableSafe;
110
101
  /**
111
102
  * Sets environment variable.
112
103
  *
113
104
  * @param key Environment key
114
105
  * @param value Environment variable value
115
106
  */
116
- function setEnvVariable(key, value) {
107
+ export function setEnvVariable(key, value) {
117
108
  process.env[key] = value;
118
109
  }
119
- exports.setEnvVariable = setEnvVariable;
120
110
  /**
121
111
  * Gets environment variable. If environment variable is undefined, returns value of given function.
122
112
  *
123
113
  * @param key Environment key
124
114
  * @param fn Alternative function
125
115
  */
126
- function getEnvVariableOr(key, fn) {
116
+ export function getEnvVariableOr(key, fn) {
127
117
  const either = getEnvVariableSafe(key);
128
118
  if (either.result === "ok") {
129
119
  return either.value;
130
120
  }
131
121
  return fn();
132
122
  }
133
- exports.getEnvVariableOr = getEnvVariableOr;
134
123
  /**
135
124
  * Gets environment variable. If environment variable is undefined, returns given value.
136
125
  * Use to return an explicit alternative value e.g. in cases where environment variable may be undefined.
@@ -138,14 +127,12 @@ exports.getEnvVariableOr = getEnvVariableOr;
138
127
  * @param key Environment key
139
128
  * @param orElse Alternative value
140
129
  */
141
- function getEnvVariableOrElse(key, orElse) {
130
+ export function getEnvVariableOrElse(key, orElse) {
142
131
  return getEnvVariableOr(key, () => orElse);
143
132
  }
144
- exports.getEnvVariableOrElse = getEnvVariableOrElse;
145
- function setSecretOverideAwsRegionEnv(region) {
146
- setEnvVariable(environment_1.EnvKeys.SECRET_OVERRIDE_AWS_REGION, region);
133
+ export function setSecretOverideAwsRegionEnv(region) {
134
+ setEnvVariable(EnvKeys.SECRET_OVERRIDE_AWS_REGION, region);
147
135
  }
148
- exports.setSecretOverideAwsRegionEnv = setSecretOverideAwsRegionEnv;
149
136
  /**
150
137
  * ESLint won't allow to call Object.prototype builtin methods.
151
138
  * To call hasOwnProperty we must use Object.prototype.hasOwnProperty.call()
@@ -153,19 +140,17 @@ exports.setSecretOverideAwsRegionEnv = setSecretOverideAwsRegionEnv;
153
140
  * @param propertyName property name to check
154
141
  * @see https://eslint.org/docs/latest/rules/no-prototype-builtins
155
142
  */
156
- function hasOwnPropertySafe(object, propertyName) {
143
+ export function hasOwnPropertySafe(object, propertyName) {
157
144
  return Object.prototype.hasOwnProperty.call(object, propertyName);
158
145
  }
159
- exports.hasOwnPropertySafe = hasOwnPropertySafe;
160
146
  /**
161
147
  * Return an error message from the given object hat might be an Error object.
162
148
  * @param maybeError
163
149
  */
164
- function getErrorMessage(maybeError) {
150
+ export function getErrorMessage(maybeError) {
165
151
  if (maybeError instanceof Error) {
166
152
  return maybeError.name + ": " + maybeError.message;
167
153
  }
168
154
  return String(maybeError);
169
155
  }
170
- exports.getErrorMessage = getErrorMessage;
171
156
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.1.10-1",
3
+ "version": "2024.1.19-1",
4
4
  "description": "",
5
+ "type": "module",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/tmfg/digitraffic-common.git"
@@ -16,6 +17,92 @@
16
17
  "dist/**/*.d.ts",
17
18
  "src/**/*.ts"
18
19
  ],
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./dist/database/database": "./dist/database/database.js",
23
+ "./dist/database/cached": "./dist/database/cached.js",
24
+ "./dist/database/models": "./dist/database/models.js",
25
+ "./dist/database/last-updated": "./dist/database/last-updated.js",
26
+ "./dist/types/urn": "./dist/types/urn.js",
27
+ "./dist/types/util-types": "./dist/types/util-types.js",
28
+ "./dist/types/either": "./dist/types/either.js",
29
+ "./dist/types/validator": "./dist/types/validator.js",
30
+ "./dist/types/nullable": "./dist/types/nullable.js",
31
+ "./dist/types/aws-env": "./dist/types/aws-env.js",
32
+ "./dist/types/async-timeout-error": "./dist/types/async-timeout-error.js",
33
+ "./dist/types/input-error": "./dist/types/input-error.js",
34
+ "./dist/types/http-error": "./dist/types/http-error.js",
35
+ "./dist/types/language": "./dist/types/language.js",
36
+ "./dist/types/traffictype": "./dist/types/traffictype.js",
37
+ "./dist/test/testutils": "./dist/test/testutils.js",
38
+ "./dist/test/db-testutils": "./dist/test/db-testutils.js",
39
+ "./dist/test/httpserver": "./dist/test/httpserver.js",
40
+ "./dist/test/secrets-manager": "./dist/test/secrets-manager.js",
41
+ "./dist/test/asserter": "./dist/test/asserter.js",
42
+ "./dist/marine/rtz": "./dist/marine/rtz.js",
43
+ "./dist/marine/id_utils": "./dist/marine/id_utils.js",
44
+ "./dist/index": "./dist/index.js",
45
+ "./dist/utils/api-model": "./dist/utils/api-model.js",
46
+ "./dist/utils/logging": "./dist/utils/logging.js",
47
+ "./dist/utils/base64": "./dist/utils/base64.js",
48
+ "./dist/utils/date-utils": "./dist/utils/date-utils.js",
49
+ "./dist/utils/geojson-types": "./dist/utils/geojson-types.js",
50
+ "./dist/utils/slack": "./dist/utils/slack.js",
51
+ "./dist/utils/utils": "./dist/utils/utils.js",
52
+ "./dist/utils/retry": "./dist/utils/retry.js",
53
+ "./dist/utils/geometry": "./dist/utils/geometry.js",
54
+ "./dist/aws/infra/sqs-integration": "./dist/aws/infra/sqs-integration.js",
55
+ "./dist/aws/infra/stacks/network-stack": "./dist/aws/infra/stacks/network-stack.js",
56
+ "./dist/aws/infra/stacks/db-stack": "./dist/aws/infra/stacks/db-stack.js",
57
+ "./dist/aws/infra/stacks/db-proxy-stack": "./dist/aws/infra/stacks/db-proxy-stack.js",
58
+ "./dist/aws/infra/stacks/intra-stack-configuration": "./dist/aws/infra/stacks/intra-stack-configuration.js",
59
+ "./dist/aws/infra/stacks/db-dns-stack": "./dist/aws/infra/stacks/db-dns-stack.js",
60
+ "./dist/aws/infra/documentation": "./dist/aws/infra/documentation.js",
61
+ "./dist/aws/infra/usage-plans": "./dist/aws/infra/usage-plans.js",
62
+ "./dist/aws/infra/scheduler": "./dist/aws/infra/scheduler.js",
63
+ "./dist/aws/infra/import-util": "./dist/aws/infra/import-util.js",
64
+ "./dist/aws/infra/sqs-queue": "./dist/aws/infra/sqs-queue.js",
65
+ "./dist/aws/infra/api/response": "./dist/aws/infra/api/response.js",
66
+ "./dist/aws/infra/api/static-integration": "./dist/aws/infra/api/static-integration.js",
67
+ "./dist/aws/infra/api/responses": "./dist/aws/infra/api/responses.js",
68
+ "./dist/aws/infra/api/handler-factory": "./dist/aws/infra/api/handler-factory.js",
69
+ "./dist/aws/infra/api/integration": "./dist/aws/infra/api/integration.js",
70
+ "./dist/aws/infra/stack/stack-checking-aspect": "./dist/aws/infra/stack/stack-checking-aspect.js",
71
+ "./dist/aws/infra/stack/rest_apis": "./dist/aws/infra/stack/rest_apis.js",
72
+ "./dist/aws/infra/stack/lambda-configs": "./dist/aws/infra/stack/lambda-configs.js",
73
+ "./dist/aws/infra/stack/monitoredfunction": "./dist/aws/infra/stack/monitoredfunction.js",
74
+ "./dist/aws/infra/stack/subscription": "./dist/aws/infra/stack/subscription.js",
75
+ "./dist/aws/infra/stack/parameters": "./dist/aws/infra/stack/parameters.js",
76
+ "./dist/aws/infra/stack/stack": "./dist/aws/infra/stack/stack.js",
77
+ "./dist/aws/infra/security-rule": "./dist/aws/infra/security-rule.js",
78
+ "./dist/aws/infra/canaries/database-checker": "./dist/aws/infra/canaries/database-checker.js",
79
+ "./dist/aws/infra/canaries/canary": "./dist/aws/infra/canaries/canary.js",
80
+ "./dist/aws/infra/canaries/url-checker": "./dist/aws/infra/canaries/url-checker.js",
81
+ "./dist/aws/infra/canaries/database-canary": "./dist/aws/infra/canaries/database-canary.js",
82
+ "./dist/aws/infra/canaries/canary-alarm": "./dist/aws/infra/canaries/canary-alarm.js",
83
+ "./dist/aws/infra/canaries/canary-role": "./dist/aws/infra/canaries/canary-role.js",
84
+ "./dist/aws/infra/canaries/url-canary": "./dist/aws/infra/canaries/url-canary.js",
85
+ "./dist/aws/infra/canaries/canary-parameters": "./dist/aws/infra/canaries/canary-parameters.js",
86
+ "./dist/aws/infra/canaries/canary-keys": "./dist/aws/infra/canaries/canary-keys.js",
87
+ "./dist/aws/types/proxytypes": "./dist/aws/types/proxytypes.js",
88
+ "./dist/aws/types/tags": "./dist/aws/types/tags.js",
89
+ "./dist/aws/types/mediatypes": "./dist/aws/types/mediatypes.js",
90
+ "./dist/aws/types/model-with-reference": "./dist/aws/types/model-with-reference.js",
91
+ "./dist/aws/types/errors": "./dist/aws/types/errors.js",
92
+ "./dist/aws/types/lambda-response": "./dist/aws/types/lambda-response.js",
93
+ "./dist/aws/runtime/dt-logger-default": "./dist/aws/runtime/dt-logger-default.js",
94
+ "./dist/aws/runtime/secrets/secret": "./dist/aws/runtime/secrets/secret.js",
95
+ "./dist/aws/runtime/secrets/proxy-holder": "./dist/aws/runtime/secrets/proxy-holder.js",
96
+ "./dist/aws/runtime/secrets/dbsecret": "./dist/aws/runtime/secrets/dbsecret.js",
97
+ "./dist/aws/runtime/secrets/rds-holder": "./dist/aws/runtime/secrets/rds-holder.js",
98
+ "./dist/aws/runtime/secrets/secret-holder": "./dist/aws/runtime/secrets/secret-holder.js",
99
+ "./dist/aws/runtime/dt-logger": "./dist/aws/runtime/dt-logger.js",
100
+ "./dist/aws/runtime/s3": "./dist/aws/runtime/s3.js",
101
+ "./dist/aws/runtime/messaging": "./dist/aws/runtime/messaging.js",
102
+ "./dist/aws/runtime/apikey": "./dist/aws/runtime/apikey.js",
103
+ "./dist/aws/runtime/environment": "./dist/aws/runtime/environment.js",
104
+ "./dist/aws/runtime/digitraffic-integration-response": "./dist/aws/runtime/digitraffic-integration-response.js"
105
+ },
19
106
  "peerDependencies": {
20
107
  "@types/geojson": "^7946.0.12",
21
108
  "aws-cdk-lib": "^2.103.0",
@@ -29,9 +116,11 @@
29
116
  "geojson-validation": "^1.0.2",
30
117
  "node-ttl": "^0.2.0",
31
118
  "pg-native": "^3.0.1",
32
- "pg-promise": "^11.5.4"
119
+ "pg-promise": "^11.5.4",
120
+ "lodash": "~4.17.21"
33
121
  },
34
122
  "devDependencies": {
123
+ "@jest/globals": "^29.7.0",
35
124
  "@types/aws-lambda": "8.10.131",
36
125
  "@types/etag": "1.8.3",
37
126
  "@types/geojson": "7946.0.13",
@@ -40,7 +129,19 @@
40
129
  "@types/node": "20.10.7",
41
130
  "@types/sinon": "17.0.2",
42
131
  "@typescript-eslint/eslint-plugin": "~6.18.1",
43
- "@typescript-eslint/parser": "^6.18.1",
132
+ "@typescript-eslint/parser": "^6.19.0",
133
+ "@types/geojson-validation": "^1.0.2",
134
+ "eslint": "~8.56.0",
135
+ "eslint-config-prettier": "^9.1.0",
136
+ "eslint-plugin-deprecation": "~2.0.0",
137
+ "jest": "^29.7.0",
138
+ "jest-junit": "^16.0.0",
139
+ "prettier": "^3.2.4",
140
+ "rimraf": "^5.0.5",
141
+ "sinon": "17.0.1",
142
+ "ts-jest": "^29.1.1",
143
+ "typescript": "~5.3.3",
144
+ "velocityjs": "2.0.6",
44
145
  "aws-cdk-lib": "~2.118.0",
45
146
  "aws-sdk": "~2.1531.0",
46
147
  "axios": "^1.6.5",
@@ -48,24 +149,11 @@
48
149
  "constructs": "10.3.0",
49
150
  "date-fns": "~2.30.0",
50
151
  "date-fns-tz": "~2.0.0",
51
- "eslint": "~8.56.0",
52
- "eslint-config-prettier": "^9.1.0",
53
- "eslint-plugin-deprecation": "~2.0.0",
54
152
  "etag": "^1.8.1",
55
153
  "geojson-validation": "^1.0.2",
56
- "jest": "^29.7.0",
57
- "jest-junit": "^16.0.0",
58
- "lint-staged": "^15.2.0",
59
154
  "lodash": "~4.17.21",
60
155
  "node-ttl": "^0.2.0",
61
- "pg-native": "^3.0.1",
62
- "pg-promise": "^11.5.4",
63
- "prettier": "^3.1.1",
64
- "rimraf": "^5.0.5",
65
- "sinon": "17.0.1",
66
- "ts-jest": "^29.1.1",
67
- "typescript": "~5.3.3",
68
- "velocityjs": "2.0.6"
156
+ "pg-promise": "^11.5.4"
69
157
  },
70
158
  "dependencies": {
71
159
  "@aws-sdk/client-s3": "~3.472.0",
@@ -78,7 +166,8 @@
78
166
  "eslint-report": "eslint . --format html",
79
167
  "ci:eslint-report": "eslint . --format html -o report.html || true",
80
168
  "clean": "rimraf dist output",
81
- "test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest",
169
+ "test": "node --max-old-space-size=1536 --expose-gc ./node_modules/jest/bin/jest.js --no-cache --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand",
170
+ "test:inspect": "node --inspect-brk --expose-gc ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand",
82
171
  "test:watch": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --watch"
83
172
  }
84
173
  }
@@ -1,6 +1,6 @@
1
- import { getEnvVariableOrElse } from "../../../utils/utils";
2
- import { DtLogger } from "../../runtime/dt-logger";
3
- import { LambdaResponse } from "../../types/lambda-response";
1
+ import { getEnvVariableOrElse } from "../../../utils/utils.js";
2
+ import { DtLogger } from "../../runtime/dt-logger.js";
3
+ import { LambdaResponse } from "../../types/lambda-response.js";
4
4
 
5
5
  export type LoggingHandler = (
6
6
  method: () => Promise<LambdaResponse>,
@@ -4,8 +4,8 @@ import {
4
4
  PassthroughBehavior,
5
5
  } from "aws-cdk-lib/aws-apigateway";
6
6
  import { IFunction } from "aws-cdk-lib/aws-lambda";
7
- import { MediaType } from "../../types/mediatypes";
8
- import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response";
7
+ import { MediaType } from "../../types/mediatypes.js";
8
+ import { DigitrafficIntegrationResponse } from "../../runtime/digitraffic-integration-response.js";
9
9
 
10
10
  type ParameterType =
11
11
  | "path"
@@ -1,13 +1,13 @@
1
- import { MediaType } from "../../types/mediatypes";
1
+ import { MediaType } from "../../types/mediatypes.js";
2
2
  import {
3
3
  JsonSchema,
4
4
  JsonSchemaType,
5
5
  JsonSchemaVersion,
6
6
  MethodResponse,
7
7
  Model,
8
+ type IModel
8
9
  } from "aws-cdk-lib/aws-apigateway";
9
- import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
10
- import { dateFromIsoString } from "../../../utils/date-utils";
10
+ import { dateFromIsoString } from "../../../utils/date-utils.js";
11
11
 
12
12
  /**
13
13
  * This is velocity-script, that assumes the response to be LambdaResponse(status and body).
@@ -3,21 +3,21 @@ import {
3
3
  XmlResponseTemplate,
4
4
  NotFoundResponseTemplate,
5
5
  BadRequestResponseTemplate,
6
- } from "./response";
6
+ } from "./response.js";
7
7
  import {
8
8
  LambdaIntegration,
9
9
  MethodResponse,
10
10
  IntegrationResponse,
11
11
  PassthroughBehavior,
12
+ type IModel
12
13
  } from "aws-cdk-lib/aws-apigateway";
13
14
  import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
14
- import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
15
15
  import {
16
16
  BAD_REQUEST_MESSAGE,
17
17
  ERROR_MESSAGE,
18
18
  NOT_FOUND_MESSAGE,
19
- } from "../../types/errors";
20
- import { MediaType } from "../../types/mediatypes";
19
+ } from "../../types/errors.js";
20
+ import { MediaType } from "../../types/mediatypes.js";
21
21
 
22
22
  /// @deprecated
23
23
  export const RESPONSE_200_OK: IntegrationResponse = {
@@ -4,8 +4,8 @@ import {
4
4
  PassthroughBehavior,
5
5
  Resource,
6
6
  } from "aws-cdk-lib/aws-apigateway";
7
- import { MediaType } from "../../types/mediatypes";
8
- import { RESPONSE_CORS_INTEGRATION } from "./responses";
7
+ import { MediaType } from "../../types/mediatypes.js";
8
+ import { RESPONSE_CORS_INTEGRATION } from "./responses.js";
9
9
 
10
10
  const INTEGRATION_RESPONSE_200 = `{
11
11
  "statusCode": 200
@@ -1,5 +1,5 @@
1
1
  import { Construct } from "constructs";
2
- import { CanaryParameters } from "./canary-parameters";
2
+ import { CanaryParameters } from "./canary-parameters.js";
3
3
  import { Alarm, ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
4
4
  import { Canary } from "aws-cdk-lib/aws-synthetics";
5
5
  import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
@@ -7,10 +7,10 @@ import {
7
7
  Test,
8
8
  } from "aws-cdk-lib/aws-synthetics";
9
9
  import { Role } from "aws-cdk-lib/aws-iam";
10
- import { CanaryAlarm } from "./canary-alarm";
11
- import { CanaryParameters } from "./canary-parameters";
10
+ import { CanaryAlarm } from "./canary-alarm.js";
11
+ import { CanaryParameters } from "./canary-parameters.js";
12
12
  import { Construct } from "constructs";
13
- import { LambdaEnvironment } from "../stack/lambda-configs";
13
+ import { LambdaEnvironment } from "../stack/lambda-configs.js";
14
14
 
15
15
  export class DigitrafficCanary extends Canary {
16
16
  constructor(
@@ -4,9 +4,9 @@ import { CfnCanary } from "aws-cdk-lib/aws-synthetics";
4
4
  import { Schedule } from "aws-cdk-lib/aws-events";
5
5
  import { Duration } from "aws-cdk-lib";
6
6
 
7
- import { CanaryParameters } from "./canary-parameters";
8
- import { DigitrafficCanary } from "./canary";
9
- import { DigitrafficStack } from "../stack/stack";
7
+ import { CanaryParameters } from "./canary-parameters.js";
8
+ import { DigitrafficCanary } from "./canary.js";
9
+ import { DigitrafficStack } from "../stack/stack.js";
10
10
 
11
11
  export class DatabaseCanary extends DigitrafficCanary {
12
12
  constructor(
@@ -1,9 +1,9 @@
1
- import { DTDatabase, inDatabaseReadonly } from "../../../database/database";
2
- import { ProxyHolder } from "../../runtime/secrets/proxy-holder";
3
- import { RdsHolder } from "../../runtime/secrets/rds-holder";
4
- import { getEnvVariable } from "../../../utils/utils";
5
- import { Countable } from "../../../database/models";
6
- import { logger } from "../../runtime/dt-logger-default";
1
+ import { DTDatabase, inDatabaseReadonly } from "../../../database/database.js";
2
+ import { ProxyHolder } from "../../runtime/secrets/proxy-holder.js";
3
+ import { RdsHolder } from "../../runtime/secrets/rds-holder.js";
4
+ import { getEnvVariable } from "../../../utils/utils.js";
5
+ import { Countable } from "../../../database/models.js";
6
+ import { logger } from "../../runtime/dt-logger-default.js";
7
7
 
8
8
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
9
9
  const synthetics = require("Synthetics");