|
| 1 | +import { |
| 2 | + CharacterGetParams, |
| 3 | + CharacterGetResult, |
| 4 | + CharacterSearchParams, |
| 5 | + CharacterSearchResult, |
| 6 | + FreeCompanyGetParams, |
| 7 | + FreeCompanyGetResult, |
| 8 | + FreeCompanySearchParams, |
| 9 | + FreeCompanySearchResult, |
| 10 | + LinkshellGetResult, |
| 11 | + LinkshellSearchParams, |
| 12 | + LinkshellSearchResult, |
| 13 | + PvPTeamGetResult, |
| 14 | + PvPTeamSearchParams, |
| 15 | + PvPTeamSearchResult, |
| 16 | + SearchIndexResult, |
| 17 | + SearchIndexes, |
| 18 | + SearchResult, |
| 19 | +} from "./utils"; |
| 20 | +export * from "./utils"; |
| 21 | + |
| 22 | +declare module "@xivapi/js" { |
| 23 | + type StringAlgo = |
| 24 | + | "custom" |
| 25 | + | "wildcard" |
| 26 | + | "wildcard_plus" |
| 27 | + | "fuzzy" |
| 28 | + | "term" |
| 29 | + | "prefix" |
| 30 | + | "match" |
| 31 | + | "match_phrase" |
| 32 | + | "match_phrase_prefix" |
| 33 | + | "multi_match" |
| 34 | + | "query_string"; |
| 35 | + |
| 36 | + interface XIVAPIOptions { |
| 37 | + private_key?: string; |
| 38 | + language?: "en" | "de" | "fr" | "ja" | "cn" | "ko"; |
| 39 | + snake_case?: boolean; |
| 40 | + staging?: boolean; |
| 41 | + verbose?: boolean; |
| 42 | + } |
| 43 | + |
| 44 | + interface DataSearchParams { |
| 45 | + /** |
| 46 | + * Search a specific series of indexes separated by commas. |
| 47 | + */ |
| 48 | + indexes: SearchIndexes[]; |
| 49 | + |
| 50 | + /** |
| 51 | + * Search for lore! This is a special built search endpoint which searches a string through various lore specific content. |
| 52 | + * @see https://xivapi.com/docs/Search#lore |
| 53 | + */ |
| 54 | + lore?: boolean; |
| 55 | + |
| 56 | + /** |
| 57 | + * The column to use in string searches. |
| 58 | + * @see https://xivapi.com/docs/Search#filters |
| 59 | + */ |
| 60 | + filters?: string | string[]; |
| 61 | + |
| 62 | + /** |
| 63 | + * The search algorithm to use for string matching. |
| 64 | + * @default "wildcard" |
| 65 | + * @see https://xivapi.com/docs/Search |
| 66 | + */ |
| 67 | + string_algo?: StringAlgo; |
| 68 | + |
| 69 | + /** |
| 70 | + * The column to use in string searches. |
| 71 | + */ |
| 72 | + string_column?: string; |
| 73 | + |
| 74 | + /** |
| 75 | + * Limit the number of results to show. (from 1 to 100) |
| 76 | + */ |
| 77 | + limit?: number; |
| 78 | + } |
| 79 | + |
| 80 | + export default class XIVAPI { |
| 81 | + private readonly options: XIVAPIOptions; |
| 82 | + private readonly endpoint: string; |
| 83 | + private readonly globalParams: { [key: string]: string | number }; |
| 84 | + |
| 85 | + constructor(options: string | XIVAPIOptions); |
| 86 | + constructor(options: string | XIVAPIOptions, legacyOptions?: XIVAPIOptions); |
| 87 | + |
| 88 | + /** |
| 89 | + * XIVAPI provides the ability to quickly search all game content via Elasticsearch. |
| 90 | + * This search endpoint only searches game content and not: characters, free companies, linkshells or pvp teams. |
| 91 | + * Those have their own dedicated search endpoints as they relay to Lodestone. |
| 92 | + * @since 0.4.2 |
| 93 | + * @see https://xivapi.com/docs/Search |
| 94 | + * @example |
| 95 | + * ```ts |
| 96 | + * const xiv = new XIVAPI(); |
| 97 | + * await xiv.search("aiming"); // without params |
| 98 | + * await xiv.search("aiming", { indexes: ["Item", "Recipe"] }); // with params |
| 99 | + * ``` |
| 100 | + */ |
| 101 | + public search( |
| 102 | + input: keyof typeof SearchIndexes, |
| 103 | + params?: DataSearchParams |
| 104 | + ): Promise<SearchIndexResult>; |
| 105 | + |
| 106 | + /** |
| 107 | + * Obtain game content data of Final Fantasy XIV. |
| 108 | + * @since 0.4.2 |
| 109 | + * @see https://xivapi.com/docs/Game-Data |
| 110 | + */ |
| 111 | + public data: { |
| 112 | + /** |
| 113 | + * Returns information about a specific object including extended information. |
| 114 | + * @since 0.4.2 |
| 115 | + * @see https://xivapi.com/docs/Game-Data |
| 116 | + * @example |
| 117 | + * ```ts |
| 118 | + * const xiv = new XIVAPI(); |
| 119 | + * await xiv.data.get("Item", 1673); |
| 120 | + * ``` |
| 121 | + */ |
| 122 | + get: (name: string, id: string | number) => Promise<{ [key: string]: any }>; |
| 123 | + |
| 124 | + /** |
| 125 | + * Obtain game content data of Final Fantasy XIV. |
| 126 | + * @since 0.4.2 |
| 127 | + * @see https://xivapi.com/docs/Game-Data |
| 128 | + * @example |
| 129 | + * ```ts |
| 130 | + * const xiv = new XIVAPI(); |
| 131 | + * await xiv.data.list("Item", { limit: 100 }); // with limit param |
| 132 | + * await xiv.data.list("Item", { ids: [1673, 1674] }); // with ids param |
| 133 | + * ``` |
| 134 | + */ |
| 135 | + list: ( |
| 136 | + name: keyof typeof SearchIndexes, |
| 137 | + params?: { |
| 138 | + /** |
| 139 | + * Limit the number of items returned by the API. |
| 140 | + * @min 100 |
| 141 | + * @max 3000 |
| 142 | + */ |
| 143 | + limit?: number; |
| 144 | + |
| 145 | + /** |
| 146 | + * Filter the ids down if you want data for a specific series of items. |
| 147 | + */ |
| 148 | + ids?: number[]; |
| 149 | + } |
| 150 | + ) => Promise<SearchIndexResult>; |
| 151 | + |
| 152 | + /** |
| 153 | + * Returns information about a specific object including extended information. |
| 154 | + * @since 0.4.2 |
| 155 | + * @see https://xivapi.com/docs/Game-Data#servers |
| 156 | + */ |
| 157 | + servers: () => Promise<string[]>; |
| 158 | + |
| 159 | + /** |
| 160 | + * Another list of servers grouped by their data center. |
| 161 | + * @since 0.4.2 |
| 162 | + * @see https://xivapi.com/docs/Game-Data#data-center |
| 163 | + */ |
| 164 | + datacenters: () => Promise<{ [key: string]: string[] }>; |
| 165 | + }; |
| 166 | + |
| 167 | + /** |
| 168 | + * Search and retrieve character data from The Lodestone. Providing useful information such as character profile data, minions and mounts obtained, achievements obtained and their relative dates. Character friends, their free company, pvp team and much more! |
| 169 | + * @since 0.4.2 |
| 170 | + * @see https://xivapi.com/docs/Character |
| 171 | + */ |
| 172 | + public character: { |
| 173 | + search: (name: string, params?: CharacterSearchParams) => Promise<CharacterSearchResult>; |
| 174 | + get: (id: string | number, params?: CharacterGetParams) => Promise<CharacterGetResult>; |
| 175 | + }; |
| 176 | + |
| 177 | + /** |
| 178 | + * Search and retrieve Free Company data from The Lodestone, provides useful information such as profile information and member lists. |
| 179 | + * @since 0.4.2 |
| 180 | + * @see https://xivapi.com/docs/Free-Company |
| 181 | + */ |
| 182 | + public freecompany: { |
| 183 | + search: (name: string, params?: FreeCompanySearchParams) => Promise<FreeCompanySearchResult>; |
| 184 | + get: (id: string | number, params?: FreeCompanyGetParams) => Promise<FreeCompanyGetResult>; |
| 185 | + }; |
| 186 | + |
| 187 | + /** |
| 188 | + * Search and retrieve Linkshell data from The Lodestone. |
| 189 | + * @since 0.4.2 |
| 190 | + * @see https://xivapi.com/docs/Linkshell |
| 191 | + */ |
| 192 | + public linkshell: { |
| 193 | + search: (name: string, params?: LinkshellSearchParams) => Promise<LinkshellSearchResult>; |
| 194 | + get: (id: string | number) => Promise<LinkshellGetResult>; |
| 195 | + }; |
| 196 | + |
| 197 | + /** |
| 198 | + * Search and retrieve PVP Team data from The Lodestone. |
| 199 | + * @since 0.4.2 |
| 200 | + * @see https://xivapi.com/docs/PvP-Team |
| 201 | + */ |
| 202 | + public pvpteam: { |
| 203 | + search: (name: string, params?: PvPTeamSearchParams) => Promise<PvPTeamSearchResult>; |
| 204 | + get: (id: string | number) => Promise<PvPTeamGetResult>; |
| 205 | + }; |
| 206 | + } |
| 207 | +} |
0 commit comments