scryfall-api 4.0.0-beta.1 → 4.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/README.md +8 -3
- package/dist/scryfall-api.cjs +126 -128
- package/dist/scryfall-api.d.ts +25 -25
- package/dist/scryfall-api.js +126 -128
- package/dist/scryfall-api.min.cjs +1 -1
- package/dist/scryfall-api.min.js +1 -1
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -39,21 +39,26 @@ bun add scryfall-api
|
|
|
39
39
|
|
|
40
40
|
In the documentation below, requiring the package is assumed.
|
|
41
41
|
|
|
42
|
-
```
|
|
42
|
+
```ts
|
|
43
43
|
import scryfall from 'scryfall-api';
|
|
44
|
-
```
|
|
45
44
|
|
|
45
|
+
scryfall.Cards.byName('Black Lotus').then(console.log);
|
|
46
|
+
```
|
|
46
47
|
|
|
47
48
|
**With CommonJS**
|
|
48
49
|
|
|
49
50
|
```js
|
|
50
51
|
const scryfall = require('scryfall-api');
|
|
52
|
+
|
|
53
|
+
scryfall.Cards.byName('Black Lotus').then(console.log);
|
|
51
54
|
```
|
|
52
55
|
|
|
53
56
|
**If you only need Cards**
|
|
54
57
|
|
|
55
|
-
```
|
|
58
|
+
```ts
|
|
56
59
|
import { Cards } from 'scryfall-api';
|
|
60
|
+
|
|
61
|
+
Cards.byName('Black Lotus').then(console.log);
|
|
57
62
|
```
|
|
58
63
|
|
|
59
64
|
Link to [full documentation.](./DOCUMENTATION.md)
|
package/dist/scryfall-api.cjs
CHANGED
|
@@ -20,15 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/scryfall-api.ts
|
|
21
21
|
var scryfall_api_exports = {};
|
|
22
22
|
__export(scryfall_api_exports, {
|
|
23
|
-
CardIdentifierBuilder: () =>
|
|
24
|
-
Cards: () =>
|
|
25
|
-
Catalogs: () =>
|
|
23
|
+
CardIdentifierBuilder: () => CardIdentifierApi,
|
|
24
|
+
Cards: () => card_api_default,
|
|
25
|
+
Catalogs: () => catalog_api_default,
|
|
26
26
|
InvalidScryfallArgumentError: () => InvalidScryfallArgumentError,
|
|
27
27
|
MagicPageResult: () => MagicPageResult,
|
|
28
|
-
Rulings: () =>
|
|
28
|
+
Rulings: () => ruling_api_default,
|
|
29
29
|
ScryfallError: () => ScryfallError,
|
|
30
|
-
Sets: () =>
|
|
31
|
-
SymbologyApi: () =>
|
|
30
|
+
Sets: () => set_api_default,
|
|
31
|
+
SymbologyApi: () => symbology_api_default,
|
|
32
32
|
UnknownScryfallError: () => UnknownScryfallError
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(scryfall_api_exports);
|
|
@@ -72,68 +72,12 @@ async function debounce() {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
function createDebounceFetcher(fetcher2 = fetch) {
|
|
75
|
-
return async function debounceFetcher(...
|
|
75
|
+
return async function debounceFetcher(...arguments_) {
|
|
76
76
|
await debounce();
|
|
77
|
-
return fetcher2(...
|
|
77
|
+
return fetcher2(...arguments_);
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
// src/fetcher/page.result.ts
|
|
82
|
-
var MagicPageResult = class {
|
|
83
|
-
constructor(apiPath, query) {
|
|
84
|
-
this.apiPath = apiPath;
|
|
85
|
-
this.query = query;
|
|
86
|
-
this.#hasMore = true;
|
|
87
|
-
this.#count = 0;
|
|
88
|
-
}
|
|
89
|
-
#count;
|
|
90
|
-
#hasMore;
|
|
91
|
-
get count() {
|
|
92
|
-
return this.#count;
|
|
93
|
-
}
|
|
94
|
-
get hasMore() {
|
|
95
|
-
return this.#hasMore;
|
|
96
|
-
}
|
|
97
|
-
async all() {
|
|
98
|
-
const r = [];
|
|
99
|
-
while (this.#hasMore) {
|
|
100
|
-
const result = await this.next();
|
|
101
|
-
r.push(...result);
|
|
102
|
-
}
|
|
103
|
-
return r;
|
|
104
|
-
}
|
|
105
|
-
async get(limit) {
|
|
106
|
-
const r = [];
|
|
107
|
-
while (this.#hasMore) {
|
|
108
|
-
const result = await this.next();
|
|
109
|
-
r.push(...result);
|
|
110
|
-
if (r.length === limit) {
|
|
111
|
-
return r;
|
|
112
|
-
}
|
|
113
|
-
if (r.length > limit) {
|
|
114
|
-
return r.slice(0, limit);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return r;
|
|
118
|
-
}
|
|
119
|
-
async next() {
|
|
120
|
-
const results = await fetcher(this.apiPath, this.query);
|
|
121
|
-
this.#hasMore = results?.has_more ?? false;
|
|
122
|
-
this.#count = Number.parseInt(`${results?.total_cards ?? 0}`, 10);
|
|
123
|
-
if (this.#hasMore) {
|
|
124
|
-
this.setNextPage();
|
|
125
|
-
}
|
|
126
|
-
return results?.data ?? [];
|
|
127
|
-
}
|
|
128
|
-
async page(page) {
|
|
129
|
-
this.query.page = page;
|
|
130
|
-
return this.next();
|
|
131
|
-
}
|
|
132
|
-
setNextPage() {
|
|
133
|
-
this.query.page += 1;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
81
|
// src/fetcher/retry.fetcher.ts
|
|
138
82
|
var defaultCanRetry = async (response) => {
|
|
139
83
|
const object = await response.json();
|
|
@@ -144,11 +88,11 @@ var defaultCanRetry = async (response) => {
|
|
|
144
88
|
const code = "code" in object && typeof object.code === "string" ? object.code : void 0;
|
|
145
89
|
return code !== "not_found" && code !== "bad_request";
|
|
146
90
|
};
|
|
147
|
-
function createRetryFetcher({
|
|
91
|
+
function createRetryFetcher({ canRetry = defaultCanRetry, maxAttempts = 3 } = {}, fetcher2 = fetch) {
|
|
148
92
|
let retries = 0;
|
|
149
|
-
return async function retryFetcher(...
|
|
93
|
+
return async function retryFetcher(...arguments_) {
|
|
150
94
|
retries++;
|
|
151
|
-
const response = await fetcher2(...
|
|
95
|
+
const response = await fetcher2(...arguments_);
|
|
152
96
|
if (response.ok) {
|
|
153
97
|
return response;
|
|
154
98
|
}
|
|
@@ -162,44 +106,42 @@ function createRetryFetcher({ maxAttempts = 3, canRetry = defaultCanRetry } = {}
|
|
|
162
106
|
if (code && details && status) {
|
|
163
107
|
throw new ScryfallError(code, details, status, type, warnings);
|
|
164
108
|
}
|
|
165
|
-
throw new UnknownScryfallError(`Request failed with status ${response.status}`);
|
|
109
|
+
throw new UnknownScryfallError(`Request failed with status ${response.status.toFixed(0)}`);
|
|
166
110
|
}
|
|
167
111
|
if (canRetry(response)) {
|
|
168
|
-
return retryFetcher(...
|
|
112
|
+
return retryFetcher(...arguments_);
|
|
169
113
|
}
|
|
170
114
|
if (code && details && status) {
|
|
171
115
|
throw new ScryfallError(code, details, status, type, warnings);
|
|
172
116
|
}
|
|
173
|
-
throw new UnknownScryfallError(`Request failed with status ${response.status}`);
|
|
117
|
+
throw new UnknownScryfallError(`Request failed with status ${response.status.toFixed(0)}`);
|
|
174
118
|
};
|
|
175
119
|
}
|
|
176
120
|
|
|
177
|
-
// src/fetcher/
|
|
121
|
+
// src/fetcher/fetcher.ts
|
|
178
122
|
var simpleFetcher = createDebounceFetcher(createRetryFetcher());
|
|
179
123
|
var endpoint = "https://api.scryfall.com";
|
|
180
124
|
var DATE_REGEXP = /^\d{4}-\d{2}-\d{2}?$/;
|
|
181
125
|
var dateParser = (_key, value) => {
|
|
182
|
-
if (typeof value === "string") {
|
|
183
|
-
|
|
184
|
-
return new Date(value);
|
|
185
|
-
}
|
|
126
|
+
if (typeof value === "string" && DATE_REGEXP.test(value)) {
|
|
127
|
+
return new Date(value);
|
|
186
128
|
}
|
|
187
129
|
return value;
|
|
188
130
|
};
|
|
189
|
-
async function fetcher(apiPath,
|
|
131
|
+
async function fetcher(apiPath, parameters, body) {
|
|
190
132
|
let path = "";
|
|
191
133
|
if (typeof apiPath === "number" || typeof apiPath === "string") {
|
|
192
134
|
path = apiPath;
|
|
193
135
|
} else if (apiPath) {
|
|
194
136
|
path = apiPath.join("/");
|
|
195
137
|
}
|
|
196
|
-
const url = new URL(`${endpoint}/${path}`);
|
|
197
|
-
if (
|
|
198
|
-
|
|
138
|
+
const url = new URL(`${endpoint}/${String(path)}`);
|
|
139
|
+
if (parameters) {
|
|
140
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
199
141
|
if (value !== void 0) {
|
|
200
|
-
url.searchParams.append(key,
|
|
142
|
+
url.searchParams.append(key, value.toString());
|
|
201
143
|
}
|
|
202
|
-
}
|
|
144
|
+
}
|
|
203
145
|
}
|
|
204
146
|
try {
|
|
205
147
|
const init = {
|
|
@@ -214,19 +156,75 @@ async function fetcher(apiPath, params, body) {
|
|
|
214
156
|
const response = await simpleFetcher(url, init);
|
|
215
157
|
const content = await response.text();
|
|
216
158
|
return JSON.parse(content, dateParser);
|
|
217
|
-
} catch (
|
|
218
|
-
if (
|
|
219
|
-
if (
|
|
220
|
-
console.warn(
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error instanceof ScryfallError) {
|
|
161
|
+
if (error.warnings) {
|
|
162
|
+
console.warn(error.warnings);
|
|
221
163
|
}
|
|
222
|
-
if (
|
|
164
|
+
if (error.code === "not_found" || error.code === "bad_request") {
|
|
223
165
|
return void 0;
|
|
224
166
|
}
|
|
225
167
|
}
|
|
226
|
-
throw
|
|
168
|
+
throw error;
|
|
227
169
|
}
|
|
228
170
|
}
|
|
229
171
|
|
|
172
|
+
// src/fetcher/page.result.ts
|
|
173
|
+
var MagicPageResult = class {
|
|
174
|
+
constructor(apiPath, query) {
|
|
175
|
+
this.apiPath = apiPath;
|
|
176
|
+
this.query = query;
|
|
177
|
+
this.#hasMore = true;
|
|
178
|
+
this.#count = 0;
|
|
179
|
+
}
|
|
180
|
+
#count;
|
|
181
|
+
#hasMore;
|
|
182
|
+
get count() {
|
|
183
|
+
return this.#count;
|
|
184
|
+
}
|
|
185
|
+
get hasMore() {
|
|
186
|
+
return this.#hasMore;
|
|
187
|
+
}
|
|
188
|
+
async all() {
|
|
189
|
+
const r = [];
|
|
190
|
+
while (this.#hasMore) {
|
|
191
|
+
const result = await this.next();
|
|
192
|
+
r.push(...result);
|
|
193
|
+
}
|
|
194
|
+
return r;
|
|
195
|
+
}
|
|
196
|
+
async get(limit) {
|
|
197
|
+
const r = [];
|
|
198
|
+
while (this.#hasMore) {
|
|
199
|
+
const result = await this.next();
|
|
200
|
+
r.push(...result);
|
|
201
|
+
if (r.length === limit) {
|
|
202
|
+
return r;
|
|
203
|
+
}
|
|
204
|
+
if (r.length > limit) {
|
|
205
|
+
return r.slice(0, limit);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return r;
|
|
209
|
+
}
|
|
210
|
+
async next() {
|
|
211
|
+
const results = await fetcher(this.apiPath, this.query);
|
|
212
|
+
this.#hasMore = results?.has_more ?? false;
|
|
213
|
+
this.#count = Number.parseInt(results?.total_cards?.toFixed(0) ?? "0", 10);
|
|
214
|
+
if (this.#hasMore) {
|
|
215
|
+
this.setNextPage();
|
|
216
|
+
}
|
|
217
|
+
return results?.data ?? [];
|
|
218
|
+
}
|
|
219
|
+
async page(page) {
|
|
220
|
+
this.query.page = page;
|
|
221
|
+
return this.next();
|
|
222
|
+
}
|
|
223
|
+
setNextPage() {
|
|
224
|
+
this.query.page += 1;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
230
228
|
// src/api/card/card.api.ts
|
|
231
229
|
var CardApi = class {
|
|
232
230
|
/*
|
|
@@ -292,8 +290,8 @@ var CardApi = class {
|
|
|
292
290
|
}
|
|
293
291
|
async collection(...identifiers) {
|
|
294
292
|
const cards2 = [];
|
|
295
|
-
for (let
|
|
296
|
-
const collectionSection = { identifiers: identifiers.slice(
|
|
293
|
+
for (let index = 0; index < identifiers.length; index += 75) {
|
|
294
|
+
const collectionSection = { identifiers: identifiers.slice(index, index + 75) };
|
|
297
295
|
const result = await fetcher(
|
|
298
296
|
"cards/collection",
|
|
299
297
|
void 0,
|
|
@@ -316,9 +314,6 @@ var CardApi = class {
|
|
|
316
314
|
var cards = new CardApi();
|
|
317
315
|
var card_api_default = cards;
|
|
318
316
|
|
|
319
|
-
// src/api/card/index.ts
|
|
320
|
-
var card_default = card_api_default;
|
|
321
|
-
|
|
322
317
|
// src/api/card-identifier/card-identifier.api.ts
|
|
323
318
|
var CardIdentifierApi = class {
|
|
324
319
|
static byId(id) {
|
|
@@ -343,85 +338,94 @@ var CardIdentifierApi = class {
|
|
|
343
338
|
return { oracle_id: id };
|
|
344
339
|
}
|
|
345
340
|
static bySet(set2, collectorNumber) {
|
|
346
|
-
return { collector_number:
|
|
341
|
+
return { collector_number: String(collectorNumber), set: set2 };
|
|
347
342
|
}
|
|
348
343
|
};
|
|
349
344
|
|
|
350
|
-
// src/api/card-identifier/index.ts
|
|
351
|
-
var card_identifier_default = CardIdentifierApi;
|
|
352
|
-
|
|
353
345
|
// src/api/catalog/catalog.api.ts
|
|
354
346
|
var CatalogApi = class {
|
|
355
347
|
async artifactTypes() {
|
|
356
|
-
|
|
348
|
+
const response = await fetcher("catalog/artifact-types");
|
|
349
|
+
return response?.data ?? [];
|
|
357
350
|
}
|
|
358
351
|
async artistNames() {
|
|
359
|
-
|
|
352
|
+
const response = await fetcher("catalog/artist-names");
|
|
353
|
+
return response?.data ?? [];
|
|
360
354
|
}
|
|
361
355
|
async cardNames() {
|
|
362
|
-
|
|
356
|
+
const response = await fetcher("catalog/card-names");
|
|
357
|
+
return response?.data ?? [];
|
|
363
358
|
}
|
|
364
359
|
async creatureTypes() {
|
|
365
|
-
|
|
360
|
+
const response = await fetcher("catalog/creature-types");
|
|
361
|
+
return response?.data ?? [];
|
|
366
362
|
}
|
|
367
363
|
async enchantmentTypes() {
|
|
368
|
-
|
|
364
|
+
const response = await fetcher("catalog/enchantment-types");
|
|
365
|
+
return response?.data ?? [];
|
|
369
366
|
}
|
|
370
367
|
async landTypes() {
|
|
371
|
-
|
|
368
|
+
const response = await fetcher("catalog/land-types");
|
|
369
|
+
return response?.data ?? [];
|
|
372
370
|
}
|
|
373
371
|
async loyalties() {
|
|
374
|
-
|
|
372
|
+
const response = await fetcher("catalog/loyalties");
|
|
373
|
+
return response?.data ?? [];
|
|
375
374
|
}
|
|
376
375
|
async planeswalkerTypes() {
|
|
377
|
-
|
|
376
|
+
const response = await fetcher("catalog/planeswalker-types");
|
|
377
|
+
return response?.data ?? [];
|
|
378
378
|
}
|
|
379
379
|
async powers() {
|
|
380
|
-
|
|
380
|
+
const response = await fetcher("catalog/powers");
|
|
381
|
+
return response?.data ?? [];
|
|
381
382
|
}
|
|
382
383
|
async spellTypes() {
|
|
383
|
-
|
|
384
|
+
const response = await fetcher("catalog/spell-types");
|
|
385
|
+
return response?.data ?? [];
|
|
384
386
|
}
|
|
385
387
|
async toughnesses() {
|
|
386
|
-
|
|
388
|
+
const response = await fetcher("catalog/toughnesses");
|
|
389
|
+
return response?.data ?? [];
|
|
387
390
|
}
|
|
388
391
|
async watermarks() {
|
|
389
|
-
|
|
392
|
+
const response = await fetcher("catalog/watermarks");
|
|
393
|
+
return response?.data ?? [];
|
|
390
394
|
}
|
|
391
395
|
async wordBank() {
|
|
392
|
-
|
|
396
|
+
const response = await fetcher("catalog/word-bank");
|
|
397
|
+
return response?.data ?? [];
|
|
393
398
|
}
|
|
394
399
|
};
|
|
395
400
|
var catalog = new CatalogApi();
|
|
396
401
|
var catalog_api_default = catalog;
|
|
397
402
|
|
|
398
|
-
// src/api/catalog/index.ts
|
|
399
|
-
var catalog_default = catalog_api_default;
|
|
400
|
-
|
|
401
403
|
// src/api/ruling/ruling.api.ts
|
|
402
404
|
var RulingApi = class {
|
|
403
405
|
async byArenaId(id) {
|
|
404
|
-
|
|
406
|
+
const response = await fetcher(["cards/arena", id, "rulings"]);
|
|
407
|
+
return response?.data ?? [];
|
|
405
408
|
}
|
|
406
409
|
async byId(id) {
|
|
407
|
-
|
|
410
|
+
const response = await fetcher(["cards", id, "rulings"]);
|
|
411
|
+
return response?.data ?? [];
|
|
408
412
|
}
|
|
409
413
|
async byMtgoId(id) {
|
|
410
|
-
|
|
414
|
+
const response = await fetcher(["cards/mtgo", id, "rulings"]);
|
|
415
|
+
return response?.data ?? [];
|
|
411
416
|
}
|
|
412
417
|
async byMultiverseId(id) {
|
|
413
|
-
|
|
418
|
+
const response = await fetcher(["cards/multiverse", id, "rulings"]);
|
|
419
|
+
return response?.data ?? [];
|
|
414
420
|
}
|
|
415
421
|
async bySet(setCode, collectorNumber) {
|
|
416
|
-
|
|
422
|
+
const response = await fetcher(["cards", setCode, String(collectorNumber), "rulings"]);
|
|
423
|
+
return response?.data ?? [];
|
|
417
424
|
}
|
|
418
425
|
};
|
|
419
426
|
var rulings = new RulingApi();
|
|
420
427
|
var ruling_api_default = rulings;
|
|
421
428
|
|
|
422
|
-
// src/api/ruling/index.ts
|
|
423
|
-
var ruling_default = ruling_api_default;
|
|
424
|
-
|
|
425
429
|
// src/api/set/set.api.ts
|
|
426
430
|
var SetApi = class {
|
|
427
431
|
async all() {
|
|
@@ -441,9 +445,6 @@ var SetApi = class {
|
|
|
441
445
|
var set = new SetApi();
|
|
442
446
|
var set_api_default = set;
|
|
443
447
|
|
|
444
|
-
// src/api/set/index.ts
|
|
445
|
-
var set_default = set_api_default;
|
|
446
|
-
|
|
447
448
|
// src/api/symbology/symbology.api.ts
|
|
448
449
|
var SymbologyApi = class {
|
|
449
450
|
async all() {
|
|
@@ -458,10 +459,10 @@ var SymbologyApi = class {
|
|
|
458
459
|
cost: shorthand
|
|
459
460
|
});
|
|
460
461
|
return cost ?? {
|
|
461
|
-
cost: "",
|
|
462
|
-
colors: [],
|
|
463
462
|
cmc: 0,
|
|
464
463
|
colorless: false,
|
|
464
|
+
colors: [],
|
|
465
|
+
cost: "",
|
|
465
466
|
monocolored: false,
|
|
466
467
|
multicolored: false,
|
|
467
468
|
object: "mana_cost"
|
|
@@ -470,9 +471,6 @@ var SymbologyApi = class {
|
|
|
470
471
|
};
|
|
471
472
|
var symbology = new SymbologyApi();
|
|
472
473
|
var symbology_api_default = symbology;
|
|
473
|
-
|
|
474
|
-
// src/api/symbology/index.ts
|
|
475
|
-
var symbology_default = symbology_api_default;
|
|
476
474
|
// Annotate the CommonJS export names for ESM import in node:
|
|
477
475
|
0 && (module.exports = {
|
|
478
476
|
CardIdentifierBuilder,
|
package/dist/scryfall-api.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ interface CardIdentifierCollectorSet {
|
|
|
47
47
|
collector_number: string;
|
|
48
48
|
set: string;
|
|
49
49
|
}
|
|
50
|
-
type CardIdentifier = CardIdentifierId | CardIdentifierIllustrationId | CardIdentifierMtgGoId | CardIdentifierMultiverseId | CardIdentifierNameSet | CardIdentifierOracleId
|
|
50
|
+
type CardIdentifier = CardIdentifierCollectorSet | CardIdentifierId | CardIdentifierIllustrationId | CardIdentifierMtgGoId | CardIdentifierMultiverseId | CardIdentifierNameSet | CardIdentifierOracleId;
|
|
51
51
|
|
|
52
52
|
declare class CardIdentifierApi {
|
|
53
53
|
static byId(id: string): CardIdentifier;
|
|
@@ -59,8 +59,8 @@ declare class CardIdentifierApi {
|
|
|
59
59
|
static bySet(set: string, collectorNumber: number | string): CardIdentifier;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
type CardLanguage = '
|
|
63
|
-
type CardLayout = '
|
|
62
|
+
type CardLanguage = 'ar' | 'de' | 'en' | 'es' | 'fr' | 'grc' | 'he' | 'it' | 'ja' | 'ko' | 'la' | 'ph' | 'pt' | 'ru' | 'sa' | 'zhs' | 'zht';
|
|
63
|
+
type CardLayout = 'adventure' | 'art_series' | 'augment' | 'battle' | 'case' | 'class' | 'double_faced_token' | 'emblem' | 'flip' | 'host' | 'leveler' | 'meld' | 'modal_dfc' | 'mutate' | 'normal' | 'planar' | 'prototype' | 'reversible_card' | 'saga' | 'scheme' | 'split' | 'token' | 'transform' | 'vanguard';
|
|
64
64
|
interface CardCore {
|
|
65
65
|
arena_id?: Nullable<string>;
|
|
66
66
|
cardmarket_id?: Nullable<number>;
|
|
@@ -80,7 +80,7 @@ interface CardCore {
|
|
|
80
80
|
uri: string;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
type Color = '
|
|
83
|
+
type Color = 'B' | 'G' | 'R' | 'U' | 'W';
|
|
84
84
|
interface ManaCost {
|
|
85
85
|
cmc: number;
|
|
86
86
|
colorless: boolean;
|
|
@@ -113,8 +113,8 @@ declare class SymbologyApi {
|
|
|
113
113
|
}
|
|
114
114
|
declare const symbology: SymbologyApi;
|
|
115
115
|
|
|
116
|
-
type CardComponent = '
|
|
117
|
-
type Legality = '
|
|
116
|
+
type CardComponent = 'combo_piece' | 'meld_part' | 'meld_result' | 'token';
|
|
117
|
+
type Legality = 'banned' | 'legal' | 'not_legal' | 'restricted';
|
|
118
118
|
interface ImageUris$1 {
|
|
119
119
|
art_crop: string;
|
|
120
120
|
border_crop: string;
|
|
@@ -205,7 +205,7 @@ interface GameplayCard {
|
|
|
205
205
|
type_line: string;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
type SetType = '
|
|
208
|
+
type SetType = 'alchemy' | 'archenemy' | 'arsenal' | 'box' | 'commander' | 'core' | 'draft_innovation' | 'duel_deck' | 'expansion' | 'from_the_vault' | 'funny' | 'masterpiece' | 'masters' | 'memorabilia' | 'minigame' | 'planechase' | 'premium_deck' | 'promo' | 'spellbook' | 'starter' | 'token' | 'treasure_chest' | 'vanguard';
|
|
209
209
|
interface Set {
|
|
210
210
|
arena_code?: Nullable<string>;
|
|
211
211
|
block?: Nullable<string>;
|
|
@@ -239,11 +239,11 @@ declare class SetApi {
|
|
|
239
239
|
declare const set: SetApi;
|
|
240
240
|
|
|
241
241
|
type BorderColor = 'black' | 'borderless' | 'gold' | 'silver' | 'white';
|
|
242
|
-
type Finish = '
|
|
242
|
+
type Finish = 'etched' | 'foil' | 'nonfoil';
|
|
243
243
|
type Frame = '1993' | '1997' | '2003' | '2015' | 'future';
|
|
244
|
-
type FrameEffect = '
|
|
245
|
-
type Game = '
|
|
246
|
-
type ImageStatus = '
|
|
244
|
+
type FrameEffect = 'colorshifted' | 'companion' | 'compasslanddfc' | 'convertdfc' | 'devoid' | 'draft' | 'etched' | 'extendedart' | 'fandfc' | 'inverted' | 'legendary' | 'lesson' | 'miracle' | 'mooneldrazidfc' | 'nyxtouched' | 'originpwdfc' | 'shatteredglass' | 'showcase' | 'snow' | 'sunmoondfc' | 'tombstone' | 'upsidedowndfc' | 'waxingandwaningmoondfc';
|
|
245
|
+
type Game = 'arena' | 'mtgo' | 'paper';
|
|
246
|
+
type ImageStatus = 'highres_scan' | 'lowres' | 'missing' | 'placeholder';
|
|
247
247
|
interface ImageUris {
|
|
248
248
|
art_crop: string;
|
|
249
249
|
border_crop: string;
|
|
@@ -265,14 +265,14 @@ interface Prices {
|
|
|
265
265
|
usd_etched?: Nullable<string>;
|
|
266
266
|
usd_foil?: Nullable<string>;
|
|
267
267
|
}
|
|
268
|
-
type PromoType = '
|
|
268
|
+
type PromoType = 'arenaleague' | 'buyabox' | 'convention' | 'datestamped' | 'draftweekend' | 'duels' | 'event' | 'fnm' | 'gameday' | 'gateway' | 'giftbox' | 'instore' | 'intropack' | 'judgegift' | 'league' | 'openhouse' | 'ourney' | 'planeswalkerdeck' | 'playerrewards' | 'premiereshop' | 'prerelease' | 'release' | 'setpromo' | 'starterdeck' | 'wizardsplaynetwork';
|
|
269
269
|
interface PurchaseUris {
|
|
270
270
|
[key: string]: Nullable<string>;
|
|
271
271
|
cardhoarder?: Nullable<string>;
|
|
272
272
|
cardmarket?: Nullable<string>;
|
|
273
273
|
tcgplayer?: Nullable<string>;
|
|
274
274
|
}
|
|
275
|
-
type Rarity = '
|
|
275
|
+
type Rarity = 'bonus' | 'common' | 'mythic' | 'rare' | 'special' | 'uncommon';
|
|
276
276
|
interface RelatedUris {
|
|
277
277
|
[key: string]: Nullable<string>;
|
|
278
278
|
edhrec?: Nullable<string>;
|
|
@@ -282,7 +282,7 @@ interface RelatedUris {
|
|
|
282
282
|
tcgplayer_infinite_articles?: Nullable<string>;
|
|
283
283
|
tcgplayer_infinite_decks?: Nullable<string>;
|
|
284
284
|
}
|
|
285
|
-
type SecurityStamp = '
|
|
285
|
+
type SecurityStamp = 'acorn' | 'arena' | 'circle' | 'heart' | 'oval' | 'triangle';
|
|
286
286
|
interface CardPrint {
|
|
287
287
|
artist?: Nullable<string>;
|
|
288
288
|
artist_ids?: Nullable<string[]>;
|
|
@@ -332,14 +332,14 @@ interface CardPrint {
|
|
|
332
332
|
watermark?: Nullable<string>;
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
type Card = CardCore &
|
|
335
|
+
type Card = CardCore & CardPrint & GameplayCard;
|
|
336
336
|
|
|
337
|
-
type CardSearchUnique = '
|
|
338
|
-
type CardSearchOrder = '
|
|
339
|
-
type
|
|
340
|
-
type CardSearchFormat = '
|
|
337
|
+
type CardSearchUnique = 'art' | 'cards' | 'prints';
|
|
338
|
+
type CardSearchOrder = 'artist' | 'cmc' | 'color' | 'edhrec' | 'eur' | 'name' | 'penny' | 'power' | 'rarity' | 'released' | 'review' | 'set' | 'tix' | 'toughness' | 'usd';
|
|
339
|
+
type CardSearchDirection = 'asc' | 'auto' | 'desc';
|
|
340
|
+
type CardSearchFormat = 'csv' | 'json';
|
|
341
341
|
interface CardSearch {
|
|
342
|
-
dir?:
|
|
342
|
+
dir?: CardSearchDirection;
|
|
343
343
|
format?: CardSearchFormat;
|
|
344
344
|
include_extras?: boolean;
|
|
345
345
|
include_multilingual?: boolean;
|
|
@@ -361,7 +361,7 @@ declare class CardApi {
|
|
|
361
361
|
bySet(setCode: string, collectorNumber: number, lang?: string): Promise<Card | undefined>;
|
|
362
362
|
byTcgPlayerId(id: number): Promise<Card | undefined>;
|
|
363
363
|
collection(...identifiers: CardIdentifier[]): Promise<Card[]>;
|
|
364
|
-
random(): Promise<Card
|
|
364
|
+
random(): Promise<Card>;
|
|
365
365
|
search(query: string, options?: CardSearch | number): MagicPageResult<Card>;
|
|
366
366
|
}
|
|
367
367
|
declare const cards: CardApi;
|
|
@@ -413,12 +413,12 @@ declare class InvalidScryfallArgumentError extends Error {
|
|
|
413
413
|
declare class ScryfallError extends Error {
|
|
414
414
|
readonly code: string;
|
|
415
415
|
readonly status: number;
|
|
416
|
-
readonly type?:
|
|
417
|
-
readonly warnings?: string[] |
|
|
418
|
-
constructor(code: string, details: string, status: number, type?:
|
|
416
|
+
readonly type?: null | string | undefined;
|
|
417
|
+
readonly warnings?: null | string[] | undefined;
|
|
418
|
+
constructor(code: string, details: string, status: number, type?: null | string | undefined, warnings?: null | string[] | undefined);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
declare class UnknownScryfallError extends Error {
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
export { type Card, type CardIdentifier, CardIdentifierApi as CardIdentifierBuilder, type CardIdentifierCollectorSet, type CardIdentifierId, type CardIdentifierIllustrationId, type CardIdentifierMtgGoId, type CardIdentifierMultiverseId, type CardIdentifierNameSet, type CardIdentifierOracleId, type CardSearch, type
|
|
424
|
+
export { type Card, type CardIdentifier, CardIdentifierApi as CardIdentifierBuilder, type CardIdentifierCollectorSet, type CardIdentifierId, type CardIdentifierIllustrationId, type CardIdentifierMtgGoId, type CardIdentifierMultiverseId, type CardIdentifierNameSet, type CardIdentifierOracleId, type CardSearch, type CardSearchDirection, type CardSearchFormat, type CardSearchOrder, type CardSearchUnique, cards as Cards, type Catalog, catalog as Catalogs, type Color, InvalidScryfallArgumentError, MagicPageResult, type ManaCost, type Ruling, rulings as Rulings, ScryfallError, type Set, type SetType, set as Sets, type Symbology, symbology as SymbologyApi, UnknownScryfallError };
|
package/dist/scryfall-api.js
CHANGED
|
@@ -37,68 +37,12 @@ async function debounce() {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
function createDebounceFetcher(fetcher2 = fetch) {
|
|
40
|
-
return async function debounceFetcher(...
|
|
40
|
+
return async function debounceFetcher(...arguments_) {
|
|
41
41
|
await debounce();
|
|
42
|
-
return fetcher2(...
|
|
42
|
+
return fetcher2(...arguments_);
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// src/fetcher/page.result.ts
|
|
47
|
-
var MagicPageResult = class {
|
|
48
|
-
constructor(apiPath, query) {
|
|
49
|
-
this.apiPath = apiPath;
|
|
50
|
-
this.query = query;
|
|
51
|
-
this.#hasMore = true;
|
|
52
|
-
this.#count = 0;
|
|
53
|
-
}
|
|
54
|
-
#count;
|
|
55
|
-
#hasMore;
|
|
56
|
-
get count() {
|
|
57
|
-
return this.#count;
|
|
58
|
-
}
|
|
59
|
-
get hasMore() {
|
|
60
|
-
return this.#hasMore;
|
|
61
|
-
}
|
|
62
|
-
async all() {
|
|
63
|
-
const r = [];
|
|
64
|
-
while (this.#hasMore) {
|
|
65
|
-
const result = await this.next();
|
|
66
|
-
r.push(...result);
|
|
67
|
-
}
|
|
68
|
-
return r;
|
|
69
|
-
}
|
|
70
|
-
async get(limit) {
|
|
71
|
-
const r = [];
|
|
72
|
-
while (this.#hasMore) {
|
|
73
|
-
const result = await this.next();
|
|
74
|
-
r.push(...result);
|
|
75
|
-
if (r.length === limit) {
|
|
76
|
-
return r;
|
|
77
|
-
}
|
|
78
|
-
if (r.length > limit) {
|
|
79
|
-
return r.slice(0, limit);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return r;
|
|
83
|
-
}
|
|
84
|
-
async next() {
|
|
85
|
-
const results = await fetcher(this.apiPath, this.query);
|
|
86
|
-
this.#hasMore = results?.has_more ?? false;
|
|
87
|
-
this.#count = Number.parseInt(`${results?.total_cards ?? 0}`, 10);
|
|
88
|
-
if (this.#hasMore) {
|
|
89
|
-
this.setNextPage();
|
|
90
|
-
}
|
|
91
|
-
return results?.data ?? [];
|
|
92
|
-
}
|
|
93
|
-
async page(page) {
|
|
94
|
-
this.query.page = page;
|
|
95
|
-
return this.next();
|
|
96
|
-
}
|
|
97
|
-
setNextPage() {
|
|
98
|
-
this.query.page += 1;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
46
|
// src/fetcher/retry.fetcher.ts
|
|
103
47
|
var defaultCanRetry = async (response) => {
|
|
104
48
|
const object = await response.json();
|
|
@@ -109,11 +53,11 @@ var defaultCanRetry = async (response) => {
|
|
|
109
53
|
const code = "code" in object && typeof object.code === "string" ? object.code : void 0;
|
|
110
54
|
return code !== "not_found" && code !== "bad_request";
|
|
111
55
|
};
|
|
112
|
-
function createRetryFetcher({
|
|
56
|
+
function createRetryFetcher({ canRetry = defaultCanRetry, maxAttempts = 3 } = {}, fetcher2 = fetch) {
|
|
113
57
|
let retries = 0;
|
|
114
|
-
return async function retryFetcher(...
|
|
58
|
+
return async function retryFetcher(...arguments_) {
|
|
115
59
|
retries++;
|
|
116
|
-
const response = await fetcher2(...
|
|
60
|
+
const response = await fetcher2(...arguments_);
|
|
117
61
|
if (response.ok) {
|
|
118
62
|
return response;
|
|
119
63
|
}
|
|
@@ -127,44 +71,42 @@ function createRetryFetcher({ maxAttempts = 3, canRetry = defaultCanRetry } = {}
|
|
|
127
71
|
if (code && details && status) {
|
|
128
72
|
throw new ScryfallError(code, details, status, type, warnings);
|
|
129
73
|
}
|
|
130
|
-
throw new UnknownScryfallError(`Request failed with status ${response.status}`);
|
|
74
|
+
throw new UnknownScryfallError(`Request failed with status ${response.status.toFixed(0)}`);
|
|
131
75
|
}
|
|
132
76
|
if (canRetry(response)) {
|
|
133
|
-
return retryFetcher(...
|
|
77
|
+
return retryFetcher(...arguments_);
|
|
134
78
|
}
|
|
135
79
|
if (code && details && status) {
|
|
136
80
|
throw new ScryfallError(code, details, status, type, warnings);
|
|
137
81
|
}
|
|
138
|
-
throw new UnknownScryfallError(`Request failed with status ${response.status}`);
|
|
82
|
+
throw new UnknownScryfallError(`Request failed with status ${response.status.toFixed(0)}`);
|
|
139
83
|
};
|
|
140
84
|
}
|
|
141
85
|
|
|
142
|
-
// src/fetcher/
|
|
86
|
+
// src/fetcher/fetcher.ts
|
|
143
87
|
var simpleFetcher = createDebounceFetcher(createRetryFetcher());
|
|
144
88
|
var endpoint = "https://api.scryfall.com";
|
|
145
89
|
var DATE_REGEXP = /^\d{4}-\d{2}-\d{2}?$/;
|
|
146
90
|
var dateParser = (_key, value) => {
|
|
147
|
-
if (typeof value === "string") {
|
|
148
|
-
|
|
149
|
-
return new Date(value);
|
|
150
|
-
}
|
|
91
|
+
if (typeof value === "string" && DATE_REGEXP.test(value)) {
|
|
92
|
+
return new Date(value);
|
|
151
93
|
}
|
|
152
94
|
return value;
|
|
153
95
|
};
|
|
154
|
-
async function fetcher(apiPath,
|
|
96
|
+
async function fetcher(apiPath, parameters, body) {
|
|
155
97
|
let path = "";
|
|
156
98
|
if (typeof apiPath === "number" || typeof apiPath === "string") {
|
|
157
99
|
path = apiPath;
|
|
158
100
|
} else if (apiPath) {
|
|
159
101
|
path = apiPath.join("/");
|
|
160
102
|
}
|
|
161
|
-
const url = new URL(`${endpoint}/${path}`);
|
|
162
|
-
if (
|
|
163
|
-
|
|
103
|
+
const url = new URL(`${endpoint}/${String(path)}`);
|
|
104
|
+
if (parameters) {
|
|
105
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
164
106
|
if (value !== void 0) {
|
|
165
|
-
url.searchParams.append(key,
|
|
107
|
+
url.searchParams.append(key, value.toString());
|
|
166
108
|
}
|
|
167
|
-
}
|
|
109
|
+
}
|
|
168
110
|
}
|
|
169
111
|
try {
|
|
170
112
|
const init = {
|
|
@@ -179,19 +121,75 @@ async function fetcher(apiPath, params, body) {
|
|
|
179
121
|
const response = await simpleFetcher(url, init);
|
|
180
122
|
const content = await response.text();
|
|
181
123
|
return JSON.parse(content, dateParser);
|
|
182
|
-
} catch (
|
|
183
|
-
if (
|
|
184
|
-
if (
|
|
185
|
-
console.warn(
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof ScryfallError) {
|
|
126
|
+
if (error.warnings) {
|
|
127
|
+
console.warn(error.warnings);
|
|
186
128
|
}
|
|
187
|
-
if (
|
|
129
|
+
if (error.code === "not_found" || error.code === "bad_request") {
|
|
188
130
|
return void 0;
|
|
189
131
|
}
|
|
190
132
|
}
|
|
191
|
-
throw
|
|
133
|
+
throw error;
|
|
192
134
|
}
|
|
193
135
|
}
|
|
194
136
|
|
|
137
|
+
// src/fetcher/page.result.ts
|
|
138
|
+
var MagicPageResult = class {
|
|
139
|
+
constructor(apiPath, query) {
|
|
140
|
+
this.apiPath = apiPath;
|
|
141
|
+
this.query = query;
|
|
142
|
+
this.#hasMore = true;
|
|
143
|
+
this.#count = 0;
|
|
144
|
+
}
|
|
145
|
+
#count;
|
|
146
|
+
#hasMore;
|
|
147
|
+
get count() {
|
|
148
|
+
return this.#count;
|
|
149
|
+
}
|
|
150
|
+
get hasMore() {
|
|
151
|
+
return this.#hasMore;
|
|
152
|
+
}
|
|
153
|
+
async all() {
|
|
154
|
+
const r = [];
|
|
155
|
+
while (this.#hasMore) {
|
|
156
|
+
const result = await this.next();
|
|
157
|
+
r.push(...result);
|
|
158
|
+
}
|
|
159
|
+
return r;
|
|
160
|
+
}
|
|
161
|
+
async get(limit) {
|
|
162
|
+
const r = [];
|
|
163
|
+
while (this.#hasMore) {
|
|
164
|
+
const result = await this.next();
|
|
165
|
+
r.push(...result);
|
|
166
|
+
if (r.length === limit) {
|
|
167
|
+
return r;
|
|
168
|
+
}
|
|
169
|
+
if (r.length > limit) {
|
|
170
|
+
return r.slice(0, limit);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return r;
|
|
174
|
+
}
|
|
175
|
+
async next() {
|
|
176
|
+
const results = await fetcher(this.apiPath, this.query);
|
|
177
|
+
this.#hasMore = results?.has_more ?? false;
|
|
178
|
+
this.#count = Number.parseInt(results?.total_cards?.toFixed(0) ?? "0", 10);
|
|
179
|
+
if (this.#hasMore) {
|
|
180
|
+
this.setNextPage();
|
|
181
|
+
}
|
|
182
|
+
return results?.data ?? [];
|
|
183
|
+
}
|
|
184
|
+
async page(page) {
|
|
185
|
+
this.query.page = page;
|
|
186
|
+
return this.next();
|
|
187
|
+
}
|
|
188
|
+
setNextPage() {
|
|
189
|
+
this.query.page += 1;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
195
193
|
// src/api/card/card.api.ts
|
|
196
194
|
var CardApi = class {
|
|
197
195
|
/*
|
|
@@ -257,8 +255,8 @@ var CardApi = class {
|
|
|
257
255
|
}
|
|
258
256
|
async collection(...identifiers) {
|
|
259
257
|
const cards2 = [];
|
|
260
|
-
for (let
|
|
261
|
-
const collectionSection = { identifiers: identifiers.slice(
|
|
258
|
+
for (let index = 0; index < identifiers.length; index += 75) {
|
|
259
|
+
const collectionSection = { identifiers: identifiers.slice(index, index + 75) };
|
|
262
260
|
const result = await fetcher(
|
|
263
261
|
"cards/collection",
|
|
264
262
|
void 0,
|
|
@@ -281,9 +279,6 @@ var CardApi = class {
|
|
|
281
279
|
var cards = new CardApi();
|
|
282
280
|
var card_api_default = cards;
|
|
283
281
|
|
|
284
|
-
// src/api/card/index.ts
|
|
285
|
-
var card_default = card_api_default;
|
|
286
|
-
|
|
287
282
|
// src/api/card-identifier/card-identifier.api.ts
|
|
288
283
|
var CardIdentifierApi = class {
|
|
289
284
|
static byId(id) {
|
|
@@ -308,85 +303,94 @@ var CardIdentifierApi = class {
|
|
|
308
303
|
return { oracle_id: id };
|
|
309
304
|
}
|
|
310
305
|
static bySet(set2, collectorNumber) {
|
|
311
|
-
return { collector_number:
|
|
306
|
+
return { collector_number: String(collectorNumber), set: set2 };
|
|
312
307
|
}
|
|
313
308
|
};
|
|
314
309
|
|
|
315
|
-
// src/api/card-identifier/index.ts
|
|
316
|
-
var card_identifier_default = CardIdentifierApi;
|
|
317
|
-
|
|
318
310
|
// src/api/catalog/catalog.api.ts
|
|
319
311
|
var CatalogApi = class {
|
|
320
312
|
async artifactTypes() {
|
|
321
|
-
|
|
313
|
+
const response = await fetcher("catalog/artifact-types");
|
|
314
|
+
return response?.data ?? [];
|
|
322
315
|
}
|
|
323
316
|
async artistNames() {
|
|
324
|
-
|
|
317
|
+
const response = await fetcher("catalog/artist-names");
|
|
318
|
+
return response?.data ?? [];
|
|
325
319
|
}
|
|
326
320
|
async cardNames() {
|
|
327
|
-
|
|
321
|
+
const response = await fetcher("catalog/card-names");
|
|
322
|
+
return response?.data ?? [];
|
|
328
323
|
}
|
|
329
324
|
async creatureTypes() {
|
|
330
|
-
|
|
325
|
+
const response = await fetcher("catalog/creature-types");
|
|
326
|
+
return response?.data ?? [];
|
|
331
327
|
}
|
|
332
328
|
async enchantmentTypes() {
|
|
333
|
-
|
|
329
|
+
const response = await fetcher("catalog/enchantment-types");
|
|
330
|
+
return response?.data ?? [];
|
|
334
331
|
}
|
|
335
332
|
async landTypes() {
|
|
336
|
-
|
|
333
|
+
const response = await fetcher("catalog/land-types");
|
|
334
|
+
return response?.data ?? [];
|
|
337
335
|
}
|
|
338
336
|
async loyalties() {
|
|
339
|
-
|
|
337
|
+
const response = await fetcher("catalog/loyalties");
|
|
338
|
+
return response?.data ?? [];
|
|
340
339
|
}
|
|
341
340
|
async planeswalkerTypes() {
|
|
342
|
-
|
|
341
|
+
const response = await fetcher("catalog/planeswalker-types");
|
|
342
|
+
return response?.data ?? [];
|
|
343
343
|
}
|
|
344
344
|
async powers() {
|
|
345
|
-
|
|
345
|
+
const response = await fetcher("catalog/powers");
|
|
346
|
+
return response?.data ?? [];
|
|
346
347
|
}
|
|
347
348
|
async spellTypes() {
|
|
348
|
-
|
|
349
|
+
const response = await fetcher("catalog/spell-types");
|
|
350
|
+
return response?.data ?? [];
|
|
349
351
|
}
|
|
350
352
|
async toughnesses() {
|
|
351
|
-
|
|
353
|
+
const response = await fetcher("catalog/toughnesses");
|
|
354
|
+
return response?.data ?? [];
|
|
352
355
|
}
|
|
353
356
|
async watermarks() {
|
|
354
|
-
|
|
357
|
+
const response = await fetcher("catalog/watermarks");
|
|
358
|
+
return response?.data ?? [];
|
|
355
359
|
}
|
|
356
360
|
async wordBank() {
|
|
357
|
-
|
|
361
|
+
const response = await fetcher("catalog/word-bank");
|
|
362
|
+
return response?.data ?? [];
|
|
358
363
|
}
|
|
359
364
|
};
|
|
360
365
|
var catalog = new CatalogApi();
|
|
361
366
|
var catalog_api_default = catalog;
|
|
362
367
|
|
|
363
|
-
// src/api/catalog/index.ts
|
|
364
|
-
var catalog_default = catalog_api_default;
|
|
365
|
-
|
|
366
368
|
// src/api/ruling/ruling.api.ts
|
|
367
369
|
var RulingApi = class {
|
|
368
370
|
async byArenaId(id) {
|
|
369
|
-
|
|
371
|
+
const response = await fetcher(["cards/arena", id, "rulings"]);
|
|
372
|
+
return response?.data ?? [];
|
|
370
373
|
}
|
|
371
374
|
async byId(id) {
|
|
372
|
-
|
|
375
|
+
const response = await fetcher(["cards", id, "rulings"]);
|
|
376
|
+
return response?.data ?? [];
|
|
373
377
|
}
|
|
374
378
|
async byMtgoId(id) {
|
|
375
|
-
|
|
379
|
+
const response = await fetcher(["cards/mtgo", id, "rulings"]);
|
|
380
|
+
return response?.data ?? [];
|
|
376
381
|
}
|
|
377
382
|
async byMultiverseId(id) {
|
|
378
|
-
|
|
383
|
+
const response = await fetcher(["cards/multiverse", id, "rulings"]);
|
|
384
|
+
return response?.data ?? [];
|
|
379
385
|
}
|
|
380
386
|
async bySet(setCode, collectorNumber) {
|
|
381
|
-
|
|
387
|
+
const response = await fetcher(["cards", setCode, String(collectorNumber), "rulings"]);
|
|
388
|
+
return response?.data ?? [];
|
|
382
389
|
}
|
|
383
390
|
};
|
|
384
391
|
var rulings = new RulingApi();
|
|
385
392
|
var ruling_api_default = rulings;
|
|
386
393
|
|
|
387
|
-
// src/api/ruling/index.ts
|
|
388
|
-
var ruling_default = ruling_api_default;
|
|
389
|
-
|
|
390
394
|
// src/api/set/set.api.ts
|
|
391
395
|
var SetApi = class {
|
|
392
396
|
async all() {
|
|
@@ -406,9 +410,6 @@ var SetApi = class {
|
|
|
406
410
|
var set = new SetApi();
|
|
407
411
|
var set_api_default = set;
|
|
408
412
|
|
|
409
|
-
// src/api/set/index.ts
|
|
410
|
-
var set_default = set_api_default;
|
|
411
|
-
|
|
412
413
|
// src/api/symbology/symbology.api.ts
|
|
413
414
|
var SymbologyApi = class {
|
|
414
415
|
async all() {
|
|
@@ -423,10 +424,10 @@ var SymbologyApi = class {
|
|
|
423
424
|
cost: shorthand
|
|
424
425
|
});
|
|
425
426
|
return cost ?? {
|
|
426
|
-
cost: "",
|
|
427
|
-
colors: [],
|
|
428
427
|
cmc: 0,
|
|
429
428
|
colorless: false,
|
|
429
|
+
colors: [],
|
|
430
|
+
cost: "",
|
|
430
431
|
monocolored: false,
|
|
431
432
|
multicolored: false,
|
|
432
433
|
object: "mana_cost"
|
|
@@ -435,18 +436,15 @@ var SymbologyApi = class {
|
|
|
435
436
|
};
|
|
436
437
|
var symbology = new SymbologyApi();
|
|
437
438
|
var symbology_api_default = symbology;
|
|
438
|
-
|
|
439
|
-
// src/api/symbology/index.ts
|
|
440
|
-
var symbology_default = symbology_api_default;
|
|
441
439
|
export {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
440
|
+
CardIdentifierApi as CardIdentifierBuilder,
|
|
441
|
+
card_api_default as Cards,
|
|
442
|
+
catalog_api_default as Catalogs,
|
|
445
443
|
InvalidScryfallArgumentError,
|
|
446
444
|
MagicPageResult,
|
|
447
|
-
|
|
445
|
+
ruling_api_default as Rulings,
|
|
448
446
|
ScryfallError,
|
|
449
|
-
|
|
450
|
-
|
|
447
|
+
set_api_default as Sets,
|
|
448
|
+
symbology_api_default as SymbologyApi,
|
|
451
449
|
UnknownScryfallError
|
|
452
450
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var v=(s,e)=>{for(var t in e)b(s,t,{get:e[t],enumerable:!0})},D=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!O.call(s,o)&&o!==t&&b(s,o,{get:()=>e[o],enumerable:!(n=q(e,o))||n.enumerable});return s};var Q=s=>D(b({},"__esModule",{value:!0}),s);var Y={};v(Y,{CardIdentifierBuilder:()=>m,Cards:()=>P,Catalogs:()=>T,InvalidScryfallArgumentError:()=>d,MagicPageResult:()=>l,Rulings:()=>S,ScryfallError:()=>u,Sets:()=>L,SymbologyApi:()=>N,UnknownScryfallError:()=>p});module.exports=Q(Y);var d=class extends Error{};var u=class extends Error{constructor(t,n,o,a,c){super(n);this.code=t;this.status=o;this.type=a;this.warnings=c}};var p=class extends Error{};var h=100,j=100;async function z(s=0){return new Promise(e=>{setTimeout(e,s)})}async function $(){let s=Date.now(),e=s-h;if(e>=j)h=s;else{let t=j-e;h+=t,await z(t)}}function w(s=fetch){return async function(...t){return await $(),s(...t)}}var A=async s=>{let e=await s.json(),t="status"in e?Number(e.status):void 0;if(t&&t>=500)return!0;let n="code"in e&&typeof e.code=="string"?e.code:void 0;return n!=="not_found"&&n!=="bad_request"};function x({canRetry:s=A,maxAttempts:e=3}={},t=fetch){let n=0;return async function o(...a){n++;let c=await t(...a);if(c.ok)return c;let i=await c.json(),f="code"in i&&typeof i.code=="string"?i.code:void 0,y="status"in i?Number(i.status):void 0,g="details"in i&&typeof i.details=="string"?i.details:void 0,_="type"in i&&typeof i.type=="string"?i.type:void 0,k="warnings"in i&&Array.isArray(i.warnings)?i.warnings:void 0;if(n>=e)throw f&&g&&y?new u(f,g,y,_,k):new p(`Request failed with status ${c.status.toFixed(0)}`);if(s(c))return o(...a);throw f&&g&&y?new u(f,g,y,_,k):new p(`Request failed with status ${c.status.toFixed(0)}`)}}var U=w(x()),B="https://api.scryfall.com",G=/^\d{4}-\d{2}-\d{2}?$/,J=(s,e)=>typeof e=="string"&&G.test(e)?new Date(e):e;async function r(s,e,t){let n="";typeof s=="number"||typeof s=="string"?n=s:s&&(n=s.join("/"));let o=new URL(`${B}/${String(n)}`);if(e)for(let[a,c]of Object.entries(e))c!==void 0&&o.searchParams.append(a,c.toString());try{let a={method:t?"POST":"GET"};t&&(a.body=JSON.stringify(t),a.headers={"Content-Type":"application/json"});let i=await(await U(o,a)).text();return JSON.parse(i,J)}catch(a){if(a instanceof u&&(a.warnings&&console.warn(a.warnings),a.code==="not_found"||a.code==="bad_request"))return;throw a}}var l=class{constructor(e,t){this.apiPath=e;this.query=t;this.#e=!0,this.#t=0}#t;#e;get count(){return this.#t}get hasMore(){return this.#e}async all(){let e=[];for(;this.#e;){let t=await this.next();e.push(...t)}return e}async get(e){let t=[];for(;this.#e;){let n=await this.next();if(t.push(...n),t.length===e)return t;if(t.length>e)return t.slice(0,e)}return t}async next(){let e=await r(this.apiPath,this.query);return this.#e=e?.has_more??!1,this.#t=Number.parseInt(e?.total_cards?.toFixed(0)??"0",10),this.#e&&this.setNextPage(),e?.data??[]}async page(e){return this.query.page=e,this.next()}setNextPage(){this.query.page+=1}};var C=class{async autoCompleteName(e){return(await r("cards/autocomplete",{q:e}))?.data??[]}async byArenaId(e){return r(["cards/arena",e])}async byId(e){return r(["cards",e])}async byMtgoId(e){return r(["cards/mtgo",e])}async byMultiverseId(e){return r(["cards/multiverse",e])}async byName(e,t,n=!1){let o=n,a=t;return typeof t=="boolean"&&(o=t,a=void 0),r("cards/named",{[o?"fuzzy":"exact"]:e,set:a})}async bySet(e,t,n){let o=["cards",e,t];return n&&o.push(n),r(o)}async byTcgPlayerId(e){return r(["cards/tcgplayer",e])}async collection(...e){let t=[];for(let n=0;n<e.length;n+=75){let o={identifiers:e.slice(n,n+75)},a=await r("cards/collection",void 0,o);t.push(...a?.data??[])}return t}async random(){return r("cards/random")}search(e,t){return new l("cards/search",{q:e,...typeof t=="number"?{page:t}:{...t,page:t?.page??1}})}},V=new C,P=V;var m=class{static byId(e){return{id:e}}static byIllustrationId(e){return{illustration_id:e}}static byMtgoId(e){return{mtgo_id:e}}static byMultiverseId(e){return{multiverse_id:e}}static byName(e,t){return t?{name:e,set:t}:{name:e}}static byOracleId(e){return{oracle_id:e}}static bySet(e,t){return{collector_number:String(t),set:e}}};var R=class{async artifactTypes(){return(await r("catalog/artifact-types"))?.data??[]}async artistNames(){return(await r("catalog/artist-names"))?.data??[]}async cardNames(){return(await r("catalog/card-names"))?.data??[]}async creatureTypes(){return(await r("catalog/creature-types"))?.data??[]}async enchantmentTypes(){return(await r("catalog/enchantment-types"))?.data??[]}async landTypes(){return(await r("catalog/land-types"))?.data??[]}async loyalties(){return(await r("catalog/loyalties"))?.data??[]}async planeswalkerTypes(){return(await r("catalog/planeswalker-types"))?.data??[]}async powers(){return(await r("catalog/powers"))?.data??[]}async spellTypes(){return(await r("catalog/spell-types"))?.data??[]}async toughnesses(){return(await r("catalog/toughnesses"))?.data??[]}async watermarks(){return(await r("catalog/watermarks"))?.data??[]}async wordBank(){return(await r("catalog/word-bank"))?.data??[]}},X=new R,T=X;var I=class{async byArenaId(e){return(await r(["cards/arena",e,"rulings"]))?.data??[]}async byId(e){return(await r(["cards",e,"rulings"]))?.data??[]}async byMtgoId(e){return(await r(["cards/mtgo",e,"rulings"]))?.data??[]}async byMultiverseId(e){return(await r(["cards/multiverse",e,"rulings"]))?.data??[]}async bySet(e,t){return(await r(["cards",e,String(t),"rulings"]))?.data??[]}},H=new I,S=H;var F=class{async all(){return(await r("sets"))?.data??[]}async byCode(e){return await r(["sets",e])}async byId(e){return r(["sets",e])}async byTcgPlayerId(e){return r(["sets/tcgplayer",e])}},K=new F,L=K;var M=class{async all(){return(await r("symbology"))?.data??[]}async parseMana(e){if(!e||typeof e!="string")throw new d("shorthand must be a string");return await r("symbology/parse-mana",{cost:e})??{cmc:0,colorless:!1,colors:[],cost:"",monocolored:!1,multicolored:!1,object:"mana_cost"}}},W=new M,N=W;0&&(module.exports={CardIdentifierBuilder,Cards,Catalogs,InvalidScryfallArgumentError,MagicPageResult,Rulings,ScryfallError,Sets,SymbologyApi,UnknownScryfallError});
|
package/dist/scryfall-api.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=class extends Error{};var u=class extends Error{constructor(t,n,i,a,c){super(n);this.code=t;this.status=i;this.type=a;this.warnings=c}};var p=class extends Error{};var b=100,F=100;async function j(s=0){return new Promise(e=>{setTimeout(e,s)})}async function q(){let s=Date.now(),e=s-b;if(e>=F)b=s;else{let t=F-e;b+=t,await j(t)}}function h(s=fetch){return async function(...t){return await q(),s(...t)}}var E=async s=>{let e=await s.json(),t="status"in e?Number(e.status):void 0;if(t&&t>=500)return!0;let n="code"in e&&typeof e.code=="string"?e.code:void 0;return n!=="not_found"&&n!=="bad_request"};function w({canRetry:s=E,maxAttempts:e=3}={},t=fetch){let n=0;return async function i(...a){n++;let c=await t(...a);if(c.ok)return c;let o=await c.json(),f="code"in o&&typeof o.code=="string"?o.code:void 0,y="status"in o?Number(o.status):void 0,g="details"in o&&typeof o.details=="string"?o.details:void 0,I="type"in o&&typeof o.type=="string"?o.type:void 0,S="warnings"in o&&Array.isArray(o.warnings)?o.warnings:void 0;if(n>=e)throw f&&g&&y?new u(f,g,y,I,S):new p(`Request failed with status ${c.status.toFixed(0)}`);if(s(c))return i(...a);throw f&&g&&y?new u(f,g,y,I,S):new p(`Request failed with status ${c.status.toFixed(0)}`)}}var O=h(w()),v="https://api.scryfall.com",D=/^\d{4}-\d{2}-\d{2}?$/,Q=(s,e)=>typeof e=="string"&&D.test(e)?new Date(e):e;async function r(s,e,t){let n="";typeof s=="number"||typeof s=="string"?n=s:s&&(n=s.join("/"));let i=new URL(`${v}/${String(n)}`);if(e)for(let[a,c]of Object.entries(e))c!==void 0&&i.searchParams.append(a,c.toString());try{let a={method:t?"POST":"GET"};t&&(a.body=JSON.stringify(t),a.headers={"Content-Type":"application/json"});let o=await(await O(i,a)).text();return JSON.parse(o,Q)}catch(a){if(a instanceof u&&(a.warnings&&console.warn(a.warnings),a.code==="not_found"||a.code==="bad_request"))return;throw a}}var l=class{constructor(e,t){this.apiPath=e;this.query=t;this.#e=!0,this.#t=0}#t;#e;get count(){return this.#t}get hasMore(){return this.#e}async all(){let e=[];for(;this.#e;){let t=await this.next();e.push(...t)}return e}async get(e){let t=[];for(;this.#e;){let n=await this.next();if(t.push(...n),t.length===e)return t;if(t.length>e)return t.slice(0,e)}return t}async next(){let e=await r(this.apiPath,this.query);return this.#e=e?.has_more??!1,this.#t=Number.parseInt(e?.total_cards?.toFixed(0)??"0",10),this.#e&&this.setNextPage(),e?.data??[]}async page(e){return this.query.page=e,this.next()}setNextPage(){this.query.page+=1}};var x=class{async autoCompleteName(e){return(await r("cards/autocomplete",{q:e}))?.data??[]}async byArenaId(e){return r(["cards/arena",e])}async byId(e){return r(["cards",e])}async byMtgoId(e){return r(["cards/mtgo",e])}async byMultiverseId(e){return r(["cards/multiverse",e])}async byName(e,t,n=!1){let i=n,a=t;return typeof t=="boolean"&&(i=t,a=void 0),r("cards/named",{[i?"fuzzy":"exact"]:e,set:a})}async bySet(e,t,n){let i=["cards",e,t];return n&&i.push(n),r(i)}async byTcgPlayerId(e){return r(["cards/tcgplayer",e])}async collection(...e){let t=[];for(let n=0;n<e.length;n+=75){let i={identifiers:e.slice(n,n+75)},a=await r("cards/collection",void 0,i);t.push(...a?.data??[])}return t}async random(){return r("cards/random")}search(e,t){return new l("cards/search",{q:e,...typeof t=="number"?{page:t}:{...t,page:t?.page??1}})}},z=new x,L=z;var m=class{static byId(e){return{id:e}}static byIllustrationId(e){return{illustration_id:e}}static byMtgoId(e){return{mtgo_id:e}}static byMultiverseId(e){return{multiverse_id:e}}static byName(e,t){return t?{name:e,set:t}:{name:e}}static byOracleId(e){return{oracle_id:e}}static bySet(e,t){return{collector_number:String(t),set:e}}};var C=class{async artifactTypes(){return(await r("catalog/artifact-types"))?.data??[]}async artistNames(){return(await r("catalog/artist-names"))?.data??[]}async cardNames(){return(await r("catalog/card-names"))?.data??[]}async creatureTypes(){return(await r("catalog/creature-types"))?.data??[]}async enchantmentTypes(){return(await r("catalog/enchantment-types"))?.data??[]}async landTypes(){return(await r("catalog/land-types"))?.data??[]}async loyalties(){return(await r("catalog/loyalties"))?.data??[]}async planeswalkerTypes(){return(await r("catalog/planeswalker-types"))?.data??[]}async powers(){return(await r("catalog/powers"))?.data??[]}async spellTypes(){return(await r("catalog/spell-types"))?.data??[]}async toughnesses(){return(await r("catalog/toughnesses"))?.data??[]}async watermarks(){return(await r("catalog/watermarks"))?.data??[]}async wordBank(){return(await r("catalog/word-bank"))?.data??[]}},$=new C,M=$;var P=class{async byArenaId(e){return(await r(["cards/arena",e,"rulings"]))?.data??[]}async byId(e){return(await r(["cards",e,"rulings"]))?.data??[]}async byMtgoId(e){return(await r(["cards/mtgo",e,"rulings"]))?.data??[]}async byMultiverseId(e){return(await r(["cards/multiverse",e,"rulings"]))?.data??[]}async bySet(e,t){return(await r(["cards",e,String(t),"rulings"]))?.data??[]}},A=new P,N=A;var R=class{async all(){return(await r("sets"))?.data??[]}async byCode(e){return await r(["sets",e])}async byId(e){return r(["sets",e])}async byTcgPlayerId(e){return r(["sets/tcgplayer",e])}},U=new R,_=U;var T=class{async all(){return(await r("symbology"))?.data??[]}async parseMana(e){if(!e||typeof e!="string")throw new d("shorthand must be a string");return await r("symbology/parse-mana",{cost:e})??{cmc:0,colorless:!1,colors:[],cost:"",monocolored:!1,multicolored:!1,object:"mana_cost"}}},B=new T,k=B;export{m as CardIdentifierBuilder,L as Cards,M as Catalogs,d as InvalidScryfallArgumentError,l as MagicPageResult,N as Rulings,u as ScryfallError,_ as Sets,k as SymbologyApi,p as UnknownScryfallError};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scryfall-api",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A Javascript library for https://scryfall.com/docs/api written in Typescript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"magic",
|
|
@@ -15,26 +15,27 @@
|
|
|
15
15
|
"scryfall",
|
|
16
16
|
"scry"
|
|
17
17
|
],
|
|
18
|
-
"homepage": "https://github.com/MarioMH8/scryfall-api",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/MarioMH8/scryfall-api/issues"
|
|
21
|
-
},
|
|
22
18
|
"repository": {
|
|
23
19
|
"type": "git",
|
|
24
20
|
"url": "https://github.com/MarioMH8/scryfall-api"
|
|
25
21
|
},
|
|
22
|
+
"homepage": "https://github.com/MarioMH8/scryfall-api",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/MarioMH8/scryfall-api/issues"
|
|
25
|
+
},
|
|
26
26
|
"license": "MIT",
|
|
27
|
+
"type": "module",
|
|
27
28
|
"files": [
|
|
28
29
|
"dist"
|
|
29
30
|
],
|
|
30
|
-
"
|
|
31
|
+
"main": "./dist/scryfall-api.js",
|
|
31
32
|
"module": "./dist/scryfall-api.js",
|
|
32
33
|
"types": "./dist/scryfall-api.d.ts",
|
|
33
34
|
"exports": {
|
|
34
35
|
".": {
|
|
35
36
|
"types": "./dist/scryfall-api.d.ts",
|
|
36
|
-
"require": "./dist/scryfall-api.cjs",
|
|
37
37
|
"import": "./dist/scryfall-api.js",
|
|
38
|
+
"require": "./dist/scryfall-api.cjs",
|
|
38
39
|
"default": "./dist/scryfall-api.js"
|
|
39
40
|
}
|
|
40
41
|
},
|
|
@@ -47,12 +48,12 @@
|
|
|
47
48
|
"typecheck": "tsc --noEmit"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@changesets/cli": "2.27.
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@types/bun": "1.
|
|
54
|
-
"eslint": "
|
|
55
|
-
"tsup": "8.0
|
|
56
|
-
"typescript": "5.
|
|
51
|
+
"@changesets/cli": "2.27.7",
|
|
52
|
+
"@hexadrop/eslint-config": "0.0.1-beta.14",
|
|
53
|
+
"@hexadrop/tsconfig": "0.0.5",
|
|
54
|
+
"@types/bun": "1.1.6",
|
|
55
|
+
"eslint": "9.6.0",
|
|
56
|
+
"tsup": "8.1.0",
|
|
57
|
+
"typescript": "5.5.3"
|
|
57
58
|
}
|
|
58
59
|
}
|