rettiwt-api 6.0.0 → 6.0.1
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 +25 -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 +2 -1
- package/src/index.ts +0 -1
- package/src/models/RettiwtConfig.ts +2 -5
- package/src/services/public/FetcherService.ts +31 -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. */
|
|
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.FetcherService = void 0;
|
|
37
|
+
/* eslint-disable import/no-unresolved */
|
|
38
|
+
const x_client_transaction_id_1 = require("@lami/x-client-transaction-id");
|
|
37
39
|
const axios_1 = __importStar(require("axios"));
|
|
38
40
|
const cookiejar_1 = require("cookiejar");
|
|
39
41
|
const Groups_1 = require("../../collections/Groups");
|
|
@@ -46,7 +48,6 @@ const AuthCredential_1 = require("../../models/auth/AuthCredential");
|
|
|
46
48
|
const AuthService_1 = require("../internal/AuthService");
|
|
47
49
|
const ErrorService_1 = require("../internal/ErrorService");
|
|
48
50
|
const LogService_1 = require("../internal/LogService");
|
|
49
|
-
const TidService_1 = require("../internal/TidService");
|
|
50
51
|
/**
|
|
51
52
|
* The base service that handles all HTTP requests.
|
|
52
53
|
*
|
|
@@ -59,8 +60,6 @@ class FetcherService {
|
|
|
59
60
|
_delay;
|
|
60
61
|
/** The service used to handle HTTP and API errors */
|
|
61
62
|
_errorHandler;
|
|
62
|
-
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
63
|
-
_tidProvider;
|
|
64
63
|
/** The max wait time for a response. */
|
|
65
64
|
_timeout;
|
|
66
65
|
/** The config object. */
|
|
@@ -73,7 +72,6 @@ class FetcherService {
|
|
|
73
72
|
this.config = config;
|
|
74
73
|
this._delay = config.delay;
|
|
75
74
|
this._errorHandler = config.errorHandler ?? new ErrorService_1.ErrorService();
|
|
76
|
-
this._tidProvider = config.tidProvider ?? new TidService_1.TidService(config);
|
|
77
75
|
this._timeout = config.timeout ?? 0;
|
|
78
76
|
this._auth = new AuthService_1.AuthService(config);
|
|
79
77
|
}
|
|
@@ -120,20 +118,19 @@ class FetcherService {
|
|
|
120
118
|
* @returns The header containing the transaction ID.
|
|
121
119
|
*/
|
|
122
120
|
async _getTransactionHeader(method, url) {
|
|
121
|
+
// Get the X homepage HTML document (using utility function)
|
|
122
|
+
const document = await (0, x_client_transaction_id_1.handleXMigration)();
|
|
123
|
+
// Create and initialize ClientTransaction instance
|
|
124
|
+
const transaction = await x_client_transaction_id_1.ClientTransaction.create(document);
|
|
123
125
|
// Getting the URL path excluding all params
|
|
124
126
|
const path = new URL(url).pathname.split('?')[0].trim();
|
|
125
127
|
// Generating the transaction ID
|
|
126
|
-
const tid = await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
128
|
+
const tid = await transaction.generateTransactionId(method.toUpperCase(), path);
|
|
129
|
+
return {
|
|
130
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
131
|
+
'x-client-transaction-id': tid,
|
|
132
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
133
|
+
};
|
|
137
134
|
}
|
|
138
135
|
/**
|
|
139
136
|
* Validates the given args against the given resource.
|
|
@@ -205,6 +202,8 @@ class FetcherService {
|
|
|
205
202
|
* ```
|
|
206
203
|
*/
|
|
207
204
|
async request(resource, args) {
|
|
205
|
+
/** The current retry number. */
|
|
206
|
+
let retry = 0;
|
|
208
207
|
/** The error, if any. */
|
|
209
208
|
let error = undefined;
|
|
210
209
|
// Logging
|
|
@@ -221,16 +220,20 @@ class FetcherService {
|
|
|
221
220
|
config.headers = {
|
|
222
221
|
...config.headers,
|
|
223
222
|
...cred.toHeader(),
|
|
224
|
-
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
225
223
|
...this.config.headers,
|
|
226
224
|
};
|
|
227
225
|
config.httpAgent = this.config.httpsAgent;
|
|
228
226
|
config.httpsAgent = this.config.httpsAgent;
|
|
229
227
|
config.timeout = this._timeout;
|
|
230
228
|
// Using retries for error 404
|
|
231
|
-
|
|
229
|
+
do {
|
|
232
230
|
// Sending the request
|
|
233
231
|
try {
|
|
232
|
+
// Getting and appending transaction information
|
|
233
|
+
config.headers = {
|
|
234
|
+
...config.headers,
|
|
235
|
+
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
236
|
+
};
|
|
234
237
|
// Introducing a delay
|
|
235
238
|
await this._wait();
|
|
236
239
|
// Returning the reponse body
|
|
@@ -248,7 +251,11 @@ class FetcherService {
|
|
|
248
251
|
throw err;
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
|
-
|
|
254
|
+
finally {
|
|
255
|
+
// Incrementing the number of retries done
|
|
256
|
+
retry++;
|
|
257
|
+
}
|
|
258
|
+
} while (retry < this.config.maxRetries);
|
|
252
259
|
/** If request not successful even after retries, throw the error */
|
|
253
260
|
throw error;
|
|
254
261
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../../src/services/public/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4C;AAC5C,yCAAmC;AAEnC,qDAAkH;AAClH,yDAAsD;AACtD,yCAA4C;AAC5C,iDAAiD;AAEjD,2DAAwD;AACxD,yDAAsD;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G;oBAChB,GAAG,MAAM,CAAC,OAAO;oBACjB,GAAG,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,CAAC,GAAG,IAAI,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.1",
|
|
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!",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"typescript": "^5.7.3"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@lami/x-client-transaction-id": "npm:@jsr/lami__x-client-transaction-id@^0.1.7",
|
|
48
49
|
"axios": "^1.8.4",
|
|
49
50
|
"chalk": "^5.4.1",
|
|
50
51
|
"commander": "^11.1.0",
|
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,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable import/no-unresolved */
|
|
2
|
+
import { ClientTransaction, handleXMigration } from '@lami/x-client-transaction-id';
|
|
1
3
|
import axios, { isAxiosError } from 'axios';
|
|
2
4
|
import { Cookie } from 'cookiejar';
|
|
3
5
|
|
|
@@ -12,14 +14,12 @@ import { AuthCredential } from '../../models/auth/AuthCredential';
|
|
|
12
14
|
import { RettiwtConfig } from '../../models/RettiwtConfig';
|
|
13
15
|
import { IFetchArgs } from '../../types/args/FetchArgs';
|
|
14
16
|
import { IPostArgs } from '../../types/args/PostArgs';
|
|
15
|
-
import {
|
|
16
|
-
import { ITidProvider } from '../../types/auth/TidProvider';
|
|
17
|
+
import { ITransactionHeader } from '../../types/auth/TransactionHeader';
|
|
17
18
|
import { IErrorHandler } from '../../types/ErrorHandler';
|
|
18
19
|
|
|
19
20
|
import { AuthService } from '../internal/AuthService';
|
|
20
21
|
import { ErrorService } from '../internal/ErrorService';
|
|
21
22
|
import { LogService } from '../internal/LogService';
|
|
22
|
-
import { TidService } from '../internal/TidService';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* The base service that handles all HTTP requests.
|
|
@@ -36,9 +36,6 @@ export class FetcherService {
|
|
|
36
36
|
/** The service used to handle HTTP and API errors */
|
|
37
37
|
private readonly _errorHandler: IErrorHandler;
|
|
38
38
|
|
|
39
|
-
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
40
|
-
private readonly _tidProvider: ITidProvider;
|
|
41
|
-
|
|
42
39
|
/** The max wait time for a response. */
|
|
43
40
|
private readonly _timeout: number;
|
|
44
41
|
|
|
@@ -53,7 +50,6 @@ export class FetcherService {
|
|
|
53
50
|
this.config = config;
|
|
54
51
|
this._delay = config.delay;
|
|
55
52
|
this._errorHandler = config.errorHandler ?? new ErrorService();
|
|
56
|
-
this._tidProvider = config.tidProvider ?? new TidService(config);
|
|
57
53
|
this._timeout = config.timeout ?? 0;
|
|
58
54
|
this._auth = new AuthService(config);
|
|
59
55
|
}
|
|
@@ -106,22 +102,24 @@ export class FetcherService {
|
|
|
106
102
|
*
|
|
107
103
|
* @returns The header containing the transaction ID.
|
|
108
104
|
*/
|
|
109
|
-
private async _getTransactionHeader(method: string, url: string): Promise<
|
|
105
|
+
private async _getTransactionHeader(method: string, url: string): Promise<ITransactionHeader> {
|
|
106
|
+
// Get the X homepage HTML document (using utility function)
|
|
107
|
+
const document = await handleXMigration();
|
|
108
|
+
|
|
109
|
+
// Create and initialize ClientTransaction instance
|
|
110
|
+
const transaction = await ClientTransaction.create(document);
|
|
111
|
+
|
|
110
112
|
// Getting the URL path excluding all params
|
|
111
113
|
const path = new URL(url).pathname.split('?')[0].trim();
|
|
112
114
|
|
|
113
115
|
// Generating the transaction ID
|
|
114
|
-
const tid = await
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
} else {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
116
|
+
const tid = await transaction.generateTransactionId(method.toUpperCase(), path);
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
120
|
+
'x-client-transaction-id': tid,
|
|
121
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
122
|
+
};
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
/**
|
|
@@ -199,6 +197,9 @@ export class FetcherService {
|
|
|
199
197
|
* ```
|
|
200
198
|
*/
|
|
201
199
|
public async request<T = unknown>(resource: ResourceType, args: IFetchArgs | IPostArgs): Promise<T> {
|
|
200
|
+
/** The current retry number. */
|
|
201
|
+
let retry = 0;
|
|
202
|
+
|
|
202
203
|
/** The error, if any. */
|
|
203
204
|
let error: unknown = undefined;
|
|
204
205
|
|
|
@@ -221,7 +222,6 @@ export class FetcherService {
|
|
|
221
222
|
config.headers = {
|
|
222
223
|
...config.headers,
|
|
223
224
|
...cred.toHeader(),
|
|
224
|
-
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
225
225
|
...this.config.headers,
|
|
226
226
|
};
|
|
227
227
|
config.httpAgent = this.config.httpsAgent;
|
|
@@ -229,9 +229,15 @@ export class FetcherService {
|
|
|
229
229
|
config.timeout = this._timeout;
|
|
230
230
|
|
|
231
231
|
// Using retries for error 404
|
|
232
|
-
|
|
232
|
+
do {
|
|
233
233
|
// Sending the request
|
|
234
234
|
try {
|
|
235
|
+
// Getting and appending transaction information
|
|
236
|
+
config.headers = {
|
|
237
|
+
...config.headers,
|
|
238
|
+
...(await this._getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
239
|
+
};
|
|
240
|
+
|
|
235
241
|
// Introducing a delay
|
|
236
242
|
await this._wait();
|
|
237
243
|
|
|
@@ -248,8 +254,11 @@ export class FetcherService {
|
|
|
248
254
|
this._errorHandler.handle(err);
|
|
249
255
|
throw err;
|
|
250
256
|
}
|
|
257
|
+
} finally {
|
|
258
|
+
// Incrementing the number of retries done
|
|
259
|
+
retry++;
|
|
251
260
|
}
|
|
252
|
-
}
|
|
261
|
+
} while (retry < this.config.maxRetries);
|
|
253
262
|
|
|
254
263
|
/** If request not successful even after retries, throw the error */
|
|
255
264
|
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
|