@jgardner04/ghost-mcp-server 1.5.0 → 1.7.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.
@@ -0,0 +1,47 @@
1
+ import Joi from 'joi';
2
+ import { createContextLogger } from '../utils/logger.js';
3
+ import { createNewsletter as createGhostNewsletter } from './ghostServiceImproved.js';
4
+
5
+ /**
6
+ * Validation schema for newsletter input
7
+ */
8
+ const newsletterInputSchema = Joi.object({
9
+ name: Joi.string().required(),
10
+ description: Joi.string().optional(),
11
+ sender_name: Joi.string().optional(),
12
+ sender_email: Joi.string().email().optional(),
13
+ sender_reply_to: Joi.string().valid('newsletter', 'support').optional(),
14
+ subscribe_on_signup: Joi.boolean().strict().optional(),
15
+ show_header_icon: Joi.boolean().strict().optional(),
16
+ show_header_title: Joi.boolean().strict().optional(),
17
+ });
18
+
19
+ /**
20
+ * Service layer function to handle the business logic of creating a newsletter.
21
+ * Validates input and creates a newsletter in Ghost CMS.
22
+ * @param {object} newsletterInput - Data received from the controller.
23
+ * @returns {Promise<object>} The created newsletter object from the Ghost API.
24
+ */
25
+ const createNewsletterService = async (newsletterInput) => {
26
+ const logger = createContextLogger('newsletter-service');
27
+
28
+ // Validate input
29
+ const { error, value: validatedInput } = newsletterInputSchema.validate(newsletterInput);
30
+ if (error) {
31
+ logger.error('Newsletter input validation failed', {
32
+ error: error.details[0].message,
33
+ inputKeys: Object.keys(newsletterInput),
34
+ });
35
+ throw new Error(`Invalid newsletter input: ${error.details[0].message}`);
36
+ }
37
+
38
+ logger.info('Creating Ghost newsletter', {
39
+ name: validatedInput.name,
40
+ hasSenderEmail: !!validatedInput.sender_email,
41
+ });
42
+
43
+ const newNewsletter = await createGhostNewsletter(validatedInput);
44
+ return newNewsletter;
45
+ };
46
+
47
+ export { createNewsletterService };