@vedika-io/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 +196 -0
- package/LICENSE +21 -0
- package/README.md +445 -0
- package/SECURITY.md +301 -0
- package/dist/client.d.ts +89 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +222 -0
- package/dist/client.js.map +1 -0
- package/dist/exceptions.d.ts +225 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +268 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +294 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -0
package/SECURITY.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
We release security updates for the following versions of the Vedika JavaScript SDK:
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | ------------------ |
|
|
9
|
+
| 1.0.x | :white_check_mark: |
|
|
10
|
+
| < 1.0 | :x: |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
We take the security of the Vedika JavaScript SDK seriously. If you believe you have found a security vulnerability, please report it to us as described below.
|
|
15
|
+
|
|
16
|
+
### Please Do Not:
|
|
17
|
+
|
|
18
|
+
- Open a public GitHub issue for security vulnerabilities
|
|
19
|
+
- Post about the vulnerability in public forums or social media
|
|
20
|
+
- Attempt to exploit the vulnerability beyond verifying its existence
|
|
21
|
+
|
|
22
|
+
### Please Do:
|
|
23
|
+
|
|
24
|
+
**Report security vulnerabilities to: security@vedika.io**
|
|
25
|
+
|
|
26
|
+
Include the following information:
|
|
27
|
+
|
|
28
|
+
1. **Type of vulnerability** (e.g., authentication bypass, API key exposure, injection attack)
|
|
29
|
+
2. **Full description** of the vulnerability
|
|
30
|
+
3. **Steps to reproduce** the issue
|
|
31
|
+
4. **Potential impact** of the vulnerability
|
|
32
|
+
5. **Suggested fix** (if you have one)
|
|
33
|
+
6. **Your contact information** for follow-up
|
|
34
|
+
|
|
35
|
+
### What to Expect:
|
|
36
|
+
|
|
37
|
+
- **Acknowledgment**: We will acknowledge receipt of your vulnerability report within 48 hours
|
|
38
|
+
- **Updates**: We will send you regular updates about our progress
|
|
39
|
+
- **Timeline**: We aim to release a fix within 7-14 days for critical vulnerabilities
|
|
40
|
+
- **Credit**: We will credit you in our security advisory (unless you prefer to remain anonymous)
|
|
41
|
+
|
|
42
|
+
## Security Best Practices
|
|
43
|
+
|
|
44
|
+
### API Key Management
|
|
45
|
+
|
|
46
|
+
**Never expose your API keys:**
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// ❌ DON'T: Hardcode API keys
|
|
50
|
+
const client = new VedikaClient({ apiKey: 'vk_live_your_actual_key' });
|
|
51
|
+
|
|
52
|
+
// ✅ DO: Use environment variables
|
|
53
|
+
const client = new VedikaClient({ apiKey: process.env.VEDIKA_API_KEY });
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Use .gitignore:**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Add to .gitignore
|
|
60
|
+
.env
|
|
61
|
+
.env.local
|
|
62
|
+
*.key
|
|
63
|
+
credentials.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Rotate compromised keys immediately:**
|
|
67
|
+
|
|
68
|
+
If you accidentally expose your API key:
|
|
69
|
+
1. Immediately revoke it at https://vedika.io/dashboard.html
|
|
70
|
+
2. Generate a new key
|
|
71
|
+
3. Update your application with the new key
|
|
72
|
+
4. Review API logs for unauthorized usage
|
|
73
|
+
|
|
74
|
+
### Environment Variables
|
|
75
|
+
|
|
76
|
+
**Node.js:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# .env file
|
|
80
|
+
VEDIKA_API_KEY=vk_test_your_api_key_here
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import dotenv from 'dotenv';
|
|
85
|
+
dotenv.config();
|
|
86
|
+
|
|
87
|
+
const client = new VedikaClient({
|
|
88
|
+
apiKey: process.env.VEDIKA_API_KEY
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**React:**
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# .env.local
|
|
96
|
+
REACT_APP_VEDIKA_API_KEY=vk_test_your_api_key_here
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const client = new VedikaClient({
|
|
101
|
+
apiKey: process.env.REACT_APP_VEDIKA_API_KEY
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**WARNING**: Never expose API keys in client-side code in production. Use a backend proxy instead.
|
|
106
|
+
|
|
107
|
+
### Client-Side vs Server-Side
|
|
108
|
+
|
|
109
|
+
**Server-side (Node.js) - RECOMMENDED:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// ✅ Safe: API key stays on server
|
|
113
|
+
import { VedikaClient } from 'vedika-sdk';
|
|
114
|
+
|
|
115
|
+
const client = new VedikaClient({
|
|
116
|
+
apiKey: process.env.VEDIKA_API_KEY
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
app.post('/api/astrology', async (req, res) => {
|
|
120
|
+
const response = await client.askQuestion(req.body);
|
|
121
|
+
res.json(response);
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Client-side (Browser) - USE PROXY:**
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// ❌ UNSAFE: API key exposed in browser
|
|
129
|
+
// DON'T do this in production!
|
|
130
|
+
|
|
131
|
+
// ✅ Safe: Use your own backend as proxy
|
|
132
|
+
async function askQuestion(question: string, birthDetails: any) {
|
|
133
|
+
const response = await fetch('/api/astrology', {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
headers: { 'Content-Type': 'application/json' },
|
|
136
|
+
body: JSON.stringify({ question, birthDetails })
|
|
137
|
+
});
|
|
138
|
+
return response.json();
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Input Validation
|
|
143
|
+
|
|
144
|
+
**Always validate user input:**
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
interface BirthDetails {
|
|
148
|
+
datetime: string;
|
|
149
|
+
latitude: number;
|
|
150
|
+
longitude: number;
|
|
151
|
+
timezone?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function validateBirthDetails(details: BirthDetails): boolean {
|
|
155
|
+
// Check required fields
|
|
156
|
+
if (!details.datetime || !details.latitude || !details.longitude) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Validate latitude (-90 to 90)
|
|
161
|
+
if (details.latitude < -90 || details.latitude > 90) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Validate longitude (-180 to 180)
|
|
166
|
+
if (details.longitude < -180 || details.longitude > 180) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Validate datetime format (ISO 8601)
|
|
171
|
+
try {
|
|
172
|
+
new Date(details.datetime);
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### HTTPS Only
|
|
182
|
+
|
|
183
|
+
The SDK enforces HTTPS for all API requests. Never modify the base URL to use HTTP:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// ✅ HTTPS (default and required)
|
|
187
|
+
const client = new VedikaClient({
|
|
188
|
+
apiKey: process.env.VEDIKA_API_KEY,
|
|
189
|
+
baseUrl: 'https://vedika-api-854222120654.us-central1.run.app'
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// ❌ HTTP (will fail)
|
|
193
|
+
// DO NOT attempt to use HTTP
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Rate Limiting
|
|
197
|
+
|
|
198
|
+
Respect rate limits to prevent account suspension:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { RateLimitError } from 'vedika-sdk';
|
|
202
|
+
|
|
203
|
+
async function safeApiCall(
|
|
204
|
+
client: VedikaClient,
|
|
205
|
+
query: any
|
|
206
|
+
): Promise<any> {
|
|
207
|
+
const maxRetries = 3;
|
|
208
|
+
let retryDelay = 1000;
|
|
209
|
+
|
|
210
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
211
|
+
try {
|
|
212
|
+
return await client.askQuestion(query);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error instanceof RateLimitError) {
|
|
215
|
+
if (attempt < maxRetries - 1) {
|
|
216
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
|
217
|
+
retryDelay *= 2; // Exponential backoff
|
|
218
|
+
} else {
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Error Handling
|
|
230
|
+
|
|
231
|
+
Never expose sensitive information in error messages:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
try {
|
|
235
|
+
const response = await client.askQuestion({
|
|
236
|
+
question,
|
|
237
|
+
birthDetails
|
|
238
|
+
});
|
|
239
|
+
} catch (error) {
|
|
240
|
+
// ❌ DON'T: Log full error with potentially sensitive data
|
|
241
|
+
// console.error('API call failed:', error, 'with data:', birthDetails);
|
|
242
|
+
|
|
243
|
+
// ✅ DO: Log sanitized error message
|
|
244
|
+
console.error('API call failed. Check secure logs for details.');
|
|
245
|
+
// Store detailed error in secure logs only
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Dependency Security
|
|
250
|
+
|
|
251
|
+
Keep dependencies up to date:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Check for security vulnerabilities
|
|
255
|
+
npm audit
|
|
256
|
+
|
|
257
|
+
# Fix vulnerabilities
|
|
258
|
+
npm audit fix
|
|
259
|
+
|
|
260
|
+
# Update dependencies
|
|
261
|
+
npm update vedika-sdk axios
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Known Security Considerations
|
|
265
|
+
|
|
266
|
+
### Data Privacy
|
|
267
|
+
|
|
268
|
+
- **Birth details are sensitive**: Treat birth information (date, time, location) as PII
|
|
269
|
+
- **No data retention**: Vedika API does not store queries unless explicitly enabled
|
|
270
|
+
- **GDPR compliant**: The API is GDPR compliant for EU users
|
|
271
|
+
|
|
272
|
+
### API Key Scopes
|
|
273
|
+
|
|
274
|
+
- **Test keys** (`vk_test_`): Limited functionality, safe for development
|
|
275
|
+
- **Live keys** (`vk_live_`): Full access, use only in production
|
|
276
|
+
- **Never commit keys**: Use environment variables or secret managers
|
|
277
|
+
|
|
278
|
+
### Network Security
|
|
279
|
+
|
|
280
|
+
- **TLS 1.2+**: All API requests use TLS 1.2 or higher
|
|
281
|
+
- **Certificate validation**: The SDK validates SSL certificates
|
|
282
|
+
- **No proxy support**: Direct connections only for security
|
|
283
|
+
|
|
284
|
+
## Security Audit History
|
|
285
|
+
|
|
286
|
+
| Date | Type | Findings | Status |
|
|
287
|
+
|------------|---------------|----------|----------|
|
|
288
|
+
| 2025-10-15 | Code Review | None | Passed |
|
|
289
|
+
| 2025-10-01 | Dependency | None | Passed |
|
|
290
|
+
|
|
291
|
+
## Contact
|
|
292
|
+
|
|
293
|
+
For security concerns or questions:
|
|
294
|
+
|
|
295
|
+
- **Email**: security@vedika.io
|
|
296
|
+
- **Response time**: Within 48 hours
|
|
297
|
+
- **PGP Key**: Available on request
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
**Last updated**: November 2025
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vedika API Client
|
|
3
|
+
* Main client class for interacting with the Vedika Astrology API.
|
|
4
|
+
*/
|
|
5
|
+
import { VedikaClientOptions, QuestionQuery, QuestionResponse, BirthChartQuery, BirthChart, BirthDetails, DashaResponse, CompatibilityQuery, CompatibilityResponse, YogaResponse, DoshaResponse, MuhurthaQuery, MuhurthaResponse, NumerologyQuery, NumerologyResponse, BatchQueryItem } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Main client for the Vedika Astrology API
|
|
8
|
+
*
|
|
9
|
+
* The ONLY B2B astrology API with AI-powered chatbot queries.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { VedikaClient } from '@vedika-io/sdk';
|
|
14
|
+
*
|
|
15
|
+
* const client = new VedikaClient({ apiKey: 'vk_live_...' });
|
|
16
|
+
*
|
|
17
|
+
* const response = await client.askQuestion({
|
|
18
|
+
* question: 'What are my career prospects?',
|
|
19
|
+
* birthDetails: {
|
|
20
|
+
* datetime: '1990-06-15T14:30:00+05:30',
|
|
21
|
+
* latitude: 28.6139,
|
|
22
|
+
* longitude: 77.2090,
|
|
23
|
+
* timezone: 'Asia/Kolkata'
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class VedikaClient {
|
|
29
|
+
private client;
|
|
30
|
+
private apiKey;
|
|
31
|
+
private defaultLanguage;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new Vedika API client
|
|
34
|
+
*
|
|
35
|
+
* @param options - Client configuration options
|
|
36
|
+
* @throws {AuthenticationError} If API key is not provided
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: VedikaClientOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Handle API errors and convert to appropriate exception types
|
|
41
|
+
*/
|
|
42
|
+
private handleError;
|
|
43
|
+
/**
|
|
44
|
+
* Ask a conversational astrology question (UNIQUE to Vedika!)
|
|
45
|
+
*
|
|
46
|
+
* This is the only B2B astrology API that supports natural language queries.
|
|
47
|
+
*
|
|
48
|
+
* @param query - Question query parameters
|
|
49
|
+
* @returns Promise resolving to the answer
|
|
50
|
+
*/
|
|
51
|
+
askQuestion(query: QuestionQuery): Promise<QuestionResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Stream conversational astrology question response in real-time
|
|
54
|
+
*/
|
|
55
|
+
askQuestionStream(query: QuestionQuery): AsyncGenerator<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Generate a complete birth chart
|
|
58
|
+
*/
|
|
59
|
+
getBirthChart(query: BirthChartQuery): Promise<BirthChart>;
|
|
60
|
+
/**
|
|
61
|
+
* Get Vimshottari Dasha periods
|
|
62
|
+
*/
|
|
63
|
+
getDashas(birthDetails: BirthDetails): Promise<DashaResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Check marriage compatibility using Ashtakoota matching
|
|
66
|
+
*/
|
|
67
|
+
checkCompatibility(query: CompatibilityQuery): Promise<CompatibilityResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Detect 300+ astrological yogas
|
|
70
|
+
*/
|
|
71
|
+
detectYogas(birthDetails: BirthDetails): Promise<YogaResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Analyze doshas (Kaal Sarp, Mangal, Sade Sati, etc.)
|
|
74
|
+
*/
|
|
75
|
+
analyzeDoshas(birthDetails: BirthDetails): Promise<DoshaResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Find auspicious times (Muhurtha) for important events
|
|
78
|
+
*/
|
|
79
|
+
getMuhurtha(query: MuhurthaQuery): Promise<MuhurthaResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Get numerology analysis (37 calculations)
|
|
82
|
+
*/
|
|
83
|
+
getNumerology(query: NumerologyQuery): Promise<NumerologyResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Process multiple queries in batch for efficiency
|
|
86
|
+
*/
|
|
87
|
+
batchProcess(queries: BatchQueryItem[]): Promise<QuestionResponse[]>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACf,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,eAAe,CAAS;IAEhC;;;;;OAKG;gBACS,OAAO,EAAE,mBAAmB;IA+BxC;;OAEG;IACH,OAAO,CAAC,WAAW;IAkCnB;;;;;;;OAOG;IACG,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUlE;;OAEG;IACI,iBAAiB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC;IAyBtE;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAchE;;OAEG;IACG,SAAS,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAQnE;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IASnF;;OAEG;IACG,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAQpE;;OAEG;IACG,aAAa,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAQvE;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUlE;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IASxE;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAW3E"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vedika API Client
|
|
4
|
+
* Main client class for interacting with the Vedika Astrology API.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.VedikaClient = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
10
|
+
const exceptions_1 = require("./exceptions");
|
|
11
|
+
/**
|
|
12
|
+
* Main client for the Vedika Astrology API
|
|
13
|
+
*
|
|
14
|
+
* The ONLY B2B astrology API with AI-powered chatbot queries.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { VedikaClient } from '@vedika-io/sdk';
|
|
19
|
+
*
|
|
20
|
+
* const client = new VedikaClient({ apiKey: 'vk_live_...' });
|
|
21
|
+
*
|
|
22
|
+
* const response = await client.askQuestion({
|
|
23
|
+
* question: 'What are my career prospects?',
|
|
24
|
+
* birthDetails: {
|
|
25
|
+
* datetime: '1990-06-15T14:30:00+05:30',
|
|
26
|
+
* latitude: 28.6139,
|
|
27
|
+
* longitude: 77.2090,
|
|
28
|
+
* timezone: 'Asia/Kolkata'
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class VedikaClient {
|
|
34
|
+
/**
|
|
35
|
+
* Create a new Vedika API client
|
|
36
|
+
*
|
|
37
|
+
* @param options - Client configuration options
|
|
38
|
+
* @throws {AuthenticationError} If API key is not provided
|
|
39
|
+
*/
|
|
40
|
+
constructor(options) {
|
|
41
|
+
if (!options.apiKey) {
|
|
42
|
+
throw new exceptions_1.AuthenticationError('API key is required. Get one at https://vedika.io/dashboard.html');
|
|
43
|
+
}
|
|
44
|
+
this.apiKey = options.apiKey;
|
|
45
|
+
this.defaultLanguage = options.language || 'en';
|
|
46
|
+
const baseURL = options.baseUrl || 'https://api.vedika.io';
|
|
47
|
+
const timeout = options.timeout || 60000;
|
|
48
|
+
this.client = axios_1.default.create({
|
|
49
|
+
baseURL,
|
|
50
|
+
timeout,
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
'X-API-Key': this.apiKey,
|
|
54
|
+
'User-Agent': '@vedika-io/sdk/1.0.0',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
this.client.interceptors.response.use((response) => response, async (error) => {
|
|
58
|
+
return this.handleError(error);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Handle API errors and convert to appropriate exception types
|
|
63
|
+
*/
|
|
64
|
+
handleError(error) {
|
|
65
|
+
if (error.response) {
|
|
66
|
+
const status = error.response.status;
|
|
67
|
+
const data = error.response.data;
|
|
68
|
+
const message = data?.message || error.message;
|
|
69
|
+
switch (status) {
|
|
70
|
+
case 401:
|
|
71
|
+
throw new exceptions_1.AuthenticationError(message);
|
|
72
|
+
case 402:
|
|
73
|
+
throw new exceptions_1.InsufficientCreditsError(message);
|
|
74
|
+
case 408:
|
|
75
|
+
throw new exceptions_1.TimeoutError(message);
|
|
76
|
+
case 422:
|
|
77
|
+
throw new exceptions_1.ValidationError(message);
|
|
78
|
+
case 429:
|
|
79
|
+
throw new exceptions_1.RateLimitError(message);
|
|
80
|
+
case 500:
|
|
81
|
+
case 502:
|
|
82
|
+
case 503:
|
|
83
|
+
case 504:
|
|
84
|
+
throw new exceptions_1.ServerError(message, status);
|
|
85
|
+
default:
|
|
86
|
+
throw new exceptions_1.VedikaAPIError(`HTTP ${status}: ${message}`, status);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (error.code === 'ECONNABORTED') {
|
|
90
|
+
throw new exceptions_1.TimeoutError('Request timed out. For complex queries, try increasing timeout.');
|
|
91
|
+
}
|
|
92
|
+
else if (error.request) {
|
|
93
|
+
throw new exceptions_1.NetworkError('Network error. Check your internet connection.');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
throw new exceptions_1.VedikaAPIError(error.message);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Ask a conversational astrology question (UNIQUE to Vedika!)
|
|
101
|
+
*
|
|
102
|
+
* This is the only B2B astrology API that supports natural language queries.
|
|
103
|
+
*
|
|
104
|
+
* @param query - Question query parameters
|
|
105
|
+
* @returns Promise resolving to the answer
|
|
106
|
+
*/
|
|
107
|
+
async askQuestion(query) {
|
|
108
|
+
const response = await this.client.post('/api/v1/astrology/query', {
|
|
109
|
+
question: query.question,
|
|
110
|
+
birthDetails: query.birthDetails,
|
|
111
|
+
language: query.language || this.defaultLanguage,
|
|
112
|
+
});
|
|
113
|
+
return response.data;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Stream conversational astrology question response in real-time
|
|
117
|
+
*/
|
|
118
|
+
async *askQuestionStream(query) {
|
|
119
|
+
const response = await this.client.post('/api/v1/astrology/query/stream', {
|
|
120
|
+
question: query.question,
|
|
121
|
+
birthDetails: query.birthDetails,
|
|
122
|
+
language: query.language || this.defaultLanguage,
|
|
123
|
+
}, {
|
|
124
|
+
responseType: 'stream',
|
|
125
|
+
});
|
|
126
|
+
const stream = response.data;
|
|
127
|
+
for await (const chunk of stream) {
|
|
128
|
+
const lines = chunk.toString().split('\n');
|
|
129
|
+
for (const line of lines) {
|
|
130
|
+
if (line.startsWith('data: ')) {
|
|
131
|
+
yield line.substring(6);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate a complete birth chart
|
|
138
|
+
*/
|
|
139
|
+
async getBirthChart(query) {
|
|
140
|
+
const response = await this.client.post('/api/v1/charts/birth', {
|
|
141
|
+
birthDetails: {
|
|
142
|
+
datetime: query.datetime,
|
|
143
|
+
latitude: query.latitude,
|
|
144
|
+
longitude: query.longitude,
|
|
145
|
+
timezone: query.timezone || 'UTC',
|
|
146
|
+
},
|
|
147
|
+
ayanamsa: query.ayanamsa || 'lahiri',
|
|
148
|
+
});
|
|
149
|
+
return response.data;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get Vimshottari Dasha periods
|
|
153
|
+
*/
|
|
154
|
+
async getDashas(birthDetails) {
|
|
155
|
+
const response = await this.client.post('/api/vedika/dasha-periods', {
|
|
156
|
+
birthDetails,
|
|
157
|
+
});
|
|
158
|
+
return response.data;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Check marriage compatibility using Ashtakoota matching
|
|
162
|
+
*/
|
|
163
|
+
async checkCompatibility(query) {
|
|
164
|
+
const response = await this.client.post('/api/v1/compatibility/match', {
|
|
165
|
+
person1: query.person1,
|
|
166
|
+
person2: query.person2,
|
|
167
|
+
});
|
|
168
|
+
return response.data;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Detect 300+ astrological yogas
|
|
172
|
+
*/
|
|
173
|
+
async detectYogas(birthDetails) {
|
|
174
|
+
const response = await this.client.post('/api/vedika/yoga-detection', {
|
|
175
|
+
birthDetails,
|
|
176
|
+
});
|
|
177
|
+
return response.data;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Analyze doshas (Kaal Sarp, Mangal, Sade Sati, etc.)
|
|
181
|
+
*/
|
|
182
|
+
async analyzeDoshas(birthDetails) {
|
|
183
|
+
const response = await this.client.post('/api/vedika/dosha-analysis', {
|
|
184
|
+
birthDetails,
|
|
185
|
+
});
|
|
186
|
+
return response.data;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Find auspicious times (Muhurtha) for important events
|
|
190
|
+
*/
|
|
191
|
+
async getMuhurtha(query) {
|
|
192
|
+
const response = await this.client.post('/api/vedika/muhurtha', {
|
|
193
|
+
date: query.date,
|
|
194
|
+
location: query.location,
|
|
195
|
+
eventType: query.eventType,
|
|
196
|
+
});
|
|
197
|
+
return response.data;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get numerology analysis (37 calculations)
|
|
201
|
+
*/
|
|
202
|
+
async getNumerology(query) {
|
|
203
|
+
const response = await this.client.post('/api/vedika/numerology', {
|
|
204
|
+
name: query.name,
|
|
205
|
+
birthDate: query.birthDate,
|
|
206
|
+
});
|
|
207
|
+
return response.data;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Process multiple queries in batch for efficiency
|
|
211
|
+
*/
|
|
212
|
+
async batchProcess(queries) {
|
|
213
|
+
const promises = queries.map((query) => this.askQuestion({
|
|
214
|
+
question: query.question,
|
|
215
|
+
birthDetails: query.birthDetails,
|
|
216
|
+
language: query.language,
|
|
217
|
+
}));
|
|
218
|
+
return Promise.all(promises);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.VedikaClient = VedikaClient;
|
|
222
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,0DAAyD;AAmBzD,6CASsB;AAEtB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IAKvB;;;;;OAKG;IACH,YAAY,OAA4B;Q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