Skip to content

Commit 7814f60

Browse files
committed
docs: Add retry configuration documentation
Document new retry options in README: - Add retry configuration example in usage section - Document all SocketSdkOptions interface properties - Explain retry behavior and exponential backoff - Note auth errors are not retried
1 parent 6503710 commit 7814f60

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ pnpm add @socketsecurity/sdk
1919
```javascript
2020
import { SocketSdk } from '@socketsecurity/sdk'
2121

22-
const client = new SocketSdk('yourApiKeyHere')
22+
const client = new SocketSdk('yourApiKeyHere', {
23+
retries: 3, // Retry failed requests up to 3 times (default: 3)
24+
retryDelay: 1000, // Start with 1s delay, exponential backoff (default: 1000ms)
25+
timeout: 30000, // Request timeout in milliseconds (optional)
26+
})
2327

2428
const res = await client.getQuota()
2529

@@ -29,6 +33,27 @@ if (res.success) {
2933
}
3034
```
3135

36+
### Configuration Options
37+
38+
The SDK constructor accepts the following options:
39+
40+
```typescript
41+
interface SocketSdkOptions {
42+
baseUrl?: string // API base URL (default: 'https://api.socket.dev/v0/')
43+
timeout?: number // Request timeout in milliseconds
44+
retries?: number // Number of retry attempts for failed requests (default: 3)
45+
retryDelay?: number // Initial retry delay in ms, with exponential backoff (default: 1000)
46+
userAgent?: string // Custom user agent string
47+
agent?: Agent // Custom HTTP agent for advanced networking
48+
}
49+
```
50+
51+
**Retry Logic:**
52+
- Automatically retries transient network errors and 5xx server responses
53+
- Uses exponential backoff: 1s, 2s, 4s, 8s... (configurable via `retryDelay`)
54+
- Does NOT retry 401/403 authentication errors (immediate failure)
55+
- Set `retries: 0` to disable retry logic entirely
56+
3257
### Quota Management Example
3358

3459
```javascript

0 commit comments

Comments
 (0)