@ctrl/transmission 7.1.0 → 7.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/README.md CHANGED
@@ -26,13 +26,15 @@ async function main() {
26
26
 
27
27
  ### Api
28
28
 
29
- Docs: https://transmission.vercel.app
30
- API Docs: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt
29
+ Docs: https://transmission.vercel.app
30
+ API Docs: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt
31
31
 
32
32
  ### Normalized API
33
+
33
34
  These functions have been normalized between torrent clients. Can easily support multiple torrent clients. See below for alternative supported torrent clients
34
35
 
35
36
  ##### getAllData
37
+
36
38
  Returns all torrent data and an array of label objects. Data has been normalized and does not match the output of native `listTorrents()`.
37
39
 
38
40
  ```ts
@@ -41,6 +43,7 @@ console.log(data.torrents);
41
43
  ```
42
44
 
43
45
  ##### getTorrent
46
+
44
47
  Returns one torrent data
45
48
 
46
49
  ```ts
@@ -49,6 +52,7 @@ console.log(data);
49
52
  ```
50
53
 
51
54
  ##### pauseTorrent and resumeTorrent
55
+
52
56
  Pause or resume a torrent
53
57
 
54
58
  ```ts
@@ -59,6 +63,7 @@ console.log(resumed);
59
63
  ```
60
64
 
61
65
  ##### removeTorrent
66
+
62
67
  Remove a torrent. Does not remove data on disk by default.
63
68
 
64
69
  ```ts
@@ -71,12 +76,22 @@ const res = await client.removeTorrent('torrent_id', true);
71
76
  console.log(res);
72
77
  ```
73
78
 
79
+ ##### export and create from state
80
+
81
+ If you're shutting down the server often (serverless?) you can export the state
82
+
83
+ ```ts
84
+ const state = client.exportState();
85
+ const client = Transmission.createFromState(config, state);
86
+ ```
87
+
74
88
  ### See Also
75
- All of the following npm modules provide the same normalized functions along with supporting the unique apis for each client.
89
+
90
+ All of the following npm modules provide the same normalized functions along with supporting the unique apis for each client.
76
91
 
77
92
  deluge - https://github.com/scttcper/deluge
78
93
  qbittorrent - https://github.com/scttcper/qbittorrent
79
- utorrent - https://github.com/scttcper/utorrent
94
+ utorrent - https://github.com/scttcper/utorrent
80
95
 
81
96
  ### Start a test docker container
82
97
 
@@ -1,10 +1,18 @@
1
1
  import { ofetch } from 'ofetch';
2
- import type { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentSettings } from '@ctrl/shared-torrent';
2
+ import type { Jsonify } from 'type-fest';
3
+ import type { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentClientConfig, TorrentClientState } from '@ctrl/shared-torrent';
3
4
  import type { AddTorrentOptions, AddTorrentResponse, DefaultResponse, FreeSpaceResponse, GetTorrentRepsonse, NormalizedTorrentIds, RenamePathOptions, SessionArguments, SessionResponse, SetTorrentOptions } from './types.js';
5
+ interface TransmissionState extends TorrentClientState {
6
+ auth?: {
7
+ sessionId: string;
8
+ };
9
+ }
4
10
  export declare class Transmission implements TorrentClient {
5
- config: TorrentSettings;
6
- sessionId?: string;
7
- constructor(options?: Partial<TorrentSettings>);
11
+ static createFromState(config: Readonly<TorrentClientConfig>, state: Readonly<Jsonify<TransmissionState>>): Transmission;
12
+ config: TorrentClientConfig;
13
+ state: TransmissionState;
14
+ constructor(options?: Partial<TorrentClientConfig>);
15
+ exportState(): Jsonify<TransmissionState>;
8
16
  getSession(): Promise<SessionResponse>;
9
17
  setSession(args: Partial<SessionArguments>): Promise<SessionResponse>;
10
18
  queueTop(id: NormalizedTorrentIds): Promise<DefaultResponse>;
@@ -48,11 +56,12 @@ export declare class Transmission implements TorrentClient {
48
56
  * Adding a torrent
49
57
  * @param torrent a stream of file content or contents of the file as base64 string
50
58
  */
51
- addTorrent(torrent: string | Uint8Array, options?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
52
- normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
59
+ addTorrent(torrent: string | Uint8Array<ArrayBuffer>, options?: Partial<AddTorrentOptions>): Promise<AddTorrentResponse>;
60
+ normalizedAddTorrent(torrent: string | Uint8Array<ArrayBuffer>, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
53
61
  getTorrent(id: NormalizedTorrentIds): Promise<NormalizedTorrent>;
54
62
  getAllData(): Promise<AllClientData>;
55
63
  listTorrents(id?: NormalizedTorrentIds, additionalFields?: string[]): Promise<GetTorrentRepsonse>;
56
64
  request<T>(method: string, args?: any): Promise<ReturnType<typeof ofetch.raw<T>>>;
57
65
  private _handleNormalizedIds;
58
66
  }
67
+ export {};
@@ -11,11 +11,24 @@ const defaults = {
11
11
  timeout: 5000,
12
12
  };
13
13
  export class Transmission {
14
+ static createFromState(config, state) {
15
+ const client = new Transmission(config);
16
+ client.state = {
17
+ ...state,
18
+ auth: {
19
+ sessionId: state.auth?.sessionId,
20
+ },
21
+ };
22
+ return client;
23
+ }
14
24
  config;
15
- sessionId;
25
+ state = {};
16
26
  constructor(options = {}) {
17
27
  this.config = { ...defaults, ...options };
18
28
  }
29
+ exportState() {
30
+ return JSON.parse(JSON.stringify(this.state));
31
+ }
19
32
  async getSession() {
20
33
  const res = await this.request('session-get');
21
34
  return res._data;
@@ -276,11 +289,11 @@ export class Transmission {
276
289
  return res._data;
277
290
  }
278
291
  async request(method, args = {}) {
279
- if (!this.sessionId && method !== 'session-get') {
292
+ if (!this.state.auth?.sessionId && method !== 'session-get') {
280
293
  await this.getSession();
281
294
  }
282
295
  const headers = {
283
- 'X-Transmission-Session-Id': this.sessionId,
296
+ 'X-Transmission-Session-Id': this.state.auth?.sessionId,
284
297
  'Content-Type': 'application/json',
285
298
  };
286
299
  if (this.config.username || this.config.password) {
@@ -313,7 +326,9 @@ export class Transmission {
313
326
  }
314
327
  catch (error) {
315
328
  if (error instanceof FetchError && error.response.status === 409) {
316
- this.sessionId = error.response.headers.get('x-transmission-session-id');
329
+ this.state.auth = {
330
+ sessionId: error.response.headers.get('x-transmission-session-id'),
331
+ };
317
332
  // eslint-disable-next-line no-return-await, @typescript-eslint/return-await
318
333
  return await this.request(method, args);
319
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/transmission",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "TypeScript api wrapper for transmission using got",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "license": "MIT",
@@ -17,12 +17,8 @@
17
17
  ],
18
18
  "sideEffects": false,
19
19
  "scripts": {
20
- "lint": "pnpm run '/^(lint:biome|lint:eslint)$/'",
21
- "lint:biome": "biome check .",
22
- "lint:eslint": "eslint .",
23
- "lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
24
- "lint:eslint:fix": "eslint . --fix",
25
- "lint:biome:fix": "biome check . --write",
20
+ "lint": "oxlint . && prettier --check . --experimental-cli",
21
+ "lint:fix": "oxlint . --fix && prettier --write . --log-level=error --experimental-cli",
26
22
  "prepare": "npm run build",
27
23
  "build": "tsc",
28
24
  "build:docs": "typedoc",
@@ -32,23 +28,26 @@
32
28
  },
33
29
  "dependencies": {
34
30
  "@ctrl/magnet-link": "^4.0.2",
35
- "@ctrl/shared-torrent": "^6.1.0",
31
+ "@ctrl/shared-torrent": "^6.3.0",
36
32
  "ofetch": "^1.4.1",
37
- "ufo": "^1.5.4",
38
- "uint8array-extras": "^1.4.0"
33
+ "type-fest": "^4.41.0",
34
+ "ufo": "^1.6.1",
35
+ "uint8array-extras": "^1.5.0"
39
36
  },
40
37
  "devDependencies": {
41
- "@biomejs/biome": "1.9.4",
42
- "@ctrl/eslint-config-biome": "4.2.11",
43
- "@ctrl/magnet-link": "^4.0.2",
44
- "@ctrl/shared-torrent": "^6.1.0",
45
- "@sindresorhus/tsconfig": "6.0.0",
46
- "@types/node": "22.9.0",
47
- "@vitest/coverage-v8": "2.1.4",
38
+ "@ctrl/oxlint-config": "1.2.3",
39
+ "@ctrl/magnet-link": "4.0.2",
40
+ "@ctrl/shared-torrent": "6.3.0",
41
+ "@sindresorhus/tsconfig": "8.0.1",
42
+ "@trivago/prettier-plugin-sort-imports": "5.2.2",
43
+ "@types/node": "24.3.0",
44
+ "@vitest/coverage-v8": "3.2.4",
45
+ "oxlint": "1.14.0",
48
46
  "p-wait-for": "5.0.2",
49
- "typedoc": "0.26.11",
50
- "typescript": "5.6.3",
51
- "vitest": "2.1.4"
47
+ "prettier": "3.6.2",
48
+ "typedoc": "0.28.11",
49
+ "typescript": "5.9.2",
50
+ "vitest": "3.2.4"
52
51
  },
53
52
  "publishConfig": {
54
53
  "access": "public",
@@ -61,5 +60,26 @@
61
60
  },
62
61
  "engines": {
63
62
  "node": ">=18"
63
+ },
64
+ "packageManager": "pnpm@10.15.0",
65
+ "prettier": {
66
+ "singleQuote": true,
67
+ "trailingComma": "all",
68
+ "arrowParens": "avoid",
69
+ "semi": true,
70
+ "printWidth": 100,
71
+ "plugins": [
72
+ "@trivago/prettier-plugin-sort-imports"
73
+ ],
74
+ "importOrder": [
75
+ "^node:.*$",
76
+ "<THIRD_PARTY_MODULES>",
77
+ "^(@ctrl)(/.*|$)",
78
+ "^\\.\\./(?!.*\\.css$)",
79
+ "^\\./(?!.*\\.css$)(?=.*/)",
80
+ "^\\./(?!.*\\.css$)(?!.*/)"
81
+ ],
82
+ "importOrderSeparation": true,
83
+ "importOrderSortSpecifiers": false
64
84
  }
65
85
  }