@@ -31,22 +31,52 @@ TIDAL_WORKSPACE=your_workspace_name
31
31
TIDAL_USERNAME=your_username
32
32
TIDAL_PASSWORD=your_password
33
33
LOG_LEVEL=info
34
+ BULK_BATCH_SIZE=50
35
+ BULK_CONCURRENT_BATCHES=3
36
+ BULK_RETRY_ATTEMPTS=3
37
+ BULK_RETRY_DELAY=1000
34
38
```
35
39
36
40
The base URL is automatically generated as ` https://{workspace}.tidal.cloud/api/v1 ` .
37
41
38
42
## 🚀 Quick Start
39
43
40
- ### Basic Authentication and Client Setup
44
+ ### Method 1: Manual Authentication
41
45
42
46
``` typescript
43
- import { TidalApiClient } from ' ./src/api/client' ;
47
+ import { TidalApiClient } from ' ./src/index' ;
48
+ import { loadConfig , getAuthCredentials } from ' ./src/config/environment' ;
44
49
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
47
57
});
48
58
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
50
80
```
51
81
52
82
### Server Operations
@@ -55,6 +85,14 @@ For detailed examples of server operations including backup functionality, bulk
55
85
56
86
## 🎮 Examples
57
87
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
+
58
96
### Server Backup Demo
59
97
60
98
Run the server backup demonstration:
@@ -69,6 +107,14 @@ Or run directly:
69
107
npx ts-node examples/server-backup-demo.ts
70
108
```
71
109
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
+
72
118
See the ` examples/ ` folder for more detailed usage examples and demonstrations.
73
119
74
120
## 🧪 Testing
@@ -89,10 +135,6 @@ npm test -- --testPathPattern=backup
89
135
90
136
Current test coverage: ** 88%** (exceeds 80% requirement)
91
137
92
-
93
-
94
-
95
-
96
138
## 🏗️ Architecture
97
139
98
140
```
@@ -122,18 +164,25 @@ tests/
122
164
123
165
## 🔍 Error Handling
124
166
125
- The client provides comprehensive error handling:
167
+ The client provides comprehensive error handling with specific error types :
126
168
127
169
``` typescript
170
+ import { AuthenticationError , TidalApiError , ValidationError } from ' ./src/index' ;
171
+
128
172
try {
129
- const backup = await serverOps .createServerBackup ();
173
+ const client = await createAuthenticatedClient ();
174
+ const response = await client .get (' /servers' );
130
175
} catch (error ) {
131
176
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 } ` );
133
182
} else if (error instanceof ValidationError ) {
134
- // Handle validation errors
183
+ console . error ( ' Validation error: ' , error . message );
135
184
} else {
136
- // Handle other errors
185
+ console . error ( ' Unexpected error: ' , error );
137
186
}
138
187
}
139
188
```
0 commit comments