backend-manager 5.7.6 → 5.8.1

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.
@@ -198,12 +198,22 @@
198
198
  // Standalone Ghostii article publisher (daily cron). OPT-IN: disabled by
199
199
  // default (articles: 0). Set articles >= 1 to auto-publish independent blog
200
200
  // posts. For newsletter-linked articles, use marketing.newsletter.content.article.enabled instead.
201
+ //
202
+ // Source types:
203
+ // '$app' — generic brand-topic generation
204
+ // '$feed:https://example.com/feed' — RSS/Atom/JSON feed: pick one unprocessed article per run
205
+ // 'https://example.com/page' — fetch URL content as prompt seed
206
+ // 'Write about topic X' — text: use directly as prompt seed
207
+ //
208
+ // Feed items are tracked in Firestore (ghostii-feed-items) so the same article
209
+ // is never reprocessed. When a feed is unreachable or exhausted, falls back to $app.
201
210
  ghostii: [
202
211
  {
203
212
  articles: 0,
204
213
  sources: [
205
214
  '$app',
206
- // Add more sources here
215
+ // '$feed:https://techcrunch.com/feed/',
216
+ // '$feed:https://feeds.arstechnica.com/arstechnica/technology-lab',
207
217
  ],
208
218
  links: [
209
219
  // ...
@@ -211,8 +221,20 @@
211
221
  prompt: '',
212
222
  chance: 1.0,
213
223
  author: null,
214
- // app: 'other-app-id', // Optional: target a different app
215
- // appUrl: 'https://api.otherapp.com', // Required if app is set (fetches /backend-manager/app)
224
+ postPath: 'ghostii',
225
+ // Per-entry Ghostii API overrides (all optional, fall back to framework defaults)
226
+ overrides: {
227
+ // keywords: ['AI', 'technology'],
228
+ // length: 'long', // short | medium | long | comprehensive
229
+ // research: true, // web search for real external links
230
+ // insertImages: true, // section images from Unsplash
231
+ // headerImageUrl: 'unsplash', // disabled | unsplash | generate
232
+ // maxLinks: 6,
233
+ // sectionQuantity: 5,
234
+ // feedUrl: '', // brand blog feed for title dedup
235
+ },
236
+ // brand: 'other-app-id', // Optional: target a different brand
237
+ // brandUrl: 'https://api.otherapp.com', // Required if brand is set
216
238
  }
217
239
  ],
218
240
  reviews: {
@@ -0,0 +1,528 @@
1
+ /**
2
+ * Test: content/feed-parser
3
+ * Unit tests for the RSS 2.0, Atom 1.0, and JSON Feed parser + article content extractor.
4
+ *
5
+ * Run: npx mgr test helpers/content/feed-parser
6
+ *
7
+ * Pure function tests (parseFeed, stripHtml, extractElement) — required
8
+ * directly and called with plain inputs. NOT a mock.
9
+ */
10
+ const { parseFeed, stripHtml, extractTextFromHtml } = require('../../../src/manager/libraries/content/feed-parser.js');
11
+
12
+ // --- Sample feeds for testing ---
13
+
14
+ const RSS_FULL = `<?xml version="1.0" encoding="UTF-8"?>
15
+ <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
16
+ <channel>
17
+ <title>Tech News</title>
18
+ <link>https://example.com</link>
19
+ <description>Latest tech news</description>
20
+ <item>
21
+ <guid>https://example.com/article-1</guid>
22
+ <title>First Article Title</title>
23
+ <link>https://example.com/article-1</link>
24
+ <description>Short description of the first article.</description>
25
+ <content:encoded><![CDATA[<p>Full content of the first article with <strong>HTML</strong> formatting.</p>]]></content:encoded>
26
+ <pubDate>Mon, 16 Jun 2025 10:00:00 GMT</pubDate>
27
+ <dc:creator>Jane Doe</dc:creator>
28
+ </item>
29
+ <item>
30
+ <guid isPermaLink="false">article-2-id</guid>
31
+ <title>Second Article Title</title>
32
+ <link>https://example.com/article-2</link>
33
+ <description>Short description of the second article.</description>
34
+ <pubDate>Tue, 17 Jun 2025 12:00:00 GMT</pubDate>
35
+ </item>
36
+ </channel>
37
+ </rss>`;
38
+
39
+ const RSS_MINIMAL = `<?xml version="1.0"?>
40
+ <rss version="2.0">
41
+ <channel>
42
+ <title>Minimal</title>
43
+ <item>
44
+ <title>Only Title</title>
45
+ <link>https://example.com/only</link>
46
+ </item>
47
+ </channel>
48
+ </rss>`;
49
+
50
+ const RSS_EMPTY_CHANNEL = `<?xml version="1.0"?>
51
+ <rss version="2.0">
52
+ <channel>
53
+ <title>Empty</title>
54
+ </channel>
55
+ </rss>`;
56
+
57
+ const ATOM_FULL = `<?xml version="1.0" encoding="utf-8"?>
58
+ <feed xmlns="http://www.w3.org/2005/Atom">
59
+ <title>Atom Feed</title>
60
+ <entry>
61
+ <id>urn:uuid:entry-1</id>
62
+ <title>Atom Entry One</title>
63
+ <link rel="alternate" href="https://example.com/atom-1"/>
64
+ <link rel="enclosure" href="https://example.com/atom-1.mp3"/>
65
+ <summary>Summary of entry one.</summary>
66
+ <content>Full content of entry one.</content>
67
+ <published>2025-06-16T10:00:00Z</published>
68
+ </entry>
69
+ <entry>
70
+ <id>urn:uuid:entry-2</id>
71
+ <title type="html">Atom Entry &amp; Two</title>
72
+ <link href="https://example.com/atom-2"/>
73
+ <updated>2025-06-17T12:00:00Z</updated>
74
+ </entry>
75
+ </feed>`;
76
+
77
+ const ATOM_EMPTY = `<?xml version="1.0"?>
78
+ <feed xmlns="http://www.w3.org/2005/Atom">
79
+ <title>Empty Atom</title>
80
+ </feed>`;
81
+
82
+ const JSON_FEED = JSON.stringify({
83
+ version: 'https://jsonfeed.org/version/1.1',
84
+ title: 'JSON Feed',
85
+ items: [
86
+ {
87
+ id: 'json-1',
88
+ title: 'JSON Article One',
89
+ url: 'https://example.com/json-1',
90
+ summary: 'Short summary.',
91
+ content_html: '<p>Full HTML content.</p>',
92
+ content_text: 'Full text content.',
93
+ date_published: '2025-06-16T10:00:00Z',
94
+ },
95
+ {
96
+ id: 'json-2',
97
+ title: 'JSON Article Two',
98
+ url: 'https://example.com/json-2',
99
+ content_text: 'Second article text.',
100
+ date_modified: '2025-06-17T12:00:00Z',
101
+ },
102
+ ],
103
+ });
104
+
105
+ const RSSAPP_FORMAT = JSON.stringify({
106
+ items: [
107
+ {
108
+ title: 'RSS.app Item',
109
+ url: 'https://example.com/rssapp-1',
110
+ content_text: 'Content from RSS.app feed.',
111
+ },
112
+ ],
113
+ });
114
+
115
+ module.exports = {
116
+ description: 'content/feed-parser',
117
+ type: 'group',
118
+
119
+ tests: [
120
+ // ============================
121
+ // RSS 2.0 PARSING
122
+ // ============================
123
+ {
124
+ name: 'rss-parses-standard-items',
125
+ async run({ assert }) {
126
+ const { items } = parseFeed(RSS_FULL);
127
+ assert.equal(items.length, 2, 'should parse 2 items');
128
+ assert.equal(items[0].title, 'First Article Title');
129
+ assert.equal(items[1].title, 'Second Article Title');
130
+ },
131
+ },
132
+
133
+ {
134
+ name: 'rss-extracts-guid-as-id',
135
+ async run({ assert }) {
136
+ const { items } = parseFeed(RSS_FULL);
137
+ assert.equal(items[0].id, 'https://example.com/article-1', 'text guid');
138
+ assert.equal(items[1].id, 'article-2-id', 'guid with isPermaLink attr');
139
+ },
140
+ },
141
+
142
+ {
143
+ name: 'rss-extracts-link-as-url',
144
+ async run({ assert }) {
145
+ const { items } = parseFeed(RSS_FULL);
146
+ assert.equal(items[0].url, 'https://example.com/article-1');
147
+ assert.equal(items[1].url, 'https://example.com/article-2');
148
+ },
149
+ },
150
+
151
+ {
152
+ name: 'rss-extracts-description-as-summary',
153
+ async run({ assert }) {
154
+ const { items } = parseFeed(RSS_FULL);
155
+ assert.equal(items[0].summary, 'Short description of the first article.');
156
+ },
157
+ },
158
+
159
+ {
160
+ name: 'rss-extracts-content-encoded-as-content',
161
+ async run({ assert }) {
162
+ const { items } = parseFeed(RSS_FULL);
163
+ assert.ok(items[0].content.includes('Full content of the first article'), 'has content:encoded text');
164
+ assert.ok(!items[0].content.includes('<p>'), 'HTML stripped from content');
165
+ },
166
+ },
167
+
168
+ {
169
+ name: 'rss-falls-back-to-description-when-no-content-encoded',
170
+ async run({ assert }) {
171
+ const { items } = parseFeed(RSS_FULL);
172
+ assert.equal(items[1].content, 'Short description of the second article.');
173
+ },
174
+ },
175
+
176
+ {
177
+ name: 'rss-extracts-pubdate',
178
+ async run({ assert }) {
179
+ const { items } = parseFeed(RSS_FULL);
180
+ assert.equal(items[0].publishedAt, 'Mon, 16 Jun 2025 10:00:00 GMT');
181
+ },
182
+ },
183
+
184
+ {
185
+ name: 'rss-handles-missing-optional-fields',
186
+ async run({ assert }) {
187
+ const { items } = parseFeed(RSS_MINIMAL);
188
+ assert.equal(items.length, 1);
189
+ assert.equal(items[0].title, 'Only Title');
190
+ assert.equal(items[0].url, 'https://example.com/only');
191
+ assert.equal(items[0].summary, '', 'no description');
192
+ assert.equal(items[0].publishedAt, '', 'no pubDate');
193
+ },
194
+ },
195
+
196
+ {
197
+ name: 'rss-preserves-item-order',
198
+ async run({ assert }) {
199
+ const { items } = parseFeed(RSS_FULL);
200
+ assert.equal(items[0].title, 'First Article Title', 'first item is first');
201
+ assert.equal(items[1].title, 'Second Article Title', 'second item is second');
202
+ },
203
+ },
204
+
205
+ {
206
+ name: 'rss-empty-channel-returns-empty-items',
207
+ async run({ assert }) {
208
+ const { items } = parseFeed(RSS_EMPTY_CHANNEL);
209
+ assert.equal(items.length, 0);
210
+ },
211
+ },
212
+
213
+ // ============================
214
+ // ATOM 1.0 PARSING
215
+ // ============================
216
+ {
217
+ name: 'atom-parses-standard-entries',
218
+ async run({ assert }) {
219
+ const { items } = parseFeed(ATOM_FULL);
220
+ assert.equal(items.length, 2, 'should parse 2 entries');
221
+ assert.equal(items[0].title, 'Atom Entry One');
222
+ },
223
+ },
224
+
225
+ {
226
+ name: 'atom-extracts-id',
227
+ async run({ assert }) {
228
+ const { items } = parseFeed(ATOM_FULL);
229
+ assert.equal(items[0].id, 'urn:uuid:entry-1');
230
+ assert.equal(items[1].id, 'urn:uuid:entry-2');
231
+ },
232
+ },
233
+
234
+ {
235
+ name: 'atom-picks-alternate-link-href',
236
+ async run({ assert }) {
237
+ const { items } = parseFeed(ATOM_FULL);
238
+ assert.equal(items[0].url, 'https://example.com/atom-1', 'picks rel=alternate over enclosure');
239
+ },
240
+ },
241
+
242
+ {
243
+ name: 'atom-falls-back-to-first-link-when-no-rel',
244
+ async run({ assert }) {
245
+ const { items } = parseFeed(ATOM_FULL);
246
+ assert.equal(items[1].url, 'https://example.com/atom-2', 'link without rel');
247
+ },
248
+ },
249
+
250
+ {
251
+ name: 'atom-extracts-summary-and-content',
252
+ async run({ assert }) {
253
+ const { items } = parseFeed(ATOM_FULL);
254
+ assert.equal(items[0].summary, 'Summary of entry one.');
255
+ assert.equal(items[0].content, 'Full content of entry one.');
256
+ },
257
+ },
258
+
259
+ {
260
+ name: 'atom-extracts-published-or-updated',
261
+ async run({ assert }) {
262
+ const { items } = parseFeed(ATOM_FULL);
263
+ assert.equal(items[0].publishedAt, '2025-06-16T10:00:00Z', 'published');
264
+ assert.equal(items[1].publishedAt, '2025-06-17T12:00:00Z', 'updated fallback');
265
+ },
266
+ },
267
+
268
+ {
269
+ name: 'atom-empty-feed-returns-empty-items',
270
+ async run({ assert }) {
271
+ const { items } = parseFeed(ATOM_EMPTY);
272
+ assert.equal(items.length, 0);
273
+ },
274
+ },
275
+
276
+ // ============================
277
+ // JSON FEED PARSING
278
+ // ============================
279
+ {
280
+ name: 'json-parses-standard-items',
281
+ async run({ assert }) {
282
+ const { items } = parseFeed(JSON_FEED);
283
+ assert.equal(items.length, 2);
284
+ assert.equal(items[0].title, 'JSON Article One');
285
+ assert.equal(items[1].title, 'JSON Article Two');
286
+ },
287
+ },
288
+
289
+ {
290
+ name: 'json-extracts-id-and-url',
291
+ async run({ assert }) {
292
+ const { items } = parseFeed(JSON_FEED);
293
+ assert.equal(items[0].id, 'json-1');
294
+ assert.equal(items[0].url, 'https://example.com/json-1');
295
+ },
296
+ },
297
+
298
+ {
299
+ name: 'json-prefers-content-html-over-content-text',
300
+ async run({ assert }) {
301
+ const { items } = parseFeed(JSON_FEED);
302
+ assert.equal(items[0].content, '<p>Full HTML content.</p>');
303
+ },
304
+ },
305
+
306
+ {
307
+ name: 'json-falls-back-to-content-text',
308
+ async run({ assert }) {
309
+ const { items } = parseFeed(JSON_FEED);
310
+ assert.equal(items[1].content, 'Second article text.');
311
+ },
312
+ },
313
+
314
+ {
315
+ name: 'json-extracts-dates',
316
+ async run({ assert }) {
317
+ const { items } = parseFeed(JSON_FEED);
318
+ assert.equal(items[0].publishedAt, '2025-06-16T10:00:00Z', 'date_published');
319
+ assert.equal(items[1].publishedAt, '2025-06-17T12:00:00Z', 'date_modified fallback');
320
+ },
321
+ },
322
+
323
+ {
324
+ name: 'json-handles-rssapp-format',
325
+ async run({ assert }) {
326
+ const { items } = parseFeed(RSSAPP_FORMAT);
327
+ assert.equal(items.length, 1);
328
+ assert.equal(items[0].title, 'RSS.app Item');
329
+ assert.equal(items[0].content, 'Content from RSS.app feed.');
330
+ },
331
+ },
332
+
333
+ {
334
+ name: 'json-empty-items-returns-empty',
335
+ async run({ assert }) {
336
+ const { items } = parseFeed(JSON.stringify({ items: [] }));
337
+ assert.equal(items.length, 0);
338
+ },
339
+ },
340
+
341
+ // ============================
342
+ // EDGE CASES
343
+ // ============================
344
+ {
345
+ name: 'returns-empty-for-null-input',
346
+ async run({ assert }) {
347
+ assert.deepEqual(parseFeed(null), { items: [] });
348
+ },
349
+ },
350
+
351
+ {
352
+ name: 'returns-empty-for-undefined-input',
353
+ async run({ assert }) {
354
+ assert.deepEqual(parseFeed(undefined), { items: [] });
355
+ },
356
+ },
357
+
358
+ {
359
+ name: 'returns-empty-for-empty-string',
360
+ async run({ assert }) {
361
+ assert.deepEqual(parseFeed(''), { items: [] });
362
+ },
363
+ },
364
+
365
+ {
366
+ name: 'returns-empty-for-invalid-xml',
367
+ async run({ assert }) {
368
+ const { items } = parseFeed('<not<valid>xml');
369
+ assert.equal(items.length, 0);
370
+ },
371
+ },
372
+
373
+ {
374
+ name: 'returns-empty-for-non-feed-json',
375
+ async run({ assert }) {
376
+ const { items } = parseFeed(JSON.stringify({ data: [1, 2, 3] }));
377
+ assert.equal(items.length, 0);
378
+ },
379
+ },
380
+
381
+ {
382
+ name: 'returns-empty-for-plain-text',
383
+ async run({ assert }) {
384
+ const { items } = parseFeed('just some plain text content');
385
+ assert.equal(items.length, 0);
386
+ },
387
+ },
388
+
389
+ {
390
+ name: 'handles-bom-prefix',
391
+ async run({ assert }) {
392
+ const withBom = '' + RSS_MINIMAL;
393
+ const { items } = parseFeed(withBom);
394
+ assert.equal(items.length, 1, 'BOM does not break parsing');
395
+ assert.equal(items[0].title, 'Only Title');
396
+ },
397
+ },
398
+
399
+ {
400
+ name: 'handles-namespace-prefixed-elements',
401
+ async run({ assert }) {
402
+ const { items } = parseFeed(RSS_FULL);
403
+ assert.ok(items[0].content.includes('Full content'), 'content:encoded parsed despite namespace');
404
+ },
405
+ },
406
+
407
+ {
408
+ name: 'truncates-long-content',
409
+ async run({ assert }) {
410
+ const longContent = 'x'.repeat(20000);
411
+ const feed = JSON.stringify({
412
+ items: [{ id: '1', title: 'Long', url: 'https://example.com', content_text: longContent }],
413
+ });
414
+ const { items } = parseFeed(feed);
415
+ assert.ok(items[0].content.length <= 1024 * 14, 'content truncated to 14KB');
416
+ },
417
+ },
418
+
419
+ {
420
+ name: 'truncates-long-summary',
421
+ async run({ assert }) {
422
+ const longSummary = 'y'.repeat(1000);
423
+ const feed = JSON.stringify({
424
+ items: [{ id: '1', title: 'Long Summary', url: 'https://example.com', summary: longSummary }],
425
+ });
426
+ const { items } = parseFeed(feed);
427
+ assert.ok(items[0].summary.length <= 500, 'summary truncated to 500 chars');
428
+ },
429
+ },
430
+
431
+ // ============================
432
+ // STRIP HTML
433
+ // ============================
434
+ {
435
+ name: 'stripHtml-removes-tags',
436
+ async run({ assert }) {
437
+ assert.equal(stripHtml('<p>Hello <strong>world</strong></p>'), 'Hello world');
438
+ },
439
+ },
440
+
441
+ {
442
+ name: 'stripHtml-normalizes-whitespace',
443
+ async run({ assert }) {
444
+ assert.equal(stripHtml('<p>Hello</p> <p>World</p>'), 'Hello World');
445
+ },
446
+ },
447
+
448
+ {
449
+ name: 'stripHtml-handles-empty-string',
450
+ async run({ assert }) {
451
+ assert.equal(stripHtml(''), '');
452
+ },
453
+ },
454
+
455
+ // ============================
456
+ // EXTRACT TEXT FROM HTML (Cheerio)
457
+ // ============================
458
+ {
459
+ name: 'extractTextFromHtml-extracts-from-article-tag',
460
+ async run({ assert }) {
461
+ const html = '<html><body><nav>Menu</nav><article class="post"><p>Article content</p></article><footer>Footer</footer></body></html>';
462
+ const text = extractTextFromHtml(html);
463
+ assert.ok(text.includes('Article content'), 'extracts article text');
464
+ assert.ok(!text.includes('Menu'), 'nav removed');
465
+ assert.ok(!text.includes('Footer'), 'footer removed');
466
+ },
467
+ },
468
+
469
+ {
470
+ name: 'extractTextFromHtml-falls-back-to-main',
471
+ async run({ assert }) {
472
+ const html = '<html><body><main><p>Main content</p></main><aside>Sidebar</aside></body></html>';
473
+ const text = extractTextFromHtml(html);
474
+ assert.ok(text.includes('Main content'), 'extracts main text');
475
+ assert.ok(!text.includes('Sidebar'), 'aside removed');
476
+ },
477
+ },
478
+
479
+ {
480
+ name: 'extractTextFromHtml-falls-back-to-body',
481
+ async run({ assert }) {
482
+ const html = '<html><body><p>Body content here</p></body></html>';
483
+ const text = extractTextFromHtml(html);
484
+ assert.ok(text.includes('Body content here'), 'extracts body text');
485
+ },
486
+ },
487
+
488
+ {
489
+ name: 'extractTextFromHtml-strips-scripts-and-styles',
490
+ async run({ assert }) {
491
+ const html = '<html><body><article><script>alert("xss")</script><style>.x{color:red}</style><p>Clean text</p></article></body></html>';
492
+ const text = extractTextFromHtml(html);
493
+ assert.ok(text.includes('Clean text'), 'keeps article text');
494
+ assert.ok(!text.includes('alert'), 'script removed');
495
+ assert.ok(!text.includes('color'), 'style removed');
496
+ },
497
+ },
498
+
499
+ {
500
+ name: 'extractTextFromHtml-strips-forms-and-buttons',
501
+ async run({ assert }) {
502
+ const html = '<html><body><article><p>Article text</p><form><input placeholder="Email"><button>Subscribe</button></form></article></body></html>';
503
+ const text = extractTextFromHtml(html);
504
+ assert.ok(text.includes('Article text'), 'keeps article text');
505
+ assert.ok(!text.includes('Subscribe'), 'button removed');
506
+ },
507
+ },
508
+
509
+ {
510
+ name: 'extractTextFromHtml-strips-ad-classes',
511
+ async run({ assert }) {
512
+ const html = '<html><body><article><p>Real content</p><div class="advertisement">Buy stuff</div><div class="social-share">Share this</div></article></body></html>';
513
+ const text = extractTextFromHtml(html);
514
+ assert.ok(text.includes('Real content'), 'keeps article text');
515
+ assert.ok(!text.includes('Buy stuff'), 'ad removed');
516
+ assert.ok(!text.includes('Share this'), 'social share removed');
517
+ },
518
+ },
519
+
520
+ {
521
+ name: 'extractTextFromHtml-returns-empty-for-empty-html',
522
+ async run({ assert }) {
523
+ assert.equal(extractTextFromHtml(''), '');
524
+ assert.equal(extractTextFromHtml('<html><body></body></html>'), '');
525
+ },
526
+ },
527
+ ],
528
+ };