@crosspost/sdk 0.1.2 → 0.1.3

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NearAuthData } from 'near-sign-verify';
2
- import { NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, ApiError, PlatformError } from '@crosspost/types';
2
+ import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError, PlatformError, ApiErrorCode } from '@crosspost/types';
3
3
  export * from '@crosspost/types';
4
4
 
5
5
  /**
@@ -14,7 +14,7 @@ interface RequestOptions {
14
14
  * NEAR authentication data for generating auth tokens
15
15
  * Can be undefined if not authorize yet
16
16
  */
17
- signature?: NearAuthData;
17
+ nearAuthData?: NearAuthData;
18
18
  /**
19
19
  * Request timeout in milliseconds
20
20
  */
@@ -25,6 +25,38 @@ interface RequestOptions {
25
25
  retries: number;
26
26
  }
27
27
 
28
+ /**
29
+ * Activity-related API operations
30
+ */
31
+ declare class ActivityApi {
32
+ private options;
33
+ /**
34
+ * Creates an instance of ActivityApi
35
+ * @param options Request options
36
+ */
37
+ constructor(options: RequestOptions);
38
+ /**
39
+ * Gets the global activity leaderboard
40
+ * @param query Optional query parameters
41
+ * @returns A promise resolving with the leaderboard response
42
+ */
43
+ getLeaderboard(query?: ActivityLeaderboardQuery): Promise<ActivityLeaderboardResponse>;
44
+ /**
45
+ * Gets activity for a specific account
46
+ * @param signerId The NEAR account ID
47
+ * @param query Optional query parameters
48
+ * @returns A promise resolving with the account activity response
49
+ */
50
+ getAccountActivity(signerId: string, query?: AccountActivityQuery): Promise<AccountActivityResponse>;
51
+ /**
52
+ * Gets posts for a specific account
53
+ * @param signerId The NEAR account ID
54
+ * @param query Optional query parameters
55
+ * @returns A promise resolving with the account posts response
56
+ */
57
+ getAccountPosts(signerId: string, query?: AccountPostsQuery): Promise<AccountPostsResponse>;
58
+ }
59
+
28
60
  /**
29
61
  * Authentication-related API operations
30
62
  */
@@ -141,19 +173,50 @@ declare class PostApi {
141
173
  deletePost(request: DeletePostRequest): Promise<DeletePostResponse>;
142
174
  }
143
175
 
176
+ /**
177
+ * System-related API operations
178
+ * Includes rate limits, health checks, and other system-related functionality
179
+ */
180
+ declare class SystemApi {
181
+ private options;
182
+ /**
183
+ * Creates an instance of SystemApi
184
+ * @param options Request options
185
+ */
186
+ constructor(options: RequestOptions);
187
+ /**
188
+ * Gets the current rate limit status
189
+ * @returns A promise resolving with the rate limit response
190
+ */
191
+ getRateLimits(): Promise<RateLimitResponse>;
192
+ /**
193
+ * Gets the rate limit status for a specific endpoint
194
+ * @param endpoint The endpoint to get rate limit for
195
+ * @returns A promise resolving with the endpoint rate limit response
196
+ */
197
+ getEndpointRateLimit(endpoint: string): Promise<EndpointRateLimitResponse>;
198
+ /**
199
+ * Gets the health status of the API
200
+ * @returns A promise resolving with the health status
201
+ */
202
+ getHealthStatus(): Promise<{
203
+ status: string;
204
+ }>;
205
+ }
206
+
144
207
  /**
145
208
  * Configuration options for the CrosspostClient
146
209
  */
147
210
  interface CrosspostClientConfig {
148
211
  /**
149
212
  * Base URL for the Crosspost API
150
- * @default 'https://api.opencrosspost.com'
213
+ * @default 'https://open-crosspost-proxy.deno.dev'
151
214
  */
152
215
  baseUrl?: string;
153
216
  /**
154
217
  * NEAR authentication data obtained from near-sign-verify
155
218
  */
156
- signature?: NearAuthData;
219
+ nearAuthData?: NearAuthData;
157
220
  /**
158
221
  * Request timeout in milliseconds
159
222
  * @default 30000
@@ -170,14 +233,10 @@ interface CrosspostClientConfig {
170
233
  * Main client for interacting with the Crosspost API service.
171
234
  */
172
235
  declare class CrosspostClient {
173
- /**
174
- * Authentication-related API operations
175
- */
176
236
  readonly auth: AuthApi;
177
- /**
178
- * Post-related API operations
179
- */
180
237
  readonly post: PostApi;
238
+ readonly activity: ActivityApi;
239
+ readonly system: SystemApi;
181
240
  private readonly options;
182
241
  /**
183
242
  * Creates an instance of CrosspostClient.
@@ -188,7 +247,12 @@ declare class CrosspostClient {
188
247
  * Sets the authentication data (signature) for the client and stores it in a cookie
189
248
  * @param signature The NEAR authentication data
190
249
  */
191
- setAuthentication(signature: NearAuthData): Promise<void>;
250
+ setAuthentication(nearAuthData: NearAuthData): void;
251
+ /**
252
+ * Checks if authentication data (signature) exists on client
253
+ * @param signature The NEAR authentication data
254
+ */
255
+ isAuthenticated(): boolean;
192
256
  }
193
257
 
194
258
  /**
@@ -209,6 +273,123 @@ declare function handleErrorResponse(data: any, status: number): ApiError | Plat
209
273
  */
210
274
  declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
211
275
 
276
+ /**
277
+ * Error categories grouped by type for better organization and usage
278
+ */
279
+ declare const ERROR_CATEGORIES: {
280
+ AUTH: ApiErrorCode[];
281
+ VALIDATION: ApiErrorCode[];
282
+ NETWORK: ApiErrorCode[];
283
+ PLATFORM: ApiErrorCode[];
284
+ CONTENT: ApiErrorCode[];
285
+ RATE_LIMIT: ApiErrorCode[];
286
+ POST: ApiErrorCode[];
287
+ MEDIA: ApiErrorCode[];
288
+ };
289
+ /**
290
+ * Check if an error belongs to a specific category
291
+ *
292
+ * @param error The error to check
293
+ * @param category The category to check against
294
+ * @returns True if the error belongs to the category, false otherwise
295
+ */
296
+ declare function isErrorOfCategory(error: unknown, category: ApiErrorCode[]): boolean;
297
+ /**
298
+ * Check if an error is an authentication error
299
+ *
300
+ * @param error The error to check
301
+ * @returns True if the error is an authentication error, false otherwise
302
+ */
303
+ declare function isAuthError(error: unknown): boolean;
304
+ /**
305
+ * Check if an error is a validation error
306
+ *
307
+ * @param error The error to check
308
+ * @returns True if the error is a validation error, false otherwise
309
+ */
310
+ declare function isValidationError(error: unknown): boolean;
311
+ /**
312
+ * Check if an error is a network error
313
+ *
314
+ * @param error The error to check
315
+ * @returns True if the error is a network error, false otherwise
316
+ */
317
+ declare function isNetworkError(error: unknown): boolean;
318
+ /**
319
+ * Check if an error is a platform error
320
+ *
321
+ * @param error The error to check
322
+ * @returns True if the error is a platform error, false otherwise
323
+ */
324
+ declare function isPlatformError(error: unknown): boolean;
325
+ /**
326
+ * Check if an error is a content policy error
327
+ *
328
+ * @param error The error to check
329
+ * @returns True if the error is a content policy error, false otherwise
330
+ */
331
+ declare function isContentError(error: unknown): boolean;
332
+ /**
333
+ * Check if an error is a rate limit error
334
+ *
335
+ * @param error The error to check
336
+ * @returns True if the error is a rate limit error, false otherwise
337
+ */
338
+ declare function isRateLimitError(error: unknown): boolean;
339
+ /**
340
+ * Check if an error is a post-related error
341
+ *
342
+ * @param error The error to check
343
+ * @returns True if the error is a post-related error, false otherwise
344
+ */
345
+ declare function isPostError(error: unknown): boolean;
346
+ /**
347
+ * Check if an error is a media-related error
348
+ *
349
+ * @param error The error to check
350
+ * @returns True if the error is a media-related error, false otherwise
351
+ */
352
+ declare function isMediaError(error: unknown): boolean;
353
+ /**
354
+ * Check if an error is recoverable
355
+ *
356
+ * @param error The error to check
357
+ * @returns True if the error is recoverable, false otherwise
358
+ */
359
+ declare function isRecoverableError(error: unknown): boolean;
360
+ /**
361
+ * Get a user-friendly error message
362
+ *
363
+ * @param error The error to get the message from
364
+ * @param defaultMessage The default message to return if no message is found
365
+ * @returns The error message
366
+ */
367
+ declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
368
+ /**
369
+ * Extract error details if available
370
+ *
371
+ * @param error The error to extract details from
372
+ * @returns The error details or undefined if none are found
373
+ */
374
+ declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
375
+ /**
376
+ * Enrich an error with additional context
377
+ *
378
+ * @param error The error to enrich
379
+ * @param context The context to add to the error
380
+ * @returns The enriched error
381
+ */
382
+ declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
383
+ /**
384
+ * Wrapper for API calls with consistent error handling
385
+ *
386
+ * @param apiCall The API call to wrap
387
+ * @param context Optional context to add to any errors
388
+ * @returns The result of the API call
389
+ * @throws An enriched error if the API call fails
390
+ */
391
+ declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
392
+
212
393
  declare const AUTH_COOKIE_NAME = "__crosspost_auth";
213
394
  declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
214
395
  declare const CSRF_HEADER_NAME = "X-CSRF-Token";
@@ -233,4 +414,4 @@ declare function clearAuthCookie(): void;
233
414
  */
234
415
  declare function getCsrfToken(): string | undefined;
235
416
 
236
- export { AUTH_COOKIE_NAME, AUTH_COOKIE_OPTIONS, AuthApi, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, CrosspostClient, type CrosspostClientConfig, PostApi, clearAuthCookie, createNetworkError, getAuthFromCookie, getCsrfToken, handleErrorResponse, storeAuthInCookie };
417
+ export { AUTH_COOKIE_NAME, AUTH_COOKIE_OPTIONS, ActivityApi, AuthApi, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, clearAuthCookie, createNetworkError, enrichErrorWithContext, getAuthFromCookie, getCsrfToken, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError, storeAuthInCookie };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NearAuthData } from 'near-sign-verify';
2
- import { NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, ApiError, PlatformError } from '@crosspost/types';
2
+ import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, EnhancedApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiError, PlatformError, ApiErrorCode } from '@crosspost/types';
3
3
  export * from '@crosspost/types';
4
4
 
5
5
  /**
@@ -14,7 +14,7 @@ interface RequestOptions {
14
14
  * NEAR authentication data for generating auth tokens
15
15
  * Can be undefined if not authorize yet
16
16
  */
17
- signature?: NearAuthData;
17
+ nearAuthData?: NearAuthData;
18
18
  /**
19
19
  * Request timeout in milliseconds
20
20
  */
@@ -25,6 +25,38 @@ interface RequestOptions {
25
25
  retries: number;
26
26
  }
27
27
 
28
+ /**
29
+ * Activity-related API operations
30
+ */
31
+ declare class ActivityApi {
32
+ private options;
33
+ /**
34
+ * Creates an instance of ActivityApi
35
+ * @param options Request options
36
+ */
37
+ constructor(options: RequestOptions);
38
+ /**
39
+ * Gets the global activity leaderboard
40
+ * @param query Optional query parameters
41
+ * @returns A promise resolving with the leaderboard response
42
+ */
43
+ getLeaderboard(query?: ActivityLeaderboardQuery): Promise<ActivityLeaderboardResponse>;
44
+ /**
45
+ * Gets activity for a specific account
46
+ * @param signerId The NEAR account ID
47
+ * @param query Optional query parameters
48
+ * @returns A promise resolving with the account activity response
49
+ */
50
+ getAccountActivity(signerId: string, query?: AccountActivityQuery): Promise<AccountActivityResponse>;
51
+ /**
52
+ * Gets posts for a specific account
53
+ * @param signerId The NEAR account ID
54
+ * @param query Optional query parameters
55
+ * @returns A promise resolving with the account posts response
56
+ */
57
+ getAccountPosts(signerId: string, query?: AccountPostsQuery): Promise<AccountPostsResponse>;
58
+ }
59
+
28
60
  /**
29
61
  * Authentication-related API operations
30
62
  */
@@ -141,19 +173,50 @@ declare class PostApi {
141
173
  deletePost(request: DeletePostRequest): Promise<DeletePostResponse>;
142
174
  }
143
175
 
176
+ /**
177
+ * System-related API operations
178
+ * Includes rate limits, health checks, and other system-related functionality
179
+ */
180
+ declare class SystemApi {
181
+ private options;
182
+ /**
183
+ * Creates an instance of SystemApi
184
+ * @param options Request options
185
+ */
186
+ constructor(options: RequestOptions);
187
+ /**
188
+ * Gets the current rate limit status
189
+ * @returns A promise resolving with the rate limit response
190
+ */
191
+ getRateLimits(): Promise<RateLimitResponse>;
192
+ /**
193
+ * Gets the rate limit status for a specific endpoint
194
+ * @param endpoint The endpoint to get rate limit for
195
+ * @returns A promise resolving with the endpoint rate limit response
196
+ */
197
+ getEndpointRateLimit(endpoint: string): Promise<EndpointRateLimitResponse>;
198
+ /**
199
+ * Gets the health status of the API
200
+ * @returns A promise resolving with the health status
201
+ */
202
+ getHealthStatus(): Promise<{
203
+ status: string;
204
+ }>;
205
+ }
206
+
144
207
  /**
145
208
  * Configuration options for the CrosspostClient
146
209
  */
147
210
  interface CrosspostClientConfig {
148
211
  /**
149
212
  * Base URL for the Crosspost API
150
- * @default 'https://api.opencrosspost.com'
213
+ * @default 'https://open-crosspost-proxy.deno.dev'
151
214
  */
152
215
  baseUrl?: string;
153
216
  /**
154
217
  * NEAR authentication data obtained from near-sign-verify
155
218
  */
156
- signature?: NearAuthData;
219
+ nearAuthData?: NearAuthData;
157
220
  /**
158
221
  * Request timeout in milliseconds
159
222
  * @default 30000
@@ -170,14 +233,10 @@ interface CrosspostClientConfig {
170
233
  * Main client for interacting with the Crosspost API service.
171
234
  */
172
235
  declare class CrosspostClient {
173
- /**
174
- * Authentication-related API operations
175
- */
176
236
  readonly auth: AuthApi;
177
- /**
178
- * Post-related API operations
179
- */
180
237
  readonly post: PostApi;
238
+ readonly activity: ActivityApi;
239
+ readonly system: SystemApi;
181
240
  private readonly options;
182
241
  /**
183
242
  * Creates an instance of CrosspostClient.
@@ -188,7 +247,12 @@ declare class CrosspostClient {
188
247
  * Sets the authentication data (signature) for the client and stores it in a cookie
189
248
  * @param signature The NEAR authentication data
190
249
  */
191
- setAuthentication(signature: NearAuthData): Promise<void>;
250
+ setAuthentication(nearAuthData: NearAuthData): void;
251
+ /**
252
+ * Checks if authentication data (signature) exists on client
253
+ * @param signature The NEAR authentication data
254
+ */
255
+ isAuthenticated(): boolean;
192
256
  }
193
257
 
194
258
  /**
@@ -209,6 +273,123 @@ declare function handleErrorResponse(data: any, status: number): ApiError | Plat
209
273
  */
210
274
  declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
211
275
 
276
+ /**
277
+ * Error categories grouped by type for better organization and usage
278
+ */
279
+ declare const ERROR_CATEGORIES: {
280
+ AUTH: ApiErrorCode[];
281
+ VALIDATION: ApiErrorCode[];
282
+ NETWORK: ApiErrorCode[];
283
+ PLATFORM: ApiErrorCode[];
284
+ CONTENT: ApiErrorCode[];
285
+ RATE_LIMIT: ApiErrorCode[];
286
+ POST: ApiErrorCode[];
287
+ MEDIA: ApiErrorCode[];
288
+ };
289
+ /**
290
+ * Check if an error belongs to a specific category
291
+ *
292
+ * @param error The error to check
293
+ * @param category The category to check against
294
+ * @returns True if the error belongs to the category, false otherwise
295
+ */
296
+ declare function isErrorOfCategory(error: unknown, category: ApiErrorCode[]): boolean;
297
+ /**
298
+ * Check if an error is an authentication error
299
+ *
300
+ * @param error The error to check
301
+ * @returns True if the error is an authentication error, false otherwise
302
+ */
303
+ declare function isAuthError(error: unknown): boolean;
304
+ /**
305
+ * Check if an error is a validation error
306
+ *
307
+ * @param error The error to check
308
+ * @returns True if the error is a validation error, false otherwise
309
+ */
310
+ declare function isValidationError(error: unknown): boolean;
311
+ /**
312
+ * Check if an error is a network error
313
+ *
314
+ * @param error The error to check
315
+ * @returns True if the error is a network error, false otherwise
316
+ */
317
+ declare function isNetworkError(error: unknown): boolean;
318
+ /**
319
+ * Check if an error is a platform error
320
+ *
321
+ * @param error The error to check
322
+ * @returns True if the error is a platform error, false otherwise
323
+ */
324
+ declare function isPlatformError(error: unknown): boolean;
325
+ /**
326
+ * Check if an error is a content policy error
327
+ *
328
+ * @param error The error to check
329
+ * @returns True if the error is a content policy error, false otherwise
330
+ */
331
+ declare function isContentError(error: unknown): boolean;
332
+ /**
333
+ * Check if an error is a rate limit error
334
+ *
335
+ * @param error The error to check
336
+ * @returns True if the error is a rate limit error, false otherwise
337
+ */
338
+ declare function isRateLimitError(error: unknown): boolean;
339
+ /**
340
+ * Check if an error is a post-related error
341
+ *
342
+ * @param error The error to check
343
+ * @returns True if the error is a post-related error, false otherwise
344
+ */
345
+ declare function isPostError(error: unknown): boolean;
346
+ /**
347
+ * Check if an error is a media-related error
348
+ *
349
+ * @param error The error to check
350
+ * @returns True if the error is a media-related error, false otherwise
351
+ */
352
+ declare function isMediaError(error: unknown): boolean;
353
+ /**
354
+ * Check if an error is recoverable
355
+ *
356
+ * @param error The error to check
357
+ * @returns True if the error is recoverable, false otherwise
358
+ */
359
+ declare function isRecoverableError(error: unknown): boolean;
360
+ /**
361
+ * Get a user-friendly error message
362
+ *
363
+ * @param error The error to get the message from
364
+ * @param defaultMessage The default message to return if no message is found
365
+ * @returns The error message
366
+ */
367
+ declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
368
+ /**
369
+ * Extract error details if available
370
+ *
371
+ * @param error The error to extract details from
372
+ * @returns The error details or undefined if none are found
373
+ */
374
+ declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
375
+ /**
376
+ * Enrich an error with additional context
377
+ *
378
+ * @param error The error to enrich
379
+ * @param context The context to add to the error
380
+ * @returns The enriched error
381
+ */
382
+ declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
383
+ /**
384
+ * Wrapper for API calls with consistent error handling
385
+ *
386
+ * @param apiCall The API call to wrap
387
+ * @param context Optional context to add to any errors
388
+ * @returns The result of the API call
389
+ * @throws An enriched error if the API call fails
390
+ */
391
+ declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
392
+
212
393
  declare const AUTH_COOKIE_NAME = "__crosspost_auth";
213
394
  declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
214
395
  declare const CSRF_HEADER_NAME = "X-CSRF-Token";
@@ -233,4 +414,4 @@ declare function clearAuthCookie(): void;
233
414
  */
234
415
  declare function getCsrfToken(): string | undefined;
235
416
 
236
- export { AUTH_COOKIE_NAME, AUTH_COOKIE_OPTIONS, AuthApi, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, CrosspostClient, type CrosspostClientConfig, PostApi, clearAuthCookie, createNetworkError, getAuthFromCookie, getCsrfToken, handleErrorResponse, storeAuthInCookie };
417
+ export { AUTH_COOKIE_NAME, AUTH_COOKIE_OPTIONS, ActivityApi, AuthApi, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, clearAuthCookie, createNetworkError, enrichErrorWithContext, getAuthFromCookie, getCsrfToken, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError, storeAuthInCookie };