fxtwitter 0.0.0-reserved → 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/dist/v2.mjs ADDED
@@ -0,0 +1,181 @@
1
+ import { n as FxTwitterError, t as HttpClient } from "./http-BTdKgEdX.mjs";
2
+ //#region src/v2.ts
3
+ /** Builds the `id:<rest_id>` handle form accepted by the profile endpoints. */
4
+ function byUserId(id) {
5
+ return `id:${id}`;
6
+ }
7
+ /**
8
+ * Recovers the body of a 404 that carries a well-formed, empty result page,
9
+ * which is how the list endpoints report "no results or timeline unavailable".
10
+ */
11
+ function emptyPage(error) {
12
+ if (!(error instanceof FxTwitterError) || error.status !== 404) return null;
13
+ const body = error.body;
14
+ if (typeof body !== "object" || body === null) return null;
15
+ const results = body.results;
16
+ return Array.isArray(results) ? body : null;
17
+ }
18
+ /** Client for the FxTwitter/FxEmbed v2 API (https://docs.fxembed.com/api/twitter/). */
19
+ var FxTwitterV2 = class {
20
+ http;
21
+ constructor(options = {}) {
22
+ this.http = new HttpClient(options);
23
+ }
24
+ /** Only `/2/profile/{handle}/statuses` can answer 204, so everything else demands a body. */
25
+ async get(path, query, signal) {
26
+ const body = await this.http.get({
27
+ path,
28
+ query,
29
+ signal
30
+ });
31
+ if (body === null) throw new FxTwitterError("The API returned an empty response");
32
+ return body;
33
+ }
34
+ /**
35
+ * Same as {@link get}, for the endpoints that report "no results" as a 404
36
+ * carrying an otherwise normal body. An empty page is a result, not an
37
+ * error, so it is returned rather than thrown.
38
+ *
39
+ * The API uses that same 404 for an unknown handle, which it does not
40
+ * distinguish from an empty timeline.
41
+ */
42
+ async getPage(path, query, signal) {
43
+ try {
44
+ return await this.get(path, query, signal);
45
+ } catch (error) {
46
+ const page = emptyPage(error);
47
+ if (page) return page;
48
+ throw error;
49
+ }
50
+ }
51
+ /** `GET /2/status/{id}` — a single post by snowflake ID. */
52
+ getStatus(id, options = {}) {
53
+ return this.get(`/2/status/${encodeURIComponent(id)}`, {
54
+ about_account: options.aboutAccount ? "1" : void 0,
55
+ lang: options.lang
56
+ }, options.signal);
57
+ }
58
+ /** `GET /2/status/{id}/reposts` — users who reposted a post. */
59
+ getStatusReposts(id, options = {}) {
60
+ return this.getPage(`/2/status/${encodeURIComponent(id)}/reposts`, {
61
+ count: options.count,
62
+ cursor: options.cursor
63
+ }, options.signal);
64
+ }
65
+ /** `GET /2/status/{id}/quotes` — posts quoting a post. */
66
+ getStatusQuotes(id, options = {}) {
67
+ return this.getPage(`/2/status/${encodeURIComponent(id)}/quotes`, {
68
+ count: options.count,
69
+ cursor: options.cursor,
70
+ lang: options.lang
71
+ }, options.signal);
72
+ }
73
+ /** `GET /2/thread/{id}` — a post with its unrolled thread. */
74
+ getThread(id, options = {}) {
75
+ return this.get(`/2/thread/${encodeURIComponent(id)}`, {
76
+ about_account: options.aboutAccount ? "1" : void 0,
77
+ lang: options.lang
78
+ }, options.signal);
79
+ }
80
+ /** `GET /2/conversation/{id}` — a post, its thread, and ranked replies. */
81
+ getConversation(id, options = {}) {
82
+ return this.get(`/2/conversation/${encodeURIComponent(id)}`, {
83
+ ranking_mode: options.rankingMode,
84
+ cursor: options.cursor,
85
+ about_account: options.aboutAccount ? "1" : void 0,
86
+ lang: options.lang
87
+ }, options.signal);
88
+ }
89
+ /**
90
+ * `GET /2/profile/{handle}` — a user's profile. `handle` is a username
91
+ * without `@`, or `byUserId(id)` for a numeric user ID.
92
+ */
93
+ getProfile(handle, options = {}) {
94
+ return this.get(`/2/profile/${encodeURIComponent(handle)}`, { about_account: options.aboutAccount ? "1" : void 0 }, options.signal);
95
+ }
96
+ /**
97
+ * `GET /2/profile/{handle}/statuses` — a user's posts. Resolves to `null`
98
+ * when `since` is set (without `cursor`) and nothing is newer than it.
99
+ */
100
+ async getProfileStatuses(handle, options = {}) {
101
+ try {
102
+ return await this.http.get({
103
+ path: `/2/profile/${encodeURIComponent(handle)}/statuses`,
104
+ query: {
105
+ count: options.count,
106
+ cursor: options.cursor,
107
+ since: options.since,
108
+ with_replies: options.withReplies ? "1" : void 0,
109
+ groupthreads: options.groupThreads ? "1" : void 0,
110
+ lang: options.lang
111
+ },
112
+ signal: options.signal
113
+ });
114
+ } catch (error) {
115
+ const page = emptyPage(error);
116
+ if (page) return page;
117
+ throw error;
118
+ }
119
+ }
120
+ /** `GET /2/profile/{handle}/articles` — a user's long-form articles. */
121
+ getProfileArticles(handle, options = {}) {
122
+ return this.getPage(`/2/profile/${encodeURIComponent(handle)}/articles`, {
123
+ count: options.count,
124
+ cursor: options.cursor,
125
+ lang: options.lang
126
+ }, options.signal);
127
+ }
128
+ /** `GET /2/profile/{handle}/about` — account metadata (based-in country, name changes). */
129
+ getProfileAbout(handle, options = {}) {
130
+ return this.get(`/2/profile/${encodeURIComponent(handle)}/about`, void 0, options.signal);
131
+ }
132
+ /** `GET /2/profile/{handle}/media` — a user's posts that contain media. */
133
+ getProfileMedia(handle, options = {}) {
134
+ return this.getPage(`/2/profile/${encodeURIComponent(handle)}/media`, {
135
+ count: options.count,
136
+ cursor: options.cursor,
137
+ lang: options.lang
138
+ }, options.signal);
139
+ }
140
+ /** `GET /2/profile/{handle}/followers` — a user's followers. */
141
+ getProfileFollowers(handle, options = {}) {
142
+ return this.getPage(`/2/profile/${encodeURIComponent(handle)}/followers`, {
143
+ count: options.count,
144
+ cursor: options.cursor
145
+ }, options.signal);
146
+ }
147
+ /** `GET /2/profile/{handle}/following` — accounts a user follows. */
148
+ getProfileFollowing(handle, options = {}) {
149
+ return this.getPage(`/2/profile/${encodeURIComponent(handle)}/following`, {
150
+ count: options.count,
151
+ cursor: options.cursor
152
+ }, options.signal);
153
+ }
154
+ /** `GET /2/search` — search posts. */
155
+ search(query, options = {}) {
156
+ return this.getPage("/2/search", {
157
+ q: query,
158
+ feed: options.feed,
159
+ count: options.count,
160
+ cursor: options.cursor,
161
+ lang: options.lang
162
+ }, options.signal);
163
+ }
164
+ /** `GET /2/typeahead` — search-box autocomplete suggestions. */
165
+ typeahead(query, options = {}) {
166
+ return this.get("/2/typeahead", {
167
+ q: query,
168
+ result_type: options.resultType?.join(","),
169
+ src: options.src
170
+ }, options.signal);
171
+ }
172
+ /** `GET /2/trends` — trending topics. */
173
+ trends(options = {}) {
174
+ return this.get("/2/trends", {
175
+ type: "trending",
176
+ count: options.count
177
+ }, options.signal);
178
+ }
179
+ };
180
+ //#endregion
181
+ export { FxTwitterV2, byUserId };
package/package.json CHANGED
@@ -1,19 +1,92 @@
1
1
  {
2
2
  "name": "fxtwitter",
3
- "version": "0.0.0-reserved",
4
- "main": "index.js",
5
- "scripts": {
6
- "help": "node scripts/main.js --help",
7
- "reserve": "node scripts/main.js"
3
+ "version": "2.0.0",
4
+ "description": "Typed wrapper for the FxTwitter API.",
5
+ "keywords": [
6
+ "x",
7
+ "twitter",
8
+ "fxtwitter",
9
+ "wrapper",
10
+ "api"
11
+ ],
12
+ "homepage": "https://github.com/otnc/fxtwitter-wrapper#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/otnc/fxtwitter-wrapper/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/otnc/fxtwitter-wrapper.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "otoneko.",
22
+ "type": "module",
23
+ "main": "dist/index.cjs",
24
+ "module": "dist/index.mjs",
25
+ "types": "dist/index.d.mts",
26
+ "exports": {
27
+ ".": {
28
+ "types": {
29
+ "import": "./dist/index.d.mts",
30
+ "require": "./dist/index.d.cts"
31
+ },
32
+ "import": "./dist/index.mjs",
33
+ "require": "./dist/index.cjs"
34
+ },
35
+ "./v1": {
36
+ "types": {
37
+ "import": "./dist/v1.d.mts",
38
+ "require": "./dist/v1.d.cts"
39
+ },
40
+ "import": "./dist/v1.mjs",
41
+ "require": "./dist/v1.cjs"
42
+ },
43
+ "./v2": {
44
+ "types": {
45
+ "import": "./dist/v2.d.mts",
46
+ "require": "./dist/v2.d.cts"
47
+ },
48
+ "import": "./dist/v2.mjs",
49
+ "require": "./dist/v2.cjs"
50
+ },
51
+ "./package.json": "./package.json"
8
52
  },
9
53
  "files": [
10
- "index.js"
54
+ "dist"
11
55
  ],
12
- "keywords": [],
13
- "author": "otoneko.",
14
- "description": "[Reserved]",
56
+ "engines": {
57
+ "node": ">=22"
58
+ },
59
+ "scripts": {
60
+ "setup": "node scripts/setup.js",
61
+ "build": "tsdown",
62
+ "test": "vitest run",
63
+ "test:watch": "vitest",
64
+ "test:coverage": "vitest run --coverage",
65
+ "typecheck": "tsc --noEmit",
66
+ "format": "prettier --write .",
67
+ "format:check": "prettier --check .",
68
+ "lint": "eslint .",
69
+ "lint:fix": "eslint --fix .",
70
+ "check": "prettier --write . && eslint --fix .",
71
+ "ci": "prettier --check . && eslint .",
72
+ "prepublishOnly": "npm run build"
73
+ },
74
+ "dependencies": {
75
+ "defu": "^6.1.7",
76
+ "ofetch": "^1.5.1",
77
+ "std-env": "^4.2.0"
78
+ },
15
79
  "devDependencies": {
16
- "consola": "^3.4.2",
17
- "dotenv": "^17.3.1"
80
+ "@eslint/js": "^10.0.1",
81
+ "@types/node": "^22.20.1",
82
+ "@vitest/coverage-v8": "^4.1.10",
83
+ "eslint": "^10.8.0",
84
+ "eslint-config-prettier": "^10.1.8",
85
+ "globals": "^17.8.0",
86
+ "prettier": "^3.9.6",
87
+ "tsdown": "^0.22.14",
88
+ "typescript": "^6.0.3",
89
+ "typescript-eslint": "^8.65.0",
90
+ "vitest": "^4.1.10"
18
91
  }
19
- }
92
+ }
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = console.log("fxtwitter is reserved for otoneko.");