lambda-essentials-ts 5.1.10 → 5.2.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ 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.2.0] - 2023-06-08
8
+
9
+ ### Added
10
+
11
+ Tracking of `canonicalId` and `correlationId` in New Relic.
12
+
13
+ !IMPORTANT! You must exclude the `newrelic` module from `webpack.config.ts` like so:
14
+
15
+ ```
16
+ externals: ['newrelic']
17
+ ```
18
+
19
+ ### Added
20
+
21
+ The `DeleteRequest` model.
22
+
7
23
  ## [5.1.10] - 2023-01-13
8
24
 
9
25
  ### Changed
package/lib/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import HttpClient, { HttpClientOptions, HttpLogOptions, HttpLogType } from './ht
2
2
  import Logger, { LoggerConfiguration, SuggestedLogObject } from './logger/logger';
3
3
  import OpenApiWrapper from './openApi/openApiWrapper';
4
4
  import { ApiResponse } from './openApi/apiResponseModel';
5
- import { ApiRequest, GetRequest, PostRequest, PutRequest } from './openApi/apiRequestModel';
5
+ import { ApiRequest, DeleteRequest, GetRequest, PostRequest, PutRequest } from './openApi/apiRequestModel';
6
6
  import { TokenProviderHttpClient } from './tokenProvider/tokenProvider';
7
7
  import KmsTokenProvider, { KmsTokenProviderOptions, KmsTokenConfiguration } from './tokenProvider/kmsTokenProvider';
8
8
  import SecretsManagerTokenProvider, { SecretsManagerTokenProviderOptions, SecretsManagerTokenConfiguration } from './tokenProvider/secretsManagerTokenProvider';
@@ -16,4 +16,4 @@ import { NotFoundException } from './exceptions/notFoundException';
16
16
  import { ValidationException } from './exceptions/validationException';
17
17
  import { serializeObject, serializeAxiosError } from './util';
18
18
  export { Logger, OpenApiWrapper, ApiResponse, HttpClient, HttpLogType, KmsTokenProvider, SecretsManagerTokenProvider, ValidationException, NotFoundException, InvalidDataException, InternalException, ForbiddenException, Exception, ConflictException, ClientException, serializeObject, serializeAxiosError, };
19
- export type { LoggerConfiguration, SuggestedLogObject, HttpClientOptions, HttpLogOptions, ApiRequest, GetRequest, PostRequest, PutRequest, TokenProviderHttpClient, KmsTokenProviderOptions, KmsTokenConfiguration, SecretsManagerTokenProviderOptions, SecretsManagerTokenConfiguration, };
19
+ export type { LoggerConfiguration, SuggestedLogObject, HttpClientOptions, HttpLogOptions, ApiRequest, GetRequest, PostRequest, PutRequest, DeleteRequest, TokenProviderHttpClient, KmsTokenProviderOptions, KmsTokenConfiguration, SecretsManagerTokenProviderOptions, SecretsManagerTokenConfiguration, };
@@ -46,6 +46,7 @@ class Logger {
46
46
  this.staticData = staticData;
47
47
  this.invocationId = invocationId !== null && invocationId !== void 0 ? invocationId : uuid.v4();
48
48
  }
49
+ // eslint-disable-next-line complexity
49
50
  log(message) {
50
51
  const type = typeof message;
51
52
  if (type === 'undefined' || (type === 'string' && message === '')) {
@@ -30,3 +30,5 @@ export interface PatchRequest<Body = any, Query = any> extends ApiRequest<Body,
30
30
  export interface GetRequest<Query = any> extends Omit<ApiRequest<any, Query>, 'body'> {
31
31
  queryStringParameters: Query;
32
32
  }
33
+ export interface DeleteRequest extends Omit<ApiRequest, 'body' | 'query'> {
34
+ }
@@ -1,4 +1,4 @@
1
- import { ApiRequest, GetRequest, PatchRequest, PostRequest, PutRequest } from './apiRequestModel';
1
+ import { ApiRequest, DeleteRequest, GetRequest, PatchRequest, PostRequest, PutRequest } from './apiRequestModel';
2
2
  import { ApiResponse } from './apiResponseModel';
3
3
  import { Exception } from '../exceptions/exception';
4
4
  export interface OpenApiModel {
@@ -6,7 +6,7 @@ export interface OpenApiModel {
6
6
  post: ApiControllerRoute<PostRequest>;
7
7
  put: ApiControllerRoute<PutRequest>;
8
8
  patch: ApiControllerRoute<PatchRequest>;
9
- delete: ApiControllerRoute;
9
+ delete: ApiControllerRoute<DeleteRequest>;
10
10
  head: ApiControllerRoute;
11
11
  options: ApiControllerRoute;
12
12
  any: ApiControllerRoute;
@@ -1,14 +1,17 @@
1
1
  import { OpenApiModel } from './openApiModel';
2
+ export interface OpenApiWrapperConfig {
3
+ enableNewRelicTracking: boolean;
4
+ }
2
5
  export default class OpenApiWrapper {
3
6
  private readonly notSet;
4
7
  private readonly cleared;
5
- private readonly canonicalIdKey;
6
8
  api: OpenApiModel;
7
9
  private userToken;
8
10
  private userPrincipal;
9
11
  private requestId;
10
12
  private correlationId;
11
- constructor(requestLogger: any);
13
+ private newrelic;
14
+ constructor(requestLogger: any, config?: OpenApiWrapperConfig);
12
15
  getUserToken(): string;
13
16
  getRequestId(): string;
14
17
  getUserPrincipal(): string;
@@ -33,17 +33,20 @@ const exception_1 = require("../exceptions/exception");
33
33
  const util_1 = require("../util");
34
34
  const shared_1 = require("../shared");
35
35
  class OpenApiWrapper {
36
- constructor(requestLogger) {
36
+ constructor(requestLogger, config) {
37
37
  this.notSet = 'not-set';
38
38
  this.cleared = 'cleared';
39
- this.canonicalIdKey = 'https://claims.cimpress.io/canonical_id';
40
39
  this.userToken = this.notSet;
41
40
  this.userPrincipal = this.notSet;
42
41
  this.requestId = this.notSet;
43
42
  this.correlationId = this.notSet;
43
+ if (config === null || config === void 0 ? void 0 : config.enableNewRelicTracking) {
44
+ // eslint-disable-next-line global-require
45
+ this.newrelic = require('newrelic');
46
+ }
44
47
  // @ts-ignore Later Use the options Type from OpenApiFactory
45
48
  this.api = new openapi_factory_1.default({
46
- requestMiddleware: (request) => {
49
+ requestMiddleware: async (request) => {
47
50
  var _a, _b, _c, _d, _e, _f;
48
51
  const correlationId = this.generateCorrelationId(request.headers);
49
52
  requestLogger.startInvocation(null, correlationId);
@@ -68,9 +71,15 @@ class OpenApiWrapper {
68
71
  user: this.userPrincipal,
69
72
  query: request.multiValueQueryStringParameters,
70
73
  });
74
+ if (config === null || config === void 0 ? void 0 : config.enableNewRelicTracking) {
75
+ this.newrelic.addCustomAttributes({
76
+ canonicalId: this.userPrincipal,
77
+ correlationId,
78
+ });
79
+ }
71
80
  return request;
72
81
  },
73
- responseMiddleware: (request, response) => {
82
+ responseMiddleware: async (request, response) => {
74
83
  requestLogger.log({
75
84
  title: 'ResponseLogger',
76
85
  level: 'INFO',
@@ -80,7 +89,7 @@ class OpenApiWrapper {
80
89
  this.clearContext();
81
90
  return response.withCorrelationId(correlationId);
82
91
  },
83
- errorMiddleware: (request, error) => {
92
+ errorMiddleware: async (request, error) => {
84
93
  const { correlationId } = this;
85
94
  this.clearContext();
86
95
  const serializedError = (0, util_1.serializeObject)(error, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-essentials-ts",
3
- "version": "5.1.10",
3
+ "version": "5.2.1",
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,
@@ -33,12 +33,13 @@
33
33
  "is-error": "~2.2.2",
34
34
  "jsonwebtoken": "9.0.0",
35
35
  "md5": "~2.3.0",
36
- "openapi-factory": "5.2.38",
36
+ "openapi-factory": "5.4.60",
37
37
  "retry-axios": "~2.6.0",
38
38
  "uuid": "~8.3.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^26.0.20",
42
+ "@types/newrelic": "^9.14.0",
42
43
  "eslint": "^7.18.0",
43
44
  "eslint-config-cimpress-atsquad": "^2.1.2",
44
45
  "husky": "^4.2.5",
@@ -72,6 +73,9 @@
72
73
  "collectCoverage": false
73
74
  },
74
75
  "engines": {
75
- "node": ">=12.0.0"
76
+ "node": ">=14.0.0"
77
+ },
78
+ "peerDependencies": {
79
+ "newrelic": "^10.2.0"
76
80
  }
77
81
  }