rettiwt-api 2.7.1 → 3.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/.eslintrc.js +73 -5
- package/.tool-versions +1 -0
- package/README.md +87 -20
- package/dist/Rettiwt.js +0 -1
- package/dist/Rettiwt.js.map +1 -1
- package/dist/cli.js +2 -4
- package/dist/cli.js.map +1 -1
- package/dist/collections/Extractors.d.ts +37 -0
- package/dist/collections/Extractors.js +67 -0
- package/dist/collections/Extractors.js.map +1 -0
- package/dist/collections/Groups.d.ts +19 -0
- package/dist/collections/Groups.js +55 -0
- package/dist/collections/Groups.js.map +1 -0
- package/dist/collections/Requests.d.ts +12 -0
- package/dist/collections/Requests.js +46 -0
- package/dist/collections/Requests.js.map +1 -0
- package/dist/commands/Auth.d.ts +6 -0
- package/dist/commands/Auth.js +26 -8
- package/dist/commands/Auth.js.map +1 -1
- package/dist/commands/Tweet.js +237 -82
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +197 -36
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Api.d.ts +30 -0
- package/dist/enums/Api.js +32 -1
- package/dist/enums/Api.js.map +1 -1
- package/dist/enums/Data.d.ts +9 -0
- package/dist/enums/Data.js +14 -0
- package/dist/enums/Data.js.map +1 -0
- package/dist/enums/Http.d.ts +1 -1
- package/dist/enums/Http.js +1 -1
- package/dist/enums/Logging.d.ts +6 -5
- package/dist/enums/Logging.js +6 -5
- package/dist/enums/Logging.js.map +1 -1
- package/dist/enums/Resource.d.ts +33 -0
- package/dist/enums/Resource.js +42 -0
- package/dist/enums/Resource.js.map +1 -0
- package/dist/helper/CliUtils.d.ts +1 -1
- package/dist/helper/CliUtils.js.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.js +11 -14
- package/dist/index.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +129 -0
- package/dist/models/args/FetchArgs.js +263 -0
- package/dist/models/args/FetchArgs.js.map +1 -0
- package/dist/models/args/PostArgs.d.ts +116 -0
- package/dist/models/args/PostArgs.js +232 -0
- package/dist/models/args/PostArgs.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +11 -11
- package/dist/models/data/CursoredData.js +21 -16
- package/dist/models/data/CursoredData.js.map +1 -1
- package/dist/models/data/List.d.ts +8 -10
- package/dist/models/data/List.js +2 -4
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +44 -29
- package/dist/models/data/Tweet.js +74 -15
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +38 -20
- package/dist/models/data/User.js +71 -7
- package/dist/models/data/User.js.map +1 -1
- package/dist/models/errors/ApiError.d.ts +1 -3
- package/dist/models/errors/ApiError.js +1 -4
- package/dist/models/errors/ApiError.js.map +1 -1
- package/dist/models/errors/DataValidationError.d.ts +30 -0
- package/dist/models/errors/DataValidationError.js +34 -0
- package/dist/models/errors/DataValidationError.js.map +1 -0
- package/dist/models/errors/HttpError.d.ts +1 -3
- package/dist/models/errors/HttpError.js +1 -4
- package/dist/models/errors/HttpError.js.map +1 -1
- package/dist/models/errors/TimeoutError.d.ts +2 -4
- package/dist/models/errors/TimeoutError.js +2 -5
- package/dist/models/errors/TimeoutError.js.map +1 -1
- package/dist/services/internal/ErrorService.d.ts +45 -35
- package/dist/services/internal/ErrorService.js +70 -68
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/LogService.d.ts +7 -5
- package/dist/services/internal/LogService.js +28 -9
- package/dist/services/internal/LogService.js.map +1 -1
- package/dist/services/public/AuthService.d.ts +24 -20
- package/dist/services/public/AuthService.js +38 -36
- package/dist/services/public/AuthService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +89 -0
- package/dist/services/public/FetcherService.js +240 -0
- package/dist/services/public/FetcherService.js.map +1 -0
- package/dist/services/public/TweetService.d.ts +213 -94
- package/dist/services/public/TweetService.js +409 -209
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +185 -52
- package/dist/services/public/UserService.js +338 -103
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/ReturnTypes.d.ts +21 -0
- package/dist/types/ReturnTypes.js +3 -0
- package/dist/types/ReturnTypes.js.map +1 -0
- package/package.json +4 -2
- package/src/Rettiwt.ts +0 -3
- package/src/cli.ts +2 -4
- package/src/collections/Extractors.ts +84 -0
- package/src/collections/Groups.ts +54 -0
- package/src/collections/Requests.ts +52 -0
- package/src/commands/Auth.ts +19 -7
- package/src/commands/Tweet.ts +179 -91
- package/src/commands/User.ts +118 -25
- package/src/enums/Api.ts +31 -0
- package/src/enums/Data.ts +9 -0
- package/src/enums/Http.ts +1 -1
- package/src/enums/Logging.ts +6 -5
- package/src/enums/Resource.ts +40 -0
- package/src/helper/CliUtils.ts +1 -1
- package/src/index.ts +41 -14
- package/src/models/args/FetchArgs.ts +296 -0
- package/src/models/args/PostArgs.ts +263 -0
- package/src/models/data/CursoredData.ts +23 -15
- package/src/models/data/List.ts +12 -15
- package/src/models/data/Tweet.ts +108 -39
- package/src/models/data/User.ts +99 -30
- package/src/models/errors/ApiError.ts +1 -4
- package/src/models/errors/DataValidationError.ts +44 -0
- package/src/models/errors/HttpError.ts +1 -4
- package/src/models/errors/TimeoutError.ts +2 -5
- package/src/services/internal/ErrorService.ts +76 -75
- package/src/services/internal/LogService.ts +20 -10
- package/src/services/public/AuthService.ts +39 -38
- package/src/services/public/FetcherService.ts +209 -0
- package/src/services/public/TweetService.ts +384 -179
- package/src/services/public/UserService.ts +319 -86
- package/src/types/RettiwtConfig.ts +0 -1
- package/src/types/ReturnTypes.ts +24 -0
- package/dist/models/args/TweetArgs.d.ts +0 -44
- package/dist/models/args/TweetArgs.js +0 -82
- package/dist/models/args/TweetArgs.js.map +0 -1
- package/dist/models/data/Media.d.ts +0 -14
- package/dist/models/data/Media.js +0 -19
- package/dist/models/data/Media.js.map +0 -1
- package/dist/services/internal/FetcherService.d.ts +0 -106
- package/dist/services/internal/FetcherService.js +0 -365
- package/dist/services/internal/FetcherService.js.map +0 -1
- package/src/models/args/TweetArgs.ts +0 -98
- package/src/models/data/Media.ts +0 -19
- package/src/services/internal/FetcherService.ts +0 -365
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
-
import { IErrorHandler } from '../../types/ErrorHandler';
|
|
3
2
|
import { ApiError } from '../../models/errors/ApiError';
|
|
4
3
|
import { HttpError } from '../../models/errors/HttpError';
|
|
4
|
+
import { IErrorHandler } from '../../types/ErrorHandler';
|
|
5
5
|
/**
|
|
6
6
|
* The base service that handles any errors.
|
|
7
7
|
*
|
|
@@ -13,73 +13,83 @@ export declare class ErrorService implements IErrorHandler {
|
|
|
13
13
|
*/
|
|
14
14
|
protected static readonly DEFAULT_ERROR_MESSAGE = "Unknown error";
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Creates an API error instance based on the provided error code.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
18
|
+
* @param errorCode - The error code.
|
|
19
|
+
*
|
|
20
|
+
* @returns An API error instance.
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
protected createApiError(errorCode: number): ApiError;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Creates an HTTP error instance based on the provided HTTP status.
|
|
23
25
|
*
|
|
24
|
-
* @param
|
|
25
|
-
*
|
|
26
|
+
* @param httpStatus - The HTTP status code.
|
|
27
|
+
*
|
|
28
|
+
* @returns An HTTP error instance.
|
|
26
29
|
*/
|
|
27
|
-
protected
|
|
30
|
+
protected createHttpError(httpStatus: number): HttpError;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the API error message based on the provided error code.
|
|
33
|
+
*
|
|
34
|
+
* @param errorCode - The error code.
|
|
35
|
+
*
|
|
36
|
+
* @returns The API error message.
|
|
37
|
+
*/
|
|
38
|
+
protected getApiErrorMessage(errorCode: number): string;
|
|
28
39
|
/**
|
|
29
40
|
* Retrieves the response data from the given error.
|
|
30
41
|
*
|
|
31
42
|
* @param error - The error object.
|
|
43
|
+
*
|
|
32
44
|
* @returns The response data.
|
|
45
|
+
*
|
|
33
46
|
* @throws The original error if it is not an HTTP error with a response.
|
|
34
47
|
*/
|
|
35
48
|
protected getAxiosResponse(error: AxiosError): AxiosResponse;
|
|
36
49
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param response - The response object received.
|
|
40
|
-
* @throws An error with the corresponding HTTP status text if any HTTP-related error has occurred.
|
|
41
|
-
*/
|
|
42
|
-
protected handleHttpError(response: AxiosResponse): void;
|
|
43
|
-
/**
|
|
44
|
-
* Handles API error in a response.
|
|
50
|
+
* Retrieves the API error code from the Axios response data.
|
|
45
51
|
*
|
|
46
52
|
* @param response - The response object received.
|
|
47
|
-
* @throws An error with the corresponding API error message if any API-related error has occurred.
|
|
48
|
-
*/
|
|
49
|
-
protected handleApiError(response: AxiosResponse): void;
|
|
50
|
-
/**
|
|
51
|
-
* Creates an HTTP error instance based on the provided HTTP status.
|
|
52
53
|
*
|
|
53
|
-
* @
|
|
54
|
-
* @returns An HTTP error instance.
|
|
54
|
+
* @returns The error code, or undefined if not found.
|
|
55
55
|
*/
|
|
56
|
-
protected
|
|
56
|
+
protected getErrorCode(response: AxiosResponse): number | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* Retrieves the HTTP error message based on the provided HTTP status.
|
|
59
59
|
*
|
|
60
60
|
* @param httpStatus - The HTTP status code.
|
|
61
|
+
*
|
|
61
62
|
* @returns The HTTP error message.
|
|
62
63
|
*/
|
|
63
64
|
protected getHttpErrorMessage(httpStatus: number): string;
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
+
* Handles API error in a response.
|
|
66
67
|
*
|
|
67
68
|
* @param response - The response object received.
|
|
68
|
-
*
|
|
69
|
+
*
|
|
70
|
+
* @throws An error with the corresponding API error message if any API-related error has occurred.
|
|
69
71
|
*/
|
|
70
|
-
protected
|
|
72
|
+
protected handleApiError(response: AxiosResponse): void;
|
|
71
73
|
/**
|
|
72
|
-
*
|
|
74
|
+
* Handles HTTP error in a response.
|
|
73
75
|
*
|
|
74
|
-
* @param
|
|
75
|
-
*
|
|
76
|
+
* @param response - The response object received.
|
|
77
|
+
*
|
|
78
|
+
* @throws An error with the corresponding HTTP status text if any HTTP-related error has occurred.
|
|
76
79
|
*/
|
|
77
|
-
protected
|
|
80
|
+
protected handleHttpError(response: AxiosResponse): void;
|
|
78
81
|
/**
|
|
79
|
-
*
|
|
82
|
+
* Handles exceeded timeout, configured in RettiwtConfig.
|
|
80
83
|
*
|
|
81
|
-
* @param
|
|
82
|
-
*
|
|
84
|
+
* @param error - The error object.
|
|
85
|
+
*
|
|
86
|
+
* @throws An error if the configured request timeout has been exceeded.
|
|
83
87
|
*/
|
|
84
|
-
protected
|
|
88
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
89
|
+
/**
|
|
90
|
+
* The method called when an error response is received from Twitter API.
|
|
91
|
+
*
|
|
92
|
+
* @param error - The error caught while making HTTP request to Twitter API.
|
|
93
|
+
*/
|
|
94
|
+
handle(error: unknown): void;
|
|
85
95
|
}
|
|
@@ -1,21 +1,13 @@
|
|
|
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.ErrorService = void 0;
|
|
7
|
-
|
|
8
|
-
var axios_1 = __importDefault(require("axios"));
|
|
9
|
-
var JsonUtils_1 = require("../../helper/JsonUtils");
|
|
10
|
-
// ENUMS
|
|
4
|
+
var axios_1 = require("axios");
|
|
11
5
|
var Api_1 = require("../../enums/Api");
|
|
12
6
|
var Http_1 = require("../../enums/Http");
|
|
13
|
-
var
|
|
14
|
-
// ERRORS
|
|
7
|
+
var JsonUtils_1 = require("../../helper/JsonUtils");
|
|
15
8
|
var ApiError_1 = require("../../models/errors/ApiError");
|
|
16
9
|
var HttpError_1 = require("../../models/errors/HttpError");
|
|
17
10
|
var TimeoutError_1 = require("../../models/errors/TimeoutError");
|
|
18
|
-
// TODO Refactor and document this module
|
|
19
11
|
/**
|
|
20
12
|
* The base service that handles any errors.
|
|
21
13
|
*
|
|
@@ -25,35 +17,45 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
25
17
|
function ErrorService() {
|
|
26
18
|
}
|
|
27
19
|
/**
|
|
28
|
-
*
|
|
20
|
+
* Creates an API error instance based on the provided error code.
|
|
29
21
|
*
|
|
30
|
-
* @param
|
|
22
|
+
* @param errorCode - The error code.
|
|
23
|
+
*
|
|
24
|
+
* @returns An API error instance.
|
|
31
25
|
*/
|
|
32
|
-
ErrorService.prototype.
|
|
33
|
-
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
this.handleTimeoutError(error);
|
|
37
|
-
var axiosResponse = this.getAxiosResponse(error);
|
|
38
|
-
this.handleApiError(axiosResponse);
|
|
39
|
-
this.handleHttpError(axiosResponse);
|
|
26
|
+
ErrorService.prototype.createApiError = function (errorCode) {
|
|
27
|
+
return new ApiError_1.ApiError(errorCode, this.getApiErrorMessage(errorCode));
|
|
40
28
|
};
|
|
41
29
|
/**
|
|
42
|
-
*
|
|
30
|
+
* Creates an HTTP error instance based on the provided HTTP status.
|
|
43
31
|
*
|
|
44
|
-
* @param
|
|
45
|
-
*
|
|
32
|
+
* @param httpStatus - The HTTP status code.
|
|
33
|
+
*
|
|
34
|
+
* @returns An HTTP error instance.
|
|
46
35
|
*/
|
|
47
|
-
ErrorService.prototype.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
ErrorService.prototype.createHttpError = function (httpStatus) {
|
|
37
|
+
return new HttpError_1.HttpError(httpStatus, this.getHttpErrorMessage(httpStatus));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves the API error message based on the provided error code.
|
|
41
|
+
*
|
|
42
|
+
* @param errorCode - The error code.
|
|
43
|
+
*
|
|
44
|
+
* @returns The API error message.
|
|
45
|
+
*/
|
|
46
|
+
ErrorService.prototype.getApiErrorMessage = function (errorCode) {
|
|
47
|
+
var errorCodeKey = (0, JsonUtils_1.findKeyByValue)(Api_1.EErrorCodes, errorCode.toString());
|
|
48
|
+
return !!errorCodeKey && errorCodeKey in Api_1.EApiErrors
|
|
49
|
+
? Api_1.EApiErrors[errorCodeKey]
|
|
50
|
+
: ErrorService.DEFAULT_ERROR_MESSAGE;
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
53
|
* Retrieves the response data from the given error.
|
|
54
54
|
*
|
|
55
55
|
* @param error - The error object.
|
|
56
|
+
*
|
|
56
57
|
* @returns The response data.
|
|
58
|
+
*
|
|
57
59
|
* @throws The original error if it is not an HTTP error with a response.
|
|
58
60
|
*/
|
|
59
61
|
ErrorService.prototype.getAxiosResponse = function (error) {
|
|
@@ -63,18 +65,33 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
63
65
|
throw error;
|
|
64
66
|
};
|
|
65
67
|
/**
|
|
66
|
-
*
|
|
68
|
+
* Retrieves the API error code from the Axios response data.
|
|
67
69
|
*
|
|
68
70
|
* @param response - The response object received.
|
|
69
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* @returns The error code, or undefined if not found.
|
|
70
73
|
*/
|
|
71
|
-
ErrorService.prototype.
|
|
72
|
-
|
|
74
|
+
ErrorService.prototype.getErrorCode = function (response) {
|
|
75
|
+
var errors = response.data.errors;
|
|
76
|
+
return !!errors && errors.length ? errors[0].code : undefined;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves the HTTP error message based on the provided HTTP status.
|
|
80
|
+
*
|
|
81
|
+
* @param httpStatus - The HTTP status code.
|
|
82
|
+
*
|
|
83
|
+
* @returns The HTTP error message.
|
|
84
|
+
*/
|
|
85
|
+
ErrorService.prototype.getHttpErrorMessage = function (httpStatus) {
|
|
86
|
+
return Object.values(Http_1.EHttpStatus).includes(httpStatus)
|
|
87
|
+
? Http_1.EHttpStatus[httpStatus]
|
|
88
|
+
: ErrorService.DEFAULT_ERROR_MESSAGE;
|
|
73
89
|
};
|
|
74
90
|
/**
|
|
75
91
|
* Handles API error in a response.
|
|
76
92
|
*
|
|
77
93
|
* @param response - The response object received.
|
|
94
|
+
*
|
|
78
95
|
* @throws An error with the corresponding API error message if any API-related error has occurred.
|
|
79
96
|
*/
|
|
80
97
|
ErrorService.prototype.handleApiError = function (response) {
|
|
@@ -85,55 +102,40 @@ var ErrorService = exports.ErrorService = /** @class */ (function () {
|
|
|
85
102
|
throw this.createApiError(errorCode);
|
|
86
103
|
};
|
|
87
104
|
/**
|
|
88
|
-
*
|
|
105
|
+
* Handles HTTP error in a response.
|
|
89
106
|
*
|
|
90
|
-
* @param
|
|
91
|
-
* @returns An HTTP error instance.
|
|
92
|
-
*/
|
|
93
|
-
ErrorService.prototype.createHttpError = function (httpStatus) {
|
|
94
|
-
return new HttpError_1.HttpError(httpStatus, this.getHttpErrorMessage(httpStatus));
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Retrieves the HTTP error message based on the provided HTTP status.
|
|
107
|
+
* @param response - The response object received.
|
|
98
108
|
*
|
|
99
|
-
* @
|
|
100
|
-
* @returns The HTTP error message.
|
|
109
|
+
* @throws An error with the corresponding HTTP status text if any HTTP-related error has occurred.
|
|
101
110
|
*/
|
|
102
|
-
ErrorService.prototype.
|
|
103
|
-
|
|
104
|
-
? Http_1.EHttpStatus[httpStatus]
|
|
105
|
-
: ErrorService.DEFAULT_ERROR_MESSAGE;
|
|
111
|
+
ErrorService.prototype.handleHttpError = function (response) {
|
|
112
|
+
throw this.createHttpError(response.status);
|
|
106
113
|
};
|
|
107
114
|
/**
|
|
108
|
-
*
|
|
115
|
+
* Handles exceeded timeout, configured in RettiwtConfig.
|
|
109
116
|
*
|
|
110
|
-
* @param
|
|
111
|
-
* @returns The error code, or undefined if not found.
|
|
112
|
-
*/
|
|
113
|
-
ErrorService.prototype.getErrorCode = function (response) {
|
|
114
|
-
var errors = response.data.errors;
|
|
115
|
-
return !!errors && errors.length ? errors[0].code : undefined;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Creates an API error instance based on the provided error code.
|
|
117
|
+
* @param error - The error object.
|
|
119
118
|
*
|
|
120
|
-
* @
|
|
121
|
-
* @returns An API error instance.
|
|
119
|
+
* @throws An error if the configured request timeout has been exceeded.
|
|
122
120
|
*/
|
|
123
|
-
ErrorService.prototype.
|
|
124
|
-
|
|
121
|
+
ErrorService.prototype.handleTimeoutError = function (error) {
|
|
122
|
+
if (error.code === 'ECONNABORTED') {
|
|
123
|
+
throw new TimeoutError_1.TimeoutError(error.message);
|
|
124
|
+
}
|
|
125
125
|
};
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
127
|
+
* The method called when an error response is received from Twitter API.
|
|
128
128
|
*
|
|
129
|
-
* @param
|
|
130
|
-
* @returns The API error message.
|
|
129
|
+
* @param error - The error caught while making HTTP request to Twitter API.
|
|
131
130
|
*/
|
|
132
|
-
ErrorService.prototype.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
ErrorService.prototype.handle = function (error) {
|
|
132
|
+
if (!(0, axios_1.isAxiosError)(error)) {
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
this.handleTimeoutError(error);
|
|
136
|
+
var axiosResponse = this.getAxiosResponse(error);
|
|
137
|
+
this.handleApiError(axiosResponse);
|
|
138
|
+
this.handleHttpError(axiosResponse);
|
|
137
139
|
};
|
|
138
140
|
/**
|
|
139
141
|
* Error message used when the specific error type is not defined in the required enums.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorService.js","sourceRoot":"","sources":["../../../src/services/internal/ErrorService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ErrorService.js","sourceRoot":"","sources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A+IC"}
|
|
@@ -6,17 +6,19 @@ import { ELogActions } from '../../enums/Logging';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class LogService {
|
|
8
8
|
/** Whether logging is enabled or not. */
|
|
9
|
-
|
|
9
|
+
static enabled: boolean;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* @param action - The action to be logged.
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
13
|
+
* @returns - The colored text representing the action.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
private static getColoredAction;
|
|
16
16
|
/**
|
|
17
17
|
* Logs the given data.
|
|
18
18
|
*
|
|
19
|
+
* @param action - The action to be logged.
|
|
20
|
+
*
|
|
19
21
|
* @param data - The data to be logged.
|
|
20
22
|
*/
|
|
21
|
-
log(action: ELogActions, data: NonNullable<unknown>): void;
|
|
23
|
+
static log(action: ELogActions, data: NonNullable<unknown>): void;
|
|
22
24
|
}
|
|
@@ -1,35 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.LogService = void 0;
|
|
7
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
var Logging_1 = require("../../enums/Logging");
|
|
4
9
|
/**
|
|
5
10
|
* Handles logging of data for debug purpose.
|
|
6
11
|
*
|
|
7
12
|
* @internal
|
|
8
13
|
*/
|
|
9
|
-
var LogService = /** @class */ (function () {
|
|
14
|
+
var LogService = exports.LogService = /** @class */ (function () {
|
|
15
|
+
function LogService() {
|
|
16
|
+
}
|
|
10
17
|
/**
|
|
11
|
-
*
|
|
18
|
+
* @param action - The action to be logged.
|
|
12
19
|
*
|
|
13
|
-
* @
|
|
20
|
+
* @returns - The colored text representing the action.
|
|
14
21
|
*/
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
};
|
|
18
30
|
/**
|
|
19
31
|
* Logs the given data.
|
|
20
32
|
*
|
|
33
|
+
* @param action - The action to be logged.
|
|
34
|
+
*
|
|
21
35
|
* @param data - The data to be logged.
|
|
22
36
|
*/
|
|
23
|
-
LogService.
|
|
37
|
+
LogService.log = function (action, data) {
|
|
24
38
|
// Proceed to log only if logging is enabled
|
|
25
39
|
if (this.enabled) {
|
|
26
40
|
// Preparing the log message
|
|
27
|
-
var
|
|
41
|
+
var logPrefix = chalk_1.default.blue('Rettiwt-API');
|
|
42
|
+
var logTime = new Date().toISOString();
|
|
43
|
+
var logAction = LogService.getColoredAction(action);
|
|
44
|
+
var logData = JSON.stringify(data);
|
|
45
|
+
var logMessage = "[".concat(logPrefix, "] [").concat(logTime, "] [").concat(logAction, "] ").concat(logData);
|
|
28
46
|
// Logging
|
|
29
47
|
console.log(logMessage);
|
|
30
48
|
}
|
|
31
49
|
};
|
|
50
|
+
/** Whether logging is enabled or not. */
|
|
51
|
+
LogService.enabled = false;
|
|
32
52
|
return LogService;
|
|
33
53
|
}());
|
|
34
|
-
exports.LogService = LogService;
|
|
35
54
|
//# 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":";;;;;;AAAA,gDAA0B;AAE1B,+CAAkD;AAElD;;;;GAIG;AACH;IAAA;IAuCA,CAAC;IAnCA;;;;OAIG;IACY,2BAAgB,GAA/B,UAAgC,MAAmB;QAClD,IAAI,MAAM,IAAI,qBAAW,CAAC,OAAO,EAAE;YAClC,OAAO,eAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAC5B;aAAM;YACN,OAAO,eAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAC3B;IACF,CAAC;IAED;;;;;;OAMG;IACW,cAAG,GAAjB,UAAkB,MAAmB,EAAE,IAA0B;QAChE,4CAA4C;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,4BAA4B;YAC5B,IAAM,SAAS,GAAW,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACpD,IAAM,OAAO,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACjD,IAAM,SAAS,GAAW,UAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YAC9D,IAAM,OAAO,GAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAE7C,IAAM,UAAU,GAAW,WAAI,SAAS,gBAAM,OAAO,gBAAM,SAAS,eAAK,OAAO,CAAE,CAAC;YAEnF,UAAU;YACV,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;SACxB;IACF,CAAC;IArCD,yCAAyC;IAC3B,kBAAO,GAAY,KAAK,CAAC;IAqCxC,iBAAC;CAAA,AAvCD,IAuCC"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { FetcherService } from '../internal/FetcherService';
|
|
2
1
|
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
8
|
export declare class AuthService extends FetcherService {
|
|
9
9
|
/**
|
|
10
|
-
* @param config - The config object for configuring the Rettiwt instance.
|
|
10
|
+
* @param config - The config object for configuring the `Rettiwt` instance.
|
|
11
11
|
*
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
14
14
|
constructor(config?: IRettiwtConfig);
|
|
15
15
|
/**
|
|
16
|
-
* Login to twitter
|
|
16
|
+
* Login to twitter as guest.
|
|
17
17
|
*
|
|
18
|
-
* @
|
|
19
|
-
* @param userName - The username associated with the Twitter account.
|
|
20
|
-
* @param password - The password to the Twitter account.
|
|
21
|
-
* @returns The API_KEY for the Twitter account.
|
|
18
|
+
* @returns A new guest key.
|
|
22
19
|
*
|
|
23
20
|
* @example
|
|
24
21
|
* ```
|
|
@@ -27,10 +24,10 @@ export declare class AuthService extends FetcherService {
|
|
|
27
24
|
* // Creating a new Rettiwt instance
|
|
28
25
|
* const rettiwt = new Rettiwt();
|
|
29
26
|
*
|
|
30
|
-
* // Logging in an getting
|
|
31
|
-
* rettiwt.auth.
|
|
32
|
-
* .then(
|
|
33
|
-
* // Use the
|
|
27
|
+
* // Logging in an getting a new guest key
|
|
28
|
+
* rettiwt.auth.guest()
|
|
29
|
+
* .then(guestKey => {
|
|
30
|
+
* // Use the guest key
|
|
34
31
|
* ...
|
|
35
32
|
* })
|
|
36
33
|
* .catch(err => {
|
|
@@ -38,11 +35,15 @@ export declare class AuthService extends FetcherService {
|
|
|
38
35
|
* });
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
|
|
38
|
+
guest(): Promise<string>;
|
|
42
39
|
/**
|
|
43
|
-
* Login to twitter
|
|
40
|
+
* Login to twitter using account credentials.
|
|
44
41
|
*
|
|
45
|
-
* @
|
|
42
|
+
* @param email - The email id associated with the Twitter account.
|
|
43
|
+
* @param userName - The username associated with the Twitter account.
|
|
44
|
+
* @param password - The password to the Twitter account.
|
|
45
|
+
*
|
|
46
|
+
* @returns The `API_KEY` for the Twitter account.
|
|
46
47
|
*
|
|
47
48
|
* @example
|
|
48
49
|
* ```
|
|
@@ -51,16 +52,19 @@ export declare class AuthService extends FetcherService {
|
|
|
51
52
|
* // Creating a new Rettiwt instance
|
|
52
53
|
* const rettiwt = new Rettiwt();
|
|
53
54
|
*
|
|
54
|
-
* // Logging in an getting
|
|
55
|
-
* rettiwt.auth.
|
|
56
|
-
* .then(
|
|
57
|
-
* // Use the
|
|
55
|
+
* // Logging in an getting the API_KEY
|
|
56
|
+
* rettiwt.auth.login("email@domain.com", "username", "password")
|
|
57
|
+
* .then(apiKey => {
|
|
58
|
+
* // Use the API_KEY
|
|
58
59
|
* ...
|
|
59
60
|
* })
|
|
60
61
|
* .catch(err => {
|
|
61
62
|
* console.log(err);
|
|
62
63
|
* });
|
|
63
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Interchanging `email` and `userName` works too.
|
|
64
68
|
*/
|
|
65
|
-
|
|
69
|
+
login(email: string, userName: string, password: string): Promise<string>;
|
|
66
70
|
}
|