diff --git a/.gitignore b/.gitignore index dc46084..38ef676 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ coverage # Dist files dist src/version.js + +.DS_Store \ No newline at end of file diff --git a/__tests__/basic.test.ts b/__tests__/basic.test.ts index dac9cea..fca5b58 100644 --- a/__tests__/basic.test.ts +++ b/__tests__/basic.test.ts @@ -158,3 +158,15 @@ test(`Variant Detailed`, async () => { expect((await tcgdex.card.get('me02-001'))?.variantsDetailed?.[0].type).toBeTruthy() }) + +test(`Variant Pricing`, async () => { + const tcgdex = new TCGdex('en') + TCGdex.fetch = fetch + const card = await tcgdex.card.get('me02-001') + // for backwards compatibility until V3 + expect(card?.pricing).toBeTruthy() + const normalVariant = card?.variantsDetailed?.find(v => v.type === 'normal') + expect(normalVariant?.pricing?.cardmarket).toBeTruthy() + expect(normalVariant?.pricing?.tcgplayer).toBeTruthy() +}) + diff --git a/src/interfaces.d.ts b/src/interfaces.d.ts index cfad0a6..a9ba77f 100644 --- a/src/interfaces.d.ts +++ b/src/interfaces.d.ts @@ -1,3 +1,5 @@ +import type { Pricing } from "./models/Other" + export type SupportedLanguages = 'en' | 'fr' | 'es' | 'es-mx' | 'it' | 'pt' | 'pt-br' | 'de' | 'nl' | 'pl' | 'ru' | 'ja' | 'ko' | 'zh-tw' | 'id' | 'th' | 'zh-cn' @@ -316,6 +318,8 @@ export interface Card extends CardResume expanded: boolean } + pricing?: Pricing; + boosters?: BoosterList } diff --git a/src/models/Card.ts b/src/models/Card.ts index e57819a..52b5d98 100644 --- a/src/models/Card.ts +++ b/src/models/Card.ts @@ -1,6 +1,6 @@ import { objectLoop } from '@dzeio/object-util' import CardResume from './CardResume' -import type { Booster, Variants, VariantsDetailed } from './Other' +import type { Booster, Pricing, Variants, VariantsDetailed } from './Other' import type TCGdexSet from './Set' import type SetResume from './SetResume' @@ -195,6 +195,14 @@ export default class Card extends CardResume { expanded: boolean } + /** + * Card pricing object which ingests pricing based off tcgplayer and cardmarket + * + * Note: Not availible for all cards. + */ + + public pricing?: Pricing; + public boosters?: Array public override async getCard(): Promise { diff --git a/src/models/Other.d.ts b/src/models/Other.d.ts index 00c8b8f..4107562 100644 --- a/src/models/Other.d.ts +++ b/src/models/Other.d.ts @@ -6,7 +6,6 @@ export interface Variants { } export interface Booster { - id: string name: string logo?: string @@ -61,14 +60,63 @@ export interface VariantsDetailed { */ foil?: string /** - * IDs from third part websites + * pricing data from third party websites */ - thirdParty?: { - cardmarket?: number - tcgplayer?: number - } + pricing?: Pricing; /** * A unique ID defining this variant */ variantId: string } + +export interface TcgplayerVariantPricing { + productId: number; + lowPrice: number; + midPrice: number; + highPrice: number; + marketPrice: number; + directLowPrice: number; +} + +const TCGPLAYER_VARIANTS = [ + 'normal', + 'holofoil', + 'reverse-holofoil', + '1st-edition', + '1st-edition-holofoil', + 'unlimited', + 'unlimited-holofoil', +] as const; + +type TcgplayerVariantKey = typeof TCGPLAYER_VARIANTS[number]; + +/** + * Market pricing information from multiple sources + */ +export interface Pricing { + cardmarket?: { + idProduct?: number; + updated?: string; + unit?: string; + avg?: number; + low?: number; + trend?: number; + avg1?: number; + avg7?: number; + avg30?: number; + 'avg-holo'?: number; + 'low-holo'?: number; + 'trend-holo'?: number; + 'avg1-holo'?: number; + 'avg7-holo'?: number; + 'avg30-holo'?: number; + } + tcgplayer?: { + updated: string; + unit: string; + } & { + [K in TcgplayerVariantKey]?: TcgplayerVariantPricing; + } & { + [variant: string]: TcgplayerVariantPricing | undefined; + } +}