Compare commits

..

4 Commits

Author SHA1 Message Date
d237ed15b4 fix: browser fetch need to keep it's context 2025-07-07 17:04:16 +02:00
6849546c1a bump: 2.7.0 2025-05-26 13:45:30 +02:00
95a658f98a feat: Add support for boosters to set and card (#295) 2025-05-26 13:43:35 +02:00
c866b4022f build: bump @babel/core from 7.20.12 to 7.26.7 (#293)
Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.20.12 to 7.26.7.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.26.7/packages/babel-core)

---
updated-dependencies:
- dependency-name: "@babel/core"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-05 17:17:04 +01:00
10 changed files with 578 additions and 766 deletions

1267
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,19 @@
{ {
"name": "@tcgdex/sdk", "name": "@tcgdex/sdk",
"version": "2.6.0", "version": "2.7.0",
"main": "./dist/tcgdex.node.js", "main": "./dist/tcgdex.js",
"module": "./dist/tcgdex.node.mjs", "module": "./dist/tcgdex.mjs",
"types": "./dist/tcgdex.node.d.ts", "types": "./dist/tcgdex.d.ts",
"browser": "./dist/tcgdex.browser.global.js", "browser": "./dist/tcgdex.global.js",
"exports": { "exports": {
".": { ".": {
"require": { "require": {
"types": "./dist/tcgdex.node.d.ts", "types": "./dist/tcgdex.d.ts",
"default": "./dist/tcgdex.node.js" "default": "./dist/tcgdex.js"
}, },
"import": { "import": {
"types": "./dist/tcgdex.node.d.mts", "types": "./dist/tcgdex.d.mts",
"default": "./dist/tcgdex.node.mjs" "default": "./dist/tcgdex.mjs"
} }
} }
}, },
@ -57,12 +57,11 @@
"dependencies": { "dependencies": {
"@cachex/memory": "^1", "@cachex/memory": "^1",
"@cachex/web-storage": "^1", "@cachex/web-storage": "^1",
"@dzeio/object-util": "^1", "@dzeio/object-util": "^1"
"isomorphic-unfetch": "^3"
}, },
"scripts": { "scripts": {
"prebuild": "node scripts/export-version-number.js", "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,iife --global-name TCGdex --sourcemap --dts --clean",
"prepublishOnly": "npm run build", "prepublishOnly": "npm run build",
"lint": "eslint", "lint": "eslint",
"test": "vitest run --coverage" "test": "vitest run --coverage"

13
src/interfaces.d.ts vendored
View File

@ -22,9 +22,18 @@ interface variants {
firstEdition?: boolean firstEdition?: boolean
} }
interface booster {
id: string
name: string
logo?: string
artwork_front?: string
artwork_back?: string
}
export type SetList = Array<SetResume> export type SetList = Array<SetResume>
export type SerieList = Array<SerieResume> export type SerieList = Array<SerieResume>
export type CardList = Array<CardResume> export type CardList = Array<CardResume>
export type BoosterList = Array<booster>
export interface SetResume { export interface SetResume {
id: string id: string
@ -105,6 +114,8 @@ export interface Set extends SetResume {
} }
cards: CardList cards: CardList
boosters?: BoosterList
} }
export interface CardResume { export interface CardResume {
@ -302,6 +313,8 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
*/ */
expanded: boolean expanded: boolean
} }
boosters?: BoosterList
} }
export type StringEndpointList = Array<string> export type StringEndpointList = Array<string>

View File

@ -1,5 +1,5 @@
import CardResume from './CardResume' import CardResume from './CardResume'
import type { Variants } from './Other' import type { Booster, Variants } from './Other'
import type TCGdexSet from './Set' import type TCGdexSet from './Set'
import type SetResume from './SetResume' import type SetResume from './SetResume'
@ -188,6 +188,8 @@ export default class Card extends CardResume {
expanded: boolean expanded: boolean
} }
public boosters?: Array<Booster>
public override async getCard(): Promise<Card> { public override async getCard(): Promise<Card> {
return this return this
} }

View File

@ -4,3 +4,12 @@ export interface Variants {
holo?: boolean holo?: boolean
firstEdition?: boolean firstEdition?: boolean
} }
export interface Booster {
id: string
name: string
logo?: string
artwork_front?: string
artwork_back?: string
}

View File

@ -1,7 +1,7 @@
import { objectLoop } from '@dzeio/object-util' import { objectLoop } from '@dzeio/object-util'
import CardResume from './CardResume' import CardResume from './CardResume'
import Model from './Model' import Model from './Model'
import type { Variants } from './Other' import type { Booster, Variants } from './Other'
import type SerieResume from './SerieResume' import type SerieResume from './SerieResume'
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation> // biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
@ -70,6 +70,8 @@ export default class Set extends Model {
public cards!: Array<CardResume> public cards!: Array<CardResume>
public boosters?: Array<Booster>
public async getSerie() { public async getSerie() {
return this.sdk.serie.get(this.serie.id) return this.sdk.serie.get(this.serie.id)
} }

View File

@ -1,5 +0,0 @@
import TCGdex from './tcgdex'
TCGdex.fetch = window.fetch
export default TCGdex

View File

@ -1,7 +0,0 @@
import TCGdex from './tcgdex'
import fetch from 'isomorphic-unfetch'
TCGdex.fetch = fetch as any
export default TCGdex
export * from './tcgdex'

View File

@ -31,7 +31,11 @@ export default class TCGdex {
/** /**
* How the remote data is going to be fetched * 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} * @deprecated to change the lang use {@link TCGdex.getLang} and {@link TCGdex.setLang}
@ -42,7 +46,9 @@ export default class TCGdex {
* the previously hidden caching system used by TCGdex to not kill the API * the previously hidden caching system used by TCGdex to not kill the API
*/ */
public cache: CacheInterface = 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 * the default cache TTL, only subsequent requests will have their ttl changed

View File

@ -1,7 +1,7 @@
import type { Endpoints } from './interfaces' 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' { export function detectContext(): 'browser' | 'server' {
try { try {