rettiwt-api 1.1.2 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -7
- package/dist/endpoints/Endpoints.d.ts +14 -0
- package/dist/endpoints/Endpoints.js +20 -0
- package/dist/endpoints/Endpoints.js.map +1 -0
- package/dist/endpoints/Url.d.ts +5 -0
- package/dist/endpoints/Url.js +12 -0
- package/dist/endpoints/Url.js.map +1 -0
- package/dist/enums/Endpoints.d.ts +25 -0
- package/dist/enums/Endpoints.js +31 -0
- package/dist/enums/Endpoints.js.map +1 -0
- package/dist/enums/Errors.d.ts +20 -0
- package/dist/enums/Errors.js +28 -0
- package/dist/enums/Errors.js.map +1 -0
- package/dist/enums/HTTP.d.ts +17 -0
- package/dist/enums/HTTP.js +23 -0
- package/dist/enums/HTTP.js.map +1 -0
- package/dist/graphql/enums/Errors.d.ts +21 -0
- package/dist/graphql/enums/Errors.js +29 -0
- package/dist/graphql/enums/Errors.js.map +1 -0
- package/dist/graphql/queries/RootQuery.js +10 -3
- package/dist/graphql/queries/RootQuery.js.map +1 -1
- package/dist/graphql/resolvers/AccountResolver.d.ts +3 -3
- package/dist/graphql/resolvers/AccountResolver.js.map +1 -1
- package/dist/graphql/resolvers/ResolverBase.d.ts +14 -3
- package/dist/graphql/resolvers/ResolverBase.js +13 -1
- package/dist/graphql/resolvers/ResolverBase.js.map +1 -1
- package/dist/graphql/resolvers/TweetResolver.d.ts +3 -3
- package/dist/graphql/resolvers/TweetResolver.js +30 -18
- package/dist/graphql/resolvers/TweetResolver.js.map +1 -1
- package/dist/graphql/resolvers/UserResolver.d.ts +13 -4
- package/dist/graphql/resolvers/UserResolver.js +83 -18
- package/dist/graphql/resolvers/UserResolver.js.map +1 -1
- package/dist/graphql/types/Errors.d.ts +20 -0
- package/dist/graphql/types/Errors.js +28 -0
- package/dist/graphql/types/Errors.js.map +1 -0
- package/dist/graphql/types/TweetTypes.js +2 -2
- package/dist/graphql/types/TweetTypes.js.map +1 -1
- package/dist/graphql/types/UserTypes.js +1 -1
- package/dist/graphql/types/UserTypes.js.map +1 -1
- package/dist/index.d.ts +31 -15
- package/dist/index.js +32 -17
- package/dist/index.js.map +1 -1
- package/dist/middlewares/Authentication.d.ts +0 -0
- package/dist/middlewares/Authentication.js +2 -0
- package/dist/middlewares/Authentication.js.map +1 -0
- package/dist/models/args/TweetFilter.d.ts +59 -0
- package/dist/models/args/TweetFilter.js +101 -0
- package/dist/models/args/TweetFilter.js.map +1 -0
- package/dist/models/args/TweetListArgs.d.ts +21 -0
- package/dist/models/args/TweetListArgs.js +54 -0
- package/dist/models/args/TweetListArgs.js.map +1 -0
- package/dist/models/args/UserListArgs.d.ts +21 -0
- package/dist/models/args/UserListArgs.js +54 -0
- package/dist/models/args/UserListArgs.js.map +1 -0
- package/dist/models/auth/AuthCookie.d.ts +21 -0
- package/dist/models/auth/AuthCookie.js +33 -0
- package/dist/models/auth/AuthCookie.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +34 -0
- package/dist/models/data/CursoredData.js +42 -0
- package/dist/models/data/CursoredData.js.map +1 -0
- package/dist/models/data/DataValidationError.d.ts +18 -0
- package/dist/models/data/DataValidationError.js +21 -0
- package/dist/models/data/DataValidationError.js.map +1 -0
- package/dist/models/data/Errors.d.ts +18 -0
- package/dist/models/data/Errors.js +21 -0
- package/dist/models/data/Errors.js.map +1 -0
- package/dist/models/data/Service.d.ts +33 -0
- package/dist/models/data/Service.js +41 -0
- package/dist/models/data/Service.js.map +1 -0
- package/dist/models/data/Tweet.d.ts +53 -0
- package/dist/models/data/Tweet.js +104 -0
- package/dist/models/data/Tweet.js.map +1 -0
- package/dist/models/data/User.d.ts +41 -0
- package/dist/models/data/User.js +32 -0
- package/dist/models/data/User.js.map +1 -0
- package/dist/models/errors/DataValidationError.d.ts +20 -0
- package/dist/models/errors/DataValidationError.js +23 -0
- package/dist/models/errors/DataValidationError.js.map +1 -0
- package/dist/models/query/Variables.d.ts +2 -0
- package/dist/models/query/Variables.js +10 -0
- package/dist/models/query/Variables.js.map +1 -0
- package/dist/requests/Url.d.ts +5 -0
- package/dist/requests/Url.js +12 -0
- package/dist/requests/Url.js.map +1 -0
- package/dist/requests/payloads/Variables.d.ts +23 -0
- package/dist/requests/payloads/Variables.js +24 -0
- package/dist/requests/payloads/Variables.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +9 -10
- package/dist/server.js.map +1 -1
- package/dist/services/accounts/AccountService.d.ts +6 -0
- package/dist/services/accounts/AccountService.js +6 -0
- package/dist/services/accounts/AccountService.js.map +1 -1
- package/dist/services/auth/AccountService.d.ts +88 -0
- package/dist/services/auth/AccountService.js +392 -0
- package/dist/services/auth/AccountService.js.map +1 -0
- package/dist/services/auth/AuthService.d.ts +31 -0
- package/dist/services/auth/AuthService.js +118 -0
- package/dist/services/auth/AuthService.js.map +1 -0
- package/dist/services/auth/LoginFlows.d.ts +77 -0
- package/dist/services/auth/LoginFlows.js +92 -0
- package/dist/services/auth/LoginFlows.js.map +1 -0
- package/dist/services/data/TweetService.d.ts +46 -16
- package/dist/services/data/TweetService.js +71 -54
- package/dist/services/data/TweetService.js.map +1 -1
- package/dist/services/data/UserService.d.ts +58 -19
- package/dist/services/data/UserService.js +104 -68
- package/dist/services/data/UserService.js.map +1 -1
- package/dist/services/helper/Headers.d.ts +4 -4
- package/dist/services/helper/Headers.js.map +1 -1
- package/dist/services/helper/Parser.d.ts +2 -2
- package/dist/services/helper/Parser.js.map +1 -1
- package/dist/services/helper/extractors/Tweets.d.ts +6 -6
- package/dist/services/helper/extractors/Tweets.js +1 -1
- package/dist/services/helper/extractors/Tweets.js.map +1 -1
- package/dist/services/helper/extractors/Users.d.ts +10 -4
- package/dist/services/helper/extractors/Users.js +54 -2
- package/dist/services/helper/extractors/Users.js.map +1 -1
- package/dist/services/helper/payloads/LoginFlows.d.ts +77 -0
- package/dist/services/helper/payloads/LoginFlows.js +92 -0
- package/dist/services/helper/payloads/LoginFlows.js.map +1 -0
- package/dist/services/helper/urls/Users.d.ts +8 -1
- package/dist/services/helper/urls/Users.js +12 -2
- package/dist/services/helper/urls/Users.js.map +1 -1
- package/dist/services/util/CacheService.d.ts +33 -0
- package/dist/services/util/CacheService.js +96 -0
- package/dist/services/util/CacheService.js.map +1 -0
- package/dist/services/util/FetcherService.d.ts +65 -0
- package/dist/services/util/FetcherService.js +214 -0
- package/dist/services/util/FetcherService.js.map +1 -0
- package/dist/types/Args.d.ts +38 -0
- package/dist/types/Args.js +5 -0
- package/dist/types/Args.js.map +1 -0
- package/dist/types/Authentication.d.ts +17 -2
- package/dist/types/Authentication.js +1 -0
- package/dist/types/Authentication.js.map +1 -1
- package/dist/types/Query.d.ts +80 -0
- package/dist/types/Query.js +3 -0
- package/dist/types/Query.js.map +1 -0
- package/dist/types/Resolvers.d.ts +5 -4
- package/dist/types/Rettiwt.d.ts +16 -0
- package/dist/types/Rettiwt.js +3 -0
- package/dist/types/Rettiwt.js.map +1 -0
- package/dist/types/Service.d.ts +15 -23
- package/dist/types/Service.js +2 -16
- package/dist/types/Service.js.map +1 -1
- package/dist/types/Tweet.d.ts +25 -19
- package/dist/types/Tweet.js +0 -2
- package/dist/types/Tweet.js.map +1 -1
- package/dist/types/User.d.ts +35 -0
- package/dist/types/User.js +3 -0
- package/dist/types/User.js.map +1 -0
- package/dist/types/args/TweetFilter.d.ts +54 -0
- package/dist/types/args/TweetFilter.js +96 -0
- package/dist/types/args/TweetFilter.js.map +1 -0
- package/dist/types/args/TweetListArg.d.ts +10 -0
- package/dist/types/args/TweetListArg.js +42 -0
- package/dist/types/args/TweetListArg.js.map +1 -0
- package/dist/types/args/TweetListArgs.d.ts +20 -0
- package/dist/types/args/TweetListArgs.js +52 -0
- package/dist/types/args/TweetListArgs.js.map +1 -0
- package/dist/types/args/UserListArgs.d.ts +16 -0
- package/dist/types/args/UserListArgs.js +48 -0
- package/dist/types/args/UserListArgs.js.map +1 -0
- package/dist/types/data/TweetFilter.d.ts +49 -0
- package/dist/types/data/TweetFilter.js +63 -0
- package/dist/types/data/TweetFilter.js.map +1 -0
- package/dist/types/interfaces/Args.d.ts +38 -0
- package/dist/types/interfaces/Args.js +5 -0
- package/dist/types/interfaces/Args.js.map +1 -0
- package/dist/types/interfaces/Authentication.d.ts +40 -0
- package/dist/types/interfaces/Authentication.js +5 -0
- package/dist/types/interfaces/Authentication.js.map +1 -0
- package/dist/types/interfaces/Resolvers.d.ts +14 -0
- package/dist/types/interfaces/Resolvers.js +3 -0
- package/dist/types/interfaces/Resolvers.js.map +1 -0
- package/dist/types/interfaces/Rettiwt.d.ts +16 -0
- package/dist/types/interfaces/Rettiwt.js +3 -0
- package/dist/types/interfaces/Rettiwt.js.map +1 -0
- package/dist/types/interfaces/Service.d.ts +13 -0
- package/dist/types/interfaces/Service.js +3 -0
- package/dist/types/interfaces/Service.js.map +1 -0
- package/dist/types/interfaces/Services.d.ts +13 -0
- package/dist/types/interfaces/Services.js +3 -0
- package/dist/types/interfaces/Services.js.map +1 -0
- package/dist/types/interfaces/Tweet.d.ts +46 -0
- package/dist/types/interfaces/Tweet.js +3 -0
- package/dist/types/interfaces/Tweet.js.map +1 -0
- package/dist/types/interfaces/TweetFilter.d.ts +0 -0
- package/dist/types/interfaces/TweetFilter.js +2 -0
- package/dist/types/interfaces/TweetFilter.js.map +1 -0
- package/{src/types/data/User.ts → dist/types/interfaces/User.d.ts} +35 -51
- package/dist/types/interfaces/User.js +3 -0
- package/dist/types/interfaces/User.js.map +1 -0
- package/dist/types/raw/data/tweet/Favouriters.d.ts +164 -0
- package/dist/types/raw/data/tweet/Favouriters.js +3 -0
- package/dist/types/raw/data/tweet/Favouriters.js.map +1 -0
- package/dist/types/raw/data/tweet/Retweeters.d.ts +171 -0
- package/dist/types/raw/data/tweet/Retweeters.js +3 -0
- package/dist/types/raw/data/tweet/Retweeters.js.map +1 -0
- package/dist/types/raw/data/tweet/Tweet.d.ts +746 -0
- package/dist/types/raw/data/tweet/Tweet.js +3 -0
- package/dist/types/raw/data/tweet/Tweet.js.map +1 -0
- package/dist/types/raw/data/tweet/Tweets.d.ts +386 -0
- package/dist/types/raw/data/tweet/Tweets.js +3 -0
- package/dist/types/raw/data/tweet/Tweets.js.map +1 -0
- package/dist/types/raw/data/user/Followers.d.ts +176 -0
- package/dist/types/raw/data/user/Followers.js +3 -0
- package/dist/types/raw/data/user/Followers.js.map +1 -0
- package/dist/types/raw/data/user/Following.d.ts +176 -0
- package/dist/types/raw/data/user/Following.js +3 -0
- package/dist/types/raw/data/user/Following.js.map +1 -0
- package/dist/types/raw/data/user/Likes.d.ts +1059 -0
- package/dist/types/raw/data/user/Likes.js +3 -0
- package/dist/types/raw/data/user/Likes.js.map +1 -0
- package/dist/types/raw/data/user/User.d.ts +117 -0
- package/dist/types/raw/data/user/User.js +3 -0
- package/dist/types/raw/data/user/User.js.map +1 -0
- package/dist/types/raw/query/tweet/Details.d.ts +80 -0
- package/dist/types/raw/query/tweet/Details.js +5 -0
- package/dist/types/raw/query/tweet/Details.js.map +1 -0
- package/dist/types/raw/query/tweet/Engagements.d.ts +29 -0
- package/dist/types/raw/query/tweet/Engagements.js +3 -0
- package/dist/types/raw/query/tweet/Engagements.js.map +1 -0
- package/dist/types/raw/query/tweet/Likes.d.ts +29 -0
- package/dist/types/raw/query/tweet/Likes.js +3 -0
- package/dist/types/raw/query/tweet/Likes.js.map +1 -0
- package/dist/types/raw/query/tweet/Retweets.d.ts +29 -0
- package/dist/types/raw/query/tweet/Retweets.js +3 -0
- package/dist/types/raw/query/tweet/Retweets.js.map +1 -0
- package/dist/types/raw/query/tweet/Search.d.ts +40 -0
- package/dist/types/raw/query/tweet/Search.js +3 -0
- package/dist/types/raw/query/tweet/Search.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetDetails.d.ts +34 -0
- package/dist/types/raw/query/tweet/TweetDetails.js +5 -0
- package/dist/types/raw/query/tweet/TweetDetails.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetLike.d.ts +29 -0
- package/dist/types/raw/query/tweet/TweetLike.js +3 -0
- package/dist/types/raw/query/tweet/TweetLike.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetLikes.d.ts +29 -0
- package/dist/types/raw/query/tweet/TweetLikes.js +3 -0
- package/dist/types/raw/query/tweet/TweetLikes.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetRetweets.d.ts +0 -0
- package/dist/types/raw/query/tweet/TweetRetweets.js +2 -0
- package/dist/types/raw/query/tweet/TweetRetweets.js.map +1 -0
- package/dist/types/raw/query/user/Details.d.ts +34 -0
- package/dist/types/raw/query/user/Details.js +3 -0
- package/dist/types/raw/query/user/Details.js.map +1 -0
- package/dist/types/raw/user/Tweets.d.ts +668 -1584
- package/dist/types/services/args/TweetFilter.d.ts +50 -0
- package/dist/types/services/args/TweetFilter.js +76 -0
- package/dist/types/services/args/TweetFilter.js.map +1 -0
- package/package.json +6 -3
- package/src/enums/Errors.ts +21 -0
- package/src/graphql/enums/Errors.ts +22 -0
- package/src/graphql/queries/RootQuery.ts +11 -4
- package/src/graphql/resolvers/AccountResolver.ts +3 -3
- package/src/graphql/resolvers/ResolverBase.ts +19 -5
- package/src/graphql/resolvers/TweetResolver.ts +26 -17
- package/src/graphql/resolvers/UserResolver.ts +75 -20
- package/src/graphql/types/TweetTypes.ts +2 -2
- package/src/graphql/types/UserTypes.ts +4 -4
- package/src/index.ts +39 -17
- package/src/models/args/TweetFilter.ts +119 -0
- package/src/models/args/TweetListArgs.ts +47 -0
- package/src/models/args/UserListArgs.ts +47 -0
- package/src/models/auth/AuthCookie.ts +43 -0
- package/src/models/data/CursoredData.ts +45 -0
- package/src/models/data/Tweet.ts +118 -0
- package/src/models/data/User.ts +72 -0
- package/src/models/errors/DataValidationError.ts +29 -0
- package/src/server.ts +9 -10
- package/src/services/{accounts → auth}/AccountService.ts +71 -19
- package/src/services/auth/AuthService.ts +81 -0
- package/src/services/data/TweetService.ts +81 -62
- package/src/services/data/UserService.ts +118 -80
- package/src/services/helper/Headers.ts +4 -4
- package/src/services/helper/Parser.ts +2 -2
- package/src/services/helper/extractors/Tweets.ts +7 -7
- package/src/services/helper/extractors/Users.ts +60 -5
- package/src/services/helper/urls/Users.ts +39 -23
- package/src/services/{CacheService.ts → util/CacheService.ts} +4 -1
- package/src/services/{FetcherService.ts → util/FetcherService.ts} +19 -11
- package/src/types/Args.ts +49 -0
- package/src/types/Authentication.ts +29 -7
- package/src/types/Resolvers.ts +5 -4
- package/src/types/Rettiwt.ts +20 -0
- package/src/types/Service.ts +24 -0
- package/src/types/Tweet.ts +61 -0
- package/src/types/User.ts +48 -0
- package/src/types/raw/user/Tweets.ts +1747 -0
- package/tsconfig.json +2 -2
- package/src/services/AuthService.ts +0 -68
- package/src/services/helper/deserializers/Tweets.ts +0 -70
- package/src/services/helper/deserializers/Users.ts +0 -26
- package/src/types/data/Errors.ts +0 -37
- package/src/types/data/Service.ts +0 -55
- package/src/types/data/Tweet.ts +0 -123
- package/src/types/raw/auth/Cookie.ts +0 -16
- /package/src/{types → enums}/HTTP.ts +0 -0
- /package/src/services/{accounts → helper/payloads}/LoginFlows.ts +0 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
exports.AccountService = void 0;
|
|
43
|
+
// PACKAGES
|
|
44
|
+
var node_libcurl_1 = require("node-libcurl");
|
|
45
|
+
// SERVICES
|
|
46
|
+
var AuthService_1 = require("./AuthService");
|
|
47
|
+
// ENUMS
|
|
48
|
+
var HTTP_1 = require("../../enums/HTTP");
|
|
49
|
+
var Errors_1 = require("../../enums/Errors");
|
|
50
|
+
// HELPERS
|
|
51
|
+
var LoginFlows_1 = __importDefault(require("../helper/payloads/LoginFlows"));
|
|
52
|
+
var Headers_1 = require("../helper/Headers");
|
|
53
|
+
var cookiejar_1 = require("cookiejar");
|
|
54
|
+
/**
|
|
55
|
+
* Handles all operations related to a user's account, such as loggin in, managing account, etc
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
var AccountService = /** @class */ (function () {
|
|
59
|
+
function AccountService() {
|
|
60
|
+
this.auth = new AuthService_1.AuthService();
|
|
61
|
+
this.guestCreds = { authToken: '', guestToken: '' };
|
|
62
|
+
this.cookies = [];
|
|
63
|
+
this.flowToken = '';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @returns The current guest credentials to use. If if does not exists, then a new one is created
|
|
67
|
+
*/
|
|
68
|
+
AccountService.prototype.getGuestCredentials = function () {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var _a;
|
|
71
|
+
return __generator(this, function (_b) {
|
|
72
|
+
switch (_b.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
if (!!this.guestCreds.guestToken) return [3 /*break*/, 2];
|
|
75
|
+
_a = this;
|
|
76
|
+
return [4 /*yield*/, this.auth.getGuestCredentials()];
|
|
77
|
+
case 1:
|
|
78
|
+
_a.guestCreds = _b.sent();
|
|
79
|
+
_b.label = 2;
|
|
80
|
+
case 2: return [2 /*return*/, this.guestCreds];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Step 1: Initiates login
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
AccountService.prototype.initiateLogin = function () {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var res, _a, _b, _c, _d;
|
|
92
|
+
var _e;
|
|
93
|
+
return __generator(this, function (_f) {
|
|
94
|
+
switch (_f.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
97
|
+
_c = [LoginFlows_1["default"].InitiateLogin.url];
|
|
98
|
+
_e = {};
|
|
99
|
+
_d = Headers_1.loginHeader;
|
|
100
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
101
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.toString()]),
|
|
102
|
+
_e.sslVerifyPeer = false,
|
|
103
|
+
_e.postFields = '',
|
|
104
|
+
_e)]))];
|
|
105
|
+
case 2:
|
|
106
|
+
res = _f.sent();
|
|
107
|
+
// Storing cookies received
|
|
108
|
+
this.cookies = new cookiejar_1.CookieJar().setCookies(res.headers[0]['Set-Cookie']);
|
|
109
|
+
// Getting the flow token
|
|
110
|
+
this.flowToken = res.data['flow_token'];
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Step 2: Does something
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
AccountService.prototype.jsInstrumentationSubtask = function () {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var res, _a, _b, _c, _d;
|
|
123
|
+
var _e;
|
|
124
|
+
return __generator(this, function (_f) {
|
|
125
|
+
switch (_f.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
128
|
+
_c = [LoginFlows_1["default"].JsInstrumentationSubtask.url];
|
|
129
|
+
_e = {};
|
|
130
|
+
_d = Headers_1.loginHeader;
|
|
131
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
132
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
|
|
133
|
+
_e.sslVerifyPeer = false,
|
|
134
|
+
_e.postFields = JSON.stringify(LoginFlows_1["default"].JsInstrumentationSubtask.body(this.flowToken)),
|
|
135
|
+
_e)]))];
|
|
136
|
+
case 2:
|
|
137
|
+
res = _f.sent();
|
|
138
|
+
// Getting the flow token
|
|
139
|
+
this.flowToken = res.data['flow_token'];
|
|
140
|
+
return [2 /*return*/];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Step 3: Takes the email for login
|
|
147
|
+
* @internal
|
|
148
|
+
*
|
|
149
|
+
* @throws {@link AuthenticationErrors.InvalidEmail}, if email does not exist.
|
|
150
|
+
*/
|
|
151
|
+
AccountService.prototype.enterUserIdentifier = function (email) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var res, _a, _b, _c, _d;
|
|
154
|
+
var _e;
|
|
155
|
+
return __generator(this, function (_f) {
|
|
156
|
+
switch (_f.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
159
|
+
_c = [LoginFlows_1["default"].EnterUserIdentifier.url];
|
|
160
|
+
_e = {};
|
|
161
|
+
_d = Headers_1.loginHeader;
|
|
162
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
163
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
|
|
164
|
+
_e.sslVerifyPeer = false,
|
|
165
|
+
_e.postFields = JSON.stringify(LoginFlows_1["default"].EnterUserIdentifier.body(this.flowToken, email)),
|
|
166
|
+
_e)]))];
|
|
167
|
+
case 2:
|
|
168
|
+
res = _f.sent();
|
|
169
|
+
// If no account found with given email
|
|
170
|
+
if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
|
|
171
|
+
throw new Error(Errors_1.AuthenticationErrors.InvalidEmail);
|
|
172
|
+
}
|
|
173
|
+
// Getting the flow token
|
|
174
|
+
this.flowToken = res.data['flow_token'];
|
|
175
|
+
return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Step 4: Takes the username for login
|
|
182
|
+
* @internal
|
|
183
|
+
*
|
|
184
|
+
* @throws {@link AuthenticationErrors.InvalidUsername}, if wrong username entered.
|
|
185
|
+
*/
|
|
186
|
+
AccountService.prototype.enterAlternateUserIdentifier = function (userName) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var res, _a, _b, _c, _d;
|
|
189
|
+
var _e;
|
|
190
|
+
return __generator(this, function (_f) {
|
|
191
|
+
switch (_f.label) {
|
|
192
|
+
case 0:
|
|
193
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
194
|
+
_c = [LoginFlows_1["default"].EnterAlternateUserIdentifier.url];
|
|
195
|
+
_e = {};
|
|
196
|
+
_d = Headers_1.loginHeader;
|
|
197
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
198
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
|
|
199
|
+
_e.sslVerifyPeer = false,
|
|
200
|
+
_e.postFields = JSON.stringify(LoginFlows_1["default"].EnterAlternateUserIdentifier.body(this.flowToken, userName)),
|
|
201
|
+
_e)]))];
|
|
202
|
+
case 2:
|
|
203
|
+
res = _f.sent();
|
|
204
|
+
// If invalid username for the given account
|
|
205
|
+
if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
|
|
206
|
+
throw new Error(Errors_1.AuthenticationErrors.InvalidUsername);
|
|
207
|
+
}
|
|
208
|
+
// Getting the flow token
|
|
209
|
+
this.flowToken = res.data['flow_token'];
|
|
210
|
+
return [2 /*return*/];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Step 5: Takes the password for login
|
|
217
|
+
* @internal
|
|
218
|
+
*
|
|
219
|
+
* @throws {@link AuthenticationErrors.InvalidPassword}, incorrect password entered.
|
|
220
|
+
*/
|
|
221
|
+
AccountService.prototype.enterPassword = function (password) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
+
var res, _a, _b, _c, _d;
|
|
224
|
+
var _e;
|
|
225
|
+
return __generator(this, function (_f) {
|
|
226
|
+
switch (_f.label) {
|
|
227
|
+
case 0:
|
|
228
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
229
|
+
_c = [LoginFlows_1["default"].EnterPassword.url];
|
|
230
|
+
_e = {};
|
|
231
|
+
_d = Headers_1.loginHeader;
|
|
232
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
233
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
|
|
234
|
+
_e.sslVerifyPeer = false,
|
|
235
|
+
_e.postFields = JSON.stringify(LoginFlows_1["default"].EnterPassword.body(this.flowToken, password)),
|
|
236
|
+
_e)]))];
|
|
237
|
+
case 2:
|
|
238
|
+
res = _f.sent();
|
|
239
|
+
// If invalid password for the given account
|
|
240
|
+
if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
|
|
241
|
+
throw new Error(Errors_1.AuthenticationErrors.InvalidPassword);
|
|
242
|
+
}
|
|
243
|
+
// Getting the flow token
|
|
244
|
+
this.flowToken = res.data['flow_token'];
|
|
245
|
+
return [2 /*return*/];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Step 6: Gets the actual cookies
|
|
252
|
+
* @internal
|
|
253
|
+
*/
|
|
254
|
+
AccountService.prototype.accountDuplicationCheck = function () {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var res, _a, _b, _c, _d;
|
|
257
|
+
var _e;
|
|
258
|
+
return __generator(this, function (_f) {
|
|
259
|
+
switch (_f.label) {
|
|
260
|
+
case 0:
|
|
261
|
+
_b = (_a = node_libcurl_1.curly).post;
|
|
262
|
+
_c = [LoginFlows_1["default"].AccountDuplicationCheck.url];
|
|
263
|
+
_e = {};
|
|
264
|
+
_d = Headers_1.loginHeader;
|
|
265
|
+
return [4 /*yield*/, this.getGuestCredentials()];
|
|
266
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
|
|
267
|
+
_e.sslVerifyPeer = false,
|
|
268
|
+
_e.postFields = JSON.stringify(LoginFlows_1["default"].AccountDuplicationCheck.body(this.flowToken)),
|
|
269
|
+
_e)]))];
|
|
270
|
+
case 2:
|
|
271
|
+
res = _f.sent();
|
|
272
|
+
// Getting the cookies from the set-cookie header of the reponse.
|
|
273
|
+
this.cookies = new cookiejar_1.CookieJar().setCookies(res.headers[0]['Set-Cookie']);
|
|
274
|
+
// Getting the flow token
|
|
275
|
+
this.flowToken = res.data['flow_token'];
|
|
276
|
+
return [2 /*return*/];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Execute all the flows required to login to Twitter, using the given credentials, then set the response cookies.
|
|
283
|
+
*
|
|
284
|
+
* @internal
|
|
285
|
+
*
|
|
286
|
+
* @param email The email of the account to be logged into.
|
|
287
|
+
* @param userName The username associated with the given account.
|
|
288
|
+
* @param password The password to the account.
|
|
289
|
+
*/
|
|
290
|
+
AccountService.prototype.executeLoginFlows = function (email, userName, password) {
|
|
291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
+
return __generator(this, function (_a) {
|
|
293
|
+
switch (_a.label) {
|
|
294
|
+
case 0:
|
|
295
|
+
/**
|
|
296
|
+
* This works by sending a chain of request that are required for login to twitter.
|
|
297
|
+
* Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
|
|
298
|
+
* Each such method is called a subtask.
|
|
299
|
+
* Each subtask sets the {@link flowToken} property of the class which is then given in the payload of the next subtask.
|
|
300
|
+
* The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
|
|
301
|
+
*/
|
|
302
|
+
return [4 /*yield*/, this.initiateLogin()];
|
|
303
|
+
case 1:
|
|
304
|
+
/**
|
|
305
|
+
* This works by sending a chain of request that are required for login to twitter.
|
|
306
|
+
* Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
|
|
307
|
+
* Each such method is called a subtask.
|
|
308
|
+
* Each subtask sets the {@link flowToken} property of the class which is then given in the payload of the next subtask.
|
|
309
|
+
* The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
|
|
310
|
+
*/
|
|
311
|
+
_a.sent();
|
|
312
|
+
return [4 /*yield*/, this.jsInstrumentationSubtask()];
|
|
313
|
+
case 2:
|
|
314
|
+
_a.sent();
|
|
315
|
+
return [4 /*yield*/, this.enterUserIdentifier(email)];
|
|
316
|
+
case 3:
|
|
317
|
+
_a.sent();
|
|
318
|
+
return [4 /*yield*/, this.enterAlternateUserIdentifier(userName)];
|
|
319
|
+
case 4:
|
|
320
|
+
_a.sent();
|
|
321
|
+
return [4 /*yield*/, this.enterPassword(password)];
|
|
322
|
+
case 5:
|
|
323
|
+
_a.sent();
|
|
324
|
+
return [4 /*yield*/, this.accountDuplicationCheck()];
|
|
325
|
+
case 6:
|
|
326
|
+
_a.sent();
|
|
327
|
+
return [2 /*return*/];
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Parse the authentication cookies recieved from Twitter into known format.
|
|
334
|
+
*
|
|
335
|
+
* @internal
|
|
336
|
+
*
|
|
337
|
+
* @param cookies The raw cookies received from Twitter.
|
|
338
|
+
*
|
|
339
|
+
* @returns The parsed cookies of type {@link AuthCookie}
|
|
340
|
+
*/
|
|
341
|
+
AccountService.prototype.parseCookies = function (cookies) {
|
|
342
|
+
/** The tempoorary parsed cookies. */
|
|
343
|
+
var tempCookies = {};
|
|
344
|
+
/**
|
|
345
|
+
* Parsing the cookies into a standard JSON format.
|
|
346
|
+
* The format is 'cookie_name': 'cookie_value'.
|
|
347
|
+
* All other cookie parameters like expiry, etc are dropped.
|
|
348
|
+
*/
|
|
349
|
+
cookies.forEach(function (cookie) {
|
|
350
|
+
tempCookies[cookie.name] = cookie.value;
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
kdt: tempCookies['kdt'],
|
|
354
|
+
twid: tempCookies['twid'],
|
|
355
|
+
ct0: tempCookies['ct0'],
|
|
356
|
+
auth_token: tempCookies['auth_token']
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Login to Twitter using the given credentials and get back the cookies.
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
*
|
|
364
|
+
* @param email The email of the account to be logged into.
|
|
365
|
+
* @param userName The username associated with the given account.
|
|
366
|
+
* @param password The password to the account.
|
|
367
|
+
*
|
|
368
|
+
* @returns The cookies for authenticating with the given account.
|
|
369
|
+
*/
|
|
370
|
+
AccountService.prototype.login = function (email, userName, password) {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
var parsedCookies;
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
switch (_a.label) {
|
|
375
|
+
case 0:
|
|
376
|
+
// Executing all login flows
|
|
377
|
+
return [4 /*yield*/, this.executeLoginFlows(email, userName, password)];
|
|
378
|
+
case 1:
|
|
379
|
+
// Executing all login flows
|
|
380
|
+
_a.sent();
|
|
381
|
+
// Parsing the cookies
|
|
382
|
+
parsedCookies = this.parseCookies(this.cookies);
|
|
383
|
+
// Returning the final parsed cookies
|
|
384
|
+
return [2 /*return*/, parsedCookies];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
return AccountService;
|
|
390
|
+
}());
|
|
391
|
+
exports.AccountService = AccountService;
|
|
392
|
+
//# sourceMappingURL=AccountService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountService.js","sourceRoot":"","sources":["../../../src/services/auth/AccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAAkD;AAElD,WAAW;AACX,6CAA4C;AAK5C,QAAQ;AACR,yCAA8C;AAC9C,6CAA0D;AAE1D,UAAU;AACV,6EAAuD;AACvD,6CAAgD;AAChD,uCAA8C;AAE9C;;;GAGG;AACH;IAaI;QACI,IAAI,CAAC,IAAI,GAAG,IAAI,yBAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACW,4CAAmB,GAAjC;;;;;;6BAEQ,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAA3B,wBAA2B;wBAC3B,KAAA,IAAI,CAAA;wBAAc,qBAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAA;;wBAAvD,GAAK,UAAU,GAAG,SAAqC,CAAC;;4BAG5D,sBAAO,IAAI,CAAC,UAAU,EAAC;;;;KAC1B;IAED;;;OAGG;IACW,sCAAa,GAA3B;;;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31 @@
|
|
|
1
|
+
import { AuthCookie } from '../../models/auth/AuthCookie';
|
|
2
|
+
import { IGuestCredentials, IAuthCredentials } from '../../types/Authentication';
|
|
3
|
+
/**
|
|
4
|
+
* Handles authentication of http requests and other authentication related tasks.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuthService {
|
|
9
|
+
/** The common bearer token for authentication. */
|
|
10
|
+
private authToken;
|
|
11
|
+
/** The current authentication credentials. */
|
|
12
|
+
private credentials;
|
|
13
|
+
/** Whether instance has been authenticated or not. */
|
|
14
|
+
isAuthenticated: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @param cookie The cookie to be used for authenticating.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
*
|
|
20
|
+
* If no cookie is supplied, then guest authentication is used.
|
|
21
|
+
*/
|
|
22
|
+
constructor(cookie?: AuthCookie);
|
|
23
|
+
/**
|
|
24
|
+
* @returns The current authentication credentials. A different credential is returned each time this is invoked
|
|
25
|
+
*/
|
|
26
|
+
getAuthCredentials(): Promise<IAuthCredentials>;
|
|
27
|
+
/**
|
|
28
|
+
* @returns The guest credentials fetched from twitter.
|
|
29
|
+
*/
|
|
30
|
+
getGuestCredentials(): Promise<IGuestCredentials>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
exports.AuthService = void 0;
|
|
43
|
+
// PACKAGE
|
|
44
|
+
var axios_1 = __importDefault(require("axios"));
|
|
45
|
+
// URLS
|
|
46
|
+
var Authentication_1 = require("../helper/urls/Authentication");
|
|
47
|
+
// MODELS
|
|
48
|
+
var AuthCookie_1 = require("../../models/auth/AuthCookie");
|
|
49
|
+
// CONFIGS
|
|
50
|
+
var env_1 = require("../../config/env");
|
|
51
|
+
/**
|
|
52
|
+
* Handles authentication of http requests and other authentication related tasks.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
var AuthService = /** @class */ (function () {
|
|
57
|
+
/**
|
|
58
|
+
* @param cookie The cookie to be used for authenticating.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
*
|
|
62
|
+
* If no cookie is supplied, then guest authentication is used.
|
|
63
|
+
*/
|
|
64
|
+
function AuthService(cookie) {
|
|
65
|
+
// Reading the auth token from the config, since it's always the same
|
|
66
|
+
this.authToken = env_1.config.twitter_auth_token;
|
|
67
|
+
// Setting authentication status
|
|
68
|
+
this.isAuthenticated = ((cookie === null || cookie === void 0 ? void 0 : cookie.auth_token) && (cookie === null || cookie === void 0 ? void 0 : cookie.ct0) && (cookie === null || cookie === void 0 ? void 0 : cookie.kdt) && (cookie === null || cookie === void 0 ? void 0 : cookie.twid)) ? true : false;
|
|
69
|
+
// If a cookies is supplied, initializing authenticated credentials
|
|
70
|
+
if (this.isAuthenticated) {
|
|
71
|
+
// Converting the cookie from JSON to object
|
|
72
|
+
cookie = new AuthCookie_1.AuthCookie(cookie);
|
|
73
|
+
// Setting up the authenticated credentials
|
|
74
|
+
this.credentials = { authToken: this.authToken, csrfToken: cookie.ct0, cookie: cookie.toString() };
|
|
75
|
+
}
|
|
76
|
+
// If no cookie has been supplied, initializing empty credentials
|
|
77
|
+
else {
|
|
78
|
+
// Setting up the authenticated credentials
|
|
79
|
+
this.credentials = { authToken: this.authToken, csrfToken: '', cookie: '' };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @returns The current authentication credentials. A different credential is returned each time this is invoked
|
|
84
|
+
*/
|
|
85
|
+
AuthService.prototype.getAuthCredentials = function () {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
return [2 /*return*/, this.credentials];
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* @returns The guest credentials fetched from twitter.
|
|
94
|
+
*/
|
|
95
|
+
AuthService.prototype.getGuestCredentials = function () {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var _this = this;
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0: return [4 /*yield*/, axios_1["default"].post((0, Authentication_1.guestTokenUrl)(), null, {
|
|
101
|
+
headers: {
|
|
102
|
+
'Authorization': this.authToken
|
|
103
|
+
}
|
|
104
|
+
}).then(function (res) { return ({
|
|
105
|
+
authToken: _this.authToken,
|
|
106
|
+
guestToken: res.data.guest_token
|
|
107
|
+
}); })];
|
|
108
|
+
case 1:
|
|
109
|
+
// Getting the guest credentials from twitter
|
|
110
|
+
return [2 /*return*/, _a.sent()];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
return AuthService;
|
|
116
|
+
}());
|
|
117
|
+
exports.AuthService = AuthService;
|
|
118
|
+
//# sourceMappingURL=AuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/auth/AuthService.ts"],"names":[],"mappings":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AAK,CAAC,IAAI,CAA0B,IAAA,8BAAa,GAAE,EAAE,IAAI,EAAE;4BACpE,OAAO,EAAE;gCACL,eAAe,EAAE,IAAI,CAAC,SAAS;6BAClC;yBACJ,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC;4BACZ,SAAS,EAAE,KAAI,CAAC,SAAS;4BACzB,UAAU,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW;yBACnC,CAAC,EAHa,CAGb,CAAC,EAAA;;oBARH,6CAA6C;oBAC7C,sBAAO,SAOJ,EAAC;;;;KACP;IACL,kBAAC;AAAD,CAAC,AA5DD,IA4DC;AA5DY,kCAAW"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
declare const LoginFlows: {
|
|
2
|
+
InitiateLogin: {
|
|
3
|
+
url: string;
|
|
4
|
+
};
|
|
5
|
+
JsInstrumentationSubtask: {
|
|
6
|
+
url: string;
|
|
7
|
+
body: (flowToken: string) => {
|
|
8
|
+
flow_token: string;
|
|
9
|
+
subtask_inputs: {
|
|
10
|
+
subtask_id: string;
|
|
11
|
+
js_instrumentation: {
|
|
12
|
+
response: string;
|
|
13
|
+
link: string;
|
|
14
|
+
};
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
EnterUserIdentifier: {
|
|
19
|
+
url: string;
|
|
20
|
+
body: (flowToken: string, email: string) => {
|
|
21
|
+
flow_token: string;
|
|
22
|
+
subtask_inputs: {
|
|
23
|
+
subtask_id: string;
|
|
24
|
+
settings_list: {
|
|
25
|
+
setting_responses: {
|
|
26
|
+
key: string;
|
|
27
|
+
response_data: {
|
|
28
|
+
text_data: {
|
|
29
|
+
result: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}[];
|
|
33
|
+
link: string;
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
EnterAlternateUserIdentifier: {
|
|
39
|
+
url: string;
|
|
40
|
+
body: (flowToken: string, userName: string) => {
|
|
41
|
+
flow_token: string;
|
|
42
|
+
subtask_inputs: {
|
|
43
|
+
subtask_id: string;
|
|
44
|
+
enter_text: {
|
|
45
|
+
text: string;
|
|
46
|
+
link: string;
|
|
47
|
+
};
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
EnterPassword: {
|
|
52
|
+
url: string;
|
|
53
|
+
body: (flowToken: string, password: string) => {
|
|
54
|
+
flow_token: string;
|
|
55
|
+
subtask_inputs: {
|
|
56
|
+
subtask_id: string;
|
|
57
|
+
enter_password: {
|
|
58
|
+
password: string;
|
|
59
|
+
link: string;
|
|
60
|
+
};
|
|
61
|
+
}[];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
AccountDuplicationCheck: {
|
|
65
|
+
url: string;
|
|
66
|
+
body: (flowToken: string) => {
|
|
67
|
+
flow_token: string;
|
|
68
|
+
subtask_inputs: {
|
|
69
|
+
subtask_id: string;
|
|
70
|
+
check_logged_in_account: {
|
|
71
|
+
link: string;
|
|
72
|
+
};
|
|
73
|
+
}[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export default LoginFlows;
|