Skip to content

Add TCGTracking pricing integration and scripts#1428

Open
FalconChipp wants to merge 2 commits into
masterfrom
TCGTracking-as-a-new-pricing-source
Open

Add TCGTracking pricing integration and scripts#1428
FalconChipp wants to merge 2 commits into
masterfrom
TCGTracking-as-a-new-pricing-source

Conversation

@FalconChipp
Copy link
Copy Markdown
Member

@FalconChipp FalconChipp commented May 11, 2026

Add TCGTracking as primary pricing source

This PR adds a provider-based pricing pipeline with TCGTracking as the primary source and the existing TCGPlayer/TCGCSV-backed source as fallback.

The source order is controlled by:

TCGDEX_PRICING_SOURCES=tcgtracking,tcgplayer

Supported values:

tcgtracking
tcgplayer
tcgtracking,tcgplayer
tcgplayer,tcgtracking

Background

The existing fallback pricing flow uses TCGCSV, which mirrors TCGPlayer data and is referred to as tcgplayer throughout the repo/server code.

TCGCSV has recently been unreliable/unavailable for us, so this PR adds TCGTracking as the default pricing source while keeping the existing TCGPlayer/TCGCSV path available as a fallback.

What changed

New pricing provider system

Added:

scripts/pricing/
  cache.ts
  sources.ts
  tcgtracking.ts
  tcgplayer.ts
  types.ts

This introduces a shared provider flow for resolving prices by existing thirdParty.tcgplayer IDs.

The first provider to return a price wins.

TCGTracking provider

The TCGTracking provider fetches set pricing lazily and caches it in memory per set during the run.

It uses:

/tcgapi/v1/{categoryId}/sets/{setId}/pricing

Pricing is resolved from:

prices[tcgplayerProductId].tcg[priceType].low
prices[tcgplayerProductId].tcg[priceType].market

Observed price types include:

Normal
Holofoil
Reverse Holofoil

The provider does not create, infer, or remap variants. It only uses existing card/variant thirdParty.tcgplayer IDs.

TCGPlayer fallback provider

The existing TCGPlayer/TCGCSV-backed pricing source remains available as the tcgplayer provider.

This keeps backwards compatibility and allows unresolved TCGTracking prices to fall back to the previous source where possible.

Black Bolt set ID override

TCGTracking uses a different set ID for Black Bolt:

TCGDex/TCGPlayer: 22325
TCGTracking:      24325

An override is included so pricing can be fetched from TCGTracking while still resolving against the existing TCGDex set ID.

New updater

Added:

scripts/updatePricing.ts

This replaces the TCGTracking-specific proof-of-concept updater with a generic provider-based pricing update flow.

It supports reporting/debug output and does not mutate card source files.

Known fallback cases

TCGTracking does not currently expose pricing endpoints for:

DP trainer Kit (Manaphy) - 609
DP trainer Kit (Lucario) - 610

These remain fallback cases.

Summary

This PR moves pricing to a provider-based flow:

existing thirdParty.tcgplayer ID
        ↓
configured pricing providers
        ↓
TCGTracking primary
        ↓
TCGPlayer/TCGCSV fallback
        ↓
resolved pricing/report output

Introduce TCGTracking-based pricing pipeline and server support.

- Add new scripts: scripts/preloadTCGTracking.ts (caches TCGTracking set pricing), scripts/updatePricingFromTCGTracking.ts (resolves cached pricing to a resolved-pricing artifact), and scripts/utils-data/tcgtracking.ts (helpers, fetcher, cache path helpers, category mapping, import URL fix).
- Extend scripts/preloadTCGPlayer.ts to also download TCGCSV prices into var/models/tcgplayer/prices as a fallback.
- Add set ID override support, daily cache freshness checks, polite fetch delays, failure reporting (var/reports/tcgtracking-preload-failures.json), and --strict/--apply flags for control.
- New pricing resolver supports three modes via PRICING_SOURCE: tcgtracking (default), tcgcsv (old fallback), tcgtracking-only; updatePricingFromTCGTracking supports dry-run and apply and writes var/models/tcgtracking/resolved-pricing.json when applied.
- Wire the server to use the new provider: add server/src/libs/providers/tcgplayer/tcgtracking.ts and load it by default in server/src/libs/providers/tcgplayer/index.ts unless official credentials or PRICING_SOURCE=tcgcsv are present.

Notes: The scripts do not mutate card source files or create/remap variants; caching filenames use existing TCGPlayer set IDs to remain compatible with existing data.
@FalconChipp FalconChipp marked this pull request as draft May 11, 2026 15:46
Add a unified pricing subsystem and updater: new files under scripts/pricing (cache, sources, tcgplayer, tcgtracking, types) and a top-level scripts/updatePricing.ts that scans card files, resolves prices from configured providers, and writes reports/debug artifacts. Implements a TTLCache, provider factory/ordering (TCGDEX_PRICING_SOURCES), TCGPlayer and TCGTracking providers with caching and inflight deduplication, and set ID overrides for TCGTracking. Remove legacy TCGTracking-specific preload/update scripts (scripts/preloadTCGTracking.ts and scripts/updatePricingFromTCGTracking.ts) and update package.json scripts to use pricing:update / pricing:update:debug.
@FalconChipp FalconChipp marked this pull request as ready for review May 11, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant