Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
169 lines (151 loc) · 6.31 KB
/
Copy pathindex.d.ts
File metadata and controls
169 lines (151 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Types for the Xproapi Node.js client. Field names follow the API's JSON exactly.
export const DEFAULT_BASE_URL: string;
export const VERSION: string;
export interface User {
type: 'user';
id: string;
userName: string;
name: string;
url: string;
description: string;
profilePicture: string | null;
followers: number;
following: number;
isBlueVerified: boolean;
protected: boolean;
unavailable: boolean;
}
export interface Tweet {
type: 'tweet';
id: string;
url: string;
text: string;
source: string;
retweetCount: number;
replyCount: number;
likeCount: number;
quoteCount: number;
viewCount: number;
bookmarkCount: number;
createdAt: string;
lang: string;
isReply: boolean;
inReplyToId: string | null;
conversationId: string | null;
displayTextRange: number[] | null;
inReplyToUserId: string | null;
inReplyToUsername: string | null;
author: User;
entities: Record<string, unknown>;
extendedEntities: Record<string, unknown>;
quoted_tweet: Tweet | null;
retweeted_tweet: Tweet | null;
isLimitedReply: boolean;
}
export interface Article {
author: User;
replyCount: number;
likeCount: number;
quoteCount: number;
viewCount: number;
createdAt: string;
title: string;
preview_text: string;
cover_media_img_url: string | null;
contents: unknown[];
}
interface Envelope {
status: 'success';
message?: string;
msg?: string;
}
interface Paged {
has_next_page: boolean;
/** Pass back as `cursor` for the next page; empty on the last page. */
next_cursor: string;
}
export type UserResponse = Envelope & { data: User };
export type UsersResponse = Envelope & { users: User[] };
export type UsersPage = UsersResponse & Paged;
export type FollowersPage = Envelope & Paged & { followers: User[] };
export type FollowingsPage = Envelope & Paged & { followings: User[] };
export type TweetsResponse = Envelope & { tweets: Tweet[] };
export type TweetsPage = TweetsResponse & Paged;
export type RepliesPage = Envelope & Paged & { replies: Tweet[] };
export type ArticleResponse = Envelope & { article: Article };
export type AboutResponse = Envelope & { data: Record<string, unknown> };
export interface ClientOptions {
/** From your panel → API → API keys. */
apiKey: string;
/** Defaults to https://xproapi.com/api. */
baseUrl?: string;
/** Milliseconds per request (default 30000). */
timeout?: number;
/** Retries for 429 / 502 / 503 / network errors (default 2, 0 = never). */
maxRetries?: number;
fetch?: typeof fetch;
sleep?: (ms: number) => Promise<void>;
}
type Cursor = { cursor?: string };
type TimeRange = { sinceTime?: number; untilTime?: number };
type Tweeter = { userName: string; userId?: never } | { userId: string; userName?: never };
export interface PaginatedEndpoints {
searchUsers: [{ query: string }, User];
followers: [{ userName: string; pageSize?: number }, User];
followings: [{ userName: string; pageSize?: number }, User];
lastTweets: [Tweeter & { includeReplies?: boolean }, Tweet];
tweetTimeline: [Tweeter & { includeReplies?: boolean; includeParentTweet?: boolean }, Tweet];
mentions: [{ userName: string } & TimeRange, Tweet];
advancedSearch: [{ query: string; queryType?: 'Latest' | 'Top' }, Tweet];
replies: [{ tweetId: string } & TimeRange, Tweet];
repliesV2: [{ tweetId: string; queryType?: 'Relevance' | 'Latest' | 'Likes' }, Tweet];
quotes: [{ tweetId: string; includeReplies?: boolean } & TimeRange, Tweet];
retweeters: [{ tweetId: string }, User];
threadContext: [{ tweetId: string }, Tweet];
}
export class Xproapi {
constructor(options: ClientOptions);
/** Rate limit of the last response: your per-minute limit and requests left this minute. */
rateLimit: { limit: number | null; remaining: number | null };
userInfo(userName: string): Promise<UserResponse>;
batchUserInfoByUsernames(userNames: string[]): Promise<UsersResponse>;
userAbout(userName: string): Promise<AboutResponse>;
searchUsers(query: string, options?: Cursor): Promise<UsersPage>;
followers(userName: string, options?: Cursor & { pageSize?: number }): Promise<FollowersPage>;
followings(userName: string, options?: Cursor & { pageSize?: number }): Promise<FollowingsPage>;
lastTweets(options: Tweeter & Cursor & { includeReplies?: boolean }): Promise<TweetsPage>;
tweetTimeline(options: Tweeter & Cursor & { includeReplies?: boolean; includeParentTweet?: boolean }): Promise<TweetsPage>;
mentions(userName: string, options?: Cursor & TimeRange): Promise<TweetsPage>;
tweetsByIds(tweetIds: string[]): Promise<TweetsResponse>;
advancedSearch(query: string, options?: Cursor & { queryType?: 'Latest' | 'Top' }): Promise<TweetsPage>;
replies(tweetId: string, options?: Cursor & TimeRange): Promise<RepliesPage>;
repliesV2(tweetId: string, options?: Cursor & { queryType?: 'Relevance' | 'Latest' | 'Likes' }): Promise<TweetsPage>;
quotes(tweetId: string, options?: Cursor & TimeRange & { includeReplies?: boolean }): Promise<TweetsPage>;
retweeters(tweetId: string, options?: Cursor): Promise<UsersPage>;
threadContext(tweetId: string, options?: Cursor): Promise<RepliesPage>;
article(tweetId: string): Promise<ArticleResponse>;
/** Every item of a paginated endpoint, following next_cursor. Each page is a separate (charged) request. */
paginate<E extends keyof PaginatedEndpoints>(
endpoint: E,
params: PaginatedEndpoints[E][0],
options?: { maxPages?: number },
): AsyncGenerator<PaginatedEndpoints[E][1], void, undefined>;
/** Any GET endpoint under the base URL. */
get<T = Record<string, unknown>>(path: string, params?: Record<string, string | number | boolean | null | undefined>): Promise<T>;
}
export default Xproapi;
export class XproapiError extends Error {
/** HTTP status (0 for network errors). */
status: number;
/** The decoded JSON error body, when there was one. */
body: { status: 'error'; error: number; message: string } | null;
/** Seconds to wait before retrying (429 only). */
retryAfter: number | null;
}
export class BadRequestError extends XproapiError {}
export class AuthenticationError extends XproapiError {}
export class InsufficientCreditsError extends XproapiError {}
export class PermissionDeniedError extends XproapiError {}
export class NotFoundError extends XproapiError {}
export class RateLimitError extends XproapiError {}
export class ServiceUnavailableError extends XproapiError {}