diff --git a/.gitignore b/.gitignore index 399a6189..6379360e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +dist/ # Logs npm-debug.log* diff --git a/package.json b/package.json index 37ba402e..f1e4e2a5 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "querystringify": "^2.0.0" }, "devDependencies": { + "@types/node": "^18.15.13", "babel-plugin-rewire": "^1.2.0", "jest": "^23.6.0", "mockdate": "^2.0.2", diff --git a/src/client.js b/src/client.ts similarity index 85% rename from src/client.js rename to src/client.ts index 44af45a8..e593c7aa 100644 --- a/src/client.js +++ b/src/client.ts @@ -1,55 +1,60 @@ const fetch = require('lets-fetch') const nullCache = require('./cache/null') -const endpoints = require('./endpoints') +import * as endpoints from './endpoints/index' +import { Schema } from './endpoints/schemas/schema' +import { Language } from './types' const flow = require('./flow') -module.exports = class Client { +export class Client { + private schemaVersion = '2019-03-20T00:00:00.000Z' + private lang: Language = 'en' + private fetch = fetch + private caches = [nullCache()] + private debug = false + private client: Client + private apiKey: string + constructor () { - this.schemaVersion = '2019-03-20T00:00:00.000Z' - this.lang = 'en' - this.apiKey = false - this.fetch = fetch - this.caches = [nullCache()] - this.debug = false this.client = this } // Set the schema version - schema (schema) { + schema (schema: string) { this.schemaVersion = schema this.debugMessage(`set the schema to ${schema}`) return this } // Set the language for locale-aware endpoints - language (lang) { + language (lang: Language) { this.lang = lang this.debugMessage(`set the language to ${lang}`) return this } // Set the api key for authenticated endpoints - authenticate (apiKey) { + authenticate (apiKey: string) { this.apiKey = apiKey this.debugMessage(`set the api key to ${apiKey}`) return this } // Set the caching storage method(s) - cacheStorage (caches) { + // FIXME: type + cacheStorage (caches: any[]) { this.caches = [].concat(caches) this.debugMessage(`updated the cache storage`) return this } // Set the debugging flag - debugging (flag) { + debugging (flag: boolean) { this.debug = flag return this } // Print out a debug message if debugging is enabled - debugMessage (string) { + debugMessage (string: string) { if (this.debug) { console.log(`[gw2api-client] ${string}`) } @@ -81,15 +86,15 @@ module.exports = class Client { // All the different API endpoints account () { - return new endpoints.AccountEndpoint(this) + return new endpoints.AccountEndpoint(this) } achievements () { - return new endpoints.AchievementsEndpoint(this) + return new endpoints.AchievementsEndpoint(this) } backstory () { - return new endpoints.BackstoryEndpoint(this) + return new endpoints.BackstoryEndpoint(this) } build () { @@ -221,7 +226,8 @@ module.exports = class Client { } pvp () { - return new endpoints.PvpEndpoint(this) + // FIXME: bug? No fromAccount argument was originally provided, so it always behaved falsey + return new endpoints.PvpEndpoint(this, false) } quaggans () { @@ -283,4 +289,4 @@ module.exports = class Client { wvw () { return new endpoints.WvwEndpoint(this) } -} +} \ No newline at end of file diff --git a/src/endpoint.js b/src/endpoint.ts similarity index 82% rename from src/endpoint.js rename to src/endpoint.ts index 27cfbf30..777bb859 100644 --- a/src/endpoint.js +++ b/src/endpoint.ts @@ -1,81 +1,108 @@ +import { Language, URL } from "./types" + const qs = require('querystringify') const unique = require('array-unique') const chunk = require('chunk') const hashString = require('./hash') -const clone = (x) => JSON.parse(JSON.stringify(x)) +// FIXME: replace with structuredClone? +const clone = (x: T): T => JSON.parse(JSON.stringify(x)) + +interface Headers { + headers: { + get: (prop: string) => T + }, + json: Function +} + +interface IDable { + id: number +} + +// FIXME: remove any! Just to make compilation go through for now +export class AbstractEndpoint { + public client + protected schemaVersion: string + protected lang: Language + protected apiKey + protected fetch + protected caches + protected debug + protected baseUrl: URL = 'https://api.guildwars2.com' + protected isPaginated = false + protected maxPageSize = 200 + protected isBulk = false + protected supportsBulkAll = true + protected isLocalized = false + protected isAuthenticated = false + protected isOptionallyAuthenticated = false + protected credentials = false + private _skipCache = false + + protected url: string + protected cacheTime: number -module.exports = class AbstractEndpoint { constructor (parent) { this.client = parent.client - this.schemaVersion = parent.schemaVersion || '2019-03-20T00:00:00.000Z' + this.schemaVersion = parent.schemaVersion ?? '2019-03-20T00:00:00.000Z' this.lang = parent.lang this.apiKey = parent.apiKey this.fetch = parent.fetch this.caches = parent.caches this.debug = parent.debug - - this.baseUrl = 'https://api.guildwars2.com' - this.isPaginated = false - this.maxPageSize = 200 - this.isBulk = false - this.supportsBulkAll = true - this.isLocalized = false - this.isAuthenticated = false - this.isOptionallyAuthenticated = false - this.credentials = false - - this._skipCache = false } // Set the schema version - schema (schema) { + // FIXME: Type + public schema (schema): this { this.schemaVersion = schema this.debugMessage(`set the schema to ${schema}`) return this } // Check if the schema version includes a specific version - _schemaIncludes (date) { + private _schemaIncludes (date): boolean { return this.schemaVersion >= date } // Set the language for locale-aware endpoints - language (lang) { + public language (lang: Language): this { this.lang = lang this.debugMessage(`set the language to ${lang}`) return this } // Set the api key for authenticated endpoints - authenticate (apiKey) { + // FIXME: type + public authenticate (apiKey): this { this.apiKey = apiKey this.debugMessage(`set the api key to ${apiKey}`) return this } // Set the debugging flag - debugging (flag) { + // FIXME: enum + public debugging (flag): this { this.debug = flag return this } // Print out a debug message if debugging is enabled - debugMessage (string) { + public debugMessage (string: string) { if (this.debug) { console.log(`[gw2api-client] ${string}`) } } // Skip caching and get the live data - live () { + public live (): this { this._skipCache = true this.debugMessage(`skipping cache`) return this } // Get all ids - ids () { + public async ids (): Promise { this.debugMessage(`ids(${this.url}) called`) if (!this.isBulk) { @@ -110,13 +137,15 @@ module.exports = class AbstractEndpoint { } // Get all ids from the live API - _ids () { + private async _ids (): Promise { this.debugMessage(`ids(${this.url}) requesting from api`) return this._request(this.url) } // Get a single entry by id - get (id, url = false) { + public async get (id: string, url?: true): Promise; + public async get (id: number, url?: false): Promise; + public async get (id: number | string, url: boolean = false): Promise { this.debugMessage(`get(${this.url}) called`) if (!id && this.isBulk && !url) { @@ -151,7 +180,7 @@ module.exports = class AbstractEndpoint { } // Get a single entry by id from the live API - _get (id, url) { + private async _get (id: number | string, url: boolean): Promise { this.debugMessage(`get(${this.url}) requesting from api`) // Request the single id if the endpoint a bulk endpoint @@ -169,7 +198,7 @@ module.exports = class AbstractEndpoint { } // Get multiple entries by ids - many (ids) { + public async many (ids: number[]): Promise { this.debugMessage(`many(${this.url}) called (${ids.length} ids)`) if (!this.isBulk) { @@ -201,7 +230,7 @@ module.exports = class AbstractEndpoint { this.debugMessage(`many(${this.url}) resolving partially from cache (${cached.length} ids)`) const missingIds = getMissingIds(ids, cached) - return this._many(missingIds, cached.length > 0).then(content => { + return this._many(missingIds, cached.length > 0).then(content => { const cacheContent = content.map(value => [this._cacheHash(value.id), value]) this._cacheSetMany(cacheContent) @@ -230,7 +259,7 @@ module.exports = class AbstractEndpoint { } // Get multiple entries by ids from the live API - _many (ids, partialRequest = false) { + private async _many (ids, partialRequest = false): Promise { this.debugMessage(`many(${this.url}) requesting from api (${ids.length} ids)`) // Chunk the requests to the max page size @@ -250,13 +279,13 @@ module.exports = class AbstractEndpoint { } // Work on all requests in parallel and then flatten the responses into one - return this._requestMany(requests) + return this._requestMany(requests) .then(responses => responses.reduce((x, y) => x.concat(y), [])) .catch(handleMissingIds) } // Get a single page - page (page, size = this.maxPageSize) { + public page (page: number, size = this.maxPageSize) { this.debugMessage(`page(${this.url}) called`) if (!this.isBulk && !this.isPaginated) { @@ -284,7 +313,7 @@ module.exports = class AbstractEndpoint { return cached } - return this._page(page, size).then(content => { + return this._page(page, size).then(content => { let cacheContent = [[hash, content]] if (this.isBulk) { @@ -305,13 +334,13 @@ module.exports = class AbstractEndpoint { } // Get a single page from the live API - _page (page, size) { + private async _page (page: number, size: number): Promise { this.debugMessage(`page(${this.url}) requesting from api`) return this._request(`${this.url}?page=${page}&page_size=${size}`) } // Get all entries - all () { + public async all (): Promise { this.debugMessage(`all(${this.url}) called`) if (!this.isBulk && !this.isPaginated) { @@ -320,7 +349,7 @@ module.exports = class AbstractEndpoint { // There is no cache time set, so always use the live data if (!this.cacheTime) { - return this._all() + return this._all() } // Get as much as possible out of the cache @@ -331,7 +360,7 @@ module.exports = class AbstractEndpoint { return cached } - return this._all().then(content => { + return this._all().then(content => { let cacheContent = [[hash, content]] if (this.isBulk) { @@ -352,7 +381,7 @@ module.exports = class AbstractEndpoint { } // Get all entries from the live API - _all () { + private _all (): Promise { this.debugMessage(`all(${this.url}) requesting from api`) // Use bulk expansion if the endpoint supports the "all" keyword @@ -362,10 +391,11 @@ module.exports = class AbstractEndpoint { // Get everything via all pages instead let totalEntries - return this._request(`${this.url}?page=0&page_size=${this.maxPageSize}`, 'response') + return this._request(`${this.url}?page=0&page_size=${this.maxPageSize}`, 'response') .then(firstPage => { + // Get the total number of entries off the first page's headers - totalEntries = firstPage.headers.get('X-Result-Total') + totalEntries = firstPage.headers.get('X-Result-Total') return firstPage.json() }) .then(result => { @@ -380,7 +410,7 @@ module.exports = class AbstractEndpoint { requests.push(`${this.url}?page=${page}&page_size=${this.maxPageSize}`) } - return this._requestMany(requests).then(responses => { + return this._requestMany(requests).then(responses => { responses = responses.reduce((x, y) => x.concat(y), []) return result.concat(responses) }) @@ -460,7 +490,8 @@ module.exports = class AbstractEndpoint { } // Execute a single request - _request (url, type = 'json') { + // FIXME: not sure if Headers is best placed here + private async _request (url, type = 'json'): Promise { url = this._buildUrl(url) /* istanbul ignore next */ @@ -470,7 +501,7 @@ module.exports = class AbstractEndpoint { } // Execute multiple requests in parallel - _requestMany (urls, type = 'json') { + private async _requestMany (urls, type = 'json'): Promise { urls = urls.map(url => this._buildUrl(url)) /* istanbul ignore next */ @@ -480,13 +511,13 @@ module.exports = class AbstractEndpoint { } // Build the headers for localization and authentication - _buildUrl (url) { + private _buildUrl (url: string): string { // Add the base url url = this.baseUrl + url // Parse a possibly existing query - const parsedUrl = url.split('?') - let parsedQuery = qs.parse(parsedUrl[1] || '') + const [base, urlParameters] = url.split('?') + const parsedQuery = qs.parse(urlParameters ?? '') let query = {} @@ -509,11 +540,11 @@ module.exports = class AbstractEndpoint { // Build the url with the finished query query = qs.stringify(query, true).replace(/%2C/g, ',') - return parsedUrl[0] + query + return base + query } // Guarantee the element order of bulk results - _sortByIdList (entries, ids) { + private _sortByIdList (entries: IDable[], ids: number[]): IDable[] { // Hash map of the indexes for better time complexity on big arrays let indexMap = {} ids.map((x, i) => { @@ -525,7 +556,7 @@ module.exports = class AbstractEndpoint { return entries } - _usesApiKey () { + private _usesApiKey (): boolean { return this.isAuthenticated && (!this.isOptionallyAuthenticated || this.apiKey) } } diff --git a/src/endpoints/account-blob.js b/src/endpoints/account-blob.ts similarity index 100% rename from src/endpoints/account-blob.js rename to src/endpoints/account-blob.ts diff --git a/src/endpoints/account.js b/src/endpoints/account.ts similarity index 98% rename from src/endpoints/account.js rename to src/endpoints/account.ts index dae73f6e..0300bddf 100644 --- a/src/endpoints/account.js +++ b/src/endpoints/account.ts @@ -1,11 +1,12 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' const CharactersEndpoint = require('./characters') const PvpEndpoint = require('./pvp') const CommerceEndpoint = require('./commerce') const accountBlob = require('./account-blob.js') const resetTime = require('../helpers/resetTime') -class AccountEndpoint extends AbstractEndpoint { +export class AccountEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/account' @@ -457,5 +458,3 @@ async function isStaleWeeklyData (endpointInstance) { const account = await new AccountEndpoint(endpointInstance).schema('2019-03-26').get() return new Date(account.last_modified) < resetTime.getLastWeeklyReset() } - -module.exports = AccountEndpoint diff --git a/src/endpoints/achievements.js b/src/endpoints/achievements.ts similarity index 68% rename from src/endpoints/achievements.js rename to src/endpoints/achievements.ts index 1d71055d..92cbf822 100644 --- a/src/endpoints/achievements.js +++ b/src/endpoints/achievements.ts @@ -1,6 +1,7 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class AchievementsEndpoint extends AbstractEndpoint { +export class AchievementsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/achievements' @@ -28,7 +29,7 @@ module.exports = class AchievementsEndpoint extends AbstractEndpoint { } } -class CategoriesEndpoint extends AbstractEndpoint { +class CategoriesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/achievements/categories' @@ -39,7 +40,8 @@ class CategoriesEndpoint extends AbstractEndpoint { } } -class GroupsEndpoint extends AbstractEndpoint { + +class GroupsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/achievements/groups' @@ -50,7 +52,7 @@ class GroupsEndpoint extends AbstractEndpoint { } } -class DailyEndpoint extends AbstractEndpoint { +class DailyEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/achievements/daily' @@ -58,7 +60,7 @@ class DailyEndpoint extends AbstractEndpoint { } } -class DailyTomorrowEndpoint extends AbstractEndpoint { +class DailyTomorrowEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/achievements/daily/tomorrow' diff --git a/src/endpoints/backstory.js b/src/endpoints/backstory.ts similarity index 54% rename from src/endpoints/backstory.js rename to src/endpoints/backstory.ts index 53655ebf..c10d2e84 100644 --- a/src/endpoints/backstory.js +++ b/src/endpoints/backstory.ts @@ -1,16 +1,17 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class BackstoryEndpoint extends AbstractEndpoint { +export class BackstoryEndpoint extends AbstractEndpoint { answers () { - return new AnswersEndpoint(this) + return new AnswersEndpoint(this) } questions () { - return new QuestionsEndpoint(this) + return new QuestionsEndpoint(this) } } -class AnswersEndpoint extends AbstractEndpoint { +class AnswersEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/backstory/answers' @@ -22,7 +23,7 @@ class AnswersEndpoint extends AbstractEndpoint { } } -class QuestionsEndpoint extends AbstractEndpoint { +class QuestionsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/backstory/questions' diff --git a/src/endpoints/build.js b/src/endpoints/build.js deleted file mode 100644 index baa04307..00000000 --- a/src/endpoints/build.js +++ /dev/null @@ -1,13 +0,0 @@ -const AbstractEndpoint = require('../endpoint') - -module.exports = class BuildEndpoint extends AbstractEndpoint { - constructor (client) { - super(client) - this.url = '/v2/build' - this.cacheTime = 60 - } - - get () { - return super.get().then(result => result.id) - } -} diff --git a/src/endpoints/build.ts b/src/endpoints/build.ts new file mode 100644 index 00000000..28b0fd3c --- /dev/null +++ b/src/endpoints/build.ts @@ -0,0 +1,16 @@ +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' + +// FIXME: move id into superclass somewhere +export class BuildEndpoint extends AbstractEndpoint { + constructor (client) { + super(client) + this.url = '/v2/build' + this.cacheTime = 60 + } + + get (): Promise { + // FIXME: bug? Formerly, no ID was passed, which would cause an error in the nullish check in super.get() + return super.get(-1).then(result => result.id) + } +} diff --git a/src/endpoints/cats.js b/src/endpoints/cats.js deleted file mode 100644 index 04d9a76a..00000000 --- a/src/endpoints/cats.js +++ /dev/null @@ -1,11 +0,0 @@ -const AbstractEndpoint = require('../endpoint') - -module.exports = class CatsEndpoint extends AbstractEndpoint { - constructor (client) { - super(client) - this.url = '/v2/cats' - this.isPaginated = true - this.isBulk = true - this.cacheTime = 24 * 60 * 60 - } -} diff --git a/src/endpoints/cats.ts b/src/endpoints/cats.ts new file mode 100644 index 00000000..44e8d8eb --- /dev/null +++ b/src/endpoints/cats.ts @@ -0,0 +1,12 @@ +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' + +export class CatsEndpoint extends AbstractEndpoint { + constructor (client) { + super(client) + this.url = '/v2/cats' + this.isPaginated = true + this.isBulk = true + this.cacheTime = 24 * 60 * 60 + } +} diff --git a/src/endpoints/characters.js b/src/endpoints/characters.ts similarity index 95% rename from src/endpoints/characters.js rename to src/endpoints/characters.ts index 8d9d2411..1e00034a 100644 --- a/src/endpoints/characters.js +++ b/src/endpoints/characters.ts @@ -1,6 +1,9 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' + +export class CharactersEndpoint extends AbstractEndpoint { + public name: string -module.exports = class CharactersEndpoint extends AbstractEndpoint { constructor (client, name) { super(client) this.name = name diff --git a/src/endpoints/colors.js b/src/endpoints/colors.ts similarity index 52% rename from src/endpoints/colors.js rename to src/endpoints/colors.ts index 8bb97e61..b6f93d1f 100644 --- a/src/endpoints/colors.js +++ b/src/endpoints/colors.ts @@ -1,6 +1,7 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class ColorsEndpoint extends AbstractEndpoint { +export class ColorsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/colors' diff --git a/src/endpoints/commerce.js b/src/endpoints/commerce.ts similarity index 87% rename from src/endpoints/commerce.js rename to src/endpoints/commerce.ts index 248ac471..a444c79f 100644 --- a/src/endpoints/commerce.js +++ b/src/endpoints/commerce.ts @@ -1,28 +1,28 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class CommerceEndpoint extends AbstractEndpoint { +export class CommerceEndpoint extends AbstractEndpoint { // Current things to grab in the delivery box - delivery () { + public delivery () { return new DeliveryEndpoint(this) } // Current gem/coin exchange rates - exchange () { + public exchange () { return new ExchangeEndpoint(this) } // Current tradingpost listings - listings () { + public listings () { return new ListingsEndpoint(this) } // Current tradingpost prices - prices () { + public prices () { return new PricesEndpoint(this) } // Current and completed transactions - transactions () { + public transactions () { return { current: () => ({ buys: () => new TransactionsEndpoint(this, 'current', 'buys'), @@ -52,11 +52,11 @@ class ExchangeEndpoint extends AbstractEndpoint { this.cacheTime = 10 * 60 } - gems (quantity) { + gems (quantity: number) { return super.get(`/gems?quantity=${quantity}`, true) } - coins (quantity) { + coins (quantity: number) { return super.get(`/coins?quantity=${quantity}`, true) } } diff --git a/src/endpoints/continents.js b/src/endpoints/continents.ts similarity index 60% rename from src/endpoints/continents.js rename to src/endpoints/continents.ts index b301b3eb..84f226bc 100644 --- a/src/endpoints/continents.js +++ b/src/endpoints/continents.ts @@ -1,6 +1,7 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class ContinentsEndpoint extends AbstractEndpoint { +export class ContinentsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/continents' @@ -10,12 +11,12 @@ module.exports = class ContinentsEndpoint extends AbstractEndpoint { this.cacheTime = 24 * 60 * 60 } - floors (id) { + floors (id: number) { return new FloorsEndpoint(this, id) } } -class FloorsEndpoint extends AbstractEndpoint { +class FloorsEndpoint extends AbstractEndpoint { constructor (client, continentId) { super(client) this.url = `/v2/continents/${continentId}/floors` diff --git a/src/endpoints/currencies.js b/src/endpoints/currencies.js deleted file mode 100644 index 495d5333..00000000 --- a/src/endpoints/currencies.js +++ /dev/null @@ -1,12 +0,0 @@ -const AbstractEndpoint = require('../endpoint') - -module.exports = class CurrenciesEndpoint extends AbstractEndpoint { - constructor (client) { - super(client) - this.url = '/v2/currencies' - this.isPaginated = true - this.isBulk = true - this.isLocalized = true - this.cacheTime = 24 * 60 * 60 - } -} diff --git a/src/endpoints/currencies.ts b/src/endpoints/currencies.ts new file mode 100644 index 00000000..ee1b66b8 --- /dev/null +++ b/src/endpoints/currencies.ts @@ -0,0 +1,21 @@ +import { AbstractEndpoint } from '../endpoint' +import { URL } from '../types' + +interface Currency { + id: number, + string: string, + description: string, + icon: URL, + order: number +} + +export class CurrenciesEndpoint extends AbstractEndpoint { + constructor (client) { + super(client) + this.url = '/v2/currencies' + this.isPaginated = true + this.isBulk = true + this.isLocalized = true + this.cacheTime = 24 * 60 * 60 + } +} diff --git a/src/endpoints/dailycrafting.js b/src/endpoints/dailycrafting.ts similarity index 51% rename from src/endpoints/dailycrafting.js rename to src/endpoints/dailycrafting.ts index b8cfaa2a..0ee5c8e7 100644 --- a/src/endpoints/dailycrafting.js +++ b/src/endpoints/dailycrafting.ts @@ -1,6 +1,7 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class DailycraftingEndpoint extends AbstractEndpoint { +export class DailycraftingEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/dailycrafting' diff --git a/src/endpoints/dungeons.js b/src/endpoints/dungeons.js deleted file mode 100644 index ccfc604e..00000000 --- a/src/endpoints/dungeons.js +++ /dev/null @@ -1,11 +0,0 @@ -const AbstractEndpoint = require('../endpoint') - -module.exports = class DungeonsEndpoint extends AbstractEndpoint { - constructor (client) { - super(client) - this.url = '/v2/dungeons' - this.isPaginated = true - this.isBulk = true - this.cacheTime = 24 * 60 * 60 - } -} diff --git a/src/endpoints/dungeons.ts b/src/endpoints/dungeons.ts new file mode 100644 index 00000000..8f13a0e6 --- /dev/null +++ b/src/endpoints/dungeons.ts @@ -0,0 +1,12 @@ +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' + +export class DungeonsEndpoint extends AbstractEndpoint { + constructor (client) { + super(client) + this.url = '/v2/dungeons' + this.isPaginated = true + this.isBulk = true + this.cacheTime = 24 * 60 * 60 + } +} \ No newline at end of file diff --git a/src/endpoints/emblem.js b/src/endpoints/emblem.ts similarity index 77% rename from src/endpoints/emblem.js rename to src/endpoints/emblem.ts index 5d67e776..f11ade4d 100644 --- a/src/endpoints/emblem.js +++ b/src/endpoints/emblem.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class EmblemEndpoint extends AbstractEndpoint { +export class EmblemEndpoint extends AbstractEndpoint { backgrounds () { return new LayersEndpoint(this, 'backgrounds') } diff --git a/src/endpoints/events.js b/src/endpoints/events.ts similarity index 71% rename from src/endpoints/events.js rename to src/endpoints/events.ts index b39231a9..84d4ba10 100644 --- a/src/endpoints/events.js +++ b/src/endpoints/events.ts @@ -1,6 +1,8 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class EventsEndpoint extends AbstractEndpoint { +type EventID = string + +export class EventsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v1/event_details.json' @@ -11,12 +13,12 @@ module.exports = class EventsEndpoint extends AbstractEndpoint { return super.get().then(transformV1Format) } - get (id) { + get (id: number) { return super.get(`?event_id=${id}`, true).then(json => transformV1Format(json)[0]) } } -function transformV1Format (json) { +function transformV1Format (json: {events: any[]}): {}[] { let events = json.events let transformed = [] const keys = Object.keys(events) diff --git a/src/endpoints/files.js b/src/endpoints/files.ts similarity index 59% rename from src/endpoints/files.js rename to src/endpoints/files.ts index 565d249a..fb78d5e1 100644 --- a/src/endpoints/files.js +++ b/src/endpoints/files.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class FilesEndpoint extends AbstractEndpoint { +export class FilesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/files' diff --git a/src/endpoints/finishers.js b/src/endpoints/finishers.ts similarity index 62% rename from src/endpoints/finishers.js rename to src/endpoints/finishers.ts index 7c4b1051..fda9d168 100644 --- a/src/endpoints/finishers.js +++ b/src/endpoints/finishers.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class FinishersEndpoint extends AbstractEndpoint { +export class FinishersEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/finishers' diff --git a/src/endpoints/gliders.js b/src/endpoints/gliders.ts similarity index 52% rename from src/endpoints/gliders.js rename to src/endpoints/gliders.ts index fa237abb..62f01c59 100644 --- a/src/endpoints/gliders.js +++ b/src/endpoints/gliders.ts @@ -1,6 +1,7 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' -module.exports = class GlidersEndpoint extends AbstractEndpoint { +export class GlidersEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/gliders' diff --git a/src/endpoints/guild.js b/src/endpoints/guild.ts similarity index 87% rename from src/endpoints/guild.js rename to src/endpoints/guild.ts index 6ffda69f..205a8d3a 100644 --- a/src/endpoints/guild.js +++ b/src/endpoints/guild.ts @@ -1,7 +1,12 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class GuildEndpoint extends AbstractEndpoint { - constructor (client, id) { +type GuildID = string +type LogID = number + +export class GuildEndpoint extends AbstractEndpoint { + private id: GuildID + + constructor (client, id: GuildID) { super(client) this.id = id this.url = '/v2/guild' @@ -10,7 +15,7 @@ module.exports = class GuildEndpoint extends AbstractEndpoint { this.cacheTime = 60 * 60 } - get (id) { + get (id: number) { return super.get(`/${id}`, true) } @@ -18,8 +23,9 @@ module.exports = class GuildEndpoint extends AbstractEndpoint { return new PermissionsEndpoint(this) } - search (name) { - return new SearchEndpoint(this, name) + search (name: string) { + // FIXME: bug? Constructor got passed `name` before (which is not received in the constructor) instead of chaining the call + return new SearchEndpoint(this) //, name) } upgrades () { @@ -77,7 +83,7 @@ class SearchEndpoint extends AbstractEndpoint { this.cacheTime = 60 * 60 } - name (name) { + name (name: string) { return super.get(`?name=${encodeURIComponent(name)}`, true) .then(result => result[0]) } @@ -102,7 +108,7 @@ class LogEndpoint extends AbstractEndpoint { this.cacheTime = 5 * 60 } - since (logId) { + since (logId: LogID) { return super.get(`?since=${logId}`, true) } } diff --git a/src/endpoints/home.js b/src/endpoints/home.ts similarity index 82% rename from src/endpoints/home.js rename to src/endpoints/home.ts index c4a6faff..52ea538a 100644 --- a/src/endpoints/home.js +++ b/src/endpoints/home.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class HomeEndpoint extends AbstractEndpoint { +export class HomeEndpoint extends AbstractEndpoint { cats () { return new CatsEndpoint(this) } diff --git a/src/endpoints/index.js b/src/endpoints/index.js deleted file mode 100644 index aabf021b..00000000 --- a/src/endpoints/index.js +++ /dev/null @@ -1,53 +0,0 @@ -module.exports = { - AccountEndpoint: require('./account'), - AchievementsEndpoint: require('./achievements'), - BackstoryEndpoint: require('./backstory'), - BuildEndpoint: require('./build'), - CatsEndpoint: require('./cats'), - CharactersEndpoint: require('./characters'), - ColorsEndpoint: require('./colors'), - CommerceEndpoint: require('./commerce'), - ContinentsEndpoint: require('./continents'), - CurrenciesEndpoint: require('./currencies'), - DailycraftingEndpoint: require('./dailycrafting'), - DungeonsEndpoint: require('./dungeons'), - EmblemEndpoint: require('./emblem'), - EventsEndpoint: require('./events'), - FilesEndpoint: require('./files'), - FinishersEndpoint: require('./finishers'), - GlidersEndpoint: require('./gliders'), - GuildEndpoint: require('./guild'), - HomeEndpoint: require('./home'), - ItemsEndpoint: require('./items'), - ItemstatsEndpoint: require('./itemstats'), - LegendaryarmoryEndpoint: require('./legendaryarmory'), - LegendsEndpoint: require('./legends'), - MailcarriersEndpoint: require('./mailcarriers'), - MapchestsEndpoint: require('./mapchests'), - MapsEndpoint: require('./maps'), - MasteriesEndpoint: require('./masteries'), - MaterialsEndpoint: require('./materials'), - MinisEndpoint: require('./minis'), - MountsEndpoint: require('./mounts'), - NodesEndpoint: require('./nodes'), - NoveltiesEndpoint: require('./novelties'), - OutfitsEndpoint: require('./outfits'), - PetsEndpoint: require('./pets'), - ProfessionsEndpoint: require('./professions'), - PvpEndpoint: require('./pvp'), - QuaggansEndpoint: require('./quaggans'), - QuestsEndpoint: require('./quests'), - RacesEndpoint: require('./races'), - RaidsEndpoint: require('./raids'), - RecipesEndpoint: require('./recipes'), - SkillsEndpoint: require('./skills'), - SkinsEndpoint: require('./skins'), - SpecializationsEndpoint: require('./specializations'), - StoriesEndpoint: require('./stories'), - TitlesEndpoint: require('./titles'), - TokeninfoEndpoint: require('./tokeninfo'), - TraitsEndpoint: require('./traits'), - WorldbossesEndpoint: require('./worldbosses'), - WorldsEndpoint: require('./worlds'), - WvwEndpoint: require('./wvw') -} diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts new file mode 100644 index 00000000..06cee899 --- /dev/null +++ b/src/endpoints/index.ts @@ -0,0 +1,51 @@ +export { AccountEndpoint } from './account' +export { AchievementsEndpoint } from './achievements' +export { BackstoryEndpoint } from './backstory' +export { BuildEndpoint } from './build' +export { CatsEndpoint } from './cats' +export { CharactersEndpoint } from './characters' +export { ColorsEndpoint } from './colors' +export { CommerceEndpoint } from './commerce' +export { ContinentsEndpoint } from './continents' +export { CurrenciesEndpoint } from './currencies' +export { DailycraftingEndpoint } from './dailycrafting' +export { DungeonsEndpoint } from './dungeons' +export { EmblemEndpoint } from './emblem' +export { EventsEndpoint } from './events' +export { FilesEndpoint } from './files' +export { FinishersEndpoint } from './finishers' +export { GlidersEndpoint } from './gliders' +export { GuildEndpoint } from './guild' +export { HomeEndpoint } from './home' +export { ItemsEndpoint } from './items' +export { ItemstatsEndpoint } from './itemstats' +export { LegendaryarmoryEndpoint } from './legendaryarmory' +export { LegendsEndpoint } from './legends' +export { MailcarriersEndpoint } from './mailcarriers' +export { MapchestsEndpoint } from './mapchests' +export { MapsEndpoint } from './maps' +export { MasteriesEndpoint } from './masteries' +export { MaterialsEndpoint } from './materials' +export { MinisEndpoint } from './minis' +export { MountsEndpoint } from './mounts' +export { NodesEndpoint } from './nodes' +export { NoveltiesEndpoint } from './novelties' +export { OutfitsEndpoint } from './outfits' +export { PetsEndpoint } from './pets' +export { ProfessionsEndpoint } from './professions' +export { PvpEndpoint } from './pvp' +export { QuaggansEndpoint } from './quaggans' +export { QuestsEndpoint } from './quests' +export { RacesEndpoint } from './races' +export { RaidsEndpoint } from './raids' +export { RecipesEndpoint } from './recipes' +export { SkillsEndpoint } from './skills' +export { SkinsEndpoint } from './skins' +export { SpecializationsEndpoint } from './specializations' +export { StoriesEndpoint } from './stories' +export { TitlesEndpoint } from './titles' +export { TokeninfoEndpoint } from './tokeninfo' +export { TraitsEndpoint } from './traits' +export { WorldbossesEndpoint } from './worldbosses' +export { WorldsEndpoint } from './worlds' +export { WvwEndpoint } from './wvw' diff --git a/src/endpoints/items.js b/src/endpoints/items.ts similarity index 66% rename from src/endpoints/items.js rename to src/endpoints/items.ts index 6091d611..e3e8ff17 100644 --- a/src/endpoints/items.js +++ b/src/endpoints/items.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class ItemsEndpoint extends AbstractEndpoint { +export class ItemsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/items' diff --git a/src/endpoints/itemstats.js b/src/endpoints/itemstats.ts similarity index 62% rename from src/endpoints/itemstats.js rename to src/endpoints/itemstats.ts index 798a4cec..1e66bd86 100644 --- a/src/endpoints/itemstats.js +++ b/src/endpoints/itemstats.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class ItemstatsEndpoint extends AbstractEndpoint { +export class ItemstatsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/itemstats' diff --git a/src/endpoints/legendaryarmory.js b/src/endpoints/legendaryarmory.ts similarity index 58% rename from src/endpoints/legendaryarmory.js rename to src/endpoints/legendaryarmory.ts index cafcab57..91021eba 100644 --- a/src/endpoints/legendaryarmory.js +++ b/src/endpoints/legendaryarmory.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class LegendaryarmoryEndpoint extends AbstractEndpoint { +export class LegendaryarmoryEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/legendaryarmory' diff --git a/src/endpoints/legends.js b/src/endpoints/legends.ts similarity index 58% rename from src/endpoints/legends.js rename to src/endpoints/legends.ts index 3bd64df5..729568a4 100644 --- a/src/endpoints/legends.js +++ b/src/endpoints/legends.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class LegendsEndpoint extends AbstractEndpoint { +export class LegendsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/legends' diff --git a/src/endpoints/mailcarriers.js b/src/endpoints/mailcarriers.ts similarity index 62% rename from src/endpoints/mailcarriers.js rename to src/endpoints/mailcarriers.ts index 26b9e319..27e179c5 100644 --- a/src/endpoints/mailcarriers.js +++ b/src/endpoints/mailcarriers.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MailcarriersEndpoint extends AbstractEndpoint { +export class MailcarriersEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/mailcarriers' diff --git a/src/endpoints/mapchests.js b/src/endpoints/mapchests.ts similarity index 62% rename from src/endpoints/mapchests.js rename to src/endpoints/mapchests.ts index 453eb837..77783446 100644 --- a/src/endpoints/mapchests.js +++ b/src/endpoints/mapchests.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MapchestsEndpoint extends AbstractEndpoint { +export class MapchestsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/mapchests' diff --git a/src/endpoints/maps.js b/src/endpoints/maps.ts similarity index 63% rename from src/endpoints/maps.js rename to src/endpoints/maps.ts index 4c2c0732..59f33272 100644 --- a/src/endpoints/maps.js +++ b/src/endpoints/maps.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MapsEndpoint extends AbstractEndpoint { +export class MapsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/maps' diff --git a/src/endpoints/masteries.js b/src/endpoints/masteries.ts similarity index 62% rename from src/endpoints/masteries.js rename to src/endpoints/masteries.ts index 26514863..98be0b6f 100644 --- a/src/endpoints/masteries.js +++ b/src/endpoints/masteries.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MasteriesEndpoint extends AbstractEndpoint { +export class MasteriesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/masteries' diff --git a/src/endpoints/materials.js b/src/endpoints/materials.ts similarity index 62% rename from src/endpoints/materials.js rename to src/endpoints/materials.ts index 069b1469..5f6cc3cb 100644 --- a/src/endpoints/materials.js +++ b/src/endpoints/materials.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MaterialsEndpoint extends AbstractEndpoint { +export class MaterialsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/materials' diff --git a/src/endpoints/minis.js b/src/endpoints/minis.ts similarity index 62% rename from src/endpoints/minis.js rename to src/endpoints/minis.ts index 9d0f8fac..90ed458b 100644 --- a/src/endpoints/minis.js +++ b/src/endpoints/minis.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MinisEndpoint extends AbstractEndpoint { +export class MinisEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/minis' diff --git a/src/endpoints/mounts.js b/src/endpoints/mounts.ts similarity index 84% rename from src/endpoints/mounts.js rename to src/endpoints/mounts.ts index a5e9dfd4..27b1cf82 100644 --- a/src/endpoints/mounts.js +++ b/src/endpoints/mounts.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class MountsEndpoint extends AbstractEndpoint { +export class MountsEndpoint extends AbstractEndpoint { skins () { return new SkinsEndpoint(this) } diff --git a/src/endpoints/nodes.js b/src/endpoints/nodes.ts similarity index 59% rename from src/endpoints/nodes.js rename to src/endpoints/nodes.ts index 361fa663..390afb95 100644 --- a/src/endpoints/nodes.js +++ b/src/endpoints/nodes.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class NodesEndpoint extends AbstractEndpoint { +export class NodesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/nodes' diff --git a/src/endpoints/novelties.js b/src/endpoints/novelties.ts similarity index 62% rename from src/endpoints/novelties.js rename to src/endpoints/novelties.ts index 47acce0d..b34758bf 100644 --- a/src/endpoints/novelties.js +++ b/src/endpoints/novelties.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class NoveltiesEndpoint extends AbstractEndpoint { +export class NoveltiesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/novelties' diff --git a/src/endpoints/outfits.js b/src/endpoints/outfits.ts similarity index 62% rename from src/endpoints/outfits.js rename to src/endpoints/outfits.ts index 673adcb3..644a93ba 100644 --- a/src/endpoints/outfits.js +++ b/src/endpoints/outfits.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class OutfitsEndpoint extends AbstractEndpoint { +export class OutfitsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/outfits' diff --git a/src/endpoints/pets.js b/src/endpoints/pets.ts similarity index 63% rename from src/endpoints/pets.js rename to src/endpoints/pets.ts index cad51b9e..4b12c09b 100644 --- a/src/endpoints/pets.js +++ b/src/endpoints/pets.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class PetsEndpoint extends AbstractEndpoint { +export class PetsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/pets' diff --git a/src/endpoints/professions.js b/src/endpoints/professions.ts similarity index 62% rename from src/endpoints/professions.js rename to src/endpoints/professions.ts index 78d0019d..9525e49c 100644 --- a/src/endpoints/professions.js +++ b/src/endpoints/professions.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class ProfessionsEndpoint extends AbstractEndpoint { +export class ProfessionsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/professions' diff --git a/src/endpoints/pvp.js b/src/endpoints/pvp.ts similarity index 85% rename from src/endpoints/pvp.js rename to src/endpoints/pvp.ts index e397046b..2a538ef4 100644 --- a/src/endpoints/pvp.js +++ b/src/endpoints/pvp.ts @@ -1,7 +1,14 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class PvpEndpoint extends AbstractEndpoint { - constructor (client, fromAccount) { + +type SeasonID = string +type Region = 'na' | 'eu' +type Board = 'guild' | 'legendary' + +export class PvpEndpoint extends AbstractEndpoint { + private fromAccount: boolean + + constructor (client, fromAccount: boolean) { super(client) this.fromAccount = fromAccount } @@ -93,7 +100,9 @@ class RanksEndpoint extends AbstractEndpoint { } class SeasonsEndpoint extends AbstractEndpoint { - constructor (client, id) { + private id: SeasonID + + constructor (client, id: SeasonID) { super(client) this.id = id this.url = '/v2/pvp/seasons' @@ -109,24 +118,26 @@ class SeasonsEndpoint extends AbstractEndpoint { } class SeasonLeaderboardEndpoint extends AbstractEndpoint { - constructor (client, id) { + private id: SeasonID + + constructor (client, id: SeasonID) { super(client) this.id = id this.url = `/v2/pvp/seasons/${id}/leaderboards` this.cacheTime = 24 * 60 * 60 } - ids () { + public ids () { return super.get('', true) } - board (board, region) { + public board (board, region) { return new SeasonLeaderboardBoardEndpoint(this, this.id, board, region) } } class SeasonLeaderboardBoardEndpoint extends AbstractEndpoint { - constructor (client, id, board, region) { + constructor (client, id: SeasonID, board: Board, region: Region) { super(client) this.url = `/v2/pvp/seasons/${id}/leaderboards/${board}/${region}` this.isPaginated = true diff --git a/src/endpoints/quaggans.js b/src/endpoints/quaggans.ts similarity index 58% rename from src/endpoints/quaggans.js rename to src/endpoints/quaggans.ts index dd7a219d..77203dea 100644 --- a/src/endpoints/quaggans.js +++ b/src/endpoints/quaggans.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class QuaggansEndpoint extends AbstractEndpoint { +export class QuaggansEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/quaggans' diff --git a/src/endpoints/quests.js b/src/endpoints/quests.ts similarity index 62% rename from src/endpoints/quests.js rename to src/endpoints/quests.ts index 3cd30749..ff0ab9e7 100644 --- a/src/endpoints/quests.js +++ b/src/endpoints/quests.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class QuestsEndpoint extends AbstractEndpoint { +export class QuestsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/quests' diff --git a/src/endpoints/races.js b/src/endpoints/races.ts similarity index 62% rename from src/endpoints/races.js rename to src/endpoints/races.ts index 69f52521..d02dbc54 100644 --- a/src/endpoints/races.js +++ b/src/endpoints/races.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class RacesEndpoint extends AbstractEndpoint { +export class RacesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/races' diff --git a/src/endpoints/raids.js b/src/endpoints/raids.ts similarity index 59% rename from src/endpoints/raids.js rename to src/endpoints/raids.ts index 22706ead..946f810a 100644 --- a/src/endpoints/raids.js +++ b/src/endpoints/raids.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class RaidsEndpoint extends AbstractEndpoint { +export class RaidsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/raids' diff --git a/src/endpoints/recipes.js b/src/endpoints/recipes.ts similarity index 73% rename from src/endpoints/recipes.js rename to src/endpoints/recipes.ts index aed36dac..2312ee15 100644 --- a/src/endpoints/recipes.js +++ b/src/endpoints/recipes.ts @@ -1,6 +1,8 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { ItemID } from '../types' -module.exports = class RecipesEndpoint extends AbstractEndpoint { + +export class RecipesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/recipes' @@ -22,11 +24,11 @@ class SearchEndpoint extends AbstractEndpoint { this.cacheTime = 24 * 60 * 60 } - input (id) { + input (id: ItemID) { return super.get(`?input=${id}`, true) } - output (id) { + output (id: ItemID) { return super.get(`?output=${id}`, true) } } diff --git a/src/endpoints/schemas/responses/account.ts b/src/endpoints/schemas/responses/account.ts new file mode 100644 index 00000000..59a5a2ae --- /dev/null +++ b/src/endpoints/schemas/responses/account.ts @@ -0,0 +1,58 @@ +import { ISO8601 } from "../../../types" + +/** + * - `None` – should probably never happen + * - `PlayForFree` – without any other flags, this identifies an account which has not yet purchased the game. (This flag does however also appear on accounts who have purchased the base game or any of the expansions) + * – `GuildWars2` – has purchased the base game + * - `HeartOfThorns` – has purchased Heart of Thorns, accounts that recieve Heart of Thorns by purchasing Path of Fire will not have this flag set. + * - `PathOfFire` – has purchased Path of Fire, this flag also implies that the account has access to Heart of Thorns. + * - `EndOfDragons` – has purchased End of Dragons + */ +type Access = 'None' | 'PlayForFree' | 'GuildWars2' | 'HeartOfThorns' | 'PathOfFire' | 'EndOfDragons' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/account} */ + export interface Account { + /** The unique persistent account GUID. */ + id: string + /** The age of the account in seconds. */ + age: number + /** The unique account name with numerical suffix. It is possible that the name change. Do not rely on the name, use id instead. */ + name: string + /** The id of the home world the account is assigned to. Can be resolved against /v2/worlds. */ + world: number + /** A list of guilds assigned to the given account. */ + guilds: Array + /** A list of guilds the account is leader of. Requires the additional guilds scope. */ + guild_leader: Array + /** An ISO-8601 standard timestamp of when the account was created. */ + created: string + /** A list of what content this account has access to. Possible values: */ + access: Access[] + /** True if the player has bought a commander tag. */ + commander: boolean + /** The account's personal fractal reward level. Requires the additional progression scope. */ + fractal_level: number + /** The daily AP the account has. Requires the additional progression scope. */ + daily_ap: number + /** The monthly AP the account has. Requires the additional progression scope. */ + monthly_ap: number + /** The account's personal wvw rank. Requires the additional progression scope. */ + wvw_rank: number + } +} + +export namespace Schema_2019_02_21 { + /** {@link https://wiki.guildwars2.com/API:2/account} */ + export interface Account extends Schema_1970_01_01.Account { + /** An ISO-8601 standard timestamp of when the account information last changed as perceived by the API. This field is only present when a Schema version of 2019-02-21T00:00:00Z or later is requested. */ + last_modified: ISO8601 + } +} + +export namespace Schema_2019_12_19 { + export interface Account extends Schema_2019_02_21.Account { + /** The amount of build storage slot an account has unlocked. Requires the additional builds scope. This field is only present when a Schema version of 2019-12-19T00:00:00.000Z or later is requested. */ + build_storage_slots: number + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/achievements.ts b/src/endpoints/schemas/responses/achievements.ts new file mode 100644 index 00000000..d278bab2 --- /dev/null +++ b/src/endpoints/schemas/responses/achievements.ts @@ -0,0 +1,101 @@ +export type Flag = 'PvE' | 'PvP' | 'WvW' | 'SpecialEvent' +export type Product = 'GuildWars2' | 'HeartOfThorns' | 'PathOfFire' | 'EndOfDragons' +export type Condition = 'HasAccess' | 'NoAccess' +export type LevelTuple = [number, number] +export type LevelObj = { min: number, max: number } +export type RequiredAccess = { product: Product, condition: Condition } + +/** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/daily} */ +interface BaseDaily { + id: number, + level: LevelObj, +} + +/** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/categories} */ +interface BaseCategory {} + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/account/achievements} */ + export interface Achievement { + id: number, + bits?: number, + current?: number, + max?: number, + done: boolean, + repeated?: number, + unlocked?: number + } + + + export interface Daily extends BaseDaily { + required_access: Product[] + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/daily/tomorrow} */ + export interface Dailies { + pve: Daily[], + wvw: Daily[], + fractals: Daily[], + special: Daily[] + } + + export interface Category extends BaseCategory { + id: number, + name: string, + description: string, + order: number, + icon: string, + achievements: number[], + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/groups} */ + export interface Group { + id: string, + name: string, + description: string, + order: number, + categories: number[] + } +} + + +export namespace Schema_2019_05_16 { + export interface Daily extends BaseDaily { + required_access?: RequiredAccess + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/daily/tomorrow} */ + export interface Dailies { + pve: Daily[], + wvw: Daily[], + fractals: Daily[], + special: Daily[] + } +} + + +export namespace Schema_2022_03_23 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/achievements/categories} */ + export interface Category extends BaseCategory { + achievements: [ + id: number, + name: string, + description: string, + order: number, + icon: string, + achievements: { + id: number, + required_access: RequiredAccess + flags: Flag[], + level: [number, number] + }, + tomorrow: { + id: number, + required_access: RequiredAccess, + flags: Flag[], + level: LevelTuple + } + ] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/backstory.ts b/src/endpoints/schemas/responses/backstory.ts new file mode 100644 index 00000000..780edf61 --- /dev/null +++ b/src/endpoints/schemas/responses/backstory.ts @@ -0,0 +1,30 @@ +import { Profession, Race } from "../../../types" + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/backstory} */ + export interface Backstory { + backstory: string[] + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/backstory/answers} */ + export interface Answer { + id: string, + title: string, + description: string, + journal: string, + question: number, + professions: Profession[], + races: Race[], + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/backstory/questions} */ + export interface Question { + id: number, + title: string, + description: string, + answer: number[], + order: number, + races: Race[], + professions: Profession[] + } +} diff --git a/src/endpoints/schemas/responses/build.ts b/src/endpoints/schemas/responses/build.ts new file mode 100644 index 00000000..b63f4bb7 --- /dev/null +++ b/src/endpoints/schemas/responses/build.ts @@ -0,0 +1,6 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/build} */ + export interface Build { + id: number + } +} diff --git a/src/endpoints/schemas/responses/cats.ts b/src/endpoints/schemas/responses/cats.ts new file mode 100644 index 00000000..44855f6f --- /dev/null +++ b/src/endpoints/schemas/responses/cats.ts @@ -0,0 +1,12 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/account/home/cats} */ + export interface Cat { + id: number, + hint: string + } +} + +export namespace Schema_2019_03_22 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/account/home/cats} */ + export type Cat = number +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/characters.ts b/src/endpoints/schemas/responses/characters.ts new file mode 100644 index 00000000..92ac3c25 --- /dev/null +++ b/src/endpoints/schemas/responses/characters.ts @@ -0,0 +1,338 @@ +// FIXME: https://wiki.guildwars2.com/wiki/API:2/characters heropoints, quests, and sab missing + +import { Race, Gender, Profession, ISO8601, Discipline, EquipmentSlot } from "../../../types" + +type WeaponAttribute = 'AgonyResistance' | 'BoonDuration' | 'ConditionDamage' | 'ConditionDuration' | 'CritDamage' | 'Healing' | 'Power' | 'Precision' | 'Toughness' | 'Vitality' +type Binding = 'Character' | 'Account' + +// BUILDTABS +interface BuildSpecialization { + /** The specialization id or null if none is selected. Resolvable against /v2/specializations. */ + id: number + /** Three trait ids or null in places where none is selected. Resolvable against /v2/traits. */ + traits: number[] +} + +interface BuildSkills { + /** The id of the heal skill or null if none is selected. */ + heal: number + /** Three utility skill ids or null in places where none is selected. */ + utilities: number[] + /** The id of the elite skill or null if none is selected. */ + elite: number +} + +interface BuildPets { + /** Containers the two pet ids the ranger has equipped for terrestrial combat. */ + terrestrial: [number, number] + /** Containers the two pet ids the ranger has equipped for aquaticcombat. */ + aquatic: [number, number] +} + +interface Build { + /** The name given to the build. */ + name: string + /** The characters profession. Resolvable against /v2/professions. */ + profession: string + /** Three objects providing information about the characters selected specializations. */ + specializations: [BuildSpecialization, BuildSpecialization, BuildSpecialization] + /** Contains information about the characters selected skills. All values may be resolved against /v2/skills. */ + skills: BuildSkills + /** Contains information about the characters selected underwater skills. The structure is the same as the one of skills above. */ + aquatic_skills: BuildSkills + /** Included for revenants only. Two legend ids or null in places where none is selected. Resolvable against /v2/legends. */ + legends?: [string | null, string | null] + /** Included for revenants only. The structure is the same as the one of legends above. */ + aquatic_legends?: [string | null, string | null] + /** Included for rangers only. Containers information about the characters selected pets. Resolvable against /v2/pets. */ + pets: BuildPets +} + +// EQUIPMENT + +interface EquipmentTabDetails { + /** The item id of the equipment piece. Resolvable against /v2/items. */ + id: number + /** In which slot the equipment piece is equiped. Possible values: */ + slot: string + /** The skin id of the skin transmuted onto the equipment piece. Resolvable against /v2/skins. */ + skin?: number + /** The item ids of the upgrade components sloted in the weapon. Resolvable against /v2/items. */ + upgrades?: number[] + /** The item ids of the infusions sloted in the weapon. Resolvable against /v2/items. */ + infusions?: number[] + /** The binding of the item. Possible values: */ + binding?: Binding + /** The name of the character to which the item is bound. */ + bound_to?: string + /** Either Equipped or Armory. */ + location: 'Equipped' | 'Armory' + /** Four dye ids representing the dyes used in the dye slots of the equipment piece or null if a dye slot is unavailable for a piece. Resolvable against /v2/colors. */ + dyes?: number[] + /** Contains detailed information on the weapon stats. */ + stats?: WeaponStats +} +interface ItemAttributes { + /** Shows the amount of power given */ + Power?: number + /** Shows the amount of Precision given */ + Precision?: number + /** Shows the amount of Toughness given */ + Toughness?: number + /** Shows the amount of Vitality given */ + Vitality?: number + /** Shows the amount of Condition Damage given */ + Damage?: number + /** Shows the amount of Condition Duration given */ + Duration?: number + /** Shows the amount of Healing Power given */ + Healing?: number + /** Shows the amount of Boon Duration given */ + BoonDuration?: number +} + +interface EquipmentPvP { + /** resolve id against v2/pvp/amulets. */ + amulet: number + /** resolve id against v2/items. */ + rune: number + /** resolve ids against v2/items. Will contain nulls for unequipped items. */ + sigils: number[] +} + +interface ItemStats { + /** The itemstat id, can be resolved against /v2/itemstats */ + id: number + /** Contains a summary of the stats on the item. */ + attributes: ItemAttributes +} + +interface WeaponStats { + /** The id of the wepons stats. Resolvable against /v2/itemstats. */ + id: number + /** Contains the weapon attributes in the form of key value pairs with the key being the attribute name and the value itself. */ + attributes: {[key in WeaponAttribute]?: number} +} + +// INVENTORY (also EQUIPMENT?) +interface Item { + /** The item id which can be resolved against /v2/items */ + id: number + /** Amount of item in the stack. Minium of 1, maximum of 250. */ + count: number + /** The number of charges on an item. */ + charges: number + /** returns an array of infusion item ids which can be resolved against /v2/items */ + infusions: Array + /** returns an array of upgrade component item ids which can be resolved against /v2/items */ + upgrades: Array + /** Skin id for the given equipment piece. Can be resolved against /v2/skins */ + skin: number + /** Contains information on the stats chosen if the item offers an option for stats/prefix. */ + stats: ItemStats + /** Array of selected dyes for the equipment piece. Values default to null if no dye is selected. Colors can be resolved against v2/colors */ + dyes: number[] + /** describes which kind of binding the item has. */ + binding: Binding + /** Name of the character the item is bound to. */ + bound_to: string +} + +interface Bag { + /** The bag's item id which can be resolved against /v2/items */ + id: number + /** The amount of slots available with this bag. */ + size: number + /** Contains one object structure per item, object is null if no item is in the given bag slot. */ + inventory: Array +} + +// SKILLS TRAITS TRAINING +interface SkillSet { + /** contains the skill id for the heal skill, resolvable against /v2/skills. */ + heal: number + /** each integer corresponds to a skill id for the equipped utilities, resolvable against /v2/skills. */ + utilities: number[] + /** contains the skill id for the elite skill, resolvable against /v2/skills. */ + elite: number + /** each string corresponds to a Revenant legend, resolvable against /v2/legends. */ + legends?: number[] +} + +interface Traits { + /** Specialization id, can be resolved against /v2/specializations. */ + id: number + /** returns ids for each selected trait, can be resolved against /v2/traits. */ + traits: number[] +} + +interface TrainingDetails { + /** Skill tree id, can be compared against the training section for each /v2/professions. */ + id: number + /** Shows how many hero points have been spent in this tree */ + spent: number + /** States whether or not the tree is fully trained. */ + done: boolean +} + +export namespace Schema_1970_01_01 { + // CORE STUFF + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/core} */ + export interface Core { + /** The character's name. */ + name: string + /** The character's race. Possible values: */ + race: Race + /** The character's gender. Possible values: */ + gender: Gender + /** The character's profession. Possible values: */ + profession: Profession + /** The character's level. */ + level: number + /** The guild ID of the character's currently represented guild. */ + guild?: string + /** The amount of seconds this character was played. */ + age: number + /** An ISO-8601 standard timestamp of when the account information last changed as perceived by the API. This field is only present when a Schema version of 2019-02-21T00:00:00Z or later is requested. */ + last_modified: ISO8601 + /** ISO 8601 representation of the character's creation time. */ + created: ISO8601 + /** The amount of times this character has been defeated. */ + deaths: number + /** The currently selected title for the character. References /v2/titles. */ + title?: number + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/crafting} */ + export interface Crafting { + /** The name of the discipline. Possible values: */ + discipline: Discipline + /** The current crafting level for the given discipline and character */ + rating: number + /** Describes if the given discipline is currently active or not on the character. */ + active: boolean + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/buildtabs} */ + export interface BuildTabs { + /** The "id" of this tab. (The position at which it resides.) */ + tab: number + /** Whether or not this is the tab selected on the character currently. */ + is_active: boolean + /** Contains detailed information about the build. */ + build: Build + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/buildtabs} */ + export interface Equipment { + /** The item id, resolvable against /v2/items */ + id: number + /** The equipment slot in which the item is slotted. This value is optional on schema 2019-12-19T00:00:00.000Z or later, will be missing if equipment is in an inactive tab. Possible values: */ + slot: EquipmentSlot + /** returns an array of infusion item ids which can be resolved against /v2/items */ + infusions?: Array + /** returns an array of upgrade component item ids which can be resolved against /v2/items */ + upgrades?: Array + /** Skin id for the given equipment piece. Can be resolved against /v2/skins */ + skin?: number + /** Contains information on the stats chosen if the item offers an option for stats/prefix. */ + stats: ItemStats + /** describes which kind of binding the item has. Possible values: */ + binding?: Binding + /** The amount of charges remaining on the item. */ + charges?: number + /** Name of the character the item is bound to. */ + bound_to?: string + /** Array of selected dyes for the equipment piece. Values default to null if no dye is selected. Colors can be resolved against v2/colors */ + dyes: number[] + } + + // FIXME: Whats this? + export interface Character { + /** An array containing an entry for each crafting discipline the character has unlocked */ + crafting: Array + /** An array containing an object for each equipment tab the character has. */ + equipment_tabs: Array + /** An array containing an entry for each piece of equipment currently on the selected character. */ + equipment: Array + } + + + + + export interface EquipmentTabs { + /** The "id" of this tab. (The position at which it resides.) */ + tab: number + /** The name given to the equipment combination. */ + name: string + /** Whether or not this is the tab selected on the character currently. */ + is_active: boolean + /** Contains an object for each equiped piece of equipment. */ + equipment: EquipmentTabDetails[] + /** Contains the following key-value pairs: */ + equipment_pvp: EquipmentPvP + } + + + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/inventory} */ + export interface Inventory { + /** Contains one object structure per bag in the character's inventory */ + bags: Array + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/characters/:id/recipes} */ + export interface Recipe { + recipes: number[] + } + + /** {@link https://wiki.guildwars2.com/API:2/characters/:id/skills} */ + export interface Skills { + /** contains the pve, pvp, and wvw objects for the current utilities equipped. */ + skills: { + /** contains the information on each slotted utility for PvE */ + pve: SkillSet + /** contains the information on each slotted utility for PvP */ + pvp: SkillSet + /** contains the information on each slotted utility for WvW */ + wvw: SkillSet + } + } + + /** {@link https://wiki.guildwars2.com/API:2/characters/:id/specializations} */ + export interface Specializations { + /** contains the pve, pvp, and wvw objects for the current specializations and traits equipped. */ + specializations: { + /** contains the information on each slotted specialization and trait for PvE */ + pve: Array + /** contains the information on each slotted specialization and trait for PvP */ + pvp: Array + /** contains the information on each slotted specialization and trait for WvW */ + wvw: Array + } + } + + /** {@link https://wiki.guildwars2.com/API:2/characters/:id/training} */ + export interface Training { + /** contains objects for each skill tree trained */ + training: Array + } +} + +export namespace Schema_2019_12_19 { + export interface Equipment extends Omit { + /** The unlock count of this item when location is LegendaryArmory. Available on schema 2019-12-19T00:00:00.000Z or later. */ + count: number + /** The equipment slot in which the item is slotted. This value is optional on schema 2019-12-19T00:00:00.000Z or later, will be missing if equipment is in an inactive tab. Possible values: */ + slot?: EquipmentSlot + /** describes where this item is stored. Available on schema 2019-12-19T00:00:00.000Z or later. Possible values: + * + * - "Equipped": equipped in the active tab. + * - "Armory": equipped in an inactive tabs. + * - "EquippedFromLegendaryArmor": if the item is stored in the account-wide legendary armory, but equipped in the active tab. + * - "LegendaryArmory": if the item is stored in the account-wide legendary armory, but equipped in an inactive tabs. + */ + location: 'Equipped' | 'Armory' | 'EquippedFromLegendaryArmory' | 'LegendaryArmory' + /** identifies which tabs this particular item is reused in. Available on schema 2019-12-19T00:00:00.000Z or later. */ + tabs: number[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/colors.ts b/src/endpoints/schemas/responses/colors.ts new file mode 100644 index 00000000..f53d92af --- /dev/null +++ b/src/endpoints/schemas/responses/colors.ts @@ -0,0 +1,29 @@ +export namespace Schema_1970_01_01 { + type RGB = [number, number, number] + type Hue = 'Gray' | 'Brown' | 'Red' | 'Orange' | 'Yellow' | 'Green' | 'Blue' | 'Purple' + type Material = 'Vibrant' | 'Leather' | 'Metal' + type Rarity = 'Start' | 'Common' | 'Uncommon' | 'Rare' | 'Purple' + type Category = Hue | Material | Rarity + + interface Details { + brightness: number, + contrast: number, + hue: number, + saturation: number, + lightness: number, + rgb: RGB + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/colors} */ + export interface Color { + id: number, + name: string, + base_rgb: RGB, + cloth: Details, + leather: Details, + metal: Details, + fur?: Details, + item?: number + categories: Category[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/commerce.ts b/src/endpoints/schemas/responses/commerce.ts new file mode 100644 index 00000000..04ee72e2 --- /dev/null +++ b/src/endpoints/schemas/responses/commerce.ts @@ -0,0 +1,75 @@ +import { ISO8601 } from "../../../types" + +interface DeliveryItem { + /** The item's id, resolvable against v2/items. */ + id: number + /** The amount of this item ready for pickup. */ + count: number +} + +interface ListingDetails { + /** The number of individual listings this object refers to (e.g. two players selling at the same price will end up in the same listing) */ + listings: number + /** The sell offer or buy order price in coins. */ + unit_price: number + /** The amount of items being sold/bought in this listing. */ + quantity: number +} + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/commerce/delivery} */ + export interface Delivery { + /** The amount of coins ready for pickup. */ + coins: number + items: DeliveryItem[] + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/commerce/exchange} */ + export interface Exchange { + /** The number of coins you required for a single gem. */ + coins_per_gem: number + /** The number of gems you get for the specified quantity of coins. */ + quantity: number + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/commerce/listings} */ + export interface Listing { + /** The item id. **/ + id: number + /** A list of all buy listings, descending from highest buy order. */ + buys: ListingDetails[] + /** A list of all sell listings, ascending from lowest sell offer. */ + sells: ListingDetails[] + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/commerce/prices} */ + export interface Price { + /** The item id. */ + id: number + /** Indicates whether or not a free to play account can purchase or sell this item on the trading post. */ + whitelisted: boolean + /** Buy information. */ + buys: ListingDetails + /** Sell information. */ + sells: ListingDetails + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/commerce/transactions} */ + interface Transaction { + /** Id of the transaction. */ + id: number + /** The item id. */ + item_id: number + /** The price in coins. */ + price: number + /** The quantity of the item. */ + quantity: number + /** The date of creation, using ISO-8601 standard. */ + created: ISO8601 + /** The date of purchase, using ISO-8601 standard. Not shown in current second-level endpoint. */ + purchased: ISO8601 + } + + export type Transactions = Transaction[] +} diff --git a/src/endpoints/schemas/responses/continents.ts b/src/endpoints/schemas/responses/continents.ts new file mode 100644 index 00000000..a4d57fbb --- /dev/null +++ b/src/endpoints/schemas/responses/continents.ts @@ -0,0 +1,95 @@ +export namespace Schema_1970_01_01 { + type Dim = [number, number] + type Coordinate = [number, number] + type Rectangle = [Dim, Dim] + + export interface Continent { + id: number, + name: 'Tyria' | 'Mists', + continent_dims: Dim, + min_zoom: number, + max_zoom: number, + floors: number[] + } + + export interface Floor { + texture_dims: Dim, + clamped_view: Rectangle, + regions: { [key: number]: Region } + } + + export interface Region { + name: string, + label_coord: Coordinate, + continent_rect: Rectangle, + maps: { [key: number]: MapInfo } + } + + export interface MapInfo { + name: string, + min_level: number, + max_level: number, + default_floor: number, + label_coord: Coordinate, + map_rect: Rectangle, + continent_rect: Rectangle, + points_of_interest: PointOfInterest[], + tasks: Task[], + skill_challenges: SkillChallenge[], + sectors: Sector[], + adventures: Adventure[], + mastery_points: MasteryPoint[] + } + + export interface Task { + objective: string, + level: number, + coord: Coordinate, + bounds: Coordinate[], + id: number, + chat_link: string + } + + export interface SkillChallenge { + coord: Coordinate, + id: string + } + + export interface Sector { + name: string, + level: number, + coord: Coordinate, + bounds: Coordinate[], + chat_link: String, + id: number + } + + export interface Adventure { + coord: Coordinate, + id: string, + name: string, + description: string + } + + export interface MasteryPoint { + coord: Coordinate, + id: number, + region: Region, + + } + + export interface PoI { + name: string, + type: T, + floor: number, + coord: Dim, + id: number, + chat_link: string + } + + export interface Landmark extends PoI<'landmark'> {} + export interface Waypoint extends PoI<'waypoint'> {} + export interface Vista extends PoI<'vista'> {} + export interface Unlock extends PoI<'unlock'> { chat_link: string } + export type PointOfInterest = Landmark | Waypoint | Vista | Unlock +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/currencies.ts b/src/endpoints/schemas/responses/currencies.ts new file mode 100644 index 00000000..164955e5 --- /dev/null +++ b/src/endpoints/schemas/responses/currencies.ts @@ -0,0 +1,15 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/currencies} */ + export interface Currency { + /** The currency's ID. **/ + id: number + /** The currency's name. **/ + name: string + /** A description of the currency. */ + description: string + /** A URL to an icon for the currency. */ + icon: string + /** A number that can be used to sort the list of currencies when ordered from least to greatest. */ + order: number + } +} diff --git a/src/endpoints/schemas/responses/dailycrafting.ts b/src/endpoints/schemas/responses/dailycrafting.ts new file mode 100644 index 00000000..b606288d --- /dev/null +++ b/src/endpoints/schemas/responses/dailycrafting.ts @@ -0,0 +1,5 @@ +export namespace Schema_1970_01_01 { + type DailyCraftingItem = 'lump_of_mithrilium' | 'spool_of_silk_weaving_thread' | 'spool_of_thick_elonian_cord' + + export type DailyCrafting = DailyCraftingItem[] +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/dungeons.ts b/src/endpoints/schemas/responses/dungeons.ts new file mode 100644 index 00000000..34cfba84 --- /dev/null +++ b/src/endpoints/schemas/responses/dungeons.ts @@ -0,0 +1,10 @@ +export namespace Schema_1970_01_01 { + type Dungeons = 'ascalonian_catacombs' | 'caudecus_manor' | 'twilight_arbor' | 'sorrows_embrace' | 'citadel_of_flame' | 'honor_of_the_waves' | 'crucible_of_eternity' | 'ruined_city_of_arah' + export interface Dungeon { + id: Dungeons, + paths: { + id: string, + type: 'Story' | 'Explorable' + } + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/emblems.ts b/src/endpoints/schemas/responses/emblems.ts new file mode 100644 index 00000000..11215a67 --- /dev/null +++ b/src/endpoints/schemas/responses/emblems.ts @@ -0,0 +1,11 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/emblem} */ + interface Layer { + /** The ID of the emblem part. */ + id: number, + /** An array of URLs to images that make up the various parts of the emblem. */ + layers: string[] + } + + export type Emblem = Layer[] +} diff --git a/src/endpoints/schemas/responses/events.ts b/src/endpoints/schemas/responses/events.ts new file mode 100644 index 00000000..4a25f590 --- /dev/null +++ b/src/endpoints/schemas/responses/events.ts @@ -0,0 +1,49 @@ +type EventFlag = 'group_event' | 'map_wide' | 'meta_event' | 'dungeon_event' +type LocationType = 'sphere' | 'cylinder' | 'poly' +type Coordinate3D = [number, number, number] // FIXME: reuse? +type Coordinate2D = [number, number] + +interface BaseLocation { + type: T + center: Coordinate3D +} + +interface SphereLocation extends BaseLocation<'sphere'> { + radius: number + rotation: number +} + +interface CylinderLocation extends BaseLocation<'cylinder'> { + height: number + radius: number + rotation: number +} + +interface PolyLocation extends BaseLocation<'poly'> { + z_range: Coordinate2D + points: Array +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:1/event_details} */ + export interface EventDetails { + /** The name of the event. */ + name: string + /** The event level. */ + level: number + /** The map where the event takes place. */ + map_id: number + /** A list of additional flags. Possible flags are: */ + flags: Array + /** The location of the event. */ + location: SphereLocation | CylinderLocation | PolyLocation + /** The type of the event location, can be sphere, cylinder or poly. */ + type: string + /** The icon for the event. */ + icon?: object + /** The file id to be used with the render service. */ + file_id: number + /** The file signature to be used with the render service. */ + signature: string + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/files.ts b/src/endpoints/schemas/responses/files.ts new file mode 100644 index 00000000..bae99383 --- /dev/null +++ b/src/endpoints/schemas/responses/files.ts @@ -0,0 +1,11 @@ +import { URL } from "../../../types" + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/files} */ + export interface File { + /** The file identifier. */ + id: string + /** The URL to the image. */ + icon: URL + } +} diff --git a/src/endpoints/schemas/responses/finishers.ts b/src/endpoints/schemas/responses/finishers.ts new file mode 100644 index 00000000..815e03c5 --- /dev/null +++ b/src/endpoints/schemas/responses/finishers.ts @@ -0,0 +1,17 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/finishers} */ + export interface Finisher { + /** (default/null value: 0) - The id of the finisher. */ + id: number + /** (default/null value: "") - A description explaining how to acquire the finisher. */ + unlock_details: string + /** (optional) - An array of item ids used to unlock the finisher. Can be resolved against v2/items */ + unlock_items?: number[] + /** (default/null value: 0) - The order in which the finisher appears in a list. */ + order: number + /** (default/null value: "") - The icon uri for the finisher. */ + icon: string + /** (default/null value: "") - The name of the finisher as it appears in-game. */ + name: string + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/gliders.ts b/src/endpoints/schemas/responses/gliders.ts new file mode 100644 index 00000000..041e49ec --- /dev/null +++ b/src/endpoints/schemas/responses/gliders.ts @@ -0,0 +1,19 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/gliders} */ + export interface Glider { + /** The id of the glider */ + id: number, + /** An array of item ids used to unlock the glider. Can be resolved against v2/items */ + unlock_items?: number[], + /** The order in which the glider appears in a list. This value is not unique. */ + order: number, + /** The icon uri for the glider. */ + icon: string, + /** The name of the glider as it appears in-game. */ + name: string, + /** The in-game glider description. */ + description: string, + /** List of dye ids. Can be resolved against v2/colors. */ + default_dies: number[] + } +} diff --git a/src/endpoints/schemas/responses/guilds.ts b/src/endpoints/schemas/responses/guilds.ts new file mode 100644 index 00000000..b4bc822d --- /dev/null +++ b/src/endpoints/schemas/responses/guilds.ts @@ -0,0 +1,341 @@ +// FIXME: probably break this up into multiple files + +import { ISO8601 } from "../../../types" + +type GuildFlag = 'FlipBackgroundHorizontal' | 'FlipBackgroundVertical' +type StashOperation = 'deposit' | 'withdraw' | 'move' +type UpgradeAction = 'queued' | 'cancelled' | 'completed' | 'sped_up' +// cba, FIXME? +type Permission = string + + +// EMBLEM STUFF +interface EmblemLayer { + /** The layer id, to be resolved against /v2/emblem/backgrounds or /v2/emblem/foregrounds respectively */ + id: number + /** An array of numbers containing the id of each color used. */ + colors: number[] +} + +interface Emblem { + /** An object containing information of the background of the guild emblem. */ + background: EmblemLayer + /** An object containing information of the foreground of the guild emblem. */ + foreground: EmblemLayer + /** An array containing the manipulations applied to the logo. */ + flags: GuildFlag[] +} + +// LOG STUFF +/** {@link https://wiki.guildwars2.com/API:2/guild/:id/log} */ +export interface BaseLog { + /** An ID to uniquely identify the log entry within the scope of the guild. Not globally unique. */ + id: number + /** ISO-8601 standard timestamp for when the log entry was created. */ + time: ISO8601 + /** The account name of the guild member who generated this log entry. */ + user?: string + /** The type of log entry. Additional fields are given depending on the type. */ + type: T +} + +/** user has been invited to the guild. */ +interface InvitedLogDetails { + /** Account name of the guild member which invited the player. */ + invited_by: string +} + +/** user has been kicked from the guild. */ +interface KickLogDetails { + /** Account name of the guild member which kicked the player. */ + kicked_by: string +} + +/** Rank for user has been changed. */ +interface RankChangeLogDetails { + /** Account name of the guild member which changed the player rank. */ + changed_by: string + /** Old rank name. */ + old_rank: string + /** New rank name. */ + new_rank: string +} + +/** A guild member has deposited an item into the guild's treasury. */ +interface TreasuryLogDetails { + /** The item ID that was deposited into the treasury. */ + item_id: number + /** How many of the specified item was deposited. */ + count: number +} + +/** - A guild member has deposited/withdrawn an item into the guild stash. */ +interface StashLogDetails { + operation: StashOperation + /** The item ID that was deposited into the treasury. */ + item_id: number + /** How many of the specified item was deposited. */ + count: number + /** How many coins (in copper) were deposited. */ + coins: number +} + +/** A guild member has changed the guild's MOTD. */ +interface MOTDLogDetails { + /** The new MOTD. */ + motd: string +} + +/** A guild member has interacted with a guild upgrade. Additional fields include: */ +interface UpgradeLogDetails { + /** The type of interaction had. */ + action: UpgradeAction + /** Having this action will also generate a new count field indicating how many upgrades were added. */ + completed: any + /** The upgrade ID which was completed. */ + upgrade_id: number + /** May be added if the upgrade was created through a scribe station by a scribe. */ + recipe_id: number +} + +type JoinedLog = BaseLog<'joined'> +type InvitedLog = BaseLog<'invited'> & InvitedLogDetails +type KickLog = BaseLog<'kick'> & KickLogDetails +type RankChangeLog = BaseLog<'rank_change'> & RankChangeLogDetails +type TreasuryLog = BaseLog<'treasury'> & TreasuryLogDetails +type StashLog = BaseLog<'stash'> & StashLogDetails +type MOTDLog = BaseLog<'motd'> & MOTDLogDetails +type UpgradeLog = BaseLog<'upgrade'> & UpgradeLogDetails + +// STASH STUFF +interface InventoryEntry { + /** ID of the item in this slot. */ + id: number + /** Amount of items in this slot. */ + count: number +} + +// TEAM STUFF +interface TeamMember { + /** should match up with /v2/guild/:id/members. */ + name: string + /** "Captain" or "Member". */ + role: 'Captain' | 'Member' +} + +interface Season { + id: string + wins: number + losses: number + rating: number +} + +// TREASURY STUFF +interface NeededBy { + /** The ID of the upgrade needing this item. */ + upgrade_id: number + /** The total amount the upgrade needs for this item. */ + count: number +} + +// UPGRADE STUFF +interface UpgradeCost { + /** The type of cost. */ + type: 'Item' | 'Collectible' | 'Currency' | 'Coins' + /** The name of the cost. */ + name: string + /** The amount needed. */ + count: number + /** The id of the item, if applicable, resolvable against v2/items. */ + item_id?: number +} + + +/** {@link https://wiki.guildwars2.com/API:2/guild/upgrades} */ +interface BaseUpgrade { + /** The upgrade id. */ + id: number + /** The name of the upgrade. */ + name: string + /** The guild upgrade description. */ + description: string + /** The upgrade type. Some upgrade types will add additional fields to describe them further. Possible values: + * + * - "AccumulatingCurrency": Used for mine capacity upgrades. + * - "BankBag": Used for guild bank upgrades. + * - "Boost": Used for permanent guild buffs such as waypoint cost reduction. + * - "Claimable": Used for guild WvW tactics. + * - "Consumable": Used for banners and guild siege. + * - "Decoration": Used for decorations that must be crafted by a Scribe. + * - "GuildHall": Used for claiming a Guild Hall. + * - "Hub": Used for the Guild Initiative office unlock. + * - "Queue": Used for Workshop Restoration 1. + * - "Unlock": Used for permanent unlocks, such as merchants and arena decorations. + */ + type: T + /** A URL pointing to an icon for the upgrade. */ + icon: string + /** The time it takes to build the upgrade. */ + build_time: number + /** The prerequisite level the guild must be at to build the upgrade. */ + required_level: number + /** The amount of guild experience that will be awarded upon building the upgrade. */ + experience: number + /** An array of upgrade IDs that must be completed before this can be built. */ + prerequisites: Array + /** An array of objects describing the upgrade's cost. Each object in the array has the following properties: */ + costs: Array + +} + +interface BankBagUpgradeDetails { + /** The maximum item slots of the guild bank tab. */ + bag_max_items: number + /** The maximum amount of coins that can be stored in the bank tab. */ + bag_max_coins: number +} + +type BankBagUpgrade = BaseUpgrade<'BankBag'> & BankBagUpgradeDetails +type AccumulatingCurrencyUpgrade = BaseUpgrade<'AccumulatingCurrency'> +type BoostUpgrade = BaseUpgrade<'Boost'> +type ClaimableUpgrade = BaseUpgrade<'Claimable'> +type ConsumableUpgrade = BaseUpgrade<'Consumable'> +type DecorationUpgrade = BaseUpgrade<'Decoration'> +type GuildHallUpgrade = BaseUpgrade<'GuildHall'> +type HubUpgrade = BaseUpgrade<'Hub'> +type QueueUpgrade = BaseUpgrade<'Queue'> +type UnlockUpgrade = BaseUpgrade<'Unlock'> + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/guild/:id} */ + export interface Guild { + /** The unique guild id. */ + id: string + /** The guild's name. */ + name: string + /** The 2 to 4 letter guild tag representing the guild. */ + tag: string + /** The guild emblem. */ + emblem: Emblem + /** The current level of the guild. */ + level: number + /** The message of the day written out in a single string. */ + motd: string + /** The guild's current influence. */ + influence: number + /** The guild's current aetherium level. */ + aetherium: string + /** The guild's current level of favor. */ + favor: number + /** The number of People currently in the Guild. */ + member_count: number + /** The maximum number of People that can be in the Guild. (see Guild#Membership) */ + member_capacity: number + } + + /** {@link https://wiki.guildwars2.com/wiki/API:2/guild/:id/log} */ + export type Log = JoinedLog | InvitedLog | KickLog | RankChangeLog | TreasuryLog | StashLog | MOTDLog | UpgradeLog + + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/members} */ + export interface Member { + /** The account name of the member. */ + name: string + /** The guild rank of the member. (See /v2/guild/:id/ranks.) */ + rank: string + /** The time and date the member joined the guild (ISO-8601 standard). May also be null -- the join date was not tracked before around March 19th, 2013. */ + joined: ISO8601 + } + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/ranks} */ + export interface Rank { + /** The ID and name of the rank. */ + id: string + /** A number given to each rank to specify how they should be sorted, lowest being the first and highest being the last. */ + order: number + /** An array of permission ids from /v2/guild/permissions that have been given to this rank. */ + permissions: Array + /** A URL pointing to the image currently assigned to this rank. */ + icon: string + } + + + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/stash} */ + export interface Stash { + /** ID of the guild upgrade that granted access to this section of the guild vault. */ + upgrade_id: number + /** The number of slots in this section of the guild vault. */ + size: number + /** The number of coins deposited in this section of the guild vault. */ + coins: number + /** The description set for this section of the guild's vault. */ + note: string + /** An array of objects describing the items in the guild stash of exactly size length. Each object either contains the following properties if an item is present, or is null if the slot is empty: */ + inventory: Array + } + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/storage} */ + export interface Storage { + /** ID of the guild consumable. */ + id: number + /** Amount of the consumable in storage. */ + count: number + } + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/teams} */ + export interface Team { + /** the team ID, only unique within a guild. */ + id: number + members: TeamMember[] + /** matches the format of /v2/pvp/stats. */ + aggregate: object // FIXME: infer + /** matches the format of /v2/pvp/stats. */ + ladders: object // FIXME: infer + /** matches the format of /v2/pvp/games with profession omitted. */ + games: object[] // FIXME: infer + /** Amount of items in this slot. */ + seasons: Season[] + } + + + /** {@link https://wiki.guildwars2.com/API:2/guild/:id/treasury} */ + export interface Treasury { + /** The item's ID. */ + item_id: number + /** How many of the item are currently in the treasury. */ + count: number + /** An array of objects describing which currently in-progress upgrades are needing this item. Each object has the following properties: */ + needed_by: Array + + } + + // FIXME: do we need the https://wiki.guildwars2.com/wiki/API:2/guild/:id/upgrades one? + /** {@link https://wiki.guildwars2.com/wiki/API:2/guild/upgrades} */ + export type Upgrade = BankBagUpgrade + | AccumulatingCurrencyUpgrade + | BoostUpgrade + | ClaimableUpgrade + | ConsumableUpgrade + | DecorationUpgrade + | GuildHallUpgrade + | HubUpgrade + | QueueUpgrade + | UnlockUpgrade + + /** {@link https://wiki.guildwars2.com/API:2/guild/permissions} */ + export interface Permission { + /** The permission id. */ + id: string + /** The name of the permission. */ + name: string + /** The description of the permission. */ + description: string + } + + /** {@link https://wiki.guildwars2.com/API:2/guild/search} */ + export type Search = string[] + + +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/items.ts b/src/endpoints/schemas/responses/items.ts new file mode 100644 index 00000000..7be45662 --- /dev/null +++ b/src/endpoints/schemas/responses/items.ts @@ -0,0 +1,340 @@ +import { ArmorSlot, Attribute, DamageType, Profession, Weapon as WeaponType, WeightClass, Trinket as TrinketType } from "../../../types" +import { Race } from "../../../types" +import { Rarity } from "../../../types" + +/** + * Armor - Armor + * Back - Back item + * Bag - Bags + * Consumable - Consumables + * Container - Containers + * CraftingMaterial - Crafting materials + * Gathering - Gathering tools, baits and lures + * Gizmo - Gizmos + * JadeTechModule - Sensory Array and Service Chip modules + * MiniPet - Miniatures + * PowerCore - Power Cores + * Tool - Salvage kits + * Trait - Trait guides + * Trinket - Trinkets + * Trophy - Trophies + * UpgradeComponent - Upgrade components + * Weapon - Weapons + */ +type ItemType = "Armor" | "Back" | "Bag" | "Consumable" | "Container" | "CraftingMaterial" | "Gathering" | "Gizmo" | "JadeTechModule" | "MiniPet" | "PowerCore" | "Tool" | "Trait" | "Trinket" | "Trophy" | "UpgradeComponent" | "Weapon" + +/** + * AccountBindOnUse - Account bound on use + * AccountBound - Account bound on acquire + * Attuned - If the item is attuned + * BulkConsume - If the item can be bulk consumed + * DeleteWarning - If the item will prompt the player with a warning when deleting + * HideSuffix - Hide the suffix of the upgrade component + * Infused - If the item is infused + * NoMysticForge - Not usable in the Mystic Forge + * NoSalvage - Not salvageable + * NoSell - Not sellable + * NotUpgradeable - Not upgradeable + * NoUnderwater - Not available underwater + * SoulbindOnAcquire - Soulbound on acquire + * SoulBindOnUse - Soulbound on use + * Tonic - If the item is a tonic + * Unique - Unique + */ +type ItemFlag = "AccountBindOnUse" | "AccountBound" | "Attuned" | "BulkConsume" | "DeleteWarning" | "HideSuffix" | "Infused" | "NoMysticForge" | "NoSalvage" | "NoSell" | "NotUpgradeable" | "NoUnderwater" | "SoulbindOnAcquire" | "SoulBindOnUse" | "Tonic" | "Unique" + + +/** + * Activity - Usable in activities + * Dungeon - Usable in dungeons + * Pve - Usable in general PvE + * Pvp - Usable in PvP + * PvpLobby - Usable in the Heart of the Mists + * Wvw - Usable in World vs. World + */ +type GameType = "Activity" | "Dungeon" | "Pve" | "Pvp" | "PvpLobby" | "Wvw" + + +/** + * AppearanceChange - For Total Makeover Kits, Self-Style Hair Kits, and Name Change Contracts + * Booze - Alcohol consumables + * ContractNpc - For Trading Post Express, Merchant Express, Golem Banker, Banker Golem (2 weeks) + * Currency - Some currencies + * Food - Food consumables + * Generic - Various consumables + * Halloween - Some boosters + * Immediate - Consumables granting immediate effect (most boosters, Pacified Magical Storm). Also used for currency items that are consumed immediately upon receipt. + * MountRandomUnlock - For Mount licenses + * RandomUnlock - For Guaranteed (Armor, Wardrobe, Weapon; Blue-Green Dye, Purple-Gray Dye, Red-Brown Dye, Yellow-Orange Dye) Unlocks + * Transmutation - Skin consumables + * Unlock - Unlock consumables + * UpgradeRemoval - For Upgrade Extractor + * Utility - Utility items (Potions etc.) + * TeleportToFriend - Used for Teleport to Friend + */ +type ConsumableType = "AppearanceChange" | "Booze" | "ContractNpc" | "Currency" | "Food" | "Generic" | "Halloween" | "Immediate" | "MountRandomUnlock" | "RandomUnlock" | "Transmutation" | "Unlock" | "UpgradeRemoval" | "Utility" | "TeleportToFriend" + + +/** + * BagSlot - For Bag Slot Expansion + * BankTab - For Bank Tab Expansion + * Champion - For Mist Champions + * CollectibleCapacity - For Storage Expander + * Content - Finishers and Collection unlocks, and Commander's Compendium + * CraftingRecipe - Crafting recipes + * Dye - Dyes + * GliderSkin - For Gliders + * Minipet - For Miniatures + * Ms - For Mount Skins + * Outfit - For Outfits + * SharedSlot - For Shared Inventory Slots + */ +type UnlockType = "BagSlot" | "BankTab" | "Champion" | "CollectibleCapacity" | "Content" | "CraftingRecipe" | "Dye" | "GliderSkin" | "Minipet" | "Ms" | "Outfit" | "SharedSlot" + + +/** + * GiftBox - For some presents and most dye kits + * Immediate - For containers without a UI (e.g. Pile of Silky Sand, Black Lion Arsenal—Axe, Divine Passage, Iboga Petals) + * OpenUI - For containers that have their own UI when opening (Black Lion Chest) + */ +type ContainerType = "GiftBox" | "Immediate" | "OpenUI" + + +/** + * Foraging - For harvesting sickles + * Logging - For logging axes + * Mining - For mining picks + * Bait - For baits + * Lure - For lures + */ +type GatheringType = "Foraging" | "Logging" | "Mining" | "Bait" | "Lure" + + +/** + * ContainerKey - For Black Lion Chest Keys. + * RentableContractNpc - For time-limited NPC services (e.g. Golem Banker, Personal Merchant Express) + * UnlimitedConsumable - For Permanent Self-Style Hair Kit + */ +type GizmoType = "ContainerKey" | "RentableContractNpc" | "UnlimitedConsumable" + + +/** + * Default - Infusions and Jewels (and historical PvP runes/sigils) + * Gem - Universal upgrades (Gemstones, Doubloons, and Marks/Crests/etc.) + * Rune - Rune + * Sigil - Sigil + */ +type UpgradeComponentType = "Default" | "Gem" | "Rune" | "Sigil" + +interface InfixUpgrade { + /** The itemstat id that can be resolved against /v2/itemstats. The usual whitelist restrictions apply and not all itemstats may be visible */ + id: number + attributes: { + attribute: Attribute + modifier: number + }[], + /** Object containing an additional effect. This is used for Boon Duration, Condition Duration, or additional attribute bonuses for ascended trinkets or back items. */ + buff?: { + /** The skill id of the effect. */ + skill_id: number + /** The effect's description. */ + description?: string + } +} + +/** + * Enrichment - Item has an enrichment slot. + * Infusion - Item has an infusion slot. + */ +type InfusionType = 'Enrichment' | 'Infusion' + +interface InfusionSlot { + /** Infusion slot type of infusion upgrades. The array contains a maximum of one value. */ + flags: InfusionType[] + /** The infusion upgrade already in the armor piece. Only used for +5 Agony Infusions (id 49428) */ + item_id?: number +} + +/** {@link https://wiki.guildwars2.com/API:2/items} */ +export interface Item { + /** The item id. */ + id: number + /** The chat link. */ + chat_link: string + /** The item name. */ + name: string + /** The full icon URL. */ + icon?: string + /** The item description. */ + description?: string + /** The item type. */ + type: T + /** The item rarity. */ + rarity: Rarity + /** The required level. */ + level: number + /** The value in coins when selling to a vendor. (Can be non-zero even when the item has the NoSell flag.) */ + vendor_value: number + /** The default skin id. */ + default_skin?: number + /** Flags applying to the item. */ + flags: ItemFlag[] + /** The game types in which the item is usable. At least one game type is specified. */ + game_types: GameType[] + /** Restrictions applied to the item. */ + restrictions: (Race | Profession)[] + /** Lists what items this item can be upgraded into, and the method of upgrading. Each object in the array has the following attributes: */ + upgrades_into?: Array + /** Describes the method of upgrading. */ + upgrade: string + /** The item ID that results from performing the upgrade. */ + item_id: number + /** Lists what items this item can be upgraded from, and the method of upgrading. See upgrades_into for format. */ + upgrades_from?: Array + /** Additional item details if applicable, depending on the item type (see below). */ + details?: object +} + + +export namespace Schema_1970_01_01 { + + export interface Armor extends Item { + /** The weight class of the armor piece. */ + weight_class: WeightClass + /** The defense value of the armor piece. */ + defense: number + /** Infusion slots of the armor piece (see below). */ + infusion_slots: InfusionSlot[] + /** The (x) value to be combined with the (m, gradient) multiplier and (c, offset) value to calculate the value of an attribute using API:2/itemstats. */ + attribute_adjustment: number + /** The infix upgrade object (see below). */ + infix_upgrade?: InfixUpgrade + /** The suffix item id. This is usually a rune. */ + suffix_item_id?: number + /** The secondary suffix item id. Equals to an empty string if there is no secondary suffix item. */ + secondary_suffix_item_id: string + /** A list of selectable stat IDs which are visible in API:2/itemstats */ + stat_choices?: Array + } + + export interface BackItem extends Item<'Back'> { + /** Infusion slots of the back item (see below). */ + infusion_slots: InfusionSlot[] + /** The (x) value to be combined with the (m, gradient) multiplier and (c, offset) value to calculate the value of an attribute using API:2/itemstats. */ + attribute_adjustment: number + /** The infix upgrade object (see below). */ + infix_upgrade?: InfixUpgrade + /** The suffix item id. This is usually a jewel. */ + suffix_item_id?: number + /** The secondary suffix item id. Equals to an empty string if there is no secondary suffix item. */ + secondary_suffix_item_id: string + /** A list of selectable stat IDs which are visible in API:2/itemstats */ + stat_choices?: Array + } + + export interface Bag extends Item<'Bag'> { + /** The number of bag slots. */ + size: number + /** Whether the bag is invisible/safe, and contained items won't show up at merchants etc. */ + no_sell_or_sort: boolean + } + + export interface Consumable extends Omit, 'name'> { + /** Effect description for consumables applying an effect. */ + description?: string + /** Effect duration in milliseconds. */ + duration_ms?: number + /** Unlock type for unlock consumables. */ + unlock_type?: UnlockType + /** The dye id for dye unlocks. */ + color_id?: number + /** The recipe id for recipe unlocks. */ + recipe_id?: number + /** Additional recipe ids for recipe unlocks. */ + extra_recipe_ids?: Array + /** The guild upgrade id for the item; resolvable against API:2/guild/upgrades. */ + guild_upgrade_id?: number + /** The number of stacks of the effect applied by this item. */ + apply_count?: number + /** The effect type name of the consumable. */ + name?: string + /** The icon of the effect. */ + icon?: string + /** A list of skin ids which this item unlocks; resolvable against API:2/skins. */ + skins?: Array + } + + export interface Container extends Item {} + + export interface Gathering extends Item {} + + export interface Gizmo extends Item { + /** The id for the Guild Decoration which will be deposited into the Guild storage uppon consumption of the Item; resolvable against API:2/guild/upgrades. */ + guild_upgrade_id? + } + + export interface Miniature extends Item<'MiniPet'> { + /** The miniature it unlocks and can be resolved against /v2/minis */ + minipet_id: number + } + + export interface SalvageKit extends Item<'Salvage'> { + /** Number of charges. */ + charges: number + } + + export interface Trinket extends Item { + /** Infusion slots of the trinket (see below). */ + infusion_slots: InfusionSlot[] + /** The (x) value to be combined with the (m, gradient) multiplier and (c, offset) value to calculate the value of an attribute using API:2/itemstats. */ + attribute_adjustment: number + /** The infix upgrade object (see below). */ + infix_upgrade?: InfixUpgrade + /** The suffix item id. This is usually a jewel or gem. */ + suffix_item_id?: number + /** The secondary suffix item id. Equals to an empty string if there is no secondary suffix item. */ + secondary_suffix_item_id: string + /** A list of selectable stat IDs which are visible in API:2/itemstats */ + stat_choices?: Array + } + + export interface UpgradeComponent extends Omit, 'flags'> { + /** The items that can be upgraded with the upgrade component. */ + flags: WeaponType | 'HeavyArmor' | 'MediumArmor' |'LightArmor' | 'Trinket' + /** Applicable infusion slot for infusion upgrades. */ + infusion_upgrade_flags: InfusionType + /** Enrichments */ + Enrichment: any + /** Infusions */ + Infusion: any + /** The suffix appended to the item name when the component is applied. */ + suffix: string + /** The infix upgrade object (see below). */ + infix_upgrade: InfixUpgrade + /** The bonuses from runes. */ + bonuses?: Array + } + + export interface Weapon extends Item { + /** The damage type. */ + damage_type: DamageType + /** Minimum weapon strength. */ + min_power: number + /** Maximum weapon strength. */ + max_power: number + /** The defense value of the weapon (for shields). */ + defense: number + /** Infusion slots of the weapon (see below). */ + infusion_slots: InfusionSlot[] + /** The (x) value to be combined with the (m, gradient) multiplier and (c, offset) value to calculate the value of an attribute using API:2/itemstats. */ + attribute_adjustment: number + /** The infix upgrade object (see below). */ + infix_upgrade?: object + /** The suffix item id. This is usually a sigil. */ + suffix_item_id?: number + /** The secondary suffix item id. Equals to an empty string if there is no secondary suffix item. */ + secondary_suffix_item_id: string + /** A list of selectable stats IDs which are visible in API:2/itemstats */ + stat_choices?: Array + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/itemstats.ts b/src/endpoints/schemas/responses/itemstats.ts new file mode 100644 index 00000000..93e0cdff --- /dev/null +++ b/src/endpoints/schemas/responses/itemstats.ts @@ -0,0 +1,22 @@ +import { Attribute, Race as R, URL } from '../../../types' + +interface AttributeModifier { + /** The name of the attribute, may be one of the following: */ + attribute: Attribute + /** The multiplier number for that attribute. */ + multiplier: number + /** The value number for that attribute. */ + value: number +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/itemstats} */ + export interface Itemstats { + /** The itemstat id. */ + id: number + /** The name of the set of stats. */ + name: string + /** List of attribute bonuses. Each object may contain the following : */ + attributes: AttributeModifier[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/legendaryarmory.ts b/src/endpoints/schemas/responses/legendaryarmory.ts new file mode 100644 index 00000000..1da7892a --- /dev/null +++ b/src/endpoints/schemas/responses/legendaryarmory.ts @@ -0,0 +1,18 @@ +/** + * - 1: Armor items, Back items and most Trinkets (except the ring Conflux) + * - 2: Focus, Greatsword, Hammer, Harpoon, Longbow, Rifle, Scepter, Shield, Short bow, Speargun, Staff, Torch, Trident and Warhorn. Also applies to Conflux. + * - 4: Axe, Dagger, Mace, Pistol, Sword + * - 7: Rune + * - 8: Sigil + */ +type Quantity = 1 | 2 | 4 | 7 | 8 + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/legendaryarmory} */ + export interface Legendaryarmory { + /** The item id of the Legendary Armor item. */ + id: number + /** The maximum quantity of Legendary Armory items that can be stored on an account. */ + max_count: Quantity + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/legends.ts b/src/endpoints/schemas/responses/legends.ts new file mode 100644 index 00000000..12207465 --- /dev/null +++ b/src/endpoints/schemas/responses/legends.ts @@ -0,0 +1,23 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/legends} */ + export interface Legend { + /** (default/null value: "") - The id of the Legend. */ + id: string + /** (default/null value: 0) - The id of the profession (swap Legend) skill resolvable against v2/skills. */ + swap: number + /** (default/null value: 0) - The id of the heal skill resolvable against v2/skills. */ + heal: number + /** (default/null value: 0) - The id of the elite skill resolvable against v2/skills. */ + elite: number + /** List of ids of the utility skills resolvable against v2/skills. */ + utilities: number[] + } +} + +export namespace Schema_2019_12_19 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/legends} */ + export interface Legend extends Schema_1970_01_01.Legend { + /** The legend code for a build template link. Available on schema version 2019-12-19T00:00:00.000Z or later. */ + code: number + } +} diff --git a/src/endpoints/schemas/responses/mailcarriers.ts b/src/endpoints/schemas/responses/mailcarriers.ts new file mode 100644 index 00000000..fb159345 --- /dev/null +++ b/src/endpoints/schemas/responses/mailcarriers.ts @@ -0,0 +1,21 @@ +import { URL } from "../../../types" + +type Flag = 'Default' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/mailcarriers} */ + export interface Mailcarrier { + /** The id of the mail carrier. */ + id: number + /** An array of item ids used to unlock the mailcarrier. Can be resolved against v2/items */ + unlock_items?: number[] + /** The order in which the mailcarrier appears in a list. */ + order: number + /** The icon uri for the mail carrier. */ + icon: URL + /** The name of the mailcarrier as it appears in-game. */ + name: string + /** Additional flags on the item, such as "Default" */ + flags: Flag[] + } +} diff --git a/src/endpoints/schemas/responses/mapchests.ts b/src/endpoints/schemas/responses/mapchests.ts new file mode 100644 index 00000000..31978c2f --- /dev/null +++ b/src/endpoints/schemas/responses/mapchests.ts @@ -0,0 +1,7 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/mapchests} */ + export interface Mapchest { + /** The (API-specific) id of the map chest. */ + id: string + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/maps.ts b/src/endpoints/schemas/responses/maps.ts new file mode 100644 index 00000000..d8eeb832 --- /dev/null +++ b/src/endpoints/schemas/responses/maps.ts @@ -0,0 +1,49 @@ +import { Coordinate, Race as R, URL } from '../../../types' + +/** + * BlueHome - The home borderlands of the blue worlds in WvW. + * Center - The map in WvW that resides in the center of the borderlands, Eternal Battlegrounds. + * EdgeOfTheMists - The Edge of the Mists map in WvW. + * GreenHome - The home borderlands of the green worlds in WvW. + * Instance - Instances. + * JumpPuzzle - At present only a WvW map that houses a jumping puzzle of the same name, Obsidian Sanctum. + * Public - Open world maps. + * Pvp - PvP as well as activity maps. + * RedHome - The home borderlands of the red worlds in WvW. + * Tutorial - The tutorial missions for newly created characters. + */ +type MapType = "BlueHome" | "Center" | "EdgeOfTheMists" | "GreenHome" | "Instance" | "JumpPuzzle" | "Public" | "Pvp" | "RedHome" | "Tutorial" + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/maps} */ + export interface Map { + /** The map id. */ + id: number + /** The map name. */ + name: string + /** The minimal level of this map. */ + min_level: number + /** The maximum level of this map. */ + max_level: number + /** The default floor of this map. */ + default_floor: number + /** The map type. */ + type: MapType + /** A list of available floors for this map. */ + floors: Array + /** The id of the region this map belongs to. */ + region_id: number + /** The name of the region this map belongs to. */ + region_name?: string + /** The id of the continent this map belongs to. */ + continent_id: number + /** The name of the continent this map belongs to. */ + continent_name: string + /** The dimensions of the map, given as the coordinates of the lower-left (SW) and upper-right (NE) corners. */ + map_rect: [Coordinate, Coordinate] + /** The dimensions of the map within the continent coordinate system, given as the coordinates of the upper-left (NW) and lower-right (SE) corners. */ + continent_rect: [Coordinate, Coordinate] + } + +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/masteries.ts b/src/endpoints/schemas/responses/masteries.ts new file mode 100644 index 00000000..01b7b8f9 --- /dev/null +++ b/src/endpoints/schemas/responses/masteries.ts @@ -0,0 +1,34 @@ +interface MasteryLevel { + /** The name for the given mastery. */ + name: string + /** The in game description for the given mastery. */ + description: string + /** The in game instructions for the given mastery. */ + instruction: string + /** The icon uri for the mastery. */ + icon: string + /** The amount of mastery points required to unlock the mastery. */ + point_cost: number + /** The total amount of experience needed to train the given mastery level. This total is non-cumulative between levels. */ + exp_cost: number +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/masteries} */ + export interface Mastery { + /** The id of the mastery. */ + id: number + /** The name of the selected mastery. */ + name: string + /** The written out requirements to unlock the mastery track. */ + requirement: string + /** The order in which the mastery track appears in a list. */ + order: number + /** The background uri for the mastery track. */ + background: string + /** The in-game region in which the mastery track belongs. */ + region: string + /** An array containing the information of each mastery level. */ + levels: Array + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/materials.ts b/src/endpoints/schemas/responses/materials.ts new file mode 100644 index 00000000..8a0ebb41 --- /dev/null +++ b/src/endpoints/schemas/responses/materials.ts @@ -0,0 +1,13 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/materials} */ + export interface Material { + /** The category id. */ + id: number + /** The category name. */ + name: string + /** The ids of the items in this category. */ + items: Array + /** The order in which the category appears in the material storage. */ + order: number + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/minis.ts b/src/endpoints/schemas/responses/minis.ts new file mode 100644 index 00000000..54140379 --- /dev/null +++ b/src/endpoints/schemas/responses/minis.ts @@ -0,0 +1,19 @@ +import { URL } from "../../../types" + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/minis} */ + export interface Mini { + /** The mini id. */ + id: number + /** The mini name. */ + name: string + /** A description of how to unlock the mini (only present on a few entries). */ + unlock: string + /** The mini icon. */ + icon: URL + /** The sort order that is used for displaying the mini in-game. */ + order: number + /** The item which unlocks the mini and can be resolved against /v2/items */ + item_id: number + } +} diff --git a/src/endpoints/schemas/responses/mounts.ts b/src/endpoints/schemas/responses/mounts.ts new file mode 100644 index 00000000..94b9b600 --- /dev/null +++ b/src/endpoints/schemas/responses/mounts.ts @@ -0,0 +1,41 @@ +import { ColorMaterial, WeaponSlot } from "../../../types" + +interface MountSkill { + id: number + slot: WeaponSlot +} + +interface DyeSlot { + color_id: number + material: ColorMaterial +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/mounts/types} */ + export interface Type { + /** The id of the mount. */ + id: string + /** The name of the mount type as it appears in-game. */ + name: string + /** The mount skin a mount has when first obtained. Can be resolved against v2/mounts/skins */ + default_skin: number + /** An array of mount skin ids. Can be resolved against v2/mounts/skins */ + skins: Array + /** Each object contains a key-value pair for the skill id and weapon slot. */ + skills: MountSkill[] + } + + /** {@link https://wiki.guildwars2.com/API:2/mounts/skins} */ + export interface Skin { + /** The id of the mount skin. */ + id: string + /** The name of the mount as it appears in-game. */ + name: string + /** The full icon URL. */ + icon: string + /** The mount type id for the given mount skin. Can be resolved against v2/mounts/types */ + mount: string + /** Each object contains a key-value pair for the color (dye) id and material. Can be resolved against v2/colors */ + dye_slots: DyeSlot[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/nodes.ts b/src/endpoints/schemas/responses/nodes.ts new file mode 100644 index 00000000..9aa4d038 --- /dev/null +++ b/src/endpoints/schemas/responses/nodes.ts @@ -0,0 +1,6 @@ +type Node = string + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/account/home/nodes} */ + export type Nodes = Node[] +} diff --git a/src/endpoints/schemas/responses/novelties.ts b/src/endpoints/schemas/responses/novelties.ts new file mode 100644 index 00000000..8fde90f3 --- /dev/null +++ b/src/endpoints/schemas/responses/novelties.ts @@ -0,0 +1,19 @@ +type Slot = 'Chair' | 'Music' | 'HeldItem' | 'Miscellaneous' | 'Tonic' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/novelties} */ + export interface Novelty { + /** The id of the novelty. */ + id: number + /** The name of the novelty as it appears in-game. */ + name: string + /** The in-game novelty description. */ + description: string + /** The icon url for the novelty. */ + icon: string + /** The slot which the novelty appears in the UI for. */ + slot: Slot + /** An array of item ids used to unlock the novelty. Can be resolved against v2/items */ + unlock_item: number[] + } +} diff --git a/src/endpoints/schemas/responses/outfits.ts b/src/endpoints/schemas/responses/outfits.ts new file mode 100644 index 00000000..f1b4d63f --- /dev/null +++ b/src/endpoints/schemas/responses/outfits.ts @@ -0,0 +1,13 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/outfits} */ + export interface Outfit { + /** The id of the outfit. */ + id: number + /** The name of the outfit (this is also the outfit displayed over a character in-game.) */ + name: string + /** The icon for the selected outfit. */ + icon: string + /** An array of item id which unlock this outfit; resolvable against v2/items. */ + unlock_items: number[] + } +} diff --git a/src/endpoints/schemas/responses/pets.ts b/src/endpoints/schemas/responses/pets.ts new file mode 100644 index 00000000..eed60667 --- /dev/null +++ b/src/endpoints/schemas/responses/pets.ts @@ -0,0 +1,19 @@ +interface Skill { + id: number +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/pets} */ + export interface Pet { + /** The codeid of the pet. */ + id: number + /** The name of the pet. */ + name: string + /** The description of the pet. */ + description: string + /** The icon uri for the pet. */ + icon: string + /** The id of the skill, to be resolved against v2/skills. */ + skills: Skill[] + } +} diff --git a/src/endpoints/schemas/responses/professions.ts b/src/endpoints/schemas/responses/professions.ts new file mode 100644 index 00000000..12703e55 --- /dev/null +++ b/src/endpoints/schemas/responses/professions.ts @@ -0,0 +1,86 @@ +import { Profession } from "../../../types" +import { Attunement, Weapon } from "../../../types" + +type WeaponFlag = 'Mainhand' | 'Offhand' | 'TwoHand' | 'Aquatic' +type SkillSlot = 'Profession_1' | 'Utility' | 'Heal' | 'Elite' +type ProfessionFlag = 'NotRacialSkills' | 'NoWeaponSwap' +type TrainingCategory = 'Skills' | 'Specializations' | 'EliteSpecializations' + +interface Track { + /** The cost to train this skill or trait. */ + cost: number +} + +interface Trait extends Track { + type: 'Trait' + /** This field is only present if type is Trait. */ + trait_id: number +} + +interface Skill extends Track { + type: 'Skill' + /** This field is only present if type is Skill. */ + skill_id: number +} + +interface Training { + /** The id of the API:2/skills or API:2/specializations inidcated by the category. */ + id: number + /** The category for the training object. */ + category: TrainingCategory + /** The name of the skill or specialization inidcated by the category and id. */ + name: string + /** List of skills and traits training details tracks objects. */ + track: Array +} + +interface WeaponSkill { + /** The id of the API:2/skills. */ + id: number + /** The skill bar slot that this weapon skill can be used in. */ + slot: SkillSlot + /** The name of the offhand weapon this skill requires to be equipped. This field is usually only present for Thief skills. */ + offhand?: Weapon + /** The Elementalist attunement that this skill requires. This field is usually only present for Elementalist skills. */ + attunement?: Attunement + /** The name of the class the skill was stolen from. This only applies to thief stolen skills. */ + source?: Profession +} + +interface WeaponInfo { + flag: WeaponFlag[] + /** he API:2/specializations id of the required specialization to use this weapon. This field is only present if the weapon requires a specialization to be used. */ + specialization?: number + /** The list of weapon skills objects. */ + skills: WeaponSkill[] +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/professions} */ + export interface Profession { + /** The profession id. */ + id: string + /** The name of the profession. */ + name: string + /** The icon for the profession. */ + icon: string + /** The large icon for the profession. */ + icon_big: string + /** List of API:2/specializations ids. */ + specializations: number[] + /** List of training details objects. */ + training: Training[] + /** The weapons available for this profession. The key indicates the weapon type. */ + weapons: {[key in Weapon]?: WeaponInfo} + flags: ProfessionFlag[] + } +} + +export namespace Schema_2019_12_19 { + export interface Profession extends Schema_1970_01_01.Profession { + /** The profession code for a build template link. Available on schema version 2019-12-19T00:00:00.000Z or later. */ + code: number + /** Contains arrays of two numbers. The first number is a skill palette ID obtained from a build template link, the second number is a skill ID. This is so you can resolve palette IDs obtained from a build template link to API:2/skills. This is only available on schema version 2019-12-19T00:00:00.000Z */ + skills_by_palette: Array<[number, number]> + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/quaggans.ts b/src/endpoints/schemas/responses/quaggans.ts new file mode 100644 index 00000000..efa03098 --- /dev/null +++ b/src/endpoints/schemas/responses/quaggans.ts @@ -0,0 +1,11 @@ +import { Race as R, URL } from '../../../types' + +type Quaggan = string + +export namespace Schema_1970_01_01 { + /** @link {https://wiki.guildwars2.com/wiki/API:2/quaggans} */ + export interface Quaggan { + id: Quaggan + url: URL + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/quests.ts b/src/endpoints/schemas/responses/quests.ts new file mode 100644 index 00000000..fb81e14c --- /dev/null +++ b/src/endpoints/schemas/responses/quests.ts @@ -0,0 +1,22 @@ +interface Goal { + /** The text displayed for the quest step if it is active. */ + active: string + /** The text displayed for the quest step if it is complete. */ + complete: string +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/quests} */ + export interface Quest { + /** The id of the quest. */ + id: number + /** The name of the quest. */ + name: string + /** The minimum level required for a character to begin this quest. */ + level: number + /** The id for the story; resolvable against v2/stories. */ + story: string + /** An array of goal objects providing details about the goals for this quest. */ + goals: Goal[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/races.ts b/src/endpoints/schemas/responses/races.ts new file mode 100644 index 00000000..900ce9ef --- /dev/null +++ b/src/endpoints/schemas/responses/races.ts @@ -0,0 +1,10 @@ +import { Race as R } from '../../../types' + +export namespace Schema_1970_01_01 { + /** @link {https://wiki.guildwars2.com/wiki/API:2/races} */ + export interface Race { + // FIXME: better alias? + id: R + skills: number[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/raids.ts b/src/endpoints/schemas/responses/raids.ts new file mode 100644 index 00000000..23704ff0 --- /dev/null +++ b/src/endpoints/schemas/responses/raids.ts @@ -0,0 +1,23 @@ +type EventType = 'Checkpoint' | 'Boss' + +interface Event { + /** The event/encounter name. */ + id: string + /** The type of events.*/ + type: EventType +} + +interface Wing { + /** The given name for the dungeon path. */ + id: string + events: Event[] +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/raids} */ + export interface Raid { + /** The name of the dungeon. */ + id: string + wings: Wing[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/skills.ts b/src/endpoints/schemas/responses/skills.ts new file mode 100644 index 00000000..51099b63 --- /dev/null +++ b/src/endpoints/schemas/responses/skills.ts @@ -0,0 +1,226 @@ +import { Profession, URL } from '../../../types' + +/** + * - Bundle – Used for Engineer kits or weapons picked up in-world. + * - Elite – Elite skill. + * - Heal – Heal skill. + * - Monster – Used for some NPC skills. + * - Pet – Used for Ranger pet skills. + * - Profession – Profession-specific skill, such as Elementalist attunements or Engineer toolbelt skills. + * - Toolbelt – Used for some Engineer toolbelt skills. + * - Transform – Placeholder skill used to indicate a locked slot. + * - Utility – Utility skill. + * - Weapon – Weapon skill or downed skill. + */ +type SkillType = 'Bundle' | 'Elite' | 'Heal' | 'Monster' | 'Pet' | 'Profession' | 'Toolbelt' | 'Utility' | 'Weapon' + +/** + * - Downed_[1-4] – Downed skills 1-4. + * - Pet - Used for Ranger pet skills. + * - Profession_[1-5] – Profession skills 1-5. + * - Utility – Utility skill. + * - Weapon_[1-5] – Weapon skills 1-5. + */ +type SkillSlot = 'Pet' | 'Utility' + | 'Downed_1' | 'Downed_2' | 'Downed_3' | 'Downed_4' + | 'Profession_1' | 'Profession_2' | 'Profession_3' | 'Profession_4' | 'Profession_5' + | 'Weapon_1' | 'Weapon_2' | 'Weapon_3' | 'Weapon_4' | 'Weapon_5' + +type SkillCategory = 'DualWield' | 'StealthAttack' | 'Signet' | 'Cantrip' + +type Attunment = 'Fire' | 'Water' | 'Air' | 'Earth' + +type SkillFlags = 'GroundTargeted' | 'NoUnderwater' + +type FactType = 'AttributeAdjust' | 'Buff' | 'ComboField' | 'ComboFinisher' | 'Damage' | 'Distance' | 'Duration' | 'Heal' | 'HealingAdjust' | 'NoData' | 'Number' | 'Percent' | 'PrefixedBuff' | 'Radius' | 'Range' | 'Recharge' | 'StunBreak' | 'Time' | 'Unblockable' + +type ComboFieldType = 'Air' | 'Dark' | 'Fire' | 'Ice' | 'Light' | 'Lightning' | 'Poison' | 'Smoke' | 'Ethereal' | 'Water' + +type ComboFinisherType = 'Blast' | 'Leap' | 'Projectile' | 'Whirl' + +interface AttributeAdjustFact extends BaseFact<'AttributeAdjust'> { + /** The amount target gets adjusted, based on a level 80 character at base stats. */ + value: number + /** The attribute this fact adjusts. Note that a value of Healing indicates the fact is a heal, and Ferocity is encoded at CritDamage. */ + target: string +} + +interface BuffFact extends BaseFact<'Buff'> { + /** The duration of the effect in seconds. Note that some facts of this type are just used to display the buff icon with text; in this case, duration is usually 0, or omitted entirely. */ + duration?: number + /** The boon, condition, or effect referred to by the fact. */ + status: string // FIXME: type + /** The description of the status effect. */ + description?: string + /** The number of stacks applied. */ + apply_count?: number +} + +interface ComboFieldFact extends BaseFact<'ComboField'> { + /** The type of field. */ + field_type: ComboFieldType +} + +interface ComboFinisherFact extends BaseFact<'ComboFinisher'> { + /** The percent chance that the finisher will trigger. */ + percent: number + /** The type of finisher. */ + finisher_type: ComboFinisherType +} + +interface DamageFact extends BaseFact<'Damage'> { + /** The amount of times the damage hits. */ + hit_count: number + /** Indicates the damage multiplier value of that skill. */ + dmg_multiplier: number +} + +interface DistanceFact extends BaseFact<'Distance'> { + /** The distance value. */ + distance: number +} + +interface DurationFact extends BaseFact<'Duration'> { + /** The duration in seconds. */ + duration: number +} + +interface HealFact extends BaseFact<'Heal'> { + /** The number of times the heal is applied. */ + hit_count: number +} + +// FIXME: honestly, this feels very much like a copy-paste error in the wiki... +interface HealingAdjustFact extends BaseFact<'HealingAdjust'> { + hit_count: number +} + +interface NoDataFact extends BaseFact<'NoData'> { +} + +interface NumberFact extends BaseFact<'Number'> { + /** The number value as referenced by `text`. */ + value: number +} + +interface PerecentFact extends BaseFact<'Percent'> { + /** The percentage value as referenced by `text`. */ + percent: number +} + +interface PrefixedBuffFact extends BaseFact<'PrefixedBuff'> { + /** The duration of the effect in seconds. Note that some facts of this type are just used to display the buff icon with text; in this case, duration is usually 0, or omitted entirely. */ + duration?: number + /** The boon, condition, or effect referred to by the fact. */ + status: string // FIXME: type + /** The description of the status effect. */ + description?: string + /** The number of stacks applied. */ + apply_count?: number + prefix: { + text: string, + icon: URL, + status: string, + description: string + } +} + +interface RadiusFact extends BaseFact<'Radius'> { + /** The radius value. */ + distance: number +} + +interface RangeFact extends BaseFact<'Range'> { + /** The range of the trait/skill. */ + value: number +} + +interface RechargeFact extends BaseFact<'Recharge'> { + /** The recharge time in seconds. */ + value: number +} + +interface StunBreakFact extends BaseFact<'StunBreak'> { + value: true +} + +interface TimeFact extends BaseFact<'Time'> { + /** The time value in seconds. */ + duration: number +} + +interface UnblockableFact extends BaseFact<'Unblockable'> { + value: true +} + +type Fact = AttributeAdjustFact | BuffFact | ComboFieldFact | ComboFinisherFact | DamageFact | DistanceFact | DurationFact | HealFact | HealingAdjustFact | NoDataFact | PerecentFact | PrefixedBuffFact | RadiusFact | RangeFact | RechargeFact | StunBreakFact | TimeFact | UnblockableFact + +// we'll have to make an exception from the "always interfaces over types"-rule here to accomodate TraitedFacts that are actually just mixins of some additional properties +type TraitedFact = Fact & { + /** Specifies which trait has to be selected in order for this fact to take effect. */ + requires_trait: number + /** This specifies the array index of the facts object it will override, if the trait specified in requires_trait is selected. If this field is omitted, then the fact contained within this object is to be appended to the existing facts array. */ + overrides?: number +} + +interface BaseFact { + /** An arbitrary localized string describing the fact. */ + text: string + /** A URL to the icon shown with the fact. Not included with all facts. */ + icon?: URL + /** Defines what additional fields the object will contain, and what type of fact it is. Can be one of the following: */ + type: T +} + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/skills} */ + export interface Skill { + /** The skill id. */ + id: number + /** The skill name. */ + name: string + /** The skill description. */ + description?: string + /** A URL to an icon of the skill. */ + icon: string + /** The chat link. */ + chat_link: string + /** The skill type (see below). Possible values: */ + type?: SkillType + /** Indicates what weapon the skill is on. Can also be None if not applicable. */ + weapon_type?: string + /** An array of strings indicating which profession(s) can use this skill. */ + professions: Array + /** A string indicating where this skill fits into. Possible values: */ + slot?: SkillSlot + /** An array of skill fact objects describing the skill's effect. (See below.) */ + facts?: Array + /** An array of skill fact objects that may apply to the skill, dependent on the player's trait choices. */ + traited_facts?: Array + /** An array of categories the skill falls under. Mostly used for organizational purposes, with some exceptions: */ + categories?: Array + /** Used for Elementalist weapon skills, indicates what attunement this skill falls under. One of: Fire, Water, Air, Earth. */ + attunement?: Attunment + /** Used for Revenant, Warrior, and Druid skills to indicate their energy cost. */ + cost?: number + /** Indicates what off-hand must be equipped for this dual-wield skill to appear. */ + dual_wield?: string + /** Used for skills that "flip over" into a new skill in the same slot to indicate what skill they flip to, such as Engineer toolkits or Herald facets. */ + flip_skill?: number + /** Indicates the Initiative cost for thief skills. */ + initiative?: number + /** Indicates the next skill in the chain, if applicable. */ + next_chain?: number + /** Indicates the previous skill in the chain, if applicable. */ + prev_chain?: number + /** Used to indicate that the skill will transform the player, replacing their skills with the skills listed in the array. */ + transform_skills?: Array + /** Used to indicate that the skill will replace the player's skills with the skills listed in the array. */ + bundle_skills?: Array + /** Used for Engineer utility skills to indicate their associated toolbelt skill. */ + toolbelt_skill?: number + /** Used to indicate usage limitations, more than one value can be set. One of: GroundTargeted, NoUnderwater. */ + flags?: Array + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/skins.ts b/src/endpoints/schemas/responses/skins.ts new file mode 100644 index 00000000..8edcfb6c --- /dev/null +++ b/src/endpoints/schemas/responses/skins.ts @@ -0,0 +1,66 @@ +import { Race, Rarity, URL } from "../../../types" + +type WeightClass = 'Clothing' | 'Light' | 'Medium' | 'Heavy' +type SkinType = 'Armor' | 'Weapon' | 'Back' | 'Gathering' +type Flag = 'ShowInWardRobe' | 'NoCost' |'HideIfLocked' | 'OverrideRarity' +type Material = 'cloth' | 'leather' | 'metal' +type Overrides = 'AsuraMale' | 'AsuraFemale' | 'CharrMale' | 'CharrFemale' | 'HumanMale' | 'HumanFemale' | 'NornMale' | 'NornFemale' | 'SylvariMale' | 'SylvariFemale' +type DyeSlot = { + /** The id of the default color, to be resolved against v2/colors */ + color_id: number, + /** The type of material. Either cloth, leather, metal */ + material: Material +} + +interface Armor { + /** The armor type (slot). */ + type: string // FIXME: typedef? + /** The armor weight, either Clothing, Light, Medium or Heavy. */ + weight_class: WeightClass + /** An object containing information on default slots and skin overrides. If the array item is null, this means dye cannot be applied to that slot, except if otherwise overriden by non-null values in the overrides array. */ + dye_slots: { + default: DyeSlot[], + /** Object of race/gender overrides. Each sub-object follows the same structure as default. The possible override sub-objects are: AsuraMale, AsuraFemale, CharrMale, CharrFemale, HumanMale, HumanFemale, NornMale, NornFemale, SylvariMale, SylvariFemale */ + overrides: {[key in Overrides]?: DyeSlot[]} + } +} + +interface Weapon { + /** The weapon type. */ + type: string // FIXME: typedef? + /** The damage type, either Physical, Fire, Lightning, Ice or Choking. */ + damage_type: 'Physical' | 'Fire' | 'Lightning' | 'Ice' | 'Choking' +} + +/** The tool type, either Foraging, Logging or Mining */ +type GatheringTool = 'Foraging' | 'Logging' | 'Mining' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/account/skins} */ + export interface Skin { + /** The skin id. */ + id: number + /** The name of the skin. */ + name: string + /** The skin type, either Armor, Weapon, Back or Gathering. */ + type: SkinType + /** Additional skin flags. Possible flags are: + * - ShowInWardrobe – When displayed in the account wardrobe (set for all skins listed in the API). + * - NoCost – When applying the skin is free. + * - HideIfLocked – When the skin is hidden until it is unlocked. + * - OverrideRarity - When the skin overrides item rarity when applied + */ + flags: Flag[] + /** Race restrictions that apply to the skin, e.g. Human will be a listed restriction, if the skin can only be applied to human characters. */ + restrictions: Race[] + /** The full icon URL. */ + icon: URL + /** The rarity of the skin */ + rarity: Rarity + /** Optional skin description. */ + description: string + /** Additional skin details if applicable, depending on the skin type */ + details: Armor | Weapon | GatheringTool + } + +} diff --git a/src/endpoints/schemas/responses/specializations.ts b/src/endpoints/schemas/responses/specializations.ts new file mode 100644 index 00000000..7c3a09bd --- /dev/null +++ b/src/endpoints/schemas/responses/specializations.ts @@ -0,0 +1,23 @@ +import { URL } from "../../../types" + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/specializations} */ + export interface Specialization { + /** The specialization's ID. */ + id: number + /** The name of the specialization. */ + name: string + /** The profession that this specialization belongs to. */ + profession: string + /** true if this specialization is an Elite specialization, false otherwise. */ + elite: boolean + /** A URL to an icon of the specialization. */ + icon: URL + /** A URL to the background image of the specialization. */ + background: URL + /** Contains a list of IDs specifying the minor traits in the specialization. */ + minor_traits: Array + /** Contains a list of IDs specifying the major traits in the specialization. */ + major_traits: Array + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/stories.ts b/src/endpoints/schemas/responses/stories.ts new file mode 100644 index 00000000..1443a217 --- /dev/null +++ b/src/endpoints/schemas/responses/stories.ts @@ -0,0 +1,33 @@ +import { Race } from "../../../types" + +// FIXME: are there more? +type StoryFlag = 'RequiresUnlock' + +interface Chapter { + /** The name of the chapter. */ + name: string +} + +export namespace Schema_1970_01_01 { + /** @link {https://wiki.guildwars2.com/wiki/API:2/stories} */ + export interface Story { + /** The id of the story. */ + id: number + /** The id for the story season; resolvable against v2/stories/seasons. */ + season: string + /** The name of the story. */ + name: string + /** The description of the story. */ + description: string + /** The (in-game, not real-world) date of the story. */ + timeline: string + /** The minimum level required for a character to begin this story. */ + level: number + /** The order in which this story is displayed in the Story Journal. */ + order: number + /** An array of chapter objects providing details about the chapters for this story. */ + chapters: Chapter[] + races?: Race[] + flags?: StoryFlag[] + } +} diff --git a/src/endpoints/schemas/responses/titles.ts b/src/endpoints/schemas/responses/titles.ts new file mode 100644 index 00000000..518a415d --- /dev/null +++ b/src/endpoints/schemas/responses/titles.ts @@ -0,0 +1,15 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/titles} */ + export interface Title { + /** The id of the title. */ + id: number + /** The name of the title (this is also the title displayed over a character in-game.) */ + name: string + /** (Now depreciated) - The id of the achievement that grants this title; resolvable against v2/achievements. */ + achievement: number + /** The id of the achievement that grants this title; resolvable against v2/achievements. */ + achievements: number[] + /** The amount of AP required to have said title. */ + ap_required: number + } +} diff --git a/src/endpoints/schemas/responses/tokeninfo.ts b/src/endpoints/schemas/responses/tokeninfo.ts new file mode 100644 index 00000000..9562dc0f --- /dev/null +++ b/src/endpoints/schemas/responses/tokeninfo.ts @@ -0,0 +1,24 @@ +import { ISO8601, URL } from "../../../types" + +type Permission = 'account' | 'builds' | 'characters' | 'guilds' | 'inventories' | 'progression' | 'pvp' | 'tradingpost' | 'unlocks' | 'wallet' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/tokeninfo} */ + export interface TokenInfo { + /** The first half of the API key that was requested. */ + id: number + /** The name given to the API key by the account owner. Warning: The value of this field is not escaped and may contain valid HTML, JavaScript, other code. Handle with care. */ + name: string + /** Array of strings describing which permissions the API key has. */ + permissions: Permission[] + } +} + +export namespace Schema_2022_05_19 { + export interface TokenInfo extends Schema_1970_01_01.TokenInfo { + type: 'APIKey' | 'Subtoken' + expires_at: ISO8601 + issued_at: ISO8601 + urls: URL[] + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/traits.ts b/src/endpoints/schemas/responses/traits.ts new file mode 100644 index 00000000..c4e545cd --- /dev/null +++ b/src/endpoints/schemas/responses/traits.ts @@ -0,0 +1,172 @@ +type FactTypeName = 'AttributeAdjust' | 'Buff' | 'BuffConversion' | 'ComboField' | 'ComboFinisher' | 'Damage' | 'Distance' | 'NoData' | 'Number' | 'Percent' | 'PrefixedBuff' | 'Radius' | 'Range' | 'Recharge' | 'Time' | 'Unblockable' +type FactType = AttributeAdjust | Buff | BuffConversion | ComboField | ComboFinisher | Damage | Distance | NoData | Number | Percent | PrefixedBuff | Radius | Range | Recharge | Time | Unblockable +type TraitType = 'Major' | 'Minor' + +interface Skill { + /** The ID of the skill. */ + id: number + /** The name of the skill. */ + name: string + /** The description of the skill. */ + description: string + /** The URL for the icon of the skill. */ + icon: string + /** A list of tooltip facts associated with the skill. (See below.) */ + facts?: Array + /** A list of additions or changes to tooltip facts where there is interplay between traits. (See below.) */ + traited_facts?: Array +} + +interface TraitedFact { + /** Specifies which trait has to be selected in order for this fact to take effect. */ + requires_trait: number + /** This specifies the array index of the facts object it will override, if the trait specified in requires_trait is selected. If this field is omitted, then the fact contained within this object is to be appended to the existing facts array. */ + overrides?: number +} + +interface Fact { + /** An arbitrary localized string describing the fact. Not included with all facts. */ + text?: string + /** A URL to the icon shown with the fact. Not included with all facts. */ + icon?: string + /** Defines what additional fields the object will contain, and what type of fact it is. Can be one of the following: */ + type: T +} + +interface AttributeAdjust extends Fact<'AttributeAdjust'> { + /** The amount target gets adjusted, based on a level 80 character at base stats. */ + value: number + /** The attribute this fact adjusts. Note that a value of Healing indicates the fact is a heal, and Ferocity is encoded at CritDamage. */ + target: string +} + +interface Buff extends Fact<'Buff'> { + /** The boon, condition, or effect referred to by the fact. */ + status: string + /** The description of the status effect. */ + description?: string + /** The number of stacks applied. */ + apply_count?: number + /** The duration of the effect in seconds. Note that some facts of this type are just used to display the buff icon with text; in this case, duration is usually 0, or omitted entirely. */ + duration?: number +} + +interface BuffConversion extends Fact<'BuffConversion'> { + /** The attribute that is used to calculate the attribute gain. */ + source: string + /** How much of the source attribute is added to target. */ + percent: string + /** The attribute that gets added to. */ + target: string +} + +interface ComboField extends Fact<'ComboField'> { + /** The type of field. */ + field_type: 'Air' | 'Dark' | 'Fire' | 'Ice' | 'Light' | 'Lightning' | 'Poison' | 'Smoke' | 'Ethereal' | 'Water' +} + +interface ComboFinisher extends Fact<'ComboFinisher'> { + /** The type of finisher. */ + finisher_type: 'Blast' | 'Leap' | 'Projectile' | 'Whirl' + /** The percent chance that the finisher will trigger. */ + percent: number +} + +interface Damage extends Fact<'Damage'> { + /** The amount of times the damage hits. */ + hit_count: number +} + +interface Distance extends Fact<'Distance'> { + /** The distance value. */ + distance: number +} + +interface NoData extends Fact<'NoData'> { +} + +interface Number extends Fact<'Number'> { + /** The number value as referenced by text. */ + value: number +} + +interface Percent extends Fact<'Percent'> { + /** The percentage value as referenced by text. */ + value: number +} + +interface PrefixedBuff extends Fact<'Percent'> { + /** The boon, condition, or effect referred to by the fact. */ + status: string + /** The description of the status effect. */ + description?: string + /** The number of stacks applied. */ + apply_count?: number + /** The duration of the effect in seconds. Note that some facts of this type are just used to display the buff icon with text; in this case, duration is usually 0, or omitted entirely. */ + duration?: number + prefix: { + text: string + icon: string + status: string + description?: string + } +} + +interface Radius extends Fact<'Radius'> { + /** The radius value. */ + distance: number +} + +interface Range extends Fact<'Range'> { + /** The range of the trait/skill. */ + value: number +} + +interface Recharge extends Fact<'Recharge'> { + /** The recharge time in seconds. */ + recharge: number +} + +interface Time extends Fact<'Time'> { + /** The time value in seconds. */ + duration: number +} + +interface Unblockable extends Fact<'Unblockable'> { + /** Always true. */ + value: true +} + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/wiki/API:2/traits} */ + export interface Trait { + /** The trait id. */ + id: number + /** The trait name. */ + name: string + /** The trait's icon URL. */ + icon: string + /** The trait description. */ + description: string + /** The id of the specialization this trait belongs to. */ + specialization: number + /** The trait's tier (Adept, Master, Grandmaster) as a value from 1-3. Elite specializations also contain a tier 0 minor trait, describing which weapon the elite specialization gains access to. */ + tier: number + /** Either Major or Minor depending on the trait's slot. Minor traits are the ones given immediately when choosing a specialization. */ + slot: TraitType + /** A list of tooltip facts associated with the trait itself. (See below.) */ + facts?: Array + /** A list of additions or changes to tooltip facts where there is interplay between traits. (See below.) */ + traited_facts?: Array + /** A list of skills which may be triggered by the trait. (See below.) */ + skills?: Array + } +} + + + + + + + + diff --git a/src/endpoints/schemas/responses/worldbosses.ts b/src/endpoints/schemas/responses/worldbosses.ts new file mode 100644 index 00000000..5471a3a1 --- /dev/null +++ b/src/endpoints/schemas/responses/worldbosses.ts @@ -0,0 +1,7 @@ +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/worldbosses} */ + export interface Worldboss { + /** The (API-specific) id of the world boss. */ + id: string + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/worlds.ts b/src/endpoints/schemas/responses/worlds.ts new file mode 100644 index 00000000..aea79c8e --- /dev/null +++ b/src/endpoints/schemas/responses/worlds.ts @@ -0,0 +1,18 @@ +type Population = 'Low' | 'Medium' | 'High' | 'VeryHigh' | 'Full' + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/worlds} */ + export interface World { + /** The world id. + * + * The first digit of the id indicates the world's region. 1 is North America, 2 is Europe. + * + * The second digit of the id currently correlates with the world's assigned language: 1 means French, 2 means German, and 3 means Spanish. + */ + id: number + /** The world name. */ + name: string + /** The world population level. One of: Low, Medium, High, VeryHigh, Full */ + population: string + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/responses/wvw.ts b/src/endpoints/schemas/responses/wvw.ts new file mode 100644 index 00000000..cb3db568 --- /dev/null +++ b/src/endpoints/schemas/responses/wvw.ts @@ -0,0 +1,184 @@ +import { Coordinate, Coordinate3, URL } from "../../../types" + +type Faction = 'red' | 'blue' | 'green' +type FactionData = { [key in Faction]: T } +type ObjectiveType = 'Spawn' | 'Camp' | 'Ruins' | 'Tower' | 'Keep' | 'Castle' | 'Mercenary' +type WvWMap = 'RedHome' | 'GreenHome' | 'BlueHome' | 'Center' + + +interface Rank { + /** The cost in WvW experience points to purchase the ability. */ + cost: number + /** The effect given to players for obtaining the given ability rank. */ + effect: string +} + +interface MatchObjective { + /** The objective id. */ + id: string + /** The objective type, with possible values Spawn, Camp, Ruins, Tower, Keep, Castle, and Mercenary (Dredge/Krait/Frogs). */ + type: ObjectiveType + /** The current owner of the objective. Can be any one of Red, Green, Blue or Neutral. */ + owner: Faction | 'Neutral' + /** The time at which this objective was last captured by a server. (ISO-8601 Standard) */ + last_flipped: string + /** The guild id of the guild currently claiming the objective, or null if not claimed. (Not present for unclaimable objectives.) */ + claimed_by?: string + /** The time the objective was claimed by the claimed_by guild (ISO-8601 Standard), or null if not claimed. (Not present for unclaimable objectives.) */ + claimed_at?: string + /** The amount of points per tick the given objective yields. */ + points_tick: number + /** The amount of points awarded for capturing the objective. */ + points_capture: number + /** An array of ids, resolvable against v2/guild/upgrades, showing which guild upgrades are currently slotted. */ + guild_upgrades?: number[] + /** The total amount of yak shipments delivered to the objective. Not limited to the shipments within the current tier only. */ + yaks_delivered?: number +} + +interface Bonus { + /** A shorthand name for the bonus. Currently can only be Bloodlust. */ + type: 'Bloodlust' + /** The color representing which world group owns the bloodlust. */ + owner: Faction +} + + + +interface Map { + /** The map id */ + id: number + /** The identifier for the map. Can be either RedHome, GreenHome or BlueHome for the borderlands or Center for Eternal Battlegrounds. */ + type: WvWMap + /** An object containing the score of the three servers for only the specified map, under the values red, blue, and green. */ + scores: FactionData + /** An object containing the total kills of the three servers for only the specified map, under the values red, blue, and green. */ + kills: FactionData + /** An object containing the total deaths of the three servers for only the specified map, under the values red, blue, and green. */ + deaths: FactionData + /** A list of objective objects for this map. Each object contains the following properties: */ + objectives: Array + /** A list of all bonuses being granted by this map. If no player team owns a bonus from the map, this list is empty. */ + bonuses: Array +} + + +interface MapScore { + /** Which map is being looked at, can have the values "Center", "RedHome", "BlueHome", or "GreenHome" */ + type: WvWMap + /** Object containing total scores for each team color on the selected map, under the values red, blue, and green. */ + scores: FactionData +} + + +interface Skirmish { + /** The skirmish id */ + id: number + /** Object containing total scores for each team color, under the values red, blue, and green. */ + scores: FactionData + /** Contains the map specific scores for the specific skirmish. */ + map_scores: Array +} + +interface Upgrade { + /** The name of the upgrade tier. */ + name: string + /** The given description for this upgrade. */ + description: string + /** The url/image link for the upgrade's icon. */ + icon: URL +} + +interface Tier { + /** The name of the upgrade tier. */ + name: string + /** The number of required yaks. */ + yaks_required: number + upgrades: Array +} + + +export namespace Schema_1970_01_01 { + /** {@link https://wiki.guildwars2.com/API:2/wvw/abilities} */ + export interface Ability { + /** The id of the abilities. */ + id: number + /** The given name for the WvW ability. */ + name: string + /** The given description for the WvW ability. */ + description: string + /** The uri for the ability's icon. */ + icon: URL + ranks: Array + } + + + /** {@link https://wiki.guildwars2.com/API:2/wvw/matches} */ + export interface Match { + /** The WvW match id. */ + id: string + /** The starting time of the matchup. (ISO-8601 Standard) */ + start_time: string + /** The ending time of the matchup. (ISO-8601 Standard) */ + end_time: string + /** An object containing the score of the three servers, under the values red, blue, and green. */ + scores: object + /** An object containing the IDs of the three primary matchup worlds. */ + worlds: FactionData + /** An object containing the world IDs of the three combined servers, under the values red, blue, and green. */ + all_worlds: FactionData + /** An object containing the total deaths of the three servers, under the values red, blue, and green. */ + deaths: FactionData + /** An object containing the total kills of the three servers, under the values red, blue, and green. */ + kills: FactionData + /** An object containing the victory points of the three servers, under the values red, blue, and green. */ + victory_points: FactionData + /** A list of objects containing detailed information about each of the four maps. The map detail objects contain the following properties: */ + maps: Array + skirmishes: Array + } + + /** {@link https://wiki.guildwars2.com/API:2/wvw/objectives} */ + export interface Objective { + /** The objective id. */ + id: string + /** The name of the objective. */ + name: string + /** The type of the objective. Possible values include: */ + type: string + /** The map sector the objective can be found in. (See /v2/continents.) */ + sector_id: any + /** The ID of the map that this objective can be found on. */ + map_id: number + /** The map that this objective can be found on. One of: GreenHome, BlueHome, RedHome, Center, or EdgeOfTheMists. */ + map_type: string + /** An array of three numbers representing the X, Y and Z coordinates of the objectives marker on the map. */ + coord: Coordinate3 + /** An array of two numbers representing the X and Y coordinates of the sector centroid. */ + label_coord: Coordinate + /** The icon link */ + marker: URL + /** The chat code for the observed objective. */ + chat_link: string + /** The upgrade id to be resolved against v2/wvw/upgrades. */ + upgrade_id: number + } + + + /** {@link https://wiki.guildwars2.com/API:2/wvw/ranks} */ + export interface Rank { + /** The id of the rank. */ + id: number + /** The given title for the WvW rank. */ + title: string + /** The minimum WvW level required to be at this rank. */ + min_rank: number + } + + /** {@link https://wiki.guildwars2.com/API:2/wvw/upgrades} */ + export interface Upgrade { + /** The upgrade id. */ + id: string + tiers: Array + } +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema.ts b/src/endpoints/schemas/schema.ts new file mode 100644 index 00000000..c463dcfc --- /dev/null +++ b/src/endpoints/schemas/schema.ts @@ -0,0 +1,69 @@ +export interface EndpointResponse {} + +export interface Schema { + Account: EndpointResponse, + Achievements: EndpointResponse, + Answers: EndpointResponse, + Backstory: EndpointResponse, + Build: EndpointResponse, + Category: EndpointResponse, + Cats: EndpointResponse, + Characters: EndpointResponse, + Colors: EndpointResponse, + Commerce: EndpointResponse, + Continents: EndpointResponse, + Currencies: EndpointResponse, + Exchange: EndpointResponse, + Daily: EndpointResponse + Dailies: EndpointResponse + Dailycrafting: EndpointResponse, + Delivery: EndpointResponse, + Dungeons: EndpointResponse, + Emblem: EndpointResponse, + Events: EndpointResponse, + Files: EndpointResponse, + Finishers: EndpointResponse, + Floor: EndpointResponse, + Gliders: EndpointResponse, + Group: EndpointResponse + Guild: EndpointResponse, + Home: EndpointResponse, + Items: EndpointResponse, + Itemstats: EndpointResponse, + Legendaryarmory: EndpointResponse, + Legends: EndpointResponse, + Listings: EndpointResponse, + Mailcarriers: EndpointResponse, + Mapchests: EndpointResponse, + Maps: EndpointResponse, + Masteries: EndpointResponse, + Materials: EndpointResponse, + Minis: EndpointResponse, + Mounts: EndpointResponse, + Nodes: EndpointResponse, + Novelties: EndpointResponse, + Outfits: EndpointResponse, + Pets: EndpointResponse, + Prices: EndpointResponse, + Professions: EndpointResponse, + Pvp: EndpointResponse, + Quaggans: EndpointResponse, + Questions: EndpointResponse, + Quests: EndpointResponse, + Races: EndpointResponse, + Raids: EndpointResponse, + Recipes: EndpointResponse, + Skills: EndpointResponse, + Skins: EndpointResponse, + Specializations: EndpointResponse, + Stories: EndpointResponse, + Titles: EndpointResponse, + Tokeninfo: EndpointResponse, + Traits: EndpointResponse, + Transactions: EndpointResponse, + Worldbosses: EndpointResponse, + Worlds: EndpointResponse, + Wvw: EndpointResponse, +} + + diff --git a/src/endpoints/schemas/schema_1970_01_01.ts b/src/endpoints/schemas/schema_1970_01_01.ts new file mode 100644 index 00000000..cf6c5b07 --- /dev/null +++ b/src/endpoints/schemas/schema_1970_01_01.ts @@ -0,0 +1,194 @@ +import { Schema as BaseSchema } from './schema' + +import { Schema_1970_01_01 as backstory } from './responses/backstory' +import { Schema_1970_01_01 as achievements } from './responses/achievements' +import { Schema_1970_01_01 as build } from './responses/build' +import { Schema_1970_01_01 as cats } from './responses/cats' +import { Schema_1970_01_01 as currencies } from './responses/currencies' +import { Schema_1970_01_01 as commerce } from './responses/commerce' +import { Schema_1970_01_01 as dungeons } from './responses/dungeons' +import { Schema_1970_01_01 as finishers } from './responses/finishers' +import { Schema_1970_01_01 as gliders } from './responses/gliders' +import { Schema_1970_01_01 as continents } from './responses/continents' +import { Schema_1970_01_01 as colors } from './responses/colors' +import { Schema_1970_01_01 as dailycrafting } from './responses/dailycrafting' +import { Schema_1970_01_01 as emblems } from './responses/emblems' +import { Schema_1970_01_01 as legends } from './responses/legends' +import { Schema_1970_01_01 as mailcarriers } from './responses/mailcarriers' +import { Schema_1970_01_01 as minis } from './responses/minis' +import { Schema_1970_01_01 as skins } from './responses/skins' +import { Schema_1970_01_01 as titles } from './responses/titles' +import { Schema_1970_01_01 as tokeninfo } from './responses/tokeninfo' +import { Schema_1970_01_01 as nodes } from './responses/nodes' +import { Schema_1970_01_01 as traits } from './responses/traits' +import { Schema_1970_01_01 as races } from './responses/races' +import { Schema_1970_01_01 as quaggans } from './responses/quaggans' +import { Schema_1970_01_01 as novelties } from './responses/novelties' +import { Schema_1970_01_01 as outfits } from './responses/outfits' +import { Schema_1970_01_01 as pets } from './responses/pets' +import { Schema_1970_01_01 as professions } from './responses/professions' +import { Schema_1970_01_01 as files } from './responses/files' +import { Schema_1970_01_01 as masteries } from './responses/masteries' +import { Schema_1970_01_01 as mounts } from './responses/mounts' +import { Schema_1970_01_01 as raids } from './responses/raids' +import { Schema_1970_01_01 as mapchests } from './responses/mapchests' +import { Schema_1970_01_01 as legendaryarmory } from './responses/legendaryarmory' +import { Schema_1970_01_01 as worldbosses } from './responses/worldbosses' +import { Schema_1970_01_01 as worlds } from './responses/worlds' +import { Schema_1970_01_01 as quests } from './responses/quests' +import { Schema_1970_01_01 as stories } from './responses/stories' +import { Schema_1970_01_01 as account } from './responses/account' +import { Schema_1970_01_01 as specializations } from './responses/specializations' +import { Schema_1970_01_01 as materials } from './responses/materials' +import { Schema_1970_01_01 as guilds } from './responses/guilds' +import { Schema_1970_01_01 as characters } from './responses/characters' +import { Schema_1970_01_01 as skills } from './responses/skills' +import { Schema_1970_01_01 as events } from './responses/events' +import { Schema_1970_01_01 as items } from './responses/items' +import { Schema_1970_01_01 as itemstats } from './responses/itemstats' +import { Schema_1970_01_01 as maps } from './responses/maps' +import { Schema_1970_01_01 as wvw } from './responses/wvw' + +export interface Schema extends BaseSchema { + // Account + Account: account.Account + // Achievements + Daily: achievements.Daily + Dailies: achievements.Dailies + Category: achievements.Category + Achievement: achievements.Achievement + Group: achievements.Group + // Build + Build: build.Build + // Character + Core: characters.Core + Equipment: characters.Equipment + Crafting: characters.Crafting + BuildTabs: characters.BuildTabs + EquipmentTabs: characters.EquipmentTabs + Inventory: characters.Inventory + Recipe: characters.Recipe + // FIXME: really need to nest! Collision with Skills + cSkills: characters.Skills + // FIXME: duplicate? + CharacterSpecializations: characters.Specializations + Training: characters.Training + // Home + Cats: cats.Cat + Nodes: nodes.Nodes + // Backstory + Answers: backstory.Answer + Questions: backstory.Question + // Currencies + Currencies: currencies.Currency + // Colors + Colors: colors.Color + // Commerce + Delivery: commerce.Delivery + Exchange: commerce.Exchange + Listings: commerce.Listing + Prices: commerce.Price + Transactions: commerce.Transactions + // Dailycrafting + Dailycrafting: dailycrafting.DailyCrafting + // Dungeon + Dungeons: dungeons.Dungeon + // Emblem + Emblem: emblems.Emblem + // Events + Events: events.EventDetails + // Files + Files: files.File + // Finisher + Finishers: finishers.Finisher + // Gliders + Gliders: gliders.Glider + // Guilds + Guilds: guilds.Guild + Logs: guilds.Log + Members: guilds.Member + Ranks: guilds.Rank + Stash: guilds.Stash + Storage: guilds.Storage + Team: guilds.Team + Treasury: guilds.Treasury + Upgrades: guilds.Upgrade + Permissions: guilds.Permission + Search: guilds.Search + // Items + BackItems: items.BackItem + Bags: items.Bag + Consumables: items.Consumable + Containers: items.Container + Gathering: items.Gathering + Gizmos: items.Gizmo + Miniatures: items.Miniature + SalvageKits: items.SalvageKit + Trinket: items.Trinket + UpgradeComponent: items.UpgradeComponent + Weapons: items.Weapon + Armor: items.Armor + // Itemstats + Itemstats: itemstats.Itemstats + // Continents + Continents: continents.Continent + Floor: continents.Floor + // Quests + Quests: quests.Quest + // Legendary Armory + LegendaryArmory: legendaryarmory.Legendaryarmory + // Legends + Legends: legends.Legend + // Mailcarriers + Mailcarriers: mailcarriers.Mailcarrier + Map: maps.Map + // Mapchests + Mapchests: mapchests.Mapchest + // Masteries + Masteries: masteries.Mastery + // Materials + Materials: materials.Material + // Mounts + MountType: mounts.Type + MountSkin: mounts.Skin + // Minis + Minis: minis.Mini + // Novelties + Novelties: novelties.Novelty + // Outfits + Outfits: outfits.Outfit + // Pets + Pets: pets.Pet + // Professions + Professions: professions.Profession + // Quaggans + Quaggans: quaggans.Quaggan + // Races + Races: races.Race + // Raid + Raid: raids.Raid + // Specializations + Specializations: specializations.Specialization + // Stories + Stories: stories.Story + // Titles + Titles: titles.Title + // Tokeninfo + Tokeninfo: tokeninfo.TokenInfo + // Trait + Traits: traits.Trait + Skills: skills.Skill + // Skins + Skins: skins.Skin + // Worlds + Worlds: worlds.World + // Worldbosses + Worldbosses: worldbosses.Worldboss + // WvW + Abilities: wvw.Ability + Matches: wvw.Match + Objective: wvw.Objective + // FIXME: collision! + wRanks: wvw.Rank + Upgrade: wvw.Upgrade +} diff --git a/src/endpoints/schemas/schema_2019_02_21.ts b/src/endpoints/schemas/schema_2019_02_21.ts new file mode 100644 index 00000000..2580555a --- /dev/null +++ b/src/endpoints/schemas/schema_2019_02_21.ts @@ -0,0 +1,6 @@ +import { Schema as BaseSchema } from './schema_1970_01_01' +import * as account from './responses/account' + +export interface Schema extends Omit { + Account: account.Schema_2019_02_21.Account +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2019_03_22.ts b/src/endpoints/schemas/schema_2019_03_22.ts new file mode 100644 index 00000000..5389d810 --- /dev/null +++ b/src/endpoints/schemas/schema_2019_03_22.ts @@ -0,0 +1,6 @@ +import { Schema as BaseSchema } from './schema_2019_02_21' +import * as cats from './responses/cats' + +export interface Schema extends Omit { + Cats: cats.Schema_2019_03_22.Cat +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2019_05_16.ts b/src/endpoints/schemas/schema_2019_05_16.ts new file mode 100644 index 00000000..f95236e1 --- /dev/null +++ b/src/endpoints/schemas/schema_2019_05_16.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2019_03_22' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2019_05_21.ts b/src/endpoints/schemas/schema_2019_05_21.ts new file mode 100644 index 00000000..87ad94b3 --- /dev/null +++ b/src/endpoints/schemas/schema_2019_05_21.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2019_05_16' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2019_05_22.ts b/src/endpoints/schemas/schema_2019_05_22.ts new file mode 100644 index 00000000..4b24899a --- /dev/null +++ b/src/endpoints/schemas/schema_2019_05_22.ts @@ -0,0 +1,6 @@ +import { Schema as BaseSchema } from './schema_2019_05_21' +import * as tokeninfo from './responses/tokeninfo' + +export interface Schema extends Omit { + Tokeninfo: tokeninfo.Schema_2022_05_19.TokenInfo +} diff --git a/src/endpoints/schemas/schema_2019_12_19.ts b/src/endpoints/schemas/schema_2019_12_19.ts new file mode 100644 index 00000000..79773df2 --- /dev/null +++ b/src/endpoints/schemas/schema_2019_12_19.ts @@ -0,0 +1,12 @@ +import { Schema as BaseSchema } from './schema_2019_05_22' +import * as account from './responses/account' +import * as legends from './responses/legends' +import * as professions from './responses/professions' +import * as characters from './responses/characters' + +export interface Schema extends Omit { + Account: account.Schema_2019_12_19.Account + Legends: legends.Schema_2019_12_19.Legend + Professions: professions.Schema_2019_12_19.Profession + Equipment: characters.Schema_2019_12_19.Equipment +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2020_11_17.ts b/src/endpoints/schemas/schema_2020_11_17.ts new file mode 100644 index 00000000..3d073e63 --- /dev/null +++ b/src/endpoints/schemas/schema_2020_11_17.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2019_12_19' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2021_04_06.ts b/src/endpoints/schemas/schema_2021_04_06.ts new file mode 100644 index 00000000..adc20c86 --- /dev/null +++ b/src/endpoints/schemas/schema_2021_04_06.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2020_11_17' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2021_07_15.ts b/src/endpoints/schemas/schema_2021_07_15.ts new file mode 100644 index 00000000..259abd65 --- /dev/null +++ b/src/endpoints/schemas/schema_2021_07_15.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2021_04_06' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2022_03_09.ts b/src/endpoints/schemas/schema_2022_03_09.ts new file mode 100644 index 00000000..b70263ec --- /dev/null +++ b/src/endpoints/schemas/schema_2022_03_09.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2021_07_15' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/schemas/schema_2022_03_23.ts b/src/endpoints/schemas/schema_2022_03_23.ts new file mode 100644 index 00000000..840fabb4 --- /dev/null +++ b/src/endpoints/schemas/schema_2022_03_23.ts @@ -0,0 +1,5 @@ +import { Schema as BaseSchema } from './schema_2022_03_09' + +export interface Schema extends BaseSchema { + +} \ No newline at end of file diff --git a/src/endpoints/skills.js b/src/endpoints/skills.ts similarity index 62% rename from src/endpoints/skills.js rename to src/endpoints/skills.ts index de08f8f7..e8131ba2 100644 --- a/src/endpoints/skills.js +++ b/src/endpoints/skills.ts @@ -1,6 +1,5 @@ -const AbstractEndpoint = require('../endpoint') - -module.exports = class SkillsEndpoint extends AbstractEndpoint { +import { AbstractEndpoint } from '../endpoint' +export class SkillsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/skills' diff --git a/src/endpoints/skins.js b/src/endpoints/skins.ts similarity index 66% rename from src/endpoints/skins.js rename to src/endpoints/skins.ts index 8fdb33cc..0ef39061 100644 --- a/src/endpoints/skins.js +++ b/src/endpoints/skins.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class SkinsEndpoint extends AbstractEndpoint { +export class SkinsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/skins' diff --git a/src/endpoints/specializations.js b/src/endpoints/specializations.ts similarity index 62% rename from src/endpoints/specializations.js rename to src/endpoints/specializations.ts index 2826c079..94502655 100644 --- a/src/endpoints/specializations.js +++ b/src/endpoints/specializations.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class SpecializationsEndpoint extends AbstractEndpoint { +export class SpecializationsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/specializations' diff --git a/src/endpoints/stories.js b/src/endpoints/stories.ts similarity index 81% rename from src/endpoints/stories.js rename to src/endpoints/stories.ts index 746cfbeb..e22c4c95 100644 --- a/src/endpoints/stories.js +++ b/src/endpoints/stories.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class StoriesEndpoint extends AbstractEndpoint { +export class StoriesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/stories' diff --git a/src/endpoints/titles.js b/src/endpoints/titles.ts similarity index 62% rename from src/endpoints/titles.js rename to src/endpoints/titles.ts index 66006831..1061b36e 100644 --- a/src/endpoints/titles.js +++ b/src/endpoints/titles.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class TitlesEndpoint extends AbstractEndpoint { +export class TitlesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/titles' diff --git a/src/endpoints/tokeninfo.js b/src/endpoints/tokeninfo.ts similarity index 54% rename from src/endpoints/tokeninfo.js rename to src/endpoints/tokeninfo.ts index 6157f1da..8bff10a5 100644 --- a/src/endpoints/tokeninfo.js +++ b/src/endpoints/tokeninfo.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class TokeninfoEndpoint extends AbstractEndpoint { +export class TokeninfoEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/tokeninfo' diff --git a/src/endpoints/traits.js b/src/endpoints/traits.ts similarity index 62% rename from src/endpoints/traits.js rename to src/endpoints/traits.ts index a1f21676..a00fe305 100644 --- a/src/endpoints/traits.js +++ b/src/endpoints/traits.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class TraitsEndpoint extends AbstractEndpoint { +export class TraitsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/traits' diff --git a/src/endpoints/worldbosses.js b/src/endpoints/worldbosses.ts similarity index 62% rename from src/endpoints/worldbosses.js rename to src/endpoints/worldbosses.ts index 67d105c1..b4c2a8a4 100644 --- a/src/endpoints/worldbosses.js +++ b/src/endpoints/worldbosses.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class WorldbossesEndpoint extends AbstractEndpoint { +export class WorldbossesEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/worldbosses' diff --git a/src/endpoints/worlds.js b/src/endpoints/worlds.ts similarity index 62% rename from src/endpoints/worlds.js rename to src/endpoints/worlds.ts index 5ac78e8c..137d4c73 100644 --- a/src/endpoints/worlds.js +++ b/src/endpoints/worlds.ts @@ -1,6 +1,6 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' -module.exports = class WorldsEndpoint extends AbstractEndpoint { +export class WorldsEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/worlds' diff --git a/src/endpoints/wvw.js b/src/endpoints/wvw.ts similarity index 53% rename from src/endpoints/wvw.js rename to src/endpoints/wvw.ts index a21d5f8b..649920e8 100644 --- a/src/endpoints/wvw.js +++ b/src/endpoints/wvw.ts @@ -1,6 +1,78 @@ -const AbstractEndpoint = require('../endpoint') +import { AbstractEndpoint } from '../endpoint' +import { Schema } from './schemas/schema' + +type Team = 'red' | 'blue' | 'green' +type Top = 'kills' | 'kdr' + +namespace NA { + export type MatchupID = '1-1' | '1-2' | '1-3' | '1-4' + export enum WorldID { + AnvilRock = 1001, + BorlisPass = 1002, + YaksBend = 1003, + HengeOfDenravi = 1004, + Maguuma = 1005, + SorrowsFurnace = 1006, + GateOfMadness = 1007, + JadeQuarry = 1008, + FortAspendWood = 1009, + EhmryBay = 1010, + StormbluffIsle = 1011, + Darkhaven = 1012, + SanctumOfRall = 1013, + CrystalDesert = 1014, + IsleOfJanthir = 1015, + SeaOfSorrows = 1016, + TarnishedCoast = 1017, + NorthernShiverpeaks = 1018, + Blackgate = 1019, + FergusonsCrossing = 1020, + Dragonbrand = 1021, + Kaineng = 1022, + DevonasRest = 1023, + EredonsTerrace = 1024 + } +} + +namespace EU { + export type MatchupID = '2-1' | '2-2' | '2-3' | '2-4' + export enum WorldID { + FissureOfWoe = 2001, + Desolation = 2002, + Gandara = 2003, + Blacktide = 2004, + RingOfFire = 2005, + Underworld = 2006, + FarShiverpeaks = 2007, + WhitesideRidge = 2008, + RuinsOfSurmia = 2009, + SeafarersRest = 2010, + Vabbi = 2011, + PikenSquare = 2012, + AuroraGlade = 2013, + GunnarsHold = 2014, + JadeSea = 2101, + FortRanik = 2102, + AuguryRock = 2103, + VizunahSquare = 2104, + Arborstone = 2105, + Kodash = 2201, + Riverside = 2202, + ElonaReach = 2203, + AbaddonsMouth = 2204, + DrakkarLake = 2205, + MillersSound = 2206, + Dzagonur = 2207, + BaruchBay = 2301 + } +} + +type MatchupID = NA.MatchupID | EU.MatchupID +type WorldID = NA.WorldID | EU.WorldID + -module.exports = class WvwEndpoint extends AbstractEndpoint { + +export class WvwEndpoint extends AbstractEndpoint { abilities () { return new AbilitiesEndpoint(this) } @@ -33,6 +105,8 @@ class AbilitiesEndpoint extends AbstractEndpoint { } } +interface World {} + class MatchesEndpoint extends AbstractEndpoint { constructor (client) { super(client) @@ -42,7 +116,7 @@ class MatchesEndpoint extends AbstractEndpoint { this.cacheTime = 30 } - world (worldId) { + world (worldId: WorldID): Promise { return super.get(`?world=${worldId}`, true) } @@ -54,33 +128,38 @@ class MatchesEndpoint extends AbstractEndpoint { return new MatchesScoresEndpoint(this) } - stats (id) { + stats (id: MatchupID) { return new MatchesStatsEndpoint(this, id) } } class TeamsEndpoint extends AbstractEndpoint { - constructor (client, id, team) { + private team: Team + private id: MatchupID + + constructor (client, id: MatchupID, team: Team) { super(client) this.team = team this.id = id this.url = `/v2/wvw/matches/stats/${id}/teams` } - top (which) { + top (which: Top) { return new TopStatsEndpoint(this, this.id, this.team, which) } } class TopStatsEndpoint extends AbstractEndpoint { - constructor (client, id, team, which) { + private which: Top + + constructor (client, id: MatchupID, team: Team, which: Top) { super(client) this.which = which this.url = `/v2/wvw/matches/stats/${id}/teams/${team}/top/${which}` } } -class MatchesOverviewEndpoint extends AbstractEndpoint { +class MatchesOverviewEndpoint extends AbstractEndpoint { constructor (client) { super(client) this.url = '/v2/wvw/matches/overview' @@ -89,7 +168,7 @@ class MatchesOverviewEndpoint extends AbstractEndpoint { this.cacheTime = 30 } - world (worldId) { + public world (worldId: WorldID): Promise { return super.get(`?world=${worldId}`, true) } } @@ -103,13 +182,15 @@ class MatchesScoresEndpoint extends AbstractEndpoint { this.cacheTime = 30 } - world (worldId) { + public world (worldId: WorldID) { return super.get(`?world=${worldId}`, true) } } class MatchesStatsEndpoint extends AbstractEndpoint { - constructor (client, id) { + private id: MatchupID + + constructor (client, id: MatchupID) { super(client) this.id = id this.url = '/v2/wvw/matches/stats' @@ -118,11 +199,11 @@ class MatchesStatsEndpoint extends AbstractEndpoint { this.cacheTime = 30 } - world (worldId) { + public world (worldId: WorldID) { return super.get(`?world=${worldId}`, true) } - teams (team) { + public teams (team: Team) { return new TeamsEndpoint(this, this.id, team) } } diff --git a/src/flow.js b/src/flow.ts similarity index 80% rename from src/flow.js rename to src/flow.ts index ef510769..e0863993 100644 --- a/src/flow.js +++ b/src/flow.ts @@ -1,4 +1,5 @@ -async function parallel (promises) { +// FIXME: a bit handywavey... +export async function parallel (promises: Function): Promise { const results = await Promise.all( Object.values(promises).map(func => func()) ) @@ -15,5 +16,3 @@ async function parallel (promises) { return object }, {}) } - -module.exports = { parallel } diff --git a/src/hash.js b/src/hash.ts similarity index 65% rename from src/hash.js rename to src/hash.ts index 84b80503..c3097157 100644 --- a/src/hash.js +++ b/src/hash.ts @@ -1,13 +1,11 @@ const emotionHash = require('@emotion/hash/dist/hash.browser.cjs.js').default -let cache = {} +const cache: {[key: string]: string} = {} -function hash (string) { +export function hash (string: string): string { if (!cache[string]) { cache[string] = emotionHash(string) } return cache[string] } - -module.exports = hash diff --git a/src/helpers/resetTime.js b/src/helpers/resetTime.ts similarity index 79% rename from src/helpers/resetTime.js rename to src/helpers/resetTime.ts index 59d50ee8..1f0dbcce 100644 --- a/src/helpers/resetTime.js +++ b/src/helpers/resetTime.ts @@ -1,21 +1,21 @@ const DAY_MS = 24 * 60 * 60 * 1000 -function getDateAtTime (date, time) { +export function getDateAtTime (date: Date, time: string): Date { return new Date(date.toISOString().replace(/T.*Z/, `T${time}.000Z`)) } -function getDailyReset (date) { +export function getDailyReset (date: Date): Date { date = date ? new Date(date) : new Date() date = new Date(date.getTime() + DAY_MS) return getDateAtTime(date, '00:00:00') } -function getLastDailyReset (date) { +export function getLastDailyReset (date: Date): Date { return new Date(getDailyReset(date).getTime() - DAY_MS) } -function getWeeklyReset (date) { +export function getWeeklyReset (date: Date): Date { date = date ? new Date(date) : new Date() const weekday = date.getUTCDay() @@ -48,14 +48,6 @@ function getWeeklyReset (date) { return getDateAtTime(date, '07:30:00') } -function getLastWeeklyReset (date) { +export function getLastWeeklyReset (date: Date): Date { return new Date(getWeeklyReset(date).getTime() - 7 * DAY_MS) -} - -module.exports = { - getDateAtTime, - getDailyReset, - getLastDailyReset, - getWeeklyReset, - getLastWeeklyReset -} +} \ No newline at end of file diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..4a838f24 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,25 @@ +export type ItemID = number + +export type URL = string +export type ISO8601 = string + +export type Coordinate = [number, number] +export type Coordinate3 = [number, number, number] + +export type Attribute = 'AgonyResistance' | 'BoonDuration' | 'ConditionDamage' | 'ConditionDuration' | 'CritDamage' | 'Healing' | 'Power' | 'Precision' | 'Toughness' | 'Vitality' +export type Language = 'en' | 'de' | 'es' | 'fr' +export type Gender = 'Male' | 'Female' +export type Race = 'Human' | 'Norn' | 'Charr' | 'Sylvari' | 'Asura' +export type Profession = 'Guardian' | 'Revenant' | 'Warrior' | 'Engineer' | 'Ranger' | 'Thief' | 'Elementalist' | 'Mesmer' | 'Necromancer' +export type Discipline = 'Armorsmith' | 'Artificer' | 'Chef' | 'Huntsman' | 'Jeweler' | 'Leatherworker' | 'Scribe' | 'Tailor' | 'Weaponsmith' +export type Region = 'Tyria' | 'Maguuma' | 'Desert' | 'Tundra' +export type Rarity = 'Junk' | 'Basic' | 'Fine' | 'Masterwork' | 'Rare' | 'Exotic' | 'Ascended' | 'Legendary' +export type Weapon = 'Axe' | 'Dagger' | 'Mace' | 'Pistol' | 'Sword' | 'Scepter' | 'Focus' | 'Shield' | 'Torch' | 'Warhorn' | 'Greatsword' | 'Hammer' | 'Longbow' | 'Rifle' | 'Shortbow' | 'Staff' | 'Speargun' | 'Spear' | 'Trident' | 'LargeBundle' | 'SmallBundle' | 'Toy' | 'ToyTwoHanded' +export type Attunement = 'Fire' | 'Water' | 'Wind' | 'Earth' +export type WeaponSlot = 'Weapon_1' +export type Trinket = 'Accessory' | 'Amulet' | 'Ring' +export type ArmorSlot = 'Coat' | 'Boots' | 'Gloves' | 'Helm' | 'Leggings' | 'Shoulders' | 'HelmAquatic' +export type EquipmentSlot = ArmorSlot | 'Backpack' | 'Accessory1' | 'Accessory2' | 'Ring1' | 'Ring2' | 'Amulet' | 'WeaponAquaticA' | 'WeaponAquaticB' | 'WeaponA1' | 'WeaponA2' | 'WeaponB1' | 'WeaponB2' | 'Sickle' | 'Axe' | 'Pick' +export type ColorMaterial = 'cloth' | 'metal' | 'leather' | 'fur' +export type WeightClass = 'Heavy' | 'Medium' | 'Light' | 'Clothing' +export type DamageType = 'Fire' | 'Ice' | 'Lightning' | 'Physical' | 'Choking' \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..afbeb492 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "allowJs": true, + "target": "es6" + }, + "include": ["./src/**/*"] + } \ No newline at end of file