@pokemontcgapi/sdk 0.1.2 → 0.1.4
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 +139 -26
- package/dist/client.d.ts +28 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +31 -2
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +14 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +20 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +82 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109 -5
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +250 -29
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -7
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# @pokemontcgapi/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript client for the Pokémon TCG API at [pokemontcgapi.com](https://pokemontcgapi.com)
|
|
4
|
-
|
|
5
|
-
Simplified Chinese
|
|
6
|
-
their source, basis, grade and sample size.
|
|
3
|
+
TypeScript client for the Pokémon TCG API at [pokemontcgapi.com](https://pokemontcgapi.com): cards,
|
|
4
|
+
sets, illustrators, the reference vocabularies and photo recognition, across three print lines,
|
|
5
|
+
international, Japanese and Simplified Chinese, with card names in eight locales, images, and prices
|
|
6
|
+
that state their source, basis, grade and sample size. The current counts are live at
|
|
7
|
+
[/v1/status](https://api.pokemontcgapi.com/v1/status).
|
|
8
|
+
|
|
9
|
+
**Every data route has a method**: cards, sets, series, artists, sealed products, the dedicated
|
|
10
|
+
price routes (current, batch, history, stats, movers, sources), the `/v1/changes` feed, the reference
|
|
11
|
+
vocabularies and photo recognition. Account and billing routes (`/v1/me`, keys, checkout) are not
|
|
12
|
+
wrapped: they belong to the dashboard.
|
|
7
13
|
|
|
8
14
|
**Zero runtime dependencies.** Uses the global `fetch`, so it runs unchanged on Node ≥ 20, Bun, Deno,
|
|
9
15
|
Cloudflare Workers and in the browser.
|
|
@@ -12,6 +18,21 @@ Unofficial. Not produced, endorsed, supported by or affiliated with Nintendo, Cr
|
|
|
12
18
|
GAME FREAK inc. or The Pokémon Company International. Pokémon and all related marks are trademarks of
|
|
13
19
|
their respective owners.
|
|
14
20
|
|
|
21
|
+
## Get a key
|
|
22
|
+
|
|
23
|
+
One call, no dashboard and no card:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
curl -s -X POST "https://api.pokemontcgapi.com/v1/accounts/free" \
|
|
27
|
+
-H "Content-Type: application/json" \
|
|
28
|
+
-H "Idempotency-Key: $(uuidgen)" \
|
|
29
|
+
-d '{"email":"you@example.com"}'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The key comes back once, in `data.key.secret`. Confirming the address we email raises the trial from
|
|
33
|
+
80 to 800 credits, and the trial ends 30 days after signup. Paid plans start at 29 EUR a month:
|
|
34
|
+
[pricing](https://pokemontcgapi.com/pricing).
|
|
35
|
+
|
|
15
36
|
## Install
|
|
16
37
|
|
|
17
38
|
```bash
|
|
@@ -27,7 +48,7 @@ const client = new PokemonTcgApi({ apiKey: process.env.PTCG_API_KEY });
|
|
|
27
48
|
|
|
28
49
|
const card = await client.cards.get('base1-4', { include: ['prices'] });
|
|
29
50
|
console.log(card.id, card.name, card.index_eur);
|
|
30
|
-
// bs-4 Charizard
|
|
51
|
+
// bs-4 Charizard 523.76 ← the index on 16 September 2026; it moves, yours will differ
|
|
31
52
|
```
|
|
32
53
|
|
|
33
54
|
`base1-4` and `bs-4` both resolve: the id is the printed coordinate — set code, dash, collector
|
|
@@ -37,14 +58,27 @@ not start with a matching problem.
|
|
|
37
58
|
### Pagination that you never have to think about
|
|
38
59
|
|
|
39
60
|
Every list method returns a `Page`, which is also an `AsyncIterable`. Iterating it follows
|
|
40
|
-
`links.next` for you
|
|
61
|
+
`links.next` for you. For an initial import of all cards, use the flat card list so pages fill
|
|
62
|
+
across set boundaries:
|
|
41
63
|
|
|
42
64
|
```ts
|
|
43
|
-
for await (const
|
|
44
|
-
console.log(
|
|
65
|
+
for await (const card of await client.cards.search({ limit: 250, orderBy: 'id' })) {
|
|
66
|
+
console.log(card.id, card.name, card.set_code);
|
|
45
67
|
}
|
|
46
68
|
```
|
|
47
69
|
|
|
70
|
+
For Japanese cards, add `q: 'set.region:JP'`; for Simplified Chinese cards, use
|
|
71
|
+
`q: 'set.region:CN'`. Add `include: ['translations']` when you need localized names;
|
|
72
|
+
this keeps the plain catalogue cost. `include: ['index']` and `include: ['prices']`
|
|
73
|
+
have different credit costs. `lang` selects a name translation, not a print region.
|
|
74
|
+
|
|
75
|
+
Use `client.sets.list({ region: 'JP', limit: 250 })` to browse set metadata and
|
|
76
|
+
`client.sets.cards('obf', { limit: 250 })` when you need one particular set. For all cards,
|
|
77
|
+
the flat list uses fewer requests than a card loop for every set. The
|
|
78
|
+
[quickstart](https://pokemontcgapi.com/docs/quickstart#page-the-whole-catalogue) includes dated
|
|
79
|
+
measurements, and the [migration guide](https://pokemontcgapi.com/docs/migrate-from-pokemontcg-io)
|
|
80
|
+
explains capturing the change feed watermark before an import and keeping the replica current.
|
|
81
|
+
|
|
48
82
|
The cursor carries a signature of the sort order, so it must never be reconstructed by hand — the SDK
|
|
49
83
|
follows the URL the API returned, which is the failure mode this avoids. `.toArray({ max })` requires
|
|
50
84
|
an explicit ceiling, because the catalogue is large enough that an unbounded materialisation is a
|
|
@@ -53,15 +87,24 @@ mistake rather than a choice.
|
|
|
53
87
|
### One call for a hundred cards
|
|
54
88
|
|
|
55
89
|
```ts
|
|
56
|
-
const { data, requested, found } = await client.cards.batch(['
|
|
90
|
+
const { data, requested, found, missing } = await client.cards.batch(['sv8-116', 'sv8-100', 'inventato-xyz'], {
|
|
57
91
|
include: ['index'], // index_eur on list and batch rows is opt-in: 1 credit per 50 cards
|
|
58
92
|
select: ['id', 'name', 'index_eur'],
|
|
59
93
|
});
|
|
60
94
|
```
|
|
61
95
|
|
|
62
|
-
|
|
96
|
+
`missing` is optional: it is absent when every id resolves. Otherwise each unresolved id appears once
|
|
97
|
+
as `{ id, suggested_id? }`. A suggestion is included only for an existing historical candidate in a
|
|
98
|
+
different canonical set. In this example only `sv8-100` is returned; `sv8-116` suggests `ssp-116`,
|
|
99
|
+
and `inventato-xyz` has no suggestion. A canonical set prefix binds the lookup to that set;
|
|
100
|
+
`base1-4` still resolves to `bs-4` because `base1` is only a historical alias.
|
|
101
|
+
|
|
102
|
+
`data` contains distinct cards. Repeated ids count towards `requested` and credits, but do not
|
|
103
|
+
repeat rows in `data` or `missing`. Two valid aliases for one card can make `found` smaller than
|
|
104
|
+
`requested` with no missing ids. Missing entries ignore case and retain the first spelling and
|
|
105
|
+
request order after whitespace trimming. `withheld` remains an optional top-level field.
|
|
63
106
|
|
|
64
|
-
### Japanese, and the other
|
|
107
|
+
### Japanese, and the other seven locales
|
|
65
108
|
|
|
66
109
|
```ts
|
|
67
110
|
const page = await client.sets.cards('sv8', { lang: 'ja', limit: 1 });
|
|
@@ -69,7 +112,9 @@ console.log(page.data[0]?.name); // タマタマ
|
|
|
69
112
|
```
|
|
70
113
|
|
|
71
114
|
`lang` replaces the `name` field itself and falls back to English where a translation is missing.
|
|
72
|
-
Locales: `en
|
|
115
|
+
Locales, with the rows each one actually has on 16 September 2026: `en` 57,421, `fr` 42,858,
|
|
116
|
+
`de` 42,604, `ja` 27,230, `it` 21,644, `es` 21,003, `pt` 13,822, `zh` 3,492. A thin locale answers
|
|
117
|
+
mostly in English, because the fallback is per card and not per request.
|
|
73
118
|
|
|
74
119
|
### Conditional requests are free
|
|
75
120
|
|
|
@@ -77,11 +122,16 @@ Locales: `en`, `ja`, `fr`, `de`, `es`, `it`.
|
|
|
77
122
|
const client = new PokemonTcgApi({ cache: 'etag' });
|
|
78
123
|
```
|
|
79
124
|
|
|
80
|
-
Every collection carries
|
|
81
|
-
|
|
125
|
+
Every collection carries an ETag. We compute it strong, from the body; the edge rewrites it weak with
|
|
126
|
+
an encoding suffix when it compresses, so what you receive looks like `W/"…-gzip"` and you send back
|
|
127
|
+
exactly that. With the cache on, the client stores it and replays a `304` without a body, and a `304`
|
|
128
|
+
consumes no quota. A mirror that re-syncs often pays only for what changed.
|
|
82
129
|
|
|
83
130
|
### A photo instead of an id
|
|
84
131
|
|
|
132
|
+
**Included from the Growth plan up.** On a trial or a Developer key the call answers `403
|
|
133
|
+
PLAN_REQUIRED` with `details.min_plan`, before reading the image and without spending credits.
|
|
134
|
+
|
|
85
135
|
```ts
|
|
86
136
|
const { data } = await client.vision.identify(file, { set: 'sv3' });
|
|
87
137
|
|
|
@@ -134,30 +184,93 @@ Stated up front so you find out here rather than three days into an integration:
|
|
|
134
184
|
carry no data.
|
|
135
185
|
- **Card game text is English, and uneven.** `attacks`, `abilities`, `weaknesses`, `resistances`,
|
|
136
186
|
`subtypes`, `retreat_cost`, `rules` and `flavor_text` carry rows since 3 September 2026, on the
|
|
137
|
-
20,725 Western printings
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
187
|
+
20,725 Western printings. Measured on 16 September 2026 against 57,450 cards: `attacks` on 29.9% of
|
|
188
|
+
the whole catalogue and 82.9% of the Western part, `subtypes` 35.0%, `abilities` 7.0%.
|
|
189
|
+
Japanese and Chinese printings carry none. The types in this package keep them nullable, so the
|
|
190
|
+
compiler makes you handle the part that is absent.
|
|
191
|
+
- **No format legalities.** The card object has no `legalities` field and `include` rejects the
|
|
192
|
+
value with a 400. If you are building a deck checker, this is not the data source you need.
|
|
142
193
|
|
|
143
194
|
What it does have: the printing itself — set, number, rarity, region, release date, illustrator,
|
|
144
|
-
image, marketplace ids,
|
|
195
|
+
image, marketplace ids, names in eight locales — and prices.
|
|
145
196
|
|
|
146
197
|
## Prices
|
|
147
198
|
|
|
148
199
|
```ts
|
|
149
200
|
const card = await client.cards.get('base1-4', { include: ['prices'] });
|
|
150
201
|
for (const price of card.prices ?? []) {
|
|
151
|
-
console.log(price.source, price.basis, price.
|
|
202
|
+
console.log(price.source, price.basis, price.amount, price.currency, price.as_of, price.sample_n);
|
|
152
203
|
}
|
|
153
204
|
```
|
|
154
205
|
|
|
155
|
-
|
|
206
|
+
The dedicated price routes have their own methods, and they are the ones to use when prices are the
|
|
207
|
+
point of the call:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const { data, meta } = await client.prices.card('base1-4'); // index + quotes, 2 credits
|
|
211
|
+
const many = await client.prices.current(['base1-4', 'sv3-125']); // up to 50 ids, 4 credits per 25
|
|
212
|
+
const history = await client.prices.history('base1-4', { bucket: 'week' }); // 5 credits
|
|
213
|
+
const stats = await client.prices.stats('base1-4', { window: '30d' }); // 2 credits
|
|
214
|
+
const movers = await client.prices.movers({ window: '7d', direction: 'gainers' }); // Growth and up
|
|
215
|
+
const box = await client.sealed.prices('evolving-skies-booster-box');
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`history` is bounded by your plan (7 days on the trial, 30 on Developer, everything from Growth): a
|
|
219
|
+
wider window throws `UpgradeRequiredError`, whose `permittedWindow` says what you may ask for.
|
|
220
|
+
`movers` below Growth throws `PlanRequiredError`, and a trial past its 30 days throws
|
|
221
|
+
`TrialExpiredError` on every route that costs credits. Both extend `PermissionDeniedError`.
|
|
222
|
+
|
|
223
|
+
There is no printing filter on `include: ['prices']`: first edition, holofoil and graded rows come back together, so read
|
|
156
224
|
`printing`, `condition` and `grading` per row. `basis` separates `GUIDE` (published upstream) from
|
|
157
|
-
`DERIVED` (computed by us). `PTCG_INDEX` is a composite index in EUR carrying `sample_n`, and
|
|
158
|
-
|
|
225
|
+
`DERIVED` (computed by us). `PTCG_INDEX` is a composite index in EUR carrying `sample_n`, and the same
|
|
226
|
+
number sits on the card row as `index_eur` wherever we have enough observations to compute one: 51,636
|
|
227
|
+
cards of 57,450 on 16 September 2026, so treat it as nullable. On a list or batch it comes with `include: ['index']`
|
|
159
228
|
(1 credit per 50 rows), so a list still has a comparable number without a second request per card.
|
|
160
229
|
|
|
230
|
+
What your plan withholds is named rather than hidden, but it is named in three different places, so
|
|
231
|
+
read the one that matches the call you made:
|
|
232
|
+
|
|
233
|
+
| call | where the exclusions are |
|
|
234
|
+
|---|---|
|
|
235
|
+
| `client.prices.card(id)` | `meta.withheld` |
|
|
236
|
+
| `client.cards.get(id, { include: ['prices'] })` | the `X-Plan-Withheld` header: `client.lastResponse?.planWithheld` |
|
|
237
|
+
| `client.cards.batch(ids, …)` | a top-level `withheld` field |
|
|
238
|
+
|
|
239
|
+
The values are `graded` and `non_english_locales`: a trial key gets both, Developer keeps `graded`,
|
|
240
|
+
and from Growth up nothing is withheld, in which case the field is absent rather than an empty array.
|
|
241
|
+
Read it before concluding that a card has no graded observations: it may be your plan, not the
|
|
242
|
+
catalogue. Prices also carry their own `locale`, and a card read with `include: ['prices']` returns
|
|
243
|
+
every locale your plan allows, so the currency does not tell you the language.
|
|
244
|
+
|
|
245
|
+
## Credits and quota
|
|
246
|
+
|
|
247
|
+
Every response says what it cost. The SDK keeps the headers of the last one, and hands each one to
|
|
248
|
+
`onResponse` if you want a running total:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
let spent = 0;
|
|
252
|
+
const client = new PokemonTcgApi({ onResponse: (r) => { spent += r.creditsCost ?? 0; } });
|
|
253
|
+
|
|
254
|
+
await client.cards.search({ q: 'name:charizard', include: ['index'] });
|
|
255
|
+
console.log(client.lastResponse?.creditsCost, client.lastResponse?.quotaRemaining);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The trial is 800 credits, once, for 30 days, with at most 400 spent in a day; `trialExpiresAt` on
|
|
259
|
+
the same object says when it ends.
|
|
260
|
+
|
|
261
|
+
## The change feed
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
let since = Number(await store.get('ptcg_since') ?? 0);
|
|
265
|
+
for (;;) {
|
|
266
|
+
const page = await client.changes({ since, limit: 500 });
|
|
267
|
+
for (const change of page.data) await apply(change); // kind, entity_id, op, version
|
|
268
|
+
since = page.meta.next_since;
|
|
269
|
+
await store.set('ptcg_since', since);
|
|
270
|
+
if (!page.meta.has_more) break;
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
161
274
|
## Also available
|
|
162
275
|
|
|
163
276
|
- **MCP server** for agents: [`@pokemontcgapi/mcp`](https://www.npmjs.com/package/@pokemontcgapi/mcp) — [source](https://github.com/pokemontcgapi/mcp-server)
|
|
@@ -172,8 +285,8 @@ npm run typecheck
|
|
|
172
285
|
npm run build
|
|
173
286
|
```
|
|
174
287
|
|
|
175
|
-
Node >= 20.
|
|
176
|
-
typechecks and builds on both Node 20 and Node 22, and that `npm pack` produces
|
|
288
|
+
Node >= 20. `npm test` runs the type-level and unit tests in `tests/`. CI enforces that the
|
|
289
|
+
package typechecks and builds on both Node 20 and Node 22, and that `npm pack` produces
|
|
177
290
|
the file list the registry is meant to receive.
|
|
178
291
|
|
|
179
292
|
This package is developed inside the private monorepo that runs
|
package/dist/client.d.ts
CHANGED
|
@@ -28,6 +28,29 @@ export interface ClientOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
readonly cache?: 'none' | 'etag';
|
|
30
30
|
readonly userAgent?: string;
|
|
31
|
+
/** Chiamata a ogni risposta ricevuta, errori compresi: il posto per un contatore di crediti. */
|
|
32
|
+
readonly onResponse?: (info: ResponseInfo) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Cio' che la risposta dice negli header e che il corpo non porta.
|
|
36
|
+
*
|
|
37
|
+
* `planWithheld` e' il motivo per cui esiste: su `cards.get(id, { include:
|
|
38
|
+
* ['prices'] })` le righe che il piano non copre (le quotazioni gradate sotto
|
|
39
|
+
* Growth) mancano in silenzio dal corpo, e solo `X-Plan-Withheld` lo dice.
|
|
40
|
+
*/
|
|
41
|
+
export interface ResponseInfo {
|
|
42
|
+
readonly url: string;
|
|
43
|
+
readonly status: number;
|
|
44
|
+
readonly requestId: string | null;
|
|
45
|
+
/** Crediti scalati da questa chiamata. 0 su rotte gratuite, 304 ed errori del client. */
|
|
46
|
+
readonly creditsCost: number | null;
|
|
47
|
+
readonly quotaLimit: number | null;
|
|
48
|
+
readonly quotaRemaining: number | null;
|
|
49
|
+
readonly quotaReset: string | null;
|
|
50
|
+
readonly rateLimitRemaining: number | null;
|
|
51
|
+
readonly planWithheld: readonly string[];
|
|
52
|
+
/** Solo sulla prova: quando scade. */
|
|
53
|
+
readonly trialExpiresAt: string | null;
|
|
31
54
|
}
|
|
32
55
|
export declare function serializeParams(params: Record<string, unknown> | undefined): URLSearchParams;
|
|
33
56
|
export declare class HttpClient {
|
|
@@ -38,6 +61,9 @@ export declare class HttpClient {
|
|
|
38
61
|
private readonly doFetch;
|
|
39
62
|
private readonly userAgent;
|
|
40
63
|
private readonly etags;
|
|
64
|
+
private readonly onResponse;
|
|
65
|
+
/** Gli header dell'ultima risposta ricevuta da questa istanza. */
|
|
66
|
+
lastResponse: ResponseInfo | null;
|
|
41
67
|
constructor(options?: ClientOptions);
|
|
42
68
|
/** URL assoluto da un path applicativo piu' i parametri. */
|
|
43
69
|
url(path: string, params?: Record<string, unknown>): string;
|
|
@@ -88,8 +114,8 @@ export declare class Page<T> implements AsyncIterable<T> {
|
|
|
88
114
|
nextPage(): Promise<Page<T> | null>;
|
|
89
115
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
90
116
|
/**
|
|
91
|
-
* Materializza in un array. `max` e' OBBLIGATORIO: il catalogo ha
|
|
92
|
-
*
|
|
117
|
+
* Materializza in un array. `max` e' OBBLIGATORIO: il catalogo ha decine di
|
|
118
|
+
* migliaia di carte, e un `.toArray()` senza tetto e' il modo piu' rapido di
|
|
93
119
|
* riempire la memoria di un processo per sbaglio.
|
|
94
120
|
*/
|
|
95
121
|
toArray({ max }: {
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,E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AAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAQtD"}
|
package/dist/client.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import { ApiConnectionError, ApiTimeoutError, PokemonTcgApiError, QuotaExceededError, RateLimitedError, ServerError, toApiError, } from './errors.js';
|
|
2
|
+
function headerNumber(headers, name) {
|
|
3
|
+
const raw = headers.get(name);
|
|
4
|
+
if (raw === null)
|
|
5
|
+
return null;
|
|
6
|
+
const n = Number(raw);
|
|
7
|
+
return Number.isFinite(n) ? n : null;
|
|
8
|
+
}
|
|
9
|
+
function toResponseInfo(url, response) {
|
|
10
|
+
const h = response.headers;
|
|
11
|
+
const withheld = h.get('x-plan-withheld');
|
|
12
|
+
return {
|
|
13
|
+
url,
|
|
14
|
+
status: response.status,
|
|
15
|
+
requestId: h.get('x-request-id'),
|
|
16
|
+
creditsCost: headerNumber(h, 'x-credits-cost'),
|
|
17
|
+
quotaLimit: headerNumber(h, 'x-quota-limit'),
|
|
18
|
+
quotaRemaining: headerNumber(h, 'x-quota-remaining'),
|
|
19
|
+
quotaReset: h.get('x-quota-reset'),
|
|
20
|
+
rateLimitRemaining: headerNumber(h, 'ratelimit-remaining'),
|
|
21
|
+
planWithheld: withheld === null || withheld === '' ? [] : withheld.split(',').map((v) => v.trim()),
|
|
22
|
+
trialExpiresAt: h.get('x-trial-expires-at'),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
2
25
|
const DEFAULT_BASE_URL = 'https://api.pokemontcgapi.com';
|
|
3
26
|
const DEFAULT_TIMEOUT = 30_000;
|
|
4
27
|
const DEFAULT_MAX_RETRIES = 2;
|
|
@@ -64,6 +87,9 @@ export class HttpClient {
|
|
|
64
87
|
doFetch;
|
|
65
88
|
userAgent;
|
|
66
89
|
etags;
|
|
90
|
+
onResponse;
|
|
91
|
+
/** Gli header dell'ultima risposta ricevuta da questa istanza. */
|
|
92
|
+
lastResponse = null;
|
|
67
93
|
constructor(options = {}) {
|
|
68
94
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
69
95
|
this.apiKey = options.apiKey ?? readEnv('PTCG_API_KEY');
|
|
@@ -72,6 +98,7 @@ export class HttpClient {
|
|
|
72
98
|
this.doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
73
99
|
this.userAgent = options.userAgent ?? '@pokemontcgapi/sdk';
|
|
74
100
|
this.etags = options.cache === 'etag' ? new Map() : null;
|
|
101
|
+
this.onResponse = options.onResponse;
|
|
75
102
|
}
|
|
76
103
|
/** URL assoluto da un path applicativo piu' i parametri. */
|
|
77
104
|
url(path, params) {
|
|
@@ -157,6 +184,8 @@ export class HttpClient {
|
|
|
157
184
|
finally {
|
|
158
185
|
clearTimeout(timer);
|
|
159
186
|
}
|
|
187
|
+
this.lastResponse = toResponseInfo(url, response);
|
|
188
|
+
this.onResponse?.(this.lastResponse);
|
|
160
189
|
// 304: il corpo e' vuoto per definizione, la risposta e' quella in cache.
|
|
161
190
|
if (response.status === 304 && cached !== undefined)
|
|
162
191
|
return cached.body;
|
|
@@ -230,8 +259,8 @@ export class Page {
|
|
|
230
259
|
}
|
|
231
260
|
}
|
|
232
261
|
/**
|
|
233
|
-
* Materializza in un array. `max` e' OBBLIGATORIO: il catalogo ha
|
|
234
|
-
*
|
|
262
|
+
* Materializza in un array. `max` e' OBBLIGATORIO: il catalogo ha decine di
|
|
263
|
+
* migliaia di carte, e un `.toArray()` senza tetto e' il modo piu' rapido di
|
|
235
264
|
* riempire la memoria di un processo per sbaglio.
|
|
236
265
|
*/
|
|
237
266
|
async toArray({ max }) {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EAC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BAAE,MAAM,IAAI,CAAC;YACzC,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAmB;QACpC,MAAM,GAAG,GAAQ,EAAE,CAAC;QACpB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YAC9B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACf,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG;gBAAE,MAAM;QAC/B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -36,7 +36,20 @@ export declare class AuthenticationError extends PokemonTcgApiError {
|
|
|
36
36
|
/** 403 — la chiave e' valida ma non puo' fare questa cosa. */
|
|
37
37
|
export declare class PermissionDeniedError extends PokemonTcgApiError {
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* 403 PLAN_REQUIRED — la rotta non e' nel piano (movers e foto partono da
|
|
41
|
+
* Growth). Estende `PermissionDeniedError`: chi gia' la catturava continua a
|
|
42
|
+
* farlo, chi vuole distinguere "compra" da "scope sbagliato" ora puo'.
|
|
43
|
+
*/
|
|
44
|
+
export declare class PlanRequiredError extends PermissionDeniedError {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 403 TRIAL_EXPIRED — la prova e' finita (30 giorni) e la rotta costa crediti.
|
|
48
|
+
* Non passa aspettando ne' riprovando: serve un piano.
|
|
49
|
+
*/
|
|
50
|
+
export declare class TrialExpiredError extends PermissionDeniedError {
|
|
51
|
+
}
|
|
52
|
+
/** 403 UPGRADE_REQUIRED — la finestra chiesta e' piu' larga di quella del piano. */
|
|
40
53
|
export declare class UpgradeRequiredError extends PokemonTcgApiError {
|
|
41
54
|
/** Finestra concessa dal piano corrente, quando l'API la dichiara. */
|
|
42
55
|
get permittedWindow(): unknown;
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;gBAE1C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY;CAQ/C;AAED,mDAAmD;AACnD,qBAAa,mBAAoB,SAAQ,kBAAkB;CAAG;AAE9D,8DAA8D;AAC9D,qBAAa,qBAAsB,SAAQ,kBAAkB;CAAG;AAEhE,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CA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KAAK;IAC3C,gEAAgE;IAChE,SAAkB,KAAK,EAAE,OAAO,CAAC;gBACrB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAK5C;AAED,+DAA+D;AAC/D,qBAAa,eAAgB,SAAQ,kBAAkB;gBACzC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAI9C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAetG"}
|
package/dist/errors.js
CHANGED
|
@@ -37,7 +37,20 @@ export class AuthenticationError extends PokemonTcgApiError {
|
|
|
37
37
|
/** 403 — la chiave e' valida ma non puo' fare questa cosa. */
|
|
38
38
|
export class PermissionDeniedError extends PokemonTcgApiError {
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* 403 PLAN_REQUIRED — la rotta non e' nel piano (movers e foto partono da
|
|
42
|
+
* Growth). Estende `PermissionDeniedError`: chi gia' la catturava continua a
|
|
43
|
+
* farlo, chi vuole distinguere "compra" da "scope sbagliato" ora puo'.
|
|
44
|
+
*/
|
|
45
|
+
export class PlanRequiredError extends PermissionDeniedError {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 403 TRIAL_EXPIRED — la prova e' finita (30 giorni) e la rotta costa crediti.
|
|
49
|
+
* Non passa aspettando ne' riprovando: serve un piano.
|
|
50
|
+
*/
|
|
51
|
+
export class TrialExpiredError extends PermissionDeniedError {
|
|
52
|
+
}
|
|
53
|
+
/** 403 UPGRADE_REQUIRED — la finestra chiesta e' piu' larga di quella del piano. */
|
|
41
54
|
export class UpgradeRequiredError extends PokemonTcgApiError {
|
|
42
55
|
/** Finestra concessa dal piano corrente, quando l'API la dichiara. */
|
|
43
56
|
get permittedWindow() {
|
|
@@ -95,10 +108,14 @@ export class ApiTimeoutError extends ApiConnectionError {
|
|
|
95
108
|
*/
|
|
96
109
|
export function toApiError(status, body, retryAfter) {
|
|
97
110
|
const code = body.code;
|
|
98
|
-
if (code === 'QUOTA_EXCEEDED'
|
|
111
|
+
if (code === 'QUOTA_EXCEEDED')
|
|
99
112
|
return new QuotaExceededError(status, body);
|
|
100
|
-
if (code === 'UPGRADE_REQUIRED'
|
|
113
|
+
if (code === 'UPGRADE_REQUIRED')
|
|
101
114
|
return new UpgradeRequiredError(status, body);
|
|
115
|
+
if (code === 'PLAN_REQUIRED')
|
|
116
|
+
return new PlanRequiredError(status, body);
|
|
117
|
+
if (code === 'TRIAL_EXPIRED')
|
|
118
|
+
return new TrialExpiredError(status, body);
|
|
102
119
|
if (status === 429)
|
|
103
120
|
return new RateLimitedError(status, body, retryAfter);
|
|
104
121
|
if (status === 401)
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,6DAA6D;IACpD,IAAI,CAAS;IACb,MAAM,CAAS;IACxB;;;OAGG;IACM,SAAS,CAAqB;IAC9B,OAAO,CAAsC;IAEtD,YAAY,MAAc,EAAE,IAAkB;QAC5C,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;CACF;AAED,mDAAmD;AACnD,MAAM,OAAO,mBAAoB,SAAQ,k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