@adbjs/sdk 0.1.1 → 2.0.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
@@ -1,223 +1,336 @@
1
- # @adbjs/sdk
2
-
3
- Modern TypeScript SDK for the AllDebrid API.
4
-
5
- ## Features
6
-
7
- - ✨ **TypeScript-first** - Full type safety with auto-generated types from OpenAPI spec
8
- - 🚀 **Modern** - Built with wretch, ESM + CJS support
9
- - 📦 **Tree-shakeable** - Import only what you need
10
- - 🔄 **Auto-retry** - Built-in retry logic with configurable options
11
- - 🎯 **Type-safe errors** - Typed error classes for better error handling
12
- - 📝 **Fully documented** - JSDoc comments with examples
13
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install @adbjs/sdk
18
- # or
19
- pnpm add @adbjs/sdk
20
- # or
21
- yarn add @adbjs/sdk
22
- ```
23
-
24
- ## Quick Start
25
-
26
- ```typescript
27
- import { AllDebridClient } from '@adbjs/sdk'
28
-
29
- // Create a client
30
- const client = new AllDebridClient({
31
- apiKey: 'your-api-key-here',
32
- })
33
-
34
- // Get user info
35
- const user = await client.user.getInfo()
36
- console.log(user.username, user.isPremium)
37
-
38
- // Unlock a link
39
- const result = await client.link.unlock('https://example.com/file.zip')
40
- console.log('Direct link:', result.link)
41
-
42
- // Upload a magnet
43
- const magnet = await client.magnet.upload('magnet:?xt=urn:btih:...')
44
- console.log('Magnet ID:', magnet.magnets[0].id)
45
- ```
46
-
47
- ## API Reference
48
-
49
- ### Client Configuration
50
-
51
- ```typescript
52
- const client = new AllDebridClient({
53
- apiKey: string // Required: Your AllDebrid API key
54
- agent?: string // Optional: User agent (default: '@alldebrid/sdk')
55
- baseUrl?: string // Optional: API base URL
56
- timeout?: number // Optional: Request timeout in ms (default: 30000)
57
- retry?: boolean // Optional: Enable auto-retry (default: true)
58
- maxRetries?: number // Optional: Max retry attempts (default: 3)
59
- })
60
- ```
61
-
62
- ### User Resource
63
-
64
- ```typescript
65
- // Get user profile
66
- const user = await client.user.getInfo()
67
-
68
- // Get available hosts for user
69
- const hosts = await client.user.getHosts()
70
- const hostsOnly = await client.user.getHosts(true) // Exclude streams/redirectors
71
-
72
- // Clear a notification
73
- await client.user.clearNotification('NOTIF_CODE')
74
-
75
- // Saved Links Management
76
- const savedLinks = await client.user.getLinks()
77
- await client.user.saveLink('https://example.com/file.zip')
78
- await client.user.deleteLink('saved-link-id')
79
-
80
- // History Management
81
- const history = await client.user.getHistory()
82
- await client.user.clearHistory()
83
- ```
84
-
85
- ### Link Resource
86
-
87
- ```typescript
88
- // Get link information
89
- const info = await client.link.infos('https://example.com/file.zip')
90
- const multipleInfos = await client.link.infos([
91
- 'https://example.com/file1.zip',
92
- 'https://example.com/file2.zip',
93
- ])
94
-
95
- // Extract from redirector
96
- const links = await client.link.redirector('https://linkprotector.com/abc123')
97
-
98
- // Unlock a link
99
- const result = await client.link.unlock('https://example.com/file.zip')
100
-
101
- // Get streaming options
102
- const streams = await client.link.streaming('generated-id')
103
-
104
- // Check delayed link status
105
- const delayed = await client.link.delayed('delayed-id')
106
- ```
107
-
108
- ### Magnet Resource
109
-
110
- ```typescript
111
- // Upload magnets
112
- const result = await client.magnet.upload('magnet:?xt=urn:btih:...')
113
- const multiple = await client.magnet.upload(['magnet:?xt=urn:btih:...', 'magnet:?xt=urn:btih:...'])
114
-
115
- // Upload torrent file
116
- const file = new File([buffer], 'torrent.torrent')
117
- const uploaded = await client.magnet.uploadFile(file)
118
-
119
- // Get magnet status
120
- const status = await client.magnet.status(123)
121
-
122
- // Delete a magnet
123
- await client.magnet.delete(123)
124
-
125
- // Restart a failed magnet
126
- await client.magnet.restart(123)
127
-
128
- // Check instant availability
129
- const available = await client.magnet.instant(['hash1', 'hash2'])
130
-
131
- // Watch magnet with polling
132
- await client.magnet.watch(123, {
133
- interval: 3000, // Poll every 3s
134
- maxAttempts: 30, // Max 30 attempts
135
- stopOnStatus: 'Ready', // Stop when ready
136
- onUpdate: (status) => {
137
- console.log('Progress:', status.magnets[0]?.status)
138
- },
139
- })
140
- ```
141
-
142
- ### Host Resource
143
-
144
- ```typescript
145
- // Get all supported hosts
146
- const hosts = await client.host.list()
147
-
148
- // Get only file hosts (exclude streams/redirectors)
149
- const hostsOnly = await client.host.list(true)
150
-
151
- // Get all supported domain names
152
- const domains = await client.host.domains()
153
-
154
- // Get hosts by priority
155
- const priority = await client.host.priority()
156
- ```
157
-
158
- ## Error Handling
159
-
160
- The SDK provides typed error classes for better error handling:
161
-
162
- ```typescript
163
- import {
164
- AllDebridError,
165
- AuthenticationError,
166
- LinkError,
167
- MagnetError,
168
- NetworkError,
169
- } from '@adbjs/sdk'
170
-
171
- try {
172
- await client.link.unlock(url)
173
- } catch (error) {
174
- if (error instanceof AuthenticationError) {
175
- console.error('Invalid API key')
176
- } else if (error instanceof LinkError) {
177
- console.error('Link error:', error.code, error.message)
178
- } else if (error instanceof NetworkError) {
179
- console.error('Network error:', error.statusCode)
180
- }
181
- }
182
- ```
183
-
184
- ## Type Safety
185
-
186
- All responses are fully typed using types generated from the official AllDebrid OpenAPI specification:
187
-
188
- ```typescript
189
- import type {
190
- GetLinkUnlockResponse,
191
- GetMagnetStatusResponse,
192
- GetUserResponse,
193
- } from '@adbjs/sdk'
194
- ```
195
-
196
- ## Development
197
-
198
- ```bash
199
- # Install dependencies
200
- pnpm install
201
-
202
- # Generate types from OpenAPI spec
203
- pnpm generate
204
-
205
- # Build
206
- pnpm build
207
-
208
- # Run tests
209
- pnpm test
210
-
211
- # Type check
212
- pnpm typecheck
213
- ```
214
-
215
- ## License
216
-
217
- MIT
218
-
219
- ## Links
220
-
221
- - [AllDebrid API Documentation](https://docs.alldebrid.com/)
222
- - [GitHub Repository](https://github.com/Trisard/alldebrid-ts)
223
- - [NPM Package](https://www.npmjs.com/package/@adbjs/sdk)
1
+ # @adbjs/sdk
2
+
3
+ Modern TypeScript SDK for the AllDebrid API v4.1.
4
+
5
+ ## Features
6
+
7
+ - ✨ **TypeScript-first** - Full type safety with auto-generated types from OpenAPI v4.1 spec
8
+ - 🚀 **Modern** - Built with wretch, ESM + CJS support
9
+ - 📦 **Tree-shakeable** - Import only what you need
10
+ - 🔄 **Auto-retry** - Built-in retry logic with configurable options
11
+ - 🎯 **Type-safe errors** - Typed error classes for better error handling
12
+ - 📝 **Fully documented** - JSDoc comments with examples
13
+ - ⚡ **API v4.1 optimized** - Designed and optimized for AllDebrid API v4.1
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @adbjs/sdk
19
+ # or
20
+ pnpm add @adbjs/sdk
21
+ # or
22
+ yarn add @adbjs/sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { AllDebridClient } from '@adbjs/sdk'
29
+
30
+ // Create a client
31
+ const client = new AllDebridClient({
32
+ apiKey: 'your-api-key-here',
33
+ })
34
+
35
+ // Get user info
36
+ const user = await client.user.getInfo()
37
+ console.log(user.username, user.isPremium)
38
+
39
+ // Unlock a link
40
+ const result = await client.link.unlock('https://example.com/file.zip')
41
+ console.log('Direct link:', result.link)
42
+
43
+ // Upload a magnet
44
+ const magnet = await client.magnet.upload('magnet:?xt=urn:btih:...')
45
+ console.log('Magnet ID:', magnet.magnets[0].id)
46
+ ```
47
+
48
+ ## API Reference
49
+
50
+ ### Client Configuration
51
+
52
+ ```typescript
53
+ const client = new AllDebridClient({
54
+ apiKey: string // Required: Your AllDebrid API key
55
+ agent?: string // Optional: User agent (default: '@alldebrid/sdk')
56
+ baseUrl?: string // Optional: API base URL
57
+ timeout?: number // Optional: Request timeout in ms (default: 30000)
58
+ retry?: boolean // Optional: Enable auto-retry (default: true)
59
+ maxRetries?: number // Optional: Max retry attempts (default: 3)
60
+ })
61
+ ```
62
+
63
+ ### User Resource
64
+
65
+ ```typescript
66
+ // Get user profile
67
+ const user = await client.user.getInfo()
68
+
69
+ // Get available hosts for user
70
+ const hosts = await client.user.getHosts()
71
+ const hostsOnly = await client.user.getHosts(true) // Exclude streams/redirectors
72
+
73
+ // Clear a notification
74
+ await client.user.clearNotification('NOTIF_CODE')
75
+
76
+ // Saved Links Management
77
+ const savedLinks = await client.user.getLinks()
78
+
79
+ // Save single link
80
+ await client.user.saveLink('https://example.com/file.zip')
81
+
82
+ // Save multiple links at once (batch operation)
83
+ await client.user.saveLink(['https://example.com/file1.zip', 'https://example.com/file2.zip'])
84
+
85
+ // Delete single link
86
+ await client.user.deleteLink('saved-link-id')
87
+
88
+ // Delete multiple links at once (batch operation)
89
+ await client.user.deleteLink(['id1', 'id2', 'id3'])
90
+
91
+ // History Management
92
+ const history = await client.user.getHistory()
93
+ await client.user.clearHistory()
94
+
95
+ // Email Verification
96
+ const status = await client.user.getVerificationStatus('token')
97
+ await client.user.resendVerification('token')
98
+ ```
99
+
100
+ ### Link Resource
101
+
102
+ ```typescript
103
+ // Get link information
104
+ const info = await client.link.infos('https://example.com/file.zip')
105
+ const multipleInfos = await client.link.infos([
106
+ 'https://example.com/file1.zip',
107
+ 'https://example.com/file2.zip',
108
+ ])
109
+
110
+ // Get link information with password
111
+ const protectedInfo = await client.link.infos('https://example.com/file.zip', 'password123')
112
+
113
+ // Extract from redirector
114
+ const links = await client.link.redirector('https://linkprotector.com/abc123')
115
+
116
+ // Unlock a link
117
+ const result = await client.link.unlock('https://example.com/file.zip')
118
+
119
+ // Unlock a password-protected link
120
+ const protectedResult = await client.link.unlock('https://example.com/file.zip', 'password123')
121
+
122
+ // Get streaming options
123
+ const streams = await client.link.streaming('generated-id')
124
+
125
+ // Check delayed link status
126
+ const delayed = await client.link.delayed('delayed-id')
127
+ ```
128
+
129
+ ### Magnet Resource
130
+
131
+ ```typescript
132
+ // Upload magnets
133
+ const result = await client.magnet.upload('magnet:?xt=urn:btih:...')
134
+ const multiple = await client.magnet.upload(['magnet:?xt=urn:btih:...', 'magnet:?xt=urn:btih:...'])
135
+
136
+ // Upload torrent file
137
+ const file = new File([buffer], 'torrent.torrent')
138
+ const uploaded = await client.magnet.uploadFile(file)
139
+
140
+ // ===== Standard Mode: Get magnet status =====
141
+
142
+ // Get status of a specific magnet by ID
143
+ const status = await client.magnet.status(123)
144
+ console.log('Magnet status:', status.magnets[0]?.status)
145
+
146
+ // Get list of all magnets
147
+ const allMagnets = await client.magnet.statusList()
148
+
149
+ // Get list of magnets filtered by status
150
+ const activeMagnets = await client.magnet.statusList('active') // Downloading
151
+ const readyMagnets = await client.magnet.statusList('ready') // Completed
152
+ const expiredMagnets = await client.magnet.statusList('expired') // Expired
153
+ const errorMagnets = await client.magnet.statusList('error') // Failed
154
+
155
+ // ===== Live Mode: Efficient polling with delta sync =====
156
+ // Live mode only returns magnets that changed since the last request,
157
+ // significantly reducing bandwidth usage. Perfect for real-time monitoring.
158
+
159
+ // Initialize live mode with a random session ID
160
+ const session = Math.floor(Math.random() * 1000000)
161
+ let counter = 0
162
+
163
+ // First call: Returns all magnets (full sync)
164
+ const firstCall = await client.magnet.statusLive({ session, counter })
165
+ console.log('Full sync:', firstCall.magnets)
166
+
167
+ // Update counter from response
168
+ counter = firstCall.counter // Important: Use the returned counter value
169
+
170
+ // Subsequent calls: Only returns changed magnets (delta sync)
171
+ const secondCall = await client.magnet.statusLive({ session, counter })
172
+ console.log('Delta sync (only changes):', secondCall.magnets)
173
+
174
+ // Live mode can also track a specific magnet
175
+ counter = secondCall.counter
176
+ const specificMagnet = await client.magnet.statusLive({ session, counter }, 123)
177
+ console.log('Changes for magnet 123:', specificMagnet.magnets)
178
+
179
+ // ===== Magnet management =====
180
+
181
+ // Delete a magnet
182
+ await client.magnet.delete(123)
183
+
184
+ // Restart a failed magnet
185
+ await client.magnet.restart(123)
186
+
187
+ // Get download links for a completed magnet
188
+ const files = await client.magnet.files(123)
189
+ files?.forEach((file) => {
190
+ console.log(file.filename, file.link)
191
+ })
192
+
193
+ // ===== Watch: Monitor magnet progress with automatic polling =====
194
+
195
+ // Standard mode: Full status check on each poll
196
+ await client.magnet.watch(123, {
197
+ interval: 3000, // Check every 3 seconds
198
+ maxAttempts: 30, // Stop after 30 attempts
199
+ stopOnStatus: 'Ready', // Stop when magnet is ready
200
+ onUpdate: (status) => {
201
+ const magnet = status.magnets[0]
202
+ console.log(`Progress: ${magnet?.status} - ${magnet?.downloaded || 0}%`)
203
+ },
204
+ })
205
+
206
+ // Live mode: Delta sync for reduced bandwidth (recommended for long-running monitors)
207
+ await client.magnet.watch(123, {
208
+ useLiveMode: true, // Enable live mode
209
+ interval: 2000, // Check every 2 seconds
210
+ maxAttempts: 0, // 0 = infinite polling
211
+ onUpdate: (status) => {
212
+ // Only called when the magnet status changes
213
+ console.log('Magnet updated:', status.magnets[0])
214
+ },
215
+ })
216
+ ```
217
+
218
+ ### Host Resource
219
+
220
+ ```typescript
221
+ // Get all supported hosts
222
+ const hosts = await client.host.list()
223
+
224
+ // Get only file hosts (exclude streams/redirectors)
225
+ const hostsOnly = await client.host.list(true)
226
+
227
+ // Get all supported domain names
228
+ const domains = await client.host.domains()
229
+
230
+ // Get hosts by priority
231
+ const priority = await client.host.priority()
232
+ ```
233
+
234
+ ### Pin Resource
235
+
236
+ ```typescript
237
+ // Generate a PIN for authentication
238
+ const pinData = await client.pin.generate()
239
+ console.log('Visit:', pinData.user_url)
240
+ console.log('PIN:', pinData.pin)
241
+
242
+ // Check PIN status manually
243
+ const result = await client.pin.check(pinData.check, pinData.pin)
244
+ if (result?.activated && result?.apikey) {
245
+ console.log('Authorized! API Key:', result.apikey)
246
+ }
247
+
248
+ // Wait for authorization with automatic polling
249
+ const apikey = await client.pin.waitForAuth(pinData.check, pinData.pin, {
250
+ timeout: 600000, // 10 minutes
251
+ interval: 3000, // Check every 3 seconds
252
+ })
253
+ ```
254
+
255
+ ### Voucher Resource
256
+
257
+ ```typescript
258
+ // Get reseller voucher balance
259
+ const balance = await client.voucher.getBalance()
260
+ console.log('Remaining balance:', balance.balance, '€')
261
+
262
+ // Retrieve existing vouchers from inventory
263
+ const allVouchers = await client.voucher.getVouchers()
264
+ console.log('Vouchers:', allVouchers?.codes)
265
+
266
+ // Retrieve specific quantity of vouchers
267
+ const fiveVouchers = await client.voucher.getVouchers(5)
268
+
269
+ // Generate new vouchers (deducts from balance)
270
+ // Generate 10 vouchers valid for 30 days
271
+ const newVouchers = await client.voucher.generateVouchers(10, 30)
272
+ console.log('Generated vouchers:', newVouchers?.codes)
273
+ ```
274
+
275
+ ## Error Handling
276
+
277
+ The SDK provides typed error classes for better error handling:
278
+
279
+ ```typescript
280
+ import {
281
+ AllDebridError,
282
+ AuthenticationError,
283
+ LinkError,
284
+ MagnetError,
285
+ NetworkError,
286
+ } from '@adbjs/sdk'
287
+
288
+ try {
289
+ await client.link.unlock(url)
290
+ } catch (error) {
291
+ if (error instanceof AuthenticationError) {
292
+ console.error('Invalid API key')
293
+ } else if (error instanceof LinkError) {
294
+ console.error('Link error:', error.code, error.message)
295
+ } else if (error instanceof NetworkError) {
296
+ console.error('Network error:', error.statusCode)
297
+ }
298
+ }
299
+ ```
300
+
301
+ ## Type Safety
302
+
303
+ All responses are fully typed using types generated from the official AllDebrid API v4.1 OpenAPI specification:
304
+
305
+ ```typescript
306
+ import type { GetLinkUnlockResponse, GetMagnetStatusResponse, GetUserResponse } from '@adbjs/sdk'
307
+ ```
308
+
309
+ ## Development
310
+
311
+ ```bash
312
+ # Install dependencies
313
+ pnpm install
314
+
315
+ # Generate types from OpenAPI spec
316
+ pnpm generate
317
+
318
+ # Build
319
+ pnpm build
320
+
321
+ # Run tests
322
+ pnpm test
323
+
324
+ # Type check
325
+ pnpm typecheck
326
+ ```
327
+
328
+ ## License
329
+
330
+ MIT
331
+
332
+ ## Links
333
+
334
+ - [AllDebrid API Documentation](https://docs.alldebrid.com/)
335
+ - [GitHub Repository](https://github.com/Trisard/alldebrid-ts)
336
+ - [NPM Package](https://www.npmjs.com/package/@adbjs/sdk)