@omelhorsite/sdk 0.16.0 → 0.18.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/README.md +1 -1
- package/dist/index.js +540 -19
- package/dist/types/auth/tokens.d.ts +1 -1
- package/dist/types/client.d.ts +3 -0
- package/dist/types/resources/admin/llm.d.ts +34 -0
- package/dist/types/resources/bots.d.ts +394 -0
- package/dist/types/resources/content/news/feeds.d.ts +9 -2
- package/dist/types/resources/content/news/index.d.ts +23 -0
- package/dist/types/resources/content/news/items.d.ts +40 -0
- package/dist/types/resources/content/news/sources.d.ts +61 -5
- package/dist/types/resources/content/notifications.d.ts +1 -1
- package/dist/types/resources/cron.d.ts +319 -26
- package/dist/types/resources/index.d.ts +1 -0
- package/dist/types/resources/search.d.ts +5 -0
- package/dist/types/resources/tools/imageGeneration.d.ts +156 -0
- package/dist/types/resources/tools/index.d.ts +4 -0
- package/package.json +1 -1
|
@@ -38,8 +38,20 @@ export interface NewsSource {
|
|
|
38
38
|
readonly config: Record<string, Json>;
|
|
39
39
|
/** The {@link NewsFeed} it belongs to. */
|
|
40
40
|
readonly news_feed_id: Id;
|
|
41
|
-
/** Which {@link NewsScript} fetches this source. */
|
|
42
|
-
readonly news_script_id: Id;
|
|
41
|
+
/** Which {@link NewsScript} fetches this source, or `null` when a job does. */
|
|
42
|
+
readonly news_script_id: Id | null;
|
|
43
|
+
/**
|
|
44
|
+
* The cron job (`oms.cron.jobs`, with `output` items) that fetches this
|
|
45
|
+
* source instead of a script, and the schedule of that job the source owns:
|
|
46
|
+
* its `cron` comes from `poll_interval_minutes` and its `params` are the
|
|
47
|
+
* source's `config`. `null` for a script source.
|
|
48
|
+
*/
|
|
49
|
+
readonly cron_job_id: Id | null;
|
|
50
|
+
readonly cron_schedule_id: Id | null;
|
|
51
|
+
/** The schedule's cron expression, for a job source. */
|
|
52
|
+
readonly cron: string | null;
|
|
53
|
+
/** Where the job runs, for a job source: `sandbox` or `full`. */
|
|
54
|
+
readonly runtime: "sandbox" | "full" | null;
|
|
43
55
|
/** Minutes between polls. Validated `in: 5..1440`. */
|
|
44
56
|
readonly poll_interval_minutes: number;
|
|
45
57
|
/**
|
|
@@ -67,7 +79,7 @@ export interface NewsSource {
|
|
|
67
79
|
readonly consecutive_failures: number;
|
|
68
80
|
}
|
|
69
81
|
/** Filter columns of `GET /news_sources`, on top of {@link BASE_FILTER_COLUMNS}. */
|
|
70
|
-
export declare const NEWS_SOURCE_FILTER_COLUMNS: readonly ["name", "health", "enabled", "news_feed_id", "news_script_id"];
|
|
82
|
+
export declare const NEWS_SOURCE_FILTER_COLUMNS: readonly ["name", "health", "enabled", "news_feed_id", "news_script_id", "cron_job_id"];
|
|
71
83
|
/** Filters for {@link NewsSourcesNamespace.list}. */
|
|
72
84
|
export interface ListNewsSourcesParams extends ListParams<(typeof NEWS_SOURCE_FILTER_COLUMNS)[number]> {
|
|
73
85
|
/** Only healthy / only broken sources. Sent as `exact_search[health]`. */
|
|
@@ -78,6 +90,8 @@ export interface ListNewsSourcesParams extends ListParams<(typeof NEWS_SOURCE_FI
|
|
|
78
90
|
readonly feedId?: Id;
|
|
79
91
|
/** Every source driven by one script. */
|
|
80
92
|
readonly scriptId?: Id;
|
|
93
|
+
/** Every source driven by one job. */
|
|
94
|
+
readonly jobId?: Id;
|
|
81
95
|
}
|
|
82
96
|
/** Arguments for {@link NewsSourcesNamespace.create}. */
|
|
83
97
|
export interface CreateNewsSourceInput {
|
|
@@ -89,9 +103,17 @@ export interface CreateNewsSourceInput {
|
|
|
89
103
|
* The script that fetches it. Must be a built-in or one of yours;
|
|
90
104
|
* `script_visible_to_owner` rejects anything else with
|
|
91
105
|
* `400 "News script is not accessible"` rather than a 404, so this also
|
|
92
|
-
* tells you the id exists. Do not use it as an existence oracle.
|
|
106
|
+
* tells you the id exists. Do not use it as an existence oracle. Give
|
|
107
|
+
* either this or `jobId`.
|
|
93
108
|
*/
|
|
94
|
-
readonly scriptId
|
|
109
|
+
readonly scriptId?: Id;
|
|
110
|
+
/**
|
|
111
|
+
* A cron job of yours with `output: { kind: "items" }` that fetches it
|
|
112
|
+
* instead of a script. The source gets a schedule of that job: the cron
|
|
113
|
+
* from `pollIntervalMinutes`, the `config` as the run params. `400` when
|
|
114
|
+
* the job has no items output.
|
|
115
|
+
*/
|
|
116
|
+
readonly jobId?: Id;
|
|
95
117
|
/** Whatever that script reads. Free-form; the API validates nothing in it. */
|
|
96
118
|
readonly config?: Record<string, Json>;
|
|
97
119
|
/** 5-1440. Defaults to 15 server-side. */
|
|
@@ -104,11 +126,36 @@ export interface CreateNewsSourceInput {
|
|
|
104
126
|
*
|
|
105
127
|
* One key wider than the create form: `cursor` is updatable and not creatable.
|
|
106
128
|
*/
|
|
129
|
+
/** Arguments for {@link NewsSourcesNamespace.test}: a script, or a sandbox job (its config goes under the given one). */
|
|
130
|
+
export interface TestNewsSourceInput {
|
|
131
|
+
readonly scriptId?: Id;
|
|
132
|
+
readonly jobId?: Id;
|
|
133
|
+
readonly config?: Record<string, Json>;
|
|
134
|
+
}
|
|
135
|
+
export interface NewsSourceTestItem {
|
|
136
|
+
readonly external_id: string;
|
|
137
|
+
readonly title: string;
|
|
138
|
+
readonly url: string | null;
|
|
139
|
+
readonly published_at: Timestamp | null;
|
|
140
|
+
readonly content: string | null;
|
|
141
|
+
}
|
|
142
|
+
/** What a dry run produced. `ok: false` carries the script's error. */
|
|
143
|
+
export interface NewsSourceTest {
|
|
144
|
+
readonly ok: boolean;
|
|
145
|
+
readonly error?: string;
|
|
146
|
+
readonly items: NewsSourceTestItem[];
|
|
147
|
+
readonly count: number;
|
|
148
|
+
/** Items published in the last 30 days. */
|
|
149
|
+
readonly dated: number;
|
|
150
|
+
readonly logs: string[];
|
|
151
|
+
}
|
|
107
152
|
export interface UpdateNewsSourceInput {
|
|
108
153
|
readonly name?: string;
|
|
109
154
|
/** Moves the source (and nothing else: its items stay where they were written) to another of your feeds. */
|
|
110
155
|
readonly newsFeedId?: Id;
|
|
156
|
+
/** Setting a script drops the job (and its schedule); setting a job drops the script. */
|
|
111
157
|
readonly scriptId?: Id;
|
|
158
|
+
readonly jobId?: Id;
|
|
112
159
|
/**
|
|
113
160
|
* REPLACES the whole object; there is no merge. `assign_attributes` writes
|
|
114
161
|
* the JSON column wholesale, so sending `{ url: "..." }` to a source that
|
|
@@ -235,5 +282,14 @@ export declare class NewsSourcesNamespace extends Resource {
|
|
|
235
282
|
* @throws {OmsApiError} 404 `"Resource not found"` when the source is not
|
|
236
283
|
* yours.
|
|
237
284
|
*/
|
|
285
|
+
/**
|
|
286
|
+
* `POST /news_sources/test` - run a script with a config once, with no cursor
|
|
287
|
+
* and without creating anything, and get back the items it would produce.
|
|
288
|
+
* The dry run before creating or repairing a source.
|
|
289
|
+
*
|
|
290
|
+
* @throws {OmsApiError} 400 when the script is not a built-in or one of
|
|
291
|
+
* yours; 502 when the runner is down.
|
|
292
|
+
*/
|
|
293
|
+
test(input: TestNewsSourceInput, options?: RequestOptions): Promise<NewsSourceTest>;
|
|
238
294
|
run(id: Id, options?: RequestOptions): Promise<NewsSourceRunAccepted>;
|
|
239
295
|
}
|
|
@@ -20,7 +20,7 @@ export type NotificationCategory = (typeof NOTIFICATION_CATEGORIES)[number];
|
|
|
20
20
|
* `admin_*` kinds only ever reach administrators. The `_done` / `_failed`
|
|
21
21
|
* pairs of the media tools only reach the account that started the job.
|
|
22
22
|
*/
|
|
23
|
-
export declare const NOTIFICATION_KINDS: readonly ["security_new_session", "security_password_changed", "security_email_changed", "security_passkey_added", "security_app_authorized", "friendship_request", "friendship_accepted", "user_followed", "message_received", "group_chat_message", "jam_invite", "fs_grant_received", "chest_expires_soon", "vocal_separation_done", "vocal_separation_failed", "transcription_done", "transcription_failed", "upscale_done", "upscale_failed", "background_removal_done", "background_removal_failed", "caption_job_done", "caption_job_failed", "jumpstyle_job_done", "jumpstyle_job_failed", "song_import_done", "song_import_failed", "spotify_sync_done", "spotify_sync_failed", "artist_import_done", "blog_new_post", "form_submission_received", "ticket_reply", "ticket_status_changed", "news_source_failing", "cron_run_failed", "cron_run_done", "oauth_application_approved", "oauth_application_rejected", "admin_oauth_application_submitted", "admin_ticket_created", "admin_feedback_received"];
|
|
23
|
+
export declare const NOTIFICATION_KINDS: readonly ["security_new_session", "security_password_changed", "security_email_changed", "security_passkey_added", "security_app_authorized", "friendship_request", "friendship_accepted", "user_followed", "message_received", "group_chat_message", "jam_invite", "fs_grant_received", "chest_expires_soon", "vocal_separation_done", "vocal_separation_failed", "transcription_done", "transcription_failed", "upscale_done", "upscale_failed", "background_removal_done", "background_removal_failed", "caption_job_done", "caption_job_failed", "jumpstyle_job_done", "jumpstyle_job_failed", "song_import_done", "song_import_failed", "spotify_sync_done", "spotify_sync_failed", "artist_import_done", "blog_new_post", "form_submission_received", "ticket_reply", "ticket_status_changed", "news_source_failing", "cron_run_failed", "cron_run_done", "bot_message_received", "bot_needs_human", "oauth_application_approved", "oauth_application_rejected", "admin_oauth_application_submitted", "admin_ticket_created", "admin_feedback_received"];
|
|
24
24
|
/**
|
|
25
25
|
* One of {@link NOTIFICATION_KINDS}.
|
|
26
26
|
*
|
|
@@ -2,25 +2,49 @@
|
|
|
2
2
|
* The `cron` namespace: TypeScript scripts of the signed-in person that the
|
|
3
3
|
* server runs on a schedule.
|
|
4
4
|
*
|
|
5
|
-
* A script is an ES module exporting `run(ctx)`.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* A script is an ES module exporting `run(ctx)`. WHERE it runs follows from
|
|
6
|
+
* what it declares: a job with no scopes runs in the light sandbox (the one
|
|
7
|
+
* the news sources use: no token, no SDK, only a guarded `fetchText` and the
|
|
8
|
+
* HTML/XML helpers, thousands of runs a day); a job with scopes runs in the
|
|
9
|
+
* full runner, with `ctx.oms` authenticated as the owner and, when the job
|
|
10
|
+
* has `network` on, a `ctx.fetch` that goes through the server's guard
|
|
11
|
+
* against private addresses. The base contract (`config`, `params`, `state`,
|
|
12
|
+
* `log`, `fetchText`, `select`, `parseXml`, `htmlText`) is the same in both.
|
|
13
|
+
* What a script keeps in `ctx.state` is stored when a run ends well and
|
|
14
|
+
* handed back on the next one; what it returns is the run's `result`, and
|
|
15
|
+
* `result.summary` is what the listing shows.
|
|
16
|
+
*
|
|
17
|
+
* A job whose `output` is `{ kind: "items" }` returns `{ items, cursor? }`
|
|
18
|
+
* and the server stores the items in the news source the run belongs to.
|
|
19
|
+
*
|
|
20
|
+
* A job has zero or more SCHEDULES ({@link CronSchedule}): each a cron
|
|
21
|
+
* expression in a timezone with its own `params` and switch. A run carries
|
|
22
|
+
* `params`: an object merged over the job's `config` (so the script reads
|
|
23
|
+
* `ctx.config` as usual) and handed on its own as `ctx.params`. They come
|
|
24
|
+
* from the schedule that fired, or from whoever called `run`.
|
|
12
25
|
*
|
|
13
26
|
* Needs the `cron:read` scope to read and `cron:write` to change anything.
|
|
14
|
-
* A job's own token never carries either:
|
|
27
|
+
* A job's own token never carries either; with `cron:run` it may start other
|
|
28
|
+
* jobs.
|
|
15
29
|
*/
|
|
16
30
|
import { Resource, type ApiClient } from "../http";
|
|
17
31
|
import type { ListParams } from "../listing";
|
|
18
|
-
import type { Id, Json, Paginated, RequestOptions, Timestamp } from "../types";
|
|
19
|
-
/**
|
|
20
|
-
|
|
32
|
+
import type { Id, Json, JsonObject, Paginated, RequestOptions, Timestamp } from "../types";
|
|
33
|
+
/**
|
|
34
|
+
* Scopes a job may ask for its token. Anything else answers `400`. `cron:run`
|
|
35
|
+
* lets a script run other jobs (with params) without reading or editing them.
|
|
36
|
+
*/
|
|
37
|
+
export declare const CRON_JOB_SCOPES: readonly ["profile", "news:read", "news:write", "storage:read", "storage:write", "llm", "tools:read", "tools:write", "blogs:read", "blogs:write", "bots:read", "bots:write", "cron:run"];
|
|
21
38
|
export type CronJobScope = (typeof CRON_JOB_SCOPES)[number];
|
|
22
39
|
export declare const CRON_JOB_HEALTHS: readonly ["unknown", "ok", "error"];
|
|
23
40
|
export type CronJobHealth = (typeof CRON_JOB_HEALTHS)[number];
|
|
41
|
+
/** Where a job runs, derived from its scopes: none means the light sandbox. */
|
|
42
|
+
export declare const CRON_JOB_RUNTIMES: readonly ["sandbox", "full"];
|
|
43
|
+
export type CronJobRuntime = (typeof CRON_JOB_RUNTIMES)[number];
|
|
44
|
+
/** What a job's runs produce, when it is not just a result: news items for a source. */
|
|
45
|
+
export interface CronJobOutput {
|
|
46
|
+
readonly kind: "items";
|
|
47
|
+
}
|
|
24
48
|
/** Consecutive failures after which a job switches itself off. Turn `enabled` back on to revive it. */
|
|
25
49
|
export declare const CRON_JOB_DISABLE_AFTER_FAILURES = 10;
|
|
26
50
|
/** Code longer than this answers `400`. */
|
|
@@ -28,8 +52,10 @@ export declare const CRON_JOB_MAX_CODE_BYTES: number;
|
|
|
28
52
|
/** `state` and `config` ceilings. A run whose state grows past this fails and the state is not stored. */
|
|
29
53
|
export declare const CRON_JOB_MAX_STATE_BYTES: number;
|
|
30
54
|
export declare const CRON_JOB_MAX_CONFIG_BYTES: number;
|
|
31
|
-
/** Two
|
|
55
|
+
/** Two occurrences of one schedule must be at least this far apart. */
|
|
32
56
|
export declare const CRON_JOB_MIN_INTERVAL_MINUTES = 5;
|
|
57
|
+
/** Schedules one job may have. */
|
|
58
|
+
export declare const CRON_SCHEDULES_MAX_PER_JOB = 200;
|
|
33
59
|
/** `timeout_seconds` range; above 120 the account needs a trusted tier, like `network`. */
|
|
34
60
|
export declare const CRON_JOB_MIN_TIMEOUT_SECONDS = 5;
|
|
35
61
|
export declare const CRON_JOB_MAX_TIMEOUT_SECONDS = 1200;
|
|
@@ -41,20 +67,27 @@ export interface CronJob {
|
|
|
41
67
|
/** Up to 120 characters, unique per account. */
|
|
42
68
|
readonly name: string;
|
|
43
69
|
readonly description: string | null;
|
|
44
|
-
/**
|
|
45
|
-
readonly schedule: string;
|
|
46
|
-
/**
|
|
70
|
+
/** The cron expression of the job's FIRST schedule, or `null` when it has none. The whole list is in {@link CronJobDetail.schedules}. */
|
|
71
|
+
readonly schedule: string | null;
|
|
72
|
+
/** How many schedules the job has. */
|
|
73
|
+
readonly schedules_count: number;
|
|
74
|
+
/** An IANA zone such as `"Europe/Lisbon"` (the default); the default timezone of new schedules. */
|
|
47
75
|
readonly timezone: string;
|
|
48
|
-
/** The scopes the run's token carries. */
|
|
76
|
+
/** The scopes the run's token carries. Empty means the job runs in the sandbox, with no token. */
|
|
49
77
|
readonly scopes: CronJobScope[];
|
|
78
|
+
/** Derived from `scopes`: `sandbox` when there are none, `full` otherwise. */
|
|
79
|
+
readonly runtime: CronJobRuntime;
|
|
80
|
+
/** `{ kind: "items" }` when the script returns news items the server ingests; `null` for a plain result. */
|
|
81
|
+
readonly output: CronJobOutput | null;
|
|
50
82
|
/** Names of the stored secrets. The values never leave the server. */
|
|
51
83
|
readonly secret_keys: string[];
|
|
52
|
-
/** Whether `ctx.fetch`
|
|
84
|
+
/** Whether `ctx.fetch`/`ctx.fetchText` exist in the script. In the sandbox this needs no trusted tier. */
|
|
53
85
|
readonly network: boolean;
|
|
54
86
|
readonly timeout_seconds: number;
|
|
55
87
|
/** A folder of the owner's storage handed to the script as `ctx.job.outputDirId`. */
|
|
56
88
|
readonly output_dir_id: Id | null;
|
|
57
89
|
readonly enabled: boolean;
|
|
90
|
+
/** The nearest occurrence among the enabled schedules; `null` when the job is off or has none. */
|
|
58
91
|
readonly next_run_at: Timestamp | null;
|
|
59
92
|
readonly last_run_at: Timestamp | null;
|
|
60
93
|
readonly last_success_at: Timestamp | null;
|
|
@@ -67,25 +100,86 @@ export interface CronJob {
|
|
|
67
100
|
/** Whether a run is queued or running right now. */
|
|
68
101
|
readonly running: boolean;
|
|
69
102
|
}
|
|
70
|
-
/**
|
|
103
|
+
/** The types a script may give a variable it declares with `// @var key type Label | description`. */
|
|
104
|
+
export declare const CRON_VAR_TYPES: readonly ["string", "text", "number", "boolean", "list", "json"];
|
|
105
|
+
export type CronVarType = (typeof CRON_VAR_TYPES)[number];
|
|
106
|
+
/**
|
|
107
|
+
* A variable a script declares as editable, parsed by the server from the
|
|
108
|
+
* `// @var` lines at the top of the code. Its value lives in `config[key]`.
|
|
109
|
+
*/
|
|
110
|
+
export interface CronVar {
|
|
111
|
+
readonly key: string;
|
|
112
|
+
readonly type: CronVarType;
|
|
113
|
+
readonly label: string;
|
|
114
|
+
readonly description: string | null;
|
|
115
|
+
}
|
|
116
|
+
/** `GET /cron_jobs/:id` (and every write) adds the code, the config, the state, the declared variables and the schedules. */
|
|
71
117
|
export interface CronJobDetail extends CronJob {
|
|
72
118
|
readonly code: string;
|
|
73
119
|
readonly config: Record<string, Json>;
|
|
74
120
|
readonly state: Record<string, Json>;
|
|
121
|
+
readonly vars: CronVar[];
|
|
122
|
+
/** Oldest first. */
|
|
123
|
+
readonly schedules: CronSchedule[];
|
|
75
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* One schedule of a job: when it fires and with what params. A job may have
|
|
127
|
+
* several (a source per site, a report per feed) or none (run by hand, by
|
|
128
|
+
* the API or by another job).
|
|
129
|
+
*/
|
|
130
|
+
export interface CronSchedule {
|
|
131
|
+
readonly id: Id;
|
|
132
|
+
readonly created_at: Timestamp;
|
|
133
|
+
readonly updated_at: Timestamp;
|
|
134
|
+
readonly cron_job_id: Id;
|
|
135
|
+
/** Optional label, up to 120 characters. */
|
|
136
|
+
readonly name: string | null;
|
|
137
|
+
/** Five-field cron expression, read in `timezone`. */
|
|
138
|
+
readonly cron: string;
|
|
139
|
+
readonly timezone: string;
|
|
140
|
+
/** Handed to every run this schedule starts, merged over the job's config and as `ctx.params`. */
|
|
141
|
+
readonly params: Record<string, Json>;
|
|
142
|
+
/** Off, the schedule does not fire; the job's other schedules still do. */
|
|
143
|
+
readonly enabled: boolean;
|
|
144
|
+
readonly next_run_at: Timestamp | null;
|
|
145
|
+
readonly last_run_at: Timestamp | null;
|
|
146
|
+
}
|
|
147
|
+
export declare const CRON_SCHEDULE_FILTER_COLUMNS: readonly ["cron_job_id", "enabled"];
|
|
148
|
+
export interface ListCronSchedulesParams extends ListParams<(typeof CRON_SCHEDULE_FILTER_COLUMNS)[number]> {
|
|
149
|
+
readonly jobId?: Id;
|
|
150
|
+
readonly enabled?: boolean;
|
|
151
|
+
}
|
|
152
|
+
export interface CreateCronScheduleInput {
|
|
153
|
+
readonly jobId: Id;
|
|
154
|
+
/** Five fields; two occurrences must be at least {@link CRON_JOB_MIN_INTERVAL_MINUTES} apart. */
|
|
155
|
+
readonly cron: string;
|
|
156
|
+
/** Defaults to `"Europe/Lisbon"`. */
|
|
157
|
+
readonly timezone?: string;
|
|
158
|
+
readonly name?: string | null;
|
|
159
|
+
/** Up to 64 KB. */
|
|
160
|
+
readonly params?: Record<string, Json>;
|
|
161
|
+
readonly enabled?: boolean;
|
|
162
|
+
}
|
|
163
|
+
export type UpdateCronScheduleInput = Partial<Omit<CreateCronScheduleInput, "jobId">>;
|
|
76
164
|
export declare const CRON_JOB_FILTER_COLUMNS: readonly ["name", "enabled", "health", "template_slug"];
|
|
77
165
|
export interface ListCronJobsParams extends ListParams<(typeof CRON_JOB_FILTER_COLUMNS)[number]> {
|
|
78
166
|
}
|
|
79
167
|
export interface CreateCronJobInput {
|
|
80
168
|
readonly name: string;
|
|
81
169
|
readonly description?: string | null;
|
|
82
|
-
/**
|
|
83
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Creates the job's first schedule (in `timezone`). Optional: a job with no
|
|
172
|
+
* schedule runs by hand, by the API or by another job. Add more with
|
|
173
|
+
* {@link CronSchedulesNamespace.create}; on update this edits the first one.
|
|
174
|
+
*/
|
|
175
|
+
readonly schedule?: string;
|
|
84
176
|
readonly timezone?: string;
|
|
85
177
|
/** TypeScript. Checked for syntax on the server before it is stored. */
|
|
86
178
|
readonly code: string;
|
|
87
|
-
/** Defaults to every scope but `news:write` and `tools:write`. */
|
|
179
|
+
/** Defaults to every scope but `news:write` and `tools:write`. Pass `[]` for a sandbox job (no token, no SDK). */
|
|
88
180
|
readonly scopes?: readonly CronJobScope[];
|
|
181
|
+
/** `{ kind: "items" }` makes the runs' items go to the news source of each run. `null` removes it. */
|
|
182
|
+
readonly output?: CronJobOutput | null;
|
|
89
183
|
readonly config?: Record<string, Json>;
|
|
90
184
|
/** Stored encrypted; on update the object is MERGED, and a `null` value removes that key. */
|
|
91
185
|
readonly secrets?: Record<string, string | null>;
|
|
@@ -101,16 +195,28 @@ export interface CreateCronJobInput {
|
|
|
101
195
|
export type UpdateCronJobInput = Partial<Omit<CreateCronJobInput, "templateSlug">>;
|
|
102
196
|
export declare const CRON_RUN_STATUSES: readonly ["queued", "running", "ok", "error", "timeout", "skipped"];
|
|
103
197
|
export type CronRunStatus = (typeof CRON_RUN_STATUSES)[number];
|
|
104
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Who asked for a run: a schedule, a person with a session (`manual`), a
|
|
200
|
+
* third-party OAuth token (`api`), another job's run token (`job`), or a test.
|
|
201
|
+
*/
|
|
202
|
+
export declare const CRON_RUN_TRIGGERS: readonly ["schedule", "manual", "api", "job", "test"];
|
|
105
203
|
export type CronRunTrigger = (typeof CRON_RUN_TRIGGERS)[number];
|
|
106
204
|
export interface CronRun {
|
|
107
205
|
readonly id: Id;
|
|
108
206
|
readonly created_at: Timestamp;
|
|
109
207
|
readonly updated_at: Timestamp;
|
|
110
208
|
readonly cron_job_id: Id;
|
|
209
|
+
/** The schedule that fired it, when the trigger is `schedule` and it still exists. */
|
|
210
|
+
readonly cron_schedule_id: Id | null;
|
|
211
|
+
/** The news source that received the items, for runs of a job with `output` items bound to a source. */
|
|
212
|
+
readonly news_source_id: Id | null;
|
|
213
|
+
/** Where it ran; `null` while queued. Sandbox runs do not count towards `cron_run_seconds`. */
|
|
214
|
+
readonly runtime: CronJobRuntime | null;
|
|
111
215
|
readonly status: CronRunStatus;
|
|
112
216
|
/** `test` runs never write the state back and never count as failures. */
|
|
113
217
|
readonly trigger: CronRunTrigger;
|
|
218
|
+
/** Merged over the job's config for this run and handed to the script as `ctx.params`. */
|
|
219
|
+
readonly params: Record<string, Json>;
|
|
114
220
|
readonly scheduled_at: Timestamp;
|
|
115
221
|
readonly started_at: Timestamp | null;
|
|
116
222
|
readonly finished_at: Timestamp | null;
|
|
@@ -136,6 +242,11 @@ export interface ListCronRunsParams extends ListParams<(typeof CRON_RUN_FILTER_C
|
|
|
136
242
|
readonly jobId?: Id;
|
|
137
243
|
readonly status?: CronRunStatus;
|
|
138
244
|
}
|
|
245
|
+
/** What `run` and `test` accept. */
|
|
246
|
+
export interface RunCronJobInput {
|
|
247
|
+
/** Merged over the job's config for this run only; the script also gets them as `ctx.params`. Up to 64 KB. */
|
|
248
|
+
readonly params?: Record<string, Json>;
|
|
249
|
+
}
|
|
139
250
|
/** A ready-made script: copy it into a job with {@link CronJobsNamespace.create}. */
|
|
140
251
|
export interface CronTemplate {
|
|
141
252
|
readonly slug: string;
|
|
@@ -143,10 +254,15 @@ export interface CronTemplate {
|
|
|
143
254
|
readonly description: string;
|
|
144
255
|
/** The schedule the template expects. */
|
|
145
256
|
readonly schedule: string;
|
|
257
|
+
/** Empty for sandbox templates (the news source scripts). */
|
|
146
258
|
readonly scopes: CronJobScope[];
|
|
259
|
+
readonly runtime: CronJobRuntime;
|
|
260
|
+
readonly output: CronJobOutput | null;
|
|
147
261
|
readonly network: boolean;
|
|
148
262
|
/** The config the script reads, with defaults. */
|
|
149
263
|
readonly config: Record<string, Json>;
|
|
264
|
+
/** The variables the template declares as editable (`// @var`). */
|
|
265
|
+
readonly vars: CronVar[];
|
|
150
266
|
/** SHA-256 of the code, so a client can tell an edited copy from a pristine one. */
|
|
151
267
|
readonly hash: string;
|
|
152
268
|
}
|
|
@@ -179,15 +295,33 @@ export declare class CronJobsNamespace extends Resource {
|
|
|
179
295
|
* `POST /cron_jobs/:id/run` - runs now, outside the schedule, as a normal
|
|
180
296
|
* run (the state is stored). `202` with the queued run.
|
|
181
297
|
*
|
|
182
|
-
* @throws {OmsApiError} 400 `this job is already running
|
|
183
|
-
* `error: "limit"` when the day's
|
|
298
|
+
* @throws {OmsApiError} 400 `this job is already running`, or
|
|
299
|
+
* `params must be an object`; 429 `error: "limit"` when the day's
|
|
300
|
+
* `cron_run_seconds` are spent.
|
|
184
301
|
*/
|
|
185
|
-
run(id: Id, options?: RequestOptions): Promise<CronRun>;
|
|
302
|
+
run(id: Id, input?: RunCronJobInput, options?: RequestOptions): Promise<CronRun>;
|
|
186
303
|
/** `POST /cron_jobs/:id/test` - runs now WITHOUT storing the state or counting a failure. `202`. */
|
|
187
|
-
test(id: Id, options?: RequestOptions): Promise<CronRun>;
|
|
304
|
+
test(id: Id, input?: RunCronJobInput, options?: RequestOptions): Promise<CronRun>;
|
|
188
305
|
/** `POST /cron_jobs/check` - the syntax check the server runs before storing code, on its own. */
|
|
189
306
|
check(code: string, options?: RequestOptions): Promise<CronCheckResult>;
|
|
190
307
|
}
|
|
308
|
+
export declare class CronSchedulesNamespace extends Resource {
|
|
309
|
+
/** `GET /cron_schedules` - oldest first, narrowed by job. */
|
|
310
|
+
list(params?: ListCronSchedulesParams, options?: RequestOptions): Promise<Paginated<CronSchedule>>;
|
|
311
|
+
get(id: Id, options?: RequestOptions): Promise<CronSchedule>;
|
|
312
|
+
/**
|
|
313
|
+
* `POST /cron_schedules`. `201`.
|
|
314
|
+
*
|
|
315
|
+
* @throws {OmsApiError} 400 with the sentence: a bad or too frequent cron,
|
|
316
|
+
* an unknown timezone, `params must be an object`,
|
|
317
|
+
* `cron_job_id must be one of your jobs`, or `schedule limit reached`.
|
|
318
|
+
*/
|
|
319
|
+
create(input: CreateCronScheduleInput, options?: RequestOptions): Promise<CronSchedule>;
|
|
320
|
+
/** `PATCH /cron_schedules/:id`. Changing the cron or the timezone recomputes `next_run_at`. */
|
|
321
|
+
update(id: Id, input: UpdateCronScheduleInput, options?: RequestOptions): Promise<CronSchedule>;
|
|
322
|
+
/** `DELETE /cron_schedules/:id`. Past runs keep existing without it. `204`. */
|
|
323
|
+
delete(id: Id, options?: RequestOptions): Promise<void>;
|
|
324
|
+
}
|
|
191
325
|
export declare class CronRunsNamespace extends Resource {
|
|
192
326
|
/** `GET /cron_runs` - newest first. */
|
|
193
327
|
list(params?: ListCronRunsParams, options?: RequestOptions): Promise<Paginated<CronRun>>;
|
|
@@ -201,9 +335,168 @@ export declare class CronTemplatesNamespace extends Resource {
|
|
|
201
335
|
get(slug: string, options?: RequestOptions): Promise<CronTemplateDetail>;
|
|
202
336
|
}
|
|
203
337
|
/** The `cron` namespace, reachable as `oms.cron`. */
|
|
338
|
+
/**
|
|
339
|
+
* A job's small database: rows a script keeps between runs, instead of one
|
|
340
|
+
* JSON file it has to read and rewrite whole to change a line.
|
|
341
|
+
*
|
|
342
|
+
* A row lives in a COLLECTION of the job (`"mentions"`, `"seen"`), under a
|
|
343
|
+
* KEY unique within it, and holds a JSON object. `at` is the row's own
|
|
344
|
+
* instant - the date of the mention, the delivery, the decision - and is what
|
|
345
|
+
* {@link CronRecordsNamespace.list} orders by and
|
|
346
|
+
* {@link CronRecordsNamespace.prune} trims. Writing is an upsert: the data is
|
|
347
|
+
* replaced, and `at` only changes when the write carries one.
|
|
348
|
+
*
|
|
349
|
+
* Reading needs `cron:read` and writing `cron:write`; a script running as the
|
|
350
|
+
* job reaches its OWN job's records with the token it already has.
|
|
351
|
+
*/
|
|
352
|
+
export interface CronRecord {
|
|
353
|
+
readonly id: Id;
|
|
354
|
+
readonly created_at: Timestamp;
|
|
355
|
+
readonly updated_at: Timestamp;
|
|
356
|
+
readonly cron_job_id: Id;
|
|
357
|
+
readonly collection: string;
|
|
358
|
+
readonly key: string;
|
|
359
|
+
readonly data: JsonObject;
|
|
360
|
+
readonly at: Timestamp | null;
|
|
361
|
+
}
|
|
362
|
+
/** Lowercase letters, digits, `-` and `_`, up to this many characters. */
|
|
363
|
+
export declare const CRON_RECORD_COLLECTION_MAX = 64;
|
|
364
|
+
/** Longer keys are shortened by {@link cronRecordKey} before they are sent. */
|
|
365
|
+
export declare const CRON_RECORD_KEY_MAX = 200;
|
|
366
|
+
/** A row's `data`, serialised. */
|
|
367
|
+
export declare const CRON_RECORD_MAX_DATA_BYTES: number;
|
|
368
|
+
/** Rows one job may hold. Past it new keys are refused; the ones already there still update. */
|
|
369
|
+
export declare const CRON_RECORD_MAX_PER_JOB = 200000;
|
|
370
|
+
/** Rows one write may carry. {@link CronRecordsNamespace.putMany} splits longer lists. */
|
|
371
|
+
export declare const CRON_RECORD_MAX_PER_BATCH = 500;
|
|
372
|
+
/** Rows one {@link CronRecordsNamespace.prune} deletes. Call it again until it answers `0`. */
|
|
373
|
+
export declare const CRON_RECORD_MAX_PER_DELETE = 10000;
|
|
374
|
+
/** `where` fields one listing may compare. */
|
|
375
|
+
export declare const CRON_RECORD_MAX_WHERE = 5;
|
|
376
|
+
export declare const CRON_RECORD_MAX_LIMIT = 500;
|
|
377
|
+
/** What a listing sorts by. Descending unless the suffix says otherwise; rows without an `at` come last either way. */
|
|
378
|
+
export type CronRecordOrder = "at" | "at:asc" | "at:desc" | "updated_at" | "updated_at:asc" | "updated_at:desc";
|
|
379
|
+
export interface ListCronRecordsParams {
|
|
380
|
+
readonly collection: string;
|
|
381
|
+
/** 1 to {@link CRON_RECORD_MAX_LIMIT}; 50 by default. */
|
|
382
|
+
readonly limit?: number;
|
|
383
|
+
/** The `next_cursor` of the previous page. */
|
|
384
|
+
readonly cursor?: string | null;
|
|
385
|
+
/** Over `at`, inclusive. A row without an `at` is outside both. */
|
|
386
|
+
readonly since?: string | Date;
|
|
387
|
+
readonly until?: string | Date;
|
|
388
|
+
/** Fetch several rows at once. Long keys are shortened as {@link CronRecordsNamespace.put} shortens them. */
|
|
389
|
+
readonly keys?: readonly string[];
|
|
390
|
+
/** Equality against `data->>field`, as text. At most {@link CRON_RECORD_MAX_WHERE} fields. */
|
|
391
|
+
readonly where?: Readonly<Record<string, string | number | boolean>>;
|
|
392
|
+
readonly order?: CronRecordOrder;
|
|
393
|
+
/** Ask for `count`: how many rows the filter matches, not just this page. */
|
|
394
|
+
readonly count?: boolean;
|
|
395
|
+
}
|
|
396
|
+
export interface CronRecordPage {
|
|
397
|
+
readonly records: CronRecord[];
|
|
398
|
+
/** `null` on the last page. */
|
|
399
|
+
readonly next_cursor: string | null;
|
|
400
|
+
/** `null` unless the request asked for it. */
|
|
401
|
+
readonly count: number | null;
|
|
402
|
+
}
|
|
403
|
+
export interface CronRecordInput {
|
|
404
|
+
readonly collection: string;
|
|
405
|
+
readonly key: string;
|
|
406
|
+
/** Up to {@link CRON_RECORD_MAX_DATA_BYTES} serialised. Defaults to `{}`. */
|
|
407
|
+
readonly data?: JsonObject;
|
|
408
|
+
/** The row's own instant. Left out, a row that already exists keeps the one it has. */
|
|
409
|
+
readonly at?: string | Date | null;
|
|
410
|
+
}
|
|
411
|
+
export interface CronRecordWriteResult {
|
|
412
|
+
readonly created: number;
|
|
413
|
+
readonly updated: number;
|
|
414
|
+
}
|
|
415
|
+
export interface CronRecordDeleteResult {
|
|
416
|
+
readonly deleted: number;
|
|
417
|
+
}
|
|
418
|
+
/** One collection of a job, as {@link CronRecordsNamespace.collections} reports it. */
|
|
419
|
+
export interface CronRecordCollection {
|
|
420
|
+
readonly collection: string;
|
|
421
|
+
readonly count: number;
|
|
422
|
+
readonly first_at: Timestamp | null;
|
|
423
|
+
readonly last_at: Timestamp | null;
|
|
424
|
+
readonly updated_at: Timestamp;
|
|
425
|
+
}
|
|
426
|
+
export interface PruneCronRecordsOptions {
|
|
427
|
+
/** Delete the rows at or before this instant. */
|
|
428
|
+
readonly before: string | Date;
|
|
429
|
+
/** Which instant to read: the row's own (default) or the last write. */
|
|
430
|
+
readonly on?: "at" | "updated_at";
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* The key the server stores for a value. Anything past
|
|
434
|
+
* {@link CRON_RECORD_KEY_MAX} keeps its start and gains a fingerprint of the
|
|
435
|
+
* whole, so a link stays a usable key and always resolves to the same row.
|
|
436
|
+
*
|
|
437
|
+
* @throws {TypeError} on a runtime without WebCrypto, and only for a value
|
|
438
|
+
* long enough to need shortening.
|
|
439
|
+
*/
|
|
440
|
+
export declare function cronRecordKey(value: string): Promise<string>;
|
|
441
|
+
export declare class CronRecordsNamespace extends Resource {
|
|
442
|
+
/**
|
|
443
|
+
* `GET /cron_jobs/:id/records` - one page of a collection, newest first,
|
|
444
|
+
* paged by cursor rather than by offset so writes in between neither repeat
|
|
445
|
+
* nor skip a row.
|
|
446
|
+
*
|
|
447
|
+
* @throws {OmsApiError} 400 for a missing or malformed `collection`, a
|
|
448
|
+
* `limit` outside 1..500, an unknown `order`, an unparsable date, a
|
|
449
|
+
* cursor from somewhere else, or more than 5 `where` fields.
|
|
450
|
+
*/
|
|
451
|
+
list(jobId: Id, params: ListCronRecordsParams, options?: RequestOptions): Promise<CronRecordPage>;
|
|
452
|
+
/** Every row of a collection, page after page. The filters of {@link list} apply. */
|
|
453
|
+
all(jobId: Id, collection: string, params?: Omit<ListCronRecordsParams, "collection" | "cursor" | "count">, options?: RequestOptions): AsyncGenerator<CronRecord>;
|
|
454
|
+
/** One row, or `null` when the collection has no such key. */
|
|
455
|
+
get(jobId: Id, collection: string, key: string, options?: RequestOptions): Promise<CronRecord | null>;
|
|
456
|
+
/** `POST /cron_jobs/:id/records` - creates or replaces one row. */
|
|
457
|
+
put(jobId: Id, collection: string, key: string, data?: JsonObject, at?: string | Date | null, options?: RequestOptions): Promise<CronRecordWriteResult>;
|
|
458
|
+
/**
|
|
459
|
+
* Creates or replaces many rows. Each request is one transaction; a list
|
|
460
|
+
* longer than {@link CRON_RECORD_MAX_PER_BATCH} goes in several, so a
|
|
461
|
+
* failure part-way leaves the batches before it written.
|
|
462
|
+
*
|
|
463
|
+
* @throws {OmsApiError} 400 for a bad collection, an empty or too long key,
|
|
464
|
+
* `data` that is not an object or is past the size ceiling, or
|
|
465
|
+
* `record limit reached` when the job is full.
|
|
466
|
+
*/
|
|
467
|
+
putMany(jobId: Id, records: readonly CronRecordInput[], options?: RequestOptions): Promise<CronRecordWriteResult>;
|
|
468
|
+
/** `DELETE /cron_jobs/:id/records` - one row. `deleted` is `0` when there was none. */
|
|
469
|
+
remove(jobId: Id, collection: string, key: string, options?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
470
|
+
/** Several rows by key, in one request. */
|
|
471
|
+
removeMany(jobId: Id, collection: string, keys: readonly string[], options?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
472
|
+
/**
|
|
473
|
+
* Deletes the old rows of a collection, up to
|
|
474
|
+
* {@link CRON_RECORD_MAX_PER_DELETE} per call - call it again while
|
|
475
|
+
* `deleted` comes back full.
|
|
476
|
+
*/
|
|
477
|
+
prune(jobId: Id, collection: string, options: PruneCronRecordsOptions, requestOptions?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
478
|
+
/** `GET /cron_jobs/:id/records/collections` - what the job holds, by name. */
|
|
479
|
+
collections(jobId: Id, options?: RequestOptions): Promise<CronRecordCollection[]>;
|
|
480
|
+
/** The same methods bound to one job, which is what a running script is handed. */
|
|
481
|
+
for(jobId: Id): BoundCronRecords;
|
|
482
|
+
}
|
|
483
|
+
/** {@link CronRecordsNamespace} with the job already filled in. */
|
|
484
|
+
export interface BoundCronRecords {
|
|
485
|
+
list(params: ListCronRecordsParams, options?: RequestOptions): Promise<CronRecordPage>;
|
|
486
|
+
all(collection: string, params?: Omit<ListCronRecordsParams, "collection" | "cursor" | "count">, options?: RequestOptions): AsyncGenerator<CronRecord>;
|
|
487
|
+
get(collection: string, key: string, options?: RequestOptions): Promise<CronRecord | null>;
|
|
488
|
+
put(collection: string, key: string, data?: JsonObject, at?: string | Date | null, options?: RequestOptions): Promise<CronRecordWriteResult>;
|
|
489
|
+
putMany(records: readonly CronRecordInput[], options?: RequestOptions): Promise<CronRecordWriteResult>;
|
|
490
|
+
remove(collection: string, key: string, options?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
491
|
+
removeMany(collection: string, keys: readonly string[], options?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
492
|
+
prune(collection: string, options: PruneCronRecordsOptions, requestOptions?: RequestOptions): Promise<CronRecordDeleteResult>;
|
|
493
|
+
collections(options?: RequestOptions): Promise<CronRecordCollection[]>;
|
|
494
|
+
}
|
|
204
495
|
export declare class CronNamespace extends Resource {
|
|
205
496
|
readonly jobs: CronJobsNamespace;
|
|
497
|
+
readonly schedules: CronSchedulesNamespace;
|
|
206
498
|
readonly runs: CronRunsNamespace;
|
|
207
499
|
readonly templates: CronTemplatesNamespace;
|
|
500
|
+
readonly records: CronRecordsNamespace;
|
|
208
501
|
constructor(http: ApiClient);
|
|
209
502
|
}
|
|
@@ -123,6 +123,11 @@ export interface SearchPage {
|
|
|
123
123
|
readonly title: string;
|
|
124
124
|
/** Plain text, whitespace collapsed, cut at `maxChars`. Never empty: a page with nothing readable is a `422`. */
|
|
125
125
|
readonly text: string;
|
|
126
|
+
/**
|
|
127
|
+
* When the page says it was published (`article:published_time`, JSON-LD
|
|
128
|
+
* `datePublished`, a `<time datetime>`), as ISO 8601; `null` when it does not.
|
|
129
|
+
*/
|
|
130
|
+
readonly published_at: string | null;
|
|
126
131
|
}
|
|
127
132
|
/** The `search` namespace, reachable as `oms.search`. */
|
|
128
133
|
export declare class SearchNamespace extends Resource {
|