mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-04-22 10:42:10 +00:00
File reorganisation
Signed-off-by: Avior <github@avior.me>
This commit is contained in:
parent
f28fa11710
commit
4789c15c7d
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,8 +1,6 @@
|
|||||||
|
# Dev Files
|
||||||
node_modules
|
node_modules
|
||||||
|
test.ts
|
||||||
|
|
||||||
# Dist files
|
# Dist files
|
||||||
*.js
|
dist
|
||||||
*.d.ts
|
|
||||||
!interfaces.d.ts
|
|
||||||
!main.d.ts
|
|
||||||
test.ts
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
src
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.gitignore
|
.gitignore
|
||||||
.npmignore
|
.npmignore
|
||||||
tsconfig.json
|
webpack.config.js
|
||||||
*.ts
|
tsconfig.*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
test.js
|
CHANGELOG.md
|
||||||
test.d.ts
|
|
||||||
|
@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [2.2.0] - 2021-06-19
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added new fields
|
||||||
|
|
||||||
## [2.1.1] - 2021-05-31
|
## [2.1.1] - 2021-05-31
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
4
main.d.ts
vendored
4
main.d.ts
vendored
@ -1,4 +0,0 @@
|
|||||||
import TCGdex from './tcgdex'
|
|
||||||
export * from './interfaces'
|
|
||||||
|
|
||||||
export default TCGdex
|
|
38
package.json
38
package.json
@ -1,26 +1,44 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"main": "./tcgdex.js",
|
"main": "./dist/cjs/tcgdex.js",
|
||||||
"types": "./main.d.ts",
|
"module": "./dist/modules/tcgdex.js",
|
||||||
|
"types": "./dist/types/tcgdex.d.ts",
|
||||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@parcel/packager-ts": "2.0.0-beta.2",
|
||||||
"@types/node-fetch": "^2.5.10",
|
"@types/node-fetch": "^2.5.10",
|
||||||
|
"awesome-typescript-loader": "^5.2.1",
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.1.3",
|
||||||
|
"webpack": "^5.40.0",
|
||||||
|
"webpack-nano": "^1.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isomorphic-unfetch": "^3.1.0"
|
"node-fetch": "^2.6.1",
|
||||||
|
"unfetch": "^4.2.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --project tsconfig.json",
|
"build": "yarn build:cjs && yarn build:browser && yarn build:es2015",
|
||||||
|
"build:cjs": "tsc --project tsconfig.json",
|
||||||
|
"build:es2015": "tsc --project tsconfig.es2015.json",
|
||||||
|
"build:browser": "wp --config webpack.config.js",
|
||||||
"prepublishOnly": "yarn build"
|
"prepublishOnly": "yarn build"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"*.js",
|
"dist"
|
||||||
"*.d.ts",
|
],
|
||||||
"**/*.js",
|
"sideEffects": false,
|
||||||
"**/*.d.ts"
|
"targets": {
|
||||||
]
|
"browser": {
|
||||||
|
"context": "browser",
|
||||||
|
"engines": {
|
||||||
|
"browsers": "since 2017-06"
|
||||||
|
},
|
||||||
|
"includeNodeModules": true,
|
||||||
|
"optimize": false,
|
||||||
|
"scopeHoist": false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import fetch from 'isomorphic-unfetch'
|
import TCGdex from './tcgdex'
|
||||||
import { version, name } from './package.json'
|
|
||||||
|
|
||||||
export default class RequestWrapper {
|
export default class RequestWrapper {
|
||||||
private static cache: Array<Request<any>> = []
|
private static cache: Array<Request<any>> = []
|
||||||
@ -36,9 +35,10 @@ export class Request<T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch Response
|
// Fetch Response
|
||||||
const resp = await fetch(this.url, {
|
const unfetch = TCGdex.fetch
|
||||||
|
const resp = await unfetch(this.url, {
|
||||||
headers: {
|
headers: {
|
||||||
'user-agent': `${name}/${version}`
|
'user-agent': `@tcgdex/javascript-sdk/${TCGdex.VERSION}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
@ -2,7 +2,7 @@ export type SupportedLanguages = 'en' | 'fr'
|
|||||||
|
|
||||||
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
|
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
|
||||||
|
|
||||||
interface SerieResume {
|
export interface SerieResume {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
@ -22,7 +22,7 @@ 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>
|
||||||
|
|
||||||
interface SetResume {
|
export interface SetResume {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
logo?: string
|
logo?: string
|
||||||
@ -94,7 +94,7 @@ export interface Set extends SetResume {
|
|||||||
cards: CardList
|
cards: CardList
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CardResume {
|
export interface CardResume {
|
||||||
id: string
|
id: string
|
||||||
localId: string
|
localId: string
|
||||||
|
|
7
src/tcgdex.browser.ts
Normal file
7
src/tcgdex.browser.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import TCGdex from './tcgdex'
|
||||||
|
import unfetch from 'unfetch'
|
||||||
|
|
||||||
|
TCGdex.fetch = unfetch as any
|
||||||
|
|
||||||
|
export default TCGdex
|
||||||
|
export * from './tcgdex'
|
7
src/tcgdex.node.ts
Normal file
7
src/tcgdex.node.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import TCGdex from './tcgdex'
|
||||||
|
import fetch from 'node-fetch'
|
||||||
|
|
||||||
|
TCGdex.fetch = fetch as any
|
||||||
|
|
||||||
|
export default TCGdex
|
||||||
|
export * from './tcgdex'
|
@ -1,12 +1,16 @@
|
|||||||
import RequestWrapper from './Request'
|
import RequestWrapper from './Request'
|
||||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
||||||
|
|
||||||
type Endpoint = 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
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 ENDPOINTS: Array<Endpoint> = ['cards', 'categories', 'hp', 'illustrators', 'rarities', 'retreats', 'series', 'sets', 'types']
|
||||||
const BASE_URL = 'https://api.tcgdex.net/v2'
|
const BASE_URL = 'https://api.tcgdex.net/v2'
|
||||||
|
|
||||||
export default class TCGdex {
|
export default class TCGdex {
|
||||||
|
|
||||||
|
|
||||||
|
public static fetch: typeof fetch
|
||||||
|
|
||||||
|
public static readonly VERSION = "2.2.0"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated to change the lang use `this.lang`
|
* @deprecated to change the lang use `this.lang`
|
||||||
*/
|
*/
|
||||||
@ -169,3 +173,5 @@ export default class TCGdex {
|
|||||||
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
|
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from './interfaces'
|
11
tsconfig.es2015.json
Normal file
11
tsconfig.es2015.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"include": ["./src/tcgdex.node.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
|
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
|
"declaration": false, /* Generates corresponding '.d.ts' file. */
|
||||||
|
"declarationDir": null,
|
||||||
|
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,21 @@
|
|||||||
{
|
{
|
||||||
"include": ["**/*.ts"],
|
"include": ["./src/tcgdex.node.ts"],
|
||||||
"exclude": ["translations"],
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
"target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
"target": "ES2020", /* 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'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
// "declarationDir": "types", /* Folder where the declarations are*/
|
"declarationDir": "./dist/types", /* Folder where the declarations are*/
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
"outDir": "./dist/cjs", /* Redirect output structure to the directory. */
|
||||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
// "composite": true, /* Enable project compilation */
|
// "composite": true, /* Enable project compilation */
|
||||||
// "tsBuildInfoFile": "", /* Specify file to store incremental compilation information */
|
// "tsBuildInfoFile": "", /* Specify file to store incremental compilation information */
|
||||||
// "removeComments": true, /* Do not emit comments to output. */
|
// "removeComments": true, /* Do not emit comments to output. */
|
||||||
@ -26,24 +25,24 @@
|
|||||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||||
/* Strict Type-Checking Options */
|
/* Strict Type-Checking Options */
|
||||||
"strict": true, /* Enable all 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. */
|
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
"strictNullChecks": true, /* Enable strict null checks. */
|
"strictNullChecks": true, /* Enable strict null checks. */
|
||||||
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||||
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||||
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
"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. */
|
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
|
||||||
/* Additional Checks */
|
/* Additional Checks */
|
||||||
"noUnusedLocals": true, /* Report errors on unused locals. */
|
"noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
"noUnusedParameters": true, /* Report errors on unused parameters. */
|
"noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
"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,
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
/* Module Resolution Options */
|
/* Module Resolution Options */
|
||||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
@ -61,7 +60,7 @@
|
|||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
|
||||||
/* Experimental Options */
|
/* Experimental Options */
|
||||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
webpack.config.js
Normal file
31
webpack.config.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'production',
|
||||||
|
entry: './src/tcgdex.browser.ts',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'tcgdex.browser.js',
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
library: 'TCGdex',
|
||||||
|
umdNamedDefine: true
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.ts']
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: true
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
test: /\.ts$/,
|
||||||
|
loader: 'awesome-typescript-loader',
|
||||||
|
exclude: /node_modules/,
|
||||||
|
options: {
|
||||||
|
sourceMap: false,
|
||||||
|
declarationDir: false,
|
||||||
|
target: 'ES2016'
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user