apogeoapi 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 +52 -0
- package/EXAMPLES.md +666 -0
- package/README.md +532 -0
- package/dist/clients/account.client.d.ts +76 -0
- package/dist/clients/account.client.d.ts.map +1 -0
- package/dist/clients/account.client.js +85 -0
- package/dist/clients/account.client.js.map +1 -0
- package/dist/clients/api-keys.client.d.ts +90 -0
- package/dist/clients/api-keys.client.d.ts.map +1 -0
- package/dist/clients/api-keys.client.js +105 -0
- package/dist/clients/api-keys.client.js.map +1 -0
- package/dist/clients/auth.client.d.ts +63 -0
- package/dist/clients/auth.client.d.ts.map +1 -0
- package/dist/clients/auth.client.js +86 -0
- package/dist/clients/auth.client.js.map +1 -0
- package/dist/clients/billing.client.d.ts +79 -0
- package/dist/clients/billing.client.d.ts.map +1 -0
- package/dist/clients/billing.client.js +101 -0
- package/dist/clients/billing.client.js.map +1 -0
- package/dist/clients/geo.client.d.ts +105 -0
- package/dist/clients/geo.client.d.ts.map +1 -0
- package/dist/clients/geo.client.js +149 -0
- package/dist/clients/geo.client.js.map +1 -0
- package/dist/clients/webhooks.client.d.ts +110 -0
- package/dist/clients/webhooks.client.d.ts.map +1 -0
- package/dist/clients/webhooks.client.js +129 -0
- package/dist/clients/webhooks.client.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +157 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +243 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/http-client.d.ts +43 -0
- package/dist/utils/http-client.d.ts.map +1 -0
- package/dist/utils/http-client.js +140 -0
- package/dist/utils/http-client.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
# @geo-api/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for Geo API - Professional geographic data API with comprehensive country, state, and city information.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@geo-api/sdk)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
|
|
10
|
+
- ✅ **Full TypeScript Support** - Complete type definitions with autocomplete
|
|
11
|
+
- ✅ **Auto-Retry Logic** - Automatic retry with exponential backoff
|
|
12
|
+
- ✅ **Error Handling** - Typed error responses
|
|
13
|
+
- ✅ **Rate Limit Handling** - Respects retry-after headers
|
|
14
|
+
- ✅ **Multiple Auth Methods** - API Key or JWT token
|
|
15
|
+
- ✅ **Comprehensive Coverage** - All API endpoints covered
|
|
16
|
+
- ✅ **Zero Config** - Works out of the box with sensible defaults
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @geo-api/sdk
|
|
22
|
+
|
|
23
|
+
# or with yarn
|
|
24
|
+
yarn add @geo-api/sdk
|
|
25
|
+
|
|
26
|
+
# or with pnpm
|
|
27
|
+
pnpm add @geo-api/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🏃 Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { GeoAPI } from '@geo-api/sdk';
|
|
34
|
+
|
|
35
|
+
// Initialize with API key (recommended)
|
|
36
|
+
const client = new GeoAPI({
|
|
37
|
+
apiKey: 'geoapi_live_xxxxx',
|
|
38
|
+
baseURL: 'https://api.yourcompany.com/v1' // optional
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Get all countries
|
|
42
|
+
const countries = await client.geo.getCountries();
|
|
43
|
+
console.log(`Total countries: ${countries.length}`);
|
|
44
|
+
|
|
45
|
+
// Search for cities
|
|
46
|
+
const cities = await client.geo.searchCities('New York', 10);
|
|
47
|
+
console.log(cities);
|
|
48
|
+
|
|
49
|
+
// Get usage statistics
|
|
50
|
+
const dashboard = await client.account.getDashboard();
|
|
51
|
+
console.log(`API calls this month: ${dashboard.usage.requestsThisMonth}`);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 📚 Table of Contents
|
|
55
|
+
|
|
56
|
+
- [Authentication](#authentication)
|
|
57
|
+
- [Geography API](#geography-api)
|
|
58
|
+
- [Account Management](#account-management)
|
|
59
|
+
- [API Keys Management](#api-keys-management)
|
|
60
|
+
- [Billing & Subscriptions](#billing--subscriptions)
|
|
61
|
+
- [Webhooks](#webhooks)
|
|
62
|
+
- [Error Handling](#error-handling)
|
|
63
|
+
- [Advanced Configuration](#advanced-configuration)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🔐 Authentication
|
|
68
|
+
|
|
69
|
+
### API Key (Recommended for Client-Side)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const client = new GeoAPI({
|
|
73
|
+
apiKey: 'geoapi_live_xxxxx'
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### JWT Token (After Login)
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const client = new GeoAPI({
|
|
81
|
+
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Or set token after initialization
|
|
85
|
+
client.setToken('new_token_here');
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Register & Login
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Register new user
|
|
92
|
+
const { user, access_token, refresh_token } = await client.auth.register({
|
|
93
|
+
email: 'user@example.com',
|
|
94
|
+
password: 'securePassword123',
|
|
95
|
+
username: 'johndoe'
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Login
|
|
99
|
+
const tokens = await client.auth.login({
|
|
100
|
+
email: 'user@example.com',
|
|
101
|
+
password: 'securePassword123'
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Token is automatically set after login
|
|
105
|
+
console.log('Logged in as:', tokens.user.username);
|
|
106
|
+
|
|
107
|
+
// Refresh token
|
|
108
|
+
const newTokens = await client.auth.refreshToken({
|
|
109
|
+
refresh_token: tokens.refresh_token
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 🌍 Geography API
|
|
116
|
+
|
|
117
|
+
### Countries
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// Get all countries
|
|
121
|
+
const countries = await client.geo.getCountries();
|
|
122
|
+
|
|
123
|
+
// Get country by ISO code
|
|
124
|
+
const usa = await client.geo.getCountryByIso('US');
|
|
125
|
+
console.log(usa.name); // "United States"
|
|
126
|
+
console.log(usa.capital); // "Washington"
|
|
127
|
+
console.log(usa.currency); // "USD"
|
|
128
|
+
|
|
129
|
+
// Search countries
|
|
130
|
+
const matching = await client.geo.searchCountries('united', 5);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### States/Provinces
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Get all states of a country
|
|
137
|
+
const usStates = await client.geo.getStates('US');
|
|
138
|
+
console.log(`US has ${usStates.length} states`);
|
|
139
|
+
|
|
140
|
+
// Get specific state
|
|
141
|
+
const california = await client.geo.getStateById(1234);
|
|
142
|
+
console.log(california.name); // "California"
|
|
143
|
+
|
|
144
|
+
// Search states
|
|
145
|
+
const texasMatch = await client.geo.searchStates('texas', 1);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Cities
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Get cities of a state
|
|
152
|
+
const californiaCities = await client.geo.getCities(1234, 100, 0);
|
|
153
|
+
|
|
154
|
+
// Get specific city
|
|
155
|
+
const city = await client.geo.getCityById(5678);
|
|
156
|
+
console.log(`${city.name}, ${city.state.name}`);
|
|
157
|
+
|
|
158
|
+
// Search cities
|
|
159
|
+
const newYorkCities = await client.geo.searchCities('New York', 10);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Universal Search
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// Search across all types
|
|
166
|
+
const results = await client.geo.search({
|
|
167
|
+
query: 'san',
|
|
168
|
+
limit: 20,
|
|
169
|
+
offset: 0,
|
|
170
|
+
type: 'city' // optional: 'country' | 'state' | 'city'
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
console.log(`Found ${results.total} results`);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 👤 Account Management
|
|
179
|
+
|
|
180
|
+
### Dashboard
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// Get complete dashboard
|
|
184
|
+
const dashboard = await client.account.getDashboard();
|
|
185
|
+
|
|
186
|
+
console.log('User:', dashboard.user.username);
|
|
187
|
+
console.log('Tier:', dashboard.subscription.tier);
|
|
188
|
+
console.log('Usage:', dashboard.usage.requestsThisMonth, '/', dashboard.usage.monthlyQuota);
|
|
189
|
+
console.log('API Keys:', dashboard.apiKeys.active, '/', dashboard.apiKeys.max);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Profile
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Update profile
|
|
196
|
+
await client.account.updateProfile({
|
|
197
|
+
username: 'new_username',
|
|
198
|
+
email: 'newemail@example.com'
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Change password
|
|
202
|
+
await client.account.changePassword({
|
|
203
|
+
currentPassword: 'oldpass123',
|
|
204
|
+
newPassword: 'newpass456'
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Usage Statistics
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// Get usage for date range
|
|
212
|
+
const stats = await client.account.getUsage({
|
|
213
|
+
startDate: new Date('2024-01-01'),
|
|
214
|
+
endDate: new Date('2024-01-31'),
|
|
215
|
+
groupBy: 'day' // or 'month'
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
stats.forEach(stat => {
|
|
219
|
+
console.log(`${stat.date}: ${stat.requests} requests`);
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 🔑 API Keys Management
|
|
226
|
+
|
|
227
|
+
### List & Create
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// List all API keys
|
|
231
|
+
const keys = await client.apiKeys.list();
|
|
232
|
+
|
|
233
|
+
// Create new API key
|
|
234
|
+
const newKey = await client.apiKeys.create({
|
|
235
|
+
name: 'Production Server',
|
|
236
|
+
expiresAt: new Date('2025-12-31')
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
console.log('🔑 Save this key:', newKey.key);
|
|
240
|
+
// ⚠️ Key is only shown once!
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Update & Delete
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
// Rename key
|
|
247
|
+
await client.apiKeys.update(keyId, {
|
|
248
|
+
name: 'Production Server v2'
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// Revoke key (deactivate)
|
|
252
|
+
await client.apiKeys.revoke(keyId);
|
|
253
|
+
|
|
254
|
+
// Reactivate key
|
|
255
|
+
await client.apiKeys.activate(keyId);
|
|
256
|
+
|
|
257
|
+
// Delete permanently
|
|
258
|
+
await client.apiKeys.delete(keyId);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## 💳 Billing & Subscriptions
|
|
264
|
+
|
|
265
|
+
### Upgrade Plan
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Create checkout session
|
|
269
|
+
const checkout = await client.billing.createCheckoutSession(
|
|
270
|
+
'professional', // tier
|
|
271
|
+
'https://myapp.com/success', // success URL
|
|
272
|
+
'https://myapp.com/cancel' // cancel URL
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
// Redirect user to Stripe
|
|
276
|
+
window.location.href = checkout.url;
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Manage Subscription
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// Access billing portal
|
|
283
|
+
const portal = await client.billing.createPortalSession(
|
|
284
|
+
'https://myapp.com/account' // return URL
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
// Redirect user to Stripe portal
|
|
288
|
+
window.location.href = portal.url;
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Invoices
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// Get all invoices
|
|
295
|
+
const invoices = await client.billing.getInvoices(10);
|
|
296
|
+
|
|
297
|
+
invoices.forEach(invoice => {
|
|
298
|
+
console.log(`${invoice.created}: $${invoice.amount/100} - ${invoice.status}`);
|
|
299
|
+
console.log(`PDF: ${invoice.invoice_pdf}`);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Get specific invoice
|
|
303
|
+
const invoice = await client.billing.getInvoice('in_xxxxx');
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Cancel Subscription
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
// Cancel at period end
|
|
310
|
+
await client.billing.cancelSubscription();
|
|
311
|
+
// User keeps access until period ends
|
|
312
|
+
|
|
313
|
+
// Reactivate before period ends
|
|
314
|
+
await client.billing.reactivateSubscription();
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## 🪝 Webhooks
|
|
320
|
+
|
|
321
|
+
### Create Webhook
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
// Create webhook
|
|
325
|
+
const webhook = await client.webhooks.create({
|
|
326
|
+
url: 'https://myapp.com/webhooks/geo-api',
|
|
327
|
+
events: [
|
|
328
|
+
'usage.quota_warning',
|
|
329
|
+
'usage.quota_exceeded',
|
|
330
|
+
'subscription.updated'
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
console.log('Webhook ID:', webhook.id);
|
|
335
|
+
console.log('Secret:', webhook.secret); // Use to validate payloads
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Manage Webhooks
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// List all webhooks
|
|
342
|
+
const webhooks = await client.webhooks.list();
|
|
343
|
+
|
|
344
|
+
// Update webhook
|
|
345
|
+
await client.webhooks.update(webhookId, {
|
|
346
|
+
url: 'https://myapp.com/new-webhook-url',
|
|
347
|
+
events: ['subscription.created', 'subscription.canceled']
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Test webhook
|
|
351
|
+
const result = await client.webhooks.test(webhookId);
|
|
352
|
+
console.log('Test success:', result.success);
|
|
353
|
+
|
|
354
|
+
// Deactivate
|
|
355
|
+
await client.webhooks.deactivate(webhookId);
|
|
356
|
+
|
|
357
|
+
// Delete
|
|
358
|
+
await client.webhooks.delete(webhookId);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Delivery Logs
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// Get webhook delivery logs
|
|
365
|
+
const logs = await client.webhooks.getLogs(webhookId, 50);
|
|
366
|
+
|
|
367
|
+
logs.forEach(log => {
|
|
368
|
+
console.log(`${log.createdAt}: ${log.event} - ${log.success ? '✅' : '❌'}`);
|
|
369
|
+
if (!log.success) {
|
|
370
|
+
console.log(` Status: ${log.statusCode}`);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## ⚠️ Error Handling
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import { GeoAPI, GeoAPIError } from '@geo-api/sdk';
|
|
381
|
+
|
|
382
|
+
const client = new GeoAPI({ apiKey: 'xxx' });
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const country = await client.geo.getCountryByIso('INVALID');
|
|
386
|
+
} catch (error) {
|
|
387
|
+
if (error instanceof GeoAPIError) {
|
|
388
|
+
console.error('Status:', error.statusCode);
|
|
389
|
+
console.error('Message:', error.message);
|
|
390
|
+
console.error('Response:', error.response);
|
|
391
|
+
|
|
392
|
+
// Handle specific errors
|
|
393
|
+
if (error.statusCode === 404) {
|
|
394
|
+
console.log('Country not found');
|
|
395
|
+
} else if (error.statusCode === 429) {
|
|
396
|
+
console.log('Rate limit exceeded, retry after:', error.response?.retryAfter);
|
|
397
|
+
} else if (error.statusCode === 403) {
|
|
398
|
+
console.log('Quota exceeded or invalid API key');
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
console.error('Unexpected error:', error);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
## ⚙️ Advanced Configuration
|
|
409
|
+
|
|
410
|
+
### Custom Configuration
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
const client = new GeoAPI({
|
|
414
|
+
apiKey: 'geoapi_live_xxxxx',
|
|
415
|
+
baseURL: 'https://api.yourcompany.com/v1',
|
|
416
|
+
timeout: 30000, // 30 seconds
|
|
417
|
+
retries: 3, // retry failed requests 3 times
|
|
418
|
+
debug: true // enable debug logging
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Debug Mode
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
const client = new GeoAPI({
|
|
426
|
+
apiKey: 'xxx',
|
|
427
|
+
debug: true
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Logs all requests and retries
|
|
431
|
+
// [SDK] GET /geo/countries
|
|
432
|
+
// [SDK] Response 200 from /geo/countries
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Using Different Environments
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
// Development
|
|
439
|
+
const devClient = new GeoAPI({
|
|
440
|
+
apiKey: process.env.DEV_API_KEY,
|
|
441
|
+
baseURL: 'http://localhost:3000/v1'
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// Production
|
|
445
|
+
const prodClient = new GeoAPI({
|
|
446
|
+
apiKey: process.env.PROD_API_KEY,
|
|
447
|
+
baseURL: 'https://api.yourcompany.com/v1'
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## 🧪 Examples
|
|
454
|
+
|
|
455
|
+
### Complete Application Example
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { GeoAPI } from '@geo-api/sdk';
|
|
459
|
+
|
|
460
|
+
const client = new GeoAPI({
|
|
461
|
+
apiKey: process.env.GEO_API_KEY!
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
async function main() {
|
|
465
|
+
// 1. Get dashboard
|
|
466
|
+
const dashboard = await client.account.getDashboard();
|
|
467
|
+
console.log(`Welcome ${dashboard.user.username}!`);
|
|
468
|
+
console.log(`You're on the ${dashboard.subscription.tier} plan`);
|
|
469
|
+
console.log(`Usage: ${dashboard.usage.usagePercentage}%`);
|
|
470
|
+
|
|
471
|
+
// 2. Query geography data
|
|
472
|
+
const countries = await client.geo.getCountries();
|
|
473
|
+
console.log(`\nTotal countries: ${countries.length}`);
|
|
474
|
+
|
|
475
|
+
// 3. Search for specific location
|
|
476
|
+
const cities = await client.geo.searchCities('Paris', 5);
|
|
477
|
+
console.log(`\nCities named Paris:`);
|
|
478
|
+
cities.forEach(city => {
|
|
479
|
+
console.log(`- ${city.name}, ${city.state?.name}, ${city.country?.name}`);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// 4. Check usage
|
|
483
|
+
const usage = await client.account.getUsage({
|
|
484
|
+
startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
|
|
485
|
+
endDate: new Date(),
|
|
486
|
+
groupBy: 'day'
|
|
487
|
+
});
|
|
488
|
+
console.log(`\nLast 30 days usage:`, usage.length, 'days');
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
main().catch(console.error);
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## 📝 TypeScript Support
|
|
497
|
+
|
|
498
|
+
Full TypeScript support with complete type definitions:
|
|
499
|
+
|
|
500
|
+
```typescript
|
|
501
|
+
import { GeoAPI, Country, City, Tier, WebhookEvent } from '@geo-api/sdk';
|
|
502
|
+
|
|
503
|
+
const client = new GeoAPI({ apiKey: 'xxx' });
|
|
504
|
+
|
|
505
|
+
// All responses are fully typed
|
|
506
|
+
const country: Country = await client.geo.getCountryByIso('US');
|
|
507
|
+
const cities: City[] = await client.geo.searchCities('London', 10);
|
|
508
|
+
|
|
509
|
+
// Enums are typed
|
|
510
|
+
const tier: Tier = 'professional';
|
|
511
|
+
const events: WebhookEvent[] = ['usage.quota_warning', 'subscription.updated'];
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
---
|
|
515
|
+
|
|
516
|
+
## 🤝 Contributing
|
|
517
|
+
|
|
518
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
519
|
+
|
|
520
|
+
## 📄 License
|
|
521
|
+
|
|
522
|
+
MIT © Geo API Team
|
|
523
|
+
|
|
524
|
+
## 🔗 Links
|
|
525
|
+
|
|
526
|
+
- [API Documentation](https://api.yourcompany.com/docs)
|
|
527
|
+
- [GitHub Repository](https://github.com/your-org/geo-api-sdk)
|
|
528
|
+
- [Support](mailto:support@yourcompany.com)
|
|
529
|
+
|
|
530
|
+
---
|
|
531
|
+
|
|
532
|
+
**Made with ❤️ by the Geo API Team**
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { HttpClient } from '../utils/http-client';
|
|
2
|
+
import { AccountDashboard, UpdateProfileDto, ChangePasswordDto, UsageStats, UsageQuery } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* AccountClient - Handles user account operations
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const account = new AccountClient(httpClient);
|
|
9
|
+
*
|
|
10
|
+
* // Get dashboard data
|
|
11
|
+
* const dashboard = await account.getDashboard();
|
|
12
|
+
*
|
|
13
|
+
* // Update profile
|
|
14
|
+
* await account.updateProfile({ username: 'new_username' });
|
|
15
|
+
*
|
|
16
|
+
* // Get usage statistics
|
|
17
|
+
* const usage = await account.getUsage({
|
|
18
|
+
* startDate: new Date('2024-01-01'),
|
|
19
|
+
* endDate: new Date('2024-01-31'),
|
|
20
|
+
* groupBy: 'day'
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class AccountClient {
|
|
25
|
+
private http;
|
|
26
|
+
constructor(http: HttpClient);
|
|
27
|
+
/**
|
|
28
|
+
* Get account dashboard with all information
|
|
29
|
+
*
|
|
30
|
+
* Includes:
|
|
31
|
+
* - User profile
|
|
32
|
+
* - Subscription details
|
|
33
|
+
* - Usage statistics
|
|
34
|
+
* - Tier limits
|
|
35
|
+
* - API keys count
|
|
36
|
+
*
|
|
37
|
+
* @returns Complete dashboard data
|
|
38
|
+
*/
|
|
39
|
+
getDashboard(): Promise<AccountDashboard>;
|
|
40
|
+
/**
|
|
41
|
+
* Update user profile
|
|
42
|
+
*
|
|
43
|
+
* @param data - Profile update data (username, email)
|
|
44
|
+
* @returns Success response
|
|
45
|
+
*/
|
|
46
|
+
updateProfile(data: UpdateProfileDto): Promise<{
|
|
47
|
+
message: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Change password
|
|
51
|
+
*
|
|
52
|
+
* @param data - Password change data (currentPassword, newPassword)
|
|
53
|
+
* @returns Success response
|
|
54
|
+
*/
|
|
55
|
+
changePassword(data: ChangePasswordDto): Promise<{
|
|
56
|
+
message: string;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Get usage statistics
|
|
60
|
+
*
|
|
61
|
+
* @param query - Query parameters (startDate, endDate, groupBy)
|
|
62
|
+
* @returns Array of usage statistics
|
|
63
|
+
*/
|
|
64
|
+
getUsage(query?: UsageQuery): Promise<UsageStats[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete account permanently
|
|
67
|
+
*
|
|
68
|
+
* **Warning:** This action is irreversible
|
|
69
|
+
*
|
|
70
|
+
* @returns Success response
|
|
71
|
+
*/
|
|
72
|
+
deleteAccount(): Promise<{
|
|
73
|
+
message: string;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=account.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.client.d.ts","sourceRoot":"","sources":["../../src/clients/account.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACX,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEpC;;;;;;;;;;;OAWG;IACG,YAAY,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAI/C;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAIzE;;;;;OAKG;IACG,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAI3E;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAMzD;;;;;;OAMG;IACG,aAAa,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAGpD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* AccountClient - Handles user account operations
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const account = new AccountClient(httpClient);
|
|
10
|
+
*
|
|
11
|
+
* // Get dashboard data
|
|
12
|
+
* const dashboard = await account.getDashboard();
|
|
13
|
+
*
|
|
14
|
+
* // Update profile
|
|
15
|
+
* await account.updateProfile({ username: 'new_username' });
|
|
16
|
+
*
|
|
17
|
+
* // Get usage statistics
|
|
18
|
+
* const usage = await account.getUsage({
|
|
19
|
+
* startDate: new Date('2024-01-01'),
|
|
20
|
+
* endDate: new Date('2024-01-31'),
|
|
21
|
+
* groupBy: 'day'
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class AccountClient {
|
|
26
|
+
constructor(http) {
|
|
27
|
+
this.http = http;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get account dashboard with all information
|
|
31
|
+
*
|
|
32
|
+
* Includes:
|
|
33
|
+
* - User profile
|
|
34
|
+
* - Subscription details
|
|
35
|
+
* - Usage statistics
|
|
36
|
+
* - Tier limits
|
|
37
|
+
* - API keys count
|
|
38
|
+
*
|
|
39
|
+
* @returns Complete dashboard data
|
|
40
|
+
*/
|
|
41
|
+
async getDashboard() {
|
|
42
|
+
return this.http.get('/account/dashboard');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Update user profile
|
|
46
|
+
*
|
|
47
|
+
* @param data - Profile update data (username, email)
|
|
48
|
+
* @returns Success response
|
|
49
|
+
*/
|
|
50
|
+
async updateProfile(data) {
|
|
51
|
+
return this.http.put('/account/profile', data);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Change password
|
|
55
|
+
*
|
|
56
|
+
* @param data - Password change data (currentPassword, newPassword)
|
|
57
|
+
* @returns Success response
|
|
58
|
+
*/
|
|
59
|
+
async changePassword(data) {
|
|
60
|
+
return this.http.put('/account/password', data);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get usage statistics
|
|
64
|
+
*
|
|
65
|
+
* @param query - Query parameters (startDate, endDate, groupBy)
|
|
66
|
+
* @returns Array of usage statistics
|
|
67
|
+
*/
|
|
68
|
+
async getUsage(query) {
|
|
69
|
+
return this.http.get('/account/usage', {
|
|
70
|
+
params: query,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Delete account permanently
|
|
75
|
+
*
|
|
76
|
+
* **Warning:** This action is irreversible
|
|
77
|
+
*
|
|
78
|
+
* @returns Success response
|
|
79
|
+
*/
|
|
80
|
+
async deleteAccount() {
|
|
81
|
+
return this.http.delete('/account');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.AccountClient = AccountClient;
|
|
85
|
+
//# sourceMappingURL=account.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.client.js","sourceRoot":"","sources":["../../src/clients/account.client.ts"],"names":[],"mappings":";;;AASA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,aAAa;IACxB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAmB,oBAAoB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,IAAsB;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAsB,kBAAkB,EAAE,IAAI,CAAC,CAAC;IACtE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,IAAuB;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAsB,mBAAmB,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAkB;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAe,gBAAgB,EAAE;YACnD,MAAM,EAAE,KAAY;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAsB,UAAU,CAAC,CAAC;IAC3D,CAAC;CACF;AA7DD,sCA6DC"}
|