Compare commits

..

17 Commits

Author SHA1 Message Date
d42b0057c7 v2.0.0-alpha.2 2021-03-11 10:40:39 +01:00
b13e554162 V2 added typing for compiler
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-03-11 10:10:44 +01:00
1db0b1ab38 Updated SDK to support new incoming datas
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-02-13 20:04:50 +01:00
97acf4287f v1.7.0 2021-01-31 13:49:49 +01:00
7f0e95d574 Added the new Rarity v1.7.0
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-31 13:49:36 +01:00
b7d8fac835 v1.6.1
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-31 13:46:57 +01:00
d965aabad7 v1.6.1 2021-01-31 13:28:23 +01:00
e22d63d2ee Merge branch 'master' of github.com:tcgdex/javascript-sdk 2021-01-08 15:21:51 +01:00
5d2b836af6 Publish update
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:21:34 +01:00
dd7e252027 Remove console.warn
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:21:20 +01:00
c4fff9b370 Let the enduser handle not found errors
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 15:20:19 +01:00
610d2590e8 Update package.json 2021-01-08 11:54:41 +01:00
b180369514 1.5.1 - Because 1.5 already existed
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 11:44:51 +01:00
17ffd73fb3 Publish Update
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 11:41:42 +01:00
ec4f5d1a84 Merge branch 'master' of github.com:tcgdex/javascript-sdk 2021-01-08 11:40:50 +01:00
ae7f3077c0 Added raw getSet that don't process Date
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-01-08 11:39:01 +01:00
2c0a12a2e8 Update dependency typescript to v3.9.5 (#4)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2020-06-24 10:04:19 +02:00
26 changed files with 296 additions and 739 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@ node_modules
# Dist files
*.js
*.d.ts
!interfaces.d.ts
test.ts

View File

@ -1 +1,6 @@
test.js
.editorconfig
.gitignore
.npmignore
tsconfig.json
*.ts
yarn.lock

View File

@ -2,7 +2,7 @@
MIT License
Copyright (c) 2020 TCGdex
Copyright (c) 2021 TCGdex
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -23,7 +23,7 @@ export class Request<T = any> {
this.url = url
}
public async get(): Promise<T> {
public async get(): Promise<T | undefined> {
const now = new Date()
if (
this.fetched &&
@ -34,22 +34,17 @@ export class Request<T = any> {
}
// Fetch Response
try {
const resp = await fetch(this.url, {
headers: {
"Content-Type": "text/plain"
}
})
if (resp.status !== 200) {
throw new Error(`Error request ended with the code (${resp.status})`)
const resp = await fetch(this.url, {
headers: {
"Content-Type": "text/plain"
}
const response = await resp.json()
this.response = response
this.fetched = now
return response
} catch (e) {
console.error(e)
throw new Error('An error occured')
})
if (resp.status !== 200) {
return undefined
}
const response = await resp.json()
this.response = response
this.fetched = now
return response
}
}

View File

@ -1,53 +0,0 @@
import LangList, { Langs } from "./interfaces/LangList";
import AbilityType from "./interfaces/AbilityType";
import Category from "./interfaces/Category";
import Rarity from "./interfaces/Rarity";
import Tag from "./interfaces/Tag";
import Type from "./interfaces/Type";
import atTrans from './translations/abilityType'
import cTrans from './translations/category'
import rTrans from './translations/rarity'
import taTrans from './translations/tag'
import tyTrans from './translations/type'
type possibilities = "abilityType" | "category" | "rarity" | "tag" | "type"
export default class TranslationUtil {
public static translate(master: "abilityType",a: AbilityType, lang: Langs): string|undefined;
public static translate(master: "category",a: Category, lang: Langs): string|undefined;
public static translate(master: "rarity",a: Rarity, lang: Langs): string|undefined;
public static translate(master: "tag",a: Tag, lang: Langs): string|undefined;
public static translate(master: "type",a: Type, lang: Langs): string|undefined;
public static translate(master: possibilities,a: number, lang: Langs): string|undefined {
let langlist: LangList<Array<string>>|undefined
switch (master) {
case 'abilityType':
langlist = atTrans
break
case 'category':
langlist = cTrans
break
case 'rarity':
langlist = rTrans
break
case 'tag':
langlist = taTrans
break
case 'type':
langlist = tyTrans
break
default:
break;
}
if (!langlist) return
const tmp = langlist[lang]
if (!tmp) return
return tmp[a]
}
}
export type translations = LangList<Array<string>>

235
interfaces.d.ts vendored Normal file
View File

@ -0,0 +1,235 @@
export type SupportedLanguages = 'en' | 'fr'
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
interface SerieResume {
id: string
name: string
}
export interface Serie extends SerieResume {
sets: SetList
}
interface variants {
normal?: boolean
reverse?: boolean
holo?: boolean
firstEdition?: boolean
}
export type Types = 'Colorless' | 'Darkness' | 'Dragon' |
'Fairy' | 'Fightning' | 'Fire' |
'Grass' | 'Lightning' | 'Metal' |
'Psychic' | 'Water'
export type SetList = Array<SetResume>
export type SerieList = Array<SerieResume>
export type CardList = Array<CardResume>
interface SetResume {
id: string
name: string
logo?: string
symbol?: string
cardCount: {
total: number
official: number
}
}
export interface Set extends SetResume {
serie: SerieResume
tcgOnline?: string
variants?: variants
releaseDate: string
legal?: {
standard: boolean
expanded: boolean
}
cards: CardList
}
interface CardResume {
id: string
localId: string
/**
* Card Name (Including the suffix if next to card name)
*/
name: string
image?: string
}
export interface Card<SetType extends SetResume = SetResume> extends CardResume {
/**
* Card illustrator
*/
illustrator?: string
/**
* Card Rarity
*
* - None https://www.tcgdex.net/database/sm/smp/SM01
* - Common https://www.tcgdex.net/database/xy/xy9/1
* - Uncommon https://www.tcgdex.net/database/xy/xy9/2
* - Rare https://www.tcgdex.net/database/xy/xy9/3
* - Ultra Rare
* - Secret Rare
*/
rarity: 'None' | 'Common'| 'Uncommon' | 'Rare' | 'Ultra Rare' | 'Secret Rare'
/**
* Card Category
*
* - Pokemon
* - Trainer
* - Energy
*/
category: 'Pokemon' | 'Trainer' | 'Energy'
/**
* Card Variants (Override Set Variants)
*/
variants?: variants
/**
* Card Set
*/
set: SetType
/**
* Pokemon only elements
*/
/**
* Pokemon Pokedex ID
*/
dexId?: Array<number>
/**
* Pokemon HP
*/
hp?: number
/**
* Pokemon Types
*/
types?: Array<Types> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
/**
* Pokemon Sub Evolution
*/
evolveFrom?: string
/**
* Pokemon Weight
*/
weight?: string
/**
* Pokemon Description
*/
description?: string
/**
* Level of the Pokemon
*
* NOTE: can be equal to 'X' when the pokemon is a LEVEL-UP one
*/
level?: number | string
/**
* Pokemon Stage
*
* - Basic https://www.tcgdex.net/database/xy/xy9/1
* - BREAK https://www.tcgdex.net/database/xy/xy9/18
* - LEVEL-UP https://www.tcgdex.net/database/dp/dp1/121
* - MEGA https://www.tcgdex.net/database/xy/xy1/2
* - RESTORED https://www.tcgdex.net/database/bw/bw5/53
* - Stage1 https://www.tcgdex.net/database/xy/xy9/2
* - Stage2 https://www.tcgdex.net/database/xy/xy9/3
* - VMAX https://www.tcgdex.net/database/swsh/swsh1/50
*/
stage?: 'Basic' | 'BREAK' | 'LEVEL-UP' | 'MEGA' | 'RESTORED' | 'Stage1' | 'Stage2' | 'VMAX'
/**
* Card Suffix
*
* - EX https://www.tcgdex.net/database/ex/ex2/94
* - GX https://www.tcgdex.net/database/sm/sm12/4
* - V https://www.tcgdex.net/database/swsh/swsh1/1
* - Legend https://www.tcgdex.net/database/hgss/hgss1/114
* - Prime https://www.tcgdex.net/database/hgss/hgss2/85
* - SP https://www.tcgdex.net/database/pl/pl1/7
* - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226
*/
suffix?: 'EX' | 'GX' | 'V' | 'Legend' | 'Prime' | 'SP' | 'TAG TEAM-GX'
/**
* Pokemon Held Item
*
* ex https://www.tcgdex.net/database/dp/dp2/75
*/
item?: {
name: string
effect: string
}
/**
* Pokemon Abilities
*
* multi abilities ex https://www.tcgdex.net/database/ex/ex15/10
*/
abilities?: Array<{
type: 'Pokemon Power' | 'Poke-BODY' | 'Poke-POWER' | 'Ability' | 'Ancient Trait'
name: string
effect: string
}>
/**
* Pokemon Attacks
*/
attacks?: Array<{
cost?: Array<Types>
name: string
effect?: string
damage?: string | number
}>
/**
* Pokemon Weaknesses
*/
weaknesses?: Array<{
type: Types
value?: string
}>
resistances?: Array<{
type: Types
value?: string
}>
retreat?: number
//Trainer/Energy
effect?: string
// Trainer Only
trainerType?: 'Supporter' | // https://www.tcgdex.net/database/ex/ex7/83
'Item' | // https://www.tcgdex.net/database/ex/ex7/89
'Stadium' | // https://www.tcgdex.net/database/ex/ex7/87
'Tool' | // https://www.tcgdex.net/database/neo/neo1/93
'Ace Spec' | // https://www.tcgdex.net/database/bw/bw7/139
'Technical Machine' | // https://www.tcgdex.net/database/ecard/ecard1/144
'Goldenred Game Corner' | // https://www.tcgdex.net/database/neo/neo1/83
'Rocket\'s Secret Machine' // https://www.tcgdex.net/database/ex/ex7/84
// Energy Only
energyType?: 'Normal' | // https://www.tcgdex.net/database/ecard/ecard1/160
'Special' // https://www.tcgdex.net/database/ecard/ecard1/158
}

View File

@ -1,19 +0,0 @@
import AbilityType, { AbilityTypeSimple } from "./AbilityType";
import LangList from "./LangList";
export interface AbilitySingle extends AbilitySimple {
type: AbilityTypeSimple
text: string
}
export interface AbilitySimple {
// id: number // WIP
name: string
}
export default interface Ability {
id?: number
type: AbilityType
name: LangList<string>
text: LangList<string>
}

View File

@ -1,19 +0,0 @@
export interface AbilityTypeSimple {
id: AbilityType
name: string
}
export type AbilityTypeSingle = {
id: AbilityType
name: string
cards: string
}
enum AbilityType {
POKEBODY,
POKEPOWER,
TALENT,
ANCIENTTRAIT
}
export default AbilityType

View File

@ -1,20 +0,0 @@
import Type from "./Type";
import LangList from "./LangList";
export interface AttackSingle extends AttackSimple {
cost?: Array<string>
text?: string
damage?: string|number
}
export interface AttackSimple {
// id: number
name: string
}
export default interface Attack {
cost?: Array<Type>
name: LangList<string>
text?: LangList<string>
damage?: string|number
}

View File

@ -1,139 +0,0 @@
import Type, { TypeSimple } from "./Type";
import Tag, { TagSimple } from "./Tag";
import { RaritySimple, Rarity } from "./Rarity";
import { CategorySimple, Category } from "./Category";
import { IllustratorSimple } from "./Illustrator";
import Ability, { AbilitySingle } from "./Ability";
import Attack, { AttackSingle } from "./Attack";
import { List } from "./General";
import LangList from "./LangList";
import Set from "./Set";
export interface CardSimple {
id: string
localId: string|number
name: string
image: string
}
export interface CardSingle {
// General
id: string
localId: number|string
name: string
image?: {
low: string
high?: string
}
tags: Array<TagSimple>
illustrator?: IllustratorSimple
rarity: RaritySimple
category: CategorySimple
set: {
name: string
code: string
}
/**
* Some Pokémons have item like a berry
*/
item?: {
name: string
effect: string
}
// Pokémon only
hp?: number
dexId?: number
lvl?: number
type?: Array<TypeSimple>
evolveFrom?: string
evolveTo?: Array<string>
abilities?: Array<AbilitySingle>
attacks?: Array<AttackSingle>
weaknesses?: Array<WeakRes>
resistances?: Array<WeakRes>
retreat?: number
// Trainer/Energy only
effect?: string
}
export type CardList = List<CardSimple>
type WeakRes = {
type: TypeSimple
value?: string
}
type Card = {
// global id made of setid and localId
id: string
// set id
localId: string|number
dexId?: number
// Card informations (from top to bottom of card)
name: LangList<string>
hp?: number //optionnal because energy/trainer cards might have not any hp
type?: Array<Type> // ex for multiple https://api.pokemon.com/us/pokemon-tcg/pokemon-cards/ex-series/ex13/17/
image?: {
low: LangList<string>
high?: LangList<string>
}
evolveFrom?: LangList<string>
evolveTo?: Array<LangList<string>>
tags: Array<Tag> // made after
illustrator?: string
abilities?: Array<Ability>
attacks?: Array<Attack>
// If card is trainer or energy effect is here
effect?: LangList<string>
item?: {
name: LangList<string>
effect: LangList<string>
}
weaknesses?: Array<{
type: Type
value?: string
}>
resistances?: Array<{
type: Type
value?: string
}>
retreat?: number
rarity: Rarity
// Other elements
category: Category
set: {
name: string
code: string
}| Set
/**
* Override Set defaults
*/
cardTypes?: {
normal: boolean
reverse: boolean
holo: boolean
firstEd: boolean
}
}
export default Card

View File

@ -1,24 +0,0 @@
import { List } from "./General"
import { CardSimple } from "./Card"
export enum Category {
POKEMON,
TRAINER,
ENERGY
}
export default Category
export type CategorySingle = {
id: Category
name: string
cards: Array<CardSimple>
}
export type CategorySimple = {
id: Category
name: string
}
export type CategoryList = List<CategorySimple>

View File

@ -1,22 +0,0 @@
import { SetSimple } from "./Set";
import { List } from "./General";
import LangList from "./LangList";
export type ExpansionSingle = {
code: string
name: string
sets: Array<SetSimple>
}
export type ExpansionSimple = {
code: string
name: string
}
export type ExpansionList = List<ExpansionSimple>
export default interface Expansion {
name: LangList<string> | string
code: string
sets?: Array<string>
}

View File

@ -1,4 +0,0 @@
export type List<T> = {
count: number
list: Array<T>
}

View File

@ -1,11 +0,0 @@
import { CardSimple } from "./Card";
import { List } from "./General";
export type HpSingle = {
hp: number
cards: Array<CardSimple>
}
export type HpSimple = number
export type HpList = List<HpSimple>

View File

@ -1,22 +0,0 @@
import { CardSimple } from "./Card";
import { List } from "./General";
export type IllustratorSingle = {
id: number,
name: string,
cards: Array<CardSimple>
}
export interface IllustratorSimple {
id: number
name: string
}
export type IllustratorsList = List<IllustratorSimple>
interface Illustrator {
id: number
name: string
}
export default Illustrator

View File

@ -1,15 +0,0 @@
type LangList<T> = {
[key in Langs]?: T
}
export type Langs = "en" | "fr"
namespace LangList {
export function insert(from: LangList<any>, el: any, lang: Langs) {
if (typeof from !== "object") from = {}
from[lang] = el
return from
}
}
export default LangList

View File

@ -1,6 +0,0 @@
import { Langs as l } from './LangList'
/**
* @deprecated
*/
export type Langs = l

View File

@ -1,29 +0,0 @@
import { List } from "./General"
import { CardSimple } from "./Card"
export enum Rarity {
NONE,
COMMON,
UNCOMMON,
RARE,
// Both RAREULTRA and ULTRARARE are the same until I know the correct name
RAREULTRA = 4,
ULTRARARE = 4
}
export default Rarity
export interface RaritySimple {
id: Rarity
name: string
}
export type RaritySingle = {
id: Rarity
name: string
cards: Array<CardSimple>
}
export type RarityList = List<RaritySimple>

View File

@ -1,11 +0,0 @@
import { CardSimple } from "./Card";
import { List } from "./General";
export type RetreatSimple = number
export interface RetreatSingle {
id: RetreatSimple
cards: Array<CardSimple>
}
export type RetreatList = List<RetreatSimple>

View File

@ -1,160 +0,0 @@
import { CardSimple } from "./Card";
import { List } from "./General";
import LangList from "./LangList";
import Expansion from "./Expansion";
export type SetRequest = SetSingle
export type SetSingle = {
name: string
code: string
expansionCode?: string
tcgoCode?: string
cardCount: {
total: number
official: number
}
releaseDate: Date|string
legal?: {
standard: boolean
expanded: boolean
}
images?: {
symbol?: string
logo?: string
}
list: Array<CardSimple>
}
export type SetSimple = {
code: string
name: string
logo?: string
symbol?: string
total: number
}
export type SetList = List<SetSimple>
export default interface Set {
/**
* Display Name
*/
name: LangList<string> | string
/**
* Expansion Object
*/
expansion?: Expansion
/**
* Expansion code
*/
expansionCode?: string
/**
* Set code (Also used as the slug)
*/
code: string
/**
* Trading card online code
*/
tcgoCode?: string
cardCount: {
/**
* total number of cards including secrets
*/
total: number
/**
* number of card indicated at the bottom of each cards
*/
official: number
}
cardTypes?: {
/**
* Default: true
*/
normal: boolean
/**
* Default: true
*/
reverse: boolean
/**
* Default: true
*/
holo: boolean
/**
* Default: false
*/
ed1: boolean
}
/**
* Format of numbering
* ex: SWSH[000] mean that it has SWSH as prefix and start at 000 -> 001 -> 002 -> etc
*
* @type {string}
* @memberof Set
*/
format?: string
/**
* Release date of the set
* in format: yyyy-mm-dd
* ex: 2002-12-22
*
* @type {string}
* @memberof Set
*/
releaseDate: string // date in format yyyy-mm-dd
/**
* Aol Endpoint for scrapping
*/
api?: string
/**
* Competition usage
*/
legal?: {
standard: boolean
expanded: boolean
}
images?: {
/**
* Symbol icon on bottom of card
* available extensions [
* webp
* jpg
* png
* ]
*/
symbol?: string
/**
* Official logo of set
* available extensions [
* webp
* jpg
* png
* ]
*/
logo?: string
}
/**
* Language in which the set is available
*/
availability?: LangList<boolean>
}

View File

@ -1,98 +0,0 @@
import { List } from "./General"
import { CardSimple } from "./Card"
/**
* Anum of "Tags" each card can contains
*
* @enum {number}
*/
enum Tag {
/**
* basic pokémon
*/
BASIC,
/**
* Basic Energy
*/
BASICENERGY,
BREAK,
EX,
GX,
ITEM,
LEGEND,
LEVELUP,
MEGA,
RESTORED,
ROCKETSECRETMACHINE,
SP,
SPECIAL,
STADIUM,
/**
* Stage 1 pokémon
*/
STAGE1,
/**
* Stage 2 Pokémon
*/
STAGE2,
SUPPORTER,
TAGTEAM,
TECHNICALMACHINE,
TOOL,
/**
* V Pokémon
*/
V,
/**
* VMAX Pokémon
*/
VMAX,
/**
* The card is available with the holographic picture
*/
HASHOLO,
/**
* Card can have a 1st badge
*/
HAS1ST,
/**
* Card is full art (art is not in the frame)
*/
ISFULLART,
/**
* PRIME Pokemon
*/
PRIME,
/**
* ACE Pokemon
*/
ACE,
/**
* Card is "rainbow"
*/
RAINBOW,
}
export default Tag
export interface TagSimple {
id: Tag
name: string
}
export type TagSingle = {
id: Tag
name: string
cards: Array<CardSimple>
}
export type TagList = List<TagSimple>

View File

@ -1,31 +0,0 @@
import { List } from "./General"
import { CardSimple } from "./Card"
enum Type {
COLORLESS,
DARKNESS,
DRAGON,
FAIRY,
FIGHTING,
FIRE,
GRASS,
LIGHTNING,
METAL,
PSYCHIC,
WATER,
}
export interface TypeSimple {
id: Type
name: string
}
export type TypeSingle = {
id: Type
name: string
cards: Array<CardSimple>
}
export type TypeList = List<TypeSimple>
export default Type

View File

@ -1,9 +1,9 @@
{
"name": "@tcgdex/sdk",
"version": "1.4.2",
"version": "2.0.0-alpha.2",
"main": "./tcgdex.js",
"types": "./tcgdex.d.ts",
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
"repository": "https://github.com/tcgdex/javascript-sdk.git",
"license": "MIT",
"devDependencies": {
"@types/node-fetch": "2.5.7",

View File

@ -1,5 +0,0 @@
{
"extends": [
"config:base"
]
}

View File

@ -1,16 +1,10 @@
import { Langs } from './interfaces/Langs'
import { SetSingle, SetSimple, SetList } from './interfaces/Set'
import { CardSingle, CardList, CardSimple } from './interfaces/Card'
import { ExpansionSingle, ExpansionList } from './interfaces/Expansion'
import RequestWrapper from './Request'
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages } from './interfaces'
export default class TCGdex {
public static defaultLang: Langs = "en"
public lang?: Langs
public static defaultLang: SupportedLanguages = "en"
public constructor(lang?: Langs) {
if (lang) this.lang = lang
}
public constructor(public lang?: SupportedLanguages) {}
public getLang() {
return this.lang || TCGdex.defaultLang
@ -18,59 +12,73 @@ export default class TCGdex {
private getBaseUrl() {
return `https://api.tcgdex.net/v1/${this.getLang()}`
return `https://api.tcgdex.net/v2/${this.getLang()}`
}
private gbu() {
return this.getBaseUrl()
}
public async getCard(id: string|number, set: string): Promise<CardSingle>;
public async getCard(id: string): Promise<CardSingle>;
public async getCard(id: string|number, set?: string): Promise<CardSingle> {
public async getCard(id: string|number, full: true, set?: string): Promise<Card<Set> | undefined>
// @ts-expect-error Temporary while building it in the compiler
public async getCard(id: string|number, full?: boolean, set?: string): Promise<Card | undefined> {
const txt = set ? `sets/${set}` : "cards"
const req = this.rwgr<CardSingle>(`${this.gbu()}/${txt}/${id}/`)
const req = this.rwgr<Card>(`${this.gbu()}/${txt}/${id}/`)
return req.get()
}
public async getCards(set?: string): Promise<Array<CardSimple>> {
public async getCards(set?: string): Promise<Array<CardResume> | undefined> {
if (set) {
const setSingle = await this.getSet(set)
return setSingle.list
if (!setSingle) {
return undefined
}
return setSingle.cards
}
console.warn("note: while it's possible to fetch every cards at once it's not recommended as it take much more time than any other requests")
const req = this.rwgr<CardList>(`${this.gbu()}/cards/`)
const req = this.rwgr<Array<CardResume>>(`/cards/`)
const resp = await req.get()
return resp.list
if (!resp) {
return undefined
}
return resp
}
public async getSet(set: string): Promise<SetSingle> {
const req = this.rwgr<SetSingle>(`${this.gbu()}/sets/${set}/`)
public async getSet(set: string): Promise<Set | undefined> {
const req = this.rwgr<Set>(`/sets/${set}/`)
const resp = await req.get()
return Object.assign(resp, {releaseDate: new Date(resp.releaseDate)}) as SetSingle
if (!resp) {
return undefined
}
return resp
}
public async getExpansion(expansion: string): Promise<ExpansionSingle> {
const req = this.rwgr<ExpansionSingle>(`${this.gbu()}/expansions/${expansion}/`)
public async getSerie(expansion: string): Promise<Serie | undefined> {
const req = this.rwgr<Serie>(`/expansions/${expansion}/`)
return req.get()
}
public async getExpansions(): Promise<ExpansionList> {
const req = this.rwgr<ExpansionList>(`${this.gbu()}/expansions/`)
public async getSeries(): Promise<SerieList | undefined> {
const req = this.rwgr<SerieList>(`/expansions/`)
return req.get()
}
public async getSets(expansion?: string): Promise<Array<SetSimple>> {
public async getSets(expansion?: string): Promise<SetList | undefined> {
if (expansion) {
const expansionSingle = await this.getExpansion(expansion)
const expansionSingle = await this.getSerie(expansion)
if (!expansionSingle) {
return undefined
}
return expansionSingle.sets
}
const req = this.rwgr<SetList>(`${this.gbu()}/sets/`)
const req = this.rwgr<SetList>(`/sets/`)
const list = await req.get()
return list.list
if (!list) {
return undefined
}
return list
}
private rwgr<T = any>(url: string) {
return RequestWrapper.getRequest<T>(url)
return RequestWrapper.getRequest<T>(`${this.gbu()}${url}`)
}
}

View File

@ -1,5 +1,6 @@
{
"include": ["**/*.ts"],
"exclude": ["translations"],
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */