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
@@ -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];
@@ -22,12 +22,9 @@ export async function defaultParseResponse<T>(client: XTwitterScraper, props: AP
22
22
  if (props.options.stream) {
23
23
  loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
24
24
 
25
- // Note: there is an invariant here that isn't represented in the type system
26
- // that if you set `stream: true` the response type must also be `Stream<T>`
27
25
  return Stream.fromSSEResponse(response, props.controller, client) as any;
28
26
  }
29
27
 
30
- // fetch refuses to read the body when the status code is 204.
31
28
  if (response.status === 204) {
32
29
  return null as T;
33
30
  }
@@ -42,7 +39,6 @@ export async function defaultParseResponse<T>(client: XTwitterScraper, props: AP
42
39
  if (isJSON) {
43
40
  const contentLength = response.headers.get('content-length');
44
41
  if (contentLength === '0') {
45
- // if there is no content we can't do anything
46
42
  return undefined as T;
47
43
  }
48
44
 
@@ -2,13 +2,6 @@
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
- /**
6
- * Shims for types that we can't always rely on being available globally.
7
- *
8
- * Note: these only exist at the type-level, there is no corresponding runtime
9
- * version for any of these symbols.
10
- */
11
-
12
5
  type NeverToAny<T> = T extends never ? any : T;
13
6
 
14
7
  /** @ts-ignore */
@@ -2,13 +2,6 @@
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
- /**
6
- * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
7
- *
8
- * These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error
9
- * messages in cases where an environment isn't fully supported.
10
- */
11
-
12
5
  import type { Fetch } from './builtin-types';
13
6
  import type { ReadableStream } from './shim-types';
14
7
 
@@ -27,8 +20,6 @@ type ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;
27
20
  export function makeReadableStream(...args: ReadableStreamArgs): ReadableStream {
28
21
  const ReadableStream = (globalThis as any).ReadableStream;
29
22
  if (typeof ReadableStream === 'undefined') {
30
- // Note: All of the platforms / runtimes we officially support already define
31
- // `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
32
23
  throw new Error(
33
24
  '`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`',
34
25
  );
@@ -58,9 +49,6 @@ export function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>):
58
49
  }
59
50
 
60
51
  /**
61
- * Most browsers don't yet have async iterable support for ReadableStream,
62
- * and Node has a very different way of reading bytes from its "ReadableStream".
63
- *
64
52
  * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
65
53
  */
66
54
  export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
@@ -71,10 +59,10 @@ export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIter
71
59
  async next() {
72
60
  try {
73
61
  const result = await reader.read();
74
- if (result?.done) reader.releaseLock(); // release lock when stream becomes closed
62
+ if (result?.done) reader.releaseLock();
75
63
  return result;
76
64
  } catch (e) {
77
- reader.releaseLock(); // release lock when stream becomes errored
65
+ reader.releaseLock();
78
66
  throw e;
79
67
  }
80
68
  },
@@ -8,24 +8,13 @@ import { checkFileSupport } from './uploads';
8
8
 
9
9
  type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
10
10
 
11
- /**
12
- * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
13
- * Don't add arrayBuffer here, node-fetch doesn't have it
14
- */
15
11
  interface BlobLike {
16
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
17
12
  readonly size: number;
18
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
19
13
  readonly type: string;
20
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
21
14
  text(): Promise<string>;
22
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
23
15
  slice(start?: number, end?: number): BlobLike;
24
16
  }
25
17
 
26
- /**
27
- * This check adds the arrayBuffer() method type because it is available and used at runtime
28
- */
29
18
  const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
30
19
  value != null &&
31
20
  typeof value === 'object' &&
@@ -35,19 +24,11 @@ const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<Ar
35
24
  typeof value.slice === 'function' &&
36
25
  typeof value.arrayBuffer === 'function';
37
26
 
38
- /**
39
- * Intended to match DOM File, node:buffer File, undici File, etc.
40
- */
41
27
  interface FileLike extends BlobLike {
42
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
43
28
  readonly lastModified: number;
44
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
45
29
  readonly name?: string | undefined;
46
30
  }
47
31
 
48
- /**
49
- * This check adds the arrayBuffer() method type because it is available and used at runtime
50
- */
51
32
  const isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
52
33
  value != null &&
53
34
  typeof value === 'object' &&
@@ -55,9 +36,6 @@ const isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<Ar
55
36
  typeof value.lastModified === 'number' &&
56
37
  isBlobLike(value);
57
38
 
58
- /**
59
- * Intended to match DOM Response, node-fetch Response, undici Response, etc.
60
- */
61
39
  export interface ResponseLike {
62
40
  url: string;
63
41
  blob(): Promise<BlobLike>;
@@ -88,10 +66,8 @@ export async function toFile(
88
66
  ): Promise<File> {
89
67
  checkFileSupport();
90
68
 
91
- // If it's a promise, resolve it.
92
69
  value = await value;
93
70
 
94
- // If we've been given a `File` we don't need to do anything
95
71
  if (isFileLike(value)) {
96
72
  if (value instanceof File) {
97
73
  return value;
@@ -122,19 +98,13 @@ export async function toFile(
122
98
 
123
99
  async function getBytes(value: BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>> {
124
100
  let parts: Array<BlobPart> = [];
125
- if (
126
- typeof value === 'string' ||
127
- ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
128
- value instanceof ArrayBuffer
129
- ) {
101
+ if (typeof value === 'string' || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
130
102
  parts.push(value);
131
103
  } else if (isBlobLike(value)) {
132
104
  parts.push(value instanceof Blob ? value : await value.arrayBuffer());
133
- } else if (
134
- isAsyncIterable(value) // includes Readable, ReadableStream, etc.
135
- ) {
105
+ } else if (isAsyncIterable(value)) {
136
106
  for await (const chunk of value) {
137
- parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?
107
+ parts.push(...(await getBytes(chunk as BlobLikePart)));
138
108
  }
139
109
  } else {
140
110
  const constructor = value?.constructor?.name;
@@ -11,9 +11,6 @@ export type FinalizedRequestInit = RequestInit & { headers: Headers };
11
11
 
12
12
  type NotAny<T> = [0] extends [1 & T] ? never : T;
13
13
 
14
- /**
15
- * Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
16
- */
17
14
  type OverloadedParameters<T> =
18
15
  T extends (
19
16
  {
@@ -43,28 +40,6 @@ type OverloadedParameters<T> =
43
40
  : never;
44
41
 
45
42
  /* eslint-disable */
46
- /**
47
- * These imports attempt to get types from a parent package's dependencies.
48
- * Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
49
- * would cause typescript to show types not present at runtime. To avoid this, we import
50
- * directly from parent node_modules folders.
51
- *
52
- * We need to check multiple levels because we don't know what directory structure we'll be in.
53
- * For example, pnpm generates directories like this:
54
- * ```
55
- * node_modules
56
- * ├── .pnpm
57
- * │ └── pkg@1.0.0
58
- * │ └── node_modules
59
- * │ └── pkg
60
- * │ └── internal
61
- * │ └── types.d.ts
62
- * ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
63
- * └── undici
64
- * ```
65
- *
66
- * [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
67
- */
68
43
  /** @ts-ignore For users with \@types/node */
69
44
  type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
70
45
  /** @ts-ignore For users with undici */
@@ -88,10 +63,5 @@ type RequestInits =
88
63
  | NotAny<RequestInit>
89
64
  | NotAny<FetchRequestInit>;
90
65
 
91
- /**
92
- * This type contains `RequestInit` options that may be available on the current runtime,
93
- * including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
94
- */
95
66
  export type MergedRequestInit = RequestInits &
96
- /** We don't include these in the types as they'll be overridden for every request. */
97
67
  Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
@@ -40,10 +40,6 @@ export const checkFileSupport = () => {
40
40
  */
41
41
  export type Uploadable = File | Response | FsReadStream | BunFile;
42
42
 
43
- /**
44
- * Construct a `File` instance. This is used to ensure a helpful error is thrown
45
- * for environments that don't define a global `File` yet.
46
- */
47
43
  export function makeFile(
48
44
  fileBits: BlobPart[],
49
45
  fileName: string | undefined,
@@ -72,10 +68,6 @@ export function getName(value: any): string | undefined {
72
68
  export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
73
69
  value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
74
70
 
75
- /**
76
- * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
77
- * Otherwise returns the request as is.
78
- */
79
71
  export const maybeMultipartFormRequestOptions = async (
80
72
  opts: RequestOptions,
81
73
  fetch: XTwitterScraper | Fetch,
@@ -96,12 +88,6 @@ export const multipartFormRequestOptions = async (
96
88
 
97
89
  const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
98
90
 
99
- /**
100
- * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
101
- * properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
102
- * This function detects if the fetch function provided supports the global FormData object to avoid
103
- * confusing error messages later on.
104
- */
105
91
  function supportsFormData(fetchObject: XTwitterScraper | Fetch): Promise<boolean> {
106
92
  const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
107
93
  const cached = supportsFormDataMap.get(fetch);
@@ -118,7 +104,6 @@ function supportsFormData(fetchObject: XTwitterScraper | Fetch): Promise<boolean
118
104
  }
119
105
  return true;
120
106
  } catch {
121
- // avoid false negatives
122
107
  return true;
123
108
  }
124
109
  })();
@@ -140,8 +125,6 @@ export const createForm = async <T = Record<string, unknown>>(
140
125
  return form;
141
126
  };
142
127
 
143
- // We check for Blob not File because Bun.File doesn't inherit from File,
144
- // but they both inherit from Blob and have a `name` property at runtime.
145
128
  const isNamedBlob = (value: unknown) => value instanceof Blob && 'name' in value;
146
129
 
147
130
  const isUploadable = (value: unknown) =>
@@ -168,7 +151,6 @@ const addFormValue = async (form: FormData, key: string, value: unknown): Promis
168
151
  );
169
152
  }
170
153
 
171
- // TODO: make nested formats configurable
172
154
  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
173
155
  form.append(key, String(value));
174
156
  } else if (value instanceof Response) {
@@ -2,13 +2,6 @@
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
 
5
- /**
6
- * Read an environment variable.
7
- *
8
- * Trims beginning and trailing whitespace.
9
- *
10
- * Will return undefined if the environment variable doesn't exist or cannot be accessed.
11
- */
12
5
  export const readEnv = (env: string): string | undefined => {
13
6
  if (typeof (globalThis as any).process !== 'undefined') {
14
7
  return (globalThis as any).process.env?.[env]?.trim() || undefined;
@@ -48,7 +48,6 @@ function makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel:
48
48
  if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
49
49
  return noop;
50
50
  } else {
51
- // Don't wrap logger functions, we want the stacktrace intact!
52
51
  return logger[fnLevel].bind(logger);
53
52
  }
54
53
  }
@@ -100,7 +99,7 @@ export const formatRequestDetails = (details: {
100
99
  }) => {
101
100
  if (details.options) {
102
101
  details.options = { ...details.options };
103
- delete details.options['headers']; // redundant + leaks internals
102
+ delete details.options['headers'];
104
103
  }
105
104
  if (details.headers) {
106
105
  details.headers = Object.fromEntries(
@@ -20,7 +20,6 @@ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null))
20
20
 
21
21
  export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
22
22
  function path(statics: readonly string[], ...params: readonly unknown[]): string {
23
- // If there are no params, no processing is needed.
24
23
  if (statics.length === 1) return statics[0]!;
25
24
 
26
25
  let postPath = false;
@@ -35,7 +34,6 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
35
34
  index !== params.length &&
36
35
  (value == null ||
37
36
  (typeof value === 'object' &&
38
- // handle values from other realms
39
37
  value.toString ===
40
38
  Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
41
39
  ?.toString))
@@ -56,7 +54,6 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
56
54
  const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
57
55
  let match;
58
56
 
59
- // Find all invalid segments
60
57
  while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
61
58
  invalidSegments.push({
62
59
  start: match.index,
@@ -86,7 +83,4 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
86
83
  return path;
87
84
  };
88
85
 
89
- /**
90
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
91
- */
92
86
  export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
@@ -4,9 +4,6 @@
4
4
 
5
5
  import { XTwitterScraperError } from '../../core/error';
6
6
 
7
- /**
8
- * Basic re-implementation of `qs.stringify` for primitive types.
9
- */
10
7
  export function stringifyQuery(query: object | Record<string, unknown>) {
11
8
  return Object.entries(query)
12
9
  .filter(([_, value]) => typeof value !== 'undefined')
@@ -14,7 +14,6 @@ export const isAbsoluteURL = (url: string): boolean => {
14
14
  export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
15
15
  export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
16
16
 
17
- /** Returns an object if the given value isn't an object, otherwise returns as-is */
18
17
  export function maybeObj(x: unknown): object {
19
18
  if (typeof x !== 'object') {
20
19
  return {};
@@ -23,14 +22,12 @@ export function maybeObj(x: unknown): object {
23
22
  return x ?? {};
24
23
  }
25
24
 
26
- // https://stackoverflow.com/a/34491287
27
25
  export function isEmptyObj(obj: Object | null | undefined): boolean {
28
26
  if (!obj) return true;
29
27
  for (const _k in obj) return false;
30
28
  return true;
31
29
  }
32
30
 
33
- // https://eslint.org/docs/latest/rules/no-prototype-builtins
34
31
  export function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {
35
32
  return Object.prototype.hasOwnProperty.call(obj, key);
36
33
  }
@@ -125,16 +125,20 @@ export {
125
125
  type XAutocompleteSearchResponse,
126
126
  type XGetArticleResponse,
127
127
  type XGetHashflagsResponse,
128
+ type XGetNewsStoryVersionsResponse,
128
129
  type XGetNotificationsResponse,
129
130
  type XGetTrendLocationsResponse,
130
131
  type XGetTrendsResponse,
132
+ type XGetTrendsHistoryResponse,
131
133
  type XSearchPlacesResponse,
132
134
  type XAutocompleteSearchParams,
133
135
  type XGetArticleParams,
134
136
  type XGetHashflagsParams,
135
137
  type XGetHomeTimelineParams,
138
+ type XGetNewsStoryVersionsParams,
136
139
  type XGetNotificationsParams,
137
140
  type XGetTrendLocationsParams,
138
141
  type XGetTrendsParams,
142
+ type XGetTrendsHistoryParams,
139
143
  type XSearchPlacesParams,
140
144
  } from './x/x';