@buun_group/gunspec-sdk 0.1.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/README.md +129 -0
- package/dist/index.cjs +2342 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4554 -0
- package/dist/index.d.ts +4554 -0
- package/dist/index.js +2307 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @gunspec/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the [GunSpec.io](https://gunspec.io) firearms specification database API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gunspec/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { GunSpec } from '@gunspec/sdk';
|
|
15
|
+
|
|
16
|
+
// Reads GUNSPEC_API_KEY from process.env automatically
|
|
17
|
+
const client = new GunSpec();
|
|
18
|
+
|
|
19
|
+
// List firearms
|
|
20
|
+
const { data, pagination } = await client.firearms.list({
|
|
21
|
+
category: 'pistol',
|
|
22
|
+
manufacturer: 'glock',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
for (const firearm of data) {
|
|
26
|
+
console.log(firearm.name, firearm.caliber);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Get a single firearm
|
|
30
|
+
const { data: glock } = await client.firearms.get('glock-g17');
|
|
31
|
+
console.log(glock.name);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { GunSpec } from '@gunspec/sdk';
|
|
38
|
+
|
|
39
|
+
const client = new GunSpec({
|
|
40
|
+
apiKey: process.env.GUNSPEC_API_KEY, // or set env var
|
|
41
|
+
baseURL: 'https://api.gunspec.io', // default
|
|
42
|
+
timeout: 30000, // 30s default
|
|
43
|
+
retry: {
|
|
44
|
+
maxRetries: 2, // default
|
|
45
|
+
initialDelayMs: 500, // default
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Resources
|
|
51
|
+
|
|
52
|
+
| Resource | Methods |
|
|
53
|
+
|----------|---------|
|
|
54
|
+
| `client.firearms` | `list`, `get`, `search`, `compare`, `gameMeta`, `actionTypes`, `filterOptions`, `random`, `top`, `headToHead`, `byFeature`, `byAction`, `byMaterial`, `byDesigner`, `powerRating`, `timeline`, `byConflict`, `getVariants`, `getImages`, `getGameStats`, `getDimensions`, `getUsers`, `getFamilyTree`, `getSimilar`, `getAdoptionMap`, `getGameProfile`, `getSilhouette`, `calculate`, `load`, `listAutoPaging` |
|
|
55
|
+
| `client.manufacturers` | `list`, `get`, `getFirearms`, `getTimeline`, `getStats`, `listAutoPaging` |
|
|
56
|
+
| `client.calibers` | `list`, `get`, `compare`, `ballistics`, `getFirearms`, `getParentChain`, `getFamily`, `getAmmunition`, `listAutoPaging` |
|
|
57
|
+
| `client.categories` | `list`, `getFirearms` |
|
|
58
|
+
| `client.stats` | `summary`, `productionStatus`, `fieldCoverage`, `popularCalibers`, `prolificManufacturers`, `byCategory`, `byEra`, `materials`, `adoptionByCountry`, `adoptionByType`, `actionTypes`, `featureFrequency`, `caliberPopularityByEra` |
|
|
59
|
+
| `client.game` | `balanceReport`, `tierList`, `matchups`, `roleRoster`, `statDistribution` |
|
|
60
|
+
| `client.gameStats` | `listVersions`, `listFirearms`, `getFirearm` |
|
|
61
|
+
| `client.ammunition` | `list`, `get`, `getBulletSvg`, `ballistics`, `listAutoPaging` |
|
|
62
|
+
| `client.countries` | `list`, `getArsenal` |
|
|
63
|
+
| `client.conflicts` | `list` |
|
|
64
|
+
| `client.dataQuality` | `coverage`, `confidence` |
|
|
65
|
+
| `client.favorites` | `list`, `add`, `remove` |
|
|
66
|
+
| `client.reports` | `create`, `list` |
|
|
67
|
+
| `client.support` | `create`, `list`, `get`, `reply` |
|
|
68
|
+
| `client.webhooks` | `list`, `create`, `get`, `update`, `delete`, `test` |
|
|
69
|
+
| `client.usage` | `get` |
|
|
70
|
+
|
|
71
|
+
## Auto-Pagination
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
for await (const firearm of client.firearms.listAutoPaging({
|
|
75
|
+
category: 'rifle',
|
|
76
|
+
})) {
|
|
77
|
+
console.log(firearm.name);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Error Handling
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import {
|
|
85
|
+
GunSpec,
|
|
86
|
+
NotFoundError,
|
|
87
|
+
RateLimitError,
|
|
88
|
+
AuthenticationError,
|
|
89
|
+
} from '@gunspec/sdk';
|
|
90
|
+
|
|
91
|
+
const client = new GunSpec();
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const { data } = await client.firearms.get('nonexistent');
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof NotFoundError) {
|
|
97
|
+
console.log('Not found:', error.message);
|
|
98
|
+
console.log('Request ID:', error.requestId);
|
|
99
|
+
} else if (error instanceof RateLimitError) {
|
|
100
|
+
console.log('Retry after:', error.retryAfter, 'ms');
|
|
101
|
+
} else if (error instanceof AuthenticationError) {
|
|
102
|
+
console.log('Invalid API key');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
- Node.js >= 18
|
|
110
|
+
- TypeScript >= 5.0 (for type-checking; not required at runtime)
|
|
111
|
+
|
|
112
|
+
## Publishing
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cd packages/sdk
|
|
116
|
+
|
|
117
|
+
# Build
|
|
118
|
+
npm run build
|
|
119
|
+
|
|
120
|
+
# Verify package contents
|
|
121
|
+
npm pack --dry-run
|
|
122
|
+
|
|
123
|
+
# Publish to npm (public scoped package)
|
|
124
|
+
npm publish --access public
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|