tcgpriser 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/LICENSE +21 -0
- package/README.md +299 -0
- package/dist/index.cjs +476 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3376 -0
- package/dist/index.d.ts +3376 -0
- package/dist/index.js +472 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SebbeJohansson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# tcgpriser
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/tcgpriser"><img src="https://img.shields.io/npm/v/tcgpriser" alt="Version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/tcgpriser"><img src="https://img.shields.io/npm/dm/tcgpriser" alt="Downloads"></a>
|
|
6
|
+
<a href="https://github.com/SebbeJohansson/tcgpriser-js/blob/main/LICENSE"><img src="https://img.shields.io/github/license/sebbejohansson/tcgpriser-js" alt="License"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
A typed Node.js / browser client for the [tcgpriser.se](https://tcgpriser.se) API: PokΓ©mon TCG catalog data, price history, shop listings and bargains for shops tracked in Sweden.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- π― **Fully typed**, straight off the API's own OpenAPI spec
|
|
14
|
+
- β‘ **Async/await** on every method, no callbacks
|
|
15
|
+
- π οΈ **Full IntelliSense** for every method and response field
|
|
16
|
+
- π¦ **Zero runtime dependencies**, built on the standard `fetch` API, ships as ESM and CJS
|
|
17
|
+
- π **Types stay in sync with the API**: `yarn generate:types` regenerates them from a live instance
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install tcgpriser
|
|
23
|
+
```
|
|
24
|
+
or with yarn
|
|
25
|
+
```bash
|
|
26
|
+
yarn add tcgpriser
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Needs Node 18+ for global `fetch`, or pass your own `fetch` implementation (see [Options](#options)).
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { TcgPriser } from 'tcgpriser';
|
|
35
|
+
|
|
36
|
+
const tcgpriser = new TcgPriser();
|
|
37
|
+
|
|
38
|
+
const card = await tcgpriser.cards.get('mega-evolution-ascended-heroes-fezandipiti-ex');
|
|
39
|
+
console.log(card.retailPrice, card.lowestShopOffer?.shop.name);
|
|
40
|
+
|
|
41
|
+
const { data: bargains } = await tcgpriser.bargains.list({ type: 'card' });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Public methods need no token. A handful of premium methods do, see [Authentication](#authentication).
|
|
45
|
+
|
|
46
|
+
### Cards
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
await tcgpriser.cards.list({ search: 'pikachu', limit: 10 });
|
|
50
|
+
await tcgpriser.cards.get('mega-evolution-ascended-heroes-fezandipiti-ex'); // id or technicalName
|
|
51
|
+
await tcgpriser.cards.matches('fezandipiti-ex', { inStock: true });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Sealed products
|
|
55
|
+
|
|
56
|
+
Booster boxes, ETBs, tins and the like. Single cards live under `cards`, not here.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
await tcgpriser.products.list({ search: 'booster box' });
|
|
60
|
+
await tcgpriser.products.get('scarlet-violet-booster-pack');
|
|
61
|
+
await tcgpriser.products.matches('scarlet-violet-booster-pack');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Expansions
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
await tcgpriser.expansions.list();
|
|
68
|
+
await tcgpriser.expansions.products('eng-scarlet-violet-journey-together'); // { expansion, cards, sealed }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Shops
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
await tcgpriser.shops.list({ active: true });
|
|
75
|
+
await tcgpriser.shops.get('alphaspel');
|
|
76
|
+
await tcgpriser.shopMatches.forShop('alphaspel'); // everything currently listed there
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Price stats and bargains
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
await tcgpriser.priceStats.daily({ technicalName: 'scarlet-violet-booster-pack' });
|
|
83
|
+
await tcgpriser.priceStats.estimatedValues({ expansion: 'eng-scarlet-violet-journey-together' });
|
|
84
|
+
await tcgpriser.bargains.list({ type: 'sealed' }); // 'sealed' | 'card' | 'all'
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Pack rates
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
await tcgpriser.packRates.list();
|
|
91
|
+
await tcgpriser.packRates.get(expansionId);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Available Methods
|
|
95
|
+
|
|
96
|
+
### `cards`
|
|
97
|
+
|
|
98
|
+
| Method | Description |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `list(params)` | Search or list cards |
|
|
101
|
+
| `get(id)` | Fetch one card by id or technicalName |
|
|
102
|
+
| `matches(id, params)` | Current shop listings matched to this card |
|
|
103
|
+
| `prices(id, params)` π | Individual marketplace sale records |
|
|
104
|
+
| `referencePrices(id, params)` π | Cardmarket / TCGplayer / eBay / Tradera price history |
|
|
105
|
+
| `livePricing(id)` π | Pricing computed fresh for this request |
|
|
106
|
+
|
|
107
|
+
### `products`
|
|
108
|
+
|
|
109
|
+
| Method | Description |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `list(params)` | Search or list sealed products |
|
|
112
|
+
| `get(id)` | Fetch one product by id or technicalName |
|
|
113
|
+
| `matches(id, params)` | Current shop listings matched to this product |
|
|
114
|
+
| `prices(id, params)` π | Individual marketplace sale records |
|
|
115
|
+
| `referencePrices(id, params)` π | Cardmarket / TCGplayer / Tradera price history |
|
|
116
|
+
| `livePricing(id)` π | Pricing computed fresh for this request |
|
|
117
|
+
|
|
118
|
+
### `expansions`
|
|
119
|
+
|
|
120
|
+
| Method | Description |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `list()` | Every expansion |
|
|
123
|
+
| `products(technicalName)` | Every card and sealed product in one expansion |
|
|
124
|
+
| `livePricing(technicalName)` π | Fresh pricing for every item in one expansion |
|
|
125
|
+
|
|
126
|
+
### `shops`
|
|
127
|
+
|
|
128
|
+
| Method | Description |
|
|
129
|
+
|---|---|
|
|
130
|
+
| `list(params)` | Every tracked shop |
|
|
131
|
+
| `get(id)` | Fetch one shop by id or technicalName |
|
|
132
|
+
|
|
133
|
+
### `shopMatches`
|
|
134
|
+
|
|
135
|
+
| Method | Description |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `list(params)` | Every current match across every shop |
|
|
138
|
+
| `forShop(shop, params)` | Everything currently listed at one shop |
|
|
139
|
+
| `shopStats(params)` | Match counts per shop |
|
|
140
|
+
|
|
141
|
+
### `shopMatchStats` π
|
|
142
|
+
|
|
143
|
+
| Method | Description |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `forProduct(id, params)` | One product's price history, broken out per shop |
|
|
146
|
+
| `forShop(shop, params)` | One shop's price history, broken out per product |
|
|
147
|
+
| `compare(params)` | One product's price at every shop that carries it |
|
|
148
|
+
|
|
149
|
+
### `priceStats`
|
|
150
|
+
|
|
151
|
+
| Method | Description |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `daily(params)` | Daily average price history |
|
|
154
|
+
| `estimatedValues(params)` | Current estimated market value |
|
|
155
|
+
| `topProducts(params)` | Items ranked by shop availability |
|
|
156
|
+
| `product(id)` π | Daily history, estimate and variant summary for one product |
|
|
157
|
+
| `productFull(id)` π | `product()` plus the item's current shop matches |
|
|
158
|
+
| `productDaily(id, params)` π | Daily history for one product, custom window |
|
|
159
|
+
| `productDailyLast30(id)` π | Daily history, fixed to the last 30 days |
|
|
160
|
+
| `productEstimatedValue(id)` π | Current estimated value only |
|
|
161
|
+
| `productByVariant(id, params)` π | Price stats per card condition/grade |
|
|
162
|
+
| `productDailyByVariant(id, params)` π | Daily history for one condition/grade |
|
|
163
|
+
|
|
164
|
+
### `bargains`
|
|
165
|
+
|
|
166
|
+
| Method | Description |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `list(params)` | Current listings priced below their reference price |
|
|
169
|
+
| `search(params)` π | Same, with real pagination and filters |
|
|
170
|
+
|
|
171
|
+
### `packRates`
|
|
172
|
+
|
|
173
|
+
| Method | Description |
|
|
174
|
+
|---|---|
|
|
175
|
+
| `list()` | Pull-rate odds for every expansion that has them |
|
|
176
|
+
| `get(expansionId)` | Pull-rate odds for one expansion |
|
|
177
|
+
|
|
178
|
+
### `shopUrls` π
|
|
179
|
+
|
|
180
|
+
| Method | Description |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `submit(params)` | Submit a shop URL for scraping |
|
|
183
|
+
| `assignProduct(id, params)` | Manually assign (or clear) the product a URL resolves to |
|
|
184
|
+
|
|
185
|
+
### `stats`
|
|
186
|
+
|
|
187
|
+
| Method | Description |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `platform()` | Platform-wide overview counts |
|
|
190
|
+
|
|
191
|
+
π = premium, needs a subscriber's token. See below.
|
|
192
|
+
|
|
193
|
+
## Authentication
|
|
194
|
+
|
|
195
|
+
Public methods work with no setup. Premium methods (marked π above) need a signed-in subscriber's JWT from tcgpriser.se. This package doesn't handle login itself; the site's sign-in is OAuth-based, so a headless client can't drive it. Pass a token your own app already has:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
const tcgpriser = new TcgPriser(myJwt); // shorthand for { authToken: myJwt }
|
|
199
|
+
await tcgpriser.cards.livePricing('fezandipiti-ex');
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Or set no default and pass a token per call, which fits better when one client instance serves requests for many different signed-in users:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const tcgpriser = new TcgPriser();
|
|
206
|
+
await tcgpriser.cards.livePricing('fezandipiti-ex', { authToken: requestUserJwt });
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
A missing or invalid token gets `401 unauthorized`. A valid token without an active subscription gets `403 premiumRequired`. Both come back as `TcgPriserError`:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { TcgPriser, TcgPriserError } from 'tcgpriser';
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
await tcgpriser.cards.get('does-not-exist');
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof TcgPriserError) {
|
|
218
|
+
console.log(error.statusCode, error.code, error.message); // 404 'notFound' 'Card not found'
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Options
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
new TcgPriser(myJwt); // shorthand for { authToken: myJwt }
|
|
227
|
+
new TcgPriser(); // no token, public methods only
|
|
228
|
+
|
|
229
|
+
new TcgPriser({
|
|
230
|
+
authToken: myJwt,
|
|
231
|
+
|
|
232
|
+
// Local dev, self-hosting or tests only. Leave this out for normal use.
|
|
233
|
+
advanced: {
|
|
234
|
+
baseUrl: 'https://api.tcgpriser.se', // default; point at a local dev server instead
|
|
235
|
+
headers: { 'User-Agent': 'my-app/1.0' },
|
|
236
|
+
fetch: myCustomFetch, // defaults to global fetch (Node 18+)
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Types
|
|
242
|
+
|
|
243
|
+
Every response type is exported from the package root:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import type { Card, SealedProduct, Bargain, ItemStats } from 'tcgpriser';
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
If you need the raw generated schema instead, it's exported too:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import type { components } from 'tcgpriser';
|
|
253
|
+
|
|
254
|
+
type CardSchema = components['schemas']['CardWithPricing'];
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Most types in `tcgpriser` are direct aliases onto that generated schema, so a field in your code and a field in the API docs are the same field, always.
|
|
258
|
+
|
|
259
|
+
## Scripts
|
|
260
|
+
|
|
261
|
+
### Build
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
yarn build
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Bundles to `dist/` as ESM, CJS and `.d.ts` with `tsup`.
|
|
268
|
+
|
|
269
|
+
### Regenerate types
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
yarn generate:types
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Regenerates `src/generated/openapi.d.ts` from a live API instance (defaults to `http://localhost:5000`, the local dev server). Committed to the repo, not gitignored. Regenerate it, review the diff, commit it, same as `pris-tabell-ui` does for its own generated types.
|
|
276
|
+
|
|
277
|
+
### Test
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
yarn test
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`test/http.test.ts` runs against a mocked fetch. `test/live.test.ts` hits a real API instance and skips itself if nothing answers at `TCGPRISER_TEST_BASE_URL` (default `http://localhost:5000`), so the suite stays green with no server running.
|
|
284
|
+
|
|
285
|
+
### Example
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
yarn example
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Runs `examples/basic.ts` against a local dev API. Set `TCGPRISER_AUTH_TOKEN` to see the premium call succeed instead of the expected 401.
|
|
292
|
+
|
|
293
|
+
## Scope
|
|
294
|
+
|
|
295
|
+
Covers the API's full documented surface: public catalog, price and bargain reads, plus the premium endpoints above. Not covered: the admin/scraper/auth surface, which isn't part of any published contract.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT
|