rettiwt-api 1.3.1 → 2.0.0
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/.eslintignore +3 -0
- package/.eslintrc.js +54 -0
- package/.github/workflows/documentation.yml +47 -0
- package/.github/workflows/{publish-to-npm.yml → publish.yml} +8 -8
- package/.prettierignore +3 -0
- package/.prettierrc +13 -0
- package/README.md +59 -61
- package/dist/Rettiwt.d.ts +19 -0
- package/dist/Rettiwt.js +30 -0
- package/dist/Rettiwt.js.map +1 -0
- package/dist/enums/ApiErrors.d.ts +30 -0
- package/dist/enums/ApiErrors.js +35 -0
- package/dist/enums/ApiErrors.js.map +1 -0
- package/dist/enums/HTTP.d.ts +11 -11
- package/dist/enums/HTTP.js +15 -16
- package/dist/enums/HTTP.js.map +1 -1
- package/dist/helper/JsonUtils.d.ts +26 -0
- package/dist/helper/JsonUtils.js +88 -0
- package/dist/helper/JsonUtils.js.map +1 -0
- package/dist/index.d.ts +10 -43
- package/dist/index.js +16 -55
- package/dist/index.js.map +1 -1
- package/dist/models/CursoredData.d.ts +37 -0
- package/dist/models/CursoredData.js +59 -0
- package/dist/models/CursoredData.js.map +1 -0
- package/dist/models/{data/Tweet.d.ts → Tweet.d.ts} +4 -4
- package/dist/models/{data/Tweet.js → Tweet.js} +7 -32
- package/dist/models/Tweet.js.map +1 -0
- package/dist/models/{data/User.d.ts → User.d.ts} +3 -3
- package/dist/models/{data/User.js → User.js} +3 -3
- package/dist/models/User.js.map +1 -0
- package/dist/services/FetcherService.d.ts +66 -0
- package/dist/services/FetcherService.js +207 -0
- package/dist/services/FetcherService.js.map +1 -0
- package/dist/services/TweetService.d.ts +88 -0
- package/dist/services/TweetService.js +244 -0
- package/dist/services/TweetService.js.map +1 -0
- package/dist/services/UserService.d.ts +60 -0
- package/dist/services/UserService.js +188 -0
- package/dist/services/UserService.js.map +1 -0
- package/dist/types/{Service.d.ts → CursoredData.d.ts} +3 -3
- package/dist/types/CursoredData.js +3 -0
- package/dist/types/CursoredData.js.map +1 -0
- package/dist/types/Tweet.js +1 -1
- package/dist/types/User.js +1 -1
- package/package.json +15 -19
- package/src/Rettiwt.ts +33 -0
- package/src/enums/ApiErrors.ts +30 -0
- package/src/enums/HTTP.ts +12 -12
- package/src/helper/JsonUtils.ts +86 -0
- package/src/index.ts +14 -57
- package/src/models/CursoredData.ts +64 -0
- package/src/models/Tweet.ts +116 -0
- package/src/models/User.ts +72 -0
- package/src/services/FetcherService.ts +183 -0
- package/src/services/TweetService.ts +153 -0
- package/src/services/UserService.ts +117 -0
- package/src/types/CursoredData.ts +24 -0
- package/src/types/Tweet.ts +35 -35
- package/src/types/User.ts +30 -30
- package/tsconfig.json +9 -9
- package/.github/workflows/build-docs.yml +0 -28
- package/dist/config/env.d.ts +0 -5
- package/dist/config/env.js +0 -9
- package/dist/config/env.js.map +0 -1
- package/dist/enums/Errors.d.ts +0 -21
- package/dist/enums/Errors.js +0 -29
- package/dist/enums/Errors.js.map +0 -1
- package/dist/graphql/enums/Errors.d.ts +0 -21
- package/dist/graphql/enums/Errors.js +0 -29
- package/dist/graphql/enums/Errors.js.map +0 -1
- package/dist/graphql/queries/RootQuery.d.ts +0 -4
- package/dist/graphql/queries/RootQuery.js +0 -78
- package/dist/graphql/queries/RootQuery.js.map +0 -1
- package/dist/graphql/resolvers/AccountResolver.d.ts +0 -12
- package/dist/graphql/resolvers/AccountResolver.js +0 -84
- package/dist/graphql/resolvers/AccountResolver.js.map +0 -1
- package/dist/graphql/resolvers/ResolverBase.d.ts +0 -16
- package/dist/graphql/resolvers/ResolverBase.js +0 -23
- package/dist/graphql/resolvers/ResolverBase.js.map +0 -1
- package/dist/graphql/resolvers/TweetResolver.d.ts +0 -46
- package/dist/graphql/resolvers/TweetResolver.js +0 -312
- package/dist/graphql/resolvers/TweetResolver.js.map +0 -1
- package/dist/graphql/resolvers/UserResolver.d.ts +0 -48
- package/dist/graphql/resolvers/UserResolver.js +0 -334
- package/dist/graphql/resolvers/UserResolver.js.map +0 -1
- package/dist/graphql/types/Global.d.ts +0 -4
- package/dist/graphql/types/Global.js +0 -13
- package/dist/graphql/types/Global.js.map +0 -1
- package/dist/graphql/types/TweetTypes.d.ts +0 -4
- package/dist/graphql/types/TweetTypes.js +0 -160
- package/dist/graphql/types/TweetTypes.js.map +0 -1
- package/dist/graphql/types/UserTypes.d.ts +0 -3
- package/dist/graphql/types/UserTypes.js +0 -137
- package/dist/graphql/types/UserTypes.js.map +0 -1
- package/dist/models/args/TweetListArgs.d.ts +0 -21
- package/dist/models/args/TweetListArgs.js +0 -54
- package/dist/models/args/TweetListArgs.js.map +0 -1
- package/dist/models/args/UserListArgs.d.ts +0 -21
- package/dist/models/args/UserListArgs.js +0 -54
- package/dist/models/args/UserListArgs.js.map +0 -1
- package/dist/models/auth/AuthCookie.d.ts +0 -21
- package/dist/models/auth/AuthCookie.js +0 -33
- package/dist/models/auth/AuthCookie.js.map +0 -1
- package/dist/models/data/CursoredData.d.ts +0 -34
- package/dist/models/data/CursoredData.js +0 -42
- package/dist/models/data/CursoredData.js.map +0 -1
- package/dist/models/data/Tweet.js.map +0 -1
- package/dist/models/data/User.js.map +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -76
- package/dist/server.js.map +0 -1
- package/dist/services/auth/AccountService.d.ts +0 -83
- package/dist/services/auth/AccountService.js +0 -412
- package/dist/services/auth/AccountService.js.map +0 -1
- package/dist/services/auth/AuthService.d.ts +0 -31
- package/dist/services/auth/AuthService.js +0 -118
- package/dist/services/auth/AuthService.js.map +0 -1
- package/dist/services/data/TweetService.d.ts +0 -60
- package/dist/services/data/TweetService.js +0 -251
- package/dist/services/data/TweetService.js.map +0 -1
- package/dist/services/data/UserService.d.ts +0 -71
- package/dist/services/data/UserService.js +0 -278
- package/dist/services/data/UserService.js.map +0 -1
- package/dist/services/helper/Headers.d.ts +0 -19
- package/dist/services/helper/Headers.js +0 -62
- package/dist/services/helper/Headers.js.map +0 -1
- package/dist/services/helper/Parser.d.ts +0 -22
- package/dist/services/helper/Parser.js +0 -84
- package/dist/services/helper/Parser.js.map +0 -1
- package/dist/services/helper/extractors/Tweets.d.ts +0 -23
- package/dist/services/helper/extractors/Tweets.js +0 -200
- package/dist/services/helper/extractors/Tweets.js.map +0 -1
- package/dist/services/helper/extractors/Users.d.ts +0 -17
- package/dist/services/helper/extractors/Users.js +0 -151
- package/dist/services/helper/extractors/Users.js.map +0 -1
- package/dist/services/helper/payloads/LoginFlows.d.ts +0 -77
- package/dist/services/helper/payloads/LoginFlows.js +0 -92
- package/dist/services/helper/payloads/LoginFlows.js.map +0 -1
- package/dist/services/helper/urls/Authentication.d.ts +0 -4
- package/dist/services/helper/urls/Authentication.js +0 -11
- package/dist/services/helper/urls/Authentication.js.map +0 -1
- package/dist/services/util/CacheService.d.ts +0 -33
- package/dist/services/util/CacheService.js +0 -96
- package/dist/services/util/CacheService.js.map +0 -1
- package/dist/services/util/FetcherService.d.ts +0 -65
- package/dist/services/util/FetcherService.js +0 -202
- package/dist/services/util/FetcherService.js.map +0 -1
- package/dist/types/Args.d.ts +0 -11
- package/dist/types/Args.js +0 -4
- package/dist/types/Args.js.map +0 -1
- package/dist/types/Authentication.d.ts +0 -55
- package/dist/types/Authentication.js +0 -6
- package/dist/types/Authentication.js.map +0 -1
- package/dist/types/Resolvers.d.ts +0 -15
- package/dist/types/Resolvers.js +0 -3
- package/dist/types/Resolvers.js.map +0 -1
- package/dist/types/Rettiwt.d.ts +0 -16
- package/dist/types/Rettiwt.js +0 -3
- package/dist/types/Rettiwt.js.map +0 -1
- package/dist/types/Service.js +0 -5
- package/dist/types/Service.js.map +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -64
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/AccountService.html +0 -286
- package/docs/classes/AuthCookie.html +0 -146
- package/docs/classes/AuthService.html +0 -147
- package/docs/classes/CacheService.html +0 -157
- package/docs/classes/Cursor.html +0 -102
- package/docs/classes/CursoredData.html +0 -126
- package/docs/classes/DataValidationError.html +0 -120
- package/docs/classes/FetcherService.html +0 -225
- package/docs/classes/Tweet.html +0 -210
- package/docs/classes/TweetEntities.html +0 -128
- package/docs/classes/TweetFilter.html +0 -223
- package/docs/classes/TweetListArgs.html +0 -118
- package/docs/classes/TweetService.html +0 -319
- package/docs/classes/User.html +0 -230
- package/docs/classes/UserListArgs.html +0 -118
- package/docs/classes/UserService.html +0 -355
- package/docs/enums/HttpMethods.html +0 -74
- package/docs/functions/Rettiwt.html +0 -100
- package/docs/index.html +0 -159
- package/docs/interfaces/IAuthCookie.html +0 -104
- package/docs/interfaces/ICursor.html +0 -77
- package/docs/interfaces/ICursoredData.html +0 -93
- package/docs/interfaces/IDataContext.html +0 -91
- package/docs/interfaces/IDataValidationError.html +0 -109
- package/docs/interfaces/IListArgs.html +0 -87
- package/docs/interfaces/ITweet.html +0 -176
- package/docs/interfaces/ITweetEntities.html +0 -104
- package/docs/interfaces/ITweetFilter.html +0 -158
- package/docs/interfaces/IUser.html +0 -194
- package/docs/modules.html +0 -111
- package/environment.d.ts +0 -11
- package/src/config/env.ts +0 -5
- package/src/enums/Errors.ts +0 -22
- package/src/graphql/enums/Errors.ts +0 -22
- package/src/graphql/queries/RootQuery.ts +0 -75
- package/src/graphql/resolvers/AccountResolver.ts +0 -22
- package/src/graphql/resolvers/ResolverBase.ts +0 -26
- package/src/graphql/resolvers/TweetResolver.ts +0 -237
- package/src/graphql/resolvers/UserResolver.ts +0 -257
- package/src/graphql/types/Global.ts +0 -10
- package/src/graphql/types/TweetTypes.ts +0 -158
- package/src/graphql/types/UserTypes.ts +0 -135
- package/src/models/args/TweetListArgs.ts +0 -47
- package/src/models/args/UserListArgs.ts +0 -47
- package/src/models/auth/AuthCookie.ts +0 -43
- package/src/models/data/CursoredData.ts +0 -45
- package/src/models/data/Tweet.ts +0 -118
- package/src/models/data/User.ts +0 -72
- package/src/server.ts +0 -37
- package/src/services/auth/AccountService.ts +0 -283
- package/src/services/auth/AuthService.ts +0 -81
- package/src/services/data/TweetService.ts +0 -198
- package/src/services/data/UserService.ts +0 -221
- package/src/services/helper/Headers.ts +0 -60
- package/src/services/helper/Parser.ts +0 -89
- package/src/services/helper/extractors/Tweets.ts +0 -190
- package/src/services/helper/extractors/Users.ts +0 -141
- package/src/services/helper/payloads/LoginFlows.ts +0 -90
- package/src/services/helper/urls/Authentication.ts +0 -6
- package/src/services/util/CacheService.ts +0 -76
- package/src/services/util/FetcherService.ts +0 -143
- package/src/types/Args.ts +0 -12
- package/src/types/Authentication.ts +0 -63
- package/src/types/Resolvers.ts +0 -18
- package/src/types/Rettiwt.ts +0 -20
- package/src/types/Service.ts +0 -24
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// PACKAGE
|
|
2
|
-
import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList, GraphQLUnionType, GraphQLType } from 'graphql';
|
|
3
|
-
import { TweetFilter } from 'rettiwt-core';
|
|
4
|
-
|
|
5
|
-
// TYPES
|
|
6
|
-
import { Tweet, TweetList } from './TweetTypes'
|
|
7
|
-
import { Cursor } from './Global';
|
|
8
|
-
|
|
9
|
-
// RESOLVERS
|
|
10
|
-
import UserResolver from '../resolvers/UserResolver';
|
|
11
|
-
import TweetResolver from '../resolvers/TweetResolver';
|
|
12
|
-
|
|
13
|
-
export const User: GraphQLObjectType = new GraphQLObjectType({
|
|
14
|
-
name: 'User',
|
|
15
|
-
description: 'The details of a single target twitter user',
|
|
16
|
-
fields: () => ({
|
|
17
|
-
id: { type: GraphQLString },
|
|
18
|
-
userName: { type: GraphQLString },
|
|
19
|
-
fullName: { type: GraphQLString },
|
|
20
|
-
createdAt: { type: GraphQLString },
|
|
21
|
-
description: { type: GraphQLString },
|
|
22
|
-
isVerified: { type: GraphQLBoolean },
|
|
23
|
-
location: { type: GraphQLString },
|
|
24
|
-
pinnedTweet: {
|
|
25
|
-
type: Tweet,
|
|
26
|
-
resolve: (parent, args, context) => (parent.pinnedTweet) ? new TweetResolver(context).resolveTweet(parent.pinnedTweet) : undefined
|
|
27
|
-
},
|
|
28
|
-
profileBanner: { type: GraphQLString },
|
|
29
|
-
profileImage: { type: GraphQLString },
|
|
30
|
-
favouritesCount: { type: GraphQLInt },
|
|
31
|
-
likes: {
|
|
32
|
-
type: TweetList,
|
|
33
|
-
args: {
|
|
34
|
-
count: {
|
|
35
|
-
description: "The number of liked tweets to fetch, must be >= 40 (when no cursor if provided)",
|
|
36
|
-
type: GraphQLInt,
|
|
37
|
-
defaultValue: 10
|
|
38
|
-
},
|
|
39
|
-
all: {
|
|
40
|
-
description: "Whether to fetch all tweets liked by user",
|
|
41
|
-
type: GraphQLBoolean,
|
|
42
|
-
defaultValue: false
|
|
43
|
-
},
|
|
44
|
-
cursor: {
|
|
45
|
-
type: GraphQLString,
|
|
46
|
-
description: 'The cursor to the batch of likes list to fetch',
|
|
47
|
-
defaultValue: ''
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
resolve: (parent, args, context) => new UserResolver(context).resolveUserLikes(parent.id, args.count, args.all, args.cursor, parent.favouritesCount)
|
|
51
|
-
},
|
|
52
|
-
followersCount: { type: GraphQLInt },
|
|
53
|
-
followers: {
|
|
54
|
-
type: UserList,
|
|
55
|
-
args: {
|
|
56
|
-
count: {
|
|
57
|
-
description: "The number of followers to fetch, must be >= 40 (when no cursor is provided)",
|
|
58
|
-
type: GraphQLInt,
|
|
59
|
-
defaultValue: 40
|
|
60
|
-
},
|
|
61
|
-
all: {
|
|
62
|
-
description: "Whether to fetch all followers list",
|
|
63
|
-
type: GraphQLBoolean,
|
|
64
|
-
defaultValue: false
|
|
65
|
-
},
|
|
66
|
-
cursor: {
|
|
67
|
-
type: GraphQLString,
|
|
68
|
-
description: 'The cursor to the batch of followers list to fetch',
|
|
69
|
-
defaultValue: ''
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
resolve: (parent, args, context) => new UserResolver(context).resolveUserFollowers(parent.id, args.count, args.all, args.cursor, parent.followersCount)
|
|
73
|
-
},
|
|
74
|
-
followingsCount: { type: GraphQLInt },
|
|
75
|
-
following: {
|
|
76
|
-
type: UserList,
|
|
77
|
-
args: {
|
|
78
|
-
count: {
|
|
79
|
-
type: GraphQLInt,
|
|
80
|
-
description: "The number of followings to fetch, must be >= 40 (when no cursor is provided)",
|
|
81
|
-
defaultValue: 40
|
|
82
|
-
},
|
|
83
|
-
all: {
|
|
84
|
-
description: "Whether to fetch all followings list",
|
|
85
|
-
type: GraphQLBoolean,
|
|
86
|
-
defaultValue: false
|
|
87
|
-
},
|
|
88
|
-
cursor: {
|
|
89
|
-
type: GraphQLString,
|
|
90
|
-
description: 'The cursor to the batch of followers list to fetch',
|
|
91
|
-
defaultValue: ''
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
resolve: (parent, args, context) => new UserResolver(context).resolveUserFollowing(parent.id, args.count, args.all, args.cursor, parent.followingsCount)
|
|
95
|
-
},
|
|
96
|
-
statusesCount: { type: GraphQLInt },
|
|
97
|
-
tweets: {
|
|
98
|
-
type: TweetList,
|
|
99
|
-
args: {
|
|
100
|
-
count: {
|
|
101
|
-
description: "The number of tweets to fetch, must be >= 1",
|
|
102
|
-
type: GraphQLInt,
|
|
103
|
-
defaultValue: 10
|
|
104
|
-
},
|
|
105
|
-
all: {
|
|
106
|
-
description: "Whether to fetch all tweets made by user",
|
|
107
|
-
type: GraphQLBoolean,
|
|
108
|
-
defaultValue: false
|
|
109
|
-
},
|
|
110
|
-
cursor: {
|
|
111
|
-
type: GraphQLString,
|
|
112
|
-
description: 'The cursor to the batch of tweets list to fetch',
|
|
113
|
-
defaultValue: ''
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
resolve: (parent, args, context) => new UserResolver(context).resolveUserTweets(parent.userName, args.count, args.all, args.cursor, parent.statusesCount)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
export const UserList: GraphQLList<GraphQLType> = new GraphQLList(new GraphQLUnionType({
|
|
122
|
-
name: 'UserCursorUnion',
|
|
123
|
-
description: 'A union type which can either be a User or a Cursor, used in cursored User lists',
|
|
124
|
-
types: [User, Cursor],
|
|
125
|
-
resolveType: (data) => {
|
|
126
|
-
// If it has a userName field => this is a User object
|
|
127
|
-
if (data.userName) {
|
|
128
|
-
return User;
|
|
129
|
-
}
|
|
130
|
-
// If it has a value field => this is a Cursor object
|
|
131
|
-
else if (data.value) {
|
|
132
|
-
return Cursor;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}));
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// PACKAGES
|
|
2
|
-
import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
|
|
3
|
-
import { DataValidationError } from 'rettiwt-core';
|
|
4
|
-
|
|
5
|
-
// TYPES
|
|
6
|
-
import { IListArgs } from '../../types/Args';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The arguments for fetching cursored list in TweetService.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export class TweetListArgs implements IListArgs {
|
|
14
|
-
/** The number of data items to fetch.
|
|
15
|
-
*
|
|
16
|
-
* @defaultValue 10
|
|
17
|
-
* @remarks Must be >= 10 and <= 100
|
|
18
|
-
*/
|
|
19
|
-
@IsInt()
|
|
20
|
-
@IsOptional()
|
|
21
|
-
@Max(100)
|
|
22
|
-
@ValidateIf(ob => ob.cursor.length == 0)
|
|
23
|
-
@Min(10)
|
|
24
|
-
count: number;
|
|
25
|
-
|
|
26
|
-
/** The cursor to the batch of data to fetch. */
|
|
27
|
-
@IsString()
|
|
28
|
-
@IsOptional()
|
|
29
|
-
cursor: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param count The number of data items to fetch.
|
|
33
|
-
* @param cursor The cursor to the batch of data to fetch.
|
|
34
|
-
*/
|
|
35
|
-
constructor(count: number = 10, cursor: string = '') {
|
|
36
|
-
this.count = count;
|
|
37
|
-
this.cursor = cursor;
|
|
38
|
-
|
|
39
|
-
// Validating the arguments
|
|
40
|
-
const validationResult = validateSync(this);
|
|
41
|
-
|
|
42
|
-
// If valiation error occured
|
|
43
|
-
if (validationResult.length) {
|
|
44
|
-
throw new DataValidationError(validationResult);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// PACKAGES
|
|
2
|
-
import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
|
|
3
|
-
import { DataValidationError } from 'rettiwt-core';
|
|
4
|
-
|
|
5
|
-
// TYPES
|
|
6
|
-
import { IListArgs } from '../../types/Args';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The arguments for fetching cursored list in TweetService.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export class UserListArgs implements IListArgs {
|
|
14
|
-
/** The number of data items to fetch.
|
|
15
|
-
*
|
|
16
|
-
* @defaultValue 40
|
|
17
|
-
* @remarks Must be >= 40 and <= 100
|
|
18
|
-
*/
|
|
19
|
-
@IsInt()
|
|
20
|
-
@IsOptional()
|
|
21
|
-
@Max(100)
|
|
22
|
-
@ValidateIf(ob => ob.cursor.length == 0)
|
|
23
|
-
@Min(40)
|
|
24
|
-
count: number;
|
|
25
|
-
|
|
26
|
-
/** The cursor to the batch of data to fetch. */
|
|
27
|
-
@IsString()
|
|
28
|
-
@IsOptional()
|
|
29
|
-
cursor: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param count The number of data items to fetch.
|
|
33
|
-
* @param cursor The cursor to the batch of data to fetch.
|
|
34
|
-
*/
|
|
35
|
-
constructor(count: number = 40, cursor: string = '') {
|
|
36
|
-
this.count = count;
|
|
37
|
-
this.cursor = cursor;
|
|
38
|
-
|
|
39
|
-
// Validating the arguments
|
|
40
|
-
const validationResult = validateSync(this);
|
|
41
|
-
|
|
42
|
-
// If valiation error occured
|
|
43
|
-
if (validationResult.length) {
|
|
44
|
-
throw new DataValidationError(validationResult);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// TYPES
|
|
2
|
-
import { IAuthCookie } from '../../types/Authentication';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The cookie containing the tokens that are used to authenticate against Twitter.
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export class AuthCookie implements IAuthCookie {
|
|
10
|
-
/** Token used to authenticate a device. */
|
|
11
|
-
kdt: string;
|
|
12
|
-
|
|
13
|
-
/** Token used to authenticate a user using a Twitter ID. */
|
|
14
|
-
twid: string;
|
|
15
|
-
|
|
16
|
-
/** The CSRF token of the session. */
|
|
17
|
-
ct0: string;
|
|
18
|
-
|
|
19
|
-
/** The authentication token used while logging in to the account. */
|
|
20
|
-
auth_token: string;
|
|
21
|
-
|
|
22
|
-
constructor(cookie?: IAuthCookie) {
|
|
23
|
-
this.auth_token = cookie?.auth_token ?? '';
|
|
24
|
-
this.ct0 = cookie?.ct0 ?? '';
|
|
25
|
-
this.kdt = cookie?.kdt ?? '';
|
|
26
|
-
this.twid = cookie?.twid ?? '';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @returns The string respresentation of this cookie in the valid cookie string format.
|
|
31
|
-
*/
|
|
32
|
-
toString(): string {
|
|
33
|
-
/** The string representation of this cookie. */
|
|
34
|
-
let cookieString: string = '';
|
|
35
|
-
|
|
36
|
-
// Iterating through the (key, value) pairs of this cookie
|
|
37
|
-
for (let [key, value] of Object.entries(this)) {
|
|
38
|
-
cookieString += `${key}=${value};`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return cookieString;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// TYPES
|
|
2
|
-
import { ICursor,ICursoredData } from "../../types/Service";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The cursor to the batch of data to be fetched.
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export class Cursor implements ICursor {
|
|
10
|
-
/** The cursor string. */
|
|
11
|
-
value: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Initializes a new cursor from the given cursor string.
|
|
15
|
-
*
|
|
16
|
-
* @param cursorStr The string representation of the cursor.
|
|
17
|
-
*/
|
|
18
|
-
constructor(cursorStr: string) {
|
|
19
|
-
this.value = cursorStr;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The data that us fetched batch-wise along with a cursor.
|
|
25
|
-
*
|
|
26
|
-
* @internal
|
|
27
|
-
*
|
|
28
|
-
* @typeParam Type - The type of data present in the list.
|
|
29
|
-
*/
|
|
30
|
-
export class CursoredData<T> implements ICursoredData<T> {
|
|
31
|
-
/** The list of data of the given type. */
|
|
32
|
-
list: T[];
|
|
33
|
-
|
|
34
|
-
/** The cursor to the next batch of data. */
|
|
35
|
-
next: Cursor;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param list The list of data item to store.
|
|
39
|
-
* @param next The cursor to the next batch of data.
|
|
40
|
-
*/
|
|
41
|
-
constructor(list: T[] = [], next: string = '') {
|
|
42
|
-
this.list = list;
|
|
43
|
-
this.next = new Cursor(next);
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/models/data/Tweet.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// TYPES
|
|
2
|
-
import { ITweet, ITweetEntities } from '../../types/Tweet';
|
|
3
|
-
import { ITweet as IRawTweet, IEntities as IRawTweetEntities } from 'rettiwt-core';
|
|
4
|
-
|
|
5
|
-
// PARSERS
|
|
6
|
-
import * as Parsers from '../../services/helper/Parser';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The different types parsed entities like urls, media, mentions, hashtags, etc.
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export class TweetEntities implements ITweetEntities {
|
|
14
|
-
// MEMBER DATA
|
|
15
|
-
/** The list of hashtags mentioned in the tweet. */
|
|
16
|
-
hashtags: string[] = [];
|
|
17
|
-
|
|
18
|
-
/** The list of urls mentioned in the tweet. */
|
|
19
|
-
urls: string[] = [];
|
|
20
|
-
|
|
21
|
-
/** The list of IDs of users mentioned in the tweet. */
|
|
22
|
-
mentionedUsers: string[] = [];
|
|
23
|
-
|
|
24
|
-
/** The list of urls to various media mentioned in the tweet. */
|
|
25
|
-
media: string[] = [];
|
|
26
|
-
|
|
27
|
-
// MEMBER METHODS
|
|
28
|
-
constructor(entities: IRawTweetEntities) {
|
|
29
|
-
// Extracting user mentions
|
|
30
|
-
if (entities.user_mentions) {
|
|
31
|
-
for (let user of entities.user_mentions) {
|
|
32
|
-
this.mentionedUsers.push(user.id_str);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Extracting urls
|
|
37
|
-
if (entities.urls) {
|
|
38
|
-
for (let url of entities.urls) {
|
|
39
|
-
this.urls.push(url.expanded_url);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Extracting hashtags
|
|
44
|
-
if (entities.hashtags) {
|
|
45
|
-
for (let hashtag of entities.hashtags) {
|
|
46
|
-
this.hashtags.push(hashtag.text);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Extracting media urls (if any)
|
|
51
|
-
if (entities.media) {
|
|
52
|
-
for (const media of entities.media) {
|
|
53
|
-
this.media.push(media.media_url_https);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The details of a single Tweet.
|
|
61
|
-
*
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
export class Tweet implements ITweet {
|
|
65
|
-
/** The rest id of the tweet. */
|
|
66
|
-
id: string;
|
|
67
|
-
|
|
68
|
-
/** The rest id of the user who made the tweet. */
|
|
69
|
-
tweetBy: string;
|
|
70
|
-
|
|
71
|
-
/** The date and time of creation of the tweet, in UTC string format. */
|
|
72
|
-
createdAt: string;
|
|
73
|
-
|
|
74
|
-
/** Additional tweet entities like urls, mentions, etc. */
|
|
75
|
-
entities: TweetEntities;
|
|
76
|
-
|
|
77
|
-
/** The rest id of the tweet which is quoted in the tweet. */
|
|
78
|
-
quoted: string;
|
|
79
|
-
|
|
80
|
-
/** The full text content of the tweet. */
|
|
81
|
-
fullText: string;
|
|
82
|
-
|
|
83
|
-
/** The rest id of the user to which the tweet is a reply. */
|
|
84
|
-
replyTo: string;
|
|
85
|
-
|
|
86
|
-
/** The language in which the tweet is written. */
|
|
87
|
-
lang: string;
|
|
88
|
-
|
|
89
|
-
/** The number of quotes of the tweet. */
|
|
90
|
-
quoteCount: number;
|
|
91
|
-
|
|
92
|
-
/** The number of replies to the tweet. */
|
|
93
|
-
replyCount: number;
|
|
94
|
-
|
|
95
|
-
/** The number of retweets of the tweet. */
|
|
96
|
-
retweetCount: number;
|
|
97
|
-
|
|
98
|
-
/** The number of likes of the tweet. */
|
|
99
|
-
likeCount: number;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @param tweet The raw tweet data.
|
|
103
|
-
*/
|
|
104
|
-
constructor(tweet: IRawTweet) {
|
|
105
|
-
this.id = tweet.rest_id;
|
|
106
|
-
this.createdAt = tweet.legacy.created_at;
|
|
107
|
-
this.tweetBy = tweet.legacy.user_id_str;
|
|
108
|
-
this.entities = new TweetEntities(tweet.legacy.entities);
|
|
109
|
-
this.quoted = tweet.legacy.quoted_status_id_str;
|
|
110
|
-
this.fullText = Parsers.normalizeText(tweet.legacy.full_text);
|
|
111
|
-
this.replyTo = tweet.legacy.in_reply_to_status_id_str;
|
|
112
|
-
this.lang = tweet.legacy.lang;
|
|
113
|
-
this.quoteCount = tweet.legacy.quote_count;
|
|
114
|
-
this.replyCount = tweet.legacy.reply_count;
|
|
115
|
-
this.retweetCount = tweet.legacy.retweet_count;
|
|
116
|
-
this.likeCount = tweet.legacy.favorite_count;
|
|
117
|
-
}
|
|
118
|
-
}
|
package/src/models/data/User.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// TYPES
|
|
2
|
-
import { IUser } from '../../types/User';
|
|
3
|
-
import { IUser as IRawUser } from 'rettiwt-core';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The details of a single user.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export class User implements IUser {
|
|
11
|
-
/** The rest id of the user. */
|
|
12
|
-
id: string;
|
|
13
|
-
|
|
14
|
-
/** The username/screenname of the user. */
|
|
15
|
-
userName: string;
|
|
16
|
-
|
|
17
|
-
/** The full name of the user. */
|
|
18
|
-
fullName: string;
|
|
19
|
-
|
|
20
|
-
/** The creation date of user's account. */
|
|
21
|
-
createdAt: string;
|
|
22
|
-
|
|
23
|
-
/** The user's description. */
|
|
24
|
-
description: string;
|
|
25
|
-
|
|
26
|
-
/** Whether the account is verified or not. */
|
|
27
|
-
isVerified: boolean;
|
|
28
|
-
|
|
29
|
-
/** The number of tweets liked by the user. */
|
|
30
|
-
favouritesCount: number;
|
|
31
|
-
|
|
32
|
-
/** The number of followers of the user. */
|
|
33
|
-
followersCount: number;
|
|
34
|
-
|
|
35
|
-
/** The number of following of the user. */
|
|
36
|
-
followingsCount: number;
|
|
37
|
-
|
|
38
|
-
/** The number of tweets made by the user. */
|
|
39
|
-
statusesCount: number;
|
|
40
|
-
|
|
41
|
-
/** The location of user as provided by user. */
|
|
42
|
-
location: string;
|
|
43
|
-
|
|
44
|
-
/** The rest id of the tweet pinned in the user's profile. */
|
|
45
|
-
pinnedTweet: string;
|
|
46
|
-
|
|
47
|
-
/** The url of the profile banner image. */
|
|
48
|
-
profileBanner: string;
|
|
49
|
-
|
|
50
|
-
/** The url of the profile image. */
|
|
51
|
-
profileImage: string;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @param user The raw user data.
|
|
55
|
-
*/
|
|
56
|
-
constructor(user: IRawUser) {
|
|
57
|
-
this.id = user.rest_id;
|
|
58
|
-
this.userName = user.legacy.screen_name;
|
|
59
|
-
this.fullName = user.legacy.name;
|
|
60
|
-
this.createdAt = user.legacy.created_at;
|
|
61
|
-
this.description = user.legacy.description;
|
|
62
|
-
this.isVerified = user.legacy.verified;
|
|
63
|
-
this.favouritesCount = user.legacy.favourites_count;
|
|
64
|
-
this.followersCount = user.legacy.followers_count;
|
|
65
|
-
this.followingsCount = user.legacy.friends_count;
|
|
66
|
-
this.statusesCount = user.legacy.statuses_count;
|
|
67
|
-
this.location = user.legacy.location;
|
|
68
|
-
this.pinnedTweet = user.legacy.pinned_tweet_ids_str[0];
|
|
69
|
-
this.profileBanner = user.legacy.profile_banner_url;
|
|
70
|
-
this.profileImage = user.legacy.profile_image_url_https;
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/server.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// PACKAGE
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import { graphqlHTTP } from 'express-graphql';
|
|
4
|
-
import { GraphQLSchema } from 'graphql';
|
|
5
|
-
import 'reflect-metadata';
|
|
6
|
-
|
|
7
|
-
// SERVICES
|
|
8
|
-
import { Rettiwt } from '.';
|
|
9
|
-
|
|
10
|
-
// SCHEMA
|
|
11
|
-
import { rootQuery } from './graphql/queries/RootQuery';
|
|
12
|
-
|
|
13
|
-
// CONFIGS
|
|
14
|
-
import { config } from './config/env';
|
|
15
|
-
|
|
16
|
-
// Initialising express instance
|
|
17
|
-
const app = express();
|
|
18
|
-
|
|
19
|
-
// Setting up graphql endpoint
|
|
20
|
-
app.use('/graphql', graphqlHTTP(req => ({
|
|
21
|
-
schema: new GraphQLSchema({
|
|
22
|
-
query: rootQuery
|
|
23
|
-
}),
|
|
24
|
-
context: Rettiwt({
|
|
25
|
-
auth_token: req.headers['auth_token'] as string,
|
|
26
|
-
ct0: req.headers['ct0'] as string,
|
|
27
|
-
kdt: req.headers['kdt'] as string,
|
|
28
|
-
twid: req.headers['twid'] as string,
|
|
29
|
-
}),
|
|
30
|
-
// If app is running in development environment, enable graphiql
|
|
31
|
-
graphiql: config.is_development
|
|
32
|
-
})));
|
|
33
|
-
|
|
34
|
-
// Setting up express server
|
|
35
|
-
app.listen(config.port, async () => {
|
|
36
|
-
console.log(`Listening on port ${config.port}`);
|
|
37
|
-
});
|