Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
cce804d1c3 build: bump vitest from 2.1.8 to 2.1.9
Bumps [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) from 2.1.8 to 2.1.9.
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v2.1.9/packages/vitest)

---
updated-dependencies:
- dependency-name: vitest
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-04 17:40:06 +00:00
7 changed files with 668 additions and 564 deletions

1165
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@tcgdex/sdk",
"version": "2.7.0",
"version": "2.6.0",
"main": "./dist/tcgdex.node.js",
"module": "./dist/tcgdex.node.mjs",
"types": "./dist/tcgdex.node.d.ts",

13
src/interfaces.d.ts vendored
View File

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

View File

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

View File

@@ -4,12 +4,3 @@ export interface Variants {
holo?: 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 CardResume from './CardResume'
import Model from './Model'
import type { Booster, Variants } from './Other'
import type { Variants } from './Other'
import type SerieResume from './SerieResume'
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
@@ -70,8 +70,6 @@ export default class Set extends Model {
public cards!: Array<CardResume>
public boosters?: Array<Booster>
public async getSerie() {
return this.sdk.serie.get(this.serie.id)
}

View File

@@ -326,22 +326,19 @@ export default class TCGdex {
* format the final URL
*/
private getFullURL(
path: Array<string | number>,
url: Array<string | number>,
searchParams?: Array<{ key: string, value: string | number | boolean }>
): string {
// build base path
const url = new URL(`${this.getEndpoint()}/${this.getLang()}`)
// set url path
url.pathname = `${url.pathname}/${path.join('/')}`
// Normalize path
let path = url.map(this.encode).join('/')
// handle the Search Params
for (const param of searchParams ?? []) {
url.searchParams.append(param.key, param.value.toString())
if (searchParams) {
path += '?' + searchParams.map((it) => `${this.encode(it.key)}=${this.encode(it.value)}`).join('&')
}
// return with the endpoint and all the shit
return url.toString()
return `${this.getEndpoint()}/${this.getLang()}/${path}`
}
private async actualFetch<T = object>(path: string): Promise<T | undefined> {
@@ -379,6 +376,26 @@ export default class TCGdex {
this.cache.set(path, json, this.cacheTTL)
return json as T
}
/**
* encode a string to be used in an url
* @param str the string to encode to URL
* @returns the encoded string
*/
private encode(str: string | number | boolean): string {
return encodeURI(
str
// Transform numbers to string
.toString()
// replace this special character with an escaped one
.replace('?', '%3F')
// normalize the string
.normalize('NFC')
// remove some special chars
// eslint-disable-next-line no-misleading-character-class
.replace(/["'\u0300-\u036f]/gu, '')
)
}
}
// export the old interfaces