@spectratools/xapi-cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +32 -15
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -10,26 +10,38 @@ import { Cli, z as z2 } from "incur";
10
10
 
11
11
  // src/api.ts
12
12
  import { createHttpClient, withRetry } from "@spectratools/cli-shared";
13
- var BASE_URL = "https://api.x.com/2";
13
+ var BASE_URL_V2 = "https://api.x.com/2";
14
+ var BASE_URL_V1_1 = "https://api.x.com/1.1";
14
15
  var RETRY_OPTIONS = { maxRetries: 3, baseMs: 500, maxMs: 1e4 };
15
16
  function createXApiClient(bearerToken) {
16
- const http = createHttpClient({
17
- baseUrl: BASE_URL,
18
- defaultHeaders: {
19
- Authorization: `Bearer ${bearerToken}`
20
- }
17
+ const defaultHeaders = {
18
+ Authorization: `Bearer ${bearerToken}`
19
+ };
20
+ const httpV2 = createHttpClient({
21
+ baseUrl: BASE_URL_V2,
22
+ defaultHeaders
23
+ });
24
+ const httpV1_1 = createHttpClient({
25
+ baseUrl: BASE_URL_V1_1,
26
+ defaultHeaders
21
27
  });
22
28
  function get(path, query) {
23
29
  return withRetry(
24
- () => http.request(path, query !== void 0 ? { query } : {}),
30
+ () => httpV2.request(path, query !== void 0 ? { query } : {}),
31
+ RETRY_OPTIONS
32
+ );
33
+ }
34
+ function getV1_1(path, query) {
35
+ return withRetry(
36
+ () => httpV1_1.request(path, query !== void 0 ? { query } : {}),
25
37
  RETRY_OPTIONS
26
38
  );
27
39
  }
28
40
  function post(path, body) {
29
- return withRetry(() => http.request(path, { method: "POST", body }), RETRY_OPTIONS);
41
+ return withRetry(() => httpV2.request(path, { method: "POST", body }), RETRY_OPTIONS);
30
42
  }
31
43
  function del(path) {
32
- return withRetry(() => http.request(path, { method: "DELETE" }), RETRY_OPTIONS);
44
+ return withRetry(() => httpV2.request(path, { method: "DELETE" }), RETRY_OPTIONS);
33
45
  }
34
46
  const POST_FIELDS = "id,text,author_id,created_at,public_metrics";
35
47
  function getPost(id) {
@@ -148,14 +160,19 @@ function createXApiClient(bearerToken) {
148
160
  });
149
161
  }
150
162
  function getTrendingPlaces() {
151
- return get(
152
- "/trends/available"
153
- );
163
+ return getV1_1(
164
+ "/trends/available.json"
165
+ ).then((places) => ({ data: places }));
154
166
  }
155
167
  function getTrendsByLocation(woeid) {
156
- return get(
157
- `/trends/place/${woeid}`
158
- );
168
+ return getV1_1("/trends/place.json", { id: woeid }).then((locations) => {
169
+ const trends2 = (locations[0]?.trends ?? []).map((trend) => ({
170
+ name: trend.name,
171
+ query: trend.query,
172
+ tweet_volume: trend.tweet_volume ?? void 0
173
+ }));
174
+ return { data: trends2 };
175
+ });
159
176
  }
160
177
  function getDmConversations(userId, maxResults, nextToken) {
161
178
  return get(`/users/${userId}/dm_conversations`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectratools/xapi-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "X (Twitter) API CLI for spectra-the-bot",
5
5
  "type": "module",
6
6
  "license": "MIT",