opensecureconf-client 2.2.0 โ 2.2.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 +429 -215
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,297 +1,511 @@
|
|
|
1
|
-
# OpenSecureConf JavaScript
|
|
2
|
-
|
|
3
|
-
JavaScript/TypeScript client library for [OpenSecureConf](https://github.com/yourusername/OpenSecureConf) - A secure, encrypted configuration management system with REST API.
|
|
1
|
+
# OpenSecureConf TypeScript/JavaScript Client
|
|
4
2
|
|
|
5
3
|
[](https://www.npmjs.com/package/opensecureconf-client)
|
|
6
|
-
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A comprehensive TypeScript/JavaScript client library for OpenSecureConf - Encrypted configuration management with cluster support and HTTPS/SSL.
|
|
7
8
|
|
|
8
|
-
## Features
|
|
9
|
+
## ๐ Features
|
|
9
10
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
11
|
+
- โ
**Full TypeScript Support** - Complete type definitions
|
|
12
|
+
- ๐ **HTTPS/SSL Support** - Production-ready with TLS
|
|
13
|
+
- ๐ **Self-Signed Certificates** - Option for development environments
|
|
14
|
+
- ๐ฆ **Batch Operations** - Bulk create, read, delete
|
|
15
|
+
- ๐ **Cluster Support** - Status and health check methods
|
|
14
16
|
- โก **Async/Await** - Modern promise-based API
|
|
15
|
-
- ๐ก๏ธ **
|
|
16
|
-
-
|
|
17
|
-
-
|
|
17
|
+
- ๐ก๏ธ **Type-Safe** - Full TypeScript definitions
|
|
18
|
+
- ๐ **Universal** - Works in Node.js and browsers
|
|
19
|
+
- ๐ **Auto-Retry** - Built-in timeout and error handling
|
|
20
|
+
- ๐ **Metrics** - Prometheus metrics support
|
|
18
21
|
|
|
19
|
-
## Installation
|
|
22
|
+
## ๐ฆ Installation
|
|
20
23
|
|
|
24
|
+
### NPM
|
|
21
25
|
```bash
|
|
22
26
|
npm install opensecureconf-client
|
|
23
27
|
```
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
### Yarn
|
|
30
|
+
```bash
|
|
31
|
+
yarn add opensecureconf-client
|
|
32
|
+
```
|
|
26
33
|
|
|
27
|
-
###
|
|
34
|
+
### PNPM
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add opensecureconf-client
|
|
37
|
+
```
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
## ๐ฏ Quick Start
|
|
40
|
+
|
|
41
|
+
### Basic HTTP Usage
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import OpenSecureConfClient from 'opensecureconf-client';
|
|
31
45
|
|
|
32
46
|
const client = new OpenSecureConfClient({
|
|
33
47
|
baseUrl: 'http://localhost:9000',
|
|
34
|
-
userKey: 'my-
|
|
35
|
-
apiKey: '
|
|
48
|
+
userKey: 'my-secret-key-12345',
|
|
49
|
+
apiKey: 'optional-api-key', // Optional
|
|
36
50
|
});
|
|
37
51
|
|
|
38
|
-
// Create
|
|
39
|
-
await client.create('
|
|
52
|
+
// Create configuration
|
|
53
|
+
const config = await client.create('database', {
|
|
54
|
+
host: 'localhost',
|
|
55
|
+
port: 5432,
|
|
56
|
+
username: 'admin',
|
|
57
|
+
});
|
|
40
58
|
|
|
41
|
-
// Read
|
|
42
|
-
const
|
|
43
|
-
console.log(
|
|
59
|
+
// Read configuration
|
|
60
|
+
const retrieved = await client.read('database');
|
|
61
|
+
console.log(retrieved.value); // { host: 'localhost', port: 5432, ... }
|
|
62
|
+
|
|
63
|
+
// Update configuration
|
|
64
|
+
await client.update('database', {
|
|
65
|
+
host: 'db.example.com',
|
|
66
|
+
port: 5432,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Delete configuration
|
|
70
|
+
await client.delete('database');
|
|
44
71
|
```
|
|
45
72
|
|
|
46
|
-
###
|
|
73
|
+
### HTTPS with Valid Certificate (Production)
|
|
47
74
|
|
|
48
75
|
```typescript
|
|
49
|
-
|
|
76
|
+
const client = new OpenSecureConfClient({
|
|
77
|
+
baseUrl: 'https://config.example.com',
|
|
78
|
+
userKey: 'my-secret-key-12345',
|
|
79
|
+
apiKey: 'production-api-key',
|
|
80
|
+
timeout: 60000, // 60 seconds
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// All operations work the same
|
|
84
|
+
const config = await client.create('api_keys', {
|
|
85
|
+
stripe: 'sk_live_xxx',
|
|
86
|
+
aws: 'AKIA_xxx',
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### HTTPS with Self-Signed Certificate (Development)
|
|
50
91
|
|
|
92
|
+
```typescript
|
|
51
93
|
const client = new OpenSecureConfClient({
|
|
52
|
-
baseUrl: '
|
|
53
|
-
userKey: 'my-
|
|
94
|
+
baseUrl: 'https://localhost:9443',
|
|
95
|
+
userKey: 'my-secret-key-12345',
|
|
96
|
+
rejectUnauthorized: false, // โ ๏ธ Accept self-signed certs (dev only!)
|
|
54
97
|
});
|
|
55
98
|
|
|
56
|
-
|
|
99
|
+
// Works with self-signed certificates
|
|
100
|
+
const info = await client.getInfo();
|
|
101
|
+
console.log(info.service); // OpenSecureConf API
|
|
57
102
|
```
|
|
58
103
|
|
|
59
|
-
## API Reference
|
|
104
|
+
## ๐ API Reference
|
|
105
|
+
|
|
106
|
+
### Constructor Options
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
interface OpenSecureConfOptions {
|
|
110
|
+
baseUrl: string; // API server URL (http:// or https://)
|
|
111
|
+
userKey: string; // Encryption key (min 8 chars)
|
|
112
|
+
apiKey?: string; // Optional API key for authentication
|
|
113
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
114
|
+
rejectUnauthorized?: boolean; // Reject invalid SSL certs (default: true)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
60
117
|
|
|
61
118
|
### Methods
|
|
62
119
|
|
|
63
|
-
|
|
64
|
-
- `read(key)` - Read configuration by key
|
|
65
|
-
- `update(key, value, category?)` - Update configuration
|
|
66
|
-
- `delete(key)` - Delete configuration
|
|
67
|
-
- `list(category?)` - List all configurations
|
|
68
|
-
- `getClusterStatus()` - Get cluster status
|
|
69
|
-
- `healthCheck()` - Perform health check
|
|
70
|
-
- `getMetrics()` - Get Prometheus metrics
|
|
71
|
-
- `getInfo()` - Get API information
|
|
120
|
+
#### Configuration Operations
|
|
72
121
|
|
|
73
|
-
|
|
122
|
+
```typescript
|
|
123
|
+
// Create
|
|
124
|
+
await client.create(
|
|
125
|
+
key: string,
|
|
126
|
+
value: Record<string, any>,
|
|
127
|
+
category?: string
|
|
128
|
+
): Promise<ConfigEntry>
|
|
129
|
+
|
|
130
|
+
// Read
|
|
131
|
+
await client.read(key: string): Promise<ConfigEntry>
|
|
132
|
+
|
|
133
|
+
// Update
|
|
134
|
+
await client.update(
|
|
135
|
+
key: string,
|
|
136
|
+
value: Record<string, any>,
|
|
137
|
+
category?: string
|
|
138
|
+
): Promise<ConfigEntry>
|
|
139
|
+
|
|
140
|
+
// Delete
|
|
141
|
+
await client.delete(key: string): Promise<{ message: string }>
|
|
142
|
+
|
|
143
|
+
// List
|
|
144
|
+
await client.list(category?: string): Promise<ConfigEntry[]>
|
|
145
|
+
|
|
146
|
+
// Check existence
|
|
147
|
+
await client.exists(key: string): Promise<boolean>
|
|
148
|
+
|
|
149
|
+
// Count
|
|
150
|
+
await client.count(category?: string): Promise<number>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Batch Operations
|
|
74
154
|
|
|
75
155
|
```typescript
|
|
76
|
-
|
|
156
|
+
// Bulk create
|
|
157
|
+
await client.bulkCreate(
|
|
158
|
+
configs: Array<{ key: string; value: Record<string, any>; category?: string }>,
|
|
159
|
+
ignoreErrors?: boolean
|
|
160
|
+
): Promise<ConfigEntry[]>
|
|
161
|
+
|
|
162
|
+
// Bulk read
|
|
163
|
+
await client.bulkRead(
|
|
164
|
+
keys: string[],
|
|
165
|
+
ignoreErrors?: boolean
|
|
166
|
+
): Promise<ConfigEntry[]>
|
|
167
|
+
|
|
168
|
+
// Bulk delete
|
|
169
|
+
await client.bulkDelete(
|
|
170
|
+
keys: string[],
|
|
171
|
+
ignoreErrors?: boolean
|
|
172
|
+
): Promise<{ deleted: string[]; failed: Array<{ key: string; error: any }> }>
|
|
173
|
+
```
|
|
77
174
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
175
|
+
#### Cluster & Health
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
// Get service info
|
|
179
|
+
await client.getInfo(): Promise<Record<string, any>>
|
|
180
|
+
|
|
181
|
+
// Cluster status
|
|
182
|
+
await client.getClusterStatus(): Promise<ClusterStatus>
|
|
183
|
+
|
|
184
|
+
// Health check
|
|
185
|
+
await client.healthCheck(): Promise<{ status: string; node_id: string }>
|
|
186
|
+
|
|
187
|
+
// Get metrics
|
|
188
|
+
await client.getMetrics(): Promise<string>
|
|
85
189
|
```
|
|
86
190
|
|
|
87
|
-
##
|
|
191
|
+
## ๐ HTTPS/SSL Configuration
|
|
88
192
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
193
|
+
### Production (Valid Certificates)
|
|
194
|
+
|
|
195
|
+
For production environments with valid SSL certificates from Let's Encrypt or a trusted CA:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const client = new OpenSecureConfClient({
|
|
199
|
+
baseUrl: 'https://config.example.com',
|
|
200
|
+
userKey: 'my-secret-key-12345',
|
|
201
|
+
apiKey: 'production-api-key',
|
|
202
|
+
// rejectUnauthorized: true (default)
|
|
203
|
+
});
|
|
94
204
|
```
|
|
95
205
|
|
|
96
|
-
|
|
206
|
+
### Development (Self-Signed Certificates)
|
|
97
207
|
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
tests/client.test.ts,"import { OpenSecureConfClient, OpenSecureConfError } from '../src/index';
|
|
208
|
+
For development with self-signed certificates:
|
|
101
209
|
|
|
102
|
-
|
|
103
|
-
|
|
210
|
+
```typescript
|
|
211
|
+
const client = new OpenSecureConfClient({
|
|
212
|
+
baseUrl: 'https://localhost:9443',
|
|
213
|
+
userKey: 'my-secret-key-12345',
|
|
214
|
+
rejectUnauthorized: false, // โ ๏ธ Only for development!
|
|
215
|
+
});
|
|
216
|
+
```
|
|
104
217
|
|
|
105
|
-
|
|
106
|
-
client = new OpenSecureConfClient({
|
|
107
|
-
baseUrl: 'http://localhost:9000',
|
|
108
|
-
userKey: 'test-user-key-12345',
|
|
109
|
-
apiKey: 'your-super-secret-api-key-here',
|
|
110
|
-
});
|
|
111
|
-
});
|
|
218
|
+
**โ ๏ธ Security Warning**: Never use `rejectUnauthorized: false` in production! This disables SSL certificate validation and makes your connection vulnerable to man-in-the-middle attacks.
|
|
112
219
|
|
|
113
|
-
|
|
114
|
-
it('should create client with valid options', () => {
|
|
115
|
-
expect(client).toBeInstanceOf(OpenSecureConfClient);
|
|
116
|
-
});
|
|
220
|
+
### Node.js HTTPS Agent
|
|
117
221
|
|
|
118
|
-
|
|
119
|
-
expect(() => {
|
|
120
|
-
new OpenSecureConfClient({
|
|
121
|
-
baseUrl: 'http://localhost:9000',
|
|
122
|
-
userKey: 'short',
|
|
123
|
-
});
|
|
124
|
-
}).toThrow('userKey must be at least 8 characters long');
|
|
125
|
-
});
|
|
126
|
-
});
|
|
222
|
+
When running in Node.js, the client automatically creates an HTTPS agent with the appropriate SSL settings:
|
|
127
223
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
224
|
+
```typescript
|
|
225
|
+
// In Node.js, HTTPS agent is automatically configured
|
|
226
|
+
const client = new OpenSecureConfClient({
|
|
227
|
+
baseUrl: 'https://localhost:9443',
|
|
228
|
+
userKey: 'my-secret-key-12345',
|
|
229
|
+
rejectUnauthorized: false,
|
|
230
|
+
});
|
|
131
231
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
expect(result).toHaveProperty('value');
|
|
136
|
-
});
|
|
232
|
+
// Agent is used for all HTTPS requests automatically
|
|
233
|
+
await client.getInfo();
|
|
234
|
+
```
|
|
137
235
|
|
|
138
|
-
|
|
139
|
-
const result = await client.read(testKey);
|
|
140
|
-
expect(result).toHaveProperty('key', testKey);
|
|
141
|
-
});
|
|
236
|
+
### Browser Usage
|
|
142
237
|
|
|
143
|
-
|
|
144
|
-
const result = await client.list();
|
|
145
|
-
expect(Array.isArray(result)).toBe(true);
|
|
146
|
-
});
|
|
238
|
+
In browser environments, the native `fetch` API handles HTTPS automatically. Certificate validation follows browser security policies:
|
|
147
239
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
240
|
+
```typescript
|
|
241
|
+
// Works in browsers with valid certificates
|
|
242
|
+
const client = new OpenSecureConfClient({
|
|
243
|
+
baseUrl: 'https://config.example.com',
|
|
244
|
+
userKey: 'my-secret-key-12345',
|
|
153
245
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*/
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## ๐ Usage Examples
|
|
158
249
|
|
|
159
|
-
|
|
250
|
+
### Complete Workflow
|
|
160
251
|
|
|
161
|
-
|
|
162
|
-
|
|
252
|
+
```typescript
|
|
253
|
+
import OpenSecureConfClient, { OpenSecureConfError } from 'opensecureconf-client';
|
|
254
|
+
|
|
255
|
+
async function workflow() {
|
|
163
256
|
const client = new OpenSecureConfClient({
|
|
164
|
-
baseUrl: '
|
|
257
|
+
baseUrl: 'https://localhost:9443',
|
|
165
258
|
userKey: 'my-secure-encryption-key',
|
|
166
|
-
apiKey: '
|
|
259
|
+
apiKey: 'workflow-api-key',
|
|
260
|
+
rejectUnauthorized: false,
|
|
167
261
|
});
|
|
168
262
|
|
|
169
263
|
try {
|
|
170
|
-
//
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
264
|
+
// 1. Health check
|
|
265
|
+
const health = await client.healthCheck();
|
|
266
|
+
console.log(`Status: ${health.status}`);
|
|
267
|
+
|
|
268
|
+
// 2. Create configurations
|
|
269
|
+
await client.create('database', {
|
|
270
|
+
host: 'postgres.local',
|
|
271
|
+
port: 5432,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// 3. Batch create
|
|
275
|
+
await client.bulkCreate([
|
|
276
|
+
{ key: 'redis', value: { host: 'redis.local', port: 6379 } },
|
|
277
|
+
{ key: 'cache', value: { ttl: 3600, maxSize: 1000 } },
|
|
278
|
+
], true);
|
|
279
|
+
|
|
280
|
+
// 4. List all
|
|
281
|
+
const configs = await client.list();
|
|
282
|
+
console.log(`Total: ${configs.length} configurations`);
|
|
283
|
+
|
|
284
|
+
// 5. Update
|
|
285
|
+
await client.update('database', {
|
|
286
|
+
host: 'postgres.local',
|
|
287
|
+
port: 5432,
|
|
288
|
+
ssl: true,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// 6. Cleanup
|
|
292
|
+
await client.bulkDelete(['database', 'redis', 'cache'], true);
|
|
194
293
|
|
|
195
294
|
} catch (error) {
|
|
196
|
-
if (error
|
|
197
|
-
console.error(
|
|
198
|
-
} else {
|
|
199
|
-
console.error('Error:', error);
|
|
295
|
+
if (error instanceof OpenSecureConfError) {
|
|
296
|
+
console.error(`Error ${error.statusCode}: ${error.message}`);
|
|
200
297
|
}
|
|
201
298
|
}
|
|
202
299
|
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Error Handling
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
try {
|
|
306
|
+
const config = await client.read('nonexistent');
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (error instanceof OpenSecureConfError) {
|
|
309
|
+
switch (error.statusCode) {
|
|
310
|
+
case 401:
|
|
311
|
+
console.error('Authentication failed');
|
|
312
|
+
break;
|
|
313
|
+
case 404:
|
|
314
|
+
console.error('Configuration not found');
|
|
315
|
+
break;
|
|
316
|
+
case 408:
|
|
317
|
+
console.error('Request timeout');
|
|
318
|
+
break;
|
|
319
|
+
default:
|
|
320
|
+
console.error(`API error: ${error.message}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
203
325
|
|
|
204
|
-
|
|
205
|
-
"
|
|
206
|
-
examples/advanced-usage.ts,"/**
|
|
207
|
-
* Advanced usage example with TypeScript
|
|
208
|
-
*/
|
|
326
|
+
### Cluster Operations
|
|
209
327
|
|
|
328
|
+
```typescript
|
|
329
|
+
// Check cluster status
|
|
330
|
+
const status = await client.getClusterStatus();
|
|
331
|
+
if (status.enabled) {
|
|
332
|
+
console.log(`Mode: ${status.mode}`);
|
|
333
|
+
console.log(`Nodes: ${status.healthy_nodes}/${status.total_nodes}`);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Get Prometheus metrics
|
|
337
|
+
const metrics = await client.getMetrics();
|
|
338
|
+
console.log(metrics);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## ๐ ๏ธ Advanced Usage
|
|
342
|
+
|
|
343
|
+
### Custom Timeout
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
const client = new OpenSecureConfClient({
|
|
347
|
+
baseUrl: 'https://config.example.com',
|
|
348
|
+
userKey: 'my-secret-key-12345',
|
|
349
|
+
timeout: 5000, // 5 seconds
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Category Filtering
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
// Create with category
|
|
357
|
+
await client.create('db', { host: 'localhost' }, 'production');
|
|
358
|
+
await client.create('cache', { ttl: 3600 }, 'production');
|
|
359
|
+
|
|
360
|
+
// List by category
|
|
361
|
+
const prodConfigs = await client.list('production');
|
|
362
|
+
console.log(prodConfigs); // Only production configs
|
|
363
|
+
|
|
364
|
+
// Count by category
|
|
365
|
+
const count = await client.count('production');
|
|
366
|
+
console.log(`Production configs: ${count}`);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Batch Operations with Error Handling
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
const result = await client.bulkDelete(
|
|
373
|
+
['config1', 'config2', 'config3'],
|
|
374
|
+
true // ignoreErrors
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
console.log(`Deleted: ${result.deleted.length}`);
|
|
378
|
+
console.log(`Failed: ${result.failed.length}`);
|
|
379
|
+
|
|
380
|
+
for (const failure of result.failed) {
|
|
381
|
+
console.error(`Failed to delete ${failure.key}: ${failure.error}`);
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## ๐ TypeScript Support
|
|
386
|
+
|
|
387
|
+
Full TypeScript definitions included:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
210
390
|
import OpenSecureConfClient, {
|
|
391
|
+
OpenSecureConfOptions,
|
|
211
392
|
ConfigEntry,
|
|
393
|
+
ClusterStatus,
|
|
212
394
|
OpenSecureConfError,
|
|
213
395
|
} from 'opensecureconf-client';
|
|
214
396
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
397
|
+
// All types are fully typed
|
|
398
|
+
const options: OpenSecureConfOptions = {
|
|
399
|
+
baseUrl: 'https://localhost:9443',
|
|
400
|
+
userKey: 'my-key',
|
|
401
|
+
rejectUnauthorized: false,
|
|
402
|
+
};
|
|
221
403
|
|
|
222
|
-
|
|
223
|
-
private client: OpenSecureConfClient;
|
|
404
|
+
const client = new OpenSecureConfClient(options);
|
|
224
405
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
apiKey,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
406
|
+
// Return types are inferred
|
|
407
|
+
const config: ConfigEntry = await client.read('key');
|
|
408
|
+
const status: ClusterStatus = await client.getClusterStatus();
|
|
409
|
+
```
|
|
232
410
|
|
|
233
|
-
|
|
234
|
-
const config = await this.client.read(key);
|
|
235
|
-
return config.value as DatabaseConfig;
|
|
236
|
-
}
|
|
411
|
+
## ๐ Security Best Practices
|
|
237
412
|
|
|
238
|
-
|
|
239
|
-
await this.client.create(key, config as Record<string, any>, 'database');
|
|
240
|
-
}
|
|
413
|
+
### โ
Do's
|
|
241
414
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
249
|
-
try {
|
|
250
|
-
return await operation();
|
|
251
|
-
} catch (error) {
|
|
252
|
-
lastError = error as Error;
|
|
253
|
-
|
|
254
|
-
if (error instanceof OpenSecureConfError) {
|
|
255
|
-
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (i < maxRetries - 1) {
|
|
261
|
-
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
415
|
+
- Use HTTPS in production (`https://`)
|
|
416
|
+
- Use valid SSL certificates (Let's Encrypt, trusted CA)
|
|
417
|
+
- Set strong user keys (16+ characters)
|
|
418
|
+
- Enable API key authentication
|
|
419
|
+
- Use environment variables for secrets
|
|
420
|
+
- Set appropriate timeouts
|
|
265
421
|
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
}
|
|
422
|
+
### โ Don'ts
|
|
269
423
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
);
|
|
424
|
+
- **Never** use `rejectUnauthorized: false` in production
|
|
425
|
+
- **Never** hardcode credentials in source code
|
|
426
|
+
- **Never** commit secrets to version control
|
|
427
|
+
- **Never** use short encryption keys (<8 chars)
|
|
428
|
+
- **Never** expose API endpoints without authentication
|
|
276
429
|
|
|
277
|
-
|
|
278
|
-
await manager.setDatabaseConfig('prod-db', {
|
|
279
|
-
host: 'db.example.com',
|
|
280
|
-
port: 5432,
|
|
281
|
-
database: 'production',
|
|
282
|
-
ssl: true,
|
|
283
|
-
});
|
|
430
|
+
### Environment Variables
|
|
284
431
|
|
|
285
|
-
|
|
286
|
-
|
|
432
|
+
```typescript
|
|
433
|
+
const client = new OpenSecureConfClient({
|
|
434
|
+
baseUrl: process.env.OSC_BASE_URL!,
|
|
435
|
+
userKey: process.env.OSC_USER_KEY!,
|
|
436
|
+
apiKey: process.env.OSC_API_KEY,
|
|
437
|
+
rejectUnauthorized: process.env.NODE_ENV === 'production',
|
|
438
|
+
});
|
|
439
|
+
```
|
|
287
440
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
441
|
+
## ๐ Browser vs Node.js
|
|
442
|
+
|
|
443
|
+
### Node.js
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
// Automatic HTTPS agent setup
|
|
447
|
+
// Supports rejectUnauthorized option
|
|
448
|
+
// Full control over SSL/TLS
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Browser
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
// Uses native fetch API
|
|
455
|
+
// SSL validation by browser
|
|
456
|
+
// rejectUnauthorized ignored (browser controls SSL)
|
|
457
|
+
// Works with CORS-enabled servers
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## ๐ Error Codes
|
|
461
|
+
|
|
462
|
+
| Status Code | Error Type | Description |
|
|
463
|
+
|-------------|------------|-------------|
|
|
464
|
+
| 0 | Network Error | Connection failed |
|
|
465
|
+
| 400 | Bad Request | Invalid parameters |
|
|
466
|
+
| 401 | Authentication | Invalid user key |
|
|
467
|
+
| 403 | Forbidden | Invalid API key |
|
|
468
|
+
| 404 | Not Found | Configuration not found |
|
|
469
|
+
| 408 | Timeout | Request timeout |
|
|
470
|
+
| 429 | Rate Limit | Too many requests |
|
|
471
|
+
| 500+ | Server Error | Internal server error |
|
|
472
|
+
|
|
473
|
+
## ๐ Links
|
|
474
|
+
|
|
475
|
+
- **GitHub**: [OpenSecureConf](https://github.com/lordraw77/OpenSecureConf)
|
|
476
|
+
- **Docker Hub**: [lordraw/open-secureconfiguration](https://hub.docker.com/r/lordraw/open-secureconfiguration)
|
|
477
|
+
- **PyPI Client**: [opensecureconf-client](https://pypi.org/project/opensecureconf-client/)
|
|
478
|
+
- **Documentation**: [GitHub README](https://github.com/lordraw77/OpenSecureConf/blob/main/README.md)
|
|
479
|
+
|
|
480
|
+
## ๐ License
|
|
481
|
+
|
|
482
|
+
MIT License - see [LICENSE](LICENSE)
|
|
483
|
+
|
|
484
|
+
## ๐ Contributing
|
|
485
|
+
|
|
486
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
487
|
+
|
|
488
|
+
## ๐ Changelog
|
|
489
|
+
|
|
490
|
+
### v1.1.0
|
|
491
|
+
- โจ Added HTTPS/SSL support
|
|
492
|
+
- โจ Added `rejectUnauthorized` option
|
|
493
|
+
- โจ Auto HTTPS agent for Node.js
|
|
494
|
+
- โจ Batch operations (bulkCreate, bulkRead, bulkDelete)
|
|
495
|
+
- โจ Utility methods (exists, count)
|
|
496
|
+
- ๐ Enhanced SSL error messages
|
|
497
|
+
- ๐ Improved documentation
|
|
498
|
+
|
|
499
|
+
### v1.0.0
|
|
500
|
+
- ๐ Initial release
|
|
501
|
+
- โ
Basic CRUD operations
|
|
502
|
+
- โ
Cluster support
|
|
503
|
+
- โ
TypeScript definitions
|
|
504
|
+
|
|
505
|
+
---
|
|
506
|
+
|
|
507
|
+
**OpenSecureConf TypeScript Client** - Secure configuration management made simple.
|
|
296
508
|
|
|
297
|
-
|
|
509
|
+
**Version**: 2.2.1
|
|
510
|
+
**Author**: lordraw77
|
|
511
|
+
**Support**: [GitHub Issues](https://github.com/lordraw77/OpenSecureConf/issues)
|
package/package.json
CHANGED