Skip to content

Commit 924dffb

Browse files
committed
Enhance README and examples with updated authentication methods and configuration details. Introduce environment-based authentication as a recommended approach, add new configuration options for bulk operations, and improve error handling examples. Update basic authentication example to demonstrate both manual and environment-based methods.
1 parent 9c87af8 commit 924dffb

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

README.md

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,52 @@ TIDAL_WORKSPACE=your_workspace_name
3131
TIDAL_USERNAME=your_username
3232
TIDAL_PASSWORD=your_password
3333
LOG_LEVEL=info
34+
BULK_BATCH_SIZE=50
35+
BULK_CONCURRENT_BATCHES=3
36+
BULK_RETRY_ATTEMPTS=3
37+
BULK_RETRY_DELAY=1000
3438
```
3539

3640
The base URL is automatically generated as `https://{workspace}.tidal.cloud/api/v1`.
3741

3842
## 🚀 Quick Start
3943

40-
### Basic Authentication and Client Setup
44+
### Method 1: Manual Authentication
4145

4246
```typescript
43-
import { TidalApiClient } from './src/api/client';
47+
import { TidalApiClient } from './src/index';
48+
import { loadConfig, getAuthCredentials } from './src/config/environment';
4449

45-
const client = new TidalApiClient({
46-
workspace: 'your-workspace'
50+
// Load configuration from environment
51+
const config = loadConfig();
52+
const credentials = getAuthCredentials();
53+
54+
const client = new TidalApiClient({
55+
workspace: config.workspace,
56+
baseUrl: config.baseUrl
4757
});
4858

49-
await client.authenticate('username', 'password');
59+
// Authenticate with credentials from .env
60+
await client.authenticate(credentials.username, credentials.password);
61+
console.log(`Authenticated: ${client.isAuthenticated()}`);
62+
```
63+
64+
### Method 2: Environment-based Authentication (Recommended)
65+
66+
```typescript
67+
import { createAuthenticatedClient } from './src/index';
68+
69+
// This automatically loads from environment variables
70+
const client = await createAuthenticatedClient();
71+
console.log(`Workspace: ${client.getWorkspace()}`);
72+
```
73+
74+
### Basic Authentication Example
75+
76+
Run the basic authentication example to see both methods in action:
77+
78+
```bash
79+
npx ts-node examples/basic-authentication.ts
5080
```
5181

5282
### Server Operations
@@ -55,6 +85,14 @@ For detailed examples of server operations including backup functionality, bulk
5585

5686
## 🎮 Examples
5787

88+
### Basic Authentication
89+
90+
Demonstrates both manual and environment-based authentication methods:
91+
92+
```bash
93+
npx ts-node examples/basic-authentication.ts
94+
```
95+
5896
### Server Backup Demo
5997

6098
Run the server backup demonstration:
@@ -69,6 +107,14 @@ Or run directly:
69107
npx ts-node examples/server-backup-demo.ts
70108
```
71109

110+
### Available Examples
111+
112+
- `basic-authentication.ts` - Authentication methods and client setup
113+
- `server-backup-demo.ts` - Server backup operations
114+
- `hostname-to-fqdn-demo.ts` - Hostname to FQDN conversion
115+
- `hostname-to-tag-demo.ts` - Hostname to tag operations
116+
- `description-to-hostname-demo.ts` - Description to hostname mapping
117+
72118
See the `examples/` folder for more detailed usage examples and demonstrations.
73119

74120
## 🧪 Testing
@@ -89,10 +135,6 @@ npm test -- --testPathPattern=backup
89135

90136
Current test coverage: **88%** (exceeds 80% requirement)
91137

92-
93-
94-
95-
96138
## 🏗️ Architecture
97139

98140
```
@@ -122,18 +164,25 @@ tests/
122164

123165
## 🔍 Error Handling
124166

125-
The client provides comprehensive error handling:
167+
The client provides comprehensive error handling with specific error types:
126168

127169
```typescript
170+
import { AuthenticationError, TidalApiError, ValidationError } from './src/index';
171+
128172
try {
129-
const backup = await serverOps.createServerBackup();
173+
const client = await createAuthenticatedClient();
174+
const response = await client.get('/servers');
130175
} catch (error) {
131176
if (error instanceof AuthenticationError) {
132-
// Handle authentication issues
177+
console.error('Authentication failed:', error.message);
178+
// Check credentials in .env file
179+
} else if (error instanceof TidalApiError) {
180+
console.error('API Error:', error.message);
181+
console.error(`Status: ${error.status}, Code: ${error.code}`);
133182
} else if (error instanceof ValidationError) {
134-
// Handle validation errors
183+
console.error('Validation error:', error.message);
135184
} else {
136-
// Handle other errors
185+
console.error('Unexpected error:', error);
137186
}
138187
}
139188
```

examples/basic-authentication.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { TidalApiClient, createAuthenticatedClient } from '../src/index';
1919
import { AuthenticationError, TidalApiError } from '../src/utils/errors';
20-
import { logger } from '../src/utils/logger';
2120
import { loadConfig, getAuthCredentials } from '../src/config/environment';
2221

2322
async function basicAuthenticationExample() {

0 commit comments

Comments
 (0)