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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/dist/declarations/dist/src/api/CardIdentifierBuilder.d.ts +10 -0
  3. package/dist/declarations/dist/src/api/Cards.d.ts +19 -0
  4. package/dist/declarations/dist/src/api/Catalog.d.ts +18 -0
  5. package/dist/declarations/dist/src/api/Rulings.d.ts +11 -0
  6. package/dist/declarations/dist/src/api/Sets.d.ts +10 -0
  7. package/dist/declarations/dist/src/api/Symbology.d.ts +8 -0
  8. package/dist/declarations/dist/src/error/MagicQueryError.d.ts +5 -0
  9. package/dist/declarations/dist/src/index.d.ts +10 -0
  10. package/dist/declarations/dist/src/query/MagicPageResult.d.ts +18 -0
  11. package/dist/declarations/dist/src/query/MagicQuery.d.ts +13 -0
  12. package/dist/declarations/dist/src/types/Border.d.ts +7 -0
  13. package/dist/declarations/dist/src/types/BulkDataDefinition.d.ts +14 -0
  14. package/dist/declarations/dist/src/types/BulkDataType.d.ts +2 -0
  15. package/dist/declarations/dist/src/types/BulkDataTypes.d.ts +7 -0
  16. package/dist/declarations/dist/src/types/Card.d.ts +91 -0
  17. package/dist/declarations/dist/src/types/CardFace.d.ts +22 -0
  18. package/dist/declarations/dist/src/types/CardIdentifier.d.ts +10 -0
  19. package/dist/declarations/dist/src/types/CardSymbol.d.ts +13 -0
  20. package/dist/declarations/dist/src/types/Color.d.ts +9 -0
  21. package/dist/declarations/dist/src/types/Format.d.ts +15 -0
  22. package/dist/declarations/dist/src/types/FrameEffect.d.ts +17 -0
  23. package/dist/declarations/dist/src/types/Game.d.ts +5 -0
  24. package/dist/declarations/dist/src/types/HomepageLink.d.ts +9 -0
  25. package/dist/declarations/dist/src/types/ImageUris.d.ts +8 -0
  26. package/dist/declarations/dist/src/types/Layout.d.ts +20 -0
  27. package/dist/declarations/dist/src/types/Legalties.d.ts +5 -0
  28. package/dist/declarations/dist/src/types/Legalty.d.ts +6 -0
  29. package/dist/declarations/dist/src/types/ManaCost.d.ts +9 -0
  30. package/dist/declarations/dist/src/types/PageQuery.d.ts +5 -0
  31. package/dist/declarations/dist/src/types/PageQueryValue.d.ts +1 -0
  32. package/dist/declarations/dist/src/types/Preview.d.ts +5 -0
  33. package/dist/declarations/dist/src/types/Prices.d.ts +6 -0
  34. package/dist/declarations/dist/src/types/PromoType.d.ts +27 -0
  35. package/dist/declarations/dist/src/types/PurchaseUris.d.ts +6 -0
  36. package/dist/declarations/dist/src/types/Query.d.ts +4 -0
  37. package/dist/declarations/dist/src/types/Rarity.d.ts +6 -0
  38. package/dist/declarations/dist/src/types/RelatedCard.d.ts +9 -0
  39. package/dist/declarations/dist/src/types/RelatedCardComponent.d.ts +6 -0
  40. package/dist/declarations/dist/src/types/RelatedUris.d.ts +7 -0
  41. package/dist/declarations/dist/src/types/ResultCatalog.d.ts +2 -0
  42. package/dist/declarations/dist/src/types/ResultData.d.ts +4 -0
  43. package/dist/declarations/dist/src/types/ResultList.d.ts +7 -0
  44. package/dist/declarations/dist/src/types/RetryStrategy.d.ts +11 -0
  45. package/dist/declarations/dist/src/types/Ruling.d.ts +5 -0
  46. package/dist/declarations/dist/src/types/SearchError.d.ts +7 -0
  47. package/dist/declarations/dist/src/types/SearchOptions.d.ts +15 -0
  48. package/dist/declarations/dist/src/types/Set.d.ts +20 -0
  49. package/dist/declarations/dist/src/types/SetType.d.ts +22 -0
  50. package/dist/declarations/dist/src/types/Sort.d.ts +15 -0
  51. package/dist/declarations/dist/src/types/SortDirection.d.ts +5 -0
  52. package/dist/declarations/dist/src/types/TOrArrayOfT.d.ts +1 -0
  53. package/dist/declarations/dist/src/types/UniqueStrategy.d.ts +5 -0
  54. package/dist/declarations/dist/src/types/index.d.ts +42 -0
  55. package/dist/scryfall-api.cjs.d.ts +1 -1
  56. package/dist/scryfall-api.cjs.dev.js +53 -122
  57. package/dist/scryfall-api.cjs.prod.js +53 -122
  58. package/dist/scryfall-api.esm.js +54 -122
  59. package/dist/scryfall-api.umd.min.js +1 -1
  60. package/dist/scryfall-api.umd.min.js.map +1 -1
  61. package/package.json +59 -7
  62. package/CHANGELOG.md +0 -13
  63. package/DOCUMENTATION.md +0 -505
  64. package/SUPPORT.md +0 -38
@@ -0,0 +1,15 @@
1
+ export declare enum Sort {
2
+ name = 0,
3
+ set = 1,
4
+ released = 2,
5
+ rarity = 3,
6
+ color = 4,
7
+ usd = 5,
8
+ tix = 6,
9
+ eur = 7,
10
+ cmc = 8,
11
+ power = 9,
12
+ toughness = 10,
13
+ edhrec = 11,
14
+ artist = 12
15
+ }
@@ -0,0 +1,5 @@
1
+ export declare enum SortDirection {
2
+ auto = 0,
3
+ asc = 1,
4
+ desc = 2
5
+ }
@@ -0,0 +1 @@
1
+ export declare type TOrArrayOfT<T> = T | T[];
@@ -0,0 +1,5 @@
1
+ export declare enum UniqueStrategy {
2
+ cards = 0,
3
+ art = 1,
4
+ prints = 2
5
+ }
@@ -0,0 +1,42 @@
1
+ export * from './Border';
2
+ export * from './BulkDataDefinition';
3
+ export * from './BulkDataType';
4
+ export * from './BulkDataTypes';
5
+ export * from './Card';
6
+ export * from './CardFace';
7
+ export * from './CardIdentifier';
8
+ export * from './CardSymbol';
9
+ export * from './Color';
10
+ export * from './Format';
11
+ export * from './FrameEffect';
12
+ export * from './Game';
13
+ export * from './HomepageLink';
14
+ export * from './ImageUris';
15
+ export * from './Layout';
16
+ export * from './Legalties';
17
+ export * from './Legalty';
18
+ export * from './ManaCost';
19
+ export * from './PageQuery';
20
+ export * from './PageQueryValue';
21
+ export * from './Preview';
22
+ export * from './Prices';
23
+ export * from './PromoType';
24
+ export * from './PurchaseUris';
25
+ export * from './Query';
26
+ export * from './Rarity';
27
+ export * from './RelatedCard';
28
+ export * from './RelatedCardComponent';
29
+ export * from './RelatedUris';
30
+ export * from './ResultCatalog';
31
+ export * from './ResultData';
32
+ export * from './ResultList';
33
+ export * from './RetryStrategy';
34
+ export * from './Ruling';
35
+ export * from './SearchError';
36
+ export * from './SearchOptions';
37
+ export * from './Set';
38
+ export * from './SetType';
39
+ export * from './Sort';
40
+ export * from './SortDirection';
41
+ export * from './TOrArrayOfT';
42
+ export * from './UniqueStrategy';
@@ -1 +1 @@
1
- export * from "./declarations/src/index";
1
+ export * from "./declarations/dist/src/index";
@@ -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 = (results == null ? void 0 : results.has_more) || false;
78
- this._count = Number.parseInt(((results == null ? void 0 : results.total_cards) || 0) + '');
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 (results == null ? void 0 : results.data) || [];
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 == null ? void 0 : data.details);
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
- // the path to the api
109
- // time where the last api call was made
110
- // the api requests 50-100 ms between calls, we go on the generous side and never wait less than 100 ms between calls
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 ((error == null ? void 0 : error.code) == 'not_found' || (error == null ? void 0 : error.code) == 'bad_request') return false;
113
- return !MagicQuery.retry.canRetry || MagicQuery.retry.canRetry(error);
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
- }, requestOptions);
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((_error$response = error.response) == null ? void 0 : _error$response.data);
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 (_result = result) == null ? void 0 : _result.data;
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 (result == null ? void 0 : result.data) || [];
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(...((result == null ? void 0 : result.data) || []));
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', _extends({
263
- q: query
264
- }, typeof options === 'number' ? {
265
- page: options
266
- } : _extends({
267
- page: 1
268
- }, options)));
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
- var _await$this$query;
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
- var _await$this$query2;
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
- var _await$this$query3;
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
- var _await$this$query4;
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
- var _await$this$query5;
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
- var _await$this$query6;
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
- var _await$this$query7;
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
- var _await$this$query8;
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
- var _await$this$query9;
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
- var _await$this$query10;
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
- var _await$this$query11;
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
- var _await$this$query12;
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
- var _await$this$query13;
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
- var _await$this$query;
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
- var _await$this$query2;
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
- var _await$this$query3;
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
- var _await$this$query4;
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
- var _await$this$query5;
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 (result == null ? void 0 : result.data) || [];
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
- var _await$this$query;
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;