mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-25 15:39:50 +00:00
Compare commits
6 Commits
v2.6.0
...
fix/use-ur
Author | SHA1 | Date | |
---|---|---|---|
2f0448059b
|
|||
6849546c1a | |||
95a658f98a | |||
c866b4022f | |||
978a676a79 | |||
1f801f4a94 |
1024
package-lock.json
generated
1024
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "2.6.0",
|
"version": "2.7.0",
|
||||||
"main": "./dist/tcgdex.node.js",
|
"main": "./dist/tcgdex.node.js",
|
||||||
"module": "./dist/tcgdex.node.mjs",
|
"module": "./dist/tcgdex.node.mjs",
|
||||||
"types": "./dist/tcgdex.node.d.ts",
|
"types": "./dist/tcgdex.node.d.ts",
|
||||||
|
13
src/interfaces.d.ts
vendored
13
src/interfaces.d.ts
vendored
@ -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>
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
9
src/models/Other.d.ts
vendored
9
src/models/Other.d.ts
vendored
@ -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
|
||||||
|
}
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -326,19 +326,22 @@ export default class TCGdex {
|
|||||||
* format the final URL
|
* format the final URL
|
||||||
*/
|
*/
|
||||||
private getFullURL(
|
private getFullURL(
|
||||||
url: Array<string | number>,
|
path: Array<string | number>,
|
||||||
searchParams?: Array<{ key: string, value: string | number | boolean }>
|
searchParams?: Array<{ key: string, value: string | number | boolean }>
|
||||||
): string {
|
): string {
|
||||||
// Normalize path
|
// build base path
|
||||||
let path = url.map(this.encode).join('/')
|
const url = new URL(`${this.getEndpoint()}/${this.getLang()}`)
|
||||||
|
|
||||||
|
// set url path
|
||||||
|
url.pathname = `${url.pathname}/${path.join('/')}`
|
||||||
|
|
||||||
// handle the Search Params
|
// handle the Search Params
|
||||||
if (searchParams) {
|
for (const param of searchParams ?? []) {
|
||||||
path += '?' + searchParams.map((it) => `${this.encode(it.key)}=${this.encode(it.value)}`).join('&')
|
url.searchParams.append(param.key, param.value.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// return with the endpoint and all the shit
|
// return with the endpoint and all the shit
|
||||||
return `${this.getEndpoint()}/${this.getLang()}/${path}`
|
return url.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async actualFetch<T = object>(path: string): Promise<T | undefined> {
|
private async actualFetch<T = object>(path: string): Promise<T | undefined> {
|
||||||
@ -376,26 +379,6 @@ export default class TCGdex {
|
|||||||
this.cache.set(path, json, this.cacheTTL)
|
this.cache.set(path, json, this.cacheTTL)
|
||||||
return json as T
|
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
|
// export the old interfaces
|
||||||
|
Reference in New Issue
Block a user