rettiwt-api 1.4.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +54 -0
  3. package/.github/workflows/documentation.yml +29 -9
  4. package/.github/workflows/publish.yml +8 -3
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +13 -0
  7. package/README.md +59 -61
  8. package/dist/Rettiwt.d.ts +19 -0
  9. package/dist/Rettiwt.js +30 -0
  10. package/dist/Rettiwt.js.map +1 -0
  11. package/dist/enums/ApiErrors.d.ts +30 -0
  12. package/dist/enums/ApiErrors.js +35 -0
  13. package/dist/enums/ApiErrors.js.map +1 -0
  14. package/dist/enums/HTTP.d.ts +11 -11
  15. package/dist/enums/HTTP.js +15 -16
  16. package/dist/enums/HTTP.js.map +1 -1
  17. package/dist/helper/JsonUtils.d.ts +26 -0
  18. package/dist/helper/JsonUtils.js +88 -0
  19. package/dist/helper/JsonUtils.js.map +1 -0
  20. package/dist/index.d.ts +10 -43
  21. package/dist/index.js +16 -55
  22. package/dist/index.js.map +1 -1
  23. package/dist/models/CursoredData.d.ts +37 -0
  24. package/dist/models/CursoredData.js +59 -0
  25. package/dist/models/CursoredData.js.map +1 -0
  26. package/dist/models/{data/Tweet.d.ts → Tweet.d.ts} +4 -4
  27. package/dist/models/{data/Tweet.js → Tweet.js} +7 -32
  28. package/dist/models/Tweet.js.map +1 -0
  29. package/dist/models/{data/User.d.ts → User.d.ts} +3 -3
  30. package/dist/models/{data/User.js → User.js} +3 -3
  31. package/dist/models/User.js.map +1 -0
  32. package/dist/services/FetcherService.d.ts +66 -0
  33. package/dist/services/FetcherService.js +209 -0
  34. package/dist/services/FetcherService.js.map +1 -0
  35. package/dist/services/TweetService.d.ts +88 -0
  36. package/dist/services/TweetService.js +244 -0
  37. package/dist/services/TweetService.js.map +1 -0
  38. package/dist/services/UserService.d.ts +60 -0
  39. package/dist/services/UserService.js +188 -0
  40. package/dist/services/UserService.js.map +1 -0
  41. package/dist/types/{Service.d.ts → CursoredData.d.ts} +3 -3
  42. package/dist/types/CursoredData.js +3 -0
  43. package/dist/types/CursoredData.js.map +1 -0
  44. package/dist/types/Tweet.js +1 -1
  45. package/dist/types/User.js +1 -1
  46. package/package.json +15 -19
  47. package/src/Rettiwt.ts +33 -0
  48. package/src/enums/ApiErrors.ts +30 -0
  49. package/src/enums/HTTP.ts +12 -12
  50. package/src/helper/JsonUtils.ts +86 -0
  51. package/src/index.ts +14 -57
  52. package/src/models/CursoredData.ts +64 -0
  53. package/src/models/Tweet.ts +116 -0
  54. package/src/models/User.ts +72 -0
  55. package/src/services/FetcherService.ts +186 -0
  56. package/src/services/TweetService.ts +153 -0
  57. package/src/services/UserService.ts +117 -0
  58. package/src/types/CursoredData.ts +24 -0
  59. package/src/types/Tweet.ts +35 -35
  60. package/src/types/User.ts +30 -30
  61. package/tsconfig.json +9 -9
  62. package/dist/config/env.d.ts +0 -5
  63. package/dist/config/env.js +0 -9
  64. package/dist/config/env.js.map +0 -1
  65. package/dist/enums/Errors.d.ts +0 -21
  66. package/dist/enums/Errors.js +0 -29
  67. package/dist/enums/Errors.js.map +0 -1
  68. package/dist/graphql/enums/Errors.d.ts +0 -21
  69. package/dist/graphql/enums/Errors.js +0 -29
  70. package/dist/graphql/enums/Errors.js.map +0 -1
  71. package/dist/graphql/queries/RootQuery.d.ts +0 -4
  72. package/dist/graphql/queries/RootQuery.js +0 -83
  73. package/dist/graphql/queries/RootQuery.js.map +0 -1
  74. package/dist/graphql/resolvers/AccountResolver.d.ts +0 -12
  75. package/dist/graphql/resolvers/AccountResolver.js +0 -84
  76. package/dist/graphql/resolvers/AccountResolver.js.map +0 -1
  77. package/dist/graphql/resolvers/ResolverBase.d.ts +0 -16
  78. package/dist/graphql/resolvers/ResolverBase.js +0 -23
  79. package/dist/graphql/resolvers/ResolverBase.js.map +0 -1
  80. package/dist/graphql/resolvers/TweetResolver.d.ts +0 -46
  81. package/dist/graphql/resolvers/TweetResolver.js +0 -302
  82. package/dist/graphql/resolvers/TweetResolver.js.map +0 -1
  83. package/dist/graphql/resolvers/UserResolver.d.ts +0 -48
  84. package/dist/graphql/resolvers/UserResolver.js +0 -334
  85. package/dist/graphql/resolvers/UserResolver.js.map +0 -1
  86. package/dist/graphql/types/Global.d.ts +0 -4
  87. package/dist/graphql/types/Global.js +0 -13
  88. package/dist/graphql/types/Global.js.map +0 -1
  89. package/dist/graphql/types/TweetTypes.d.ts +0 -4
  90. package/dist/graphql/types/TweetTypes.js +0 -160
  91. package/dist/graphql/types/TweetTypes.js.map +0 -1
  92. package/dist/graphql/types/UserTypes.d.ts +0 -3
  93. package/dist/graphql/types/UserTypes.js +0 -137
  94. package/dist/graphql/types/UserTypes.js.map +0 -1
  95. package/dist/models/args/TweetListArgs.d.ts +0 -21
  96. package/dist/models/args/TweetListArgs.js +0 -54
  97. package/dist/models/args/TweetListArgs.js.map +0 -1
  98. package/dist/models/args/UserListArgs.d.ts +0 -21
  99. package/dist/models/args/UserListArgs.js +0 -54
  100. package/dist/models/args/UserListArgs.js.map +0 -1
  101. package/dist/models/auth/AuthCookie.d.ts +0 -21
  102. package/dist/models/auth/AuthCookie.js +0 -33
  103. package/dist/models/auth/AuthCookie.js.map +0 -1
  104. package/dist/models/data/CursoredData.d.ts +0 -34
  105. package/dist/models/data/CursoredData.js +0 -42
  106. package/dist/models/data/CursoredData.js.map +0 -1
  107. package/dist/models/data/Tweet.js.map +0 -1
  108. package/dist/models/data/User.js.map +0 -1
  109. package/dist/server.d.ts +0 -1
  110. package/dist/server.js +0 -76
  111. package/dist/server.js.map +0 -1
  112. package/dist/services/auth/AccountService.d.ts +0 -83
  113. package/dist/services/auth/AccountService.js +0 -412
  114. package/dist/services/auth/AccountService.js.map +0 -1
  115. package/dist/services/auth/AuthService.d.ts +0 -31
  116. package/dist/services/auth/AuthService.js +0 -118
  117. package/dist/services/auth/AuthService.js.map +0 -1
  118. package/dist/services/data/TweetService.d.ts +0 -60
  119. package/dist/services/data/TweetService.js +0 -250
  120. package/dist/services/data/TweetService.js.map +0 -1
  121. package/dist/services/data/UserService.d.ts +0 -71
  122. package/dist/services/data/UserService.js +0 -278
  123. package/dist/services/data/UserService.js.map +0 -1
  124. package/dist/services/helper/Headers.d.ts +0 -19
  125. package/dist/services/helper/Headers.js +0 -62
  126. package/dist/services/helper/Headers.js.map +0 -1
  127. package/dist/services/helper/Parser.d.ts +0 -22
  128. package/dist/services/helper/Parser.js +0 -84
  129. package/dist/services/helper/Parser.js.map +0 -1
  130. package/dist/services/helper/extractors/Tweets.d.ts +0 -23
  131. package/dist/services/helper/extractors/Tweets.js +0 -200
  132. package/dist/services/helper/extractors/Tweets.js.map +0 -1
  133. package/dist/services/helper/extractors/Users.d.ts +0 -17
  134. package/dist/services/helper/extractors/Users.js +0 -151
  135. package/dist/services/helper/extractors/Users.js.map +0 -1
  136. package/dist/services/helper/payloads/LoginFlows.d.ts +0 -77
  137. package/dist/services/helper/payloads/LoginFlows.js +0 -92
  138. package/dist/services/helper/payloads/LoginFlows.js.map +0 -1
  139. package/dist/services/helper/urls/Authentication.d.ts +0 -4
  140. package/dist/services/helper/urls/Authentication.js +0 -11
  141. package/dist/services/helper/urls/Authentication.js.map +0 -1
  142. package/dist/services/util/CacheService.d.ts +0 -33
  143. package/dist/services/util/CacheService.js +0 -96
  144. package/dist/services/util/CacheService.js.map +0 -1
  145. package/dist/services/util/FetcherService.d.ts +0 -65
  146. package/dist/services/util/FetcherService.js +0 -202
  147. package/dist/services/util/FetcherService.js.map +0 -1
  148. package/dist/types/Args.d.ts +0 -11
  149. package/dist/types/Args.js +0 -4
  150. package/dist/types/Args.js.map +0 -1
  151. package/dist/types/Authentication.d.ts +0 -55
  152. package/dist/types/Authentication.js +0 -6
  153. package/dist/types/Authentication.js.map +0 -1
  154. package/dist/types/Resolvers.d.ts +0 -15
  155. package/dist/types/Resolvers.js +0 -3
  156. package/dist/types/Resolvers.js.map +0 -1
  157. package/dist/types/Rettiwt.d.ts +0 -16
  158. package/dist/types/Rettiwt.js +0 -3
  159. package/dist/types/Rettiwt.js.map +0 -1
  160. package/dist/types/Service.js +0 -5
  161. package/dist/types/Service.js.map +0 -1
  162. package/docs/.nojekyll +0 -1
  163. package/docs/assets/highlight.css +0 -64
  164. package/docs/assets/main.js +0 -58
  165. package/docs/assets/search.js +0 -1
  166. package/docs/assets/style.css +0 -1280
  167. package/docs/classes/AccountService.html +0 -286
  168. package/docs/classes/AuthCookie.html +0 -146
  169. package/docs/classes/AuthService.html +0 -147
  170. package/docs/classes/CacheService.html +0 -157
  171. package/docs/classes/Cursor.html +0 -102
  172. package/docs/classes/CursoredData.html +0 -126
  173. package/docs/classes/DataValidationError.html +0 -120
  174. package/docs/classes/FetcherService.html +0 -225
  175. package/docs/classes/Tweet.html +0 -210
  176. package/docs/classes/TweetEntities.html +0 -128
  177. package/docs/classes/TweetFilter.html +0 -233
  178. package/docs/classes/TweetListArgs.html +0 -118
  179. package/docs/classes/TweetService.html +0 -319
  180. package/docs/classes/User.html +0 -230
  181. package/docs/classes/UserListArgs.html +0 -118
  182. package/docs/classes/UserService.html +0 -355
  183. package/docs/enums/HttpMethods.html +0 -74
  184. package/docs/functions/Rettiwt.html +0 -100
  185. package/docs/index.html +0 -159
  186. package/docs/interfaces/IAuthCookie.html +0 -104
  187. package/docs/interfaces/ICursor.html +0 -77
  188. package/docs/interfaces/ICursoredData.html +0 -93
  189. package/docs/interfaces/IDataContext.html +0 -91
  190. package/docs/interfaces/IDataValidationError.html +0 -109
  191. package/docs/interfaces/IListArgs.html +0 -87
  192. package/docs/interfaces/ITweet.html +0 -176
  193. package/docs/interfaces/ITweetEntities.html +0 -104
  194. package/docs/interfaces/ITweetFilter.html +0 -158
  195. package/docs/interfaces/IUser.html +0 -194
  196. package/docs/modules.html +0 -111
  197. package/environment.d.ts +0 -11
  198. package/src/config/env.ts +0 -5
  199. package/src/enums/Errors.ts +0 -22
  200. package/src/graphql/enums/Errors.ts +0 -22
  201. package/src/graphql/queries/RootQuery.ts +0 -81
  202. package/src/graphql/resolvers/AccountResolver.ts +0 -22
  203. package/src/graphql/resolvers/ResolverBase.ts +0 -26
  204. package/src/graphql/resolvers/TweetResolver.ts +0 -225
  205. package/src/graphql/resolvers/UserResolver.ts +0 -257
  206. package/src/graphql/types/Global.ts +0 -10
  207. package/src/graphql/types/TweetTypes.ts +0 -158
  208. package/src/graphql/types/UserTypes.ts +0 -134
  209. package/src/models/args/TweetListArgs.ts +0 -47
  210. package/src/models/args/UserListArgs.ts +0 -47
  211. package/src/models/auth/AuthCookie.ts +0 -43
  212. package/src/models/data/CursoredData.ts +0 -45
  213. package/src/models/data/Tweet.ts +0 -118
  214. package/src/models/data/User.ts +0 -72
  215. package/src/server.ts +0 -37
  216. package/src/services/auth/AccountService.ts +0 -283
  217. package/src/services/auth/AuthService.ts +0 -81
  218. package/src/services/data/TweetService.ts +0 -197
  219. package/src/services/data/UserService.ts +0 -221
  220. package/src/services/helper/Headers.ts +0 -60
  221. package/src/services/helper/Parser.ts +0 -89
  222. package/src/services/helper/extractors/Tweets.ts +0 -190
  223. package/src/services/helper/extractors/Users.ts +0 -141
  224. package/src/services/helper/payloads/LoginFlows.ts +0 -90
  225. package/src/services/helper/urls/Authentication.ts +0 -6
  226. package/src/services/util/CacheService.ts +0 -76
  227. package/src/services/util/FetcherService.ts +0 -143
  228. package/src/types/Args.ts +0 -12
  229. package/src/types/Authentication.ts +0 -63
  230. package/src/types/Resolvers.ts +0 -18
  231. package/src/types/Rettiwt.ts +0 -20
  232. package/src/types/Service.ts +0 -24
@@ -1,412 +0,0 @@
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
- /** The AuthService instance to use for authentication. */
61
- this.auth = new AuthService_1.AuthService();
62
- /** The current guest credentials to use. */
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. */
71
- this.cookies = [];
72
- /** The flow token received after execution of current flow. */
73
- this.flowToken = '';
74
- }
75
- /**
76
- * @returns The current guest credentials to use. If if does not exists, then a new one is created
77
- */
78
- AccountService.prototype.getGuestCredentials = function () {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var _a;
81
- return __generator(this, function (_b) {
82
- switch (_b.label) {
83
- case 0:
84
- if (!!this.guestCreds.guestToken) return [3 /*break*/, 2];
85
- _a = this;
86
- return [4 /*yield*/, this.auth.getGuestCredentials()];
87
- case 1:
88
- _a.guestCreds = _b.sent();
89
- _b.label = 2;
90
- case 2: return [2 /*return*/, this.guestCreds];
91
- }
92
- });
93
- });
94
- };
95
- /**
96
- * Step 1: Initiates login
97
- * @internal
98
- */
99
- AccountService.prototype.initiateLogin = function () {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var res, _a, _b, _c, _d;
102
- var _e;
103
- return __generator(this, function (_f) {
104
- switch (_f.label) {
105
- case 0:
106
- _b = (_a = node_libcurl_1.curly).post;
107
- _c = [LoginFlows_1["default"].InitiateLogin.url];
108
- _e = {};
109
- _d = Headers_1.loginHeader;
110
- return [4 /*yield*/, this.getGuestCredentials()];
111
- case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.toString()]),
112
- _e.sslVerifyPeer = false,
113
- _e.postFields = '',
114
- _e)]))];
115
- case 2:
116
- res = _f.sent();
117
- // Storing cookies received
118
- this.cookies = new cookiejar_1.CookieJar().setCookies(res.headers[0]['Set-Cookie']);
119
- // Getting the flow token
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();
126
- return [2 /*return*/];
127
- }
128
- });
129
- });
130
- };
131
- /**
132
- * Step 2: Does something
133
- * @internal
134
- */
135
- AccountService.prototype.jsInstrumentationSubtask = function () {
136
- return __awaiter(this, void 0, void 0, function () {
137
- var res, _a, _b, _c, _d;
138
- var _e;
139
- return __generator(this, function (_f) {
140
- switch (_f.label) {
141
- case 0:
142
- _b = (_a = node_libcurl_1.curly).post;
143
- _c = [LoginFlows_1["default"].JsInstrumentationSubtask.url];
144
- _e = {};
145
- _d = Headers_1.loginHeader;
146
- return [4 /*yield*/, this.getGuestCredentials()];
147
- case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
148
- _e.sslVerifyPeer = false,
149
- _e.postFields = JSON.stringify(LoginFlows_1["default"].JsInstrumentationSubtask.body(this.flowToken)),
150
- _e)]))];
151
- case 2:
152
- res = _f.sent();
153
- // Getting the flow token
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();
160
- return [2 /*return*/];
161
- }
162
- });
163
- });
164
- };
165
- /**
166
- * Step 3: Takes the email for login
167
- * @internal
168
- *
169
- * @throws {@link AuthenticationErrors.InvalidEmail}, if email does not exist.
170
- */
171
- AccountService.prototype.enterUserIdentifier = function () {
172
- return __awaiter(this, void 0, void 0, function () {
173
- var res, _a, _b, _c, _d, _i, _e, task;
174
- var _f;
175
- return __generator(this, function (_g) {
176
- switch (_g.label) {
177
- case 0:
178
- _b = (_a = node_libcurl_1.curly).post;
179
- _c = [LoginFlows_1["default"].EnterUserIdentifier.url];
180
- _f = {};
181
- _d = Headers_1.loginHeader;
182
- return [4 /*yield*/, this.getGuestCredentials()];
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)]))];
187
- case 2:
188
- res = _g.sent();
189
- // If no account found with given email
190
- if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
191
- throw new Error(Errors_1.AuthenticationErrors.InvalidEmail);
192
- }
193
- // Getting the flow token
194
- this.flowToken = res.data['flow_token'];
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*/];
219
- }
220
- });
221
- });
222
- };
223
- /**
224
- * Step 4: Takes the username for login
225
- * @internal
226
- *
227
- * @throws {@link AuthenticationErrors.InvalidUsername}, if wrong username entered.
228
- */
229
- AccountService.prototype.enterAlternateUserIdentifier = function () {
230
- return __awaiter(this, void 0, void 0, function () {
231
- var res, _a, _b, _c, _d;
232
- var _e;
233
- return __generator(this, function (_f) {
234
- switch (_f.label) {
235
- case 0:
236
- _b = (_a = node_libcurl_1.curly).post;
237
- _c = [LoginFlows_1["default"].EnterAlternateUserIdentifier.url];
238
- _e = {};
239
- _d = Headers_1.loginHeader;
240
- return [4 /*yield*/, this.getGuestCredentials()];
241
- case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
242
- _e.sslVerifyPeer = false,
243
- _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterAlternateUserIdentifier.body(this.flowToken, this.userName)),
244
- _e)]))];
245
- case 2:
246
- res = _f.sent();
247
- // If invalid username for the given account
248
- if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
249
- throw new Error(Errors_1.AuthenticationErrors.InvalidUsername);
250
- }
251
- // Getting the flow token
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();
258
- return [2 /*return*/];
259
- }
260
- });
261
- });
262
- };
263
- /**
264
- * Step 5: Takes the password for login
265
- * @internal
266
- *
267
- * @throws {@link AuthenticationErrors.InvalidPassword}, incorrect password entered.
268
- */
269
- AccountService.prototype.enterPassword = function () {
270
- return __awaiter(this, void 0, void 0, function () {
271
- var res, _a, _b, _c, _d;
272
- var _e;
273
- return __generator(this, function (_f) {
274
- switch (_f.label) {
275
- case 0:
276
- _b = (_a = node_libcurl_1.curly).post;
277
- _c = [LoginFlows_1["default"].EnterPassword.url];
278
- _e = {};
279
- _d = Headers_1.loginHeader;
280
- return [4 /*yield*/, this.getGuestCredentials()];
281
- case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
282
- _e.sslVerifyPeer = false,
283
- _e.postFields = JSON.stringify(LoginFlows_1["default"].EnterPassword.body(this.flowToken, this.password)),
284
- _e)]))];
285
- case 2:
286
- res = _f.sent();
287
- // If invalid password for the given account
288
- if (res.statusCode == HTTP_1.HttpStatus.BadRequest && res.data.errors[0].code == 399) {
289
- throw new Error(Errors_1.AuthenticationErrors.InvalidPassword);
290
- }
291
- // Getting the flow token
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();
298
- return [2 /*return*/];
299
- }
300
- });
301
- });
302
- };
303
- /**
304
- * Step 6: Gets the actual cookies
305
- * @internal
306
- */
307
- AccountService.prototype.accountDuplicationCheck = function () {
308
- return __awaiter(this, void 0, void 0, function () {
309
- var res, _a, _b, _c, _d;
310
- var _e;
311
- return __generator(this, function (_f) {
312
- switch (_f.label) {
313
- case 0:
314
- _b = (_a = node_libcurl_1.curly).post;
315
- _c = [LoginFlows_1["default"].AccountDuplicationCheck.url];
316
- _e = {};
317
- _d = Headers_1.loginHeader;
318
- return [4 /*yield*/, this.getGuestCredentials()];
319
- case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_e.httpHeader = _d.apply(void 0, [_f.sent(), this.cookies.join(';').toString()]),
320
- _e.sslVerifyPeer = false,
321
- _e.postFields = JSON.stringify(LoginFlows_1["default"].AccountDuplicationCheck.body(this.flowToken)),
322
- _e)]))];
323
- case 2:
324
- res = _f.sent();
325
- // Getting the cookies from the set-cookie header of the reponse.
326
- this.cookies = new cookiejar_1.CookieJar().setCookies(res.headers[0]['Set-Cookie']);
327
- // Getting the flow token
328
- this.flowToken = res.data['flow_token'];
329
- return [2 /*return*/];
330
- }
331
- });
332
- });
333
- };
334
- /**
335
- * Parse the authentication cookies recieved from Twitter into known format.
336
- *
337
- * @internal
338
- *
339
- * @param cookies The raw cookies received from Twitter.
340
- *
341
- * @returns The parsed cookies of type {@link AuthCookie}
342
- */
343
- AccountService.prototype.parseCookies = function (cookies) {
344
- /** The tempoorary parsed cookies. */
345
- var tempCookies = {};
346
- /**
347
- * Parsing the cookies into a standard JSON format.
348
- * The format is 'cookie_name': 'cookie_value'.
349
- * All other cookie parameters like expiry, etc are dropped.
350
- */
351
- cookies.forEach(function (cookie) {
352
- tempCookies[cookie.name] = cookie.value;
353
- });
354
- return {
355
- kdt: tempCookies['kdt'],
356
- twid: tempCookies['twid'],
357
- ct0: tempCookies['ct0'],
358
- auth_token: tempCookies['auth_token']
359
- };
360
- };
361
- /**
362
- * Login to Twitter using the given credentials and get back the cookies.
363
- *
364
- * @public
365
- *
366
- * @param email The email of the account to be logged into.
367
- * @param userName The username associated with the given account.
368
- * @param password The password to the account.
369
- *
370
- * @returns The cookies for authenticating with the given account.
371
- */
372
- AccountService.prototype.login = function (email, userName, password) {
373
- return __awaiter(this, void 0, void 0, function () {
374
- var parsedCookies;
375
- return __generator(this, function (_a) {
376
- switch (_a.label) {
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()];
391
- case 1:
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
- */
400
- _a.sent();
401
- // Parsing the cookies
402
- parsedCookies = this.parseCookies(this.cookies);
403
- // Returning the final parsed cookies
404
- return [2 /*return*/, parsedCookies];
405
- }
406
- });
407
- });
408
- };
409
- return AccountService;
410
- }());
411
- exports.AccountService = AccountService;
412
- //# sourceMappingURL=AccountService.js.map
@@ -1 +0,0 @@
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;IAAA;QACI,0DAA0D;QAClD,SAAI,GAAgB,IAAI,yBAAW,EAAE,CAAC;QAE9C,4CAA4C;QACpC,eAAU,GAAsB,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;QAE1E,yDAAyD;QACjD,UAAK,GAAW,EAAE,CAAC;QAE3B,6DAA6D;QACrD,aAAQ,GAAW,EAAE,CAAC;QAE9B,6DAA6D;QACrD,aAAQ,GAAW,EAAE,CAAC;QAE9B,0DAA0D;QAClD,YAAO,GAAa,EAAE,CAAC;QAE/B,+DAA+D;QACvD,cAAS,GAAW,EAAE,CAAC;IAgPnC,CAAC;IA9OG;;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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,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"}
@@ -1,31 +0,0 @@
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
- }
@@ -1,118 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/auth/AuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,UAAU;AACV,gDAA0B;AAE1B,OAAO;AACP,gEAA8D;AAE9D,SAAS;AACT,2DAA0D;AAK1D,UAAU;AACV,wCAA0C;AAE1C;;;;GAIG;AACH;IAUI;;;;;;OAMG;IACH,qBAAY,MAAmB;QAC3B,qEAAqE;QACrE,IAAI,CAAC,SAAS,GAAG,YAAM,CAAC,kBAAkB,CAAC;QAE3C,gCAAgC;QAChC,IAAI,CAAC,eAAe,GAAG,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,MAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAA,KAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAA,KAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAA,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAEzG,mEAAmE;QACnE,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,4CAA4C;YAC5C,MAAM,GAAG,IAAI,uBAAU,CAAC,MAAM,CAAC,CAAC;YAEhC,2CAA2C;YAC3C,IAAI,CAAC,WAAW,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;SACtG;QACD,iEAAiE;aAC5D;YACD,2CAA2C;YAC3C,IAAI,CAAC,WAAW,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;SAC/E;IACL,CAAC;IAED;;OAEG;IACG,wCAAkB,GAAxB;;;gBACI,sBAAO,IAAI,CAAC,WAAW,EAAC;;;KAC3B;IAED;;OAEG;IACG,yCAAmB,GAAzB;;;;;4BAEW,qBAAM,kBAAK,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"}
@@ -1,60 +0,0 @@
1
- import { TweetFilter } from 'rettiwt-core';
2
- import { FetcherService } from "../util/FetcherService";
3
- import { AuthService } from "../auth/AuthService";
4
- import { Tweet } from "../../models/data/Tweet";
5
- import { User } from "../../models/data/User";
6
- import { CursoredData } from '../../models/data/CursoredData';
7
- /**
8
- * Handles fetching of data related to tweets.
9
- * @public
10
- */
11
- export declare class TweetService extends FetcherService {
12
- /**
13
- * @param auth The AuthService instance to use for authentication.
14
- */
15
- constructor(auth: AuthService);
16
- /**
17
- * @param filter The filter be used for searching the tweets.
18
- * @param count The number of tweets to fetch, must be >= 10 (when no cursor is provided) and <= 20
19
- * @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched.
20
- *
21
- * @returns The list of tweets that match the given filter.
22
- *
23
- * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
24
- * @throws {@link Errors.ValidationErrors.InvalidCount} error, if an invalid count has been provided.
25
- */
26
- getTweets(query: TweetFilter, count?: number, cursor?: string): Promise<CursoredData<Tweet>>;
27
- /**
28
- * @param id The id of the target tweet.
29
- *
30
- * @returns The details of a single tweet with the given tweet id.
31
- *
32
- * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
33
- * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
34
- */
35
- getTweetDetails(id: string): Promise<Tweet>;
36
- /**
37
- * @param tweetId The rest id of the target tweet.
38
- * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 20.
39
- * @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
40
- *
41
- * @returns The list of users who liked the given tweet.
42
- *
43
- * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
44
- * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
45
- * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
46
- */
47
- getTweetLikers(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>>;
48
- /**
49
- * @param tweetId The rest id of the target tweet.
50
- * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100.
51
- * @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
52
- *
53
- * @returns The list of users who retweeted the given tweet.
54
- *
55
- * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
56
- * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
57
- * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
58
- */
59
- getTweetRetweeters(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>>;
60
- }