@finch_ren/x-scraper 0.1.4 → 0.1.5

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.
@@ -11,8 +11,8 @@ export declare const getKwargs: (flag: {
11
11
  export declare const errorCheck: <T>(data: T | undefined, error: i.ErrorResponse[] | undefined) => T;
12
12
  export declare const instructionToEntry: (item: i.InstructionUnion[]) => i.TimelineAddEntry[];
13
13
  export declare const instructionConverter: (item: i.InstructionUnion[]) => TweetApiUtilsData[];
14
- export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[]) => TweetApiUtilsData[];
15
- export declare const moduleConverter: (item: i.ModuleItem[]) => TweetApiUtilsData[];
14
+ export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[] | any) => TweetApiUtilsData[];
15
+ export declare const moduleConverter: (item: i.ModuleItem[] | any) => TweetApiUtilsData[];
16
16
  type buildTweetApiUtilsArgs = {
17
17
  result: i.ItemResult | any;
18
18
  promotedMetadata?: any;
@@ -90,8 +90,44 @@ const instructionConverter = (item) => {
90
90
  .flat();
91
91
  };
92
92
  exports.instructionConverter = instructionConverter;
93
+ const isTimelineAddEntry = (value) => {
94
+ return value != undefined && typeof value == 'object' && 'content' in value && 'entryId' in value;
95
+ };
96
+ const isInstructionLike = (value) => {
97
+ return value != undefined && typeof value == 'object' && typeof value.type == 'string';
98
+ };
99
+ const normalizeTimelineEntries = (value) => {
100
+ if (value == undefined)
101
+ return [];
102
+ if (Array.isArray(value)) {
103
+ if (value.length == 0)
104
+ return [];
105
+ if (value.every(isTimelineAddEntry)) {
106
+ return value;
107
+ }
108
+ if (value.every(isInstructionLike)) {
109
+ return (0, exports.instructionToEntry)(value);
110
+ }
111
+ return [];
112
+ }
113
+ if (typeof value != 'object')
114
+ return [];
115
+ if (Array.isArray(value.instructions)) {
116
+ return (0, exports.instructionToEntry)(value.instructions);
117
+ }
118
+ if (Array.isArray(value.entries)) {
119
+ return value.entries;
120
+ }
121
+ if (value.entry != undefined) {
122
+ return [value.entry];
123
+ }
124
+ if (isTimelineAddEntry(value)) {
125
+ return [value];
126
+ }
127
+ return [];
128
+ };
93
129
  const tweetEntriesConverter = (item) => {
94
- return item
130
+ return normalizeTimelineEntries(item)
95
131
  .map((e) => {
96
132
  if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
97
133
  const item = e.content.itemContent;
@@ -117,8 +153,8 @@ const tweetEntriesConverter = (item) => {
117
153
  };
118
154
  exports.tweetEntriesConverter = tweetEntriesConverter;
119
155
  const moduleConverter = (item) => {
120
- const timelineList = item
121
- .filter((e) => e.item.itemContent.itemType == i.ContentItemType.TimelineTweet)
156
+ const timelineList = (item ?? [])
157
+ .filter((e) => e?.item?.itemContent?.itemType == i.ContentItemType.TimelineTweet)
122
158
  .map((e) => e.item.itemContent);
123
159
  if (timelineList.length == 0)
124
160
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finch_ren/x-scraper",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A TypeScript SDK for X (Twitter) internal GraphQL endpoints with cookie-based authentication.",
5
5
  "keywords": [
6
6
  "twitter",