@lucaapp/service-utils 5.43.0 → 5.44.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
|
-
import type { ErrorRequestHandler } from 'express';
|
|
2
|
+
import type { ErrorRequestHandler, RequestHandler } from 'express';
|
|
3
3
|
export type ErrorReportingOptions = {
|
|
4
4
|
dsn?: string;
|
|
5
5
|
serviceName: string;
|
|
@@ -20,5 +20,6 @@ export declare const isErrorReportingEnabled: () => boolean;
|
|
|
20
20
|
export declare const statusOf: (error: unknown) => number;
|
|
21
21
|
export declare const captureServerError: (error: unknown, context?: ServerErrorContext) => void;
|
|
22
22
|
export declare const errorReportingHandler: ErrorRequestHandler;
|
|
23
|
+
export declare const errorReportingMiddleware: RequestHandler;
|
|
23
24
|
export declare const exitAfterReport: (error: unknown) => void;
|
|
24
25
|
export declare const closeErrorReporting: () => Promise<void>;
|
|
@@ -33,14 +33,29 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.closeErrorReporting = exports.exitAfterReport = exports.errorReportingHandler = exports.captureServerError = exports.statusOf = exports.isErrorReportingEnabled = exports.initErrorReporting = exports.scrubEvent = exports.scrubValue = exports.scrubString = void 0;
|
|
36
|
+
exports.closeErrorReporting = exports.exitAfterReport = exports.errorReportingMiddleware = exports.errorReportingHandler = exports.captureServerError = exports.statusOf = exports.isErrorReportingEnabled = exports.initErrorReporting = exports.scrubEvent = exports.scrubValue = exports.scrubString = void 0;
|
|
37
37
|
const Sentry = __importStar(require("@sentry/node"));
|
|
38
38
|
const boom_1 = require("@hapi/boom");
|
|
39
39
|
const DEFAULT_FLUSH_TIMEOUT_MS = 800;
|
|
40
40
|
const MAX_DEPTH = 8;
|
|
41
|
+
// Bounds regex backtracking in beforeSend.
|
|
42
|
+
const MAX_STRING_LENGTH = 4096;
|
|
41
43
|
const FILTERED = '[Filtered]';
|
|
42
|
-
const SENSITIVE_KEY = /auth|cookie|token|secret|passw|passcode|^pin$|session|e-?mail|phone|iban|card|(^|_)pan($|_|number)|cvc|cvv|shopper|reservation|booking|confirmation|(^|_)name$|surname|(first|last|full|guest|holder)_?name|address|birth
|
|
44
|
+
const SENSITIVE_KEY = /auth|cookie|token|secret|passw|passcode|^pin$|session|e-?mail|phone|iban|card|(^|_)pan($|_|number)|cvc|cvv|shopper|reservation|booking|confirmation|(^|_)name$|surname|(first|last|full|guest|holder|given|family)_?name|address|birth|^dob$|^ip$|passport|signature|tax_?id|vat|api_?key/i;
|
|
43
45
|
const digitCount = (value) => value.replaceAll(/\D/g, '').length;
|
|
46
|
+
const isLuhnValid = (digits) => {
|
|
47
|
+
let sum = 0;
|
|
48
|
+
for (let index = 0; index < digits.length; index += 1) {
|
|
49
|
+
let digit = Number(digits[digits.length - 1 - index]);
|
|
50
|
+
if (index % 2 === 1) {
|
|
51
|
+
digit *= 2;
|
|
52
|
+
if (digit > 9)
|
|
53
|
+
digit -= 9;
|
|
54
|
+
}
|
|
55
|
+
sum += digit;
|
|
56
|
+
}
|
|
57
|
+
return sum % 10 === 0;
|
|
58
|
+
};
|
|
44
59
|
const STRING_PATTERNS = [
|
|
45
60
|
[/eyJ[\w-]+\.[\w-]+\.[\w-]+(?:\.[\w-]+\.[\w-]+)?/g, () => '[jwt]'],
|
|
46
61
|
[
|
|
@@ -55,15 +70,17 @@ const STRING_PATTERNS = [
|
|
|
55
70
|
[
|
|
56
71
|
/\d[\d -]{11,}\d/g,
|
|
57
72
|
match => {
|
|
58
|
-
const digits =
|
|
59
|
-
return digits >= 13 && digits <= 19
|
|
73
|
+
const digits = match.replaceAll(/\D/g, '');
|
|
74
|
+
return digits.length >= 13 && digits.length <= 19 && isLuhnValid(digits)
|
|
75
|
+
? '[number]'
|
|
76
|
+
: match;
|
|
60
77
|
},
|
|
61
78
|
],
|
|
62
79
|
];
|
|
63
80
|
let enabled = false;
|
|
64
81
|
let flushTimeoutMs = DEFAULT_FLUSH_TIMEOUT_MS;
|
|
65
82
|
const scrubString = (value) => {
|
|
66
|
-
let result = value;
|
|
83
|
+
let result = value.slice(0, MAX_STRING_LENGTH);
|
|
67
84
|
for (const [pattern, replacement] of STRING_PATTERNS) {
|
|
68
85
|
result = result.replace(pattern, replacement);
|
|
69
86
|
}
|
|
@@ -137,6 +154,7 @@ const initErrorReporting = (options) => {
|
|
|
137
154
|
release: options.release,
|
|
138
155
|
serverName: options.serviceName,
|
|
139
156
|
sendDefaultPii: false,
|
|
157
|
+
sendClientReports: false,
|
|
140
158
|
skipOpenTelemetrySetup: true,
|
|
141
159
|
defaultIntegrations: false,
|
|
142
160
|
integrations: [
|
|
@@ -193,6 +211,34 @@ const errorReportingHandler = (error, request, _response, next) => {
|
|
|
193
211
|
next(error);
|
|
194
212
|
};
|
|
195
213
|
exports.errorReportingHandler = errorReportingHandler;
|
|
214
|
+
// Mount first: service-utils endpoints answer 5xx themselves and only set
|
|
215
|
+
// response.err, so the decision is made on the status actually sent.
|
|
216
|
+
const errorReportingMiddleware = (request, response, next) => {
|
|
217
|
+
if (enabled) {
|
|
218
|
+
let reported = false;
|
|
219
|
+
const report = () => {
|
|
220
|
+
if (reported || response.statusCode < 500)
|
|
221
|
+
return;
|
|
222
|
+
reported = true;
|
|
223
|
+
try {
|
|
224
|
+
Sentry.captureException(response.err ??
|
|
225
|
+
new Error(`HTTP ${response.statusCode} ${request.method} ${routeOf(request)}`), {
|
|
226
|
+
tags: {
|
|
227
|
+
method: request.method,
|
|
228
|
+
status: String(response.statusCode),
|
|
229
|
+
route: routeOf(request),
|
|
230
|
+
...(request.id !== undefined && { reqId: String(request.id) }),
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch { }
|
|
235
|
+
};
|
|
236
|
+
response.once('finish', report);
|
|
237
|
+
response.once('close', report);
|
|
238
|
+
}
|
|
239
|
+
next();
|
|
240
|
+
};
|
|
241
|
+
exports.errorReportingMiddleware = errorReportingMiddleware;
|
|
196
242
|
const exitAfterReport = (error) => {
|
|
197
243
|
if (enabled) {
|
|
198
244
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucaapp/service-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.44.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"axios": "1.20.0",
|
|
35
35
|
"axios-rate-limit": "^1.4.0",
|
|
36
36
|
"axios-retry": "^4.5.0",
|
|
37
|
-
"body-parser": "1.20.
|
|
37
|
+
"body-parser": "1.20.9",
|
|
38
38
|
"busboy": "^1.6.0",
|
|
39
39
|
"cls-rtracer": "^2.6.3",
|
|
40
40
|
"express": "4.22.1",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
},
|
|
100
100
|
"resolutions": {
|
|
101
101
|
"tar": "7.5.21",
|
|
102
|
-
"body-parser": "1.20.
|
|
102
|
+
"body-parser": "1.20.9",
|
|
103
103
|
"lodash": "^4.18.1",
|
|
104
104
|
"qs": "6.16.0",
|
|
105
105
|
"dottie": "2.0.7",
|