hide-a-bed 7.2.1 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cjs/index.cjs +81 -68
- package/dist/esm/index.mjs +81 -68
- package/impl/bindConfig.mts +3 -0
- package/impl/bulkSave.mts +2 -0
- package/impl/patch.mts +10 -4
- package/impl/retry.mts +33 -5
- package/impl/utils/errors.mts +13 -3
- package/package.json +1 -1
- package/schema/config.mts +8 -0
- package/types/output/impl/bindConfig.d.mts.map +1 -1
- package/types/output/impl/bulkSave.d.mts.map +1 -1
- package/types/output/impl/patch.d.mts.map +1 -1
- package/types/output/impl/retry.d.mts +5 -1
- package/types/output/impl/retry.d.mts.map +1 -1
- package/types/output/impl/utils/errors.d.mts +3 -1
- package/types/output/impl/utils/errors.d.mts.map +1 -1
- package/types/output/schema/config.d.mts +1 -0
- package/types/output/schema/config.d.mts.map +1 -1
package/README.md
CHANGED
|
@@ -766,6 +766,7 @@ The config object supports the following properties:
|
|
|
766
766
|
| throwOnGetNotFound | boolean | false | If true, `get()` throws `NotFoundError` on 404. If false, `get()` returns `null` |
|
|
767
767
|
| bindWithRetry | boolean | true | When using bindConfig(), adds retry logic to bound methods |
|
|
768
768
|
| maxRetries | number | 3 | Maximum number of retry attempts for retryable operations |
|
|
769
|
+
| maxAuthRetries | number | 3 | Maximum number of retry attempts for transient `401`/`403` auth errors |
|
|
769
770
|
| initialDelay | number | 1000 | Initial delay in milliseconds before first retry |
|
|
770
771
|
| backoffFactor | number | 2 | Multiplier for exponential backoff between retries |
|
|
771
772
|
| useConsoleLogger | boolean | false | If true, enables console logging when no logger is provided |
|
|
@@ -793,7 +794,7 @@ const config = {
|
|
|
793
794
|
}
|
|
794
795
|
```
|
|
795
796
|
|
|
796
|
-
`bindConfig()` and `withRetry()`
|
|
797
|
+
`bindConfig()` and `withRetry()` perform bounded built-in retries (default `3`, configurable via `maxAuthRetries`) for transient `401` and `403` responses before surfacing the error.
|
|
797
798
|
|
|
798
799
|
### withRetry
|
|
799
800
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -39,65 +39,6 @@ let stream_json_streamers_StreamArray_js = require("stream-json/streamers/Stream
|
|
|
39
39
|
stream_json_streamers_StreamArray_js = __toESM(stream_json_streamers_StreamArray_js);
|
|
40
40
|
let events = require("events");
|
|
41
41
|
|
|
42
|
-
//#region schema/request.mts
|
|
43
|
-
const isAbortSignal = (value) => {
|
|
44
|
-
return value instanceof AbortSignal;
|
|
45
|
-
};
|
|
46
|
-
const isDispatcher = (value) => {
|
|
47
|
-
if (typeof value !== "object" || value === null) return false;
|
|
48
|
-
return typeof value.dispatch === "function";
|
|
49
|
-
};
|
|
50
|
-
const RequestOptions = zod.z.strictObject({
|
|
51
|
-
dispatcher: zod.z.custom(isDispatcher, { message: "dispatcher must expose a dispatch method" }).optional().describe("dispatcher to use for the request"),
|
|
52
|
-
signal: zod.z.custom(isAbortSignal, { message: "signal must be an AbortSignal" }).optional().describe("abort signal for the request"),
|
|
53
|
-
timeout: zod.z.number().nonnegative().optional().describe("request timeout in milliseconds")
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region schema/config.mts
|
|
58
|
-
const loggerLevels = [
|
|
59
|
-
"error",
|
|
60
|
-
"warn",
|
|
61
|
-
"info",
|
|
62
|
-
"debug"
|
|
63
|
-
];
|
|
64
|
-
const isLoggerMethod = (value) => typeof value === "function";
|
|
65
|
-
const LoggerSchema = zod.z.custom((value) => {
|
|
66
|
-
if (isLoggerMethod(value)) return true;
|
|
67
|
-
if (value === null || typeof value !== "object") return false;
|
|
68
|
-
return loggerLevels.every((level) => {
|
|
69
|
-
const method = value[level];
|
|
70
|
-
return method === void 0 || isLoggerMethod(method);
|
|
71
|
-
});
|
|
72
|
-
}, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
|
|
73
|
-
const CouchAuth = zod.z.strictObject({
|
|
74
|
-
username: zod.z.string().describe("basic auth username for CouchDB requests"),
|
|
75
|
-
password: zod.z.string().describe("basic auth password for CouchDB requests")
|
|
76
|
-
});
|
|
77
|
-
const CouchUrl = zod.z.custom((value) => {
|
|
78
|
-
try {
|
|
79
|
-
const url = new URL(value);
|
|
80
|
-
return url.username === "" && url.password === "";
|
|
81
|
-
} catch {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
const CouchConfig = zod.z.strictObject({
|
|
86
|
-
auth: CouchAuth.optional().describe("basic auth credentials for CouchDB requests"),
|
|
87
|
-
backoffFactor: zod.z.number().optional().default(2).describe("multiplier for exponential backoff"),
|
|
88
|
-
bindWithRetry: zod.z.boolean().optional().default(true).describe("should we bind with retry"),
|
|
89
|
-
couch: CouchUrl.describe("URL of the couch db without embedded credentials"),
|
|
90
|
-
initialDelay: zod.z.number().optional().default(1e3).describe("initial retry delay in milliseconds"),
|
|
91
|
-
logger: LoggerSchema.optional().describe("logging interface supporting winston-like or simple function interface"),
|
|
92
|
-
maxRetries: zod.z.number().optional().default(3).describe("maximum number of retry attempts"),
|
|
93
|
-
request: RequestOptions.optional().describe("default request controls for CouchDB requests"),
|
|
94
|
-
throwOnGetNotFound: zod.z.boolean().optional().default(false).describe("if true, get() throws NotFoundError on 404; otherwise it returns null"),
|
|
95
|
-
useConsoleLogger: zod.z.boolean().optional().default(false).describe("turn on console as a fallback logger"),
|
|
96
|
-
"~emitter": zod.z.any().optional().describe("emitter for events"),
|
|
97
|
-
"~normalizedLogger": zod.z.any().optional()
|
|
98
|
-
}).describe("The std config object");
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
42
|
//#region impl/utils/response.mts
|
|
102
43
|
const isRecord = (value) => {
|
|
103
44
|
return value !== null && typeof value === "object";
|
|
@@ -173,11 +114,15 @@ const getNestedNetworkError = (value) => {
|
|
|
173
114
|
const hasStatusCode = (error) => {
|
|
174
115
|
return isObject(error) && "statusCode" in error && typeof error.statusCode === "number";
|
|
175
116
|
};
|
|
176
|
-
const
|
|
117
|
+
const DEFAULT_MAX_AUTH_RETRIES = 3;
|
|
118
|
+
const isAuthError = (error) => {
|
|
177
119
|
if (!hasStatusCode(error)) return false;
|
|
178
|
-
if (attempt > 0) return false;
|
|
179
120
|
return error.statusCode === 401 || error.statusCode === 403;
|
|
180
121
|
};
|
|
122
|
+
const isTransientAuthError = (error, attempt, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES) => {
|
|
123
|
+
if (attempt >= maxAuthRetries) return false;
|
|
124
|
+
return isAuthError(error);
|
|
125
|
+
};
|
|
181
126
|
/**
|
|
182
127
|
* Shared base class for operational errors thrown by hide-a-bed.
|
|
183
128
|
*
|
|
@@ -386,6 +331,66 @@ function isConflictError(err) {
|
|
|
386
331
|
return err.statusCode === 409;
|
|
387
332
|
}
|
|
388
333
|
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region schema/request.mts
|
|
336
|
+
const isAbortSignal = (value) => {
|
|
337
|
+
return value instanceof AbortSignal;
|
|
338
|
+
};
|
|
339
|
+
const isDispatcher = (value) => {
|
|
340
|
+
if (typeof value !== "object" || value === null) return false;
|
|
341
|
+
return typeof value.dispatch === "function";
|
|
342
|
+
};
|
|
343
|
+
const RequestOptions = zod.z.strictObject({
|
|
344
|
+
dispatcher: zod.z.custom(isDispatcher, { message: "dispatcher must expose a dispatch method" }).optional().describe("dispatcher to use for the request"),
|
|
345
|
+
signal: zod.z.custom(isAbortSignal, { message: "signal must be an AbortSignal" }).optional().describe("abort signal for the request"),
|
|
346
|
+
timeout: zod.z.number().nonnegative().optional().describe("request timeout in milliseconds")
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region schema/config.mts
|
|
351
|
+
const loggerLevels = [
|
|
352
|
+
"error",
|
|
353
|
+
"warn",
|
|
354
|
+
"info",
|
|
355
|
+
"debug"
|
|
356
|
+
];
|
|
357
|
+
const isLoggerMethod = (value) => typeof value === "function";
|
|
358
|
+
const LoggerSchema = zod.z.custom((value) => {
|
|
359
|
+
if (isLoggerMethod(value)) return true;
|
|
360
|
+
if (value === null || typeof value !== "object") return false;
|
|
361
|
+
return loggerLevels.every((level) => {
|
|
362
|
+
const method = value[level];
|
|
363
|
+
return method === void 0 || isLoggerMethod(method);
|
|
364
|
+
});
|
|
365
|
+
}, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
|
|
366
|
+
const CouchAuth = zod.z.strictObject({
|
|
367
|
+
username: zod.z.string().describe("basic auth username for CouchDB requests"),
|
|
368
|
+
password: zod.z.string().describe("basic auth password for CouchDB requests")
|
|
369
|
+
});
|
|
370
|
+
const CouchUrl = zod.z.custom((value) => {
|
|
371
|
+
try {
|
|
372
|
+
const url = new URL(value);
|
|
373
|
+
return url.username === "" && url.password === "";
|
|
374
|
+
} catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const CouchConfig = zod.z.strictObject({
|
|
379
|
+
auth: CouchAuth.optional().describe("basic auth credentials for CouchDB requests"),
|
|
380
|
+
backoffFactor: zod.z.number().optional().default(2).describe("multiplier for exponential backoff"),
|
|
381
|
+
bindWithRetry: zod.z.boolean().optional().default(true).describe("should we bind with retry"),
|
|
382
|
+
couch: CouchUrl.describe("URL of the couch db without embedded credentials"),
|
|
383
|
+
initialDelay: zod.z.number().optional().default(1e3).describe("initial retry delay in milliseconds"),
|
|
384
|
+
logger: LoggerSchema.optional().describe("logging interface supporting winston-like or simple function interface"),
|
|
385
|
+
maxAuthRetries: zod.z.number().int().min(0).optional().default(DEFAULT_MAX_AUTH_RETRIES).describe("maximum number of retry attempts for transient 401/403 auth errors"),
|
|
386
|
+
maxRetries: zod.z.number().optional().default(3).describe("maximum number of retry attempts"),
|
|
387
|
+
request: RequestOptions.optional().describe("default request controls for CouchDB requests"),
|
|
388
|
+
throwOnGetNotFound: zod.z.boolean().optional().default(false).describe("if true, get() throws NotFoundError on 404; otherwise it returns null"),
|
|
389
|
+
useConsoleLogger: zod.z.boolean().optional().default(false).describe("turn on console as a fallback logger"),
|
|
390
|
+
"~emitter": zod.z.any().optional().describe("emitter for events"),
|
|
391
|
+
"~normalizedLogger": zod.z.any().optional()
|
|
392
|
+
}).describe("The std config object");
|
|
393
|
+
|
|
389
394
|
//#endregion
|
|
390
395
|
//#region impl/utils/request.mts
|
|
391
396
|
const definedSignals = (signals) => {
|
|
@@ -730,8 +735,9 @@ const createQuery = () => new QueryBuilder();
|
|
|
730
735
|
|
|
731
736
|
//#endregion
|
|
732
737
|
//#region impl/retry.mts
|
|
733
|
-
const shouldRetryError = (error,
|
|
734
|
-
|
|
738
|
+
const shouldRetryError = (error, authRetryCount, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES) => {
|
|
739
|
+
if (isAuthError(error)) return isTransientAuthError(error, authRetryCount, maxAuthRetries);
|
|
740
|
+
return error instanceof RetryableError;
|
|
735
741
|
};
|
|
736
742
|
/**
|
|
737
743
|
* Wrap an async-capable function with retry semantics that respect {@link RetryableError}.
|
|
@@ -741,14 +747,16 @@ const shouldRetryError = (error, attempt) => {
|
|
|
741
747
|
* @returns A function mirroring `fn` that automatically retries on {@link RetryableError}.
|
|
742
748
|
*/
|
|
743
749
|
function withRetry(fn, options = {}) {
|
|
744
|
-
const { maxRetries = 3, initialDelay = 1e3, backoffFactor = 2, maxDelay = 3e4 } = options;
|
|
750
|
+
const { maxRetries = 3, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES, initialDelay = 1e3, backoffFactor = 2, maxDelay = 3e4 } = options;
|
|
745
751
|
return async (...args) => {
|
|
746
752
|
let delay = initialDelay;
|
|
753
|
+
let authRetries = 0;
|
|
747
754
|
for (let attempt = 0; attempt <= maxRetries; attempt++) try {
|
|
748
755
|
return await fn(...args);
|
|
749
756
|
} catch (error) {
|
|
750
|
-
if (!shouldRetryError(error,
|
|
757
|
+
if (!shouldRetryError(error, authRetries, maxAuthRetries)) throw error;
|
|
751
758
|
if (attempt === maxRetries) throw error;
|
|
759
|
+
if (isAuthError(error)) authRetries += 1;
|
|
752
760
|
await (0, node_timers_promises.setTimeout)(Math.min(delay, maxDelay));
|
|
753
761
|
delay *= backoffFactor;
|
|
754
762
|
}
|
|
@@ -1509,9 +1517,10 @@ const patch = async (configInput, id, _properties) => {
|
|
|
1509
1517
|
const patchDangerously = async (configInput, id, properties) => {
|
|
1510
1518
|
const config = CouchConfig.parse(configInput);
|
|
1511
1519
|
const logger = createLogger(config);
|
|
1512
|
-
const maxRetries = config.maxRetries
|
|
1513
|
-
let delay = config.initialDelay
|
|
1520
|
+
const maxRetries = config.maxRetries ?? 5;
|
|
1521
|
+
let delay = config.initialDelay ?? 1e3;
|
|
1514
1522
|
let attempts = 0;
|
|
1523
|
+
let authRetries = 0;
|
|
1515
1524
|
logger.info(`Starting patch operation for document ${id}`);
|
|
1516
1525
|
logger.debug("Patch properties:", properties);
|
|
1517
1526
|
let lastError;
|
|
@@ -1536,7 +1545,8 @@ const patchDangerously = async (configInput, id, properties) => {
|
|
|
1536
1545
|
return result;
|
|
1537
1546
|
} catch (err) {
|
|
1538
1547
|
if (!(err instanceof Error)) throw err;
|
|
1539
|
-
if (!(err instanceof ConflictError || shouldRetryError(err,
|
|
1548
|
+
if (!(err instanceof ConflictError || shouldRetryError(err, authRetries, config.maxAuthRetries))) throw err;
|
|
1549
|
+
if (isAuthError(err)) authRetries++;
|
|
1540
1550
|
lastError = err;
|
|
1541
1551
|
attempts++;
|
|
1542
1552
|
if (attempts > maxRetries) {
|
|
@@ -1827,6 +1837,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1827
1837
|
const logger = createLogger(config);
|
|
1828
1838
|
const retryOptions = {
|
|
1829
1839
|
maxRetries: config.maxRetries ?? 10,
|
|
1840
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
1830
1841
|
initialDelay: config.initialDelay ?? 1e3,
|
|
1831
1842
|
backoffFactor: config.backoffFactor ?? 2
|
|
1832
1843
|
};
|
|
@@ -2488,6 +2499,7 @@ function getBoundWithRetry(func, config) {
|
|
|
2488
2499
|
const bound = func.bind(null, config);
|
|
2489
2500
|
if (config.bindWithRetry) return withRetry(bound, {
|
|
2490
2501
|
maxRetries: config.maxRetries ?? 10,
|
|
2502
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
2491
2503
|
initialDelay: config.initialDelay ?? 1e3,
|
|
2492
2504
|
backoffFactor: config.backoffFactor ?? 2
|
|
2493
2505
|
});
|
|
@@ -2503,6 +2515,7 @@ function getBoundWithRetry(func, config) {
|
|
|
2503
2515
|
function doBind(config) {
|
|
2504
2516
|
const retryOptions = {
|
|
2505
2517
|
maxRetries: config.maxRetries ?? 10,
|
|
2518
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
2506
2519
|
initialDelay: config.initialDelay ?? 1e3,
|
|
2507
2520
|
backoffFactor: config.backoffFactor ?? 2
|
|
2508
2521
|
};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -7,65 +7,6 @@ import Pick from "stream-json/filters/Pick.js";
|
|
|
7
7
|
import StreamArray from "stream-json/streamers/StreamArray.js";
|
|
8
8
|
import { EventEmitter } from "events";
|
|
9
9
|
|
|
10
|
-
//#region schema/request.mts
|
|
11
|
-
const isAbortSignal = (value) => {
|
|
12
|
-
return value instanceof AbortSignal;
|
|
13
|
-
};
|
|
14
|
-
const isDispatcher = (value) => {
|
|
15
|
-
if (typeof value !== "object" || value === null) return false;
|
|
16
|
-
return typeof value.dispatch === "function";
|
|
17
|
-
};
|
|
18
|
-
const RequestOptions = z$1.strictObject({
|
|
19
|
-
dispatcher: z$1.custom(isDispatcher, { message: "dispatcher must expose a dispatch method" }).optional().describe("dispatcher to use for the request"),
|
|
20
|
-
signal: z$1.custom(isAbortSignal, { message: "signal must be an AbortSignal" }).optional().describe("abort signal for the request"),
|
|
21
|
-
timeout: z$1.number().nonnegative().optional().describe("request timeout in milliseconds")
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region schema/config.mts
|
|
26
|
-
const loggerLevels = [
|
|
27
|
-
"error",
|
|
28
|
-
"warn",
|
|
29
|
-
"info",
|
|
30
|
-
"debug"
|
|
31
|
-
];
|
|
32
|
-
const isLoggerMethod = (value) => typeof value === "function";
|
|
33
|
-
const LoggerSchema = z$1.custom((value) => {
|
|
34
|
-
if (isLoggerMethod(value)) return true;
|
|
35
|
-
if (value === null || typeof value !== "object") return false;
|
|
36
|
-
return loggerLevels.every((level) => {
|
|
37
|
-
const method = value[level];
|
|
38
|
-
return method === void 0 || isLoggerMethod(method);
|
|
39
|
-
});
|
|
40
|
-
}, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
|
|
41
|
-
const CouchAuth = z$1.strictObject({
|
|
42
|
-
username: z$1.string().describe("basic auth username for CouchDB requests"),
|
|
43
|
-
password: z$1.string().describe("basic auth password for CouchDB requests")
|
|
44
|
-
});
|
|
45
|
-
const CouchUrl = z$1.custom((value) => {
|
|
46
|
-
try {
|
|
47
|
-
const url = new URL(value);
|
|
48
|
-
return url.username === "" && url.password === "";
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const CouchConfig = z$1.strictObject({
|
|
54
|
-
auth: CouchAuth.optional().describe("basic auth credentials for CouchDB requests"),
|
|
55
|
-
backoffFactor: z$1.number().optional().default(2).describe("multiplier for exponential backoff"),
|
|
56
|
-
bindWithRetry: z$1.boolean().optional().default(true).describe("should we bind with retry"),
|
|
57
|
-
couch: CouchUrl.describe("URL of the couch db without embedded credentials"),
|
|
58
|
-
initialDelay: z$1.number().optional().default(1e3).describe("initial retry delay in milliseconds"),
|
|
59
|
-
logger: LoggerSchema.optional().describe("logging interface supporting winston-like or simple function interface"),
|
|
60
|
-
maxRetries: z$1.number().optional().default(3).describe("maximum number of retry attempts"),
|
|
61
|
-
request: RequestOptions.optional().describe("default request controls for CouchDB requests"),
|
|
62
|
-
throwOnGetNotFound: z$1.boolean().optional().default(false).describe("if true, get() throws NotFoundError on 404; otherwise it returns null"),
|
|
63
|
-
useConsoleLogger: z$1.boolean().optional().default(false).describe("turn on console as a fallback logger"),
|
|
64
|
-
"~emitter": z$1.any().optional().describe("emitter for events"),
|
|
65
|
-
"~normalizedLogger": z$1.any().optional()
|
|
66
|
-
}).describe("The std config object");
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
10
|
//#region impl/utils/response.mts
|
|
70
11
|
const isRecord = (value) => {
|
|
71
12
|
return value !== null && typeof value === "object";
|
|
@@ -141,11 +82,15 @@ const getNestedNetworkError = (value) => {
|
|
|
141
82
|
const hasStatusCode = (error) => {
|
|
142
83
|
return isObject(error) && "statusCode" in error && typeof error.statusCode === "number";
|
|
143
84
|
};
|
|
144
|
-
const
|
|
85
|
+
const DEFAULT_MAX_AUTH_RETRIES = 3;
|
|
86
|
+
const isAuthError = (error) => {
|
|
145
87
|
if (!hasStatusCode(error)) return false;
|
|
146
|
-
if (attempt > 0) return false;
|
|
147
88
|
return error.statusCode === 401 || error.statusCode === 403;
|
|
148
89
|
};
|
|
90
|
+
const isTransientAuthError = (error, attempt, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES) => {
|
|
91
|
+
if (attempt >= maxAuthRetries) return false;
|
|
92
|
+
return isAuthError(error);
|
|
93
|
+
};
|
|
149
94
|
/**
|
|
150
95
|
* Shared base class for operational errors thrown by hide-a-bed.
|
|
151
96
|
*
|
|
@@ -354,6 +299,66 @@ function isConflictError(err) {
|
|
|
354
299
|
return err.statusCode === 409;
|
|
355
300
|
}
|
|
356
301
|
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region schema/request.mts
|
|
304
|
+
const isAbortSignal = (value) => {
|
|
305
|
+
return value instanceof AbortSignal;
|
|
306
|
+
};
|
|
307
|
+
const isDispatcher = (value) => {
|
|
308
|
+
if (typeof value !== "object" || value === null) return false;
|
|
309
|
+
return typeof value.dispatch === "function";
|
|
310
|
+
};
|
|
311
|
+
const RequestOptions = z$1.strictObject({
|
|
312
|
+
dispatcher: z$1.custom(isDispatcher, { message: "dispatcher must expose a dispatch method" }).optional().describe("dispatcher to use for the request"),
|
|
313
|
+
signal: z$1.custom(isAbortSignal, { message: "signal must be an AbortSignal" }).optional().describe("abort signal for the request"),
|
|
314
|
+
timeout: z$1.number().nonnegative().optional().describe("request timeout in milliseconds")
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region schema/config.mts
|
|
319
|
+
const loggerLevels = [
|
|
320
|
+
"error",
|
|
321
|
+
"warn",
|
|
322
|
+
"info",
|
|
323
|
+
"debug"
|
|
324
|
+
];
|
|
325
|
+
const isLoggerMethod = (value) => typeof value === "function";
|
|
326
|
+
const LoggerSchema = z$1.custom((value) => {
|
|
327
|
+
if (isLoggerMethod(value)) return true;
|
|
328
|
+
if (value === null || typeof value !== "object") return false;
|
|
329
|
+
return loggerLevels.every((level) => {
|
|
330
|
+
const method = value[level];
|
|
331
|
+
return method === void 0 || isLoggerMethod(method);
|
|
332
|
+
});
|
|
333
|
+
}, { message: "logger must be a function or object with optional error, warn, info, and debug methods" });
|
|
334
|
+
const CouchAuth = z$1.strictObject({
|
|
335
|
+
username: z$1.string().describe("basic auth username for CouchDB requests"),
|
|
336
|
+
password: z$1.string().describe("basic auth password for CouchDB requests")
|
|
337
|
+
});
|
|
338
|
+
const CouchUrl = z$1.custom((value) => {
|
|
339
|
+
try {
|
|
340
|
+
const url = new URL(value);
|
|
341
|
+
return url.username === "" && url.password === "";
|
|
342
|
+
} catch {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const CouchConfig = z$1.strictObject({
|
|
347
|
+
auth: CouchAuth.optional().describe("basic auth credentials for CouchDB requests"),
|
|
348
|
+
backoffFactor: z$1.number().optional().default(2).describe("multiplier for exponential backoff"),
|
|
349
|
+
bindWithRetry: z$1.boolean().optional().default(true).describe("should we bind with retry"),
|
|
350
|
+
couch: CouchUrl.describe("URL of the couch db without embedded credentials"),
|
|
351
|
+
initialDelay: z$1.number().optional().default(1e3).describe("initial retry delay in milliseconds"),
|
|
352
|
+
logger: LoggerSchema.optional().describe("logging interface supporting winston-like or simple function interface"),
|
|
353
|
+
maxAuthRetries: z$1.number().int().min(0).optional().default(DEFAULT_MAX_AUTH_RETRIES).describe("maximum number of retry attempts for transient 401/403 auth errors"),
|
|
354
|
+
maxRetries: z$1.number().optional().default(3).describe("maximum number of retry attempts"),
|
|
355
|
+
request: RequestOptions.optional().describe("default request controls for CouchDB requests"),
|
|
356
|
+
throwOnGetNotFound: z$1.boolean().optional().default(false).describe("if true, get() throws NotFoundError on 404; otherwise it returns null"),
|
|
357
|
+
useConsoleLogger: z$1.boolean().optional().default(false).describe("turn on console as a fallback logger"),
|
|
358
|
+
"~emitter": z$1.any().optional().describe("emitter for events"),
|
|
359
|
+
"~normalizedLogger": z$1.any().optional()
|
|
360
|
+
}).describe("The std config object");
|
|
361
|
+
|
|
357
362
|
//#endregion
|
|
358
363
|
//#region impl/utils/request.mts
|
|
359
364
|
const definedSignals = (signals) => {
|
|
@@ -698,8 +703,9 @@ const createQuery = () => new QueryBuilder();
|
|
|
698
703
|
|
|
699
704
|
//#endregion
|
|
700
705
|
//#region impl/retry.mts
|
|
701
|
-
const shouldRetryError = (error,
|
|
702
|
-
|
|
706
|
+
const shouldRetryError = (error, authRetryCount, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES) => {
|
|
707
|
+
if (isAuthError(error)) return isTransientAuthError(error, authRetryCount, maxAuthRetries);
|
|
708
|
+
return error instanceof RetryableError;
|
|
703
709
|
};
|
|
704
710
|
/**
|
|
705
711
|
* Wrap an async-capable function with retry semantics that respect {@link RetryableError}.
|
|
@@ -709,14 +715,16 @@ const shouldRetryError = (error, attempt) => {
|
|
|
709
715
|
* @returns A function mirroring `fn` that automatically retries on {@link RetryableError}.
|
|
710
716
|
*/
|
|
711
717
|
function withRetry(fn, options = {}) {
|
|
712
|
-
const { maxRetries = 3, initialDelay = 1e3, backoffFactor = 2, maxDelay = 3e4 } = options;
|
|
718
|
+
const { maxRetries = 3, maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES, initialDelay = 1e3, backoffFactor = 2, maxDelay = 3e4 } = options;
|
|
713
719
|
return async (...args) => {
|
|
714
720
|
let delay = initialDelay;
|
|
721
|
+
let authRetries = 0;
|
|
715
722
|
for (let attempt = 0; attempt <= maxRetries; attempt++) try {
|
|
716
723
|
return await fn(...args);
|
|
717
724
|
} catch (error) {
|
|
718
|
-
if (!shouldRetryError(error,
|
|
725
|
+
if (!shouldRetryError(error, authRetries, maxAuthRetries)) throw error;
|
|
719
726
|
if (attempt === maxRetries) throw error;
|
|
727
|
+
if (isAuthError(error)) authRetries += 1;
|
|
720
728
|
await setTimeout$1(Math.min(delay, maxDelay));
|
|
721
729
|
delay *= backoffFactor;
|
|
722
730
|
}
|
|
@@ -1477,9 +1485,10 @@ const patch = async (configInput, id, _properties) => {
|
|
|
1477
1485
|
const patchDangerously = async (configInput, id, properties) => {
|
|
1478
1486
|
const config = CouchConfig.parse(configInput);
|
|
1479
1487
|
const logger = createLogger(config);
|
|
1480
|
-
const maxRetries = config.maxRetries
|
|
1481
|
-
let delay = config.initialDelay
|
|
1488
|
+
const maxRetries = config.maxRetries ?? 5;
|
|
1489
|
+
let delay = config.initialDelay ?? 1e3;
|
|
1482
1490
|
let attempts = 0;
|
|
1491
|
+
let authRetries = 0;
|
|
1483
1492
|
logger.info(`Starting patch operation for document ${id}`);
|
|
1484
1493
|
logger.debug("Patch properties:", properties);
|
|
1485
1494
|
let lastError;
|
|
@@ -1504,7 +1513,8 @@ const patchDangerously = async (configInput, id, properties) => {
|
|
|
1504
1513
|
return result;
|
|
1505
1514
|
} catch (err) {
|
|
1506
1515
|
if (!(err instanceof Error)) throw err;
|
|
1507
|
-
if (!(err instanceof ConflictError || shouldRetryError(err,
|
|
1516
|
+
if (!(err instanceof ConflictError || shouldRetryError(err, authRetries, config.maxAuthRetries))) throw err;
|
|
1517
|
+
if (isAuthError(err)) authRetries++;
|
|
1508
1518
|
lastError = err;
|
|
1509
1519
|
attempts++;
|
|
1510
1520
|
if (attempts > maxRetries) {
|
|
@@ -1795,6 +1805,7 @@ const bulkSaveTransaction = async (config, transactionId, docs) => {
|
|
|
1795
1805
|
const logger = createLogger(config);
|
|
1796
1806
|
const retryOptions = {
|
|
1797
1807
|
maxRetries: config.maxRetries ?? 10,
|
|
1808
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
1798
1809
|
initialDelay: config.initialDelay ?? 1e3,
|
|
1799
1810
|
backoffFactor: config.backoffFactor ?? 2
|
|
1800
1811
|
};
|
|
@@ -2456,6 +2467,7 @@ function getBoundWithRetry(func, config) {
|
|
|
2456
2467
|
const bound = func.bind(null, config);
|
|
2457
2468
|
if (config.bindWithRetry) return withRetry(bound, {
|
|
2458
2469
|
maxRetries: config.maxRetries ?? 10,
|
|
2470
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
2459
2471
|
initialDelay: config.initialDelay ?? 1e3,
|
|
2460
2472
|
backoffFactor: config.backoffFactor ?? 2
|
|
2461
2473
|
});
|
|
@@ -2471,6 +2483,7 @@ function getBoundWithRetry(func, config) {
|
|
|
2471
2483
|
function doBind(config) {
|
|
2472
2484
|
const retryOptions = {
|
|
2473
2485
|
maxRetries: config.maxRetries ?? 10,
|
|
2486
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
2474
2487
|
initialDelay: config.initialDelay ?? 1e3,
|
|
2475
2488
|
backoffFactor: config.backoffFactor ?? 2
|
|
2476
2489
|
};
|
package/impl/bindConfig.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { find, type FindBound } from './find.mts'
|
|
|
3
3
|
import type z from 'zod'
|
|
4
4
|
import { CouchConfig, type CouchConfigInput } from '../schema/config.mts'
|
|
5
5
|
import { withRetry } from './retry.mts'
|
|
6
|
+
import { DEFAULT_MAX_AUTH_RETRIES } from './utils/errors.mts'
|
|
6
7
|
import {
|
|
7
8
|
type BulkGetBound,
|
|
8
9
|
bulkGet,
|
|
@@ -94,6 +95,7 @@ export function getBoundWithRetry<TBound extends (...args: any[]) => Promise<any
|
|
|
94
95
|
if (config.bindWithRetry) {
|
|
95
96
|
return withRetry(bound, {
|
|
96
97
|
maxRetries: config.maxRetries ?? 10,
|
|
98
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
97
99
|
initialDelay: config.initialDelay ?? 1000,
|
|
98
100
|
backoffFactor: config.backoffFactor ?? 2
|
|
99
101
|
}) as TBound
|
|
@@ -113,6 +115,7 @@ function doBind(config: CouchConfig): BoundMethods {
|
|
|
113
115
|
// Default retry options
|
|
114
116
|
const retryOptions = {
|
|
115
117
|
maxRetries: config.maxRetries ?? 10,
|
|
118
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
116
119
|
initialDelay: config.initialDelay ?? 1000,
|
|
117
120
|
backoffFactor: config.backoffFactor ?? 2
|
|
118
121
|
}
|
package/impl/bulkSave.mts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { CouchConfig, type CouchConfigInput } from '../schema/config.mts'
|
|
16
16
|
import {
|
|
17
17
|
ConflictError,
|
|
18
|
+
DEFAULT_MAX_AUTH_RETRIES,
|
|
18
19
|
OperationError,
|
|
19
20
|
RetryableError,
|
|
20
21
|
createResponseError
|
|
@@ -158,6 +159,7 @@ export const bulkSaveTransaction = async (
|
|
|
158
159
|
const logger = createLogger(config)
|
|
159
160
|
const retryOptions = {
|
|
160
161
|
maxRetries: config.maxRetries ?? 10,
|
|
162
|
+
maxAuthRetries: config.maxAuthRetries ?? DEFAULT_MAX_AUTH_RETRIES,
|
|
161
163
|
initialDelay: config.initialDelay ?? 1000,
|
|
162
164
|
backoffFactor: config.backoffFactor ?? 2
|
|
163
165
|
}
|
package/impl/patch.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { createLogger } from './utils/logger.mts'
|
|
|
4
4
|
import { setTimeout } from 'node:timers/promises'
|
|
5
5
|
import { CouchConfig, type CouchConfigInput } from '../schema/config.mts'
|
|
6
6
|
import { z } from 'zod'
|
|
7
|
-
import { ConflictError, HideABedError, OperationError } from './utils/errors.mts'
|
|
7
|
+
import { ConflictError, HideABedError, isAuthError, OperationError } from './utils/errors.mts'
|
|
8
8
|
import { shouldRetryError } from './retry.mts'
|
|
9
9
|
|
|
10
10
|
const PatchProperties = z
|
|
@@ -78,9 +78,10 @@ export const patchDangerously = async (
|
|
|
78
78
|
) => {
|
|
79
79
|
const config = CouchConfig.parse(configInput)
|
|
80
80
|
const logger = createLogger(config)
|
|
81
|
-
const maxRetries = config.maxRetries
|
|
82
|
-
let delay = config.initialDelay
|
|
81
|
+
const maxRetries = config.maxRetries ?? 5
|
|
82
|
+
let delay = config.initialDelay ?? 1000
|
|
83
83
|
let attempts = 0
|
|
84
|
+
let authRetries = 0
|
|
84
85
|
|
|
85
86
|
logger.info(`Starting patch operation for document ${id}`)
|
|
86
87
|
logger.debug('Patch properties:', properties)
|
|
@@ -107,12 +108,17 @@ export const patchDangerously = async (
|
|
|
107
108
|
throw err
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
const shouldRetry =
|
|
111
|
+
const shouldRetry =
|
|
112
|
+
err instanceof ConflictError || shouldRetryError(err, authRetries, config.maxAuthRetries)
|
|
111
113
|
|
|
112
114
|
if (!shouldRetry) {
|
|
113
115
|
throw err
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
if (isAuthError(err)) {
|
|
119
|
+
authRetries++
|
|
120
|
+
}
|
|
121
|
+
|
|
116
122
|
lastError = err
|
|
117
123
|
attempts++
|
|
118
124
|
if (attempts > maxRetries) {
|
package/impl/retry.mts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_MAX_AUTH_RETRIES,
|
|
4
|
+
isAuthError,
|
|
5
|
+
isTransientAuthError,
|
|
6
|
+
RetryableError
|
|
7
|
+
} from './utils/errors.mts'
|
|
3
8
|
|
|
4
|
-
export const shouldRetryError = (
|
|
5
|
-
|
|
9
|
+
export const shouldRetryError = (
|
|
10
|
+
error: unknown,
|
|
11
|
+
authRetryCount: number,
|
|
12
|
+
maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES
|
|
13
|
+
) => {
|
|
14
|
+
if (isAuthError(error)) {
|
|
15
|
+
return isTransientAuthError(error, authRetryCount, maxAuthRetries)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return error instanceof RetryableError
|
|
6
19
|
}
|
|
7
20
|
|
|
8
21
|
/**
|
|
@@ -13,6 +26,10 @@ export interface RetryOptions {
|
|
|
13
26
|
* Maximum number of retry attempts before rethrowing the original error.
|
|
14
27
|
*/
|
|
15
28
|
maxRetries?: number
|
|
29
|
+
/**
|
|
30
|
+
* Maximum number of retry attempts for transient 401/403 authentication errors.
|
|
31
|
+
*/
|
|
32
|
+
maxAuthRetries?: number
|
|
16
33
|
/**
|
|
17
34
|
* Initial wait duration in milliseconds before attempting the first retry.
|
|
18
35
|
*/
|
|
@@ -41,17 +58,24 @@ export function withRetry<Fn extends (...args: any[]) => MaybePromise<any>>(
|
|
|
41
58
|
fn: Fn,
|
|
42
59
|
options: RetryOptions = {}
|
|
43
60
|
): (...args: Parameters<Fn>) => Promise<Awaited<ReturnType<Fn>>> {
|
|
44
|
-
const {
|
|
61
|
+
const {
|
|
62
|
+
maxRetries = 3,
|
|
63
|
+
maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES,
|
|
64
|
+
initialDelay = 1000,
|
|
65
|
+
backoffFactor = 2,
|
|
66
|
+
maxDelay = 30000
|
|
67
|
+
} = options
|
|
45
68
|
|
|
46
69
|
return async (...args: Parameters<Fn>): Promise<Awaited<ReturnType<Fn>>> => {
|
|
47
70
|
let delay = initialDelay
|
|
71
|
+
let authRetries = 0
|
|
48
72
|
|
|
49
73
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
50
74
|
try {
|
|
51
75
|
const result = await fn(...args)
|
|
52
76
|
return result
|
|
53
77
|
} catch (error) {
|
|
54
|
-
if (!shouldRetryError(error,
|
|
78
|
+
if (!shouldRetryError(error, authRetries, maxAuthRetries)) {
|
|
55
79
|
throw error
|
|
56
80
|
}
|
|
57
81
|
|
|
@@ -59,6 +83,10 @@ export function withRetry<Fn extends (...args: any[]) => MaybePromise<any>>(
|
|
|
59
83
|
throw error
|
|
60
84
|
}
|
|
61
85
|
|
|
86
|
+
if (isAuthError(error)) {
|
|
87
|
+
authRetries += 1
|
|
88
|
+
}
|
|
89
|
+
|
|
62
90
|
const nextDelay = Math.min(delay, maxDelay)
|
|
63
91
|
await setTimeout(nextDelay)
|
|
64
92
|
delay *= backoffFactor
|
package/impl/utils/errors.mts
CHANGED
|
@@ -91,13 +91,23 @@ export const hasStatusCode = (error: unknown): error is { statusCode: number } =
|
|
|
91
91
|
return isObject(error) && 'statusCode' in error && typeof error.statusCode === 'number'
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export const
|
|
95
|
-
if (!hasStatusCode(error)) return false
|
|
96
|
-
if (attempt > 0) return false
|
|
94
|
+
export const DEFAULT_MAX_AUTH_RETRIES = 3
|
|
97
95
|
|
|
96
|
+
export const isAuthError = (error: unknown) => {
|
|
97
|
+
if (!hasStatusCode(error)) return false
|
|
98
98
|
return error.statusCode === 401 || error.statusCode === 403
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export const isTransientAuthError = (
|
|
102
|
+
error: unknown,
|
|
103
|
+
attempt: number,
|
|
104
|
+
maxAuthRetries = DEFAULT_MAX_AUTH_RETRIES
|
|
105
|
+
) => {
|
|
106
|
+
if (attempt >= maxAuthRetries) return false
|
|
107
|
+
|
|
108
|
+
return isAuthError(error)
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
/**
|
|
102
112
|
* Shared structured fields available on hide-a-bed operational errors.
|
|
103
113
|
*
|
package/package.json
CHANGED
package/schema/config.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
|
+
import { DEFAULT_MAX_AUTH_RETRIES } from '../impl/utils/errors.mts'
|
|
2
3
|
import type { StandardSchemaV1 } from '../types/standard-schema.ts'
|
|
3
4
|
import { RequestOptions } from './request.mts'
|
|
4
5
|
|
|
@@ -60,6 +61,13 @@ export const CouchConfig = z
|
|
|
60
61
|
logger: LoggerSchema.optional().describe(
|
|
61
62
|
'logging interface supporting winston-like or simple function interface'
|
|
62
63
|
),
|
|
64
|
+
maxAuthRetries: z
|
|
65
|
+
.number()
|
|
66
|
+
.int()
|
|
67
|
+
.min(0)
|
|
68
|
+
.optional()
|
|
69
|
+
.default(DEFAULT_MAX_AUTH_RETRIES)
|
|
70
|
+
.describe('maximum number of retry attempts for transient 401/403 auth errors'),
|
|
63
71
|
maxRetries: z.number().optional().default(3).describe('maximum number of retry attempts'),
|
|
64
72
|
request: RequestOptions.optional().describe('default request controls for CouchDB requests'),
|
|
65
73
|
throwOnGetNotFound: z
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindConfig.d.mts","sourceRoot":"","sources":["../../../impl/bindConfig.mts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"bindConfig.d.mts","sourceRoot":"","sources":["../../../impl/bindConfig.mts"],"names":[],"mappings":"AAAA,O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gB,iBAAiB,CAAC,MAAM,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC/E,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC3D,MAAM,EAAE,WAAW,UAapB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkSave.d.mts","sourceRoot":"","sources":["../../../impl/bulkSave.mts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAEhB,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"bulkSave.d.mts","sourceRoot":"","sources":["../../../impl/bulkSave.mts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAEhB,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AA0BzE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,GAAU,QAAQ,gBAAgB,EAAE,MAAM,aAAa,EAAE;;;;;;;;KA+C7E,CAAA;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,gBAAgB,EACxB,eAAe,MAAM,EACrB,MAAM,aAAa,EAAE,KACpB,OAAO,CAAC,gBAAgB,CAqK1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.d.mts","sourceRoot":"","sources":["../../../impl/patch.mts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,QAAA,MAAM,eAAe;;iBAIiB,CAAA;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC;;;;;EAwB7C,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;
|
|
1
|
+
{"version":3,"file":"patch.d.mts","sourceRoot":"","sources":["../../../impl/patch.mts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,QAAA,MAAM,eAAe;;iBAIiB,CAAA;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK,GAChB,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,aAAa,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC;;;;;EAwB7C,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,gBAAgB,EAC7B,IAAI,MAAM,EACV,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;EAsEpC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const shouldRetryError: (error: unknown,
|
|
1
|
+
export declare const shouldRetryError: (error: unknown, authRetryCount: number, maxAuthRetries?: number) => boolean;
|
|
2
2
|
/**
|
|
3
3
|
* Settings that control how retry attempts are scheduled.
|
|
4
4
|
*/
|
|
@@ -7,6 +7,10 @@ export interface RetryOptions {
|
|
|
7
7
|
* Maximum number of retry attempts before rethrowing the original error.
|
|
8
8
|
*/
|
|
9
9
|
maxRetries?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of retry attempts for transient 401/403 authentication errors.
|
|
12
|
+
*/
|
|
13
|
+
maxAuthRetries?: number;
|
|
10
14
|
/**
|
|
11
15
|
* Initial wait duration in milliseconds before attempting the first retry.
|
|
12
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.mts","sourceRoot":"","sources":["../../../impl/retry.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.d.mts","sourceRoot":"","sources":["../../../impl/retry.mts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB,GAC3B,OAAO,OAAO,EACd,gBAAgB,MAAM,EACtB,uBAAyC,YAO1C,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,KAAK,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzC;;;;;;GAMG;AAEH,wBAAgB,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAAC,GAAG,CAAC,EACxE,EAAE,EAAE,EAAE,EACN,OAAO,GAAE,YAAiB,GACzB,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAsC/D"}
|
|
@@ -19,7 +19,9 @@ export type ErrorOperation = 'get' | 'getAtRev' | 'getDBInfo' | 'headDB' | 'patc
|
|
|
19
19
|
export declare const hasStatusCode: (error: unknown) => error is {
|
|
20
20
|
statusCode: number;
|
|
21
21
|
};
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const DEFAULT_MAX_AUTH_RETRIES = 3;
|
|
23
|
+
export declare const isAuthError: (error: unknown) => boolean;
|
|
24
|
+
export declare const isTransientAuthError: (error: unknown, attempt: number, maxAuthRetries?: number) => boolean;
|
|
23
25
|
/**
|
|
24
26
|
* Shared structured fields available on hide-a-bed operational errors.
|
|
25
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../../../../impl/utils/errors.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGtE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAMD,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,aAAa,CAAA;AAEjB,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,UAAU,GACV,WAAW,GACX,QAAQ,GACR,OAAO,GACP,kBAAkB,GAClB,KAAK,GACL,MAAM,GACN,OAAO,GACP,aAAa,GACb,QAAQ,GACR,SAAS,GACT,WAAW,CAAA;AA0Cf,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI;IAAE,UAAU,EAAE,MAAM,CAAA;CAE3E,CAAA;AAED,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../../../../impl/utils/errors.mts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAGtE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB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,SAAQ,aAAa;gBAE7C,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC,GAAG;QACtF,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC,CAAA;KACtD;IAeR;;;;;;OAMG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,IAAI,MAAM;IAKlF;;;;;;;OAOG;IACH,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,GAAE,cAA0B,GAAG,KAAK;CAgBtF;AAED,KAAK,oBAAoB,GAAG;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,cAAc,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAYD,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,cAAc,EACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,UAAU,EACX,EAAE,oBAAoB,GAAG,aAAa,CAwCtC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKrD"}
|
|
@@ -19,6 +19,7 @@ export declare const CouchConfig: z.ZodObject<{
|
|
|
19
19
|
couch: z.ZodCustom<string | URL, string | URL>;
|
|
20
20
|
initialDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
21
21
|
logger: z.ZodOptional<z.ZodCustom<ConfigLogger, ConfigLogger>>;
|
|
22
|
+
maxAuthRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
22
23
|
maxRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
23
24
|
request: z.ZodOptional<z.ZodType<RequestOptions, RequestOptions, z.core.$ZodTypeInternals<RequestOptions, RequestOptions>>>;
|
|
24
25
|
throwOnGetNotFound: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../schema/config.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.mts","sourceRoot":"","sources":["../../../schema/config.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAChD,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;AACtF,KAAK,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,YAAY,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAC7E,KAAK,YAAY,GAAG,YAAY,GAAG,cAAc,CAAA;AA2BjD,eAAO,MAAM,SAAS;;;kBAGpB,CAAA;AAWF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;kBAoCY,CAAA;AAEpC,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,SAAS,CAAC,CAAA;AACtE,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAA;AAC1E,MAAM,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,WAAW,CAAC,CAAA;AAC1E,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAA"}
|