@crosspost/types 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.cjs +379 -684
- package/dist/index.d.cts +1469 -5908
- package/dist/index.d.ts +1469 -5908
- package/dist/index.js +374 -660
- package/package.json +1 -1
- package/src/activity.ts +30 -115
- package/src/auth.ts +40 -70
- package/src/common.ts +8 -10
- package/src/errors.ts +97 -0
- package/src/index.ts +1 -13
- package/src/post.ts +22 -168
- package/src/rate-limit.ts +33 -72
- package/src/response.ts +41 -288
- package/src/user-profile.ts +2 -26
- package/src/errors/api-error.ts +0 -155
- package/src/errors/base-error.ts +0 -13
- package/src/errors/composite-api-error.ts +0 -33
- package/src/errors/index.ts +0 -8
- package/src/errors/platform-error.ts +0 -34
package/package.json
CHANGED
package/src/activity.ts
CHANGED
@@ -1,16 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* Activity Schemas and Types
|
3
|
-
* Defines Zod schemas for activity-related requests and responses
|
4
|
-
* TypeScript types are derived from Zod schemas for type safety
|
5
|
-
*/
|
6
|
-
|
7
1
|
import { z } from 'zod';
|
8
|
-
import { EnhancedResponseSchema } from './response.ts';
|
9
2
|
import { PlatformSchema } from './common.ts';
|
10
3
|
|
11
|
-
/**
|
12
|
-
* Time periods for activity filtering
|
13
|
-
*/
|
14
4
|
export enum TimePeriod {
|
15
5
|
ALL = 'all',
|
16
6
|
YEARLY = 'year',
|
@@ -19,9 +9,6 @@ export enum TimePeriod {
|
|
19
9
|
DAILY = 'day',
|
20
10
|
}
|
21
11
|
|
22
|
-
/**
|
23
|
-
* Activity leaderboard query schema
|
24
|
-
*/
|
25
12
|
export const ActivityLeaderboardQuerySchema = z.object({
|
26
13
|
timeframe: z.nativeEnum(TimePeriod).optional().describe(
|
27
14
|
'Timeframe for the leaderboard',
|
@@ -36,9 +23,6 @@ export const ActivityLeaderboardQuerySchema = z.object({
|
|
36
23
|
.describe('Offset for pagination'),
|
37
24
|
}).describe('Activity leaderboard query');
|
38
25
|
|
39
|
-
/**
|
40
|
-
* Account activity entry schema
|
41
|
-
*/
|
42
26
|
export const AccountActivityEntrySchema = z.object({
|
43
27
|
signerId: z.string().describe('NEAR account ID'),
|
44
28
|
totalPosts: z.number().describe('Total number of posts'),
|
@@ -51,39 +35,23 @@ export const AccountActivityEntrySchema = z.object({
|
|
51
35
|
lastActive: z.string().datetime().describe('Timestamp of last activity'),
|
52
36
|
}).describe('Account activity entry');
|
53
37
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
entries: z.array(AccountActivityEntrySchema).describe('Leaderboard entries'),
|
61
|
-
total: z.number().describe('Total number of entries in the leaderboard'),
|
62
|
-
limit: z.number().describe('Maximum number of results returned'),
|
63
|
-
offset: z.number().describe('Offset for pagination'),
|
64
|
-
generatedAt: z.string().datetime().describe('Timestamp when the leaderboard was generated'),
|
65
|
-
}),
|
66
|
-
).describe('Activity leaderboard response');
|
38
|
+
const ActivityLeaderboardResponseSchema = z.object({
|
39
|
+
timeframe: z.nativeEnum(TimePeriod).describe('Timeframe for the leaderboard'),
|
40
|
+
entries: z.array(AccountActivityEntrySchema).describe('Leaderboard entries'),
|
41
|
+
generatedAt: z.string().datetime().describe('Timestamp when the leaderboard was generated'),
|
42
|
+
platform: PlatformSchema.optional().describe('Platform filter (if applied)'),
|
43
|
+
});
|
67
44
|
|
68
|
-
/**
|
69
|
-
* Account activity params schema
|
70
|
-
*/
|
71
45
|
export const AccountActivityParamsSchema = z.object({
|
72
46
|
signerId: z.string().describe('NEAR account ID'),
|
73
47
|
}).describe('Account activity params');
|
74
48
|
|
75
|
-
/**
|
76
|
-
* Account activity query schema
|
77
|
-
*/
|
78
49
|
export const AccountActivityQuerySchema = z.object({
|
79
50
|
timeframe: z.nativeEnum(TimePeriod).optional().describe(
|
80
51
|
'Timeframe for the activity',
|
81
52
|
),
|
82
53
|
}).describe('Account activity query');
|
83
54
|
|
84
|
-
/**
|
85
|
-
* Platform activity schema
|
86
|
-
*/
|
87
55
|
export const PlatformActivitySchema = z.object({
|
88
56
|
platform: PlatformSchema,
|
89
57
|
posts: z.number().describe('Number of posts on this platform'),
|
@@ -95,35 +63,24 @@ export const PlatformActivitySchema = z.object({
|
|
95
63
|
lastActive: z.string().datetime().describe('Timestamp of last activity on this platform'),
|
96
64
|
}).describe('Platform activity');
|
97
65
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
z.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
rank: z.number().describe('Rank on the leaderboard'),
|
112
|
-
lastActive: z.string().datetime().describe('Timestamp of last activity across all platforms'),
|
113
|
-
platforms: z.array(PlatformActivitySchema).describe('Activity breakdown by platform'),
|
114
|
-
}),
|
115
|
-
).describe('Account activity response');
|
66
|
+
const AccountActivityResponseSchema = z.object({
|
67
|
+
signerId: z.string().describe('NEAR account ID'),
|
68
|
+
timeframe: z.nativeEnum(TimePeriod).describe('Timeframe for the activity'),
|
69
|
+
totalPosts: z.number().describe('Total number of posts across all platforms'),
|
70
|
+
totalLikes: z.number().describe('Total number of likes across all platforms'),
|
71
|
+
totalReposts: z.number().describe('Total number of reposts across all platforms'),
|
72
|
+
totalReplies: z.number().describe('Total number of replies across all platforms'),
|
73
|
+
totalQuotes: z.number().describe('Total number of quote posts across all platforms'),
|
74
|
+
totalScore: z.number().describe('Total activity score across all platforms'),
|
75
|
+
rank: z.number().describe('Rank on the leaderboard'),
|
76
|
+
lastActive: z.string().datetime().describe('Timestamp of last activity across all platforms'),
|
77
|
+
platforms: z.array(PlatformActivitySchema).describe('Activity breakdown by platform'),
|
78
|
+
});
|
116
79
|
|
117
|
-
/**
|
118
|
-
* Account posts params schema
|
119
|
-
*/
|
120
80
|
export const AccountPostsParamsSchema = z.object({
|
121
81
|
signerId: z.string().describe('NEAR account ID'),
|
122
82
|
}).describe('Account posts params');
|
123
83
|
|
124
|
-
/**
|
125
|
-
* Account posts query schema
|
126
|
-
*/
|
127
84
|
export const AccountPostsQuerySchema = z.object({
|
128
85
|
platform: z.string().optional().describe('Filter by platform (optional)'),
|
129
86
|
limit: z.string().optional()
|
@@ -139,9 +96,6 @@ export const AccountPostsQuerySchema = z.object({
|
|
139
96
|
),
|
140
97
|
}).describe('Account posts query');
|
141
98
|
|
142
|
-
/**
|
143
|
-
* Account post schema
|
144
|
-
*/
|
145
99
|
export const AccountPostSchema = z.object({
|
146
100
|
id: z.string().describe('Post ID'),
|
147
101
|
platform: PlatformSchema,
|
@@ -159,25 +113,17 @@ export const AccountPostSchema = z.object({
|
|
159
113
|
quotedPostId: z.string().optional().describe('ID of the post this is quoting (if applicable)'),
|
160
114
|
}).describe('Account post');
|
161
115
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
z.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
limit: z.number().describe('Maximum number of results returned'),
|
171
|
-
offset: z.number().describe('Offset for pagination'),
|
172
|
-
platform: z.string().optional().describe('Platform filter (if applied)'),
|
173
|
-
type: z.enum(['post', 'repost', 'reply', 'quote', 'like', 'all']).optional().describe(
|
174
|
-
'Post type filter (if applied)',
|
175
|
-
),
|
176
|
-
}),
|
177
|
-
).describe('Account posts response');
|
116
|
+
const AccountPostsResponseSchema = z.object({
|
117
|
+
signerId: z.string().describe('NEAR account ID'),
|
118
|
+
posts: z.array(AccountPostSchema).describe('List of posts'),
|
119
|
+
platform: z.string().optional().describe('Platform filter (if applied)'),
|
120
|
+
type: z.enum(['post', 'repost', 'reply', 'quote', 'like', 'all']).optional().describe(
|
121
|
+
'Post type filter (if applied)',
|
122
|
+
),
|
123
|
+
});
|
178
124
|
|
179
125
|
/**
|
180
|
-
* Interface for account activity
|
126
|
+
* Interface for account activity Response
|
181
127
|
*/
|
182
128
|
export interface AccountActivity {
|
183
129
|
signerId: string;
|
@@ -187,14 +133,14 @@ export interface AccountActivity {
|
|
187
133
|
}
|
188
134
|
|
189
135
|
/**
|
190
|
-
* Interface for platform-specific account activity
|
136
|
+
* Interface for platform-specific account activity Response
|
191
137
|
*/
|
192
138
|
export interface PlatformAccountActivity extends AccountActivity {
|
193
139
|
platform: string;
|
194
140
|
}
|
195
141
|
|
196
142
|
/**
|
197
|
-
* Interface for post record
|
143
|
+
* Interface for post record Response (storage optimized)
|
198
144
|
*/
|
199
145
|
export interface PostRecord {
|
200
146
|
id: string; // postId
|
@@ -203,33 +149,6 @@ export interface PostRecord {
|
|
203
149
|
u: string; // userId
|
204
150
|
}
|
205
151
|
|
206
|
-
/**
|
207
|
-
* Interface for post record data (API response)
|
208
|
-
*/
|
209
|
-
export interface PostRecordResponse {
|
210
|
-
postId: string;
|
211
|
-
platform: string;
|
212
|
-
timestamp: string;
|
213
|
-
userId: string;
|
214
|
-
}
|
215
|
-
|
216
|
-
/**
|
217
|
-
* Interface for leaderboard entry
|
218
|
-
*/
|
219
|
-
export interface LeaderboardEntry {
|
220
|
-
signerId: string;
|
221
|
-
postCount: number;
|
222
|
-
lastPostTimestamp: number;
|
223
|
-
}
|
224
|
-
|
225
|
-
/**
|
226
|
-
* Interface for platform-specific leaderboard entry
|
227
|
-
*/
|
228
|
-
export interface PlatformLeaderboardEntry extends LeaderboardEntry {
|
229
|
-
platform: string;
|
230
|
-
}
|
231
|
-
|
232
|
-
// Derive TypeScript types from Zod schemas
|
233
152
|
export type ActivityLeaderboardQuery = z.infer<typeof ActivityLeaderboardQuerySchema>;
|
234
153
|
export type AccountActivityEntry = z.infer<typeof AccountActivityEntrySchema>;
|
235
154
|
export type ActivityLeaderboardResponse = z.infer<typeof ActivityLeaderboardResponseSchema>;
|
@@ -241,7 +160,3 @@ export type AccountPostsParams = z.infer<typeof AccountPostsParamsSchema>;
|
|
241
160
|
export type AccountPostsQuery = z.infer<typeof AccountPostsQuerySchema>;
|
242
161
|
export type AccountPost = z.infer<typeof AccountPostSchema>;
|
243
162
|
export type AccountPostsResponse = z.infer<typeof AccountPostsResponseSchema>;
|
244
|
-
|
245
|
-
// Legacy type aliases for backward compatibility
|
246
|
-
export type LeaderboardQuery = ActivityLeaderboardQuery;
|
247
|
-
export type LeaderboardResponse = ActivityLeaderboardResponse;
|
package/src/auth.ts
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
-
/**
|
2
|
-
* Auth Schemas and Types
|
3
|
-
* Defines Zod schemas for authentication-related requests and responses
|
4
|
-
* TypeScript types are derived from Zod schemas for type safety
|
5
|
-
*/
|
6
|
-
|
7
1
|
import { z } from 'zod';
|
8
|
-
import { EnhancedResponseSchema } from './response.ts';
|
9
2
|
import { PlatformSchema } from './common.ts';
|
10
3
|
|
11
|
-
// Platform parameter schema
|
12
4
|
export const PlatformParamSchema = z.object({
|
13
5
|
platform: z.string().describe('Social media platform'),
|
14
6
|
}).describe('Platform parameter');
|
15
7
|
|
16
|
-
// Auth initialization request schema
|
17
8
|
export const AuthInitRequestSchema = z.object({
|
18
9
|
successUrl: z.string().url().optional().describe(
|
19
10
|
'URL to redirect to on successful authentication',
|
@@ -21,55 +12,43 @@ export const AuthInitRequestSchema = z.object({
|
|
21
12
|
errorUrl: z.string().url().optional().describe('URL to redirect to on authentication error'),
|
22
13
|
}).describe('Auth initialization request');
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
z.
|
27
|
-
|
28
|
-
|
29
|
-
platform: PlatformSchema,
|
30
|
-
}),
|
31
|
-
).describe('Auth URL response');
|
15
|
+
export const AuthUrlResponseSchema = z.object({
|
16
|
+
url: z.string().describe('Authentication URL to redirect the user to'),
|
17
|
+
state: z.string().describe('State parameter for CSRF protection'),
|
18
|
+
platform: PlatformSchema,
|
19
|
+
}).describe('Auth URL response');
|
32
20
|
|
33
|
-
// Auth callback query schema
|
34
21
|
export const AuthCallbackQuerySchema = z.object({
|
35
22
|
code: z.string().describe('Authorization code from OAuth provider'),
|
36
23
|
state: z.string().describe('State parameter for CSRF protection'),
|
37
24
|
}).describe('Auth callback query');
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
z.
|
42
|
-
|
43
|
-
|
44
|
-
userId: z.string().describe('User ID'),
|
45
|
-
redirectUrl: z.string().optional().describe('URL to redirect the user to after authentication'),
|
46
|
-
}),
|
47
|
-
).describe('Auth callback response');
|
26
|
+
export const AuthCallbackResponseSchema = z.object({
|
27
|
+
platform: PlatformSchema,
|
28
|
+
userId: z.string().describe('User ID'),
|
29
|
+
redirectUrl: z.string().optional().describe('URL to redirect the user to after authentication'),
|
30
|
+
}).describe('Auth callback response');
|
48
31
|
|
49
|
-
|
50
|
-
|
51
|
-
z.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
expired: z.boolean().describe('Whether the token is expired'),
|
58
|
-
expiresAt: z.string().optional().describe('When the token expires'),
|
59
|
-
}),
|
32
|
+
export const AuthStatusResponseSchema = z.object({
|
33
|
+
platform: PlatformSchema,
|
34
|
+
userId: z.string().describe('User ID'),
|
35
|
+
authenticated: z.boolean().describe('Whether the user is authenticated'),
|
36
|
+
tokenStatus: z.object({
|
37
|
+
valid: z.boolean().describe('Whether the token is valid'),
|
38
|
+
expired: z.boolean().describe('Whether the token is expired'),
|
39
|
+
expiresAt: z.string().optional().describe('When the token expires'),
|
60
40
|
}),
|
61
|
-
).describe('Auth status response');
|
41
|
+
}).describe('Auth status response');
|
62
42
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
).describe('Auth revoke response');
|
43
|
+
export const AuthTokenRequestSchema = z.object({
|
44
|
+
userId: z.string().describe('User ID on the platform'),
|
45
|
+
}).describe('Auth token request');
|
46
|
+
|
47
|
+
export const AuthRevokeResponseSchema = z.object({
|
48
|
+
platform: PlatformSchema,
|
49
|
+
userId: z.string().describe('User ID'),
|
50
|
+
}).describe('Auth revoke response');
|
71
51
|
|
72
|
-
// Connected account schema
|
73
52
|
export const ConnectedAccountSchema = z.object({
|
74
53
|
platform: PlatformSchema,
|
75
54
|
userId: z.string().describe('User ID on the platform'),
|
@@ -78,35 +57,25 @@ export const ConnectedAccountSchema = z.object({
|
|
78
57
|
connectedAt: z.string().optional().describe('When the account was connected'),
|
79
58
|
}).describe('Connected account');
|
80
59
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
).describe('Connected accounts response');
|
60
|
+
export const ConnectedAccountsResponseSchema = z.array(ConnectedAccountSchema).describe(
|
61
|
+
'Connected accounts response',
|
62
|
+
);
|
85
63
|
|
86
|
-
// NEAR authorization request schema
|
87
64
|
export const NearAuthorizationRequestSchema = z.object({
|
88
65
|
// No additional parameters needed, as the NEAR account ID is extracted from the signature
|
89
66
|
}).describe('NEAR authorization request');
|
90
67
|
|
91
|
-
|
92
|
-
|
93
|
-
z.
|
94
|
-
|
95
|
-
nearAccount: z.string().describe('NEAR account ID'),
|
96
|
-
authorized: z.boolean().describe('Whether the account is authorized'),
|
97
|
-
}),
|
98
|
-
).describe('NEAR authorization response');
|
68
|
+
export const NearAuthorizationResponseSchema = z.object({
|
69
|
+
nearAccount: z.string().describe('NEAR account ID'),
|
70
|
+
authorized: z.boolean().describe('Whether the account is authorized'),
|
71
|
+
}).describe('NEAR authorization response');
|
99
72
|
|
100
|
-
|
101
|
-
|
102
|
-
z.
|
103
|
-
|
104
|
-
|
105
|
-
authorizedAt: z.string().optional().describe('When the account was authorized'),
|
106
|
-
}),
|
107
|
-
).describe('NEAR authorization status response');
|
73
|
+
export const NearAuthorizationStatusResponseSchema = z.object({
|
74
|
+
nearAccount: z.string().describe('NEAR account ID'),
|
75
|
+
authorized: z.boolean().describe('Whether the account is authorized'),
|
76
|
+
authorizedAt: z.string().optional().describe('When the account was authorized'),
|
77
|
+
}).describe('NEAR authorization status response');
|
108
78
|
|
109
|
-
// Derive TypeScript types from Zod schemas
|
110
79
|
export type PlatformParam = z.infer<typeof PlatformParamSchema>;
|
111
80
|
export type AuthInitRequest = z.infer<typeof AuthInitRequestSchema>;
|
112
81
|
export type AuthUrlResponse = z.infer<typeof AuthUrlResponseSchema>;
|
@@ -119,3 +88,4 @@ export type ConnectedAccountsResponse = z.infer<typeof ConnectedAccountsResponse
|
|
119
88
|
export type NearAuthorizationRequest = z.infer<typeof NearAuthorizationRequestSchema>;
|
120
89
|
export type NearAuthorizationResponse = z.infer<typeof NearAuthorizationResponseSchema>;
|
121
90
|
export type NearAuthorizationStatusResponse = z.infer<typeof NearAuthorizationStatusResponseSchema>;
|
91
|
+
export type AuthTokenRequest = z.infer<typeof AuthTokenRequestSchema>;
|
package/src/common.ts
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
/**
|
2
|
-
* Common Schemas and Types
|
3
|
-
* Defines common Zod schemas and derived TypeScript types used across the API
|
4
|
-
*/
|
5
|
-
|
6
1
|
import { z } from 'zod';
|
7
2
|
|
8
3
|
/**
|
9
|
-
* Platform enum
|
4
|
+
* Platform enum
|
10
5
|
*/
|
11
6
|
export enum Platform {
|
12
7
|
UNKNOWN = 'unknown',
|
@@ -17,14 +12,14 @@ export enum Platform {
|
|
17
12
|
// INSTAGRAM = 'instagram',
|
18
13
|
}
|
19
14
|
|
20
|
-
export const PlatformSchema = z.nativeEnum(Platform)
|
21
|
-
.describe('Social media platform');
|
22
|
-
|
23
15
|
/**
|
24
|
-
*
|
16
|
+
* PlatformName type - Derived from the Platform enum
|
25
17
|
*/
|
26
18
|
export type PlatformName = Platform;
|
27
19
|
|
20
|
+
export const PlatformSchema = z.nativeEnum(Platform)
|
21
|
+
.describe('Social media platform');
|
22
|
+
|
28
23
|
/**
|
29
24
|
* Array of currently supported platforms
|
30
25
|
*/
|
@@ -47,3 +42,6 @@ SupportedPlatformSchema.describe('Currently supported social media platforms');
|
|
47
42
|
export function isPlatformSupported(platform: Platform): platform is SupportedPlatformName {
|
48
43
|
return (SUPPORTED_PLATFORMS as readonly Platform[]).includes(platform);
|
49
44
|
}
|
45
|
+
|
46
|
+
// Re-export StatusCode from hono
|
47
|
+
export type { StatusCode } from 'hono/utils/http-status';
|
package/src/errors.ts
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import type { ResponseMeta } from './response.ts';
|
3
|
+
import type { PlatformName } from './common.ts';
|
4
|
+
import type { StatusCode } from './index.ts';
|
5
|
+
|
6
|
+
export enum ApiErrorCode {
|
7
|
+
// General errors
|
8
|
+
UNKNOWN_ERROR = 'UNKNOWN_ERROR',
|
9
|
+
INTERNAL_ERROR = 'INTERNAL_ERROR',
|
10
|
+
|
11
|
+
// Authentication/Authorization errors
|
12
|
+
UNAUTHORIZED = 'UNAUTHORIZED',
|
13
|
+
FORBIDDEN = 'FORBIDDEN',
|
14
|
+
|
15
|
+
// Validation errors
|
16
|
+
VALIDATION_ERROR = 'VALIDATION_ERROR',
|
17
|
+
INVALID_REQUEST = 'INVALID_REQUEST',
|
18
|
+
|
19
|
+
// Rate limiting
|
20
|
+
RATE_LIMITED = 'RATE_LIMITED',
|
21
|
+
|
22
|
+
// Resource errors
|
23
|
+
NOT_FOUND = 'NOT_FOUND',
|
24
|
+
|
25
|
+
// Platform-specific errors
|
26
|
+
PLATFORM_ERROR = 'PLATFORM_ERROR',
|
27
|
+
PLATFORM_UNAVAILABLE = 'PLATFORM_UNAVAILABLE',
|
28
|
+
|
29
|
+
// Content errors
|
30
|
+
CONTENT_POLICY_VIOLATION = 'CONTENT_POLICY_VIOLATION',
|
31
|
+
DUPLICATE_CONTENT = 'DUPLICATE_CONTENT',
|
32
|
+
|
33
|
+
// Media errors
|
34
|
+
MEDIA_UPLOAD_FAILED = 'MEDIA_UPLOAD_FAILED',
|
35
|
+
|
36
|
+
// Post errors
|
37
|
+
MULTI_STATUS = 'MULTI_STATUS',
|
38
|
+
POST_CREATION_FAILED = 'POST_CREATION_FAILED',
|
39
|
+
THREAD_CREATION_FAILED = 'THREAD_CREATION_FAILED',
|
40
|
+
POST_DELETION_FAILED = 'POST_DELETION_FAILED',
|
41
|
+
POST_INTERACTION_FAILED = 'POST_INTERACTION_FAILED',
|
42
|
+
|
43
|
+
// Network errors
|
44
|
+
NETWORK_ERROR = 'NETWORK_ERROR',
|
45
|
+
}
|
46
|
+
|
47
|
+
export const ApiErrorCodeSchema = z.enum(Object.values(ApiErrorCode) as [string, ...string[]]);
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Map of API error codes to HTTP status codes
|
51
|
+
* This ensures consistent HTTP status codes across the application
|
52
|
+
*/
|
53
|
+
export const errorCodeToStatusCode: Record<ApiErrorCode, StatusCode> = {
|
54
|
+
[ApiErrorCode.MULTI_STATUS]: 207,
|
55
|
+
[ApiErrorCode.UNKNOWN_ERROR]: 500,
|
56
|
+
[ApiErrorCode.INTERNAL_ERROR]: 500,
|
57
|
+
[ApiErrorCode.VALIDATION_ERROR]: 400,
|
58
|
+
[ApiErrorCode.INVALID_REQUEST]: 400,
|
59
|
+
[ApiErrorCode.NOT_FOUND]: 404,
|
60
|
+
[ApiErrorCode.UNAUTHORIZED]: 401,
|
61
|
+
[ApiErrorCode.FORBIDDEN]: 403,
|
62
|
+
[ApiErrorCode.RATE_LIMITED]: 429,
|
63
|
+
[ApiErrorCode.PLATFORM_ERROR]: 502,
|
64
|
+
[ApiErrorCode.PLATFORM_UNAVAILABLE]: 503,
|
65
|
+
[ApiErrorCode.CONTENT_POLICY_VIOLATION]: 400,
|
66
|
+
[ApiErrorCode.DUPLICATE_CONTENT]: 400,
|
67
|
+
[ApiErrorCode.MEDIA_UPLOAD_FAILED]: 400,
|
68
|
+
[ApiErrorCode.POST_CREATION_FAILED]: 500,
|
69
|
+
[ApiErrorCode.THREAD_CREATION_FAILED]: 500,
|
70
|
+
[ApiErrorCode.POST_DELETION_FAILED]: 500,
|
71
|
+
[ApiErrorCode.POST_INTERACTION_FAILED]: 500,
|
72
|
+
[ApiErrorCode.NETWORK_ERROR]: 503,
|
73
|
+
};
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Common error details that can be included in any error
|
77
|
+
*/
|
78
|
+
export interface ErrorDetails {
|
79
|
+
platform?: PlatformName;
|
80
|
+
userId?: string;
|
81
|
+
[key: string]: unknown;
|
82
|
+
}
|
83
|
+
|
84
|
+
export const ErrorDetailSchema = z.object({
|
85
|
+
message: z.string().describe('Human-readable error message'),
|
86
|
+
code: ApiErrorCodeSchema.describe('Machine-readable error code'),
|
87
|
+
recoverable: z.boolean().describe('Whether the error can be recovered from'),
|
88
|
+
details: z.record(z.unknown()).optional().describe('Additional error details'),
|
89
|
+
});
|
90
|
+
|
91
|
+
export type ErrorDetail = z.infer<typeof ErrorDetailSchema>;
|
92
|
+
|
93
|
+
export interface ApiErrorResponse {
|
94
|
+
success: false;
|
95
|
+
errors: ErrorDetail[];
|
96
|
+
meta: ResponseMeta;
|
97
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,18 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* @crosspost/types
|
3
|
-
* Shared TypeScript type definitions and Zod schemas for the Crosspost API ecosystem
|
4
|
-
*/
|
5
|
-
|
6
|
-
// Export common types and schemas
|
7
1
|
export * from './common.ts';
|
8
|
-
|
9
|
-
// Export enhanced response types and schemas
|
10
2
|
export * from './response.ts';
|
11
|
-
|
12
|
-
// Export error types
|
13
|
-
export * from './errors/index.ts';
|
14
|
-
|
15
|
-
// Export domain-specific types and schemas
|
3
|
+
export * from './errors.ts';
|
16
4
|
export * from './auth.ts';
|
17
5
|
export * from './post.ts';
|
18
6
|
export * from './rate-limit.ts';
|