rettiwt-api 6.0.6 → 6.0.8
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/dist/models/RettiwtConfig.js +1 -1
- package/dist/models/RettiwtConfig.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +1 -0
- package/dist/services/public/FetcherService.js +63 -2
- package/dist/services/public/FetcherService.js.map +1 -1
- package/package.json +3 -1
- package/src/models/RettiwtConfig.ts +1 -2
- package/src/services/public/FetcherService.ts +85 -3
|
@@ -15,7 +15,7 @@ const DefaultHeaders = {
|
|
|
15
15
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
16
16
|
'Cache-Control': 'no-cache',
|
|
17
17
|
Referer: 'https://x.com',
|
|
18
|
-
'User-Agent': 'Mozilla/5.0 (
|
|
18
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
|
|
19
19
|
'X-Twitter-Active-User': 'yes',
|
|
20
20
|
'X-Twitter-Client-Language': 'en',
|
|
21
21
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RettiwtConfig.js","sourceRoot":"","sources":["../../src/models/RettiwtConfig.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,yDAAoD;AAEpD,kEAA+D;AAI/D;;;;GAIG;AACH,MAAM,cAAc,GAAG;IACtB,yDAAyD;IAEzD,SAAS,EAAE,OAAO;IAClB,iBAAiB,EAAE,gBAAgB;IACnC,eAAe,EAAE,UAAU;IAC3B,OAAO,EAAE,eAAe;IACxB,YAAY,
|
|
1
|
+
{"version":3,"file":"RettiwtConfig.js","sourceRoot":"","sources":["../../src/models/RettiwtConfig.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,yDAAoD;AAEpD,kEAA+D;AAI/D;;;;GAIG;AACH,MAAM,cAAc,GAAG;IACtB,yDAAyD;IAEzD,SAAS,EA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G,cAAc;YACjB,GAAG,MAAM,EAAE,OAAO;SAClB,CAAC;IACH,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,IAAW,OAAO;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,uCAAuC;IACvC,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,8DAA8D;IAC9D,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,IAAW,MAAM,CAAC,MAA0B;QAC3C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,yBAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,CAAC;IAED,IAAW,OAAO,CAAC,OAA8C;QAChE,IAAI,CAAC,QAAQ,GAAG;YACf,GAAG,cAAc;YACjB,GAAG,OAAO;SACV,CAAC;IACH,CAAC;IAED,IAAW,QAAQ,CAAC,QAAyB;QAC5C,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,mCAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,aAAK,EAAE,CAAC;IAC3E,CAAC;CACD;AAlED,sCAkEC"}
|
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.FetcherService = void 0;
|
|
37
37
|
const axios_1 = __importStar(require("axios"));
|
|
38
38
|
const cookiejar_1 = require("cookiejar");
|
|
39
|
+
const jsdom_1 = require("jsdom");
|
|
39
40
|
const x_client_transaction_id_glacier_1 = require("x-client-transaction-id-glacier");
|
|
40
41
|
const Groups_1 = require("../../collections/Groups");
|
|
41
42
|
const Requests_1 = require("../../collections/Requests");
|
|
@@ -118,7 +119,7 @@ class FetcherService {
|
|
|
118
119
|
*/
|
|
119
120
|
async _getTransactionHeader(method, url) {
|
|
120
121
|
// Get the X homepage HTML document (using utility function)
|
|
121
|
-
const document = await
|
|
122
|
+
const document = await this._handleXMigration();
|
|
122
123
|
// Create and initialize ClientTransaction instance
|
|
123
124
|
const transaction = await x_client_transaction_id_glacier_1.ClientTransaction.create(document);
|
|
124
125
|
// Getting the URL path excluding all params
|
|
@@ -131,6 +132,66 @@ class FetcherService {
|
|
|
131
132
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
132
133
|
};
|
|
133
134
|
}
|
|
135
|
+
async _handleXMigration() {
|
|
136
|
+
// Fetch X.com homepage
|
|
137
|
+
const homePageResponse = await axios_1.default.get('https://x.com', {
|
|
138
|
+
headers: this.config.headers,
|
|
139
|
+
httpAgent: this.config.httpsAgent,
|
|
140
|
+
httpsAgent: this.config.httpsAgent,
|
|
141
|
+
});
|
|
142
|
+
// Parse HTML using linkedom
|
|
143
|
+
let dom = new jsdom_1.JSDOM(homePageResponse.data);
|
|
144
|
+
let document = dom.window.document;
|
|
145
|
+
// Check for migration redirection links
|
|
146
|
+
const migrationRedirectionRegex = new RegExp('(http(?:s)?://(?:www\\.)?(twitter|x){1}\\.com(/x)?/migrate([/?])?tok=[a-zA-Z0-9%\\-_]+)+', 'i');
|
|
147
|
+
const metaRefresh = document.querySelector("meta[http-equiv='refresh']");
|
|
148
|
+
const metaContent = metaRefresh ? metaRefresh.getAttribute('content') || '' : '';
|
|
149
|
+
const migrationRedirectionUrl = migrationRedirectionRegex.exec(metaContent) || migrationRedirectionRegex.exec(homePageResponse.data);
|
|
150
|
+
if (migrationRedirectionUrl) {
|
|
151
|
+
// Follow redirection URL
|
|
152
|
+
const redirectResponse = await axios_1.default.get(migrationRedirectionUrl[0], {
|
|
153
|
+
httpAgent: this.config.httpsAgent,
|
|
154
|
+
httpsAgent: this.config.httpsAgent,
|
|
155
|
+
});
|
|
156
|
+
dom = new jsdom_1.JSDOM(redirectResponse.data);
|
|
157
|
+
document = dom.window.document;
|
|
158
|
+
}
|
|
159
|
+
// Handle migration form if present
|
|
160
|
+
const migrationForm = document.querySelector("form[name='f']") ||
|
|
161
|
+
document.querySelector("form[action='https://x.com/x/migrate']");
|
|
162
|
+
if (migrationForm) {
|
|
163
|
+
const url = migrationForm.getAttribute('action') || 'https://x.com/x/migrate';
|
|
164
|
+
const method = migrationForm.getAttribute('method') || 'POST';
|
|
165
|
+
// Collect form input fields
|
|
166
|
+
const requestPayload = new FormData();
|
|
167
|
+
const inputFields = migrationForm.querySelectorAll('input');
|
|
168
|
+
for (const element of Array.from(inputFields)) {
|
|
169
|
+
const name = element.getAttribute('name');
|
|
170
|
+
const value = element.getAttribute('value');
|
|
171
|
+
if (name && value) {
|
|
172
|
+
requestPayload.append(name, value);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Submit form using POST request
|
|
176
|
+
const formResponse = await axios_1.default.request({
|
|
177
|
+
method: method,
|
|
178
|
+
url: url,
|
|
179
|
+
data: requestPayload,
|
|
180
|
+
headers: {
|
|
181
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
182
|
+
'Content-Type': 'multipart/form-data',
|
|
183
|
+
...this.config.headers,
|
|
184
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
185
|
+
},
|
|
186
|
+
httpAgent: this.config.httpsAgent,
|
|
187
|
+
httpsAgent: this.config.httpsAgent,
|
|
188
|
+
});
|
|
189
|
+
dom = new jsdom_1.JSDOM(formResponse.data);
|
|
190
|
+
document = dom.window.document;
|
|
191
|
+
}
|
|
192
|
+
// Return final DOM document
|
|
193
|
+
return document;
|
|
194
|
+
}
|
|
134
195
|
/**
|
|
135
196
|
* Validates the given args against the given resource.
|
|
136
197
|
*
|
|
@@ -230,8 +291,8 @@ class FetcherService {
|
|
|
230
291
|
try {
|
|
231
292
|
// Getting and appending transaction information
|
|
232
293
|
config.headers = {
|
|
233
|
-
...config.headers,
|
|
234
294
|
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
295
|
+
...config.headers,
|
|
235
296
|
};
|
|
236
297
|
// Introducing a delay
|
|
237
298
|
await this._wait();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../../src/services/public/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,yCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../../src/services/public/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,yCAAmC;AACnC,iCAA8B;AAC9B,qFAAoE;AAEpE,qDAAkH;AAClH,yDAAsD;AACtD,yCAA4C;AAC5C,iDAAiD;AAEjD,2DAAwD;AACxD,yDAAsD;AACtD,qEAAkE;AAOlE,yDAAsD;AACtD,2DAAwD;AACxD,uDAAoD;AAEpD;;;;GAIG;AACH,MAAa,cAAc;IAC1B,uCAAuC;IACtB,KAAK,CAAc;IAEpC,4CAA4C;IAC3B,MAAM,CAA6C;IAEpE,qDAAqD;IACpC,aAAa,CAAgB;IAE9C,wCAAwC;IACvB,QAAQ,CAAS;IAElC,yBAAyB;IACN,MAAM,CAAgB;IAEzC;;OAEG;IACH,YAAmB,MAAqB;QACvC,uBAAU,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,YAAY,IAAI,IAAI,2BAAY,EAAE,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,CAAC;IAC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QAEzC,oEAAoE;QACpE,MAAM,KAAK,CAAC;IACb,CAAC;CACD;AA9TD,wCA8TC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rettiwt-api",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.8",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "An API for fetching data from TwitterAPI, without any rate limits!",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/cookiejar": "^2.1.5",
|
|
36
|
+
"@types/jsdom": "^27.0.0",
|
|
36
37
|
"@types/node": "^22.13.1",
|
|
37
38
|
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
|
38
39
|
"@typescript-eslint/parser": "^8.24.0",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"commander": "^11.1.0",
|
|
51
52
|
"cookiejar": "^2.1.4",
|
|
52
53
|
"https-proxy-agent": "^7.0.6",
|
|
54
|
+
"jsdom": "^27.2.0",
|
|
53
55
|
"node-html-parser": "^7.0.1",
|
|
54
56
|
"x-client-transaction-id-glacier": "^1.0.0"
|
|
55
57
|
}
|
|
@@ -18,8 +18,7 @@ const DefaultHeaders = {
|
|
|
18
18
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
19
19
|
'Cache-Control': 'no-cache',
|
|
20
20
|
Referer: 'https://x.com',
|
|
21
|
-
'User-Agent':
|
|
22
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
|
|
21
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
|
|
23
22
|
'X-Twitter-Active-User': 'yes',
|
|
24
23
|
'X-Twitter-Client-Language': 'en',
|
|
25
24
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
2
|
import { Cookie } from 'cookiejar';
|
|
3
|
-
import {
|
|
3
|
+
import { JSDOM } from 'jsdom';
|
|
4
|
+
import { ClientTransaction } from 'x-client-transaction-id-glacier';
|
|
4
5
|
|
|
5
6
|
import { AllowGuestAuthenticationGroup, FetchResourcesGroup, PostResourcesGroup } from '../../collections/Groups';
|
|
6
7
|
import { Requests } from '../../collections/Requests';
|
|
@@ -103,7 +104,7 @@ export class FetcherService {
|
|
|
103
104
|
*/
|
|
104
105
|
private async _getTransactionHeader(method: string, url: string): Promise<ITransactionHeader> {
|
|
105
106
|
// Get the X homepage HTML document (using utility function)
|
|
106
|
-
const document = await
|
|
107
|
+
const document = await this._handleXMigration();
|
|
107
108
|
|
|
108
109
|
// Create and initialize ClientTransaction instance
|
|
109
110
|
const transaction = await ClientTransaction.create(document);
|
|
@@ -121,6 +122,87 @@ export class FetcherService {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
private async _handleXMigration(): Promise<Document> {
|
|
126
|
+
// Fetch X.com homepage
|
|
127
|
+
const homePageResponse = await axios.get<string>('https://x.com', {
|
|
128
|
+
headers: this.config.headers,
|
|
129
|
+
httpAgent: this.config.httpsAgent,
|
|
130
|
+
httpsAgent: this.config.httpsAgent,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Parse HTML using linkedom
|
|
134
|
+
let dom = new JSDOM(homePageResponse.data);
|
|
135
|
+
let document = dom.window.document;
|
|
136
|
+
|
|
137
|
+
// Check for migration redirection links
|
|
138
|
+
const migrationRedirectionRegex = new RegExp(
|
|
139
|
+
'(http(?:s)?://(?:www\\.)?(twitter|x){1}\\.com(/x)?/migrate([/?])?tok=[a-zA-Z0-9%\\-_]+)+',
|
|
140
|
+
'i',
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const metaRefresh = document.querySelector("meta[http-equiv='refresh']");
|
|
144
|
+
const metaContent = metaRefresh ? metaRefresh.getAttribute('content') || '' : '';
|
|
145
|
+
|
|
146
|
+
const migrationRedirectionUrl =
|
|
147
|
+
migrationRedirectionRegex.exec(metaContent) || migrationRedirectionRegex.exec(homePageResponse.data);
|
|
148
|
+
|
|
149
|
+
if (migrationRedirectionUrl) {
|
|
150
|
+
// Follow redirection URL
|
|
151
|
+
const redirectResponse = await axios.get<string>(migrationRedirectionUrl[0], {
|
|
152
|
+
httpAgent: this.config.httpsAgent,
|
|
153
|
+
httpsAgent: this.config.httpsAgent,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
dom = new JSDOM(redirectResponse.data);
|
|
157
|
+
document = dom.window.document;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Handle migration form if present
|
|
161
|
+
const migrationForm =
|
|
162
|
+
document.querySelector("form[name='f']") ||
|
|
163
|
+
document.querySelector("form[action='https://x.com/x/migrate']");
|
|
164
|
+
|
|
165
|
+
if (migrationForm) {
|
|
166
|
+
const url = migrationForm.getAttribute('action') || 'https://x.com/x/migrate';
|
|
167
|
+
const method = migrationForm.getAttribute('method') || 'POST';
|
|
168
|
+
|
|
169
|
+
// Collect form input fields
|
|
170
|
+
const requestPayload = new FormData();
|
|
171
|
+
|
|
172
|
+
const inputFields = migrationForm.querySelectorAll('input');
|
|
173
|
+
for (const element of Array.from(inputFields)) {
|
|
174
|
+
const name = element.getAttribute('name');
|
|
175
|
+
const value = element.getAttribute('value');
|
|
176
|
+
if (name && value) {
|
|
177
|
+
requestPayload.append(name, value);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Submit form using POST request
|
|
182
|
+
const formResponse = await axios.request<string>({
|
|
183
|
+
method: method,
|
|
184
|
+
url: url,
|
|
185
|
+
data: requestPayload,
|
|
186
|
+
headers: {
|
|
187
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
188
|
+
|
|
189
|
+
'Content-Type': 'multipart/form-data',
|
|
190
|
+
...this.config.headers,
|
|
191
|
+
|
|
192
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
193
|
+
},
|
|
194
|
+
httpAgent: this.config.httpsAgent,
|
|
195
|
+
httpsAgent: this.config.httpsAgent,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
dom = new JSDOM(formResponse.data);
|
|
199
|
+
document = dom.window.document;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Return final DOM document
|
|
203
|
+
return document;
|
|
204
|
+
}
|
|
205
|
+
|
|
124
206
|
/**
|
|
125
207
|
* Validates the given args against the given resource.
|
|
126
208
|
*
|
|
@@ -233,8 +315,8 @@ export class FetcherService {
|
|
|
233
315
|
try {
|
|
234
316
|
// Getting and appending transaction information
|
|
235
317
|
config.headers = {
|
|
236
|
-
...config.headers,
|
|
237
318
|
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
319
|
+
...config.headers,
|
|
238
320
|
};
|
|
239
321
|
|
|
240
322
|
// Introducing a delay
|