rettiwt-api 1.1.7 → 1.1.8

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.
@@ -8,11 +8,16 @@ export declare class AccountService {
8
8
  private auth;
9
9
  /** The current guest credentials to use. */
10
10
  private guestCreds;
11
+ /** The email id of Twitter account to be logged into. */
12
+ private email;
13
+ /** The user name of the Twitter account ot be logged into */
14
+ private userName;
15
+ /** The password to the Twitter account to be logged into. */
16
+ private password;
11
17
  /** The cookies received from Twitter after logging in. */
12
18
  private cookies;
13
19
  /** The flow token received after execution of current flow. */
14
20
  private flowToken;
15
- constructor();
16
21
  /**
17
22
  * @returns The current guest credentials to use. If if does not exists, then a new one is created
18
23
  */
@@ -53,16 +58,6 @@ export declare class AccountService {
53
58
  * @internal
54
59
  */
55
60
  private accountDuplicationCheck;
56
- /**
57
- * Execute all the flows required to login to Twitter, using the given credentials, then set the response cookies.
58
- *
59
- * @internal
60
- *
61
- * @param email The email of the account to be logged into.
62
- * @param userName The username associated with the given account.
63
- * @param password The password to the account.
64
- */
65
- private executeLoginFlows;
66
61
  /**
67
62
  * Parse the authentication cookies recieved from Twitter into known format.
68
63
  *
@@ -57,9 +57,19 @@ var cookiejar_1 = require("cookiejar");
57
57
  */
58
58
  var AccountService = /** @class */ (function () {
59
59
  function AccountService() {
60
+ /** The AuthService instance to use for authentication. */
60
61
  this.auth = new AuthService_1.AuthService();
62
+ /** The current guest credentials to use. */
61
63
  this.guestCreds = { authToken: '', guestToken: '' };
64
+ /** The email id of Twitter account to be logged into. */
65
+ this.email = '';
66
+ /** The user name of the Twitter account ot be logged into */
67
+ this.userName = '';
68
+ /** The password to the Twitter account to be logged into. */
69
+ this.password = '';
70
+ /** The cookies received from Twitter after logging in. */
62
71
  this.cookies = [];
72
+ /** The flow token received after execution of current flow. */
63
73
  this.flowToken = '';
64
74
  }
65
75
  /**
@@ -108,6 +118,11 @@ var AccountService = /** @class */ (function () {
108
118
  this.cookies = new cookiejar_1.CookieJar().setCookies(res.headers[0]['Set-Cookie']);
109
119
  // Getting the flow token
110
120
  this.flowToken = res.data['flow_token'];
121
+ // Executing next subtask
122
+ return [4 /*yield*/, this.jsInstrumentationSubtask()];
123
+ case 3:
124
+ // Executing next subtask
125
+ _f.sent();
111
126
  return [2 /*return*/];
112
127
  }
113
128
  });
@@ -137,6 +152,11 @@ var AccountService = /** @class */ (function () {
137
152
  res = _f.sent();
138
153
  // Getting the flow token
139
154
  this.flowToken = res.data['flow_token'];
155
+ // Executing next subtask
156
+ return [4 /*yield*/, this.enterUserIdentifier()];
157
+ case 3:
158
+ // Executing next subtask
159
+ _f.sent();
140
160
  return [2 /*return*/];
141
161
  }
142
162
  });
@@ -148,31 +168,54 @@ var AccountService = /** @class */ (function () {
148
168
  *
149
169
  * @throws {@link AuthenticationErrors.InvalidEmail}, if email does not exist.
150
170
  */
151
- AccountService.prototype.enterUserIdentifier = function (email) {
171
+ AccountService.prototype.enterUserIdentifier = function () {
152
172
  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) {
173
+ var res, _a, _b, _c, _d, _i, _e, task;
174
+ var _f;
175
+ return __generator(this, function (_g) {
176
+ switch (_g.label) {
157
177
  case 0:
158
178
  _b = (_a = node_libcurl_1.curly).post;
159
179
  _c = [LoginFlows_1["default"].EnterUserIdentifier.url];
160
- _e = {};
180
+ _f = {};
161
181
  _d = Headers_1.loginHeader;
162
182
  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)]))];
183
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_f.httpHeader = _d.apply(void 0, [_g.sent(), this.cookies.join(';').toString()]),
184
+ _f.sslVerifyPeer = false,
185
+ _f.postFields = JSON.stringify(LoginFlows_1["default"].EnterUserIdentifier.body(this.flowToken, this.email)),
186
+ _f)]))];
167
187
  case 2:
168
- res = _f.sent();
188
+ res = _g.sent();
169
189
  // If no account found with given email
170
190
  if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
171
191
  throw new Error(Errors_1.AuthenticationErrors.InvalidEmail);
172
192
  }
173
193
  // Getting the flow token
174
194
  this.flowToken = res.data['flow_token'];
175
- return [2 /*return*/];
195
+ _i = 0, _e = res.data.subtasks;
196
+ _g.label = 3;
197
+ case 3:
198
+ if (!(_i < _e.length)) return [3 /*break*/, 8];
199
+ task = _e[_i];
200
+ if (!(task['subtask_id'] == 'LoginEnterAlternateIdentifierSubtask')) return [3 /*break*/, 5];
201
+ // Executing next subtask
202
+ return [4 /*yield*/, this.enterAlternateUserIdentifier()];
203
+ case 4:
204
+ // Executing next subtask
205
+ _g.sent();
206
+ return [3 /*break*/, 8];
207
+ case 5:
208
+ if (!(task['subtask_id'] == 'LoginEnterPassword')) return [3 /*break*/, 7];
209
+ // Executing next subtask
210
+ return [4 /*yield*/, this.enterPassword()];
211
+ case 6:
212
+ // Executing next subtask
213
+ _g.sent();
214
+ return [3 /*break*/, 8];
215
+ case 7:
216
+ _i++;
217
+ return [3 /*break*/, 3];
218
+ case 8: return [2 /*return*/];
176
219
  }
177
220
  });
178
221
  });
@@ -183,7 +226,7 @@ var AccountService = /** @class */ (function () {
183
226
  *
184
227
  * @throws {@link AuthenticationErrors.InvalidUsername}, if wrong username entered.
185
228
  */
186
- AccountService.prototype.enterAlternateUserIdentifier = function (userName) {
229
+ AccountService.prototype.enterAlternateUserIdentifier = function () {
187
230
  return __awaiter(this, void 0, void 0, function () {
188
231
  var res, _a, _b, _c, _d;
189
232
  var _e;
@@ -197,7 +240,7 @@ var AccountService = /** @class */ (function () {
197
240
  return [4 /*yield*/, this.getGuestCredentials()];
198
241
  case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
199
242
  _e.sslVerifyPeer = false,
200
- _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterAlternateUserIdentifier.body(this.flowToken, userName)),
243
+ _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterAlternateUserIdentifier.body(this.flowToken, this.userName)),
201
244
  _e)]))];
202
245
  case 2:
203
246
  res = _f.sent();
@@ -207,6 +250,11 @@ var AccountService = /** @class */ (function () {
207
250
  }
208
251
  // Getting the flow token
209
252
  this.flowToken = res.data['flow_token'];
253
+ // Executing next subtask
254
+ return [4 /*yield*/, this.enterPassword()];
255
+ case 3:
256
+ // Executing next subtask
257
+ _f.sent();
210
258
  return [2 /*return*/];
211
259
  }
212
260
  });
@@ -218,7 +266,7 @@ var AccountService = /** @class */ (function () {
218
266
  *
219
267
  * @throws {@link AuthenticationErrors.InvalidPassword}, incorrect password entered.
220
268
  */
221
- AccountService.prototype.enterPassword = function (password) {
269
+ AccountService.prototype.enterPassword = function () {
222
270
  return __awaiter(this, void 0, void 0, function () {
223
271
  var res, _a, _b, _c, _d;
224
272
  var _e;
@@ -232,7 +280,7 @@ var AccountService = /** @class */ (function () {
232
280
  return [4 /*yield*/, this.getGuestCredentials()];
233
281
  case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
234
282
  _e.sslVerifyPeer = false,
235
- _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterPassword.body(this.flowToken, password)),
283
+ _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterPassword.body(this.flowToken, this.password)),
236
284
  _e)]))];
237
285
  case 2:
238
286
  res = _f.sent();
@@ -242,6 +290,11 @@ var AccountService = /** @class */ (function () {
242
290
  }
243
291
  // Getting the flow token
244
292
  this.flowToken = res.data['flow_token'];
293
+ // Executing next subtask
294
+ return [4 /*yield*/, this.accountDuplicationCheck()];
295
+ case 3:
296
+ // Executing next subtask
297
+ _f.sent();
245
298
  return [2 /*return*/];
246
299
  }
247
300
  });
@@ -278,57 +331,6 @@ var AccountService = /** @class */ (function () {
278
331
  });
279
332
  });
280
333
  };
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
334
  /**
333
335
  * Parse the authentication cookies recieved from Twitter into known format.
334
336
  *
@@ -372,11 +374,29 @@ var AccountService = /** @class */ (function () {
372
374
  var parsedCookies;
373
375
  return __generator(this, function (_a) {
374
376
  switch (_a.label) {
375
- case 0:
376
- // Executing all login flows
377
- return [4 /*yield*/, this.executeLoginFlows(email, userName, password)];
377
+ case 0:
378
+ // Setting user credentials
379
+ this.email = email;
380
+ this.userName = userName;
381
+ this.password = password;
382
+ // Initiating login
383
+ /**
384
+ * This works by sending a chain of request that are required for login to twitter.
385
+ * Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
386
+ * Each such method is called a subtask.
387
+ * Each subtask sets the {@link flowToken} property of the class which is used in the payload of the next subtask.
388
+ * The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
389
+ */
390
+ return [4 /*yield*/, this.initiateLogin()];
378
391
  case 1:
379
- // Executing all login flows
392
+ // Initiating login
393
+ /**
394
+ * This works by sending a chain of request that are required for login to twitter.
395
+ * Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
396
+ * Each such method is called a subtask.
397
+ * Each subtask sets the {@link flowToken} property of the class which is used in the payload of the next subtask.
398
+ * The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
399
+ */
380
400
  _a.sent();
381
401
  // Parsing the cookies
382
402
  parsedCookies = this.parseCookies(this.cookies);
@@ -1 +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,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AK,CAAC;YACvB,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC;SACxC,CAAC;IACN,CAAC;IAED;;;;;;;;;;OAUG;IACU,8BAAK,GAAlB,UAAmB,KAAa,EAAE,QAAgB,EAAE,QAAgB;;;;;;wBAIhE,2BAA2B;wBAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;wBACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;wBACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;wBAEzB,mBAAmB;wBACnB;;;;;;2BAMG;wBACH,qBAAM,IAAI,CAAC,aAAa,EAAE,EAAA;;wBAR1B,mBAAmB;wBACnB;;;;;;2BAMG;wBACH,SAA0B,CAAC;wBAE3B,sBAAsB;wBACtB,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBAEhD,qCAAqC;wBACrC,sBAAO,aAAa,EAAC;;;;KACxB;IACL,qBAAC;AAAD,CAAC,AApQD,IAoQC;AApQY,wCAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rettiwt-api",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "An API for fetching data from TwitterAPI, without any rate limits!",
@@ -22,23 +22,25 @@ import { Cookie, CookieJar } from 'cookiejar';
22
22
  */
23
23
  export class AccountService {
24
24
  /** The AuthService instance to use for authentication. */
25
- private auth: AuthService;
26
-
25
+ private auth: AuthService = new AuthService();
26
+
27
27
  /** The current guest credentials to use. */
28
- private guestCreds: IGuestCredentials;
28
+ private guestCreds: IGuestCredentials = { authToken: '', guestToken: '' };
29
+
30
+ /** The email id of Twitter account to be logged into. */
31
+ private email: string = '';
32
+
33
+ /** The user name of the Twitter account ot be logged into */
34
+ private userName: string = '';
35
+
36
+ /** The password to the Twitter account to be logged into. */
37
+ private password: string = '';
29
38
 
30
39
  /** The cookies received from Twitter after logging in. */
31
- private cookies: Cookie[];
40
+ private cookies: Cookie[] = [];
32
41
 
33
42
  /** The flow token received after execution of current flow. */
34
- private flowToken: string;
35
-
36
- constructor() {
37
- this.auth = new AuthService();
38
- this.guestCreds = { authToken: '', guestToken: '' };
39
- this.cookies = [];
40
- this.flowToken = '';
41
- }
43
+ private flowToken: string = '';
42
44
 
43
45
  /**
44
46
  * @returns The current guest credentials to use. If if does not exists, then a new one is created
@@ -69,6 +71,9 @@ export class AccountService {
69
71
 
70
72
  // Getting the flow token
71
73
  this.flowToken = res.data['flow_token'];
74
+
75
+ // Executing next subtask
76
+ await this.jsInstrumentationSubtask();
72
77
  }
73
78
 
74
79
  /**
@@ -76,7 +81,7 @@ export class AccountService {
76
81
  * @internal
77
82
  */
78
83
  private async jsInstrumentationSubtask(): Promise<void> {
79
- // Executing the flow
84
+ // Executing the subtask
80
85
  const res: CurlyResult = await curly.post(LoginFlows.JsInstrumentationSubtask.url, {
81
86
  httpHeader: loginHeader(await this.getGuestCredentials(), this.cookies.join(';').toString()),
82
87
  sslVerifyPeer: false,
@@ -85,6 +90,9 @@ export class AccountService {
85
90
 
86
91
  // Getting the flow token
87
92
  this.flowToken = res.data['flow_token'];
93
+
94
+ // Executing next subtask
95
+ await this.enterUserIdentifier();
88
96
  }
89
97
 
90
98
  /**
@@ -93,12 +101,12 @@ export class AccountService {
93
101
  *
94
102
  * @throws {@link AuthenticationErrors.InvalidEmail}, if email does not exist.
95
103
  */
96
- private async enterUserIdentifier(email: string): Promise<void> {
97
- // Executing the flow
104
+ private async enterUserIdentifier(): Promise<void> {
105
+ // Executing the subtask
98
106
  const res: CurlyResult = await curly.post(LoginFlows.EnterUserIdentifier.url, {
99
107
  httpHeader: loginHeader(await this.getGuestCredentials(), this.cookies.join(';').toString()),
100
108
  sslVerifyPeer: false,
101
- postFields: JSON.stringify(LoginFlows.EnterUserIdentifier.body(this.flowToken, email))
109
+ postFields: JSON.stringify(LoginFlows.EnterUserIdentifier.body(this.flowToken, this.email))
102
110
  });
103
111
 
104
112
  // If no account found with given email
@@ -108,6 +116,31 @@ export class AccountService {
108
116
 
109
117
  // Getting the flow token
110
118
  this.flowToken = res.data['flow_token'];
119
+
120
+ // Checking the next available subtasks
121
+ /**
122
+ * This subtask has two possible outcomes.
123
+ * 1. The server asks for a username next.
124
+ * 2. The server directly asks for password, skipping username check.
125
+ *
126
+ * So, checking which is the subtask required by server, and executing that particular subtask.
127
+ */
128
+ for (let task of res.data.subtasks) {
129
+ // If next subtask is to enter username
130
+ if (task['subtask_id'] == 'LoginEnterAlternateIdentifierSubtask') {
131
+ // Executing next subtask
132
+ await this.enterAlternateUserIdentifier();
133
+
134
+ break;
135
+ }
136
+ // If next subtask is to enter password
137
+ else if (task['subtask_id'] == 'LoginEnterPassword') {
138
+ // Executing next subtask
139
+ await this.enterPassword();
140
+
141
+ break;
142
+ }
143
+ }
111
144
  }
112
145
 
113
146
  /**
@@ -116,12 +149,12 @@ export class AccountService {
116
149
  *
117
150
  * @throws {@link AuthenticationErrors.InvalidUsername}, if wrong username entered.
118
151
  */
119
- private async enterAlternateUserIdentifier(userName: string): Promise<void> {
120
- // Executing the flow
152
+ private async enterAlternateUserIdentifier(): Promise<void> {
153
+ // Executing the subtask
121
154
  const res: CurlyResult = await curly.post(LoginFlows.EnterAlternateUserIdentifier.url, {
122
155
  httpHeader: loginHeader(await this.getGuestCredentials(), this.cookies.join(';').toString()),
123
156
  sslVerifyPeer: false,
124
- postFields: JSON.stringify(LoginFlows.EnterAlternateUserIdentifier.body(this.flowToken, userName))
157
+ postFields: JSON.stringify(LoginFlows.EnterAlternateUserIdentifier.body(this.flowToken, this.userName))
125
158
  });
126
159
 
127
160
  // If invalid username for the given account
@@ -131,6 +164,9 @@ export class AccountService {
131
164
 
132
165
  // Getting the flow token
133
166
  this.flowToken = res.data['flow_token'];
167
+
168
+ // Executing next subtask
169
+ await this.enterPassword();
134
170
  }
135
171
 
136
172
  /**
@@ -139,12 +175,12 @@ export class AccountService {
139
175
  *
140
176
  * @throws {@link AuthenticationErrors.InvalidPassword}, incorrect password entered.
141
177
  */
142
- private async enterPassword(password: string): Promise<void> {
143
- // Executing the flow
178
+ private async enterPassword(): Promise<void> {
179
+ // Executing the subtask
144
180
  const res: CurlyResult = await curly.post(LoginFlows.EnterPassword.url, {
145
181
  httpHeader: loginHeader(await this.getGuestCredentials(), this.cookies.join(';').toString()),
146
182
  sslVerifyPeer: false,
147
- postFields: JSON.stringify(LoginFlows.EnterPassword.body(this.flowToken, password))
183
+ postFields: JSON.stringify(LoginFlows.EnterPassword.body(this.flowToken, this.password))
148
184
  });
149
185
 
150
186
  // If invalid password for the given account
@@ -154,6 +190,9 @@ export class AccountService {
154
190
 
155
191
  // Getting the flow token
156
192
  this.flowToken = res.data['flow_token'];
193
+
194
+ // Executing next subtask
195
+ await this.accountDuplicationCheck();
157
196
  }
158
197
 
159
198
  /**
@@ -161,7 +200,7 @@ export class AccountService {
161
200
  * @internal
162
201
  */
163
202
  private async accountDuplicationCheck(): Promise<void> {
164
- // Executing the flow
203
+ // Executing the subtask
165
204
  const res: CurlyResult = await curly.post(LoginFlows.AccountDuplicationCheck.url, {
166
205
  httpHeader: loginHeader(await this.getGuestCredentials(), this.cookies.join(';').toString()),
167
206
  sslVerifyPeer: false,
@@ -175,31 +214,6 @@ export class AccountService {
175
214
  this.flowToken = res.data['flow_token'];
176
215
  }
177
216
 
178
- /**
179
- * Execute all the flows required to login to Twitter, using the given credentials, then set the response cookies.
180
- *
181
- * @internal
182
- *
183
- * @param email The email of the account to be logged into.
184
- * @param userName The username associated with the given account.
185
- * @param password The password to the account.
186
- */
187
- private async executeLoginFlows(email: string, userName: string, password: string): Promise<void> {
188
- /**
189
- * This works by sending a chain of request that are required for login to twitter.
190
- * Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
191
- * Each such method is called a subtask.
192
- * Each subtask sets the {@link flowToken} property of the class which is then given in the payload of the next subtask.
193
- * The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
194
- */
195
- await this.initiateLogin();
196
- await this.jsInstrumentationSubtask();
197
- await this.enterUserIdentifier(email);
198
- await this.enterAlternateUserIdentifier(userName);
199
- await this.enterPassword(password);
200
- await this.accountDuplicationCheck();
201
- }
202
-
203
217
  /**
204
218
  * Parse the authentication cookies recieved from Twitter into known format.
205
219
  *
@@ -212,7 +226,7 @@ export class AccountService {
212
226
  private parseCookies(cookies: Cookie[]): IAuthCookie {
213
227
  /** The tempoorary parsed cookies. */
214
228
  let tempCookies: any = {};
215
-
229
+
216
230
  /**
217
231
  * Parsing the cookies into a standard JSON format.
218
232
  * The format is 'cookie_name': 'cookie_value'.
@@ -244,13 +258,25 @@ export class AccountService {
244
258
  public async login(email: string, userName: string, password: string): Promise<IAuthCookie> {
245
259
  /** The parsed cookies that will be returned. */
246
260
  let parsedCookies: IAuthCookie;
247
-
248
- // Executing all login flows
249
- await this.executeLoginFlows(email, userName, password);
261
+
262
+ // Setting user credentials
263
+ this.email = email;
264
+ this.userName = userName;
265
+ this.password = password;
266
+
267
+ // Initiating login
268
+ /**
269
+ * This works by sending a chain of request that are required for login to twitter.
270
+ * Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
271
+ * Each such method is called a subtask.
272
+ * Each subtask sets the {@link flowToken} property of the class which is used in the payload of the next subtask.
273
+ * The final subtask returns the headers which actually contains the cookie in the 'set-cookie' field.
274
+ */
275
+ await this.initiateLogin();
250
276
 
251
277
  // Parsing the cookies
252
278
  parsedCookies = this.parseCookies(this.cookies);
253
-
279
+
254
280
  // Returning the final parsed cookies
255
281
  return parsedCookies;
256
282
  }