113 Commits

Author SHA1 Message Date
e061d81e19 Update package.json 2025-01-20 17:09:54 +00:00
0cbb20fdf2 Update package.json 2025-01-20 14:35:23 +00:00
6a08d3a61a Update package.json 2025-01-20 13:28:56 +00:00
73328a1df2 Update package.json 2025-01-20 11:24:46 +00:00
25b4c2f5d1 Update package.json 2025-01-20 11:03:12 +00:00
Tee
5f2de997ea Bump version number 2021-12-16 20:53:39 -05:00
Tee
befb72bde6 Update contribution instructions 2021-12-16 20:52:46 -05:00
Tee
6cd9eab51b add regulationMark property to card interface 2021-12-16 20:51:59 -05:00
Tee
c4967fb899 Add name and github link to contrubition section 2021-12-16 20:51:11 -05:00
Tee
7ff5d7863d Update version 2021-08-26 22:26:31 -04:00
Tee
f93dbe2fb6 Add missing set import 2021-08-26 21:20:27 -04:00
Tee
9b95435d9e Add new release date and extra contribution steps 2021-08-26 21:20:04 -04:00
Tee
b554a5f5d8 Merge pull request #26 from CptSpaceToaster/add-cardmarket-properties
Add some cardmarket properties
2021-08-10 10:01:58 -04:00
a0b055f6e7 Add some cardmarket properties
Most of these are nullable
2021-08-05 22:56:46 -04:00
ee12437d1a Merge pull request #23 from CptSpaceToaster/main
Add `1stEditionNormal` and `1stEditionHoloFoil` properties in TCGPlayer interface
2021-04-01 21:47:03 -04:00
380d2e7c97 Add missing properties, but their names are weird
They're like this in the JSON :(
2021-03-26 12:36:18 -04:00
Tee
5b5d076e52 Bump patch version 2021-03-24 22:52:56 -04:00
Tee
5d45d75720 fix evolvesFrom typo 2021-03-24 22:52:27 -04:00
Tee
aa62e1b6ee Bump patch for doc update 2021-03-23 00:22:41 -04:00
Tee
4b4d4cb901 Add API configuration steps 2021-03-23 00:21:34 -04:00
Tee
aca7f28a93 Update version number 2021-03-22 22:45:29 -04:00
Tee
0bdd1f0def Update minor version 2021-03-22 22:45:05 -04:00
Tee
e0afb2932a Update card and set property docs 2021-03-22 22:43:29 -04:00
Tee
2d7b47efd4 Add deprication notice in README 2021-03-22 22:41:18 -04:00
Tee
f077348af4 Add deprication notices to Meta methods 2021-03-22 22:31:06 -04:00
Tee
21d94dd997 Refactor meta route retrieval and return types 2021-03-22 22:26:08 -04:00
Tee
c5d48dba11 Add set deprication noticess 2021-03-22 22:23:29 -04:00
Tee
4d442f2d81 Add card method deprication notices 2021-03-22 22:23:14 -04:00
Tee
ed55ddc434 Add v2 Migration guide 2021-03-22 22:22:53 -04:00
Tee
9d40a50d80 Install types/node dependency for environment variables 2021-03-22 00:39:43 -04:00
Tee
eedad4f043 Set API key header with environment variable 2021-03-22 00:39:23 -04:00
Tee
47861f3760 Update optional properties and formatting for Card 2021-03-22 00:39:05 -04:00
Tee
3624938ade Update optional properties for card interfaces 2021-03-22 00:38:39 -04:00
82ca4b6626 Merge pull request #20 from PokemonTCG/revert-19-v2-migration
Revert "Add v2 Migration"
2021-03-16 00:24:43 -04:00
76fa13fa12 Revert "Add v2 Migration" 2021-03-16 00:24:25 -04:00
3b3b65e7d0 Merge pull request #19 from acupoftee/v2-migration
Add v2 Migration
2021-03-16 00:22:27 -04:00
Tee
fd3df49bc8 Add name for contribution 2021-03-16 00:18:09 -04:00
Tee
9443263499 Update sdk version 2021-03-16 00:17:37 -04:00
Tee
0ef85368c8 Updated gitignore with .idea directory 2021-03-15 23:23:40 -04:00
Tee
5755c744a3 Add formatted and linted files 2021-03-15 23:23:06 -04:00
Tee
de16add8d1 Add eslint dependencies 2021-03-15 21:45:12 -04:00
Tee
315f8cbef3 Add prettierignore 2021-03-15 21:44:36 -04:00
Tee
8a3b2a0b7a Add eslint config files 2021-03-15 21:43:43 -04:00
Tee
66965487a7 Add return type to Client.getInstance 2021-03-15 12:35:47 -04:00
Tee
523201535d Add prettierrc.json 2021-03-15 08:45:16 -04:00
Tee
904c92bb9b Remove optional parameter in params to query function 2021-03-15 08:44:57 -04:00
Tee
0e4698f2a1 Install prettier dependency 2021-03-15 08:38:23 -04:00
Tee
417cced318 Add test timeout in jest config 2021-03-15 08:37:56 -04:00
Tee
b0a744fd58 Fix cardService test formatting 2021-03-14 21:36:53 -04:00
Tee
1033ad9dc2 Add tests for card enums 2021-03-14 21:33:46 -04:00
Tee
1bcdd1d990 Add param check 2021-03-14 21:33:20 -04:00
Tee
619ec93332 Fix spelling errors in card enums 2021-03-14 21:32:56 -04:00
Tee
517ee0ff53 Add functions for card constants 2021-03-14 21:32:36 -04:00
Tee
6f1c4958b1 Add enum types for select Card properties 2021-03-14 17:15:48 -04:00
Tee
eb01211d09 Use singular naming scheme for enums 2021-03-14 17:04:42 -04:00
Tee
bfc4ad92b9 Add search parameter enums 2021-03-12 22:01:41 -05:00
Tee
71266cf726 Update legality enum casing 2021-03-12 22:00:35 -05:00
Tee
11c0c9041f Add type enums 2021-03-12 21:58:57 -05:00
Tee
decba63848 Add supertype enums 2021-03-12 21:58:53 -05:00
Tee
da9f106165 Add subtype enums 2021-03-12 21:58:46 -05:00
Tee
6c034d399f Add rarity enums 2021-03-12 21:58:40 -05:00
Tee
de37e0ef40 Match Set property ordering with API resource ordering 2021-03-12 21:31:46 -05:00
Tee
4e87f38bc5 Match Card property order with API resource order 2021-03-12 21:31:36 -05:00
Tee
1492b96a23 Update testing dependencies 2021-03-11 19:40:07 -05:00
Tee
5435e233e9 Delete client.test.ts 2021-03-11 19:29:58 -05:00
Tee
32e6de135e Add Set Service test 2021-03-11 19:27:04 -05:00
Tee
735d428dc2 Export individual functions in setService 2021-03-11 19:26:23 -05:00
Tee
ed16e6e937 Remove query builder abstraction 2021-03-11 12:46:02 -05:00
Tee
33116796dd Export individual card service functions 2021-03-11 08:02:32 -05:00
Tee
1ab1add58a Add ampersand and parameter conditions in client.ts 2021-03-11 07:59:21 -05:00
Tee
8c75754623 Add passing card service integration tests 2021-03-11 07:57:39 -05:00
Tee
d9fcb2ed55 Merge typing updates from v2-migration branch 2021-03-10 09:00:23 -05:00
Tee
f86810201d Merge branch 'master' into v2-migration 2021-03-10 08:55:31 -05:00
Tee
bfa0502a1e Update and pin Axios to latest release 2021-03-09 20:06:10 -05:00
fcbf7849ff Merge pull request #2 from PokemonTCG/master
Update TypeScript
2021-03-09 17:58:46 -05:00
c00754f7df Merge pull request #18 from acupoftee/typescript-update
Update TypeScript to latest stable version
2021-03-05 13:54:00 -06:00
Tee
daf61a0f9c Upgrade TypeScript to latest stable release 2021-03-04 23:34:01 -05:00
Tee
ba2ce6e79b Use optional property syntax for ILegality 2021-03-04 07:45:38 -05:00
Tee
f47353849a Use new singleton instance of Client 2021-03-04 00:08:46 -05:00
Tee
9992fc99eb Remove coverage directory 2021-03-04 00:07:36 -05:00
Tee
54c42b7654 Update test directory in exclude setting 2021-03-04 00:07:18 -05:00
Tee
b6d387e7a5 Move test files to test directory 2021-03-04 00:06:52 -05:00
Tee
2bf257de45 Create jest config 2021-03-04 00:05:58 -05:00
Tee
4238438adb Use optional property syntax in TCGPlayer interface 2021-03-01 22:01:47 -05:00
Tee
0d00d4f984 Refactor Resistance and Weakness imports 2021-03-01 22:01:24 -05:00
Tee
979a6367b8 Refactor SDK imports 2021-03-01 22:01:12 -05:00
Tee
b12e306c73 Remove API service interface 2021-03-01 22:00:14 -05:00
Tee
320d62dd41 Extend shared stats interface to weakness and resistance 2021-03-01 21:31:52 -05:00
Tee
e7d36cc5a1 Use default exports for Set service methods instead of classes 2021-02-28 23:45:36 -05:00
Tee
fb33ea3617 Use default exports for service methods instead of classes 2021-02-28 23:44:13 -05:00
Tee
aa4179d523 Remove card and set classes 2021-02-28 22:55:20 -05:00
Tee
7f71588138 Use private client methods in services 2021-02-28 22:27:48 -05:00
Tee
537a236b42 Create private singleton class for Client 2021-02-27 23:06:15 -05:00
Tee
e588d35dd9 Remove QueryBuilder 2021-02-26 21:24:51 -05:00
Tee
5f19f8227e Add SetService 2021-02-26 19:56:41 -05:00
Tee
a7afa92184 Use generic APIService implemention for CardService 2021-02-26 10:58:05 -05:00
Tee
2f186599dd Refactor APIService into generic interface 2021-02-26 10:56:55 -05:00
Tee
f30b2313fe Remove QueryBuilder abstraction from CardService 2021-02-26 08:57:15 -05:00
Tee
4006272f4d Refactor newly merged interface names 2021-02-25 22:19:25 -05:00
Tee
43c1987a83 Refactor card interface names from merge 2021-02-25 22:11:17 -05:00
Tee
e8201df35f Transfer API information to client for ownership 2021-02-25 22:09:07 -05:00
Tee
363bcfd321 Refactor query interface imports 2021-02-25 22:08:38 -05:00
Tee
657605eaa0 Add API service interface 2021-02-25 22:08:02 -05:00
Tee
669e6db54c Refactor interface names 2021-02-25 22:02:32 -05:00
Tee
ade8606e8f Merge initial v2 changes 2021-02-25 20:47:55 -05:00
424a32af9c Merge pull request #1 from PokemonTCG/master
Add Initial v2 Data Structure Changes
2021-02-25 20:32:39 -05:00
9d5905a33f Merge pull request #16 from CptSpaceToaster/master
Initial update to v2
2021-02-22 16:15:34 -06:00
74055255e3 Fix tests 2021-02-22 12:05:08 -05:00
239b18bcd3 Initial update to v2 data structures 2021-02-22 12:05:03 -05:00
Tee
cec9ea8c5e Move API constants to client.ts for ownership 2021-02-19 19:29:44 -05:00
Tee
9b6acd5b9a Remove API constants from sdk.ts 2021-02-19 19:29:16 -05:00
25e1972242 1.2.6 2020-11-17 08:12:22 -06:00
668c6740e7 Moved tests and updated Set 2020-11-17 08:12:12 -06:00
20 changed files with 465 additions and 1682 deletions

157
MIGRATING.md Normal file
View File

@ -0,0 +1,157 @@
# Migrating from v1 to v2
The functions and typings in V2 the SDK have been re-named to improve developer experience.
The guide will provide you with the steps to help you migrate your application.
## Type Changes
Interfaces are no longer prefixed with the letter `I`. **Interfaces in the TypeScript compile are used solely for type-checking purposes.**
Originally, `ICard` and `ISet` existed to be implemented with the `Card` and `Set` classes respectively. Because each function is now an independently exported function,
the TypeScript interfaces can be used as intended, which is to simply describe the shape of the data from the API:
`IQuery` was also changed to `Parameter` to complement the [new parameter syntax](https://docs.pokemontcg.io/#api_v2cards_list) in V2 of the API.
* `ICard` -> `Card`
* `ISet` -> `Set`
* `IAbility` -> `Ability`
* `IResistance` -> `Resistance`
* `IWeakness` -> `Weakness`
* `IAttack` -> `Attack`
* `IQuery` -> `Parameter`
## Function Changes
The API functions are no longer abstracted in classes. Instead, each function is an individual export which still returns
data of type `Card` or `Set` to reduce redundancy in the SDK. The function names were renamed to reveal intent as clearly as possible. This results
in code that is self documenting, and enforces a convention where the API functionality is described
thoroughly for developers.
There is no change in the function return types, nor underlying functionality. Functions will continue to return a generic promised based on the resource (i.e. `Promise<Card>`, `Promise<Set>`).
It is recommended to refactor the function names with the find-and-replace tool in your IDE or text editor in order for your project
to be compatible with V2 of the SDK.
## Card Functions
### `PokemonTCG.Card.all()` -> `PokemonTCG.getAllCards()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Card.all();
// V2
PokemonTCG.getAllCards();
```
### `PokemonTCG.Card.find()` -> `PokemonTCG.findCardByID()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Card.find('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
});
// V2
PokemonTCG.findCardByID('xy7-54').then((card: PokemonTCG.Card) => {
console.log(card.name) // Gardevoir
});
```
### `PokemonTCG.Card.where()` -> `PokemonTCG.findCardsByQueries()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value: 'Gardevoir' }];
PokemonTCG.Card.where(paramsV1).then((cards: PokemonTCG.Card[]) => {
console.log(card[0].name) // Gardevoir
});
// V2
const paramsV2: PokemonTCG.Parameter[] = { q: 'id:xy7-54' };
PokemonTCG.findCardsByQueries(paramsV2).then((cards: PokemonTCG.Card[]) => {
console.log(card[0].name) // Gardevoir
});
```
## Set Functions
### `PokemonTCG.Set.all()` -> `PokemonTCG.getAllSets()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Set.all();
// V2
PokemonTCG.getAllSets();
```
### `PokemonTCG.Set.find()` -> `PokemonTCG.findSetByID()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Set.find('base1').then((set: PokemonTCG.Set) => {
console.log(set.name) // Base
});
// V2
PokemonTCG.findSetByID('base1').then((set: PokemonTCG.Set) => {
console.log(set.name) // Base
});
```
### `PokemonTCG.Set.where()` -> `PokemonTCG.findSetsByQueries()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
const paramsV1: PokemonTCG.IQuery[] = [{ name: 'name', value:'Base' }];
PokemonTCG.Set.where(paramsV1).then((sets: PokemonTCG.Set[]) => {
console.log(sets[0].name) // Base
});
// V2
const paramsV2: PokemonTCG.Parameter[] = { q: 'name:Base' };
PokemonTCG.findSetsByQueries(paramsV2).then((sets: PokemonTCG.Set[]) => {
console.log(sets[0].name) // Base
});
```
## Meta Functions
### `PokemonTCG.Meta.allTypes()` -> `PokemonTCG.getTypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.getAllTypes();
// V2
PokemonTCG.getTypes();
```
### `PokemonTCG.Meta.allSupertypes()` -> `PokemonTCG.getSupertypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.allSupertypes();
// V2
PokemonTCG.getSupertypes();
```
### `PokemonTCG.Meta.allSubtypes()` -> `PokemonTCG.getSubtypes()`
```typescript
import { PokemonTCG } from 'pokemon-tcg-sdk-typescript';
// V1
PokemonTCG.Meta.allSubtypes();
// V2
PokemonTCG.getSubtypes();
```

106
README.md
View File

@ -2,6 +2,9 @@
This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io).
# V2 Announcement
Version 1 of this SDK is officially depricated. Version 2 stable release this SDK is scheduled to be released on **Friday, September 17th, 20201**. Version 1 will continue to receive support until then. **See the [migration guide](MIGRATING.md) for steps to update your app to use the latest supported version of the SDK**
## Installation
**npm**
@ -12,35 +15,41 @@ This is the TypeScript SDK for the [Pokemon TCG API](https://pokemontcg.io).
yarn add pokemon-tcg-sdk-typescript
It is recommended to use an API key for version 2 of the API. By default, requests are limited to 20,000/day. Requests are rate limited to 1000 requests a day, and a maximum of 30 per minute.
To use the SDK with an API key, create an account at https://dev.pokemontcg.io to grab an API key. Then set your API key to the environment variable POKEMONTCG_API_KEY in a .env file. Make sure to use this exact environment variable, otherwise the SDK will not be able to read the API key.
## Class Definitions
### Card
```typescript
ability: IAbility;
ancientTrait?: IAncientTrait;
artist: string;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
id: string;
name: string;
supertype: string;
subtypes: string[];
hp?: string;
types?: string[];
evolesFrom?: string;
evolvesTo?: string[];
rules?: string[];
ancientTrait?: IAncientTrait;
abilities?: IAbility[];
attacks?: IAttack[];
weaknesses?: IWeakness[];
resistances?: IResistance[];
retreatCost?: string[];
convertedRetreatCost?: number;
set: ISet;
number: string;
artist?: string;
rarity: string;
flavorText?: string;
nationalPokedexNumbers?: number[];
legalities: ILegality;
images: ICardImage;
tcgplayer?: ITCGPlayer;
cardmarket?: ICardmarket;
```
### IAbility
@ -71,17 +80,16 @@ value: string;
### Set
```typescript
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
updatedAt: string;
id: string;
images: ISetImage;
legalities: ILegality;
name: string;
printedTotal: number;
ptcgoCode: string;
releaseDate: string;
series: string;
total: number;
updatedAt: string;
```
### IQuery
@ -140,17 +148,19 @@ PokemonTCG.Card.all()
```
## Contributing
* Fork it (click the Fork button at the top of the page)
* Create your feature branch (git checkout -b my-new-feature)
* Make some changes and fix some bugs!
* Run the tests `npm run-script test`
* Test your changes in a project of yours:
* Create a link with [npm](https://docs.npmjs.com/cli/link.html) or [yarn](https://yarnpkg.com/lang/en/docs/cli/link/) (depending on what tool you installed this SDK with)
* In your project that **uses** the SDK, install the linked package with `yarn/npm link pokemon-tcg-sdk-typescript`
* Verify the SDK behaves as expected, and your changes took effect
* Commit your changes (git commit -am 'Add some feature')
* Push to the branch (git push origin my-new-feature)
* Create a new Pull Request
* Open an issue
* Describe what the SDK is missing and what changes you'd like to see implemented
* **Ask clarifying questions**
* Fork it (click the Fork button at the top of the page)
* Create your feature branch (git checkout -b my-new-feature)
* Make some changes and fix some bugs!
* Run the tests `npm run-script test`
* Test your changes in a project of yours:
* Create a link with [npm](https://docs.npmjs.com/cli/link.html) or [yarn](https://yarnpkg.com/lang/en/docs/cli/link/) (depending on what tool you installed this SDK with)
* In your project that **uses** the SDK, install the linked package with `yarn/npm link pokemon-tcg-sdk-typescript`
* Verify the SDK behaves as expected, and your changes took effect
* Commit your changes (git commit -am 'Add some feature')
* Push to the branch (git push origin my-new-feature)
* Create a new Pull Request to `master`
## TODO
* Add more testing?

View File

@ -1,6 +1,6 @@
import * as chai from 'chai';
import { Client } from '../client';
import { IQuery } from '../interfaces/query';
import { Client } from '../src/client';
import { IQuery } from '../src/interfaces/query';
const expect = chai.expect;
describe('Client', () => {
@ -13,7 +13,7 @@ describe('Client', () => {
Client.get('cards', params)
.then(response => {
expect(response).to.be.a('array');
expect(response[0].name).to.equal('Gardevoir');
expect(response[0].name).to.equal('Ampharos');
});
});
@ -21,7 +21,7 @@ describe('Client', () => {
Client.get('cards')
.then(response => {
expect(response).to.be.a('array');
expect(response.length).to.equal(100);
expect(response.length).to.equal(250);
});
});
@ -56,7 +56,7 @@ describe('Client', () => {
.then(response => {
expect(response).to.be.a('array');
expect(response[0]).to.be.a('object');
expect(response[0].code).to.equal('base1');
expect(response[0].id).to.equal('base1');
});
});

View File

@ -1,7 +1,7 @@
import * as chai from 'chai';
import { Card } from '../classes/card';
import { QueryBuilder } from '../queryBuilder';
import { IQuery } from '../interfaces/query';
import { Card } from '../src/classes/card';
import { QueryBuilder } from '../src/queryBuilder';
import { IQuery } from '../src/interfaces/query';
const expect = chai.expect;
describe('QueryBuilder', () => {
@ -16,13 +16,8 @@ describe('QueryBuilder', () => {
it('should use where to filter data', () => {
const params: IQuery[] = [
{
name: 'name',
value: 'Charizard'
},
{
name: 'setCode',
value: 'base1'
name: 'q',
value: 'name:Charizard set.id:base1'
}
];
@ -30,14 +25,14 @@ describe('QueryBuilder', () => {
.then(cards => {
expect(cards.length).to.equal(1);
expect(cards[0].id).to.equal('base1-4');
expect(cards[0].set).to.equal('Base');
expect(cards[0].set.name).to.equal('Base');
});
});
it('should use all to get all cards', () => {
QueryBuilder.all<Card>(Card)
.then(cards => {
expect(cards.length).to.equal(1000);
expect(cards.length).to.equal(250);
});
});
});

1531
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "pokemon-tcg-sdk-typescript",
"version": "1.2.5",
"version": "1.3.4",
"description": "Typescript SDK for the PokemonTCG API (https://pokemontcg.io)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@ -11,29 +11,32 @@
"SDK"
],
"scripts": {
"test": "mocha --reporter spec --require ts-node/register 'src/**/*.test.ts'",
"prepare": "npm run build",
"test": "mocha --reporter spec --require ts-node/register 'coverage/**/*.test.ts'",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "https://github.com/PokemonTCG/pokemon-tcg-sdk-typescript"
"url": "https://gitea.sebar.dev/gitea_admin/pokemon-tcg-sdk-typescript.git"
},
"contributors": [
"Bradyn Glines (https://github.com/glinesbdev)",
"CptSpaceToaster (https://github.com/CptSpaceToaster)",
"Monbrey (https://github.com/Monbrey)",
"Jonathan Meyer (https://github.com/jonathan-meyer)"
"Jonathan Meyer (https://github.com/jonathan-meyer)",
"Tee Diang (https://github.com/acupoftee"
],
"license": "MIT",
"dependencies": {
"axios": "^0.19.0",
"typescript": "^2.6.2"
"axios": "^1.7.9"
},
"devDependencies": {
"@types/chai": "^4.1.1",
"@types/mocha": "^2.2.46",
"@types/node": "^14.14.35",
"chai": "^4.1.2",
"mocha": "^8.2.1",
"ts-node": "^4.1.0"
"ts-node": "^4.1.0",
"typescript": "4.1.5"
}
}

View File

@ -1,63 +1,80 @@
import { IAbility } from '../interfaces/ability';
import { IAncientTrait } from '../interfaces/ancientTrait';
import { IAttack } from '../interfaces/attack';
import { ICard } from '../interfaces/card';
import { IQuery } from '../interfaces/query';
import { IResistance } from '../interfaces/resistance';
import { IWeakness } from '../interfaces/weakness';
import { QueryBuilder } from '../queryBuilder';
import { IAbility } from "../interfaces/ability";
import { IAncientTrait } from "../interfaces/ancientTrait";
import { IAttack } from "../interfaces/attack";
import { ICard } from "../interfaces/card";
import { ICardImage } from "../interfaces/image";
import { ICardmarket } from "../interfaces/cardmarket";
import { ILegality } from "../interfaces/legality";
import { IQuery } from "../interfaces/query";
import { IResistance } from "../interfaces/resistance";
import { ISet } from "../interfaces/set";
import { ITCGPlayer } from "../interfaces/tcgplayer";
import { IWeakness } from "../interfaces/weakness";
import { QueryBuilder } from "../queryBuilder";
export class Card implements ICard {
ability: IAbility;
artist: string;
ancientTrait?: IAncientTrait;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
subtypes: string[];
hp?: string;
types?: string[];
evolesFrom?: string;
evolvesTo?: string[];
rules?: string[];
ancientTrait?: IAncientTrait;
abilities?: IAbility[];
attacks?: IAttack[];
weaknesses?: IWeakness[];
resistances?: IResistance[];
retreatCost?: string[];
convertedRetreatCost?: number;
set: ISet;
number: string;
artist?: string;
rarity: string;
flavorText?: string;
nationalPokedexNumbers?: number[];
legalities: ILegality;
regulationMark?: string;
images: ICardImage;
tcgplayer?: ITCGPlayer;
cardmarket?: ICardmarket;
resource(): string {
return 'cards';
return "cards";
}
/**
* @deprecated `Card.find` is renamed to `findCardById` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async find(id: string): Promise<Card> {
return QueryBuilder.find(this, id)
.then(response => {
.then((response) => {
return response;
})
.catch(error => Promise.reject(error));
.catch((error) => Promise.reject(error));
}
/**
* @deprecated `Card.all` is renamed to `getAllCards` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async all(): Promise<Card[]> {
return QueryBuilder.all(this)
.then(response => {
.then((response) => {
return response;
})
.catch(error => Promise.reject(error));
.catch((error) => Promise.reject(error));
}
/**
* @deprecated `Card.where` is renamed to `findCardsByQueries` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async where(params: IQuery[]): Promise<Card[]> {
return QueryBuilder.where(this, params)
.then(response => {
.then((response) => {
return response;
})
.catch(error => Promise.reject(error));
.catch((error) => Promise.reject(error));
}
}
}

View File

@ -1,15 +1,35 @@
import { Client } from '../client';
export class Meta {
/**
* @deprecated `allTypes` is renamed to `getAllTypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async allTypes(): Promise<string[]> {
return Client.get('types');
const resposne = await Client.get('types');
return resposne;
}
/**
* @deprecated `allSubtypes` is renamed to `getAllSubtypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async allSubtypes(): Promise<string[]> {
return Client.get('subtypes');
const response = await Client.get('subtypes');
return response;
}
/**
* @deprecated `allSupertypes` is renamed to `getAllSupertypes` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async allSupertypes(): Promise<string[]> {
return Client.get('supertypes');
const response = await Client.get('supertypes');
return response;
}
}
/**
* @deprecated `allRarities` is renamed to `getAllRarities` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async allRarities(): Promise<string[]> {
const response = await Client.get('rarities');
return response;
}
}

View File

@ -1,24 +1,28 @@
import { ISet } from '../interfaces/set';
import { IQuery } from '../interfaces/query';
import { QueryBuilder } from '../queryBuilder';
import { ILegality } from '../interfaces/legality';
import { ISetImage } from '../interfaces/image';
export class Set implements ISet {
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
id: string;
images: ISetImage;
legalities: ILegality;
name: string;
printedTotal: number;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
series: string;
total: number;
updatedAt: string;
resource(): string {
return 'sets';
}
/**
* @deprecated `Set.find` is renamed to `findSetById` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async find(id: string): Promise<Set> {
return QueryBuilder.find(this, id)
.then(response => {
@ -27,6 +31,9 @@ export class Set implements ISet {
.catch(error => Promise.reject(error));
}
/**
* @deprecated `Set.all` is renamed to `getAllSets` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async all(): Promise<Set[]> {
return QueryBuilder.all(this)
.then(response => {
@ -35,6 +42,9 @@ export class Set implements ISet {
.catch(error => Promise.reject(error));
}
/**
* @deprecated `Set.where` is renamed to `findSetsByQueries` in version 2. See the **[migration guide](https://github.com/acupoftee/pokemon-tcg-sdk-typescript/blob/master/MIGRATING.md)** for more info.
*/
static async where(params: IQuery[]): Promise<Set[]> {
return QueryBuilder.where(this, params)
.then(response => {
@ -42,4 +52,4 @@ export class Set implements ISet {
})
.catch(error => Promise.reject(error));
}
}
}

View File

@ -7,12 +7,17 @@ export class Client {
static async get(resource: string, params?: IQuery[] | string): Promise<any> {
let url: string = `${this.apiUrl}/${resource}`;
const POKEMONTCG_API_KEY = process.env.POKEMONTCG_API_KEY;
const config: axios.AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json'
}
};
if (POKEMONTCG_API_KEY) {
config.headers['X-Api-Key'] = POKEMONTCG_API_KEY;
}
if(typeof params === 'string') url += `/${params}`;
else url += `?${this.paramsToQuery(params)}`;
@ -34,4 +39,4 @@ export class Client {
return query;
}
}
}

View File

@ -1,5 +1,5 @@
export interface IAttack {
convertedEnergyCost: string;
convertedEnergyCost: number;
cost: string[];
damage: string;
name: string;

View File

@ -1,32 +1,40 @@
import { IAbility } from '../interfaces/ability';
import { IAncientTrait } from './ancientTrait';
import { IAttack } from '../interfaces/attack';
import { IResistance } from '../interfaces/resistance';
import { IWeakness } from '../interfaces/weakness';
import { IAbility } from "../interfaces/ability";
import { IAncientTrait } from "./ancientTrait";
import { IAttack } from "../interfaces/attack";
import { IResistance } from "../interfaces/resistance";
import { IWeakness } from "../interfaces/weakness";
import { ICardImage } from "./image";
import { ICardmarket } from "./cardmarket";
import { ILegality } from "./legality";
import { ISet } from "./set";
import { ITCGPlayer } from "./tcgplayer";
export interface ICard {
ability: IAbility;
ancientTrait?: IAncientTrait;
artist: string;
attacks: IAttack[];
convertedRetreatCost: number;
evolvesFrom: string;
hp: string;
id: string;
imageUrl: string;
imageUrlHiRes: string;
name: string;
nationalPokedexNumber: number;
number: string;
rarity: string;
resistances: IResistance[];
retreatCost: string[];
series: string;
set: string;
setCode: string;
subtype: string;
supertype: string;
text: string[];
types: string[];
weaknesses: IWeakness[];
}
subtypes: string[];
hp?: string;
types?: string[];
evolvesFrom?: string;
evolvesTo?: string[];
rules?: string[];
ancientTrait?: IAncientTrait;
abilities?: IAbility[];
attacks?: IAttack[];
weaknesses?: IWeakness[];
resistances?: IResistance[];
retreatCost?: string[];
convertedRetreatCost?: number;
set: ISet;
number: string;
artist?: string;
rarity: string;
flavorText?: string;
nationalPokedexNumbers?: number[];
legalities: ILegality;
regulationMark?: string;
images: ICardImage;
tcgplayer?: ITCGPlayer;
cardmarket?: ICardmarket;
}

View File

@ -0,0 +1,21 @@
export interface ICardmarket {
url: string;
updatedAt: string;
prices: {
averageSellPrice: number | null
lowPrice: number | null
trendPrice: number | null
germanProLow: number | null
suggestedPrice: number | null
reverseHoloSell: number | null
reverseHoloLow: number | null
reverseHoloTrend: number | null
lowPriceExPlus: number | null
avg1: number | null
avg7: number | null
avg30: number | null
reverseHoloAvg1: number | null
reverseHoloAvg7: number | null
reverseHoloAvg30: number | null
}
}

9
src/interfaces/image.ts Normal file
View File

@ -0,0 +1,9 @@
export interface ISetImage {
symbol: string;
logo: string;
}
export interface ICardImage {
small: string;
large: string;
}

View File

@ -0,0 +1,10 @@
export enum Legality {
LEGAL = 'Legal',
BANNED = 'Banned',
}
export interface ILegality {
expanded: Legality | undefined
standard: Legality | undefined
unlimited: Legality | undefined
}

View File

@ -1,14 +1,15 @@
import { ISetImage } from "./image";
import { ILegality } from "./legality";
export interface ISet {
code: string;
expandedLegal: boolean;
logoUrl: string;
name: string;
id: string;
images: ISetImage;
legalities: ILegality;
name: string;
printedTotal: number;
ptcgoCode: string;
releaseDate: string;
series: string;
standardLegal: boolean;
symbolUrl: string;
totalCards: number;
series: string;
total: number;
updatedAt: string;
updatedSince: string;
}

View File

@ -0,0 +1,19 @@
export interface ITCGPlayer {
url: string;
updatedAt: string;
prices: {
normal: IPrice | undefined;
holofoil: IPrice | undefined;
reverseHolofoil: IPrice | undefined;
'1stEditionNormal': IPrice | undefined;
'1stEditionHolofoil': IPrice | undefined;
}
}
export interface IPrice {
low: number | null
mid: number | null
high: number | null
market: number | null
directLow: number | null
}

View File

@ -8,7 +8,7 @@ export class QueryBuilder {
const t = new type();
const params: IQuery[] = [{
name: 'pageSize',
value: 1000
value: 250,
}];
return Client.get(t.resource(), params);

View File

@ -1,6 +1,6 @@
// Constants
export const API_URL: string = 'https://api.pokemontcg.io';
export const API_VERSION: string = '1';
export const API_VERSION: string = '2';
// Classes
export * from './classes/card';
@ -11,6 +11,7 @@ export * from './classes/meta';
export * from './interfaces/ability';
export * from './interfaces/attack';
export * from './interfaces/card';
export * from './interfaces/set';
export * from './interfaces/query';
export * from './interfaces/resistance';
export * from './interfaces/weakness';

View File

@ -6,9 +6,13 @@
"outDir": "./dist",
"sourceMap": true,
"experimentalDecorators": true,
"lib": ["ES2015"]
"lib": ["ES6"]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"coverage"
]
}