lambda-essentials-ts 5.1.6 → 5.1.8

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.8] - 2022-12-15
8
+
9
+ ### Changed
10
+
11
+ Removed client_secret from API response
12
+
13
+ ## [5.1.7] - 2022-12-13
14
+
15
+ ### Changed
16
+
17
+ Add timeout option in HttpClient. If no value is provided the default is no timeout.
18
+
7
19
  ## [5.1.6] - 2022-11-30
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({
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  const uuid = __importStar(require("uuid"));
31
31
  const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify"));
32
32
  const is_error_1 = __importDefault(require("is-error"));
33
+ const util_1 = require("../util");
33
34
  class Logger {
34
35
  constructor(configuration) {
35
36
  var _a, _b;
@@ -74,12 +75,9 @@ class Logger {
74
75
  const truncateToken = (innerPayload) => {
75
76
  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
77
  };
77
- const truncateSecret = (data) => {
78
- return data.replace(/(\\*"client_secret\\*":\\*")([a-zA-Z0-9_+=.@/-]{60,})(\\*")/gi, (m, p1, p2, p3) => `${p1}<REDACTED>${p3}`);
79
- };
80
78
  const replacer = (key, value) => ((0, is_error_1.default)(value) ? Logger.errorToObject(value) : value);
81
79
  let stringifiedPayload = truncateToken((0, fast_safe_stringify_1.default)(payload, replacer, this.jsonSpace));
82
- stringifiedPayload = truncateSecret(stringifiedPayload);
80
+ stringifiedPayload = (0, util_1.redactSecret)(stringifiedPayload);
83
81
  // https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html 256KB => 32768 characters
84
82
  if (stringifiedPayload.length >= 32768) {
85
83
  const replacementPayload = {
@@ -83,7 +83,7 @@ class OpenApiWrapper {
83
83
  errorMiddleware: (request, error) => {
84
84
  const { correlationId } = this;
85
85
  this.clearContext();
86
- const serializedError = (0, util_1.serializeObject)(error);
86
+ const serializedError = (0, util_1.serializeObject)(error, true);
87
87
  if (error instanceof exception_1.Exception) {
88
88
  if (error.statusCode === 500) {
89
89
  requestLogger.log({ title: 'ErrorLogger', level: 'ERROR', ...serializedError });
package/lib/util.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { AxiosError } from 'axios';
2
2
  export declare function safeJwtCanonicalIdParse(jwtToken: string): string | undefined;
3
3
  export declare function safeJsonParse(input: any, defaultValue: unknown): unknown;
4
- export declare function serializeObject(obj: unknown): object;
4
+ export declare const redactSecret: (data: string) => string;
5
+ export declare function serializeObject(obj: unknown, redact?: boolean): object;
5
6
  export declare function serializeAxiosError(error: AxiosError): SerializedAxiosError | undefined;
6
7
  export interface SerializedAxiosError {
7
8
  status: number;
package/lib/util.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.serializeAxiosError = exports.serializeObject = exports.safeJsonParse = exports.safeJwtCanonicalIdParse = void 0;
6
+ exports.serializeAxiosError = exports.serializeObject = exports.redactSecret = exports.safeJsonParse = exports.safeJwtCanonicalIdParse = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
8
  function safeJwtCanonicalIdParse(jwtToken) {
9
9
  var _a;
@@ -24,15 +24,22 @@ function safeJsonParse(input, defaultValue) {
24
24
  }
25
25
  }
26
26
  exports.safeJsonParse = safeJsonParse;
27
- function serializeObject(obj) {
27
+ const redactSecret = (data) => {
28
+ return data.replace(/(\\*"*'*client_secret\\*"*'*:\s*\\*"*'*)([^"'\\]+)(\\*"*'*)/gi, (m, p1, p2, p3) => `${p1}<REDACTED>${p3}`);
29
+ };
30
+ exports.redactSecret = redactSecret;
31
+ function serializeObject(obj, redact) {
32
+ let modObj = obj;
28
33
  if (obj && typeof obj === 'object') {
29
- return Object.getOwnPropertyNames(obj).reduce((map, key) => {
34
+ modObj = Object.getOwnPropertyNames(obj).reduce((map, key) => {
30
35
  // eslint-disable-next-line no-param-reassign
31
36
  map[key] = obj[key];
32
37
  return map;
33
38
  }, {});
34
39
  }
35
- return JSON.parse(JSON.stringify(obj));
40
+ return redact
41
+ ? JSON.parse((0, exports.redactSecret)(JSON.stringify(modObj)))
42
+ : JSON.parse(JSON.stringify(modObj));
36
43
  }
37
44
  exports.serializeObject = serializeObject;
38
45
  function serializeAxiosError(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-essentials-ts",
3
- "version": "5.1.6",
3
+ "version": "5.1.8",
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,