twitter-openapi-typescript 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api.d.ts +2 -0
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/api.js +5 -1
- package/dist/src/api.js.map +1 -1
- package/dist/src/apis/defaultApi.d.ts.map +1 -1
- package/dist/src/apis/defaultApi.js +9 -13
- package/dist/src/apis/defaultApi.js.map +1 -1
- package/dist/src/apis/index.d.ts +1 -0
- package/dist/src/apis/index.d.ts.map +1 -1
- package/dist/src/apis/index.js +3 -1
- package/dist/src/apis/index.js.map +1 -1
- package/dist/src/apis/postApi.d.ts.map +1 -1
- package/dist/src/apis/postApi.js +54 -48
- package/dist/src/apis/postApi.js.map +1 -1
- package/dist/src/apis/tweetApi.d.ts +13 -12
- package/dist/src/apis/tweetApi.d.ts.map +1 -1
- package/dist/src/apis/tweetApi.js +20 -21
- package/dist/src/apis/tweetApi.js.map +1 -1
- package/dist/src/apis/userApi.d.ts +5 -12
- package/dist/src/apis/userApi.d.ts.map +1 -1
- package/dist/src/apis/userApi.js +14 -58
- package/dist/src/apis/userApi.js.map +1 -1
- package/dist/src/apis/userListApi.d.ts +8 -7
- package/dist/src/apis/userListApi.d.ts.map +1 -1
- package/dist/src/apis/userListApi.js +23 -24
- package/dist/src/apis/userListApi.js.map +1 -1
- package/dist/src/apis/usersApi.d.ts +18 -0
- package/dist/src/apis/usersApi.d.ts.map +1 -0
- package/dist/src/apis/usersApi.js +101 -0
- package/dist/src/apis/usersApi.js.map +1 -0
- package/dist/src/models/header.d.ts +5 -5
- package/dist/src/models/header.d.ts.map +1 -1
- package/dist/src/models/index.d.ts +0 -3
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +0 -3
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/models/timeline.d.ts +18 -1
- package/dist/src/models/timeline.d.ts.map +1 -1
- package/dist/src/models/utils.d.ts +3 -10
- package/dist/src/models/utils.d.ts.map +1 -1
- package/dist/src/utils/api.d.ts +9 -2
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js +72 -18
- package/dist/src/utils/api.js.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +6 -1
- package/src/apis/defaultApi.ts +5 -13
- package/src/apis/index.ts +1 -0
- package/src/apis/postApi.ts +9 -7
- package/src/apis/tweetApi.ts +36 -33
- package/src/apis/userApi.ts +15 -56
- package/src/apis/userListApi.ts +44 -31
- package/src/apis/usersApi.ts +48 -0
- package/src/models/header.ts +5 -5
- package/src/models/index.ts +0 -3
- package/src/models/timeline.ts +21 -1
- package/src/models/utils.ts +3 -11
- package/src/utils/api.ts +59 -19
- package/test/api/tweetApi.test.ts +10 -10
- package/test/api/userApi.test.ts +10 -5
- package/test/api/userListApi.test.ts +5 -5
- package/test/api/usersApi.test.ts +12 -0
- package/test/util.ts +19 -8
- package/dist/src/models/tweet.d.ts +0 -18
- package/dist/src/models/tweet.d.ts.map +0 -1
- package/dist/src/models/tweet.js +0 -3
- package/dist/src/models/tweet.js.map +0 -1
- package/dist/src/models/user.d.ts +0 -16
- package/dist/src/models/user.d.ts.map +0 -1
- package/dist/src/models/user.js +0 -3
- package/dist/src/models/user.js.map +0 -1
- package/dist/src/models/user_list.d.ts +0 -13
- package/dist/src/models/user_list.d.ts.map +0 -1
- package/dist/src/models/user_list.js +0 -3
- package/dist/src/models/user_list.js.map +0 -1
- package/src/models/tweet.ts +0 -19
- package/src/models/user.ts +0 -17
- package/src/models/user_list.ts +0 -14
package/src/apis/userListApi.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
RequestParam,
|
|
4
|
+
DefaultFlag,
|
|
5
|
+
ApiUtilsRaw,
|
|
6
|
+
TimelineApiUtilsResponse,
|
|
7
|
+
TwitterApiUtilsResponse,
|
|
8
|
+
UserApiUtilsData,
|
|
9
|
+
TwitterApiUtilsRaw,
|
|
10
|
+
} from '@/models';
|
|
11
|
+
import {
|
|
12
|
+
buildHeader,
|
|
13
|
+
userResultConverter,
|
|
14
|
+
entriesCursor,
|
|
15
|
+
instructionToEntry,
|
|
16
|
+
userEntriesConverter,
|
|
17
|
+
getKwargs,
|
|
18
|
+
errorCheck,
|
|
19
|
+
} from '@/utils';
|
|
4
20
|
|
|
5
21
|
type GetFollowersParam = {
|
|
6
22
|
userId: string;
|
|
@@ -37,6 +53,8 @@ type GetRetweetersParam = {
|
|
|
37
53
|
extraParam?: { [key: string]: any };
|
|
38
54
|
};
|
|
39
55
|
|
|
56
|
+
type ResponseType = TwitterApiUtilsResponse<TimelineApiUtilsResponse<UserApiUtilsData>>;
|
|
57
|
+
|
|
40
58
|
export class UserListApiUtils {
|
|
41
59
|
api: i.UserListApi;
|
|
42
60
|
flag: DefaultFlag;
|
|
@@ -46,38 +64,33 @@ export class UserListApiUtils {
|
|
|
46
64
|
this.flag = flag;
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
async request<T>(param: RequestParam<i.InstructionUnion[], T>): Promise<
|
|
67
|
+
async request<T>(param: RequestParam<i.InstructionUnion[], T>): Promise<ResponseType> {
|
|
50
68
|
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const response = await apiFn({
|
|
56
|
-
pathQueryId: this.flag[param.key]['queryId'],
|
|
57
|
-
queryId: this.flag[param.key]['queryId'],
|
|
58
|
-
variables: JSON.stringify({ ...this.flag[param.key]['variables'], ...param.param }),
|
|
59
|
-
features: JSON.stringify(this.flag[param.key]['features']),
|
|
60
|
-
...fieldTogglesFn(),
|
|
61
|
-
});
|
|
62
|
-
const instruction = param.convertFn(await response.value());
|
|
69
|
+
const args = getKwargs(this.flag[param.key], param.param);
|
|
70
|
+
const response = await apiFn(args);
|
|
71
|
+
const checked = errorCheck(await response.value());
|
|
72
|
+
const instruction = param.convertFn(checked);
|
|
63
73
|
const entry = instructionToEntry(instruction);
|
|
64
74
|
const userList = userEntriesConverter(entry);
|
|
65
|
-
const data = userList
|
|
75
|
+
const data = userResultConverter(userList);
|
|
66
76
|
|
|
67
|
-
const raw: ApiUtilsRaw = {
|
|
68
|
-
response: response.raw,
|
|
69
|
-
instruction: instruction,
|
|
70
|
-
entry: entry,
|
|
71
|
-
};
|
|
72
77
|
return {
|
|
73
|
-
raw:
|
|
78
|
+
raw: {
|
|
79
|
+
response: response.raw,
|
|
80
|
+
},
|
|
74
81
|
header: buildHeader(response.raw.headers),
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
data: {
|
|
83
|
+
raw: {
|
|
84
|
+
instruction: instruction,
|
|
85
|
+
entry: entry,
|
|
86
|
+
},
|
|
87
|
+
data: data,
|
|
88
|
+
cursor: entriesCursor(entry),
|
|
89
|
+
},
|
|
77
90
|
};
|
|
78
91
|
}
|
|
79
92
|
|
|
80
|
-
async getFollowers(param: GetFollowersParam): Promise<
|
|
93
|
+
async getFollowers(param: GetFollowersParam): Promise<ResponseType> {
|
|
81
94
|
const args = {
|
|
82
95
|
userId: param.userId,
|
|
83
96
|
...(param.cursor == null ? {} : { cursor: param.cursor }),
|
|
@@ -92,7 +105,7 @@ export class UserListApiUtils {
|
|
|
92
105
|
});
|
|
93
106
|
return response;
|
|
94
107
|
}
|
|
95
|
-
async getFollowing(param: GetFollowingParam): Promise<
|
|
108
|
+
async getFollowing(param: GetFollowingParam): Promise<ResponseType> {
|
|
96
109
|
const args = {
|
|
97
110
|
userId: param.userId,
|
|
98
111
|
...(param.cursor == null ? {} : { cursor: param.cursor }),
|
|
@@ -108,7 +121,7 @@ export class UserListApiUtils {
|
|
|
108
121
|
return response;
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
async getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<
|
|
124
|
+
async getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<ResponseType> {
|
|
112
125
|
const args = {
|
|
113
126
|
userId: param.userId,
|
|
114
127
|
...(param.cursor == null ? {} : { cursor: param.cursor }),
|
|
@@ -124,7 +137,7 @@ export class UserListApiUtils {
|
|
|
124
137
|
return response;
|
|
125
138
|
}
|
|
126
139
|
|
|
127
|
-
async getFavoriters(param: GetFavoritersParam): Promise<
|
|
140
|
+
async getFavoriters(param: GetFavoritersParam): Promise<ResponseType> {
|
|
128
141
|
const args = {
|
|
129
142
|
tweetId: param.tweetId,
|
|
130
143
|
...(param.cursor == null ? {} : { cursor: param.cursor }),
|
|
@@ -132,7 +145,7 @@ export class UserListApiUtils {
|
|
|
132
145
|
...param.extraParam,
|
|
133
146
|
};
|
|
134
147
|
const response = await this.request({
|
|
135
|
-
apiFn: this.api.
|
|
148
|
+
apiFn: this.api.getFavoritersRaw,
|
|
136
149
|
convertFn: (e) => e.data.favoritersTimeline.timeline.instructions,
|
|
137
150
|
key: 'Favoriters',
|
|
138
151
|
param: args,
|
|
@@ -140,7 +153,7 @@ export class UserListApiUtils {
|
|
|
140
153
|
return response;
|
|
141
154
|
}
|
|
142
155
|
|
|
143
|
-
async getRetweeters(param: GetRetweetersParam): Promise<
|
|
156
|
+
async getRetweeters(param: GetRetweetersParam): Promise<ResponseType> {
|
|
144
157
|
const args = {
|
|
145
158
|
tweetId: param.tweetId,
|
|
146
159
|
...(param.cursor == null ? {} : { cursor: param.cursor }),
|
|
@@ -148,7 +161,7 @@ export class UserListApiUtils {
|
|
|
148
161
|
...param.extraParam,
|
|
149
162
|
};
|
|
150
163
|
const response = await this.request({
|
|
151
|
-
apiFn: this.api.
|
|
164
|
+
apiFn: this.api.getRetweetersRaw,
|
|
152
165
|
convertFn: (e) => e.data.retweetersTimeline.timeline.instructions,
|
|
153
166
|
key: 'Retweeters',
|
|
154
167
|
param: args,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { RequestParam, DefaultFlag, UserApiUtilsData, TwitterApiUtilsResponse } from '@/models';
|
|
3
|
+
import { buildHeader, errorCheck, getKwargs, userOrNullConverter, userResultConverter } from '@/utils';
|
|
4
|
+
|
|
5
|
+
type getUsersByRestIdsParam = {
|
|
6
|
+
userIds: string[];
|
|
7
|
+
extraParam?: { [key: string]: any };
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type ResponseType = TwitterApiUtilsResponse<UserApiUtilsData[]>;
|
|
11
|
+
|
|
12
|
+
export class UsersApiUtils {
|
|
13
|
+
api: i.UsersApi;
|
|
14
|
+
flag: DefaultFlag;
|
|
15
|
+
|
|
16
|
+
constructor(api: i.UsersApi, flag: DefaultFlag) {
|
|
17
|
+
this.api = api;
|
|
18
|
+
this.flag = flag;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async request<T>(param: RequestParam<i.UserResults[], T>): Promise<ResponseType> {
|
|
22
|
+
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
23
|
+
const args = getKwargs(this.flag[param.key], param.param);
|
|
24
|
+
const response = await apiFn(args);
|
|
25
|
+
const checked = errorCheck(await response.value());
|
|
26
|
+
const result = param.convertFn(checked);
|
|
27
|
+
const user = userResultConverter(result);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
raw: { response: response.raw },
|
|
31
|
+
header: buildHeader(response.raw.headers),
|
|
32
|
+
data: user,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async getUsersByRestIds(param: getUsersByRestIdsParam): Promise<ResponseType> {
|
|
36
|
+
const args = {
|
|
37
|
+
userIds: param.userIds,
|
|
38
|
+
...param.extraParam,
|
|
39
|
+
};
|
|
40
|
+
const response = this.request({
|
|
41
|
+
key: 'UsersByRestIds',
|
|
42
|
+
apiFn: this.api.getUsersByRestIdsRaw,
|
|
43
|
+
convertFn: (e) => e.data.users,
|
|
44
|
+
param: args,
|
|
45
|
+
});
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/models/header.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export type ApiUtilsHeader = {
|
|
2
2
|
raw: Headers;
|
|
3
|
-
connectionHash: string
|
|
4
|
-
contentTypeOptions: string
|
|
5
|
-
frameOptions: string
|
|
3
|
+
connectionHash: string;
|
|
4
|
+
contentTypeOptions: string;
|
|
5
|
+
frameOptions: string;
|
|
6
6
|
rateLimitLimit: number;
|
|
7
7
|
rateLimitRemaining: number;
|
|
8
8
|
rateLimitReset: number;
|
|
9
9
|
responseTime: number;
|
|
10
10
|
tfePreserveBody: boolean;
|
|
11
|
-
transactionId: string
|
|
12
|
-
twitterResponseTags: string
|
|
11
|
+
transactionId: string;
|
|
12
|
+
twitterResponseTags: string;
|
|
13
13
|
xssProtection: number;
|
|
14
14
|
};
|
package/src/models/index.ts
CHANGED
package/src/models/timeline.ts
CHANGED
|
@@ -6,7 +6,27 @@ export type CursorApiUtilsResponse = {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export type ApiUtilsRaw = {
|
|
9
|
-
response: Response;
|
|
10
9
|
instruction: i.InstructionUnion[];
|
|
11
10
|
entry: i.TimelineAddEntry[];
|
|
12
11
|
};
|
|
12
|
+
|
|
13
|
+
export type TweetApiUtilsData = {
|
|
14
|
+
raw: i.ItemResult;
|
|
15
|
+
tweet: i.Tweet;
|
|
16
|
+
user: i.User;
|
|
17
|
+
replies: TweetApiUtilsData[];
|
|
18
|
+
quoted?: TweetApiUtilsData;
|
|
19
|
+
retweeted?: TweetApiUtilsData;
|
|
20
|
+
promotedMetadata?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type UserApiUtilsData = {
|
|
24
|
+
raw: i.UserResults;
|
|
25
|
+
user: i.User;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type TimelineApiUtilsResponse<T> = {
|
|
29
|
+
raw: ApiUtilsRaw;
|
|
30
|
+
cursor: CursorApiUtilsResponse;
|
|
31
|
+
data: T[];
|
|
32
|
+
};
|
package/src/models/utils.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
2
|
|
|
3
|
-
export type ApiFunction<T> = (requestParameters:
|
|
4
|
-
pathQueryId: string;
|
|
5
|
-
queryId: string;
|
|
6
|
-
variables: string;
|
|
7
|
-
features: string;
|
|
8
|
-
fieldToggles: string;
|
|
9
|
-
}) => Promise<i.ApiResponse<T>>;
|
|
3
|
+
export type ApiFunction<T> = (requestParameters: any) => Promise<i.ApiResponse<T>>;
|
|
10
4
|
|
|
11
5
|
export type RequestParam<T1, T2> = {
|
|
12
|
-
apiFn: ApiFunction<T2>;
|
|
13
|
-
convertFn:
|
|
6
|
+
apiFn: ApiFunction<i.Errors | T2>;
|
|
7
|
+
convertFn: (arg0: T2) => T1;
|
|
14
8
|
key: string;
|
|
15
9
|
param: { [key: string]: any };
|
|
16
10
|
};
|
|
17
|
-
|
|
18
|
-
export type ConvertFunction<T1, T2> = (arg0: T2) => T1;
|
package/src/utils/api.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
2
|
import { TweetApiUtilsData, UserApiUtilsData, CursorApiUtilsResponse, ApiUtilsHeader } from '@/models';
|
|
3
3
|
|
|
4
|
+
export const getKwargs = (flag: { [key: string]: any }, additional: { [key: string]: any }): any => {
|
|
5
|
+
const kwargs: { [key: string]: any } = { pathQueryId: flag.queryId };
|
|
6
|
+
if (flag.variables != null) {
|
|
7
|
+
kwargs.variables = JSON.stringify({ ...flag.variables, ...additional });
|
|
8
|
+
}
|
|
9
|
+
if (flag.features != null) {
|
|
10
|
+
kwargs.features = JSON.stringify(flag.features);
|
|
11
|
+
}
|
|
12
|
+
if (flag.fieldToggles != null) {
|
|
13
|
+
kwargs.fieldToggles = JSON.stringify(flag.fieldToggles);
|
|
14
|
+
}
|
|
15
|
+
return kwargs;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const errorCheck = <T>(data: i.Errors | T): T => {
|
|
19
|
+
const res: any = data;
|
|
20
|
+
if (res.data != undefined) {
|
|
21
|
+
return res;
|
|
22
|
+
} else if (res.error != undefined) {
|
|
23
|
+
throw Error(res.errors[0].message);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
4
27
|
export const instructionToEntry = (item: i.InstructionUnion[]): i.TimelineAddEntry[] => {
|
|
5
28
|
return item.flatMap((e) => {
|
|
6
29
|
if (e.type == i.InstructionType.TimelineAddEntries) {
|
|
7
30
|
return (e as i.TimelineAddEntries).entries;
|
|
8
31
|
} else if (e.type == i.InstructionType.TimelineReplaceEntry) {
|
|
9
32
|
return [(e as i.TimelineReplaceEntry).entry];
|
|
10
|
-
} else {
|
|
11
|
-
return null;
|
|
12
33
|
}
|
|
34
|
+
return [];
|
|
13
35
|
});
|
|
14
36
|
};
|
|
15
37
|
|
|
@@ -49,17 +71,21 @@ type buildTweetApiUtilsArgs = {
|
|
|
49
71
|
export const buildTweetApiUtils = (args: buildTweetApiUtilsArgs): TweetApiUtilsData | undefined => {
|
|
50
72
|
const tweet = tweetResultsConverter(args.result);
|
|
51
73
|
if (tweet == null) return undefined;
|
|
74
|
+
const user = userOrNullConverter(tweet.core.userResults.result);
|
|
75
|
+
if (user == null) return undefined;
|
|
52
76
|
const quoted = tweet.quotedStatusResult;
|
|
53
77
|
const retweeted = tweet.legacy.retweetedStatusResult;
|
|
78
|
+
const reply =
|
|
79
|
+
args.reply
|
|
80
|
+
?.map((e) => buildTweetApiUtils({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }))
|
|
81
|
+
.filter((e): e is NonNullable<typeof e> => e != null) ?? [];
|
|
54
82
|
return {
|
|
55
83
|
raw: args.result,
|
|
56
84
|
promotedMetadata: args.promotedMetadata,
|
|
57
85
|
tweet: tweet,
|
|
58
|
-
user:
|
|
59
|
-
reply
|
|
60
|
-
|
|
61
|
-
?.map((e) => buildTweetApiUtils({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }))
|
|
62
|
-
.filter((e): e is NonNullable<typeof e> => e != null) ?? [],
|
|
86
|
+
user: user,
|
|
87
|
+
replies: reply,
|
|
88
|
+
retweeted: retweeted == undefined ? undefined : buildTweetApiUtils({ result: retweeted }),
|
|
63
89
|
quoted: quoted == undefined ? undefined : buildTweetApiUtils({ result: quoted }),
|
|
64
90
|
};
|
|
65
91
|
};
|
|
@@ -76,22 +102,36 @@ export const tweetResultsConverter = (tweetResults: i.ItemResult): i.Tweet | und
|
|
|
76
102
|
throw Error();
|
|
77
103
|
};
|
|
78
104
|
|
|
79
|
-
export const
|
|
105
|
+
export const userOrNullConverter = (userResults: i.UserUnion): i.User | null => {
|
|
106
|
+
if (userResults.typename == i.TypeName.User) {
|
|
107
|
+
return userResults as i.User;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const userEntriesConverter = (item: i.TimelineAddEntry[]): i.UserResults[] => {
|
|
80
112
|
return item
|
|
81
113
|
.map((e) => {
|
|
82
114
|
if (e.content.typename == i.TypeName.TimelineTimelineItem) {
|
|
83
115
|
const item = (e.content as i.TimelineTimelineItem).itemContent;
|
|
84
|
-
|
|
116
|
+
if (item.itemType == i.ContentItemType.TimelineUser) {
|
|
117
|
+
return (item as i.TimelineUser).userResults;
|
|
118
|
+
}
|
|
85
119
|
}
|
|
86
120
|
})
|
|
87
121
|
.filter((e): e is NonNullable<typeof e> => e != null);
|
|
88
122
|
};
|
|
89
123
|
|
|
90
|
-
export const
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
124
|
+
export const userResultConverter = (user: i.UserResults[]): UserApiUtilsData[] => {
|
|
125
|
+
return user
|
|
126
|
+
.map((e) => {
|
|
127
|
+
const user = userOrNullConverter(e.result);
|
|
128
|
+
if (user == null) return null;
|
|
129
|
+
return {
|
|
130
|
+
raw: e,
|
|
131
|
+
user: user,
|
|
132
|
+
};
|
|
133
|
+
})
|
|
134
|
+
.filter((e): e is NonNullable<typeof e> => e != null);
|
|
95
135
|
};
|
|
96
136
|
|
|
97
137
|
export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsResponse => {
|
|
@@ -112,8 +152,8 @@ export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsRespons
|
|
|
112
152
|
|
|
113
153
|
export const buildCursor = (cursorList: i.TimelineTimelineCursor[]): CursorApiUtilsResponse => {
|
|
114
154
|
return {
|
|
115
|
-
top: cursorList.find((e) => e.cursorType == i.
|
|
116
|
-
bottom: cursorList.find((e) => e.cursorType == i.
|
|
155
|
+
top: cursorList.find((e) => e.cursorType == i.CursorType.Top),
|
|
156
|
+
bottom: cursorList.find((e) => e.cursorType == i.CursorType.Bottom),
|
|
117
157
|
};
|
|
118
158
|
};
|
|
119
159
|
|
|
@@ -123,9 +163,9 @@ export const buildHeader = (headers: Headers): ApiUtilsHeader => {
|
|
|
123
163
|
connectionHash: headers.get('x-connection-hash'),
|
|
124
164
|
contentTypeOptions: headers.get('x-content-type-options'),
|
|
125
165
|
frameOptions: headers.get('x-frame-options'),
|
|
126
|
-
rateLimitLimit: Number(headers.get('x-rate-limit-limit')),
|
|
127
|
-
rateLimitRemaining: Number(headers.get('x-rate-limit-remaining')),
|
|
128
|
-
rateLimitReset: Number(headers.get('x-rate-limit-reset')),
|
|
166
|
+
rateLimitLimit: Number(headers.get('x-rate-limit-limit') ?? 0),
|
|
167
|
+
rateLimitRemaining: Number(headers.get('x-rate-limit-remaining') ?? 0),
|
|
168
|
+
rateLimitReset: Number(headers.get('x-rate-limit-reset') ?? 0),
|
|
129
169
|
responseTime: Number(headers.get('x-response-time')),
|
|
130
170
|
tfePreserveBody: headers.get('x-tfe-preserve-body') == 'true',
|
|
131
171
|
transactionId: headers.get('x-transaction-id'),
|
|
@@ -5,7 +5,7 @@ test('getTweetDetail', async () => {
|
|
|
5
5
|
logger.log('getTweetDetail');
|
|
6
6
|
const client = await getClient();
|
|
7
7
|
const response = await client.getTweetApi().getTweetDetail({ focalTweetId: '1349129669258448897' });
|
|
8
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
8
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
9
9
|
expect(response.raw.response.ok).toBe(true);
|
|
10
10
|
});
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ test('getSearchTimeline', async () => {
|
|
|
13
13
|
logger.log('getSearchTimeline');
|
|
14
14
|
const client = await getClient();
|
|
15
15
|
const response = await client.getTweetApi().getSearchTimeline({ rawQuery: 'elonmusk' });
|
|
16
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
16
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
17
17
|
expect(response.raw.response.ok).toBe(true);
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ test('getHomeTimeline', async () => {
|
|
|
21
21
|
logger.log('getHomeTimeline');
|
|
22
22
|
const client = await getClient();
|
|
23
23
|
const response = await client.getTweetApi().getHomeTimeline();
|
|
24
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
24
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
25
25
|
expect(response.raw.response.ok).toBe(true);
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ test('getHomeLatestTimeline', async () => {
|
|
|
29
29
|
logger.log('getHomeLatestTimeline');
|
|
30
30
|
const client = await getClient();
|
|
31
31
|
const response = await client.getTweetApi().getHomeLatestTimeline();
|
|
32
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
32
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
33
33
|
expect(response.raw.response.ok).toBe(true);
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ test('getListLatestTweetsTimeline', async () => {
|
|
|
37
37
|
logger.log('getListLatestTweetsTimeline');
|
|
38
38
|
const client = await getClient();
|
|
39
39
|
const response = await client.getTweetApi().getListLatestTweetsTimeline({ listId: '1141162794290520064' });
|
|
40
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
40
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
41
41
|
expect(response.raw.response.ok).toBe(true);
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ test('getUserTweets', async () => {
|
|
|
45
45
|
logger.log('getUserTweets');
|
|
46
46
|
const client = await getClient();
|
|
47
47
|
const response = await client.getTweetApi().getUserTweets({ userId: '44196397' });
|
|
48
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
48
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
49
49
|
expect(response.raw.response.ok).toBe(true);
|
|
50
50
|
});
|
|
51
51
|
|
|
@@ -53,7 +53,7 @@ test('getUserTweetsAndReplies', async () => {
|
|
|
53
53
|
logger.log('getUserTweetsAndReplies');
|
|
54
54
|
const client = await getClient();
|
|
55
55
|
const response = await client.getTweetApi().getUserTweetsAndReplies({ userId: '44196397' });
|
|
56
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
56
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
57
57
|
expect(response.raw.response.ok).toBe(true);
|
|
58
58
|
});
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@ test('getUserMedia', async () => {
|
|
|
61
61
|
logger.log('getUserMedia');
|
|
62
62
|
const client = await getClient();
|
|
63
63
|
const response = await client.getTweetApi().getUserMedia({ userId: '44196397' });
|
|
64
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
64
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
65
65
|
expect(response.raw.response.ok).toBe(true);
|
|
66
66
|
});
|
|
67
67
|
|
|
@@ -69,7 +69,7 @@ test('getLikes', async () => {
|
|
|
69
69
|
logger.log('getLikes');
|
|
70
70
|
const client = await getClient();
|
|
71
71
|
const response = await client.getTweetApi().getLikes({ userId: '44196397' });
|
|
72
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
72
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
73
73
|
expect(response.raw.response.ok).toBe(true);
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -77,6 +77,6 @@ test('getBookmarks', async () => {
|
|
|
77
77
|
logger.log('getBookmarks');
|
|
78
78
|
const client = await getClient();
|
|
79
79
|
const response = await client.getTweetApi().getBookmarks();
|
|
80
|
-
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
80
|
+
response.data.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e));
|
|
81
81
|
expect(response.raw.response.ok).toBe(true);
|
|
82
82
|
});
|
package/test/api/userApi.test.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { getClient, logger } from '@test/init';
|
|
2
|
+
import { printUser } from '@test/util';
|
|
2
3
|
|
|
3
4
|
test('getUserByScreenName', async () => {
|
|
4
5
|
logger.log('getUserByScreenName');
|
|
5
6
|
const client = await getClient();
|
|
6
7
|
const response = await client.getUserApi().getUserByScreenName({ screenName: 'elonmusk' });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
printUser(response.data);
|
|
9
|
+
expect(response.raw.response.ok).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('getUserByRestId', async () => {
|
|
13
|
+
logger.log('getUserByRestId');
|
|
14
|
+
const client = await getClient();
|
|
15
|
+
const response = await client.getUserApi().getUserByRestId({ userId: '44196397' });
|
|
16
|
+
printUser(response.data);
|
|
12
17
|
expect(response.raw.response.ok).toBe(true);
|
|
13
18
|
});
|
|
@@ -5,7 +5,7 @@ test('getFollowers', async () => {
|
|
|
5
5
|
logger.log('getFollowers');
|
|
6
6
|
const client = await getClient();
|
|
7
7
|
const response = await client.getUserListApi().getFollowers({ userId: '44196397' });
|
|
8
|
-
response.data.forEach((e) => printUser(e));
|
|
8
|
+
response.data.data.forEach((e) => printUser(e));
|
|
9
9
|
expect(response.raw.response.ok).toBe(true);
|
|
10
10
|
});
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ test('getFollowing', async () => {
|
|
|
13
13
|
logger.log('getFollowing');
|
|
14
14
|
const client = await getClient();
|
|
15
15
|
const response = await client.getUserListApi().getFollowing({ userId: '44196397' });
|
|
16
|
-
response.data.forEach((e) => printUser(e));
|
|
16
|
+
response.data.data.forEach((e) => printUser(e));
|
|
17
17
|
expect(response.raw.response.ok).toBe(true);
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -21,7 +21,7 @@ test('getFollowersYouKnow', async () => {
|
|
|
21
21
|
logger.log('getFollowersYouKnow');
|
|
22
22
|
const client = await getClient();
|
|
23
23
|
const response = await client.getUserListApi().getFollowersYouKnow({ userId: '44196397' });
|
|
24
|
-
response.data.forEach((e) => printUser(e));
|
|
24
|
+
response.data.data.forEach((e) => printUser(e));
|
|
25
25
|
expect(response.raw.response.ok).toBe(true);
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ test('getFavoriters', async () => {
|
|
|
29
29
|
logger.log('getFavoriters');
|
|
30
30
|
const client = await getClient();
|
|
31
31
|
const response = await client.getUserListApi().getFavoriters({ tweetId: '1349129669258448897' });
|
|
32
|
-
response.data.forEach((e) => printUser(e));
|
|
32
|
+
response.data.data.forEach((e) => printUser(e));
|
|
33
33
|
expect(response.raw.response.ok).toBe(true);
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -37,6 +37,6 @@ test('getRetweeters', async () => {
|
|
|
37
37
|
logger.log('getRetweeters');
|
|
38
38
|
const client = await getClient();
|
|
39
39
|
const response = await client.getUserListApi().getRetweeters({ tweetId: '1349129669258448897' });
|
|
40
|
-
response.data.forEach((e) => printUser(e));
|
|
40
|
+
response.data.data.forEach((e) => printUser(e));
|
|
41
41
|
expect(response.raw.response.ok).toBe(true);
|
|
42
42
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getClient, logger } from '@test/init';
|
|
2
|
+
import { printLegacyUser } from '@test/util';
|
|
3
|
+
|
|
4
|
+
test('getUserByRestId', async () => {
|
|
5
|
+
logger.log('getUserByRestId');
|
|
6
|
+
const client = await getClient();
|
|
7
|
+
const response = await client.getUsersApi().getUsersByRestIds({ userIds: ['44196397'] });
|
|
8
|
+
response.data.forEach((e) => {
|
|
9
|
+
printLegacyUser(e.user.legacy);
|
|
10
|
+
});
|
|
11
|
+
expect(response.raw.response.ok).toBe(true);
|
|
12
|
+
});
|
package/test/util.ts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
|
|
1
3
|
import { TweetApiUtilsData, UserApiUtilsData } from '@/models';
|
|
2
|
-
import {
|
|
4
|
+
import { logger } from '@test/init';
|
|
3
5
|
|
|
4
6
|
export const printTweet = (tweet: TweetApiUtilsData) => {
|
|
5
7
|
logger.log(`${tweet.user.legacy.screenName}: ${tweet.tweet.legacy.fullText}`.replace(/\n/g, ' '));
|
|
6
|
-
tweet.
|
|
7
|
-
|
|
8
|
+
tweet.replies.forEach((reply) => {
|
|
9
|
+
printLegacyTweet(reply.user.legacy, reply.tweet.legacy);
|
|
8
10
|
});
|
|
9
|
-
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const printLegacyTweet = (user: i.UserLegacy, tweet: i.TweetLegacy) => {
|
|
14
|
+
const text = `${user.screenName.padStart(20)}: ${tweet.fullText}`.replace(/\n/g, ' ');
|
|
15
|
+
logger.log(text);
|
|
10
16
|
};
|
|
11
17
|
|
|
12
18
|
export const printUser = (user: UserApiUtilsData) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
printLegacyUser(user.user.legacy);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const printLegacyUser = (user: i.UserLegacy) => {
|
|
23
|
+
logger.log(user.screenName);
|
|
24
|
+
logger.log(`listedCount: ${user.listedCount}`);
|
|
25
|
+
logger.log(`followedBy: ${user.followedBy} following: ${user.following}`);
|
|
26
|
+
const text = `friendsCount: ${user.friendsCount} followersCount: ${user.followersCount}`;
|
|
27
|
+
logger.log(text);
|
|
17
28
|
logger.log('┄'.repeat(50));
|
|
18
29
|
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
-
import { CursorApiUtilsResponse, ApiUtilsRaw, ApiUtilsHeader } from './';
|
|
3
|
-
export type TweetListApiUtilsResponse = {
|
|
4
|
-
raw: ApiUtilsRaw;
|
|
5
|
-
header: ApiUtilsHeader;
|
|
6
|
-
cursor: CursorApiUtilsResponse;
|
|
7
|
-
data: TweetApiUtilsData[];
|
|
8
|
-
};
|
|
9
|
-
export type TweetApiUtilsData = {
|
|
10
|
-
raw: i.ItemResult;
|
|
11
|
-
tweet: i.Tweet;
|
|
12
|
-
user: i.User;
|
|
13
|
-
reply: TweetApiUtilsData[];
|
|
14
|
-
quoted?: TweetApiUtilsData;
|
|
15
|
-
retweeted?: TweetApiUtilsData;
|
|
16
|
-
promotedMetadata?: any;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=tweet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tweet.d.ts","sourceRoot":"","sources":["../../../src/models/tweet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,sCAAsC,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/E,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,IAAI,EAAE,iBAAiB,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC;IACf,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACb,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,gBAAgB,CAAC,EAAE,GAAG,CAAC;CACxB,CAAC"}
|
package/dist/src/models/tweet.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tweet.js","sourceRoot":"","sources":["../../../src/models/tweet.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
-
import { ApiUtilsHeader } from './';
|
|
3
|
-
export type UserApiUtilsResponse = {
|
|
4
|
-
raw: UserApiUtilsRaw;
|
|
5
|
-
header: ApiUtilsHeader;
|
|
6
|
-
data: i.User;
|
|
7
|
-
};
|
|
8
|
-
export type UsersApiUtilsResponse = {
|
|
9
|
-
raw: UserApiUtilsRaw;
|
|
10
|
-
header: ApiUtilsHeader;
|
|
11
|
-
data: i.User[];
|
|
12
|
-
};
|
|
13
|
-
export type UserApiUtilsRaw = {
|
|
14
|
-
response: Response;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=user.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/models/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,sCAAsC,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;CACd,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC"}
|