@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 +336 -223
- package/dist/index.cjs +518 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +885 -1025
- package/dist/index.d.ts +885 -1025
- package/dist/index.js +517 -82
- package/dist/index.js.map +1 -1
- package/package.json +66 -66
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await client.user.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
await client.
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
await client.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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)
|