@doist/todoist-api-typescript 6.1.11 → 6.1.12
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.
|
@@ -45,7 +45,8 @@ function headersToObject(headers) {
|
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* Creates an AbortSignal that
|
|
48
|
+
* Creates an AbortSignal that aborts after timeoutMs. Returns the signal and a
|
|
49
|
+
* clear function to cancel the timeout early.
|
|
49
50
|
*/
|
|
50
51
|
function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
51
52
|
const controller = new AbortController();
|
|
@@ -53,6 +54,9 @@ function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
|
53
54
|
const timeoutId = setTimeout(() => {
|
|
54
55
|
controller.abort(new Error(`Request timeout after ${timeoutMs}ms`));
|
|
55
56
|
}, timeoutMs);
|
|
57
|
+
function clear() {
|
|
58
|
+
clearTimeout(timeoutId);
|
|
59
|
+
}
|
|
56
60
|
// If there's an existing signal, forward its abort
|
|
57
61
|
if (existingSignal) {
|
|
58
62
|
if (existingSignal.aborted) {
|
|
@@ -70,7 +74,7 @@ function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
|
70
74
|
controller.signal.addEventListener('abort', () => {
|
|
71
75
|
clearTimeout(timeoutId);
|
|
72
76
|
});
|
|
73
|
-
return controller.signal;
|
|
77
|
+
return { signal: controller.signal, clear };
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* Converts native fetch Response to CustomFetchResponse for consistency
|
|
@@ -96,11 +100,15 @@ async function fetchWithRetry(args) {
|
|
|
96
100
|
const { timeout, signal: userSignal } = options, fetchOptions = __rest(options, ["timeout", "signal"]);
|
|
97
101
|
let lastError;
|
|
98
102
|
for (let attempt = 0; attempt <= config.retries; attempt++) {
|
|
103
|
+
// Timeout clear function for this attempt (hoisted for catch scope)
|
|
104
|
+
let clearTimeoutFn;
|
|
99
105
|
try {
|
|
100
106
|
// Set up timeout and signal handling
|
|
101
107
|
let requestSignal = userSignal || undefined;
|
|
102
108
|
if (timeout && timeout > 0) {
|
|
103
|
-
|
|
109
|
+
const timeoutResult = createTimeoutSignal(timeout, requestSignal);
|
|
110
|
+
requestSignal = timeoutResult.signal;
|
|
111
|
+
clearTimeoutFn = timeoutResult.clear;
|
|
104
112
|
}
|
|
105
113
|
// Use custom fetch or native fetch
|
|
106
114
|
let fetchResponse;
|
|
@@ -153,6 +161,10 @@ async function fetchWithRetry(args) {
|
|
|
153
161
|
// If JSON parsing fails, return the raw text
|
|
154
162
|
data = responseText;
|
|
155
163
|
}
|
|
164
|
+
// Success – clear pending timeout (if any) so Node can exit promptly
|
|
165
|
+
if (clearTimeoutFn) {
|
|
166
|
+
clearTimeoutFn();
|
|
167
|
+
}
|
|
156
168
|
return {
|
|
157
169
|
data,
|
|
158
170
|
status: fetchResponse.status,
|
|
@@ -170,6 +182,9 @@ async function fetchWithRetry(args) {
|
|
|
170
182
|
const networkError = lastError;
|
|
171
183
|
networkError.isNetworkError = true;
|
|
172
184
|
}
|
|
185
|
+
if (clearTimeoutFn) {
|
|
186
|
+
clearTimeoutFn();
|
|
187
|
+
}
|
|
173
188
|
throw lastError;
|
|
174
189
|
}
|
|
175
190
|
// Wait before retrying
|
|
@@ -177,6 +192,10 @@ async function fetchWithRetry(args) {
|
|
|
177
192
|
if (delay > 0) {
|
|
178
193
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
179
194
|
}
|
|
195
|
+
// Retry path – ensure this attempt's timeout is cleared before looping
|
|
196
|
+
if (clearTimeoutFn) {
|
|
197
|
+
clearTimeoutFn();
|
|
198
|
+
}
|
|
180
199
|
}
|
|
181
200
|
}
|
|
182
201
|
// This should never be reached, but just in case
|
|
@@ -42,7 +42,8 @@ function headersToObject(headers) {
|
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Creates an AbortSignal that
|
|
45
|
+
* Creates an AbortSignal that aborts after timeoutMs. Returns the signal and a
|
|
46
|
+
* clear function to cancel the timeout early.
|
|
46
47
|
*/
|
|
47
48
|
function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
48
49
|
const controller = new AbortController();
|
|
@@ -50,6 +51,9 @@ function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
|
50
51
|
const timeoutId = setTimeout(() => {
|
|
51
52
|
controller.abort(new Error(`Request timeout after ${timeoutMs}ms`));
|
|
52
53
|
}, timeoutMs);
|
|
54
|
+
function clear() {
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
}
|
|
53
57
|
// If there's an existing signal, forward its abort
|
|
54
58
|
if (existingSignal) {
|
|
55
59
|
if (existingSignal.aborted) {
|
|
@@ -67,7 +71,7 @@ function createTimeoutSignal(timeoutMs, existingSignal) {
|
|
|
67
71
|
controller.signal.addEventListener('abort', () => {
|
|
68
72
|
clearTimeout(timeoutId);
|
|
69
73
|
});
|
|
70
|
-
return controller.signal;
|
|
74
|
+
return { signal: controller.signal, clear };
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
77
|
* Converts native fetch Response to CustomFetchResponse for consistency
|
|
@@ -93,11 +97,15 @@ export async function fetchWithRetry(args) {
|
|
|
93
97
|
const { timeout, signal: userSignal } = options, fetchOptions = __rest(options, ["timeout", "signal"]);
|
|
94
98
|
let lastError;
|
|
95
99
|
for (let attempt = 0; attempt <= config.retries; attempt++) {
|
|
100
|
+
// Timeout clear function for this attempt (hoisted for catch scope)
|
|
101
|
+
let clearTimeoutFn;
|
|
96
102
|
try {
|
|
97
103
|
// Set up timeout and signal handling
|
|
98
104
|
let requestSignal = userSignal || undefined;
|
|
99
105
|
if (timeout && timeout > 0) {
|
|
100
|
-
|
|
106
|
+
const timeoutResult = createTimeoutSignal(timeout, requestSignal);
|
|
107
|
+
requestSignal = timeoutResult.signal;
|
|
108
|
+
clearTimeoutFn = timeoutResult.clear;
|
|
101
109
|
}
|
|
102
110
|
// Use custom fetch or native fetch
|
|
103
111
|
let fetchResponse;
|
|
@@ -150,6 +158,10 @@ export async function fetchWithRetry(args) {
|
|
|
150
158
|
// If JSON parsing fails, return the raw text
|
|
151
159
|
data = responseText;
|
|
152
160
|
}
|
|
161
|
+
// Success – clear pending timeout (if any) so Node can exit promptly
|
|
162
|
+
if (clearTimeoutFn) {
|
|
163
|
+
clearTimeoutFn();
|
|
164
|
+
}
|
|
153
165
|
return {
|
|
154
166
|
data,
|
|
155
167
|
status: fetchResponse.status,
|
|
@@ -167,6 +179,9 @@ export async function fetchWithRetry(args) {
|
|
|
167
179
|
const networkError = lastError;
|
|
168
180
|
networkError.isNetworkError = true;
|
|
169
181
|
}
|
|
182
|
+
if (clearTimeoutFn) {
|
|
183
|
+
clearTimeoutFn();
|
|
184
|
+
}
|
|
170
185
|
throw lastError;
|
|
171
186
|
}
|
|
172
187
|
// Wait before retrying
|
|
@@ -174,6 +189,10 @@ export async function fetchWithRetry(args) {
|
|
|
174
189
|
if (delay > 0) {
|
|
175
190
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
176
191
|
}
|
|
192
|
+
// Retry path – ensure this attempt's timeout is cleared before looping
|
|
193
|
+
if (clearTimeoutFn) {
|
|
194
|
+
clearTimeoutFn();
|
|
195
|
+
}
|
|
177
196
|
}
|
|
178
197
|
}
|
|
179
198
|
// This should never be reached, but just in case
|
package/package.json
CHANGED