x-twitter-scraper 0.13.3 → 0.14.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 (196) hide show
  1. package/CHANGELOG.md +12 -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 +4 -50
  8. package/client.js.map +1 -1
  9. package/client.mjs +4 -50
  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 +2 -2
  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/x.d.mts +255 -1
  161. package/resources/x/x.d.mts.map +1 -1
  162. package/resources/x/x.d.ts +255 -1
  163. package/resources/x/x.d.ts.map +1 -1
  164. package/resources/x/x.js +38 -0
  165. package/resources/x/x.js.map +1 -1
  166. package/resources/x/x.mjs +38 -0
  167. package/resources/x/x.mjs.map +1 -1
  168. package/src/client.ts +12 -52
  169. package/src/core/api-promise.ts +0 -11
  170. package/src/core/error.ts +0 -1
  171. package/src/core/streaming.ts +0 -10
  172. package/src/internal/builtin-types.ts +0 -41
  173. package/src/internal/decoders/line.ts +4 -21
  174. package/src/internal/detect-platform.ts +0 -21
  175. package/src/internal/errors.ts +0 -2
  176. package/src/internal/headers.ts +0 -10
  177. package/src/internal/parse.ts +0 -4
  178. package/src/internal/shim-types.ts +0 -7
  179. package/src/internal/shims.ts +2 -14
  180. package/src/internal/to-file.ts +3 -33
  181. package/src/internal/types.ts +0 -30
  182. package/src/internal/uploads.ts +0 -18
  183. package/src/internal/utils/env.ts +0 -7
  184. package/src/internal/utils/log.ts +1 -2
  185. package/src/internal/utils/path.ts +0 -6
  186. package/src/internal/utils/query.ts +0 -3
  187. package/src/internal/utils/values.ts +0 -3
  188. package/src/resources/index.ts +4 -0
  189. package/src/resources/x/community-notes.ts +1040 -0
  190. package/src/resources/x/index.ts +13 -0
  191. package/src/resources/x/x.ts +335 -0
  192. package/src/version.ts +1 -1
  193. package/version.d.mts +1 -1
  194. package/version.d.ts +1 -1
  195. package/version.js +1 -1
  196. 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
  *
@@ -147,6 +164,26 @@ export class X extends APIResource {
147
164
  getTrends(query = {}, options) {
148
165
  return this._client.get('/x/trends', { query, ...options });
149
166
  }
167
+ /**
168
+ * Returns the Twitter trends archive of a place, as the lists X showed there over a
169
+ * range of time. Use it for trending on Twitter yesterday, last week or any day
170
+ * since 2026-10-13 02:20 UTC. Xquik stores 1 list per place every 5 minutes and
171
+ * keeps it for 25 months. Pick the place by woeid, country or location name, the
172
+ * range with from & to, and the step with every. from & to take a time or a span
173
+ * back from now, such as 7d, so a schedule can read the last day on every run.
174
+ * Each step returns the first list stored in it, with its own time. Each returned
175
+ * list costs 1 credit, so 24 lists cost 24 credits. A step with no stored list
176
+ * returns none and costs nothing. 1 request returns 24 lists, or up to 100 with
177
+ * limit.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * const response = await client.x.getTrendsHistory();
182
+ * ```
183
+ */
184
+ getTrendsHistory(query = {}, options) {
185
+ return this._client.get('/x/trends/history', { query, ...options });
186
+ }
150
187
  /**
151
188
  * Finds places on X by name. Pass a place's id as place to /x/tweets/search to
152
189
  * read posts tagged there. X ranks the places, so their order can differ between
@@ -177,5 +214,6 @@ X.AccountConnectionAttempts = AccountConnectionAttempts;
177
214
  X.Bookmarks = Bookmarks;
178
215
  X.Lists = Lists;
179
216
  X.Broadcasts = Broadcasts;
217
+ X.CommunityNotes = CommunityNotes;
180
218
  X.Spaces = Spaces;
181
219
  //# 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,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C,kBAAkB,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;CACF;AAi3CD,CAAC,CAAC,YAAY,GAAG,YAAY,CAAC;AAC9B,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACtB,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;AAClB,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;AAChB,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC;AACxB,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;AACd,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;AACV,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;AAChB,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;AACpB,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC;AAC5B,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACtB,CAAC,CAAC,2BAA2B,GAAG,2BAA2B,CAAC;AAC5D,CAAC,CAAC,yBAAyB,GAAG,yBAAyB,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,
@@ -204,7 +208,7 @@ export interface ClientOptions {
204
208
  /**
205
209
  * Specify a custom `fetch` function implementation.
206
210
  *
207
- * If not provided, we expect that `fetch` is defined globally.
211
+ * Defaults to globalThis.fetch.
208
212
  */
209
213
  fetch?: Fetch | undefined;
210
214
 
@@ -293,10 +297,9 @@ export class XTwitterScraper {
293
297
  };
294
298
 
295
299
  this.baseURL = options.baseURL!;
296
- this.timeout = options.timeout ?? XTwitterScraper.DEFAULT_TIMEOUT; /* 1 minute */
300
+ this.timeout = options.timeout ?? XTwitterScraper.DEFAULT_TIMEOUT;
297
301
  this.logger = options.logger ?? console;
298
302
  const defaultLogLevel = 'warn';
299
- // Set default logLevel early so that we can log a warning in parseLogLevel.
300
303
  this.logLevel = defaultLogLevel;
301
304
  this.logLevel =
302
305
  parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
@@ -345,9 +348,6 @@ export class XTwitterScraper {
345
348
  return client;
346
349
  }
347
350
 
348
- /**
349
- * Check whether the base URL is set to its default.
350
- */
351
351
  #baseURLOverridden(): boolean {
352
352
  return this.baseURL !== 'https://xquik.com/api/v1';
353
353
  }
@@ -400,9 +400,6 @@ export class XTwitterScraper {
400
400
  return buildHeaders([{ Authorization: `Bearer ${this.bearerToken}` }]);
401
401
  }
402
402
 
403
- /**
404
- * Basic re-implementation of `qs.stringify` for primitive types.
405
- */
406
403
  protected stringifyQuery(query: object | Record<string, unknown>): string {
407
404
  return stringifyQuery(query);
408
405
  }
@@ -448,17 +445,8 @@ export class XTwitterScraper {
448
445
  return url.toString();
449
446
  }
450
447
 
451
- /**
452
- * Used as a callback for mutating the given `FinalRequestOptions` object.
453
- */
454
448
  protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
455
449
 
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
450
  protected async prepareRequest(
463
451
  request: RequestInit,
464
452
  { url, options }: { url: string; options: FinalRequestOptions },
@@ -522,7 +510,6 @@ export class XTwitterScraper {
522
510
 
523
511
  await this.prepareRequest(req, { url, options });
524
512
 
525
- /** Not an API request ID, just for correlating local log entries. */
526
513
  const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
527
514
  const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
528
515
  const startTime = Date.now();
@@ -551,10 +538,6 @@ export class XTwitterScraper {
551
538
  if (options.signal?.aborted) {
552
539
  throw new Errors.APIUserAbortError();
553
540
  }
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
541
  const isTimeout =
559
542
  isAbortError(response) ||
560
543
  /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
@@ -600,7 +583,6 @@ export class XTwitterScraper {
600
583
  if (retriesRemaining && shouldRetry) {
601
584
  const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
602
585
 
603
- // We don't need the body of this response.
604
586
  await Shims.CancelReadableStream(response.body);
605
587
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
606
588
  loggerFor(this).debug(
@@ -689,7 +671,6 @@ export class XTwitterScraper {
689
671
  }
690
672
 
691
673
  try {
692
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
693
674
  return await this.fetch.call(undefined, url, fetchOptions);
694
675
  } finally {
695
676
  clearTimeout(timeout);
@@ -697,23 +678,17 @@ export class XTwitterScraper {
697
678
  }
698
679
 
699
680
  private async shouldRetry(response: Response): Promise<boolean> {
700
- // Note this is not a standard header.
701
681
  const shouldRetryHeader = response.headers.get('x-should-retry');
702
682
 
703
- // If the server explicitly says whether or not to retry, obey.
704
683
  if (shouldRetryHeader === 'true') return true;
705
684
  if (shouldRetryHeader === 'false') return false;
706
685
 
707
- // Retry on request timeouts.
708
686
  if (response.status === 408) return true;
709
687
 
710
- // Retry on lock timeouts.
711
688
  if (response.status === 409) return true;
712
689
 
713
- // Retry on rate limits.
714
690
  if (response.status === 429) return true;
715
691
 
716
- // Retry internal errors.
717
692
  if (response.status >= 500) return true;
718
693
 
719
694
  return false;
@@ -727,7 +702,6 @@ export class XTwitterScraper {
727
702
  ): Promise<APIResponseProps> {
728
703
  let timeoutMillis: number | undefined;
729
704
 
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
705
  const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
732
706
  if (retryAfterMillisHeader) {
733
707
  const timeoutMs = parseFloat(retryAfterMillisHeader);
@@ -736,7 +710,6 @@ export class XTwitterScraper {
736
710
  }
737
711
  }
738
712
 
739
- // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
740
713
  const retryAfterHeader = responseHeaders?.get('retry-after');
741
714
  if (retryAfterHeader && !timeoutMillis) {
742
715
  const timeoutSeconds = parseFloat(retryAfterHeader);
@@ -747,8 +720,6 @@ export class XTwitterScraper {
747
720
  }
748
721
  }
749
722
 
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
723
  if (timeoutMillis === undefined) {
753
724
  const maxRetries = options.maxRetries ?? this.maxRetries;
754
725
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
@@ -764,10 +735,8 @@ export class XTwitterScraper {
764
735
 
765
736
  const numRetries = maxRetries - retriesRemaining;
766
737
 
767
- // Apply exponential backoff, but not more than the max.
768
738
  const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
769
739
 
770
- // Apply some jitter, take up to at most 25 percent of the retry time.
771
740
  const jitter = 1 - Math.random() * 0.25;
772
741
 
773
742
  return sleepSeconds * jitter * 1000;
@@ -841,8 +810,6 @@ export class XTwitterScraper {
841
810
  }
842
811
 
843
812
  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
813
  return () => controller.abort();
847
814
  }
848
815
 
@@ -852,10 +819,6 @@ export class XTwitterScraper {
852
819
  } {
853
820
  const { body, headers: rawHeaders } = options;
854
821
  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
822
  if (body == null && 'body' in options) {
860
823
  return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
861
824
  }
@@ -863,20 +826,13 @@ export class XTwitterScraper {
863
826
  }
864
827
  const headers = buildHeaders([rawHeaders]);
865
828
  if (
866
- // Pass raw type verbatim
867
829
  ArrayBuffer.isView(body) ||
868
830
  body instanceof ArrayBuffer ||
869
831
  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`
832
+ (typeof body === 'string' && headers.values.has('content-type')) ||
874
833
  ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
875
- // `FormData` -> `multipart/form-data`
876
834
  body instanceof FormData ||
877
- // `URLSearchParams` -> `application/x-www-form-urlencoded`
878
835
  body instanceof URLSearchParams ||
879
- // Send chunked stream (each chunk has own `length`)
880
836
  ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
881
837
  ) {
882
838
  return { bodyHeaders: undefined, body: body as BodyInit };
@@ -900,7 +856,7 @@ export class XTwitterScraper {
900
856
  }
901
857
 
902
858
  static XTwitterScraper = this;
903
- static DEFAULT_TIMEOUT = 60000; // 1 minute
859
+ static DEFAULT_TIMEOUT = 60000;
904
860
 
905
861
  static XTwitterScraperError = Errors.XTwitterScraperError;
906
862
  static APIError = Errors.APIError;
@@ -1119,17 +1075,21 @@ export declare namespace XTwitterScraper {
1119
1075
  type XAutocompleteSearchResponse as XAutocompleteSearchResponse,
1120
1076
  type XGetArticleResponse as XGetArticleResponse,
1121
1077
  type XGetHashflagsResponse as XGetHashflagsResponse,
1078
+ type XGetNewsStoryVersionsResponse as XGetNewsStoryVersionsResponse,
1122
1079
  type XGetNotificationsResponse as XGetNotificationsResponse,
1123
1080
  type XGetTrendLocationsResponse as XGetTrendLocationsResponse,
1124
1081
  type XGetTrendsResponse as XGetTrendsResponse,
1082
+ type XGetTrendsHistoryResponse as XGetTrendsHistoryResponse,
1125
1083
  type XSearchPlacesResponse as XSearchPlacesResponse,
1126
1084
  type XAutocompleteSearchParams as XAutocompleteSearchParams,
1127
1085
  type XGetArticleParams as XGetArticleParams,
1128
1086
  type XGetHashflagsParams as XGetHashflagsParams,
1129
1087
  type XGetHomeTimelineParams as XGetHomeTimelineParams,
1088
+ type XGetNewsStoryVersionsParams as XGetNewsStoryVersionsParams,
1130
1089
  type XGetNotificationsParams as XGetNotificationsParams,
1131
1090
  type XGetTrendLocationsParams as XGetTrendLocationsParams,
1132
1091
  type XGetTrendsParams as XGetTrendsParams,
1092
+ type XGetTrendsHistoryParams as XGetTrendsHistoryParams,
1133
1093
  type XSearchPlacesParams as XSearchPlacesParams,
1134
1094
  };
1135
1095
 
@@ -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
  }
@@ -15,17 +15,9 @@ export type HeadersLike =
15
15
 
16
16
  const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
17
17
 
18
- /**
19
- * @internal
20
- * Users can pass explicit nulls to unset default headers. When we parse them
21
- * into a standard headers type we need to preserve that information.
22
- */
23
18
  export type NullableHeaders = {
24
- /** Brand check, prevent users from creating a NullableHeaders. */
25
19
  [brand_privateNullableHeaders]: true;
26
- /** Parsed headers. */
27
20
  values: Headers;
28
- /** Set of lowercase header names explicitly set to null. */
29
21
  nulls: Set<string>;
30
22
  };
31
23
 
@@ -59,8 +51,6 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
59
51
  for (const value of values) {
60
52
  if (value === undefined) continue;
61
53
 
62
- // Objects keys always overwrite older headers, they never append.
63
- // Yield a null to clear the header before adding the new values.
64
54
  if (shouldClear && !didClear) {
65
55
  didClear = true;
66
56
  yield [name, null];