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.
Files changed (139) hide show
  1. package/.eslintrc.js +73 -5
  2. package/.tool-versions +1 -0
  3. package/README.md +87 -20
  4. package/dist/Rettiwt.js +0 -1
  5. package/dist/Rettiwt.js.map +1 -1
  6. package/dist/cli.js +2 -4
  7. package/dist/cli.js.map +1 -1
  8. package/dist/collections/Extractors.d.ts +37 -0
  9. package/dist/collections/Extractors.js +67 -0
  10. package/dist/collections/Extractors.js.map +1 -0
  11. package/dist/collections/Groups.d.ts +19 -0
  12. package/dist/collections/Groups.js +55 -0
  13. package/dist/collections/Groups.js.map +1 -0
  14. package/dist/collections/Requests.d.ts +12 -0
  15. package/dist/collections/Requests.js +46 -0
  16. package/dist/collections/Requests.js.map +1 -0
  17. package/dist/commands/Auth.d.ts +6 -0
  18. package/dist/commands/Auth.js +26 -8
  19. package/dist/commands/Auth.js.map +1 -1
  20. package/dist/commands/Tweet.js +237 -82
  21. package/dist/commands/Tweet.js.map +1 -1
  22. package/dist/commands/User.js +197 -36
  23. package/dist/commands/User.js.map +1 -1
  24. package/dist/enums/Api.d.ts +30 -0
  25. package/dist/enums/Api.js +32 -1
  26. package/dist/enums/Api.js.map +1 -1
  27. package/dist/enums/Data.d.ts +9 -0
  28. package/dist/enums/Data.js +14 -0
  29. package/dist/enums/Data.js.map +1 -0
  30. package/dist/enums/Http.d.ts +1 -1
  31. package/dist/enums/Http.js +1 -1
  32. package/dist/enums/Logging.d.ts +6 -5
  33. package/dist/enums/Logging.js +6 -5
  34. package/dist/enums/Logging.js.map +1 -1
  35. package/dist/enums/Resource.d.ts +33 -0
  36. package/dist/enums/Resource.js +42 -0
  37. package/dist/enums/Resource.js.map +1 -0
  38. package/dist/helper/CliUtils.d.ts +1 -1
  39. package/dist/helper/CliUtils.js.map +1 -1
  40. package/dist/index.d.ts +11 -9
  41. package/dist/index.js +11 -14
  42. package/dist/index.js.map +1 -1
  43. package/dist/models/args/FetchArgs.d.ts +129 -0
  44. package/dist/models/args/FetchArgs.js +263 -0
  45. package/dist/models/args/FetchArgs.js.map +1 -0
  46. package/dist/models/args/PostArgs.d.ts +116 -0
  47. package/dist/models/args/PostArgs.js +232 -0
  48. package/dist/models/args/PostArgs.js.map +1 -0
  49. package/dist/models/data/CursoredData.d.ts +11 -11
  50. package/dist/models/data/CursoredData.js +21 -16
  51. package/dist/models/data/CursoredData.js.map +1 -1
  52. package/dist/models/data/List.d.ts +8 -10
  53. package/dist/models/data/List.js +2 -4
  54. package/dist/models/data/List.js.map +1 -1
  55. package/dist/models/data/Tweet.d.ts +44 -29
  56. package/dist/models/data/Tweet.js +74 -15
  57. package/dist/models/data/Tweet.js.map +1 -1
  58. package/dist/models/data/User.d.ts +38 -20
  59. package/dist/models/data/User.js +71 -7
  60. package/dist/models/data/User.js.map +1 -1
  61. package/dist/models/errors/ApiError.d.ts +1 -3
  62. package/dist/models/errors/ApiError.js +1 -4
  63. package/dist/models/errors/ApiError.js.map +1 -1
  64. package/dist/models/errors/DataValidationError.d.ts +30 -0
  65. package/dist/models/errors/DataValidationError.js +34 -0
  66. package/dist/models/errors/DataValidationError.js.map +1 -0
  67. package/dist/models/errors/HttpError.d.ts +1 -3
  68. package/dist/models/errors/HttpError.js +1 -4
  69. package/dist/models/errors/HttpError.js.map +1 -1
  70. package/dist/models/errors/TimeoutError.d.ts +2 -4
  71. package/dist/models/errors/TimeoutError.js +2 -5
  72. package/dist/models/errors/TimeoutError.js.map +1 -1
  73. package/dist/services/internal/ErrorService.d.ts +45 -35
  74. package/dist/services/internal/ErrorService.js +70 -68
  75. package/dist/services/internal/ErrorService.js.map +1 -1
  76. package/dist/services/internal/LogService.d.ts +7 -5
  77. package/dist/services/internal/LogService.js +28 -9
  78. package/dist/services/internal/LogService.js.map +1 -1
  79. package/dist/services/public/AuthService.d.ts +24 -20
  80. package/dist/services/public/AuthService.js +38 -36
  81. package/dist/services/public/AuthService.js.map +1 -1
  82. package/dist/services/public/FetcherService.d.ts +89 -0
  83. package/dist/services/public/FetcherService.js +240 -0
  84. package/dist/services/public/FetcherService.js.map +1 -0
  85. package/dist/services/public/TweetService.d.ts +213 -94
  86. package/dist/services/public/TweetService.js +409 -209
  87. package/dist/services/public/TweetService.js.map +1 -1
  88. package/dist/services/public/UserService.d.ts +185 -52
  89. package/dist/services/public/UserService.js +338 -103
  90. package/dist/services/public/UserService.js.map +1 -1
  91. package/dist/types/ReturnTypes.d.ts +21 -0
  92. package/dist/types/ReturnTypes.js +3 -0
  93. package/dist/types/ReturnTypes.js.map +1 -0
  94. package/package.json +4 -2
  95. package/src/Rettiwt.ts +0 -3
  96. package/src/cli.ts +2 -4
  97. package/src/collections/Extractors.ts +84 -0
  98. package/src/collections/Groups.ts +54 -0
  99. package/src/collections/Requests.ts +52 -0
  100. package/src/commands/Auth.ts +19 -7
  101. package/src/commands/Tweet.ts +179 -91
  102. package/src/commands/User.ts +118 -25
  103. package/src/enums/Api.ts +31 -0
  104. package/src/enums/Data.ts +9 -0
  105. package/src/enums/Http.ts +1 -1
  106. package/src/enums/Logging.ts +6 -5
  107. package/src/enums/Resource.ts +40 -0
  108. package/src/helper/CliUtils.ts +1 -1
  109. package/src/index.ts +41 -14
  110. package/src/models/args/FetchArgs.ts +296 -0
  111. package/src/models/args/PostArgs.ts +263 -0
  112. package/src/models/data/CursoredData.ts +23 -15
  113. package/src/models/data/List.ts +12 -15
  114. package/src/models/data/Tweet.ts +108 -39
  115. package/src/models/data/User.ts +99 -30
  116. package/src/models/errors/ApiError.ts +1 -4
  117. package/src/models/errors/DataValidationError.ts +44 -0
  118. package/src/models/errors/HttpError.ts +1 -4
  119. package/src/models/errors/TimeoutError.ts +2 -5
  120. package/src/services/internal/ErrorService.ts +76 -75
  121. package/src/services/internal/LogService.ts +20 -10
  122. package/src/services/public/AuthService.ts +39 -38
  123. package/src/services/public/FetcherService.ts +209 -0
  124. package/src/services/public/TweetService.ts +384 -179
  125. package/src/services/public/UserService.ts +319 -86
  126. package/src/types/RettiwtConfig.ts +0 -1
  127. package/src/types/ReturnTypes.ts +24 -0
  128. package/dist/models/args/TweetArgs.d.ts +0 -44
  129. package/dist/models/args/TweetArgs.js +0 -82
  130. package/dist/models/args/TweetArgs.js.map +0 -1
  131. package/dist/models/data/Media.d.ts +0 -14
  132. package/dist/models/data/Media.js +0 -19
  133. package/dist/models/data/Media.js.map +0 -1
  134. package/dist/services/internal/FetcherService.d.ts +0 -106
  135. package/dist/services/internal/FetcherService.js +0 -365
  136. package/dist/services/internal/FetcherService.js.map +0 -1
  137. package/src/models/args/TweetArgs.ts +0 -98
  138. package/src/models/data/Media.ts +0 -19
  139. 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
- * The method called when an error response is received from Twitter API.
16
+ * Creates an API error instance based on the provided error code.
17
17
  *
18
- * @param error - The error caught while making HTTP request to Twitter API.
18
+ * @param errorCode - The error code.
19
+ *
20
+ * @returns An API error instance.
19
21
  */
20
- handle(error: unknown): void;
22
+ protected createApiError(errorCode: number): ApiError;
21
23
  /**
22
- * Handles exceeded timeout, configured in RettiwtConfig.
24
+ * Creates an HTTP error instance based on the provided HTTP status.
23
25
  *
24
- * @param error - The error object.
25
- * @throws An error if the configured request timeout has been exceeded.
26
+ * @param httpStatus - The HTTP status code.
27
+ *
28
+ * @returns An HTTP error instance.
26
29
  */
27
- protected handleTimeoutError(error: AxiosError): void;
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
- * Handles HTTP error in a response.
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
- * @param httpStatus - The HTTP status code.
54
- * @returns An HTTP error instance.
54
+ * @returns The error code, or undefined if not found.
55
55
  */
56
- protected createHttpError(httpStatus: number): HttpError;
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
- * Retrieves the API error code from the Axios response data.
66
+ * Handles API error in a response.
66
67
  *
67
68
  * @param response - The response object received.
68
- * @returns The error code, or undefined if not found.
69
+ *
70
+ * @throws An error with the corresponding API error message if any API-related error has occurred.
69
71
  */
70
- protected getErrorCode(response: AxiosResponse): number | undefined;
72
+ protected handleApiError(response: AxiosResponse): void;
71
73
  /**
72
- * Creates an API error instance based on the provided error code.
74
+ * Handles HTTP error in a response.
73
75
  *
74
- * @param errorCode - The error code.
75
- * @returns An API error instance.
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 createApiError(errorCode: number): ApiError;
80
+ protected handleHttpError(response: AxiosResponse): void;
78
81
  /**
79
- * Retrieves the API error message based on the provided error code.
82
+ * Handles exceeded timeout, configured in RettiwtConfig.
80
83
  *
81
- * @param errorCode - The error code.
82
- * @returns The API error message.
84
+ * @param error - The error object.
85
+ *
86
+ * @throws An error if the configured request timeout has been exceeded.
83
87
  */
84
- protected getApiErrorMessage(errorCode: number): string;
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
- // PACKAGES
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 rettiwt_core_1 = require("rettiwt-core");
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
- * The method called when an error response is received from Twitter API.
20
+ * Creates an API error instance based on the provided error code.
29
21
  *
30
- * @param error - The error caught while making HTTP request to Twitter API.
22
+ * @param errorCode - The error code.
23
+ *
24
+ * @returns An API error instance.
31
25
  */
32
- ErrorService.prototype.handle = function (error) {
33
- if (!axios_1.default.isAxiosError(error)) {
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
- * Handles exceeded timeout, configured in RettiwtConfig.
30
+ * Creates an HTTP error instance based on the provided HTTP status.
43
31
  *
44
- * @param error - The error object.
45
- * @throws An error if the configured request timeout has been exceeded.
32
+ * @param httpStatus - The HTTP status code.
33
+ *
34
+ * @returns An HTTP error instance.
46
35
  */
47
- ErrorService.prototype.handleTimeoutError = function (error) {
48
- if (error.code === 'ECONNABORTED') {
49
- throw new TimeoutError_1.TimeoutError(error.message);
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
- * Handles HTTP error in a response.
68
+ * Retrieves the API error code from the Axios response data.
67
69
  *
68
70
  * @param response - The response object received.
69
- * @throws An error with the corresponding HTTP status text if any HTTP-related error has occurred.
71
+ *
72
+ * @returns The error code, or undefined if not found.
70
73
  */
71
- ErrorService.prototype.handleHttpError = function (response) {
72
- throw this.createHttpError(response.status);
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
- * Creates an HTTP error instance based on the provided HTTP status.
105
+ * Handles HTTP error in a response.
89
106
  *
90
- * @param httpStatus - The HTTP status code.
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
- * @param httpStatus - The HTTP status code.
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.getHttpErrorMessage = function (httpStatus) {
103
- return Object.values(Http_1.EHttpStatus).includes(httpStatus)
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
- * Retrieves the API error code from the Axios response data.
115
+ * Handles exceeded timeout, configured in RettiwtConfig.
109
116
  *
110
- * @param response - The response object received.
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
- * @param errorCode - The error code.
121
- * @returns An API error instance.
119
+ * @throws An error if the configured request timeout has been exceeded.
122
120
  */
123
- ErrorService.prototype.createApiError = function (errorCode) {
124
- return new ApiError_1.ApiError(errorCode, this.getApiErrorMessage(errorCode));
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
- * Retrieves the API error message based on the provided error code.
127
+ * The method called when an error response is received from Twitter API.
128
128
  *
129
- * @param errorCode - The error code.
130
- * @returns The API error message.
129
+ * @param error - The error caught while making HTTP request to Twitter API.
131
130
  */
132
- ErrorService.prototype.getApiErrorMessage = function (errorCode) {
133
- var errorCodeKey = (0, JsonUtils_1.findKeyByValue)(rettiwt_core_1.EErrorCodes, errorCode.toString());
134
- return !!errorCodeKey && errorCodeKey in Api_1.EApiErrors
135
- ? Api_1.EApiErrors[errorCodeKey]
136
- : ErrorService.DEFAULT_ERROR_MESSAGE;
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":";;;;;;AAAA,WAAW;AACX,gDAAyD;AACzD,oDAAwD;AAKxD,QAAQ;AACR,uCAA6C;AAC7C,yCAA+C;AAC/C,6CAA2C;AAE3C,SAAS;AACT,yDAAwD;AACxD,2DAA0D;AAC1D,iEAAgE;AAEhE,yCAAyC;AAEzC;;;;GAIG;AACH;IAAA;IAqIA,CAAC;IA/HA;;;;OAIG;IACI,6BAAM,GAAb,UAAc,KAAc;QAC3B,IAAI,CAAC,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;YAC/B,MAAM,KAAK,CAAC;SACZ;QAED,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE/B,IAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACO,yCAAkB,GAA5B,UAA6B,KAAiB;QAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;YAClC,MAAM,IAAI,2BAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;SACtC;IACF,CAAC;IAED;;;;;;OAMG;IACO,uCAAgB,GAA1B,UAA2B,KAAiB;QAC3C,IAAI,KAAK,CAAC,QAAQ,EAAE;YACnB,OAAO,KAAK,CAAC,QAAQ,CAAC;SACtB;QAED,MAAM,KAAK,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACO,sCAAe,GAAzB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E;YACzB,MAAM,KAAK,CAAC;SACZ;QAED,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE/B,IAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;IA7ID;;OAEG;IACuB,kCAAqB,GAAG,eAAe,CAAC;IA2InE,mBAAC;CAAA,AA/ID,IA+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
- private readonly enabled;
9
+ static enabled: boolean;
10
10
  /**
11
- * Initializes a new LogService instance.
11
+ * @param action - The action to be logged.
12
12
  *
13
- * @param enable - Whether to enable logging or not.
13
+ * @returns - The colored text representing the action.
14
14
  */
15
- constructor(enable?: boolean);
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
- * Initializes a new LogService instance.
18
+ * @param action - The action to be logged.
12
19
  *
13
- * @param enable - Whether to enable logging or not.
20
+ * @returns - The colored text representing the action.
14
21
  */
15
- function LogService(enable) {
16
- this.enabled = enable !== null && enable !== void 0 ? enable : false;
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.prototype.log = function (action, data) {
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 logMessage = "[Rettiwt-API] [".concat(action, "] [").concat(new Date().toISOString(), "] ").concat(JSON.stringify(data));
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":";;;AAGA;;;;GAIG;AACH;IAIC;;;;OAIG;IACH,oBAAmB,MAAgB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,KAAK,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,wBAAG,GAAV,UAAW,MAAmB,EAAE,IAA0B;QACzD,4CAA4C;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE;YACjB,4BAA4B;YAC5B,IAAM,UAAU,GA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AY,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
- * Handles authentication.
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 using account credentials.
16
+ * Login to twitter as guest.
17
17
  *
18
- * @param email - The email id associated with the Twitter account.
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 the API_KEY
31
- * rettiwt.auth.login("email@domain.com", "username", "password")
32
- * .then(apiKey => {
33
- * // Use the API_KEY
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
- login(email: string, userName: string, password: string): Promise<string>;
38
+ guest(): Promise<string>;
42
39
  /**
43
- * Login to twitter as guest.
40
+ * Login to twitter using account credentials.
44
41
  *
45
- * @returns A new guest key.
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 a new guest key
55
- * rettiwt.auth.guest()
56
- * .then(guestKey => {
57
- * // Use the guest key
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
- guest(): Promise<string>;
69
+ login(email: string, userName: string, password: string): Promise<string>;
66
70
  }