@rendobar/sdk 3.0.1 → 3.2.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 +69 -5
- package/dist/index.d.cts +70 -7
- package/dist/index.d.mts +70 -7
- package/dist/index.mjs +68 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,32 @@ var ApiError = class extends Error {
|
|
|
18
18
|
function isApiError(error) {
|
|
19
19
|
return error instanceof ApiError;
|
|
20
20
|
}
|
|
21
|
+
/** Thrown by jobs.wait() when the deadline passes before the job reaches a terminal state. */
|
|
22
|
+
var WaitTimeoutError = class extends Error {
|
|
23
|
+
jobId;
|
|
24
|
+
lastStatus;
|
|
25
|
+
timeoutMs;
|
|
26
|
+
constructor(jobId, lastStatus, timeoutMs) {
|
|
27
|
+
super(`Job ${jobId} did not complete within ${timeoutMs}ms (last status: ${lastStatus}). It may still be queued — check the dashboard or retry.`);
|
|
28
|
+
this.name = "WaitTimeoutError";
|
|
29
|
+
this.jobId = jobId;
|
|
30
|
+
this.lastStatus = lastStatus;
|
|
31
|
+
this.timeoutMs = timeoutMs;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** Thrown by jobs.wait({ throwOnFailure: true }) when the job ends failed/cancelled. */
|
|
35
|
+
var JobFailedError = class extends Error {
|
|
36
|
+
jobId;
|
|
37
|
+
status;
|
|
38
|
+
job;
|
|
39
|
+
constructor(jobId, status, job, detail) {
|
|
40
|
+
super(`Job ${jobId} ended with status "${status}"${detail ? `: ${detail}` : ""}.`);
|
|
41
|
+
this.name = "JobFailedError";
|
|
42
|
+
this.jobId = jobId;
|
|
43
|
+
this.status = status;
|
|
44
|
+
this.job = job;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
21
47
|
//#endregion
|
|
22
48
|
//#region src/lib/request.ts
|
|
23
49
|
/**
|
|
@@ -183,21 +209,24 @@ function createJobsResource(request) {
|
|
|
183
209
|
}
|
|
184
210
|
},
|
|
185
211
|
async wait(id, options = {}) {
|
|
186
|
-
const { timeout = 3e5, interval = 2e3, onProgress, signal } = options;
|
|
212
|
+
const { timeout = 3e5, interval = 2e3, maxInterval = 1e4, onProgress, signal, throwOnFailure = false } = options;
|
|
187
213
|
const deadline = Date.now() + timeout;
|
|
214
|
+
let currentInterval = interval;
|
|
188
215
|
while (Date.now() < deadline) {
|
|
189
216
|
if (signal?.aborted) throw new DOMException("Wait aborted", "AbortError");
|
|
190
217
|
const job = await request(`/jobs/${id}`, { signal });
|
|
191
218
|
onProgress?.(job);
|
|
192
|
-
if (TERMINAL_STATUSES$1.has(job.status)) return job;
|
|
219
|
+
if (TERMINAL_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
193
220
|
const remaining = deadline - Date.now();
|
|
194
|
-
const delay = Math.min(
|
|
221
|
+
const delay = Math.min(currentInterval, remaining);
|
|
195
222
|
if (delay <= 0) break;
|
|
196
223
|
await sleep(delay, signal);
|
|
224
|
+
currentInterval = Math.min(currentInterval * 1.5, maxInterval);
|
|
197
225
|
}
|
|
198
226
|
const job = await request(`/jobs/${id}`, { signal });
|
|
199
|
-
|
|
200
|
-
|
|
227
|
+
onProgress?.(job);
|
|
228
|
+
if (TERMINAL_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
229
|
+
throw new WaitTimeoutError(id, job.status, timeout);
|
|
201
230
|
},
|
|
202
231
|
async cancel(id, options) {
|
|
203
232
|
return request(`/jobs/${id}/cancel`, {
|
|
@@ -222,6 +251,21 @@ function createJobsResource(request) {
|
|
|
222
251
|
}
|
|
223
252
|
};
|
|
224
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Handle a terminal job result: throw JobFailedError when throwOnFailure is
|
|
256
|
+
* set and the status is failed/cancelled; otherwise return the job.
|
|
257
|
+
*
|
|
258
|
+
* Narrowing on `status === "failed"` before reading `job.error` is required
|
|
259
|
+
* because `error` is only present on the "failed" variant of the discriminated
|
|
260
|
+
* union — the compiler won't allow access without narrowing first.
|
|
261
|
+
*/
|
|
262
|
+
function resolveTerminal(id, job, throwOnFailure) {
|
|
263
|
+
if (throwOnFailure && (job.status === "failed" || job.status === "cancelled")) {
|
|
264
|
+
const detail = job.status === "failed" ? job.error.message : void 0;
|
|
265
|
+
throw new JobFailedError(id, job.status, job, detail);
|
|
266
|
+
}
|
|
267
|
+
return job;
|
|
268
|
+
}
|
|
225
269
|
function sleep(ms, signal) {
|
|
226
270
|
return new Promise((resolve, reject) => {
|
|
227
271
|
if (signal?.aborted) {
|
|
@@ -575,6 +619,16 @@ function createOrgsResource(request) {
|
|
|
575
619
|
method: "DELETE",
|
|
576
620
|
signal: options?.signal
|
|
577
621
|
});
|
|
622
|
+
},
|
|
623
|
+
async getSettings(options) {
|
|
624
|
+
return request("/orgs/current/settings", { signal: options?.signal });
|
|
625
|
+
},
|
|
626
|
+
async updateSettings(body, options) {
|
|
627
|
+
return request("/orgs/current/settings", {
|
|
628
|
+
method: "PATCH",
|
|
629
|
+
body,
|
|
630
|
+
signal: options?.signal
|
|
631
|
+
});
|
|
578
632
|
}
|
|
579
633
|
};
|
|
580
634
|
}
|
|
@@ -699,6 +753,8 @@ const KNOWN_EVENT_TYPES = new Set([
|
|
|
699
753
|
"job.progress",
|
|
700
754
|
"job.step",
|
|
701
755
|
"job.log",
|
|
756
|
+
"job.metrics",
|
|
757
|
+
"job.context",
|
|
702
758
|
"balance.updated",
|
|
703
759
|
"subscription.updated",
|
|
704
760
|
"notification",
|
|
@@ -787,6 +843,12 @@ function dispatchJobEvent(event, options) {
|
|
|
787
843
|
case "job.result":
|
|
788
844
|
options.onResult?.(event);
|
|
789
845
|
break;
|
|
846
|
+
case "job.metrics":
|
|
847
|
+
options.onMetrics?.(event);
|
|
848
|
+
break;
|
|
849
|
+
case "job.context":
|
|
850
|
+
options.onContext?.(event);
|
|
851
|
+
break;
|
|
790
852
|
}
|
|
791
853
|
}
|
|
792
854
|
//#endregion
|
|
@@ -851,6 +913,8 @@ function jobData(job) {
|
|
|
851
913
|
}
|
|
852
914
|
//#endregion
|
|
853
915
|
exports.ApiError = ApiError;
|
|
916
|
+
exports.JobFailedError = JobFailedError;
|
|
917
|
+
exports.WaitTimeoutError = WaitTimeoutError;
|
|
854
918
|
exports.createClient = createClient;
|
|
855
919
|
exports.isApiError = isApiError;
|
|
856
920
|
exports.jobData = jobData;
|
package/dist/index.d.cts
CHANGED
|
@@ -2269,6 +2269,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2269
2269
|
error: ZodOptional<ZodString>;
|
|
2270
2270
|
}, $strip>>;
|
|
2271
2271
|
logsAvailable: ZodBoolean;
|
|
2272
|
+
metricsAvailable: ZodBoolean;
|
|
2273
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2272
2274
|
createdAt: ZodNumber;
|
|
2273
2275
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2274
2276
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2305,6 +2307,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2305
2307
|
error: ZodOptional<ZodString>;
|
|
2306
2308
|
}, $strip>>;
|
|
2307
2309
|
logsAvailable: ZodBoolean;
|
|
2310
|
+
metricsAvailable: ZodBoolean;
|
|
2311
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2308
2312
|
createdAt: ZodNumber;
|
|
2309
2313
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2310
2314
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2343,6 +2347,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2343
2347
|
error: ZodOptional<ZodString>;
|
|
2344
2348
|
}, $strip>>;
|
|
2345
2349
|
logsAvailable: ZodBoolean;
|
|
2350
|
+
metricsAvailable: ZodBoolean;
|
|
2351
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2346
2352
|
createdAt: ZodNumber;
|
|
2347
2353
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2348
2354
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2381,6 +2387,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2381
2387
|
error: ZodOptional<ZodString>;
|
|
2382
2388
|
}, $strip>>;
|
|
2383
2389
|
logsAvailable: ZodBoolean;
|
|
2390
|
+
metricsAvailable: ZodBoolean;
|
|
2391
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2384
2392
|
createdAt: ZodNumber;
|
|
2385
2393
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2386
2394
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2461,6 +2469,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2461
2469
|
error: ZodOptional<ZodString>;
|
|
2462
2470
|
}, $strip>>;
|
|
2463
2471
|
logsAvailable: ZodBoolean;
|
|
2472
|
+
metricsAvailable: ZodBoolean;
|
|
2473
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2464
2474
|
createdAt: ZodNumber;
|
|
2465
2475
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2466
2476
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2503,6 +2513,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2503
2513
|
error: ZodOptional<ZodString>;
|
|
2504
2514
|
}, $strip>>;
|
|
2505
2515
|
logsAvailable: ZodBoolean;
|
|
2516
|
+
metricsAvailable: ZodBoolean;
|
|
2517
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2506
2518
|
createdAt: ZodNumber;
|
|
2507
2519
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2508
2520
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2520,7 +2532,7 @@ declare const jobTypeSchema: ZodObject<{
|
|
|
2520
2532
|
summary: ZodString;
|
|
2521
2533
|
needs: ZodArray<ZodString>;
|
|
2522
2534
|
pattern: ZodNullable<ZodString>;
|
|
2523
|
-
|
|
2535
|
+
runner: ZodOptional<ZodObject<{
|
|
2524
2536
|
id: ZodString;
|
|
2525
2537
|
resource: ZodString;
|
|
2526
2538
|
}, $strip>>;
|
|
@@ -2782,6 +2794,12 @@ declare const assetListMetaSchema: ZodObject<{
|
|
|
2782
2794
|
limit: ZodNumber;
|
|
2783
2795
|
offset: ZodNumber;
|
|
2784
2796
|
}, $strip>;
|
|
2797
|
+
declare const orgSettingsResponseSchema: ZodObject<{
|
|
2798
|
+
billingEmailsEnabled: ZodBoolean;
|
|
2799
|
+
defaultRegion: ZodString;
|
|
2800
|
+
regionPinned: ZodBoolean;
|
|
2801
|
+
}, $strip>;
|
|
2802
|
+
type OrgSettings = output<typeof orgSettingsResponseSchema>;
|
|
2785
2803
|
type JobResponse = output<typeof jobResponseSchema>;
|
|
2786
2804
|
type JobStep = output<typeof jobStepSchema>;
|
|
2787
2805
|
type Output = output<typeof jobOutputSchema>;
|
|
@@ -2866,6 +2884,19 @@ declare const orgEventSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2866
2884
|
stepProgress: ZodOptional<ZodNumber>;
|
|
2867
2885
|
eta: ZodOptional<ZodNumber>;
|
|
2868
2886
|
metrics: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodNumber, ZodString]>>>;
|
|
2887
|
+
}, $strip>, ZodObject<{
|
|
2888
|
+
type: ZodLiteral<"job.metrics">;
|
|
2889
|
+
jobId: ZodString;
|
|
2890
|
+
timestamp: ZodNumber;
|
|
2891
|
+
cpuPct: ZodNumber;
|
|
2892
|
+
cpuCores: ZodNumber;
|
|
2893
|
+
allocatedCores: ZodOptional<ZodNumber>;
|
|
2894
|
+
memUsedMB: ZodNumber;
|
|
2895
|
+
memLimitMB: ZodNumber;
|
|
2896
|
+
diskRMBps: ZodOptional<ZodNumber>;
|
|
2897
|
+
diskWMBps: ZodOptional<ZodNumber>;
|
|
2898
|
+
netRxMBps: ZodOptional<ZodNumber>;
|
|
2899
|
+
netTxMBps: ZodOptional<ZodNumber>;
|
|
2869
2900
|
}, $strip>, ZodObject<{
|
|
2870
2901
|
type: ZodLiteral<"job.step">;
|
|
2871
2902
|
jobId: ZodString;
|
|
@@ -2902,10 +2933,10 @@ declare const orgEventSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2902
2933
|
}, $strip>], "type">;
|
|
2903
2934
|
type OrgEvent = output<typeof orgEventSchema>;
|
|
2904
2935
|
/**
|
|
2905
|
-
* Log entry data structure used by dashboard hooks and
|
|
2936
|
+
* Log entry data structure used by dashboard hooks and runner.
|
|
2906
2937
|
* Import from `@rendobar/shared/events/org-events`.
|
|
2907
2938
|
*
|
|
2908
|
-
* Matches
|
|
2939
|
+
* Matches runner's log event format.
|
|
2909
2940
|
*/
|
|
2910
2941
|
interface LogEntryData {
|
|
2911
2942
|
timestamp: number;
|
|
@@ -2949,7 +2980,7 @@ declare function jobData<T>(job: JobResponse): T | null;
|
|
|
2949
2980
|
* Per-job execution timing breakdown. Returned by `client.jobs.getTimings(id)`.
|
|
2950
2981
|
*
|
|
2951
2982
|
* All values are milliseconds, or `null` if the corresponding stage did not
|
|
2952
|
-
* execute (e.g. a sync-completed job has no
|
|
2983
|
+
* execute (e.g. a sync-completed job has no runner or queue timings).
|
|
2953
2984
|
*/
|
|
2954
2985
|
interface JobTimings {
|
|
2955
2986
|
jobId: string;
|
|
@@ -3159,6 +3190,12 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3159
3190
|
delete(options?: {
|
|
3160
3191
|
signal?: AbortSignal;
|
|
3161
3192
|
}): Promise<void>;
|
|
3193
|
+
getSettings(options?: {
|
|
3194
|
+
signal?: AbortSignal;
|
|
3195
|
+
}): Promise<OrgSettings>;
|
|
3196
|
+
updateSettings(body: Partial<Pick<OrgSettings, "billingEmailsEnabled" | "defaultRegion" | "regionPinned">>, options?: {
|
|
3197
|
+
signal?: AbortSignal;
|
|
3198
|
+
}): Promise<OrgSettings>;
|
|
3162
3199
|
};
|
|
3163
3200
|
batches: {
|
|
3164
3201
|
create(params: {
|
|
@@ -3247,6 +3284,20 @@ declare class ApiError extends Error {
|
|
|
3247
3284
|
constructor(code: string, statusCode: number, message: string, details?: Record<string, unknown> | undefined, retryAfter?: number | undefined);
|
|
3248
3285
|
}
|
|
3249
3286
|
declare function isApiError(error: unknown): error is ApiError;
|
|
3287
|
+
/** Thrown by jobs.wait() when the deadline passes before the job reaches a terminal state. */
|
|
3288
|
+
declare class WaitTimeoutError extends Error {
|
|
3289
|
+
readonly jobId: string;
|
|
3290
|
+
readonly lastStatus: string;
|
|
3291
|
+
readonly timeoutMs: number;
|
|
3292
|
+
constructor(jobId: string, lastStatus: string, timeoutMs: number);
|
|
3293
|
+
}
|
|
3294
|
+
/** Thrown by jobs.wait({ throwOnFailure: true }) when the job ends failed/cancelled. */
|
|
3295
|
+
declare class JobFailedError extends Error {
|
|
3296
|
+
readonly jobId: string;
|
|
3297
|
+
readonly status: string;
|
|
3298
|
+
readonly job: unknown;
|
|
3299
|
+
constructor(jobId: string, status: string, job: unknown, detail?: string);
|
|
3300
|
+
}
|
|
3250
3301
|
//#endregion
|
|
3251
3302
|
//#region src/realtime/client.d.ts
|
|
3252
3303
|
interface RealtimeConnectOptions {
|
|
@@ -3278,6 +3329,12 @@ interface JobSubscribeOptions {
|
|
|
3278
3329
|
onComplete?: (event: Extract<OrgEvent, {
|
|
3279
3330
|
type: "job.status";
|
|
3280
3331
|
}>) => void;
|
|
3332
|
+
onMetrics?: (event: Extract<OrgEvent, {
|
|
3333
|
+
type: "job.metrics";
|
|
3334
|
+
}>) => void;
|
|
3335
|
+
onContext?: (event: Extract<OrgEvent, {
|
|
3336
|
+
type: "job.context";
|
|
3337
|
+
}>) => void;
|
|
3281
3338
|
onError?: (error: Error) => void;
|
|
3282
3339
|
}
|
|
3283
3340
|
interface JobSubscription {
|
|
@@ -3323,10 +3380,16 @@ type ListJobsParams = {
|
|
|
3323
3380
|
offset?: number;
|
|
3324
3381
|
};
|
|
3325
3382
|
type WaitOptions = {
|
|
3326
|
-
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /**
|
|
3327
|
-
interval?: number; /**
|
|
3383
|
+
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
3384
|
+
interval?: number; /** Cap for the backoff poll interval in ms. Default: 10_000. */
|
|
3385
|
+
maxInterval?: number; /** Called on each poll with the latest job state. */
|
|
3328
3386
|
onProgress?: (job: JobResponse) => void; /** Abort signal for cancellation. */
|
|
3329
3387
|
signal?: AbortSignal;
|
|
3388
|
+
/**
|
|
3389
|
+
* When true, throw JobFailedError if the job ends with status "failed" or "cancelled".
|
|
3390
|
+
* Default: false (returns the terminal job, preserving existing behavior).
|
|
3391
|
+
*/
|
|
3392
|
+
throwOnFailure?: boolean;
|
|
3330
3393
|
};
|
|
3331
3394
|
type JobListPage = {
|
|
3332
3395
|
data: JobResponse[];
|
|
@@ -3426,4 +3489,4 @@ type AssetListPage = {
|
|
|
3426
3489
|
meta: AssetListMeta;
|
|
3427
3490
|
};
|
|
3428
3491
|
//#endregion
|
|
3429
|
-
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BatchResult, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCreatedResponse, type JobError, type JobListPage, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, type WebhookDelivery, type WebhookEndpoint, createClient, isApiError, jobData, outputUrl };
|
|
3492
|
+
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BatchResult, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCreatedResponse, type JobError, JobFailedError, type JobListPage, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type OrgSettings, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, WaitTimeoutError, type WebhookDelivery, type WebhookEndpoint, createClient, isApiError, jobData, outputUrl };
|
package/dist/index.d.mts
CHANGED
|
@@ -2269,6 +2269,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2269
2269
|
error: ZodOptional<ZodString>;
|
|
2270
2270
|
}, $strip>>;
|
|
2271
2271
|
logsAvailable: ZodBoolean;
|
|
2272
|
+
metricsAvailable: ZodBoolean;
|
|
2273
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2272
2274
|
createdAt: ZodNumber;
|
|
2273
2275
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2274
2276
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2305,6 +2307,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2305
2307
|
error: ZodOptional<ZodString>;
|
|
2306
2308
|
}, $strip>>;
|
|
2307
2309
|
logsAvailable: ZodBoolean;
|
|
2310
|
+
metricsAvailable: ZodBoolean;
|
|
2311
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2308
2312
|
createdAt: ZodNumber;
|
|
2309
2313
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2310
2314
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2343,6 +2347,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2343
2347
|
error: ZodOptional<ZodString>;
|
|
2344
2348
|
}, $strip>>;
|
|
2345
2349
|
logsAvailable: ZodBoolean;
|
|
2350
|
+
metricsAvailable: ZodBoolean;
|
|
2351
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2346
2352
|
createdAt: ZodNumber;
|
|
2347
2353
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2348
2354
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2381,6 +2387,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2381
2387
|
error: ZodOptional<ZodString>;
|
|
2382
2388
|
}, $strip>>;
|
|
2383
2389
|
logsAvailable: ZodBoolean;
|
|
2390
|
+
metricsAvailable: ZodBoolean;
|
|
2391
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2384
2392
|
createdAt: ZodNumber;
|
|
2385
2393
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2386
2394
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2461,6 +2469,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2461
2469
|
error: ZodOptional<ZodString>;
|
|
2462
2470
|
}, $strip>>;
|
|
2463
2471
|
logsAvailable: ZodBoolean;
|
|
2472
|
+
metricsAvailable: ZodBoolean;
|
|
2473
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2464
2474
|
createdAt: ZodNumber;
|
|
2465
2475
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2466
2476
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2503,6 +2513,8 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2503
2513
|
error: ZodOptional<ZodString>;
|
|
2504
2514
|
}, $strip>>;
|
|
2505
2515
|
logsAvailable: ZodBoolean;
|
|
2516
|
+
metricsAvailable: ZodBoolean;
|
|
2517
|
+
region: ZodOptional<ZodNullable<ZodString>>;
|
|
2506
2518
|
createdAt: ZodNumber;
|
|
2507
2519
|
dispatchedAt: ZodNullable<ZodNumber>;
|
|
2508
2520
|
startedAt: ZodNullable<ZodNumber>;
|
|
@@ -2520,7 +2532,7 @@ declare const jobTypeSchema: ZodObject<{
|
|
|
2520
2532
|
summary: ZodString;
|
|
2521
2533
|
needs: ZodArray<ZodString>;
|
|
2522
2534
|
pattern: ZodNullable<ZodString>;
|
|
2523
|
-
|
|
2535
|
+
runner: ZodOptional<ZodObject<{
|
|
2524
2536
|
id: ZodString;
|
|
2525
2537
|
resource: ZodString;
|
|
2526
2538
|
}, $strip>>;
|
|
@@ -2782,6 +2794,12 @@ declare const assetListMetaSchema: ZodObject<{
|
|
|
2782
2794
|
limit: ZodNumber;
|
|
2783
2795
|
offset: ZodNumber;
|
|
2784
2796
|
}, $strip>;
|
|
2797
|
+
declare const orgSettingsResponseSchema: ZodObject<{
|
|
2798
|
+
billingEmailsEnabled: ZodBoolean;
|
|
2799
|
+
defaultRegion: ZodString;
|
|
2800
|
+
regionPinned: ZodBoolean;
|
|
2801
|
+
}, $strip>;
|
|
2802
|
+
type OrgSettings = output<typeof orgSettingsResponseSchema>;
|
|
2785
2803
|
type JobResponse = output<typeof jobResponseSchema>;
|
|
2786
2804
|
type JobStep = output<typeof jobStepSchema>;
|
|
2787
2805
|
type Output = output<typeof jobOutputSchema>;
|
|
@@ -2866,6 +2884,19 @@ declare const orgEventSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2866
2884
|
stepProgress: ZodOptional<ZodNumber>;
|
|
2867
2885
|
eta: ZodOptional<ZodNumber>;
|
|
2868
2886
|
metrics: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodNumber, ZodString]>>>;
|
|
2887
|
+
}, $strip>, ZodObject<{
|
|
2888
|
+
type: ZodLiteral<"job.metrics">;
|
|
2889
|
+
jobId: ZodString;
|
|
2890
|
+
timestamp: ZodNumber;
|
|
2891
|
+
cpuPct: ZodNumber;
|
|
2892
|
+
cpuCores: ZodNumber;
|
|
2893
|
+
allocatedCores: ZodOptional<ZodNumber>;
|
|
2894
|
+
memUsedMB: ZodNumber;
|
|
2895
|
+
memLimitMB: ZodNumber;
|
|
2896
|
+
diskRMBps: ZodOptional<ZodNumber>;
|
|
2897
|
+
diskWMBps: ZodOptional<ZodNumber>;
|
|
2898
|
+
netRxMBps: ZodOptional<ZodNumber>;
|
|
2899
|
+
netTxMBps: ZodOptional<ZodNumber>;
|
|
2869
2900
|
}, $strip>, ZodObject<{
|
|
2870
2901
|
type: ZodLiteral<"job.step">;
|
|
2871
2902
|
jobId: ZodString;
|
|
@@ -2902,10 +2933,10 @@ declare const orgEventSchema: ZodDiscriminatedUnion<[ZodObject<{
|
|
|
2902
2933
|
}, $strip>], "type">;
|
|
2903
2934
|
type OrgEvent = output<typeof orgEventSchema>;
|
|
2904
2935
|
/**
|
|
2905
|
-
* Log entry data structure used by dashboard hooks and
|
|
2936
|
+
* Log entry data structure used by dashboard hooks and runner.
|
|
2906
2937
|
* Import from `@rendobar/shared/events/org-events`.
|
|
2907
2938
|
*
|
|
2908
|
-
* Matches
|
|
2939
|
+
* Matches runner's log event format.
|
|
2909
2940
|
*/
|
|
2910
2941
|
interface LogEntryData {
|
|
2911
2942
|
timestamp: number;
|
|
@@ -2949,7 +2980,7 @@ declare function jobData<T>(job: JobResponse): T | null;
|
|
|
2949
2980
|
* Per-job execution timing breakdown. Returned by `client.jobs.getTimings(id)`.
|
|
2950
2981
|
*
|
|
2951
2982
|
* All values are milliseconds, or `null` if the corresponding stage did not
|
|
2952
|
-
* execute (e.g. a sync-completed job has no
|
|
2983
|
+
* execute (e.g. a sync-completed job has no runner or queue timings).
|
|
2953
2984
|
*/
|
|
2954
2985
|
interface JobTimings {
|
|
2955
2986
|
jobId: string;
|
|
@@ -3159,6 +3190,12 @@ declare function createClient(config?: ClientConfig): {
|
|
|
3159
3190
|
delete(options?: {
|
|
3160
3191
|
signal?: AbortSignal;
|
|
3161
3192
|
}): Promise<void>;
|
|
3193
|
+
getSettings(options?: {
|
|
3194
|
+
signal?: AbortSignal;
|
|
3195
|
+
}): Promise<OrgSettings>;
|
|
3196
|
+
updateSettings(body: Partial<Pick<OrgSettings, "billingEmailsEnabled" | "defaultRegion" | "regionPinned">>, options?: {
|
|
3197
|
+
signal?: AbortSignal;
|
|
3198
|
+
}): Promise<OrgSettings>;
|
|
3162
3199
|
};
|
|
3163
3200
|
batches: {
|
|
3164
3201
|
create(params: {
|
|
@@ -3247,6 +3284,20 @@ declare class ApiError extends Error {
|
|
|
3247
3284
|
constructor(code: string, statusCode: number, message: string, details?: Record<string, unknown> | undefined, retryAfter?: number | undefined);
|
|
3248
3285
|
}
|
|
3249
3286
|
declare function isApiError(error: unknown): error is ApiError;
|
|
3287
|
+
/** Thrown by jobs.wait() when the deadline passes before the job reaches a terminal state. */
|
|
3288
|
+
declare class WaitTimeoutError extends Error {
|
|
3289
|
+
readonly jobId: string;
|
|
3290
|
+
readonly lastStatus: string;
|
|
3291
|
+
readonly timeoutMs: number;
|
|
3292
|
+
constructor(jobId: string, lastStatus: string, timeoutMs: number);
|
|
3293
|
+
}
|
|
3294
|
+
/** Thrown by jobs.wait({ throwOnFailure: true }) when the job ends failed/cancelled. */
|
|
3295
|
+
declare class JobFailedError extends Error {
|
|
3296
|
+
readonly jobId: string;
|
|
3297
|
+
readonly status: string;
|
|
3298
|
+
readonly job: unknown;
|
|
3299
|
+
constructor(jobId: string, status: string, job: unknown, detail?: string);
|
|
3300
|
+
}
|
|
3250
3301
|
//#endregion
|
|
3251
3302
|
//#region src/realtime/client.d.ts
|
|
3252
3303
|
interface RealtimeConnectOptions {
|
|
@@ -3278,6 +3329,12 @@ interface JobSubscribeOptions {
|
|
|
3278
3329
|
onComplete?: (event: Extract<OrgEvent, {
|
|
3279
3330
|
type: "job.status";
|
|
3280
3331
|
}>) => void;
|
|
3332
|
+
onMetrics?: (event: Extract<OrgEvent, {
|
|
3333
|
+
type: "job.metrics";
|
|
3334
|
+
}>) => void;
|
|
3335
|
+
onContext?: (event: Extract<OrgEvent, {
|
|
3336
|
+
type: "job.context";
|
|
3337
|
+
}>) => void;
|
|
3281
3338
|
onError?: (error: Error) => void;
|
|
3282
3339
|
}
|
|
3283
3340
|
interface JobSubscription {
|
|
@@ -3323,10 +3380,16 @@ type ListJobsParams = {
|
|
|
3323
3380
|
offset?: number;
|
|
3324
3381
|
};
|
|
3325
3382
|
type WaitOptions = {
|
|
3326
|
-
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /**
|
|
3327
|
-
interval?: number; /**
|
|
3383
|
+
/** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Initial poll interval in ms. Default: 2_000. Grows with exponential backoff. */
|
|
3384
|
+
interval?: number; /** Cap for the backoff poll interval in ms. Default: 10_000. */
|
|
3385
|
+
maxInterval?: number; /** Called on each poll with the latest job state. */
|
|
3328
3386
|
onProgress?: (job: JobResponse) => void; /** Abort signal for cancellation. */
|
|
3329
3387
|
signal?: AbortSignal;
|
|
3388
|
+
/**
|
|
3389
|
+
* When true, throw JobFailedError if the job ends with status "failed" or "cancelled".
|
|
3390
|
+
* Default: false (returns the terminal job, preserving existing behavior).
|
|
3391
|
+
*/
|
|
3392
|
+
throwOnFailure?: boolean;
|
|
3330
3393
|
};
|
|
3331
3394
|
type JobListPage = {
|
|
3332
3395
|
data: JobResponse[];
|
|
@@ -3426,4 +3489,4 @@ type AssetListPage = {
|
|
|
3426
3489
|
meta: AssetListMeta;
|
|
3427
3490
|
};
|
|
3428
3491
|
//#endregion
|
|
3429
|
-
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BatchResult, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCreatedResponse, type JobError, type JobListPage, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, type WebhookDelivery, type WebhookEndpoint, createClient, isApiError, jobData, outputUrl };
|
|
3492
|
+
export { ApiError, type ApiKey, type AssetResponse as Asset, type AssetDownloadResponse, type AssetInitResponse, type AssetListMeta, type AssetListPage, type BatchResult, type BillingInvoice, type BillingState, type ClientConfig, type Cost, type CreateJobParams, type CreateUploadOptions, type CreateWebhookParams, type FfmpegParams, type FileType, type JobResponse as Job, type JobCreatedResponse, type JobError, JobFailedError, type JobListPage, type JobStep, type JobSubscribeOptions, type JobSubscription, type JobTimings, type JobType, type ListAssetsParams, type ListDeliveriesParams, type ListJobsParams, type LogEntryData, type OrgCurrentResponse, type OrgEvent, type OrgSettings, type Organization, type Output, type OutputFile, type PaginationMeta, type PaymentMethod, type RealtimeConnectOptions, type RealtimeConnection, type RendobarClient, type Transaction, type TransactionListParams, type UpdateWebhookParams, type UploadProgress, type UsageParams, type UsageSummary, type WaitOptions, WaitTimeoutError, type WebhookDelivery, type WebhookEndpoint, createClient, isApiError, jobData, outputUrl };
|
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,32 @@ var ApiError = class extends Error {
|
|
|
17
17
|
function isApiError(error) {
|
|
18
18
|
return error instanceof ApiError;
|
|
19
19
|
}
|
|
20
|
+
/** Thrown by jobs.wait() when the deadline passes before the job reaches a terminal state. */
|
|
21
|
+
var WaitTimeoutError = class extends Error {
|
|
22
|
+
jobId;
|
|
23
|
+
lastStatus;
|
|
24
|
+
timeoutMs;
|
|
25
|
+
constructor(jobId, lastStatus, timeoutMs) {
|
|
26
|
+
super(`Job ${jobId} did not complete within ${timeoutMs}ms (last status: ${lastStatus}). It may still be queued — check the dashboard or retry.`);
|
|
27
|
+
this.name = "WaitTimeoutError";
|
|
28
|
+
this.jobId = jobId;
|
|
29
|
+
this.lastStatus = lastStatus;
|
|
30
|
+
this.timeoutMs = timeoutMs;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** Thrown by jobs.wait({ throwOnFailure: true }) when the job ends failed/cancelled. */
|
|
34
|
+
var JobFailedError = class extends Error {
|
|
35
|
+
jobId;
|
|
36
|
+
status;
|
|
37
|
+
job;
|
|
38
|
+
constructor(jobId, status, job, detail) {
|
|
39
|
+
super(`Job ${jobId} ended with status "${status}"${detail ? `: ${detail}` : ""}.`);
|
|
40
|
+
this.name = "JobFailedError";
|
|
41
|
+
this.jobId = jobId;
|
|
42
|
+
this.status = status;
|
|
43
|
+
this.job = job;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
20
46
|
//#endregion
|
|
21
47
|
//#region src/lib/request.ts
|
|
22
48
|
/**
|
|
@@ -182,21 +208,24 @@ function createJobsResource(request) {
|
|
|
182
208
|
}
|
|
183
209
|
},
|
|
184
210
|
async wait(id, options = {}) {
|
|
185
|
-
const { timeout = 3e5, interval = 2e3, onProgress, signal } = options;
|
|
211
|
+
const { timeout = 3e5, interval = 2e3, maxInterval = 1e4, onProgress, signal, throwOnFailure = false } = options;
|
|
186
212
|
const deadline = Date.now() + timeout;
|
|
213
|
+
let currentInterval = interval;
|
|
187
214
|
while (Date.now() < deadline) {
|
|
188
215
|
if (signal?.aborted) throw new DOMException("Wait aborted", "AbortError");
|
|
189
216
|
const job = await request(`/jobs/${id}`, { signal });
|
|
190
217
|
onProgress?.(job);
|
|
191
|
-
if (TERMINAL_STATUSES$1.has(job.status)) return job;
|
|
218
|
+
if (TERMINAL_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
192
219
|
const remaining = deadline - Date.now();
|
|
193
|
-
const delay = Math.min(
|
|
220
|
+
const delay = Math.min(currentInterval, remaining);
|
|
194
221
|
if (delay <= 0) break;
|
|
195
222
|
await sleep(delay, signal);
|
|
223
|
+
currentInterval = Math.min(currentInterval * 1.5, maxInterval);
|
|
196
224
|
}
|
|
197
225
|
const job = await request(`/jobs/${id}`, { signal });
|
|
198
|
-
|
|
199
|
-
|
|
226
|
+
onProgress?.(job);
|
|
227
|
+
if (TERMINAL_STATUSES$1.has(job.status)) return resolveTerminal(id, job, throwOnFailure);
|
|
228
|
+
throw new WaitTimeoutError(id, job.status, timeout);
|
|
200
229
|
},
|
|
201
230
|
async cancel(id, options) {
|
|
202
231
|
return request(`/jobs/${id}/cancel`, {
|
|
@@ -221,6 +250,21 @@ function createJobsResource(request) {
|
|
|
221
250
|
}
|
|
222
251
|
};
|
|
223
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Handle a terminal job result: throw JobFailedError when throwOnFailure is
|
|
255
|
+
* set and the status is failed/cancelled; otherwise return the job.
|
|
256
|
+
*
|
|
257
|
+
* Narrowing on `status === "failed"` before reading `job.error` is required
|
|
258
|
+
* because `error` is only present on the "failed" variant of the discriminated
|
|
259
|
+
* union — the compiler won't allow access without narrowing first.
|
|
260
|
+
*/
|
|
261
|
+
function resolveTerminal(id, job, throwOnFailure) {
|
|
262
|
+
if (throwOnFailure && (job.status === "failed" || job.status === "cancelled")) {
|
|
263
|
+
const detail = job.status === "failed" ? job.error.message : void 0;
|
|
264
|
+
throw new JobFailedError(id, job.status, job, detail);
|
|
265
|
+
}
|
|
266
|
+
return job;
|
|
267
|
+
}
|
|
224
268
|
function sleep(ms, signal) {
|
|
225
269
|
return new Promise((resolve, reject) => {
|
|
226
270
|
if (signal?.aborted) {
|
|
@@ -574,6 +618,16 @@ function createOrgsResource(request) {
|
|
|
574
618
|
method: "DELETE",
|
|
575
619
|
signal: options?.signal
|
|
576
620
|
});
|
|
621
|
+
},
|
|
622
|
+
async getSettings(options) {
|
|
623
|
+
return request("/orgs/current/settings", { signal: options?.signal });
|
|
624
|
+
},
|
|
625
|
+
async updateSettings(body, options) {
|
|
626
|
+
return request("/orgs/current/settings", {
|
|
627
|
+
method: "PATCH",
|
|
628
|
+
body,
|
|
629
|
+
signal: options?.signal
|
|
630
|
+
});
|
|
577
631
|
}
|
|
578
632
|
};
|
|
579
633
|
}
|
|
@@ -698,6 +752,8 @@ const KNOWN_EVENT_TYPES = new Set([
|
|
|
698
752
|
"job.progress",
|
|
699
753
|
"job.step",
|
|
700
754
|
"job.log",
|
|
755
|
+
"job.metrics",
|
|
756
|
+
"job.context",
|
|
701
757
|
"balance.updated",
|
|
702
758
|
"subscription.updated",
|
|
703
759
|
"notification",
|
|
@@ -786,6 +842,12 @@ function dispatchJobEvent(event, options) {
|
|
|
786
842
|
case "job.result":
|
|
787
843
|
options.onResult?.(event);
|
|
788
844
|
break;
|
|
845
|
+
case "job.metrics":
|
|
846
|
+
options.onMetrics?.(event);
|
|
847
|
+
break;
|
|
848
|
+
case "job.context":
|
|
849
|
+
options.onContext?.(event);
|
|
850
|
+
break;
|
|
789
851
|
}
|
|
790
852
|
}
|
|
791
853
|
//#endregion
|
|
@@ -849,4 +911,4 @@ function jobData(job) {
|
|
|
849
911
|
return job.output.data;
|
|
850
912
|
}
|
|
851
913
|
//#endregion
|
|
852
|
-
export { ApiError, createClient, isApiError, jobData, outputUrl };
|
|
914
|
+
export { ApiError, JobFailedError, WaitTimeoutError, createClient, isApiError, jobData, outputUrl };
|