twitter-openapi-typescript 0.0.15 → 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 -31
- package/LICENSE.AGPL +660 -660
- 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 +25 -20
- package/dist/src/utils/api.js.map +1 -1
- package/jest.config.js +2 -5
- package/package.json +17 -17
- 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 +28 -22
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,sCAAsC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEvG,eAAO,MAAM,SAAS;;;;MAAuE,GAY5F,CAAC;AAEF,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,sCAAsC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEvG,eAAO,MAAM,SAAS;;;;MAAuE,GAY5F,CAAC;AAEF,eAAO,MAAM,UAAU,8BAQtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,SAAU,EAAE,gBAAgB,EAAE,KAAG,EAAE,gBAAgB,EASjF,CAAC;AAEF,eAAO,MAAM,qBAAqB,SAAU,EAAE,gBAAgB,EAAE,KAAG,iBAAiB,EA0BnF,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;IACrB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC;CAC3B,CAAC;AACF,eAAO,MAAM,kBAAkB,SAAU,sBAAsB,KAAG,iBAAiB,GAAG,SAsBrF,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAAkB,EAAE,UAAU,KAAG,EAAE,KAAK,GAAG,SAW5E,CAAC;AAEF,eAAO,MAAM,mBAAmB,gBAAiB,EAAE,SAAS,KAAG,EAAE,IAAI,GAAG,SAIvE,CAAC;AAEF,eAAO,MAAM,oBAAoB,SAAU,EAAE,gBAAgB,EAAE,KAAG,EAAE,WAAW,EAW9E,CAAC;AAMF,eAAO,MAAM,mBAAmB,SAAU,EAAE,WAAW,EAAE,KAAG,gBAAgB,EAW3E,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,EAAE,gBAAgB,EAAE,KAAG,sBAc1D,CAAC;AAEF,eAAO,MAAM,WAAW,eAAgB,EAAE,sBAAsB,EAAE,KAAG,sBAKpE,CAAC;AAEF,eAAO,MAAM,WAAW,YAAa,OAAO,KAAG,cAe9C,CAAC"}
|
package/dist/src/utils/api.js
CHANGED
|
@@ -15,13 +15,13 @@ exports.buildHeader = exports.buildCursor = exports.entriesCursor = exports.user
|
|
|
15
15
|
var i = require("twitter-openapi-typescript-generated");
|
|
16
16
|
var getKwargs = function (flag, additional) {
|
|
17
17
|
var kwargs = { pathQueryId: flag.queryId };
|
|
18
|
-
if (flag.variables !=
|
|
18
|
+
if (flag.variables != undefined) {
|
|
19
19
|
kwargs.variables = JSON.stringify(__assign(__assign({}, flag.variables), additional));
|
|
20
20
|
}
|
|
21
|
-
if (flag.features !=
|
|
21
|
+
if (flag.features != undefined) {
|
|
22
22
|
kwargs.features = JSON.stringify(flag.features);
|
|
23
23
|
}
|
|
24
|
-
if (flag.fieldToggles !=
|
|
24
|
+
if (flag.fieldToggles != undefined) {
|
|
25
25
|
kwargs.fieldToggles = JSON.stringify(flag.fieldToggles);
|
|
26
26
|
}
|
|
27
27
|
return kwargs;
|
|
@@ -35,6 +35,7 @@ var errorCheck = function (data) {
|
|
|
35
35
|
else if (res.error != undefined) {
|
|
36
36
|
throw Error(res.errors[0].message);
|
|
37
37
|
}
|
|
38
|
+
throw Error();
|
|
38
39
|
};
|
|
39
40
|
exports.errorCheck = errorCheck;
|
|
40
41
|
var instructionToEntry = function (item) {
|
|
@@ -55,9 +56,9 @@ var tweetEntriesConverter = function (item) {
|
|
|
55
56
|
var _a;
|
|
56
57
|
if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
|
|
57
58
|
var item_1 = e.content.itemContent;
|
|
58
|
-
var timeline = item_1.itemType == i.ContentItemType.TimelineTweet ? item_1 :
|
|
59
|
-
if (timeline ==
|
|
60
|
-
return
|
|
59
|
+
var timeline = item_1.itemType == i.ContentItemType.TimelineTweet ? item_1 : undefined;
|
|
60
|
+
if (timeline == undefined)
|
|
61
|
+
return undefined;
|
|
61
62
|
return (0, exports.buildTweetApiUtils)({
|
|
62
63
|
result: timeline.tweetResults,
|
|
63
64
|
promotedMetadata: timeline.promotedMetadata,
|
|
@@ -69,7 +70,7 @@ var tweetEntriesConverter = function (item) {
|
|
|
69
70
|
.filter(function (e) { return e.item.itemContent.itemType == i.ContentItemType.TimelineTweet; })
|
|
70
71
|
.map(function (e) { return e.item.itemContent; });
|
|
71
72
|
if (timelineList.length == 0)
|
|
72
|
-
return
|
|
73
|
+
return undefined;
|
|
73
74
|
var timeline = timelineList[0];
|
|
74
75
|
return (0, exports.buildTweetApiUtils)({
|
|
75
76
|
result: timeline.tweetResults,
|
|
@@ -78,20 +79,21 @@ var tweetEntriesConverter = function (item) {
|
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
})
|
|
81
|
-
.filter(function (e) { return e !=
|
|
82
|
+
.filter(function (e) { return e != undefined; });
|
|
82
83
|
};
|
|
83
84
|
exports.tweetEntriesConverter = tweetEntriesConverter;
|
|
84
85
|
var buildTweetApiUtils = function (args) {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
+
var _a, _b, _c, _d;
|
|
86
87
|
var tweet = (0, exports.tweetResultsConverter)(args.result);
|
|
87
|
-
if (tweet ==
|
|
88
|
+
if (tweet == undefined)
|
|
88
89
|
return undefined;
|
|
89
|
-
var
|
|
90
|
-
|
|
90
|
+
var result = (_a = tweet.core) === null || _a === void 0 ? void 0 : _a.userResults.result;
|
|
91
|
+
var user = result && (0, exports.userOrNullConverter)(result);
|
|
92
|
+
if (user == undefined)
|
|
91
93
|
return undefined;
|
|
92
94
|
var quoted = tweet.quotedStatusResult;
|
|
93
|
-
var retweeted = (
|
|
94
|
-
var reply = (
|
|
95
|
+
var retweeted = (_b = tweet.legacy) === null || _b === void 0 ? void 0 : _b.retweetedStatusResult;
|
|
96
|
+
var reply = (_d = (_c = args.reply) === null || _c === void 0 ? void 0 : _c.map(function (e) { return (0, exports.buildTweetApiUtils)({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }); }).filter(function (e) { return e != undefined; })) !== null && _d !== void 0 ? _d : [];
|
|
95
97
|
return {
|
|
96
98
|
raw: args.result,
|
|
97
99
|
promotedMetadata: args.promotedMetadata,
|
|
@@ -133,21 +135,24 @@ var userEntriesConverter = function (item) {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
})
|
|
136
|
-
.filter(function (e) { return e !=
|
|
138
|
+
.filter(function (e) { return e != undefined; });
|
|
137
139
|
};
|
|
138
140
|
exports.userEntriesConverter = userEntriesConverter;
|
|
141
|
+
var a = function (a) {
|
|
142
|
+
return a;
|
|
143
|
+
};
|
|
139
144
|
var userResultConverter = function (user) {
|
|
140
145
|
return user
|
|
141
146
|
.map(function (e) {
|
|
142
|
-
var user = (0, exports.userOrNullConverter)(e.result);
|
|
143
|
-
if (user ==
|
|
144
|
-
return
|
|
147
|
+
var user = e.result && (0, exports.userOrNullConverter)(e.result);
|
|
148
|
+
if (user == undefined)
|
|
149
|
+
return undefined;
|
|
145
150
|
return {
|
|
146
151
|
raw: e,
|
|
147
152
|
user: user,
|
|
148
153
|
};
|
|
149
154
|
})
|
|
150
|
-
.filter(function (e) { return e !=
|
|
155
|
+
.filter(function (e) { return e != undefined; });
|
|
151
156
|
};
|
|
152
157
|
exports.userResultConverter = userResultConverter;
|
|
153
158
|
var entriesCursor = function (item) {
|
|
@@ -163,7 +168,7 @@ var entriesCursor = function (item) {
|
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
})
|
|
166
|
-
.filter(function (e) { return e !=
|
|
171
|
+
.filter(function (e) { return e != undefined; });
|
|
167
172
|
return (0, exports.buildCursor)(cursorList);
|
|
168
173
|
};
|
|
169
174
|
exports.entriesCursor = entriesCursor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAA0D;AAGnD,IAAM,SAAS,GAAG,UAAC,IAA4B,EAAE,UAAkC;IACxF,IAAM,MAAM,GAA2B,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACrE,IAAI,IAAI,CAAC,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/utils/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wDAA0D;AAGnD,IAAM,SAAS,GAAG,UAAC,IAA4B,EAAE,UAAkC;IACxF,IAAM,MAAM,GAA2B,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACrE,IAAI,IAAI,CAAC,SAAS,IAAI,SAAS,EAAE;QAC/B,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,uBAAM,IAAI,CAAC,SAAS,GAAK,UAAU,EAAG,CAAC;KACzE;IACD,IAAI,IAAI,CAAC,QAAQ,IAAI,SAAS,EAAE;QAC9B,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjD;IACD,IAAI,IAAI,CAAC,YAAY,IAAI,SAAS,EAAE;QAClC,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACzD;IACD,OAAO,MAAM,CA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.config.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
1
|
module.exports = {
|
|
3
2
|
preset: 'ts-jest',
|
|
4
3
|
testEnvironment: 'node',
|
|
5
|
-
|
|
6
|
-
"ts-jest"
|
|
7
|
-
tsconfig: "<rootDir>/tsconfig.json",
|
|
8
|
-
},
|
|
4
|
+
transform: {
|
|
5
|
+
"^.+\\.ts$": "ts-jest",
|
|
9
6
|
},
|
|
10
7
|
moduleNameMapper: {
|
|
11
8
|
"^@/(.*)$": "<rootDir>/src/$1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twitter-openapi-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Implementation of Twitter internal API in TypeScript",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -22,24 +22,24 @@
|
|
|
22
22
|
"main": "./dist/src/index.js",
|
|
23
23
|
"typings": "./dist/src/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"twitter-openapi-typescript-generated": "^0.0.
|
|
25
|
+
"twitter-openapi-typescript-generated": "^0.0.12"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/jest": "
|
|
29
|
-
"@types/node": "
|
|
30
|
-
"@types/node-fetch": "
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "
|
|
32
|
-
"@typescript-eslint/parser": "
|
|
33
|
-
"dotenv": "^16.
|
|
34
|
-
"eslint": "^8.
|
|
35
|
-
"eslint-config-standard-with-typescript": "
|
|
36
|
-
"eslint-plugin-import": "
|
|
37
|
-
"eslint-plugin-n": "
|
|
38
|
-
"eslint-plugin-promise": "
|
|
39
|
-
"jest": "^
|
|
40
|
-
"
|
|
28
|
+
"@types/jest": "any",
|
|
29
|
+
"@types/node": "any",
|
|
30
|
+
"@types/node-fetch": "any",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "any",
|
|
32
|
+
"@typescript-eslint/parser": "any",
|
|
33
|
+
"dotenv": "^16.3.0",
|
|
34
|
+
"eslint": "^8.50.0",
|
|
35
|
+
"eslint-config-standard-with-typescript": "any",
|
|
36
|
+
"eslint-plugin-import": "any",
|
|
37
|
+
"eslint-plugin-n": "any",
|
|
38
|
+
"eslint-plugin-promise": "any",
|
|
39
|
+
"jest": "^29.7.0",
|
|
40
|
+
"ts-jest": "any",
|
|
41
|
+
"log4js": "^6.9.0",
|
|
41
42
|
"node-fetch": "^2.0.0",
|
|
42
|
-
"
|
|
43
|
-
"typescript": "^5.1"
|
|
43
|
+
"typescript": "^5.2.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/api.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type TwitterOpenApiCookie = {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export class TwitterOpenApi {
|
|
31
|
-
static hash = '
|
|
31
|
+
static hash = '7560ee63488ec9d15f5389e64867f2413701d7dd';
|
|
32
32
|
static url = `https://raw.githubusercontent.com/fa0311/twitter-openapi/${this.hash}/src/config/placeholder.json`;
|
|
33
33
|
static twitter = 'https://twitter.com/home';
|
|
34
34
|
|
|
@@ -75,7 +75,7 @@ export class TwitterOpenApi {
|
|
|
75
75
|
|
|
76
76
|
const re = new RegExp('<script nonce="([a-zA-Z0-9]{48})">(document.cookie="(.*?)";)+<\\/script>');
|
|
77
77
|
|
|
78
|
-
const script = html.match(re)[0];
|
|
78
|
+
const script = html.match(re)![0];
|
|
79
79
|
script
|
|
80
80
|
.split('document.cookie="')
|
|
81
81
|
.slice(1)
|
package/src/apis/defaultApi.ts
CHANGED
|
@@ -51,7 +51,9 @@ export class DefaultApiUtils {
|
|
|
51
51
|
return response;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async getTweetResultByRestId(
|
|
54
|
+
async getTweetResultByRestId(
|
|
55
|
+
param: TweetResultByRestIdParam,
|
|
56
|
+
): Promise<TwitterApiUtilsResponse<TweetApiUtilsData | undefined>> {
|
|
55
57
|
const args = {
|
|
56
58
|
tweetId: param.tweetId,
|
|
57
59
|
...param.extraParam,
|
package/src/apis/postApi.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { error } from 'console';
|
|
|
6
6
|
|
|
7
7
|
type PostCreateTweetParam = {
|
|
8
8
|
tweetText: string;
|
|
9
|
+
media_ids?: string[];
|
|
9
10
|
extraParam?: { [key: string]: any };
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -48,9 +49,16 @@ export class PostApiUtils {
|
|
|
48
49
|
tweetText: param.tweetText,
|
|
49
50
|
...param.extraParam,
|
|
50
51
|
};
|
|
52
|
+
|
|
51
53
|
const queryId = 'CreateTweet';
|
|
52
54
|
const features = i.PostCreateTweetRequestFeaturesFromJSON(this.flag[queryId]['features']);
|
|
53
55
|
const variables = i.PostCreateTweetRequestVariablesFromJSON(this.flag[queryId]['variables']);
|
|
56
|
+
variables.media.mediaEntities =
|
|
57
|
+
param.media_ids?.map((mediaId) => ({
|
|
58
|
+
mediaId: mediaId,
|
|
59
|
+
taggedUsers: [],
|
|
60
|
+
})) ?? [];
|
|
61
|
+
|
|
54
62
|
const response = await this.api.postCreateTweetRaw({
|
|
55
63
|
pathQueryId: this.flag[queryId]['queryId'],
|
|
56
64
|
postCreateTweetRequest: {
|
package/src/apis/tweetApi.ts
CHANGED
|
@@ -113,8 +113,8 @@ export class TweetApiUtils {
|
|
|
113
113
|
async getTweetDetail(param: GetTweetDetailParam): Promise<ResponseType> {
|
|
114
114
|
const args = {
|
|
115
115
|
focalTweetId: param.focalTweetId,
|
|
116
|
-
...(param.cursor ==
|
|
117
|
-
...(param.controllerData ==
|
|
116
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
117
|
+
...(param.controllerData == undefined ? {} : { controller_data: param.controllerData }),
|
|
118
118
|
...param.extraParam,
|
|
119
119
|
};
|
|
120
120
|
|
|
@@ -129,9 +129,9 @@ export class TweetApiUtils {
|
|
|
129
129
|
async getSearchTimeline(param: GetSearchTimelineParam): Promise<ResponseType> {
|
|
130
130
|
const args = {
|
|
131
131
|
rawQuery: param.rawQuery,
|
|
132
|
-
...(param.product ==
|
|
133
|
-
...(param.cursor ==
|
|
134
|
-
...(param.count ==
|
|
132
|
+
...(param.product == undefined ? {} : { product: param.product }),
|
|
133
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
134
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
135
135
|
...param.extraParam,
|
|
136
136
|
};
|
|
137
137
|
|
|
@@ -146,8 +146,8 @@ export class TweetApiUtils {
|
|
|
146
146
|
|
|
147
147
|
async getHomeTimeline(param: GetHomeTimelineParam = {}): Promise<ResponseType> {
|
|
148
148
|
const args = {
|
|
149
|
-
...(param.count ==
|
|
150
|
-
...(param.couser ==
|
|
149
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
150
|
+
...(param.couser == undefined ? {} : { couser: param.couser }),
|
|
151
151
|
...param.extraParam,
|
|
152
152
|
};
|
|
153
153
|
|
|
@@ -162,8 +162,8 @@ export class TweetApiUtils {
|
|
|
162
162
|
|
|
163
163
|
async getHomeLatestTimeline(param: GetHomeLatestTimelineParam = {}): Promise<ResponseType> {
|
|
164
164
|
const args = {
|
|
165
|
-
...(param.count ==
|
|
166
|
-
...(param.cursor ==
|
|
165
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
166
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
167
167
|
...param.extraParam,
|
|
168
168
|
};
|
|
169
169
|
|
|
@@ -179,14 +179,14 @@ export class TweetApiUtils {
|
|
|
179
179
|
async getListLatestTweetsTimeline(param: GetListLatestTweetsTimelineParam): Promise<ResponseType> {
|
|
180
180
|
const args = {
|
|
181
181
|
listId: param.listId,
|
|
182
|
-
...(param.count ==
|
|
183
|
-
...(param.cursor ==
|
|
182
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
183
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
184
184
|
...param.extraParam,
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const response = await this.request({
|
|
188
188
|
apiFn: this.api.getListLatestTweetsTimelineRaw,
|
|
189
|
-
convertFn: (e) => e.data.list.tweetsTimeline.timeline
|
|
189
|
+
convertFn: (e) => e.data.list.tweetsTimeline.timeline?.instructions ?? [],
|
|
190
190
|
key: 'ListLatestTweetsTimeline',
|
|
191
191
|
param: args,
|
|
192
192
|
});
|
|
@@ -196,8 +196,8 @@ export class TweetApiUtils {
|
|
|
196
196
|
async getUserTweets(param: GetUserTweetsParam): Promise<ResponseType> {
|
|
197
197
|
const args = {
|
|
198
198
|
userId: param.userId,
|
|
199
|
-
...(param.count ==
|
|
200
|
-
...(param.cursor ==
|
|
199
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
200
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
201
201
|
...param.extraParam,
|
|
202
202
|
};
|
|
203
203
|
|
|
@@ -213,8 +213,8 @@ export class TweetApiUtils {
|
|
|
213
213
|
async getUserTweetsAndReplies(param: GetUserTweetsAndRepliesParam): Promise<ResponseType> {
|
|
214
214
|
const args = {
|
|
215
215
|
userId: param.userId,
|
|
216
|
-
...(param.count ==
|
|
217
|
-
...(param.cursor ==
|
|
216
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
217
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
218
218
|
...param.extraParam,
|
|
219
219
|
};
|
|
220
220
|
|
|
@@ -230,8 +230,8 @@ export class TweetApiUtils {
|
|
|
230
230
|
async getUserMedia(param: GetUserMediaParam): Promise<ResponseType> {
|
|
231
231
|
const args = {
|
|
232
232
|
userId: param.userId,
|
|
233
|
-
...(param.count ==
|
|
234
|
-
...(param.cursor ==
|
|
233
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
234
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
235
235
|
...param.extraParam,
|
|
236
236
|
};
|
|
237
237
|
|
|
@@ -246,8 +246,8 @@ export class TweetApiUtils {
|
|
|
246
246
|
async getLikes(param: GetLikesParam): Promise<ResponseType> {
|
|
247
247
|
const args = {
|
|
248
248
|
userId: param.userId,
|
|
249
|
-
...(param.count ==
|
|
250
|
-
...(param.cursor ==
|
|
249
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
250
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
251
251
|
...param.extraParam,
|
|
252
252
|
};
|
|
253
253
|
|
|
@@ -261,8 +261,8 @@ export class TweetApiUtils {
|
|
|
261
261
|
}
|
|
262
262
|
async getBookmarks(param: GetBookmarksParam = {}): Promise<ResponseType> {
|
|
263
263
|
const args = {
|
|
264
|
-
...(param.count ==
|
|
265
|
-
...(param.cursor ==
|
|
264
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
265
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
266
266
|
...param.extraParam,
|
|
267
267
|
};
|
|
268
268
|
|
package/src/apis/userApi.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class UserApiUtils {
|
|
|
29
29
|
const response = await apiFn(args);
|
|
30
30
|
const checked = errorCheck(await response.value());
|
|
31
31
|
const result = param.convertFn(checked);
|
|
32
|
-
const user = userOrNullConverter(result.result);
|
|
32
|
+
const user = result.result && userOrNullConverter(result.result);
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
raw: { response: response.raw },
|
package/src/apis/userListApi.ts
CHANGED
|
@@ -93,8 +93,8 @@ export class UserListApiUtils {
|
|
|
93
93
|
async getFollowers(param: GetFollowersParam): Promise<ResponseType> {
|
|
94
94
|
const args = {
|
|
95
95
|
userId: param.userId,
|
|
96
|
-
...(param.cursor ==
|
|
97
|
-
...(param.count ==
|
|
96
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
97
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
98
98
|
...param.extraParam,
|
|
99
99
|
};
|
|
100
100
|
const response = await this.request({
|
|
@@ -108,8 +108,8 @@ export class UserListApiUtils {
|
|
|
108
108
|
async getFollowing(param: GetFollowingParam): Promise<ResponseType> {
|
|
109
109
|
const args = {
|
|
110
110
|
userId: param.userId,
|
|
111
|
-
...(param.cursor ==
|
|
112
|
-
...(param.count ==
|
|
111
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
112
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
113
113
|
...param.extraParam,
|
|
114
114
|
};
|
|
115
115
|
const response = await this.request({
|
|
@@ -124,8 +124,8 @@ export class UserListApiUtils {
|
|
|
124
124
|
async getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<ResponseType> {
|
|
125
125
|
const args = {
|
|
126
126
|
userId: param.userId,
|
|
127
|
-
...(param.cursor ==
|
|
128
|
-
...(param.count ==
|
|
127
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
128
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
129
129
|
...param.extraParam,
|
|
130
130
|
};
|
|
131
131
|
const response = await this.request({
|
|
@@ -140,8 +140,8 @@ export class UserListApiUtils {
|
|
|
140
140
|
async getFavoriters(param: GetFavoritersParam): Promise<ResponseType> {
|
|
141
141
|
const args = {
|
|
142
142
|
tweetId: param.tweetId,
|
|
143
|
-
...(param.cursor ==
|
|
144
|
-
...(param.count ==
|
|
143
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
144
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
145
145
|
...param.extraParam,
|
|
146
146
|
};
|
|
147
147
|
const response = await this.request({
|
|
@@ -156,8 +156,8 @@ export class UserListApiUtils {
|
|
|
156
156
|
async getRetweeters(param: GetRetweetersParam): Promise<ResponseType> {
|
|
157
157
|
const args = {
|
|
158
158
|
tweetId: param.tweetId,
|
|
159
|
-
...(param.cursor ==
|
|
160
|
-
...(param.count ==
|
|
159
|
+
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
160
|
+
...(param.count == undefined ? {} : { count: param.count }),
|
|
161
161
|
...param.extraParam,
|
|
162
162
|
};
|
|
163
163
|
const response = await this.request({
|
package/src/models/timeline.ts
CHANGED
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,16 +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
79
|
const retweeted = tweet.legacy?.retweetedStatusResult;
|
|
78
80
|
|
|
79
81
|
const reply =
|
|
80
82
|
args.reply
|
|
81
83
|
?.map((e) => buildTweetApiUtils({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }))
|
|
82
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
84
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined) ?? [];
|
|
83
85
|
return {
|
|
84
86
|
raw: args.result,
|
|
85
87
|
promotedMetadata: args.promotedMetadata,
|
|
@@ -104,7 +106,7 @@ export const tweetResultsConverter = (tweetResults: i.ItemResult): i.Tweet | und
|
|
|
104
106
|
throw Error();
|
|
105
107
|
};
|
|
106
108
|
|
|
107
|
-
export const userOrNullConverter = (userResults: i.UserUnion): i.User |
|
|
109
|
+
export const userOrNullConverter = (userResults: i.UserUnion): i.User | undefined => {
|
|
108
110
|
if (userResults.typename == i.TypeName.User) {
|
|
109
111
|
return userResults as i.User;
|
|
110
112
|
}
|
|
@@ -120,20 +122,24 @@ export const userEntriesConverter = (item: i.TimelineAddEntry[]): i.UserResults[
|
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
})
|
|
123
|
-
.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;
|
|
124
130
|
};
|
|
125
131
|
|
|
126
132
|
export const userResultConverter = (user: i.UserResults[]): UserApiUtilsData[] => {
|
|
127
133
|
return user
|
|
128
134
|
.map((e) => {
|
|
129
|
-
const user = userOrNullConverter(e.result);
|
|
130
|
-
if (user ==
|
|
135
|
+
const user = e.result && userOrNullConverter(e.result);
|
|
136
|
+
if (user == undefined) return undefined;
|
|
131
137
|
return {
|
|
132
138
|
raw: e,
|
|
133
139
|
user: user,
|
|
134
140
|
};
|
|
135
141
|
})
|
|
136
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
142
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
137
143
|
};
|
|
138
144
|
|
|
139
145
|
export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsResponse => {
|
|
@@ -148,7 +154,7 @@ export const entriesCursor = (item: i.TimelineAddEntry[]): CursorApiUtilsRespons
|
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
})
|
|
151
|
-
.filter((e): e is NonNullable<typeof e> => e !=
|
|
157
|
+
.filter((e): e is NonNullable<typeof e> => e != undefined);
|
|
152
158
|
return buildCursor(cursorList);
|
|
153
159
|
};
|
|
154
160
|
|
|
@@ -162,16 +168,16 @@ export const buildCursor = (cursorList: i.TimelineTimelineCursor[]): CursorApiUt
|
|
|
162
168
|
export const buildHeader = (headers: Headers): ApiUtilsHeader => {
|
|
163
169
|
return {
|
|
164
170
|
raw: headers,
|
|
165
|
-
connectionHash: headers.get('x-connection-hash')
|
|
166
|
-
contentTypeOptions: headers.get('x-content-type-options')
|
|
167
|
-
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')!,
|
|
168
174
|
rateLimitLimit: Number(headers.get('x-rate-limit-limit') ?? 0),
|
|
169
175
|
rateLimitRemaining: Number(headers.get('x-rate-limit-remaining') ?? 0),
|
|
170
176
|
rateLimitReset: Number(headers.get('x-rate-limit-reset') ?? 0),
|
|
171
177
|
responseTime: Number(headers.get('x-response-time')),
|
|
172
178
|
tfePreserveBody: headers.get('x-tfe-preserve-body') == 'true',
|
|
173
|
-
transactionId: headers.get('x-transaction-id')
|
|
174
|
-
twitterResponseTags: headers.get('x-twitter-response-tags')
|
|
179
|
+
transactionId: headers.get('x-transaction-id')!,
|
|
180
|
+
twitterResponseTags: headers.get('x-twitter-response-tags')!,
|
|
175
181
|
xssProtection: Number(headers.get('x-xss-protection')),
|
|
176
182
|
};
|
|
177
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
|
});
|