scryfall-api 2.2.1 → 3.0.2

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.
Files changed (79) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +8 -14
  3. package/{lib → dist/declarations/src}/api/CardIdentifierBuilder.d.ts +10 -10
  4. package/{lib → dist/declarations/src}/api/Cards.d.ts +19 -19
  5. package/{lib → dist/declarations/src}/api/Catalog.d.ts +18 -18
  6. package/{lib → dist/declarations/src}/api/Misc.d.ts +7 -7
  7. package/{lib → dist/declarations/src}/api/Rulings.d.ts +11 -11
  8. package/{lib → dist/declarations/src}/api/Sets.d.ts +10 -10
  9. package/{lib → dist/declarations/src}/api/Symbology.d.ts +8 -8
  10. package/{lib → dist/declarations/src}/error/MagicQueryError.d.ts +5 -5
  11. package/{lib → dist/declarations/src}/index.d.ts +11 -11
  12. package/{lib → dist/declarations/src}/query/MagicPageResult.d.ts +18 -18
  13. package/{lib → dist/declarations/src}/query/MagicQuery.d.ts +13 -13
  14. package/{lib → dist/declarations/src}/types/Border.d.ts +7 -7
  15. package/{lib → dist/declarations/src}/types/BulkDataDefinition.d.ts +14 -14
  16. package/{lib → dist/declarations/src}/types/BulkDataType.d.ts +2 -2
  17. package/{lib → dist/declarations/src}/types/BulkDataTypes.d.ts +7 -7
  18. package/{lib → dist/declarations/src}/types/Card.d.ts +91 -91
  19. package/{lib → dist/declarations/src}/types/CardFace.d.ts +22 -22
  20. package/{lib → dist/declarations/src}/types/CardIdentifier.d.ts +10 -10
  21. package/{lib → dist/declarations/src}/types/CardSymbol.d.ts +13 -13
  22. package/{lib → dist/declarations/src}/types/Color.d.ts +9 -9
  23. package/{lib → dist/declarations/src}/types/Format.d.ts +15 -15
  24. package/{lib → dist/declarations/src}/types/FrameEffect.d.ts +17 -17
  25. package/{lib → dist/declarations/src}/types/Game.d.ts +5 -5
  26. package/{lib → dist/declarations/src}/types/HomepageLink.d.ts +9 -9
  27. package/{lib → dist/declarations/src}/types/ImageUris.d.ts +8 -8
  28. package/{lib → dist/declarations/src}/types/Layout.d.ts +20 -20
  29. package/{lib → dist/declarations/src}/types/Legalties.d.ts +5 -5
  30. package/{lib → dist/declarations/src}/types/Legalty.d.ts +6 -6
  31. package/{lib → dist/declarations/src}/types/ManaCost.d.ts +9 -9
  32. package/{lib → dist/declarations/src}/types/PageQuery.d.ts +5 -5
  33. package/{lib → dist/declarations/src}/types/PageQueryValue.d.ts +1 -1
  34. package/{lib → dist/declarations/src}/types/Preview.d.ts +5 -5
  35. package/{lib → dist/declarations/src}/types/Prices.d.ts +6 -6
  36. package/{lib → dist/declarations/src}/types/PromoType.d.ts +27 -27
  37. package/{lib → dist/declarations/src}/types/PurchaseUris.d.ts +6 -6
  38. package/{lib → dist/declarations/src}/types/Query.d.ts +4 -4
  39. package/{lib → dist/declarations/src}/types/Rarity.d.ts +6 -6
  40. package/{lib → dist/declarations/src}/types/RelatedCard.d.ts +9 -9
  41. package/{lib → dist/declarations/src}/types/RelatedCardComponent.d.ts +6 -6
  42. package/{lib → dist/declarations/src}/types/RelatedUris.d.ts +7 -7
  43. package/{lib → dist/declarations/src}/types/ResultCatalog.d.ts +2 -2
  44. package/{lib → dist/declarations/src}/types/ResultData.d.ts +4 -4
  45. package/{lib → dist/declarations/src}/types/ResultList.d.ts +7 -7
  46. package/{lib → dist/declarations/src}/types/RetryStrategy.d.ts +11 -11
  47. package/{lib → dist/declarations/src}/types/Ruling.d.ts +5 -5
  48. package/{lib → dist/declarations/src}/types/SearchError.d.ts +7 -7
  49. package/{lib → dist/declarations/src}/types/SearchOptions.d.ts +15 -15
  50. package/{lib → dist/declarations/src}/types/Set.d.ts +20 -20
  51. package/{lib → dist/declarations/src}/types/SetType.d.ts +22 -22
  52. package/{lib → dist/declarations/src}/types/Sort.d.ts +15 -15
  53. package/{lib → dist/declarations/src}/types/SortDirection.d.ts +5 -5
  54. package/{lib → dist/declarations/src}/types/TOrArrayOfT.d.ts +1 -1
  55. package/{lib → dist/declarations/src}/types/UniqueStrategy.d.ts +5 -5
  56. package/{lib → dist/declarations/src}/types/index.d.ts +42 -42
  57. package/dist/scryfall-api.cjs.d.ts +1 -0
  58. package/dist/scryfall-api.cjs.dev.js +653 -0
  59. package/dist/scryfall-api.cjs.js +7 -0
  60. package/dist/scryfall-api.cjs.prod.js +653 -0
  61. package/dist/scryfall-api.esm.js +638 -0
  62. package/dist/scryfall-api.umd.min.js +2 -0
  63. package/dist/scryfall-api.umd.min.js.map +1 -0
  64. package/package.json +39 -91
  65. package/CHANGELOG.md +0 -47
  66. package/lib/api/Cards.spec.d.ts +0 -1
  67. package/lib/api/Catalog.spec.d.ts +0 -1
  68. package/lib/api/Misc.spec.d.ts +0 -1
  69. package/lib/api/Rulings.spec.d.ts +0 -1
  70. package/lib/api/Sets.spec.d.ts +0 -1
  71. package/lib/api/Symbology.spec.d.ts +0 -1
  72. package/lib/skryfall.es5.js +0 -660
  73. package/lib/skryfall.es5.js.map +0 -1
  74. package/lib/skryfall.es5.min.js +0 -16
  75. package/lib/skryfall.es5.min.js.map +0 -1
  76. package/lib/skryfall.umd.js +0 -679
  77. package/lib/skryfall.umd.js.map +0 -1
  78. package/lib/skryfall.umd.min.js +0 -16
  79. package/lib/skryfall.umd.min.js.map +0 -1
@@ -0,0 +1,638 @@
1
+ import Axios from 'axios';
2
+
3
+ class MagicPageResult {
4
+ constructor(q, apiPath, query, post) {
5
+ this.q = q;
6
+ this.apiPath = apiPath;
7
+ this.query = query;
8
+ this.post = post;
9
+ this._hasMore = true;
10
+ this._count = 0;
11
+ }
12
+
13
+ get count() {
14
+ return this._count;
15
+ }
16
+
17
+ get hasMore() {
18
+ return this._hasMore;
19
+ }
20
+
21
+ async all() {
22
+ const r = [];
23
+
24
+ while (this._hasMore) {
25
+ const result = await this.next();
26
+ r.push(...result);
27
+ }
28
+
29
+ return r;
30
+ }
31
+
32
+ async get(limit) {
33
+ const r = [];
34
+
35
+ while (this._hasMore) {
36
+ const result = await this.next();
37
+ r.push(...result);
38
+
39
+ if (r.length == limit) {
40
+ return r;
41
+ } else if (r.length > limit) {
42
+ return r.slice(0, limit);
43
+ }
44
+ }
45
+
46
+ return r;
47
+ }
48
+
49
+ async next() {
50
+ const results = await this.q.query(this.apiPath, this.query, this.post);
51
+ this._hasMore = results?.has_more || false;
52
+ this._count = Number.parseInt((results?.total_cards || 0) + '');
53
+
54
+ if (this._hasMore) {
55
+ this.setNextPage();
56
+ }
57
+
58
+ return results?.data || [];
59
+ }
60
+
61
+ async page(page) {
62
+ this.query.page = page;
63
+ return this.next();
64
+ }
65
+
66
+ setNextPage() {
67
+ this.query.page = this.query.page + 1;
68
+ }
69
+
70
+ }
71
+
72
+ class MagicQueryError extends Error {
73
+ constructor(data) {
74
+ super(data?.details);
75
+ this.data = data;
76
+ Object.setPrototypeOf(this, MagicQueryError.prototype);
77
+ }
78
+
79
+ }
80
+
81
+ class MagicQuery {
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
+
92
+ static canRetry(error) {
93
+ if (error?.code == 'not_found' || error?.code == 'bad_request') return false;
94
+ return !MagicQuery.retry.canRetry ;
95
+ }
96
+
97
+ static async debounce() {
98
+ const now = Date.now();
99
+ const timeSinceLastQuery = now - MagicQuery.lastQuery;
100
+
101
+ if (timeSinceLastQuery >= MagicQuery.rateLimit) {
102
+ MagicQuery.lastQuery = now;
103
+ } else {
104
+ const timeUntilNextQuery = MagicQuery.rateLimit - timeSinceLastQuery;
105
+ MagicQuery.lastQuery += timeUntilNextQuery;
106
+ await MagicQuery.sleep(timeUntilNextQuery);
107
+ }
108
+ }
109
+
110
+ static sleep(ms = 0) {
111
+ return new Promise(resolve => setTimeout(resolve, ms));
112
+ }
113
+
114
+ static async tryQuery(apiPath, query, post, requestOptions) {
115
+ await MagicQuery.debounce();
116
+ const config = {
117
+ data: post,
118
+ method: post ? 'POST' : 'GET',
119
+ params: query,
120
+ url: `${MagicQuery.endpoint}/${apiPath}`,
121
+ ...requestOptions
122
+ };
123
+
124
+ try {
125
+ return await Axios.request(config);
126
+ } catch (e) {
127
+ if (e['isAxiosError']) {
128
+ const error = e;
129
+ throw new MagicQueryError(error.response?.data);
130
+ } else {
131
+ throw e;
132
+ }
133
+ }
134
+ }
135
+
136
+ async query(apiPath, query, post, requestOptions) {
137
+ if (Array.isArray(apiPath)) {
138
+ apiPath = apiPath.join('/');
139
+ }
140
+
141
+ let retries;
142
+ let result;
143
+
144
+ for (retries = 0; retries < MagicQuery.retry.attempts; retries++) {
145
+ let error;
146
+
147
+ try {
148
+ result = await MagicQuery.tryQuery(`${apiPath}`, query, post, requestOptions);
149
+ } catch (e) {
150
+ if (e instanceof MagicQueryError) {
151
+ error = e.data;
152
+ } else {
153
+ throw e;
154
+ }
155
+ }
156
+
157
+ if (result || !MagicQuery.canRetry(error)) break;
158
+ await MagicQuery.sleep(MagicQuery.retry.timeout);
159
+ }
160
+
161
+ return result?.data;
162
+ }
163
+
164
+ }
165
+
166
+ class Cards extends MagicQuery {
167
+ async autoCompleteName(name) {
168
+ const result = await this.query('cards/autocomplete', {
169
+ q: name
170
+ });
171
+ return result?.data || [];
172
+ }
173
+
174
+ async byArenaId(id) {
175
+ return this.query(['cards/arena', id]);
176
+ }
177
+
178
+ async byId(id) {
179
+ return this.query(['cards', id]);
180
+ }
181
+
182
+ async byMtgoId(id) {
183
+ return this.query(['cards/mtgo', id]);
184
+ }
185
+
186
+ async byMultiverseId(id) {
187
+ return this.query(['cards/multiverse', id]);
188
+ }
189
+
190
+ async byName(name, set, fuzzy = false) {
191
+ if (typeof set === 'boolean') {
192
+ fuzzy = set;
193
+ set = undefined;
194
+ }
195
+
196
+ return this.query('cards/named', {
197
+ [fuzzy ? 'fuzzy' : 'exact']: name,
198
+ set
199
+ });
200
+ }
201
+
202
+ async bySet(setCode, collectorNumber, lang) {
203
+ const path = ['cards', setCode, collectorNumber];
204
+ if (lang) path.push(lang);
205
+ return this.query(path);
206
+ }
207
+
208
+ async byTcgPlayerId(id) {
209
+ return this.query(['cards/tcgplayer', id]);
210
+ }
211
+
212
+ async collection(...identifiers) {
213
+ const cards = [];
214
+
215
+ for (let i = 0; i < identifiers.length; i += 75) {
216
+ // the api only supports a max collection size of 75, so we take the list of identifiers (any length)
217
+ // and split it into 75 card-max requests
218
+ const collectionSection = {
219
+ identifiers: identifiers.slice(i, i + 75)
220
+ };
221
+ const result = await this.query('cards/collection', undefined, collectionSection);
222
+ cards.push(...(result?.data || []));
223
+ }
224
+
225
+ return cards;
226
+ }
227
+
228
+ async random() {
229
+ return this.query('cards/random');
230
+ }
231
+
232
+ search(query, options) {
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
+ });
242
+ }
243
+
244
+ }
245
+
246
+ var Cards$1 = new Cards();
247
+
248
+ class Catalog extends MagicQuery {
249
+ async artifactTypes() {
250
+ return (await this.query('catalog/artifact-types'))?.data || [];
251
+ }
252
+
253
+ async artistNames() {
254
+ return (await this.query('catalog/artist-names'))?.data || [];
255
+ }
256
+
257
+ async cardNames() {
258
+ return (await this.query('catalog/card-names'))?.data || [];
259
+ }
260
+
261
+ async creatureTypes() {
262
+ return (await this.query('catalog/creature-types'))?.data || [];
263
+ }
264
+
265
+ async enchantmentTypes() {
266
+ return (await this.query('catalog/enchantment-types'))?.data || [];
267
+ }
268
+
269
+ async landTypes() {
270
+ return (await this.query('catalog/land-types'))?.data || [];
271
+ }
272
+
273
+ async loyalties() {
274
+ return (await this.query('catalog/loyalties'))?.data || [];
275
+ }
276
+
277
+ async planeswalkerTypes() {
278
+ return (await this.query('catalog/planeswalker-types'))?.data || [];
279
+ }
280
+
281
+ async powers() {
282
+ return (await this.query('catalog/powers'))?.data || [];
283
+ }
284
+
285
+ async spellTypes() {
286
+ return (await this.query('catalog/spell-types'))?.data || [];
287
+ }
288
+
289
+ async toughnesses() {
290
+ return (await this.query('catalog/toughnesses'))?.data || [];
291
+ }
292
+
293
+ async watermarks() {
294
+ return (await this.query('catalog/watermarks'))?.data || [];
295
+ }
296
+
297
+ async wordBank() {
298
+ return (await this.query('catalog/word-bank'))?.data || [];
299
+ }
300
+
301
+ }
302
+
303
+ var Catalog$1 = new Catalog();
304
+
305
+ class Misc extends MagicQuery {
306
+ async homepageLinks() {
307
+ return (await this.query('homepage-links'))?.data || [];
308
+ }
309
+
310
+ }
311
+
312
+ var Misc$1 = new Misc();
313
+
314
+ class Rulings extends MagicQuery {
315
+ async byArenaId(id) {
316
+ return (await this.query(['cards/arena', id, 'rulings']))?.data || [];
317
+ }
318
+
319
+ async byId(id) {
320
+ return (await this.query(['cards', id, 'rulings']))?.data || [];
321
+ }
322
+
323
+ async byMtgoId(id) {
324
+ return (await this.query(['cards/mtgo', id, 'rulings']))?.data || [];
325
+ }
326
+
327
+ async byMultiverseId(id) {
328
+ return (await this.query(['cards/multiverse', id, 'rulings']))?.data || [];
329
+ }
330
+
331
+ async bySet(setCode, collectorNumber) {
332
+ return (await this.query(['cards', setCode, `${collectorNumber}`, 'rulings']))?.data || [];
333
+ }
334
+
335
+ }
336
+
337
+ var Rulings$1 = new Rulings();
338
+
339
+ class Sets extends MagicQuery {
340
+ async all() {
341
+ const result = await this.query('sets');
342
+ return result?.data || [];
343
+ }
344
+
345
+ async byCode(code) {
346
+ return await this.query(['sets', code]);
347
+ }
348
+
349
+ async byId(id) {
350
+ return this.query(['sets', id]);
351
+ }
352
+
353
+ async byTcgPlayerId(id) {
354
+ return this.query(['sets/tcgplayer', id]);
355
+ }
356
+
357
+ }
358
+
359
+ var Sets$1 = new Sets();
360
+
361
+ class Symbology extends MagicQuery {
362
+ async all() {
363
+ return (await this.query('symbology'))?.data || [];
364
+ }
365
+
366
+ async parseMana(shorthand) {
367
+ return await this.query('symbology/parse-mana', {
368
+ cost: shorthand
369
+ });
370
+ }
371
+
372
+ }
373
+
374
+ var Symbology$1 = new Symbology();
375
+
376
+ class CardIdentifierBuilder {
377
+ static byId(id) {
378
+ return {
379
+ id
380
+ };
381
+ }
382
+
383
+ static byIllustrationId(id) {
384
+ return {
385
+ illustration_id: id
386
+ };
387
+ }
388
+
389
+ static byMtgoId(id) {
390
+ return {
391
+ mtgo_id: id
392
+ };
393
+ }
394
+
395
+ static byMultiverseId(id) {
396
+ return {
397
+ multiverse_id: id
398
+ };
399
+ }
400
+
401
+ static byName(name, set) {
402
+ return {
403
+ name,
404
+ set
405
+ };
406
+ }
407
+
408
+ static byOracleId(id) {
409
+ return {
410
+ oracle_id: id
411
+ };
412
+ }
413
+
414
+ static bySet(set, collectorNumber) {
415
+ return {
416
+ collector_number: `${collectorNumber}`,
417
+ set
418
+ };
419
+ }
420
+
421
+ }
422
+
423
+ let Border;
424
+
425
+ (function (Border) {
426
+ Border[Border["black"] = 0] = "black";
427
+ Border[Border["borderless"] = 1] = "borderless";
428
+ Border[Border["gold"] = 2] = "gold";
429
+ Border[Border["silver"] = 3] = "silver";
430
+ Border[Border["white"] = 4] = "white";
431
+ })(Border || (Border = {}));
432
+
433
+ let BulkDataTypes;
434
+
435
+ (function (BulkDataTypes) {
436
+ BulkDataTypes[BulkDataTypes["oracle_cards"] = 0] = "oracle_cards";
437
+ BulkDataTypes[BulkDataTypes["unique_artwork"] = 1] = "unique_artwork";
438
+ BulkDataTypes[BulkDataTypes["default_cards"] = 2] = "default_cards";
439
+ BulkDataTypes[BulkDataTypes["all_cards"] = 3] = "all_cards";
440
+ BulkDataTypes[BulkDataTypes["rulings"] = 4] = "rulings";
441
+ })(BulkDataTypes || (BulkDataTypes = {}));
442
+
443
+ var Colors;
444
+
445
+ (function (Colors) {
446
+ Colors[Colors["W"] = 0] = "W";
447
+ Colors[Colors["B"] = 1] = "B";
448
+ Colors[Colors["R"] = 2] = "R";
449
+ Colors[Colors["U"] = 3] = "U";
450
+ Colors[Colors["G"] = 4] = "G";
451
+ })(Colors || (Colors = {}));
452
+
453
+ let Format;
454
+
455
+ (function (Format) {
456
+ Format[Format["standard"] = 0] = "standard";
457
+ Format[Format["future"] = 1] = "future";
458
+ Format[Format["historic"] = 2] = "historic";
459
+ Format[Format["pioneer"] = 3] = "pioneer";
460
+ Format[Format["modern"] = 4] = "modern";
461
+ Format[Format["legacy"] = 5] = "legacy";
462
+ Format[Format["pauper"] = 6] = "pauper";
463
+ Format[Format["vintage"] = 7] = "vintage";
464
+ Format[Format["penny"] = 8] = "penny";
465
+ Format[Format["commander"] = 9] = "commander";
466
+ Format[Format["brawl"] = 10] = "brawl";
467
+ Format[Format["duel"] = 11] = "duel";
468
+ Format[Format["oldschool"] = 12] = "oldschool";
469
+ })(Format || (Format = {}));
470
+
471
+ let FrameEffect;
472
+
473
+ (function (FrameEffect) {
474
+ FrameEffect[FrameEffect["legendary"] = 0] = "legendary";
475
+ FrameEffect[FrameEffect["miracle"] = 1] = "miracle";
476
+ FrameEffect[FrameEffect["nyxtouched"] = 2] = "nyxtouched";
477
+ FrameEffect[FrameEffect["draft"] = 3] = "draft";
478
+ FrameEffect[FrameEffect["devoid"] = 4] = "devoid";
479
+ FrameEffect[FrameEffect["tombstone"] = 5] = "tombstone";
480
+ FrameEffect[FrameEffect["colorshifted"] = 6] = "colorshifted";
481
+ FrameEffect[FrameEffect["inverted"] = 7] = "inverted";
482
+ FrameEffect[FrameEffect["sunmoondfc"] = 8] = "sunmoondfc";
483
+ FrameEffect[FrameEffect["compasslanddfc"] = 9] = "compasslanddfc";
484
+ FrameEffect[FrameEffect["originpwdfc"] = 10] = "originpwdfc";
485
+ FrameEffect[FrameEffect["mooneldrazidfc"] = 11] = "mooneldrazidfc";
486
+ FrameEffect[FrameEffect["moonreversemoondfc"] = 12] = "moonreversemoondfc";
487
+ FrameEffect[FrameEffect["showcase"] = 13] = "showcase";
488
+ FrameEffect[FrameEffect["extendedart"] = 14] = "extendedart";
489
+ })(FrameEffect || (FrameEffect = {}));
490
+
491
+ let Game;
492
+
493
+ (function (Game) {
494
+ Game[Game["paper"] = 0] = "paper";
495
+ Game[Game["arena"] = 1] = "arena";
496
+ Game[Game["mtgo"] = 2] = "mtgo";
497
+ })(Game || (Game = {}));
498
+
499
+ let Layout;
500
+
501
+ (function (Layout) {
502
+ Layout[Layout["normal"] = 0] = "normal";
503
+ Layout[Layout["split"] = 1] = "split";
504
+ Layout[Layout["flip"] = 2] = "flip";
505
+ Layout[Layout["transform"] = 3] = "transform";
506
+ Layout[Layout["meld"] = 4] = "meld";
507
+ Layout[Layout["leveler"] = 5] = "leveler";
508
+ Layout[Layout["saga"] = 6] = "saga";
509
+ Layout[Layout["adventure"] = 7] = "adventure";
510
+ Layout[Layout["planar"] = 8] = "planar";
511
+ Layout[Layout["scheme"] = 9] = "scheme";
512
+ Layout[Layout["vanguard"] = 10] = "vanguard";
513
+ Layout[Layout["token"] = 11] = "token";
514
+ Layout[Layout["double_faced_token"] = 12] = "double_faced_token";
515
+ Layout[Layout["emblem"] = 13] = "emblem";
516
+ Layout[Layout["augment"] = 14] = "augment";
517
+ Layout[Layout["host"] = 15] = "host";
518
+ Layout[Layout["art_series"] = 16] = "art_series";
519
+ Layout[Layout["double_sided"] = 17] = "double_sided";
520
+ })(Layout || (Layout = {}));
521
+
522
+ let Legality;
523
+
524
+ (function (Legality) {
525
+ Legality[Legality["legal"] = 0] = "legal";
526
+ Legality[Legality["not_legal"] = 1] = "not_legal";
527
+ Legality[Legality["restricted"] = 2] = "restricted";
528
+ Legality[Legality["banned"] = 3] = "banned";
529
+ })(Legality || (Legality = {}));
530
+
531
+ let PromoType;
532
+
533
+ (function (PromoType) {
534
+ PromoType[PromoType["tourney"] = 0] = "tourney";
535
+ PromoType[PromoType["prerelease"] = 1] = "prerelease";
536
+ PromoType[PromoType["datestamped"] = 2] = "datestamped";
537
+ PromoType[PromoType["planeswalkerdeck"] = 3] = "planeswalkerdeck";
538
+ PromoType[PromoType["buyabox"] = 4] = "buyabox";
539
+ PromoType[PromoType["judgegift"] = 5] = "judgegift";
540
+ PromoType[PromoType["event"] = 6] = "event";
541
+ PromoType[PromoType["convention"] = 7] = "convention";
542
+ PromoType[PromoType["starterdeck"] = 8] = "starterdeck";
543
+ PromoType[PromoType["instore"] = 9] = "instore";
544
+ PromoType[PromoType["setpromo"] = 10] = "setpromo";
545
+ PromoType[PromoType["fnm"] = 11] = "fnm";
546
+ PromoType[PromoType["openhouse"] = 12] = "openhouse";
547
+ PromoType[PromoType["league"] = 13] = "league";
548
+ PromoType[PromoType["draftweekend"] = 14] = "draftweekend";
549
+ PromoType[PromoType["gameday"] = 15] = "gameday";
550
+ PromoType[PromoType["release"] = 16] = "release";
551
+ PromoType[PromoType["intropack"] = 17] = "intropack";
552
+ PromoType[PromoType["giftbox"] = 18] = "giftbox";
553
+ PromoType[PromoType["duels"] = 19] = "duels";
554
+ PromoType[PromoType["wizardsplaynetwork"] = 20] = "wizardsplaynetwork";
555
+ PromoType[PromoType["premiereshop"] = 21] = "premiereshop";
556
+ PromoType[PromoType["playerrewards"] = 22] = "playerrewards";
557
+ PromoType[PromoType["gateway"] = 23] = "gateway";
558
+ PromoType[PromoType["arenaleague"] = 24] = "arenaleague";
559
+ })(PromoType || (PromoType = {}));
560
+
561
+ let Rarity;
562
+
563
+ (function (Rarity) {
564
+ Rarity[Rarity["common"] = 0] = "common";
565
+ Rarity[Rarity["uncommon"] = 1] = "uncommon";
566
+ Rarity[Rarity["rare"] = 2] = "rare";
567
+ Rarity[Rarity["mythic"] = 3] = "mythic";
568
+ })(Rarity || (Rarity = {}));
569
+
570
+ let RelatedCardComponent;
571
+
572
+ (function (RelatedCardComponent) {
573
+ RelatedCardComponent[RelatedCardComponent["token"] = 0] = "token";
574
+ RelatedCardComponent[RelatedCardComponent["meld_part"] = 1] = "meld_part";
575
+ RelatedCardComponent[RelatedCardComponent["meld_result"] = 2] = "meld_result";
576
+ RelatedCardComponent[RelatedCardComponent["combo_piece"] = 3] = "combo_piece";
577
+ })(RelatedCardComponent || (RelatedCardComponent = {}));
578
+
579
+ let SetType;
580
+
581
+ (function (SetType) {
582
+ SetType[SetType["core"] = 0] = "core";
583
+ SetType[SetType["expansion"] = 1] = "expansion";
584
+ SetType[SetType["masters"] = 2] = "masters";
585
+ SetType[SetType["masterpiece"] = 3] = "masterpiece";
586
+ SetType[SetType["from_the_vault"] = 4] = "from_the_vault";
587
+ SetType[SetType["spellbook"] = 5] = "spellbook";
588
+ SetType[SetType["premium_deck"] = 6] = "premium_deck";
589
+ SetType[SetType["duel_deck"] = 7] = "duel_deck";
590
+ SetType[SetType["draft_innovation"] = 8] = "draft_innovation";
591
+ SetType[SetType["treasure_chest"] = 9] = "treasure_chest";
592
+ SetType[SetType["commander"] = 10] = "commander";
593
+ SetType[SetType["planechase"] = 11] = "planechase";
594
+ SetType[SetType["archenemy"] = 12] = "archenemy";
595
+ SetType[SetType["vanguard"] = 13] = "vanguard";
596
+ SetType[SetType["funny"] = 14] = "funny";
597
+ SetType[SetType["starter"] = 15] = "starter";
598
+ SetType[SetType["box"] = 16] = "box";
599
+ SetType[SetType["promo"] = 17] = "promo";
600
+ SetType[SetType["token"] = 18] = "token";
601
+ SetType[SetType["memorabilia"] = 19] = "memorabilia";
602
+ })(SetType || (SetType = {}));
603
+
604
+ let Sort;
605
+
606
+ (function (Sort) {
607
+ Sort[Sort["name"] = 0] = "name";
608
+ Sort[Sort["set"] = 1] = "set";
609
+ Sort[Sort["released"] = 2] = "released";
610
+ Sort[Sort["rarity"] = 3] = "rarity";
611
+ Sort[Sort["color"] = 4] = "color";
612
+ Sort[Sort["usd"] = 5] = "usd";
613
+ Sort[Sort["tix"] = 6] = "tix";
614
+ Sort[Sort["eur"] = 7] = "eur";
615
+ Sort[Sort["cmc"] = 8] = "cmc";
616
+ Sort[Sort["power"] = 9] = "power";
617
+ Sort[Sort["toughness"] = 10] = "toughness";
618
+ Sort[Sort["edhrec"] = 11] = "edhrec";
619
+ Sort[Sort["artist"] = 12] = "artist";
620
+ })(Sort || (Sort = {}));
621
+
622
+ let SortDirection;
623
+
624
+ (function (SortDirection) {
625
+ SortDirection[SortDirection["auto"] = 0] = "auto";
626
+ SortDirection[SortDirection["asc"] = 1] = "asc";
627
+ SortDirection[SortDirection["desc"] = 2] = "desc";
628
+ })(SortDirection || (SortDirection = {}));
629
+
630
+ let UniqueStrategy;
631
+
632
+ (function (UniqueStrategy) {
633
+ UniqueStrategy[UniqueStrategy["cards"] = 0] = "cards";
634
+ UniqueStrategy[UniqueStrategy["art"] = 1] = "art";
635
+ UniqueStrategy[UniqueStrategy["prints"] = 2] = "prints";
636
+ })(UniqueStrategy || (UniqueStrategy = {}));
637
+
638
+ export { Border, BulkDataTypes, CardIdentifierBuilder, Cards$1 as Cards, Catalog$1 as Catalog, Format, FrameEffect, Game, Layout, Legality, MagicQueryError, Misc$1 as Misc, PromoType, Rarity, RelatedCardComponent, Rulings$1 as Rulings, SetType, Sets$1 as Sets, Sort, SortDirection, Symbology$1 as Symbology, UniqueStrategy };
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ScryfallAPI={},e.axios)}(this,(function(e,t){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}var r=a(t);class s{constructor(e,t,a,r){this.q=e,this.apiPath=t,this.query=a,this.post=r,this._hasMore=!0,this._count=0}get count(){return this._count}get hasMore(){return this._hasMore}async all(){const e=[];for(;this._hasMore;){const t=await this.next();e.push(...t)}return e}async get(e){const t=[];for(;this._hasMore;){const a=await this.next();if(t.push(...a),t.length==e)return t;if(t.length>e)return t.slice(0,e)}return t}async next(){const e=await this.q.query(this.apiPath,this.query,this.post);return this._hasMore=e?.has_more||!1,this._count=Number.parseInt((e?.total_cards||0)+""),this._hasMore&&this.setNextPage(),e?.data||[]}async page(e){return this.query.page=e,this.next()}setNextPage(){this.query.page=this.query.page+1}}class n extends Error{constructor(e){super(e?.details),this.data=e,Object.setPrototypeOf(this,n.prototype)}}class o{static retry={attempts:1};static endpoint="https://api.scryfall.com";static lastQuery=100;static rateLimit=100;static canRetry(e){return"not_found"!=e?.code&&"bad_request"!=e?.code&&!o.retry.canRetry}static async debounce(){const e=Date.now(),t=e-o.lastQuery;if(t>=o.rateLimit)o.lastQuery=e;else{const e=o.rateLimit-t;o.lastQuery+=e,await o.sleep(e)}}static sleep(e=0){return new Promise((t=>setTimeout(t,e)))}static async tryQuery(e,t,a,s){await o.debounce();const i={data:a,method:a?"POST":"GET",params:t,url:`${o.endpoint}/${e}`,...s};try{return await r.default.request(i)}catch(e){if(e.isAxiosError){throw new n(e.response?.data)}throw e}}async query(e,t,a,r){let s,i;for(Array.isArray(e)&&(e=e.join("/")),s=0;s<o.retry.attempts;s++){let s;try{i=await o.tryQuery(`${e}`,t,a,r)}catch(e){if(!(e instanceof n))throw e;s=e.data}if(i||!o.canRetry(s))break;await o.sleep(o.retry.timeout)}return i?.data}}var i=new class extends o{async autoCompleteName(e){return(await this.query("cards/autocomplete",{q:e}))?.data||[]}async byArenaId(e){return this.query(["cards/arena",e])}async byId(e){return this.query(["cards",e])}async byMtgoId(e){return this.query(["cards/mtgo",e])}async byMultiverseId(e){return this.query(["cards/multiverse",e])}async byName(e,t,a=!1){return"boolean"==typeof t&&(a=t,t=void 0),this.query("cards/named",{[a?"fuzzy":"exact"]:e,set:t})}async bySet(e,t,a){const r=["cards",e,t];return a&&r.push(a),this.query(r)}async byTcgPlayerId(e){return this.query(["cards/tcgplayer",e])}async collection(...e){const t=[];for(let a=0;a<e.length;a+=75){const r={identifiers:e.slice(a,a+75)},s=await this.query("cards/collection",void 0,r);t.push(...s?.data||[])}return t}async random(){return this.query("cards/random")}search(e,t){return new s(this,"cards/search",{q:e,..."number"==typeof t?{page:t}:{page:1,...t}})}};var c=new class extends o{async artifactTypes(){return(await this.query("catalog/artifact-types"))?.data||[]}async artistNames(){return(await this.query("catalog/artist-names"))?.data||[]}async cardNames(){return(await this.query("catalog/card-names"))?.data||[]}async creatureTypes(){return(await this.query("catalog/creature-types"))?.data||[]}async enchantmentTypes(){return(await this.query("catalog/enchantment-types"))?.data||[]}async landTypes(){return(await this.query("catalog/land-types"))?.data||[]}async loyalties(){return(await this.query("catalog/loyalties"))?.data||[]}async planeswalkerTypes(){return(await this.query("catalog/planeswalker-types"))?.data||[]}async powers(){return(await this.query("catalog/powers"))?.data||[]}async spellTypes(){return(await this.query("catalog/spell-types"))?.data||[]}async toughnesses(){return(await this.query("catalog/toughnesses"))?.data||[]}async watermarks(){return(await this.query("catalog/watermarks"))?.data||[]}async wordBank(){return(await this.query("catalog/word-bank"))?.data||[]}};var d=new class extends o{async homepageLinks(){return(await this.query("homepage-links"))?.data||[]}};var u=new class extends o{async byArenaId(e){return(await this.query(["cards/arena",e,"rulings"]))?.data||[]}async byId(e){return(await this.query(["cards",e,"rulings"]))?.data||[]}async byMtgoId(e){return(await this.query(["cards/mtgo",e,"rulings"]))?.data||[]}async byMultiverseId(e){return(await this.query(["cards/multiverse",e,"rulings"]))?.data||[]}async bySet(e,t){return(await this.query(["cards",e,`${t}`,"rulings"]))?.data||[]}};var l=new class extends o{async all(){return(await this.query("sets"))?.data||[]}async byCode(e){return await this.query(["sets",e])}async byId(e){return this.query(["sets",e])}async byTcgPlayerId(e){return this.query(["sets/tcgplayer",e])}};var y,m,p,h,g,f,w,b,_,v,q,k,x,T,I,S=new class extends o{async all(){return(await this.query("symbology"))?.data||[]}async parseMana(e){return await this.query("symbology/parse-mana",{cost:e})}};e.Border=void 0,(y=e.Border||(e.Border={}))[y.black=0]="black",y[y.borderless=1]="borderless",y[y.gold=2]="gold",y[y.silver=3]="silver",y[y.white=4]="white",e.BulkDataTypes=void 0,(m=e.BulkDataTypes||(e.BulkDataTypes={}))[m.oracle_cards=0]="oracle_cards",m[m.unique_artwork=1]="unique_artwork",m[m.default_cards=2]="default_cards",m[m.all_cards=3]="all_cards",m[m.rulings=4]="rulings",function(e){e[e.W=0]="W",e[e.B=1]="B",e[e.R=2]="R",e[e.U=3]="U",e[e.G=4]="G"}(p||(p={})),e.Format=void 0,(h=e.Format||(e.Format={}))[h.standard=0]="standard",h[h.future=1]="future",h[h.historic=2]="historic",h[h.pioneer=3]="pioneer",h[h.modern=4]="modern",h[h.legacy=5]="legacy",h[h.pauper=6]="pauper",h[h.vintage=7]="vintage",h[h.penny=8]="penny",h[h.commander=9]="commander",h[h.brawl=10]="brawl",h[h.duel=11]="duel",h[h.oldschool=12]="oldschool",e.FrameEffect=void 0,(g=e.FrameEffect||(e.FrameEffect={}))[g.legendary=0]="legendary",g[g.miracle=1]="miracle",g[g.nyxtouched=2]="nyxtouched",g[g.draft=3]="draft",g[g.devoid=4]="devoid",g[g.tombstone=5]="tombstone",g[g.colorshifted=6]="colorshifted",g[g.inverted=7]="inverted",g[g.sunmoondfc=8]="sunmoondfc",g[g.compasslanddfc=9]="compasslanddfc",g[g.originpwdfc=10]="originpwdfc",g[g.mooneldrazidfc=11]="mooneldrazidfc",g[g.moonreversemoondfc=12]="moonreversemoondfc",g[g.showcase=13]="showcase",g[g.extendedart=14]="extendedart",e.Game=void 0,(f=e.Game||(e.Game={}))[f.paper=0]="paper",f[f.arena=1]="arena",f[f.mtgo=2]="mtgo",e.Layout=void 0,(w=e.Layout||(e.Layout={}))[w.normal=0]="normal",w[w.split=1]="split",w[w.flip=2]="flip",w[w.transform=3]="transform",w[w.meld=4]="meld",w[w.leveler=5]="leveler",w[w.saga=6]="saga",w[w.adventure=7]="adventure",w[w.planar=8]="planar",w[w.scheme=9]="scheme",w[w.vanguard=10]="vanguard",w[w.token=11]="token",w[w.double_faced_token=12]="double_faced_token",w[w.emblem=13]="emblem",w[w.augment=14]="augment",w[w.host=15]="host",w[w.art_series=16]="art_series",w[w.double_sided=17]="double_sided",e.Legality=void 0,(b=e.Legality||(e.Legality={}))[b.legal=0]="legal",b[b.not_legal=1]="not_legal",b[b.restricted=2]="restricted",b[b.banned=3]="banned",e.PromoType=void 0,(_=e.PromoType||(e.PromoType={}))[_.tourney=0]="tourney",_[_.prerelease=1]="prerelease",_[_.datestamped=2]="datestamped",_[_.planeswalkerdeck=3]="planeswalkerdeck",_[_.buyabox=4]="buyabox",_[_.judgegift=5]="judgegift",_[_.event=6]="event",_[_.convention=7]="convention",_[_.starterdeck=8]="starterdeck",_[_.instore=9]="instore",_[_.setpromo=10]="setpromo",_[_.fnm=11]="fnm",_[_.openhouse=12]="openhouse",_[_.league=13]="league",_[_.draftweekend=14]="draftweekend",_[_.gameday=15]="gameday",_[_.release=16]="release",_[_.intropack=17]="intropack",_[_.giftbox=18]="giftbox",_[_.duels=19]="duels",_[_.wizardsplaynetwork=20]="wizardsplaynetwork",_[_.premiereshop=21]="premiereshop",_[_.playerrewards=22]="playerrewards",_[_.gateway=23]="gateway",_[_.arenaleague=24]="arenaleague",e.Rarity=void 0,(v=e.Rarity||(e.Rarity={}))[v.common=0]="common",v[v.uncommon=1]="uncommon",v[v.rare=2]="rare",v[v.mythic=3]="mythic",e.RelatedCardComponent=void 0,(q=e.RelatedCardComponent||(e.RelatedCardComponent={}))[q.token=0]="token",q[q.meld_part=1]="meld_part",q[q.meld_result=2]="meld_result",q[q.combo_piece=3]="combo_piece",e.SetType=void 0,(k=e.SetType||(e.SetType={}))[k.core=0]="core",k[k.expansion=1]="expansion",k[k.masters=2]="masters",k[k.masterpiece=3]="masterpiece",k[k.from_the_vault=4]="from_the_vault",k[k.spellbook=5]="spellbook",k[k.premium_deck=6]="premium_deck",k[k.duel_deck=7]="duel_deck",k[k.draft_innovation=8]="draft_innovation",k[k.treasure_chest=9]="treasure_chest",k[k.commander=10]="commander",k[k.planechase=11]="planechase",k[k.archenemy=12]="archenemy",k[k.vanguard=13]="vanguard",k[k.funny=14]="funny",k[k.starter=15]="starter",k[k.box=16]="box",k[k.promo=17]="promo",k[k.token=18]="token",k[k.memorabilia=19]="memorabilia",e.Sort=void 0,(x=e.Sort||(e.Sort={}))[x.name=0]="name",x[x.set=1]="set",x[x.released=2]="released",x[x.rarity=3]="rarity",x[x.color=4]="color",x[x.usd=5]="usd",x[x.tix=6]="tix",x[x.eur=7]="eur",x[x.cmc=8]="cmc",x[x.power=9]="power",x[x.toughness=10]="toughness",x[x.edhrec=11]="edhrec",x[x.artist=12]="artist",e.SortDirection=void 0,(T=e.SortDirection||(e.SortDirection={}))[T.auto=0]="auto",T[T.asc=1]="asc",T[T.desc=2]="desc",e.UniqueStrategy=void 0,(I=e.UniqueStrategy||(e.UniqueStrategy={}))[I.cards=0]="cards",I[I.art=1]="art",I[I.prints=2]="prints",e.CardIdentifierBuilder=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{name:e,set:t}}static byOracleId(e){return{oracle_id:e}}static bySet(e,t){return{collector_number:`${t}`,set:e}}},e.Cards=i,e.Catalog=c,e.MagicQueryError=n,e.Misc=d,e.Rulings=u,e.Sets=l,e.Symbology=S,Object.defineProperty(e,"__esModule",{value:!0})}));
2
+ //# sourceMappingURL=scryfall-api.umd.min.js.map