@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +361 -2
  3. package/dist/cjs/client.d.ts +65 -0
  4. package/dist/cjs/client.d.ts.map +1 -0
  5. package/dist/cjs/client.js +84 -0
  6. package/dist/cjs/client.js.map +1 -0
  7. package/dist/cjs/errors.d.ts +38 -0
  8. package/dist/cjs/errors.d.ts.map +1 -0
  9. package/dist/cjs/errors.js +70 -0
  10. package/dist/cjs/errors.js.map +1 -0
  11. package/dist/cjs/http.d.ts +28 -0
  12. package/dist/cjs/http.d.ts.map +1 -0
  13. package/dist/cjs/http.js +250 -0
  14. package/dist/cjs/http.js.map +1 -0
  15. package/dist/cjs/index.d.ts +13 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +36 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/package.json +3 -0
  20. package/dist/cjs/resources/account.d.ts +24 -0
  21. package/dist/cjs/resources/account.d.ts.map +1 -0
  22. package/dist/cjs/resources/account.js +54 -0
  23. package/dist/cjs/resources/account.js.map +1 -0
  24. package/dist/cjs/resources/communities.d.ts +26 -0
  25. package/dist/cjs/resources/communities.d.ts.map +1 -0
  26. package/dist/cjs/resources/communities.js +47 -0
  27. package/dist/cjs/resources/communities.js.map +1 -0
  28. package/dist/cjs/resources/lists.d.ts +24 -0
  29. package/dist/cjs/resources/lists.d.ts.map +1 -0
  30. package/dist/cjs/resources/lists.js +61 -0
  31. package/dist/cjs/resources/lists.js.map +1 -0
  32. package/dist/cjs/resources/search.d.ts +60 -0
  33. package/dist/cjs/resources/search.d.ts.map +1 -0
  34. package/dist/cjs/resources/search.js +198 -0
  35. package/dist/cjs/resources/search.js.map +1 -0
  36. package/dist/cjs/resources/stream.d.ts +45 -0
  37. package/dist/cjs/resources/stream.d.ts.map +1 -0
  38. package/dist/cjs/resources/stream.js +129 -0
  39. package/dist/cjs/resources/stream.js.map +1 -0
  40. package/dist/cjs/resources/trending.d.ts +11 -0
  41. package/dist/cjs/resources/trending.d.ts.map +1 -0
  42. package/dist/cjs/resources/trending.js +21 -0
  43. package/dist/cjs/resources/trending.js.map +1 -0
  44. package/dist/cjs/resources/tweets.d.ts +84 -0
  45. package/dist/cjs/resources/tweets.d.ts.map +1 -0
  46. package/dist/cjs/resources/tweets.js +179 -0
  47. package/dist/cjs/resources/tweets.js.map +1 -0
  48. package/dist/cjs/resources/users.d.ts +81 -0
  49. package/dist/cjs/resources/users.d.ts.map +1 -0
  50. package/dist/cjs/resources/users.js +182 -0
  51. package/dist/cjs/resources/users.js.map +1 -0
  52. package/dist/cjs/types.d.ts +256 -0
  53. package/dist/cjs/types.d.ts.map +1 -0
  54. package/dist/cjs/types.js +4 -0
  55. package/dist/cjs/types.js.map +1 -0
  56. package/dist/esm/client.d.ts +65 -0
  57. package/dist/esm/client.d.ts.map +1 -0
  58. package/dist/esm/client.js +80 -0
  59. package/dist/esm/client.js.map +1 -0
  60. package/dist/esm/errors.d.ts +38 -0
  61. package/dist/esm/errors.d.ts.map +1 -0
  62. package/dist/esm/errors.js +62 -0
  63. package/dist/esm/errors.js.map +1 -0
  64. package/dist/esm/http.d.ts +28 -0
  65. package/dist/esm/http.d.ts.map +1 -0
  66. package/dist/esm/http.js +246 -0
  67. package/dist/esm/http.js.map +1 -0
  68. package/dist/esm/index.d.ts +13 -0
  69. package/dist/esm/index.d.ts.map +1 -0
  70. package/dist/esm/index.js +16 -0
  71. package/dist/esm/index.js.map +1 -0
  72. package/dist/esm/resources/account.d.ts +24 -0
  73. package/dist/esm/resources/account.d.ts.map +1 -0
  74. package/dist/esm/resources/account.js +50 -0
  75. package/dist/esm/resources/account.js.map +1 -0
  76. package/dist/esm/resources/communities.d.ts +26 -0
  77. package/dist/esm/resources/communities.d.ts.map +1 -0
  78. package/dist/esm/resources/communities.js +43 -0
  79. package/dist/esm/resources/communities.js.map +1 -0
  80. package/dist/esm/resources/lists.d.ts +24 -0
  81. package/dist/esm/resources/lists.d.ts.map +1 -0
  82. package/dist/esm/resources/lists.js +56 -0
  83. package/dist/esm/resources/lists.js.map +1 -0
  84. package/dist/esm/resources/search.d.ts +60 -0
  85. package/dist/esm/resources/search.d.ts.map +1 -0
  86. package/dist/esm/resources/search.js +193 -0
  87. package/dist/esm/resources/search.js.map +1 -0
  88. package/dist/esm/resources/stream.d.ts +45 -0
  89. package/dist/esm/resources/stream.d.ts.map +1 -0
  90. package/dist/esm/resources/stream.js +124 -0
  91. package/dist/esm/resources/stream.js.map +1 -0
  92. package/dist/esm/resources/trending.d.ts +11 -0
  93. package/dist/esm/resources/trending.d.ts.map +1 -0
  94. package/dist/esm/resources/trending.js +17 -0
  95. package/dist/esm/resources/trending.js.map +1 -0
  96. package/dist/esm/resources/tweets.d.ts +84 -0
  97. package/dist/esm/resources/tweets.d.ts.map +1 -0
  98. package/dist/esm/resources/tweets.js +174 -0
  99. package/dist/esm/resources/tweets.js.map +1 -0
  100. package/dist/esm/resources/users.d.ts +81 -0
  101. package/dist/esm/resources/users.d.ts.map +1 -0
  102. package/dist/esm/resources/users.js +177 -0
  103. package/dist/esm/resources/users.js.map +1 -0
  104. package/dist/esm/types.d.ts +256 -0
  105. package/dist/esm/types.d.ts.map +1 -0
  106. package/dist/esm/types.js +3 -0
  107. package/dist/esm/types.js.map +1 -0
  108. package/package.json +43 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 XCROP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,362 @@
1
- # Temporary Holding Version
1
+ # @xcrop/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official JavaScript/TypeScript SDK for the [XCROP API](https://xcrop.io), the X/Twitter data intelligence platform, covering 42 endpoints (profiles, tweets, search, lists, communities, account monitoring, and the Write API).
4
+
5
+ - Full TypeScript support with detailed types for all endpoints
6
+ - Auto-retry on rate limits (429) with exponential backoff
7
+ - Auto-retry on server errors (5xx), max 3 attempts
8
+ - Auto-pagination via async iterators
9
+ - SSE streaming support for search and real-time feeds
10
+ - ESM and CommonJS dual output
11
+ - Zero dependencies (uses native `fetch`)
12
+
13
+ ## Requirements
14
+
15
+ - Node.js 18+ (native `fetch` required)
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @xcrop/sdk
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { XCrop } from '@xcrop/sdk';
27
+
28
+ const client = new XCrop({ apiKey: 'xc_live_...' });
29
+
30
+ // Get a user profile
31
+ const { data: user } = await client.users.get('elonmusk');
32
+ console.log(user.name, user.followers_count);
33
+
34
+ // Get user tweets
35
+ const { data: tweets } = await client.users.tweets('elonmusk', { count: 50 });
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ ```typescript
41
+ const client = new XCrop({
42
+ apiKey: 'xc_live_...', // Required
43
+ baseUrl: 'https://...', // Default: https://xcrop.io/api/v2
44
+ timeout: 30000, // Default: 30s
45
+ maxRetries: 3, // Default: 3 (for 429/5xx)
46
+ });
47
+ ```
48
+
49
+ ## Users
50
+
51
+ ```typescript
52
+ // Profile
53
+ const { data: user } = await client.users.get('elonmusk');
54
+
55
+ // Tweets, mentions, replies, media
56
+ const { data: tweets } = await client.users.tweets('elonmusk', { count: 20 });
57
+ const { data: mentions } = await client.users.mentions('elonmusk');
58
+ const { data: replies } = await client.users.replies('elonmusk');
59
+ const { data: media } = await client.users.media('elonmusk');
60
+
61
+ // Followers & following
62
+ const { data: followers } = await client.users.followers('elonmusk', { count: 100 });
63
+ const { data: following } = await client.users.following('elonmusk');
64
+ const { data: verified } = await client.users.verifiedFollowers('elonmusk');
65
+
66
+ // Raw follower IDs (bulk, no profile metadata, up to 5000/call)
67
+ const { data: ids } = await client.users.followersIds('elonmusk', { count: 5000 });
68
+
69
+ // Batch lookup (max 100)
70
+ const { data: users } = await client.users.batch(['elonmusk', 'jack', 'VitalikButerin']);
71
+
72
+ // Check follow relationship
73
+ const { data: rel } = await client.users.checkFollow('elonmusk', 'jack');
74
+ console.log(rel.source_follows_target, rel.target_follows_source);
75
+
76
+ // Eligibility checks for airdrop/giveaway gating
77
+ const { data: qa } = await client.users.checkQualifiedAccount('elonmusk', {
78
+ min_followers: 1000,
79
+ min_age_days: 30,
80
+ });
81
+ const { data: qn } = await client.users.checkQualifiedName('elonmusk', {
82
+ contains: 'crypto',
83
+ position: 'anywhere', // 'anywhere' | 'left' | 'right'
84
+ });
85
+ ```
86
+
87
+ ## Tweets
88
+
89
+ ```typescript
90
+ // Single tweet
91
+ const { data: tweet } = await client.tweets.get('1234567890');
92
+
93
+ // Conversation thread
94
+ const { data: thread } = await client.tweets.conversation('1234567890', { count: 50 });
95
+
96
+ // Quote tweets
97
+ const { data: quotes } = await client.tweets.quotes('1234567890');
98
+
99
+ // Batch lookup (max 100)
100
+ const { data: tweets } = await client.tweets.batch(['123', '456', '789']);
101
+ ```
102
+
103
+ ## Communities
104
+
105
+ X Communities data. These endpoints are in beta and may return a 503
106
+ (`ENDPOINT_IN_DEVELOPMENT`) while the backend is being finished.
107
+
108
+ ```typescript
109
+ const { data: community } = await client.communities.get('1708766018985501165');
110
+ const { data: tweets } = await client.communities.tweets('1708766018985501165', { sort: 'latest' });
111
+ const { data: members } = await client.communities.members('1708766018985501165', { sort: 'default' });
112
+ ```
113
+
114
+ ## Search
115
+
116
+ ```typescript
117
+ // Search tweets
118
+ const { data: results } = await client.search.tweets({
119
+ query: 'bitcoin',
120
+ count: 50,
121
+ sort: 'latest', // 'latest' | 'popular' | 'engagement'
122
+ lang: 'en',
123
+ min_likes: 10,
124
+ exclude_replies: true,
125
+ since: '2024-01-01',
126
+ until: '2024-12-31',
127
+ });
128
+
129
+ // Search users
130
+ const { data: users } = await client.search.users({ query: 'crypto', count: 20 });
131
+ ```
132
+
133
+ ## Auto-Pagination
134
+
135
+ Use the `paginate` helper to automatically iterate through all pages:
136
+
137
+ ```typescript
138
+ // Iterate all tweets
139
+ for await (const tweet of client.paginate.userTweets('elonmusk', { count: 100 })) {
140
+ console.log(tweet.text);
141
+ }
142
+
143
+ // Also works with: client.users.tweets.paginate()
144
+ for await (const tweet of client.users.tweets.paginate('elonmusk', { count: 200 })) {
145
+ console.log(tweet.id);
146
+ }
147
+
148
+ // All paginated endpoints:
149
+ client.paginate.userTweets(username, params)
150
+ client.paginate.userMentions(username, params)
151
+ client.paginate.userFollowers(username, params)
152
+ client.paginate.userFollowing(username, params)
153
+ client.paginate.userReplies(username, params)
154
+ client.paginate.userMedia(username, params)
155
+ client.paginate.userVerifiedFollowers(username, params)
156
+ client.paginate.tweetConversation(tweetId, params)
157
+ client.paginate.tweetQuotes(tweetId, params)
158
+ client.paginate.listTweets(listId, params)
159
+ client.paginate.listMembers(listId, params)
160
+ client.paginate.listSubscribers(listId, params)
161
+ client.paginate.communityTweets(communityId, params)
162
+ client.paginate.communityMembers(communityId, params)
163
+ ```
164
+
165
+ ## Streaming
166
+
167
+ ### Search Stream (SSE)
168
+
169
+ ```typescript
170
+ const stream = client.search.stream({ query: 'crypto', count: 500 });
171
+
172
+ stream.on('tweet', (tweet) => {
173
+ console.log(tweet.text);
174
+ });
175
+
176
+ stream.on('done', (meta) => {
177
+ console.log('Stream complete', meta);
178
+ });
179
+
180
+ stream.on('error', (err) => {
181
+ console.error('Stream error', err);
182
+ });
183
+
184
+ // Close early
185
+ stream.close();
186
+ ```
187
+
188
+ ### Real-time Stream
189
+
190
+ ```typescript
191
+ const stream = client.stream.connect();
192
+
193
+ stream.on('tweet', (tweet) => {
194
+ console.log('New tweet:', tweet.text);
195
+ });
196
+
197
+ stream.on('error', (err) => {
198
+ console.error(err);
199
+ });
200
+
201
+ // Close when done
202
+ stream.close();
203
+ ```
204
+
205
+ ## Write Operations
206
+
207
+ Write operations require a connected X account.
208
+
209
+ ### Connect Account
210
+
211
+ ```typescript
212
+ // Via credentials
213
+ await client.account.connect({
214
+ username: 'myuser',
215
+ password: 'mypass',
216
+ totp_secret: 'ABCDEF123456', // Optional 2FA
217
+ });
218
+
219
+ // Via cookies
220
+ await client.account.connect({
221
+ cookies: {
222
+ auth_token: '...',
223
+ ct0: '...',
224
+ },
225
+ });
226
+
227
+ // Check status
228
+ const { data: status } = await client.account.status();
229
+ console.log(status.connected, status.username);
230
+
231
+ // Disconnect
232
+ await client.account.disconnect();
233
+ ```
234
+
235
+ ### Create, Reply, Quote
236
+
237
+ ```typescript
238
+ // Create tweet
239
+ const { data: result } = await client.tweets.create({ text: 'Hello world!' });
240
+ console.log(result.tweet_id);
241
+
242
+ // Reply
243
+ await client.tweets.reply({ tweet_id: '1234567890', text: 'Great thread!' });
244
+
245
+ // Quote
246
+ await client.tweets.quote({ tweet_id: '1234567890', text: 'Interesting take' });
247
+
248
+ // Delete
249
+ await client.tweets.delete('1234567890');
250
+ ```
251
+
252
+ ### Like, Retweet, Follow
253
+
254
+ ```typescript
255
+ await client.tweets.like('1234567890');
256
+ await client.tweets.unlike('1234567890');
257
+
258
+ await client.tweets.retweet('1234567890');
259
+ await client.tweets.unretweet('1234567890');
260
+
261
+ await client.users.follow('elonmusk');
262
+ await client.users.unfollow('elonmusk');
263
+ ```
264
+
265
+ ## Interaction Checks
266
+
267
+ Check if a user interacted with a specific tweet (no connected account needed):
268
+
269
+ ```typescript
270
+ const { data: retweeted } = await client.tweets.checkRetweet('1234567890', 'username');
271
+ const { data: replied } = await client.tweets.checkReply('1234567890', 'username');
272
+ const { data: quoted } = await client.tweets.checkQuote('1234567890', 'username');
273
+
274
+ console.log(retweeted.found); // boolean
275
+ ```
276
+
277
+ ## Lists
278
+
279
+ ```typescript
280
+ const { data: tweets } = await client.lists.tweets('12345', { count: 50 });
281
+ const { data: members } = await client.lists.members('12345');
282
+ const { data: subs } = await client.lists.subscribers('12345');
283
+ ```
284
+
285
+ ## Trending
286
+
287
+ ```typescript
288
+ // Trending topics (defaults to Worldwide)
289
+ const { data: trends } = await client.trending.get();
290
+ const { data: usTrends } = await client.trending.get({ country: 'United States' });
291
+ ```
292
+
293
+ ## Account Monitoring
294
+
295
+ Track specific X accounts over time (profile snapshots, tweet activity) via
296
+ the `users` and `search` endpoints above: poll `client.users.get()` /
297
+ `client.users.tweets()` on a schedule, or use `client.stream.connect()` for
298
+ real-time updates.
299
+
300
+ ## Error Handling
301
+
302
+ ```typescript
303
+ import { XCrop, AuthError, RateLimitError, NotFoundError, XCropError } from '@xcrop/sdk';
304
+
305
+ try {
306
+ await client.users.get('nonexistent_user_12345');
307
+ } catch (err) {
308
+ if (err instanceof NotFoundError) {
309
+ console.log('User not found');
310
+ } else if (err instanceof AuthError) {
311
+ console.log('Invalid API key');
312
+ } else if (err instanceof RateLimitError) {
313
+ console.log(`Rate limited. Retry after ${err.retryAfter}s`);
314
+ console.log(`Remaining: ${err.remaining}/${err.limit}`);
315
+ } else if (err instanceof XCropError) {
316
+ console.log(`API error: ${err.status} ${err.code} — ${err.message}`);
317
+ }
318
+ }
319
+ ```
320
+
321
+ ## Rate Limits
322
+
323
+ Per-minute request limits, by plan:
324
+
325
+ | Plan | Requests/min |
326
+ |------|---------------|
327
+ | Starter | 60 |
328
+ | Basic | 300 |
329
+ | Pro | 600 |
330
+ | Pay-as-You-Go | 300 |
331
+
332
+ Every plan (including the free Starter tier) can call all 42 endpoints. Plans
333
+ differ only by monthly credits, the rate limit above, and credit price. On a
334
+ 429 the SDK auto-retries with backoff (see `RateLimitError` above for the
335
+ raw `retryAfter`/`remaining`/`limit` fields).
336
+
337
+ ## Payment
338
+
339
+ Plans and credit top-ups are paid via cryptocurrency: USDT (BEP-20), USDC
340
+ (BEP-20), SOL, and POL. Card payments (Stripe) are coming soon. See
341
+ [xcrop.io/pricing](https://xcrop.io/pricing) for details.
342
+
343
+ ## Response Format
344
+
345
+ All methods return the raw API response envelope:
346
+
347
+ ```typescript
348
+ interface ApiResponse<T> {
349
+ data: T;
350
+ meta: {
351
+ latency_ms?: number;
352
+ cached?: boolean;
353
+ total?: number;
354
+ cursor?: string; // For pagination
355
+ has_next?: boolean; // More pages available
356
+ };
357
+ }
358
+ ```
359
+
360
+ ## License
361
+
362
+ MIT
@@ -0,0 +1,65 @@
1
+ import { UsersResource } from './resources/users.js';
2
+ import { TweetsResource } from './resources/tweets.js';
3
+ import { SearchResource } from './resources/search.js';
4
+ import { ListsResource } from './resources/lists.js';
5
+ import { TrendingResource } from './resources/trending.js';
6
+ import { CommunitiesResource } from './resources/communities.js';
7
+ import { AccountResource } from './resources/account.js';
8
+ import { StreamResource } from './resources/stream.js';
9
+ import type { XCropOptions, PaginationParams, CommunityTweetsParams, CommunityMembersParams, Tweet, User } from './types.js';
10
+ type UserTweetsFn = UsersResource['tweets'] & {
11
+ paginate(username: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
12
+ };
13
+ interface PaginateHelpers {
14
+ userTweets(username: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
15
+ userMentions(username: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
16
+ userFollowers(username: string, params?: PaginationParams): AsyncGenerator<User, void, undefined>;
17
+ userFollowing(username: string, params?: PaginationParams): AsyncGenerator<User, void, undefined>;
18
+ userReplies(username: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
19
+ userMedia(username: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
20
+ userVerifiedFollowers(username: string, params?: PaginationParams): AsyncGenerator<User, void, undefined>;
21
+ tweetConversation(tweetId: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
22
+ tweetQuotes(tweetId: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
23
+ listTweets(listId: string, params?: PaginationParams): AsyncGenerator<Tweet, void, undefined>;
24
+ listMembers(listId: string, params?: PaginationParams): AsyncGenerator<User, void, undefined>;
25
+ listSubscribers(listId: string, params?: PaginationParams): AsyncGenerator<User, void, undefined>;
26
+ communityTweets(communityId: string, params?: CommunityTweetsParams): AsyncGenerator<Tweet, void, undefined>;
27
+ communityMembers(communityId: string, params?: CommunityMembersParams): AsyncGenerator<User, void, undefined>;
28
+ }
29
+ /**
30
+ * XCROP SDK client for the X/Twitter data intelligence API.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { XCrop } from '@xcrop/sdk';
35
+ *
36
+ * const client = new XCrop({ apiKey: 'xc_live_...' });
37
+ * const user = await client.users.get('elonmusk');
38
+ * ```
39
+ */
40
+ export declare class XCrop {
41
+ private readonly http;
42
+ /** User profile, tweets, followers, and follow-check endpoints. */
43
+ readonly users: UsersResource & {
44
+ tweets: UserTweetsFn;
45
+ };
46
+ /** Tweet data, write operations, interactions, and checks. */
47
+ readonly tweets: TweetsResource;
48
+ /** Search tweets and users, with streaming support. */
49
+ readonly search: SearchResource;
50
+ /** Twitter list data. */
51
+ readonly lists: ListsResource;
52
+ /** Trending topics. */
53
+ readonly trending: TrendingResource;
54
+ /** X Communities data (beta — may return 503 while under development). */
55
+ readonly communities: CommunitiesResource;
56
+ /** X account connection management for write operations. */
57
+ readonly account: AccountResource;
58
+ /** Real-time SSE stream. */
59
+ readonly stream: StreamResource;
60
+ /** Pagination helper — auto-iterate through all pages. */
61
+ readonly paginate: PaginateHelpers;
62
+ constructor(options: XCropOptions);
63
+ }
64
+ export {};
65
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,KAAK,EACL,IAAI,EACL,MAAM,YAAY,CAAC;AAEpB,KAAK,YAAY,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;CAC/F,CAAC;AAEF,UAAU,eAAe;IACvB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,KAAK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0;
4
+ const http_js_1 = require("./http.js");
5
+ const users_js_1 = require("./resources/users.js");
6
+ const tweets_js_1 = require("./resources/tweets.js");
7
+ const search_js_1 = require("./resources/search.js");
8
+ const lists_js_1 = require("./resources/lists.js");
9
+ const trending_js_1 = require("./resources/trending.js");
10
+ const communities_js_1 = require("./resources/communities.js");
11
+ const account_js_1 = require("./resources/account.js");
12
+ const stream_js_1 = require("./resources/stream.js");
13
+ /**
14
+ * XCROP SDK client for the X/Twitter data intelligence API.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { XCrop } from '@xcrop/sdk';
19
+ *
20
+ * const client = new XCrop({ apiKey: 'xc_live_...' });
21
+ * const user = await client.users.get('elonmusk');
22
+ * ```
23
+ */
24
+ class XCrop {
25
+ http;
26
+ /** User profile, tweets, followers, and follow-check endpoints. */
27
+ users;
28
+ /** Tweet data, write operations, interactions, and checks. */
29
+ tweets;
30
+ /** Search tweets and users, with streaming support. */
31
+ search;
32
+ /** Twitter list data. */
33
+ lists;
34
+ /** Trending topics. */
35
+ trending;
36
+ /** X Communities data (beta — may return 503 while under development). */
37
+ communities;
38
+ /** X account connection management for write operations. */
39
+ account;
40
+ /** Real-time SSE stream. */
41
+ stream;
42
+ /** Pagination helper — auto-iterate through all pages. */
43
+ paginate;
44
+ constructor(options) {
45
+ if (!options.apiKey) {
46
+ throw new Error('apiKey is required');
47
+ }
48
+ this.http = new http_js_1.HttpClient(options);
49
+ // Initialize resources
50
+ const usersBase = new users_js_1.UsersResource(this.http);
51
+ this.tweets = new tweets_js_1.TweetsResource(this.http);
52
+ this.search = new search_js_1.SearchResource(this.http);
53
+ this.lists = new lists_js_1.ListsResource(this.http);
54
+ this.trending = new trending_js_1.TrendingResource(this.http);
55
+ this.communities = new communities_js_1.CommunitiesResource(this.http);
56
+ this.account = new account_js_1.AccountResource(this.http);
57
+ this.stream = new stream_js_1.StreamResource(this.http);
58
+ // Build users.tweets with nested .paginate()
59
+ const boundTweets = usersBase.tweets.bind(usersBase);
60
+ const tweetsFn = Object.assign(boundTweets, {
61
+ paginate: (username, params) => (0, users_js_1.paginateUser)(boundTweets, username, params),
62
+ });
63
+ this.users = Object.assign(usersBase, { tweets: tweetsFn });
64
+ // Build top-level paginate helpers
65
+ this.paginate = {
66
+ userTweets: (username, params) => (0, users_js_1.paginateUser)(boundTweets, username, params),
67
+ userMentions: (username, params) => (0, users_js_1.paginateUser)(usersBase.mentions.bind(usersBase), username, params),
68
+ userFollowers: (username, params) => (0, users_js_1.paginateUser)(usersBase.followers.bind(usersBase), username, params),
69
+ userFollowing: (username, params) => (0, users_js_1.paginateUser)(usersBase.following.bind(usersBase), username, params),
70
+ userReplies: (username, params) => (0, users_js_1.paginateUser)(usersBase.replies.bind(usersBase), username, params),
71
+ userMedia: (username, params) => (0, users_js_1.paginateUser)(usersBase.media.bind(usersBase), username, params),
72
+ userVerifiedFollowers: (username, params) => (0, users_js_1.paginateUser)(usersBase.verifiedFollowers.bind(usersBase), username, params),
73
+ tweetConversation: (tweetId, params) => (0, tweets_js_1.paginateTweet)(this.tweets.conversation.bind(this.tweets), tweetId, params),
74
+ tweetQuotes: (tweetId, params) => (0, tweets_js_1.paginateTweet)(this.tweets.quotes.bind(this.tweets), tweetId, params),
75
+ listTweets: (listId, params) => (0, lists_js_1.paginateList)(this.lists.tweets.bind(this.lists), listId, params),
76
+ listMembers: (listId, params) => (0, lists_js_1.paginateList)(this.lists.members.bind(this.lists), listId, params),
77
+ listSubscribers: (listId, params) => (0, lists_js_1.paginateList)(this.lists.subscribers.bind(this.lists), listId, params),
78
+ communityTweets: (communityId, params) => (0, lists_js_1.paginateList)(this.communities.tweets.bind(this.communities), communityId, params),
79
+ communityMembers: (communityId, params) => (0, lists_js_1.paginateList)(this.communities.members.bind(this.communities), communityId, params),
80
+ };
81
+ }
82
+ }
83
+ exports.XCrop = XCrop;
84
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.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AC,MAAc,EAAE,MAAyB,EAAE,EAAE,CAC7D,IAAA,uBAAY,EAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC;YAC7E,eAAe,EAAE,CAAC,WAAmB,EAAE,MAA8B,EAAE,EAAE,CACvE,IAAA,uBAAY,EAAQ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC;YAC1F,gBAAgB,EAAE,CAAC,WAAmB,EAAE,MAA+B,EAAE,EAAE,CACzE,IAAA,uBAAY,EAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC;SAC3F,CAAC;IACJ,CAAC;CACF;AAjFD,sBAiFC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Base error class for all XCROP SDK errors.
3
+ */
4
+ export declare class XCropError extends Error {
5
+ readonly status: number;
6
+ readonly code: string;
7
+ readonly headers: Record<string, string>;
8
+ constructor(message: string, status: number, code: string, headers?: Record<string, string>);
9
+ }
10
+ /**
11
+ * Thrown when authentication fails (401).
12
+ */
13
+ export declare class AuthError extends XCropError {
14
+ constructor(message: string, headers?: Record<string, string>);
15
+ }
16
+ /**
17
+ * Thrown when rate limit is exceeded (429).
18
+ * Contains retry timing information.
19
+ */
20
+ export declare class RateLimitError extends XCropError {
21
+ readonly retryAfter: number | null;
22
+ readonly remaining: number;
23
+ readonly limit: number;
24
+ constructor(message: string, headers?: Record<string, string>);
25
+ }
26
+ /**
27
+ * Thrown when a resource is not found (404).
28
+ */
29
+ export declare class NotFoundError extends XCropError {
30
+ constructor(message: string, headers?: Record<string, string>);
31
+ }
32
+ /**
33
+ * Thrown when the request is forbidden (403).
34
+ */
35
+ export declare class ForbiddenError extends XCropError {
36
+ constructor(message: string, headers?: Record<string, string>);
37
+ }
38
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAG9C,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CASvC;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,UAAU;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CAIlE;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,SAAgB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CAUvC;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CAIlE;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CAIlE"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForbiddenError = exports.NotFoundError = exports.RateLimitError = exports.AuthError = exports.XCropError = void 0;
4
+ /**
5
+ * Base error class for all XCROP SDK errors.
6
+ */
7
+ class XCropError extends Error {
8
+ status;
9
+ code;
10
+ headers;
11
+ constructor(message, status, code, headers = {}) {
12
+ super(message);
13
+ this.name = 'XCropError';
14
+ this.status = status;
15
+ this.code = code;
16
+ this.headers = headers;
17
+ Object.setPrototypeOf(this, new.target.prototype);
18
+ }
19
+ }
20
+ exports.XCropError = XCropError;
21
+ /**
22
+ * Thrown when authentication fails (401).
23
+ */
24
+ class AuthError extends XCropError {
25
+ constructor(message, headers = {}) {
26
+ super(message, 401, 'AUTH_ERROR', headers);
27
+ this.name = 'AuthError';
28
+ }
29
+ }
30
+ exports.AuthError = AuthError;
31
+ /**
32
+ * Thrown when rate limit is exceeded (429).
33
+ * Contains retry timing information.
34
+ */
35
+ class RateLimitError extends XCropError {
36
+ retryAfter;
37
+ remaining;
38
+ limit;
39
+ constructor(message, headers = {}) {
40
+ super(message, 429, 'RATE_LIMIT', headers);
41
+ this.name = 'RateLimitError';
42
+ this.retryAfter = headers['retry-after']
43
+ ? parseInt(headers['retry-after'], 10)
44
+ : null;
45
+ this.remaining = parseInt(headers['x-ratelimit-remaining'] || '0', 10);
46
+ this.limit = parseInt(headers['x-ratelimit-limit'] || '0', 10);
47
+ }
48
+ }
49
+ exports.RateLimitError = RateLimitError;
50
+ /**
51
+ * Thrown when a resource is not found (404).
52
+ */
53
+ class NotFoundError extends XCropError {
54
+ constructor(message, headers = {}) {
55
+ super(message, 404, 'NOT_FOUND', headers);
56
+ this.name = 'NotFoundError';
57
+ }
58
+ }
59
+ exports.NotFoundError = NotFoundError;
60
+ /**
61
+ * Thrown when the request is forbidden (403).
62
+ */
63
+ class ForbiddenError extends XCropError {
64
+ constructor(message, headers = {}) {
65
+ super(message, 403, 'FORBIDDEN', headers);
66
+ this.name = 'ForbiddenError';
67
+ }
68
+ }
69
+ exports.ForbiddenError = ForbiddenError;
70
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1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