@adbjs/sdk 0.1.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.
- package/README.md +223 -0
- package/dist/index.cjs +687 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1594 -0
- package/dist/index.d.ts +1594 -0
- package/dist/index.js +671 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
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)
|