@xcrop/sdk 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +415 -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 +46 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +79 -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 +28 -0
- package/dist/cjs/resources/account.d.ts.map +1 -0
- package/dist/cjs/resources/account.js +63 -0
- package/dist/cjs/resources/account.js.map +1 -0
- package/dist/cjs/resources/communities.d.ts +29 -0
- package/dist/cjs/resources/communities.d.ts.map +1 -0
- package/dist/cjs/resources/communities.js +56 -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 +66 -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 +90 -0
- package/dist/cjs/resources/tweets.d.ts.map +1 -0
- package/dist/cjs/resources/tweets.js +202 -0
- package/dist/cjs/resources/tweets.js.map +1 -0
- package/dist/cjs/resources/users.d.ts +96 -0
- package/dist/cjs/resources/users.d.ts.map +1 -0
- package/dist/cjs/resources/users.js +238 -0
- package/dist/cjs/resources/users.js.map +1 -0
- package/dist/cjs/types.d.ts +442 -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 +46 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +71 -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 +28 -0
- package/dist/esm/resources/account.d.ts.map +1 -0
- package/dist/esm/resources/account.js +59 -0
- package/dist/esm/resources/account.js.map +1 -0
- package/dist/esm/resources/communities.d.ts +29 -0
- package/dist/esm/resources/communities.d.ts.map +1 -0
- package/dist/esm/resources/communities.js +52 -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 +61 -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 +90 -0
- package/dist/esm/resources/tweets.d.ts.map +1 -0
- package/dist/esm/resources/tweets.js +197 -0
- package/dist/esm/resources/tweets.js.map +1 -0
- package/dist/esm/resources/users.d.ts +96 -0
- package/dist/esm/resources/users.d.ts.map +1 -0
- package/dist/esm/resources/users.js +233 -0
- package/dist/esm/resources/users.js.map +1 -0
- package/dist/esm/types.d.ts +442 -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,79 @@
|
|
|
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
|
+
/**
|
|
12
|
+
* Extra detail the API adds to some errors (404s), e.g. `suspended`,
|
|
13
|
+
* `deactivated`, `not_found`. null when the response carried none.
|
|
14
|
+
*/
|
|
15
|
+
reason;
|
|
16
|
+
constructor(message, status, code, headers = {}, reason = null) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'XCropError';
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.headers = headers;
|
|
22
|
+
this.reason = reason;
|
|
23
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.XCropError = XCropError;
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when authentication fails (401).
|
|
29
|
+
*/
|
|
30
|
+
class AuthError extends XCropError {
|
|
31
|
+
constructor(message, headers = {}) {
|
|
32
|
+
super(message, 401, 'AUTH_ERROR', headers);
|
|
33
|
+
this.name = 'AuthError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.AuthError = AuthError;
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when rate limit is exceeded (429).
|
|
39
|
+
* Contains retry timing information.
|
|
40
|
+
*/
|
|
41
|
+
class RateLimitError extends XCropError {
|
|
42
|
+
retryAfter;
|
|
43
|
+
remaining;
|
|
44
|
+
limit;
|
|
45
|
+
constructor(message, headers = {}) {
|
|
46
|
+
super(message, 429, 'RATE_LIMIT', headers);
|
|
47
|
+
this.name = 'RateLimitError';
|
|
48
|
+
this.retryAfter = headers['retry-after']
|
|
49
|
+
? parseInt(headers['retry-after'], 10)
|
|
50
|
+
: null;
|
|
51
|
+
this.remaining = parseInt(headers['x-ratelimit-remaining'] || '0', 10);
|
|
52
|
+
this.limit = parseInt(headers['x-ratelimit-limit'] || '0', 10);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.RateLimitError = RateLimitError;
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when a resource is not found (404).
|
|
58
|
+
*
|
|
59
|
+
* `code` is the API's code: `NOT_FOUND` (default), `USER_SUSPENDED` or
|
|
60
|
+
* `USER_UNAVAILABLE` (with `reason`, e.g. `suspended` / `deactivated`).
|
|
61
|
+
*/
|
|
62
|
+
class NotFoundError extends XCropError {
|
|
63
|
+
constructor(message, headers = {}, code = 'NOT_FOUND', reason = null) {
|
|
64
|
+
super(message, 404, code, headers, reason);
|
|
65
|
+
this.name = 'NotFoundError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.NotFoundError = NotFoundError;
|
|
69
|
+
/**
|
|
70
|
+
* Thrown when the request is forbidden (403).
|
|
71
|
+
*/
|
|
72
|
+
class ForbiddenError extends XCropError {
|
|
73
|
+
constructor(message, headers = {}) {
|
|
74
|
+
super(message, 403, 'FORBIDDEN', headers);
|
|
75
|
+
this.name = 'ForbiddenError';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ForbiddenError = ForbiddenError;
|
|
79
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,OAAO,CAAyB;IAChD;;;OAGG;IACa,MAAM,CAAgB;IAEtC,YACE,OAAe,EACf,MAAc,EACd,IAAY,EACZ,UAAkC,EAAE,EACpC,SAAwB,IAAI;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAzBD,gCAyBC;AAED;;GAEG;AACH,MAAa,SAAU,SAAQ,UAAU;IACvC,YAAY,OAAe,EAAE,UAAkC,EAAE;QAC/D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AALD,8BAKC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, RequestOptions, XCropOptions } from './types.js';
|
|
2
|
+
/** SDK version — single source of truth */
|
|
3
|
+
export declare const SDK_VERSION = "1.1.0";
|
|
4
|
+
/**
|
|
5
|
+
* Low-level HTTP client with automatic retry, backoff, and error mapping.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HttpClient {
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
private readonly timeout;
|
|
11
|
+
private readonly maxRetries;
|
|
12
|
+
constructor(options: XCropOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Execute a request with automatic retry on 429 and 5xx errors.
|
|
15
|
+
* Returns the parsed JSON response with proper typing for both
|
|
16
|
+
* single-item and paginated responses.
|
|
17
|
+
*/
|
|
18
|
+
request<T>(options: RequestOptions): Promise<ApiResponse<T>>;
|
|
19
|
+
request<T>(options: RequestOptions): Promise<PaginatedResponse<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Execute a request and return a raw Response for streaming.
|
|
22
|
+
* Includes retry logic for 429/5xx (same as request()).
|
|
23
|
+
* Timeout only applies to the initial connection, not to the stream body.
|
|
24
|
+
*/
|
|
25
|
+
requestRaw(options: RequestOptions): Promise<Response>;
|
|
26
|
+
private buildUrl;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM/F,2CAA2C;AAC3C,eAAO,MAAM,WAAW,UAAU,CAAC;AAGnC;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,EAAE,YAAY;IAOjC;;;;OAIG;IACG,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IA2HxE;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgH5D,OAAO,CAAC,QAAQ;CAcjB"}
|
package/dist/cjs/http.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = exports.SDK_VERSION = void 0;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
const DEFAULT_BASE_URL = 'https://xcrop.io/api/v2';
|
|
6
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
7
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
8
|
+
/** SDK version — single source of truth */
|
|
9
|
+
exports.SDK_VERSION = '1.1.0';
|
|
10
|
+
const USER_AGENT = `@xcrop/sdk/${exports.SDK_VERSION}`;
|
|
11
|
+
/**
|
|
12
|
+
* Low-level HTTP client with automatic retry, backoff, and error mapping.
|
|
13
|
+
*/
|
|
14
|
+
class HttpClient {
|
|
15
|
+
apiKey;
|
|
16
|
+
baseUrl;
|
|
17
|
+
timeout;
|
|
18
|
+
maxRetries;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.apiKey = options.apiKey;
|
|
21
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
22
|
+
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
23
|
+
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
24
|
+
}
|
|
25
|
+
async request(options) {
|
|
26
|
+
const { method, path, query, body, noRetry, signal } = options;
|
|
27
|
+
const url = this.buildUrl(path, query);
|
|
28
|
+
const headers = {
|
|
29
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
'User-Agent': USER_AGENT,
|
|
32
|
+
};
|
|
33
|
+
const maxAttempts = noRetry ? 1 : this.maxRetries + 1;
|
|
34
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
35
|
+
try {
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
38
|
+
// If an external signal is provided, link it
|
|
39
|
+
if (signal) {
|
|
40
|
+
if (signal.aborted) {
|
|
41
|
+
clearTimeout(timeoutId);
|
|
42
|
+
throw new errors_js_1.XCropError('Request aborted', 0, 'ABORTED');
|
|
43
|
+
}
|
|
44
|
+
signal.addEventListener('abort', () => controller.abort(), { once: true });
|
|
45
|
+
}
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method,
|
|
48
|
+
headers,
|
|
49
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
50
|
+
signal: controller.signal,
|
|
51
|
+
});
|
|
52
|
+
clearTimeout(timeoutId);
|
|
53
|
+
const responseHeaders = extractHeaders(response.headers);
|
|
54
|
+
if (response.ok) {
|
|
55
|
+
const json = await response.json();
|
|
56
|
+
return json;
|
|
57
|
+
}
|
|
58
|
+
// Parse error body
|
|
59
|
+
let errorBody = {};
|
|
60
|
+
try {
|
|
61
|
+
errorBody = await response.json();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// ignore parse errors
|
|
65
|
+
}
|
|
66
|
+
const errorMessage = errorBody.error ?? `HTTP ${response.status}`;
|
|
67
|
+
const errorCode = errorBody.code ?? `HTTP_${response.status}`;
|
|
68
|
+
// Non-retryable errors
|
|
69
|
+
if (response.status === 401) {
|
|
70
|
+
throw new errors_js_1.AuthError(errorMessage, responseHeaders);
|
|
71
|
+
}
|
|
72
|
+
if (response.status === 403) {
|
|
73
|
+
throw new errors_js_1.ForbiddenError(errorMessage, responseHeaders);
|
|
74
|
+
}
|
|
75
|
+
if (response.status === 404) {
|
|
76
|
+
throw new errors_js_1.NotFoundError(errorMessage, responseHeaders, errorBody.code, errorBody.reason ?? null);
|
|
77
|
+
}
|
|
78
|
+
// Retryable: 429 rate limit
|
|
79
|
+
if (response.status === 429) {
|
|
80
|
+
if (attempt < maxAttempts - 1) {
|
|
81
|
+
const retryAfter = parseInt(responseHeaders['retry-after'] || '', 10);
|
|
82
|
+
const delay = retryAfter > 0
|
|
83
|
+
? retryAfter * 1000
|
|
84
|
+
: backoffDelay(attempt);
|
|
85
|
+
await sleep(delay);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
throw new errors_js_1.RateLimitError(errorMessage, responseHeaders);
|
|
89
|
+
}
|
|
90
|
+
// Retryable: 5xx server errors
|
|
91
|
+
if (response.status >= 500) {
|
|
92
|
+
if (attempt < maxAttempts - 1) {
|
|
93
|
+
await sleep(backoffDelay(attempt));
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
throw new errors_js_1.XCropError(errorMessage, response.status, errorCode, responseHeaders, errorBody.reason ?? null);
|
|
97
|
+
}
|
|
98
|
+
// Other 4xx — not retryable
|
|
99
|
+
throw new errors_js_1.XCropError(errorMessage, response.status, errorCode, responseHeaders, errorBody.reason ?? null);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err instanceof errors_js_1.XCropError)
|
|
103
|
+
throw err;
|
|
104
|
+
// Abort / timeout
|
|
105
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
106
|
+
if (attempt < maxAttempts - 1) {
|
|
107
|
+
await sleep(backoffDelay(attempt));
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
throw new errors_js_1.XCropError(`Request timed out after ${this.timeout}ms`, 0, 'TIMEOUT');
|
|
111
|
+
}
|
|
112
|
+
// Network errors — retry
|
|
113
|
+
if (attempt < maxAttempts - 1) {
|
|
114
|
+
await sleep(backoffDelay(attempt));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
throw new errors_js_1.XCropError(err.message ?? 'Network error', 0, 'NETWORK_ERROR');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Should never reach here
|
|
121
|
+
throw new errors_js_1.XCropError('Max retries exceeded', 0, 'MAX_RETRIES');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Execute a request and return a raw Response for streaming.
|
|
125
|
+
* Includes retry logic for 429/5xx (same as request()).
|
|
126
|
+
* Timeout only applies to the initial connection, not to the stream body.
|
|
127
|
+
*/
|
|
128
|
+
async requestRaw(options) {
|
|
129
|
+
const { method, path, query, body, signal: externalSignal } = options;
|
|
130
|
+
const url = this.buildUrl(path, query);
|
|
131
|
+
const headers = {
|
|
132
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
133
|
+
'Content-Type': 'application/json',
|
|
134
|
+
'User-Agent': USER_AGENT,
|
|
135
|
+
'Accept': 'text/event-stream',
|
|
136
|
+
};
|
|
137
|
+
const maxAttempts = this.maxRetries + 1;
|
|
138
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
139
|
+
try {
|
|
140
|
+
// For streaming: only timeout the initial connection, not the full stream
|
|
141
|
+
const connectController = new AbortController();
|
|
142
|
+
const connectTimeout = setTimeout(() => connectController.abort(), this.timeout);
|
|
143
|
+
// Link external signal (for .close() cancellation)
|
|
144
|
+
if (externalSignal) {
|
|
145
|
+
if (externalSignal.aborted) {
|
|
146
|
+
clearTimeout(connectTimeout);
|
|
147
|
+
throw new errors_js_1.XCropError('Request aborted', 0, 'ABORTED');
|
|
148
|
+
}
|
|
149
|
+
externalSignal.addEventListener('abort', () => connectController.abort(), { once: true });
|
|
150
|
+
}
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
method,
|
|
153
|
+
headers,
|
|
154
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
155
|
+
signal: connectController.signal,
|
|
156
|
+
});
|
|
157
|
+
// Connection established — clear the connect timeout
|
|
158
|
+
// The stream can now read for as long as needed
|
|
159
|
+
clearTimeout(connectTimeout);
|
|
160
|
+
if (response.ok) {
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
const responseHeaders = extractHeaders(response.headers);
|
|
164
|
+
let errorBody = {};
|
|
165
|
+
try {
|
|
166
|
+
errorBody = await response.json();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// ignore
|
|
170
|
+
}
|
|
171
|
+
const msg = errorBody.error ?? `HTTP ${response.status}`;
|
|
172
|
+
// Non-retryable
|
|
173
|
+
if (response.status === 401)
|
|
174
|
+
throw new errors_js_1.AuthError(msg, responseHeaders);
|
|
175
|
+
if (response.status === 403)
|
|
176
|
+
throw new errors_js_1.ForbiddenError(msg, responseHeaders);
|
|
177
|
+
if (response.status === 404)
|
|
178
|
+
throw new errors_js_1.NotFoundError(msg, responseHeaders, errorBody.code, errorBody.reason ?? null);
|
|
179
|
+
// Retryable: 429
|
|
180
|
+
if (response.status === 429) {
|
|
181
|
+
if (attempt < maxAttempts - 1) {
|
|
182
|
+
const retryAfter = parseInt(responseHeaders['retry-after'] || '', 10);
|
|
183
|
+
const delay = retryAfter > 0 ? retryAfter * 1000 : backoffDelay(attempt);
|
|
184
|
+
await sleep(delay);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
throw new errors_js_1.RateLimitError(msg, responseHeaders);
|
|
188
|
+
}
|
|
189
|
+
// Retryable: 5xx
|
|
190
|
+
if (response.status >= 500) {
|
|
191
|
+
if (attempt < maxAttempts - 1) {
|
|
192
|
+
await sleep(backoffDelay(attempt));
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw new errors_js_1.XCropError(msg, response.status, errorBody.code ?? 'ERROR', responseHeaders, errorBody.reason ?? null);
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
if (err instanceof errors_js_1.XCropError)
|
|
200
|
+
throw err;
|
|
201
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
202
|
+
// Check if it was an external abort (user called .close())
|
|
203
|
+
if (externalSignal?.aborted) {
|
|
204
|
+
throw new errors_js_1.XCropError('Request aborted', 0, 'ABORTED');
|
|
205
|
+
}
|
|
206
|
+
if (attempt < maxAttempts - 1) {
|
|
207
|
+
await sleep(backoffDelay(attempt));
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
throw new errors_js_1.XCropError(`Request timed out after ${this.timeout}ms`, 0, 'TIMEOUT');
|
|
211
|
+
}
|
|
212
|
+
if (attempt < maxAttempts - 1) {
|
|
213
|
+
await sleep(backoffDelay(attempt));
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
throw new errors_js_1.XCropError(err.message ?? 'Network error', 0, 'NETWORK_ERROR');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
throw new errors_js_1.XCropError('Max retries exceeded', 0, 'MAX_RETRIES');
|
|
220
|
+
}
|
|
221
|
+
buildUrl(path, query) {
|
|
222
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
223
|
+
if (query) {
|
|
224
|
+
for (const [key, value] of Object.entries(query)) {
|
|
225
|
+
if (value !== undefined && value !== null) {
|
|
226
|
+
url.searchParams.set(key, String(value));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return url.toString();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.HttpClient = HttpClient;
|
|
234
|
+
function extractHeaders(headers) {
|
|
235
|
+
const result = {};
|
|
236
|
+
headers.forEach((value, key) => {
|
|
237
|
+
result[key.toLowerCase()] = value;
|
|
238
|
+
});
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
function backoffDelay(attempt) {
|
|
242
|
+
// Exponential backoff: 1s, 2s, 4s + jitter
|
|
243
|
+
const base = Math.min(1000 * Math.pow(2, attempt), 10_000);
|
|
244
|
+
const jitter = Math.random() * 500;
|
|
245
|
+
return base + jitter;
|
|
246
|
+
}
|
|
247
|
+
function sleep(ms) {
|
|
248
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA,2CAMqB;AAGrB,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,2CAA2C;AAC9B,QAAA,WAAW,GAAG,OAAO,CAAC;AACnC,MAAM,UAAU,GAAG,cAAc,mBAAW,EAAE,CAAC;AAE/C;;GAEG;AACH,MAAa,UAAU;IACJ,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,UAAU,CAAS;IAEpC,YAAY,OAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;IAC9D,CAAC;IASD,KAAK,CAAC,OAAO,CAAI,OAAuB;QACtC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE/D,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,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;QACH,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;CACF;AAjRD,gCAiRC;AAED,SAAS,cAAc,CAAC,OAAgB;IACtC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACnC,2CAA2C;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;IACnC,OAAO,IAAI,GAAG,MAAM,CAAC;AACvB,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { XCrop } from './client.js';
|
|
2
|
+
export { SDK_VERSION } from './http.js';
|
|
3
|
+
export { XCropError, AuthError, RateLimitError, NotFoundError, ForbiddenError, } from './errors.js';
|
|
4
|
+
export { UsersResource } from './resources/users.js';
|
|
5
|
+
export { TweetsResource } from './resources/tweets.js';
|
|
6
|
+
export { SearchResource, SearchStream } from './resources/search.js';
|
|
7
|
+
export { ListsResource } from './resources/lists.js';
|
|
8
|
+
export { TrendingResource } from './resources/trending.js';
|
|
9
|
+
export { CommunitiesResource } from './resources/communities.js';
|
|
10
|
+
export { AccountResource } from './resources/account.js';
|
|
11
|
+
export { StreamResource, RealtimeStream } from './resources/stream.js';
|
|
12
|
+
export type { XCropOptions, ApiMeta, ApiResponse, ApiErrorResponse, XCropErrorCode, PaginationParams, PaginatedResponse, User, UserAffiliation, CheckFollowResult, Tweet, TweetMetrics, TweetInReplyTo, TweetEntities, TweetEdit, TweetPlace, TweetCard, Media, UrlEntity, List, TrendingTopic, TrendingParams, Community, SearchTweetsParams, SearchUsersParams, ConnectAccountParams, AccountStatus, AccountCredits, CreateTweetParams, ReplyTweetParams, QuoteTweetParams, WriteResult, InteractionCheckResult, QualifiedAccountParams, QualifiedAccountResult, QualifiedNameParams, QualifiedNameResult, FollowersIdsParams, FollowersIdsMeta, FollowersIdsResponse, CommunityTweetsParams, CommunityMembersParams, CommunityModeratorsParams, TimeWindowParams, UserLookupParams, UserPaginationParams, UserListParams, UserMentionsParams, TweetQuotesParams, ConversationParams, StreamOptions, StreamEvent, RequestOptions, } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,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,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvE,YAAY,EAEV,YAAY,EAGZ,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAGjB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,KAAK,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,SAAS,EACT,UAAU,EACV,SAAS,EACT,KAAK,EACL,SAAS,EACT,IAAI,EACJ,aAAa,EACb,cAAc,EACd,SAAS,EAGT,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RealtimeStream = exports.StreamResource = exports.AccountResource = exports.CommunitiesResource = exports.TrendingResource = exports.ListsResource = exports.SearchStream = exports.SearchResource = exports.TweetsResource = exports.UsersResource = exports.ForbiddenError = exports.NotFoundError = exports.RateLimitError = exports.AuthError = exports.XCropError = exports.SDK_VERSION = exports.XCrop = void 0;
|
|
4
|
+
// Main client
|
|
5
|
+
var client_js_1 = require("./client.js");
|
|
6
|
+
Object.defineProperty(exports, "XCrop", { enumerable: true, get: function () { return client_js_1.XCrop; } });
|
|
7
|
+
// SDK version
|
|
8
|
+
var http_js_1 = require("./http.js");
|
|
9
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return http_js_1.SDK_VERSION; } });
|
|
10
|
+
// Error classes
|
|
11
|
+
var errors_js_1 = require("./errors.js");
|
|
12
|
+
Object.defineProperty(exports, "XCropError", { enumerable: true, get: function () { return errors_js_1.XCropError; } });
|
|
13
|
+
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_js_1.AuthError; } });
|
|
14
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
|
|
15
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
|
|
16
|
+
Object.defineProperty(exports, "ForbiddenError", { enumerable: true, get: function () { return errors_js_1.ForbiddenError; } });
|
|
17
|
+
// Resource classes (for advanced usage / type narrowing)
|
|
18
|
+
var users_js_1 = require("./resources/users.js");
|
|
19
|
+
Object.defineProperty(exports, "UsersResource", { enumerable: true, get: function () { return users_js_1.UsersResource; } });
|
|
20
|
+
var tweets_js_1 = require("./resources/tweets.js");
|
|
21
|
+
Object.defineProperty(exports, "TweetsResource", { enumerable: true, get: function () { return tweets_js_1.TweetsResource; } });
|
|
22
|
+
var search_js_1 = require("./resources/search.js");
|
|
23
|
+
Object.defineProperty(exports, "SearchResource", { enumerable: true, get: function () { return search_js_1.SearchResource; } });
|
|
24
|
+
Object.defineProperty(exports, "SearchStream", { enumerable: true, get: function () { return search_js_1.SearchStream; } });
|
|
25
|
+
var lists_js_1 = require("./resources/lists.js");
|
|
26
|
+
Object.defineProperty(exports, "ListsResource", { enumerable: true, get: function () { return lists_js_1.ListsResource; } });
|
|
27
|
+
var trending_js_1 = require("./resources/trending.js");
|
|
28
|
+
Object.defineProperty(exports, "TrendingResource", { enumerable: true, get: function () { return trending_js_1.TrendingResource; } });
|
|
29
|
+
var communities_js_1 = require("./resources/communities.js");
|
|
30
|
+
Object.defineProperty(exports, "CommunitiesResource", { enumerable: true, get: function () { return communities_js_1.CommunitiesResource; } });
|
|
31
|
+
var account_js_1 = require("./resources/account.js");
|
|
32
|
+
Object.defineProperty(exports, "AccountResource", { enumerable: true, get: function () { return account_js_1.AccountResource; } });
|
|
33
|
+
var stream_js_1 = require("./resources/stream.js");
|
|
34
|
+
Object.defineProperty(exports, "StreamResource", { enumerable: true, get: function () { return stream_js_1.StreamResource; } });
|
|
35
|
+
Object.defineProperty(exports, "RealtimeStream", { enumerable: true, get: function () { return stream_js_1.RealtimeStream; } });
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,cAAc;AACd,yCAAoC;AAA3B,kGAAA,KAAK,OAAA;AAEd,cAAc;AACd,qCAAwC;AAA/B,sGAAA,WAAW,OAAA;AAEpB,gBAAgB;AAChB,yCAMqB;AALnB,uGAAA,UAAU,OAAA;AACV,sGAAA,SAAS,OAAA;AACT,2GAAA,cAAc,OAAA;AACd,0GAAA,aAAa,OAAA;AACb,2GAAA,cAAc,OAAA;AAGhB,yDAAyD;AACzD,iDAAqD;AAA5C,yGAAA,aAAa,OAAA;AACtB,mDAAuD;AAA9C,2GAAA,cAAc,OAAA;AACvB,mDAAqE;AAA5D,2GAAA,cAAc,OAAA;AAAE,yGAAA,YAAY,OAAA;AACrC,iDAAqD;AAA5C,yGAAA,aAAa,OAAA;AACtB,uDAA2D;AAAlD,+GAAA,gBAAgB,OAAA;AACzB,6DAAiE;AAAxD,qHAAA,mBAAmB,OAAA;AAC5B,qDAAyD;AAAhD,6GAAA,eAAe,OAAA;AACxB,mDAAuE;AAA9D,2GAAA,cAAc,OAAA;AAAE,2GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { ConnectAccountParams, AccountStatus, AccountCredits, ApiResponse } from '../types.js';
|
|
3
|
+
export declare class AccountResource {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
/**
|
|
7
|
+
* Connect an X account using credentials or cookies.
|
|
8
|
+
* Required for write operations (tweet, like, retweet, follow).
|
|
9
|
+
*/
|
|
10
|
+
connect(params: ConnectAccountParams): Promise<ApiResponse<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
}>>;
|
|
13
|
+
/**
|
|
14
|
+
* Check the current X account connection status.
|
|
15
|
+
*/
|
|
16
|
+
status(): Promise<ApiResponse<AccountStatus>>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the current credit balance (plan allowance plus top-ups). Free.
|
|
19
|
+
*/
|
|
20
|
+
credits(): Promise<ApiResponse<AccountCredits>>;
|
|
21
|
+
/**
|
|
22
|
+
* Disconnect the X account and remove stored credentials.
|
|
23
|
+
*/
|
|
24
|
+
disconnect(): Promise<ApiResponse<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
}>>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/resources/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;OAGG;IACG,OAAO,CACX,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAuB7C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAOnD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAOrD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAM/D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountResource = void 0;
|
|
4
|
+
class AccountResource {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Connect an X account using credentials or cookies.
|
|
11
|
+
* Required for write operations (tweet, like, retweet, follow).
|
|
12
|
+
*/
|
|
13
|
+
async connect(params) {
|
|
14
|
+
const hasCredentials = params.username && params.password;
|
|
15
|
+
const hasCookies = params.cookies?.auth_token && params.cookies?.ct0;
|
|
16
|
+
if (!hasCredentials && !hasCookies) {
|
|
17
|
+
throw new Error('Either credentials (username + password) or cookies (auth_token + ct0) must be provided');
|
|
18
|
+
}
|
|
19
|
+
const body = {};
|
|
20
|
+
if (params.username)
|
|
21
|
+
body.username = params.username;
|
|
22
|
+
if (params.password)
|
|
23
|
+
body.password = params.password;
|
|
24
|
+
if (params.totp_secret)
|
|
25
|
+
body.totp_secret = params.totp_secret;
|
|
26
|
+
if (params.cookies)
|
|
27
|
+
body.cookies = params.cookies;
|
|
28
|
+
return this.http.request({
|
|
29
|
+
method: 'POST',
|
|
30
|
+
path: '/account/connect',
|
|
31
|
+
body,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check the current X account connection status.
|
|
36
|
+
*/
|
|
37
|
+
async status() {
|
|
38
|
+
return this.http.request({
|
|
39
|
+
method: 'GET',
|
|
40
|
+
path: '/account/status',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the current credit balance (plan allowance plus top-ups). Free.
|
|
45
|
+
*/
|
|
46
|
+
async credits() {
|
|
47
|
+
return this.http.request({
|
|
48
|
+
method: 'GET',
|
|
49
|
+
path: '/account/credits',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Disconnect the X account and remove stored credentials.
|
|
54
|
+
*/
|
|
55
|
+
async disconnect() {
|
|
56
|
+
return this.http.request({
|
|
57
|
+
method: 'DELETE',
|
|
58
|
+
path: '/account/disconnect',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AccountResource = AccountResource;
|
|
63
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/resources/account.ts"],"names":[],"mappings":";;;AAQA,MAAa,eAAe;IACG;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;;OAGG;IACH,KAAK,CAAC,OAAO,CACX,MAA4B;QAE5B,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC;QAC1D,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,EAAE,UAAU,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;QAErE,IAAI,CAAC,cAAc,IAAI,CAAC,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,IAAI,MAAM,CAAC,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrD,IAAI,MAAM,CAAC,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrD,IAAI,MAAM,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QAC9D,IAAI,MAAM,CAAC,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAElD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAuB;YAC7C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,kBAAkB;YACxB,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB;YACtC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,iBAAiB;SACxB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAiB;YACvC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAuB;YAC7C,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,qBAAqB;SAC5B,CAAC,CAAC;IACL,CAAC;CACF;AA7DD,0CA6DC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { Community, Tweet, User, PaginatedResponse, ApiResponse, CommunityTweetsParams, CommunityMembersParams, CommunityModeratorsParams } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* X Communities data (details, timeline, members, moderators).
|
|
5
|
+
*
|
|
6
|
+
* `count` is a minimum on members and moderators: X serves whole pages, so a
|
|
7
|
+
* response can hold more rows than requested.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CommunitiesResource {
|
|
10
|
+
private readonly http;
|
|
11
|
+
constructor(http: HttpClient);
|
|
12
|
+
/**
|
|
13
|
+
* Get a community's profile.
|
|
14
|
+
*/
|
|
15
|
+
get(communityId: string): Promise<ApiResponse<Community>>;
|
|
16
|
+
/**
|
|
17
|
+
* Get tweets from a community's timeline (latest first, no `sort` option).
|
|
18
|
+
*/
|
|
19
|
+
tweets(communityId: string, params?: CommunityTweetsParams): Promise<PaginatedResponse<Tweet>>;
|
|
20
|
+
/**
|
|
21
|
+
* Get members of a community.
|
|
22
|
+
*/
|
|
23
|
+
members(communityId: string, params?: CommunityMembersParams): Promise<PaginatedResponse<User>>;
|
|
24
|
+
/**
|
|
25
|
+
* Get moderators of a community. Rows carry `community_role`.
|
|
26
|
+
*/
|
|
27
|
+
moderators(communityId: string, params?: CommunityModeratorsParams): Promise<PaginatedResponse<User>>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=communities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"communities.d.ts","sourceRoot":"","sources":["../../../src/resources/communities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,IAAI,EACJ,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;OAEG;IACG,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAO/D;;OAEG;IACG,MAAM,CACV,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,qBAA0B,GACjC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAQpC;;OAEG;IACG,OAAO,CACX,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,sBAA2B,GAClC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAQnC;;OAEG;IACG,UAAU,CACd,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,yBAA8B,GACrC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAOpC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommunitiesResource = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* X Communities data (details, timeline, members, moderators).
|
|
6
|
+
*
|
|
7
|
+
* `count` is a minimum on members and moderators: X serves whole pages, so a
|
|
8
|
+
* response can hold more rows than requested.
|
|
9
|
+
*/
|
|
10
|
+
class CommunitiesResource {
|
|
11
|
+
http;
|
|
12
|
+
constructor(http) {
|
|
13
|
+
this.http = http;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a community's profile.
|
|
17
|
+
*/
|
|
18
|
+
async get(communityId) {
|
|
19
|
+
return this.http.request({
|
|
20
|
+
method: 'GET',
|
|
21
|
+
path: `/communities/${encodeURIComponent(communityId)}`,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get tweets from a community's timeline (latest first, no `sort` option).
|
|
26
|
+
*/
|
|
27
|
+
async tweets(communityId, params = {}) {
|
|
28
|
+
return this.http.request({
|
|
29
|
+
method: 'GET',
|
|
30
|
+
path: `/communities/${encodeURIComponent(communityId)}/tweets`,
|
|
31
|
+
query: { count: params.count, cursor: params.cursor },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get members of a community.
|
|
36
|
+
*/
|
|
37
|
+
async members(communityId, params = {}) {
|
|
38
|
+
return this.http.request({
|
|
39
|
+
method: 'GET',
|
|
40
|
+
path: `/communities/${encodeURIComponent(communityId)}/members`,
|
|
41
|
+
query: { count: params.count, sort: params.sort, cursor: params.cursor },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get moderators of a community. Rows carry `community_role`.
|
|
46
|
+
*/
|
|
47
|
+
async moderators(communityId, params = {}) {
|
|
48
|
+
return this.http.request({
|
|
49
|
+
method: 'GET',
|
|
50
|
+
path: `/communities/${encodeURIComponent(communityId)}/moderators`,
|
|
51
|
+
query: { count: params.count, sort: params.sort, cursor: params.cursor },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CommunitiesResource = CommunitiesResource;
|
|
56
|
+
//# sourceMappingURL=communities.js.map
|