@codybrom/denim 1.3.5 → 2.0.0

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.
Files changed (46) hide show
  1. package/.github/workflows/publish.yml +17 -7
  2. package/.vscode/settings.json +34 -9
  3. package/CHANGELOG.md +128 -0
  4. package/deno.json +22 -8
  5. package/deno.lock +17 -59
  6. package/examples/edge-function.ts +171 -177
  7. package/mod.ts +138 -650
  8. package/mod_test.ts +1287 -380
  9. package/package.json +22 -22
  10. package/readme.md +155 -191
  11. package/src/api/createCarouselItem.ts +86 -0
  12. package/src/api/createThreadsContainer.ts +122 -0
  13. package/src/api/debugToken.ts +35 -0
  14. package/src/api/deleteThread.ts +36 -0
  15. package/src/api/exchangeCodeForToken.ts +50 -0
  16. package/src/api/exchangeToken.ts +36 -0
  17. package/src/api/getAppAccessToken.ts +35 -0
  18. package/src/api/getConversation.ts +51 -0
  19. package/src/api/getGhostPosts.ts +50 -0
  20. package/src/api/getLocation.ts +38 -0
  21. package/src/api/getMediaInsights.ts +39 -0
  22. package/src/api/getMentions.ts +57 -0
  23. package/src/api/getOEmbed.ts +41 -0
  24. package/src/api/getProfile.ts +46 -0
  25. package/src/api/getProfilePosts.ts +53 -0
  26. package/src/api/getPublishingLimit.ts +59 -0
  27. package/src/api/getReplies.ts +51 -0
  28. package/src/api/getSingleThread.ts +37 -0
  29. package/src/api/getThreadsList.ts +49 -0
  30. package/src/api/getUserInsights.ts +54 -0
  31. package/src/api/getUserReplies.ts +54 -0
  32. package/src/api/lookupProfile.ts +53 -0
  33. package/src/api/manageReply.ts +41 -0
  34. package/src/api/publishThreadsContainer.ts +107 -0
  35. package/src/api/refreshToken.ts +33 -0
  36. package/src/api/repost.ts +38 -0
  37. package/src/api/searchKeyword.ts +86 -0
  38. package/src/api/searchLocations.ts +46 -0
  39. package/src/constants.ts +80 -0
  40. package/src/types.ts +925 -0
  41. package/src/utils/checkContainerStatus.ts +39 -0
  42. package/src/utils/getAPI.ts +13 -0
  43. package/src/utils/mock_threads_api.ts +582 -0
  44. package/src/utils/validateRequest.ts +166 -0
  45. package/mock_threads_api.ts +0 -174
  46. package/types.ts +0 -235
package/mod.ts CHANGED
@@ -1,657 +1,145 @@
1
- // mod.ts
2
- import type {
3
- ThreadsPostRequest,
4
- PublishingLimit,
5
- ThreadsPost,
6
- ThreadsListResponse,
7
- MockThreadsAPI,
8
- } from "./types.ts";
9
- export type {
10
- ThreadsPostRequest,
11
- PublishingLimit,
12
- ThreadsPost,
13
- ThreadsListResponse,
14
- };
15
-
16
- /**
17
- * Retrieves the mock API instance if available.
18
- *
19
- * @returns The mock API instance or null if not available
20
- */
21
- function getAPI(): MockThreadsAPI | null {
22
- return (globalThis as { threadsAPI?: MockThreadsAPI }).threadsAPI || null;
23
- }
24
-
25
1
  /**
26
2
  * @module
27
3
  *
28
- * This module provides functions to interact with the Threads API,
29
- * allowing users to create and publish posts on Threads.
30
- */
31
-
32
- /** The base URL for the Threads API */
33
- export const THREADS_API_BASE_URL = "https://graph.threads.net/v1.0";
34
-
35
- /**
36
- * Creates a Threads media container.
37
- *
38
- * @param request - The ThreadsPostRequest object containing post details
39
- * @returns A Promise that resolves to the container ID
40
- * @throws Will throw an error if the API request fails
41
- *
42
- * @example
43
- * ```typescript
44
- * const request: ThreadsPostRequest = {
45
- * userId: "123456",
46
- * accessToken: "your_access_token",
47
- * mediaType: "VIDEO",
48
- * text: "Check out this video!",
49
- * videoUrl: "https://example.com/video.mp4",
50
- * altText: "A cool video"
51
- * };
52
- * const containerId = await createThreadsContainer(request);
53
- * ```
54
- */
55
- export async function createThreadsContainer(
56
- request: ThreadsPostRequest
57
- ): Promise<string | { id: string; permalink: string }> {
58
- const api = getAPI();
59
- if (api) {
60
- // Use mock API
61
- return api.createThreadsContainer(request);
62
- }
63
- try {
64
- // Input validation
65
- validateRequest(request);
66
-
67
- const url = `${THREADS_API_BASE_URL}/${request.userId}/threads`;
68
- const body = new URLSearchParams({
69
- access_token: request.accessToken,
70
- media_type: request.mediaType,
71
- });
72
-
73
- // Add common optional parameters
74
- if (request.text) body.append("text", request.text);
75
- if (request.altText) body.append("alt_text", request.altText);
76
- if (request.replyControl)
77
- body.append("reply_control", request.replyControl);
78
- if (request.allowlistedCountryCodes) {
79
- body.append(
80
- "allowlisted_country_codes",
81
- request.allowlistedCountryCodes.join(",")
82
- );
83
- }
84
-
85
- // Handle media type specific parameters
86
- if (request.mediaType === "VIDEO" && request.videoUrl) {
87
- const videoItemId = await createVideoItemContainer(request);
88
- body.set("media_type", "CAROUSEL");
89
- body.append("children", videoItemId);
90
- } else if (request.mediaType === "IMAGE" && request.imageUrl) {
91
- body.append("image_url", request.imageUrl);
92
- } else if (request.mediaType === "TEXT" && request.linkAttachment) {
93
- body.append("link_attachment", request.linkAttachment);
94
- } else if (request.mediaType === "CAROUSEL" && request.children) {
95
- body.append("children", request.children.join(","));
96
- }
97
-
98
- console.log(`Sending request to: ${url}`);
99
- console.log(`Request body: ${body.toString()}`);
100
-
101
- const response = await fetch(url, {
102
- method: "POST",
103
- body: body,
104
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
105
- });
106
-
107
- const responseText = await response.text();
108
-
109
- console.log(`Response status: ${response.status} ${response.statusText}`);
110
- console.log(`Response body: ${responseText}`);
111
-
112
- if (!response.ok) {
113
- throw new Error(`Internal Server Error. Details: ${responseText}`);
114
- }
115
-
116
- const data = JSON.parse(responseText);
117
-
118
- // If getPermalink is true, fetch the permalink
119
- if (request.getPermalink) {
120
- const threadData = await getSingleThread(data.id, request.accessToken);
121
- return {
122
- id: data.id,
123
- permalink: threadData.permalink || "",
124
- };
125
- } else {
126
- return data.id;
127
- }
128
- } catch (error) {
129
- // Access error message safely
130
- const errorMessage =
131
- error instanceof Error ? error.message : "Unknown Error";
132
- throw new Error(`Failed to create Threads container: ${errorMessage}`);
133
- }
134
- }
135
-
136
- /**
137
- * Validates the ThreadsPostRequest object to ensure correct usage of media-specific properties.
138
- *
139
- * @param request - The ThreadsPostRequest object to validate
140
- * @throws Will throw an error if the request contains invalid combinations of media type and properties
141
- *
142
- * @example
143
- * ```typescript
144
- * const request: ThreadsPostRequest = {
145
- * userId: "123456",
146
- * accessToken: "your_access_token",
147
- * mediaType: "IMAGE",
148
- * imageUrl: "https://example.com/image.jpg"
149
- * };
150
- * validateRequest(request); // This will not throw an error
151
- *
152
- * const invalidRequest: ThreadsPostRequest = {
153
- * userId: "123456",
154
- * accessToken: "your_access_token",
155
- * mediaType: "TEXT",
156
- * imageUrl: "https://example.com/image.jpg"
157
- * };
158
- * validateRequest(invalidRequest); // This will throw an error
159
- * ```
160
- */
161
- function validateRequest(request: ThreadsPostRequest): void {
162
- if (request.mediaType !== "IMAGE" && request.imageUrl) {
163
- throw new Error("imageUrl can only be used with IMAGE media type");
164
- }
165
- if (request.mediaType !== "VIDEO" && request.videoUrl) {
166
- throw new Error("videoUrl can only be used with VIDEO media type");
167
- }
168
- if (request.mediaType !== "TEXT" && request.linkAttachment) {
169
- throw new Error("linkAttachment can only be used with TEXT media type");
170
- }
171
- if (request.mediaType !== "CAROUSEL" && request.children) {
172
- throw new Error("children can only be used with CAROUSEL media type");
173
- }
174
- if (
175
- request.mediaType === "CAROUSEL" &&
176
- (!request.children || request.children.length < 2)
177
- ) {
178
- throw new Error("CAROUSEL media type requires at least 2 children");
179
- }
180
- }
181
-
182
- /**
183
- * Creates a video item container for Threads.
184
- *
185
- * @param request - The ThreadsPostRequest object containing video post details
186
- * @returns A Promise that resolves to the video item container ID
187
- * @throws Will throw an error if the API request fails
188
- */
189
- async function createVideoItemContainer(
190
- request: ThreadsPostRequest
191
- ): Promise<string> {
192
- const url = `${THREADS_API_BASE_URL}/${request.userId}/threads`;
193
- const body = new URLSearchParams({
194
- access_token: request.accessToken,
195
- is_carousel_item: "true",
196
- media_type: "VIDEO",
197
- video_url: request.videoUrl!,
198
- ...(request.altText && { alt_text: request.altText }),
199
- });
200
-
201
- const response = await fetch(url, {
202
- method: "POST",
203
- body: body,
204
- headers: {
205
- "Content-Type": "application/x-www-form-urlencoded",
206
- },
207
- });
208
-
209
- const responseText = await response.text();
210
-
211
- if (!response.ok) {
212
- throw new Error(
213
- `Failed to create video item container: ${response.statusText}. Details: ${responseText}`
214
- );
215
- }
216
-
217
- try {
218
- const data = JSON.parse(responseText);
219
- return data.id;
220
- } catch (error) {
221
- console.error(`Failed to parse response JSON: ${error}`);
222
- throw new Error(`Invalid response from Threads API: ${responseText}`);
223
- }
224
- }
225
-
226
- /**
227
- * Creates a carousel item for a Threads carousel post.
228
- *
229
- * This function sends a request to the Threads API to create a single item
230
- * that will be part of a carousel post. It can be used for both image and
231
- * video items.
232
- *
233
- * @param request - The request object containing carousel item details
234
- * @param request.userId - The user ID of the Threads account
235
- * @param request.accessToken - The access token for authentication
236
- * @param request.mediaType - The type of media for this carousel item ('IMAGE' or 'VIDEO')
237
- * @param request.imageUrl - The URL of the image (required if mediaType is 'IMAGE')
238
- * @param request.videoUrl - The URL of the video (required if mediaType is 'VIDEO')
239
- * @param request.altText - Optional accessibility text for the image or video
240
- * @returns A Promise that resolves to the carousel item ID
241
- * @throws Will throw an error if the API request fails or returns an invalid response
242
- *
243
- * @example
244
- * ```typescript
245
- * const itemRequest = {
246
- * userId: "123456",
247
- * accessToken: "your_access_token",
248
- * mediaType: "IMAGE" as const,
249
- * imageUrl: "https://example.com/image.jpg",
250
- * altText: "A beautiful landscape"
251
- * };
252
- * const itemId = await createCarouselItem(itemRequest);
253
- * ```
4
+ * Denim - A Deno/TypeScript library for the Threads API.
5
+ * Provides complete coverage of all Threads API endpoints including
6
+ * posting, retrieval, replies, insights, search, locations, and more.
254
7
  */
255
- export async function createCarouselItem(
256
- request: Omit<ThreadsPostRequest, "mediaType"> & {
257
- mediaType: "IMAGE" | "VIDEO";
258
- }
259
- ): Promise<string | { id: string }> {
260
- const api = getAPI();
261
- if (api) {
262
- // Use mock API
263
- return api.createCarouselItem(request);
264
- }
265
- if (request.mediaType !== "IMAGE" && request.mediaType !== "VIDEO") {
266
- throw new Error("Carousel items must be either IMAGE or VIDEO type");
267
- }
268
-
269
- if (request.mediaType === "IMAGE" && !request.imageUrl) {
270
- throw new Error("imageUrl is required for IMAGE type carousel items");
271
- }
272
-
273
- if (request.mediaType === "VIDEO" && !request.videoUrl) {
274
- throw new Error("videoUrl is required for VIDEO type carousel items");
275
- }
276
8
 
277
- const url = `${THREADS_API_BASE_URL}/${request.userId}/threads`;
278
- const body = new URLSearchParams({
279
- access_token: request.accessToken,
280
- media_type: request.mediaType,
281
- is_carousel_item: "true",
282
- ...(request.imageUrl && { image_url: request.imageUrl }),
283
- ...(request.videoUrl && { video_url: request.videoUrl }),
284
- ...(request.altText && { alt_text: request.altText }),
285
- });
286
-
287
- const response = await fetch(url, {
288
- method: "POST",
289
- body: body,
290
- headers: {
291
- "Content-Type": "application/x-www-form-urlencoded",
292
- },
293
- });
294
-
295
- const responseText = await response.text();
296
-
297
- if (!response.ok) {
298
- throw new Error(
299
- `Failed to create carousel item: ${response.statusText}. Details: ${responseText}`
300
- );
301
- }
302
-
303
- try {
304
- const data = JSON.parse(responseText);
305
- return data.id;
306
- } catch (error) {
307
- console.error(`Failed to parse response JSON: ${error}`);
308
- throw new Error(`Invalid response from Threads API: ${responseText}`);
309
- }
310
- }
311
-
312
- /**
313
- * Checks the status of a Threads container.
314
- *
315
- * @param containerId - The ID of the container to check
316
- * @param accessToken - The access token for authentication
317
- * @returns A Promise that resolves to the container status
318
- * @throws Will throw an error if the API request fails
319
- */
320
- async function checkContainerStatus(
321
- containerId: string,
322
- accessToken: string
323
- ): Promise<string> {
324
- const url = `${THREADS_API_BASE_URL}/${containerId}?fields=status,error_message&access_token=${accessToken}`;
325
-
326
- const response = await fetch(url);
327
- if (!response.ok) {
328
- throw new Error(`Failed to check container status: ${response.statusText}`);
329
- }
330
-
331
- const data = await response.json();
332
- return data.status;
333
- }
334
-
335
- /**
336
- * Publishes a Threads media container.
337
- *
338
- * @param userId - The user ID of the Threads account
339
- * @param accessToken - The access token for authentication
340
- * @param containerId - The ID of the container to publish
341
- * @returns A Promise that resolves to the published container ID
342
- * @throws Will throw an error if the API request fails or if publishing times out
343
- *
344
- * @example
345
- * ```typescript
346
- * const publishedId = await publishThreadsContainer("123456", "your_access_token", "container_id");
347
- * ```
348
- */
349
- export async function publishThreadsContainer(
350
- userId: string,
351
- accessToken: string,
352
- containerId: string,
353
- getPermalink: boolean = false
354
- ): Promise<string | { id: string; permalink: string }> {
355
- const api = getAPI();
356
- if (api) {
357
- // Use mock API
358
- return api.publishThreadsContainer(
359
- userId,
360
- accessToken,
361
- containerId,
362
- getPermalink
363
- );
364
- }
365
- try {
366
- const publishUrl = `${THREADS_API_BASE_URL}/${userId}/threads_publish`;
367
- const publishBody = new URLSearchParams({
368
- access_token: accessToken,
369
- creation_id: containerId,
370
- });
371
-
372
- const publishResponse = await fetch(publishUrl, {
373
- method: "POST",
374
- body: publishBody,
375
- headers: {
376
- "Content-Type": "application/x-www-form-urlencoded",
377
- },
378
- });
379
-
380
- if (!publishResponse.ok) {
381
- throw new Error(
382
- `Failed to publish Threads container: ${publishResponse.statusText}`
383
- );
384
- }
385
-
386
- const publishData = await publishResponse.json();
387
-
388
- if (getPermalink) {
389
- const mediaId = publishData.id;
390
- const permalinkUrl = `${THREADS_API_BASE_URL}/${mediaId}?fields=permalink&access_token=${accessToken}`;
391
- const permalinkResponse = await fetch(permalinkUrl);
392
-
393
- if (permalinkResponse.ok) {
394
- const permalinkData = await permalinkResponse.json();
395
- return {
396
- id: mediaId,
397
- permalink: permalinkData.permalink,
398
- };
399
- } else {
400
- throw new Error("Failed to fetch permalink");
401
- }
402
- }
403
-
404
- // Check container status
405
- let status = await checkContainerStatus(containerId, accessToken);
406
- let attempts = 0;
407
- const maxAttempts = 5;
408
-
409
- while (
410
- status !== "PUBLISHED" &&
411
- status !== "FINISHED" &&
412
- attempts < maxAttempts
413
- ) {
414
- await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second
415
- status = await checkContainerStatus(containerId, accessToken);
416
- attempts++;
417
- }
418
-
419
- if (status === "ERROR") {
420
- throw new Error(`Failed to publish container. Error: ${status}`);
421
- }
422
-
423
- if (status !== "PUBLISHED" && status !== "FINISHED") {
424
- throw new Error(
425
- `Container not published after ${maxAttempts} attempts. Current status: ${status}`
426
- );
427
- }
428
-
429
- return publishData.id;
430
- } catch (error) {
431
- if (error instanceof Error) {
432
- throw new Error(`Failed to publish Threads container: ${error.message}`);
433
- }
434
- throw error;
435
- }
436
- }
437
- /**
438
- * Serves HTTP requests to create and publish Threads posts.
439
- *
440
- * This function sets up a server that listens for POST requests
441
- * containing ThreadsPostRequest data. It creates a container and
442
- * immediately publishes it.
443
- *
444
- * @throws Will throw an error if the request is invalid or if there's an error during processing
445
- *
446
- * @example
447
- * ```typescript
448
- * // Start the server
449
- * serveRequests();
450
- * ```
451
- */
452
- export function serveRequests() {
453
- const api = getAPI();
454
-
455
- Deno.serve(async (req) => {
456
- if (req.method !== "POST") {
457
- return new Response("Method Not Allowed", { status: 405 });
458
- }
459
-
460
- try {
461
- const requestData: ThreadsPostRequest = await req.json();
462
- console.log(`Received request data: ${JSON.stringify(requestData)}`);
463
-
464
- if (
465
- !requestData.userId ||
466
- !requestData.accessToken ||
467
- !requestData.mediaType
468
- ) {
469
- return new Response(
470
- JSON.stringify({ success: false, error: "Missing required fields" }),
471
- {
472
- status: 400,
473
- headers: { "Content-Type": "application/json" },
474
- }
475
- );
476
- }
477
-
478
- let containerResult;
479
- let publishResult;
480
-
481
- if (api) {
482
- // Use mock API
483
- containerResult = await api.createThreadsContainer(requestData);
484
- publishResult = await api.publishThreadsContainer(
485
- requestData.userId,
486
- requestData.accessToken,
487
- typeof containerResult === "string"
488
- ? containerResult
489
- : containerResult.id,
490
- requestData.getPermalink
491
- );
492
- } else {
493
- // Use real API calls
494
- containerResult = await createThreadsContainer(requestData);
495
- if (typeof containerResult === "string") {
496
- publishResult = await publishThreadsContainer(
497
- requestData.userId,
498
- requestData.accessToken,
499
- containerResult,
500
- requestData.getPermalink
501
- );
502
- } else {
503
- publishResult = containerResult;
504
- }
505
- }
506
-
507
- let responseData;
508
- if (typeof publishResult === "string") {
509
- responseData = { success: true, publishedId: publishResult };
510
- } else {
511
- responseData = {
512
- success: true,
513
- publishedId: publishResult.id,
514
- permalink: publishResult.permalink,
515
- };
516
- }
517
-
518
- return new Response(JSON.stringify(responseData), {
519
- headers: { "Content-Type": "application/json" },
520
- });
521
- } catch (error) {
522
- console.error("Error posting to Threads:", error);
523
- return new Response(
524
- JSON.stringify({
525
- success: false,
526
- error: error.message,
527
- stack: error.stack,
528
- }),
529
- {
530
- status: 500,
531
- headers: { "Content-Type": "application/json" },
532
- }
533
- );
534
- }
535
- });
536
- }
537
-
538
- /**
539
- * Retrieves the current publishing rate limit usage for a user.
540
- *
541
- * @param userId - The user ID of the Threads account
542
- * @param accessToken - The access token for authentication
543
- * @returns A Promise that resolves to the rate limit usage information
544
- * @throws Will throw an error if the API request fails
545
- * @example
546
- * ```typescript
547
- * const rateLimit = await getPublishingLimit("123456", "your_access_token");
548
- * console.log(`Current usage: ${rateLimit.quota_usage}`);
549
- * ```
550
- */
551
- export async function getPublishingLimit(
552
- userId: string,
553
- accessToken: string
554
- ): Promise<PublishingLimit> {
555
- const api = getAPI();
556
- if (api) {
557
- // Use mock API
558
- return api.getPublishingLimit(userId, accessToken);
559
- }
560
- const url = `${THREADS_API_BASE_URL}/${userId}/threads_publishing_limit`;
561
- const params = new URLSearchParams({
562
- access_token: accessToken,
563
- fields: "quota_usage,config",
564
- });
565
-
566
- const response = await fetch(`${url}?${params}`);
567
- if (!response.ok) {
568
- throw new Error(`Failed to get publishing limit: ${response.statusText}`);
569
- }
570
-
571
- const data = await response.json();
572
- return data.data[0];
573
- }
574
-
575
- /**
576
- * Retrieves a list of all threads created by a user.
577
- *
578
- * @param userId - The user ID of the Threads account
579
- * @param accessToken - The access token for authentication
580
- * @param options - Optional parameters for the request
581
- * @param options.since - Start date for fetching threads (ISO 8601 format)
582
- * @param options.until - End date for fetching threads (ISO 8601 format)
583
- * @param options.limit - Maximum number of threads to return
584
- * @param options.after - Cursor for pagination (next page)
585
- * @param options.before - Cursor for pagination (previous page)
586
- * @returns A Promise that resolves to the ThreadsListResponse
587
- * @throws Will throw an error if the API request fails
588
- */
589
- export async function getThreadsList(
590
- userId: string,
591
- accessToken: string,
592
- options?: {
593
- since?: string;
594
- until?: string;
595
- limit?: number;
596
- after?: string;
597
- before?: string;
598
- }
599
- ): Promise<ThreadsListResponse> {
600
- const api = getAPI();
601
- if (api) {
602
- // Use mock API
603
- return api.getThreadsList(userId, accessToken, options);
604
- }
605
- const fields =
606
- "id,media_product_type,media_type,media_url,permalink,owner,username,text,timestamp,shortcode,thumbnail_url,children,is_quote_post";
607
- const url = new URL(`${THREADS_API_BASE_URL}/${userId}/threads`);
608
- url.searchParams.append("fields", fields);
609
- url.searchParams.append("access_token", accessToken);
610
-
611
- if (options) {
612
- if (options.since) url.searchParams.append("since", options.since);
613
- if (options.until) url.searchParams.append("until", options.until);
614
- if (options.limit)
615
- url.searchParams.append("limit", options.limit.toString());
616
- if (options.after) url.searchParams.append("after", options.after);
617
- if (options.before) url.searchParams.append("before", options.before);
618
- }
619
-
620
- const response = await fetch(url.toString());
621
- if (!response.ok) {
622
- throw new Error(`Failed to retrieve threads list: ${response.statusText}`);
623
- }
624
-
625
- return await response.json();
626
- }
627
-
628
- /**
629
- * Retrieves a single Threads media object.
630
- *
631
- * @param mediaId - The ID of the Threads media object
632
- * @param accessToken - The access token for authentication
633
- * @returns A Promise that resolves to the ThreadsPost object
634
- * @throws Will throw an error if the API request fails
635
- */
636
- export async function getSingleThread(
637
- mediaId: string,
638
- accessToken: string
639
- ): Promise<ThreadsPost> {
640
- const api = getAPI();
641
- if (api) {
642
- // Use mock API
643
- return api.getSingleThread(mediaId, accessToken);
644
- }
645
- const fields =
646
- "id,media_product_type,media_type,media_url,permalink,owner,username,text,timestamp,shortcode,thumbnail_url,children,is_quote_post";
647
- const url = new URL(`${THREADS_API_BASE_URL}/${mediaId}`);
648
- url.searchParams.append("fields", fields);
649
- url.searchParams.append("access_token", accessToken);
9
+ // ─── Types ───────────────────────────────────────────────────────────────────
10
+ import type {
11
+ AuthCodeResponse,
12
+ CursorPaginationOptions,
13
+ DebugTokenInfo,
14
+ GifAttachment,
15
+ InsightValue,
16
+ KeywordSearchOptions,
17
+ LocationSearchOptions,
18
+ MediaInsight,
19
+ MediaInsightsResponse,
20
+ MediaType,
21
+ MockThreadsAPI,
22
+ OEmbedResponse,
23
+ PaginationOptions,
24
+ PollAttachment,
25
+ PollAttachmentInput,
26
+ PublicProfile,
27
+ PublishingLimit,
28
+ QuotaConfig,
29
+ ReplyControl,
30
+ ResponseMediaType,
31
+ TextAttachment,
32
+ TextAttachmentInput,
33
+ TextEntity,
34
+ ThreadsContainer,
35
+ ThreadsListResponse,
36
+ ThreadsLocation,
37
+ ThreadsPost,
38
+ ThreadsPostRequest,
39
+ ThreadsProfile,
40
+ TokenResponse,
41
+ UserInsight,
42
+ UserInsightsOptions,
43
+ UserInsightsResponse,
44
+ WebhookDeleteValue,
45
+ WebhookMentionValue,
46
+ WebhookPayload,
47
+ WebhookPublishValue,
48
+ WebhookReplyValue,
49
+ } from "./src/types.ts";
650
50
 
651
- const response = await fetch(url.toString());
652
- if (!response.ok) {
653
- throw new Error(`Failed to retrieve thread: ${response.statusText}`);
654
- }
51
+ export type {
52
+ AuthCodeResponse,
53
+ CursorPaginationOptions,
54
+ DebugTokenInfo,
55
+ GifAttachment,
56
+ InsightValue,
57
+ KeywordSearchOptions,
58
+ LocationSearchOptions,
59
+ MediaInsight,
60
+ MediaInsightsResponse,
61
+ MediaType,
62
+ MockThreadsAPI,
63
+ OEmbedResponse,
64
+ PaginationOptions,
65
+ PollAttachment,
66
+ PollAttachmentInput,
67
+ PublicProfile,
68
+ PublishingLimit,
69
+ QuotaConfig,
70
+ ReplyControl,
71
+ ResponseMediaType,
72
+ TextAttachment,
73
+ TextAttachmentInput,
74
+ TextEntity,
75
+ ThreadsContainer,
76
+ ThreadsListResponse,
77
+ ThreadsLocation,
78
+ ThreadsPost,
79
+ ThreadsPostRequest,
80
+ ThreadsProfile,
81
+ TokenResponse,
82
+ UserInsight,
83
+ UserInsightsOptions,
84
+ UserInsightsResponse,
85
+ WebhookDeleteValue,
86
+ WebhookMentionValue,
87
+ WebhookPayload,
88
+ WebhookPublishValue,
89
+ WebhookReplyValue,
90
+ };
655
91
 
656
- return await response.json();
657
- }
92
+ // ─── Publishing ──────────────────────────────────────────────────────────────
93
+ export { createCarouselItem } from "./src/api/createCarouselItem.ts";
94
+ export { createThreadsContainer } from "./src/api/createThreadsContainer.ts";
95
+ export { deleteThread } from "./src/api/deleteThread.ts";
96
+ export { publishThreadsContainer } from "./src/api/publishThreadsContainer.ts";
97
+ export { repost } from "./src/api/repost.ts";
98
+
99
+ // ─── Retrieval ───────────────────────────────────────────────────────────────
100
+ export { getGhostPosts } from "./src/api/getGhostPosts.ts";
101
+ export { getSingleThread } from "./src/api/getSingleThread.ts";
102
+ export { getThreadsList } from "./src/api/getThreadsList.ts";
103
+
104
+ // ─── Profiles ────────────────────────────────────────────────────────────────
105
+ export { getProfile } from "./src/api/getProfile.ts";
106
+ export { getProfilePosts } from "./src/api/getProfilePosts.ts";
107
+ export { lookupProfile } from "./src/api/lookupProfile.ts";
108
+
109
+ // ─── Replies ─────────────────────────────────────────────────────────────────
110
+ export { getConversation } from "./src/api/getConversation.ts";
111
+ export { getReplies } from "./src/api/getReplies.ts";
112
+ export { getUserReplies } from "./src/api/getUserReplies.ts";
113
+ export { manageReply } from "./src/api/manageReply.ts";
114
+
115
+ // ─── Mentions ────────────────────────────────────────────────────────────────
116
+ export { getMentions } from "./src/api/getMentions.ts";
117
+
118
+ // ─── Insights ────────────────────────────────────────────────────────────────
119
+ export { getMediaInsights } from "./src/api/getMediaInsights.ts";
120
+ export { getUserInsights } from "./src/api/getUserInsights.ts";
121
+
122
+ // ─── Search ──────────────────────────────────────────────────────────────────
123
+ export { getLocation } from "./src/api/getLocation.ts";
124
+ export { searchKeyword } from "./src/api/searchKeyword.ts";
125
+ export { searchLocations } from "./src/api/searchLocations.ts";
126
+
127
+ // ─── Tokens ──────────────────────────────────────────────────────────────────
128
+ export { debugToken } from "./src/api/debugToken.ts";
129
+ export { exchangeCodeForToken } from "./src/api/exchangeCodeForToken.ts";
130
+ export { exchangeToken } from "./src/api/exchangeToken.ts";
131
+ export { getAppAccessToken } from "./src/api/getAppAccessToken.ts";
132
+ export { refreshToken } from "./src/api/refreshToken.ts";
133
+
134
+ // ─── oEmbed ──────────────────────────────────────────────────────────────────
135
+ export { getOEmbed } from "./src/api/getOEmbed.ts";
136
+
137
+ // ─── Rate Limits ─────────────────────────────────────────────────────────────
138
+ export { getPublishingLimit } from "./src/api/getPublishingLimit.ts";
139
+
140
+ // ─── Utilities ───────────────────────────────────────────────────────────────
141
+ export { checkContainerStatus } from "./src/utils/checkContainerStatus.ts";
142
+ export { validateRequest } from "./src/utils/validateRequest.ts";
143
+
144
+ // ─── Testing ─────────────────────────────────────────────────────────────────
145
+ export { MockThreadsAPIImpl } from "./src/utils/mock_threads_api.ts";