rettiwt-api 6.0.0 → 6.0.2
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 +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/models/RettiwtConfig.d.ts +0 -2
- package/dist/models/RettiwtConfig.js +2 -4
- package/dist/models/RettiwtConfig.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +0 -2
- package/dist/services/public/FetcherService.js +24 -18
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/types/RettiwtConfig.d.ts +0 -3
- package/dist/types/auth/TransactionHeader.d.ts +6 -0
- package/dist/types/auth/TransactionHeader.js +4 -0
- package/dist/types/auth/TransactionHeader.js.map +1 -0
- package/package.json +3 -2
- package/src/index.ts +0 -1
- package/src/models/RettiwtConfig.ts +2 -5
- package/src/services/public/FetcherService.ts +30 -22
- package/src/types/RettiwtConfig.ts +0 -4
- package/src/types/auth/TransactionHeader.ts +8 -0
- package/dist/helper/TidUtils.d.ts +0 -4
- package/dist/helper/TidUtils.js +0 -171
- package/dist/helper/TidUtils.js.map +0 -1
- package/dist/services/internal/TidService.d.ts +0 -43
- package/dist/services/internal/TidService.js +0 -156
- package/dist/services/internal/TidService.js.map +0 -1
- package/dist/types/auth/TidDynamicArgs.d.ts +0 -10
- package/dist/types/auth/TidDynamicArgs.js +0 -3
- package/dist/types/auth/TidDynamicArgs.js.map +0 -1
- package/dist/types/auth/TidHeader.d.ts +0 -8
- package/dist/types/auth/TidHeader.js +0 -3
- package/dist/types/auth/TidHeader.js.map +0 -1
- package/dist/types/auth/TidParams.d.ts +0 -27
- package/dist/types/auth/TidParams.js +0 -3
- package/dist/types/auth/TidParams.js.map +0 -1
- package/dist/types/auth/TidProvider.d.ts +0 -18
- package/dist/types/auth/TidProvider.js +0 -3
- package/dist/types/auth/TidProvider.js.map +0 -1
- package/src/helper/TidUtils.ts +0 -198
- package/src/services/internal/TidService.ts +0 -140
- package/src/types/auth/TidDynamicArgs.ts +0 -10
- package/src/types/auth/TidHeader.ts +0 -12
- package/src/types/auth/TidParams.ts +0 -36
- package/src/types/auth/TidProvider.ts +0 -19
package/README.md
CHANGED
|
@@ -143,8 +143,8 @@ When initializing a new Rettiwt instance, it can be configures using various par
|
|
|
143
143
|
- `errorHandler` (interface) - The custom error handler to use.
|
|
144
144
|
- `tidProvider` (interface) - The custom TID provider to use for generating transaction token.
|
|
145
145
|
- `headers` (object) - Custom HTTP headers to append to the default headers.
|
|
146
|
-
- `delay` (number/function) - The delay to use between concurrent requests, can either be a number in milliseconds, or a function that returns the number. Default is
|
|
147
|
-
- `maxRetries` (number) - The maximum number of retries to use in case when a random error 404 is encountered. Default is
|
|
146
|
+
- `delay` (number/function) - The delay to use between concurrent requests, can either be a number in milliseconds, or a function that returns the number. Default is 0 (no delay).
|
|
147
|
+
- `maxRetries` (number) - The maximum number of retries to use in case when a random error 404 is encountered. Default is 0 (no retries).
|
|
148
148
|
|
|
149
149
|
Of these parameters, the following are hot-swappable, using their respective setters:
|
|
150
150
|
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,6 @@ export * from './services/public/TweetService';
|
|
|
29
29
|
export * from './services/public/UserService';
|
|
30
30
|
export * from './types/args/FetchArgs';
|
|
31
31
|
export * from './types/args/PostArgs';
|
|
32
|
-
export * from './types/auth/TidProvider';
|
|
33
32
|
export * from './types/data/CursoredData';
|
|
34
33
|
export * from './types/data/List';
|
|
35
34
|
export * from './types/data/Notification';
|
package/dist/index.js
CHANGED
|
@@ -51,7 +51,6 @@ __exportStar(require("./services/public/UserService"), exports);
|
|
|
51
51
|
// TYPES
|
|
52
52
|
__exportStar(require("./types/args/FetchArgs"), exports);
|
|
53
53
|
__exportStar(require("./types/args/PostArgs"), exports);
|
|
54
|
-
__exportStar(require("./types/auth/TidProvider"), exports);
|
|
55
54
|
__exportStar(require("./types/data/CursoredData"), exports);
|
|
56
55
|
__exportStar(require("./types/data/List"), exports);
|
|
57
56
|
__exportStar(require("./types/data/Notification"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAO;AACP,4CAA0B;AAE1B,QAAQ;AACR,wDAAsC;AACtC,oDAAkC;AAClC,2DAAyC;AACzC,oDAAkC;AAClC,8CAA4B;AAC5B,yDAAuC;AACvC,+CAA6B;AAC7B,kDAAgC;AAChC,gDAA8B;AAC9B,uDAAqC;AACrC,mDAAiC;AACjC,gDAA8B;AAE9B,SAAS;AACT,0DAAwC;AACxC,yDAAuC;AACvC,6DAA2C;AAC3C,qDAAmC;AACnC,6DAA2C;AAC3C,sDAAoC;AACpC,qDAAmC;AACnC,+DAA6C;AAE7C,WAAW;AACX,kDAAgC;AAChC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAEhC,WAAW;AACX,mEAAiD;AACjD,gEAA8C;AAC9C,iEAA+C;AAC/C,gEAA8C;AAE9C,QAAQ;AACR,yDAAuC;AACvC,wDAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAO;AACP,4CAA0B;AAE1B,QAAQ;AACR,wDAAsC;AACtC,oDAAkC;AAClC,2DAAyC;AACzC,oDAAkC;AAClC,8CAA4B;AAC5B,yDAAuC;AACvC,+CAA6B;AAC7B,kDAAgC;AAChC,gDAA8B;AAC9B,uDAAqC;AACrC,mDAAiC;AACjC,gDAA8B;AAE9B,SAAS;AACT,0DAAwC;AACxC,yDAAuC;AACvC,6DAA2C;AAC3C,qDAAmC;AACnC,6DAA2C;AAC3C,sDAAoC;AACpC,qDAAmC;AACnC,+DAA6C;AAE7C,WAAW;AACX,kDAAgC;AAChC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAEhC,WAAW;AACX,mEAAiD;AACjD,gEAA8C;AAC9C,iEAA+C;AAC/C,gEAA8C;AAE9C,QAAQ;AACR,yDAAuC;AACvC,wDAAsC;AACtC,4DAA0C;AAC1C,oDAAkC;AAClC,4DAA0C;AAC1C,qDAAmC;AACnC,oDAAkC;AAClC,8DAA4C;AAC5C,2DAAyC;AAsDzC,uDAAqC;AACrC,wDAAsC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Agent } from 'https';
|
|
2
|
-
import { ITidProvider } from '../types/auth/TidProvider';
|
|
3
2
|
import { IErrorHandler } from '../types/ErrorHandler';
|
|
4
3
|
import { IRettiwtConfig } from '../types/RettiwtConfig';
|
|
5
4
|
/**
|
|
@@ -30,7 +29,6 @@ export declare class RettiwtConfig implements IRettiwtConfig {
|
|
|
30
29
|
readonly errorHandler?: IErrorHandler;
|
|
31
30
|
readonly logging?: boolean;
|
|
32
31
|
readonly maxRetries: number;
|
|
33
|
-
readonly tidProvider?: ITidProvider;
|
|
34
32
|
readonly timeout?: number;
|
|
35
33
|
/**
|
|
36
34
|
* @param config - The config for Rettiwt of type {@link IRettiwtConfig}.
|
|
@@ -37,7 +37,6 @@ class RettiwtConfig {
|
|
|
37
37
|
errorHandler;
|
|
38
38
|
logging;
|
|
39
39
|
maxRetries;
|
|
40
|
-
tidProvider;
|
|
41
40
|
timeout;
|
|
42
41
|
/**
|
|
43
42
|
* @param config - The config for Rettiwt of type {@link IRettiwtConfig}.
|
|
@@ -46,11 +45,10 @@ class RettiwtConfig {
|
|
|
46
45
|
this._apiKey = config?.apiKey;
|
|
47
46
|
this._httpsAgent = config?.proxyUrl ? new https_proxy_agent_1.HttpsProxyAgent(config?.proxyUrl) : new https_1.Agent();
|
|
48
47
|
this._userId = config?.apiKey ? AuthService_1.AuthService.getUserId(config?.apiKey) : undefined;
|
|
49
|
-
this.delay = config?.delay ??
|
|
50
|
-
this.maxRetries = config?.maxRetries ??
|
|
48
|
+
this.delay = config?.delay ?? 0;
|
|
49
|
+
this.maxRetries = config?.maxRetries ?? 0;
|
|
51
50
|
this.errorHandler = config?.errorHandler;
|
|
52
51
|
this.logging = config?.logging;
|
|
53
|
-
this.tidProvider = config?.tidProvider;
|
|
54
52
|
this.timeout = config?.timeout;
|
|
55
53
|
this.apiKey = config?.apiKey;
|
|
56
54
|
this._headers = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RettiwtConfig.js","sourceRoot":"","sources":["../../src/models/RettiwtConfig.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,yDAAoD;AAEpD,kEAA+D;
|
|
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,EACX,iHAAiH;IAClH,uBAAuB,EAAE,KAAK;IAC9B,2BAA2B,EAAE,IAAI;IAEjC,wDAAwD;CACxD,CAAC;AA2EyB,+CAAqB;AAzEhD;;;;GAIG;AACH,MAAa,aAAa;IACzB,8BAA8B;IACtB,OAAO,CAAU;IACjB,QAAQ,CAA4B;IACpC,WAAW,CAAQ;IACnB,OAAO,CAAqB;IAEpC,uDAAuD;IACvC,KAAK,CAA6C;IAClD,YAAY,CAAiB;IAC7B,OAAO,CAAW;IAClB,UAAU,CAAS;IACnB,OAAO,CAAU;IAEjC;;OAEG;IACH,YAAmB,MAAuB;QACzC,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,mCAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,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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"}
|
|
@@ -14,8 +14,6 @@ export declare class FetcherService {
|
|
|
14
14
|
private readonly _delay?;
|
|
15
15
|
/** The service used to handle HTTP and API errors */
|
|
16
16
|
private readonly _errorHandler;
|
|
17
|
-
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
18
|
-
private readonly _tidProvider;
|
|
19
17
|
/** The max wait time for a response. */
|
|
20
18
|
private readonly _timeout;
|
|
21
19
|
/** The config object. */
|
|
@@ -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 x_client_transaction_id_1 = require("x-client-transaction-id");
|
|
39
40
|
const Groups_1 = require("../../collections/Groups");
|
|
40
41
|
const Requests_1 = require("../../collections/Requests");
|
|
41
42
|
const Api_1 = require("../../enums/Api");
|
|
@@ -46,7 +47,6 @@ const AuthCredential_1 = require("../../models/auth/AuthCredential");
|
|
|
46
47
|
const AuthService_1 = require("../internal/AuthService");
|
|
47
48
|
const ErrorService_1 = require("../internal/ErrorService");
|
|
48
49
|
const LogService_1 = require("../internal/LogService");
|
|
49
|
-
const TidService_1 = require("../internal/TidService");
|
|
50
50
|
/**
|
|
51
51
|
* The base service that handles all HTTP requests.
|
|
52
52
|
*
|
|
@@ -59,8 +59,6 @@ class FetcherService {
|
|
|
59
59
|
_delay;
|
|
60
60
|
/** The service used to handle HTTP and API errors */
|
|
61
61
|
_errorHandler;
|
|
62
|
-
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
63
|
-
_tidProvider;
|
|
64
62
|
/** The max wait time for a response. */
|
|
65
63
|
_timeout;
|
|
66
64
|
/** The config object. */
|
|
@@ -73,7 +71,6 @@ class FetcherService {
|
|
|
73
71
|
this.config = config;
|
|
74
72
|
this._delay = config.delay;
|
|
75
73
|
this._errorHandler = config.errorHandler ?? new ErrorService_1.ErrorService();
|
|
76
|
-
this._tidProvider = config.tidProvider ?? new TidService_1.TidService(config);
|
|
77
74
|
this._timeout = config.timeout ?? 0;
|
|
78
75
|
this._auth = new AuthService_1.AuthService(config);
|
|
79
76
|
}
|
|
@@ -120,20 +117,19 @@ class FetcherService {
|
|
|
120
117
|
* @returns The header containing the transaction ID.
|
|
121
118
|
*/
|
|
122
119
|
async _getTransactionHeader(method, url) {
|
|
120
|
+
// Get the X homepage HTML document (using utility function)
|
|
121
|
+
const document = await (0, x_client_transaction_id_1.handleXMigration)();
|
|
122
|
+
// Create and initialize ClientTransaction instance
|
|
123
|
+
const transaction = await x_client_transaction_id_1.ClientTransaction.create(document);
|
|
123
124
|
// Getting the URL path excluding all params
|
|
124
125
|
const path = new URL(url).pathname.split('?')[0].trim();
|
|
125
126
|
// Generating the transaction ID
|
|
126
|
-
const tid = await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
127
|
+
const tid = await transaction.generateTransactionId(method.toUpperCase(), path);
|
|
128
|
+
return {
|
|
129
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
130
|
+
'x-client-transaction-id': tid,
|
|
131
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
132
|
+
};
|
|
137
133
|
}
|
|
138
134
|
/**
|
|
139
135
|
* Validates the given args against the given resource.
|
|
@@ -205,6 +201,8 @@ class FetcherService {
|
|
|
205
201
|
* ```
|
|
206
202
|
*/
|
|
207
203
|
async request(resource, args) {
|
|
204
|
+
/** The current retry number. */
|
|
205
|
+
let retry = 0;
|
|
208
206
|
/** The error, if any. */
|
|
209
207
|
let error = undefined;
|
|
210
208
|
// Logging
|
|
@@ -221,16 +219,20 @@ class FetcherService {
|
|
|
221
219
|
config.headers = {
|
|
222
220
|
...config.headers,
|
|
223
221
|
...cred.toHeader(),
|
|
224
|
-
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
225
222
|
...this.config.headers,
|
|
226
223
|
};
|
|
227
224
|
config.httpAgent = this.config.httpsAgent;
|
|
228
225
|
config.httpsAgent = this.config.httpsAgent;
|
|
229
226
|
config.timeout = this._timeout;
|
|
230
227
|
// Using retries for error 404
|
|
231
|
-
|
|
228
|
+
do {
|
|
232
229
|
// Sending the request
|
|
233
230
|
try {
|
|
231
|
+
// Getting and appending transaction information
|
|
232
|
+
config.headers = {
|
|
233
|
+
...config.headers,
|
|
234
|
+
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
235
|
+
};
|
|
234
236
|
// Introducing a delay
|
|
235
237
|
await this._wait();
|
|
236
238
|
// Returning the reponse body
|
|
@@ -248,7 +250,11 @@ class FetcherService {
|
|
|
248
250
|
throw err;
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
|
-
|
|
253
|
+
finally {
|
|
254
|
+
// Incrementing the number of retries done
|
|
255
|
+
retry++;
|
|
256
|
+
}
|
|
257
|
+
} while (retry < this.config.maxRetries);
|
|
252
258
|
/** If request not successful even after retries, throw the error */
|
|
253
259
|
throw error;
|
|
254
260
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../../src/services/public/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,yCAAmC;
|
|
1
|
+
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../../src/services/public/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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AI,EAAE,CAAC,CAAC;iBAC5E,CAAC;gBAEF,sBAAsB;gBACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;gBAEnB,6BAA6B;gBAC7B,OAAO,CAAC,MAAM,IAAA,eAAK,EAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;YACtC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,8BAA8B;gBAC9B,IAAI,IAAA,oBAAY,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBAC7C,KAAK,GAAG,GAAG,CAAC;oBACZ,SAAS;gBACV,CAAC;gBACD,gCAAgC;qBAC3B,CAAC;oBACL,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBAC/B,MAAM,GAAG,CAAC;gBACX,CAAC;YACF,CAAC;oBAAS,CAAC;gBACV,0CAA0C;gBAC1C,KAAK,EAAE,CAAC;YACT,CAAC;QACF,CAAC,QAAQ,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;QAEzC,oEAAoE;QACpE,MAAM,KAAK,CAAC;IACb,CAAC;CACD;AA7OD,wCA6OC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ITidProvider } from './auth/TidProvider';
|
|
2
1
|
import { IErrorHandler } from './ErrorHandler';
|
|
3
2
|
/**
|
|
4
3
|
* The configuration for initializing a new Rettiwt instance.
|
|
@@ -20,8 +19,6 @@ export interface IRettiwtConfig {
|
|
|
20
19
|
logging?: boolean;
|
|
21
20
|
/** Optional custom error handler to define error conditions and process API/HTTP errors in responses. */
|
|
22
21
|
errorHandler?: IErrorHandler;
|
|
23
|
-
/** Optional custom `x-client-transaction-id` header provider. */
|
|
24
|
-
tidProvider?: ITidProvider;
|
|
25
22
|
/**
|
|
26
23
|
* Optional custom HTTP headers to add to all requests to Twitter API.
|
|
27
24
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionHeader.js","sourceRoot":"","sources":["../../../src/types/auth/TransactionHeader.ts"],"names":[],"mappings":";AAAA,yDAAyD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rettiwt-api",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
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!",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"commander": "^11.1.0",
|
|
51
51
|
"cookiejar": "^2.1.4",
|
|
52
52
|
"https-proxy-agent": "^7.0.6",
|
|
53
|
-
"node-html-parser": "^7.0.1"
|
|
53
|
+
"node-html-parser": "^7.0.1",
|
|
54
|
+
"x-client-transaction-id": "^0.1.7"
|
|
54
55
|
}
|
|
55
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -40,7 +40,6 @@ export * from './services/public/UserService';
|
|
|
40
40
|
// TYPES
|
|
41
41
|
export * from './types/args/FetchArgs';
|
|
42
42
|
export * from './types/args/PostArgs';
|
|
43
|
-
export * from './types/auth/TidProvider';
|
|
44
43
|
export * from './types/data/CursoredData';
|
|
45
44
|
export * from './types/data/List';
|
|
46
45
|
export * from './types/data/Notification';
|
|
@@ -3,7 +3,6 @@ import { Agent } from 'https';
|
|
|
3
3
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
4
4
|
|
|
5
5
|
import { AuthService } from '../services/internal/AuthService';
|
|
6
|
-
import { ITidProvider } from '../types/auth/TidProvider';
|
|
7
6
|
import { IErrorHandler } from '../types/ErrorHandler';
|
|
8
7
|
import { IRettiwtConfig } from '../types/RettiwtConfig';
|
|
9
8
|
|
|
@@ -44,7 +43,6 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
44
43
|
public readonly errorHandler?: IErrorHandler;
|
|
45
44
|
public readonly logging?: boolean;
|
|
46
45
|
public readonly maxRetries: number;
|
|
47
|
-
public readonly tidProvider?: ITidProvider;
|
|
48
46
|
public readonly timeout?: number;
|
|
49
47
|
|
|
50
48
|
/**
|
|
@@ -54,11 +52,10 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
54
52
|
this._apiKey = config?.apiKey;
|
|
55
53
|
this._httpsAgent = config?.proxyUrl ? new HttpsProxyAgent(config?.proxyUrl) : new Agent();
|
|
56
54
|
this._userId = config?.apiKey ? AuthService.getUserId(config?.apiKey) : undefined;
|
|
57
|
-
this.delay = config?.delay ??
|
|
58
|
-
this.maxRetries = config?.maxRetries ??
|
|
55
|
+
this.delay = config?.delay ?? 0;
|
|
56
|
+
this.maxRetries = config?.maxRetries ?? 0;
|
|
59
57
|
this.errorHandler = config?.errorHandler;
|
|
60
58
|
this.logging = config?.logging;
|
|
61
|
-
this.tidProvider = config?.tidProvider;
|
|
62
59
|
this.timeout = config?.timeout;
|
|
63
60
|
this.apiKey = config?.apiKey;
|
|
64
61
|
this._headers = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
2
|
import { Cookie } from 'cookiejar';
|
|
3
|
+
import { ClientTransaction, handleXMigration } from 'x-client-transaction-id';
|
|
3
4
|
|
|
4
5
|
import { AllowGuestAuthenticationGroup, FetchResourcesGroup, PostResourcesGroup } from '../../collections/Groups';
|
|
5
6
|
import { Requests } from '../../collections/Requests';
|
|
@@ -12,14 +13,12 @@ import { AuthCredential } from '../../models/auth/AuthCredential';
|
|
|
12
13
|
import { RettiwtConfig } from '../../models/RettiwtConfig';
|
|
13
14
|
import { IFetchArgs } from '../../types/args/FetchArgs';
|
|
14
15
|
import { IPostArgs } from '../../types/args/PostArgs';
|
|
15
|
-
import {
|
|
16
|
-
import { ITidProvider } from '../../types/auth/TidProvider';
|
|
16
|
+
import { ITransactionHeader } from '../../types/auth/TransactionHeader';
|
|
17
17
|
import { IErrorHandler } from '../../types/ErrorHandler';
|
|
18
18
|
|
|
19
19
|
import { AuthService } from '../internal/AuthService';
|
|
20
20
|
import { ErrorService } from '../internal/ErrorService';
|
|
21
21
|
import { LogService } from '../internal/LogService';
|
|
22
|
-
import { TidService } from '../internal/TidService';
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* The base service that handles all HTTP requests.
|
|
@@ -36,9 +35,6 @@ export class FetcherService {
|
|
|
36
35
|
/** The service used to handle HTTP and API errors */
|
|
37
36
|
private readonly _errorHandler: IErrorHandler;
|
|
38
37
|
|
|
39
|
-
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
40
|
-
private readonly _tidProvider: ITidProvider;
|
|
41
|
-
|
|
42
38
|
/** The max wait time for a response. */
|
|
43
39
|
private readonly _timeout: number;
|
|
44
40
|
|
|
@@ -53,7 +49,6 @@ export class FetcherService {
|
|
|
53
49
|
this.config = config;
|
|
54
50
|
this._delay = config.delay;
|
|
55
51
|
this._errorHandler = config.errorHandler ?? new ErrorService();
|
|
56
|
-
this._tidProvider = config.tidProvider ?? new TidService(config);
|
|
57
52
|
this._timeout = config.timeout ?? 0;
|
|
58
53
|
this._auth = new AuthService(config);
|
|
59
54
|
}
|
|
@@ -106,22 +101,24 @@ export class FetcherService {
|
|
|
106
101
|
*
|
|
107
102
|
* @returns The header containing the transaction ID.
|
|
108
103
|
*/
|
|
109
|
-
private async _getTransactionHeader(method: string, url: string): Promise<
|
|
104
|
+
private async _getTransactionHeader(method: string, url: string): Promise<ITransactionHeader> {
|
|
105
|
+
// Get the X homepage HTML document (using utility function)
|
|
106
|
+
const document = await handleXMigration();
|
|
107
|
+
|
|
108
|
+
// Create and initialize ClientTransaction instance
|
|
109
|
+
const transaction = await ClientTransaction.create(document);
|
|
110
|
+
|
|
110
111
|
// Getting the URL path excluding all params
|
|
111
112
|
const path = new URL(url).pathname.split('?')[0].trim();
|
|
112
113
|
|
|
113
114
|
// Generating the transaction ID
|
|
114
|
-
const tid = await
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
} else {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
115
|
+
const tid = await transaction.generateTransactionId(method.toUpperCase(), path);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
119
|
+
'x-client-transaction-id': tid,
|
|
120
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
121
|
+
};
|
|
125
122
|
}
|
|
126
123
|
|
|
127
124
|
/**
|
|
@@ -199,6 +196,9 @@ export class FetcherService {
|
|
|
199
196
|
* ```
|
|
200
197
|
*/
|
|
201
198
|
public async request<T = unknown>(resource: ResourceType, args: IFetchArgs | IPostArgs): Promise<T> {
|
|
199
|
+
/** The current retry number. */
|
|
200
|
+
let retry = 0;
|
|
201
|
+
|
|
202
202
|
/** The error, if any. */
|
|
203
203
|
let error: unknown = undefined;
|
|
204
204
|
|
|
@@ -221,7 +221,6 @@ export class FetcherService {
|
|
|
221
221
|
config.headers = {
|
|
222
222
|
...config.headers,
|
|
223
223
|
...cred.toHeader(),
|
|
224
|
-
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
225
224
|
...this.config.headers,
|
|
226
225
|
};
|
|
227
226
|
config.httpAgent = this.config.httpsAgent;
|
|
@@ -229,9 +228,15 @@ export class FetcherService {
|
|
|
229
228
|
config.timeout = this._timeout;
|
|
230
229
|
|
|
231
230
|
// Using retries for error 404
|
|
232
|
-
|
|
231
|
+
do {
|
|
233
232
|
// Sending the request
|
|
234
233
|
try {
|
|
234
|
+
// Getting and appending transaction information
|
|
235
|
+
config.headers = {
|
|
236
|
+
...config.headers,
|
|
237
|
+
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
238
|
+
};
|
|
239
|
+
|
|
235
240
|
// Introducing a delay
|
|
236
241
|
await this._wait();
|
|
237
242
|
|
|
@@ -248,8 +253,11 @@ export class FetcherService {
|
|
|
248
253
|
this._errorHandler.handle(err);
|
|
249
254
|
throw err;
|
|
250
255
|
}
|
|
256
|
+
} finally {
|
|
257
|
+
// Incrementing the number of retries done
|
|
258
|
+
retry++;
|
|
251
259
|
}
|
|
252
|
-
}
|
|
260
|
+
} while (retry < this.config.maxRetries);
|
|
253
261
|
|
|
254
262
|
/** If request not successful even after retries, throw the error */
|
|
255
263
|
throw error;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ITidProvider } from './auth/TidProvider';
|
|
2
1
|
import { IErrorHandler } from './ErrorHandler';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -26,9 +25,6 @@ export interface IRettiwtConfig {
|
|
|
26
25
|
/** Optional custom error handler to define error conditions and process API/HTTP errors in responses. */
|
|
27
26
|
errorHandler?: IErrorHandler;
|
|
28
27
|
|
|
29
|
-
/** Optional custom `x-client-transaction-id` header provider. */
|
|
30
|
-
tidProvider?: ITidProvider;
|
|
31
|
-
|
|
32
28
|
/**
|
|
33
29
|
* Optional custom HTTP headers to add to all requests to Twitter API.
|
|
34
30
|
*
|
package/dist/helper/TidUtils.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUnixTime = getUnixTime;
|
|
4
|
-
exports.getNanosecondPrecisionTime = getNanosecondPrecisionTime;
|
|
5
|
-
exports.calculateClientTransactionIdHeader = calculateClientTransactionIdHeader;
|
|
6
|
-
const node_crypto_1 = require("node:crypto");
|
|
7
|
-
function getUnixTime() {
|
|
8
|
-
const [seconds, nanoseconds] = process.hrtime();
|
|
9
|
-
return Date.now() / 1000 + seconds + nanoseconds / 1e9;
|
|
10
|
-
}
|
|
11
|
-
function getNanosecondPrecisionTime() {
|
|
12
|
-
return Number(((BigInt(Date.now()) * 1000000n + process.hrtime.bigint()) * 1000n) / BigInt(1000000)) / 1000000;
|
|
13
|
-
}
|
|
14
|
-
function calculateClientTransactionIdHeader(args) {
|
|
15
|
-
const time = Math.floor(((args.time || getUnixTime()) * 1000 - 1682924400 * 1000) / 1000);
|
|
16
|
-
const timeBuffer = new Uint8Array(new Uint32Array([time]).buffer);
|
|
17
|
-
const keyBytes = Array.from(Buffer.from(args.verificationKey, 'base64'));
|
|
18
|
-
const animationKey = args.animationKey || getAnimationKey(keyBytes, args.frames, args.indices);
|
|
19
|
-
const value = [args.method, args.path, time].join('!') + args.keyword + animationKey;
|
|
20
|
-
const valueEncoded = new TextEncoder().encode(value);
|
|
21
|
-
const hash = (0, node_crypto_1.createHash)('sha-256').update(valueEncoded).digest();
|
|
22
|
-
const hashBytes = Array.from(new Uint8Array(hash));
|
|
23
|
-
const xorByte = args.xorByte || Math.floor(Math.random() * 256);
|
|
24
|
-
const bytes = new Uint8Array(keyBytes.concat(Array.from(timeBuffer), hashBytes.slice(0, 16), [args.extraByte]));
|
|
25
|
-
return encode(xor(xorByte, bytes));
|
|
26
|
-
}
|
|
27
|
-
function getAnimationKey(keyBytes, frames, indices) {
|
|
28
|
-
const totalTime = 4096;
|
|
29
|
-
const rowIndex = keyBytes[indices[0]] % 16;
|
|
30
|
-
const frameTime = indices
|
|
31
|
-
.slice(1)
|
|
32
|
-
.map((idx) => keyBytes[idx] % 16)
|
|
33
|
-
.reduce((a, b) => a * b, 1);
|
|
34
|
-
const targetTime = frameTime / totalTime;
|
|
35
|
-
const frameRow = frames[keyBytes[5] % 4][rowIndex];
|
|
36
|
-
return animate(frameRow, targetTime);
|
|
37
|
-
}
|
|
38
|
-
function animate(frameRow, targetTime) {
|
|
39
|
-
const curves = frameRow.slice(7).map((v, i) => Number(a(v, b(i), 1).toFixed(2)));
|
|
40
|
-
const cubicValue = getCubicCurveValue(curves, targetTime);
|
|
41
|
-
const fromColor = [...frameRow.slice(0, 3), 1];
|
|
42
|
-
const toColor = [...frameRow.slice(3, 6), 1];
|
|
43
|
-
const color = interpolate(fromColor, toColor, cubicValue);
|
|
44
|
-
const fromRotation = [0];
|
|
45
|
-
const toRotation = [Math.floor(a(frameRow[6], 60, 360))];
|
|
46
|
-
const rotation = interpolate(fromRotation, toRotation, cubicValue);
|
|
47
|
-
const matrix = convertRotationToMatrix(rotation[0]);
|
|
48
|
-
const strArray = [];
|
|
49
|
-
for (let i = 0; i < color.length - 1; i++) {
|
|
50
|
-
strArray.push(Math.round(color[i]).toString(16));
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0; i < matrix.length; i++) {
|
|
53
|
-
let rounded = Number(matrix[i].toFixed(2));
|
|
54
|
-
if (rounded < 0) {
|
|
55
|
-
rounded = -rounded;
|
|
56
|
-
}
|
|
57
|
-
const hexValue = floatToHex(rounded);
|
|
58
|
-
if (hexValue.startsWith('.')) {
|
|
59
|
-
strArray.push('0' + hexValue);
|
|
60
|
-
}
|
|
61
|
-
else if (hexValue) {
|
|
62
|
-
strArray.push(hexValue);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
strArray.push('0');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
strArray.push('0', '0');
|
|
69
|
-
return strArray.join('').replace(/[.-]/g, '').toLowerCase();
|
|
70
|
-
}
|
|
71
|
-
function a(b, c, d) {
|
|
72
|
-
return (b * (d - c)) / 255 + c;
|
|
73
|
-
}
|
|
74
|
-
function b(a) {
|
|
75
|
-
return a % 2 === 1 ? -1 : 0;
|
|
76
|
-
}
|
|
77
|
-
function getCubicCurveValue(curves, time) {
|
|
78
|
-
let startGradient = 0;
|
|
79
|
-
let endGradient = 0;
|
|
80
|
-
if (time <= 0) {
|
|
81
|
-
if (curves[0] > 0) {
|
|
82
|
-
startGradient = curves[1] / curves[0];
|
|
83
|
-
}
|
|
84
|
-
else if (curves[1] === 0 && curves[2] > 0) {
|
|
85
|
-
startGradient = curves[3] / curves[2];
|
|
86
|
-
}
|
|
87
|
-
return startGradient * time;
|
|
88
|
-
}
|
|
89
|
-
if (time >= 1) {
|
|
90
|
-
if (curves[2] < 1) {
|
|
91
|
-
endGradient = (curves[3] - 1) / (curves[2] - 1);
|
|
92
|
-
}
|
|
93
|
-
else if (curves[2] === 1 && curves[0] < 1) {
|
|
94
|
-
endGradient = (curves[1] - 1) / (curves[0] - 1);
|
|
95
|
-
}
|
|
96
|
-
return 1 + endGradient * (time - 1);
|
|
97
|
-
}
|
|
98
|
-
let start = 0;
|
|
99
|
-
let end = 1;
|
|
100
|
-
let mid = 0;
|
|
101
|
-
while (start < end) {
|
|
102
|
-
mid = (start + end) / 2;
|
|
103
|
-
const xEst = calculateBezier(curves[0], curves[2], mid);
|
|
104
|
-
if (Math.abs(time - xEst) < 0.00001) {
|
|
105
|
-
return calculateBezier(curves[1], curves[3], mid);
|
|
106
|
-
}
|
|
107
|
-
if (xEst < time) {
|
|
108
|
-
start = mid;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
end = mid;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return calculateBezier(curves[1], curves[3], mid);
|
|
115
|
-
}
|
|
116
|
-
function calculateBezier(a, b, m) {
|
|
117
|
-
return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m;
|
|
118
|
-
}
|
|
119
|
-
function interpolate(from, to, f) {
|
|
120
|
-
const out = [];
|
|
121
|
-
for (let i = 0; i < from.length; i++) {
|
|
122
|
-
out.push(from[i] * (1 - f) + to[i] * f);
|
|
123
|
-
}
|
|
124
|
-
return out;
|
|
125
|
-
}
|
|
126
|
-
function convertRotationToMatrix(degrees) {
|
|
127
|
-
const radians = (degrees * Math.PI) / 180;
|
|
128
|
-
const c = Math.cos(radians);
|
|
129
|
-
const s = Math.sin(radians);
|
|
130
|
-
return [c, -s, s, c];
|
|
131
|
-
}
|
|
132
|
-
function floatToHex(x) {
|
|
133
|
-
const result = [];
|
|
134
|
-
let quotient = Math.floor(x);
|
|
135
|
-
let fraction = x - quotient;
|
|
136
|
-
while (quotient > 0) {
|
|
137
|
-
const remainder = quotient % 16;
|
|
138
|
-
quotient = Math.floor(quotient / 16);
|
|
139
|
-
if (remainder > 9) {
|
|
140
|
-
result.unshift(String.fromCharCode(remainder + 55));
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
result.unshift(remainder.toString());
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (fraction === 0) {
|
|
147
|
-
return result.join('');
|
|
148
|
-
}
|
|
149
|
-
result.push('.');
|
|
150
|
-
while (fraction > 0) {
|
|
151
|
-
fraction *= 16;
|
|
152
|
-
const integer = Math.floor(fraction);
|
|
153
|
-
fraction -= integer;
|
|
154
|
-
if (integer > 9) {
|
|
155
|
-
result.push(String.fromCharCode(integer + 55));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
result.push(integer.toString());
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return result.join('');
|
|
162
|
-
}
|
|
163
|
-
function xor(xorByte, data) {
|
|
164
|
-
return new Uint8Array([xorByte, ...data.map((v) => v ^ xorByte)]);
|
|
165
|
-
}
|
|
166
|
-
function encode(data) {
|
|
167
|
-
return btoa(Array.from(data)
|
|
168
|
-
.map((v) => String.fromCharCode(v))
|
|
169
|
-
.join('')).replaceAll('=', '');
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=TidUtils.js.map
|