Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twitter-openapi-typescript

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-openapi-typescript - npm Package Compare versions

Comparing version 0.0.23 to 0.0.24

7

dist/src/api.d.ts

@@ -5,5 +5,2 @@ import * as i from 'twitter-openapi-typescript-generated';

import { UsersApiUtils } from './apis/usersApi';
export type TwitterOpenApiParams = {
fetchApi?: i.FetchAPI;
};
export declare class TwitterOpenApi {

@@ -45,5 +42,3 @@ static hash: string;

};
param: TwitterOpenApiParams;
constructor(param?: TwitterOpenApiParams);
get fetchApi(): i.FetchAPI;
static fetchApi: i.FetchAPI;
cookie_normalize(cookie: string[]): {

@@ -50,0 +45,0 @@ [key: string]: string;

29

dist/src/api.js

@@ -80,13 +80,4 @@ "use strict";

var TwitterOpenApi = /** @class */ (function () {
function TwitterOpenApi(param) {
if (param === void 0) { param = {}; }
this.param = param;
function TwitterOpenApi() {
}
Object.defineProperty(TwitterOpenApi.prototype, "fetchApi", {
get: function () {
return this.param.fetchApi || fetch;
},
enumerable: false,
configurable: true
});
TwitterOpenApi.prototype.cookie_normalize = function (cookie) {

@@ -116,3 +107,3 @@ return cookie.reduce(function (a, b) {

return __awaiter(this, void 0, void 0, function () {
var cookies, response, raw, html, re, find, activate_headers, guest_token;
var cookies, response, html, re, find, activate_headers, guest_token;
return __generator(this, function (_b) {

@@ -122,3 +113,3 @@ switch (_b.label) {

cookies = {};
return [4 /*yield*/, this.fetchApi(_a.twitter, {
return [4 /*yield*/, _a.fetchApi(_a.twitter, {
method: 'GET',

@@ -130,5 +121,4 @@ redirect: 'manual',

response = _b.sent();
raw = response.headers.raw();
cookies = __assign(__assign({}, cookies), this.cookie_normalize(raw['set-cookie']));
return [4 /*yield*/, this.fetchApi(_a.twitter, {
cookies = __assign(__assign({}, cookies), this.cookie_normalize(response.headers.getSetCookie()));
return [4 /*yield*/, _a.fetchApi(_a.twitter, {
method: 'GET',

@@ -154,3 +144,3 @@ headers: { Cookie: this.cookieEncode(cookies) },

activate_headers = __assign(__assign({}, _a.api_key), { authorization: "Bearer ".concat(_a.bearer) });
return [4 /*yield*/, this.fetchApi('https://api.twitter.com/1.1/guest/activate.json', {
return [4 /*yield*/, _a.fetchApi('https://api.twitter.com/1.1/guest/activate.json', {
method: 'POST',

@@ -186,3 +176,3 @@ headers: activate_headers,

config = {
fetchApi: this.fetchApi,
fetchApi: _a.fetchApi,
middleware: [{ pre: function (context) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {

@@ -203,3 +193,5 @@ return [2 /*return*/, this.setCookies(context, cookies)];

switch (_b.label) {
case 0: return [4 /*yield*/, this.fetchApi(_a.url, { method: 'GET' }).then(function (res) { return res.json(); })];
case 0: return [4 /*yield*/, _a.fetchApi(_a.url, { method: 'GET' }).then(function (res) {
return res.json();
})];
case 1:

@@ -234,2 +226,3 @@ flag = (_b.sent());

TwitterOpenApi.api_key = __assign({ 'x-twitter-client-language': 'en', 'x-twitter-active-user': 'yes' }, _a.browser_headers);
TwitterOpenApi.fetchApi = fetch;
return TwitterOpenApi;

@@ -236,0 +229,0 @@ }());

{
"name": "twitter-openapi-typescript",
"version": "0.0.23",
"version": "0.0.24",
"description": "Implementation of Twitter internal API in TypeScript",

@@ -41,5 +41,4 @@ "scripts": {

"log4js": "^6.9.0",
"node-fetch": "^2.0.0",
"typescript": "^5.2.0"
}
}

@@ -21,9 +21,2 @@ # twitter-openapi-typescript

### Node.js
```typescript
import fetch from "node-fetch";
const api = new TwitterOpenApi({ fetchApi: fetch as any });
```
### Login

@@ -30,0 +23,0 @@

@@ -16,6 +16,2 @@ import * as i from 'twitter-openapi-typescript-generated';

export type TwitterOpenApiParams = {
fetchApi?: i.FetchAPI;
};
export class TwitterOpenApi {

@@ -52,12 +48,4 @@ static hash = '7560ee63488ec9d15f5389e64867f2413701d7dd';

param: TwitterOpenApiParams;
static fetchApi: i.FetchAPI = fetch;
constructor(param: TwitterOpenApiParams = {}) {
this.param = param;
}
get fetchApi(): i.FetchAPI {
return this.param.fetchApi || fetch;
}
cookie_normalize(cookie: string[]): { [key: string]: string } {

@@ -87,3 +75,3 @@ return cookie.reduce((a, b) => {

const response = await this.fetchApi(TwitterOpenApi.twitter, {
const response = await TwitterOpenApi.fetchApi(TwitterOpenApi.twitter, {
method: 'GET',

@@ -93,6 +81,5 @@ redirect: 'manual',

});
const raw = (response.headers as any).raw();
cookies = { ...cookies, ...this.cookie_normalize(raw['set-cookie']) };
cookies = { ...cookies, ...this.cookie_normalize(response.headers.getSetCookie()) };
const html = await this.fetchApi(TwitterOpenApi.twitter, {
const html = await TwitterOpenApi.fetchApi(TwitterOpenApi.twitter, {
method: 'GET',

@@ -116,3 +103,3 @@ headers: { Cookie: this.cookieEncode(cookies) },

};
const { guest_token } = await this.fetchApi('https://api.twitter.com/1.1/guest/activate.json', {
const { guest_token } = await TwitterOpenApi.fetchApi('https://api.twitter.com/1.1/guest/activate.json', {
method: 'POST',

@@ -142,3 +129,3 @@ headers: activate_headers,

const config: i.ConfigurationParameters = {
fetchApi: this.fetchApi,
fetchApi: TwitterOpenApi.fetchApi,
middleware: [{ pre: async (context) => this.setCookies(context, cookies) }],

@@ -152,3 +139,5 @@ apiKey: (key) => api_key[key.toLowerCase()],

async getClient(api: i.Configuration): Promise<TwitterOpenApiClient> {
const flag = (await this.fetchApi(TwitterOpenApi.url, { method: 'GET' }).then((res) => res.json())) as DefaultFlag;
const flag = (await TwitterOpenApi.fetchApi(TwitterOpenApi.url, { method: 'GET' }).then((res) =>
res.json(),
)) as DefaultFlag;
return new TwitterOpenApiClient(api, flag);

@@ -155,0 +144,0 @@ }

@@ -30,3 +30,3 @@ import { TwitterOpenApi } from '@/api';

export const getClient = async () => {
const api = new TwitterOpenApi({ fetchApi: fetch as any });
const api = new TwitterOpenApi();
const client = await api.getClientFromCookies({

@@ -39,5 +39,5 @@ ct0: CsrfToken,

export const getGuestClient = async () => {
const api = new TwitterOpenApi({ fetchApi: fetch as any });
const api = new TwitterOpenApi();
const client = await api.getGuestClient();
return client;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc