runlater-js 0.9.0 → 0.11.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 +87 -13
- package/dist/index.d.ts +87 -13
- package/dist/index.js +81 -14
- package/dist/index.mjs +81 -14
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -56,6 +56,62 @@ interface CronResponse {
|
|
|
56
56
|
inserted_at: string;
|
|
57
57
|
updated_at: string;
|
|
58
58
|
}
|
|
59
|
+
interface Schedule {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
url: string;
|
|
63
|
+
method: string;
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
body: string | null;
|
|
66
|
+
cron: string;
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
timeout_ms: number;
|
|
69
|
+
callback_url: string | null;
|
|
70
|
+
expected_status_codes: string | null;
|
|
71
|
+
expected_body_pattern: string | null;
|
|
72
|
+
notify_on_failure: boolean | null;
|
|
73
|
+
notify_on_recovery: boolean | null;
|
|
74
|
+
on_failure_url: string | null;
|
|
75
|
+
on_recovery_url: string | null;
|
|
76
|
+
script: string | null;
|
|
77
|
+
next_run_at: string | null;
|
|
78
|
+
inserted_at: string;
|
|
79
|
+
updated_at: string;
|
|
80
|
+
}
|
|
81
|
+
interface CreateScheduleOptions {
|
|
82
|
+
url: string;
|
|
83
|
+
cron: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
86
|
+
headers?: Record<string, string>;
|
|
87
|
+
body?: unknown;
|
|
88
|
+
timeout?: number;
|
|
89
|
+
callback?: string;
|
|
90
|
+
enabled?: boolean;
|
|
91
|
+
on_failure_url?: string;
|
|
92
|
+
on_recovery_url?: string;
|
|
93
|
+
expected_status_codes?: string;
|
|
94
|
+
expected_body_pattern?: string;
|
|
95
|
+
script?: string;
|
|
96
|
+
}
|
|
97
|
+
interface UpdateScheduleOptions {
|
|
98
|
+
name?: string;
|
|
99
|
+
url?: string;
|
|
100
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
101
|
+
headers?: Record<string, string>;
|
|
102
|
+
body?: string;
|
|
103
|
+
cron?: string;
|
|
104
|
+
timeout_ms?: number;
|
|
105
|
+
callback_url?: string;
|
|
106
|
+
enabled?: boolean;
|
|
107
|
+
notify_on_failure?: boolean | null;
|
|
108
|
+
notify_on_recovery?: boolean | null;
|
|
109
|
+
on_failure_url?: string;
|
|
110
|
+
on_recovery_url?: string;
|
|
111
|
+
expected_status_codes?: string;
|
|
112
|
+
expected_body_pattern?: string;
|
|
113
|
+
script?: string | null;
|
|
114
|
+
}
|
|
59
115
|
interface Task {
|
|
60
116
|
id: string;
|
|
61
117
|
name: string;
|
|
@@ -128,10 +184,16 @@ interface Monitor {
|
|
|
128
184
|
inserted_at: string;
|
|
129
185
|
updated_at: string;
|
|
130
186
|
}
|
|
131
|
-
interface
|
|
187
|
+
interface BatchTask {
|
|
132
188
|
url: string;
|
|
189
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
190
|
+
headers?: Record<string, string>;
|
|
191
|
+
body?: unknown;
|
|
192
|
+
name?: string;
|
|
193
|
+
}
|
|
194
|
+
interface BatchOptions {
|
|
133
195
|
queue: string;
|
|
134
|
-
|
|
196
|
+
tasks: BatchTask[];
|
|
135
197
|
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
136
198
|
headers?: Record<string, string>;
|
|
137
199
|
run_at?: string | Date;
|
|
@@ -199,12 +261,12 @@ interface PingResponse {
|
|
|
199
261
|
monitor: string;
|
|
200
262
|
}
|
|
201
263
|
interface SyncOptions {
|
|
202
|
-
|
|
264
|
+
schedules?: CronOptions[];
|
|
203
265
|
monitors?: CreateMonitorOptions[];
|
|
204
266
|
deleteRemoved?: boolean;
|
|
205
267
|
}
|
|
206
268
|
interface SyncResponse {
|
|
207
|
-
|
|
269
|
+
schedules: {
|
|
208
270
|
created: string[];
|
|
209
271
|
updated: string[];
|
|
210
272
|
deleted: string[];
|
|
@@ -285,6 +347,7 @@ declare class Runlater {
|
|
|
285
347
|
tasks: Tasks;
|
|
286
348
|
monitors: Monitors;
|
|
287
349
|
endpoints: Endpoints;
|
|
350
|
+
schedules: Schedules;
|
|
288
351
|
constructor(options: RunlaterOptions | string);
|
|
289
352
|
/**
|
|
290
353
|
* Send a request immediately with reliable delivery and retries.
|
|
@@ -339,7 +402,7 @@ declare class Runlater {
|
|
|
339
402
|
*
|
|
340
403
|
* ```js
|
|
341
404
|
* await rl.sync({
|
|
342
|
-
*
|
|
405
|
+
* schedules: [
|
|
343
406
|
* { name: "daily-report", url: "https://...", schedule: "0 9 * * *" }
|
|
344
407
|
* ],
|
|
345
408
|
* deleteRemoved: true
|
|
@@ -366,20 +429,20 @@ declare class Tasks {
|
|
|
366
429
|
update(id: string, options: UpdateTaskOptions): Promise<Task>;
|
|
367
430
|
executions(id: string, limit?: number): Promise<Execution[]>;
|
|
368
431
|
/**
|
|
369
|
-
* Create many tasks at once
|
|
432
|
+
* Create many tasks at once. Each task defines its own URL and can
|
|
433
|
+
* optionally override method, headers, body, and name. Top-level
|
|
434
|
+
* settings serve as defaults.
|
|
370
435
|
*
|
|
371
|
-
* Each item in the array becomes the request body for one task.
|
|
372
|
-
* All tasks share the same URL, method, headers, timing, and queue.
|
|
373
436
|
* Use the queue name with `cancelQueue()` to cancel them as a group.
|
|
374
437
|
*
|
|
375
438
|
* ```js
|
|
376
439
|
* await rl.tasks.batch({
|
|
377
|
-
* url: "https://myapp.com/api/send-email",
|
|
378
440
|
* queue: "march-newsletter",
|
|
441
|
+
* method: "POST",
|
|
379
442
|
* run_at: "2026-03-01T09:00:00Z",
|
|
380
|
-
*
|
|
381
|
-
* {
|
|
382
|
-
* {
|
|
443
|
+
* tasks: [
|
|
444
|
+
* { url: "https://myapp.com/api/send-email", body: { to: "alice@example.com" } },
|
|
445
|
+
* { url: "https://myapp.com/api/send-sms", body: { to: "+1234567890" } },
|
|
383
446
|
* ]
|
|
384
447
|
* })
|
|
385
448
|
* ```
|
|
@@ -397,6 +460,17 @@ declare class Tasks {
|
|
|
397
460
|
*/
|
|
398
461
|
cancelQueue(queue: string): Promise<CancelQueueResponse>;
|
|
399
462
|
}
|
|
463
|
+
declare class Schedules {
|
|
464
|
+
private client;
|
|
465
|
+
constructor(client: Runlater);
|
|
466
|
+
list(options?: ListOptions): Promise<ListResponse<Schedule>>;
|
|
467
|
+
get(id: string): Promise<Schedule>;
|
|
468
|
+
create(options: CreateScheduleOptions): Promise<Schedule>;
|
|
469
|
+
update(id: string, options: UpdateScheduleOptions): Promise<Schedule>;
|
|
470
|
+
delete(id: string): Promise<void>;
|
|
471
|
+
trigger(id: string): Promise<TriggerResponse>;
|
|
472
|
+
executions(id: string, limit?: number): Promise<Execution[]>;
|
|
473
|
+
}
|
|
400
474
|
declare class Monitors {
|
|
401
475
|
private client;
|
|
402
476
|
constructor(client: Runlater);
|
|
@@ -422,4 +496,4 @@ declare class Endpoints {
|
|
|
422
496
|
resume(id: string): Promise<Endpoint>;
|
|
423
497
|
}
|
|
424
498
|
|
|
425
|
-
export { type BatchOptions, type BatchResponse, type CancelQueueResponse, type CreateEndpointOptions, type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Endpoint, type Execution, type InboundEvent, 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 UpdateEndpointOptions, type UpdateMonitorOptions, type UpdateTaskOptions };
|
|
499
|
+
export { type BatchOptions, type BatchResponse, type BatchTask, type CancelQueueResponse, type CreateEndpointOptions, type CreateMonitorOptions, type CreateScheduleOptions, type CronOptions, type CronResponse, type DelayOptions, type Endpoint, type Execution, type InboundEvent, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type Schedule, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateEndpointOptions, type UpdateMonitorOptions, type UpdateScheduleOptions, type UpdateTaskOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,62 @@ interface CronResponse {
|
|
|
56
56
|
inserted_at: string;
|
|
57
57
|
updated_at: string;
|
|
58
58
|
}
|
|
59
|
+
interface Schedule {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
url: string;
|
|
63
|
+
method: string;
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
body: string | null;
|
|
66
|
+
cron: string;
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
timeout_ms: number;
|
|
69
|
+
callback_url: string | null;
|
|
70
|
+
expected_status_codes: string | null;
|
|
71
|
+
expected_body_pattern: string | null;
|
|
72
|
+
notify_on_failure: boolean | null;
|
|
73
|
+
notify_on_recovery: boolean | null;
|
|
74
|
+
on_failure_url: string | null;
|
|
75
|
+
on_recovery_url: string | null;
|
|
76
|
+
script: string | null;
|
|
77
|
+
next_run_at: string | null;
|
|
78
|
+
inserted_at: string;
|
|
79
|
+
updated_at: string;
|
|
80
|
+
}
|
|
81
|
+
interface CreateScheduleOptions {
|
|
82
|
+
url: string;
|
|
83
|
+
cron: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
86
|
+
headers?: Record<string, string>;
|
|
87
|
+
body?: unknown;
|
|
88
|
+
timeout?: number;
|
|
89
|
+
callback?: string;
|
|
90
|
+
enabled?: boolean;
|
|
91
|
+
on_failure_url?: string;
|
|
92
|
+
on_recovery_url?: string;
|
|
93
|
+
expected_status_codes?: string;
|
|
94
|
+
expected_body_pattern?: string;
|
|
95
|
+
script?: string;
|
|
96
|
+
}
|
|
97
|
+
interface UpdateScheduleOptions {
|
|
98
|
+
name?: string;
|
|
99
|
+
url?: string;
|
|
100
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
101
|
+
headers?: Record<string, string>;
|
|
102
|
+
body?: string;
|
|
103
|
+
cron?: string;
|
|
104
|
+
timeout_ms?: number;
|
|
105
|
+
callback_url?: string;
|
|
106
|
+
enabled?: boolean;
|
|
107
|
+
notify_on_failure?: boolean | null;
|
|
108
|
+
notify_on_recovery?: boolean | null;
|
|
109
|
+
on_failure_url?: string;
|
|
110
|
+
on_recovery_url?: string;
|
|
111
|
+
expected_status_codes?: string;
|
|
112
|
+
expected_body_pattern?: string;
|
|
113
|
+
script?: string | null;
|
|
114
|
+
}
|
|
59
115
|
interface Task {
|
|
60
116
|
id: string;
|
|
61
117
|
name: string;
|
|
@@ -128,10 +184,16 @@ interface Monitor {
|
|
|
128
184
|
inserted_at: string;
|
|
129
185
|
updated_at: string;
|
|
130
186
|
}
|
|
131
|
-
interface
|
|
187
|
+
interface BatchTask {
|
|
132
188
|
url: string;
|
|
189
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
190
|
+
headers?: Record<string, string>;
|
|
191
|
+
body?: unknown;
|
|
192
|
+
name?: string;
|
|
193
|
+
}
|
|
194
|
+
interface BatchOptions {
|
|
133
195
|
queue: string;
|
|
134
|
-
|
|
196
|
+
tasks: BatchTask[];
|
|
135
197
|
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
136
198
|
headers?: Record<string, string>;
|
|
137
199
|
run_at?: string | Date;
|
|
@@ -199,12 +261,12 @@ interface PingResponse {
|
|
|
199
261
|
monitor: string;
|
|
200
262
|
}
|
|
201
263
|
interface SyncOptions {
|
|
202
|
-
|
|
264
|
+
schedules?: CronOptions[];
|
|
203
265
|
monitors?: CreateMonitorOptions[];
|
|
204
266
|
deleteRemoved?: boolean;
|
|
205
267
|
}
|
|
206
268
|
interface SyncResponse {
|
|
207
|
-
|
|
269
|
+
schedules: {
|
|
208
270
|
created: string[];
|
|
209
271
|
updated: string[];
|
|
210
272
|
deleted: string[];
|
|
@@ -285,6 +347,7 @@ declare class Runlater {
|
|
|
285
347
|
tasks: Tasks;
|
|
286
348
|
monitors: Monitors;
|
|
287
349
|
endpoints: Endpoints;
|
|
350
|
+
schedules: Schedules;
|
|
288
351
|
constructor(options: RunlaterOptions | string);
|
|
289
352
|
/**
|
|
290
353
|
* Send a request immediately with reliable delivery and retries.
|
|
@@ -339,7 +402,7 @@ declare class Runlater {
|
|
|
339
402
|
*
|
|
340
403
|
* ```js
|
|
341
404
|
* await rl.sync({
|
|
342
|
-
*
|
|
405
|
+
* schedules: [
|
|
343
406
|
* { name: "daily-report", url: "https://...", schedule: "0 9 * * *" }
|
|
344
407
|
* ],
|
|
345
408
|
* deleteRemoved: true
|
|
@@ -366,20 +429,20 @@ declare class Tasks {
|
|
|
366
429
|
update(id: string, options: UpdateTaskOptions): Promise<Task>;
|
|
367
430
|
executions(id: string, limit?: number): Promise<Execution[]>;
|
|
368
431
|
/**
|
|
369
|
-
* Create many tasks at once
|
|
432
|
+
* Create many tasks at once. Each task defines its own URL and can
|
|
433
|
+
* optionally override method, headers, body, and name. Top-level
|
|
434
|
+
* settings serve as defaults.
|
|
370
435
|
*
|
|
371
|
-
* Each item in the array becomes the request body for one task.
|
|
372
|
-
* All tasks share the same URL, method, headers, timing, and queue.
|
|
373
436
|
* Use the queue name with `cancelQueue()` to cancel them as a group.
|
|
374
437
|
*
|
|
375
438
|
* ```js
|
|
376
439
|
* await rl.tasks.batch({
|
|
377
|
-
* url: "https://myapp.com/api/send-email",
|
|
378
440
|
* queue: "march-newsletter",
|
|
441
|
+
* method: "POST",
|
|
379
442
|
* run_at: "2026-03-01T09:00:00Z",
|
|
380
|
-
*
|
|
381
|
-
* {
|
|
382
|
-
* {
|
|
443
|
+
* tasks: [
|
|
444
|
+
* { url: "https://myapp.com/api/send-email", body: { to: "alice@example.com" } },
|
|
445
|
+
* { url: "https://myapp.com/api/send-sms", body: { to: "+1234567890" } },
|
|
383
446
|
* ]
|
|
384
447
|
* })
|
|
385
448
|
* ```
|
|
@@ -397,6 +460,17 @@ declare class Tasks {
|
|
|
397
460
|
*/
|
|
398
461
|
cancelQueue(queue: string): Promise<CancelQueueResponse>;
|
|
399
462
|
}
|
|
463
|
+
declare class Schedules {
|
|
464
|
+
private client;
|
|
465
|
+
constructor(client: Runlater);
|
|
466
|
+
list(options?: ListOptions): Promise<ListResponse<Schedule>>;
|
|
467
|
+
get(id: string): Promise<Schedule>;
|
|
468
|
+
create(options: CreateScheduleOptions): Promise<Schedule>;
|
|
469
|
+
update(id: string, options: UpdateScheduleOptions): Promise<Schedule>;
|
|
470
|
+
delete(id: string): Promise<void>;
|
|
471
|
+
trigger(id: string): Promise<TriggerResponse>;
|
|
472
|
+
executions(id: string, limit?: number): Promise<Execution[]>;
|
|
473
|
+
}
|
|
400
474
|
declare class Monitors {
|
|
401
475
|
private client;
|
|
402
476
|
constructor(client: Runlater);
|
|
@@ -422,4 +496,4 @@ declare class Endpoints {
|
|
|
422
496
|
resume(id: string): Promise<Endpoint>;
|
|
423
497
|
}
|
|
424
498
|
|
|
425
|
-
export { type BatchOptions, type BatchResponse, type CancelQueueResponse, type CreateEndpointOptions, type CreateMonitorOptions, type CronOptions, type CronResponse, type DelayOptions, type Endpoint, type Execution, type InboundEvent, 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 UpdateEndpointOptions, type UpdateMonitorOptions, type UpdateTaskOptions };
|
|
499
|
+
export { type BatchOptions, type BatchResponse, type BatchTask, type CancelQueueResponse, type CreateEndpointOptions, type CreateMonitorOptions, type CreateScheduleOptions, type CronOptions, type CronResponse, type DelayOptions, type Endpoint, type Execution, type InboundEvent, type ListOptions, type ListResponse, type Monitor, type Ping, type PingResponse, Runlater, RunlaterError, type RunlaterOptions, type Schedule, type ScheduleOptions, type SendOptions, type SyncOptions, type SyncResponse, type Task, type TaskResponse, type TriggerResponse, type UpdateEndpointOptions, type UpdateMonitorOptions, type UpdateScheduleOptions, type UpdateTaskOptions };
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ var Runlater = class {
|
|
|
45
45
|
tasks;
|
|
46
46
|
monitors;
|
|
47
47
|
endpoints;
|
|
48
|
+
schedules;
|
|
48
49
|
constructor(options) {
|
|
49
50
|
if (typeof options === "string") {
|
|
50
51
|
this.apiKey = options;
|
|
@@ -56,6 +57,7 @@ var Runlater = class {
|
|
|
56
57
|
this.tasks = new Tasks(this);
|
|
57
58
|
this.monitors = new Monitors(this);
|
|
58
59
|
this.endpoints = new Endpoints(this);
|
|
60
|
+
this.schedules = new Schedules(this);
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
61
63
|
* Send a request immediately with reliable delivery and retries.
|
|
@@ -130,7 +132,7 @@ var Runlater = class {
|
|
|
130
132
|
* ```
|
|
131
133
|
*/
|
|
132
134
|
async cron(name, options) {
|
|
133
|
-
const res = await this.request("POST", "/
|
|
135
|
+
const res = await this.request("POST", "/schedules", {
|
|
134
136
|
body: {
|
|
135
137
|
name,
|
|
136
138
|
url: options.url,
|
|
@@ -153,7 +155,7 @@ var Runlater = class {
|
|
|
153
155
|
*
|
|
154
156
|
* ```js
|
|
155
157
|
* await rl.sync({
|
|
156
|
-
*
|
|
158
|
+
* schedules: [
|
|
157
159
|
* { name: "daily-report", url: "https://...", schedule: "0 9 * * *" }
|
|
158
160
|
* ],
|
|
159
161
|
* deleteRemoved: true
|
|
@@ -162,8 +164,8 @@ var Runlater = class {
|
|
|
162
164
|
*/
|
|
163
165
|
async sync(options) {
|
|
164
166
|
const body = {};
|
|
165
|
-
if (options.
|
|
166
|
-
body.
|
|
167
|
+
if (options.schedules) {
|
|
168
|
+
body.schedules = options.schedules.map((t) => ({
|
|
167
169
|
name: t.url,
|
|
168
170
|
// name defaults to url if not in CronOptions
|
|
169
171
|
url: t.url,
|
|
@@ -220,7 +222,7 @@ var Runlater = class {
|
|
|
220
222
|
const headers = {
|
|
221
223
|
Authorization: `Bearer ${this.apiKey}`,
|
|
222
224
|
"Content-Type": "application/json",
|
|
223
|
-
"User-Agent": "runlater-js/0.
|
|
225
|
+
"User-Agent": "runlater-js/0.11.0"
|
|
224
226
|
};
|
|
225
227
|
if (options.idempotencyKey) {
|
|
226
228
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
@@ -285,29 +287,34 @@ var Tasks = class {
|
|
|
285
287
|
return res.data;
|
|
286
288
|
}
|
|
287
289
|
/**
|
|
288
|
-
* Create many tasks at once
|
|
290
|
+
* Create many tasks at once. Each task defines its own URL and can
|
|
291
|
+
* optionally override method, headers, body, and name. Top-level
|
|
292
|
+
* settings serve as defaults.
|
|
289
293
|
*
|
|
290
|
-
* Each item in the array becomes the request body for one task.
|
|
291
|
-
* All tasks share the same URL, method, headers, timing, and queue.
|
|
292
294
|
* Use the queue name with `cancelQueue()` to cancel them as a group.
|
|
293
295
|
*
|
|
294
296
|
* ```js
|
|
295
297
|
* await rl.tasks.batch({
|
|
296
|
-
* url: "https://myapp.com/api/send-email",
|
|
297
298
|
* queue: "march-newsletter",
|
|
299
|
+
* method: "POST",
|
|
298
300
|
* run_at: "2026-03-01T09:00:00Z",
|
|
299
|
-
*
|
|
300
|
-
* {
|
|
301
|
-
* {
|
|
301
|
+
* tasks: [
|
|
302
|
+
* { url: "https://myapp.com/api/send-email", body: { to: "alice@example.com" } },
|
|
303
|
+
* { url: "https://myapp.com/api/send-sms", body: { to: "+1234567890" } },
|
|
302
304
|
* ]
|
|
303
305
|
* })
|
|
304
306
|
* ```
|
|
305
307
|
*/
|
|
306
308
|
async batch(options) {
|
|
307
309
|
const body = {
|
|
308
|
-
url: options.url,
|
|
309
310
|
queue: options.queue,
|
|
310
|
-
|
|
311
|
+
tasks: options.tasks.map((t) => ({
|
|
312
|
+
url: t.url,
|
|
313
|
+
method: t.method,
|
|
314
|
+
headers: t.headers,
|
|
315
|
+
body: t.body != null ? typeof t.body === "string" ? t.body : JSON.stringify(t.body) : void 0,
|
|
316
|
+
name: t.name
|
|
317
|
+
})),
|
|
311
318
|
method: options.method ?? "POST",
|
|
312
319
|
headers: options.headers,
|
|
313
320
|
timeout_ms: options.timeout,
|
|
@@ -343,6 +350,66 @@ var Tasks = class {
|
|
|
343
350
|
return res.data;
|
|
344
351
|
}
|
|
345
352
|
};
|
|
353
|
+
var Schedules = class {
|
|
354
|
+
constructor(client) {
|
|
355
|
+
this.client = client;
|
|
356
|
+
}
|
|
357
|
+
async list(options = {}) {
|
|
358
|
+
const params = new URLSearchParams();
|
|
359
|
+
if (options.limit != null) params.set("limit", String(options.limit));
|
|
360
|
+
if (options.offset != null) params.set("offset", String(options.offset));
|
|
361
|
+
const query = params.toString();
|
|
362
|
+
return this.client.request("GET", `/schedules${query ? `?${query}` : ""}`);
|
|
363
|
+
}
|
|
364
|
+
async get(id) {
|
|
365
|
+
const res = await this.client.request("GET", `/schedules/${id}`);
|
|
366
|
+
return res.data;
|
|
367
|
+
}
|
|
368
|
+
async create(options) {
|
|
369
|
+
const res = await this.client.request("POST", "/schedules", {
|
|
370
|
+
body: {
|
|
371
|
+
name: options.name,
|
|
372
|
+
url: options.url,
|
|
373
|
+
method: options.method ?? "GET",
|
|
374
|
+
cron: options.cron,
|
|
375
|
+
headers: options.headers,
|
|
376
|
+
body: options.body != null ? JSON.stringify(options.body) : void 0,
|
|
377
|
+
timeout_ms: options.timeout,
|
|
378
|
+
callback_url: options.callback,
|
|
379
|
+
enabled: options.enabled,
|
|
380
|
+
expected_status_codes: options.expected_status_codes,
|
|
381
|
+
expected_body_pattern: options.expected_body_pattern,
|
|
382
|
+
on_failure_url: options.on_failure_url,
|
|
383
|
+
on_recovery_url: options.on_recovery_url,
|
|
384
|
+
script: options.script
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
return res.data;
|
|
388
|
+
}
|
|
389
|
+
async update(id, options) {
|
|
390
|
+
const res = await this.client.request("PUT", `/schedules/${id}`, {
|
|
391
|
+
body: options
|
|
392
|
+
});
|
|
393
|
+
return res.data;
|
|
394
|
+
}
|
|
395
|
+
async delete(id) {
|
|
396
|
+
await this.client.request("DELETE", `/schedules/${id}`);
|
|
397
|
+
}
|
|
398
|
+
async trigger(id) {
|
|
399
|
+
const res = await this.client.request(
|
|
400
|
+
"POST",
|
|
401
|
+
`/schedules/${id}/trigger`
|
|
402
|
+
);
|
|
403
|
+
return res.data;
|
|
404
|
+
}
|
|
405
|
+
async executions(id, limit = 50) {
|
|
406
|
+
const res = await this.client.request(
|
|
407
|
+
"GET",
|
|
408
|
+
`/schedules/${id}/executions?limit=${limit}`
|
|
409
|
+
);
|
|
410
|
+
return res.data;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
346
413
|
var Monitors = class {
|
|
347
414
|
constructor(client) {
|
|
348
415
|
this.client = client;
|
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ var Runlater = class {
|
|
|
18
18
|
tasks;
|
|
19
19
|
monitors;
|
|
20
20
|
endpoints;
|
|
21
|
+
schedules;
|
|
21
22
|
constructor(options) {
|
|
22
23
|
if (typeof options === "string") {
|
|
23
24
|
this.apiKey = options;
|
|
@@ -29,6 +30,7 @@ var Runlater = class {
|
|
|
29
30
|
this.tasks = new Tasks(this);
|
|
30
31
|
this.monitors = new Monitors(this);
|
|
31
32
|
this.endpoints = new Endpoints(this);
|
|
33
|
+
this.schedules = new Schedules(this);
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Send a request immediately with reliable delivery and retries.
|
|
@@ -103,7 +105,7 @@ var Runlater = class {
|
|
|
103
105
|
* ```
|
|
104
106
|
*/
|
|
105
107
|
async cron(name, options) {
|
|
106
|
-
const res = await this.request("POST", "/
|
|
108
|
+
const res = await this.request("POST", "/schedules", {
|
|
107
109
|
body: {
|
|
108
110
|
name,
|
|
109
111
|
url: options.url,
|
|
@@ -126,7 +128,7 @@ var Runlater = class {
|
|
|
126
128
|
*
|
|
127
129
|
* ```js
|
|
128
130
|
* await rl.sync({
|
|
129
|
-
*
|
|
131
|
+
* schedules: [
|
|
130
132
|
* { name: "daily-report", url: "https://...", schedule: "0 9 * * *" }
|
|
131
133
|
* ],
|
|
132
134
|
* deleteRemoved: true
|
|
@@ -135,8 +137,8 @@ var Runlater = class {
|
|
|
135
137
|
*/
|
|
136
138
|
async sync(options) {
|
|
137
139
|
const body = {};
|
|
138
|
-
if (options.
|
|
139
|
-
body.
|
|
140
|
+
if (options.schedules) {
|
|
141
|
+
body.schedules = options.schedules.map((t) => ({
|
|
140
142
|
name: t.url,
|
|
141
143
|
// name defaults to url if not in CronOptions
|
|
142
144
|
url: t.url,
|
|
@@ -193,7 +195,7 @@ var Runlater = class {
|
|
|
193
195
|
const headers = {
|
|
194
196
|
Authorization: `Bearer ${this.apiKey}`,
|
|
195
197
|
"Content-Type": "application/json",
|
|
196
|
-
"User-Agent": "runlater-js/0.
|
|
198
|
+
"User-Agent": "runlater-js/0.11.0"
|
|
197
199
|
};
|
|
198
200
|
if (options.idempotencyKey) {
|
|
199
201
|
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
@@ -258,29 +260,34 @@ var Tasks = class {
|
|
|
258
260
|
return res.data;
|
|
259
261
|
}
|
|
260
262
|
/**
|
|
261
|
-
* Create many tasks at once
|
|
263
|
+
* Create many tasks at once. Each task defines its own URL and can
|
|
264
|
+
* optionally override method, headers, body, and name. Top-level
|
|
265
|
+
* settings serve as defaults.
|
|
262
266
|
*
|
|
263
|
-
* Each item in the array becomes the request body for one task.
|
|
264
|
-
* All tasks share the same URL, method, headers, timing, and queue.
|
|
265
267
|
* Use the queue name with `cancelQueue()` to cancel them as a group.
|
|
266
268
|
*
|
|
267
269
|
* ```js
|
|
268
270
|
* await rl.tasks.batch({
|
|
269
|
-
* url: "https://myapp.com/api/send-email",
|
|
270
271
|
* queue: "march-newsletter",
|
|
272
|
+
* method: "POST",
|
|
271
273
|
* run_at: "2026-03-01T09:00:00Z",
|
|
272
|
-
*
|
|
273
|
-
* {
|
|
274
|
-
* {
|
|
274
|
+
* tasks: [
|
|
275
|
+
* { url: "https://myapp.com/api/send-email", body: { to: "alice@example.com" } },
|
|
276
|
+
* { url: "https://myapp.com/api/send-sms", body: { to: "+1234567890" } },
|
|
275
277
|
* ]
|
|
276
278
|
* })
|
|
277
279
|
* ```
|
|
278
280
|
*/
|
|
279
281
|
async batch(options) {
|
|
280
282
|
const body = {
|
|
281
|
-
url: options.url,
|
|
282
283
|
queue: options.queue,
|
|
283
|
-
|
|
284
|
+
tasks: options.tasks.map((t) => ({
|
|
285
|
+
url: t.url,
|
|
286
|
+
method: t.method,
|
|
287
|
+
headers: t.headers,
|
|
288
|
+
body: t.body != null ? typeof t.body === "string" ? t.body : JSON.stringify(t.body) : void 0,
|
|
289
|
+
name: t.name
|
|
290
|
+
})),
|
|
284
291
|
method: options.method ?? "POST",
|
|
285
292
|
headers: options.headers,
|
|
286
293
|
timeout_ms: options.timeout,
|
|
@@ -316,6 +323,66 @@ var Tasks = class {
|
|
|
316
323
|
return res.data;
|
|
317
324
|
}
|
|
318
325
|
};
|
|
326
|
+
var Schedules = class {
|
|
327
|
+
constructor(client) {
|
|
328
|
+
this.client = client;
|
|
329
|
+
}
|
|
330
|
+
async list(options = {}) {
|
|
331
|
+
const params = new URLSearchParams();
|
|
332
|
+
if (options.limit != null) params.set("limit", String(options.limit));
|
|
333
|
+
if (options.offset != null) params.set("offset", String(options.offset));
|
|
334
|
+
const query = params.toString();
|
|
335
|
+
return this.client.request("GET", `/schedules${query ? `?${query}` : ""}`);
|
|
336
|
+
}
|
|
337
|
+
async get(id) {
|
|
338
|
+
const res = await this.client.request("GET", `/schedules/${id}`);
|
|
339
|
+
return res.data;
|
|
340
|
+
}
|
|
341
|
+
async create(options) {
|
|
342
|
+
const res = await this.client.request("POST", "/schedules", {
|
|
343
|
+
body: {
|
|
344
|
+
name: options.name,
|
|
345
|
+
url: options.url,
|
|
346
|
+
method: options.method ?? "GET",
|
|
347
|
+
cron: options.cron,
|
|
348
|
+
headers: options.headers,
|
|
349
|
+
body: options.body != null ? JSON.stringify(options.body) : void 0,
|
|
350
|
+
timeout_ms: options.timeout,
|
|
351
|
+
callback_url: options.callback,
|
|
352
|
+
enabled: options.enabled,
|
|
353
|
+
expected_status_codes: options.expected_status_codes,
|
|
354
|
+
expected_body_pattern: options.expected_body_pattern,
|
|
355
|
+
on_failure_url: options.on_failure_url,
|
|
356
|
+
on_recovery_url: options.on_recovery_url,
|
|
357
|
+
script: options.script
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
return res.data;
|
|
361
|
+
}
|
|
362
|
+
async update(id, options) {
|
|
363
|
+
const res = await this.client.request("PUT", `/schedules/${id}`, {
|
|
364
|
+
body: options
|
|
365
|
+
});
|
|
366
|
+
return res.data;
|
|
367
|
+
}
|
|
368
|
+
async delete(id) {
|
|
369
|
+
await this.client.request("DELETE", `/schedules/${id}`);
|
|
370
|
+
}
|
|
371
|
+
async trigger(id) {
|
|
372
|
+
const res = await this.client.request(
|
|
373
|
+
"POST",
|
|
374
|
+
`/schedules/${id}/trigger`
|
|
375
|
+
);
|
|
376
|
+
return res.data;
|
|
377
|
+
}
|
|
378
|
+
async executions(id, limit = 50) {
|
|
379
|
+
const res = await this.client.request(
|
|
380
|
+
"GET",
|
|
381
|
+
`/schedules/${id}/executions?limit=${limit}`
|
|
382
|
+
);
|
|
383
|
+
return res.data;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
319
386
|
var Monitors = class {
|
|
320
387
|
constructor(client) {
|
|
321
388
|
this.client = client;
|