@olastudio/social-media-sdk 0.1.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 (76) hide show
  1. package/README.md +112 -0
  2. package/dist/adapters/expo.d.mts +19 -0
  3. package/dist/adapters/expo.d.ts +19 -0
  4. package/dist/adapters/expo.js +100 -0
  5. package/dist/adapters/expo.js.map +1 -0
  6. package/dist/adapters/expo.mjs +77 -0
  7. package/dist/adapters/expo.mjs.map +1 -0
  8. package/dist/adapters/index.d.mts +21 -0
  9. package/dist/adapters/index.d.ts +21 -0
  10. package/dist/adapters/index.js +6 -0
  11. package/dist/adapters/index.js.map +1 -0
  12. package/dist/adapters/index.mjs +3 -0
  13. package/dist/adapters/index.mjs.map +1 -0
  14. package/dist/auth.types-DTXCyA56.d.mts +128 -0
  15. package/dist/auth.types-DTXCyA56.d.ts +128 -0
  16. package/dist/chunk-36RADUUO.mjs +31 -0
  17. package/dist/chunk-36RADUUO.mjs.map +1 -0
  18. package/dist/chunk-7QAMNVQU.js +666 -0
  19. package/dist/chunk-7QAMNVQU.js.map +1 -0
  20. package/dist/chunk-B6NUTR54.js +4 -0
  21. package/dist/chunk-B6NUTR54.js.map +1 -0
  22. package/dist/chunk-BX3RO5PW.js +4 -0
  23. package/dist/chunk-BX3RO5PW.js.map +1 -0
  24. package/dist/chunk-CGNGZNVG.mjs +391 -0
  25. package/dist/chunk-CGNGZNVG.mjs.map +1 -0
  26. package/dist/chunk-ER5A6TIL.js +296 -0
  27. package/dist/chunk-ER5A6TIL.js.map +1 -0
  28. package/dist/chunk-GF3OEIKI.mjs +3 -0
  29. package/dist/chunk-GF3OEIKI.mjs.map +1 -0
  30. package/dist/chunk-H5GAC4UG.mjs +277 -0
  31. package/dist/chunk-H5GAC4UG.mjs.map +1 -0
  32. package/dist/chunk-HPLIHYLQ.js +35 -0
  33. package/dist/chunk-HPLIHYLQ.js.map +1 -0
  34. package/dist/chunk-MV6HJQQO.mjs +3 -0
  35. package/dist/chunk-MV6HJQQO.mjs.map +1 -0
  36. package/dist/chunk-ONR2OJOB.mjs +848 -0
  37. package/dist/chunk-ONR2OJOB.mjs.map +1 -0
  38. package/dist/chunk-PJ4KYVHH.js +854 -0
  39. package/dist/chunk-PJ4KYVHH.js.map +1 -0
  40. package/dist/chunk-QRGJXASL.js +402 -0
  41. package/dist/chunk-QRGJXASL.js.map +1 -0
  42. package/dist/chunk-QZHJXRRW.mjs +661 -0
  43. package/dist/chunk-QZHJXRRW.mjs.map +1 -0
  44. package/dist/core/index.d.mts +105 -0
  45. package/dist/core/index.d.ts +105 -0
  46. package/dist/core/index.js +94 -0
  47. package/dist/core/index.js.map +1 -0
  48. package/dist/core/index.mjs +5 -0
  49. package/dist/core/index.mjs.map +1 -0
  50. package/dist/index.d.mts +7 -0
  51. package/dist/index.d.ts +7 -0
  52. package/dist/index.js +174 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/index.mjs +9 -0
  55. package/dist/index.mjs.map +1 -0
  56. package/dist/insights.types-5z7HJnbt.d.mts +351 -0
  57. package/dist/insights.types-DF2_r0L1.d.ts +351 -0
  58. package/dist/providers/facebook/index.d.mts +464 -0
  59. package/dist/providers/facebook/index.d.ts +464 -0
  60. package/dist/providers/facebook/index.js +30 -0
  61. package/dist/providers/facebook/index.js.map +1 -0
  62. package/dist/providers/facebook/index.mjs +5 -0
  63. package/dist/providers/facebook/index.mjs.map +1 -0
  64. package/dist/providers/instagram/index.d.mts +355 -0
  65. package/dist/providers/instagram/index.d.ts +355 -0
  66. package/dist/providers/instagram/index.js +26 -0
  67. package/dist/providers/instagram/index.js.map +1 -0
  68. package/dist/providers/instagram/index.mjs +5 -0
  69. package/dist/providers/instagram/index.mjs.map +1 -0
  70. package/dist/providers/tiktok/index.d.mts +346 -0
  71. package/dist/providers/tiktok/index.d.ts +346 -0
  72. package/dist/providers/tiktok/index.js +48 -0
  73. package/dist/providers/tiktok/index.js.map +1 -0
  74. package/dist/providers/tiktok/index.mjs +3 -0
  75. package/dist/providers/tiktok/index.mjs.map +1 -0
  76. package/package.json +97 -0
@@ -0,0 +1,854 @@
1
+ 'use strict';
2
+
3
+ var chunkER5A6TIL_js = require('./chunk-ER5A6TIL.js');
4
+ var chunkHPLIHYLQ_js = require('./chunk-HPLIHYLQ.js');
5
+
6
+ // providers/facebook/api/FacebookAPI.ts
7
+ var FacebookAPI = class {
8
+ constructor(config, accessToken) {
9
+ this.config = config;
10
+ this.accessToken = accessToken;
11
+ this.httpClient = new chunkER5A6TIL_js.HttpClient({
12
+ baseURL: chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL,
13
+ accessToken: this.accessToken
14
+ });
15
+ }
16
+ /**
17
+ * Generic request
18
+ */
19
+ async request(endpoint, options = {}) {
20
+ if (this.accessToken && !options.params?.access_token) {
21
+ options.params = {
22
+ ...options.params,
23
+ access_token: this.accessToken
24
+ };
25
+ }
26
+ return this.httpClient.request(endpoint, options);
27
+ }
28
+ /**
29
+ * GET request
30
+ */
31
+ async get(endpoint, params) {
32
+ return this.request(endpoint, { method: "GET", params });
33
+ }
34
+ /**
35
+ * POST request
36
+ */
37
+ async post(endpoint, body) {
38
+ return this.request(endpoint, { method: "POST", body });
39
+ }
40
+ /**
41
+ * PUT request
42
+ */
43
+ async put(endpoint, body) {
44
+ return this.request(endpoint, { method: "PUT", body });
45
+ }
46
+ /**
47
+ * DELETE request
48
+ */
49
+ async delete(endpoint) {
50
+ return this.request(endpoint, { method: "DELETE" });
51
+ }
52
+ /**
53
+ * Update access token
54
+ */
55
+ setAccessToken(token) {
56
+ this.accessToken = token;
57
+ this.httpClient.setAccessToken(token);
58
+ }
59
+ /**
60
+ * Get current access token
61
+ */
62
+ getAccessToken() {
63
+ return this.accessToken;
64
+ }
65
+ // ============= Facebook-specific methods =============
66
+ /**
67
+ * Get user's pages
68
+ */
69
+ async getPages(userAccessToken) {
70
+ try {
71
+ const token = userAccessToken || this.accessToken;
72
+ if (!token) {
73
+ throw new chunkHPLIHYLQ_js.APIError("Access token is required", 401, "NO_TOKEN");
74
+ }
75
+ const response = await this.get("/me/accounts", {
76
+ fields: "id,name,access_token,picture",
77
+ access_token: token
78
+ });
79
+ return response.data;
80
+ } catch (error) {
81
+ throw new chunkHPLIHYLQ_js.APIError(
82
+ `Failed to fetch Facebook pages: ${error instanceof Error ? error.message : "Unknown error"}`,
83
+ void 0,
84
+ "PAGES_FETCH_ERROR",
85
+ error
86
+ );
87
+ }
88
+ }
89
+ /**
90
+ * Publish post to Facebook page
91
+ */
92
+ async publishPost(params) {
93
+ const { pageId, pageAccessToken, message, imageUrl, scheduledPublishTime } = params;
94
+ try {
95
+ let endpoint = `/${pageId}/`;
96
+ const body = {
97
+ access_token: pageAccessToken
98
+ };
99
+ if (scheduledPublishTime) {
100
+ body.published = false;
101
+ body.scheduled_publish_time = scheduledPublishTime;
102
+ }
103
+ if (imageUrl) {
104
+ endpoint += "photos";
105
+ body.url = imageUrl;
106
+ if (message) body.caption = message;
107
+ } else if (message) {
108
+ endpoint += "feed";
109
+ body.message = message;
110
+ } else {
111
+ throw new chunkHPLIHYLQ_js.APIError(
112
+ "Either message or imageUrl must be provided",
113
+ 400,
114
+ "INVALID_PARAMS"
115
+ );
116
+ }
117
+ const response = await this.request(endpoint, {
118
+ method: "POST",
119
+ headers: {
120
+ "Content-Type": "application/x-www-form-urlencoded"
121
+ },
122
+ body
123
+ });
124
+ return response;
125
+ } catch (error) {
126
+ throw new chunkHPLIHYLQ_js.APIError(
127
+ `Failed to publish post: ${error instanceof Error ? error.message : "Unknown error"}`,
128
+ void 0,
129
+ "POST_PUBLISH_ERROR",
130
+ error
131
+ );
132
+ }
133
+ }
134
+ /**
135
+ * Delete Facebook post
136
+ */
137
+ async deletePost(postId, pageAccessToken) {
138
+ try {
139
+ const response = await this.delete(
140
+ `/${postId}?access_token=${pageAccessToken}`
141
+ );
142
+ return response.success === true;
143
+ } catch (error) {
144
+ throw new chunkHPLIHYLQ_js.APIError(
145
+ `Failed to delete post: ${error instanceof Error ? error.message : "Unknown error"}`,
146
+ void 0,
147
+ "POST_DELETE_ERROR",
148
+ error
149
+ );
150
+ }
151
+ }
152
+ /**
153
+ * Get page information
154
+ */
155
+ async getPage(pageId, fields) {
156
+ try {
157
+ const fieldsParam = fields?.join(",") || "id,name,access_token,picture";
158
+ return await this.get(`/${pageId}`, {
159
+ fields: fieldsParam
160
+ });
161
+ } catch (error) {
162
+ throw new chunkHPLIHYLQ_js.APIError(
163
+ `Failed to fetch page info: ${error instanceof Error ? error.message : "Unknown error"}`,
164
+ void 0,
165
+ "PAGE_FETCH_ERROR",
166
+ error
167
+ );
168
+ }
169
+ }
170
+ /**
171
+ * Debug/validate a Facebook access token
172
+ * Uses Facebook's debug_token endpoint
173
+ *
174
+ * @param inputToken - The token to validate
175
+ * @param appAccessToken - App token (app_id|app_secret)
176
+ * @returns Token debug information
177
+ */
178
+ async debugToken(inputToken, appAccessToken) {
179
+ try {
180
+ return await this.get("/debug_token", {
181
+ input_token: inputToken,
182
+ access_token: appAccessToken
183
+ });
184
+ } catch (error) {
185
+ throw new chunkHPLIHYLQ_js.APIError(
186
+ `Failed to debug token: ${error instanceof Error ? error.message : "Unknown error"}`,
187
+ void 0,
188
+ "TOKEN_DEBUG_ERROR",
189
+ error
190
+ );
191
+ }
192
+ }
193
+ /**
194
+ * Get page insights/analytics
195
+ * @param pageId - Facebook Page ID
196
+ * @param options - Insights options
197
+ * @returns Page insights data
198
+ */
199
+ async getPageInsights(pageId, options) {
200
+ try {
201
+ const params = {
202
+ metric: options.metric.join(","),
203
+ period: options.period || "day"
204
+ };
205
+ if (options.since) params.since = options.since;
206
+ if (options.until) params.until = options.until;
207
+ const response = await this.get(`/${pageId}/insights`, params);
208
+ return response;
209
+ } catch (error) {
210
+ throw new chunkHPLIHYLQ_js.APIError(
211
+ `Failed to fetch page insights: ${error instanceof Error ? error.message : "Unknown error"}`,
212
+ void 0,
213
+ "INSIGHTS_FETCH_ERROR",
214
+ error
215
+ );
216
+ }
217
+ }
218
+ /**
219
+ * Get page fans count (total followers)
220
+ * @param pageId - Facebook Page ID
221
+ * @returns Page with fan count
222
+ */
223
+ async getPageFansCount(pageId) {
224
+ try {
225
+ return await this.get(`/${pageId}`, {
226
+ fields: "id,fan_count"
227
+ });
228
+ } catch (error) {
229
+ throw new chunkHPLIHYLQ_js.APIError(
230
+ `Failed to fetch page fans count: ${error instanceof Error ? error.message : "Unknown error"}`,
231
+ void 0,
232
+ "FANS_COUNT_ERROR",
233
+ error
234
+ );
235
+ }
236
+ }
237
+ /**
238
+ * Get page overview with key metrics
239
+ * @param pageId - Facebook Page ID
240
+ * @returns Page overview data
241
+ */
242
+ async getPageOverview(pageId) {
243
+ try {
244
+ const response = await this.get(`/${pageId}`, {
245
+ fields: "id,name,followers_count,fan_count"
246
+ });
247
+ return {
248
+ id: response.id,
249
+ name: response.name,
250
+ followers_count: response.followers_count || response.fan_count || 0,
251
+ fan_count: response.fan_count
252
+ };
253
+ } catch (error) {
254
+ throw new chunkHPLIHYLQ_js.APIError(
255
+ `Failed to fetch page overview: ${error instanceof Error ? error.message : "Unknown error"}`,
256
+ void 0,
257
+ "PAGE_OVERVIEW_ERROR",
258
+ error
259
+ );
260
+ }
261
+ }
262
+ // ============= Video Insights Methods =============
263
+ /**
264
+ * Get video insights
265
+ * @param videoId - Facebook Video ID
266
+ * @param metrics - Specific metrics to fetch (defaults to common metrics)
267
+ * @returns Video insights data
268
+ */
269
+ async getVideoInsights(videoId, metrics) {
270
+ try {
271
+ const metricsToFetch = metrics || chunkER5A6TIL_js.METRIC_PRESETS.VIDEO_PERFORMANCE;
272
+ const response = await this.get(
273
+ `/${videoId}/video_insights`,
274
+ {
275
+ metric: metricsToFetch.join(",")
276
+ }
277
+ );
278
+ return response;
279
+ } catch (error) {
280
+ throw new chunkHPLIHYLQ_js.APIError(
281
+ `Failed to fetch video insights: ${error instanceof Error ? error.message : "Unknown error"}`,
282
+ void 0,
283
+ "VIDEO_INSIGHTS_ERROR",
284
+ error
285
+ );
286
+ }
287
+ }
288
+ /**
289
+ * Get video insights with parsed values
290
+ * @param videoId - Facebook Video ID
291
+ * @returns Parsed video insights
292
+ */
293
+ async getVideoInsightsParsed(videoId) {
294
+ try {
295
+ const response = await this.getVideoInsights(videoId, [...chunkER5A6TIL_js.VIDEO_METRICS.slice(0, 8)]);
296
+ const insights = { id: videoId };
297
+ for (const item of response.data) {
298
+ const value = item.values?.[0]?.value ?? item.total_value?.value;
299
+ if (typeof value !== "number") continue;
300
+ switch (item.name) {
301
+ case "total_video_views":
302
+ insights.total_views = value;
303
+ break;
304
+ case "total_video_views_unique":
305
+ insights.unique_views = value;
306
+ break;
307
+ case "total_video_avg_time_watched":
308
+ insights.avg_time_watched = value;
309
+ break;
310
+ case "total_video_complete_views":
311
+ insights.complete_views = value;
312
+ break;
313
+ case "total_video_views_organic":
314
+ insights.organic_views = value;
315
+ break;
316
+ case "total_video_views_paid":
317
+ insights.paid_views = value;
318
+ break;
319
+ case "total_video_view_total_time":
320
+ insights.total_time_watched = value;
321
+ break;
322
+ }
323
+ }
324
+ return insights;
325
+ } catch (error) {
326
+ throw new chunkHPLIHYLQ_js.APIError(
327
+ `Failed to fetch parsed video insights: ${error instanceof Error ? error.message : "Unknown error"}`,
328
+ void 0,
329
+ "VIDEO_INSIGHTS_PARSED_ERROR",
330
+ error
331
+ );
332
+ }
333
+ }
334
+ /**
335
+ * Get page videos with basic info
336
+ * @param pageId - Facebook Page ID
337
+ * @param limit - Number of videos to fetch
338
+ * @returns List of videos
339
+ */
340
+ async getPageVideos(pageId, limit = 25) {
341
+ try {
342
+ return await this.get(`/${pageId}/videos`, {
343
+ fields: "id,title,description,created_time,length",
344
+ limit
345
+ });
346
+ } catch (error) {
347
+ throw new chunkHPLIHYLQ_js.APIError(
348
+ `Failed to fetch page videos: ${error instanceof Error ? error.message : "Unknown error"}`,
349
+ void 0,
350
+ "PAGE_VIDEOS_ERROR",
351
+ error
352
+ );
353
+ }
354
+ }
355
+ // ============= Reels Insights Methods =============
356
+ /**
357
+ * Get reels insights
358
+ * @param reelId - Facebook Reel ID
359
+ * @param metrics - Specific metrics to fetch
360
+ * @returns Reels insights data
361
+ */
362
+ async getReelsInsights(reelId, metrics) {
363
+ try {
364
+ const metricsToFetch = metrics || chunkER5A6TIL_js.METRIC_PRESETS.REELS_PERFORMANCE;
365
+ const response = await this.get(
366
+ `/${reelId}/video_insights`,
367
+ {
368
+ metric: metricsToFetch.join(",")
369
+ }
370
+ );
371
+ return response;
372
+ } catch (error) {
373
+ throw new chunkHPLIHYLQ_js.APIError(
374
+ `Failed to fetch reels insights: ${error instanceof Error ? error.message : "Unknown error"}`,
375
+ void 0,
376
+ "REELS_INSIGHTS_ERROR",
377
+ error
378
+ );
379
+ }
380
+ }
381
+ /**
382
+ * Get reels insights with parsed values
383
+ * @param reelId - Facebook Reel ID
384
+ * @returns Parsed reels insights
385
+ */
386
+ async getReelsInsightsParsed(reelId) {
387
+ try {
388
+ const response = await this.getReelsInsights(reelId, [...chunkER5A6TIL_js.REELS_METRICS]);
389
+ const insights = { id: reelId };
390
+ for (const item of response.data) {
391
+ const value = item.values?.[0]?.value ?? item.total_value?.value;
392
+ if (typeof value !== "number") continue;
393
+ switch (item.name) {
394
+ case "blue_reels_play_count":
395
+ insights.plays = value;
396
+ break;
397
+ case "post_video_avg_time_watched":
398
+ insights.avg_time_watched = value;
399
+ break;
400
+ case "post_video_views":
401
+ insights.total_plays = value;
402
+ break;
403
+ }
404
+ }
405
+ try {
406
+ const postResponse = await this.get(`/${reelId}`, {
407
+ fields: "reactions.summary(true),comments.summary(true),shares"
408
+ });
409
+ insights.likes = postResponse.reactions?.summary?.total_count;
410
+ insights.comments = postResponse.comments?.summary?.total_count;
411
+ insights.shares = postResponse.shares?.count;
412
+ } catch {
413
+ }
414
+ return insights;
415
+ } catch (error) {
416
+ throw new chunkHPLIHYLQ_js.APIError(
417
+ `Failed to fetch parsed reels insights: ${error instanceof Error ? error.message : "Unknown error"}`,
418
+ void 0,
419
+ "REELS_INSIGHTS_PARSED_ERROR",
420
+ error
421
+ );
422
+ }
423
+ }
424
+ /**
425
+ * Get page reels
426
+ * @param pageId - Facebook Page ID
427
+ * @param limit - Number of reels to fetch
428
+ * @returns List of reels
429
+ */
430
+ async getPageReels(pageId, limit = 25) {
431
+ try {
432
+ return await this.get(`/${pageId}/video_reels`, {
433
+ fields: "id,description,created_time",
434
+ limit
435
+ });
436
+ } catch (error) {
437
+ throw new chunkHPLIHYLQ_js.APIError(
438
+ `Failed to fetch page reels: ${error instanceof Error ? error.message : "Unknown error"}`,
439
+ void 0,
440
+ "PAGE_REELS_ERROR",
441
+ error
442
+ );
443
+ }
444
+ }
445
+ // ============= Post Insights Methods =============
446
+ /**
447
+ * Get post insights
448
+ * @param postId - Facebook Post ID
449
+ * @param metrics - Specific metrics to fetch
450
+ * @returns Post insights data
451
+ */
452
+ async getPostInsights(postId, metrics) {
453
+ try {
454
+ const metricsToFetch = metrics || [...chunkER5A6TIL_js.POST_METRICS];
455
+ const response = await this.get(
456
+ `/${postId}/insights`,
457
+ {
458
+ metric: metricsToFetch.join(",")
459
+ }
460
+ );
461
+ return response;
462
+ } catch (error) {
463
+ throw new chunkHPLIHYLQ_js.APIError(
464
+ `Failed to fetch post insights: ${error instanceof Error ? error.message : "Unknown error"}`,
465
+ void 0,
466
+ "POST_INSIGHTS_ERROR",
467
+ error
468
+ );
469
+ }
470
+ }
471
+ /**
472
+ * Get post insights with parsed values
473
+ * @param postId - Facebook Post ID
474
+ * @returns Parsed post insights
475
+ */
476
+ async getPostInsightsParsed(postId) {
477
+ try {
478
+ const response = await this.getPostInsights(postId);
479
+ const insights = { id: postId };
480
+ for (const item of response.data) {
481
+ const value = item.values?.[0]?.value ?? item.total_value?.value;
482
+ switch (item.name) {
483
+ case "post_engaged_users":
484
+ if (typeof value === "number") insights.engaged_users = value;
485
+ break;
486
+ case "post_clicks":
487
+ if (typeof value === "number") insights.clicks = value;
488
+ break;
489
+ case "post_negative_feedback":
490
+ if (typeof value === "number") insights.negative_feedback = value;
491
+ break;
492
+ case "post_reactions_by_type_total":
493
+ if (typeof value === "object") insights.reactions_by_type = value;
494
+ break;
495
+ }
496
+ }
497
+ return insights;
498
+ } catch (error) {
499
+ throw new chunkHPLIHYLQ_js.APIError(
500
+ `Failed to fetch parsed post insights: ${error instanceof Error ? error.message : "Unknown error"}`,
501
+ void 0,
502
+ "POST_INSIGHTS_PARSED_ERROR",
503
+ error
504
+ );
505
+ }
506
+ }
507
+ /**
508
+ * Get page posts/feed
509
+ * @param pageId - Facebook Page ID
510
+ * @param limit - Number of posts to fetch
511
+ * @returns List of posts
512
+ */
513
+ async getPagePosts(pageId, limit = 25) {
514
+ try {
515
+ return await this.get(`/${pageId}/feed`, {
516
+ fields: "id,message,created_time,type",
517
+ limit
518
+ });
519
+ } catch (error) {
520
+ throw new chunkHPLIHYLQ_js.APIError(
521
+ `Failed to fetch page posts: ${error instanceof Error ? error.message : "Unknown error"}`,
522
+ void 0,
523
+ "PAGE_POSTS_ERROR",
524
+ error
525
+ );
526
+ }
527
+ }
528
+ // ============= Photo Insights Methods =============
529
+ /**
530
+ * Get photo insights
531
+ * @param photoId - Facebook Photo ID
532
+ * @param metrics - Specific metrics to fetch
533
+ * @returns Photo insights data
534
+ */
535
+ async getPhotoInsights(photoId, metrics) {
536
+ try {
537
+ const metricsToFetch = metrics || [...chunkER5A6TIL_js.PHOTO_METRICS];
538
+ const response = await this.get(
539
+ `/${photoId}/insights`,
540
+ {
541
+ metric: metricsToFetch.join(",")
542
+ }
543
+ );
544
+ return response;
545
+ } catch (error) {
546
+ throw new chunkHPLIHYLQ_js.APIError(
547
+ `Failed to fetch photo insights: ${error instanceof Error ? error.message : "Unknown error"}`,
548
+ void 0,
549
+ "PHOTO_INSIGHTS_ERROR",
550
+ error
551
+ );
552
+ }
553
+ }
554
+ /**
555
+ * Get photo insights with parsed values
556
+ * @param photoId - Facebook Photo ID
557
+ * @returns Parsed photo insights
558
+ */
559
+ async getPhotoInsightsParsed(photoId) {
560
+ try {
561
+ const response = await this.getPhotoInsights(photoId);
562
+ const insights = { id: photoId };
563
+ for (const item of response.data) {
564
+ const value = item.values?.[0]?.value ?? item.total_value?.value;
565
+ if (typeof value !== "number") continue;
566
+ switch (item.name) {
567
+ case "photo_views":
568
+ insights.views = value;
569
+ break;
570
+ case "photo_reach":
571
+ insights.reach = value;
572
+ break;
573
+ case "engaged_users":
574
+ insights.engaged_users = value;
575
+ break;
576
+ }
577
+ }
578
+ return insights;
579
+ } catch (error) {
580
+ throw new chunkHPLIHYLQ_js.APIError(
581
+ `Failed to fetch parsed photo insights: ${error instanceof Error ? error.message : "Unknown error"}`,
582
+ void 0,
583
+ "PHOTO_INSIGHTS_PARSED_ERROR",
584
+ error
585
+ );
586
+ }
587
+ }
588
+ /**
589
+ * Get page photos
590
+ * @param pageId - Facebook Page ID
591
+ * @param limit - Number of photos to fetch
592
+ * @returns List of photos
593
+ */
594
+ async getPagePhotos(pageId, limit = 25) {
595
+ try {
596
+ return await this.get(`/${pageId}/photos`, {
597
+ fields: "id,name,created_time",
598
+ type: "uploaded",
599
+ limit
600
+ });
601
+ } catch (error) {
602
+ throw new chunkHPLIHYLQ_js.APIError(
603
+ `Failed to fetch page photos: ${error instanceof Error ? error.message : "Unknown error"}`,
604
+ void 0,
605
+ "PAGE_PHOTOS_ERROR",
606
+ error
607
+ );
608
+ }
609
+ }
610
+ // ============= Batch/Helper Methods =============
611
+ /**
612
+ * Get quick insights summary for a page
613
+ * Combines key metrics in a single call
614
+ * @param pageId - Facebook Page ID
615
+ * @param period - Period for time-based metrics
616
+ * @returns Summary of page insights
617
+ */
618
+ async getPageInsightsSummary(pageId, period = "days_28") {
619
+ try {
620
+ const overview = await this.getPageOverview(pageId);
621
+ const insightsResponse = await this.getPageInsights(pageId, {
622
+ metric: [...chunkER5A6TIL_js.METRIC_PRESETS.PAGE_OVERVIEW],
623
+ period
624
+ });
625
+ const engagement = {};
626
+ for (const item of insightsResponse.data) {
627
+ const values = item.values || [];
628
+ const total = values.reduce((sum, v) => sum + (typeof v.value === "number" ? v.value : 0), 0);
629
+ switch (item.name) {
630
+ case "page_views_total":
631
+ engagement.views = total;
632
+ break;
633
+ case "page_post_engagements":
634
+ engagement.post_engagements = total;
635
+ break;
636
+ case "page_video_views":
637
+ engagement.video_views = total;
638
+ break;
639
+ }
640
+ }
641
+ return { overview, engagement };
642
+ } catch (error) {
643
+ throw new chunkHPLIHYLQ_js.APIError(
644
+ `Failed to fetch page insights summary: ${error instanceof Error ? error.message : "Unknown error"}`,
645
+ void 0,
646
+ "PAGE_SUMMARY_ERROR",
647
+ error
648
+ );
649
+ }
650
+ }
651
+ /**
652
+ * Get current API version (read-only)
653
+ */
654
+ getApiVersion() {
655
+ return chunkER5A6TIL_js.FACEBOOK_GRAPH_API_VERSION;
656
+ }
657
+ };
658
+
659
+ // providers/facebook/auth/FacebookAuth.ts
660
+ var FacebookAuth = class {
661
+ constructor(config) {
662
+ this.config = config;
663
+ this.httpClient = new chunkER5A6TIL_js.HttpClient({
664
+ baseURL: chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL
665
+ });
666
+ }
667
+ /**
668
+ * Exchange Facebook token for session
669
+ * In Expo + Supabase, this is handled in the app
670
+ * This function only validates and gets profile info
671
+ */
672
+ async exchangeToken(facebookToken) {
673
+ try {
674
+ const profile = await this.getProfile(facebookToken);
675
+ return {
676
+ accessToken: facebookToken,
677
+ user: profile
678
+ };
679
+ } catch (error) {
680
+ throw new chunkHPLIHYLQ_js.AuthError(
681
+ `Failed to exchange Facebook token: ${error instanceof Error ? error.message : "Unknown error"}`,
682
+ "TOKEN_EXCHANGE_ERROR",
683
+ error
684
+ );
685
+ }
686
+ }
687
+ /**
688
+ * Get Facebook user profile
689
+ */
690
+ async getProfile(accessToken) {
691
+ try {
692
+ const profile = await this.httpClient.get("/me", {
693
+ fields: "id,name,email,picture",
694
+ access_token: accessToken
695
+ });
696
+ return {
697
+ id: profile.id,
698
+ name: profile.name,
699
+ email: profile.email,
700
+ picture: profile.picture?.data?.url
701
+ };
702
+ } catch (error) {
703
+ throw new chunkHPLIHYLQ_js.AuthError(
704
+ `Failed to fetch Facebook profile: ${error instanceof Error ? error.message : "Unknown error"}`,
705
+ "PROFILE_FETCH_ERROR",
706
+ error
707
+ );
708
+ }
709
+ }
710
+ /**
711
+ * Exchange short-lived token for long-lived token
712
+ */
713
+ async exchangeForLongLivedToken(params) {
714
+ try {
715
+ const response = await this.httpClient.get(
716
+ "/oauth/access_token",
717
+ {
718
+ grant_type: "fb_exchange_token",
719
+ client_id: params.appId,
720
+ client_secret: params.appSecret,
721
+ fb_exchange_token: params.shortLivedToken
722
+ }
723
+ );
724
+ return response.access_token;
725
+ } catch (error) {
726
+ throw new chunkHPLIHYLQ_js.AuthError(
727
+ `Failed to exchange for long-lived token: ${error instanceof Error ? error.message : "Unknown error"}`,
728
+ "LONG_LIVED_TOKEN_ERROR",
729
+ error
730
+ );
731
+ }
732
+ }
733
+ /**
734
+ * Get OAuth configuration for Facebook
735
+ */
736
+ getOAuthConfig(scopes, redirectUri) {
737
+ return {
738
+ authorizationEndpoint: chunkER5A6TIL_js.FACEBOOK_OAUTH_AUTHORIZATION_URL,
739
+ tokenEndpoint: `${chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL}/oauth/access_token`,
740
+ clientId: this.config.appId,
741
+ clientSecret: this.config.appSecret,
742
+ redirectUri,
743
+ scopes,
744
+ responseType: "token",
745
+ extraParams: {
746
+ display: "popup"
747
+ }
748
+ };
749
+ }
750
+ /**
751
+ * Get authorization URL
752
+ */
753
+ getAuthorizationUrl(scopes, redirectUri, state) {
754
+ const params = new URLSearchParams({
755
+ client_id: this.config.appId,
756
+ redirect_uri: redirectUri,
757
+ scope: scopes.join(","),
758
+ response_type: "token",
759
+ display: "popup",
760
+ ...state && { state }
761
+ });
762
+ return `${chunkER5A6TIL_js.FACEBOOK_OAUTH_AUTHORIZATION_URL}?${params.toString()}`;
763
+ }
764
+ /**
765
+ * Get current API version (read-only)
766
+ */
767
+ getApiVersion() {
768
+ return chunkER5A6TIL_js.FACEBOOK_GRAPH_API_VERSION;
769
+ }
770
+ };
771
+
772
+ // providers/facebook/FacebookProvider.ts
773
+ var FacebookProvider = class {
774
+ constructor(config) {
775
+ this.name = "facebook";
776
+ this.config = config;
777
+ this.auth = new FacebookAuth(config);
778
+ this.api = new FacebookAPI(config);
779
+ }
780
+ /**
781
+ * Create new API instance with access token
782
+ */
783
+ createAPIClient(accessToken) {
784
+ return new FacebookAPI(this.config, accessToken);
785
+ }
786
+ /**
787
+ * Update access token of existing API client
788
+ */
789
+ setAccessToken(accessToken) {
790
+ this.api.setAccessToken(accessToken);
791
+ }
792
+ /**
793
+ * Get current access token
794
+ */
795
+ getAccessToken() {
796
+ return this.api.getAccessToken();
797
+ }
798
+ };
799
+
800
+ // providers/facebook/types/index.ts
801
+ var FacebookScopesBusiness = /* @__PURE__ */ ((FacebookScopesBusiness2) => {
802
+ FacebookScopesBusiness2["PUBLIC_PROFILE"] = "public_profile";
803
+ FacebookScopesBusiness2["EMAIL"] = "email";
804
+ FacebookScopesBusiness2["PAGES_SHOW_LIST"] = "pages_show_list";
805
+ FacebookScopesBusiness2["PAGES_READ_ENGAGEMENT"] = "pages_read_engagement";
806
+ FacebookScopesBusiness2["PAGES_MANAGE_POSTS"] = "pages_manage_posts";
807
+ FacebookScopesBusiness2["ADS_MANAGEMENT"] = "ads_management";
808
+ FacebookScopesBusiness2["ADS_READ"] = "ads_read";
809
+ FacebookScopesBusiness2["BUSINESS_MANAGEMENT"] = "business_management";
810
+ FacebookScopesBusiness2["CATALOG_MANAGEMENT"] = "catalog_management";
811
+ FacebookScopesBusiness2["COMMERCE_ACCOUNT_MANAGE_ORDERS"] = "commerce_account_manage_orders";
812
+ FacebookScopesBusiness2["COMMERCE_ACCOUNT_READ_ORDERS"] = "commerce_account_read_orders";
813
+ FacebookScopesBusiness2["COMMERCE_ACCOUNT_READ_REPORTS"] = "commerce_account_read_reports";
814
+ FacebookScopesBusiness2["COMMERCE_ACCOUNT_READ_SETTINGS"] = "commerce_account_read_settings";
815
+ FacebookScopesBusiness2["COMMERCE_MANAGE_ACCOUNTS"] = "commerce_manage_accounts";
816
+ FacebookScopesBusiness2["INSTAGRAM_BASIC"] = "instagram_basic";
817
+ FacebookScopesBusiness2["INSTAGRAM_CONTENT_PUBLISH"] = "instagram_content_publish";
818
+ FacebookScopesBusiness2["INSTAGRAM_MANAGE_COMMENTS"] = "instagram_manage_comments";
819
+ FacebookScopesBusiness2["INSTAGRAM_MANAGE_INSIGHTS"] = "instagram_manage_insights";
820
+ FacebookScopesBusiness2["INSTAGRAM_MANAGE_MESSAGES"] = "instagram_manage_messages";
821
+ FacebookScopesBusiness2["INSTAGRAM_SHOPPING_TAG_PRODUCTS"] = "instagram_shopping_tag_products";
822
+ FacebookScopesBusiness2["LEADS_RETRIEVAL"] = "leads_retrieval";
823
+ FacebookScopesBusiness2["MANAGE_APP_SOLUTIONS"] = "manage_app_solutions";
824
+ FacebookScopesBusiness2["MANAGE_FUNDRAISERS"] = "manage_fundraisers";
825
+ FacebookScopesBusiness2["PAGES_MANAGE_CTA"] = "pages_manage_cta";
826
+ FacebookScopesBusiness2["PAGE_EVENTS"] = "page_events";
827
+ FacebookScopesBusiness2["PAGES_MANAGE_ADS"] = "pages_manage_ads";
828
+ FacebookScopesBusiness2["PAGES_MANAGE_ENGAGEMENT"] = "pages_manage_engagement";
829
+ FacebookScopesBusiness2["PAGES_MANAGE_INSTANT_ARTICLES"] = "pages_manage_instant_articles";
830
+ FacebookScopesBusiness2["PAGES_MANAGE_METADATA"] = "pages_manage_metadata";
831
+ FacebookScopesBusiness2["PAGES_MESSAGING"] = "pages_messaging";
832
+ FacebookScopesBusiness2["PAGES_READ_USER_CONTENT"] = "pages_read_user_content";
833
+ FacebookScopesBusiness2["PRIVATE_COMPUTATION_ACCESS"] = "private_computation_access";
834
+ FacebookScopesBusiness2["PUBLISH_VIDEO"] = "publish_video";
835
+ FacebookScopesBusiness2["READ_INSIGHTS"] = "read_insights";
836
+ FacebookScopesBusiness2["READ_AUDIENCE_NETWORK_INSIGHTS"] = "read_audience_network_insights";
837
+ FacebookScopesBusiness2["WHATSAPP_BUSINESS_MANAGEMENT"] = "whatsapp_business_management";
838
+ FacebookScopesBusiness2["WHATSAPP_BUSINESS_MESSAGING"] = "whatsapp_business_messaging";
839
+ return FacebookScopesBusiness2;
840
+ })(FacebookScopesBusiness || {});
841
+ var FacebookScopesUser = /* @__PURE__ */ ((FacebookScopesUser2) => {
842
+ FacebookScopesUser2["PUBLIC_PROFILE"] = "public_profile";
843
+ FacebookScopesUser2["EMAIL"] = "email";
844
+ FacebookScopesUser2["USER_FRIENDS"] = "user_friends";
845
+ return FacebookScopesUser2;
846
+ })(FacebookScopesUser || {});
847
+
848
+ exports.FacebookAPI = FacebookAPI;
849
+ exports.FacebookAuth = FacebookAuth;
850
+ exports.FacebookProvider = FacebookProvider;
851
+ exports.FacebookScopesBusiness = FacebookScopesBusiness;
852
+ exports.FacebookScopesUser = FacebookScopesUser;
853
+ //# sourceMappingURL=chunk-PJ4KYVHH.js.map
854
+ //# sourceMappingURL=chunk-PJ4KYVHH.js.map