@ctrl/sabnzbd 0.0.1

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.
@@ -0,0 +1,328 @@
1
+ import { type AddNzbOptions as NormalizedAddNzbOptions, type AllClientData, type Category, type FoundUsenetJob, type NormalizedUsenetHistoryItem, type NormalizedUsenetJob, type NzbInput, type Script, type UsenetClient, type UsenetClientConfig, type UsenetClientState, UsenetPriority } from '@ctrl/shared-usenet';
2
+ import type { Jsonify } from 'type-fest';
3
+ import type { SabAddOptions, SabAddResponse, SabAuthResponse, SabFilesResponse, SabFullStatus, SabHistory, SabHistoryQuery, SabQueue, SabQueueQuery, SabServerStats, SabWarning } from './types.js';
4
+ interface SabnzbdState extends UsenetClientState {
5
+ auth?: {
6
+ apiKey?: string;
7
+ nzbKey?: string;
8
+ };
9
+ version?: {
10
+ version: string;
11
+ };
12
+ }
13
+ export declare class Sabnzbd implements UsenetClient {
14
+ static createFromState(config: Readonly<UsenetClientConfig>, state: Readonly<Jsonify<SabnzbdState>>): Sabnzbd;
15
+ config: UsenetClientConfig;
16
+ state: SabnzbdState;
17
+ constructor(options?: Partial<UsenetClientConfig>);
18
+ exportState(): Jsonify<SabnzbdState>;
19
+ /**
20
+ * Verifies configured credentials against the SABnzbd API.
21
+ *
22
+ * Calls SABnzbd `mode=auth`.
23
+ *
24
+ * @returns The raw SABnzbd authentication response.
25
+ */
26
+ auth(): Promise<SabAuthResponse>;
27
+ /**
28
+ * Reads the SABnzbd version string.
29
+ *
30
+ * Calls SABnzbd `mode=version`.
31
+ *
32
+ * @returns The SABnzbd version.
33
+ */
34
+ getVersion(): Promise<string>;
35
+ /**
36
+ * Loads full server and queue status details from SABnzbd.
37
+ *
38
+ * Calls SABnzbd `mode=fullstatus` with `skip_dashboard=1`.
39
+ *
40
+ * @returns The full status payload.
41
+ */
42
+ getFullStatus(): Promise<SabFullStatus>;
43
+ /**
44
+ * Retrieves the current SABnzbd warning list.
45
+ *
46
+ * Calls SABnzbd `mode=warnings`.
47
+ *
48
+ * @returns All active warnings.
49
+ */
50
+ getWarnings(): Promise<SabWarning[]>;
51
+ /**
52
+ * Retrieves per-server traffic totals from SABnzbd.
53
+ *
54
+ * Calls SABnzbd `mode=server_stats`.
55
+ *
56
+ * @returns Aggregate and per-server transfer statistics.
57
+ */
58
+ getServerStats(): Promise<SabServerStats>;
59
+ /**
60
+ * Lists queue entries, optionally filtered and paged.
61
+ *
62
+ * Calls SABnzbd `mode=queue`.
63
+ *
64
+ * @param query Optional queue filters and pagination controls.
65
+ * @returns The raw queue payload including `slots`.
66
+ */
67
+ listQueue(query?: SabQueueQuery): Promise<SabQueue>;
68
+ /**
69
+ * Lists history entries, optionally filtered and paged.
70
+ *
71
+ * Calls SABnzbd `mode=history`.
72
+ *
73
+ * @param query Optional history filters, pagination, and archive controls.
74
+ * @returns The raw history payload including `slots`.
75
+ */
76
+ listHistory(query?: SabHistoryQuery): Promise<SabHistory>;
77
+ /**
78
+ * Retrieves configured SABnzbd categories.
79
+ *
80
+ * Calls SABnzbd `mode=get_cats`.
81
+ *
82
+ * @returns Categories normalized to shared `Category` objects.
83
+ */
84
+ getCategories(): Promise<Category[]>;
85
+ /**
86
+ * Retrieves configured SABnzbd post-processing scripts.
87
+ *
88
+ * Calls SABnzbd `mode=get_scripts`.
89
+ *
90
+ * @returns Scripts normalized to shared `Script` objects.
91
+ */
92
+ getScripts(): Promise<Script[]>;
93
+ /**
94
+ * Pauses the global download queue.
95
+ *
96
+ * Calls SABnzbd `mode=pause`.
97
+ *
98
+ * @returns `true` when SABnzbd accepts the pause command.
99
+ */
100
+ pauseQueue(): Promise<boolean>;
101
+ /**
102
+ * Resumes the global download queue.
103
+ *
104
+ * Calls SABnzbd `mode=resume`.
105
+ *
106
+ * @returns `true` when SABnzbd accepts the resume command.
107
+ */
108
+ resumeQueue(): Promise<boolean>;
109
+ /**
110
+ * Requests SABnzbd shutdown.
111
+ *
112
+ * Calls SABnzbd `mode=shutdown`.
113
+ *
114
+ * @returns `true` when SABnzbd accepts the shutdown command.
115
+ */
116
+ shutdown(): Promise<boolean>;
117
+ /**
118
+ * Requests a standard SABnzbd restart.
119
+ *
120
+ * Calls SABnzbd `mode=restart`.
121
+ *
122
+ * @returns `true` when SABnzbd accepts the restart command.
123
+ */
124
+ restart(): Promise<boolean>;
125
+ /**
126
+ * Requests SABnzbd restart with queue repair.
127
+ *
128
+ * Calls SABnzbd `mode=restart_repair`.
129
+ *
130
+ * @returns `true` when SABnzbd accepts the repair restart command.
131
+ */
132
+ restartRepair(): Promise<boolean>;
133
+ /**
134
+ * Pauses post-processing tasks.
135
+ *
136
+ * Calls SABnzbd `mode=pause_pp`.
137
+ *
138
+ * @returns `true` when SABnzbd accepts the post-processing pause command.
139
+ */
140
+ pausePostProcessing(): Promise<boolean>;
141
+ /**
142
+ * Resumes post-processing tasks.
143
+ *
144
+ * Calls SABnzbd `mode=resume_pp`.
145
+ *
146
+ * @returns `true` when SABnzbd accepts the post-processing resume command.
147
+ */
148
+ resumePostProcessing(): Promise<boolean>;
149
+ /**
150
+ * Triggers immediate RSS processing.
151
+ *
152
+ * Calls SABnzbd `mode=rss_now`.
153
+ *
154
+ * @returns `true` when SABnzbd accepts the RSS trigger command.
155
+ */
156
+ fetchRss(): Promise<boolean>;
157
+ /**
158
+ * Triggers an immediate scan of the watched folder.
159
+ *
160
+ * Calls SABnzbd `mode=watched_now`.
161
+ *
162
+ * @returns `true` when SABnzbd accepts the watched-folder scan command.
163
+ */
164
+ scanWatchedFolder(): Promise<boolean>;
165
+ /**
166
+ * Resets SABnzbd quota counters.
167
+ *
168
+ * Calls SABnzbd `mode=reset_quota`.
169
+ *
170
+ * @returns `true` when SABnzbd accepts the quota reset command.
171
+ */
172
+ resetQuota(): Promise<boolean>;
173
+ /**
174
+ * Clears currently active warnings.
175
+ *
176
+ * Calls SABnzbd `mode=warnings` with `name=clear`.
177
+ *
178
+ * @returns `true` when SABnzbd accepts the warning clear command.
179
+ */
180
+ clearWarnings(): Promise<boolean>;
181
+ /**
182
+ * Pauses a queue job by its SAB `nzo_id`.
183
+ *
184
+ * Calls SABnzbd `mode=queue` with `name=pause`.
185
+ *
186
+ * @param id SAB queue job identifier (`nzo_id`).
187
+ * @returns `true` when SABnzbd accepts the job pause command.
188
+ */
189
+ pauseJob(id: string): Promise<boolean>;
190
+ /**
191
+ * Resumes a queue job by its SAB `nzo_id`.
192
+ *
193
+ * Calls SABnzbd `mode=queue` with `name=resume`.
194
+ *
195
+ * @param id SAB queue job identifier (`nzo_id`).
196
+ * @returns `true` when SABnzbd accepts the job resume command.
197
+ */
198
+ resumeJob(id: string): Promise<boolean>;
199
+ /**
200
+ * Deletes a queue job by its SAB `nzo_id`.
201
+ *
202
+ * Calls SABnzbd `mode=queue` with `name=delete`.
203
+ *
204
+ * @param id SAB queue job identifier (`nzo_id`).
205
+ * @param deleteFiles When `true`, also remove downloaded data files; defaults to `false`.
206
+ * @returns `true` when SABnzbd accepts the delete command.
207
+ */
208
+ deleteJob(id: string, deleteFiles?: boolean): Promise<boolean>;
209
+ /**
210
+ * Moves a queue job to a target position.
211
+ *
212
+ * Calls SABnzbd `mode=switch`.
213
+ *
214
+ * @param id SAB queue job identifier (`nzo_id`).
215
+ * @param position Target zero-based queue position.
216
+ * @returns `true` when SABnzbd accepts the move command.
217
+ */
218
+ moveJob(id: string, position: number): Promise<boolean>;
219
+ /**
220
+ * Changes a queue job category.
221
+ *
222
+ * Calls SABnzbd `mode=change_cat`.
223
+ *
224
+ * @param id SAB queue job identifier (`nzo_id`).
225
+ * @param category SAB category name.
226
+ * @returns `true` when SABnzbd accepts the category change.
227
+ */
228
+ changeCategory(id: string, category: string): Promise<boolean>;
229
+ /**
230
+ * Changes a queue job post-processing script.
231
+ *
232
+ * Calls SABnzbd `mode=change_script`.
233
+ *
234
+ * @param id SAB queue job identifier (`nzo_id`).
235
+ * @param script SAB configured script name.
236
+ * @returns `true` when SABnzbd accepts the script change.
237
+ */
238
+ changeScript(id: string, script: string): Promise<boolean>;
239
+ /**
240
+ * Changes queue job priority.
241
+ *
242
+ * Calls SABnzbd `mode=queue` with `name=priority`.
243
+ *
244
+ * @param id SAB queue job identifier (`nzo_id`).
245
+ * @param priority Shared normalized priority value.
246
+ * @returns The new queue position when reported by SABnzbd, otherwise `undefined`.
247
+ */
248
+ changePriority(id: string, priority: UsenetPriority): Promise<number | undefined>;
249
+ /**
250
+ * Changes queue job post-processing options.
251
+ *
252
+ * Calls SABnzbd `mode=change_opts`.
253
+ *
254
+ * @param id SAB queue job identifier (`nzo_id`).
255
+ * @param postProcess Normalized post-processing mode to apply.
256
+ * @returns `true` when SABnzbd accepts the option change.
257
+ */
258
+ changePostProcess(id: string, postProcess: NormalizedAddNzbOptions['postProcess']): Promise<boolean>;
259
+ /**
260
+ * Renames a queue job and optionally sets an archive password.
261
+ *
262
+ * Calls SABnzbd `mode=rename`.
263
+ *
264
+ * @param id SAB queue job identifier (`nzo_id`).
265
+ * @param name New queue job name.
266
+ * @param password Optional archive password; defaults to an empty string.
267
+ * @returns `true` when SABnzbd accepts the rename command.
268
+ */
269
+ renameJob(id: string, name: string, password?: string): Promise<boolean>;
270
+ /**
271
+ * Lists files for a queue job.
272
+ *
273
+ * Calls SABnzbd `mode=get_files`.
274
+ *
275
+ * @param id SAB queue job identifier (`nzo_id`).
276
+ * @returns The raw file listing payload.
277
+ */
278
+ getFiles(id: string): Promise<SabFilesResponse>;
279
+ /**
280
+ * Sets the global download speed limit.
281
+ *
282
+ * Calls SABnzbd `mode=config` with `name=speedlimit`.
283
+ *
284
+ * @param limit Speed limit value passed directly to SABnzbd.
285
+ * @returns `true` when SABnzbd accepts the speed limit update.
286
+ */
287
+ setSpeedLimit(limit: string | number): Promise<boolean>;
288
+ /**
289
+ * Adds an NZB to the queue from a URL.
290
+ *
291
+ * Calls SABnzbd `mode=addurl`.
292
+ *
293
+ * @param url Remote NZB URL.
294
+ * @param options Optional SAB add fields; defaults include `category="*"`, `script="Default"`,
295
+ * `priority=-100`, and `postProcess=-1`.
296
+ * @returns The raw SAB add response containing status and optional `nzo_ids`.
297
+ */
298
+ addUrl(url: string, options?: SabAddOptions): Promise<SabAddResponse>;
299
+ /**
300
+ * Adds an NZB to the queue by file upload.
301
+ *
302
+ * Calls SABnzbd `mode=addfile`.
303
+ *
304
+ * @param nzb NZB XML content as text or bytes.
305
+ * @param options Optional SAB add fields; defaults include `category="*"`, `script="Default"`,
306
+ * `priority=-100`, and `postProcess=-1`.
307
+ * @returns The raw SAB add response containing status and optional `nzo_ids`.
308
+ */
309
+ addFile(nzb: string | Uint8Array, options?: SabAddOptions): Promise<SabAddResponse>;
310
+ getQueue(): Promise<NormalizedUsenetJob[]>;
311
+ getHistory(): Promise<NormalizedUsenetHistoryItem[]>;
312
+ getQueueJob(id: string): Promise<NormalizedUsenetJob>;
313
+ getHistoryJob(id: string): Promise<NormalizedUsenetHistoryItem>;
314
+ findJob(id: string): Promise<FoundUsenetJob | null>;
315
+ getAllData(): Promise<AllClientData>;
316
+ removeJob(id: string, removeData?: boolean): Promise<boolean>;
317
+ setCategory(id: string, category: string): Promise<boolean>;
318
+ setPriority(id: string, priority: UsenetPriority): Promise<boolean>;
319
+ addNzbFile(nzb: string | Uint8Array, options?: Partial<NormalizedAddNzbOptions>): Promise<string>;
320
+ addNzbUrl(url: string, options?: Partial<NormalizedAddNzbOptions>): Promise<string>;
321
+ normalizedAddNzb(input: NzbInput, options?: Partial<NormalizedAddNzbOptions>): Promise<NormalizedUsenetJob>;
322
+ private waitForQueueJob;
323
+ private normalizeAddOptions;
324
+ private request;
325
+ private getAuthQuery;
326
+ private assertSabResponse;
327
+ }
328
+ export {};