@postrun/js 4.0.0 → 4.2.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { mediaAbort, mediaComplete, mediaListParts, mediaSignPart, mediaGet } from './chunk-YP26OO5J.js';
2
- export { PostrunError, connectionsConnect, connectionsDelete, connectionsGet, connectionsListAccounts, connectionsListByProfile, connectionsSelect, createPostrunClient, logsGet, logsList, mediaAbort, mediaComplete, mediaCreate, mediaDelete, mediaGet, mediaList, mediaListParts, mediaSignPart, mediaUpdate, postsCreate, postsDelete, postsGet, postsList, postsRetry, postsUpdate, postsValidate, profilesCreate, profilesDelete, profilesGet, profilesList, profilesUpdate, tiktokCreatorInfo, tokensMint, webhooksCreateEndpoint, webhooksCreatePortal, webhooksDeleteEndpoint, webhooksGetEndpoint, webhooksListEndpoints, webhooksListEventTypes, webhooksPing, webhooksUpdateEndpoint } from './chunk-YP26OO5J.js';
3
- import './chunk-VCOKMHAJ.js';
1
+ import { mediaAbort, mediaComplete, mediaListParts, mediaSignPart, mediaGet } from './chunk-HY5QFRKO.js';
2
+ export { PostrunError, connectionsConnect, connectionsDelete, connectionsGet, connectionsGetAnalytics, connectionsListAccounts, connectionsListByProfile, connectionsSelect, createPostrunClient, logsGet, logsList, mediaAbort, mediaComplete, mediaCreate, mediaDelete, mediaGet, mediaList, mediaListParts, mediaSignPart, mediaUpdate, postsCreate, postsDelete, postsGet, postsGetAnalytics, postsList, postsRetry, postsUpdate, postsValidate, profilesCreate, profilesDelete, profilesGet, profilesList, profilesUpdate, tiktokCreatorInfo, tokensMint, webhooksCreateEndpoint, webhooksCreatePortal, webhooksDeleteEndpoint, webhooksGetEndpoint, webhooksListEndpoints, webhooksListEventTypes, webhooksPing, webhooksUpdateEndpoint } from './chunk-HY5QFRKO.js';
3
+ import './chunk-C4MYARB5.js';
4
4
  import Uppy from '@uppy/core';
5
5
  import AwsS3 from '@uppy/aws-s3';
6
6
  import pWaitFor from 'p-wait-for';
@@ -171,8 +171,8 @@ function linkedinPollDurationLabel(value) {
171
171
  }
172
172
 
173
173
  // src/x.ts
174
- function plural(n, unit) {
175
- return `${n} ${unit}${n === 1 ? "" : "s"} left`;
174
+ function plural(n, unit2) {
175
+ return `${n} ${unit2}${n === 1 ? "" : "s"} left`;
176
176
  }
177
177
  function xPollDurationLabel(durationMinutes) {
178
178
  if (durationMinutes >= 1440) {
@@ -184,6 +184,212 @@ function xPollDurationLabel(durationMinutes) {
184
184
  return plural(durationMinutes, "minute");
185
185
  }
186
186
 
187
+ // src/analytics.ts
188
+ var ANALYTICS_PLATFORMS = [
189
+ "tiktok",
190
+ "instagram",
191
+ "facebook_page"
192
+ ];
193
+ function hasAnalytics(platform) {
194
+ return ANALYTICS_PLATFORMS.some((supported) => supported === platform);
195
+ }
196
+ function hasPostAnalytics(variant) {
197
+ return variant.status === "published" && hasAnalytics(variant.platform);
198
+ }
199
+ var TIKTOK_POST = [
200
+ { key: "video_views", label: "Views" },
201
+ { key: "reach", label: "Reach" },
202
+ { key: "likes", label: "Likes" },
203
+ { key: "comments", label: "Comments" },
204
+ { key: "shares", label: "Shares" },
205
+ { key: "favorites", label: "Saves" },
206
+ { key: "average_time_watched", label: "Avg. watch time", format: "seconds" },
207
+ { key: "full_video_watched_rate", label: "Completion", format: "ratio" },
208
+ { key: "new_followers", label: "New followers" },
209
+ { key: "profile_views", label: "Profile views" }
210
+ ];
211
+ var INSTAGRAM_SHARED = [
212
+ { key: "views", label: "Views" },
213
+ { key: "reach", label: "Reach" },
214
+ { key: "likes", label: "Likes" },
215
+ { key: "comments", label: "Comments" },
216
+ { key: "shares", label: "Shares" },
217
+ { key: "saved", label: "Saves" },
218
+ { key: "reposts", label: "Reposts" },
219
+ { key: "total_interactions", label: "Interactions" }
220
+ ];
221
+ var INSTAGRAM_FEED = [
222
+ ...INSTAGRAM_SHARED,
223
+ { key: "follows", label: "Follows" },
224
+ { key: "profile_visits", label: "Profile visits" },
225
+ { key: "profile_activity", label: "Profile activity" }
226
+ ];
227
+ var INSTAGRAM_REEL = [
228
+ ...INSTAGRAM_SHARED,
229
+ {
230
+ key: "ig_reels_avg_watch_time",
231
+ label: "Avg. watch time",
232
+ format: "milliseconds"
233
+ },
234
+ {
235
+ key: "ig_reels_video_view_total_time",
236
+ label: "Watch time",
237
+ format: "milliseconds"
238
+ },
239
+ { key: "reels_skip_rate", label: "Skip rate", format: "percent" }
240
+ ];
241
+ var FACEBOOK_FEED = [
242
+ { key: "post_media_view", label: "Views" },
243
+ { key: "post_total_media_view_unique", label: "Viewers" },
244
+ { key: "post_reactions_by_type_total", label: "Reactions" },
245
+ { key: "post_clicks", label: "Clicks" },
246
+ { key: "post_clicks_by_type", label: "Clicks by type" },
247
+ { key: "comments", label: "Comments" },
248
+ { key: "shares", label: "Shares" }
249
+ ];
250
+ var FACEBOOK_REEL = [
251
+ { key: "blue_reels_play_count", label: "Plays" },
252
+ { key: "fb_reels_total_plays", label: "Total plays" },
253
+ { key: "fb_reels_replay_count", label: "Replays" },
254
+ {
255
+ key: "post_video_avg_time_watched",
256
+ label: "Avg. watch time",
257
+ format: "milliseconds"
258
+ },
259
+ { key: "post_video_view_time", label: "Watch time", format: "milliseconds" },
260
+ { key: "post_video_followers", label: "New followers" },
261
+ { key: "post_video_likes_by_reaction_type", label: "Reactions" }
262
+ ];
263
+ function rowsOf(fields, metrics) {
264
+ return fields.map(({ key, label, format = "count" }) => ({
265
+ key,
266
+ label,
267
+ format,
268
+ value: metrics[key]
269
+ }));
270
+ }
271
+ function postMetricRows(metrics, postType) {
272
+ switch (metrics.platform) {
273
+ case "tiktok":
274
+ return rowsOf(TIKTOK_POST, metrics);
275
+ case "instagram":
276
+ return rowsOf(
277
+ postType === "reel" ? INSTAGRAM_REEL : INSTAGRAM_FEED,
278
+ metrics
279
+ );
280
+ case "facebook_page":
281
+ return rowsOf(
282
+ postType === "reel" ? FACEBOOK_REEL : FACEBOOK_FEED,
283
+ metrics
284
+ );
285
+ }
286
+ }
287
+ var TIKTOK_ACCOUNT = [
288
+ { key: "followers_count", label: "Followers" },
289
+ { key: "following_count", label: "Following" },
290
+ { key: "total_likes", label: "Likes" },
291
+ { key: "videos_count", label: "Videos" }
292
+ ];
293
+ var INSTAGRAM_ACCOUNT = [
294
+ { key: "followers_count", label: "Followers" },
295
+ { key: "follows_count", label: "Following" },
296
+ { key: "media_count", label: "Posts" }
297
+ ];
298
+ var INSTAGRAM_LAST_30_DAYS = [
299
+ { key: "views", label: "Views \xB7 30d" },
300
+ { key: "reach", label: "Reach \xB7 30d" },
301
+ { key: "accounts_engaged", label: "Engaged \xB7 30d" },
302
+ { key: "total_interactions", label: "Interactions \xB7 30d" }
303
+ ];
304
+ var FACEBOOK_ACCOUNT = [
305
+ { key: "followers_count", label: "Followers" }
306
+ ];
307
+ function accountMetricRows(metrics) {
308
+ switch (metrics.platform) {
309
+ case "tiktok":
310
+ return rowsOf(TIKTOK_ACCOUNT, metrics);
311
+ case "instagram":
312
+ return [
313
+ ...rowsOf(INSTAGRAM_ACCOUNT, metrics),
314
+ ...rowsOf(INSTAGRAM_LAST_30_DAYS, metrics.last_30_days)
315
+ ];
316
+ case "facebook_page":
317
+ return rowsOf(FACEBOOK_ACCOUNT, metrics);
318
+ }
319
+ }
320
+ function pointsOf(daily, key) {
321
+ return daily.flatMap((day) => {
322
+ const value = day[key];
323
+ return value === null ? [] : [{ date: day.date, value }];
324
+ });
325
+ }
326
+ function accountTrend(metrics) {
327
+ switch (metrics.platform) {
328
+ case "tiktok":
329
+ return {
330
+ label: "Followers",
331
+ points: pointsOf(metrics.daily, "followers_count")
332
+ };
333
+ case "instagram":
334
+ return { label: "Reach", points: pointsOf(metrics.daily, "reach") };
335
+ case "facebook_page":
336
+ return {
337
+ label: "Followers",
338
+ points: pointsOf(metrics.daily, "page_follows")
339
+ };
340
+ }
341
+ }
342
+ var COUNT = new Intl.NumberFormat("en-US", {
343
+ notation: "compact",
344
+ maximumFractionDigits: 1
345
+ });
346
+ var PERCENT = new Intl.NumberFormat("en-US", {
347
+ style: "percent",
348
+ maximumFractionDigits: 1
349
+ });
350
+ var unit = (name) => new Intl.NumberFormat("en-US", {
351
+ style: "unit",
352
+ unit: name,
353
+ unitDisplay: "narrow",
354
+ maximumFractionDigits: 1
355
+ });
356
+ var SECONDS = unit("second");
357
+ var MINUTES = unit("minute");
358
+ var HOURS = unit("hour");
359
+ var roundsBelow = (value, limit) => Math.round(value * 10) / 10 < limit;
360
+ function formatDuration(seconds) {
361
+ if (roundsBelow(seconds, 60)) {
362
+ return SECONDS.format(seconds);
363
+ }
364
+ const minutes = seconds / 60;
365
+ return roundsBelow(minutes, 60) ? MINUTES.format(minutes) : HOURS.format(minutes / 60);
366
+ }
367
+ function formatNumber(value, format) {
368
+ switch (format) {
369
+ case "count":
370
+ return COUNT.format(value);
371
+ case "seconds":
372
+ return formatDuration(value);
373
+ case "milliseconds":
374
+ return formatDuration(value / 1e3);
375
+ case "ratio":
376
+ return PERCENT.format(value);
377
+ case "percent":
378
+ return PERCENT.format(value / 100);
379
+ }
380
+ }
381
+ var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
382
+ function formatMetric(value, format = "count") {
383
+ if (value === null) {
384
+ return "\u2014";
385
+ }
386
+ if (typeof value === "number") {
387
+ return formatNumber(value, format);
388
+ }
389
+ const entries = Object.entries(value).sort(([, a], [, b]) => b - a);
390
+ return entries.length === 0 ? "0" : entries.map(([type, count]) => `${capitalize(type)} ${COUNT.format(count)}`).join(" \xB7 ");
391
+ }
392
+
187
393
  // src/tiktok-options.ts
188
394
  var TIKTOK_CAPTION_MAX = { video: 2200, photo: 4e3 };
189
395
  function captionMaxFor(postType) {
@@ -381,12 +587,22 @@ var tiktokHandler = {
381
587
  settings
382
588
  })
383
589
  };
590
+ var youtubeHandler = {
591
+ buildVariant: ({ settings, connectionId, body, media }) => ({
592
+ platform: "youtube",
593
+ connection_id: connectionId,
594
+ body,
595
+ media: [...media],
596
+ settings
597
+ })
598
+ };
384
599
  var PLATFORM_HANDLERS = {
385
600
  x: xHandler,
386
601
  linkedin: linkedInHandler,
387
602
  facebook_page: facebookHandler,
388
603
  instagram: instagramHandler,
389
- tiktok: tiktokHandler
604
+ tiktok: tiktokHandler,
605
+ youtube: youtubeHandler
390
606
  };
391
607
  function isPostPlatform(value) {
392
608
  return Object.prototype.hasOwnProperty.call(PLATFORM_HANDLERS, value);
@@ -472,6 +688,6 @@ function buildUpdatePost(input, connections = []) {
472
688
  };
473
689
  }
474
690
 
475
- export { ComposeError, POST_PLATFORMS, TIKTOK_AUDIENCE_REQUIRED_HINT, TIKTOK_BRANDED_CONTENT_POLICY_URL, TIKTOK_BRANDED_CONTENT_PRIVATE_DISABLED_REASON, TIKTOK_CAPTION_MAX, TIKTOK_DISCLOSURE_REQUIRED_HINT, TIKTOK_MUSIC_CONFIRMATION_URL, TIKTOK_PROCESSING_NOTICE, UploadError, audiencePrivacyOptions, audienceUnselected, brandedContentDeclared, brandedContentDisabledReason, buildCreatePost, buildUpdatePost, captionMaxFor, commercialDisclosureIncomplete, commercialLabelNotice, defaultTikTokOptions, failedVariants, interactionRows, interactionValueKey, isInteractionForbidden, isPostPlatform, isPublished, linkedinPollDurationLabel, parsePrivacyLevel, setBrandKind, setCommercialDisclosure, tiktokDurationError, tiktokOptionsFromSettings, tiktokOptionsReady, tiktokPrivacyLabel, tiktokSettings, toggleInteraction, uploadFile, waitForMedia, xPollDurationLabel };
691
+ export { ComposeError, POST_PLATFORMS, TIKTOK_AUDIENCE_REQUIRED_HINT, TIKTOK_BRANDED_CONTENT_POLICY_URL, TIKTOK_BRANDED_CONTENT_PRIVATE_DISABLED_REASON, TIKTOK_CAPTION_MAX, TIKTOK_DISCLOSURE_REQUIRED_HINT, TIKTOK_MUSIC_CONFIRMATION_URL, TIKTOK_PROCESSING_NOTICE, UploadError, accountMetricRows, accountTrend, audiencePrivacyOptions, audienceUnselected, brandedContentDeclared, brandedContentDisabledReason, buildCreatePost, buildUpdatePost, captionMaxFor, commercialDisclosureIncomplete, commercialLabelNotice, defaultTikTokOptions, failedVariants, formatMetric, hasAnalytics, hasPostAnalytics, interactionRows, interactionValueKey, isInteractionForbidden, isPostPlatform, isPublished, linkedinPollDurationLabel, parsePrivacyLevel, postMetricRows, setBrandKind, setCommercialDisclosure, tiktokDurationError, tiktokOptionsFromSettings, tiktokOptionsReady, tiktokPrivacyLabel, tiktokSettings, toggleInteraction, uploadFile, waitForMedia, xPollDurationLabel };
476
692
  //# sourceMappingURL=index.js.map
477
693
  //# sourceMappingURL=index.js.map