@rendobar/sdk 5.4.0 → 5.5.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/dist/index.cjs +18 -3
- package/dist/index.d.cts +16 -1
- package/dist/index.d.mts +16 -1
- package/dist/index.mjs +18 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -181,16 +181,31 @@ const TERMINAL_JOB_STATUSES$1 = /* @__PURE__ */ new Set([
|
|
|
181
181
|
"failed",
|
|
182
182
|
"cancelled"
|
|
183
183
|
]);
|
|
184
|
+
/** Wait bound used until the server reports the job's own budget, and the floor. */
|
|
185
|
+
const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
|
|
186
|
+
/** Headroom past the execution budget for upload + terminal callback delivery. */
|
|
187
|
+
const WAIT_GRACE_MS = 12e4;
|
|
184
188
|
function createJobsResource(request) {
|
|
185
189
|
async function wait(id, options = {}) {
|
|
186
|
-
const { timeout
|
|
187
|
-
const
|
|
190
|
+
const { timeout, interval = 2e3, maxInterval = 1e4, onProgress, signal, throwOnFailure = false } = options;
|
|
191
|
+
const waitStartedAt = Date.now();
|
|
192
|
+
let effectiveTimeout = timeout ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
193
|
+
let deadline = waitStartedAt + effectiveTimeout;
|
|
194
|
+
let adoptedJobBudget = false;
|
|
188
195
|
let currentInterval = interval;
|
|
189
196
|
while (Date.now() < deadline) {
|
|
190
197
|
if (signal?.aborted) throw new DOMException("Wait aborted", "AbortError");
|
|
191
198
|
const job = await request(`/jobs/${id}`, { signal });
|
|
192
199
|
onProgress?.(job);
|
|
193
200
|
if (TERMINAL_JOB_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
201
|
+
if (timeout === void 0 && !adoptedJobBudget && typeof job.timeoutMs === "number") {
|
|
202
|
+
adoptedJobBudget = true;
|
|
203
|
+
const budgetDeadline = waitStartedAt + job.timeoutMs + WAIT_GRACE_MS;
|
|
204
|
+
if (budgetDeadline > deadline) {
|
|
205
|
+
deadline = budgetDeadline;
|
|
206
|
+
effectiveTimeout = deadline - waitStartedAt;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
194
209
|
const remaining = deadline - Date.now();
|
|
195
210
|
const delay = Math.min(currentInterval, remaining);
|
|
196
211
|
if (delay <= 0) break;
|
|
@@ -200,7 +215,7 @@ function createJobsResource(request) {
|
|
|
200
215
|
const job = await request(`/jobs/${id}`, { signal });
|
|
201
216
|
onProgress?.(job);
|
|
202
217
|
if (TERMINAL_JOB_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
203
|
-
throw new WaitTimeoutError(id, job.status,
|
|
218
|
+
throw new WaitTimeoutError(id, job.status, effectiveTimeout);
|
|
204
219
|
}
|
|
205
220
|
async function create(params, options) {
|
|
206
221
|
return request("/jobs", {
|
package/dist/index.d.cts
CHANGED
|
@@ -2298,6 +2298,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2298
2298
|
resourcesAvailable: ZodBoolean;
|
|
2299
2299
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2300
2300
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2301
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2301
2302
|
createdAt: ZodNumber;
|
|
2302
2303
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2303
2304
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2352,6 +2353,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2352
2353
|
resourcesAvailable: ZodBoolean;
|
|
2353
2354
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2354
2355
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2356
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2355
2357
|
createdAt: ZodNumber;
|
|
2356
2358
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2357
2359
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2415,6 +2417,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2415
2417
|
resourcesAvailable: ZodBoolean;
|
|
2416
2418
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2417
2419
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2420
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2418
2421
|
createdAt: ZodNumber;
|
|
2419
2422
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2420
2423
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2471,6 +2474,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2471
2474
|
resourcesAvailable: ZodBoolean;
|
|
2472
2475
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2473
2476
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2477
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2474
2478
|
createdAt: ZodNumber;
|
|
2475
2479
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2476
2480
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2571,6 +2575,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2571
2575
|
resourcesAvailable: ZodBoolean;
|
|
2572
2576
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2573
2577
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2578
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2574
2579
|
createdAt: ZodNumber;
|
|
2575
2580
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2576
2581
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2636,6 +2641,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2636
2641
|
resourcesAvailable: ZodBoolean;
|
|
2637
2642
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2638
2643
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2644
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2639
2645
|
createdAt: ZodNumber;
|
|
2640
2646
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2641
2647
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -3832,7 +3838,16 @@ type StatsParams = {
|
|
|
3832
3838
|
window?: "24h" | "7d" | "30d";
|
|
3833
3839
|
};
|
|
3834
3840
|
type WaitOptions = {
|
|
3835
|
-
/**
|
|
3841
|
+
/**
|
|
3842
|
+
* Max wait time in ms.
|
|
3843
|
+
*
|
|
3844
|
+
* Omit it and the wait follows the job's own execution budget (`job.timeoutMs`,
|
|
3845
|
+
* your plan's per-job limit) plus grace for upload and callback, so a long job
|
|
3846
|
+
* is not reported as timed out while it is still running. Until the server
|
|
3847
|
+
* reports that budget the bound is 5 minutes, which is also the floor.
|
|
3848
|
+
*
|
|
3849
|
+
* Pass a number to bound the wait yourself regardless of the job's budget.
|
|
3850
|
+
*/
|
|
3836
3851
|
timeout?: number;
|
|
3837
3852
|
/** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
3838
3853
|
interval?: number;
|
package/dist/index.d.mts
CHANGED
|
@@ -2298,6 +2298,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2298
2298
|
resourcesAvailable: ZodBoolean;
|
|
2299
2299
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2300
2300
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2301
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2301
2302
|
createdAt: ZodNumber;
|
|
2302
2303
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2303
2304
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2352,6 +2353,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2352
2353
|
resourcesAvailable: ZodBoolean;
|
|
2353
2354
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2354
2355
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2356
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2355
2357
|
createdAt: ZodNumber;
|
|
2356
2358
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2357
2359
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2415,6 +2417,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2415
2417
|
resourcesAvailable: ZodBoolean;
|
|
2416
2418
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2417
2419
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2420
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2418
2421
|
createdAt: ZodNumber;
|
|
2419
2422
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2420
2423
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2471,6 +2474,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2471
2474
|
resourcesAvailable: ZodBoolean;
|
|
2472
2475
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2473
2476
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2477
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2474
2478
|
createdAt: ZodNumber;
|
|
2475
2479
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2476
2480
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2571,6 +2575,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2571
2575
|
resourcesAvailable: ZodBoolean;
|
|
2572
2576
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2573
2577
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2578
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2574
2579
|
createdAt: ZodNumber;
|
|
2575
2580
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2576
2581
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2636,6 +2641,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2636
2641
|
resourcesAvailable: ZodBoolean;
|
|
2637
2642
|
metricsAvailable: ZodOptional<ZodBoolean>;
|
|
2638
2643
|
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2644
|
+
timeoutMs: ZodNullable<ZodNumber>;
|
|
2639
2645
|
createdAt: ZodNumber;
|
|
2640
2646
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2641
2647
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -3832,7 +3838,16 @@ type StatsParams = {
|
|
|
3832
3838
|
window?: "24h" | "7d" | "30d";
|
|
3833
3839
|
};
|
|
3834
3840
|
type WaitOptions = {
|
|
3835
|
-
/**
|
|
3841
|
+
/**
|
|
3842
|
+
* Max wait time in ms.
|
|
3843
|
+
*
|
|
3844
|
+
* Omit it and the wait follows the job's own execution budget (`job.timeoutMs`,
|
|
3845
|
+
* your plan's per-job limit) plus grace for upload and callback, so a long job
|
|
3846
|
+
* is not reported as timed out while it is still running. Until the server
|
|
3847
|
+
* reports that budget the bound is 5 minutes, which is also the floor.
|
|
3848
|
+
*
|
|
3849
|
+
* Pass a number to bound the wait yourself regardless of the job's budget.
|
|
3850
|
+
*/
|
|
3836
3851
|
timeout?: number;
|
|
3837
3852
|
/** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
3838
3853
|
interval?: number;
|
package/dist/index.mjs
CHANGED
|
@@ -180,16 +180,31 @@ const TERMINAL_JOB_STATUSES$1 = /* @__PURE__ */ new Set([
|
|
|
180
180
|
"failed",
|
|
181
181
|
"cancelled"
|
|
182
182
|
]);
|
|
183
|
+
/** Wait bound used until the server reports the job's own budget, and the floor. */
|
|
184
|
+
const DEFAULT_WAIT_TIMEOUT_MS = 3e5;
|
|
185
|
+
/** Headroom past the execution budget for upload + terminal callback delivery. */
|
|
186
|
+
const WAIT_GRACE_MS = 12e4;
|
|
183
187
|
function createJobsResource(request) {
|
|
184
188
|
async function wait(id, options = {}) {
|
|
185
|
-
const { timeout
|
|
186
|
-
const
|
|
189
|
+
const { timeout, interval = 2e3, maxInterval = 1e4, onProgress, signal, throwOnFailure = false } = options;
|
|
190
|
+
const waitStartedAt = Date.now();
|
|
191
|
+
let effectiveTimeout = timeout ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
192
|
+
let deadline = waitStartedAt + effectiveTimeout;
|
|
193
|
+
let adoptedJobBudget = false;
|
|
187
194
|
let currentInterval = interval;
|
|
188
195
|
while (Date.now() < deadline) {
|
|
189
196
|
if (signal?.aborted) throw new DOMException("Wait aborted", "AbortError");
|
|
190
197
|
const job = await request(`/jobs/${id}`, { signal });
|
|
191
198
|
onProgress?.(job);
|
|
192
199
|
if (TERMINAL_JOB_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
200
|
+
if (timeout === void 0 && !adoptedJobBudget && typeof job.timeoutMs === "number") {
|
|
201
|
+
adoptedJobBudget = true;
|
|
202
|
+
const budgetDeadline = waitStartedAt + job.timeoutMs + WAIT_GRACE_MS;
|
|
203
|
+
if (budgetDeadline > deadline) {
|
|
204
|
+
deadline = budgetDeadline;
|
|
205
|
+
effectiveTimeout = deadline - waitStartedAt;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
193
208
|
const remaining = deadline - Date.now();
|
|
194
209
|
const delay = Math.min(currentInterval, remaining);
|
|
195
210
|
if (delay <= 0) break;
|
|
@@ -199,7 +214,7 @@ function createJobsResource(request) {
|
|
|
199
214
|
const job = await request(`/jobs/${id}`, { signal });
|
|
200
215
|
onProgress?.(job);
|
|
201
216
|
if (TERMINAL_JOB_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
202
|
-
throw new WaitTimeoutError(id, job.status,
|
|
217
|
+
throw new WaitTimeoutError(id, job.status, effectiveTimeout);
|
|
203
218
|
}
|
|
204
219
|
async function create(params, options) {
|
|
205
220
|
return request("/jobs", {
|