apitally 0.6.1 → 0.8.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.
Files changed (206) hide show
  1. package/dist/common/client.cjs +559 -0
  2. package/dist/common/client.cjs.map +1 -0
  3. package/dist/common/client.d.cts +38 -0
  4. package/dist/common/client.d.ts +38 -0
  5. package/dist/common/client.js +526 -0
  6. package/dist/common/client.js.map +1 -0
  7. package/dist/common/consumerRegistry.cjs +86 -0
  8. package/dist/common/consumerRegistry.cjs.map +1 -0
  9. package/dist/common/consumerRegistry.d.cts +14 -0
  10. package/dist/common/consumerRegistry.d.ts +14 -0
  11. package/dist/common/consumerRegistry.js +63 -0
  12. package/dist/common/consumerRegistry.js.map +1 -0
  13. package/dist/common/logging.cjs +41 -0
  14. package/dist/common/logging.cjs.map +1 -0
  15. package/dist/common/logging.d.cts +11 -0
  16. package/{lib/types → dist}/common/logging.d.ts +6 -3
  17. package/dist/common/logging.js +18 -0
  18. package/dist/common/logging.js.map +1 -0
  19. package/dist/common/packageVersions.cjs +42 -0
  20. package/dist/common/packageVersions.cjs.map +1 -0
  21. package/dist/common/packageVersions.d.cts +3 -0
  22. package/dist/common/packageVersions.d.ts +3 -0
  23. package/dist/common/packageVersions.js +18 -0
  24. package/dist/common/packageVersions.js.map +1 -0
  25. package/dist/common/paramValidation.cjs +43 -0
  26. package/dist/common/paramValidation.cjs.map +1 -0
  27. package/dist/common/paramValidation.d.cts +4 -0
  28. package/dist/common/paramValidation.d.ts +4 -0
  29. package/dist/common/paramValidation.js +19 -0
  30. package/dist/common/paramValidation.js.map +1 -0
  31. package/dist/common/requestCounter.cjs +111 -0
  32. package/dist/common/requestCounter.cjs.map +1 -0
  33. package/dist/common/requestCounter.d.cts +18 -0
  34. package/{lib/types → dist}/common/requestCounter.d.ts +7 -3
  35. package/dist/common/requestCounter.js +92 -0
  36. package/dist/common/requestCounter.js.map +1 -0
  37. package/dist/common/serverErrorCounter.cjs +133 -0
  38. package/dist/common/serverErrorCounter.cjs.map +1 -0
  39. package/dist/common/serverErrorCounter.d.cts +20 -0
  40. package/{lib/types → dist}/common/serverErrorCounter.d.ts +7 -3
  41. package/dist/common/serverErrorCounter.js +104 -0
  42. package/dist/common/serverErrorCounter.js.map +1 -0
  43. package/dist/common/types.cjs +19 -0
  44. package/dist/common/types.cjs.map +1 -0
  45. package/dist/common/types.d.cts +83 -0
  46. package/{lib/types → dist}/common/types.d.ts +25 -15
  47. package/dist/common/types.js +1 -0
  48. package/dist/common/types.js.map +1 -0
  49. package/dist/common/validationErrorCounter.cjs +76 -0
  50. package/dist/common/validationErrorCounter.cjs.map +1 -0
  51. package/dist/common/validationErrorCounter.d.cts +14 -0
  52. package/{lib/types → dist}/common/validationErrorCounter.d.ts +7 -3
  53. package/dist/common/validationErrorCounter.js +57 -0
  54. package/dist/common/validationErrorCounter.js.map +1 -0
  55. package/dist/express/index.cjs +898 -0
  56. package/dist/express/index.cjs.map +1 -0
  57. package/dist/express/index.d.cts +5 -0
  58. package/dist/express/index.d.ts +5 -0
  59. package/dist/express/index.js +862 -0
  60. package/dist/express/index.js.map +1 -0
  61. package/dist/express/listEndpoints.cjs +144 -0
  62. package/dist/express/listEndpoints.cjs.map +1 -0
  63. package/dist/express/listEndpoints.d.cts +3 -0
  64. package/dist/express/listEndpoints.d.ts +3 -0
  65. package/dist/express/listEndpoints.js +125 -0
  66. package/dist/express/listEndpoints.js.map +1 -0
  67. package/dist/express/middleware.cjs +896 -0
  68. package/dist/express/middleware.cjs.map +1 -0
  69. package/dist/express/middleware.d.cts +14 -0
  70. package/dist/express/middleware.d.ts +14 -0
  71. package/dist/express/middleware.js +862 -0
  72. package/dist/express/middleware.js.map +1 -0
  73. package/dist/fastify/index.cjs +754 -0
  74. package/dist/fastify/index.cjs.map +1 -0
  75. package/dist/fastify/index.d.cts +5 -0
  76. package/dist/fastify/index.d.ts +5 -0
  77. package/dist/fastify/index.js +718 -0
  78. package/dist/fastify/index.js.map +1 -0
  79. package/dist/fastify/plugin.cjs +748 -0
  80. package/dist/fastify/plugin.cjs.map +1 -0
  81. package/dist/fastify/plugin.d.cts +18 -0
  82. package/dist/fastify/plugin.d.ts +18 -0
  83. package/dist/fastify/plugin.js +718 -0
  84. package/dist/fastify/plugin.js.map +1 -0
  85. package/dist/index.cjs +2 -0
  86. package/dist/index.cjs.map +1 -0
  87. package/dist/index.d.cts +2 -0
  88. package/dist/index.d.ts +2 -0
  89. package/dist/index.js +1 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/koa/index.cjs +718 -0
  92. package/dist/koa/index.cjs.map +1 -0
  93. package/dist/koa/index.d.cts +5 -0
  94. package/dist/koa/index.d.ts +5 -0
  95. package/dist/koa/index.js +682 -0
  96. package/dist/koa/index.js.map +1 -0
  97. package/dist/koa/middleware.cjs +718 -0
  98. package/dist/koa/middleware.cjs.map +1 -0
  99. package/dist/koa/middleware.d.cts +8 -0
  100. package/dist/koa/middleware.d.ts +8 -0
  101. package/dist/koa/middleware.js +682 -0
  102. package/dist/koa/middleware.js.map +1 -0
  103. package/dist/nestjs/index.cjs +898 -0
  104. package/dist/nestjs/index.cjs.map +1 -0
  105. package/dist/nestjs/index.d.cts +5 -0
  106. package/dist/nestjs/index.d.ts +5 -0
  107. package/dist/nestjs/index.js +862 -0
  108. package/dist/nestjs/index.js.map +1 -0
  109. package/package.json +55 -92
  110. package/lib/cjs/common/client.cjs +0 -334
  111. package/lib/cjs/common/client.cjs.map +0 -1
  112. package/lib/cjs/common/logging.cjs +0 -17
  113. package/lib/cjs/common/logging.cjs.map +0 -1
  114. package/lib/cjs/common/packageVersions.cjs +0 -16
  115. package/lib/cjs/common/packageVersions.cjs.map +0 -1
  116. package/lib/cjs/common/paramValidation.cjs +0 -16
  117. package/lib/cjs/common/paramValidation.cjs.map +0 -1
  118. package/lib/cjs/common/requestCounter.cjs +0 -108
  119. package/lib/cjs/common/requestCounter.cjs.map +0 -1
  120. package/lib/cjs/common/serverErrorCounter.cjs +0 -154
  121. package/lib/cjs/common/serverErrorCounter.cjs.map +0 -1
  122. package/lib/cjs/common/types.cjs +0 -6
  123. package/lib/cjs/common/types.cjs.map +0 -1
  124. package/lib/cjs/common/validationErrorCounter.cjs +0 -60
  125. package/lib/cjs/common/validationErrorCounter.cjs.map +0 -1
  126. package/lib/cjs/express/index.cjs +0 -13
  127. package/lib/cjs/express/index.cjs.map +0 -1
  128. package/lib/cjs/express/listEndpoints.cjs +0 -177
  129. package/lib/cjs/express/listEndpoints.cjs.map +0 -1
  130. package/lib/cjs/express/middleware.cjs +0 -189
  131. package/lib/cjs/express/middleware.cjs.map +0 -1
  132. package/lib/cjs/fastify/index.cjs +0 -14
  133. package/lib/cjs/fastify/index.cjs.map +0 -1
  134. package/lib/cjs/fastify/plugin.cjs +0 -171
  135. package/lib/cjs/fastify/plugin.cjs.map +0 -1
  136. package/lib/cjs/index.cjs +0 -6
  137. package/lib/cjs/index.cjs.map +0 -1
  138. package/lib/cjs/koa/index.cjs +0 -13
  139. package/lib/cjs/koa/index.cjs.map +0 -1
  140. package/lib/cjs/koa/middleware.cjs +0 -139
  141. package/lib/cjs/koa/middleware.cjs.map +0 -1
  142. package/lib/cjs/nestjs/index.cjs +0 -13
  143. package/lib/cjs/nestjs/index.cjs.map +0 -1
  144. package/lib/esm/common/client.js +0 -324
  145. package/lib/esm/common/client.js.map +0 -1
  146. package/lib/esm/common/logging.js +0 -11
  147. package/lib/esm/common/logging.js.map +0 -1
  148. package/lib/esm/common/packageVersions.js +0 -10
  149. package/lib/esm/common/packageVersions.js.map +0 -1
  150. package/lib/esm/common/paramValidation.js +0 -9
  151. package/lib/esm/common/paramValidation.js.map +0 -1
  152. package/lib/esm/common/requestCounter.js +0 -102
  153. package/lib/esm/common/requestCounter.js.map +0 -1
  154. package/lib/esm/common/serverErrorCounter.js +0 -143
  155. package/lib/esm/common/serverErrorCounter.js.map +0 -1
  156. package/lib/esm/common/types.js +0 -1
  157. package/lib/esm/common/types.js.map +0 -1
  158. package/lib/esm/common/validationErrorCounter.js +0 -54
  159. package/lib/esm/common/validationErrorCounter.js.map +0 -1
  160. package/lib/esm/express/index.js +0 -1
  161. package/lib/esm/express/index.js.map +0 -1
  162. package/lib/esm/express/listEndpoints.js +0 -170
  163. package/lib/esm/express/listEndpoints.js.map +0 -1
  164. package/lib/esm/express/middleware.js +0 -182
  165. package/lib/esm/express/middleware.js.map +0 -1
  166. package/lib/esm/fastify/index.js +0 -1
  167. package/lib/esm/fastify/index.js.map +0 -1
  168. package/lib/esm/fastify/plugin.js +0 -164
  169. package/lib/esm/fastify/plugin.js.map +0 -1
  170. package/lib/esm/index.js +0 -1
  171. package/lib/esm/index.js.map +0 -1
  172. package/lib/esm/koa/index.js +0 -1
  173. package/lib/esm/koa/index.js.map +0 -1
  174. package/lib/esm/koa/middleware.js +0 -132
  175. package/lib/esm/koa/middleware.js.map +0 -1
  176. package/lib/esm/nestjs/index.js +0 -1
  177. package/lib/esm/nestjs/index.js.map +0 -1
  178. package/lib/types/common/client.d.ts +0 -33
  179. package/lib/types/common/client.d.ts.map +0 -1
  180. package/lib/types/common/logging.d.ts.map +0 -1
  181. package/lib/types/common/packageVersions.d.ts +0 -2
  182. package/lib/types/common/packageVersions.d.ts.map +0 -1
  183. package/lib/types/common/paramValidation.d.ts +0 -3
  184. package/lib/types/common/paramValidation.d.ts.map +0 -1
  185. package/lib/types/common/requestCounter.d.ts.map +0 -1
  186. package/lib/types/common/serverErrorCounter.d.ts.map +0 -1
  187. package/lib/types/common/types.d.ts.map +0 -1
  188. package/lib/types/common/validationErrorCounter.d.ts.map +0 -1
  189. package/lib/types/express/index.d.ts +0 -2
  190. package/lib/types/express/index.d.ts.map +0 -1
  191. package/lib/types/express/listEndpoints.d.ts +0 -3
  192. package/lib/types/express/listEndpoints.d.ts.map +0 -1
  193. package/lib/types/express/middleware.d.ts +0 -10
  194. package/lib/types/express/middleware.d.ts.map +0 -1
  195. package/lib/types/fastify/index.d.ts +0 -2
  196. package/lib/types/fastify/index.d.ts.map +0 -1
  197. package/lib/types/fastify/plugin.d.ts +0 -15
  198. package/lib/types/fastify/plugin.d.ts.map +0 -1
  199. package/lib/types/index.d.ts +0 -2
  200. package/lib/types/index.d.ts.map +0 -1
  201. package/lib/types/koa/index.d.ts +0 -2
  202. package/lib/types/koa/index.d.ts.map +0 -1
  203. package/lib/types/koa/middleware.d.ts +0 -4
  204. package/lib/types/koa/middleware.d.ts.map +0 -1
  205. package/lib/types/nestjs/index.d.ts +0 -2
  206. package/lib/types/nestjs/index.d.ts.map +0 -1
@@ -0,0 +1,92 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common/requestCounter.ts
5
+ var _RequestCounter = class _RequestCounter {
6
+ requestCounts;
7
+ requestSizeSums;
8
+ responseSizeSums;
9
+ responseTimes;
10
+ requestSizes;
11
+ responseSizes;
12
+ constructor() {
13
+ this.requestCounts = /* @__PURE__ */ new Map();
14
+ this.requestSizeSums = /* @__PURE__ */ new Map();
15
+ this.responseSizeSums = /* @__PURE__ */ new Map();
16
+ this.responseTimes = /* @__PURE__ */ new Map();
17
+ this.requestSizes = /* @__PURE__ */ new Map();
18
+ this.responseSizes = /* @__PURE__ */ new Map();
19
+ }
20
+ getKey(requestInfo) {
21
+ return [
22
+ requestInfo.consumer || "",
23
+ requestInfo.method.toUpperCase(),
24
+ requestInfo.path,
25
+ requestInfo.statusCode
26
+ ].join("|");
27
+ }
28
+ addRequest(requestInfo) {
29
+ const key = this.getKey(requestInfo);
30
+ this.requestCounts.set(key, (this.requestCounts.get(key) || 0) + 1);
31
+ if (!this.responseTimes.has(key)) {
32
+ this.responseTimes.set(key, /* @__PURE__ */ new Map());
33
+ }
34
+ const responseTimeMap = this.responseTimes.get(key);
35
+ const responseTimeMsBin = Math.floor(requestInfo.responseTime / 10) * 10;
36
+ responseTimeMap.set(responseTimeMsBin, (responseTimeMap.get(responseTimeMsBin) || 0) + 1);
37
+ if (requestInfo.requestSize !== void 0) {
38
+ requestInfo.requestSize = Number(requestInfo.requestSize);
39
+ this.requestSizeSums.set(key, (this.requestSizeSums.get(key) || 0) + requestInfo.requestSize);
40
+ if (!this.requestSizes.has(key)) {
41
+ this.requestSizes.set(key, /* @__PURE__ */ new Map());
42
+ }
43
+ const requestSizeMap = this.requestSizes.get(key);
44
+ const requestSizeKbBin = Math.floor(requestInfo.requestSize / 1e3);
45
+ requestSizeMap.set(requestSizeKbBin, (requestSizeMap.get(requestSizeKbBin) || 0) + 1);
46
+ }
47
+ if (requestInfo.responseSize !== void 0) {
48
+ requestInfo.responseSize = Number(requestInfo.responseSize);
49
+ this.responseSizeSums.set(key, (this.responseSizeSums.get(key) || 0) + requestInfo.responseSize);
50
+ if (!this.responseSizes.has(key)) {
51
+ this.responseSizes.set(key, /* @__PURE__ */ new Map());
52
+ }
53
+ const responseSizeMap = this.responseSizes.get(key);
54
+ const responseSizeKbBin = Math.floor(requestInfo.responseSize / 1e3);
55
+ responseSizeMap.set(responseSizeKbBin, (responseSizeMap.get(responseSizeKbBin) || 0) + 1);
56
+ }
57
+ }
58
+ getAndResetRequests() {
59
+ const data = [];
60
+ this.requestCounts.forEach((count, key) => {
61
+ const [consumer, method, path, statusCodeStr] = key.split("|");
62
+ const responseTimes = this.responseTimes.get(key) || /* @__PURE__ */ new Map();
63
+ const requestSizes = this.requestSizes.get(key) || /* @__PURE__ */ new Map();
64
+ const responseSizes = this.responseSizes.get(key) || /* @__PURE__ */ new Map();
65
+ data.push({
66
+ consumer: consumer || null,
67
+ method,
68
+ path,
69
+ status_code: parseInt(statusCodeStr),
70
+ request_count: count,
71
+ request_size_sum: this.requestSizeSums.get(key) || 0,
72
+ response_size_sum: this.responseSizeSums.get(key) || 0,
73
+ response_times: Object.fromEntries(responseTimes),
74
+ request_sizes: Object.fromEntries(requestSizes),
75
+ response_sizes: Object.fromEntries(responseSizes)
76
+ });
77
+ });
78
+ this.requestCounts.clear();
79
+ this.requestSizeSums.clear();
80
+ this.responseSizeSums.clear();
81
+ this.responseTimes.clear();
82
+ this.requestSizes.clear();
83
+ this.responseSizes.clear();
84
+ return data;
85
+ }
86
+ };
87
+ __name(_RequestCounter, "RequestCounter");
88
+ var RequestCounter = _RequestCounter;
89
+ export {
90
+ RequestCounter as default
91
+ };
92
+ //# sourceMappingURL=requestCounter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/requestCounter.ts"],"sourcesContent":["import { RequestInfo, RequestsItem } from \"./types.js\";\n\nexport default class RequestCounter {\n private requestCounts: Map<string, number>;\n private requestSizeSums: Map<string, number>;\n private responseSizeSums: Map<string, number>;\n private responseTimes: Map<string, Map<number, number>>;\n private requestSizes: Map<string, Map<number, number>>;\n private responseSizes: Map<string, Map<number, number>>;\n\n constructor() {\n this.requestCounts = new Map<string, number>();\n this.requestSizeSums = new Map<string, number>();\n this.responseSizeSums = new Map<string, number>();\n this.responseTimes = new Map<string, Map<number, number>>();\n this.requestSizes = new Map<string, Map<number, number>>();\n this.responseSizes = new Map<string, Map<number, number>>();\n }\n\n private getKey(requestInfo: RequestInfo) {\n return [\n requestInfo.consumer || \"\",\n requestInfo.method.toUpperCase(),\n requestInfo.path,\n requestInfo.statusCode,\n ].join(\"|\");\n }\n\n addRequest(requestInfo: RequestInfo) {\n const key = this.getKey(requestInfo);\n\n // Increment request count\n this.requestCounts.set(key, (this.requestCounts.get(key) || 0) + 1);\n\n // Add response time\n if (!this.responseTimes.has(key)) {\n this.responseTimes.set(key, new Map<number, number>());\n }\n const responseTimeMap = this.responseTimes.get(key)!;\n const responseTimeMsBin = Math.floor(requestInfo.responseTime / 10) * 10; // Rounded to nearest 10ms\n responseTimeMap.set(\n responseTimeMsBin,\n (responseTimeMap.get(responseTimeMsBin) || 0) + 1,\n );\n\n // Add request size\n if (requestInfo.requestSize !== undefined) {\n requestInfo.requestSize = Number(requestInfo.requestSize);\n this.requestSizeSums.set(\n key,\n (this.requestSizeSums.get(key) || 0) + requestInfo.requestSize,\n );\n if (!this.requestSizes.has(key)) {\n this.requestSizes.set(key, new Map<number, number>());\n }\n const requestSizeMap = this.requestSizes.get(key)!;\n const requestSizeKbBin = Math.floor(requestInfo.requestSize / 1000); // Rounded down to nearest KB\n requestSizeMap.set(\n requestSizeKbBin,\n (requestSizeMap.get(requestSizeKbBin) || 0) + 1,\n );\n }\n\n // Add response size\n if (requestInfo.responseSize !== undefined) {\n requestInfo.responseSize = Number(requestInfo.responseSize);\n this.responseSizeSums.set(\n key,\n (this.responseSizeSums.get(key) || 0) + requestInfo.responseSize,\n );\n if (!this.responseSizes.has(key)) {\n this.responseSizes.set(key, new Map<number, number>());\n }\n const responseSizeMap = this.responseSizes.get(key)!;\n const responseSizeKbBin = Math.floor(requestInfo.responseSize / 1000); // Rounded down to nearest KB\n responseSizeMap.set(\n responseSizeKbBin,\n (responseSizeMap.get(responseSizeKbBin) || 0) + 1,\n );\n }\n }\n\n getAndResetRequests() {\n const data: Array<RequestsItem> = [];\n this.requestCounts.forEach((count, key) => {\n const [consumer, method, path, statusCodeStr] = key.split(\"|\");\n const responseTimes =\n this.responseTimes.get(key) || new Map<number, number>();\n const requestSizes =\n this.requestSizes.get(key) || new Map<number, number>();\n const responseSizes =\n this.responseSizes.get(key) || new Map<number, number>();\n data.push({\n consumer: consumer || null,\n method,\n path,\n status_code: parseInt(statusCodeStr),\n request_count: count,\n request_size_sum: this.requestSizeSums.get(key) || 0,\n response_size_sum: this.responseSizeSums.get(key) || 0,\n response_times: Object.fromEntries(responseTimes),\n request_sizes: Object.fromEntries(requestSizes),\n response_sizes: Object.fromEntries(responseSizes),\n });\n });\n\n // Reset the counts and times\n this.requestCounts.clear();\n this.requestSizeSums.clear();\n this.responseSizeSums.clear();\n this.responseTimes.clear();\n this.requestSizes.clear();\n this.responseSizes.clear();\n\n return data;\n }\n}\n"],"mappings":";;;;AAEA,IAAqBA,kBAArB,MAAqBA,gBAAAA;EACXC;EACAC;EACAC;EACAC;EACAC;EACAC;EAERC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8C,eAAeF,OAAOC,YAAY5C,YAAAA;QAClC8C,gBAAgBH,OAAOC,YAAY3C,aAAAA;MACrC,CAAA;IACF,CAAA;AAGA,SAAKL,cAAcmD,MAAK;AACxB,SAAKlD,gBAAgBkD,MAAK;AAC1B,SAAKjD,iBAAiBiD,MAAK;AAC3B,SAAKhD,cAAcgD,MAAK;AACxB,SAAK/C,aAAa+C,MAAK;AACvB,SAAK9C,cAAc8C,MAAK;AAExB,WAAOhB;EACT;AACF;AAlHqBpC;AAArB,IAAqBA,iBAArB;","names":["RequestCounter","requestCounts","requestSizeSums","responseSizeSums","responseTimes","requestSizes","responseSizes","constructor","Map","getKey","requestInfo","consumer","method","toUpperCase","path","statusCode","join","addRequest","key","set","get","has","responseTimeMap","responseTimeMsBin","Math","floor","responseTime","requestSize","undefined","Number","requestSizeMap","requestSizeKbBin","responseSize","responseSizeMap","responseSizeKbBin","getAndResetRequests","data","forEach","count","statusCodeStr","split","push","status_code","parseInt","request_count","request_size_sum","response_size_sum","response_times","Object","fromEntries","request_sizes","response_sizes","clear"]}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/common/serverErrorCounter.ts
32
+ var serverErrorCounter_exports = {};
33
+ __export(serverErrorCounter_exports, {
34
+ default: () => ServerErrorCounter
35
+ });
36
+ module.exports = __toCommonJS(serverErrorCounter_exports);
37
+ var import_crypto = require("crypto");
38
+ var MAX_MSG_LENGTH = 2048;
39
+ var MAX_STACKTRACE_LENGTH = 65536;
40
+ var _ServerErrorCounter = class _ServerErrorCounter {
41
+ errorCounts;
42
+ errorDetails;
43
+ sentryEventIds;
44
+ sentry;
45
+ constructor() {
46
+ this.errorCounts = /* @__PURE__ */ new Map();
47
+ this.errorDetails = /* @__PURE__ */ new Map();
48
+ this.sentryEventIds = /* @__PURE__ */ new Map();
49
+ this.tryImportSentry();
50
+ }
51
+ addServerError(serverError) {
52
+ const key = this.getKey(serverError);
53
+ if (!this.errorDetails.has(key)) {
54
+ this.errorDetails.set(key, serverError);
55
+ }
56
+ this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);
57
+ this.captureSentryEventId(key);
58
+ }
59
+ getAndResetServerErrors() {
60
+ const data = [];
61
+ this.errorCounts.forEach((count, key) => {
62
+ const serverError = this.errorDetails.get(key);
63
+ if (serverError) {
64
+ data.push({
65
+ consumer: serverError.consumer || null,
66
+ method: serverError.method,
67
+ path: serverError.path,
68
+ type: serverError.type,
69
+ msg: this.getTruncatedMessage(serverError.msg),
70
+ traceback: this.getTruncatedStack(serverError.traceback),
71
+ sentry_event_id: this.sentryEventIds.get(key) || null,
72
+ error_count: count
73
+ });
74
+ }
75
+ });
76
+ this.errorCounts.clear();
77
+ this.errorDetails.clear();
78
+ return data;
79
+ }
80
+ getKey(serverError) {
81
+ const hashInput = [
82
+ serverError.consumer || "",
83
+ serverError.method.toUpperCase(),
84
+ serverError.path,
85
+ serverError.type,
86
+ serverError.msg.trim(),
87
+ serverError.traceback.trim()
88
+ ].join("|");
89
+ return (0, import_crypto.createHash)("md5").update(hashInput).digest("hex");
90
+ }
91
+ getTruncatedMessage(msg) {
92
+ msg = msg.trim();
93
+ if (msg.length <= MAX_MSG_LENGTH) {
94
+ return msg;
95
+ }
96
+ const suffix = "... (truncated)";
97
+ const cutoff = MAX_MSG_LENGTH - suffix.length;
98
+ return msg.substring(0, cutoff) + suffix;
99
+ }
100
+ getTruncatedStack(stack) {
101
+ const suffix = "... (truncated) ...";
102
+ const cutoff = MAX_STACKTRACE_LENGTH - suffix.length;
103
+ const lines = stack.trim().split("\n");
104
+ const truncatedLines = [];
105
+ let length = 0;
106
+ for (const line of lines) {
107
+ if (length + line.length + 1 > cutoff) {
108
+ truncatedLines.push(suffix);
109
+ break;
110
+ }
111
+ truncatedLines.push(line);
112
+ length += line.length + 1;
113
+ }
114
+ return truncatedLines.join("\n");
115
+ }
116
+ captureSentryEventId(serverErrorKey) {
117
+ if (this.sentry && this.sentry.lastEventId) {
118
+ const eventId = this.sentry.lastEventId();
119
+ if (eventId) {
120
+ this.sentryEventIds.set(serverErrorKey, eventId);
121
+ }
122
+ }
123
+ }
124
+ async tryImportSentry() {
125
+ try {
126
+ this.sentry = await import("@sentry/node");
127
+ } catch (e) {
128
+ }
129
+ }
130
+ };
131
+ __name(_ServerErrorCounter, "ServerErrorCounter");
132
+ var ServerErrorCounter = _ServerErrorCounter;
133
+ //# sourceMappingURL=serverErrorCounter.cjs.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;oBAA2B;AAI3B,IAAMA,iBAAiB;AACvB,IAAMC,wBAAwB;AAE9B,IAAqBC,sBAArB,MAAqBA,oBAAAA;EACXC;EACAC;EACAC;EACAC;EAERC,cAAc;AACZ,SAAKJ,cAAc,oBAAIK,IAAAA;AACvB,SAAKJ,eAAe,oBAAII,IAAAA;AACxB,SAAKH,iBAAiB,oBAAIG,IAAAA;AAC1B,SAAKC,gBAAe;EACtB;EAEOC,eAAeC,aAA+C;AACnE,UAAMC,MAAM,KAAKC,OAAOF,WAAAA;AACxB,QAAI,CAAC,KAAKP,aAAaU,IAAIF,GAAAA,GAAM;AAC/B,WAAKR,aAAaW,IAAIH,KAAKD,WAAAA;IAC7B;AACA,SAAKR,YAAYY,IAAIH,MAAM,KAAKT,YAAYa,IAAIJ,GAAAA,KAAQ,KAAK,CAAA;AAC7D,SAAKK,qBAAqBL,GAAAA;EAC5B;EAEOM,0BAA0B;AAC/B,UAAMC,OAAgC,CAAA;AACtC,SAAKhB,YAAYiB,QAAQ,CAACC,OAAOT,QAAAA;AAC/B,YAAMD,cAAc,KAAKP,aAAaY,IAAIJ,GAAAA;AAC1C,UAAID,aAAa;AACfQ,aAAKG,KAAK;UACRC,UAAUZ,YAAYY,YAAY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EQpB,qBAAqBiC,gBAAwB;AACnD,QAAI,KAAK5C,UAAU,KAAKA,OAAO6C,aAAa;AAC1C,YAAMC,UAAU,KAAK9C,OAAO6C,YAAW;AACvC,UAAIC,SAAS;AACX,aAAK/C,eAAeU,IAAImC,gBAAgBE,OAAAA;MAC1C;IACF;EACF;EAEA,MAAc3C,kBAAkB;AAC9B,QAAI;AACF,WAAKH,SAAS,MAAM,OAAO,cAAA;IAC7B,SAAS+C,GAAG;IAEZ;EACF;AACF;AAnGqBnD;AAArB,IAAqBA,qBAArB;","names":["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,20 @@
1
+ import { ConsumerMethodPath, ServerError, ServerErrorsItem } from './types.cjs';
2
+ import './logging.cjs';
3
+ import 'winston';
4
+
5
+ declare class ServerErrorCounter {
6
+ private errorCounts;
7
+ private errorDetails;
8
+ private sentryEventIds;
9
+ private sentry;
10
+ constructor();
11
+ addServerError(serverError: ConsumerMethodPath & ServerError): void;
12
+ getAndResetServerErrors(): ServerErrorsItem[];
13
+ private getKey;
14
+ private getTruncatedMessage;
15
+ private getTruncatedStack;
16
+ private captureSentryEventId;
17
+ private tryImportSentry;
18
+ }
19
+
20
+ export { ServerErrorCounter as default };
@@ -1,5 +1,8 @@
1
- import { ConsumerMethodPath, ServerError, ServerErrorsItem } from "./types.js";
2
- export default class ServerErrorCounter {
1
+ import { ConsumerMethodPath, ServerError, ServerErrorsItem } from './types.js';
2
+ import './logging.js';
3
+ import 'winston';
4
+
5
+ declare class ServerErrorCounter {
3
6
  private errorCounts;
4
7
  private errorDetails;
5
8
  private sentryEventIds;
@@ -13,4 +16,5 @@ export default class ServerErrorCounter {
13
16
  private captureSentryEventId;
14
17
  private tryImportSentry;
15
18
  }
16
- //# sourceMappingURL=serverErrorCounter.d.ts.map
19
+
20
+ export { ServerErrorCounter as default };
@@ -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":";;;;AACA,SAASA,kBAAkB;AAI3B,IAAMC,iBAAiB;AACvB,IAAMC,wBAAwB;AAE9B,IAAqBC,sBAArB,MAAqBA,oBAAAA;EACXC;EACAC;EACAC;EACAC;EAERC,cAAc;AACZ,SAAKJ,cAAc,oBAAIK,IAAAA;AACvB,SAAKJ,eAAe,oBAAII,IAAAA;AACxB,SAAKH,iBAAiB,oBAAIG,IAAAA;AAC1B,SAAKC,gBAAe;EACtB;EAEOC,eAAeC,aAA+C;AACnE,UAAMC,MAAM,KAAKC,OAAOF,WAAAA;AACxB,QAAI,CAAC,KAAKP,aAAaU,IAAIF,GAAAA,GAAM;AAC/B,WAAKR,aAAaW,IAAIH,KAAKD,WAAAA;IAC7B;AACA,SAAKR,YAAYY,IAAIH,MAAM,KAAKT,YAAYa,IAAIJ,GAAAA,KAAQ,KAAK,CAAA;AAC7D,SAAKK,qBAAqBL,GAAAA;EAC5B;EAEOM,0BAA0B;AAC/B,UAAMC,OAAgC,CAAA;AACtC,SAAKhB,YAAYiB,QAAQ,CAACC,OAAOT,QAAAA;AAC/B,YAAMD,cAAc,KAAKP,aAAaY,IAAIJ,GAAAA;AAC1C,UAAID,aAAa;AACfQ,aAAKG,KAAK;UACRC,UAAUZ,YAAYY,YAAY;UAClCC,QAAQb,YAAYa;UACpBC,MAAMd,YAAYc;UAClBC,MAAMf,YAAYe;UAClBC,KAAK,KAAKC,oBAAoBjB,YAAYgB,GAAG;UAC7CE,WAAW,KAAKC,kBAAkBnB,YAAYkB,SAAS;UACvDE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AAgBE,OAAAA;MAC1C;IACF;EACF;EAEA,MAAc3C,kBAAkB;AAC9B,QAAI;AACF,WAAKH,SAAS,MAAM,OAAO,cAAA;IAC7B,SAAS+C,GAAG;IAEZ;EACF;AACF;AAnGqBnD;AAArB,IAAqBA,qBAArB;","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 ApitallyConsumer = {\n identifier: string;\n name?: string | null;\n group?: string | null;\n};\n\nexport type PathInfo = {\n method: string;\n path: string;\n};\n\nexport type StartupData = {\n paths: PathInfo[];\n versions: Record<string, string>;\n client: string;\n};\n\nexport type StartupPayload = {\n instance_uuid: string;\n message_uuid: string;\n} & StartupData;\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 ConsumerItem = ApitallyConsumer;\n\nexport type SyncPayload = {\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 consumers: Array<ConsumerItem>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAoFA;;","names":[]}
@@ -0,0 +1,83 @@
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 ApitallyConsumer = {
12
+ identifier: string;
13
+ name?: string | null;
14
+ group?: string | null;
15
+ };
16
+ type PathInfo = {
17
+ method: string;
18
+ path: string;
19
+ };
20
+ type StartupData = {
21
+ paths: PathInfo[];
22
+ versions: Record<string, string>;
23
+ client: string;
24
+ };
25
+ type StartupPayload = {
26
+ instance_uuid: string;
27
+ message_uuid: string;
28
+ } & StartupData;
29
+ type ConsumerMethodPath = {
30
+ consumer?: string | null;
31
+ method: string;
32
+ path: string;
33
+ };
34
+ type RequestInfo = ConsumerMethodPath & {
35
+ statusCode: number;
36
+ responseTime: number;
37
+ requestSize?: string | number;
38
+ responseSize?: string | number;
39
+ };
40
+ type RequestsItem = ConsumerMethodPath & {
41
+ status_code: number;
42
+ request_count: number;
43
+ request_size_sum: number;
44
+ response_size_sum: number;
45
+ response_times: Record<number, number>;
46
+ request_sizes: Record<number, number>;
47
+ response_sizes: Record<number, number>;
48
+ };
49
+ type ValidationError = {
50
+ loc: string;
51
+ msg: string;
52
+ type: string;
53
+ };
54
+ type ValidationErrorsItem = ConsumerMethodPath & {
55
+ loc: Array<string>;
56
+ msg: string;
57
+ type: string;
58
+ error_count: number;
59
+ };
60
+ type ServerError = {
61
+ type: string;
62
+ msg: string;
63
+ traceback: string;
64
+ };
65
+ type ServerErrorsItem = ConsumerMethodPath & {
66
+ type: string;
67
+ msg: string;
68
+ traceback: string;
69
+ sentry_event_id: string | null;
70
+ error_count: number;
71
+ };
72
+ type ConsumerItem = ApitallyConsumer;
73
+ type SyncPayload = {
74
+ time_offset: number;
75
+ instance_uuid: string;
76
+ message_uuid: string;
77
+ requests: Array<RequestsItem>;
78
+ validation_errors: Array<ValidationErrorsItem>;
79
+ server_errors: Array<ServerErrorsItem>;
80
+ consumers: Array<ConsumerItem>;
81
+ };
82
+
83
+ export type { ApitallyConfig, ApitallyConsumer, ConsumerItem, ConsumerMethodPath, PathInfo, RequestInfo, RequestsItem, ServerError, ServerErrorsItem, StartupData, StartupPayload, SyncPayload, ValidationError, ValidationErrorsItem };
@@ -1,36 +1,43 @@
1
- import { Logger } from "./logging.js";
2
- export type ApitallyConfig = {
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
- export type PathInfo = {
11
+ type ApitallyConsumer = {
12
+ identifier: string;
13
+ name?: string | null;
14
+ group?: string | null;
15
+ };
16
+ type PathInfo = {
10
17
  method: string;
11
18
  path: string;
12
19
  };
13
- export type AppInfo = {
20
+ type StartupData = {
14
21
  paths: PathInfo[];
15
22
  versions: Record<string, string>;
16
23
  client: string;
17
24
  };
18
- export type AppInfoPayload = {
25
+ type StartupPayload = {
19
26
  instance_uuid: string;
20
27
  message_uuid: string;
21
- } & AppInfo;
22
- export type ConsumerMethodPath = {
28
+ } & StartupData;
29
+ type ConsumerMethodPath = {
23
30
  consumer?: string | null;
24
31
  method: string;
25
32
  path: string;
26
33
  };
27
- export type RequestInfo = ConsumerMethodPath & {
34
+ type RequestInfo = ConsumerMethodPath & {
28
35
  statusCode: number;
29
36
  responseTime: number;
30
37
  requestSize?: string | number;
31
38
  responseSize?: string | number;
32
39
  };
33
- export type RequestsItem = ConsumerMethodPath & {
40
+ type RequestsItem = ConsumerMethodPath & {
34
41
  status_code: number;
35
42
  request_count: number;
36
43
  request_size_sum: number;
@@ -39,35 +46,38 @@ export type RequestsItem = ConsumerMethodPath & {
39
46
  request_sizes: Record<number, number>;
40
47
  response_sizes: Record<number, number>;
41
48
  };
42
- export type ValidationError = {
49
+ type ValidationError = {
43
50
  loc: string;
44
51
  msg: string;
45
52
  type: string;
46
53
  };
47
- export type ValidationErrorsItem = ConsumerMethodPath & {
54
+ type ValidationErrorsItem = ConsumerMethodPath & {
48
55
  loc: Array<string>;
49
56
  msg: string;
50
57
  type: string;
51
58
  error_count: number;
52
59
  };
53
- export type ServerError = {
60
+ type ServerError = {
54
61
  type: string;
55
62
  msg: string;
56
63
  traceback: string;
57
64
  };
58
- export type ServerErrorsItem = ConsumerMethodPath & {
65
+ type ServerErrorsItem = ConsumerMethodPath & {
59
66
  type: string;
60
67
  msg: string;
61
68
  traceback: string;
62
69
  sentry_event_id: string | null;
63
70
  error_count: number;
64
71
  };
65
- export type RequestsDataPayload = {
72
+ type ConsumerItem = ApitallyConsumer;
73
+ type SyncPayload = {
66
74
  time_offset: number;
67
75
  instance_uuid: string;
68
76
  message_uuid: string;
69
77
  requests: Array<RequestsItem>;
70
78
  validation_errors: Array<ValidationErrorsItem>;
71
79
  server_errors: Array<ServerErrorsItem>;
80
+ consumers: Array<ConsumerItem>;
72
81
  };
73
- //# sourceMappingURL=types.d.ts.map
82
+
83
+ export type { ApitallyConfig, ApitallyConsumer, ConsumerItem, ConsumerMethodPath, PathInfo, RequestInfo, RequestsItem, ServerError, ServerErrorsItem, StartupData, StartupPayload, SyncPayload, ValidationError, ValidationErrorsItem };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}