@xcrop/sdk 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +361 -2
- package/dist/cjs/client.d.ts +65 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +84 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.d.ts +38 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +70 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/http.d.ts +28 -0
- package/dist/cjs/http.d.ts.map +1 -0
- package/dist/cjs/http.js +250 -0
- package/dist/cjs/http.js.map +1 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/resources/account.d.ts +24 -0
- package/dist/cjs/resources/account.d.ts.map +1 -0
- package/dist/cjs/resources/account.js +54 -0
- package/dist/cjs/resources/account.js.map +1 -0
- package/dist/cjs/resources/communities.d.ts +26 -0
- package/dist/cjs/resources/communities.d.ts.map +1 -0
- package/dist/cjs/resources/communities.js +47 -0
- package/dist/cjs/resources/communities.js.map +1 -0
- package/dist/cjs/resources/lists.d.ts +24 -0
- package/dist/cjs/resources/lists.d.ts.map +1 -0
- package/dist/cjs/resources/lists.js +61 -0
- package/dist/cjs/resources/lists.js.map +1 -0
- package/dist/cjs/resources/search.d.ts +60 -0
- package/dist/cjs/resources/search.d.ts.map +1 -0
- package/dist/cjs/resources/search.js +198 -0
- package/dist/cjs/resources/search.js.map +1 -0
- package/dist/cjs/resources/stream.d.ts +45 -0
- package/dist/cjs/resources/stream.d.ts.map +1 -0
- package/dist/cjs/resources/stream.js +129 -0
- package/dist/cjs/resources/stream.js.map +1 -0
- package/dist/cjs/resources/trending.d.ts +11 -0
- package/dist/cjs/resources/trending.d.ts.map +1 -0
- package/dist/cjs/resources/trending.js +21 -0
- package/dist/cjs/resources/trending.js.map +1 -0
- package/dist/cjs/resources/tweets.d.ts +84 -0
- package/dist/cjs/resources/tweets.d.ts.map +1 -0
- package/dist/cjs/resources/tweets.js +179 -0
- package/dist/cjs/resources/tweets.js.map +1 -0
- package/dist/cjs/resources/users.d.ts +81 -0
- package/dist/cjs/resources/users.d.ts.map +1 -0
- package/dist/cjs/resources/users.js +182 -0
- package/dist/cjs/resources/users.js.map +1 -0
- package/dist/cjs/types.d.ts +256 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/client.d.ts +65 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +80 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +38 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +62 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/http.d.ts +28 -0
- package/dist/esm/http.d.ts.map +1 -0
- package/dist/esm/http.js +246 -0
- package/dist/esm/http.js.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/resources/account.d.ts +24 -0
- package/dist/esm/resources/account.d.ts.map +1 -0
- package/dist/esm/resources/account.js +50 -0
- package/dist/esm/resources/account.js.map +1 -0
- package/dist/esm/resources/communities.d.ts +26 -0
- package/dist/esm/resources/communities.d.ts.map +1 -0
- package/dist/esm/resources/communities.js +43 -0
- package/dist/esm/resources/communities.js.map +1 -0
- package/dist/esm/resources/lists.d.ts +24 -0
- package/dist/esm/resources/lists.d.ts.map +1 -0
- package/dist/esm/resources/lists.js +56 -0
- package/dist/esm/resources/lists.js.map +1 -0
- package/dist/esm/resources/search.d.ts +60 -0
- package/dist/esm/resources/search.d.ts.map +1 -0
- package/dist/esm/resources/search.js +193 -0
- package/dist/esm/resources/search.js.map +1 -0
- package/dist/esm/resources/stream.d.ts +45 -0
- package/dist/esm/resources/stream.d.ts.map +1 -0
- package/dist/esm/resources/stream.js +124 -0
- package/dist/esm/resources/stream.js.map +1 -0
- package/dist/esm/resources/trending.d.ts +11 -0
- package/dist/esm/resources/trending.d.ts.map +1 -0
- package/dist/esm/resources/trending.js +17 -0
- package/dist/esm/resources/trending.js.map +1 -0
- package/dist/esm/resources/tweets.d.ts +84 -0
- package/dist/esm/resources/tweets.d.ts.map +1 -0
- package/dist/esm/resources/tweets.js +174 -0
- package/dist/esm/resources/tweets.js.map +1 -0
- package/dist/esm/resources/users.d.ts +81 -0
- package/dist/esm/resources/users.d.ts.map +1 -0
- package/dist/esm/resources/users.js +177 -0
- package/dist/esm/resources/users.js.map +1 -0
- package/dist/esm/types.d.ts +256 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +43 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { Tweet, User, PaginatedResponse, ApiResponse, SearchTweetsParams, SearchUsersParams } from '../types.js';
|
|
3
|
+
export declare class SearchResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
/**
|
|
7
|
+
* Search for tweets.
|
|
8
|
+
*/
|
|
9
|
+
tweets(params: SearchTweetsParams): Promise<PaginatedResponse<Tweet>>;
|
|
10
|
+
/**
|
|
11
|
+
* Search for users.
|
|
12
|
+
*/
|
|
13
|
+
users(params: SearchUsersParams): Promise<ApiResponse<User[]>>;
|
|
14
|
+
/**
|
|
15
|
+
* Stream search results via SSE. Returns an EventSource-like object.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const stream = client.search.stream({ query: 'bitcoin', count: 500 });
|
|
20
|
+
* stream.on('tweet', (tweet) => console.log(tweet));
|
|
21
|
+
* stream.on('done', (meta) => console.log('finished', meta));
|
|
22
|
+
* stream.on('error', (err) => console.error(err));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
stream(params: Omit<SearchTweetsParams, 'stream' | 'cursor'>): SearchStream;
|
|
26
|
+
}
|
|
27
|
+
type StreamCallback<T> = (data: T) => void;
|
|
28
|
+
/**
|
|
29
|
+
* SSE stream wrapper for search results.
|
|
30
|
+
* Connects to the search endpoint with stream=true and emits events.
|
|
31
|
+
*/
|
|
32
|
+
export declare class SearchStream {
|
|
33
|
+
private readonly http;
|
|
34
|
+
private readonly params;
|
|
35
|
+
private listeners;
|
|
36
|
+
private abortController;
|
|
37
|
+
private started;
|
|
38
|
+
constructor(http: HttpClient, params: Omit<SearchTweetsParams, 'stream' | 'cursor'>);
|
|
39
|
+
/**
|
|
40
|
+
* Register an event listener.
|
|
41
|
+
*/
|
|
42
|
+
on(event: 'tweet', callback: StreamCallback<Tweet>): this;
|
|
43
|
+
on(event: 'done', callback: StreamCallback<Record<string, unknown>>): this;
|
|
44
|
+
on(event: 'error', callback: StreamCallback<Error>): this;
|
|
45
|
+
/**
|
|
46
|
+
* Remove an event listener.
|
|
47
|
+
*/
|
|
48
|
+
off(event: 'tweet', callback: StreamCallback<Tweet>): this;
|
|
49
|
+
off(event: 'done', callback: StreamCallback<Record<string, unknown>>): this;
|
|
50
|
+
off(event: 'error', callback: StreamCallback<Error>): this;
|
|
51
|
+
/**
|
|
52
|
+
* Abort the stream.
|
|
53
|
+
*/
|
|
54
|
+
close(): void;
|
|
55
|
+
private start;
|
|
56
|
+
private processSSELine;
|
|
57
|
+
private emit;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/resources/search.ts"],"names":[],"mappings":"AAAA,OAA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,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IASzD;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAC1D,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI;IAC3E,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAW1D;;OAEG;IACH,KAAK,IAAI,IAAI;YAIC,KAAK;IAoDnB,OAAO,CAAC,cAAc;IAyBtB,OAAO,CAAC,IAAI;CAYb"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SearchStream = exports.SearchResource = void 0;
|
|
4
|
+
class SearchResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Search for tweets.
|
|
11
|
+
*/
|
|
12
|
+
async tweets(params) {
|
|
13
|
+
return this.http.request({
|
|
14
|
+
method: 'POST',
|
|
15
|
+
path: '/search',
|
|
16
|
+
body: buildSearchBody(params),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Search for users.
|
|
21
|
+
*/
|
|
22
|
+
async users(params) {
|
|
23
|
+
return this.http.request({
|
|
24
|
+
method: 'POST',
|
|
25
|
+
path: '/search/users',
|
|
26
|
+
body: { query: params.query, count: params.count },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Stream search results via SSE. Returns an EventSource-like object.
|
|
31
|
+
*
|
|
32
|
+
* Usage:
|
|
33
|
+
* ```ts
|
|
34
|
+
* const stream = client.search.stream({ query: 'bitcoin', count: 500 });
|
|
35
|
+
* stream.on('tweet', (tweet) => console.log(tweet));
|
|
36
|
+
* stream.on('done', (meta) => console.log('finished', meta));
|
|
37
|
+
* stream.on('error', (err) => console.error(err));
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
stream(params) {
|
|
41
|
+
return new SearchStream(this.http, params);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.SearchResource = SearchResource;
|
|
45
|
+
function buildSearchBody(params) {
|
|
46
|
+
const body = { query: params.query };
|
|
47
|
+
if (params.count !== undefined)
|
|
48
|
+
body.count = params.count;
|
|
49
|
+
if (params.sort !== undefined)
|
|
50
|
+
body.sort = params.sort;
|
|
51
|
+
if (params.cursor !== undefined)
|
|
52
|
+
body.cursor = params.cursor;
|
|
53
|
+
if (params.lang !== undefined)
|
|
54
|
+
body.lang = params.lang;
|
|
55
|
+
if (params.min_likes !== undefined)
|
|
56
|
+
body.min_likes = params.min_likes;
|
|
57
|
+
if (params.min_retweets !== undefined)
|
|
58
|
+
body.min_retweets = params.min_retweets;
|
|
59
|
+
if (params.exclude_replies !== undefined)
|
|
60
|
+
body.exclude_replies = params.exclude_replies;
|
|
61
|
+
if (params.exclude_retweets !== undefined)
|
|
62
|
+
body.exclude_retweets = params.exclude_retweets;
|
|
63
|
+
if (params.since !== undefined)
|
|
64
|
+
body.since = params.since;
|
|
65
|
+
if (params.until !== undefined)
|
|
66
|
+
body.until = params.until;
|
|
67
|
+
if (params.stream !== undefined)
|
|
68
|
+
body.stream = params.stream;
|
|
69
|
+
return body;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* SSE stream wrapper for search results.
|
|
73
|
+
* Connects to the search endpoint with stream=true and emits events.
|
|
74
|
+
*/
|
|
75
|
+
class SearchStream {
|
|
76
|
+
http;
|
|
77
|
+
params;
|
|
78
|
+
listeners = { tweet: [], done: [], error: [] };
|
|
79
|
+
abortController;
|
|
80
|
+
started = false;
|
|
81
|
+
constructor(http, params) {
|
|
82
|
+
this.http = http;
|
|
83
|
+
this.params = params;
|
|
84
|
+
this.abortController = new AbortController();
|
|
85
|
+
// Auto-start on next tick so listeners can be attached
|
|
86
|
+
queueMicrotask(() => this.start());
|
|
87
|
+
}
|
|
88
|
+
on(event, callback) {
|
|
89
|
+
const key = event;
|
|
90
|
+
if (this.listeners[key]) {
|
|
91
|
+
this.listeners[key].push(callback);
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
off(event, callback) {
|
|
96
|
+
const key = event;
|
|
97
|
+
if (this.listeners[key]) {
|
|
98
|
+
const arr = this.listeners[key];
|
|
99
|
+
const idx = arr.indexOf(callback);
|
|
100
|
+
if (idx !== -1)
|
|
101
|
+
arr.splice(idx, 1);
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Abort the stream.
|
|
107
|
+
*/
|
|
108
|
+
close() {
|
|
109
|
+
this.abortController.abort();
|
|
110
|
+
}
|
|
111
|
+
async start() {
|
|
112
|
+
if (this.started)
|
|
113
|
+
return;
|
|
114
|
+
this.started = true;
|
|
115
|
+
try {
|
|
116
|
+
const body = buildSearchBody({ ...this.params, stream: true });
|
|
117
|
+
const response = await this.http.requestRaw({
|
|
118
|
+
method: 'POST',
|
|
119
|
+
path: '/search',
|
|
120
|
+
body,
|
|
121
|
+
signal: this.abortController.signal,
|
|
122
|
+
});
|
|
123
|
+
if (!response.body) {
|
|
124
|
+
this.emit('error', new Error('No response body for stream'));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const reader = response.body.getReader();
|
|
128
|
+
const decoder = new TextDecoder();
|
|
129
|
+
let buffer = '';
|
|
130
|
+
try {
|
|
131
|
+
while (true) {
|
|
132
|
+
const { done, value } = await reader.read();
|
|
133
|
+
if (done)
|
|
134
|
+
break;
|
|
135
|
+
buffer += decoder.decode(value, { stream: true });
|
|
136
|
+
const lines = buffer.split('\n');
|
|
137
|
+
buffer = lines.pop() ?? '';
|
|
138
|
+
for (const line of lines) {
|
|
139
|
+
this.processSSELine(line);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (readErr) {
|
|
144
|
+
// If aborted by .close(), swallow the error
|
|
145
|
+
if (this.abortController.signal.aborted)
|
|
146
|
+
return;
|
|
147
|
+
throw readErr;
|
|
148
|
+
}
|
|
149
|
+
// Process remaining buffer
|
|
150
|
+
if (buffer.trim()) {
|
|
151
|
+
this.processSSELine(buffer);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (!this.abortController.signal.aborted) {
|
|
156
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
processSSELine(line) {
|
|
161
|
+
const trimmed = line.trim();
|
|
162
|
+
if (!trimmed || trimmed.startsWith(':'))
|
|
163
|
+
return;
|
|
164
|
+
if (trimmed.startsWith('data: ')) {
|
|
165
|
+
const jsonStr = trimmed.slice(6);
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(jsonStr);
|
|
168
|
+
if (parsed.type === 'tweet' && parsed.data) {
|
|
169
|
+
this.emit('tweet', parsed.data);
|
|
170
|
+
}
|
|
171
|
+
else if (parsed.type === 'done') {
|
|
172
|
+
this.emit('done', (parsed.meta ?? parsed));
|
|
173
|
+
}
|
|
174
|
+
else if (parsed.type === 'error') {
|
|
175
|
+
this.emit('error', new Error(parsed.error ?? 'Stream error'));
|
|
176
|
+
}
|
|
177
|
+
else if (parsed.data && !parsed.type) {
|
|
178
|
+
// Single tweet object without type wrapper
|
|
179
|
+
this.emit('tweet', parsed.data);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Ignore malformed JSON lines
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
emit(event, data) {
|
|
188
|
+
const key = event;
|
|
189
|
+
const callbacks = this.listeners[key];
|
|
190
|
+
if (callbacks) {
|
|
191
|
+
for (const cb of callbacks) {
|
|
192
|
+
cb(data);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.SearchStream = SearchStream;
|
|
198
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/resources/search.ts"],"names":[],"mappings":";;;AAWA,MAAa,cAAc;IACI;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,MAA0B;QACrC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YACvB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,MAAyB;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAS;YAC/B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;SACnD,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,MAAqD;QAC1D,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF;AAvCD,wCAuCC;AAED,SAAS,eAAe,CAAC,MAA0B;IACjD,MAAM,IAAI,GAA4B,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;IAC9D,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;QAAE,IAAI,CAAC,KAAK,GAAG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AK,CAAC,MAAM,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC;gBAChE,CAAC;qBAAM,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;oBACvC,2CAA2C;oBAC3C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAa,CAAC,CAAC;gBAC3C,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,8BAA8B;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAKO,IAAI,CAAC,KAAa,EAAE,IAAa;QACvC,MAAM,GAAG,GAAG,KAA8B,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC1B,EAA8B,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA5ID,oCA4IC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { Tweet } from '../types.js';
|
|
3
|
+
type StreamCallback<T> = (data: T) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Real-time SSE stream from the /stream endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const stream = client.stream.connect();
|
|
10
|
+
* stream.on('tweet', (tweet) => console.log(tweet));
|
|
11
|
+
* stream.on('error', (err) => console.error(err));
|
|
12
|
+
* // Later:
|
|
13
|
+
* stream.close();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class RealtimeStream {
|
|
17
|
+
private readonly http;
|
|
18
|
+
private listeners;
|
|
19
|
+
private abortController;
|
|
20
|
+
private started;
|
|
21
|
+
constructor(http: HttpClient);
|
|
22
|
+
on(event: 'tweet', callback: StreamCallback<Tweet>): this;
|
|
23
|
+
on(event: 'error', callback: StreamCallback<Error>): this;
|
|
24
|
+
on(event: 'close', callback: StreamCallback<void>): this;
|
|
25
|
+
/**
|
|
26
|
+
* Remove an event listener.
|
|
27
|
+
*/
|
|
28
|
+
off(event: 'tweet', callback: StreamCallback<Tweet>): this;
|
|
29
|
+
off(event: 'error', callback: StreamCallback<Error>): this;
|
|
30
|
+
off(event: 'close', callback: StreamCallback<void>): this;
|
|
31
|
+
close(): void;
|
|
32
|
+
private start;
|
|
33
|
+
private processLine;
|
|
34
|
+
private emit;
|
|
35
|
+
}
|
|
36
|
+
export declare class StreamResource {
|
|
37
|
+
private readonly http;
|
|
38
|
+
constructor(http: HttpClient);
|
|
39
|
+
/**
|
|
40
|
+
* Connect to the real-time SSE stream.
|
|
41
|
+
*/
|
|
42
|
+
connect(): RealtimeStream;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/resources/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,aAAa,CAAC;AAEtD,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAU3C;;;;;;;;;;;GAWG;AACH,qBAAa,cAAc;IAKb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC,OAAO,CAAC,SAAS,CAAgE;IACjF,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAAS;gBAEK,IAAI,EAAE,UAAU;IAK7C,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IACzD,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IACzD,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IASxD;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAC1D,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,GAAG,IAAI;IAC1D,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IAWzD,KAAK,IAAI,IAAI;YAKC,KAAK;IA6CnB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,IAAI;CAYb;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACH,OAAO,IAAI,cAAc;CAG1B"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamResource = exports.RealtimeStream = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Real-time SSE stream from the /stream endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const stream = client.stream.connect();
|
|
10
|
+
* stream.on('tweet', (tweet) => console.log(tweet));
|
|
11
|
+
* stream.on('error', (err) => console.error(err));
|
|
12
|
+
* // Later:
|
|
13
|
+
* stream.close();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
class RealtimeStream {
|
|
17
|
+
http;
|
|
18
|
+
listeners = { tweet: [], error: [], close: [] };
|
|
19
|
+
abortController;
|
|
20
|
+
started = false;
|
|
21
|
+
constructor(http) {
|
|
22
|
+
this.http = http;
|
|
23
|
+
this.abortController = new AbortController();
|
|
24
|
+
queueMicrotask(() => this.start());
|
|
25
|
+
}
|
|
26
|
+
on(event, callback) {
|
|
27
|
+
const key = event;
|
|
28
|
+
if (this.listeners[key]) {
|
|
29
|
+
this.listeners[key].push(callback);
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
off(event, callback) {
|
|
34
|
+
const key = event;
|
|
35
|
+
if (this.listeners[key]) {
|
|
36
|
+
const arr = this.listeners[key];
|
|
37
|
+
const idx = arr.indexOf(callback);
|
|
38
|
+
if (idx !== -1)
|
|
39
|
+
arr.splice(idx, 1);
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
close() {
|
|
44
|
+
this.abortController.abort();
|
|
45
|
+
this.emit('close', undefined);
|
|
46
|
+
}
|
|
47
|
+
async start() {
|
|
48
|
+
if (this.started)
|
|
49
|
+
return;
|
|
50
|
+
this.started = true;
|
|
51
|
+
try {
|
|
52
|
+
const response = await this.http.requestRaw({
|
|
53
|
+
method: 'GET',
|
|
54
|
+
path: '/stream',
|
|
55
|
+
signal: this.abortController.signal,
|
|
56
|
+
});
|
|
57
|
+
if (!response.body) {
|
|
58
|
+
this.emit('error', new Error('No response body for stream'));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const reader = response.body.getReader();
|
|
62
|
+
const decoder = new TextDecoder();
|
|
63
|
+
let buffer = '';
|
|
64
|
+
try {
|
|
65
|
+
while (true) {
|
|
66
|
+
const { done, value } = await reader.read();
|
|
67
|
+
if (done)
|
|
68
|
+
break;
|
|
69
|
+
buffer += decoder.decode(value, { stream: true });
|
|
70
|
+
const lines = buffer.split('\n');
|
|
71
|
+
buffer = lines.pop() ?? '';
|
|
72
|
+
for (const line of lines) {
|
|
73
|
+
this.processLine(line.trim());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (readErr) {
|
|
78
|
+
// If aborted by .close(), swallow the error
|
|
79
|
+
if (this.abortController.signal.aborted)
|
|
80
|
+
return;
|
|
81
|
+
throw readErr;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (!this.abortController.signal.aborted) {
|
|
86
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
processLine(line) {
|
|
91
|
+
if (!line || line.startsWith(':'))
|
|
92
|
+
return;
|
|
93
|
+
if (line.startsWith('data: ')) {
|
|
94
|
+
try {
|
|
95
|
+
const parsed = JSON.parse(line.slice(6));
|
|
96
|
+
if (parsed.data) {
|
|
97
|
+
this.emit('tweet', parsed.data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// ignore
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
emit(event, data) {
|
|
106
|
+
const key = event;
|
|
107
|
+
const callbacks = this.listeners[key];
|
|
108
|
+
if (callbacks) {
|
|
109
|
+
for (const cb of callbacks) {
|
|
110
|
+
cb(data);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.RealtimeStream = RealtimeStream;
|
|
116
|
+
class StreamResource {
|
|
117
|
+
http;
|
|
118
|
+
constructor(http) {
|
|
119
|
+
this.http = http;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Connect to the real-time SSE stream.
|
|
123
|
+
*/
|
|
124
|
+
connect() {
|
|
125
|
+
return new RealtimeStream(this.http);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.StreamResource = StreamResource;
|
|
129
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/resources/stream.ts"],"names":[],"mappings":";;;AAaA;;;;;;;;;;;GAWG;AACH,MAAa,cAAc;IAKI;IAJrB,SAAS,GAA4B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AAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACF;AATD,wCASC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { TrendingTopic, TrendingParams, ApiResponse } from '../types.js';
|
|
3
|
+
export declare class TrendingResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
/**
|
|
7
|
+
* Get current trending topics.
|
|
8
|
+
*/
|
|
9
|
+
get(params?: TrendingParams): Promise<ApiResponse<TrendingTopic[]>>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=trending.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trending.d.ts","sourceRoot":"","sources":["../../../src/resources/trending.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9E,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,GAAG,CAAC,MAAM,GAAE,cAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC;CAO9E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrendingResource = void 0;
|
|
4
|
+
class TrendingResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get current trending topics.
|
|
11
|
+
*/
|
|
12
|
+
async get(params = {}) {
|
|
13
|
+
return this.http.request({
|
|
14
|
+
method: 'GET',
|
|
15
|
+
path: '/trending',
|
|
16
|
+
query: { country: params.country },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.TrendingResource = TrendingResource;
|
|
21
|
+
//# sourceMappingURL=trending.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trending.js","sourceRoot":"","sources":["../../../src/resources/trending.ts"],"names":[],"mappings":";;;AAGA,MAAa,gBAAgB;IACE;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,SAAyB,EAAE;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAkB;YACxC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;SACnC,CAAC,CAAC;IACL,CAAC;CACF;AAbD,4CAaC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { Tweet, PaginationParams, PaginatedResponse, ApiResponse, CreateTweetParams, ReplyTweetParams, QuoteTweetParams, WriteResult, InteractionCheckResult } from '../types.js';
|
|
3
|
+
export declare class TweetsResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
/**
|
|
7
|
+
* Get a single tweet by ID.
|
|
8
|
+
*/
|
|
9
|
+
get(tweetId: string): Promise<ApiResponse<Tweet>>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the conversation thread for a tweet.
|
|
12
|
+
*/
|
|
13
|
+
conversation(tweetId: string, params?: PaginationParams): Promise<PaginatedResponse<Tweet>>;
|
|
14
|
+
/**
|
|
15
|
+
* Get quote tweets of a tweet.
|
|
16
|
+
*/
|
|
17
|
+
quotes(tweetId: string, params?: PaginationParams): Promise<PaginatedResponse<Tweet>>;
|
|
18
|
+
/**
|
|
19
|
+
* Batch lookup multiple tweets by ID (max 100).
|
|
20
|
+
*/
|
|
21
|
+
batch(tweetIds: string[]): Promise<ApiResponse<Tweet[]>>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new tweet. Requires a connected X account.
|
|
24
|
+
*/
|
|
25
|
+
create(params: CreateTweetParams): Promise<ApiResponse<WriteResult>>;
|
|
26
|
+
/**
|
|
27
|
+
* Reply to a tweet. Requires a connected X account.
|
|
28
|
+
*/
|
|
29
|
+
reply(params: ReplyTweetParams): Promise<ApiResponse<WriteResult>>;
|
|
30
|
+
/**
|
|
31
|
+
* Quote a tweet. Requires a connected X account.
|
|
32
|
+
*/
|
|
33
|
+
quote(params: QuoteTweetParams): Promise<ApiResponse<WriteResult>>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete a tweet. Requires a connected X account.
|
|
36
|
+
*/
|
|
37
|
+
delete(tweetId: string): Promise<ApiResponse<{
|
|
38
|
+
success: boolean;
|
|
39
|
+
}>>;
|
|
40
|
+
/**
|
|
41
|
+
* Like a tweet. Requires a connected X account.
|
|
42
|
+
*/
|
|
43
|
+
like(tweetId: string): Promise<ApiResponse<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
}>>;
|
|
46
|
+
/**
|
|
47
|
+
* Unlike a tweet. Requires a connected X account.
|
|
48
|
+
*/
|
|
49
|
+
unlike(tweetId: string): Promise<ApiResponse<{
|
|
50
|
+
success: boolean;
|
|
51
|
+
}>>;
|
|
52
|
+
/**
|
|
53
|
+
* Retweet a tweet. Requires a connected X account.
|
|
54
|
+
*/
|
|
55
|
+
retweet(tweetId: string): Promise<ApiResponse<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
}>>;
|
|
58
|
+
/**
|
|
59
|
+
* Unretweet a tweet. Requires a connected X account.
|
|
60
|
+
*/
|
|
61
|
+
unretweet(tweetId: string): Promise<ApiResponse<{
|
|
62
|
+
success: boolean;
|
|
63
|
+
}>>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a user retweeted a tweet.
|
|
66
|
+
*/
|
|
67
|
+
checkRetweet(tweetId: string, username: string): Promise<ApiResponse<InteractionCheckResult>>;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a user replied to a tweet.
|
|
70
|
+
*/
|
|
71
|
+
checkReply(tweetId: string, username: string): Promise<ApiResponse<InteractionCheckResult>>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a user quoted a tweet.
|
|
74
|
+
*/
|
|
75
|
+
checkQuote(tweetId: string, username: string): Promise<ApiResponse<InteractionCheckResult>>;
|
|
76
|
+
}
|
|
77
|
+
type TweetPaginatedMethod<T> = (id: string, params: PaginationParams) => Promise<PaginatedResponse<T>>;
|
|
78
|
+
/**
|
|
79
|
+
* Async generator that auto-paginates a tweet-based paginated endpoint.
|
|
80
|
+
* @param maxPages Safety limit to prevent infinite loops (default 100).
|
|
81
|
+
*/
|
|
82
|
+
export declare function paginateTweet<T>(method: TweetPaginatedMethod<T>, id: string, params?: PaginationParams, maxPages?: number): AsyncGenerator<T, void, undefined>;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=tweets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tweets.d.ts","sourceRoot":"","sources":["../../../src/resources/tweets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,KAAK,EACL,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAIrB,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAOvD;;OAEG;IACG,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,gBAAqB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