@rendobar/sdk 3.1.0 → 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 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(interval, remaining);
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
- if (TERMINAL_STATUSES$1.has(job.status)) return job;
200
- throw new Error(`Job ${id} did not complete within ${timeout}ms (status: ${job.status})`);
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
  }
@@ -859,6 +913,8 @@ function jobData(job) {
859
913
  }
860
914
  //#endregion
861
915
  exports.ApiError = ApiError;
916
+ exports.JobFailedError = JobFailedError;
917
+ exports.WaitTimeoutError = WaitTimeoutError;
862
918
  exports.createClient = createClient;
863
919
  exports.isApiError = isApiError;
864
920
  exports.jobData = jobData;
package/dist/index.d.cts CHANGED
@@ -2270,6 +2270,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2270
2270
  }, $strip>>;
2271
2271
  logsAvailable: ZodBoolean;
2272
2272
  metricsAvailable: ZodBoolean;
2273
+ region: ZodOptional<ZodNullable<ZodString>>;
2273
2274
  createdAt: ZodNumber;
2274
2275
  dispatchedAt: ZodNullable<ZodNumber>;
2275
2276
  startedAt: ZodNullable<ZodNumber>;
@@ -2307,6 +2308,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2307
2308
  }, $strip>>;
2308
2309
  logsAvailable: ZodBoolean;
2309
2310
  metricsAvailable: ZodBoolean;
2311
+ region: ZodOptional<ZodNullable<ZodString>>;
2310
2312
  createdAt: ZodNumber;
2311
2313
  dispatchedAt: ZodNullable<ZodNumber>;
2312
2314
  startedAt: ZodNullable<ZodNumber>;
@@ -2346,6 +2348,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2346
2348
  }, $strip>>;
2347
2349
  logsAvailable: ZodBoolean;
2348
2350
  metricsAvailable: ZodBoolean;
2351
+ region: ZodOptional<ZodNullable<ZodString>>;
2349
2352
  createdAt: ZodNumber;
2350
2353
  dispatchedAt: ZodNullable<ZodNumber>;
2351
2354
  startedAt: ZodNullable<ZodNumber>;
@@ -2385,6 +2388,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2385
2388
  }, $strip>>;
2386
2389
  logsAvailable: ZodBoolean;
2387
2390
  metricsAvailable: ZodBoolean;
2391
+ region: ZodOptional<ZodNullable<ZodString>>;
2388
2392
  createdAt: ZodNumber;
2389
2393
  dispatchedAt: ZodNullable<ZodNumber>;
2390
2394
  startedAt: ZodNullable<ZodNumber>;
@@ -2466,6 +2470,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2466
2470
  }, $strip>>;
2467
2471
  logsAvailable: ZodBoolean;
2468
2472
  metricsAvailable: ZodBoolean;
2473
+ region: ZodOptional<ZodNullable<ZodString>>;
2469
2474
  createdAt: ZodNumber;
2470
2475
  dispatchedAt: ZodNullable<ZodNumber>;
2471
2476
  startedAt: ZodNullable<ZodNumber>;
@@ -2509,6 +2514,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2509
2514
  }, $strip>>;
2510
2515
  logsAvailable: ZodBoolean;
2511
2516
  metricsAvailable: ZodBoolean;
2517
+ region: ZodOptional<ZodNullable<ZodString>>;
2512
2518
  createdAt: ZodNumber;
2513
2519
  dispatchedAt: ZodNullable<ZodNumber>;
2514
2520
  startedAt: ZodNullable<ZodNumber>;
@@ -2788,6 +2794,12 @@ declare const assetListMetaSchema: ZodObject<{
2788
2794
  limit: ZodNumber;
2789
2795
  offset: ZodNumber;
2790
2796
  }, $strip>;
2797
+ declare const orgSettingsResponseSchema: ZodObject<{
2798
+ billingEmailsEnabled: ZodBoolean;
2799
+ defaultRegion: ZodString;
2800
+ regionPinned: ZodBoolean;
2801
+ }, $strip>;
2802
+ type OrgSettings = output<typeof orgSettingsResponseSchema>;
2791
2803
  type JobResponse = output<typeof jobResponseSchema>;
2792
2804
  type JobStep = output<typeof jobStepSchema>;
2793
2805
  type Output = output<typeof jobOutputSchema>;
@@ -3178,6 +3190,12 @@ declare function createClient(config?: ClientConfig): {
3178
3190
  delete(options?: {
3179
3191
  signal?: AbortSignal;
3180
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>;
3181
3199
  };
3182
3200
  batches: {
3183
3201
  create(params: {
@@ -3266,6 +3284,20 @@ declare class ApiError extends Error {
3266
3284
  constructor(code: string, statusCode: number, message: string, details?: Record<string, unknown> | undefined, retryAfter?: number | undefined);
3267
3285
  }
3268
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
+ }
3269
3301
  //#endregion
3270
3302
  //#region src/realtime/client.d.ts
3271
3303
  interface RealtimeConnectOptions {
@@ -3348,10 +3380,16 @@ type ListJobsParams = {
3348
3380
  offset?: number;
3349
3381
  };
3350
3382
  type WaitOptions = {
3351
- /** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Poll interval in ms. Default: 2_000. */
3352
- interval?: number; /** Called on each poll with the latest job state. */
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. */
3353
3386
  onProgress?: (job: JobResponse) => void; /** Abort signal for cancellation. */
3354
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;
3355
3393
  };
3356
3394
  type JobListPage = {
3357
3395
  data: JobResponse[];
@@ -3451,4 +3489,4 @@ type AssetListPage = {
3451
3489
  meta: AssetListMeta;
3452
3490
  };
3453
3491
  //#endregion
3454
- 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
@@ -2270,6 +2270,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2270
2270
  }, $strip>>;
2271
2271
  logsAvailable: ZodBoolean;
2272
2272
  metricsAvailable: ZodBoolean;
2273
+ region: ZodOptional<ZodNullable<ZodString>>;
2273
2274
  createdAt: ZodNumber;
2274
2275
  dispatchedAt: ZodNullable<ZodNumber>;
2275
2276
  startedAt: ZodNullable<ZodNumber>;
@@ -2307,6 +2308,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2307
2308
  }, $strip>>;
2308
2309
  logsAvailable: ZodBoolean;
2309
2310
  metricsAvailable: ZodBoolean;
2311
+ region: ZodOptional<ZodNullable<ZodString>>;
2310
2312
  createdAt: ZodNumber;
2311
2313
  dispatchedAt: ZodNullable<ZodNumber>;
2312
2314
  startedAt: ZodNullable<ZodNumber>;
@@ -2346,6 +2348,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2346
2348
  }, $strip>>;
2347
2349
  logsAvailable: ZodBoolean;
2348
2350
  metricsAvailable: ZodBoolean;
2351
+ region: ZodOptional<ZodNullable<ZodString>>;
2349
2352
  createdAt: ZodNumber;
2350
2353
  dispatchedAt: ZodNullable<ZodNumber>;
2351
2354
  startedAt: ZodNullable<ZodNumber>;
@@ -2385,6 +2388,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2385
2388
  }, $strip>>;
2386
2389
  logsAvailable: ZodBoolean;
2387
2390
  metricsAvailable: ZodBoolean;
2391
+ region: ZodOptional<ZodNullable<ZodString>>;
2388
2392
  createdAt: ZodNumber;
2389
2393
  dispatchedAt: ZodNullable<ZodNumber>;
2390
2394
  startedAt: ZodNullable<ZodNumber>;
@@ -2466,6 +2470,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2466
2470
  }, $strip>>;
2467
2471
  logsAvailable: ZodBoolean;
2468
2472
  metricsAvailable: ZodBoolean;
2473
+ region: ZodOptional<ZodNullable<ZodString>>;
2469
2474
  createdAt: ZodNumber;
2470
2475
  dispatchedAt: ZodNullable<ZodNumber>;
2471
2476
  startedAt: ZodNullable<ZodNumber>;
@@ -2509,6 +2514,7 @@ declare const jobResponseSchema: ZodDiscriminatedUnion<[ZodObject<{
2509
2514
  }, $strip>>;
2510
2515
  logsAvailable: ZodBoolean;
2511
2516
  metricsAvailable: ZodBoolean;
2517
+ region: ZodOptional<ZodNullable<ZodString>>;
2512
2518
  createdAt: ZodNumber;
2513
2519
  dispatchedAt: ZodNullable<ZodNumber>;
2514
2520
  startedAt: ZodNullable<ZodNumber>;
@@ -2788,6 +2794,12 @@ declare const assetListMetaSchema: ZodObject<{
2788
2794
  limit: ZodNumber;
2789
2795
  offset: ZodNumber;
2790
2796
  }, $strip>;
2797
+ declare const orgSettingsResponseSchema: ZodObject<{
2798
+ billingEmailsEnabled: ZodBoolean;
2799
+ defaultRegion: ZodString;
2800
+ regionPinned: ZodBoolean;
2801
+ }, $strip>;
2802
+ type OrgSettings = output<typeof orgSettingsResponseSchema>;
2791
2803
  type JobResponse = output<typeof jobResponseSchema>;
2792
2804
  type JobStep = output<typeof jobStepSchema>;
2793
2805
  type Output = output<typeof jobOutputSchema>;
@@ -3178,6 +3190,12 @@ declare function createClient(config?: ClientConfig): {
3178
3190
  delete(options?: {
3179
3191
  signal?: AbortSignal;
3180
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>;
3181
3199
  };
3182
3200
  batches: {
3183
3201
  create(params: {
@@ -3266,6 +3284,20 @@ declare class ApiError extends Error {
3266
3284
  constructor(code: string, statusCode: number, message: string, details?: Record<string, unknown> | undefined, retryAfter?: number | undefined);
3267
3285
  }
3268
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
+ }
3269
3301
  //#endregion
3270
3302
  //#region src/realtime/client.d.ts
3271
3303
  interface RealtimeConnectOptions {
@@ -3348,10 +3380,16 @@ type ListJobsParams = {
3348
3380
  offset?: number;
3349
3381
  };
3350
3382
  type WaitOptions = {
3351
- /** Max wait time in ms. Default: 300_000 (5 minutes). */timeout?: number; /** Poll interval in ms. Default: 2_000. */
3352
- interval?: number; /** Called on each poll with the latest job state. */
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. */
3353
3386
  onProgress?: (job: JobResponse) => void; /** Abort signal for cancellation. */
3354
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;
3355
3393
  };
3356
3394
  type JobListPage = {
3357
3395
  data: JobResponse[];
@@ -3451,4 +3489,4 @@ type AssetListPage = {
3451
3489
  meta: AssetListMeta;
3452
3490
  };
3453
3491
  //#endregion
3454
- 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(interval, remaining);
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
- if (TERMINAL_STATUSES$1.has(job.status)) return job;
199
- throw new Error(`Job ${id} did not complete within ${timeout}ms (status: ${job.status})`);
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
  }
@@ -857,4 +911,4 @@ function jobData(job) {
857
911
  return job.output.data;
858
912
  }
859
913
  //#endregion
860
- export { ApiError, createClient, isApiError, jobData, outputUrl };
914
+ export { ApiError, JobFailedError, WaitTimeoutError, createClient, isApiError, jobData, outputUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rendobar/sdk",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript client for the Rendobar media processing API",
6
6
  "main": "./dist/index.cjs",