x-twitter-scraper 0.13.3 → 0.15.0

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.
Files changed (205) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +54 -12
  3. package/client.d.mts +3 -15
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +3 -15
  6. package/client.d.ts.map +1 -1
  7. package/client.js +7 -52
  8. package/client.js.map +1 -1
  9. package/client.mjs +7 -52
  10. package/client.mjs.map +1 -1
  11. package/core/api-promise.d.mts +0 -8
  12. package/core/api-promise.d.mts.map +1 -1
  13. package/core/api-promise.d.ts +0 -8
  14. package/core/api-promise.d.ts.map +1 -1
  15. package/core/api-promise.js +0 -11
  16. package/core/api-promise.js.map +1 -1
  17. package/core/api-promise.mjs +0 -11
  18. package/core/api-promise.mjs.map +1 -1
  19. package/core/error.d.mts.map +1 -1
  20. package/core/error.d.ts.map +1 -1
  21. package/core/error.js +0 -1
  22. package/core/error.js.map +1 -1
  23. package/core/error.mjs +0 -1
  24. package/core/error.mjs.map +1 -1
  25. package/core/streaming.d.mts.map +1 -1
  26. package/core/streaming.d.ts.map +1 -1
  27. package/core/streaming.js +0 -10
  28. package/core/streaming.js.map +1 -1
  29. package/core/streaming.mjs +0 -10
  30. package/core/streaming.mjs.map +1 -1
  31. package/internal/builtin-types.d.mts +0 -41
  32. package/internal/builtin-types.d.mts.map +1 -1
  33. package/internal/builtin-types.d.ts +0 -41
  34. package/internal/builtin-types.d.ts.map +1 -1
  35. package/internal/decoders/line.d.mts.map +1 -1
  36. package/internal/decoders/line.d.ts.map +1 -1
  37. package/internal/decoders/line.js +4 -21
  38. package/internal/decoders/line.js.map +1 -1
  39. package/internal/decoders/line.mjs +4 -21
  40. package/internal/decoders/line.mjs.map +1 -1
  41. package/internal/detect-platform.d.mts.map +1 -1
  42. package/internal/detect-platform.d.ts.map +1 -1
  43. package/internal/detect-platform.js +0 -20
  44. package/internal/detect-platform.js.map +1 -1
  45. package/internal/detect-platform.mjs +0 -20
  46. package/internal/detect-platform.mjs.map +1 -1
  47. package/internal/errors.d.mts.map +1 -1
  48. package/internal/errors.d.ts.map +1 -1
  49. package/internal/errors.js +0 -2
  50. package/internal/errors.js.map +1 -1
  51. package/internal/errors.mjs +0 -2
  52. package/internal/errors.mjs.map +1 -1
  53. package/internal/headers.d.mts +0 -8
  54. package/internal/headers.d.mts.map +1 -1
  55. package/internal/headers.d.ts +0 -8
  56. package/internal/headers.d.ts.map +1 -1
  57. package/internal/headers.js +0 -2
  58. package/internal/headers.js.map +1 -1
  59. package/internal/headers.mjs +0 -2
  60. package/internal/headers.mjs.map +1 -1
  61. package/internal/parse.d.mts.map +1 -1
  62. package/internal/parse.d.ts.map +1 -1
  63. package/internal/parse.js +0 -4
  64. package/internal/parse.js.map +1 -1
  65. package/internal/parse.mjs +0 -4
  66. package/internal/parse.mjs.map +1 -1
  67. package/internal/shim-types.d.mts +0 -6
  68. package/internal/shim-types.d.mts.map +1 -1
  69. package/internal/shim-types.d.ts +0 -6
  70. package/internal/shim-types.d.ts.map +1 -1
  71. package/internal/shims.d.mts +0 -9
  72. package/internal/shims.d.mts.map +1 -1
  73. package/internal/shims.d.ts +0 -9
  74. package/internal/shims.d.ts.map +1 -1
  75. package/internal/shims.js +2 -7
  76. package/internal/shims.js.map +1 -1
  77. package/internal/shims.mjs +2 -7
  78. package/internal/shims.mjs.map +1 -1
  79. package/internal/to-file.d.mts +0 -16
  80. package/internal/to-file.d.mts.map +1 -1
  81. package/internal/to-file.d.ts +0 -16
  82. package/internal/to-file.d.ts.map +1 -1
  83. package/internal/to-file.js +3 -14
  84. package/internal/to-file.js.map +1 -1
  85. package/internal/to-file.mjs +3 -14
  86. package/internal/to-file.mjs.map +1 -1
  87. package/internal/types.d.mts +1 -32
  88. package/internal/types.d.mts.map +1 -1
  89. package/internal/types.d.ts +1 -32
  90. package/internal/types.d.ts.map +1 -1
  91. package/internal/uploads.d.mts +0 -8
  92. package/internal/uploads.d.mts.map +1 -1
  93. package/internal/uploads.d.ts +0 -8
  94. package/internal/uploads.d.ts.map +1 -1
  95. package/internal/uploads.js +0 -18
  96. package/internal/uploads.js.map +1 -1
  97. package/internal/uploads.mjs +0 -18
  98. package/internal/uploads.mjs.map +1 -1
  99. package/internal/utils/env.d.mts +0 -7
  100. package/internal/utils/env.d.mts.map +1 -1
  101. package/internal/utils/env.d.ts +0 -7
  102. package/internal/utils/env.d.ts.map +1 -1
  103. package/internal/utils/env.js +0 -7
  104. package/internal/utils/env.js.map +1 -1
  105. package/internal/utils/env.mjs +0 -7
  106. package/internal/utils/env.mjs.map +1 -1
  107. package/internal/utils/log.d.mts.map +1 -1
  108. package/internal/utils/log.d.ts.map +1 -1
  109. package/internal/utils/log.js +1 -2
  110. package/internal/utils/log.js.map +1 -1
  111. package/internal/utils/log.mjs +1 -2
  112. package/internal/utils/log.mjs.map +1 -1
  113. package/internal/utils/path.d.mts +0 -3
  114. package/internal/utils/path.d.mts.map +1 -1
  115. package/internal/utils/path.d.ts +0 -3
  116. package/internal/utils/path.d.ts.map +1 -1
  117. package/internal/utils/path.js +0 -6
  118. package/internal/utils/path.js.map +1 -1
  119. package/internal/utils/path.mjs +0 -6
  120. package/internal/utils/path.mjs.map +1 -1
  121. package/internal/utils/query.d.mts +0 -3
  122. package/internal/utils/query.d.mts.map +1 -1
  123. package/internal/utils/query.d.ts +0 -3
  124. package/internal/utils/query.d.ts.map +1 -1
  125. package/internal/utils/query.js +0 -3
  126. package/internal/utils/query.js.map +1 -1
  127. package/internal/utils/query.mjs +0 -3
  128. package/internal/utils/query.mjs.map +1 -1
  129. package/internal/utils/values.d.mts +0 -1
  130. package/internal/utils/values.d.mts.map +1 -1
  131. package/internal/utils/values.d.ts +0 -1
  132. package/internal/utils/values.d.ts.map +1 -1
  133. package/internal/utils/values.js +0 -3
  134. package/internal/utils/values.js.map +1 -1
  135. package/internal/utils/values.mjs +0 -3
  136. package/internal/utils/values.mjs.map +1 -1
  137. package/package.json +3 -3
  138. package/resources/index.d.mts +1 -1
  139. package/resources/index.d.mts.map +1 -1
  140. package/resources/index.d.ts +1 -1
  141. package/resources/index.d.ts.map +1 -1
  142. package/resources/index.js.map +1 -1
  143. package/resources/index.mjs.map +1 -1
  144. package/resources/x/community-notes.d.mts +850 -0
  145. package/resources/x/community-notes.d.mts.map +1 -0
  146. package/resources/x/community-notes.d.ts +850 -0
  147. package/resources/x/community-notes.d.ts.map +1 -0
  148. package/resources/x/community-notes.js +62 -0
  149. package/resources/x/community-notes.js.map +1 -0
  150. package/resources/x/community-notes.mjs +58 -0
  151. package/resources/x/community-notes.mjs.map +1 -0
  152. package/resources/x/index.d.mts +2 -1
  153. package/resources/x/index.d.mts.map +1 -1
  154. package/resources/x/index.d.ts +2 -1
  155. package/resources/x/index.d.ts.map +1 -1
  156. package/resources/x/index.js +3 -1
  157. package/resources/x/index.js.map +1 -1
  158. package/resources/x/index.mjs +1 -0
  159. package/resources/x/index.mjs.map +1 -1
  160. package/resources/x/spaces.d.mts +16 -11
  161. package/resources/x/spaces.d.mts.map +1 -1
  162. package/resources/x/spaces.d.ts +16 -11
  163. package/resources/x/spaces.d.ts.map +1 -1
  164. package/resources/x/spaces.js +4 -3
  165. package/resources/x/spaces.js.map +1 -1
  166. package/resources/x/spaces.mjs +4 -3
  167. package/resources/x/spaces.mjs.map +1 -1
  168. package/resources/x/x.d.mts +279 -3
  169. package/resources/x/x.d.mts.map +1 -1
  170. package/resources/x/x.d.ts +279 -3
  171. package/resources/x/x.d.ts.map +1 -1
  172. package/resources/x/x.js +42 -2
  173. package/resources/x/x.js.map +1 -1
  174. package/resources/x/x.mjs +42 -2
  175. package/resources/x/x.mjs.map +1 -1
  176. package/src/client.ts +16 -54
  177. package/src/core/api-promise.ts +0 -11
  178. package/src/core/error.ts +0 -1
  179. package/src/core/streaming.ts +0 -10
  180. package/src/internal/builtin-types.ts +0 -41
  181. package/src/internal/decoders/line.ts +4 -21
  182. package/src/internal/detect-platform.ts +0 -21
  183. package/src/internal/errors.ts +0 -2
  184. package/src/internal/headers.ts +0 -10
  185. package/src/internal/parse.ts +0 -4
  186. package/src/internal/shim-types.ts +0 -7
  187. package/src/internal/shims.ts +2 -14
  188. package/src/internal/to-file.ts +3 -33
  189. package/src/internal/types.ts +0 -30
  190. package/src/internal/uploads.ts +0 -18
  191. package/src/internal/utils/env.ts +0 -7
  192. package/src/internal/utils/log.ts +1 -2
  193. package/src/internal/utils/path.ts +0 -6
  194. package/src/internal/utils/query.ts +0 -3
  195. package/src/internal/utils/values.ts +0 -3
  196. package/src/resources/index.ts +4 -0
  197. package/src/resources/x/community-notes.ts +1040 -0
  198. package/src/resources/x/index.ts +13 -0
  199. package/src/resources/x/spaces.ts +16 -11
  200. package/src/resources/x/x.ts +362 -2
  201. package/src/version.ts +1 -1
  202. package/version.d.mts +1 -1
  203. package/version.d.ts +1 -1
  204. package/version.js +1 -1
  205. package/version.mjs +1 -1
package/resources/x/x.mjs CHANGED
@@ -14,6 +14,8 @@ import * as BookmarksAPI from "./bookmarks.mjs";
14
14
  import { Bookmarks, } from "./bookmarks.mjs";
15
15
  import * as BroadcastsAPI from "./broadcasts.mjs";
16
16
  import { Broadcasts } from "./broadcasts.mjs";
17
+ import * as CommunityNotesAPI from "./community-notes.mjs";
18
+ import { CommunityNotes, } from "./community-notes.mjs";
17
19
  import * as DmAPI from "./dm.mjs";
18
20
  import { Dm, } from "./dm.mjs";
19
21
  import * as FollowersAPI from "./followers.mjs";
@@ -56,6 +58,7 @@ export class X extends APIResource {
56
58
  this.bookmarks = new BookmarksAPI.Bookmarks(this._client);
57
59
  this.lists = new ListsAPI.Lists(this._client);
58
60
  this.broadcasts = new BroadcastsAPI.Broadcasts(this._client);
61
+ this.communityNotes = new CommunityNotesAPI.CommunityNotes(this._client);
59
62
  this.spaces = new SpacesAPI.Spaces(this._client);
60
63
  }
61
64
  /**
@@ -111,6 +114,20 @@ export class X extends APIResource {
111
114
  getHomeTimeline(query = {}, options) {
112
115
  return this._client.get('/x/timeline', { query, ...options });
113
116
  }
117
+ /**
118
+ * Returns each version X wrote of 1 news story, the AI trends x.com shows under
119
+ * Explore & News. Each version has its time, headline & text, oldest first, so you
120
+ * can see how the story changed. X lists every version at once. Each request costs
121
+ * 1 credit.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const response = await client.x.getNewsStoryVersions('id');
126
+ * ```
127
+ */
128
+ getNewsStoryVersions(id, query = {}, options) {
129
+ return this._client.get(path `/x/news/${id}/versions`, { query, ...options });
130
+ }
114
131
  /**
115
132
  * Returns your X account's notifications, else 424 `account_required`.
116
133
  *
@@ -136,8 +153,10 @@ export class X extends APIResource {
136
153
  }
137
154
  /**
138
155
  * Returns X's current trends for a place you choose. Pick it by woeid, country or
139
- * location name. Without one, trends are worldwide. Each request costs 1 credit,
140
- * however many trends it returns.
156
+ * location name. Without one, trends are worldwide. Add at to read what was
157
+ * trending on Twitter at a past time, such as yesterday. Xquik keeps a Twitter
158
+ * trends archive from 2026-10-13 02:20 UTC on, with 1 list per place every 5
159
+ * minutes. Each request costs 1 credit, however many trends it returns.
141
160
  *
142
161
  * @example
143
162
  * ```ts
@@ -147,6 +166,26 @@ export class X extends APIResource {
147
166
  getTrends(query = {}, options) {
148
167
  return this._client.get('/x/trends', { query, ...options });
149
168
  }
169
+ /**
170
+ * Returns the Twitter trends archive of a place, as the lists X showed there over a
171
+ * range of time. Use it for trending on Twitter yesterday, last week or any day
172
+ * since 2026-10-13 02:20 UTC. Xquik stores 1 list per place every 5 minutes and
173
+ * keeps it for 25 months. Pick the place by woeid, country or location name, the
174
+ * range with from & to, and the step with every. from & to take a time or a span
175
+ * back from now, such as 7d, so a schedule can read the last day on every run.
176
+ * Each step returns the first list stored in it, with its own time. Each returned
177
+ * list costs 1 credit, so 24 lists cost 24 credits. A step with no stored list
178
+ * returns none and costs nothing. 1 request returns 24 lists, or up to 100 with
179
+ * limit.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * const response = await client.x.getTrendsHistory();
184
+ * ```
185
+ */
186
+ getTrendsHistory(query = {}, options) {
187
+ return this._client.get('/x/trends/history', { query, ...options });
188
+ }
150
189
  /**
151
190
  * Finds places on X by name. Pass a place's id as place to /x/tweets/search to
152
191
  * read posts tagged there. X ranks the places, so their order can differ between
@@ -177,5 +216,6 @@ X.AccountConnectionAttempts = AccountConnectionAttempts;
177
216
  X.Bookmarks = Bookmarks;
178
217
  X.Lists = Lists;
179
218
  X.Broadcasts = Broadcasts;
219
+ X.CommunityNotes = CommunityNotes;
180
220
  X.Spaces = Spaces;
181
221
  //# sourceMappingURL=x.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"x.mjs","sourceRoot":"","sources":["../../src/resources/x/x.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,sCAAsC;AAEtC,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAElD,OAAO,KAAK,4BAA4B,0CAAsC;AAC9E,OAAO,EAEL,yBAAyB,GAC1B,0CAAsC;AACvC,OAAO,KAAK,8BAA8B,4CAAwC;AAClF,OAAO,EAGL,2BAA2B,GAC5B,4CAAwC;AACzC,OAAO,KAAK,WAAW,uBAAmB;AAC1C,OAAO,EASL,QAAQ,GAGT,uBAAmB;AACpB,OAAO,KAAK,WAAW,uBAAmB;AAC1C,OAAO,EACL,QAAQ,GAaT,uBAAmB;AACpB,OAAO,KAAK,YAAY,wBAAoB;AAC5C,OAAO,EAIL,SAAS,GACV,wBAAoB;AACrB,OAAO,KAAK,aAAa,yBAAqB;AAC9C,OAAO,EAAsD,UAAU,EAAE,yBAAqB;AAC9F,OAAO,KAAK,KAAK,iBAAa;AAC9B,OAAO,EACL,EAAE,GAOH,iBAAa;AACd,OAAO,KAAK,YAAY,wBAAoB;AAC5C,OAAO,EAA8C,SAAS,EAAE,wBAAoB;AACpF,OAAO,KAAK,OAAO,mBAAe;AAClC,OAAO,EAOL,IAAI,GACL,mBAAe;AAChB,OAAO,KAAK,QAAQ,oBAAgB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BAAyB,CAAC;AACxD,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC;AACxB,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;AAChB,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC;AAC1B,CAAC,CAAC,cAAc,GAAG,cAAc,CAAC;AAClC,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC"}
package/src/client.ts CHANGED
@@ -145,10 +145,14 @@ import {
145
145
  XGetHashflagsParams,
146
146
  XGetHashflagsResponse,
147
147
  XGetHomeTimelineParams,
148
+ XGetNewsStoryVersionsParams,
149
+ XGetNewsStoryVersionsResponse,
148
150
  XGetNotificationsParams,
149
151
  XGetNotificationsResponse,
150
152
  XGetTrendLocationsParams,
151
153
  XGetTrendLocationsResponse,
154
+ XGetTrendsHistoryParams,
155
+ XGetTrendsHistoryResponse,
152
156
  XGetTrendsParams,
153
157
  XGetTrendsResponse,
154
158
  XSearchPlacesParams,
@@ -167,6 +171,8 @@ import {
167
171
  } from './internal/utils/log';
168
172
  import { isEmptyObj } from './internal/utils/values';
169
173
 
174
+ const DEFAULT_BASE_URL = 'https://xquik.com/api/v1';
175
+
170
176
  export interface ClientOptions {
171
177
  /**
172
178
  * Defaults to process.env['X_TWITTER_SCRAPER_API_KEY'].
@@ -204,7 +210,7 @@ export interface ClientOptions {
204
210
  /**
205
211
  * Specify a custom `fetch` function implementation.
206
212
  *
207
- * If not provided, we expect that `fetch` is defined globally.
213
+ * Defaults to globalThis.fetch.
208
214
  */
209
215
  fetch?: Fetch | undefined;
210
216
 
@@ -289,14 +295,13 @@ export class XTwitterScraper {
289
295
  apiKey,
290
296
  bearerToken,
291
297
  ...opts,
292
- baseURL: baseURL || `https://xquik.com/api/v1`,
298
+ baseURL: baseURL || DEFAULT_BASE_URL,
293
299
  };
294
300
 
295
301
  this.baseURL = options.baseURL!;
296
- this.timeout = options.timeout ?? XTwitterScraper.DEFAULT_TIMEOUT; /* 1 minute */
302
+ this.timeout = options.timeout ?? XTwitterScraper.DEFAULT_TIMEOUT;
297
303
  this.logger = options.logger ?? console;
298
304
  const defaultLogLevel = 'warn';
299
- // Set default logLevel early so that we can log a warning in parseLogLevel.
300
305
  this.logLevel = defaultLogLevel;
301
306
  this.logLevel =
302
307
  parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
@@ -345,11 +350,8 @@ export class XTwitterScraper {
345
350
  return client;
346
351
  }
347
352
 
348
- /**
349
- * Check whether the base URL is set to its default.
350
- */
351
353
  #baseURLOverridden(): boolean {
352
- return this.baseURL !== 'https://xquik.com/api/v1';
354
+ return this.baseURL !== DEFAULT_BASE_URL;
353
355
  }
354
356
 
355
357
  protected defaultQuery(): Record<string, string | undefined> | undefined {
@@ -400,9 +402,6 @@ export class XTwitterScraper {
400
402
  return buildHeaders([{ Authorization: `Bearer ${this.bearerToken}` }]);
401
403
  }
402
404
 
403
- /**
404
- * Basic re-implementation of `qs.stringify` for primitive types.
405
- */
406
405
  protected stringifyQuery(query: object | Record<string, unknown>): string {
407
406
  return stringifyQuery(query);
408
407
  }
@@ -448,17 +447,8 @@ export class XTwitterScraper {
448
447
  return url.toString();
449
448
  }
450
449
 
451
- /**
452
- * Used as a callback for mutating the given `FinalRequestOptions` object.
453
- */
454
450
  protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
455
451
 
456
- /**
457
- * Used as a callback for mutating the given `RequestInit` object.
458
- *
459
- * This is useful for cases where you want to add certain headers based off of
460
- * the request properties, e.g. `method` or `url`.
461
- */
462
452
  protected async prepareRequest(
463
453
  request: RequestInit,
464
454
  { url, options }: { url: string; options: FinalRequestOptions },
@@ -522,7 +512,6 @@ export class XTwitterScraper {
522
512
 
523
513
  await this.prepareRequest(req, { url, options });
524
514
 
525
- /** Not an API request ID, just for correlating local log entries. */
526
515
  const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
527
516
  const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
528
517
  const startTime = Date.now();
@@ -551,10 +540,6 @@ export class XTwitterScraper {
551
540
  if (options.signal?.aborted) {
552
541
  throw new Errors.APIUserAbortError();
553
542
  }
554
- // detect native connection timeout errors
555
- // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
556
- // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
557
- // others do not provide enough information to distinguish timeouts from other connection errors
558
543
  const isTimeout =
559
544
  isAbortError(response) ||
560
545
  /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
@@ -600,7 +585,6 @@ export class XTwitterScraper {
600
585
  if (retriesRemaining && shouldRetry) {
601
586
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
602
587
 
603
- // We don't need the body of this response.
604
588
  await Shims.CancelReadableStream(response.body);
605
589
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
606
590
  loggerFor(this).debug(
@@ -689,7 +673,6 @@ export class XTwitterScraper {
689
673
  }
690
674
 
691
675
  try {
692
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
693
676
  return await this.fetch.call(undefined, url, fetchOptions);
694
677
  } finally {
695
678
  clearTimeout(timeout);
@@ -697,23 +680,17 @@ export class XTwitterScraper {
697
680
  }
698
681
 
699
682
  private async shouldRetry(response: Response): Promise<boolean> {
700
- // Note this is not a standard header.
701
683
  const shouldRetryHeader = response.headers.get('x-should-retry');
702
684
 
703
- // If the server explicitly says whether or not to retry, obey.
704
685
  if (shouldRetryHeader === 'true') return true;
705
686
  if (shouldRetryHeader === 'false') return false;
706
687
 
707
- // Retry on request timeouts.
708
688
  if (response.status === 408) return true;
709
689
 
710
- // Retry on lock timeouts.
711
690
  if (response.status === 409) return true;
712
691
 
713
- // Retry on rate limits.
714
692
  if (response.status === 429) return true;
715
693
 
716
- // Retry internal errors.
717
694
  if (response.status >= 500) return true;
718
695
 
719
696
  return false;
@@ -727,7 +704,6 @@ export class XTwitterScraper {
727
704
  ): Promise<APIResponseProps> {
728
705
  let timeoutMillis: number | undefined;
729
706
 
730
- // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
731
707
  const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
732
708
  if (retryAfterMillisHeader) {
733
709
  const timeoutMs = parseFloat(retryAfterMillisHeader);
@@ -736,7 +712,6 @@ export class XTwitterScraper {
736
712
  }
737
713
  }
738
714
 
739
- // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
740
715
  const retryAfterHeader = responseHeaders?.get('retry-after');
741
716
  if (retryAfterHeader && !timeoutMillis) {
742
717
  const timeoutSeconds = parseFloat(retryAfterHeader);
@@ -747,8 +722,6 @@ export class XTwitterScraper {
747
722
  }
748
723
  }
749
724
 
750
- // If the API asks us to wait a certain amount of time, just do what it
751
- // says, but otherwise calculate a default
752
725
  if (timeoutMillis === undefined) {
753
726
  const maxRetries = options.maxRetries ?? this.maxRetries;
754
727
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
@@ -764,10 +737,8 @@ export class XTwitterScraper {
764
737
 
765
738
  const numRetries = maxRetries - retriesRemaining;
766
739
 
767
- // Apply exponential backoff, but not more than the max.
768
740
  const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
769
741
 
770
- // Apply some jitter, take up to at most 25 percent of the retry time.
771
742
  const jitter = 1 - Math.random() * 0.25;
772
743
 
773
744
  return sleepSeconds * jitter * 1000;
@@ -841,8 +812,6 @@ export class XTwitterScraper {
841
812
  }
842
813
 
843
814
  private _makeAbort(controller: AbortController) {
844
- // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
845
- // would capture all request options, and cause a memory leak.
846
815
  return () => controller.abort();
847
816
  }
848
817
 
@@ -852,10 +821,6 @@ export class XTwitterScraper {
852
821
  } {
853
822
  const { body, headers: rawHeaders } = options;
854
823
  if (!body) {
855
- // A resource method always passes a `body` key when its operation defines a
856
- // request body, even if the caller omitted an optional body param. Keep the
857
- // content-type for those, and only elide it for operations with no body at
858
- // all (e.g. GET/DELETE).
859
824
  if (body == null && 'body' in options) {
860
825
  return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
861
826
  }
@@ -863,20 +828,13 @@ export class XTwitterScraper {
863
828
  }
864
829
  const headers = buildHeaders([rawHeaders]);
865
830
  if (
866
- // Pass raw type verbatim
867
831
  ArrayBuffer.isView(body) ||
868
832
  body instanceof ArrayBuffer ||
869
833
  body instanceof DataView ||
870
- (typeof body === 'string' &&
871
- // Preserve legacy string encoding behavior for now
872
- headers.values.has('content-type')) ||
873
- // `Blob` is superset of `File`
834
+ (typeof body === 'string' && headers.values.has('content-type')) ||
874
835
  ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
875
- // `FormData` -> `multipart/form-data`
876
836
  body instanceof FormData ||
877
- // `URLSearchParams` -> `application/x-www-form-urlencoded`
878
837
  body instanceof URLSearchParams ||
879
- // Send chunked stream (each chunk has own `length`)
880
838
  ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
881
839
  ) {
882
840
  return { bodyHeaders: undefined, body: body as BodyInit };
@@ -900,7 +858,7 @@ export class XTwitterScraper {
900
858
  }
901
859
 
902
860
  static XTwitterScraper = this;
903
- static DEFAULT_TIMEOUT = 60000; // 1 minute
861
+ static DEFAULT_TIMEOUT = 60000;
904
862
 
905
863
  static XTwitterScraperError = Errors.XTwitterScraperError;
906
864
  static APIError = Errors.APIError;
@@ -1119,17 +1077,21 @@ export declare namespace XTwitterScraper {
1119
1077
  type XAutocompleteSearchResponse as XAutocompleteSearchResponse,
1120
1078
  type XGetArticleResponse as XGetArticleResponse,
1121
1079
  type XGetHashflagsResponse as XGetHashflagsResponse,
1080
+ type XGetNewsStoryVersionsResponse as XGetNewsStoryVersionsResponse,
1122
1081
  type XGetNotificationsResponse as XGetNotificationsResponse,
1123
1082
  type XGetTrendLocationsResponse as XGetTrendLocationsResponse,
1124
1083
  type XGetTrendsResponse as XGetTrendsResponse,
1084
+ type XGetTrendsHistoryResponse as XGetTrendsHistoryResponse,
1125
1085
  type XSearchPlacesResponse as XSearchPlacesResponse,
1126
1086
  type XAutocompleteSearchParams as XAutocompleteSearchParams,
1127
1087
  type XGetArticleParams as XGetArticleParams,
1128
1088
  type XGetHashflagsParams as XGetHashflagsParams,
1129
1089
  type XGetHomeTimelineParams as XGetHomeTimelineParams,
1090
+ type XGetNewsStoryVersionsParams as XGetNewsStoryVersionsParams,
1130
1091
  type XGetNotificationsParams as XGetNotificationsParams,
1131
1092
  type XGetTrendLocationsParams as XGetTrendLocationsParams,
1132
1093
  type XGetTrendsParams as XGetTrendsParams,
1094
+ type XGetTrendsHistoryParams as XGetTrendsHistoryParams,
1133
1095
  type XSearchPlacesParams as XSearchPlacesParams,
1134
1096
  };
1135
1097
 
@@ -24,9 +24,6 @@ export class APIPromise<T> extends Promise<T> {
24
24
  ) => PromiseOrValue<T> = defaultParseResponse,
25
25
  ) {
26
26
  super((resolve) => {
27
- // this is maybe a bit weird but this has to be a no-op to not implicitly
28
- // parse the response body; instead .then, .catch, .finally are overridden
29
- // to parse the response
30
27
  resolve(null as any);
31
28
  });
32
29
  this.#client = client;
@@ -44,10 +41,6 @@ export class APIPromise<T> extends Promise<T> {
44
41
  *
45
42
  * If you want to parse the response body but still get the `Response`
46
43
  * instance, you can use {@link withResponse()}.
47
- *
48
- * 👋 Getting the wrong TypeScript type for `Response`?
49
- * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
50
- * to your `tsconfig.json`.
51
44
  */
52
45
  asResponse(): Promise<Response> {
53
46
  return this.responsePromise.then((p) => p.response);
@@ -58,10 +51,6 @@ export class APIPromise<T> extends Promise<T> {
58
51
  *
59
52
  * If you just want to get the raw `Response` instance without parsing it,
60
53
  * you can use {@link asResponse()}.
61
- *
62
- * 👋 Getting the wrong TypeScript type for `Response`?
63
- * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
64
- * to your `tsconfig.json`.
65
54
  */
66
55
  async withResponse(): Promise<{ data: T; response: Response }> {
67
56
  const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
package/src/core/error.ts CHANGED
@@ -103,7 +103,6 @@ export class APIUserAbortError extends APIError<undefined, undefined, undefined>
103
103
  export class APIConnectionError extends APIError<undefined, undefined, undefined> {
104
104
  constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
105
105
  super(undefined, undefined, message || 'Connection error.', undefined);
106
- // in some environments the 'cause' property is already declared
107
106
  // @ts-ignore
108
107
  if (cause) this.cause = cause;
109
108
  }
@@ -51,7 +51,6 @@ export class Stream<Item> implements AsyncIterable<Item> {
51
51
  let done = false;
52
52
  try {
53
53
  for await (const sse of _iterSSEMessages(response, controller)) {
54
- // Each event is named by its type, so every event with data is yielded.
55
54
  if (!sse.data) continue;
56
55
 
57
56
  try {
@@ -64,11 +63,9 @@ export class Stream<Item> implements AsyncIterable<Item> {
64
63
  }
65
64
  done = true;
66
65
  } catch (e) {
67
- // If the user calls `stream.controller.abort()`, we should exit without throwing.
68
66
  if (isAbortError(e)) return;
69
67
  throw e;
70
68
  } finally {
71
- // If the user `break`s, abort the ongoing request.
72
69
  if (!done) controller.abort();
73
70
  }
74
71
  }
@@ -117,11 +114,9 @@ export class Stream<Item> implements AsyncIterable<Item> {
117
114
  }
118
115
  done = true;
119
116
  } catch (e) {
120
- // If the user calls `stream.controller.abort()`, we should exit without throwing.
121
117
  if (isAbortError(e)) return;
122
118
  throw e;
123
119
  } finally {
124
- // If the user `break`s, abort the ongoing request.
125
120
  if (!done) controller.abort();
126
121
  }
127
122
  }
@@ -227,10 +222,6 @@ export async function* _iterSSEMessages(
227
222
  }
228
223
  }
229
224
 
230
- /**
231
- * Given an async iterable iterator, iterates over it and yields full
232
- * SSE chunks, i.e. yields when a double new-line is encountered.
233
- */
234
225
  async function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGenerator<Uint8Array> {
235
226
  let data = new Uint8Array();
236
227
 
@@ -278,7 +269,6 @@ class SSEDecoder {
278
269
  }
279
270
 
280
271
  if (!line) {
281
- // empty line and we didn't previously encounter any messages
282
272
  if (!this.event && !this.data.length) return null;
283
273
 
284
274
  const sse: ServerSentEvent = {
@@ -4,53 +4,18 @@
4
4
 
5
5
  export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
6
6
 
7
- /**
8
- * An alias to the builtin `RequestInit` type so we can
9
- * easily alias it in import statements if there are name clashes.
10
- *
11
- * https://developer.mozilla.org/docs/Web/API/RequestInit
12
- */
13
7
  type _RequestInit = RequestInit;
14
8
 
15
- /**
16
- * An alias to the builtin `Response` type so we can
17
- * easily alias it in import statements if there are name clashes.
18
- *
19
- * https://developer.mozilla.org/docs/Web/API/Response
20
- */
21
9
  type _Response = Response;
22
10
 
23
- /**
24
- * The type for the first argument to `fetch`.
25
- *
26
- * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
27
- */
28
11
  type _RequestInfo = Request | URL | string;
29
12
 
30
- /**
31
- * The type for constructing `RequestInit` Headers.
32
- *
33
- * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
34
- */
35
13
  type _HeadersInit = RequestInit['headers'];
36
14
 
37
- /**
38
- * The type for constructing `RequestInit` body.
39
- *
40
- * https://developer.mozilla.org/docs/Web/API/RequestInit#body
41
- */
42
15
  type _BodyInit = RequestInit['body'];
43
16
 
44
- /**
45
- * An alias to the builtin `Array<T>` type so we can
46
- * easily alias it in import statements if there are name clashes.
47
- */
48
17
  type _Array<T> = Array<T>;
49
18
 
50
- /**
51
- * An alias to the builtin `Record<K, T>` type so we can
52
- * easily alias it in import statements if there are name clashes.
53
- */
54
19
  type _Record<K extends keyof any, T> = Record<K, T>;
55
20
 
56
21
  export type {
@@ -63,12 +28,6 @@ export type {
63
28
  _Response as Response,
64
29
  };
65
30
 
66
- /**
67
- * A copy of the builtin `EndingType` type as it isn't fully supported in certain
68
- * environments and attempting to reference the global version will error.
69
- *
70
- * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
71
- */
72
31
  type EndingType = 'native' | 'transparent';
73
32
 
74
33
  /**
@@ -40,12 +40,10 @@ export class LineDecoder {
40
40
  let patternIndex;
41
41
  while ((patternIndex = findNewlineIndex(this.#buffer, this.#carriageReturnIndex)) != null) {
42
42
  if (patternIndex.carriage && this.#carriageReturnIndex == null) {
43
- // skip until we either get a corresponding `\n`, a new `\r` or nothing
44
43
  this.#carriageReturnIndex = patternIndex.index;
45
44
  continue;
46
45
  }
47
46
 
48
- // we got double \r or \rtext\n
49
47
  if (
50
48
  this.#carriageReturnIndex != null &&
51
49
  (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
@@ -77,21 +75,12 @@ export class LineDecoder {
77
75
  }
78
76
  }
79
77
 
80
- /**
81
- * This function searches the buffer for the end patterns, (\r or \n)
82
- * and returns an object with the index preceding the matched newline and the
83
- * index after the newline char. `null` is returned if no new line is found.
84
- *
85
- * ```ts
86
- * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
87
- * ```
88
- */
89
78
  function findNewlineIndex(
90
79
  buffer: Uint8Array,
91
80
  startIndex: number | null,
92
81
  ): { preceding: number; index: number; carriage: boolean } | null {
93
- const newline = 0x0a; // \n
94
- const carriage = 0x0d; // \r
82
+ const newline = 0x0a;
83
+ const carriage = 0x0d;
95
84
 
96
85
  for (let i = startIndex ?? 0; i < buffer.length; i++) {
97
86
  if (buffer[i] === newline) {
@@ -107,19 +96,14 @@ function findNewlineIndex(
107
96
  }
108
97
 
109
98
  export function findDoubleNewlineIndex(buffer: Uint8Array): number {
110
- // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
111
- // and returns the index right after the first occurrence of any pattern,
112
- // or -1 if none of the patterns are found.
113
- const newline = 0x0a; // \n
114
- const carriage = 0x0d; // \r
99
+ const newline = 0x0a;
100
+ const carriage = 0x0d;
115
101
 
116
102
  for (let i = 0; i < buffer.length - 1; i++) {
117
103
  if (buffer[i] === newline && buffer[i + 1] === newline) {
118
- // \n\n
119
104
  return i + 2;
120
105
  }
121
106
  if (buffer[i] === carriage && buffer[i + 1] === carriage) {
122
- // \r\r
123
107
  return i + 2;
124
108
  }
125
109
  if (
@@ -129,7 +113,6 @@ export function findDoubleNewlineIndex(buffer: Uint8Array): number {
129
113
  buffer[i + 2] === carriage &&
130
114
  buffer[i + 3] === newline
131
115
  ) {
132
- // \r\n\r\n
133
116
  return i + 4;
134
117
  }
135
118
  }
@@ -17,9 +17,6 @@ export const isRunningInBrowser = () => {
17
17
 
18
18
  type DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';
19
19
 
20
- /**
21
- * Note this does not detect 'browser'; for that, use getBrowserInfo().
22
- */
23
20
  function getDetectedPlatform(): DetectedPlatform {
24
21
  if (typeof Deno !== 'undefined' && Deno.build != null) {
25
22
  return 'deno';
@@ -74,7 +71,6 @@ const getPlatformProperties = (): PlatformProperties => {
74
71
  'X-Stainless-Runtime-Version': (globalThis as any).process.version,
75
72
  };
76
73
  }
77
- // Check if Node.js
78
74
  if (detectedPlatform === 'node') {
79
75
  return {
80
76
  'X-Stainless-Lang': 'js',
@@ -98,7 +94,6 @@ const getPlatformProperties = (): PlatformProperties => {
98
94
  };
99
95
  }
100
96
 
101
- // TODO add support for Cloudflare workers, etc.
102
97
  return {
103
98
  'X-Stainless-Lang': 'js',
104
99
  'X-Stainless-Package-Version': VERSION,
@@ -122,7 +117,6 @@ function getBrowserInfo(): BrowserInfo | null {
122
117
  return null;
123
118
  }
124
119
 
125
- // NOTE: The order matters here!
126
120
  const browserPatterns = [
127
121
  { key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
128
122
  { key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
@@ -132,7 +126,6 @@ function getBrowserInfo(): BrowserInfo | null {
132
126
  { key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
133
127
  ];
134
128
 
135
- // Find the FIRST matching browser
136
129
  for (const { key, pattern } of browserPatterns) {
137
130
  const match = pattern.exec(navigator.userAgent);
138
131
  if (match) {
@@ -148,10 +141,6 @@ function getBrowserInfo(): BrowserInfo | null {
148
141
  }
149
142
 
150
143
  const normalizeArch = (arch: string): Arch => {
151
- // Node docs:
152
- // - https://nodejs.org/api/process.html#processarch
153
- // Deno docs:
154
- // - https://doc.deno.land/deno/stable/~/Deno.build
155
144
  if (arch === 'x32') return 'x32';
156
145
  if (arch === 'x86_64' || arch === 'x64') return 'x64';
157
146
  if (arch === 'arm') return 'arm';
@@ -161,18 +150,8 @@ const normalizeArch = (arch: string): Arch => {
161
150
  };
162
151
 
163
152
  const normalizePlatform = (platform: string): PlatformName => {
164
- // Node platforms:
165
- // - https://nodejs.org/api/process.html#processplatform
166
- // Deno platforms:
167
- // - https://doc.deno.land/deno/stable/~/Deno.build
168
- // - https://github.com/denoland/deno/issues/14799
169
-
170
153
  platform = platform.toLowerCase();
171
154
 
172
- // NOTE: this iOS check is untested and may not work
173
- // Node does not work natively on IOS, there is a fork at
174
- // https://github.com/nodejs-mobile/nodejs-mobile
175
- // however it is unknown at the time of writing how to detect if it is running
176
155
  if (platform.includes('ios')) return 'iOS';
177
156
  if (platform === 'android') return 'Android';
178
157
  if (platform === 'darwin') return 'MacOS';
@@ -6,9 +6,7 @@ export function isAbortError(err: unknown) {
6
6
  return (
7
7
  typeof err === 'object' &&
8
8
  err !== null &&
9
- // Spec-compliant fetch implementations
10
9
  (('name' in err && (err as any).name === 'AbortError') ||
11
- // Expo fetch
12
10
  ('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))
13
11
  );
14
12
  }