Skip to content
Merged
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
8 changes: 5 additions & 3 deletions __tests__/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@ const endpoints = [
{ endpoint: 'card', params: ['swsh1-136'] },
{ endpoint: 'set', params: ['swsh1'] },
{ endpoint: 'serie', params: ['swsh'] },
{ endpoint: 'type', params: ['fire'] },
// TODO: re-enable after server answer faster
// { endpoint: 'type', params: ['fire'] },
{ endpoint: 'retreat', params: ['1'] },
{ endpoint: 'rarity', params: ['common'] },
{ endpoint: 'illustrator', params: [''] },
{ endpoint: 'hp', params: ['30'] },
{ endpoint: 'categorie', params: ['pokemon'] },
{ endpoint: 'categorie', params: ['energy'] },
{ endpoint: 'dexID', params: ['1'] },
{ endpoint: 'energyType', params: ['normal'] },
{ endpoint: 'regulationMark', params: ['f'] },
{ endpoint: 'stage', params: ['basic'] },
{ endpoint: 'suffixe', params: ['ex'] },
{ endpoint: 'trainerType', params: ['item'] },
{ endpoint: 'variant', params: ['normal'] },
// TODO: re-enable after server answer faster
// { endpoint: 'variant', params: ['normal'] },
]

for (const endpoint of endpoints) {
Expand Down
100 changes: 3 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "@tcgdex/sdk",
"version": "2.7.0",
"main": "./dist/tcgdex.node.js",
"module": "./dist/tcgdex.node.mjs",
"types": "./dist/tcgdex.node.d.ts",
"main": "./dist/tcgdex.js",
"module": "./dist/tcgdex.mjs",
"types": "./dist/tcgdex.d.ts",
"browser": "./dist/tcgdex.browser.global.js",
"exports": {
".": {
"require": {
"types": "./dist/tcgdex.node.d.ts",
"default": "./dist/tcgdex.node.js"
"types": "./dist/tcgdex.d.ts",
"default": "./dist/tcgdex.js"
},
"import": {
"types": "./dist/tcgdex.node.d.mts",
"default": "./dist/tcgdex.node.mjs"
"types": "./dist/tcgdex.d.mts",
"default": "./dist/tcgdex.mjs"
}
}
},
Expand Down Expand Up @@ -52,17 +52,16 @@
"vitest": "^2"
},
"engines": {
"node": ">=12"
"node": ">=18"
},
"dependencies": {
"@cachex/memory": "^1",
"@cachex/web-storage": "^1",
"@dzeio/object-util": "^1",
"isomorphic-unfetch": "^3"
"@dzeio/object-util": "^1"
},
"scripts": {
"prebuild": "node scripts/export-version-number.js",
"build": "rm -rf dist && tsup ./src/tcgdex.node.ts --format cjs,esm --dts --clean && tsup ./src/tcgdex.browser.ts --format iife --global-name TCGdex --sourcemap",
"build": "rm -rf dist && tsup ./src/tcgdex.ts --format cjs,esm --dts --clean && tsup ./src/tcgdex.browser.ts --format iife --global-name TCGdex --sourcemap",
"prepublishOnly": "npm run build",
"lint": "eslint",
"test": "vitest run --coverage"
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface booster {
name: string
logo?: string
artwork_front?: string
artwork_back?: string
artwork_back?: string
}

export type SetList = Array<SetResume>
Expand Down
6 changes: 2 additions & 4 deletions src/tcgdex.browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import TCGdex from './tcgdex'
import TCGdex from "./tcgdex"

TCGdex.fetch = window.fetch

export default TCGdex
module.exports = TCGdex
7 changes: 0 additions & 7 deletions src/tcgdex.node.ts

This file was deleted.

10 changes: 8 additions & 2 deletions src/tcgdex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export default class TCGdex {
/**
* How the remote data is going to be fetched
*/
public static fetch: typeof fetch = fetch
public static fetch: typeof fetch =
detectContext() === 'browser'
// fixe: TypeError: 'fetch' called on an object that does not implement interface Window.
? (...params: Parameters<typeof fetch>) => window.fetch(...params)
: fetch

/**
* @deprecated to change the lang use {@link TCGdex.getLang} and {@link TCGdex.setLang}
Expand All @@ -42,7 +46,9 @@ export default class TCGdex {
* the previously hidden caching system used by TCGdex to not kill the API
*/
public cache: CacheInterface =
detectContext() === 'browser' ? new LocalStorageCache('tcgdex-cache') : new MemoryCache()
detectContext() === 'browser'
? new LocalStorageCache('tcgdex-cache')
: new MemoryCache()

/**
* the default cache TTL, only subsequent requests will have their ttl changed
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Endpoints } from './interfaces'

/**
* detect the current running context ofthe program
* detect the current running context of the program
*/
export function detectContext(): 'browser' | 'server' {
try {
Expand Down