Skip to content

Commit 005de52

Browse files
authored
Merge pull request #16 from c0reme/master
feat: add typescript support
2 parents 690b715 + 856ccd9 commit 005de52

File tree

10 files changed

+837
-1
lines changed

10 files changed

+837
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
"bugs": {
2727
"url": "https://github.com/xivapi/xivapi-js/issues"
2828
},
29-
"homepage": "https://github.com/xivapi/xivapi-js#readme"
29+
"homepage": "https://github.com/xivapi/xivapi-js#readme",
30+
"types": "./typings/index.d.ts"
3031
}

typings/index.d.ts

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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+
}

typings/utils/achievements.d.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { GamePatchData, ItemData, TitleData } from "./item";
2+
import { SearchResult } from "./search";
3+
4+
export interface AchievementsData {
5+
List: { Date: number; ID: number }[];
6+
Points: number;
7+
}
8+
9+
export interface AchievementCategoryData {
10+
AchievementsKind: {
11+
ID: number;
12+
Name: string;
13+
Name_de: string;
14+
Name_en: string;
15+
Name_fr: string;
16+
Name_ja: string;
17+
Order: number;
18+
};
19+
AchievementKindTarget: string;
20+
AchievementKindTargetID: number;
21+
HideCategory: number;
22+
ID: number;
23+
Name: string;
24+
Name_de: string;
25+
Name_en: string;
26+
Name_fr: string;
27+
Name_ja: string;
28+
Order: number;
29+
ShowComplete: number;
30+
}
31+
32+
export interface AchievementGetResult {
33+
AchievementCategory: AchievementCategoryData;
34+
AchievementCategoryTarget: string;
35+
AchievementCategoryTargetID: number;
36+
AchievementHideCondition: string | null;
37+
AchievementHideConditionTarget: string;
38+
AchievementHideConditionTargetID: number;
39+
AchievementTarget: { ID: number; Type: 1; Value: number } | null;
40+
AchievementTargetID: number | null;
41+
ClassJobRequirements: {}[];
42+
Data0: number;
43+
Data1: number;
44+
Data2: number;
45+
Data3: number;
46+
Data4: number;
47+
Data5: number;
48+
Data6: number;
49+
Data7: number;
50+
Description: string;
51+
Description_de: string;
52+
Description_en: string;
53+
Description_fr: string;
54+
Description_ja: string;
55+
GameContentLinks: [];
56+
GamePatch: GamePatchData;
57+
ID: number;
58+
Icon: string;
59+
IconHD: string;
60+
ItemID: number;
61+
Item: ItemData | null;
62+
ItemTarget: string;
63+
ItemTargetID: number;
64+
Key: number;
65+
Name: string;
66+
Name_de: string;
67+
Name_en: string;
68+
Name_fr: string;
69+
Name_ja: string;
70+
Order: number;
71+
Patch: number | null;
72+
Points: number;
73+
PostAchievements: [];
74+
PreAchievements: [];
75+
QuestRequirements: {}[];
76+
QuestRequirementsAll: boolean;
77+
Title: TitleData | null;
78+
TitleTarget: string;
79+
TitleTargetID: number;
80+
Type: number;
81+
Url: string;
82+
}

0 commit comments

Comments
 (0)