@jgardner04/ghost-mcp-server 1.13.2 → 1.13.4

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.
Files changed (34) hide show
  1. package/package.json +5 -13
  2. package/src/__tests__/helpers/mockGhostApi.js +36 -0
  3. package/src/__tests__/mcp_server.test.js +204 -117
  4. package/src/__tests__/mcp_server_pages.test.js +32 -18
  5. package/src/config/mcp-config.js +1 -1
  6. package/src/controllers/__tests__/tagController.test.js +12 -8
  7. package/src/controllers/tagController.js +2 -2
  8. package/src/errors/__tests__/index.test.js +3 -3
  9. package/src/errors/index.js +1 -1
  10. package/src/index.js +1 -1
  11. package/src/mcp_server.js +35 -31
  12. package/src/schemas/__tests__/postSchemas.test.js +19 -0
  13. package/src/schemas/__tests__/tagSchemas.test.js +1 -1
  14. package/src/schemas/common.js +2 -2
  15. package/src/schemas/memberSchemas.js +20 -8
  16. package/src/schemas/newsletterSchemas.js +10 -10
  17. package/src/schemas/pageSchemas.js +16 -11
  18. package/src/schemas/postSchemas.js +22 -15
  19. package/src/schemas/tagSchemas.js +12 -7
  20. package/src/schemas/tierSchemas.js +17 -8
  21. package/src/services/__tests__/ghostServiceImproved.members.test.js +31 -62
  22. package/src/services/__tests__/ghostServiceImproved.newsletters.test.js +66 -69
  23. package/src/services/__tests__/ghostServiceImproved.pages.test.js +77 -48
  24. package/src/services/__tests__/ghostServiceImproved.posts.test.js +69 -55
  25. package/src/services/__tests__/ghostServiceImproved.tags.test.js +29 -66
  26. package/src/services/__tests__/ghostServiceImproved.tiers.test.js +12 -62
  27. package/src/services/__tests__/memberService.test.js +0 -28
  28. package/src/services/__tests__/tierService.test.js +0 -28
  29. package/src/services/ghostServiceImproved.js +117 -299
  30. package/src/services/imageProcessingService.js +1 -1
  31. package/src/services/memberService.js +0 -13
  32. package/src/services/tierService.js +0 -13
  33. package/src/utils/__tests__/nqlSanitizer.test.js +38 -0
  34. package/src/utils/nqlSanitizer.js +11 -0
@@ -284,21 +284,8 @@ export function validateTierQueryOptions(options) {
284
284
  }
285
285
  }
286
286
 
287
- /**
288
- * Sanitizes a value for use in NQL filters to prevent injection
289
- * Escapes backslashes, single quotes, and double quotes
290
- * @param {string} value - The value to sanitize
291
- * @returns {string} The sanitized value
292
- */
293
- export function sanitizeNqlValue(value) {
294
- if (!value) return value;
295
- // Escape backslashes first, then quotes
296
- return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"');
297
- }
298
-
299
287
  export default {
300
288
  validateTierData,
301
289
  validateTierUpdateData,
302
290
  validateTierQueryOptions,
303
- sanitizeNqlValue,
304
291
  };
@@ -0,0 +1,38 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { sanitizeNqlValue } from '../nqlSanitizer.js';
3
+
4
+ describe('sanitizeNqlValue', () => {
5
+ it('should escape backslashes', () => {
6
+ expect(sanitizeNqlValue('hello\\world')).toBe('hello\\\\world');
7
+ });
8
+
9
+ it('should escape single quotes', () => {
10
+ expect(sanitizeNqlValue("it's")).toBe("it\\'s");
11
+ });
12
+
13
+ it('should escape double quotes', () => {
14
+ expect(sanitizeNqlValue('say "hello"')).toBe('say \\"hello\\"');
15
+ });
16
+
17
+ it('should escape all three special characters combined', () => {
18
+ expect(sanitizeNqlValue('a\\b\'c"d')).toBe('a\\\\b\\\'c\\"d');
19
+ });
20
+
21
+ it('should return null as-is', () => {
22
+ expect(sanitizeNqlValue(null)).toBe(null);
23
+ });
24
+
25
+ it('should return undefined as-is', () => {
26
+ expect(sanitizeNqlValue(undefined)).toBe(undefined);
27
+ });
28
+
29
+ it('should return empty string as-is', () => {
30
+ expect(sanitizeNqlValue('')).toBe('');
31
+ });
32
+
33
+ it('should pass through normal strings without special characters', () => {
34
+ expect(sanitizeNqlValue('simple-value')).toBe('simple-value');
35
+ expect(sanitizeNqlValue('test@example.com')).toBe('test@example.com');
36
+ expect(sanitizeNqlValue('hello world 123')).toBe('hello world 123');
37
+ });
38
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sanitizes a value for use in NQL (Ghost's filter query language) to prevent injection.
3
+ * Escapes backslashes, single quotes, and double quotes.
4
+ * @param {string} value - The value to sanitize
5
+ * @returns {string} The sanitized value
6
+ */
7
+ export function sanitizeNqlValue(value) {
8
+ if (!value) return value;
9
+ // Escape backslashes first, then quotes
10
+ return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"');
11
+ }