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,86 @@
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/consumerRegistry.ts
22
+ var consumerRegistry_exports = {};
23
+ __export(consumerRegistry_exports, {
24
+ consumerFromStringOrObject: () => consumerFromStringOrObject,
25
+ default: () => ConsumerRegistry
26
+ });
27
+ module.exports = __toCommonJS(consumerRegistry_exports);
28
+ var consumerFromStringOrObject = /* @__PURE__ */ __name((consumer) => {
29
+ var _a, _b;
30
+ if (typeof consumer === "string") {
31
+ consumer = String(consumer).trim().substring(0, 128);
32
+ return consumer ? {
33
+ identifier: consumer
34
+ } : null;
35
+ } else {
36
+ consumer.identifier = String(consumer.identifier).trim().substring(0, 128);
37
+ consumer.name = (_a = consumer.name) == null ? void 0 : _a.trim().substring(0, 64);
38
+ consumer.group = (_b = consumer.group) == null ? void 0 : _b.trim().substring(0, 64);
39
+ return consumer.identifier ? consumer : null;
40
+ }
41
+ }, "consumerFromStringOrObject");
42
+ var _ConsumerRegistry = class _ConsumerRegistry {
43
+ consumers;
44
+ updated;
45
+ constructor() {
46
+ this.consumers = /* @__PURE__ */ new Map();
47
+ this.updated = /* @__PURE__ */ new Set();
48
+ }
49
+ addOrUpdateConsumer(consumer) {
50
+ if (!consumer || !consumer.name && !consumer.group) {
51
+ return;
52
+ }
53
+ const existing = this.consumers.get(consumer.identifier);
54
+ if (!existing) {
55
+ this.consumers.set(consumer.identifier, consumer);
56
+ this.updated.add(consumer.identifier);
57
+ } else {
58
+ if (consumer.name && consumer.name !== existing.name) {
59
+ existing.name = consumer.name;
60
+ this.updated.add(consumer.identifier);
61
+ }
62
+ if (consumer.group && consumer.group !== existing.group) {
63
+ existing.group = consumer.group;
64
+ this.updated.add(consumer.identifier);
65
+ }
66
+ }
67
+ }
68
+ getAndResetUpdatedConsumers() {
69
+ const data = [];
70
+ this.updated.forEach((identifier) => {
71
+ const consumer = this.consumers.get(identifier);
72
+ if (consumer) {
73
+ data.push(consumer);
74
+ }
75
+ });
76
+ this.updated.clear();
77
+ return data;
78
+ }
79
+ };
80
+ __name(_ConsumerRegistry, "ConsumerRegistry");
81
+ var ConsumerRegistry = _ConsumerRegistry;
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ consumerFromStringOrObject
85
+ });
86
+ //# sourceMappingURL=consumerRegistry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/consumerRegistry.ts"],"sourcesContent":["import { ApitallyConsumer } from \"./types.js\";\n\nexport const consumerFromStringOrObject = (\n consumer: ApitallyConsumer | string,\n) => {\n if (typeof consumer === \"string\") {\n consumer = String(consumer).trim().substring(0, 128);\n return consumer ? { identifier: consumer } : null;\n } else {\n consumer.identifier = String(consumer.identifier).trim().substring(0, 128);\n consumer.name = consumer.name?.trim().substring(0, 64);\n consumer.group = consumer.group?.trim().substring(0, 64);\n return consumer.identifier ? consumer : null;\n }\n};\n\nexport default class ConsumerRegistry {\n private consumers: Map<string, ApitallyConsumer>;\n private updated: Set<string>;\n\n constructor() {\n this.consumers = new Map();\n this.updated = new Set();\n }\n\n public addOrUpdateConsumer(consumer?: ApitallyConsumer | null) {\n if (!consumer || (!consumer.name && !consumer.group)) {\n return;\n }\n const existing = this.consumers.get(consumer.identifier);\n if (!existing) {\n this.consumers.set(consumer.identifier, consumer);\n this.updated.add(consumer.identifier);\n } else {\n if (consumer.name && consumer.name !== existing.name) {\n existing.name = consumer.name;\n this.updated.add(consumer.identifier);\n }\n if (consumer.group && consumer.group !== existing.group) {\n existing.group = consumer.group;\n this.updated.add(consumer.identifier);\n }\n }\n }\n\n public getAndResetUpdatedConsumers() {\n const data: Array<ApitallyConsumer> = [];\n this.updated.forEach((identifier) => {\n const consumer = this.consumers.get(identifier);\n if (consumer) {\n data.push(consumer);\n }\n });\n this.updated.clear();\n return data;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;AAAO,IAAMA,6BAA6B,wBACxCC,aAAAA;AADF;AAGE,MAAI,OAAOA,aAAa,UAAU;AAChCA,eAAWC,OAAOD,QAAAA,EAAUE,KAAI,EAAGC,UAAU,GAAG,GAAA;AAChD,WAAOH,WAAW;MAAEI,YAAYJ;IAAS,IAAI;EAC/C,OAAO;AACLA,aAASI,aAAaH,OAAOD,SAASI,UAAU,EAAEF,KAAI,EAAGC,UAAU,GAAG,GAAA;AACtEH,aAASK,QAAOL,cAASK,SAATL,mBAAeE,OAAOC,UAAU,GAAG;AACnDH,aAASM,SAAQN,cAASM,UAATN,mBAAgBE,OAAOC,UAAU,GAAG;AACrD,WAAOH,SAASI,aAAaJ,WAAW;EAC1C;AACF,GAZ0C;AAc1C,IAAqBO,oBAArB,MAAqBA,kBAAAA;EACXC;EACAC;EAERC,cAAc;AACZ,SAAKF,YAAY,oBAAIG,IAAAA;AACrB,SAAKF,UAAU,oBAAIG,IAAAA;EACrB;EAEOC,oBAAoBb,UAAoC;AAC7D,QAAI,CAACA,YAAa,CAACA,SAASK,QAAQ,CAACL,SAASM,OAAQ;AACpD;IACF;AACA,UAAMQ,WAAW,KAAKN,UAAUO,IAAIf,SAASI,UAAU;AACvD,QAAI,CAACU,UAAU;AACb,WAAKN,UAAUQ,IAAIhB,SAASI,YAAYJ,QAAAA;AACxC,WAAKS,QAAQQ,IAAIjB,SAASI,UAAU;IACtC,OAAO;AACL,UAAIJ,SAASK,QAAQL,SAASK,SAASS,SAAST,MAAM;AACpDS,iBAAST,OAAOL,SAASK;AACzB,aAAKI,QAAQQ,IAAIjB,SAASI,UAAU;MACtC;AACA,UAAIJ,SAASM,SAASN,SAASM,UAAUQ,SAASR,OAAO;AACvDQ,iBAASR,QAAQN,SAASM;AAC1B,aAAKG,QAAQQ,IAAIjB,SAASI,UAAU;MACtC;IACF;EACF;EAEOc,8BAA8B;AACnC,UAAMC,OAAgC,CAAA;AACtC,SAAKV,QAAQW,QAAQ,CAAChB,eAAAA;AACpB,YAAMJ,WAAW,KAAKQ,UAAUO,IAAIX,UAAAA;AACpC,UAAIJ,UAAU;AACZmB,aAAKE,KAAKrB,QAAAA;MACZ;IACF,CAAA;AACA,SAAKS,QAAQa,MAAK;AAClB,WAAOH;EACT;AACF;AAxCqBZ;AAArB,IAAqBA,mBAArB;","names":["consumerFromStringOrObject","consumer","String","trim","substring","identifier","name","group","ConsumerRegistry","consumers","updated","constructor","Map","Set","addOrUpdateConsumer","existing","get","set","add","getAndResetUpdatedConsumers","data","forEach","push","clear"]}
@@ -0,0 +1,14 @@
1
+ import { ApitallyConsumer } from './types.cjs';
2
+ import './logging.cjs';
3
+ import 'winston';
4
+
5
+ declare const consumerFromStringOrObject: (consumer: ApitallyConsumer | string) => ApitallyConsumer | null;
6
+ declare class ConsumerRegistry {
7
+ private consumers;
8
+ private updated;
9
+ constructor();
10
+ addOrUpdateConsumer(consumer?: ApitallyConsumer | null): void;
11
+ getAndResetUpdatedConsumers(): ApitallyConsumer[];
12
+ }
13
+
14
+ export { consumerFromStringOrObject, ConsumerRegistry as default };
@@ -0,0 +1,14 @@
1
+ import { ApitallyConsumer } from './types.js';
2
+ import './logging.js';
3
+ import 'winston';
4
+
5
+ declare const consumerFromStringOrObject: (consumer: ApitallyConsumer | string) => ApitallyConsumer | null;
6
+ declare class ConsumerRegistry {
7
+ private consumers;
8
+ private updated;
9
+ constructor();
10
+ addOrUpdateConsumer(consumer?: ApitallyConsumer | null): void;
11
+ getAndResetUpdatedConsumers(): ApitallyConsumer[];
12
+ }
13
+
14
+ export { consumerFromStringOrObject, ConsumerRegistry as default };
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common/consumerRegistry.ts
5
+ var consumerFromStringOrObject = /* @__PURE__ */ __name((consumer) => {
6
+ var _a, _b;
7
+ if (typeof consumer === "string") {
8
+ consumer = String(consumer).trim().substring(0, 128);
9
+ return consumer ? {
10
+ identifier: consumer
11
+ } : null;
12
+ } else {
13
+ consumer.identifier = String(consumer.identifier).trim().substring(0, 128);
14
+ consumer.name = (_a = consumer.name) == null ? void 0 : _a.trim().substring(0, 64);
15
+ consumer.group = (_b = consumer.group) == null ? void 0 : _b.trim().substring(0, 64);
16
+ return consumer.identifier ? consumer : null;
17
+ }
18
+ }, "consumerFromStringOrObject");
19
+ var _ConsumerRegistry = class _ConsumerRegistry {
20
+ consumers;
21
+ updated;
22
+ constructor() {
23
+ this.consumers = /* @__PURE__ */ new Map();
24
+ this.updated = /* @__PURE__ */ new Set();
25
+ }
26
+ addOrUpdateConsumer(consumer) {
27
+ if (!consumer || !consumer.name && !consumer.group) {
28
+ return;
29
+ }
30
+ const existing = this.consumers.get(consumer.identifier);
31
+ if (!existing) {
32
+ this.consumers.set(consumer.identifier, consumer);
33
+ this.updated.add(consumer.identifier);
34
+ } else {
35
+ if (consumer.name && consumer.name !== existing.name) {
36
+ existing.name = consumer.name;
37
+ this.updated.add(consumer.identifier);
38
+ }
39
+ if (consumer.group && consumer.group !== existing.group) {
40
+ existing.group = consumer.group;
41
+ this.updated.add(consumer.identifier);
42
+ }
43
+ }
44
+ }
45
+ getAndResetUpdatedConsumers() {
46
+ const data = [];
47
+ this.updated.forEach((identifier) => {
48
+ const consumer = this.consumers.get(identifier);
49
+ if (consumer) {
50
+ data.push(consumer);
51
+ }
52
+ });
53
+ this.updated.clear();
54
+ return data;
55
+ }
56
+ };
57
+ __name(_ConsumerRegistry, "ConsumerRegistry");
58
+ var ConsumerRegistry = _ConsumerRegistry;
59
+ export {
60
+ consumerFromStringOrObject,
61
+ ConsumerRegistry as default
62
+ };
63
+ //# sourceMappingURL=consumerRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/consumerRegistry.ts"],"sourcesContent":["import { ApitallyConsumer } from \"./types.js\";\n\nexport const consumerFromStringOrObject = (\n consumer: ApitallyConsumer | string,\n) => {\n if (typeof consumer === \"string\") {\n consumer = String(consumer).trim().substring(0, 128);\n return consumer ? { identifier: consumer } : null;\n } else {\n consumer.identifier = String(consumer.identifier).trim().substring(0, 128);\n consumer.name = consumer.name?.trim().substring(0, 64);\n consumer.group = consumer.group?.trim().substring(0, 64);\n return consumer.identifier ? consumer : null;\n }\n};\n\nexport default class ConsumerRegistry {\n private consumers: Map<string, ApitallyConsumer>;\n private updated: Set<string>;\n\n constructor() {\n this.consumers = new Map();\n this.updated = new Set();\n }\n\n public addOrUpdateConsumer(consumer?: ApitallyConsumer | null) {\n if (!consumer || (!consumer.name && !consumer.group)) {\n return;\n }\n const existing = this.consumers.get(consumer.identifier);\n if (!existing) {\n this.consumers.set(consumer.identifier, consumer);\n this.updated.add(consumer.identifier);\n } else {\n if (consumer.name && consumer.name !== existing.name) {\n existing.name = consumer.name;\n this.updated.add(consumer.identifier);\n }\n if (consumer.group && consumer.group !== existing.group) {\n existing.group = consumer.group;\n this.updated.add(consumer.identifier);\n }\n }\n }\n\n public getAndResetUpdatedConsumers() {\n const data: Array<ApitallyConsumer> = [];\n this.updated.forEach((identifier) => {\n const consumer = this.consumers.get(identifier);\n if (consumer) {\n data.push(consumer);\n }\n });\n this.updated.clear();\n return data;\n }\n}\n"],"mappings":";;;;AAEO,IAAMA,6BAA6B,wBACxCC,aAAAA;AADF;AAGE,MAAI,OAAOA,aAAa,UAAU;AAChCA,eAAWC,OAAOD,QAAAA,EAAUE,KAAI,EAAGC,UAAU,GAAG,GAAA;AAChD,WAAOH,WAAW;MAAEI,YAAYJ;IAAS,IAAI;EAC/C,OAAO;AACLA,aAASI,aAAaH,OAAOD,SAASI,UAAU,EAAEF,KAAI,EAAGC,UAAU,GAAG,GAAA;AACtEH,aAASK,QAAOL,cAASK,SAATL,mBAAeE,OAAOC,UAAU,GAAG;AACnDH,aAASM,SAAQN,cAASM,UAATN,mBAAgBE,OAAOC,UAAU,GAAG;AACrD,WAAOH,SAASI,aAAaJ,WAAW;EAC1C;AACF,GAZ0C;AAc1C,IAAqBO,oBAArB,MAAqBA,kBAAAA;EACXC;EACAC;EAERC,cAAc;AACZ,SAAKF,YAAY,oBAAIG,IAAAA;AACrB,SAAKF,UAAU,oBAAIG,IAAAA;EACrB;EAEOC,oBAAoBb,UAAoC;AAC7D,QAAI,CAACA,YAAa,CAACA,SAASK,QAAQ,CAACL,SAASM,OAAQ;AACpD;IACF;AACA,UAAMQ,WAAW,KAAKN,UAAUO,IAAIf,SAASI,UAAU;AACvD,QAAI,CAACU,UAAU;AACb,WAAKN,UAAUQ,IAAIhB,SAASI,YAAYJ,QAAAA;AACxC,WAAKS,QAAQQ,IAAIjB,SAASI,UAAU;IACtC,OAAO;AACL,UAAIJ,SAASK,QAAQL,SAASK,SAASS,SAAST,MAAM;AACpDS,iBAAST,OAAOL,SAASK;AACzB,aAAKI,QAAQQ,IAAIjB,SAASI,UAAU;MACtC;AACA,UAAIJ,SAASM,SAASN,SAASM,UAAUQ,SAASR,OAAO;AACvDQ,iBAASR,QAAQN,SAASM;AAC1B,aAAKG,QAAQQ,IAAIjB,SAASI,UAAU;MACtC;IACF;EACF;EAEOc,8BAA8B;AACnC,UAAMC,OAAgC,CAAA;AACtC,SAAKV,QAAQW,QAAQ,CAAChB,eAAAA;AACpB,YAAMJ,WAAW,KAAKQ,UAAUO,IAAIX,UAAAA;AACpC,UAAIJ,UAAU;AACZmB,aAAKE,KAAKrB,QAAAA;MACZ;IACF,CAAA;AACA,SAAKS,QAAQa,MAAK;AAClB,WAAOH;EACT;AACF;AAxCqBZ;AAArB,IAAqBA,mBAArB;","names":["consumerFromStringOrObject","consumer","String","trim","substring","identifier","name","group","ConsumerRegistry","consumers","updated","constructor","Map","Set","addOrUpdateConsumer","existing","get","set","add","getAndResetUpdatedConsumers","data","forEach","push","clear"]}
@@ -0,0 +1,41 @@
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/logging.ts
22
+ var logging_exports = {};
23
+ __export(logging_exports, {
24
+ getLogger: () => getLogger
25
+ });
26
+ module.exports = __toCommonJS(logging_exports);
27
+ var import_winston = require("winston");
28
+ var getLogger = /* @__PURE__ */ __name(() => {
29
+ return (0, import_winston.createLogger)({
30
+ level: process.env.APITALLY_DEBUG ? "debug" : "warn",
31
+ format: import_winston.format.combine(import_winston.format.colorize(), import_winston.format.timestamp(), import_winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)),
32
+ transports: [
33
+ new import_winston.transports.Console()
34
+ ]
35
+ });
36
+ }, "getLogger");
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ getLogger
40
+ });
41
+ //# sourceMappingURL=logging.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/logging.ts"],"sourcesContent":["import { createLogger, format, transports } from \"winston\";\n\nexport interface Logger {\n debug: (message: string, meta?: object) => void;\n info: (message: string, meta?: object) => void;\n warn: (message: string, meta?: object) => void;\n error: (message: string, meta?: object) => void;\n}\n\nexport const getLogger = () => {\n return createLogger({\n level: process.env.APITALLY_DEBUG ? \"debug\" : \"warn\",\n format: format.combine(\n format.colorize(),\n format.timestamp(),\n format.printf(\n (info) => `${info.timestamp} ${info.level}: ${info.message}`,\n ),\n ),\n transports: [new transports.Console()],\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;qBAAiD;AAS1C,IAAMA,YAAY,6BAAA;AACvB,aAAOC,6BAAa;IAClBC,OAAOC,QAAQC,IAAIC,iBAAiB,UAAU;IAC9CC,QAAQA,sBAAOC,QACbD,sBAAOE,SAAQ,GACfF,sBAAOG,UAAS,GAChBH,sBAAOI,OACL,CAACC,SAAS,GAAGA,KAAKF,SAAS,IAAIE,KAAKT,KAAK,KAAKS,KAAKC,OAAO,EAAE,CAAA;IAGhEC,YAAY;MAAC,IAAIA,0BAAWC,QAAO;;EACrC,CAAA;AACF,GAZyB;","names":["getLogger","createLogger","level","process","env","APITALLY_DEBUG","format","combine","colorize","timestamp","printf","info","message","transports","Console"]}
@@ -0,0 +1,11 @@
1
+ import * as winston from 'winston';
2
+
3
+ interface Logger {
4
+ debug: (message: string, meta?: object) => void;
5
+ info: (message: string, meta?: object) => void;
6
+ warn: (message: string, meta?: object) => void;
7
+ error: (message: string, meta?: object) => void;
8
+ }
9
+ declare const getLogger: () => winston.Logger;
10
+
11
+ export { type Logger, getLogger };
@@ -1,8 +1,11 @@
1
- export interface Logger {
1
+ import * as winston from 'winston';
2
+
3
+ interface Logger {
2
4
  debug: (message: string, meta?: object) => void;
3
5
  info: (message: string, meta?: object) => void;
4
6
  warn: (message: string, meta?: object) => void;
5
7
  error: (message: string, meta?: object) => void;
6
8
  }
7
- export declare const getLogger: () => import("winston").Logger;
8
- //# sourceMappingURL=logging.d.ts.map
9
+ declare const getLogger: () => winston.Logger;
10
+
11
+ export { type Logger, getLogger };
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common/logging.ts
5
+ import { createLogger, format, transports } from "winston";
6
+ var getLogger = /* @__PURE__ */ __name(() => {
7
+ return createLogger({
8
+ level: process.env.APITALLY_DEBUG ? "debug" : "warn",
9
+ format: format.combine(format.colorize(), format.timestamp(), format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)),
10
+ transports: [
11
+ new transports.Console()
12
+ ]
13
+ });
14
+ }, "getLogger");
15
+ export {
16
+ getLogger
17
+ };
18
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/logging.ts"],"sourcesContent":["import { createLogger, format, transports } from \"winston\";\n\nexport interface Logger {\n debug: (message: string, meta?: object) => void;\n info: (message: string, meta?: object) => void;\n warn: (message: string, meta?: object) => void;\n error: (message: string, meta?: object) => void;\n}\n\nexport const getLogger = () => {\n return createLogger({\n level: process.env.APITALLY_DEBUG ? \"debug\" : \"warn\",\n format: format.combine(\n format.colorize(),\n format.timestamp(),\n format.printf(\n (info) => `${info.timestamp} ${info.level}: ${info.message}`,\n ),\n ),\n transports: [new transports.Console()],\n });\n};\n"],"mappings":";;;;AAAA,SAASA,cAAcC,QAAQC,kBAAkB;AAS1C,IAAMC,YAAY,6BAAA;AACvB,SAAOC,aAAa;IAClBC,OAAOC,QAAQC,IAAIC,iBAAiB,UAAU;IAC9CC,QAAQA,OAAOC,QACbD,OAAOE,SAAQ,GACfF,OAAOG,UAAS,GAChBH,OAAOI,OACL,CAACC,SAAS,GAAGA,KAAKF,SAAS,IAAIE,KAAKT,KAAK,KAAKS,KAAKC,OAAO,EAAE,CAAA;IAGhEC,YAAY;MAAC,IAAIA,WAAWC,QAAO;;EACrC,CAAA;AACF,GAZyB;","names":["createLogger","format","transports","getLogger","createLogger","level","process","env","APITALLY_DEBUG","format","combine","colorize","timestamp","printf","info","message","transports","Console"]}
@@ -0,0 +1,42 @@
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/packageVersions.ts
22
+ var packageVersions_exports = {};
23
+ __export(packageVersions_exports, {
24
+ getPackageVersion: () => getPackageVersion
25
+ });
26
+ module.exports = __toCommonJS(packageVersions_exports);
27
+ var import_module = require("module");
28
+ var import_meta = {};
29
+ function getPackageVersion(name) {
30
+ try {
31
+ const _require = (0, import_module.createRequire)(import_meta.url);
32
+ return _require(`${name}/package.json`).version || null;
33
+ } catch (error) {
34
+ return null;
35
+ }
36
+ }
37
+ __name(getPackageVersion, "getPackageVersion");
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ getPackageVersion
41
+ });
42
+ //# sourceMappingURL=packageVersions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/packageVersions.ts"],"sourcesContent":["import { createRequire } from \"module\";\n\nexport function getPackageVersion(name: string): string | null {\n try {\n const _require = createRequire(import.meta.url);\n return _require(`${name}/package.json`).version || null;\n } catch (error) {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;oBAA8B;AAA9B;AAEO,SAASA,kBAAkBC,MAAY;AAC5C,MAAI;AACF,UAAMC,eAAWC,6BAAc,YAAYC,GAAG;AAC9C,WAAOF,SAAS,GAAGD,IAAAA,eAAmB,EAAEI,WAAW;EACrD,SAASC,OAAO;AACd,WAAO;EACT;AACF;AAPgBN;","names":["getPackageVersion","name","_require","createRequire","url","version","error"]}
@@ -0,0 +1,3 @@
1
+ declare function getPackageVersion(name: string): string | null;
2
+
3
+ export { getPackageVersion };
@@ -0,0 +1,3 @@
1
+ declare function getPackageVersion(name: string): string | null;
2
+
3
+ export { getPackageVersion };
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common/packageVersions.ts
5
+ import { createRequire } from "module";
6
+ function getPackageVersion(name) {
7
+ try {
8
+ const _require = createRequire(import.meta.url);
9
+ return _require(`${name}/package.json`).version || null;
10
+ } catch (error) {
11
+ return null;
12
+ }
13
+ }
14
+ __name(getPackageVersion, "getPackageVersion");
15
+ export {
16
+ getPackageVersion
17
+ };
18
+ //# sourceMappingURL=packageVersions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/packageVersions.ts"],"sourcesContent":["import { createRequire } from \"module\";\n\nexport function getPackageVersion(name: string): string | null {\n try {\n const _require = createRequire(import.meta.url);\n return _require(`${name}/package.json`).version || null;\n } catch (error) {\n return null;\n }\n}\n"],"mappings":";;;;AAAA,SAASA,qBAAqB;AAEvB,SAASC,kBAAkBC,MAAY;AAC5C,MAAI;AACF,UAAMC,WAAWC,cAAc,YAAYC,GAAG;AAC9C,WAAOF,SAAS,GAAGD,IAAAA,eAAmB,EAAEI,WAAW;EACrD,SAASC,OAAO;AACd,WAAO;EACT;AACF;AAPgBN;","names":["createRequire","getPackageVersion","name","_require","createRequire","url","version","error"]}
@@ -0,0 +1,43 @@
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/paramValidation.ts
22
+ var paramValidation_exports = {};
23
+ __export(paramValidation_exports, {
24
+ isValidClientId: () => isValidClientId,
25
+ isValidEnv: () => isValidEnv
26
+ });
27
+ module.exports = __toCommonJS(paramValidation_exports);
28
+ function isValidClientId(clientId) {
29
+ const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
30
+ return regexExp.test(clientId);
31
+ }
32
+ __name(isValidClientId, "isValidClientId");
33
+ function isValidEnv(env) {
34
+ const regexExp = /^[\w-]{1,32}$/;
35
+ return regexExp.test(env);
36
+ }
37
+ __name(isValidEnv, "isValidEnv");
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ isValidClientId,
41
+ isValidEnv
42
+ });
43
+ //# sourceMappingURL=paramValidation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/paramValidation.ts"],"sourcesContent":["export function isValidClientId(clientId: string): boolean {\n const regexExp =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n return regexExp.test(clientId);\n}\n\nexport function isValidEnv(env: string): boolean {\n const regexExp = /^[\\w-]{1,32}$/;\n return regexExp.test(env);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAO,SAASA,gBAAgBC,UAAgB;AAC9C,QAAMC,WACJ;AACF,SAAOA,SAASC,KAAKF,QAAAA;AACvB;AAJgBD;AAMT,SAASI,WAAWC,KAAW;AACpC,QAAMH,WAAW;AACjB,SAAOA,SAASC,KAAKE,GAAAA;AACvB;AAHgBD;","names":["isValidClientId","clientId","regexExp","test","isValidEnv","env"]}
@@ -0,0 +1,4 @@
1
+ declare function isValidClientId(clientId: string): boolean;
2
+ declare function isValidEnv(env: string): boolean;
3
+
4
+ export { isValidClientId, isValidEnv };
@@ -0,0 +1,4 @@
1
+ declare function isValidClientId(clientId: string): boolean;
2
+ declare function isValidEnv(env: string): boolean;
3
+
4
+ export { isValidClientId, isValidEnv };
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/common/paramValidation.ts
5
+ function isValidClientId(clientId) {
6
+ const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
7
+ return regexExp.test(clientId);
8
+ }
9
+ __name(isValidClientId, "isValidClientId");
10
+ function isValidEnv(env) {
11
+ const regexExp = /^[\w-]{1,32}$/;
12
+ return regexExp.test(env);
13
+ }
14
+ __name(isValidEnv, "isValidEnv");
15
+ export {
16
+ isValidClientId,
17
+ isValidEnv
18
+ };
19
+ //# sourceMappingURL=paramValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/paramValidation.ts"],"sourcesContent":["export function isValidClientId(clientId: string): boolean {\n const regexExp =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n return regexExp.test(clientId);\n}\n\nexport function isValidEnv(env: string): boolean {\n const regexExp = /^[\\w-]{1,32}$/;\n return regexExp.test(env);\n}\n"],"mappings":";;;;AAAO,SAASA,gBAAgBC,UAAgB;AAC9C,QAAMC,WACJ;AACF,SAAOA,SAASC,KAAKF,QAAAA;AACvB;AAJgBD;AAMT,SAASI,WAAWC,KAAW;AACpC,QAAMH,WAAW;AACjB,SAAOA,SAASC,KAAKE,GAAAA;AACvB;AAHgBD;","names":["isValidClientId","clientId","regexExp","test","isValidEnv","env"]}
@@ -0,0 +1,111 @@
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/requestCounter.ts
22
+ var requestCounter_exports = {};
23
+ __export(requestCounter_exports, {
24
+ default: () => RequestCounter
25
+ });
26
+ module.exports = __toCommonJS(requestCounter_exports);
27
+ var _RequestCounter = class _RequestCounter {
28
+ requestCounts;
29
+ requestSizeSums;
30
+ responseSizeSums;
31
+ responseTimes;
32
+ requestSizes;
33
+ responseSizes;
34
+ constructor() {
35
+ this.requestCounts = /* @__PURE__ */ new Map();
36
+ this.requestSizeSums = /* @__PURE__ */ new Map();
37
+ this.responseSizeSums = /* @__PURE__ */ new Map();
38
+ this.responseTimes = /* @__PURE__ */ new Map();
39
+ this.requestSizes = /* @__PURE__ */ new Map();
40
+ this.responseSizes = /* @__PURE__ */ new Map();
41
+ }
42
+ getKey(requestInfo) {
43
+ return [
44
+ requestInfo.consumer || "",
45
+ requestInfo.method.toUpperCase(),
46
+ requestInfo.path,
47
+ requestInfo.statusCode
48
+ ].join("|");
49
+ }
50
+ addRequest(requestInfo) {
51
+ const key = this.getKey(requestInfo);
52
+ this.requestCounts.set(key, (this.requestCounts.get(key) || 0) + 1);
53
+ if (!this.responseTimes.has(key)) {
54
+ this.responseTimes.set(key, /* @__PURE__ */ new Map());
55
+ }
56
+ const responseTimeMap = this.responseTimes.get(key);
57
+ const responseTimeMsBin = Math.floor(requestInfo.responseTime / 10) * 10;
58
+ responseTimeMap.set(responseTimeMsBin, (responseTimeMap.get(responseTimeMsBin) || 0) + 1);
59
+ if (requestInfo.requestSize !== void 0) {
60
+ requestInfo.requestSize = Number(requestInfo.requestSize);
61
+ this.requestSizeSums.set(key, (this.requestSizeSums.get(key) || 0) + requestInfo.requestSize);
62
+ if (!this.requestSizes.has(key)) {
63
+ this.requestSizes.set(key, /* @__PURE__ */ new Map());
64
+ }
65
+ const requestSizeMap = this.requestSizes.get(key);
66
+ const requestSizeKbBin = Math.floor(requestInfo.requestSize / 1e3);
67
+ requestSizeMap.set(requestSizeKbBin, (requestSizeMap.get(requestSizeKbBin) || 0) + 1);
68
+ }
69
+ if (requestInfo.responseSize !== void 0) {
70
+ requestInfo.responseSize = Number(requestInfo.responseSize);
71
+ this.responseSizeSums.set(key, (this.responseSizeSums.get(key) || 0) + requestInfo.responseSize);
72
+ if (!this.responseSizes.has(key)) {
73
+ this.responseSizes.set(key, /* @__PURE__ */ new Map());
74
+ }
75
+ const responseSizeMap = this.responseSizes.get(key);
76
+ const responseSizeKbBin = Math.floor(requestInfo.responseSize / 1e3);
77
+ responseSizeMap.set(responseSizeKbBin, (responseSizeMap.get(responseSizeKbBin) || 0) + 1);
78
+ }
79
+ }
80
+ getAndResetRequests() {
81
+ const data = [];
82
+ this.requestCounts.forEach((count, key) => {
83
+ const [consumer, method, path, statusCodeStr] = key.split("|");
84
+ const responseTimes = this.responseTimes.get(key) || /* @__PURE__ */ new Map();
85
+ const requestSizes = this.requestSizes.get(key) || /* @__PURE__ */ new Map();
86
+ const responseSizes = this.responseSizes.get(key) || /* @__PURE__ */ new Map();
87
+ data.push({
88
+ consumer: consumer || null,
89
+ method,
90
+ path,
91
+ status_code: parseInt(statusCodeStr),
92
+ request_count: count,
93
+ request_size_sum: this.requestSizeSums.get(key) || 0,
94
+ response_size_sum: this.responseSizeSums.get(key) || 0,
95
+ response_times: Object.fromEntries(responseTimes),
96
+ request_sizes: Object.fromEntries(requestSizes),
97
+ response_sizes: Object.fromEntries(responseSizes)
98
+ });
99
+ });
100
+ this.requestCounts.clear();
101
+ this.requestSizeSums.clear();
102
+ this.responseSizeSums.clear();
103
+ this.responseTimes.clear();
104
+ this.requestSizes.clear();
105
+ this.responseSizes.clear();
106
+ return data;
107
+ }
108
+ };
109
+ __name(_RequestCounter, "RequestCounter");
110
+ var RequestCounter = _RequestCounter;
111
+ //# sourceMappingURL=requestCounter.cjs.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":"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","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,18 @@
1
+ import { RequestInfo, RequestsItem } from './types.cjs';
2
+ import './logging.cjs';
3
+ import 'winston';
4
+
5
+ declare class RequestCounter {
6
+ private requestCounts;
7
+ private requestSizeSums;
8
+ private responseSizeSums;
9
+ private responseTimes;
10
+ private requestSizes;
11
+ private responseSizes;
12
+ constructor();
13
+ private getKey;
14
+ addRequest(requestInfo: RequestInfo): void;
15
+ getAndResetRequests(): RequestsItem[];
16
+ }
17
+
18
+ export { RequestCounter as default };
@@ -1,5 +1,8 @@
1
- import { RequestInfo, RequestsItem } from "./types.js";
2
- export default class RequestCounter {
1
+ import { RequestInfo, RequestsItem } from './types.js';
2
+ import './logging.js';
3
+ import 'winston';
4
+
5
+ declare class RequestCounter {
3
6
  private requestCounts;
4
7
  private requestSizeSums;
5
8
  private responseSizeSums;
@@ -11,4 +14,5 @@ export default class RequestCounter {
11
14
  addRequest(requestInfo: RequestInfo): void;
12
15
  getAndResetRequests(): RequestsItem[];
13
16
  }
14
- //# sourceMappingURL=requestCounter.d.ts.map
17
+
18
+ export { RequestCounter as default };