@crosspost/sdk 0.1.2 → 0.1.4
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 +308 -205
- package/dist/index.cjs +427 -170
- package/dist/index.d.cts +193 -37
- package/dist/index.d.ts +193 -37
- package/dist/index.js +404 -150
- package/package.json +1 -3
- package/src/api/activity.ts +77 -0
- package/src/api/system.ts +55 -0
- package/src/core/client.ts +20 -19
- package/src/core/config.ts +4 -4
- package/src/core/request.ts +112 -96
- package/src/index.ts +24 -14
- package/src/utils/error.ts +300 -0
- package/src/utils/cookie.ts +0 -75
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, ApiErrorCode, PlatformError } 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
|
-
|
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://
|
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
|
-
|
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.
|
@@ -185,12 +244,133 @@ declare class CrosspostClient {
|
|
185
244
|
*/
|
186
245
|
constructor(config?: CrosspostClientConfig);
|
187
246
|
/**
|
188
|
-
* Sets the authentication data (signature) for the client
|
247
|
+
* Sets the authentication data (signature) for the client
|
248
|
+
* @param nearAuthData The NEAR authentication data
|
249
|
+
*/
|
250
|
+
setAuthentication(nearAuthData: NearAuthData): void;
|
251
|
+
/**
|
252
|
+
* Checks if authentication data (signature) exists on client
|
189
253
|
* @param signature The NEAR authentication data
|
190
254
|
*/
|
191
|
-
|
255
|
+
isAuthenticated(): boolean;
|
192
256
|
}
|
193
257
|
|
258
|
+
/**
|
259
|
+
* Error categories grouped by type
|
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;
|
279
|
+
/**
|
280
|
+
* 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
|
+
*/
|
285
|
+
declare function isAuthError(error: unknown): boolean;
|
286
|
+
/**
|
287
|
+
* 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
|
+
*/
|
292
|
+
declare function isValidationError(error: unknown): boolean;
|
293
|
+
/**
|
294
|
+
* 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
|
+
*/
|
299
|
+
declare function isNetworkError(error: unknown): boolean;
|
300
|
+
/**
|
301
|
+
* 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
|
+
*/
|
306
|
+
declare function isPlatformError(error: unknown): boolean;
|
307
|
+
/**
|
308
|
+
* 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
|
+
*/
|
313
|
+
declare function isContentError(error: unknown): boolean;
|
314
|
+
/**
|
315
|
+
* 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
|
+
*/
|
320
|
+
declare function isRateLimitError(error: unknown): boolean;
|
321
|
+
/**
|
322
|
+
* 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
|
+
*/
|
327
|
+
declare function isPostError(error: unknown): boolean;
|
328
|
+
/**
|
329
|
+
* 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
|
+
*/
|
334
|
+
declare function isMediaError(error: unknown): boolean;
|
335
|
+
/**
|
336
|
+
* 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
|
+
*/
|
341
|
+
declare function isRecoverableError(error: unknown): boolean;
|
342
|
+
/**
|
343
|
+
* 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
|
+
*/
|
349
|
+
declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
|
350
|
+
/**
|
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
|
355
|
+
*/
|
356
|
+
declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
|
357
|
+
/**
|
358
|
+
* 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
|
+
*/
|
364
|
+
declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
|
365
|
+
/**
|
366
|
+
* 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
|
+
*/
|
373
|
+
declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
|
194
374
|
/**
|
195
375
|
* Handles error responses from the API and converts them to appropriate error objects.
|
196
376
|
*
|
@@ -209,28 +389,4 @@ declare function handleErrorResponse(data: any, status: number): ApiError | Plat
|
|
209
389
|
*/
|
210
390
|
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
211
391
|
|
212
|
-
|
213
|
-
declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
|
214
|
-
declare const CSRF_HEADER_NAME = "X-CSRF-Token";
|
215
|
-
declare const AUTH_COOKIE_OPTIONS: Cookies.CookieAttributes;
|
216
|
-
/**
|
217
|
-
* Gets authentication data from the cookie
|
218
|
-
* @returns The NearAuthData object or undefined if not found
|
219
|
-
*/
|
220
|
-
declare function getAuthFromCookie(): NearAuthData | undefined;
|
221
|
-
/**
|
222
|
-
* Stores authentication data in a secure cookie
|
223
|
-
* @param authData The NearAuthData object to store
|
224
|
-
*/
|
225
|
-
declare function storeAuthInCookie(authData: NearAuthData): void;
|
226
|
-
/**
|
227
|
-
* Clears the authentication cookie
|
228
|
-
*/
|
229
|
-
declare function clearAuthCookie(): void;
|
230
|
-
/**
|
231
|
-
* Gets the CSRF token from the cookie
|
232
|
-
* @returns The CSRF token or undefined if not found
|
233
|
-
*/
|
234
|
-
declare function getCsrfToken(): string | undefined;
|
235
|
-
|
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 };
|
392
|
+
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 };
|
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, ApiErrorCode, PlatformError } 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
|
-
|
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://
|
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
|
-
|
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.
|
@@ -185,12 +244,133 @@ declare class CrosspostClient {
|
|
185
244
|
*/
|
186
245
|
constructor(config?: CrosspostClientConfig);
|
187
246
|
/**
|
188
|
-
* Sets the authentication data (signature) for the client
|
247
|
+
* Sets the authentication data (signature) for the client
|
248
|
+
* @param nearAuthData The NEAR authentication data
|
249
|
+
*/
|
250
|
+
setAuthentication(nearAuthData: NearAuthData): void;
|
251
|
+
/**
|
252
|
+
* Checks if authentication data (signature) exists on client
|
189
253
|
* @param signature The NEAR authentication data
|
190
254
|
*/
|
191
|
-
|
255
|
+
isAuthenticated(): boolean;
|
192
256
|
}
|
193
257
|
|
258
|
+
/**
|
259
|
+
* Error categories grouped by type
|
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;
|
279
|
+
/**
|
280
|
+
* 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
|
+
*/
|
285
|
+
declare function isAuthError(error: unknown): boolean;
|
286
|
+
/**
|
287
|
+
* 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
|
+
*/
|
292
|
+
declare function isValidationError(error: unknown): boolean;
|
293
|
+
/**
|
294
|
+
* 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
|
+
*/
|
299
|
+
declare function isNetworkError(error: unknown): boolean;
|
300
|
+
/**
|
301
|
+
* 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
|
+
*/
|
306
|
+
declare function isPlatformError(error: unknown): boolean;
|
307
|
+
/**
|
308
|
+
* 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
|
+
*/
|
313
|
+
declare function isContentError(error: unknown): boolean;
|
314
|
+
/**
|
315
|
+
* 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
|
+
*/
|
320
|
+
declare function isRateLimitError(error: unknown): boolean;
|
321
|
+
/**
|
322
|
+
* 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
|
+
*/
|
327
|
+
declare function isPostError(error: unknown): boolean;
|
328
|
+
/**
|
329
|
+
* 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
|
+
*/
|
334
|
+
declare function isMediaError(error: unknown): boolean;
|
335
|
+
/**
|
336
|
+
* 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
|
+
*/
|
341
|
+
declare function isRecoverableError(error: unknown): boolean;
|
342
|
+
/**
|
343
|
+
* 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
|
+
*/
|
349
|
+
declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
|
350
|
+
/**
|
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
|
355
|
+
*/
|
356
|
+
declare function getErrorDetails(error: unknown): Record<string, any> | undefined;
|
357
|
+
/**
|
358
|
+
* 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
|
+
*/
|
364
|
+
declare function enrichErrorWithContext(error: unknown, context: Record<string, any>): Error;
|
365
|
+
/**
|
366
|
+
* 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
|
+
*/
|
373
|
+
declare function apiWrapper<T>(apiCall: () => Promise<T>, context?: Record<string, any>): Promise<T>;
|
194
374
|
/**
|
195
375
|
* Handles error responses from the API and converts them to appropriate error objects.
|
196
376
|
*
|
@@ -209,28 +389,4 @@ declare function handleErrorResponse(data: any, status: number): ApiError | Plat
|
|
209
389
|
*/
|
210
390
|
declare function createNetworkError(error: unknown, url: string, timeout: number): ApiError;
|
211
391
|
|
212
|
-
|
213
|
-
declare const CSRF_COOKIE_NAME = "XSRF-TOKEN";
|
214
|
-
declare const CSRF_HEADER_NAME = "X-CSRF-Token";
|
215
|
-
declare const AUTH_COOKIE_OPTIONS: Cookies.CookieAttributes;
|
216
|
-
/**
|
217
|
-
* Gets authentication data from the cookie
|
218
|
-
* @returns The NearAuthData object or undefined if not found
|
219
|
-
*/
|
220
|
-
declare function getAuthFromCookie(): NearAuthData | undefined;
|
221
|
-
/**
|
222
|
-
* Stores authentication data in a secure cookie
|
223
|
-
* @param authData The NearAuthData object to store
|
224
|
-
*/
|
225
|
-
declare function storeAuthInCookie(authData: NearAuthData): void;
|
226
|
-
/**
|
227
|
-
* Clears the authentication cookie
|
228
|
-
*/
|
229
|
-
declare function clearAuthCookie(): void;
|
230
|
-
/**
|
231
|
-
* Gets the CSRF token from the cookie
|
232
|
-
* @returns The CSRF token or undefined if not found
|
233
|
-
*/
|
234
|
-
declare function getCsrfToken(): string | undefined;
|
235
|
-
|
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 };
|
392
|
+
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 };
|