scryfall-api 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/declarations/dist/src/api/CardIdentifierBuilder.d.ts +10 -0
- package/dist/declarations/dist/src/api/Cards.d.ts +19 -0
- package/dist/declarations/dist/src/api/Catalog.d.ts +18 -0
- package/dist/declarations/dist/src/api/Rulings.d.ts +11 -0
- package/dist/declarations/dist/src/api/Sets.d.ts +10 -0
- package/dist/declarations/dist/src/api/Symbology.d.ts +8 -0
- package/dist/declarations/dist/src/error/MagicQueryError.d.ts +5 -0
- package/dist/declarations/dist/src/index.d.ts +10 -0
- package/dist/declarations/dist/src/query/MagicPageResult.d.ts +18 -0
- package/dist/declarations/dist/src/query/MagicQuery.d.ts +13 -0
- package/dist/declarations/dist/src/types/Border.d.ts +7 -0
- package/dist/declarations/dist/src/types/BulkDataDefinition.d.ts +14 -0
- package/dist/declarations/dist/src/types/BulkDataType.d.ts +2 -0
- package/dist/declarations/dist/src/types/BulkDataTypes.d.ts +7 -0
- package/dist/declarations/dist/src/types/Card.d.ts +91 -0
- package/dist/declarations/dist/src/types/CardFace.d.ts +22 -0
- package/dist/declarations/dist/src/types/CardIdentifier.d.ts +10 -0
- package/dist/declarations/dist/src/types/CardSymbol.d.ts +13 -0
- package/dist/declarations/dist/src/types/Color.d.ts +9 -0
- package/dist/declarations/dist/src/types/Format.d.ts +15 -0
- package/dist/declarations/dist/src/types/FrameEffect.d.ts +17 -0
- package/dist/declarations/dist/src/types/Game.d.ts +5 -0
- package/dist/declarations/dist/src/types/HomepageLink.d.ts +9 -0
- package/dist/declarations/dist/src/types/ImageUris.d.ts +8 -0
- package/dist/declarations/dist/src/types/Layout.d.ts +20 -0
- package/dist/declarations/dist/src/types/Legalties.d.ts +5 -0
- package/dist/declarations/dist/src/types/Legalty.d.ts +6 -0
- package/dist/declarations/dist/src/types/ManaCost.d.ts +9 -0
- package/dist/declarations/dist/src/types/PageQuery.d.ts +5 -0
- package/dist/declarations/dist/src/types/PageQueryValue.d.ts +1 -0
- package/dist/declarations/dist/src/types/Preview.d.ts +5 -0
- package/dist/declarations/dist/src/types/Prices.d.ts +6 -0
- package/dist/declarations/dist/src/types/PromoType.d.ts +27 -0
- package/dist/declarations/dist/src/types/PurchaseUris.d.ts +6 -0
- package/dist/declarations/dist/src/types/Query.d.ts +4 -0
- package/dist/declarations/dist/src/types/Rarity.d.ts +6 -0
- package/dist/declarations/dist/src/types/RelatedCard.d.ts +9 -0
- package/dist/declarations/dist/src/types/RelatedCardComponent.d.ts +6 -0
- package/dist/declarations/dist/src/types/RelatedUris.d.ts +7 -0
- package/dist/declarations/dist/src/types/ResultCatalog.d.ts +2 -0
- package/dist/declarations/dist/src/types/ResultData.d.ts +4 -0
- package/dist/declarations/dist/src/types/ResultList.d.ts +7 -0
- package/dist/declarations/dist/src/types/RetryStrategy.d.ts +11 -0
- package/dist/declarations/dist/src/types/Ruling.d.ts +5 -0
- package/dist/declarations/dist/src/types/SearchError.d.ts +7 -0
- package/dist/declarations/dist/src/types/SearchOptions.d.ts +15 -0
- package/dist/declarations/dist/src/types/Set.d.ts +20 -0
- package/dist/declarations/dist/src/types/SetType.d.ts +22 -0
- package/dist/declarations/dist/src/types/Sort.d.ts +15 -0
- package/dist/declarations/dist/src/types/SortDirection.d.ts +5 -0
- package/dist/declarations/dist/src/types/TOrArrayOfT.d.ts +1 -0
- package/dist/declarations/dist/src/types/UniqueStrategy.d.ts +5 -0
- package/dist/declarations/dist/src/types/index.d.ts +42 -0
- package/dist/scryfall-api.cjs.d.ts +1 -1
- package/dist/scryfall-api.cjs.dev.js +53 -122
- package/dist/scryfall-api.cjs.prod.js +53 -122
- package/dist/scryfall-api.esm.js +54 -122
- package/dist/scryfall-api.umd.min.js +1 -1
- package/dist/scryfall-api.umd.min.js.map +1 -1
- package/package.json +59 -7
- package/CHANGELOG.md +0 -13
- package/DOCUMENTATION.md +0 -505
- package/SUPPORT.md +0 -38
|
@@ -8,24 +8,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
8
8
|
|
|
9
9
|
var Axios__default = /*#__PURE__*/_interopDefault(Axios);
|
|
10
10
|
|
|
11
|
-
function _extends() {
|
|
12
|
-
_extends = Object.assign || function (target) {
|
|
13
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
-
var source = arguments[i];
|
|
15
|
-
|
|
16
|
-
for (var key in source) {
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
18
|
-
target[key] = source[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return target;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return _extends.apply(this, arguments);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
11
|
class MagicPageResult {
|
|
30
12
|
constructor(q, apiPath, query, post) {
|
|
31
13
|
this.q = q;
|
|
@@ -74,14 +56,14 @@ class MagicPageResult {
|
|
|
74
56
|
|
|
75
57
|
async next() {
|
|
76
58
|
const results = await this.q.query(this.apiPath, this.query, this.post);
|
|
77
|
-
this._hasMore =
|
|
78
|
-
this._count = Number.parseInt((
|
|
59
|
+
this._hasMore = results?.has_more || false;
|
|
60
|
+
this._count = Number.parseInt((results?.total_cards || 0) + '');
|
|
79
61
|
|
|
80
62
|
if (this._hasMore) {
|
|
81
63
|
this.setNextPage();
|
|
82
64
|
}
|
|
83
65
|
|
|
84
|
-
return
|
|
66
|
+
return results?.data || [];
|
|
85
67
|
}
|
|
86
68
|
|
|
87
69
|
async page(page) {
|
|
@@ -97,7 +79,7 @@ class MagicPageResult {
|
|
|
97
79
|
|
|
98
80
|
class MagicQueryError extends Error {
|
|
99
81
|
constructor(data) {
|
|
100
|
-
super(data
|
|
82
|
+
super(data?.details);
|
|
101
83
|
this.data = data;
|
|
102
84
|
Object.setPrototypeOf(this, MagicQueryError.prototype);
|
|
103
85
|
}
|
|
@@ -105,12 +87,19 @@ class MagicQueryError extends Error {
|
|
|
105
87
|
}
|
|
106
88
|
|
|
107
89
|
class MagicQuery {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// the
|
|
90
|
+
static retry = {
|
|
91
|
+
attempts: 1
|
|
92
|
+
}; // the path to the api
|
|
93
|
+
|
|
94
|
+
static endpoint = 'https://api.scryfall.com'; // time where the last api call was made
|
|
95
|
+
|
|
96
|
+
static lastQuery = 100; // the api requests 50-100 ms between calls, we go on the generous side and never wait less than 100 ms between calls
|
|
97
|
+
|
|
98
|
+
static rateLimit = 100;
|
|
99
|
+
|
|
111
100
|
static canRetry(error) {
|
|
112
|
-
if (
|
|
113
|
-
return !MagicQuery.retry.canRetry
|
|
101
|
+
if (error?.code == 'not_found' || error?.code == 'bad_request') return false;
|
|
102
|
+
return !MagicQuery.retry.canRetry ;
|
|
114
103
|
}
|
|
115
104
|
|
|
116
105
|
static async debounce() {
|
|
@@ -132,22 +121,20 @@ class MagicQuery {
|
|
|
132
121
|
|
|
133
122
|
static async tryQuery(apiPath, query, post, requestOptions) {
|
|
134
123
|
await MagicQuery.debounce();
|
|
135
|
-
|
|
136
|
-
const config = _extends({
|
|
124
|
+
const config = {
|
|
137
125
|
data: post,
|
|
138
126
|
method: post ? 'POST' : 'GET',
|
|
139
127
|
params: query,
|
|
140
|
-
url: `${MagicQuery.endpoint}/${apiPath}
|
|
141
|
-
|
|
128
|
+
url: `${MagicQuery.endpoint}/${apiPath}`,
|
|
129
|
+
...requestOptions
|
|
130
|
+
};
|
|
142
131
|
|
|
143
132
|
try {
|
|
144
133
|
return await Axios__default["default"].request(config);
|
|
145
134
|
} catch (e) {
|
|
146
135
|
if (e['isAxiosError']) {
|
|
147
|
-
var _error$response;
|
|
148
|
-
|
|
149
136
|
const error = e;
|
|
150
|
-
throw new MagicQueryError(
|
|
137
|
+
throw new MagicQueryError(error.response?.data);
|
|
151
138
|
} else {
|
|
152
139
|
throw e;
|
|
153
140
|
}
|
|
@@ -155,8 +142,6 @@ class MagicQuery {
|
|
|
155
142
|
}
|
|
156
143
|
|
|
157
144
|
async query(apiPath, query, post, requestOptions) {
|
|
158
|
-
var _result;
|
|
159
|
-
|
|
160
145
|
if (Array.isArray(apiPath)) {
|
|
161
146
|
apiPath = apiPath.join('/');
|
|
162
147
|
}
|
|
@@ -181,23 +166,17 @@ class MagicQuery {
|
|
|
181
166
|
await MagicQuery.sleep(MagicQuery.retry.timeout);
|
|
182
167
|
}
|
|
183
168
|
|
|
184
|
-
return
|
|
169
|
+
return result?.data;
|
|
185
170
|
}
|
|
186
171
|
|
|
187
172
|
}
|
|
188
|
-
MagicQuery.retry = {
|
|
189
|
-
attempts: 1
|
|
190
|
-
};
|
|
191
|
-
MagicQuery.endpoint = 'https://api.scryfall.com';
|
|
192
|
-
MagicQuery.lastQuery = 100;
|
|
193
|
-
MagicQuery.rateLimit = 100;
|
|
194
173
|
|
|
195
174
|
class Cards extends MagicQuery {
|
|
196
175
|
async autoCompleteName(name) {
|
|
197
176
|
const result = await this.query('cards/autocomplete', {
|
|
198
177
|
q: name
|
|
199
178
|
});
|
|
200
|
-
return
|
|
179
|
+
return result?.data || [];
|
|
201
180
|
}
|
|
202
181
|
|
|
203
182
|
async byArenaId(id) {
|
|
@@ -248,7 +227,7 @@ class Cards extends MagicQuery {
|
|
|
248
227
|
identifiers: identifiers.slice(i, i + 75)
|
|
249
228
|
};
|
|
250
229
|
const result = await this.query('cards/collection', undefined, collectionSection);
|
|
251
|
-
cards.push(...(
|
|
230
|
+
cards.push(...(result?.data || []));
|
|
252
231
|
}
|
|
253
232
|
|
|
254
233
|
return cards;
|
|
@@ -259,13 +238,15 @@ class Cards extends MagicQuery {
|
|
|
259
238
|
}
|
|
260
239
|
|
|
261
240
|
search(query, options) {
|
|
262
|
-
return new MagicPageResult(this, 'cards/search',
|
|
263
|
-
q: query
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
241
|
+
return new MagicPageResult(this, 'cards/search', {
|
|
242
|
+
q: query,
|
|
243
|
+
...(typeof options === 'number' ? {
|
|
244
|
+
page: options
|
|
245
|
+
} : {
|
|
246
|
+
page: 1,
|
|
247
|
+
...options
|
|
248
|
+
})
|
|
249
|
+
});
|
|
269
250
|
}
|
|
270
251
|
|
|
271
252
|
}
|
|
@@ -274,127 +255,80 @@ var Cards$1 = new Cards();
|
|
|
274
255
|
|
|
275
256
|
class Catalog extends MagicQuery {
|
|
276
257
|
async artifactTypes() {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return ((_await$this$query = await this.query('catalog/artifact-types')) == null ? void 0 : _await$this$query.data) || [];
|
|
258
|
+
return (await this.query('catalog/artifact-types'))?.data || [];
|
|
280
259
|
}
|
|
281
260
|
|
|
282
261
|
async artistNames() {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return ((_await$this$query2 = await this.query('catalog/artist-names')) == null ? void 0 : _await$this$query2.data) || [];
|
|
262
|
+
return (await this.query('catalog/artist-names'))?.data || [];
|
|
286
263
|
}
|
|
287
264
|
|
|
288
265
|
async cardNames() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return ((_await$this$query3 = await this.query('catalog/card-names')) == null ? void 0 : _await$this$query3.data) || [];
|
|
266
|
+
return (await this.query('catalog/card-names'))?.data || [];
|
|
292
267
|
}
|
|
293
268
|
|
|
294
269
|
async creatureTypes() {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return ((_await$this$query4 = await this.query('catalog/creature-types')) == null ? void 0 : _await$this$query4.data) || [];
|
|
270
|
+
return (await this.query('catalog/creature-types'))?.data || [];
|
|
298
271
|
}
|
|
299
272
|
|
|
300
273
|
async enchantmentTypes() {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return ((_await$this$query5 = await this.query('catalog/enchantment-types')) == null ? void 0 : _await$this$query5.data) || [];
|
|
274
|
+
return (await this.query('catalog/enchantment-types'))?.data || [];
|
|
304
275
|
}
|
|
305
276
|
|
|
306
277
|
async landTypes() {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return ((_await$this$query6 = await this.query('catalog/land-types')) == null ? void 0 : _await$this$query6.data) || [];
|
|
278
|
+
return (await this.query('catalog/land-types'))?.data || [];
|
|
310
279
|
}
|
|
311
280
|
|
|
312
281
|
async loyalties() {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return ((_await$this$query7 = await this.query('catalog/loyalties')) == null ? void 0 : _await$this$query7.data) || [];
|
|
282
|
+
return (await this.query('catalog/loyalties'))?.data || [];
|
|
316
283
|
}
|
|
317
284
|
|
|
318
285
|
async planeswalkerTypes() {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return ((_await$this$query8 = await this.query('catalog/planeswalker-types')) == null ? void 0 : _await$this$query8.data) || [];
|
|
286
|
+
return (await this.query('catalog/planeswalker-types'))?.data || [];
|
|
322
287
|
}
|
|
323
288
|
|
|
324
289
|
async powers() {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return ((_await$this$query9 = await this.query('catalog/powers')) == null ? void 0 : _await$this$query9.data) || [];
|
|
290
|
+
return (await this.query('catalog/powers'))?.data || [];
|
|
328
291
|
}
|
|
329
292
|
|
|
330
293
|
async spellTypes() {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return ((_await$this$query10 = await this.query('catalog/spell-types')) == null ? void 0 : _await$this$query10.data) || [];
|
|
294
|
+
return (await this.query('catalog/spell-types'))?.data || [];
|
|
334
295
|
}
|
|
335
296
|
|
|
336
297
|
async toughnesses() {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return ((_await$this$query11 = await this.query('catalog/toughnesses')) == null ? void 0 : _await$this$query11.data) || [];
|
|
298
|
+
return (await this.query('catalog/toughnesses'))?.data || [];
|
|
340
299
|
}
|
|
341
300
|
|
|
342
301
|
async watermarks() {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return ((_await$this$query12 = await this.query('catalog/watermarks')) == null ? void 0 : _await$this$query12.data) || [];
|
|
302
|
+
return (await this.query('catalog/watermarks'))?.data || [];
|
|
346
303
|
}
|
|
347
304
|
|
|
348
305
|
async wordBank() {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return ((_await$this$query13 = await this.query('catalog/word-bank')) == null ? void 0 : _await$this$query13.data) || [];
|
|
306
|
+
return (await this.query('catalog/word-bank'))?.data || [];
|
|
352
307
|
}
|
|
353
308
|
|
|
354
309
|
}
|
|
355
310
|
|
|
356
311
|
var Catalog$1 = new Catalog();
|
|
357
312
|
|
|
358
|
-
class Misc extends MagicQuery {
|
|
359
|
-
async homepageLinks() {
|
|
360
|
-
var _await$this$query;
|
|
361
|
-
|
|
362
|
-
return ((_await$this$query = await this.query('homepage-links')) == null ? void 0 : _await$this$query.data) || [];
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
var Misc$1 = new Misc();
|
|
368
|
-
|
|
369
313
|
class Rulings extends MagicQuery {
|
|
370
314
|
async byArenaId(id) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return ((_await$this$query = await this.query(['cards/arena', id, 'rulings'])) == null ? void 0 : _await$this$query.data) || [];
|
|
315
|
+
return (await this.query(['cards/arena', id, 'rulings']))?.data || [];
|
|
374
316
|
}
|
|
375
317
|
|
|
376
318
|
async byId(id) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return ((_await$this$query2 = await this.query(['cards', id, 'rulings'])) == null ? void 0 : _await$this$query2.data) || [];
|
|
319
|
+
return (await this.query(['cards', id, 'rulings']))?.data || [];
|
|
380
320
|
}
|
|
381
321
|
|
|
382
322
|
async byMtgoId(id) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
return ((_await$this$query3 = await this.query(['cards/mtgo', id, 'rulings'])) == null ? void 0 : _await$this$query3.data) || [];
|
|
323
|
+
return (await this.query(['cards/mtgo', id, 'rulings']))?.data || [];
|
|
386
324
|
}
|
|
387
325
|
|
|
388
326
|
async byMultiverseId(id) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return ((_await$this$query4 = await this.query(['cards/multiverse', id, 'rulings'])) == null ? void 0 : _await$this$query4.data) || [];
|
|
327
|
+
return (await this.query(['cards/multiverse', id, 'rulings']))?.data || [];
|
|
392
328
|
}
|
|
393
329
|
|
|
394
330
|
async bySet(setCode, collectorNumber) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return ((_await$this$query5 = await this.query(['cards', setCode, `${collectorNumber}`, 'rulings'])) == null ? void 0 : _await$this$query5.data) || [];
|
|
331
|
+
return (await this.query(['cards', setCode, `${collectorNumber}`, 'rulings']))?.data || [];
|
|
398
332
|
}
|
|
399
333
|
|
|
400
334
|
}
|
|
@@ -404,7 +338,7 @@ var Rulings$1 = new Rulings();
|
|
|
404
338
|
class Sets extends MagicQuery {
|
|
405
339
|
async all() {
|
|
406
340
|
const result = await this.query('sets');
|
|
407
|
-
return
|
|
341
|
+
return result?.data || [];
|
|
408
342
|
}
|
|
409
343
|
|
|
410
344
|
async byCode(code) {
|
|
@@ -425,9 +359,7 @@ var Sets$1 = new Sets();
|
|
|
425
359
|
|
|
426
360
|
class Symbology extends MagicQuery {
|
|
427
361
|
async all() {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return ((_await$this$query = await this.query('symbology')) == null ? void 0 : _await$this$query.data) || [];
|
|
362
|
+
return (await this.query('symbology'))?.data || [];
|
|
431
363
|
}
|
|
432
364
|
|
|
433
365
|
async parseMana(shorthand) {
|
|
@@ -706,7 +638,6 @@ exports.CardIdentifierBuilder = CardIdentifierBuilder;
|
|
|
706
638
|
exports.Cards = Cards$1;
|
|
707
639
|
exports.Catalog = Catalog$1;
|
|
708
640
|
exports.MagicQueryError = MagicQueryError;
|
|
709
|
-
exports.Misc = Misc$1;
|
|
710
641
|
exports.Rulings = Rulings$1;
|
|
711
642
|
exports.Sets = Sets$1;
|
|
712
643
|
exports.Symbology = Symbology$1;
|
package/dist/scryfall-api.esm.js
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
import Axios from 'axios';
|
|
2
2
|
|
|
3
|
-
function _extends() {
|
|
4
|
-
_extends = Object.assign || function (target) {
|
|
5
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
6
|
-
var source = arguments[i];
|
|
7
|
-
|
|
8
|
-
for (var key in source) {
|
|
9
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
10
|
-
target[key] = source[key];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return target;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return _extends.apply(this, arguments);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
3
|
class MagicPageResult {
|
|
22
4
|
constructor(q, apiPath, query, post) {
|
|
23
5
|
this.q = q;
|
|
@@ -66,14 +48,14 @@ class MagicPageResult {
|
|
|
66
48
|
|
|
67
49
|
async next() {
|
|
68
50
|
const results = await this.q.query(this.apiPath, this.query, this.post);
|
|
69
|
-
this._hasMore =
|
|
70
|
-
this._count = Number.parseInt((
|
|
51
|
+
this._hasMore = results?.has_more || false;
|
|
52
|
+
this._count = Number.parseInt((results?.total_cards || 0) + '');
|
|
71
53
|
|
|
72
54
|
if (this._hasMore) {
|
|
73
55
|
this.setNextPage();
|
|
74
56
|
}
|
|
75
57
|
|
|
76
|
-
return
|
|
58
|
+
return results?.data || [];
|
|
77
59
|
}
|
|
78
60
|
|
|
79
61
|
async page(page) {
|
|
@@ -89,7 +71,7 @@ class MagicPageResult {
|
|
|
89
71
|
|
|
90
72
|
class MagicQueryError extends Error {
|
|
91
73
|
constructor(data) {
|
|
92
|
-
super(data
|
|
74
|
+
super(data?.details);
|
|
93
75
|
this.data = data;
|
|
94
76
|
Object.setPrototypeOf(this, MagicQueryError.prototype);
|
|
95
77
|
}
|
|
@@ -97,12 +79,19 @@ class MagicQueryError extends Error {
|
|
|
97
79
|
}
|
|
98
80
|
|
|
99
81
|
class MagicQuery {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// the
|
|
82
|
+
static retry = {
|
|
83
|
+
attempts: 1
|
|
84
|
+
}; // the path to the api
|
|
85
|
+
|
|
86
|
+
static endpoint = 'https://api.scryfall.com'; // time where the last api call was made
|
|
87
|
+
|
|
88
|
+
static lastQuery = 100; // the api requests 50-100 ms between calls, we go on the generous side and never wait less than 100 ms between calls
|
|
89
|
+
|
|
90
|
+
static rateLimit = 100;
|
|
91
|
+
|
|
103
92
|
static canRetry(error) {
|
|
104
|
-
if (
|
|
105
|
-
return !MagicQuery.retry.canRetry
|
|
93
|
+
if (error?.code == 'not_found' || error?.code == 'bad_request') return false;
|
|
94
|
+
return !MagicQuery.retry.canRetry ;
|
|
106
95
|
}
|
|
107
96
|
|
|
108
97
|
static async debounce() {
|
|
@@ -124,22 +113,20 @@ class MagicQuery {
|
|
|
124
113
|
|
|
125
114
|
static async tryQuery(apiPath, query, post, requestOptions) {
|
|
126
115
|
await MagicQuery.debounce();
|
|
127
|
-
|
|
128
|
-
const config = _extends({
|
|
116
|
+
const config = {
|
|
129
117
|
data: post,
|
|
130
118
|
method: post ? 'POST' : 'GET',
|
|
131
119
|
params: query,
|
|
132
|
-
url: `${MagicQuery.endpoint}/${apiPath}
|
|
133
|
-
|
|
120
|
+
url: `${MagicQuery.endpoint}/${apiPath}`,
|
|
121
|
+
...requestOptions
|
|
122
|
+
};
|
|
134
123
|
|
|
135
124
|
try {
|
|
136
125
|
return await Axios.request(config);
|
|
137
126
|
} catch (e) {
|
|
138
127
|
if (e['isAxiosError']) {
|
|
139
|
-
var _error$response;
|
|
140
|
-
|
|
141
128
|
const error = e;
|
|
142
|
-
throw new MagicQueryError(
|
|
129
|
+
throw new MagicQueryError(error.response?.data);
|
|
143
130
|
} else {
|
|
144
131
|
throw e;
|
|
145
132
|
}
|
|
@@ -147,8 +134,6 @@ class MagicQuery {
|
|
|
147
134
|
}
|
|
148
135
|
|
|
149
136
|
async query(apiPath, query, post, requestOptions) {
|
|
150
|
-
var _result;
|
|
151
|
-
|
|
152
137
|
if (Array.isArray(apiPath)) {
|
|
153
138
|
apiPath = apiPath.join('/');
|
|
154
139
|
}
|
|
@@ -173,23 +158,17 @@ class MagicQuery {
|
|
|
173
158
|
await MagicQuery.sleep(MagicQuery.retry.timeout);
|
|
174
159
|
}
|
|
175
160
|
|
|
176
|
-
return
|
|
161
|
+
return result?.data;
|
|
177
162
|
}
|
|
178
163
|
|
|
179
164
|
}
|
|
180
|
-
MagicQuery.retry = {
|
|
181
|
-
attempts: 1
|
|
182
|
-
};
|
|
183
|
-
MagicQuery.endpoint = 'https://api.scryfall.com';
|
|
184
|
-
MagicQuery.lastQuery = 100;
|
|
185
|
-
MagicQuery.rateLimit = 100;
|
|
186
165
|
|
|
187
166
|
class Cards extends MagicQuery {
|
|
188
167
|
async autoCompleteName(name) {
|
|
189
168
|
const result = await this.query('cards/autocomplete', {
|
|
190
169
|
q: name
|
|
191
170
|
});
|
|
192
|
-
return
|
|
171
|
+
return result?.data || [];
|
|
193
172
|
}
|
|
194
173
|
|
|
195
174
|
async byArenaId(id) {
|
|
@@ -240,7 +219,7 @@ class Cards extends MagicQuery {
|
|
|
240
219
|
identifiers: identifiers.slice(i, i + 75)
|
|
241
220
|
};
|
|
242
221
|
const result = await this.query('cards/collection', undefined, collectionSection);
|
|
243
|
-
cards.push(...(
|
|
222
|
+
cards.push(...(result?.data || []));
|
|
244
223
|
}
|
|
245
224
|
|
|
246
225
|
return cards;
|
|
@@ -251,13 +230,15 @@ class Cards extends MagicQuery {
|
|
|
251
230
|
}
|
|
252
231
|
|
|
253
232
|
search(query, options) {
|
|
254
|
-
return new MagicPageResult(this, 'cards/search',
|
|
255
|
-
q: query
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
233
|
+
return new MagicPageResult(this, 'cards/search', {
|
|
234
|
+
q: query,
|
|
235
|
+
...(typeof options === 'number' ? {
|
|
236
|
+
page: options
|
|
237
|
+
} : {
|
|
238
|
+
page: 1,
|
|
239
|
+
...options
|
|
240
|
+
})
|
|
241
|
+
});
|
|
261
242
|
}
|
|
262
243
|
|
|
263
244
|
}
|
|
@@ -266,127 +247,80 @@ var Cards$1 = new Cards();
|
|
|
266
247
|
|
|
267
248
|
class Catalog extends MagicQuery {
|
|
268
249
|
async artifactTypes() {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return ((_await$this$query = await this.query('catalog/artifact-types')) == null ? void 0 : _await$this$query.data) || [];
|
|
250
|
+
return (await this.query('catalog/artifact-types'))?.data || [];
|
|
272
251
|
}
|
|
273
252
|
|
|
274
253
|
async artistNames() {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return ((_await$this$query2 = await this.query('catalog/artist-names')) == null ? void 0 : _await$this$query2.data) || [];
|
|
254
|
+
return (await this.query('catalog/artist-names'))?.data || [];
|
|
278
255
|
}
|
|
279
256
|
|
|
280
257
|
async cardNames() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return ((_await$this$query3 = await this.query('catalog/card-names')) == null ? void 0 : _await$this$query3.data) || [];
|
|
258
|
+
return (await this.query('catalog/card-names'))?.data || [];
|
|
284
259
|
}
|
|
285
260
|
|
|
286
261
|
async creatureTypes() {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return ((_await$this$query4 = await this.query('catalog/creature-types')) == null ? void 0 : _await$this$query4.data) || [];
|
|
262
|
+
return (await this.query('catalog/creature-types'))?.data || [];
|
|
290
263
|
}
|
|
291
264
|
|
|
292
265
|
async enchantmentTypes() {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return ((_await$this$query5 = await this.query('catalog/enchantment-types')) == null ? void 0 : _await$this$query5.data) || [];
|
|
266
|
+
return (await this.query('catalog/enchantment-types'))?.data || [];
|
|
296
267
|
}
|
|
297
268
|
|
|
298
269
|
async landTypes() {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return ((_await$this$query6 = await this.query('catalog/land-types')) == null ? void 0 : _await$this$query6.data) || [];
|
|
270
|
+
return (await this.query('catalog/land-types'))?.data || [];
|
|
302
271
|
}
|
|
303
272
|
|
|
304
273
|
async loyalties() {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return ((_await$this$query7 = await this.query('catalog/loyalties')) == null ? void 0 : _await$this$query7.data) || [];
|
|
274
|
+
return (await this.query('catalog/loyalties'))?.data || [];
|
|
308
275
|
}
|
|
309
276
|
|
|
310
277
|
async planeswalkerTypes() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return ((_await$this$query8 = await this.query('catalog/planeswalker-types')) == null ? void 0 : _await$this$query8.data) || [];
|
|
278
|
+
return (await this.query('catalog/planeswalker-types'))?.data || [];
|
|
314
279
|
}
|
|
315
280
|
|
|
316
281
|
async powers() {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return ((_await$this$query9 = await this.query('catalog/powers')) == null ? void 0 : _await$this$query9.data) || [];
|
|
282
|
+
return (await this.query('catalog/powers'))?.data || [];
|
|
320
283
|
}
|
|
321
284
|
|
|
322
285
|
async spellTypes() {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return ((_await$this$query10 = await this.query('catalog/spell-types')) == null ? void 0 : _await$this$query10.data) || [];
|
|
286
|
+
return (await this.query('catalog/spell-types'))?.data || [];
|
|
326
287
|
}
|
|
327
288
|
|
|
328
289
|
async toughnesses() {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return ((_await$this$query11 = await this.query('catalog/toughnesses')) == null ? void 0 : _await$this$query11.data) || [];
|
|
290
|
+
return (await this.query('catalog/toughnesses'))?.data || [];
|
|
332
291
|
}
|
|
333
292
|
|
|
334
293
|
async watermarks() {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return ((_await$this$query12 = await this.query('catalog/watermarks')) == null ? void 0 : _await$this$query12.data) || [];
|
|
294
|
+
return (await this.query('catalog/watermarks'))?.data || [];
|
|
338
295
|
}
|
|
339
296
|
|
|
340
297
|
async wordBank() {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return ((_await$this$query13 = await this.query('catalog/word-bank')) == null ? void 0 : _await$this$query13.data) || [];
|
|
298
|
+
return (await this.query('catalog/word-bank'))?.data || [];
|
|
344
299
|
}
|
|
345
300
|
|
|
346
301
|
}
|
|
347
302
|
|
|
348
303
|
var Catalog$1 = new Catalog();
|
|
349
304
|
|
|
350
|
-
class Misc extends MagicQuery {
|
|
351
|
-
async homepageLinks() {
|
|
352
|
-
var _await$this$query;
|
|
353
|
-
|
|
354
|
-
return ((_await$this$query = await this.query('homepage-links')) == null ? void 0 : _await$this$query.data) || [];
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
var Misc$1 = new Misc();
|
|
360
|
-
|
|
361
305
|
class Rulings extends MagicQuery {
|
|
362
306
|
async byArenaId(id) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return ((_await$this$query = await this.query(['cards/arena', id, 'rulings'])) == null ? void 0 : _await$this$query.data) || [];
|
|
307
|
+
return (await this.query(['cards/arena', id, 'rulings']))?.data || [];
|
|
366
308
|
}
|
|
367
309
|
|
|
368
310
|
async byId(id) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return ((_await$this$query2 = await this.query(['cards', id, 'rulings'])) == null ? void 0 : _await$this$query2.data) || [];
|
|
311
|
+
return (await this.query(['cards', id, 'rulings']))?.data || [];
|
|
372
312
|
}
|
|
373
313
|
|
|
374
314
|
async byMtgoId(id) {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return ((_await$this$query3 = await this.query(['cards/mtgo', id, 'rulings'])) == null ? void 0 : _await$this$query3.data) || [];
|
|
315
|
+
return (await this.query(['cards/mtgo', id, 'rulings']))?.data || [];
|
|
378
316
|
}
|
|
379
317
|
|
|
380
318
|
async byMultiverseId(id) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
return ((_await$this$query4 = await this.query(['cards/multiverse', id, 'rulings'])) == null ? void 0 : _await$this$query4.data) || [];
|
|
319
|
+
return (await this.query(['cards/multiverse', id, 'rulings']))?.data || [];
|
|
384
320
|
}
|
|
385
321
|
|
|
386
322
|
async bySet(setCode, collectorNumber) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return ((_await$this$query5 = await this.query(['cards', setCode, `${collectorNumber}`, 'rulings'])) == null ? void 0 : _await$this$query5.data) || [];
|
|
323
|
+
return (await this.query(['cards', setCode, `${collectorNumber}`, 'rulings']))?.data || [];
|
|
390
324
|
}
|
|
391
325
|
|
|
392
326
|
}
|
|
@@ -396,7 +330,7 @@ var Rulings$1 = new Rulings();
|
|
|
396
330
|
class Sets extends MagicQuery {
|
|
397
331
|
async all() {
|
|
398
332
|
const result = await this.query('sets');
|
|
399
|
-
return
|
|
333
|
+
return result?.data || [];
|
|
400
334
|
}
|
|
401
335
|
|
|
402
336
|
async byCode(code) {
|
|
@@ -417,9 +351,7 @@ var Sets$1 = new Sets();
|
|
|
417
351
|
|
|
418
352
|
class Symbology extends MagicQuery {
|
|
419
353
|
async all() {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return ((_await$this$query = await this.query('symbology')) == null ? void 0 : _await$this$query.data) || [];
|
|
354
|
+
return (await this.query('symbology'))?.data || [];
|
|
423
355
|
}
|
|
424
356
|
|
|
425
357
|
async parseMana(shorthand) {
|
|
@@ -694,4 +626,4 @@ let UniqueStrategy;
|
|
|
694
626
|
UniqueStrategy[UniqueStrategy["prints"] = 2] = "prints";
|
|
695
627
|
})(UniqueStrategy || (UniqueStrategy = {}));
|
|
696
628
|
|
|
697
|
-
export { Border, BulkDataTypes, CardIdentifierBuilder, Cards$1 as Cards, Catalog$1 as Catalog, Format, FrameEffect, Game, Layout, Legality, MagicQueryError,
|
|
629
|
+
export { Border, BulkDataTypes, CardIdentifierBuilder, Cards$1 as Cards, Catalog$1 as Catalog, Format, FrameEffect, Game, Layout, Legality, MagicQueryError, PromoType, Rarity, RelatedCardComponent, Rulings$1 as Rulings, SetType, Sets$1 as Sets, Sort, SortDirection, Symbology$1 as Symbology, UniqueStrategy };
|