twitter-api-browser-js 0.0.7 → 0.0.9

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.
package/README.md CHANGED
@@ -2,4 +2,6 @@
2
2
  This is JavaScript version of [fa0311/twitter_api_browser_python](https://github.com/fa0311/twitter_api_browser_python);
3
3
  Look [example.ts](./example.ts);
4
4
 
5
+ notice: It doesn't work well with Bun or Deno due to compatibility issues.
6
+
5
7
  <img width="890" height="234" alt="image" src="https://github.com/user-attachments/assets/768a3524-5b2a-463d-b06c-cd39cdbb4f72" />
package/dist/main.d.ts CHANGED
@@ -47,5 +47,5 @@ export declare class TwitterAPIBrowser {
47
47
  * @param fieldToggles - The fields to toggle on or off in the operation
48
48
  * @returns Response of the request
49
49
  */
50
- request<T extends keyof TwitterOpenAPIModelsMapping = string>(operationName: T, variables: LooseType, fieldToggles?: Record<string, boolean>): Promise<SuccessResponse<T> | LooseErrorResponse>;
50
+ request<T extends keyof TwitterOpenAPIModelsMapping = string>(operationName: T, variables: LooseType, fieldToggles?: Record<string, boolean>, features?: Record<string, LooseType>): Promise<SuccessResponse<T> | LooseErrorResponse>;
51
51
  }
package/dist/main.js CHANGED
@@ -144,7 +144,9 @@ export class TwitterAPIBrowser {
144
144
  }
145
145
  await this.page.evaluate(SETUP_SCRIPT);
146
146
  await sleep(500);
147
- const response = [await this.page.evaluate(`globalThis.${REQUEST_FUNC_GLOBAL_KEY}(${JSON.stringify(removeNullRecursively(args))})`)].flat();
147
+ const response = [
148
+ await this.page.evaluate(`globalThis.${REQUEST_FUNC_GLOBAL_KEY}(${JSON.stringify(removeNullRecursively(args))})`),
149
+ ].flat();
148
150
  const result = pickFirstItem(response, "response");
149
151
  if (result instanceof Error) {
150
152
  console.log(`!!! Please report this error to the developer !!!`);
@@ -160,7 +162,7 @@ export class TwitterAPIBrowser {
160
162
  * @param fieldToggles - The fields to toggle on or off in the operation
161
163
  * @returns Response of the request
162
164
  */
163
- async request(operationName, variables, fieldToggles = {}) {
165
+ async request(operationName, variables, fieldToggles = {}, features = {}) {
164
166
  if (!this.page || !this.operations || !this.initialState) {
165
167
  throw new Error("Maybe you forgot to call setup()?");
166
168
  }
@@ -185,7 +187,9 @@ export class TwitterAPIBrowser {
185
187
  ...this.initialState.featureSwitch.debug,
186
188
  ...this.initialState.featureSwitch.customOverrides,
187
189
  };
188
- const featureSwitchesMap = Object.fromEntries(Object.entries(featureSwitch).filter(([k]) => featureSwitches.includes(k)).map(([k, v]) => [k, v.value]));
190
+ const featureSwitchesMap = Object.fromEntries(Object.entries(featureSwitch)
191
+ .filter(([k]) => featureSwitches.includes(k))
192
+ .map(([k, v]) => [k, v.value]));
189
193
  const body = {
190
194
  variables: variables,
191
195
  queryId: queryId,
@@ -195,9 +199,19 @@ export class TwitterAPIBrowser {
195
199
  if (featureSwitchesMap && Object.keys(featureSwitchesMap).length > 0) {
196
200
  body.features = featureSwitchesMap;
197
201
  }
198
- if (fieldToggle && Object.keys(fieldToggle).length > 0) {
202
+ if (features) {
203
+ body.features = features;
204
+ }
205
+ if (fieldToggle) {
199
206
  body.fieldToggle = fieldToggle;
200
207
  }
208
+ const otherProps = ["features", "fieldToggle"];
209
+ otherProps.forEach((key) => {
210
+ const o = body[key];
211
+ if (o && Object.keys(o).length === 0) {
212
+ delete body[key];
213
+ }
214
+ });
201
215
  return await this.graphql(method, `/graphql/${queryId}/${operationName}`, body);
202
216
  }
203
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twitter-api-browser-js",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {