lambda-essentials-ts 5.4.0 → 6.1.0
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 +7 -0
- package/lib/exceptions/clientException.d.ts +1 -1
- package/lib/exceptions/clientException.js +2 -2
- package/lib/httpClient/httpClient.js +2 -2
- package/lib/tokenProvider/kmsTokenProvider.d.ts +2 -2
- package/lib/tokenProvider/kmsTokenProvider.js +5 -5
- package/lib/tokenProvider/secretsManagerTokenProvider.d.ts +2 -2
- package/lib/tokenProvider/secretsManagerTokenProvider.js +4 -3
- package/lib/util.d.ts +1 -0
- package/lib/util.js +2 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ 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
|
+
## [6.0.0] - 2022-02-22
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **[Breaking change]** Upgraded aws-sdk to v3 which has `SecretsManager` and `KMS` replaced by `SecretsManagerClient` and `KMSClient` class.
|
|
12
|
+
The functionality and interface remains the same, the imports need to be changed.
|
|
13
|
+
|
|
7
14
|
## [5.4.0] - 2024-02-08
|
|
8
15
|
|
|
9
16
|
### Added
|
|
@@ -3,6 +3,6 @@ export declare class ClientException extends Exception {
|
|
|
3
3
|
readonly serviceName: string;
|
|
4
4
|
readonly originalStatusCode?: number;
|
|
5
5
|
private static readonly statusCodeMap;
|
|
6
|
-
constructor(serviceName: string, originalStatusCode?: number, details?: any, statusCodeMapOverride?: Record<number, number>);
|
|
6
|
+
constructor(serviceName: string, originalStatusCode?: number, details?: any, originalMessage?: string, statusCodeMapOverride?: Record<number, number>);
|
|
7
7
|
private static convertStatusCode;
|
|
8
8
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ClientException = void 0;
|
|
4
4
|
const exception_1 = require("./exception");
|
|
5
5
|
class ClientException extends exception_1.Exception {
|
|
6
|
-
constructor(serviceName, originalStatusCode, details, statusCodeMapOverride) {
|
|
7
|
-
super(`Dependent service "${serviceName}" returned error`, ClientException.convertStatusCode(originalStatusCode, statusCodeMapOverride), details);
|
|
6
|
+
constructor(serviceName, originalStatusCode, details, originalMessage, statusCodeMapOverride) {
|
|
7
|
+
super(`Dependent service "${serviceName}" returned error: ${originalMessage !== null && originalMessage !== void 0 ? originalMessage : 'Unknown error'}`, ClientException.convertStatusCode(originalStatusCode, statusCodeMapOverride), details);
|
|
8
8
|
this.serviceName = serviceName;
|
|
9
9
|
this.originalStatusCode = originalStatusCode;
|
|
10
10
|
}
|
|
@@ -130,7 +130,7 @@ class HttpClient {
|
|
|
130
130
|
const hostname = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url)
|
|
131
131
|
? new url_1.URL(error.config.url, error.config.baseURL).hostname
|
|
132
132
|
: 'N/A';
|
|
133
|
-
throw new clientException_1.ClientException(hostname, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.status, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.details, this.clientExceptionStatusCodeMapOverride);
|
|
133
|
+
throw new clientException_1.ClientException(hostname, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.status, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.details, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.message, this.clientExceptionStatusCodeMapOverride);
|
|
134
134
|
});
|
|
135
135
|
this.client.interceptors.response.use((response) => {
|
|
136
136
|
if (this.logOptions.enabledLogs.includes(HttpLogType.responses)) {
|
|
@@ -169,7 +169,7 @@ class HttpClient {
|
|
|
169
169
|
const hostname = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url)
|
|
170
170
|
? new url_1.URL(error.config.url, error.config.baseURL).hostname
|
|
171
171
|
: 'N/A';
|
|
172
|
-
throw new clientException_1.ClientException(hostname, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.status, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.details, this.clientExceptionStatusCodeMapOverride);
|
|
172
|
+
throw new clientException_1.ClientException(hostname, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.status, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.details, serializedAxiosError === null || serializedAxiosError === void 0 ? void 0 : serializedAxiosError.message, this.clientExceptionStatusCodeMapOverride);
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
static extractRequestLogData(requestConfig) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KMS } from 'aws-sdk';
|
|
2
1
|
import TokenProvider, { Auth0Secret, TokenConfiguration, TokenProviderOptions } from './tokenProvider';
|
|
2
|
+
import { KMSClient } from '@aws-sdk/client-kms';
|
|
3
3
|
export default class KmsTokenProvider extends TokenProvider {
|
|
4
4
|
private kmsClient;
|
|
5
5
|
private kmsConfiguration;
|
|
@@ -10,7 +10,7 @@ export interface KmsTokenProviderOptions extends TokenProviderOptions {
|
|
|
10
10
|
/**
|
|
11
11
|
* AWS KMS Client
|
|
12
12
|
*/
|
|
13
|
-
kmsClient:
|
|
13
|
+
kmsClient: KMSClient;
|
|
14
14
|
/**
|
|
15
15
|
* Configuration needed for the token
|
|
16
16
|
*/
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const tokenProvider_1 = __importDefault(require("./tokenProvider"));
|
|
7
|
+
const client_kms_1 = require("@aws-sdk/client-kms");
|
|
7
8
|
class KmsTokenProvider extends tokenProvider_1.default {
|
|
8
9
|
constructor(options) {
|
|
9
10
|
super(options);
|
|
@@ -11,12 +12,11 @@ class KmsTokenProvider extends tokenProvider_1.default {
|
|
|
11
12
|
this.kmsConfiguration = options.tokenConfiguration;
|
|
12
13
|
}
|
|
13
14
|
async getClientSecret() {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
var _a;
|
|
16
|
+
const data = await this.kmsClient.send(new client_kms_1.DecryptCommand({
|
|
16
17
|
CiphertextBlob: Buffer.from(this.kmsConfiguration.encryptedClientSecret, 'base64'),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
.then((data) => { var _a; return (_a = data.Plaintext) === null || _a === void 0 ? void 0 : _a.toString(); });
|
|
18
|
+
}));
|
|
19
|
+
const secret = (_a = data.Plaintext) === null || _a === void 0 ? void 0 : _a.toString();
|
|
20
20
|
if (!secret) {
|
|
21
21
|
throw new Error('Request error: failed to decrypt secret using KMS');
|
|
22
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SecretsManager } from 'aws-sdk';
|
|
2
1
|
import TokenProvider, { Auth0Secret, TokenConfiguration, TokenProviderOptions } from './tokenProvider';
|
|
2
|
+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
3
3
|
export default class SecretsManagerTokenProvider extends TokenProvider {
|
|
4
4
|
private secretsManagerClient;
|
|
5
5
|
private secretsManagerConfiguration;
|
|
@@ -10,7 +10,7 @@ export interface SecretsManagerTokenProviderOptions extends TokenProviderOptions
|
|
|
10
10
|
/**
|
|
11
11
|
* AWS Secrets Manager Client
|
|
12
12
|
*/
|
|
13
|
-
secretsManagerClient:
|
|
13
|
+
secretsManagerClient: SecretsManagerClient;
|
|
14
14
|
/**
|
|
15
15
|
* Configuration needed for the token
|
|
16
16
|
*/
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const tokenProvider_1 = __importDefault(require("./tokenProvider"));
|
|
7
|
+
const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
|
|
7
8
|
class SecretsManagerTokenProvider extends tokenProvider_1.default {
|
|
8
9
|
constructor(options) {
|
|
9
10
|
super(options);
|
|
@@ -11,9 +12,9 @@ class SecretsManagerTokenProvider extends tokenProvider_1.default {
|
|
|
11
12
|
this.secretsManagerConfiguration = options.tokenConfiguration;
|
|
12
13
|
}
|
|
13
14
|
async getClientSecret() {
|
|
14
|
-
const secret = await this.secretsManagerClient
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const secret = await this.secretsManagerClient.send(new client_secrets_manager_1.GetSecretValueCommand({
|
|
16
|
+
SecretId: this.secretsManagerConfiguration.clientSecretId,
|
|
17
|
+
}));
|
|
17
18
|
if (!(secret === null || secret === void 0 ? void 0 : secret.SecretString)) {
|
|
18
19
|
throw new Error('Request error: failed to retrieve secret from Secrets Manager');
|
|
19
20
|
}
|
package/lib/util.d.ts
CHANGED
package/lib/util.js
CHANGED
|
@@ -53,7 +53,8 @@ function serializeAxiosError(error) {
|
|
|
53
53
|
const { status, data } = error.response;
|
|
54
54
|
return {
|
|
55
55
|
status: (_a = data.originalStatusCode) !== null && _a !== void 0 ? _a : status,
|
|
56
|
-
details: data.details && Object.keys(data.details).length > 0 ? data.details : data,
|
|
56
|
+
details: data.details && Object.keys(data.details).length > 0 ? data.details : data,
|
|
57
|
+
message: data.message,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
exports.serializeAxiosError = serializeAxiosError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambda-essentials-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
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,
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/Cimpress-MCP/lambda-essentials-ts#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"aws-sdk": "^
|
|
29
|
+
"@aws-sdk/client-kms": "^3.569.0",
|
|
30
|
+
"@aws-sdk/client-secrets-manager": "^3.569.0",
|
|
30
31
|
"axios": "~0.21.3",
|
|
31
32
|
"axios-cache-adapter": "~2.7.3",
|
|
32
33
|
"fast-safe-stringify": "~2.0.7",
|