-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
333 lines (306 loc) · 8.96 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import {z} from 'zod';
type Without<T, U> = {[P in Exclude<keyof T, keyof U>]?: never};
type XOR<T, U> = T | U extends object
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U;
export type CursorPaginationParams = {
before?: string;
after?: string;
limit?: number;
};
export type TemporalRangeParams = {
since?: string;
until?: string;
};
export type TemporalPaginationParams = TemporalRangeParams & {
limit?: number;
};
const makePaginatedResponseSchema = <T>(dataSchema: z.ZodType<T>) =>
z.object({
data: z.array(dataSchema),
paging: z.object({
cursors: z.object({
before: z.string().optional(),
after: z.string().optional(),
}),
}),
});
export const SuccessResponseSchema = z.object({
success: z.boolean(),
});
export type SuccessResponse = z.infer<typeof SuccessResponseSchema>;
export const ErrorResponseSchema = z.object({
error: z.object({
code: z.number().optional(),
fbtrace_id: z.string().optional(),
message: z.string().optional(),
type: z.string().optional(),
}),
});
export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
export const ExchangeAuthorizationCodeResponseSchema = z.object({
access_token: z.string(),
user_id: z.coerce.string(),
});
export type ExchangeAuthorizationCodeResponse = z.infer<
typeof ExchangeAuthorizationCodeResponseSchema
>;
export type CreateMediaContainerParams = {
replyToId?: string;
replyControl?: 'everyone' | 'accounts_you_follow' | 'mentioned_only';
} & (
| {
mediaType: 'TEXT';
text: string;
}
| {
mediaType: 'IMAGE';
imageUrl: string;
isCarouselItem?: boolean;
text?: string;
}
| {
mediaType: 'VIDEO';
videoUrl: string;
isCarouselItem?: boolean;
text?: string;
}
| {
mediaType: 'CAROUSEL';
children: string[];
text?: string;
}
);
export const CreateMediaContainerResponseSchema = z.object({
id: z.string(),
});
export type CreateMediaContainerResponse = z.infer<
typeof CreateMediaContainerResponseSchema
>;
export type PublishParams = {
creationId: string;
};
export const PublishResponseSchema = z.object({
id: z.string(),
});
export type PublishResponse = z.infer<typeof PublishResponseSchema>;
export const ThreadsMediaObjectSchema = z.object({
id: z.string().optional(),
media_product_type: z.string().optional(),
media_type: z
.enum([
'TEXT_POST',
'IMAGE',
'VIDEO',
'CAROUSEL_ALBUM',
'AUDIO',
'REPOST_FACADE',
])
.optional(),
media_url: z.string().optional(),
permalink: z.string().optional(),
owner: z.string().optional(),
username: z.string().optional(),
text: z.string().optional(),
timestamp: z.string().optional(),
shortcode: z.string().optional(),
thumbnail_url: z.string().optional(),
// TODO: check if this is an array of string IDs or an array of media objects
children: z.array(z.string()).optional(),
is_quote_post: z.boolean().optional(),
is_reply: z.boolean().optional(),
status_code: z.string().optional(),
});
export type ThreadsMediaObject = z.infer<typeof ThreadsMediaObjectSchema>;
export type ThreadsMediaObjectField = keyof ThreadsMediaObject;
export const ThreadsReplySchema = z.object({
id: z.string().optional(),
text: z.string().optional(),
username: z.string().optional(),
permalink: z.string().optional(),
timestamp: z.string().optional(),
media_product_type: z.string().optional(),
media_type: z
.enum(['TEXT_POST', 'IMAGE', 'VIDEO', 'CAROUSEL_ALBUM', 'AUDIO'])
.optional(),
media_url: z.string().optional(),
shortcode: z.string().optional(),
thumbnail_url: z.string().optional(),
// TODO: check if this is an array of string IDs or an array of media objects
children: z.array(z.string()).optional(),
is_quote_post: z.boolean().optional(),
has_replies: z.boolean().optional(),
root_post: z.string().optional(),
replied_to: z.string().optional(),
is_reply: z.boolean().optional(),
is_reply_owned_by_me: z.boolean().optional(),
hide_status: z
.enum([
'NOT_HUSHED',
'UNHUSHED',
'HIDDEN',
'COVERED',
'BLOCKED',
'RESTRICTED',
])
.optional(),
});
export type ThreadsReply = z.infer<typeof ThreadsReplySchema>;
export type ThreadsReplyField = keyof ThreadsReply;
export type GetUserThreadsParams = {
id: string;
fields?: ThreadsMediaObjectField[];
} & XOR<TemporalPaginationParams, CursorPaginationParams>;
export const GetUserThreadsResponseSchema = makePaginatedResponseSchema(
ThreadsMediaObjectSchema,
);
export type GetUserThreadsResponse = z.infer<
typeof GetUserThreadsResponseSchema
>;
export type GetMediaObjectParams = {
id: string;
fields?: ThreadsMediaObjectField[];
};
export const GetMediaObjectResponseSchema = ThreadsMediaObjectSchema;
export type GetMediaObjectResponse = z.infer<
typeof GetMediaObjectResponseSchema
>;
export type GetRepliesParams = {
id: string;
fields?: ThreadsReplyField[];
reverse?: boolean;
} & XOR<TemporalPaginationParams, CursorPaginationParams>;
export const GetRepliesResponseSchema =
makePaginatedResponseSchema(ThreadsReplySchema);
export type GetRepliesResponse = z.infer<typeof GetRepliesResponseSchema>;
export type GetConversationParams = {
id: string;
fields?: ThreadsReplyField[];
reverse?: boolean;
} & XOR<TemporalPaginationParams, CursorPaginationParams>;
export const GetConversationResponseSchema =
makePaginatedResponseSchema(ThreadsReplySchema);
export type GetConversationResponse = z.infer<
typeof GetConversationResponseSchema
>;
export type ManageReplyParams = {
id: string;
hide: boolean;
};
export const ManageReplyResponseSchema = SuccessResponseSchema;
export type ManageReplyResponse = z.infer<typeof ManageReplyResponseSchema>;
export const ThreadsUserProfileSchema = z.object({
id: z.string().optional(),
username: z.string().optional(),
threads_profile_picture_url: z.string().optional(),
threads_biography: z.string().optional(),
});
export type ThreadsUserProfile = z.infer<typeof ThreadsUserProfileSchema>;
export type ThreadsUserProfileField = keyof ThreadsUserProfile;
export type GetUserProfileParams = {
id: string;
fields?: ThreadsUserProfileField[];
};
export const GetUserProfileResponseSchema = ThreadsUserProfileSchema;
export type GetUserProfileResponse = z.infer<
typeof GetUserProfileResponseSchema
>;
export const ThreadsPublishingLimitSchema = z.object({
data: z.array(
z.object({
reply_quota_usage: z.number().optional(),
reply_config: z
.object({
quota_total: z.number().optional(),
quota_duration: z.number().optional(),
})
.optional(),
}),
),
});
export type ThreadsPublishingLimit = z.infer<
typeof ThreadsPublishingLimitSchema
>;
export type ThreadsPublishingLimitField =
keyof ThreadsPublishingLimit['data'][0];
export type GetUserThreadsPublishingLimitParams = {
id: string;
fields?: ThreadsPublishingLimitField[];
};
export const GetUserThreadsPublishingLimitResponseSchema =
ThreadsPublishingLimitSchema;
export type GetUserThreadsPublishingLimitResponse = z.infer<
typeof GetUserThreadsPublishingLimitResponseSchema
>;
export const ThreadsMediaMetricSchema = z.enum([
'views',
'likes',
'replies',
'reposts',
'quotes',
]);
export type ThreadsMediaMetric = z.infer<typeof ThreadsMediaMetricSchema>;
export const ThreadsMediaMetricValueSchema = z.object({
name: ThreadsMediaMetricSchema,
// TODO: figure out literal union type
period: z.string(),
values: z.array(
z.object({
value: z.number(),
}),
),
title: z.string(),
description: z.string(),
id: z.string(),
});
export type ThreadsMediaMetricValue = z.infer<
typeof ThreadsMediaMetricValueSchema
>;
export type GetMediaMetricsParams = {
id: string;
metrics?: ThreadsMediaMetric[];
} & TemporalRangeParams;
export const GetMediaMetricsResponseSchema = z.object({
data: z.array(ThreadsMediaMetricValueSchema),
});
export type GetMediaMetricsResponse = z.infer<
typeof GetMediaMetricsResponseSchema
>;
export const ThreadsAccountMetricSchema = z.enum([
'views',
'likes',
'replies',
'reposts',
'quotes',
'followers_count',
'follower_demographics',
]);
export type ThreadsAccountMetric = z.infer<typeof ThreadsAccountMetricSchema>;
export const ThreadsAccountMetricValueSchema = z.object({
name: ThreadsAccountMetricSchema,
// TODO: figure out literal union type
period: z.string(),
// TODO: can we restrict this to be a homogenous array?
values: z.array(
z.object({
value: z.number(),
end_time: z.string().optional(),
}),
),
title: z.string(),
description: z.string(),
id: z.string(),
});
export type ThreadsAccountMetricValue = z.infer<
typeof ThreadsAccountMetricValueSchema
>;
export type GetAccountMetricsParams = {
id: string;
metrics?: ThreadsAccountMetric[];
} & TemporalRangeParams;
export const GetAccountMetricsResponseSchema = z.object({
data: z.array(ThreadsAccountMetricValueSchema),
});
export type GetAccountMetricsResponse = z.infer<
typeof GetAccountMetricsResponseSchema
>;