SDK for communicating with the Catalog Engine API — a language binding for frontend applications.
Inspired by the TCGdex JavaScript SDK, this SDK provides a fluent, type-safe interface for querying catalog items (TCG cards, video games, consoles, etc.) from the Catalog Engine microservice.
Works in both Node.js and browser environments. See more at NPM.
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
# Create the package to later reference and build from
npm packnpm install /path/to/catalog/client
# or
yarn add /path/to/catalog/client
# or
pnpm add /path/to/catalog/clientnpm login
npm publish --access publicAdd the package to your projct
npm install @topchased/catalog-client-sdk
import { CatalogClient } from '@topchased/catalog-client-sdk';
// Create a client pointing to your Catalog Engine API
const client = new CatalogClient('http://localhost:3001/api/v1');
// Search for Pokemon cards
const results = await client.search()
.query('charizard')
.category('tcg')
.brand('pokemon')
.language('en')
.paginate(1, 20)
.execute();
console.log(results.items); // Array of catalog items
console.log(`Found ${results.total} results`);The main SDK class. Create an instance with the base URL of your Catalog Engine API.
const client = new CatalogClient('http://localhost:3001/api/v1');Create a fluent search query. Chain filters and call .execute() to run.
const results = await client.search()
.query('charizard') // Search text
.category('tcg') // tcg | video_game | video_game_consoles
.brand('pokemon') // pokemon | yugioh | one_piece
.productType('card') // card | sealed_product
.language('en') // Card language
.setName('Base Set') // Filter by set name
.setCode('base1') // Filter by set code
.illustrator('Ken Sugimori') // Filter by illustrator
.platform('nintendo-switch') // For video games/consoles
.paginate(1, 20) // Page number, items per page
.limit(5) // Limit number of items returned
.sort('title', 'asc') // Sort field and order
.execute();Search using a plain object of filters.
const results = await client.searchWithFilters({
q: 'charizard',
category: 'tcg',
brand: 'pokemon',
limit: 20,
});Get a single catalog item by its ID.
const item = await client.getItem('abc123');
if (item) {
console.log(item.title);
}List catalog items with optional filters (no text search).
const results = await client.listItems({
category: 'tcg',
brand: 'pokemon',
limit: 50,
});Get autocomplete suggestions for a search query.
const suggestions = await client.autocomplete('char', 'tcg', 'pokemon');You can also use the standalone Query class to build query parameters:
import { Query } from '@topchased/catalog-client-sdk';
const query = Query.create()
.search('charizard')
.category('tcg')
.brand('pokemon')
.language('en')
.paginate(1, 20)
.sort('title', 'asc');
// query.params contains the key-value pairsThe SDK includes type guards for narrowing catalog item types:
import { isPokemonCatalogItem, isVideoGameCatalogItem } from '@topchased/catalog-client-sdk';
if (isPokemonCatalogItem(item)) {
console.log(item.brand); // 'pokemon'
console.log(item.details.hp); // Pokemon-specific fields
}interface CatalogSearchResponse {
items: CatalogItem[];
total: number;
page: number;
limit: number;
hasMore: boolean;
}PokemonCatalogItem— TCG cards withbrand: 'pokemon'YugiohCatalogItem— TCG cards withbrand: 'yugioh'OnePieceCatalogItem— TCG cards withbrand: 'one_piece'VideoGameCatalogItem— Video games withcategory: 'video_game'ConsoleCatalogItem— Consoles withcategory: 'video_game_consoles'
The SDK works in the browser out of the box. It auto-detects the environment and uses window.fetch when in a browser context.
<script src="https://unpkg.com/@catalog/client/dist/index.browser.global.js"></script>
<script>
const client = new CatalogClient('http://localhost:3001/api/v1');
client.search()
.query('charizard')
.category('tcg')
.execute()
.then(results => console.log(results));
</script>import { CatalogClient } from '@topchased/catalog-client-sdk';# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Type check
npm run typechecknpm run build
npm pack
To install locally to other repos:
# point to tar ie
npm add ../catalog-client-sdk/topchased-catalog-client-1.0.0.tgz
MIT