runlater-js 0.2.0 → 0.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/dist/index.d.mts CHANGED
@@ -113,6 +113,26 @@ interface Monitor {
113
113
  inserted_at: string;
114
114
  updated_at: string;
115
115
  }
116
+ interface BatchOptions {
117
+ url: string;
118
+ queue: string;
119
+ items: unknown[];
120
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
121
+ headers?: Record<string, string>;
122
+ run_at?: string | Date;
123
+ delay?: string | number;
124
+ timeout?: number;
125
+ retries?: number;
126
+ callback?: string;
127
+ }
128
+ interface BatchResponse {
129
+ queue: string;
130
+ created: number;
131
+ scheduled_for: string;
132
+ }
133
+ interface CancelQueueResponse {
134
+ cancelled: number;
135
+ }
116
136
  interface UpdateTaskOptions {
117
137
  name?: string;
118
138
  url?: string;
@@ -267,6 +287,37 @@ declare class Tasks {
267
287
  trigger(id: string): Promise<TriggerResponse>;
268
288
  update(id: string, options: UpdateTaskOptions): Promise<Task>;
269
289
  executions(id: string, limit?: number): Promise<Execution[]>;
290
+ /**
291
+ * Create many tasks at once with shared configuration.
292
+ *
293
+ * Each item in the array becomes the request body for one task.
294
+ * All tasks share the same URL, method, headers, timing, and queue.
295
+ * Use the queue name with `cancelQueue()` to cancel them as a group.
296
+ *
297
+ * ```js
298
+ * await rl.tasks.batch({
299
+ * url: "https://myapp.com/api/send-email",
300
+ * queue: "march-newsletter",
301
+ * run_at: "2026-03-01T09:00:00Z",
302
+ * items: [
303
+ * { to: "user1@example.com", name: "Alice" },
304
+ * { to: "user2@example.com", name: "Bob" },
305
+ * ]
306
+ * })
307
+ * ```
308
+ */
309
+ batch(options: BatchOptions): Promise<BatchResponse>;
310
+ /**
311
+ * Cancel all tasks in a queue.
312
+ *
313
+ * Soft-deletes every task in the queue and removes their pending executions.
314
+ *
315
+ * ```js
316
+ * const { cancelled } = await rl.tasks.cancelQueue("march-newsletter")
317
+ * console.log(`Cancelled ${cancelled} tasks`)
318
+ * ```
319
+ */
320
+ cancelQueue(queue: string): Promise<CancelQueueResponse>;
270
321
  }
271
322
  declare class Monitors {
272
323
  private client;
@@ -280,4 +331,4 @@ declare class Monitors {
280
331
  ping(token: string): Promise<PingResponse>;
281
332
  }
282
333
 
283
- export { type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Execution, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateMonitorOptions, type UpdateTaskOptions };
334
+ export { type BatchOptions, type BatchResponse, type CancelQueueResponse, type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Execution, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateMonitorOptions, type UpdateTaskOptions };
package/dist/index.d.ts CHANGED
@@ -113,6 +113,26 @@ interface Monitor {
113
113
  inserted_at: string;
114
114
  updated_at: string;
115
115
  }
116
+ interface BatchOptions {
117
+ url: string;
118
+ queue: string;
119
+ items: unknown[];
120
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
121
+ headers?: Record<string, string>;
122
+ run_at?: string | Date;
123
+ delay?: string | number;
124
+ timeout?: number;
125
+ retries?: number;
126
+ callback?: string;
127
+ }
128
+ interface BatchResponse {
129
+ queue: string;
130
+ created: number;
131
+ scheduled_for: string;
132
+ }
133
+ interface CancelQueueResponse {
134
+ cancelled: number;
135
+ }
116
136
  interface UpdateTaskOptions {
117
137
  name?: string;
118
138
  url?: string;
@@ -267,6 +287,37 @@ declare class Tasks {
267
287
  trigger(id: string): Promise<TriggerResponse>;
268
288
  update(id: string, options: UpdateTaskOptions): Promise<Task>;
269
289
  executions(id: string, limit?: number): Promise<Execution[]>;
290
+ /**
291
+ * Create many tasks at once with shared configuration.
292
+ *
293
+ * Each item in the array becomes the request body for one task.
294
+ * All tasks share the same URL, method, headers, timing, and queue.
295
+ * Use the queue name with `cancelQueue()` to cancel them as a group.
296
+ *
297
+ * ```js
298
+ * await rl.tasks.batch({
299
+ * url: "https://myapp.com/api/send-email",
300
+ * queue: "march-newsletter",
301
+ * run_at: "2026-03-01T09:00:00Z",
302
+ * items: [
303
+ * { to: "user1@example.com", name: "Alice" },
304
+ * { to: "user2@example.com", name: "Bob" },
305
+ * ]
306
+ * })
307
+ * ```
308
+ */
309
+ batch(options: BatchOptions): Promise<BatchResponse>;
310
+ /**
311
+ * Cancel all tasks in a queue.
312
+ *
313
+ * Soft-deletes every task in the queue and removes their pending executions.
314
+ *
315
+ * ```js
316
+ * const { cancelled } = await rl.tasks.cancelQueue("march-newsletter")
317
+ * console.log(`Cancelled ${cancelled} tasks`)
318
+ * ```
319
+ */
320
+ cancelQueue(queue: string): Promise<CancelQueueResponse>;
270
321
  }
271
322
  declare class Monitors {
272
323
  private client;
@@ -280,4 +331,4 @@ declare class Monitors {
280
331
  ping(token: string): Promise<PingResponse>;
281
332
  }
282
333
 
283
- export { type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Execution, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateMonitorOptions, type UpdateTaskOptions };
334
+ export { type BatchOptions, type BatchResponse, type CancelQueueResponse, type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Execution, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateMonitorOptions, type UpdateTaskOptions };
package/dist/index.js CHANGED
@@ -278,6 +278,64 @@ var Tasks = class {
278
278
  );
279
279
  return res.data;
280
280
  }
281
+ /**
282
+ * Create many tasks at once with shared configuration.
283
+ *
284
+ * Each item in the array becomes the request body for one task.
285
+ * All tasks share the same URL, method, headers, timing, and queue.
286
+ * Use the queue name with `cancelQueue()` to cancel them as a group.
287
+ *
288
+ * ```js
289
+ * await rl.tasks.batch({
290
+ * url: "https://myapp.com/api/send-email",
291
+ * queue: "march-newsletter",
292
+ * run_at: "2026-03-01T09:00:00Z",
293
+ * items: [
294
+ * { to: "user1@example.com", name: "Alice" },
295
+ * { to: "user2@example.com", name: "Bob" },
296
+ * ]
297
+ * })
298
+ * ```
299
+ */
300
+ async batch(options) {
301
+ const body = {
302
+ url: options.url,
303
+ queue: options.queue,
304
+ items: options.items,
305
+ method: options.method ?? "POST",
306
+ headers: options.headers,
307
+ timeout_ms: options.timeout,
308
+ retry_attempts: options.retries,
309
+ callback_url: options.callback
310
+ };
311
+ if (options.run_at != null) {
312
+ body.run_at = options.run_at instanceof Date ? options.run_at.toISOString() : options.run_at;
313
+ }
314
+ if (options.delay != null) {
315
+ body.delay = formatDelay(options.delay);
316
+ }
317
+ const res = await this.client.request("POST", "/tasks/batch", {
318
+ body
319
+ });
320
+ return res.data;
321
+ }
322
+ /**
323
+ * Cancel all tasks in a queue.
324
+ *
325
+ * Soft-deletes every task in the queue and removes their pending executions.
326
+ *
327
+ * ```js
328
+ * const { cancelled } = await rl.tasks.cancelQueue("march-newsletter")
329
+ * console.log(`Cancelled ${cancelled} tasks`)
330
+ * ```
331
+ */
332
+ async cancelQueue(queue) {
333
+ const res = await this.client.request(
334
+ "DELETE",
335
+ `/tasks?queue=${encodeURIComponent(queue)}`
336
+ );
337
+ return res.data;
338
+ }
281
339
  };
282
340
  var Monitors = class {
283
341
  constructor(client) {
package/dist/index.mjs CHANGED
@@ -251,6 +251,64 @@ var Tasks = class {
251
251
  );
252
252
  return res.data;
253
253
  }
254
+ /**
255
+ * Create many tasks at once with shared configuration.
256
+ *
257
+ * Each item in the array becomes the request body for one task.
258
+ * All tasks share the same URL, method, headers, timing, and queue.
259
+ * Use the queue name with `cancelQueue()` to cancel them as a group.
260
+ *
261
+ * ```js
262
+ * await rl.tasks.batch({
263
+ * url: "https://myapp.com/api/send-email",
264
+ * queue: "march-newsletter",
265
+ * run_at: "2026-03-01T09:00:00Z",
266
+ * items: [
267
+ * { to: "user1@example.com", name: "Alice" },
268
+ * { to: "user2@example.com", name: "Bob" },
269
+ * ]
270
+ * })
271
+ * ```
272
+ */
273
+ async batch(options) {
274
+ const body = {
275
+ url: options.url,
276
+ queue: options.queue,
277
+ items: options.items,
278
+ method: options.method ?? "POST",
279
+ headers: options.headers,
280
+ timeout_ms: options.timeout,
281
+ retry_attempts: options.retries,
282
+ callback_url: options.callback
283
+ };
284
+ if (options.run_at != null) {
285
+ body.run_at = options.run_at instanceof Date ? options.run_at.toISOString() : options.run_at;
286
+ }
287
+ if (options.delay != null) {
288
+ body.delay = formatDelay(options.delay);
289
+ }
290
+ const res = await this.client.request("POST", "/tasks/batch", {
291
+ body
292
+ });
293
+ return res.data;
294
+ }
295
+ /**
296
+ * Cancel all tasks in a queue.
297
+ *
298
+ * Soft-deletes every task in the queue and removes their pending executions.
299
+ *
300
+ * ```js
301
+ * const { cancelled } = await rl.tasks.cancelQueue("march-newsletter")
302
+ * console.log(`Cancelled ${cancelled} tasks`)
303
+ * ```
304
+ */
305
+ async cancelQueue(queue) {
306
+ const res = await this.client.request(
307
+ "DELETE",
308
+ `/tasks?queue=${encodeURIComponent(queue)}`
309
+ );
310
+ return res.data;
311
+ }
254
312
  };
255
313
  var Monitors = class {
256
314
  constructor(client) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runlater-js",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Delayed tasks, cron jobs, and reliable webhooks. No infrastructure required.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",