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,205 +0,0 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.AuthService = void 0;
|
|
55
|
-
var rettiwt_auth_1 = require("rettiwt-auth");
|
|
56
|
-
var Api_1 = require("../../enums/Api");
|
|
57
|
-
var FetcherService_1 = require("./FetcherService");
|
|
58
|
-
/**
|
|
59
|
-
* The services that handles authentication.
|
|
60
|
-
*
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
|
-
var AuthService = /** @class */ (function (_super) {
|
|
64
|
-
__extends(AuthService, _super);
|
|
65
|
-
/**
|
|
66
|
-
* @param config - The config object for configuring the `Rettiwt` instance.
|
|
67
|
-
*
|
|
68
|
-
* @internal
|
|
69
|
-
*/
|
|
70
|
-
function AuthService(config) {
|
|
71
|
-
return _super.call(this, config) || this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Decodes the encoded cookie string.
|
|
75
|
-
*
|
|
76
|
-
* @param encodedCookies - The encoded cookie string to decode.
|
|
77
|
-
* @returns The decoded cookie string.
|
|
78
|
-
*/
|
|
79
|
-
AuthService.decodeCookie = function (encodedCookies) {
|
|
80
|
-
// Decoding the encoded cookie string
|
|
81
|
-
var decodedCookies = Buffer.from(encodedCookies, 'base64').toString('ascii');
|
|
82
|
-
return decodedCookies;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Encodes the given cookie string.
|
|
86
|
-
*
|
|
87
|
-
* @param cookieString - The cookie string to encode.
|
|
88
|
-
* @returns The encoded cookie string.
|
|
89
|
-
*/
|
|
90
|
-
AuthService.encodeCookie = function (cookieString) {
|
|
91
|
-
// Encoding the cookie string to base64
|
|
92
|
-
var encodedCookies = Buffer.from(cookieString).toString('base64');
|
|
93
|
-
return encodedCookies;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Gets the user's id from the given API key.
|
|
97
|
-
*
|
|
98
|
-
* @param apiKey - The API key.
|
|
99
|
-
* @returns The user id associated with the API key.
|
|
100
|
-
*/
|
|
101
|
-
AuthService.getUserId = function (apiKey) {
|
|
102
|
-
// Getting the cookie string from the API key
|
|
103
|
-
var cookieString = AuthService.decodeCookie(apiKey);
|
|
104
|
-
// Searching for the user id in the cookie string
|
|
105
|
-
var searchResults = cookieString.match(/((?<=twid="u=)(\d+)(?="))|((?<=twid=u%3D)(\d+)(?=;))/);
|
|
106
|
-
// If user id was found
|
|
107
|
-
if (searchResults) {
|
|
108
|
-
return searchResults[0];
|
|
109
|
-
}
|
|
110
|
-
// If user id was not found
|
|
111
|
-
else {
|
|
112
|
-
throw new Error(Api_1.EApiErrors.BAD_AUTHENTICATION);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Login to twitter as guest.
|
|
117
|
-
*
|
|
118
|
-
* @returns A new guest key.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* ```
|
|
122
|
-
* import { Rettiwt } from 'rettiwt-api';
|
|
123
|
-
*
|
|
124
|
-
* // Creating a new Rettiwt instance
|
|
125
|
-
* const rettiwt = new Rettiwt();
|
|
126
|
-
*
|
|
127
|
-
* // Logging in an getting a new guest key
|
|
128
|
-
* rettiwt.auth.guest()
|
|
129
|
-
* .then(guestKey => {
|
|
130
|
-
* // Use the guest key
|
|
131
|
-
* ...
|
|
132
|
-
* })
|
|
133
|
-
* .catch(err => {
|
|
134
|
-
* console.log(err);
|
|
135
|
-
* });
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
AuthService.prototype.guest = function () {
|
|
139
|
-
var _a;
|
|
140
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
-
var guestKey;
|
|
142
|
-
return __generator(this, function (_b) {
|
|
143
|
-
switch (_b.label) {
|
|
144
|
-
case 0: return [4 /*yield*/, new rettiwt_auth_1.Auth().getGuestCredential()];
|
|
145
|
-
case 1:
|
|
146
|
-
guestKey = (_a = (_b.sent()).guestToken) !== null && _a !== void 0 ? _a : '';
|
|
147
|
-
return [2 /*return*/, guestKey];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Login to twitter using account credentials.
|
|
154
|
-
*
|
|
155
|
-
* @param email - The email id associated with the Twitter account.
|
|
156
|
-
* @param userName - The username associated with the Twitter account.
|
|
157
|
-
* @param password - The password to the Twitter account.
|
|
158
|
-
*
|
|
159
|
-
* @returns The `API_KEY` for the Twitter account.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```
|
|
163
|
-
* import { Rettiwt } from 'rettiwt-api';
|
|
164
|
-
*
|
|
165
|
-
* // Creating a new Rettiwt instance
|
|
166
|
-
* const rettiwt = new Rettiwt();
|
|
167
|
-
*
|
|
168
|
-
* // Logging in an getting the API_KEY
|
|
169
|
-
* rettiwt.auth.login("email@domain.com", "username", "password")
|
|
170
|
-
* .then(apiKey => {
|
|
171
|
-
* // Use the API_KEY
|
|
172
|
-
* ...
|
|
173
|
-
* })
|
|
174
|
-
* .catch(err => {
|
|
175
|
-
* console.log(err);
|
|
176
|
-
* });
|
|
177
|
-
* ```
|
|
178
|
-
*
|
|
179
|
-
* @remarks
|
|
180
|
-
* Interchanging `email` and `userName` works too.
|
|
181
|
-
*/
|
|
182
|
-
AuthService.prototype.login = function (email, userName, password) {
|
|
183
|
-
var _a;
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var apiKey;
|
|
186
|
-
return __generator(this, function (_b) {
|
|
187
|
-
switch (_b.label) {
|
|
188
|
-
case 0: return [4 /*yield*/, new rettiwt_auth_1.Auth({ proxyUrl: this.authProxyUrl }).getUserCredential({
|
|
189
|
-
email: email,
|
|
190
|
-
userName: userName,
|
|
191
|
-
password: password,
|
|
192
|
-
})];
|
|
193
|
-
case 1:
|
|
194
|
-
apiKey = (_a = (_b.sent()).toHeader().cookie) !== null && _a !== void 0 ? _a : '';
|
|
195
|
-
// Converting the credentials to base64 string
|
|
196
|
-
apiKey = AuthService.encodeCookie(apiKey);
|
|
197
|
-
return [2 /*return*/, apiKey];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
return AuthService;
|
|
203
|
-
}(FetcherService_1.FetcherService));
|
|
204
|
-
exports.AuthService = AuthService;
|
|
205
|
-
//# sourceMappingURL=AuthService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/public/AuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAoC;AAEpC,uCAA6C;AAG7C,mDAAkD;AAElD;;;;GAIG;AACH;IAAiC,+BAAc;IAC9C;;;;OAIG;IACH,qBAAmB,MAAuB;eACzC,kBAAM,MAAM,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACW,wBAAY,GAA1B,UAA2B,cAAsB;QAChD,qCAAqC;QACrC,IAAM,cAAc,GAAW,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEvF,OAAO,cAAc,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACW,wBAAY,GAA1B,UAA2B,YAAoB;QAC9C,uCAAuC;QACvC,IAAM,cAAc,GAAW,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAE5E,OAAO,cAAc,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACW,qBAAS,GAAvB,UAAwB,MAAc;QACrC,6CAA6C;QAC7C,IAAM,YAAY,GAAW,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAE9D,iDAAiD;QACjD,IAAM,aAAa,GAAoB,YAAY,CAAC,KAAK,CACxD,sDAAsD,CACtD,CAAC;QAEF,uBAAuB;QACvB,IAAI,aAAa,EAAE;YAClB,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC;SACxB;QACD,2BAA2B;aACtB;YACJ,MAAM,IAAI,KAAK,CAAC,gBAAU,CAAC,kBAAkB,CAAC,CAAC;SAC/C;IACF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,2BAAK,GAAlB;;;;;;4BAE2B,qBAAM,IAAI,mBAAI,EAAE,CAAC,kBAAkB,EAAE,EAAA;;wBAAzD,QAAQ,GAAW,MAAA,CAAC,SAAqC,CAAC,CAAC,UAAU,mCAAI,EAAE;wBAEjF,sBAAO,QAAQ,EAAC;;;;KAChB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACU,2BAAK,GAAlB,UAAmB,KAAa,EAAE,QAAgB,EAAE,QAAgB;;;;;;4BAIjE,qBAAM,IAAI,mBAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,iBAAiB,CAAC;4BACjE,KAAK,EAAE,KAAK;4BACZ,QAAQ,EAAE,QAAQ;4BAClB,QAAQ,EAAE,QAAQ;yBAClB,CAAC,EAAA;;wBANA,MAAM,GACT,MAAC,CACA,SAIE,CACF,CAAC,QAAQ,EAAE,CAAC,MAAiB,mCAAI,EAAE;wBAErC,8CAA8C;wBAC9C,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;wBAE1C,sBAAO,MAAM,EAAC;;;;KACd;IACF,kBAAC;AAAD,CAAC,AAzID,CAAiC,+BAAc,GAyI9C;AAzIY,kCAAW"}
|
package/src/commands/Auth.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Command, createCommand } from 'commander';
|
|
2
|
-
|
|
3
|
-
import { output } from '../helper/CliUtils';
|
|
4
|
-
import { Rettiwt } from '../Rettiwt';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new 'auth' command which uses the given Rettiwt instance.
|
|
8
|
-
*
|
|
9
|
-
* @param rettiwt - The Rettiwt instance to use.
|
|
10
|
-
* @returns The created 'auth' command.
|
|
11
|
-
*/
|
|
12
|
-
function createAuthCommand(rettiwt: Rettiwt): Command {
|
|
13
|
-
// Creating the 'auth' command
|
|
14
|
-
const auth = createCommand('auth').description('Manage authentication');
|
|
15
|
-
|
|
16
|
-
// Login
|
|
17
|
-
auth.command('login')
|
|
18
|
-
.description('Generate a new API key using Twitter account login credentials')
|
|
19
|
-
.argument('<email>', 'The email id of the Twitter account')
|
|
20
|
-
.argument('<username>', 'The username associated with the Twitter account')
|
|
21
|
-
.argument('<password>', 'The password to the Twitter account')
|
|
22
|
-
.action(async (email: string, username: string, password: string) => {
|
|
23
|
-
try {
|
|
24
|
-
const apiKey: string = await rettiwt.auth.login(email, username, password);
|
|
25
|
-
output(apiKey);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
output(error);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Guest
|
|
32
|
-
auth.command('guest')
|
|
33
|
-
.description('Generate a new guest key')
|
|
34
|
-
.action(async () => {
|
|
35
|
-
try {
|
|
36
|
-
const guestKey: string = await rettiwt.auth.guest();
|
|
37
|
-
output(guestKey);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
output(error);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return auth;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default createAuthCommand;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents and error when any fields of a validation-enabled class fails to validate.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export class DataValidationError {
|
|
9
|
-
/** The detaied error message(s). */
|
|
10
|
-
public details: ValidationErrorDetails[];
|
|
11
|
-
|
|
12
|
-
/** The user-friendly error message. */
|
|
13
|
-
public message: string;
|
|
14
|
-
|
|
15
|
-
/** The name of the error. */
|
|
16
|
-
public name: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param data - The error details, as a list of type {@link ValidationError}
|
|
20
|
-
*/
|
|
21
|
-
public constructor(errorDetails: ValidationError[]) {
|
|
22
|
-
this.name = 'VALIDATION_ERROR';
|
|
23
|
-
this.message = 'One or more validation error(s) occured, check details field.';
|
|
24
|
-
this.details = errorDetails.map((error) => new ValidationErrorDetails(error));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Represents the validation error details of a single field.
|
|
30
|
-
*
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export class ValidationErrorDetails {
|
|
34
|
-
/** The constraints which failed to be validated for the given field. */
|
|
35
|
-
public constraints: string[];
|
|
36
|
-
|
|
37
|
-
/** The name of the field which failed validation. */
|
|
38
|
-
public field: string;
|
|
39
|
-
|
|
40
|
-
public constructor(details: ValidationError) {
|
|
41
|
-
this.field = details.property;
|
|
42
|
-
this.constraints = Object.values(details.constraints!);
|
|
43
|
-
}
|
|
44
|
-
}
|