@blamejs/core 0.4.1

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 (160) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/LICENSE +201 -0
  3. package/LTS-CALENDAR.md +29 -0
  4. package/MIGRATING.md +7 -0
  5. package/NOTICE +59 -0
  6. package/README.md +100 -0
  7. package/bin/blamejs.js +13 -0
  8. package/index.js +253 -0
  9. package/lib/api-key.js +705 -0
  10. package/lib/api-snapshot.js +335 -0
  11. package/lib/app-shutdown.js +381 -0
  12. package/lib/app.js +364 -0
  13. package/lib/atomic-file.js +525 -0
  14. package/lib/audit-chain.js +168 -0
  15. package/lib/audit-sign.js +319 -0
  16. package/lib/audit-tools.js +682 -0
  17. package/lib/audit.js +753 -0
  18. package/lib/auth/jwt.js +280 -0
  19. package/lib/auth/oauth.js +691 -0
  20. package/lib/auth/passkey.js +185 -0
  21. package/lib/auth/password.js +139 -0
  22. package/lib/auth/totp.js +17 -0
  23. package/lib/auth-header.js +81 -0
  24. package/lib/backup/bundle.js +219 -0
  25. package/lib/backup/crypto.js +174 -0
  26. package/lib/backup/index.js +490 -0
  27. package/lib/backup/manifest.js +275 -0
  28. package/lib/bundler.js +295 -0
  29. package/lib/cache.js +819 -0
  30. package/lib/chain-writer.js +234 -0
  31. package/lib/cli-helpers.js +201 -0
  32. package/lib/cli.js +1377 -0
  33. package/lib/cluster-provider-db.js +245 -0
  34. package/lib/cluster-storage.js +166 -0
  35. package/lib/cluster.js +691 -0
  36. package/lib/consent.js +222 -0
  37. package/lib/constants.js +186 -0
  38. package/lib/cookies.js +293 -0
  39. package/lib/credential-hash.js +303 -0
  40. package/lib/crypto-field.js +159 -0
  41. package/lib/crypto.js +250 -0
  42. package/lib/db-query.js +297 -0
  43. package/lib/db-schema.js +250 -0
  44. package/lib/db.js +1054 -0
  45. package/lib/deprecate.js +226 -0
  46. package/lib/dev.js +324 -0
  47. package/lib/error-page.js +424 -0
  48. package/lib/events.js +135 -0
  49. package/lib/external-db.js +422 -0
  50. package/lib/forms.js +378 -0
  51. package/lib/framework-error.js +189 -0
  52. package/lib/framework-schema.js +604 -0
  53. package/lib/handlers.js +350 -0
  54. package/lib/html-balance.js +227 -0
  55. package/lib/http-client.js +615 -0
  56. package/lib/i18n.js +780 -0
  57. package/lib/jobs.js +181 -0
  58. package/lib/lazy-require.js +48 -0
  59. package/lib/log-stream-local.js +137 -0
  60. package/lib/log-stream-webhook.js +170 -0
  61. package/lib/log-stream.js +211 -0
  62. package/lib/log.js +355 -0
  63. package/lib/mail-bounce.js +507 -0
  64. package/lib/mail.js +701 -0
  65. package/lib/metrics.js +647 -0
  66. package/lib/middleware/api-encrypt.js +553 -0
  67. package/lib/middleware/attach-user.js +156 -0
  68. package/lib/middleware/body-parser.js +883 -0
  69. package/lib/middleware/bot-guard.js +148 -0
  70. package/lib/middleware/compression.js +436 -0
  71. package/lib/middleware/cors.js +236 -0
  72. package/lib/middleware/csp-nonce.js +332 -0
  73. package/lib/middleware/csrf-protect.js +275 -0
  74. package/lib/middleware/error-handler.js +46 -0
  75. package/lib/middleware/health.js +358 -0
  76. package/lib/middleware/index.js +52 -0
  77. package/lib/middleware/rate-limit.js +319 -0
  78. package/lib/middleware/request-id.js +53 -0
  79. package/lib/middleware/require-auth.js +95 -0
  80. package/lib/middleware/security-headers.js +91 -0
  81. package/lib/migrations.js +353 -0
  82. package/lib/mtls-ca.js +333 -0
  83. package/lib/mtls-engine-default.js +285 -0
  84. package/lib/nonce-store.js +177 -0
  85. package/lib/notify.js +643 -0
  86. package/lib/ntp-check.js +178 -0
  87. package/lib/object-store/azure-blob.js +467 -0
  88. package/lib/object-store/gcs.js +469 -0
  89. package/lib/object-store/http-put.js +153 -0
  90. package/lib/object-store/index.js +140 -0
  91. package/lib/object-store/local.js +163 -0
  92. package/lib/object-store/retry.js +15 -0
  93. package/lib/object-store/sigv4.js +535 -0
  94. package/lib/observability.js +114 -0
  95. package/lib/pagination.js +371 -0
  96. package/lib/parsers/index.js +64 -0
  97. package/lib/parsers/safe-csv.js +224 -0
  98. package/lib/parsers/safe-env.js +614 -0
  99. package/lib/parsers/safe-toml.js +745 -0
  100. package/lib/parsers/safe-xml.js +379 -0
  101. package/lib/parsers/safe-yaml.js +977 -0
  102. package/lib/permissions.js +430 -0
  103. package/lib/pqc-agent.js +85 -0
  104. package/lib/pqc-gate.js +266 -0
  105. package/lib/protocol-dispatcher.js +144 -0
  106. package/lib/queue-local.js +327 -0
  107. package/lib/queue.js +430 -0
  108. package/lib/redact.js +192 -0
  109. package/lib/render.js +193 -0
  110. package/lib/request-helpers.js +178 -0
  111. package/lib/restore-bundle.js +239 -0
  112. package/lib/restore-rollback.js +254 -0
  113. package/lib/restore.js +301 -0
  114. package/lib/retry.js +329 -0
  115. package/lib/router.js +437 -0
  116. package/lib/safe-async.js +520 -0
  117. package/lib/safe-buffer.js +162 -0
  118. package/lib/safe-json.js +532 -0
  119. package/lib/safe-schema.js +1176 -0
  120. package/lib/safe-sql.js +157 -0
  121. package/lib/safe-url.js +109 -0
  122. package/lib/scheduler.js +680 -0
  123. package/lib/seeders.js +622 -0
  124. package/lib/session.js +304 -0
  125. package/lib/slug.js +243 -0
  126. package/lib/static.js +268 -0
  127. package/lib/storage.js +470 -0
  128. package/lib/subject.js +281 -0
  129. package/lib/template.js +781 -0
  130. package/lib/testing.js +621 -0
  131. package/lib/totp.js +285 -0
  132. package/lib/tracing.js +484 -0
  133. package/lib/validate-opts.js +56 -0
  134. package/lib/vault/index.js +299 -0
  135. package/lib/vault/passphrase-ops.js +311 -0
  136. package/lib/vault/passphrase-source.js +198 -0
  137. package/lib/vault/rotate.js +761 -0
  138. package/lib/vault/wrap.js +289 -0
  139. package/lib/vendor/MANIFEST.json +84 -0
  140. package/lib/vendor/argon2/argon2.cjs +466 -0
  141. package/lib/vendor/argon2/argon2.d.cts +62 -0
  142. package/lib/vendor/argon2/package.json +1 -0
  143. package/lib/vendor/argon2/prebuilds/darwin-arm64/argon2.armv8.glibc.node +0 -0
  144. package/lib/vendor/argon2/prebuilds/darwin-x64/argon2.glibc.node +0 -0
  145. package/lib/vendor/argon2/prebuilds/freebsd-arm64/argon2.armv8.glibc.node +0 -0
  146. package/lib/vendor/argon2/prebuilds/freebsd-x64/argon2.glibc.node +0 -0
  147. package/lib/vendor/argon2/prebuilds/linux-arm/argon2.armv7.glibc.node +0 -0
  148. package/lib/vendor/argon2/prebuilds/linux-arm/argon2.armv7.musl.node +0 -0
  149. package/lib/vendor/argon2/prebuilds/linux-arm64/argon2.armv8.glibc.node +0 -0
  150. package/lib/vendor/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node +0 -0
  151. package/lib/vendor/argon2/prebuilds/linux-x64/argon2.glibc.node +0 -0
  152. package/lib/vendor/argon2/prebuilds/linux-x64/argon2.musl.node +0 -0
  153. package/lib/vendor/argon2/prebuilds/win32-x64/argon2.glibc.node +0 -0
  154. package/lib/vendor/noble-ciphers.cjs +9 -0
  155. package/lib/vendor/pki.cjs +181 -0
  156. package/lib/vendor/simplewebauthn-server.cjs +328 -0
  157. package/lib/webhook.js +632 -0
  158. package/lib/websocket-channels.js +413 -0
  159. package/lib/websocket.js +833 -0
  160. package/package.json +39 -0
package/lib/retry.js ADDED
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ /**
3
+ * b.retry — exponential-backoff retry + circuit breaker.
4
+ *
5
+ * Two layers of resilience for any operation that may fail transiently:
6
+ *
7
+ * 1. PER-CALL retry (withRetry) — exponential backoff with jitter.
8
+ * Default classifier targets HTTP 408/425/429/5xx and Node net-layer
9
+ * error codes. Caller can override `opts.isRetryable` for non-network
10
+ * semantics (e.g. operator-defined flush() in handlers).
11
+ *
12
+ * 2. PER-TARGET circuit breaker (CircuitBreaker) — N consecutive
13
+ * failures opens the circuit (fast-fail for the cooldown window).
14
+ * After cooldown the breaker enters half-open: probe successes close
15
+ * it, a probe failure reopens it.
16
+ *
17
+ * Both are intentionally side-effect-free in the success path — they
18
+ * compose freely with `safeAsync.withTimeout`, AbortSignals, and any
19
+ * caller-side instrumentation.
20
+ *
21
+ * Validation tiers:
22
+ *
23
+ * - withRetry opts at first call → Tier A (throw)
24
+ * - CircuitBreaker constructor opts → Tier A (throw)
25
+ * - backoffDelay(attempt) attempt argument → Tier A (throw)
26
+ * - isRetryable(err) defensive read → Tier C (return defaults)
27
+ * - onRetry callback throw → Tier B (drop silent)
28
+ * - breaker internal _onSuccess/_onFailure → Tier B (drop silent)
29
+ *
30
+ * HTTP-client auto-retry is intentionally NOT provided here. Callers
31
+ * wrap their own outbound calls in `b.retry.withRetry(...)` to keep
32
+ * timeout/idempotency/body-replay decisions explicit.
33
+ */
34
+
35
+ var C = require("./constants");
36
+ var lazyRequire = require("./lazy-require");
37
+ // safe-async re-exports withRetry + CircuitBreaker from this module, so a
38
+ // direct top-level require would create a cycle. Lazy-require defers the
39
+ // resolution until the first sleep() call, by which point both modules
40
+ // are fully loaded.
41
+ var safeAsync = lazyRequire(function () { return require("./safe-async"); });
42
+ // observability is also lazy-required because the metrics + tracing
43
+ // registry boots after this file loads. event() is Tier B — any
44
+ // throw inside the metrics sink is swallowed by observability itself.
45
+ var observability = lazyRequire(function () { return require("./observability"); });
46
+
47
+ function _emitEvent(name, value, labels) {
48
+ try { observability().event(name, value, labels || {}); }
49
+ catch (_e) { /* Tier B: hot-path observability sink */ }
50
+ }
51
+
52
+ // ---- Defaults ----
53
+
54
+ var DEFAULT_RETRY = Object.freeze({
55
+ maxAttempts: 5, // total attempts incl. the first try
56
+ baseDelayMs: 100, // initial backoff (sub-second; ms literal is clearest)
57
+ maxDelayMs: C.TIME.seconds(10), // cap between attempts
58
+ jitterFactor: 0.5, // 0 = no jitter, 1 = full jitter
59
+ });
60
+
61
+ // Errors that are permanently fatal — do NOT retry.
62
+ var NON_RETRYABLE_HTTP_STATUS = new Set([400, 401, 403, 404, 405, 409, 410, 411, 412, 413, 414, 415, 416, 417, 422, 451, 501, 505]);
63
+
64
+ // Errors that should be retried — transient by nature.
65
+ var RETRYABLE_HTTP_STATUS = new Set([408, 425, 429, 500, 502, 503, 504]);
66
+
67
+ // Network errors from Node's net layer that map to "retry" semantics.
68
+ var RETRYABLE_NET_ERRORS = new Set([
69
+ "ECONNRESET", "ECONNREFUSED", "ECONNABORTED", "ETIMEDOUT",
70
+ "EPIPE", "EAGAIN", "ENOTFOUND", "ENETUNREACH",
71
+ ]);
72
+
73
+ var STATE_CLOSED = "closed"; // normal — calls go through
74
+ var STATE_OPEN = "open"; // failing — calls fail fast
75
+ var STATE_HALF = "half-open"; // probing — one call goes through
76
+
77
+ var DEFAULT_BREAKER = Object.freeze({
78
+ failureThreshold: 10, // consecutive failures to open
79
+ cooldownMs: C.TIME.seconds(30), // time in OPEN before HALF_OPEN probe
80
+ successThreshold: 2, // consecutive HALF probes that close it
81
+ });
82
+
83
+ // ---- Tier-A validation helpers ----
84
+
85
+ function _isPositiveInt(n) {
86
+ return typeof n === "number" && isFinite(n) && n >= 1 && Math.floor(n) === n;
87
+ }
88
+ function _isNonNegFinite(n) {
89
+ return typeof n === "number" && isFinite(n) && n >= 0;
90
+ }
91
+ function _isAbortSignal(s) {
92
+ // Duck-typed: AbortSignal exposes .aborted (bool) and .addEventListener (fn)
93
+ return s != null && typeof s === "object" &&
94
+ typeof s.aborted === "boolean" &&
95
+ typeof s.addEventListener === "function";
96
+ }
97
+
98
+ function _validateRetryOpts(opts) {
99
+ if (!_isPositiveInt(opts.maxAttempts)) {
100
+ throw new TypeError("retry.withRetry: maxAttempts must be a positive integer, got " +
101
+ typeof opts.maxAttempts + " " + JSON.stringify(opts.maxAttempts));
102
+ }
103
+ if (!_isNonNegFinite(opts.baseDelayMs)) {
104
+ throw new TypeError("retry.withRetry: baseDelayMs must be a non-negative finite number, got " +
105
+ typeof opts.baseDelayMs + " " + JSON.stringify(opts.baseDelayMs));
106
+ }
107
+ if (!_isNonNegFinite(opts.maxDelayMs)) {
108
+ throw new TypeError("retry.withRetry: maxDelayMs must be a non-negative finite number, got " +
109
+ typeof opts.maxDelayMs + " " + JSON.stringify(opts.maxDelayMs));
110
+ }
111
+ if (typeof opts.jitterFactor !== "number" || !isFinite(opts.jitterFactor) ||
112
+ opts.jitterFactor < 0 || opts.jitterFactor > 1) {
113
+ throw new TypeError("retry.withRetry: jitterFactor must be a finite number in [0, 1], got " +
114
+ typeof opts.jitterFactor + " " + JSON.stringify(opts.jitterFactor));
115
+ }
116
+ if (opts.isRetryable !== undefined && typeof opts.isRetryable !== "function") {
117
+ throw new TypeError("retry.withRetry: isRetryable must be a function or undefined, got " +
118
+ typeof opts.isRetryable);
119
+ }
120
+ if (opts.onRetry !== undefined && typeof opts.onRetry !== "function") {
121
+ throw new TypeError("retry.withRetry: onRetry must be a function or undefined, got " +
122
+ typeof opts.onRetry);
123
+ }
124
+ if (opts.signal !== undefined && opts.signal !== null && !_isAbortSignal(opts.signal)) {
125
+ throw new TypeError("retry.withRetry: signal must be an AbortSignal or undefined");
126
+ }
127
+ }
128
+
129
+ function _validateBreakerOpts(name, opts) {
130
+ if (typeof name !== "string" || name.length === 0) {
131
+ throw new TypeError("retry.CircuitBreaker: name must be a non-empty string, got " +
132
+ typeof name + " " + JSON.stringify(name));
133
+ }
134
+ if (!_isPositiveInt(opts.failureThreshold)) {
135
+ throw new TypeError("retry.CircuitBreaker: failureThreshold must be a positive integer, got " +
136
+ typeof opts.failureThreshold + " " + JSON.stringify(opts.failureThreshold));
137
+ }
138
+ if (!_isNonNegFinite(opts.cooldownMs)) {
139
+ throw new TypeError("retry.CircuitBreaker: cooldownMs must be a non-negative finite number, got " +
140
+ typeof opts.cooldownMs + " " + JSON.stringify(opts.cooldownMs));
141
+ }
142
+ if (!_isPositiveInt(opts.successThreshold)) {
143
+ throw new TypeError("retry.CircuitBreaker: successThreshold must be a positive integer, got " +
144
+ typeof opts.successThreshold + " " + JSON.stringify(opts.successThreshold));
145
+ }
146
+ }
147
+
148
+ // ---- Public surface ----
149
+
150
+ // Tier C: defensive read of err shape; missing fields → false.
151
+ function isRetryable(err) {
152
+ if (!err) return false;
153
+ if (err.isObjectStoreError && err.permanent) return false;
154
+ if (err.permanent) return false;
155
+ if (typeof err.statusCode === "number") {
156
+ if (RETRYABLE_HTTP_STATUS.has(err.statusCode)) return true;
157
+ if (NON_RETRYABLE_HTTP_STATUS.has(err.statusCode)) return false;
158
+ if (err.statusCode >= 500) return true; // unknown 5xx → assume retryable
159
+ return false;
160
+ }
161
+ if (err.code && RETRYABLE_NET_ERRORS.has(err.code)) return true;
162
+ return false; // default: not retryable (avoid masking bugs)
163
+ }
164
+
165
+ // Tier A: attempt must be a positive int; opts (when supplied) must
166
+ // have non-neg-finite baseDelayMs/maxDelayMs and finite jitterFactor in [0,1].
167
+ // We don't full-validate opts here every call (hot path) — defaults are
168
+ // frozen, so the only way a bad opts reaches here is via withRetry which
169
+ // already validated, OR a caller using backoffDelay directly. For that
170
+ // direct case we still validate the attempt arg loudly.
171
+ function backoffDelay(attempt, opts) {
172
+ if (!_isPositiveInt(attempt)) {
173
+ throw new TypeError("retry.backoffDelay: attempt must be a positive integer, got " +
174
+ typeof attempt + " " + JSON.stringify(attempt));
175
+ }
176
+ opts = opts || DEFAULT_RETRY;
177
+ var base = opts.baseDelayMs * Math.pow(2, attempt - 1);
178
+ var capped = Math.min(base, opts.maxDelayMs);
179
+ var jitter = capped * opts.jitterFactor * Math.random();
180
+ return Math.floor(capped - jitter);
181
+ }
182
+
183
+ async function withRetry(fn, opts) {
184
+ if (typeof fn !== "function") {
185
+ throw new TypeError("retry.withRetry: fn must be a function, got " + typeof fn);
186
+ }
187
+ opts = Object.assign({}, DEFAULT_RETRY, opts || {});
188
+ _validateRetryOpts(opts);
189
+ // opts.isRetryable lets callers override the default classifier.
190
+ // Default classifier targets HTTP/network errors and is intentionally
191
+ // conservative (unknown errors → NOT retryable, to avoid masking bugs).
192
+ // Callers like the handlers primitive whose flush failures are operator-
193
+ // defined (not network-shaped) pass `isRetryable: function () { return true; }`
194
+ // to retry on any error. When overridden, the caller owns full classification
195
+ // including any `err.permanent` semantics they want to honor.
196
+ var classify = (typeof opts.isRetryable === "function") ? opts.isRetryable : isRetryable;
197
+ var lastErr = null;
198
+ for (var attempt = 1; attempt <= opts.maxAttempts; attempt++) {
199
+ try {
200
+ return await fn(attempt);
201
+ } catch (err) {
202
+ lastErr = err;
203
+ var retryable = classify(err);
204
+ if (!retryable || attempt === opts.maxAttempts) {
205
+ if (!retryable) {
206
+ _emitEvent("retry.exhausted", 1, { reason: "non-retryable" });
207
+ } else {
208
+ _emitEvent("retry.exhausted", 1, { reason: "max-attempts", attempts: attempt });
209
+ }
210
+ throw err;
211
+ }
212
+ var delay = backoffDelay(attempt, opts);
213
+ _emitEvent("retry.attempt", 1, { attempt: attempt });
214
+ if (typeof opts.onRetry === "function") {
215
+ // Tier B: hot-path observability sink. A thrown observer must
216
+ // not crash the retry loop — by design.
217
+ try { opts.onRetry({ attempt: attempt, delay: delay, error: err }); } catch (_e) {}
218
+ }
219
+ // Honor opts.signal during the backoff sleep — a caller who aborts
220
+ // mid-retry should be unblocked immediately rather than waiting
221
+ // out the (potentially multi-second) backoff.
222
+ await safeAsync().sleep(delay, { signal: opts.signal });
223
+ }
224
+ }
225
+ throw lastErr;
226
+ }
227
+
228
+ // ---- Circuit breaker ----
229
+
230
+ class CircuitBreaker {
231
+ constructor(name, opts) {
232
+ var merged = Object.assign({}, DEFAULT_BREAKER, opts || {});
233
+ _validateBreakerOpts(name || "", merged);
234
+ this.name = name;
235
+ this.opts = merged;
236
+ this.state = STATE_CLOSED;
237
+ this.consecutiveFailures = 0;
238
+ this.consecutiveSuccesses = 0;
239
+ this.openedAt = 0;
240
+ }
241
+
242
+ // Wrap an async function. The breaker observes outcomes and may fail-fast.
243
+ async wrap(fn) {
244
+ if (typeof fn !== "function") {
245
+ throw new TypeError("retry.CircuitBreaker.wrap: fn must be a function, got " + typeof fn);
246
+ }
247
+ if (this.state === STATE_OPEN) {
248
+ if (Date.now() - this.openedAt >= this.opts.cooldownMs) {
249
+ this._transition(STATE_OPEN, STATE_HALF);
250
+ } else {
251
+ var err = new Error("circuit breaker '" + this.name + "' is OPEN");
252
+ err.code = "CIRCUIT_OPEN";
253
+ err.permanent = false; // still transient
254
+ err.isObjectStoreError = true;
255
+ throw err;
256
+ }
257
+ }
258
+ try {
259
+ var result = await fn();
260
+ this._onSuccess();
261
+ return result;
262
+ } catch (e) {
263
+ this._onFailure(e);
264
+ throw e;
265
+ }
266
+ }
267
+
268
+ // Centralizes state changes so we emit one observability event per
269
+ // transition. Same name + label shape regardless of which method
270
+ // initiated the change.
271
+ _transition(from, to) {
272
+ if (from === to) return;
273
+ this.state = to;
274
+ _emitEvent("breaker.state.change", 1, { name: this.name, from: from, to: to });
275
+ }
276
+
277
+ _onSuccess() {
278
+ if (this.state === STATE_HALF) {
279
+ this.consecutiveSuccesses += 1;
280
+ if (this.consecutiveSuccesses >= this.opts.successThreshold) {
281
+ this._transition(STATE_HALF, STATE_CLOSED);
282
+ this.consecutiveFailures = 0;
283
+ this.consecutiveSuccesses = 0;
284
+ }
285
+ } else {
286
+ this.consecutiveFailures = 0;
287
+ }
288
+ }
289
+
290
+ _onFailure(err) {
291
+ // Don't trip the breaker on permanent errors — those are caller bugs,
292
+ // not backend health issues.
293
+ if (err && err.permanent) return;
294
+ if (err && err.isObjectStoreError && err.code === "CIRCUIT_OPEN") return;
295
+
296
+ this.consecutiveFailures += 1;
297
+ this.consecutiveSuccesses = 0;
298
+ if (this.state === STATE_HALF) {
299
+ this._transition(STATE_HALF, STATE_OPEN);
300
+ this.openedAt = Date.now();
301
+ } else if (this.state === STATE_CLOSED && this.consecutiveFailures >= this.opts.failureThreshold) {
302
+ this._transition(STATE_CLOSED, STATE_OPEN);
303
+ this.openedAt = Date.now();
304
+ }
305
+ }
306
+
307
+ getState() { return this.state; }
308
+
309
+ reset() {
310
+ var prior = this.state;
311
+ if (prior !== STATE_CLOSED) this._transition(prior, STATE_CLOSED);
312
+ this.consecutiveFailures = 0;
313
+ this.consecutiveSuccesses = 0;
314
+ this.openedAt = 0;
315
+ }
316
+ }
317
+
318
+ module.exports = {
319
+ withRetry: withRetry,
320
+ isRetryable: isRetryable,
321
+ backoffDelay: backoffDelay,
322
+ CircuitBreaker: CircuitBreaker,
323
+ DEFAULT_RETRY: DEFAULT_RETRY,
324
+ DEFAULT_BREAKER: DEFAULT_BREAKER,
325
+ RETRYABLE_HTTP_STATUS: Array.from(RETRYABLE_HTTP_STATUS),
326
+ NON_RETRYABLE_HTTP_STATUS: Array.from(NON_RETRYABLE_HTTP_STATUS),
327
+ RETRYABLE_NET_ERRORS: Array.from(RETRYABLE_NET_ERRORS),
328
+ STATES: { CLOSED: STATE_CLOSED, OPEN: STATE_OPEN, HALF_OPEN: STATE_HALF },
329
+ };