rettiwt-api 4.2.0 → 5.0.0-alpha.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/.eslintrc.js +2 -3
- package/.github/workflows/documentation.yml +1 -1
- package/.github/workflows/publish-alpha.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/.prettierignore +1 -1
- package/.tool-versions +1 -1
- package/README.md +100 -100
- package/dist/Rettiwt.d.ts +1 -1
- package/dist/Rettiwt.js +15 -8
- package/dist/Rettiwt.js.map +1 -1
- package/dist/cli.js +8 -11
- package/dist/cli.js.map +1 -1
- package/dist/collections/Extractors.d.ts +1 -0
- package/dist/collections/Extractors.js +38 -69
- package/dist/collections/Extractors.js.map +1 -1
- package/dist/collections/Groups.js +2 -1
- package/dist/collections/Groups.js.map +1 -1
- package/dist/collections/Requests.d.ts +3 -3
- package/dist/collections/Requests.js +36 -35
- package/dist/collections/Requests.js.map +1 -1
- package/dist/commands/List.js +21 -78
- package/dist/commands/List.js.map +1 -1
- package/dist/commands/Tweet.js +185 -370
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +129 -306
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Authentication.d.ts +18 -0
- package/dist/enums/Authentication.js +24 -0
- package/dist/enums/Authentication.js.map +1 -0
- package/dist/enums/Data.d.ts +12 -0
- package/dist/enums/Data.js +14 -1
- package/dist/enums/Data.js.map +1 -1
- package/dist/enums/Resource.d.ts +1 -0
- package/dist/enums/Resource.js +1 -0
- package/dist/enums/Resource.js.map +1 -1
- package/dist/helper/CliUtils.js +1 -2
- package/dist/helper/CliUtils.js.map +1 -1
- package/dist/helper/JsonUtils.js +6 -11
- package/dist/helper/JsonUtils.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +4 -133
- package/dist/models/args/FetchArgs.js +12 -416
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/args/PostArgs.d.ts +16 -101
- package/dist/models/args/PostArgs.js +26 -258
- package/dist/models/args/PostArgs.js.map +1 -1
- package/dist/models/auth/AccountCredential.d.ts +13 -0
- package/dist/models/auth/AccountCredential.js +21 -0
- package/dist/models/auth/AccountCredential.js.map +1 -0
- package/dist/models/auth/AuthCookie.d.ts +19 -0
- package/dist/models/auth/AuthCookie.js +53 -0
- package/dist/models/auth/AuthCookie.js.map +1 -0
- package/dist/models/auth/AuthCredential.d.ts +28 -0
- package/dist/models/auth/AuthCredential.js +76 -0
- package/dist/models/auth/AuthCredential.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +3 -4
- package/dist/models/data/CursoredData.js +19 -19
- package/dist/models/data/CursoredData.js.map +1 -1
- package/dist/models/data/List.d.ts +2 -8
- package/dist/models/data/List.js +10 -4
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Notification.d.ts +5 -21
- package/dist/models/data/Notification.js +24 -33
- package/dist/models/data/Notification.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +4 -17
- package/dist/models/data/Tweet.js +83 -73
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +2 -15
- package/dist/models/data/User.js +33 -23
- package/dist/models/data/User.js.map +1 -1
- package/dist/models/errors/ApiError.js +8 -24
- package/dist/models/errors/ApiError.js.map +1 -1
- package/dist/models/errors/HttpError.js +8 -24
- package/dist/models/errors/HttpError.js.map +1 -1
- package/dist/models/errors/RettiwtError.js +5 -23
- package/dist/models/errors/RettiwtError.js.map +1 -1
- package/dist/models/errors/TimeoutError.js +5 -22
- package/dist/models/errors/TimeoutError.js.map +1 -1
- package/dist/services/{public → internal}/AuthService.d.ts +5 -34
- package/dist/services/internal/AuthService.js +109 -0
- package/dist/services/internal/AuthService.js.map +1 -0
- package/dist/services/internal/ErrorService.js +38 -40
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/LogService.d.ts +0 -6
- package/dist/services/internal/LogService.js +12 -32
- package/dist/services/internal/LogService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +5 -3
- package/dist/services/public/FetcherService.js +96 -141
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/services/public/ListService.js +31 -100
- package/dist/services/public/ListService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +29 -4
- package/dist/services/public/TweetService.js +208 -386
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.js +186 -385
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/RettiwtConfig.d.ts +8 -0
- package/dist/types/args/FetchArgs.d.ts +59 -0
- package/dist/types/args/FetchArgs.js +3 -0
- package/dist/types/args/FetchArgs.js.map +1 -0
- package/dist/types/args/PostArgs.d.ts +56 -0
- package/dist/types/args/PostArgs.js +3 -0
- package/dist/types/args/PostArgs.js.map +1 -0
- package/dist/types/auth/AccountCredential.d.ts +11 -0
- package/dist/types/auth/AccountCredential.js +3 -0
- package/dist/types/auth/AccountCredential.js.map +1 -0
- package/dist/types/auth/AuthCookie.d.ts +13 -0
- package/dist/types/auth/AuthCookie.js +3 -0
- package/dist/types/auth/AuthCookie.js.map +1 -0
- package/dist/types/auth/AuthCredential.d.ts +21 -0
- package/dist/types/auth/AuthCredential.js +3 -0
- package/dist/types/auth/AuthCredential.js.map +1 -0
- package/dist/types/data/CursoredData.d.ts +25 -0
- package/dist/types/data/CursoredData.js +3 -0
- package/dist/types/data/CursoredData.js.map +1 -0
- package/dist/types/data/List.d.ts +21 -0
- package/dist/types/data/List.js +3 -0
- package/dist/types/data/List.js.map +1 -0
- package/dist/types/data/Notification.d.ts +20 -0
- package/dist/types/data/Notification.js +3 -0
- package/dist/types/data/Notification.js.map +1 -0
- package/dist/types/data/Tweet.d.ts +71 -0
- package/dist/types/data/Tweet.js +3 -0
- package/dist/types/data/Tweet.js.map +1 -0
- package/dist/types/data/User.d.ts +35 -0
- package/dist/types/data/User.js +3 -0
- package/dist/types/data/User.js.map +1 -0
- package/eslint.config.mjs +17 -0
- package/package.json +22 -19
- package/src/Rettiwt.ts +1 -1
- package/src/cli.ts +0 -2
- package/src/collections/Extractors.ts +2 -0
- package/src/collections/Groups.ts +1 -0
- package/src/collections/Requests.ts +37 -36
- package/src/enums/Authentication.ts +19 -0
- package/src/enums/Data.ts +13 -0
- package/src/enums/Resource.ts +1 -0
- package/src/helper/JsonUtils.ts +1 -1
- package/src/index.ts +1 -2
- package/src/models/args/FetchArgs.ts +4 -470
- package/src/models/args/PostArgs.ts +20 -285
- package/src/models/auth/AccountCredential.ts +19 -0
- package/src/models/auth/AuthCookie.ts +56 -0
- package/src/models/auth/AuthCredential.ts +83 -0
- package/src/models/data/CursoredData.ts +12 -9
- package/src/models/data/List.ts +3 -14
- package/src/models/data/Notification.ts +6 -28
- package/src/models/data/Tweet.ts +17 -43
- package/src/models/data/User.ts +5 -31
- package/src/services/{public → internal}/AuthService.ts +28 -55
- package/src/services/internal/LogService.ts +4 -19
- package/src/services/public/FetcherService.ts +18 -8
- package/src/services/public/TweetService.ts +44 -4
- package/src/services/public/UserService.ts +2 -2
- package/src/types/RettiwtConfig.ts +7 -0
- package/src/types/args/FetchArgs.ts +64 -0
- package/src/types/args/PostArgs.ts +62 -0
- package/src/types/auth/AccountCredential.ts +13 -0
- package/src/types/auth/AuthCookie.ts +20 -0
- package/src/types/auth/AuthCredential.ts +26 -0
- package/src/types/data/CursoredData.ts +28 -0
- package/src/types/data/List.ts +27 -0
- package/src/types/data/Notification.ts +26 -0
- package/src/types/data/Tweet.ts +96 -0
- package/src/types/data/User.ts +48 -0
- package/tsconfig.json +7 -5
- package/.eslintignore +0 -3
- package/dist/commands/Auth.d.ts +0 -10
- package/dist/commands/Auth.js +0 -101
- package/dist/commands/Auth.js.map +0 -1
- package/dist/models/errors/DataValidationError.d.ts +0 -30
- package/dist/models/errors/DataValidationError.js +0 -34
- package/dist/models/errors/DataValidationError.js.map +0 -1
- package/dist/services/public/AuthService.js +0 -205
- package/dist/services/public/AuthService.js.map +0 -1
- package/src/commands/Auth.ts +0 -46
- package/src/models/errors/DataValidationError.ts +0 -44
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.RettiwtError = void 0;
|
|
19
4
|
/**
|
|
@@ -21,14 +6,11 @@ exports.RettiwtError = void 0;
|
|
|
21
6
|
*
|
|
22
7
|
* @internal
|
|
23
8
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Object.setPrototypeOf(_this, RettiwtError.prototype);
|
|
29
|
-
return _this;
|
|
9
|
+
class RettiwtError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
Object.setPrototypeOf(this, RettiwtError.prototype);
|
|
30
13
|
}
|
|
31
|
-
|
|
32
|
-
}(Error));
|
|
14
|
+
}
|
|
33
15
|
exports.RettiwtError = RettiwtError;
|
|
34
16
|
//# sourceMappingURL=RettiwtError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RettiwtError.js","sourceRoot":"","sources":["../../../src/models/errors/RettiwtError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RettiwtError.js","sourceRoot":"","sources":["../../../src/models/errors/RettiwtError.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,YAAa,SAAQ,KAAK;IACtC,YAAmB,OAAgB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CACD;AAND,oCAMC"}
|
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.TimeoutError = void 0;
|
|
19
|
-
|
|
4
|
+
const RettiwtError_1 = require("./RettiwtError");
|
|
20
5
|
/**
|
|
21
6
|
* Represents a timeout error that occues while making a request to Twitter API.
|
|
22
7
|
*
|
|
23
8
|
* @public
|
|
24
9
|
*/
|
|
25
|
-
|
|
26
|
-
__extends(TimeoutError, _super);
|
|
10
|
+
class TimeoutError extends RettiwtError_1.RettiwtError {
|
|
27
11
|
/**
|
|
28
12
|
* @param message - Error message with the configured timeout.
|
|
29
13
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
}(RettiwtError_1.RettiwtError));
|
|
17
|
+
}
|
|
35
18
|
exports.TimeoutError = TimeoutError;
|
|
36
19
|
//# sourceMappingURL=TimeoutError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../../src/models/errors/TimeoutError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TimeoutError.js","sourceRoot":"","sources":["../../../src/models/errors/TimeoutError.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;;GAIG;AACH,MAAa,YAAa,SAAQ,2BAAY;IAC7C;;OAEG;IACH,YAAmB,OAAgB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD;AAPD,oCAOC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { AuthCredential } from '../../models/auth/AuthCredential';
|
|
1
2
|
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
2
|
-
import { FetcherService } from './FetcherService';
|
|
3
3
|
/**
|
|
4
4
|
* The services that handles authentication.
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export declare class AuthService
|
|
8
|
+
export declare class AuthService {
|
|
9
|
+
/** The HTTPS Agent to use for requests to Twitter API. */
|
|
10
|
+
private readonly _httpsAgent;
|
|
9
11
|
/**
|
|
10
12
|
* @param config - The config object for configuring the `Rettiwt` instance.
|
|
11
13
|
*
|
|
@@ -56,36 +58,5 @@ export declare class AuthService extends FetcherService {
|
|
|
56
58
|
* });
|
|
57
59
|
* ```
|
|
58
60
|
*/
|
|
59
|
-
guest(): Promise<
|
|
60
|
-
/**
|
|
61
|
-
* Login to twitter using account credentials.
|
|
62
|
-
*
|
|
63
|
-
* @param email - The email id associated with the Twitter account.
|
|
64
|
-
* @param userName - The username associated with the Twitter account.
|
|
65
|
-
* @param password - The password to the Twitter account.
|
|
66
|
-
*
|
|
67
|
-
* @returns The `API_KEY` for the Twitter account.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```
|
|
71
|
-
* import { Rettiwt } from 'rettiwt-api';
|
|
72
|
-
*
|
|
73
|
-
* // Creating a new Rettiwt instance
|
|
74
|
-
* const rettiwt = new Rettiwt();
|
|
75
|
-
*
|
|
76
|
-
* // Logging in an getting the API_KEY
|
|
77
|
-
* rettiwt.auth.login("email@domain.com", "username", "password")
|
|
78
|
-
* .then(apiKey => {
|
|
79
|
-
* // Use the API_KEY
|
|
80
|
-
* ...
|
|
81
|
-
* })
|
|
82
|
-
* .catch(err => {
|
|
83
|
-
* console.log(err);
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @remarks
|
|
88
|
-
* Interchanging `email` and `userName` works too.
|
|
89
|
-
*/
|
|
90
|
-
login(email: string, userName: string, password: string): Promise<string>;
|
|
61
|
+
guest(): Promise<AuthCredential>;
|
|
91
62
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AuthService = void 0;
|
|
7
|
+
const https_1 = __importDefault(require("https"));
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
10
|
+
const Api_1 = require("../../enums/Api");
|
|
11
|
+
const AuthCredential_1 = require("../../models/auth/AuthCredential");
|
|
12
|
+
/**
|
|
13
|
+
* The services that handles authentication.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class AuthService {
|
|
18
|
+
/** The HTTPS Agent to use for requests to Twitter API. */
|
|
19
|
+
_httpsAgent;
|
|
20
|
+
/**
|
|
21
|
+
* @param config - The config object for configuring the `Rettiwt` instance.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this._httpsAgent = config?.proxyUrl ? new https_proxy_agent_1.HttpsProxyAgent(config.proxyUrl) : new https_1.default.Agent();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decodes the encoded cookie string.
|
|
30
|
+
*
|
|
31
|
+
* @param encodedCookies - The encoded cookie string to decode.
|
|
32
|
+
* @returns The decoded cookie string.
|
|
33
|
+
*/
|
|
34
|
+
static decodeCookie(encodedCookies) {
|
|
35
|
+
// Decoding the encoded cookie string
|
|
36
|
+
const decodedCookies = Buffer.from(encodedCookies, 'base64').toString('ascii');
|
|
37
|
+
return decodedCookies;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Encodes the given cookie string.
|
|
41
|
+
*
|
|
42
|
+
* @param cookieString - The cookie string to encode.
|
|
43
|
+
* @returns The encoded cookie string.
|
|
44
|
+
*/
|
|
45
|
+
static encodeCookie(cookieString) {
|
|
46
|
+
// Encoding the cookie string to base64
|
|
47
|
+
const encodedCookies = Buffer.from(cookieString).toString('base64');
|
|
48
|
+
return encodedCookies;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the user's id from the given API key.
|
|
52
|
+
*
|
|
53
|
+
* @param apiKey - The API key.
|
|
54
|
+
* @returns The user id associated with the API key.
|
|
55
|
+
*/
|
|
56
|
+
static getUserId(apiKey) {
|
|
57
|
+
// Getting the cookie string from the API key
|
|
58
|
+
const cookieString = AuthService.decodeCookie(apiKey);
|
|
59
|
+
// Searching for the user id in the cookie string
|
|
60
|
+
const searchResults = cookieString.match(/((?<=twid="u=)(\d+)(?="))|((?<=twid=u%3D)(\d+)(?=;))/);
|
|
61
|
+
// If user id was found
|
|
62
|
+
if (searchResults) {
|
|
63
|
+
return searchResults[0];
|
|
64
|
+
}
|
|
65
|
+
// If user id was not found
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(Api_1.EApiErrors.BAD_AUTHENTICATION);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Login to twitter as guest.
|
|
72
|
+
*
|
|
73
|
+
* @returns A new guest key.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```
|
|
77
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
78
|
+
*
|
|
79
|
+
* // Creating a new Rettiwt instance
|
|
80
|
+
* const rettiwt = new Rettiwt();
|
|
81
|
+
*
|
|
82
|
+
* // Logging in an getting a new guest key
|
|
83
|
+
* rettiwt.auth.guest()
|
|
84
|
+
* .then(guestKey => {
|
|
85
|
+
* // Use the guest key
|
|
86
|
+
* ...
|
|
87
|
+
* })
|
|
88
|
+
* .catch(err => {
|
|
89
|
+
* console.log(err);
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
async guest() {
|
|
94
|
+
// Creating a new blank credential
|
|
95
|
+
const cred = new AuthCredential_1.AuthCredential();
|
|
96
|
+
// Getting the guest token
|
|
97
|
+
await axios_1.default
|
|
98
|
+
.get('https://api.twitter.com/1.1/guest/activate.json', {
|
|
99
|
+
headers: cred.toHeader(),
|
|
100
|
+
httpsAgent: this._httpsAgent,
|
|
101
|
+
})
|
|
102
|
+
.then((res) => {
|
|
103
|
+
cred.guestToken = res.data.guest_token;
|
|
104
|
+
});
|
|
105
|
+
return cred;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.AuthService = AuthService;
|
|
109
|
+
//# sourceMappingURL=AuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/internal/AuthService.ts"],"names":[],"mappings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;;;;;;;OAsBG;IACI,KAAK,CAAC,KAAK;QACjB,kCAAkC;QAClC,MAAM,IAAI,GAAmB,IAAI,+BAAc,EAAE,CAAC;QAElD,0BAA0B;QAC1B,MAAM,eAAK;aACT,GAAG,CAID,iDAAiD,EAAE;YACrD,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE;YACxB,UAAU,EAAE,IAAI,CAAC,WAAW;SAC5B,CAAC;aACD,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC;QACxC,CAAC,CAAC,CAAC;QAEJ,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA3GD,kCA2GC"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorService = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const Api_1 = require("../../enums/Api");
|
|
6
|
+
const Http_1 = require("../../enums/Http");
|
|
7
|
+
const JsonUtils_1 = require("../../helper/JsonUtils");
|
|
8
|
+
const ApiError_1 = require("../../models/errors/ApiError");
|
|
9
|
+
const HttpError_1 = require("../../models/errors/HttpError");
|
|
10
|
+
const TimeoutError_1 = require("../../models/errors/TimeoutError");
|
|
11
11
|
/**
|
|
12
12
|
* The base service that handles any errors.
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
class ErrorService {
|
|
17
|
+
/**
|
|
18
|
+
* Error message used when the specific error type is not defined in the required enums.
|
|
19
|
+
*/
|
|
20
|
+
static DEFAULT_ERROR_MESSAGE = 'Unknown error';
|
|
19
21
|
/**
|
|
20
22
|
* Creates an API error instance based on the provided error code.
|
|
21
23
|
*
|
|
@@ -23,9 +25,9 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
23
25
|
*
|
|
24
26
|
* @returns An API error instance.
|
|
25
27
|
*/
|
|
26
|
-
|
|
28
|
+
createApiError(errorCode) {
|
|
27
29
|
return new ApiError_1.ApiError(errorCode, this.getApiErrorMessage(errorCode));
|
|
28
|
-
}
|
|
30
|
+
}
|
|
29
31
|
/**
|
|
30
32
|
* Creates an HTTP error instance based on the provided HTTP status.
|
|
31
33
|
*
|
|
@@ -33,9 +35,9 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
33
35
|
*
|
|
34
36
|
* @returns An HTTP error instance.
|
|
35
37
|
*/
|
|
36
|
-
|
|
38
|
+
createHttpError(httpStatus) {
|
|
37
39
|
return new HttpError_1.HttpError(httpStatus, this.getHttpErrorMessage(httpStatus));
|
|
38
|
-
}
|
|
40
|
+
}
|
|
39
41
|
/**
|
|
40
42
|
* Retrieves the API error message based on the provided error code.
|
|
41
43
|
*
|
|
@@ -43,12 +45,12 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
43
45
|
*
|
|
44
46
|
* @returns The API error message.
|
|
45
47
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
getApiErrorMessage(errorCode) {
|
|
49
|
+
const errorCodeKey = (0, JsonUtils_1.findKeyByValue)(Api_1.EErrorCodes, errorCode.toString());
|
|
48
50
|
return !!errorCodeKey && errorCodeKey in Api_1.EApiErrors
|
|
49
51
|
? Api_1.EApiErrors[errorCodeKey]
|
|
50
52
|
: ErrorService.DEFAULT_ERROR_MESSAGE;
|
|
51
|
-
}
|
|
53
|
+
}
|
|
52
54
|
/**
|
|
53
55
|
* Retrieves the response data from the given error.
|
|
54
56
|
*
|
|
@@ -58,12 +60,12 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
58
60
|
*
|
|
59
61
|
* @throws The original error if it is not an HTTP error with a response.
|
|
60
62
|
*/
|
|
61
|
-
|
|
63
|
+
getAxiosResponse(error) {
|
|
62
64
|
if (error.response) {
|
|
63
65
|
return error.response;
|
|
64
66
|
}
|
|
65
67
|
throw error;
|
|
66
|
-
}
|
|
68
|
+
}
|
|
67
69
|
/**
|
|
68
70
|
* Retrieves the API error code from the Axios response data.
|
|
69
71
|
*
|
|
@@ -71,10 +73,10 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
71
73
|
*
|
|
72
74
|
* @returns The error code, or undefined if not found.
|
|
73
75
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
getErrorCode(response) {
|
|
77
|
+
const errors = response.data.errors;
|
|
76
78
|
return !!errors && errors.length ? errors[0].code : undefined;
|
|
77
|
-
}
|
|
79
|
+
}
|
|
78
80
|
/**
|
|
79
81
|
* Retrieves the HTTP error message based on the provided HTTP status.
|
|
80
82
|
*
|
|
@@ -82,11 +84,11 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
82
84
|
*
|
|
83
85
|
* @returns The HTTP error message.
|
|
84
86
|
*/
|
|
85
|
-
|
|
87
|
+
getHttpErrorMessage(httpStatus) {
|
|
86
88
|
return Object.values(Http_1.EHttpStatus).includes(httpStatus)
|
|
87
89
|
? Http_1.EHttpStatus[httpStatus]
|
|
88
90
|
: ErrorService.DEFAULT_ERROR_MESSAGE;
|
|
89
|
-
}
|
|
91
|
+
}
|
|
90
92
|
/**
|
|
91
93
|
* Handles API error in a response.
|
|
92
94
|
*
|
|
@@ -94,13 +96,13 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
94
96
|
*
|
|
95
97
|
* @throws An error with the corresponding API error message if any API-related error has occurred.
|
|
96
98
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
handleApiError(response) {
|
|
100
|
+
const errorCode = this.getErrorCode(response);
|
|
99
101
|
if (errorCode === undefined) {
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
102
104
|
throw this.createApiError(errorCode);
|
|
103
|
-
}
|
|
105
|
+
}
|
|
104
106
|
/**
|
|
105
107
|
* Handles HTTP error in a response.
|
|
106
108
|
*
|
|
@@ -108,9 +110,9 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
108
110
|
*
|
|
109
111
|
* @throws An error with the corresponding HTTP status text if any HTTP-related error has occurred.
|
|
110
112
|
*/
|
|
111
|
-
|
|
113
|
+
handleHttpError(response) {
|
|
112
114
|
throw this.createHttpError(response.status);
|
|
113
|
-
}
|
|
115
|
+
}
|
|
114
116
|
/**
|
|
115
117
|
* Handles exceeded timeout, configured in RettiwtConfig.
|
|
116
118
|
*
|
|
@@ -118,29 +120,25 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
118
120
|
*
|
|
119
121
|
* @throws An error if the configured request timeout has been exceeded.
|
|
120
122
|
*/
|
|
121
|
-
|
|
123
|
+
handleTimeoutError(error) {
|
|
122
124
|
if (error.code === 'ECONNABORTED') {
|
|
123
125
|
throw new TimeoutError_1.TimeoutError(error.message);
|
|
124
126
|
}
|
|
125
|
-
}
|
|
127
|
+
}
|
|
126
128
|
/**
|
|
127
129
|
* The method called when an error response is received from Twitter API.
|
|
128
130
|
*
|
|
129
131
|
* @param error - The error caught while making HTTP request to Twitter API.
|
|
130
132
|
*/
|
|
131
|
-
|
|
133
|
+
handle(error) {
|
|
132
134
|
if (!(0, axios_1.isAxiosError)(error)) {
|
|
133
135
|
throw error;
|
|
134
136
|
}
|
|
135
137
|
this.handleTimeoutError(error);
|
|
136
|
-
|
|
138
|
+
const axiosResponse = this.getAxiosResponse(error);
|
|
137
139
|
this.handleApiError(axiosResponse);
|
|
138
140
|
this.handleHttpError(axiosResponse);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*/
|
|
143
|
-
ErrorService.DEFAULT_ERROR_MESSAGE = 'Unknown error';
|
|
144
|
-
return ErrorService;
|
|
145
|
-
}());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.ErrorService = ErrorService;
|
|
146
144
|
//# sourceMappingURL=ErrorService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorService.js","sourceRoot":"","sources":["../../../src/services/internal/ErrorService.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"ErrorService.js","sourceRoot":"","sources":["../../../src/services/internal/ErrorService.ts"],"names":[],"mappings":";;;AAAA,iCAAgE;AAEhE,yCAA0D;AAC1D,2CAA+C;AAC/C,sDAAwD;AACxD,2DAAwD;AACxD,6DAA0D;AAC1D,mEAAgE;AAGhE;;;;GAIG;AACH,MAAa,YAAY;IACxB;;OAEG;IACO,MAAM,CAAU,qBAAqB,GAAG,eAAe,CAAC;IAElE;;;;;;OAMG;IACO,cAAc,CAAC,SAAiB;QACzC,OAAO,IAAI,mBAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACO,eAAe,CAAC,UAAkB;QAC3C,OAAO,IAAI,qBAAS,CAAC,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;;;OAMG;IACO,kBAAkB,CAAC,SAAiB;QAC7C,MAAM,YAAY,GAAG,IAAA,0BAAc,EAAC,iBAAW,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEvE,OAAO,CAAC,CAAC,YAAY,IAAI,YAAY,IAAI,gBAAU;YAClD,CAAC,CAAC,gBAAU,CAAC,YAAuC,CAAC;YACrD,CAAC,CAAC,YAAY,CAAC,qBAAqB,CAAC;IACvC,CAAC;IAED;;;;;;;;OAQG;IACO,gBAAgB,CAAC,KAAiB;QAC3C,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC,QAAQ,CAAC;QACvB,CAAC;QAED,MAAM,KAAK,CAAC;IACb,CAAC;IAED;;;;;;OAM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AC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;;AA9IF,oCA+IC"}
|
|
@@ -7,12 +7,6 @@ import { ELogActions } from '../../enums/Logging';
|
|
|
7
7
|
export declare class LogService {
|
|
8
8
|
/** Whether logging is enabled or not. */
|
|
9
9
|
static enabled: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* @param action - The action to be logged.
|
|
12
|
-
*
|
|
13
|
-
* @returns - The colored text representing the action.
|
|
14
|
-
*/
|
|
15
|
-
private static getColoredAction;
|
|
16
10
|
/**
|
|
17
11
|
* Logs the given data.
|
|
18
12
|
*
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.LogService = void 0;
|
|
7
|
-
var chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
var Logging_1 = require("../../enums/Logging");
|
|
9
4
|
/**
|
|
10
5
|
* Handles logging of data for debug purpose.
|
|
11
6
|
*
|
|
12
7
|
* @internal
|
|
13
8
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param action - The action to be logged.
|
|
19
|
-
*
|
|
20
|
-
* @returns - The colored text representing the action.
|
|
21
|
-
*/
|
|
22
|
-
LogService.getColoredAction = function (action) {
|
|
23
|
-
if (action == Logging_1.ELogActions.WARNING) {
|
|
24
|
-
return chalk_1.default.yellow(action);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return chalk_1.default.green(action);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
9
|
+
class LogService {
|
|
10
|
+
/** Whether logging is enabled or not. */
|
|
11
|
+
static enabled = false;
|
|
30
12
|
/**
|
|
31
13
|
* Logs the given data.
|
|
32
14
|
*
|
|
@@ -34,21 +16,19 @@ var LogService = exports.LogService = /** @class */ (function () {
|
|
|
34
16
|
*
|
|
35
17
|
* @param data - The data to be logged.
|
|
36
18
|
*/
|
|
37
|
-
|
|
19
|
+
static log(action, data) {
|
|
38
20
|
// Proceed to log only if logging is enabled
|
|
39
21
|
if (this.enabled) {
|
|
40
22
|
// Preparing the log message
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
const logPrefix = 'Rettiwt-API';
|
|
24
|
+
const logTime = new Date().toISOString();
|
|
25
|
+
const logAction = action;
|
|
26
|
+
const logData = JSON.stringify(data);
|
|
27
|
+
const logMessage = `[${logPrefix}] [${logTime}] [${logAction}] ${logData}`;
|
|
46
28
|
// Logging
|
|
47
29
|
console.log(logMessage);
|
|
48
30
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return LogService;
|
|
53
|
-
}());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.LogService = LogService;
|
|
54
34
|
//# sourceMappingURL=LogService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LogService.js","sourceRoot":"","sources":["../../../src/services/internal/LogService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LogService.js","sourceRoot":"","sources":["../../../src/services/internal/LogService.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACH,MAAa,UAAU;IACtB,yCAAyC;IAClC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;IAE9B;;;;;;OAMG;IACI,MAAM,CAAC,GAAG,CAAC,MAAmB,EAAE,IAA0B;QAChE,4CAA4C;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,4BAA4B;YAC5B,MAAM,SAAS,GAAG,aAAa,CAAC;YAChC,MAAM,OAAO,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,SAAS,GAAW,MAAM,CAAC;YACjC,MAAM,OAAO,GAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAE7C,MAAM,UAAU,GAAG,IAAI,SAAS,MAAM,OAAO,MAAM,SAAS,KAAK,OAAO,EAAE,CAAC;YAE3E,UAAU;YACV,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;;AAzBF,gCA0BC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EResourceType } from '../../enums/Resource';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { IFetchArgs } from '../../types/args/FetchArgs';
|
|
3
|
+
import { IPostArgs } from '../../types/args/PostArgs';
|
|
4
4
|
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
5
5
|
/**
|
|
6
6
|
* The base service that handles all HTTP requests.
|
|
@@ -10,6 +10,8 @@ import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
|
10
10
|
export declare class FetcherService {
|
|
11
11
|
/** The api key to use for authenticating against Twitter API as user. */
|
|
12
12
|
private readonly _apiKey?;
|
|
13
|
+
/** Custom headers to use for all requests */
|
|
14
|
+
private readonly _customHeaders?;
|
|
13
15
|
/** The service used to handle HTTP and API errors */
|
|
14
16
|
private readonly _errorHandler;
|
|
15
17
|
/** The guest key to use for authenticating against Twitter API as guest. */
|
|
@@ -85,5 +87,5 @@ export declare class FetcherService {
|
|
|
85
87
|
* })
|
|
86
88
|
* ```
|
|
87
89
|
*/
|
|
88
|
-
request<T>(resource: EResourceType, args:
|
|
90
|
+
request<T>(resource: EResourceType, args: IFetchArgs | IPostArgs): Promise<T>;
|
|
89
91
|
}
|