@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,46 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Extra detail the API adds to some errors (404s), e.g. `suspended`,
|
|
10
|
+
* `deactivated`, `not_found`. null when the response carried none.
|
|
11
|
+
*/
|
|
12
|
+
readonly reason: string | null;
|
|
13
|
+
constructor(message: string, status: number, code: string, headers?: Record<string, string>, reason?: string | null);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Thrown when authentication fails (401).
|
|
17
|
+
*/
|
|
18
|
+
export declare class AuthError extends XCropError {
|
|
19
|
+
constructor(message: string, headers?: Record<string, string>);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown when rate limit is exceeded (429).
|
|
23
|
+
* Contains retry timing information.
|
|
24
|
+
*/
|
|
25
|
+
export declare class RateLimitError extends XCropError {
|
|
26
|
+
readonly retryAfter: number | null;
|
|
27
|
+
readonly remaining: number;
|
|
28
|
+
readonly limit: number;
|
|
29
|
+
constructor(message: string, headers?: Record<string, string>);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Thrown when a resource is not found (404).
|
|
33
|
+
*
|
|
34
|
+
* `code` is the API's code: `NOT_FOUND` (default), `USER_SUSPENDED` or
|
|
35
|
+
* `USER_UNAVAILABLE` (with `reason`, e.g. `suspended` / `deactivated`).
|
|
36
|
+
*/
|
|
37
|
+
export declare class NotFoundError extends XCropError {
|
|
38
|
+
constructor(message: string, headers?: Record<string, string>, code?: string, reason?: string | null);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Thrown when the request is forbidden (403).
|
|
42
|
+
*/
|
|
43
|
+
export declare class ForbiddenError extends XCropError {
|
|
44
|
+
constructor(message: string, headers?: Record<string, string>);
|
|
45
|
+
}
|
|
46
|
+
//# 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;IAChD;;;OAGG;IACH,SAAgB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAGpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,MAAM,GAAE,MAAM,GAAG,IAAW;CAU/B;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;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,UAAU;gBAEzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,IAAI,GAAE,MAAoB,EAC1B,MAAM,GAAE,MAAM,GAAG,IAAW;CAK/B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,UAAU;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;CAIlE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all XCROP SDK errors.
|
|
3
|
+
*/
|
|
4
|
+
export class XCropError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
code;
|
|
7
|
+
headers;
|
|
8
|
+
/**
|
|
9
|
+
* Extra detail the API adds to some errors (404s), e.g. `suspended`,
|
|
10
|
+
* `deactivated`, `not_found`. null when the response carried none.
|
|
11
|
+
*/
|
|
12
|
+
reason;
|
|
13
|
+
constructor(message, status, code, headers = {}, reason = null) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'XCropError';
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.headers = headers;
|
|
19
|
+
this.reason = reason;
|
|
20
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when authentication fails (401).
|
|
25
|
+
*/
|
|
26
|
+
export class AuthError extends XCropError {
|
|
27
|
+
constructor(message, headers = {}) {
|
|
28
|
+
super(message, 401, 'AUTH_ERROR', headers);
|
|
29
|
+
this.name = 'AuthError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when rate limit is exceeded (429).
|
|
34
|
+
* Contains retry timing information.
|
|
35
|
+
*/
|
|
36
|
+
export class RateLimitError extends XCropError {
|
|
37
|
+
retryAfter;
|
|
38
|
+
remaining;
|
|
39
|
+
limit;
|
|
40
|
+
constructor(message, headers = {}) {
|
|
41
|
+
super(message, 429, 'RATE_LIMIT', headers);
|
|
42
|
+
this.name = 'RateLimitError';
|
|
43
|
+
this.retryAfter = headers['retry-after']
|
|
44
|
+
? parseInt(headers['retry-after'], 10)
|
|
45
|
+
: null;
|
|
46
|
+
this.remaining = parseInt(headers['x-ratelimit-remaining'] || '0', 10);
|
|
47
|
+
this.limit = parseInt(headers['x-ratelimit-limit'] || '0', 10);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when a resource is not found (404).
|
|
52
|
+
*
|
|
53
|
+
* `code` is the API's code: `NOT_FOUND` (default), `USER_SUSPENDED` or
|
|
54
|
+
* `USER_UNAVAILABLE` (with `reason`, e.g. `suspended` / `deactivated`).
|
|
55
|
+
*/
|
|
56
|
+
export class NotFoundError extends XCropError {
|
|
57
|
+
constructor(message, headers = {}, code = 'NOT_FOUND', reason = null) {
|
|
58
|
+
super(message, 404, code, headers, reason);
|
|
59
|
+
this.name = 'NotFoundError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Thrown when the request is forbidden (403).
|
|
64
|
+
*/
|
|
65
|
+
export class ForbiddenError extends XCropError {
|
|
66
|
+
constructor(message, headers = {}) {
|
|
67
|
+
super(message, 403, 'FORBIDDEN', headers);
|
|
68
|
+
this.name = 'ForbiddenError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,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;AAED;;GAEG;AACH,MAAM,OAAO,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;AAED;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5B,UAAU,CAAgB;IAC1B,SAAS,CAAS;IAClB,KAAK,CAAS;IAE9B,YACE,OAAe,EACf,UAAkC,EAAE;QAEpC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;YACtC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;YACtC,CAAC,CAAC,IAAI,CAAC;QACT,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,uBAAuB,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YACE,OAAe,EACf,UAAkC,EAAE,EACpC,OAAe,WAAW,EAC1B,SAAwB,IAAI;QAE5B,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAY,OAAe,EAAE,UAAkC,EAAE;QAC/D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ApiResponse, PaginatedResponse, 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/esm/http.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { XCropError, AuthError, RateLimitError, NotFoundError, ForbiddenError, } from './errors.js';
|
|
2
|
+
const DEFAULT_BASE_URL = 'https://xcrop.io/api/v2';
|
|
3
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
4
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
5
|
+
/** SDK version — single source of truth */
|
|
6
|
+
export const SDK_VERSION = '1.1.0';
|
|
7
|
+
const USER_AGENT = `@xcrop/sdk/${SDK_VERSION}`;
|
|
8
|
+
/**
|
|
9
|
+
* Low-level HTTP client with automatic retry, backoff, and error mapping.
|
|
10
|
+
*/
|
|
11
|
+
export class HttpClient {
|
|
12
|
+
apiKey;
|
|
13
|
+
baseUrl;
|
|
14
|
+
timeout;
|
|
15
|
+
maxRetries;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.apiKey = options.apiKey;
|
|
18
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
19
|
+
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
20
|
+
this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
21
|
+
}
|
|
22
|
+
async request(options) {
|
|
23
|
+
const { method, path, query, body, noRetry, signal } = options;
|
|
24
|
+
const url = this.buildUrl(path, query);
|
|
25
|
+
const headers = {
|
|
26
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
'User-Agent': USER_AGENT,
|
|
29
|
+
};
|
|
30
|
+
const maxAttempts = noRetry ? 1 : this.maxRetries + 1;
|
|
31
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
32
|
+
try {
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
35
|
+
// If an external signal is provided, link it
|
|
36
|
+
if (signal) {
|
|
37
|
+
if (signal.aborted) {
|
|
38
|
+
clearTimeout(timeoutId);
|
|
39
|
+
throw new XCropError('Request aborted', 0, 'ABORTED');
|
|
40
|
+
}
|
|
41
|
+
signal.addEventListener('abort', () => controller.abort(), { once: true });
|
|
42
|
+
}
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method,
|
|
45
|
+
headers,
|
|
46
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
47
|
+
signal: controller.signal,
|
|
48
|
+
});
|
|
49
|
+
clearTimeout(timeoutId);
|
|
50
|
+
const responseHeaders = extractHeaders(response.headers);
|
|
51
|
+
if (response.ok) {
|
|
52
|
+
const json = await response.json();
|
|
53
|
+
return json;
|
|
54
|
+
}
|
|
55
|
+
// Parse error body
|
|
56
|
+
let errorBody = {};
|
|
57
|
+
try {
|
|
58
|
+
errorBody = await response.json();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// ignore parse errors
|
|
62
|
+
}
|
|
63
|
+
const errorMessage = errorBody.error ?? `HTTP ${response.status}`;
|
|
64
|
+
const errorCode = errorBody.code ?? `HTTP_${response.status}`;
|
|
65
|
+
// Non-retryable errors
|
|
66
|
+
if (response.status === 401) {
|
|
67
|
+
throw new AuthError(errorMessage, responseHeaders);
|
|
68
|
+
}
|
|
69
|
+
if (response.status === 403) {
|
|
70
|
+
throw new ForbiddenError(errorMessage, responseHeaders);
|
|
71
|
+
}
|
|
72
|
+
if (response.status === 404) {
|
|
73
|
+
throw new NotFoundError(errorMessage, responseHeaders, errorBody.code, errorBody.reason ?? null);
|
|
74
|
+
}
|
|
75
|
+
// Retryable: 429 rate limit
|
|
76
|
+
if (response.status === 429) {
|
|
77
|
+
if (attempt < maxAttempts - 1) {
|
|
78
|
+
const retryAfter = parseInt(responseHeaders['retry-after'] || '', 10);
|
|
79
|
+
const delay = retryAfter > 0
|
|
80
|
+
? retryAfter * 1000
|
|
81
|
+
: backoffDelay(attempt);
|
|
82
|
+
await sleep(delay);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
throw new RateLimitError(errorMessage, responseHeaders);
|
|
86
|
+
}
|
|
87
|
+
// Retryable: 5xx server errors
|
|
88
|
+
if (response.status >= 500) {
|
|
89
|
+
if (attempt < maxAttempts - 1) {
|
|
90
|
+
await sleep(backoffDelay(attempt));
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
throw new XCropError(errorMessage, response.status, errorCode, responseHeaders, errorBody.reason ?? null);
|
|
94
|
+
}
|
|
95
|
+
// Other 4xx — not retryable
|
|
96
|
+
throw new XCropError(errorMessage, response.status, errorCode, responseHeaders, errorBody.reason ?? null);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (err instanceof XCropError)
|
|
100
|
+
throw err;
|
|
101
|
+
// Abort / timeout
|
|
102
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
103
|
+
if (attempt < maxAttempts - 1) {
|
|
104
|
+
await sleep(backoffDelay(attempt));
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
throw new XCropError(`Request timed out after ${this.timeout}ms`, 0, 'TIMEOUT');
|
|
108
|
+
}
|
|
109
|
+
// Network errors — retry
|
|
110
|
+
if (attempt < maxAttempts - 1) {
|
|
111
|
+
await sleep(backoffDelay(attempt));
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
throw new XCropError(err.message ?? 'Network error', 0, 'NETWORK_ERROR');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Should never reach here
|
|
118
|
+
throw new XCropError('Max retries exceeded', 0, 'MAX_RETRIES');
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Execute a request and return a raw Response for streaming.
|
|
122
|
+
* Includes retry logic for 429/5xx (same as request()).
|
|
123
|
+
* Timeout only applies to the initial connection, not to the stream body.
|
|
124
|
+
*/
|
|
125
|
+
async requestRaw(options) {
|
|
126
|
+
const { method, path, query, body, signal: externalSignal } = options;
|
|
127
|
+
const url = this.buildUrl(path, query);
|
|
128
|
+
const headers = {
|
|
129
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
'User-Agent': USER_AGENT,
|
|
132
|
+
'Accept': 'text/event-stream',
|
|
133
|
+
};
|
|
134
|
+
const maxAttempts = this.maxRetries + 1;
|
|
135
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
136
|
+
try {
|
|
137
|
+
// For streaming: only timeout the initial connection, not the full stream
|
|
138
|
+
const connectController = new AbortController();
|
|
139
|
+
const connectTimeout = setTimeout(() => connectController.abort(), this.timeout);
|
|
140
|
+
// Link external signal (for .close() cancellation)
|
|
141
|
+
if (externalSignal) {
|
|
142
|
+
if (externalSignal.aborted) {
|
|
143
|
+
clearTimeout(connectTimeout);
|
|
144
|
+
throw new XCropError('Request aborted', 0, 'ABORTED');
|
|
145
|
+
}
|
|
146
|
+
externalSignal.addEventListener('abort', () => connectController.abort(), { once: true });
|
|
147
|
+
}
|
|
148
|
+
const response = await fetch(url, {
|
|
149
|
+
method,
|
|
150
|
+
headers,
|
|
151
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
152
|
+
signal: connectController.signal,
|
|
153
|
+
});
|
|
154
|
+
// Connection established — clear the connect timeout
|
|
155
|
+
// The stream can now read for as long as needed
|
|
156
|
+
clearTimeout(connectTimeout);
|
|
157
|
+
if (response.ok) {
|
|
158
|
+
return response;
|
|
159
|
+
}
|
|
160
|
+
const responseHeaders = extractHeaders(response.headers);
|
|
161
|
+
let errorBody = {};
|
|
162
|
+
try {
|
|
163
|
+
errorBody = await response.json();
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// ignore
|
|
167
|
+
}
|
|
168
|
+
const msg = errorBody.error ?? `HTTP ${response.status}`;
|
|
169
|
+
// Non-retryable
|
|
170
|
+
if (response.status === 401)
|
|
171
|
+
throw new AuthError(msg, responseHeaders);
|
|
172
|
+
if (response.status === 403)
|
|
173
|
+
throw new ForbiddenError(msg, responseHeaders);
|
|
174
|
+
if (response.status === 404)
|
|
175
|
+
throw new NotFoundError(msg, responseHeaders, errorBody.code, errorBody.reason ?? null);
|
|
176
|
+
// Retryable: 429
|
|
177
|
+
if (response.status === 429) {
|
|
178
|
+
if (attempt < maxAttempts - 1) {
|
|
179
|
+
const retryAfter = parseInt(responseHeaders['retry-after'] || '', 10);
|
|
180
|
+
const delay = retryAfter > 0 ? retryAfter * 1000 : backoffDelay(attempt);
|
|
181
|
+
await sleep(delay);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
throw new RateLimitError(msg, responseHeaders);
|
|
185
|
+
}
|
|
186
|
+
// Retryable: 5xx
|
|
187
|
+
if (response.status >= 500) {
|
|
188
|
+
if (attempt < maxAttempts - 1) {
|
|
189
|
+
await sleep(backoffDelay(attempt));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
throw new XCropError(msg, response.status, errorBody.code ?? 'ERROR', responseHeaders, errorBody.reason ?? null);
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
if (err instanceof XCropError)
|
|
197
|
+
throw err;
|
|
198
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
199
|
+
// Check if it was an external abort (user called .close())
|
|
200
|
+
if (externalSignal?.aborted) {
|
|
201
|
+
throw new XCropError('Request aborted', 0, 'ABORTED');
|
|
202
|
+
}
|
|
203
|
+
if (attempt < maxAttempts - 1) {
|
|
204
|
+
await sleep(backoffDelay(attempt));
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
throw new XCropError(`Request timed out after ${this.timeout}ms`, 0, 'TIMEOUT');
|
|
208
|
+
}
|
|
209
|
+
if (attempt < maxAttempts - 1) {
|
|
210
|
+
await sleep(backoffDelay(attempt));
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
throw new XCropError(err.message ?? 'Network error', 0, 'NETWORK_ERROR');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
throw new XCropError('Max retries exceeded', 0, 'MAX_RETRIES');
|
|
217
|
+
}
|
|
218
|
+
buildUrl(path, query) {
|
|
219
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
220
|
+
if (query) {
|
|
221
|
+
for (const [key, value] of Object.entries(query)) {
|
|
222
|
+
if (value !== undefined && value !== null) {
|
|
223
|
+
url.searchParams.set(key, String(value));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return url.toString();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function extractHeaders(headers) {
|
|
231
|
+
const result = {};
|
|
232
|
+
headers.forEach((value, key) => {
|
|
233
|
+
result[key.toLowerCase()] = value;
|
|
234
|
+
});
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
function backoffDelay(attempt) {
|
|
238
|
+
// Exponential backoff: 1s, 2s, 4s + jitter
|
|
239
|
+
const base = Math.min(1000 * Math.pow(2, attempt), 10_000);
|
|
240
|
+
const jitter = Math.random() * 500;
|
|
241
|
+
return base + jitter;
|
|
242
|
+
}
|
|
243
|
+
function sleep(ms) {
|
|
244
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,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,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,16 @@
|
|
|
1
|
+
// Main client
|
|
2
|
+
export { XCrop } from './client.js';
|
|
3
|
+
// SDK version
|
|
4
|
+
export { SDK_VERSION } from './http.js';
|
|
5
|
+
// Error classes
|
|
6
|
+
export { XCropError, AuthError, RateLimitError, NotFoundError, ForbiddenError, } from './errors.js';
|
|
7
|
+
// Resource classes (for advanced usage / type narrowing)
|
|
8
|
+
export { UsersResource } from './resources/users.js';
|
|
9
|
+
export { TweetsResource } from './resources/tweets.js';
|
|
10
|
+
export { SearchResource, SearchStream } from './resources/search.js';
|
|
11
|
+
export { ListsResource } from './resources/lists.js';
|
|
12
|
+
export { TrendingResource } from './resources/trending.js';
|
|
13
|
+
export { CommunitiesResource } from './resources/communities.js';
|
|
14
|
+
export { AccountResource } from './resources/account.js';
|
|
15
|
+
export { StreamResource, RealtimeStream } from './resources/stream.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,cAAc;AACd,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,gBAAgB;AAChB,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,yDAAyD;AACzD,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"}
|
|
@@ -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,59 @@
|
|
|
1
|
+
export class AccountResource {
|
|
2
|
+
http;
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Connect an X account using credentials or cookies.
|
|
8
|
+
* Required for write operations (tweet, like, retweet, follow).
|
|
9
|
+
*/
|
|
10
|
+
async connect(params) {
|
|
11
|
+
const hasCredentials = params.username && params.password;
|
|
12
|
+
const hasCookies = params.cookies?.auth_token && params.cookies?.ct0;
|
|
13
|
+
if (!hasCredentials && !hasCookies) {
|
|
14
|
+
throw new Error('Either credentials (username + password) or cookies (auth_token + ct0) must be provided');
|
|
15
|
+
}
|
|
16
|
+
const body = {};
|
|
17
|
+
if (params.username)
|
|
18
|
+
body.username = params.username;
|
|
19
|
+
if (params.password)
|
|
20
|
+
body.password = params.password;
|
|
21
|
+
if (params.totp_secret)
|
|
22
|
+
body.totp_secret = params.totp_secret;
|
|
23
|
+
if (params.cookies)
|
|
24
|
+
body.cookies = params.cookies;
|
|
25
|
+
return this.http.request({
|
|
26
|
+
method: 'POST',
|
|
27
|
+
path: '/account/connect',
|
|
28
|
+
body,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check the current X account connection status.
|
|
33
|
+
*/
|
|
34
|
+
async status() {
|
|
35
|
+
return this.http.request({
|
|
36
|
+
method: 'GET',
|
|
37
|
+
path: '/account/status',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the current credit balance (plan allowance plus top-ups). Free.
|
|
42
|
+
*/
|
|
43
|
+
async credits() {
|
|
44
|
+
return this.http.request({
|
|
45
|
+
method: 'GET',
|
|
46
|
+
path: '/account/credits',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Disconnect the X account and remove stored credentials.
|
|
51
|
+
*/
|
|
52
|
+
async disconnect() {
|
|
53
|
+
return this.http.request({
|
|
54
|
+
method: 'DELETE',
|
|
55
|
+
path: '/account/disconnect',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/resources/account.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,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"}
|
|
@@ -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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X Communities data (details, timeline, members, moderators).
|
|
3
|
+
*
|
|
4
|
+
* `count` is a minimum on members and moderators: X serves whole pages, so a
|
|
5
|
+
* response can hold more rows than requested.
|
|
6
|
+
*/
|
|
7
|
+
export class CommunitiesResource {
|
|
8
|
+
http;
|
|
9
|
+
constructor(http) {
|
|
10
|
+
this.http = http;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get a community's profile.
|
|
14
|
+
*/
|
|
15
|
+
async get(communityId) {
|
|
16
|
+
return this.http.request({
|
|
17
|
+
method: 'GET',
|
|
18
|
+
path: `/communities/${encodeURIComponent(communityId)}`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get tweets from a community's timeline (latest first, no `sort` option).
|
|
23
|
+
*/
|
|
24
|
+
async tweets(communityId, params = {}) {
|
|
25
|
+
return this.http.request({
|
|
26
|
+
method: 'GET',
|
|
27
|
+
path: `/communities/${encodeURIComponent(communityId)}/tweets`,
|
|
28
|
+
query: { count: params.count, cursor: params.cursor },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get members of a community.
|
|
33
|
+
*/
|
|
34
|
+
async members(communityId, params = {}) {
|
|
35
|
+
return this.http.request({
|
|
36
|
+
method: 'GET',
|
|
37
|
+
path: `/communities/${encodeURIComponent(communityId)}/members`,
|
|
38
|
+
query: { count: params.count, sort: params.sort, cursor: params.cursor },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get moderators of a community. Rows carry `community_role`.
|
|
43
|
+
*/
|
|
44
|
+
async moderators(communityId, params = {}) {
|
|
45
|
+
return this.http.request({
|
|
46
|
+
method: 'GET',
|
|
47
|
+
path: `/communities/${encodeURIComponent(communityId)}/moderators`,
|
|
48
|
+
query: { count: params.count, sort: params.sort, cursor: params.cursor },
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=communities.js.map
|