UNPKG

@memberjunction/actions-bizapps-social

Version:

Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer

77 lines 3.94 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { RegisterClass } from '@memberjunction/global'; import { BufferBaseAction } from '../buffer-base.action.js'; import { BaseAction } from '@memberjunction/actions'; /** * Retrieves sent (published) posts from Buffer. * Uses the posts query filtered by status "sent". */ let BufferGetSentPostsAction = class BufferGetSentPostsAction extends BufferBaseAction { async InternalRunAction(params) { const { Params } = params; try { const authError = await this.ensureAuthenticated(params); if (authError) return authError; const channelId = this.getParamValue(Params, 'ChannelID'); const limit = this.getParamValue(Params, 'Limit') || 20; const cursor = this.getParamValue(Params, 'After'); const startDate = this.getParamValue(Params, 'StartDate'); const endDate = this.getParamValue(Params, 'EndDate'); const organizationId = await this.resolveOrganizationId(Params); const status = 'sent'; const filters = { status }; if (channelId) filters.channelIds = [channelId]; if (startDate) filters.startDate = new Date(startDate).toISOString(); if (endDate) filters.endDate = new Date(endDate).toISOString(); const connection = await this.fetchPosts(organizationId, filters, limit, cursor || undefined); const posts = connection.edges.map((edge) => this.normalizePost(edge.node)); const summary = { totalPosts: posts.length, totalCount: connection.totalCount, hasMore: connection.pageInfo.hasNextPage, endCursor: connection.pageInfo.endCursor, channelId: channelId || 'all', dateRange: { earliest: posts.length > 0 ? posts[posts.length - 1].publishedAt : null, latest: posts.length > 0 ? posts[0].publishedAt : null, }, postsByDay: this.groupPostsByDay(posts, 'publishedAt'), }; this.setOutputParam(Params, 'Posts', posts); this.setOutputParam(Params, 'Summary', summary); return { Success: true, ResultCode: 'SUCCESS', Message: `Retrieved ${posts.length} sent posts from Buffer`, Params }; } catch (error) { return this.buildErrorResult(error, 'get sent posts', Params); } } get Params() { return [ ...this.bufferCommonParams, { Name: 'ChannelID', Type: 'Input', Value: null }, { Name: 'Limit', Type: 'Input', Value: 20 }, { Name: 'After', Type: 'Input', Value: null }, { Name: 'StartDate', Type: 'Input', Value: null }, { Name: 'EndDate', Type: 'Input', Value: null }, { Name: 'Posts', Type: 'Output', Value: null }, { Name: 'Summary', Type: 'Output', Value: null }, ]; } get Description() { return 'Retrieves sent (published) posts from Buffer with optional date range filtering'; } }; BufferGetSentPostsAction = __decorate([ RegisterClass(BaseAction, 'BufferGetSentPostsAction') ], BufferGetSentPostsAction); export { BufferGetSentPostsAction }; //# sourceMappingURL=get-sent-posts.action.js.map