mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 18:45:09 +00:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
f28fa11710
|
|||
95c48e530e
|
|||
c3791959be
|
|||
a3537a1af7 | |||
4da8131d11 | |||
8405302286 | |||
b1d97a4278 | |||
b004321f40 | |||
b3d34182a2 | |||
1b1bcfbb84 | |||
a593271aba | |||
6e93a70f1e | |||
fbf6f2e2cd | |||
8e3de78b00 | |||
b845e36784 | |||
23da33f81f |
202
CHANGELOG.md
Normal file
202
CHANGELOG.md
Normal file
@ -0,0 +1,202 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.1.1] - 2021-05-31
|
||||
|
||||
### Fixed
|
||||
|
||||
- Package building in the wrong version of ECMAScript
|
||||
|
||||
## [2.1.0] - 2021-05-31
|
||||
|
||||
### Added
|
||||
|
||||
- new `fetch` function that manage all the API endpoints
|
||||
|
||||
## [2.0.2-2.0.3] - 2021-05-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- `rotationMark` should have been named `regulationMark`
|
||||
|
||||
## [2.0.1] - 2021-05-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Hardcoded string values are now strings as they depends on the language
|
||||
|
||||
## [2.0.0] - 2021-05-28
|
||||
|
||||
### Added
|
||||
|
||||
- simple string endpoint typing
|
||||
- Typing is exported through the main.d.ts file
|
||||
- `cardCount` field in the set interface
|
||||
- a `rotationMark` to the card interface
|
||||
|
||||
### Changed
|
||||
|
||||
- Support new incoming datas
|
||||
- Point the SDK to the new V2
|
||||
- Renamed `getExpansion(s)` to `getSerie(s)`
|
||||
- Typing for the new SDK
|
||||
- Functions now use `fetch` instead of `get` in their names
|
||||
- URL Normalization is now done by the SDK
|
||||
|
||||
### Fixed
|
||||
|
||||
- `getSerie(s)` now point to the correct endpoint
|
||||
|
||||
### Removed
|
||||
|
||||
- TranslationUtil as now translation are managed by the API
|
||||
- the interfaces folder as every interfaces are now in `interfaces.d.ts`
|
||||
- `this.gbu`
|
||||
- Translation files as they are now in the Compiler
|
||||
|
||||
## [1.7.0] - 2021-01-31
|
||||
|
||||
### Added
|
||||
|
||||
- new Rarities
|
||||
|
||||
## [1.6.1] - 2021-01-31
|
||||
|
||||
### Changed
|
||||
|
||||
- tags are now optionnal
|
||||
|
||||
## [1.6.0] - 2021-01-08
|
||||
|
||||
### Changed
|
||||
|
||||
- Errors are now handled to return `undefined`
|
||||
|
||||
### Removed
|
||||
|
||||
- console.warn when using `getCards`
|
||||
|
||||
## [1.5.0] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- getSet can now not transform the API Date to a Javascript Date
|
||||
|
||||
## [1.4.2] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- new Tags
|
||||
|
||||
### Changed
|
||||
|
||||
- rarities to have less strange rarities
|
||||
-
|
||||
|
||||
### Fixed
|
||||
|
||||
- CORS blocked
|
||||
|
||||
|
||||
## [1.4.1] - 2020-04-24
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed API url to the new one
|
||||
|
||||
## [1.4.0] - 2020-03-25
|
||||
|
||||
### Added
|
||||
|
||||
- a `defaultLang` static field to customize the default lang
|
||||
- a `getLang` function to get the current lang for the SDK
|
||||
|
||||
### Fixed
|
||||
|
||||
- Warnings for translations
|
||||
|
||||
## [1.3.0] - 2020-03-18
|
||||
|
||||
### Added
|
||||
|
||||
- A cache system
|
||||
- some informations about differents tags on a card
|
||||
- lvl on the card interface
|
||||
|
||||
### Removed
|
||||
|
||||
- cardTypes on the card interface
|
||||
|
||||
## [1.2.1] - 2020-03-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix items datas not in the correct interface
|
||||
|
||||
## [1.2.0] - 2020-03-14
|
||||
|
||||
### Added
|
||||
|
||||
- Added The getCards endpoint to fetch the big list of card with an optionnal filter on the set
|
||||
- Added The getExpansions endpoint to fetch the list of expansions
|
||||
- Added Some informations about cardTypes
|
||||
- Updated DB to add support for items
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix translation not getting the correct file
|
||||
|
||||
|
||||
## [1.0.8] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed typing for some interfaces
|
||||
|
||||
## [1.0.1-1.0.7] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Renamed the class Name from `TCGDex` to `TCGdex`
|
||||
- lang argument is now public so it can be changed while the SDK is active
|
||||
|
||||
### Added
|
||||
|
||||
- some typing for getCard and translationUtil
|
||||
|
||||
## [1.0.0] - 2020-03-11
|
||||
|
||||
### Added
|
||||
|
||||
- the getCard function to use with the fetch a card with it's id
|
||||
- the getSet function to use with the fetch a set with it's id
|
||||
- the getExpansion function to use with the fetch an expansion with it's id
|
||||
- Constructor arg support for multiple langs
|
||||
- TranslationUtil to go from the SDK value to a text value
|
||||
|
||||
[Unreleased]: https://github.com/tcgdex/javascript-sdk/compare/v2.1.1...HEAD
|
||||
|
||||
[2.1.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.1
|
||||
[2.1.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.0
|
||||
[2.0.2-2.0.3]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.3
|
||||
[2.0.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.1
|
||||
[2.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.0
|
||||
[1.7.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.7.0
|
||||
[1.6.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.6.1
|
||||
[1.6.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.6.0
|
||||
[1.5.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.5.0
|
||||
[1.4.2]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.2
|
||||
[1.4.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.1
|
||||
[1.4.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.0
|
||||
[1.3.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.3.0
|
||||
[1.2.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.1
|
||||
[1.2.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.0
|
||||
[1.0.8]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.8
|
||||
[1.0.1-1.0.7]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.7
|
||||
[1.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.0.0
|
50
README.md
50
README.md
@ -1,14 +1,14 @@
|
||||
# TCGdex Javacript SDK
|
||||
# TCGdex JavaScript/TypeScript SDK
|
||||
|
||||
This is the SDK used to communicate with the Open source [TCGdex API](https://www.github.com/tcgdex/cards-database)
|
||||
|
||||
Full API/SDK documentation in progress at https://www.tcgdex.net/docs
|
||||
|
||||
## Install
|
||||
|
||||
### Yarn/npm
|
||||
|
||||
```bash
|
||||
yarn add @tcgdex/sdk
|
||||
```
|
||||
or with npm
|
||||
```bash
|
||||
# or
|
||||
npm install @tcgdex/sdk
|
||||
```
|
||||
|
||||
@ -18,27 +18,33 @@ _Note: a complete documentation is in progress_
|
||||
|
||||
```javascript
|
||||
import TCGdex from '@tcgdex/sdk'
|
||||
import TranslationUtil from '@tcgdex/sdk/TranslationUtil'
|
||||
import Tag from '@tcgdex/sdk/interfaces/Tag'
|
||||
|
||||
// init the class
|
||||
const tcgdex = new TCGdex("en") // Lang code (Optionnal) (See TranslationUtil.ts line 3)
|
||||
// initialize the SDK
|
||||
const tcgdex = new TCGdex('en') // Lang code (Optionnal) (See interfaces.d.ts line 1 for supported languages)
|
||||
|
||||
// change lang
|
||||
tcgdex.lang = "fr"
|
||||
// if you need to change the language
|
||||
tcgdex.lang = 'fr'
|
||||
|
||||
// get Card object wih global id
|
||||
await tcgdex.getCard("base1-1")
|
||||
// get a Card using its global ID
|
||||
await tcgdex.fetch('cards', 'base1-1')
|
||||
|
||||
// get Card object with local id and set
|
||||
await tcgdex.getCard(1, "base1")
|
||||
// fetch a Card using it's local id and set name/ID
|
||||
await tcgdex.fetch('sets', 'Base Set', 1)
|
||||
|
||||
// get Set informations
|
||||
await tcgdex.getSet("base1")
|
||||
// fetch a Set's informations using the set's name/ID
|
||||
await tcgdex.fetch('sets', 'Sword & Shield')
|
||||
|
||||
// get Expansion
|
||||
await tcgdex.getExpansion("base")
|
||||
// Fetch a serie using the serie's name/ID
|
||||
await tcgdex.fetch('series', 'Black & White')
|
||||
|
||||
// Translate information from code to the lang
|
||||
TranslationUtil.translate("tag", Tag.STAGE2, "en")
|
||||
// Fetch cards using other endpoints
|
||||
/**
|
||||
* categories => the the different cards categories
|
||||
* hp => fetch the different cards possible HPs
|
||||
* illustrators => fetch all the cards illustrators
|
||||
* rarities => fetch the cards rarities
|
||||
* retreats => fetch the cards using the retreat count
|
||||
* types => fetch the cards using the Pokémon type(s)
|
||||
**/
|
||||
await tcgdex.fetch('categories')
|
||||
```
|
||||
|
17
Request.ts
17
Request.ts
@ -1,4 +1,5 @@
|
||||
import fetch from 'isomorphic-unfetch'
|
||||
import { version, name } from './package.json'
|
||||
|
||||
export default class RequestWrapper {
|
||||
private static cache: Array<Request<any>> = []
|
||||
@ -15,16 +16,17 @@ export default class RequestWrapper {
|
||||
|
||||
export class Request<T = any> {
|
||||
public static ttl = 1000 * 60 * 60 // 1 hour
|
||||
|
||||
private response?: T
|
||||
private fetched?: Date
|
||||
public url: string // url is public for quick url test
|
||||
|
||||
public constructor(url: string) {
|
||||
this.url = url
|
||||
}
|
||||
public constructor(
|
||||
public url: string // url is public for quick url test
|
||||
) {}
|
||||
|
||||
public async get(): Promise<T | undefined> {
|
||||
const now = new Date()
|
||||
// if reponse was already fetched and TTL was not passed
|
||||
if (
|
||||
this.fetched &&
|
||||
this.response &&
|
||||
@ -36,15 +38,14 @@ export class Request<T = any> {
|
||||
// Fetch Response
|
||||
const resp = await fetch(this.url, {
|
||||
headers: {
|
||||
"Content-Type": "text/plain"
|
||||
'user-agent': `${name}/${version}`
|
||||
}
|
||||
})
|
||||
if (resp.status !== 200) {
|
||||
return undefined
|
||||
}
|
||||
const response = await resp.json()
|
||||
this.response = response
|
||||
this.response = await resp.json()
|
||||
this.fetched = now
|
||||
return response
|
||||
return this.response
|
||||
}
|
||||
}
|
||||
|
32
interfaces.d.ts
vendored
32
interfaces.d.ts
vendored
@ -46,8 +46,21 @@ export interface Set extends SetResume {
|
||||
|
||||
releaseDate: string
|
||||
|
||||
legal?: {
|
||||
/**
|
||||
* Designate if the set is usable in tournaments
|
||||
*
|
||||
* Note: this is specific to the set and if a
|
||||
* card is banned from the set it will still be true
|
||||
*/
|
||||
legal: {
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
@ -257,6 +270,23 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
||||
* Define the rotation mark on cards >= Sword & Shield
|
||||
*/
|
||||
regulationMark?: string
|
||||
|
||||
/**
|
||||
* Card ability to be played in official tournaments
|
||||
*
|
||||
* Note: all cards are avaialable to play in unlimited tournaments
|
||||
*/
|
||||
legal: {
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export type StringEndpointList = Array<string>
|
||||
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@tcgdex/sdk",
|
||||
"version": "2.0.3",
|
||||
"version": "2.2.0",
|
||||
"main": "./tcgdex.js",
|
||||
"types": "./main.d.ts",
|
||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node-fetch": "2.5.7",
|
||||
"ts-node": "^9.1.1",
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
|
188
tcgdex.ts
188
tcgdex.ts
@ -1,79 +1,171 @@
|
||||
import RequestWrapper from './Request'
|
||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages } from './interfaces'
|
||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
||||
|
||||
type Endpoint = 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
||||
|
||||
const ENDPOINTS: Array<Endpoint> = ['cards', 'categories', 'hp', 'illustrators', 'rarities', 'retreats', 'series', 'sets', 'types']
|
||||
const BASE_URL = 'https://api.tcgdex.net/v2'
|
||||
|
||||
export default class TCGdex {
|
||||
/**
|
||||
* @deprecated to change the lang use `this.lang`
|
||||
*/
|
||||
public static defaultLang: SupportedLanguages = "en"
|
||||
|
||||
public constructor(public lang?: SupportedLanguages) {}
|
||||
|
||||
public getLang() {
|
||||
return this.lang || TCGdex.defaultLang
|
||||
}
|
||||
|
||||
private getBaseUrl() {
|
||||
return `https://api.tcgdex.net/v2/${this.getLang()}`
|
||||
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to easily fetch a card using both it's global id and it's local ID
|
||||
* @param id the card global/local ID
|
||||
* @param set the card set name/ID (optionnal)
|
||||
* @returns the card object
|
||||
*/
|
||||
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
|
||||
const path = set ? ['sets', set] : ['cards']
|
||||
return this.rwgr<Card>(...path, id).get()
|
||||
// @ts-expect-error the base endpoint is 'sets' or 'cards'
|
||||
return this.fetch(...path, id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to easily fetch cards using an optionnal set name/ID
|
||||
* @param set the card set name/ID (optionnal)
|
||||
* @returns a card list
|
||||
*/
|
||||
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
|
||||
if (set) {
|
||||
const setSingle = await this.fetchSet(set)
|
||||
if (!setSingle) {
|
||||
return undefined
|
||||
const fSet = await this.fetch('sets', set)
|
||||
return fSet ? fSet.cards : undefined
|
||||
}
|
||||
return setSingle.cards
|
||||
}
|
||||
const req = this.rwgr<Array<CardResume>>('cards')
|
||||
const resp = await req.get()
|
||||
if (!resp) {
|
||||
return undefined
|
||||
}
|
||||
return resp
|
||||
return this.fetch('cards')
|
||||
}
|
||||
|
||||
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||
const req = this.rwgr<Set>('sets', set)
|
||||
const resp = await req.get()
|
||||
if (!resp) {
|
||||
return undefined
|
||||
}
|
||||
return resp
|
||||
/**
|
||||
* @deprecated use `this.fetch('sets', set)`
|
||||
*/
|
||||
public async fetchSet(set: string) {
|
||||
return this.fetch('sets', set)
|
||||
}
|
||||
|
||||
public async fetchSerie(expansion: string): Promise<Serie | undefined> {
|
||||
const req = this.rwgr<Serie>('series', expansion)
|
||||
return req.get()
|
||||
/**
|
||||
* @deprecated use `this.fetch('series', serie)`
|
||||
*/
|
||||
public async fetchSerie(serie: string): Promise<Serie | undefined> {
|
||||
return this.fetch('series', serie)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use `this.fetch('series')`
|
||||
*/
|
||||
public async fetchSeries(): Promise<SerieList | undefined> {
|
||||
const req = this.rwgr<SerieList>('series')
|
||||
return req.get()
|
||||
return this.fetch('series')
|
||||
}
|
||||
|
||||
public async fetchSets(expansion?: string): Promise<SetList | undefined> {
|
||||
if (expansion) {
|
||||
const expansionSingle = await this.fetchSerie(expansion)
|
||||
if (!expansionSingle) {
|
||||
return undefined
|
||||
/**
|
||||
* Shortcut to easily fetch sets using an optionnal serie name/ID
|
||||
* @param serie the card set name/ID (optionnal)
|
||||
* @returns a card list
|
||||
*/
|
||||
public async fetchSets(serie?: string): Promise<SetList | undefined> {
|
||||
if (serie) {
|
||||
const fSerie = await this.fetch('series', serie)
|
||||
return fSerie ? fSerie.sets : undefined
|
||||
}
|
||||
return expansionSingle.sets
|
||||
}
|
||||
const req = this.rwgr<SetList>('sets')
|
||||
const list = await req.get()
|
||||
if (!list) {
|
||||
return undefined
|
||||
}
|
||||
return list
|
||||
return this.fetch('sets')
|
||||
}
|
||||
|
||||
private rwgr<T = any>(...url: Array<string | number>) {
|
||||
return RequestWrapper.getRequest<T>(`${this.getBaseUrl()}/${url.map((v) => encodeURI(
|
||||
// Normalize URL
|
||||
v.toString().replace('?', '%3F').normalize('NFC').replace(/["'\u0300-\u036f]/g, "")
|
||||
)).join('/')}`)
|
||||
/**
|
||||
* Fetch a card using its global id
|
||||
* @param endpoint_0 'cards'
|
||||
* @param endpoint_1 {string} the card global ID
|
||||
*/
|
||||
public async fetch(...type: ['cards', string]): Promise<Card | undefined>
|
||||
/**
|
||||
* Fetch every cards in the database
|
||||
* @param endpoint_0 'cards'
|
||||
*/
|
||||
public async fetch(type: 'cards'): Promise<Array<CardResume> | undefined>
|
||||
/**
|
||||
* Fetch a card using its local id and its set
|
||||
* @param endpoint_0 'sets'
|
||||
* @param endpoint_1 {string} the set name or ID
|
||||
* @param endpoint_2 {string} the card local ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['sets', string, string]): Promise<Card | undefined>
|
||||
/**
|
||||
* Fetch a set
|
||||
* @param endpoint_0 'sets'
|
||||
* @param endpoint_1 {string} the set name or ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['sets', string]): Promise<Set | undefined>
|
||||
/**
|
||||
* Fetch every sets
|
||||
* @param endpoint_0 'sets'
|
||||
*/
|
||||
public async fetch(endpoint: 'sets'): Promise<SetList | undefined>
|
||||
/**
|
||||
* Fetch a serie
|
||||
* @param endpoint_0 'series'
|
||||
* @param endpoint_1 {string} the serie name or ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['series', string]): Promise<Serie | undefined>
|
||||
/**
|
||||
* Fetch every series
|
||||
* @param endpoint_0 'series'
|
||||
*/
|
||||
public async fetch(endpoint: 'series'): Promise<SerieList | undefined>
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'}
|
||||
* Possible value 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'
|
||||
* @param endpoint_1 {string} the value set while fetching the index
|
||||
*/
|
||||
public async fetch(...endpoint: ['categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types', string]): Promise<StringEndpoint | undefined>
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||
* Possible value 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'
|
||||
* @param endpoint_1 {string} Fetch the possible values to use depending on the endpoint
|
||||
*/
|
||||
public async fetch(endpoint: 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'): Promise<Array<string> | undefined>
|
||||
/**
|
||||
* Fetch The differents endpoints depending on the first argument
|
||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||
* Possible value 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
||||
* @param endpoint_1 {string} (Optionnal) some details to go from the index file to the item file (mostly the ID/name)
|
||||
* @param endpoint_2 {string} (Optionnal) only for sets the card local ID to fetch the card through the set
|
||||
*/
|
||||
public async fetch(...endpoint: Array<Endpoint | string>): Promise<any | undefined> {
|
||||
if (endpoint.length === 0) {
|
||||
throw new Error(`endpoint to fetch is empty!`)
|
||||
}
|
||||
// @ts-expect-error with the precedent check, we KNOW that type is not empty
|
||||
const baseEndpoint = endpoint.shift().toLowerCase() as Endpoint
|
||||
if (!ENDPOINTS.includes(baseEndpoint)) {
|
||||
throw new Error(`unknown endpoint to fetch! (${baseEndpoint})`)
|
||||
}
|
||||
return this.makeRequest(baseEndpoint, ...endpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to make the request and normalize the whole path
|
||||
*/
|
||||
private makeRequest<T = any>(...url: Array<string | number>) {
|
||||
// Normalize path
|
||||
const path = url.map((v) => encodeURI(
|
||||
v
|
||||
// Transform numbers to string
|
||||
.toString()
|
||||
// replace this special character with an escaped one
|
||||
.replace('?', '%3F')
|
||||
// normalize the string
|
||||
.normalize('NFC')
|
||||
// remove some special chars by nothing
|
||||
.replace(/["'\u0300-\u036f]/g, "")
|
||||
)).join('/')
|
||||
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
@ -19,28 +19,29 @@
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "", /* Specify file to store incremental compilation information */
|
||||
"removeComments": true, /* Do not emit comments to output. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"strictNullChecks": true, /* Enable strict null checks. */
|
||||
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
"noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
"noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
"resolveJsonModule": true,
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
@ -49,7 +50,7 @@
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
@ -60,7 +61,7 @@
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
}
|
||||
}
|
||||
|
52
yarn.lock
52
yarn.lock
@ -2,18 +2,38 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node-fetch@2.5.7":
|
||||
version "2.5.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
|
||||
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
|
||||
"@tsconfig/node10@^1.0.7":
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.7.tgz#1eb1de36c73478a2479cc661ef5af1c16d86d606"
|
||||
integrity sha512-aBvUmXLQbayM4w3A8TrjwrXs4DZ8iduJnuJLLRGdkWlyakCf1q6uHZJBzXoRA/huAEknG5tcUyQxN3A+In5euQ==
|
||||
|
||||
"@tsconfig/node12@^1.0.7":
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.7.tgz#677bd9117e8164dc319987dd6ff5fc1ba6fbf18b"
|
||||
integrity sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A==
|
||||
|
||||
"@tsconfig/node14@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.0.tgz#5bd046e508b1ee90bc091766758838741fdefd6e"
|
||||
integrity sha512-RKkL8eTdPv6t5EHgFKIVQgsDapugbuOptNd9OOunN/HAkzmmTnZELx1kNCK0rSdUYGmiFMM3rRQMAWiyp023LQ==
|
||||
|
||||
"@tsconfig/node16@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
|
||||
integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==
|
||||
|
||||
"@types/node-fetch@^2.5.10":
|
||||
version "2.5.10"
|
||||
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.10.tgz#9b4d4a0425562f9fcea70b12cb3fcdd946ca8132"
|
||||
integrity sha512-IpkX0AasN44hgEad0gEF/V6EgR5n69VEqPEgnmoM8GsIGro3PowbWs4tR6IhxUTyPLpOn+fiGG6nrQhcmoCuIQ==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
form-data "^3.0.0"
|
||||
|
||||
"@types/node@*":
|
||||
version "14.14.41"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.41.tgz#d0b939d94c1d7bd53d04824af45f1139b8c45615"
|
||||
integrity sha512-dueRKfaJL4RTtSa7bWeTK1M+VH+Gns73oCgzvYfHZywRCoPSd8EkXBL0mZ9unPTveBn+D9phZBaxuzpwjWkW0g==
|
||||
version "15.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08"
|
||||
integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==
|
||||
|
||||
arg@^4.1.0:
|
||||
version "4.1.3"
|
||||
@ -104,11 +124,15 @@ source-map@^0.6.0:
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
ts-node@^9.1.1:
|
||||
version "9.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.1.1.tgz#51a9a450a3e959401bda5f004a72d54b936d376d"
|
||||
integrity sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==
|
||||
ts-node@^10.0.0:
|
||||
version "10.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
|
||||
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
|
||||
dependencies:
|
||||
"@tsconfig/node10" "^1.0.7"
|
||||
"@tsconfig/node12" "^1.0.7"
|
||||
"@tsconfig/node14" "^1.0.0"
|
||||
"@tsconfig/node16" "^1.0.1"
|
||||
arg "^4.1.0"
|
||||
create-require "^1.1.0"
|
||||
diff "^4.0.1"
|
||||
@ -117,9 +141,9 @@ ts-node@^9.1.1:
|
||||
yn "3.1.1"
|
||||
|
||||
typescript@^4.1.3:
|
||||
version "4.2.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
|
||||
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
|
||||
version "4.3.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
|
||||
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==
|
||||
|
||||
unfetch@^4.2.0:
|
||||
version "4.2.0"
|
||||
|
Reference in New Issue
Block a user