lambda-essentials-ts 7.0.0-beta → 7.0.4

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.
@@ -1,2 +1 @@
1
- import { createClient } from 'redis';
2
- export default function createRedisStorage(client: ReturnType<typeof createClient>): import("axios-cache-interceptor").AxiosStorage;
1
+ export default function createRedisStorage(redisEndpoint: string): import("axios-cache-interceptor").AxiosStorage;
@@ -4,15 +4,24 @@ exports.default = createRedisStorage;
4
4
  const axios_cache_interceptor_1 = require("axios-cache-interceptor");
5
5
  const KEY_PREFIX = 'axios-cache-';
6
6
  const MIN_TTL = 60000;
7
- function createRedisStorage(client) {
7
+ function createRedisStorage(redisEndpoint) {
8
+ // eslint-disable-next-line import/no-extraneous-dependencies
9
+ const redis = require('redis');
10
+ const client = redis.createClient({ url: redisEndpoint });
8
11
  // source https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage
9
12
  return (0, axios_cache_interceptor_1.buildStorage)({
10
13
  async find(key) {
14
+ if (!client.isReady) {
15
+ await client.connect();
16
+ }
11
17
  const result = await client.get(`${KEY_PREFIX}${key}`);
12
18
  return result ? JSON.parse(result) : undefined;
13
19
  },
14
20
  // eslint-disable-next-line complexity
15
21
  async set(key, value, req) {
22
+ if (!client.isReady) {
23
+ await client.connect();
24
+ }
16
25
  await client.set(`${KEY_PREFIX}${key}`, JSON.stringify(value), {
17
26
  PXAT:
18
27
  // We don't want to keep indefinitely values in the storage if
@@ -30,6 +39,9 @@ function createRedisStorage(client) {
30
39
  });
31
40
  },
32
41
  async remove(key) {
42
+ if (!client.isReady) {
43
+ await client.connect();
44
+ }
33
45
  await client.del(`${KEY_PREFIX}${key}`);
34
46
  },
35
47
  });
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
7
7
  const httpClient_1 = __importDefault(require("../httpClient/httpClient"));
8
+ const logger_1 = __importDefault(require("../logger/logger"));
8
9
  class TokenProvider {
9
10
  /**
10
11
  * Create a new Instance of the TokenProvider
@@ -13,6 +14,7 @@ class TokenProvider {
13
14
  this.httpClient =
14
15
  options.httpClient ??
15
16
  new httpClient_1.default({
17
+ logFunction: (msg) => new logger_1.default().log(msg),
16
18
  enableCache: false,
17
19
  enableRetry: true,
18
20
  retryOptions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-essentials-ts",
3
- "version": "7.0.0-beta",
3
+ "version": "7.0.4",
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,
@@ -28,12 +28,12 @@
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-kms": "^3.930.0",
30
30
  "@aws-sdk/client-secrets-manager": "^3.930.0",
31
- "@types/node": "^24.10.1",
31
+ "@types/node": "^25.0.3",
32
32
  "axios": "1.13.2",
33
- "axios-cache-interceptor": "^1.8.3",
33
+ "axios-cache-interceptor": "1.11.2",
34
34
  "fast-safe-stringify": "~2.1.1",
35
35
  "is-error": "~2.2.2",
36
- "jsonwebtoken": "9.0.2",
36
+ "jsonwebtoken": "9.0.3",
37
37
  "md5": "~2.3.0",
38
38
  "openapi-factory": "5.4.60",
39
39
  "retry-axios": "~3.2.1",
@@ -42,17 +42,17 @@
42
42
  "devDependencies": {
43
43
  "@types/jest": "^29.5.14",
44
44
  "@types/newrelic": "^9.14.8",
45
- "redis": "^5.9.0",
46
45
  "axios-mock-adapter": "^2.1.0",
47
46
  "eslint": "^8.57.1",
48
- "eslint-config-cimpress-atsquad": "^2.2.0-beta",
47
+ "eslint-config-cimpress-atsquad": "^2.2.3",
49
48
  "husky": "^9.1.7",
50
49
  "jest": "^29.7.0",
51
50
  "lint-staged": "^15.5.2",
52
51
  "prettier": "^2.8.8",
53
- "ts-jest": "^29.4.5",
52
+ "ts-jest": "^29.4.6",
54
53
  "ts-node": "^10.9.2",
55
- "typescript": "^5.9.3"
54
+ "typescript": "^5.9.3",
55
+ "redis": "^5.10.0"
56
56
  },
57
57
  "eslintConfig": {
58
58
  "extends": "cimpress-atsquad"
package/CHANGELOG.md DELETED
@@ -1,280 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
-
7
- ## [7.0.0-beta] - 2025-11-14
8
-
9
- ### Changed
10
-
11
- - Add 429 status code mapping
12
- - Changed logging format. Removed the inner `message` object.
13
- - Update packages
14
- - Use axios-cache-interceptor instead of axios-cache-adapter
15
-
16
- ## [6.1.1] - 2025-10-27
17
-
18
- ### Changed
19
-
20
- - TokenProviderHttpClient now uses the http client with retries as default.
21
-
22
- ## [6.1.0] - 2024-09-30
23
-
24
- ### Changed
25
-
26
- - Preserve the original message in ClientException
27
-
28
- ## [6.0.0] - 2024-02-22
29
-
30
- ### Changed
31
-
32
- - **[Breaking change]** Upgraded aws-sdk to v3 which has `SecretsManager` and `KMS` replaced by `SecretsManagerClient` and `KMSClient` class.
33
- The functionality and interface remains the same, the imports need to be changed.
34
-
35
- ## [5.4.0] - 2024-02-08
36
-
37
- ### Added
38
-
39
- HttpClient options now accept `clientExceptionStatusCodeMapOverride` which can be used to override the default HTTP error status code mapping. This is useful e.g. when a dependent service is not following REST-ful best practices and e.g. returns a 403 when there's an intermittent network error communicating with the authorization service
40
-
41
- ## [5.3.2] - 2024-02-08
42
-
43
- ### Fixed
44
-
45
- Error details of external HTTP error responses are propagated correctly
46
-
47
- ## [5.3.1] - 2023-10-25
48
-
49
- ### Fixed
50
-
51
- The `getUserToken()` and `getUserPrincipal()` order was wrongly set in version `5.3.0`. The new fixed
52
- priority order:
53
-
54
- `getUserToken()`
55
-
56
- 1. `request.authorizerContext.jwt`
57
- 2. `request.authorizerContext.accessToken` (new)
58
- 3. `request.headers.Authorization`
59
-
60
- `getUserPrincipal()`
61
-
62
- 1. `authorizerContext.canonicalId` (**prefer canonicalId**)
63
- 2. `authorizerContext.principalId` (new)
64
- 3. `request.headers.Authorization`
65
-
66
- ## [5.3.0] - 2023-09-07
67
-
68
- ### Changed
69
-
70
- The `getUserToken()` and `getUserPrincipal()` methods now support multiple sources of for their values
71
-
72
- `getUserToken()` in priority order:
73
-
74
- 1. `request.authorizerContext.accessToken` (new)
75
- 2. `request.authorizerContext.jwt`
76
- 3. `request.headers.Authorization`
77
-
78
- `getUserPrincipal()` in priority order:
79
-
80
- 1. `authorizerContext.principalId` (new)
81
- 2. `authorizerContext.canonicalId`
82
- 3. `request.headers.Authorization`
83
-
84
- ## [5.2.2] - 2023-08-25
85
-
86
- ### Added
87
-
88
- HttpClient now also logs unexpected (e.g. network) errors that are not coming from Axios
89
-
90
- ## [5.2.0] - 2023-06-08
91
-
92
- ### Added
93
-
94
- Tracking of `canonicalId` and `correlationId` in New Relic.
95
-
96
- !IMPORTANT! You must exclude the `newrelic` module from `webpack.config.ts` like so:
97
-
98
- ```
99
- externals: ['newrelic']
100
- ```
101
-
102
- ### Added
103
-
104
- The `DeleteRequest` model.
105
-
106
- ## [5.1.10] - 2023-01-13
107
-
108
- ### Changed
109
-
110
- The error middleware logs `4xx` errors with log level `WARN` (previously `INFO`).
111
-
112
- ## [5.1.9] - 2023-01-04
113
-
114
- ### Changed
115
-
116
- Upgraded jsonwebtoken version to 9.0.0 and aws-sdk to version 2.1287.0
117
-
118
- ## [5.1.8] - 2022-12-15
119
-
120
- ### Changed
121
-
122
- Removed client_secret from API response
123
-
124
- ## [5.1.7] - 2022-12-13
125
-
126
- ### Changed
127
-
128
- Add timeout option in HttpClient. If no value is provided the default is no timeout.
129
-
130
- ## [5.1.6] - 2022-11-30
131
-
132
- ### Changed
133
-
134
- Removed logging of client_secret
135
-
136
- ## [5.1.5] - 2022-11-15
137
-
138
- ### Changed
139
-
140
- The fix described in 5.1.4 missed one instance where the bug can occur. This change covers all known instances.
141
-
142
- ## [5.1.4] - 2022-11-08
143
-
144
- ### Changed
145
-
146
- Using `baseURL` in the axios config without specifying the full URL resulted in an error in the exception handling. So the `AxiosError` was thrown instead of a customer `ClientException`.
147
-
148
- ## [5.1.3] - 2022-10-03
149
-
150
- ### Changed
151
-
152
- RequestLogger now logs only `Host`, 'User-Agent`, `orion-correlation-id-parent`, `orion-correlation-id-root` headers.
153
-
154
- ## [5.1.2] - 2022-09-14
155
-
156
- ### Changed
157
-
158
- Properties `stageVariables`, `isBase64Encoded` and `route` from openapi-factory are available in the Typescript definitions.
159
-
160
- ## [5.1.1] - 2022-09-05
161
-
162
- ### Changed
163
-
164
- HttpApi payload version 2.0 events supported for openApiWrapper.
165
-
166
- ## [5.1.0] - 2022-09-05
167
-
168
- ### Changed
169
-
170
- Dependencies aren't pinned to a fixed version to allow users of the library to independently upgrade minor (devDependencies) and patch (dependencies) versions. This will simplify fixing security alerts faster than in this library, for example by applying `npm audit fix`.
171
-
172
- ## [5.0.0] - 2022-02-22
173
-
174
- ### Changed
175
-
176
- - **[Breaking change]** `TokenProvider` was replaced by more specific `KmsTokenProvider` class.
177
- The functionality and interface remains the same, the imports need to be changed.
178
-
179
- ### Added
180
-
181
- - New `SecretsManagerTokenProvider` that relies on AWS Secrets Manager to retrieve client ID and client secret.
182
- The advantage of using AWS Secrets Manager is that it can be supplied with a secret rotation function.
183
-
184
- ## [4.1.5] - 2022-02-10
185
-
186
- ### Changed
187
-
188
- `ClientException` now maps `HTTP 422` client responses to `HTTP 422` server responses (was `HTTP 503` before).
189
-
190
- ## [4.1.2] - 2021-12-02
191
-
192
- ### Changed
193
-
194
- Expose the `Location`, `Access-Control-Allow-Origin` and `orion-correlation-id-root` headers
195
-
196
- ## [4.1.1] - 2021-11-22
197
-
198
- ### Fixed
199
-
200
- - `ApiResponse` default content-type header was renamed to `Content-Type` to overwrite the default header
201
- of [openapi-factory.js](https://github.com/Rhosys/openapi-factory.js/blob/release/5.2/src/response.js#L15)
202
- - Also upgraded `openapi-factory.js` to get support of over-writing response headers
203
-
204
- ## [4.1.0] - 2021-11-22
205
-
206
- ### Changed
207
-
208
- - `ApiResponse` default content-type header was changed from `application/links+json` to `application/hal+json`
209
-
210
- ## [4.0.0] - 2021-11-12
211
-
212
- ### Changed
213
-
214
- - `HttpClient` the [retryAdapterEnhancer axios adapter](https://github.com/kuitos/axios-extensions#cacheadapterenhancer)
215
- was replaced by the more flexible [axios-cache-adapter](https://github.com/RasCarlito/axios-cache-adapter).
216
- - **[Breaking change]** `HttpClientOptions.cacheOptions` now accepts [extensive cache configuration](https://github.com/RasCarlito/axios-cache-adapter/blob/master/axios-cache-adapter.d.ts#L26).
217
- - The cache is now partitioned by `canonical_id` JWT claim.
218
-
219
- ## [3.0.1] - 2021-09-13
220
-
221
- ### Fixed
222
-
223
- - Downgraded Axios to 0.21.1 due to response interceptors not being applied correctly in 0.21.2. [There has been a fix to
224
- axios but a version with the fix is not available yet.](https://github.com/axios/axios/commit/83ae3830e4070adbcdcdcdd6e8afbac568afd708)
225
-
226
- ## [3.0.0] - 2021-09-10
227
-
228
- ### Changed
229
-
230
- - `HttpClient` the [retryAdapterEnhancer axios adapter](https://github.com/kuitos/axios-extensions#retryadapterenhancer)
231
- was replaced by the more flexible [retry-axios interceptor](https://github.com/JustinBeckwith/retry-axios).
232
- - **[Breaking change]** `HttpClientOptions.retryOptions` now accepts [extensive retry configuration](https://github.com/JustinBeckwith/retry-axios/blob/v2.6.0/src/index.ts#L11)
233
- such as specifying HTTP status codes that should be retried.
234
- - **[Breaking change]** All HTTP status codes are no longer retried by default. The new default are these ranges:
235
- - [100, 199] Informational, request still processing
236
- - [429, 429] Too Many Requests
237
- - [500, 599] Server errors
238
-
239
- ## [2.2.2] - 2021-07-08
240
-
241
- ### Fixed bugs
242
-
243
- - Some HTTP error log statements were throwing exceptions. This was due to accessing `error.request.headers[orionCorrelationIdRoot]`
244
- from Axios error object, where the `headers` object was `undefined`. The correct field was `error.config.headers`.
245
-
246
- ## [2.2.1] - 2021-07-08
247
-
248
- ### Changed
249
-
250
- - `HttpClient` logs additional request data (query parameters, body).
251
-
252
- ### Added
253
-
254
- - `HttpClientOptions` now accepts `logOptions` object that allows enabling informational request and **response (new)** logs.
255
-
256
- ```js
257
- {
258
- logOptions: {
259
- enabledLogs: [HttpLogType.requests, HttpLogType.responses];
260
- }
261
- }
262
- ```
263
-
264
- ## [2.1.0] - 2021-03-11
265
-
266
- ### Changed
267
-
268
- - ClientException propagates the original status code and details through multiple services. E.g. instead of `error.detials?.data.details?.userDefinedProp` use `error.details?.userDefinedProp`
269
-
270
- ## [2.0.0] - 2021-03-08
271
-
272
- ### Changed
273
-
274
- - ClientException no longer wraps details in an `error` property. Instead of `error.details?.error.userDefinedProp` use `error.details?.userDefinedProp`
275
-
276
- ## [1.2.0] - 2021-02-16
277
-
278
- ### Updated
279
-
280
- - [IMPORTANT!] HttpClient throws serialized Axios errors through ClientExceptions.