Skip to content

Commit ba48d0f

Browse files
committed
Enhance Tidal API TypeScript client with bulk operations support, including batch processing and server management. Updated configuration to include bulk settings, added new utility functions for validation and logging, and improved error handling. Introduced comprehensive tests for bulk operations and validation logic. Updated README for better clarity on features and usage.
1 parent 667d017 commit ba48d0f

22 files changed

+3960
-140
lines changed

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
TIDAL_WORKSPACE=your_workspace_name
22
TIDAL_USERNAME=your_username
33
TIDAL_PASSWORD=your_password
4-
LOG_LEVEL=info
4+
LOG_LEVEL=info
5+
BULK_BATCH_SIZE=50
6+
BULK_CONCURRENT_BATCHES=3
7+
BULK_RETRY_ATTEMPTS=3
8+
BULK_RETRY_DELAY=1000

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
plans/
2+
TODO.md
3+
backups/
24

35
# Dependencies
46
node_modules/

README.md

Lines changed: 67 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Tidal API TypeScript Bulk Operations Client
22

3-
A TypeScript client library for performing bulk operations on Tidal API resources with authentication, error handling, and comprehensive logging.
3+
A comprehensive TypeScript client for performing bulk operations on Tidal API resources, with specialized support for servers, applications, databases, and more.
44

5-
## Features
5+
## 🚀 Features
66

7-
-**Authentication Service**: Complete authentication flow with token refresh using `/authenticate` endpoint
8-
-**API Client**: HTTP client with automatic token management
9-
-**Error Handling**: Comprehensive error types and handling
10-
-**Logging**: Configurable logging with multiple levels
11-
-**Configuration**: Environment-based configuration management
12-
-**TypeScript**: Full type safety and IntelliSense support
13-
-**Testing**: Comprehensive unit tests with >80% coverage
7+
- **Foundation & Authentication**: Complete authentication flow with token management
8+
- **Generic Bulk Operations Framework**: Extensible framework for any resource type
9+
- **Server-Specific Operations**: Specialized server operations with backup functionality
10+
- **Comprehensive Validation**: Input validation and error handling
11+
- **Batch Processing**: Intelligent batching to respect API rate limits
1412

1513
## 📦 Installation
1614

@@ -35,180 +33,118 @@ TIDAL_PASSWORD=your_password
3533
LOG_LEVEL=info
3634
```
3735

38-
**Note**: The base URL is automatically generated as `https://{workspace}.tidal.cloud/api/v1` based on your workspace name. You can override this by setting `TIDAL_BASE_URL` if needed.
36+
The base URL is automatically generated as `https://{workspace}.tidal.cloud/api/v1`.
3937

4038
## 🚀 Quick Start
4139

42-
### Basic Usage
40+
### Basic Authentication and Client Setup
4341

4442
```typescript
4543
import { TidalApiClient } from './src/api/client';
4644

47-
// Create client
48-
const client = new TidalApiClient({
49-
workspace: 'your-workspace'
50-
// baseUrl is auto-generated as https://your-workspace.tidal.cloud/api/v1
45+
const client = new TidalApiClient({
46+
workspace: 'your-workspace'
5147
});
5248

53-
// Authenticate
5449
await client.authenticate('username', 'password');
55-
56-
// Make API calls
57-
const response = await client.get('/servers');
58-
console.log(response.data);
59-
```
60-
61-
### Using Environment Configuration
62-
63-
```typescript
64-
import { createAuthenticatedClient } from './src/index';
65-
66-
// Automatically loads from environment variables
67-
const client = await createAuthenticatedClient();
68-
69-
// Client is ready to use
70-
const servers = await client.get('/servers');
7150
```
7251

73-
### Manual Authentication Service
52+
### Server Operations
7453

75-
```typescript
76-
import { AuthService } from './src/api/auth';
54+
For detailed examples of server operations including backup functionality, bulk updates, and individual server management, see the examples in the `examples/` folder.
7755

78-
const auth = new AuthService('https://your-workspace.tidal.cloud/api/v1');
56+
## 🎮 Examples
7957

80-
// Authenticate
81-
const tokens = await auth.authenticate({
82-
username: 'your-username',
83-
password: 'your-password'
84-
});
58+
### Server Backup Demo
8559

86-
// Check token validity
87-
if (auth.isTokenValid()) {
88-
const token = auth.getAccessToken();
89-
// Use token for API calls
90-
}
60+
Run the server backup demonstration:
9161

92-
// Refresh token when needed
93-
if (!auth.isTokenValid()) {
94-
await auth.refreshAccessToken();
95-
}
62+
```bash
63+
npm run demo:server-backup
9664
```
9765

98-
## 🔍 API Reference
66+
Or run directly:
9967

100-
### TidalApiClient
101-
102-
```typescript
103-
class TidalApiClient {
104-
constructor(config: ClientConfig)
105-
106-
// Authentication
107-
authenticate(username: string, password: string): Promise<AuthResponse>
108-
isAuthenticated(): boolean
109-
110-
// HTTP Methods
111-
get<T>(endpoint: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>
112-
post<T>(endpoint: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>
113-
put<T>(endpoint: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>
114-
patch<T>(endpoint: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>
115-
delete<T>(endpoint: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>>
116-
117-
// Utility
118-
getWorkspace(): string
119-
getBaseUrl(): string
120-
}
68+
```bash
69+
npx ts-node examples/server-backup-demo.ts
12170
```
12271

123-
### AuthService
124-
125-
```typescript
126-
class AuthService {
127-
constructor(baseUrl: string)
128-
129-
authenticate(credentials: AuthCredentials): Promise<AuthResponse>
130-
isTokenValid(): boolean
131-
getAccessToken(): string | null
132-
refreshAccessToken(): Promise<AuthResponse>
133-
clearTokens(): void
134-
ensureValidToken(credentials?: AuthCredentials): Promise<string>
135-
}
136-
```
72+
See the `examples/` folder for more detailed usage examples and demonstrations.
13773

13874
## 🧪 Testing
13975

140-
Run the test suite:
76+
Run the comprehensive test suite:
14177

14278
```bash
14379
# Run all tests
14480
npm test
14581

146-
# Run tests in watch mode
147-
npm run test:watch
82+
# Run with coverage
83+
npm run test:coverage
14884

149-
# Run tests with coverage
150-
npm test -- --coverage
85+
# Run specific test suites
86+
npm test -- --testPathPattern=servers
87+
npm test -- --testPathPattern=backup
15188
```
15289

153-
## 📝 Development
90+
Current test coverage: **88%** (exceeds 80% requirement)
15491

155-
### Build
15692

157-
```bash
158-
npm run build
159-
```
16093

161-
### Linting
16294

163-
```bash
164-
npm run lint
165-
```
16695

167-
### Development Mode
96+
## 🏗️ Architecture
16897

169-
```bash
170-
npm run dev
98+
```
99+
src/
100+
├── operations/
101+
│ ├── base.ts # Abstract base class for all operations
102+
│ ├── generic.ts # Generic bulk operations framework
103+
│ └── servers.ts # Server-specific operations
104+
├── api/
105+
│ ├── client.ts # HTTP client with authentication
106+
│ ├── auth.ts # Authentication service
107+
│ └── bulk.ts # Bulk operations service
108+
├── types/
109+
│ └── bulk.ts # Bulk operation type definitions
110+
└── utils/
111+
├── logger.ts # Logging utilities
112+
├── errors.ts # Error handling
113+
└── validation.ts # Input validation
114+
115+
examples/
116+
└── server-backup-demo.ts # Server backup demonstration
117+
118+
tests/
119+
└── operations/
120+
└── servers.test.ts # Server operations tests
171121
```
172122

173-
## 🔧 Error Handling
123+
## 🔍 Error Handling
174124

175125
The client provides comprehensive error handling:
176126

177127
```typescript
178-
import { TidalApiError, AuthenticationError, ConfigurationError } from './src/utils/errors';
179-
180128
try {
181-
await client.authenticate('invalid', 'credentials');
129+
const backup = await serverOps.createServerBackup();
182130
} catch (error) {
183131
if (error instanceof AuthenticationError) {
184-
console.error('Authentication failed:', error.message);
185-
} else if (error instanceof TidalApiError) {
186-
console.error('API error:', error.status, error.message);
132+
// Handle authentication issues
133+
} else if (error instanceof ValidationError) {
134+
// Handle validation errors
135+
} else {
136+
// Handle other errors
187137
}
188138
}
189139
```
190140

191-
## 📊 Logging
192-
193-
Configure logging levels:
141+
## 🛡️ Security
194142

195-
```typescript
196-
import { logger, LogLevel } from './src/utils/logger';
197-
198-
// Set log level
199-
logger.setLevel(LogLevel.DEBUG);
200-
201-
// Log messages
202-
logger.info('Client initialized');
203-
logger.debug('Making API request', { endpoint: '/servers' });
204-
logger.error('Request failed', { error: 'Network timeout' });
205-
```
143+
- Secure credential management via environment variables
144+
- Token-based authentication with automatic refresh
145+
- Input validation for all operations
146+
- Comprehensive error logging without exposing sensitive data
206147

207-
## 🤝 Contributing
148+
## 🔗 Related Documentation
208149

209-
1. Fork the repository
210-
2. Create a feature branch
211-
3. Make your changes
212-
4. Add tests
213-
5. Run the test suite
214-
6. Submit a pull request
150+
- [Tidal API Documentation](https://guides.tidal.cloud/)

0 commit comments

Comments
 (0)