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/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..4a10548 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 @@ -72,3 +71,55 @@ export interface VariantsDetailed { */ variantId: string } + +export interface TcgplayerVariantPricing { + 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?: { + productId: number; + updated: string; + unit: string; + } & { + [K in TcgplayerVariantKey]?: TcgplayerVariantPricing; + } & { + [variant: string]: TcgplayerVariantPricing | undefined; + } +}