@memberjunction/actions-bizapps-social
Version:
Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer
120 lines • 4.55 kB
JavaScript
;
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.BufferDeletePostAction = 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 delete a post from Buffer
*/
let BufferDeletePostAction = class BufferDeletePostAction extends buffer_base_action_1.BufferBaseAction {
/**
* Delete a Buffer post
*/
async InternalRunAction(params) {
const { Params, ContextUser } = params;
try {
// Get parameters
const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID');
const updateId = this.getParamValue(Params, 'UpdateID');
// Validate required parameters
if (!companyIntegrationId) {
throw new Error('CompanyIntegrationID is required');
}
if (!updateId) {
throw new Error('UpdateID is required');
}
// Initialize OAuth
if (!await this.initializeOAuth(companyIntegrationId)) {
return {
Success: false,
ResultCode: 'INVALID_TOKEN',
Message: 'Failed to initialize Buffer OAuth connection',
Params
};
}
// Delete the update
const success = await this.deleteUpdate(updateId);
// Create summary
const summary = {
updateId: updateId,
deleted: success,
deletedAt: new Date()
};
// Update output parameters
const outputParams = [...Params];
const deletedParam = outputParams.find(p => p.Name === 'Deleted');
if (deletedParam)
deletedParam.Value = success;
const summaryParam = outputParams.find(p => p.Name === 'Summary');
if (summaryParam)
summaryParam.Value = summary;
if (success) {
return {
Success: true,
ResultCode: 'SUCCESS',
Message: `Successfully deleted Buffer post ${updateId}`,
Params: outputParams
};
}
else {
return {
Success: false,
ResultCode: 'DELETE_FAILED',
Message: `Failed to delete Buffer post ${updateId}`,
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 delete post: ${errorMessage}`,
Params
};
}
}
/**
* Define the parameters this action expects
*/
get Params() {
return [
...this.commonSocialParams,
{
Name: 'UpdateID',
Type: 'Input',
Value: null
},
{
Name: 'Deleted',
Type: 'Output',
Value: false
},
{
Name: 'Summary',
Type: 'Output',
Value: null
}
];
}
/**
* Metadata about this action
*/
get Description() {
return 'Deletes a pending or sent post from Buffer';
}
};
exports.BufferDeletePostAction = BufferDeletePostAction;
exports.BufferDeletePostAction = BufferDeletePostAction = __decorate([
(0, global_1.RegisterClass)(actions_1.BaseAction, 'BufferDeletePostAction')
], BufferDeletePostAction);
//# sourceMappingURL=delete-post.action.js.map