Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ coverage
# Dist files
dist
src/version.js

.DS_Store
12 changes: 12 additions & 0 deletions __tests__/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

4 changes: 4 additions & 0 deletions src/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -316,6 +318,8 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
expanded: boolean
}

pricing?: Pricing;

boosters?: BoosterList
}

Expand Down
10 changes: 9 additions & 1 deletion src/models/Card.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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<Booster>

public override async getCard(): Promise<Card> {
Expand Down
60 changes: 54 additions & 6 deletions src/models/Other.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface Variants {
}

export interface Booster {

id: string
name: string
logo?: string
Expand Down Expand Up @@ -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;
Comment thread
advra marked this conversation as resolved.
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;
Comment thread
advra marked this conversation as resolved.
}
}