@finch_ren/x-scraper 0.1.3 → 0.1.4

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.
@@ -14,12 +14,12 @@ export declare const instructionConverter: (item: i.InstructionUnion[]) => Tweet
14
14
  export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[]) => TweetApiUtilsData[];
15
15
  export declare const moduleConverter: (item: i.ModuleItem[]) => TweetApiUtilsData[];
16
16
  type buildTweetApiUtilsArgs = {
17
- result: i.ItemResult;
17
+ result: i.ItemResult | any;
18
18
  promotedMetadata?: any;
19
- reply?: i.TimelineTweet[];
19
+ reply?: Array<i.TimelineTweet | any>;
20
20
  };
21
21
  export declare const buildTweetApiUtils: (args: buildTweetApiUtilsArgs) => TweetApiUtilsData | undefined;
22
- export declare const tweetResultsConverter: (tweetResults: i.ItemResult) => i.Tweet | undefined;
22
+ export declare const tweetResultsConverter: (tweetResults: i.ItemResult | any) => i.Tweet | undefined;
23
23
  export declare const userOrNullConverter: (userResults: i.UserUnion) => i.User | undefined;
24
24
  export declare const userEntriesConverter: (item: i.TimelineAddEntry[]) => i.UserResults[];
25
25
  export declare const userResultConverter: (user: i.UserResults[]) => UserApiUtilsData[];
@@ -100,8 +100,8 @@ const tweetEntriesConverter = (item) => {
100
100
  return undefined;
101
101
  return [
102
102
  (0, exports.buildTweetApiUtils)({
103
- result: timeline.tweetResults,
104
- promotedMetadata: timeline.promotedMetadata,
103
+ result: getTimelineTweetResult(timeline),
104
+ promotedMetadata: getTimelinePromotedMetadata(timeline),
105
105
  }),
106
106
  ];
107
107
  }
@@ -125,8 +125,8 @@ const moduleConverter = (item) => {
125
125
  if (timelineList[0].tweetDisplayType == i.TimelineTweetTweetDisplayTypeEnum.MediaGrid) {
126
126
  return timelineList
127
127
  .map((e) => (0, exports.buildTweetApiUtils)({
128
- result: e.tweetResults,
129
- promotedMetadata: e.promotedMetadata,
128
+ result: getTimelineTweetResult(e),
129
+ promotedMetadata: getTimelinePromotedMetadata(e),
130
130
  }))
131
131
  .filter((e) => e != undefined);
132
132
  }
@@ -134,26 +134,43 @@ const moduleConverter = (item) => {
134
134
  const timeline = timelineList[0];
135
135
  return [
136
136
  (0, exports.buildTweetApiUtils)({
137
- result: timeline.tweetResults,
138
- promotedMetadata: timeline.promotedMetadata,
137
+ result: getTimelineTweetResult(timeline),
138
+ promotedMetadata: getTimelinePromotedMetadata(timeline),
139
139
  reply: timelineList.slice(1),
140
140
  }),
141
141
  ].filter((e) => e != undefined);
142
142
  }
143
143
  };
144
144
  exports.moduleConverter = moduleConverter;
145
+ const getTimelineTweetResult = (timeline) => {
146
+ return timeline?.tweetResults ?? timeline?.tweet_results;
147
+ };
148
+ const getTimelinePromotedMetadata = (timeline) => {
149
+ return timeline?.promotedMetadata ?? timeline?.promoted_metadata;
150
+ };
151
+ const getTweetUserResult = (tweet) => {
152
+ return tweet?.core?.userResults?.result ?? tweet?.core?.user_results?.result;
153
+ };
154
+ const getQuotedStatusResult = (tweet) => {
155
+ return tweet?.quotedStatusResult ?? tweet?.quoted_status_result;
156
+ };
157
+ const getRetweetedStatusResult = (tweet) => {
158
+ return tweet?.legacy?.retweetedStatusResult ?? tweet?.legacy?.retweeted_status_result;
159
+ };
145
160
  const buildTweetApiUtils = (args) => {
161
+ if (args.result == undefined)
162
+ return undefined;
146
163
  const tweet = (0, exports.tweetResultsConverter)(args.result);
147
164
  if (tweet == undefined)
148
165
  return undefined;
149
- const result = tweet.core?.userResults.result;
166
+ const result = getTweetUserResult(tweet);
150
167
  const user = result && (0, exports.userOrNullConverter)(result);
151
168
  if (user == undefined)
152
169
  return undefined;
153
- const quoted = tweet.quotedStatusResult;
154
- const retweeted = tweet.legacy?.retweetedStatusResult;
170
+ const quoted = getQuotedStatusResult(tweet);
171
+ const retweeted = getRetweetedStatusResult(tweet);
155
172
  const reply = args.reply
156
- ?.map((e) => (0, exports.buildTweetApiUtils)({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }))
173
+ ?.map((e) => (0, exports.buildTweetApiUtils)({ result: getTimelineTweetResult(e), promotedMetadata: getTimelinePromotedMetadata(e) }))
157
174
  .filter((e) => e != undefined) ?? [];
158
175
  return {
159
176
  raw: args.result,
@@ -167,6 +184,8 @@ const buildTweetApiUtils = (args) => {
167
184
  };
168
185
  exports.buildTweetApiUtils = buildTweetApiUtils;
169
186
  const tweetResultsConverter = (tweetResults) => {
187
+ if (tweetResults == undefined)
188
+ return undefined;
170
189
  if (tweetResults.result == undefined)
171
190
  return undefined;
172
191
  switch (tweetResults.result.typename) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finch_ren/x-scraper",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A TypeScript SDK for X (Twitter) internal GraphQL endpoints with cookie-based authentication.",
5
5
  "keywords": [
6
6
  "twitter",