@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,31 @@
1
+ // core/errors/BaseError.ts
2
+ var BaseError = class extends Error {
3
+ constructor(message, code, details) {
4
+ super(message);
5
+ this.name = this.constructor.name;
6
+ this.code = code;
7
+ this.details = details;
8
+ Error.captureStackTrace(this, this.constructor);
9
+ }
10
+ };
11
+
12
+ // core/errors/AuthError.ts
13
+ var AuthError = class extends BaseError {
14
+ constructor(message, code, details) {
15
+ super(message, code, details);
16
+ this.name = "AuthError";
17
+ }
18
+ };
19
+
20
+ // core/errors/APIError.ts
21
+ var APIError = class extends BaseError {
22
+ constructor(message, statusCode, code, details) {
23
+ super(message, code, details);
24
+ this.name = "APIError";
25
+ this.statusCode = statusCode;
26
+ }
27
+ };
28
+
29
+ export { APIError, AuthError, BaseError };
30
+ //# sourceMappingURL=chunk-36RADUUO.mjs.map
31
+ //# sourceMappingURL=chunk-36RADUUO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../core/errors/BaseError.ts","../core/errors/AuthError.ts","../core/errors/APIError.ts"],"names":[],"mappings":";AAIO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EAKnC,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAwB,OAAA,EAAe;AAClE,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,KAAK,WAAA,CAAY,IAAA;AAC7B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,KAAA,CAAM,iBAAA,CAAkB,IAAA,EAAM,IAAA,CAAK,WAAW,CAAA;AAAA,EAChD;AACF;;;ACVO,IAAM,SAAA,GAAN,cAAwB,SAAA,CAAU;AAAA,EACvC,WAAA,CAAY,OAAA,EAAiB,IAAA,EAAwB,OAAA,EAAe;AAClE,IAAA,KAAA,CAAM,OAAA,EAAS,MAAM,OAAO,CAAA;AAC5B,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AAAA,EACd;AACF;;;ACLO,IAAM,QAAA,GAAN,cAAuB,SAAA,CAAU;AAAA,EACtC,WAAA,CACE,OAAA,EACA,UAAA,EACA,IAAA,EACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,MAAM,OAAO,CAAA;AAC5B,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAAA,EACpB;AACF","file":"chunk-36RADUUO.mjs","sourcesContent":["/**\n * Base Error - Error base para la librería\n */\n\nexport class BaseError extends Error {\n public code?: string | number;\n public statusCode?: number;\n public details?: any;\n\n constructor(message: string, code?: string | number, details?: any) {\n super(message);\n this.name = this.constructor.name;\n this.code = code;\n this.details = details;\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n\n","/**\n * Auth Error - Authentication errors\n */\n\nimport { BaseError } from './BaseError';\n\nexport class AuthError extends BaseError {\n constructor(message: string, code?: string | number, details?: any) {\n super(message, code, details);\n this.name = 'AuthError';\n }\n}\n\n\n","/**\n * API Error - Errores de API\n */\n\nimport { BaseError } from './BaseError';\n\nexport class APIError extends BaseError {\n constructor(\n message: string,\n statusCode?: number,\n code?: string | number,\n details?: any\n ) {\n super(message, code, details);\n this.name = 'APIError';\n this.statusCode = statusCode;\n }\n}\n\n\n"]}
@@ -0,0 +1,666 @@
1
+ 'use strict';
2
+
3
+ var chunkER5A6TIL_js = require('./chunk-ER5A6TIL.js');
4
+ var chunkHPLIHYLQ_js = require('./chunk-HPLIHYLQ.js');
5
+
6
+ // providers/instagram/auth/InstagramAuth.ts
7
+ var InstagramAuth = class {
8
+ constructor(config) {
9
+ this.config = config;
10
+ this.httpClient = new chunkER5A6TIL_js.HttpClient({
11
+ baseURL: chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL
12
+ });
13
+ }
14
+ /**
15
+ * Exchange Instagram/Facebook token for session
16
+ */
17
+ async exchangeToken(instagramToken) {
18
+ try {
19
+ const profile = await this.getProfile(instagramToken);
20
+ return {
21
+ accessToken: instagramToken,
22
+ user: profile
23
+ };
24
+ } catch (error) {
25
+ throw new chunkHPLIHYLQ_js.AuthError(
26
+ `Failed to exchange Instagram token: ${error instanceof Error ? error.message : "Unknown error"}`,
27
+ "TOKEN_EXCHANGE_ERROR",
28
+ error
29
+ );
30
+ }
31
+ }
32
+ /**
33
+ * Get Instagram user profile
34
+ * First gets Facebook profile, then Instagram Business profile
35
+ */
36
+ async getProfile(accessToken) {
37
+ try {
38
+ const response = await this.httpClient.get("/me/accounts", {
39
+ fields: "instagram_business_account",
40
+ access_token: accessToken
41
+ });
42
+ if (!response.data || response.data.length === 0) {
43
+ throw new chunkHPLIHYLQ_js.AuthError(
44
+ "No Instagram business account found",
45
+ "NO_INSTAGRAM_ACCOUNT"
46
+ );
47
+ }
48
+ const instagramAccountId = response.data[0]?.instagram_business_account?.id;
49
+ if (!instagramAccountId) {
50
+ throw new chunkHPLIHYLQ_js.AuthError(
51
+ "No Instagram business account ID found",
52
+ "NO_INSTAGRAM_ACCOUNT_ID"
53
+ );
54
+ }
55
+ const profile = await this.httpClient.get(
56
+ `/${instagramAccountId}`,
57
+ {
58
+ fields: "id,username,name,account_type,profile_picture_url",
59
+ access_token: accessToken
60
+ }
61
+ );
62
+ return {
63
+ id: profile.id,
64
+ name: profile.name || profile.username,
65
+ username: profile.username,
66
+ picture: profile.profile_picture_url
67
+ };
68
+ } catch (error) {
69
+ throw new chunkHPLIHYLQ_js.AuthError(
70
+ `Failed to fetch Instagram profile: ${error instanceof Error ? error.message : "Unknown error"}`,
71
+ "PROFILE_FETCH_ERROR",
72
+ error
73
+ );
74
+ }
75
+ }
76
+ /**
77
+ * Get OAuth configuration for Instagram
78
+ * Instagram uses the same OAuth flow as Facebook
79
+ */
80
+ getOAuthConfig(scopes, redirectUri) {
81
+ return {
82
+ authorizationEndpoint: chunkER5A6TIL_js.FACEBOOK_OAUTH_AUTHORIZATION_URL,
83
+ tokenEndpoint: `${chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL}/oauth/access_token`,
84
+ clientId: this.config.appId,
85
+ clientSecret: this.config.appSecret,
86
+ redirectUri,
87
+ scopes,
88
+ responseType: "token",
89
+ extraParams: {
90
+ display: "popup"
91
+ }
92
+ };
93
+ }
94
+ /**
95
+ * Get authorization URL
96
+ */
97
+ getAuthorizationUrl(scopes, redirectUri, state) {
98
+ const params = new URLSearchParams({
99
+ client_id: this.config.appId,
100
+ redirect_uri: redirectUri,
101
+ scope: scopes.join(","),
102
+ response_type: "token",
103
+ display: "popup",
104
+ ...state && { state }
105
+ });
106
+ return `${chunkER5A6TIL_js.FACEBOOK_OAUTH_AUTHORIZATION_URL}?${params.toString()}`;
107
+ }
108
+ /**
109
+ * Get current API version (read-only)
110
+ */
111
+ getApiVersion() {
112
+ return chunkER5A6TIL_js.FACEBOOK_GRAPH_API_VERSION;
113
+ }
114
+ };
115
+
116
+ // providers/instagram/api/InstagramAPI.ts
117
+ var InstagramAPI = class {
118
+ constructor(config, accessToken) {
119
+ this.config = config;
120
+ this.accessToken = accessToken;
121
+ this.httpClient = new chunkER5A6TIL_js.HttpClient({
122
+ baseURL: chunkER5A6TIL_js.FACEBOOK_GRAPH_API_BASE_URL,
123
+ accessToken: this.accessToken
124
+ });
125
+ }
126
+ /**
127
+ * Generic request
128
+ */
129
+ async request(endpoint, options = {}) {
130
+ if (this.accessToken && !options.params?.access_token) {
131
+ options.params = {
132
+ ...options.params,
133
+ access_token: this.accessToken
134
+ };
135
+ }
136
+ return this.httpClient.request(endpoint, options);
137
+ }
138
+ /**
139
+ * GET request
140
+ */
141
+ async get(endpoint, params) {
142
+ return this.request(endpoint, { method: "GET", params });
143
+ }
144
+ /**
145
+ * POST request
146
+ */
147
+ async post(endpoint, body) {
148
+ return this.request(endpoint, { method: "POST", body });
149
+ }
150
+ /**
151
+ * PUT request
152
+ */
153
+ async put(endpoint, body) {
154
+ return this.request(endpoint, { method: "PUT", body });
155
+ }
156
+ /**
157
+ * DELETE request
158
+ */
159
+ async delete(endpoint) {
160
+ return this.request(endpoint, { method: "DELETE" });
161
+ }
162
+ /**
163
+ * Update access token
164
+ */
165
+ setAccessToken(token) {
166
+ this.accessToken = token;
167
+ this.httpClient.setAccessToken(token);
168
+ }
169
+ /**
170
+ * Get current access token
171
+ */
172
+ getAccessToken() {
173
+ return this.accessToken;
174
+ }
175
+ // ============= Instagram-specific methods =============
176
+ /**
177
+ * Get user's Instagram Business account (single account from first page)
178
+ */
179
+ async getAccount(pageAccessToken) {
180
+ try {
181
+ const token = pageAccessToken || this.accessToken;
182
+ if (!token) {
183
+ throw new chunkHPLIHYLQ_js.APIError("Access token is required", 401, "NO_TOKEN");
184
+ }
185
+ const response = await this.get("/me/accounts", {
186
+ fields: "instagram_business_account",
187
+ access_token: token
188
+ });
189
+ if (!response.data || response.data.length === 0) {
190
+ throw new chunkHPLIHYLQ_js.APIError(
191
+ "No Instagram business account found",
192
+ 404,
193
+ "NO_INSTAGRAM_ACCOUNT"
194
+ );
195
+ }
196
+ const instagramAccountId = response.data[0]?.instagram_business_account?.id;
197
+ if (!instagramAccountId) {
198
+ throw new chunkHPLIHYLQ_js.APIError(
199
+ "No Instagram business account ID found",
200
+ 404,
201
+ "NO_INSTAGRAM_ACCOUNT_ID"
202
+ );
203
+ }
204
+ const account = await this.get(
205
+ `/${instagramAccountId}`,
206
+ {
207
+ fields: "id,username,name,profile_picture_url,followers_count,follows_count,media_count",
208
+ access_token: token
209
+ }
210
+ );
211
+ return account;
212
+ } catch (error) {
213
+ throw new chunkHPLIHYLQ_js.APIError(
214
+ `Failed to fetch Instagram account: ${error instanceof Error ? error.message : "Unknown error"}`,
215
+ void 0,
216
+ "ACCOUNT_FETCH_ERROR",
217
+ error
218
+ );
219
+ }
220
+ }
221
+ /**
222
+ * Get all Instagram Business accounts linked to user's Facebook pages
223
+ * Returns all Instagram accounts from all connected Facebook pages
224
+ */
225
+ async getInstagramAccounts(userAccessToken) {
226
+ try {
227
+ const token = userAccessToken || this.accessToken;
228
+ if (!token) {
229
+ throw new chunkHPLIHYLQ_js.APIError("Access token is required", 401, "NO_TOKEN");
230
+ }
231
+ const response = await this.get("/me/accounts", {
232
+ fields: "id,name,instagram_business_account{id,username,name,profile_picture_url,followers_count,follows_count,media_count}",
233
+ access_token: token
234
+ });
235
+ if (!response.data || response.data.length === 0) {
236
+ console.log(" \u2139\uFE0F No Facebook pages found");
237
+ return [];
238
+ }
239
+ const instagramAccounts = [];
240
+ for (const page of response.data) {
241
+ if (page.instagram_business_account) {
242
+ instagramAccounts.push({
243
+ id: page.instagram_business_account.id,
244
+ username: page.instagram_business_account.username,
245
+ name: page.instagram_business_account.name,
246
+ profile_picture_url: page.instagram_business_account.profile_picture_url,
247
+ followers_count: page.instagram_business_account.followers_count,
248
+ follows_count: page.instagram_business_account.follows_count,
249
+ media_count: page.instagram_business_account.media_count
250
+ });
251
+ }
252
+ }
253
+ console.log(` \u2705 Found ${instagramAccounts.length} Instagram account(s)`);
254
+ return instagramAccounts;
255
+ } catch (error) {
256
+ throw new chunkHPLIHYLQ_js.APIError(
257
+ `Failed to fetch Instagram accounts: ${error instanceof Error ? error.message : "Unknown error"}`,
258
+ void 0,
259
+ "ACCOUNTS_FETCH_ERROR",
260
+ error
261
+ );
262
+ }
263
+ }
264
+ /**
265
+ * Get Instagram media
266
+ */
267
+ async getMedia(instagramAccountId, limit = 25) {
268
+ try {
269
+ const response = await this.get(
270
+ `/${instagramAccountId}/media`,
271
+ {
272
+ fields: "id,media_type,media_url,thumbnail_url,permalink,caption,timestamp,like_count,comments_count",
273
+ limit
274
+ }
275
+ );
276
+ return response.data;
277
+ } catch (error) {
278
+ throw new chunkHPLIHYLQ_js.APIError(
279
+ `Failed to fetch Instagram media: ${error instanceof Error ? error.message : "Unknown error"}`,
280
+ void 0,
281
+ "MEDIA_FETCH_ERROR",
282
+ error
283
+ );
284
+ }
285
+ }
286
+ /**
287
+ * Publish photo to Instagram (2-step process)
288
+ */
289
+ async publishPhoto(params) {
290
+ const { instagramAccountId, imageUrl, caption } = params;
291
+ if (!imageUrl) {
292
+ throw new chunkHPLIHYLQ_js.APIError(
293
+ "Image URL is required for photo posts",
294
+ 400,
295
+ "INVALID_PARAMS"
296
+ );
297
+ }
298
+ try {
299
+ const containerResponse = await this.post(
300
+ `/${instagramAccountId}/media`,
301
+ {
302
+ image_url: imageUrl,
303
+ caption: caption || ""
304
+ }
305
+ );
306
+ const publishResponse = await this.post(
307
+ `/${instagramAccountId}/media_publish`,
308
+ {
309
+ creation_id: containerResponse.id
310
+ }
311
+ );
312
+ return publishResponse;
313
+ } catch (error) {
314
+ throw new chunkHPLIHYLQ_js.APIError(
315
+ `Failed to publish photo: ${error instanceof Error ? error.message : "Unknown error"}`,
316
+ void 0,
317
+ "PHOTO_PUBLISH_ERROR",
318
+ error
319
+ );
320
+ }
321
+ }
322
+ /**
323
+ * Publish video to Instagram (2-step process)
324
+ */
325
+ async publishVideo(params) {
326
+ const { instagramAccountId, videoUrl, caption } = params;
327
+ if (!videoUrl) {
328
+ throw new chunkHPLIHYLQ_js.APIError(
329
+ "Video URL is required for video posts",
330
+ 400,
331
+ "INVALID_PARAMS"
332
+ );
333
+ }
334
+ try {
335
+ const containerResponse = await this.post(
336
+ `/${instagramAccountId}/media`,
337
+ {
338
+ media_type: "VIDEO",
339
+ video_url: videoUrl,
340
+ caption: caption || ""
341
+ }
342
+ );
343
+ const publishResponse = await this.post(
344
+ `/${instagramAccountId}/media_publish`,
345
+ {
346
+ creation_id: containerResponse.id
347
+ }
348
+ );
349
+ return publishResponse;
350
+ } catch (error) {
351
+ throw new chunkHPLIHYLQ_js.APIError(
352
+ `Failed to publish video: ${error instanceof Error ? error.message : "Unknown error"}`,
353
+ void 0,
354
+ "VIDEO_PUBLISH_ERROR",
355
+ error
356
+ );
357
+ }
358
+ }
359
+ /**
360
+ * Delete Instagram media
361
+ */
362
+ async deleteMedia(mediaId) {
363
+ try {
364
+ const response = await this.delete(
365
+ `/${mediaId}`
366
+ );
367
+ return response.success === true;
368
+ } catch (error) {
369
+ throw new chunkHPLIHYLQ_js.APIError(
370
+ `Failed to delete media: ${error instanceof Error ? error.message : "Unknown error"}`,
371
+ void 0,
372
+ "MEDIA_DELETE_ERROR",
373
+ error
374
+ );
375
+ }
376
+ }
377
+ /**
378
+ * Get Instagram account insights
379
+ */
380
+ async getAccountInsights(instagramAccountId, params) {
381
+ try {
382
+ const { metric, period, metric_type, since, until } = params;
383
+ const response = await this.get(
384
+ `/${instagramAccountId}/insights`,
385
+ {
386
+ metric: metric.join(","),
387
+ period: period || "day",
388
+ metric_type: metric_type || "total_value",
389
+ ...since && { since },
390
+ ...until && { until }
391
+ }
392
+ );
393
+ return response;
394
+ } catch (error) {
395
+ throw new chunkHPLIHYLQ_js.APIError(
396
+ `Failed to fetch insights: ${error instanceof Error ? error.message : "Unknown error"}`,
397
+ void 0,
398
+ "INSIGHTS_FETCH_ERROR",
399
+ error
400
+ );
401
+ }
402
+ }
403
+ /**
404
+ * Get specific media insights
405
+ */
406
+ async getMediaInsights(mediaId, metrics) {
407
+ try {
408
+ const response = await this.get(
409
+ `/${mediaId}/insights`,
410
+ {
411
+ metric: metrics.join(",")
412
+ }
413
+ );
414
+ return response;
415
+ } catch (error) {
416
+ throw new chunkHPLIHYLQ_js.APIError(
417
+ `Failed to fetch media insights: ${error instanceof Error ? error.message : "Unknown error"}`,
418
+ void 0,
419
+ "MEDIA_INSIGHTS_ERROR",
420
+ error
421
+ );
422
+ }
423
+ }
424
+ // ============= Enhanced Insights Methods =============
425
+ /**
426
+ * Get account insights with default metrics
427
+ * Uses updated metrics (views instead of impressions)
428
+ * @param instagramAccountId - Instagram Account ID
429
+ * @param period - Period for metrics
430
+ * @returns Account insights
431
+ */
432
+ async getAccountInsightsOverview(instagramAccountId, period = "days_28") {
433
+ return this.getAccountInsights(instagramAccountId, {
434
+ metric: [...chunkER5A6TIL_js.METRIC_PRESETS.INSTAGRAM_OVERVIEW],
435
+ period,
436
+ metric_type: "total_value"
437
+ });
438
+ }
439
+ /**
440
+ * Get account summary with parsed values
441
+ * @param instagramAccountId - Instagram Account ID
442
+ * @param period - Period for metrics
443
+ * @returns Parsed account summary
444
+ */
445
+ async getAccountSummary(instagramAccountId, period = "days_28") {
446
+ try {
447
+ const account = await this.get(`/${instagramAccountId}`, {
448
+ fields: "id,username,followers_count"
449
+ });
450
+ const insights = await this.getAccountInsightsOverview(instagramAccountId, period);
451
+ const summary = {
452
+ id: account.id,
453
+ username: account.username,
454
+ followers_count: account.followers_count || 0
455
+ };
456
+ for (const item of insights.data) {
457
+ const value = item.total_value?.value ?? item.values?.[0]?.value;
458
+ if (typeof value !== "number") continue;
459
+ switch (item.name) {
460
+ case "views":
461
+ summary.views = value;
462
+ break;
463
+ case "reach":
464
+ summary.reach = value;
465
+ break;
466
+ case "accounts_engaged":
467
+ summary.accounts_engaged = value;
468
+ break;
469
+ case "total_interactions":
470
+ summary.total_interactions = value;
471
+ break;
472
+ }
473
+ }
474
+ return summary;
475
+ } catch (error) {
476
+ throw new chunkHPLIHYLQ_js.APIError(
477
+ `Failed to fetch account summary: ${error instanceof Error ? error.message : "Unknown error"}`,
478
+ void 0,
479
+ "ACCOUNT_SUMMARY_ERROR",
480
+ error
481
+ );
482
+ }
483
+ }
484
+ /**
485
+ * Get media insights based on media type
486
+ * Automatically selects appropriate metrics
487
+ * @param mediaId - Media ID
488
+ * @param mediaType - Type of media
489
+ * @returns Media insights
490
+ */
491
+ async getMediaInsightsByType(mediaId, mediaType) {
492
+ let metrics;
493
+ switch (mediaType) {
494
+ case "REELS":
495
+ metrics = chunkER5A6TIL_js.INSTAGRAM_REELS_METRICS;
496
+ break;
497
+ case "VIDEO":
498
+ metrics = [...chunkER5A6TIL_js.INSTAGRAM_MEDIA_METRICS_COMMON, "plays"];
499
+ break;
500
+ default:
501
+ metrics = chunkER5A6TIL_js.INSTAGRAM_MEDIA_METRICS_COMMON;
502
+ }
503
+ return this.getMediaInsights(mediaId, [...metrics]);
504
+ }
505
+ /**
506
+ * Get media insights with parsed values
507
+ * @param mediaId - Media ID
508
+ * @param mediaType - Type of media
509
+ * @returns Parsed media insights
510
+ */
511
+ async getMediaInsightsParsed(mediaId, mediaType = "IMAGE") {
512
+ try {
513
+ const response = await this.getMediaInsightsByType(mediaId, mediaType);
514
+ const insights = {
515
+ id: mediaId,
516
+ media_type: mediaType
517
+ };
518
+ for (const item of response.data) {
519
+ const value = item.total_value?.value ?? item.values?.[0]?.value;
520
+ if (typeof value !== "number") continue;
521
+ switch (item.name) {
522
+ case "views":
523
+ insights.views = value;
524
+ break;
525
+ case "reach":
526
+ insights.reach = value;
527
+ break;
528
+ case "likes":
529
+ insights.likes = value;
530
+ break;
531
+ case "comments":
532
+ insights.comments = value;
533
+ break;
534
+ case "shares":
535
+ insights.shares = value;
536
+ break;
537
+ case "saved":
538
+ insights.saves = value;
539
+ break;
540
+ case "plays":
541
+ insights.plays = value;
542
+ break;
543
+ case "total_interactions":
544
+ insights.total_interactions = value;
545
+ break;
546
+ }
547
+ }
548
+ return insights;
549
+ } catch (error) {
550
+ throw new chunkHPLIHYLQ_js.APIError(
551
+ `Failed to fetch parsed media insights: ${error instanceof Error ? error.message : "Unknown error"}`,
552
+ void 0,
553
+ "MEDIA_INSIGHTS_PARSED_ERROR",
554
+ error
555
+ );
556
+ }
557
+ }
558
+ /**
559
+ * Get story insights
560
+ * @param storyId - Story media ID
561
+ * @returns Story insights
562
+ */
563
+ async getStoryInsights(storyId) {
564
+ return this.getMediaInsights(storyId, [...chunkER5A6TIL_js.INSTAGRAM_STORIES_METRICS]);
565
+ }
566
+ /**
567
+ * Get reels insights
568
+ * @param reelId - Reel media ID
569
+ * @returns Reel insights
570
+ */
571
+ async getReelInsights(reelId) {
572
+ return this.getMediaInsights(reelId, [...chunkER5A6TIL_js.INSTAGRAM_REELS_METRICS]);
573
+ }
574
+ /**
575
+ * Get engagement metrics for account
576
+ * @param instagramAccountId - Instagram Account ID
577
+ * @param period - Period for metrics
578
+ * @returns Engagement insights
579
+ */
580
+ async getEngagementInsights(instagramAccountId, period = "days_28") {
581
+ return this.getAccountInsights(instagramAccountId, {
582
+ metric: [...chunkER5A6TIL_js.METRIC_PRESETS.INSTAGRAM_ENGAGEMENT],
583
+ period,
584
+ metric_type: "total_value"
585
+ });
586
+ }
587
+ /**
588
+ * Get demographics insights for account
589
+ * @param instagramAccountId - Instagram Account ID
590
+ * @param breakdown - Demographic breakdown type
591
+ * @returns Demographics insights
592
+ */
593
+ async getDemographicsInsights(instagramAccountId, breakdown = "country") {
594
+ try {
595
+ const response = await this.get(
596
+ `/${instagramAccountId}/insights`,
597
+ {
598
+ metric: "follower_demographics",
599
+ period: "lifetime",
600
+ metric_type: "total_value",
601
+ breakdown
602
+ }
603
+ );
604
+ return response;
605
+ } catch (error) {
606
+ throw new chunkHPLIHYLQ_js.APIError(
607
+ `Failed to fetch demographics insights: ${error instanceof Error ? error.message : "Unknown error"}`,
608
+ void 0,
609
+ "DEMOGRAPHICS_ERROR",
610
+ error
611
+ );
612
+ }
613
+ }
614
+ /**
615
+ * Get current API version (read-only)
616
+ */
617
+ getApiVersion() {
618
+ return chunkER5A6TIL_js.FACEBOOK_GRAPH_API_VERSION;
619
+ }
620
+ };
621
+
622
+ // providers/instagram/InstagramProvider.ts
623
+ var InstagramProvider = class {
624
+ constructor(config) {
625
+ this.name = "instagram";
626
+ this.config = config;
627
+ this.auth = new InstagramAuth(config);
628
+ this.api = new InstagramAPI(config);
629
+ }
630
+ /**
631
+ * Create new API instance with access token
632
+ */
633
+ createAPIClient(accessToken) {
634
+ return new InstagramAPI(this.config, accessToken);
635
+ }
636
+ /**
637
+ * Update access token of existing API client
638
+ */
639
+ setAccessToken(accessToken) {
640
+ this.api.setAccessToken(accessToken);
641
+ }
642
+ /**
643
+ * Get current access token
644
+ */
645
+ getAccessToken() {
646
+ return this.api.getAccessToken();
647
+ }
648
+ };
649
+
650
+ // providers/instagram/types/index.ts
651
+ var InstagramScopes = /* @__PURE__ */ ((InstagramScopes2) => {
652
+ InstagramScopes2["BASIC"] = "instagram_basic";
653
+ InstagramScopes2["CONTENT_PUBLISH"] = "instagram_content_publish";
654
+ InstagramScopes2["MANAGE_COMMENTS"] = "instagram_manage_comments";
655
+ InstagramScopes2["MANAGE_INSIGHTS"] = "instagram_manage_insights";
656
+ InstagramScopes2["MANAGE_MESSAGES"] = "instagram_manage_messages";
657
+ InstagramScopes2["SHOPPING_TAG_PRODUCTS"] = "instagram_shopping_tag_products";
658
+ return InstagramScopes2;
659
+ })(InstagramScopes || {});
660
+
661
+ exports.InstagramAPI = InstagramAPI;
662
+ exports.InstagramAuth = InstagramAuth;
663
+ exports.InstagramProvider = InstagramProvider;
664
+ exports.InstagramScopes = InstagramScopes;
665
+ //# sourceMappingURL=chunk-7QAMNVQU.js.map
666
+ //# sourceMappingURL=chunk-7QAMNVQU.js.map