@crosspost/sdk 0.1.6 → 0.1.7

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 { 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, ApiErrorCode, PlatformError, CompositeApiError } from '@crosspost/types';
2
+ import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, ApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiErrorCode, StatusCode, ErrorDetails } from '@crosspost/types';
3
3
  export * from '@crosspost/types';
4
4
 
5
5
  /**
@@ -87,19 +87,19 @@ declare class AuthApi {
87
87
  loginToPlatform(platform: Platform, options?: {
88
88
  successUrl?: string;
89
89
  errorUrl?: string;
90
- }): Promise<EnhancedApiResponse<any>>;
90
+ }): Promise<ApiResponse<any>>;
91
91
  /**
92
92
  * Refreshes the authentication token for the specified platform.
93
93
  * @param platform The target platform.
94
94
  * @returns A promise resolving with the refresh response.
95
95
  */
96
- refreshToken(platform: Platform): Promise<EnhancedApiResponse<any>>;
96
+ refreshToken(platform: Platform): Promise<ApiResponse<any>>;
97
97
  /**
98
98
  * Refreshes the user's profile information from the specified platform.
99
99
  * @param platform The target platform.
100
100
  * @returns A promise resolving with the profile refresh response.
101
101
  */
102
- refreshProfile(platform: Platform): Promise<EnhancedApiResponse<any>>;
102
+ refreshProfile(platform: Platform): Promise<ApiResponse<any>>;
103
103
  /**
104
104
  * Gets the authentication status for the specified platform.
105
105
  * @param platform The target platform.
@@ -199,9 +199,9 @@ declare class SystemApi {
199
199
  * Gets the health status of the API
200
200
  * @returns A promise resolving with the health status
201
201
  */
202
- getHealthStatus(): Promise<{
202
+ getHealthStatus(): Promise<ApiResponse<{
203
203
  status: string;
204
- }>;
204
+ }>>;
205
205
  }
206
206
 
207
207
  /**
@@ -256,129 +256,82 @@ declare class CrosspostClient {
256
256
  }
257
257
 
258
258
  /**
259
- * Error categories grouped by type
259
+ * CrosspostError class for SDK error handling
260
260
  */
261
- declare const ERROR_CATEGORIES: {
262
- AUTH: ApiErrorCode[];
263
- VALIDATION: ApiErrorCode[];
264
- NETWORK: ApiErrorCode[];
265
- PLATFORM: ApiErrorCode[];
266
- CONTENT: ApiErrorCode[];
267
- RATE_LIMIT: ApiErrorCode[];
268
- POST: ApiErrorCode[];
269
- MEDIA: ApiErrorCode[];
270
- };
271
- /**
272
- * Check if an error belongs to a specific category
273
- *
274
- * @param error The error to check
275
- * @param category The category to check against
276
- * @returns True if the error belongs to the category, false otherwise
277
- */
278
- declare function isErrorOfCategory(error: unknown, category: ApiErrorCode[]): boolean;
261
+ declare class CrosspostError extends Error {
262
+ readonly code: ApiErrorCode;
263
+ readonly status: StatusCode;
264
+ readonly details?: ErrorDetails;
265
+ readonly recoverable: boolean;
266
+ constructor(message: string, code: ApiErrorCode, status: StatusCode, details?: ErrorDetails, recoverable?: boolean);
267
+ /**
268
+ * Get platform from details if available
269
+ */
270
+ get platform(): string | undefined;
271
+ /**
272
+ * Get userId from details if available
273
+ */
274
+ get userId(): string | undefined;
275
+ }
279
276
  /**
280
277
  * Check if an error is an authentication error
281
- *
282
- * @param error The error to check
283
- * @returns True if the error is an authentication error, false otherwise
284
278
  */
285
279
  declare function isAuthError(error: unknown): boolean;
286
280
  /**
287
281
  * Check if an error is a validation error
288
- *
289
- * @param error The error to check
290
- * @returns True if the error is a validation error, false otherwise
291
282
  */
292
283
  declare function isValidationError(error: unknown): boolean;
293
284
  /**
294
285
  * Check if an error is a network error
295
- *
296
- * @param error The error to check
297
- * @returns True if the error is a network error, false otherwise
298
286
  */
299
287
  declare function isNetworkError(error: unknown): boolean;
300
288
  /**
301
289
  * Check if an error is a platform error
302
- *
303
- * @param error The error to check
304
- * @returns True if the error is a platform error, false otherwise
305
290
  */
306
291
  declare function isPlatformError(error: unknown): boolean;
307
292
  /**
308
293
  * Check if an error is a content policy error
309
- *
310
- * @param error The error to check
311
- * @returns True if the error is a content policy error, false otherwise
312
294
  */
313
295
  declare function isContentError(error: unknown): boolean;
314
296
  /**
315
297
  * Check if an error is a rate limit error
316
- *
317
- * @param error The error to check
318
- * @returns True if the error is a rate limit error, false otherwise
319
298
  */
320
299
  declare function isRateLimitError(error: unknown): boolean;
321
300
  /**
322
301
  * Check if an error is a post-related error
323
- *
324
- * @param error The error to check
325
- * @returns True if the error is a post-related error, false otherwise
326
302
  */
327
303
  declare function isPostError(error: unknown): boolean;
328
304
  /**
329
305
  * Check if an error is a media-related error
330
- *
331
- * @param error The error to check
332
- * @returns True if the error is a media-related error, false otherwise
333
306
  */
334
307
  declare function isMediaError(error: unknown): boolean;
335
308
  /**
336
309
  * Check if an error is recoverable
337
- *
338
- * @param error The error to check
339
- * @returns True if the error is recoverable, false otherwise
340
310
  */
341
311
  declare function isRecoverableError(error: unknown): boolean;
342
312
  /**
343
313
  * Get a user-friendly error message
344
- *
345
- * @param error The error to get the message from
346
- * @param defaultMessage The default message to return if no message is found
347
- * @returns The error message
348
314
  */
349
315
  declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
350
316
  /**
351
- * Extract error details if available
352
- *
353
- * @param error The error to extract details from
354
- * @returns The error details or undefined if none are found
317
+ * Get error details if available
355
318
  */
356
- declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
319
+ declare function getErrorDetails(error: unknown): ErrorDetails | undefined;
357
320
  /**
358
321
  * Enrich an error with additional context
359
- *
360
- * @param error The error to enrich
361
- * @param context The context to add to the error
362
- * @returns The enriched error
363
322
  */
364
- declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
323
+ declare function enrichErrorWithContext(error: unknown, context: Record<string, unknown>): Error;
365
324
  /**
366
325
  * Wrapper for API calls with consistent error handling
367
- *
368
- * @param apiCall The API call to wrap
369
- * @param context Optional context to add to any errors
370
- * @returns The result of the API call
371
- * @throws An enriched error if the API call fails
372
326
  */
373
- declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
327
+ declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, unknown>): Promise<T>;
374
328
  /**
375
329
  * Handles error responses from the API and converts them to appropriate error objects.
376
- *
377
- * @param data The error response data
378
- * @param status The HTTP status code
379
- * @returns An ApiError or PlatformError instance
380
330
  */
381
- declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError | CompositeApiError;
382
- declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
331
+ declare function handleErrorResponse(data: any, status: number): CrosspostError;
332
+ /**
333
+ * Creates a network error with appropriate details
334
+ */
335
+ declare function createNetworkError(error: unknown, url: string, timeout: number): CrosspostError;
383
336
 
384
- export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };
337
+ export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NearAuthData } from 'near-sign-verify';
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, ApiErrorCode, PlatformError, CompositeApiError } from '@crosspost/types';
2
+ import { ActivityLeaderboardQuery, ActivityLeaderboardResponse, AccountActivityQuery, AccountActivityResponse, AccountPostsQuery, AccountPostsResponse, NearAuthorizationResponse, Platform, ApiResponse, AuthStatusResponse, AuthRevokeResponse, ConnectedAccountsResponse, CreatePostRequest, CreatePostResponse, RepostRequest, RepostResponse, QuotePostRequest, QuotePostResponse, ReplyToPostRequest, ReplyToPostResponse, LikePostRequest, LikePostResponse, UnlikePostRequest, UnlikePostResponse, DeletePostRequest, DeletePostResponse, RateLimitResponse, EndpointRateLimitResponse, ApiErrorCode, StatusCode, ErrorDetails } from '@crosspost/types';
3
3
  export * from '@crosspost/types';
4
4
 
5
5
  /**
@@ -87,19 +87,19 @@ declare class AuthApi {
87
87
  loginToPlatform(platform: Platform, options?: {
88
88
  successUrl?: string;
89
89
  errorUrl?: string;
90
- }): Promise<EnhancedApiResponse<any>>;
90
+ }): Promise<ApiResponse<any>>;
91
91
  /**
92
92
  * Refreshes the authentication token for the specified platform.
93
93
  * @param platform The target platform.
94
94
  * @returns A promise resolving with the refresh response.
95
95
  */
96
- refreshToken(platform: Platform): Promise<EnhancedApiResponse<any>>;
96
+ refreshToken(platform: Platform): Promise<ApiResponse<any>>;
97
97
  /**
98
98
  * Refreshes the user's profile information from the specified platform.
99
99
  * @param platform The target platform.
100
100
  * @returns A promise resolving with the profile refresh response.
101
101
  */
102
- refreshProfile(platform: Platform): Promise<EnhancedApiResponse<any>>;
102
+ refreshProfile(platform: Platform): Promise<ApiResponse<any>>;
103
103
  /**
104
104
  * Gets the authentication status for the specified platform.
105
105
  * @param platform The target platform.
@@ -199,9 +199,9 @@ declare class SystemApi {
199
199
  * Gets the health status of the API
200
200
  * @returns A promise resolving with the health status
201
201
  */
202
- getHealthStatus(): Promise<{
202
+ getHealthStatus(): Promise<ApiResponse<{
203
203
  status: string;
204
- }>;
204
+ }>>;
205
205
  }
206
206
 
207
207
  /**
@@ -256,129 +256,82 @@ declare class CrosspostClient {
256
256
  }
257
257
 
258
258
  /**
259
- * Error categories grouped by type
259
+ * CrosspostError class for SDK error handling
260
260
  */
261
- declare const ERROR_CATEGORIES: {
262
- AUTH: ApiErrorCode[];
263
- VALIDATION: ApiErrorCode[];
264
- NETWORK: ApiErrorCode[];
265
- PLATFORM: ApiErrorCode[];
266
- CONTENT: ApiErrorCode[];
267
- RATE_LIMIT: ApiErrorCode[];
268
- POST: ApiErrorCode[];
269
- MEDIA: ApiErrorCode[];
270
- };
271
- /**
272
- * Check if an error belongs to a specific category
273
- *
274
- * @param error The error to check
275
- * @param category The category to check against
276
- * @returns True if the error belongs to the category, false otherwise
277
- */
278
- declare function isErrorOfCategory(error: unknown, category: ApiErrorCode[]): boolean;
261
+ declare class CrosspostError extends Error {
262
+ readonly code: ApiErrorCode;
263
+ readonly status: StatusCode;
264
+ readonly details?: ErrorDetails;
265
+ readonly recoverable: boolean;
266
+ constructor(message: string, code: ApiErrorCode, status: StatusCode, details?: ErrorDetails, recoverable?: boolean);
267
+ /**
268
+ * Get platform from details if available
269
+ */
270
+ get platform(): string | undefined;
271
+ /**
272
+ * Get userId from details if available
273
+ */
274
+ get userId(): string | undefined;
275
+ }
279
276
  /**
280
277
  * Check if an error is an authentication error
281
- *
282
- * @param error The error to check
283
- * @returns True if the error is an authentication error, false otherwise
284
278
  */
285
279
  declare function isAuthError(error: unknown): boolean;
286
280
  /**
287
281
  * Check if an error is a validation error
288
- *
289
- * @param error The error to check
290
- * @returns True if the error is a validation error, false otherwise
291
282
  */
292
283
  declare function isValidationError(error: unknown): boolean;
293
284
  /**
294
285
  * Check if an error is a network error
295
- *
296
- * @param error The error to check
297
- * @returns True if the error is a network error, false otherwise
298
286
  */
299
287
  declare function isNetworkError(error: unknown): boolean;
300
288
  /**
301
289
  * Check if an error is a platform error
302
- *
303
- * @param error The error to check
304
- * @returns True if the error is a platform error, false otherwise
305
290
  */
306
291
  declare function isPlatformError(error: unknown): boolean;
307
292
  /**
308
293
  * Check if an error is a content policy error
309
- *
310
- * @param error The error to check
311
- * @returns True if the error is a content policy error, false otherwise
312
294
  */
313
295
  declare function isContentError(error: unknown): boolean;
314
296
  /**
315
297
  * Check if an error is a rate limit error
316
- *
317
- * @param error The error to check
318
- * @returns True if the error is a rate limit error, false otherwise
319
298
  */
320
299
  declare function isRateLimitError(error: unknown): boolean;
321
300
  /**
322
301
  * Check if an error is a post-related error
323
- *
324
- * @param error The error to check
325
- * @returns True if the error is a post-related error, false otherwise
326
302
  */
327
303
  declare function isPostError(error: unknown): boolean;
328
304
  /**
329
305
  * Check if an error is a media-related error
330
- *
331
- * @param error The error to check
332
- * @returns True if the error is a media-related error, false otherwise
333
306
  */
334
307
  declare function isMediaError(error: unknown): boolean;
335
308
  /**
336
309
  * Check if an error is recoverable
337
- *
338
- * @param error The error to check
339
- * @returns True if the error is recoverable, false otherwise
340
310
  */
341
311
  declare function isRecoverableError(error: unknown): boolean;
342
312
  /**
343
313
  * Get a user-friendly error message
344
- *
345
- * @param error The error to get the message from
346
- * @param defaultMessage The default message to return if no message is found
347
- * @returns The error message
348
314
  */
349
315
  declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
350
316
  /**
351
- * Extract error details if available
352
- *
353
- * @param error The error to extract details from
354
- * @returns The error details or undefined if none are found
317
+ * Get error details if available
355
318
  */
356
- declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
319
+ declare function getErrorDetails(error: unknown): ErrorDetails | undefined;
357
320
  /**
358
321
  * Enrich an error with additional context
359
- *
360
- * @param error The error to enrich
361
- * @param context The context to add to the error
362
- * @returns The enriched error
363
322
  */
364
- declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
323
+ declare function enrichErrorWithContext(error: unknown, context: Record<string, unknown>): Error;
365
324
  /**
366
325
  * Wrapper for API calls with consistent error handling
367
- *
368
- * @param apiCall The API call to wrap
369
- * @param context Optional context to add to any errors
370
- * @returns The result of the API call
371
- * @throws An enriched error if the API call fails
372
326
  */
373
- declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
327
+ declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, unknown>): Promise<T>;
374
328
  /**
375
329
  * Handles error responses from the API and converts them to appropriate error objects.
376
- *
377
- * @param data The error response data
378
- * @param status The HTTP status code
379
- * @returns An ApiError or PlatformError instance
380
330
  */
381
- declare function handleErrorResponse(data: any, status: number): ApiError | PlatformError | CompositeApiError;
382
- declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
331
+ declare function handleErrorResponse(data: any, status: number): CrosspostError;
332
+ /**
333
+ * Creates a network error with appropriate details
334
+ */
335
+ declare function createNetworkError(error: unknown, url: string, timeout: number): CrosspostError;
383
336
 
384
- export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, ERROR_CATEGORIES, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isErrorOfCategory, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };
337
+ export { ActivityApi, AuthApi, CrosspostClient, type CrosspostClientConfig, PostApi, SystemApi, apiWrapper, createNetworkError, enrichErrorWithContext, getErrorDetails, getErrorMessage, handleErrorResponse, isAuthError, isContentError, isMediaError, isNetworkError, isPlatformError, isPostError, isRateLimitError, isRecoverableError, isValidationError };