@crosspost/types 0.1.2
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/README.md +125 -0
- package/dist/index.cjs +964 -0
- package/dist/index.d.cts +7421 -0
- package/dist/index.d.ts +7421 -0
- package/dist/index.js +852 -0
- package/mod.ts +9 -0
- package/package.json +51 -0
- package/src/auth.ts +121 -0
- package/src/common.ts +33 -0
- package/src/errors/api-error.ts +153 -0
- package/src/errors/base-error.ts +13 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/platform-error.ts +34 -0
- package/src/index.ts +20 -0
- package/src/leaderboard.ts +179 -0
- package/src/post.ts +347 -0
- package/src/rate-limit.ts +145 -0
- package/src/response.ts +297 -0
- package/src/user-profile.ts +43 -0
package/src/post.ts
ADDED
@@ -0,0 +1,347 @@
|
|
1
|
+
/**
|
2
|
+
* Post Schemas and Types
|
3
|
+
* Defines Zod schemas for post-related requests and responses
|
4
|
+
* TypeScript types are derived from Zod schemas for type safety
|
5
|
+
*/
|
6
|
+
|
7
|
+
import { z } from 'zod';
|
8
|
+
import { PlatformSchema } from './common.ts';
|
9
|
+
import { EnhancedResponseSchema, ErrorDetailSchema } from './response.ts';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Media content schema
|
13
|
+
*/
|
14
|
+
export const MediaContentSchema = z.object({
|
15
|
+
data: z.union([z.string(), z.instanceof(Blob)]).describe('Media data as string or Blob'),
|
16
|
+
mimeType: z.string().optional().describe('Media MIME type'),
|
17
|
+
altText: z.string().optional().describe('Alt text for the media'),
|
18
|
+
}).describe('Media content object');
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Media schema
|
22
|
+
*/
|
23
|
+
export const MediaSchema = z.object({
|
24
|
+
id: z.string().describe('Media ID'),
|
25
|
+
type: z.enum(['image', 'video', 'gif']).describe('Media type'),
|
26
|
+
url: z.string().optional().describe('Media URL'),
|
27
|
+
altText: z.string().optional().describe('Alt text for the media'),
|
28
|
+
}).describe('Media object');
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Post metrics schema
|
32
|
+
*/
|
33
|
+
export const PostMetricsSchema = z.object({
|
34
|
+
retweets: z.number().describe('Number of retweets'),
|
35
|
+
quotes: z.number().describe('Number of quotes'),
|
36
|
+
likes: z.number().describe('Number of likes'),
|
37
|
+
replies: z.number().describe('Number of replies'),
|
38
|
+
}).describe('Post metrics');
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Post schema
|
42
|
+
*/
|
43
|
+
export const PostSchema = z.object({
|
44
|
+
id: z.string().describe('Post ID'),
|
45
|
+
text: z.string().describe('Post text content'),
|
46
|
+
createdAt: z.string().describe('Post creation date'),
|
47
|
+
authorId: z.string().describe('Author ID'),
|
48
|
+
media: z.array(MediaSchema).optional().describe('Media attached to the post'),
|
49
|
+
metrics: PostMetricsSchema.optional().describe('Post metrics'),
|
50
|
+
inReplyToId: z.string().optional().describe('ID of the post this is a reply to'),
|
51
|
+
quotedPostId: z.string().optional().describe('ID of the post this is quoting'),
|
52
|
+
}).describe('Post object');
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Post content schema
|
56
|
+
*/
|
57
|
+
export const PostContentSchema = z.object({
|
58
|
+
text: z.string().optional().describe('Text content for the post'),
|
59
|
+
media: z.array(MediaContentSchema).optional().describe('Media attachments for the post'),
|
60
|
+
}).describe('Post content');
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Post result schema
|
64
|
+
*/
|
65
|
+
export const PostResultSchema = z.object({
|
66
|
+
id: z.string().describe('Post ID'),
|
67
|
+
text: z.string().optional().describe('Post text content'),
|
68
|
+
createdAt: z.string().describe('Post creation date'),
|
69
|
+
mediaIds: z.array(z.string()).optional().describe('Media IDs attached to the post'),
|
70
|
+
threadIds: z.array(z.string()).optional().describe('Thread IDs for threaded posts'),
|
71
|
+
quotedPostId: z.string().optional().describe('ID of the post this is quoting'),
|
72
|
+
inReplyToId: z.string().optional().describe('ID of the post this is a reply to'),
|
73
|
+
success: z.boolean().optional().describe('Whether the operation was successful'),
|
74
|
+
}).catchall(z.any()).describe('Post result');
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Delete result schema
|
78
|
+
*/
|
79
|
+
export const DeleteResultSchema = z.object({
|
80
|
+
success: z.boolean().describe('Whether the deletion was successful'),
|
81
|
+
id: z.string().describe('ID of the deleted post'),
|
82
|
+
}).describe('Delete result');
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Like result schema
|
86
|
+
*/
|
87
|
+
export const LikeResultSchema = z.object({
|
88
|
+
success: z.boolean().describe('Whether the like was successful'),
|
89
|
+
id: z.string().describe('ID of the liked post'),
|
90
|
+
}).describe('Like result');
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Success detail schema for post operations
|
94
|
+
*/
|
95
|
+
export const PostSuccessDetailSchema = z.object({
|
96
|
+
platform: PlatformSchema,
|
97
|
+
userId: z.string().describe('User ID'),
|
98
|
+
status: z.literal('success'),
|
99
|
+
postId: z.string().optional().describe('Post ID'),
|
100
|
+
postUrl: z.string().optional().describe('URL to the post'),
|
101
|
+
}).catchall(z.any()).describe('Post success detail');
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Request schemas
|
105
|
+
*/
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Target schema - common for all operations
|
109
|
+
*/
|
110
|
+
export const TargetSchema = z.object({
|
111
|
+
platform: PlatformSchema.describe('The platform to post to (e.g., "twitter")'),
|
112
|
+
userId: z.string().describe('User ID on the platform'),
|
113
|
+
}).describe('Target for posting operations');
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Create post request schema
|
117
|
+
*/
|
118
|
+
export const CreatePostRequestSchema = z.object({
|
119
|
+
targets: z.array(TargetSchema).describe('Array of targets to post to (can be a single target)'),
|
120
|
+
content: z.array(PostContentSchema).describe(
|
121
|
+
'The content of the post, always an array of PostContent objects, even for a single post',
|
122
|
+
),
|
123
|
+
}).describe('Create post request');
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Repost request schema
|
127
|
+
*/
|
128
|
+
export const RepostRequestSchema = z.object({
|
129
|
+
targets: z.array(TargetSchema).describe('Array of targets to post to'),
|
130
|
+
platform: PlatformSchema.describe('Platform of the post being reposted'),
|
131
|
+
postId: z.string().describe('ID of the post to repost'),
|
132
|
+
}).describe('Repost request');
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Quote post request schema
|
136
|
+
*/
|
137
|
+
export const QuotePostRequestSchema = z.object({
|
138
|
+
targets: z.array(TargetSchema).describe(
|
139
|
+
'Array of targets to post to (must be on the same platform as the post being quoted)',
|
140
|
+
),
|
141
|
+
platform: PlatformSchema.describe('Platform of the post being quoted'),
|
142
|
+
postId: z.string().describe('ID of the post to quote'),
|
143
|
+
content: z.array(PostContentSchema).describe(
|
144
|
+
'Content for the quote post(s), always an array, even for a single post',
|
145
|
+
),
|
146
|
+
}).describe('Quote post request');
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Reply to post request schema
|
150
|
+
*/
|
151
|
+
export const ReplyToPostRequestSchema = z.object({
|
152
|
+
targets: z.array(TargetSchema).describe(
|
153
|
+
'Array of targets to post to (must be on the same platform as the post being replied to)',
|
154
|
+
),
|
155
|
+
platform: PlatformSchema.describe('Platform of the post being replied to'),
|
156
|
+
postId: z.string().describe('ID of the post to reply to'),
|
157
|
+
content: z.array(PostContentSchema).describe(
|
158
|
+
'Content for the reply post(s), always an array, even for a single post',
|
159
|
+
),
|
160
|
+
}).describe('Reply to post request');
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Post to delete schema
|
164
|
+
*/
|
165
|
+
export const PostToDeleteSchema = z.object({
|
166
|
+
platform: PlatformSchema.describe('Platform of the post to delete'),
|
167
|
+
userId: z.string().describe('User ID on the platform'),
|
168
|
+
postId: z.string().describe('ID of the post to delete'),
|
169
|
+
}).describe('Post to delete');
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Delete post request schema
|
173
|
+
*/
|
174
|
+
export const DeletePostRequestSchema = z.object({
|
175
|
+
targets: z.array(TargetSchema).describe('Array of targets to delete posts'),
|
176
|
+
posts: z.array(PostToDeleteSchema).describe('Array of posts to delete'),
|
177
|
+
}).describe('Delete post request');
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Like post request schema
|
181
|
+
*/
|
182
|
+
export const LikePostRequestSchema = z.object({
|
183
|
+
targets: z.array(TargetSchema).describe(
|
184
|
+
'Array of targets to like the post (must be on the same platform as the post being liked)',
|
185
|
+
),
|
186
|
+
platform: PlatformSchema.describe('Platform of the post being liked'),
|
187
|
+
postId: z.string().describe('ID of the post to like'),
|
188
|
+
}).describe('Like post request');
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Unlike post request schema
|
192
|
+
*/
|
193
|
+
export const UnlikePostRequestSchema = z.object({
|
194
|
+
targets: z.array(TargetSchema).describe(
|
195
|
+
'Array of targets to unlike the post (must be on the same platform as the post being unliked)',
|
196
|
+
),
|
197
|
+
platform: PlatformSchema.describe('Platform of the post being unliked'),
|
198
|
+
postId: z.string().describe('ID of the post to unlike'),
|
199
|
+
}).describe('Unlike post request');
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Response schemas
|
203
|
+
*/
|
204
|
+
|
205
|
+
/**
|
206
|
+
* Post response schema
|
207
|
+
*/
|
208
|
+
export const PostResponseSchema = EnhancedResponseSchema(
|
209
|
+
z.union([PostSchema, z.array(PostSchema)]),
|
210
|
+
).describe('Post response');
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Create post response schema (legacy)
|
214
|
+
*/
|
215
|
+
export const CreatePostResponseLegacySchema = PostResponseSchema.describe(
|
216
|
+
'Create post response (legacy)',
|
217
|
+
);
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Repost response schema
|
221
|
+
*/
|
222
|
+
export const RepostResponseSchema = PostResponseSchema.describe('Repost response');
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Quote post response schema
|
226
|
+
*/
|
227
|
+
export const QuotePostResponseSchema = PostResponseSchema.describe('Quote post response');
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Reply to post response schema
|
231
|
+
*/
|
232
|
+
export const ReplyToPostResponseSchema = PostResponseSchema.describe('Reply to post response');
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Delete post response schema
|
236
|
+
*/
|
237
|
+
export const DeletePostResponseSchema = EnhancedResponseSchema(
|
238
|
+
z.object({
|
239
|
+
success: z.boolean().describe('Whether the deletion was successful'),
|
240
|
+
id: z.string().describe('ID of the deleted post'),
|
241
|
+
}),
|
242
|
+
).describe('Delete post response');
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Like post response schema
|
246
|
+
*/
|
247
|
+
export const LikePostResponseSchema = EnhancedResponseSchema(
|
248
|
+
z.object({
|
249
|
+
success: z.boolean().describe('Whether the like was successful'),
|
250
|
+
id: z.string().describe('ID of the liked post'),
|
251
|
+
}),
|
252
|
+
).describe('Like post response');
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Unlike post response schema
|
256
|
+
*/
|
257
|
+
export const UnlikePostResponseSchema = EnhancedResponseSchema(
|
258
|
+
z.object({
|
259
|
+
success: z.boolean().describe('Whether the unlike was successful'),
|
260
|
+
id: z.string().describe('ID of the unliked post'),
|
261
|
+
}),
|
262
|
+
).describe('Unlike post response');
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Multi-status response schema for batch operations
|
266
|
+
*/
|
267
|
+
export const PostMultiStatusResponseSchema = z.object({
|
268
|
+
success: z.boolean().describe('Whether the operation was partially or fully successful'),
|
269
|
+
data: z.object({
|
270
|
+
summary: z.object({
|
271
|
+
total: z.number().describe('Total number of operations'),
|
272
|
+
succeeded: z.number().describe('Number of successful operations'),
|
273
|
+
failed: z.number().describe('Number of failed operations'),
|
274
|
+
}),
|
275
|
+
results: z.array(PostSuccessDetailSchema).describe('Successful operations'),
|
276
|
+
errors: z.array(ErrorDetailSchema).describe('Failed operations'),
|
277
|
+
}),
|
278
|
+
}).describe('Multi-status response for post operations');
|
279
|
+
|
280
|
+
// Derive TypeScript types from Zod schemas
|
281
|
+
export type Media = z.infer<typeof MediaSchema>;
|
282
|
+
export type MediaContent = z.infer<typeof MediaContentSchema>;
|
283
|
+
export type PostMetrics = z.infer<typeof PostMetricsSchema>;
|
284
|
+
export type Post = z.infer<typeof PostSchema>;
|
285
|
+
export type PostContent = z.infer<typeof PostContentSchema>;
|
286
|
+
export type PostResult = z.infer<typeof PostResultSchema>;
|
287
|
+
export type DeleteResult = z.infer<typeof DeleteResultSchema>;
|
288
|
+
export type LikeResult = z.infer<typeof LikeResultSchema>;
|
289
|
+
export type PostSuccessDetail = z.infer<typeof PostSuccessDetailSchema>;
|
290
|
+
export type Target = z.infer<typeof TargetSchema>;
|
291
|
+
export type PostToDelete = z.infer<typeof PostToDeleteSchema>;
|
292
|
+
|
293
|
+
// Request types
|
294
|
+
export type CreatePostRequest = z.infer<typeof CreatePostRequestSchema>;
|
295
|
+
export type RepostRequest = z.infer<typeof RepostRequestSchema>;
|
296
|
+
export type QuotePostRequest = z.infer<typeof QuotePostRequestSchema>;
|
297
|
+
export type ReplyToPostRequest = z.infer<typeof ReplyToPostRequestSchema>;
|
298
|
+
export type DeletePostRequest = z.infer<typeof DeletePostRequestSchema>;
|
299
|
+
export type LikePostRequest = z.infer<typeof LikePostRequestSchema>;
|
300
|
+
export type UnlikePostRequest = z.infer<typeof UnlikePostRequestSchema>;
|
301
|
+
|
302
|
+
// Response types
|
303
|
+
export type PostResponse = z.infer<typeof PostResponseSchema>;
|
304
|
+
export type CreatePostResponse = z.infer<typeof CreatePostResponseLegacySchema>;
|
305
|
+
export type RepostResponse = z.infer<typeof RepostResponseSchema>;
|
306
|
+
export type QuotePostResponse = z.infer<typeof QuotePostResponseSchema>;
|
307
|
+
export type ReplyToPostResponse = z.infer<typeof ReplyToPostResponseSchema>;
|
308
|
+
export type DeletePostResponse = z.infer<typeof DeletePostResponseSchema>;
|
309
|
+
export type LikePostResponse = z.infer<typeof LikePostResponseSchema>;
|
310
|
+
export type UnlikePostResponse = z.infer<typeof UnlikePostResponseSchema>;
|
311
|
+
export type PostMultiStatusResponse = z.infer<typeof PostMultiStatusResponseSchema>;
|
312
|
+
|
313
|
+
/**
|
314
|
+
* Create post target result schema
|
315
|
+
*/
|
316
|
+
export const CreatePostTargetResultSchema = z.object({
|
317
|
+
platform: PlatformSchema.describe('The platform the post was created on'),
|
318
|
+
userId: z.string().describe('The user ID on the platform'),
|
319
|
+
result: z.array(z.any()).describe('The result of the post creation'),
|
320
|
+
}).describe('Create post target result');
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Create post target error schema
|
324
|
+
*/
|
325
|
+
export const CreatePostTargetErrorSchema = z.object({
|
326
|
+
platform: PlatformSchema.optional().describe(
|
327
|
+
'The platform where the error occurred (if applicable)',
|
328
|
+
),
|
329
|
+
userId: z.string().optional().describe('The user ID where the error occurred (if applicable)'),
|
330
|
+
error: z.string().describe('The error message'),
|
331
|
+
}).describe('Create post target error');
|
332
|
+
|
333
|
+
/**
|
334
|
+
* Create post response schema
|
335
|
+
*/
|
336
|
+
export const CreatePostResponseSchema = EnhancedResponseSchema(
|
337
|
+
z.object({
|
338
|
+
results: z.array(CreatePostTargetResultSchema).describe('Array of successful post results'),
|
339
|
+
errors: z.array(CreatePostTargetErrorSchema).optional().describe(
|
340
|
+
'Array of errors that occurred (if any)',
|
341
|
+
),
|
342
|
+
}),
|
343
|
+
).describe('Create post response');
|
344
|
+
|
345
|
+
// Additional derived types
|
346
|
+
export type CreatePostTargetResult = z.infer<typeof CreatePostTargetResultSchema>;
|
347
|
+
export type CreatePostTargetError = z.infer<typeof CreatePostTargetErrorSchema>;
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/**
|
2
|
+
* Rate Limit Schemas and Types
|
3
|
+
* Defines Zod schemas for rate limit-related requests and responses
|
4
|
+
* TypeScript types are derived from Zod schemas for type safety
|
5
|
+
*/
|
6
|
+
|
7
|
+
import { z } from 'zod';
|
8
|
+
import { EnhancedResponseSchema } from './response.ts';
|
9
|
+
import { PlatformSchema } from './common.ts';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Rate limit endpoint parameter schema
|
13
|
+
*/
|
14
|
+
export const RateLimitEndpointParamSchema = z.object({
|
15
|
+
endpoint: z.string().optional().describe(
|
16
|
+
'Specific endpoint to get rate limit information for (optional)',
|
17
|
+
),
|
18
|
+
}).describe('Rate limit endpoint parameter');
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Rate limit endpoint schema
|
22
|
+
*/
|
23
|
+
export const RateLimitEndpointSchema = z.object({
|
24
|
+
endpoint: z.string().describe('API endpoint'),
|
25
|
+
method: z.enum(['GET', 'POST', 'PUT', 'DELETE']).describe('HTTP method'),
|
26
|
+
limit: z.number().describe('Rate limit'),
|
27
|
+
remaining: z.number().describe('Remaining requests'),
|
28
|
+
reset: z.number().describe('Reset timestamp (Unix timestamp in seconds)'),
|
29
|
+
resetDate: z.string().describe('Reset date (ISO string)'),
|
30
|
+
}).describe('Rate limit endpoint');
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Rate limit status schema
|
34
|
+
*/
|
35
|
+
export const RateLimitStatusSchema = z.object({
|
36
|
+
endpoint: z.string().describe('API endpoint or action'),
|
37
|
+
limit: z.number().describe('Maximum number of requests allowed in the time window'),
|
38
|
+
remaining: z.number().describe('Number of requests remaining in the current time window'),
|
39
|
+
reset: z.string().datetime().describe('Timestamp when the rate limit will reset'),
|
40
|
+
resetSeconds: z.number().describe('Seconds until the rate limit will reset'),
|
41
|
+
}).describe('Rate limit status');
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Platform-specific rate limit schema
|
45
|
+
*/
|
46
|
+
export const PlatformRateLimitSchema = z.object({
|
47
|
+
platform: PlatformSchema,
|
48
|
+
endpoints: z.record(z.string(), RateLimitStatusSchema).describe(
|
49
|
+
'Rate limit status for each endpoint',
|
50
|
+
),
|
51
|
+
}).describe('Platform-specific rate limit');
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Usage rate limit schema
|
55
|
+
*/
|
56
|
+
export const UsageRateLimitSchema = z.object({
|
57
|
+
endpoint: z.string().describe('API endpoint or action'),
|
58
|
+
limit: z.number().describe('Maximum number of requests allowed in the time window'),
|
59
|
+
remaining: z.number().describe('Number of requests remaining in the current time window'),
|
60
|
+
reset: z.string().datetime().describe('Timestamp when the rate limit will reset'),
|
61
|
+
resetSeconds: z.number().describe('Seconds until the rate limit will reset'),
|
62
|
+
timeWindow: z.string().describe('Time window for the rate limit'),
|
63
|
+
}).describe('Usage rate limit');
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Rate limit status response schema
|
67
|
+
*/
|
68
|
+
export const RateLimitStatusResponseSchema = EnhancedResponseSchema(
|
69
|
+
z.object({
|
70
|
+
platform: PlatformSchema,
|
71
|
+
userId: z.string().optional().describe('User ID'),
|
72
|
+
endpoints: z.array(RateLimitEndpointSchema).describe('Rate limits for specific endpoints'),
|
73
|
+
app: z.object({
|
74
|
+
limit: z.number().describe('App-wide rate limit'),
|
75
|
+
remaining: z.number().describe('Remaining requests'),
|
76
|
+
reset: z.number().describe('Reset timestamp (Unix timestamp in seconds)'),
|
77
|
+
resetDate: z.string().describe('Reset date (ISO string)'),
|
78
|
+
}).optional().describe('App-wide rate limits'),
|
79
|
+
}),
|
80
|
+
).describe('Rate limit status response');
|
81
|
+
|
82
|
+
/**
|
83
|
+
* All rate limits response schema
|
84
|
+
*/
|
85
|
+
export const AllRateLimitsResponseSchema = EnhancedResponseSchema(
|
86
|
+
z.object({
|
87
|
+
platforms: z.record(
|
88
|
+
PlatformSchema,
|
89
|
+
z.object({
|
90
|
+
users: z.record(
|
91
|
+
z.string(),
|
92
|
+
z.object({
|
93
|
+
endpoints: z.array(RateLimitEndpointSchema).describe(
|
94
|
+
'Rate limits for specific endpoints',
|
95
|
+
),
|
96
|
+
lastUpdated: z.string().describe('Last updated date (ISO string)'),
|
97
|
+
}),
|
98
|
+
).describe('User-specific rate limits'),
|
99
|
+
app: z.object({
|
100
|
+
limit: z.number().describe('App-wide rate limit'),
|
101
|
+
remaining: z.number().describe('Remaining requests'),
|
102
|
+
reset: z.number().describe('Reset timestamp (Unix timestamp in seconds)'),
|
103
|
+
resetDate: z.string().describe('Reset date (ISO string)'),
|
104
|
+
}).optional().describe('App-wide rate limits'),
|
105
|
+
}),
|
106
|
+
).describe('Rate limits by platform'),
|
107
|
+
}),
|
108
|
+
).describe('All rate limits response');
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Rate limit response schema
|
112
|
+
*/
|
113
|
+
export const RateLimitResponseSchema = z.object({
|
114
|
+
platformLimits: z.array(PlatformRateLimitSchema).describe('Platform-specific rate limits'),
|
115
|
+
usageLimits: z.record(z.string(), UsageRateLimitSchema).describe(
|
116
|
+
'Usage-based rate limits for the NEAR account',
|
117
|
+
),
|
118
|
+
signerId: z.string().describe('NEAR account ID'),
|
119
|
+
}).describe('Rate limit response');
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Single endpoint rate limit response schema
|
123
|
+
*/
|
124
|
+
export const EndpointRateLimitResponseSchema = z.object({
|
125
|
+
platformLimits: z.array(
|
126
|
+
z.object({
|
127
|
+
platform: PlatformSchema,
|
128
|
+
status: RateLimitStatusSchema.describe('Rate limit status for the endpoint'),
|
129
|
+
}),
|
130
|
+
).describe('Platform-specific rate limits for the endpoint'),
|
131
|
+
usageLimit: UsageRateLimitSchema.describe('Usage-based rate limit for the NEAR account'),
|
132
|
+
endpoint: z.string().describe('API endpoint or action'),
|
133
|
+
signerId: z.string().describe('NEAR account ID'),
|
134
|
+
}).describe('Endpoint rate limit response');
|
135
|
+
|
136
|
+
// Derive TypeScript types from Zod schemas
|
137
|
+
export type RateLimitEndpointParam = z.infer<typeof RateLimitEndpointParamSchema>;
|
138
|
+
export type RateLimitEndpoint = z.infer<typeof RateLimitEndpointSchema>;
|
139
|
+
export type RateLimitStatus = z.infer<typeof RateLimitStatusSchema>;
|
140
|
+
export type PlatformRateLimit = z.infer<typeof PlatformRateLimitSchema>;
|
141
|
+
export type UsageRateLimit = z.infer<typeof UsageRateLimitSchema>;
|
142
|
+
export type RateLimitStatusResponse = z.infer<typeof RateLimitStatusResponseSchema>;
|
143
|
+
export type AllRateLimitsResponse = z.infer<typeof AllRateLimitsResponseSchema>;
|
144
|
+
export type RateLimitResponse = z.infer<typeof RateLimitResponseSchema>;
|
145
|
+
export type EndpointRateLimitResponse = z.infer<typeof EndpointRateLimitResponseSchema>;
|