lambda-essentials-ts 5.1.5 → 5.1.7

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
6
 
7
+ ## [5.1.7] - 2022-12-13
8
+
9
+ ### Changed
10
+
11
+ Add timeout option in HttpClient. If no value is provided the default is no timeout.
12
+
13
+ ## [5.1.6] - 2022-11-30
14
+
15
+ ### Changed
16
+
17
+ Removed logging of client_secret
18
+
7
19
  ## [5.1.5] - 2022-11-15
8
20
 
9
21
  ### Changed
package/README.md CHANGED
@@ -69,6 +69,7 @@ let httpClient = new HttpClient({
69
69
  query: false, // also cache requests with query parameters
70
70
  },
71
71
  },
72
+ timeout: 1000
72
73
  });
73
74
 
74
75
  let headers = {};
@@ -16,6 +16,7 @@ export default class HttpClient {
16
16
  private readonly client;
17
17
  private readonly enableRetry;
18
18
  private readonly enableCache;
19
+ private readonly timeout?;
19
20
  /**
20
21
  * Create a new Instance of the HttpClient
21
22
  */
@@ -94,6 +95,11 @@ export interface HttpClientOptions {
94
95
  * @link https://github.com/JustinBeckwith/retry-axios/blob/v2.6.0/src/index.ts#L11
95
96
  */
96
97
  retryOptions?: RetryConfig;
98
+ /**
99
+ * Number of milliseconds before the request times out. Default or `0` is no time out.
100
+ * @link https://github.com/axios/axios/blob/main/README.md#request-config
101
+ */
102
+ timeout?: number;
97
103
  }
98
104
  /**
99
105
  * Log options object.
@@ -61,6 +61,7 @@ class HttpClient {
61
61
  this.correlationIdResolverFunction = options === null || options === void 0 ? void 0 : options.correlationIdResolver;
62
62
  this.enableCache = (_c = options === null || options === void 0 ? void 0 : options.enableCache) !== null && _c !== void 0 ? _c : false;
63
63
  this.enableRetry = (_d = options === null || options === void 0 ? void 0 : options.enableRetry) !== null && _d !== void 0 ? _d : false;
64
+ this.timeout = options === null || options === void 0 ? void 0 : options.timeout;
64
65
  this.client =
65
66
  (_e = options === null || options === void 0 ? void 0 : options.client) !== null && _e !== void 0 ? _e : axios_1.default.create({
66
67
  adapter: (() => {
@@ -101,6 +102,9 @@ class HttpClient {
101
102
  // attach retry-axios
102
103
  rax.attach(this.client);
103
104
  }
105
+ if (this.timeout) {
106
+ this.client.defaults.timeout = this.timeout;
107
+ }
104
108
  this.client.interceptors.request.use((config) => {
105
109
  if (this.logOptions.enabledLogs.includes(HttpLogType.requests)) {
106
110
  this.logFunction({
@@ -74,8 +74,12 @@ class Logger {
74
74
  const truncateToken = (innerPayload) => {
75
75
  return innerPayload.replace(/(eyJ[a-zA-Z0-9_-]{5,}\.eyJ[a-zA-Z0-9_-]{5,})\.[a-zA-Z0-9_-]*/gi, (m, p1) => `${p1}.<sig>`);
76
76
  };
77
+ const truncateSecret = (data) => {
78
+ return data.replace(/(\\*"client_secret\\*":\\*")([a-zA-Z0-9_+=.@/-]{60,})(\\*")/gi, (m, p1, p2, p3) => `${p1}<REDACTED>${p3}`);
79
+ };
77
80
  const replacer = (key, value) => ((0, is_error_1.default)(value) ? Logger.errorToObject(value) : value);
78
81
  let stringifiedPayload = truncateToken((0, fast_safe_stringify_1.default)(payload, replacer, this.jsonSpace));
82
+ stringifiedPayload = truncateSecret(stringifiedPayload);
79
83
  // https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html 256KB => 32768 characters
80
84
  if (stringifiedPayload.length >= 32768) {
81
85
  const replacementPayload = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-essentials-ts",
3
- "version": "5.1.5",
3
+ "version": "5.1.7",
4
4
  "description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
5
5
  "main": "lib/index.js",
6
6
  "private": false,