UNPKG

@memberjunction/actions-bizapps-social

Version:

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

139 lines 5.79 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BufferReorderQueueAction = void 0; const global_1 = require("@memberjunction/global"); const buffer_base_action_1 = require("../buffer-base.action"); const actions_1 = require("@memberjunction/actions"); /** * Action to reorder posts in a Buffer profile's queue */ let BufferReorderQueueAction = class BufferReorderQueueAction extends buffer_base_action_1.BufferBaseAction { /** * Reorder posts in the queue */ async InternalRunAction(params) { const { Params, ContextUser } = params; try { // Get parameters const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID'); const profileId = this.getParamValue(Params, 'ProfileID'); const updateIds = this.getParamValue(Params, 'UpdateIDs'); const offset = this.getParamValue(Params, 'Offset'); // Validate required parameters if (!companyIntegrationId) { throw new Error('CompanyIntegrationID is required'); } if (!profileId) { throw new Error('ProfileID is required'); } if (!updateIds || !Array.isArray(updateIds) || updateIds.length === 0) { throw new Error('UpdateIDs array is required with at least one update ID'); } // Initialize OAuth if (!await this.initializeOAuth(companyIntegrationId)) { return { Success: false, ResultCode: 'INVALID_TOKEN', Message: 'Failed to initialize Buffer OAuth connection', Params }; } // Reorder the updates const result = await this.reorderUpdates(profileId, updateIds, offset); // Get the new queue order to confirm const pendingPosts = await this.getUpdates(profileId, 'pending', { count: updateIds.length + (offset || 0) + 10 }); // Find the reordered posts in the new queue const reorderedPosts = pendingPosts.updates?.filter((update) => updateIds.includes(update.id)) || []; // Create summary const summary = { profileId: profileId, reorderedCount: updateIds.length, offset: offset || 0, newOrder: updateIds, success: result.success === true, newPositions: reorderedPosts.map((post, index) => ({ id: post.id, position: index + (offset || 0), scheduledFor: post.due_at ? new Date(post.due_at * 1000) : null, text: post.text?.substring(0, 100) + (post.text?.length > 100 ? '...' : '') })) }; // Update output parameters const outputParams = [...Params]; const summaryParam = outputParams.find(p => p.Name === 'Summary'); if (summaryParam) summaryParam.Value = summary; const reorderedParam = outputParams.find(p => p.Name === 'ReorderedPosts'); if (reorderedParam) reorderedParam.Value = reorderedPosts; return { Success: true, ResultCode: 'SUCCESS', Message: `Successfully reordered ${updateIds.length} posts in Buffer queue`, Params: outputParams }; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; const resultCode = this.mapBufferError(error); return { Success: false, ResultCode: resultCode, Message: `Failed to reorder queue: ${errorMessage}`, Params }; } } /** * Define the parameters this action expects */ get Params() { return [ ...this.commonSocialParams, { Name: 'ProfileID', Type: 'Input', Value: null }, { Name: 'UpdateIDs', Type: 'Input', Value: null }, { Name: 'Offset', Type: 'Input', Value: null }, { Name: 'Summary', Type: 'Output', Value: null }, { Name: 'ReorderedPosts', Type: 'Output', Value: null } ]; } /** * Metadata about this action */ get Description() { return 'Reorders posts in a Buffer profile\'s queue, allowing you to change the posting schedule order'; } }; exports.BufferReorderQueueAction = BufferReorderQueueAction; exports.BufferReorderQueueAction = BufferReorderQueueAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, 'BufferReorderQueueAction') ], BufferReorderQueueAction); //# sourceMappingURL=reorder-queue.action.js.map