@djangocfg/monitor 2.1.217 → 2.1.219

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.cjs CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,6 +30,235 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
34
+ var require_retry_operation = __commonJS({
35
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module2) {
36
+ function RetryOperation(timeouts, options) {
37
+ if (typeof options === "boolean") {
38
+ options = { forever: options };
39
+ }
40
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
41
+ this._timeouts = timeouts;
42
+ this._options = options || {};
43
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
44
+ this._fn = null;
45
+ this._errors = [];
46
+ this._attempts = 1;
47
+ this._operationTimeout = null;
48
+ this._operationTimeoutCb = null;
49
+ this._timeout = null;
50
+ this._operationStart = null;
51
+ this._timer = null;
52
+ if (this._options.forever) {
53
+ this._cachedTimeouts = this._timeouts.slice(0);
54
+ }
55
+ }
56
+ __name(RetryOperation, "RetryOperation");
57
+ module2.exports = RetryOperation;
58
+ RetryOperation.prototype.reset = function() {
59
+ this._attempts = 1;
60
+ this._timeouts = this._originalTimeouts.slice(0);
61
+ };
62
+ RetryOperation.prototype.stop = function() {
63
+ if (this._timeout) {
64
+ clearTimeout(this._timeout);
65
+ }
66
+ if (this._timer) {
67
+ clearTimeout(this._timer);
68
+ }
69
+ this._timeouts = [];
70
+ this._cachedTimeouts = null;
71
+ };
72
+ RetryOperation.prototype.retry = function(err) {
73
+ if (this._timeout) {
74
+ clearTimeout(this._timeout);
75
+ }
76
+ if (!err) {
77
+ return false;
78
+ }
79
+ var currentTime = (/* @__PURE__ */ new Date()).getTime();
80
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
81
+ this._errors.push(err);
82
+ this._errors.unshift(new Error("RetryOperation timeout occurred"));
83
+ return false;
84
+ }
85
+ this._errors.push(err);
86
+ var timeout = this._timeouts.shift();
87
+ if (timeout === void 0) {
88
+ if (this._cachedTimeouts) {
89
+ this._errors.splice(0, this._errors.length - 1);
90
+ timeout = this._cachedTimeouts.slice(-1);
91
+ } else {
92
+ return false;
93
+ }
94
+ }
95
+ var self = this;
96
+ this._timer = setTimeout(function() {
97
+ self._attempts++;
98
+ if (self._operationTimeoutCb) {
99
+ self._timeout = setTimeout(function() {
100
+ self._operationTimeoutCb(self._attempts);
101
+ }, self._operationTimeout);
102
+ if (self._options.unref) {
103
+ self._timeout.unref();
104
+ }
105
+ }
106
+ self._fn(self._attempts);
107
+ }, timeout);
108
+ if (this._options.unref) {
109
+ this._timer.unref();
110
+ }
111
+ return true;
112
+ };
113
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
114
+ this._fn = fn;
115
+ if (timeoutOps) {
116
+ if (timeoutOps.timeout) {
117
+ this._operationTimeout = timeoutOps.timeout;
118
+ }
119
+ if (timeoutOps.cb) {
120
+ this._operationTimeoutCb = timeoutOps.cb;
121
+ }
122
+ }
123
+ var self = this;
124
+ if (this._operationTimeoutCb) {
125
+ this._timeout = setTimeout(function() {
126
+ self._operationTimeoutCb();
127
+ }, self._operationTimeout);
128
+ }
129
+ this._operationStart = (/* @__PURE__ */ new Date()).getTime();
130
+ this._fn(this._attempts);
131
+ };
132
+ RetryOperation.prototype.try = function(fn) {
133
+ console.log("Using RetryOperation.try() is deprecated");
134
+ this.attempt(fn);
135
+ };
136
+ RetryOperation.prototype.start = function(fn) {
137
+ console.log("Using RetryOperation.start() is deprecated");
138
+ this.attempt(fn);
139
+ };
140
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
141
+ RetryOperation.prototype.errors = function() {
142
+ return this._errors;
143
+ };
144
+ RetryOperation.prototype.attempts = function() {
145
+ return this._attempts;
146
+ };
147
+ RetryOperation.prototype.mainError = function() {
148
+ if (this._errors.length === 0) {
149
+ return null;
150
+ }
151
+ var counts = {};
152
+ var mainError = null;
153
+ var mainErrorCount = 0;
154
+ for (var i = 0; i < this._errors.length; i++) {
155
+ var error = this._errors[i];
156
+ var message = error.message;
157
+ var count = (counts[message] || 0) + 1;
158
+ counts[message] = count;
159
+ if (count >= mainErrorCount) {
160
+ mainError = error;
161
+ mainErrorCount = count;
162
+ }
163
+ }
164
+ return mainError;
165
+ };
166
+ }
167
+ });
168
+
169
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
170
+ var require_retry = __commonJS({
171
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
172
+ var RetryOperation = require_retry_operation();
173
+ exports.operation = function(options) {
174
+ var timeouts = exports.timeouts(options);
175
+ return new RetryOperation(timeouts, {
176
+ forever: options && (options.forever || options.retries === Infinity),
177
+ unref: options && options.unref,
178
+ maxRetryTime: options && options.maxRetryTime
179
+ });
180
+ };
181
+ exports.timeouts = function(options) {
182
+ if (options instanceof Array) {
183
+ return [].concat(options);
184
+ }
185
+ var opts = {
186
+ retries: 10,
187
+ factor: 2,
188
+ minTimeout: 1 * 1e3,
189
+ maxTimeout: Infinity,
190
+ randomize: false
191
+ };
192
+ for (var key in options) {
193
+ opts[key] = options[key];
194
+ }
195
+ if (opts.minTimeout > opts.maxTimeout) {
196
+ throw new Error("minTimeout is greater than maxTimeout");
197
+ }
198
+ var timeouts = [];
199
+ for (var i = 0; i < opts.retries; i++) {
200
+ timeouts.push(this.createTimeout(i, opts));
201
+ }
202
+ if (options && options.forever && !timeouts.length) {
203
+ timeouts.push(this.createTimeout(i, opts));
204
+ }
205
+ timeouts.sort(function(a, b) {
206
+ return a - b;
207
+ });
208
+ return timeouts;
209
+ };
210
+ exports.createTimeout = function(attempt, opts) {
211
+ var random = opts.randomize ? Math.random() + 1 : 1;
212
+ var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
213
+ timeout = Math.min(timeout, opts.maxTimeout);
214
+ return timeout;
215
+ };
216
+ exports.wrap = function(obj, options, methods) {
217
+ if (options instanceof Array) {
218
+ methods = options;
219
+ options = null;
220
+ }
221
+ if (!methods) {
222
+ methods = [];
223
+ for (var key in obj) {
224
+ if (typeof obj[key] === "function") {
225
+ methods.push(key);
226
+ }
227
+ }
228
+ }
229
+ for (var i = 0; i < methods.length; i++) {
230
+ var method = methods[i];
231
+ var original = obj[method];
232
+ obj[method] = (/* @__PURE__ */ __name(function retryWrapper(original2) {
233
+ var op = exports.operation(options);
234
+ var args = Array.prototype.slice.call(arguments, 1);
235
+ var callback = args.pop();
236
+ args.push(function(err) {
237
+ if (op.retry(err)) {
238
+ return;
239
+ }
240
+ if (err) {
241
+ arguments[0] = op.mainError();
242
+ }
243
+ callback.apply(this, arguments);
244
+ });
245
+ op.attempt(function() {
246
+ original2.apply(obj, args);
247
+ });
248
+ }, "retryWrapper")).bind(obj, original);
249
+ obj[method].options = options;
250
+ }
251
+ };
252
+ }
253
+ });
254
+
255
+ // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
256
+ var require_retry2 = __commonJS({
257
+ "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module2) {
258
+ module2.exports = require_retry();
259
+ }
260
+ });
261
+
30
262
  // src/server/index.ts
31
263
  var server_exports = {};
32
264
  __export(server_exports, {
@@ -349,8 +581,127 @@ __name(_APILogger, "APILogger");
349
581
  var APILogger = _APILogger;
350
582
  var defaultLogger = new APILogger();
351
583
 
584
+ // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
585
+ var import_retry = __toESM(require_retry2(), 1);
586
+
587
+ // ../../node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js
588
+ var objectToString = Object.prototype.toString;
589
+ var isError = /* @__PURE__ */ __name((value) => objectToString.call(value) === "[object Error]", "isError");
590
+ var errorMessages = /* @__PURE__ */ new Set([
591
+ "network error",
592
+ // Chrome
593
+ "Failed to fetch",
594
+ // Chrome
595
+ "NetworkError when attempting to fetch resource.",
596
+ // Firefox
597
+ "The Internet connection appears to be offline.",
598
+ // Safari 16
599
+ "Network request failed",
600
+ // `cross-fetch`
601
+ "fetch failed",
602
+ // Undici (Node.js)
603
+ "terminated",
604
+ // Undici (Node.js)
605
+ " A network error occurred.",
606
+ // Bun (WebKit)
607
+ "Network connection lost"
608
+ // Cloudflare Workers (fetch)
609
+ ]);
610
+ function isNetworkError(error) {
611
+ const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
612
+ if (!isValid) {
613
+ return false;
614
+ }
615
+ const { message, stack } = error;
616
+ if (message === "Load failed") {
617
+ return stack === void 0 || "__sentry_captured__" in error;
618
+ }
619
+ if (message.startsWith("error sending request for url")) {
620
+ return true;
621
+ }
622
+ return errorMessages.has(message);
623
+ }
624
+ __name(isNetworkError, "isNetworkError");
625
+
626
+ // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
627
+ var _AbortError = class _AbortError extends Error {
628
+ constructor(message) {
629
+ super();
630
+ if (message instanceof Error) {
631
+ this.originalError = message;
632
+ ({ message } = message);
633
+ } else {
634
+ this.originalError = new Error(message);
635
+ this.originalError.stack = this.stack;
636
+ }
637
+ this.name = "AbortError";
638
+ this.message = message;
639
+ }
640
+ };
641
+ __name(_AbortError, "AbortError");
642
+ var AbortError = _AbortError;
643
+ var decorateErrorWithCounts = /* @__PURE__ */ __name((error, attemptNumber, options) => {
644
+ const retriesLeft = options.retries - (attemptNumber - 1);
645
+ error.attemptNumber = attemptNumber;
646
+ error.retriesLeft = retriesLeft;
647
+ return error;
648
+ }, "decorateErrorWithCounts");
649
+ async function pRetry(input, options) {
650
+ return new Promise((resolve, reject) => {
651
+ options = { ...options };
652
+ options.onFailedAttempt ?? (options.onFailedAttempt = () => {
653
+ });
654
+ options.shouldRetry ?? (options.shouldRetry = () => true);
655
+ options.retries ?? (options.retries = 10);
656
+ const operation = import_retry.default.operation(options);
657
+ const abortHandler = /* @__PURE__ */ __name(() => {
658
+ operation.stop();
659
+ reject(options.signal?.reason);
660
+ }, "abortHandler");
661
+ if (options.signal && !options.signal.aborted) {
662
+ options.signal.addEventListener("abort", abortHandler, { once: true });
663
+ }
664
+ const cleanUp = /* @__PURE__ */ __name(() => {
665
+ options.signal?.removeEventListener("abort", abortHandler);
666
+ operation.stop();
667
+ }, "cleanUp");
668
+ operation.attempt(async (attemptNumber) => {
669
+ try {
670
+ const result = await input(attemptNumber);
671
+ cleanUp();
672
+ resolve(result);
673
+ } catch (error) {
674
+ try {
675
+ if (!(error instanceof Error)) {
676
+ throw new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
677
+ }
678
+ if (error instanceof AbortError) {
679
+ throw error.originalError;
680
+ }
681
+ if (error instanceof TypeError && !isNetworkError(error)) {
682
+ throw error;
683
+ }
684
+ decorateErrorWithCounts(error, attemptNumber, options);
685
+ if (!await options.shouldRetry(error)) {
686
+ operation.stop();
687
+ reject(error);
688
+ }
689
+ await options.onFailedAttempt(error);
690
+ if (!operation.retry(error)) {
691
+ throw operation.mainError();
692
+ }
693
+ } catch (finalError) {
694
+ decorateErrorWithCounts(finalError, attemptNumber, options);
695
+ cleanUp();
696
+ reject(finalError);
697
+ }
698
+ }
699
+ });
700
+ });
701
+ }
702
+ __name(pRetry, "pRetry");
703
+
352
704
  // src/_api/generated/cfg_monitor/retry.ts
353
- var import_p_retry = __toESM(require("p-retry"), 1);
354
705
  var DEFAULT_RETRY_CONFIG = {
355
706
  retries: 3,
356
707
  factor: 2,
@@ -379,13 +730,13 @@ function shouldRetry(error) {
379
730
  __name(shouldRetry, "shouldRetry");
380
731
  async function withRetry(fn, config) {
381
732
  const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
382
- return (0, import_p_retry.default)(
733
+ return pRetry(
383
734
  async () => {
384
735
  try {
385
736
  return await fn();
386
737
  } catch (error) {
387
738
  if (!shouldRetry(error)) {
388
- throw new import_p_retry.AbortError(error);
739
+ throw new AbortError(error);
389
740
  }
390
741
  throw error;
391
742
  }