twitter-openapi-typescript 0.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/.prettierrc +8 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/settings.json +5 -0
- package/dist/src/api.d.ts +30 -0
- package/dist/src/api.js +145 -0
- package/dist/src/apis/defaultApi.d.ts +17 -0
- package/dist/src/apis/defaultApi.js +106 -0
- package/dist/src/apis/index.d.ts +9 -0
- package/dist/src/apis/index.js +21 -0
- package/dist/src/apis/initialStateApi.d.ts +2 -0
- package/dist/src/apis/initialStateApi.js +9 -0
- package/dist/src/apis/postApi.d.ts +51 -0
- package/dist/src/apis/postApi.js +236 -0
- package/dist/src/apis/tweetApi.d.ts +88 -0
- package/dist/src/apis/tweetApi.js +277 -0
- package/dist/src/apis/userApi.d.ts +17 -0
- package/dist/src/apis/userApi.js +101 -0
- package/dist/src/apis/userListApi.d.ts +28 -0
- package/dist/src/apis/userListApi.js +135 -0
- package/dist/src/apis/v11GetApi.d.ts +7 -0
- package/dist/src/apis/v11GetApi.js +11 -0
- package/dist/src/apis/v11PostApi.d.ts +22 -0
- package/dist/src/apis/v11PostApi.js +93 -0
- package/dist/src/apis/v20GetApi.d.ts +7 -0
- package/dist/src/apis/v20GetApi.js +11 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +20 -0
- package/dist/src/models/api.d.ts +17 -0
- package/dist/src/models/api.js +130 -0
- package/dist/src/models/index.d.ts +2 -0
- package/dist/src/models/index.js +18 -0
- package/dist/src/models/type.d.ts +15 -0
- package/dist/src/models/type.js +2 -0
- package/dist/src/types/flag.d.ts +5 -0
- package/dist/src/types/flag.js +2 -0
- package/dist/src/types/header.d.ts +14 -0
- package/dist/src/types/header.js +2 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.js +23 -0
- package/dist/src/types/response.d.ts +9 -0
- package/dist/src/types/response.js +2 -0
- package/dist/src/types/timeline.d.ts +10 -0
- package/dist/src/types/timeline.js +2 -0
- package/dist/src/types/tweet.d.ts +17 -0
- package/dist/src/types/tweet.js +2 -0
- package/dist/src/types/user.d.ts +10 -0
- package/dist/src/types/user.js +2 -0
- package/dist/src/types/user_list.d.ts +12 -0
- package/dist/src/types/user_list.js +2 -0
- package/jest.config.js +14 -0
- package/package.json +44 -0
- package/src/api.ts +118 -0
- package/src/apis/defaultApi.ts +51 -0
- package/src/apis/index.ts +9 -0
- package/src/apis/initialStateApi.ts +3 -0
- package/src/apis/postApi.ts +169 -0
- package/src/apis/tweetApi.ts +244 -0
- package/src/apis/userApi.ts +47 -0
- package/src/apis/userListApi.ts +90 -0
- package/src/apis/v11GetApi.ts +12 -0
- package/src/apis/v11PostApi.ts +73 -0
- package/src/apis/v20GetApi.ts +12 -0
- package/src/index.ts +4 -0
- package/src/models/api.ts +129 -0
- package/src/models/index.ts +2 -0
- package/src/models/type.ts +16 -0
- package/src/types/flag.ts +5 -0
- package/src/types/header.ts +14 -0
- package/src/types/index.ts +7 -0
- package/src/types/response.ts +11 -0
- package/src/types/timeline.ts +12 -0
- package/src/types/tweet.ts +19 -0
- package/src/types/user.ts +12 -0
- package/src/types/user_list.ts +14 -0
- package/test/api/defaultApi.test.ts +13 -0
- package/test/api/postApi.test.ts +50 -0
- package/test/api/tweetApi.test.ts +74 -0
- package/test/api/userApi.test.ts +13 -0
- package/test/api/userListApi.test.ts +18 -0
- package/test/api/v11PostApi.test.ts +13 -0
- package/test/init.ts +39 -0
- package/test/raw/tweet_api.test.ts +12 -0
- package/test/util.ts +18 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { DefaultFlag, TwitterApiUtilsResponse } from '../types';
|
|
3
|
+
type PostCreateFriendshipsParam = {
|
|
4
|
+
userId: string;
|
|
5
|
+
extraParam?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type PostDestroyFriendshipsParam = {
|
|
10
|
+
userId: string;
|
|
11
|
+
extraParam?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare class V11PostApiUtils {
|
|
16
|
+
api: i.V11PostApi;
|
|
17
|
+
flag: DefaultFlag;
|
|
18
|
+
constructor(api: i.V11PostApi, flag: DefaultFlag);
|
|
19
|
+
postCreateFriendships(param: PostCreateFriendshipsParam): Promise<TwitterApiUtilsResponse<undefined>>;
|
|
20
|
+
postDestroyFriendships(param: PostDestroyFriendshipsParam): Promise<TwitterApiUtilsResponse<undefined>>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.V11PostApiUtils = void 0;
|
|
51
|
+
var models_1 = require("../models");
|
|
52
|
+
var V11PostApiUtils = /** @class */ (function () {
|
|
53
|
+
function V11PostApiUtils(api, flag) {
|
|
54
|
+
this.api = api;
|
|
55
|
+
this.flag = flag;
|
|
56
|
+
}
|
|
57
|
+
V11PostApiUtils.prototype.postCreateFriendships = function (param) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var response;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0: return [4 /*yield*/, this.api.postCreateFriendshipsRaw(__assign({ includeBlockedBy: 1, includeBlocking: 1, includeCanDm: 1, includeCanMediaTag: 1, includeExtHasNftAvatar: 1, includeExtIsBlueVerified: 1, includeExtProfileImageShape: 1, includeExtVerifiedType: 1, includeFollowedBy: 1, includeMuteEdge: 1, includeProfileInterstitialType: 1, includeWantRetweets: 1, skipStatus: 1, userId: param.userId }, param.extraParam))];
|
|
63
|
+
case 1:
|
|
64
|
+
response = _a.sent();
|
|
65
|
+
return [2 /*return*/, {
|
|
66
|
+
raw: { response: response.raw },
|
|
67
|
+
header: (0, models_1.buildHeader)(response.raw.headers),
|
|
68
|
+
data: undefined,
|
|
69
|
+
}];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
V11PostApiUtils.prototype.postDestroyFriendships = function (param) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var response;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0: return [4 /*yield*/, this.api.postDestroyFriendshipsRaw(__assign({ includeBlockedBy: 0, includeBlocking: 0, includeCanDm: 0, includeCanMediaTag: 0, includeExtHasNftAvatar: 0, includeExtIsBlueVerified: 0, includeExtProfileImageShape: 0, includeExtVerifiedType: 0, includeFollowedBy: 0, includeMuteEdge: 0, includeProfileInterstitialType: 0, includeWantRetweets: 0, skipStatus: 0, userId: param.userId }, param.extraParam))];
|
|
80
|
+
case 1:
|
|
81
|
+
response = _a.sent();
|
|
82
|
+
return [2 /*return*/, {
|
|
83
|
+
raw: { response: response.raw },
|
|
84
|
+
header: (0, models_1.buildHeader)(response.raw.headers),
|
|
85
|
+
data: undefined,
|
|
86
|
+
}];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
return V11PostApiUtils;
|
|
92
|
+
}());
|
|
93
|
+
exports.V11PostApiUtils = V11PostApiUtils;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.V20GetApiUtils = void 0;
|
|
4
|
+
var V20GetApiUtils = /** @class */ (function () {
|
|
5
|
+
function V20GetApiUtils(api, flag) {
|
|
6
|
+
this.api = api;
|
|
7
|
+
this.flag = flag;
|
|
8
|
+
}
|
|
9
|
+
return V20GetApiUtils;
|
|
10
|
+
}());
|
|
11
|
+
exports.V20GetApiUtils = V20GetApiUtils;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./apis"), exports);
|
|
18
|
+
__exportStar(require("./models"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./api"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { TweetApiUtilsData, UserApiUtilsData, CursorApiUtilsResponse, ApiUtilsHeader } from '../types';
|
|
3
|
+
export declare const instructionToEntry: (item: i.InstructionUnion[]) => i.TimelineAddEntry[];
|
|
4
|
+
export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[]) => TweetApiUtilsData[];
|
|
5
|
+
type buildTweetApiUtilsArgs = {
|
|
6
|
+
result: i.ItemResult;
|
|
7
|
+
promotedMetadata?: any;
|
|
8
|
+
reply?: i.TimelineTweet[];
|
|
9
|
+
};
|
|
10
|
+
export declare const buildTweetApiUtils: (args: buildTweetApiUtilsArgs) => TweetApiUtilsData | undefined;
|
|
11
|
+
export declare const tweetResultsConverter: (tweetResults: i.ItemResult) => i.Tweet | undefined;
|
|
12
|
+
export declare const userEntriesConverter: (item: i.TimelineAddEntry[]) => i.TimelineUser[];
|
|
13
|
+
export declare const buildUserResponse: (user: i.TimelineUser) => UserApiUtilsData;
|
|
14
|
+
export declare const entriesCursor: (item: i.TimelineAddEntry[]) => CursorApiUtilsResponse;
|
|
15
|
+
export declare const buildCursor: (cursorList: i.TimelineTimelineCursor[]) => CursorApiUtilsResponse;
|
|
16
|
+
export declare const buildHeader: (headers: Headers) => ApiUtilsHeader;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildHeader = exports.buildCursor = exports.entriesCursor = exports.buildUserResponse = exports.userEntriesConverter = exports.tweetResultsConverter = exports.buildTweetApiUtils = exports.tweetEntriesConverter = exports.instructionToEntry = void 0;
|
|
4
|
+
var i = require("twitter-openapi-typescript-generated");
|
|
5
|
+
var instructionToEntry = function (item) {
|
|
6
|
+
return item
|
|
7
|
+
.map(function (e) { return (e.type == i.InstructionType.TimelineAddEntries ? e : null); })
|
|
8
|
+
.find(function (e) { return e; }).entries;
|
|
9
|
+
};
|
|
10
|
+
exports.instructionToEntry = instructionToEntry;
|
|
11
|
+
var tweetEntriesConverter = function (item) {
|
|
12
|
+
return item
|
|
13
|
+
.map(function (e) {
|
|
14
|
+
var _a;
|
|
15
|
+
if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
|
|
16
|
+
var item_1 = e.content.itemContent;
|
|
17
|
+
var timeline = item_1.itemType == i.ContentItemType.TimelineTweet ? item_1 : null;
|
|
18
|
+
if (timeline == null)
|
|
19
|
+
return null;
|
|
20
|
+
return (0, exports.buildTweetApiUtils)({
|
|
21
|
+
result: timeline.tweetResults,
|
|
22
|
+
promotedMetadata: timeline.promotedMetadata,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else if (e.content.entryType == i.ContentEntryType.TimelineTimelineModule) {
|
|
26
|
+
var item_2 = (_a = e.content.items) !== null && _a !== void 0 ? _a : [];
|
|
27
|
+
var timelineList = item_2
|
|
28
|
+
.filter(function (e) { return e.item.itemContent.itemType == i.ContentItemType.TimelineTweet; })
|
|
29
|
+
.map(function (e) { return e.item.itemContent; });
|
|
30
|
+
if (timelineList.length == 0)
|
|
31
|
+
return null;
|
|
32
|
+
var timeline = timelineList[0];
|
|
33
|
+
return (0, exports.buildTweetApiUtils)({
|
|
34
|
+
result: timeline.tweetResults,
|
|
35
|
+
promotedMetadata: timeline.promotedMetadata,
|
|
36
|
+
reply: timelineList.slice(1),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.filter(function (e) { return e != null; });
|
|
41
|
+
};
|
|
42
|
+
exports.tweetEntriesConverter = tweetEntriesConverter;
|
|
43
|
+
var buildTweetApiUtils = function (args) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
var tweet = (0, exports.tweetResultsConverter)(args.result);
|
|
46
|
+
if (tweet == null)
|
|
47
|
+
return undefined;
|
|
48
|
+
var quoted = tweet.quotedStatusResult;
|
|
49
|
+
var retweeted = tweet.legacy.retweetedStatusResult;
|
|
50
|
+
return {
|
|
51
|
+
raw: args.result,
|
|
52
|
+
promotedMetadata: args.promotedMetadata,
|
|
53
|
+
tweet: tweet,
|
|
54
|
+
user: tweet.core.userResults.result,
|
|
55
|
+
reply: (_b = (_a = args.reply) === null || _a === void 0 ? void 0 : _a.map(function (e) { return (0, exports.buildTweetApiUtils)({ result: e.tweetResults, promotedMetadata: e.promotedMetadata }); }).filter(function (e) { return e != null; })) !== null && _b !== void 0 ? _b : [],
|
|
56
|
+
quoted: quoted == undefined ? undefined : (0, exports.buildTweetApiUtils)({ result: quoted }),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.buildTweetApiUtils = buildTweetApiUtils;
|
|
60
|
+
var tweetResultsConverter = function (tweetResults) {
|
|
61
|
+
switch (tweetResults.result.typename) {
|
|
62
|
+
case i.TypeName.Tweet:
|
|
63
|
+
return tweetResults.result;
|
|
64
|
+
case i.TypeName.TweetWithVisibilityResults:
|
|
65
|
+
return tweetResults.result.tweet;
|
|
66
|
+
case i.TypeName.TweetTombstone:
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
throw Error();
|
|
70
|
+
};
|
|
71
|
+
exports.tweetResultsConverter = tweetResultsConverter;
|
|
72
|
+
var userEntriesConverter = function (item) {
|
|
73
|
+
return item
|
|
74
|
+
.map(function (e) {
|
|
75
|
+
if (e.content.typename == i.TypeName.TimelineTimelineItem) {
|
|
76
|
+
var item_3 = e.content.itemContent;
|
|
77
|
+
return item_3.itemType == i.ContentItemType.TimelineUser ? item_3 : null;
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.filter(function (e) { return e != null; });
|
|
81
|
+
};
|
|
82
|
+
exports.userEntriesConverter = userEntriesConverter;
|
|
83
|
+
var buildUserResponse = function (user) {
|
|
84
|
+
return {
|
|
85
|
+
raw: user,
|
|
86
|
+
user: user.userResults.result,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.buildUserResponse = buildUserResponse;
|
|
90
|
+
var entriesCursor = function (item) {
|
|
91
|
+
var cursorList = item
|
|
92
|
+
.map(function (e) {
|
|
93
|
+
if (e.content.entryType == i.ContentEntryType.TimelineTimelineCursor) {
|
|
94
|
+
return e.content;
|
|
95
|
+
}
|
|
96
|
+
else if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
|
|
97
|
+
var item_4 = e.content;
|
|
98
|
+
if (item_4.itemContent.itemType == i.ContentItemType.TimelineTimelineCursor) {
|
|
99
|
+
return item_4.itemContent;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
.filter(function (e) { return e != null; });
|
|
104
|
+
return (0, exports.buildCursor)(cursorList);
|
|
105
|
+
};
|
|
106
|
+
exports.entriesCursor = entriesCursor;
|
|
107
|
+
var buildCursor = function (cursorList) {
|
|
108
|
+
return {
|
|
109
|
+
top: cursorList.find(function (e) { return e.cursorType == i.TimelineTimelineCursorCursorTypeEnum.Top; }),
|
|
110
|
+
bottom: cursorList.find(function (e) { return e.cursorType == i.TimelineTimelineCursorCursorTypeEnum.Bottom; }),
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
exports.buildCursor = buildCursor;
|
|
114
|
+
var buildHeader = function (headers) {
|
|
115
|
+
return {
|
|
116
|
+
raw: headers,
|
|
117
|
+
connectionHash: headers.get('x-connection-hash'),
|
|
118
|
+
contentTypeOptions: headers.get('x-content-type-options'),
|
|
119
|
+
frameOptions: headers.get('x-frame-options'),
|
|
120
|
+
rateLimitLimit: Number(headers.get('x-rate-limit-limit')),
|
|
121
|
+
rateLimitRemaining: Number(headers.get('x-rate-limit-remaining')),
|
|
122
|
+
rateLimitReset: Number(headers.get('x-rate-limit-reset')),
|
|
123
|
+
responseTime: Number(headers.get('x-response-time')),
|
|
124
|
+
tfePreserveBody: headers.get('x-tfe-preserve-body') == 'true',
|
|
125
|
+
transactionId: headers.get('x-transaction-id'),
|
|
126
|
+
twitterResponseTags: headers.get('x-twitter-response-tags'),
|
|
127
|
+
xssProtection: Number(headers.get('x-xss-protection')),
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
exports.buildHeader = buildHeader;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api"), exports);
|
|
18
|
+
__exportStar(require("./type"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
export type ApiFunction<T> = (requestParameters: {
|
|
3
|
+
queryId: string;
|
|
4
|
+
variables: string;
|
|
5
|
+
features: string;
|
|
6
|
+
}) => Promise<i.ApiResponse<T>>;
|
|
7
|
+
export type RequestParam<T1, T2> = {
|
|
8
|
+
apiFn: ApiFunction<T2>;
|
|
9
|
+
convertFn: ConvertFunction<T1, T2>;
|
|
10
|
+
key: string;
|
|
11
|
+
param: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type ConvertFunction<T1, T2> = (arg0: T2) => T1;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ApiUtilsHeader = {
|
|
2
|
+
raw: Headers;
|
|
3
|
+
connectionHash: string | null;
|
|
4
|
+
contentTypeOptions: string | null;
|
|
5
|
+
frameOptions: string | null;
|
|
6
|
+
rateLimitLimit: number;
|
|
7
|
+
rateLimitRemaining: number;
|
|
8
|
+
rateLimitReset: number;
|
|
9
|
+
responseTime: number;
|
|
10
|
+
tfePreserveBody: boolean;
|
|
11
|
+
transactionId: string | null;
|
|
12
|
+
twitterResponseTags: string | null;
|
|
13
|
+
xssProtection: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./flag"), exports);
|
|
18
|
+
__exportStar(require("./header"), exports);
|
|
19
|
+
__exportStar(require("./timeline"), exports);
|
|
20
|
+
__exportStar(require("./tweet"), exports);
|
|
21
|
+
__exportStar(require("./user_list"), exports);
|
|
22
|
+
__exportStar(require("./user"), exports);
|
|
23
|
+
__exportStar(require("./response"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
export type CursorApiUtilsResponse = {
|
|
3
|
+
bottom?: i.TimelineTimelineCursor;
|
|
4
|
+
top?: i.TimelineTimelineCursor;
|
|
5
|
+
};
|
|
6
|
+
export type ApiUtilsRaw = {
|
|
7
|
+
response: Response;
|
|
8
|
+
instruction: i.InstructionUnion[];
|
|
9
|
+
entry: i.TimelineAddEntry[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { CursorApiUtilsResponse, ApiUtilsRaw, ApiUtilsHeader } from './';
|
|
3
|
+
export type TweetListApiUtilsResponse = {
|
|
4
|
+
raw: ApiUtilsRaw;
|
|
5
|
+
header: ApiUtilsHeader;
|
|
6
|
+
cursor: CursorApiUtilsResponse;
|
|
7
|
+
data: TweetApiUtilsData[];
|
|
8
|
+
};
|
|
9
|
+
export type TweetApiUtilsData = {
|
|
10
|
+
raw: i.ItemResult;
|
|
11
|
+
tweet: i.Tweet;
|
|
12
|
+
user: i.User;
|
|
13
|
+
reply: TweetApiUtilsData[];
|
|
14
|
+
quoted?: TweetApiUtilsData;
|
|
15
|
+
retweeted?: TweetApiUtilsData;
|
|
16
|
+
promotedMetadata?: any;
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { ApiUtilsHeader } from './';
|
|
3
|
+
export type UserApiUtilsResponse = {
|
|
4
|
+
raw: UserApiUtilsRaw;
|
|
5
|
+
header: ApiUtilsHeader;
|
|
6
|
+
data: i.User;
|
|
7
|
+
};
|
|
8
|
+
export type UserApiUtilsRaw = {
|
|
9
|
+
response: Response;
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as i from 'twitter-openapi-typescript-generated';
|
|
2
|
+
import { ApiUtilsRaw, CursorApiUtilsResponse, ApiUtilsHeader } from './';
|
|
3
|
+
export type UserListApiUtilsResponse = {
|
|
4
|
+
raw: ApiUtilsRaw;
|
|
5
|
+
header: ApiUtilsHeader;
|
|
6
|
+
cursor: CursorApiUtilsResponse;
|
|
7
|
+
data: UserApiUtilsData[];
|
|
8
|
+
};
|
|
9
|
+
export type UserApiUtilsData = {
|
|
10
|
+
raw: i.TimelineUser;
|
|
11
|
+
user: i.User;
|
|
12
|
+
};
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
globals: {
|
|
6
|
+
"ts-jest": {
|
|
7
|
+
tsconfig: "<rootDir>/tsconfig.json",
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
"^@/(.*)$": "<rootDir>/src/$1",
|
|
12
|
+
"^@test/(.*)$": "<rootDir>/test/$1",
|
|
13
|
+
},
|
|
14
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "twitter-openapi-typescript",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Implementation of Twitter internal API in TypeScript",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "jest",
|
|
7
|
+
"build": "tsc -p tsconfig.build.json && npx tscpaths -p tsconfig.build.json -s . -o ./dist",
|
|
8
|
+
"prepare": "npm run build"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"twitter",
|
|
12
|
+
"api",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"author": "fa0311",
|
|
16
|
+
"license": "LGPL-3.0-only",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/fa0311/twitter-openapi-typescript.git"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/src/index.js",
|
|
22
|
+
"typings": "./dist/src/index.d.ts",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"twitter-openapi-typescript-generated": "^0.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^28.0.0",
|
|
28
|
+
"@types/node": "^20.2.0",
|
|
29
|
+
"@types/node-fetch": "^2.0.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
31
|
+
"@typescript-eslint/parser": "^5.53.0",
|
|
32
|
+
"dotenv": "^16.0.0",
|
|
33
|
+
"eslint": "^8.0.0",
|
|
34
|
+
"eslint-config-standard-with-typescript": "^34.0.0",
|
|
35
|
+
"eslint-plugin-import": "^2.25.0",
|
|
36
|
+
"eslint-plugin-n": "^15.0.0",
|
|
37
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
38
|
+
"jest": "^28.0.0",
|
|
39
|
+
"log4js": "^6.9.1",
|
|
40
|
+
"node-fetch": "^2.0.0",
|
|
41
|
+
"ts-jest": "^28.0.0",
|
|
42
|
+
"typescript": "^4.0"
|
|
43
|
+
}
|
|
44
|
+
}
|