twitter-openapi-typescript 0.0.14 → 0.0.16
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/LICENSE +31 -0
- package/{LICENSE.txt → LICENSE.AGPL} +3 -3
- package/README.md +7 -0
- package/dist/src/api.js +11 -10
- package/dist/src/api.js.map +1 -1
- package/dist/src/apis/defaultApi.d.ts +1 -1
- package/dist/src/apis/defaultApi.d.ts.map +1 -1
- package/dist/src/apis/defaultApi.js.map +1 -1
- package/dist/src/apis/postApi.d.ts +1 -0
- package/dist/src/apis/postApi.d.ts.map +1 -1
- package/dist/src/apis/postApi.js +15 -9
- package/dist/src/apis/postApi.js.map +1 -1
- package/dist/src/apis/tweetApi.js +11 -11
- package/dist/src/apis/tweetApi.js.map +1 -1
- package/dist/src/apis/userApi.js +1 -1
- package/dist/src/apis/userApi.js.map +1 -1
- package/dist/src/apis/userListApi.js +5 -5
- package/dist/src/apis/userListApi.js.map +1 -1
- package/dist/src/models/timeline.d.ts +1 -1
- package/dist/src/models/timeline.d.ts.map +1 -1
- package/dist/src/models/tweet.d.ts +18 -0
- package/dist/src/models/tweet.d.ts.map +1 -0
- package/dist/src/models/tweet.js +3 -0
- package/dist/src/models/tweet.js.map +1 -0
- package/dist/src/models/user.d.ts +16 -0
- package/dist/src/models/user.d.ts.map +1 -0
- package/dist/src/models/user.js +3 -0
- package/dist/src/models/user.js.map +1 -0
- package/dist/src/models/user_list.d.ts +13 -0
- package/dist/src/models/user_list.d.ts.map +1 -0
- package/dist/src/models/user_list.js +3 -0
- package/dist/src/models/user_list.js.map +1 -0
- package/dist/src/utils/api.d.ts +1 -1
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js +27 -20
- package/dist/src/utils/api.js.map +1 -1
- package/jest.config.js +2 -5
- package/package.json +18 -18
- package/src/api.ts +2 -2
- package/src/apis/defaultApi.ts +3 -1
- package/src/apis/postApi.ts +8 -0
- package/src/apis/tweetApi.ts +22 -22
- package/src/apis/userApi.ts +1 -1
- package/src/apis/userListApi.ts +10 -10
- package/src/models/timeline.ts +1 -1
- package/src/utils/api.ts +31 -23
- package/test/api/defaultApi.test.ts +2 -2
- package/test/api/usersApi.test.ts +1 -1
- package/test/util.ts +3 -3
- package/tsconfig.build.json +2 -1
- package/tsconfig.json +2 -1
package/src/utils/api.ts
CHANGED
|
@@ -3,13 +3,13 @@ import { TweetApiUtilsData, UserApiUtilsData, CursorApiUtilsResponse, ApiUtilsHe
|
|
|
3
3
|
|
|
4
4
|
export const getKwargs = (flag: { [key: string]: any }, additional: { [key: string]: any }): any => {
|
|
5
5
|
const kwargs: { [key: string]: any } = { pathQueryId: flag.queryId };
|
|
6
|
-
if (flag.variables !=
|
|
6
|
+
if (flag.variables != undefined) {
|
|
7
7
|
kwargs.variables = JSON.stringify({ ...flag.variables, ...additional });
|
|
8
8
|
}
|
|
9
|
-
if (flag.features !=
|
|
9
|
+
if (flag.features != undefined) {
|
|
10
10
|
kwargs.features = JSON.stringify(flag.features);
|
|
11
11
|
}
|
|
12
|
-
if (flag.fieldToggles !=
|
|
12
|
+
if (flag.fieldToggles != undefined) {
|
|
13
13
|
kwargs.fieldToggles = JSON.stringify(flag.fieldToggles);
|
|
14
14
|
}
|
|
15
15
|
return kwargs;
|
|
@@ -22,6 +22,7 @@ export const errorCheck = <T>(data: i.Errors | T): T => {
|
|
|
22
22
|
} else if (res.error != undefined) {
|
|
23
23
|
throw Error(res.errors[0].message);
|
|
24
24
|
}
|
|
25
|
+
throw Error();
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export const instructionToEntry = (item: i.InstructionUnion[]): i.TimelineAddEntry[] => {
|
|
@@ -40,8 +41,8 @@ export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtils
|
|
|
40
41
|
.map((e) => {
|
|
41
42
|
if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
|
|
42
43
|
const item = (e.content as i.TimelineTimelineItem).itemContent;
|
|
43
|
-
const timeline = item.itemType == i.ContentItemType.TimelineTweet ? (item as i.TimelineTweet) :
|
|
44
|
-
if (timeline ==
|
|
44
|
+
const timeline = item.itemType == i.ContentItemType.TimelineTweet ? (item as i.TimelineTweet) : undefined;
|
|
45
|
+
if (timeline == undefined) return undefined;
|
|
45
46
|
return buildTweetApiUtils({
|
|
46
47
|
result: timeline.tweetResults,
|
|
47
48
|
promotedMetadata: timeline.promotedMetadata,
|
|
@@ -51,7 +52,7 @@ export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtils
|
|
|
51
52
|
const timelineList = item
|
|
52
53
|
.filter((e) => e.item.itemContent.itemType == i.ContentItemType.TimelineTweet)
|
|
53
54
|
.map((e) => e.item.itemContent as i.TimelineTweet);
|
|
54
|
-
if (timelineList.length == 0) return
|
|
55
|
+
if (timelineList.length == 0) return undefined;
|
|
55
56
|
const timeline = timelineList[0];
|
|
56
57
|
return buildTweetApiUtils({
|
|
57
58
|
result: timeline.tweetResults,
|
|
@@ -60,7 +61,7 @@ export const tweetEntriesConverter = (item: i.TimelineAddEntry[]): TweetApiUtils
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
})
|
|
63
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
64
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
type buildTweetApiUtilsArgs = {
|
|
@@ -70,15 +71,17 @@ type buildTweetApiUtilsArgs = {
|
|
|
70
71
|
};
|
|
71
72
|
export const buildTweetApiUtils = (args: buildTweetApiUtilsArgs): TweetApiUtilsData | undefined => {
|
|
72
73
|
const tweet = tweetResultsConverter(args.result);
|
|
73
|
-
if (tweet ==
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
if (tweet == undefined) return undefined;
|
|
75
|
+
const result = tweet.core?.userResults.result;
|
|
76
|
+
const user = result && userOrNullConverter(result);
|
|
77
|
+
if (user == undefined) return undefined;
|
|
76
78
|
const quoted = tweet.quotedStatusResult;
|
|
77
|
-
const retweeted = tweet.legacy
|
|
79
|
+
const retweeted = tweet.legacy?.retweetedStatusResult;
|
|
80
|
+
|
|
78
81
|
const reply =
|
|
79
82
|
args.reply
|
|
80
83
|
?.map((e) => buildTweetApiUtils({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }))
|
|
81
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
84
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined) ?? [];
|
|
82
85
|
return {
|
|
83
86
|
raw: args.result,
|
|
84
87
|
promotedMetadata: args.promotedMetadata,
|
|
@@ -91,6 +94,7 @@ export const buildTweetApiUtils = (args: buildTweetApiUtilsArgs): TweetApiUtilsD
|
|
|
91
94
|
};
|
|
92
95
|
|
|
93
96
|
export const tweetResultsConverter = (tweetResults: i.ItemResult): i.Tweet | undefined => {
|
|
97
|
+
if (tweetResults.result == undefined) return undefined;
|
|
94
98
|
switch (tweetResults.result.typename) {
|
|
95
99
|
case i.TypeName.Tweet:
|
|
96
100
|
return tweetResults.result as i.Tweet;
|
|
@@ -102,7 +106,7 @@ export const tweetResultsConverter = (tweetResults: i.ItemResult): i.Tweet | und
|
|
|
102
106
|
throw Error();
|
|
103
107
|
};
|
|
104
108
|
|
|
105
|
-
export const userOrNullConverter = (userResults: i.UserUnion): i.User |
|
|
109
|
+
export const userOrNullConverter = (userResults: i.UserUnion): i.User | undefined => {
|
|
106
110
|
if (userResults.typename == i.TypeName.User) {
|
|
107
111
|
return userResults as i.User;
|
|
108
112
|
}
|
|
@@ -118,20 +122,24 @@ export const userEntriesConverter = (item: i.TimelineAddEntry[]): i.UserResults[
|
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
})
|
|
121
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
125
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const a = (a: string) => {
|
|
129
|
+
return a;
|
|
122
130
|
};
|
|
123
131
|
|
|
124
132
|
export const userResultConverter = (user: i.UserResults[]): UserApiUtilsData[] => {
|
|
125
133
|
return user
|
|
126
134
|
.map((e) => {
|
|
127
|
-
const user = userOrNullConverter(e.result);
|
|
128
|
-
if (user ==
|
|
135
|
+
const user = e.result && userOrNullConverter(e.result);
|
|
136
|
+
if (user == undefined) return undefined;
|
|
129
137
|
return {
|
|
130
138
|
raw: e,
|
|
131
139
|
user: user,
|
|
132
140
|
};
|
|
133
141
|
})
|
|
134
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
142
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
135
143
|
};
|
|
136
144
|
|
|
137
145
|
export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsResponse => {
|
|
@@ -146,7 +154,7 @@ export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsRespons
|
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
156
|
})
|
|
149
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
157
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
150
158
|
return buildCursor(cursorList);
|
|
151
159
|
};
|
|
152
160
|
|
|
@@ -160,16 +168,16 @@ export const buildCursor = (cursorList: i.TimelineTimelineCursor[]): CursorApiUt
|
|
|
160
168
|
export const buildHeader = (headers: Headers): ApiUtilsHeader => {
|
|
161
169
|
return {
|
|
162
170
|
raw: headers,
|
|
163
|
-
connectionHash: headers.get('x-connection-hash')
|
|
164
|
-
contentTypeOptions: headers.get('x-content-type-options')
|
|
165
|
-
frameOptions: headers.get('x-frame-options')
|
|
171
|
+
connectionHash: headers.get('x-connection-hash')!,
|
|
172
|
+
contentTypeOptions: headers.get('x-content-type-options')!,
|
|
173
|
+
frameOptions: headers.get('x-frame-options')!,
|
|
166
174
|
rateLimitLimit: Number(headers.get('x-rate-limit-limit') ?? 0),
|
|
167
175
|
rateLimitRemaining: Number(headers.get('x-rate-limit-remaining') ?? 0),
|
|
168
176
|
rateLimitReset: Number(headers.get('x-rate-limit-reset') ?? 0),
|
|
169
177
|
responseTime: Number(headers.get('x-response-time')),
|
|
170
178
|
tfePreserveBody: headers.get('x-tfe-preserve-body') == 'true',
|
|
171
|
-
transactionId: headers.get('x-transaction-id')
|
|
172
|
-
twitterResponseTags: headers.get('x-twitter-response-tags')
|
|
179
|
+
transactionId: headers.get('x-transaction-id')!,
|
|
180
|
+
twitterResponseTags: headers.get('x-twitter-response-tags')!,
|
|
173
181
|
xssProtection: Number(headers.get('x-xss-protection')),
|
|
174
182
|
};
|
|
175
183
|
};
|
|
@@ -6,7 +6,7 @@ test('getProfileSpotlightsQuery', async () => {
|
|
|
6
6
|
const client = await getClient();
|
|
7
7
|
const response = await client.getDefaultApi().getProfileSpotlightsQuery({ screenName: 'elonmusk' });
|
|
8
8
|
const legacy = response.data.result.legacy;
|
|
9
|
-
logger.log(legacy.screenName);
|
|
9
|
+
logger.log(legacy.screenName ?? 'undefined');
|
|
10
10
|
logger.log(`followedBy: ${legacy.followedBy} following: ${legacy.following}`);
|
|
11
11
|
logger.log('┄'.repeat(50));
|
|
12
12
|
expect(response.raw.response.ok).toBe(true);
|
|
@@ -16,6 +16,6 @@ test('getTweetResultByRestId', async () => {
|
|
|
16
16
|
logger.log('getTweetResultByRestId');
|
|
17
17
|
const client = await getClient();
|
|
18
18
|
const response = await client.getDefaultApi().getTweetResultByRestId({ tweetId: '1349129669258448897' });
|
|
19
|
-
printTweet(response.data);
|
|
19
|
+
printTweet(response.data!);
|
|
20
20
|
expect(response.raw.response.ok).toBe(true);
|
|
21
21
|
});
|
|
@@ -6,7 +6,7 @@ test('getUserByRestId', async () => {
|
|
|
6
6
|
const client = await getClient();
|
|
7
7
|
const response = await client.getUsersApi().getUsersByRestIds({ userIds: ['44196397'] });
|
|
8
8
|
response.data.forEach((e) => {
|
|
9
|
-
printLegacyUser(e.user.legacy);
|
|
9
|
+
e.user && printLegacyUser(e.user.legacy);
|
|
10
10
|
});
|
|
11
11
|
expect(response.raw.response.ok).toBe(true);
|
|
12
12
|
});
|
package/test/util.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { TweetApiUtilsData, UserApiUtilsData } from '@/models';
|
|
|
4
4
|
import { logger } from '@test/init';
|
|
5
5
|
|
|
6
6
|
export const printTweet = (tweet: TweetApiUtilsData) => {
|
|
7
|
-
logger.log(`${tweet.user.legacy.screenName}: ${tweet.tweet.legacy
|
|
7
|
+
logger.log(`${tweet.user.legacy.screenName}: ${tweet.tweet.legacy?.fullText}`.replace(/\n/g, ' '));
|
|
8
8
|
tweet.replies.forEach((reply) => {
|
|
9
|
-
printLegacyTweet(reply.user.legacy, reply.tweet.legacy);
|
|
9
|
+
reply.tweet.legacy && printLegacyTweet(reply.user.legacy, reply.tweet.legacy);
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ export const printLegacyTweet = (user: i.UserLegacy, tweet: i.TweetLegacy) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const printUser = (user: UserApiUtilsData) => {
|
|
19
|
-
printLegacyUser(user.user.legacy);
|
|
19
|
+
user.user && printLegacyUser(user.user.legacy);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export const printLegacyUser = (user: i.UserLegacy) => {
|
package/tsconfig.build.json
CHANGED