atp-sdk 1.0.0
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/CHANGELOG.md +111 -0
- package/LICENSE +201 -0
- package/README.md +633 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +55 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client/atp.d.ts.map +1 -0
- package/dist/client/atp.js +90 -0
- package/dist/client/atp.js.map +1 -0
- package/dist/client/audit.d.ts.map +1 -0
- package/dist/client/audit.js +125 -0
- package/dist/client/audit.js.map +1 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +190 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/credentials.d.ts.map +1 -0
- package/dist/client/credentials.js +112 -0
- package/dist/client/credentials.js.map +1 -0
- package/dist/client/gateway.d.ts.map +1 -0
- package/dist/client/gateway.js +214 -0
- package/dist/client/gateway.js.map +1 -0
- package/dist/client/identity.d.ts.map +1 -0
- package/dist/client/identity.js +94 -0
- package/dist/client/identity.js.map +1 -0
- package/dist/client/permissions.d.ts.map +1 -0
- package/dist/client/permissions.js +132 -0
- package/dist/client/permissions.js.map +1 -0
- package/dist/index.cjs +89 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/simple-agent.d.ts.map +1 -0
- package/dist/simple-agent.js +261 -0
- package/dist/simple-agent.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +48 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +100 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/did.d.ts.map +1 -0
- package/dist/utils/did.js +225 -0
- package/dist/utils/did.js.map +1 -0
- package/dist/utils/jwt.d.ts.map +1 -0
- package/dist/utils/jwt.js +235 -0
- package/dist/utils/jwt.js.map +1 -0
- package/docs/README.md +362 -0
- package/docs/api/README.md +1077 -0
- package/docs/guides/authentication.md +667 -0
- package/docs/guides/best-practices.md +1004 -0
- package/docs/guides/configuration.md +588 -0
- package/docs/guides/error-handling.md +1073 -0
- package/docs/guides/troubleshooting.md +850 -0
- package/examples/01-basic-setup.js +53 -0
- package/examples/02-identity-management.js +130 -0
- package/examples/03-verifiable-credentials.js +234 -0
- package/examples/04-permissions-and-access-control.js +326 -0
- package/examples/05-audit-logging.js +310 -0
- package/examples/06-real-time-monitoring.js +302 -0
- package/examples/07-advanced-use-cases.js +584 -0
- package/examples/README.md +211 -0
- package/examples/index.js +135 -0
- package/examples/simple-3-line.ts +51 -0
- package/package.json +108 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
This guide covers advanced configuration options for the ATP™ SDK.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Basic Configuration](#basic-configuration)
|
|
8
|
+
2. [Environment-based Configuration](#environment-based-configuration)
|
|
9
|
+
3. [Service-specific Configuration](#service-specific-configuration)
|
|
10
|
+
4. [Network Configuration](#network-configuration)
|
|
11
|
+
5. [Security Configuration](#security-configuration)
|
|
12
|
+
6. [Performance Configuration](#performance-configuration)
|
|
13
|
+
7. [Development vs Production](#development-vs-production)
|
|
14
|
+
|
|
15
|
+
## Basic Configuration
|
|
16
|
+
|
|
17
|
+
### Quick Configuration
|
|
18
|
+
|
|
19
|
+
For local development, use the `createQuickConfig` helper:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { createQuickConfig } from '@atp/sdk';
|
|
23
|
+
|
|
24
|
+
const config = createQuickConfig('http://localhost', {
|
|
25
|
+
timeout: 30000,
|
|
26
|
+
retries: 3,
|
|
27
|
+
auth: {
|
|
28
|
+
did: 'did:atp:testnet:example',
|
|
29
|
+
privateKey: 'your-private-key'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Full Configuration
|
|
35
|
+
|
|
36
|
+
For production environments, provide a complete configuration:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const config = {
|
|
40
|
+
baseUrl: 'https://api.atp.example.com',
|
|
41
|
+
|
|
42
|
+
// Service endpoints (optional - will use baseUrl + default ports if not specified)
|
|
43
|
+
services: {
|
|
44
|
+
identity: 'https://identity.atp.example.com',
|
|
45
|
+
credentials: 'https://credentials.atp.example.com',
|
|
46
|
+
permissions: 'https://permissions.atp.example.com',
|
|
47
|
+
audit: 'https://audit.atp.example.com',
|
|
48
|
+
gateway: 'https://gateway.atp.example.com'
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// Authentication
|
|
52
|
+
auth: {
|
|
53
|
+
did: 'did:atp:mainnet:your-identifier',
|
|
54
|
+
privateKey: process.env.ATP_PRIVATE_KEY,
|
|
55
|
+
// OR use token-based auth
|
|
56
|
+
// token: process.env.ATP_AUTH_TOKEN
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Network configuration
|
|
60
|
+
timeout: 30000, // 30 seconds
|
|
61
|
+
retries: 3, // Retry failed requests 3 times
|
|
62
|
+
retryDelay: 1000, // Wait 1 second between retries
|
|
63
|
+
|
|
64
|
+
// Debugging
|
|
65
|
+
debug: process.env.NODE_ENV === 'development',
|
|
66
|
+
|
|
67
|
+
// Custom headers
|
|
68
|
+
headers: {
|
|
69
|
+
'User-Agent': 'MyApp/1.0.0',
|
|
70
|
+
'X-API-Version': '1.0'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Environment-based Configuration
|
|
76
|
+
|
|
77
|
+
### Environment Variables
|
|
78
|
+
|
|
79
|
+
The SDK recognizes these environment variables:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Base configuration
|
|
83
|
+
ATP_BASE_URL=https://api.atp.example.com
|
|
84
|
+
ATP_TIMEOUT=30000
|
|
85
|
+
ATP_RETRIES=3
|
|
86
|
+
ATP_RETRY_DELAY=1000
|
|
87
|
+
ATP_DEBUG=true
|
|
88
|
+
|
|
89
|
+
# Authentication
|
|
90
|
+
ATP_DID=did:atp:mainnet:your-identifier
|
|
91
|
+
ATP_PRIVATE_KEY=your-private-key-hex
|
|
92
|
+
ATP_AUTH_TOKEN=your-jwt-token
|
|
93
|
+
|
|
94
|
+
# Service endpoints
|
|
95
|
+
ATP_IDENTITY_URL=https://identity.atp.example.com
|
|
96
|
+
ATP_CREDENTIALS_URL=https://credentials.atp.example.com
|
|
97
|
+
ATP_PERMISSIONS_URL=https://permissions.atp.example.com
|
|
98
|
+
ATP_AUDIT_URL=https://audit.atp.example.com
|
|
99
|
+
ATP_GATEWAY_URL=https://gateway.atp.example.com
|
|
100
|
+
|
|
101
|
+
# TLS Configuration
|
|
102
|
+
ATP_TLS_CERT_PATH=/path/to/client.crt
|
|
103
|
+
ATP_TLS_KEY_PATH=/path/to/client.key
|
|
104
|
+
ATP_TLS_CA_PATH=/path/to/ca.crt
|
|
105
|
+
ATP_TLS_VERIFY=true
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Loading from Environment
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
import { createConfigFromEnv } from '@atp/sdk';
|
|
112
|
+
|
|
113
|
+
// Loads configuration from environment variables
|
|
114
|
+
const config = createConfigFromEnv();
|
|
115
|
+
|
|
116
|
+
// Or with overrides
|
|
117
|
+
const config = createConfigFromEnv({
|
|
118
|
+
timeout: 60000, // Override default timeout
|
|
119
|
+
debug: true // Force debug mode
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Configuration Files
|
|
124
|
+
|
|
125
|
+
Load configuration from JSON files:
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
import fs from 'fs';
|
|
129
|
+
|
|
130
|
+
// Load from JSON file
|
|
131
|
+
const configFile = process.env.ATP_CONFIG_FILE || './atp-config.json';
|
|
132
|
+
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
|
|
133
|
+
|
|
134
|
+
// Merge with environment overrides
|
|
135
|
+
config.auth.privateKey = process.env.ATP_PRIVATE_KEY || config.auth.privateKey;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Example `atp-config.json`:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"baseUrl": "https://api.atp.example.com",
|
|
143
|
+
"services": {
|
|
144
|
+
"identity": "https://identity.atp.example.com:443",
|
|
145
|
+
"credentials": "https://credentials.atp.example.com:443",
|
|
146
|
+
"permissions": "https://permissions.atp.example.com:443",
|
|
147
|
+
"audit": "https://audit.atp.example.com:443",
|
|
148
|
+
"gateway": "https://gateway.atp.example.com:443"
|
|
149
|
+
},
|
|
150
|
+
"timeout": 30000,
|
|
151
|
+
"retries": 3,
|
|
152
|
+
"retryDelay": 1000,
|
|
153
|
+
"debug": false,
|
|
154
|
+
"headers": {
|
|
155
|
+
"User-Agent": "MyApp/1.0.0"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Service-specific Configuration
|
|
161
|
+
|
|
162
|
+
### Custom Service URLs
|
|
163
|
+
|
|
164
|
+
Override specific service endpoints:
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
const config = {
|
|
168
|
+
baseUrl: 'https://api.atp.example.com',
|
|
169
|
+
services: {
|
|
170
|
+
// Use custom identity service
|
|
171
|
+
identity: 'https://custom-identity.example.com',
|
|
172
|
+
|
|
173
|
+
// Use internal audit service
|
|
174
|
+
audit: 'http://internal-audit.local:3004',
|
|
175
|
+
|
|
176
|
+
// Other services use baseUrl + default ports
|
|
177
|
+
credentials: undefined, // Will use baseUrl:3002
|
|
178
|
+
permissions: undefined, // Will use baseUrl:3003
|
|
179
|
+
gateway: undefined // Will use baseUrl:3000
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Load Balancing Configuration
|
|
185
|
+
|
|
186
|
+
For high availability deployments:
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
const config = {
|
|
190
|
+
services: {
|
|
191
|
+
identity: [
|
|
192
|
+
'https://identity-1.atp.example.com',
|
|
193
|
+
'https://identity-2.atp.example.com',
|
|
194
|
+
'https://identity-3.atp.example.com'
|
|
195
|
+
],
|
|
196
|
+
credentials: [
|
|
197
|
+
'https://creds-1.atp.example.com',
|
|
198
|
+
'https://creds-2.atp.example.com'
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
loadBalancing: {
|
|
202
|
+
strategy: 'round-robin', // 'round-robin', 'random', 'least-connections'
|
|
203
|
+
healthCheck: true,
|
|
204
|
+
healthCheckInterval: 30000
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Network Configuration
|
|
210
|
+
|
|
211
|
+
### Timeout Configuration
|
|
212
|
+
|
|
213
|
+
Configure different timeouts for different operations:
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
const config = {
|
|
217
|
+
timeout: 30000, // Default timeout
|
|
218
|
+
|
|
219
|
+
// Per-service timeouts
|
|
220
|
+
serviceTimeouts: {
|
|
221
|
+
identity: 10000, // Identity operations: 10s
|
|
222
|
+
credentials: 20000, // Credential operations: 20s
|
|
223
|
+
permissions: 5000, // Permission checks: 5s
|
|
224
|
+
audit: 60000, // Audit queries: 60s
|
|
225
|
+
gateway: 120000 // Real-time connections: 2min
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
// Per-operation timeouts
|
|
229
|
+
operationTimeouts: {
|
|
230
|
+
'identity.resolve': 5000,
|
|
231
|
+
'credentials.verify': 15000,
|
|
232
|
+
'audit.generateReport': 300000 // 5 minutes for reports
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Retry Configuration
|
|
238
|
+
|
|
239
|
+
Advanced retry strategies:
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
const config = {
|
|
243
|
+
retries: 3,
|
|
244
|
+
retryDelay: 1000,
|
|
245
|
+
|
|
246
|
+
// Exponential backoff
|
|
247
|
+
retryStrategy: 'exponential',
|
|
248
|
+
maxRetryDelay: 30000,
|
|
249
|
+
|
|
250
|
+
// Retry conditions
|
|
251
|
+
retryCondition: (error) => {
|
|
252
|
+
// Retry on network errors and 5xx responses
|
|
253
|
+
return error.code === 'ECONNRESET' ||
|
|
254
|
+
error.code === 'ETIMEDOUT' ||
|
|
255
|
+
(error.status >= 500 && error.status < 600);
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
// Per-service retry configuration
|
|
259
|
+
serviceRetries: {
|
|
260
|
+
audit: {
|
|
261
|
+
retries: 5, // More retries for audit service
|
|
262
|
+
retryDelay: 2000
|
|
263
|
+
},
|
|
264
|
+
permissions: {
|
|
265
|
+
retries: 1, // Fewer retries for real-time decisions
|
|
266
|
+
retryDelay: 500
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Proxy Configuration
|
|
273
|
+
|
|
274
|
+
Configure HTTP/HTTPS proxies:
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
const config = {
|
|
278
|
+
proxy: {
|
|
279
|
+
host: 'proxy.company.com',
|
|
280
|
+
port: 8080,
|
|
281
|
+
auth: {
|
|
282
|
+
username: 'proxy-user',
|
|
283
|
+
password: 'proxy-pass'
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
// SOCKS proxy
|
|
288
|
+
socksProxy: {
|
|
289
|
+
host: 'socks-proxy.company.com',
|
|
290
|
+
port: 1080,
|
|
291
|
+
type: 5 // SOCKS5
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Security Configuration
|
|
297
|
+
|
|
298
|
+
### TLS Configuration
|
|
299
|
+
|
|
300
|
+
Configure TLS/SSL settings:
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
const config = {
|
|
304
|
+
tls: {
|
|
305
|
+
// Client certificate authentication
|
|
306
|
+
cert: fs.readFileSync('./client.crt'),
|
|
307
|
+
key: fs.readFileSync('./client.key'),
|
|
308
|
+
ca: fs.readFileSync('./ca.crt'),
|
|
309
|
+
|
|
310
|
+
// Certificate verification
|
|
311
|
+
rejectUnauthorized: true,
|
|
312
|
+
checkServerIdentity: true,
|
|
313
|
+
|
|
314
|
+
// TLS version
|
|
315
|
+
minVersion: 'TLSv1.2',
|
|
316
|
+
maxVersion: 'TLSv1.3',
|
|
317
|
+
|
|
318
|
+
// Cipher suites
|
|
319
|
+
ciphers: 'ECDHE+AESGCM:ECDHE+CHACHA20:DHE+AESGCM',
|
|
320
|
+
|
|
321
|
+
// OCSP stapling
|
|
322
|
+
requestOCSP: true
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### API Key Configuration
|
|
328
|
+
|
|
329
|
+
For API key-based authentication:
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
const config = {
|
|
333
|
+
auth: {
|
|
334
|
+
apiKey: process.env.ATP_API_KEY,
|
|
335
|
+
apiKeyHeader: 'X-ATP-API-Key', // Custom header name
|
|
336
|
+
|
|
337
|
+
// API key rotation
|
|
338
|
+
rotateApiKey: true,
|
|
339
|
+
rotationInterval: 24 * 60 * 60 * 1000 // 24 hours
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Rate Limiting
|
|
345
|
+
|
|
346
|
+
Configure client-side rate limiting:
|
|
347
|
+
|
|
348
|
+
```javascript
|
|
349
|
+
const config = {
|
|
350
|
+
rateLimit: {
|
|
351
|
+
enabled: true,
|
|
352
|
+
requests: 100, // Max requests
|
|
353
|
+
window: 60000, // Per 60 seconds
|
|
354
|
+
burst: 10, // Burst capacity
|
|
355
|
+
|
|
356
|
+
// Per-service limits
|
|
357
|
+
serviceLimits: {
|
|
358
|
+
audit: { requests: 50, window: 60000 },
|
|
359
|
+
permissions: { requests: 200, window: 60000 }
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Performance Configuration
|
|
366
|
+
|
|
367
|
+
### Connection Pooling
|
|
368
|
+
|
|
369
|
+
Configure HTTP connection pooling:
|
|
370
|
+
|
|
371
|
+
```javascript
|
|
372
|
+
const config = {
|
|
373
|
+
connectionPool: {
|
|
374
|
+
maxSockets: 50, // Max concurrent connections
|
|
375
|
+
maxFreeSockets: 10, // Keep-alive connections
|
|
376
|
+
timeout: 60000, // Connection timeout
|
|
377
|
+
freeSocketTimeout: 15000, // Keep-alive timeout
|
|
378
|
+
|
|
379
|
+
// Per-host limits
|
|
380
|
+
maxSocketsPerHost: 10
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Caching
|
|
386
|
+
|
|
387
|
+
Configure response caching:
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
const config = {
|
|
391
|
+
cache: {
|
|
392
|
+
enabled: true,
|
|
393
|
+
ttl: 300000, // 5 minutes default TTL
|
|
394
|
+
|
|
395
|
+
// Per-operation caching
|
|
396
|
+
operationCache: {
|
|
397
|
+
'identity.resolve': { ttl: 600000 }, // 10 minutes
|
|
398
|
+
'credentials.getSchema': { ttl: 3600000 }, // 1 hour
|
|
399
|
+
'permissions.getPolicy': { ttl: 1800000 } // 30 minutes
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
// Cache storage
|
|
403
|
+
storage: 'memory', // 'memory', 'redis', 'file'
|
|
404
|
+
|
|
405
|
+
// Redis configuration (if using Redis)
|
|
406
|
+
redis: {
|
|
407
|
+
host: 'redis.example.com',
|
|
408
|
+
port: 6379,
|
|
409
|
+
password: process.env.REDIS_PASSWORD
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
### Compression
|
|
416
|
+
|
|
417
|
+
Enable response compression:
|
|
418
|
+
|
|
419
|
+
```javascript
|
|
420
|
+
const config = {
|
|
421
|
+
compression: {
|
|
422
|
+
enabled: true,
|
|
423
|
+
algorithms: ['gzip', 'deflate', 'br'], // Supported algorithms
|
|
424
|
+
threshold: 1024 // Minimum size to compress (bytes)
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Development vs Production
|
|
430
|
+
|
|
431
|
+
### Development Configuration
|
|
432
|
+
|
|
433
|
+
```javascript
|
|
434
|
+
// development.config.js
|
|
435
|
+
export const developmentConfig = {
|
|
436
|
+
baseUrl: 'http://localhost',
|
|
437
|
+
|
|
438
|
+
// Relaxed timeouts for debugging
|
|
439
|
+
timeout: 60000,
|
|
440
|
+
retries: 1,
|
|
441
|
+
|
|
442
|
+
// Enable debugging
|
|
443
|
+
debug: true,
|
|
444
|
+
|
|
445
|
+
// Mock authentication for testing
|
|
446
|
+
auth: {
|
|
447
|
+
mock: true,
|
|
448
|
+
mockUser: 'did:atp:testnet:developer'
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
// Disable TLS verification for local testing
|
|
452
|
+
tls: {
|
|
453
|
+
rejectUnauthorized: false
|
|
454
|
+
},
|
|
455
|
+
|
|
456
|
+
// Enable request logging
|
|
457
|
+
logging: {
|
|
458
|
+
requests: true,
|
|
459
|
+
responses: true,
|
|
460
|
+
level: 'debug'
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### Production Configuration
|
|
466
|
+
|
|
467
|
+
```javascript
|
|
468
|
+
// production.config.js
|
|
469
|
+
export const productionConfig = {
|
|
470
|
+
baseUrl: 'https://api.atp.example.com',
|
|
471
|
+
|
|
472
|
+
// Production timeouts
|
|
473
|
+
timeout: 30000,
|
|
474
|
+
retries: 3,
|
|
475
|
+
retryDelay: 1000,
|
|
476
|
+
|
|
477
|
+
// Strict security
|
|
478
|
+
tls: {
|
|
479
|
+
rejectUnauthorized: true,
|
|
480
|
+
minVersion: 'TLSv1.2'
|
|
481
|
+
},
|
|
482
|
+
|
|
483
|
+
// Production authentication
|
|
484
|
+
auth: {
|
|
485
|
+
did: process.env.ATP_DID,
|
|
486
|
+
privateKey: process.env.ATP_PRIVATE_KEY
|
|
487
|
+
},
|
|
488
|
+
|
|
489
|
+
// Error reporting
|
|
490
|
+
errorReporting: {
|
|
491
|
+
enabled: true,
|
|
492
|
+
endpoint: 'https://errors.example.com/api/errors',
|
|
493
|
+
apiKey: process.env.ERROR_REPORTING_KEY
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
// Monitoring
|
|
497
|
+
monitoring: {
|
|
498
|
+
enabled: true,
|
|
499
|
+
metricsEndpoint: 'https://metrics.example.com',
|
|
500
|
+
healthCheckInterval: 30000
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Configuration Validation
|
|
506
|
+
|
|
507
|
+
Validate configuration before using:
|
|
508
|
+
|
|
509
|
+
```javascript
|
|
510
|
+
import { validateConfig } from '@atp/sdk';
|
|
511
|
+
|
|
512
|
+
const config = loadConfiguration();
|
|
513
|
+
|
|
514
|
+
// Validate configuration
|
|
515
|
+
const validation = validateConfig(config);
|
|
516
|
+
if (!validation.valid) {
|
|
517
|
+
console.error('Configuration validation failed:');
|
|
518
|
+
validation.errors.forEach(error => {
|
|
519
|
+
console.error(`- ${error.field}: ${error.message}`);
|
|
520
|
+
});
|
|
521
|
+
process.exit(1);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Configuration is valid, create client
|
|
525
|
+
const client = new ATPClient(config);
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
### Environment-specific Loading
|
|
529
|
+
|
|
530
|
+
```javascript
|
|
531
|
+
// config/index.js
|
|
532
|
+
const environment = process.env.NODE_ENV || 'development';
|
|
533
|
+
|
|
534
|
+
let config;
|
|
535
|
+
switch (environment) {
|
|
536
|
+
case 'development':
|
|
537
|
+
config = await import('./development.config.js');
|
|
538
|
+
break;
|
|
539
|
+
case 'staging':
|
|
540
|
+
config = await import('./staging.config.js');
|
|
541
|
+
break;
|
|
542
|
+
case 'production':
|
|
543
|
+
config = await import('./production.config.js');
|
|
544
|
+
break;
|
|
545
|
+
default:
|
|
546
|
+
throw new Error(`Unknown environment: ${environment}`);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export default config.default;
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
## Configuration Best Practices
|
|
553
|
+
|
|
554
|
+
1. **Environment Variables**: Use environment variables for sensitive data
|
|
555
|
+
2. **Validation**: Always validate configuration before use
|
|
556
|
+
3. **Defaults**: Provide sensible defaults for optional settings
|
|
557
|
+
4. **Documentation**: Document all configuration options
|
|
558
|
+
5. **Encryption**: Encrypt configuration files containing secrets
|
|
559
|
+
6. **Rotation**: Implement credential rotation for production
|
|
560
|
+
7. **Monitoring**: Monitor configuration changes
|
|
561
|
+
8. **Testing**: Test configuration in staging environments first
|
|
562
|
+
|
|
563
|
+
## Troubleshooting Configuration
|
|
564
|
+
|
|
565
|
+
### Common Issues
|
|
566
|
+
|
|
567
|
+
1. **Connection Refused**: Check baseUrl and service endpoints
|
|
568
|
+
2. **Timeout Errors**: Increase timeout values
|
|
569
|
+
3. **Authentication Failures**: Verify DID and private key
|
|
570
|
+
4. **Certificate Errors**: Check TLS configuration
|
|
571
|
+
5. **Rate Limiting**: Adjust rate limit settings
|
|
572
|
+
|
|
573
|
+
### Debug Configuration
|
|
574
|
+
|
|
575
|
+
Enable debug mode to troubleshoot:
|
|
576
|
+
|
|
577
|
+
```javascript
|
|
578
|
+
const config = {
|
|
579
|
+
debug: true,
|
|
580
|
+
logging: {
|
|
581
|
+
level: 'debug',
|
|
582
|
+
requests: true,
|
|
583
|
+
responses: true
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
This will log all HTTP requests and responses to help identify configuration issues.
|