rettiwt-api 1.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.
- package/.dockerignore +2 -0
- package/.gitattributes +3 -0
- package/Dockerfile +9 -0
- package/README.md +38 -0
- package/dist/config/env.d.ts +5 -0
- package/dist/config/env.js +9 -0
- package/dist/config/env.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/models/graphql/Global.d.ts +4 -0
- package/dist/models/graphql/Global.js +13 -0
- package/dist/models/graphql/Global.js.map +1 -0
- package/dist/models/graphql/TweetTypes.d.ts +6 -0
- package/dist/models/graphql/TweetTypes.js +156 -0
- package/dist/models/graphql/TweetTypes.js.map +1 -0
- package/dist/models/graphql/UserTypes.d.ts +3 -0
- package/dist/models/graphql/UserTypes.js +139 -0
- package/dist/models/graphql/UserTypes.js.map +1 -0
- package/dist/queries/RootQuery.d.ts +4 -0
- package/dist/queries/RootQuery.js +59 -0
- package/dist/queries/RootQuery.js.map +1 -0
- package/dist/resolvers/ResolverBase.d.ts +5 -0
- package/dist/resolvers/ResolverBase.js +11 -0
- package/dist/resolvers/ResolverBase.js.map +1 -0
- package/dist/resolvers/TweetResolver.d.ts +54 -0
- package/dist/resolvers/TweetResolver.js +328 -0
- package/dist/resolvers/TweetResolver.js.map +1 -0
- package/dist/resolvers/UserResolver.d.ts +47 -0
- package/dist/resolvers/UserResolver.js +302 -0
- package/dist/resolvers/UserResolver.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +75 -0
- package/dist/server.js.map +1 -0
- package/dist/services/AuthService.d.ts +17 -0
- package/dist/services/AuthService.js +103 -0
- package/dist/services/AuthService.js.map +1 -0
- package/dist/services/CacheService.d.ts +25 -0
- package/dist/services/CacheService.js +141 -0
- package/dist/services/CacheService.js.map +1 -0
- package/dist/services/FetcherService.d.ts +30 -0
- package/dist/services/FetcherService.js +171 -0
- package/dist/services/FetcherService.js.map +1 -0
- package/dist/services/data/TweetService.d.ts +43 -0
- package/dist/services/data/TweetService.js +229 -0
- package/dist/services/data/TweetService.js.map +1 -0
- package/dist/services/data/UserAccountService.d.ts +49 -0
- package/dist/services/data/UserAccountService.js +250 -0
- package/dist/services/data/UserAccountService.js.map +1 -0
- package/dist/services/helper/Deserializers.d.ts +19 -0
- package/dist/services/helper/Deserializers.js +115 -0
- package/dist/services/helper/Deserializers.js.map +1 -0
- package/dist/services/helper/Extractors.d.ts +101 -0
- package/dist/services/helper/Extractors.js +409 -0
- package/dist/services/helper/Extractors.js.map +1 -0
- package/dist/services/helper/Headers.d.ts +9 -0
- package/dist/services/helper/Headers.js +47 -0
- package/dist/services/helper/Headers.js.map +1 -0
- package/dist/services/helper/Parser.d.ts +28 -0
- package/dist/services/helper/Parser.js +104 -0
- package/dist/services/helper/Parser.js.map +1 -0
- package/dist/services/helper/Urls.d.ts +74 -0
- package/dist/services/helper/Urls.js +114 -0
- package/dist/services/helper/Urls.js.map +1 -0
- package/dist/test/Test.js +2 -0
- package/dist/test/Test.js.map +1 -0
- package/dist/types/Authentication.d.ts +15 -0
- package/dist/types/Authentication.js +5 -0
- package/dist/types/Authentication.js.map +1 -0
- package/dist/types/HTTP.d.ts +22 -0
- package/dist/types/HTTP.js +30 -0
- package/dist/types/HTTP.js.map +1 -0
- package/dist/types/Service.d.ts +27 -0
- package/dist/types/Service.js +19 -0
- package/dist/types/Service.js.map +1 -0
- package/dist/types/Tweet.d.ts +40 -0
- package/dist/types/Tweet.js +5 -0
- package/dist/types/Tweet.js.map +1 -0
- package/dist/types/UserAccount.d.ts +19 -0
- package/dist/types/UserAccount.js +4 -0
- package/dist/types/UserAccount.js.map +1 -0
- package/dist/types/graphql/Errors.d.ts +15 -0
- package/dist/types/graphql/Errors.js +23 -0
- package/dist/types/graphql/Errors.js.map +1 -0
- package/dist/types/raw/auth/Cookie.d.ts +16 -0
- package/dist/types/raw/auth/Cookie.js +3 -0
- package/dist/types/raw/auth/Cookie.js.map +1 -0
- package/dist/types/raw/tweet/Favouriters.d.ts +164 -0
- package/dist/types/raw/tweet/Favouriters.js +3 -0
- package/dist/types/raw/tweet/Favouriters.js.map +1 -0
- package/dist/types/raw/tweet/Retweeters.d.ts +171 -0
- package/dist/types/raw/tweet/Retweeters.js +3 -0
- package/dist/types/raw/tweet/Retweeters.js.map +1 -0
- package/dist/types/raw/tweet/Tweet.d.ts +746 -0
- package/dist/types/raw/tweet/Tweet.js +3 -0
- package/dist/types/raw/tweet/Tweet.js.map +1 -0
- package/dist/types/raw/tweet/Tweets.d.ts +386 -0
- package/dist/types/raw/tweet/Tweets.js +3 -0
- package/dist/types/raw/tweet/Tweets.js.map +1 -0
- package/dist/types/raw/user/Followers.d.ts +176 -0
- package/dist/types/raw/user/Followers.js +3 -0
- package/dist/types/raw/user/Followers.js.map +1 -0
- package/dist/types/raw/user/Following.d.ts +176 -0
- package/dist/types/raw/user/Following.js +3 -0
- package/dist/types/raw/user/Following.js.map +1 -0
- package/dist/types/raw/user/Likes.d.ts +1059 -0
- package/dist/types/raw/user/Likes.js +3 -0
- package/dist/types/raw/user/Likes.js.map +1 -0
- package/dist/types/raw/user/Tweets.d.ts +2428 -0
- package/dist/types/raw/user/Tweets.js +3 -0
- package/dist/types/raw/user/Tweets.js.map +1 -0
- package/dist/types/raw/user/User.d.ts +117 -0
- package/dist/types/raw/user/User.js +3 -0
- package/dist/types/raw/user/User.js.map +1 -0
- package/dist/types/raw/user/Users.d.ts +120 -0
- package/dist/types/raw/user/Users.js +3 -0
- package/dist/types/raw/user/Users.js.map +1 -0
- package/environment.d.ts +11 -0
- package/package.json +40 -0
- package/src/config/env.ts +5 -0
- package/src/index.ts +19 -0
- package/src/models/graphql/Global.ts +10 -0
- package/src/models/graphql/TweetTypes.ts +154 -0
- package/src/models/graphql/UserTypes.ts +137 -0
- package/src/queries/RootQuery.ts +56 -0
- package/src/resolvers/ResolverBase.ts +12 -0
- package/src/resolvers/TweetResolver.ts +257 -0
- package/src/resolvers/UserResolver.ts +239 -0
- package/src/server.ts +36 -0
- package/src/services/AuthService.ts +58 -0
- package/src/services/CacheService.ts +70 -0
- package/src/services/FetcherService.ts +84 -0
- package/src/services/data/TweetService.ts +163 -0
- package/src/services/data/UserAccountService.ts +187 -0
- package/src/services/helper/Deserializers.ts +95 -0
- package/src/services/helper/Extractors.ts +455 -0
- package/src/services/helper/Headers.ts +45 -0
- package/src/services/helper/Parser.ts +108 -0
- package/src/services/helper/Urls.ts +109 -0
- package/src/types/Authentication.ts +16 -0
- package/src/types/HTTP.ts +23 -0
- package/src/types/Service.ts +36 -0
- package/src/types/Tweet.ts +44 -0
- package/src/types/UserAccount.ts +21 -0
- package/src/types/graphql/Errors.ts +16 -0
- package/src/types/raw/auth/Cookie.ts +16 -0
- package/src/types/raw/tweet/Favouriters.ts +193 -0
- package/src/types/raw/tweet/Retweeters.ts +201 -0
- package/src/types/raw/tweet/Tweet.ts +882 -0
- package/src/types/raw/tweet/Tweets.ts +444 -0
- package/src/types/raw/user/Followers.ts +208 -0
- package/src/types/raw/user/Following.ts +208 -0
- package/src/types/raw/user/Likes.ts +1247 -0
- package/src/types/raw/user/Tweets.ts +2847 -0
- package/src/types/raw/user/User.ts +135 -0
- package/tsconfig.json +95 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
exports.__esModule = true;
|
|
57
|
+
// RESOLVERS
|
|
58
|
+
var ResolverBase_1 = __importDefault(require("./ResolverBase"));
|
|
59
|
+
// TYPES
|
|
60
|
+
var Service_1 = require("../types/Service");
|
|
61
|
+
// HELPERS
|
|
62
|
+
var Errors_1 = require("../types/graphql/Errors");
|
|
63
|
+
var UserResolver = /** @class */ (function (_super) {
|
|
64
|
+
__extends(UserResolver, _super);
|
|
65
|
+
// MEMBER METHODS
|
|
66
|
+
function UserResolver(context) {
|
|
67
|
+
return _super.call(this, context) || this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @returns The details of the target twitter user
|
|
71
|
+
* @param userName The user name of the target twitter user
|
|
72
|
+
* @param id The id of the target twitter user
|
|
73
|
+
*/
|
|
74
|
+
UserResolver.prototype.resolveUserDetails = function (userName, id) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
if (!userName) return [3 /*break*/, 2];
|
|
80
|
+
return [4 /*yield*/, this.context.users.getUserAccountDetails(userName)];
|
|
81
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
82
|
+
case 2:
|
|
83
|
+
if (!id) return [3 /*break*/, 4];
|
|
84
|
+
return [4 /*yield*/, this.context.users.getUserAccountDetailsById(id)];
|
|
85
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
86
|
+
case 4: throw new Error(Errors_1.ValidationErrors.NoUserIdentification);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* @returns The list of tweets liked by the given user
|
|
93
|
+
* @param id The id of the user whose likes are to be fetched
|
|
94
|
+
* @param count The number of likes to fetch
|
|
95
|
+
* @param all Whether to fetch list of all tweets liked by user
|
|
96
|
+
* @param cursor The cursor to the batch of likes to fetch
|
|
97
|
+
* @param favouritesCount The total number of tweets liked by target user
|
|
98
|
+
*/
|
|
99
|
+
UserResolver.prototype.resolveUserLikes = function (id, count, all, cursor, favouritesCount) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var likes, next, total, batchSize, res;
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
likes = [];
|
|
106
|
+
next = new Service_1.Cursor(cursor);
|
|
107
|
+
total = 0;
|
|
108
|
+
batchSize = 20;
|
|
109
|
+
// If all liked tweets are to be fetched
|
|
110
|
+
count = all ? favouritesCount : count;
|
|
111
|
+
// If required count less than batch size, setting batch size to required count
|
|
112
|
+
batchSize = (count < batchSize) ? count : batchSize;
|
|
113
|
+
_a.label = 1;
|
|
114
|
+
case 1:
|
|
115
|
+
if (!(total < count)) return [3 /*break*/, 3];
|
|
116
|
+
// If this is the last batch, change batch size to number of remaining tweets
|
|
117
|
+
batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
|
|
118
|
+
return [4 /*yield*/, this.context.users.getUserLikes(id, count, next.value)];
|
|
119
|
+
case 2:
|
|
120
|
+
res = _a.sent();
|
|
121
|
+
// If data is available
|
|
122
|
+
if (res.list.length) {
|
|
123
|
+
// Adding fetched tweets to list of tweets
|
|
124
|
+
likes = likes.concat(res.list);
|
|
125
|
+
// Updating total tweets fetched
|
|
126
|
+
total = likes.length;
|
|
127
|
+
// Getting cursor to next batch
|
|
128
|
+
next = res.next;
|
|
129
|
+
}
|
|
130
|
+
// If no more data is available
|
|
131
|
+
else {
|
|
132
|
+
return [3 /*break*/, 3];
|
|
133
|
+
}
|
|
134
|
+
return [3 /*break*/, 1];
|
|
135
|
+
case 3:
|
|
136
|
+
// Adding the cursor to the end of list of data
|
|
137
|
+
likes.push(next);
|
|
138
|
+
return [2 /*return*/, likes];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* @returns The list of followers of the given twiiter user
|
|
145
|
+
* @param id The id of the user whose followers are to be fetched
|
|
146
|
+
* @param count The number of followers to fetch
|
|
147
|
+
* @param all Whether to fetch all followers list
|
|
148
|
+
* @param cursor The cursor to the batch of followers to fetch
|
|
149
|
+
* @param followerCount The total number of followers of the target user
|
|
150
|
+
*/
|
|
151
|
+
UserResolver.prototype.resolveUserFollowers = function (id, count, all, cursor, followersCount) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var followers, next, total, batchSize, res;
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
switch (_a.label) {
|
|
156
|
+
case 0:
|
|
157
|
+
followers = [];
|
|
158
|
+
next = new Service_1.Cursor(cursor);
|
|
159
|
+
total = 0;
|
|
160
|
+
batchSize = 20;
|
|
161
|
+
// If all followers are to be fetched
|
|
162
|
+
count = (all || count > followersCount) ? followersCount : count;
|
|
163
|
+
// If required count less than batch size, setting batch size to required count
|
|
164
|
+
batchSize = (count < batchSize) ? count : batchSize;
|
|
165
|
+
_a.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
if (!(total < count)) return [3 /*break*/, 3];
|
|
168
|
+
// If this is the last batch, change batch size to number of remaining followers
|
|
169
|
+
batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
|
|
170
|
+
return [4 /*yield*/, this.context.users.getUserFollowers(id, count, next.value)];
|
|
171
|
+
case 2:
|
|
172
|
+
res = _a.sent();
|
|
173
|
+
// If data is available
|
|
174
|
+
if (res.list.length) {
|
|
175
|
+
// Adding fetched followers to list of followers
|
|
176
|
+
followers = followers.concat(res.list);
|
|
177
|
+
// Updating total followers fetched
|
|
178
|
+
total = followers.length;
|
|
179
|
+
// Getting cursor to next batch
|
|
180
|
+
next = res.next;
|
|
181
|
+
}
|
|
182
|
+
// If no more data is available
|
|
183
|
+
else {
|
|
184
|
+
return [3 /*break*/, 3];
|
|
185
|
+
}
|
|
186
|
+
return [3 /*break*/, 1];
|
|
187
|
+
case 3:
|
|
188
|
+
// Adding the cursor to the end of list of data
|
|
189
|
+
followers.push(next);
|
|
190
|
+
return [2 /*return*/, followers];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* @returns The list of following of the given twiiter user
|
|
197
|
+
* @param id The id of the user whose followings are to be fetched
|
|
198
|
+
* @param count The number of following to fetch
|
|
199
|
+
* @param all Whether to fetch list of all followings
|
|
200
|
+
* @param cursor The cursor to the batch of followings to fetch
|
|
201
|
+
* @param followingsCount The total number of followings of the target user
|
|
202
|
+
*/
|
|
203
|
+
UserResolver.prototype.resolveUserFollowing = function (id, count, all, cursor, followingsCount) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
var following, next, total, batchSize, res;
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
following = [];
|
|
210
|
+
next = new Service_1.Cursor(cursor);
|
|
211
|
+
total = 0;
|
|
212
|
+
batchSize = 20;
|
|
213
|
+
// If all followings are to be fetched
|
|
214
|
+
count = (all || count > followingsCount) ? followingsCount : count;
|
|
215
|
+
// If required count less than batch size, setting batch size to required count
|
|
216
|
+
batchSize = (count < batchSize) ? count : batchSize;
|
|
217
|
+
_a.label = 1;
|
|
218
|
+
case 1:
|
|
219
|
+
if (!(total < count)) return [3 /*break*/, 3];
|
|
220
|
+
// If this is the last batch, change batch size to number of remaining following
|
|
221
|
+
batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
|
|
222
|
+
return [4 /*yield*/, this.context.users.getUserFollowing(id, count, next.value)];
|
|
223
|
+
case 2:
|
|
224
|
+
res = _a.sent();
|
|
225
|
+
// If data is available
|
|
226
|
+
if (res.list.length) {
|
|
227
|
+
// Adding fetched following to list of following
|
|
228
|
+
following = following.concat(res.list);
|
|
229
|
+
// Updating total following fetched
|
|
230
|
+
total = following.length;
|
|
231
|
+
// Getting cursor to next batch
|
|
232
|
+
next = res.next;
|
|
233
|
+
}
|
|
234
|
+
// If no more data is available
|
|
235
|
+
else {
|
|
236
|
+
return [3 /*break*/, 3];
|
|
237
|
+
}
|
|
238
|
+
return [3 /*break*/, 1];
|
|
239
|
+
case 3:
|
|
240
|
+
// Adding the cursor to the end of list of data
|
|
241
|
+
following.push(next);
|
|
242
|
+
return [2 /*return*/, following];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* @returns The list of tweets made by the given user
|
|
249
|
+
* @param id The id of the user whose tweets are to be fetched
|
|
250
|
+
* @param count The number of tweets to fetch
|
|
251
|
+
* @param all Whether to fetch list of all tweets made by user
|
|
252
|
+
* @param cursor The cursor to the batch of tweets to fetch
|
|
253
|
+
* @param statusesCount The total number of tweets made by target user
|
|
254
|
+
*/
|
|
255
|
+
UserResolver.prototype.resolveUserTweets = function (id, count, all, cursor, statusesCount) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
+
var tweets, next, total, batchSize, res;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0:
|
|
261
|
+
tweets = [];
|
|
262
|
+
next = new Service_1.Cursor(cursor);
|
|
263
|
+
total = 0;
|
|
264
|
+
batchSize = 20;
|
|
265
|
+
// If all tweets are to be fetched
|
|
266
|
+
count = all ? statusesCount : count;
|
|
267
|
+
// If required count less than batch size, setting batch size to required count
|
|
268
|
+
batchSize = (count < batchSize) ? count : batchSize;
|
|
269
|
+
_a.label = 1;
|
|
270
|
+
case 1:
|
|
271
|
+
if (!(total < count)) return [3 /*break*/, 3];
|
|
272
|
+
// If this is the last batch, change batch size to number of remaining tweets
|
|
273
|
+
batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
|
|
274
|
+
return [4 /*yield*/, this.context.users.getUserTweets(id, count, next.value)];
|
|
275
|
+
case 2:
|
|
276
|
+
res = _a.sent();
|
|
277
|
+
// If data is available
|
|
278
|
+
if (res.list.length) {
|
|
279
|
+
// Adding fetched tweets to list of tweets
|
|
280
|
+
tweets = tweets.concat(res.list);
|
|
281
|
+
// Updating total tweets fetched
|
|
282
|
+
total = tweets.length;
|
|
283
|
+
// Getting cursor to next batch
|
|
284
|
+
next = res.next;
|
|
285
|
+
}
|
|
286
|
+
// If no more data is available
|
|
287
|
+
else {
|
|
288
|
+
return [3 /*break*/, 3];
|
|
289
|
+
}
|
|
290
|
+
return [3 /*break*/, 1];
|
|
291
|
+
case 3:
|
|
292
|
+
// Adding the cursor to the end of list of data
|
|
293
|
+
tweets.push(next);
|
|
294
|
+
return [2 /*return*/, tweets];
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
return UserResolver;
|
|
300
|
+
}(ResolverBase_1["default"]));
|
|
301
|
+
exports["default"] = UserResolver;
|
|
302
|
+
//# sourceMappingURL=UserResolver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KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;wBAEpC,+EAA+E;wBAC/E,SAAS,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;;;6BAG7C,CAAA,KAAK,GAAG,KAAK,CAAA;wBAChB,6EAA6E;wBAC7E,SAAS,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;wBAG5D,qBAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAA;;wBAAnE,GAAG,GAAG,SAA6D;wBAEzE,uBAAuB;wBACvB,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE;4BACjB,0CAA0C;4BAC1C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;4BAEjC,gCAAgC;4BAChC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;4BAEtB,+BAA+B;4BAC/B,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;yBACnB;wBACD,+BAA+B;6BAC1B;4BACD,wBAAM;yBACT;;;wBAGL,+CAA+C;wBAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAElB,sBAAO,MAAM,EAAC;;;;KACjB;IACL,mBAAC;AAAD,CAAC,AArOD,CAA0C,yBAAY,GAqOrD"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
// PACKAGE
|
|
43
|
+
var express_1 = __importDefault(require("express"));
|
|
44
|
+
var express_graphql_1 = require("express-graphql");
|
|
45
|
+
var graphql_1 = require("graphql");
|
|
46
|
+
// Services
|
|
47
|
+
var UserAccountService_1 = require("./services/data/UserAccountService");
|
|
48
|
+
var TweetService_1 = require("./services/data/TweetService");
|
|
49
|
+
var AuthService_1 = require("./services/AuthService");
|
|
50
|
+
// SCHEMA
|
|
51
|
+
var RootQuery_1 = require("./queries/RootQuery");
|
|
52
|
+
// CONFIGS
|
|
53
|
+
var env_1 = require("./config/env");
|
|
54
|
+
// Initialising express instance
|
|
55
|
+
var app = (0, express_1["default"])();
|
|
56
|
+
// Setting up graphql endpoint
|
|
57
|
+
app.use('/graphql', (0, express_graphql_1.graphqlHTTP)(function (req) { return ({
|
|
58
|
+
schema: new graphql_1.GraphQLSchema({
|
|
59
|
+
query: RootQuery_1.rootQuery
|
|
60
|
+
}),
|
|
61
|
+
context: {
|
|
62
|
+
users: new UserAccountService_1.UserAccountService(new AuthService_1.AuthService(req.headers.cookie)),
|
|
63
|
+
tweets: new TweetService_1.TweetService(new AuthService_1.AuthService(req.headers.cookie))
|
|
64
|
+
},
|
|
65
|
+
// If app is running in development environment, enable graphiql
|
|
66
|
+
graphiql: env_1.config.is_development
|
|
67
|
+
}); }));
|
|
68
|
+
// Setting up express server
|
|
69
|
+
app.listen(env_1.config.port, function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
console.log("Listening on port ".concat(env_1.config.port));
|
|
72
|
+
return [2 /*return*/];
|
|
73
|
+
});
|
|
74
|
+
}); });
|
|
75
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,UAAU;AACV,oDAA8B;AAC9B,mDAA8C;AAC9C,mCAAwC;AAExC,WAAW;AACX,yEAAwE;AACxE,6DAA4D;AAC5D,sDAAqD;AAErD,SAAS;AACT,iDAAgD;AAEhD,UAAU;AACV,oCAAsC;AAEtC,gCAAgC;AAChC,IAAM,GAAG,GAAG,IAAA,oBAAO,GAAE,CAAC;AAEtB,8BAA8B;AAC9B,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,IAAA,6BAAW,EAAC,UAAA,GAAG,IAAI,OAAA,CAAC;IACpC,MAAM,EAAE,IAAI,uBAAa,CAAC;QACtB,KAAK,EAAE,qBAAS;KACnB,CAAC;IACF,OAAO,EAAE;QACL,KAAK,EAAE,IAAI,uCAAkB,CAAC,IAAI,yBAAW,CAAC,GAAG,CAAC,OAAO,CAAC,MAAgB,CAAC,CAAC;QAC5E,MAAM,EAAE,IAAI,2BAAY,CAAC,IAAI,yBAAW,CAAC,GAAG,CAAC,OAAO,CAAC,MAAgB,CAAC,CAAC;KAC1E;IACD,gEAAgE;IAChE,QAAQ,EAAE,YAAM,CAAC,cAAc;CAClC,CAAC,EAVqC,CAUrC,CAAC,CAAC,CAAC;AAEL,4BAA4B;AAC5B,GAAG,CAAC,MAAM,CAAC,YAAM,CAAC,IAAI,EAAE;;QACpB,OAAO,CAAC,GAAG,CAAC,4BAAqB,YAAM,CAAC,IAAI,CAAE,CAAC,CAAC;;;KACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GuestCredentials, AuthCredentials } from '../types/Authentication';
|
|
2
|
+
/**
|
|
3
|
+
* @summary Handles authentication of http requests and other authentication related tasks
|
|
4
|
+
*/
|
|
5
|
+
export declare class AuthService {
|
|
6
|
+
private authToken;
|
|
7
|
+
private credentials;
|
|
8
|
+
constructor(cookie?: string);
|
|
9
|
+
/**
|
|
10
|
+
* @returns The current authentication credentials. A different credential is returned each time this is invoked
|
|
11
|
+
*/
|
|
12
|
+
getAuthCredentials(): Promise<AuthCredentials>;
|
|
13
|
+
/**
|
|
14
|
+
* @returns The guest credentials fetched from twitter
|
|
15
|
+
*/
|
|
16
|
+
getGuestCredentials(): Promise<GuestCredentials>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 Urls_1 = require("./helper/Urls");
|
|
47
|
+
// CONFIGS
|
|
48
|
+
var env_1 = require("../config/env");
|
|
49
|
+
/**
|
|
50
|
+
* @summary Handles authentication of http requests and other authentication related tasks
|
|
51
|
+
*/
|
|
52
|
+
var AuthService = /** @class */ (function () {
|
|
53
|
+
// MEMBER METHODS
|
|
54
|
+
function AuthService(cookie) {
|
|
55
|
+
if (cookie === void 0) { cookie = ''; }
|
|
56
|
+
// Reading the auth token from the config, since it's always the same
|
|
57
|
+
this.authToken = env_1.config.twitter_auth_token;
|
|
58
|
+
// Setting up the authenticated credentials
|
|
59
|
+
/**
|
|
60
|
+
* The following regex pattern is used to extract the csrfToken from the cookie string.
|
|
61
|
+
* This is done by matching any string between the characters 'ct0=' and nearest enclosing ';'.
|
|
62
|
+
* (?<=pattern) starts matching after the given pattern.
|
|
63
|
+
* (?=pattern) stops matching just before the pattern
|
|
64
|
+
*/
|
|
65
|
+
this.credentials = { authToken: this.authToken, csrfToken: cookie.match(/(?<=ct0=).+?(?=;)/) + '', cookie: cookie };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @returns The current authentication credentials. A different credential is returned each time this is invoked
|
|
69
|
+
*/
|
|
70
|
+
AuthService.prototype.getAuthCredentials = function () {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
return [2 /*return*/, this.credentials];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* @returns The guest credentials fetched from twitter
|
|
79
|
+
*/
|
|
80
|
+
AuthService.prototype.getGuestCredentials = function () {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
var _this = this;
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, axios_1["default"].post((0, Urls_1.guestTokenUrl)(), null, {
|
|
86
|
+
headers: {
|
|
87
|
+
'Authorization': this.authToken
|
|
88
|
+
}
|
|
89
|
+
}).then(function (res) { return ({
|
|
90
|
+
authToken: _this.authToken,
|
|
91
|
+
guestToken: res.data.guest_token
|
|
92
|
+
}); })];
|
|
93
|
+
case 1:
|
|
94
|
+
// Getting the guest credentials from twitter
|
|
95
|
+
return [2 /*return*/, _a.sent()];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
return AuthService;
|
|
101
|
+
}());
|
|
102
|
+
exports.AuthService = AuthService;
|
|
103
|
+
//# sourceMappingURL=AuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../src/services/AuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,UAAU;AACV,gDAA0B;AAE1B,OAAO;AACP,sCAA8C;AAK9C,UAAU;AACV,qCAAuC;AAEvC;;GAEG;AACH;IAKI,iBAAiB;IACjB,qBAAY,MAAmB;QAAnB,uBAAA,EAAA,WAAmB;QAC3B,qEAAqE;QACrE,IAAI,CAAC,SAAS,GAAG,YAAM,CAAC,kBAAkB,CAAC;QAE3C,2CAA2C;QAC3C;;;;;WAKG;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAC,CAAC;IAEvH,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,oBAAa,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,AA1CD,IA0CC;AA1CY,kCAAW"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Handles reading and writing of data from and to cache.
|
|
3
|
+
*
|
|
4
|
+
* **Note**: To be able to CacheService, the data to be cached must have a unique "id" field.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CacheService {
|
|
7
|
+
private static instance;
|
|
8
|
+
private client;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* @returns The current working instance of CacheService
|
|
12
|
+
*/
|
|
13
|
+
static getInstance(): Promise<CacheService>;
|
|
14
|
+
/**
|
|
15
|
+
* @summary Stores the input data into the cache.
|
|
16
|
+
* @returns Whether writing to cache was successful or not
|
|
17
|
+
* @param data The input data to store
|
|
18
|
+
*/
|
|
19
|
+
write(data: any): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @returns The data with the given id/rest id from cache
|
|
22
|
+
* @param id The id/rest id of the data to be fetched from cache
|
|
23
|
+
*/
|
|
24
|
+
read(id: string): Promise<any>;
|
|
25
|
+
}
|