apitally 0.6.1 → 0.7.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/dist/common/client.cjs +514 -0
- package/dist/common/client.cjs.map +1 -0
- package/dist/common/client.d.cts +36 -0
- package/{lib/types → dist}/common/client.d.ts +12 -9
- package/dist/common/client.js +481 -0
- package/dist/common/client.js.map +1 -0
- package/dist/common/logging.cjs +41 -0
- package/dist/common/logging.cjs.map +1 -0
- package/dist/common/logging.d.cts +11 -0
- package/{lib/types → dist}/common/logging.d.ts +6 -3
- package/dist/common/logging.js +18 -0
- package/dist/common/logging.js.map +1 -0
- package/dist/common/packageVersions.cjs +42 -0
- package/dist/common/packageVersions.cjs.map +1 -0
- package/dist/common/packageVersions.d.cts +3 -0
- package/dist/common/packageVersions.d.ts +3 -0
- package/dist/common/packageVersions.js +18 -0
- package/dist/common/packageVersions.js.map +1 -0
- package/dist/common/paramValidation.cjs +43 -0
- package/dist/common/paramValidation.cjs.map +1 -0
- package/dist/common/paramValidation.d.cts +4 -0
- package/dist/common/paramValidation.d.ts +4 -0
- package/dist/common/paramValidation.js +19 -0
- package/dist/common/paramValidation.js.map +1 -0
- package/dist/common/requestCounter.cjs +111 -0
- package/dist/common/requestCounter.cjs.map +1 -0
- package/dist/common/requestCounter.d.cts +18 -0
- package/{lib/types → dist}/common/requestCounter.d.ts +7 -3
- package/dist/common/requestCounter.js +92 -0
- package/dist/common/requestCounter.js.map +1 -0
- package/dist/common/serverErrorCounter.cjs +133 -0
- package/dist/common/serverErrorCounter.cjs.map +1 -0
- package/dist/common/serverErrorCounter.d.cts +20 -0
- package/{lib/types → dist}/common/serverErrorCounter.d.ts +7 -3
- package/dist/common/serverErrorCounter.js +104 -0
- package/dist/common/serverErrorCounter.js.map +1 -0
- package/dist/common/types.cjs +19 -0
- package/dist/common/types.cjs.map +1 -0
- package/dist/common/types.d.cts +76 -0
- package/{lib/types → dist}/common/types.d.ts +17 -14
- package/dist/common/types.js +1 -0
- package/dist/common/types.js.map +1 -0
- package/dist/common/validationErrorCounter.cjs +76 -0
- package/dist/common/validationErrorCounter.cjs.map +1 -0
- package/dist/common/validationErrorCounter.d.cts +14 -0
- package/{lib/types → dist}/common/validationErrorCounter.d.ts +7 -3
- package/dist/common/validationErrorCounter.js +57 -0
- package/dist/common/validationErrorCounter.js.map +1 -0
- package/dist/express/index.cjs +837 -0
- package/dist/express/index.cjs.map +1 -0
- package/dist/express/index.d.cts +5 -0
- package/dist/express/index.d.ts +5 -0
- package/dist/express/index.js +801 -0
- package/dist/express/index.js.map +1 -0
- package/dist/express/listEndpoints.cjs +144 -0
- package/dist/express/listEndpoints.cjs.map +1 -0
- package/dist/express/listEndpoints.d.cts +3 -0
- package/dist/express/listEndpoints.d.ts +3 -0
- package/dist/express/listEndpoints.js +125 -0
- package/dist/express/listEndpoints.js.map +1 -0
- package/dist/express/middleware.cjs +835 -0
- package/dist/express/middleware.cjs.map +1 -0
- package/dist/express/middleware.d.cts +14 -0
- package/dist/express/middleware.d.ts +14 -0
- package/dist/express/middleware.js +801 -0
- package/dist/express/middleware.js.map +1 -0
- package/dist/fastify/index.cjs +685 -0
- package/dist/fastify/index.cjs.map +1 -0
- package/dist/fastify/index.d.cts +5 -0
- package/dist/fastify/index.d.ts +5 -0
- package/dist/fastify/index.js +649 -0
- package/dist/fastify/index.js.map +1 -0
- package/dist/fastify/plugin.cjs +679 -0
- package/dist/fastify/plugin.cjs.map +1 -0
- package/dist/fastify/plugin.d.cts +18 -0
- package/{lib/types → dist}/fastify/plugin.d.ts +7 -4
- package/dist/fastify/plugin.js +649 -0
- package/dist/fastify/plugin.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/koa/index.cjs +655 -0
- package/dist/koa/index.cjs.map +1 -0
- package/dist/koa/index.d.cts +5 -0
- package/dist/koa/index.d.ts +5 -0
- package/dist/koa/index.js +619 -0
- package/dist/koa/index.js.map +1 -0
- package/dist/koa/middleware.cjs +655 -0
- package/dist/koa/middleware.cjs.map +1 -0
- package/dist/koa/middleware.d.cts +8 -0
- package/dist/koa/middleware.d.ts +8 -0
- package/dist/koa/middleware.js +619 -0
- package/dist/koa/middleware.js.map +1 -0
- package/dist/nestjs/index.cjs +837 -0
- package/dist/nestjs/index.cjs.map +1 -0
- package/dist/nestjs/index.d.cts +5 -0
- package/dist/nestjs/index.d.ts +5 -0
- package/dist/nestjs/index.js +801 -0
- package/dist/nestjs/index.js.map +1 -0
- package/package.json +55 -92
- package/lib/cjs/common/client.cjs +0 -334
- package/lib/cjs/common/client.cjs.map +0 -1
- package/lib/cjs/common/logging.cjs +0 -17
- package/lib/cjs/common/logging.cjs.map +0 -1
- package/lib/cjs/common/packageVersions.cjs +0 -16
- package/lib/cjs/common/packageVersions.cjs.map +0 -1
- package/lib/cjs/common/paramValidation.cjs +0 -16
- package/lib/cjs/common/paramValidation.cjs.map +0 -1
- package/lib/cjs/common/requestCounter.cjs +0 -108
- package/lib/cjs/common/requestCounter.cjs.map +0 -1
- package/lib/cjs/common/serverErrorCounter.cjs +0 -154
- package/lib/cjs/common/serverErrorCounter.cjs.map +0 -1
- package/lib/cjs/common/types.cjs +0 -6
- package/lib/cjs/common/types.cjs.map +0 -1
- package/lib/cjs/common/validationErrorCounter.cjs +0 -60
- package/lib/cjs/common/validationErrorCounter.cjs.map +0 -1
- package/lib/cjs/express/index.cjs +0 -13
- package/lib/cjs/express/index.cjs.map +0 -1
- package/lib/cjs/express/listEndpoints.cjs +0 -177
- package/lib/cjs/express/listEndpoints.cjs.map +0 -1
- package/lib/cjs/express/middleware.cjs +0 -189
- package/lib/cjs/express/middleware.cjs.map +0 -1
- package/lib/cjs/fastify/index.cjs +0 -14
- package/lib/cjs/fastify/index.cjs.map +0 -1
- package/lib/cjs/fastify/plugin.cjs +0 -171
- package/lib/cjs/fastify/plugin.cjs.map +0 -1
- package/lib/cjs/index.cjs +0 -6
- package/lib/cjs/index.cjs.map +0 -1
- package/lib/cjs/koa/index.cjs +0 -13
- package/lib/cjs/koa/index.cjs.map +0 -1
- package/lib/cjs/koa/middleware.cjs +0 -139
- package/lib/cjs/koa/middleware.cjs.map +0 -1
- package/lib/cjs/nestjs/index.cjs +0 -13
- package/lib/cjs/nestjs/index.cjs.map +0 -1
- package/lib/esm/common/client.js +0 -324
- package/lib/esm/common/client.js.map +0 -1
- package/lib/esm/common/logging.js +0 -11
- package/lib/esm/common/logging.js.map +0 -1
- package/lib/esm/common/packageVersions.js +0 -10
- package/lib/esm/common/packageVersions.js.map +0 -1
- package/lib/esm/common/paramValidation.js +0 -9
- package/lib/esm/common/paramValidation.js.map +0 -1
- package/lib/esm/common/requestCounter.js +0 -102
- package/lib/esm/common/requestCounter.js.map +0 -1
- package/lib/esm/common/serverErrorCounter.js +0 -143
- package/lib/esm/common/serverErrorCounter.js.map +0 -1
- package/lib/esm/common/types.js +0 -1
- package/lib/esm/common/types.js.map +0 -1
- package/lib/esm/common/validationErrorCounter.js +0 -54
- package/lib/esm/common/validationErrorCounter.js.map +0 -1
- package/lib/esm/express/index.js +0 -1
- package/lib/esm/express/index.js.map +0 -1
- package/lib/esm/express/listEndpoints.js +0 -170
- package/lib/esm/express/listEndpoints.js.map +0 -1
- package/lib/esm/express/middleware.js +0 -182
- package/lib/esm/express/middleware.js.map +0 -1
- package/lib/esm/fastify/index.js +0 -1
- package/lib/esm/fastify/index.js.map +0 -1
- package/lib/esm/fastify/plugin.js +0 -164
- package/lib/esm/fastify/plugin.js.map +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/koa/index.js +0 -1
- package/lib/esm/koa/index.js.map +0 -1
- package/lib/esm/koa/middleware.js +0 -132
- package/lib/esm/koa/middleware.js.map +0 -1
- package/lib/esm/nestjs/index.js +0 -1
- package/lib/esm/nestjs/index.js.map +0 -1
- package/lib/types/common/client.d.ts.map +0 -1
- package/lib/types/common/logging.d.ts.map +0 -1
- package/lib/types/common/packageVersions.d.ts +0 -2
- package/lib/types/common/packageVersions.d.ts.map +0 -1
- package/lib/types/common/paramValidation.d.ts +0 -3
- package/lib/types/common/paramValidation.d.ts.map +0 -1
- package/lib/types/common/requestCounter.d.ts.map +0 -1
- package/lib/types/common/serverErrorCounter.d.ts.map +0 -1
- package/lib/types/common/types.d.ts.map +0 -1
- package/lib/types/common/validationErrorCounter.d.ts.map +0 -1
- package/lib/types/express/index.d.ts +0 -2
- package/lib/types/express/index.d.ts.map +0 -1
- package/lib/types/express/listEndpoints.d.ts +0 -3
- package/lib/types/express/listEndpoints.d.ts.map +0 -1
- package/lib/types/express/middleware.d.ts +0 -10
- package/lib/types/express/middleware.d.ts.map +0 -1
- package/lib/types/fastify/index.d.ts +0 -2
- package/lib/types/fastify/index.d.ts.map +0 -1
- package/lib/types/fastify/plugin.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/koa/index.d.ts +0 -2
- package/lib/types/koa/index.d.ts.map +0 -1
- package/lib/types/koa/middleware.d.ts +0 -4
- package/lib/types/koa/middleware.d.ts.map +0 -1
- package/lib/types/nestjs/index.d.ts +0 -2
- package/lib/types/nestjs/index.d.ts.map +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/common/serverErrorCounter.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var MAX_MSG_LENGTH = 2048;
|
|
7
|
+
var MAX_STACKTRACE_LENGTH = 65536;
|
|
8
|
+
var _ServerErrorCounter = class _ServerErrorCounter {
|
|
9
|
+
errorCounts;
|
|
10
|
+
errorDetails;
|
|
11
|
+
sentryEventIds;
|
|
12
|
+
sentry;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.errorCounts = /* @__PURE__ */ new Map();
|
|
15
|
+
this.errorDetails = /* @__PURE__ */ new Map();
|
|
16
|
+
this.sentryEventIds = /* @__PURE__ */ new Map();
|
|
17
|
+
this.tryImportSentry();
|
|
18
|
+
}
|
|
19
|
+
addServerError(serverError) {
|
|
20
|
+
const key = this.getKey(serverError);
|
|
21
|
+
if (!this.errorDetails.has(key)) {
|
|
22
|
+
this.errorDetails.set(key, serverError);
|
|
23
|
+
}
|
|
24
|
+
this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);
|
|
25
|
+
this.captureSentryEventId(key);
|
|
26
|
+
}
|
|
27
|
+
getAndResetServerErrors() {
|
|
28
|
+
const data = [];
|
|
29
|
+
this.errorCounts.forEach((count, key) => {
|
|
30
|
+
const serverError = this.errorDetails.get(key);
|
|
31
|
+
if (serverError) {
|
|
32
|
+
data.push({
|
|
33
|
+
consumer: serverError.consumer || null,
|
|
34
|
+
method: serverError.method,
|
|
35
|
+
path: serverError.path,
|
|
36
|
+
type: serverError.type,
|
|
37
|
+
msg: this.getTruncatedMessage(serverError.msg),
|
|
38
|
+
traceback: this.getTruncatedStack(serverError.traceback),
|
|
39
|
+
sentry_event_id: this.sentryEventIds.get(key) || null,
|
|
40
|
+
error_count: count
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.errorCounts.clear();
|
|
45
|
+
this.errorDetails.clear();
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
getKey(serverError) {
|
|
49
|
+
const hashInput = [
|
|
50
|
+
serverError.consumer || "",
|
|
51
|
+
serverError.method.toUpperCase(),
|
|
52
|
+
serverError.path,
|
|
53
|
+
serverError.type,
|
|
54
|
+
serverError.msg.trim(),
|
|
55
|
+
serverError.traceback.trim()
|
|
56
|
+
].join("|");
|
|
57
|
+
return createHash("md5").update(hashInput).digest("hex");
|
|
58
|
+
}
|
|
59
|
+
getTruncatedMessage(msg) {
|
|
60
|
+
msg = msg.trim();
|
|
61
|
+
if (msg.length <= MAX_MSG_LENGTH) {
|
|
62
|
+
return msg;
|
|
63
|
+
}
|
|
64
|
+
const suffix = "... (truncated)";
|
|
65
|
+
const cutoff = MAX_MSG_LENGTH - suffix.length;
|
|
66
|
+
return msg.substring(0, cutoff) + suffix;
|
|
67
|
+
}
|
|
68
|
+
getTruncatedStack(stack) {
|
|
69
|
+
const suffix = "... (truncated) ...";
|
|
70
|
+
const cutoff = MAX_STACKTRACE_LENGTH - suffix.length;
|
|
71
|
+
const lines = stack.trim().split("\n");
|
|
72
|
+
const truncatedLines = [];
|
|
73
|
+
let length = 0;
|
|
74
|
+
for (const line of lines) {
|
|
75
|
+
if (length + line.length + 1 > cutoff) {
|
|
76
|
+
truncatedLines.push(suffix);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
truncatedLines.push(line);
|
|
80
|
+
length += line.length + 1;
|
|
81
|
+
}
|
|
82
|
+
return truncatedLines.join("\n");
|
|
83
|
+
}
|
|
84
|
+
captureSentryEventId(serverErrorKey) {
|
|
85
|
+
if (this.sentry && this.sentry.lastEventId) {
|
|
86
|
+
const eventId = this.sentry.lastEventId();
|
|
87
|
+
if (eventId) {
|
|
88
|
+
this.sentryEventIds.set(serverErrorKey, eventId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async tryImportSentry() {
|
|
93
|
+
try {
|
|
94
|
+
this.sentry = await import("@sentry/node");
|
|
95
|
+
} catch (e) {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
__name(_ServerErrorCounter, "ServerErrorCounter");
|
|
100
|
+
var ServerErrorCounter = _ServerErrorCounter;
|
|
101
|
+
export {
|
|
102
|
+
ServerErrorCounter as default
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=serverErrorCounter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/serverErrorCounter.ts"],"sourcesContent":["import type * as Sentry from \"@sentry/node\";\nimport { createHash } from \"crypto\";\n\nimport { ConsumerMethodPath, ServerError, ServerErrorsItem } from \"./types.js\";\n\nconst MAX_MSG_LENGTH = 2048;\nconst MAX_STACKTRACE_LENGTH = 65536;\n\nexport default class ServerErrorCounter {\n private errorCounts: Map<string, number>;\n private errorDetails: Map<string, ConsumerMethodPath & ServerError>;\n private sentryEventIds: Map<string, string>;\n private sentry: typeof Sentry | undefined;\n\n constructor() {\n this.errorCounts = new Map();\n this.errorDetails = new Map();\n this.sentryEventIds = new Map();\n this.tryImportSentry();\n }\n\n public addServerError(serverError: ConsumerMethodPath & ServerError) {\n const key = this.getKey(serverError);\n if (!this.errorDetails.has(key)) {\n this.errorDetails.set(key, serverError);\n }\n this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);\n this.captureSentryEventId(key);\n }\n\n public getAndResetServerErrors() {\n const data: Array<ServerErrorsItem> = [];\n this.errorCounts.forEach((count, key) => {\n const serverError = this.errorDetails.get(key);\n if (serverError) {\n data.push({\n consumer: serverError.consumer || null,\n method: serverError.method,\n path: serverError.path,\n type: serverError.type,\n msg: this.getTruncatedMessage(serverError.msg),\n traceback: this.getTruncatedStack(serverError.traceback),\n sentry_event_id: this.sentryEventIds.get(key) || null,\n error_count: count,\n });\n }\n });\n this.errorCounts.clear();\n this.errorDetails.clear();\n return data;\n }\n\n private getKey(serverError: ConsumerMethodPath & ServerError) {\n const hashInput = [\n serverError.consumer || \"\",\n serverError.method.toUpperCase(),\n serverError.path,\n serverError.type,\n serverError.msg.trim(),\n serverError.traceback.trim(),\n ].join(\"|\");\n return createHash(\"md5\").update(hashInput).digest(\"hex\");\n }\n\n private getTruncatedMessage(msg: string) {\n msg = msg.trim();\n if (msg.length <= MAX_MSG_LENGTH) {\n return msg;\n }\n const suffix = \"... (truncated)\";\n const cutoff = MAX_MSG_LENGTH - suffix.length;\n return msg.substring(0, cutoff) + suffix;\n }\n\n private getTruncatedStack(stack: string) {\n const suffix = \"... (truncated) ...\";\n const cutoff = MAX_STACKTRACE_LENGTH - suffix.length;\n const lines = stack.trim().split(\"\\n\");\n const truncatedLines: string[] = [];\n let length = 0;\n for (const line of lines) {\n if (length + line.length + 1 > cutoff) {\n truncatedLines.push(suffix);\n break;\n }\n truncatedLines.push(line);\n length += line.length + 1;\n }\n return truncatedLines.join(\"\\n\");\n }\n\n private captureSentryEventId(serverErrorKey: string) {\n if (this.sentry && this.sentry.lastEventId) {\n const eventId = this.sentry.lastEventId();\n if (eventId) {\n this.sentryEventIds.set(serverErrorKey, eventId);\n }\n }\n }\n\n private async tryImportSentry() {\n try {\n this.sentry = await import(\"@sentry/node\");\n } catch (e) {\n // Sentry SDK is not installed, ignore\n }\n }\n}\n"],"mappings":"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","names":["createHash","MAX_MSG_LENGTH","MAX_STACKTRACE_LENGTH","ServerErrorCounter","errorCounts","errorDetails","sentryEventIds","sentry","constructor","Map","tryImportSentry","addServerError","serverError","key","getKey","has","set","get","captureSentryEventId","getAndResetServerErrors","data","forEach","count","push","consumer","method","path","type","msg","getTruncatedMessage","traceback","getTruncatedStack","sentry_event_id","error_count","clear","hashInput","toUpperCase","trim","join","createHash","update","digest","length","suffix","cutoff","substring","stack","lines","split","truncatedLines","line","serverErrorKey","lastEventId","eventId","e"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/common/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/types.ts"],"sourcesContent":["import { Logger } from \"./logging.js\";\n\nexport type ApitallyConfig = {\n clientId: string;\n env?: string;\n openApiUrl?: string;\n appVersion?: string;\n logger?: Logger;\n};\n\nexport type PathInfo = {\n method: string;\n path: string;\n};\n\nexport type AppInfo = {\n paths: PathInfo[];\n versions: Record<string, string>;\n client: string;\n};\n\nexport type AppInfoPayload = {\n instance_uuid: string;\n message_uuid: string;\n} & AppInfo;\n\nexport type ConsumerMethodPath = {\n consumer?: string | null;\n method: string;\n path: string;\n};\n\nexport type RequestInfo = ConsumerMethodPath & {\n statusCode: number;\n responseTime: number;\n requestSize?: string | number;\n responseSize?: string | number;\n};\n\nexport type RequestsItem = ConsumerMethodPath & {\n status_code: number;\n request_count: number;\n request_size_sum: number;\n response_size_sum: number;\n response_times: Record<number, number>;\n request_sizes: Record<number, number>;\n response_sizes: Record<number, number>;\n};\n\nexport type ValidationError = {\n loc: string;\n msg: string;\n type: string;\n};\n\nexport type ValidationErrorsItem = ConsumerMethodPath & {\n loc: Array<string>;\n msg: string;\n type: string;\n error_count: number;\n};\n\nexport type ServerError = {\n type: string;\n msg: string;\n traceback: string;\n};\n\nexport type ServerErrorsItem = ConsumerMethodPath & {\n type: string;\n msg: string;\n traceback: string;\n sentry_event_id: string | null;\n error_count: number;\n};\n\nexport type RequestsDataPayload = {\n time_offset: number;\n instance_uuid: string;\n message_uuid: string;\n requests: Array<RequestsItem>;\n validation_errors: Array<ValidationErrorsItem>;\n server_errors: Array<ServerErrorsItem>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA4EA;;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Logger } from './logging.cjs';
|
|
2
|
+
import 'winston';
|
|
3
|
+
|
|
4
|
+
type ApitallyConfig = {
|
|
5
|
+
clientId: string;
|
|
6
|
+
env?: string;
|
|
7
|
+
openApiUrl?: string;
|
|
8
|
+
appVersion?: string;
|
|
9
|
+
logger?: Logger;
|
|
10
|
+
};
|
|
11
|
+
type PathInfo = {
|
|
12
|
+
method: string;
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
type AppInfo = {
|
|
16
|
+
paths: PathInfo[];
|
|
17
|
+
versions: Record<string, string>;
|
|
18
|
+
client: string;
|
|
19
|
+
};
|
|
20
|
+
type AppInfoPayload = {
|
|
21
|
+
instance_uuid: string;
|
|
22
|
+
message_uuid: string;
|
|
23
|
+
} & AppInfo;
|
|
24
|
+
type ConsumerMethodPath = {
|
|
25
|
+
consumer?: string | null;
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
};
|
|
29
|
+
type RequestInfo = ConsumerMethodPath & {
|
|
30
|
+
statusCode: number;
|
|
31
|
+
responseTime: number;
|
|
32
|
+
requestSize?: string | number;
|
|
33
|
+
responseSize?: string | number;
|
|
34
|
+
};
|
|
35
|
+
type RequestsItem = ConsumerMethodPath & {
|
|
36
|
+
status_code: number;
|
|
37
|
+
request_count: number;
|
|
38
|
+
request_size_sum: number;
|
|
39
|
+
response_size_sum: number;
|
|
40
|
+
response_times: Record<number, number>;
|
|
41
|
+
request_sizes: Record<number, number>;
|
|
42
|
+
response_sizes: Record<number, number>;
|
|
43
|
+
};
|
|
44
|
+
type ValidationError = {
|
|
45
|
+
loc: string;
|
|
46
|
+
msg: string;
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
type ValidationErrorsItem = ConsumerMethodPath & {
|
|
50
|
+
loc: Array<string>;
|
|
51
|
+
msg: string;
|
|
52
|
+
type: string;
|
|
53
|
+
error_count: number;
|
|
54
|
+
};
|
|
55
|
+
type ServerError = {
|
|
56
|
+
type: string;
|
|
57
|
+
msg: string;
|
|
58
|
+
traceback: string;
|
|
59
|
+
};
|
|
60
|
+
type ServerErrorsItem = ConsumerMethodPath & {
|
|
61
|
+
type: string;
|
|
62
|
+
msg: string;
|
|
63
|
+
traceback: string;
|
|
64
|
+
sentry_event_id: string | null;
|
|
65
|
+
error_count: number;
|
|
66
|
+
};
|
|
67
|
+
type RequestsDataPayload = {
|
|
68
|
+
time_offset: number;
|
|
69
|
+
instance_uuid: string;
|
|
70
|
+
message_uuid: string;
|
|
71
|
+
requests: Array<RequestsItem>;
|
|
72
|
+
validation_errors: Array<ValidationErrorsItem>;
|
|
73
|
+
server_errors: Array<ServerErrorsItem>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type { ApitallyConfig, AppInfo, AppInfoPayload, ConsumerMethodPath, PathInfo, RequestInfo, RequestsDataPayload, RequestsItem, ServerError, ServerErrorsItem, ValidationError, ValidationErrorsItem };
|
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import { Logger } from
|
|
2
|
-
|
|
1
|
+
import { Logger } from './logging.js';
|
|
2
|
+
import 'winston';
|
|
3
|
+
|
|
4
|
+
type ApitallyConfig = {
|
|
3
5
|
clientId: string;
|
|
4
6
|
env?: string;
|
|
5
7
|
openApiUrl?: string;
|
|
6
8
|
appVersion?: string;
|
|
7
9
|
logger?: Logger;
|
|
8
10
|
};
|
|
9
|
-
|
|
11
|
+
type PathInfo = {
|
|
10
12
|
method: string;
|
|
11
13
|
path: string;
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
type AppInfo = {
|
|
14
16
|
paths: PathInfo[];
|
|
15
17
|
versions: Record<string, string>;
|
|
16
18
|
client: string;
|
|
17
19
|
};
|
|
18
|
-
|
|
20
|
+
type AppInfoPayload = {
|
|
19
21
|
instance_uuid: string;
|
|
20
22
|
message_uuid: string;
|
|
21
23
|
} & AppInfo;
|
|
22
|
-
|
|
24
|
+
type ConsumerMethodPath = {
|
|
23
25
|
consumer?: string | null;
|
|
24
26
|
method: string;
|
|
25
27
|
path: string;
|
|
26
28
|
};
|
|
27
|
-
|
|
29
|
+
type RequestInfo = ConsumerMethodPath & {
|
|
28
30
|
statusCode: number;
|
|
29
31
|
responseTime: number;
|
|
30
32
|
requestSize?: string | number;
|
|
31
33
|
responseSize?: string | number;
|
|
32
34
|
};
|
|
33
|
-
|
|
35
|
+
type RequestsItem = ConsumerMethodPath & {
|
|
34
36
|
status_code: number;
|
|
35
37
|
request_count: number;
|
|
36
38
|
request_size_sum: number;
|
|
@@ -39,30 +41,30 @@ export type RequestsItem = ConsumerMethodPath & {
|
|
|
39
41
|
request_sizes: Record<number, number>;
|
|
40
42
|
response_sizes: Record<number, number>;
|
|
41
43
|
};
|
|
42
|
-
|
|
44
|
+
type ValidationError = {
|
|
43
45
|
loc: string;
|
|
44
46
|
msg: string;
|
|
45
47
|
type: string;
|
|
46
48
|
};
|
|
47
|
-
|
|
49
|
+
type ValidationErrorsItem = ConsumerMethodPath & {
|
|
48
50
|
loc: Array<string>;
|
|
49
51
|
msg: string;
|
|
50
52
|
type: string;
|
|
51
53
|
error_count: number;
|
|
52
54
|
};
|
|
53
|
-
|
|
55
|
+
type ServerError = {
|
|
54
56
|
type: string;
|
|
55
57
|
msg: string;
|
|
56
58
|
traceback: string;
|
|
57
59
|
};
|
|
58
|
-
|
|
60
|
+
type ServerErrorsItem = ConsumerMethodPath & {
|
|
59
61
|
type: string;
|
|
60
62
|
msg: string;
|
|
61
63
|
traceback: string;
|
|
62
64
|
sentry_event_id: string | null;
|
|
63
65
|
error_count: number;
|
|
64
66
|
};
|
|
65
|
-
|
|
67
|
+
type RequestsDataPayload = {
|
|
66
68
|
time_offset: number;
|
|
67
69
|
instance_uuid: string;
|
|
68
70
|
message_uuid: string;
|
|
@@ -70,4 +72,5 @@ export type RequestsDataPayload = {
|
|
|
70
72
|
validation_errors: Array<ValidationErrorsItem>;
|
|
71
73
|
server_errors: Array<ServerErrorsItem>;
|
|
72
74
|
};
|
|
73
|
-
|
|
75
|
+
|
|
76
|
+
export type { ApitallyConfig, AppInfo, AppInfoPayload, ConsumerMethodPath, PathInfo, RequestInfo, RequestsDataPayload, RequestsItem, ServerError, ServerErrorsItem, ValidationError, ValidationErrorsItem };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/common/validationErrorCounter.ts
|
|
22
|
+
var validationErrorCounter_exports = {};
|
|
23
|
+
__export(validationErrorCounter_exports, {
|
|
24
|
+
default: () => ValidationErrorCounter
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(validationErrorCounter_exports);
|
|
27
|
+
var import_crypto = require("crypto");
|
|
28
|
+
var _ValidationErrorCounter = class _ValidationErrorCounter {
|
|
29
|
+
errorCounts;
|
|
30
|
+
errorDetails;
|
|
31
|
+
constructor() {
|
|
32
|
+
this.errorCounts = /* @__PURE__ */ new Map();
|
|
33
|
+
this.errorDetails = /* @__PURE__ */ new Map();
|
|
34
|
+
}
|
|
35
|
+
addValidationError(validationError) {
|
|
36
|
+
const key = this.getKey(validationError);
|
|
37
|
+
if (!this.errorDetails.has(key)) {
|
|
38
|
+
this.errorDetails.set(key, validationError);
|
|
39
|
+
}
|
|
40
|
+
this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);
|
|
41
|
+
}
|
|
42
|
+
getAndResetValidationErrors() {
|
|
43
|
+
const data = [];
|
|
44
|
+
this.errorCounts.forEach((count, key) => {
|
|
45
|
+
const validationError = this.errorDetails.get(key);
|
|
46
|
+
if (validationError) {
|
|
47
|
+
data.push({
|
|
48
|
+
consumer: validationError.consumer || null,
|
|
49
|
+
method: validationError.method,
|
|
50
|
+
path: validationError.path,
|
|
51
|
+
loc: validationError.loc.split("."),
|
|
52
|
+
msg: validationError.msg,
|
|
53
|
+
type: validationError.type,
|
|
54
|
+
error_count: count
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
this.errorCounts.clear();
|
|
59
|
+
this.errorDetails.clear();
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
getKey(validationError) {
|
|
63
|
+
const hashInput = [
|
|
64
|
+
validationError.consumer || "",
|
|
65
|
+
validationError.method.toUpperCase(),
|
|
66
|
+
validationError.path,
|
|
67
|
+
validationError.loc,
|
|
68
|
+
validationError.msg.trim(),
|
|
69
|
+
validationError.type
|
|
70
|
+
].join("|");
|
|
71
|
+
return (0, import_crypto.createHash)("md5").update(hashInput).digest("hex");
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
__name(_ValidationErrorCounter, "ValidationErrorCounter");
|
|
75
|
+
var ValidationErrorCounter = _ValidationErrorCounter;
|
|
76
|
+
//# sourceMappingURL=validationErrorCounter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/validationErrorCounter.ts"],"sourcesContent":["import { createHash } from \"crypto\";\n\nimport {\n ConsumerMethodPath,\n ValidationError,\n ValidationErrorsItem,\n} from \"./types.js\";\n\nexport default class ValidationErrorCounter {\n private errorCounts: Map<string, number>;\n private errorDetails: Map<string, ConsumerMethodPath & ValidationError>;\n\n constructor() {\n this.errorCounts = new Map();\n this.errorDetails = new Map();\n }\n\n public addValidationError(\n validationError: ConsumerMethodPath & ValidationError,\n ) {\n const key = this.getKey(validationError);\n if (!this.errorDetails.has(key)) {\n this.errorDetails.set(key, validationError);\n }\n this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);\n }\n\n public getAndResetValidationErrors() {\n const data: Array<ValidationErrorsItem> = [];\n this.errorCounts.forEach((count, key) => {\n const validationError = this.errorDetails.get(key);\n if (validationError) {\n data.push({\n consumer: validationError.consumer || null,\n method: validationError.method,\n path: validationError.path,\n loc: validationError.loc.split(\".\"),\n msg: validationError.msg,\n type: validationError.type,\n error_count: count,\n });\n }\n });\n this.errorCounts.clear();\n this.errorDetails.clear();\n return data;\n }\n\n private getKey(validationError: ConsumerMethodPath & ValidationError) {\n const hashInput = [\n validationError.consumer || \"\",\n validationError.method.toUpperCase(),\n validationError.path,\n validationError.loc,\n validationError.msg.trim(),\n validationError.type,\n ].join(\"|\");\n return createHash(\"md5\").update(hashInput).digest(\"hex\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;oBAA2B;AAQ3B,IAAqBA,0BAArB,MAAqBA,wBAAAA;EACXC;EACAC;EAERC,cAAc;AACZ,SAAKF,cAAc,oBAAIG,IAAAA;AACvB,SAAKF,eAAe,oBAAIE,IAAAA;EAC1B;EAEOC,mBACLC,iBACA;AACA,UAAMC,MAAM,KAAKC,OAAOF,eAAAA;AACxB,QAAI,CAAC,KAAKJ,aAAaO,IAAIF,GAAAA,GAAM;AAC/B,WAAKL,aAAaQ,IAAIH,KAAKD,eAAAA;IAC7B;AACA,SAAKL,YAAYS,IAAIH,MAAM,KAAKN,YAAYU,IAAIJ,GAAAA,KAAQ,KAAK,CAAA;EAC/D;EAEOK,8BAA8B;AACnC,UAAMC,OAAoC,CAAA;AAC1C,SAAKZ,YAAYa,QAAQ,CAACC,OAAOR,QAAAA;AAC/B,YAAMD,kBAAkB,KAAKJ,aAAaS,IAAIJ,GAAAA;AAC9C,UAAID,iBAAiB;AACnBO,aAAKG,KAAK;UACRC,UAAUX,gBAAgBW,YAAY;UACtCC,QAAQZ,gBAAgBY;UACxBC,MAAMb,gBAAgBa;UACtBC,KAAKd,gBAAgBc,IAAIC,MAAM,GAAA;UAC/BC,KAAKhB,gBAAgBgB;UACrBC,MAAMjB,gBAAgBiB;UACtBC,aAAaT;QACf,CAAA;MACF;IACF,CAAA;AACA,SAAKd,YAAYwB,MAAK;AACtB,SAAKvB,aAAauB,MAAK;AACvB,WAAOZ;EACT;EAEQL,OAAOF,iBAAuD;AACpE,UAAMoB,YAAY;MAChBpB,gBAAgBW,YAAY;MAC5BX,gBAAgBY,OAAOS,YAAW;MAClCrB,gBAAgBa;MAChBb,gBAAgBc;MAChBd,gBAAgBgB,IAAIM,KAAI;MACxBtB,gBAAgBiB;MAChBM,KAAK,GAAA;AACP,eAAOC,0BAAW,KAAA,EAAOC,OAAOL,SAAAA,EAAWM,OAAO,KAAA;EACpD;AACF;AAnDqBhC;AAArB,IAAqBA,yBAArB;","names":["ValidationErrorCounter","errorCounts","errorDetails","constructor","Map","addValidationError","validationError","key","getKey","has","set","get","getAndResetValidationErrors","data","forEach","count","push","consumer","method","path","loc","split","msg","type","error_count","clear","hashInput","toUpperCase","trim","join","createHash","update","digest"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConsumerMethodPath, ValidationError, ValidationErrorsItem } from './types.cjs';
|
|
2
|
+
import './logging.cjs';
|
|
3
|
+
import 'winston';
|
|
4
|
+
|
|
5
|
+
declare class ValidationErrorCounter {
|
|
6
|
+
private errorCounts;
|
|
7
|
+
private errorDetails;
|
|
8
|
+
constructor();
|
|
9
|
+
addValidationError(validationError: ConsumerMethodPath & ValidationError): void;
|
|
10
|
+
getAndResetValidationErrors(): ValidationErrorsItem[];
|
|
11
|
+
private getKey;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { ValidationErrorCounter as default };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { ConsumerMethodPath, ValidationError, ValidationErrorsItem } from
|
|
2
|
-
|
|
1
|
+
import { ConsumerMethodPath, ValidationError, ValidationErrorsItem } from './types.js';
|
|
2
|
+
import './logging.js';
|
|
3
|
+
import 'winston';
|
|
4
|
+
|
|
5
|
+
declare class ValidationErrorCounter {
|
|
3
6
|
private errorCounts;
|
|
4
7
|
private errorDetails;
|
|
5
8
|
constructor();
|
|
@@ -7,4 +10,5 @@ export default class ValidationErrorCounter {
|
|
|
7
10
|
getAndResetValidationErrors(): ValidationErrorsItem[];
|
|
8
11
|
private getKey;
|
|
9
12
|
}
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
export { ValidationErrorCounter as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/common/validationErrorCounter.ts
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
|
+
var _ValidationErrorCounter = class _ValidationErrorCounter {
|
|
7
|
+
errorCounts;
|
|
8
|
+
errorDetails;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.errorCounts = /* @__PURE__ */ new Map();
|
|
11
|
+
this.errorDetails = /* @__PURE__ */ new Map();
|
|
12
|
+
}
|
|
13
|
+
addValidationError(validationError) {
|
|
14
|
+
const key = this.getKey(validationError);
|
|
15
|
+
if (!this.errorDetails.has(key)) {
|
|
16
|
+
this.errorDetails.set(key, validationError);
|
|
17
|
+
}
|
|
18
|
+
this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);
|
|
19
|
+
}
|
|
20
|
+
getAndResetValidationErrors() {
|
|
21
|
+
const data = [];
|
|
22
|
+
this.errorCounts.forEach((count, key) => {
|
|
23
|
+
const validationError = this.errorDetails.get(key);
|
|
24
|
+
if (validationError) {
|
|
25
|
+
data.push({
|
|
26
|
+
consumer: validationError.consumer || null,
|
|
27
|
+
method: validationError.method,
|
|
28
|
+
path: validationError.path,
|
|
29
|
+
loc: validationError.loc.split("."),
|
|
30
|
+
msg: validationError.msg,
|
|
31
|
+
type: validationError.type,
|
|
32
|
+
error_count: count
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
this.errorCounts.clear();
|
|
37
|
+
this.errorDetails.clear();
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
getKey(validationError) {
|
|
41
|
+
const hashInput = [
|
|
42
|
+
validationError.consumer || "",
|
|
43
|
+
validationError.method.toUpperCase(),
|
|
44
|
+
validationError.path,
|
|
45
|
+
validationError.loc,
|
|
46
|
+
validationError.msg.trim(),
|
|
47
|
+
validationError.type
|
|
48
|
+
].join("|");
|
|
49
|
+
return createHash("md5").update(hashInput).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__name(_ValidationErrorCounter, "ValidationErrorCounter");
|
|
53
|
+
var ValidationErrorCounter = _ValidationErrorCounter;
|
|
54
|
+
export {
|
|
55
|
+
ValidationErrorCounter as default
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=validationErrorCounter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/validationErrorCounter.ts"],"sourcesContent":["import { createHash } from \"crypto\";\n\nimport {\n ConsumerMethodPath,\n ValidationError,\n ValidationErrorsItem,\n} from \"./types.js\";\n\nexport default class ValidationErrorCounter {\n private errorCounts: Map<string, number>;\n private errorDetails: Map<string, ConsumerMethodPath & ValidationError>;\n\n constructor() {\n this.errorCounts = new Map();\n this.errorDetails = new Map();\n }\n\n public addValidationError(\n validationError: ConsumerMethodPath & ValidationError,\n ) {\n const key = this.getKey(validationError);\n if (!this.errorDetails.has(key)) {\n this.errorDetails.set(key, validationError);\n }\n this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);\n }\n\n public getAndResetValidationErrors() {\n const data: Array<ValidationErrorsItem> = [];\n this.errorCounts.forEach((count, key) => {\n const validationError = this.errorDetails.get(key);\n if (validationError) {\n data.push({\n consumer: validationError.consumer || null,\n method: validationError.method,\n path: validationError.path,\n loc: validationError.loc.split(\".\"),\n msg: validationError.msg,\n type: validationError.type,\n error_count: count,\n });\n }\n });\n this.errorCounts.clear();\n this.errorDetails.clear();\n return data;\n }\n\n private getKey(validationError: ConsumerMethodPath & ValidationError) {\n const hashInput = [\n validationError.consumer || \"\",\n validationError.method.toUpperCase(),\n validationError.path,\n validationError.loc,\n validationError.msg.trim(),\n validationError.type,\n ].join(\"|\");\n return createHash(\"md5\").update(hashInput).digest(\"hex\");\n }\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAQ3B,IAAqBC,0BAArB,MAAqBA,wBAAAA;EACXC;EACAC;EAERC,cAAc;AACZ,SAAKF,cAAc,oBAAIG,IAAAA;AACvB,SAAKF,eAAe,oBAAIE,IAAAA;EAC1B;EAEOC,mBACLC,iBACA;AACA,UAAMC,MAAM,KAAKC,OAAOF,eAAAA;AACxB,QAAI,CAAC,KAAKJ,aAAaO,IAAIF,GAAAA,GAAM;AAC/B,WAAKL,aAAaQ,IAAIH,KAAKD,eAAAA;IAC7B;AACA,SAAKL,YAAYS,IAAIH,MAAM,KAAKN,YAAYU,IAAIJ,GAAAA,KAAQ,KAAK,CAAA;EAC/D;EAEOK,8BAA8B;AACnC,UAAMC,OAAoC,CAAA;AAC1C,SAAKZ,YAAYa,QAAQ,CAACC,OAAOR,QAAAA;AAC/B,YAAMD,kBAAkB,KAAKJ,aAAaS,IAAIJ,GAAAA;AAC9C,UAAID,iBAAiB;AACnBO,aAAKG,KAAK;UACRC,UAAUX,gBAAgBW,YAAY;UACtCC,QAAQZ,gBAAgBY;UACxBC,MAAMb,gBAAgBa;UACtBC,KAAKd,gBAAgBc,IAAIC,MAAM,GAAA;UAC/BC,KAAKhB,gBAAgBgB;UACrBC,MAAMjB,gBAAgBiB;UACtBC,aAAaT;QACf,CAAA;MACF;IACF,CAAA;AACA,SAAKd,YAAYwB,MAAK;AACtB,SAAKvB,aAAauB,MAAK;AACvB,WAAOZ;EACT;EAEQL,OAAOF,iBAAuD;AACpE,UAAMoB,YAAY;MAChBpB,gBAAgBW,YAAY;MAC5BX,gBAAgBY,OAAOS,YAAW;MAClCrB,gBAAgBa;MAChBb,gBAAgBc;MAChBd,gBAAgBgB,IAAIM,KAAI;MACxBtB,gBAAgBiB;MAChBM,KAAK,GAAA;AACP,WAAOC,WAAW,KAAA,EAAOC,OAAOL,SAAAA,EAAWM,OAAO,KAAA;EACpD;AACF;AAnDqBhC;AAArB,IAAqBA,yBAArB;","names":["createHash","ValidationErrorCounter","errorCounts","errorDetails","constructor","Map","addValidationError","validationError","key","getKey","has","set","get","getAndResetValidationErrors","data","forEach","count","push","consumer","method","path","loc","split","msg","type","error_count","clear","hashInput","toUpperCase","trim","join","createHash","update","digest"]}
|