UNPKG

@memberjunction/actions-bizapps-social

Version:

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

129 lines 5.28 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.BufferGetProfilesAction = 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 get all Buffer profiles (social media accounts) for the authenticated user */ let BufferGetProfilesAction = class BufferGetProfilesAction extends buffer_base_action_1.BufferBaseAction { /** * Get Buffer profiles */ async InternalRunAction(params) { const { Params, ContextUser } = params; try { // Get company integration ID const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID'); if (!companyIntegrationId) { throw new Error('CompanyIntegrationID is required'); } // Initialize OAuth if (!await this.initializeOAuth(companyIntegrationId)) { return { Success: false, ResultCode: 'INVALID_TOKEN', Message: 'Failed to initialize Buffer OAuth connection', Params }; } // Get profiles const profiles = await this.getProfiles(); // Format profile data const formattedProfiles = profiles.map(profile => ({ id: profile.id, service: profile.service, serviceId: profile.service_id, serviceUsername: profile.service_username, serviceType: profile.service_type, default: profile.default, createdAt: new Date(profile.created_at * 1000), formattedUsername: profile.formatted_username, formattedServiceType: profile.formatted_service, avatar: profile.avatar, avatarHttps: profile.avatar_https, statistics: { followers: profile.statistics?.followers || 0 }, timezone: profile.timezone, schedules: profile.schedules || [] })); // Create summary const summary = { totalProfiles: formattedProfiles.length, profilesByService: this.groupByService(formattedProfiles), defaultProfile: formattedProfiles.find(p => p.default)?.id }; // Update output parameters const outputParams = [...Params]; const profilesParam = outputParams.find(p => p.Name === 'Profiles'); if (profilesParam) profilesParam.Value = formattedProfiles; const summaryParam = outputParams.find(p => p.Name === 'Summary'); if (summaryParam) summaryParam.Value = summary; return { Success: true, ResultCode: 'SUCCESS', Message: `Retrieved ${formattedProfiles.length} Buffer profiles`, 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 get Buffer profiles: ${errorMessage}`, Params }; } } /** * Group profiles by service */ groupByService(profiles) { return profiles.reduce((acc, profile) => { const service = profile.service || 'unknown'; acc[service] = (acc[service] || 0) + 1; return acc; }, {}); } /** * Define the parameters this action expects */ get Params() { return [ ...this.commonSocialParams, { Name: 'Profiles', Type: 'Output', Value: null }, { Name: 'Summary', Type: 'Output', Value: null } ]; } /** * Metadata about this action */ get Description() { return 'Retrieves all Buffer profiles (social media accounts) associated with the authenticated user'; } }; exports.BufferGetProfilesAction = BufferGetProfilesAction; exports.BufferGetProfilesAction = BufferGetProfilesAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, 'BufferGetProfilesAction') ], BufferGetProfilesAction); //# sourceMappingURL=get-profiles.action.js.map